LLDB mainline
ObjectFileCOFF.h
Go to the documentation of this file.
1//===-- ObjectFileCOFF.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_COFF_OBJECTFILECOFF_H
10#define LLDB_SOURCE_PLUGINS_OBJECTFILE_COFF_OBJECTFILECOFF_H
11
13
14#include "llvm/Object/COFF.h"
15
16/// \class ObjectFileELF
17/// Generic COFF object file reader.
18///
19/// This class provides a generic COFF reader plugin implementing the ObjectFile
20/// protocol. Assumes that the COFF object format is a Microsoft style COFF
21/// rather than the full generality afforded by it.
23 std::unique_ptr<llvm::object::COFFObjectFile> m_object;
25
26 ObjectFileCOFF(std::unique_ptr<llvm::object::COFFObjectFile> object,
27 const lldb::ModuleSP &module_sp, lldb::DataBufferSP data_sp,
28 lldb::offset_t data_offset, const lldb_private::FileSpec *file,
29 lldb::offset_t file_offset, lldb::offset_t length)
30 : ObjectFile(module_sp, file, file_offset, length, data_sp, data_offset),
31 m_object(std::move(object)) {}
32
33public:
34 ~ObjectFileCOFF() override;
35
36 static void Initialize();
37 static void Terminate();
38
39 static llvm::StringRef GetPluginNameStatic() { return "COFF"; }
40 static llvm::StringRef GetPluginDescriptionStatic() {
41 return "COFF Object File Reader";
42 }
43
45 CreateInstance(const lldb::ModuleSP &module_sp, lldb::DataBufferSP data_sp,
46 lldb::offset_t data_offset, const lldb_private::FileSpec *file,
47 lldb::offset_t file_offset, lldb::offset_t length);
48
50 CreateMemoryInstance(const lldb::ModuleSP &module_sp,
52 const lldb::ProcessSP &process_sp, lldb::addr_t header);
53
54 static size_t GetModuleSpecifications(const lldb_private::FileSpec &file,
55 lldb::DataBufferSP &data_sp,
56 lldb::offset_t data_offset,
57 lldb::offset_t file_offset,
58 lldb::offset_t length,
60
61 // LLVM RTTI support
62 static char ID;
63 bool isA(const void *ClassID) const override {
64 return ClassID == &ID || ObjectFile::isA(ClassID);
65 }
66 static bool classof(const ObjectFile *obj) { return obj->isA(&ID); }
67
68 // PluginInterface protocol
69 llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
70
71 // ObjectFile protocol
72 void Dump(lldb_private::Stream *stream) override;
73
74 uint32_t GetAddressByteSize() const override;
75
77 return 0;
78 }
79
80 bool IsExecutable() const override {
81 // COFF is an object file format only, it cannot host an executable.
82 return false;
83 }
84
86
88
89 void ParseSymtab(lldb_private::Symtab &) override;
90
91 bool IsStripped() override {
92 // FIXME see if there is a good way to identify a /Z7 v /Zi or /ZI build.
93 return false;
94 }
95
96 lldb_private::UUID GetUUID() override { return m_uuid; }
97
98 lldb::ByteOrder GetByteOrder() const override {
99 // Microsoft always uses little endian.
101 }
102
103 bool ParseHeader() override;
104
106 // COFF is an object file format only, it cannot host an executable.
108 }
109
111 // FIXME the object file may correspond to a kernel image.
113 }
114};
115
116#endif
uint32_t GetAddressByteSize() const override
Gets the address size in bytes for the current object file.
static bool classof(const ObjectFile *obj)
void ParseSymtab(lldb_private::Symtab &) override
Parse the symbol table into the provides symbol table object.
static lldb_private::ObjectFile * CreateInstance(const lldb::ModuleSP &module_sp, lldb::DataBufferSP data_sp, lldb::offset_t data_offset, const lldb_private::FileSpec *file, lldb::offset_t file_offset, lldb::offset_t length)
static size_t GetModuleSpecifications(const lldb_private::FileSpec &file, lldb::DataBufferSP &data_sp, lldb::offset_t data_offset, lldb::offset_t file_offset, lldb::offset_t length, lldb_private::ModuleSpecList &specs)
uint32_t GetDependentModules(lldb_private::FileSpecList &specs) override
Extract the dependent modules from an object file.
lldb_private::ObjectFile::Type CalculateType() override
The object file should be able to calculate its type by looking at its file header and possibly the s...
llvm::StringRef GetPluginName() override
static lldb_private::ObjectFile * CreateMemoryInstance(const lldb::ModuleSP &module_sp, lldb::WritableDataBufferSP data_sp, const lldb::ProcessSP &process_sp, lldb::addr_t header)
static void Initialize()
lldb_private::UUID GetUUID() override
Gets the UUID for this object file.
void Dump(lldb_private::Stream *stream) override
Dump a description of this object to a Stream.
void CreateSections(lldb_private::SectionList &) override
bool IsStripped() override
Detect if this object file has been stripped of local symbols.
lldb_private::UUID m_uuid
bool isA(const void *ClassID) const override
bool IsExecutable() const override
Tells whether this object file is capable of being the main executable for a process.
static char ID
static llvm::StringRef GetPluginDescriptionStatic()
lldb_private::ArchSpec GetArchitecture() override
Get the ArchSpec for this object file.
~ObjectFileCOFF() override
bool ParseHeader() override
Attempts to parse the object header.
lldb::ByteOrder GetByteOrder() const override
Gets whether endian swapping should occur when extracting data from this object file.
lldb_private::ObjectFile::Strata CalculateStrata() override
The object file should be able to calculate the strata of the object file.
static void Terminate()
ObjectFileCOFF(std::unique_ptr< llvm::object::COFFObjectFile > object, const lldb::ModuleSP &module_sp, lldb::DataBufferSP data_sp, lldb::offset_t data_offset, const lldb_private::FileSpec *file, lldb::offset_t file_offset, lldb::offset_t length)
std::unique_ptr< llvm::object::COFFObjectFile > m_object
static llvm::StringRef GetPluginNameStatic()
An architecture specification class.
Definition: ArchSpec.h:31
A file collection class.
Definition: FileSpecList.h:85
A file utility class.
Definition: FileSpec.h:56
A plug-in interface definition class for object file parsers.
Definition: ObjectFile.h:44
ObjectFile(const lldb::ModuleSP &module_sp, const FileSpec *file_spec_ptr, lldb::offset_t file_offset, lldb::offset_t length, lldb::DataBufferSP data_sp, lldb::offset_t data_offset)
Construct with a parent module, offset, and header data.
Definition: ObjectFile.cpp:241
@ eTypeObjectFile
An intermediate object file.
Definition: ObjectFile.h:59
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
uint64_t offset_t
Definition: lldb-types.h:83
std::shared_ptr< lldb_private::Process > ProcessSP
Definition: lldb-forward.h:381
ByteOrder
Byte ordering definitions.
@ eByteOrderLittle
std::shared_ptr< lldb_private::DataBuffer > DataBufferSP
Definition: lldb-forward.h:328
std::shared_ptr< lldb_private::WritableDataBuffer > WritableDataBufferSP
Definition: lldb-forward.h:329
uint64_t addr_t
Definition: lldb-types.h:79
std::shared_ptr< lldb_private::Module > ModuleSP
Definition: lldb-forward.h:365