Commit 66dba199 authored by shess@chromium.org's avatar shess@chromium.org

[Mac] Log CHECK() file, line and message into breakpad.

This should make it somewhat easier to figure out which FATAL log line
fired, in the face of inlining and branching.

BUG=none
TEST=monitor crashes.


Review URL: http://codereview.chromium.org/8401018

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@107805 0039d316-1c4b-4281-b951-d872f2087c98
parent 54087fe8
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <CoreFoundation/CoreFoundation.h> #include <CoreFoundation/CoreFoundation.h>
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#include "base/auto_reset.h"
#include "base/base_switches.h" #include "base/base_switches.h"
#import "base/basictypes.h" #import "base/basictypes.h"
#include "base/command_line.h" #include "base/command_line.h"
...@@ -50,6 +51,40 @@ void ClearCrashKeyValue(NSString* key) { ...@@ -50,6 +51,40 @@ void ClearCrashKeyValue(NSString* key) {
BreakpadRemoveUploadParameter(gBreakpadRef, 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 } // namespace
bool IsCrashReporterEnabled() { bool IsCrashReporterEnabled() {
...@@ -176,7 +211,9 @@ void InitCrashReporter() { ...@@ -176,7 +211,9 @@ void InitCrashReporter() {
std::string guid = std::string guid =
command_line->GetSwitchValueASCII(switches::kEnableCrashReporter); command_line->GetSwitchValueASCII(switches::kEnableCrashReporter);
child_process_logging::SetClientId(guid); child_process_logging::SetClientId(guid);
} }
logging::SetLogMessageHandler(&FatalMessageHandler);
} }
void InitCrashProcessInfo() { void InitCrashProcessInfo() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment