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