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
257 m_file_offset(file_offset), m_length(length),
258 m_data_nsp(std::make_shared<DataExtractor>()), m_process_wp(),
260 m_symtab_once_up(new llvm::once_flag()) {
261 if (file_spec_ptr)
262 m_file = *file_spec_ptr;
263 if (data_sp)
264 m_data_nsp->SetData(data_sp, data_offset, length);
265 Log *log = GetLog(LLDBLog::Object);
266 LLDB_LOGF(log,
267 "%p ObjectFile::ObjectFile() module = %p (%s), file = %s, "
268 "file_offset = 0x%8.8" PRIx64 ", size = %" PRIu64,
269 static_cast<void *>(this), static_cast<void *>(module_sp.get()),
270 module_sp->GetSpecificationDescription().c_str(),
271 m_file ? m_file.GetPath().c_str() : "<NULL>", m_file_offset,
272 m_length);
273}
274
276 const ProcessSP &process_sp, lldb::addr_t header_addr,
277 DataBufferSP header_data_sp)
278 : ModuleChild(module_sp), m_file(), m_type(eTypeInvalid),
280 m_data_nsp(std::make_shared<DataExtractor>()), m_process_wp(process_sp),
281 m_memory_addr(header_addr), m_sections_up(), m_symtab_up(),
282 m_symtab_once_up(new llvm::once_flag()) {
283 if (header_data_sp)
284 m_data_nsp->SetData(header_data_sp, 0, header_data_sp->GetByteSize());
285 Log *log = GetLog(LLDBLog::Object);
286 LLDB_LOGF(log,
287 "%p ObjectFile::ObjectFile() module = %p (%s), process = %p, "
288 "header_addr = 0x%" PRIx64,
289 static_cast<void *>(this), static_cast<void *>(module_sp.get()),
290 module_sp->GetSpecificationDescription().c_str(),
291 static_cast<void *>(process_sp.get()), m_memory_addr);
292}
293
295 Log *log = GetLog(LLDBLog::Object);
296 LLDB_LOGF(log, "%p ObjectFile::~ObjectFile ()\n", static_cast<void *>(this));
297}
298
300 ModuleSP module_sp(GetModule());
301 if (module_sp)
302 return module_sp->SetArchitecture(new_arch);
303 return false;
304}
305
307 Symtab *symtab = GetSymtab();
308 if (symtab) {
309 Symbol *symbol = symtab->FindSymbolContainingFileAddress(file_addr);
310 if (symbol) {
311 if (symbol->ValueIsAddress()) {
312 const SectionSP section_sp(symbol->GetAddressRef().GetSection());
313 if (section_sp) {
314 const SectionType section_type = section_sp->GetType();
315 switch (section_type) {
318 case eSectionTypeCode:
319 return AddressClass::eCode;
322 case eSectionTypeData:
334 return AddressClass::eData;
370 case eSectionTypeCTF:
388 // In case of absolute sections decide the address class based on
389 // the symbol type because the section type isn't specify if it is
390 // a code or a data section.
391 break;
392 }
393 }
394 }
395
396 const SymbolType symbol_type = symbol->GetType();
397 switch (symbol_type) {
398 case eSymbolTypeAny:
402 case eSymbolTypeCode:
403 return AddressClass::eCode;
405 return AddressClass::eCode;
407 return AddressClass::eCode;
408 case eSymbolTypeData:
409 return AddressClass::eData;
422 case eSymbolTypeBlock:
424 case eSymbolTypeLocal:
425 return AddressClass::eData;
426 case eSymbolTypeParam:
427 return AddressClass::eData;
429 return AddressClass::eData;
456 }
457 }
458 }
460}
461
463 lldb::addr_t addr,
464 size_t byte_size) {
465 WritableDataBufferSP data_sp;
466 if (process_sp) {
467 std::unique_ptr<DataBufferHeap> data_up(new DataBufferHeap(byte_size, 0));
469 const size_t bytes_read = process_sp->ReadMemory(
470 addr, data_up->GetBytes(), data_up->GetByteSize(), error);
471 if (bytes_read == byte_size)
472 data_sp.reset(data_up.release());
473 }
474 return data_sp;
475}
476
477size_t ObjectFile::GetData(lldb::offset_t offset, size_t length,
478 DataExtractor &data) const {
479 // The entire file has already been mmap'ed into m_data_nsp, so just copy from
480 // there as the back mmap buffer will be shared with shared pointers.
481 return data.SetData(*m_data_nsp.get(), offset, length);
482}
483
484size_t ObjectFile::CopyData(lldb::offset_t offset, size_t length,
485 void *dst) const {
486 // The entire file has already been mmap'ed into m_data_nsp, so just copy from
487 // there Note that the data remains in target byte order.
488 return m_data_nsp->CopyData(offset, length, dst);
489}
490
492 lldb::offset_t section_offset, void *dst,
493 size_t dst_len) {
494 assert(section);
495 section_offset *= section->GetTargetByteSize();
496
497 // If some other objectfile owns this data, pass this to them.
498 if (section->GetObjectFile() != this)
499 return section->GetObjectFile()->ReadSectionData(section, section_offset,
500 dst, dst_len);
501
502 if (!section->IsRelocated())
503 RelocateSection(section);
504
505 if (IsInMemory()) {
506 ProcessSP process_sp(m_process_wp.lock());
507 if (process_sp) {
509 const addr_t base_load_addr =
510 section->GetLoadBaseAddress(&process_sp->GetTarget());
511 if (base_load_addr != LLDB_INVALID_ADDRESS)
512 return process_sp->ReadMemory(base_load_addr + section_offset, dst,
513 dst_len, error);
514 }
515 } else {
516 const lldb::offset_t section_file_size = section->GetFileSize();
517 if (section_offset < section_file_size) {
518 const size_t section_bytes_left = section_file_size - section_offset;
519 size_t section_dst_len = dst_len;
520 if (section_dst_len > section_bytes_left)
521 section_dst_len = section_bytes_left;
522 return CopyData(section->GetFileOffset() + section_offset,
523 section_dst_len, dst);
524 } else {
525 if (section->GetType() == eSectionTypeZeroFill) {
526 const uint64_t section_size = section->GetByteSize();
527 const uint64_t section_bytes_left = section_size - section_offset;
528 uint64_t section_dst_len = dst_len;
529 if (section_dst_len > section_bytes_left)
530 section_dst_len = section_bytes_left;
531 memset(dst, 0, section_dst_len);
532 return section_dst_len;
533 }
534 }
535 }
536 return 0;
537}
538
539// Get the section data the file on disk
541 DataExtractor &section_data) {
542 // If some other objectfile owns this data, pass this to them.
543 if (section->GetObjectFile() != this)
544 return section->GetObjectFile()->ReadSectionData(section, section_data);
545
546 if (!section->IsRelocated())
547 RelocateSection(section);
548
549 if (IsInMemory()) {
550 ProcessSP process_sp(m_process_wp.lock());
551 if (process_sp) {
552 const addr_t base_load_addr =
553 section->GetLoadBaseAddress(&process_sp->GetTarget());
554 if (base_load_addr != LLDB_INVALID_ADDRESS) {
555 DataBufferSP data_sp(
556 ReadMemory(process_sp, base_load_addr, section->GetByteSize()));
557 if (data_sp) {
558 section_data.SetData(data_sp, 0, data_sp->GetByteSize());
559 section_data.SetByteOrder(process_sp->GetByteOrder());
560 section_data.SetAddressByteSize(process_sp->GetAddressByteSize());
561 return section_data.GetByteSize();
562 }
563 }
564 }
565 }
566
567 // The object file now contains a full mmap'ed copy of the object file
568 // data, so just use this
569 return GetData(section->GetFileOffset(), GetSectionDataSize(section),
570 section_data);
571}
572
573bool ObjectFile::SplitArchivePathWithObject(llvm::StringRef path_with_object,
574 FileSpec &archive_file,
575 ConstString &archive_object,
576 bool must_exist) {
577 size_t len = path_with_object.size();
578 if (len < 2 || path_with_object.back() != ')')
579 return false;
580 llvm::StringRef archive = path_with_object.substr(0, path_with_object.rfind('('));
581 if (archive.empty())
582 return false;
583 llvm::StringRef object = path_with_object.substr(archive.size() + 1).drop_back();
584 archive_file.SetFile(archive, FileSpec::Style::native);
585 if (must_exist && !FileSystem::Instance().Exists(archive_file))
586 return false;
587 archive_object.SetString(object);
588 return true;
589}
590
592 ModuleSP module_sp(GetModule());
593 if (module_sp) {
594 Log *log = GetLog(LLDBLog::Object);
595 LLDB_LOGF(log, "%p ObjectFile::ClearSymtab () symtab = %p",
596 static_cast<void *>(this),
597 static_cast<void *>(m_symtab_up.get()));
598 // Since we need to clear the symbol table, we need a new llvm::once_flag
599 // instance so we can safely create another symbol table
600 m_symtab_once_up.reset(new llvm::once_flag());
601 m_symtab_up.reset();
602 }
603}
604
605SectionList *ObjectFile::GetSectionList(bool update_module_section_list) {
606 if (m_sections_up == nullptr) {
607 if (update_module_section_list) {
608 ModuleSP module_sp(GetModule());
609 if (module_sp) {
610 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
611 CreateSections(*module_sp->GetUnifiedSectionList());
612 }
613 } else {
614 SectionList unified_section_list;
615 CreateSections(unified_section_list);
616 }
617 }
618 return m_sections_up.get();
619}
620
623 lldb::SymbolType symbol_type_hint) {
624 if (!name.empty()) {
625 if (name.starts_with("_OBJC_")) {
626 // ObjC
627 if (name.starts_with("_OBJC_CLASS_$_"))
629 if (name.starts_with("_OBJC_METACLASS_$_"))
631 if (name.starts_with("_OBJC_IVAR_$_"))
633 } else if (name.starts_with(".objc_class_name_")) {
634 // ObjC v1
636 }
637 }
638 return symbol_type_hint;
639}
640
643 return llvm::StringSwitch<SectionType>(name)
644 .Case("abbrev", eSectionTypeDWARFDebugAbbrev)
645 .Case("abbrev.dwo", eSectionTypeDWARFDebugAbbrevDwo)
646 .Case("addr", eSectionTypeDWARFDebugAddr)
647 .Case("aranges", eSectionTypeDWARFDebugAranges)
648 .Case("cu_index", eSectionTypeDWARFDebugCuIndex)
649 .Case("frame", eSectionTypeDWARFDebugFrame)
650 .Case("info", eSectionTypeDWARFDebugInfo)
651 .Case("info.dwo", eSectionTypeDWARFDebugInfoDwo)
652 .Cases({"line", "line.dwo"}, eSectionTypeDWARFDebugLine)
653 .Cases({"line_str", "line_str.dwo"}, eSectionTypeDWARFDebugLineStr)
654 .Case("loc", eSectionTypeDWARFDebugLoc)
655 .Case("loc.dwo", eSectionTypeDWARFDebugLocDwo)
656 .Case("loclists", eSectionTypeDWARFDebugLocLists)
657 .Case("loclists.dwo", eSectionTypeDWARFDebugLocListsDwo)
658 .Case("macinfo", eSectionTypeDWARFDebugMacInfo)
659 .Cases({"macro", "macro.dwo"}, eSectionTypeDWARFDebugMacro)
660 .Case("names", eSectionTypeDWARFDebugNames)
661 .Case("pubnames", eSectionTypeDWARFDebugPubNames)
662 .Case("pubtypes", eSectionTypeDWARFDebugPubTypes)
663 .Case("ranges", eSectionTypeDWARFDebugRanges)
664 .Case("rnglists", eSectionTypeDWARFDebugRngLists)
665 .Case("rnglists.dwo", eSectionTypeDWARFDebugRngListsDwo)
666 .Case("str", eSectionTypeDWARFDebugStr)
667 .Case("str.dwo", eSectionTypeDWARFDebugStrDwo)
668 .Cases({"str_offsets", "str_offs"}, eSectionTypeDWARFDebugStrOffsets)
669 .Case("str_offsets.dwo", eSectionTypeDWARFDebugStrOffsetsDwo)
670 .Case("tu_index", eSectionTypeDWARFDebugTuIndex)
671 .Case("types", eSectionTypeDWARFDebugTypes)
672 .Case("types.dwo", eSectionTypeDWARFDebugTypesDwo)
673 .Default(eSectionTypeOther);
674}
675
676std::vector<ObjectFile::LoadableData>
678 std::vector<LoadableData> loadables;
679 SectionList *section_list = GetSectionList();
680 if (!section_list)
681 return loadables;
682 // Create a list of loadable data from loadable sections
683 size_t section_count = section_list->GetNumSections(0);
684 for (size_t i = 0; i < section_count; ++i) {
685 LoadableData loadable;
686 SectionSP section_sp = section_list->GetSectionAtIndex(i);
687 loadable.Dest = target.GetSectionLoadAddress(section_sp);
688 if (loadable.Dest == LLDB_INVALID_ADDRESS)
689 continue;
690 // We can skip sections like bss
691 if (section_sp->GetFileSize() == 0)
692 continue;
693 DataExtractor section_data;
694 section_sp->GetSectionData(section_data);
695 loadable.Contents = llvm::ArrayRef<uint8_t>(section_data.GetDataStart(),
696 section_data.GetByteSize());
697 loadables.push_back(loadable);
698 }
699 return loadables;
700}
701
702std::unique_ptr<CallFrameInfo> ObjectFile::CreateCallFrameInfo() {
703 return {};
704}
705
709
711 uint64_t Offset) {
712 return FileSystem::Instance().CreateDataBuffer(file.GetPath(), Size, Offset);
713}
714
715void llvm::format_provider<ObjectFile::Type>::format(
716 const ObjectFile::Type &type, raw_ostream &OS, StringRef Style) {
717 switch (type) {
719 OS << "invalid";
720 break;
722 OS << "core file";
723 break;
725 OS << "executable";
726 break;
728 OS << "debug info";
729 break;
731 OS << "dynamic linker";
732 break;
734 OS << "object file";
735 break;
737 OS << "shared library";
738 break;
740 OS << "stub library";
741 break;
743 OS << "jit";
744 break;
746 OS << "unknown";
747 break;
748 }
749}
750
751void llvm::format_provider<ObjectFile::Strata>::format(
752 const ObjectFile::Strata &strata, raw_ostream &OS, StringRef Style) {
753 switch (strata) {
755 OS << "invalid";
756 break;
758 OS << "unknown";
759 break;
761 OS << "user";
762 break;
764 OS << "kernel";
765 break;
767 OS << "raw image";
768 break;
770 OS << "jit";
771 break;
772 }
773}
774
775Symtab *ObjectFile::GetSymtab(bool can_create) {
776 ModuleSP module_sp(GetModule());
777 if (module_sp && can_create) {
778 // We can't take the module lock in ObjectFile::GetSymtab() or we can
779 // deadlock in DWARF indexing when any file asks for the symbol table from
780 // an object file. This currently happens in the preloading of symbols in
781 // SymbolFileDWARF::PreloadSymbols() because the main thread will take the
782 // module lock, and then threads will be spun up to index the DWARF and
783 // any of those threads might end up trying to relocate items in the DWARF
784 // sections which causes ObjectFile::GetSectionData(...) to relocate section
785 // data which requires the symbol table.
786 //
787 // So to work around this, we create the symbol table one time using
788 // llvm::once_flag, lock it, and then set the unique pointer. Any other
789 // thread that gets ahold of the symbol table before parsing is done, will
790 // not be able to access the symbol table contents since all APIs in Symtab
791 // are protected by a mutex in the Symtab object itself.
792 llvm::call_once(*m_symtab_once_up, [&]() {
793 Symtab *symtab = new Symtab(this);
794 std::lock_guard<std::recursive_mutex> symtab_guard(symtab->GetMutex());
795 m_symtab_up.reset(symtab);
796 if (!m_symtab_up->LoadFromCache()) {
797 ElapsedTime elapsed(module_sp->GetSymtabParseTime());
799 m_symtab_up->Finalize();
800 }
801 });
802 }
803 return m_symtab_up.get();
804}
805
807 if (m_cache_hash)
808 return *m_cache_hash;
809 StreamString strm;
810 strm.Format("{0}-{1}-{2}", m_file, GetType(), GetStrata());
811 m_cache_hash = llvm::djbHash(strm.GetString());
812 return *m_cache_hash;
813}
814
815std::string ObjectFile::GetObjectName() const {
816 if (ModuleSP module_sp = GetModule())
817 if (ConstString object_name = module_sp->GetObjectName())
818 return llvm::formatv("{0}({1})", GetFileSpec().GetFilename().GetString(),
819 object_name.GetString())
820 .str();
821 return GetFileSpec().GetFilename().GetString();
822}
823
824namespace llvm {
825namespace json {
826
827bool fromJSON(const llvm::json::Value &value,
828 lldb_private::ObjectFile::Type &type, llvm::json::Path path) {
829 if (auto str = value.getAsString()) {
830 type = llvm::StringSwitch<ObjectFile::Type>(*str)
831 .Case("corefile", ObjectFile::eTypeCoreFile)
832 .Case("executable", ObjectFile::eTypeExecutable)
833 .Case("debuginfo", ObjectFile::eTypeDebugInfo)
834 .Case("dynamiclinker", ObjectFile::eTypeDynamicLinker)
835 .Case("objectfile", ObjectFile::eTypeObjectFile)
836 .Case("sharedlibrary", ObjectFile::eTypeSharedLibrary)
837 .Case("stublibrary", ObjectFile::eTypeStubLibrary)
838 .Case("jit", ObjectFile::eTypeJIT)
839 .Case("unknown", ObjectFile::eTypeUnknown)
840 .Default(ObjectFile::eTypeInvalid);
841
842 if (type == ObjectFile::eTypeInvalid) {
843 path.report("invalid object type");
844 return false;
845 }
846
847 return true;
848 }
849 path.report("expected string");
850 return false;
851}
852} // namespace json
853} // namespace llvm
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOGF(log,...)
Definition Log.h:376
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)
static double elapsed(const StatsTimepoint &start, const StatsTimepoint &end)
#define LLDB_SCOPED_TIMERF(...)
Definition Timer.h:86
lldb::SectionSP GetSection() const
Get const accessor for the section.
Definition Address.h:432
An architecture specification class.
Definition ArchSpec.h:31
A uniqued constant string class.
Definition ConstString.h:40
std::string GetString() const
Get the string value as a std::string.
void SetString(llvm::StringRef s)
A subclass of DataBuffer that stores a data buffer on the heap.
An data extractor class.
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:76
A file utility class.
Definition FileSpec.h:57
void SetFile(llvm::StringRef path, Style style)
Change the file specified with a new path.
Definition FileSpec.cpp:174
const ConstString & GetFilename() const
Filename string const get accessor.
Definition FileSpec.h:251
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
Definition FileSpec.cpp:374
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.
ModuleChild(const lldb::ModuleSP &module_sp)
Construct with owning module.
lldb::ModuleSP GetModule() const
Get const accessor for the module pointer.
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.
std::unique_ptr< lldb_private::SectionList > m_sections_up
Definition ObjectFile.h:799
static bool IsObjectFile(lldb_private::FileSpec file_spec)
static lldb::DataBufferSP MapFileData(const FileSpec &file, uint64_t Size, uint64_t Offset)
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.
virtual std::vector< LoadableData > GetLoadableData(Target &target)
Loads this objfile to memory.
~ObjectFile() override
Destructor.
std::unique_ptr< lldb_private::Symtab > m_symtab_up
Definition ObjectFile.h:800
const lldb::addr_t m_memory_addr
Set if the object file only exists in memory.
Definition ObjectFile.h:798
static size_t g_initial_bytes_to_read
The number of bytes to read when going through the plugins.
Definition ObjectFile.h:822
static lldb::SectionType GetDWARFSectionTypeFromName(llvm::StringRef name)
Parses the section type from a section name for DWARF sections.
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.
Symtab * GetSymtab(bool can_create=true)
Gets the symbol table for the currently selected architecture (and object for archives).
DataExtractorNSP m_data_nsp
The data for this object file so things can be parsed lazily.
Definition ObjectFile.h:792
static lldb::WritableDataBufferSP ReadMemory(const lldb::ProcessSP &process_sp, lldb::addr_t addr, size_t byte_size)
size_t GetData(lldb::offset_t offset, size_t length, DataExtractor &data) const
@ eTypeExecutable
A normal executable.
Definition ObjectFile.h:55
@ eTypeDebugInfo
An object file that contains only debug information.
Definition ObjectFile.h:57
@ eTypeStubLibrary
A library that can be linked against but not used for execution.
Definition ObjectFile.h:65
@ eTypeObjectFile
An intermediate object file.
Definition ObjectFile.h:61
@ eTypeDynamicLinker
The platform's dynamic linker executable.
Definition ObjectFile.h:59
@ eTypeCoreFile
A core file that has a checkpoint of a program's execution state.
Definition ObjectFile.h:53
@ eTypeSharedLibrary
A shared library that can be used during execution.
Definition ObjectFile.h:63
@ eTypeJIT
JIT code that has symbols, sections and possibly debug info.
Definition ObjectFile.h:67
lldb::addr_t m_file_offset
The offset in bytes into the file, or the address in memory.
Definition ObjectFile.h:787
static lldb::SymbolType GetSymbolTypeFromName(llvm::StringRef name, lldb::SymbolType symbol_type_hint=lldb::eSymbolTypeUndefined)
virtual size_t GetSectionDataSize(Section *section)
Definition ObjectFile.h:705
virtual std::unique_ptr< CallFrameInfo > CreateCallFrameInfo()
Creates a plugin-specific call frame info.
virtual void ClearSymtab()
Frees the symbol table.
bool SetModulesArchitecture(const ArchSpec &new_arch)
Sets the architecture for a module.
virtual FileSpec & GetFileSpec()
Get accessor to the object file specification.
Definition ObjectFile.h:282
std::string GetObjectName() const
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.
virtual void CreateSections(SectionList &unified_section_list)=0
size_t CopyData(lldb::offset_t offset, size_t length, void *dst) const
virtual void RelocateSection(lldb_private::Section *section)
Perform relocations on the section if necessary.
std::optional< uint32_t > m_cache_hash
Definition ObjectFile.h:807
virtual SectionList * GetSectionList(bool update_module_section_list=true)
Gets the section list for the currently selected architecture (and object for archives).
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:806
bool IsInMemory() const
Returns true if the object file exists only in memory.
Definition ObjectFile.h:710
lldb::ProcessWP m_process_wp
Definition ObjectFile.h:796
uint32_t GetCacheHash()
Get a hash that can be used for caching object file releated information.
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:789
virtual size_t ReadSectionData(Section *section, lldb::offset_t section_offset, void *dst, size_t dst_len)
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())
virtual lldb::addr_t GetByteSize() const
Definition ObjectFile.h:275
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:546
lldb::SectionSP GetSectionAtIndex(size_t idx) const
Definition Section.cpp:557
uint32_t GetTargetByteSize() const
Definition Section.h:276
lldb::offset_t GetFileOffset() const
Definition Section.h:183
ObjectFile * GetObjectFile()
Definition Section.h:233
lldb::SectionType GetType() const
Definition Section.h:217
lldb::addr_t GetLoadBaseAddress(Target *target) const
Definition Section.cpp:233
lldb::addr_t GetByteSize() const
Definition Section.h:199
lldb::offset_t GetFileSize() const
Definition Section.h:189
bool IsRelocated() const
Definition Section.h:278
An error handling class.
Definition Status.h:118
llvm::StringRef GetString() const
void Format(const char *format, Args &&... args)
Definition Stream.h:364
bool ValueIsAddress() const
Definition Symbol.cpp:165
Address & GetAddressRef()
Definition Symbol.h:73
lldb::SymbolType GetType() const
Definition Symbol.h:169
Symbol * FindSymbolContainingFileAddress(lldb::addr_t file_addr)
Definition Symtab.cpp:1037
std::recursive_mutex & GetMutex()
Definition Symtab.h:51
lldb::addr_t GetSectionLoadAddress(const lldb::SectionSP &section_sp)
Definition Target.cpp:5335
#define LLDB_INVALID_ADDRESS
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:332
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)
ObjectContainer *(* ObjectContainerCreateInstance)(const lldb::ModuleSP &module_sp, lldb::DataBufferSP &data_sp, lldb::offset_t data_offset, const FileSpec *file, lldb::offset_t offset, lldb::offset_t length)
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)
ObjectFile *(* ObjectFileCreateInstance)(const lldb::ModuleSP &module_sp, lldb::DataBufferSP data_sp, lldb::offset_t data_offset, const FileSpec *file, lldb::offset_t file_offset, lldb::offset_t length)
uint64_t offset_t
Definition lldb-types.h:85
std::shared_ptr< lldb_private::ObjectFile > ObjectFileSP
std::shared_ptr< lldb_private::Process > ProcessSP
SymbolType
Symbol types.
@ eSymbolTypeUndefined
@ eSymbolTypeVariableType
@ eSymbolTypeObjCMetaClass
@ eSymbolTypeReExported
@ eSymbolTypeObjCClass
@ eSymbolTypeObjectFile
@ eSymbolTypeTrampoline
@ eSymbolTypeResolver
@ eSymbolTypeSourceFile
@ eSymbolTypeException
@ eSymbolTypeVariable
@ eSymbolTypeAbsolute
@ eSymbolTypeAdditional
When symbols take more than one entry, the extra entries get this type.
@ eSymbolTypeInstrumentation
@ eSymbolTypeHeaderFile
@ eSymbolTypeCommonBlock
@ eSymbolTypeCompiler
@ eSymbolTypeLineHeader
@ eSymbolTypeObjCIVar
@ eSymbolTypeLineEntry
@ eSymbolTypeScopeBegin
@ eSymbolTypeScopeEnd
std::shared_ptr< lldb_private::DataBuffer > DataBufferSP
std::shared_ptr< lldb_private::Section > SectionSP
std::shared_ptr< lldb_private::WritableDataBuffer > WritableDataBufferSP
uint64_t addr_t
Definition lldb-types.h:80
@ eSectionTypeDWARFDebugStrOffsets
@ eSectionTypeELFDynamicSymbols
Elf SHT_DYNSYM section.
@ eSectionTypeInvalid
@ eSectionTypeDWARFDebugPubNames
@ eSectionTypeDataObjCCFStrings
Objective-C const CFString/NSString objects.
@ 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
@ eSectionTypeLLDBFormatters
@ eSectionTypeDWARFDebugNames
DWARF v5 .debug_names.
@ eSectionTypeDWARFDebugRngLists
DWARF v5 .debug_rnglists.
@ eSectionTypeEHFrame
@ eSectionTypeDWARFDebugStrOffsetsDwo
@ eSectionTypeDWARFDebugMacro
@ eSectionTypeDWARFAppleTypes
@ eSectionTypeDWARFDebugInfo
@ eSectionTypeDWARFDebugTypesDwo
@ eSectionTypeDWARFDebugRanges
@ eSectionTypeDWARFDebugRngListsDwo
@ eSectionTypeLLDBTypeSummaries
@ eSectionTypeGoSymtab
@ eSectionTypeARMexidx
@ eSectionTypeDWARFDebugLine
@ eSectionTypeDWARFDebugPubTypes
@ eSectionTypeDataObjCMessageRefs
Pointer to function pointer + selector.
@ eSectionTypeDWARFDebugTuIndex
@ eSectionTypeDWARFDebugStr
@ eSectionTypeDWARFDebugLineStr
DWARF v5 .debug_line_str.
@ eSectionTypeDWARFDebugLoc
@ eSectionTypeDWARFAppleNames
@ eSectionTypeDataCStringPointers
Pointers to C string data.
@ eSectionTypeDWARFAppleObjC
@ eSectionTypeSwiftModules
@ eSectionTypeDWARFDebugCuIndex
@ eSectionTypeDWARFDebugAranges
@ eSectionTypeDWARFDebugAbbrevDwo
@ eSectionTypeDWARFGNUDebugAltLink
@ eSectionTypeDWARFDebugStrDwo
@ eSectionTypeDWARFDebugAbbrev
@ eSectionTypeDataPointers
@ eSectionTypeDWARFDebugLocListsDwo
@ eSectionTypeDWARFDebugInfoDwo
@ eSectionTypeDWARFDebugAddr
@ eSectionTypeWasmName
@ eSectionTypeDataCString
Inlined C string data.
@ eSectionTypeELFSymbolTable
Elf SHT_SYMTAB section.
std::shared_ptr< lldb_private::Module > ModuleSP
llvm::ArrayRef< uint8_t > Contents
Definition ObjectFile.h:98