summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/chrome_browser_application_mac.mm49
-rw-r--r--chrome/chrome_common.gypi2
-rw-r--r--chrome/common/crash_keys.cc26
-rw-r--r--chrome/common/crash_keys.h38
-rw-r--r--chrome/common/mac/objc_zombie.mm20
5 files changed, 99 insertions, 36 deletions
diff --git a/chrome/browser/chrome_browser_application_mac.mm b/chrome/browser/chrome_browser_application_mac.mm
index b3f3533..791421d 100644
--- a/chrome/browser/chrome_browser_application_mac.mm
+++ b/chrome/browser/chrome_browser_application_mac.mm
@@ -5,14 +5,16 @@
#import "chrome/browser/chrome_browser_application_mac.h"
#import "base/auto_reset.h"
+#include "base/debug/crash_logging.h"
#import "base/logging.h"
-#include "base/mac/crash_logging.h"
#import "base/mac/scoped_nsexception_enabler.h"
#import "base/memory/scoped_nsobject.h"
#import "base/metrics/histogram.h"
+#include "base/stringprintf.h"
#import "base/sys_string_conversions.h"
#import "chrome/browser/app_controller_mac.h"
#include "chrome/browser/ui/tab_contents/tab_contents_iterator.h"
+#include "chrome/common/crash_keys.h"
#import "chrome/common/mac/objc_method_swizzle.h"
#import "chrome/common/mac/objc_zombie.h"
#include "content/public/browser/browser_accessibility_state.h"
@@ -61,10 +63,9 @@ static IMP gOriginalInitIMP = NULL;
if (!found) {
// Update breakpad with the exception info.
- static NSString* const kNSExceptionKey = @"nsexception";
- NSString* value =
- [NSString stringWithFormat:@"%@ reason %@", aName, aReason];
- base::mac::SetCrashKeyValue(kNSExceptionKey, value);
+ std::string value = base::StringPrintf("%s reason %s",
+ [aName UTF8String], [aReason UTF8String]);
+ base::debug::SetCrashKeyValue(crash_keys::mac::kNSException, value);
// Force crash for selected exceptions to generate crash dumps.
BOOL fatal = NO;
@@ -107,12 +108,12 @@ static IMP gOriginalInitIMP = NULL;
const bool allow = base::mac::GetNSExceptionsAllowed();
if (fatal && !allow) {
LOG(FATAL) << "Someone is trying to raise an exception! "
- << base::SysNSStringToUTF8(value);
+ << value;
} else {
// Make sure that developers see when their code throws
// exceptions.
DCHECK(allow) << "Someone is trying to raise an exception! "
- << base::SysNSStringToUTF8(value);
+ << value;
}
}
@@ -369,7 +370,6 @@ void SwizzleInit() {
// When a Cocoa control is wired to a freed object, we get crashers
// in the call to |super| with no useful information in the
// backtrace. Attempt to add some useful information.
- static NSString* const kActionKey = @"sendaction";
// If the action is something generic like -commandDispatch:, then
// the tag is essential.
@@ -384,14 +384,13 @@ void SwizzleInit() {
}
NSString* actionString = NSStringFromSelector(anAction);
- NSString* value =
- [NSString stringWithFormat:@"%@ tag %ld sending %@ to %p",
- [sender className],
- static_cast<long>(tag),
- actionString,
- aTarget];
+ std::string value = base::StringPrintf("%s tag %ld sending %s to %p",
+ [[sender className] UTF8String],
+ static_cast<long>(tag),
+ [actionString UTF8String],
+ aTarget);
- base::mac::ScopedCrashKey key(kActionKey, value);
+ base::debug::ScopedCrashKey key(crash_keys::mac::kSendAction, value);
// Certain third-party code, such as print drivers, can still throw
// exceptions and Chromium cannot fix them. This provides a way to
@@ -456,24 +455,22 @@ void SwizzleInit() {
// is tracked because it may be the one which caused the system to
// go off the rails. The last exception thrown is tracked because
// it may be the one most directly associated with the crash.
- static NSString* const kFirstExceptionKey = @"firstexception";
- static NSString* const kFirstExceptionBtKey = @"firstexception_bt";
static BOOL trackedFirstException = NO;
- static NSString* const kLastExceptionKey = @"lastexception";
- static NSString* const kLastExceptionBtKey = @"lastexception_bt";
- NSString* const kExceptionKey =
- trackedFirstException ? kLastExceptionKey : kFirstExceptionKey;
+ const char* const kExceptionKey =
+ trackedFirstException ? crash_keys::mac::kLastNSException
+ : crash_keys::mac::kFirstNSException;
NSString* value = [NSString stringWithFormat:@"%@ reason %@",
[anException name], [anException reason]];
- base::mac::SetCrashKeyValue(kExceptionKey, value);
+ base::debug::SetCrashKeyValue(kExceptionKey, [value UTF8String]);
// Encode the callstack from point of throw.
// TODO(shess): Our swizzle plus the 23-frame limit plus Cocoa
// overhead may make this less than useful. If so, perhaps skip
// some items and/or use two keys.
- NSString* const kExceptionBtKey =
- trackedFirstException ? kLastExceptionBtKey : kFirstExceptionBtKey;
+ const char* const kExceptionBtKey =
+ trackedFirstException ? crash_keys::mac::kLastNSExceptionTrace
+ : crash_keys::mac::kFirstNSExceptionTrace;
NSArray* addressArray = [anException callStackReturnAddresses];
NSUInteger addressCount = [addressArray count];
if (addressCount) {
@@ -487,10 +484,10 @@ void SwizzleInit() {
addresses[i] = reinterpret_cast<void*>(
[[addressArray objectAtIndex:i] unsignedIntegerValue]);
}
- base::mac::SetCrashKeyFromAddresses(
+ base::debug::SetCrashKeyFromAddresses(
kExceptionBtKey, addresses, static_cast<size_t>(addressCount));
} else {
- base::mac::ClearCrashKey(kExceptionBtKey);
+ base::debug::ClearCrashKey(kExceptionBtKey);
}
trackedFirstException = YES;
diff --git a/chrome/chrome_common.gypi b/chrome/chrome_common.gypi
index 2f715b5..4665614 100644
--- a/chrome/chrome_common.gypi
+++ b/chrome/chrome_common.gypi
@@ -118,6 +118,8 @@
'common/content_settings_pattern_parser.cc',
'common/content_settings_pattern_parser.h',
'common/content_settings_types.h',
+ 'common/crash_keys.cc',
+ 'common/crash_keys.h',
'common/custom_handlers/protocol_handler.cc',
'common/custom_handlers/protocol_handler.h',
'common/descriptors_android.h',
diff --git a/chrome/common/crash_keys.cc b/chrome/common/crash_keys.cc
new file mode 100644
index 0000000..55b0864
--- /dev/null
+++ b/chrome/common/crash_keys.cc
@@ -0,0 +1,26 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/common/crash_keys.h"
+
+namespace crash_keys {
+
+namespace mac {
+
+const char kFirstNSException[] = "firstexception";
+const char kFirstNSExceptionTrace[] = "firstexception_bt";
+
+const char kLastNSException[] = "lastexception";
+const char kLastNSExceptionTrace[] = "lastexception_bt";
+
+const char kNSException[] = "nsexception";
+
+const char kSendAction[] = "sendaction";
+
+const char kZombie[] = "zombie";
+const char kZombieTrace[] = "zombie_dealloc_bt";
+
+} // namespace mac
+
+} // namespace crash_keys
diff --git a/chrome/common/crash_keys.h b/chrome/common/crash_keys.h
new file mode 100644
index 0000000..34f2589
--- /dev/null
+++ b/chrome/common/crash_keys.h
@@ -0,0 +1,38 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_COMMON_CRASH_KEYS_H_
+#define CHROME_COMMON_CRASH_KEYS_H_
+
+namespace crash_keys {
+
+// Crash Key Name Constants ////////////////////////////////////////////////////
+
+namespace mac {
+
+// Used to report the first Cocoa/Mac NSException and its backtrace.
+extern const char kFirstNSException[];
+extern const char kFirstNSExceptionTrace[];
+
+// Used to report the last Cocoa/Mac NSException and its backtrace.
+extern const char kLastNSException[];
+extern const char kLastNSExceptionTrace[];
+
+// Records the current NSException as it's being created.
+extern const char kNSException[];
+
+// In the CrApplication, records information about the current event's
+// target-action.
+extern const char kSendAction[];
+
+// Records Cocoa zombie/used-after-freed objects that resulted in a
+// deliberate crash.
+extern const char kZombie[];
+extern const char kZombieTrace[];
+
+} // namespace mac
+
+} // namespace crash_keys
+
+#endif // CHROME_COMMON_CRASH_KEYS_H_
diff --git a/chrome/common/mac/objc_zombie.mm b/chrome/common/mac/objc_zombie.mm
index 0f01a52..a0cd90e 100644
--- a/chrome/common/mac/objc_zombie.mm
+++ b/chrome/common/mac/objc_zombie.mm
@@ -11,14 +11,15 @@
#include <algorithm>
+#include "base/debug/crash_logging.h"
#include "base/debug/stack_trace.h"
#include "base/lazy_instance.h"
#include "base/logging.h"
-#include "base/mac/crash_logging.h"
+#include "base/stringprintf.h"
#include "base/synchronization/lock.h"
+#include "chrome/common/crash_keys.h"
#import "chrome/common/mac/objc_method_swizzle.h"
-
#if !defined(OS_IOS) && (MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_6)
// Apparently objc/runtime.h doesn't define this with the 10.6 SDK yet.
// The docs say it exists since 10.6 however.
@@ -204,21 +205,20 @@ void ZombieObjectCrash(id object, SEL aSelector, SEL viaSelector) {
}
const char* wasaName = (wasa ? class_getName(wasa) : "<unknown>");
- NSString* aString =
- [NSString stringWithFormat:@"Zombie <%s: %p> received -%s",
- wasaName, object, sel_getName(aSelector)];
+ std::string aString = base::StringPrintf("Zombie <%s: %p> received -%s",
+ wasaName, object, sel_getName(aSelector));
if (viaSelector != NULL) {
const char* viaName = sel_getName(viaSelector);
- aString = [aString stringByAppendingFormat:@" (via -%s)", viaName];
+ base::StringAppendF(&aString, " (via -%s)", viaName);
}
// Set a value for breakpad to report.
- base::mac::SetCrashKeyValue(@"zombie", aString);
+ base::debug::SetCrashKeyValue(crash_keys::mac::kZombie, aString);
// Encode trace into a breakpad key.
if (found) {
- base::mac::SetCrashKeyFromAddresses(
- @"zombie_dealloc_bt", record.trace, record.traceDepth);
+ base::debug::SetCrashKeyFromAddresses(
+ crash_keys::mac::kZombieTrace, record.trace, record.traceDepth);
}
// Log -dealloc backtrace in debug builds then crash with a useful
@@ -228,7 +228,7 @@ void ZombieObjectCrash(id object, SEL aSelector, SEL viaSelector) {
} else {
DLOG(INFO) << "Unable to generate backtrace from -dealloc.";
}
- DLOG(FATAL) << [aString UTF8String];
+ DLOG(FATAL) << aString;
// This is how about:crash is implemented. Using instead of
// |base::debug::BreakDebugger()| or |LOG(FATAL)| to make the top of