From cd90ce49a1ddcb02827e43ec8f4459205d041443 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Tue, 18 May 2010 20:53:52 -0500 Subject: [PATCH] Bug 564185: Centralize the breakpad-triggering abort code in mozalloc and use |*NULL| to abort on mac, since abort() doesn't trigger breakpad. r=ted --- memory/mozalloc/mozalloc_abort.cpp | 32 ++++++++++--------------- xpcom/base/nsDebugImpl.cpp | 38 +++--------------------------- 2 files changed, 16 insertions(+), 54 deletions(-) diff --git a/memory/mozalloc/mozalloc_abort.cpp b/memory/mozalloc/mozalloc_abort.cpp index 66c082eb0a8b..94f592aeb864 100644 --- a/memory/mozalloc/mozalloc_abort.cpp +++ b/memory/mozalloc/mozalloc_abort.cpp @@ -55,37 +55,31 @@ static int gDummyCounter; +static void +TouchBadMemory() +{ + // XXX this should use the frame poisoning code + gDummyCounter += *((int *) 0); // TODO annotation saying we know + // this is crazy +} + void mozalloc_abort(const char* const msg) { fputs(msg, stderr); fputs("\n", stderr); - // XXX/cjones: most of this function was copied from - // xpcom/base/nsDebugImpl.cpp:Abort(), except that we assume on - // UNIX-like platforms can directly abort() rather than need to go - // through PR_Abort(). we don't want this code to rely on NSPR. - // FIXME/bug 558928: improve implementation for windows/wince -#if defined(_WIN32) -# if !defined(WINCE) - //This should exit us - raise(SIGABRT); -# endif - //If we are ignored exit this way.. - _exit(3); -#elif defined(XP_UNIX) || defined(XP_OS2) || defined(XP_BEOS) +#if defined(XP_UNIX) && !defined(XP_MACOSX) abort(); -#else -# warning not attempting to abort() on this platform #endif + // abort() doesn't trigger breakpad on Mac and Windows, "fall + // through" to the fail-safe code // Still haven't aborted? Try dereferencing null. - // (Written this way to lessen the likelihood of it being optimized away.) - gDummyCounter += *((int*) 0); // TODO annotation saying we know - // this is crazy - + TouchBadMemory(); + // Still haven't aborted? Try _exit(). _exit(127); } diff --git a/xpcom/base/nsDebugImpl.cpp b/xpcom/base/nsDebugImpl.cpp index 61408566c71a..eb2357e3ef7f 100644 --- a/xpcom/base/nsDebugImpl.cpp +++ b/xpcom/base/nsDebugImpl.cpp @@ -72,6 +72,8 @@ #include "nsString.h" #endif +#include "mozilla/mozalloc_abort.h" + static void Abort(const char *aMsg); @@ -363,44 +365,10 @@ NS_DebugBreak(PRUint32 aSeverity, const char *aStr, const char *aExpr, } } -static void -TouchBadMemory() -{ - // XXX this should use the frame poisoning code - gAssertionCount += *((PRInt32 *) 0); // TODO annotation saying we know - // this is crazy -} - static void Abort(const char *aMsg) { -#if defined(_WIN32) - TouchBadMemory(); - -#ifndef WINCE - //This should exit us - raise(SIGABRT); -#endif - //If we are ignored exit this way.. - _exit(3); -#elif defined(XP_UNIX) - PR_Abort(); -#elif defined(XP_BEOS) - { -#ifndef DEBUG_cls - DEBUGGER(aMsg); -#endif - } -#else - // Don't know how to abort on this platform! call Break() instead - Break(aMsg); -#endif - - // Still haven't aborted? Try dereferencing null. - TouchBadMemory(); - - // Still haven't aborted? Try _exit(). - PR_ProcessExit(127); + mozalloc_abort(aMsg); } static void