summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Gaeke <gaeke@uiuc.edu>2004-02-20 06:40:59 +0000
committerBrian Gaeke <gaeke@uiuc.edu>2004-02-20 06:40:59 +0000
commit38ce7e57d4eb43d7868f08d55a7b7343cc3eea8c (patch)
tree5c2d098a043a5c5a34dcf914209283104b2cfa1c
parent0c803894985f80e894b36ad4de58ea4c2e906b07 (diff)
downloadllvm-38ce7e57d4eb43d7868f08d55a7b7343cc3eea8c.tar.gz
llvm-38ce7e57d4eb43d7868f08d55a7b7343cc3eea8c.tar.bz2
llvm-38ce7e57d4eb43d7868f08d55a7b7343cc3eea8c.tar.xz
Use backtrace() and include execinfo.h, if they were detected by autoconf.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11658 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Support/Signals.cpp15
1 files changed, 10 insertions, 5 deletions
diff --git a/lib/Support/Signals.cpp b/lib/Support/Signals.cpp
index b3baed0668..978d3b7ccb 100644
--- a/lib/Support/Signals.cpp
+++ b/lib/Support/Signals.cpp
@@ -17,10 +17,12 @@
#include <algorithm>
#include <cstdlib>
#include <cstdio>
-//#include <execinfo.h>
+#include "Config/config.h" // Get the signal handler return type
+#ifdef HAVE_EXECINFO_H
+# include <execinfo.h> // For backtrace().
+#endif
#include <signal.h>
#include <unistd.h>
-#include "Config/config.h" // Get the signal handler return type
using namespace llvm;
static std::vector<std::string> FilesToRemove;
@@ -54,9 +56,12 @@ static RETSIGTYPE SignalHandler(int Sig) {
exit(1); // If this is an interrupt signal, exit the program
// 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);
+ // STDERR (if we can) and reissue the signal to die...
+#ifdef HAVE_BACKTRACE
+ // Use backtrace() to output a backtrace on Linux systems with glibc.
+ int depth = backtrace(StackTrace, sizeof(StackTrace)/sizeof(StackTrace[0]));
+ backtrace_symbols_fd(StackTrace, depth, STDERR_FILENO);
+#endif
signal(Sig, SIG_DFL);
}