Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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) |
|
danakj
2016/03/25 23:21:32
Seems like dumping should win here.
Wez
2016/03/25 23:57:29
I've added an #error to break things explicitly if
| |
| 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) \ |
|
danakj
2016/03/24 00:10:34
But in this case it won't log?
Wez
2016/03/25 23:57:30
Not sure what you mean, but PREFAST + DCHECK_IS_DU
| |
| 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) \ | |
| 686 (condition) ? (void)0 : logging::DCheckDumpWithoutCrashing(), \ | |
|
danakj
2016/03/24 00:10:34
No DCHECK_IS_ON() check here? This will make DCHEC
danakj
2016/03/25 23:21:32
I still think this should be
DCHECK_IS_ON() && (c
Wez
2016/03/25 23:57:29
The patch forces DCHECK on, so the effect is the s
| |
| 687 EAT_STREAM_PARAMETERS | |
| 688 | |
| 689 // Since we're uploading a crash dump, not logging, DPCHECK behaves identically. | |
| 690 #define DPCHECK(condition) DCHECK(condition) | |
| 691 | |
| 673 #else // _PREFAST_ | 692 #else // _PREFAST_ |
| 674 | 693 |
| 675 #define DCHECK(condition) \ | 694 #define DCHECK(condition) \ |
| 676 LAZY_STREAM(LOG_STREAM(DCHECK), DCHECK_IS_ON() ? !(condition) : false) \ | 695 LAZY_STREAM(LOG_STREAM(DCHECK), DCHECK_IS_ON() ? !(condition) : false) \ |
| 677 << "Check failed: " #condition ". " | 696 << "Check failed: " #condition ". " |
| 678 | 697 |
| 679 #define DPCHECK(condition) \ | 698 #define DPCHECK(condition) \ |
| 680 LAZY_STREAM(PLOG_STREAM(DCHECK), DCHECK_IS_ON() ? !(condition) : false) \ | 699 LAZY_STREAM(PLOG_STREAM(DCHECK), DCHECK_IS_ON() ? !(condition) : false) \ |
| 681 << "Check failed: " #condition ". " | 700 << "Check failed: " #condition ". " |
| 682 | 701 |
| 683 #endif // _PREFAST_ | 702 #endif // _PREFAST_ |
| 684 | 703 |
| 685 // Helper macro for binary operators. | 704 // Helper macro for binary operators. |
| 686 // Don't use this macro directly in your code, use DCHECK_EQ et al below. | 705 // Don't use this macro directly in your code, use DCHECK_EQ et al below. |
| 706 | |
| 707 #if defined(DCHECK_IS_DUMP_WITHOUT_CRASH) | |
| 708 // DCHECK is configured to dump-without-crashing, rather than logging. | |
| 709 // See crbug.com/596231. | |
| 710 | |
| 711 // Use logging::Check*Impl() to ensure that operator<<()s don't go unused. | |
|
danakj
2016/03/25 23:21:32
Didn't you use DCHECK() to ensure that rather? DCH
Wez
2016/03/25 23:57:29
No; you could implement this as DCHECK((val1) op (
| |
| 712 #define DCHECK_OP(name, op, val1, val2) \ | |
| 713 DCHECK(logging::Check##name##Impl((val1), (val2), #val1 " " #op " " #val2)) | |
|
danakj
2016/03/24 00:10:34
No DCHECK_IS_ON() check here?
Wez
2016/03/25 23:57:29
Added a #if block check instead.
| |
| 714 | |
| 715 #else | |
| 716 | |
| 687 // The 'switch' is used to prevent the 'else' from being ambiguous when the | 717 // The 'switch' is used to prevent the 'else' from being ambiguous when the |
| 688 // macro is used in an 'if' clause such as: | 718 // macro is used in an 'if' clause such as: |
| 689 // if (a == 1) | 719 // if (a == 1) |
| 690 // DCHECK_EQ(2, a); | 720 // DCHECK_EQ(2, a); |
| 691 #define DCHECK_OP(name, op, val1, val2) \ | 721 #define DCHECK_OP(name, op, val1, val2) \ |
| 692 switch (0) case 0: default: \ | 722 switch (0) case 0: default: \ |
| 693 if (logging::CheckOpResult true_if_passed = \ | 723 if (logging::CheckOpResult true_if_passed = \ |
| 694 DCHECK_IS_ON() ? \ | 724 DCHECK_IS_ON() ? \ |
| 695 logging::Check##name##Impl((val1), (val2), \ | 725 logging::Check##name##Impl((val1), (val2), \ |
| 696 #val1 " " #op " " #val2) : nullptr) \ | 726 #val1 " " #op " " #val2) : nullptr) \ |
| 697 ; \ | 727 ; \ |
| 698 else \ | 728 else \ |
| 699 logging::LogMessage(__FILE__, __LINE__, ::logging::LOG_DCHECK, \ | 729 logging::LogMessage(__FILE__, __LINE__, ::logging::LOG_DCHECK, \ |
| 700 true_if_passed.message()).stream() | 730 true_if_passed.message()).stream() |
| 701 | 731 |
| 732 #endif | |
|
danakj
2016/03/25 23:21:32
comment what you're ending
Wez
2016/03/25 23:57:29
Done.
| |
| 733 | |
| 702 // Equality/Inequality checks - compare two values, and log a | 734 // Equality/Inequality checks - compare two values, and log a |
| 703 // LOG_DCHECK message including the two values when the result is not | 735 // LOG_DCHECK message including the two values when the result is not |
| 704 // as expected. The values must have operator<<(ostream, ...) | 736 // as expected. The values must have operator<<(ostream, ...) |
| 705 // defined. | 737 // defined. |
| 706 // | 738 // |
| 707 // You may append to the error message like so: | 739 // You may append to the error message like so: |
| 708 // DCHECK_NE(1, 2) << ": The world must be ending!"; | 740 // DCHECK_NE(1, 2) << ": The world must be ending!"; |
| 709 // | 741 // |
| 710 // We are very careful to ensure that each argument is evaluated exactly | 742 // 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 | 743 // 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 Loading... | |
| 956 #elif NOTIMPLEMENTED_POLICY == 5 | 988 #elif NOTIMPLEMENTED_POLICY == 5 |
| 957 #define NOTIMPLEMENTED() do {\ | 989 #define NOTIMPLEMENTED() do {\ |
| 958 static bool logged_once = false;\ | 990 static bool logged_once = false;\ |
| 959 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\ | 991 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\ |
| 960 logged_once = true;\ | 992 logged_once = true;\ |
| 961 } while(0);\ | 993 } while(0);\ |
| 962 EAT_STREAM_PARAMETERS | 994 EAT_STREAM_PARAMETERS |
| 963 #endif | 995 #endif |
| 964 | 996 |
| 965 #endif // BASE_LOGGING_H_ | 997 #endif // BASE_LOGGING_H_ |
| OLD | NEW |