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

Side by Side Diff: base/logging.h

Issue 2525723004: Move IMMEDIATE_CRASH and OOM_CRASH from wtf to base. (Closed)
Patch Set: Remove #define LOGGING_CRASH — unnecessary. 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 #ifndef IMMEDIATE_CRASH
danakj 2016/11/28 22:28:08 Why the #ifndef?
palmer 2016/11/28 22:44:47 It's only there because it was in the original Bli
450 #if defined(COMPILER_GCC) || defined(__clang__)
451 #define IMMEDIATE_CRASH() __builtin_trap()
452 #else
453 #define IMMEDIATE_CRASH() ((void)(*(volatile char*)0 = 0))
454 #endif
455 #endif
456
457 // Specialization of IMMEDIATE_CRASH which will raise a custom exception on
458 // Windows to signal this is OOM and not a normal assert.
459 #ifndef OOM_CRASH
danakj 2016/11/28 22:28:08 same. is there some collision that this is worryin
460 #if defined(OS_WIN)
461 #define OOM_CRASH() \
462 do { \
463 ::RaiseException(0xE0000008, EXCEPTION_NONCONTINUABLE, 0, nullptr); \
464 IMMEDIATE_CRASH(); \
465 } while (0)
466 #else
467 #define OOM_CRASH() IMMEDIATE_CRASH()
468 #endif
469 #endif
470
448 // CHECK dies with a fatal error if condition is not true. It is *not* 471 // 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 472 // controlled by NDEBUG, so the check will be executed regardless of
450 // compilation mode. 473 // compilation mode.
451 // 474 //
452 // We make sure CHECK et al. always evaluates their arguments, as 475 // We make sure CHECK et al. always evaluates their arguments, as
453 // doing CHECK(FunctionWithSideEffect()) is a common idiom. 476 // doing CHECK(FunctionWithSideEffect()) is a common idiom.
454 477
455 #if defined(OFFICIAL_BUILD) && defined(NDEBUG) 478 #if defined(OFFICIAL_BUILD) && defined(NDEBUG)
456 479
457 // Make all CHECK functions discard their log strings to reduce code
458 // bloat, and improve performance, for official release builds.
459
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 480 // 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 481 // calling an out-of-line function instead of a noreturn inline macro prevents
468 // compiler optimizations. 482 // compiler optimizations.
469 #define CHECK(condition) \ 483 #define CHECK(condition) \
470 !(condition) ? LOGGING_CRASH() : EAT_STREAM_PARAMETERS 484 !(condition) ? IMMEDIATE_CRASH() : EAT_STREAM_PARAMETERS
471 485
472 #define PCHECK(condition) CHECK(condition) 486 #define PCHECK(condition) CHECK(condition)
473 487
474 #define CHECK_OP(name, op, val1, val2) CHECK((val1) op (val2)) 488 #define CHECK_OP(name, op, val1, val2) CHECK((val1) op (val2))
475 489
476 #else // !(OFFICIAL_BUILD && NDEBUG) 490 #else // !(OFFICIAL_BUILD && NDEBUG)
477 491
478 #if defined(_PREFAST_) && defined(OS_WIN) 492 #if defined(_PREFAST_) && defined(OS_WIN)
479 // Use __analysis_assume to tell the VC++ static analysis engine that 493 // Use __analysis_assume to tell the VC++ static analysis engine that
480 // assert conditions are true, to suppress warnings. The LAZY_STREAM 494 // 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 1016 #elif NOTIMPLEMENTED_POLICY == 5
1003 #define NOTIMPLEMENTED() do {\ 1017 #define NOTIMPLEMENTED() do {\
1004 static bool logged_once = false;\ 1018 static bool logged_once = false;\
1005 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\ 1019 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\
1006 logged_once = true;\ 1020 logged_once = true;\
1007 } while(0);\ 1021 } while(0);\
1008 EAT_STREAM_PARAMETERS 1022 EAT_STREAM_PARAMETERS
1009 #endif 1023 #endif
1010 1024
1011 #endif // BASE_LOGGING_H_ 1025 #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