PrettyStackTrace.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. #ifndef LLVM_SUPPORT_PRETTYSTACKTRACE_H
  16. #define LLVM_SUPPORT_PRETTYSTACKTRACE_H
  17. #include "llvm/Support/Compiler.h"
  18. namespace llvm {
  19. class raw_ostream;
  20. void EnablePrettyStackTrace();
  21. /// PrettyStackTraceEntry - This class is used to represent a frame of the
  22. /// "pretty" stack trace that is dumped when a program crashes. You can define
  23. /// subclasses of this and declare them on the program stack: when they are
  24. /// constructed and destructed, they will add their symbolic frames to a
  25. /// virtual stack trace. This gets dumped out if the program crashes.
  26. class PrettyStackTraceEntry {
  27. const PrettyStackTraceEntry *NextEntry;
  28. PrettyStackTraceEntry(const PrettyStackTraceEntry &) = delete;
  29. void operator=(const PrettyStackTraceEntry&) = delete;
  30. public:
  31. PrettyStackTraceEntry();
  32. virtual ~PrettyStackTraceEntry();
  33. /// print - Emit information about this stack frame to OS.
  34. virtual void print(raw_ostream &OS) const = 0;
  35. /// getNextEntry - Return the next entry in the list of frames.
  36. const PrettyStackTraceEntry *getNextEntry() const { return NextEntry; }
  37. };
  38. /// PrettyStackTraceString - This object prints a specified string (which
  39. /// should not contain newlines) to the stream as the stack trace when a crash
  40. /// occurs.
  41. class PrettyStackTraceString : public PrettyStackTraceEntry {
  42. const char *Str;
  43. public:
  44. PrettyStackTraceString(const char *str) : Str(str) {}
  45. void print(raw_ostream &OS) const override;
  46. };
  47. /// PrettyStackTraceProgram - This object prints a specified program arguments
  48. /// to the stream as the stack trace when a crash occurs.
  49. class PrettyStackTraceProgram : public PrettyStackTraceEntry {
  50. int ArgC;
  51. const char *const *ArgV;
  52. public:
  53. PrettyStackTraceProgram(int argc, const char * const*argv)
  54. : ArgC(argc), ArgV(argv) {
  55. EnablePrettyStackTrace();
  56. }
  57. void print(raw_ostream &OS) const override;
  58. };
  59. } // end namespace llvm
  60. #endif