LLVM API Documentation
00001 //===- llvm/Support/PrettyStackTrace.h - Pretty Crash Handling --*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file defines the PrettyStackTraceEntry class, which is used to make 00011 // crashes give more contextual information about what the program was doing 00012 // when it crashed. 00013 // 00014 //===----------------------------------------------------------------------===// 00015 00016 #ifndef LLVM_SUPPORT_PRETTYSTACKTRACE_H 00017 #define LLVM_SUPPORT_PRETTYSTACKTRACE_H 00018 00019 namespace llvm { 00020 class raw_ostream; 00021 00022 /// DisablePrettyStackTrace - Set this to true to disable this module. This 00023 /// might be neccessary if the host application installs its own signal 00024 /// handlers which conflict with the ones installed by this module. 00025 /// Defaults to false. 00026 extern bool DisablePrettyStackTrace; 00027 00028 /// PrettyStackTraceEntry - This class is used to represent a frame of the 00029 /// "pretty" stack trace that is dumped when a program crashes. You can define 00030 /// subclasses of this and declare them on the program stack: when they are 00031 /// constructed and destructed, they will add their symbolic frames to a 00032 /// virtual stack trace. This gets dumped out if the program crashes. 00033 class PrettyStackTraceEntry { 00034 const PrettyStackTraceEntry *NextEntry; 00035 PrettyStackTraceEntry(const PrettyStackTraceEntry &); // DO NOT IMPLEMENT 00036 void operator=(const PrettyStackTraceEntry&); // DO NOT IMPLEMENT 00037 public: 00038 PrettyStackTraceEntry(); 00039 virtual ~PrettyStackTraceEntry(); 00040 00041 /// print - Emit information about this stack frame to OS. 00042 virtual void print(raw_ostream &OS) const = 0; 00043 00044 /// getNextEntry - Return the next entry in the list of frames. 00045 const PrettyStackTraceEntry *getNextEntry() const { return NextEntry; } 00046 }; 00047 00048 /// PrettyStackTraceString - This object prints a specified string (which 00049 /// should not contain newlines) to the stream as the stack trace when a crash 00050 /// occurs. 00051 class PrettyStackTraceString : public PrettyStackTraceEntry { 00052 const char *Str; 00053 public: 00054 PrettyStackTraceString(const char *str) : Str(str) {} 00055 virtual void print(raw_ostream &OS) const; 00056 }; 00057 00058 /// PrettyStackTraceProgram - This object prints a specified program arguments 00059 /// to the stream as the stack trace when a crash occurs. 00060 class PrettyStackTraceProgram : public PrettyStackTraceEntry { 00061 int ArgC; 00062 const char *const *ArgV; 00063 public: 00064 PrettyStackTraceProgram(int argc, const char * const*argv) 00065 : ArgC(argc), ArgV(argv) {} 00066 virtual void print(raw_ostream &OS) const; 00067 }; 00068 00069 } // end namespace llvm 00070 00071 #endif