blob: 0316ec681355e277aeaca93404cea71f10b32018 [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
Greg Claytone1a916a2010-07-21 22:12:05 +000013#include "llvm/Support/MachO.h"
14
Jim Ingham672e6f52011-03-07 23:44:08 +000015#include "lldb/Core/Address.h"
Greg Claytonc3776bf2012-02-09 06:16:32 +000016#include "lldb/Core/RangeMap.h"
Greg Clayton53239f02011-02-08 05:05:52 +000017#include "lldb/Host/FileSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000018#include "lldb/Host/Mutex.h"
19#include "lldb/Symbol/ObjectFile.h"
20
21//----------------------------------------------------------------------
22// This class needs to be hidden as eventually belongs in a plugin that
23// will export the ObjectFile protocol
24//----------------------------------------------------------------------
25class ObjectFileMachO :
26 public lldb_private::ObjectFile
27{
28public:
29 //------------------------------------------------------------------
30 // Static Functions
31 //------------------------------------------------------------------
32 static void
33 Initialize();
34
35 static void
36 Terminate();
37
Greg Clayton57abc5d2013-05-10 21:47:16 +000038 static lldb_private::ConstString
Chris Lattner30fdc8d2010-06-08 16:52:24 +000039 GetPluginNameStatic();
40
41 static const char *
42 GetPluginDescriptionStatic();
43
Greg Claytonc9660542012-02-05 02:38:54 +000044 static lldb_private::ObjectFile *
Greg Claytone72dfb32012-02-24 01:59:29 +000045 CreateInstance (const lldb::ModuleSP &module_sp,
Greg Clayton5ce9c562013-02-06 17:22:03 +000046 lldb::DataBufferSP& data_sp,
47 lldb::offset_t data_offset,
Chris Lattner30fdc8d2010-06-08 16:52:24 +000048 const lldb_private::FileSpec* file,
Greg Clayton5ce9c562013-02-06 17:22:03 +000049 lldb::offset_t file_offset,
50 lldb::offset_t length);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000051
Greg Claytonc9660542012-02-05 02:38:54 +000052 static lldb_private::ObjectFile *
Greg Claytone72dfb32012-02-24 01:59:29 +000053 CreateMemoryInstance (const lldb::ModuleSP &module_sp,
Greg Claytonc9660542012-02-05 02:38:54 +000054 lldb::DataBufferSP& data_sp,
55 const lldb::ProcessSP &process_sp,
56 lldb::addr_t header_addr);
57
Greg Claytonf4d6de62013-04-24 22:29:28 +000058 static size_t
59 GetModuleSpecifications (const lldb_private::FileSpec& file,
60 lldb::DataBufferSP& data_sp,
61 lldb::offset_t data_offset,
62 lldb::offset_t file_offset,
63 lldb::offset_t length,
64 lldb_private::ModuleSpecList &specs);
65
Chris Lattner30fdc8d2010-06-08 16:52:24 +000066 static bool
Greg Clayton5ce9c562013-02-06 17:22:03 +000067 MagicBytesMatch (lldb::DataBufferSP& data_sp,
Greg Clayton44435ed2012-01-12 05:25:17 +000068 lldb::addr_t offset,
69 lldb::addr_t length);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000070
71 //------------------------------------------------------------------
72 // Member Functions
73 //------------------------------------------------------------------
Greg Claytone72dfb32012-02-24 01:59:29 +000074 ObjectFileMachO (const lldb::ModuleSP &module_sp,
Greg Clayton5ce9c562013-02-06 17:22:03 +000075 lldb::DataBufferSP& data_sp,
76 lldb::offset_t data_offset,
Chris Lattner30fdc8d2010-06-08 16:52:24 +000077 const lldb_private::FileSpec* file,
Greg Clayton5ce9c562013-02-06 17:22:03 +000078 lldb::offset_t offset,
79 lldb::offset_t length);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000080
Greg Claytone72dfb32012-02-24 01:59:29 +000081 ObjectFileMachO (const lldb::ModuleSP &module_sp,
Greg Clayton5ce9c562013-02-06 17:22:03 +000082 lldb::DataBufferSP& data_sp,
Greg Claytonc9660542012-02-05 02:38:54 +000083 const lldb::ProcessSP &process_sp,
84 lldb::addr_t header_addr);
85
Chris Lattner30fdc8d2010-06-08 16:52:24 +000086 virtual
87 ~ObjectFileMachO();
88
89 virtual bool
90 ParseHeader ();
91
92 virtual lldb::ByteOrder
93 GetByteOrder () const;
Jim Ingham5aee1622010-08-09 23:31:02 +000094
95 virtual bool
96 IsExecutable () const;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000097
Greg Claytonc7bece562013-01-25 18:06:21 +000098 virtual uint32_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +000099 GetAddressByteSize () const;
100
Greg Claytonc8e0c242012-04-13 00:07:34 +0000101 virtual lldb::AddressClass
Greg Claytonded470d2011-03-19 01:12:21 +0000102 GetAddressClass (lldb::addr_t file_addr);
103
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000104 virtual lldb_private::Symtab *
Greg Clayton3046e662013-07-10 01:23:25 +0000105 GetSymtab();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000106
Greg Clayton3046e662013-07-10 01:23:25 +0000107 virtual bool
108 IsStripped ();
109
110 virtual void
111 CreateSections (lldb_private::SectionList &unified_section_list);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000112
113 virtual void
114 Dump (lldb_private::Stream *s);
115
116 virtual bool
Greg Clayton514487e2011-02-15 21:59:32 +0000117 GetArchitecture (lldb_private::ArchSpec &arch);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000118
119 virtual bool
120 GetUUID (lldb_private::UUID* uuid);
121
122 virtual uint32_t
123 GetDependentModules (lldb_private::FileSpecList& files);
124
125 //------------------------------------------------------------------
126 // PluginInterface protocol
127 //------------------------------------------------------------------
Greg Clayton57abc5d2013-05-10 21:47:16 +0000128 virtual lldb_private::ConstString
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000129 GetPluginName();
130
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000131 virtual uint32_t
132 GetPluginVersion();
133
Jim Ingham672e6f52011-03-07 23:44:08 +0000134 virtual lldb_private::Address
135 GetEntryPointAddress ();
Greg Claytonc9660542012-02-05 02:38:54 +0000136
137 virtual lldb_private::Address
138 GetHeaderAddress ();
139
Greg Claytonc3776bf2012-02-09 06:16:32 +0000140 virtual uint32_t
141 GetNumThreadContexts ();
142
143 virtual lldb::RegisterContextSP
144 GetThreadContextAtIndex (uint32_t idx, lldb_private::Thread &thread);
145
Greg Clayton9e00b6a652011-07-09 00:41:34 +0000146 virtual ObjectFile::Type
147 CalculateType();
148
149 virtual ObjectFile::Strata
150 CalculateStrata();
151
Greg Claytonc2ff9312012-02-22 19:41:02 +0000152 virtual uint32_t
153 GetVersion (uint32_t *versions, uint32_t num_versions);
154
Greg Clayton9b234982013-10-24 22:54:08 +0000155 virtual uint32_t
156 GetMinimumOSVersion (uint32_t *versions, uint32_t num_versions);
157
158 virtual uint32_t
159 GetSDKVersion (uint32_t *versions, uint32_t num_versions);
160
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000161protected:
Jason Molenda0e0954c2013-04-16 06:24:42 +0000162
Greg Claytonf4d6de62013-04-24 22:29:28 +0000163 static bool
164 ParseHeader (lldb_private::DataExtractor &data,
165 lldb::offset_t *data_offset_ptr,
166 llvm::MachO::mach_header &header);
167
168
169 static bool
170 GetUUID (const llvm::MachO::mach_header &header,
171 const lldb_private::DataExtractor &data,
172 lldb::offset_t lc_offset, // Offset to the first load command
173 lldb_private::UUID& uuid);
174
175 // Intended for same-host arm device debugging where lldb needs to
Jason Molenda0e0954c2013-04-16 06:24:42 +0000176 // detect libraries in the shared cache and augment the nlist entries
177 // with an on-disk dyld_shared_cache file. The process will record
178 // the shared cache UUID so the on-disk cache can be matched or rejected
179 // correctly.
180 lldb_private::UUID
181 GetProcessSharedCacheUUID (lldb_private::Process *);
182
183 // Intended for same-host arm device debugging where lldb will read
184 // shared cache libraries out of its own memory instead of the remote
185 // process' memory as an optimization. If lldb's shared cache UUID
186 // does not match the process' shared cache UUID, this optimization
187 // should not be used.
188 lldb_private::UUID
189 GetLLDBSharedCacheUUID ();
190
Greg Claytone1a916a2010-07-21 22:12:05 +0000191 llvm::MachO::mach_header m_header;
Greg Claytonc9660542012-02-05 02:38:54 +0000192 static const lldb_private::ConstString &GetSegmentNameTEXT();
193 static const lldb_private::ConstString &GetSegmentNameDATA();
194 static const lldb_private::ConstString &GetSegmentNameOBJC();
195 static const lldb_private::ConstString &GetSegmentNameLINKEDIT();
196 static const lldb_private::ConstString &GetSectionNameEHFrame();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000197
Greg Claytone1a916a2010-07-21 22:12:05 +0000198 llvm::MachO::dysymtab_command m_dysymtab;
199 std::vector<llvm::MachO::segment_command_64> m_mach_segments;
200 std::vector<llvm::MachO::section_64> m_mach_sections;
Greg Clayton9b234982013-10-24 22:54:08 +0000201 std::vector<uint32_t> m_min_os_versions;
202 std::vector<uint32_t> m_sdk_versions;
Greg Clayton9422dd62013-03-04 21:46:16 +0000203 typedef lldb_private::RangeVector<uint32_t, uint32_t> FileRangeArray;
Jim Ingham672e6f52011-03-07 23:44:08 +0000204 lldb_private::Address m_entry_point_address;
Greg Claytonc3776bf2012-02-09 06:16:32 +0000205 FileRangeArray m_thread_context_offsets;
206 bool m_thread_context_offsets_valid;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000207
208 size_t
Greg Clayton3046e662013-07-10 01:23:25 +0000209 ParseSymtab ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000210
211};
212
213#endif // liblldb_ObjectFileMachO_h_