From 688940d76349a49ee9ba6c1257fe913c56ddb4cd Mon Sep 17 00:00:00 2001 From: Brian Gaeke Date: Fri, 20 Feb 2004 06:40:59 +0000 Subject: [PATCH] Use backtrace() and include execinfo.h, if they were detected by autoconf. llvm-svn: 11658 --- lib/Support/Signals.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/Support/Signals.cpp b/lib/Support/Signals.cpp index b3baed06683..978d3b7ccb2 100644 --- a/lib/Support/Signals.cpp +++ b/lib/Support/Signals.cpp @@ -17,10 +17,12 @@ #include #include #include -//#include +#include "Config/config.h" // Get the signal handler return type +#ifdef HAVE_EXECINFO_H +# include // For backtrace(). +#endif #include #include -#include "Config/config.h" // Get the signal handler return type using namespace llvm; static std::vector 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); }