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

Side by Side Diff: base/logging.h

Issue 1814423002: Patch to try dump-on-DCHECK. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Disable Blink ASSERT in dump-without-DCHECK builds Created 4 years, 8 months 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
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 619 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 LAZY_STREAM(PLOG_STREAM(severity), DLOG_IS_ON(severity)) 630 LAZY_STREAM(PLOG_STREAM(severity), DLOG_IS_ON(severity))
631 631
632 #define DVLOG(verboselevel) DVLOG_IF(verboselevel, VLOG_IS_ON(verboselevel)) 632 #define DVLOG(verboselevel) DVLOG_IF(verboselevel, VLOG_IS_ON(verboselevel))
633 633
634 #define DVPLOG(verboselevel) DVPLOG_IF(verboselevel, VLOG_IS_ON(verboselevel)) 634 #define DVPLOG(verboselevel) DVPLOG_IF(verboselevel, VLOG_IS_ON(verboselevel))
635 635
636 // Definitions for DCHECK et al. 636 // Definitions for DCHECK et al.
637 637
638 #if DCHECK_IS_ON() 638 #if DCHECK_IS_ON()
639 639
640 // If DCHECK is configured to dump-without-crashing then omit these, so that
641 // anything using them directly will break the build. See crbug.com/596231.
642 #if !defined(DCHECK_IS_DUMP_WITHOUT_CRASH)
643
640 #define COMPACT_GOOGLE_LOG_EX_DCHECK(ClassName, ...) \ 644 #define COMPACT_GOOGLE_LOG_EX_DCHECK(ClassName, ...) \
641 COMPACT_GOOGLE_LOG_EX_FATAL(ClassName , ##__VA_ARGS__) 645 COMPACT_GOOGLE_LOG_EX_FATAL(ClassName , ##__VA_ARGS__)
642 #define COMPACT_GOOGLE_LOG_DCHECK COMPACT_GOOGLE_LOG_FATAL 646 #define COMPACT_GOOGLE_LOG_DCHECK COMPACT_GOOGLE_LOG_FATAL
643 const LogSeverity LOG_DCHECK = LOG_FATAL; 647 const LogSeverity LOG_DCHECK = LOG_FATAL;
644 648
649 #endif // !defined(DCHECK_IS_DUMP_WITHOUT_CRASH)
650
645 #else // DCHECK_IS_ON() 651 #else // DCHECK_IS_ON()
646 652
647 // These are just dummy values. 653 // These are just dummy values.
648 #define COMPACT_GOOGLE_LOG_EX_DCHECK(ClassName, ...) \ 654 #define COMPACT_GOOGLE_LOG_EX_DCHECK(ClassName, ...) \
649 COMPACT_GOOGLE_LOG_EX_INFO(ClassName , ##__VA_ARGS__) 655 COMPACT_GOOGLE_LOG_EX_INFO(ClassName , ##__VA_ARGS__)
650 #define COMPACT_GOOGLE_LOG_DCHECK COMPACT_GOOGLE_LOG_INFO 656 #define COMPACT_GOOGLE_LOG_DCHECK COMPACT_GOOGLE_LOG_INFO
651 const LogSeverity LOG_DCHECK = LOG_INFO; 657 const LogSeverity LOG_DCHECK = LOG_INFO;
652 658
653 #endif // DCHECK_IS_ON() 659 #endif // DCHECK_IS_ON()
654 660
655 // DCHECK et al. make sure to reference |condition| regardless of 661 // DCHECK et al. make sure to reference |condition| regardless of
656 // whether DCHECKs are enabled; this is so that we don't get unused 662 // whether DCHECKs are enabled; this is so that we don't get unused
657 // variable warnings if the only use of a variable is in a DCHECK. 663 // variable warnings if the only use of a variable is in a DCHECK.
658 // This behavior is different from DLOG_IF et al. 664 // This behavior is different from DLOG_IF et al.
659 665
660 #if defined(_PREFAST_) && defined(OS_WIN) 666 #if defined(_PREFAST_) && defined(OS_WIN)
661 // See comments on the previous use of __analysis_assume. 667 // See comments on the previous use of __analysis_assume.
662 668
669 #if defined(DCHECK_IS_DUMP_WITHOUT_CRASH)
670 #error "Only one of _PREFAST_ and DCHECK_IS_DUMP_WITHOUT_CRASH may be set"
671 #endif // defined(DCHECK_IS_DUMP_WITHOUT_CRASH)
672
663 #define DCHECK(condition) \ 673 #define DCHECK(condition) \
664 __analysis_assume(!!(condition)), \ 674 __analysis_assume(!!(condition)), \
665 LAZY_STREAM(LOG_STREAM(DCHECK), false) \ 675 LAZY_STREAM(LOG_STREAM(DCHECK), false) \
666 << "Check failed: " #condition ". " 676 << "Check failed: " #condition ". "
667 677
668 #define DPCHECK(condition) \ 678 #define DPCHECK(condition) \
669 __analysis_assume(!!(condition)), \ 679 __analysis_assume(!!(condition)), \
670 LAZY_STREAM(PLOG_STREAM(DCHECK), false) \ 680 LAZY_STREAM(PLOG_STREAM(DCHECK), false) \
671 << "Check failed: " #condition ". " 681 << "Check failed: " #condition ". "
672 682
673 #else // _PREFAST_ 683 #elif DCHECK_IS_ON() && defined(DCHECK_IS_DUMP_WITHOUT_CRASH)
684 // DCHECK is configured to dump-without-crashing, rather than logging.
685 // See crbug.com/596231.
686
687 BASE_EXPORT void DCheckDumpWithoutCrashing();
688
689 #define DCHECK(condition) \
690 (condition) ? (void)0 : logging::DCheckDumpWithoutCrashing(), \
691 EAT_STREAM_PARAMETERS
692
693 // Since we're uploading a crash dump, not logging, DPCHECK behaves identically.
694 #define DPCHECK(condition) DCHECK(condition)
695
696 #else // DCHECK_IS_ON() && defined(DCHECK_IS_DUMP_WITHOUT_CRASH)
674 697
675 #define DCHECK(condition) \ 698 #define DCHECK(condition) \
676 LAZY_STREAM(LOG_STREAM(DCHECK), DCHECK_IS_ON() ? !(condition) : false) \ 699 LAZY_STREAM(LOG_STREAM(DCHECK), DCHECK_IS_ON() ? !(condition) : false) \
677 << "Check failed: " #condition ". " 700 << "Check failed: " #condition ". "
678 701
679 #define DPCHECK(condition) \ 702 #define DPCHECK(condition) \
680 LAZY_STREAM(PLOG_STREAM(DCHECK), DCHECK_IS_ON() ? !(condition) : false) \ 703 LAZY_STREAM(PLOG_STREAM(DCHECK), DCHECK_IS_ON() ? !(condition) : false) \
681 << "Check failed: " #condition ". " 704 << "Check failed: " #condition ". "
682 705
683 #endif // _PREFAST_ 706 #endif // DCHECK_IS_ON() && defined(DCHECK_IS_DUMP_WITHOUT_CRASH)
684 707
685 // Helper macro for binary operators. 708 // Helper macro for binary operators.
686 // Don't use this macro directly in your code, use DCHECK_EQ et al below. 709 // Don't use this macro directly in your code, use DCHECK_EQ et al below.
710
711 #if DCHECK_IS_ON() && defined(DCHECK_IS_DUMP_WITHOUT_CRASH)
712 // DCHECK is configured to dump-without-crashing, rather than logging.
713 // See crbug.com/596231.
714
715 // Use logging::Check*Impl() to ensure that operator<<()s don't go unused.
716 #define DCHECK_OP(name, op, val1, val2) \
717 DCHECK(logging::Check##name##Impl((val1), (val2), #val1 " " #op " " #val2))
718
719 #else // DCHECK_IS_ON() && defined(DCHECK_IS_DUMP_WITHOUT_CRASH)
720
687 // The 'switch' is used to prevent the 'else' from being ambiguous when the 721 // The 'switch' is used to prevent the 'else' from being ambiguous when the
688 // macro is used in an 'if' clause such as: 722 // macro is used in an 'if' clause such as:
689 // if (a == 1) 723 // if (a == 1)
690 // DCHECK_EQ(2, a); 724 // DCHECK_EQ(2, a);
691 #define DCHECK_OP(name, op, val1, val2) \ 725 #define DCHECK_OP(name, op, val1, val2) \
692 switch (0) case 0: default: \ 726 switch (0) case 0: default: \
693 if (logging::CheckOpResult true_if_passed = \ 727 if (logging::CheckOpResult true_if_passed = \
694 DCHECK_IS_ON() ? \ 728 DCHECK_IS_ON() ? \
695 logging::Check##name##Impl((val1), (val2), \ 729 logging::Check##name##Impl((val1), (val2), \
696 #val1 " " #op " " #val2) : nullptr) \ 730 #val1 " " #op " " #val2) : nullptr) \
697 ; \ 731 ; \
698 else \ 732 else \
699 logging::LogMessage(__FILE__, __LINE__, ::logging::LOG_DCHECK, \ 733 logging::LogMessage(__FILE__, __LINE__, ::logging::LOG_DCHECK, \
700 true_if_passed.message()).stream() 734 true_if_passed.message()).stream()
701 735
736 #endif // DCHECK_IS_ON() && defined(DCHECK_IS_DUMP_WITHOUT_CRASH)
737
702 // Equality/Inequality checks - compare two values, and log a 738 // Equality/Inequality checks - compare two values, and log a
703 // LOG_DCHECK message including the two values when the result is not 739 // LOG_DCHECK message including the two values when the result is not
704 // as expected. The values must have operator<<(ostream, ...) 740 // as expected. The values must have operator<<(ostream, ...)
705 // defined. 741 // defined.
706 // 742 //
707 // You may append to the error message like so: 743 // You may append to the error message like so:
708 // DCHECK_NE(1, 2) << ": The world must be ending!"; 744 // DCHECK_NE(1, 2) << ": The world must be ending!";
709 // 745 //
710 // We are very careful to ensure that each argument is evaluated exactly 746 // We are very careful to ensure that each argument is evaluated exactly
711 // once, and that anything which is legal to pass as a function argument is 747 // once, and that anything which is legal to pass as a function argument is
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
956 #elif NOTIMPLEMENTED_POLICY == 5 992 #elif NOTIMPLEMENTED_POLICY == 5
957 #define NOTIMPLEMENTED() do {\ 993 #define NOTIMPLEMENTED() do {\
958 static bool logged_once = false;\ 994 static bool logged_once = false;\
959 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\ 995 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\
960 logged_once = true;\ 996 logged_once = true;\
961 } while(0);\ 997 } while(0);\
962 EAT_STREAM_PARAMETERS 998 EAT_STREAM_PARAMETERS
963 #endif 999 #endif
964 1000
965 #endif // BASE_LOGGING_H_ 1001 #endif // BASE_LOGGING_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698