llvm.org GIT mirror llvm / 6d6e4e4
Add functions to save and restore the PrettyStackTrace state. PrettyStackTraceHead is a LLVM_THREAD_LOCAL, which means it's just a global in LLVM_ENABLE_THREADS=NO builds. If a CrashRecoveryContext is used with code that uses PrettyStackEntries, and a crash happens, PrettyStackTraceHead is currently not reset to its pre-crash value. These functions make it possible to add a cleanup to such code that does this. (Not reseting the value then causes the assert in ~PrettyStackTraceEntry() to fire if the code outside of the CrashRecoveryContext also uses PrettyStackEntries -- for example, clang when building a module.) Part of PR11974. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@244338 91177308-0d34-0410-b5e6-96231b3b80d8 Nico Weber 5 years ago
2 changed file(s) with 26 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
6565 void print(raw_ostream &OS) const override;
6666 };
6767
68 /// Returns the topmost element of the "pretty" stack state.
69 const void* SavePrettyStackState();
70
71 /// Restores the topmost element of the "pretty" stack state to State, which
72 /// should come from a previous call to SavePrettyStackState(). This is
73 /// useful when using a CrashRecoveryContext in code that also uses
74 /// PrettyStackTraceEntries, to make sure the stack that's printed if a crash
75 /// happens after a crash that's been recovered by CrashRecoveryContext
76 /// doesn't have frames on it that were added in code unwound by the
77 /// CrashRecoveryContext.
78 void RestorePrettyStackState(const void* State);
79
6880 } // end namespace llvm
6981
7082 #endif
153153 #endif
154154 }
155155
156 const void* llvm::SavePrettyStackState() {
157 #if defined(HAVE_BACKTRACE) && defined(ENABLE_BACKTRACES)
158 return PrettyStackTraceHead;
159 #else
160 return nullptr;
161 #endif
162 }
163
164 void llvm::RestorePrettyStackState(const void* Top) {
165 #if defined(HAVE_BACKTRACE) && defined(ENABLE_BACKTRACES)
166 PrettyStackTraceHead = (const PrettyStackTraceEntry*)Top;
167 #endif
168 }
169
156170 void LLVMEnablePrettyStackTrace() {
157171 EnablePrettyStackTrace();
158172 }