Index: base/logging.cc |
diff --git a/base/logging.cc b/base/logging.cc |
index cea6edae4a37cef2519ff32045c46c0a3c73e4d0..15ab4735b7114ed2c60585e3109e340027b744d1 100644 |
--- a/base/logging.cc |
+++ b/base/logging.cc |
@@ -57,6 +57,7 @@ typedef pthread_mutex_t* MutexHandle; |
#include "base/command_line.h" |
#include "base/debug/alias.h" |
#include "base/debug/debugger.h" |
+#include "base/debug/dump_without_crashing.h" |
#include "base/debug/stack_trace.h" |
#include "base/posix/eintr_wrapper.h" |
#include "base/strings/string_piece.h" |
@@ -82,8 +83,10 @@ namespace { |
VlogInfo* g_vlog_info = nullptr; |
VlogInfo* g_vlog_info_prev = nullptr; |
-const char* const log_severity_names[LOG_NUM_SEVERITIES] = { |
- "INFO", "WARNING", "ERROR", "FATAL" }; |
+const char* const log_severity_names[] = {"INFO", "WARNING", "ERROR", "FATAL", |
+ "DUMP"}; |
+static_assert(LOG_NUM_SEVERITIES == arraysize(log_severity_names), |
+ "Incorrect number of log_severity_names"); |
const char* log_severity_name(int severity) { |
if (severity >= 0 && severity < LOG_NUM_SEVERITIES) |
@@ -123,6 +126,7 @@ bool show_error_dialogs = false; |
// An assert handler override specified by the client to be called instead of |
// the debug message dialog and process termination. |
LogAssertHandlerFunction log_assert_handler = nullptr; |
+ |
// A log message handler that gets notified of every log message we process. |
LogMessageHandlerFunction log_message_handler = nullptr; |
@@ -726,7 +730,7 @@ LogMessage::~LogMessage() { |
} |
} |
- if (severity_ == LOG_FATAL) { |
+ if (severity_ == LOG_FATAL || severity_ == LOG_DUMP) { |
// Write the log message to the global activity tracker, if running. |
base::debug::GlobalActivityTracker* tracker = |
base::debug::GlobalActivityTracker::Get(); |
@@ -739,7 +743,20 @@ LogMessage::~LogMessage() { |
str_newline.copy(str_stack, arraysize(str_stack)); |
base::debug::Alias(str_stack); |
- if (log_assert_handler) { |
+ if (severity_ == LOG_DUMP) { |
+ // To ensure we don't risk spamming Crash with dump-on-DCHECK reports we |
+ // log |
+ // only the first[*] DCHECK to fail once DumpWithoutCrashing() is working. |
+ // [*] This is racey, but in the pathological case still only results in |
+ // one |
+ // dump per-racing-thread, rather than our aim of one per-process. |
+ static bool dump_on_dcheck = true; |
Wez
2017/01/15 01:18:41
gab, danakj: Perhaps this should be a global so we
|
+ if (dump_on_dcheck) |
+ dump_on_dcheck = !base::debug::DumpWithoutCrashing(); |
+ return; |
+ } |
+ |
+ else if (log_assert_handler) { |
// Make a copy of the string for the handler out of paranoia. |
log_assert_handler(std::string(stream_.str())); |
} else { |