MCPcopy Create free account
hub / github.com/boostorg/stacktrace / dladdr

Function dladdr

include/boost/stacktrace/detail/location_from_symbol.hpp:41–95  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39};
40
41int dladdr(const void* address_raw, Dl_info* info) noexcept {
42 static constexpr std::size_t dl_buff_size = 0x1000;
43
44 try {
45 std::vector<struct ld_info> pld_info_storage;
46 pld_info_storage.resize(
47 (dl_buff_size + sizeof(struct ld_info) - 1) / sizeof(struct ld_info)
48 );
49
50 if (loadquery(L_GETINFO, pld_info_storage.data(), dl_buff_size) == -1) {
51 return 0;
52 }
53
54 const auto* pld_info = pld_info_storage.data();
55 const char* const address = static_cast<const char*>(address_raw);
56 while (true) {
57 const auto* const dataorg = static_cast<char*>(pld_info->ldinfo_dataorg);
58 const auto* const textorg = static_cast<char*>(pld_info->ldinfo_textorg);
59 if ((address >= dataorg && address < dataorg + pld_info->ldinfo_datasize )
60 || (address >= textorg && address < textorg + pld_info->ldinfo_textsize )) {
61
62 /* ldinfo_filename is the null-terminated path name followed
63 by null-terminated member name.
64 If the file is not an archive, then member name is null. */
65 const auto size_filename = std::strlen(pld_info->ldinfo_filename);
66 const auto size_member = std::strlen(pld_info->ldinfo_filename + size_filename + 1);
67
68 /* If member is not null, '(' and ')' must be added to create a
69 fname looking like "filename(membername)". */
70 info->fname_storage.reserve(size_filename + (size_member ? size_member + 3 : 1));
71 info->fname_storage = pld_info->ldinfo_filename;
72 if (size_member) {
73 info->fname_storage += "(";
74 info->fname_storage += pld_info->ldinfo_filename + size_filename + 1;
75 info->fname_storage += ")";
76 }
77
78 info->dli_fname = info->fname_storage.c_str();
79 return 1;
80 }
81
82 if (!pld_info->ldinfo_next) {
83 break;
84 }
85
86 pld_info = reinterpret_cast<const struct ld_info *>(
87 reinterpret_cast<const char*>(pld_info) + pld_info->ldinfo_next
88 );
89 };
90 } catch (...) {
91 // ignore
92 }
93
94 return 0;
95}
96
97}}} // namespace boost::stacktrace::detail
98

Callers 1

location_from_symbolMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected