call_stack
is a
platform-agnostic data structure to keep call_frame
s
information in. Use a boost::call_stack::call_stack_info
to render it in a human-readable form.
The template is parameterized by the maximum depth of the stack to be collected.
One can get the stack either when a call_stack
object is constructed, either later, by calling member get_stack()
.
See previous section.
call_frame
holds
the information of a call
stack frame. Use a call_frame_info
to print it.
boost::call_stack::call_stack<40> astack; // astack.get_stack(); // Where am I now? for (std::size_t i = 0; i < astack.size(); ++i) { boost::call_stack::call_frame aframe( astack[i] ); std::cout << boost::call_stack::call_frame_info< boost::call_stack::extended_symbol_resolver // extended_symbol_resolver, basic_symbol_resolver or null_symbol_resolver , boost::call_stack::fancy_call_frame_formatter // fancy_call_frame_formatter or terse_call_frame_formatter > (aframe) << "\n" ; }
A call_frame
formatter
dictates how the symbol information is to be printed to an output stream. The
library supplies two symbol formatters:
typedef boost::call_stack::call_stack<39> stack_type; std::cout << "I am here: \n" << boost::call_stack::call_stack_info< stack_type , boost::call_stack::null_symbol_resolver , boost::call_stack::terse_call_frame_formatter >(stack_type(true)) << std::endl;
Output:
I am here: [eb1eea] ??+0x0 (??) in ??:0 [eb6f30] ??+0x0 (??) in ??:0 [eb2b1c] ??+0x0 (??) in ??:0 [eb2ab4] ??+0x0 (??) in ??:0 [eb1086] ??+0x0 (??) in ??:0 [eb9689] ??+0x0 (??) in ??:0 [eb97cd] ??+0x0 (??) in ??:0 [765433aa] ??+0x0 (??) in ??:0 [779d9ef2] ??+0x0 (??) in ??:0 [779d9ec5] ??+0x0 (??) in ??:0
call_frame_info
binds together:
Used to output call_frame information.
boost::call_stack::call_stack<40> astack; // astack.get_stack(); // Where am I now? for (std::size_t i = 0; i < astack.size(); ++i) { boost::call_stack::call_frame aframe( astack[i] ); std::cout << boost::call_stack::call_frame_info< boost::call_stack::extended_symbol_resolver // extended_symbol_resolver, basic_symbol_resolver or null_symbol_resolver , boost::call_stack::fancy_call_frame_formatter // fancy_call_frame_formatter or terse_call_frame_formatter > (aframe) << "\n" ; }
symbol_info
binds
together:
You can pass in to the constructor an arbitrary memory address. Do so at your own risk: proper resolution is platform-dependent and sometimes unreliable.
// Construction from some address (of a function). Notes: MSVC 7.1 fails to resolve it. boost::call_stack::symbol_info< boost::call_stack::extended_symbol_resolver, boost::call_stack::fancy_symbol_formatter > sym1( func1 ); std::cout << "\nfunc1 symbol info:\n" << sym1 << std::endl;
A symbol formatter dictates how the symbol information is to be printed to an output stream. The library supplies two symbol formatters:
See above.
There are three symbol resolvers in the library:
null_symbol_resolver
:
Does nothing. This could be useful when tracing call stacks in difficult
situations, such as low memory conditions. Typically, resolving symols
implies memory allocations by the platform API used to resolve symbols.
basic_symbol_resolver
:
Resolve symbols to the extent that the API used is installed by default
on the platform. For instance, for GCC that would bean API restricted to
libc.lib.
extended_symbol_resolver
:
Resolve symbols with the help of extra libraries. This could add link dependencies
to libraries that are not installed. For instance, for GCC, libbfd is used
to resolve file names and line numbers. Define BOOST_CALL_STACK_NO_OPTIONAL_LIBS
to cut these dependencies off.
See above.
call_stack_info
is used to render to render call_stack
in a human-readable form.
It binds together:
See previous section.
boost::call_stack::init
.
Library initialization. Called implicitly at first usage of a symbol resolver.
boost::call_stack::shutdown
.
Library de-initilization. Call it explicitly if the platform requires.