ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Control
CxxUtils
src
exctrace
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>
25
#include "
CxxUtils/checker_macros.h
"
26
27
// Maximum stack depth.
28
static
29
const
int
bt_depth
= 100;
30
31
// Static buffer used to save the backtrace.
32
static
thread_local
int
exctrace_last_depth
= 0;
33
static
thread_local
void
*
exctrace_last_trace
[
bt_depth
];
34
35
// The real __cxa_throw function.
36
typedef
void
throwfn
(
void
*,
void
*,
void
(*dest)(
void
*));
37
static
throwfn
*
old_throw
;
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.
43
void
extrace_force_libstd_link
()
44
{
45
std::terminate();
46
}
47
48
49
extern
"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.
63
extern
"C"
void
__cxa_throw
(
void
* thrown_exception,
64
void
* tinfo,
65
void
(*dest)(
void
*))
66
{
67
exctrace_last_depth
= backtrace (
exctrace_last_trace
,
bt_depth
);
68
old_throw
(thrown_exception, tinfo, dest);
69
// not reached
70
std::abort();
71
}
72
73
74
// Initialization: install the hook.
75
namespace
CxxUtils
{
76
77
78
struct
ATLAS_NOT_THREAD_SAFE
extrace_init
79
{
80
extrace_init
();
81
};
82
83
84
extrace_init::extrace_init
()
85
{
86
old_throw
= (
throwfn
*)(
long
)dlsym (RTLD_NEXT,
"__cxa_throw"
);
87
}
88
89
90
static
extrace_init
initer
;
91
92
93
}
// namespace CxxUtils
checker_macros.h
Define macros for attributes used to control the static checker.
ATLAS_NOT_THREAD_SAFE
#define ATLAS_NOT_THREAD_SAFE
getNoisyStrip() Find noisy strips from hitmaps and write out into xml/db formats
Definition
checker_macros.h:212
throwfn
void throwfn(void *, void *, void(*dest)(void *))
Definition
exctrace_collector.cxx:36
exctrace_get_last_trace
int exctrace_get_last_trace(int max_depth, void *trace[])
Definition
exctrace_collector.cxx:52
bt_depth
static const int bt_depth
Definition
exctrace_collector.cxx:29
__cxa_throw
void __cxa_throw(void *thrown_exception, void *tinfo, void(*dest)(void *))
Definition
exctrace_collector.cxx:63
exctrace_last_depth
static int exctrace_last_depth
Definition
exctrace_collector.cxx:32
old_throw
static throwfn * old_throw
Definition
exctrace_collector.cxx:37
extrace_force_libstd_link
void extrace_force_libstd_link()
Definition
exctrace_collector.cxx:43
exctrace_last_trace
static void * exctrace_last_trace[bt_depth]
Definition
exctrace_collector.cxx:33
CxxUtils
Definition
aligned_vector.h:29
CxxUtils::initer
static extrace_init initer
Definition
exctrace_collector.cxx:90
CxxUtils::extrace_init
Definition
exctrace_collector.cxx:79
CxxUtils::extrace_init::extrace_init
extrace_init()
Definition
exctrace_collector.cxx:84
Generated on
for ATLAS Offline Software by
1.17.0