25 #if (( defined( __linux__ ) && defined( __GNUC__ )) && !defined( __ANDROID__) || defined ( __APPLE__ ))
26 #define BACKTRACE_SUPPORTED
29 #ifdef BACKTRACE_SUPPORTED
41 #include <boost/algorithm/string.hpp>
43 #include "WException.h"
64 std::cerr <<
m_headlineColor( std::string(
"Exception thrown! Callstack's backtrace:" ) ) << std::endl <<
getBacktrace() << std::endl;
81 std::cerr <<
m_headlineColor( std::string(
"Exception thrown! Callstack's backtrace:" ) ) << std::endl <<
getBacktrace() << std::endl;
98 std::string result(
what() );
100 std::list< std::string >::const_iterator citer;
102 result +=
"trace: " + *citer +
"\n";
103 boost::trim( result );
110 std::ostringstream o;
112 #ifdef BACKTRACE_SUPPORTED
116 const size_t maxDepth = 100;
118 void* stackAddrs[maxDepth];
122 stackDepth = backtrace( stackAddrs, maxDepth );
123 stackSymbols = backtrace_symbols( stackAddrs, stackDepth );
126 for(
size_t i = 1; i < stackDepth; ++i )
130 size_t functionLength = 512;
131 char*
function =
new char[functionLength];
138 for(
char* j = stackSymbols[i]; *j; ++j )
158 char* ret = abi::__cxa_demangle( begin,
function, &functionLength, &status );
168 std::strncpy(
function, begin, functionLength );
169 std::strncat(
function,
"()", functionLength );
170 function[functionLength-1] =
'\0';
191 free( stackSymbols );
193 o <<
"Backtrace not supported on your platform. Currently just works on Linux and MacOS with GCC. Sorry!" << std::endl
194 <<
"Message was: " <<
what();