OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/mac/crash_logging.h" | 5 #include "base/mac/crash_logging.h" |
6 | 6 |
7 #include <algorithm> | |
8 | |
7 #import <Foundation/Foundation.h> | 9 #import <Foundation/Foundation.h> |
8 | 10 |
11 #include "base/logging.h" | |
12 | |
9 namespace base { | 13 namespace base { |
10 namespace mac { | 14 namespace mac { |
11 | 15 |
12 static SetCrashKeyValueFuncPtr g_set_key_func; | 16 static SetCrashKeyValueFuncPtr g_set_key_func; |
13 static ClearCrashKeyValueFuncPtr g_clear_key_func; | 17 static ClearCrashKeyValueFuncPtr g_clear_key_func; |
14 | 18 |
15 void SetCrashKeyFunctions(SetCrashKeyValueFuncPtr set_key_func, | 19 void SetCrashKeyFunctions(SetCrashKeyValueFuncPtr set_key_func, |
16 ClearCrashKeyValueFuncPtr clear_key_func) { | 20 ClearCrashKeyValueFuncPtr clear_key_func) { |
17 g_set_key_func = set_key_func; | 21 g_set_key_func = set_key_func; |
18 g_clear_key_func = clear_key_func; | 22 g_clear_key_func = clear_key_func; |
19 } | 23 } |
20 | 24 |
21 void SetCrashKeyValue(NSString* key, NSString* val) { | 25 void SetCrashKeyValue(NSString* key, NSString* val) { |
22 if (g_set_key_func) | 26 if (g_set_key_func) |
23 g_set_key_func(key, val); | 27 g_set_key_func(key, val); |
24 } | 28 } |
25 | 29 |
26 void ClearCrashKey(NSString* key) { | 30 void ClearCrashKey(NSString* key) { |
27 if (g_clear_key_func) | 31 if (g_clear_key_func) |
28 g_clear_key_func(key); | 32 g_clear_key_func(key); |
29 } | 33 } |
30 | 34 |
35 void SetCrashKeyFromAddresses(NSString* key, | |
36 const void* const* addresses, | |
37 size_t count) { | |
38 NSString* value = @"<null>"; | |
39 if (addresses && count) { | |
40 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.
| |
41 | |
42 // %p encodes 32-bit pointers as "0x" followed by up to 8 hex | |
43 // bytes. Plus one byte for separating space. | |
44 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
| |
45 count = std::min(count, kMaxCount); | |
46 | |
47 NSMutableArray* hexBacktrace = [NSMutableArray arrayWithCapacity:count]; | |
48 for (size_t i = 0; i < count; ++i) { | |
49 NSString* s = [NSString stringWithFormat:@"%p", addresses[i]]; | |
50 [hexBacktrace addObject:s]; | |
51 } | |
52 value = [hexBacktrace componentsJoinedByString:@" "]; | |
53 | |
54 // Warn someone if this exceeds the breakpad limits. Most likely | |
55 // a 64-bit compile. | |
56 DCHECK_LE(strlen([value UTF8String]), kBreakpadValueMax); | |
57 } | |
58 base::mac::SetCrashKeyValue(key, value); | |
59 } | |
60 | |
31 ScopedCrashKey::ScopedCrashKey(NSString* key, NSString* value) | 61 ScopedCrashKey::ScopedCrashKey(NSString* key, NSString* value) |
32 : crash_key_([key retain]) { | 62 : crash_key_([key retain]) { |
33 if (g_set_key_func) | 63 if (g_set_key_func) |
34 g_set_key_func(crash_key_, value); | 64 g_set_key_func(crash_key_, value); |
35 } | 65 } |
36 | 66 |
37 ScopedCrashKey::~ScopedCrashKey() { | 67 ScopedCrashKey::~ScopedCrashKey() { |
38 if (g_clear_key_func) | 68 if (g_clear_key_func) |
39 g_clear_key_func(crash_key_); | 69 g_clear_key_func(crash_key_); |
40 } | 70 } |
41 | 71 |
42 } // namespace mac | 72 } // namespace mac |
43 } // namespace base | 73 } // namespace base |
OLD | NEW |