libexcept 1.1.21
Stack trace along C++ exceptions
Classes | Functions | Variables
libexcept::anonymous_namespace{stack_trace.cpp} Namespace Reference

Classes

struct  symbol_info
 Structure used to collect symbol information. More...
 

Functions

int backtrace_callback (void *data, uintptr_t pc, char const *filename, int line, char const *function)
 Call back with backtrace data.
 
void error_callback (void *data, char const *msg, int err)
 Capture errors while running backtrace_pcinfo().
 
backtrace_state * get_backtrace_state ()
 Retrieve a pointer to the backtrace state.
 

Variables

bool g_extended_stack = false
 The extended stack flag.
 

Function Documentation

◆ backtrace_callback()

int libexcept::anonymous_namespace{stack_trace.cpp}::backtrace_callback ( void *  data,
uintptr_t  pc,
char const *  filename,
int  line,
char const *  function 
)

This function gets called by the backtrace_pcinfo() function each time it finds a match.

The function is used to collect the filename, line number and function name of each hit.

Note
There can be multiple hits because you used macros, templates, functions get inlined, and a few other cases.
Parameters
[in]dataA pointer to our structure.
[in]pcThe concerned pointer counter (memory address).
[in]filenameThe name of the file with the source code.
[in]lineThe line number where the call happened.
[in]functionThe name of the function being called.
Returns
Always 0 so we can capture all the possible names.

Definition at line 171 of file stack_trace.cpp.

References backtrace_callback(), libexcept::demangle_cpp_name(), and libexcept::anonymous_namespace{stack_trace.cpp}::symbol_info::f_pc.

Referenced by backtrace_callback().

◆ error_callback()

void libexcept::anonymous_namespace{stack_trace.cpp}::error_callback ( void *  data,
char const *  msg,
int  err 
)

When trying to collect information about a function, we call the backtrace_pcinfo() function with this function as a callback function for errors. It generates an error message in std::cerr with the library's message and err number.

Parameters
[in]dataOur data pointer.
[in]msgThe library's message.
[in]errThe error number.

Definition at line 95 of file stack_trace.cpp.

References error_callback().

Referenced by error_callback(), and get_backtrace_state().

◆ get_backtrace_state()

backtrace_state * libexcept::anonymous_namespace{stack_trace.cpp}::get_backtrace_state ( )

To use the backtrace_pcinfo() function, we need to have a backtrace state. Function safely allocate that state the first time it gets called. We automatically create a thread safe version of the state.

Note
This state leaks.
Returns
A pointer to the backtrace_state object.

Definition at line 119 of file stack_trace.cpp.

References error_callback(), and get_backtrace_state().

Referenced by get_backtrace_state().

Variable Documentation

◆ g_extended_stack

bool libexcept::anonymous_namespace{stack_trace.cpp}::g_extended_stack = false

When creating a stack trace, we skip various frames by default: the libexcept frames, because they are rather useless (assuming this library functions as expected) and the functions called before the main() function.

You may change the behavior by calling the set_extended_stack() function.

Note
The stack depth also determines how many frames of stack you will get in your output. That is limited to STACK_TRACE_DEPTH (20) by default. Skipped frames generally do not count against that depth.

Definition at line 81 of file stack_trace.cpp.

This document is part of the Snap! Websites Project.

Copyright by Made to Order Software Corp.