| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #include "components/crash/content/app/crashpad.h" | 5 #include "components/crash/content/app/crashpad.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 void SetCrashKeyValue(const base::StringPiece& key, | 46 void SetCrashKeyValue(const base::StringPiece& key, |
| 47 const base::StringPiece& value) { | 47 const base::StringPiece& value) { |
| 48 g_simple_string_dictionary->SetKeyValue(key.data(), value.data()); | 48 g_simple_string_dictionary->SetKeyValue(key.data(), value.data()); |
| 49 } | 49 } |
| 50 | 50 |
| 51 void ClearCrashKey(const base::StringPiece& key) { | 51 void ClearCrashKey(const base::StringPiece& key) { |
| 52 g_simple_string_dictionary->RemoveKey(key.data()); | 52 g_simple_string_dictionary->RemoveKey(key.data()); |
| 53 } | 53 } |
| 54 | 54 |
| 55 bool LogMessageHandler(int severity, | 55 bool LogMessageHandler(int severity, |
| 56 const char* file, | 56 const std::string& file, |
| 57 int line, | 57 int line, |
| 58 size_t message_start, | |
| 59 const std::string& string) { | 58 const std::string& string) { |
| 60 // Only handle FATAL. | 59 // Only handle FATAL. |
| 61 if (severity != logging::LOG_FATAL) { | 60 if (severity != logging::LOG_FATAL) { |
| 62 return false; | 61 return false; |
| 63 } | 62 } |
| 64 | 63 |
| 65 // In case of an out-of-memory condition, this code could be reentered when | 64 // In case of an out-of-memory condition, this code could be reentered when |
| 66 // constructing and storing the key. Using a static is not thread-safe, but if | 65 // constructing and storing the key. Using a static is not thread-safe, but if |
| 67 // multiple threads are in the process of a fatal crash at the same time, this | 66 // multiple threads are in the process of a fatal crash at the same time, this |
| 68 // should work. | 67 // should work. |
| 69 static bool guarded = false; | 68 static bool guarded = false; |
| 70 if (guarded) { | 69 if (guarded) { |
| 71 return false; | 70 return false; |
| 72 } | 71 } |
| 73 base::AutoReset<bool> guard(&guarded, true); | 72 base::AutoReset<bool> guard(&guarded, true); |
| 74 | 73 |
| 75 // Only log last path component. This matches logging.cc. | 74 // Only log last path component. This matches logging.cc. |
| 76 if (file) { | 75 size_t last_slash = file.rfind('/'); |
| 77 const char* slash = strrchr(file, '/'); | 76 if (last_slash == file.npos) |
| 78 if (slash) { | 77 last_slash = 0; |
| 79 file = slash + 1; | 78 else |
| 80 } | 79 last_slash++; |
| 81 } | |
| 82 | 80 |
| 83 CHECK_LE(message_start, string.size()); | 81 std::string message = base::StringPrintf("%s:%d: %s", |
| 84 std::string message = base::StringPrintf("%s:%d: %s", file, line, | 82 file.substr(last_slash).c_str(), |
| 85 string.c_str() + message_start); | 83 line, string.c_str()); |
| 86 SetCrashKeyValue("LOG_FATAL", message); | 84 SetCrashKeyValue("LOG_FATAL", message); |
| 87 | 85 |
| 88 // Rather than including the code to force the crash here, allow the caller to | 86 // Rather than including the code to force the crash here, allow the caller to |
| 89 // do it. | 87 // do it. |
| 90 return false; | 88 return false; |
| 91 } | 89 } |
| 92 | 90 |
| 93 void DumpWithoutCrashing() { | 91 void DumpWithoutCrashing() { |
| 94 CRASHPAD_SIMULATE_CRASH(); | 92 CRASHPAD_SIMULATE_CRASH(); |
| 95 } | 93 } |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 crash_reporter_client->RegisterCrashKeys(); | 155 crash_reporter_client->RegisterCrashKeys(); |
| 158 | 156 |
| 159 SetCrashKeyValue("ptype", browser_process ? base::StringPiece("browser") | 157 SetCrashKeyValue("ptype", browser_process ? base::StringPiece("browser") |
| 160 : base::StringPiece(process_type)); | 158 : base::StringPiece(process_type)); |
| 161 #if defined(OS_POSIX) | 159 #if defined(OS_POSIX) |
| 162 SetCrashKeyValue("pid", base::IntToString(getpid())); | 160 SetCrashKeyValue("pid", base::IntToString(getpid())); |
| 163 #elif defined(OS_WIN) | 161 #elif defined(OS_WIN) |
| 164 SetCrashKeyValue("pid", base::IntToString(::GetCurrentProcessId())); | 162 SetCrashKeyValue("pid", base::IntToString(::GetCurrentProcessId())); |
| 165 #endif | 163 #endif |
| 166 | 164 |
| 167 logging::SetLogMessageHandler(LogMessageHandler); | 165 logging::AddLogMessageHandler(LogMessageHandler); |
| 168 | 166 |
| 169 // If clients called CRASHPAD_SIMULATE_CRASH() instead of | 167 // If clients called CRASHPAD_SIMULATE_CRASH() instead of |
| 170 // base::debug::DumpWithoutCrashing(), these dumps would appear as crashes in | 168 // base::debug::DumpWithoutCrashing(), these dumps would appear as crashes in |
| 171 // the correct function, at the correct file and line. This would be | 169 // the correct function, at the correct file and line. This would be |
| 172 // preferable to having all occurrences show up in DumpWithoutCrashing() at | 170 // preferable to having all occurrences show up in DumpWithoutCrashing() at |
| 173 // the same file and line. | 171 // the same file and line. |
| 174 base::debug::SetDumpWithoutCrashingFunction(DumpWithoutCrashing); | 172 base::debug::SetDumpWithoutCrashingFunction(DumpWithoutCrashing); |
| 175 | 173 |
| 176 #if defined(OS_MACOSX) | 174 #if defined(OS_MACOSX) |
| 177 // On Mac, we only want the browser to initialize the database, but not the | 175 // On Mac, we only want the browser to initialize the database, but not the |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 | 329 |
| 332 // This helper is invoked by code in chrome.dll to request a single crash report | 330 // This helper is invoked by code in chrome.dll to request a single crash report |
| 333 // upload. See CrashUploadListCrashpad. | 331 // upload. See CrashUploadListCrashpad. |
| 334 void __declspec(dllexport) | 332 void __declspec(dllexport) |
| 335 RequestSingleCrashUploadImpl(const std::string& local_id) { | 333 RequestSingleCrashUploadImpl(const std::string& local_id) { |
| 336 crash_reporter::RequestSingleCrashUpload(local_id); | 334 crash_reporter::RequestSingleCrashUpload(local_id); |
| 337 } | 335 } |
| 338 } // extern "C" | 336 } // extern "C" |
| 339 | 337 |
| 340 #endif // OS_WIN | 338 #endif // OS_WIN |
| OLD | NEW |