| 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 | |
| 13 | namespace bs = boost::stacktrace; |
| 14 | void 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 | |
| 27 | namespace bs = boost::stacktrace; |
| 28 | void 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 | |
| 38 | BOOST_NOINLINE boost::stacktrace::stacktrace rec1(int i); |
| 39 | BOOST_NOINLINE boost::stacktrace::stacktrace rec2(int i); |
| 40 | |
| 41 | BOOST_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 | |
| 50 | BOOST_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 | |
| 59 | int main() { |
| 60 | dump_compact(st: rec1(i: 8)); |
| 61 | } |
| 62 | |
| 63 | |
| 64 |
