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

Unified Diff: base/mac/crash_logging.mm

Issue 10408004: [Mac] Log stack trace for CHECK in bug 97285. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 7 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
Index: base/mac/crash_logging.mm
diff --git a/base/mac/crash_logging.mm b/base/mac/crash_logging.mm
index ce0db392a8239c9b991a9db35395fb1a81d6dfd2..3715be8f0881f086abf12846798cf6df765eca4f 100644
--- a/base/mac/crash_logging.mm
+++ b/base/mac/crash_logging.mm
@@ -4,8 +4,12 @@
#include "base/mac/crash_logging.h"
+#include <algorithm>
+
#import <Foundation/Foundation.h>
+#include "base/logging.h"
+
namespace base {
namespace mac {
@@ -28,6 +32,32 @@ void ClearCrashKey(NSString* key) {
g_clear_key_func(key);
}
+void SetCrashKeyFromAddresses(NSString* key,
+ const void* const* addresses,
+ size_t count) {
+ NSString* value = @"<null>";
+ if (addresses && count) {
+ static const size_t kBreakpadValueMax = 255;
Nico 2012/05/16 23:04:56 Remove static, also below
Scott Hess - ex-Googler 2012/05/17 22:08:12 Done.
+
+ // %p encodes 32-bit pointers as "0x" followed by up to 8 hex
+ // bytes. Plus one byte for separating space.
+ static const size_t kMaxCount = kBreakpadValueMax / 11;
Nico 2012/05/16 23:04:56 s/11/strlen("0xaabbccdd ")?
Scott Hess - ex-Googler 2012/05/17 22:08:12 Rather than pile things higher and deeper, I revis
+ count = std::min(count, kMaxCount);
+
+ NSMutableArray* hexBacktrace = [NSMutableArray arrayWithCapacity:count];
+ for (size_t i = 0; i < count; ++i) {
+ NSString* s = [NSString stringWithFormat:@"%p", addresses[i]];
+ [hexBacktrace addObject:s];
+ }
+ value = [hexBacktrace componentsJoinedByString:@" "];
+
+ // Warn someone if this exceeds the breakpad limits. Most likely
+ // a 64-bit compile.
+ DCHECK_LE(strlen([value UTF8String]), kBreakpadValueMax);
+ }
+ base::mac::SetCrashKeyValue(key, value);
+}
+
ScopedCrashKey::ScopedCrashKey(NSString* key, NSString* value)
: crash_key_([key retain]) {
if (g_set_key_func)

Powered by Google App Engine
This is Rietveld 408576698