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

Side by Side Diff: components/crash/content/app/crashpad.cc

Issue 1479283002: Reland: Crashpad Windows: Use the Crashpad client instead of Breakpad on Windows (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: with crashpad 1f3ced1846f3956e678c562c90e0d6c970543617 Created 5 years 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 | « components/crash/content/app/crashpad.h ('k') | components/crash/content/app/crashpad_mac.h » ('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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #include "components/crash/content/app/crashpad_mac.h" 5 #include "components/crash/content/app/crashpad.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 #include <unistd.h>
9 8
10 #include <algorithm> 9 #include <algorithm>
11 #include <map> 10 #include <map>
12 #include <vector> 11 #include <vector>
13 12
14 #include "base/auto_reset.h" 13 #include "base/auto_reset.h"
14 #include "base/command_line.h"
15 #include "base/debug/crash_logging.h" 15 #include "base/debug/crash_logging.h"
16 #include "base/debug/dump_without_crashing.h" 16 #include "base/debug/dump_without_crashing.h"
17 #include "base/files/file_path.h"
18 #include "base/logging.h" 17 #include "base/logging.h"
19 #include "base/mac/bundle_locations.h"
20 #include "base/mac/foundation_util.h"
21 #include "base/strings/string_number_conversions.h" 18 #include "base/strings/string_number_conversions.h"
22 #include "base/strings/string_piece.h" 19 #include "base/strings/string_piece.h"
23 #include "base/strings/stringprintf.h" 20 #include "base/strings/stringprintf.h"
24 #include "base/strings/sys_string_conversions.h" 21 #include "base/strings/sys_string_conversions.h"
22 #include "build/build_config.h"
25 #include "components/crash/content/app/crash_reporter_client.h" 23 #include "components/crash/content/app/crash_reporter_client.h"
26 #include "third_party/crashpad/crashpad/client/crash_report_database.h" 24 #include "third_party/crashpad/crashpad/client/crash_report_database.h"
27 #include "third_party/crashpad/crashpad/client/crashpad_client.h" 25 #include "third_party/crashpad/crashpad/client/crashpad_client.h"
28 #include "third_party/crashpad/crashpad/client/crashpad_info.h" 26 #include "third_party/crashpad/crashpad/client/crashpad_info.h"
29 #include "third_party/crashpad/crashpad/client/settings.h" 27 #include "third_party/crashpad/crashpad/client/settings.h"
30 #include "third_party/crashpad/crashpad/client/simple_string_dictionary.h" 28 #include "third_party/crashpad/crashpad/client/simple_string_dictionary.h"
31 #include "third_party/crashpad/crashpad/client/simulate_crash.h" 29 #include "third_party/crashpad/crashpad/client/simulate_crash.h"
32 30
31 #if defined(OS_POSIX)
32 #include <unistd.h>
33 #endif // OS_POSIX
34
33 namespace crash_reporter { 35 namespace crash_reporter {
34 36
35 namespace { 37 namespace {
36 38
37 crashpad::SimpleStringDictionary* g_simple_string_dictionary; 39 crashpad::SimpleStringDictionary* g_simple_string_dictionary;
38 crashpad::CrashReportDatabase* g_database; 40 crashpad::CrashReportDatabase* g_database;
39 41
40 void SetCrashKeyValue(const base::StringPiece& key, 42 void SetCrashKeyValue(const base::StringPiece& key,
41 const base::StringPiece& value) { 43 const base::StringPiece& value) {
42 g_simple_string_dictionary->SetKeyValue(key.data(), value.data()); 44 g_simple_string_dictionary->SetKeyValue(key.data(), value.data());
(...skipping 24 matching lines...) Expand all
67 base::AutoReset<bool> guard(&guarded, true); 69 base::AutoReset<bool> guard(&guarded, true);
68 70
69 // Only log last path component. This matches logging.cc. 71 // Only log last path component. This matches logging.cc.
70 if (file) { 72 if (file) {
71 const char* slash = strrchr(file, '/'); 73 const char* slash = strrchr(file, '/');
72 if (slash) { 74 if (slash) {
73 file = slash + 1; 75 file = slash + 1;
74 } 76 }
75 } 77 }
76 78
79 CHECK_LE(message_start, string.size());
77 std::string message = base::StringPrintf("%s:%d: %s", file, line, 80 std::string message = base::StringPrintf("%s:%d: %s", file, line,
78 string.c_str() + message_start); 81 string.c_str() + message_start);
79 SetCrashKeyValue("LOG_FATAL", message); 82 SetCrashKeyValue("LOG_FATAL", message);
80 83
81 // Rather than including the code to force the crash here, allow the caller to 84 // Rather than including the code to force the crash here, allow the caller to
82 // do it. 85 // do it.
83 return false; 86 return false;
84 } 87 }
85 88
86 void DumpWithoutCrashing() { 89 void DumpWithoutCrashing() {
87 CRASHPAD_SIMULATE_CRASH(); 90 CRASHPAD_SIMULATE_CRASH();
88 } 91 }
89 92
90 } // namespace 93 } // namespace
91 94
92 void InitializeCrashpad(bool initial_client, const std::string& process_type) { 95 void InitializeCrashpad(bool initial_client, const std::string& process_type) {
93 static bool initialized = false; 96 static bool initialized = false;
94 DCHECK(!initialized); 97 DCHECK(!initialized);
95 initialized = true; 98 initialized = true;
96 99
97 const bool browser_process = process_type.empty(); 100 const bool browser_process = process_type.empty();
98 CrashReporterClient* crash_reporter_client = GetCrashReporterClient(); 101 CrashReporterClient* crash_reporter_client = GetCrashReporterClient();
99 102
100 if (initial_client) { 103 if (initial_client) {
104 #if defined(OS_MACOSX)
101 // "relauncher" is hard-coded because it's a Chrome --type, but this 105 // "relauncher" is hard-coded because it's a Chrome --type, but this
102 // component can't see Chrome's switches. This is only used for argument 106 // component can't see Chrome's switches. This is only used for argument
103 // sanitization. 107 // sanitization.
104 DCHECK(browser_process || process_type == "relauncher"); 108 DCHECK(browser_process || process_type == "relauncher");
109 #else
110 DCHECK(browser_process);
111 #endif // OS_MACOSX
105 } else { 112 } else {
106 DCHECK(!browser_process); 113 DCHECK(!browser_process);
107 } 114 }
108 115
109 base::FilePath database_path; // Only valid in the browser process. 116 // database_path is only valid in the browser process.
110 117 base::FilePath database_path =
111 if (initial_client) { 118 internal::PlatformCrashpadInitialization(initial_client, browser_process);
112 @autoreleasepool {
113 base::FilePath framework_bundle_path = base::mac::FrameworkBundlePath();
114 base::FilePath handler_path =
115 framework_bundle_path.Append("Helpers").Append("crashpad_handler");
116
117 // Is there a way to recover if this fails?
118 crash_reporter_client->GetCrashDumpLocation(&database_path);
119
120 // TODO(mark): Reading the Breakpad keys is temporary and transitional. At
121 // the very least, they should be renamed to Crashpad. For the time being,
122 // this isn't the worst thing: Crashpad is still uploading to a
123 // Breakpad-type server, after all.
124 NSBundle* framework_bundle = base::mac::FrameworkBundle();
125 NSString* product = base::mac::ObjCCast<NSString>(
126 [framework_bundle objectForInfoDictionaryKey:@"BreakpadProduct"]);
127 NSString* version = base::mac::ObjCCast<NSString>(
128 [framework_bundle objectForInfoDictionaryKey:@"BreakpadVersion"]);
129 NSString* url_ns = base::mac::ObjCCast<NSString>(
130 [framework_bundle objectForInfoDictionaryKey:@"BreakpadURL"]);
131
132 std::string url = base::SysNSStringToUTF8(url_ns);
133
134 std::map<std::string, std::string> process_annotations;
135 process_annotations["prod"] = base::SysNSStringToUTF8(product);
136 process_annotations["ver"] = base::SysNSStringToUTF8(version);
137 process_annotations["plat"] = std::string("OS X");
138
139 crashpad::CrashpadClient crashpad_client;
140
141 std::vector<std::string> arguments;
142 if (!browser_process) {
143 // If this is an initial client that's not the browser process, it's
144 // important that the new Crashpad handler also not be connected to any
145 // existing handler. This argument tells the new Crashpad handler to
146 // sever this connection.
147 arguments.push_back(
148 "--reset-own-crash-exception-port-to-system-default");
149 }
150
151 bool result = crashpad_client.StartHandler(handler_path,
152 database_path,
153 url,
154 process_annotations,
155 arguments,
156 true);
157 if (result) {
158 result = crashpad_client.UseHandler();
159 }
160
161 // If this is an initial client that's not the browser process, it's
162 // important to sever the connection to any existing handler. If
163 // StartHandler() or UseHandler() failed, call UseSystemDefaultHandler()
164 // in that case to drop the link to the existing handler.
165 if (!result && !browser_process) {
166 crashpad::CrashpadClient::UseSystemDefaultHandler();
167 }
168 } // @autoreleasepool
169 }
170 119
171 crashpad::CrashpadInfo* crashpad_info = 120 crashpad::CrashpadInfo* crashpad_info =
172 crashpad::CrashpadInfo::GetCrashpadInfo(); 121 crashpad::CrashpadInfo::GetCrashpadInfo();
173 122
123 #if defined(OS_MACOSX)
174 #if defined(NDEBUG) 124 #if defined(NDEBUG)
175 const bool is_debug_build = false; 125 const bool is_debug_build = false;
176 #else 126 #else
177 const bool is_debug_build = true; 127 const bool is_debug_build = true;
178 #endif 128 #endif
179 129
180 // Disable forwarding to the system's crash reporter in processes other than 130 // Disable forwarding to the system's crash reporter in processes other than
181 // the browser process. For the browser, the system's crash reporter presents 131 // the browser process. For the browser, the system's crash reporter presents
182 // the crash UI to the user, so it's desirable there. Additionally, having 132 // the crash UI to the user, so it's desirable there. Additionally, having
183 // crash reports appear in ~/Library/Logs/DiagnosticReports provides a 133 // crash reports appear in ~/Library/Logs/DiagnosticReports provides a
184 // fallback. Forwarding is turned off for debug-mode builds even for the 134 // fallback. Forwarding is turned off for debug-mode builds even for the
185 // browser process, because the system's crash reporter can take a very long 135 // browser process, because the system's crash reporter can take a very long
186 // time to chew on symbols. 136 // time to chew on symbols.
187 if (!browser_process || is_debug_build) { 137 if (!browser_process || is_debug_build) {
188 crashpad_info->set_system_crash_reporter_forwarding( 138 crashpad_info->set_system_crash_reporter_forwarding(
189 crashpad::TriState::kDisabled); 139 crashpad::TriState::kDisabled);
190 } 140 }
141 #endif // OS_MACOSX
191 142
192 g_simple_string_dictionary = new crashpad::SimpleStringDictionary(); 143 g_simple_string_dictionary = new crashpad::SimpleStringDictionary();
193 crashpad_info->set_simple_annotations(g_simple_string_dictionary); 144 crashpad_info->set_simple_annotations(g_simple_string_dictionary);
194 145
195 base::debug::SetCrashKeyReportingFunctions(SetCrashKeyValue, ClearCrashKey); 146 base::debug::SetCrashKeyReportingFunctions(SetCrashKeyValue, ClearCrashKey);
196 crash_reporter_client->RegisterCrashKeys(); 147 crash_reporter_client->RegisterCrashKeys();
197 148
198 SetCrashKeyValue("ptype", browser_process ? base::StringPiece("browser") 149 SetCrashKeyValue("ptype", browser_process ? base::StringPiece("browser")
199 : base::StringPiece(process_type)); 150 : base::StringPiece(process_type));
151 #if defined(OS_POSIX)
200 SetCrashKeyValue("pid", base::IntToString(getpid())); 152 SetCrashKeyValue("pid", base::IntToString(getpid()));
153 #elif defined(OS_WIN)
154 SetCrashKeyValue("pid", base::IntToString(::GetCurrentProcessId()));
155 #endif
201 156
202 logging::SetLogMessageHandler(LogMessageHandler); 157 logging::SetLogMessageHandler(LogMessageHandler);
203 158
204 // If clients called CRASHPAD_SIMULATE_CRASH() instead of 159 // If clients called CRASHPAD_SIMULATE_CRASH() instead of
205 // base::debug::DumpWithoutCrashing(), these dumps would appear as crashes in 160 // base::debug::DumpWithoutCrashing(), these dumps would appear as crashes in
206 // the correct function, at the correct file and line. This would be 161 // the correct function, at the correct file and line. This would be
207 // preferable to having all occurrences show up in DumpWithoutCrashing() at 162 // preferable to having all occurrences show up in DumpWithoutCrashing() at
208 // the same file and line. 163 // the same file and line.
209 base::debug::SetDumpWithoutCrashingFunction(DumpWithoutCrashing); 164 base::debug::SetDumpWithoutCrashingFunction(DumpWithoutCrashing);
210 165
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 if (completed_report.uploaded) { 220 if (completed_report.uploaded) {
266 UploadedReport uploaded_report; 221 UploadedReport uploaded_report;
267 uploaded_report.local_id = completed_report.uuid.ToString(); 222 uploaded_report.local_id = completed_report.uuid.ToString();
268 uploaded_report.remote_id = completed_report.id; 223 uploaded_report.remote_id = completed_report.id;
269 uploaded_report.creation_time = completed_report.creation_time; 224 uploaded_report.creation_time = completed_report.creation_time;
270 225
271 uploaded_reports->push_back(uploaded_report); 226 uploaded_reports->push_back(uploaded_report);
272 } 227 }
273 } 228 }
274 229
275 struct { 230 std::sort(uploaded_reports->begin(), uploaded_reports->end(),
276 bool operator()(const UploadedReport& a, const UploadedReport& b) { 231 [](const UploadedReport& a, const UploadedReport& b) {
277 return a.creation_time >= b.creation_time; 232 return a.creation_time >= b.creation_time;
278 } 233 });
279 } sort_by_time;
280 std::sort(uploaded_reports->begin(), uploaded_reports->end(), sort_by_time);
281 } 234 }
282 235
283 } // namespace crash_reporter 236 } // namespace crash_reporter
OLDNEW
« no previous file with comments | « components/crash/content/app/crashpad.h ('k') | components/crash/content/app/crashpad_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698