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

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: Fix conditional for DCheckDumpWithoutCrashing Created 4 years, 9 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
663 #define DCHECK(condition) \ 669 #define DCHECK(condition) \
664 __analysis_assume(!!(condition)), \ 670 __analysis_assume(!!(condition)), \
665 LAZY_STREAM(LOG_STREAM(DCHECK), false) \ 671 LAZY_STREAM(LOG_STREAM(DCHECK), false) \
666 << "Check failed: " #condition ". " 672 << "Check failed: " #condition ". "
667 673
668 #define DPCHECK(condition) \ 674 #define DPCHECK(condition) \
669 __analysis_assume(!!(condition)), \ 675 __analysis_assume(!!(condition)), \
670 LAZY_STREAM(PLOG_STREAM(DCHECK), false) \ 676 LAZY_STREAM(PLOG_STREAM(DCHECK), false) \
671 << "Check failed: " #condition ". " 677 << "Check failed: " #condition ". "
672 678
679 #elif defined(DCHECK_IS_DUMP_WITHOUT_CRASH)
680 // DCHECK is configured to dump-without-crashing, rather than logging.
681 // See crbug.com/596231.
682
683 BASE_EXPORT void DCheckDumpWithoutCrashing();
684
685 #define DCHECK(condition) (condition) ? (void) 0 : logging::DCheckDumpWithoutCr ashing(), EAT_STREAM_PARAMETERS
scottmg 2016/03/21 17:28:12 extra spaces and 80col
Wez 2016/03/23 04:18:13 Done.
686
687 // Since we're uploading a crash dump, not logging, DPCHECK behaves identically.
688 #define DPCHECK(condition) DCHECK(condition)
689
673 #else // _PREFAST_ 690 #else // _PREFAST_
674 691
675 #define DCHECK(condition) \ 692 #define DCHECK(condition) \
676 LAZY_STREAM(LOG_STREAM(DCHECK), DCHECK_IS_ON() ? !(condition) : false) \ 693 LAZY_STREAM(LOG_STREAM(DCHECK), DCHECK_IS_ON() ? !(condition) : false) \
677 << "Check failed: " #condition ". " 694 << "Check failed: " #condition ". "
678 695
679 #define DPCHECK(condition) \ 696 #define DPCHECK(condition) \
680 LAZY_STREAM(PLOG_STREAM(DCHECK), DCHECK_IS_ON() ? !(condition) : false) \ 697 LAZY_STREAM(PLOG_STREAM(DCHECK), DCHECK_IS_ON() ? !(condition) : false) \
681 << "Check failed: " #condition ". " 698 << "Check failed: " #condition ". "
682 699
683 #endif // _PREFAST_ 700 #endif // _PREFAST_
684 701
685 // Helper macro for binary operators. 702 // Helper macro for binary operators.
686 // Don't use this macro directly in your code, use DCHECK_EQ et al below. 703 // Don't use this macro directly in your code, use DCHECK_EQ et al below.
704
705 #if defined(DCHECK_IS_DUMP_WITHOUT_CRASH)
706 // DCHECK is configured to dump-without-crashing, rather than logging.
707 // See crbug.com/596231.
708
709 // Use logging::Check*Impl() to ensure that operator<<()s don't go unused.
710 #define DCHECK_OP(name, op, val1, val2) DCHECK(logging::Check##name##Impl((val1) , (val2), #val1 " " #op " " #val2))
scottmg 2016/03/21 17:28:12 80col
Wez 2016/03/23 04:18:13 Done. (git cl format does macros - awesome!)
711
712 #else
713
687 // The 'switch' is used to prevent the 'else' from being ambiguous when the 714 // The 'switch' is used to prevent the 'else' from being ambiguous when the
688 // macro is used in an 'if' clause such as: 715 // macro is used in an 'if' clause such as:
689 // if (a == 1) 716 // if (a == 1)
690 // DCHECK_EQ(2, a); 717 // DCHECK_EQ(2, a);
691 #define DCHECK_OP(name, op, val1, val2) \ 718 #define DCHECK_OP(name, op, val1, val2) \
692 switch (0) case 0: default: \ 719 switch (0) case 0: default: \
693 if (logging::CheckOpResult true_if_passed = \ 720 if (logging::CheckOpResult true_if_passed = \
694 DCHECK_IS_ON() ? \ 721 DCHECK_IS_ON() ? \
695 logging::Check##name##Impl((val1), (val2), \ 722 logging::Check##name##Impl((val1), (val2), \
696 #val1 " " #op " " #val2) : nullptr) \ 723 #val1 " " #op " " #val2) : nullptr) \
697 ; \ 724 ; \
698 else \ 725 else \
699 logging::LogMessage(__FILE__, __LINE__, ::logging::LOG_DCHECK, \ 726 logging::LogMessage(__FILE__, __LINE__, ::logging::LOG_DCHECK, \
700 true_if_passed.message()).stream() 727 true_if_passed.message()).stream()
701 728
729 #endif
730
702 // Equality/Inequality checks - compare two values, and log a 731 // Equality/Inequality checks - compare two values, and log a
703 // LOG_DCHECK message including the two values when the result is not 732 // LOG_DCHECK message including the two values when the result is not
704 // as expected. The values must have operator<<(ostream, ...) 733 // as expected. The values must have operator<<(ostream, ...)
705 // defined. 734 // defined.
706 // 735 //
707 // You may append to the error message like so: 736 // You may append to the error message like so:
708 // DCHECK_NE(1, 2) << ": The world must be ending!"; 737 // DCHECK_NE(1, 2) << ": The world must be ending!";
709 // 738 //
710 // We are very careful to ensure that each argument is evaluated exactly 739 // 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 740 // 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 985 #elif NOTIMPLEMENTED_POLICY == 5
957 #define NOTIMPLEMENTED() do {\ 986 #define NOTIMPLEMENTED() do {\
958 static bool logged_once = false;\ 987 static bool logged_once = false;\
959 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\ 988 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\
960 logged_once = true;\ 989 logged_once = true;\
961 } while(0);\ 990 } while(0);\
962 EAT_STREAM_PARAMETERS 991 EAT_STREAM_PARAMETERS
963 #endif 992 #endif
964 993
965 #endif // BASE_LOGGING_H_ 994 #endif // BASE_LOGGING_H_
OLDNEW
« no previous file with comments | « base/debug/dump_without_crashing.cc ('k') | base/logging.cc » ('j') | base/logging.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698