diff options
-rw-r--r-- | DEPS | 2 | ||||
-rw-r--r-- | breakpad/breakpad.gyp | 8 | ||||
-rw-r--r-- | chrome/app/breakpad_mac.h | 5 | ||||
-rw-r--r-- | chrome/app/breakpad_mac.mm | 139 | ||||
-rw-r--r-- | chrome/app/breakpad_mac_stubs.mm | 27 | ||||
-rw-r--r-- | chrome/app/chrome_dll_main.cc | 6 | ||||
-rw-r--r-- | chrome/chrome.gyp | 16 |
7 files changed, 128 insertions, 75 deletions
@@ -7,7 +7,7 @@ vars = { deps = { "src/breakpad/src": - "http://google-breakpad.googlecode.com/svn/trunk/src@322", + "http://google-breakpad.googlecode.com/svn/trunk/src@328", "src/googleurl": "http://google-url.googlecode.com/svn/trunk@100", diff --git a/breakpad/breakpad.gyp b/breakpad/breakpad.gyp index 26a2a6d..ac70ca9e 100644 --- a/breakpad/breakpad.gyp +++ b/breakpad/breakpad.gyp @@ -12,6 +12,14 @@ 'include_dirs': [ 'src/', ], + 'configurations': { + 'Debug': { + 'defines': [ + # This is needed for GTMLogger to work correctly. + 'DEBUG', + ], + }, + }, }, 'targets': [ { diff --git a/chrome/app/breakpad_mac.h b/chrome/app/breakpad_mac.h index b52e89c..3d8ab32 100644 --- a/chrome/app/breakpad_mac.h +++ b/chrome/app/breakpad_mac.h @@ -10,6 +10,11 @@ // Initializes Breakpad. void InitCrashReporter(); +// Give Breakpad a chance to store information about the current process. +// Extra information requires a parsed command line, so call this after +// CommandLine::Init has been called. +void InitCrashProcessInfo(); + // Is Breakpad enabled? bool IsCrashReporterEnabled(); 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); } diff --git a/chrome/app/breakpad_mac_stubs.mm b/chrome/app/breakpad_mac_stubs.mm new file mode 100644 index 0000000..8497f4f --- /dev/null +++ b/chrome/app/breakpad_mac_stubs.mm @@ -0,0 +1,27 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#import "chrome/app/breakpad_mac.h" + +// Stubbed out versions of breakpad integration functions so we can compile +// without linking in Breakpad on non-official builds. + +bool IsCrashReporterEnabled() { + return false; +} + +void InitCrashProcessInfo() { +} + +void DestructCrashReporter() { +} + +void InitCrashReporter() { +} + +void SetCrashKeyValue(NSString* key, NSString* value) { +} + +void ClearCrashKeyValue(NSString* key) { +} diff --git a/chrome/app/chrome_dll_main.cc b/chrome/app/chrome_dll_main.cc index 63658ca..ba078ab 100644 --- a/chrome/app/chrome_dll_main.cc +++ b/chrome/app/chrome_dll_main.cc @@ -281,6 +281,12 @@ int ChromeMain(int argc, const char** argv) { #else CommandLine::Init(argc, argv); #endif + +#if defined(OS_MACOSX) + // Needs to be called after CommandLine::Init(). + InitCrashProcessInfo(); +#endif + const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); #if defined(OS_WIN) diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index d2613a0..b22be98 100644 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -213,10 +213,6 @@ 'common/libxml_utils.h', 'common/logging_chrome.cc', 'common/logging_chrome.h', - 'common/mach_ipc_mac.h', - 'common/mach_ipc_mac.mm', - 'common/mach_message_source_mac.cc', - 'common/mach_message_source_mac.h', 'common/main_function_params.h', 'common/message_box_flags.h', 'common/message_router.cc', @@ -1658,6 +1654,16 @@ # "bundle_id" is the name of the variable used to replace # BUNDLE_ID in Info.plist. 'variables': {'bundle_id': 'com.google.Chrome'}, + # Only include breakpad in official builds. + 'dependencies': [ + '../breakpad/breakpad.gyp:breakpad', + ], + 'copies': [ + { + 'destination': '<(PRODUCT_DIR)/<(branding).app/Contents/Resources/', + 'files': ['<(PRODUCT_DIR)/crash_inspector', '<(PRODUCT_DIR)/crash_report_sender.app'], + }, + ] }, { # else: branding!="Chrome" 'mac_bundle_resources': ['app/theme/chromium/app.icns'], 'variables': {'bundle_id': 'org.chromium.Chromium'}, @@ -2121,7 +2127,7 @@ '..', ], 'sources': [ - 'app/breakpad_mac.mm', + 'app/breakpad_mac_stubs.mm', # All unittests in browser, common, and renderer. 'browser/autocomplete/autocomplete_unittest.cc', 'browser/autocomplete/history_contents_provider_unittest.cc', |