• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright Antony Polukhin, 2016-2020.
2 //
3 // Distributed under the Boost Software License, Version 1.0. (See
4 // accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
6 
7 //[getting_started_debug_function
8 #include <signal.h>     // ::signal
9 #include <boost/stacktrace/frame.hpp>
10 #include <iostream>     // std::cerr
11 #include <cstdlib>      // std::exit
12 
print_signal_handler_and_exit()13 void print_signal_handler_and_exit() {
14     typedef void(*function_t)(int);
15 
16     function_t old_signal_function = ::signal(SIGSEGV, SIG_DFL);
17     boost::stacktrace::frame f(old_signal_function);
18     std::cout << f << std::endl;
19     std::exit(0);
20 }
21 //]
22 
23 
my_signal_handler(int)24 void my_signal_handler(int /*signum*/) {
25     std::exit(1);
26 }
27 
main()28 int main() {
29     ::signal(SIGSEGV, &my_signal_handler);
30     print_signal_handler_and_exit();
31 }
32 
33 
34