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