LLDB mainline
ObjectContainerUniversalMachO.h
Go to the documentation of this file.
1//===-- ObjectContainerUniversalMachO.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_OBJECTCONTAINER_UNIVERSAL_MACH_O_OBJECTCONTAINERUNIVERSALMACHO_H
10#define LLDB_SOURCE_PLUGINS_OBJECTCONTAINER_UNIVERSAL_MACH_O_OBJECTCONTAINERUNIVERSALMACHO_H
11
12#include "lldb/Host/SafeMachO.h"
15
17public:
19 lldb::DataBufferSP &data_sp,
20 lldb::offset_t data_offset,
21 const lldb_private::FileSpec *file,
22 lldb::offset_t offset, lldb::offset_t length);
23
25
26 // Static Functions
27 static void Initialize();
28
29 static void Terminate();
30
31 static llvm::StringRef GetPluginNameStatic() { return "mach-o"; }
32
33 static llvm::StringRef GetPluginDescriptionStatic() {
34 return "Universal mach-o object container reader.";
35 }
36
38 CreateInstance(const lldb::ModuleSP &module_sp, lldb::DataBufferSP &data_sp,
39 lldb::offset_t data_offset, const lldb_private::FileSpec *file,
40 lldb::offset_t offset, lldb::offset_t length);
41
44 lldb::DataExtractorSP &extractor_sp,
45 lldb::offset_t file_offset, lldb::offset_t length);
46
47 static bool MagicBytesMatch(const lldb_private::DataExtractor &data);
48
49 // Member Functions
50 bool ParseHeader() override;
51
52 size_t GetNumArchitectures() const override;
53
54 bool GetArchitectureAtIndex(uint32_t cpu_idx,
55 lldb_private::ArchSpec &arch) const override;
56
58
59 // PluginInterface protocol
60 llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
61
62protected:
63 llvm::MachO::fat_header m_header;
64
65 struct FatArch {
66 FatArch(llvm::MachO::fat_arch arch) : m_arch(arch), m_is_fat64(false) {}
67 FatArch(llvm::MachO::fat_arch_64 arch) : m_arch(arch), m_is_fat64(true) {}
68
69 uint32_t GetCPUType() const {
70 return m_is_fat64 ? m_arch.fat_arch_64.cputype : m_arch.fat_arch.cputype;
71 }
72
73 uint32_t GetCPUSubType() const {
74 return m_is_fat64 ? m_arch.fat_arch_64.cpusubtype
75 : m_arch.fat_arch.cpusubtype;
76 }
77
78 uint64_t GetOffset() const {
79 return m_is_fat64 ? m_arch.fat_arch_64.offset : m_arch.fat_arch.offset;
80 }
81
82 uint64_t GetSize() const {
83 return m_is_fat64 ? m_arch.fat_arch_64.size : m_arch.fat_arch.size;
84 }
85
86 uint32_t GetAlign() const {
87 return m_is_fat64 ? m_arch.fat_arch_64.align : m_arch.fat_arch.align;
88 }
89
90 private:
91 const union Arch {
92 Arch(llvm::MachO::fat_arch arch) : fat_arch(arch) {}
93 Arch(llvm::MachO::fat_arch_64 arch) : fat_arch_64(arch) {}
94 llvm::MachO::fat_arch fat_arch;
95 llvm::MachO::fat_arch_64 fat_arch_64;
97 const bool m_is_fat64;
98 };
99 std::vector<FatArch> m_fat_archs;
100
102 llvm::MachO::fat_header &header,
103 std::vector<FatArch> &fat_archs);
104};
105
106#endif // LLDB_SOURCE_PLUGINS_OBJECTCONTAINER_UNIVERSAL_MACH_O_OBJECTCONTAINERUNIVERSALMACHO_H
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 lldb_private::ModuleSpecList GetModuleSpecifications(const lldb_private::FileSpec &file, lldb::DataExtractorSP &extractor_sp, lldb::offset_t file_offset, lldb::offset_t length)
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.
An architecture specification class.
Definition ArchSpec.h:32
An data extractor class.
A file utility class.
Definition FileSpec.h:57
A plug-in interface definition class for object containers.
uint64_t offset_t
Definition lldb-types.h:85
std::shared_ptr< lldb_private::ObjectFile > ObjectFileSP
std::shared_ptr< lldb_private::DataBuffer > DataBufferSP
std::shared_ptr< lldb_private::DataExtractor > DataExtractorSP
std::shared_ptr< lldb_private::Module > ModuleSP
const union ObjectContainerUniversalMachO::FatArch::Arch m_arch