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

Unified Diff: base/logging.cc

Issue 2638763004: Report CHECK/DCHECK to test launcher summary output. (Closed)
Patch Set: Add comment. Fix missed usage of SetLogAssertHandler. Created 3 years, 11 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
Index: base/logging.cc
diff --git a/base/logging.cc b/base/logging.cc
index cea6edae4a37cef2519ff32045c46c0a3c73e4d0..7da6bf19041d7f9524adf6b6b7190658dc8c4406 100644
--- a/base/logging.cc
+++ b/base/logging.cc
@@ -7,6 +7,7 @@
#include <limits.h>
#include <stdint.h>
+#include "base/callback.h"
#include "base/debug/activity_tracker.h"
#include "base/macros.h"
#include "build/build_config.h"
@@ -121,8 +122,15 @@ bool g_log_tickcount = false;
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;
+// the debug message dialog and process termination. Assert handlers are stored
+// in stack to allow overriding and restoring.
+struct LogAssertHandlerStackItem {
+ LogAssertHandlerStackItem* next;
+ LogAssertHandlerFunction handler;
+};
+
+LogAssertHandlerStackItem* log_assert_handler_stack = nullptr;
+
// A log message handler that gets notified of every log message we process.
LogMessageHandlerFunction log_message_handler = nullptr;
@@ -340,6 +348,27 @@ void CloseLogFileUnlocked() {
g_log_file = nullptr;
}
+void PushLogAssertHandler(LogAssertHandlerFunction handler) {
+ LogAssertHandlerStackItem* stack_item = new LogAssertHandlerStackItem;
+ stack_item->handler = handler;
+ stack_item->next = log_assert_handler_stack;
+ log_assert_handler_stack = stack_item;
+}
+
+void PopLogAssertHandler() {
+ LogAssertHandlerStackItem* stack_item = log_assert_handler_stack;
+ if (stack_item) {
+ log_assert_handler_stack = stack_item->next;
+ delete stack_item;
+ }
+}
+
+LogAssertHandlerFunction GetLogAssertHandler() {
+ if (log_assert_handler_stack)
+ return log_assert_handler_stack->handler;
+ return LogAssertHandlerFunction();
+}
+
} // namespace
// This is never instantiated, it's just used for EAT_STREAM_PARAMETERS to have
@@ -445,7 +474,11 @@ void SetShowErrorDialogs(bool enable_dialogs) {
}
void SetLogAssertHandler(LogAssertHandlerFunction handler) {
- log_assert_handler = handler;
+ PushLogAssertHandler(handler);
Paweł Hajdan Jr. 2017/01/27 17:19:43 Why create separate functions instead of putting t
alex-ac 2017/02/11 20:12:19 Done.
+}
+
+void ResetLogAssertHandler() {
+ PopLogAssertHandler();
}
void SetLogMessageHandler(LogMessageHandlerFunction handler) {
@@ -531,6 +564,7 @@ LogMessage::LogMessage(const char* file, int line, LogSeverity severity,
}
LogMessage::~LogMessage() {
+ size_t stack_start = stream_.str().length();
#if !defined(OFFICIAL_BUILD) && !defined(OS_NACL) && !defined(__UCLIBC__)
if (severity_ == LOG_FATAL && !base::debug::BeingDebugged()) {
// Include a stack trace on a fatal, unless a debugger is attached.
@@ -739,9 +773,11 @@ LogMessage::~LogMessage() {
str_newline.copy(str_stack, arraysize(str_stack));
base::debug::Alias(str_stack);
+ LogAssertHandlerFunction log_assert_handler = GetLogAssertHandler();
if (log_assert_handler) {
// Make a copy of the string for the handler out of paranoia.
- log_assert_handler(std::string(stream_.str()));
+ log_assert_handler.Run(file_, line_, message_start_, stack_start,
Paweł Hajdan Jr. 2017/01/27 17:19:44 Would it make sense to execute all handlers on the
alex-ac 2017/02/11 20:12:19 No there's some code that adds new handler to prev
+ std::string(stream_.str()));
} else {
// Don't use the string with the newline, get a fresh version to send to
// the debug message process. We also don't display assertions to the

Powered by Google App Engine
This is Rietveld 408576698