diff options
author | jeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-30 21:24:07 +0000 |
---|---|---|
committer | jeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-30 21:24:07 +0000 |
commit | fcf195410ee81b7444469c2863e5d2416fe1688a (patch) | |
tree | 92f61230bbe69b7a2b0fcb1b15c867003054ee8c /chrome/app/breakpad_mac.mm | |
parent | 161ce86fc859484708d88e68b31af9ad28abafa6 (diff) | |
download | chromium_src-fcf195410ee81b7444469c2863e5d2416fe1688a.zip chromium_src-fcf195410ee81b7444469c2863e5d2416fe1688a.tar.gz chromium_src-fcf195410ee81b7444469c2863e5d2416fe1688a.tar.bz2 |
* Breakpad on OSX now works with stock Breakpad framwork.
* We now add all the same Metadata on OS X as we do on Windows.
* Made the code for logging URLs in crash dumps a little more x-platform.
Remove custom Breakpad hacks so we can use an unmodified version of the Framework.
Review URL: http://codereview.chromium.org/55028
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@12811 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/app/breakpad_mac.mm')
-rw-r--r-- | chrome/app/breakpad_mac.mm | 90 |
1 files changed, 73 insertions, 17 deletions
diff --git a/chrome/app/breakpad_mac.mm b/chrome/app/breakpad_mac.mm index 5ffc147..a301e86 100644 --- a/chrome/app/breakpad_mac.mm +++ b/chrome/app/breakpad_mac.mm @@ -4,27 +4,38 @@ #import "chrome/app/breakpad_mac.h" -#import <objc/objc-class.h> +#import <dlfcn.h> #import <Foundation/Foundation.h> #import "base/basictypes.h" #import "base/logging.h" #import "base/scoped_nsautorelease_pool.h" +// For definition of SetActiveRendererURL(). +#import "chrome/renderer/renderer_logging.h" +#import "googleurl/src/gurl.h" + +// TODO(jeremy): On Windows we store the current URL when a process crashes +// we probably want to do the same on OS X. + +namespace { + // TODO(jeremy): Remove this block once we include the breakpad sources // in the public tree. -@interface GoogleBreakpadWrapper : NSObject - +(void*)Create:(NSDictionary*) parameters; - +(void)Release:(void*) ref; -@end typedef void* GoogleBreakpadRef; -namespace { +typedef void (*GoogleBreakpadSetKeyValuePtr) (GoogleBreakpadRef, NSString*, + NSString*); +typedef void (*GoogleBreakpadRemoveKeyValuePtr) (GoogleBreakpadRef, NSString*); +typedef GoogleBreakpadRef (*GoogleBreakPadCreatePtr) (NSDictionary*); +typedef void (*GoogleBreakPadReleasePtr) (GoogleBreakpadRef); -// TODO(jeremy): On Windows we store the current URL when a process crashes -// we probably want to do the same on OS X. GoogleBreakpadRef gBreakpadRef = NULL; +GoogleBreakPadCreatePtr gBreakPadCreateFunc = NULL; +GoogleBreakPadReleasePtr gBreakPadReleaseFunc = NULL; +GoogleBreakpadSetKeyValuePtr gBreakpadSetKeyValueFunc = NULL; +GoogleBreakpadRemoveKeyValuePtr gBreakpadRemoveKeyValueFunc = NULL; // Did the user optin for reporting stats. bool IsStatsReportingAllowed() { @@ -40,8 +51,8 @@ bool IsCrashReporterEnabled() { void DestructCrashReporter() { if (gBreakpadRef) { - Class breakpad_interface = objc_getClass("GoogleBreakpadWrapper"); - [breakpad_interface Release:gBreakpadRef]; + DCHECK(gBreakPadReleaseFunc != NULL); + gBreakPadReleaseFunc(gBreakpadRef); gBreakpadRef = NULL; } } @@ -75,21 +86,66 @@ void InitCrashReporter() { return; } - Class breakpad_interface = [breakpad_bundle - classNamed:@"GoogleBreakpadWrapper"]; - - if (!breakpad_interface) { - LOG(ERROR) << "Failed to find GoogleBreakpadWrapper class."; + // Retrieve Breakpad interface functions. + gBreakPadCreateFunc = reinterpret_cast<GoogleBreakPadCreatePtr>( + dlsym(RTLD_DEFAULT, "GoogleBreakpadCreate")); + gBreakPadReleaseFunc = reinterpret_cast<GoogleBreakPadReleasePtr>( + dlsym(RTLD_DEFAULT, "GoogleBreakpadRelease")); + gBreakpadSetKeyValueFunc = reinterpret_cast<GoogleBreakpadSetKeyValuePtr>( + dlsym(RTLD_DEFAULT, "GoogleBreakpadSetKeyValue")); + gBreakpadRemoveKeyValueFunc = + reinterpret_cast<GoogleBreakpadRemoveKeyValuePtr>( + dlsym(RTLD_DEFAULT, "GoogleBreakpadRemoveKeyValue")); + + if (!gBreakPadCreateFunc || !gBreakPadReleaseFunc + || !gBreakpadSetKeyValueFunc || !gBreakpadRemoveKeyValueFunc) { + LOG(ERROR) << "Failed to find Breakpad wrapper classes."; return; } NSDictionary* info_dictionary = [main_bundle infoDictionary]; - GoogleBreakpadRef breakpad = 0; - breakpad = [breakpad_interface Create:info_dictionary]; + GoogleBreakpadRef breakpad = NULL; + breakpad = gBreakPadCreateFunc(info_dictionary); if (!breakpad) { LOG(ERROR) << "Breakpad init failed."; return; } + // TODO(jeremy): determine whether we're running in the browser or + // renderer processes. + bool is_renderer = false; + + // This needs to be set before calling SetCrashKeyValue(). gBreakpadRef = breakpad; + + // Set breakpad MetaData values. + NSString* version_str = [info_dictionary objectForKey:@"CFBundleVersion"]; + SetCrashKeyValue(@"ver", version_str); + NSString* prod_name_str = [info_dictionary objectForKey:@"CFBundleExecutable"]; + SetCrashKeyValue(@"prod", prod_name_str); + SetCrashKeyValue(@"plat", @"OS X"); + NSString *product_type = is_renderer ? @"renderer" : @"browser"; + SetCrashKeyValue(@"ptype", product_type); +} + +void SetCrashKeyValue(NSString* key, NSString* value) { + // Comment repeated from header to prevent confusion: + // IMPORTANT: On OS X, the key/value pairs are sent to the crash server + // out of bounds and not recorded on disk in the minidump, this means + // that if you look at the minidump file locally you won't see them! + if (gBreakpadRef == NULL) { + return; + } + + DCHECK(gBreakpadSetKeyValueFunc != NULL); + gBreakpadSetKeyValueFunc(gBreakpadRef, key, value); +} + +void ClearCrashKeyValue(NSString* key) { + if (gBreakpadRef == NULL) { + return; + } + + DCHECK(gBreakpadRemoveKeyValueFunc != NULL); + gBreakpadRemoveKeyValueFunc(gBreakpadRef, key); } |