15ffd83dbSDimitry Andric //===-- ObjectFile.cpp ----------------------------------------------------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric
90b57cec5SDimitry Andric #include "lldb/Symbol/ObjectFile.h"
100b57cec5SDimitry Andric #include "lldb/Core/Module.h"
110b57cec5SDimitry Andric #include "lldb/Core/ModuleSpec.h"
120b57cec5SDimitry Andric #include "lldb/Core/PluginManager.h"
130b57cec5SDimitry Andric #include "lldb/Core/Section.h"
149dba64beSDimitry Andric #include "lldb/Symbol/CallFrameInfo.h"
150b57cec5SDimitry Andric #include "lldb/Symbol/ObjectContainer.h"
160b57cec5SDimitry Andric #include "lldb/Symbol/SymbolFile.h"
170b57cec5SDimitry Andric #include "lldb/Target/Process.h"
180b57cec5SDimitry Andric #include "lldb/Target/SectionLoadList.h"
190b57cec5SDimitry Andric #include "lldb/Target/Target.h"
200b57cec5SDimitry Andric #include "lldb/Utility/DataBuffer.h"
210b57cec5SDimitry Andric #include "lldb/Utility/DataBufferHeap.h"
220b57cec5SDimitry Andric #include "lldb/Utility/Log.h"
230b57cec5SDimitry Andric #include "lldb/Utility/Timer.h"
240b57cec5SDimitry Andric #include "lldb/lldb-private.h"
250b57cec5SDimitry Andric
260b57cec5SDimitry Andric using namespace lldb;
270b57cec5SDimitry Andric using namespace lldb_private;
280b57cec5SDimitry Andric
299dba64beSDimitry Andric char ObjectFile::ID;
309dba64beSDimitry Andric
31*af732203SDimitry Andric static ObjectFileSP
CreateObjectFromContainer(const lldb::ModuleSP & module_sp,const FileSpec * file,lldb::offset_t file_offset,lldb::offset_t file_size,DataBufferSP & data_sp,lldb::offset_t & data_offset)32*af732203SDimitry Andric CreateObjectFromContainer(const lldb::ModuleSP &module_sp, const FileSpec *file,
33*af732203SDimitry Andric lldb::offset_t file_offset, lldb::offset_t file_size,
34*af732203SDimitry Andric DataBufferSP &data_sp, lldb::offset_t &data_offset) {
35*af732203SDimitry Andric ObjectContainerCreateInstance callback;
36*af732203SDimitry Andric for (uint32_t idx = 0;
37*af732203SDimitry Andric (callback = PluginManager::GetObjectContainerCreateCallbackAtIndex(
38*af732203SDimitry Andric idx)) != nullptr;
39*af732203SDimitry Andric ++idx) {
40*af732203SDimitry Andric std::unique_ptr<ObjectContainer> object_container_up(callback(
41*af732203SDimitry Andric module_sp, data_sp, data_offset, file, file_offset, file_size));
42*af732203SDimitry Andric if (object_container_up)
43*af732203SDimitry Andric return object_container_up->GetObjectFile(file);
44*af732203SDimitry Andric }
45*af732203SDimitry Andric return {};
46*af732203SDimitry Andric }
47*af732203SDimitry Andric
480b57cec5SDimitry Andric ObjectFileSP
FindPlugin(const lldb::ModuleSP & module_sp,const FileSpec * file,lldb::offset_t file_offset,lldb::offset_t file_size,DataBufferSP & data_sp,lldb::offset_t & data_offset)490b57cec5SDimitry Andric ObjectFile::FindPlugin(const lldb::ModuleSP &module_sp, const FileSpec *file,
500b57cec5SDimitry Andric lldb::offset_t file_offset, lldb::offset_t file_size,
510b57cec5SDimitry Andric DataBufferSP &data_sp, lldb::offset_t &data_offset) {
52*af732203SDimitry Andric LLDB_SCOPED_TIMERF(
530b57cec5SDimitry Andric "ObjectFile::FindPlugin (module = %s, file = %p, file_offset = "
540b57cec5SDimitry Andric "0x%8.8" PRIx64 ", file_size = 0x%8.8" PRIx64 ")",
550b57cec5SDimitry Andric module_sp->GetFileSpec().GetPath().c_str(),
560b57cec5SDimitry Andric static_cast<const void *>(file), static_cast<uint64_t>(file_offset),
570b57cec5SDimitry Andric static_cast<uint64_t>(file_size));
58*af732203SDimitry Andric
59*af732203SDimitry Andric if (!module_sp)
60*af732203SDimitry Andric return {};
61*af732203SDimitry Andric
62*af732203SDimitry Andric if (!file)
63*af732203SDimitry Andric return {};
640b57cec5SDimitry Andric
650b57cec5SDimitry Andric if (!data_sp) {
665ffd83dbSDimitry Andric const bool file_exists = FileSystem::Instance().Exists(*file);
670b57cec5SDimitry Andric // We have an object name which most likely means we have a .o file in
680b57cec5SDimitry Andric // a static archive (.a file). Try and see if we have a cached archive
690b57cec5SDimitry Andric // first without reading any data first
700b57cec5SDimitry Andric if (file_exists && module_sp->GetObjectName()) {
71*af732203SDimitry Andric ObjectFileSP object_file_sp = CreateObjectFromContainer(
72*af732203SDimitry Andric module_sp, file, file_offset, file_size, data_sp, data_offset);
73*af732203SDimitry Andric if (object_file_sp)
740b57cec5SDimitry Andric return object_file_sp;
750b57cec5SDimitry Andric }
760b57cec5SDimitry Andric // Ok, we didn't find any containers that have a named object, now lets
770b57cec5SDimitry Andric // read the first 512 bytes from the file so the object file and object
780b57cec5SDimitry Andric // container plug-ins can use these bytes to see if they can parse this
790b57cec5SDimitry Andric // file.
800b57cec5SDimitry Andric if (file_size > 0) {
81*af732203SDimitry Andric data_sp = FileSystem::Instance().CreateDataBuffer(file->GetPath(), 512,
82*af732203SDimitry Andric file_offset);
830b57cec5SDimitry Andric data_offset = 0;
840b57cec5SDimitry Andric }
850b57cec5SDimitry Andric }
860b57cec5SDimitry Andric
870b57cec5SDimitry Andric if (!data_sp || data_sp->GetByteSize() == 0) {
880b57cec5SDimitry Andric // Check for archive file with format "/path/to/archive.a(object.o)"
899dba64beSDimitry Andric llvm::SmallString<256> path_with_object;
909dba64beSDimitry Andric module_sp->GetFileSpec().GetPath(path_with_object);
910b57cec5SDimitry Andric
92*af732203SDimitry Andric FileSpec archive_file;
930b57cec5SDimitry Andric ConstString archive_object;
940b57cec5SDimitry Andric const bool must_exist = true;
95*af732203SDimitry Andric if (ObjectFile::SplitArchivePathWithObject(path_with_object, archive_file,
96*af732203SDimitry Andric archive_object, must_exist)) {
970b57cec5SDimitry Andric file_size = FileSystem::Instance().GetByteSize(archive_file);
980b57cec5SDimitry Andric if (file_size > 0) {
990b57cec5SDimitry Andric file = &archive_file;
1000b57cec5SDimitry Andric module_sp->SetFileSpecAndObjectName(archive_file, archive_object);
1010b57cec5SDimitry Andric // Check if this is a object container by iterating through all
1020b57cec5SDimitry Andric // object container plugin instances and then trying to get an
1030b57cec5SDimitry Andric // object file from the container plugins since we had a name.
1040b57cec5SDimitry Andric // Also, don't read
1050b57cec5SDimitry Andric // ANY data in case there is data cached in the container plug-ins
1060b57cec5SDimitry Andric // (like BSD archives caching the contained objects within an
1070b57cec5SDimitry Andric // file).
108*af732203SDimitry Andric ObjectFileSP object_file_sp = CreateObjectFromContainer(
109*af732203SDimitry Andric module_sp, file, file_offset, file_size, data_sp, data_offset);
110*af732203SDimitry Andric if (object_file_sp)
1110b57cec5SDimitry Andric return object_file_sp;
1120b57cec5SDimitry Andric // We failed to find any cached object files in the container plug-
1130b57cec5SDimitry Andric // ins, so lets read the first 512 bytes and try again below...
1140b57cec5SDimitry Andric data_sp = FileSystem::Instance().CreateDataBuffer(
1150b57cec5SDimitry Andric archive_file.GetPath(), 512, file_offset);
1160b57cec5SDimitry Andric }
1170b57cec5SDimitry Andric }
1180b57cec5SDimitry Andric }
1190b57cec5SDimitry Andric
1200b57cec5SDimitry Andric if (data_sp && data_sp->GetByteSize() > 0) {
1210b57cec5SDimitry Andric // Check if this is a normal object file by iterating through all
1220b57cec5SDimitry Andric // object file plugin instances.
123*af732203SDimitry Andric ObjectFileCreateInstance callback;
1240b57cec5SDimitry Andric for (uint32_t idx = 0;
125*af732203SDimitry Andric (callback = PluginManager::GetObjectFileCreateCallbackAtIndex(idx)) !=
1260b57cec5SDimitry Andric nullptr;
1270b57cec5SDimitry Andric ++idx) {
128*af732203SDimitry Andric ObjectFileSP object_file_sp(callback(module_sp, data_sp, data_offset,
129*af732203SDimitry Andric file, file_offset, file_size));
1300b57cec5SDimitry Andric if (object_file_sp.get())
1310b57cec5SDimitry Andric return object_file_sp;
1320b57cec5SDimitry Andric }
1330b57cec5SDimitry Andric
1340b57cec5SDimitry Andric // Check if this is a object container by iterating through all object
1350b57cec5SDimitry Andric // container plugin instances and then trying to get an object file
1360b57cec5SDimitry Andric // from the container.
137*af732203SDimitry Andric ObjectFileSP object_file_sp = CreateObjectFromContainer(
138*af732203SDimitry Andric module_sp, file, file_offset, file_size, data_sp, data_offset);
139*af732203SDimitry Andric if (object_file_sp)
1400b57cec5SDimitry Andric return object_file_sp;
1410b57cec5SDimitry Andric }
142*af732203SDimitry Andric
1430b57cec5SDimitry Andric // We didn't find it, so clear our shared pointer in case it contains
1440b57cec5SDimitry Andric // anything and return an empty shared pointer
145*af732203SDimitry Andric return {};
1460b57cec5SDimitry Andric }
1470b57cec5SDimitry Andric
FindPlugin(const lldb::ModuleSP & module_sp,const ProcessSP & process_sp,lldb::addr_t header_addr,DataBufferSP & data_sp)1480b57cec5SDimitry Andric ObjectFileSP ObjectFile::FindPlugin(const lldb::ModuleSP &module_sp,
1490b57cec5SDimitry Andric const ProcessSP &process_sp,
1500b57cec5SDimitry Andric lldb::addr_t header_addr,
1510b57cec5SDimitry Andric DataBufferSP &data_sp) {
1520b57cec5SDimitry Andric ObjectFileSP object_file_sp;
1530b57cec5SDimitry Andric
1540b57cec5SDimitry Andric if (module_sp) {
155*af732203SDimitry Andric LLDB_SCOPED_TIMERF("ObjectFile::FindPlugin (module = "
1560b57cec5SDimitry Andric "%s, process = %p, header_addr = "
1570b57cec5SDimitry Andric "0x%" PRIx64 ")",
1580b57cec5SDimitry Andric module_sp->GetFileSpec().GetPath().c_str(),
1590b57cec5SDimitry Andric static_cast<void *>(process_sp.get()), header_addr);
1600b57cec5SDimitry Andric uint32_t idx;
1610b57cec5SDimitry Andric
1620b57cec5SDimitry Andric // Check if this is a normal object file by iterating through all object
1630b57cec5SDimitry Andric // file plugin instances.
1640b57cec5SDimitry Andric ObjectFileCreateMemoryInstance create_callback;
1650b57cec5SDimitry Andric for (idx = 0;
1660b57cec5SDimitry Andric (create_callback =
1670b57cec5SDimitry Andric PluginManager::GetObjectFileCreateMemoryCallbackAtIndex(idx)) !=
1680b57cec5SDimitry Andric nullptr;
1690b57cec5SDimitry Andric ++idx) {
1700b57cec5SDimitry Andric object_file_sp.reset(
1710b57cec5SDimitry Andric create_callback(module_sp, data_sp, process_sp, header_addr));
1720b57cec5SDimitry Andric if (object_file_sp.get())
1730b57cec5SDimitry Andric return object_file_sp;
1740b57cec5SDimitry Andric }
1750b57cec5SDimitry Andric }
1760b57cec5SDimitry Andric
1770b57cec5SDimitry Andric // We didn't find it, so clear our shared pointer in case it contains
1780b57cec5SDimitry Andric // anything and return an empty shared pointer
1790b57cec5SDimitry Andric object_file_sp.reset();
1800b57cec5SDimitry Andric return object_file_sp;
1810b57cec5SDimitry Andric }
1820b57cec5SDimitry Andric
GetModuleSpecifications(const FileSpec & file,lldb::offset_t file_offset,lldb::offset_t file_size,ModuleSpecList & specs,DataBufferSP data_sp)1830b57cec5SDimitry Andric size_t ObjectFile::GetModuleSpecifications(const FileSpec &file,
1840b57cec5SDimitry Andric lldb::offset_t file_offset,
1850b57cec5SDimitry Andric lldb::offset_t file_size,
1865ffd83dbSDimitry Andric ModuleSpecList &specs,
1875ffd83dbSDimitry Andric DataBufferSP data_sp) {
1885ffd83dbSDimitry Andric if (!data_sp)
1895ffd83dbSDimitry Andric data_sp = FileSystem::Instance().CreateDataBuffer(file.GetPath(), 512,
1905ffd83dbSDimitry Andric file_offset);
1910b57cec5SDimitry Andric if (data_sp) {
1920b57cec5SDimitry Andric if (file_size == 0) {
1930b57cec5SDimitry Andric const lldb::offset_t actual_file_size =
1940b57cec5SDimitry Andric FileSystem::Instance().GetByteSize(file);
1950b57cec5SDimitry Andric if (actual_file_size > file_offset)
1960b57cec5SDimitry Andric file_size = actual_file_size - file_offset;
1970b57cec5SDimitry Andric }
1980b57cec5SDimitry Andric return ObjectFile::GetModuleSpecifications(file, // file spec
1990b57cec5SDimitry Andric data_sp, // data bytes
2000b57cec5SDimitry Andric 0, // data offset
2010b57cec5SDimitry Andric file_offset, // file offset
2020b57cec5SDimitry Andric file_size, // file length
2030b57cec5SDimitry Andric specs);
2040b57cec5SDimitry Andric }
2050b57cec5SDimitry Andric return 0;
2060b57cec5SDimitry Andric }
2070b57cec5SDimitry Andric
GetModuleSpecifications(const lldb_private::FileSpec & file,lldb::DataBufferSP & data_sp,lldb::offset_t data_offset,lldb::offset_t file_offset,lldb::offset_t file_size,lldb_private::ModuleSpecList & specs)2080b57cec5SDimitry Andric size_t ObjectFile::GetModuleSpecifications(
2090b57cec5SDimitry Andric const lldb_private::FileSpec &file, lldb::DataBufferSP &data_sp,
2100b57cec5SDimitry Andric lldb::offset_t data_offset, lldb::offset_t file_offset,
2110b57cec5SDimitry Andric lldb::offset_t file_size, lldb_private::ModuleSpecList &specs) {
2120b57cec5SDimitry Andric const size_t initial_count = specs.GetSize();
2130b57cec5SDimitry Andric ObjectFileGetModuleSpecifications callback;
2140b57cec5SDimitry Andric uint32_t i;
2150b57cec5SDimitry Andric // Try the ObjectFile plug-ins
2160b57cec5SDimitry Andric for (i = 0;
2170b57cec5SDimitry Andric (callback =
2180b57cec5SDimitry Andric PluginManager::GetObjectFileGetModuleSpecificationsCallbackAtIndex(
2190b57cec5SDimitry Andric i)) != nullptr;
2200b57cec5SDimitry Andric ++i) {
2210b57cec5SDimitry Andric if (callback(file, data_sp, data_offset, file_offset, file_size, specs) > 0)
2220b57cec5SDimitry Andric return specs.GetSize() - initial_count;
2230b57cec5SDimitry Andric }
2240b57cec5SDimitry Andric
2250b57cec5SDimitry Andric // Try the ObjectContainer plug-ins
2260b57cec5SDimitry Andric for (i = 0;
2270b57cec5SDimitry Andric (callback = PluginManager::
2280b57cec5SDimitry Andric GetObjectContainerGetModuleSpecificationsCallbackAtIndex(i)) !=
2290b57cec5SDimitry Andric nullptr;
2300b57cec5SDimitry Andric ++i) {
2310b57cec5SDimitry Andric if (callback(file, data_sp, data_offset, file_offset, file_size, specs) > 0)
2320b57cec5SDimitry Andric return specs.GetSize() - initial_count;
2330b57cec5SDimitry Andric }
2340b57cec5SDimitry Andric return 0;
2350b57cec5SDimitry Andric }
2360b57cec5SDimitry Andric
ObjectFile(const lldb::ModuleSP & module_sp,const FileSpec * file_spec_ptr,lldb::offset_t file_offset,lldb::offset_t length,const lldb::DataBufferSP & data_sp,lldb::offset_t data_offset)2370b57cec5SDimitry Andric ObjectFile::ObjectFile(const lldb::ModuleSP &module_sp,
2380b57cec5SDimitry Andric const FileSpec *file_spec_ptr,
2390b57cec5SDimitry Andric lldb::offset_t file_offset, lldb::offset_t length,
2400b57cec5SDimitry Andric const lldb::DataBufferSP &data_sp,
2410b57cec5SDimitry Andric lldb::offset_t data_offset)
2420b57cec5SDimitry Andric : ModuleChild(module_sp),
2430b57cec5SDimitry Andric m_file(), // This file could be different from the original module's file
2440b57cec5SDimitry Andric m_type(eTypeInvalid), m_strata(eStrataInvalid),
2450b57cec5SDimitry Andric m_file_offset(file_offset), m_length(length), m_data(), m_process_wp(),
2460b57cec5SDimitry Andric m_memory_addr(LLDB_INVALID_ADDRESS), m_sections_up(), m_symtab_up(),
2470b57cec5SDimitry Andric m_synthetic_symbol_idx(0) {
2480b57cec5SDimitry Andric if (file_spec_ptr)
2490b57cec5SDimitry Andric m_file = *file_spec_ptr;
2500b57cec5SDimitry Andric if (data_sp)
2510b57cec5SDimitry Andric m_data.SetData(data_sp, data_offset, length);
2520b57cec5SDimitry Andric Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OBJECT));
2539dba64beSDimitry Andric LLDB_LOGF(log,
2549dba64beSDimitry Andric "%p ObjectFile::ObjectFile() module = %p (%s), file = %s, "
2550b57cec5SDimitry Andric "file_offset = 0x%8.8" PRIx64 ", size = %" PRIu64,
2560b57cec5SDimitry Andric static_cast<void *>(this), static_cast<void *>(module_sp.get()),
2570b57cec5SDimitry Andric module_sp->GetSpecificationDescription().c_str(),
2580b57cec5SDimitry Andric m_file ? m_file.GetPath().c_str() : "<NULL>", m_file_offset,
2590b57cec5SDimitry Andric m_length);
2600b57cec5SDimitry Andric }
2610b57cec5SDimitry Andric
ObjectFile(const lldb::ModuleSP & module_sp,const ProcessSP & process_sp,lldb::addr_t header_addr,DataBufferSP & header_data_sp)2620b57cec5SDimitry Andric ObjectFile::ObjectFile(const lldb::ModuleSP &module_sp,
2630b57cec5SDimitry Andric const ProcessSP &process_sp, lldb::addr_t header_addr,
2640b57cec5SDimitry Andric DataBufferSP &header_data_sp)
2650b57cec5SDimitry Andric : ModuleChild(module_sp), m_file(), m_type(eTypeInvalid),
2660b57cec5SDimitry Andric m_strata(eStrataInvalid), m_file_offset(0), m_length(0), m_data(),
2670b57cec5SDimitry Andric m_process_wp(process_sp), m_memory_addr(header_addr), m_sections_up(),
2680b57cec5SDimitry Andric m_symtab_up(), m_synthetic_symbol_idx(0) {
2690b57cec5SDimitry Andric if (header_data_sp)
2700b57cec5SDimitry Andric m_data.SetData(header_data_sp, 0, header_data_sp->GetByteSize());
2710b57cec5SDimitry Andric Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OBJECT));
2729dba64beSDimitry Andric LLDB_LOGF(log,
2739dba64beSDimitry Andric "%p ObjectFile::ObjectFile() module = %p (%s), process = %p, "
2740b57cec5SDimitry Andric "header_addr = 0x%" PRIx64,
2750b57cec5SDimitry Andric static_cast<void *>(this), static_cast<void *>(module_sp.get()),
2760b57cec5SDimitry Andric module_sp->GetSpecificationDescription().c_str(),
2770b57cec5SDimitry Andric static_cast<void *>(process_sp.get()), m_memory_addr);
2780b57cec5SDimitry Andric }
2790b57cec5SDimitry Andric
~ObjectFile()2800b57cec5SDimitry Andric ObjectFile::~ObjectFile() {
2810b57cec5SDimitry Andric Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OBJECT));
2829dba64beSDimitry Andric LLDB_LOGF(log, "%p ObjectFile::~ObjectFile ()\n", static_cast<void *>(this));
2830b57cec5SDimitry Andric }
2840b57cec5SDimitry Andric
SetModulesArchitecture(const ArchSpec & new_arch)2850b57cec5SDimitry Andric bool ObjectFile::SetModulesArchitecture(const ArchSpec &new_arch) {
2860b57cec5SDimitry Andric ModuleSP module_sp(GetModule());
2870b57cec5SDimitry Andric if (module_sp)
2880b57cec5SDimitry Andric return module_sp->SetArchitecture(new_arch);
2890b57cec5SDimitry Andric return false;
2900b57cec5SDimitry Andric }
2910b57cec5SDimitry Andric
GetAddressClass(addr_t file_addr)2920b57cec5SDimitry Andric AddressClass ObjectFile::GetAddressClass(addr_t file_addr) {
2930b57cec5SDimitry Andric Symtab *symtab = GetSymtab();
2940b57cec5SDimitry Andric if (symtab) {
2950b57cec5SDimitry Andric Symbol *symbol = symtab->FindSymbolContainingFileAddress(file_addr);
2960b57cec5SDimitry Andric if (symbol) {
2970b57cec5SDimitry Andric if (symbol->ValueIsAddress()) {
2980b57cec5SDimitry Andric const SectionSP section_sp(symbol->GetAddressRef().GetSection());
2990b57cec5SDimitry Andric if (section_sp) {
3000b57cec5SDimitry Andric const SectionType section_type = section_sp->GetType();
3010b57cec5SDimitry Andric switch (section_type) {
3020b57cec5SDimitry Andric case eSectionTypeInvalid:
3030b57cec5SDimitry Andric return AddressClass::eUnknown;
3040b57cec5SDimitry Andric case eSectionTypeCode:
3050b57cec5SDimitry Andric return AddressClass::eCode;
3060b57cec5SDimitry Andric case eSectionTypeContainer:
3070b57cec5SDimitry Andric return AddressClass::eUnknown;
3080b57cec5SDimitry Andric case eSectionTypeData:
3090b57cec5SDimitry Andric case eSectionTypeDataCString:
3100b57cec5SDimitry Andric case eSectionTypeDataCStringPointers:
3110b57cec5SDimitry Andric case eSectionTypeDataSymbolAddress:
3120b57cec5SDimitry Andric case eSectionTypeData4:
3130b57cec5SDimitry Andric case eSectionTypeData8:
3140b57cec5SDimitry Andric case eSectionTypeData16:
3150b57cec5SDimitry Andric case eSectionTypeDataPointers:
3160b57cec5SDimitry Andric case eSectionTypeZeroFill:
3170b57cec5SDimitry Andric case eSectionTypeDataObjCMessageRefs:
3180b57cec5SDimitry Andric case eSectionTypeDataObjCCFStrings:
3190b57cec5SDimitry Andric case eSectionTypeGoSymtab:
3200b57cec5SDimitry Andric return AddressClass::eData;
3210b57cec5SDimitry Andric case eSectionTypeDebug:
3220b57cec5SDimitry Andric case eSectionTypeDWARFDebugAbbrev:
3230b57cec5SDimitry Andric case eSectionTypeDWARFDebugAbbrevDwo:
3240b57cec5SDimitry Andric case eSectionTypeDWARFDebugAddr:
3250b57cec5SDimitry Andric case eSectionTypeDWARFDebugAranges:
3260b57cec5SDimitry Andric case eSectionTypeDWARFDebugCuIndex:
3270b57cec5SDimitry Andric case eSectionTypeDWARFDebugFrame:
3280b57cec5SDimitry Andric case eSectionTypeDWARFDebugInfo:
3290b57cec5SDimitry Andric case eSectionTypeDWARFDebugInfoDwo:
3300b57cec5SDimitry Andric case eSectionTypeDWARFDebugLine:
3310b57cec5SDimitry Andric case eSectionTypeDWARFDebugLineStr:
3320b57cec5SDimitry Andric case eSectionTypeDWARFDebugLoc:
333480093f4SDimitry Andric case eSectionTypeDWARFDebugLocDwo:
3340b57cec5SDimitry Andric case eSectionTypeDWARFDebugLocLists:
335480093f4SDimitry Andric case eSectionTypeDWARFDebugLocListsDwo:
3360b57cec5SDimitry Andric case eSectionTypeDWARFDebugMacInfo:
3370b57cec5SDimitry Andric case eSectionTypeDWARFDebugMacro:
3380b57cec5SDimitry Andric case eSectionTypeDWARFDebugNames:
3390b57cec5SDimitry Andric case eSectionTypeDWARFDebugPubNames:
3400b57cec5SDimitry Andric case eSectionTypeDWARFDebugPubTypes:
3410b57cec5SDimitry Andric case eSectionTypeDWARFDebugRanges:
3420b57cec5SDimitry Andric case eSectionTypeDWARFDebugRngLists:
343480093f4SDimitry Andric case eSectionTypeDWARFDebugRngListsDwo:
3440b57cec5SDimitry Andric case eSectionTypeDWARFDebugStr:
3450b57cec5SDimitry Andric case eSectionTypeDWARFDebugStrDwo:
3460b57cec5SDimitry Andric case eSectionTypeDWARFDebugStrOffsets:
3470b57cec5SDimitry Andric case eSectionTypeDWARFDebugStrOffsetsDwo:
3485ffd83dbSDimitry Andric case eSectionTypeDWARFDebugTuIndex:
3490b57cec5SDimitry Andric case eSectionTypeDWARFDebugTypes:
3500b57cec5SDimitry Andric case eSectionTypeDWARFDebugTypesDwo:
3510b57cec5SDimitry Andric case eSectionTypeDWARFAppleNames:
3520b57cec5SDimitry Andric case eSectionTypeDWARFAppleTypes:
3530b57cec5SDimitry Andric case eSectionTypeDWARFAppleNamespaces:
3540b57cec5SDimitry Andric case eSectionTypeDWARFAppleObjC:
3550b57cec5SDimitry Andric case eSectionTypeDWARFGNUDebugAltLink:
3560b57cec5SDimitry Andric return AddressClass::eDebug;
3570b57cec5SDimitry Andric case eSectionTypeEHFrame:
3580b57cec5SDimitry Andric case eSectionTypeARMexidx:
3590b57cec5SDimitry Andric case eSectionTypeARMextab:
3600b57cec5SDimitry Andric case eSectionTypeCompactUnwind:
3610b57cec5SDimitry Andric return AddressClass::eRuntime;
3620b57cec5SDimitry Andric case eSectionTypeELFSymbolTable:
3630b57cec5SDimitry Andric case eSectionTypeELFDynamicSymbols:
3640b57cec5SDimitry Andric case eSectionTypeELFRelocationEntries:
3650b57cec5SDimitry Andric case eSectionTypeELFDynamicLinkInfo:
3660b57cec5SDimitry Andric case eSectionTypeOther:
3670b57cec5SDimitry Andric return AddressClass::eUnknown;
3680b57cec5SDimitry Andric case eSectionTypeAbsoluteAddress:
3690b57cec5SDimitry Andric // In case of absolute sections decide the address class based on
3700b57cec5SDimitry Andric // the symbol type because the section type isn't specify if it is
3710b57cec5SDimitry Andric // a code or a data section.
3720b57cec5SDimitry Andric break;
3730b57cec5SDimitry Andric }
3740b57cec5SDimitry Andric }
3750b57cec5SDimitry Andric }
3760b57cec5SDimitry Andric
3770b57cec5SDimitry Andric const SymbolType symbol_type = symbol->GetType();
3780b57cec5SDimitry Andric switch (symbol_type) {
3790b57cec5SDimitry Andric case eSymbolTypeAny:
3800b57cec5SDimitry Andric return AddressClass::eUnknown;
3810b57cec5SDimitry Andric case eSymbolTypeAbsolute:
3820b57cec5SDimitry Andric return AddressClass::eUnknown;
3830b57cec5SDimitry Andric case eSymbolTypeCode:
3840b57cec5SDimitry Andric return AddressClass::eCode;
3850b57cec5SDimitry Andric case eSymbolTypeTrampoline:
3860b57cec5SDimitry Andric return AddressClass::eCode;
3870b57cec5SDimitry Andric case eSymbolTypeResolver:
3880b57cec5SDimitry Andric return AddressClass::eCode;
3890b57cec5SDimitry Andric case eSymbolTypeData:
3900b57cec5SDimitry Andric return AddressClass::eData;
3910b57cec5SDimitry Andric case eSymbolTypeRuntime:
3920b57cec5SDimitry Andric return AddressClass::eRuntime;
3930b57cec5SDimitry Andric case eSymbolTypeException:
3940b57cec5SDimitry Andric return AddressClass::eRuntime;
3950b57cec5SDimitry Andric case eSymbolTypeSourceFile:
3960b57cec5SDimitry Andric return AddressClass::eDebug;
3970b57cec5SDimitry Andric case eSymbolTypeHeaderFile:
3980b57cec5SDimitry Andric return AddressClass::eDebug;
3990b57cec5SDimitry Andric case eSymbolTypeObjectFile:
4000b57cec5SDimitry Andric return AddressClass::eDebug;
4010b57cec5SDimitry Andric case eSymbolTypeCommonBlock:
4020b57cec5SDimitry Andric return AddressClass::eDebug;
4030b57cec5SDimitry Andric case eSymbolTypeBlock:
4040b57cec5SDimitry Andric return AddressClass::eDebug;
4050b57cec5SDimitry Andric case eSymbolTypeLocal:
4060b57cec5SDimitry Andric return AddressClass::eData;
4070b57cec5SDimitry Andric case eSymbolTypeParam:
4080b57cec5SDimitry Andric return AddressClass::eData;
4090b57cec5SDimitry Andric case eSymbolTypeVariable:
4100b57cec5SDimitry Andric return AddressClass::eData;
4110b57cec5SDimitry Andric case eSymbolTypeVariableType:
4120b57cec5SDimitry Andric return AddressClass::eDebug;
4130b57cec5SDimitry Andric case eSymbolTypeLineEntry:
4140b57cec5SDimitry Andric return AddressClass::eDebug;
4150b57cec5SDimitry Andric case eSymbolTypeLineHeader:
4160b57cec5SDimitry Andric return AddressClass::eDebug;
4170b57cec5SDimitry Andric case eSymbolTypeScopeBegin:
4180b57cec5SDimitry Andric return AddressClass::eDebug;
4190b57cec5SDimitry Andric case eSymbolTypeScopeEnd:
4200b57cec5SDimitry Andric return AddressClass::eDebug;
4210b57cec5SDimitry Andric case eSymbolTypeAdditional:
4220b57cec5SDimitry Andric return AddressClass::eUnknown;
4230b57cec5SDimitry Andric case eSymbolTypeCompiler:
4240b57cec5SDimitry Andric return AddressClass::eDebug;
4250b57cec5SDimitry Andric case eSymbolTypeInstrumentation:
4260b57cec5SDimitry Andric return AddressClass::eDebug;
4270b57cec5SDimitry Andric case eSymbolTypeUndefined:
4280b57cec5SDimitry Andric return AddressClass::eUnknown;
4290b57cec5SDimitry Andric case eSymbolTypeObjCClass:
4300b57cec5SDimitry Andric return AddressClass::eRuntime;
4310b57cec5SDimitry Andric case eSymbolTypeObjCMetaClass:
4320b57cec5SDimitry Andric return AddressClass::eRuntime;
4330b57cec5SDimitry Andric case eSymbolTypeObjCIVar:
4340b57cec5SDimitry Andric return AddressClass::eRuntime;
4350b57cec5SDimitry Andric case eSymbolTypeReExported:
4360b57cec5SDimitry Andric return AddressClass::eRuntime;
4370b57cec5SDimitry Andric }
4380b57cec5SDimitry Andric }
4390b57cec5SDimitry Andric }
4400b57cec5SDimitry Andric return AddressClass::eUnknown;
4410b57cec5SDimitry Andric }
4420b57cec5SDimitry Andric
ReadMemory(const ProcessSP & process_sp,lldb::addr_t addr,size_t byte_size)4430b57cec5SDimitry Andric DataBufferSP ObjectFile::ReadMemory(const ProcessSP &process_sp,
4440b57cec5SDimitry Andric lldb::addr_t addr, size_t byte_size) {
4450b57cec5SDimitry Andric DataBufferSP data_sp;
4460b57cec5SDimitry Andric if (process_sp) {
4470b57cec5SDimitry Andric std::unique_ptr<DataBufferHeap> data_up(new DataBufferHeap(byte_size, 0));
4480b57cec5SDimitry Andric Status error;
4490b57cec5SDimitry Andric const size_t bytes_read = process_sp->ReadMemory(
4500b57cec5SDimitry Andric addr, data_up->GetBytes(), data_up->GetByteSize(), error);
4510b57cec5SDimitry Andric if (bytes_read == byte_size)
4520b57cec5SDimitry Andric data_sp.reset(data_up.release());
4530b57cec5SDimitry Andric }
4540b57cec5SDimitry Andric return data_sp;
4550b57cec5SDimitry Andric }
4560b57cec5SDimitry Andric
GetData(lldb::offset_t offset,size_t length,DataExtractor & data) const4570b57cec5SDimitry Andric size_t ObjectFile::GetData(lldb::offset_t offset, size_t length,
4580b57cec5SDimitry Andric DataExtractor &data) const {
4590b57cec5SDimitry Andric // The entire file has already been mmap'ed into m_data, so just copy from
4600b57cec5SDimitry Andric // there as the back mmap buffer will be shared with shared pointers.
4610b57cec5SDimitry Andric return data.SetData(m_data, offset, length);
4620b57cec5SDimitry Andric }
4630b57cec5SDimitry Andric
CopyData(lldb::offset_t offset,size_t length,void * dst) const4640b57cec5SDimitry Andric size_t ObjectFile::CopyData(lldb::offset_t offset, size_t length,
4650b57cec5SDimitry Andric void *dst) const {
4660b57cec5SDimitry Andric // The entire file has already been mmap'ed into m_data, so just copy from
4670b57cec5SDimitry Andric // there Note that the data remains in target byte order.
4680b57cec5SDimitry Andric return m_data.CopyData(offset, length, dst);
4690b57cec5SDimitry Andric }
4700b57cec5SDimitry Andric
ReadSectionData(Section * section,lldb::offset_t section_offset,void * dst,size_t dst_len)4710b57cec5SDimitry Andric size_t ObjectFile::ReadSectionData(Section *section,
4720b57cec5SDimitry Andric lldb::offset_t section_offset, void *dst,
4730b57cec5SDimitry Andric size_t dst_len) {
4740b57cec5SDimitry Andric assert(section);
4750b57cec5SDimitry Andric section_offset *= section->GetTargetByteSize();
4760b57cec5SDimitry Andric
4770b57cec5SDimitry Andric // If some other objectfile owns this data, pass this to them.
4780b57cec5SDimitry Andric if (section->GetObjectFile() != this)
4790b57cec5SDimitry Andric return section->GetObjectFile()->ReadSectionData(section, section_offset,
4800b57cec5SDimitry Andric dst, dst_len);
4810b57cec5SDimitry Andric
482*af732203SDimitry Andric if (!section->IsRelocated())
483*af732203SDimitry Andric RelocateSection(section);
484*af732203SDimitry Andric
4850b57cec5SDimitry Andric if (IsInMemory()) {
4860b57cec5SDimitry Andric ProcessSP process_sp(m_process_wp.lock());
4870b57cec5SDimitry Andric if (process_sp) {
4880b57cec5SDimitry Andric Status error;
4890b57cec5SDimitry Andric const addr_t base_load_addr =
4900b57cec5SDimitry Andric section->GetLoadBaseAddress(&process_sp->GetTarget());
4910b57cec5SDimitry Andric if (base_load_addr != LLDB_INVALID_ADDRESS)
4920b57cec5SDimitry Andric return process_sp->ReadMemory(base_load_addr + section_offset, dst,
4930b57cec5SDimitry Andric dst_len, error);
4940b57cec5SDimitry Andric }
4950b57cec5SDimitry Andric } else {
4960b57cec5SDimitry Andric const lldb::offset_t section_file_size = section->GetFileSize();
4970b57cec5SDimitry Andric if (section_offset < section_file_size) {
4980b57cec5SDimitry Andric const size_t section_bytes_left = section_file_size - section_offset;
4990b57cec5SDimitry Andric size_t section_dst_len = dst_len;
5000b57cec5SDimitry Andric if (section_dst_len > section_bytes_left)
5010b57cec5SDimitry Andric section_dst_len = section_bytes_left;
5020b57cec5SDimitry Andric return CopyData(section->GetFileOffset() + section_offset,
5030b57cec5SDimitry Andric section_dst_len, dst);
5040b57cec5SDimitry Andric } else {
5050b57cec5SDimitry Andric if (section->GetType() == eSectionTypeZeroFill) {
5060b57cec5SDimitry Andric const uint64_t section_size = section->GetByteSize();
5070b57cec5SDimitry Andric const uint64_t section_bytes_left = section_size - section_offset;
5080b57cec5SDimitry Andric uint64_t section_dst_len = dst_len;
5090b57cec5SDimitry Andric if (section_dst_len > section_bytes_left)
5100b57cec5SDimitry Andric section_dst_len = section_bytes_left;
5110b57cec5SDimitry Andric memset(dst, 0, section_dst_len);
5120b57cec5SDimitry Andric return section_dst_len;
5130b57cec5SDimitry Andric }
5140b57cec5SDimitry Andric }
5150b57cec5SDimitry Andric }
5160b57cec5SDimitry Andric return 0;
5170b57cec5SDimitry Andric }
5180b57cec5SDimitry Andric
5190b57cec5SDimitry Andric // Get the section data the file on disk
ReadSectionData(Section * section,DataExtractor & section_data)5200b57cec5SDimitry Andric size_t ObjectFile::ReadSectionData(Section *section,
5210b57cec5SDimitry Andric DataExtractor §ion_data) {
5220b57cec5SDimitry Andric // If some other objectfile owns this data, pass this to them.
5230b57cec5SDimitry Andric if (section->GetObjectFile() != this)
5240b57cec5SDimitry Andric return section->GetObjectFile()->ReadSectionData(section, section_data);
5250b57cec5SDimitry Andric
526*af732203SDimitry Andric if (!section->IsRelocated())
527*af732203SDimitry Andric RelocateSection(section);
528*af732203SDimitry Andric
5290b57cec5SDimitry Andric if (IsInMemory()) {
5300b57cec5SDimitry Andric ProcessSP process_sp(m_process_wp.lock());
5310b57cec5SDimitry Andric if (process_sp) {
5320b57cec5SDimitry Andric const addr_t base_load_addr =
5330b57cec5SDimitry Andric section->GetLoadBaseAddress(&process_sp->GetTarget());
5340b57cec5SDimitry Andric if (base_load_addr != LLDB_INVALID_ADDRESS) {
5350b57cec5SDimitry Andric DataBufferSP data_sp(
5360b57cec5SDimitry Andric ReadMemory(process_sp, base_load_addr, section->GetByteSize()));
5370b57cec5SDimitry Andric if (data_sp) {
5380b57cec5SDimitry Andric section_data.SetData(data_sp, 0, data_sp->GetByteSize());
5390b57cec5SDimitry Andric section_data.SetByteOrder(process_sp->GetByteOrder());
5400b57cec5SDimitry Andric section_data.SetAddressByteSize(process_sp->GetAddressByteSize());
5410b57cec5SDimitry Andric return section_data.GetByteSize();
5420b57cec5SDimitry Andric }
5430b57cec5SDimitry Andric }
5440b57cec5SDimitry Andric }
545*af732203SDimitry Andric }
546*af732203SDimitry Andric
5470b57cec5SDimitry Andric // The object file now contains a full mmap'ed copy of the object file
5480b57cec5SDimitry Andric // data, so just use this
5490b57cec5SDimitry Andric return GetData(section->GetFileOffset(), section->GetFileSize(),
5500b57cec5SDimitry Andric section_data);
5510b57cec5SDimitry Andric }
5520b57cec5SDimitry Andric
SplitArchivePathWithObject(llvm::StringRef path_with_object,FileSpec & archive_file,ConstString & archive_object,bool must_exist)5539dba64beSDimitry Andric bool ObjectFile::SplitArchivePathWithObject(llvm::StringRef path_with_object,
5540b57cec5SDimitry Andric FileSpec &archive_file,
5550b57cec5SDimitry Andric ConstString &archive_object,
5560b57cec5SDimitry Andric bool must_exist) {
5579dba64beSDimitry Andric size_t len = path_with_object.size();
5589dba64beSDimitry Andric if (len < 2 || path_with_object.back() != ')')
5590b57cec5SDimitry Andric return false;
5609dba64beSDimitry Andric llvm::StringRef archive = path_with_object.substr(0, path_with_object.rfind('('));
5619dba64beSDimitry Andric if (archive.empty())
5629dba64beSDimitry Andric return false;
5639dba64beSDimitry Andric llvm::StringRef object = path_with_object.substr(archive.size() + 1).drop_back();
5649dba64beSDimitry Andric archive_file.SetFile(archive, FileSpec::Style::native);
5659dba64beSDimitry Andric if (must_exist && !FileSystem::Instance().Exists(archive_file))
5669dba64beSDimitry Andric return false;
5679dba64beSDimitry Andric archive_object.SetString(object);
5689dba64beSDimitry Andric return true;
5690b57cec5SDimitry Andric }
5700b57cec5SDimitry Andric
ClearSymtab()5710b57cec5SDimitry Andric void ObjectFile::ClearSymtab() {
5720b57cec5SDimitry Andric ModuleSP module_sp(GetModule());
5730b57cec5SDimitry Andric if (module_sp) {
5740b57cec5SDimitry Andric std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
5750b57cec5SDimitry Andric Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OBJECT));
5769dba64beSDimitry Andric LLDB_LOGF(log, "%p ObjectFile::ClearSymtab () symtab = %p",
5770b57cec5SDimitry Andric static_cast<void *>(this),
5780b57cec5SDimitry Andric static_cast<void *>(m_symtab_up.get()));
5790b57cec5SDimitry Andric m_symtab_up.reset();
5800b57cec5SDimitry Andric }
5810b57cec5SDimitry Andric }
5820b57cec5SDimitry Andric
GetSectionList(bool update_module_section_list)5830b57cec5SDimitry Andric SectionList *ObjectFile::GetSectionList(bool update_module_section_list) {
5840b57cec5SDimitry Andric if (m_sections_up == nullptr) {
5850b57cec5SDimitry Andric if (update_module_section_list) {
5860b57cec5SDimitry Andric ModuleSP module_sp(GetModule());
5870b57cec5SDimitry Andric if (module_sp) {
5880b57cec5SDimitry Andric std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
5890b57cec5SDimitry Andric CreateSections(*module_sp->GetUnifiedSectionList());
5900b57cec5SDimitry Andric }
5910b57cec5SDimitry Andric } else {
5920b57cec5SDimitry Andric SectionList unified_section_list;
5930b57cec5SDimitry Andric CreateSections(unified_section_list);
5940b57cec5SDimitry Andric }
5950b57cec5SDimitry Andric }
5960b57cec5SDimitry Andric return m_sections_up.get();
5970b57cec5SDimitry Andric }
5980b57cec5SDimitry Andric
5990b57cec5SDimitry Andric lldb::SymbolType
GetSymbolTypeFromName(llvm::StringRef name,lldb::SymbolType symbol_type_hint)6000b57cec5SDimitry Andric ObjectFile::GetSymbolTypeFromName(llvm::StringRef name,
6010b57cec5SDimitry Andric lldb::SymbolType symbol_type_hint) {
6020b57cec5SDimitry Andric if (!name.empty()) {
6030b57cec5SDimitry Andric if (name.startswith("_OBJC_")) {
6040b57cec5SDimitry Andric // ObjC
6050b57cec5SDimitry Andric if (name.startswith("_OBJC_CLASS_$_"))
6060b57cec5SDimitry Andric return lldb::eSymbolTypeObjCClass;
6070b57cec5SDimitry Andric if (name.startswith("_OBJC_METACLASS_$_"))
6080b57cec5SDimitry Andric return lldb::eSymbolTypeObjCMetaClass;
6090b57cec5SDimitry Andric if (name.startswith("_OBJC_IVAR_$_"))
6100b57cec5SDimitry Andric return lldb::eSymbolTypeObjCIVar;
6110b57cec5SDimitry Andric } else if (name.startswith(".objc_class_name_")) {
6120b57cec5SDimitry Andric // ObjC v1
6130b57cec5SDimitry Andric return lldb::eSymbolTypeObjCClass;
6140b57cec5SDimitry Andric }
6150b57cec5SDimitry Andric }
6160b57cec5SDimitry Andric return symbol_type_hint;
6170b57cec5SDimitry Andric }
6180b57cec5SDimitry Andric
6190b57cec5SDimitry Andric std::vector<ObjectFile::LoadableData>
GetLoadableData(Target & target)6200b57cec5SDimitry Andric ObjectFile::GetLoadableData(Target &target) {
6210b57cec5SDimitry Andric std::vector<LoadableData> loadables;
6220b57cec5SDimitry Andric SectionList *section_list = GetSectionList();
6230b57cec5SDimitry Andric if (!section_list)
6240b57cec5SDimitry Andric return loadables;
6250b57cec5SDimitry Andric // Create a list of loadable data from loadable sections
6260b57cec5SDimitry Andric size_t section_count = section_list->GetNumSections(0);
6270b57cec5SDimitry Andric for (size_t i = 0; i < section_count; ++i) {
6280b57cec5SDimitry Andric LoadableData loadable;
6290b57cec5SDimitry Andric SectionSP section_sp = section_list->GetSectionAtIndex(i);
6300b57cec5SDimitry Andric loadable.Dest =
6310b57cec5SDimitry Andric target.GetSectionLoadList().GetSectionLoadAddress(section_sp);
6320b57cec5SDimitry Andric if (loadable.Dest == LLDB_INVALID_ADDRESS)
6330b57cec5SDimitry Andric continue;
6340b57cec5SDimitry Andric // We can skip sections like bss
6350b57cec5SDimitry Andric if (section_sp->GetFileSize() == 0)
6360b57cec5SDimitry Andric continue;
6370b57cec5SDimitry Andric DataExtractor section_data;
6380b57cec5SDimitry Andric section_sp->GetSectionData(section_data);
6390b57cec5SDimitry Andric loadable.Contents = llvm::ArrayRef<uint8_t>(section_data.GetDataStart(),
6400b57cec5SDimitry Andric section_data.GetByteSize());
6410b57cec5SDimitry Andric loadables.push_back(loadable);
6420b57cec5SDimitry Andric }
6430b57cec5SDimitry Andric return loadables;
6440b57cec5SDimitry Andric }
6450b57cec5SDimitry Andric
CreateCallFrameInfo()6469dba64beSDimitry Andric std::unique_ptr<CallFrameInfo> ObjectFile::CreateCallFrameInfo() {
6479dba64beSDimitry Andric return {};
6489dba64beSDimitry Andric }
6499dba64beSDimitry Andric
RelocateSection(lldb_private::Section * section)6500b57cec5SDimitry Andric void ObjectFile::RelocateSection(lldb_private::Section *section)
6510b57cec5SDimitry Andric {
6520b57cec5SDimitry Andric }
6530b57cec5SDimitry Andric
MapFileData(const FileSpec & file,uint64_t Size,uint64_t Offset)6540b57cec5SDimitry Andric DataBufferSP ObjectFile::MapFileData(const FileSpec &file, uint64_t Size,
6550b57cec5SDimitry Andric uint64_t Offset) {
6560b57cec5SDimitry Andric return FileSystem::Instance().CreateDataBuffer(file.GetPath(), Size, Offset);
6570b57cec5SDimitry Andric }
6580b57cec5SDimitry Andric
format(const ObjectFile::Type & type,raw_ostream & OS,StringRef Style)6590b57cec5SDimitry Andric void llvm::format_provider<ObjectFile::Type>::format(
6600b57cec5SDimitry Andric const ObjectFile::Type &type, raw_ostream &OS, StringRef Style) {
6610b57cec5SDimitry Andric switch (type) {
6620b57cec5SDimitry Andric case ObjectFile::eTypeInvalid:
6630b57cec5SDimitry Andric OS << "invalid";
6640b57cec5SDimitry Andric break;
6650b57cec5SDimitry Andric case ObjectFile::eTypeCoreFile:
6660b57cec5SDimitry Andric OS << "core file";
6670b57cec5SDimitry Andric break;
6680b57cec5SDimitry Andric case ObjectFile::eTypeExecutable:
6690b57cec5SDimitry Andric OS << "executable";
6700b57cec5SDimitry Andric break;
6710b57cec5SDimitry Andric case ObjectFile::eTypeDebugInfo:
6720b57cec5SDimitry Andric OS << "debug info";
6730b57cec5SDimitry Andric break;
6740b57cec5SDimitry Andric case ObjectFile::eTypeDynamicLinker:
6750b57cec5SDimitry Andric OS << "dynamic linker";
6760b57cec5SDimitry Andric break;
6770b57cec5SDimitry Andric case ObjectFile::eTypeObjectFile:
6780b57cec5SDimitry Andric OS << "object file";
6790b57cec5SDimitry Andric break;
6800b57cec5SDimitry Andric case ObjectFile::eTypeSharedLibrary:
6810b57cec5SDimitry Andric OS << "shared library";
6820b57cec5SDimitry Andric break;
6830b57cec5SDimitry Andric case ObjectFile::eTypeStubLibrary:
6840b57cec5SDimitry Andric OS << "stub library";
6850b57cec5SDimitry Andric break;
6860b57cec5SDimitry Andric case ObjectFile::eTypeJIT:
6870b57cec5SDimitry Andric OS << "jit";
6880b57cec5SDimitry Andric break;
6890b57cec5SDimitry Andric case ObjectFile::eTypeUnknown:
6900b57cec5SDimitry Andric OS << "unknown";
6910b57cec5SDimitry Andric break;
6920b57cec5SDimitry Andric }
6930b57cec5SDimitry Andric }
6940b57cec5SDimitry Andric
format(const ObjectFile::Strata & strata,raw_ostream & OS,StringRef Style)6950b57cec5SDimitry Andric void llvm::format_provider<ObjectFile::Strata>::format(
6960b57cec5SDimitry Andric const ObjectFile::Strata &strata, raw_ostream &OS, StringRef Style) {
6970b57cec5SDimitry Andric switch (strata) {
6980b57cec5SDimitry Andric case ObjectFile::eStrataInvalid:
6990b57cec5SDimitry Andric OS << "invalid";
7000b57cec5SDimitry Andric break;
7010b57cec5SDimitry Andric case ObjectFile::eStrataUnknown:
7020b57cec5SDimitry Andric OS << "unknown";
7030b57cec5SDimitry Andric break;
7040b57cec5SDimitry Andric case ObjectFile::eStrataUser:
7050b57cec5SDimitry Andric OS << "user";
7060b57cec5SDimitry Andric break;
7070b57cec5SDimitry Andric case ObjectFile::eStrataKernel:
7080b57cec5SDimitry Andric OS << "kernel";
7090b57cec5SDimitry Andric break;
7100b57cec5SDimitry Andric case ObjectFile::eStrataRawImage:
7110b57cec5SDimitry Andric OS << "raw image";
7120b57cec5SDimitry Andric break;
7130b57cec5SDimitry Andric case ObjectFile::eStrataJIT:
7140b57cec5SDimitry Andric OS << "jit";
7150b57cec5SDimitry Andric break;
7160b57cec5SDimitry Andric }
7170b57cec5SDimitry Andric }
718