1 | //===-- DebugNamesDWARFIndex.h ---------------------------------*- C++ -*-===// |
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_SYMBOLFILE_DWARF_DEBUGNAMESDWARFINDEX_H |
10 | #define LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DEBUGNAMESDWARFINDEX_H |
11 | |
12 | #include "Plugins/SymbolFile/DWARF/DWARFIndex.h" |
13 | #include "Plugins/SymbolFile/DWARF/LogChannelDWARF.h" |
14 | #include "Plugins/SymbolFile/DWARF/ManualDWARFIndex.h" |
15 | #include "Plugins/SymbolFile/DWARF/SymbolFileDWARF.h" |
16 | #include "lldb/Utility/ConstString.h" |
17 | #include "llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h" |
18 | #include <optional> |
19 | |
20 | namespace lldb_private::plugin { |
21 | namespace dwarf { |
22 | class DebugNamesDWARFIndex : public DWARFIndex { |
23 | public: |
24 | static llvm::Expected<std::unique_ptr<DebugNamesDWARFIndex>> |
25 | (Module &module, DWARFDataExtractor debug_names, |
26 | DWARFDataExtractor debug_str, SymbolFileDWARF &dwarf); |
27 | |
28 | void Preload() override { m_fallback.Preload(); } |
29 | |
30 | void |
31 | GetGlobalVariables(ConstString basename, |
32 | llvm::function_ref<bool(DWARFDIE die)> callback) override; |
33 | void |
34 | GetGlobalVariables(const RegularExpression ®ex, |
35 | llvm::function_ref<bool(DWARFDIE die)> callback) override; |
36 | void |
37 | GetGlobalVariables(DWARFUnit &cu, |
38 | llvm::function_ref<bool(DWARFDIE die)> callback) override; |
39 | void |
40 | GetObjCMethods(ConstString class_name, |
41 | llvm::function_ref<bool(DWARFDIE die)> callback) override {} |
42 | void GetCompleteObjCClass( |
43 | ConstString class_name, bool must_be_implementation, |
44 | llvm::function_ref<bool(DWARFDIE die)> callback) override; |
45 | |
46 | /// Uses DWARF5's IDX_parent fields, when available, to speed up this query. |
47 | void GetFullyQualifiedType( |
48 | const DWARFDeclContext &context, |
49 | llvm::function_ref<bool(DWARFDIE die)> callback) override; |
50 | void GetTypes(ConstString name, |
51 | llvm::function_ref<bool(DWARFDIE die)> callback) override; |
52 | void GetTypes(const DWARFDeclContext &context, |
53 | llvm::function_ref<bool(DWARFDIE die)> callback) override; |
54 | void GetNamespaces(ConstString name, |
55 | llvm::function_ref<bool(DWARFDIE die)> callback) override; |
56 | void GetFunctions(const Module::LookupInfo &lookup_info, |
57 | SymbolFileDWARF &dwarf, |
58 | const CompilerDeclContext &parent_decl_ctx, |
59 | llvm::function_ref<bool(DWARFDIE die)> callback) override; |
60 | void GetFunctions(const RegularExpression ®ex, |
61 | llvm::function_ref<bool(DWARFDIE die)> callback) override; |
62 | |
63 | void Dump(Stream &s) override; |
64 | |
65 | private: |
66 | (Module &module, |
67 | std::unique_ptr<llvm::DWARFDebugNames> debug_names_up, |
68 | DWARFDataExtractor debug_names_data, |
69 | DWARFDataExtractor debug_str_data, |
70 | SymbolFileDWARF &dwarf) |
71 | : DWARFIndex(module), m_debug_info(dwarf.DebugInfo()), |
72 | m_debug_names_data(debug_names_data), m_debug_str_data(debug_str_data), |
73 | m_debug_names_up(std::move(debug_names_up)), |
74 | m_fallback(module, dwarf, GetUnits(debug_names: *m_debug_names_up)) {} |
75 | |
76 | DWARFDebugInfo &m_debug_info; |
77 | |
78 | // LLVM DWARFDebugNames will hold a non-owning reference to this data, so keep |
79 | // track of the ownership here. |
80 | DWARFDataExtractor m_debug_names_data; |
81 | DWARFDataExtractor m_debug_str_data; |
82 | |
83 | using DebugNames = llvm::DWARFDebugNames; |
84 | std::unique_ptr<DebugNames> m_debug_names_up; |
85 | ManualDWARFIndex m_fallback; |
86 | |
87 | std::optional<DIERef> ToDIERef(const DebugNames::Entry &entry) const; |
88 | bool ProcessEntry(const DebugNames::Entry &entry, |
89 | llvm::function_ref<bool(DWARFDIE die)> callback); |
90 | |
91 | /// Returns true if `parent_entries` have identical names to `parent_names`. |
92 | bool SameParentChain(llvm::ArrayRef<llvm::StringRef> parent_names, |
93 | llvm::ArrayRef<DebugNames::Entry> parent_entries) const; |
94 | |
95 | static void MaybeLogLookupError(llvm::Error error, |
96 | const DebugNames::NameIndex &ni, |
97 | llvm::StringRef name); |
98 | |
99 | static llvm::DenseSet<dw_offset_t> GetUnits(const DebugNames &debug_names); |
100 | }; |
101 | |
102 | } // namespace dwarf |
103 | } // namespace lldb_private::plugin |
104 | |
105 | #endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DEBUGNAMESDWARFINDEX_H |
106 | |