]> git.proxmox.com Git - rustc.git/blob - src/llvm/include/llvm/Support/PrettyStackTrace.h
Imported Upstream version 0.6
[rustc.git] / src / llvm / include / llvm / Support / PrettyStackTrace.h
1 //===- llvm/Support/PrettyStackTrace.h - Pretty Crash Handling --*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the PrettyStackTraceEntry class, which is used to make
11 // crashes give more contextual information about what the program was doing
12 // when it crashed.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #ifndef LLVM_SUPPORT_PRETTYSTACKTRACE_H
17 #define LLVM_SUPPORT_PRETTYSTACKTRACE_H
18
19 #include "llvm/Support/Compiler.h"
20
21 namespace llvm {
22 class raw_ostream;
23
24 /// DisablePrettyStackTrace - Set this to true to disable this module. This
25 /// might be necessary if the host application installs its own signal
26 /// handlers which conflict with the ones installed by this module.
27 /// Defaults to false.
28 extern bool DisablePrettyStackTrace;
29
30 /// PrettyStackTraceEntry - This class is used to represent a frame of the
31 /// "pretty" stack trace that is dumped when a program crashes. You can define
32 /// subclasses of this and declare them on the program stack: when they are
33 /// constructed and destructed, they will add their symbolic frames to a
34 /// virtual stack trace. This gets dumped out if the program crashes.
35 class PrettyStackTraceEntry {
36 const PrettyStackTraceEntry *NextEntry;
37 PrettyStackTraceEntry(const PrettyStackTraceEntry &) LLVM_DELETED_FUNCTION;
38 void operator=(const PrettyStackTraceEntry&) LLVM_DELETED_FUNCTION;
39 public:
40 PrettyStackTraceEntry();
41 virtual ~PrettyStackTraceEntry();
42
43 /// print - Emit information about this stack frame to OS.
44 virtual void print(raw_ostream &OS) const = 0;
45
46 /// getNextEntry - Return the next entry in the list of frames.
47 const PrettyStackTraceEntry *getNextEntry() const { return NextEntry; }
48 };
49
50 /// PrettyStackTraceString - This object prints a specified string (which
51 /// should not contain newlines) to the stream as the stack trace when a crash
52 /// occurs.
53 class PrettyStackTraceString : public PrettyStackTraceEntry {
54 const char *Str;
55 public:
56 PrettyStackTraceString(const char *str) : Str(str) {}
57 virtual void print(raw_ostream &OS) const LLVM_OVERRIDE;
58 };
59
60 /// PrettyStackTraceProgram - This object prints a specified program arguments
61 /// to the stream as the stack trace when a crash occurs.
62 class PrettyStackTraceProgram : public PrettyStackTraceEntry {
63 int ArgC;
64 const char *const *ArgV;
65 public:
66 PrettyStackTraceProgram(int argc, const char * const*argv)
67 : ArgC(argc), ArgV(argv) {}
68 virtual void print(raw_ostream &OS) const LLVM_OVERRIDE;
69 };
70
71 } // end namespace llvm
72
73 #endif