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_LOCATION_FROM_SYMBOL_HPP
8 #define BOOST_STACKTRACE_DETAIL_LOCATION_FROM_SYMBOL_HPP
10 #include <boost/config.hpp>
11 #ifdef BOOST_HAS_PRAGMA_ONCE
15 #if !defined(BOOST_WINDOWS) && !defined(__CYGWIN__)
18 # include <boost/detail/winapi/dll.hpp>
21 namespace boost { namespace stacktrace { namespace detail {
23 #if !defined(BOOST_WINDOWS) && !defined(__CYGWIN__)
24 class location_from_symbol {
28 explicit location_from_symbol(const void* addr) BOOST_NOEXCEPT
31 if (!::dladdr(addr, &dli_)) {
36 bool empty() const BOOST_NOEXCEPT {
37 return !dli_.dli_fname;
40 const char* name() const BOOST_NOEXCEPT {
41 return dli_.dli_fname;
45 class program_location {
47 const char* name() const BOOST_NOEXCEPT {
54 class location_from_symbol {
55 BOOST_STATIC_CONSTEXPR boost::detail::winapi::DWORD_ DEFAULT_PATH_SIZE_ = 260;
56 char file_name_[DEFAULT_PATH_SIZE_];
59 explicit location_from_symbol(const void* addr) BOOST_NOEXCEPT {
62 boost::detail::winapi::MEMORY_BASIC_INFORMATION_ mbi;
63 if (!boost::detail::winapi::VirtualQuery(addr, &mbi, sizeof(mbi))) {
67 boost::detail::winapi::HMODULE_ handle = reinterpret_cast<boost::detail::winapi::HMODULE_>(mbi.AllocationBase);
68 if (!boost::detail::winapi::GetModuleFileNameA(handle, file_name_, DEFAULT_PATH_SIZE_)) {
74 bool empty() const BOOST_NOEXCEPT {
75 return file_name_[0] == '\0';
78 const char* name() const BOOST_NOEXCEPT {
83 class program_location {
84 BOOST_STATIC_CONSTEXPR boost::detail::winapi::DWORD_ DEFAULT_PATH_SIZE_ = 260;
85 char file_name_[DEFAULT_PATH_SIZE_];
88 program_location() BOOST_NOEXCEPT {
91 const boost::detail::winapi::HMODULE_ handle = 0;
92 if (!boost::detail::winapi::GetModuleFileNameA(handle, file_name_, DEFAULT_PATH_SIZE_)) {
97 const char* name() const BOOST_NOEXCEPT {
98 return file_name_[0] ? file_name_ : 0;
103 }}} // namespace boost::stacktrace::detail
105 #endif // BOOST_STACKTRACE_DETAIL_LOCATION_FROM_SYMBOL_HPP