summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorrsesek@chromium.org <rsesek@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-03 02:10:56 +0000
committerrsesek@chromium.org <rsesek@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-03 02:10:56 +0000
commit2d5538e545d012e59e3a953f2468197ad3b6c3c4 (patch)
treef9b5b40d72b139c710e75790bfb9de08b5b2f055 /base
parentc28e9d11956ffed60eca7924f36e735e6e918b1e (diff)
downloadchromium_src-2d5538e545d012e59e3a953f2468197ad3b6c3c4.zip
chromium_src-2d5538e545d012e59e3a953f2468197ad3b6c3c4.tar.gz
chromium_src-2d5538e545d012e59e3a953f2468197ad3b6c3c4.tar.bz2
Create a cross-platform crash key system in base/debug/crash_logging.h.
This is a direct port of the Mac-specific one, and that has been reimplemented on top of the new cross-platform one. Currently only the Mac implementation is hooked up. BUG=77656 TEST=Built official and caused some crashes, verified report data in upload. Review URL: https://chromiumcodereview.appspot.com/11635030 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@174911 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/base.gypi4
-rw-r--r--base/debug/crash_logging.cc81
-rw-r--r--base/debug/crash_logging.h67
-rw-r--r--base/mac/crash_logging.h12
-rw-r--r--base/mac/crash_logging.mm69
-rw-r--r--base/mac/crash_logging_mac.mm44
6 files changed, 200 insertions, 77 deletions
diff --git a/base/base.gypi b/base/base.gypi
index 99e16ab..69a844e 100644
--- a/base/base.gypi
+++ b/base/base.gypi
@@ -101,6 +101,8 @@
'critical_closure_ios.mm',
'debug/alias.cc',
'debug/alias.h',
+ 'debug/crash_logging.cc',
+ 'debug/crash_logging.h',
'debug/debug_on_start_win.cc',
'debug/debug_on_start_win.h',
'debug/debugger.cc',
@@ -207,7 +209,7 @@
'mac/bundle_locations.mm',
'mac/cocoa_protocols.h',
'mac/crash_logging.h',
- 'mac/crash_logging.mm',
+ 'mac/crash_logging_mac.mm',
'mac/foundation_util.h',
'mac/foundation_util.mm',
'mac/launchd.cc',
diff --git a/base/debug/crash_logging.cc b/base/debug/crash_logging.cc
new file mode 100644
index 0000000..1e20677
--- /dev/null
+++ b/base/debug/crash_logging.cc
@@ -0,0 +1,81 @@
+// Copyright (c) 2012 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 "base/debug/crash_logging.h"
+
+#include "base/debug/stack_trace.h"
+#include "base/logging.h"
+#include "base/string_util.h"
+#include "base/stringprintf.h"
+
+namespace base {
+namespace debug {
+
+static SetCrashKeyValueFuncT g_set_key_func_ = NULL;
+static ClearCrashKeyValueFuncT g_clear_key_func_ = NULL;
+
+void SetCrashKeyValue(const base::StringPiece& key,
+ const base::StringPiece& value) {
+ if (g_set_key_func_)
+ g_set_key_func_(key, value);
+}
+
+void ClearCrashKey(const base::StringPiece& key) {
+ if (g_clear_key_func_)
+ g_clear_key_func_(key);
+}
+
+void SetCrashKeyToStackTrace(const base::StringPiece& key,
+ const StackTrace& trace) {
+ size_t count = 0;
+ const void* const* addresses = trace.Addresses(&count);
+ SetCrashKeyFromAddresses(key, addresses, count);
+}
+
+void SetCrashKeyFromAddresses(const base::StringPiece& key,
+ const void* const* addresses,
+ size_t count) {
+ std::string value = "<null>";
+ if (addresses && count) {
+ const size_t kBreakpadValueMax = 255;
+
+ std::vector<std::string> hex_backtrace;
+ size_t length = 0;
+
+ for (size_t i = 0; i < count; ++i) {
+ std::string s = base::StringPrintf("%p", addresses[i]);
+ length += s.length() + 1;
+ if (length > kBreakpadValueMax)
+ break;
+ hex_backtrace.push_back(s);
+ }
+
+ value = JoinString(hex_backtrace, ' ');
+
+ // Warn if this exceeds the breakpad limits.
+ DCHECK_LE(value.length(), kBreakpadValueMax);
+ }
+
+ SetCrashKeyValue(key, value);
+}
+
+ScopedCrashKey::ScopedCrashKey(const base::StringPiece& key,
+ const base::StringPiece& value)
+ : key_(key.as_string()) {
+ SetCrashKeyValue(key, value);
+}
+
+ScopedCrashKey::~ScopedCrashKey() {
+ ClearCrashKey(key_);
+}
+
+void SetCrashKeyReportingFunctions(
+ SetCrashKeyValueFuncT set_key_func,
+ ClearCrashKeyValueFuncT clear_key_func) {
+ g_set_key_func_ = set_key_func;
+ g_clear_key_func_ = clear_key_func;
+}
+
+} // namespace debug
+} // namespace base
diff --git a/base/debug/crash_logging.h b/base/debug/crash_logging.h
new file mode 100644
index 0000000..c39c41d
--- /dev/null
+++ b/base/debug/crash_logging.h
@@ -0,0 +1,67 @@
+// Copyright (c) 2012 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 BASE_DEBUG_CRASH_LOGGING_H_
+#define BASE_DEBUG_CRASH_LOGGING_H_
+
+#include <string>
+
+#include "base/base_export.h"
+#include "base/basictypes.h"
+#include "base/string_piece.h"
+
+// These functions add metadata to the upload payload when sending crash reports
+// to the crash server.
+//
+// IMPORTANT: On OS X and Linux, the key/value pairs are only sent as part of
+// the upload and are not included in the minidump!
+
+namespace base {
+namespace debug {
+
+class StackTrace;
+
+// Set or clear a specific key-value pair from the crash metadata.
+BASE_EXPORT void SetCrashKeyValue(const base::StringPiece& key,
+ const base::StringPiece& value);
+BASE_EXPORT void ClearCrashKey(const base::StringPiece& key);
+
+// Records the given StackTrace into a crash key.
+BASE_EXPORT void SetCrashKeyToStackTrace(const base::StringPiece& key,
+ const StackTrace& trace);
+
+// Formats |count| instruction pointers from |addresses| using %p and
+// sets the resulting string as a value for crash key |key. A maximum of 23
+// items will be encoded, since breakpad limits values to 255 bytes.
+BASE_EXPORT void SetCrashKeyFromAddresses(const base::StringPiece& key,
+ const void* const* addresses,
+ size_t count);
+
+// A scoper that sets the specified key to value for the lifetime of the
+// object, and clears it on destruction.
+class BASE_EXPORT ScopedCrashKey {
+ public:
+ ScopedCrashKey(const base::StringPiece& key, const base::StringPiece& value);
+ ~ScopedCrashKey();
+
+ private:
+ std::string key_;
+
+ DISALLOW_COPY_AND_ASSIGN(ScopedCrashKey);
+};
+
+typedef void (*SetCrashKeyValueFuncT)(const base::StringPiece&,
+ const base::StringPiece&);
+typedef void (*ClearCrashKeyValueFuncT)(const base::StringPiece&);
+
+// Sets the function pointers that are used to integrate with the platform-
+// specific crash reporting libraries.
+BASE_EXPORT void SetCrashKeyReportingFunctions(
+ SetCrashKeyValueFuncT set_key_func,
+ ClearCrashKeyValueFuncT clear_key_func);
+
+} // namespace debug
+} // namespace base
+
+#endif // BASE_DEBUG_CRASH_LOGGING_H_
diff --git a/base/mac/crash_logging.h b/base/mac/crash_logging.h
index 7e83eae..837a044 100644
--- a/base/mac/crash_logging.h
+++ b/base/mac/crash_logging.h
@@ -15,16 +15,14 @@
class NSString;
#endif
+// !!! DEPRECATED !!!!
+// Please use base/debug/crash_logging.h instead.
+//
+// TODO(rsesek): Convert all callers to the new API.
+
namespace base {
namespace mac {
-typedef void (*SetCrashKeyValueFuncPtr)(NSString*, NSString*);
-typedef void (*ClearCrashKeyValueFuncPtr)(NSString*);
-
-// Set the low level functions used to supply crash keys to Breakpad.
-BASE_EXPORT void SetCrashKeyFunctions(SetCrashKeyValueFuncPtr set_key_func,
- ClearCrashKeyValueFuncPtr clear_key_func);
-
// Set and clear meta information for Minidump.
// IMPORTANT: On OS X, the key/value pairs are sent to the crash server
// out of bounds and not recorded on disk in the minidump, this means
diff --git a/base/mac/crash_logging.mm b/base/mac/crash_logging.mm
deleted file mode 100644
index e18a3fb..0000000
--- a/base/mac/crash_logging.mm
+++ /dev/null
@@ -1,69 +0,0 @@
-// Copyright (c) 2012 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 "base/mac/crash_logging.h"
-
-#import <Foundation/Foundation.h>
-
-#include "base/logging.h"
-
-namespace base {
-namespace mac {
-
-static SetCrashKeyValueFuncPtr g_set_key_func;
-static ClearCrashKeyValueFuncPtr g_clear_key_func;
-
-void SetCrashKeyFunctions(SetCrashKeyValueFuncPtr set_key_func,
- ClearCrashKeyValueFuncPtr clear_key_func) {
- g_set_key_func = set_key_func;
- g_clear_key_func = clear_key_func;
-}
-
-void SetCrashKeyValue(NSString* key, NSString* val) {
- if (g_set_key_func)
- g_set_key_func(key, val);
-}
-
-void ClearCrashKey(NSString* key) {
- if (g_clear_key_func)
- g_clear_key_func(key);
-}
-
-void SetCrashKeyFromAddresses(NSString* key,
- const void* const* addresses,
- size_t count) {
- NSString* value = @"<null>";
- if (addresses && count) {
- const size_t kBreakpadValueMax = 255;
-
- NSMutableArray* hexBacktrace = [NSMutableArray arrayWithCapacity:count];
- size_t length = 0;
- for (size_t i = 0; i < count; ++i) {
- NSString* s = [NSString stringWithFormat:@"%p", addresses[i]];
- length += 1 + [s length];
- if (length > kBreakpadValueMax)
- break;
- [hexBacktrace addObject:s];
- }
- value = [hexBacktrace componentsJoinedByString:@" "];
-
- // Warn someone if this exceeds the breakpad limits.
- 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)
- g_set_key_func(crash_key_, value);
-}
-
-ScopedCrashKey::~ScopedCrashKey() {
- if (g_clear_key_func)
- g_clear_key_func(crash_key_);
-}
-
-} // namespace mac
-} // namespace base
diff --git a/base/mac/crash_logging_mac.mm b/base/mac/crash_logging_mac.mm
new file mode 100644
index 0000000..85e5202
--- /dev/null
+++ b/base/mac/crash_logging_mac.mm
@@ -0,0 +1,44 @@
+// Copyright (c) 2012 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 "base/mac/crash_logging.h"
+
+#import <Foundation/Foundation.h>
+
+#include "base/debug/crash_logging.h"
+#include "base/sys_string_conversions.h"
+
+namespace base {
+namespace mac {
+
+void SetCrashKeyValue(NSString* key, NSString* val) {
+ base::debug::SetCrashKeyValue(
+ base::SysNSStringToUTF8(key),
+ base::SysNSStringToUTF8(val));
+}
+
+void ClearCrashKey(NSString* key) {
+ base::debug::ClearCrashKey(base::SysNSStringToUTF8(key));
+}
+
+void SetCrashKeyFromAddresses(NSString* key,
+ const void* const* addresses,
+ size_t count) {
+ base::debug::SetCrashKeyFromAddresses(
+ base::SysNSStringToUTF8(key),
+ addresses,
+ count);
+}
+
+ScopedCrashKey::ScopedCrashKey(NSString* key, NSString* value)
+ : crash_key_([key retain]) {
+ SetCrashKeyValue(key, value);
+}
+
+ScopedCrashKey::~ScopedCrashKey() {
+ ClearCrashKey(crash_key_);
+}
+
+} // namespace mac
+} // namespace base