LLDB  mainline
ObjectFilePDB.h
Go to the documentation of this file.
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 llvm::StringRef GetPluginNameStatic() { return "pdb"; }
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
51  llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
52 
53  // LLVM RTTI support
54  static char ID;
55  bool isA(const void *ClassID) const override {
56  return ClassID == &ID || ObjectFile::isA(ClassID);
57  }
58  static bool classof(const ObjectFile *obj) { return obj->isA(&ID); }
59 
60  // ObjectFile Protocol.
61  uint32_t GetAddressByteSize() const override { return 8; }
62 
63  lldb::ByteOrder GetByteOrder() const override {
65  }
66 
67  bool ParseHeader() override { return true; }
68 
69  bool IsExecutable() const override { return false; }
70 
71  Symtab *GetSymtab() override { return nullptr; }
72 
73  bool IsStripped() override { return false; }
74 
75  // No section in PDB file.
76  void CreateSections(SectionList &unified_section_list) override {}
77 
78  void Dump(Stream *s) override {}
79 
80  ArchSpec GetArchitecture() override;
81 
82  UUID GetUUID() override { return m_uuid; }
83 
84  uint32_t GetDependentModules(FileSpecList &files) override { return 0; }
85 
86  Type CalculateType() override { return eTypeDebugInfo; }
87 
88  Strata CalculateStrata() override { return eStrataUser; }
89 
90  llvm::pdb::PDBFile &GetPDBFile() { return *m_file_up; }
91 
92  ObjectFilePDB(const lldb::ModuleSP &module_sp, lldb::DataBufferSP &data_sp,
93  lldb::offset_t data_offset, const FileSpec *file,
94  lldb::offset_t offset, lldb::offset_t length);
95 
96 private:
98  llvm::BumpPtrAllocator m_allocator;
99  std::unique_ptr<llvm::pdb::PDBFile> m_file_up;
100 
101  bool initPDBFile();
102 };
103 
104 } // namespace lldb_private
105 #endif // LLDB_PLUGINS_OBJECTFILE_PDB_OBJECTFILEPDB_H
lldb_private::ObjectFile::isA
virtual bool isA(const void *ClassID) const
Definition: ObjectFile.h:226
lldb_private::UUID
Definition: UUID.h:23
lldb_private::ObjectFilePDB::IsExecutable
bool IsExecutable() const override
Tells whether this object file is capable of being the main executable for a process.
Definition: ObjectFilePDB.h:69
lldb_private::ArchSpec
Definition: ArchSpec.h:33
lldb_private::ObjectFilePDB::GetSymtab
Symtab * GetSymtab() override
Gets the symbol table for the currently selected architecture (and object for archives).
Definition: ObjectFilePDB.h:71
lldb_private::ModuleSpecList
Definition: ModuleSpec.h:280
lldb_private::ObjectFilePDB::ParseHeader
bool ParseHeader() override
Attempts to parse the object header.
Definition: ObjectFilePDB.h:67
lldb_private::ObjectFilePDB::GetModuleSpecifications
static size_t GetModuleSpecifications(const FileSpec &file, lldb::DataBufferSP &data_sp, lldb::offset_t data_offset, lldb::offset_t file_offset, lldb::offset_t length, ModuleSpecList &specs)
Definition: ObjectFilePDB.cpp:107
lldb_private::ObjectFilePDB::GetUUID
UUID GetUUID() override
Gets the UUID for this object file.
Definition: ObjectFilePDB.h:82
lldb_private::SectionList
Definition: Section.h:34
lldb::offset_t
uint64_t offset_t
Definition: lldb-types.h:87
lldb_private::Stream
Definition: Stream.h:28
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
lldb_private::ObjectFile::Type
Type
Definition: ObjectFile.h:64
lldb_private::ObjectFilePDB::Terminate
static void Terminate()
Definition: ObjectFilePDB.cpp:45
lldb_private::ObjectFilePDB::GetByteOrder
lldb::ByteOrder GetByteOrder() const override
Gets whether endian swapping should occur when extracting data from this object file.
Definition: ObjectFilePDB.h:63
lldb_private::FileSpec
Definition: FileSpec.h:56
lldb_private::ObjectFilePDB::ID
static char ID
Definition: ObjectFilePDB.h:54
lldb_private::ObjectFilePDB::CreateInstance
static ObjectFile * CreateInstance(const lldb::ModuleSP &module_sp, lldb::DataBufferSP &data_sp, lldb::offset_t data_offset, const FileSpec *file, lldb::offset_t file_offset, lldb::offset_t length)
Definition: ObjectFilePDB.cpp:90
lldb_private::ObjectFilePDB::CreateSections
void CreateSections(SectionList &unified_section_list) override
Definition: ObjectFilePDB.h:76
lldb_private::ObjectFile::eStrataUser
@ eStrataUser
Definition: ObjectFile.h:88
lldb_private::ObjectFilePDB::GetPluginDescriptionStatic
static const char * GetPluginDescriptionStatic()
Definition: ObjectFilePDB.h:26
lldb_private::ObjectFilePDB::CalculateType
Type CalculateType() override
The object file should be able to calculate its type by looking at its file header and possibly the s...
Definition: ObjectFilePDB.h:86
lldb_private::ObjectFilePDB::isA
bool isA(const void *ClassID) const override
Definition: ObjectFilePDB.h:55
lldb_private::ObjectFilePDB::CreateMemoryInstance
static ObjectFile * CreateMemoryInstance(const lldb::ModuleSP &module_sp, lldb::DataBufferSP &data_sp, const lldb::ProcessSP &process_sp, lldb::addr_t header_addr)
Definition: ObjectFilePDB.cpp:100
lldb_private::ObjectFilePDB::Dump
void Dump(Stream *s) override
Dump a description of this object to a Stream.
Definition: ObjectFilePDB.h:78
lldb_private::ObjectFilePDB::GetAddressByteSize
uint32_t GetAddressByteSize() const override
Gets the address size in bytes for the current object file.
Definition: ObjectFilePDB.h:61
lldb_private::ObjectFilePDB::GetPluginNameStatic
static llvm::StringRef GetPluginNameStatic()
Definition: ObjectFilePDB.h:25
lldb_private::ObjectFilePDB::classof
static bool classof(const ObjectFile *obj)
Definition: ObjectFilePDB.h:58
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:40
lldb_private::ObjectFilePDB::m_file_up
std::unique_ptr< llvm::pdb::PDBFile > m_file_up
Definition: ObjectFilePDB.h:99
lldb_private::ObjectFilePDB::GetArchitecture
ArchSpec GetArchitecture() override
Get the ArchSpec for this object file.
Definition: ObjectFilePDB.cpp:49
ObjectFile.h
lldb_private::ObjectFilePDB::initPDBFile
bool initPDBFile()
Definition: ObjectFilePDB.cpp:76
lldb_private::ObjectFilePDB::IsStripped
bool IsStripped() override
Detect if this object file has been stripped of local symbols.
Definition: ObjectFilePDB.h:73
lldb_private::ObjectFilePDB::CalculateStrata
Strata CalculateStrata() override
The object file should be able to calculate the strata of the object file.
Definition: ObjectFilePDB.h:88
lldb_private::ObjectFilePDB::ObjectFilePDB
ObjectFilePDB(const lldb::ModuleSP &module_sp, lldb::DataBufferSP &data_sp, lldb::offset_t data_offset, const FileSpec *file, lldb::offset_t offset, lldb::offset_t length)
Definition: ObjectFilePDB.cpp:158
lldb_private::Symtab
Definition: Symtab.h:22
uint32_t
lldb_private::ObjectFile::eTypeDebugInfo
@ eTypeDebugInfo
An object file that contains only debug information.
Definition: ObjectFile.h:71
lldb_private::ObjectFilePDB::GetDependentModules
uint32_t GetDependentModules(FileSpecList &files) override
Extract the dependent modules from an object file.
Definition: ObjectFilePDB.h:84
lldb_private::ObjectFilePDB::Initialize
static void Initialize()
Definition: ObjectFilePDB.cpp:39
lldb_private::ObjectFilePDB
Definition: ObjectFilePDB.h:19
lldb_private::ObjectFilePDB::GetPluginName
llvm::StringRef GetPluginName() override
Definition: ObjectFilePDB.h:51
ArchSpec.h
lldb_private::ObjectFilePDB::m_uuid
UUID m_uuid
Definition: ObjectFilePDB.h:97
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::ObjectFilePDB::loadPDBFile
static std::unique_ptr< llvm::pdb::PDBFile > loadPDBFile(std::string PdbPath, llvm::BumpPtrAllocator &Allocator)
Definition: ObjectFilePDB.cpp:164
lldb_private::ObjectFilePDB::m_allocator
llvm::BumpPtrAllocator m_allocator
Definition: ObjectFilePDB.h:98
lldb::eByteOrderLittle
@ eByteOrderLittle
Definition: lldb-enumerations.h:142
lldb_private::ObjectFile::Strata
Strata
Definition: ObjectFile.h:85
lldb_private::ObjectFile
Definition: ObjectFile.h:58
lldb::ByteOrder
ByteOrder
Byte ordering definitions.
Definition: lldb-enumerations.h:138
lldb_private::ObjectFilePDB::GetPDBFile
llvm::pdb::PDBFile & GetPDBFile()
Definition: ObjectFilePDB.h:90