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 { 21 class DebugNamesDWARFIndex : public DWARFIndex { 22 public: 23 static llvm::Expected<std::unique_ptr<DebugNamesDWARFIndex>> 24 Create(Module &module, DWARFDataExtractor debug_names, 25 DWARFDataExtractor debug_str, SymbolFileDWARF &dwarf); 26 27 void Preload() override { m_fallback.Preload(); } 28 29 void 30 GetGlobalVariables(ConstString basename, 31 llvm::function_ref<bool(DWARFDIE die)> callback) override; 32 void 33 GetGlobalVariables(const RegularExpression ®ex, 34 llvm::function_ref<bool(DWARFDIE die)> callback) override; 35 void 36 GetGlobalVariables(DWARFUnit &cu, 37 llvm::function_ref<bool(DWARFDIE die)> callback) override; 38 void 39 GetObjCMethods(ConstString class_name, 40 llvm::function_ref<bool(DWARFDIE die)> callback) override {} 41 void GetCompleteObjCClass( 42 ConstString class_name, bool must_be_implementation, 43 llvm::function_ref<bool(DWARFDIE die)> callback) override; 44 void GetTypes(ConstString name, 45 llvm::function_ref<bool(DWARFDIE die)> callback) override; 46 void GetTypes(const DWARFDeclContext &context, 47 llvm::function_ref<bool(DWARFDIE die)> callback) override; 48 void GetNamespaces(ConstString name, 49 llvm::function_ref<bool(DWARFDIE die)> callback) override; 50 void GetFunctions(const Module::LookupInfo &lookup_info, 51 SymbolFileDWARF &dwarf, 52 const CompilerDeclContext &parent_decl_ctx, 53 llvm::function_ref<bool(DWARFDIE die)> callback) override; 54 void GetFunctions(const RegularExpression ®ex, 55 llvm::function_ref<bool(DWARFDIE die)> callback) override; 56 57 void Dump(Stream &s) override; 58 59 private: 60 DebugNamesDWARFIndex(Module &module, 61 std::unique_ptr<llvm::DWARFDebugNames> debug_names_up, 62 DWARFDataExtractor debug_names_data, 63 DWARFDataExtractor debug_str_data, 64 SymbolFileDWARF &dwarf) 65 : DWARFIndex(module), m_debug_info(dwarf.DebugInfo()), 66 m_debug_names_data(debug_names_data), m_debug_str_data(debug_str_data), 67 m_debug_names_up(std::move(debug_names_up)), 68 m_fallback(module, dwarf, GetUnits(*m_debug_names_up)) {} 69 70 DWARFDebugInfo &m_debug_info; 71 72 // LLVM DWARFDebugNames will hold a non-owning reference to this data, so keep 73 // track of the ownership here. 74 DWARFDataExtractor m_debug_names_data; 75 DWARFDataExtractor m_debug_str_data; 76 77 using DebugNames = llvm::DWARFDebugNames; 78 std::unique_ptr<DebugNames> m_debug_names_up; 79 ManualDWARFIndex m_fallback; 80 81 std::optional<DIERef> ToDIERef(const DebugNames::Entry &entry); 82 bool ProcessEntry(const DebugNames::Entry &entry, 83 llvm::function_ref<bool(DWARFDIE die)> callback, 84 llvm::StringRef name); 85 86 static void MaybeLogLookupError(llvm::Error error, 87 const DebugNames::NameIndex &ni, 88 llvm::StringRef name); 89 90 static llvm::DenseSet<dw_offset_t> GetUnits(const DebugNames &debug_names); 91 }; 92 93 } // namespace lldb_private 94 95 #endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DEBUGNAMESDWARFINDEX_H 96