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"
23 class SymbolFilePDB : public lldb_private::SymbolFile {
25 //------------------------------------------------------------------
27 //------------------------------------------------------------------
28 static void Initialize();
30 static void Terminate();
32 static void DebuggerInitialize(lldb_private::Debugger &debugger);
34 static lldb_private::ConstString GetPluginNameStatic();
36 static const char *GetPluginDescriptionStatic();
38 static lldb_private::SymbolFile *
39 CreateInstance(lldb_private::ObjectFile *obj_file);
41 //------------------------------------------------------------------
42 // Constructors and Destructors
43 //------------------------------------------------------------------
44 SymbolFilePDB(lldb_private::ObjectFile *ofile);
46 ~SymbolFilePDB() override;
48 uint32_t CalculateAbilities() override;
50 void InitializeObject() override;
52 //------------------------------------------------------------------
53 // Compile Unit function calls
54 //------------------------------------------------------------------
56 uint32_t GetNumCompileUnits() override;
58 lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override;
61 ParseCompileUnitLanguage(const lldb_private::SymbolContext &sc) override;
64 ParseCompileUnitFunctions(const lldb_private::SymbolContext &sc) override;
67 ParseCompileUnitLineTable(const lldb_private::SymbolContext &sc) override;
70 ParseCompileUnitDebugMacros(const lldb_private::SymbolContext &sc) override;
72 bool ParseCompileUnitSupportFiles(
73 const lldb_private::SymbolContext &sc,
74 lldb_private::FileSpecList &support_files) override;
76 bool ParseImportedModules(
77 const lldb_private::SymbolContext &sc,
78 std::vector<lldb_private::ConstString> &imported_modules) override;
80 size_t ParseFunctionBlocks(const lldb_private::SymbolContext &sc) override;
82 size_t ParseTypes(const lldb_private::SymbolContext &sc) override;
85 ParseVariablesForContext(const lldb_private::SymbolContext &sc) override;
87 lldb_private::Type *ResolveTypeUID(lldb::user_id_t type_uid) override;
89 bool CompleteType(lldb_private::CompilerType &compiler_type) override;
91 lldb_private::CompilerDecl GetDeclForUID(lldb::user_id_t uid) override;
93 lldb_private::CompilerDeclContext
94 GetDeclContextForUID(lldb::user_id_t uid) override;
96 lldb_private::CompilerDeclContext
97 GetDeclContextContainingUID(lldb::user_id_t uid) override;
100 ParseDeclsForContext(lldb_private::CompilerDeclContext decl_ctx) override;
102 uint32_t ResolveSymbolContext(const lldb_private::Address &so_addr,
103 uint32_t resolve_scope,
104 lldb_private::SymbolContext &sc) override;
107 ResolveSymbolContext(const lldb_private::FileSpec &file_spec, uint32_t line,
108 bool check_inlines, uint32_t resolve_scope,
109 lldb_private::SymbolContextList &sc_list) override;
112 FindGlobalVariables(const lldb_private::ConstString &name,
113 const lldb_private::CompilerDeclContext *parent_decl_ctx,
114 uint32_t max_matches,
115 lldb_private::VariableList &variables) override;
117 uint32_t FindGlobalVariables(const lldb_private::RegularExpression ®ex,
118 uint32_t max_matches,
119 lldb_private::VariableList &variables) override;
122 FindFunctions(const lldb_private::ConstString &name,
123 const lldb_private::CompilerDeclContext *parent_decl_ctx,
124 uint32_t name_type_mask, bool include_inlines, bool append,
125 lldb_private::SymbolContextList &sc_list) override;
127 uint32_t FindFunctions(const lldb_private::RegularExpression ®ex,
128 bool include_inlines, bool append,
129 lldb_private::SymbolContextList &sc_list) override;
131 void GetMangledNamesForFunction(
132 const std::string &scope_qualified_name,
133 std::vector<lldb_private::ConstString> &mangled_names) override;
136 FindTypes(const lldb_private::SymbolContext &sc,
137 const lldb_private::ConstString &name,
138 const lldb_private::CompilerDeclContext *parent_decl_ctx,
139 bool append, uint32_t max_matches,
140 llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
141 lldb_private::TypeMap &types) override;
143 size_t FindTypes(const std::vector<lldb_private::CompilerContext> &context,
144 bool append, lldb_private::TypeMap &types) override;
146 void FindTypesByRegex(const lldb_private::RegularExpression ®ex,
147 uint32_t max_matches, lldb_private::TypeMap &types);
149 lldb_private::TypeList *GetTypeList() override;
151 size_t GetTypes(lldb_private::SymbolContextScope *sc_scope,
153 lldb_private::TypeList &type_list) override;
155 lldb_private::TypeSystem *
156 GetTypeSystemForLanguage(lldb::LanguageType language) override;
158 lldb_private::CompilerDeclContext FindNamespace(
159 const lldb_private::SymbolContext &sc,
160 const lldb_private::ConstString &name,
161 const lldb_private::CompilerDeclContext *parent_decl_ctx) override;
163 lldb_private::ConstString GetPluginName() override;
165 uint32_t GetPluginVersion() override;
167 llvm::pdb::IPDBSession &GetPDBSession();
169 const llvm::pdb::IPDBSession &GetPDBSession() const;
172 lldb::CompUnitSP ParseCompileUnitForUID(uint32_t id,
173 uint32_t index = UINT32_MAX);
175 bool ParseCompileUnitLineTable(const lldb_private::SymbolContext &sc,
176 uint32_t match_line);
178 void BuildSupportFileIdToSupportFileIndexMap(
179 const llvm::pdb::PDBSymbolCompiland &pdb_compiland,
180 llvm::DenseMap<uint32_t, uint32_t> &index_map) const;
182 void FindTypesByName(const std::string &name, uint32_t max_matches,
183 lldb_private::TypeMap &types);
185 std::string GetMangledForPDBData(const llvm::pdb::PDBSymbolData &pdb_data);
188 ParseVariableForPDBData(const lldb_private::SymbolContext &sc,
189 const llvm::pdb::PDBSymbolData &pdb_data);
191 size_t ParseVariables(const lldb_private::SymbolContext &sc,
192 const llvm::pdb::PDBSymbol &pdb_data,
193 lldb_private::VariableList *variable_list = nullptr);
196 GetCompileUnitContainsAddress(const lldb_private::Address &so_addr);
198 typedef std::vector<lldb_private::Type *> TypeCollection;
200 void GetTypesForPDBSymbol(const llvm::pdb::PDBSymbol &pdb_symbol,
202 TypeCollection &type_collection);
204 lldb_private::Function *
205 ParseCompileUnitFunctionForPDBFunc(const llvm::pdb::PDBSymbolFunc &pdb_func,
206 const lldb_private::SymbolContext &sc);
208 void GetCompileUnitIndex(const llvm::pdb::PDBSymbolCompiland &pdb_compiland,
211 std::unique_ptr<llvm::pdb::PDBSymbolCompiland>
212 GetPDBCompilandByUID(uint32_t uid);
214 lldb_private::Mangled
215 GetMangledForPDBFunc(const llvm::pdb::PDBSymbolFunc &pdb_func);
217 bool ResolveFunction(const llvm::pdb::PDBSymbolFunc &pdb_func,
218 bool include_inlines,
219 lldb_private::SymbolContextList &sc_list);
221 bool ResolveFunction(uint32_t uid, bool include_inlines,
222 lldb_private::SymbolContextList &sc_list);
224 void CacheFunctionNames();
226 bool DeclContextMatchesThisSymbolFile(
227 const lldb_private::CompilerDeclContext *decl_ctx);
229 llvm::DenseMap<uint32_t, lldb::CompUnitSP> m_comp_units;
230 llvm::DenseMap<uint32_t, lldb::TypeSP> m_types;
231 llvm::DenseMap<uint32_t, lldb::VariableSP> m_variables;
233 std::vector<lldb::TypeSP> m_builtin_types;
234 std::unique_ptr<llvm::pdb::IPDBSession> m_session_up;
235 std::unique_ptr<llvm::pdb::PDBSymbolExe> m_global_scope_up;
236 uint32_t m_cached_compile_unit_count;
237 std::unique_ptr<lldb_private::CompilerDeclContext> m_tu_decl_ctx_up;
239 lldb_private::UniqueCStringMap<uint32_t> m_func_full_names;
240 lldb_private::UniqueCStringMap<uint32_t> m_func_base_names;
241 lldb_private::UniqueCStringMap<uint32_t> m_func_method_names;
244 #endif // lldb_Plugins_SymbolFile_PDB_SymbolFilePDB_h_