97 static_cast<void>(data);
100 <<
"libbacktrace error: "
121 static backtrace_state * g_backtrace_state = backtrace_create_state(
127 return g_backtrace_state;
145 std::string f_filename = std::string();
146 std::string f_function = std::string();
174 ,
char const * filename
176 ,
char const * function)
182 .f_filename = filename ==
nullptr ? std::string() : filename,
187 info_list->push_back(info);
214 g_extended_stack = extended_stack;
231 return g_extended_stack;
277 if(stack_trace_depth > 0)
279 std::vector<void *> array;
280 array.resize(std::max(stack_trace_depth, 1'000));
281 int const size(backtrace(&array[0], stack_trace_depth));
285 std::unique_ptr<
char *,
decltype(&::free)> stack_string_list(backtrace_symbols(&array[0], size), &::free);
286 if(stack_string_list !=
nullptr)
288 for(
int idx(0); idx < size; ++idx)
290 char const * stack_string(stack_string_list.get()[idx]);
291 stack_trace.push_back(stack_string);
337 if(stack_trace_depth > 0)
339 std::vector<void *> array;
341 array.resize(std::max(stack_trace_depth + 3, 1'000));
342 int const size(backtrace(&array[0], stack_trace_depth));
343 backtrace_state * state(get_backtrace_state());
344 for(
int idx(0); idx < size; ++idx)
348 symbol_info::list_t info_list;
351 ,
reinterpret_cast<uintptr_t
>(array[idx])
356 for(
auto & info : info_list)
358 if(!info.f_filename.empty())
362 && info.f_function.starts_with(
"libexcept::"))
369 if(info.f_function ==
"main")
371 if(!g_extended_stack)
381 info.f_function =
"main(int, char *[])";
383 std::string result(info.f_filename);
385 result += std::to_string(info.f_line);
387 result += info.f_function;
388 stack_trace.push_back(result);
400 std::unique_ptr<
char *,
decltype(&::free)> stack_string_list(backtrace_symbols(&array[idx], 1), &::free);
401 if(stack_string_list.get() !=
nullptr)
403 stack_trace.push_back(stack_string_list.get()[0]);
Declarations of demangle functions we support.
Declarations of the exception library.
int backtrace_callback(void *data, uintptr_t pc, char const *filename, int line, char const *function)
Call back with backtrace data.
bool g_extended_stack
The extended stack flag.
backtrace_state * get_backtrace_state()
Retrieve a pointer to the backtrace state.
void error_callback(void *data, char const *msg, int err)
Capture errors while running backtrace_pcinfo().
void set_extended_stack(bool extended_stack)
Set the extended stack flag status.
bool get_extended_stack()
Get the extended stack flag status.
stack_trace_t collect_stack_trace(int stack_trace_depth)
Collect the raw stack trace in a list of strings.
std::string demangle_cpp_name(char const *type_id_name)
Demangle the specified type string.
std::list< std::string > stack_trace_t
The stack trace results.
stack_trace_t collect_stack_trace_with_line_numbers(int stack_trace_depth)
Collect the stack trace in a list of strings.
Structure used to collect symbol information.
std::list< symbol_info > list_t