llvm.org GIT mirror llvm / fe90da8
Revert r227332, which merged in r227300: "[LPM] Rip all of ManagedStatic and ThreadLocal out of the pretty stack tracing code." The patch has been having trouble on trunk and doesn't seem ready for 3.6. Reverting to get it out of the branch before tagging rc2. git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_36@227646 91177308-0d34-0410-b5e6-96231b3b80d8 Hans Wennborg 4 years ago
1 changed file(s) with 21 addition(s) and 18 deletion(s). Raw diff Collapse all Expand all
1515 #include "llvm-c/Core.h"
1616 #include "llvm/ADT/SmallString.h"
1717 #include "llvm/Config/config.h" // Get autoconf configuration settings
18 #include "llvm/Support/ManagedStatic.h"
1819 #include "llvm/Support/Signals.h"
20 #include "llvm/Support/ThreadLocal.h"
1921 #include "llvm/Support/Watchdog.h"
2022 #include "llvm/Support/raw_ostream.h"
2123
2527
2628 using namespace llvm;
2729
28 // We need a thread local pointer to manage the stack of our stack trace
29 // objects, but we *really* cannot tolerate destructors running and do not want
30 // to pay any overhead of synchronizing. As a consequence, we use a raw
31 // thread-local variable. Some day, we should be able to use a limited subset
32 // of C++11's thread_local, but compilers aren't up for it today.
33 // FIXME: This should be moved to a Compiler.h abstraction.
34 #ifdef _MSC_VER // MSVC supports this with a __declspec.
35 static __declspec(thread) const PrettyStackTraceEntry
36 *PrettyStackTraceHead = nullptr;
37 #else // Clang, GCC, and all compatible compilers tend to use __thread.
38 static __thread const PrettyStackTraceEntry *PrettyStackTraceHead = nullptr;
39 #endif
30 static ManagedStatic > PrettyStackTraceHead;
4031
4132 static unsigned PrintStack(const PrettyStackTraceEntry *Entry, raw_ostream &OS){
4233 unsigned NextID = 0;
5445 /// PrintCurStackTrace - Print the current stack trace to the specified stream.
5546 static void PrintCurStackTrace(raw_ostream &OS) {
5647 // Don't print an empty trace.
57 if (!PrettyStackTraceHead) return;
48 if (!PrettyStackTraceHead->get()) return;
5849
5950 // If there are pretty stack frames registered, walk and emit them.
6051 OS << "Stack dump:\n";
6152
62 PrintStack(PrettyStackTraceHead, OS);
53 PrintStack(PrettyStackTraceHead->get(), OS);
6354 OS.flush();
6455 }
6556
109100
110101 PrettyStackTraceEntry::PrettyStackTraceEntry() {
111102 // Link ourselves.
112 NextEntry = PrettyStackTraceHead;
113 PrettyStackTraceHead = this;
103 NextEntry = PrettyStackTraceHead->get();
104 PrettyStackTraceHead->set(this);
114105 }
115106
116107 PrettyStackTraceEntry::~PrettyStackTraceEntry() {
117 assert(PrettyStackTraceHead == this &&
108 // Do nothing if PrettyStackTraceHead is uninitialized. This can only happen
109 // if a shutdown occurred after we created the PrettyStackTraceEntry. That
110 // does occur in the following idiom:
111 //
112 // PrettyStackTraceProgram X(...);
113 // llvm_shutdown_obj Y;
114 //
115 // Without this check, we may end up removing ourselves from the stack trace
116 // after PrettyStackTraceHead has already been destroyed.
117 if (!PrettyStackTraceHead.isConstructed())
118 return;
119
120 assert(PrettyStackTraceHead->get() == this &&
118121 "Pretty stack trace entry destruction is out of order");
119 PrettyStackTraceHead = getNextEntry();
122 PrettyStackTraceHead->set(getNextEntry());
120123 }
121124
122125 void PrettyStackTraceString::print(raw_ostream &OS) const {