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,
28 lldb::DataExtractorSP extractor_sp, lldb::offset_t data_offset,
29 const lldb_private::FileSpec *file, lldb::offset_t file_offset,
30 lldb::offset_t length)
31 : ObjectFile(module_sp, file, file_offset, length, extractor_sp,
32 data_offset),
33 m_object(std::move(object)) {}
34
35public:
36 ~ObjectFileCOFF() override;
37
38 static void Initialize();
39 static void Terminate();
40
41 static llvm::StringRef GetPluginNameStatic() { return "COFF"; }
42 static llvm::StringRef GetPluginDescriptionStatic() {
43 return "COFF Object File Reader";
44 }
45
47 CreateInstance(const lldb::ModuleSP &module_sp,
48 lldb::DataExtractorSP extractor_sp, lldb::offset_t data_offset,
49 const lldb_private::FileSpec *file, lldb::offset_t file_offset,
50 lldb::offset_t length);
51
53 CreateMemoryInstance(const lldb::ModuleSP &module_sp,
55 const lldb::ProcessSP &process_sp, lldb::addr_t header);
56
57 static size_t GetModuleSpecifications(const lldb_private::FileSpec &file,
58 lldb::DataBufferSP &data_sp,
59 lldb::offset_t data_offset,
60 lldb::offset_t file_offset,
61 lldb::offset_t length,
63
64 // LLVM RTTI support
65 static char ID;
66 bool isA(const void *ClassID) const override {
67 return ClassID == &ID || ObjectFile::isA(ClassID);
68 }
69 static bool classof(const ObjectFile *obj) { return obj->isA(&ID); }
70
71 // PluginInterface protocol
72 llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
73
74 // ObjectFile protocol
75 void Dump(lldb_private::Stream *stream) override;
76
77 uint32_t GetAddressByteSize() const override;
78
80 return 0;
81 }
82
83 bool IsExecutable() const override {
84 // COFF is an object file format only, it cannot host an executable.
85 return false;
86 }
87
89
91
92 void ParseSymtab(lldb_private::Symtab &) override;
93
94 bool IsStripped() override {
95 // FIXME see if there is a good way to identify a /Z7 v /Zi or /ZI build.
96 return false;
97 }
98
99 lldb_private::UUID GetUUID() override { return m_uuid; }
100
101 lldb::ByteOrder GetByteOrder() const override {
102 // Microsoft always uses little endian.
104 }
105
106 bool ParseHeader() override;
107
109 // COFF is an object file format only, it cannot host an executable.
111 }
112
114 // FIXME the object file may correspond to a kernel image.
116 }
117};
118
119#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 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()
std::unique_ptr< llvm::object::COFFObjectFile > m_object
ObjectFileCOFF(std::unique_ptr< llvm::object::COFFObjectFile > object, const lldb::ModuleSP &module_sp, lldb::DataExtractorSP extractor_sp, lldb::offset_t data_offset, const lldb_private::FileSpec *file, lldb::offset_t file_offset, lldb::offset_t length)
static lldb_private::ObjectFile * CreateInstance(const lldb::ModuleSP &module_sp, lldb::DataExtractorSP extractor_sp, lldb::offset_t data_offset, const lldb_private::FileSpec *file, lldb::offset_t file_offset, lldb::offset_t length)
static llvm::StringRef GetPluginNameStatic()
An architecture specification class.
Definition ArchSpec.h:31
A file collection class.
A file utility class.
Definition FileSpec.h:57
A plug-in interface definition class for object file parsers.
Definition ObjectFile.h:46
@ eTypeObjectFile
An intermediate object file.
Definition ObjectFile.h:61
ObjectFile(const lldb::ModuleSP &module_sp, const FileSpec *file_spec_ptr, lldb::offset_t file_offset, lldb::offset_t length, lldb::DataExtractorSP extractor_sp, lldb::offset_t data_offset)
Construct with a parent module, offset, and header data.
A stream class that can stream formatted output to a file.
Definition Stream.h:28
Represents UUID's of various sizes.
Definition UUID.h:27
uint64_t offset_t
Definition lldb-types.h:85
std::shared_ptr< lldb_private::Process > ProcessSP
ByteOrder
Byte ordering definitions.
std::shared_ptr< lldb_private::DataBuffer > DataBufferSP
std::shared_ptr< lldb_private::WritableDataBuffer > WritableDataBufferSP
uint64_t addr_t
Definition lldb-types.h:80
std::shared_ptr< lldb_private::DataExtractor > DataExtractorSP
std::shared_ptr< lldb_private::Module > ModuleSP