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