1 //===-- SymbolFilePDB.h -------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef lldb_Plugins_SymbolFile_PDB_SymbolFilePDB_h_
11 #define lldb_Plugins_SymbolFile_PDB_SymbolFilePDB_h_
13 #include "lldb/Core/UniqueCStringMap.h"
14 #include "lldb/Symbol/SymbolFile.h"
15 #include "lldb/Symbol/VariableList.h"
16 #include "lldb/Utility/UserID.h"
18 #include "llvm/ADT/DenseMap.h"
19 #include "llvm/DebugInfo/PDB/IPDBSession.h"
20 #include "llvm/DebugInfo/PDB/PDB.h"
21 #include "llvm/DebugInfo/PDB/PDBSymbolExe.h"
25 class SymbolFilePDB : public lldb_private::SymbolFile {
27 //------------------------------------------------------------------
29 //------------------------------------------------------------------
30 static void Initialize();
32 static void Terminate();
34 static void DebuggerInitialize(lldb_private::Debugger &debugger);
36 static lldb_private::ConstString GetPluginNameStatic();
38 static const char *GetPluginDescriptionStatic();
40 static lldb_private::SymbolFile *
41 CreateInstance(lldb_private::ObjectFile *obj_file);
43 //------------------------------------------------------------------
44 // Constructors and Destructors
45 //------------------------------------------------------------------
46 SymbolFilePDB(lldb_private::ObjectFile *ofile);
48 ~SymbolFilePDB() override;
50 uint32_t CalculateAbilities() override;
52 void InitializeObject() override;
54 //------------------------------------------------------------------
55 // Compile Unit function calls
56 //------------------------------------------------------------------
58 uint32_t GetNumCompileUnits() override;
60 lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override;
63 ParseLanguage(lldb_private::CompileUnit &comp_unit) override;
65 size_t ParseFunctions(lldb_private::CompileUnit &comp_unit) override;
67 bool ParseLineTable(lldb_private::CompileUnit &comp_unit) override;
69 bool ParseDebugMacros(lldb_private::CompileUnit &comp_unit) override;
71 bool ParseSupportFiles(lldb_private::CompileUnit &comp_unit,
72 lldb_private::FileSpecList &support_files) override;
74 size_t ParseTypes(lldb_private::CompileUnit &comp_unit) override;
76 bool ParseImportedModules(
77 const lldb_private::SymbolContext &sc,
78 std::vector<lldb_private::ConstString> &imported_modules) override;
80 size_t ParseBlocksRecursive(lldb_private::Function &func) override;
83 ParseVariablesForContext(const lldb_private::SymbolContext &sc) override;
85 lldb_private::Type *ResolveTypeUID(lldb::user_id_t type_uid) override;
86 llvm::Optional<ArrayInfo> GetDynamicArrayInfoForUID(
87 lldb::user_id_t type_uid,
88 const lldb_private::ExecutionContext *exe_ctx) override;
90 bool CompleteType(lldb_private::CompilerType &compiler_type) override;
92 lldb_private::CompilerDecl GetDeclForUID(lldb::user_id_t uid) override;
94 lldb_private::CompilerDeclContext
95 GetDeclContextForUID(lldb::user_id_t uid) override;
97 lldb_private::CompilerDeclContext
98 GetDeclContextContainingUID(lldb::user_id_t uid) override;
101 ParseDeclsForContext(lldb_private::CompilerDeclContext decl_ctx) override;
103 uint32_t ResolveSymbolContext(const lldb_private::Address &so_addr,
104 lldb::SymbolContextItem resolve_scope,
105 lldb_private::SymbolContext &sc) override;
108 ResolveSymbolContext(const lldb_private::FileSpec &file_spec, uint32_t line,
110 lldb::SymbolContextItem resolve_scope,
111 lldb_private::SymbolContextList &sc_list) override;
114 FindGlobalVariables(const lldb_private::ConstString &name,
115 const lldb_private::CompilerDeclContext *parent_decl_ctx,
116 uint32_t max_matches,
117 lldb_private::VariableList &variables) override;
119 uint32_t FindGlobalVariables(const lldb_private::RegularExpression ®ex,
120 uint32_t max_matches,
121 lldb_private::VariableList &variables) override;
124 FindFunctions(const lldb_private::ConstString &name,
125 const lldb_private::CompilerDeclContext *parent_decl_ctx,
126 lldb::FunctionNameType name_type_mask, bool include_inlines,
127 bool append, lldb_private::SymbolContextList &sc_list) override;
129 uint32_t FindFunctions(const lldb_private::RegularExpression ®ex,
130 bool include_inlines, bool append,
131 lldb_private::SymbolContextList &sc_list) override;
133 void GetMangledNamesForFunction(
134 const std::string &scope_qualified_name,
135 std::vector<lldb_private::ConstString> &mangled_names) override;
137 void AddSymbols(lldb_private::Symtab &symtab) override;
140 FindTypes(const lldb_private::ConstString &name,
141 const lldb_private::CompilerDeclContext *parent_decl_ctx,
142 bool append, uint32_t max_matches,
143 llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
144 lldb_private::TypeMap &types) override;
146 size_t FindTypes(const std::vector<lldb_private::CompilerContext> &context,
147 bool append, lldb_private::TypeMap &types) override;
149 void FindTypesByRegex(const lldb_private::RegularExpression ®ex,
150 uint32_t max_matches, lldb_private::TypeMap &types);
152 lldb_private::TypeList *GetTypeList() override;
154 size_t GetTypes(lldb_private::SymbolContextScope *sc_scope,
155 lldb::TypeClass type_mask,
156 lldb_private::TypeList &type_list) override;
158 lldb_private::TypeSystem *
159 GetTypeSystemForLanguage(lldb::LanguageType language) override;
161 lldb_private::CompilerDeclContext FindNamespace(
162 const lldb_private::ConstString &name,
163 const lldb_private::CompilerDeclContext *parent_decl_ctx) override;
165 lldb_private::ConstString GetPluginName() override;
167 uint32_t GetPluginVersion() override;
169 llvm::pdb::IPDBSession &GetPDBSession();
171 const llvm::pdb::IPDBSession &GetPDBSession() const;
173 void DumpClangAST(lldb_private::Stream &s) override;
176 struct SecContribInfo {
179 uint32_t CompilandId;
181 using SecContribsMap = std::map<uint32_t, std::vector<SecContribInfo>>;
183 lldb::CompUnitSP ParseCompileUnitForUID(uint32_t id,
184 uint32_t index = UINT32_MAX);
186 bool ParseCompileUnitLineTable(lldb_private::CompileUnit &comp_unit,
187 uint32_t match_line);
189 void BuildSupportFileIdToSupportFileIndexMap(
190 const llvm::pdb::PDBSymbolCompiland &pdb_compiland,
191 llvm::DenseMap<uint32_t, uint32_t> &index_map) const;
193 void FindTypesByName(llvm::StringRef name,
194 const lldb_private::CompilerDeclContext *parent_decl_ctx,
195 uint32_t max_matches, lldb_private::TypeMap &types);
197 std::string GetMangledForPDBData(const llvm::pdb::PDBSymbolData &pdb_data);
200 ParseVariableForPDBData(const lldb_private::SymbolContext &sc,
201 const llvm::pdb::PDBSymbolData &pdb_data);
203 size_t ParseVariables(const lldb_private::SymbolContext &sc,
204 const llvm::pdb::PDBSymbol &pdb_data,
205 lldb_private::VariableList *variable_list = nullptr);
208 GetCompileUnitContainsAddress(const lldb_private::Address &so_addr);
210 typedef std::vector<lldb_private::Type *> TypeCollection;
212 void GetTypesForPDBSymbol(const llvm::pdb::PDBSymbol &pdb_symbol,
214 TypeCollection &type_collection);
216 lldb_private::Function *
217 ParseCompileUnitFunctionForPDBFunc(const llvm::pdb::PDBSymbolFunc &pdb_func,
218 lldb_private::CompileUnit &comp_unit);
220 void GetCompileUnitIndex(const llvm::pdb::PDBSymbolCompiland &pdb_compiland,
223 PDBASTParser *GetPDBAstParser();
225 std::unique_ptr<llvm::pdb::PDBSymbolCompiland>
226 GetPDBCompilandByUID(uint32_t uid);
228 lldb_private::Mangled
229 GetMangledForPDBFunc(const llvm::pdb::PDBSymbolFunc &pdb_func);
231 bool ResolveFunction(const llvm::pdb::PDBSymbolFunc &pdb_func,
232 bool include_inlines,
233 lldb_private::SymbolContextList &sc_list);
235 bool ResolveFunction(uint32_t uid, bool include_inlines,
236 lldb_private::SymbolContextList &sc_list);
238 void CacheFunctionNames();
240 bool DeclContextMatchesThisSymbolFile(
241 const lldb_private::CompilerDeclContext *decl_ctx);
243 uint32_t GetCompilandId(const llvm::pdb::PDBSymbolData &data);
245 llvm::DenseMap<uint32_t, lldb::CompUnitSP> m_comp_units;
246 llvm::DenseMap<uint32_t, lldb::TypeSP> m_types;
247 llvm::DenseMap<uint32_t, lldb::VariableSP> m_variables;
248 llvm::DenseMap<uint64_t, std::string> m_public_names;
250 SecContribsMap m_sec_contribs;
252 std::vector<lldb::TypeSP> m_builtin_types;
253 std::unique_ptr<llvm::pdb::IPDBSession> m_session_up;
254 std::unique_ptr<llvm::pdb::PDBSymbolExe> m_global_scope_up;
255 uint32_t m_cached_compile_unit_count;
256 std::unique_ptr<lldb_private::CompilerDeclContext> m_tu_decl_ctx_up;
258 lldb_private::UniqueCStringMap<uint32_t> m_func_full_names;
259 lldb_private::UniqueCStringMap<uint32_t> m_func_base_names;
260 lldb_private::UniqueCStringMap<uint32_t> m_func_method_names;
263 #endif // lldb_Plugins_SymbolFile_PDB_SymbolFilePDB_h_