1 //===-- SymbolFileNativePDB.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_NATIVEPDB_SYMBOLFILENATIVEPDB_H 10 #define LLDB_SOURCE_PLUGINS_SYMBOLFILE_NATIVEPDB_SYMBOLFILENATIVEPDB_H 11 12 #include "lldb/Symbol/LineTable.h" 13 #include "lldb/Symbol/SymbolFile.h" 14 15 #include "llvm/ADT/DenseMap.h" 16 #include "llvm/DebugInfo/CodeView/CVRecord.h" 17 #include "llvm/DebugInfo/CodeView/SymbolRecord.h" 18 #include "llvm/DebugInfo/PDB/PDBTypes.h" 19 20 #include "CompileUnitIndex.h" 21 #include "PdbIndex.h" 22 23 namespace clang { 24 class TagDecl; 25 } 26 27 namespace llvm { 28 namespace codeview { 29 class ClassRecord; 30 class EnumRecord; 31 class ModifierRecord; 32 class PointerRecord; 33 struct UnionRecord; 34 } // namespace codeview 35 } // namespace llvm 36 37 namespace lldb_private { 38 39 namespace npdb { 40 class PdbAstBuilder; 41 42 class SymbolFileNativePDB : public SymbolFileCommon { 43 friend class UdtRecordCompleter; 44 45 /// LLVM RTTI support. 46 static char ID; 47 48 public: 49 /// LLVM RTTI support. 50 /// \{ 51 bool isA(const void *ClassID) const override { 52 return ClassID == &ID || SymbolFileCommon::isA(ClassID); 53 } 54 static bool classof(const SymbolFile *obj) { return obj->isA(&ID); } 55 /// \} 56 57 // Static Functions 58 static void Initialize(); 59 60 static void Terminate(); 61 62 static void DebuggerInitialize(Debugger &debugger); 63 64 static llvm::StringRef GetPluginNameStatic() { return "native-pdb"; } 65 66 static llvm::StringRef GetPluginDescriptionStatic(); 67 68 static SymbolFile *CreateInstance(lldb::ObjectFileSP objfile_sp); 69 70 // Constructors and Destructors 71 SymbolFileNativePDB(lldb::ObjectFileSP objfile_sp); 72 73 ~SymbolFileNativePDB() override; 74 75 uint32_t CalculateAbilities() override; 76 77 void InitializeObject() override; 78 79 uint64_t GetDebugInfoSize() override; 80 81 // Compile Unit function calls 82 83 void 84 ParseDeclsForContext(lldb_private::CompilerDeclContext decl_ctx) override; 85 86 lldb::LanguageType 87 ParseLanguage(lldb_private::CompileUnit &comp_unit) override; 88 89 size_t ParseFunctions(lldb_private::CompileUnit &comp_unit) override; 90 91 bool ParseLineTable(lldb_private::CompileUnit &comp_unit) override; 92 93 bool ParseDebugMacros(lldb_private::CompileUnit &comp_unit) override; 94 95 bool ParseSupportFiles(lldb_private::CompileUnit &comp_unit, 96 FileSpecList &support_files) override; 97 size_t ParseTypes(lldb_private::CompileUnit &comp_unit) override; 98 99 bool ParseImportedModules( 100 const SymbolContext &sc, 101 std::vector<lldb_private::SourceModule> &imported_modules) override; 102 103 size_t ParseBlocksRecursive(Function &func) override; 104 105 void FindGlobalVariables(ConstString name, 106 const CompilerDeclContext &parent_decl_ctx, 107 uint32_t max_matches, 108 VariableList &variables) override; 109 110 size_t ParseVariablesForContext(const SymbolContext &sc) override; 111 112 void AddSymbols(Symtab &symtab) override; 113 114 CompilerDecl GetDeclForUID(lldb::user_id_t uid) override; 115 CompilerDeclContext GetDeclContextForUID(lldb::user_id_t uid) override; 116 CompilerDeclContext GetDeclContextContainingUID(lldb::user_id_t uid) override; 117 Type *ResolveTypeUID(lldb::user_id_t type_uid) override; 118 llvm::Optional<ArrayInfo> GetDynamicArrayInfoForUID( 119 lldb::user_id_t type_uid, 120 const lldb_private::ExecutionContext *exe_ctx) override; 121 122 bool CompleteType(CompilerType &compiler_type) override; 123 uint32_t ResolveSymbolContext(const Address &so_addr, 124 lldb::SymbolContextItem resolve_scope, 125 SymbolContext &sc) override; 126 uint32_t ResolveSymbolContext(const SourceLocationSpec &src_location_spec, 127 lldb::SymbolContextItem resolve_scope, 128 SymbolContextList &sc_list) override; 129 130 void GetTypes(SymbolContextScope *sc_scope, lldb::TypeClass type_mask, 131 TypeList &type_list) override; 132 133 void FindFunctions(ConstString name, 134 const CompilerDeclContext &parent_decl_ctx, 135 lldb::FunctionNameType name_type_mask, 136 bool include_inlines, SymbolContextList &sc_list) override; 137 138 void FindFunctions(const RegularExpression ®ex, bool include_inlines, 139 SymbolContextList &sc_list) override; 140 141 void FindTypes(ConstString name, const CompilerDeclContext &parent_decl_ctx, 142 uint32_t max_matches, 143 llvm::DenseSet<SymbolFile *> &searched_symbol_files, 144 TypeMap &types) override; 145 146 void FindTypes(llvm::ArrayRef<CompilerContext> pattern, LanguageSet languages, 147 llvm::DenseSet<SymbolFile *> &searched_symbol_files, 148 TypeMap &types) override; 149 150 llvm::Expected<TypeSystem &> 151 GetTypeSystemForLanguage(lldb::LanguageType language) override; 152 153 CompilerDeclContext 154 FindNamespace(ConstString name, 155 const CompilerDeclContext &parent_decl_ctx) override; 156 157 llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); } 158 159 llvm::pdb::PDBFile &GetPDBFile() { return m_index->pdb(); } 160 const llvm::pdb::PDBFile &GetPDBFile() const { return m_index->pdb(); } 161 162 void DumpClangAST(Stream &s) override; 163 164 private: 165 struct LineTableEntryComparator { 166 bool operator()(const lldb_private::LineTable::Entry &lhs, 167 const lldb_private::LineTable::Entry &rhs) const { 168 return lhs.file_addr < rhs.file_addr; 169 } 170 }; 171 172 // From address range relative to function base to source line number. 173 using RangeSourceLineVector = 174 lldb_private::RangeDataVector<uint32_t, uint32_t, int32_t>; 175 // InlineSite contains information in a S_INLINESITE record. 176 struct InlineSite { 177 PdbCompilandSymId parent_id; 178 std::shared_ptr<InlineFunctionInfo> inline_function_info; 179 RangeSourceLineVector ranges; 180 std::vector<lldb_private::LineTable::Entry> line_entries; 181 InlineSite(PdbCompilandSymId parent_id) : parent_id(parent_id){}; 182 }; 183 184 uint32_t CalculateNumCompileUnits() override; 185 186 lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override; 187 188 void FindTypesByName(llvm::StringRef name, uint32_t max_matches, 189 TypeMap &types); 190 191 lldb::TypeSP CreateModifierType(PdbTypeSymId type_id, 192 const llvm::codeview::ModifierRecord &mr, 193 CompilerType ct); 194 lldb::TypeSP CreatePointerType(PdbTypeSymId type_id, 195 const llvm::codeview::PointerRecord &pr, 196 CompilerType ct); 197 lldb::TypeSP CreateSimpleType(llvm::codeview::TypeIndex ti, CompilerType ct); 198 lldb::TypeSP CreateTagType(PdbTypeSymId type_id, 199 const llvm::codeview::ClassRecord &cr, 200 CompilerType ct); 201 lldb::TypeSP CreateTagType(PdbTypeSymId type_id, 202 const llvm::codeview::EnumRecord &er, 203 CompilerType ct); 204 lldb::TypeSP CreateTagType(PdbTypeSymId type_id, 205 const llvm::codeview::UnionRecord &ur, 206 CompilerType ct); 207 lldb::TypeSP CreateArrayType(PdbTypeSymId type_id, 208 const llvm::codeview::ArrayRecord &ar, 209 CompilerType ct); 210 lldb::TypeSP CreateFunctionType(PdbTypeSymId type_id, 211 const llvm::codeview::MemberFunctionRecord &pr, 212 CompilerType ct); 213 lldb::TypeSP CreateProcedureType(PdbTypeSymId type_id, 214 const llvm::codeview::ProcedureRecord &pr, 215 CompilerType ct); 216 lldb::TypeSP CreateClassStructUnion(PdbTypeSymId type_id, 217 const llvm::codeview::TagRecord &record, 218 size_t size, CompilerType ct); 219 220 lldb::FunctionSP GetOrCreateFunction(PdbCompilandSymId func_id, 221 CompileUnit &comp_unit); 222 lldb::CompUnitSP GetOrCreateCompileUnit(const CompilandIndexItem &cci); 223 lldb::TypeSP GetOrCreateType(PdbTypeSymId type_id); 224 lldb::TypeSP GetOrCreateType(llvm::codeview::TypeIndex ti); 225 lldb::VariableSP GetOrCreateGlobalVariable(PdbGlobalSymId var_id); 226 Block &GetOrCreateBlock(PdbCompilandSymId block_id); 227 lldb::VariableSP GetOrCreateLocalVariable(PdbCompilandSymId scope_id, 228 PdbCompilandSymId var_id, 229 bool is_param); 230 lldb::TypeSP GetOrCreateTypedef(PdbGlobalSymId id); 231 232 lldb::FunctionSP CreateFunction(PdbCompilandSymId func_id, 233 CompileUnit &comp_unit); 234 Block &CreateBlock(PdbCompilandSymId block_id); 235 lldb::VariableSP CreateLocalVariable(PdbCompilandSymId scope_id, 236 PdbCompilandSymId var_id, bool is_param); 237 lldb::TypeSP CreateTypedef(PdbGlobalSymId id); 238 lldb::CompUnitSP CreateCompileUnit(const CompilandIndexItem &cci); 239 lldb::TypeSP CreateType(PdbTypeSymId type_id, CompilerType ct); 240 lldb::TypeSP CreateAndCacheType(PdbTypeSymId type_id); 241 lldb::VariableSP CreateGlobalVariable(PdbGlobalSymId var_id); 242 lldb::VariableSP CreateConstantSymbol(PdbGlobalSymId var_id, 243 const llvm::codeview::CVSymbol &cvs); 244 size_t ParseVariablesForCompileUnit(CompileUnit &comp_unit, 245 VariableList &variables); 246 size_t ParseVariablesForBlock(PdbCompilandSymId block_id); 247 248 llvm::Expected<uint32_t> GetFileIndex(const CompilandIndexItem &cii, 249 uint32_t file_id); 250 251 size_t ParseSymbolArrayInScope( 252 PdbCompilandSymId parent, 253 llvm::function_ref<bool(llvm::codeview::SymbolKind, PdbCompilandSymId)> 254 fn); 255 256 void ParseInlineSite(PdbCompilandSymId inline_site_id, Address func_addr); 257 258 llvm::BumpPtrAllocator m_allocator; 259 260 lldb::addr_t m_obj_load_address = 0; 261 bool m_done_full_type_scan = false; 262 263 std::unique_ptr<llvm::pdb::PDBFile> m_file_up; 264 std::unique_ptr<PdbIndex> m_index; 265 266 std::unique_ptr<PdbAstBuilder> m_ast; 267 268 llvm::DenseMap<lldb::user_id_t, lldb::VariableSP> m_global_vars; 269 llvm::DenseMap<lldb::user_id_t, lldb::VariableSP> m_local_variables; 270 llvm::DenseMap<lldb::user_id_t, lldb::BlockSP> m_blocks; 271 llvm::DenseMap<lldb::user_id_t, lldb::FunctionSP> m_functions; 272 llvm::DenseMap<lldb::user_id_t, lldb::CompUnitSP> m_compilands; 273 llvm::DenseMap<lldb::user_id_t, lldb::TypeSP> m_types; 274 llvm::DenseMap<lldb::user_id_t, std::shared_ptr<InlineSite>> m_inline_sites; 275 }; 276 277 } // namespace npdb 278 } // namespace lldb_private 279 280 #endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_NATIVEPDB_SYMBOLFILENATIVEPDB_H 281