LLVM API Documentation

PrettyStackTrace.h
Go to the documentation of this file.
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 #include "llvm/Support/Compiler.h"
00020 
00021 namespace llvm {
00022   class raw_ostream;
00023 
00024   void EnablePrettyStackTrace();
00025 
00026   /// PrettyStackTraceEntry - This class is used to represent a frame of the
00027   /// "pretty" stack trace that is dumped when a program crashes. You can define
00028   /// subclasses of this and declare them on the program stack: when they are
00029   /// constructed and destructed, they will add their symbolic frames to a
00030   /// virtual stack trace.  This gets dumped out if the program crashes.
00031   class PrettyStackTraceEntry {
00032     const PrettyStackTraceEntry *NextEntry;
00033     PrettyStackTraceEntry(const PrettyStackTraceEntry &) LLVM_DELETED_FUNCTION;
00034     void operator=(const PrettyStackTraceEntry&) LLVM_DELETED_FUNCTION;
00035   public:
00036     PrettyStackTraceEntry();
00037     virtual ~PrettyStackTraceEntry();
00038 
00039     /// print - Emit information about this stack frame to OS.
00040     virtual void print(raw_ostream &OS) const = 0;
00041 
00042     /// getNextEntry - Return the next entry in the list of frames.
00043     const PrettyStackTraceEntry *getNextEntry() const { return NextEntry; }
00044   };
00045 
00046   /// PrettyStackTraceString - This object prints a specified string (which
00047   /// should not contain newlines) to the stream as the stack trace when a crash
00048   /// occurs.
00049   class PrettyStackTraceString : public PrettyStackTraceEntry {
00050     const char *Str;
00051   public:
00052     PrettyStackTraceString(const char *str) : Str(str) {}
00053     void print(raw_ostream &OS) const override;
00054   };
00055 
00056   /// PrettyStackTraceProgram - This object prints a specified program arguments
00057   /// to the stream as the stack trace when a crash occurs.
00058   class PrettyStackTraceProgram : public PrettyStackTraceEntry {
00059     int ArgC;
00060     const char *const *ArgV;
00061   public:
00062     PrettyStackTraceProgram(int argc, const char * const*argv)
00063       : ArgC(argc), ArgV(argv) {
00064       EnablePrettyStackTrace();
00065     }
00066     void print(raw_ostream &OS) const override;
00067   };
00068 
00069 } // end namespace llvm
00070 
00071 #endif