Changeset 273e668 in git for external/fastjet/Error.cc
- Timestamp:
- Oct 15, 2014, 10:55:55 AM (10 years ago)
- Branches:
- ImprovedOutputFile, Timing, dual_readout, llp, master
- Children:
- 35b9204, b25d4cf
- Parents:
- f14bd6a
- git-author:
- Pavel Demin <pavel.demin@…> (10/10/14 08:56:40)
- git-committer:
- Pavel Demin <pavel.demin@…> (10/15/14 10:55:55)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
external/fastjet/Error.cc
rf14bd6a r273e668 1 1 //FJSTARTHEADER 2 // $Id: Error.cc 3 433 2014-07-23 08:17:03Z salam$2 // $Id: Error.cc 3695 2014-09-18 13:57:56Z cacciari $ 3 3 // 4 4 // Copyright (c) 2005-2014, Matteo Cacciari, Gavin P. Salam and Gregory Soyez … … 33 33 #include <sstream> 34 34 35 #ifndef __FJCORE__ 35 36 // printing the stack would need execinfo 36 37 #ifdef FASTJET_HAVE_EXECINFO_H 37 38 #include <execinfo.h> 38 39 #include <cstdlib> 39 #endif 40 #ifdef FASTJET_HAVE_DEMANGLING_SUPPORT 41 #include <cstdio> 42 #include <cxxabi.h> 43 #endif // FASTJET_HAVE_DEMANGLING_SUPPORT 44 #endif // FASTJET_HAVE_EXECINFO_H 45 #endif // __FJCORE__ 40 46 41 47 FASTJET_BEGIN_NAMESPACE // defined in fastjet/internal/base.hh … … 46 52 bool Error::_print_backtrace = false; 47 53 ostream * Error::_default_ostr = & cerr; 54 #if (!defined(FASTJET_HAVE_EXECINFO_H)) || defined(__FJCORE__) 55 LimitedWarning Error::_execinfo_undefined; 56 #endif 48 57 58 //---------------------------------------------------------------------- 59 #ifndef __FJCORE__ 60 61 // demangling only is included, i.e. --enable-demangling is specified 62 // at configure time, execinfo.h is present and the GNU C++ ABI is 63 // supported 64 #if defined(FASTJET_HAVE_EXECINFO_H) && defined(FASTJET_HAVE_DEMANGLING_SUPPORT) 65 // demangle a given backtrace symbol 66 // 67 // Notes: 68 // - at the moment, only the symbol is parsed. 69 // - one can get the offset by using 70 // "%*[^(]%*[^_]%127[^+)]%64[+x0123456789abcdef]", symbol, offset 71 // and checking if sscanf returns 0, 1 or 2 72 // (offset includes the leading +) 73 // - Similarly one could exctract the address and try to convert it 74 // into a filename+line number like addr2line does but this seems 75 // to require exteral dependencies. If we want to go down that 76 // route, one could look into the inplementation o faddr2line(.c) 77 // and/or dladdr. 78 string Error::_demangle(const char* symbol) { 79 size_t size; 80 int status; 81 char temp[128]; 82 char* demangled; 83 // first, try to demangle a c++ name 84 // decryption: 85 // %*[^(] matches any number of characters different from "(" 86 // the * tells not to store in input var 87 // %*[^_] matches any number of characters different from "_" 88 // the * tells not to store in input var 89 // %127[^)+] matches at most 127 characters different from "+" 90 // match is stored 91 if (1 == sscanf(symbol, "%*[^(]%*[^_]%127[^)+]", temp)) { 92 //cout << symbol << " -> " << temp << endl; 93 if (NULL != (demangled = abi::__cxa_demangle(temp, NULL, &size, &status))) { 94 string result(demangled); 95 free(demangled); 96 return result; 97 } 98 } 99 //if that didn't work, try to get a regular c symbol 100 if (1 == sscanf(symbol, "%127s", temp)) { 101 return temp; 102 } 103 104 //if all else fails, just return the symbol 105 return symbol; 106 } 107 #endif // FASTJET_HAVE_DEMANGLING_SUPPORT && FASTJET_HAVE_EXECINFO_H 108 #endif // __FJCORE__ 109 110 111 //---------------------------------------------------------------------- 49 112 Error::Error(const std::string & message_in) { 50 113 _message = message_in; 114 51 115 if (_print_errors && _default_ostr){ 52 116 ostringstream oss; 53 117 oss << "fastjet::Error: "<< message_in << endl; 54 118 119 #ifndef __FJCORE__ 55 120 // only print the stack if execinfo is available and stack enabled 56 121 #ifdef FASTJET_HAVE_EXECINFO_H … … 64 129 oss << "stack:" << endl; 65 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; 134 #else 66 135 oss << " #" << i << ": " << messages[i] << endl; 136 #endif 67 137 } 68 138 free(messages); 69 139 } 70 #endif 140 #endif // FASTJET_HAVE_EXECINFO_H 141 #endif // __FJCORE__ 71 142 72 143 *_default_ostr << oss.str(); … … 85 156 } 86 157 158 //---------------------------------------------------------------------- 159 void Error::set_print_backtrace(bool enabled) { 160 #if (!defined(FASTJET_HAVE_EXECINFO_H)) || defined(__FJCORE__) 161 if (enabled) { 162 _execinfo_undefined.warn("Error::set_print_backtrace(true) will not work with this build of FastJet"); 163 } 164 #endif 165 _print_backtrace = enabled; 166 } 167 87 168 FASTJET_END_NAMESPACE 88 169
Note:
See TracChangeset
for help on using the changeset viewer.