Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-18 09:06:28

0001 // Copyright Antony Polukhin, 2016-2025.
0002 //
0003 // Distributed under the Boost Software License, Version 1.0. (See
0004 // accompanying file LICENSE_1_0.txt or copy at
0005 // http://www.boost.org/LICENSE_1_0.txt)
0006 
0007 #ifndef BOOST_STACKTRACE_DETAIL_FRAME_UNWIND_IPP
0008 #define BOOST_STACKTRACE_DETAIL_FRAME_UNWIND_IPP
0009 
0010 #include <boost/config.hpp>
0011 #ifdef BOOST_HAS_PRAGMA_ONCE
0012 #   pragma once
0013 #endif
0014 
0015 #include <boost/stacktrace/frame.hpp>
0016 
0017 #include <boost/stacktrace/detail/to_hex_array.hpp>
0018 #include <boost/stacktrace/detail/location_from_symbol.hpp>
0019 #include <boost/stacktrace/detail/to_dec_array.hpp>
0020 #include <boost/stacktrace/detail/addr_base.hpp>
0021 #include <boost/core/demangle.hpp>
0022 
0023 #include <cstdio>
0024 
0025 #ifdef BOOST_STACKTRACE_USE_BACKTRACE
0026 #   include <boost/stacktrace/detail/libbacktrace_impls.hpp>
0027 #elif defined(BOOST_STACKTRACE_USE_ADDR2LINE)
0028 #   include <boost/stacktrace/detail/addr2line_impls.hpp>
0029 #else
0030 #   include <boost/stacktrace/detail/unwind_base_impls.hpp>
0031 #endif
0032 
0033 namespace boost { namespace stacktrace { namespace detail {
0034 
0035 template <class Base>
0036 class to_string_impl_base: private Base {
0037 public:
0038     std::string operator()(boost::stacktrace::detail::native_frame_ptr_t addr) {
0039         Base::res.clear();
0040         Base::prepare_function_name(addr);
0041         if (!Base::res.empty()) {
0042             Base::res = boost::core::demangle(Base::res.c_str());
0043         } else {
0044 #ifdef BOOST_STACKTRACE_DISABLE_OFFSET_ADDR_BASE
0045             Base::res = to_hex_array(addr).data();
0046 #else
0047             const auto addr_base = boost::stacktrace::detail::get_own_proc_addr_base(addr);
0048             Base::res = to_hex_array(reinterpret_cast<uintptr_t>(addr) - addr_base).data();
0049 #endif
0050         }
0051 
0052         if (Base::prepare_source_location(addr)) {
0053             return Base::res;
0054         }
0055 
0056         boost::stacktrace::detail::location_from_symbol loc(addr);
0057         if (!loc.empty()) {
0058             Base::res += " in ";
0059             Base::res += loc.name();
0060         }
0061 
0062         return Base::res;
0063     }
0064 };
0065 
0066 std::string to_string(const frame* frames, std::size_t size) {
0067     std::string res;
0068     if (size == 0) {
0069         return res;
0070     }
0071     res.reserve(64 * size);
0072 
0073     to_string_impl impl;
0074 
0075     for (std::size_t i = 0; i < size; ++i) {
0076         if (i < 10) {
0077             res += ' ';
0078         }
0079         res += boost::stacktrace::detail::to_dec_array(i).data();
0080         res += '#';
0081         res += ' ';
0082         res += impl(frames[i].address());
0083         res += '\n';
0084     }
0085 
0086     return res;
0087 }
0088 
0089 
0090 } // namespace detail
0091 
0092 
0093 std::string frame::name() const {
0094     if (!addr_) {
0095         return std::string();
0096     }
0097 
0098 #if !defined(BOOST_WINDOWS) && !defined(__CYGWIN__)
0099     boost::stacktrace::detail::Dl_info dli;
0100     const bool dl_ok = !!boost::stacktrace::detail::dladdr(addr_, dli);
0101     if (dl_ok && dli.dli_sname) {
0102         return boost::core::demangle(dli.dli_sname);
0103     }
0104 #endif
0105     return boost::stacktrace::detail::name_impl(addr_);
0106 }
0107 
0108 std::string to_string(const frame& f) {
0109     if (!f) {
0110         return std::string();
0111     }
0112 
0113     boost::stacktrace::detail::to_string_impl impl;
0114     return impl(f.address());
0115 }
0116 
0117 
0118 }} // namespace boost::stacktrace
0119 
0120 #endif // BOOST_STACKTRACE_DETAIL_FRAME_UNWIND_IPP