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/Utility/UserID.h" 16 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" 21 22 class SymbolFilePDB : public lldb_private::SymbolFile { 23 public: 24 //------------------------------------------------------------------ 25 // Static Functions 26 //------------------------------------------------------------------ 27 static void Initialize(); 28 29 static void Terminate(); 30 31 static void DebuggerInitialize(lldb_private::Debugger &debugger); 32 33 static lldb_private::ConstString GetPluginNameStatic(); 34 35 static const char *GetPluginDescriptionStatic(); 36 37 static lldb_private::SymbolFile * 38 CreateInstance(lldb_private::ObjectFile *obj_file); 39 40 //------------------------------------------------------------------ 41 // Constructors and Destructors 42 //------------------------------------------------------------------ 43 SymbolFilePDB(lldb_private::ObjectFile *ofile); 44 45 ~SymbolFilePDB() override; 46 47 uint32_t CalculateAbilities() override; 48 49 void InitializeObject() override; 50 51 //------------------------------------------------------------------ 52 // Compile Unit function calls 53 //------------------------------------------------------------------ 54 55 uint32_t GetNumCompileUnits() override; 56 57 lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override; 58 59 lldb::LanguageType 60 ParseCompileUnitLanguage(const lldb_private::SymbolContext &sc) override; 61 62 size_t 63 ParseCompileUnitFunctions(const lldb_private::SymbolContext &sc) override; 64 65 bool 66 ParseCompileUnitLineTable(const lldb_private::SymbolContext &sc) override; 67 68 bool 69 ParseCompileUnitDebugMacros(const lldb_private::SymbolContext &sc) override; 70 71 bool ParseCompileUnitSupportFiles( 72 const lldb_private::SymbolContext &sc, 73 lldb_private::FileSpecList &support_files) override; 74 75 bool ParseImportedModules( 76 const lldb_private::SymbolContext &sc, 77 std::vector<lldb_private::ConstString> &imported_modules) override; 78 79 size_t ParseFunctionBlocks(const lldb_private::SymbolContext &sc) override; 80 81 size_t ParseTypes(const lldb_private::SymbolContext &sc) override; 82 83 size_t 84 ParseVariablesForContext(const lldb_private::SymbolContext &sc) override; 85 86 lldb_private::Type *ResolveTypeUID(lldb::user_id_t type_uid) override; 87 88 bool CompleteType(lldb_private::CompilerType &compiler_type) override; 89 90 lldb_private::CompilerDecl GetDeclForUID(lldb::user_id_t uid) override; 91 92 lldb_private::CompilerDeclContext 93 GetDeclContextForUID(lldb::user_id_t uid) override; 94 95 lldb_private::CompilerDeclContext 96 GetDeclContextContainingUID(lldb::user_id_t uid) override; 97 98 void 99 ParseDeclsForContext(lldb_private::CompilerDeclContext decl_ctx) override; 100 101 uint32_t ResolveSymbolContext(const lldb_private::Address &so_addr, 102 uint32_t resolve_scope, 103 lldb_private::SymbolContext &sc) override; 104 105 uint32_t 106 ResolveSymbolContext(const lldb_private::FileSpec &file_spec, uint32_t line, 107 bool check_inlines, uint32_t resolve_scope, 108 lldb_private::SymbolContextList &sc_list) override; 109 110 uint32_t 111 FindGlobalVariables(const lldb_private::ConstString &name, 112 const lldb_private::CompilerDeclContext *parent_decl_ctx, 113 bool append, uint32_t max_matches, 114 lldb_private::VariableList &variables) override; 115 116 uint32_t FindGlobalVariables(const lldb_private::RegularExpression ®ex, 117 bool append, uint32_t max_matches, 118 lldb_private::VariableList &variables) override; 119 120 uint32_t 121 FindFunctions(const lldb_private::ConstString &name, 122 const lldb_private::CompilerDeclContext *parent_decl_ctx, 123 uint32_t name_type_mask, bool include_inlines, bool append, 124 lldb_private::SymbolContextList &sc_list) override; 125 126 uint32_t FindFunctions(const lldb_private::RegularExpression ®ex, 127 bool include_inlines, bool append, 128 lldb_private::SymbolContextList &sc_list) override; 129 130 void GetMangledNamesForFunction( 131 const std::string &scope_qualified_name, 132 std::vector<lldb_private::ConstString> &mangled_names) override; 133 134 uint32_t 135 FindTypes(const lldb_private::SymbolContext &sc, 136 const lldb_private::ConstString &name, 137 const lldb_private::CompilerDeclContext *parent_decl_ctx, 138 bool append, uint32_t max_matches, 139 llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files, 140 lldb_private::TypeMap &types) override; 141 142 size_t FindTypes(const std::vector<lldb_private::CompilerContext> &context, 143 bool append, lldb_private::TypeMap &types) override; 144 145 void FindTypesByRegex(const lldb_private::RegularExpression ®ex, 146 uint32_t max_matches, lldb_private::TypeMap &types); 147 148 lldb_private::TypeList *GetTypeList() override; 149 150 size_t GetTypes(lldb_private::SymbolContextScope *sc_scope, 151 uint32_t type_mask, 152 lldb_private::TypeList &type_list) override; 153 154 lldb_private::TypeSystem * 155 GetTypeSystemForLanguage(lldb::LanguageType language) override; 156 157 lldb_private::CompilerDeclContext FindNamespace( 158 const lldb_private::SymbolContext &sc, 159 const lldb_private::ConstString &name, 160 const lldb_private::CompilerDeclContext *parent_decl_ctx) override; 161 162 lldb_private::ConstString GetPluginName() override; 163 164 uint32_t GetPluginVersion() override; 165 166 llvm::pdb::IPDBSession &GetPDBSession(); 167 168 const llvm::pdb::IPDBSession &GetPDBSession() const; 169 170 private: 171 lldb::CompUnitSP ParseCompileUnitForUID(uint32_t id, 172 uint32_t index = UINT32_MAX); 173 174 bool ParseCompileUnitLineTable(const lldb_private::SymbolContext &sc, 175 uint32_t match_line); 176 177 void BuildSupportFileIdToSupportFileIndexMap( 178 const llvm::pdb::PDBSymbolCompiland &pdb_compiland, 179 llvm::DenseMap<uint32_t, uint32_t> &index_map) const; 180 181 void FindTypesByName(const std::string &name, uint32_t max_matches, 182 lldb_private::TypeMap &types); 183 184 lldb::CompUnitSP 185 GetCompileUnitContainsAddress(const lldb_private::Address &so_addr); 186 187 typedef std::vector<lldb_private::Type *> TypeCollection; 188 189 void GetTypesForPDBSymbol(const llvm::pdb::PDBSymbol &pdb_symbol, 190 uint32_t type_mask, 191 TypeCollection &type_collection); 192 193 lldb_private::Function * 194 ParseCompileUnitFunctionForPDBFunc(const llvm::pdb::PDBSymbolFunc &pdb_func, 195 const lldb_private::SymbolContext &sc); 196 197 void GetCompileUnitIndex(const llvm::pdb::PDBSymbolCompiland &pdb_compiland, 198 uint32_t &index); 199 200 std::unique_ptr<llvm::pdb::PDBSymbolCompiland> 201 GetPDBCompilandByUID(uint32_t uid); 202 203 lldb_private::Mangled 204 GetMangledForPDBFunc(const llvm::pdb::PDBSymbolFunc &pdb_func); 205 206 bool ResolveFunction(const llvm::pdb::PDBSymbolFunc &pdb_func, 207 bool include_inlines, 208 lldb_private::SymbolContextList &sc_list); 209 210 bool ResolveFunction(uint32_t uid, bool include_inlines, 211 lldb_private::SymbolContextList &sc_list); 212 213 void CacheFunctionNames(); 214 215 bool DeclContextMatchesThisSymbolFile( 216 const lldb_private::CompilerDeclContext *decl_ctx); 217 218 llvm::DenseMap<uint32_t, lldb::CompUnitSP> m_comp_units; 219 llvm::DenseMap<uint32_t, lldb::TypeSP> m_types; 220 221 std::vector<lldb::TypeSP> m_builtin_types; 222 std::unique_ptr<llvm::pdb::IPDBSession> m_session_up; 223 std::unique_ptr<llvm::pdb::PDBSymbolExe> m_global_scope_up; 224 uint32_t m_cached_compile_unit_count; 225 std::unique_ptr<lldb_private::CompilerDeclContext> m_tu_decl_ctx_up; 226 227 lldb_private::UniqueCStringMap<uint32_t> m_func_full_names; 228 lldb_private::UniqueCStringMap<uint32_t> m_func_base_names; 229 lldb_private::UniqueCStringMap<uint32_t> m_func_method_names; 230 }; 231 232 #endif // lldb_Plugins_SymbolFile_PDB_SymbolFilePDB_h_ 233