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 <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <cassert> | 10 #include <cassert> |
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 std::string* message_; | 441 std::string* message_; |
442 }; | 442 }; |
443 | 443 |
444 // CHECK dies with a fatal error if condition is not true. It is *not* | 444 // CHECK dies with a fatal error if condition is not true. It is *not* |
445 // controlled by NDEBUG, so the check will be executed regardless of | 445 // controlled by NDEBUG, so the check will be executed regardless of |
446 // compilation mode. | 446 // compilation mode. |
447 // | 447 // |
448 // We make sure CHECK et al. always evaluates their arguments, as | 448 // We make sure CHECK et al. always evaluates their arguments, as |
449 // doing CHECK(FunctionWithSideEffect()) is a common idiom. | 449 // doing CHECK(FunctionWithSideEffect()) is a common idiom. |
450 | 450 |
451 #if defined(OFFICIAL_BUILD) && defined(NDEBUG) && !defined(OS_ANDROID) | 451 #if defined(OFFICIAL_BUILD) && defined(NDEBUG) |
452 | 452 |
453 // Make all CHECK functions discard their log strings to reduce code | 453 // Make all CHECK functions discard their log strings to reduce code |
454 // bloat for official release builds (except Android). | 454 // bloat, and improve performance, for official release builds. |
455 | 455 |
456 // TODO(akalin): This would be more valuable if there were some way to | 456 // TODO(akalin): This would be more valuable if there were some way to |
457 // remove BreakDebugger() from the backtrace, perhaps by turning it | 457 // remove BreakDebugger() from the backtrace, perhaps by turning it |
458 // into a macro (like __debugbreak() on Windows). | 458 // into a macro (like __debugbreak() on Windows). |
459 #define CHECK(condition) \ | 459 #define CHECK(condition) \ |
460 !(condition) ? ::base::debug::BreakDebugger() : EAT_STREAM_PARAMETERS | 460 !(condition) ? ::base::debug::BreakDebugger() : EAT_STREAM_PARAMETERS |
461 | 461 |
462 #define PCHECK(condition) CHECK(condition) | 462 #define PCHECK(condition) CHECK(condition) |
463 | 463 |
464 #define CHECK_OP(name, op, val1, val2) CHECK((val1) op (val2)) | 464 #define CHECK_OP(name, op, val1, val2) CHECK((val1) op (val2)) |
465 | 465 |
466 #else | 466 #else // !(OFFICIAL_BUILD && NDEBUG) |
467 | 467 |
468 #if defined(_PREFAST_) && defined(OS_WIN) | 468 #if defined(_PREFAST_) && defined(OS_WIN) |
469 // Use __analysis_assume to tell the VC++ static analysis engine that | 469 // Use __analysis_assume to tell the VC++ static analysis engine that |
470 // assert conditions are true, to suppress warnings. The LAZY_STREAM | 470 // assert conditions are true, to suppress warnings. The LAZY_STREAM |
471 // parameter doesn't reference 'condition' in /analyze builds because | 471 // parameter doesn't reference 'condition' in /analyze builds because |
472 // this evaluation confuses /analyze. The !! before condition is because | 472 // this evaluation confuses /analyze. The !! before condition is because |
473 // __analysis_assume gets confused on some conditions: | 473 // __analysis_assume gets confused on some conditions: |
474 // http://randomascii.wordpress.com/2011/09/13/analyze-for-visual-studio-the-ugl
y-part-5/ | 474 // http://randomascii.wordpress.com/2011/09/13/analyze-for-visual-studio-the-ugl
y-part-5/ |
475 | 475 |
476 #define CHECK(condition) \ | 476 #define CHECK(condition) \ |
(...skipping 27 matching lines...) Expand all Loading... |
504 // CHECK_EQ(2, a); | 504 // CHECK_EQ(2, a); |
505 #define CHECK_OP(name, op, val1, val2) \ | 505 #define CHECK_OP(name, op, val1, val2) \ |
506 switch (0) case 0: default: \ | 506 switch (0) case 0: default: \ |
507 if (logging::CheckOpResult true_if_passed = \ | 507 if (logging::CheckOpResult true_if_passed = \ |
508 logging::Check##name##Impl((val1), (val2), \ | 508 logging::Check##name##Impl((val1), (val2), \ |
509 #val1 " " #op " " #val2)) \ | 509 #val1 " " #op " " #val2)) \ |
510 ; \ | 510 ; \ |
511 else \ | 511 else \ |
512 logging::LogMessage(__FILE__, __LINE__, true_if_passed.message()).stream() | 512 logging::LogMessage(__FILE__, __LINE__, true_if_passed.message()).stream() |
513 | 513 |
514 #endif | 514 #endif // !(OFFICIAL_BUILD && NDEBUG) |
515 | 515 |
516 // This formats a value for a failing CHECK_XX statement. Ordinarily, | 516 // This formats a value for a failing CHECK_XX statement. Ordinarily, |
517 // it uses the definition for operator<<, with a few special cases below. | 517 // it uses the definition for operator<<, with a few special cases below. |
518 template <typename T> | 518 template <typename T> |
519 inline void MakeCheckOpValueString(std::ostream* os, const T& v) { | 519 inline void MakeCheckOpValueString(std::ostream* os, const T& v) { |
520 (*os) << v; | 520 (*os) << v; |
521 } | 521 } |
522 | 522 |
523 // We need an explicit specialization for std::nullptr_t. | 523 // We need an explicit specialization for std::nullptr_t. |
524 template <> | 524 template <> |
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
973 #elif NOTIMPLEMENTED_POLICY == 5 | 973 #elif NOTIMPLEMENTED_POLICY == 5 |
974 #define NOTIMPLEMENTED() do {\ | 974 #define NOTIMPLEMENTED() do {\ |
975 static bool logged_once = false;\ | 975 static bool logged_once = false;\ |
976 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\ | 976 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\ |
977 logged_once = true;\ | 977 logged_once = true;\ |
978 } while(0);\ | 978 } while(0);\ |
979 EAT_STREAM_PARAMETERS | 979 EAT_STREAM_PARAMETERS |
980 #endif | 980 #endif |
981 | 981 |
982 #endif // BASE_LOGGING_H_ | 982 #endif // BASE_LOGGING_H_ |
OLD | NEW |