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

Side by Side Diff: base/logging.h

Issue 2525723004: Move IMMEDIATE_CRASH and OOM_CRASH from wtf to base. (Closed)
Patch Set: 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
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
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 480 // Make all CHECK functions discard their log strings to reduce code
458 // bloat, and improve performance, for official release builds. 481 // bloat, and improve performance, for official release builds.
459 482 #define LOGGING_CRASH() IMMEDIATE_CRASH()
danakj 2016/11/28 20:55:06 Just remove this and use IMMEDIATE_CRASH below?
palmer 2016/11/28 22:21:33 Done.
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 483
466 // This is not calling BreakDebugger since this is called frequently, and 484 // 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 485 // calling an out-of-line function instead of a noreturn inline macro prevents
468 // compiler optimizations. 486 // compiler optimizations.
469 #define CHECK(condition) \ 487 #define CHECK(condition) \
470 !(condition) ? LOGGING_CRASH() : EAT_STREAM_PARAMETERS 488 !(condition) ? LOGGING_CRASH() : EAT_STREAM_PARAMETERS
471 489
472 #define PCHECK(condition) CHECK(condition) 490 #define PCHECK(condition) CHECK(condition)
473 491
474 #define CHECK_OP(name, op, val1, val2) CHECK((val1) op (val2)) 492 #define CHECK_OP(name, op, val1, val2) CHECK((val1) op (val2))
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after
988 #elif NOTIMPLEMENTED_POLICY == 5 1006 #elif NOTIMPLEMENTED_POLICY == 5
989 #define NOTIMPLEMENTED() do {\ 1007 #define NOTIMPLEMENTED() do {\
990 static bool logged_once = false;\ 1008 static bool logged_once = false;\
991 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\ 1009 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\
992 logged_once = true;\ 1010 logged_once = true;\
993 } while(0);\ 1011 } while(0);\
994 EAT_STREAM_PARAMETERS 1012 EAT_STREAM_PARAMETERS
995 #endif 1013 #endif
996 1014
997 #endif // BASE_LOGGING_H_ 1015 #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