31 #include "fastjet/Error.hh" 32 #include "fastjet/config.h" 37 #ifdef FASTJET_HAVE_EXECINFO_H 40 #ifdef FASTJET_HAVE_DEMANGLING_SUPPORT 43 #endif // FASTJET_HAVE_DEMANGLING_SUPPORT 44 #endif // FASTJET_HAVE_EXECINFO_H 47 FASTJET_BEGIN_NAMESPACE
51 bool Error::_print_errors =
true;
52 bool Error::_print_backtrace =
false;
53 ostream * Error::_default_ostr = & cerr;
54 #if (!defined(FASTJET_HAVE_EXECINFO_H)) || defined(__FJCORE__) 55 LimitedWarning Error::_execinfo_undefined;
64 #if defined(FASTJET_HAVE_EXECINFO_H) && defined(FASTJET_HAVE_DEMANGLING_SUPPORT) 78 string Error::_demangle(
const char* symbol) {
91 if (1 == sscanf(symbol,
"%*[^(]%*[^_]%127[^)+]", temp)) {
93 if (NULL != (demangled = abi::__cxa_demangle(temp, NULL, &size, &status))) {
94 string result(demangled);
100 if (1 == sscanf(symbol,
"%127s", temp)) {
107 #endif // FASTJET_HAVE_DEMANGLING_SUPPORT && FASTJET_HAVE_EXECINFO_H 112 Error::Error(
const std::string & message_in) {
113 _message = message_in;
115 if (_print_errors && _default_ostr){
117 oss <<
"fastjet::Error: "<< message_in << endl;
121 #ifdef FASTJET_HAVE_EXECINFO_H 122 if (_print_backtrace){
126 int size = backtrace(array, 10);
127 messages = backtrace_symbols(array, size);
129 oss <<
"stack:" << endl;
130 for (
int i = 1; i < size && messages != NULL; ++i){
131 #ifdef FASTJET_HAVE_DEMANGLING_SUPPORT 132 oss <<
" #" << i <<
": " << _demangle(messages[i])
133 <<
" [" << messages[i] <<
"]" << endl;
135 oss <<
" #" << i <<
": " << messages[i] << endl;
140 #endif // FASTJET_HAVE_EXECINFO_H 143 *_default_ostr << oss.str();
146 _default_ostr->flush();
159 void Error::set_print_backtrace(
bool enabled) {
160 #if (!defined(FASTJET_HAVE_EXECINFO_H)) || defined(__FJCORE__) 162 _execinfo_undefined.warn(
"Error::set_print_backtrace(true) will not work with this build of FastJet");
165 _print_backtrace = enabled;
168 FASTJET_END_NAMESPACE