21using namespace llvm::MachO;
24 ObjectContainerMachOArchive)
44 data.
SetData(data_sp, data_offset, length);
46 std::unique_ptr<ObjectContainerUniversalMachO> container_up(
48 file, file_offset, length));
49 if (container_up->ParseHeader()) {
50 return container_up.release();
59 uint32_t magic = data.
GetU32(&offset);
60 return magic == FAT_MAGIC || magic == FAT_CIGAM || magic == FAT_MAGIC_64 ||
61 magic == FAT_CIGAM_64;
70 m_header(), m_fat_archs() {
86 std::vector<FatArch> &fat_archs) {
91 header.magic = data.
GetU32(&offset);
95 if (header.magic == FAT_MAGIC || header.magic == FAT_MAGIC_64) {
96 const bool is_fat64 = header.magic == FAT_MAGIC_64;
99 header.nfat_arch = data.
GetU32(&offset);
104 for (uint32_t arch_idx = 0; arch_idx < header.nfat_arch; ++arch_idx) {
108 arch.cputype = data.
GetU32(&offset);
109 arch.cpusubtype = data.
GetU32(&offset);
110 arch.offset = data.
GetU64(&offset);
111 arch.size = data.
GetU64(&offset);
112 arch.align = data.
GetU32(&offset);
113 arch.reserved = data.
GetU32(&offset);
114 fat_archs.emplace_back(arch);
117 arch.cputype = data.
GetU32(&offset);
118 arch.cpusubtype = data.
GetU32(&offset);
119 arch.offset = data.
GetU32(&offset);
120 arch.size = data.
GetU32(&offset);
121 arch.align = data.
GetU32(&offset);
122 fat_archs.emplace_back(arch);
129 memset(&header, 0,
sizeof(header));
138 uint32_t idx,
ArchSpec &arch)
const {
149 uint32_t arch_idx = 0;
155 if (!module_sp->GetArchitecture().IsValid()) {
160 arch = module_sp->GetArchitecture();
164 for (arch_idx = 0; arch_idx <
m_header.nfat_arch; ++arch_idx) {
171 if (arch_idx >=
m_header.nfat_arch) {
172 for (arch_idx = 0; arch_idx <
m_header.nfat_arch; ++arch_idx) {
179 if (arch_idx <
m_header.nfat_arch) {
184 m_fat_archs[arch_idx].GetSize(), data_sp, data_offset);
194 const size_t initial_count = specs.
GetSize();
197 data.
SetData(data_sp, data_offset, data_sp->GetByteSize());
200 llvm::MachO::fat_header header;
201 std::vector<FatArch> fat_archs;
203 for (
const FatArch &fat_arch : fat_archs) {
205 fat_arch.GetOffset() + file_offset;
206 if (fat_arch.GetOffset() < file_size && file_size > slice_file_offset) {
208 file, slice_file_offset, file_size - slice_file_offset, specs);
213 return specs.
GetSize() - initial_count;
#define LLDB_PLUGIN_DEFINE_ADV(ClassName, PluginName)
bool GetArchitectureAtIndex(uint32_t cpu_idx, lldb_private::ArchSpec &arch) const override
Gets the architecture given an index.
size_t GetNumArchitectures() const override
Get the number of architectures in this object file.
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 llvm::StringRef GetPluginNameStatic()
ObjectContainerUniversalMachO(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)
~ObjectContainerUniversalMachO() override
static bool MagicBytesMatch(const lldb_private::DataExtractor &data)
static llvm::StringRef GetPluginDescriptionStatic()
lldb::ObjectFileSP GetObjectFile(const lldb_private::FileSpec *file) override
Selects an architecture in an object file.
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)
bool ParseHeader() override
Attempts to parse the object header.
std::vector< FatArch > m_fat_archs
llvm::MachO::fat_header m_header
An architecture specification class.
bool IsValid() const
Tests if this ArchSpec is valid.
bool SetTriple(const llvm::Triple &triple)
Architecture triple setter.
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.
bool IsCompatibleMatch(const ArchSpec &rhs) const
Shorthand for IsMatch(rhs, CompatibleMatch).
bool IsExactMatch(const ArchSpec &rhs) const
Shorthand for IsMatch(rhs, ExactMatch).
lldb::ModuleSP GetModule() const
Get const accessor for the module pointer.
A plug-in interface definition class for object containers.
DataExtractor m_data
The data for this object file so things can be parsed lazily.
lldb::addr_t m_offset
The offset in bytes into the file, or the address in memory.
virtual lldb::addr_t GetOffset() const
Returns the offset into a file at which this object resides.
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 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)
static ArchSpec GetDefaultArchitecture()
#define LLDB_ARCH_DEFAULT
CPU Type definitions.
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::ObjectFile > ObjectFileSP
std::shared_ptr< lldb_private::DataBuffer > DataBufferSP
std::shared_ptr< lldb_private::Module > ModuleSP