| 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 class FatalMessageHandler : logging::LogMessageHandler { |
| 77 size_t message_start, const std::string& str) { | 77 bool OnMessage(int severity, |
| 78 const char* file, |
| 79 int line, |
| 80 size_t message_start, |
| 81 const std::string& str) override; |
| 82 }; |
| 83 |
| 84 bool FatalMessageHandler::OnMessage(int severity, |
| 85 const char* file, |
| 86 int line, |
| 87 size_t message_start, |
| 88 const std::string& str) { |
| 78 // Do not handle non-FATAL. | 89 // Do not handle non-FATAL. |
| 79 if (severity != logging::LOG_FATAL) | 90 if (severity != logging::LOG_FATAL) |
| 80 return false; | 91 return false; |
| 81 | 92 |
| 82 // In case of OOM condition, this code could be reentered when | 93 // In case of OOM condition, this code could be reentered when |
| 83 // constructing and storing the key. Using a static is not | 94 // constructing and storing the key. Using a static is not |
| 84 // thread-safe, but if multiple threads are in the process of a | 95 // thread-safe, but if multiple threads are in the process of a |
| 85 // fatal crash at the same time, this should work. | 96 // fatal crash at the same time, this should work. |
| 86 static bool guarded = false; | 97 static bool guarded = false; |
| 87 if (guarded) | 98 if (guarded) |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 base::debug::SetCrashKeyReportingFunctions(&SetCrashKeyValueImpl, | 268 base::debug::SetCrashKeyReportingFunctions(&SetCrashKeyValueImpl, |
| 258 &ClearCrashKeyValueImpl); | 269 &ClearCrashKeyValueImpl); |
| 259 GetCrashReporterClient()->RegisterCrashKeys(); | 270 GetCrashReporterClient()->RegisterCrashKeys(); |
| 260 | 271 |
| 261 // Set Breakpad metadata values. These values are added to Info.plist during | 272 // Set Breakpad metadata values. These values are added to Info.plist during |
| 262 // the branded Google Chrome.app build. | 273 // the branded Google Chrome.app build. |
| 263 SetCrashKeyValue(@"ver", [info_dictionary objectForKey:@BREAKPAD_VERSION]); | 274 SetCrashKeyValue(@"ver", [info_dictionary objectForKey:@BREAKPAD_VERSION]); |
| 264 SetCrashKeyValue(@"prod", [info_dictionary objectForKey:@BREAKPAD_PRODUCT]); | 275 SetCrashKeyValue(@"prod", [info_dictionary objectForKey:@BREAKPAD_PRODUCT]); |
| 265 SetCrashKeyValue(@"plat", @"OS X"); | 276 SetCrashKeyValue(@"plat", @"OS X"); |
| 266 | 277 |
| 267 logging::SetLogMessageHandler(&FatalMessageHandler); | 278 // Intentionally leak the handler. |
| 279 auto* log_handler = new FatalMessageHandler(); |
| 280 CHECK(log_handler); |
| 281 |
| 268 base::debug::SetDumpWithoutCrashingFunction(&DumpHelper::DumpWithoutCrashing); | 282 base::debug::SetDumpWithoutCrashingFunction(&DumpHelper::DumpWithoutCrashing); |
| 269 | 283 |
| 270 // abort() sends SIGABRT, which breakpad does not intercept. | 284 // abort() sends SIGABRT, which breakpad does not intercept. |
| 271 // Register a signal handler to crash in a way breakpad will | 285 // Register a signal handler to crash in a way breakpad will |
| 272 // intercept. | 286 // intercept. |
| 273 struct sigaction sigact; | 287 struct sigaction sigact; |
| 274 memset(&sigact, 0, sizeof(sigact)); | 288 memset(&sigact, 0, sizeof(sigact)); |
| 275 sigact.sa_handler = SIGABRTHandler; | 289 sigact.sa_handler = SIGABRTHandler; |
| 276 CHECK(0 == sigaction(SIGABRT, &sigact, NULL)); | 290 CHECK(0 == sigaction(SIGABRT, &sigact, NULL)); |
| 277 } | 291 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 289 | 303 |
| 290 // Store process type in crash dump. | 304 // Store process type in crash dump. |
| 291 SetCrashKeyValue(@"ptype", process_type); | 305 SetCrashKeyValue(@"ptype", process_type); |
| 292 | 306 |
| 293 NSString* pid_value = | 307 NSString* pid_value = |
| 294 [NSString stringWithFormat:@"%d", static_cast<unsigned int>(getpid())]; | 308 [NSString stringWithFormat:@"%d", static_cast<unsigned int>(getpid())]; |
| 295 SetCrashKeyValue(@"pid", pid_value); | 309 SetCrashKeyValue(@"pid", pid_value); |
| 296 } | 310 } |
| 297 | 311 |
| 298 } // namespace breakpad | 312 } // namespace breakpad |
| OLD | NEW |