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
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
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()) {
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).
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.
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
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 DataBufferSP data_sp;
189 offset_t data_offset = 0;
190 ModuleSP module_sp = std::make_shared<Module>(file_spec);
191 return static_cast<bool>(ObjectFile::FindPlugin(
192 module_sp, &file_spec, 0, FileSystem::Instance().GetByteSize(file_spec),
193 data_sp, data_offset));
194}
195
197 lldb::offset_t file_offset,
198 lldb::offset_t file_size,
199 ModuleSpecList &specs,
200 DataBufferSP data_sp) {
201 if (!data_sp)
203 file.GetPath(), g_initial_bytes_to_read, file_offset);
204 if (data_sp) {
205 if (file_size == 0) {
206 const lldb::offset_t actual_file_size =
208 if (actual_file_size > file_offset)
209 file_size = actual_file_size - file_offset;
210 }
211 return ObjectFile::GetModuleSpecifications(file, // file spec
212 data_sp, // data bytes
213 0, // data offset
214 file_offset, // file offset
215 file_size, // file length
216 specs);
217 }
218 return 0;
219}
220
222 const lldb_private::FileSpec &file, lldb::DataBufferSP &data_sp,
223 lldb::offset_t data_offset, lldb::offset_t file_offset,
225 const size_t initial_count = specs.GetSize();
227 uint32_t i;
228 // Try the ObjectFile plug-ins
229 for (i = 0;
230 (callback =
232 i)) != nullptr;
233 ++i) {
234 if (callback(file, data_sp, data_offset, file_offset, file_size, specs) > 0)
235 return specs.GetSize() - initial_count;
236 }
237
238 // Try the ObjectContainer plug-ins
239 for (i = 0;
240 (callback = PluginManager::
242 nullptr;
243 ++i) {
244 if (callback(file, data_sp, data_offset, file_offset, file_size, specs) > 0)
245 return specs.GetSize() - initial_count;
246 }
247 return 0;
248}
249
251 const FileSpec *file_spec_ptr,
252 lldb::offset_t file_offset, lldb::offset_t length,
253 lldb::DataBufferSP data_sp, lldb::offset_t data_offset)
254 : ModuleChild(module_sp),
255 m_file(), // This file could be different from the original module's file
256 m_type(eTypeInvalid), m_strata(eStrataInvalid),
257 m_file_offset(file_offset), m_length(length), m_data(), m_process_wp(),
258 m_memory_addr(LLDB_INVALID_ADDRESS), m_sections_up(), m_symtab_up(),
259 m_symtab_once_up(new llvm::once_flag()) {
260 if (file_spec_ptr)
261 m_file = *file_spec_ptr;
262 if (data_sp)
263 m_data.SetData(data_sp, data_offset, length);
264 Log *log = GetLog(LLDBLog::Object);
265 LLDB_LOGF(log,
266 "%p ObjectFile::ObjectFile() module = %p (%s), file = %s, "
267 "file_offset = 0x%8.8" PRIx64 ", size = %" PRIu64,
268 static_cast<void *>(this), static_cast<void *>(module_sp.get()),
269 module_sp->GetSpecificationDescription().c_str(),
270 m_file ? m_file.GetPath().c_str() : "<NULL>", m_file_offset,
271 m_length);
272}
273
275 const ProcessSP &process_sp, lldb::addr_t header_addr,
276 DataBufferSP header_data_sp)
277 : ModuleChild(module_sp), m_file(), m_type(eTypeInvalid),
278 m_strata(eStrataInvalid), m_file_offset(0), m_length(0), m_data(),
279 m_process_wp(process_sp), m_memory_addr(header_addr), m_sections_up(),
280 m_symtab_up(), m_symtab_once_up(new llvm::once_flag()) {
281 if (header_data_sp)
282 m_data.SetData(header_data_sp, 0, header_data_sp->GetByteSize());
283 Log *log = GetLog(LLDBLog::Object);
284 LLDB_LOGF(log,
285 "%p ObjectFile::ObjectFile() module = %p (%s), process = %p, "
286 "header_addr = 0x%" PRIx64,
287 static_cast<void *>(this), static_cast<void *>(module_sp.get()),
288 module_sp->GetSpecificationDescription().c_str(),
289 static_cast<void *>(process_sp.get()), m_memory_addr);
290}
291
293 Log *log = GetLog(LLDBLog::Object);
294 LLDB_LOGF(log, "%p ObjectFile::~ObjectFile ()\n", static_cast<void *>(this));
295}
296
298 ModuleSP module_sp(GetModule());
299 if (module_sp)
300 return module_sp->SetArchitecture(new_arch);
301 return false;
302}
303
305 Symtab *symtab = GetSymtab();
306 if (symtab) {
307 Symbol *symbol = symtab->FindSymbolContainingFileAddress(file_addr);
308 if (symbol) {
309 if (symbol->ValueIsAddress()) {
310 const SectionSP section_sp(symbol->GetAddressRef().GetSection());
311 if (section_sp) {
312 const SectionType section_type = section_sp->GetType();
313 switch (section_type) {
316 case eSectionTypeCode:
317 return AddressClass::eCode;
320 case eSectionTypeData:
332 return AddressClass::eData;
368 case eSectionTypeCTF:
383 // In case of absolute sections decide the address class based on
384 // the symbol type because the section type isn't specify if it is
385 // a code or a data section.
386 break;
387 }
388 }
389 }
390
391 const SymbolType symbol_type = symbol->GetType();
392 switch (symbol_type) {
393 case eSymbolTypeAny:
397 case eSymbolTypeCode:
398 return AddressClass::eCode;
400 return AddressClass::eCode;
402 return AddressClass::eCode;
403 case eSymbolTypeData:
404 return AddressClass::eData;
417 case eSymbolTypeBlock:
419 case eSymbolTypeLocal:
420 return AddressClass::eData;
421 case eSymbolTypeParam:
422 return AddressClass::eData;
424 return AddressClass::eData;
451 }
452 }
453 }
455}
456
458 lldb::addr_t addr,
459 size_t byte_size) {
460 WritableDataBufferSP data_sp;
461 if (process_sp) {
462 std::unique_ptr<DataBufferHeap> data_up(new DataBufferHeap(byte_size, 0));
464 const size_t bytes_read = process_sp->ReadMemory(
465 addr, data_up->GetBytes(), data_up->GetByteSize(), error);
466 if (bytes_read == byte_size)
467 data_sp.reset(data_up.release());
468 }
469 return data_sp;
470}
471
472size_t ObjectFile::GetData(lldb::offset_t offset, size_t length,
473 DataExtractor &data) const {
474 // The entire file has already been mmap'ed into m_data, so just copy from
475 // there as the back mmap buffer will be shared with shared pointers.
476 return data.SetData(m_data, offset, length);
477}
478
479size_t ObjectFile::CopyData(lldb::offset_t offset, size_t length,
480 void *dst) const {
481 // The entire file has already been mmap'ed into m_data, so just copy from
482 // there Note that the data remains in target byte order.
483 return m_data.CopyData(offset, length, dst);
484}
485
487 lldb::offset_t section_offset, void *dst,
488 size_t dst_len) {
489 assert(section);
490 section_offset *= section->GetTargetByteSize();
491
492 // If some other objectfile owns this data, pass this to them.
493 if (section->GetObjectFile() != this)
494 return section->GetObjectFile()->ReadSectionData(section, section_offset,
495 dst, dst_len);
496
497 if (!section->IsRelocated())
498 RelocateSection(section);
499
500 if (IsInMemory()) {
501 ProcessSP process_sp(m_process_wp.lock());
502 if (process_sp) {
504 const addr_t base_load_addr =
505 section->GetLoadBaseAddress(&process_sp->GetTarget());
506 if (base_load_addr != LLDB_INVALID_ADDRESS)
507 return process_sp->ReadMemory(base_load_addr + section_offset, dst,
508 dst_len, error);
509 }
510 } else {
511 const lldb::offset_t section_file_size = section->GetFileSize();
512 if (section_offset < section_file_size) {
513 const size_t section_bytes_left = section_file_size - section_offset;
514 size_t section_dst_len = dst_len;
515 if (section_dst_len > section_bytes_left)
516 section_dst_len = section_bytes_left;
517 return CopyData(section->GetFileOffset() + section_offset,
518 section_dst_len, dst);
519 } else {
520 if (section->GetType() == eSectionTypeZeroFill) {
521 const uint64_t section_size = section->GetByteSize();
522 const uint64_t section_bytes_left = section_size - section_offset;
523 uint64_t section_dst_len = dst_len;
524 if (section_dst_len > section_bytes_left)
525 section_dst_len = section_bytes_left;
526 memset(dst, 0, section_dst_len);
527 return section_dst_len;
528 }
529 }
530 }
531 return 0;
532}
533
534// Get the section data the file on disk
536 DataExtractor &section_data) {
537 // If some other objectfile owns this data, pass this to them.
538 if (section->GetObjectFile() != this)
539 return section->GetObjectFile()->ReadSectionData(section, section_data);
540
541 if (!section->IsRelocated())
542 RelocateSection(section);
543
544 if (IsInMemory()) {
545 ProcessSP process_sp(m_process_wp.lock());
546 if (process_sp) {
547 const addr_t base_load_addr =
548 section->GetLoadBaseAddress(&process_sp->GetTarget());
549 if (base_load_addr != LLDB_INVALID_ADDRESS) {
550 DataBufferSP data_sp(
551 ReadMemory(process_sp, base_load_addr, section->GetByteSize()));
552 if (data_sp) {
553 section_data.SetData(data_sp, 0, data_sp->GetByteSize());
554 section_data.SetByteOrder(process_sp->GetByteOrder());
555 section_data.SetAddressByteSize(process_sp->GetAddressByteSize());
556 return section_data.GetByteSize();
557 }
558 }
559 }
560 }
561
562 // The object file now contains a full mmap'ed copy of the object file
563 // data, so just use this
564 return GetData(section->GetFileOffset(), GetSectionDataSize(section),
565 section_data);
566}
567
568bool ObjectFile::SplitArchivePathWithObject(llvm::StringRef path_with_object,
569 FileSpec &archive_file,
570 ConstString &archive_object,
571 bool must_exist) {
572 size_t len = path_with_object.size();
573 if (len < 2 || path_with_object.back() != ')')
574 return false;
575 llvm::StringRef archive = path_with_object.substr(0, path_with_object.rfind('('));
576 if (archive.empty())
577 return false;
578 llvm::StringRef object = path_with_object.substr(archive.size() + 1).drop_back();
579 archive_file.SetFile(archive, FileSpec::Style::native);
580 if (must_exist && !FileSystem::Instance().Exists(archive_file))
581 return false;
582 archive_object.SetString(object);
583 return true;
584}
585
587 ModuleSP module_sp(GetModule());
588 if (module_sp) {
589 Log *log = GetLog(LLDBLog::Object);
590 LLDB_LOGF(log, "%p ObjectFile::ClearSymtab () symtab = %p",
591 static_cast<void *>(this),
592 static_cast<void *>(m_symtab_up.get()));
593 // Since we need to clear the symbol table, we need a new llvm::once_flag
594 // instance so we can safely create another symbol table
595 m_symtab_once_up.reset(new llvm::once_flag());
596 m_symtab_up.reset();
597 }
598}
599
600SectionList *ObjectFile::GetSectionList(bool update_module_section_list) {
601 if (m_sections_up == nullptr) {
602 if (update_module_section_list) {
603 ModuleSP module_sp(GetModule());
604 if (module_sp) {
605 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
606 CreateSections(*module_sp->GetUnifiedSectionList());
607 }
608 } else {
609 SectionList unified_section_list;
610 CreateSections(unified_section_list);
611 }
612 }
613 return m_sections_up.get();
614}
615
618 lldb::SymbolType symbol_type_hint) {
619 if (!name.empty()) {
620 if (name.starts_with("_OBJC_")) {
621 // ObjC
622 if (name.starts_with("_OBJC_CLASS_$_"))
624 if (name.starts_with("_OBJC_METACLASS_$_"))
626 if (name.starts_with("_OBJC_IVAR_$_"))
628 } else if (name.starts_with(".objc_class_name_")) {
629 // ObjC v1
631 }
632 }
633 return symbol_type_hint;
634}
635
636std::vector<ObjectFile::LoadableData>
638 std::vector<LoadableData> loadables;
639 SectionList *section_list = GetSectionList();
640 if (!section_list)
641 return loadables;
642 // Create a list of loadable data from loadable sections
643 size_t section_count = section_list->GetNumSections(0);
644 for (size_t i = 0; i < section_count; ++i) {
645 LoadableData loadable;
646 SectionSP section_sp = section_list->GetSectionAtIndex(i);
647 loadable.Dest =
648 target.GetSectionLoadList().GetSectionLoadAddress(section_sp);
649 if (loadable.Dest == LLDB_INVALID_ADDRESS)
650 continue;
651 // We can skip sections like bss
652 if (section_sp->GetFileSize() == 0)
653 continue;
654 DataExtractor section_data;
655 section_sp->GetSectionData(section_data);
656 loadable.Contents = llvm::ArrayRef<uint8_t>(section_data.GetDataStart(),
657 section_data.GetByteSize());
658 loadables.push_back(loadable);
659 }
660 return loadables;
661}
662
663std::unique_ptr<CallFrameInfo> ObjectFile::CreateCallFrameInfo() {
664 return {};
665}
666
668{
669}
670
672 uint64_t Offset) {
673 return FileSystem::Instance().CreateDataBuffer(file.GetPath(), Size, Offset);
674}
675
676void llvm::format_provider<ObjectFile::Type>::format(
677 const ObjectFile::Type &type, raw_ostream &OS, StringRef Style) {
678 switch (type) {
680 OS << "invalid";
681 break;
683 OS << "core file";
684 break;
686 OS << "executable";
687 break;
689 OS << "debug info";
690 break;
692 OS << "dynamic linker";
693 break;
695 OS << "object file";
696 break;
698 OS << "shared library";
699 break;
701 OS << "stub library";
702 break;
704 OS << "jit";
705 break;
707 OS << "unknown";
708 break;
709 }
710}
711
712void llvm::format_provider<ObjectFile::Strata>::format(
713 const ObjectFile::Strata &strata, raw_ostream &OS, StringRef Style) {
714 switch (strata) {
716 OS << "invalid";
717 break;
719 OS << "unknown";
720 break;
722 OS << "user";
723 break;
725 OS << "kernel";
726 break;
728 OS << "raw image";
729 break;
731 OS << "jit";
732 break;
733 }
734}
735
736
738 ModuleSP module_sp(GetModule());
739 if (module_sp) {
740 // We can't take the module lock in ObjectFile::GetSymtab() or we can
741 // deadlock in DWARF indexing when any file asks for the symbol table from
742 // an object file. This currently happens in the preloading of symbols in
743 // SymbolFileDWARF::PreloadSymbols() because the main thread will take the
744 // module lock, and then threads will be spun up to index the DWARF and
745 // any of those threads might end up trying to relocate items in the DWARF
746 // sections which causes ObjectFile::GetSectionData(...) to relocate section
747 // data which requires the symbol table.
748 //
749 // So to work around this, we create the symbol table one time using
750 // llvm::once_flag, lock it, and then set the unique pointer. Any other
751 // thread that gets ahold of the symbol table before parsing is done, will
752 // not be able to access the symbol table contents since all APIs in Symtab
753 // are protected by a mutex in the Symtab object itself.
754 llvm::call_once(*m_symtab_once_up, [&]() {
755 Symtab *symtab = new Symtab(this);
756 std::lock_guard<std::recursive_mutex> symtab_guard(symtab->GetMutex());
757 m_symtab_up.reset(symtab);
758 if (!m_symtab_up->LoadFromCache()) {
759 ElapsedTime elapsed(module_sp->GetSymtabParseTime());
761 m_symtab_up->Finalize();
762 }
763 });
764 }
765 return m_symtab_up.get();
766}
767
769 if (m_cache_hash)
770 return *m_cache_hash;
771 StreamString strm;
772 strm.Format("{0}-{1}-{2}", m_file, GetType(), GetStrata());
773 m_cache_hash = llvm::djbHash(strm.GetString());
774 return *m_cache_hash;
775}
776
777namespace llvm {
778namespace json {
779
780bool fromJSON(const llvm::json::Value &value,
781 lldb_private::ObjectFile::Type &type, llvm::json::Path path) {
782 if (auto str = value.getAsString()) {
783 type = llvm::StringSwitch<ObjectFile::Type>(*str)
784 .Case("corefile", ObjectFile::eTypeCoreFile)
785 .Case("executable", ObjectFile::eTypeExecutable)
786 .Case("debuginfo", ObjectFile::eTypeDebugInfo)
787 .Case("dynamiclinker", ObjectFile::eTypeDynamicLinker)
788 .Case("objectfile", ObjectFile::eTypeObjectFile)
789 .Case("sharedlibrary", ObjectFile::eTypeSharedLibrary)
790 .Case("stublibrary", ObjectFile::eTypeStubLibrary)
791 .Case("jit", ObjectFile::eTypeJIT)
792 .Case("unknown", ObjectFile::eTypeUnknown)
793 .Default(ObjectFile::eTypeInvalid);
794
795 if (type == ObjectFile::eTypeInvalid) {
796 path.report("invalid object type");
797 return false;
798 }
799
800 return true;
801 }
802 path.report("expected string");
803 return false;
804}
805} // namespace json
806} // namespace llvm
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOGF(log,...)
Definition: Log.h:366
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:39
#define LLDB_SCOPED_TIMERF(...)
Definition: Timer.h:86
lldb::SectionSP GetSection() const
Get const accessor for the section.
Definition: Address.h:439
An architecture specification class.
Definition: ArchSpec.h:31
A uniqued constant string class.
Definition: ConstString.h:40
void SetString(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:69
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:174
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
Definition: FileSpec.cpp:367
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
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.
Definition: ObjectFile.cpp:53
DataExtractor m_data
The data for this object file so things can be parsed lazily.
Definition: ObjectFile.h:758
Symtab * GetSymtab()
Gets the symbol table for the currently selected architecture (and object for archives).
Definition: ObjectFile.cpp:737
std::unique_ptr< lldb_private::SectionList > m_sections_up
Definition: ObjectFile.h:762
static bool IsObjectFile(lldb_private::FileSpec file_spec)
Definition: ObjectFile.cpp:187
static lldb::DataBufferSP MapFileData(const FileSpec &file, uint64_t Size, uint64_t Offset)
Definition: ObjectFile.cpp:671
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:250
virtual std::vector< LoadableData > GetLoadableData(Target &target)
Loads this objfile to memory.
Definition: ObjectFile.cpp:637
~ObjectFile() override
Destructor.
Definition: ObjectFile.cpp:292
std::unique_ptr< lldb_private::Symtab > m_symtab_up
Definition: ObjectFile.h:763
const lldb::addr_t m_memory_addr
Set if the object file only exists in memory.
Definition: ObjectFile.h:761
static size_t g_initial_bytes_to_read
The number of bytes to read when going through the plugins.
Definition: ObjectFile.h:785
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:304
static lldb::WritableDataBufferSP ReadMemory(const lldb::ProcessSP &process_sp, lldb::addr_t addr, size_t byte_size)
Definition: ObjectFile.cpp:457
size_t GetData(lldb::offset_t offset, size_t length, DataExtractor &data) const
Definition: ObjectFile.cpp:472
@ eTypeExecutable
A normal executable.
Definition: ObjectFile.h:53
@ eTypeDebugInfo
An object file that contains only debug information.
Definition: ObjectFile.h:55
@ eTypeStubLibrary
A library that can be linked against but not used for execution.
Definition: ObjectFile.h:63
@ eTypeObjectFile
An intermediate object file.
Definition: ObjectFile.h:59
@ eTypeDynamicLinker
The platform's dynamic linker executable.
Definition: ObjectFile.h:57
@ eTypeCoreFile
A core file that has a checkpoint of a program's execution state.
Definition: ObjectFile.h:51
@ eTypeSharedLibrary
A shared library that can be used during execution.
Definition: ObjectFile.h:61
@ eTypeJIT
JIT code that has symbols, sections and possibly debug info.
Definition: ObjectFile.h:65
lldb::addr_t m_file_offset
The offset in bytes into the file, or the address in memory.
Definition: ObjectFile.h:752
static lldb::SymbolType GetSymbolTypeFromName(llvm::StringRef name, lldb::SymbolType symbol_type_hint=lldb::eSymbolTypeUndefined)
Definition: ObjectFile.cpp:617
virtual size_t GetSectionDataSize(Section *section)
Definition: ObjectFile.h:686
virtual std::unique_ptr< CallFrameInfo > CreateCallFrameInfo()
Creates a plugin-specific call frame info.
Definition: ObjectFile.cpp:663
virtual void ClearSymtab()
Frees the symbol table.
Definition: ObjectFile.cpp:586
bool SetModulesArchitecture(const ArchSpec &new_arch)
Sets the architecture for a module.
Definition: ObjectFile.cpp:297
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:568
virtual void CreateSections(SectionList &unified_section_list)=0
size_t CopyData(lldb::offset_t offset, size_t length, void *dst) const
Definition: ObjectFile.cpp:479
virtual void RelocateSection(lldb_private::Section *section)
Perform relocations on the section if necessary.
Definition: ObjectFile.cpp:667
std::optional< uint32_t > m_cache_hash
Definition: ObjectFile.h:770
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:600
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:769
bool IsInMemory() const
Returns true if the object file exists only in memory.
Definition: ObjectFile.h:691
lldb::ProcessWP m_process_wp
Definition: ObjectFile.h:759
uint32_t GetCacheHash()
Get a hash that can be used for caching object file releated information.
Definition: ObjectFile.cpp:768
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:754
virtual size_t ReadSectionData(Section *section, lldb::offset_t section_offset, void *dst, size_t dst_len)
Definition: ObjectFile.cpp:486
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())
Definition: ObjectFile.cpp:196
virtual lldb::addr_t GetByteSize() const
Definition: ObjectFile.h:268
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:533
lldb::SectionSP GetSectionAtIndex(size_t idx) const
Definition: Section.cpp:544
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:228
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:353
bool ValueIsAddress() const
Definition: Symbol.cpp:165
Address & GetAddressRef()
Definition: Symbol.h:72
lldb::SymbolType GetType() const
Definition: Symbol.h:168
Symbol * FindSymbolContainingFileAddress(lldb::addr_t file_addr)
Definition: Symtab.cpp:1044
std::recursive_mutex & GetMutex()
Definition: Symtab.h:51
SectionLoadList & GetSectionLoadList()
Definition: Target.h:1143
#define LLDB_INVALID_ADDRESS
Definition: lldb-defines.h:82
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition: Log.h:331
size_t(* ObjectFileGetModuleSpecifications)(const FileSpec &file, lldb::DataBufferSP &data_sp, lldb::offset_t data_offset, lldb::offset_t file_offset, lldb::offset_t length, ModuleSpecList &module_specs)
ObjectFile *(* ObjectFileCreateMemoryInstance)(const lldb::ModuleSP &module_sp, lldb::WritableDataBufferSP data_sp, const lldb::ProcessSP &process_sp, lldb::addr_t offset)
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:85
std::shared_ptr< lldb_private::ObjectFile > ObjectFileSP
Definition: lldb-forward.h:373
std::shared_ptr< lldb_private::Process > ProcessSP
Definition: lldb-forward.h:387
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
std::shared_ptr< lldb_private::DataBuffer > DataBufferSP
Definition: lldb-forward.h:334
std::shared_ptr< lldb_private::Section > SectionSP
Definition: lldb-forward.h:414
std::shared_ptr< lldb_private::WritableDataBuffer > WritableDataBufferSP
Definition: lldb-forward.h:335
uint64_t addr_t
Definition: lldb-types.h:80
@ 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
@ eSectionTypeSwiftModules
@ eSectionTypeDebug
@ eSectionTypeDWARFDebugCuIndex
@ eSectionTypeDWARFDebugAranges
@ eSectionTypeDWARFDebugAbbrevDwo
@ eSectionTypeDWARFGNUDebugAltLink
@ eSectionTypeDWARFDebugStrDwo
@ eSectionTypeDWARFDebugAbbrev
@ eSectionTypeDataPointers
@ eSectionTypeDWARFDebugLocListsDwo
@ eSectionTypeDWARFDebugInfoDwo
@ eSectionTypeDWARFDebugAddr
@ eSectionTypeDataCString
Inlined C string data.
@ eSectionTypeELFSymbolTable
Elf SHT_SYMTAB section.
std::shared_ptr< lldb_private::Module > ModuleSP
Definition: lldb-forward.h:371
Definition: Debugger.h:54
llvm::ArrayRef< uint8_t > Contents
Definition: ObjectFile.h:91