[llvm] r244338 - Add functions to save and restore the PrettyStackTrace state.

Nico Weber via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 7 10:47:03 PDT 2015


Author: nico
Date: Fri Aug  7 12:47:03 2015
New Revision: 244338

URL: http://llvm.org/viewvc/llvm-project?rev=244338&view=rev
Log:
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.

Modified:
    llvm/trunk/include/llvm/Support/PrettyStackTrace.h
    llvm/trunk/lib/Support/PrettyStackTrace.cpp

Modified: llvm/trunk/include/llvm/Support/PrettyStackTrace.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/PrettyStackTrace.h?rev=244338&r1=244337&r2=244338&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/PrettyStackTrace.h (original)
+++ llvm/trunk/include/llvm/Support/PrettyStackTrace.h Fri Aug  7 12:47:03 2015
@@ -66,6 +66,18 @@ namespace llvm {
     void print(raw_ostream &OS) const override;
   };
 
+  /// Returns the topmost element of the "pretty" stack state.
+  const void* SavePrettyStackState();
+
+  /// Restores the topmost element of the "pretty" stack state to State, which
+  /// should come from a previous call to SavePrettyStackState().  This is
+  /// useful when using a CrashRecoveryContext in code that also uses
+  /// PrettyStackTraceEntries, to make sure the stack that's printed if a crash
+  /// happens after a crash that's been recovered by CrashRecoveryContext
+  /// doesn't have frames on it that were added in code unwound by the
+  /// CrashRecoveryContext.
+  void RestorePrettyStackState(const void* State);
+
 } // end namespace llvm
 
 #endif

Modified: llvm/trunk/lib/Support/PrettyStackTrace.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/PrettyStackTrace.cpp?rev=244338&r1=244337&r2=244338&view=diff
==============================================================================
--- llvm/trunk/lib/Support/PrettyStackTrace.cpp (original)
+++ llvm/trunk/lib/Support/PrettyStackTrace.cpp Fri Aug  7 12:47:03 2015
@@ -154,6 +154,20 @@ void llvm::EnablePrettyStackTrace() {
 #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() {
   EnablePrettyStackTrace();
 }




More information about the llvm-commits mailing list