summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/Signals.cpp
diff options
context:
space:
mode:
authorAlkis Evlogimenos <alkis@evlogimenos.com>2004-02-19 07:36:35 +0000
committerAlkis Evlogimenos <alkis@evlogimenos.com>2004-02-19 07:36:35 +0000
commitc94edd6cdee4f3a51ae42be6e3cb6c585271c8be (patch)
treeeb17d14c70c62fc0266580bdfe0d32dcdae91ee8 /llvm/lib/Support/Signals.cpp
parentd0a60b71fc3da869e4796ffb1f97d7fa003c8db9 (diff)
downloadbcm5719-llvm-c94edd6cdee4f3a51ae42be6e3cb6c585271c8be.tar.gz
bcm5719-llvm-c94edd6cdee4f3a51ae42be6e3cb6c585271c8be.zip
Print stacktrace in STDERR before dying on a fatal signal. Currently
the symbols are not demangled. llvm-svn: 11620
Diffstat (limited to 'llvm/lib/Support/Signals.cpp')
-rw-r--r--llvm/lib/Support/Signals.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/llvm/lib/Support/Signals.cpp b/llvm/lib/Support/Signals.cpp
index 27e3eb80e50..03482f9512c 100644
--- a/llvm/lib/Support/Signals.cpp
+++ b/llvm/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);
}
OpenPOWER on IntegriCloud