]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | #ifndef CEPH_BACKTRACE_H |
2 | #define CEPH_BACKTRACE_H | |
3 | ||
4 | #include "acconfig.h" | |
5 | #include <iosfwd> | |
6 | #ifdef HAVE_EXECINFO_H | |
7 | #include <execinfo.h> | |
8 | #endif | |
9 | #include <stdlib.h> | |
10 | ||
11 | namespace ceph { | |
12 | ||
13 | struct BackTrace { | |
14 | const static int max = 100; | |
15 | ||
16 | int skip; | |
224ce89b | 17 | void *array[max]{}; |
7c673cae FG |
18 | size_t size; |
19 | char **strings; | |
20 | ||
21 | explicit BackTrace(int s) : skip(s) { | |
22 | #ifdef HAVE_EXECINFO_H | |
23 | size = backtrace(array, max); | |
24 | strings = backtrace_symbols(array, size); | |
25 | #else | |
26 | skip = 0; | |
27 | size = 0; | |
28 | strings = nullptr; | |
29 | #endif | |
30 | } | |
31 | ~BackTrace() { | |
32 | free(strings); | |
33 | } | |
34 | ||
35 | BackTrace(const BackTrace& other); | |
36 | const BackTrace& operator=(const BackTrace& other); | |
37 | ||
38 | void print(std::ostream& out) const; | |
39 | }; | |
40 | ||
41 | inline std::ostream& operator<<(std::ostream& out, const BackTrace& bt) { | |
42 | bt.print(out); | |
43 | return out; | |
44 | } | |
45 | ||
46 | } | |
47 | ||
48 | #endif |