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/Utility/SafeMachO.h" 18 #include "lldb/Core/Address.h" 19 #include "lldb/Core/FileSpecList.h" 20 #include "lldb/Core/RangeMap.h" 21 #include "lldb/Host/FileSpec.h" 22 #include "lldb/Host/Mutex.h" 23 #include "lldb/Symbol/ObjectFile.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 : 30 public lldb_private::ObjectFile 31 { 32 public: 33 ObjectFileMachO(const lldb::ModuleSP &module_sp, 34 lldb::DataBufferSP& data_sp, 35 lldb::offset_t data_offset, 36 const lldb_private::FileSpec* file, 37 lldb::offset_t offset, 38 lldb::offset_t length); 39 40 ObjectFileMachO(const lldb::ModuleSP &module_sp, 41 lldb::DataBufferSP& data_sp, 42 const lldb::ProcessSP &process_sp, 43 lldb::addr_t header_addr); 44 45 ~ObjectFileMachO() override = default; 46 47 //------------------------------------------------------------------ 48 // Static Functions 49 //------------------------------------------------------------------ 50 static void 51 Initialize(); 52 53 static void 54 Terminate(); 55 56 static lldb_private::ConstString 57 GetPluginNameStatic(); 58 59 static const char * 60 GetPluginDescriptionStatic(); 61 62 static lldb_private::ObjectFile * 63 CreateInstance (const lldb::ModuleSP &module_sp, 64 lldb::DataBufferSP& data_sp, 65 lldb::offset_t data_offset, 66 const lldb_private::FileSpec* file, 67 lldb::offset_t file_offset, 68 lldb::offset_t length); 69 70 static lldb_private::ObjectFile * 71 CreateMemoryInstance (const lldb::ModuleSP &module_sp, 72 lldb::DataBufferSP& data_sp, 73 const lldb::ProcessSP &process_sp, 74 lldb::addr_t header_addr); 75 76 static size_t 77 GetModuleSpecifications (const lldb_private::FileSpec& file, 78 lldb::DataBufferSP& data_sp, 79 lldb::offset_t data_offset, 80 lldb::offset_t file_offset, 81 lldb::offset_t length, 82 lldb_private::ModuleSpecList &specs); 83 84 static bool 85 SaveCore (const lldb::ProcessSP &process_sp, 86 const lldb_private::FileSpec &outfile, 87 lldb_private::Error &error); 88 89 static bool 90 MagicBytesMatch (lldb::DataBufferSP& data_sp, 91 lldb::addr_t offset, 92 lldb::addr_t length); 93 94 //------------------------------------------------------------------ 95 // Member Functions 96 //------------------------------------------------------------------ 97 bool 98 ParseHeader() override; 99 100 bool 101 SetLoadAddress(lldb_private::Target &target, 102 lldb::addr_t value, 103 bool value_is_offset) override; 104 105 lldb::ByteOrder 106 GetByteOrder() const override; 107 108 bool 109 IsExecutable() const override; 110 111 uint32_t 112 GetAddressByteSize() const override; 113 114 lldb::AddressClass 115 GetAddressClass(lldb::addr_t file_addr) override; 116 117 lldb_private::Symtab * 118 GetSymtab() override; 119 120 bool 121 IsStripped() override; 122 123 void 124 CreateSections(lldb_private::SectionList &unified_section_list) override; 125 126 void 127 Dump(lldb_private::Stream *s) override; 128 129 bool 130 GetArchitecture(lldb_private::ArchSpec &arch) override; 131 132 bool 133 GetUUID(lldb_private::UUID* uuid) override; 134 135 uint32_t 136 GetDependentModules(lldb_private::FileSpecList& files) override; 137 138 lldb_private::FileSpecList 139 GetReExportedLibraries() override 140 { 141 return m_reexported_dylibs; 142 } 143 144 lldb_private::Address 145 GetEntryPointAddress() override; 146 147 lldb_private::Address 148 GetHeaderAddress() override; 149 150 uint32_t 151 GetNumThreadContexts() override; 152 153 lldb::RegisterContextSP 154 GetThreadContextAtIndex(uint32_t idx, lldb_private::Thread &thread) override; 155 156 ObjectFile::Type 157 CalculateType() override; 158 159 ObjectFile::Strata 160 CalculateStrata() override; 161 162 uint32_t 163 GetVersion(uint32_t *versions, uint32_t num_versions) override; 164 165 uint32_t 166 GetMinimumOSVersion(uint32_t *versions, uint32_t num_versions) override; 167 168 uint32_t 169 GetSDKVersion(uint32_t *versions, uint32_t num_versions) override; 170 171 bool 172 GetIsDynamicLinkEditor() override; 173 174 static bool 175 ParseHeader (lldb_private::DataExtractor &data, 176 lldb::offset_t *data_offset_ptr, 177 llvm::MachO::mach_header &header); 178 179 bool 180 AllowAssemblyEmulationUnwindPlans () override; 181 182 //------------------------------------------------------------------ 183 // PluginInterface protocol 184 //------------------------------------------------------------------ 185 lldb_private::ConstString 186 GetPluginName() override; 187 188 uint32_t 189 GetPluginVersion() override; 190 191 protected: 192 static bool 193 GetUUID (const llvm::MachO::mach_header &header, 194 const lldb_private::DataExtractor &data, 195 lldb::offset_t lc_offset, // Offset to the first load command 196 lldb_private::UUID& uuid); 197 198 static bool 199 GetArchitecture (const llvm::MachO::mach_header &header, 200 const lldb_private::DataExtractor &data, 201 lldb::offset_t lc_offset, 202 lldb_private::ArchSpec &arch); 203 204 // Intended for same-host arm device debugging where lldb needs to 205 // detect libraries in the shared cache and augment the nlist entries 206 // with an on-disk dyld_shared_cache file. The process will record 207 // the shared cache UUID so the on-disk cache can be matched or rejected 208 // correctly. 209 lldb_private::UUID 210 GetProcessSharedCacheUUID (lldb_private::Process *); 211 212 // Intended for same-host arm device debugging where lldb will read 213 // shared cache libraries out of its own memory instead of the remote 214 // process' memory as an optimization. If lldb's shared cache UUID 215 // does not match the process' shared cache UUID, this optimization 216 // should not be used. 217 lldb_private::UUID 218 GetLLDBSharedCacheUUID (); 219 220 lldb_private::Section * 221 GetMachHeaderSection(); 222 223 lldb::addr_t 224 CalculateSectionLoadAddressForMemoryImage(lldb::addr_t mach_header_load_address, 225 const lldb_private::Section *mach_header_section, 226 const lldb_private::Section *section); 227 228 lldb_private::UUID 229 GetSharedCacheUUID (lldb_private::FileSpec dyld_shared_cache, const lldb::ByteOrder byte_order, const uint32_t addr_byte_size); 230 231 size_t 232 ParseSymtab(); 233 234 llvm::MachO::mach_header m_header; 235 static const lldb_private::ConstString &GetSegmentNameTEXT(); 236 static const lldb_private::ConstString &GetSegmentNameDATA(); 237 static const lldb_private::ConstString &GetSegmentNameDATA_DIRTY(); 238 static const lldb_private::ConstString &GetSegmentNameDATA_CONST(); 239 static const lldb_private::ConstString &GetSegmentNameOBJC(); 240 static const lldb_private::ConstString &GetSegmentNameLINKEDIT(); 241 static const lldb_private::ConstString &GetSectionNameEHFrame(); 242 243 llvm::MachO::dysymtab_command m_dysymtab; 244 std::vector<llvm::MachO::segment_command_64> m_mach_segments; 245 std::vector<llvm::MachO::section_64> m_mach_sections; 246 std::vector<uint32_t> m_min_os_versions; 247 std::vector<uint32_t> m_sdk_versions; 248 typedef lldb_private::RangeVector<uint32_t, uint32_t> FileRangeArray; 249 lldb_private::Address m_entry_point_address; 250 FileRangeArray m_thread_context_offsets; 251 bool m_thread_context_offsets_valid; 252 lldb_private::FileSpecList m_reexported_dylibs; 253 bool m_allow_assembly_emulation_unwind_plans; 254 }; 255 256 #endif // liblldb_ObjectFileMachO_h_ 257