diff options
author | Alkis Evlogimenos <alkis@evlogimenos.com> | 2004-02-19 07:36:35 +0000 |
---|---|---|
committer | Alkis Evlogimenos <alkis@evlogimenos.com> | 2004-02-19 07:36:35 +0000 |
commit | 280f9c939df526cca97b025bca405fb495db474d (patch) | |
tree | 70f1aa56140c9e7122bbbfd070ced50dc7cf7545 /lib/Support/Signals.cpp | |
parent | 2acef2da068763d7a48934de96a2fbef440beee5 (diff) |
Print stacktrace in STDERR before dying on a fatal signal. Currently
the symbols are not demangled.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11620 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/Signals.cpp')
-rw-r--r-- | lib/Support/Signals.cpp | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/Support/Signals.cpp b/lib/Support/Signals.cpp index 27e3eb80e5..03482f9512 100644 --- a/lib/Support/Signals.cpp +++ b/lib/Support/Signals.cpp @@ -17,7 +17,9 @@ #include <algorithm> #include <cstdlib> #include <cstdio> +#include <execinfo.h> #include <signal.h> +#include <unistd.h> #include "Config/config.h" // Get the signal handler return type using namespace llvm; @@ -39,6 +41,7 @@ static const int KillSigs[] = { }; static const int *KillSigsEnd = KillSigs + sizeof(KillSigs)/sizeof(KillSigs[0]); +static void* StackTrace[256]; // SignalHandler - The signal handler that runs... static RETSIGTYPE SignalHandler(int Sig) { @@ -50,7 +53,10 @@ static RETSIGTYPE SignalHandler(int Sig) { if (std::find(IntSigs, IntSigsEnd, Sig) != IntSigsEnd) exit(1); // If this is an interrupt signal, exit the program - // Otherwise if it is a fault (like SEGV) reissue the signal to die... + // Otherwise if it is a fault (like SEGV) output the stacktrace to + // STDERR and reissue the signal to die... + int depth = backtrace(StackTrace, sizeof(StackTrace)/sizeof(StackTrace[0])); + backtrace_symbols_fd(StackTrace, depth, STDERR_FILENO); signal(Sig, SIG_DFL); } |