llvm.org GIT mirror llvm / fa0da86
Make the pretty stack trace be an opt-in, rather than opt-out, facility. Enable pretty stack traces by default if you use PrettyStackTraceProgram, so that existing LLVM-based tools will continue to get it without any changes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@193971 91177308-0d34-0410-b5e6-96231b3b80d8 Filip Pizlo 6 years ago
3 changed file(s) with 22 addition(s) and 29 deletion(s). Raw diff Collapse all Expand all
2020 namespace llvm {
2121 class raw_ostream;
2222
23 /// DisablePrettyStackTrace - Set this to true to disable this module. This
24 /// might be necessary if the host application installs its own signal
25 /// handlers which conflict with the ones installed by this module.
26 /// Defaults to false.
27 extern bool DisablePrettyStackTrace;
23 void EnablePrettyStackTrace();
2824
2925 /// PrettyStackTraceEntry - This class is used to represent a frame of the
3026 /// "pretty" stack trace that is dumped when a program crashes. You can define
6359 const char *const *ArgV;
6460 public:
6561 PrettyStackTraceProgram(int argc, const char * const*argv)
66 : ArgC(argc), ArgV(argv) {}
62 : ArgC(argc), ArgV(argv) {
63 EnablePrettyStackTrace();
64 }
6765 virtual void print(raw_ostream &OS) const LLVM_OVERRIDE;
6866 };
6967
433433 void LLVMResetFatalErrorHandler(void);
434434
435435 /**
436 * Disable LLVM's built-in stack trace code. This must be called before any
437 * other LLVM APIs; otherwise the results are undefined.
438 *
439 * FIXME: This API should be replaced by a LLVMEnablePrettyStackTrace()
440 * function; the default should be that pretty stack traces are disabled.
441 */
442 void LLVMDisablePrettyStackTrace(void);
436 * Enable LLVM's built-in stack trace code. This intercepts the OS's crash
437 * signals and prints which component of LLVM you were in at the time if the
438 * crash.
439 */
440 void LLVMEnablePrettyStackTrace(void);
443441
444442 /**
445443 * @defgroup LLVMCCoreContext Contexts
2626 #endif
2727
2828 using namespace llvm;
29
30 namespace llvm {
31 bool DisablePrettyStackTrace = false;
32 }
3329
3430 static ManagedStatic > PrettyStackTraceHead;
3531
10298 #endif
10399 }
104100
105 static bool RegisterCrashPrinter() {
106 if (!DisablePrettyStackTrace)
107 sys::AddSignalHandler(CrashHandler, 0);
108 return false;
109 }
110
111101 PrettyStackTraceEntry::PrettyStackTraceEntry() {
112 // The first time this is called, we register the crash printer.
113 static bool HandlerRegistered = RegisterCrashPrinter();
114 (void)HandlerRegistered;
115
116102 // Link ourselves.
117103 NextEntry = PrettyStackTraceHead->get();
118104 PrettyStackTraceHead->set(this);
148134 OS << '\n';
149135 }
150136
151 void LLVMDisablePrettyStackTrace() {
152 DisablePrettyStackTrace = true;
137 static bool RegisterCrashPrinter() {
138 sys::AddSignalHandler(CrashHandler, 0);
139 return false;
153140 }
141
142 void llvm::EnablePrettyStackTrace() {
143 // The first time this is called, we register the crash printer.
144 static bool HandlerRegistered = RegisterCrashPrinter();
145 (void)HandlerRegistered;
146 }
147
148 void LLVMEnablePrettyStackTrace() {
149 EnablePrettyStackTrace();
150 }