LLDB mainline
SymbolFilePDB.h
Go to the documentation of this file.
1//===-- SymbolFilePDB.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_PDB_SYMBOLFILEPDB_H
10#define LLDB_SOURCE_PLUGINS_SYMBOLFILE_PDB_SYMBOLFILEPDB_H
11
15#include "lldb/Utility/UserID.h"
16
17#include "llvm/ADT/DenseMap.h"
18#include "llvm/DebugInfo/PDB/IPDBSession.h"
19#include "llvm/DebugInfo/PDB/PDB.h"
20#include "llvm/DebugInfo/PDB/PDBSymbolExe.h"
21#include <optional>
22
23class PDBASTParser;
24
26 /// LLVM RTTI support.
27 static char ID;
28
29public:
30 /// LLVM RTTI support.
31 /// \{
32 bool isA(const void *ClassID) const override {
33 return ClassID == &ID || SymbolFileCommon::isA(ClassID);
34 }
35 static bool classof(const SymbolFile *obj) { return obj->isA(&ID); }
36 /// \}
37
38 // Static Functions
39 static void Initialize();
40
41 static void Terminate();
42
43 static void DebuggerInitialize(lldb_private::Debugger &debugger);
44
45 static llvm::StringRef GetPluginNameStatic() { return "pdb"; }
46
47 static llvm::StringRef GetPluginDescriptionStatic();
48
51
52 static bool UseNativePDB();
53
54 // Constructors and Destructors
56
57 ~SymbolFilePDB() override;
58
59 uint32_t CalculateAbilities() override;
60
61 void InitializeObject() override;
62
63 // Compile Unit function calls
64
66 ParseLanguage(lldb_private::CompileUnit &comp_unit) override;
67
68 size_t ParseFunctions(lldb_private::CompileUnit &comp_unit) override;
69
70 bool ParseLineTable(lldb_private::CompileUnit &comp_unit) override;
71
72 bool ParseDebugMacros(lldb_private::CompileUnit &comp_unit) override;
73
75 lldb_private::SupportFileList &support_files) override;
76
77 size_t ParseTypes(lldb_private::CompileUnit &comp_unit) override;
78
81 std::vector<lldb_private::SourceModule> &imported_modules) override;
82
83 size_t ParseBlocksRecursive(lldb_private::Function &func) override;
84
85 size_t
87
89 std::optional<ArrayInfo> GetDynamicArrayInfoForUID(
90 lldb::user_id_t type_uid,
91 const lldb_private::ExecutionContext *exe_ctx) override;
92
93 bool CompleteType(lldb_private::CompilerType &compiler_type) override;
94
96
99
102
103 void
105
107 lldb::SymbolContextItem resolve_scope,
108 lldb_private::SymbolContext &sc) override;
109
111 const lldb_private::SourceLocationSpec &src_location_spec,
112 lldb::SymbolContextItem resolve_scope,
113 lldb_private::SymbolContextList &sc_list) override;
114
115 void
117 const lldb_private::CompilerDeclContext &parent_decl_ctx,
118 uint32_t max_matches,
119 lldb_private::VariableList &variables) override;
120
122 uint32_t max_matches,
123 lldb_private::VariableList &variables) override;
124
125 void FindFunctions(const lldb_private::Module::LookupInfo &lookup_info,
126 const lldb_private::CompilerDeclContext &parent_decl_ctx,
127 bool include_inlines,
128 lldb_private::SymbolContextList &sc_list) override;
129
131 bool include_inlines,
132 lldb_private::SymbolContextList &sc_list) override;
133
135 const std::string &scope_qualified_name,
136 std::vector<lldb_private::ConstString> &mangled_names) override;
137
138 void AddSymbols(lldb_private::Symtab &symtab) override;
139 void FindTypes(const lldb_private::TypeQuery &match,
140 lldb_private::TypeResults &results) override;
142 uint32_t max_matches, lldb_private::TypeMap &types);
143
145 lldb::TypeClass type_mask,
146 lldb_private::TypeList &type_list) override;
147
148 llvm::Expected<lldb::TypeSystemSP>
150
153 const lldb_private::CompilerDeclContext &parent_decl_ctx,
154 bool only_root_namespaces) override;
155
156 llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
157
158 llvm::pdb::IPDBSession &GetPDBSession();
159
160 const llvm::pdb::IPDBSession &GetPDBSession() const;
161
162 void DumpClangAST(lldb_private::Stream &s, llvm::StringRef filter,
163 bool show_color) override;
164
165private:
167 uint32_t Offset;
168 uint32_t Size;
169 uint32_t CompilandId;
170 };
171 using SecContribsMap = std::map<uint32_t, std::vector<SecContribInfo>>;
172
173 uint32_t CalculateNumCompileUnits() override;
174
175 lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override;
176
178 uint32_t index = UINT32_MAX);
179
181 uint32_t match_line);
182
184 const llvm::pdb::PDBSymbolCompiland &pdb_compiland,
185 llvm::DenseMap<uint32_t, uint32_t> &index_map) const;
186
187 void FindTypesByName(llvm::StringRef name,
188 const lldb_private::CompilerDeclContext &parent_decl_ctx,
189 uint32_t max_matches, lldb_private::TypeMap &types);
190
191 std::string GetMangledForPDBData(const llvm::pdb::PDBSymbolData &pdb_data);
192
195 const llvm::pdb::PDBSymbolData &pdb_data);
196
198 const llvm::pdb::PDBSymbol &pdb_data,
199 lldb_private::VariableList *variable_list = nullptr);
200
203
204 typedef std::vector<lldb_private::Type *> TypeCollection;
205
206 void GetTypesForPDBSymbol(const llvm::pdb::PDBSymbol &pdb_symbol,
207 uint32_t type_mask,
208 TypeCollection &type_collection);
209
211 ParseCompileUnitFunctionForPDBFunc(const llvm::pdb::PDBSymbolFunc &pdb_func,
212 lldb_private::CompileUnit &comp_unit);
213
214 void GetCompileUnitIndex(const llvm::pdb::PDBSymbolCompiland &pdb_compiland,
215 uint32_t &index);
216
218
219 std::unique_ptr<llvm::pdb::PDBSymbolCompiland>
220 GetPDBCompilandByUID(uint32_t uid);
221
223 GetMangledForPDBFunc(const llvm::pdb::PDBSymbolFunc &pdb_func);
224
225 bool ResolveFunction(const llvm::pdb::PDBSymbolFunc &pdb_func,
226 bool include_inlines,
228
229 bool ResolveFunction(uint32_t uid, bool include_inlines,
231
232 void CacheFunctionNames();
233
235 const lldb_private::CompilerDeclContext &decl_ctx);
236
237 uint32_t GetCompilandId(const llvm::pdb::PDBSymbolData &data);
238
239 llvm::DenseMap<uint32_t, lldb::CompUnitSP> m_comp_units;
240 llvm::DenseMap<uint32_t, lldb::TypeSP> m_types;
241 llvm::DenseMap<uint32_t, lldb::VariableSP> m_variables;
242 llvm::DenseMap<uint64_t, std::string> m_public_names;
243
245
246 std::vector<lldb::TypeSP> m_builtin_types;
247 std::unique_ptr<llvm::pdb::IPDBSession> m_session_up;
248 std::unique_ptr<llvm::pdb::PDBSymbolExe> m_global_scope_up;
249
253};
254
255#endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_PDB_SYMBOLFILEPDB_H
lldb_private::CompilerDeclContext GetDeclContextContainingUID(lldb::user_id_t uid) override
std::unique_ptr< llvm::pdb::PDBSymbolCompiland > GetPDBCompilandByUID(uint32_t uid)
static lldb_private::SymbolFile * CreateInstance(lldb::ObjectFileSP objfile_sp)
void DumpClangAST(lldb_private::Stream &s, llvm::StringRef filter, bool show_color) override
std::unique_ptr< llvm::pdb::IPDBSession > m_session_up
lldb::CompUnitSP GetCompileUnitContainsAddress(const lldb_private::Address &so_addr)
void GetMangledNamesForFunction(const std::string &scope_qualified_name, std::vector< lldb_private::ConstString > &mangled_names) override
void GetTypes(lldb_private::SymbolContextScope *sc_scope, lldb::TypeClass type_mask, lldb_private::TypeList &type_list) override
void FindFunctions(const lldb_private::Module::LookupInfo &lookup_info, const lldb_private::CompilerDeclContext &parent_decl_ctx, bool include_inlines, lldb_private::SymbolContextList &sc_list) override
lldb_private::CompilerDeclContext FindNamespace(lldb_private::ConstString name, const lldb_private::CompilerDeclContext &parent_decl_ctx, bool only_root_namespaces) override
Finds a namespace of name name and whose parent context is parent_decl_ctx.
std::unique_ptr< llvm::pdb::PDBSymbolExe > m_global_scope_up
llvm::DenseMap< uint32_t, lldb::CompUnitSP > m_comp_units
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.
size_t ParseTypes(lldb_private::CompileUnit &comp_unit) override
static llvm::StringRef GetPluginNameStatic()
bool ParseCompileUnitLineTable(lldb_private::CompileUnit &comp_unit, uint32_t match_line)
void BuildSupportFileIdToSupportFileIndexMap(const llvm::pdb::PDBSymbolCompiland &pdb_compiland, llvm::DenseMap< uint32_t, uint32_t > &index_map) const
lldb_private::Function * ParseCompileUnitFunctionForPDBFunc(const llvm::pdb::PDBSymbolFunc &pdb_func, lldb_private::CompileUnit &comp_unit)
static bool classof(const SymbolFile *obj)
lldb_private::UniqueCStringMap< uint32_t > m_func_base_names
bool ParseImportedModules(const lldb_private::SymbolContext &sc, std::vector< lldb_private::SourceModule > &imported_modules) override
bool isA(const void *ClassID) const override
LLVM RTTI support.
void FindGlobalVariables(lldb_private::ConstString name, const lldb_private::CompilerDeclContext &parent_decl_ctx, uint32_t max_matches, lldb_private::VariableList &variables) override
size_t ParseVariablesForContext(const lldb_private::SymbolContext &sc) override
static void Initialize()
bool ParseLineTable(lldb_private::CompileUnit &comp_unit) override
void GetCompileUnitIndex(const llvm::pdb::PDBSymbolCompiland &pdb_compiland, uint32_t &index)
llvm::DenseMap< uint32_t, lldb::TypeSP > m_types
void AddSymbols(lldb_private::Symtab &symtab) override
size_t ParseBlocksRecursive(lldb_private::Function &func) override
llvm::DenseMap< uint64_t, std::string > m_public_names
size_t ParseVariables(const lldb_private::SymbolContext &sc, const llvm::pdb::PDBSymbol &pdb_data, lldb_private::VariableList *variable_list=nullptr)
lldb::LanguageType ParseLanguage(lldb_private::CompileUnit &comp_unit) override
bool ParseDebugMacros(lldb_private::CompileUnit &comp_unit) override
void InitializeObject() override
Initialize the SymbolFile object.
static bool UseNativePDB()
uint32_t ResolveSymbolContext(const lldb_private::Address &so_addr, lldb::SymbolContextItem resolve_scope, lldb_private::SymbolContext &sc) override
PDBASTParser * GetPDBAstParser()
uint32_t CalculateNumCompileUnits() override
SymbolFilePDB(lldb::ObjectFileSP objfile_sp)
~SymbolFilePDB() override
uint32_t ResolveSymbolContext(const lldb_private::SourceLocationSpec &src_location_spec, lldb::SymbolContextItem resolve_scope, lldb_private::SymbolContextList &sc_list) override
uint32_t GetCompilandId(const llvm::pdb::PDBSymbolData &data)
std::vector< lldb::TypeSP > m_builtin_types
llvm::pdb::IPDBSession & GetPDBSession()
bool ParseSupportFiles(lldb_private::CompileUnit &comp_unit, lldb_private::SupportFileList &support_files) override
static char ID
LLVM RTTI support.
void FindTypesByRegex(const lldb_private::RegularExpression &regex, uint32_t max_matches, lldb_private::TypeMap &types)
size_t ParseFunctions(lldb_private::CompileUnit &comp_unit) override
lldb::CompUnitSP ParseCompileUnitForUID(uint32_t id, uint32_t index=UINT32_MAX)
lldb_private::Mangled GetMangledForPDBFunc(const llvm::pdb::PDBSymbolFunc &pdb_func)
llvm::StringRef GetPluginName() override
std::vector< lldb_private::Type * > TypeCollection
std::map< uint32_t, std::vector< SecContribInfo > > SecContribsMap
void ParseDeclsForContext(lldb_private::CompilerDeclContext decl_ctx) override
void GetTypesForPDBSymbol(const llvm::pdb::PDBSymbol &pdb_symbol, uint32_t type_mask, TypeCollection &type_collection)
bool CompleteType(lldb_private::CompilerType &compiler_type) override
static void DebuggerInitialize(lldb_private::Debugger &debugger)
static llvm::StringRef GetPluginDescriptionStatic()
lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override
std::string GetMangledForPDBData(const llvm::pdb::PDBSymbolData &pdb_data)
lldb_private::Type * ResolveTypeUID(lldb::user_id_t type_uid) override
lldb_private::UniqueCStringMap< uint32_t > m_func_full_names
static void Terminate()
lldb_private::UniqueCStringMap< uint32_t > m_func_method_names
bool DeclContextMatchesThisSymbolFile(const lldb_private::CompilerDeclContext &decl_ctx)
lldb_private::CompilerDeclContext GetDeclContextForUID(lldb::user_id_t uid) override
void FindTypes(const lldb_private::TypeQuery &match, lldb_private::TypeResults &results) override
Find types using a type-matching object that contains all search parameters.
llvm::Expected< lldb::TypeSystemSP > GetTypeSystemForLanguage(lldb::LanguageType language) override
SecContribsMap m_sec_contribs
lldb::VariableSP ParseVariableForPDBData(const lldb_private::SymbolContext &sc, const llvm::pdb::PDBSymbolData &pdb_data)
bool ResolveFunction(const llvm::pdb::PDBSymbolFunc &pdb_func, bool include_inlines, lldb_private::SymbolContextList &sc_list)
uint32_t CalculateAbilities() override
llvm::DenseMap< uint32_t, lldb::VariableSP > m_variables
void FindTypesByName(llvm::StringRef name, const lldb_private::CompilerDeclContext &parent_decl_ctx, uint32_t max_matches, lldb_private::TypeMap &types)
lldb_private::CompilerDecl GetDeclForUID(lldb::user_id_t uid) override
A section + offset based address class.
Definition Address.h:62
A class that describes a compilation unit.
Definition CompileUnit.h:43
Represents a generic declaration context in a program.
Represents a generic declaration such as a function declaration.
Generic representation of a type in a programming language.
A uniqued constant string class.
Definition ConstString.h:40
A class to manage flag bits.
Definition Debugger.h:80
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
A class that describes a function.
Definition Function.h:400
A class that handles mangled names.
Definition Mangled.h:34
A class that encapsulates name lookup information.
Definition Module.h:916
"lldb/Core/SourceLocationSpec.h" A source location specifier class.
A stream class that can stream formatted output to a file.
Definition Stream.h:28
A list of support files for a CompileUnit.
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.
Containing protected virtual methods for child classes to override.
Definition SymbolFile.h:537
Provides public interface for all SymbolFiles.
Definition SymbolFile.h:51
A class that contains all state required for type lookups.
Definition Type.h:104
This class tracks the state and results of a TypeQuery.
Definition Type.h:344
#define UINT32_MAX
std::shared_ptr< lldb_private::ObjectFile > ObjectFileSP
LanguageType
Programming language type.
std::shared_ptr< lldb_private::Variable > VariableSP
uint64_t user_id_t
Definition lldb-types.h:82
std::shared_ptr< lldb_private::CompileUnit > CompUnitSP