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