LLDB mainline
ManualDWARFIndex.h
Go to the documentation of this file.
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-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_MANUALDWARFINDEX_H
10#define LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_MANUALDWARFINDEX_H
11
16#include "llvm/ADT/DenseSet.h"
17
18namespace lldb_private::plugin {
19namespace dwarf {
20class DWARFDebugInfo;
22
24public:
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
35 ConstString basename,
36 llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;
38 const RegularExpression &regex,
39 llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;
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;
47 ConstString class_name, bool must_be_implementation,
48 llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;
49 void
51 llvm::function_ref<IterationAction(DWARFDIE die)> callback) override;
52 void
53 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 data
80 /// The decoder object that references the serialized data.
81 ///
82 /// \param offset_ptr
83 /// A pointer that contains the offset from which the data will be decoded
84 /// from that gets updated as data gets decoded.
85 ///
86 /// \param strtab
87 /// All strings in cache files are put into string tables for efficiency
88 /// and cache file size reduction. Strings are stored as uint32_t string
89 /// 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 encoder
98 /// A data encoder object that serialized bytes will be encoded into.
99 ///
100 /// \param strtab
101 /// All strings in cache files are put into string tables for efficiency
102 /// and cache file size reduction. Strings are stored as uint32_t string
103 /// table offsets in the cache data.
104 ///
105 /// \return
106 /// True if the symbol table's object file can generate a valid signature
107 /// 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 followed
113 /// by information that indicates this key is for caching the symbol table
114 /// contents and should also include the has of the object file. A module can
115 /// be represented by an ObjectFile object for the main executable, but can
116 /// 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, one
118 /// for the main executable and one for the symbol file.
119 ///
120 /// \return
121 /// The unique cache key used to save and retrieve data from the index
122 /// 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 take
130 /// some time to initialize. This is due to the many sources for data that are
131 /// used to create a symbol table:
132 /// - standard symbol table
133 /// - dynamic symbol table (ELF)
134 /// - compressed debug info sections
135 /// - unwind information
136 /// - function pointers found in runtimes for global constructor/destructors
137 /// - other sources.
138 /// All of the above sources are combined and one symbol table results after
139 /// 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 saves
145 /// time when the debugger starts up. The index cache file for the symbol
146 /// 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 load
148 /// the symbol table from the serlized cache file.
149 ///
150 /// \return
151 /// 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,
157
158 static void IndexUnitImpl(DWARFUnit &unit,
159 const lldb::LanguageType cu_language,
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 also
165 /// when we have .debug_names we will use one to index any compile or type
166 /// units that are not covered by the .debug_names table.
167 ///
168 /// \return
169 /// True if this index is a partial index, false otherwise.
170 bool IsPartial() const;
171
172 /// The DWARF file which we are indexing.
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
179 std::once_flag m_indexed_flag;
180};
181} // namespace dwarf
182} // namespace lldb_private::plugin
183
184#endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_MANUALDWARFINDEX_H
Represents a generic declaration context in a program.
A uniqued constant string class.
Definition ConstString.h:40
An binary data encoding class.
Definition DataEncoder.h:42
An data extractor class.
A class that encapsulates name lookup information.
Definition Module.h:916
A class that describes an executable image and its associated object and symbol files.
Definition Module.h:90
A stream class that can stream formatted output to a file.
Definition Stream.h:28
void IndexImpl()
Call ManualDWARFIndex::Index() instead.
SymbolFileDWARF * m_dwarf
The DWARF file which we are indexing.
void IndexUnit(DWARFUnit &unit, SymbolFileDWARFDwo *dwp, IndexSet< NameToDIE > &set)
bool IsPartial() const
Return true if this manual DWARF index is covering only part of the DWARF.
bool Encode(DataEncoder &encoder) const
Encode this object into a data encoder object.
void GetGlobalVariables(ConstString basename, llvm::function_ref< IterationAction(DWARFDIE die)> callback) override
Finds global variables with the given base name.
void Index()
Reads the DWARF debug info to build the index once.
void GetFunctions(const Module::LookupInfo &lookup_info, SymbolFileDWARF &dwarf, const CompilerDeclContext &parent_decl_ctx, llvm::function_ref< IterationAction(DWARFDIE die)> callback) override
llvm::DenseSet< dw_offset_t > m_units_to_avoid
Which dwarf units should we skip while building the index.
std::string GetCacheKey()
Get the cache key string for this symbol table.
bool Decode(const DataExtractor &data, lldb::offset_t *offset_ptr, bool &signature_mismatch)
Decode a serialized version of this object from data.
bool LoadFromCache()
Load the symbol table from the index cache.
ManualDWARFIndex(Module &module, SymbolFileDWARF &dwarf, llvm::DenseSet< dw_offset_t > units_to_avoid={}, llvm::DenseSet< uint64_t > type_sigs_to_avoid={})
void GetObjCMethods(ConstString class_name, llvm::function_ref< IterationAction(DWARFDIE die)> callback) override
static void IndexUnitImpl(DWARFUnit &unit, const lldb::LanguageType cu_language, IndexSet< NameToDIE > &set)
void SaveToCache()
Save the symbol table data out into a cache.
void GetCompleteObjCClass(ConstString class_name, bool must_be_implementation, llvm::function_ref< IterationAction(DWARFDIE die)> callback) override
void GetTypes(ConstString name, llvm::function_ref< IterationAction(DWARFDIE die)> callback) override
void GetNamespaces(ConstString name, llvm::function_ref< IterationAction(DWARFDIE die)> callback) override
IterationAction
Useful for callbacks whose return type indicates whether to continue iteration or short-circuit.
uint64_t offset_t
Definition lldb-types.h:85
LanguageType
Programming language type.