1 //===-- SymbolFilePDB.h -------------------------------------*- C++ -*-===// 2 // 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 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef LLDB_SOURCE_PLUGINS_SYMBOLFILE_PDB_SYMBOLFILEPDB_H 10 #define LLDB_SOURCE_PLUGINS_SYMBOLFILE_PDB_SYMBOLFILEPDB_H 11 12 #include "lldb/Core/UniqueCStringMap.h" 13 #include "lldb/Symbol/SymbolFile.h" 14 #include "lldb/Symbol/VariableList.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 PDBASTParser; 23 24 class SymbolFilePDB : public lldb_private::SymbolFile { 25 /// LLVM RTTI support. 26 static char ID; 27 28 public: 29 /// LLVM RTTI support. 30 /// \{ isA(const void * ClassID)31 bool isA(const void *ClassID) const override { 32 return ClassID == &ID || SymbolFile::isA(ClassID); 33 } classof(const SymbolFile * obj)34 static bool classof(const SymbolFile *obj) { return obj->isA(&ID); } 35 /// \} 36 37 // Static Functions 38 static void Initialize(); 39 40 static void Terminate(); 41 42 static void DebuggerInitialize(lldb_private::Debugger &debugger); 43 44 static lldb_private::ConstString GetPluginNameStatic(); 45 46 static const char *GetPluginDescriptionStatic(); 47 48 static lldb_private::SymbolFile * 49 CreateInstance(lldb::ObjectFileSP objfile_sp); 50 51 // Constructors and Destructors 52 SymbolFilePDB(lldb::ObjectFileSP objfile_sp); 53 54 ~SymbolFilePDB() override; 55 56 uint32_t CalculateAbilities() override; 57 58 void InitializeObject() override; 59 60 // Compile Unit function calls 61 62 lldb::LanguageType 63 ParseLanguage(lldb_private::CompileUnit &comp_unit) override; 64 65 size_t ParseFunctions(lldb_private::CompileUnit &comp_unit) override; 66 67 bool ParseLineTable(lldb_private::CompileUnit &comp_unit) override; 68 69 bool ParseDebugMacros(lldb_private::CompileUnit &comp_unit) override; 70 71 bool ParseSupportFiles(lldb_private::CompileUnit &comp_unit, 72 lldb_private::FileSpecList &support_files) override; 73 74 size_t ParseTypes(lldb_private::CompileUnit &comp_unit) override; 75 76 bool ParseImportedModules( 77 const lldb_private::SymbolContext &sc, 78 std::vector<lldb_private::SourceModule> &imported_modules) override; 79 80 size_t ParseBlocksRecursive(lldb_private::Function &func) override; 81 82 size_t 83 ParseVariablesForContext(const lldb_private::SymbolContext &sc) override; 84 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; 89 90 bool CompleteType(lldb_private::CompilerType &compiler_type) override; 91 92 lldb_private::CompilerDecl GetDeclForUID(lldb::user_id_t uid) override; 93 94 lldb_private::CompilerDeclContext 95 GetDeclContextForUID(lldb::user_id_t uid) override; 96 97 lldb_private::CompilerDeclContext 98 GetDeclContextContainingUID(lldb::user_id_t uid) override; 99 100 void 101 ParseDeclsForContext(lldb_private::CompilerDeclContext decl_ctx) override; 102 103 uint32_t ResolveSymbolContext(const lldb_private::Address &so_addr, 104 lldb::SymbolContextItem resolve_scope, 105 lldb_private::SymbolContext &sc) override; 106 107 uint32_t 108 ResolveSymbolContext(const lldb_private::FileSpec &file_spec, uint32_t line, 109 bool check_inlines, 110 lldb::SymbolContextItem resolve_scope, 111 lldb_private::SymbolContextList &sc_list) override; 112 113 void 114 FindGlobalVariables(lldb_private::ConstString name, 115 const lldb_private::CompilerDeclContext &parent_decl_ctx, 116 uint32_t max_matches, 117 lldb_private::VariableList &variables) override; 118 119 void FindGlobalVariables(const lldb_private::RegularExpression ®ex, 120 uint32_t max_matches, 121 lldb_private::VariableList &variables) override; 122 123 void FindFunctions(lldb_private::ConstString name, 124 const lldb_private::CompilerDeclContext &parent_decl_ctx, 125 lldb::FunctionNameType name_type_mask, 126 bool include_inlines, 127 lldb_private::SymbolContextList &sc_list) override; 128 129 void FindFunctions(const lldb_private::RegularExpression ®ex, 130 bool include_inlines, 131 lldb_private::SymbolContextList &sc_list) override; 132 133 void GetMangledNamesForFunction( 134 const std::string &scope_qualified_name, 135 std::vector<lldb_private::ConstString> &mangled_names) override; 136 137 void AddSymbols(lldb_private::Symtab &symtab) override; 138 139 void 140 FindTypes(lldb_private::ConstString name, 141 const lldb_private::CompilerDeclContext &parent_decl_ctx, 142 uint32_t max_matches, 143 llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files, 144 lldb_private::TypeMap &types) override; 145 146 void FindTypes(llvm::ArrayRef<lldb_private::CompilerContext> pattern, 147 lldb_private::LanguageSet languages, 148 llvm::DenseSet<SymbolFile *> &searched_symbol_files, 149 lldb_private::TypeMap &types) override; 150 151 void FindTypesByRegex(const lldb_private::RegularExpression ®ex, 152 uint32_t max_matches, lldb_private::TypeMap &types); 153 154 void GetTypes(lldb_private::SymbolContextScope *sc_scope, 155 lldb::TypeClass type_mask, 156 lldb_private::TypeList &type_list) override; 157 158 llvm::Expected<lldb_private::TypeSystem &> 159 GetTypeSystemForLanguage(lldb::LanguageType language) override; 160 161 lldb_private::CompilerDeclContext FindNamespace( 162 lldb_private::ConstString name, 163 const lldb_private::CompilerDeclContext &parent_decl_ctx) override; 164 165 lldb_private::ConstString GetPluginName() override; 166 167 uint32_t GetPluginVersion() override; 168 169 llvm::pdb::IPDBSession &GetPDBSession(); 170 171 const llvm::pdb::IPDBSession &GetPDBSession() const; 172 173 void DumpClangAST(lldb_private::Stream &s) override; 174 175 private: 176 struct SecContribInfo { 177 uint32_t Offset; 178 uint32_t Size; 179 uint32_t CompilandId; 180 }; 181 using SecContribsMap = std::map<uint32_t, std::vector<SecContribInfo>>; 182 183 uint32_t CalculateNumCompileUnits() override; 184 185 lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override; 186 187 lldb::CompUnitSP ParseCompileUnitForUID(uint32_t id, 188 uint32_t index = UINT32_MAX); 189 190 bool ParseCompileUnitLineTable(lldb_private::CompileUnit &comp_unit, 191 uint32_t match_line); 192 193 void BuildSupportFileIdToSupportFileIndexMap( 194 const llvm::pdb::PDBSymbolCompiland &pdb_compiland, 195 llvm::DenseMap<uint32_t, uint32_t> &index_map) const; 196 197 void FindTypesByName(llvm::StringRef name, 198 const lldb_private::CompilerDeclContext &parent_decl_ctx, 199 uint32_t max_matches, lldb_private::TypeMap &types); 200 201 std::string GetMangledForPDBData(const llvm::pdb::PDBSymbolData &pdb_data); 202 203 lldb::VariableSP 204 ParseVariableForPDBData(const lldb_private::SymbolContext &sc, 205 const llvm::pdb::PDBSymbolData &pdb_data); 206 207 size_t ParseVariables(const lldb_private::SymbolContext &sc, 208 const llvm::pdb::PDBSymbol &pdb_data, 209 lldb_private::VariableList *variable_list = nullptr); 210 211 lldb::CompUnitSP 212 GetCompileUnitContainsAddress(const lldb_private::Address &so_addr); 213 214 typedef std::vector<lldb_private::Type *> TypeCollection; 215 216 void GetTypesForPDBSymbol(const llvm::pdb::PDBSymbol &pdb_symbol, 217 uint32_t type_mask, 218 TypeCollection &type_collection); 219 220 lldb_private::Function * 221 ParseCompileUnitFunctionForPDBFunc(const llvm::pdb::PDBSymbolFunc &pdb_func, 222 lldb_private::CompileUnit &comp_unit); 223 224 void GetCompileUnitIndex(const llvm::pdb::PDBSymbolCompiland &pdb_compiland, 225 uint32_t &index); 226 227 PDBASTParser *GetPDBAstParser(); 228 229 std::unique_ptr<llvm::pdb::PDBSymbolCompiland> 230 GetPDBCompilandByUID(uint32_t uid); 231 232 lldb_private::Mangled 233 GetMangledForPDBFunc(const llvm::pdb::PDBSymbolFunc &pdb_func); 234 235 bool ResolveFunction(const llvm::pdb::PDBSymbolFunc &pdb_func, 236 bool include_inlines, 237 lldb_private::SymbolContextList &sc_list); 238 239 bool ResolveFunction(uint32_t uid, bool include_inlines, 240 lldb_private::SymbolContextList &sc_list); 241 242 void CacheFunctionNames(); 243 244 bool DeclContextMatchesThisSymbolFile( 245 const lldb_private::CompilerDeclContext &decl_ctx); 246 247 uint32_t GetCompilandId(const llvm::pdb::PDBSymbolData &data); 248 249 llvm::DenseMap<uint32_t, lldb::CompUnitSP> m_comp_units; 250 llvm::DenseMap<uint32_t, lldb::TypeSP> m_types; 251 llvm::DenseMap<uint32_t, lldb::VariableSP> m_variables; 252 llvm::DenseMap<uint64_t, std::string> m_public_names; 253 254 SecContribsMap m_sec_contribs; 255 256 std::vector<lldb::TypeSP> m_builtin_types; 257 std::unique_ptr<llvm::pdb::IPDBSession> m_session_up; 258 std::unique_ptr<llvm::pdb::PDBSymbolExe> m_global_scope_up; 259 260 lldb_private::UniqueCStringMap<uint32_t> m_func_full_names; 261 lldb_private::UniqueCStringMap<uint32_t> m_func_base_names; 262 lldb_private::UniqueCStringMap<uint32_t> m_func_method_names; 263 }; 264 265 #endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_PDB_SYMBOLFILEPDB_H 266