LLDB mainline
SymbolFileNativePDB.h
Go to the documentation of this file.
1//===-- SymbolFileNativePDB.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_NATIVEPDB_SYMBOLFILENATIVEPDB_H
10#define LLDB_SOURCE_PLUGINS_SYMBOLFILE_NATIVEPDB_SYMBOLFILENATIVEPDB_H
11
14
15#include "llvm/ADT/DenseMap.h"
16#include "llvm/DebugInfo/CodeView/CVRecord.h"
17#include "llvm/DebugInfo/CodeView/SymbolRecord.h"
18#include "llvm/DebugInfo/PDB/PDBTypes.h"
19
20#include "CompileUnitIndex.h"
21#include "PdbIndex.h"
22#include "PdbAstBuilder.h"
23#include <optional>
24
25namespace clang {
26class TagDecl;
27}
28
29namespace llvm {
30namespace codeview {
31class ClassRecord;
32class EnumRecord;
33class ModifierRecord;
34class PointerRecord;
35struct UnionRecord;
36} // namespace codeview
37} // namespace llvm
38
39namespace lldb_private {
40
41namespace npdb {
42
44 friend class UdtRecordCompleter;
45
46 /// LLVM RTTI support.
47 static char ID;
48
49public:
50 /// LLVM RTTI support.
51 /// \{
52 bool isA(const void *ClassID) const override {
53 return ClassID == &ID || SymbolFileCommon::isA(ClassID);
54 }
55 static bool classof(const SymbolFile *obj) { return obj->isA(&ID); }
56 /// \}
57
58 // Static Functions
59 static void Initialize();
60
61 static void Terminate();
62
63 static void DebuggerInitialize(Debugger &debugger);
64
65 static llvm::StringRef GetPluginNameStatic() { return "native-pdb"; }
66
67 static llvm::StringRef GetPluginDescriptionStatic();
68
70
71 // Constructors and Destructors
73
75
76 uint32_t CalculateAbilities() override;
77
78 void InitializeObject() override;
79
80 uint64_t GetDebugInfoSize() override;
81
82 // Compile Unit function calls
83
84 void
86
88 ParseLanguage(lldb_private::CompileUnit &comp_unit) override;
89
90 size_t ParseFunctions(lldb_private::CompileUnit &comp_unit) override;
91
92 bool ParseLineTable(lldb_private::CompileUnit &comp_unit) override;
93
94 bool ParseDebugMacros(lldb_private::CompileUnit &comp_unit) override;
95
97 FileSpecList &support_files) override;
98 size_t ParseTypes(lldb_private::CompileUnit &comp_unit) override;
99
101 const SymbolContext &sc,
102 std::vector<lldb_private::SourceModule> &imported_modules) override;
103
104 size_t ParseBlocksRecursive(Function &func) override;
105
107 const CompilerDeclContext &parent_decl_ctx,
108 uint32_t max_matches,
109 VariableList &variables) override;
110
111 size_t ParseVariablesForContext(const SymbolContext &sc) override;
112
113 void AddSymbols(Symtab &symtab) override;
114
118 Type *ResolveTypeUID(lldb::user_id_t type_uid) override;
119 std::optional<ArrayInfo> GetDynamicArrayInfoForUID(
120 lldb::user_id_t type_uid,
121 const lldb_private::ExecutionContext *exe_ctx) override;
122
123 bool CompleteType(CompilerType &compiler_type) override;
124 uint32_t ResolveSymbolContext(const Address &so_addr,
125 lldb::SymbolContextItem resolve_scope,
126 SymbolContext &sc) override;
127 uint32_t ResolveSymbolContext(const SourceLocationSpec &src_location_spec,
128 lldb::SymbolContextItem resolve_scope,
129 SymbolContextList &sc_list) override;
130
131 void GetTypes(SymbolContextScope *sc_scope, lldb::TypeClass type_mask,
132 TypeList &type_list) override;
133
134 void FindFunctions(const Module::LookupInfo &lookup_info,
135 const CompilerDeclContext &parent_decl_ctx,
136 bool include_inlines, SymbolContextList &sc_list) override;
137
138 void FindFunctions(const RegularExpression &regex, bool include_inlines,
139 SymbolContextList &sc_list) override;
140
141 std::optional<PdbCompilandSymId> FindSymbolScope(PdbCompilandSymId id);
142
143 void FindTypes(ConstString name, const CompilerDeclContext &parent_decl_ctx,
144 uint32_t max_matches,
145 llvm::DenseSet<SymbolFile *> &searched_symbol_files,
146 TypeMap &types) override;
147
148 void FindTypes(llvm::ArrayRef<CompilerContext> pattern, LanguageSet languages,
149 llvm::DenseSet<SymbolFile *> &searched_symbol_files,
150 TypeMap &types) override;
151
152 llvm::Expected<lldb::TypeSystemSP>
154
156 const CompilerDeclContext &parent_decl_ctx,
157 bool only_root_namespaces) override;
158
159 llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
160
161 llvm::pdb::PDBFile &GetPDBFile() { return m_index->pdb(); }
162 const llvm::pdb::PDBFile &GetPDBFile() const { return m_index->pdb(); }
163
164 PdbIndex &GetIndex() { return *m_index; };
165
166 void DumpClangAST(Stream &s) override;
167
168 std::optional<llvm::codeview::TypeIndex>
169 GetParentType(llvm::codeview::TypeIndex ti);
170
171private:
174 const lldb_private::LineTable::Entry &rhs) const {
175 return lhs.file_addr < rhs.file_addr;
176 }
177 };
178
179 // From address range relative to function base to source line number.
182 // InlineSite contains information in a S_INLINESITE record.
183 struct InlineSite {
185 std::shared_ptr<InlineFunctionInfo> inline_function_info;
187 std::vector<lldb_private::LineTable::Entry> line_entries;
189 };
190
191 void BuildParentMap();
192
193 uint32_t CalculateNumCompileUnits() override;
194
195 lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override;
196
197 void FindTypesByName(llvm::StringRef name, uint32_t max_matches,
198 TypeMap &types);
199
201 const llvm::codeview::ModifierRecord &mr,
202 CompilerType ct);
204 const llvm::codeview::PointerRecord &pr,
205 CompilerType ct);
206 lldb::TypeSP CreateSimpleType(llvm::codeview::TypeIndex ti, CompilerType ct);
208 const llvm::codeview::ClassRecord &cr,
209 CompilerType ct);
211 const llvm::codeview::EnumRecord &er,
212 CompilerType ct);
214 const llvm::codeview::UnionRecord &ur,
215 CompilerType ct);
217 const llvm::codeview::ArrayRecord &ar,
218 CompilerType ct);
220 const llvm::codeview::MemberFunctionRecord &pr,
221 CompilerType ct);
223 const llvm::codeview::ProcedureRecord &pr,
224 CompilerType ct);
226 const llvm::codeview::TagRecord &record,
227 size_t size, CompilerType ct);
228
230 CompileUnit &comp_unit);
233 lldb::TypeSP GetOrCreateType(llvm::codeview::TypeIndex ti);
237 PdbCompilandSymId var_id,
238 bool is_param);
240
242 CompileUnit &comp_unit);
245 PdbCompilandSymId var_id, bool is_param);
252 const llvm::codeview::CVSymbol &cvs);
254 VariableList &variables);
256
257 llvm::Expected<uint32_t> GetFileIndex(const CompilandIndexItem &cii,
258 uint32_t file_id);
259
261 PdbCompilandSymId parent,
262 llvm::function_ref<bool(llvm::codeview::SymbolKind, PdbCompilandSymId)>
263 fn);
264
265 void ParseInlineSite(PdbCompilandSymId inline_site_id, Address func_addr);
266
267 llvm::BumpPtrAllocator m_allocator;
268
271 // UID for anonymous union and anonymous struct as they don't have entities in
272 // pdb debug info.
274
275 std::unique_ptr<llvm::pdb::PDBFile> m_file_up;
276 std::unique_ptr<PdbIndex> m_index;
277
278 llvm::DenseMap<lldb::user_id_t, lldb::VariableSP> m_global_vars;
279 llvm::DenseMap<lldb::user_id_t, lldb::VariableSP> m_local_variables;
280 llvm::DenseMap<lldb::user_id_t, lldb::BlockSP> m_blocks;
281 llvm::DenseMap<lldb::user_id_t, lldb::FunctionSP> m_functions;
282 llvm::DenseMap<lldb::user_id_t, lldb::CompUnitSP> m_compilands;
283 llvm::DenseMap<lldb::user_id_t, lldb::TypeSP> m_types;
284 llvm::DenseMap<lldb::user_id_t, std::shared_ptr<InlineSite>> m_inline_sites;
285 llvm::DenseMap<llvm::codeview::TypeIndex, llvm::codeview::TypeIndex>
287};
288
289} // namespace npdb
290} // namespace lldb_private
291
292#endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_NATIVEPDB_SYMBOLFILENATIVEPDB_H
A section + offset based address class.
Definition: Address.h:59
A class that describes a single lexical block.
Definition: Block.h:41
A class that describes a compilation unit.
Definition: CompileUnit.h:41
Represents a generic declaration context in a program.
Represents a generic declaration such as a function declaration.
Definition: CompilerDecl.h:28
Generic representation of a type in a programming language.
Definition: CompilerType.h:36
A uniqued constant string class.
Definition: ConstString.h:40
A class to manage flag bits.
Definition: Debugger.h:79
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
A file collection class.
Definition: FileSpecList.h:24
A class that describes a function.
Definition: Function.h:399
A class that encapsulates name lookup information.
Definition: Module.h:949
"lldb/Core/SourceLocationSpec.h" A source location specifier class.
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
Defines a list of symbol context objects.
"lldb/Symbol/SymbolContextScope.h" Inherit from this if your object is part of a symbol context and c...
Defines a symbol context baton that can be handed other debug core functions.
Definition: SymbolContext.h:33
Containing protected virtual methods for child classes to override.
Definition: SymbolFile.h:469
bool isA(const void *ClassID) const override
LLVM RTTI support.
Definition: SymbolFile.h:476
Provides public interface for all SymbolFiles.
Definition: SymbolFile.h:49
virtual bool isA(const void *ClassID) const
LLVM RTTI support.
Definition: SymbolFile.h:56
PdbIndex - Lazy access to the important parts of a PDB file.
Definition: PdbIndex.h:47
lldb::VariableSP GetOrCreateGlobalVariable(PdbGlobalSymId var_id)
bool ParseLineTable(lldb_private::CompileUnit &comp_unit) override
lldb::TypeSP CreateArrayType(PdbTypeSymId type_id, const llvm::codeview::ArrayRecord &ar, CompilerType ct)
std::optional< ArrayInfo > GetDynamicArrayInfoForUID(lldb::user_id_t type_uid, const lldb_private::ExecutionContext *exe_ctx) override
If type_uid points to an array type, return its characteristics.
lldb::VariableSP CreateGlobalVariable(PdbGlobalSymId var_id)
llvm::Expected< lldb::TypeSystemSP > GetTypeSystemForLanguage(lldb::LanguageType language) override
void InitializeObject() override
Initialize the SymbolFile object.
static SymbolFile * CreateInstance(lldb::ObjectFileSP objfile_sp)
llvm::DenseMap< lldb::user_id_t, lldb::TypeSP > m_types
bool CompleteType(CompilerType &compiler_type) override
lldb::LanguageType ParseLanguage(lldb_private::CompileUnit &comp_unit) override
CompilerDeclContext GetDeclContextForUID(lldb::user_id_t uid) override
lldb::VariableSP GetOrCreateLocalVariable(PdbCompilandSymId scope_id, PdbCompilandSymId var_id, bool is_param)
Block & CreateBlock(PdbCompilandSymId block_id)
size_t ParseVariablesForContext(const SymbolContext &sc) override
size_t ParseFunctions(lldb_private::CompileUnit &comp_unit) override
lldb::TypeSP CreatePointerType(PdbTypeSymId type_id, const llvm::codeview::PointerRecord &pr, CompilerType ct)
lldb::FunctionSP CreateFunction(PdbCompilandSymId func_id, CompileUnit &comp_unit)
llvm::DenseMap< lldb::user_id_t, lldb::BlockSP > m_blocks
CompilerDecl GetDeclForUID(lldb::user_id_t uid) override
bool isA(const void *ClassID) const override
LLVM RTTI support.
lldb::TypeSP GetOrCreateTypedef(PdbGlobalSymId id)
void FindTypesByName(llvm::StringRef name, uint32_t max_matches, TypeMap &types)
lldb::TypeSP CreateTagType(PdbTypeSymId type_id, const llvm::codeview::ClassRecord &cr, CompilerType ct)
lldb::TypeSP GetOrCreateType(PdbTypeSymId type_id)
lldb::TypeSP CreateTagType(PdbTypeSymId type_id, const llvm::codeview::UnionRecord &ur, CompilerType ct)
void GetTypes(SymbolContextScope *sc_scope, lldb::TypeClass type_mask, TypeList &type_list) override
llvm::DenseMap< lldb::user_id_t, lldb::VariableSP > m_local_variables
lldb::VariableSP CreateConstantSymbol(PdbGlobalSymId var_id, const llvm::codeview::CVSymbol &cvs)
lldb::TypeSP CreateType(PdbTypeSymId type_id, CompilerType ct)
void FindTypes(ConstString name, const CompilerDeclContext &parent_decl_ctx, uint32_t max_matches, llvm::DenseSet< SymbolFile * > &searched_symbol_files, TypeMap &types) override
std::optional< llvm::codeview::TypeIndex > GetParentType(llvm::codeview::TypeIndex ti)
void FindFunctions(const Module::LookupInfo &lookup_info, const CompilerDeclContext &parent_decl_ctx, bool include_inlines, SymbolContextList &sc_list) override
static llvm::StringRef GetPluginDescriptionStatic()
std::unique_ptr< llvm::pdb::PDBFile > m_file_up
lldb::VariableSP CreateLocalVariable(PdbCompilandSymId scope_id, PdbCompilandSymId var_id, bool is_param)
lldb::TypeSP CreateProcedureType(PdbTypeSymId type_id, const llvm::codeview::ProcedureRecord &pr, CompilerType ct)
lldb::TypeSP CreateModifierType(PdbTypeSymId type_id, const llvm::codeview::ModifierRecord &mr, CompilerType ct)
size_t ParseTypes(lldb_private::CompileUnit &comp_unit) override
size_t ParseBlocksRecursive(Function &func) override
lldb::CompUnitSP CreateCompileUnit(const CompilandIndexItem &cci)
std::optional< PdbCompilandSymId > FindSymbolScope(PdbCompilandSymId id)
size_t ParseSymbolArrayInScope(PdbCompilandSymId parent, llvm::function_ref< bool(llvm::codeview::SymbolKind, PdbCompilandSymId)> fn)
const llvm::pdb::PDBFile & GetPDBFile() const
size_t ParseVariablesForCompileUnit(CompileUnit &comp_unit, VariableList &variables)
llvm::DenseMap< lldb::user_id_t, lldb::CompUnitSP > m_compilands
bool ParseSupportFiles(lldb_private::CompileUnit &comp_unit, FileSpecList &support_files) override
llvm::Expected< uint32_t > GetFileIndex(const CompilandIndexItem &cii, uint32_t file_id)
lldb::CompUnitSP GetOrCreateCompileUnit(const CompilandIndexItem &cci)
Type * ResolveTypeUID(lldb::user_id_t type_uid) override
llvm::DenseMap< lldb::user_id_t, lldb::FunctionSP > m_functions
bool ParseImportedModules(const SymbolContext &sc, std::vector< lldb_private::SourceModule > &imported_modules) override
static void DebuggerInitialize(Debugger &debugger)
llvm::DenseMap< lldb::user_id_t, std::shared_ptr< InlineSite > > m_inline_sites
void ParseInlineSite(PdbCompilandSymId inline_site_id, Address func_addr)
lldb::TypeSP CreateTagType(PdbTypeSymId type_id, const llvm::codeview::EnumRecord &er, CompilerType ct)
lldb::TypeSP CreateClassStructUnion(PdbTypeSymId type_id, const llvm::codeview::TagRecord &record, size_t size, CompilerType ct)
void FindGlobalVariables(ConstString name, const CompilerDeclContext &parent_decl_ctx, uint32_t max_matches, VariableList &variables) override
static llvm::StringRef GetPluginNameStatic()
size_t ParseVariablesForBlock(PdbCompilandSymId block_id)
void ParseDeclsForContext(lldb_private::CompilerDeclContext decl_ctx) override
lldb::FunctionSP GetOrCreateFunction(PdbCompilandSymId func_id, CompileUnit &comp_unit)
Block & GetOrCreateBlock(PdbCompilandSymId block_id)
llvm::DenseMap< llvm::codeview::TypeIndex, llvm::codeview::TypeIndex > m_parent_types
lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override
lldb::TypeSP CreateFunctionType(PdbTypeSymId type_id, const llvm::codeview::MemberFunctionRecord &pr, CompilerType ct)
lldb::TypeSP CreateAndCacheType(PdbTypeSymId type_id)
CompilerDeclContext FindNamespace(ConstString name, const CompilerDeclContext &parent_decl_ctx, bool only_root_namespaces) override
Finds a namespace of name name and whose parent context is parent_decl_ctx.
CompilerDeclContext GetDeclContextContainingUID(lldb::user_id_t uid) override
bool ParseDebugMacros(lldb_private::CompileUnit &comp_unit) override
lldb::TypeSP CreateTypedef(PdbGlobalSymId id)
uint64_t GetDebugInfoSize() override
Metrics gathering functions.
lldb::TypeSP GetOrCreateType(llvm::codeview::TypeIndex ti)
static bool classof(const SymbolFile *obj)
uint32_t ResolveSymbolContext(const Address &so_addr, lldb::SymbolContextItem resolve_scope, SymbolContext &sc) override
llvm::DenseMap< lldb::user_id_t, lldb::VariableSP > m_global_vars
lldb::TypeSP CreateSimpleType(llvm::codeview::TypeIndex ti, CompilerType ct)
#define LLDB_INVALID_UID
Definition: lldb-defines.h:82
A class that represents a running process on the host machine.
Definition: SBAttachInfo.h:14
std::shared_ptr< lldb_private::Function > FunctionSP
Definition: lldb-forward.h:336
std::shared_ptr< lldb_private::ObjectFile > ObjectFileSP
Definition: lldb-forward.h:356
LanguageType
Programming language type.
std::shared_ptr< lldb_private::Type > TypeSP
Definition: lldb-forward.h:436
std::shared_ptr< lldb_private::Variable > VariableSP
Definition: lldb-forward.h:460
uint64_t user_id_t
Definition: lldb-types.h:80
uint64_t addr_t
Definition: lldb-types.h:79
std::shared_ptr< lldb_private::CompileUnit > CompUnitSP
Definition: lldb-forward.h:317
Definition: Debugger.h:53
A SmallBitVector that represents a set of source languages (lldb::LanguageType).
Definition: TypeSystem.h:45
lldb::addr_t file_addr
The file address for this line entry.
Definition: LineTable.h:280
Represents a single compile unit.
std::vector< lldb_private::LineTable::Entry > line_entries
std::shared_ptr< InlineFunctionInfo > inline_function_info
bool operator()(const lldb_private::LineTable::Entry &lhs, const lldb_private::LineTable::Entry &rhs) const