File indexing completed on 2025-01-30 10:00:50
0001
0002
0003
0004
0005
0006
0007 #ifndef BOOST_STACKTRACE_DETAIL_LOCATION_FROM_SYMBOL_HPP
0008 #define BOOST_STACKTRACE_DETAIL_LOCATION_FROM_SYMBOL_HPP
0009
0010 #include <boost/config.hpp>
0011 #ifdef BOOST_HAS_PRAGMA_ONCE
0012 # pragma once
0013 #endif
0014
0015 #if !defined(BOOST_WINDOWS) && !defined(__CYGWIN__)
0016 # include <dlfcn.h>
0017 #else
0018 # include <boost/winapi/dll.hpp>
0019 #endif
0020
0021 namespace boost { namespace stacktrace { namespace detail {
0022
0023 #if !defined(BOOST_WINDOWS) && !defined(__CYGWIN__)
0024 class location_from_symbol {
0025 ::Dl_info dli_;
0026
0027 public:
0028 explicit location_from_symbol(const void* addr) noexcept
0029 : dli_()
0030 {
0031 if (!::dladdr(const_cast<void*>(addr), &dli_)) {
0032 dli_.dli_fname = 0;
0033 }
0034 }
0035
0036 bool empty() const noexcept {
0037 return !dli_.dli_fname;
0038 }
0039
0040 const char* name() const noexcept {
0041 return dli_.dli_fname;
0042 }
0043 };
0044
0045 class program_location {
0046 public:
0047 const char* name() const noexcept {
0048 return 0;
0049 }
0050 };
0051
0052 #else
0053
0054 class location_from_symbol {
0055 BOOST_STATIC_CONSTEXPR boost::winapi::DWORD_ DEFAULT_PATH_SIZE_ = 260;
0056 char file_name_[DEFAULT_PATH_SIZE_];
0057
0058 public:
0059 explicit location_from_symbol(const void* addr) noexcept {
0060 file_name_[0] = '\0';
0061
0062 boost::winapi::MEMORY_BASIC_INFORMATION_ mbi;
0063 if (!boost::winapi::VirtualQuery(addr, &mbi, sizeof(mbi))) {
0064 return;
0065 }
0066
0067 boost::winapi::HMODULE_ handle = reinterpret_cast<boost::winapi::HMODULE_>(mbi.AllocationBase);
0068 if (!boost::winapi::GetModuleFileNameA(handle, file_name_, DEFAULT_PATH_SIZE_)) {
0069 file_name_[0] = '\0';
0070 return;
0071 }
0072 }
0073
0074 bool empty() const noexcept {
0075 return file_name_[0] == '\0';
0076 }
0077
0078 const char* name() const noexcept {
0079 return file_name_;
0080 }
0081 };
0082
0083 class program_location {
0084 BOOST_STATIC_CONSTEXPR boost::winapi::DWORD_ DEFAULT_PATH_SIZE_ = 260;
0085 char file_name_[DEFAULT_PATH_SIZE_];
0086
0087 public:
0088 program_location() noexcept {
0089 file_name_[0] = '\0';
0090
0091 const boost::winapi::HMODULE_ handle = 0;
0092 if (!boost::winapi::GetModuleFileNameA(handle, file_name_, DEFAULT_PATH_SIZE_)) {
0093 file_name_[0] = '\0';
0094 }
0095 }
0096
0097 const char* name() const noexcept {
0098 return file_name_[0] ? file_name_ : 0;
0099 }
0100 };
0101 #endif
0102
0103 }}}
0104
0105 #endif