зеркало из https://github.com/mozilla/pjs.git
Bug 326594 ��� Consider using backtrace() for Unix stack traces:
Add safety checks to i386/ppc unwind and use libgcc_s for amd64 and others r=dbaron,bsmedberg a=schrep
This commit is contained in:
Родитель
822a6f38f1
Коммит
366cdd4a7a
12
configure.in
12
configure.in
|
@ -2857,6 +2857,12 @@ case $target in
|
|||
AC_DEFINE(HAVE_LIBDL)))
|
||||
;;
|
||||
esac
|
||||
|
||||
_SAVE_CFLAGS="$CFLAGS"
|
||||
CFLAGS="$CFLAGS -D_GNU_SOURCE"
|
||||
AC_CHECK_FUNCS(dladdr)
|
||||
CFLAGS="$_SAVE_CFLAGS"
|
||||
|
||||
if test ! "$GNU_CXX"; then
|
||||
|
||||
case $target in
|
||||
|
@ -6360,6 +6366,12 @@ if test "$HAVE_DEMANGLE" -a "$HAVE_GCC3_ABI" && test "$MOZ_DEBUG" -o "$NS_TRACE_
|
|||
fi
|
||||
AC_SUBST(MOZ_DEMANGLE_SYMBOLS)
|
||||
|
||||
dnl ========================================================
|
||||
dnl = Support for gcc stack unwinding (from gcc 3.3)
|
||||
dnl ========================================================
|
||||
if test "$HAVE_GCC3_ABI" && test -z "$SKIP_LIBRARY_CHECKS"; then
|
||||
AC_CHECK_FUNCS(_Unwind_Backtrace)
|
||||
fi
|
||||
|
||||
dnl ========================================================
|
||||
dnl =
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
/* vim: set shiftwidth=4 tabstop=8 autoindent cindent expandtab: */
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
* vim: set shiftwidth=4 tabstop=8 autoindent cindent expandtab: */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
|
@ -1093,7 +1094,7 @@ NS_FormatCodeAddressDetails(void *aPC, const nsCodeAddressDetails *aDetails,
|
|||
|
||||
// WIN32 x86 stack walking code
|
||||
// i386 or PPC Linux stackwalking code or Solaris
|
||||
#elif (defined(linux) && defined(__GNUC__) && (defined(__i386) || defined(PPC) || defined(__x86_64__))) || (defined(__sun) && (defined(__sparc) || defined(sparc) || defined(__i386) || defined(i386))) || (defined(XP_MACOSX) && (defined(__ppc__) || defined(__i386)))
|
||||
#elif HAVE_DLADDR && (HAVE__UNWIND_BACKTRACE || (defined(linux) && defined(__GNUC__) && (defined(__i386) || defined(PPC))) || (defined(__sun) && (defined(__sparc) || defined(sparc) || defined(__i386) || defined(i386))) || (defined(XP_MACOSX) && (defined(__ppc__) || defined(__i386))))
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
@ -1142,99 +1143,7 @@ void DemangleSymbol(const char * aSymbol,
|
|||
}
|
||||
|
||||
|
||||
#if (defined(linux) && defined(__GNUC__) && (defined(__i386) || defined(PPC) || defined(__x86_64__))) || (defined(XP_MACOSX) && (defined(__i386) || defined(__ppc__))) // i386 or PPC Linux stackwalking code
|
||||
|
||||
|
||||
EXPORT_XPCOM_API(nsresult)
|
||||
NS_StackWalk(NS_WalkStackCallback aCallback, PRUint32 aSkipFrames,
|
||||
void *aClosure)
|
||||
{
|
||||
// Stack walking code courtesy Kipp's "leaky".
|
||||
|
||||
// Get the frame pointer
|
||||
void **bp;
|
||||
#if defined(__i386)
|
||||
__asm__( "movl %%ebp, %0" : "=g"(bp));
|
||||
#elif defined(__x86_64__)
|
||||
__asm__( "movq %%rbp, %0" : "=g"(bp));
|
||||
#else
|
||||
// It would be nice if this worked uniformly, but at least on i386 and
|
||||
// x86_64, it stopped working with gcc 4.1, because it points to the
|
||||
// end of the saved registers instead of the start.
|
||||
bp = (void**) __builtin_frame_address(0);
|
||||
#endif
|
||||
|
||||
int skip = aSkipFrames;
|
||||
for ( ; (void**)*bp > bp; bp = (void**)*bp) {
|
||||
#if defined(__ppc__) && defined(XP_MACOSX) // other PPC platforms?
|
||||
void *pc = *(bp+2);
|
||||
#else
|
||||
void *pc = *(bp+1);
|
||||
#endif
|
||||
if (--skip < 0) {
|
||||
(*aCallback)(pc, aClosure);
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
EXPORT_XPCOM_API(nsresult)
|
||||
NS_DescribeCodeAddress(void *aPC, nsCodeAddressDetails *aDetails)
|
||||
{
|
||||
aDetails->library[0] = '\0';
|
||||
aDetails->loffset = 0;
|
||||
aDetails->filename[0] = '\0';
|
||||
aDetails->lineno = 0;
|
||||
aDetails->function[0] = '\0';
|
||||
aDetails->foffset = 0;
|
||||
|
||||
Dl_info info;
|
||||
int ok = dladdr(aPC, &info);
|
||||
if (!ok) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
PL_strncpyz(aDetails->library, info.dli_fname, sizeof(aDetails->library));
|
||||
aDetails->loffset = (char*)aPC - (char*)info.dli_fbase;
|
||||
|
||||
const char * symbol = info.dli_sname;
|
||||
int len;
|
||||
if (!symbol || !(len = strlen(symbol))) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
char demangled[4096] = "\0";
|
||||
|
||||
DemangleSymbol(symbol, demangled, sizeof(demangled));
|
||||
|
||||
if (strlen(demangled)) {
|
||||
symbol = demangled;
|
||||
len = strlen(symbol);
|
||||
}
|
||||
|
||||
PL_strncpyz(aDetails->function, symbol, sizeof(aDetails->function));
|
||||
aDetails->foffset = (char*)aPC - (char*)info.dli_saddr;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
EXPORT_XPCOM_API(nsresult)
|
||||
NS_FormatCodeAddressDetails(void *aPC, const nsCodeAddressDetails *aDetails,
|
||||
char *aBuffer, PRUint32 aBufferSize)
|
||||
{
|
||||
if (!aDetails->library[0]) {
|
||||
snprintf(aBuffer, aBufferSize, "UNKNOWN %p\n", aPC);
|
||||
} else if (!aDetails->function[0]) {
|
||||
snprintf(aBuffer, aBufferSize, "UNKNOWN [%s +0x%08lX]\n",
|
||||
aDetails->library, aDetails->loffset);
|
||||
} else {
|
||||
snprintf(aBuffer, aBufferSize, "%s+0x%08lX [%s +0x%08lX]\n",
|
||||
aDetails->function, aDetails->foffset,
|
||||
aDetails->library, aDetails->loffset);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
#elif defined(__sun) && (defined(__sparc) || defined(sparc) || defined(__i386) || defined(i386))
|
||||
#if defined(__sun) && (defined(__sparc) || defined(sparc) || defined(__i386) || defined(i386))
|
||||
|
||||
/*
|
||||
* Stack walking code for Solaris courtesy of Bart Smaalder's "memtrak".
|
||||
|
@ -1470,6 +1379,159 @@ NS_FormatCodeAddressDetails(void *aPC, const nsCodeAddressDetails *aDetails,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
#else // not __sun-specific
|
||||
|
||||
#if (defined(linux) && defined(__GNUC__) && (defined(__i386) || defined(PPC))) || (defined(XP_MACOSX) && (defined(__i386) || defined(__ppc__))) // i386 or PPC Linux or Mac stackwalking code
|
||||
|
||||
#if __GLIBC__ > 2 || __GLIBC_MINOR > 1
|
||||
#define HAVE___LIBC_STACK_END 1
|
||||
#else
|
||||
#define HAVE___LIBC_STACK_END 0
|
||||
#endif
|
||||
|
||||
#if HAVE___LIBC_STACK_END
|
||||
extern void *__libc_stack_end; // from ld-linux.so
|
||||
#endif
|
||||
|
||||
EXPORT_XPCOM_API(nsresult)
|
||||
NS_StackWalk(NS_WalkStackCallback aCallback, PRUint32 aSkipFrames,
|
||||
void *aClosure)
|
||||
{
|
||||
// Stack walking code courtesy Kipp's "leaky".
|
||||
|
||||
// Get the frame pointer
|
||||
void **bp;
|
||||
#if defined(__i386)
|
||||
__asm__( "movl %%ebp, %0" : "=g"(bp));
|
||||
#else
|
||||
// It would be nice if this worked uniformly, but at least on i386 and
|
||||
// x86_64, it stopped working with gcc 4.1, because it points to the
|
||||
// end of the saved registers instead of the start.
|
||||
bp = (void**) __builtin_frame_address(0);
|
||||
#endif
|
||||
|
||||
int skip = aSkipFrames;
|
||||
while (1) {
|
||||
void **next = (void**)*bp;
|
||||
// bp may not be a frame pointer on i386 if code was compiled with
|
||||
// -fomit-frame-pointer, so do some sanity checks.
|
||||
// (bp should be a frame pointer on ppc(64) but checking anyway may help
|
||||
// a little if the stack has been corrupted.)
|
||||
if (next <= bp ||
|
||||
#if HAVE___LIBC_STACK_END
|
||||
next > __libc_stack_end ||
|
||||
#endif
|
||||
(long(next) & 3)) {
|
||||
break;
|
||||
}
|
||||
#if (defined(__ppc__) && defined(XP_MACOSX)) || defined(__powerpc64__)
|
||||
// ppc mac or powerpc64 linux
|
||||
void *pc = *(bp+2);
|
||||
#else // i386 or powerpc32 linux
|
||||
void *pc = *(bp+1);
|
||||
#endif
|
||||
if (--skip < 0) {
|
||||
(*aCallback)(pc, aClosure);
|
||||
}
|
||||
bp = next;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
#elif defined(HAVE__UNWIND_BACKTRACE)
|
||||
|
||||
// libgcc_s.so symbols _Unwind_Backtrace@@GCC_3.3 and _Unwind_GetIP@@GCC_3.0
|
||||
#include <unwind.h>
|
||||
|
||||
struct unwind_info {
|
||||
NS_WalkStackCallback callback;
|
||||
int skip;
|
||||
void *closure;
|
||||
};
|
||||
|
||||
static _Unwind_Reason_Code
|
||||
unwind_callback (struct _Unwind_Context *context, void *closure)
|
||||
{
|
||||
unwind_info *info = static_cast<unwind_info *>(closure);
|
||||
if (--info->skip < 0) {
|
||||
void *pc = reinterpret_cast<void *>(_Unwind_GetIP(context));
|
||||
(*info->callback)(pc, info->closure);
|
||||
}
|
||||
return _URC_NO_REASON;
|
||||
}
|
||||
|
||||
EXPORT_XPCOM_API(nsresult)
|
||||
NS_StackWalk(NS_WalkStackCallback aCallback, PRUint32 aSkipFrames,
|
||||
void *aClosure)
|
||||
{
|
||||
unwind_info info;
|
||||
info.callback = aCallback;
|
||||
info.skip = aSkipFrames + 1;
|
||||
info.closure = aClosure;
|
||||
|
||||
_Unwind_Backtrace(unwind_callback, &info);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
EXPORT_XPCOM_API(nsresult)
|
||||
NS_DescribeCodeAddress(void *aPC, nsCodeAddressDetails *aDetails)
|
||||
{
|
||||
aDetails->library[0] = '\0';
|
||||
aDetails->loffset = 0;
|
||||
aDetails->filename[0] = '\0';
|
||||
aDetails->lineno = 0;
|
||||
aDetails->function[0] = '\0';
|
||||
aDetails->foffset = 0;
|
||||
|
||||
Dl_info info;
|
||||
int ok = dladdr(aPC, &info);
|
||||
if (!ok) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
PL_strncpyz(aDetails->library, info.dli_fname, sizeof(aDetails->library));
|
||||
aDetails->loffset = (char*)aPC - (char*)info.dli_fbase;
|
||||
|
||||
const char * symbol = info.dli_sname;
|
||||
int len;
|
||||
if (!symbol || !(len = strlen(symbol))) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
char demangled[4096] = "\0";
|
||||
|
||||
DemangleSymbol(symbol, demangled, sizeof(demangled));
|
||||
|
||||
if (strlen(demangled)) {
|
||||
symbol = demangled;
|
||||
len = strlen(symbol);
|
||||
}
|
||||
|
||||
PL_strncpyz(aDetails->function, symbol, sizeof(aDetails->function));
|
||||
aDetails->foffset = (char*)aPC - (char*)info.dli_saddr;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
EXPORT_XPCOM_API(nsresult)
|
||||
NS_FormatCodeAddressDetails(void *aPC, const nsCodeAddressDetails *aDetails,
|
||||
char *aBuffer, PRUint32 aBufferSize)
|
||||
{
|
||||
if (!aDetails->library[0]) {
|
||||
snprintf(aBuffer, aBufferSize, "UNKNOWN %p\n", aPC);
|
||||
} else if (!aDetails->function[0]) {
|
||||
snprintf(aBuffer, aBufferSize, "UNKNOWN [%s +0x%08lX]\n",
|
||||
aDetails->library, aDetails->loffset);
|
||||
} else {
|
||||
snprintf(aBuffer, aBufferSize, "%s+0x%08lX [%s +0x%08lX]\n",
|
||||
aDetails->function, aDetails->foffset,
|
||||
aDetails->library, aDetails->loffset);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#else // unsupported platform.
|
||||
|
|
Загрузка…
Ссылка в новой задаче