From b329bd26b84bc1ea1a984b56031afdc3444c4636 Mon Sep 17 00:00:00 2001 From: "kbalazs@webkit.org" Date: Wed, 18 Jan 2012 13:35:57 +0000 Subject: [PATCH] [Qt] Consolidate layout test crash logging https://bugs.webkit.org/show_bug.cgi?id=75088 Reviewed by Simon Hausmann. Move backtrace generating logic into WTFReportBacktrace and add a way to deinstall signal handlers if we know that we have already printed the backtrace. .: * Source/qtwebkit-export.map: Source/JavaScriptCore: * JavaScriptCore.exp: * JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def: * wtf/Assertions.cpp: (WTFLogLocker::WTFReportBacktrace): (WTFLogLocker::WTFSetCrashHook): (WTFLogLocker::WTFInvokeCrashHook): * wtf/Assertions.h: Tools: * DumpRenderTree/qt/main.cpp: (crashHandler): (setupSignalHandlers): (WTFCrashHook): (main): * WebKitTestRunner/InjectedBundle/qt/InjectedBundleQt.cpp: (WTR::crashHandler): (WTR::setupSignalHandlers): (WTR::crashHook): (WTR::InjectedBundle::platformInitialize): git-svn-id: http://svn.webkit.org/repository/webkit/trunk@105267 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- ChangeLog | 13 +++++ Source/JavaScriptCore/ChangeLog | 19 +++++++ Source/JavaScriptCore/JavaScriptCore.exp | 2 + .../JavaScriptCore/JavaScriptCore.def | 2 + Source/JavaScriptCore/wtf/Assertions.cpp | 41 +++++++++++++- Source/JavaScriptCore/wtf/Assertions.h | 6 +++ Source/qtwebkit-export.map | 2 + Tools/ChangeLog | 22 ++++++++ Tools/DumpRenderTree/qt/main.cpp | 63 +++++++++------------- .../InjectedBundle/qt/InjectedBundleQt.cpp | 57 ++++++++------------ 10 files changed, 152 insertions(+), 75 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5e2575b..0e4fc0b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2012-01-18 Balazs Kelemen + + [Qt] Consolidate layout test crash logging + https://bugs.webkit.org/show_bug.cgi?id=75088 + + Reviewed by Simon Hausmann. + + Move backtrace generating logic into WTFReportBacktrace + and add a way to deinstall signal handlers if we know + that we have already printed the backtrace. + + * Source/qtwebkit-export.map: + 2012-01-18 Tor Arne Vestbø [Qt] Move OTHER_FILES from WebKit.pro to Tools.pro diff --git a/Source/JavaScriptCore/ChangeLog b/Source/JavaScriptCore/ChangeLog index 6f41cbc..073993f 100644 --- a/Source/JavaScriptCore/ChangeLog +++ b/Source/JavaScriptCore/ChangeLog @@ -1,3 +1,22 @@ +2012-01-18 Balazs Kelemen + + [Qt] Consolidate layout test crash logging + https://bugs.webkit.org/show_bug.cgi?id=75088 + + Reviewed by Simon Hausmann. + + Move backtrace generating logic into WTFReportBacktrace + and add a way to deinstall signal handlers if we know + that we have already printed the backtrace. + + * JavaScriptCore.exp: + * JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def: + * wtf/Assertions.cpp: + (WTFLogLocker::WTFReportBacktrace): + (WTFLogLocker::WTFSetCrashHook): + (WTFLogLocker::WTFInvokeCrashHook): + * wtf/Assertions.h: + 2012-01-17 Geoffrey Garen Factored out some code into a helper function. diff --git a/Source/JavaScriptCore/JavaScriptCore.exp b/Source/JavaScriptCore/JavaScriptCore.exp index fd61f15..ebddada 100644 --- a/Source/JavaScriptCore/JavaScriptCore.exp +++ b/Source/JavaScriptCore/JavaScriptCore.exp @@ -91,6 +91,7 @@ _JSWeakObjectMapGet _JSWeakObjectMapRemove _JSWeakObjectMapSet _WTFGetBacktrace +_WTFInvokeCrashHook _WTFLog _WTFLogVerbose _WTFReportArgumentAssertionFailure @@ -99,6 +100,7 @@ _WTFReportAssertionFailureWithMessage _WTFReportBacktrace _WTFReportError _WTFReportFatalError +_WTFSetCrashHook __ZN14OpaqueJSString6createERKN3JSC7UStringE __ZN3JSC10HandleHeap12writeBarrierEPNS_7JSValueERKS1_ __ZN3JSC10HandleHeap4growEv diff --git a/Source/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def b/Source/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def index 6694177..3827815 100644 --- a/Source/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def +++ b/Source/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def @@ -367,6 +367,7 @@ EXPORTS ?writeBarrier@HandleHeap@JSC@@QAEXPAVJSValue@2@ABV32@@Z ?yield@WTF@@YAXXZ WTFGetBacktrace + WTFInvokeCrashHook WTFLog WTFLogVerbose WTFReportArgumentAssertionFailure @@ -374,3 +375,4 @@ EXPORTS WTFReportAssertionFailureWithMessage WTFReportBacktrace WTFReportError + WTFSetCrashHook diff --git a/Source/JavaScriptCore/wtf/Assertions.cpp b/Source/JavaScriptCore/wtf/Assertions.cpp index 3da67ef..80afcf4 100644 --- a/Source/JavaScriptCore/wtf/Assertions.cpp +++ b/Source/JavaScriptCore/wtf/Assertions.cpp @@ -272,6 +272,16 @@ void WTFGetBacktrace(void** stack, int* size) #endif } +#if OS(DARWIN) || OS(LINUX) +# if PLATFORM(QT) || PLATFORM(GTK) +# if defined(__GLIBC__) && !defined(__UCLIBC__) +# define WTF_USE_BACKTRACE_SYMBOLS 1 +# endif +# else +# define WTF_USE_DLADDR 1 +# endif +#endif + void WTFReportBacktrace() { static const int framesToShow = 31; @@ -281,11 +291,18 @@ void WTFReportBacktrace() WTFGetBacktrace(samples, &frames); +#if USE(BACKTRACE_SYMBOLS) + char** symbols = backtrace_symbols(samples, frames); + if (!symbols) + return; +#endif + for (int i = framesToSkip; i < frames; ++i) { const char* mangledName = 0; char* cxaDemangled = 0; - -#if !PLATFORM(GTK) && !PLATFORM(QT) && (OS(DARWIN) || OS(LINUX)) +#if USE(BACKTRACE_SYMBOLS) + mangledName = symbols[i]; +#elif USE(DLADDR) Dl_info info; if (dladdr(samples[i], &info) && info.dli_sname) mangledName = info.dli_sname; @@ -299,6 +316,26 @@ void WTFReportBacktrace() printf_stderr_common("%-3d %p\n", frameNumber, samples[i]); free(cxaDemangled); } + +#if USE(BACKTRACE_SYMBOLS) + free(symbols); +#endif +} + +#undef WTF_USE_BACKTRACE_SYMBOLS +#undef WTF_USE_DLADDR + +static WTFCrashHookFunction globalHook = 0; + +void WTFSetCrashHook(WTFCrashHookFunction function) +{ + globalHook = function; +} + +void WTFInvokeCrashHook() +{ + if (globalHook) + globalHook(); } void WTFReportFatalError(const char* file, int line, const char* function, const char* format, ...) diff --git a/Source/JavaScriptCore/wtf/Assertions.h b/Source/JavaScriptCore/wtf/Assertions.h index 2b3d794..42dc0bd 100644 --- a/Source/JavaScriptCore/wtf/Assertions.h +++ b/Source/JavaScriptCore/wtf/Assertions.h @@ -147,6 +147,10 @@ WTF_EXPORT_PRIVATE void WTFLogVerbose(const char* file, int line, const char* fu WTF_EXPORT_PRIVATE void WTFGetBacktrace(void** stack, int* size); WTF_EXPORT_PRIVATE void WTFReportBacktrace(); +typedef void (*WTFCrashHookFunction)(); +WTF_EXPORT_PRIVATE void WTFSetCrashHook(WTFCrashHookFunction); +WTF_EXPORT_PRIVATE void WTFInvokeCrashHook(); + #ifdef __cplusplus } #endif @@ -163,12 +167,14 @@ WTF_EXPORT_PRIVATE void WTFReportBacktrace(); #if COMPILER(CLANG) #define CRASH() do { \ WTFReportBacktrace(); \ + WTFInvokeCrashHook(); \ *(int *)(uintptr_t)0xbbadbeef = 0; \ __builtin_trap(); \ } while (false) #else #define CRASH() do { \ WTFReportBacktrace(); \ + WTFInvokeCrashHook(); \ *(int *)(uintptr_t)0xbbadbeef = 0; \ ((void(*)())0)(); /* More reliable, but doesn't say BBADBEEF */ \ } while (false) diff --git a/Source/qtwebkit-export.map b/Source/qtwebkit-export.map index 3af8492..ba2e2fb 100644 --- a/Source/qtwebkit-export.map +++ b/Source/qtwebkit-export.map @@ -40,6 +40,8 @@ qwk_1.0 { WTFReportArgumentAssertionFailure; WTFReportAssertionFailure; WTFReportBacktrace; + WTFInvokeCrashHook; + WTFSetCrashHook; extern "C++" { # WebKit 1 API *QGraphicsWebView; diff --git a/Tools/ChangeLog b/Tools/ChangeLog index baddf0a..3258909 100644 --- a/Tools/ChangeLog +++ b/Tools/ChangeLog @@ -1,3 +1,25 @@ +2012-01-18 Balazs Kelemen + + [Qt] Consolidate layout test crash logging + https://bugs.webkit.org/show_bug.cgi?id=75088 + + Reviewed by Simon Hausmann. + + Move backtrace generating logic into WTFReportBacktrace + and add a way to deinstall signal handlers if we know + that we have already printed the backtrace. + + * DumpRenderTree/qt/main.cpp: + (crashHandler): + (setupSignalHandlers): + (WTFCrashHook): + (main): + * WebKitTestRunner/InjectedBundle/qt/InjectedBundleQt.cpp: + (WTR::crashHandler): + (WTR::setupSignalHandlers): + (WTR::crashHook): + (WTR::InjectedBundle::platformInitialize): + 2012-01-18 Ilya Tikhonovsky Unreviewed build fix after r105256. diff --git a/Tools/DumpRenderTree/qt/main.cpp b/Tools/DumpRenderTree/qt/main.cpp index 3d9673b..43f5294 100644 --- a/Tools/DumpRenderTree/qt/main.cpp +++ b/Tools/DumpRenderTree/qt/main.cpp @@ -53,9 +53,8 @@ #include #include -#if defined(__GLIBC__) && !defined(__UCLIBC__) -#include -#endif +#include +#include void messageHandler(QtMsgType type, const char *message) { @@ -93,38 +92,31 @@ void printUsage() fflush(stderr); } -QString get_backtrace() { - QString s; - -#if defined(__GLIBC__) && !defined(__UCLIBC__) - void* array[256]; - size_t size; /* number of stack frames */ - - size = backtrace(array, 256); - - if (!size) - return s; - - char** strings = backtrace_symbols(array, size); - for (int i = 0; i < int(size); ++i) { - s += QString::number(i) + - QLatin1String(": ") + - QLatin1String(strings[i]) + QLatin1String("\n"); - } +#if HAVE(SIGNAL_H) +typedef void (*SignalHandler)(int); - if (strings) - free (strings); -#endif +static NO_RETURN void crashHandler(int sig) +{ + WTFReportBacktrace(); + exit(128 + sig); +} - return s; +static void setupSignalHandlers(SignalHandler handler) +{ + signal(SIGILL, handler); /* 4: illegal instruction (not reset when caught) */ + signal(SIGTRAP, handler); /* 5: trace trap (not reset when caught) */ + signal(SIGFPE, handler); /* 8: floating point exception */ + signal(SIGBUS, handler); /* 10: bus error */ + signal(SIGSEGV, handler); /* 11: segmentation violation */ + signal(SIGSYS, handler); /* 12: bad argument to system call */ + signal(SIGPIPE, handler); /* 13: write on a pipe with no reader */ + signal(SIGXCPU, handler); /* 24: exceeded CPU time limit */ + signal(SIGXFSZ, handler); /* 25: exceeded file size limit */ } -#if HAVE(SIGNAL_H) -static NO_RETURN void crashHandler(int sig) +static void WTFCrashHook() { - fprintf(stderr, "%s\n", strsignal(sig)); - fprintf(stderr, "%s\n", get_backtrace().toLatin1().constData()); - exit(128 + sig); + setupSignalHandlers(SIG_DFL); } #endif @@ -175,15 +167,8 @@ int main(int argc, char* argv[]) QApplication::setFont(QWidget().font()); #if HAVE(SIGNAL_H) - signal(SIGILL, crashHandler); /* 4: illegal instruction (not reset when caught) */ - signal(SIGTRAP, crashHandler); /* 5: trace trap (not reset when caught) */ - signal(SIGFPE, crashHandler); /* 8: floating point exception */ - signal(SIGBUS, crashHandler); /* 10: bus error */ - signal(SIGSEGV, crashHandler); /* 11: segmentation violation */ - signal(SIGSYS, crashHandler); /* 12: bad argument to system call */ - signal(SIGPIPE, crashHandler); /* 13: write on a pipe with no reader */ - signal(SIGXCPU, crashHandler); /* 24: exceeded CPU time limit */ - signal(SIGXFSZ, crashHandler); /* 25: exceeded file size limit */ + setupSignalHandlers(&crashHandler); + WTFSetCrashHook(&WTFCrashHook); #endif QStringList args = app.arguments(); diff --git a/Tools/WebKitTestRunner/InjectedBundle/qt/InjectedBundleQt.cpp b/Tools/WebKitTestRunner/InjectedBundle/qt/InjectedBundleQt.cpp index 7edb58b..6420e7d 100644 --- a/Tools/WebKitTestRunner/InjectedBundle/qt/InjectedBundleQt.cpp +++ b/Tools/WebKitTestRunner/InjectedBundle/qt/InjectedBundleQt.cpp @@ -31,43 +31,39 @@ #include #include #include +#include #if HAVE(SIGNAL_H) #include #endif -#if defined(__GLIBC__) && !defined(__UCLIBC__) -#include -#endif - namespace WTR { -static inline void printBacktrace() -{ -#if defined(__GLIBC__) && !defined(__UCLIBC__) - void* frames[256]; - size_t size = backtrace(frames, 256); - if (!size) - return; - - char** symbols = backtrace_symbols(frames, size); - if (!symbols) - return; +#if HAVE(SIGNAL_H) +typedef void (*SignalHandler)(int); - for (unsigned i = 0; i < size; ++i) - fprintf(stderr, "%u: %s\n", i, symbols[i]); +static NO_RETURN void crashHandler(int sig) +{ + WTFReportBacktrace(); + exit(128 + sig); +} - fflush(stderr); - free(symbols); -#endif +static void setupSignalHandlers(SignalHandler handler) +{ + signal(SIGILL, handler); /* 4: illegal instruction (not reset when caught) */ + signal(SIGTRAP, handler); /* 5: trace trap (not reset when caught) */ + signal(SIGFPE, handler); /* 8: floating point exception */ + signal(SIGBUS, handler); /* 10: bus error */ + signal(SIGSEGV, handler); /* 11: segmentation violation */ + signal(SIGSYS, handler); /* 12: bad argument to system call */ + signal(SIGPIPE, handler); /* 13: write on a pipe with no reader */ + signal(SIGXCPU, handler); /* 24: exceeded CPU time limit */ + signal(SIGXFSZ, handler); /* 25: exceeded file size limit */ } -#if HAVE(SIGNAL_H) -static NO_RETURN void crashHandler(int signal) +static void crashHook() { - fprintf(stderr, "%s\n", strsignal(signal)); - printBacktrace(); - exit(128 + signal); + setupSignalHandlers(SIG_DFL); } #endif @@ -77,15 +73,8 @@ void InjectedBundle::platformInitialize(WKTypeRef) return; #if HAVE(SIGNAL_H) - signal(SIGILL, crashHandler); /* 4: illegal instruction (not reset when caught) */ - signal(SIGTRAP, crashHandler); /* 5: trace trap (not reset when caught) */ - signal(SIGFPE, crashHandler); /* 8: floating point exception */ - signal(SIGBUS, crashHandler); /* 10: bus error */ - signal(SIGSEGV, crashHandler); /* 11: segmentation violation */ - signal(SIGSYS, crashHandler); /* 12: bad argument to system call */ - signal(SIGPIPE, crashHandler); /* 13: write on a pipe with no reader */ - signal(SIGXCPU, crashHandler); /* 24: exceeded CPU time limit */ - signal(SIGXFSZ, crashHandler); /* 25: exceeded file size limit */ + setupSignalHandlers(&crashHandler); + WTFSetCrashHook(&crashHook); #endif } -- 2.7.4