brintos

brintos / llvm-project-archived public Read only

0
0
Text · 7.2 KiB · 41e0e62 Raw
185 lines · c
1//===-- ManualDWARFIndex.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_MANUALDWARFINDEX_H10#define LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_MANUALDWARFINDEX_H11 12#include "Plugins/SymbolFile/DWARF/DWARFIndex.h"13#include "Plugins/SymbolFile/DWARF/ManualDWARFIndexSet.h"14#include "Plugins/SymbolFile/DWARF/NameToDIE.h"15#include "lldb/lldb-private-enumerations.h"16#include "llvm/ADT/DenseSet.h"17 18namespace lldb_private::plugin {19namespace dwarf {20class DWARFDebugInfo;21class SymbolFileDWARFDwo;22 23class ManualDWARFIndex : public DWARFIndex {24public:25  ManualDWARFIndex(Module &module, SymbolFileDWARF &dwarf,26                   llvm::DenseSet<dw_offset_t> units_to_avoid = {},27                   llvm::DenseSet<uint64_t> type_sigs_to_avoid = {})28      : DWARFIndex(module), m_dwarf(&dwarf),29        m_units_to_avoid(std::move(units_to_avoid)),30        m_type_sigs_to_avoid(std::move(type_sigs_to_avoid)) {}31 32  void Preload() override { Index(); }33 34  void GetGlobalVariables(35      ConstString basename,36      llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;37  void GetGlobalVariables(38      const RegularExpression &regex,39      llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;40  void GetGlobalVariables(41      DWARFUnit &unit,42      llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;43  void GetObjCMethods(44      ConstString class_name,45      llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;46  void GetCompleteObjCClass(47      ConstString class_name, bool must_be_implementation,48      llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;49  void50  GetTypes(ConstString name,51           llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;52  void53  GetTypes(const DWARFDeclContext &context,54           llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;55  void GetNamespaces(56      ConstString name,57      llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;58  void GetFunctions(59      const Module::LookupInfo &lookup_info, SymbolFileDWARF &dwarf,60      const CompilerDeclContext &parent_decl_ctx,61      llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;62  void GetFunctions(63      const RegularExpression &regex,64      llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;65 66  void Dump(Stream &s) override;67 68private:69  /// Reads the DWARF debug info to build the index once.70  ///71  /// Should be called before attempting to retrieve symbols.72  void Index();73 74  /// Call `ManualDWARFIndex::Index()` instead.75  void IndexImpl();76 77  /// Decode a serialized version of this object from data.78  ///79  /// \param data80  ///   The decoder object that references the serialized data.81  ///82  /// \param offset_ptr83  ///   A pointer that contains the offset from which the data will be decoded84  ///   from that gets updated as data gets decoded.85  ///86  /// \param strtab87  ///   All strings in cache files are put into string tables for efficiency88  ///   and cache file size reduction. Strings are stored as uint32_t string89  ///   table offsets in the cache data.90  bool Decode(const DataExtractor &data, lldb::offset_t *offset_ptr,91              bool &signature_mismatch);92 93  /// Encode this object into a data encoder object.94  ///95  /// This allows this object to be serialized to disk.96  ///97  /// \param encoder98  ///   A data encoder object that serialized bytes will be encoded into.99  ///100  /// \param strtab101  ///   All strings in cache files are put into string tables for efficiency102  ///   and cache file size reduction. Strings are stored as uint32_t string103  ///   table offsets in the cache data.104  ///105  /// \return106  ///   True if the symbol table's object file can generate a valid signature107  ///   and all data for the symbol table was encoded, false otherwise.108  bool Encode(DataEncoder &encoder) const;109 110  /// Get the cache key string for this symbol table.111  ///112  /// The cache key must start with the module's cache key and is followed113  /// by information that indicates this key is for caching the symbol table114  /// contents and should also include the has of the object file. A module can115  /// be represented by an ObjectFile object for the main executable, but can116  /// also have a symbol file that is from the same or a different object file.117  /// This means we might have two symbol tables cached in the index cache, one118  /// for the main executable and one for the symbol file.119  ///120  /// \return121  ///   The unique cache key used to save and retrieve data from the index122  ///   cache.123  std::string GetCacheKey();124 125  /// Save the symbol table data out into a cache.126  ///127  /// The symbol table will only be saved to a cache file if caching is enabled.128  ///129  /// We cache the contents of the symbol table since symbol tables in LLDB take130  /// some time to initialize. This is due to the many sources for data that are131  /// used to create a symbol table:132  /// - standard symbol table133  /// - dynamic symbol table (ELF)134  /// - compressed debug info sections135  /// - unwind information136  /// - function pointers found in runtimes for global constructor/destructors137  /// - other sources.138  /// All of the above sources are combined and one symbol table results after139  /// all sources have been considered.140  void SaveToCache();141 142  /// Load the symbol table from the index cache.143  ///144  /// Quickly load the finalized symbol table from the index cache. This saves145  /// time when the debugger starts up. The index cache file for the symbol146  /// table has the modification time set to the same time as the main module.147  /// If the cache file exists and the modification times match, we will load148  /// the symbol table from the serlized cache file.149  ///150  /// \return151  ///   True if the symbol table was successfully loaded from the index cache,152  ///   false if the symbol table wasn't cached or was out of date.153  bool LoadFromCache();154 155  void IndexUnit(DWARFUnit &unit, SymbolFileDWARFDwo *dwp,156                 IndexSet<NameToDIE> &set);157 158  static void IndexUnitImpl(DWARFUnit &unit,159                            const lldb::LanguageType cu_language,160                            IndexSet<NameToDIE> &set);161 162  /// Return true if this manual DWARF index is covering only part of the DWARF.163  ///164  /// An instance of this class will be used to index all of the DWARF, but also165  /// when we have .debug_names we will use one to index any compile or type166  /// units that are not covered by the .debug_names table.167  ///168  /// \return169  ///   True if this index is a partial index, false otherwise.170  bool IsPartial() const;171 172  /// The DWARF file which we are indexing.173  SymbolFileDWARF *m_dwarf;174  /// Which dwarf units should we skip while building the index.175  llvm::DenseSet<dw_offset_t> m_units_to_avoid;176  llvm::DenseSet<uint64_t> m_type_sigs_to_avoid;177 178  IndexSet<NameToDIE> m_set;179  std::once_flag m_indexed_flag;180};181} // namespace dwarf182} // namespace lldb_private::plugin183 184#endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_MANUALDWARFINDEX_H185