1 //===-- SymbolFilePDB.h -------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #ifndef lldb_Plugins_SymbolFile_PDB_SymbolFilePDB_h_ 11 #define lldb_Plugins_SymbolFile_PDB_SymbolFilePDB_h_ 12 13 #include "lldb/Core/UniqueCStringMap.h" 14 #include "lldb/Symbol/SymbolFile.h" 15 #include "lldb/Symbol/VariableList.h" 16 #include "lldb/Utility/UserID.h" 17 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" 22 23 class SymbolFilePDB : public lldb_private::SymbolFile { 24 public: 25 //------------------------------------------------------------------ 26 // Static Functions 27 //------------------------------------------------------------------ 28 static void Initialize(); 29 30 static void Terminate(); 31 32 static void DebuggerInitialize(lldb_private::Debugger &debugger); 33 34 static lldb_private::ConstString GetPluginNameStatic(); 35 36 static const char *GetPluginDescriptionStatic(); 37 38 static lldb_private::SymbolFile * 39 CreateInstance(lldb_private::ObjectFile *obj_file); 40 41 //------------------------------------------------------------------ 42 // Constructors and Destructors 43 //------------------------------------------------------------------ 44 SymbolFilePDB(lldb_private::ObjectFile *ofile); 45 46 ~SymbolFilePDB() override; 47 48 uint32_t CalculateAbilities() override; 49 50 void InitializeObject() override; 51 52 //------------------------------------------------------------------ 53 // Compile Unit function calls 54 //------------------------------------------------------------------ 55 56 uint32_t GetNumCompileUnits() override; 57 58 lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override; 59 60 lldb::LanguageType 61 ParseCompileUnitLanguage(const lldb_private::SymbolContext &sc) override; 62 63 size_t 64 ParseCompileUnitFunctions(const lldb_private::SymbolContext &sc) override; 65 66 bool 67 ParseCompileUnitLineTable(const lldb_private::SymbolContext &sc) override; 68 69 bool 70 ParseCompileUnitDebugMacros(const lldb_private::SymbolContext &sc) override; 71 72 bool ParseCompileUnitSupportFiles( 73 const lldb_private::SymbolContext &sc, 74 lldb_private::FileSpecList &support_files) override; 75 76 bool ParseImportedModules( 77 const lldb_private::SymbolContext &sc, 78 std::vector<lldb_private::ConstString> &imported_modules) override; 79 80 size_t ParseFunctionBlocks(const lldb_private::SymbolContext &sc) override; 81 82 size_t ParseTypes(const lldb_private::SymbolContext &sc) override; 83 84 size_t 85 ParseVariablesForContext(const lldb_private::SymbolContext &sc) override; 86 87 lldb_private::Type *ResolveTypeUID(lldb::user_id_t type_uid) override; 88 89 bool CompleteType(lldb_private::CompilerType &compiler_type) override; 90 91 lldb_private::CompilerDecl GetDeclForUID(lldb::user_id_t uid) override; 92 93 lldb_private::CompilerDeclContext 94 GetDeclContextForUID(lldb::user_id_t uid) override; 95 96 lldb_private::CompilerDeclContext 97 GetDeclContextContainingUID(lldb::user_id_t uid) override; 98 99 void 100 ParseDeclsForContext(lldb_private::CompilerDeclContext decl_ctx) override; 101 102 uint32_t ResolveSymbolContext(const lldb_private::Address &so_addr, 103 uint32_t resolve_scope, 104 lldb_private::SymbolContext &sc) override; 105 106 uint32_t 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; 110 111 uint32_t 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; 116 117 uint32_t FindGlobalVariables(const lldb_private::RegularExpression ®ex, 118 uint32_t max_matches, 119 lldb_private::VariableList &variables) override; 120 121 uint32_t 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; 126 127 uint32_t FindFunctions(const lldb_private::RegularExpression ®ex, 128 bool include_inlines, bool append, 129 lldb_private::SymbolContextList &sc_list) override; 130 131 void GetMangledNamesForFunction( 132 const std::string &scope_qualified_name, 133 std::vector<lldb_private::ConstString> &mangled_names) override; 134 135 uint32_t 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; 142 143 size_t FindTypes(const std::vector<lldb_private::CompilerContext> &context, 144 bool append, lldb_private::TypeMap &types) override; 145 146 void FindTypesByRegex(const lldb_private::RegularExpression ®ex, 147 uint32_t max_matches, lldb_private::TypeMap &types); 148 149 lldb_private::TypeList *GetTypeList() override; 150 151 size_t GetTypes(lldb_private::SymbolContextScope *sc_scope, 152 uint32_t type_mask, 153 lldb_private::TypeList &type_list) override; 154 155 lldb_private::TypeSystem * 156 GetTypeSystemForLanguage(lldb::LanguageType language) override; 157 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; 162 163 lldb_private::ConstString GetPluginName() override; 164 165 uint32_t GetPluginVersion() override; 166 167 llvm::pdb::IPDBSession &GetPDBSession(); 168 169 const llvm::pdb::IPDBSession &GetPDBSession() const; 170 171 private: 172 lldb::CompUnitSP ParseCompileUnitForUID(uint32_t id, 173 uint32_t index = UINT32_MAX); 174 175 bool ParseCompileUnitLineTable(const lldb_private::SymbolContext &sc, 176 uint32_t match_line); 177 178 void BuildSupportFileIdToSupportFileIndexMap( 179 const llvm::pdb::PDBSymbolCompiland &pdb_compiland, 180 llvm::DenseMap<uint32_t, uint32_t> &index_map) const; 181 182 void FindTypesByName(const std::string &name, uint32_t max_matches, 183 lldb_private::TypeMap &types); 184 185 std::string GetMangledForPDBData(const llvm::pdb::PDBSymbolData &pdb_data); 186 187 lldb::VariableSP 188 ParseVariableForPDBData(const lldb_private::SymbolContext &sc, 189 const llvm::pdb::PDBSymbolData &pdb_data); 190 191 size_t ParseVariables(const lldb_private::SymbolContext &sc, 192 const llvm::pdb::PDBSymbol &pdb_data, 193 lldb_private::VariableList *variable_list = nullptr); 194 195 lldb::CompUnitSP 196 GetCompileUnitContainsAddress(const lldb_private::Address &so_addr); 197 198 typedef std::vector<lldb_private::Type *> TypeCollection; 199 200 void GetTypesForPDBSymbol(const llvm::pdb::PDBSymbol &pdb_symbol, 201 uint32_t type_mask, 202 TypeCollection &type_collection); 203 204 lldb_private::Function * 205 ParseCompileUnitFunctionForPDBFunc(const llvm::pdb::PDBSymbolFunc &pdb_func, 206 const lldb_private::SymbolContext &sc); 207 208 void GetCompileUnitIndex(const llvm::pdb::PDBSymbolCompiland &pdb_compiland, 209 uint32_t &index); 210 211 std::unique_ptr<llvm::pdb::PDBSymbolCompiland> 212 GetPDBCompilandByUID(uint32_t uid); 213 214 lldb_private::Mangled 215 GetMangledForPDBFunc(const llvm::pdb::PDBSymbolFunc &pdb_func); 216 217 bool ResolveFunction(const llvm::pdb::PDBSymbolFunc &pdb_func, 218 bool include_inlines, 219 lldb_private::SymbolContextList &sc_list); 220 221 bool ResolveFunction(uint32_t uid, bool include_inlines, 222 lldb_private::SymbolContextList &sc_list); 223 224 void CacheFunctionNames(); 225 226 bool DeclContextMatchesThisSymbolFile( 227 const lldb_private::CompilerDeclContext *decl_ctx); 228 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; 232 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; 238 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; 242 }; 243 244 #endif // lldb_Plugins_SymbolFile_PDB_SymbolFilePDB_h_ 245