1193323Sed//===- llvm/Support/PrettyStackTrace.h - Pretty Crash Handling --*- C++ -*-===//
2193323Sed//
3193323Sed//                     The LLVM Compiler Infrastructure
4193323Sed//
5193323Sed// This file is distributed under the University of Illinois Open Source
6193323Sed// License. See LICENSE.TXT for details.
7193323Sed//
8193323Sed//===----------------------------------------------------------------------===//
9193323Sed//
10193323Sed// This file defines the PrettyStackTraceEntry class, which is used to make
11193323Sed// crashes give more contextual information about what the program was doing
12193323Sed// when it crashed.
13193323Sed//
14193323Sed//===----------------------------------------------------------------------===//
15193323Sed
16193323Sed#ifndef LLVM_SUPPORT_PRETTYSTACKTRACE_H
17193323Sed#define LLVM_SUPPORT_PRETTYSTACKTRACE_H
18193323Sed
19245431Sdim#include "llvm/Support/Compiler.h"
20245431Sdim
21193323Sednamespace llvm {
22193323Sed  class raw_ostream;
23198090Srdivacky
24263509Sdim  void EnablePrettyStackTrace();
25212904Sdim
26193323Sed  /// PrettyStackTraceEntry - This class is used to represent a frame of the
27193323Sed  /// "pretty" stack trace that is dumped when a program crashes. You can define
28212904Sdim  /// subclasses of this and declare them on the program stack: when they are
29193323Sed  /// constructed and destructed, they will add their symbolic frames to a
30193323Sed  /// virtual stack trace.  This gets dumped out if the program crashes.
31193323Sed  class PrettyStackTraceEntry {
32193323Sed    const PrettyStackTraceEntry *NextEntry;
33245431Sdim    PrettyStackTraceEntry(const PrettyStackTraceEntry &) LLVM_DELETED_FUNCTION;
34245431Sdim    void operator=(const PrettyStackTraceEntry&) LLVM_DELETED_FUNCTION;
35193323Sed  public:
36193323Sed    PrettyStackTraceEntry();
37193323Sed    virtual ~PrettyStackTraceEntry();
38212904Sdim
39193323Sed    /// print - Emit information about this stack frame to OS.
40193323Sed    virtual void print(raw_ostream &OS) const = 0;
41212904Sdim
42193323Sed    /// getNextEntry - Return the next entry in the list of frames.
43193323Sed    const PrettyStackTraceEntry *getNextEntry() const { return NextEntry; }
44193323Sed  };
45212904Sdim
46193323Sed  /// PrettyStackTraceString - This object prints a specified string (which
47193323Sed  /// should not contain newlines) to the stream as the stack trace when a crash
48193323Sed  /// occurs.
49193323Sed  class PrettyStackTraceString : public PrettyStackTraceEntry {
50193323Sed    const char *Str;
51193323Sed  public:
52193323Sed    PrettyStackTraceString(const char *str) : Str(str) {}
53245431Sdim    virtual void print(raw_ostream &OS) const LLVM_OVERRIDE;
54193323Sed  };
55212904Sdim
56193323Sed  /// PrettyStackTraceProgram - This object prints a specified program arguments
57193323Sed  /// to the stream as the stack trace when a crash occurs.
58193323Sed  class PrettyStackTraceProgram : public PrettyStackTraceEntry {
59193323Sed    int ArgC;
60193323Sed    const char *const *ArgV;
61193323Sed  public:
62193323Sed    PrettyStackTraceProgram(int argc, const char * const*argv)
63263509Sdim      : ArgC(argc), ArgV(argv) {
64263509Sdim      EnablePrettyStackTrace();
65263509Sdim    }
66245431Sdim    virtual void print(raw_ostream &OS) const LLVM_OVERRIDE;
67193323Sed  };
68212904Sdim
69193323Sed} // end namespace llvm
70193323Sed
71193323Sed#endif
72