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

Side by Side Diff: base/logging.h

Issue 2525723004: Move IMMEDIATE_CRASH and OOM_CRASH from wtf to base. (Closed)
Patch Set: Everything in its right place. Created 4 years 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 | third_party/WebKit/Source/wtf/Assertions.h » ('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 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 CheckOpResult(std::string* message) : message_(message) {} 438 CheckOpResult(std::string* message) : message_(message) {}
439 // Returns true if the check succeeded. 439 // Returns true if the check succeeded.
440 operator bool() const { return !message_; } 440 operator bool() const { return !message_; }
441 // Returns the message. 441 // Returns the message.
442 std::string* message() { return message_; } 442 std::string* message() { return message_; }
443 443
444 private: 444 private:
445 std::string* message_; 445 std::string* message_;
446 }; 446 };
447 447
448 // Crashes in the fastest, simplest possible way with no attempt at logging.
449 #if defined(COMPILER_GCC) || defined(__clang__)
450 #define IMMEDIATE_CRASH() __builtin_trap()
451 #else
452 #define IMMEDIATE_CRASH() ((void)(*(volatile char*)0 = 0))
453 #endif
454
455 // Specialization of IMMEDIATE_CRASH which will raise a custom exception on
456 // Windows to signal this is OOM and not a normal assert.
457 #if defined(OS_WIN)
458 #define OOM_CRASH() \
459 do { \
460 ::RaiseException(0xE0000008, EXCEPTION_NONCONTINUABLE, 0, nullptr); \
461 IMMEDIATE_CRASH(); \
462 } while (0)
463 #else
464 #define OOM_CRASH() IMMEDIATE_CRASH()
465 #endif
466
448 // CHECK dies with a fatal error if condition is not true. It is *not* 467 // CHECK dies with a fatal error if condition is not true. It is *not*
449 // controlled by NDEBUG, so the check will be executed regardless of 468 // controlled by NDEBUG, so the check will be executed regardless of
450 // compilation mode. 469 // compilation mode.
451 // 470 //
452 // We make sure CHECK et al. always evaluates their arguments, as 471 // We make sure CHECK et al. always evaluates their arguments, as
453 // doing CHECK(FunctionWithSideEffect()) is a common idiom. 472 // doing CHECK(FunctionWithSideEffect()) is a common idiom.
454 473
455 #if defined(OFFICIAL_BUILD) && defined(NDEBUG) 474 #if defined(OFFICIAL_BUILD) && defined(NDEBUG)
456 475
457 // Make all CHECK functions discard their log strings to reduce code 476 // Make all CHECK functions discard their log strings to reduce code bloat, and
458 // bloat, and improve performance, for official release builds. 477 // improve performance, for official release builds.
459 478 //
460 #if defined(COMPILER_GCC) || __clang__
461 #define LOGGING_CRASH() __builtin_trap()
462 #else
463 #define LOGGING_CRASH() ((void)(*(volatile char*)0 = 0))
464 #endif
465
466 // This is not calling BreakDebugger since this is called frequently, and 479 // This is not calling BreakDebugger since this is called frequently, and
467 // calling an out-of-line function instead of a noreturn inline macro prevents 480 // calling an out-of-line function instead of a noreturn inline macro prevents
468 // compiler optimizations. 481 // compiler optimizations.
469 #define CHECK(condition) \ 482 #define CHECK(condition) \
470 !(condition) ? LOGGING_CRASH() : EAT_STREAM_PARAMETERS 483 !(condition) ? IMMEDIATE_CRASH() : EAT_STREAM_PARAMETERS
471 484
472 #define PCHECK(condition) CHECK(condition) 485 #define PCHECK(condition) CHECK(condition)
473 486
474 #define CHECK_OP(name, op, val1, val2) CHECK((val1) op (val2)) 487 #define CHECK_OP(name, op, val1, val2) CHECK((val1) op (val2))
475 488
476 #else // !(OFFICIAL_BUILD && NDEBUG) 489 #else // !(OFFICIAL_BUILD && NDEBUG)
477 490
478 #if defined(_PREFAST_) && defined(OS_WIN) 491 #if defined(_PREFAST_) && defined(OS_WIN)
479 // Use __analysis_assume to tell the VC++ static analysis engine that 492 // Use __analysis_assume to tell the VC++ static analysis engine that
480 // assert conditions are true, to suppress warnings. The LAZY_STREAM 493 // assert conditions are true, to suppress warnings. The LAZY_STREAM
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after
1002 #elif NOTIMPLEMENTED_POLICY == 5 1015 #elif NOTIMPLEMENTED_POLICY == 5
1003 #define NOTIMPLEMENTED() do {\ 1016 #define NOTIMPLEMENTED() do {\
1004 static bool logged_once = false;\ 1017 static bool logged_once = false;\
1005 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\ 1018 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\
1006 logged_once = true;\ 1019 logged_once = true;\
1007 } while(0);\ 1020 } while(0);\
1008 EAT_STREAM_PARAMETERS 1021 EAT_STREAM_PARAMETERS
1009 #endif 1022 #endif
1010 1023
1011 #endif // BASE_LOGGING_H_ 1024 #endif // BASE_LOGGING_H_
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/wtf/Assertions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698