Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(185)

Side by Side Diff: chrome/app/breakpad_mac.mm

Issue 88043: More OS X Breakpad integration (Closed)
Patch Set: Fix jrg's comments. Created 11 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/app/breakpad_mac.h ('k') | chrome/app/chrome_dll_main.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
9 #include "base/base_switches.h"
10 #import "base/basictypes.h" 10 #import "base/basictypes.h"
11 #include "base/command_line.h"
11 #import "base/logging.h" 12 #import "base/logging.h"
12 #import "base/scoped_nsautorelease_pool.h" 13 #import "base/scoped_nsautorelease_pool.h"
14 #include "base/sys_string_conversions.h"
15 #import "breakpad/src/client/mac/Framework/Breakpad.h"
13 16
14 // For definition of SetActiveRendererURL(). 17 #if !defined(GOOGLE_CHROME_BUILD)
15 #import "chrome/renderer/renderer_logging.h" 18 // If we aren't compiling as a branded build, then add dummy versions of the
16 #import "googleurl/src/gurl.h" 19 // Breakpad functions so we don't have to link against Breakpad.
17 20
18 // TODO(jeremy): On Windows we store the current URL when a process crashes 21 BreakpadRef BreakpadCreate(NSDictionary *parameters) {
19 // we probably want to do the same on OS X. 22 NOTREACHED();
23 return NULL;
24 }
25
26 void BreakpadRelease(BreakpadRef ref) {
27 NOTREACHED();
28 }
29
30 void BreakpadSetKeyValue(BreakpadRef ref, NSString *key, NSString *value) {
31 NOTREACHED();
32 }
33
34 void BreakpadRemoveKeyValue(BreakpadRef ref, NSString *key) {
35 NOTREACHED();
36 }
37
38 #endif // !defined(GOOGLE_CHROME_BUILD)
20 39
21 namespace { 40 namespace {
22 41
23 // TODO(jeremy): Remove this block once we include the breakpad sources 42 BreakpadRef gBreakpadRef = NULL;
24 // in the public tree.
25 typedef void* GoogleBreakpadRef;
26
27 typedef void (*GoogleBreakpadSetKeyValuePtr) (GoogleBreakpadRef, NSString*,
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 43
40 // Did the user optin for reporting stats. 44 // Did the user optin for reporting stats.
41 bool IsStatsReportingAllowed() { 45 bool IsStatsReportingAllowed() {
42 NOTIMPLEMENTED(); 46 NOTIMPLEMENTED();
43 return true; 47 return true;
44 } 48 }
45 49
46 } // namespace 50 } // namespace
47 51
48 bool IsCrashReporterEnabled() { 52 bool IsCrashReporterEnabled() {
49 return gBreakpadRef == NULL; 53 return gBreakpadRef == NULL;
50 } 54 }
51 55
52 void DestructCrashReporter() { 56 void DestructCrashReporter() {
53 if (gBreakpadRef) { 57 if (gBreakpadRef) {
54 DCHECK(gBreakPadReleaseFunc != NULL); 58 BreakpadRelease(gBreakpadRef);
55 gBreakPadReleaseFunc(gBreakpadRef);
56 gBreakpadRef = NULL; 59 gBreakpadRef = NULL;
57 } 60 }
58 } 61 }
59 62
60 void InitCrashReporter() { 63 void InitCrashReporter() {
John Grabowski 2009/04/22 00:01:58 Add a comment that InitCrashReporter() is only cal
61 DCHECK(gBreakpadRef == NULL); 64 DCHECK(gBreakpadRef == NULL);
62 base::ScopedNSAutoreleasePool autorelease_pool; 65 base::ScopedNSAutoreleasePool autorelease_pool;
63 66
64 // Check for Send stats preference. If preference is not specifically turned 67 // Check for Send stats preference. If preference is not specifically turned
65 // on then disable crash reporting. 68 // on then disable crash reporting.
66 if (!IsStatsReportingAllowed()) { 69 if (!IsStatsReportingAllowed()) {
67 LOG(WARNING) << "Breakpad disabled"; 70 LOG(WARNING) << "Breakpad disabled";
68 return; 71 return;
69 } 72 }
70 73
71 NSBundle* main_bundle = [NSBundle mainBundle]; 74 NSBundle* main_bundle = [NSBundle mainBundle];
72 75 NSString* resource_path = [main_bundle resourcePath];
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 76
106 NSDictionary* info_dictionary = [main_bundle infoDictionary]; 77 NSDictionary* info_dictionary = [main_bundle infoDictionary];
107 GoogleBreakpadRef breakpad = NULL; 78 NSMutableDictionary *breakpad_config = [info_dictionary
108 breakpad = gBreakPadCreateFunc(info_dictionary); 79 mutableCopy];
80
81 // Tell Breakpad where inspector & crash_reporter are.
82 NSString *inspector_location = [resource_path
83 stringByAppendingPathComponent:@"crash_inspector"];
84 NSString *reporter_bundle_location = [resource_path
85 stringByAppendingPathComponent:@"crash_report_sender.app"];
86 NSString *reporter_location = [[NSBundle
87 bundleWithPath:reporter_bundle_location]
88 executablePath];
89
90 [breakpad_config setObject:inspector_location
91 forKey:@BREAKPAD_INSPECTOR_LOCATION];
92 [breakpad_config setObject:reporter_location
93 forKey:@BREAKPAD_REPORTER_EXE_LOCATION];
94
95 // Init breakpad
96 BreakpadRef breakpad = NULL;
97 breakpad = BreakpadCreate(breakpad_config);
109 if (!breakpad) { 98 if (!breakpad) {
110 LOG(ERROR) << "Breakpad init failed."; 99 LOG(ERROR) << "Breakpad init failed.";
111 return; 100 return;
112 } 101 }
113 102
114 // TODO(jeremy): determine whether we're running in the browser or
115 // renderer processes.
116 bool is_renderer = false;
117
118 // This needs to be set before calling SetCrashKeyValue(). 103 // This needs to be set before calling SetCrashKeyValue().
119 gBreakpadRef = breakpad; 104 gBreakpadRef = breakpad;
120 105
121 // Set breakpad MetaData values. 106 // Set breakpad MetaData values.
122 NSString* version_str = [info_dictionary objectForKey:@"CFBundleVersion"]; 107 NSString* version_str = [info_dictionary objectForKey:@BREAKPAD_VERSION];
John Grabowski 2009/04/22 00:01:58 Feedback not applied or responded on this line
123 SetCrashKeyValue(@"ver", version_str); 108 SetCrashKeyValue(@"ver", version_str);
124 NSString* prod_name_str = [info_dictionary objectForKey:@"CFBundleExecutable"] ; 109 NSString* prod_name_str = [info_dictionary objectForKey:@BREAKPAD_PRODUCT];
125 SetCrashKeyValue(@"prod", prod_name_str); 110 SetCrashKeyValue(@"prod", prod_name_str);
126 SetCrashKeyValue(@"plat", @"OS X"); 111 SetCrashKeyValue(@"plat", @"OS X");
127 NSString *product_type = is_renderer ? @"renderer" : @"browser"; 112 }
128 SetCrashKeyValue(@"ptype", product_type); 113
114 void InitCrashProcessInfo() {
115 if (gBreakpadRef == NULL) {
116 return;
117 }
118
119 // Determine the process type.
120 NSString *process_type = @"browser";
121 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
122 std::wstring process_type_switch =
123 parsed_command_line.GetSwitchValue(switches::kProcessType);
124 if (!process_type_switch.empty()) {
125 process_type = base::SysWideToNSString(process_type_switch);
126 }
127
128 // Store process type in crash dump.
129 SetCrashKeyValue(@"ptype", process_type);
129 } 130 }
130 131
131 void SetCrashKeyValue(NSString* key, NSString* value) { 132 void SetCrashKeyValue(NSString* key, NSString* value) {
132 // Comment repeated from header to prevent confusion: 133 // Comment repeated from header to prevent confusion:
133 // IMPORTANT: On OS X, the key/value pairs are sent to the crash server 134 // 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 135 // 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! 136 // that if you look at the minidump file locally you won't see them!
136 if (gBreakpadRef == NULL) { 137 if (gBreakpadRef == NULL) {
137 return; 138 return;
138 } 139 }
139 140
140 DCHECK(gBreakpadSetKeyValueFunc != NULL); 141 BreakpadSetKeyValue(gBreakpadRef, key, value);
141 gBreakpadSetKeyValueFunc(gBreakpadRef, key, value);
142 } 142 }
143 143
144 void ClearCrashKeyValue(NSString* key) { 144 void ClearCrashKeyValue(NSString* key) {
145 if (gBreakpadRef == NULL) { 145 if (gBreakpadRef == NULL) {
146 return; 146 return;
147 } 147 }
148 148
149 DCHECK(gBreakpadRemoveKeyValueFunc != NULL); 149 BreakpadRemoveKeyValue(gBreakpadRef, key);
150 gBreakpadRemoveKeyValueFunc(gBreakpadRef, key);
151 } 150 }
OLDNEW
« no previous file with comments | « chrome/app/breakpad_mac.h ('k') | chrome/app/chrome_dll_main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698