14#include "llvm/ADT/StringRef.h"
15#include "llvm/BinaryFormat/MachO.h"
21using namespace llvm::MachO;
32 printf(
"0x%16.16llx 0x%16.16llx 0x%16.16llx \"%s\"",
33 static_cast<unsigned long long>(
address),
34 static_cast<unsigned long long>(
flags),
35 static_cast<unsigned long long>(
other),
name.GetCString());
43 printf(
"[%3u] 0x%16.16llx: ", idx,
51 const bool is_arm,
addr_t text_seg_base_addr,
53 std::set<lldb::addr_t> &resolver_addresses,
54 std::vector<TrieEntryWithOffset> &reexports,
55 std::vector<TrieEntryWithOffset> &ext_symbols,
56 std::set<lldb::offset_t> &visited_nodes) {
62 if (!visited_nodes.insert(offset).second)
67 const uint64_t terminalSize = data.
GetULEB128(&offset);
69 if (terminalSize != 0) {
72 const char *import_name =
nullptr;
73 if (e.entry.flags & EXPORT_SYMBOL_FLAGS_REEXPORT) {
76 import_name = data.
GetCStr(&offset);
80 e.entry.address += text_seg_base_addr;
81 if (e.entry.flags & EXPORT_SYMBOL_FLAGS_STUB_AND_RESOLVER) {
83 uint64_t resolver_addr = e.entry.other;
85 resolver_addr += text_seg_base_addr;
88 resolver_addresses.insert(resolver_addr);
92 bool add_this_entry =
false;
93 if (
Flags(e.entry.flags).
Test(EXPORT_SYMBOL_FLAGS_REEXPORT) &&
94 import_name && import_name[0]) {
96 add_this_entry =
true;
97 }
else if (e.entry.flags == 0 &&
98 (import_name ==
nullptr || import_name[0] ==
'\0')) {
101 add_this_entry =
true;
103 if (add_this_entry) {
104 if (prefix.size() > 1) {
106 e.entry.name.SetString(llvm::StringRef(prefix).drop_front());
110 e.entry.import_name.SetCString(import_name + 1);
112 if (
Flags(e.entry.flags).
Test(EXPORT_SYMBOL_FLAGS_REEXPORT)) {
113 reexports.push_back(e);
115 if (is_arm && (e.entry.address & 1)) {
119 ext_symbols.push_back(e);
124 const uint8_t childrenCount = data.
GetU8(&children_offset);
125 for (uint8_t i = 0; i < childrenCount; ++i) {
126 const char *cstr = data.
GetCStr(&children_offset);
131 const size_t prevSize = prefix.size();
136 if (!ParseTrieEntriesImpl(data, childNodeOffset, is_arm, text_seg_base_addr,
137 prefix, resolver_addresses, reexports,
138 ext_symbols, visited_nodes))
140 prefix.resize(prevSize);
149 std::set<lldb::addr_t> &resolver_addresses,
150 std::vector<TrieEntryWithOffset> &reexports,
151 std::vector<TrieEntryWithOffset> &ext_symbols) {
153 std::set<lldb::offset_t> visited_nodes;
155 return ParseTrieEntriesImpl(data, offset, is_arm, text_seg_base_addr, prefix,
156 resolver_addresses, reexports, ext_symbols,
static constexpr size_t kMaxTrieSymbolNameLength
Upper bound on the length of a symbol name assembled from export-trie edge labels.
bool Test(ValueType bit) const
Test a single flag bit.
#define LLDB_INVALID_ADDRESS
A class that represents a running process on the host machine.
constexpr uint64_t THUMB_ADDRESS_BIT_MASK
Mask that clears the low Thumb bit from an ARM function address.
bool ParseTrieEntries(DataExtractor &data, const bool is_arm, lldb::addr_t text_seg_base_addr, std::set< lldb::addr_t > &resolver_addresses, std::vector< TrieEntryWithOffset > &reexports, std::vector< TrieEntryWithOffset > &ext_symbols)
Parse the Mach-O export trie (the dyld symbol trie from LC_DYLD_INFO or LC_DYLD_EXPORTS_TRIE) startin...
constexpr uint64_t TRIE_SYMBOL_IS_THUMB
Set on TrieEntry::flags for an ARM symbol whose address has the low Thumb bit set; the bit is strippe...
A TrieEntry paired with the offset of the trie node it was parsed from.
lldb::offset_t nodeOffset
void Dump(uint32_t idx) const