Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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 // This gets called instead of ExceptionHandlerDirectCallback when running | |
| 196 // with the BREAKPAD_IN_PROCESS option. | |
| 197 static bool HandleMinidumpCallback(const char *dump_dir, | |
| 198 const char *minidump_id, | |
| 199 void *context, bool succeeded); | |
|
Mark Mentovai
2014/09/15 13:38:44
If you have to break parameters up to take more th
Andre
2014/09/15 17:42:39
Done.
| |
| 200 | |
| 201 bool HandleMinidump(const char *dump_dir, | |
|
Mark Mentovai
2014/09/15 13:38:44
This should also have a comment explaining that it
Andre
2014/09/15 17:42:39
Done.
This method does not actually write the mini
| |
| 202 const char *minidump_id); | |
|
Mark Mentovai
2014/09/15 13:38:44
Nit (may be irrelevant if the method is renamed):
Andre
2014/09/15 17:42:39
Done.
| |
| 203 | |
| 191 // Since ExceptionHandler (w/o namespace) is defined as typedef in OSX's | 204 // Since ExceptionHandler (w/o namespace) is defined as typedef in OSX's |
| 192 // MachineExceptions.h, we have to explicitly name the handler. | 205 // MachineExceptions.h, we have to explicitly name the handler. |
| 193 google_breakpad::ExceptionHandler *handler_; // The actual handler (STRONG) | 206 google_breakpad::ExceptionHandler *handler_; // The actual handler (STRONG) |
| 194 | 207 |
| 195 char inspector_path_[PATH_MAX]; // Path to inspector tool | 208 char inspector_path_[PATH_MAX]; // Path to inspector tool |
| 196 | 209 |
| 197 SimpleStringDictionary *config_params_; // Create parameters (STRONG) | 210 SimpleStringDictionary *config_params_; // Create parameters (STRONG) |
| 198 | 211 |
| 199 OnDemandServer inspector_; | 212 OnDemandServer inspector_; |
| 200 | 213 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 259 if (!breakpad) | 272 if (!breakpad) |
| 260 return false; | 273 return false; |
| 261 | 274 |
| 262 return breakpad->HandleException( exception_type, | 275 return breakpad->HandleException( exception_type, |
| 263 exception_code, | 276 exception_code, |
| 264 exception_subcode, | 277 exception_subcode, |
| 265 crashing_thread); | 278 crashing_thread); |
| 266 } | 279 } |
| 267 | 280 |
| 268 //============================================================================= | 281 //============================================================================= |
| 282 bool Breakpad::HandleMinidumpCallback(const char *dump_dir, | |
| 283 const char *minidump_id, | |
| 284 void *context, bool succeeded) { | |
|
Mark Mentovai
2014/09/15 13:38:44
As above.
Andre
2014/09/15 17:42:39
Done.
| |
| 285 Breakpad *breakpad = (Breakpad *)context; | |
| 286 | |
| 287 // If our context is damaged or something, just return false to indicate that | |
| 288 // the handler should continue without us. | |
| 289 if (!breakpad || !succeeded) | |
| 290 return false; | |
| 291 | |
| 292 return breakpad->HandleMinidump(dump_dir, minidump_id); | |
| 293 } | |
| 294 | |
| 295 //============================================================================= | |
| 269 #pragma mark - | 296 #pragma mark - |
| 270 | 297 |
| 271 #include <dlfcn.h> | 298 #include <dlfcn.h> |
| 272 | 299 |
| 273 //============================================================================= | 300 //============================================================================= |
| 274 // Returns the pathname to the Resources directory for this version of | 301 // Returns the pathname to the Resources directory for this version of |
| 275 // Breakpad which we are now running. | 302 // Breakpad which we are now running. |
| 276 // | 303 // |
| 277 // Don't make the function static, since _dyld_lookup_and_bind_fully needs a | 304 // Don't make the function static, since _dyld_lookup_and_bind_fully needs a |
| 278 // simple non-static C name | 305 // simple non-static C name |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 319 // Check for debugger | 346 // Check for debugger |
| 320 if (IsDebuggerActive()) { | 347 if (IsDebuggerActive()) { |
| 321 return true; | 348 return true; |
| 322 } | 349 } |
| 323 | 350 |
| 324 // Gather any user specified parameters | 351 // Gather any user specified parameters |
| 325 if (!ExtractParameters(parameters)) { | 352 if (!ExtractParameters(parameters)) { |
| 326 return false; | 353 return false; |
| 327 } | 354 } |
| 328 | 355 |
| 356 if ([[parameters objectForKey:@BREAKPAD_IN_PROCESS] boolValue]) | |
| 357 return InitializeInProcess(parameters); | |
| 358 else | |
| 359 return InitializeOutOfProcess(parameters); | |
| 360 } | |
| 361 | |
| 362 //============================================================================= | |
| 363 bool Breakpad::InitializeInProcess(NSDictionary* parameters) { | |
| 364 handler_ = | |
| 365 new (gBreakpadAllocator->Allocate( | |
| 366 sizeof(google_breakpad::ExceptionHandler))) | |
| 367 google_breakpad::ExceptionHandler( | |
| 368 config_params_->GetValueForKey(BREAKPAD_DUMP_DIRECTORY), | |
| 369 0, &HandleMinidumpCallback, this, true, 0); | |
| 370 return true; | |
| 371 } | |
| 372 | |
| 373 //============================================================================= | |
| 374 bool Breakpad::InitializeOutOfProcess(NSDictionary* parameters) { | |
| 329 // Get path to Inspector executable. | 375 // Get path to Inspector executable. |
| 330 NSString *inspectorPathString = KeyValue(@BREAKPAD_INSPECTOR_LOCATION); | 376 NSString *inspectorPathString = KeyValue(@BREAKPAD_INSPECTOR_LOCATION); |
| 331 | 377 |
| 332 // Standardize path (resolve symlinkes, etc.) and escape spaces | 378 // Standardize path (resolve symlinkes, etc.) and escape spaces |
| 333 inspectorPathString = [inspectorPathString stringByStandardizingPath]; | 379 inspectorPathString = [inspectorPathString stringByStandardizingPath]; |
| 334 inspectorPathString = [[inspectorPathString componentsSeparatedByString:@" "] | 380 inspectorPathString = [[inspectorPathString componentsSeparatedByString:@" "] |
| 335 componentsJoinedByString:@"\\ "]; | 381 componentsJoinedByString:@"\\ "]; |
| 336 | 382 |
| 337 // Create an on-demand server object representing the Inspector. | 383 // Create an on-demand server object representing the Inspector. |
| 338 // In case of a crash, we simply need to call the LaunchOnDemand() | 384 // In case of a crash, we simply need to call the LaunchOnDemand() |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 704 #endif | 750 #endif |
| 705 | 751 |
| 706 // If we don't want any forwarding, return true here to indicate that we've | 752 // If we don't want any forwarding, return true here to indicate that we've |
| 707 // processed things as much as we want. | 753 // processed things as much as we want. |
| 708 if (send_and_exit_) return true; | 754 if (send_and_exit_) return true; |
| 709 | 755 |
| 710 return false; | 756 return false; |
| 711 } | 757 } |
| 712 | 758 |
| 713 //============================================================================= | 759 //============================================================================= |
| 760 bool Breakpad::HandleMinidump(const char *dump_dir, | |
| 761 const char *minidump_id) { | |
| 762 google_breakpad::ConfigFile config_file; | |
| 763 config_file.WriteFile(dump_dir, config_params_, dump_dir, minidump_id); | |
| 764 google_breakpad::LaunchReporter( | |
| 765 config_params_->GetValueForKey(BREAKPAD_REPORTER_EXE_LOCATION), | |
| 766 config_file.GetFilePath()); | |
| 767 return true; | |
| 768 } | |
| 769 | |
| 770 //============================================================================= | |
| 714 //============================================================================= | 771 //============================================================================= |
| 715 | 772 |
| 716 #pragma mark - | 773 #pragma mark - |
| 717 #pragma mark Public API | 774 #pragma mark Public API |
| 718 | 775 |
| 719 //============================================================================= | 776 //============================================================================= |
| 720 BreakpadRef BreakpadCreate(NSDictionary *parameters) { | 777 BreakpadRef BreakpadCreate(NSDictionary *parameters) { |
| 721 try { | 778 try { |
| 722 // This is confusing. Our two main allocators for breakpad memory are: | 779 // This is confusing. Our two main allocators for breakpad memory are: |
| 723 // - gKeyValueAllocator for the key/value memory | 780 // - gKeyValueAllocator for the key/value memory |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 976 } | 1033 } |
| 977 logFileCounter++; | 1034 logFileCounter++; |
| 978 logFileKey = [NSString stringWithFormat:@"%@%d", | 1035 logFileKey = [NSString stringWithFormat:@"%@%d", |
| 979 @BREAKPAD_LOGFILE_KEY_PREFIX, | 1036 @BREAKPAD_LOGFILE_KEY_PREFIX, |
| 980 logFileCounter]; | 1037 logFileCounter]; |
| 981 existingLogFilename = BreakpadKeyValue(ref, logFileKey); | 1038 existingLogFilename = BreakpadKeyValue(ref, logFileKey); |
| 982 } | 1039 } |
| 983 | 1040 |
| 984 BreakpadSetKeyValue(ref, logFileKey, logPathname); | 1041 BreakpadSetKeyValue(ref, logFileKey, logPathname); |
| 985 } | 1042 } |
| OLD | NEW |