17#include "llvm/Support/DJB.h"
22using namespace llvm::dwarf;
29 llvm::DataExtractor llvm_debug_str = debug_str.
GetAsLLVM();
31 auto apple_names_table_up = std::make_unique<llvm::AppleAcceleratorTable>(
34 auto apple_namespaces_table_up =
35 std::make_unique<llvm::AppleAcceleratorTable>(
38 auto apple_types_table_up = std::make_unique<llvm::AppleAcceleratorTable>(
41 auto apple_objc_table_up = std::make_unique<llvm::AppleAcceleratorTable>(
44 auto extract_and_check = [](
auto &TablePtr) {
45 if (
auto E = TablePtr->extract()) {
46 llvm::consumeError(std::move(E));
51 extract_and_check(apple_names_table_up);
52 extract_and_check(apple_namespaces_table_up);
53 extract_and_check(apple_types_table_up);
54 extract_and_check(apple_objc_table_up);
61 if (apple_names_table_up || apple_namespaces_table_up ||
62 apple_types_table_up || apple_objc_table_up)
63 return std::make_unique<AppleDWARFIndex>(
64 module, std::move(apple_names_table_up),
65 std::move(apple_namespaces_table_up), std::move(apple_types_table_up),
75 return tag == DW_TAG_class_type || tag == DW_TAG_structure_type;
82 uint32_t expected_hash) {
83 std::optional<llvm::DWARFFormValue> form_value =
84 entry.lookup(llvm::dwarf::DW_ATOM_qual_name_hash);
87 std::optional<uint64_t> hash = form_value->getAsUnsignedConstant();
88 return hash && (*hash == expected_hash);
96 std::optional<llvm::DWARFFormValue> form_value =
97 entry.lookup(llvm::dwarf::DW_ATOM_die_tag);
100 std::optional<uint64_t> maybe_tag = form_value->getAsUnsignedConstant();
103 auto tag =
static_cast<dw_tag_t>(*maybe_tag);
104 return tag == expected_tag ||
112 std::optional<llvm::DWARFFormValue> form_value =
113 entry.lookup(llvm::dwarf::DW_ATOM_type_flags);
116 std::optional<uint64_t>
Flags = form_value->getAsUnsignedConstant();
118 (*
Flags & llvm::dwarf::AcceleratorTable::DW_FLAG_type_implementation);
122 const llvm::AppleAcceleratorTable &table, llvm::StringRef name,
124 std::optional<dw_tag_t> search_for_tag,
125 std::optional<uint32_t> search_for_qualhash) {
127 for (
const auto &entry : table.equal_range(name)) {
128 if (search_for_qualhash &&
155 if (std::optional<llvm::StringRef> name = entry.readName();
169 auto is_in_range = [lower_bound, upper_bound](std::optional<uint32_t> val) {
170 return val.has_value() && *val >= lower_bound && *val < upper_bound;
175 if (is_in_range(entry.BaseEntry.getDIESectionOffset()))
190 ConstString class_name,
bool must_be_implementation,
195 llvm::SmallVector<DIERef> decl_dies;
205 *entry.getDIESectionOffset());
208 if (must_be_implementation)
210 for (
DIERef ref : decl_dies)
230 const bool entries_have_tag =
232 const bool entries_have_qual_hash =
235 llvm::StringRef expected_name = context[0].name;
237 if (entries_have_tag && entries_have_qual_hash) {
238 const dw_tag_t expected_tag = context[0].tag;
239 const uint32_t expected_qualname_hash =
242 m_module.LogMessage(log,
"FindByNameAndTagAndQualifiedNameHash()");
244 expected_qualname_hash);
249 if (!entries_have_tag) {
267 m_module.LogMessage(log,
"FindByNameAndTag()");
268 const dw_tag_t expected_tag = context[0].tag;
290 *entry.getDIESectionOffset());
312 s.
PutCString(
".apple_namespaces index present\n");
static bool HasImplementationFlag(const llvm::AppleAcceleratorTable::Entry &entry)
Returns true if entry has an extractable DW_ATOM_type_flags and the flag "DW_FLAG_type_implementation...
static bool IsClassOrStruct(dw_tag_t tag)
Returns true if tag is a class_type of structure_type tag.
static bool EntryHasMatchingQualhash(const llvm::AppleAcceleratorTable::Entry &entry, uint32_t expected_hash)
Returns true if entry has an extractable DW_ATOM_qual_name_hash and it matches expected_hash.
static bool EntryHasMatchingTag(const llvm::AppleAcceleratorTable::Entry &entry, dw_tag_t expected_tag)
Returns true if entry has an extractable DW_ATOM_die_tag and it matches expected_tag.
Represents a generic declaration context in a program.
A uniqued constant string class.
A class that handles mangled names.
bool NameMatches(ConstString name) const
Check if "name" matches either the mangled or demangled name.
A class that encapsulates name lookup information.
ConstString GetLookupName() const
A class that describes an executable image and its associated object and symbol files.
llvm::StringRef GetText() const
Access the regular expression text.
A stream class that can stream formatted output to a file.
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
std::unique_ptr< llvm::AppleAcceleratorTable > m_apple_types_up
void SearchFor(const llvm::AppleAcceleratorTable &table, llvm::StringRef name, llvm::function_ref< IterationAction(DWARFDIE die)> callback, std::optional< dw_tag_t > search_for_tag=std::nullopt, std::optional< uint32_t > search_for_qualhash=std::nullopt)
}
static std::unique_ptr< AppleDWARFIndex > Create(Module &module, DWARFDataExtractor apple_names, DWARFDataExtractor apple_namespaces, DWARFDataExtractor apple_types, DWARFDataExtractor apple_objc, DWARFDataExtractor debug_str)
void GetNamespaces(ConstString name, llvm::function_ref< IterationAction(DWARFDIE die)> callback) override
void GetTypes(ConstString name, llvm::function_ref< IterationAction(DWARFDIE die)> callback) override
std::unique_ptr< llvm::AppleAcceleratorTable > m_apple_names_up
void GetCompleteObjCClass(ConstString class_name, bool must_be_implementation, llvm::function_ref< IterationAction(DWARFDIE die)> callback) override
void GetObjCMethods(ConstString class_name, llvm::function_ref< IterationAction(DWARFDIE die)> callback) override
void GetFunctions(const Module::LookupInfo &lookup_info, SymbolFileDWARF &dwarf, const CompilerDeclContext &parent_decl_ctx, llvm::function_ref< IterationAction(DWARFDIE die)> callback) override
std::unique_ptr< llvm::AppleAcceleratorTable > m_apple_namespaces_up
void Dump(Stream &s) override
std::unique_ptr< llvm::AppleAcceleratorTable > m_apple_objc_up
void GetGlobalVariables(ConstString basename, llvm::function_ref< IterationAction(DWARFDIE die)> callback) override
Finds global variables with the given base name.
Identifies a DWARF debug info entry within a given Module.
const char * GetQualifiedName() const
IterationAction ProcessFunctionDIE(const Module::LookupInfo &lookup_info, DWARFDIE die, const CompilerDeclContext &parent_decl_ctx, llvm::function_ref< IterationAction(DWARFDIE die)> callback)
Helper function implementing common logic for processing function dies.
DIERefCallbackImpl DIERefCallback(llvm::function_ref< IterationAction(DWARFDIE die)> callback, llvm::StringRef name={}) const
void ReportInvalidDIERef(DIERef ref, llvm::StringRef name) const
dw_offset_t GetOffset() const
dw_offset_t GetNextUnitOffset() const
DWARFUnit & GetNonSkeletonUnit()
llvm::dwarf::Tag dw_tag_t
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
IterationAction
Useful for callbacks whose return type indicates whether to continue iteration or short-circuit.