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 llvm::Optional<ArrayInfo> GetDynamicArrayInfoForUID( 117 lldb::user_id_t type_uid, 118 const lldb_private::ExecutionContext *exe_ctx) override; 119 120 bool CompleteType(CompilerType &compiler_type) override; 121 uint32_t ResolveSymbolContext(const Address &so_addr, 122 lldb::SymbolContextItem resolve_scope, 123 SymbolContext &sc) override; 124 125 size_t GetTypes(SymbolContextScope *sc_scope, lldb::TypeClass type_mask, 126 TypeList &type_list) override; 127 128 uint32_t FindFunctions(const ConstString &name, 129 const CompilerDeclContext *parent_decl_ctx, 130 lldb::FunctionNameType name_type_mask, 131 bool include_inlines, bool append, 132 SymbolContextList &sc_list) override; 133 134 uint32_t FindFunctions(const RegularExpression ®ex, bool include_inlines, 135 bool append, SymbolContextList &sc_list) override; 136 137 uint32_t FindTypes(const SymbolContext &sc, const ConstString &name, 138 const CompilerDeclContext *parent_decl_ctx, bool append, 139 uint32_t max_matches, 140 llvm::DenseSet<SymbolFile *> &searched_symbol_files, 141 TypeMap &types) override; 142 143 size_t FindTypes(const std::vector<CompilerContext> &context, bool append, 144 TypeMap &types) override; 145 146 TypeSystem *GetTypeSystemForLanguage(lldb::LanguageType language) override; 147 148 CompilerDeclContext 149 FindNamespace(const SymbolContext &sc, const ConstString &name, 150 const CompilerDeclContext *parent_decl_ctx) override; 151 152 ConstString GetPluginName() override; 153 154 uint32_t GetPluginVersion() override; 155 156 llvm::pdb::PDBFile &GetPDBFile() { return m_index->pdb(); } 157 const llvm::pdb::PDBFile &GetPDBFile() const { return m_index->pdb(); } 158 159 ClangASTContext &GetASTContext() { return *m_clang; } 160 ClangASTImporter &GetASTImporter() { return *m_importer; } 161 162 void DumpClangAST(Stream &s) override; 163 164 private: 165 size_t FindTypesByName(llvm::StringRef name, uint32_t max_matches, 166 TypeMap &types); 167 168 lldb::TypeSP CreateModifierType(PdbSymUid type_uid, 169 const llvm::codeview::ModifierRecord &mr); 170 lldb::TypeSP CreatePointerType(PdbSymUid type_uid, 171 const llvm::codeview::PointerRecord &pr); 172 lldb::TypeSP CreateSimpleType(llvm::codeview::TypeIndex ti); 173 lldb::TypeSP CreateTagType(PdbSymUid type_uid, 174 const llvm::codeview::ClassRecord &cr); 175 lldb::TypeSP CreateTagType(PdbSymUid type_uid, 176 const llvm::codeview::EnumRecord &er); 177 lldb::TypeSP CreateTagType(PdbSymUid type_uid, 178 const llvm::codeview::UnionRecord &ur); 179 lldb::TypeSP CreateArrayType(PdbSymUid type_uid, 180 const llvm::codeview::ArrayRecord &ar); 181 lldb::TypeSP CreateProcedureType(PdbSymUid type_uid, 182 const llvm::codeview::ProcedureRecord &pr); 183 lldb::TypeSP 184 CreateClassStructUnion(PdbSymUid type_uid, llvm::StringRef name, size_t size, 185 clang::TagTypeKind ttk, 186 clang::MSInheritanceAttr::Spelling inheritance); 187 188 lldb::FunctionSP GetOrCreateFunction(PdbSymUid func_uid, 189 const SymbolContext &sc); 190 lldb::CompUnitSP GetOrCreateCompileUnit(const CompilandIndexItem &cci); 191 lldb::TypeSP GetOrCreateType(PdbSymUid type_uid); 192 lldb::TypeSP GetOrCreateType(llvm::codeview::TypeIndex ti); 193 lldb::VariableSP GetOrCreateGlobalVariable(PdbSymUid var_uid); 194 195 lldb::FunctionSP CreateFunction(PdbSymUid func_uid, const SymbolContext &sc); 196 lldb::CompUnitSP CreateCompileUnit(const CompilandIndexItem &cci); 197 lldb::TypeSP CreateType(PdbSymUid type_uid); 198 lldb::TypeSP CreateAndCacheType(PdbSymUid type_uid); 199 lldb::VariableSP CreateGlobalVariable(PdbSymUid var_uid); 200 201 llvm::BumpPtrAllocator m_allocator; 202 203 lldb::addr_t m_obj_load_address = 0; 204 205 std::unique_ptr<PdbIndex> m_index; 206 std::unique_ptr<ClangASTImporter> m_importer; 207 ClangASTContext *m_clang = nullptr; 208 209 llvm::DenseMap<clang::TagDecl *, DeclStatus> m_decl_to_status; 210 211 llvm::DenseMap<lldb::user_id_t, clang::TagDecl *> m_uid_to_decl; 212 213 llvm::DenseMap<lldb::user_id_t, lldb::VariableSP> m_global_vars; 214 llvm::DenseMap<lldb::user_id_t, lldb::FunctionSP> m_functions; 215 llvm::DenseMap<lldb::user_id_t, lldb::CompUnitSP> m_compilands; 216 llvm::DenseMap<lldb::user_id_t, lldb::TypeSP> m_types; 217 }; 218 219 } // namespace npdb 220 } // namespace lldb_private 221 222 #endif // lldb_Plugins_SymbolFile_PDB_SymbolFilePDB_h_ 223