| 1 | // Copyright Antony Polukhin, 2023-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 | #ifndef BOOST_STACKTRACE_THIS_THREAD_HPP |
| 8 | #define BOOST_STACKTRACE_THIS_THREAD_HPP |
| 9 | |
| 10 | #include <boost/config.hpp> |
| 11 | #ifdef BOOST_HAS_PRAGMA_ONCE |
| 12 | # pragma once |
| 13 | #endif |
| 14 | |
| 15 | #include <boost/stacktrace/stacktrace.hpp> |
| 16 | |
| 17 | namespace boost { namespace stacktrace { namespace this_thread { |
| 18 | |
| 19 | /// @brief Invoking the function with the enable parameter equal to `true` |
| 20 | /// enables capturing of stacktraces by the current thread of execution at |
| 21 | /// exception object construction if the `boost_stacktrace_from_exception` |
| 22 | /// library is linked to the current binary; disables otherwise. |
| 23 | /// |
| 24 | /// Implements https://wg21.link/p2370r1 |
| 25 | inline void set_capture_stacktraces_at_throw(bool enable = true) noexcept { |
| 26 | #if defined(__GNUC__) && defined(__ELF__) |
| 27 | if (impl::ref_capture_stacktraces_at_throw) { |
| 28 | impl::ref_capture_stacktraces_at_throw() = enable; |
| 29 | } |
| 30 | #endif |
| 31 | (void)enable; |
| 32 | } |
| 33 | |
| 34 | /// @return whether the capturing of stacktraces by the current thread of |
| 35 | /// execution is enabled and |
| 36 | /// boost::stacktrace::basic_stacktrace::from_current_exception may return a |
| 37 | /// non empty stacktrace. |
| 38 | /// |
| 39 | /// Returns true if set_capture_stacktraces_at_throw(false) was not called |
| 40 | /// and the `boost_stacktrace_from_exception` is linked to the current binary. |
| 41 | /// |
| 42 | /// Implements https://wg21.link/p2370r1 |
| 43 | inline bool get_capture_stacktraces_at_throw() noexcept { |
| 44 | #if defined(__GNUC__) && defined(__ELF__) |
| 45 | if (impl::ref_capture_stacktraces_at_throw) { |
| 46 | return impl::ref_capture_stacktraces_at_throw(); |
| 47 | } |
| 48 | #endif |
| 49 | return false; |
| 50 | } |
| 51 | |
| 52 | }}} // namespace boost::stacktrace::this_thread |
| 53 | |
| 54 | #endif // BOOST_STACKTRACE_THIS_THREAD_HPP |
| 55 | |