BitShares-Core  5.0.0
BitShares blockchain implementation and command-line interface software
stacktrace.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-2019 BitShares Blockchain Foundation, and contributors.
3  *
4  * The MIT License
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  */
24 
25 #include <ostream>
26 #include <boost/version.hpp>
27 
28 // only include stacktrace stuff if boost >= 1.65 and not macOS
29 #if BOOST_VERSION / 100 >= 1065 && !defined(__APPLE__)
30 #include <signal.h>
31 #include <fc/log/logger.hpp>
32 #if defined(__OpenBSD__)
33  #define BOOST_STACKTRACE_GNU_SOURCE_NOT_REQUIRED
34 #endif
35 #include <boost/stacktrace.hpp>
36 
37 namespace fc
38 {
39 
40 static void segfault_signal_handler(int signum)
41 {
42  ::signal(signum, SIG_DFL);
43  std::stringstream ss;
44  ss << boost::stacktrace::stacktrace();
45  elog(ss.str());
46  ::raise(SIGABRT);
47 }
48 
50 {
51  ::signal(SIGSEGV, &segfault_signal_handler);
52 }
53 
54 void print_stacktrace(std::ostream& out)
55 {
56  out << boost::stacktrace::stacktrace();
57 }
58 
59 }
60 #else
61 // Stacktrace output requires Boost 1.65 or above.
62 // Therefore calls to these methods do nothing.
63 namespace fc
64 {
66 void print_stacktrace(std::ostream& out) {}
67 }
68 
69 #endif
#define elog(FORMAT,...)
Definition: logger.hpp:129
void print_stacktrace(std::ostream &out)
Definition: stacktrace.cpp:66
void print_stacktrace_on_segfault()
Definition: stacktrace.cpp:65
Definition: api.hpp:15
boost::signals2::signal< T > signal
Definition: signals.hpp:20