diff options
| author | Stephen Hines <srhines@google.com> | 2019-07-02 16:25:20 -0700 |
|---|---|---|
| committer | Ali B <abittin@gmail.com> | 2019-07-05 19:33:16 +0300 |
| commit | 9afee4e65dc5f9f5eb371683729ff67b8df81d03 (patch) | |
| tree | 4cf241d6c9044f91ee8c06e6920174d06f8de0b6 /clang-r353983e/include/llvm/Support/PrettyStackTrace.h | |
| parent | 2f19bd722c4c825320d1511c1ed83161b7f95d51 (diff) | |
clang 9.0.5 (based on r353983e) from build 5696680.
Bug: http://b/135931688
Bug: http://b/136008926
Test: N/A
Change-Id: I922d17410047d2e2df4625615352c588ee71b203
Diffstat (limited to 'clang-r353983e/include/llvm/Support/PrettyStackTrace.h')
| -rw-r--r-- | clang-r353983e/include/llvm/Support/PrettyStackTrace.h | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/clang-r353983e/include/llvm/Support/PrettyStackTrace.h b/clang-r353983e/include/llvm/Support/PrettyStackTrace.h new file mode 100644 index 00000000..f6ed7c94 --- /dev/null +++ b/clang-r353983e/include/llvm/Support/PrettyStackTrace.h @@ -0,0 +1,95 @@ +//===- llvm/Support/PrettyStackTrace.h - Pretty Crash Handling --*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file defines the PrettyStackTraceEntry class, which is used to make +// crashes give more contextual information about what the program was doing +// when it crashed. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_SUPPORT_PRETTYSTACKTRACE_H +#define LLVM_SUPPORT_PRETTYSTACKTRACE_H + +#include "llvm/ADT/SmallVector.h" +#include "llvm/Support/Compiler.h" + +namespace llvm { + class raw_ostream; + + void EnablePrettyStackTrace(); + + /// PrettyStackTraceEntry - This class is used to represent a frame of the + /// "pretty" stack trace that is dumped when a program crashes. You can define + /// subclasses of this and declare them on the program stack: when they are + /// constructed and destructed, they will add their symbolic frames to a + /// virtual stack trace. This gets dumped out if the program crashes. + class PrettyStackTraceEntry { + friend PrettyStackTraceEntry *ReverseStackTrace(PrettyStackTraceEntry *); + + PrettyStackTraceEntry *NextEntry; + PrettyStackTraceEntry(const PrettyStackTraceEntry &) = delete; + void operator=(const PrettyStackTraceEntry &) = delete; + public: + PrettyStackTraceEntry(); + virtual ~PrettyStackTraceEntry(); + + /// print - Emit information about this stack frame to OS. + virtual void print(raw_ostream &OS) const = 0; + + /// getNextEntry - Return the next entry in the list of frames. + const PrettyStackTraceEntry *getNextEntry() const { return NextEntry; } + }; + + /// PrettyStackTraceString - This object prints a specified string (which + /// should not contain newlines) to the stream as the stack trace when a crash + /// occurs. + class PrettyStackTraceString : public PrettyStackTraceEntry { + const char *Str; + public: + PrettyStackTraceString(const char *str) : Str(str) {} + void print(raw_ostream &OS) const override; + }; + + /// PrettyStackTraceFormat - This object prints a string (which may use + /// printf-style formatting but should not contain newlines) to the stream + /// as the stack trace when a crash occurs. + class PrettyStackTraceFormat : public PrettyStackTraceEntry { + llvm::SmallVector<char, 32> Str; + public: + PrettyStackTraceFormat(const char *Format, ...); + void print(raw_ostream &OS) const override; + }; + + /// PrettyStackTraceProgram - This object prints a specified program arguments + /// to the stream as the stack trace when a crash occurs. + class PrettyStackTraceProgram : public PrettyStackTraceEntry { + int ArgC; + const char *const *ArgV; + public: + PrettyStackTraceProgram(int argc, const char * const*argv) + : ArgC(argc), ArgV(argv) { + EnablePrettyStackTrace(); + } + void print(raw_ostream &OS) const override; + }; + + /// Returns the topmost element of the "pretty" stack state. + const void *SavePrettyStackState(); + + /// Restores the topmost element of the "pretty" stack state to State, which + /// should come from a previous call to SavePrettyStackState(). This is + /// useful when using a CrashRecoveryContext in code that also uses + /// PrettyStackTraceEntries, to make sure the stack that's printed if a crash + /// happens after a crash that's been recovered by CrashRecoveryContext + /// doesn't have frames on it that were added in code unwound by the + /// CrashRecoveryContext. + void RestorePrettyStackState(const void *State); + +} // end namespace llvm + +#endif |
