blob: eb8c7073dac1623f002c9210871dae5247debd24 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- 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
Jim Ingham46d005d2014-04-02 22:53:21 +000013#include "lldb/Utility/SafeMachO.h"
Greg Claytone1a916a2010-07-21 22:12:05 +000014
Jim Ingham672e6f52011-03-07 23:44:08 +000015#include "lldb/Core/Address.h"
Jim Inghamfbe0b9a2014-05-21 03:58:03 +000016#include "lldb/Core/FileSpecList.h"
Greg Claytonc3776bf2012-02-09 06:16:32 +000017#include "lldb/Core/RangeMap.h"
Greg Clayton53239f02011-02-08 05:05:52 +000018#include "lldb/Host/FileSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000019#include "lldb/Host/Mutex.h"
20#include "lldb/Symbol/ObjectFile.h"
21
22//----------------------------------------------------------------------
23// This class needs to be hidden as eventually belongs in a plugin that
24// will export the ObjectFile protocol
25//----------------------------------------------------------------------
26class ObjectFileMachO :
27 public lldb_private::ObjectFile
28{
29public:
30 //------------------------------------------------------------------
31 // Static Functions
32 //------------------------------------------------------------------
33 static void
34 Initialize();
35
36 static void
37 Terminate();
38
Greg Clayton57abc5d2013-05-10 21:47:16 +000039 static lldb_private::ConstString
Chris Lattner30fdc8d2010-06-08 16:52:24 +000040 GetPluginNameStatic();
41
42 static const char *
43 GetPluginDescriptionStatic();
44
Greg Claytonc9660542012-02-05 02:38:54 +000045 static lldb_private::ObjectFile *
Greg Claytone72dfb32012-02-24 01:59:29 +000046 CreateInstance (const lldb::ModuleSP &module_sp,
Greg Clayton5ce9c562013-02-06 17:22:03 +000047 lldb::DataBufferSP& data_sp,
48 lldb::offset_t data_offset,
Chris Lattner30fdc8d2010-06-08 16:52:24 +000049 const lldb_private::FileSpec* file,
Greg Clayton5ce9c562013-02-06 17:22:03 +000050 lldb::offset_t file_offset,
51 lldb::offset_t length);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000052
Greg Claytonc9660542012-02-05 02:38:54 +000053 static lldb_private::ObjectFile *
Greg Claytone72dfb32012-02-24 01:59:29 +000054 CreateMemoryInstance (const lldb::ModuleSP &module_sp,
Greg Claytonc9660542012-02-05 02:38:54 +000055 lldb::DataBufferSP& data_sp,
56 const lldb::ProcessSP &process_sp,
57 lldb::addr_t header_addr);
58
Greg Claytonf4d6de62013-04-24 22:29:28 +000059 static size_t
60 GetModuleSpecifications (const lldb_private::FileSpec& file,
61 lldb::DataBufferSP& data_sp,
62 lldb::offset_t data_offset,
63 lldb::offset_t file_offset,
64 lldb::offset_t length,
65 lldb_private::ModuleSpecList &specs);
66
Chris Lattner30fdc8d2010-06-08 16:52:24 +000067 static bool
Greg Claytona2715cf2014-06-13 00:54:12 +000068 SaveCore (const lldb::ProcessSP &process_sp,
69 const lldb_private::FileSpec &outfile,
70 lldb_private::Error &error);
71
72 static bool
Greg Clayton5ce9c562013-02-06 17:22:03 +000073 MagicBytesMatch (lldb::DataBufferSP& data_sp,
Greg Clayton44435ed2012-01-12 05:25:17 +000074 lldb::addr_t offset,
75 lldb::addr_t length);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000076
77 //------------------------------------------------------------------
78 // Member Functions
79 //------------------------------------------------------------------
Greg Claytone72dfb32012-02-24 01:59:29 +000080 ObjectFileMachO (const lldb::ModuleSP &module_sp,
Greg Clayton5ce9c562013-02-06 17:22:03 +000081 lldb::DataBufferSP& data_sp,
82 lldb::offset_t data_offset,
Chris Lattner30fdc8d2010-06-08 16:52:24 +000083 const lldb_private::FileSpec* file,
Greg Clayton5ce9c562013-02-06 17:22:03 +000084 lldb::offset_t offset,
85 lldb::offset_t length);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000086
Greg Claytone72dfb32012-02-24 01:59:29 +000087 ObjectFileMachO (const lldb::ModuleSP &module_sp,
Greg Clayton5ce9c562013-02-06 17:22:03 +000088 lldb::DataBufferSP& data_sp,
Greg Claytonc9660542012-02-05 02:38:54 +000089 const lldb::ProcessSP &process_sp,
90 lldb::addr_t header_addr);
91
Chris Lattner30fdc8d2010-06-08 16:52:24 +000092 virtual
93 ~ObjectFileMachO();
94
95 virtual bool
96 ParseHeader ();
97
Greg Clayton7524e092014-02-06 20:10:16 +000098 virtual bool
Greg Clayton751caf62014-02-07 22:54:47 +000099 SetLoadAddress(lldb_private::Target &target,
100 lldb::addr_t value,
101 bool value_is_offset);
Greg Clayton7524e092014-02-06 20:10:16 +0000102
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000103 virtual lldb::ByteOrder
104 GetByteOrder () const;
Jim Ingham5aee1622010-08-09 23:31:02 +0000105
106 virtual bool
107 IsExecutable () const;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000108
Greg Claytonc7bece562013-01-25 18:06:21 +0000109 virtual uint32_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000110 GetAddressByteSize () const;
111
Greg Claytonc8e0c242012-04-13 00:07:34 +0000112 virtual lldb::AddressClass
Greg Claytonded470d2011-03-19 01:12:21 +0000113 GetAddressClass (lldb::addr_t file_addr);
114
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000115 virtual lldb_private::Symtab *
Greg Clayton3046e662013-07-10 01:23:25 +0000116 GetSymtab();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000117
Greg Clayton3046e662013-07-10 01:23:25 +0000118 virtual bool
119 IsStripped ();
120
121 virtual void
122 CreateSections (lldb_private::SectionList &unified_section_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000123
124 virtual void
125 Dump (lldb_private::Stream *s);
126
127 virtual bool
Greg Clayton514487e2011-02-15 21:59:32 +0000128 GetArchitecture (lldb_private::ArchSpec &arch);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000129
130 virtual bool
131 GetUUID (lldb_private::UUID* uuid);
132
133 virtual uint32_t
134 GetDependentModules (lldb_private::FileSpecList& files);
135
Jim Inghamfbe0b9a2014-05-21 03:58:03 +0000136 virtual lldb_private::FileSpecList
137 GetReExportedLibraries ()
138 {
139 return m_reexported_dylibs;
140 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000141 //------------------------------------------------------------------
142 // PluginInterface protocol
143 //------------------------------------------------------------------
Greg Clayton57abc5d2013-05-10 21:47:16 +0000144 virtual lldb_private::ConstString
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000145 GetPluginName();
146
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000147 virtual uint32_t
148 GetPluginVersion();
149
Jim Ingham672e6f52011-03-07 23:44:08 +0000150 virtual lldb_private::Address
151 GetEntryPointAddress ();
Greg Claytonc9660542012-02-05 02:38:54 +0000152
153 virtual lldb_private::Address
154 GetHeaderAddress ();
155
Greg Claytonc3776bf2012-02-09 06:16:32 +0000156 virtual uint32_t
157 GetNumThreadContexts ();
158
159 virtual lldb::RegisterContextSP
160 GetThreadContextAtIndex (uint32_t idx, lldb_private::Thread &thread);
161
Greg Clayton9e00b6a652011-07-09 00:41:34 +0000162 virtual ObjectFile::Type
163 CalculateType();
164
165 virtual ObjectFile::Strata
166 CalculateStrata();
167
Greg Claytonc2ff9312012-02-22 19:41:02 +0000168 virtual uint32_t
169 GetVersion (uint32_t *versions, uint32_t num_versions);
170
Greg Clayton9b234982013-10-24 22:54:08 +0000171 virtual uint32_t
172 GetMinimumOSVersion (uint32_t *versions, uint32_t num_versions);
173
174 virtual uint32_t
175 GetSDKVersion (uint32_t *versions, uint32_t num_versions);
Greg Clayton08928f32015-02-05 02:01:34 +0000176
177 virtual bool
178 GetIsDynamicLinkEditor();
179
Greg Claytonf4d6de62013-04-24 22:29:28 +0000180 static bool
181 ParseHeader (lldb_private::DataExtractor &data,
182 lldb::offset_t *data_offset_ptr,
183 llvm::MachO::mach_header &header);
184
Greg Clayton9cbd3c62014-03-07 19:24:39 +0000185protected:
Greg Claytonf4d6de62013-04-24 22:29:28 +0000186
187 static bool
188 GetUUID (const llvm::MachO::mach_header &header,
189 const lldb_private::DataExtractor &data,
190 lldb::offset_t lc_offset, // Offset to the first load command
191 lldb_private::UUID& uuid);
192
Greg Clayton7ab7f892014-05-29 21:33:45 +0000193 static bool
194 GetArchitecture (const llvm::MachO::mach_header &header,
195 const lldb_private::DataExtractor &data,
196 lldb::offset_t lc_offset,
197 lldb_private::ArchSpec &arch);
198
Greg Claytonf4d6de62013-04-24 22:29:28 +0000199 // Intended for same-host arm device debugging where lldb needs to
Jason Molenda0e0954c2013-04-16 06:24:42 +0000200 // detect libraries in the shared cache and augment the nlist entries
201 // with an on-disk dyld_shared_cache file. The process will record
202 // the shared cache UUID so the on-disk cache can be matched or rejected
203 // correctly.
204 lldb_private::UUID
205 GetProcessSharedCacheUUID (lldb_private::Process *);
206
207 // Intended for same-host arm device debugging where lldb will read
208 // shared cache libraries out of its own memory instead of the remote
209 // process' memory as an optimization. If lldb's shared cache UUID
210 // does not match the process' shared cache UUID, this optimization
211 // should not be used.
212 lldb_private::UUID
213 GetLLDBSharedCacheUUID ();
214
Greg Clayton07347372015-06-08 21:53:11 +0000215 lldb_private::Section *
216 GetMachHeaderSection();
217
218 lldb::addr_t
219 CalculateSectionLoadAddressForMemoryImage(lldb::addr_t mach_header_load_address,
220 const lldb_private::Section *mach_header_section,
221 const lldb_private::Section *section);
222
Greg Claytone1a916a2010-07-21 22:12:05 +0000223 llvm::MachO::mach_header m_header;
Greg Claytonc9660542012-02-05 02:38:54 +0000224 static const lldb_private::ConstString &GetSegmentNameTEXT();
225 static const lldb_private::ConstString &GetSegmentNameDATA();
226 static const lldb_private::ConstString &GetSegmentNameOBJC();
227 static const lldb_private::ConstString &GetSegmentNameLINKEDIT();
228 static const lldb_private::ConstString &GetSectionNameEHFrame();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000229
Greg Claytone1a916a2010-07-21 22:12:05 +0000230 llvm::MachO::dysymtab_command m_dysymtab;
231 std::vector<llvm::MachO::segment_command_64> m_mach_segments;
232 std::vector<llvm::MachO::section_64> m_mach_sections;
Greg Clayton9b234982013-10-24 22:54:08 +0000233 std::vector<uint32_t> m_min_os_versions;
234 std::vector<uint32_t> m_sdk_versions;
Greg Clayton9422dd62013-03-04 21:46:16 +0000235 typedef lldb_private::RangeVector<uint32_t, uint32_t> FileRangeArray;
Jim Ingham672e6f52011-03-07 23:44:08 +0000236 lldb_private::Address m_entry_point_address;
Greg Claytonc3776bf2012-02-09 06:16:32 +0000237 FileRangeArray m_thread_context_offsets;
238 bool m_thread_context_offsets_valid;
Jim Inghamfbe0b9a2014-05-21 03:58:03 +0000239 lldb_private::FileSpecList m_reexported_dylibs;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000240
241 size_t
Greg Clayton3046e662013-07-10 01:23:25 +0000242 ParseSymtab ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000243
244};
245
246#endif // liblldb_ObjectFileMachO_h_