LLDB  mainline
Go to the documentation of this file.
1 //===-- ObjectFileMachO.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 //===----------------------------------------------------------------------===//
9 #ifndef liblldb_ObjectFileMachO_h_
10 #define liblldb_ObjectFileMachO_h_
12 #include "lldb/Core/Address.h"
13 #include "lldb/Core/FileSpecList.h"
14 #include "lldb/Host/SafeMachO.h"
15 #include "lldb/Symbol/ObjectFile.h"
16 #include "lldb/Utility/FileSpec.h"
17 #include "lldb/Utility/RangeMap.h"
18 #include "lldb/Utility/UUID.h"
20 // This class needs to be hidden as eventually belongs in a plugin that
21 // will export the ObjectFile protocol
23 public:
24  ObjectFileMachO(const lldb::ModuleSP &module_sp, lldb::DataBufferSP &data_sp,
25  lldb::offset_t data_offset,
26  const lldb_private::FileSpec *file, lldb::offset_t offset,
27  lldb::offset_t length);
29  ObjectFileMachO(const lldb::ModuleSP &module_sp, lldb::DataBufferSP &data_sp,
30  const lldb::ProcessSP &process_sp, lldb::addr_t header_addr);
32  ~ObjectFileMachO() override = default;
34  // Static Functions
35  static void Initialize();
37  static void Terminate();
41  static const char *GetPluginDescriptionStatic();
44  CreateInstance(const lldb::ModuleSP &module_sp, lldb::DataBufferSP &data_sp,
45  lldb::offset_t data_offset, const lldb_private::FileSpec *file,
46  lldb::offset_t file_offset, lldb::offset_t length);
49  const lldb::ModuleSP &module_sp, lldb::DataBufferSP &data_sp,
50  const lldb::ProcessSP &process_sp, lldb::addr_t header_addr);
52  static size_t GetModuleSpecifications(const lldb_private::FileSpec &file,
53  lldb::DataBufferSP &data_sp,
54  lldb::offset_t data_offset,
55  lldb::offset_t file_offset,
56  lldb::offset_t length,
59  static bool SaveCore(const lldb::ProcessSP &process_sp,
60  const lldb_private::FileSpec &outfile,
61  lldb_private::Status &error);
63  static bool MagicBytesMatch(lldb::DataBufferSP &data_sp, lldb::addr_t offset,
64  lldb::addr_t length);
66  // Member Functions
67  bool ParseHeader() override;
70  bool value_is_offset) override;
72  lldb::ByteOrder GetByteOrder() const override;
74  bool IsExecutable() const override;
76  uint32_t GetAddressByteSize() const override;
80  lldb_private::Symtab *GetSymtab() override;
82  bool IsStripped() override;
84  void CreateSections(lldb_private::SectionList &unified_section_list) override;
86  void Dump(lldb_private::Stream *s) override;
90  lldb_private::UUID GetUUID() override;
92  uint32_t GetDependentModules(lldb_private::FileSpecList &files) override;
94  lldb_private::FileSpecList GetReExportedLibraries() override {
95  return m_reexported_dylibs;
96  }
102  uint32_t GetNumThreadContexts() override;
104  std::string GetIdentifierString() override;
106  bool GetCorefileMainBinaryInfo (lldb::addr_t &address, lldb_private::UUID &uuid) override;
108  lldb::RegisterContextSP
111  ObjectFile::Type CalculateType() override;
113  ObjectFile::Strata CalculateStrata() override;
115  llvm::VersionTuple GetVersion() override;
117  llvm::VersionTuple GetMinimumOSVersion() override;
119  uint32_t GetSDKVersion(uint32_t *versions, uint32_t num_versions) override;
121  bool GetIsDynamicLinkEditor() override;
123  static bool ParseHeader(lldb_private::DataExtractor &data,
124  lldb::offset_t *data_offset_ptr,
125  llvm::MachO::mach_header &header);
127  bool AllowAssemblyEmulationUnwindPlans() override;
129  // PluginInterface protocol
132  uint32_t GetPluginVersion() override;
134 protected:
135  static lldb_private::UUID
136  GetUUID(const llvm::MachO::mach_header &header,
137  const lldb_private::DataExtractor &data,
138  lldb::offset_t lc_offset); // Offset to the first load command
141  GetArchitecture(const llvm::MachO::mach_header &header,
142  const lldb_private::DataExtractor &data,
143  lldb::offset_t lc_offset);
145  // Intended for same-host arm device debugging where lldb needs to
146  // detect libraries in the shared cache and augment the nlist entries
147  // with an on-disk dyld_shared_cache file. The process will record
148  // the shared cache UUID so the on-disk cache can be matched or rejected
149  // correctly.
152  // Intended for same-host arm device debugging where lldb will read
153  // shared cache libraries out of its own memory instead of the remote
154  // process' memory as an optimization. If lldb's shared cache UUID
155  // does not match the process' shared cache UUID, this optimization
156  // should not be used.
157  void GetLLDBSharedCacheUUID(lldb::addr_t &base_addir, lldb_private::UUID &uuid);
162  lldb::addr_t mach_header_load_address,
163  const lldb_private::Section *mach_header_section,
164  const lldb_private::Section *section);
167  GetSharedCacheUUID(lldb_private::FileSpec dyld_shared_cache,
168  const lldb::ByteOrder byte_order,
169  const uint32_t addr_byte_size);
171  size_t ParseSymtab();
174  EncryptedFileRanges GetEncryptedFileRanges();
176  struct SegmentParsingContext;
177  void ProcessDysymtabCommand(const llvm::MachO::load_command &load_cmd,
178  lldb::offset_t offset);
179  void ProcessSegmentCommand(const llvm::MachO::load_command &load_cmd,
180  lldb::offset_t offset, uint32_t cmd_idx,
181  SegmentParsingContext &context);
182  void SanitizeSegmentCommand(llvm::MachO::segment_command_64 &seg_cmd,
183  uint32_t cmd_idx);
185  bool SectionIsLoadable(const lldb_private::Section *section);
187  llvm::MachO::mach_header m_header;
197  llvm::MachO::dysymtab_command m_dysymtab;
198  std::vector<llvm::MachO::segment_command_64> m_mach_segments;
199  std::vector<llvm::MachO::section_64> m_mach_sections;
200  llvm::Optional<llvm::VersionTuple> m_min_os_version;
201  std::vector<uint32_t> m_sdk_versions;
204  FileRangeArray m_thread_context_offsets;
206  lldb_private::FileSpecList m_reexported_dylibs;
208 };
210 #endif // liblldb_ObjectFileMachO_h_
void GetProcessSharedCacheUUID(lldb_private::Process *, lldb::addr_t &base_addr, lldb_private::UUID &uuid)
lldb_private::Symtab * GetSymtab() override
Gets the symbol table for the currently selected architecture (and object for archives).
llvm::MachO::mach_header m_header
static void Terminate()
EncryptedFileRanges GetEncryptedFileRanges()
lldb_private::FileSpecList m_reexported_dylibs
An data extractor class.
Definition: DataExtractor.h:47
lldb_private::FileSpecList GetReExportedLibraries() override
Gets the file spec list of libraries re-exported by this object file.
uint32_t GetAddressByteSize() const override
Gets the address size in bytes for the current object file.
bool AllowAssemblyEmulationUnwindPlans() override
Returns if the function bounds for symbols in this symbol file are likely accurate.
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
static bool SaveCore(const lldb::ProcessSP &process_sp, const lldb_private::FileSpec &outfile, lldb_private::Status &error)
std::vector< uint32_t > m_sdk_versions
void Dump(lldb_private::Stream *s) override
Dump a description of this object to a Stream.
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 lldb_private::ConstString GetSectionNameEHFrame()
lldb_private::ArchSpec GetArchitecture() override
Get the ArchSpec for this object file.
lldb_private::AddressClass GetAddressClass(lldb::addr_t file_addr) override
Get the address type given a file address in an object file.
~ObjectFileMachO() override=default
lldb_private::RangeVector< uint32_t, uint32_t > FileRangeArray
A file utility class.
Definition: FileSpec.h:55
An architecture specification class.
Definition: ArchSpec.h:32
ObjectFile::Strata CalculateStrata() override
The object file should be able to calculate the strata of the object file.
A plug-in interface definition class for object file parsers.
Definition: ObjectFile.h:58
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)
FileRangeArray m_thread_context_offsets
bool GetCorefileMainBinaryInfo(lldb::addr_t &address, lldb_private::UUID &uuid) override
When the ObjectFile is a core file, lldb needs to locate the "binary" in the core file...
bool IsExecutable() const override
Tells whether this object file is capable of being the main executable for a process.
lldb_private::Section * GetMachHeaderSection()
bool IsStripped() override
Detect if this object file has been stripped of local symbols.
void CreateSections(lldb_private::SectionList &unified_section_list) override
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 SetLoadAddress(lldb_private::Target &target, lldb::addr_t value, bool value_is_offset) override
Sets the load address for an entire module, assuming a rigid slide of sections, if possible in the im...
std::vector< llvm::MachO::segment_command_64 > m_mach_segments
lldb_private::UUID GetSharedCacheUUID(lldb_private::FileSpec dyld_shared_cache, const lldb::ByteOrder byte_order, const uint32_t addr_byte_size)
void SanitizeSegmentCommand(llvm::MachO::segment_command_64 &seg_cmd, uint32_t cmd_idx)
static lldb_private::ConstString GetSegmentNameTEXT()
uint64_t offset_t
Definition: lldb-types.h:87
llvm::MachO::dysymtab_command m_dysymtab
static bool MagicBytesMatch(lldb::DataBufferSP &data_sp, lldb::addr_t offset, lldb::addr_t length)
lldb_private::Address GetEntryPointAddress() override
Returns the address of the Entry Point in this object file - if the object file doesn&#39;t have an entry...
lldb_private::Address m_entry_point_address
llvm::VersionTuple GetMinimumOSVersion() override
Get the minimum OS version this object file can run on.
void ProcessSegmentCommand(const llvm::MachO::load_command &load_cmd, lldb::offset_t offset, uint32_t cmd_idx, SegmentParsingContext &context)
A plug-in interface definition class for debugging a process.
Definition: Process.h:353
uint32_t GetDependentModules(lldb_private::FileSpecList &files) override
static lldb_private::ConstString GetSegmentNameLINKEDIT()
static lldb_private::ConstString GetSegmentNameDWARF()
lldb_private::ConstString GetPluginName() override
static lldb_private::ConstString GetSegmentNameDATA_DIRTY()
static lldb_private::ConstString GetSegmentNameDATA_CONST()
A section + offset based address class.
Definition: Address.h:80
ObjectFileMachO(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)
void ProcessDysymtabCommand(const llvm::MachO::load_command &load_cmd, lldb::offset_t offset)
lldb_private::UUID GetUUID() override
Gets the UUID for this object file.
void GetLLDBSharedCacheUUID(lldb::addr_t &base_addir, lldb_private::UUID &uuid)
static const char * GetPluginDescriptionStatic()
bool m_thread_context_offsets_valid
std::string GetIdentifierString() override
Some object files may have an identifier string embedded in them, e.g.
uint64_t addr_t
Definition: lldb-types.h:83
A uniqued constant string class.
Definition: ConstString.h:38
bool GetIsDynamicLinkEditor() override
Return true if this file is a dynamic link editor (dyld)
bool ParseHeader() override
Attempts to parse the object header.
uint32_t GetNumThreadContexts() override
lldb::RegisterContextSP GetThreadContextAtIndex(uint32_t idx, lldb_private::Thread &thread) override
static lldb_private::ConstString GetPluginNameStatic()
uint32_t GetPluginVersion() override
uint32_t GetSDKVersion(uint32_t *versions, uint32_t num_versions) override
Get the SDK OS version this object file was built with.
static lldb_private::ConstString GetSegmentNameDATA()
bool SectionIsLoadable(const lldb_private::Section *section)
bool m_allow_assembly_emulation_unwind_plans
lldb_private::Address GetBaseAddress() override
Returns base address of this object file.
static lldb_private::ConstString GetSegmentNameOBJC()
lldb::addr_t CalculateSectionLoadAddressForMemoryImage(lldb::addr_t mach_header_load_address, const lldb_private::Section *mach_header_section, const lldb_private::Section *section)
llvm::Optional< llvm::VersionTuple > m_min_os_version
lldb::ByteOrder GetByteOrder() const override
Gets whether endian swapping should occur when extracting data from this object file.
llvm::VersionTuple GetVersion() override
Get the object file version numbers.
static void Initialize()
lldb_private::RangeArray< uint32_t, uint32_t, 8 > EncryptedFileRanges
std::vector< llvm::MachO::section_64 > m_mach_sections
An error handling class.
Definition: Status.h:44
static lldb_private::ObjectFile * CreateMemoryInstance(const lldb::ModuleSP &module_sp, lldb::DataBufferSP &data_sp, const lldb::ProcessSP &process_sp, lldb::addr_t header_addr)