diff --git a/memory/mozalloc/mozalloc_abort.cpp b/memory/mozalloc/mozalloc_abort.cpp index 3eab8c5c208..d4c30bf05b3 100644 --- a/memory/mozalloc/mozalloc_abort.cpp +++ b/memory/mozalloc/mozalloc_abort.cpp @@ -5,76 +5,27 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include "mozilla/Assertions.h" + #include -#include // for abort() - -#if defined(_MSC_VER) // MSVC -# include // for __debugbreak() -#elif defined(XP_WIN) // mingw -# include // for DebugBreak -#elif defined(XP_UNIX) -# include // for _exit -# include -#endif - -#if defined(XP_WIN) || defined(XP_OS2) -# define MOZALLOC_EXPORT __declspec(dllexport) -#endif #include "mozilla/mozalloc_abort.h" -static int gDummyCounter; - -// Not inlining this function avoids the compiler making optimizations -// that end up corrupting stack traces. -MOZ_NEVER_INLINE static void -TouchBadMemory() -{ - // XXX this should use the frame poisoning code - volatile int *p = 0; - gDummyCounter += *p; // TODO annotation saying we know - // this is crazy -} - void mozalloc_abort(const char* const msg) { fputs(msg, stderr); fputs("\n", stderr); - -#if defined(_MSC_VER) - __debugbreak(); -#elif defined(XP_WIN) - DebugBreak(); -#endif - - // On *NIX platforms the prefered way to abort is by touching bad memory, - // since this generates a stack trace inside our own code (avoiding - // problems with starting the trace inside libc, where we might not have - // symbols and can get lost). - - TouchBadMemory(); - - // If we haven't aborted yet, we can try to raise SIGABRT which might work - // on some *NIXs, but not OS X (it doesn't trigger breakpad there). - // Note that we don't call abort(), since raise is likelier to give us - // useful stack data, and also since abort() is redirected to call this - // function (see below). -#if defined(XP_UNIX) && !defined(XP_MACOSX) - raise(SIGABRT); -#endif - - // Still haven't aborted? Try _exit(). - _exit(127); + MOZ_CRASH(); } #if defined(XP_UNIX) // Define abort() here, so that it is used instead of the system abort(). This // lets us control the behavior when aborting, in order to get better results -// on *NIX platfrorms. See mozalloc_abort for details. +// on *NIX platforms. See mozalloc_abort for details. void abort(void) { - mozalloc_abort("Redirecting call to abort() to mozalloc_abort\n"); + mozalloc_abort("Redirecting call to abort() to mozalloc_abort\n"); } #endif diff --git a/toolkit/crashreporter/test/CrashTestUtils.jsm b/toolkit/crashreporter/test/CrashTestUtils.jsm index 8de5e5262fa..2c984906758 100644 --- a/toolkit/crashreporter/test/CrashTestUtils.jsm +++ b/toolkit/crashreporter/test/CrashTestUtils.jsm @@ -13,6 +13,7 @@ let CrashTestUtils = { CRASH_PURE_VIRTUAL_CALL: 1, CRASH_RUNTIMEABORT: 2, CRASH_OOM: 3, + CRASH_MOZ_CRASH: 4, // Constants for dumpHasStream() // From google_breakpad/common/minidump_format.h diff --git a/toolkit/crashreporter/test/nsTestCrasher.cpp b/toolkit/crashreporter/test/nsTestCrasher.cpp index 9e1699e7e81..8ff97397f8f 100644 --- a/toolkit/crashreporter/test/nsTestCrasher.cpp +++ b/toolkit/crashreporter/test/nsTestCrasher.cpp @@ -1,3 +1,5 @@ +#include "mozilla/Assertions.h" + #include #include "nscore.h" @@ -42,6 +44,7 @@ const PRInt16 CRASH_INVALID_POINTER_DEREF = 0; const PRInt16 CRASH_PURE_VIRTUAL_CALL = 1; const PRInt16 CRASH_RUNTIMEABORT = 2; const PRInt16 CRASH_OOM = 3; +const PRInt16 CRASH_MOZ_CRASH = 4; extern "C" NS_EXPORT void Crash(PRInt16 how) @@ -68,6 +71,10 @@ void Crash(PRInt16 how) (void) moz_xmalloc((size_t) -1); break; } + case CRASH_MOZ_CRASH: { + MOZ_CRASH(); + break; + } default: break; } diff --git a/toolkit/crashreporter/test/unit/test_crash_moz_crash.js b/toolkit/crashreporter/test/unit/test_crash_moz_crash.js new file mode 100644 index 00000000000..067e68b7d88 --- /dev/null +++ b/toolkit/crashreporter/test/unit/test_crash_moz_crash.js @@ -0,0 +1,14 @@ +function run_test() +{ + // Try crashing with a runtime abort + do_crash(function() { + crashType = CrashTestUtils.CRASH_MOZ_CRASH; + crashReporter.annotateCrashReport("TestKey", "TestValue"); + }, + function(mdump, extra) { + do_check_eq(extra.TestKey, "TestValue"); + do_check_false("OOMAllocationSize" in extra); + }, + // process will exit with a zero exit status + true); +} diff --git a/toolkit/crashreporter/test/unit/xpcshell.ini b/toolkit/crashreporter/test/unit/xpcshell.ini index 46583dd180c..54515a5efd2 100644 --- a/toolkit/crashreporter/test/unit/xpcshell.ini +++ b/toolkit/crashreporter/test/unit/xpcshell.ini @@ -2,6 +2,7 @@ head = head_crashreporter.js tail = +[test_crash_moz_crash.js] [test_crash_purevirtual.js] [test_crash_runtimeabort.js] [test_crash_oom.js]