1 //===-- SymbolFileNativePDB.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_NATIVEPDB_SYMBOLFILENATIVEPDB_H
10 #define LLDB_PLUGINS_SYMBOLFILE_NATIVEPDB_SYMBOLFILENATIVEPDB_H
12 #include "lldb/Symbol/ClangASTImporter.h"
13 #include "lldb/Symbol/SymbolFile.h"
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"
20 #include "CompileUnitIndex.h"
34 } // namespace codeview
37 namespace lldb_private {
38 class ClangASTImporter;
43 class SymbolFileNativePDB : public SymbolFile {
44 friend class UdtRecordCompleter;
48 static void Initialize();
50 static void Terminate();
52 static void DebuggerInitialize(Debugger &debugger);
54 static ConstString GetPluginNameStatic();
56 static const char *GetPluginDescriptionStatic();
58 static SymbolFile *CreateInstance(ObjectFile *obj_file);
60 // Constructors and Destructors
61 SymbolFileNativePDB(ObjectFile *ofile);
63 ~SymbolFileNativePDB() override;
65 uint32_t CalculateAbilities() override;
67 void InitializeObject() override;
69 // Compile Unit function calls
71 uint32_t GetNumCompileUnits() override;
74 ParseDeclsForContext(lldb_private::CompilerDeclContext decl_ctx) override;
76 lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override;
79 ParseLanguage(lldb_private::CompileUnit &comp_unit) override;
81 size_t ParseFunctions(lldb_private::CompileUnit &comp_unit) override;
83 bool ParseLineTable(lldb_private::CompileUnit &comp_unit) override;
85 bool ParseDebugMacros(lldb_private::CompileUnit &comp_unit) override;
87 bool ParseSupportFiles(lldb_private::CompileUnit &comp_unit,
88 FileSpecList &support_files) override;
89 size_t ParseTypes(lldb_private::CompileUnit &comp_unit) override;
91 bool ParseImportedModules(
92 const SymbolContext &sc,
93 std::vector<lldb_private::SourceModule> &imported_modules) override;
95 size_t ParseBlocksRecursive(Function &func) override;
97 uint32_t FindGlobalVariables(ConstString name,
98 const CompilerDeclContext *parent_decl_ctx,
100 VariableList &variables) override;
102 size_t ParseVariablesForContext(const SymbolContext &sc) override;
104 void AddSymbols(Symtab &symtab) override;
106 CompilerDecl GetDeclForUID(lldb::user_id_t uid) override;
107 CompilerDeclContext GetDeclContextForUID(lldb::user_id_t uid) override;
108 CompilerDeclContext GetDeclContextContainingUID(lldb::user_id_t uid) override;
109 Type *ResolveTypeUID(lldb::user_id_t type_uid) override;
110 llvm::Optional<ArrayInfo> GetDynamicArrayInfoForUID(
111 lldb::user_id_t type_uid,
112 const lldb_private::ExecutionContext *exe_ctx) override;
114 bool CompleteType(CompilerType &compiler_type) override;
115 uint32_t ResolveSymbolContext(const Address &so_addr,
116 lldb::SymbolContextItem resolve_scope,
117 SymbolContext &sc) override;
118 uint32_t ResolveSymbolContext(const FileSpec &file_spec, uint32_t line,
120 lldb::SymbolContextItem resolve_scope,
121 SymbolContextList &sc_list) override;
123 size_t GetTypes(SymbolContextScope *sc_scope, lldb::TypeClass type_mask,
124 TypeList &type_list) override;
126 uint32_t FindFunctions(ConstString name,
127 const CompilerDeclContext *parent_decl_ctx,
128 lldb::FunctionNameType name_type_mask,
129 bool include_inlines, bool append,
130 SymbolContextList &sc_list) override;
132 uint32_t FindFunctions(const RegularExpression ®ex, bool include_inlines,
133 bool append, SymbolContextList &sc_list) override;
135 uint32_t FindTypes(ConstString name,
136 const CompilerDeclContext *parent_decl_ctx, bool append,
137 uint32_t max_matches,
138 llvm::DenseSet<SymbolFile *> &searched_symbol_files,
139 TypeMap &types) override;
141 size_t FindTypes(const std::vector<CompilerContext> &context, bool append,
142 TypeMap &types) override;
144 TypeSystem *GetTypeSystemForLanguage(lldb::LanguageType language) override;
147 FindNamespace(ConstString name,
148 const CompilerDeclContext *parent_decl_ctx) override;
150 ConstString GetPluginName() override;
152 uint32_t GetPluginVersion() override;
154 llvm::pdb::PDBFile &GetPDBFile() { return m_index->pdb(); }
155 const llvm::pdb::PDBFile &GetPDBFile() const { return m_index->pdb(); }
157 void DumpClangAST(Stream &s) override;
161 size_t FindTypesByName(llvm::StringRef name, uint32_t max_matches,
164 lldb::TypeSP CreateModifierType(PdbTypeSymId type_id,
165 const llvm::codeview::ModifierRecord &mr,
167 lldb::TypeSP CreatePointerType(PdbTypeSymId type_id,
168 const llvm::codeview::PointerRecord &pr,
170 lldb::TypeSP CreateSimpleType(llvm::codeview::TypeIndex ti, CompilerType ct);
171 lldb::TypeSP CreateTagType(PdbTypeSymId type_id,
172 const llvm::codeview::ClassRecord &cr,
174 lldb::TypeSP CreateTagType(PdbTypeSymId type_id,
175 const llvm::codeview::EnumRecord &er,
177 lldb::TypeSP CreateTagType(PdbTypeSymId type_id,
178 const llvm::codeview::UnionRecord &ur,
180 lldb::TypeSP CreateArrayType(PdbTypeSymId type_id,
181 const llvm::codeview::ArrayRecord &ar,
183 lldb::TypeSP CreateFunctionType(PdbTypeSymId type_id,
184 const llvm::codeview::MemberFunctionRecord &pr,
186 lldb::TypeSP CreateProcedureType(PdbTypeSymId type_id,
187 const llvm::codeview::ProcedureRecord &pr,
189 lldb::TypeSP CreateClassStructUnion(PdbTypeSymId type_id,
190 const llvm::codeview::TagRecord &record,
191 size_t size, CompilerType ct);
193 lldb::FunctionSP GetOrCreateFunction(PdbCompilandSymId func_id,
194 CompileUnit &comp_unit);
195 lldb::CompUnitSP GetOrCreateCompileUnit(const CompilandIndexItem &cci);
196 lldb::TypeSP GetOrCreateType(PdbTypeSymId type_id);
197 lldb::TypeSP GetOrCreateType(llvm::codeview::TypeIndex ti);
198 lldb::VariableSP GetOrCreateGlobalVariable(PdbGlobalSymId var_id);
199 Block &GetOrCreateBlock(PdbCompilandSymId block_id);
200 lldb::VariableSP GetOrCreateLocalVariable(PdbCompilandSymId scope_id,
201 PdbCompilandSymId var_id,
203 lldb::TypeSP GetOrCreateTypedef(PdbGlobalSymId id);
205 lldb::FunctionSP CreateFunction(PdbCompilandSymId func_id,
206 CompileUnit &comp_unit);
207 Block &CreateBlock(PdbCompilandSymId block_id);
208 lldb::VariableSP CreateLocalVariable(PdbCompilandSymId scope_id,
209 PdbCompilandSymId var_id, bool is_param);
210 lldb::TypeSP CreateTypedef(PdbGlobalSymId id);
211 lldb::CompUnitSP CreateCompileUnit(const CompilandIndexItem &cci);
212 lldb::TypeSP CreateType(PdbTypeSymId type_id, CompilerType ct);
213 lldb::TypeSP CreateAndCacheType(PdbTypeSymId type_id);
214 lldb::VariableSP CreateGlobalVariable(PdbGlobalSymId var_id);
215 lldb::VariableSP CreateConstantSymbol(PdbGlobalSymId var_id,
216 const llvm::codeview::CVSymbol &cvs);
217 size_t ParseVariablesForCompileUnit(CompileUnit &comp_unit,
218 VariableList &variables);
219 size_t ParseVariablesForBlock(PdbCompilandSymId block_id);
221 llvm::BumpPtrAllocator m_allocator;
223 lldb::addr_t m_obj_load_address = 0;
224 bool m_done_full_type_scan = false;
226 std::unique_ptr<PdbIndex> m_index;
228 std::unique_ptr<PdbAstBuilder> m_ast;
230 llvm::DenseMap<lldb::user_id_t, lldb::VariableSP> m_global_vars;
231 llvm::DenseMap<lldb::user_id_t, lldb::VariableSP> m_local_variables;
232 llvm::DenseMap<lldb::user_id_t, lldb::BlockSP> m_blocks;
233 llvm::DenseMap<lldb::user_id_t, lldb::FunctionSP> m_functions;
234 llvm::DenseMap<lldb::user_id_t, lldb::CompUnitSP> m_compilands;
235 llvm::DenseMap<lldb::user_id_t, lldb::TypeSP> m_types;
239 } // namespace lldb_private
241 #endif // lldb_Plugins_SymbolFile_PDB_SymbolFilePDB_h_