BitShares-Core  4.0.0
BitShares blockchain implementation and command-line interface software
stacktrace.cpp
Go to the documentation of this file.
1 //
2 // A stacktrace handler for bitshares
3 //
4 #include <ostream>
5 #include <boost/version.hpp>
6 
7 // only include stacktrace stuff if boost >= 1.65 and not macOS
8 #if BOOST_VERSION / 100 >= 1065 && !defined(__APPLE__)
9 #include <signal.h>
10 #include <fc/log/logger.hpp>
11 #if defined(__OpenBSD__)
12  #define BOOST_STACKTRACE_GNU_SOURCE_NOT_REQUIRED
13 #endif
14 #include <boost/stacktrace.hpp>
15 
16 namespace fc
17 {
18 
19 static void segfault_signal_handler(int signum)
20 {
21  ::signal(signum, SIG_DFL);
22  std::stringstream ss;
23  ss << boost::stacktrace::stacktrace();
24  elog(ss.str());
25  ::raise(SIGABRT);
26 }
27 
29 {
30  ::signal(SIGSEGV, &segfault_signal_handler);
31 }
32 
33 void print_stacktrace(std::ostream& out)
34 {
35  out << boost::stacktrace::stacktrace();
36 }
37 
38 }
39 #else
40 // Stacktrace output requires Boost 1.65 or above.
41 // Therefore calls to these methods do nothing.
42 namespace fc
43 {
45 void print_stacktrace(std::ostream& out) {}
46 }
47 
48 #endif
#define elog(FORMAT,...)
Definition: logger.hpp:129
void print_stacktrace(std::ostream &out)
Definition: stacktrace.cpp:45
void print_stacktrace_on_segfault()
Definition: stacktrace.cpp:44
Definition: api.hpp:15
boost::signals2::signal< T > signal
Definition: signals.hpp:20