22using namespace llvm::MachO;
28 GetPluginDescriptionStatic(), CreateInstance,
29 GetModuleSpecifications, CreateMemoryInstance);
40 :
ObjectContainer(module_sp, file, offset, length, data_sp, data_offset),
46 :
ObjectContainer(module_sp, nullptr, 0, data_sp->GetByteSize(), data_sp,
48 m_process_wp(process_sp), m_memory_addr(header_addr) {}
58 data.
SetData(data_sp, data_offset, length);
62 auto container_up = std::make_unique<ObjectContainerMachOFileset>(
63 module_sp, data_sp, data_offset, file, file_offset, length);
64 if (!container_up->ParseHeader())
67 return container_up.release();
76 auto container_up = std::make_unique<ObjectContainerMachOFileset>(
77 module_sp, data_sp, process_sp, header_addr);
78 if (!container_up->ParseHeader())
81 return container_up.release();
90 return sizeof(
struct mach_header);
93 return sizeof(
struct mach_header_64);
102 header.magic = data.
GetU32(&offset);
103 switch (header.magic) {
128 header.cputype = data.
GetU32(&offset);
129 header.cpusubtype = data.
GetU32(&offset);
130 header.filetype = data.
GetU32(&offset);
131 header.ncmds = data.
GetU32(&offset);
132 header.sizeofcmds = data.
GetU32(&offset);
138 std::vector<ObjectContainerMachOFileset::Entry> &entries,
139 std::optional<lldb::addr_t> load_addr = std::nullopt) {
142 for (uint32_t i = 0; i < header.ncmds; ++i) {
144 load_command lc = {};
145 if (data.
GetU32(&offset, &lc.cmd, 2) ==
nullptr)
150 if (lc.cmd == llvm::MachO::LC_SEGMENT_64) {
151 segment_command_64 segment;
152 data.
CopyData(load_cmd_offset,
sizeof(segment_command_64), &segment);
153 if (llvm::StringRef(segment.segname) ==
"__TEXT")
154 slide = *load_addr - segment.vmaddr;
158 if (lc.cmd == LC_FILESET_ENTRY) {
159 fileset_entry_command entry;
160 data.
CopyData(load_cmd_offset,
sizeof(fileset_entry_command), &entry);
161 lldb::offset_t entry_id_offset = load_cmd_offset + entry.entry_id.offset;
162 if (
const char *
id = data.
GetCStr(&entry_id_offset))
163 entries.emplace_back(entry.vmaddr + slide, entry.fileoff,
167 offset = load_cmd_offset + lc.cmdsize;
182 const size_t header_and_lc_size = header_size + header->sizeofcmds;
198 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
205 const size_t header_and_lc_size = header_size + header->sizeofcmds;
224 const size_t initial_count = specs.
GetSize();
227 data.
SetData(data_sp, data_offset, data_sp->GetByteSize());
230 std::vector<Entry> entries;
231 if (
ParseHeader(data, file, file_offset, entries)) {
232 for (
const Entry &entry : entries) {
235 file, entry_offset, file_size - entry_offset, specs)) {
242 return specs.
GetSize() - initial_count;
249 data.
SetData(data_sp, data_offset, data_length);
255 uint32_t magic = data.
GetU32(&offset);
267 uint32_t filetype = data.
GetU32(&offset);
268 return filetype == MH_FILESET;
277 ConstString object_name = module_sp->GetObjectName();
static bool ParseFileset(DataExtractor &data, mach_header header, std::vector< ObjectContainerMachOFileset::Entry > &entries, std::optional< lldb::addr_t > load_addr=std::nullopt)
static std::optional< mach_header > ParseMachOHeader(DataExtractor &data)
static uint32_t MachHeaderSizeFromMagic(uint32_t magic)
#define LLDB_PLUGIN_DEFINE(PluginName)
A uniqued constant string class.
const char * GetCString() const
Get the string value as a C string.
lldb::ModuleSP GetModule() const
Get const accessor for the module pointer.
ModuleSpec & GetModuleSpecRefAtIndex(size_t i)
ConstString & GetObjectName()
static bool MagicBytesMatch(const lldb_private::DataExtractor &data)
static lldb_private::ObjectContainer * CreateInstance(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)
~ObjectContainerMachOFileset() override
ObjectContainerMachOFileset(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::ObjectContainer * CreateMemoryInstance(const lldb::ModuleSP &module_sp, lldb::WritableDataBufferSP data_sp, const lldb::ProcessSP &process_sp, lldb::addr_t header_addr)
Entry * FindEntry(llvm::StringRef id)
const lldb::addr_t m_memory_addr
lldb::ProcessWP m_process_wp
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)
std::vector< Entry > m_entries
bool ParseHeader() override
Attempts to parse the object header.
lldb::ObjectFileSP GetObjectFile(const lldb_private::FileSpec *file) override
Selects an architecture in an object file.
A plug-in interface definition class for object containers.
DataExtractor m_data
The data for this object file so things can be parsed lazily.
FileSpec m_file
The file that represents this container objects (which can be different from the module's file).
lldb::addr_t m_offset
The offset in bytes into the file, or the address in memory.
static lldb::ObjectFileSP FindPlugin(const lldb::ModuleSP &module_sp, const FileSpec *file_spec, lldb::offset_t file_offset, lldb::offset_t file_size, lldb::DataBufferSP &data_sp, lldb::offset_t &data_offset)
Find a ObjectFile plug-in that can parse file_spec.
static lldb::DataBufferSP MapFileData(const FileSpec &file, uint64_t Size, uint64_t Offset)
static lldb::WritableDataBufferSP ReadMemory(const lldb::ProcessSP &process_sp, lldb::addr_t addr, size_t byte_size)
static size_t GetModuleSpecifications(const FileSpec &file, lldb::offset_t file_offset, lldb::offset_t file_size, ModuleSpecList &specs, lldb::DataBufferSP data_sp=lldb::DataBufferSP())
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
static bool UnregisterPlugin(ABICreateInstance create_callback)
#define LLDB_INVALID_ADDRESS
lldb::ByteOrder InlHostByteOrder()
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::ObjectFile > ObjectFileSP
std::shared_ptr< lldb_private::Process > ProcessSP
std::shared_ptr< lldb_private::DataBuffer > DataBufferSP
std::shared_ptr< lldb_private::WritableDataBuffer > WritableDataBufferSP
std::shared_ptr< lldb_private::Module > ModuleSP