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