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