Path: blob/main/contrib/llvm-project/lldb/source/Plugins/SymbolFile/DWARF/ManualDWARFIndex.h
39645 views
//===-- ManualDWARFIndex.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_MANUALDWARFINDEX_H9#define LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_MANUALDWARFINDEX_H1011#include "Plugins/SymbolFile/DWARF/DWARFIndex.h"12#include "Plugins/SymbolFile/DWARF/NameToDIE.h"13#include "llvm/ADT/DenseSet.h"1415namespace lldb_private::plugin {16namespace dwarf {17class DWARFDebugInfo;18class SymbolFileDWARFDwo;1920class ManualDWARFIndex : public DWARFIndex {21public:22ManualDWARFIndex(Module &module, SymbolFileDWARF &dwarf,23llvm::DenseSet<dw_offset_t> units_to_avoid = {},24llvm::DenseSet<uint64_t> type_sigs_to_avoid = {})25: DWARFIndex(module), m_dwarf(&dwarf),26m_units_to_avoid(std::move(units_to_avoid)),27m_type_sigs_to_avoid(std::move(type_sigs_to_avoid)) {}2829void Preload() override { Index(); }3031void32GetGlobalVariables(ConstString basename,33llvm::function_ref<bool(DWARFDIE die)> callback) override;34void35GetGlobalVariables(const RegularExpression ®ex,36llvm::function_ref<bool(DWARFDIE die)> callback) override;37void38GetGlobalVariables(DWARFUnit &unit,39llvm::function_ref<bool(DWARFDIE die)> callback) override;40void GetObjCMethods(ConstString class_name,41llvm::function_ref<bool(DWARFDIE die)> callback) override;42void GetCompleteObjCClass(43ConstString class_name, bool must_be_implementation,44llvm::function_ref<bool(DWARFDIE die)> callback) override;45void GetTypes(ConstString name,46llvm::function_ref<bool(DWARFDIE die)> callback) override;47void GetTypes(const DWARFDeclContext &context,48llvm::function_ref<bool(DWARFDIE die)> callback) override;49void GetNamespaces(ConstString name,50llvm::function_ref<bool(DWARFDIE die)> callback) override;51void GetFunctions(const Module::LookupInfo &lookup_info,52SymbolFileDWARF &dwarf,53const CompilerDeclContext &parent_decl_ctx,54llvm::function_ref<bool(DWARFDIE die)> callback) override;55void GetFunctions(const RegularExpression ®ex,56llvm::function_ref<bool(DWARFDIE die)> callback) override;5758void Dump(Stream &s) override;5960// Make IndexSet public so we can unit test the encoding and decoding logic.61struct IndexSet {62NameToDIE function_basenames;63NameToDIE function_fullnames;64NameToDIE function_methods;65NameToDIE function_selectors;66NameToDIE objc_class_selectors;67NameToDIE globals;68NameToDIE types;69NameToDIE namespaces;70bool Decode(const DataExtractor &data, lldb::offset_t *offset_ptr);71void Encode(DataEncoder &encoder) const;72bool operator==(const IndexSet &rhs) const {73return function_basenames == rhs.function_basenames &&74function_fullnames == rhs.function_fullnames &&75function_methods == rhs.function_methods &&76function_selectors == rhs.function_selectors &&77objc_class_selectors == rhs.objc_class_selectors &&78globals == rhs.globals && types == rhs.types &&79namespaces == rhs.namespaces;80}81};8283private:84void Index();8586/// Decode a serialized version of this object from data.87///88/// \param data89/// The decoder object that references the serialized data.90///91/// \param offset_ptr92/// A pointer that contains the offset from which the data will be decoded93/// from that gets updated as data gets decoded.94///95/// \param strtab96/// All strings in cache files are put into string tables for efficiency97/// and cache file size reduction. Strings are stored as uint32_t string98/// table offsets in the cache data.99bool Decode(const DataExtractor &data, lldb::offset_t *offset_ptr,100bool &signature_mismatch);101102/// Encode this object into a data encoder object.103///104/// This allows this object to be serialized to disk.105///106/// \param encoder107/// A data encoder object that serialized bytes will be encoded into.108///109/// \param strtab110/// All strings in cache files are put into string tables for efficiency111/// and cache file size reduction. Strings are stored as uint32_t string112/// table offsets in the cache data.113///114/// \return115/// True if the symbol table's object file can generate a valid signature116/// and all data for the symbol table was encoded, false otherwise.117bool Encode(DataEncoder &encoder) const;118119/// Get the cache key string for this symbol table.120///121/// The cache key must start with the module's cache key and is followed122/// by information that indicates this key is for caching the symbol table123/// contents and should also include the has of the object file. A module can124/// be represented by an ObjectFile object for the main executable, but can125/// also have a symbol file that is from the same or a different object file.126/// This means we might have two symbol tables cached in the index cache, one127/// for the main executable and one for the symbol file.128///129/// \return130/// The unique cache key used to save and retrieve data from the index131/// cache.132std::string GetCacheKey();133134/// Save the symbol table data out into a cache.135///136/// The symbol table will only be saved to a cache file if caching is enabled.137///138/// We cache the contents of the symbol table since symbol tables in LLDB take139/// some time to initialize. This is due to the many sources for data that are140/// used to create a symbol table:141/// - standard symbol table142/// - dynamic symbol table (ELF)143/// - compressed debug info sections144/// - unwind information145/// - function pointers found in runtimes for global constructor/destructors146/// - other sources.147/// All of the above sources are combined and one symbol table results after148/// all sources have been considered.149void SaveToCache();150151/// Load the symbol table from the index cache.152///153/// Quickly load the finalized symbol table from the index cache. This saves154/// time when the debugger starts up. The index cache file for the symbol155/// table has the modification time set to the same time as the main module.156/// If the cache file exists and the modification times match, we will load157/// the symbol table from the serlized cache file.158///159/// \return160/// True if the symbol table was successfully loaded from the index cache,161/// false if the symbol table wasn't cached or was out of date.162bool LoadFromCache();163164void IndexUnit(DWARFUnit &unit, SymbolFileDWARFDwo *dwp, IndexSet &set);165166static void IndexUnitImpl(DWARFUnit &unit,167const lldb::LanguageType cu_language,168IndexSet &set);169170/// The DWARF file which we are indexing.171SymbolFileDWARF *m_dwarf;172/// Which dwarf units should we skip while building the index.173llvm::DenseSet<dw_offset_t> m_units_to_avoid;174llvm::DenseSet<uint64_t> m_type_sigs_to_avoid;175176IndexSet m_set;177bool m_indexed = false;178};179} // namespace dwarf180} // namespace lldb_private::plugin181182#endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_MANUALDWARFINDEX_H183184185