frame.hpp 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // Copyright Antony Polukhin, 2016-2025.
  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. #ifndef BOOST_STACKTRACE_FRAME_HPP
  7. #define BOOST_STACKTRACE_FRAME_HPP
  8. #include <boost/config.hpp>
  9. #ifdef BOOST_HAS_PRAGMA_ONCE
  10. # pragma once
  11. #endif
  12. #include <iosfwd>
  13. #include <string>
  14. #include <boost/stacktrace/safe_dump_to.hpp> // boost::stacktrace::detail::native_frame_ptr_t
  15. #include <boost/stacktrace/detail/frame_decl.hpp>
  16. #include <boost/stacktrace/detail/push_options.h>
  17. #if defined(BOOST_MSVC) && (defined(BOOST_STACKTRACE_INTERNAL_BUILD_LIBS) || !defined(BOOST_STACKTRACE_LINK))
  18. extern "C" {
  19. #if defined(BOOST_STACKTRACE_DYN_LINK)
  20. BOOST_SYMBOL_EXPORT
  21. #elif defined(BOOST_STACKTRACE_LINK)
  22. #else
  23. BOOST_SYMBOL_EXPORT inline
  24. #endif
  25. void* boost_stacktrace_impl_return_nullptr() { return nullptr; }
  26. }
  27. #endif
  28. namespace boost { namespace stacktrace {
  29. /// Comparison operators that provide platform dependant ordering and have O(1) complexity; are Async-Handler-Safe.
  30. constexpr inline bool operator< (const frame& lhs, const frame& rhs) noexcept { return lhs.address() < rhs.address(); }
  31. constexpr inline bool operator> (const frame& lhs, const frame& rhs) noexcept { return rhs < lhs; }
  32. constexpr inline bool operator<=(const frame& lhs, const frame& rhs) noexcept { return !(lhs > rhs); }
  33. constexpr inline bool operator>=(const frame& lhs, const frame& rhs) noexcept { return !(lhs < rhs); }
  34. constexpr inline bool operator==(const frame& lhs, const frame& rhs) noexcept { return lhs.address() == rhs.address(); }
  35. constexpr inline bool operator!=(const frame& lhs, const frame& rhs) noexcept { return !(lhs == rhs); }
  36. /// Fast hashing support, O(1) complexity; Async-Handler-Safe.
  37. inline std::size_t hash_value(const frame& f) noexcept {
  38. return reinterpret_cast<std::size_t>(f.address());
  39. }
  40. /// Outputs stacktrace::frame in a human readable format to string; unsafe to use in async handlers.
  41. BOOST_STACKTRACE_FUNCTION std::string to_string(const frame& f);
  42. /// Outputs stacktrace::frame in a human readable format to output stream; unsafe to use in async handlers.
  43. template <class CharT, class TraitsT>
  44. std::basic_ostream<CharT, TraitsT>& operator<<(std::basic_ostream<CharT, TraitsT>& os, const frame& f) {
  45. return os << boost::stacktrace::to_string(f);
  46. }
  47. }} // namespace boost::stacktrace
  48. /// @cond
  49. #include <boost/stacktrace/detail/pop_options.h>
  50. #ifndef BOOST_STACKTRACE_LINK
  51. # if defined(BOOST_STACKTRACE_USE_NOOP)
  52. # include <boost/stacktrace/detail/frame_noop.ipp>
  53. # elif defined(BOOST_MSVC) || defined(BOOST_STACKTRACE_USE_WINDBG) || defined(BOOST_STACKTRACE_USE_WINDBG_CACHED)
  54. # include <boost/stacktrace/detail/frame_msvc.ipp>
  55. # else
  56. # include <boost/stacktrace/detail/frame_unwind.ipp>
  57. # endif
  58. #endif
  59. /// @endcond
  60. #endif // BOOST_STACKTRACE_FRAME_HPP