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