Commit bd3152c8 authored by gavinp@chromium.org's avatar gavinp@chromium.org

add more stack dumping methods

       https://bugs.webkit.org/show_bug.cgi?id=69018

       In addition to WTFReportBacktrace, this adds the cross-platform WTFGetBacktrace, which lets
       WebKit programmatically retrieve the current stack.  This is useful if you need to add more
       reporting to field crash report uploads, if you're tracking down an irreproducable bug,
       for instance.

       Reviewed by Darin Adler.

       * wtf/Assertions.cpp:
       * wtf/Assertions.h:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@96595 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 29d01f5a
2011-10-04 Gavin Peters <gavinp@chromium.org>
add more stack dumping methods
https://bugs.webkit.org/show_bug.cgi?id=69018
In addition to WTFReportBacktrace, this adds the cross-platform WTFGetBacktrace, which lets
WebKit programmatically retrieve the current stack. This is useful if you need to add more
reporting to field crash report uploads, if you're tracking down an irreproducable bug,
for instance.
Reviewed by Darin Adler.
* wtf/Assertions.cpp:
* wtf/Assertions.h:
2011-10-03 Filip Pizlo <fpizlo@apple.com>
DFG should inline Array.push and Array.pop
......@@ -49,7 +49,7 @@
#include <windows.h>
#endif
#if PLATFORM(MAC)
#if OS(DARWIN) || OS(LINUX)
#include <cxxabi.h>
#include <dlfcn.h>
#include <execinfo.h>
......@@ -166,32 +166,56 @@ void WTFReportArgumentAssertionFailure(const char* file, int line, const char* f
printCallSite(file, line, function);
}
void WTFGetBacktrace(void** stack, int* size)
{
#if OS(DARWIN) || OS(LINUX)
*size = backtrace(stack, *size);
#elif OS(WINDOWS)
// The CaptureStackBackTrace function is available in XP, but it is not defined
// in the Windows Server 2003 R2 Platform SDK. So, we'll grab the function
// through GetProcAddress.
typedef WORD (NTAPI* RtlCaptureStackBackTraceFunc)(DWORD, DWORD, PVOID*, PDWORD);
HMODULE kernel32 = ::GetModuleHandleW(L"Kernel32.dll");
if (!kernel32) {
*size = 0;
return;
}
RtlCaptureStackBackTraceFunc captureStackBackTraceFunc = reinterpret_cast<RtlCaptureStackBackTraceFunc>(
::GetProcAddress(kernel32, "RtlCaptureStackBackTrace"));
if (captureStackBackTraceFunc)
*size = captureStackBackTraceFunc(1, *size, stack, 0);
else
*size = 0;
#else
*size = 0;
#endif
}
void WTFReportBacktrace()
{
#if PLATFORM(MAC)
static const int maxFrames = 32;
void* samples[maxFrames];
int frames = backtrace(samples, maxFrames);
int frames = maxFrames;
WTFGetBacktrace(samples, &frames);
for (int i = 1; i < frames; ++i) {
void* pointer = samples[i];
const char* mangledName = 0;
char* cxaDemangled = 0;
// Try to get a symbol name from the dynamic linker.
#if !PLATFORM(QT) && (OS(DARWIN) || OS(LINUX))
Dl_info info;
if (dladdr(pointer, &info) && info.dli_sname) {
const char* mangledName = info.dli_sname;
// Assume c++ & try to demangle the name.
char* demangledName = abi::__cxa_demangle(mangledName, 0, 0, 0);
if (demangledName) {
fprintf(stderr, "%-3d %s\n", i, demangledName);
free(demangledName);
} else
fprintf(stderr, "%-3d %s\n", i, mangledName);
} else
fprintf(stderr, "%-3d %p\n", i, pointer);
}
if (dladdr(samples[i], &info) && info.dli_sname)
mangledName = info.dli_sname;
if (mangledName)
cxaDemangled = abi::__cxa_demangle(mangledName, 0, 0, 0);
#endif
if (mangledName || cxaDemangled)
fprintf(stderr, "%-3d %p %s\n", i, samples[i], cxaDemangled ? cxaDemangled : mangledName);
else
fprintf(stderr, "%-3d %p\n", i, samples[i]);
free(cxaDemangled);
}
}
void WTFReportFatalError(const char* file, int line, const char* function, const char* format, ...)
......
......@@ -144,12 +144,14 @@ typedef struct {
WTF_EXPORT_PRIVATE void WTFReportAssertionFailure(const char* file, int line, const char* function, const char* assertion);
WTF_EXPORT_PRIVATE void WTFReportAssertionFailureWithMessage(const char* file, int line, const char* function, const char* assertion, const char* format, ...) WTF_ATTRIBUTE_PRINTF(5, 6);
WTF_EXPORT_PRIVATE void WTFReportArgumentAssertionFailure(const char* file, int line, const char* function, const char* argName, const char* assertion);
WTF_EXPORT_PRIVATE void WTFReportBacktrace();
WTF_EXPORT_PRIVATE void WTFReportFatalError(const char* file, int line, const char* function, const char* format, ...) WTF_ATTRIBUTE_PRINTF(4, 5);
WTF_EXPORT_PRIVATE void WTFReportError(const char* file, int line, const char* function, const char* format, ...) WTF_ATTRIBUTE_PRINTF(4, 5);
WTF_EXPORT_PRIVATE void WTFLog(WTFLogChannel*, const char* format, ...) WTF_ATTRIBUTE_PRINTF(2, 3);
WTF_EXPORT_PRIVATE void WTFLogVerbose(const char* file, int line, const char* function, WTFLogChannel*, const char* format, ...) WTF_ATTRIBUTE_PRINTF(5, 6);
WTF_EXPORT_PRIVATE void WTFGetBacktrace(void** stack, int* size);
WTF_EXPORT_PRIVATE void WTFReportBacktrace();
#ifdef __cplusplus
}
#endif
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment