LLDB mainline
ObjectFile.cpp
Go to the documentation of this file.
1//===-- ObjectFile.cpp ----------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
10#include "lldb/Core/Module.h"
13#include "lldb/Core/Section.h"
17#include "lldb/Target/Process.h"
19#include "lldb/Target/Target.h"
23#include "lldb/Utility/Log.h"
24#include "lldb/Utility/Timer.h"
25#include "lldb/lldb-private.h"
26
27#include "llvm/Support/DJB.h"
28
29using namespace lldb;
30using namespace lldb_private;
31
34
35static ObjectFileSP
36CreateObjectFromContainer(const lldb::ModuleSP &module_sp, const FileSpec *file,
37 lldb::offset_t file_offset, lldb::offset_t file_size,
38 DataBufferSP data_sp, lldb::offset_t &data_offset) {
40 for (uint32_t idx = 0;
42 idx)) != nullptr;
43 ++idx) {
44 std::unique_ptr<ObjectContainer> object_container_up(callback(
45 module_sp, data_sp, data_offset, file, file_offset, file_size));
46 if (object_container_up)
47 return object_container_up->GetObjectFile(file);
48 }
49 return {};
50}
51
52ObjectFileSP
53ObjectFile::FindPlugin(const lldb::ModuleSP &module_sp, const FileSpec *file,
54 lldb::offset_t file_offset, lldb::offset_t file_size,
55 DataBufferSP &data_sp, lldb::offset_t &data_offset) {
57 "ObjectFile::FindPlugin (module = %s, file = %p, file_offset = "
58 "0x%8.8" PRIx64 ", file_size = 0x%8.8" PRIx64 ")",
59 module_sp->GetFileSpec().GetPath().c_str(),
60 static_cast<const void *>(file), static_cast<uint64_t>(file_offset),
61 static_cast<uint64_t>(file_size));
62
63 if (!module_sp)
64 return {};
65
66 if (!file)
67 return {};
68
69 if (!data_sp) {
70 const bool file_exists = FileSystem::Instance().Exists(*file);
71 // We have an object name which most likely means we have a .o file in
72 // a static archive (.a file). Try and see if we have a cached archive
73 // first without reading any data first
74 if (file_exists && module_sp->GetObjectName()) {
75 ObjectFileSP object_file_sp = CreateObjectFromContainer(
76 module_sp, file, file_offset, file_size, data_sp, data_offset);
77 if (object_file_sp)
78 return object_file_sp;
79 }
80 // Ok, we didn't find any containers that have a named object, now lets
81 // read the first 512 bytes from the file so the object file and object
82 // container plug-ins can use these bytes to see if they can parse this
83 // file.
84 if (file_size > 0) {
86 file->GetPath(), g_initial_bytes_to_read, file_offset);
87 data_offset = 0;
88 }
89 }
90
91 if (!data_sp || data_sp->GetByteSize() == 0) {
92 // Check for archive file with format "/path/to/archive.a(object.o)"
93 llvm::SmallString<256> path_with_object;
94 module_sp->GetFileSpec().GetPath(path_with_object);
95
96 FileSpec archive_file;
97 ConstString archive_object;
98 const bool must_exist = true;
99 if (ObjectFile::SplitArchivePathWithObject(path_with_object, archive_file,
100 archive_object, must_exist)) {
101 file_size = FileSystem::Instance().GetByteSize(archive_file);
102 if (file_size > 0) {
103 file = &archive_file;
104 module_sp->SetFileSpecAndObjectName(archive_file, archive_object);
105 // Check if this is a object container by iterating through all
106 // object container plugin instances and then trying to get an
107 // object file from the container plugins since we had a name.
108 // Also, don't read
109 // ANY data in case there is data cached in the container plug-ins
110 // (like BSD archives caching the contained objects within an
111 // file).
112 ObjectFileSP object_file_sp = CreateObjectFromContainer(
113 module_sp, file, file_offset, file_size, data_sp, data_offset);
114 if (object_file_sp)
115 return object_file_sp;
116 // We failed to find any cached object files in the container plug-
117 // ins, so lets read the first 512 bytes and try again below...
119 archive_file.GetPath(), g_initial_bytes_to_read, file_offset);
120 }
121 }
122 }
123
124 if (data_sp && data_sp->GetByteSize() > 0) {
125 // Check if this is a normal object file by iterating through all
126 // object file plugin instances.
128 for (uint32_t idx = 0;
130 nullptr;
131 ++idx) {
132 ObjectFileSP object_file_sp(callback(module_sp, data_sp, data_offset,
133 file, file_offset, file_size));
134 if (object_file_sp.get())
135 return object_file_sp;
136 }
137
138 // Check if this is a object container by iterating through all object
139 // container plugin instances and then trying to get an object file
140 // from the container.
141 ObjectFileSP object_file_sp = CreateObjectFromContainer(
142 module_sp, file, file_offset, file_size, data_sp, data_offset);
143 if (object_file_sp)
144 return object_file_sp;
145 }
146
147 // We didn't find it, so clear our shared pointer in case it contains
148 // anything and return an empty shared pointer
149 return {};
150}
151
152ObjectFileSP ObjectFile::FindPlugin(const lldb::ModuleSP &module_sp,
153 const ProcessSP &process_sp,
154 lldb::addr_t header_addr,
155 WritableDataBufferSP data_sp) {
156 ObjectFileSP object_file_sp;
157
158 if (module_sp) {
159 LLDB_SCOPED_TIMERF("ObjectFile::FindPlugin (module = "
160 "%s, process = %p, header_addr = "
161 "0x%" PRIx64 ")",
162 module_sp->GetFileSpec().GetPath().c_str(),
163 static_cast<void *>(process_sp.get()), header_addr);
164 uint32_t idx;
165
166 // Check if this is a normal object file by iterating through all object
167 // file plugin instances.
168 ObjectFileCreateMemoryInstance create_callback;
169 for (idx = 0;
170 (create_callback =
172 nullptr;
173 ++idx) {
174 object_file_sp.reset(
175 create_callback(module_sp, data_sp, process_sp, header_addr));
176 if (object_file_sp.get())
177 return object_file_sp;
178 }
179 }
180
181 // We didn't find it, so clear our shared pointer in case it contains
182 // anything and return an empty shared pointer
183 object_file_sp.reset();
184 return object_file_sp;
185}
186
188 lldb::offset_t file_offset,
189 lldb::offset_t file_size,
190 ModuleSpecList &specs,
191 DataBufferSP data_sp) {
192 if (!data_sp)
194 file.GetPath(), g_initial_bytes_to_read, file_offset);
195 if (data_sp) {
196 if (file_size == 0) {
197 const lldb::offset_t actual_file_size =
199 if (actual_file_size > file_offset)
200 file_size = actual_file_size - file_offset;
201 }
202 return ObjectFile::GetModuleSpecifications(file, // file spec
203 data_sp, // data bytes
204 0, // data offset
205 file_offset, // file offset
206 file_size, // file length
207 specs);
208 }
209 return 0;
210}
211
213 const lldb_private::FileSpec &file, lldb::DataBufferSP &data_sp,
214 lldb::offset_t data_offset, lldb::offset_t file_offset,
216 const size_t initial_count = specs.GetSize();
217 ObjectFileGetModuleSpecifications callback;
218 uint32_t i;
219 // Try the ObjectFile plug-ins
220 for (i = 0;
221 (callback =
223 i)) != nullptr;
224 ++i) {
225 if (callback(file, data_sp, data_offset, file_offset, file_size, specs) > 0)
226 return specs.GetSize() - initial_count;
227 }
228
229 // Try the ObjectContainer plug-ins
230 for (i = 0;
231 (callback = PluginManager::
233 nullptr;
234 ++i) {
235 if (callback(file, data_sp, data_offset, file_offset, file_size, specs) > 0)
236 return specs.GetSize() - initial_count;
237 }
238 return 0;
239}
240
241ObjectFile::ObjectFile(const lldb::ModuleSP &module_sp,
242 const FileSpec *file_spec_ptr,
243 lldb::offset_t file_offset, lldb::offset_t length,
244 lldb::DataBufferSP data_sp, lldb::offset_t data_offset)
245 : ModuleChild(module_sp),
246 m_file(), // This file could be different from the original module's file
247 m_type(eTypeInvalid), m_strata(eStrataInvalid),
248 m_file_offset(file_offset), m_length(length), m_data(), m_process_wp(),
249 m_memory_addr(LLDB_INVALID_ADDRESS), m_sections_up(), m_symtab_up(),
250 m_symtab_once_up(new llvm::once_flag()) {
251 if (file_spec_ptr)
252 m_file = *file_spec_ptr;
253 if (data_sp)
254 m_data.SetData(data_sp, data_offset, length);
255 Log *log = GetLog(LLDBLog::Object);
256 LLDB_LOGF(log,
257 "%p ObjectFile::ObjectFile() module = %p (%s), file = %s, "
258 "file_offset = 0x%8.8" PRIx64 ", size = %" PRIu64,
259 static_cast<void *>(this), static_cast<void *>(module_sp.get()),
260 module_sp->GetSpecificationDescription().c_str(),
261 m_file ? m_file.GetPath().c_str() : "<NULL>", m_file_offset,
262 m_length);
263}
264
265ObjectFile::ObjectFile(const lldb::ModuleSP &module_sp,
266 const ProcessSP &process_sp, lldb::addr_t header_addr,
267 DataBufferSP header_data_sp)
268 : ModuleChild(module_sp), m_file(), m_type(eTypeInvalid),
269 m_strata(eStrataInvalid), m_file_offset(0), m_length(0), m_data(),
270 m_process_wp(process_sp), m_memory_addr(header_addr), m_sections_up(),
271 m_symtab_up(), m_symtab_once_up(new llvm::once_flag()) {
272 if (header_data_sp)
273 m_data.SetData(header_data_sp, 0, header_data_sp->GetByteSize());
274 Log *log = GetLog(LLDBLog::Object);
275 LLDB_LOGF(log,
276 "%p ObjectFile::ObjectFile() module = %p (%s), process = %p, "
277 "header_addr = 0x%" PRIx64,
278 static_cast<void *>(this), static_cast<void *>(module_sp.get()),
279 module_sp->GetSpecificationDescription().c_str(),
280 static_cast<void *>(process_sp.get()), m_memory_addr);
281}
282
284 Log *log = GetLog(LLDBLog::Object);
285 LLDB_LOGF(log, "%p ObjectFile::~ObjectFile ()\n", static_cast<void *>(this));
286}
287
289 ModuleSP module_sp(GetModule());
290 if (module_sp)
291 return module_sp->SetArchitecture(new_arch);
292 return false;
293}
294
296 Symtab *symtab = GetSymtab();
297 if (symtab) {
298 Symbol *symbol = symtab->FindSymbolContainingFileAddress(file_addr);
299 if (symbol) {
300 if (symbol->ValueIsAddress()) {
301 const SectionSP section_sp(symbol->GetAddressRef().GetSection());
302 if (section_sp) {
303 const SectionType section_type = section_sp->GetType();
304 switch (section_type) {
307 case eSectionTypeCode:
308 return AddressClass::eCode;
311 case eSectionTypeData:
323 return AddressClass::eData;
372 // In case of absolute sections decide the address class based on
373 // the symbol type because the section type isn't specify if it is
374 // a code or a data section.
375 break;
376 }
377 }
378 }
379
380 const SymbolType symbol_type = symbol->GetType();
381 switch (symbol_type) {
382 case eSymbolTypeAny:
386 case eSymbolTypeCode:
387 return AddressClass::eCode;
389 return AddressClass::eCode;
391 return AddressClass::eCode;
392 case eSymbolTypeData:
393 return AddressClass::eData;
406 case eSymbolTypeBlock:
408 case eSymbolTypeLocal:
409 return AddressClass::eData;
410 case eSymbolTypeParam:
411 return AddressClass::eData;
413 return AddressClass::eData;
440 }
441 }
442 }
444}
445
446DataBufferSP ObjectFile::ReadMemory(const ProcessSP &process_sp,
447 lldb::addr_t addr, size_t byte_size) {
448 DataBufferSP data_sp;
449 if (process_sp) {
450 std::unique_ptr<DataBufferHeap> data_up(new DataBufferHeap(byte_size, 0));
452 const size_t bytes_read = process_sp->ReadMemory(
453 addr, data_up->GetBytes(), data_up->GetByteSize(), error);
454 if (bytes_read == byte_size)
455 data_sp.reset(data_up.release());
456 }
457 return data_sp;
458}
459
460size_t ObjectFile::GetData(lldb::offset_t offset, size_t length,
461 DataExtractor &data) const {
462 // The entire file has already been mmap'ed into m_data, so just copy from
463 // there as the back mmap buffer will be shared with shared pointers.
464 return data.SetData(m_data, offset, length);
465}
466
467size_t ObjectFile::CopyData(lldb::offset_t offset, size_t length,
468 void *dst) const {
469 // The entire file has already been mmap'ed into m_data, so just copy from
470 // there Note that the data remains in target byte order.
471 return m_data.CopyData(offset, length, dst);
472}
473
475 lldb::offset_t section_offset, void *dst,
476 size_t dst_len) {
477 assert(section);
478 section_offset *= section->GetTargetByteSize();
479
480 // If some other objectfile owns this data, pass this to them.
481 if (section->GetObjectFile() != this)
482 return section->GetObjectFile()->ReadSectionData(section, section_offset,
483 dst, dst_len);
484
485 if (!section->IsRelocated())
486 RelocateSection(section);
487
488 if (IsInMemory()) {
489 ProcessSP process_sp(m_process_wp.lock());
490 if (process_sp) {
492 const addr_t base_load_addr =
493 section->GetLoadBaseAddress(&process_sp->GetTarget());
494 if (base_load_addr != LLDB_INVALID_ADDRESS)
495 return process_sp->ReadMemory(base_load_addr + section_offset, dst,
496 dst_len, error);
497 }
498 } else {
499 const lldb::offset_t section_file_size = section->GetFileSize();
500 if (section_offset < section_file_size) {
501 const size_t section_bytes_left = section_file_size - section_offset;
502 size_t section_dst_len = dst_len;
503 if (section_dst_len > section_bytes_left)
504 section_dst_len = section_bytes_left;
505 return CopyData(section->GetFileOffset() + section_offset,
506 section_dst_len, dst);
507 } else {
508 if (section->GetType() == eSectionTypeZeroFill) {
509 const uint64_t section_size = section->GetByteSize();
510 const uint64_t section_bytes_left = section_size - section_offset;
511 uint64_t section_dst_len = dst_len;
512 if (section_dst_len > section_bytes_left)
513 section_dst_len = section_bytes_left;
514 memset(dst, 0, section_dst_len);
515 return section_dst_len;
516 }
517 }
518 }
519 return 0;
520}
521
522// Get the section data the file on disk
524 DataExtractor &section_data) {
525 // If some other objectfile owns this data, pass this to them.
526 if (section->GetObjectFile() != this)
527 return section->GetObjectFile()->ReadSectionData(section, section_data);
528
529 if (!section->IsRelocated())
530 RelocateSection(section);
531
532 if (IsInMemory()) {
533 ProcessSP process_sp(m_process_wp.lock());
534 if (process_sp) {
535 const addr_t base_load_addr =
536 section->GetLoadBaseAddress(&process_sp->GetTarget());
537 if (base_load_addr != LLDB_INVALID_ADDRESS) {
538 DataBufferSP data_sp(
539 ReadMemory(process_sp, base_load_addr, section->GetByteSize()));
540 if (data_sp) {
541 section_data.SetData(data_sp, 0, data_sp->GetByteSize());
542 section_data.SetByteOrder(process_sp->GetByteOrder());
543 section_data.SetAddressByteSize(process_sp->GetAddressByteSize());
544 return section_data.GetByteSize();
545 }
546 }
547 }
548 }
549
550 // The object file now contains a full mmap'ed copy of the object file
551 // data, so just use this
552 return GetData(section->GetFileOffset(), section->GetFileSize(),
553 section_data);
554}
555
556bool ObjectFile::SplitArchivePathWithObject(llvm::StringRef path_with_object,
557 FileSpec &archive_file,
558 ConstString &archive_object,
559 bool must_exist) {
560 size_t len = path_with_object.size();
561 if (len < 2 || path_with_object.back() != ')')
562 return false;
563 llvm::StringRef archive = path_with_object.substr(0, path_with_object.rfind('('));
564 if (archive.empty())
565 return false;
566 llvm::StringRef object = path_with_object.substr(archive.size() + 1).drop_back();
567 archive_file.SetFile(archive, FileSpec::Style::native);
568 if (must_exist && !FileSystem::Instance().Exists(archive_file))
569 return false;
570 archive_object.SetString(object);
571 return true;
572}
573
575 ModuleSP module_sp(GetModule());
576 if (module_sp) {
577 Log *log = GetLog(LLDBLog::Object);
578 LLDB_LOGF(log, "%p ObjectFile::ClearSymtab () symtab = %p",
579 static_cast<void *>(this),
580 static_cast<void *>(m_symtab_up.get()));
581 // Since we need to clear the symbol table, we need a new llvm::once_flag
582 // instance so we can safely create another symbol table
583 m_symtab_once_up.reset(new llvm::once_flag());
584 m_symtab_up.reset();
585 }
586}
587
588SectionList *ObjectFile::GetSectionList(bool update_module_section_list) {
589 if (m_sections_up == nullptr) {
590 if (update_module_section_list) {
591 ModuleSP module_sp(GetModule());
592 if (module_sp) {
593 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
594 CreateSections(*module_sp->GetUnifiedSectionList());
595 }
596 } else {
597 SectionList unified_section_list;
598 CreateSections(unified_section_list);
599 }
600 }
601 return m_sections_up.get();
602}
603
606 lldb::SymbolType symbol_type_hint) {
607 if (!name.empty()) {
608 if (name.startswith("_OBJC_")) {
609 // ObjC
610 if (name.startswith("_OBJC_CLASS_$_"))
612 if (name.startswith("_OBJC_METACLASS_$_"))
614 if (name.startswith("_OBJC_IVAR_$_"))
616 } else if (name.startswith(".objc_class_name_")) {
617 // ObjC v1
619 }
620 }
621 return symbol_type_hint;
622}
623
624std::vector<ObjectFile::LoadableData>
626 std::vector<LoadableData> loadables;
627 SectionList *section_list = GetSectionList();
628 if (!section_list)
629 return loadables;
630 // Create a list of loadable data from loadable sections
631 size_t section_count = section_list->GetNumSections(0);
632 for (size_t i = 0; i < section_count; ++i) {
633 LoadableData loadable;
634 SectionSP section_sp = section_list->GetSectionAtIndex(i);
635 loadable.Dest =
636 target.GetSectionLoadList().GetSectionLoadAddress(section_sp);
637 if (loadable.Dest == LLDB_INVALID_ADDRESS)
638 continue;
639 // We can skip sections like bss
640 if (section_sp->GetFileSize() == 0)
641 continue;
642 DataExtractor section_data;
643 section_sp->GetSectionData(section_data);
644 loadable.Contents = llvm::ArrayRef<uint8_t>(section_data.GetDataStart(),
645 section_data.GetByteSize());
646 loadables.push_back(loadable);
647 }
648 return loadables;
649}
650
651std::unique_ptr<CallFrameInfo> ObjectFile::CreateCallFrameInfo() {
652 return {};
653}
654
656{
657}
658
659DataBufferSP ObjectFile::MapFileData(const FileSpec &file, uint64_t Size,
660 uint64_t Offset) {
661 return FileSystem::Instance().CreateDataBuffer(file.GetPath(), Size, Offset);
662}
663
664void llvm::format_provider<ObjectFile::Type>::format(
665 const ObjectFile::Type &type, raw_ostream &OS, StringRef Style) {
666 switch (type) {
668 OS << "invalid";
669 break;
671 OS << "core file";
672 break;
674 OS << "executable";
675 break;
677 OS << "debug info";
678 break;
680 OS << "dynamic linker";
681 break;
683 OS << "object file";
684 break;
686 OS << "shared library";
687 break;
689 OS << "stub library";
690 break;
692 OS << "jit";
693 break;
695 OS << "unknown";
696 break;
697 }
698}
699
700void llvm::format_provider<ObjectFile::Strata>::format(
701 const ObjectFile::Strata &strata, raw_ostream &OS, StringRef Style) {
702 switch (strata) {
704 OS << "invalid";
705 break;
707 OS << "unknown";
708 break;
710 OS << "user";
711 break;
713 OS << "kernel";
714 break;
716 OS << "raw image";
717 break;
719 OS << "jit";
720 break;
721 }
722}
723
724
726 ModuleSP module_sp(GetModule());
727 if (module_sp) {
728 // We can't take the module lock in ObjectFile::GetSymtab() or we can
729 // deadlock in DWARF indexing when any file asks for the symbol table from
730 // an object file. This currently happens in the preloading of symbols in
731 // SymbolFileDWARF::PreloadSymbols() because the main thread will take the
732 // module lock, and then threads will be spun up to index the DWARF and
733 // any of those threads might end up trying to relocate items in the DWARF
734 // sections which causes ObjectFile::GetSectionData(...) to relocate section
735 // data which requires the symbol table.
736 //
737 // So to work around this, we create the symbol table one time using
738 // llvm::once_flag, lock it, and then set the unique pointer. Any other
739 // thread that gets ahold of the symbol table before parsing is done, will
740 // not be able to access the symbol table contents since all APIs in Symtab
741 // are protected by a mutex in the Symtab object itself.
742 llvm::call_once(*m_symtab_once_up, [&]() {
743 Symtab *symtab = new Symtab(this);
744 std::lock_guard<std::recursive_mutex> symtab_guard(symtab->GetMutex());
745 m_symtab_up.reset(symtab);
746 if (!m_symtab_up->LoadFromCache()) {
747 ElapsedTime elapsed(module_sp->GetSymtabParseTime());
749 m_symtab_up->Finalize();
750 }
751 });
752 }
753 return m_symtab_up.get();
754}
755
757 if (m_cache_hash)
758 return *m_cache_hash;
759 StreamString strm;
760 strm.Format("{0}-{1}-{2}", m_file, GetType(), GetStrata());
761 m_cache_hash = llvm::djbHash(strm.GetString());
762 return *m_cache_hash;
763}
764
765namespace llvm {
766namespace json {
767
768bool fromJSON(const llvm::json::Value &value,
769 lldb_private::ObjectFile::Type &type, llvm::json::Path path) {
770 if (auto str = value.getAsString()) {
771 type = llvm::StringSwitch<ObjectFile::Type>(*str)
772 .Case("corefile", ObjectFile::eTypeCoreFile)
773 .Case("executable", ObjectFile::eTypeExecutable)
774 .Case("debuginfo", ObjectFile::eTypeDebugInfo)
775 .Case("dynamiclinker", ObjectFile::eTypeDynamicLinker)
776 .Case("objectfile", ObjectFile::eTypeObjectFile)
777 .Case("sharedlibrary", ObjectFile::eTypeSharedLibrary)
778 .Case("stublibrary", ObjectFile::eTypeStubLibrary)
779 .Case("jit", ObjectFile::eTypeJIT)
780 .Case("unknown", ObjectFile::eTypeUnknown)
781 .Default(ObjectFile::eTypeInvalid);
782
783 if (type == ObjectFile::eTypeInvalid) {
784 path.report("invalid object type");
785 return false;
786 }
787
788 return true;
789 }
790 path.report("expected string");
791 return false;
792}
793} // namespace json
794} // namespace llvm
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOGF(log,...)
Definition: Log.h:344
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)
Definition: ObjectFile.cpp:36
static double elapsed(const StatsTimepoint &start, const StatsTimepoint &end)
Definition: Statistics.cpp:36
#define LLDB_SCOPED_TIMERF(...)
Definition: Timer.h:86
lldb::SectionSP GetSection() const
Get const accessor for the section.
Definition: Address.h:429
An architecture specification class.
Definition: ArchSpec.h:31
A uniqued constant string class.
Definition: ConstString.h:40
void SetString(const llvm::StringRef &s)
A subclass of DataBuffer that stores a data buffer on the heap.
An data extractor class.
Definition: DataExtractor.h:48
lldb::offset_t CopyData(lldb::offset_t offset, lldb::offset_t length, void *dst) const
Copy length bytes from *offset, without swapping bytes.
void SetByteOrder(lldb::ByteOrder byte_order)
Set the byte_order value.
uint64_t GetByteSize() const
Get the number of bytes contained in this object.
const uint8_t * GetDataStart() const
Get the data start pointer.
lldb::offset_t SetData(const void *bytes, lldb::offset_t length, lldb::ByteOrder byte_order)
Set data with a buffer that is caller owned.
void SetAddressByteSize(uint32_t addr_size)
Set the address byte size.
A class that measures elapsed time in an exception safe way.
Definition: Statistics.h:68
A file utility class.
Definition: FileSpec.h:56
void SetFile(llvm::StringRef path, Style style)
Change the file specified with a new path.
Definition: FileSpec.cpp:173
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
Definition: FileSpec.cpp:366
uint64_t GetByteSize(const FileSpec &file_spec) const
Returns the on-disk size of the given file in bytes.
bool Exists(const FileSpec &file_spec) const
Returns whether the given file exists.
static FileSystem & Instance()
std::shared_ptr< DataBuffer > CreateDataBuffer(const llvm::Twine &path, uint64_t size=0, uint64_t offset=0)
Create memory buffer from path.
A mix in class that contains a pointer back to the module that owns the object which inherits from it...
Definition: ModuleChild.h:19
lldb::ModuleSP GetModule() const
Get const accessor for the module pointer.
Definition: ModuleChild.cpp:24
DataExtractor m_data
The data for this object file so things can be parsed lazily.
Definition: ObjectFile.h:725
Symtab * GetSymtab()
Gets the symbol table for the currently selected architecture (and object for archives).
Definition: ObjectFile.cpp:725
std::unique_ptr< lldb_private::SectionList > m_sections_up
Definition: ObjectFile.h:729
static lldb::DataBufferSP MapFileData(const FileSpec &file, uint64_t Size, uint64_t Offset)
Definition: ObjectFile.cpp:659
ObjectFile(const lldb::ModuleSP &module_sp, const FileSpec *file_spec_ptr, lldb::offset_t file_offset, lldb::offset_t length, lldb::DataBufferSP data_sp, lldb::offset_t data_offset)
Construct with a parent module, offset, and header data.
Definition: ObjectFile.cpp:241
virtual std::vector< LoadableData > GetLoadableData(Target &target)
Loads this objfile to memory.
Definition: ObjectFile.cpp:625
~ObjectFile() override
Destructor.
Definition: ObjectFile.cpp:283
std::unique_ptr< lldb_private::Symtab > m_symtab_up
Definition: ObjectFile.h:730
const lldb::addr_t m_memory_addr
Set if the object file only exists in memory.
Definition: ObjectFile.h:728
static size_t g_initial_bytes_to_read
The number of bytes to read when going through the plugins.
Definition: ObjectFile.h:752
virtual void ParseSymtab(Symtab &symtab)=0
Parse the symbol table into the provides symbol table object.
virtual AddressClass GetAddressClass(lldb::addr_t file_addr)
Get the address type given a file address in an object file.
Definition: ObjectFile.cpp:295
static lldb::DataBufferSP ReadMemory(const lldb::ProcessSP &process_sp, lldb::addr_t addr, size_t byte_size)
Definition: ObjectFile.cpp:446
static lldb::ObjectFileSP FindPlugin(const lldb::ModuleSP &module_sp, const FileSpec *file_spec, lldb::offset_t file_offset, lldb::offset_t file_size, lldb::DataBufferSP &data_sp, lldb::offset_t &data_offset)
Find a ObjectFile plug-in that can parse file_spec.
size_t GetData(lldb::offset_t offset, size_t length, DataExtractor &data) const
Definition: ObjectFile.cpp:460
@ eTypeExecutable
A normal executable.
Definition: ObjectFile.h:52
@ eTypeDebugInfo
An object file that contains only debug information.
Definition: ObjectFile.h:54
@ eTypeStubLibrary
A library that can be linked against but not used for execution.
Definition: ObjectFile.h:62
@ eTypeObjectFile
An intermediate object file.
Definition: ObjectFile.h:58
@ eTypeDynamicLinker
The platform's dynamic linker executable.
Definition: ObjectFile.h:56
@ eTypeCoreFile
A core file that has a checkpoint of a program's execution state.
Definition: ObjectFile.h:50
@ eTypeSharedLibrary
A shared library that can be used during execution.
Definition: ObjectFile.h:60
@ eTypeJIT
JIT code that has symbols, sections and possibly debug info.
Definition: ObjectFile.h:64
lldb::addr_t m_file_offset
The offset in bytes into the file, or the address in memory.
Definition: ObjectFile.h:719
static lldb::SymbolType GetSymbolTypeFromName(llvm::StringRef name, lldb::SymbolType symbol_type_hint=lldb::eSymbolTypeUndefined)
Definition: ObjectFile.cpp:605
virtual std::unique_ptr< CallFrameInfo > CreateCallFrameInfo()
Creates a plugin-specific call frame info.
Definition: ObjectFile.cpp:651
virtual void ClearSymtab()
Frees the symbol table.
Definition: ObjectFile.cpp:574
bool SetModulesArchitecture(const ArchSpec &new_arch)
Sets the architecture for a module.
Definition: ObjectFile.cpp:288
static size_t GetModuleSpecifications(const FileSpec &file, lldb::offset_t file_offset, lldb::offset_t file_size, ModuleSpecList &specs, lldb::DataBufferSP data_sp=lldb::DataBufferSP())
static bool SplitArchivePathWithObject(llvm::StringRef path_with_object, lldb_private::FileSpec &archive_file, lldb_private::ConstString &archive_object, bool must_exist)
Split a path into a file path with object name.
Definition: ObjectFile.cpp:556
virtual void CreateSections(SectionList &unified_section_list)=0
size_t CopyData(lldb::offset_t offset, size_t length, void *dst) const
Definition: ObjectFile.cpp:467
virtual void RelocateSection(lldb_private::Section *section)
Perform relocations on the section if necessary.
Definition: ObjectFile.cpp:655
std::optional< uint32_t > m_cache_hash
Definition: ObjectFile.h:737
virtual SectionList * GetSectionList(bool update_module_section_list=true)
Gets the section list for the currently selected architecture (and object for archives).
Definition: ObjectFile.cpp:588
std::unique_ptr< llvm::once_flag > m_symtab_once_up
We need a llvm::once_flag that we can use to avoid locking the module lock and deadlocking LLDB.
Definition: ObjectFile.h:736
bool IsInMemory() const
Returns true if the object file exists only in memory.
Definition: ObjectFile.h:658
lldb::ProcessWP m_process_wp
Definition: ObjectFile.h:726
uint32_t GetCacheHash()
Get a hash that can be used for caching object file releated information.
Definition: ObjectFile.cpp:756
lldb::addr_t m_length
The length of this object file if it is known (can be zero if length is unknown or can't be determine...
Definition: ObjectFile.h:721
virtual size_t ReadSectionData(Section *section, lldb::offset_t section_offset, void *dst, size_t dst_len)
Definition: ObjectFile.cpp:474
static ObjectFileCreateMemoryInstance GetObjectFileCreateMemoryCallbackAtIndex(uint32_t idx)
static ObjectContainerCreateInstance GetObjectContainerCreateCallbackAtIndex(uint32_t idx)
static ObjectFileCreateInstance GetObjectFileCreateCallbackAtIndex(uint32_t idx)
static ObjectFileGetModuleSpecifications GetObjectContainerGetModuleSpecificationsCallbackAtIndex(uint32_t idx)
static ObjectFileGetModuleSpecifications GetObjectFileGetModuleSpecificationsCallbackAtIndex(uint32_t idx)
size_t GetNumSections(uint32_t depth) const
Definition: Section.cpp:527
lldb::SectionSP GetSectionAtIndex(size_t idx) const
Definition: Section.cpp:538
lldb::addr_t GetSectionLoadAddress(const lldb::SectionSP &section_sp) const
uint32_t GetTargetByteSize() const
Definition: Section.h:247
lldb::offset_t GetFileOffset() const
Definition: Section.h:154
ObjectFile * GetObjectFile()
Definition: Section.h:204
lldb::SectionType GetType() const
Definition: Section.h:188
lldb::addr_t GetLoadBaseAddress(Target *target) const
Definition: Section.cpp:224
lldb::addr_t GetByteSize() const
Definition: Section.h:170
lldb::offset_t GetFileSize() const
Definition: Section.h:160
bool IsRelocated() const
Definition: Section.h:249
An error handling class.
Definition: Status.h:44
llvm::StringRef GetString() const
void Format(const char *format, Args &&... args)
Definition: Stream.h:309
bool ValueIsAddress() const
Definition: Symbol.cpp:167
Address & GetAddressRef()
Definition: Symbol.h:71
lldb::SymbolType GetType() const
Definition: Symbol.h:167
Symbol * FindSymbolContainingFileAddress(lldb::addr_t file_addr)
Definition: Symtab.cpp:1035
std::recursive_mutex & GetMutex()
Definition: Symtab.h:51
SectionLoadList & GetSectionLoadList()
Definition: Target.h:1109
#define LLDB_INVALID_ADDRESS
Definition: lldb-defines.h:74
A class that represents a running process on the host machine.
Definition: SBAttachInfo.h:14
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition: Log.h:309
bool fromJSON(const llvm::json::Value &value, TraceSupportedResponse &info, llvm::json::Path path)
Definition: SBAddress.h:15
uint64_t offset_t
Definition: lldb-types.h:83
SymbolType
Symbol types.
@ eSymbolTypeUndefined
@ eSymbolTypeVariableType
@ eSymbolTypeObjCMetaClass
@ eSymbolTypeReExported
@ eSymbolTypeObjCClass
@ eSymbolTypeObjectFile
@ eSymbolTypeTrampoline
@ eSymbolTypeResolver
@ eSymbolTypeParam
@ eSymbolTypeSourceFile
@ eSymbolTypeException
@ eSymbolTypeVariable
@ eSymbolTypeAbsolute
@ eSymbolTypeAdditional
When symbols take more than one entry, the extra entries get this type.
@ eSymbolTypeInstrumentation
@ eSymbolTypeLocal
@ eSymbolTypeHeaderFile
@ eSymbolTypeBlock
@ eSymbolTypeCommonBlock
@ eSymbolTypeCompiler
@ eSymbolTypeLineHeader
@ eSymbolTypeObjCIVar
@ eSymbolTypeLineEntry
@ eSymbolTypeRuntime
@ eSymbolTypeScopeBegin
@ eSymbolTypeScopeEnd
uint64_t addr_t
Definition: lldb-types.h:79
@ eSectionTypeDWARFDebugStrOffsets
@ eSectionTypeELFDynamicSymbols
Elf SHT_DYNSYM section.
@ eSectionTypeData
@ eSectionTypeInvalid
@ eSectionTypeDWARFDebugPubNames
@ eSectionTypeDataObjCCFStrings
Objective-C const CFString/NSString objects.
@ eSectionTypeData16
@ eSectionTypeZeroFill
@ eSectionTypeDWARFDebugLocDwo
@ eSectionTypeDWARFDebugFrame
@ eSectionTypeARMextab
@ eSectionTypeContainer
The section contains child sections.
@ eSectionTypeDWARFDebugLocLists
DWARF v5 .debug_loclists.
@ eSectionTypeDWARFDebugTypes
DWARF .debug_types section.
@ eSectionTypeDataSymbolAddress
Address of a symbol in the symbol table.
@ eSectionTypeELFDynamicLinkInfo
Elf SHT_DYNAMIC section.
@ eSectionTypeDWARFDebugMacInfo
@ eSectionTypeAbsoluteAddress
Dummy section for symbols with absolute address.
@ eSectionTypeCompactUnwind
compact unwind section in Mach-O, __TEXT,__unwind_info
@ eSectionTypeELFRelocationEntries
Elf SHT_REL or SHT_REL section.
@ eSectionTypeDWARFAppleNamespaces
@ eSectionTypeOther
@ eSectionTypeDWARFDebugNames
DWARF v5 .debug_names.
@ eSectionTypeDWARFDebugRngLists
DWARF v5 .debug_rnglists.
@ eSectionTypeEHFrame
@ eSectionTypeDWARFDebugStrOffsetsDwo
@ eSectionTypeDWARFDebugMacro
@ eSectionTypeDWARFAppleTypes
@ eSectionTypeDWARFDebugInfo
@ eSectionTypeDWARFDebugTypesDwo
@ eSectionTypeDWARFDebugRanges
@ eSectionTypeDWARFDebugRngListsDwo
@ eSectionTypeGoSymtab
@ eSectionTypeARMexidx
@ eSectionTypeDWARFDebugLine
@ eSectionTypeDWARFDebugPubTypes
@ eSectionTypeDataObjCMessageRefs
Pointer to function pointer + selector.
@ eSectionTypeDWARFDebugTuIndex
@ eSectionTypeData4
@ eSectionTypeDWARFDebugStr
@ eSectionTypeDWARFDebugLineStr
DWARF v5 .debug_line_str.
@ eSectionTypeDWARFDebugLoc
@ eSectionTypeDWARFAppleNames
@ eSectionTypeDataCStringPointers
Pointers to C string data.
@ eSectionTypeDWARFAppleObjC
@ eSectionTypeCode
@ eSectionTypeData8
@ eSectionTypeDebug
@ eSectionTypeDWARFDebugCuIndex
@ eSectionTypeDWARFDebugAranges
@ eSectionTypeDWARFDebugAbbrevDwo
@ eSectionTypeDWARFGNUDebugAltLink
@ eSectionTypeDWARFDebugStrDwo
@ eSectionTypeDWARFDebugAbbrev
@ eSectionTypeDataPointers
@ eSectionTypeDWARFDebugLocListsDwo
@ eSectionTypeDWARFDebugInfoDwo
@ eSectionTypeDWARFDebugAddr
@ eSectionTypeDataCString
Inlined C string data.
@ eSectionTypeELFSymbolTable
Elf SHT_SYMTAB section.
Definition: Debugger.h:52
llvm::ArrayRef< uint8_t > Contents
Definition: ObjectFile.h:90