Chromium Code Reviews| Index: base/logging.cc |
| diff --git a/base/logging.cc b/base/logging.cc |
| index 0771b47c182e5c18c868f1124a0784bf411d74a9..dd812c1911d77e0344bd609345bac671cda17ed3 100644 |
| --- a/base/logging.cc |
| +++ b/base/logging.cc |
| @@ -53,9 +53,11 @@ typedef pthread_mutex_t* MutexHandle; |
| #include <ostream> |
| #include <string> |
| +#include "base/auto_reset.h" |
| #include "base/base_switches.h" |
| #include "base/command_line.h" |
| #include "base/debug/alias.h" |
| +#include "base/debug/crash_logging.h" |
| #include "base/debug/debugger.h" |
| #include "base/debug/stack_trace.h" |
| #include "base/posix/eintr_wrapper.h" |
| @@ -126,6 +128,27 @@ LogAssertHandlerFunction log_assert_handler = nullptr; |
| // A log message handler that gets notified of every log message we process. |
| LogMessageHandlerFunction log_message_handler = nullptr; |
| +void SetLogFatalCrashKey(size_t message_start, |
| + const std::string& string) { |
| +// Nacl targets miss base/debug/crash_logging.cc. |
|
scottmg
2016/10/05 22:06:21
nit; "NaCl targets do not have ..."
rkuksin
2016/10/06 08:50:33
Done.
|
| +#if !defined(NACL_TC_REV) |
|
scottmg
2016/10/05 22:06:21
OS_NACL.
rkuksin
2016/10/06 08:50:33
Done.
|
| + // In case of an out-of-memory condition, this code could be reentered when |
| + // constructing and storing the key. Using a static is not thread-safe, but if |
| + // multiple threads are in the process of a fatal crash at the same time, this |
| + // should work. |
| + static bool guarded = false; |
| + if (guarded) { |
| + return; |
| + } |
| + base::AutoReset<bool> guard(&guarded, true); |
| + |
| + CHECK_LE(message_start, string.size()); |
| + std::string message = base::StringPrintf("%s", |
| + string.c_str() + message_start); |
| + base::debug::SetCrashKeyValue("LOG_FATAL", message); |
|
scottmg
2016/10/05 22:06:21
This takes a StringPiece so no need for the Sprint
rkuksin
2016/10/06 08:50:33
Done.
|
| +#endif // !defined(NACL_TC_REV) |
| +} |
| + |
| // Helper functions to wrap platform differences. |
| int32_t CurrentProcessId() { |
| @@ -537,6 +560,10 @@ LogMessage::~LogMessage() { |
| stream_ << std::endl; |
| std::string str_newline(stream_.str()); |
| + if (severity_ == LOG_FATAL) { |
| + SetLogFatalCrashKey(message_start_, str_newline); |
| + } |
| + |
| // Give any log message handler first dibs on the message. |
| if (log_message_handler && |
| log_message_handler(severity_, file_, line_, |