Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- ObjectFile.cpp ------------------------------------------*- 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 | #include "lldb/lldb-private.h" |
Greg Clayton | e40b642 | 2011-09-18 18:59:15 +0000 | [diff] [blame] | 11 | #include "lldb/lldb-private-log.h" |
Greg Clayton | db2dc2b | 2012-01-12 05:25:17 +0000 | [diff] [blame] | 12 | #include "lldb/Core/DataBuffer.h" |
Greg Clayton | b5a8f14 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 13 | #include "lldb/Core/DataBufferHeap.h" |
Greg Clayton | e40b642 | 2011-09-18 18:59:15 +0000 | [diff] [blame] | 14 | #include "lldb/Core/Log.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 15 | #include "lldb/Core/Module.h" |
| 16 | #include "lldb/Core/PluginManager.h" |
| 17 | #include "lldb/Core/RegularExpression.h" |
Greg Clayton | 49ce896 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 18 | #include "lldb/Core/Section.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 19 | #include "lldb/Core/Timer.h" |
| 20 | #include "lldb/Symbol/ObjectFile.h" |
| 21 | #include "lldb/Symbol/ObjectContainer.h" |
| 22 | #include "lldb/Symbol/SymbolFile.h" |
Greg Clayton | b5a8f14 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 23 | #include "lldb/Target/Process.h" |
Greg Clayton | 49ce896 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 24 | #include "Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 25 | |
| 26 | using namespace lldb; |
| 27 | using namespace lldb_private; |
| 28 | |
Greg Clayton | e40b642 | 2011-09-18 18:59:15 +0000 | [diff] [blame] | 29 | ObjectFileSP |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 30 | ObjectFile::FindPlugin (const lldb::ModuleSP &module_sp, const FileSpec* file, addr_t file_offset, addr_t file_size, DataBufferSP &file_data_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 31 | { |
Greg Clayton | e40b642 | 2011-09-18 18:59:15 +0000 | [diff] [blame] | 32 | ObjectFileSP object_file_sp; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 33 | |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 34 | if (module_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 35 | { |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 36 | Timer scoped_timer (__PRETTY_FUNCTION__, |
Daniel Malea | 5f35a4b | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 37 | "ObjectFile::FindPlugin (module = %s/%s, file = %p, file_offset = 0x%8.8" PRIx64 ", file_size = 0x%8.8" PRIx64 ")", |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 38 | module_sp->GetFileSpec().GetDirectory().AsCString(), |
| 39 | module_sp->GetFileSpec().GetFilename().AsCString(), |
Jason Molenda | ef9eb80 | 2012-09-11 06:35:15 +0000 | [diff] [blame] | 40 | file, (uint64_t) file_offset, (uint64_t) file_size); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 41 | if (file) |
| 42 | { |
Greg Clayton | db2dc2b | 2012-01-12 05:25:17 +0000 | [diff] [blame] | 43 | // Memory map the entire file contents |
Greg Clayton | 49ce896 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 44 | if (!file_data_sp && file_size > 0) |
Greg Clayton | db2dc2b | 2012-01-12 05:25:17 +0000 | [diff] [blame] | 45 | { |
| 46 | assert (file_offset == 0); |
| 47 | file_data_sp = file->MemoryMapFileContents(file_offset, file_size); |
| 48 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 49 | |
Greg Clayton | db2dc2b | 2012-01-12 05:25:17 +0000 | [diff] [blame] | 50 | if (!file_data_sp || file_data_sp->GetByteSize() == 0) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 51 | { |
| 52 | // Check for archive file with format "/path/to/archive.a(object.o)" |
| 53 | char path_with_object[PATH_MAX*2]; |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 54 | module_sp->GetFileSpec().GetPath(path_with_object, sizeof(path_with_object)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 55 | |
Greg Clayton | 49ce896 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 56 | FileSpec archive_file; |
| 57 | ConstString archive_object; |
| 58 | if (ObjectFile::SplitArchivePathWithObject (path_with_object, archive_file, archive_object)) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 59 | { |
Greg Clayton | 49ce896 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 60 | file_size = archive_file.GetByteSize(); |
| 61 | if (file_size > 0) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 62 | { |
Greg Clayton | 49ce896 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 63 | module_sp->SetFileSpecAndObjectName (archive_file, archive_object); |
| 64 | file_data_sp = archive_file.MemoryMapFileContents(file_offset, file_size); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 65 | } |
| 66 | } |
| 67 | } |
| 68 | |
Greg Clayton | db2dc2b | 2012-01-12 05:25:17 +0000 | [diff] [blame] | 69 | if (file_data_sp && file_data_sp->GetByteSize() > 0) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 70 | { |
Greg Clayton | db2dc2b | 2012-01-12 05:25:17 +0000 | [diff] [blame] | 71 | uint32_t idx; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 72 | |
Greg Clayton | db2dc2b | 2012-01-12 05:25:17 +0000 | [diff] [blame] | 73 | // Check if this is a normal object file by iterating through |
| 74 | // all object file plugin instances. |
| 75 | ObjectFileCreateInstance create_object_file_callback; |
| 76 | for (idx = 0; (create_object_file_callback = PluginManager::GetObjectFileCreateCallbackAtIndex(idx)) != NULL; ++idx) |
| 77 | { |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 78 | object_file_sp.reset (create_object_file_callback(module_sp, file_data_sp, file, file_offset, file_size)); |
Greg Clayton | db2dc2b | 2012-01-12 05:25:17 +0000 | [diff] [blame] | 79 | if (object_file_sp.get()) |
| 80 | return object_file_sp; |
| 81 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 82 | |
Greg Clayton | db2dc2b | 2012-01-12 05:25:17 +0000 | [diff] [blame] | 83 | // Check if this is a object container by iterating through |
| 84 | // all object container plugin instances and then trying to get |
| 85 | // an object file from the container. |
| 86 | ObjectContainerCreateInstance create_object_container_callback; |
| 87 | for (idx = 0; (create_object_container_callback = PluginManager::GetObjectContainerCreateCallbackAtIndex(idx)) != NULL; ++idx) |
| 88 | { |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 89 | std::auto_ptr<ObjectContainer> object_container_ap(create_object_container_callback(module_sp, file_data_sp, file, file_offset, file_size)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 90 | |
Greg Clayton | db2dc2b | 2012-01-12 05:25:17 +0000 | [diff] [blame] | 91 | if (object_container_ap.get()) |
| 92 | object_file_sp = object_container_ap->GetObjectFile(file); |
| 93 | |
| 94 | if (object_file_sp.get()) |
| 95 | return object_file_sp; |
| 96 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 97 | } |
| 98 | } |
| 99 | } |
Greg Clayton | e40b642 | 2011-09-18 18:59:15 +0000 | [diff] [blame] | 100 | // We didn't find it, so clear our shared pointer in case it |
| 101 | // contains anything and return an empty shared pointer |
| 102 | object_file_sp.reset(); |
| 103 | return object_file_sp; |
| 104 | } |
| 105 | |
Greg Clayton | b5a8f14 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 106 | ObjectFileSP |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 107 | ObjectFile::FindPlugin (const lldb::ModuleSP &module_sp, |
Greg Clayton | b5a8f14 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 108 | const ProcessSP &process_sp, |
| 109 | lldb::addr_t header_addr, |
| 110 | DataBufferSP &file_data_sp) |
| 111 | { |
Greg Clayton | b5a8f14 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 112 | ObjectFileSP object_file_sp; |
| 113 | |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 114 | if (module_sp) |
Greg Clayton | b5a8f14 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 115 | { |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 116 | Timer scoped_timer (__PRETTY_FUNCTION__, |
Daniel Malea | 5f35a4b | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 117 | "ObjectFile::FindPlugin (module = %s/%s, process = %p, header_addr = 0x%" PRIx64 ")", |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 118 | module_sp->GetFileSpec().GetDirectory().AsCString(), |
| 119 | module_sp->GetFileSpec().GetFilename().AsCString(), |
| 120 | process_sp.get(), header_addr); |
Greg Clayton | b5a8f14 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 121 | uint32_t idx; |
| 122 | |
| 123 | // Check if this is a normal object file by iterating through |
| 124 | // all object file plugin instances. |
| 125 | ObjectFileCreateMemoryInstance create_callback; |
| 126 | for (idx = 0; (create_callback = PluginManager::GetObjectFileCreateMemoryCallbackAtIndex(idx)) != NULL; ++idx) |
| 127 | { |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 128 | object_file_sp.reset (create_callback(module_sp, file_data_sp, process_sp, header_addr)); |
Greg Clayton | b5a8f14 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 129 | if (object_file_sp.get()) |
| 130 | return object_file_sp; |
| 131 | } |
| 132 | |
| 133 | } |
| 134 | // We didn't find it, so clear our shared pointer in case it |
| 135 | // contains anything and return an empty shared pointer |
| 136 | object_file_sp.reset(); |
| 137 | return object_file_sp; |
| 138 | } |
| 139 | |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 140 | ObjectFile::ObjectFile (const lldb::ModuleSP &module_sp, |
Greg Clayton | e40b642 | 2011-09-18 18:59:15 +0000 | [diff] [blame] | 141 | const FileSpec *file_spec_ptr, |
Greg Clayton | db2dc2b | 2012-01-12 05:25:17 +0000 | [diff] [blame] | 142 | addr_t file_offset, |
| 143 | addr_t file_size, |
| 144 | DataBufferSP& file_data_sp) : |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 145 | ModuleChild (module_sp), |
Greg Clayton | e40b642 | 2011-09-18 18:59:15 +0000 | [diff] [blame] | 146 | m_file (), // This file could be different from the original module's file |
| 147 | m_type (eTypeInvalid), |
| 148 | m_strata (eStrataInvalid), |
Greg Clayton | db2dc2b | 2012-01-12 05:25:17 +0000 | [diff] [blame] | 149 | m_offset (file_offset), |
| 150 | m_length (file_size), |
| 151 | m_data (), |
Greg Clayton | b5a8f14 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 152 | m_unwind_table (*this), |
| 153 | m_process_wp(), |
Greg Clayton | 46c9a35 | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 154 | m_memory_addr (LLDB_INVALID_ADDRESS) |
Greg Clayton | e40b642 | 2011-09-18 18:59:15 +0000 | [diff] [blame] | 155 | { |
| 156 | if (file_spec_ptr) |
| 157 | m_file = *file_spec_ptr; |
Greg Clayton | db2dc2b | 2012-01-12 05:25:17 +0000 | [diff] [blame] | 158 | if (file_data_sp) |
| 159 | m_data.SetData (file_data_sp, file_offset, file_size); |
Greg Clayton | e40b642 | 2011-09-18 18:59:15 +0000 | [diff] [blame] | 160 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT)); |
| 161 | if (log) |
| 162 | { |
| 163 | if (m_file) |
| 164 | { |
Daniel Malea | 5f35a4b | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 165 | log->Printf ("%p ObjectFile::ObjectFile () module = %s/%s, file = %s/%s, offset = 0x%8.8" PRIx64 ", size = %" PRIu64 "\n", |
Greg Clayton | e40b642 | 2011-09-18 18:59:15 +0000 | [diff] [blame] | 166 | this, |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 167 | module_sp->GetFileSpec().GetDirectory().AsCString(), |
| 168 | module_sp->GetFileSpec().GetFilename().AsCString(), |
Greg Clayton | e40b642 | 2011-09-18 18:59:15 +0000 | [diff] [blame] | 169 | m_file.GetDirectory().AsCString(), |
| 170 | m_file.GetFilename().AsCString(), |
| 171 | m_offset, |
| 172 | m_length); |
| 173 | } |
| 174 | else |
| 175 | { |
Daniel Malea | 5f35a4b | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 176 | log->Printf ("%p ObjectFile::ObjectFile () module = %s/%s, file = <NULL>, offset = 0x%8.8" PRIx64 ", size = %" PRIu64 "\n", |
Greg Clayton | e40b642 | 2011-09-18 18:59:15 +0000 | [diff] [blame] | 177 | this, |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 178 | module_sp->GetFileSpec().GetDirectory().AsCString(), |
| 179 | module_sp->GetFileSpec().GetFilename().AsCString(), |
Greg Clayton | e40b642 | 2011-09-18 18:59:15 +0000 | [diff] [blame] | 180 | m_offset, |
| 181 | m_length); |
| 182 | } |
| 183 | } |
| 184 | } |
| 185 | |
Greg Clayton | b5a8f14 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 186 | |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 187 | ObjectFile::ObjectFile (const lldb::ModuleSP &module_sp, |
Greg Clayton | b5a8f14 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 188 | const ProcessSP &process_sp, |
| 189 | lldb::addr_t header_addr, |
| 190 | DataBufferSP& header_data_sp) : |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 191 | ModuleChild (module_sp), |
Greg Clayton | b5a8f14 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 192 | m_file (), |
| 193 | m_type (eTypeInvalid), |
| 194 | m_strata (eStrataInvalid), |
| 195 | m_offset (header_addr), |
| 196 | m_length (0), |
| 197 | m_data (), |
| 198 | m_unwind_table (*this), |
| 199 | m_process_wp (process_sp), |
Greg Clayton | 46c9a35 | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 200 | m_memory_addr (header_addr) |
Greg Clayton | b5a8f14 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 201 | { |
| 202 | if (header_data_sp) |
| 203 | m_data.SetData (header_data_sp, 0, header_data_sp->GetByteSize()); |
| 204 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT)); |
| 205 | if (log) |
| 206 | { |
Daniel Malea | 5f35a4b | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 207 | log->Printf ("%p ObjectFile::ObjectFile () module = %s/%s, process = %p, header_addr = 0x%" PRIx64 "\n", |
Greg Clayton | b5a8f14 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 208 | this, |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 209 | module_sp->GetFileSpec().GetDirectory().AsCString(), |
| 210 | module_sp->GetFileSpec().GetFilename().AsCString(), |
Greg Clayton | b5a8f14 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 211 | process_sp.get(), |
| 212 | m_offset); |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | |
Greg Clayton | e40b642 | 2011-09-18 18:59:15 +0000 | [diff] [blame] | 217 | ObjectFile::~ObjectFile() |
| 218 | { |
| 219 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT)); |
| 220 | if (log) |
Greg Clayton | c9b798c | 2012-11-28 00:44:24 +0000 | [diff] [blame] | 221 | log->Printf ("%p ObjectFile::~ObjectFile ()\n", this); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 222 | } |
Jim Ingham | 7508e73 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 223 | |
| 224 | bool |
| 225 | ObjectFile::SetModulesArchitecture (const ArchSpec &new_arch) |
| 226 | { |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 227 | ModuleSP module_sp (GetModule()); |
| 228 | if (module_sp) |
| 229 | return module_sp->SetArchitecture (new_arch); |
| 230 | return false; |
Jim Ingham | 7508e73 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 231 | } |
| 232 | |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 233 | AddressClass |
Greg Clayton | e40b642 | 2011-09-18 18:59:15 +0000 | [diff] [blame] | 234 | ObjectFile::GetAddressClass (addr_t file_addr) |
Greg Clayton | b1888f2 | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 235 | { |
| 236 | Symtab *symtab = GetSymtab(); |
| 237 | if (symtab) |
| 238 | { |
| 239 | Symbol *symbol = symtab->FindSymbolContainingFileAddress(file_addr); |
| 240 | if (symbol) |
| 241 | { |
Greg Clayton | 0c31d3d | 2012-03-07 21:03:09 +0000 | [diff] [blame] | 242 | if (symbol->ValueIsAddress()) |
Greg Clayton | b1888f2 | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 243 | { |
Greg Clayton | 0c31d3d | 2012-03-07 21:03:09 +0000 | [diff] [blame] | 244 | const SectionSP section_sp (symbol->GetAddress().GetSection()); |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 245 | if (section_sp) |
Greg Clayton | b1888f2 | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 246 | { |
Greg Clayton | 3508c38 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 247 | const SectionType section_type = section_sp->GetType(); |
Greg Clayton | b1888f2 | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 248 | switch (section_type) |
| 249 | { |
| 250 | case eSectionTypeInvalid: return eAddressClassUnknown; |
| 251 | case eSectionTypeCode: return eAddressClassCode; |
| 252 | case eSectionTypeContainer: return eAddressClassUnknown; |
Greg Clayton | 24a6bd9 | 2011-10-27 17:55:14 +0000 | [diff] [blame] | 253 | case eSectionTypeData: |
| 254 | case eSectionTypeDataCString: |
| 255 | case eSectionTypeDataCStringPointers: |
| 256 | case eSectionTypeDataSymbolAddress: |
| 257 | case eSectionTypeData4: |
| 258 | case eSectionTypeData8: |
| 259 | case eSectionTypeData16: |
| 260 | case eSectionTypeDataPointers: |
| 261 | case eSectionTypeZeroFill: |
| 262 | case eSectionTypeDataObjCMessageRefs: |
| 263 | case eSectionTypeDataObjCCFStrings: |
| 264 | return eAddressClassData; |
| 265 | case eSectionTypeDebug: |
| 266 | case eSectionTypeDWARFDebugAbbrev: |
| 267 | case eSectionTypeDWARFDebugAranges: |
| 268 | case eSectionTypeDWARFDebugFrame: |
| 269 | case eSectionTypeDWARFDebugInfo: |
| 270 | case eSectionTypeDWARFDebugLine: |
| 271 | case eSectionTypeDWARFDebugLoc: |
| 272 | case eSectionTypeDWARFDebugMacInfo: |
| 273 | case eSectionTypeDWARFDebugPubNames: |
| 274 | case eSectionTypeDWARFDebugPubTypes: |
| 275 | case eSectionTypeDWARFDebugRanges: |
| 276 | case eSectionTypeDWARFDebugStr: |
| 277 | case eSectionTypeDWARFAppleNames: |
| 278 | case eSectionTypeDWARFAppleTypes: |
| 279 | case eSectionTypeDWARFAppleNamespaces: |
| 280 | case eSectionTypeDWARFAppleObjC: |
| 281 | return eAddressClassDebug; |
Greg Clayton | b1888f2 | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 282 | case eSectionTypeEHFrame: return eAddressClassRuntime; |
| 283 | case eSectionTypeOther: return eAddressClassUnknown; |
| 284 | } |
| 285 | } |
| 286 | } |
| 287 | |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 288 | const SymbolType symbol_type = symbol->GetType(); |
Greg Clayton | b1888f2 | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 289 | switch (symbol_type) |
| 290 | { |
| 291 | case eSymbolTypeAny: return eAddressClassUnknown; |
| 292 | case eSymbolTypeAbsolute: return eAddressClassUnknown; |
Greg Clayton | b1888f2 | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 293 | case eSymbolTypeCode: return eAddressClassCode; |
| 294 | case eSymbolTypeTrampoline: return eAddressClassCode; |
| 295 | case eSymbolTypeData: return eAddressClassData; |
| 296 | case eSymbolTypeRuntime: return eAddressClassRuntime; |
| 297 | case eSymbolTypeException: return eAddressClassRuntime; |
| 298 | case eSymbolTypeSourceFile: return eAddressClassDebug; |
| 299 | case eSymbolTypeHeaderFile: return eAddressClassDebug; |
| 300 | case eSymbolTypeObjectFile: return eAddressClassDebug; |
| 301 | case eSymbolTypeCommonBlock: return eAddressClassDebug; |
| 302 | case eSymbolTypeBlock: return eAddressClassDebug; |
| 303 | case eSymbolTypeLocal: return eAddressClassData; |
| 304 | case eSymbolTypeParam: return eAddressClassData; |
| 305 | case eSymbolTypeVariable: return eAddressClassData; |
| 306 | case eSymbolTypeVariableType: return eAddressClassDebug; |
| 307 | case eSymbolTypeLineEntry: return eAddressClassDebug; |
| 308 | case eSymbolTypeLineHeader: return eAddressClassDebug; |
| 309 | case eSymbolTypeScopeBegin: return eAddressClassDebug; |
| 310 | case eSymbolTypeScopeEnd: return eAddressClassDebug; |
| 311 | case eSymbolTypeAdditional: return eAddressClassUnknown; |
| 312 | case eSymbolTypeCompiler: return eAddressClassDebug; |
| 313 | case eSymbolTypeInstrumentation:return eAddressClassDebug; |
| 314 | case eSymbolTypeUndefined: return eAddressClassUnknown; |
Greg Clayton | 3f69eac | 2011-12-03 02:30:59 +0000 | [diff] [blame] | 315 | case eSymbolTypeObjCClass: return eAddressClassRuntime; |
| 316 | case eSymbolTypeObjCMetaClass: return eAddressClassRuntime; |
| 317 | case eSymbolTypeObjCIVar: return eAddressClassRuntime; |
Greg Clayton | b1888f2 | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 318 | } |
| 319 | } |
| 320 | } |
| 321 | return eAddressClassUnknown; |
| 322 | } |
| 323 | |
Greg Clayton | b5a8f14 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 324 | DataBufferSP |
| 325 | ObjectFile::ReadMemory (const ProcessSP &process_sp, lldb::addr_t addr, size_t byte_size) |
| 326 | { |
| 327 | DataBufferSP data_sp; |
| 328 | if (process_sp) |
| 329 | { |
| 330 | std::auto_ptr<DataBufferHeap> data_ap (new DataBufferHeap (byte_size, 0)); |
| 331 | Error error; |
| 332 | const size_t bytes_read = process_sp->ReadMemory (addr, |
| 333 | data_ap->GetBytes(), |
| 334 | data_ap->GetByteSize(), |
| 335 | error); |
| 336 | if (bytes_read == byte_size) |
| 337 | data_sp.reset (data_ap.release()); |
| 338 | } |
| 339 | return data_sp; |
| 340 | } |
| 341 | |
Greg Clayton | db2dc2b | 2012-01-12 05:25:17 +0000 | [diff] [blame] | 342 | size_t |
| 343 | ObjectFile::GetData (off_t offset, size_t length, DataExtractor &data) const |
| 344 | { |
| 345 | // The entire file has already been mmap'ed into m_data, so just copy from there |
| 346 | // as the back mmap buffer will be shared with shared pointers. |
| 347 | return data.SetData (m_data, offset, length); |
| 348 | } |
| 349 | |
| 350 | size_t |
| 351 | ObjectFile::CopyData (off_t offset, size_t length, void *dst) const |
| 352 | { |
| 353 | // The entire file has already been mmap'ed into m_data, so just copy from there |
| 354 | return m_data.CopyByteOrderedData (offset, length, dst, length, lldb::endian::InlHostByteOrder()); |
| 355 | } |
Greg Clayton | b1888f2 | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 356 | |
Greg Clayton | b5a8f14 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 357 | |
| 358 | size_t |
| 359 | ObjectFile::ReadSectionData (const Section *section, off_t section_offset, void *dst, size_t dst_len) const |
| 360 | { |
Greg Clayton | 46c9a35 | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 361 | if (IsInMemory()) |
Greg Clayton | b5a8f14 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 362 | { |
| 363 | ProcessSP process_sp (m_process_wp.lock()); |
| 364 | if (process_sp) |
| 365 | { |
| 366 | Error error; |
Greg Clayton | 2ddb2b8 | 2013-02-01 21:38:35 +0000 | [diff] [blame^] | 367 | const addr_t base_load_addr = section->GetLoadBaseAddress (&process_sp->GetTarget()); |
| 368 | if (base_load_addr != LLDB_INVALID_ADDRESS) |
| 369 | return process_sp->ReadMemory (base_load_addr + section_offset, dst, dst_len, error); |
Greg Clayton | b5a8f14 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 370 | } |
| 371 | } |
| 372 | else |
| 373 | { |
Greg Clayton | 3383c17 | 2012-02-21 17:34:25 +0000 | [diff] [blame] | 374 | const uint64_t section_file_size = section->GetFileSize(); |
| 375 | if (section_offset < section_file_size) |
| 376 | { |
| 377 | const uint64_t section_bytes_left = section_file_size - section_offset; |
| 378 | uint64_t section_dst_len = dst_len; |
| 379 | if (section_dst_len > section_bytes_left) |
| 380 | section_dst_len = section_bytes_left; |
| 381 | return CopyData (section->GetFileOffset() + section_offset, section_dst_len, dst); |
| 382 | } |
Sean Callanan | 1e52600 | 2013-01-04 23:20:01 +0000 | [diff] [blame] | 383 | else |
| 384 | { |
| 385 | if (section->GetType() == eSectionTypeZeroFill) |
| 386 | { |
| 387 | const uint64_t section_size = section->GetByteSize(); |
| 388 | const uint64_t section_bytes_left = section_size - section_offset; |
| 389 | uint64_t section_dst_len = dst_len; |
| 390 | if (section_dst_len > section_bytes_left) |
| 391 | section_dst_len = section_bytes_left; |
| 392 | bzero(dst, section_dst_len); |
| 393 | return section_dst_len; |
| 394 | } |
| 395 | } |
Greg Clayton | b5a8f14 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 396 | } |
| 397 | return 0; |
| 398 | } |
| 399 | |
| 400 | //---------------------------------------------------------------------- |
| 401 | // Get the section data the file on disk |
| 402 | //---------------------------------------------------------------------- |
| 403 | size_t |
| 404 | ObjectFile::ReadSectionData (const Section *section, DataExtractor& section_data) const |
| 405 | { |
Greg Clayton | 46c9a35 | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 406 | if (IsInMemory()) |
Greg Clayton | b5a8f14 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 407 | { |
| 408 | ProcessSP process_sp (m_process_wp.lock()); |
| 409 | if (process_sp) |
| 410 | { |
Greg Clayton | 2ddb2b8 | 2013-02-01 21:38:35 +0000 | [diff] [blame^] | 411 | const addr_t base_load_addr = section->GetLoadBaseAddress (&process_sp->GetTarget()); |
| 412 | if (base_load_addr != LLDB_INVALID_ADDRESS) |
Greg Clayton | b5a8f14 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 413 | { |
Greg Clayton | 2ddb2b8 | 2013-02-01 21:38:35 +0000 | [diff] [blame^] | 414 | DataBufferSP data_sp (ReadMemory (process_sp, base_load_addr, section->GetByteSize())); |
| 415 | if (data_sp) |
| 416 | { |
| 417 | section_data.SetData (data_sp, 0, data_sp->GetByteSize()); |
| 418 | section_data.SetByteOrder (process_sp->GetByteOrder()); |
| 419 | section_data.SetAddressByteSize (process_sp->GetAddressByteSize()); |
| 420 | return section_data.GetByteSize(); |
| 421 | } |
Greg Clayton | b5a8f14 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 422 | } |
| 423 | } |
| 424 | } |
| 425 | else |
| 426 | { |
| 427 | // The object file now contains a full mmap'ed copy of the object file data, so just use this |
| 428 | return MemoryMapSectionData (section, section_data); |
| 429 | } |
| 430 | section_data.Clear(); |
| 431 | return 0; |
| 432 | } |
| 433 | |
| 434 | size_t |
| 435 | ObjectFile::MemoryMapSectionData (const Section *section, DataExtractor& section_data) const |
| 436 | { |
Greg Clayton | 46c9a35 | 2012-02-09 06:16:32 +0000 | [diff] [blame] | 437 | if (IsInMemory()) |
Greg Clayton | b5a8f14 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 438 | { |
| 439 | return ReadSectionData (section, section_data); |
| 440 | } |
| 441 | else |
| 442 | { |
| 443 | // The object file now contains a full mmap'ed copy of the object file data, so just use this |
Greg Clayton | 23d90ae | 2012-03-27 02:40:46 +0000 | [diff] [blame] | 444 | return GetData(section->GetFileOffset(), section->GetFileSize(), section_data); |
Greg Clayton | b5a8f14 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 445 | } |
| 446 | section_data.Clear(); |
| 447 | return 0; |
| 448 | } |
| 449 | |
Greg Clayton | 49ce896 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 450 | |
| 451 | bool |
| 452 | ObjectFile::SplitArchivePathWithObject (const char *path_with_object, FileSpec &archive_file, ConstString &archive_object) |
| 453 | { |
| 454 | RegularExpression g_object_regex("(.*)\\(([^\\)]+)\\)$"); |
| 455 | if (g_object_regex.Execute (path_with_object, 2)) |
| 456 | { |
| 457 | std::string path; |
| 458 | std::string obj; |
| 459 | if (g_object_regex.GetMatchAtIndex (path_with_object, 1, path) && |
| 460 | g_object_regex.GetMatchAtIndex (path_with_object, 2, obj)) |
| 461 | { |
| 462 | archive_file.SetFile (path.c_str(), false); |
| 463 | archive_object.SetCString(obj.c_str()); |
| 464 | return true; |
| 465 | } |
| 466 | } |
| 467 | return false; |
| 468 | } |
| 469 | |