forked from cryfs/cryfs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbacktrace_nonwindows.cpp
More file actions
49 lines (38 loc) · 1.06 KB
/
backtrace_nonwindows.cpp
File metadata and controls
49 lines (38 loc) · 1.06 KB
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
49
#if !defined(_MSC_VER)
#include <csignal>
#include <sstream>
#include "../logging/logging.h"
#include <cpp-utils/process/SignalHandler.h>
#include <boost/stacktrace.hpp>
using std::string;
using std::ostringstream;
using namespace cpputils::logging;
namespace cpputils {
string backtrace() {
std::ostringstream str;
str << boost::stacktrace::stacktrace();
return str.str();
}
namespace {
void sigsegv_handler(int) {
LOG(ERR, "SIGSEGV\n{}", backtrace());
exit(1);
}
void sigill_handler(int) {
LOG(ERR, "SIGILL\n{}", backtrace());
exit(1);
}
void sigabrt_handler(int) {
LOG(ERR, "SIGABRT\n{}", backtrace());
exit(1);
}
}
void showBacktraceOnCrash() {
// the signal handler RAII objects will be initialized on first call (which will register the signal handler)
// and destroyed on program exit (which will unregister the signal handler)
static SignalHandlerRAII<&sigsegv_handler> segv(SIGSEGV);
static SignalHandlerRAII<&sigabrt_handler> abrt(SIGABRT);
static SignalHandlerRAII<&sigill_handler> ill(SIGILL);
}
}
#endif