]> git.proxmox.com Git - ceph.git/blame - ceph/src/common/BackTrace.h
import quincy beta 17.1.0
[ceph.git] / ceph / src / common / BackTrace.h
CommitLineData
11fdf7f2
TL
1// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2// vim: ts=8 sw=2 smarttab
3
7c673cae
FG
4#ifndef CEPH_BACKTRACE_H
5#define CEPH_BACKTRACE_H
6
7#include "acconfig.h"
8#include <iosfwd>
9#ifdef HAVE_EXECINFO_H
10#include <execinfo.h>
11#endif
12#include <stdlib.h>
13
20effc67
TL
14#include <list>
15#include <string>
16
7c673cae
FG
17namespace ceph {
18
11fdf7f2
TL
19class Formatter;
20
7c673cae 21struct BackTrace {
20effc67
TL
22 virtual ~BackTrace() {}
23 virtual void print(std::ostream& out) const = 0;
24 virtual void dump(Formatter *f) const = 0;
25};
26
27inline std::ostream& operator<<(std::ostream& out, const BackTrace& bt) {
28 bt.print(out);
29 return out;
30}
31
32
33struct ClibBackTrace : public BackTrace {
34 const static int max = 32;
7c673cae
FG
35
36 int skip;
224ce89b 37 void *array[max]{};
7c673cae
FG
38 size_t size;
39 char **strings;
40
20effc67 41 explicit ClibBackTrace(int s) {
7c673cae 42#ifdef HAVE_EXECINFO_H
20effc67 43 skip = s;
7c673cae
FG
44 size = backtrace(array, max);
45 strings = backtrace_symbols(array, size);
46#else
47 skip = 0;
48 size = 0;
49 strings = nullptr;
50#endif
51 }
20effc67 52 ~ClibBackTrace() {
7c673cae
FG
53 free(strings);
54 }
55
20effc67
TL
56 ClibBackTrace(const ClibBackTrace& other);
57 const ClibBackTrace& operator=(const ClibBackTrace& other);
58
59 void print(std::ostream& out) const override;
60 void dump(Formatter *f) const override;
7c673cae 61
f67539c2 62 static std::string demangle(const char* name);
7c673cae
FG
63};
64
20effc67
TL
65
66struct PyBackTrace : public BackTrace {
67 std::list<std::string> strings;
68
69 explicit PyBackTrace(std::list<std::string>& s) : strings(s) {}
70
71 void dump(Formatter *f) const override;
72 void print(std::ostream& out) const override;
73};
74
7c673cae
FG
75
76}
77
78#endif