summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/stacktrace/example/trace_addresses.cpp
blob: 0ad30a5b38c98fa31eee9fd6aa6fc8391a1f1633 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright Antony Polukhin, 2016-2019.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

#include <boost/config.hpp>

#ifdef BOOST_NO_CXX11_RANGE_BASED_FOR
#include <boost/stacktrace.hpp>
#include <iostream>     // std::cout

namespace bs = boost::stacktrace;
void dump_compact(const bs::stacktrace& st) {
    for (unsigned i = 0; i < st.size(); ++i) {
        bs::frame frame = st[i];
        std::cout << frame.address() << ',';
    }

    std::cout << std::endl;
}
#else
//[getting_started_trace_addresses
#include <boost/stacktrace.hpp>
#include <iostream>     // std::cout

namespace bs = boost::stacktrace;
void dump_compact(const bs::stacktrace& st) {
    for (bs::frame frame: st) {
        std::cout << frame.address() << ',';
    }

    std::cout << std::endl;
}
//]
#endif

BOOST_NOINLINE boost::stacktrace::stacktrace rec1(int i);
BOOST_NOINLINE boost::stacktrace::stacktrace rec2(int i);

BOOST_NOINLINE boost::stacktrace::stacktrace rec1(int i) {
    if (i < 5) {
        if (!i) return boost::stacktrace::stacktrace();
        return rec2(--i);
    }

    return rec2(i - 2);
}

BOOST_NOINLINE boost::stacktrace::stacktrace rec2(int i) {
    if (i < 5) {
        if (!i) return boost::stacktrace::stacktrace();
        return rec2(--i);
    }

    return rec2(i - 2);
}

int main() {
    dump_compact(rec1(8));
}