Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(143)

Side by Side Diff: base/logging.h

Issue 1884023002: Implement Dump-on-DCHECK (via alternate DCHECK and DCHECK_OP macro implementations). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase on cleanups Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | base/logging.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef BASE_LOGGING_H_ 5 #ifndef BASE_LOGGING_H_
6 #define BASE_LOGGING_H_ 6 #define BASE_LOGGING_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <cassert> 10 #include <cassert>
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 const LogSeverity LOG_VERBOSE = -1; // This is level 1 verbosity 328 const LogSeverity LOG_VERBOSE = -1; // This is level 1 verbosity
329 // Note: the log severities are used to index into the array of names, 329 // Note: the log severities are used to index into the array of names,
330 // see log_severity_names. 330 // see log_severity_names.
331 const LogSeverity LOG_INFO = 0; 331 const LogSeverity LOG_INFO = 0;
332 const LogSeverity LOG_WARNING = 1; 332 const LogSeverity LOG_WARNING = 1;
333 const LogSeverity LOG_ERROR = 2; 333 const LogSeverity LOG_ERROR = 2;
334 const LogSeverity LOG_FATAL = 3; 334 const LogSeverity LOG_FATAL = 3;
335 const LogSeverity LOG_NUM_SEVERITIES = 4; 335 const LogSeverity LOG_NUM_SEVERITIES = 4;
336 336
337 // LOG_DFATAL is LOG_FATAL in debug mode, ERROR in normal mode 337 // LOG_DFATAL is LOG_FATAL in debug mode, ERROR in normal mode
338 #if defined(NDEBUG) 338 #if defined(NDEBUG) || defined(DCHECK_IS_DUMP_WITHOUT_CRASH)
339 const LogSeverity LOG_DFATAL = LOG_ERROR; 339 const LogSeverity LOG_DFATAL = LOG_ERROR;
340 #else 340 #else
341 const LogSeverity LOG_DFATAL = LOG_FATAL; 341 const LogSeverity LOG_DFATAL = LOG_FATAL;
342 #endif 342 #endif
343 343
344 // A few definitions of macros that don't generate much code. These are used 344 // A few definitions of macros that don't generate much code. These are used
345 // by LOG() and LOG_IF, etc. Since these are used all over our code, it's 345 // by LOG() and LOG_IF, etc. Since these are used all over our code, it's
346 // better to have compact code for these operations. 346 // better to have compact code for these operations.
347 #define COMPACT_GOOGLE_LOG_EX_INFO(ClassName, ...) \ 347 #define COMPACT_GOOGLE_LOG_EX_INFO(ClassName, ...) \
348 ::logging::ClassName(__FILE__, __LINE__, ::logging::LOG_INFO, ##__VA_ARGS__) 348 ::logging::ClassName(__FILE__, __LINE__, ::logging::LOG_INFO, ##__VA_ARGS__)
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 // whether DCHECKs are enabled; this is so that we don't get unused 801 // whether DCHECKs are enabled; this is so that we don't get unused
802 // variable warnings if the only use of a variable is in a DCHECK. 802 // variable warnings if the only use of a variable is in a DCHECK.
803 // This behavior is different from DLOG_IF et al. 803 // This behavior is different from DLOG_IF et al.
804 // 804 //
805 // Note that the definition of the DCHECK macros depends on whether or not 805 // Note that the definition of the DCHECK macros depends on whether or not
806 // DCHECK_IS_ON() is true. When DCHECK_IS_ON() is false, the macros use 806 // DCHECK_IS_ON() is true. When DCHECK_IS_ON() is false, the macros use
807 // EAT_STREAM_PARAMETERS to avoid expressions that would create temporaries. 807 // EAT_STREAM_PARAMETERS to avoid expressions that would create temporaries.
808 808
809 #if DCHECK_IS_ON() 809 #if DCHECK_IS_ON()
810 810
811 #if defined(DCHECK_IS_DUMP_WITHOUT_CRASH)
812 // DCHECK is configured to dump-without-crashing, rather than logging.
813 // Since we only intend to enable this in official builds, we follow the
814 // example of CHECK_OP etc in official builds, and strip out logging.
815 // See crbug.com/596231.
816
817 BASE_EXPORT void DCheckDumpWithoutCrashingOnce();
818
819 #define DCHECK(condition) \
820 !(condition) ? ::logging::DCheckDumpWithoutCrashingOnce() \
821 : EAT_STREAM_PARAMETERS
822
823 #define DPCHECK(condition) DCHECK(condition)
824
825 #else // defined(DCHECK_IS_DUMP_WITHOUT_CRASH)
826
811 #define DCHECK(condition) \ 827 #define DCHECK(condition) \
812 LAZY_STREAM(LOG_STREAM(DCHECK), !ANALYZER_ASSUME_TRUE(condition)) \ 828 LAZY_STREAM(LOG_STREAM(DCHECK), !ANALYZER_ASSUME_TRUE(condition)) \
813 << "Check failed: " #condition ". " 829 << "Check failed: " #condition ". "
814 #define DPCHECK(condition) \ 830 #define DPCHECK(condition) \
815 LAZY_STREAM(PLOG_STREAM(DCHECK), !ANALYZER_ASSUME_TRUE(condition)) \ 831 LAZY_STREAM(PLOG_STREAM(DCHECK), !ANALYZER_ASSUME_TRUE(condition)) \
816 << "Check failed: " #condition ". " 832 << "Check failed: " #condition ". "
817 833
834 #endif // defined(DCHECK_IS_DUMP_WITHOUT_CRASH)
835
818 #else // DCHECK_IS_ON() 836 #else // DCHECK_IS_ON()
819 837
820 #define DCHECK(condition) \ 838 #define DCHECK(condition) \
821 EAT_STREAM_PARAMETERS << !ANALYZER_ASSUME_TRUE(condition) 839 EAT_STREAM_PARAMETERS << !ANALYZER_ASSUME_TRUE(condition)
822 #define DPCHECK(condition) \ 840 #define DPCHECK(condition) \
823 EAT_STREAM_PARAMETERS << !ANALYZER_ASSUME_TRUE(condition) 841 EAT_STREAM_PARAMETERS << !ANALYZER_ASSUME_TRUE(condition)
824 842
825 #endif // DCHECK_IS_ON() 843 #endif // DCHECK_IS_ON()
826 844
827 // Helper macro for binary operators. 845 // Helper macro for binary operators.
828 // Don't use this macro directly in your code, use DCHECK_EQ et al below. 846 // Don't use this macro directly in your code, use DCHECK_EQ et al below.
829 // The 'switch' is used to prevent the 'else' from being ambiguous when the 847 // The 'switch' is used to prevent the 'else' from being ambiguous when the
830 // macro is used in an 'if' clause such as: 848 // macro is used in an 'if' clause such as:
831 // if (a == 1) 849 // if (a == 1)
832 // DCHECK_EQ(2, a); 850 // DCHECK_EQ(2, a);
833 #if DCHECK_IS_ON() 851 #if DCHECK_IS_ON()
834 852
853 #if defined(DCHECK_IS_DUMP_WITHOUT_CRASH)
854 // DCHECK is configured to dump-without-crashing, rather than logging.
855 // DCHECK_OP builds on DCHECK in this case (thereby inheriting the stripping
856 // of any << logged output. We use Check[op]Impl() for the comparison rather
857 // that comparing val1 and val2 directly because it ensures that the values'
858 // operator<< implementation is referenced, while coping with unnamed enums.
859 // See crbug.com/596231.
860
861 #define DCHECK_OP(name, op, val1, val2) \
862 DCHECK(::logging::Check##name##Impl((val1), (val2), "") == nullptr)
863
864 #else // defined(DCHECK_IS_DUMP_WITHOUT_CRASH)
865
835 #define DCHECK_OP(name, op, val1, val2) \ 866 #define DCHECK_OP(name, op, val1, val2) \
836 switch (0) case 0: default: \ 867 switch (0) case 0: default: \
837 if (::logging::CheckOpResult true_if_passed = \ 868 if (::logging::CheckOpResult true_if_passed = \
838 DCHECK_IS_ON() ? \ 869 DCHECK_IS_ON() ? \
839 ::logging::Check##name##Impl((val1), (val2), \ 870 ::logging::Check##name##Impl((val1), (val2), \
840 #val1 " " #op " " #val2) : nullptr) \ 871 #val1 " " #op " " #val2) : nullptr) \
841 ; \ 872 ; \
842 else \ 873 else \
843 ::logging::LogMessage(__FILE__, __LINE__, ::logging::LOG_DCHECK, \ 874 ::logging::LogMessage(__FILE__, __LINE__, ::logging::LOG_DCHECK, \
844 true_if_passed.message()).stream() 875 true_if_passed.message()).stream()
845 876
877 #endif // defined(DCHECK_IS_DUMP_WITHOUT_CRASH)
878
846 #else // DCHECK_IS_ON() 879 #else // DCHECK_IS_ON()
847 880
848 // When DCHECKs aren't enabled, DCHECK_OP still needs to reference operator<< 881 // When DCHECKs aren't enabled, DCHECK_OP still needs to reference operator<<
849 // overloads for |val1| and |val2| to avoid potential compiler warnings about 882 // overloads for |val1| and |val2| to avoid potential compiler warnings about
850 // unused functions. For the same reason, it also compares |val1| and |val2| 883 // unused functions. For the same reason, it also compares |val1| and |val2|
851 // using |op|. 884 // using |op|.
852 // 885 //
853 // Note that the contract of DCHECK_EQ, etc is that arguments are only evaluated 886 // Note that the contract of DCHECK_EQ, etc is that arguments are only evaluated
854 // once. Even though |val1| and |val2| appear twice in this version of the macro 887 // once. Even though |val1| and |val2| appear twice in this version of the macro
855 // expansion, this is OK, since the expression is never actually evaluated. 888 // expansion, this is OK, since the expression is never actually evaluated.
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
1125 #elif NOTIMPLEMENTED_POLICY == 5 1158 #elif NOTIMPLEMENTED_POLICY == 5
1126 #define NOTIMPLEMENTED() do {\ 1159 #define NOTIMPLEMENTED() do {\
1127 static bool logged_once = false;\ 1160 static bool logged_once = false;\
1128 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\ 1161 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\
1129 logged_once = true;\ 1162 logged_once = true;\
1130 } while(0);\ 1163 } while(0);\
1131 EAT_STREAM_PARAMETERS 1164 EAT_STREAM_PARAMETERS
1132 #endif 1165 #endif
1133 1166
1134 #endif // BASE_LOGGING_H_ 1167 #endif // BASE_LOGGING_H_
OLDNEW
« no previous file with comments | « no previous file | base/logging.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698