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

Unified Diff: base/logging.cc

Issue 2638763004: Report CHECK/DCHECK to test launcher summary output. (Closed)
Patch Set: Fix error on ios. Created 3 years, 9 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..954c07c6520be93678860df76db5387790c885e4 100644
--- a/base/logging.cc
+++ b/base/logging.cc
@@ -7,12 +7,12 @@
#include <limits.h>
#include <stdint.h>
-#include "base/debug/activity_tracker.h"
#include "base/macros.h"
#include "build/build_config.h"
#if defined(OS_WIN)
#include <io.h>
+#include <windows.h>
typedef HANDLE FileHandle;
typedef HANDLE MutexHandle;
// Windows warns on using write(). It prefers _write().
@@ -51,13 +51,17 @@ typedef pthread_mutex_t* MutexHandle;
#include <ctime>
#include <iomanip>
#include <ostream>
+#include <stack>
#include <string>
#include "base/base_switches.h"
+#include "base/callback.h"
#include "base/command_line.h"
+#include "base/debug/activity_tracker.h"
#include "base/debug/alias.h"
#include "base/debug/debugger.h"
#include "base/debug/stack_trace.h"
+#include "base/lazy_instance.h"
#include "base/posix/eintr_wrapper.h"
#include "base/strings/string_piece.h"
#include "base/strings/string_util.h"
@@ -121,8 +125,11 @@ 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.
+base::LazyInstance<std::stack<LogAssertHandlerFunction>>::Leaky
+ log_assert_handler_stack = LAZY_INSTANCE_INITIALIZER;
+
// A log message handler that gets notified of every log message we process.
LogMessageHandlerFunction log_message_handler = nullptr;
@@ -444,8 +451,13 @@ void SetShowErrorDialogs(bool enable_dialogs) {
show_error_dialogs = enable_dialogs;
}
-void SetLogAssertHandler(LogAssertHandlerFunction handler) {
- log_assert_handler = handler;
+ScopedLogAssertHandler::ScopedLogAssertHandler(
+ LogAssertHandlerFunction handler) {
+ log_assert_handler_stack.Get().push(handler);
+}
+
+ScopedLogAssertHandler::~ScopedLogAssertHandler() {
+ log_assert_handler_stack.Get().pop();
}
void SetLogMessageHandler(LogMessageHandlerFunction handler) {
@@ -531,6 +543,7 @@ LogMessage::LogMessage(const char* file, int line, LogSeverity severity,
}
LogMessage::~LogMessage() {
+ size_t stack_start = stream_.str().length();
dcheng 2017/03/15 09:57:24 Can we use tellp to get the length and avoid doubl
alex-ac 2017/03/21 12:37:12 Done.
#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 +752,17 @@ LogMessage::~LogMessage() {
str_newline.copy(str_stack, arraysize(str_stack));
base::debug::Alias(str_stack);
+ LogAssertHandlerFunction log_assert_handler;
+ if (!log_assert_handler_stack.Get().empty())
+ log_assert_handler = log_assert_handler_stack.Get().top();
+
if (log_assert_handler) {
- // Make a copy of the string for the handler out of paranoia.
- log_assert_handler(std::string(stream_.str()));
+ const std::string& full_message = stream_.str();
dcheng 2017/03/15 09:57:24 Can this use str_newline to avoid creating an addi
alex-ac 2017/03/21 12:37:12 Done.
+ log_assert_handler.Run(
+ file_, line_,
+ base::StringPiece(full_message.c_str() + message_start_,
+ stack_start - message_start_),
+ base::StringPiece(full_message.c_str() + stack_start));
} 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
« no previous file with comments | « base/logging.h ('k') | base/logging_unittest.cc » ('j') | base/test/test_suite.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698