]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h
Vendor import of lldb trunk r338150:
[FreeBSD/FreeBSD.git] / source / Plugins / ObjectFile / Mach-O / ObjectFileMachO.h
1 //===-- ObjectFileMachO.h ---------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef liblldb_ObjectFileMachO_h_
11 #define liblldb_ObjectFileMachO_h_
12
13 // C Includes
14 // C++ Includes
15 // Other libraries and framework includes
16 // Project includes
17 #include "lldb/Core/Address.h"
18 #include "lldb/Core/FileSpecList.h"
19 #include "lldb/Core/RangeMap.h"
20 #include "lldb/Symbol/ObjectFile.h"
21 #include "lldb/Utility/FileSpec.h"
22 #include "lldb/Utility/SafeMachO.h"
23 #include "lldb/Utility/UUID.h"
24
25 //----------------------------------------------------------------------
26 // This class needs to be hidden as eventually belongs in a plugin that
27 // will export the ObjectFile protocol
28 //----------------------------------------------------------------------
29 class ObjectFileMachO : public lldb_private::ObjectFile {
30 public:
31   ObjectFileMachO(const lldb::ModuleSP &module_sp, lldb::DataBufferSP &data_sp,
32                   lldb::offset_t data_offset,
33                   const lldb_private::FileSpec *file, lldb::offset_t offset,
34                   lldb::offset_t length);
35
36   ObjectFileMachO(const lldb::ModuleSP &module_sp, lldb::DataBufferSP &data_sp,
37                   const lldb::ProcessSP &process_sp, lldb::addr_t header_addr);
38
39   ~ObjectFileMachO() override = default;
40
41   //------------------------------------------------------------------
42   // Static Functions
43   //------------------------------------------------------------------
44   static void Initialize();
45
46   static void Terminate();
47
48   static lldb_private::ConstString GetPluginNameStatic();
49
50   static const char *GetPluginDescriptionStatic();
51
52   static lldb_private::ObjectFile *
53   CreateInstance(const lldb::ModuleSP &module_sp, lldb::DataBufferSP &data_sp,
54                  lldb::offset_t data_offset, const lldb_private::FileSpec *file,
55                  lldb::offset_t file_offset, lldb::offset_t length);
56
57   static lldb_private::ObjectFile *CreateMemoryInstance(
58       const lldb::ModuleSP &module_sp, lldb::DataBufferSP &data_sp,
59       const lldb::ProcessSP &process_sp, lldb::addr_t header_addr);
60
61   static size_t GetModuleSpecifications(const lldb_private::FileSpec &file,
62                                         lldb::DataBufferSP &data_sp,
63                                         lldb::offset_t data_offset,
64                                         lldb::offset_t file_offset,
65                                         lldb::offset_t length,
66                                         lldb_private::ModuleSpecList &specs);
67
68   static bool SaveCore(const lldb::ProcessSP &process_sp,
69                        const lldb_private::FileSpec &outfile,
70                        lldb_private::Status &error);
71
72   static bool MagicBytesMatch(lldb::DataBufferSP &data_sp, lldb::addr_t offset,
73                               lldb::addr_t length);
74
75   //------------------------------------------------------------------
76   // Member Functions
77   //------------------------------------------------------------------
78   bool ParseHeader() override;
79
80   bool SetLoadAddress(lldb_private::Target &target, lldb::addr_t value,
81                       bool value_is_offset) override;
82
83   lldb::ByteOrder GetByteOrder() const override;
84
85   bool IsExecutable() const override;
86
87   uint32_t GetAddressByteSize() const override;
88
89   lldb_private::AddressClass GetAddressClass(lldb::addr_t file_addr) override;
90
91   lldb_private::Symtab *GetSymtab() override;
92
93   bool IsStripped() override;
94
95   void CreateSections(lldb_private::SectionList &unified_section_list) override;
96
97   void Dump(lldb_private::Stream *s) override;
98
99   bool GetArchitecture(lldb_private::ArchSpec &arch) override;
100
101   bool GetUUID(lldb_private::UUID *uuid) override;
102
103   uint32_t GetDependentModules(lldb_private::FileSpecList &files) override;
104
105   lldb_private::FileSpecList GetReExportedLibraries() override {
106     return m_reexported_dylibs;
107   }
108
109   lldb_private::Address GetEntryPointAddress() override;
110
111   lldb_private::Address GetHeaderAddress() override;
112
113   uint32_t GetNumThreadContexts() override;
114
115   std::string GetIdentifierString() override;
116
117   bool GetCorefileMainBinaryInfo (lldb::addr_t &address, lldb_private::UUID &uuid) override;
118
119   lldb::RegisterContextSP
120   GetThreadContextAtIndex(uint32_t idx, lldb_private::Thread &thread) override;
121
122   ObjectFile::Type CalculateType() override;
123
124   ObjectFile::Strata CalculateStrata() override;
125
126   llvm::VersionTuple GetVersion() override;
127
128   llvm::VersionTuple GetMinimumOSVersion() override;
129
130   uint32_t GetSDKVersion(uint32_t *versions, uint32_t num_versions) override;
131
132   bool GetIsDynamicLinkEditor() override;
133
134   static bool ParseHeader(lldb_private::DataExtractor &data,
135                           lldb::offset_t *data_offset_ptr,
136                           llvm::MachO::mach_header &header);
137
138   bool AllowAssemblyEmulationUnwindPlans() override;
139
140   //------------------------------------------------------------------
141   // PluginInterface protocol
142   //------------------------------------------------------------------
143   lldb_private::ConstString GetPluginName() override;
144
145   uint32_t GetPluginVersion() override;
146
147 protected:
148   static bool
149   GetUUID(const llvm::MachO::mach_header &header,
150           const lldb_private::DataExtractor &data,
151           lldb::offset_t lc_offset, // Offset to the first load command
152           lldb_private::UUID &uuid);
153
154   static bool GetArchitecture(const llvm::MachO::mach_header &header,
155                               const lldb_private::DataExtractor &data,
156                               lldb::offset_t lc_offset,
157                               lldb_private::ArchSpec &arch);
158
159   // Intended for same-host arm device debugging where lldb needs to
160   // detect libraries in the shared cache and augment the nlist entries
161   // with an on-disk dyld_shared_cache file.  The process will record
162   // the shared cache UUID so the on-disk cache can be matched or rejected
163   // correctly.
164   void GetProcessSharedCacheUUID(lldb_private::Process *, lldb::addr_t &base_addr, lldb_private::UUID &uuid);
165
166   // Intended for same-host arm device debugging where lldb will read
167   // shared cache libraries out of its own memory instead of the remote
168   // process' memory as an optimization.  If lldb's shared cache UUID
169   // does not match the process' shared cache UUID, this optimization
170   // should not be used.
171   void GetLLDBSharedCacheUUID(lldb::addr_t &base_addir, lldb_private::UUID &uuid);
172
173   lldb_private::Section *GetMachHeaderSection();
174
175   lldb::addr_t CalculateSectionLoadAddressForMemoryImage(
176       lldb::addr_t mach_header_load_address,
177       const lldb_private::Section *mach_header_section,
178       const lldb_private::Section *section);
179
180   lldb_private::UUID
181   GetSharedCacheUUID(lldb_private::FileSpec dyld_shared_cache,
182                      const lldb::ByteOrder byte_order,
183                      const uint32_t addr_byte_size);
184
185   size_t ParseSymtab();
186
187   typedef lldb_private::RangeArray<uint32_t, uint32_t, 8> EncryptedFileRanges;
188   EncryptedFileRanges GetEncryptedFileRanges();
189
190   struct SegmentParsingContext;
191   void ProcessDysymtabCommand(const llvm::MachO::load_command &load_cmd,
192                               lldb::offset_t offset);
193   void ProcessSegmentCommand(const llvm::MachO::load_command &load_cmd,
194                              lldb::offset_t offset, uint32_t cmd_idx,
195                              SegmentParsingContext &context);
196   void SanitizeSegmentCommand(llvm::MachO::segment_command_64 &seg_cmd,
197                               uint32_t cmd_idx);
198
199   llvm::MachO::mach_header m_header;
200   static const lldb_private::ConstString &GetSegmentNameTEXT();
201   static const lldb_private::ConstString &GetSegmentNameDATA();
202   static const lldb_private::ConstString &GetSegmentNameDATA_DIRTY();
203   static const lldb_private::ConstString &GetSegmentNameDATA_CONST();
204   static const lldb_private::ConstString &GetSegmentNameOBJC();
205   static const lldb_private::ConstString &GetSegmentNameLINKEDIT();
206   static const lldb_private::ConstString &GetSectionNameEHFrame();
207
208   llvm::MachO::dysymtab_command m_dysymtab;
209   std::vector<llvm::MachO::segment_command_64> m_mach_segments;
210   std::vector<llvm::MachO::section_64> m_mach_sections;
211   llvm::Optional<llvm::VersionTuple> m_min_os_version;
212   std::vector<uint32_t> m_sdk_versions;
213   typedef lldb_private::RangeVector<uint32_t, uint32_t> FileRangeArray;
214   lldb_private::Address m_entry_point_address;
215   FileRangeArray m_thread_context_offsets;
216   bool m_thread_context_offsets_valid;
217   lldb_private::FileSpecList m_reexported_dylibs;
218   bool m_allow_assembly_emulation_unwind_plans;
219 };
220
221 #endif // liblldb_ObjectFileMachO_h_