Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(573)

Unified Diff: base/logging.cc

Issue 2288473002: Implement Dump-on-DCHECK (via a new LogSeverity). (Closed)
Patch Set: Pull the Official Windows build default in, and rebase Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/logging.h ('k') | base/logging_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/logging.cc
diff --git a/base/logging.cc b/base/logging.cc
index cea6edae4a37cef2519ff32045c46c0a3c73e4d0..f9f07ade9f8c6446b62115f0665395da252f7fe8 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,19 @@ 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 one per-process.
+ static bool dump_on_dcheck = true;
+ 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 {
« no previous file with comments | « base/logging.h ('k') | base/logging_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698