29 std::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);
50 struct Symbol :
public bt::Frame::Symbol
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 98 frame_pointer_(frame_pointer),
120 std::shared_ptr<bt::Frame::Symbol> bt::Frame::Symbol::for_testing_from_raw_symbol(
const char*
symbol)
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++)
Frame(std::size_t depth, void *frame_pointer, const char *symbol)
const Symbol & symbol() const
symbol returns the symbolic representation of this frame.
The Frame class models an individual frame of a backtrace.
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)
void visit_with_handler(const FrameHandler &handler)
visit_with_handler iterates the backtrace of the calling program, invoking the handler for every fram...
std::size_t depth() const
depth returns the depth of this frame in the overall backtrace.
std::string demangled() const
Symbol(const char *symbol)
virtual void * frame_pointer() const
frame_pointer returns the the raw frame pointer of this frame.