31#include "fastjet/Error.hh"
32#include "fastjet/config.h"
37#ifdef FASTJET_HAVE_EXECINFO_H
40#ifdef FASTJET_HAVE_DEMANGLING_SUPPORT
47FASTJET_BEGIN_NAMESPACE
51#ifdef FASTJET_HAVE_LIMITED_THREAD_SAFETY
52atomic<bool> Error::_print_errors{
true};
53atomic<bool> Error::_print_backtrace{
false};
54atomic<ostream *> Error::_default_ostr{& cerr};
55atomic<mutex *> Error::_stream_mutex{
nullptr};
57bool Error::_print_errors =
true;
58bool Error::_print_backtrace =
false;
59ostream * Error::_default_ostr = & cerr;
62#if (!defined(FASTJET_HAVE_EXECINFO_H)) || defined(__FJCORE__)
63 LimitedWarning Error::_execinfo_undefined;
72#if defined(FASTJET_HAVE_EXECINFO_H) && defined(FASTJET_HAVE_DEMANGLING_SUPPORT)
86string Error::_demangle(
const char* symbol) {
99 if (1 == sscanf(symbol,
"%*[^(]%*[^_]%127[^)+]", temp)) {
101 if (NULL != (demangled = abi::__cxa_demangle(temp, NULL, &size, &status))) {
102 string result(demangled);
108 if (1 == sscanf(symbol,
"%127s", temp)) {
120Error::Error(
const std::string & message_in) {
121 _message = message_in;
127 ostream* ostr = _default_ostr;
128 if (_print_errors && ostr){
130 oss <<
"fastjet::Error: "<< message_in << endl;
134#ifdef FASTJET_HAVE_EXECINFO_H
135 if (_print_backtrace){
139 int size = backtrace(array, 10);
140 messages = backtrace_symbols(array, size);
142 oss <<
"stack:" << endl;
143 for (
int i = 1; i < size && messages != NULL; ++i){
144#ifdef FASTJET_HAVE_DEMANGLING_SUPPORT
145 oss <<
" #" << i <<
": " << _demangle(messages[i])
146 <<
" [" << messages[i] <<
"]" << endl;
148 oss <<
" #" << i <<
": " << messages[i] << endl;
156#ifdef FASTJET_HAVE_LIMITED_THREAD_SAFETY
158 std::lock_guard<std::mutex> guard(*_stream_mutex);
171void Error::set_print_backtrace(
bool enabled) {
172#if (!defined(FASTJET_HAVE_EXECINFO_H)) || defined(__FJCORE__)
174 _execinfo_undefined.warn(
"Error::set_print_backtrace(true) will not work with this build of FastJet");
177 _print_backtrace = enabled;