[PATCH] D27683: Prepare PrettyStackTrace for LLDB adoption

2021-05-17 Thread Greg Clayton via Phabricator via cfe-commits
clayborg added inline comments.



Comment at: llvm/trunk/lib/Support/PrettyStackTrace.cpp:92-93
+#elif defined(__APPLE__) && HAVE_CRASHREPORTER_INFO
+extern "C" const char *__crashreporter_info__
+__attribute__((visibility("hidden"))) = 0;
 asm(".desc ___crashreporter_info__, 0x10");

lol, if we still need the ___crashreporter_info__ symbol to be around, then it 
should be visible so that ReportCrash can find it... 


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D27683/new/

https://reviews.llvm.org/D27683

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D27683: Prepare PrettyStackTrace for LLDB adoption

2021-05-17 Thread Nico Weber via Phabricator via cfe-commits
thakis added inline comments.
Herald added subscribers: llvm-commits, kristina.
Herald added a project: LLVM.



Comment at: llvm/trunk/lib/Support/PrettyStackTrace.cpp:93
+extern "C" const char *__crashreporter_info__
+__attribute__((visibility("hidden"))) = 0;
 asm(".desc ___crashreporter_info__, 0x10");

As far as I can tell, making this a hidden symbol makes the `.desc 
___crashreporter_info__, 0x10` (ie REFERENCED_DYNAMICALLY) not have any effect:

```
% cat crashref.cc
extern "C" const char *__crashreporter_info__  
__attribute__((visibility("hidden"))) = 0;
asm(".desc ___crashreporter_info__, 0x10");
int main() {}
% clang crashref.cc
% nm -m a.out
00014000 (__DATA,__common) non-external (was a private external) 
___crashreporter_info__
0001 (__TEXT,__text) [referenced dynamically] external 
__mh_execute_header
00013fb0 (__TEXT,__text) external _main
 (undefined) external dyld_stub_binder (from libSystem)
% strip -r a.out
% nm -m a.out
0001 (__TEXT,__text) [referenced dynamically] external 
__mh_execute_header
```

It does have an effect without it:
```
% cat crashref.cc
extern "C" const char *__crashreporter_info__ = 0;
asm(".desc ___crashreporter_info__, 0x10");
int main() {}
% clang crashref.cc
% nm -m a.out
00014000 (__DATA,__common) [referenced dynamically] external 
___crashreporter_info__
0001 (__TEXT,__text) [referenced dynamically] external 
__mh_execute_header
00013fb0 (__TEXT,__text) external _main
 (undefined) external dyld_stub_binder (from libSystem)
% strip -r a.out
% nm -m a.out
00014000 (__DATA,__common) [referenced dynamically] external 
___crashreporter_info__
0001 (__TEXT,__text) [referenced dynamically] external 
__mh_execute_header
```

Is that intentional? Should we just remove the `.desc` line?


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D27683/new/

https://reviews.llvm.org/D27683

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D27683: Prepare PrettyStackTrace for LLDB adoption

2016-12-19 Thread David Blaikie via cfe-commits
On Mon, Dec 19, 2016 at 9:39 AM Sean Callanan  wrote:

> That would require making LLDB crash and collecting the relevant crash log
> data out of the user's own logs.  This isn't impossible – but additionally
> the generation of that log is asynchronous and you don't quite know when
> it'll land.
> Would you be all right with a more restricted macOS-only unit test where
> we check that __crashreporter_info__ contains what we think it does?  That
> won't check end-to-end but at least it'll give us some confidence that
> things are sane.
>

I was thinking something like a unit test of PrettyStackTraceFormat - that
wouldn't need to be OS specific, would it?


>
> Sean
>
> On Dec 19, 2016, at 9:01 AM, David Blaikie  wrote:
>
> Test coverage?
>
> On Tue, Dec 13, 2016 at 2:39 PM Sean Callanan via Phabricator via
> cfe-commits  wrote:
>
> spyffe retitled this revision from "Fix the linkage for
> __crashtracer_info__" to "Prepare PrettyStackTrace for LLDB adoption".
> spyffe updated the summary for this revision.
> spyffe updated this revision to Diff 81304.
>
> Repository:
>   rL LLVM
>
> https://reviews.llvm.org/D27683
>
> Files:
>   include/llvm/Support/PrettyStackTrace.h
>   lib/Support/PrettyStackTrace.cpp
>
>
> Index: lib/Support/PrettyStackTrace.cpp
> ===
> --- lib/Support/PrettyStackTrace.cpp
> +++ lib/Support/PrettyStackTrace.cpp
> @@ -89,7 +89,7 @@
>  = { CRASHREPORTER_ANNOTATIONS_VERSION, 0, 0, 0, 0, 0, 0 };
>  }
>  #elif defined (__APPLE__) && HAVE_CRASHREPORTER_INFO
> -static const char *__crashreporter_info__ = 0;
> +extern "C" const char *__crashreporter_info__
> __attribute__((visibility("hidden"))) = 0;
>  asm(".desc ___crashreporter_info__, 0x10");
>  #endif
>
> @@ -145,6 +145,28 @@
>OS << Str << "\n";
>  }
>
> +PrettyStackTraceFormat::PrettyStackTraceFormat(const char *format, ...) {
> +  va_list ap;
> +
> +  va_start(ap, format);
> +  const int size_or_error = vsnprintf(nullptr, 0, format, ap);
> +  va_end(ap);
> +
> +  if (size_or_error < 0) {
> +return;
> +  }
> +
> +  const int size = size_or_error + 1; // '\0'
> +
> +  Str.resize(size);
> +
> +  va_start(ap, format);
> +  vsnprintf(Str.data(), size, format, ap);
> +  va_end(ap);
> +}
> +
> +void PrettyStackTraceFormat::print(raw_ostream ) const { OS << Str <<
> "\n"; }
> +
>  void PrettyStackTraceProgram::print(raw_ostream ) const {
>OS << "Program arguments: ";
>// Print the argument list.
> Index: include/llvm/Support/PrettyStackTrace.h
> ===
> --- include/llvm/Support/PrettyStackTrace.h
> +++ 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 ) 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 Str;
> +  public:
> +PrettyStackTraceFormat(const char *format, ...);
> +void print(raw_ostream ) 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 {
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D27683: Prepare PrettyStackTrace for LLDB adoption

2016-12-19 Thread Sean Callanan via cfe-commits
That would require making LLDB crash and collecting the relevant crash log data 
out of the user's own logs.  This isn't impossible – but additionally the 
generation of that log is asynchronous and you don't quite know when it'll land.
Would you be all right with a more restricted macOS-only unit test where we 
check that __crashreporter_info__ contains what we think it does?  That won't 
check end-to-end but at least it'll give us some confidence that things are 
sane.

Sean

> On Dec 19, 2016, at 9:01 AM, David Blaikie  wrote:
> 
> Test coverage?
> 
> On Tue, Dec 13, 2016 at 2:39 PM Sean Callanan via Phabricator via cfe-commits 
> > wrote:
> spyffe retitled this revision from "Fix the linkage for __crashtracer_info__" 
> to "Prepare PrettyStackTrace for LLDB adoption".
> spyffe updated the summary for this revision.
> spyffe updated this revision to Diff 81304.
> 
> Repository:
>   rL LLVM
> 
> https://reviews.llvm.org/D27683 
> 
> Files:
>   include/llvm/Support/PrettyStackTrace.h
>   lib/Support/PrettyStackTrace.cpp
> 
> 
> Index: lib/Support/PrettyStackTrace.cpp
> ===
> --- lib/Support/PrettyStackTrace.cpp
> +++ lib/Support/PrettyStackTrace.cpp
> @@ -89,7 +89,7 @@
>  = { CRASHREPORTER_ANNOTATIONS_VERSION, 0, 0, 0, 0, 0, 0 };
>  }
>  #elif defined (__APPLE__) && HAVE_CRASHREPORTER_INFO
> -static const char *__crashreporter_info__ = 0;
> +extern "C" const char *__crashreporter_info__ 
> __attribute__((visibility("hidden"))) = 0;
>  asm(".desc ___crashreporter_info__, 0x10");
>  #endif
> 
> @@ -145,6 +145,28 @@
>OS << Str << "\n";
>  }
> 
> +PrettyStackTraceFormat::PrettyStackTraceFormat(const char *format, ...) {
> +  va_list ap;
> +
> +  va_start(ap, format);
> +  const int size_or_error = vsnprintf(nullptr, 0, format, ap);
> +  va_end(ap);
> +
> +  if (size_or_error < 0) {
> +return;
> +  }
> +
> +  const int size = size_or_error + 1; // '\0'
> +
> +  Str.resize(size);
> +
> +  va_start(ap, format);
> +  vsnprintf(Str.data(), size, format, ap);
> +  va_end(ap);
> +}
> +
> +void PrettyStackTraceFormat::print(raw_ostream ) const { OS << Str << 
> "\n"; }
> +
>  void PrettyStackTraceProgram::print(raw_ostream ) const {
>OS << "Program arguments: ";
>// Print the argument list.
> Index: include/llvm/Support/PrettyStackTrace.h
> ===
> --- include/llvm/Support/PrettyStackTrace.h
> +++ 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 ) 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 Str;
> +  public:
> +PrettyStackTraceFormat(const char *format, ...);
> +void print(raw_ostream ) 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 {
> 
> 
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org 
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits 
> 

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D27683: Prepare PrettyStackTrace for LLDB adoption

2016-12-19 Thread David Blaikie via cfe-commits
Test coverage?

On Tue, Dec 13, 2016 at 2:39 PM Sean Callanan via Phabricator via
cfe-commits  wrote:

> spyffe retitled this revision from "Fix the linkage for
> __crashtracer_info__" to "Prepare PrettyStackTrace for LLDB adoption".
> spyffe updated the summary for this revision.
> spyffe updated this revision to Diff 81304.
>
> Repository:
>   rL LLVM
>
> https://reviews.llvm.org/D27683
>
> Files:
>   include/llvm/Support/PrettyStackTrace.h
>   lib/Support/PrettyStackTrace.cpp
>
>
> Index: lib/Support/PrettyStackTrace.cpp
> ===
> --- lib/Support/PrettyStackTrace.cpp
> +++ lib/Support/PrettyStackTrace.cpp
> @@ -89,7 +89,7 @@
>  = { CRASHREPORTER_ANNOTATIONS_VERSION, 0, 0, 0, 0, 0, 0 };
>  }
>  #elif defined (__APPLE__) && HAVE_CRASHREPORTER_INFO
> -static const char *__crashreporter_info__ = 0;
> +extern "C" const char *__crashreporter_info__
> __attribute__((visibility("hidden"))) = 0;
>  asm(".desc ___crashreporter_info__, 0x10");
>  #endif
>
> @@ -145,6 +145,28 @@
>OS << Str << "\n";
>  }
>
> +PrettyStackTraceFormat::PrettyStackTraceFormat(const char *format, ...) {
> +  va_list ap;
> +
> +  va_start(ap, format);
> +  const int size_or_error = vsnprintf(nullptr, 0, format, ap);
> +  va_end(ap);
> +
> +  if (size_or_error < 0) {
> +return;
> +  }
> +
> +  const int size = size_or_error + 1; // '\0'
> +
> +  Str.resize(size);
> +
> +  va_start(ap, format);
> +  vsnprintf(Str.data(), size, format, ap);
> +  va_end(ap);
> +}
> +
> +void PrettyStackTraceFormat::print(raw_ostream ) const { OS << Str <<
> "\n"; }
> +
>  void PrettyStackTraceProgram::print(raw_ostream ) const {
>OS << "Program arguments: ";
>// Print the argument list.
> Index: include/llvm/Support/PrettyStackTrace.h
> ===
> --- include/llvm/Support/PrettyStackTrace.h
> +++ 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 ) 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 Str;
> +  public:
> +PrettyStackTraceFormat(const char *format, ...);
> +void print(raw_ostream ) 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 {
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D27683: Prepare PrettyStackTrace for LLDB adoption

2016-12-14 Thread Sean Callanan via Phabricator via cfe-commits
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=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 ) 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 Str;
+  public:
+PrettyStackTraceFormat(const char *Format, ...);
+void print(raw_ostream ) 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 ) const {
-  OS << Str << "\n";
+void PrettyStackTraceString::print(raw_ostream ) 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 ) const { OS << Str << "\n"; 
}
+
 void PrettyStackTraceProgram::print(raw_ostream ) const {
   OS << "Program arguments: ";
   // Print the argument list.


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 ) 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 Str;
+  public:
+PrettyStackTraceFormat(const char *Format, ...);
+void print(raw_ostream ) 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 

[PATCH] D27683: Prepare PrettyStackTrace for LLDB adoption

2016-12-13 Thread Chris Bieneman via Phabricator via cfe-commits
beanz accepted this revision.
beanz added a comment.

LGTM other than a few style comments. Please clang-format before committing. 
Some of the formatting looks off (although that might just be my phone).




Comment at: lib/Support/PrettyStackTrace.cpp:152
+  va_start(ap, format);
+  const int size_or_error = vsnprintf(nullptr, 0, format, ap);
+  va_end(ap);

Your variable names are very LLDB-esque. Please follow the LLVM style guide, 
which is CamelCase.


Repository:
  rL LLVM

https://reviews.llvm.org/D27683



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D27683: Prepare PrettyStackTrace for LLDB adoption

2016-12-13 Thread Sean Callanan via Phabricator via cfe-commits
spyffe added a comment.

The LLDB side of this is https://reviews.llvm.org/D27735


Repository:
  rL LLVM

https://reviews.llvm.org/D27683



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D27683: Prepare PrettyStackTrace for LLDB adoption

2016-12-13 Thread Sean Callanan via Phabricator via cfe-commits
spyffe retitled this revision from "Fix the linkage for __crashtracer_info__" 
to "Prepare PrettyStackTrace for LLDB adoption".
spyffe updated the summary for this revision.
spyffe updated this revision to Diff 81304.

Repository:
  rL LLVM

https://reviews.llvm.org/D27683

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


Index: lib/Support/PrettyStackTrace.cpp
===
--- lib/Support/PrettyStackTrace.cpp
+++ lib/Support/PrettyStackTrace.cpp
@@ -89,7 +89,7 @@
 = { CRASHREPORTER_ANNOTATIONS_VERSION, 0, 0, 0, 0, 0, 0 };
 }
 #elif defined (__APPLE__) && HAVE_CRASHREPORTER_INFO
-static const char *__crashreporter_info__ = 0;
+extern "C" const char *__crashreporter_info__ 
__attribute__((visibility("hidden"))) = 0;
 asm(".desc ___crashreporter_info__, 0x10");
 #endif
 
@@ -145,6 +145,28 @@
   OS << Str << "\n";
 }
 
+PrettyStackTraceFormat::PrettyStackTraceFormat(const char *format, ...) {
+  va_list ap;
+
+  va_start(ap, format);
+  const int size_or_error = vsnprintf(nullptr, 0, format, ap);
+  va_end(ap);
+
+  if (size_or_error < 0) {
+return;
+  }
+
+  const int size = size_or_error + 1; // '\0'
+
+  Str.resize(size);
+
+  va_start(ap, format);
+  vsnprintf(Str.data(), size, format, ap);
+  va_end(ap);
+}
+
+void PrettyStackTraceFormat::print(raw_ostream ) const { OS << Str << "\n"; 
}
+
 void PrettyStackTraceProgram::print(raw_ostream ) const {
   OS << "Program arguments: ";
   // Print the argument list.
Index: include/llvm/Support/PrettyStackTrace.h
===
--- include/llvm/Support/PrettyStackTrace.h
+++ 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 ) 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 Str;
+  public:
+PrettyStackTraceFormat(const char *format, ...);
+void print(raw_ostream ) 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: lib/Support/PrettyStackTrace.cpp
===
--- lib/Support/PrettyStackTrace.cpp
+++ lib/Support/PrettyStackTrace.cpp
@@ -89,7 +89,7 @@
 = { CRASHREPORTER_ANNOTATIONS_VERSION, 0, 0, 0, 0, 0, 0 };
 }
 #elif defined (__APPLE__) && HAVE_CRASHREPORTER_INFO
-static const char *__crashreporter_info__ = 0;
+extern "C" const char *__crashreporter_info__ __attribute__((visibility("hidden"))) = 0;
 asm(".desc ___crashreporter_info__, 0x10");
 #endif
 
@@ -145,6 +145,28 @@
   OS << Str << "\n";
 }
 
+PrettyStackTraceFormat::PrettyStackTraceFormat(const char *format, ...) {
+  va_list ap;
+
+  va_start(ap, format);
+  const int size_or_error = vsnprintf(nullptr, 0, format, ap);
+  va_end(ap);
+
+  if (size_or_error < 0) {
+return;
+  }
+
+  const int size = size_or_error + 1; // '\0'
+
+  Str.resize(size);
+
+  va_start(ap, format);
+  vsnprintf(Str.data(), size, format, ap);
+  va_end(ap);
+}
+
+void PrettyStackTraceFormat::print(raw_ostream ) const { OS << Str << "\n"; }
+
 void PrettyStackTraceProgram::print(raw_ostream ) const {
   OS << "Program arguments: ";
   // Print the argument list.
Index: include/llvm/Support/PrettyStackTrace.h
===
--- include/llvm/Support/PrettyStackTrace.h
+++ 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 ) 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 Str;
+  public:
+PrettyStackTraceFormat(const char *format, ...);
+void print(raw_ostream ) 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 {
___
cfe-commits mailing list