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" |
| 70 #if defined(OS_POSIX) | 71 #if defined(OS_POSIX) |
| 71 #include "base/posix/safe_strerror.h" | 72 #include "base/posix/safe_strerror.h" |
| 72 #endif | 73 #endif |
| 73 | 74 |
| 74 #if defined(OS_ANDROID) | 75 #if defined(OS_ANDROID) |
| 75 #include <android/log.h> | 76 #include <android/log.h> |
| 76 #endif | 77 #endif |
| 77 | 78 |
| 78 namespace logging { | 79 namespace logging { |
| 79 | 80 |
| 80 namespace { | 81 namespace { |
| 81 | 82 |
| 82 VlogInfo* g_vlog_info = nullptr; | 83 VlogInfo* g_vlog_info = nullptr; |
| 83 VlogInfo* g_vlog_info_prev = nullptr; | 84 VlogInfo* g_vlog_info_prev = nullptr; |
| 84 | 85 |
| 85 const char* const log_severity_names[LOG_NUM_SEVERITIES] = { | 86 const char* const log_severity_names[] = {"INFO", "WARNING", "ERROR", "FATAL", |
| 86 "INFO", "WARNING", "ERROR", "FATAL" }; | 87 "DUMP"}; |
| 88 static_assert(LOG_NUM_SEVERITIES == arraysize(log_severity_names), | |
| 89 "Incorrect number of log_severity_names"); | |
| 87 | 90 |
| 88 const char* log_severity_name(int severity) { | 91 const char* log_severity_name(int severity) { |
| 89 if (severity >= 0 && severity < LOG_NUM_SEVERITIES) | 92 if (severity >= 0 && severity < LOG_NUM_SEVERITIES) |
| 90 return log_severity_names[severity]; | 93 return log_severity_names[severity]; |
| 91 return "UNKNOWN"; | 94 return "UNKNOWN"; |
| 92 } | 95 } |
| 93 | 96 |
| 94 int g_min_log_level = 0; | 97 int g_min_log_level = 0; |
| 95 | 98 |
| 96 LoggingDestination g_logging_destination = LOG_DEFAULT; | 99 LoggingDestination g_logging_destination = LOG_DEFAULT; |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 116 bool g_log_thread_id = false; | 119 bool g_log_thread_id = false; |
| 117 bool g_log_timestamp = true; | 120 bool g_log_timestamp = true; |
| 118 bool g_log_tickcount = false; | 121 bool g_log_tickcount = false; |
| 119 | 122 |
| 120 // Should we pop up fatal debug messages in a dialog? | 123 // Should we pop up fatal debug messages in a dialog? |
| 121 bool show_error_dialogs = false; | 124 bool show_error_dialogs = false; |
| 122 | 125 |
| 123 // An assert handler override specified by the client to be called instead of | 126 // An assert handler override specified by the client to be called instead of |
| 124 // the debug message dialog and process termination. | 127 // the debug message dialog and process termination. |
| 125 LogAssertHandlerFunction log_assert_handler = nullptr; | 128 LogAssertHandlerFunction log_assert_handler = nullptr; |
| 129 | |
| 126 // A log message handler that gets notified of every log message we process. | 130 // A log message handler that gets notified of every log message we process. |
| 127 LogMessageHandlerFunction log_message_handler = nullptr; | 131 LogMessageHandlerFunction log_message_handler = nullptr; |
| 128 | 132 |
| 129 // Helper functions to wrap platform differences. | 133 // Helper functions to wrap platform differences. |
| 130 | 134 |
| 131 int32_t CurrentProcessId() { | 135 int32_t CurrentProcessId() { |
| 132 #if defined(OS_WIN) | 136 #if defined(OS_WIN) |
| 133 return GetCurrentProcessId(); | 137 return GetCurrentProcessId(); |
| 134 #elif defined(OS_POSIX) | 138 #elif defined(OS_POSIX) |
| 135 return getpid(); | 139 return getpid(); |
| (...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 719 &num_written, | 723 &num_written, |
| 720 nullptr); | 724 nullptr); |
| 721 #else | 725 #else |
| 722 ignore_result(fwrite( | 726 ignore_result(fwrite( |
| 723 str_newline.data(), str_newline.size(), 1, g_log_file)); | 727 str_newline.data(), str_newline.size(), 1, g_log_file)); |
| 724 fflush(g_log_file); | 728 fflush(g_log_file); |
| 725 #endif | 729 #endif |
| 726 } | 730 } |
| 727 } | 731 } |
| 728 | 732 |
| 729 if (severity_ == LOG_FATAL) { | 733 if (severity_ == LOG_FATAL || severity_ == LOG_DUMP) { |
| 730 // Write the log message to the global activity tracker, if running. | 734 // Write the log message to the global activity tracker, if running. |
| 731 base::debug::GlobalActivityTracker* tracker = | 735 base::debug::GlobalActivityTracker* tracker = |
| 732 base::debug::GlobalActivityTracker::Get(); | 736 base::debug::GlobalActivityTracker::Get(); |
| 733 if (tracker) | 737 if (tracker) |
| 734 tracker->RecordLogMessage(str_newline); | 738 tracker->RecordLogMessage(str_newline); |
| 735 | 739 |
| 736 // Ensure the first characters of the string are on the stack so they | 740 // Ensure the first characters of the string are on the stack so they |
| 737 // are contained in minidumps for diagnostic purposes. | 741 // are contained in minidumps for diagnostic purposes. |
| 738 char str_stack[1024]; | 742 char str_stack[1024]; |
| 739 str_newline.copy(str_stack, arraysize(str_stack)); | 743 str_newline.copy(str_stack, arraysize(str_stack)); |
| 740 base::debug::Alias(str_stack); | 744 base::debug::Alias(str_stack); |
| 741 | 745 |
| 742 if (log_assert_handler) { | 746 if (severity_ == LOG_DUMP) { |
| 747 // To ensure we don't risk spamming Crash with dump-on-DCHECK reports we | |
| 748 // log | |
| 749 // only the first[*] DCHECK to fail once DumpWithoutCrashing() is working. | |
| 750 // [*] This is racey, but in the pathological case still only results in | |
| 751 // one | |
| 752 // dump per-racing-thread, rather than our aim of one per-process. | |
| 753 static bool dump_on_dcheck = true; | |
|
Wez
2017/01/15 01:18:41
gab, danakj: Perhaps this should be a global so we
| |
| 754 if (dump_on_dcheck) | |
| 755 dump_on_dcheck = !base::debug::DumpWithoutCrashing(); | |
| 756 return; | |
| 757 } | |
| 758 | |
| 759 else if (log_assert_handler) { | |
| 743 // Make a copy of the string for the handler out of paranoia. | 760 // Make a copy of the string for the handler out of paranoia. |
| 744 log_assert_handler(std::string(stream_.str())); | 761 log_assert_handler(std::string(stream_.str())); |
| 745 } else { | 762 } else { |
| 746 // Don't use the string with the newline, get a fresh version to send to | 763 // 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 | 764 // 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 | 765 // user in release mode. The enduser can't do anything with this |
| 749 // information, and displaying message boxes when the application is | 766 // information, and displaying message boxes when the application is |
| 750 // hosed can cause additional problems. | 767 // hosed can cause additional problems. |
| 751 #ifndef NDEBUG | 768 #ifndef NDEBUG |
| 752 if (!base::debug::BeingDebugged()) { | 769 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) { | 964 BASE_EXPORT void LogErrorNotReached(const char* file, int line) { |
| 948 LogMessage(file, line, LOG_ERROR).stream() | 965 LogMessage(file, line, LOG_ERROR).stream() |
| 949 << "NOTREACHED() hit."; | 966 << "NOTREACHED() hit."; |
| 950 } | 967 } |
| 951 | 968 |
| 952 } // namespace logging | 969 } // namespace logging |
| 953 | 970 |
| 954 std::ostream& std::operator<<(std::ostream& out, const wchar_t* wstr) { | 971 std::ostream& std::operator<<(std::ostream& out, const wchar_t* wstr) { |
| 955 return out << (wstr ? base::WideToUTF8(wstr) : std::string()); | 972 return out << (wstr ? base::WideToUTF8(wstr) : std::string()); |
| 956 } | 973 } |
| OLD | NEW |