| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/crash/content/app/breakpad_mac.h" | 5 #import "components/crash/content/app/breakpad_mac.h" |
| 6 | 6 |
| 7 #include <CoreFoundation/CoreFoundation.h> | 7 #include <CoreFoundation/CoreFoundation.h> |
| 8 #import <Foundation/Foundation.h> | 8 #import <Foundation/Foundation.h> |
| 9 #include <stddef.h> | 9 #include <stddef.h> |
| 10 #include <string.h> | 10 #include <string.h> |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 base::SysUTF8ToNSString(value.as_string())); | 66 base::SysUTF8ToNSString(value.as_string())); |
| 67 } | 67 } |
| 68 } | 68 } |
| 69 | 69 |
| 70 void ClearCrashKeyValueImpl(const base::StringPiece& key) { | 70 void ClearCrashKeyValueImpl(const base::StringPiece& key) { |
| 71 @autoreleasepool { | 71 @autoreleasepool { |
| 72 ClearCrashKeyValue(base::SysUTF8ToNSString(key.as_string())); | 72 ClearCrashKeyValue(base::SysUTF8ToNSString(key.as_string())); |
| 73 } | 73 } |
| 74 } | 74 } |
| 75 | 75 |
| 76 bool FatalMessageHandler(int severity, const char* file, int line, | 76 bool FatalMessageHandler(int severity, const std::string&, int line, |
| 77 size_t message_start, const std::string& str) { | 77 const std::string& str) { |
| 78 // Do not handle non-FATAL. | 78 // Do not handle non-FATAL. |
| 79 if (severity != logging::LOG_FATAL) | 79 if (severity != logging::LOG_FATAL) |
| 80 return false; | 80 return false; |
| 81 | 81 |
| 82 // In case of OOM condition, this code could be reentered when | 82 // In case of OOM condition, this code could be reentered when |
| 83 // constructing and storing the key. Using a static is not | 83 // constructing and storing the key. Using a static is not |
| 84 // thread-safe, but if multiple threads are in the process of a | 84 // thread-safe, but if multiple threads are in the process of a |
| 85 // fatal crash at the same time, this should work. | 85 // fatal crash at the same time, this should work. |
| 86 static bool guarded = false; | 86 static bool guarded = false; |
| 87 if (guarded) | 87 if (guarded) |
| 88 return false; | 88 return false; |
| 89 | 89 |
| 90 base::AutoReset<bool> guard(&guarded, true); | 90 base::AutoReset<bool> guard(&guarded, true); |
| 91 | 91 |
| 92 // Only log last path component. This matches logging.cc. | 92 // Only log last path component. This matches logging.cc. |
| 93 if (file) { | 93 size_t last_slash = file.rfind('/'); |
| 94 const char* slash = strrchr(file, '/'); | 94 if (last_slash == file.npos) |
| 95 if (slash) | 95 last_slash = 0; |
| 96 file = slash + 1; | 96 else |
| 97 } | 97 last_slash++; |
| 98 | 98 |
| 99 NSString* fatal_key = @"LOG_FATAL"; | 99 NSString* fatal_key = @"LOG_FATAL"; |
| 100 NSString* fatal_value = | 100 NSString* fatal_value = |
| 101 [NSString stringWithFormat:@"%s:%d: %s", | 101 [NSString stringWithFormat:@"%s:%d: %s", |
| 102 file, line, str.c_str() + message_start]; | 102 file.substr(last_slash).c_str(), line, |
| 103 str.c_str()]; |
| 103 SetCrashKeyValue(fatal_key, fatal_value); | 104 SetCrashKeyValue(fatal_key, fatal_value); |
| 104 | 105 |
| 105 // Rather than including the code to force the crash here, allow the | 106 // Rather than including the code to force the crash here, allow the |
| 106 // caller to do it. | 107 // caller to do it. |
| 107 return false; | 108 return false; |
| 108 } | 109 } |
| 109 | 110 |
| 110 // BreakpadGenerateAndSendReport() does not report the current | 111 // BreakpadGenerateAndSendReport() does not report the current |
| 111 // thread. This class can be used to spin up a thread to run it. | 112 // thread. This class can be used to spin up a thread to run it. |
| 112 class DumpHelper : public base::PlatformThread::Delegate { | 113 class DumpHelper : public base::PlatformThread::Delegate { |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 base::debug::SetCrashKeyReportingFunctions(&SetCrashKeyValueImpl, | 258 base::debug::SetCrashKeyReportingFunctions(&SetCrashKeyValueImpl, |
| 258 &ClearCrashKeyValueImpl); | 259 &ClearCrashKeyValueImpl); |
| 259 GetCrashReporterClient()->RegisterCrashKeys(); | 260 GetCrashReporterClient()->RegisterCrashKeys(); |
| 260 | 261 |
| 261 // Set Breakpad metadata values. These values are added to Info.plist during | 262 // Set Breakpad metadata values. These values are added to Info.plist during |
| 262 // the branded Google Chrome.app build. | 263 // the branded Google Chrome.app build. |
| 263 SetCrashKeyValue(@"ver", [info_dictionary objectForKey:@BREAKPAD_VERSION]); | 264 SetCrashKeyValue(@"ver", [info_dictionary objectForKey:@BREAKPAD_VERSION]); |
| 264 SetCrashKeyValue(@"prod", [info_dictionary objectForKey:@BREAKPAD_PRODUCT]); | 265 SetCrashKeyValue(@"prod", [info_dictionary objectForKey:@BREAKPAD_PRODUCT]); |
| 265 SetCrashKeyValue(@"plat", @"OS X"); | 266 SetCrashKeyValue(@"plat", @"OS X"); |
| 266 | 267 |
| 267 logging::SetLogMessageHandler(&FatalMessageHandler); | 268 logging::AddLogMessageHandler(&FatalMessageHandler); |
| 268 base::debug::SetDumpWithoutCrashingFunction(&DumpHelper::DumpWithoutCrashing); | 269 base::debug::SetDumpWithoutCrashingFunction(&DumpHelper::DumpWithoutCrashing); |
| 269 | 270 |
| 270 // abort() sends SIGABRT, which breakpad does not intercept. | 271 // abort() sends SIGABRT, which breakpad does not intercept. |
| 271 // Register a signal handler to crash in a way breakpad will | 272 // Register a signal handler to crash in a way breakpad will |
| 272 // intercept. | 273 // intercept. |
| 273 struct sigaction sigact; | 274 struct sigaction sigact; |
| 274 memset(&sigact, 0, sizeof(sigact)); | 275 memset(&sigact, 0, sizeof(sigact)); |
| 275 sigact.sa_handler = SIGABRTHandler; | 276 sigact.sa_handler = SIGABRTHandler; |
| 276 CHECK(0 == sigaction(SIGABRT, &sigact, NULL)); | 277 CHECK(0 == sigaction(SIGABRT, &sigact, NULL)); |
| 277 } | 278 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 289 | 290 |
| 290 // Store process type in crash dump. | 291 // Store process type in crash dump. |
| 291 SetCrashKeyValue(@"ptype", process_type); | 292 SetCrashKeyValue(@"ptype", process_type); |
| 292 | 293 |
| 293 NSString* pid_value = | 294 NSString* pid_value = |
| 294 [NSString stringWithFormat:@"%d", static_cast<unsigned int>(getpid())]; | 295 [NSString stringWithFormat:@"%d", static_cast<unsigned int>(getpid())]; |
| 295 SetCrashKeyValue(@"pid", pid_value); | 296 SetCrashKeyValue(@"pid", pid_value); |
| 296 } | 297 } |
| 297 | 298 |
| 298 } // namespace breakpad | 299 } // namespace breakpad |
| OLD | NEW |