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#include <boost/config.hpp>
8
9#ifdef BOOST_NO_CXX11_RANGE_BASED_FOR
10#include <boost/stacktrace.hpp>
11#include <iostream> // std::cout
12
13namespace bs = boost::stacktrace;
14void dump_compact(const bs::stacktrace& st) {
15 for (unsigned i = 0; i < st.size(); ++i) {
16 bs::frame frame = st[i];
17 std::cout << frame.address() << ',';
18 }
19
20 std::cout << std::endl;
21}
22#else
23//[getting_started_trace_addresses
24#include <boost/stacktrace.hpp>
25#include <iostream> // std::cout
26
27namespace bs = boost::stacktrace;
28void dump_compact(const bs::stacktrace& st) {
29 for (bs::frame frame: st) {
30 std::cout << frame.address() << ',';
31 }
32
33 std::cout << std::endl;
34}
35//]
36#endif
37
38BOOST_NOINLINE boost::stacktrace::stacktrace rec1(int i);
39BOOST_NOINLINE boost::stacktrace::stacktrace rec2(int i);
40
41BOOST_NOINLINE boost::stacktrace::stacktrace rec1(int i) {
42 if (i < 5) {
43 if (!i) return boost::stacktrace::stacktrace();
44 return rec2(i: --i);
45 }
46
47 return rec2(i: i - 2);
48}
49
50BOOST_NOINLINE boost::stacktrace::stacktrace rec2(int i) {
51 if (i < 5) {
52 if (!i) return boost::stacktrace::stacktrace();
53 return rec2(i: --i);
54 }
55
56 return rec2(i: i - 2);
57}
58
59int main() {
60 dump_compact(st: rec1(i: 8));
61}
62
63
64

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