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 #include "base/logging.h" | 5 #include "base/logging.h" |
| 6 | 6 |
| 7 #include <limits.h> | 7 #include <limits.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include "base/debug/activity_tracker.h" | 10 #include "base/debug/activity_tracker.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 50 #include <cstring> | 50 #include <cstring> |
| 51 #include <ctime> | 51 #include <ctime> |
| 52 #include <iomanip> | 52 #include <iomanip> |
| 53 #include <ostream> | 53 #include <ostream> |
| 54 #include <string> | 54 #include <string> |
| 55 | 55 |
| 56 #include "base/base_switches.h" | 56 #include "base/base_switches.h" |
| 57 #include "base/command_line.h" | 57 #include "base/command_line.h" |
| 58 #include "base/debug/alias.h" | 58 #include "base/debug/alias.h" |
| 59 #include "base/debug/debugger.h" | 59 #include "base/debug/debugger.h" |
| 60 #include "base/debug/dump_without_crashing.h" | |
| 60 #include "base/debug/stack_trace.h" | 61 #include "base/debug/stack_trace.h" |
| 61 #include "base/posix/eintr_wrapper.h" | 62 #include "base/posix/eintr_wrapper.h" |
| 62 #include "base/strings/string_piece.h" | 63 #include "base/strings/string_piece.h" |
| 63 #include "base/strings/string_util.h" | 64 #include "base/strings/string_util.h" |
| 64 #include "base/strings/stringprintf.h" | 65 #include "base/strings/stringprintf.h" |
| 65 #include "base/strings/sys_string_conversions.h" | 66 #include "base/strings/sys_string_conversions.h" |
| 66 #include "base/strings/utf_string_conversions.h" | 67 #include "base/strings/utf_string_conversions.h" |
| 67 #include "base/synchronization/lock_impl.h" | 68 #include "base/synchronization/lock_impl.h" |
| 68 #include "base/threading/platform_thread.h" | 69 #include "base/threading/platform_thread.h" |
| 69 #include "base/vlog.h" | 70 #include "base/vlog.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 116 bool g_log_thread_id = false; | 117 bool g_log_thread_id = false; |
| 117 bool g_log_timestamp = true; | 118 bool g_log_timestamp = true; |
| 118 bool g_log_tickcount = false; | 119 bool g_log_tickcount = false; |
| 119 | 120 |
| 120 // Should we pop up fatal debug messages in a dialog? | 121 // Should we pop up fatal debug messages in a dialog? |
| 121 bool show_error_dialogs = false; | 122 bool show_error_dialogs = false; |
| 122 | 123 |
| 123 // An assert handler override specified by the client to be called instead of | 124 // An assert handler override specified by the client to be called instead of |
| 124 // the debug message dialog and process termination. | 125 // the debug message dialog and process termination. |
| 125 LogAssertHandlerFunction log_assert_handler = nullptr; | 126 LogAssertHandlerFunction log_assert_handler = nullptr; |
| 127 | |
| 126 // A log message handler that gets notified of every log message we process. | 128 // A log message handler that gets notified of every log message we process. |
| 127 LogMessageHandlerFunction log_message_handler = nullptr; | 129 LogMessageHandlerFunction log_message_handler = nullptr; |
| 128 | 130 |
| 129 // Helper functions to wrap platform differences. | 131 // Helper functions to wrap platform differences. |
| 130 | 132 |
| 131 int32_t CurrentProcessId() { | 133 int32_t CurrentProcessId() { |
| 132 #if defined(OS_WIN) | 134 #if defined(OS_WIN) |
| 133 return GetCurrentProcessId(); | 135 return GetCurrentProcessId(); |
| 134 #elif defined(OS_POSIX) | 136 #elif defined(OS_POSIX) |
| 135 return getpid(); | 137 return getpid(); |
| (...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 719 &num_written, | 721 &num_written, |
| 720 nullptr); | 722 nullptr); |
| 721 #else | 723 #else |
| 722 ignore_result(fwrite( | 724 ignore_result(fwrite( |
| 723 str_newline.data(), str_newline.size(), 1, g_log_file)); | 725 str_newline.data(), str_newline.size(), 1, g_log_file)); |
| 724 fflush(g_log_file); | 726 fflush(g_log_file); |
| 725 #endif | 727 #endif |
| 726 } | 728 } |
| 727 } | 729 } |
| 728 | 730 |
| 729 if (severity_ == LOG_FATAL) { | 731 if (severity_ == LOG_FATAL || severity_ == LOG_DUMP) { |
| 730 // Write the log message to the global activity tracker, if running. | 732 // Write the log message to the global activity tracker, if running. |
| 731 base::debug::GlobalActivityTracker* tracker = | 733 base::debug::GlobalActivityTracker* tracker = |
| 732 base::debug::GlobalActivityTracker::Get(); | 734 base::debug::GlobalActivityTracker::Get(); |
| 733 if (tracker) | 735 if (tracker) |
| 734 tracker->RecordLogMessage(str_newline); | 736 tracker->RecordLogMessage(str_newline); |
| 735 | 737 |
| 736 // Ensure the first characters of the string are on the stack so they | 738 // Ensure the first characters of the string are on the stack so they |
| 737 // are contained in minidumps for diagnostic purposes. | 739 // are contained in minidumps for diagnostic purposes. |
| 738 char str_stack[1024]; | 740 char str_stack[1024]; |
| 739 str_newline.copy(str_stack, arraysize(str_stack)); | 741 str_newline.copy(str_stack, arraysize(str_stack)); |
| 740 base::debug::Alias(str_stack); | 742 base::debug::Alias(str_stack); |
| 741 | 743 |
| 742 if (log_assert_handler) { | 744 if (severity_ == LOG_DUMP) { |
|
Wez
2016/12/19 23:57:46
Q: Is it more or less readable to have LOG_DUMP im
| |
| 745 // To ensure we don't risk spamming Crash with dump-on-DCHECK reports we | |
| 746 // log | |
| 747 // only the first[*] DCHECK to fail once DumpWithoutCrashing() is working. | |
| 748 // [*] This is racey, but in the pathological case still only results in | |
| 749 // one | |
| 750 // dump per-racing-thread, rather than our aim of one per-process. | |
|
Wez
2016/12/19 23:57:46
Note to self: Fix comment line-wrap.
| |
| 751 static bool dump_on_dcheck = true; | |
| 752 if (dump_on_dcheck) | |
| 753 dump_on_dcheck = !base::debug::DumpWithoutCrashing(); | |
| 754 return; | |
| 755 } | |
| 756 | |
| 757 | |
| 758 else if (log_assert_handler) { | |
| 743 // Make a copy of the string for the handler out of paranoia. | 759 // Make a copy of the string for the handler out of paranoia. |
| 744 log_assert_handler(std::string(stream_.str())); | 760 log_assert_handler(std::string(stream_.str())); |
| 745 } else { | 761 } else { |
| 746 // Don't use the string with the newline, get a fresh version to send to | 762 // Don't use the string with the newline, get a fresh version to send to |
| 747 // the debug message process. We also don't display assertions to the | 763 // the debug message process. We also don't display assertions to the |
| 748 // user in release mode. The enduser can't do anything with this | 764 // user in release mode. The enduser can't do anything with this |
| 749 // information, and displaying message boxes when the application is | 765 // information, and displaying message boxes when the application is |
| 750 // hosed can cause additional problems. | 766 // hosed can cause additional problems. |
| 751 #ifndef NDEBUG | 767 #ifndef NDEBUG |
| 752 if (!base::debug::BeingDebugged()) { | 768 if (!base::debug::BeingDebugged()) { |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 947 BASE_EXPORT void LogErrorNotReached(const char* file, int line) { | 963 BASE_EXPORT void LogErrorNotReached(const char* file, int line) { |
| 948 LogMessage(file, line, LOG_ERROR).stream() | 964 LogMessage(file, line, LOG_ERROR).stream() |
| 949 << "NOTREACHED() hit."; | 965 << "NOTREACHED() hit."; |
| 950 } | 966 } |
| 951 | 967 |
| 952 } // namespace logging | 968 } // namespace logging |
| 953 | 969 |
| 954 std::ostream& std::operator<<(std::ostream& out, const wchar_t* wstr) { | 970 std::ostream& std::operator<<(std::ostream& out, const wchar_t* wstr) { |
| 955 return out << (wstr ? base::WideToUTF8(wstr) : std::string()); | 971 return out << (wstr ? base::WideToUTF8(wstr) : std::string()); |
| 956 } | 972 } |
| OLD | NEW |