]> git.proxmox.com Git - ceph.git/blame - ceph/src/common/BackTrace.h
update sources to ceph Nautilus 14.2.1
[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
14namespace ceph {
15
11fdf7f2
TL
16class Formatter;
17
7c673cae
FG
18struct BackTrace {
19 const static int max = 100;
20
21 int skip;
224ce89b 22 void *array[max]{};
7c673cae
FG
23 size_t size;
24 char **strings;
25
26 explicit BackTrace(int s) : skip(s) {
27#ifdef HAVE_EXECINFO_H
28 size = backtrace(array, max);
29 strings = backtrace_symbols(array, size);
30#else
31 skip = 0;
32 size = 0;
33 strings = nullptr;
34#endif
35 }
36 ~BackTrace() {
37 free(strings);
38 }
39
40 BackTrace(const BackTrace& other);
41 const BackTrace& operator=(const BackTrace& other);
42
43 void print(std::ostream& out) const;
11fdf7f2 44 void dump(Formatter *f) const;
7c673cae
FG
45};
46
47inline std::ostream& operator<<(std::ostream& out, const BackTrace& bt) {
48 bt.print(out);
49 return out;
50}
51
52}
53
54#endif