diff options
author | Sean Callanan <scallanan@apple.com> | 2016-12-14 19:09:43 +0000 |
---|---|---|
committer | Sean Callanan <scallanan@apple.com> | 2016-12-14 19:09:43 +0000 |
commit | 032dbf9ee3646743de95a98195149d377065573f (patch) | |
tree | 3ef7b757b9a60a0d5ce1953b4df1749bef58f5db /llvm/lib/Support/PrettyStackTrace.cpp | |
parent | 373e36a4104e4b94ac101ce821291b840500aabc (diff) | |
download | bcm5719-llvm-032dbf9ee3646743de95a98195149d377065573f.tar.gz bcm5719-llvm-032dbf9ee3646743de95a98195149d377065573f.zip |
Prepare PrettyStackTrace for LLDB adoption
This patch fixes the linkage for __crashtracer_info__, making it have the proper mangling (extern "C") and linkage (private extern).
It also adds a new PrettyStackTrace type, allowing LLDB to adopt this instead of Host::SetCrashDescriptionWithFormat().
Without this patch, CrashTracer on macOS won't pick up pretty stack traces from any LLVM client.
An LLDB commit adopting this API will follow shortly.
Differential Revision: https://reviews.llvm.org/D27683
llvm-svn: 289689
Diffstat (limited to 'llvm/lib/Support/PrettyStackTrace.cpp')
-rw-r--r-- | llvm/lib/Support/PrettyStackTrace.cpp | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/llvm/lib/Support/PrettyStackTrace.cpp b/llvm/lib/Support/PrettyStackTrace.cpp index f49eb0a99a7..e14dbc1b56c 100644 --- a/llvm/lib/Support/PrettyStackTrace.cpp +++ b/llvm/lib/Support/PrettyStackTrace.cpp @@ -88,12 +88,12 @@ struct crashreporter_annotations_t gCRAnnotations __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 @@ PrettyStackTraceEntry::~PrettyStackTraceEntry() { #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. |