Bug 1337051 - Test that we crash properly when exceptions thrown by third-party libraries aren't caught. r?ted
MozReview-Commit-ID: AypoGVccNU9
--- a/toolkit/crashreporter/test/CrashTestUtils.jsm
+++ b/toolkit/crashreporter/test/CrashTestUtils.jsm
@@ -12,16 +12,17 @@ this.CrashTestUtils = {
// Constants for crash()
// Keep these in sync with nsTestCrasher.cpp!
CRASH_INVALID_POINTER_DEREF: 0,
CRASH_PURE_VIRTUAL_CALL: 1,
CRASH_RUNTIMEABORT: 2,
CRASH_OOM: 3,
CRASH_MOZ_CRASH: 4,
CRASH_ABORT: 5,
+ CRASH_UNCAUGHT_EXCEPTION: 6,
// Constants for dumpHasStream()
// From google_breakpad/common/minidump_format.h
MD_THREAD_LIST_STREAM: 3,
MD_MEMORY_INFO_LIST_STREAM: 16
};
// Grab APIs from the testcrasher shared library
new file mode 100644
--- /dev/null
+++ b/toolkit/crashreporter/test/ExceptionThrower.cpp
@@ -0,0 +1,6 @@
+#include "ExceptionThrower.h"
+
+void ThrowException()
+{
+ throw 1;
+}
new file mode 100644
--- /dev/null
+++ b/toolkit/crashreporter/test/ExceptionThrower.h
@@ -0,0 +1,1 @@
+void ThrowException();
--- a/toolkit/crashreporter/test/moz.build
+++ b/toolkit/crashreporter/test/moz.build
@@ -15,16 +15,30 @@ UNIFIED_SOURCES += [
'../google-breakpad/src/processor/logging.cc',
'../google-breakpad/src/processor/minidump.cc',
'../google-breakpad/src/processor/pathname_stripper.cc',
'../google-breakpad/src/processor/proc_maps_linux.cc',
'dumputils.cpp',
'nsTestCrasher.cpp',
]
+SOURCES += [
+ 'ExceptionThrower.cpp',
+]
+
+if CONFIG['CLANG_CL']:
+ SOURCES['ExceptionThrower.cpp'].flags += [
+ '-Xclang',
+ '-fcxx-exceptions',
+ ]
+elif not CONFIG['_MSC_VER']:
+ SOURCES['ExceptionThrower.cpp'].flags += [
+ '-fexceptions',
+ ]
+
GeckoSharedLibrary('testcrasher')
DEFINES['SHARED_LIBRARY'] = '%s%s%s' % (
CONFIG['DLL_PREFIX'],
LIBRARY_NAME,
CONFIG['DLL_SUFFIX']
)
--- a/toolkit/crashreporter/test/nsTestCrasher.cpp
+++ b/toolkit/crashreporter/test/nsTestCrasher.cpp
@@ -1,15 +1,16 @@
#include "mozilla/Assertions.h"
#include <stdio.h>
#include "nscore.h"
#include "nsExceptionHandler.h"
#include "mozilla/Unused.h"
+#include "ExceptionThrower.h"
/*
* This pure virtual call example is from MSDN
*/
class A;
void fcn( A* );
@@ -40,16 +41,17 @@ void PureVirtualCall()
}
// Keep these in sync with CrashTestUtils.jsm!
const int16_t CRASH_INVALID_POINTER_DEREF = 0;
const int16_t CRASH_PURE_VIRTUAL_CALL = 1;
const int16_t CRASH_OOM = 3;
const int16_t CRASH_MOZ_CRASH = 4;
const int16_t CRASH_ABORT = 5;
+const int16_t CRASH_UNCAUGHT_EXCEPTION = 6;
extern "C" NS_EXPORT
void Crash(int16_t how)
{
switch (how) {
case CRASH_INVALID_POINTER_DEREF: {
volatile int* foo = (int*)0x42;
*foo = 0;
@@ -70,16 +72,20 @@ void Crash(int16_t how)
case CRASH_MOZ_CRASH: {
MOZ_CRASH();
break;
}
case CRASH_ABORT: {
abort();
break;
}
+ case CRASH_UNCAUGHT_EXCEPTION: {
+ ThrowException();
+ break;
+ }
default:
break;
}
}
char testData[32];
extern "C" NS_EXPORT
new file mode 100644
--- /dev/null
+++ b/toolkit/crashreporter/test/unit/test_crash_uncaught_exception.js
@@ -0,0 +1,16 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+function run_test() {
+ // Try crashing with an uncaught exception.
+ do_crash(function() {
+ crashType = CrashTestUtils.CRASH_UNCAUGHT_EXCEPTION;
+ crashReporter.annotateCrashReport("TestKey", "TestValue");
+ },
+ function(mdump, extra) {
+ do_check_eq(extra.TestKey, "TestValue");
+ },
+ // process will exit with a zero exit status
+ true);
+}
+
--- a/toolkit/crashreporter/test/unit/xpcshell.ini
+++ b/toolkit/crashreporter/test/unit/xpcshell.ini
@@ -14,16 +14,17 @@ support-files =
[test_crash_after_js_large_allocation_failure_reporting.js]
[test_crash_oom.js]
[test_oom_annotation_windows.js]
skip-if = os != 'win'
[test_crash_abort.js]
skip-if = os == 'win'
+[test_crash_uncaught_exception.js]
[test_crash_with_memory_report.js]
[test_crashreporter.js]
[test_crashreporter_crash.js]
[test_override_exception_handler.js]
skip-if = os != 'win'
[test_crashreporter_appmem.js]
# we need to skip this due to bug 838613