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
92 /// Encode this object into a data encoder object.
93 ///
94 /// This allows this object to be serialized to disk.
95 ///
96 /// \param encoder
97 /// A data encoder object that serialized bytes will be encoded into.
98 ///
99 /// \param strtab
100 /// All strings in cache files are put into string tables for efficiency
101 /// and cache file size reduction. Strings are stored as uint32_t string
102 /// table offsets in the cache data.
103 ///
104 /// \return
105 /// True if the symbol table's object file can generate a valid signature
106 /// and all data for the symbol table was encoded, false otherwise.
107 bool Encode(DataEncoder &encoder) const;
108
109 /// Get the cache key string for this symbol table.
110 ///
111 /// The cache key must start with the module's cache key and is followed
112 /// by information that indicates this key is for caching the symbol table
113 /// contents and should also include the has of the object file. A module can
114 /// be represented by an ObjectFile object for the main executable, but can
115 /// also have a symbol file that is from the same or a different object file.
116 /// This means we might have two symbol tables cached in the index cache, one
117 /// for the main executable and one for the symbol file.
118 ///
119 /// \return
120 /// The unique cache key used to save and retrieve data from the index
121 /// cache.
122 std::string GetCacheKey();
123
124 /// Save the symbol table data out into a cache.
125 ///
126 /// The symbol table will only be saved to a cache file if caching is enabled.
127 ///
128 /// We cache the contents of the symbol table since symbol tables in LLDB take
129 /// some time to initialize. This is due to the many sources for data that are
130 /// used to create a symbol table:
131 /// - standard symbol table
132 /// - dynamic symbol table (ELF)
133 /// - compressed debug info sections
134 /// - unwind information
135 /// - function pointers found in runtimes for global constructor/destructors
136 /// - other sources.
137 /// All of the above sources are combined and one symbol table results after
138 /// all sources have been considered.
139 void SaveToCache();
140
141 /// Load the symbol table from the index cache.
142 ///
143 /// Quickly load the finalized symbol table from the index cache. This saves
144 /// time when the debugger starts up. The index cache file for the symbol
145 /// table has the modification time set to the same time as the main module.
146 /// If the cache file exists and the modification times match, we will load
147 /// the symbol table from the serlized cache file.
148 ///
149 /// \return
150 /// True if the symbol table was successfully loaded from the index cache,
151 /// false if the symbol table wasn't cached or was out of date.
152 bool LoadFromCache();
153
154 void IndexUnit(DWARFUnit &unit, SymbolFileDWARFDwo *dwp,
156
157 static void IndexUnitImpl(DWARFUnit &unit,
158 const lldb::LanguageType cu_language,
160
161 /// Return true if this manual DWARF index is covering only part of the DWARF.
162 ///
163 /// An instance of this class will be used to index all of the DWARF, but also
164 /// when we have .debug_names we will use one to index any compile or type
165 /// units that are not covered by the .debug_names table.
166 ///
167 /// \return
168 /// True if this index is a partial index, false otherwise.
169 bool IsPartial() const;
170
171 /// The DWARF file which we are indexing.
173 /// Which dwarf units should we skip while building the index.
174 llvm::DenseSet<dw_offset_t> m_units_to_avoid;
175 llvm::DenseSet<uint64_t> m_type_sigs_to_avoid;
176
178 std::once_flag m_indexed_flag;
179};
180} // namespace dwarf
181} // namespace lldb_private::plugin
182
183#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:973
A class that describes an executable image and its associated object and symbol files.
Definition Module.h:92
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 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
bool Decode(const DataExtractor &data, lldb::offset_t *offset_ptr)
Decode a serialized version of this object from data.
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:86
LanguageType
Programming language type.