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