| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | #pragma once | 
| 2 |  |  |  |  |  |  | #include | 
| 3 |  |  |  |  |  |  | #include | 
| 4 |  |  |  |  |  |  | #include "string.h" | 
| 5 |  |  |  |  |  |  | #include "refcnt.h" | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | namespace panda { | 
| 8 |  |  |  |  |  |  |  | 
| 9 | 0 | 0 |  |  |  |  | struct Stackframe: public Refcnt { | 
| 10 |  |  |  |  |  |  | string file; | 
| 11 |  |  |  |  |  |  | string library; | 
| 12 |  |  |  |  |  |  | string name; | 
| 13 |  |  |  |  |  |  | string mangled_name; | 
| 14 |  |  |  |  |  |  | std::uint64_t address = 0; | 
| 15 |  |  |  |  |  |  | std::uint64_t offset = 0; | 
| 16 |  |  |  |  |  |  | std::uint64_t line_no = 0; | 
| 17 |  |  |  |  |  |  | std::vector args; | 
| 18 |  |  |  |  |  |  | }; | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  | using StackframeSP = iptr; | 
| 21 |  |  |  |  |  |  | using StackFrames = std::vector; | 
| 22 |  |  |  |  |  |  |  | 
| 23 |  |  |  |  |  |  | struct BacktraceBackend: Refcnt { | 
| 24 |  |  |  |  |  |  | virtual bool produce_frame(StackFrames& result, size_t i) = 0; | 
| 25 |  |  |  |  |  |  | }; | 
| 26 |  |  |  |  |  |  | using BacktraceBackendSP = iptr; | 
| 27 |  |  |  |  |  |  |  | 
| 28 |  |  |  |  |  |  | struct BacktraceInfo : Refcnt { | 
| 29 | 50 |  |  |  |  |  | BacktraceInfo(std::vector&& frames_) : frames(std::move(frames_)) {} | 
| 30 |  |  |  |  |  |  | virtual ~BacktraceInfo(); | 
| 31 | 76 |  |  |  |  |  | const std::vector& get_frames() const noexcept { return frames;} | 
| 32 |  |  |  |  |  |  | virtual string to_string() const noexcept; | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  | StackFrames frames; | 
| 35 |  |  |  |  |  |  | }; | 
| 36 |  |  |  |  |  |  |  | 
| 37 |  |  |  |  |  |  | struct Backtrace; | 
| 38 |  |  |  |  |  |  | using RawTrace = std::vector; | 
| 39 |  |  |  |  |  |  | using RawTraceProducer = int(*)(void**, int); | 
| 40 |  |  |  |  |  |  | using BacktraceProducer = BacktraceBackendSP(*)(const Backtrace& raw_traces); | 
| 41 |  |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  | struct Backtrace { | 
| 43 |  |  |  |  |  |  | static const constexpr int max_depth = 50; | 
| 44 |  |  |  |  |  |  |  | 
| 45 |  |  |  |  |  |  | Backtrace () noexcept; | 
| 46 |  |  |  |  |  |  | Backtrace (const Backtrace &other) noexcept; | 
| 47 |  |  |  |  |  |  | virtual ~Backtrace (); | 
| 48 |  |  |  |  |  |  | Backtrace& operator=(const Backtrace& other) = default; | 
| 49 |  |  |  |  |  |  |  | 
| 50 |  |  |  |  |  |  | iptr get_backtrace_info() const noexcept; | 
| 51 |  |  |  |  |  |  | const RawTrace& get_trace () const noexcept { return buffer; } | 
| 52 |  |  |  |  |  |  |  | 
| 53 |  |  |  |  |  |  | static void install_producer(BacktraceProducer& producer); | 
| 54 |  |  |  |  |  |  | static string dump_trace() noexcept; | 
| 55 |  |  |  |  |  |  |  | 
| 56 |  |  |  |  |  |  | std::vector buffer; | 
| 57 |  |  |  |  |  |  | }; | 
| 58 |  |  |  |  |  |  |  | 
| 59 |  |  |  |  |  |  | template | 
| 60 |  |  |  |  |  |  | struct bt : T, Backtrace { | 
| 61 |  |  |  |  |  |  | template | 
| 62 |  |  |  |  |  |  | bt (Args&&... args) noexcept : T(std::forward(args...)) {} | 
| 63 |  |  |  |  |  |  | }; | 
| 64 |  |  |  |  |  |  |  | 
| 65 |  |  |  |  |  |  | struct exception : std::exception, Backtrace { | 
| 66 |  |  |  |  |  |  | exception () noexcept; | 
| 67 |  |  |  |  |  |  | exception (const string& whats) noexcept; | 
| 68 |  |  |  |  |  |  | exception (const exception& oth) noexcept; | 
| 69 |  |  |  |  |  |  | exception& operator= (const exception& oth) noexcept; | 
| 70 |  |  |  |  |  |  |  | 
| 71 |  |  |  |  |  |  | const char* what () const noexcept override; | 
| 72 |  |  |  |  |  |  |  | 
| 73 |  |  |  |  |  |  | virtual string whats () const noexcept; | 
| 74 |  |  |  |  |  |  |  | 
| 75 |  |  |  |  |  |  | private: | 
| 76 |  |  |  |  |  |  | mutable string _whats; | 
| 77 |  |  |  |  |  |  | }; | 
| 78 |  |  |  |  |  |  |  | 
| 79 |  |  |  |  |  |  |  | 
| 80 |  |  |  |  |  |  | } |