1 // Copyright Antony Polukhin, 2016-2017.
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)
7 #ifndef BOOST_STACKTRACE_DETAIL_FRAME_DECL_HPP
8 #define BOOST_STACKTRACE_DETAIL_FRAME_DECL_HPP
10 #include <boost/config.hpp>
11 #ifdef BOOST_HAS_PRAGMA_ONCE
18 #include <boost/core/explicit_operator_bool.hpp>
20 #include <boost/stacktrace/safe_dump_to.hpp> // boost::stacktrace::detail::native_frame_ptr_t
21 #include <boost/stacktrace/detail/void_ptr_cast.hpp>
23 #include <boost/stacktrace/detail/push_options.h>
25 /// @file boost/stacktrace/detail/frame_decl.hpp
26 /// Use <boost/stacktrace/frame.hpp> header instead of this one!
28 namespace boost { namespace stacktrace {
30 /// @class boost::stacktrace::frame boost/stacktrace/detail/frame_decl.hpp <boost/stacktrace/frame.hpp>
31 /// @brief Class that stores frame/function address and can get information about it at runtime.
34 typedef boost::stacktrace::detail::native_frame_ptr_t native_frame_ptr_t;
38 native_frame_ptr_t addr_;
42 /// @brief Constructs frame that references NULL address.
43 /// Calls to source_file() and source_line() will return empty string.
44 /// Calls to source_line() will return 0.
46 /// @b Complexity: O(1).
48 /// @b Async-Handler-Safety: Safe.
50 BOOST_CONSTEXPR frame() BOOST_NOEXCEPT
54 #ifdef BOOST_STACKTRACE_DOXYGEN_INVOKED
55 /// @brief Copy constructs frame.
57 /// @b Complexity: O(1).
59 /// @b Async-Handler-Safety: Safe.
61 constexpr frame(const frame&) = default;
63 /// @brief Copy assigns frame.
65 /// @b Complexity: O(1).
67 /// @b Async-Handler-Safety: Safe.
69 constexpr frame& operator=(const frame&) = default;
72 /// @brief Constructs frame that references addr and could later generate information about that address using platform specific features.
74 /// @b Complexity: O(1).
76 /// @b Async-Handler-Safety: Safe.
78 BOOST_CONSTEXPR explicit frame(native_frame_ptr_t addr) BOOST_NOEXCEPT
82 /// @brief Constructs frame that references function_addr and could later generate information about that function using platform specific features.
84 /// @b Complexity: O(1).
86 /// @b Async-Handler-Safety: Safe.
89 explicit frame(T* function_addr) BOOST_NOEXCEPT
90 : addr_(boost::stacktrace::detail::void_ptr_cast<native_frame_ptr_t>(function_addr))
93 /// @returns Name of the frame (function name in a human readable form).
95 /// @b Complexity: unknown (lots of platform specific work).
97 /// @b Async-Handler-Safety: Unsafe.
98 /// @throws std::bad_alloc if not enough memory to construct resulting string.
99 BOOST_STACKTRACE_FUNCTION std::string name() const;
101 /// @returns Address of the frame function.
103 /// @b Complexity: O(1).
105 /// @b Async-Handler-Safety: Safe.
107 BOOST_CONSTEXPR native_frame_ptr_t address() const BOOST_NOEXCEPT {
111 /// @returns Path to the source file, were the function of the frame is defined. Returns empty string
112 /// if this->source_line() == 0.
113 /// @throws std::bad_alloc if not enough memory to construct resulting string.
115 /// @b Complexity: unknown (lots of platform specific work).
117 /// @b Async-Handler-Safety: Unsafe.
118 BOOST_STACKTRACE_FUNCTION std::string source_file() const;
120 /// @returns Code line in the source file, were the function of the frame is defined.
121 /// @throws std::bad_alloc if not enough memory to construct string for internal needs.
123 /// @b Complexity: unknown (lots of platform specific work).
125 /// @b Async-Handler-Safety: Unsafe.
126 BOOST_STACKTRACE_FUNCTION std::size_t source_line() const;
128 /// @brief Checks that frame is not references NULL address.
129 /// @returns `true` if `this->address() != 0`
131 /// @b Complexity: O(1)
133 /// @b Async-Handler-Safety: Safe.
134 BOOST_EXPLICIT_OPERATOR_BOOL()
136 /// @brief Checks that frame references NULL address.
137 /// @returns `true` if `this->address() == 0`
139 /// @b Complexity: O(1)
141 /// @b Async-Handler-Safety: Safe.
142 BOOST_CONSTEXPR bool empty() const BOOST_NOEXCEPT { return !address(); }
145 BOOST_CONSTEXPR bool operator!() const BOOST_NOEXCEPT { return !address(); }
151 BOOST_STACKTRACE_FUNCTION std::string to_string(const frame* frames, std::size_t size);
152 } // namespace detail
154 }} // namespace boost::stacktrace
157 #include <boost/stacktrace/detail/pop_options.h>
159 #endif // BOOST_STACKTRACE_DETAIL_FRAME_DECL_HPP