14#include <AUI/Common/AString.h>
15#include <AUI/Common/AVector.h>
42 explicit Entry(
void* ptr) : mPtr(ptr), mFunctionName(std::nullopt) {}
65 void* ptr() const noexcept {
70 using iterator = AVector<Entry>::iterator;
99 const
AVector<Entry>& entries() const noexcept {
104 auto begin() const noexcept {
105 return mEntries.begin();
109 auto end() const noexcept {
110 return mEntries.end();
114 auto rbegin() const noexcept {
115 return mEntries.rbegin();
119 auto rend() const noexcept {
120 return mEntries.rend();
130 static AStacktrace capture(
unsigned skipFrames = 0,
unsigned maxFrames = 128) noexcept;
133 mutable
AVector<Entry> mEntries;
134 mutable
bool mSymbolNamesResolved = false;
139inline std::ostream& operator<<(std::ostream& o,
const AStacktrace& stacktrace)
noexcept {
140 stacktrace.resolveSymbolsIfNeeded();
141 for (
const auto& entry : stacktrace) {
142 o <<
" - at " << entry.ptr();
143 if (
auto name = entry.functionName()) {
148 if (
auto filename = entry.fileName()) {
154 if (
auto line = entry.lineNumber()) {
160 o <<
")" << std::endl;
Utility wrapper implementing the stack-allocated (fast) optional idiom.
Definition: AOptional.h:32
Stacktrace entry.
Definition: AStacktrace.h:33
const AOptional< AString > & fileName() const noexcept
Definition: AStacktrace.h:54
const AOptional< AString > & functionName() const noexcept
Definition: AStacktrace.h:47
AOptional< unsigned > lineNumber() const noexcept
Definition: AStacktrace.h:61
Stacktrace consisting of a collection of stack function frames.
Definition: AStacktrace.h:28
aui::range< iterator > stripBeforeFunctionCall(void *pFunction, int maxAllowedOffsetInBytes=50)
Tries to find the function pointer in stacktrace and strips stacktrace until function frame.
Definition: AStacktrace.cpp:7
static AStacktrace capture(unsigned skipFrames=0, unsigned maxFrames=128) noexcept
Creates stacktrace of the current thread.
Definition: AStacktraceImpl.cpp:156
void resolveSymbolsIfNeeded() const noexcept
Invokes function name resolution with function pointers.
Definition: AStacktraceImpl.cpp:152
A std::vector with AUI extensions.
Definition: AVector.h:38
Definition: iterators.h:50