Chromium Code Reviews| 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 45 | 45 |
| 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, | |
| 56 const char* file, | |
| 57 int line, | |
| 58 size_t message_start, | |
| 59 const std::string& string) { | |
| 60 // Only handle FATAL. | |
| 61 if (severity != logging::LOG_FATAL) { | |
| 62 return false; | |
| 63 } | |
| 64 | |
| 65 // 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 | |
| 67 // multiple threads are in the process of a fatal crash at the same time, this | |
| 68 // should work. | |
| 69 static bool guarded = false; | |
| 70 if (guarded) { | |
| 71 return false; | |
| 72 } | |
| 73 base::AutoReset<bool> guard(&guarded, true); | |
| 74 | |
| 75 // Only log last path component. This matches logging.cc. | |
| 76 if (file) { | |
| 77 const char* slash = strrchr(file, '/'); | |
| 78 if (slash) { | |
| 79 file = slash + 1; | |
| 80 } | |
| 81 } | |
| 82 | |
| 83 CHECK_LE(message_start, string.size()); | |
| 84 std::string message = base::StringPrintf("%s:%d: %s", file, line, | |
| 85 string.c_str() + message_start); | |
| 86 SetCrashKeyValue("LOG_FATAL", message); | |
| 87 | |
| 88 // Rather than including the code to force the crash here, allow the caller to | |
| 89 // do it. | |
| 90 return false; | |
| 91 } | |
| 92 | |
| 93 void DumpWithoutCrashing() { | 55 void DumpWithoutCrashing() { |
| 94 CRASHPAD_SIMULATE_CRASH(); | 56 CRASHPAD_SIMULATE_CRASH(); |
| 95 } | 57 } |
| 96 | 58 |
| 97 void InitializeCrashpadImpl(bool initial_client, | 59 void InitializeCrashpadImpl(bool initial_client, |
| 98 const std::string& process_type, | 60 const std::string& process_type, |
| 99 bool embedded_handler) { | 61 bool embedded_handler) { |
| 100 static bool initialized = false; | 62 static bool initialized = false; |
| 101 DCHECK(!initialized); | 63 DCHECK(!initialized); |
| 102 initialized = true; | 64 initialized = true; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 157 crash_reporter_client->RegisterCrashKeys(); | 119 crash_reporter_client->RegisterCrashKeys(); |
| 158 | 120 |
| 159 SetCrashKeyValue("ptype", browser_process ? base::StringPiece("browser") | 121 SetCrashKeyValue("ptype", browser_process ? base::StringPiece("browser") |
| 160 : base::StringPiece(process_type)); | 122 : base::StringPiece(process_type)); |
| 161 #if defined(OS_POSIX) | 123 #if defined(OS_POSIX) |
| 162 SetCrashKeyValue("pid", base::IntToString(getpid())); | 124 SetCrashKeyValue("pid", base::IntToString(getpid())); |
| 163 #elif defined(OS_WIN) | 125 #elif defined(OS_WIN) |
| 164 SetCrashKeyValue("pid", base::IntToString(::GetCurrentProcessId())); | 126 SetCrashKeyValue("pid", base::IntToString(::GetCurrentProcessId())); |
| 165 #endif | 127 #endif |
| 166 | 128 |
| 167 logging::SetLogMessageHandler(LogMessageHandler); | |
|
scottmg
2016/10/05 22:06:21
Does this do anything here for logging that does a
rkuksin
2016/10/06 08:50:33
base::debug::SetCrashKeyReportingFunctions subtitu
| |
| 168 | |
| 169 // If clients called CRASHPAD_SIMULATE_CRASH() instead of | 129 // If clients called CRASHPAD_SIMULATE_CRASH() instead of |
| 170 // base::debug::DumpWithoutCrashing(), these dumps would appear as crashes in | 130 // base::debug::DumpWithoutCrashing(), these dumps would appear as crashes in |
| 171 // the correct function, at the correct file and line. This would be | 131 // the correct function, at the correct file and line. This would be |
| 172 // preferable to having all occurrences show up in DumpWithoutCrashing() at | 132 // preferable to having all occurrences show up in DumpWithoutCrashing() at |
| 173 // the same file and line. | 133 // the same file and line. |
| 174 base::debug::SetDumpWithoutCrashingFunction(DumpWithoutCrashing); | 134 base::debug::SetDumpWithoutCrashingFunction(DumpWithoutCrashing); |
| 175 | 135 |
| 176 #if defined(OS_MACOSX) | 136 #if defined(OS_MACOSX) |
| 177 // On Mac, we only want the browser to initialize the database, but not the | 137 // On Mac, we only want the browser to initialize the database, but not the |
| 178 // relauncher. | 138 // relauncher. |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 331 | 291 |
| 332 // This helper is invoked by code in chrome.dll to request a single crash report | 292 // This helper is invoked by code in chrome.dll to request a single crash report |
| 333 // upload. See CrashUploadListCrashpad. | 293 // upload. See CrashUploadListCrashpad. |
| 334 void __declspec(dllexport) | 294 void __declspec(dllexport) |
| 335 RequestSingleCrashUploadImpl(const std::string& local_id) { | 295 RequestSingleCrashUploadImpl(const std::string& local_id) { |
| 336 crash_reporter::RequestSingleCrashUpload(local_id); | 296 crash_reporter::RequestSingleCrashUpload(local_id); |
| 337 } | 297 } |
| 338 } // extern "C" | 298 } // extern "C" |
| 339 | 299 |
| 340 #endif // OS_WIN | 300 #endif // OS_WIN |
| OLD | NEW |