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 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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) | 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, and improve performance, for official release builds. | 454 // bloat, and improve performance, for official release builds. |
455 | 455 |
456 #if defined(COMPILER_GCC) || __clang__ | 456 // TODO(akalin): This would be more valuable if there were some way to |
457 #define LOGGING_CRASH() __builtin_trap() | 457 // remove BreakDebugger() from the backtrace, perhaps by turning it |
458 #else | 458 // into a macro (like __debugbreak() on Windows). |
459 #define LOGGING_CRASH() ((void)(*(volatile char*)0 = 0)) | |
460 #endif | |
461 | |
462 // This is not calling BreakDebugger since this is called frequently, and | |
463 // calling an out-of-line function instead of a noreturn inline macro prevents | |
464 // compiler optimizations. | |
465 #define CHECK(condition) \ | 459 #define CHECK(condition) \ |
466 !(condition) ? LOGGING_CRASH() : EAT_STREAM_PARAMETERS | 460 !(condition) ? ::base::debug::BreakDebugger() : EAT_STREAM_PARAMETERS |
467 | 461 |
468 #define PCHECK(condition) CHECK(condition) | 462 #define PCHECK(condition) CHECK(condition) |
469 | 463 |
470 #define CHECK_OP(name, op, val1, val2) CHECK((val1) op (val2)) | 464 #define CHECK_OP(name, op, val1, val2) CHECK((val1) op (val2)) |
471 | 465 |
472 #else // !(OFFICIAL_BUILD && NDEBUG) | 466 #else // !(OFFICIAL_BUILD && NDEBUG) |
473 | 467 |
474 #if defined(_PREFAST_) && defined(OS_WIN) | 468 #if defined(_PREFAST_) && defined(OS_WIN) |
475 // Use __analysis_assume to tell the VC++ static analysis engine that | 469 // Use __analysis_assume to tell the VC++ static analysis engine that |
476 // assert conditions are true, to suppress warnings. The LAZY_STREAM | 470 // assert conditions are true, to suppress warnings. The LAZY_STREAM |
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
979 #elif NOTIMPLEMENTED_POLICY == 5 | 973 #elif NOTIMPLEMENTED_POLICY == 5 |
980 #define NOTIMPLEMENTED() do {\ | 974 #define NOTIMPLEMENTED() do {\ |
981 static bool logged_once = false;\ | 975 static bool logged_once = false;\ |
982 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\ | 976 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\ |
983 logged_once = true;\ | 977 logged_once = true;\ |
984 } while(0);\ | 978 } while(0);\ |
985 EAT_STREAM_PARAMETERS | 979 EAT_STREAM_PARAMETERS |
986 #endif | 980 #endif |
987 | 981 |
988 #endif // BASE_LOGGING_H_ | 982 #endif // BASE_LOGGING_H_ |
OLD | NEW |