X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FSupport%2FPrettyStackTrace.cpp;h=d6782a70e1a4906877151d34767e3a113b07931f;hb=34509ffd82b5929133008e234c490cee8ca5d4b9;hp=2e9634c6946652b49cd603d2248dd10943181eb5;hpb=2aefa011df74864377242e413033166a125ef793;p=oota-llvm.git diff --git a/lib/Support/PrettyStackTrace.cpp b/lib/Support/PrettyStackTrace.cpp index 2e9634c6946..d6782a70e1a 100644 --- a/lib/Support/PrettyStackTrace.cpp +++ b/lib/Support/PrettyStackTrace.cpp @@ -16,6 +16,7 @@ #include "llvm-c/Core.h" #include "llvm/ADT/SmallString.h" #include "llvm/Config/config.h" // Get autoconf configuration settings +#include "llvm/Support/Compiler.h" #include "llvm/Support/Signals.h" #include "llvm/Support/Watchdog.h" #include "llvm/Support/raw_ostream.h" @@ -26,29 +27,15 @@ using namespace llvm; +// If backtrace support is not enabled, compile out support for pretty stack +// traces. This has the secondary effect of not requiring thread local storage +// when backtrace support is disabled. +#if defined(HAVE_BACKTRACE) && defined(ENABLE_BACKTRACES) + // 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 // to pay any overhead of synchronizing. As a consequence, we use a raw -// thread-local variable. Some day, we should be able to use a limited subset -// of C++11's thread_local, but compilers aren't up for it today. -// FIXME: This should be moved to a Compiler.h abstraction. -#ifdef _MSC_VER -// MSVC supports this with a __declspec. -#define LLVM_THREAD_LOCAL __declspec(thread) -#else -// Clang, GCC, and all compatible compilers tend to use __thread. But we need -// to work aronud a bug in the combination of Clang's compilation of -// local-dynamic TLS and the ppc64 linker relocations which we do by forcing to -// general-dynamic. -// FIXME: Make this conditional on the Clang version once this is fixed in -// top-of-tree. -#if defined(__clang__) && defined(__powerpc64__) -#define LLVM_THREAD_LOCAL __thread __attribute__((tls_model("general-dynamic"))) -#else -#define LLVM_THREAD_LOCAL __thread -#endif -#endif - +// thread-local variable. static LLVM_THREAD_LOCAL const PrettyStackTraceEntry *PrettyStackTraceHead = nullptr; @@ -121,16 +108,23 @@ static void CrashHandler(void *) { #endif } +// defined(HAVE_BACKTRACE) && defined(ENABLE_BACKTRACES) +#endif + PrettyStackTraceEntry::PrettyStackTraceEntry() { +#if defined(HAVE_BACKTRACE) && defined(ENABLE_BACKTRACES) // Link ourselves. NextEntry = PrettyStackTraceHead; PrettyStackTraceHead = this; +#endif } PrettyStackTraceEntry::~PrettyStackTraceEntry() { +#if defined(HAVE_BACKTRACE) && defined(ENABLE_BACKTRACES) assert(PrettyStackTraceHead == this && "Pretty stack trace entry destruction is out of order"); PrettyStackTraceHead = getNextEntry(); +#endif } void PrettyStackTraceString::print(raw_ostream &OS) const { @@ -145,15 +139,33 @@ void PrettyStackTraceProgram::print(raw_ostream &OS) const { OS << '\n'; } +#if defined(HAVE_BACKTRACE) && defined(ENABLE_BACKTRACES) static bool RegisterCrashPrinter() { sys::AddSignalHandler(CrashHandler, nullptr); return false; } +#endif void llvm::EnablePrettyStackTrace() { +#if defined(HAVE_BACKTRACE) && defined(ENABLE_BACKTRACES) // The first time this is called, we register the crash printer. static bool HandlerRegistered = RegisterCrashPrinter(); (void)HandlerRegistered; +#endif +} + +const void* llvm::SavePrettyStackState() { +#if defined(HAVE_BACKTRACE) && defined(ENABLE_BACKTRACES) + return PrettyStackTraceHead; +#else + return nullptr; +#endif +} + +void llvm::RestorePrettyStackState(const void* Top) { +#if defined(HAVE_BACKTRACE) && defined(ENABLE_BACKTRACES) + PrettyStackTraceHead = (const PrettyStackTraceEntry*)Top; +#endif } void LLVMEnablePrettyStackTrace() {