Zth (libzth)
Loading...
Searching...
No Matches
backtrace.h
Go to the documentation of this file.
1#ifndef ZTH_BACKTRACE_H
2#define ZTH_BACKTRACE_H
3/*
4 * SPDX-FileCopyrightText: 2019-2026 Jochem Rutgers
5 *
6 * SPDX-License-Identifier: MPL-2.0
7 */
8
9#include <libzth/macros.h>
10
11#include <libzth/util.h>
12
13#ifdef __cplusplus
14
15# include <libzth/allocator.h>
16# include <libzth/config.h>
17# include <libzth/time.h>
18
19namespace zth {
20
21class Fiber;
22
23namespace impl {
24
27public:
28 typedef void* bt_type;
29
30 explicit NoBacktrace(size_t skip = 0, size_t maxDepth = 128) noexcept
31 {
32 (void)skip;
33 (void)maxDepth;
34 }
35
36 Fiber* fiber() const noexcept
37 {
38 return nullptr;
39 }
40
41 uint64_t fiberId() const noexcept
42 {
43 return 0;
44 }
45
46 bt_type bt() const noexcept
47 {
48 return nullptr;
49 }
50
51 bool truncated() const noexcept
52 {
53 return true;
54 }
55
56 Timestamp t0() const noexcept
57 {
58 return Timestamp();
59 }
60
61 Timestamp t1() const noexcept
62 {
63 return Timestamp();
64 }
65
66 void printPartial(size_t start, ssize_t end = -1, int color = -1) const
67 {
68 (void)start;
69 (void)end;
70 (void)color;
71 }
72
73 void print(int color = -1) const
74 {
75 (void)color;
76 }
77
78 void printDelta(NoBacktrace const& other, int color = -1) const
79 {
80 (void)other;
81 (void)color;
82 }
83};
84
92class Backtrace {
94public:
96
97 explicit Backtrace(size_t skip = 0, size_t maxDepth = 128) noexcept;
98
99 Fiber* fiber() const noexcept
100 {
101 return m_fiber;
102 }
103
104 uint64_t fiberId() const noexcept
105 {
106 return m_fiberId;
107 }
108
109 bt_type const& bt() const noexcept
110 {
111 return m_bt;
112 }
113
114 bt_type& bt() noexcept
115 {
116 return m_bt;
117 }
118
119 bool truncated() const noexcept
120 {
121 return m_truncated;
122 }
123
124 void truncated(bool set) noexcept
125 {
126 m_truncated = set;
127 }
128
129 Timestamp const& t0() const noexcept
130 {
131 return m_t0;
132 }
133
134 Timestamp const& t1() const noexcept
135 {
136 return m_t1;
137 }
138
139 void printPartial(size_t start, ssize_t end = -1, int color = -1) const;
140 void print(int color = -1) const;
141 void printDelta(Backtrace const& other, int color = -1) const;
142
143private:
144 Timestamp m_t0;
145 Timestamp m_t1;
146 Fiber* m_fiber;
147 uint64_t m_fiberId;
148 bt_type m_bt;
149 bool m_truncated;
150};
151
152template <bool Enable = Config::EnableBacktrace>
155};
156
157template <>
158struct PickBacktrace<false> {
160};
161
162} // namespace impl
163
169
170} // namespace zth
171#endif // __cplusplus
172#endif // ZTH_BACKTRACE_H
The fiber.
Definition fiber.h:62
Convenient wrapper around struct timespec that contains an absolute timestamp.
Definition time.h:629
Save a backtrace.
Definition backtrace.h:92
bt_type const & bt() const noexcept
Definition backtrace.h:109
void print(int color=-1) const
Fiber * fiber() const noexcept
Definition backtrace.h:99
vector_type< void * >::type bt_type
Definition backtrace.h:95
bool truncated() const noexcept
Definition backtrace.h:119
bt_type & bt() noexcept
Definition backtrace.h:114
void printDelta(Backtrace const &other, int color=-1) const
void truncated(bool set) noexcept
Definition backtrace.h:124
uint64_t fiberId() const noexcept
Definition backtrace.h:104
void printPartial(size_t start, ssize_t end=-1, int color=-1) const
Timestamp const & t1() const noexcept
Definition backtrace.h:134
Timestamp const & t0() const noexcept
Definition backtrace.h:129
uint64_t fiberId() const noexcept
Definition backtrace.h:41
NoBacktrace(size_t skip=0, size_t maxDepth=128) noexcept
Definition backtrace.h:30
bt_type bt() const noexcept
Definition backtrace.h:46
void printPartial(size_t start, ssize_t end=-1, int color=-1) const
Definition backtrace.h:66
Fiber * fiber() const noexcept
Definition backtrace.h:36
Timestamp t0() const noexcept
Definition backtrace.h:56
Timestamp t1() const noexcept
Definition backtrace.h:61
void printDelta(NoBacktrace const &other, int color=-1) const
Definition backtrace.h:78
void print(int color=-1) const
Definition backtrace.h:73
bool truncated() const noexcept
Definition backtrace.h:51
impl::PickBacktrace ::type Backtrace
Save a backtrace.
Definition backtrace.h:168
#define ZTH_CLASS_NEW_DELETE(T)
Define new/delete operators for a class, which are allocator-aware.
Definition allocator.h:160
std::vector< T, typename Config::Allocator< T >::type > type
Definition allocator.h:195