15 #ifndef INCLUDED_utility_backtrace_hh
16 #define INCLUDED_utility_backtrace_hh
34 #define MY__has_include( x ) __has_include( x )
36 #define MY__has_include( x ) 1
40 #if defined(__GNUC__) && !defined(WIN32) && !defined(__CYGWIN__) && MY__has_include( <cxxabi.h> )
61 demangle( std::string
trace ) {
69 begin = trace.find(
" _") + 1;
70 end = trace.find(
" +",begin);
74 if ( begin == std::string::npos || end == std::string::npos ) {
75 begin = trace.find(
"(_") + 1;
76 end = trace.find(
"+",begin);
80 if ( begin != std::string::npos && end != std::string::npos ) {
81 std::string mangled_trace = trace.substr(begin, end - begin);
82 size_t maxName = 1024;
85 char* demangledName = (
char*) malloc(maxName);
86 if ( (demangledName = abi::__cxa_demangle(mangled_trace.c_str(), demangledName, &maxName,
87 &demangleStatus)) && demangleStatus == 0 ) {
88 trace = trace.substr(0,begin) + demangledName + trace.substr(end );
114 size_t const callstack_size = 128;
115 void* callstack[callstack_size];
116 int i, frames = backtrace(callstack, callstack_size);
117 char** strs = backtrace_symbols(callstack, frames);
119 for ( i = 0; i < frames; ++i ) {
120 std::cerr << demangle( strs[i] ).c_str() << std::endl;
127 #define debug_assert(condition) {assert( ( condition ) || print_backtrace() ); }
140 #define debug_assert(condition) {assert( condition ); }
144 #endif // INCLUDED_utility_backtrace_HH
ocstream cerr(std::cerr)
Wrapper around std::cerr.
utility::keys::lookup::end< KeyType > const end
static THREAD_LOCAL basic::Tracer trace("fragment_picker")
static CSI_Sequence const CSI_Reset("\x1b[0m")
utility::keys::lookup::begin< KeyType > const begin
static CSI_Sequence const CSI_Magenta("\x1b[35m")