]> git.proxmox.com Git - ceph.git/blob - ceph/src/common/BackTrace.h
fe0ad0e7efacd21abc705f2797ef0cd0fcaa06c8
[ceph.git] / ceph / src / common / BackTrace.h
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;
17 void *array[max];
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