ATLAS Offline Software
Loading...
Searching...
No Matches
exctrace_collector.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
16
17
18#include <dlfcn.h>
19#include <execinfo.h>
20#include <cstdio>
21#include <typeinfo>
22#include <utility>
23#include <algorithm>
24#include <exception>
26
27// Maximum stack depth.
28static
29const int bt_depth = 100;
30
31// Static buffer used to save the backtrace.
32static thread_local int exctrace_last_depth = 0;
33static thread_local void* exctrace_last_trace[bt_depth];
34
35// The real __cxa_throw function.
36typedef void throwfn (void*, void*, void (*dest)(void*));
38
39
40// Force a dependency on libstdc++ so that we will be able to find
41// __cxa_throw via dlsym. Otherwise the link dependency may be removed
42// since we usually link with as-needed.
44{
45 std::terminate();
46}
47
48
49extern "C" {
50 // Function to retrieve the last trace.
51 // extern "C" because we want to find it with dlsym.
52 int exctrace_get_last_trace (int max_depth, void* trace[])
53 {
54 int ncopy = std::min (exctrace_last_depth, max_depth);
55 std::copy (exctrace_last_trace, exctrace_last_trace+ncopy, trace);
56 return ncopy;
57 }
58}
59
60
61// The __cxa_throw hook function.
62// Record a backtrace, then chain to the real throw function.
63extern "C" void __cxa_throw (void* thrown_exception,
64 void* tinfo,
65 void (*dest)(void*))
66{
68 old_throw (thrown_exception, tinfo, dest);
69 // not reached
70 std::abort();
71}
72
73
74// Initialization: install the hook.
75namespace CxxUtils {
76
77
82
83
85{
86 old_throw = (throwfn*)(long)dlsym (RTLD_NEXT, "__cxa_throw");
87}
88
89
91
92
93} // namespace CxxUtils
Define macros for attributes used to control the static checker.
#define ATLAS_NOT_THREAD_SAFE
getNoisyStrip() Find noisy strips from hitmaps and write out into xml/db formats
void throwfn(void *, void *, void(*dest)(void *))
int exctrace_get_last_trace(int max_depth, void *trace[])
static thread_local void * exctrace_last_trace[bt_depth]
static const int bt_depth
void __cxa_throw(void *thrown_exception, void *tinfo, void(*dest)(void *))
static thread_local int exctrace_last_depth
static throwfn * old_throw
void extrace_force_libstd_link()
static extrace_init initer