Changeset 96595 in webkit


Ignore:
Timestamp:
Oct 4, 2011 8:39:46 AM (12 years ago)
Author:
gavinp@chromium.org
Message:

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:
Location:
trunk/Source/JavaScriptCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r96569 r96595  
     12011-10-04  Gavin Peters  <gavinp@chromium.org>
     2
     3       add more stack dumping methods
     4       https://bugs.webkit.org/show_bug.cgi?id=69018
     5
     6       In addition to WTFReportBacktrace, this adds the cross-platform WTFGetBacktrace, which lets
     7       WebKit programmatically retrieve the current stack.  This is useful if you need to add more
     8       reporting to field crash report uploads, if you're tracking down an irreproducable bug,
     9       for instance.
     10
     11       Reviewed by Darin Adler.
     12
     13       * wtf/Assertions.cpp:
     14       * wtf/Assertions.h:
     15
    1162011-10-03  Filip Pizlo  <fpizlo@apple.com>
    217
  • trunk/Source/JavaScriptCore/wtf/Assertions.cpp

    r95555 r96595  
    5050#endif
    5151
    52 #if PLATFORM(MAC)
     52#if OS(DARWIN) || OS(LINUX)
    5353#include <cxxabi.h>
    5454#include <dlfcn.h>
     
    167167}
    168168
     169void WTFGetBacktrace(void** stack, int* size)
     170{
     171#if OS(DARWIN) || OS(LINUX)
     172    *size = backtrace(stack, *size);
     173#elif OS(WINDOWS)
     174    // The CaptureStackBackTrace function is available in XP, but it is not defined
     175    // in the Windows Server 2003 R2 Platform SDK. So, we'll grab the function
     176    // through GetProcAddress.
     177    typedef WORD (NTAPI* RtlCaptureStackBackTraceFunc)(DWORD, DWORD, PVOID*, PDWORD);
     178    HMODULE kernel32 = ::GetModuleHandleW(L"Kernel32.dll");
     179    if (!kernel32) {
     180        *size = 0;
     181        return;
     182    }
     183    RtlCaptureStackBackTraceFunc captureStackBackTraceFunc = reinterpret_cast<RtlCaptureStackBackTraceFunc>(
     184        ::GetProcAddress(kernel32, "RtlCaptureStackBackTrace"));
     185    if (captureStackBackTraceFunc)
     186        *size = captureStackBackTraceFunc(1, *size, stack, 0);
     187    else
     188        *size = 0;
     189#else
     190    *size = 0;
     191#endif
     192}
     193
    169194void WTFReportBacktrace()
    170195{
    171 #if PLATFORM(MAC)
    172196    static const int maxFrames = 32;
    173197    void* samples[maxFrames];
    174     int frames = backtrace(samples, maxFrames);
     198    int frames = maxFrames;
     199
     200    WTFGetBacktrace(samples, &frames);
    175201
    176202    for (int i = 1; i < frames; ++i) {
    177         void* pointer = samples[i];
    178 
    179         // Try to get a symbol name from the dynamic linker.
     203        const char* mangledName = 0;
     204        char* cxaDemangled = 0;
     205
     206#if !PLATFORM(QT) && (OS(DARWIN) || OS(LINUX))
    180207        Dl_info info;
    181         if (dladdr(pointer, &info) && info.dli_sname) {
    182             const char* mangledName = info.dli_sname;
    183 
    184             // Assume c++ & try to demangle the name.
    185             char* demangledName = abi::__cxa_demangle(mangledName, 0, 0, 0);
    186             if (demangledName) {
    187                 fprintf(stderr, "%-3d %s\n", i, demangledName);
    188                 free(demangledName);
    189             } else
    190                 fprintf(stderr, "%-3d %s\n", i, mangledName);
    191         } else
    192             fprintf(stderr, "%-3d %p\n", i, pointer);
    193     }
    194 #endif
     208        if (dladdr(samples[i], &info) && info.dli_sname)
     209            mangledName = info.dli_sname;
     210        if (mangledName)
     211            cxaDemangled = abi::__cxa_demangle(mangledName, 0, 0, 0);
     212#endif
     213        if (mangledName || cxaDemangled)
     214            fprintf(stderr, "%-3d %p %s\n", i, samples[i], cxaDemangled ? cxaDemangled : mangledName);
     215        else
     216            fprintf(stderr, "%-3d %p\n", i, samples[i]);
     217        free(cxaDemangled);
     218    }
    195219}
    196220
  • trunk/Source/JavaScriptCore/wtf/Assertions.h

    r95555 r96595  
    145145WTF_EXPORT_PRIVATE void WTFReportAssertionFailureWithMessage(const char* file, int line, const char* function, const char* assertion, const char* format, ...) WTF_ATTRIBUTE_PRINTF(5, 6);
    146146WTF_EXPORT_PRIVATE void WTFReportArgumentAssertionFailure(const char* file, int line, const char* function, const char* argName, const char* assertion);
    147 WTF_EXPORT_PRIVATE void WTFReportBacktrace();
    148147WTF_EXPORT_PRIVATE void WTFReportFatalError(const char* file, int line, const char* function, const char* format, ...) WTF_ATTRIBUTE_PRINTF(4, 5);
    149148WTF_EXPORT_PRIVATE void WTFReportError(const char* file, int line, const char* function, const char* format, ...) WTF_ATTRIBUTE_PRINTF(4, 5);
    150149WTF_EXPORT_PRIVATE void WTFLog(WTFLogChannel*, const char* format, ...) WTF_ATTRIBUTE_PRINTF(2, 3);
    151150WTF_EXPORT_PRIVATE void WTFLogVerbose(const char* file, int line, const char* function, WTFLogChannel*, const char* format, ...) WTF_ATTRIBUTE_PRINTF(5, 6);
     151
     152WTF_EXPORT_PRIVATE void WTFGetBacktrace(void** stack, int* size);
     153WTF_EXPORT_PRIVATE void WTFReportBacktrace();
    152154
    153155#ifdef __cplusplus
Note: See TracChangeset for help on using the changeset viewer.