The Sparta Modeling Framework
Loading...
Searching...
No Matches
Backtrace.hpp
Go to the documentation of this file.
1// <Backtrace.hpp> -*- C++ -*-
2
8#pragma once
9
10#ifndef _GNU_SOURCE
11#define _GNU_SOURCE
12#endif
13#ifndef __USE_GNU
14#define __USE_GNU
15#endif
16
17#include <csignal>
18#include <iostream>
19#include <map>
20#include <vector>
21#include <string>
22
23namespace sparta
24{
25 namespace app
26 {
27
33{
34
38 std::vector<std::pair<void*, std::string>> frames_;
39
40public:
41
45 BacktraceData() = default;
46
50 BacktraceData(const BacktraceData&) = default;
51
56
63 void render(std::ostream& o, bool line_info=true) const;
64
72 void addFrame(void* addr, const char* message);
73};
74
82{
83 struct sigaction sigact_;
84
85 std::map<int, struct sigaction> handled_;
86
87public:
88
93
98
104 void setAsHandler(int signum=SIGSEGV);
105
109 static void dumpBacktrace(std::ostream& o);
110
115
116}; // class Backtrace
117
118 } // namespace app
119} // namespace sparta
Backtrace without line information. Can be rendered out when needed because rendering is slow.
Definition Backtrace.hpp:33
BacktraceData & operator=(const BacktraceData &)=delete
Not copy-assignable.
void addFrame(void *addr, const char *message)
Adds a new frame to the top of the backtrace (which is progressively more shallow in the real stack)....
void render(std::ostream &o, bool line_info=true) const
Render the backtrace to a file.
BacktraceData()=default
Construct the backtrace.
BacktraceData(const BacktraceData &)=default
Copy constructable.
Backtrace printer. Registers a handler for certain fatal signals and dumps the backtrace if they occu...
Definition Backtrace.hpp:82
~Backtrace()
Restore all handlers if they haven't been replaced a second time.
static BacktraceData getBacktrace()
Gets the current backtrace without rendering it.
static void dumpBacktrace(std::ostream &o)
Write the current backtrace to a stream.
void setAsHandler(int signum=SIGSEGV)
Set this as the handler for a signal.
Backtrace()
Default constructor.
Macros for handling exponential backoff.