1 //===-- SymbolFileNativePDB.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_NATIVEPDB_SYMBOLFILENATIVEPDB_H 11 #define LLDB_PLUGINS_SYMBOLFILE_NATIVEPDB_SYMBOLFILENATIVEPDB_H 12 13 #include "lldb/Symbol/ClangASTImporter.h" 14 #include "lldb/Symbol/SymbolFile.h" 15 16 #include "llvm/ADT/DenseMap.h" 17 #include "llvm/DebugInfo/CodeView/CVRecord.h" 18 #include "llvm/DebugInfo/CodeView/SymbolRecord.h" 19 #include "llvm/DebugInfo/PDB/PDBTypes.h" 20 21 #include "CompileUnitIndex.h" 22 #include "PdbIndex.h" 23 24 namespace clang { 25 class TagDecl; 26 } 27 28 namespace llvm { 29 namespace codeview { 30 class ClassRecord; 31 class EnumRecord; 32 class ModifierRecord; 33 class PointerRecord; 34 struct UnionRecord; 35 } // namespace codeview 36 } // namespace llvm 37 38 namespace lldb_private { 39 class ClangASTImporter; 40 41 namespace npdb { 42 43 struct DeclStatus { 44 DeclStatus() = default; 45 DeclStatus(lldb::user_id_t uid, Type::ResolveStateTag status) 46 : uid(uid), status(status) {} 47 lldb::user_id_t uid = 0; 48 Type::ResolveStateTag status = Type::eResolveStateForward; 49 }; 50 51 class SymbolFileNativePDB : public SymbolFile { 52 friend class UdtRecordCompleter; 53 54 public: 55 //------------------------------------------------------------------ 56 // Static Functions 57 //------------------------------------------------------------------ 58 static void Initialize(); 59 60 static void Terminate(); 61 62 static void DebuggerInitialize(Debugger &debugger); 63 64 static ConstString GetPluginNameStatic(); 65 66 static const char *GetPluginDescriptionStatic(); 67 68 static SymbolFile *CreateInstance(ObjectFile *obj_file); 69 70 //------------------------------------------------------------------ 71 // Constructors and Destructors 72 //------------------------------------------------------------------ 73 SymbolFileNativePDB(ObjectFile *ofile); 74 75 ~SymbolFileNativePDB() override; 76 77 uint32_t CalculateAbilities() override; 78 79 void InitializeObject() override; 80 81 //------------------------------------------------------------------ 82 // Compile Unit function calls 83 //------------------------------------------------------------------ 84 85 uint32_t GetNumCompileUnits() override; 86 87 lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override; 88 89 lldb::LanguageType ParseCompileUnitLanguage(const SymbolContext &sc) override; 90 91 size_t ParseCompileUnitFunctions(const SymbolContext &sc) override; 92 93 bool ParseCompileUnitLineTable(const SymbolContext &sc) override; 94 95 bool ParseCompileUnitDebugMacros(const SymbolContext &sc) override; 96 97 bool ParseCompileUnitSupportFiles(const SymbolContext &sc, 98 FileSpecList &support_files) override; 99 100 bool 101 ParseImportedModules(const SymbolContext &sc, 102 std::vector<ConstString> &imported_modules) override; 103 104 size_t ParseFunctionBlocks(const SymbolContext &sc) override; 105 106 uint32_t FindGlobalVariables(const ConstString &name, 107 const CompilerDeclContext *parent_decl_ctx, 108 uint32_t max_matches, 109 VariableList &variables) override; 110 111 size_t ParseTypes(const SymbolContext &sc) override; 112 size_t ParseVariablesForContext(const SymbolContext &sc) override { 113 return 0; 114 } 115 Type *ResolveTypeUID(lldb::user_id_t type_uid) override; 116 bool CompleteType(CompilerType &compiler_type) override; 117 uint32_t ResolveSymbolContext(const Address &so_addr, 118 lldb::SymbolContextItem resolve_scope, 119 SymbolContext &sc) override; 120 121 size_t GetTypes(SymbolContextScope *sc_scope, lldb::TypeClass type_mask, 122 TypeList &type_list) override; 123 124 uint32_t FindFunctions(const ConstString &name, 125 const CompilerDeclContext *parent_decl_ctx, 126 lldb::FunctionNameType name_type_mask, 127 bool include_inlines, bool append, 128 SymbolContextList &sc_list) override; 129 130 uint32_t FindFunctions(const RegularExpression ®ex, bool include_inlines, 131 bool append, SymbolContextList &sc_list) override; 132 133 uint32_t FindTypes(const SymbolContext &sc, const ConstString &name, 134 const CompilerDeclContext *parent_decl_ctx, bool append, 135 uint32_t max_matches, 136 llvm::DenseSet<SymbolFile *> &searched_symbol_files, 137 TypeMap &types) override; 138 139 size_t FindTypes(const std::vector<CompilerContext> &context, bool append, 140 TypeMap &types) override; 141 142 TypeSystem *GetTypeSystemForLanguage(lldb::LanguageType language) override; 143 144 CompilerDeclContext 145 FindNamespace(const SymbolContext &sc, const ConstString &name, 146 const CompilerDeclContext *parent_decl_ctx) override; 147 148 ConstString GetPluginName() override; 149 150 uint32_t GetPluginVersion() override; 151 152 llvm::pdb::PDBFile &GetPDBFile() { return m_index->pdb(); } 153 const llvm::pdb::PDBFile &GetPDBFile() const { return m_index->pdb(); } 154 155 ClangASTContext &GetASTContext() { return *m_clang; } 156 ClangASTImporter &GetASTImporter() { return *m_importer; } 157 158 private: 159 size_t FindTypesByName(llvm::StringRef name, uint32_t max_matches, 160 TypeMap &types); 161 162 lldb::TypeSP CreateModifierType(PdbSymUid type_uid, 163 const llvm::codeview::ModifierRecord &mr); 164 lldb::TypeSP CreatePointerType(PdbSymUid type_uid, 165 const llvm::codeview::PointerRecord &pr); 166 lldb::TypeSP CreateSimpleType(llvm::codeview::TypeIndex ti); 167 lldb::TypeSP CreateTagType(PdbSymUid type_uid, 168 const llvm::codeview::ClassRecord &cr); 169 lldb::TypeSP CreateTagType(PdbSymUid type_uid, 170 const llvm::codeview::EnumRecord &er); 171 lldb::TypeSP CreateTagType(PdbSymUid type_uid, 172 const llvm::codeview::UnionRecord &ur); 173 lldb::TypeSP 174 CreateClassStructUnion(PdbSymUid type_uid, llvm::StringRef name, size_t size, 175 clang::TagTypeKind ttk, 176 clang::MSInheritanceAttr::Spelling inheritance); 177 178 lldb::FunctionSP GetOrCreateFunction(PdbSymUid func_uid, 179 const SymbolContext &sc); 180 lldb::CompUnitSP GetOrCreateCompileUnit(const CompilandIndexItem &cci); 181 lldb::TypeSP GetOrCreateType(PdbSymUid type_uid); 182 lldb::TypeSP GetOrCreateType(llvm::codeview::TypeIndex ti); 183 lldb::VariableSP GetOrCreateGlobalVariable(PdbSymUid var_uid); 184 185 lldb::FunctionSP CreateFunction(PdbSymUid func_uid, const SymbolContext &sc); 186 lldb::CompUnitSP CreateCompileUnit(const CompilandIndexItem &cci); 187 lldb::TypeSP CreateType(PdbSymUid type_uid); 188 lldb::TypeSP CreateAndCacheType(PdbSymUid type_uid); 189 lldb::VariableSP CreateGlobalVariable(PdbSymUid var_uid); 190 191 llvm::BumpPtrAllocator m_allocator; 192 193 lldb::addr_t m_obj_load_address = 0; 194 195 std::unique_ptr<PdbIndex> m_index; 196 std::unique_ptr<ClangASTImporter> m_importer; 197 ClangASTContext *m_clang = nullptr; 198 199 llvm::DenseMap<clang::TagDecl *, DeclStatus> m_decl_to_status; 200 201 llvm::DenseMap<lldb::user_id_t, clang::TagDecl *> m_uid_to_decl; 202 203 llvm::DenseMap<lldb::user_id_t, lldb::VariableSP> m_global_vars; 204 llvm::DenseMap<lldb::user_id_t, lldb::FunctionSP> m_functions; 205 llvm::DenseMap<lldb::user_id_t, lldb::CompUnitSP> m_compilands; 206 llvm::DenseMap<lldb::user_id_t, lldb::TypeSP> m_types; 207 }; 208 209 } // namespace npdb 210 } // namespace lldb_private 211 212 #endif // lldb_Plugins_SymbolFile_PDB_SymbolFilePDB_h_ 213