1 #ifndef EXCEPTIONSTACKTRACE_H
2 #define EXCEPTIONSTACKTRACE_H
8 #include <unordered_map>
17 typedef void(__cxa_throw_t)(
void*,
void*, void (*)(
void*));
18 void __cxa_throw(
void*,
void*,
void (*)(
void*));
20 typedef __attribute__((noreturn)) void(__cxa_throw_t)(
void*, std::type_info*,
void (*)(
void*));
21 __attribute__((noreturn))
void __cxa_throw(
void*, std::type_info*,
void (*)(
void*));
25 namespace artdaq::debug {
38 explicit Trace(
size_t index, std::string symbol)
39 : index_{index}, symbol_{std::move(symbol)}, address_{0}, filename_{
"unresolved"}, function_{
"unresolved"}, offset_{0}
54 std::string
print()
const;
77 std::string filename_;
81 std::string function_;
88 inline std::ostream&
operator<<(std::ostream& os, Trace
const& trace)
100 using traces_t = std::vector<Trace>;
111 std::string
print()
const;
128 static std::string
demangle(std::string
const& symbol);
134 std::string type_name_;
138 std::unique_ptr<traces_t> traces_uptr_;
151 os << stack_trace.
print();
161 using stacktrace_map_t = std::unordered_map<std::thread::id, StackTrace>;
167 : stack_traces_{}, stack_traces_mutex_{} {}
178 template<
typename... Args>
181 std::lock_guard<std::mutex> lg(stack_traces_mutex_);
182 stack_traces_.insert_or_assign(std::this_thread::get_id(),
StackTrace(std::forward<Args>(args)...));
192 std::lock_guard<std::mutex> lg(stack_traces_mutex_);
193 auto& stack_trace = stack_traces_.at(std::this_thread::get_id());
195 return stack_trace.
print();
199 return "Error: possibly corrupt stack.";
207 stacktrace_map_t stack_traces_;
212 mutable std::mutex stack_traces_mutex_;
215 StackTraceCollector& getStackTraceCollector();
static std::string demangle(std::string const &symbol)
Demangles backtrace symbols.
Represents the entire stack trace message.
Trace(size_t index, std::string symbol)
Constructor.
StackTraceCollector()
Constructor.
void resolve()
Reads and demangles backtrace symbols.
StackTrace(std::string type_name)
Constructor.
std::ostream & operator<<(std::ostream &os, Fragment const &f)
Prints the given Fragment to the stream.
void resolve()
Reads and demangles backtrace symbols.
Collects stack traces from different threads.
std::string print() const
Produces a stack trace summary.
std::string print_stacktrace()
Produces a stack trace summary.
void collect_stacktrace(Args &&...args)
Adds a stacktrace to the stack_traces_ map.
Represents one line of the stack trace message.
std::string print() const
Produces a one-line summary.