29std::tuple<std::string, bool>
demangle(
const std::string& symbol)
32 auto result = abi::__cxa_demangle(symbol.c_str(),
37 if (!result || status != 0)
39 return std::make_tuple(std::string(),
false);
42 std::string s{result};
45 return std::make_tuple(s,
true);
54 auto first =
raw_.find_first_of(
"(");
55 auto last =
raw_.find_last_of(
")");
57 if (first != std::string::npos && last != std::string::npos)
59 auto mangled_symbol =
raw_.substr(first+1,
60 (last-1) - (first+1));
62 auto plus = mangled_symbol.find_first_of(
"+");
63 if (plus != std::string::npos)
64 mangled_symbol.erase(plus);
82 std::string
raw()
const
127 static const unsigned int max_frames=64;
128 void *frames[max_frames];
130 auto frame_count =
::backtrace(frames, max_frames);
131 auto symbols = ::backtrace_symbols(frames, frame_count);
135 Scope(
char** symbols) : symbols(symbols)
144 char** symbols =
nullptr;
147 for (
int i = 0; i < frame_count; i++)
The Symbol class models the symbolic representation of a frame pointer.
static std::shared_ptr< Symbol > for_testing_from_raw_symbol(const char *symbol)
The Frame class models an individual frame of a backtrace.
virtual const Symbol & symbol() const =0
symbol returns the symbolic representation of this frame.
void visit_with_handler(const FrameHandler &handler)
visit_with_handler iterates the backtrace of the calling program, invoking the handler for every fram...
std::function< bool(const Frame &frame)> FrameHandler
FrameHandler is the functor invoked for every frame of a backtrace.
std::tuple< std::string, bool > demangle(const std::string &symbol)
bool is_cxx() const
is_cxx checks whether the symbol refers to a mangled C++ symbol.
std::string raw() const
raw The raw symbolic representation of a frame pointer.
std::string demangled() const
demangled returns the demangled C++ symbol name or raw.
Symbol(const char *symbol)
const Symbol & symbol() const
symbol returns the symbolic representation of this frame.
Frame(std::size_t depth, void *frame_pointer, const char *symbol)
std::size_t depth() const
depth returns the depth of this frame in the overall backtrace.
virtual void * frame_pointer() const
frame_pointer returns the the raw frame pointer of this frame.