28#include "llvm/ADT/StringRef.h"
29#include "llvm/BinaryFormat/XCOFF.h"
30#include "llvm/Object/XCOFFObjectFile.h"
31#include "llvm/Support/MemoryBuffer.h"
35#include <unordered_map>
48 GetPluginDescriptionStatic(), CreateInstance,
49 CreateMemoryInstance, GetModuleSpecifications);
71 if (data_sp->GetByteSize() < length) {
77 auto objfile_up = std::make_unique<ObjectFileXCOFF>(
78 module_sp, data_sp, data_offset, file, file_offset, length);
83 if (!objfile_up->CreateBinary())
86 if (!objfile_up->ParseHeader())
89 return objfile_up.release();
98 auto binary = llvm::object::ObjectFile::createObjectFile(
101 file_magic::xcoff_object_64);
104 "Failed to create binary for file ({1}): {0}",
m_file);
109 llvm::unique_dyn_cast<llvm::object::XCOFFObjectFile>(std::move(*binary));
113 LLDB_LOG(log,
"this = {0}, module = {1} ({2}), file = {3}, binary = {4}",
130 const size_t initial_count = specs.
GetSize();
141 return specs.
GetSize() - initial_count;
150 return sizeof(
struct llvm::object::XCOFFFileHeader64);
163 data.
SetData(data_sp, data_offset, data_length);
167 uint16_t magic = data.
GetU16(&offset);
173 return m_binary->fileHeader64()->Magic == XCOFF::XCOFF64;
186 return AddressClass::eUnknown;
208 if (
m_binary->fileHeader64()->Flags & XCOFF::F_EXEC)
210 else if (
m_binary->fileHeader64()->Flags & XCOFF::F_SHROBJ)
230 :
ObjectFile(module_sp, file, file_offset, length, data_sp, data_offset) {
239 :
ObjectFile(module_sp, process_sp, header_addr, header_data_sp) {}
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
#define LLDB_LOG_ERROR(log, error,...)
static uint32_t XCOFFHeaderSizeFromMagic(uint32_t magic)
#define LLDB_PLUGIN_DEFINE(PluginName)
Generic XCOFF object file reader.
ObjectFile::Type CalculateType() override
The object file should be able to calculate its type by looking at its file header and possibly the s...
bool ParseHeader() override
Attempts to parse the object header.
uint32_t GetAddressByteSize() const override
Gets the address size in bytes for the current object file.
static lldb::WritableDataBufferSP MapFileDataWritable(const lldb_private::FileSpec &file, uint64_t Size, uint64_t Offset)
lldb_private::ArchSpec GetArchitecture() override
Get the ArchSpec for this object file.
uint32_t GetDependentModules(lldb_private::FileSpecList &files) override
Extract the dependent modules from an object file.
void ParseSymtab(lldb_private::Symtab &symtab) override
Parse the symbol table into the provides symbol table object.
ObjectFile::Strata CalculateStrata() override
The object file should be able to calculate the strata of the object file.
static lldb_private::ObjectFile * CreateMemoryInstance(const lldb::ModuleSP &module_sp, lldb::WritableDataBufferSP data_sp, const lldb::ProcessSP &process_sp, lldb::addr_t header_addr)
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)
static bool MagicBytesMatch(lldb::DataBufferSP &data_sp, lldb::addr_t offset, lldb::addr_t length)
lldb::ByteOrder GetByteOrder() const override
Gets whether endian swapping should occur when extracting data from this object file.
void CreateSections(lldb_private::SectionList &unified_section_list) override
lldb_private::AddressClass GetAddressClass(lldb::addr_t file_addr) override
Get the address type given a file address in an object file.
bool IsExecutable() const override
Tells whether this object file is capable of being the main executable for a process.
lldb_private::UUID GetUUID() override
Gets the UUID for this object file.
ObjectFileXCOFF(const lldb::ModuleSP &module_sp, lldb::DataBufferSP data_sp, lldb::offset_t data_offset, const lldb_private::FileSpec *file, lldb::offset_t offset, lldb::offset_t length)
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)
bool IsStripped() override
Detect if this object file has been stripped of local symbols.
void Dump(lldb_private::Stream *s) override
Dump a description of this object to a Stream.
std::unique_ptr< llvm::object::XCOFFObjectFile > m_binary
An architecture specification class.
bool SetArchitecture(ArchitectureType arch_type, uint32_t cpu, uint32_t sub, uint32_t os=0)
Change the architecture object type, CPU type and OS type.
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
const ConstString & GetFilename() const
Filename string const get accessor.
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
std::shared_ptr< WritableDataBuffer > CreateWritableDataBuffer(const llvm::Twine &path, uint64_t size=0, uint64_t offset=0)
static FileSystem & Instance()
lldb::ModuleSP GetModule() const
Get const accessor for the module pointer.
void Append(const ModuleSpec &spec)
ArchSpec & GetArchitecture()
A plug-in interface definition class for object file parsers.
DataExtractor m_data
The data for this object file so things can be parsed lazily.
static lldb::DataBufferSP MapFileData(const FileSpec &file, uint64_t Size, uint64_t Offset)
@ eTypeExecutable
A normal executable.
@ eTypeSharedLibrary
A shared library that can be used during execution.
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
static bool UnregisterPlugin(ABICreateInstance create_callback)
A stream class that can stream formatted output to a file.
#define LLDB_INVALID_CPUTYPE
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
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
std::shared_ptr< lldb_private::Module > ModuleSP