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

This commit is contained in:
Chris Jones 2010-05-18 20:53:52 -05:00
parent 3b1e6849e8
commit 4567048351
2 changed files with 16 additions and 54 deletions

View File

@ -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);
}

View File

@ -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