diff options
author | jeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-22 21:18:55 +0000 |
---|---|---|
committer | jeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-22 21:18:55 +0000 |
commit | cc3b1826c0dbf8aa92484a0510ecfbe98f591335 (patch) | |
tree | 23cf8a79671994333bb31d3e1393552f5a167091 /chrome/app/breakpad_mac.mm | |
parent | 04f94eb6d9cd8e0049a2decc7e96cba24d6903a1 (diff) | |
download | chromium_src-cc3b1826c0dbf8aa92484a0510ecfbe98f591335.zip chromium_src-cc3b1826c0dbf8aa92484a0510ecfbe98f591335.tar.gz chromium_src-cc3b1826c0dbf8aa92484a0510ecfbe98f591335.tar.bz2 |
Last chunk of OS X Breakpad integration:
* Link agasint Breakpad from public svn repo.
* Bump DEPS to new svn rev of Breakpad with fixes for 10.5 compilation.
* Fill in code to differentiate between processes types in crash report.
Review URL: http://codereview.chromium.org/88043
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14245 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/app/breakpad_mac.mm')
-rw-r--r-- | chrome/app/breakpad_mac.mm | 139 |
1 files changed, 70 insertions, 69 deletions
diff --git a/chrome/app/breakpad_mac.mm b/chrome/app/breakpad_mac.mm index a301e86..8a689cf 100644 --- a/chrome/app/breakpad_mac.mm +++ b/chrome/app/breakpad_mac.mm @@ -4,38 +4,42 @@ #import "chrome/app/breakpad_mac.h" -#import <dlfcn.h> #import <Foundation/Foundation.h> +#include "base/base_switches.h" #import "base/basictypes.h" +#include "base/command_line.h" #import "base/logging.h" #import "base/scoped_nsautorelease_pool.h" +#include "base/sys_string_conversions.h" +#import "breakpad/src/client/mac/Framework/Breakpad.h" -// For definition of SetActiveRendererURL(). -#import "chrome/renderer/renderer_logging.h" -#import "googleurl/src/gurl.h" +#if !defined(GOOGLE_CHROME_BUILD) +// If we aren't compiling as a branded build, then add dummy versions of the +// Breakpad functions so we don't have to link against Breakpad. -// TODO(jeremy): On Windows we store the current URL when a process crashes -// we probably want to do the same on OS X. +BreakpadRef BreakpadCreate(NSDictionary *parameters) { + NOTREACHED(); + return NULL; +} -namespace { +void BreakpadRelease(BreakpadRef ref) { + NOTREACHED(); +} -// TODO(jeremy): Remove this block once we include the breakpad sources -// in the public tree. -typedef void* GoogleBreakpadRef; +void BreakpadSetKeyValue(BreakpadRef ref, NSString *key, NSString *value) { + NOTREACHED(); +} -typedef void (*GoogleBreakpadSetKeyValuePtr) (GoogleBreakpadRef, NSString*, - NSString*); -typedef void (*GoogleBreakpadRemoveKeyValuePtr) (GoogleBreakpadRef, NSString*); -typedef GoogleBreakpadRef (*GoogleBreakPadCreatePtr) (NSDictionary*); -typedef void (*GoogleBreakPadReleasePtr) (GoogleBreakpadRef); +void BreakpadRemoveKeyValue(BreakpadRef ref, NSString *key) { + NOTREACHED(); +} + +#endif // !defined(GOOGLE_CHROME_BUILD) +namespace { -GoogleBreakpadRef gBreakpadRef = NULL; -GoogleBreakPadCreatePtr gBreakPadCreateFunc = NULL; -GoogleBreakPadReleasePtr gBreakPadReleaseFunc = NULL; -GoogleBreakpadSetKeyValuePtr gBreakpadSetKeyValueFunc = NULL; -GoogleBreakpadRemoveKeyValuePtr gBreakpadRemoveKeyValueFunc = NULL; +BreakpadRef gBreakpadRef = NULL; // Did the user optin for reporting stats. bool IsStatsReportingAllowed() { @@ -51,12 +55,12 @@ bool IsCrashReporterEnabled() { void DestructCrashReporter() { if (gBreakpadRef) { - DCHECK(gBreakPadReleaseFunc != NULL); - gBreakPadReleaseFunc(gBreakpadRef); + BreakpadRelease(gBreakpadRef); gBreakpadRef = NULL; } } +// Only called for a branded build of Chrome.app. void InitCrashReporter() { DCHECK(gBreakpadRef == NULL); base::ScopedNSAutoreleasePool autorelease_pool; @@ -69,63 +73,62 @@ void InitCrashReporter() { } NSBundle* main_bundle = [NSBundle mainBundle]; - - // Get location of breakpad. - NSString* breakpadBundlePath = [[main_bundle privateFrameworksPath] - stringByAppendingPathComponent:@"GoogleBreakpad.framework"]; - - BOOL is_dir = NO; - if (![[NSFileManager defaultManager] fileExistsAtPath:breakpadBundlePath - isDirectory:&is_dir] || !is_dir) { - return; - } - - NSBundle* breakpad_bundle = [NSBundle bundleWithPath:breakpadBundlePath]; - if (![breakpad_bundle load]) { - LOG(ERROR) << "Failed to load Breakpad framework."; - return; - } - - // 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; - } + NSString* resource_path = [main_bundle resourcePath]; NSDictionary* info_dictionary = [main_bundle infoDictionary]; - GoogleBreakpadRef breakpad = NULL; - breakpad = gBreakPadCreateFunc(info_dictionary); + NSMutableDictionary *breakpad_config = [info_dictionary + mutableCopy]; + + // Tell Breakpad where inspector & crash_reporter are. + NSString *inspector_location = [resource_path + stringByAppendingPathComponent:@"crash_inspector"]; + NSString *reporter_bundle_location = [resource_path + stringByAppendingPathComponent:@"crash_report_sender.app"]; + NSString *reporter_location = [[NSBundle + bundleWithPath:reporter_bundle_location] + executablePath]; + + [breakpad_config setObject:inspector_location + forKey:@BREAKPAD_INSPECTOR_LOCATION]; + [breakpad_config setObject:reporter_location + forKey:@BREAKPAD_REPORTER_EXE_LOCATION]; + + // Init breakpad + BreakpadRef breakpad = NULL; + breakpad = BreakpadCreate(breakpad_config); 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"]; + // These values are added to the plist when building a branded Chrome.app. + NSString* version_str = [info_dictionary objectForKey:@BREAKPAD_VERSION]; SetCrashKeyValue(@"ver", version_str); - NSString* prod_name_str = [info_dictionary objectForKey:@"CFBundleExecutable"]; + NSString* prod_name_str = [info_dictionary objectForKey:@BREAKPAD_PRODUCT]; SetCrashKeyValue(@"prod", prod_name_str); SetCrashKeyValue(@"plat", @"OS X"); - NSString *product_type = is_renderer ? @"renderer" : @"browser"; - SetCrashKeyValue(@"ptype", product_type); +} + +void InitCrashProcessInfo() { + if (gBreakpadRef == NULL) { + return; + } + + // Determine the process type. + NSString *process_type = @"browser"; + const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); + std::wstring process_type_switch = + parsed_command_line.GetSwitchValue(switches::kProcessType); + if (!process_type_switch.empty()) { + process_type = base::SysWideToNSString(process_type_switch); + } + + // Store process type in crash dump. + SetCrashKeyValue(@"ptype", process_type); } void SetCrashKeyValue(NSString* key, NSString* value) { @@ -137,8 +140,7 @@ void SetCrashKeyValue(NSString* key, NSString* value) { return; } - DCHECK(gBreakpadSetKeyValueFunc != NULL); - gBreakpadSetKeyValueFunc(gBreakpadRef, key, value); + BreakpadSetKeyValue(gBreakpadRef, key, value); } void ClearCrashKeyValue(NSString* key) { @@ -146,6 +148,5 @@ void ClearCrashKeyValue(NSString* key) { return; } - DCHECK(gBreakpadRemoveKeyValueFunc != NULL); - gBreakpadRemoveKeyValueFunc(gBreakpadRef, key); + BreakpadRemoveKeyValue(gBreakpadRef, key); } |