blob: 4ffc7df79614399cfb65ac63c26bae4f96659300 [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
38 static const char *
39 GetPluginNameStatic();
40
41 static const char *
42 GetPluginDescriptionStatic();
43
Greg Claytonc9660542012-02-05 02:38:54 +000044 static lldb_private::ObjectFile *
Chris Lattner30fdc8d2010-06-08 16:52:24 +000045 CreateInstance (lldb_private::Module* module,
46 lldb::DataBufferSP& dataSP,
47 const lldb_private::FileSpec* file,
48 lldb::addr_t offset,
49 lldb::addr_t length);
50
Greg Claytonc9660542012-02-05 02:38:54 +000051 static lldb_private::ObjectFile *
52 CreateMemoryInstance (lldb_private::Module* module,
53 lldb::DataBufferSP& data_sp,
54 const lldb::ProcessSP &process_sp,
55 lldb::addr_t header_addr);
56
Chris Lattner30fdc8d2010-06-08 16:52:24 +000057 static bool
Greg Clayton44435ed2012-01-12 05:25:17 +000058 MagicBytesMatch (lldb::DataBufferSP& dataSP,
59 lldb::addr_t offset,
60 lldb::addr_t length);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000061
62 //------------------------------------------------------------------
63 // Member Functions
64 //------------------------------------------------------------------
65 ObjectFileMachO (lldb_private::Module* module,
66 lldb::DataBufferSP& dataSP,
67 const lldb_private::FileSpec* file,
68 lldb::addr_t offset,
69 lldb::addr_t length);
70
Greg Claytonc9660542012-02-05 02:38:54 +000071 ObjectFileMachO (lldb_private::Module* module,
72 lldb::DataBufferSP& dataSP,
73 const lldb::ProcessSP &process_sp,
74 lldb::addr_t header_addr);
75
Chris Lattner30fdc8d2010-06-08 16:52:24 +000076 virtual
77 ~ObjectFileMachO();
78
79 virtual bool
80 ParseHeader ();
81
82 virtual lldb::ByteOrder
83 GetByteOrder () const;
Jim Ingham5aee1622010-08-09 23:31:02 +000084
85 virtual bool
86 IsExecutable () const;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000087
88 virtual size_t
89 GetAddressByteSize () const;
90
Greg Claytone0d378b2011-03-24 21:19:54 +000091 virtual lldb_private::AddressClass
Greg Claytonded470d2011-03-19 01:12:21 +000092 GetAddressClass (lldb::addr_t file_addr);
93
Chris Lattner30fdc8d2010-06-08 16:52:24 +000094 virtual lldb_private::Symtab *
95 GetSymtab();
96
97 virtual lldb_private::SectionList *
98 GetSectionList();
99
100 virtual void
101 Dump (lldb_private::Stream *s);
102
103 virtual bool
Greg Clayton514487e2011-02-15 21:59:32 +0000104 GetArchitecture (lldb_private::ArchSpec &arch);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000105
106 virtual bool
107 GetUUID (lldb_private::UUID* uuid);
108
109 virtual uint32_t
110 GetDependentModules (lldb_private::FileSpecList& files);
111
112 //------------------------------------------------------------------
113 // PluginInterface protocol
114 //------------------------------------------------------------------
115 virtual const char *
116 GetPluginName();
117
118 virtual const char *
119 GetShortPluginName();
120
121 virtual uint32_t
122 GetPluginVersion();
123
Jim Ingham672e6f52011-03-07 23:44:08 +0000124 virtual lldb_private::Address
125 GetEntryPointAddress ();
Greg Claytonc9660542012-02-05 02:38:54 +0000126
127 virtual lldb_private::Address
128 GetHeaderAddress ();
129
Greg Claytonc3776bf2012-02-09 06:16:32 +0000130 virtual uint32_t
131 GetNumThreadContexts ();
132
133 virtual lldb::RegisterContextSP
134 GetThreadContextAtIndex (uint32_t idx, lldb_private::Thread &thread);
135
Greg Clayton9e00b6a652011-07-09 00:41:34 +0000136 virtual ObjectFile::Type
137 CalculateType();
138
139 virtual ObjectFile::Strata
140 CalculateStrata();
141
Greg Claytonc2ff9312012-02-22 19:41:02 +0000142 virtual uint32_t
143 GetVersion (uint32_t *versions, uint32_t num_versions);
144
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000145protected:
146 mutable lldb_private::Mutex m_mutex;
Greg Claytone1a916a2010-07-21 22:12:05 +0000147 llvm::MachO::mach_header m_header;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000148 mutable std::auto_ptr<lldb_private::SectionList> m_sections_ap;
149 mutable std::auto_ptr<lldb_private::Symtab> m_symtab_ap;
Greg Claytonc9660542012-02-05 02:38:54 +0000150 static const lldb_private::ConstString &GetSegmentNameTEXT();
151 static const lldb_private::ConstString &GetSegmentNameDATA();
152 static const lldb_private::ConstString &GetSegmentNameOBJC();
153 static const lldb_private::ConstString &GetSegmentNameLINKEDIT();
154 static const lldb_private::ConstString &GetSectionNameEHFrame();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000155
Greg Claytone1a916a2010-07-21 22:12:05 +0000156 llvm::MachO::dysymtab_command m_dysymtab;
157 std::vector<llvm::MachO::segment_command_64> m_mach_segments;
158 std::vector<llvm::MachO::section_64> m_mach_sections;
Greg Claytonc3776bf2012-02-09 06:16:32 +0000159 typedef lldb_private::RangeArray<uint32_t, uint32_t, 1> FileRangeArray;
Jim Ingham672e6f52011-03-07 23:44:08 +0000160 lldb_private::Address m_entry_point_address;
Greg Claytonc3776bf2012-02-09 06:16:32 +0000161 FileRangeArray m_thread_context_offsets;
162 bool m_thread_context_offsets_valid;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000163
164 size_t
165 ParseSections ();
166
167 size_t
168 ParseSymtab (bool minimize);
169
170};
171
172#endif // liblldb_ObjectFileMachO_h_