LLDB mainline
MachOTrie.h
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLDB_SOURCE_PLUGINS_OBJECTFILE_MACH_O_MACHOTRIE_H
10#define LLDB_SOURCE_PLUGINS_OBJECTFILE_MACH_O_MACHOTRIE_H
11
13#include "lldb/lldb-defines.h"
14#include "lldb/lldb-types.h"
15
16#include <cstdint>
17#include <set>
18#include <string>
19#include <vector>
20
21namespace lldb_private {
22
23class DataExtractor;
24
25/// Set on TrieEntry::flags for an ARM symbol whose address has the low Thumb
26/// bit set; the bit is stripped from the address and recorded here instead.
27inline constexpr uint64_t TRIE_SYMBOL_IS_THUMB = 1ULL << 63;
28
29/// Mask that clears the low Thumb bit from an ARM function address.
30inline constexpr uint64_t THUMB_ADDRESS_BIT_MASK = 0xfffffffffffffffeull;
31
32/// A single symbol recovered from the Mach-O export trie.
33struct TrieEntry {
34 void Dump() const;
35
38 uint64_t flags =
39 0; // EXPORT_SYMBOL_FLAGS_REEXPORT, EXPORT_SYMBOL_FLAGS_STUB_AND_RESOLVER,
40 // TRIE_SYMBOL_IS_THUMB
41 uint64_t other = 0;
43};
44
45/// A TrieEntry paired with the offset of the trie node it was parsed from.
49
51
52 void Dump(uint32_t idx) const;
53
54 bool operator<(const TrieEntryWithOffset &other) const {
55 return (nodeOffset < other.nodeOffset);
56 }
57};
58
59/// Parse the Mach-O export trie (the dyld symbol trie from LC_DYLD_INFO or
60/// LC_DYLD_EXPORTS_TRIE) starting at \a offset in \a data, collecting exported
61/// and re-exported symbols and any stub resolver addresses.
62///
63/// \param[in] data The buffer holding the raw export trie.
64/// \param[in] is_arm Whether the image is ARM, which governs Thumb-bit
65/// handling.
66/// \param[in] text_seg_base_addr The __TEXT segment file address added to each
67/// symbol address, or LLDB_INVALID_ADDRESS to leave addresses unbiased.
68/// \param[out] resolver_addresses Stub-and-resolver addresses encountered.
69/// \param[out] reexports Re-export entries with a valid import name.
70/// \param[out] ext_symbols Externally visible (non-re-export) entries.
71///
72/// \return false if the trie is detectably corrupt, true otherwise.
73bool ParseTrieEntries(DataExtractor &data, const bool is_arm,
74 lldb::addr_t text_seg_base_addr,
75 std::set<lldb::addr_t> &resolver_addresses,
76 std::vector<TrieEntryWithOffset> &reexports,
77 std::vector<TrieEntryWithOffset> &ext_symbols);
78
79} // namespace lldb_private
80
81#endif // LLDB_SOURCE_PLUGINS_OBJECTFILE_MACH_O_MACHOTRIE_H
A uniqued constant string class.
Definition ConstString.h:40
An data extractor class.
#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.
Definition MachOTrie.h:30
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...
Definition MachOTrie.h:27
uint64_t offset_t
Definition lldb-types.h:85
uint64_t addr_t
Definition lldb-types.h:80
TrieEntryWithOffset(lldb::offset_t offset)
Definition MachOTrie.h:50
bool operator<(const TrieEntryWithOffset &other) const
Definition MachOTrie.h:54
void Dump(uint32_t idx) const
Definition MachOTrie.cpp:42
A single symbol recovered from the Mach-O export trie.
Definition MachOTrie.h:33
ConstString import_name
Definition MachOTrie.h:42