24 #if (!defined(__GNUG__) && defined(__clang__)) || defined(LEOSAC_STACKTRACE_DISABLED)
25 #define LEOSAC_STACKTRACE_DISABLED
27 #include <backtrace.h>
30 #include <boost/core/demangle.hpp>
31 #include <boost/range/adaptor/reversed.hpp>
38 #ifndef LEOSAC_STACKTRACE_DISABLED
39 auto cb_error = [](
void * ,
const char *msg,
int errnum) {
40 ERROR(
"Problem when generating stacktrace: " << msg
41 <<
". Error code: " << errnum);
44 auto cb_full = [](
void *data, uintptr_t ,
const char *filename,
int line,
45 const char *
function) ->
int {
46 std::vector<Frame> *stack =
static_cast<std::vector<Frame> *
>(data);
50 frame.suppressed_ =
true;
54 frame.function_ = boost::core::demangle(
function);
56 frame.file_ = filename;
58 stack->push_back(frame);
62 struct backtrace_state *bt =
63 backtrace_create_state(
nullptr, 0,
nullptr,
nullptr);
64 backtrace_full(bt, skip, cb_full, cb_error, &
stack_);
71 int suppressed_count = 0;
74 for (
const auto &frame :
stack_)
76 if (frame_count == max_frames)
78 if (frame.suppressed_)
84 ss <<
Colorize::red(
"Frames suppressed: ") << suppressed_count
88 ss <<
"#" << frame_count <<
" in " <<
Colorize::cyan(frame.function_)