Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1010)

Side by Side Diff: components/crash/content/app/crashpad.cc

Issue 2377963002: restore LOG_FATAL crash key on windows
Patch Set: move CrashMessageHandler out of base Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/common/crash_keys.cc ('k') | components/crash/core/common/crash_keys.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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, 55 // Please keep synced with child_process_logging.cc.
56 const char* file, 56 void CrashMessageHandler(const std::string& message) {
57 int line, 57 // In case of an out-of-memory condition, this code could be reentered when
58 size_t message_start, 58 // constructing and storing the key. Using a static is not thread-safe, but
59 const std::string& string) { 59 // if multiple threads are in the process of a fatal crash at the same time,
60 // Only handle FATAL. 60 // this should work.
61 if (severity != logging::LOG_FATAL) { 61 static bool guarded = false;
62 return false; 62 if (!guarded) {
63 base::AutoReset<bool> guard(&guarded, true);
64 SetCrashKeyValue("LOG_FATAL", message);
63 } 65 }
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 } 66 }
92 67
93 void DumpWithoutCrashing() { 68 void DumpWithoutCrashing() {
94 CRASHPAD_SIMULATE_CRASH(); 69 CRASHPAD_SIMULATE_CRASH();
95 } 70 }
96 71
97 void InitializeCrashpadImpl(bool initial_client, 72 void InitializeCrashpadImpl(bool initial_client,
98 const std::string& process_type, 73 const std::string& process_type,
99 bool embedded_handler) { 74 bool embedded_handler) {
100 static bool initialized = false; 75 static bool initialized = false;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 crashpad::TriState::kDisabled); 122 crashpad::TriState::kDisabled);
148 } 123 }
149 #endif // OS_MACOSX 124 #endif // OS_MACOSX
150 125
151 g_simple_string_dictionary = new crashpad::SimpleStringDictionary(); 126 g_simple_string_dictionary = new crashpad::SimpleStringDictionary();
152 crashpad_info->set_simple_annotations(g_simple_string_dictionary); 127 crashpad_info->set_simple_annotations(g_simple_string_dictionary);
153 128
154 // On Windows chrome_elf registers crash keys. This should work identically 129 // On Windows chrome_elf registers crash keys. This should work identically
155 // for component and non component builds. 130 // for component and non component builds.
156 base::debug::SetCrashKeyReportingFunctions(SetCrashKeyValue, ClearCrashKey); 131 base::debug::SetCrashKeyReportingFunctions(SetCrashKeyValue, ClearCrashKey);
132 logging::SetCrashMessageHandler(CrashMessageHandler);
133
157 crash_reporter_client->RegisterCrashKeys(); 134 crash_reporter_client->RegisterCrashKeys();
158 135
159 SetCrashKeyValue("ptype", browser_process ? base::StringPiece("browser") 136 SetCrashKeyValue("ptype", browser_process ? base::StringPiece("browser")
160 : base::StringPiece(process_type)); 137 : base::StringPiece(process_type));
161 #if defined(OS_POSIX) 138 #if defined(OS_POSIX)
162 SetCrashKeyValue("pid", base::IntToString(getpid())); 139 SetCrashKeyValue("pid", base::IntToString(getpid()));
163 #elif defined(OS_WIN) 140 #elif defined(OS_WIN)
164 SetCrashKeyValue("pid", base::IntToString(::GetCurrentProcessId())); 141 SetCrashKeyValue("pid", base::IntToString(::GetCurrentProcessId()));
165 #endif 142 #endif
166 143
167 logging::SetLogMessageHandler(LogMessageHandler);
168
169 // If clients called CRASHPAD_SIMULATE_CRASH() instead of 144 // If clients called CRASHPAD_SIMULATE_CRASH() instead of
170 // base::debug::DumpWithoutCrashing(), these dumps would appear as crashes in 145 // base::debug::DumpWithoutCrashing(), these dumps would appear as crashes in
171 // the correct function, at the correct file and line. This would be 146 // the correct function, at the correct file and line. This would be
172 // preferable to having all occurrences show up in DumpWithoutCrashing() at 147 // preferable to having all occurrences show up in DumpWithoutCrashing() at
173 // the same file and line. 148 // the same file and line.
174 base::debug::SetDumpWithoutCrashingFunction(DumpWithoutCrashing); 149 base::debug::SetDumpWithoutCrashingFunction(DumpWithoutCrashing);
175 150
176 #if defined(OS_MACOSX) 151 #if defined(OS_MACOSX)
177 // On Mac, we only want the browser to initialize the database, but not the 152 // On Mac, we only want the browser to initialize the database, but not the
178 // relauncher. 153 // relauncher.
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 306
332 // This helper is invoked by code in chrome.dll to request a single crash report 307 // This helper is invoked by code in chrome.dll to request a single crash report
333 // upload. See CrashUploadListCrashpad. 308 // upload. See CrashUploadListCrashpad.
334 void __declspec(dllexport) 309 void __declspec(dllexport)
335 RequestSingleCrashUploadImpl(const std::string& local_id) { 310 RequestSingleCrashUploadImpl(const std::string& local_id) {
336 crash_reporter::RequestSingleCrashUpload(local_id); 311 crash_reporter::RequestSingleCrashUpload(local_id);
337 } 312 }
338 } // extern "C" 313 } // extern "C"
339 314
340 #endif // OS_WIN 315 #endif // OS_WIN
OLDNEW
« no previous file with comments | « chrome/common/crash_keys.cc ('k') | components/crash/core/common/crash_keys.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698