1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 18:54:02 +01:00

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.

llvm-svn: 193971
This commit is contained in:
Filip Pizlo 2013-11-04 02:22:25 +00:00
parent 4b13ee5f62
commit 0080a77e7a
3 changed files with 21 additions and 28 deletions

View File

@ -434,13 +434,11 @@ void LLVMInstallFatalErrorHandler(LLVMFatalErrorHandler Handler);
void LLVMResetFatalErrorHandler(void);
/**
* Disable LLVM's built-in stack trace code. This must be called before any
* other LLVM APIs; otherwise the results are undefined.
*
* FIXME: This API should be replaced by a LLVMEnablePrettyStackTrace()
* function; the default should be that pretty stack traces are disabled.
* Enable LLVM's built-in stack trace code. This intercepts the OS's crash
* signals and prints which component of LLVM you were in at the time if the
* crash.
*/
void LLVMDisablePrettyStackTrace(void);
void LLVMEnablePrettyStackTrace(void);
/**
* @defgroup LLVMCCoreContext Contexts

View File

@ -21,11 +21,7 @@
namespace llvm {
class raw_ostream;
/// DisablePrettyStackTrace - Set this to true to disable this module. This
/// might be necessary if the host application installs its own signal
/// handlers which conflict with the ones installed by this module.
/// Defaults to false.
extern bool DisablePrettyStackTrace;
void EnablePrettyStackTrace();
/// PrettyStackTraceEntry - This class is used to represent a frame of the
/// "pretty" stack trace that is dumped when a program crashes. You can define
@ -64,7 +60,9 @@ namespace llvm {
const char *const *ArgV;
public:
PrettyStackTraceProgram(int argc, const char * const*argv)
: ArgC(argc), ArgV(argv) {}
: ArgC(argc), ArgV(argv) {
EnablePrettyStackTrace();
}
virtual void print(raw_ostream &OS) const LLVM_OVERRIDE;
};

View File

@ -28,10 +28,6 @@
using namespace llvm;
namespace llvm {
bool DisablePrettyStackTrace = false;
}
static ManagedStatic<sys::ThreadLocal<const PrettyStackTraceEntry> > PrettyStackTraceHead;
static unsigned PrintStack(const PrettyStackTraceEntry *Entry, raw_ostream &OS){
@ -103,17 +99,7 @@ static void CrashHandler(void *) {
#endif
}
static bool RegisterCrashPrinter() {
if (!DisablePrettyStackTrace)
sys::AddSignalHandler(CrashHandler, 0);
return false;
}
PrettyStackTraceEntry::PrettyStackTraceEntry() {
// The first time this is called, we register the crash printer.
static bool HandlerRegistered = RegisterCrashPrinter();
(void)HandlerRegistered;
// Link ourselves.
NextEntry = PrettyStackTraceHead->get();
PrettyStackTraceHead->set(this);
@ -149,6 +135,17 @@ void PrettyStackTraceProgram::print(raw_ostream &OS) const {
OS << '\n';
}
void LLVMDisablePrettyStackTrace() {
DisablePrettyStackTrace = true;
static bool RegisterCrashPrinter() {
sys::AddSignalHandler(CrashHandler, 0);
return false;
}
void llvm::EnablePrettyStackTrace() {
// The first time this is called, we register the crash printer.
static bool HandlerRegistered = RegisterCrashPrinter();
(void)HandlerRegistered;
}
void LLVMEnablePrettyStackTrace() {
EnablePrettyStackTrace();
}