1// Copyright Antony Polukhin, 2016-2024.
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
13void 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(status: 0);
20}
21//]
22
23
24void my_signal_handler(int /*signum*/) {
25 std::exit(status: 1);
26}
27
28int main() {
29 ::signal(SIGSEGV, handler: &my_signal_handler);
30 print_signal_handler_and_exit();
31}
32
33
34

source code of boost/libs/stacktrace/example/debug_function.cpp