forked from OSchip/llvm-project
Support: enable backtraces on Windows
Some platforms, e.g. Windows, support backtraces but don't have BACKTRACE. Checking for BACKTRACE prevents Windows from having backtraces. Patch by Jason Mittertreiner! llvm-svn: 354951
This commit is contained in:
parent
7d3986ea30
commit
b67342e7cb
|
@ -33,7 +33,7 @@ using namespace llvm;
|
||||||
// If backtrace support is not enabled, compile out support for pretty stack
|
// If backtrace support is not enabled, compile out support for pretty stack
|
||||||
// traces. This has the secondary effect of not requiring thread local storage
|
// traces. This has the secondary effect of not requiring thread local storage
|
||||||
// when backtrace support is disabled.
|
// when backtrace support is disabled.
|
||||||
#if defined(HAVE_BACKTRACE) && ENABLE_BACKTRACES
|
#if ENABLE_BACKTRACES
|
||||||
|
|
||||||
// We need a thread local pointer to manage the stack of our stack trace
|
// We need a thread local pointer to manage the stack of our stack trace
|
||||||
// objects, but we *really* cannot tolerate destructors running and do not want
|
// objects, but we *really* cannot tolerate destructors running and do not want
|
||||||
|
@ -127,11 +127,10 @@ static void CrashHandler(void *) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// defined(HAVE_BACKTRACE) && ENABLE_BACKTRACES
|
#endif // ENABLE_BACKTRACES
|
||||||
#endif
|
|
||||||
|
|
||||||
PrettyStackTraceEntry::PrettyStackTraceEntry() {
|
PrettyStackTraceEntry::PrettyStackTraceEntry() {
|
||||||
#if defined(HAVE_BACKTRACE) && ENABLE_BACKTRACES
|
#if ENABLE_BACKTRACES
|
||||||
// Link ourselves.
|
// Link ourselves.
|
||||||
NextEntry = PrettyStackTraceHead;
|
NextEntry = PrettyStackTraceHead;
|
||||||
PrettyStackTraceHead = this;
|
PrettyStackTraceHead = this;
|
||||||
|
@ -139,7 +138,7 @@ PrettyStackTraceEntry::PrettyStackTraceEntry() {
|
||||||
}
|
}
|
||||||
|
|
||||||
PrettyStackTraceEntry::~PrettyStackTraceEntry() {
|
PrettyStackTraceEntry::~PrettyStackTraceEntry() {
|
||||||
#if defined(HAVE_BACKTRACE) && ENABLE_BACKTRACES
|
#if ENABLE_BACKTRACES
|
||||||
assert(PrettyStackTraceHead == this &&
|
assert(PrettyStackTraceHead == this &&
|
||||||
"Pretty stack trace entry destruction is out of order");
|
"Pretty stack trace entry destruction is out of order");
|
||||||
PrettyStackTraceHead = NextEntry;
|
PrettyStackTraceHead = NextEntry;
|
||||||
|
@ -174,7 +173,7 @@ void PrettyStackTraceProgram::print(raw_ostream &OS) const {
|
||||||
OS << '\n';
|
OS << '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(HAVE_BACKTRACE) && ENABLE_BACKTRACES
|
#if ENABLE_BACKTRACES
|
||||||
static bool RegisterCrashPrinter() {
|
static bool RegisterCrashPrinter() {
|
||||||
sys::AddSignalHandler(CrashHandler, nullptr);
|
sys::AddSignalHandler(CrashHandler, nullptr);
|
||||||
return false;
|
return false;
|
||||||
|
@ -182,7 +181,7 @@ static bool RegisterCrashPrinter() {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void llvm::EnablePrettyStackTrace() {
|
void llvm::EnablePrettyStackTrace() {
|
||||||
#if defined(HAVE_BACKTRACE) && ENABLE_BACKTRACES
|
#if ENABLE_BACKTRACES
|
||||||
// The first time this is called, we register the crash printer.
|
// The first time this is called, we register the crash printer.
|
||||||
static bool HandlerRegistered = RegisterCrashPrinter();
|
static bool HandlerRegistered = RegisterCrashPrinter();
|
||||||
(void)HandlerRegistered;
|
(void)HandlerRegistered;
|
||||||
|
@ -190,7 +189,7 @@ void llvm::EnablePrettyStackTrace() {
|
||||||
}
|
}
|
||||||
|
|
||||||
const void *llvm::SavePrettyStackState() {
|
const void *llvm::SavePrettyStackState() {
|
||||||
#if defined(HAVE_BACKTRACE) && ENABLE_BACKTRACES
|
#if ENABLE_BACKTRACES
|
||||||
return PrettyStackTraceHead;
|
return PrettyStackTraceHead;
|
||||||
#else
|
#else
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -198,7 +197,7 @@ const void *llvm::SavePrettyStackState() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void llvm::RestorePrettyStackState(const void *Top) {
|
void llvm::RestorePrettyStackState(const void *Top) {
|
||||||
#if defined(HAVE_BACKTRACE) && ENABLE_BACKTRACES
|
#if ENABLE_BACKTRACES
|
||||||
PrettyStackTraceHead =
|
PrettyStackTraceHead =
|
||||||
static_cast<PrettyStackTraceEntry *>(const_cast<void *>(Top));
|
static_cast<PrettyStackTraceEntry *>(const_cast<void *>(Top));
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue