Index: base/logging.h |
diff --git a/base/logging.h b/base/logging.h |
index 647f5804da51cfd3924cff6e2e59d717ce46e83d..ae67eacc2aaa3ac129caabfa5726eae006aec062 100644 |
--- a/base/logging.h |
+++ b/base/logging.h |
@@ -13,6 +13,7 @@ |
#include "base/base_export.h" |
#include "base/basictypes.h" |
+#include "base/debug/debugger.h" |
#include "build/build_config.h" |
// |
@@ -442,12 +443,44 @@ const LogSeverity LOG_0 = LOG_ERROR; |
#define PLOG_IF(severity, condition) \ |
LAZY_STREAM(PLOG_STREAM(severity), LOG_IS_ON(severity) && (condition)) |
+// http://crbug.com/16512 is open for a real fix for this. For now, Windows |
+// uses OFFICIAL_BUILD and other platforms use the branding flag when NDEBUG is |
+// defined. |
+#if ( defined(OS_WIN) && defined(OFFICIAL_BUILD)) || \ |
+ (!defined(OS_WIN) && defined(NDEBUG) && defined(GOOGLE_CHROME_BUILD)) |
+#define LOGGING_IS_OFFICIAL_BUILD 1 |
+#else |
+#define LOGGING_IS_OFFICIAL_BUILD 0 |
+#endif |
+ |
+// The actual stream used isn't important. |
+#define EAT_STREAM_PARAMETERS \ |
+ true ? (void) 0 : ::logging::LogMessageVoidify() & LOG_STREAM(FATAL) |
+ |
// CHECK dies with a fatal error if condition is not true. It is *not* |
// controlled by NDEBUG, so the check will be executed regardless of |
// compilation mode. |
// |
// We make sure CHECK et al. always evaluates their arguments, as |
// doing CHECK(FunctionWithSideEffect()) is a common idiom. |
+ |
+#if LOGGING_IS_OFFICIAL_BUILD |
+ |
+// Make all CHECK functions discard their log strings to reduce code |
+// bloat for official builds. |
+ |
+// TODO(akalin): This would be more valuable if there were some way to |
+// remove BreakDebugger() from the backtrace, perhaps by turning it |
+// into a macro (like __debugbreak() on Windows). |
+#define CHECK(condition) \ |
+ !(condition) ? ::base::debug::BreakDebugger() : EAT_STREAM_PARAMETERS |
+ |
+#define PCHECK(condition) CHECK(condition) |
+ |
+#define CHECK_OP(name, op, val1, val2) CHECK((val1) op (val2)) |
+ |
+#else |
+ |
#define CHECK(condition) \ |
LAZY_STREAM(LOG_STREAM(FATAL), !(condition)) \ |
<< "Check failed: " #condition ". " |
@@ -456,6 +489,19 @@ const LogSeverity LOG_0 = LOG_ERROR; |
LAZY_STREAM(PLOG_STREAM(FATAL), !(condition)) \ |
<< "Check failed: " #condition ". " |
+// Helper macro for binary operators. |
+// Don't use this macro directly in your code, use CHECK_EQ et al below. |
+// |
+// TODO(akalin): Rewrite this so that constructs like if (...) |
+// CHECK_EQ(...) else { ... } work properly. |
+#define CHECK_OP(name, op, val1, val2) \ |
+ if (std::string* _result = \ |
+ logging::Check##name##Impl((val1), (val2), \ |
+ #val1 " " #op " " #val2)) \ |
+ logging::LogMessage(__FILE__, __LINE__, _result).stream() |
+ |
+#endif |
+ |
// Build the error message string. This is separate from the "Impl" |
// function template because it is not performance critical and so can |
// be out of line, while the "Impl" code should be inline. Caller |
@@ -488,17 +534,6 @@ std::string* MakeCheckOpString<std::string, std::string>( |
const std::string&, const std::string&, const char* name); |
#endif |
-// Helper macro for binary operators. |
-// Don't use this macro directly in your code, use CHECK_EQ et al below. |
-// |
-// TODO(akalin): Rewrite this so that constructs like if (...) |
-// CHECK_EQ(...) else { ... } work properly. |
-#define CHECK_OP(name, op, val1, val2) \ |
- if (std::string* _result = \ |
- logging::Check##name##Impl((val1), (val2), \ |
- #val1 " " #op " " #val2)) \ |
- logging::LogMessage(__FILE__, __LINE__, _result).stream() |
- |
// Helper functions for CHECK_OP macro. |
// The (int, int) specialization works around the issue that the compiler |
// will not instantiate the template version of the function on values of |
@@ -529,14 +564,7 @@ DEFINE_CHECK_OP_IMPL(GT, > ) |
#define CHECK_GE(val1, val2) CHECK_OP(GE, >=, val1, val2) |
#define CHECK_GT(val1, val2) CHECK_OP(GT, > , val1, val2) |
-// http://crbug.com/16512 is open for a real fix for this. For now, Windows |
-// uses OFFICIAL_BUILD and other platforms use the branding flag when NDEBUG is |
-// defined. |
-#if ( defined(OS_WIN) && defined(OFFICIAL_BUILD)) || \ |
- (!defined(OS_WIN) && defined(NDEBUG) && defined(GOOGLE_CHROME_BUILD)) |
-// Used by unit tests. |
-#define LOGGING_IS_OFFICIAL_BUILD |
- |
+#if LOGGING_IS_OFFICIAL_BUILD |
// In order to have optimized code for official builds, remove DLOGs and |
// DCHECKs. |
#define ENABLE_DLOG 0 |
@@ -572,15 +600,12 @@ DEFINE_CHECK_OP_IMPL(GT, > ) |
// is not defined). Contrast this with DCHECK et al., which has |
// different behavior. |
-#define DLOG_EAT_STREAM_PARAMETERS \ |
- true ? (void) 0 : ::logging::LogMessageVoidify() & LOG_STREAM(FATAL) |
- |
#define DLOG_IS_ON(severity) false |
-#define DLOG_IF(severity, condition) DLOG_EAT_STREAM_PARAMETERS |
-#define DLOG_ASSERT(condition) DLOG_EAT_STREAM_PARAMETERS |
-#define DPLOG_IF(severity, condition) DLOG_EAT_STREAM_PARAMETERS |
-#define DVLOG_IF(verboselevel, condition) DLOG_EAT_STREAM_PARAMETERS |
-#define DVPLOG_IF(verboselevel, condition) DLOG_EAT_STREAM_PARAMETERS |
+#define DLOG_IF(severity, condition) EAT_STREAM_PARAMETERS |
+#define DLOG_ASSERT(condition) EAT_STREAM_PARAMETERS |
+#define DPLOG_IF(severity, condition) EAT_STREAM_PARAMETERS |
+#define DVLOG_IF(verboselevel, condition) EAT_STREAM_PARAMETERS |
+#define DVPLOG_IF(verboselevel, condition) EAT_STREAM_PARAMETERS |
#endif // ENABLE_DLOG |