From e58c09d31bdf90210e2ec1ef976cea0459cdc02a Mon Sep 17 00:00:00 2001 From: Adam Jackson Date: Sat, 2 Jul 2005 18:06:05 +0000 Subject: [PATCH] Bug #3687: Print backtraces on fatal signal on glibc systems. --- hw/xfree86/common/xf86Events.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/hw/xfree86/common/xf86Events.c b/hw/xfree86/common/xf86Events.c index 14d653f1a..318d8b0ab 100644 --- a/hw/xfree86/common/xf86Events.c +++ b/hw/xfree86/common/xf86Events.c @@ -1273,6 +1273,29 @@ xf86InterceptSigIll(void (*sigillhandler)(void)) xf86SigIllHandler = sigillhandler; } +#if defined(__GLIBC__) && __GLIBC_PREREQ(2, 1) + +#include + +static inline void xorg_backtrace(void) +{ + void *array[32]; /* deeper nesting than this means something's wrong */ + size_t size, i; + char **strings; + ErrorF("\nBacktrace:\n"); + size = backtrace(array, 32); + strings = backtrace_symbols(array, size); + for (i = 0; i < size; i++) + ErrorF("%d: %s\n", i, strings[i]); + free(strings); +} + +#else /* not glibc or glibc < 2.1 */ + +static inline void xorg_backtrace(void) { return; } + +#endif + /* * xf86SigHandler -- * Catch unexpected signals and exit or continue cleanly. @@ -1306,6 +1329,9 @@ xf86SigHandler(int signo) " *** If unresolved symbols were reported above, they might not\n" " *** be the reason for the server aborting.\n"); #endif + + xorg_backtrace(); + FatalError("Caught signal %d. Server aborting\n", signo); }