diff options
author | jeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-11 11:29:49 +0000 |
---|---|---|
committer | jeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-11 11:29:49 +0000 |
commit | 812befe3f00189ee161b5f412541dd0ba8840b79 (patch) | |
tree | a96f8ab57c5b81fef25e0c5af9aafa39e3d989fa /base | |
parent | 2c7a350921a14e0d6afb3cb24c7e36dbde141459 (diff) | |
download | chromium_src-812befe3f00189ee161b5f412541dd0ba8840b79.zip chromium_src-812befe3f00189ee161b5f412541dd0ba8840b79.tar.gz chromium_src-812befe3f00189ee161b5f412541dd0ba8840b79.tar.bz2 |
Refactor Mac crash key reporting - move to base/mac/crash_logging.{h,mm}
Breakpad support currently resides in chrome/app/breakpad_mac.* this makes it inaccessible to lower level code that would also like to set crash keys e.g. The sandboxing infrastructure.
This CL refactors the crash key reporting code to reside in base/mac.
Logging is also added to the Sandbox code to try to track down the cause of crbug.com/94758.
BUG=95272, 94758
TEST=On official builds crash logs should contain crash keys e.g. OS version.
Review URL: http://codereview.chromium.org/7849011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@100626 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/base.gypi | 2 | ||||
-rw-r--r-- | base/mac/crash_logging.h | 49 | ||||
-rw-r--r-- | base/mac/crash_logging.mm | 43 |
3 files changed, 94 insertions, 0 deletions
diff --git a/base/base.gypi b/base/base.gypi index 2db08e3..6220ea5 100644 --- a/base/base.gypi +++ b/base/base.gypi @@ -124,6 +124,8 @@ 'logging_win.cc', 'logging_win.h', 'mac/cocoa_protocols.h', + 'mac/crash_logging.h', + 'mac/crash_logging.mm', 'mac/foundation_util.h', 'mac/foundation_util.mm', 'mac/mac_util.h', diff --git a/base/mac/crash_logging.h b/base/mac/crash_logging.h new file mode 100644 index 0000000..006c847 --- /dev/null +++ b/base/mac/crash_logging.h @@ -0,0 +1,49 @@ +// Copyright (c) 2011 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_MAC_CRASH_LOGGING_H_ +#define BASE_MAC_CRASH_LOGGING_H_ + +#if __OBJC__ +#import "base/memory/scoped_nsobject.h" + +@class NSString; +#else +class NSString; +#endif + +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. +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 +// that if you look at the minidump file locally you won't see them! +void SetCrashKeyValue(NSString* key, NSString* val); +void ClearCrashKey(NSString* key); + +#if __OBJC__ + +class ScopedCrashKey { + public: + ScopedCrashKey(NSString* key, NSString* value); + ~ScopedCrashKey(); + private: + scoped_nsobject<NSString> crash_key_; + DISALLOW_COPY_AND_ASSIGN(ScopedCrashKey); +}; + +#endif // __OBJC__ + +} // namespace mac +} // namespace base + +#endif // BASE_MAC_CRASH_LOGGING_H_ diff --git a/base/mac/crash_logging.mm b/base/mac/crash_logging.mm new file mode 100644 index 0000000..ce0db39 --- /dev/null +++ b/base/mac/crash_logging.mm @@ -0,0 +1,43 @@ +// Copyright (c) 2011 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> + +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); +} + +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 |