1 //===-- SymbolFilePDB.h -------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef lldb_Plugins_SymbolFile_PDB_SymbolFilePDB_h_
10 #define lldb_Plugins_SymbolFile_PDB_SymbolFilePDB_h_
12 #include "lldb/Core/UniqueCStringMap.h"
13 #include "lldb/Symbol/SymbolFile.h"
14 #include "lldb/Symbol/VariableList.h"
15 #include "lldb/Utility/UserID.h"
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"
24 class SymbolFilePDB : public lldb_private::SymbolFile {
27 static void Initialize();
29 static void Terminate();
31 static void DebuggerInitialize(lldb_private::Debugger &debugger);
33 static lldb_private::ConstString GetPluginNameStatic();
35 static const char *GetPluginDescriptionStatic();
37 static lldb_private::SymbolFile *
38 CreateInstance(lldb_private::ObjectFile *obj_file);
40 // Constructors and Destructors
41 SymbolFilePDB(lldb_private::ObjectFile *ofile);
43 ~SymbolFilePDB() override;
45 uint32_t CalculateAbilities() override;
47 void InitializeObject() override;
49 // Compile Unit function calls
51 uint32_t GetNumCompileUnits() override;
53 lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override;
56 ParseLanguage(lldb_private::CompileUnit &comp_unit) override;
58 size_t ParseFunctions(lldb_private::CompileUnit &comp_unit) override;
60 bool ParseLineTable(lldb_private::CompileUnit &comp_unit) override;
62 bool ParseDebugMacros(lldb_private::CompileUnit &comp_unit) override;
64 bool ParseSupportFiles(lldb_private::CompileUnit &comp_unit,
65 lldb_private::FileSpecList &support_files) override;
67 size_t ParseTypes(lldb_private::CompileUnit &comp_unit) override;
69 bool ParseImportedModules(
70 const lldb_private::SymbolContext &sc,
71 std::vector<lldb_private::SourceModule> &imported_modules) override;
73 size_t ParseBlocksRecursive(lldb_private::Function &func) override;
76 ParseVariablesForContext(const lldb_private::SymbolContext &sc) override;
78 lldb_private::Type *ResolveTypeUID(lldb::user_id_t type_uid) override;
79 llvm::Optional<ArrayInfo> GetDynamicArrayInfoForUID(
80 lldb::user_id_t type_uid,
81 const lldb_private::ExecutionContext *exe_ctx) override;
83 bool CompleteType(lldb_private::CompilerType &compiler_type) override;
85 lldb_private::CompilerDecl GetDeclForUID(lldb::user_id_t uid) override;
87 lldb_private::CompilerDeclContext
88 GetDeclContextForUID(lldb::user_id_t uid) override;
90 lldb_private::CompilerDeclContext
91 GetDeclContextContainingUID(lldb::user_id_t uid) override;
94 ParseDeclsForContext(lldb_private::CompilerDeclContext decl_ctx) override;
96 uint32_t ResolveSymbolContext(const lldb_private::Address &so_addr,
97 lldb::SymbolContextItem resolve_scope,
98 lldb_private::SymbolContext &sc) override;
101 ResolveSymbolContext(const lldb_private::FileSpec &file_spec, uint32_t line,
103 lldb::SymbolContextItem resolve_scope,
104 lldb_private::SymbolContextList &sc_list) override;
107 FindGlobalVariables(lldb_private::ConstString name,
108 const lldb_private::CompilerDeclContext *parent_decl_ctx,
109 uint32_t max_matches,
110 lldb_private::VariableList &variables) override;
112 uint32_t FindGlobalVariables(const lldb_private::RegularExpression ®ex,
113 uint32_t max_matches,
114 lldb_private::VariableList &variables) override;
117 FindFunctions(lldb_private::ConstString name,
118 const lldb_private::CompilerDeclContext *parent_decl_ctx,
119 lldb::FunctionNameType name_type_mask, bool include_inlines,
120 bool append, lldb_private::SymbolContextList &sc_list) override;
122 uint32_t FindFunctions(const lldb_private::RegularExpression ®ex,
123 bool include_inlines, bool append,
124 lldb_private::SymbolContextList &sc_list) override;
126 void GetMangledNamesForFunction(
127 const std::string &scope_qualified_name,
128 std::vector<lldb_private::ConstString> &mangled_names) override;
130 void AddSymbols(lldb_private::Symtab &symtab) override;
133 FindTypes(lldb_private::ConstString name,
134 const lldb_private::CompilerDeclContext *parent_decl_ctx,
135 bool append, uint32_t max_matches,
136 llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
137 lldb_private::TypeMap &types) override;
139 size_t FindTypes(const std::vector<lldb_private::CompilerContext> &context,
140 bool append, lldb_private::TypeMap &types) override;
142 void FindTypesByRegex(const lldb_private::RegularExpression ®ex,
143 uint32_t max_matches, lldb_private::TypeMap &types);
145 lldb_private::TypeList *GetTypeList() override;
147 size_t GetTypes(lldb_private::SymbolContextScope *sc_scope,
148 lldb::TypeClass type_mask,
149 lldb_private::TypeList &type_list) override;
151 lldb_private::TypeSystem *
152 GetTypeSystemForLanguage(lldb::LanguageType language) override;
154 lldb_private::CompilerDeclContext FindNamespace(
155 lldb_private::ConstString name,
156 const lldb_private::CompilerDeclContext *parent_decl_ctx) override;
158 lldb_private::ConstString GetPluginName() override;
160 uint32_t GetPluginVersion() override;
162 llvm::pdb::IPDBSession &GetPDBSession();
164 const llvm::pdb::IPDBSession &GetPDBSession() const;
166 void DumpClangAST(lldb_private::Stream &s) override;
169 struct SecContribInfo {
172 uint32_t CompilandId;
174 using SecContribsMap = std::map<uint32_t, std::vector<SecContribInfo>>;
176 lldb::CompUnitSP ParseCompileUnitForUID(uint32_t id,
177 uint32_t index = UINT32_MAX);
179 bool ParseCompileUnitLineTable(lldb_private::CompileUnit &comp_unit,
180 uint32_t match_line);
182 void BuildSupportFileIdToSupportFileIndexMap(
183 const llvm::pdb::PDBSymbolCompiland &pdb_compiland,
184 llvm::DenseMap<uint32_t, uint32_t> &index_map) const;
186 void FindTypesByName(llvm::StringRef name,
187 const lldb_private::CompilerDeclContext *parent_decl_ctx,
188 uint32_t max_matches, lldb_private::TypeMap &types);
190 std::string GetMangledForPDBData(const llvm::pdb::PDBSymbolData &pdb_data);
193 ParseVariableForPDBData(const lldb_private::SymbolContext &sc,
194 const llvm::pdb::PDBSymbolData &pdb_data);
196 size_t ParseVariables(const lldb_private::SymbolContext &sc,
197 const llvm::pdb::PDBSymbol &pdb_data,
198 lldb_private::VariableList *variable_list = nullptr);
201 GetCompileUnitContainsAddress(const lldb_private::Address &so_addr);
203 typedef std::vector<lldb_private::Type *> TypeCollection;
205 void GetTypesForPDBSymbol(const llvm::pdb::PDBSymbol &pdb_symbol,
207 TypeCollection &type_collection);
209 lldb_private::Function *
210 ParseCompileUnitFunctionForPDBFunc(const llvm::pdb::PDBSymbolFunc &pdb_func,
211 lldb_private::CompileUnit &comp_unit);
213 void GetCompileUnitIndex(const llvm::pdb::PDBSymbolCompiland &pdb_compiland,
216 PDBASTParser *GetPDBAstParser();
218 std::unique_ptr<llvm::pdb::PDBSymbolCompiland>
219 GetPDBCompilandByUID(uint32_t uid);
221 lldb_private::Mangled
222 GetMangledForPDBFunc(const llvm::pdb::PDBSymbolFunc &pdb_func);
224 bool ResolveFunction(const llvm::pdb::PDBSymbolFunc &pdb_func,
225 bool include_inlines,
226 lldb_private::SymbolContextList &sc_list);
228 bool ResolveFunction(uint32_t uid, bool include_inlines,
229 lldb_private::SymbolContextList &sc_list);
231 void CacheFunctionNames();
233 bool DeclContextMatchesThisSymbolFile(
234 const lldb_private::CompilerDeclContext *decl_ctx);
236 uint32_t GetCompilandId(const llvm::pdb::PDBSymbolData &data);
238 llvm::DenseMap<uint32_t, lldb::CompUnitSP> m_comp_units;
239 llvm::DenseMap<uint32_t, lldb::TypeSP> m_types;
240 llvm::DenseMap<uint32_t, lldb::VariableSP> m_variables;
241 llvm::DenseMap<uint64_t, std::string> m_public_names;
243 SecContribsMap m_sec_contribs;
245 std::vector<lldb::TypeSP> m_builtin_types;
246 std::unique_ptr<llvm::pdb::IPDBSession> m_session_up;
247 std::unique_ptr<llvm::pdb::PDBSymbolExe> m_global_scope_up;
248 uint32_t m_cached_compile_unit_count;
250 lldb_private::UniqueCStringMap<uint32_t> m_func_full_names;
251 lldb_private::UniqueCStringMap<uint32_t> m_func_base_names;
252 lldb_private::UniqueCStringMap<uint32_t> m_func_method_names;
255 #endif // lldb_Plugins_SymbolFile_PDB_SymbolFilePDB_h_