1 | //===-- DWARFIndex.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_DWARFINDEX_H |
10 | #define LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFINDEX_H |
11 | |
12 | #include "Plugins/SymbolFile/DWARF/DIERef.h" |
13 | #include "Plugins/SymbolFile/DWARF/DWARFDIE.h" |
14 | #include "Plugins/SymbolFile/DWARF/DWARFFormValue.h" |
15 | #include "llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h" |
16 | |
17 | #include "lldb/Core/Module.h" |
18 | #include "lldb/Target/Statistics.h" |
19 | |
20 | namespace lldb_private::plugin { |
21 | namespace dwarf { |
22 | class DWARFDeclContext; |
23 | class DWARFDIE; |
24 | |
25 | class DWARFIndex { |
26 | public: |
27 | DWARFIndex(Module &module) : m_module(module) {} |
28 | virtual ~DWARFIndex(); |
29 | |
30 | virtual void Preload() = 0; |
31 | |
32 | /// Finds global variables with the given base name. Any additional filtering |
33 | /// (e.g., to only retrieve variables from a given context) should be done by |
34 | /// the consumer. |
35 | virtual void |
36 | GetGlobalVariables(ConstString basename, |
37 | llvm::function_ref<bool(DWARFDIE die)> callback) = 0; |
38 | |
39 | virtual void |
40 | GetGlobalVariables(const RegularExpression ®ex, |
41 | llvm::function_ref<bool(DWARFDIE die)> callback) = 0; |
42 | /// \a cu must be the skeleton unit if possible, not GetNonSkeletonUnit(). |
43 | virtual void |
44 | GetGlobalVariables(DWARFUnit &cu, |
45 | llvm::function_ref<bool(DWARFDIE die)> callback) = 0; |
46 | virtual void |
47 | GetObjCMethods(ConstString class_name, |
48 | llvm::function_ref<bool(DWARFDIE die)> callback) = 0; |
49 | virtual void |
50 | GetCompleteObjCClass(ConstString class_name, bool must_be_implementation, |
51 | llvm::function_ref<bool(DWARFDIE die)> callback) = 0; |
52 | virtual void GetTypes(ConstString name, |
53 | llvm::function_ref<bool(DWARFDIE die)> callback) = 0; |
54 | virtual void GetTypes(const DWARFDeclContext &context, |
55 | llvm::function_ref<bool(DWARFDIE die)> callback) = 0; |
56 | |
57 | /// Finds all DIEs whose fully qualified name matches `context`. A base |
58 | /// implementation is provided, and it uses the entire CU to check the DIE |
59 | /// parent hierarchy. Specializations should override this if they are able |
60 | /// to provide a faster implementation. |
61 | virtual void |
62 | GetFullyQualifiedType(const DWARFDeclContext &context, |
63 | llvm::function_ref<bool(DWARFDIE die)> callback); |
64 | virtual void |
65 | GetNamespaces(ConstString name, |
66 | llvm::function_ref<bool(DWARFDIE die)> callback) = 0; |
67 | virtual void |
68 | GetFunctions(const Module::LookupInfo &lookup_info, SymbolFileDWARF &dwarf, |
69 | const CompilerDeclContext &parent_decl_ctx, |
70 | llvm::function_ref<bool(DWARFDIE die)> callback) = 0; |
71 | virtual void |
72 | GetFunctions(const RegularExpression ®ex, |
73 | llvm::function_ref<bool(DWARFDIE die)> callback) = 0; |
74 | |
75 | virtual void Dump(Stream &s) = 0; |
76 | |
77 | StatsDuration::Duration GetIndexTime() { return m_index_time; } |
78 | |
79 | protected: |
80 | Module &m_module; |
81 | StatsDuration m_index_time; |
82 | |
83 | /// Helper function implementing common logic for processing function dies. If |
84 | /// the function given by "ref" matches search criteria given by |
85 | /// "parent_decl_ctx" and "name_type_mask", it is inserted into the "dies" |
86 | /// vector. |
87 | bool ProcessFunctionDIE(const Module::LookupInfo &lookup_info, DIERef ref, |
88 | SymbolFileDWARF &dwarf, |
89 | const CompilerDeclContext &parent_decl_ctx, |
90 | llvm::function_ref<bool(DWARFDIE die)> callback); |
91 | |
92 | class DIERefCallbackImpl { |
93 | public: |
94 | DIERefCallbackImpl(const DWARFIndex &index, |
95 | llvm::function_ref<bool(DWARFDIE die)> callback, |
96 | llvm::StringRef name); |
97 | bool operator()(DIERef ref) const; |
98 | bool operator()(const llvm::AppleAcceleratorTable::Entry &entry) const; |
99 | |
100 | private: |
101 | const DWARFIndex &m_index; |
102 | SymbolFileDWARF &m_dwarf; |
103 | const llvm::function_ref<bool(DWARFDIE die)> m_callback; |
104 | const llvm::StringRef m_name; |
105 | }; |
106 | DIERefCallbackImpl |
107 | DIERefCallback(llvm::function_ref<bool(DWARFDIE die)> callback, |
108 | llvm::StringRef name = {}) const { |
109 | return DIERefCallbackImpl(*this, callback, name); |
110 | } |
111 | |
112 | void ReportInvalidDIERef(DIERef ref, llvm::StringRef name) const; |
113 | |
114 | /// Implementation of `GetFullyQualifiedType` to check a single entry, |
115 | /// shareable with derived classes. |
116 | bool |
117 | GetFullyQualifiedTypeImpl(const DWARFDeclContext &context, DWARFDIE die, |
118 | llvm::function_ref<bool(DWARFDIE die)> callback); |
119 | }; |
120 | } // namespace dwarf |
121 | } // namespace lldb_private::plugin |
122 | |
123 | #endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFINDEX_H |
124 | |