[PATCH] D27683: Prepare PrettyStackTrace for LLDB adoption

Sean Callanan via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 14 11:20:08 PST 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL289689: Prepare PrettyStackTrace for LLDB adoption (authored by spyffe).

Changed prior to commit:
  https://reviews.llvm.org/D27683?vs=81304&id=81426#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D27683

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


Index: llvm/trunk/include/llvm/Support/PrettyStackTrace.h
===================================================================
--- llvm/trunk/include/llvm/Support/PrettyStackTrace.h
+++ llvm/trunk/include/llvm/Support/PrettyStackTrace.h
@@ -16,6 +16,7 @@
 #ifndef LLVM_SUPPORT_PRETTYSTACKTRACE_H
 #define LLVM_SUPPORT_PRETTYSTACKTRACE_H
 
+#include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/Compiler.h"
 
 namespace llvm {
@@ -55,6 +56,16 @@
     void print(raw_ostream &OS) const override;
   };
 
+  /// PrettyStackTraceFormat - This object prints a string (which may use
+  /// printf-style formatting but should not contain newlines) to the stream
+  /// as the stack trace when a crash occurs.
+  class PrettyStackTraceFormat : public PrettyStackTraceEntry {
+    llvm::SmallVector<char, 32> Str;
+  public:
+    PrettyStackTraceFormat(const char *Format, ...);
+    void print(raw_ostream &OS) const override;
+  };
+
   /// PrettyStackTraceProgram - This object prints a specified program arguments
   /// to the stream as the stack trace when a crash occurs.
   class PrettyStackTraceProgram : public PrettyStackTraceEntry {
Index: llvm/trunk/lib/Support/PrettyStackTrace.cpp
===================================================================
--- llvm/trunk/lib/Support/PrettyStackTrace.cpp
+++ llvm/trunk/lib/Support/PrettyStackTrace.cpp
@@ -88,12 +88,12 @@
         __attribute__((section("__DATA," CRASHREPORTER_ANNOTATIONS_SECTION))) 
         = { CRASHREPORTER_ANNOTATIONS_VERSION, 0, 0, 0, 0, 0, 0 };
 }
-#elif defined (__APPLE__) && HAVE_CRASHREPORTER_INFO
-static const char *__crashreporter_info__ = 0;
+#elif defined(__APPLE__) && HAVE_CRASHREPORTER_INFO
+extern "C" const char *__crashreporter_info__
+    __attribute__((visibility("hidden"))) = 0;
 asm(".desc ___crashreporter_info__, 0x10");
 #endif
 
-
 /// CrashHandler - This callback is run if a fatal signal is delivered to the
 /// process, it prints the pretty stack trace.
 static void CrashHandler(void *) {
@@ -141,10 +141,26 @@
 #endif
 }
 
-void PrettyStackTraceString::print(raw_ostream &OS) const {
-  OS << Str << "\n";
+void PrettyStackTraceString::print(raw_ostream &OS) const { OS << Str << "\n"; }
+
+PrettyStackTraceFormat::PrettyStackTraceFormat(const char *Format, ...) {
+  va_list AP;
+  va_start(AP, Format);
+  const int SizeOrError = vsnprintf(nullptr, 0, Format, AP);
+  va_end(AP);
+  if (SizeOrError < 0) {
+    return;
+  }
+
+  const int Size = SizeOrError + 1; // '\0'
+  Str.resize(Size);
+  va_start(AP, Format);
+  vsnprintf(Str.data(), Size, Format, AP);
+  va_end(AP);
 }
 
+void PrettyStackTraceFormat::print(raw_ostream &OS) const { OS << Str << "\n"; }
+
 void PrettyStackTraceProgram::print(raw_ostream &OS) const {
   OS << "Program arguments: ";
   // Print the argument list.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27683.81426.patch
Type: text/x-patch
Size: 2799 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161214/2571dd5f/attachment-0001.bin>


More information about the cfe-commits mailing list