1ac7ddfbfSEd Maste //===-- ObjectFile.cpp ------------------------------------------*- C++ -*-===//
2ac7ddfbfSEd Maste //
3ac7ddfbfSEd Maste // The LLVM Compiler Infrastructure
4ac7ddfbfSEd Maste //
5ac7ddfbfSEd Maste // This file is distributed under the University of Illinois Open Source
6ac7ddfbfSEd Maste // License. See LICENSE.TXT for details.
7ac7ddfbfSEd Maste //
8ac7ddfbfSEd Maste //===----------------------------------------------------------------------===//
9ac7ddfbfSEd Maste
10435933ddSDimitry Andric #include "lldb/Symbol/ObjectFile.h"
11ac7ddfbfSEd Maste #include "lldb/Core/Module.h"
12ac7ddfbfSEd Maste #include "lldb/Core/ModuleSpec.h"
13ac7ddfbfSEd Maste #include "lldb/Core/PluginManager.h"
14ac7ddfbfSEd Maste #include "lldb/Core/Section.h"
15ac7ddfbfSEd Maste #include "lldb/Symbol/ObjectContainer.h"
16ac7ddfbfSEd Maste #include "lldb/Symbol/SymbolFile.h"
17ac7ddfbfSEd Maste #include "lldb/Target/Process.h"
18f678e45dSDimitry Andric #include "lldb/Target/SectionLoadList.h"
19f678e45dSDimitry Andric #include "lldb/Target/Target.h"
20f678e45dSDimitry Andric #include "lldb/Utility/DataBuffer.h"
21f678e45dSDimitry Andric #include "lldb/Utility/DataBufferHeap.h"
22f678e45dSDimitry Andric #include "lldb/Utility/Log.h"
23f678e45dSDimitry Andric #include "lldb/Utility/RegularExpression.h"
24a580b014SDimitry Andric #include "lldb/Utility/Timer.h"
25435933ddSDimitry Andric #include "lldb/lldb-private.h"
26ac7ddfbfSEd Maste
27ac7ddfbfSEd Maste using namespace lldb;
28ac7ddfbfSEd Maste using namespace lldb_private;
29ac7ddfbfSEd Maste
30ac7ddfbfSEd Maste 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)31435933ddSDimitry Andric ObjectFile::FindPlugin(const lldb::ModuleSP &module_sp, const FileSpec *file,
32435933ddSDimitry Andric lldb::offset_t file_offset, lldb::offset_t file_size,
33435933ddSDimitry Andric DataBufferSP &data_sp, lldb::offset_t &data_offset) {
34ac7ddfbfSEd Maste ObjectFileSP object_file_sp;
35ac7ddfbfSEd Maste
36435933ddSDimitry Andric if (module_sp) {
375517e702SDimitry Andric static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
38435933ddSDimitry Andric Timer scoped_timer(
395517e702SDimitry Andric func_cat,
40435933ddSDimitry Andric "ObjectFile::FindPlugin (module = %s, file = %p, file_offset = "
41435933ddSDimitry Andric "0x%8.8" PRIx64 ", file_size = 0x%8.8" PRIx64 ")",
42ac7ddfbfSEd Maste module_sp->GetFileSpec().GetPath().c_str(),
43435933ddSDimitry Andric static_cast<const void *>(file), static_cast<uint64_t>(file_offset),
440127ef0fSEd Maste static_cast<uint64_t>(file_size));
45435933ddSDimitry Andric if (file) {
46ac7ddfbfSEd Maste FileSpec archive_file;
47ac7ddfbfSEd Maste ObjectContainerCreateInstance create_object_container_callback;
48ac7ddfbfSEd Maste
49*b5893f02SDimitry Andric const bool file_exists = FileSystem::Instance().Exists(*file);
50435933ddSDimitry Andric if (!data_sp) {
514ba319b5SDimitry Andric // We have an object name which most likely means we have a .o file in
524ba319b5SDimitry Andric // a static archive (.a file). Try and see if we have a cached archive
534ba319b5SDimitry Andric // first without reading any data first
54435933ddSDimitry Andric if (file_exists && module_sp->GetObjectName()) {
55435933ddSDimitry Andric for (uint32_t idx = 0;
56435933ddSDimitry Andric (create_object_container_callback =
57435933ddSDimitry Andric PluginManager::GetObjectContainerCreateCallbackAtIndex(
58435933ddSDimitry Andric idx)) != nullptr;
59435933ddSDimitry Andric ++idx) {
60435933ddSDimitry Andric std::unique_ptr<ObjectContainer> object_container_ap(
61435933ddSDimitry Andric create_object_container_callback(module_sp, data_sp,
62435933ddSDimitry Andric data_offset, file, file_offset,
63435933ddSDimitry Andric file_size));
64ac7ddfbfSEd Maste
65ac7ddfbfSEd Maste if (object_container_ap.get())
66ac7ddfbfSEd Maste object_file_sp = object_container_ap->GetObjectFile(file);
67ac7ddfbfSEd Maste
68ac7ddfbfSEd Maste if (object_file_sp.get())
69ac7ddfbfSEd Maste return object_file_sp;
70ac7ddfbfSEd Maste }
71ac7ddfbfSEd Maste }
724ba319b5SDimitry Andric // Ok, we didn't find any containers that have a named object, now lets
734ba319b5SDimitry Andric // read the first 512 bytes from the file so the object file and object
744ba319b5SDimitry Andric // container plug-ins can use these bytes to see if they can parse this
754ba319b5SDimitry Andric // file.
76435933ddSDimitry Andric if (file_size > 0) {
77*b5893f02SDimitry Andric data_sp = FileSystem::Instance().CreateDataBuffer(file->GetPath(),
78*b5893f02SDimitry Andric 512, file_offset);
79ac7ddfbfSEd Maste data_offset = 0;
80ac7ddfbfSEd Maste }
81ac7ddfbfSEd Maste }
82ac7ddfbfSEd Maste
83435933ddSDimitry Andric if (!data_sp || data_sp->GetByteSize() == 0) {
84ac7ddfbfSEd Maste // Check for archive file with format "/path/to/archive.a(object.o)"
85ac7ddfbfSEd Maste char path_with_object[PATH_MAX * 2];
86435933ddSDimitry Andric module_sp->GetFileSpec().GetPath(path_with_object,
87435933ddSDimitry Andric sizeof(path_with_object));
88ac7ddfbfSEd Maste
89ac7ddfbfSEd Maste ConstString archive_object;
90ac7ddfbfSEd Maste const bool must_exist = true;
91435933ddSDimitry Andric if (ObjectFile::SplitArchivePathWithObject(
92435933ddSDimitry Andric path_with_object, archive_file, archive_object, must_exist)) {
93*b5893f02SDimitry Andric file_size = FileSystem::Instance().GetByteSize(archive_file);
94435933ddSDimitry Andric if (file_size > 0) {
95ac7ddfbfSEd Maste file = &archive_file;
96ac7ddfbfSEd Maste module_sp->SetFileSpecAndObjectName(archive_file, archive_object);
97435933ddSDimitry Andric // Check if this is a object container by iterating through all
984ba319b5SDimitry Andric // object container plugin instances and then trying to get an
994ba319b5SDimitry Andric // object file from the container plugins since we had a name.
1004ba319b5SDimitry Andric // Also, don't read
101ac7ddfbfSEd Maste // ANY data in case there is data cached in the container plug-ins
1024ba319b5SDimitry Andric // (like BSD archives caching the contained objects within an
1034ba319b5SDimitry Andric // file).
104435933ddSDimitry Andric for (uint32_t idx = 0;
105435933ddSDimitry Andric (create_object_container_callback =
106435933ddSDimitry Andric PluginManager::GetObjectContainerCreateCallbackAtIndex(
107435933ddSDimitry Andric idx)) != nullptr;
108435933ddSDimitry Andric ++idx) {
109435933ddSDimitry Andric std::unique_ptr<ObjectContainer> object_container_ap(
110435933ddSDimitry Andric create_object_container_callback(module_sp, data_sp,
111435933ddSDimitry Andric data_offset, file,
112435933ddSDimitry Andric file_offset, file_size));
113ac7ddfbfSEd Maste
114ac7ddfbfSEd Maste if (object_container_ap.get())
115ac7ddfbfSEd Maste object_file_sp = object_container_ap->GetObjectFile(file);
116ac7ddfbfSEd Maste
117ac7ddfbfSEd Maste if (object_file_sp.get())
118ac7ddfbfSEd Maste return object_file_sp;
119ac7ddfbfSEd Maste }
1204ba319b5SDimitry Andric // We failed to find any cached object files in the container plug-
1214ba319b5SDimitry Andric // ins, so lets read the first 512 bytes and try again below...
122*b5893f02SDimitry Andric data_sp = FileSystem::Instance().CreateDataBuffer(
123*b5893f02SDimitry Andric archive_file.GetPath(), 512, file_offset);
124ac7ddfbfSEd Maste }
125ac7ddfbfSEd Maste }
126ac7ddfbfSEd Maste }
127ac7ddfbfSEd Maste
128435933ddSDimitry Andric if (data_sp && data_sp->GetByteSize() > 0) {
1294ba319b5SDimitry Andric // Check if this is a normal object file by iterating through all
1304ba319b5SDimitry Andric // object file plugin instances.
131ac7ddfbfSEd Maste ObjectFileCreateInstance create_object_file_callback;
132435933ddSDimitry Andric for (uint32_t idx = 0;
133435933ddSDimitry Andric (create_object_file_callback =
134435933ddSDimitry Andric PluginManager::GetObjectFileCreateCallbackAtIndex(idx)) !=
135435933ddSDimitry Andric nullptr;
136435933ddSDimitry Andric ++idx) {
137435933ddSDimitry Andric object_file_sp.reset(create_object_file_callback(
138435933ddSDimitry Andric module_sp, data_sp, data_offset, file, file_offset, file_size));
139ac7ddfbfSEd Maste if (object_file_sp.get())
140ac7ddfbfSEd Maste return object_file_sp;
141ac7ddfbfSEd Maste }
142ac7ddfbfSEd Maste
1434ba319b5SDimitry Andric // Check if this is a object container by iterating through all object
1444ba319b5SDimitry Andric // container plugin instances and then trying to get an object file
1454ba319b5SDimitry Andric // from the container.
146435933ddSDimitry Andric for (uint32_t idx = 0;
147435933ddSDimitry Andric (create_object_container_callback =
148435933ddSDimitry Andric PluginManager::GetObjectContainerCreateCallbackAtIndex(
149435933ddSDimitry Andric idx)) != nullptr;
150435933ddSDimitry Andric ++idx) {
151435933ddSDimitry Andric std::unique_ptr<ObjectContainer> object_container_ap(
152435933ddSDimitry Andric create_object_container_callback(module_sp, data_sp, data_offset,
153435933ddSDimitry Andric file, file_offset, file_size));
154ac7ddfbfSEd Maste
155ac7ddfbfSEd Maste if (object_container_ap.get())
156ac7ddfbfSEd Maste object_file_sp = object_container_ap->GetObjectFile(file);
157ac7ddfbfSEd Maste
158ac7ddfbfSEd Maste if (object_file_sp.get())
159ac7ddfbfSEd Maste return object_file_sp;
160ac7ddfbfSEd Maste }
161ac7ddfbfSEd Maste }
162ac7ddfbfSEd Maste }
163ac7ddfbfSEd Maste }
1644ba319b5SDimitry Andric // We didn't find it, so clear our shared pointer in case it contains
1654ba319b5SDimitry Andric // anything and return an empty shared pointer
166ac7ddfbfSEd Maste object_file_sp.reset();
167ac7ddfbfSEd Maste return object_file_sp;
168ac7ddfbfSEd Maste }
169ac7ddfbfSEd Maste
FindPlugin(const lldb::ModuleSP & module_sp,const ProcessSP & process_sp,lldb::addr_t header_addr,DataBufferSP & data_sp)170435933ddSDimitry Andric ObjectFileSP ObjectFile::FindPlugin(const lldb::ModuleSP &module_sp,
171ac7ddfbfSEd Maste const ProcessSP &process_sp,
172ac7ddfbfSEd Maste lldb::addr_t header_addr,
173435933ddSDimitry Andric DataBufferSP &data_sp) {
174ac7ddfbfSEd Maste ObjectFileSP object_file_sp;
175ac7ddfbfSEd Maste
176435933ddSDimitry Andric if (module_sp) {
1775517e702SDimitry Andric static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
1785517e702SDimitry Andric Timer scoped_timer(func_cat,
1795517e702SDimitry Andric "ObjectFile::FindPlugin (module = "
180435933ddSDimitry Andric "%s, process = %p, header_addr = "
181435933ddSDimitry Andric "0x%" PRIx64 ")",
182ac7ddfbfSEd Maste module_sp->GetFileSpec().GetPath().c_str(),
1830127ef0fSEd Maste static_cast<void *>(process_sp.get()), header_addr);
184ac7ddfbfSEd Maste uint32_t idx;
185ac7ddfbfSEd Maste
1864ba319b5SDimitry Andric // Check if this is a normal object file by iterating through all object
1874ba319b5SDimitry Andric // file plugin instances.
188ac7ddfbfSEd Maste ObjectFileCreateMemoryInstance create_callback;
189435933ddSDimitry Andric for (idx = 0;
190435933ddSDimitry Andric (create_callback =
191435933ddSDimitry Andric PluginManager::GetObjectFileCreateMemoryCallbackAtIndex(idx)) !=
192435933ddSDimitry Andric nullptr;
193435933ddSDimitry Andric ++idx) {
194435933ddSDimitry Andric object_file_sp.reset(
195435933ddSDimitry Andric create_callback(module_sp, data_sp, process_sp, header_addr));
196ac7ddfbfSEd Maste if (object_file_sp.get())
197ac7ddfbfSEd Maste return object_file_sp;
198ac7ddfbfSEd Maste }
199ac7ddfbfSEd Maste }
2000127ef0fSEd Maste
2014ba319b5SDimitry Andric // We didn't find it, so clear our shared pointer in case it contains
2024ba319b5SDimitry Andric // anything and return an empty shared pointer
203ac7ddfbfSEd Maste object_file_sp.reset();
204ac7ddfbfSEd Maste return object_file_sp;
205ac7ddfbfSEd Maste }
206ac7ddfbfSEd Maste
GetModuleSpecifications(const FileSpec & file,lldb::offset_t file_offset,lldb::offset_t file_size,ModuleSpecList & specs)207435933ddSDimitry Andric size_t ObjectFile::GetModuleSpecifications(const FileSpec &file,
208ac7ddfbfSEd Maste lldb::offset_t file_offset,
209ac7ddfbfSEd Maste lldb::offset_t file_size,
210435933ddSDimitry Andric ModuleSpecList &specs) {
211*b5893f02SDimitry Andric DataBufferSP data_sp =
212*b5893f02SDimitry Andric FileSystem::Instance().CreateDataBuffer(file.GetPath(), 512, file_offset);
213435933ddSDimitry Andric if (data_sp) {
214435933ddSDimitry Andric if (file_size == 0) {
215*b5893f02SDimitry Andric const lldb::offset_t actual_file_size =
216*b5893f02SDimitry Andric FileSystem::Instance().GetByteSize(file);
217ac7ddfbfSEd Maste if (actual_file_size > file_offset)
218ac7ddfbfSEd Maste file_size = actual_file_size - file_offset;
219ac7ddfbfSEd Maste }
220ac7ddfbfSEd Maste return ObjectFile::GetModuleSpecifications(file, // file spec
221ac7ddfbfSEd Maste data_sp, // data bytes
222ac7ddfbfSEd Maste 0, // data offset
223ac7ddfbfSEd Maste file_offset, // file offset
224ac7ddfbfSEd Maste file_size, // file length
225ac7ddfbfSEd Maste specs);
226ac7ddfbfSEd Maste }
227ac7ddfbfSEd Maste return 0;
228ac7ddfbfSEd Maste }
229ac7ddfbfSEd Maste
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)230435933ddSDimitry Andric size_t ObjectFile::GetModuleSpecifications(
231435933ddSDimitry Andric const lldb_private::FileSpec &file, lldb::DataBufferSP &data_sp,
232435933ddSDimitry Andric lldb::offset_t data_offset, lldb::offset_t file_offset,
233435933ddSDimitry Andric lldb::offset_t file_size, lldb_private::ModuleSpecList &specs) {
234ac7ddfbfSEd Maste const size_t initial_count = specs.GetSize();
235ac7ddfbfSEd Maste ObjectFileGetModuleSpecifications callback;
236ac7ddfbfSEd Maste uint32_t i;
237ac7ddfbfSEd Maste // Try the ObjectFile plug-ins
238435933ddSDimitry Andric for (i = 0;
239435933ddSDimitry Andric (callback =
240435933ddSDimitry Andric PluginManager::GetObjectFileGetModuleSpecificationsCallbackAtIndex(
241435933ddSDimitry Andric i)) != nullptr;
242435933ddSDimitry Andric ++i) {
243ac7ddfbfSEd Maste if (callback(file, data_sp, data_offset, file_offset, file_size, specs) > 0)
244ac7ddfbfSEd Maste return specs.GetSize() - initial_count;
245ac7ddfbfSEd Maste }
246ac7ddfbfSEd Maste
247ac7ddfbfSEd Maste // Try the ObjectContainer plug-ins
248435933ddSDimitry Andric for (i = 0;
249435933ddSDimitry Andric (callback = PluginManager::
250435933ddSDimitry Andric GetObjectContainerGetModuleSpecificationsCallbackAtIndex(i)) !=
251435933ddSDimitry Andric nullptr;
252435933ddSDimitry Andric ++i) {
253ac7ddfbfSEd Maste if (callback(file, data_sp, data_offset, file_offset, file_size, specs) > 0)
254ac7ddfbfSEd Maste return specs.GetSize() - initial_count;
255ac7ddfbfSEd Maste }
256ac7ddfbfSEd Maste return 0;
257ac7ddfbfSEd Maste }
258ac7ddfbfSEd Maste
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)259ac7ddfbfSEd Maste ObjectFile::ObjectFile(const lldb::ModuleSP &module_sp,
260ac7ddfbfSEd Maste const FileSpec *file_spec_ptr,
261435933ddSDimitry Andric lldb::offset_t file_offset, lldb::offset_t length,
2620127ef0fSEd Maste const lldb::DataBufferSP &data_sp,
263435933ddSDimitry Andric lldb::offset_t data_offset)
264435933ddSDimitry Andric : ModuleChild(module_sp),
265ac7ddfbfSEd Maste m_file(), // This file could be different from the original module's file
266435933ddSDimitry Andric m_type(eTypeInvalid), m_strata(eStrataInvalid),
267435933ddSDimitry Andric m_file_offset(file_offset), m_length(length), m_data(),
268435933ddSDimitry Andric m_unwind_table(*this), m_process_wp(),
269435933ddSDimitry Andric m_memory_addr(LLDB_INVALID_ADDRESS), m_sections_ap(), m_symtab_ap(),
270435933ddSDimitry Andric m_synthetic_symbol_idx(0) {
271ac7ddfbfSEd Maste if (file_spec_ptr)
272ac7ddfbfSEd Maste m_file = *file_spec_ptr;
273ac7ddfbfSEd Maste if (data_sp)
274ac7ddfbfSEd Maste m_data.SetData(data_sp, data_offset, length);
275ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OBJECT));
276ac7ddfbfSEd Maste if (log)
277435933ddSDimitry Andric log->Printf("%p ObjectFile::ObjectFile() module = %p (%s), file = %s, "
278435933ddSDimitry Andric "file_offset = 0x%8.8" PRIx64 ", size = %" PRIu64,
279435933ddSDimitry Andric static_cast<void *>(this), static_cast<void *>(module_sp.get()),
280ac7ddfbfSEd Maste module_sp->GetSpecificationDescription().c_str(),
281435933ddSDimitry Andric m_file ? m_file.GetPath().c_str() : "<NULL>", m_file_offset,
282435933ddSDimitry Andric m_length);
283ac7ddfbfSEd Maste }
284ac7ddfbfSEd Maste
ObjectFile(const lldb::ModuleSP & module_sp,const ProcessSP & process_sp,lldb::addr_t header_addr,DataBufferSP & header_data_sp)285ac7ddfbfSEd Maste ObjectFile::ObjectFile(const lldb::ModuleSP &module_sp,
286435933ddSDimitry Andric const ProcessSP &process_sp, lldb::addr_t header_addr,
287435933ddSDimitry Andric DataBufferSP &header_data_sp)
288435933ddSDimitry Andric : ModuleChild(module_sp), m_file(), m_type(eTypeInvalid),
289435933ddSDimitry Andric m_strata(eStrataInvalid), m_file_offset(0), m_length(0), m_data(),
290435933ddSDimitry Andric m_unwind_table(*this), m_process_wp(process_sp),
291435933ddSDimitry Andric m_memory_addr(header_addr), m_sections_ap(), m_symtab_ap(),
292435933ddSDimitry Andric m_synthetic_symbol_idx(0) {
293ac7ddfbfSEd Maste if (header_data_sp)
294ac7ddfbfSEd Maste m_data.SetData(header_data_sp, 0, header_data_sp->GetByteSize());
295ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OBJECT));
296ac7ddfbfSEd Maste if (log)
297435933ddSDimitry Andric log->Printf("%p ObjectFile::ObjectFile() module = %p (%s), process = %p, "
298435933ddSDimitry Andric "header_addr = 0x%" PRIx64,
299435933ddSDimitry Andric static_cast<void *>(this), static_cast<void *>(module_sp.get()),
300ac7ddfbfSEd Maste module_sp->GetSpecificationDescription().c_str(),
3010127ef0fSEd Maste static_cast<void *>(process_sp.get()), m_memory_addr);
302ac7ddfbfSEd Maste }
303ac7ddfbfSEd Maste
~ObjectFile()304435933ddSDimitry Andric ObjectFile::~ObjectFile() {
305ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OBJECT));
306ac7ddfbfSEd Maste if (log)
307435933ddSDimitry Andric log->Printf("%p ObjectFile::~ObjectFile ()\n", static_cast<void *>(this));
308ac7ddfbfSEd Maste }
309ac7ddfbfSEd Maste
SetModulesArchitecture(const ArchSpec & new_arch)310435933ddSDimitry Andric bool ObjectFile::SetModulesArchitecture(const ArchSpec &new_arch) {
311ac7ddfbfSEd Maste ModuleSP module_sp(GetModule());
312ac7ddfbfSEd Maste if (module_sp)
313ac7ddfbfSEd Maste return module_sp->SetArchitecture(new_arch);
314ac7ddfbfSEd Maste return false;
315ac7ddfbfSEd Maste }
316ac7ddfbfSEd Maste
GetAddressClass(addr_t file_addr)317435933ddSDimitry Andric AddressClass ObjectFile::GetAddressClass(addr_t file_addr) {
318ac7ddfbfSEd Maste Symtab *symtab = GetSymtab();
319435933ddSDimitry Andric if (symtab) {
320ac7ddfbfSEd Maste Symbol *symbol = symtab->FindSymbolContainingFileAddress(file_addr);
321435933ddSDimitry Andric if (symbol) {
322435933ddSDimitry Andric if (symbol->ValueIsAddress()) {
3231c3bbb01SEd Maste const SectionSP section_sp(symbol->GetAddressRef().GetSection());
324435933ddSDimitry Andric if (section_sp) {
325ac7ddfbfSEd Maste const SectionType section_type = section_sp->GetType();
326435933ddSDimitry Andric switch (section_type) {
3270127ef0fSEd Maste case eSectionTypeInvalid:
3284ba319b5SDimitry Andric return AddressClass::eUnknown;
3290127ef0fSEd Maste case eSectionTypeCode:
3304ba319b5SDimitry Andric return AddressClass::eCode;
3310127ef0fSEd Maste case eSectionTypeContainer:
3324ba319b5SDimitry Andric return AddressClass::eUnknown;
333ac7ddfbfSEd Maste case eSectionTypeData:
334ac7ddfbfSEd Maste case eSectionTypeDataCString:
335ac7ddfbfSEd Maste case eSectionTypeDataCStringPointers:
336ac7ddfbfSEd Maste case eSectionTypeDataSymbolAddress:
337ac7ddfbfSEd Maste case eSectionTypeData4:
338ac7ddfbfSEd Maste case eSectionTypeData8:
339ac7ddfbfSEd Maste case eSectionTypeData16:
340ac7ddfbfSEd Maste case eSectionTypeDataPointers:
341ac7ddfbfSEd Maste case eSectionTypeZeroFill:
342ac7ddfbfSEd Maste case eSectionTypeDataObjCMessageRefs:
343ac7ddfbfSEd Maste case eSectionTypeDataObjCCFStrings:
3449f2f44ceSEd Maste case eSectionTypeGoSymtab:
3454ba319b5SDimitry Andric return AddressClass::eData;
346ac7ddfbfSEd Maste case eSectionTypeDebug:
347ac7ddfbfSEd Maste case eSectionTypeDWARFDebugAbbrev:
348*b5893f02SDimitry Andric case eSectionTypeDWARFDebugAbbrevDwo:
3499f2f44ceSEd Maste case eSectionTypeDWARFDebugAddr:
350ac7ddfbfSEd Maste case eSectionTypeDWARFDebugAranges:
351acac075bSDimitry Andric case eSectionTypeDWARFDebugCuIndex:
352ac7ddfbfSEd Maste case eSectionTypeDWARFDebugFrame:
353ac7ddfbfSEd Maste case eSectionTypeDWARFDebugInfo:
354*b5893f02SDimitry Andric case eSectionTypeDWARFDebugInfoDwo:
355ac7ddfbfSEd Maste case eSectionTypeDWARFDebugLine:
356*b5893f02SDimitry Andric case eSectionTypeDWARFDebugLineStr:
357ac7ddfbfSEd Maste case eSectionTypeDWARFDebugLoc:
358*b5893f02SDimitry Andric case eSectionTypeDWARFDebugLocLists:
359ac7ddfbfSEd Maste case eSectionTypeDWARFDebugMacInfo:
3609f2f44ceSEd Maste case eSectionTypeDWARFDebugMacro:
3614ba319b5SDimitry Andric case eSectionTypeDWARFDebugNames:
362ac7ddfbfSEd Maste case eSectionTypeDWARFDebugPubNames:
363ac7ddfbfSEd Maste case eSectionTypeDWARFDebugPubTypes:
364ac7ddfbfSEd Maste case eSectionTypeDWARFDebugRanges:
365*b5893f02SDimitry Andric case eSectionTypeDWARFDebugRngLists:
366ac7ddfbfSEd Maste case eSectionTypeDWARFDebugStr:
367*b5893f02SDimitry Andric case eSectionTypeDWARFDebugStrDwo:
3689f2f44ceSEd Maste case eSectionTypeDWARFDebugStrOffsets:
369*b5893f02SDimitry Andric case eSectionTypeDWARFDebugStrOffsetsDwo:
3704ba319b5SDimitry Andric case eSectionTypeDWARFDebugTypes:
371ac7ddfbfSEd Maste case eSectionTypeDWARFAppleNames:
372ac7ddfbfSEd Maste case eSectionTypeDWARFAppleTypes:
373ac7ddfbfSEd Maste case eSectionTypeDWARFAppleNamespaces:
374ac7ddfbfSEd Maste case eSectionTypeDWARFAppleObjC:
3754ba319b5SDimitry Andric case eSectionTypeDWARFGNUDebugAltLink:
3764ba319b5SDimitry Andric return AddressClass::eDebug;
3770127ef0fSEd Maste case eSectionTypeEHFrame:
3789f2f44ceSEd Maste case eSectionTypeARMexidx:
3799f2f44ceSEd Maste case eSectionTypeARMextab:
3807aa51b79SEd Maste case eSectionTypeCompactUnwind:
3814ba319b5SDimitry Andric return AddressClass::eRuntime;
382ac7ddfbfSEd Maste case eSectionTypeELFSymbolTable:
383ac7ddfbfSEd Maste case eSectionTypeELFDynamicSymbols:
384ac7ddfbfSEd Maste case eSectionTypeELFRelocationEntries:
385ac7ddfbfSEd Maste case eSectionTypeELFDynamicLinkInfo:
3860127ef0fSEd Maste case eSectionTypeOther:
3874ba319b5SDimitry Andric return AddressClass::eUnknown;
3884bb0738eSEd Maste case eSectionTypeAbsoluteAddress:
389435933ddSDimitry Andric // In case of absolute sections decide the address class based on
3904ba319b5SDimitry Andric // the symbol type because the section type isn't specify if it is
3914ba319b5SDimitry Andric // a code or a data section.
3924bb0738eSEd Maste break;
393ac7ddfbfSEd Maste }
394ac7ddfbfSEd Maste }
395ac7ddfbfSEd Maste }
396ac7ddfbfSEd Maste
397ac7ddfbfSEd Maste const SymbolType symbol_type = symbol->GetType();
398435933ddSDimitry Andric switch (symbol_type) {
399435933ddSDimitry Andric case eSymbolTypeAny:
4004ba319b5SDimitry Andric return AddressClass::eUnknown;
401435933ddSDimitry Andric case eSymbolTypeAbsolute:
4024ba319b5SDimitry Andric return AddressClass::eUnknown;
403435933ddSDimitry Andric case eSymbolTypeCode:
4044ba319b5SDimitry Andric return AddressClass::eCode;
405435933ddSDimitry Andric case eSymbolTypeTrampoline:
4064ba319b5SDimitry Andric return AddressClass::eCode;
407435933ddSDimitry Andric case eSymbolTypeResolver:
4084ba319b5SDimitry Andric return AddressClass::eCode;
409435933ddSDimitry Andric case eSymbolTypeData:
4104ba319b5SDimitry Andric return AddressClass::eData;
411435933ddSDimitry Andric case eSymbolTypeRuntime:
4124ba319b5SDimitry Andric return AddressClass::eRuntime;
413435933ddSDimitry Andric case eSymbolTypeException:
4144ba319b5SDimitry Andric return AddressClass::eRuntime;
415435933ddSDimitry Andric case eSymbolTypeSourceFile:
4164ba319b5SDimitry Andric return AddressClass::eDebug;
417435933ddSDimitry Andric case eSymbolTypeHeaderFile:
4184ba319b5SDimitry Andric return AddressClass::eDebug;
419435933ddSDimitry Andric case eSymbolTypeObjectFile:
4204ba319b5SDimitry Andric return AddressClass::eDebug;
421435933ddSDimitry Andric case eSymbolTypeCommonBlock:
4224ba319b5SDimitry Andric return AddressClass::eDebug;
423435933ddSDimitry Andric case eSymbolTypeBlock:
4244ba319b5SDimitry Andric return AddressClass::eDebug;
425435933ddSDimitry Andric case eSymbolTypeLocal:
4264ba319b5SDimitry Andric return AddressClass::eData;
427435933ddSDimitry Andric case eSymbolTypeParam:
4284ba319b5SDimitry Andric return AddressClass::eData;
429435933ddSDimitry Andric case eSymbolTypeVariable:
4304ba319b5SDimitry Andric return AddressClass::eData;
431435933ddSDimitry Andric case eSymbolTypeVariableType:
4324ba319b5SDimitry Andric return AddressClass::eDebug;
433435933ddSDimitry Andric case eSymbolTypeLineEntry:
4344ba319b5SDimitry Andric return AddressClass::eDebug;
435435933ddSDimitry Andric case eSymbolTypeLineHeader:
4364ba319b5SDimitry Andric return AddressClass::eDebug;
437435933ddSDimitry Andric case eSymbolTypeScopeBegin:
4384ba319b5SDimitry Andric return AddressClass::eDebug;
439435933ddSDimitry Andric case eSymbolTypeScopeEnd:
4404ba319b5SDimitry Andric return AddressClass::eDebug;
441435933ddSDimitry Andric case eSymbolTypeAdditional:
4424ba319b5SDimitry Andric return AddressClass::eUnknown;
443435933ddSDimitry Andric case eSymbolTypeCompiler:
4444ba319b5SDimitry Andric return AddressClass::eDebug;
445435933ddSDimitry Andric case eSymbolTypeInstrumentation:
4464ba319b5SDimitry Andric return AddressClass::eDebug;
447435933ddSDimitry Andric case eSymbolTypeUndefined:
4484ba319b5SDimitry Andric return AddressClass::eUnknown;
449435933ddSDimitry Andric case eSymbolTypeObjCClass:
4504ba319b5SDimitry Andric return AddressClass::eRuntime;
451435933ddSDimitry Andric case eSymbolTypeObjCMetaClass:
4524ba319b5SDimitry Andric return AddressClass::eRuntime;
453435933ddSDimitry Andric case eSymbolTypeObjCIVar:
4544ba319b5SDimitry Andric return AddressClass::eRuntime;
455435933ddSDimitry Andric case eSymbolTypeReExported:
4564ba319b5SDimitry Andric return AddressClass::eRuntime;
457ac7ddfbfSEd Maste }
458ac7ddfbfSEd Maste }
459ac7ddfbfSEd Maste }
4604ba319b5SDimitry Andric return AddressClass::eUnknown;
461ac7ddfbfSEd Maste }
462ac7ddfbfSEd Maste
ReadMemory(const ProcessSP & process_sp,lldb::addr_t addr,size_t byte_size)463435933ddSDimitry Andric DataBufferSP ObjectFile::ReadMemory(const ProcessSP &process_sp,
464435933ddSDimitry Andric lldb::addr_t addr, size_t byte_size) {
465ac7ddfbfSEd Maste DataBufferSP data_sp;
466435933ddSDimitry Andric if (process_sp) {
467ac7ddfbfSEd Maste std::unique_ptr<DataBufferHeap> data_ap(new DataBufferHeap(byte_size, 0));
4685517e702SDimitry Andric Status error;
469435933ddSDimitry Andric const size_t bytes_read = process_sp->ReadMemory(
470435933ddSDimitry Andric addr, data_ap->GetBytes(), data_ap->GetByteSize(), error);
471ac7ddfbfSEd Maste if (bytes_read == byte_size)
472ac7ddfbfSEd Maste data_sp.reset(data_ap.release());
473ac7ddfbfSEd Maste }
474ac7ddfbfSEd Maste return data_sp;
475ac7ddfbfSEd Maste }
476ac7ddfbfSEd Maste
GetData(lldb::offset_t offset,size_t length,DataExtractor & data) const477435933ddSDimitry Andric size_t ObjectFile::GetData(lldb::offset_t offset, size_t length,
478435933ddSDimitry Andric DataExtractor &data) const {
479435933ddSDimitry Andric // The entire file has already been mmap'ed into m_data, so just copy from
4804ba319b5SDimitry Andric // there as the back mmap buffer will be shared with shared pointers.
481ac7ddfbfSEd Maste return data.SetData(m_data, offset, length);
482ac7ddfbfSEd Maste }
483ac7ddfbfSEd Maste
CopyData(lldb::offset_t offset,size_t length,void * dst) const484435933ddSDimitry Andric size_t ObjectFile::CopyData(lldb::offset_t offset, size_t length,
485435933ddSDimitry Andric void *dst) const {
486435933ddSDimitry Andric // The entire file has already been mmap'ed into m_data, so just copy from
4874ba319b5SDimitry Andric // there Note that the data remains in target byte order.
48835617911SEd Maste return m_data.CopyData(offset, length, dst);
489ac7ddfbfSEd Maste }
490ac7ddfbfSEd Maste
ReadSectionData(Section * section,lldb::offset_t section_offset,void * dst,size_t dst_len)491acac075bSDimitry Andric size_t ObjectFile::ReadSectionData(Section *section,
492435933ddSDimitry Andric lldb::offset_t section_offset, void *dst,
493acac075bSDimitry Andric size_t dst_len) {
4947aa51b79SEd Maste assert(section);
4957aa51b79SEd Maste section_offset *= section->GetTargetByteSize();
4967aa51b79SEd Maste
497ac7ddfbfSEd Maste // If some other objectfile owns this data, pass this to them.
498ac7ddfbfSEd Maste if (section->GetObjectFile() != this)
499435933ddSDimitry Andric return section->GetObjectFile()->ReadSectionData(section, section_offset,
500435933ddSDimitry Andric dst, dst_len);
501ac7ddfbfSEd Maste
502435933ddSDimitry Andric if (IsInMemory()) {
503ac7ddfbfSEd Maste ProcessSP process_sp(m_process_wp.lock());
504435933ddSDimitry Andric if (process_sp) {
5055517e702SDimitry Andric Status error;
506435933ddSDimitry Andric const addr_t base_load_addr =
507435933ddSDimitry Andric section->GetLoadBaseAddress(&process_sp->GetTarget());
508ac7ddfbfSEd Maste if (base_load_addr != LLDB_INVALID_ADDRESS)
509435933ddSDimitry Andric return process_sp->ReadMemory(base_load_addr + section_offset, dst,
510435933ddSDimitry Andric dst_len, error);
511ac7ddfbfSEd Maste }
512435933ddSDimitry Andric } else {
513acac075bSDimitry Andric if (!section->IsRelocated())
514acac075bSDimitry Andric RelocateSection(section);
515acac075bSDimitry Andric
5160127ef0fSEd Maste const lldb::offset_t section_file_size = section->GetFileSize();
517435933ddSDimitry Andric if (section_offset < section_file_size) {
5180127ef0fSEd Maste const size_t section_bytes_left = section_file_size - section_offset;
5190127ef0fSEd Maste size_t section_dst_len = dst_len;
520ac7ddfbfSEd Maste if (section_dst_len > section_bytes_left)
521ac7ddfbfSEd Maste section_dst_len = section_bytes_left;
522435933ddSDimitry Andric return CopyData(section->GetFileOffset() + section_offset,
523435933ddSDimitry Andric section_dst_len, dst);
524435933ddSDimitry Andric } else {
525435933ddSDimitry Andric if (section->GetType() == eSectionTypeZeroFill) {
526ac7ddfbfSEd Maste const uint64_t section_size = section->GetByteSize();
527ac7ddfbfSEd Maste const uint64_t section_bytes_left = section_size - section_offset;
528ac7ddfbfSEd Maste uint64_t section_dst_len = dst_len;
529ac7ddfbfSEd Maste if (section_dst_len > section_bytes_left)
530ac7ddfbfSEd Maste section_dst_len = section_bytes_left;
53135617911SEd Maste memset(dst, 0, section_dst_len);
532ac7ddfbfSEd Maste return section_dst_len;
533ac7ddfbfSEd Maste }
534ac7ddfbfSEd Maste }
535ac7ddfbfSEd Maste }
536ac7ddfbfSEd Maste return 0;
537ac7ddfbfSEd Maste }
538ac7ddfbfSEd Maste
539ac7ddfbfSEd Maste //----------------------------------------------------------------------
540ac7ddfbfSEd Maste // Get the section data the file on disk
541ac7ddfbfSEd Maste //----------------------------------------------------------------------
ReadSectionData(Section * section,DataExtractor & section_data)542acac075bSDimitry Andric size_t ObjectFile::ReadSectionData(Section *section,
543acac075bSDimitry Andric DataExtractor §ion_data) {
544ac7ddfbfSEd Maste // If some other objectfile owns this data, pass this to them.
545ac7ddfbfSEd Maste if (section->GetObjectFile() != this)
546ac7ddfbfSEd Maste return section->GetObjectFile()->ReadSectionData(section, section_data);
547ac7ddfbfSEd Maste
548435933ddSDimitry Andric if (IsInMemory()) {
549ac7ddfbfSEd Maste ProcessSP process_sp(m_process_wp.lock());
550435933ddSDimitry Andric if (process_sp) {
551435933ddSDimitry Andric const addr_t base_load_addr =
552435933ddSDimitry Andric section->GetLoadBaseAddress(&process_sp->GetTarget());
553435933ddSDimitry Andric if (base_load_addr != LLDB_INVALID_ADDRESS) {
554435933ddSDimitry Andric DataBufferSP data_sp(
555435933ddSDimitry Andric ReadMemory(process_sp, base_load_addr, section->GetByteSize()));
556435933ddSDimitry Andric if (data_sp) {
557ac7ddfbfSEd Maste section_data.SetData(data_sp, 0, data_sp->GetByteSize());
558ac7ddfbfSEd Maste section_data.SetByteOrder(process_sp->GetByteOrder());
559ac7ddfbfSEd Maste section_data.SetAddressByteSize(process_sp->GetAddressByteSize());
560ac7ddfbfSEd Maste return section_data.GetByteSize();
561ac7ddfbfSEd Maste }
562ac7ddfbfSEd Maste }
563ac7ddfbfSEd Maste }
564435933ddSDimitry Andric return GetData(section->GetFileOffset(), section->GetFileSize(),
565435933ddSDimitry Andric section_data);
566435933ddSDimitry Andric } else {
5674ba319b5SDimitry Andric // The object file now contains a full mmap'ed copy of the object file
5684ba319b5SDimitry Andric // data, so just use this
569acac075bSDimitry Andric if (!section->IsRelocated())
570acac075bSDimitry Andric RelocateSection(section);
571ac7ddfbfSEd Maste
572435933ddSDimitry Andric return GetData(section->GetFileOffset(), section->GetFileSize(),
573435933ddSDimitry Andric section_data);
574ac7ddfbfSEd Maste }
575ac7ddfbfSEd Maste }
576ac7ddfbfSEd Maste
SplitArchivePathWithObject(const char * path_with_object,FileSpec & archive_file,ConstString & archive_object,bool must_exist)577435933ddSDimitry Andric bool ObjectFile::SplitArchivePathWithObject(const char *path_with_object,
578435933ddSDimitry Andric FileSpec &archive_file,
579435933ddSDimitry Andric ConstString &archive_object,
580435933ddSDimitry Andric bool must_exist) {
581435933ddSDimitry Andric RegularExpression g_object_regex(llvm::StringRef("(.*)\\(([^\\)]+)\\)$"));
582ac7ddfbfSEd Maste RegularExpression::Match regex_match(2);
583435933ddSDimitry Andric if (g_object_regex.Execute(llvm::StringRef::withNullAsEmpty(path_with_object),
584435933ddSDimitry Andric ®ex_match)) {
585ac7ddfbfSEd Maste std::string path;
586ac7ddfbfSEd Maste std::string obj;
587ac7ddfbfSEd Maste if (regex_match.GetMatchAtIndex(path_with_object, 1, path) &&
588435933ddSDimitry Andric regex_match.GetMatchAtIndex(path_with_object, 2, obj)) {
589*b5893f02SDimitry Andric archive_file.SetFile(path, FileSpec::Style::native);
590ac7ddfbfSEd Maste archive_object.SetCString(obj.c_str());
591*b5893f02SDimitry Andric return !(must_exist && !FileSystem::Instance().Exists(archive_file));
592ac7ddfbfSEd Maste }
593ac7ddfbfSEd Maste }
594ac7ddfbfSEd Maste return false;
595ac7ddfbfSEd Maste }
596ac7ddfbfSEd Maste
ClearSymtab()597435933ddSDimitry Andric void ObjectFile::ClearSymtab() {
598ac7ddfbfSEd Maste ModuleSP module_sp(GetModule());
599435933ddSDimitry Andric if (module_sp) {
6004bb0738eSEd Maste std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
601ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OBJECT));
602ac7ddfbfSEd Maste if (log)
603ac7ddfbfSEd Maste log->Printf("%p ObjectFile::ClearSymtab () symtab = %p",
6040127ef0fSEd Maste static_cast<void *>(this),
6050127ef0fSEd Maste static_cast<void *>(m_symtab_ap.get()));
606ac7ddfbfSEd Maste m_symtab_ap.reset();
607ac7ddfbfSEd Maste }
608ac7ddfbfSEd Maste }
609ac7ddfbfSEd Maste
GetSectionList(bool update_module_section_list)610435933ddSDimitry Andric SectionList *ObjectFile::GetSectionList(bool update_module_section_list) {
611435933ddSDimitry Andric if (m_sections_ap.get() == nullptr) {
612435933ddSDimitry Andric if (update_module_section_list) {
613ac7ddfbfSEd Maste ModuleSP module_sp(GetModule());
614435933ddSDimitry Andric if (module_sp) {
6154bb0738eSEd Maste std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
616ac7ddfbfSEd Maste CreateSections(*module_sp->GetUnifiedSectionList());
617ac7ddfbfSEd Maste }
618435933ddSDimitry Andric } else {
6199f2f44ceSEd Maste SectionList unified_section_list;
6209f2f44ceSEd Maste CreateSections(unified_section_list);
6219f2f44ceSEd Maste }
6229f2f44ceSEd Maste }
623ac7ddfbfSEd Maste return m_sections_ap.get();
624ac7ddfbfSEd Maste }
6259f2f44ceSEd Maste
6269f2f44ceSEd Maste lldb::SymbolType
GetSymbolTypeFromName(llvm::StringRef name,lldb::SymbolType symbol_type_hint)6279f2f44ceSEd Maste ObjectFile::GetSymbolTypeFromName(llvm::StringRef name,
628435933ddSDimitry Andric lldb::SymbolType symbol_type_hint) {
629435933ddSDimitry Andric if (!name.empty()) {
630435933ddSDimitry Andric if (name.startswith("_OBJC_")) {
6319f2f44ceSEd Maste // ObjC
6329f2f44ceSEd Maste if (name.startswith("_OBJC_CLASS_$_"))
6339f2f44ceSEd Maste return lldb::eSymbolTypeObjCClass;
6349f2f44ceSEd Maste if (name.startswith("_OBJC_METACLASS_$_"))
6359f2f44ceSEd Maste return lldb::eSymbolTypeObjCMetaClass;
6369f2f44ceSEd Maste if (name.startswith("_OBJC_IVAR_$_"))
6379f2f44ceSEd Maste return lldb::eSymbolTypeObjCIVar;
638435933ddSDimitry Andric } else if (name.startswith(".objc_class_name_")) {
6399f2f44ceSEd Maste // ObjC v1
6409f2f44ceSEd Maste return lldb::eSymbolTypeObjCClass;
6419f2f44ceSEd Maste }
6429f2f44ceSEd Maste }
6439f2f44ceSEd Maste return symbol_type_hint;
6449f2f44ceSEd Maste }
6454bb0738eSEd Maste
GetNextSyntheticSymbolName()646435933ddSDimitry Andric ConstString ObjectFile::GetNextSyntheticSymbolName() {
6474bb0738eSEd Maste StreamString ss;
6484bb0738eSEd Maste ConstString file_name = GetModule()->GetFileSpec().GetFilename();
649435933ddSDimitry Andric ss.Printf("___lldb_unnamed_symbol%u$$%s", ++m_synthetic_symbol_idx,
650435933ddSDimitry Andric file_name.GetCString());
651435933ddSDimitry Andric return ConstString(ss.GetString());
6524bb0738eSEd Maste }
653f678e45dSDimitry Andric
6544ba319b5SDimitry Andric std::vector<ObjectFile::LoadableData>
GetLoadableData(Target & target)6554ba319b5SDimitry Andric ObjectFile::GetLoadableData(Target &target) {
6564ba319b5SDimitry Andric std::vector<LoadableData> loadables;
657f678e45dSDimitry Andric SectionList *section_list = GetSectionList();
658f678e45dSDimitry Andric if (!section_list)
6594ba319b5SDimitry Andric return loadables;
6604ba319b5SDimitry Andric // Create a list of loadable data from loadable sections
661f678e45dSDimitry Andric size_t section_count = section_list->GetNumSections(0);
662f678e45dSDimitry Andric for (size_t i = 0; i < section_count; ++i) {
6634ba319b5SDimitry Andric LoadableData loadable;
664f678e45dSDimitry Andric SectionSP section_sp = section_list->GetSectionAtIndex(i);
6654ba319b5SDimitry Andric loadable.Dest =
6664ba319b5SDimitry Andric target.GetSectionLoadList().GetSectionLoadAddress(section_sp);
6674ba319b5SDimitry Andric if (loadable.Dest == LLDB_INVALID_ADDRESS)
6684ba319b5SDimitry Andric continue;
669f678e45dSDimitry Andric // We can skip sections like bss
670f678e45dSDimitry Andric if (section_sp->GetFileSize() == 0)
671f678e45dSDimitry Andric continue;
6724ba319b5SDimitry Andric DataExtractor section_data;
673f678e45dSDimitry Andric section_sp->GetSectionData(section_data);
6744ba319b5SDimitry Andric loadable.Contents = llvm::ArrayRef<uint8_t>(section_data.GetDataStart(),
6754ba319b5SDimitry Andric section_data.GetByteSize());
6764ba319b5SDimitry Andric loadables.push_back(loadable);
677f678e45dSDimitry Andric }
6784ba319b5SDimitry Andric return loadables;
679f678e45dSDimitry Andric }
680acac075bSDimitry Andric
RelocateSection(lldb_private::Section * section)681acac075bSDimitry Andric void ObjectFile::RelocateSection(lldb_private::Section *section)
682acac075bSDimitry Andric {
683acac075bSDimitry Andric }
68438638513SDimitry Andric
MapFileData(const FileSpec & file,uint64_t Size,uint64_t Offset)68538638513SDimitry Andric DataBufferSP ObjectFile::MapFileData(const FileSpec &file, uint64_t Size,
68638638513SDimitry Andric uint64_t Offset) {
687*b5893f02SDimitry Andric return FileSystem::Instance().CreateDataBuffer(file.GetPath(), Size, Offset);
688*b5893f02SDimitry Andric }
689*b5893f02SDimitry Andric
format(const ObjectFile::Type & type,raw_ostream & OS,StringRef Style)690*b5893f02SDimitry Andric void llvm::format_provider<ObjectFile::Type>::format(
691*b5893f02SDimitry Andric const ObjectFile::Type &type, raw_ostream &OS, StringRef Style) {
692*b5893f02SDimitry Andric switch (type) {
693*b5893f02SDimitry Andric case ObjectFile::eTypeInvalid:
694*b5893f02SDimitry Andric OS << "invalid";
695*b5893f02SDimitry Andric break;
696*b5893f02SDimitry Andric case ObjectFile::eTypeCoreFile:
697*b5893f02SDimitry Andric OS << "core file";
698*b5893f02SDimitry Andric break;
699*b5893f02SDimitry Andric case ObjectFile::eTypeExecutable:
700*b5893f02SDimitry Andric OS << "executable";
701*b5893f02SDimitry Andric break;
702*b5893f02SDimitry Andric case ObjectFile::eTypeDebugInfo:
703*b5893f02SDimitry Andric OS << "debug info";
704*b5893f02SDimitry Andric break;
705*b5893f02SDimitry Andric case ObjectFile::eTypeDynamicLinker:
706*b5893f02SDimitry Andric OS << "dynamic linker";
707*b5893f02SDimitry Andric break;
708*b5893f02SDimitry Andric case ObjectFile::eTypeObjectFile:
709*b5893f02SDimitry Andric OS << "object file";
710*b5893f02SDimitry Andric break;
711*b5893f02SDimitry Andric case ObjectFile::eTypeSharedLibrary:
712*b5893f02SDimitry Andric OS << "shared library";
713*b5893f02SDimitry Andric break;
714*b5893f02SDimitry Andric case ObjectFile::eTypeStubLibrary:
715*b5893f02SDimitry Andric OS << "stub library";
716*b5893f02SDimitry Andric break;
717*b5893f02SDimitry Andric case ObjectFile::eTypeJIT:
718*b5893f02SDimitry Andric OS << "jit";
719*b5893f02SDimitry Andric break;
720*b5893f02SDimitry Andric case ObjectFile::eTypeUnknown:
721*b5893f02SDimitry Andric OS << "unknown";
722*b5893f02SDimitry Andric break;
723*b5893f02SDimitry Andric }
724*b5893f02SDimitry Andric }
725*b5893f02SDimitry Andric
format(const ObjectFile::Strata & strata,raw_ostream & OS,StringRef Style)726*b5893f02SDimitry Andric void llvm::format_provider<ObjectFile::Strata>::format(
727*b5893f02SDimitry Andric const ObjectFile::Strata &strata, raw_ostream &OS, StringRef Style) {
728*b5893f02SDimitry Andric switch (strata) {
729*b5893f02SDimitry Andric case ObjectFile::eStrataInvalid:
730*b5893f02SDimitry Andric OS << "invalid";
731*b5893f02SDimitry Andric break;
732*b5893f02SDimitry Andric case ObjectFile::eStrataUnknown:
733*b5893f02SDimitry Andric OS << "unknown";
734*b5893f02SDimitry Andric break;
735*b5893f02SDimitry Andric case ObjectFile::eStrataUser:
736*b5893f02SDimitry Andric OS << "user";
737*b5893f02SDimitry Andric break;
738*b5893f02SDimitry Andric case ObjectFile::eStrataKernel:
739*b5893f02SDimitry Andric OS << "kernel";
740*b5893f02SDimitry Andric break;
741*b5893f02SDimitry Andric case ObjectFile::eStrataRawImage:
742*b5893f02SDimitry Andric OS << "raw image";
743*b5893f02SDimitry Andric break;
744*b5893f02SDimitry Andric case ObjectFile::eStrataJIT:
745*b5893f02SDimitry Andric OS << "jit";
746*b5893f02SDimitry Andric break;
747*b5893f02SDimitry Andric }
74838638513SDimitry Andric }
749