Index: chrome/app/breakpad_mac.mm |
diff --git a/chrome/app/breakpad_mac.mm b/chrome/app/breakpad_mac.mm |
index f078271683fa448de75f40818ed7a9491d7ab3ac..40966f51c7e3f9fd486afac3e24c9a9cc98a4cbe 100644 |
--- a/chrome/app/breakpad_mac.mm |
+++ b/chrome/app/breakpad_mac.mm |
@@ -7,6 +7,7 @@ |
#include <CoreFoundation/CoreFoundation.h> |
#import <Foundation/Foundation.h> |
+#include "base/auto_reset.h" |
#include "base/base_switches.h" |
#import "base/basictypes.h" |
#include "base/command_line.h" |
@@ -50,6 +51,40 @@ void ClearCrashKeyValue(NSString* key) { |
BreakpadRemoveUploadParameter(gBreakpadRef, key); |
} |
+bool FatalMessageHandler(int severity, const char* file, int line, |
+ size_t message_start, const std::string& str) { |
+ // Do not handle non-FATAL. |
+ if (severity != logging::LOG_FATAL) |
+ return false; |
+ |
+ // In case of OOM 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 false; |
+ |
+ AutoReset<bool> guard(&guarded, true); |
+ |
+ // Only log last path component. This matches logging.cc. |
+ if (file) { |
+ const char* slash = strrchr(file, '/'); |
+ if (slash) |
+ file = slash + 1; |
+ } |
+ |
+ NSString* fatal_key = @"LOG_FATAL"; |
+ NSString* fatal_value = |
+ [NSString stringWithFormat:@"%s:%d: %s", |
+ file, line, str.c_str() + message_start]; |
+ SetCrashKeyValue(fatal_key, fatal_value); |
+ |
+ // Rather than including the code to force the crash here, allow the |
+ // caller to do it. |
+ return false; |
+} |
+ |
} // namespace |
bool IsCrashReporterEnabled() { |
@@ -176,7 +211,9 @@ void InitCrashReporter() { |
std::string guid = |
command_line->GetSwitchValueASCII(switches::kEnableCrashReporter); |
child_process_logging::SetClientId(guid); |
- } |
+ } |
+ |
+ logging::SetLogMessageHandler(&FatalMessageHandler); |
} |
void InitCrashProcessInfo() { |