OLD | NEW |
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 <cassert> | 8 #include <cassert> |
9 #include <string> | 9 #include <string> |
10 #include <cstring> | 10 #include <cstring> |
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 // CHECK dies with a fatal error if condition is not true. It is *not* | 429 // CHECK dies with a fatal error if condition is not true. It is *not* |
430 // controlled by NDEBUG, so the check will be executed regardless of | 430 // controlled by NDEBUG, so the check will be executed regardless of |
431 // compilation mode. | 431 // compilation mode. |
432 // | 432 // |
433 // We make sure CHECK et al. always evaluates their arguments, as | 433 // We make sure CHECK et al. always evaluates their arguments, as |
434 // doing CHECK(FunctionWithSideEffect()) is a common idiom. | 434 // doing CHECK(FunctionWithSideEffect()) is a common idiom. |
435 | 435 |
436 #if defined(OFFICIAL_BUILD) && defined(NDEBUG) && !defined(OS_ANDROID) | 436 #if defined(OFFICIAL_BUILD) && defined(NDEBUG) && !defined(OS_ANDROID) |
437 | 437 |
438 // Make all CHECK functions discard their log strings to reduce code | 438 // Make all CHECK functions discard their log strings to reduce code |
439 // bloat for official release builds. | 439 // bloat for official release builds (except Android). |
440 | 440 |
441 // TODO(akalin): This would be more valuable if there were some way to | 441 // TODO(akalin): This would be more valuable if there were some way to |
442 // remove BreakDebugger() from the backtrace, perhaps by turning it | 442 // remove BreakDebugger() from the backtrace, perhaps by turning it |
443 // into a macro (like __debugbreak() on Windows). | 443 // into a macro (like __debugbreak() on Windows). |
444 #define CHECK(condition) \ | 444 #define CHECK(condition) \ |
445 !(condition) ? ::base::debug::BreakDebugger() : EAT_STREAM_PARAMETERS | 445 !(condition) ? ::base::debug::BreakDebugger() : EAT_STREAM_PARAMETERS |
446 | 446 |
447 #define PCHECK(condition) CHECK(condition) | 447 #define PCHECK(condition) CHECK(condition) |
448 | 448 |
449 #define CHECK_OP(name, op, val1, val2) CHECK((val1) op (val2)) | 449 #define CHECK_OP(name, op, val1, val2) CHECK((val1) op (val2)) |
(...skipping 13 matching lines...) Expand all Loading... |
463 LAZY_STREAM(LOG_STREAM(FATAL), false) \ | 463 LAZY_STREAM(LOG_STREAM(FATAL), false) \ |
464 << "Check failed: " #condition ". " | 464 << "Check failed: " #condition ". " |
465 | 465 |
466 #define PCHECK(condition) \ | 466 #define PCHECK(condition) \ |
467 __analysis_assume(!!(condition)), \ | 467 __analysis_assume(!!(condition)), \ |
468 LAZY_STREAM(PLOG_STREAM(FATAL), false) \ | 468 LAZY_STREAM(PLOG_STREAM(FATAL), false) \ |
469 << "Check failed: " #condition ". " | 469 << "Check failed: " #condition ". " |
470 | 470 |
471 #else // _PREFAST_ | 471 #else // _PREFAST_ |
472 | 472 |
473 #define CHECK(condition) \ | 473 // Do as much work as possible out of line to reduce inline code size. |
474 LAZY_STREAM(LOG_STREAM(FATAL), !(condition)) \ | 474 #define CHECK(condition) \ |
475 << "Check failed: " #condition ". " | 475 LAZY_STREAM(logging::LogMessage(__FILE__, __LINE__, #condition).stream(), \ |
| 476 !(condition)) |
476 | 477 |
477 #define PCHECK(condition) \ | 478 #define PCHECK(condition) \ |
478 LAZY_STREAM(PLOG_STREAM(FATAL), !(condition)) \ | 479 LAZY_STREAM(PLOG_STREAM(FATAL), !(condition)) \ |
479 << "Check failed: " #condition ". " | 480 << "Check failed: " #condition ". " |
480 | 481 |
481 #endif // _PREFAST_ | 482 #endif // _PREFAST_ |
482 | 483 |
483 // Helper macro for binary operators. | 484 // Helper macro for binary operators. |
484 // Don't use this macro directly in your code, use CHECK_EQ et al below. | 485 // Don't use this macro directly in your code, use CHECK_EQ et al below. |
485 // | 486 // |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
720 // full message gets streamed to the appropriate destination. | 721 // full message gets streamed to the appropriate destination. |
721 // | 722 // |
722 // You shouldn't actually use LogMessage's constructor to log things, | 723 // You shouldn't actually use LogMessage's constructor to log things, |
723 // though. You should use the LOG() macro (and variants thereof) | 724 // though. You should use the LOG() macro (and variants thereof) |
724 // above. | 725 // above. |
725 class BASE_EXPORT LogMessage { | 726 class BASE_EXPORT LogMessage { |
726 public: | 727 public: |
727 // Used for LOG(severity). | 728 // Used for LOG(severity). |
728 LogMessage(const char* file, int line, LogSeverity severity); | 729 LogMessage(const char* file, int line, LogSeverity severity); |
729 | 730 |
| 731 // Used for CHECK(). Implied severity = LOG_FATAL. |
| 732 LogMessage(const char* file, int line, const char* condition); |
| 733 |
730 // Used for CHECK_EQ(), etc. Takes ownership of the given string. | 734 // Used for CHECK_EQ(), etc. Takes ownership of the given string. |
731 // Implied severity = LOG_FATAL. | 735 // Implied severity = LOG_FATAL. |
732 LogMessage(const char* file, int line, std::string* result); | 736 LogMessage(const char* file, int line, std::string* result); |
733 | 737 |
734 // Used for DCHECK_EQ(), etc. Takes ownership of the given string. | 738 // Used for DCHECK_EQ(), etc. Takes ownership of the given string. |
735 LogMessage(const char* file, int line, LogSeverity severity, | 739 LogMessage(const char* file, int line, LogSeverity severity, |
736 std::string* result); | 740 std::string* result); |
737 | 741 |
738 ~LogMessage(); | 742 ~LogMessage(); |
739 | 743 |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
930 #elif NOTIMPLEMENTED_POLICY == 5 | 934 #elif NOTIMPLEMENTED_POLICY == 5 |
931 #define NOTIMPLEMENTED() do {\ | 935 #define NOTIMPLEMENTED() do {\ |
932 static bool logged_once = false;\ | 936 static bool logged_once = false;\ |
933 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\ | 937 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\ |
934 logged_once = true;\ | 938 logged_once = true;\ |
935 } while(0);\ | 939 } while(0);\ |
936 EAT_STREAM_PARAMETERS | 940 EAT_STREAM_PARAMETERS |
937 #endif | 941 #endif |
938 | 942 |
939 #endif // BASE_LOGGING_H_ | 943 #endif // BASE_LOGGING_H_ |
OLD | NEW |