Path: blob/main/contrib/llvm-project/lldb/source/Plugins/SymbolFile/DWARF/DebugNamesDWARFIndex.h
39645 views
//===-- DebugNamesDWARFIndex.h ---------------------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DEBUGNAMESDWARFINDEX_H9#define LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DEBUGNAMESDWARFINDEX_H1011#include "Plugins/SymbolFile/DWARF/DWARFIndex.h"12#include "Plugins/SymbolFile/DWARF/ManualDWARFIndex.h"13#include "Plugins/SymbolFile/DWARF/SymbolFileDWARF.h"14#include "lldb/Utility/ConstString.h"15#include "llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h"16#include <optional>1718namespace lldb_private::plugin {19namespace dwarf {20class DebugNamesDWARFIndex : public DWARFIndex {21public:22static llvm::Expected<std::unique_ptr<DebugNamesDWARFIndex>>23Create(Module &module, DWARFDataExtractor debug_names,24DWARFDataExtractor debug_str, SymbolFileDWARF &dwarf);2526void Preload() override { m_fallback.Preload(); }2728void29GetGlobalVariables(ConstString basename,30llvm::function_ref<bool(DWARFDIE die)> callback) override;31void32GetGlobalVariables(const RegularExpression ®ex,33llvm::function_ref<bool(DWARFDIE die)> callback) override;34void35GetGlobalVariables(DWARFUnit &cu,36llvm::function_ref<bool(DWARFDIE die)> callback) override;37void38GetObjCMethods(ConstString class_name,39llvm::function_ref<bool(DWARFDIE die)> callback) override {}40void GetCompleteObjCClass(41ConstString class_name, bool must_be_implementation,42llvm::function_ref<bool(DWARFDIE die)> callback) override;4344/// Uses DWARF5's IDX_parent fields, when available, to speed up this query.45void GetFullyQualifiedType(46const DWARFDeclContext &context,47llvm::function_ref<bool(DWARFDIE die)> callback) override;48void GetTypes(ConstString name,49llvm::function_ref<bool(DWARFDIE die)> callback) override;50void GetTypes(const DWARFDeclContext &context,51llvm::function_ref<bool(DWARFDIE die)> callback) override;52void GetNamespaces(ConstString name,53llvm::function_ref<bool(DWARFDIE die)> callback) override;54void GetFunctions(const Module::LookupInfo &lookup_info,55SymbolFileDWARF &dwarf,56const CompilerDeclContext &parent_decl_ctx,57llvm::function_ref<bool(DWARFDIE die)> callback) override;58void GetFunctions(const RegularExpression ®ex,59llvm::function_ref<bool(DWARFDIE die)> callback) override;6061void Dump(Stream &s) override;6263private:64DebugNamesDWARFIndex(Module &module,65std::unique_ptr<llvm::DWARFDebugNames> debug_names_up,66DWARFDataExtractor debug_names_data,67DWARFDataExtractor debug_str_data,68SymbolFileDWARF &dwarf)69: DWARFIndex(module), m_debug_info(dwarf.DebugInfo()),70m_debug_names_data(debug_names_data), m_debug_str_data(debug_str_data),71m_debug_names_up(std::move(debug_names_up)),72m_fallback(module, dwarf, GetUnits(*m_debug_names_up),73GetTypeUnitSignatures(*m_debug_names_up)) {}7475DWARFDebugInfo &m_debug_info;7677// LLVM DWARFDebugNames will hold a non-owning reference to this data, so keep78// track of the ownership here.79DWARFDataExtractor m_debug_names_data;80DWARFDataExtractor m_debug_str_data;8182using DebugNames = llvm::DWARFDebugNames;83std::unique_ptr<DebugNames> m_debug_names_up;84ManualDWARFIndex m_fallback;8586DWARFUnit *GetNonSkeletonUnit(const DebugNames::Entry &entry) const;87DWARFDIE GetDIE(const DebugNames::Entry &entry) const;8889/// Checks if an entry is a foreign TU and fetch the type unit.90///91/// This function checks if the DebugNames::Entry refers to a foreign TU and92/// returns an optional with a value of the \a entry is a foreign type unit93/// entry. A valid pointer will be returned if this entry is from a .dwo file94/// or if it is from a .dwp file and it matches the type unit's originating95/// .dwo file by verifying that the DW_TAG_type_unit DIE has a DW_AT_dwo_name96/// that matches the DWO name from the originating skeleton compile unit.97///98/// \param[in] entry99/// The accelerator table entry to check.100///101/// \returns102/// A std::optional that has a value if this entry represents a foreign type103/// unit. If the pointer is valid, then we were able to find and match the104/// entry to the type unit in the .dwo or .dwp file. The returned value can105/// have a valid, yet contain NULL in the following cases:106/// - we were not able to load the .dwo file (missing or DWO ID mismatch)107/// - we were able to load the .dwp file, but the type units DWO name108/// doesn't match the originating skeleton compile unit's entry109/// Returns std::nullopt if this entry is not a foreign type unit entry.110std::optional<DWARFTypeUnit *>111GetForeignTypeUnit(const DebugNames::Entry &entry) const;112113bool ProcessEntry(const DebugNames::Entry &entry,114llvm::function_ref<bool(DWARFDIE die)> callback);115116/// Returns true if `parent_entries` have identical names to `parent_names`.117bool SameParentChain(llvm::ArrayRef<llvm::StringRef> parent_names,118llvm::ArrayRef<DebugNames::Entry> parent_entries) const;119120static void MaybeLogLookupError(llvm::Error error,121const DebugNames::NameIndex &ni,122llvm::StringRef name);123124static llvm::DenseSet<dw_offset_t> GetUnits(const DebugNames &debug_names);125static llvm::DenseSet<uint64_t>126GetTypeUnitSignatures(const DebugNames &debug_names);127};128129} // namespace dwarf130} // namespace lldb_private::plugin131132#endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DEBUGNAMESDWARFINDEX_H133134135