ObjectFile.cpp revision 00af72e395d138f459192b7f5450fa4c7854f135
124943d2ee8bfaa7cf5893e4709143924157a5c1eChris Lattner//===-- ObjectFile.cpp ------------------------------------------*- C++ -*-===// 224943d2ee8bfaa7cf5893e4709143924157a5c1eChris Lattner// 324943d2ee8bfaa7cf5893e4709143924157a5c1eChris Lattner// The LLVM Compiler Infrastructure 424943d2ee8bfaa7cf5893e4709143924157a5c1eChris Lattner// 524943d2ee8bfaa7cf5893e4709143924157a5c1eChris Lattner// This file is distributed under the University of Illinois Open Source 624943d2ee8bfaa7cf5893e4709143924157a5c1eChris Lattner// License. See LICENSE.TXT for details. 724943d2ee8bfaa7cf5893e4709143924157a5c1eChris Lattner// 824943d2ee8bfaa7cf5893e4709143924157a5c1eChris Lattner//===----------------------------------------------------------------------===// 924943d2ee8bfaa7cf5893e4709143924157a5c1eChris Lattner 1024943d2ee8bfaa7cf5893e4709143924157a5c1eChris Lattner#include "lldb/lldb-private.h" 11e40b6424d9e49306392bec4b44060da36414c382Greg Clayton#include "lldb/lldb-private-log.h" 12db2dc2b824b61ef7578dc8cdad7b338aa82b1f17Greg Clayton#include "lldb/Core/DataBuffer.h" 13b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton#include "lldb/Core/DataBufferHeap.h" 14e40b6424d9e49306392bec4b44060da36414c382Greg Clayton#include "lldb/Core/Log.h" 1524943d2ee8bfaa7cf5893e4709143924157a5c1eChris Lattner#include "lldb/Core/Module.h" 1624943d2ee8bfaa7cf5893e4709143924157a5c1eChris Lattner#include "lldb/Core/PluginManager.h" 1724943d2ee8bfaa7cf5893e4709143924157a5c1eChris Lattner#include "lldb/Core/RegularExpression.h" 1849ce8969d3154e1560106cfe530444c09410f217Greg Clayton#include "lldb/Core/Section.h" 1924943d2ee8bfaa7cf5893e4709143924157a5c1eChris Lattner#include "lldb/Core/Timer.h" 2024943d2ee8bfaa7cf5893e4709143924157a5c1eChris Lattner#include "lldb/Symbol/ObjectFile.h" 2124943d2ee8bfaa7cf5893e4709143924157a5c1eChris Lattner#include "lldb/Symbol/ObjectContainer.h" 2224943d2ee8bfaa7cf5893e4709143924157a5c1eChris Lattner#include "lldb/Symbol/SymbolFile.h" 23b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton#include "lldb/Target/Process.h" 2449ce8969d3154e1560106cfe530444c09410f217Greg Clayton#include "Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.h" 2524943d2ee8bfaa7cf5893e4709143924157a5c1eChris Lattner 2624943d2ee8bfaa7cf5893e4709143924157a5c1eChris Lattnerusing namespace lldb; 2724943d2ee8bfaa7cf5893e4709143924157a5c1eChris Lattnerusing namespace lldb_private; 2824943d2ee8bfaa7cf5893e4709143924157a5c1eChris Lattner 29e40b6424d9e49306392bec4b44060da36414c382Greg ClaytonObjectFileSP 30cbe61bd26db663fa3036866dc33315c6ffc37910Greg ClaytonObjectFile::FindPlugin (const lldb::ModuleSP &module_sp, 31cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton const FileSpec* file, 32cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton lldb::offset_t file_offset, 33cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton lldb::offset_t file_size, 34cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton DataBufferSP &data_sp, 35cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton lldb::offset_t &data_offset) 3624943d2ee8bfaa7cf5893e4709143924157a5c1eChris Lattner{ 37e40b6424d9e49306392bec4b44060da36414c382Greg Clayton ObjectFileSP object_file_sp; 3824943d2ee8bfaa7cf5893e4709143924157a5c1eChris Lattner 393508c387c3f0c9ecc439d98048fd7694d41bab1bGreg Clayton if (module_sp) 4024943d2ee8bfaa7cf5893e4709143924157a5c1eChris Lattner { 413508c387c3f0c9ecc439d98048fd7694d41bab1bGreg Clayton Timer scoped_timer (__PRETTY_FUNCTION__, 425f35a4be95aed0e5b2cb36f7d785bcbfc67284aeDaniel Malea "ObjectFile::FindPlugin (module = %s/%s, file = %p, file_offset = 0x%8.8" PRIx64 ", file_size = 0x%8.8" PRIx64 ")", 433508c387c3f0c9ecc439d98048fd7694d41bab1bGreg Clayton module_sp->GetFileSpec().GetDirectory().AsCString(), 443508c387c3f0c9ecc439d98048fd7694d41bab1bGreg Clayton module_sp->GetFileSpec().GetFilename().AsCString(), 45ef9eb809246491a7a9db1f2bd35d854924525ba6Jason Molenda file, (uint64_t) file_offset, (uint64_t) file_size); 4624943d2ee8bfaa7cf5893e4709143924157a5c1eChris Lattner if (file) 4724943d2ee8bfaa7cf5893e4709143924157a5c1eChris Lattner { 48cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton FileSpec archive_file; 49cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton ObjectContainerCreateInstance create_object_container_callback; 50cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton 51cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton const bool file_exists = file->Exists(); 52cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton if (!data_sp) 53db2dc2b824b61ef7578dc8cdad7b338aa82b1f17Greg Clayton { 54cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton // We have an object name which most likely means we have 55cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton // a .o file in a static archive (.a file). Try and see if 56cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton // we have a cached archive first without reading any data 57cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton // first 58cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton if (file_exists && module_sp->GetObjectName()) 59cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton { 60cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton for (uint32_t idx = 0; (create_object_container_callback = PluginManager::GetObjectContainerCreateCallbackAtIndex(idx)) != NULL; ++idx) 61cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton { 62cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton std::auto_ptr<ObjectContainer> object_container_ap(create_object_container_callback(module_sp, data_sp, data_offset, file, file_offset, file_size)); 63cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton 64cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton if (object_container_ap.get()) 65cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton object_file_sp = object_container_ap->GetObjectFile(file); 66cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton 67cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton if (object_file_sp.get()) 68cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton return object_file_sp; 69cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton } 70cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton } 71cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton // Ok, we didn't find any containers that have a named object, now 72cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton // lets read the first 512 bytes from the file so the object file 73cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton // and object container plug-ins can use these bytes to see if they 74cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton // can parse this file. 75cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton if (file_size > 0) 76cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton { 77cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton data_sp = file->ReadFileContents(file_offset, std::min<size_t>(512, file_size)); 78cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton data_offset = 0; 79cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton } 80db2dc2b824b61ef7578dc8cdad7b338aa82b1f17Greg Clayton } 8124943d2ee8bfaa7cf5893e4709143924157a5c1eChris Lattner 82cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton if (!data_sp || data_sp->GetByteSize() == 0) 8324943d2ee8bfaa7cf5893e4709143924157a5c1eChris Lattner { 8424943d2ee8bfaa7cf5893e4709143924157a5c1eChris Lattner // Check for archive file with format "/path/to/archive.a(object.o)" 8524943d2ee8bfaa7cf5893e4709143924157a5c1eChris Lattner char path_with_object[PATH_MAX*2]; 863508c387c3f0c9ecc439d98048fd7694d41bab1bGreg Clayton module_sp->GetFileSpec().GetPath(path_with_object, sizeof(path_with_object)); 8724943d2ee8bfaa7cf5893e4709143924157a5c1eChris Lattner 8849ce8969d3154e1560106cfe530444c09410f217Greg Clayton ConstString archive_object; 893cf7ab5462467121b4ac6cde09ee994030dad0c5Greg Clayton const bool must_exist = true; 903cf7ab5462467121b4ac6cde09ee994030dad0c5Greg Clayton if (ObjectFile::SplitArchivePathWithObject (path_with_object, archive_file, archive_object, must_exist)) 9124943d2ee8bfaa7cf5893e4709143924157a5c1eChris Lattner { 9249ce8969d3154e1560106cfe530444c09410f217Greg Clayton file_size = archive_file.GetByteSize(); 9349ce8969d3154e1560106cfe530444c09410f217Greg Clayton if (file_size > 0) 9424943d2ee8bfaa7cf5893e4709143924157a5c1eChris Lattner { 95cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton file = &archive_file; 9649ce8969d3154e1560106cfe530444c09410f217Greg Clayton module_sp->SetFileSpecAndObjectName (archive_file, archive_object); 97cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton // Check if this is a object container by iterating through all object 98cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton // container plugin instances and then trying to get an object file 99cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton // from the container plugins since we had a name. Also, don't read 100cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton // ANY data in case there is data cached in the container plug-ins 101cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton // (like BSD archives caching the contained objects within an file). 102cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton for (uint32_t idx = 0; (create_object_container_callback = PluginManager::GetObjectContainerCreateCallbackAtIndex(idx)) != NULL; ++idx) 103cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton { 104cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton std::auto_ptr<ObjectContainer> object_container_ap(create_object_container_callback(module_sp, data_sp, data_offset, file, file_offset, file_size)); 105cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton 106cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton if (object_container_ap.get()) 107cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton object_file_sp = object_container_ap->GetObjectFile(file); 108cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton 109cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton if (object_file_sp.get()) 110cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton return object_file_sp; 111cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton } 112cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton // We failed to find any cached object files in the container 113cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton // plug-ins, so lets read the first 512 bytes and try again below... 114cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton data_sp = archive_file.ReadFileContents(file_offset, 512); 11524943d2ee8bfaa7cf5893e4709143924157a5c1eChris Lattner } 11624943d2ee8bfaa7cf5893e4709143924157a5c1eChris Lattner } 11724943d2ee8bfaa7cf5893e4709143924157a5c1eChris Lattner } 11824943d2ee8bfaa7cf5893e4709143924157a5c1eChris Lattner 119cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton if (data_sp && data_sp->GetByteSize() > 0) 12024943d2ee8bfaa7cf5893e4709143924157a5c1eChris Lattner { 121db2dc2b824b61ef7578dc8cdad7b338aa82b1f17Greg Clayton // Check if this is a normal object file by iterating through 122db2dc2b824b61ef7578dc8cdad7b338aa82b1f17Greg Clayton // all object file plugin instances. 123db2dc2b824b61ef7578dc8cdad7b338aa82b1f17Greg Clayton ObjectFileCreateInstance create_object_file_callback; 124cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton for (uint32_t idx = 0; (create_object_file_callback = PluginManager::GetObjectFileCreateCallbackAtIndex(idx)) != NULL; ++idx) 125db2dc2b824b61ef7578dc8cdad7b338aa82b1f17Greg Clayton { 126cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton object_file_sp.reset (create_object_file_callback(module_sp, data_sp, data_offset, file, file_offset, file_size)); 127db2dc2b824b61ef7578dc8cdad7b338aa82b1f17Greg Clayton if (object_file_sp.get()) 128db2dc2b824b61ef7578dc8cdad7b338aa82b1f17Greg Clayton return object_file_sp; 129db2dc2b824b61ef7578dc8cdad7b338aa82b1f17Greg Clayton } 13024943d2ee8bfaa7cf5893e4709143924157a5c1eChris Lattner 131db2dc2b824b61ef7578dc8cdad7b338aa82b1f17Greg Clayton // Check if this is a object container by iterating through 132db2dc2b824b61ef7578dc8cdad7b338aa82b1f17Greg Clayton // all object container plugin instances and then trying to get 133db2dc2b824b61ef7578dc8cdad7b338aa82b1f17Greg Clayton // an object file from the container. 134cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton for (uint32_t idx = 0; (create_object_container_callback = PluginManager::GetObjectContainerCreateCallbackAtIndex(idx)) != NULL; ++idx) 135db2dc2b824b61ef7578dc8cdad7b338aa82b1f17Greg Clayton { 136cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton std::auto_ptr<ObjectContainer> object_container_ap(create_object_container_callback(module_sp, data_sp, data_offset, file, file_offset, file_size)); 137db2dc2b824b61ef7578dc8cdad7b338aa82b1f17Greg Clayton 138db2dc2b824b61ef7578dc8cdad7b338aa82b1f17Greg Clayton if (object_container_ap.get()) 139db2dc2b824b61ef7578dc8cdad7b338aa82b1f17Greg Clayton object_file_sp = object_container_ap->GetObjectFile(file); 14024943d2ee8bfaa7cf5893e4709143924157a5c1eChris Lattner 141db2dc2b824b61ef7578dc8cdad7b338aa82b1f17Greg Clayton if (object_file_sp.get()) 142db2dc2b824b61ef7578dc8cdad7b338aa82b1f17Greg Clayton return object_file_sp; 143db2dc2b824b61ef7578dc8cdad7b338aa82b1f17Greg Clayton } 14424943d2ee8bfaa7cf5893e4709143924157a5c1eChris Lattner } 14524943d2ee8bfaa7cf5893e4709143924157a5c1eChris Lattner } 14624943d2ee8bfaa7cf5893e4709143924157a5c1eChris Lattner } 147e40b6424d9e49306392bec4b44060da36414c382Greg Clayton // We didn't find it, so clear our shared pointer in case it 148e40b6424d9e49306392bec4b44060da36414c382Greg Clayton // contains anything and return an empty shared pointer 149e40b6424d9e49306392bec4b44060da36414c382Greg Clayton object_file_sp.reset(); 150e40b6424d9e49306392bec4b44060da36414c382Greg Clayton return object_file_sp; 151e40b6424d9e49306392bec4b44060da36414c382Greg Clayton} 152e40b6424d9e49306392bec4b44060da36414c382Greg Clayton 153b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg ClaytonObjectFileSP 1543508c387c3f0c9ecc439d98048fd7694d41bab1bGreg ClaytonObjectFile::FindPlugin (const lldb::ModuleSP &module_sp, 155b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton const ProcessSP &process_sp, 156b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton lldb::addr_t header_addr, 157cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton DataBufferSP &data_sp) 158b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton{ 159b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton ObjectFileSP object_file_sp; 160b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton 1613508c387c3f0c9ecc439d98048fd7694d41bab1bGreg Clayton if (module_sp) 162b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton { 1633508c387c3f0c9ecc439d98048fd7694d41bab1bGreg Clayton Timer scoped_timer (__PRETTY_FUNCTION__, 1645f35a4be95aed0e5b2cb36f7d785bcbfc67284aeDaniel Malea "ObjectFile::FindPlugin (module = %s/%s, process = %p, header_addr = 0x%" PRIx64 ")", 1653508c387c3f0c9ecc439d98048fd7694d41bab1bGreg Clayton module_sp->GetFileSpec().GetDirectory().AsCString(), 1663508c387c3f0c9ecc439d98048fd7694d41bab1bGreg Clayton module_sp->GetFileSpec().GetFilename().AsCString(), 1673508c387c3f0c9ecc439d98048fd7694d41bab1bGreg Clayton process_sp.get(), header_addr); 168b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton uint32_t idx; 169b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton 170b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton // Check if this is a normal object file by iterating through 171b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton // all object file plugin instances. 172b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton ObjectFileCreateMemoryInstance create_callback; 173b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton for (idx = 0; (create_callback = PluginManager::GetObjectFileCreateMemoryCallbackAtIndex(idx)) != NULL; ++idx) 174b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton { 175cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton object_file_sp.reset (create_callback(module_sp, data_sp, process_sp, header_addr)); 176b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton if (object_file_sp.get()) 177b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton return object_file_sp; 178b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton } 179b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton 180b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton } 181b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton // We didn't find it, so clear our shared pointer in case it 182b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton // contains anything and return an empty shared pointer 183b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton object_file_sp.reset(); 184b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton return object_file_sp; 185b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton} 186b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton 1873508c387c3f0c9ecc439d98048fd7694d41bab1bGreg ClaytonObjectFile::ObjectFile (const lldb::ModuleSP &module_sp, 188e40b6424d9e49306392bec4b44060da36414c382Greg Clayton const FileSpec *file_spec_ptr, 189cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton lldb::offset_t file_offset, 190cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton lldb::offset_t length, 191cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton lldb::DataBufferSP& data_sp, 192cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton lldb::offset_t data_offset 193cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton) : 1943508c387c3f0c9ecc439d98048fd7694d41bab1bGreg Clayton ModuleChild (module_sp), 195e40b6424d9e49306392bec4b44060da36414c382Greg Clayton m_file (), // This file could be different from the original module's file 196e40b6424d9e49306392bec4b44060da36414c382Greg Clayton m_type (eTypeInvalid), 197e40b6424d9e49306392bec4b44060da36414c382Greg Clayton m_strata (eStrataInvalid), 198cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton m_file_offset (file_offset), 199cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton m_length (length), 200db2dc2b824b61ef7578dc8cdad7b338aa82b1f17Greg Clayton m_data (), 201b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton m_unwind_table (*this), 202b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton m_process_wp(), 203464a5063bc59755cb6ec063d0b2491097302d2abGreg Clayton m_memory_addr (LLDB_INVALID_ADDRESS), 204464a5063bc59755cb6ec063d0b2491097302d2abGreg Clayton m_sections_ap (), 205464a5063bc59755cb6ec063d0b2491097302d2abGreg Clayton m_symtab_ap () 206464a5063bc59755cb6ec063d0b2491097302d2abGreg Clayton{ 207e40b6424d9e49306392bec4b44060da36414c382Greg Clayton if (file_spec_ptr) 208e40b6424d9e49306392bec4b44060da36414c382Greg Clayton m_file = *file_spec_ptr; 209cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton if (data_sp) 210cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton m_data.SetData (data_sp, data_offset, length); 211952e9dc874944fcdbbb224f3ec4fc2c859376f64Greg Clayton Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT)); 212e40b6424d9e49306392bec4b44060da36414c382Greg Clayton if (log) 213e40b6424d9e49306392bec4b44060da36414c382Greg Clayton { 214464a5063bc59755cb6ec063d0b2491097302d2abGreg Clayton const ConstString object_name (module_sp->GetObjectName()); 215e40b6424d9e49306392bec4b44060da36414c382Greg Clayton if (m_file) 216e40b6424d9e49306392bec4b44060da36414c382Greg Clayton { 217464a5063bc59755cb6ec063d0b2491097302d2abGreg Clayton log->Printf ("%p ObjectFile::ObjectFile() module = %p (%s%s%s%s), file = %s/%s, file_offset = 0x%8.8" PRIx64 ", size = %" PRIu64, 218e40b6424d9e49306392bec4b44060da36414c382Greg Clayton this, 219464a5063bc59755cb6ec063d0b2491097302d2abGreg Clayton module_sp.get(), 2203508c387c3f0c9ecc439d98048fd7694d41bab1bGreg Clayton module_sp->GetFileSpec().GetFilename().AsCString(), 221464a5063bc59755cb6ec063d0b2491097302d2abGreg Clayton object_name ? "(" : "", 222464a5063bc59755cb6ec063d0b2491097302d2abGreg Clayton object_name ? object_name.GetCString() : "", 223464a5063bc59755cb6ec063d0b2491097302d2abGreg Clayton object_name ? ")" : "", 224e40b6424d9e49306392bec4b44060da36414c382Greg Clayton m_file.GetDirectory().AsCString(), 225e40b6424d9e49306392bec4b44060da36414c382Greg Clayton m_file.GetFilename().AsCString(), 226cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton m_file_offset, 227e40b6424d9e49306392bec4b44060da36414c382Greg Clayton m_length); 228e40b6424d9e49306392bec4b44060da36414c382Greg Clayton } 229e40b6424d9e49306392bec4b44060da36414c382Greg Clayton else 230e40b6424d9e49306392bec4b44060da36414c382Greg Clayton { 231464a5063bc59755cb6ec063d0b2491097302d2abGreg Clayton log->Printf ("%p ObjectFile::ObjectFile() module = %p (%s%s%s%s), file = <NULL>, file_offset = 0x%8.8" PRIx64 ", size = %" PRIu64, 232e40b6424d9e49306392bec4b44060da36414c382Greg Clayton this, 233464a5063bc59755cb6ec063d0b2491097302d2abGreg Clayton module_sp.get(), 2343508c387c3f0c9ecc439d98048fd7694d41bab1bGreg Clayton module_sp->GetFileSpec().GetFilename().AsCString(), 235464a5063bc59755cb6ec063d0b2491097302d2abGreg Clayton object_name ? "(" : "", 236464a5063bc59755cb6ec063d0b2491097302d2abGreg Clayton object_name ? object_name.GetCString() : "", 237464a5063bc59755cb6ec063d0b2491097302d2abGreg Clayton object_name ? ")" : "", 238cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton m_file_offset, 239e40b6424d9e49306392bec4b44060da36414c382Greg Clayton m_length); 240e40b6424d9e49306392bec4b44060da36414c382Greg Clayton } 241e40b6424d9e49306392bec4b44060da36414c382Greg Clayton } 242e40b6424d9e49306392bec4b44060da36414c382Greg Clayton} 243e40b6424d9e49306392bec4b44060da36414c382Greg Clayton 244b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton 2453508c387c3f0c9ecc439d98048fd7694d41bab1bGreg ClaytonObjectFile::ObjectFile (const lldb::ModuleSP &module_sp, 246b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton const ProcessSP &process_sp, 247b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton lldb::addr_t header_addr, 248b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton DataBufferSP& header_data_sp) : 2493508c387c3f0c9ecc439d98048fd7694d41bab1bGreg Clayton ModuleChild (module_sp), 250b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton m_file (), 251b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton m_type (eTypeInvalid), 252b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton m_strata (eStrataInvalid), 253cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton m_file_offset (0), 254b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton m_length (0), 255b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton m_data (), 256b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton m_unwind_table (*this), 257b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton m_process_wp (process_sp), 258464a5063bc59755cb6ec063d0b2491097302d2abGreg Clayton m_memory_addr (header_addr), 259464a5063bc59755cb6ec063d0b2491097302d2abGreg Clayton m_sections_ap (), 260464a5063bc59755cb6ec063d0b2491097302d2abGreg Clayton m_symtab_ap () 261464a5063bc59755cb6ec063d0b2491097302d2abGreg Clayton{ 262b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton if (header_data_sp) 263b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton m_data.SetData (header_data_sp, 0, header_data_sp->GetByteSize()); 264952e9dc874944fcdbbb224f3ec4fc2c859376f64Greg Clayton Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT)); 265b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton if (log) 266b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton { 267464a5063bc59755cb6ec063d0b2491097302d2abGreg Clayton const ConstString object_name (module_sp->GetObjectName()); 268464a5063bc59755cb6ec063d0b2491097302d2abGreg Clayton log->Printf ("%p ObjectFile::ObjectFile() module = %p (%s%s%s%s), process = %p, header_addr = 0x%" PRIx64, 269b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton this, 270464a5063bc59755cb6ec063d0b2491097302d2abGreg Clayton module_sp.get(), 2713508c387c3f0c9ecc439d98048fd7694d41bab1bGreg Clayton module_sp->GetFileSpec().GetFilename().AsCString(), 272464a5063bc59755cb6ec063d0b2491097302d2abGreg Clayton object_name ? "(" : "", 273464a5063bc59755cb6ec063d0b2491097302d2abGreg Clayton object_name ? object_name.GetCString() : "", 274464a5063bc59755cb6ec063d0b2491097302d2abGreg Clayton object_name ? ")" : "", 275b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton process_sp.get(), 276cbe61bd26db663fa3036866dc33315c6ffc37910Greg Clayton m_memory_addr); 277b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton } 278b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton} 279b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton 280b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton 281e40b6424d9e49306392bec4b44060da36414c382Greg ClaytonObjectFile::~ObjectFile() 282e40b6424d9e49306392bec4b44060da36414c382Greg Clayton{ 283952e9dc874944fcdbbb224f3ec4fc2c859376f64Greg Clayton Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT)); 284e40b6424d9e49306392bec4b44060da36414c382Greg Clayton if (log) 285c9b798c06458466c818efc6b385f538a22fae022Greg Clayton log->Printf ("%p ObjectFile::~ObjectFile ()\n", this); 28624943d2ee8bfaa7cf5893e4709143924157a5c1eChris Lattner} 2877508e732818c32e1cfeaaf7d1d507fe3834ce9d2Jim Ingham 2887508e732818c32e1cfeaaf7d1d507fe3834ce9d2Jim Inghambool 2897508e732818c32e1cfeaaf7d1d507fe3834ce9d2Jim InghamObjectFile::SetModulesArchitecture (const ArchSpec &new_arch) 2907508e732818c32e1cfeaaf7d1d507fe3834ce9d2Jim Ingham{ 2913508c387c3f0c9ecc439d98048fd7694d41bab1bGreg Clayton ModuleSP module_sp (GetModule()); 2923508c387c3f0c9ecc439d98048fd7694d41bab1bGreg Clayton if (module_sp) 2933508c387c3f0c9ecc439d98048fd7694d41bab1bGreg Clayton return module_sp->SetArchitecture (new_arch); 2943508c387c3f0c9ecc439d98048fd7694d41bab1bGreg Clayton return false; 2957508e732818c32e1cfeaaf7d1d507fe3834ce9d2Jim Ingham} 2967508e732818c32e1cfeaaf7d1d507fe3834ce9d2Jim Ingham 297b344843f75ef893762c93fd0a22d2d45712ce74dGreg ClaytonAddressClass 298e40b6424d9e49306392bec4b44060da36414c382Greg ClaytonObjectFile::GetAddressClass (addr_t file_addr) 299b1888f24fa181489840b9acf193e224d125d0776Greg Clayton{ 300b1888f24fa181489840b9acf193e224d125d0776Greg Clayton Symtab *symtab = GetSymtab(); 301b1888f24fa181489840b9acf193e224d125d0776Greg Clayton if (symtab) 302b1888f24fa181489840b9acf193e224d125d0776Greg Clayton { 303b1888f24fa181489840b9acf193e224d125d0776Greg Clayton Symbol *symbol = symtab->FindSymbolContainingFileAddress(file_addr); 304b1888f24fa181489840b9acf193e224d125d0776Greg Clayton if (symbol) 305b1888f24fa181489840b9acf193e224d125d0776Greg Clayton { 3060c31d3d3a4a1d00d53346d8a23b0519f47e55d1fGreg Clayton if (symbol->ValueIsAddress()) 307b1888f24fa181489840b9acf193e224d125d0776Greg Clayton { 3080c31d3d3a4a1d00d53346d8a23b0519f47e55d1fGreg Clayton const SectionSP section_sp (symbol->GetAddress().GetSection()); 3093508c387c3f0c9ecc439d98048fd7694d41bab1bGreg Clayton if (section_sp) 310b1888f24fa181489840b9acf193e224d125d0776Greg Clayton { 3113508c387c3f0c9ecc439d98048fd7694d41bab1bGreg Clayton const SectionType section_type = section_sp->GetType(); 312b1888f24fa181489840b9acf193e224d125d0776Greg Clayton switch (section_type) 313b1888f24fa181489840b9acf193e224d125d0776Greg Clayton { 314b1888f24fa181489840b9acf193e224d125d0776Greg Clayton case eSectionTypeInvalid: return eAddressClassUnknown; 315b1888f24fa181489840b9acf193e224d125d0776Greg Clayton case eSectionTypeCode: return eAddressClassCode; 316b1888f24fa181489840b9acf193e224d125d0776Greg Clayton case eSectionTypeContainer: return eAddressClassUnknown; 31724a6bd9835ed1655984397b0cdf35127e47681e9Greg Clayton case eSectionTypeData: 31824a6bd9835ed1655984397b0cdf35127e47681e9Greg Clayton case eSectionTypeDataCString: 31924a6bd9835ed1655984397b0cdf35127e47681e9Greg Clayton case eSectionTypeDataCStringPointers: 32024a6bd9835ed1655984397b0cdf35127e47681e9Greg Clayton case eSectionTypeDataSymbolAddress: 32124a6bd9835ed1655984397b0cdf35127e47681e9Greg Clayton case eSectionTypeData4: 32224a6bd9835ed1655984397b0cdf35127e47681e9Greg Clayton case eSectionTypeData8: 32324a6bd9835ed1655984397b0cdf35127e47681e9Greg Clayton case eSectionTypeData16: 32424a6bd9835ed1655984397b0cdf35127e47681e9Greg Clayton case eSectionTypeDataPointers: 32524a6bd9835ed1655984397b0cdf35127e47681e9Greg Clayton case eSectionTypeZeroFill: 32624a6bd9835ed1655984397b0cdf35127e47681e9Greg Clayton case eSectionTypeDataObjCMessageRefs: 32724a6bd9835ed1655984397b0cdf35127e47681e9Greg Clayton case eSectionTypeDataObjCCFStrings: 32824a6bd9835ed1655984397b0cdf35127e47681e9Greg Clayton return eAddressClassData; 32924a6bd9835ed1655984397b0cdf35127e47681e9Greg Clayton case eSectionTypeDebug: 33024a6bd9835ed1655984397b0cdf35127e47681e9Greg Clayton case eSectionTypeDWARFDebugAbbrev: 33124a6bd9835ed1655984397b0cdf35127e47681e9Greg Clayton case eSectionTypeDWARFDebugAranges: 33224a6bd9835ed1655984397b0cdf35127e47681e9Greg Clayton case eSectionTypeDWARFDebugFrame: 33324a6bd9835ed1655984397b0cdf35127e47681e9Greg Clayton case eSectionTypeDWARFDebugInfo: 33424a6bd9835ed1655984397b0cdf35127e47681e9Greg Clayton case eSectionTypeDWARFDebugLine: 33524a6bd9835ed1655984397b0cdf35127e47681e9Greg Clayton case eSectionTypeDWARFDebugLoc: 33624a6bd9835ed1655984397b0cdf35127e47681e9Greg Clayton case eSectionTypeDWARFDebugMacInfo: 33724a6bd9835ed1655984397b0cdf35127e47681e9Greg Clayton case eSectionTypeDWARFDebugPubNames: 33824a6bd9835ed1655984397b0cdf35127e47681e9Greg Clayton case eSectionTypeDWARFDebugPubTypes: 33924a6bd9835ed1655984397b0cdf35127e47681e9Greg Clayton case eSectionTypeDWARFDebugRanges: 34024a6bd9835ed1655984397b0cdf35127e47681e9Greg Clayton case eSectionTypeDWARFDebugStr: 34124a6bd9835ed1655984397b0cdf35127e47681e9Greg Clayton case eSectionTypeDWARFAppleNames: 34224a6bd9835ed1655984397b0cdf35127e47681e9Greg Clayton case eSectionTypeDWARFAppleTypes: 34324a6bd9835ed1655984397b0cdf35127e47681e9Greg Clayton case eSectionTypeDWARFAppleNamespaces: 34424a6bd9835ed1655984397b0cdf35127e47681e9Greg Clayton case eSectionTypeDWARFAppleObjC: 34524a6bd9835ed1655984397b0cdf35127e47681e9Greg Clayton return eAddressClassDebug; 346b1888f24fa181489840b9acf193e224d125d0776Greg Clayton case eSectionTypeEHFrame: return eAddressClassRuntime; 347b1888f24fa181489840b9acf193e224d125d0776Greg Clayton case eSectionTypeOther: return eAddressClassUnknown; 348b1888f24fa181489840b9acf193e224d125d0776Greg Clayton } 349b1888f24fa181489840b9acf193e224d125d0776Greg Clayton } 350b1888f24fa181489840b9acf193e224d125d0776Greg Clayton } 351b1888f24fa181489840b9acf193e224d125d0776Greg Clayton 352b344843f75ef893762c93fd0a22d2d45712ce74dGreg Clayton const SymbolType symbol_type = symbol->GetType(); 353b1888f24fa181489840b9acf193e224d125d0776Greg Clayton switch (symbol_type) 354b1888f24fa181489840b9acf193e224d125d0776Greg Clayton { 355b1888f24fa181489840b9acf193e224d125d0776Greg Clayton case eSymbolTypeAny: return eAddressClassUnknown; 356b1888f24fa181489840b9acf193e224d125d0776Greg Clayton case eSymbolTypeAbsolute: return eAddressClassUnknown; 357b1888f24fa181489840b9acf193e224d125d0776Greg Clayton case eSymbolTypeCode: return eAddressClassCode; 358b1888f24fa181489840b9acf193e224d125d0776Greg Clayton case eSymbolTypeTrampoline: return eAddressClassCode; 3590688435f443de94c82a1ec3b33451beaf2f0b43dGreg Clayton case eSymbolTypeResolver: return eAddressClassCode; 360b1888f24fa181489840b9acf193e224d125d0776Greg Clayton case eSymbolTypeData: return eAddressClassData; 361b1888f24fa181489840b9acf193e224d125d0776Greg Clayton case eSymbolTypeRuntime: return eAddressClassRuntime; 362b1888f24fa181489840b9acf193e224d125d0776Greg Clayton case eSymbolTypeException: return eAddressClassRuntime; 363b1888f24fa181489840b9acf193e224d125d0776Greg Clayton case eSymbolTypeSourceFile: return eAddressClassDebug; 364b1888f24fa181489840b9acf193e224d125d0776Greg Clayton case eSymbolTypeHeaderFile: return eAddressClassDebug; 365b1888f24fa181489840b9acf193e224d125d0776Greg Clayton case eSymbolTypeObjectFile: return eAddressClassDebug; 366b1888f24fa181489840b9acf193e224d125d0776Greg Clayton case eSymbolTypeCommonBlock: return eAddressClassDebug; 367b1888f24fa181489840b9acf193e224d125d0776Greg Clayton case eSymbolTypeBlock: return eAddressClassDebug; 368b1888f24fa181489840b9acf193e224d125d0776Greg Clayton case eSymbolTypeLocal: return eAddressClassData; 369b1888f24fa181489840b9acf193e224d125d0776Greg Clayton case eSymbolTypeParam: return eAddressClassData; 370b1888f24fa181489840b9acf193e224d125d0776Greg Clayton case eSymbolTypeVariable: return eAddressClassData; 371b1888f24fa181489840b9acf193e224d125d0776Greg Clayton case eSymbolTypeVariableType: return eAddressClassDebug; 372b1888f24fa181489840b9acf193e224d125d0776Greg Clayton case eSymbolTypeLineEntry: return eAddressClassDebug; 373b1888f24fa181489840b9acf193e224d125d0776Greg Clayton case eSymbolTypeLineHeader: return eAddressClassDebug; 374b1888f24fa181489840b9acf193e224d125d0776Greg Clayton case eSymbolTypeScopeBegin: return eAddressClassDebug; 375b1888f24fa181489840b9acf193e224d125d0776Greg Clayton case eSymbolTypeScopeEnd: return eAddressClassDebug; 376b1888f24fa181489840b9acf193e224d125d0776Greg Clayton case eSymbolTypeAdditional: return eAddressClassUnknown; 377b1888f24fa181489840b9acf193e224d125d0776Greg Clayton case eSymbolTypeCompiler: return eAddressClassDebug; 378b1888f24fa181489840b9acf193e224d125d0776Greg Clayton case eSymbolTypeInstrumentation:return eAddressClassDebug; 379b1888f24fa181489840b9acf193e224d125d0776Greg Clayton case eSymbolTypeUndefined: return eAddressClassUnknown; 3803f69eacbb218a37390822c89d3675bd740590382Greg Clayton case eSymbolTypeObjCClass: return eAddressClassRuntime; 3813f69eacbb218a37390822c89d3675bd740590382Greg Clayton case eSymbolTypeObjCMetaClass: return eAddressClassRuntime; 3823f69eacbb218a37390822c89d3675bd740590382Greg Clayton case eSymbolTypeObjCIVar: return eAddressClassRuntime; 383b1888f24fa181489840b9acf193e224d125d0776Greg Clayton } 384b1888f24fa181489840b9acf193e224d125d0776Greg Clayton } 385b1888f24fa181489840b9acf193e224d125d0776Greg Clayton } 386b1888f24fa181489840b9acf193e224d125d0776Greg Clayton return eAddressClassUnknown; 387b1888f24fa181489840b9acf193e224d125d0776Greg Clayton} 388b1888f24fa181489840b9acf193e224d125d0776Greg Clayton 389b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg ClaytonDataBufferSP 390b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg ClaytonObjectFile::ReadMemory (const ProcessSP &process_sp, lldb::addr_t addr, size_t byte_size) 391b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton{ 392b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton DataBufferSP data_sp; 393b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton if (process_sp) 394b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton { 395b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton std::auto_ptr<DataBufferHeap> data_ap (new DataBufferHeap (byte_size, 0)); 396b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton Error error; 397b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton const size_t bytes_read = process_sp->ReadMemory (addr, 398b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton data_ap->GetBytes(), 399b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton data_ap->GetByteSize(), 400b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton error); 401b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton if (bytes_read == byte_size) 402b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton data_sp.reset (data_ap.release()); 403b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton } 404b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton return data_sp; 405b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton} 406b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton 407db2dc2b824b61ef7578dc8cdad7b338aa82b1f17Greg Claytonsize_t 408db2dc2b824b61ef7578dc8cdad7b338aa82b1f17Greg ClaytonObjectFile::GetData (off_t offset, size_t length, DataExtractor &data) const 409db2dc2b824b61ef7578dc8cdad7b338aa82b1f17Greg Clayton{ 410db2dc2b824b61ef7578dc8cdad7b338aa82b1f17Greg Clayton // The entire file has already been mmap'ed into m_data, so just copy from there 411db2dc2b824b61ef7578dc8cdad7b338aa82b1f17Greg Clayton // as the back mmap buffer will be shared with shared pointers. 412db2dc2b824b61ef7578dc8cdad7b338aa82b1f17Greg Clayton return data.SetData (m_data, offset, length); 413db2dc2b824b61ef7578dc8cdad7b338aa82b1f17Greg Clayton} 414db2dc2b824b61ef7578dc8cdad7b338aa82b1f17Greg Clayton 415db2dc2b824b61ef7578dc8cdad7b338aa82b1f17Greg Claytonsize_t 416db2dc2b824b61ef7578dc8cdad7b338aa82b1f17Greg ClaytonObjectFile::CopyData (off_t offset, size_t length, void *dst) const 417db2dc2b824b61ef7578dc8cdad7b338aa82b1f17Greg Clayton{ 418db2dc2b824b61ef7578dc8cdad7b338aa82b1f17Greg Clayton // The entire file has already been mmap'ed into m_data, so just copy from there 419db2dc2b824b61ef7578dc8cdad7b338aa82b1f17Greg Clayton return m_data.CopyByteOrderedData (offset, length, dst, length, lldb::endian::InlHostByteOrder()); 420db2dc2b824b61ef7578dc8cdad7b338aa82b1f17Greg Clayton} 421b1888f24fa181489840b9acf193e224d125d0776Greg Clayton 422b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton 423b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Claytonsize_t 424b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg ClaytonObjectFile::ReadSectionData (const Section *section, off_t section_offset, void *dst, size_t dst_len) const 425b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton{ 42646c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton if (IsInMemory()) 427b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton { 428b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton ProcessSP process_sp (m_process_wp.lock()); 429b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton if (process_sp) 430b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton { 431b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton Error error; 4322ddb2b8aed6d43665c6955255f6a077574a08412Greg Clayton const addr_t base_load_addr = section->GetLoadBaseAddress (&process_sp->GetTarget()); 4332ddb2b8aed6d43665c6955255f6a077574a08412Greg Clayton if (base_load_addr != LLDB_INVALID_ADDRESS) 4342ddb2b8aed6d43665c6955255f6a077574a08412Greg Clayton return process_sp->ReadMemory (base_load_addr + section_offset, dst, dst_len, error); 435b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton } 436b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton } 437b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton else 438b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton { 4393383c1741c6b0ea4648a019f89333ec73e632c5bGreg Clayton const uint64_t section_file_size = section->GetFileSize(); 4403383c1741c6b0ea4648a019f89333ec73e632c5bGreg Clayton if (section_offset < section_file_size) 4413383c1741c6b0ea4648a019f89333ec73e632c5bGreg Clayton { 4423383c1741c6b0ea4648a019f89333ec73e632c5bGreg Clayton const uint64_t section_bytes_left = section_file_size - section_offset; 4433383c1741c6b0ea4648a019f89333ec73e632c5bGreg Clayton uint64_t section_dst_len = dst_len; 4443383c1741c6b0ea4648a019f89333ec73e632c5bGreg Clayton if (section_dst_len > section_bytes_left) 4453383c1741c6b0ea4648a019f89333ec73e632c5bGreg Clayton section_dst_len = section_bytes_left; 4463383c1741c6b0ea4648a019f89333ec73e632c5bGreg Clayton return CopyData (section->GetFileOffset() + section_offset, section_dst_len, dst); 4473383c1741c6b0ea4648a019f89333ec73e632c5bGreg Clayton } 4481e52600c9f14bc28b27e816d84b5f73ec01b392eSean Callanan else 4491e52600c9f14bc28b27e816d84b5f73ec01b392eSean Callanan { 4501e52600c9f14bc28b27e816d84b5f73ec01b392eSean Callanan if (section->GetType() == eSectionTypeZeroFill) 4511e52600c9f14bc28b27e816d84b5f73ec01b392eSean Callanan { 4521e52600c9f14bc28b27e816d84b5f73ec01b392eSean Callanan const uint64_t section_size = section->GetByteSize(); 4531e52600c9f14bc28b27e816d84b5f73ec01b392eSean Callanan const uint64_t section_bytes_left = section_size - section_offset; 4541e52600c9f14bc28b27e816d84b5f73ec01b392eSean Callanan uint64_t section_dst_len = dst_len; 4551e52600c9f14bc28b27e816d84b5f73ec01b392eSean Callanan if (section_dst_len > section_bytes_left) 4561e52600c9f14bc28b27e816d84b5f73ec01b392eSean Callanan section_dst_len = section_bytes_left; 4571e52600c9f14bc28b27e816d84b5f73ec01b392eSean Callanan bzero(dst, section_dst_len); 4581e52600c9f14bc28b27e816d84b5f73ec01b392eSean Callanan return section_dst_len; 4591e52600c9f14bc28b27e816d84b5f73ec01b392eSean Callanan } 4601e52600c9f14bc28b27e816d84b5f73ec01b392eSean Callanan } 461b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton } 462b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton return 0; 463b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton} 464b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton 465b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton//---------------------------------------------------------------------- 466b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton// Get the section data the file on disk 467b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton//---------------------------------------------------------------------- 468b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Claytonsize_t 469b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg ClaytonObjectFile::ReadSectionData (const Section *section, DataExtractor& section_data) const 470b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton{ 47146c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton if (IsInMemory()) 472b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton { 473b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton ProcessSP process_sp (m_process_wp.lock()); 474b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton if (process_sp) 475b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton { 4762ddb2b8aed6d43665c6955255f6a077574a08412Greg Clayton const addr_t base_load_addr = section->GetLoadBaseAddress (&process_sp->GetTarget()); 4772ddb2b8aed6d43665c6955255f6a077574a08412Greg Clayton if (base_load_addr != LLDB_INVALID_ADDRESS) 478b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton { 4792ddb2b8aed6d43665c6955255f6a077574a08412Greg Clayton DataBufferSP data_sp (ReadMemory (process_sp, base_load_addr, section->GetByteSize())); 4802ddb2b8aed6d43665c6955255f6a077574a08412Greg Clayton if (data_sp) 4812ddb2b8aed6d43665c6955255f6a077574a08412Greg Clayton { 4822ddb2b8aed6d43665c6955255f6a077574a08412Greg Clayton section_data.SetData (data_sp, 0, data_sp->GetByteSize()); 4832ddb2b8aed6d43665c6955255f6a077574a08412Greg Clayton section_data.SetByteOrder (process_sp->GetByteOrder()); 4842ddb2b8aed6d43665c6955255f6a077574a08412Greg Clayton section_data.SetAddressByteSize (process_sp->GetAddressByteSize()); 4852ddb2b8aed6d43665c6955255f6a077574a08412Greg Clayton return section_data.GetByteSize(); 4862ddb2b8aed6d43665c6955255f6a077574a08412Greg Clayton } 487b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton } 488b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton } 489b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton } 490b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton else 491b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton { 492b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton // The object file now contains a full mmap'ed copy of the object file data, so just use this 493b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton return MemoryMapSectionData (section, section_data); 494b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton } 495b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton section_data.Clear(); 496b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton return 0; 497b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton} 498b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton 499b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Claytonsize_t 500b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg ClaytonObjectFile::MemoryMapSectionData (const Section *section, DataExtractor& section_data) const 501b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton{ 50246c9a355af9b39db78c006b2a5cbf97d3c58d947Greg Clayton if (IsInMemory()) 503b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton { 504b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton return ReadSectionData (section, section_data); 505b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton } 506b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton else 507b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton { 508b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton // The object file now contains a full mmap'ed copy of the object file data, so just use this 50923d90aea32663f114ffee323775b02dad09f2f18Greg Clayton return GetData(section->GetFileOffset(), section->GetFileSize(), section_data); 510b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton } 511b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton section_data.Clear(); 512b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton return 0; 513b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton} 514b5a8f1498e1ddaeed5187a878d57ea0b74af9c26Greg Clayton 51549ce8969d3154e1560106cfe530444c09410f217Greg Clayton 51649ce8969d3154e1560106cfe530444c09410f217Greg Claytonbool 5173cf7ab5462467121b4ac6cde09ee994030dad0c5Greg ClaytonObjectFile::SplitArchivePathWithObject (const char *path_with_object, FileSpec &archive_file, ConstString &archive_object, bool must_exist) 51849ce8969d3154e1560106cfe530444c09410f217Greg Clayton{ 51949ce8969d3154e1560106cfe530444c09410f217Greg Clayton RegularExpression g_object_regex("(.*)\\(([^\\)]+)\\)$"); 52000af72e395d138f459192b7f5450fa4c7854f135Greg Clayton RegularExpression::Match regex_match(2); 52100af72e395d138f459192b7f5450fa4c7854f135Greg Clayton if (g_object_regex.Execute (path_with_object, ®ex_match)) 52249ce8969d3154e1560106cfe530444c09410f217Greg Clayton { 52349ce8969d3154e1560106cfe530444c09410f217Greg Clayton std::string path; 52449ce8969d3154e1560106cfe530444c09410f217Greg Clayton std::string obj; 52500af72e395d138f459192b7f5450fa4c7854f135Greg Clayton if (regex_match.GetMatchAtIndex (path_with_object, 1, path) && 52600af72e395d138f459192b7f5450fa4c7854f135Greg Clayton regex_match.GetMatchAtIndex (path_with_object, 2, obj)) 52749ce8969d3154e1560106cfe530444c09410f217Greg Clayton { 52849ce8969d3154e1560106cfe530444c09410f217Greg Clayton archive_file.SetFile (path.c_str(), false); 52949ce8969d3154e1560106cfe530444c09410f217Greg Clayton archive_object.SetCString(obj.c_str()); 5303cf7ab5462467121b4ac6cde09ee994030dad0c5Greg Clayton if (must_exist && !archive_file.Exists()) 5313cf7ab5462467121b4ac6cde09ee994030dad0c5Greg Clayton return false; 53249ce8969d3154e1560106cfe530444c09410f217Greg Clayton return true; 53349ce8969d3154e1560106cfe530444c09410f217Greg Clayton } 53449ce8969d3154e1560106cfe530444c09410f217Greg Clayton } 53549ce8969d3154e1560106cfe530444c09410f217Greg Clayton return false; 53649ce8969d3154e1560106cfe530444c09410f217Greg Clayton} 53749ce8969d3154e1560106cfe530444c09410f217Greg Clayton 538464a5063bc59755cb6ec063d0b2491097302d2abGreg Claytonvoid 539464a5063bc59755cb6ec063d0b2491097302d2abGreg ClaytonObjectFile::ClearSymtab () 540464a5063bc59755cb6ec063d0b2491097302d2abGreg Clayton{ 541464a5063bc59755cb6ec063d0b2491097302d2abGreg Clayton ModuleSP module_sp(GetModule()); 542464a5063bc59755cb6ec063d0b2491097302d2abGreg Clayton if (module_sp) 543464a5063bc59755cb6ec063d0b2491097302d2abGreg Clayton { 544464a5063bc59755cb6ec063d0b2491097302d2abGreg Clayton lldb_private::Mutex::Locker locker(module_sp->GetMutex()); 545952e9dc874944fcdbbb224f3ec4fc2c859376f64Greg Clayton Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT)); 546464a5063bc59755cb6ec063d0b2491097302d2abGreg Clayton if (log) 547464a5063bc59755cb6ec063d0b2491097302d2abGreg Clayton { 548464a5063bc59755cb6ec063d0b2491097302d2abGreg Clayton log->Printf ("%p ObjectFile::ClearSymtab () symtab = %p", 549464a5063bc59755cb6ec063d0b2491097302d2abGreg Clayton this, 550464a5063bc59755cb6ec063d0b2491097302d2abGreg Clayton m_symtab_ap.get()); 551464a5063bc59755cb6ec063d0b2491097302d2abGreg Clayton } 552464a5063bc59755cb6ec063d0b2491097302d2abGreg Clayton m_symtab_ap.reset(); 553464a5063bc59755cb6ec063d0b2491097302d2abGreg Clayton } 554464a5063bc59755cb6ec063d0b2491097302d2abGreg Clayton} 555