176 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DEBUGNAMESDWARFINDEX_H10#define LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DEBUGNAMESDWARFINDEX_H11 12#include "Plugins/SymbolFile/DWARF/DWARFIndex.h"13#include "Plugins/SymbolFile/DWARF/ManualDWARFIndex.h"14#include "Plugins/SymbolFile/DWARF/SymbolFileDWARF.h"15#include "lldb/Utility/ConstString.h"16#include "lldb/lldb-private-enumerations.h"17#include "llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h"18#include <optional>19 20namespace lldb_private::plugin {21namespace dwarf {22class DebugNamesDWARFIndex : public DWARFIndex {23public:24 static llvm::Expected<std::unique_ptr<DebugNamesDWARFIndex>>25 Create(Module &module, DWARFDataExtractor debug_names,26 DWARFDataExtractor debug_str, SymbolFileDWARF &dwarf);27 28 void Preload() override { m_fallback.Preload(); }29 30 void GetGlobalVariables(31 ConstString basename,32 llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;33 void GetGlobalVariables(34 const RegularExpression ®ex,35 llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;36 void GetGlobalVariables(37 DWARFUnit &cu,38 llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;39 void GetObjCMethods(40 ConstString class_name,41 llvm::function_ref<IterationAction(DWARFDIE die)> callback) override {}42 void GetCompleteObjCClass(43 ConstString class_name, bool must_be_implementation,44 llvm::function_ref<IterationAction(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<IterationAction(DWARFDIE die)> callback) override;50 void51 GetTypes(ConstString name,52 llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;53 void54 GetTypes(const DWARFDeclContext &context,55 llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;56 void GetNamespaces(57 ConstString name,58 llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;59 void GetTypesWithQuery(60 TypeQuery &query,61 llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;62 void GetNamespacesWithParents(63 ConstString name, const CompilerDeclContext &parent_decl_ctx,64 llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;65 void GetFunctions(66 const Module::LookupInfo &lookup_info, SymbolFileDWARF &dwarf,67 const CompilerDeclContext &parent_decl_ctx,68 llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;69 void GetFunctions(70 const RegularExpression ®ex,71 llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;72 73 void Dump(Stream &s) override;74 75private:76 DebugNamesDWARFIndex(Module &module,77 std::unique_ptr<llvm::DWARFDebugNames> debug_names_up,78 DWARFDataExtractor debug_names_data,79 DWARFDataExtractor debug_str_data,80 SymbolFileDWARF &dwarf)81 : DWARFIndex(module), m_debug_info(dwarf.DebugInfo()),82 m_debug_names_data(debug_names_data), m_debug_str_data(debug_str_data),83 m_debug_names_up(std::move(debug_names_up)),84 m_fallback(module, dwarf, GetUnits(*m_debug_names_up),85 GetTypeUnitSignatures(*m_debug_names_up)) {}86 87 DWARFDebugInfo &m_debug_info;88 89 // LLVM DWARFDebugNames will hold a non-owning reference to this data, so keep90 // track of the ownership here.91 DWARFDataExtractor m_debug_names_data;92 DWARFDataExtractor m_debug_str_data;93 94 using DebugNames = llvm::DWARFDebugNames;95 std::unique_ptr<DebugNames> m_debug_names_up;96 ManualDWARFIndex m_fallback;97 98 DWARFUnit *GetNonSkeletonUnit(const DebugNames::Entry &entry) const;99 DWARFDIE GetDIE(const DebugNames::Entry &entry) const;100 101 /// Checks if an entry is a foreign TU and fetch the type unit.102 ///103 /// This function checks if the DebugNames::Entry refers to a foreign TU and104 /// returns an optional with a value of the \a entry is a foreign type unit105 /// entry. A valid pointer will be returned if this entry is from a .dwo file106 /// or if it is from a .dwp file and it matches the type unit's originating107 /// .dwo file by verifying that the DW_TAG_type_unit DIE has a DW_AT_dwo_name108 /// that matches the DWO name from the originating skeleton compile unit.109 ///110 /// \param[in] entry111 /// The accelerator table entry to check.112 ///113 /// \returns114 /// A std::optional that has a value if this entry represents a foreign type115 /// unit. If the pointer is valid, then we were able to find and match the116 /// entry to the type unit in the .dwo or .dwp file. The returned value can117 /// have a valid, yet contain NULL in the following cases:118 /// - we were not able to load the .dwo file (missing or DWO ID mismatch)119 /// - we were able to load the .dwp file, but the type units DWO name120 /// doesn't match the originating skeleton compile unit's entry121 /// Returns std::nullopt if this entry is not a foreign type unit entry.122 std::optional<DWARFTypeUnit *>123 GetForeignTypeUnit(const DebugNames::Entry &entry) const;124 125 IterationAction126 ProcessEntry(const DebugNames::Entry &entry,127 llvm::function_ref<IterationAction(DWARFDIE die)> callback);128 129 /// Returns true if `parent_entries` have identical names to `parent_names`.130 bool SameParentChain(llvm::ArrayRef<llvm::StringRef> parent_names,131 llvm::ArrayRef<DebugNames::Entry> parent_entries) const;132 133 bool SameParentChain(llvm::ArrayRef<CompilerContext> parent_contexts,134 llvm::ArrayRef<DebugNames::Entry> parent_entries) const;135 136 /// Returns true if \a parent_contexts entries are within \a parent_chain.137 /// This is diffferent from SameParentChain() which checks for exact match.138 /// This function is required because \a parent_chain can contain inline139 /// namespace entries which may not be specified in \a parent_contexts by140 /// client.141 ///142 /// \param[in] parent_contexts143 /// The list of parent contexts to check for.144 ///145 /// \param[in] parent_chain146 /// The fully qualified parent chain entries from .debug_names index table147 /// to check against.148 ///149 /// \returns150 /// True if all \a parent_contexts entries are can be sequentially found151 /// inside152 /// \a parent_chain, otherwise False.153 bool WithinParentChain(llvm::ArrayRef<CompilerContext> parent_contexts,154 llvm::ArrayRef<DebugNames::Entry> parent_chain) const;155 156 /// Returns true if .debug_names pool entry \p entry matches \p query_context.157 bool SameAsEntryContext(const CompilerContext &query_context,158 const DebugNames::Entry &entry) const;159 160 llvm::SmallVector<CompilerContext>161 GetTypeQueryParentContexts(TypeQuery &query);162 163 static void MaybeLogLookupError(llvm::Error error,164 const DebugNames::NameIndex &ni,165 llvm::StringRef name);166 167 static llvm::DenseSet<dw_offset_t> GetUnits(const DebugNames &debug_names);168 static llvm::DenseSet<uint64_t>169 GetTypeUnitSignatures(const DebugNames &debug_names);170};171 172} // namespace dwarf173} // namespace lldb_private::plugin174 175#endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DEBUGNAMESDWARFINDEX_H176