llvm.org GIT mirror llvm / 9ce84d2
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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@289689 91177308-0d34-0410-b5e6-96231b3b80d8 Sean Callanan 3 years ago
2 changed file(s) with 33 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
1515 #ifndef LLVM_SUPPORT_PRETTYSTACKTRACE_H
1616 #define LLVM_SUPPORT_PRETTYSTACKTRACE_H
1717
18 #include "llvm/ADT/SmallVector.h"
1819 #include "llvm/Support/Compiler.h"
1920
2021 namespace llvm {
5455 void print(raw_ostream &OS) const override;
5556 };
5657
58 /// PrettyStackTraceFormat - This object prints a string (which may use
59 /// printf-style formatting but should not contain newlines) to the stream
60 /// as the stack trace when a crash occurs.
61 class PrettyStackTraceFormat : public PrettyStackTraceEntry {
62 llvm::SmallVector Str;
63 public:
64 PrettyStackTraceFormat(const char *Format, ...);
65 void print(raw_ostream &OS) const override;
66 };
67
5768 /// PrettyStackTraceProgram - This object prints a specified program arguments
5869 /// to the stream as the stack trace when a crash occurs.
5970 class PrettyStackTraceProgram : public PrettyStackTraceEntry {
8787 __attribute__((section("__DATA," CRASHREPORTER_ANNOTATIONS_SECTION)))
8888 = { CRASHREPORTER_ANNOTATIONS_VERSION, 0, 0, 0, 0, 0, 0 };
8989 }
90 #elif defined (__APPLE__) && HAVE_CRASHREPORTER_INFO
91 static const char *__crashreporter_info__ = 0;
90 #elif defined(__APPLE__) && HAVE_CRASHREPORTER_INFO
91 extern "C" const char *__crashreporter_info__
92 __attribute__((visibility("hidden"))) = 0;
9293 asm(".desc ___crashreporter_info__, 0x10");
9394 #endif
94
9595
9696 /// CrashHandler - This callback is run if a fatal signal is delivered to the
9797 /// process, it prints the pretty stack trace.
140140 #endif
141141 }
142142
143 void PrettyStackTraceString::print(raw_ostream &OS) const {
144 OS << Str << "\n";
145 }
143 void PrettyStackTraceString::print(raw_ostream &OS) const { OS << Str << "\n"; }
144
145 PrettyStackTraceFormat::PrettyStackTraceFormat(const char *Format, ...) {
146 va_list AP;
147 va_start(AP, Format);
148 const int SizeOrError = vsnprintf(nullptr, 0, Format, AP);
149 va_end(AP);
150 if (SizeOrError < 0) {
151 return;
152 }
153
154 const int Size = SizeOrError + 1; // '\0'
155 Str.resize(Size);
156 va_start(AP, Format);
157 vsnprintf(Str.data(), Size, Format, AP);
158 va_end(AP);
159 }
160
161 void PrettyStackTraceFormat::print(raw_ostream &OS) const { OS << Str << "\n"; }
146162
147163 void PrettyStackTraceProgram::print(raw_ostream &OS) const {
148164 OS << "Program arguments: ";