[llvm-commits] CVS: llvm/lib/Support/Signals.cpp
Alkis Evlogimenos
alkis at cs.uiuc.edu
Thu Feb 19 01:37:02 PST 2004
Changes in directory llvm/lib/Support:
Signals.cpp updated: 1.11 -> 1.12
---
Log message:
Print stacktrace in STDERR before dying on a fatal signal. Currently
the symbols are not demangled.
---
Diffs of the changes: (+7 -1)
Index: llvm/lib/Support/Signals.cpp
diff -u llvm/lib/Support/Signals.cpp:1.11 llvm/lib/Support/Signals.cpp:1.12
--- llvm/lib/Support/Signals.cpp:1.11 Sun Dec 14 15:35:53 2003
+++ llvm/lib/Support/Signals.cpp Thu Feb 19 01:36:35 2004
@@ -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 *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 @@
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);
}
More information about the llvm-commits
mailing list