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 <cassert> | 8 #include <cassert> |
9 #include <string> | 9 #include <string> |
10 #include <cstring> | 10 #include <cstring> |
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 // into a macro (like __debugbreak() on Windows). | 443 // into a macro (like __debugbreak() on Windows). |
444 #define CHECK(condition) \ | 444 #define CHECK(condition) \ |
445 !(condition) ? ::base::debug::BreakDebugger() : EAT_STREAM_PARAMETERS | 445 !(condition) ? ::base::debug::BreakDebugger() : EAT_STREAM_PARAMETERS |
446 | 446 |
447 #define PCHECK(condition) CHECK(condition) | 447 #define PCHECK(condition) CHECK(condition) |
448 | 448 |
449 #define CHECK_OP(name, op, val1, val2) CHECK((val1) op (val2)) | 449 #define CHECK_OP(name, op, val1, val2) CHECK((val1) op (val2)) |
450 | 450 |
451 #else | 451 #else |
452 | 452 |
| 453 #if defined(_PREFAST_) && defined(OS_WIN) |
| 454 // Use __analysis_assume to tell the VC++ static analysis engine that |
| 455 // assert conditions are true, to suppress warnings. The LAZY_STREAM |
| 456 // parameter doesn't reference 'condition' in /analyze builds because |
| 457 // this evaluation confuses /analyze. The !! before condition is because |
| 458 // __analysis_assume gets confused on some conditions: |
| 459 // http://randomascii.wordpress.com/2011/09/13/analyze-for-visual-studio-the-ugl
y-part-5/ |
| 460 |
| 461 #define CHECK(condition) \ |
| 462 __analysis_assume(!!(condition)), \ |
| 463 LAZY_STREAM(LOG_STREAM(FATAL), false) \ |
| 464 << "Check failed: " #condition ". " |
| 465 |
| 466 #define PCHECK(condition) \ |
| 467 __analysis_assume(!!(condition)), \ |
| 468 LAZY_STREAM(PLOG_STREAM(FATAL), false) \ |
| 469 << "Check failed: " #condition ". " |
| 470 |
| 471 #else // _PREFAST_ |
| 472 |
453 #define CHECK(condition) \ | 473 #define CHECK(condition) \ |
454 LAZY_STREAM(LOG_STREAM(FATAL), !(condition)) \ | 474 LAZY_STREAM(LOG_STREAM(FATAL), !(condition)) \ |
455 << "Check failed: " #condition ". " | 475 << "Check failed: " #condition ". " |
456 | 476 |
457 #define PCHECK(condition) \ | 477 #define PCHECK(condition) \ |
458 LAZY_STREAM(PLOG_STREAM(FATAL), !(condition)) \ | 478 LAZY_STREAM(PLOG_STREAM(FATAL), !(condition)) \ |
459 << "Check failed: " #condition ". " | 479 << "Check failed: " #condition ". " |
460 | 480 |
| 481 #endif // _PREFAST_ |
| 482 |
461 // Helper macro for binary operators. | 483 // Helper macro for binary operators. |
462 // Don't use this macro directly in your code, use CHECK_EQ et al below. | 484 // Don't use this macro directly in your code, use CHECK_EQ et al below. |
463 // | 485 // |
464 // TODO(akalin): Rewrite this so that constructs like if (...) | 486 // TODO(akalin): Rewrite this so that constructs like if (...) |
465 // CHECK_EQ(...) else { ... } work properly. | 487 // CHECK_EQ(...) else { ... } work properly. |
466 #define CHECK_OP(name, op, val1, val2) \ | 488 #define CHECK_OP(name, op, val1, val2) \ |
467 if (std::string* _result = \ | 489 if (std::string* _result = \ |
468 logging::Check##name##Impl((val1), (val2), \ | 490 logging::Check##name##Impl((val1), (val2), \ |
469 #val1 " " #op " " #val2)) \ | 491 #val1 " " #op " " #val2)) \ |
470 logging::LogMessage(__FILE__, __LINE__, _result).stream() | 492 logging::LogMessage(__FILE__, __LINE__, _result).stream() |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
609 #define COMPACT_GOOGLE_LOG_DCHECK COMPACT_GOOGLE_LOG_INFO | 631 #define COMPACT_GOOGLE_LOG_DCHECK COMPACT_GOOGLE_LOG_INFO |
610 const LogSeverity LOG_DCHECK = LOG_INFO; | 632 const LogSeverity LOG_DCHECK = LOG_INFO; |
611 | 633 |
612 #endif // DCHECK_IS_ON | 634 #endif // DCHECK_IS_ON |
613 | 635 |
614 // DCHECK et al. make sure to reference |condition| regardless of | 636 // DCHECK et al. make sure to reference |condition| regardless of |
615 // whether DCHECKs are enabled; this is so that we don't get unused | 637 // whether DCHECKs are enabled; this is so that we don't get unused |
616 // variable warnings if the only use of a variable is in a DCHECK. | 638 // variable warnings if the only use of a variable is in a DCHECK. |
617 // This behavior is different from DLOG_IF et al. | 639 // This behavior is different from DLOG_IF et al. |
618 | 640 |
| 641 #if defined(_PREFAST_) && defined(OS_WIN) |
| 642 // See comments on the previous use of __analysis_assume. |
| 643 |
| 644 #define DCHECK(condition) \ |
| 645 __analysis_assume(!!(condition)), \ |
| 646 LAZY_STREAM(LOG_STREAM(DCHECK), false) \ |
| 647 << "Check failed: " #condition ". " |
| 648 |
| 649 #define DPCHECK(condition) \ |
| 650 __analysis_assume(!!(condition)), \ |
| 651 LAZY_STREAM(PLOG_STREAM(DCHECK), false) \ |
| 652 << "Check failed: " #condition ". " |
| 653 |
| 654 #else // _PREFAST_ |
| 655 |
619 #define DCHECK(condition) \ | 656 #define DCHECK(condition) \ |
620 LAZY_STREAM(LOG_STREAM(DCHECK), DCHECK_IS_ON ? !(condition) : false) \ | 657 LAZY_STREAM(LOG_STREAM(DCHECK), DCHECK_IS_ON ? !(condition) : false) \ |
621 << "Check failed: " #condition ". " | 658 << "Check failed: " #condition ". " |
622 | 659 |
623 #define DPCHECK(condition) \ | 660 #define DPCHECK(condition) \ |
624 LAZY_STREAM(PLOG_STREAM(DCHECK), DCHECK_IS_ON ? !(condition) : false) \ | 661 LAZY_STREAM(PLOG_STREAM(DCHECK), DCHECK_IS_ON ? !(condition) : false) \ |
625 << "Check failed: " #condition ". " | 662 << "Check failed: " #condition ". " |
626 | 663 |
| 664 #endif // _PREFAST_ |
| 665 |
627 // Helper macro for binary operators. | 666 // Helper macro for binary operators. |
628 // Don't use this macro directly in your code, use DCHECK_EQ et al below. | 667 // Don't use this macro directly in your code, use DCHECK_EQ et al below. |
629 #define DCHECK_OP(name, op, val1, val2) \ | 668 #define DCHECK_OP(name, op, val1, val2) \ |
630 if (DCHECK_IS_ON) \ | 669 if (DCHECK_IS_ON) \ |
631 if (std::string* _result = \ | 670 if (std::string* _result = \ |
632 logging::Check##name##Impl((val1), (val2), \ | 671 logging::Check##name##Impl((val1), (val2), \ |
633 #val1 " " #op " " #val2)) \ | 672 #val1 " " #op " " #val2)) \ |
634 logging::LogMessage( \ | 673 logging::LogMessage( \ |
635 __FILE__, __LINE__, ::logging::LOG_DCHECK, \ | 674 __FILE__, __LINE__, ::logging::LOG_DCHECK, \ |
636 _result).stream() | 675 _result).stream() |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
889 #elif NOTIMPLEMENTED_POLICY == 5 | 928 #elif NOTIMPLEMENTED_POLICY == 5 |
890 #define NOTIMPLEMENTED() do {\ | 929 #define NOTIMPLEMENTED() do {\ |
891 static bool logged_once = false;\ | 930 static bool logged_once = false;\ |
892 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\ | 931 LOG_IF(ERROR, !logged_once) << NOTIMPLEMENTED_MSG;\ |
893 logged_once = true;\ | 932 logged_once = true;\ |
894 } while(0);\ | 933 } while(0);\ |
895 EAT_STREAM_PARAMETERS | 934 EAT_STREAM_PARAMETERS |
896 #endif | 935 #endif |
897 | 936 |
898 #endif // BASE_LOGGING_H_ | 937 #endif // BASE_LOGGING_H_ |
OLD | NEW |