Chris Lattner | 30fdc8d | 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 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 10 | #include "lldb/Symbol/ObjectFile.h" |
| 11 | #include "Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 12 | #include "lldb/Core/Module.h" |
Greg Clayton | f4d6de6 | 2013-04-24 22:29:28 +0000 | [diff] [blame] | 13 | #include "lldb/Core/ModuleSpec.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 14 | #include "lldb/Core/PluginManager.h" |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 15 | #include "lldb/Core/Section.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 16 | #include "lldb/Symbol/ObjectContainer.h" |
| 17 | #include "lldb/Symbol/SymbolFile.h" |
Zachary Turner | bf9a773 | 2017-02-02 21:39:50 +0000 | [diff] [blame] | 18 | #include "lldb/Target/Process.h" |
Hafiz Abid Qadeer | 4687db0 | 2017-01-19 17:32:50 +0000 | [diff] [blame] | 19 | #include "lldb/Target/SectionLoadList.h" |
Zachary Turner | bf9a773 | 2017-02-02 21:39:50 +0000 | [diff] [blame] | 20 | #include "lldb/Target/Target.h" |
Zachary Turner | 666cc0b | 2017-03-04 01:30:05 +0000 | [diff] [blame] | 21 | #include "lldb/Utility/DataBuffer.h" |
| 22 | #include "lldb/Utility/DataBufferHeap.h" |
Zachary Turner | 7f6a7a3 | 2017-03-06 23:42:14 +0000 | [diff] [blame] | 23 | #include "lldb/Utility/DataBufferLLVM.h" |
Zachary Turner | 6f9e690 | 2017-03-03 20:56:28 +0000 | [diff] [blame] | 24 | #include "lldb/Utility/Log.h" |
Zachary Turner | bf9a773 | 2017-02-02 21:39:50 +0000 | [diff] [blame] | 25 | #include "lldb/Utility/RegularExpression.h" |
Pavel Labath | 38d0632 | 2017-06-29 14:32:17 +0000 | [diff] [blame] | 26 | #include "lldb/Utility/Timer.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 27 | #include "lldb/lldb-private.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 28 | |
| 29 | using namespace lldb; |
| 30 | using namespace lldb_private; |
| 31 | |
Greg Clayton | 762f713 | 2011-09-18 18:59:15 +0000 | [diff] [blame] | 32 | ObjectFileSP |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 33 | ObjectFile::FindPlugin(const lldb::ModuleSP &module_sp, const FileSpec *file, |
| 34 | lldb::offset_t file_offset, lldb::offset_t file_size, |
| 35 | DataBufferSP &data_sp, lldb::offset_t &data_offset) { |
| 36 | ObjectFileSP object_file_sp; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 37 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 38 | if (module_sp) { |
Pavel Labath | f9d1647 | 2017-05-15 13:02:37 +0000 | [diff] [blame] | 39 | static Timer::Category func_cat(LLVM_PRETTY_FUNCTION); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 40 | Timer scoped_timer( |
Pavel Labath | f9d1647 | 2017-05-15 13:02:37 +0000 | [diff] [blame] | 41 | func_cat, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 42 | "ObjectFile::FindPlugin (module = %s, file = %p, file_offset = " |
| 43 | "0x%8.8" PRIx64 ", file_size = 0x%8.8" PRIx64 ")", |
| 44 | module_sp->GetFileSpec().GetPath().c_str(), |
| 45 | static_cast<const void *>(file), static_cast<uint64_t>(file_offset), |
| 46 | static_cast<uint64_t>(file_size)); |
| 47 | if (file) { |
| 48 | FileSpec archive_file; |
| 49 | ObjectContainerCreateInstance create_object_container_callback; |
Greg Clayton | 5ce9c56 | 2013-02-06 17:22:03 +0000 | [diff] [blame] | 50 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 51 | const bool file_exists = file->Exists(); |
| 52 | if (!data_sp) { |
| 53 | // We have an object name which most likely means we have |
| 54 | // a .o file in a static archive (.a file). Try and see if |
| 55 | // we have a cached archive first without reading any data |
| 56 | // first |
| 57 | if (file_exists && module_sp->GetObjectName()) { |
| 58 | for (uint32_t idx = 0; |
| 59 | (create_object_container_callback = |
| 60 | PluginManager::GetObjectContainerCreateCallbackAtIndex( |
| 61 | idx)) != nullptr; |
| 62 | ++idx) { |
| 63 | std::unique_ptr<ObjectContainer> object_container_ap( |
| 64 | create_object_container_callback(module_sp, data_sp, |
| 65 | data_offset, file, file_offset, |
| 66 | file_size)); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 67 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 68 | if (object_container_ap.get()) |
| 69 | object_file_sp = object_container_ap->GetObjectFile(file); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 70 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 71 | if (object_file_sp.get()) |
| 72 | return object_file_sp; |
| 73 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 74 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 75 | // Ok, we didn't find any containers that have a named object, now |
| 76 | // lets read the first 512 bytes from the file so the object file |
| 77 | // and object container plug-ins can use these bytes to see if they |
| 78 | // can parse this file. |
| 79 | if (file_size > 0) { |
Zachary Turner | 7f6a7a3 | 2017-03-06 23:42:14 +0000 | [diff] [blame] | 80 | data_sp = |
| 81 | DataBufferLLVM::CreateSliceFromPath(file->GetPath(), 512, file_offset); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 82 | data_offset = 0; |
| 83 | } |
| 84 | } |
Greg Clayton | 762f713 | 2011-09-18 18:59:15 +0000 | [diff] [blame] | 85 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 86 | if (!data_sp || data_sp->GetByteSize() == 0) { |
| 87 | // Check for archive file with format "/path/to/archive.a(object.o)" |
| 88 | char path_with_object[PATH_MAX * 2]; |
| 89 | module_sp->GetFileSpec().GetPath(path_with_object, |
| 90 | sizeof(path_with_object)); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 91 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 92 | ConstString archive_object; |
| 93 | const bool must_exist = true; |
| 94 | if (ObjectFile::SplitArchivePathWithObject( |
| 95 | path_with_object, archive_file, archive_object, must_exist)) { |
| 96 | file_size = archive_file.GetByteSize(); |
| 97 | if (file_size > 0) { |
| 98 | file = &archive_file; |
| 99 | module_sp->SetFileSpecAndObjectName(archive_file, archive_object); |
| 100 | // Check if this is a object container by iterating through all |
| 101 | // object |
| 102 | // container plugin instances and then trying to get an object file |
| 103 | // from the container plugins since we had a name. Also, don't read |
| 104 | // ANY data in case there is data cached in the container plug-ins |
| 105 | // (like BSD archives caching the contained objects within an file). |
| 106 | for (uint32_t idx = 0; |
| 107 | (create_object_container_callback = |
| 108 | PluginManager::GetObjectContainerCreateCallbackAtIndex( |
| 109 | idx)) != nullptr; |
| 110 | ++idx) { |
| 111 | std::unique_ptr<ObjectContainer> object_container_ap( |
| 112 | create_object_container_callback(module_sp, data_sp, |
| 113 | data_offset, file, |
| 114 | file_offset, file_size)); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 115 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 116 | if (object_container_ap.get()) |
| 117 | object_file_sp = object_container_ap->GetObjectFile(file); |
| 118 | |
| 119 | if (object_file_sp.get()) |
| 120 | return object_file_sp; |
| 121 | } |
| 122 | // We failed to find any cached object files in the container |
| 123 | // plug-ins, so lets read the first 512 bytes and try again below... |
Zachary Turner | 7f6a7a3 | 2017-03-06 23:42:14 +0000 | [diff] [blame] | 124 | data_sp = DataBufferLLVM::CreateSliceFromPath(archive_file.GetPath(), |
| 125 | 512, file_offset); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 126 | } |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | if (data_sp && data_sp->GetByteSize() > 0) { |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 131 | // Check if this is a normal object file by iterating through |
| 132 | // all object file plugin instances. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 133 | ObjectFileCreateInstance create_object_file_callback; |
| 134 | for (uint32_t idx = 0; |
| 135 | (create_object_file_callback = |
| 136 | PluginManager::GetObjectFileCreateCallbackAtIndex(idx)) != |
| 137 | nullptr; |
| 138 | ++idx) { |
| 139 | object_file_sp.reset(create_object_file_callback( |
| 140 | module_sp, data_sp, data_offset, file, file_offset, file_size)); |
| 141 | if (object_file_sp.get()) |
| 142 | return object_file_sp; |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 143 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 144 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 145 | // Check if this is a object container by iterating through |
| 146 | // all object container plugin instances and then trying to get |
| 147 | // an object file from the container. |
| 148 | for (uint32_t idx = 0; |
| 149 | (create_object_container_callback = |
| 150 | PluginManager::GetObjectContainerCreateCallbackAtIndex( |
| 151 | idx)) != nullptr; |
| 152 | ++idx) { |
| 153 | std::unique_ptr<ObjectContainer> object_container_ap( |
| 154 | create_object_container_callback(module_sp, data_sp, data_offset, |
| 155 | file, file_offset, file_size)); |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 156 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 157 | if (object_container_ap.get()) |
| 158 | object_file_sp = object_container_ap->GetObjectFile(file); |
| 159 | |
| 160 | if (object_file_sp.get()) |
| 161 | return object_file_sp; |
Greg Clayton | 2540a8a | 2013-07-12 22:07:46 +0000 | [diff] [blame] | 162 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 163 | } |
Greg Clayton | 2540a8a | 2013-07-12 22:07:46 +0000 | [diff] [blame] | 164 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 165 | } |
| 166 | // We didn't find it, so clear our shared pointer in case it |
| 167 | // contains anything and return an empty shared pointer |
| 168 | object_file_sp.reset(); |
| 169 | return object_file_sp; |
Greg Clayton | f4d6de6 | 2013-04-24 22:29:28 +0000 | [diff] [blame] | 170 | } |
| 171 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 172 | ObjectFileSP ObjectFile::FindPlugin(const lldb::ModuleSP &module_sp, |
| 173 | const ProcessSP &process_sp, |
| 174 | lldb::addr_t header_addr, |
| 175 | DataBufferSP &data_sp) { |
| 176 | ObjectFileSP object_file_sp; |
| 177 | |
| 178 | if (module_sp) { |
Pavel Labath | f9d1647 | 2017-05-15 13:02:37 +0000 | [diff] [blame] | 179 | static Timer::Category func_cat(LLVM_PRETTY_FUNCTION); |
| 180 | Timer scoped_timer(func_cat, |
| 181 | "ObjectFile::FindPlugin (module = " |
| 182 | "%s, process = %p, header_addr = " |
| 183 | "0x%" PRIx64 ")", |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 184 | module_sp->GetFileSpec().GetPath().c_str(), |
| 185 | static_cast<void *>(process_sp.get()), header_addr); |
| 186 | uint32_t idx; |
| 187 | |
| 188 | // Check if this is a normal object file by iterating through |
| 189 | // all object file plugin instances. |
| 190 | ObjectFileCreateMemoryInstance create_callback; |
| 191 | for (idx = 0; |
| 192 | (create_callback = |
| 193 | PluginManager::GetObjectFileCreateMemoryCallbackAtIndex(idx)) != |
| 194 | nullptr; |
| 195 | ++idx) { |
| 196 | object_file_sp.reset( |
| 197 | create_callback(module_sp, data_sp, process_sp, header_addr)); |
| 198 | if (object_file_sp.get()) |
| 199 | return object_file_sp; |
Greg Clayton | f4d6de6 | 2013-04-24 22:29:28 +0000 | [diff] [blame] | 200 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 201 | } |
Greg Clayton | f4d6de6 | 2013-04-24 22:29:28 +0000 | [diff] [blame] | 202 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 203 | // We didn't find it, so clear our shared pointer in case it |
| 204 | // contains anything and return an empty shared pointer |
| 205 | object_file_sp.reset(); |
| 206 | return object_file_sp; |
| 207 | } |
| 208 | |
| 209 | size_t ObjectFile::GetModuleSpecifications(const FileSpec &file, |
| 210 | lldb::offset_t file_offset, |
| 211 | lldb::offset_t file_size, |
| 212 | ModuleSpecList &specs) { |
Zachary Turner | 7f6a7a3 | 2017-03-06 23:42:14 +0000 | [diff] [blame] | 213 | DataBufferSP data_sp = DataBufferLLVM::CreateSliceFromPath(file.GetPath(), 512, file_offset); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 214 | if (data_sp) { |
| 215 | if (file_size == 0) { |
| 216 | const lldb::offset_t actual_file_size = file.GetByteSize(); |
| 217 | if (actual_file_size > file_offset) |
| 218 | file_size = actual_file_size - file_offset; |
Greg Clayton | f4d6de6 | 2013-04-24 22:29:28 +0000 | [diff] [blame] | 219 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 220 | return ObjectFile::GetModuleSpecifications(file, // file spec |
| 221 | data_sp, // data bytes |
| 222 | 0, // data offset |
| 223 | file_offset, // file offset |
| 224 | file_size, // file length |
| 225 | specs); |
| 226 | } |
| 227 | return 0; |
Greg Clayton | f4d6de6 | 2013-04-24 22:29:28 +0000 | [diff] [blame] | 228 | } |
| 229 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 230 | size_t ObjectFile::GetModuleSpecifications( |
| 231 | const lldb_private::FileSpec &file, lldb::DataBufferSP &data_sp, |
| 232 | lldb::offset_t data_offset, lldb::offset_t file_offset, |
| 233 | lldb::offset_t file_size, lldb_private::ModuleSpecList &specs) { |
| 234 | const size_t initial_count = specs.GetSize(); |
| 235 | ObjectFileGetModuleSpecifications callback; |
| 236 | uint32_t i; |
| 237 | // Try the ObjectFile plug-ins |
| 238 | for (i = 0; |
| 239 | (callback = |
| 240 | PluginManager::GetObjectFileGetModuleSpecificationsCallbackAtIndex( |
| 241 | i)) != nullptr; |
| 242 | ++i) { |
| 243 | if (callback(file, data_sp, data_offset, file_offset, file_size, specs) > 0) |
| 244 | return specs.GetSize() - initial_count; |
| 245 | } |
| 246 | |
| 247 | // Try the ObjectContainer plug-ins |
| 248 | for (i = 0; |
| 249 | (callback = PluginManager:: |
| 250 | GetObjectContainerGetModuleSpecificationsCallbackAtIndex(i)) != |
| 251 | nullptr; |
| 252 | ++i) { |
| 253 | if (callback(file, data_sp, data_offset, file_offset, file_size, specs) > 0) |
| 254 | return specs.GetSize() - initial_count; |
| 255 | } |
| 256 | return 0; |
Greg Clayton | 762f713 | 2011-09-18 18:59:15 +0000 | [diff] [blame] | 257 | } |
| 258 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 259 | ObjectFile::ObjectFile(const lldb::ModuleSP &module_sp, |
| 260 | const FileSpec *file_spec_ptr, |
| 261 | lldb::offset_t file_offset, lldb::offset_t length, |
| 262 | const lldb::DataBufferSP &data_sp, |
| 263 | lldb::offset_t data_offset) |
| 264 | : ModuleChild(module_sp), |
| 265 | m_file(), // This file could be different from the original module's file |
| 266 | m_type(eTypeInvalid), m_strata(eStrataInvalid), |
| 267 | m_file_offset(file_offset), m_length(length), m_data(), |
| 268 | m_unwind_table(*this), m_process_wp(), |
| 269 | m_memory_addr(LLDB_INVALID_ADDRESS), m_sections_ap(), m_symtab_ap(), |
| 270 | m_synthetic_symbol_idx(0) { |
| 271 | if (file_spec_ptr) |
| 272 | m_file = *file_spec_ptr; |
| 273 | if (data_sp) |
| 274 | m_data.SetData(data_sp, data_offset, length); |
| 275 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OBJECT)); |
| 276 | if (log) |
| 277 | log->Printf("%p ObjectFile::ObjectFile() module = %p (%s), file = %s, " |
| 278 | "file_offset = 0x%8.8" PRIx64 ", size = %" PRIu64, |
| 279 | static_cast<void *>(this), static_cast<void *>(module_sp.get()), |
| 280 | module_sp->GetSpecificationDescription().c_str(), |
| 281 | m_file ? m_file.GetPath().c_str() : "<NULL>", m_file_offset, |
| 282 | m_length); |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 283 | } |
| 284 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 285 | ObjectFile::ObjectFile(const lldb::ModuleSP &module_sp, |
| 286 | const ProcessSP &process_sp, lldb::addr_t header_addr, |
| 287 | DataBufferSP &header_data_sp) |
| 288 | : ModuleChild(module_sp), m_file(), m_type(eTypeInvalid), |
| 289 | m_strata(eStrataInvalid), m_file_offset(0), m_length(0), m_data(), |
| 290 | m_unwind_table(*this), m_process_wp(process_sp), |
| 291 | m_memory_addr(header_addr), m_sections_ap(), m_symtab_ap(), |
| 292 | m_synthetic_symbol_idx(0) { |
| 293 | if (header_data_sp) |
| 294 | m_data.SetData(header_data_sp, 0, header_data_sp->GetByteSize()); |
| 295 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OBJECT)); |
| 296 | if (log) |
| 297 | log->Printf("%p ObjectFile::ObjectFile() module = %p (%s), process = %p, " |
| 298 | "header_addr = 0x%" PRIx64, |
| 299 | static_cast<void *>(this), static_cast<void *>(module_sp.get()), |
| 300 | module_sp->GetSpecificationDescription().c_str(), |
| 301 | static_cast<void *>(process_sp.get()), m_memory_addr); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 302 | } |
Jim Ingham | 5aee162 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 303 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 304 | ObjectFile::~ObjectFile() { |
| 305 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OBJECT)); |
| 306 | if (log) |
| 307 | log->Printf("%p ObjectFile::~ObjectFile ()\n", static_cast<void *>(this)); |
Jim Ingham | 5aee162 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 308 | } |
| 309 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 310 | bool ObjectFile::SetModulesArchitecture(const ArchSpec &new_arch) { |
| 311 | ModuleSP module_sp(GetModule()); |
| 312 | if (module_sp) |
| 313 | return module_sp->SetArchitecture(new_arch); |
| 314 | return false; |
| 315 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 316 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 317 | AddressClass ObjectFile::GetAddressClass(addr_t file_addr) { |
| 318 | Symtab *symtab = GetSymtab(); |
| 319 | if (symtab) { |
| 320 | Symbol *symbol = symtab->FindSymbolContainingFileAddress(file_addr); |
| 321 | if (symbol) { |
| 322 | if (symbol->ValueIsAddress()) { |
| 323 | const SectionSP section_sp(symbol->GetAddressRef().GetSection()); |
| 324 | if (section_sp) { |
| 325 | const SectionType section_type = section_sp->GetType(); |
| 326 | switch (section_type) { |
| 327 | case eSectionTypeInvalid: |
| 328 | return eAddressClassUnknown; |
| 329 | case eSectionTypeCode: |
| 330 | return eAddressClassCode; |
| 331 | case eSectionTypeContainer: |
| 332 | return eAddressClassUnknown; |
| 333 | case eSectionTypeData: |
| 334 | case eSectionTypeDataCString: |
| 335 | case eSectionTypeDataCStringPointers: |
| 336 | case eSectionTypeDataSymbolAddress: |
| 337 | case eSectionTypeData4: |
| 338 | case eSectionTypeData8: |
| 339 | case eSectionTypeData16: |
| 340 | case eSectionTypeDataPointers: |
| 341 | case eSectionTypeZeroFill: |
| 342 | case eSectionTypeDataObjCMessageRefs: |
| 343 | case eSectionTypeDataObjCCFStrings: |
| 344 | case eSectionTypeGoSymtab: |
| 345 | return eAddressClassData; |
| 346 | case eSectionTypeDebug: |
| 347 | case eSectionTypeDWARFDebugAbbrev: |
| 348 | case eSectionTypeDWARFDebugAddr: |
| 349 | case eSectionTypeDWARFDebugAranges: |
Tamas Berghammer | 963ce48 | 2017-08-25 13:56:14 +0000 | [diff] [blame] | 350 | case eSectionTypeDWARFDebugCuIndex: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 351 | case eSectionTypeDWARFDebugFrame: |
| 352 | case eSectionTypeDWARFDebugInfo: |
| 353 | case eSectionTypeDWARFDebugLine: |
| 354 | case eSectionTypeDWARFDebugLoc: |
| 355 | case eSectionTypeDWARFDebugMacInfo: |
| 356 | case eSectionTypeDWARFDebugMacro: |
| 357 | case eSectionTypeDWARFDebugPubNames: |
| 358 | case eSectionTypeDWARFDebugPubTypes: |
| 359 | case eSectionTypeDWARFDebugRanges: |
| 360 | case eSectionTypeDWARFDebugStr: |
| 361 | case eSectionTypeDWARFDebugStrOffsets: |
| 362 | case eSectionTypeDWARFAppleNames: |
| 363 | case eSectionTypeDWARFAppleTypes: |
| 364 | case eSectionTypeDWARFAppleNamespaces: |
| 365 | case eSectionTypeDWARFAppleObjC: |
Jan Kratochvil | e4777a9 | 2018-04-29 19:47:48 +0000 | [diff] [blame^] | 366 | case eSectionTypeDWARFGNUDebugAltLink: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 367 | return eAddressClassDebug; |
| 368 | case eSectionTypeEHFrame: |
| 369 | case eSectionTypeARMexidx: |
| 370 | case eSectionTypeARMextab: |
| 371 | case eSectionTypeCompactUnwind: |
| 372 | return eAddressClassRuntime; |
| 373 | case eSectionTypeELFSymbolTable: |
| 374 | case eSectionTypeELFDynamicSymbols: |
| 375 | case eSectionTypeELFRelocationEntries: |
| 376 | case eSectionTypeELFDynamicLinkInfo: |
| 377 | case eSectionTypeOther: |
| 378 | return eAddressClassUnknown; |
| 379 | case eSectionTypeAbsoluteAddress: |
| 380 | // In case of absolute sections decide the address class based on |
| 381 | // the symbol |
| 382 | // type because the section type isn't specify if it is a code or a |
| 383 | // data |
| 384 | // section. |
| 385 | break; |
| 386 | } |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 387 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 388 | } |
| 389 | |
| 390 | const SymbolType symbol_type = symbol->GetType(); |
| 391 | switch (symbol_type) { |
| 392 | case eSymbolTypeAny: |
| 393 | return eAddressClassUnknown; |
| 394 | case eSymbolTypeAbsolute: |
| 395 | return eAddressClassUnknown; |
| 396 | case eSymbolTypeCode: |
| 397 | return eAddressClassCode; |
| 398 | case eSymbolTypeTrampoline: |
| 399 | return eAddressClassCode; |
| 400 | case eSymbolTypeResolver: |
| 401 | return eAddressClassCode; |
| 402 | case eSymbolTypeData: |
| 403 | return eAddressClassData; |
| 404 | case eSymbolTypeRuntime: |
| 405 | return eAddressClassRuntime; |
| 406 | case eSymbolTypeException: |
| 407 | return eAddressClassRuntime; |
| 408 | case eSymbolTypeSourceFile: |
| 409 | return eAddressClassDebug; |
| 410 | case eSymbolTypeHeaderFile: |
| 411 | return eAddressClassDebug; |
| 412 | case eSymbolTypeObjectFile: |
| 413 | return eAddressClassDebug; |
| 414 | case eSymbolTypeCommonBlock: |
| 415 | return eAddressClassDebug; |
| 416 | case eSymbolTypeBlock: |
| 417 | return eAddressClassDebug; |
| 418 | case eSymbolTypeLocal: |
| 419 | return eAddressClassData; |
| 420 | case eSymbolTypeParam: |
| 421 | return eAddressClassData; |
| 422 | case eSymbolTypeVariable: |
| 423 | return eAddressClassData; |
| 424 | case eSymbolTypeVariableType: |
| 425 | return eAddressClassDebug; |
| 426 | case eSymbolTypeLineEntry: |
| 427 | return eAddressClassDebug; |
| 428 | case eSymbolTypeLineHeader: |
| 429 | return eAddressClassDebug; |
| 430 | case eSymbolTypeScopeBegin: |
| 431 | return eAddressClassDebug; |
| 432 | case eSymbolTypeScopeEnd: |
| 433 | return eAddressClassDebug; |
| 434 | case eSymbolTypeAdditional: |
| 435 | return eAddressClassUnknown; |
| 436 | case eSymbolTypeCompiler: |
| 437 | return eAddressClassDebug; |
| 438 | case eSymbolTypeInstrumentation: |
| 439 | return eAddressClassDebug; |
| 440 | case eSymbolTypeUndefined: |
| 441 | return eAddressClassUnknown; |
| 442 | case eSymbolTypeObjCClass: |
| 443 | return eAddressClassRuntime; |
| 444 | case eSymbolTypeObjCMetaClass: |
| 445 | return eAddressClassRuntime; |
| 446 | case eSymbolTypeObjCIVar: |
| 447 | return eAddressClassRuntime; |
| 448 | case eSymbolTypeReExported: |
| 449 | return eAddressClassRuntime; |
| 450 | } |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 451 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 452 | } |
| 453 | return eAddressClassUnknown; |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 454 | } |
| 455 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 456 | DataBufferSP ObjectFile::ReadMemory(const ProcessSP &process_sp, |
| 457 | lldb::addr_t addr, size_t byte_size) { |
| 458 | DataBufferSP data_sp; |
| 459 | if (process_sp) { |
| 460 | std::unique_ptr<DataBufferHeap> data_ap(new DataBufferHeap(byte_size, 0)); |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 461 | Status error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 462 | const size_t bytes_read = process_sp->ReadMemory( |
| 463 | addr, data_ap->GetBytes(), data_ap->GetByteSize(), error); |
| 464 | if (bytes_read == byte_size) |
| 465 | data_sp.reset(data_ap.release()); |
| 466 | } |
| 467 | return data_sp; |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 468 | } |
| 469 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 470 | size_t ObjectFile::GetData(lldb::offset_t offset, size_t length, |
| 471 | DataExtractor &data) const { |
| 472 | // The entire file has already been mmap'ed into m_data, so just copy from |
| 473 | // there |
| 474 | // as the back mmap buffer will be shared with shared pointers. |
| 475 | return data.SetData(m_data, offset, length); |
Greg Clayton | 44435ed | 2012-01-12 05:25:17 +0000 | [diff] [blame] | 476 | } |
| 477 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 478 | size_t ObjectFile::CopyData(lldb::offset_t offset, size_t length, |
| 479 | void *dst) const { |
| 480 | // The entire file has already been mmap'ed into m_data, so just copy from |
| 481 | // there |
| 482 | // Note that the data remains in target byte order. |
| 483 | return m_data.CopyData(offset, length, dst); |
Greg Clayton | 44435ed | 2012-01-12 05:25:17 +0000 | [diff] [blame] | 484 | } |
Greg Clayton | ded470d | 2011-03-19 01:12:21 +0000 | [diff] [blame] | 485 | |
Ed Maste | d13f691 | 2017-10-02 14:35:07 +0000 | [diff] [blame] | 486 | size_t ObjectFile::ReadSectionData(Section *section, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 487 | lldb::offset_t section_offset, void *dst, |
Ed Maste | d13f691 | 2017-10-02 14:35:07 +0000 | [diff] [blame] | 488 | size_t dst_len) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 489 | assert(section); |
| 490 | section_offset *= section->GetTargetByteSize(); |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 491 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 492 | // If some other objectfile owns this data, pass this to them. |
| 493 | if (section->GetObjectFile() != this) |
| 494 | return section->GetObjectFile()->ReadSectionData(section, section_offset, |
| 495 | dst, dst_len); |
Matthew Gardiner | f03e6d84 | 2014-09-29 08:02:24 +0000 | [diff] [blame] | 496 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 497 | if (IsInMemory()) { |
| 498 | ProcessSP process_sp(m_process_wp.lock()); |
| 499 | if (process_sp) { |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 500 | Status error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 501 | const addr_t base_load_addr = |
| 502 | section->GetLoadBaseAddress(&process_sp->GetTarget()); |
| 503 | if (base_load_addr != LLDB_INVALID_ADDRESS) |
| 504 | return process_sp->ReadMemory(base_load_addr + section_offset, dst, |
| 505 | dst_len, error); |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 506 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 507 | } else { |
Ed Maste | d13f691 | 2017-10-02 14:35:07 +0000 | [diff] [blame] | 508 | if (!section->IsRelocated()) |
| 509 | RelocateSection(section); |
| 510 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 511 | const lldb::offset_t section_file_size = section->GetFileSize(); |
| 512 | if (section_offset < section_file_size) { |
| 513 | const size_t section_bytes_left = section_file_size - section_offset; |
| 514 | size_t section_dst_len = dst_len; |
| 515 | if (section_dst_len > section_bytes_left) |
| 516 | section_dst_len = section_bytes_left; |
| 517 | return CopyData(section->GetFileOffset() + section_offset, |
| 518 | section_dst_len, dst); |
| 519 | } else { |
| 520 | if (section->GetType() == eSectionTypeZeroFill) { |
| 521 | const uint64_t section_size = section->GetByteSize(); |
| 522 | const uint64_t section_bytes_left = section_size - section_offset; |
| 523 | uint64_t section_dst_len = dst_len; |
| 524 | if (section_dst_len > section_bytes_left) |
| 525 | section_dst_len = section_bytes_left; |
| 526 | memset(dst, 0, section_dst_len); |
| 527 | return section_dst_len; |
| 528 | } |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 529 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 530 | } |
| 531 | return 0; |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | //---------------------------------------------------------------------- |
| 535 | // Get the section data the file on disk |
| 536 | //---------------------------------------------------------------------- |
Ed Maste | d13f691 | 2017-10-02 14:35:07 +0000 | [diff] [blame] | 537 | size_t ObjectFile::ReadSectionData(Section *section, |
| 538 | DataExtractor §ion_data) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 539 | // If some other objectfile owns this data, pass this to them. |
| 540 | if (section->GetObjectFile() != this) |
| 541 | return section->GetObjectFile()->ReadSectionData(section, section_data); |
Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 542 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 543 | if (IsInMemory()) { |
| 544 | ProcessSP process_sp(m_process_wp.lock()); |
| 545 | if (process_sp) { |
| 546 | const addr_t base_load_addr = |
| 547 | section->GetLoadBaseAddress(&process_sp->GetTarget()); |
| 548 | if (base_load_addr != LLDB_INVALID_ADDRESS) { |
| 549 | DataBufferSP data_sp( |
| 550 | ReadMemory(process_sp, base_load_addr, section->GetByteSize())); |
| 551 | if (data_sp) { |
| 552 | section_data.SetData(data_sp, 0, data_sp->GetByteSize()); |
| 553 | section_data.SetByteOrder(process_sp->GetByteOrder()); |
| 554 | section_data.SetAddressByteSize(process_sp->GetAddressByteSize()); |
| 555 | return section_data.GetByteSize(); |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 556 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 557 | } |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 558 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 559 | return GetData(section->GetFileOffset(), section->GetFileSize(), |
| 560 | section_data); |
| 561 | } else { |
| 562 | // The object file now contains a full mmap'ed copy of the object file data, |
| 563 | // so just use this |
Ed Maste | d13f691 | 2017-10-02 14:35:07 +0000 | [diff] [blame] | 564 | if (!section->IsRelocated()) |
| 565 | RelocateSection(section); |
| 566 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 567 | return GetData(section->GetFileOffset(), section->GetFileSize(), |
| 568 | section_data); |
| 569 | } |
Greg Clayton | c966054 | 2012-02-05 02:38:54 +0000 | [diff] [blame] | 570 | } |
| 571 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 572 | bool ObjectFile::SplitArchivePathWithObject(const char *path_with_object, |
| 573 | FileSpec &archive_file, |
| 574 | ConstString &archive_object, |
| 575 | bool must_exist) { |
Zachary Turner | 95eae42 | 2016-09-21 16:01:28 +0000 | [diff] [blame] | 576 | RegularExpression g_object_regex(llvm::StringRef("(.*)\\(([^\\)]+)\\)$")); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 577 | RegularExpression::Match regex_match(2); |
Zachary Turner | 95eae42 | 2016-09-21 16:01:28 +0000 | [diff] [blame] | 578 | if (g_object_regex.Execute(llvm::StringRef::withNullAsEmpty(path_with_object), |
| 579 | ®ex_match)) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 580 | std::string path; |
| 581 | std::string obj; |
| 582 | if (regex_match.GetMatchAtIndex(path_with_object, 1, path) && |
| 583 | regex_match.GetMatchAtIndex(path_with_object, 2, obj)) { |
Malcolm Parsons | 771ef6d | 2016-11-02 20:34:10 +0000 | [diff] [blame] | 584 | archive_file.SetFile(path, false); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 585 | archive_object.SetCString(obj.c_str()); |
| 586 | if (must_exist && !archive_file.Exists()) |
| 587 | return false; |
| 588 | return true; |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 589 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 590 | } |
| 591 | return false; |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 592 | } |
| 593 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 594 | void ObjectFile::ClearSymtab() { |
| 595 | ModuleSP module_sp(GetModule()); |
| 596 | if (module_sp) { |
| 597 | std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); |
| 598 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OBJECT)); |
| 599 | if (log) |
| 600 | log->Printf("%p ObjectFile::ClearSymtab () symtab = %p", |
| 601 | static_cast<void *>(this), |
| 602 | static_cast<void *>(m_symtab_ap.get())); |
| 603 | m_symtab_ap.reset(); |
| 604 | } |
| 605 | } |
| 606 | |
| 607 | SectionList *ObjectFile::GetSectionList(bool update_module_section_list) { |
| 608 | if (m_sections_ap.get() == nullptr) { |
| 609 | if (update_module_section_list) { |
| 610 | ModuleSP module_sp(GetModule()); |
| 611 | if (module_sp) { |
Saleem Abdulrasool | 16ff860 | 2016-05-18 01:59:10 +0000 | [diff] [blame] | 612 | std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 613 | CreateSections(*module_sp->GetUnifiedSectionList()); |
| 614 | } |
| 615 | } else { |
| 616 | SectionList unified_section_list; |
| 617 | CreateSections(unified_section_list); |
Greg Clayton | 9422dd6 | 2013-03-04 21:46:16 +0000 | [diff] [blame] | 618 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 619 | } |
| 620 | return m_sections_ap.get(); |
Greg Clayton | 3046e66 | 2013-07-10 01:23:25 +0000 | [diff] [blame] | 621 | } |
Jason Molenda | 649a607 | 2015-11-10 05:21:54 +0000 | [diff] [blame] | 622 | |
| 623 | lldb::SymbolType |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 624 | ObjectFile::GetSymbolTypeFromName(llvm::StringRef name, |
| 625 | lldb::SymbolType symbol_type_hint) { |
| 626 | if (!name.empty()) { |
| 627 | if (name.startswith("_OBJC_")) { |
| 628 | // ObjC |
| 629 | if (name.startswith("_OBJC_CLASS_$_")) |
| 630 | return lldb::eSymbolTypeObjCClass; |
| 631 | if (name.startswith("_OBJC_METACLASS_$_")) |
| 632 | return lldb::eSymbolTypeObjCMetaClass; |
| 633 | if (name.startswith("_OBJC_IVAR_$_")) |
| 634 | return lldb::eSymbolTypeObjCIVar; |
| 635 | } else if (name.startswith(".objc_class_name_")) { |
| 636 | // ObjC v1 |
| 637 | return lldb::eSymbolTypeObjCClass; |
Jason Molenda | 649a607 | 2015-11-10 05:21:54 +0000 | [diff] [blame] | 638 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 639 | } |
| 640 | return symbol_type_hint; |
Jason Molenda | 649a607 | 2015-11-10 05:21:54 +0000 | [diff] [blame] | 641 | } |
Tamas Berghammer | 6b63b14 | 2016-02-18 11:12:18 +0000 | [diff] [blame] | 642 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 643 | ConstString ObjectFile::GetNextSyntheticSymbolName() { |
| 644 | StreamString ss; |
| 645 | ConstString file_name = GetModule()->GetFileSpec().GetFilename(); |
| 646 | ss.Printf("___lldb_unnamed_symbol%u$$%s", ++m_synthetic_symbol_idx, |
| 647 | file_name.GetCString()); |
Zachary Turner | c156427 | 2016-11-16 21:15:24 +0000 | [diff] [blame] | 648 | return ConstString(ss.GetString()); |
Tamas Berghammer | 6b63b14 | 2016-02-18 11:12:18 +0000 | [diff] [blame] | 649 | } |
Hafiz Abid Qadeer | 4687db0 | 2017-01-19 17:32:50 +0000 | [diff] [blame] | 650 | |
Pavel Labath | 16064d3 | 2018-03-20 11:56:24 +0000 | [diff] [blame] | 651 | std::vector<ObjectFile::LoadableData> |
| 652 | ObjectFile::GetLoadableData(Target &target) { |
| 653 | std::vector<LoadableData> loadables; |
Hafiz Abid Qadeer | 4687db0 | 2017-01-19 17:32:50 +0000 | [diff] [blame] | 654 | SectionList *section_list = GetSectionList(); |
| 655 | if (!section_list) |
Pavel Labath | 16064d3 | 2018-03-20 11:56:24 +0000 | [diff] [blame] | 656 | return loadables; |
| 657 | // Create a list of loadable data from loadable sections |
Hafiz Abid Qadeer | 4687db0 | 2017-01-19 17:32:50 +0000 | [diff] [blame] | 658 | size_t section_count = section_list->GetNumSections(0); |
| 659 | for (size_t i = 0; i < section_count; ++i) { |
Pavel Labath | 16064d3 | 2018-03-20 11:56:24 +0000 | [diff] [blame] | 660 | LoadableData loadable; |
Hafiz Abid Qadeer | 4687db0 | 2017-01-19 17:32:50 +0000 | [diff] [blame] | 661 | SectionSP section_sp = section_list->GetSectionAtIndex(i); |
Pavel Labath | 16064d3 | 2018-03-20 11:56:24 +0000 | [diff] [blame] | 662 | loadable.Dest = |
| 663 | target.GetSectionLoadList().GetSectionLoadAddress(section_sp); |
| 664 | if (loadable.Dest == LLDB_INVALID_ADDRESS) |
| 665 | continue; |
| 666 | // We can skip sections like bss |
| 667 | if (section_sp->GetFileSize() == 0) |
| 668 | continue; |
| 669 | DataExtractor section_data; |
| 670 | section_sp->GetSectionData(section_data); |
| 671 | loadable.Contents = llvm::ArrayRef<uint8_t>(section_data.GetDataStart(), |
| 672 | section_data.GetByteSize()); |
| 673 | loadables.push_back(loadable); |
Hafiz Abid Qadeer | 4687db0 | 2017-01-19 17:32:50 +0000 | [diff] [blame] | 674 | } |
Pavel Labath | 16064d3 | 2018-03-20 11:56:24 +0000 | [diff] [blame] | 675 | return loadables; |
Hafiz Abid Qadeer | 4687db0 | 2017-01-19 17:32:50 +0000 | [diff] [blame] | 676 | } |
Ed Maste | d13f691 | 2017-10-02 14:35:07 +0000 | [diff] [blame] | 677 | |
| 678 | void ObjectFile::RelocateSection(lldb_private::Section *section) |
| 679 | { |
| 680 | } |
Pavel Labath | 50251fc | 2017-12-21 10:54:30 +0000 | [diff] [blame] | 681 | |
| 682 | DataBufferSP ObjectFile::MapFileData(const FileSpec &file, uint64_t Size, |
| 683 | uint64_t Offset) { |
| 684 | return DataBufferLLVM::CreateSliceFromPath(file.GetPath(), Size, Offset); |
| 685 | } |