| 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 | /// Get type DIEs meeting requires of \a query. |
| 68 | /// in its decl parent chain as subset. A base implementation is provided, |
| 69 | /// Specializations should override this if they are able to provide a faster |
| 70 | /// implementation. |
| 71 | virtual void |
| 72 | GetTypesWithQuery(TypeQuery &query, |
| 73 | llvm::function_ref<bool(DWARFDIE die)> callback); |
| 74 | /// Get namespace DIEs whose base name match \param name with \param |
| 75 | /// parent_decl_ctx in its decl parent chain. A base implementation |
| 76 | /// is provided. Specializations should override this if they are able to |
| 77 | /// provide a faster implementation. |
| 78 | virtual void |
| 79 | GetNamespacesWithParents(ConstString name, |
| 80 | const CompilerDeclContext &parent_decl_ctx, |
| 81 | llvm::function_ref<bool(DWARFDIE die)> callback); |
| 82 | virtual void |
| 83 | GetFunctions(const Module::LookupInfo &lookup_info, SymbolFileDWARF &dwarf, |
| 84 | const CompilerDeclContext &parent_decl_ctx, |
| 85 | llvm::function_ref<bool(DWARFDIE die)> callback) = 0; |
| 86 | virtual void |
| 87 | GetFunctions(const RegularExpression ®ex, |
| 88 | llvm::function_ref<bool(DWARFDIE die)> callback) = 0; |
| 89 | |
| 90 | virtual void Dump(Stream &s) = 0; |
| 91 | |
| 92 | StatsDuration::Duration GetIndexTime() { return m_index_time; } |
| 93 | |
| 94 | void ResetStatistics() { m_index_time.reset(); } |
| 95 | |
| 96 | protected: |
| 97 | Module &m_module; |
| 98 | StatsDuration m_index_time; |
| 99 | |
| 100 | /// Helper function implementing common logic for processing function dies. If |
| 101 | /// the function given by "die" matches search criteria given by |
| 102 | /// "parent_decl_ctx" and "name_type_mask", it calls the callback with the |
| 103 | /// given die. |
| 104 | bool ProcessFunctionDIE(const Module::LookupInfo &lookup_info, DWARFDIE die, |
| 105 | const CompilerDeclContext &parent_decl_ctx, |
| 106 | llvm::function_ref<bool(DWARFDIE die)> callback); |
| 107 | |
| 108 | class DIERefCallbackImpl { |
| 109 | public: |
| 110 | DIERefCallbackImpl(const DWARFIndex &index, |
| 111 | llvm::function_ref<bool(DWARFDIE die)> callback, |
| 112 | llvm::StringRef name); |
| 113 | bool operator()(DIERef ref) const; |
| 114 | bool operator()(const llvm::AppleAcceleratorTable::Entry &entry) const; |
| 115 | |
| 116 | private: |
| 117 | const DWARFIndex &m_index; |
| 118 | SymbolFileDWARF &m_dwarf; |
| 119 | const llvm::function_ref<bool(DWARFDIE die)> m_callback; |
| 120 | const llvm::StringRef m_name; |
| 121 | }; |
| 122 | DIERefCallbackImpl |
| 123 | DIERefCallback(llvm::function_ref<bool(DWARFDIE die)> callback, |
| 124 | llvm::StringRef name = {}) const { |
| 125 | return DIERefCallbackImpl(*this, callback, name); |
| 126 | } |
| 127 | |
| 128 | void ReportInvalidDIERef(DIERef ref, llvm::StringRef name) const; |
| 129 | |
| 130 | /// Implementation of `GetFullyQualifiedType` to check a single entry, |
| 131 | /// shareable with derived classes. |
| 132 | bool |
| 133 | GetFullyQualifiedTypeImpl(const DWARFDeclContext &context, DWARFDIE die, |
| 134 | llvm::function_ref<bool(DWARFDIE die)> callback); |
| 135 | |
| 136 | /// Check if the type \a die can meet the requirements of \a query. |
| 137 | bool |
| 138 | ProcessTypeDIEMatchQuery(TypeQuery &query, DWARFDIE die, |
| 139 | llvm::function_ref<bool(DWARFDIE die)> callback); |
| 140 | bool ProcessNamespaceDieMatchParents( |
| 141 | const CompilerDeclContext &parent_decl_ctx, DWARFDIE die, |
| 142 | llvm::function_ref<bool(DWARFDIE die)> callback); |
| 143 | }; |
| 144 | } // namespace dwarf |
| 145 | } // namespace lldb_private::plugin |
| 146 | |
| 147 | #endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFINDEX_H |
| 148 | |