Include obj-c exception info in crash reports. b=451709 r=ted r=bent sr=roc

This commit is contained in:
Josh Aas 2008-08-28 00:41:38 -04:00
parent 65dbea367a
commit 61ac969657
10 changed files with 87 additions and 9 deletions

View File

@ -38,10 +38,15 @@
#ifndef toolkit_breakpad_mac_utils_h__
#define toolkit_breakpad_mac_utils_h__
#include "nsStringGlue.h"
/*
* Look up a setting in our user defaults indicating
* that the user wants to see the OS crash reporting dialog.
*/
bool PassToOSCrashReporter();
// Given an Objective-C NSException object, put exception info into a string.
void GetObjCExceptionInfo(void* inException, nsACString& outString);
#endif /* toolkit_breakpad_mac_utils_h__ */

View File

@ -20,6 +20,7 @@
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Josh Aas <josh@mozilla.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
@ -39,6 +40,7 @@
#include "mac_utils.h"
#include "nsObjCExceptions.h"
#include "nsXPCOM.h"
bool PassToOSCrashReporter()
{
@ -53,3 +55,35 @@ bool PassToOSCrashReporter()
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(false);
}
void GetObjCExceptionInfo(void* inException, nsACString& outString)
{
NSException* e = (NSException*)inException;
NSString* name = [e name];
NSString* reason = [e reason];
unsigned int nameLength = [name length];
unsigned int reasonLength = [reason length];
unichar* nameBuffer = (unichar*)NS_Alloc(sizeof(unichar) * (nameLength + 1));
if (!nameBuffer)
return;
unichar* reasonBuffer = (unichar*)NS_Alloc(sizeof(unichar) * (reasonLength + 1));
if (!reasonBuffer) {
NS_Free(nameBuffer);
return;
}
[name getCharacters:nameBuffer];
[reason getCharacters:reasonBuffer];
nameBuffer[nameLength] = '\0';
reasonBuffer[reasonLength] = '\0';
outString.AssignLiteral("\nObj-C Exception data:\n");
AppendUTF16toUTF8(nameBuffer, outString);
outString.AppendLiteral(": ");
AppendUTF16toUTF8(reasonBuffer, outString);
NS_Free(nameBuffer);
NS_Free(reasonBuffer);
}

View File

@ -20,6 +20,7 @@
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Josh Aas <josh@mozilla.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
@ -885,4 +886,14 @@ nsresult WriteMinidumpForException(EXCEPTION_POINTERS* aExceptionInfo)
}
#endif
#ifdef XP_MACOSX
nsresult AppendObjCExceptionInfoToAppNotes(void *inException)
{
nsCAutoString excString;
GetObjCExceptionInfo(inException, excString);
AppendAppNotesToCrashReport(excString);
return NS_OK;
}
#endif
} // namespace CrashReporter

View File

@ -62,6 +62,9 @@ nsresult SetupExtraData(nsILocalFile* aAppDataDirectory,
#ifdef XP_WIN32
nsresult WriteMinidumpForException(EXCEPTION_POINTERS* aExceptionInfo);
#endif
#ifdef XP_MACOSX
nsresult AppendObjCExceptionInfoToAppNotes(void *inException);
#endif
}
#endif /* nsExceptionHandler_h__ */

View File

@ -39,12 +39,8 @@
#ifndef __MacLaunchHelper_h__
#define __MacLaunchHelper_h__
#ifdef __cplusplus
extern "C" {
#endif
void LaunchChildMac(int aArgc, char** aArgv);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -93,4 +93,3 @@ void LaunchChildMac(int aArgc, char** aArgv)
NS_OBJC_END_TRY_ABORT_BLOCK;
}

View File

@ -152,8 +152,8 @@ endif
endif
endif
ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT)))
CMSRCS = MacLaunchHelper.m
ifeq ($(MOZ_WIDGET_TOOLKIT),cocoa)
CMMSRCS += MacLaunchHelper.mm
CPPSRCS += nsCommandLineServiceMac.cpp
LOCAL_INCLUDES += -I$(topsrcdir)/xpfe/bootstrap/appleevents
OS_CXXFLAGS += -fexceptions

View File

@ -860,6 +860,16 @@ nsXULAppInfo::WriteMinidumpForException(void* aExceptionInfo)
}
#endif
NS_IMETHODIMP
nsXULAppInfo::AppendObjCExceptionInfoToAppNotes(void* aException)
{
#ifdef XP_MACOSX
return CrashReporter::AppendObjCExceptionInfoToAppNotes(aException);
#else
return NS_ERROR_NOT_IMPLEMENTED;
#endif
}
static const nsXULAppInfo kAppInfo;
static NS_METHOD AppInfoConstructor(nsISupports* aOuter,
REFNSIID aIID, void **aResult)

View File

@ -46,6 +46,12 @@
#import <ExceptionHandling/NSExceptionHandler.h>
#endif
#if defined(MOZ_CRASHREPORTER) && defined(__cplusplus)
#include "nsICrashReporter.h"
#include "nsCOMPtr.h"
#include "nsServiceManagerUtils.h"
#endif
#include <unistd.h>
#include <signal.h>
#include "nsError.h"
@ -58,6 +64,14 @@ static void nsObjCExceptionLog(NSException* aException)
NSLog(@"Mozilla has caught an Obj-C exception [%@: %@]",
[aException name], [aException reason]);
#if defined(MOZ_CRASHREPORTER) && defined(__cplusplus)
// Attach exception info to the crash report.
nsCOMPtr<nsICrashReporter> crashReporter =
do_GetService("@mozilla.org/toolkit/crash-reporter;1");
if (crashReporter)
crashReporter->AppendObjCExceptionInfoToAppNotes(static_cast<void*>(aException));
#endif
#ifdef DEBUG
@try {
// Try to get stack information out of the exception. 10.5 returns the stack

View File

@ -43,7 +43,7 @@
* future releases.
*/
[scriptable, uuid(189c9392-157c-445f-84db-900eb46d4839)]
[scriptable, uuid(D9A0F5B2-A7DF-4AEB-9775-21B9E01B4C59)]
interface nsICrashReporter : nsISupports
{
/**
@ -79,5 +79,11 @@ interface nsICrashReporter : nsISupports
* SEH (structured exception handling) exists on Windows only.
* @param aExceptionInfo EXCEPTION_INFO* provided by Window's SEH
*/
[noscript] void WriteMinidumpForException(in voidPtr aExceptionInfo);
[noscript] void writeMinidumpForException(in voidPtr aExceptionInfo);
/**
* Append note containing an Obj-C exception's info.
* @param aException NSException object to append note for
*/
[noscript] void appendObjCExceptionInfoToAppNotes(in voidPtr aException);
};