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

Unified Diff: chrome/app/breakpad_mac.mm

Issue 8401018: [Mac] Log CHECK() file, line and message into breakpad. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 2 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/app/breakpad_mac.mm
diff --git a/chrome/app/breakpad_mac.mm b/chrome/app/breakpad_mac.mm
index f078271683fa448de75f40818ed7a9491d7ab3ac..f73d06add082528210dbb90741aa93e96768ff5f 100644
--- a/chrome/app/breakpad_mac.mm
+++ b/chrome/app/breakpad_mac.mm
@@ -50,6 +50,36 @@ void ClearCrashKeyValue(NSString* key) {
BreakpadRemoveUploadParameter(gBreakpadRef, key);
}
+bool FatalMessageHandler(int severity, const char* file, int line,
+ size_t message_start, const std::string& str) {
+ // Do not handle non-FATAL.
+ if (severity != logging::LOG_FATAL)
+ return false;
+
+ // Only log last path component. This matches logging.cc.
+ // NOTE(shess): Could look for the shared prefix between |file| and
Mark Mentovai 2011/10/26 23:50:27 If this were to become a fully-cooked idea, it wou
Scott Hess - ex-Googler 2011/10/27 00:15:09 removed.
+ // |__FILE__|, and store what's left.
+ if (file) {
+ const char* slash = rindex(file, '/');
Mark Mentovai 2011/10/26 23:50:27 strrchr is the modern name for rindex. Use that.
Scott Hess - ex-Googler 2011/10/27 00:15:09 GET OFF MY LAWN!
+ if (slash)
+ file = slash + 1;
Mark Mentovai 2011/10/26 23:50:27 If file is an empty string, this is dangerous. Be
dmac 2011/10/27 00:07:11 if file is an empty string, won't slash be NULL? a
Scott Hess - ex-Googler 2011/10/27 00:15:09 If file were empty, slash would be NULL.
+ }
+
+ // What happens if we ran out of memory and the construction does a
Mark Mentovai 2011/10/26 23:50:27 You know how I feel about “we.”
Scott Hess - ex-Googler 2011/10/27 00:15:09 Bother.
+ // malloc? Infinite loop! By putting a CHECK() in this code, I
+ // verified that it still crashed after running out of stack...
+ // Solving would maybe need a pre-allocated mutable string?
Mark Mentovai 2011/10/26 23:50:27 You can have a static bool that gets set when you
Scott Hess - ex-Googler 2011/10/27 00:15:09 I think that's reasonable. I'll put that up as a
+ NSString* fatal_key = @"LOG_FATAL";
+ NSString* fatal_value =
+ [NSString stringWithFormat:@"%s:%d: %s",
+ file, line, str.c_str() + message_start];
+ SetCrashKeyValue(fatal_key, fatal_value);
+
+ // Rather than including the code to force the crash here, allow the
+ // caller to do it.
+ return false;
+}
+
} // namespace
bool IsCrashReporterEnabled() {
@@ -176,7 +206,9 @@ void InitCrashReporter() {
std::string guid =
command_line->GetSwitchValueASCII(switches::kEnableCrashReporter);
child_process_logging::SetClientId(guid);
- }
+ }
+
+ logging::SetLogMessageHandler(&FatalMessageHandler);
}
void InitCrashProcessInfo() {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698