| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "chrome/app/breakpad_mac.h" | 5 #import "chrome/app/breakpad_mac.h" |
| 6 | 6 |
| 7 #import <dlfcn.h> | |
| 8 #import <Foundation/Foundation.h> | 7 #import <Foundation/Foundation.h> |
| 9 | 8 |
| 10 #import "base/basictypes.h" | 9 #import "base/basictypes.h" |
| 11 #import "base/logging.h" | 10 #import "base/logging.h" |
| 12 #import "base/scoped_nsautorelease_pool.h" | 11 #import "base/scoped_nsautorelease_pool.h" |
| 12 #import "breakpad/src/client/mac/Framework/Breakpad.h" |
| 13 | 13 |
| 14 // For definition of SetActiveRendererURL(). | 14 // For definition of SetActiveRendererURL(). |
| 15 #import "chrome/renderer/renderer_logging.h" | 15 #import "chrome/renderer/renderer_logging.h" |
| 16 #import "googleurl/src/gurl.h" | 16 #import "googleurl/src/gurl.h" |
| 17 | 17 |
| 18 // TODO(jeremy): On Windows we store the current URL when a process crashes | 18 // TODO(jeremy): On Windows we store the current URL when a process crashes |
| 19 // we probably want to do the same on OS X. | 19 // we probably want to do the same on OS X. |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 // TODO(jeremy): Remove this block once we include the breakpad sources | |
| 24 // in the public tree. | |
| 25 typedef void* GoogleBreakpadRef; | |
| 26 | 23 |
| 27 typedef void (*GoogleBreakpadSetKeyValuePtr) (GoogleBreakpadRef, NSString*, | 24 BreakpadRef gBreakpadRef = NULL; |
| 28 NSString*); | |
| 29 typedef void (*GoogleBreakpadRemoveKeyValuePtr) (GoogleBreakpadRef, NSString*); | |
| 30 typedef GoogleBreakpadRef (*GoogleBreakPadCreatePtr) (NSDictionary*); | |
| 31 typedef void (*GoogleBreakPadReleasePtr) (GoogleBreakpadRef); | |
| 32 | |
| 33 | |
| 34 GoogleBreakpadRef gBreakpadRef = NULL; | |
| 35 GoogleBreakPadCreatePtr gBreakPadCreateFunc = NULL; | |
| 36 GoogleBreakPadReleasePtr gBreakPadReleaseFunc = NULL; | |
| 37 GoogleBreakpadSetKeyValuePtr gBreakpadSetKeyValueFunc = NULL; | |
| 38 GoogleBreakpadRemoveKeyValuePtr gBreakpadRemoveKeyValueFunc = NULL; | |
| 39 | 25 |
| 40 // Did the user optin for reporting stats. | 26 // Did the user optin for reporting stats. |
| 41 bool IsStatsReportingAllowed() { | 27 bool IsStatsReportingAllowed() { |
| 42 NOTIMPLEMENTED(); | 28 NOTIMPLEMENTED(); |
| 43 return true; | 29 return true; |
| 44 } | 30 } |
| 45 | 31 |
| 46 } // namespace | 32 } // namespace |
| 47 | 33 |
| 48 bool IsCrashReporterEnabled() { | 34 bool IsCrashReporterEnabled() { |
| 49 return gBreakpadRef == NULL; | 35 return gBreakpadRef == NULL; |
| 50 } | 36 } |
| 51 | 37 |
| 52 void DestructCrashReporter() { | 38 void DestructCrashReporter() { |
| 53 if (gBreakpadRef) { | 39 if (gBreakpadRef) { |
| 54 DCHECK(gBreakPadReleaseFunc != NULL); | 40 BreakpadRelease(gBreakpadRef); |
| 55 gBreakPadReleaseFunc(gBreakpadRef); | |
| 56 gBreakpadRef = NULL; | 41 gBreakpadRef = NULL; |
| 57 } | 42 } |
| 58 } | 43 } |
| 59 | 44 |
| 60 void InitCrashReporter() { | 45 void InitCrashReporter() { |
| 61 DCHECK(gBreakpadRef == NULL); | 46 DCHECK(gBreakpadRef == NULL); |
| 62 base::ScopedNSAutoreleasePool autorelease_pool; | 47 base::ScopedNSAutoreleasePool autorelease_pool; |
| 63 | 48 |
| 64 // Check for Send stats preference. If preference is not specifically turned | 49 // Check for Send stats preference. If preference is not specifically turned |
| 65 // on then disable crash reporting. | 50 // on then disable crash reporting. |
| 66 if (!IsStatsReportingAllowed()) { | 51 if (!IsStatsReportingAllowed()) { |
| 67 LOG(WARNING) << "Breakpad disabled"; | 52 LOG(WARNING) << "Breakpad disabled"; |
| 68 return; | 53 return; |
| 69 } | 54 } |
| 70 | 55 |
| 71 NSBundle* main_bundle = [NSBundle mainBundle]; | 56 NSBundle* main_bundle = [NSBundle mainBundle]; |
| 72 | 57 |
| 73 // Get location of breakpad. | |
| 74 NSString* breakpadBundlePath = [[main_bundle privateFrameworksPath] | |
| 75 stringByAppendingPathComponent:@"GoogleBreakpad.framework"]; | |
| 76 | |
| 77 BOOL is_dir = NO; | |
| 78 if (![[NSFileManager defaultManager] fileExistsAtPath:breakpadBundlePath | |
| 79 isDirectory:&is_dir] || !is_dir) { | |
| 80 return; | |
| 81 } | |
| 82 | |
| 83 NSBundle* breakpad_bundle = [NSBundle bundleWithPath:breakpadBundlePath]; | |
| 84 if (![breakpad_bundle load]) { | |
| 85 LOG(ERROR) << "Failed to load Breakpad framework."; | |
| 86 return; | |
| 87 } | |
| 88 | |
| 89 // Retrieve Breakpad interface functions. | |
| 90 gBreakPadCreateFunc = reinterpret_cast<GoogleBreakPadCreatePtr>( | |
| 91 dlsym(RTLD_DEFAULT, "GoogleBreakpadCreate")); | |
| 92 gBreakPadReleaseFunc = reinterpret_cast<GoogleBreakPadReleasePtr>( | |
| 93 dlsym(RTLD_DEFAULT, "GoogleBreakpadRelease")); | |
| 94 gBreakpadSetKeyValueFunc = reinterpret_cast<GoogleBreakpadSetKeyValuePtr>( | |
| 95 dlsym(RTLD_DEFAULT, "GoogleBreakpadSetKeyValue")); | |
| 96 gBreakpadRemoveKeyValueFunc = | |
| 97 reinterpret_cast<GoogleBreakpadRemoveKeyValuePtr>( | |
| 98 dlsym(RTLD_DEFAULT, "GoogleBreakpadRemoveKeyValue")); | |
| 99 | |
| 100 if (!gBreakPadCreateFunc || !gBreakPadReleaseFunc | |
| 101 || !gBreakpadSetKeyValueFunc || !gBreakpadRemoveKeyValueFunc) { | |
| 102 LOG(ERROR) << "Failed to find Breakpad wrapper classes."; | |
| 103 return; | |
| 104 } | |
| 105 | |
| 106 NSDictionary* info_dictionary = [main_bundle infoDictionary]; | 58 NSDictionary* info_dictionary = [main_bundle infoDictionary]; |
| 107 GoogleBreakpadRef breakpad = NULL; | 59 BreakpadRef breakpad = NULL; |
| 108 breakpad = gBreakPadCreateFunc(info_dictionary); | 60 breakpad = BreakpadCreate(info_dictionary); |
| 109 if (!breakpad) { | 61 if (!breakpad) { |
| 110 LOG(ERROR) << "Breakpad init failed."; | 62 LOG(ERROR) << "Breakpad init failed."; |
| 111 return; | 63 return; |
| 112 } | 64 } |
| 113 | 65 |
| 114 // TODO(jeremy): determine whether we're running in the browser or | 66 // TODO(jeremy): determine whether we're running in the browser or |
| 115 // renderer processes. | 67 // renderer processes. |
| 116 bool is_renderer = false; | 68 bool is_renderer = false; |
| 117 | 69 |
| 118 // This needs to be set before calling SetCrashKeyValue(). | 70 // This needs to be set before calling SetCrashKeyValue(). |
| (...skipping 11 matching lines...) Expand all Loading... |
| 130 | 82 |
| 131 void SetCrashKeyValue(NSString* key, NSString* value) { | 83 void SetCrashKeyValue(NSString* key, NSString* value) { |
| 132 // Comment repeated from header to prevent confusion: | 84 // Comment repeated from header to prevent confusion: |
| 133 // IMPORTANT: On OS X, the key/value pairs are sent to the crash server | 85 // IMPORTANT: On OS X, the key/value pairs are sent to the crash server |
| 134 // out of bounds and not recorded on disk in the minidump, this means | 86 // out of bounds and not recorded on disk in the minidump, this means |
| 135 // that if you look at the minidump file locally you won't see them! | 87 // that if you look at the minidump file locally you won't see them! |
| 136 if (gBreakpadRef == NULL) { | 88 if (gBreakpadRef == NULL) { |
| 137 return; | 89 return; |
| 138 } | 90 } |
| 139 | 91 |
| 140 DCHECK(gBreakpadSetKeyValueFunc != NULL); | 92 BreakpadSetKeyValue(gBreakpadRef, key, value); |
| 141 gBreakpadSetKeyValueFunc(gBreakpadRef, key, value); | |
| 142 } | 93 } |
| 143 | 94 |
| 144 void ClearCrashKeyValue(NSString* key) { | 95 void ClearCrashKeyValue(NSString* key) { |
| 145 if (gBreakpadRef == NULL) { | 96 if (gBreakpadRef == NULL) { |
| 146 return; | 97 return; |
| 147 } | 98 } |
| 148 | 99 |
| 149 DCHECK(gBreakpadRemoveKeyValueFunc != NULL); | 100 BreakpadRemoveKeyValue(gBreakpadRef, key); |
| 150 gBreakpadRemoveKeyValueFunc(gBreakpadRef, key); | |
| 151 } | 101 } |
| OLD | NEW |