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

Side by Side Diff: client/mac/Framework/Breakpad.mm

Issue 571523004: Mac: Add support for in-process crash reporting (Closed) Base URL: https://chromium.googlesource.com/external/google-breakpad/src.git@master
Patch Set: Implement launching of reporter app Created 6 years, 3 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
OLDNEW
1 // Copyright (c) 2006, Google Inc. 1 // Copyright (c) 2006, Google Inc.
2 // All rights reserved. 2 // All rights reserved.
3 // 3 //
4 // Redistribution and use in source and binary forms, with or without 4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are 5 // modification, are permitted provided that the following conditions are
6 // met: 6 // met:
7 // 7 //
8 // * Redistributions of source code must retain the above copyright 8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer. 9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above 10 // * Redistributions in binary form must reproduce the above
(...skipping 26 matching lines...) Expand all
37 #import <Foundation/Foundation.h> 37 #import <Foundation/Foundation.h>
38 #include <pthread.h> 38 #include <pthread.h>
39 #include <sys/stat.h> 39 #include <sys/stat.h>
40 #include <sys/sysctl.h> 40 #include <sys/sysctl.h>
41 41
42 #import "client/mac/crash_generation/Inspector.h" 42 #import "client/mac/crash_generation/Inspector.h"
43 #import "client/mac/handler/exception_handler.h" 43 #import "client/mac/handler/exception_handler.h"
44 #import "client/mac/Framework/Breakpad.h" 44 #import "client/mac/Framework/Breakpad.h"
45 #import "client/mac/Framework/OnDemandServer.h" 45 #import "client/mac/Framework/OnDemandServer.h"
46 #import "client/mac/handler/protected_memory_allocator.h" 46 #import "client/mac/handler/protected_memory_allocator.h"
47 #include "common/mac/launch_reporter.h"
47 #import "common/mac/MachIPC.h" 48 #import "common/mac/MachIPC.h"
48 #import "common/simple_string_dictionary.h" 49 #import "common/simple_string_dictionary.h"
49 50
50 #ifndef __EXCEPTIONS 51 #ifndef __EXCEPTIONS
51 // This file uses C++ try/catch (but shouldn't). Duplicate the macros from 52 // This file uses C++ try/catch (but shouldn't). Duplicate the macros from
52 // <c++/4.2.1/exception_defines.h> allowing this file to work properly with 53 // <c++/4.2.1/exception_defines.h> allowing this file to work properly with
53 // exceptions disabled even when other C++ libraries are used. #undef the try 54 // exceptions disabled even when other C++ libraries are used. #undef the try
54 // and catch macros first in case libstdc++ is in use and has already provided 55 // and catch macros first in case libstdc++ is in use and has already provided
55 // its own definitions. 56 // its own definitions.
56 #undef try 57 #undef try
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 Breakpad() 167 Breakpad()
167 : handler_(NULL), 168 : handler_(NULL),
168 config_params_(NULL), 169 config_params_(NULL),
169 send_and_exit_(true), 170 send_and_exit_(true),
170 filter_callback_(NULL), 171 filter_callback_(NULL),
171 filter_callback_context_(NULL) { 172 filter_callback_context_(NULL) {
172 inspector_path_[0] = 0; 173 inspector_path_[0] = 0;
173 } 174 }
174 175
175 bool Initialize(NSDictionary *parameters); 176 bool Initialize(NSDictionary *parameters);
177 bool InitializeInProcess(NSDictionary *parameters);
178 bool InitializeOutOfProcess(NSDictionary *parameters);
176 179
177 bool ExtractParameters(NSDictionary *parameters); 180 bool ExtractParameters(NSDictionary *parameters);
178 181
179 // Dispatches to HandleException() 182 // Dispatches to HandleException()
180 static bool ExceptionHandlerDirectCallback(void *context, 183 static bool ExceptionHandlerDirectCallback(void *context,
181 int exception_type, 184 int exception_type,
182 int exception_code, 185 int exception_code,
183 int exception_subcode, 186 int exception_subcode,
184 mach_port_t crashing_thread); 187 mach_port_t crashing_thread);
185 188
186 bool HandleException(int exception_type, 189 bool HandleException(int exception_type,
187 int exception_code, 190 int exception_code,
188 int exception_subcode, 191 int exception_subcode,
189 mach_port_t crashing_thread); 192 mach_port_t crashing_thread);
190 193
194 // Dispatches to HandleMinidump()
195 static bool HandleMinidumpCallback(const char *dump_dir,
196 const char *minidump_id,
197 void *context, bool succeeded);
198
199 bool HandleMinidump(const char *dump_dir,
200 const char *minidump_id);
201
191 // Since ExceptionHandler (w/o namespace) is defined as typedef in OSX's 202 // Since ExceptionHandler (w/o namespace) is defined as typedef in OSX's
192 // MachineExceptions.h, we have to explicitly name the handler. 203 // MachineExceptions.h, we have to explicitly name the handler.
193 google_breakpad::ExceptionHandler *handler_; // The actual handler (STRONG) 204 google_breakpad::ExceptionHandler *handler_; // The actual handler (STRONG)
194 205
195 char inspector_path_[PATH_MAX]; // Path to inspector tool 206 char inspector_path_[PATH_MAX]; // Path to inspector tool
196 207
197 SimpleStringDictionary *config_params_; // Create parameters (STRONG) 208 SimpleStringDictionary *config_params_; // Create parameters (STRONG)
198 209
199 OnDemandServer inspector_; 210 OnDemandServer inspector_;
200 211
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 if (!breakpad) 270 if (!breakpad)
260 return false; 271 return false;
261 272
262 return breakpad->HandleException( exception_type, 273 return breakpad->HandleException( exception_type,
263 exception_code, 274 exception_code,
264 exception_subcode, 275 exception_subcode,
265 crashing_thread); 276 crashing_thread);
266 } 277 }
267 278
268 //============================================================================= 279 //=============================================================================
280 bool Breakpad::HandleMinidumpCallback(const char *dump_dir,
281 const char *minidump_id,
282 void *context, bool succeeded) {
283 Breakpad *breakpad = (Breakpad *)context;
284
285 // If our context is damaged or something, just return false to indicate that
286 // the handler should continue without us.
287 if (!breakpad || !succeeded)
288 return false;
289
290 return breakpad->HandleMinidump(dump_dir, minidump_id);
291 }
292
293 //=============================================================================
269 #pragma mark - 294 #pragma mark -
270 295
271 #include <dlfcn.h> 296 #include <dlfcn.h>
272 297
273 //============================================================================= 298 //=============================================================================
274 // Returns the pathname to the Resources directory for this version of 299 // Returns the pathname to the Resources directory for this version of
275 // Breakpad which we are now running. 300 // Breakpad which we are now running.
276 // 301 //
277 // Don't make the function static, since _dyld_lookup_and_bind_fully needs a 302 // Don't make the function static, since _dyld_lookup_and_bind_fully needs a
278 // simple non-static C name 303 // simple non-static C name
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 // Check for debugger 344 // Check for debugger
320 if (IsDebuggerActive()) { 345 if (IsDebuggerActive()) {
321 return true; 346 return true;
322 } 347 }
323 348
324 // Gather any user specified parameters 349 // Gather any user specified parameters
325 if (!ExtractParameters(parameters)) { 350 if (!ExtractParameters(parameters)) {
326 return false; 351 return false;
327 } 352 }
328 353
354 if ([[parameters objectForKey:@BREAKPAD_IN_PROCESS] boolValue])
355 return InitializeInProcess(parameters);
356 else
357 return InitializeOutOfProcess(parameters);
358 }
359
360 //=============================================================================
361 bool Breakpad::InitializeInProcess(NSDictionary* parameters) {
362 handler_ =
363 new (gBreakpadAllocator->Allocate(
364 sizeof(google_breakpad::ExceptionHandler)))
365 google_breakpad::ExceptionHandler(
366 config_params_->GetValueForKey(BREAKPAD_DUMP_DIRECTORY),
367 0, &HandleMinidumpCallback, this, true, 0);
368 return true;
369 }
370
371 //=============================================================================
372 bool Breakpad::InitializeOutOfProcess(NSDictionary* parameters) {
329 // Get path to Inspector executable. 373 // Get path to Inspector executable.
330 NSString *inspectorPathString = KeyValue(@BREAKPAD_INSPECTOR_LOCATION); 374 NSString *inspectorPathString = KeyValue(@BREAKPAD_INSPECTOR_LOCATION);
331 375
332 // Standardize path (resolve symlinkes, etc.) and escape spaces 376 // Standardize path (resolve symlinkes, etc.) and escape spaces
333 inspectorPathString = [inspectorPathString stringByStandardizingPath]; 377 inspectorPathString = [inspectorPathString stringByStandardizingPath];
334 inspectorPathString = [[inspectorPathString componentsSeparatedByString:@" "] 378 inspectorPathString = [[inspectorPathString componentsSeparatedByString:@" "]
335 componentsJoinedByString:@"\\ "]; 379 componentsJoinedByString:@"\\ "];
336 380
337 // Create an on-demand server object representing the Inspector. 381 // Create an on-demand server object representing the Inspector.
338 // In case of a crash, we simply need to call the LaunchOnDemand() 382 // In case of a crash, we simply need to call the LaunchOnDemand()
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 #endif 748 #endif
705 749
706 // If we don't want any forwarding, return true here to indicate that we've 750 // If we don't want any forwarding, return true here to indicate that we've
707 // processed things as much as we want. 751 // processed things as much as we want.
708 if (send_and_exit_) return true; 752 if (send_and_exit_) return true;
709 753
710 return false; 754 return false;
711 } 755 }
712 756
713 //============================================================================= 757 //=============================================================================
758 bool Breakpad::HandleMinidump(const char *dump_dir,
759 const char *minidump_id) {
760 google_breakpad::ConfigFile config_file;
761 config_file.WriteFile(dump_dir, config_params_, dump_dir, minidump_id);
762 google_breakpad::LaunchReporter(
763 config_params_->GetValueForKey(BREAKPAD_REPORTER_EXE_LOCATION),
764 config_file.GetFilePath());
765 return true;
766 }
767
768 //=============================================================================
714 //============================================================================= 769 //=============================================================================
715 770
716 #pragma mark - 771 #pragma mark -
717 #pragma mark Public API 772 #pragma mark Public API
718 773
719 //============================================================================= 774 //=============================================================================
720 BreakpadRef BreakpadCreate(NSDictionary *parameters) { 775 BreakpadRef BreakpadCreate(NSDictionary *parameters) {
721 try { 776 try {
722 // This is confusing. Our two main allocators for breakpad memory are: 777 // This is confusing. Our two main allocators for breakpad memory are:
723 // - gKeyValueAllocator for the key/value memory 778 // - gKeyValueAllocator for the key/value memory
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
976 } 1031 }
977 logFileCounter++; 1032 logFileCounter++;
978 logFileKey = [NSString stringWithFormat:@"%@%d", 1033 logFileKey = [NSString stringWithFormat:@"%@%d",
979 @BREAKPAD_LOGFILE_KEY_PREFIX, 1034 @BREAKPAD_LOGFILE_KEY_PREFIX,
980 logFileCounter]; 1035 logFileCounter];
981 existingLogFilename = BreakpadKeyValue(ref, logFileKey); 1036 existingLogFilename = BreakpadKeyValue(ref, logFileKey);
982 } 1037 }
983 1038
984 BreakpadSetKeyValue(ref, logFileKey, logPathname); 1039 BreakpadSetKeyValue(ref, logFileKey, logPathname);
985 } 1040 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698