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 #include "lldb/Utility/SafeMachO.h" 14 15 #include "lldb/Core/Address.h" 16 #include "lldb/Core/FileSpecList.h" 17 #include "lldb/Core/RangeMap.h" 18 #include "lldb/Host/FileSpec.h" 19 #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 //---------------------------------------------------------------------- 26 class ObjectFileMachO : 27 public lldb_private::ObjectFile 28 { 29 public: 30 //------------------------------------------------------------------ 31 // Static Functions 32 //------------------------------------------------------------------ 33 static void 34 Initialize(); 35 36 static void 37 Terminate(); 38 39 static lldb_private::ConstString 40 GetPluginNameStatic(); 41 42 static const char * 43 GetPluginDescriptionStatic(); 44 45 static lldb_private::ObjectFile * 46 CreateInstance (const lldb::ModuleSP &module_sp, 47 lldb::DataBufferSP& data_sp, 48 lldb::offset_t data_offset, 49 const lldb_private::FileSpec* file, 50 lldb::offset_t file_offset, 51 lldb::offset_t length); 52 53 static lldb_private::ObjectFile * 54 CreateMemoryInstance (const lldb::ModuleSP &module_sp, 55 lldb::DataBufferSP& data_sp, 56 const lldb::ProcessSP &process_sp, 57 lldb::addr_t header_addr); 58 59 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 67 static bool 68 MagicBytesMatch (lldb::DataBufferSP& data_sp, 69 lldb::addr_t offset, 70 lldb::addr_t length); 71 72 //------------------------------------------------------------------ 73 // Member Functions 74 //------------------------------------------------------------------ 75 ObjectFileMachO (const lldb::ModuleSP &module_sp, 76 lldb::DataBufferSP& data_sp, 77 lldb::offset_t data_offset, 78 const lldb_private::FileSpec* file, 79 lldb::offset_t offset, 80 lldb::offset_t length); 81 82 ObjectFileMachO (const lldb::ModuleSP &module_sp, 83 lldb::DataBufferSP& data_sp, 84 const lldb::ProcessSP &process_sp, 85 lldb::addr_t header_addr); 86 87 virtual 88 ~ObjectFileMachO(); 89 90 virtual bool 91 ParseHeader (); 92 93 virtual bool 94 SetLoadAddress(lldb_private::Target &target, 95 lldb::addr_t value, 96 bool value_is_offset); 97 98 virtual lldb::ByteOrder 99 GetByteOrder () const; 100 101 virtual bool 102 IsExecutable () const; 103 104 virtual uint32_t 105 GetAddressByteSize () const; 106 107 virtual lldb::AddressClass 108 GetAddressClass (lldb::addr_t file_addr); 109 110 virtual lldb_private::Symtab * 111 GetSymtab(); 112 113 virtual bool 114 IsStripped (); 115 116 virtual void 117 CreateSections (lldb_private::SectionList &unified_section_list); 118 119 virtual void 120 Dump (lldb_private::Stream *s); 121 122 virtual bool 123 GetArchitecture (lldb_private::ArchSpec &arch); 124 125 virtual bool 126 GetUUID (lldb_private::UUID* uuid); 127 128 virtual uint32_t 129 GetDependentModules (lldb_private::FileSpecList& files); 130 131 virtual lldb_private::FileSpecList 132 GetReExportedLibraries () 133 { 134 return m_reexported_dylibs; 135 } 136 //------------------------------------------------------------------ 137 // PluginInterface protocol 138 //------------------------------------------------------------------ 139 virtual lldb_private::ConstString 140 GetPluginName(); 141 142 virtual uint32_t 143 GetPluginVersion(); 144 145 virtual lldb_private::Address 146 GetEntryPointAddress (); 147 148 virtual lldb_private::Address 149 GetHeaderAddress (); 150 151 virtual uint32_t 152 GetNumThreadContexts (); 153 154 virtual lldb::RegisterContextSP 155 GetThreadContextAtIndex (uint32_t idx, lldb_private::Thread &thread); 156 157 virtual ObjectFile::Type 158 CalculateType(); 159 160 virtual ObjectFile::Strata 161 CalculateStrata(); 162 163 virtual uint32_t 164 GetVersion (uint32_t *versions, uint32_t num_versions); 165 166 virtual uint32_t 167 GetMinimumOSVersion (uint32_t *versions, uint32_t num_versions); 168 169 virtual uint32_t 170 GetSDKVersion (uint32_t *versions, uint32_t num_versions); 171 172 static bool 173 ParseHeader (lldb_private::DataExtractor &data, 174 lldb::offset_t *data_offset_ptr, 175 llvm::MachO::mach_header &header); 176 177 protected: 178 179 static bool 180 GetUUID (const llvm::MachO::mach_header &header, 181 const lldb_private::DataExtractor &data, 182 lldb::offset_t lc_offset, // Offset to the first load command 183 lldb_private::UUID& uuid); 184 185 // Intended for same-host arm device debugging where lldb needs to 186 // detect libraries in the shared cache and augment the nlist entries 187 // with an on-disk dyld_shared_cache file. The process will record 188 // the shared cache UUID so the on-disk cache can be matched or rejected 189 // correctly. 190 lldb_private::UUID 191 GetProcessSharedCacheUUID (lldb_private::Process *); 192 193 // Intended for same-host arm device debugging where lldb will read 194 // shared cache libraries out of its own memory instead of the remote 195 // process' memory as an optimization. If lldb's shared cache UUID 196 // does not match the process' shared cache UUID, this optimization 197 // should not be used. 198 lldb_private::UUID 199 GetLLDBSharedCacheUUID (); 200 201 llvm::MachO::mach_header m_header; 202 static const lldb_private::ConstString &GetSegmentNameTEXT(); 203 static const lldb_private::ConstString &GetSegmentNameDATA(); 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 std::vector<uint32_t> m_min_os_versions; 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 219 size_t 220 ParseSymtab (); 221 222 }; 223 224 #endif // liblldb_ObjectFileMachO_h_ 225