1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/base/Backtrace.cc
15 #include "zypp/base/LogTools.h"
16 #include "zypp/base/String.h"
17 #include "zypp/base/Backtrace.h"
21 ///////////////////////////////////////////////////////////////////
24 std::ostream & dumpBacktrace( std::ostream & stream_r )
26 // get void*'s for all entries on the stack
27 static const size_t arraySize = 50;
28 void *array[arraySize];
29 size_t size = ::backtrace( array, arraySize );
31 // print out all the frames to stderr
32 char ** messages = ::backtrace_symbols( array, size );
35 static const size_t first = 1;
36 for ( size_t i = first; i < size; ++i )
38 char * mangled_name = 0;
39 char * offset_begin = 0;
40 char * offset_end = 0;
42 // find parantheses and +address offset surrounding mangled name
43 for ( char * p = messages[i]; *p; ++p )
63 // if the line could be processed, attempt to demangle the symbol
64 if ( mangled_name && offset_begin && offset_end && mangled_name < offset_begin )
66 *mangled_name++ = '\0';
67 *offset_begin++ = '\0';
71 char * real_name = ::abi::__cxa_demangle( mangled_name, 0, 0, &status );
73 // if demangling is successful, output the demangled function name
76 stream_r << "[bt]: (" << i << ") " << messages[i] << " : "
77 << real_name << "+" << offset_begin << offset_end;
80 // otherwise, output the mangled function name
83 stream_r << "[bt]: (" << i << ") " << messages[i] << " : "
84 << mangled_name << "+" << offset_begin << offset_end;
90 // otherwise, print the whole line
91 stream_r << "[bt]: (" << i << ") " << messages[i];
100 ///////////////////////////////////////////////////////////////////