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 "llvm/Support/MachO.h" 14 15 #include "lldb/Core/Address.h" 16 #include "lldb/Core/RangeMap.h" 17 #include "lldb/Host/FileSpec.h" 18 #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 //---------------------------------------------------------------------- 25 class ObjectFileMachO : 26 public lldb_private::ObjectFile 27 { 28 public: 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 44 static lldb_private::ObjectFile * 45 CreateInstance (const lldb::ModuleSP &module_sp, 46 lldb::DataBufferSP& data_sp, 47 lldb::offset_t data_offset, 48 const lldb_private::FileSpec* file, 49 lldb::offset_t file_offset, 50 lldb::offset_t length); 51 52 static lldb_private::ObjectFile * 53 CreateMemoryInstance (const lldb::ModuleSP &module_sp, 54 lldb::DataBufferSP& data_sp, 55 const lldb::ProcessSP &process_sp, 56 lldb::addr_t header_addr); 57 58 static bool 59 MagicBytesMatch (lldb::DataBufferSP& data_sp, 60 lldb::addr_t offset, 61 lldb::addr_t length); 62 63 //------------------------------------------------------------------ 64 // Member Functions 65 //------------------------------------------------------------------ 66 ObjectFileMachO (const lldb::ModuleSP &module_sp, 67 lldb::DataBufferSP& data_sp, 68 lldb::offset_t data_offset, 69 const lldb_private::FileSpec* file, 70 lldb::offset_t offset, 71 lldb::offset_t length); 72 73 ObjectFileMachO (const lldb::ModuleSP &module_sp, 74 lldb::DataBufferSP& data_sp, 75 const lldb::ProcessSP &process_sp, 76 lldb::addr_t header_addr); 77 78 virtual 79 ~ObjectFileMachO(); 80 81 virtual bool 82 ParseHeader (); 83 84 virtual lldb::ByteOrder 85 GetByteOrder () const; 86 87 virtual bool 88 IsExecutable () const; 89 90 virtual uint32_t 91 GetAddressByteSize () const; 92 93 virtual lldb::AddressClass 94 GetAddressClass (lldb::addr_t file_addr); 95 96 virtual lldb_private::Symtab * 97 GetSymtab(); 98 99 virtual lldb_private::SectionList * 100 GetSectionList(); 101 102 virtual void 103 Dump (lldb_private::Stream *s); 104 105 virtual bool 106 GetArchitecture (lldb_private::ArchSpec &arch); 107 108 virtual bool 109 GetUUID (lldb_private::UUID* uuid); 110 111 virtual uint32_t 112 GetDependentModules (lldb_private::FileSpecList& files); 113 114 //------------------------------------------------------------------ 115 // PluginInterface protocol 116 //------------------------------------------------------------------ 117 virtual const char * 118 GetPluginName(); 119 120 virtual const char * 121 GetShortPluginName(); 122 123 virtual uint32_t 124 GetPluginVersion(); 125 126 virtual lldb_private::Address 127 GetEntryPointAddress (); 128 129 virtual lldb_private::Address 130 GetHeaderAddress (); 131 132 virtual uint32_t 133 GetNumThreadContexts (); 134 135 virtual lldb::RegisterContextSP 136 GetThreadContextAtIndex (uint32_t idx, lldb_private::Thread &thread); 137 138 virtual ObjectFile::Type 139 CalculateType(); 140 141 virtual ObjectFile::Strata 142 CalculateStrata(); 143 144 virtual uint32_t 145 GetVersion (uint32_t *versions, uint32_t num_versions); 146 147 protected: 148 llvm::MachO::mach_header m_header; 149 static const lldb_private::ConstString &GetSegmentNameTEXT(); 150 static const lldb_private::ConstString &GetSegmentNameDATA(); 151 static const lldb_private::ConstString &GetSegmentNameOBJC(); 152 static const lldb_private::ConstString &GetSegmentNameLINKEDIT(); 153 static const lldb_private::ConstString &GetSectionNameEHFrame(); 154 155 llvm::MachO::dysymtab_command m_dysymtab; 156 std::vector<llvm::MachO::segment_command_64> m_mach_segments; 157 std::vector<llvm::MachO::section_64> m_mach_sections; 158 typedef lldb_private::RangeVector<uint32_t, uint32_t> FileRangeArray; 159 lldb_private::Address m_entry_point_address; 160 FileRangeArray m_thread_context_offsets; 161 bool m_thread_context_offsets_valid; 162 163 size_t 164 ParseSections (); 165 166 size_t 167 ParseSymtab (bool minimize); 168 169 }; 170 171 #endif // liblldb_ObjectFileMachO_h_ 172