1 //===-- ObjectFilePDB.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_OBJECTFILE_PDB_OBJECTFILEPDB_H 10 #define LLDB_SOURCE_PLUGINS_OBJECTFILE_PDB_OBJECTFILEPDB_H 11 12 #include "lldb/Symbol/ObjectFile.h" 13 #include "lldb/Utility/ArchSpec.h" 14 #include "llvm/DebugInfo/PDB/Native/NativeSession.h" 15 #include "llvm/DebugInfo/PDB/PDBTypes.h" 16 17 namespace lldb_private { 18 19 class ObjectFilePDB : public ObjectFile { 20 public: 21 // Static Functions 22 static void Initialize(); 23 static void Terminate(); 24 25 static ConstString GetPluginNameStatic(); GetPluginDescriptionStatic()26 static const char *GetPluginDescriptionStatic() { 27 return "PDB object file reader."; 28 } 29 30 static std::unique_ptr<llvm::pdb::PDBFile> 31 loadPDBFile(std::string PdbPath, llvm::BumpPtrAllocator &Allocator); 32 33 static ObjectFile * 34 CreateInstance(const lldb::ModuleSP &module_sp, lldb::DataBufferSP &data_sp, 35 lldb::offset_t data_offset, const FileSpec *file, 36 lldb::offset_t file_offset, lldb::offset_t length); 37 38 static ObjectFile *CreateMemoryInstance(const lldb::ModuleSP &module_sp, 39 lldb::DataBufferSP &data_sp, 40 const lldb::ProcessSP &process_sp, 41 lldb::addr_t header_addr); 42 43 static size_t GetModuleSpecifications(const FileSpec &file, 44 lldb::DataBufferSP &data_sp, 45 lldb::offset_t data_offset, 46 lldb::offset_t file_offset, 47 lldb::offset_t length, 48 ModuleSpecList &specs); 49 50 // PluginInterface protocol GetPluginName()51 ConstString GetPluginName() override { return GetPluginNameStatic(); } 52 GetPluginVersion()53 uint32_t GetPluginVersion() override { return 1; } 54 55 // LLVM RTTI support 56 static char ID; isA(const void * ClassID)57 bool isA(const void *ClassID) const override { 58 return ClassID == &ID || ObjectFile::isA(ClassID); 59 } classof(const ObjectFile * obj)60 static bool classof(const ObjectFile *obj) { return obj->isA(&ID); } 61 62 // ObjectFile Protocol. GetAddressByteSize()63 uint32_t GetAddressByteSize() const override { return 8; } 64 GetByteOrder()65 lldb::ByteOrder GetByteOrder() const override { 66 return lldb::eByteOrderLittle; 67 } 68 ParseHeader()69 bool ParseHeader() override { return true; } 70 IsExecutable()71 bool IsExecutable() const override { return false; } 72 GetSymtab()73 Symtab *GetSymtab() override { return nullptr; } 74 IsStripped()75 bool IsStripped() override { return false; } 76 77 // No section in PDB file. CreateSections(SectionList & unified_section_list)78 void CreateSections(SectionList &unified_section_list) override {} 79 Dump(Stream * s)80 void Dump(Stream *s) override {} 81 82 ArchSpec GetArchitecture() override; 83 GetUUID()84 UUID GetUUID() override { return m_uuid; } 85 GetDependentModules(FileSpecList & files)86 uint32_t GetDependentModules(FileSpecList &files) override { return 0; } 87 CalculateType()88 Type CalculateType() override { return eTypeDebugInfo; } 89 CalculateStrata()90 Strata CalculateStrata() override { return eStrataUser; } 91 GetPDBFile()92 llvm::pdb::PDBFile &GetPDBFile() { return *m_file_up; } 93 94 ObjectFilePDB(const lldb::ModuleSP &module_sp, lldb::DataBufferSP &data_sp, 95 lldb::offset_t data_offset, const FileSpec *file, 96 lldb::offset_t offset, lldb::offset_t length); 97 98 private: 99 UUID m_uuid; 100 llvm::BumpPtrAllocator m_allocator; 101 std::unique_ptr<llvm::pdb::PDBFile> m_file_up; 102 103 bool initPDBFile(); 104 }; 105 106 } // namespace lldb_private 107 #endif // LLDB_PLUGINS_OBJECTFILE_PDB_OBJECTFILEPDB_H 108