27#include "llvm/Support/DJB.h"
40 for (uint32_t idx = 0;
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);
59 "ObjectFile::FindPlugin (module = %s, file = %p, file_offset = "
60 "0x%8.8" PRIx64
", file_size = 0x%8.8" PRIx64
")",
61 module_sp->GetFileSpec().GetPath().c_str(),
62 static_cast<const void *
>(file),
static_cast<uint64_t
>(file_offset),
63 static_cast<uint64_t
>(file_size));
71 if (!extractor_sp || !extractor_sp->HasData()) {
76 if (file_exists && module_sp->GetObjectName()) {
78 module_sp, file, file_offset, file_size,
DataBufferSP(), data_offset);
80 return object_file_sp;
89 extractor_sp = std::make_shared<DataExtractor>();
90 extractor_sp->SetData(buffer_sp, data_offset, buffer_sp->GetByteSize());
95 if (!extractor_sp || !extractor_sp->HasData()) {
97 llvm::SmallString<256> path_with_object;
98 module_sp->GetFileSpec().GetPath(path_with_object);
102 const bool must_exist =
true;
104 archive_object, must_exist)) {
107 file = &archive_file;
108 module_sp->SetFileSpecAndObjectName(archive_file, archive_object);
117 module_sp, file, file_offset, file_size,
118 extractor_sp->GetSharedDataBuffer(), data_offset);
120 return object_file_sp;
125 extractor_sp = std::make_shared<DataExtractor>(buffer_sp);
130 if (extractor_sp && extractor_sp->HasData()) {
134 for (uint32_t idx = 0;
138 ObjectFileSP object_file_sp(callback(module_sp, extractor_sp, data_offset,
139 file, file_offset, file_size));
140 if (object_file_sp.get())
141 return object_file_sp;
147 DataBufferSP buffer_sp = extractor_sp->GetSharedDataBuffer();
149 module_sp, file, file_offset, file_size, buffer_sp, data_offset);
151 return object_file_sp;
167 "%s, process = %p, header_addr = "
169 module_sp->GetFileSpec().GetPath().c_str(),
170 static_cast<void *
>(process_sp.get()), header_addr);
181 object_file_sp.reset(
182 create_callback(module_sp, data_sp, process_sp, header_addr));
183 if (object_file_sp.get())
184 return object_file_sp;
190 object_file_sp.reset();
191 return object_file_sp;
197 ModuleSP module_sp = std::make_shared<Module>(file_spec);
200 extractor_sp, data_offset));
212 if (file_size == 0) {
215 if (actual_file_size > file_offset)
216 file_size = actual_file_size - file_offset;
232 const size_t initial_count = specs.
GetSize();
241 if (callback(file, data_sp, data_offset, file_offset, file_size, specs) > 0)
242 return specs.
GetSize() - initial_count;
251 if (callback(file, data_sp, data_offset, file_offset, file_size, specs) > 0)
252 return specs.
GetSize() - initial_count;
271 if (extractor_sp && extractor_sp->HasData()) {
272 m_data_nsp = extractor_sp;
275 m_data_nsp->SetData(extractor_sp->GetSharedDataBuffer(), data_offset,
280 "%p ObjectFile::ObjectFile() module = %p (%s), file = %s, "
281 "file_offset = 0x%8.8" PRIx64
", size = %" PRIu64,
282 static_cast<void *
>(
this),
static_cast<void *
>(module_sp.get()),
283 module_sp->GetSpecificationDescription().c_str(),
296 if (header_extractor_sp && header_extractor_sp->HasData())
300 "%p ObjectFile::ObjectFile() module = %p (%s), process = %p, "
301 "header_addr = 0x%" PRIx64,
302 static_cast<void *
>(
this),
static_cast<void *
>(module_sp.get()),
303 module_sp->GetSpecificationDescription().c_str(),
309 LLDB_LOGF(log,
"%p ObjectFile::~ObjectFile ()\n",
static_cast<void *
>(
this));
315 return module_sp->SetArchitecture(new_arch);
327 const SectionType section_type = section_sp->GetType();
328 switch (section_type) {
410 switch (symbol_type) {
480 std::unique_ptr<DataBufferHeap> data_up(
new DataBufferHeap(byte_size, 0));
482 const size_t bytes_read = process_sp->ReadMemory(
483 addr, data_up->GetBytes(), data_up->GetByteSize(),
error);
484 if (bytes_read == byte_size)
485 data_sp.reset(data_up.release());
501 return m_data_nsp->CopyData(offset, length, dst);
522 const addr_t base_load_addr =
525 return process_sp->ReadMemory(base_load_addr + section_offset, dst,
530 if (section_offset < section_file_size) {
531 const size_t section_bytes_left = section_file_size - section_offset;
532 size_t section_dst_len = dst_len;
533 if (section_dst_len > section_bytes_left)
534 section_dst_len = section_bytes_left;
536 section_dst_len, dst);
539 const uint64_t section_size = section->
GetByteSize();
540 const uint64_t section_bytes_left = section_size - section_offset;
541 uint64_t section_dst_len = dst_len;
542 if (section_dst_len > section_bytes_left)
543 section_dst_len = section_bytes_left;
544 memset(dst, 0, section_dst_len);
545 return section_dst_len;
565 const addr_t base_load_addr =
571 section_data.
SetData(data_sp, 0, data_sp->GetByteSize());
590 size_t len = path_with_object.size();
591 if (len < 2 || path_with_object.back() !=
')')
593 llvm::StringRef archive = path_with_object.substr(0, path_with_object.rfind(
'('));
596 llvm::StringRef
object = path_with_object.substr(archive.size() + 1).drop_back();
597 archive_file.
SetFile(archive, FileSpec::Style::native);
608 LLDB_LOGF(log,
"%p ObjectFile::ClearSymtab () symtab = %p",
609 static_cast<void *
>(
this),
620 if (update_module_section_list) {
623 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
638 if (name.starts_with(
"_OBJC_")) {
640 if (name.starts_with(
"_OBJC_CLASS_$_"))
642 if (name.starts_with(
"_OBJC_METACLASS_$_"))
644 if (name.starts_with(
"_OBJC_IVAR_$_"))
646 }
else if (name.starts_with(
".objc_class_name_")) {
651 return symbol_type_hint;
656 return llvm::StringSwitch<SectionType>(name)
689std::vector<ObjectFile::LoadableData>
691 std::vector<LoadableData> loadables;
697 for (
size_t i = 0; i < section_count; ++i) {
704 if (section_sp->GetFileSize() == 0)
707 section_sp->GetSectionData(section_data);
710 loadables.push_back(loadable);
728void llvm::format_provider<ObjectFile::Type>::format(
744 OS <<
"dynamic linker";
750 OS <<
"shared library";
753 OS <<
"stub library";
764void llvm::format_provider<ObjectFile::Strata>::format(
790 if (module_sp && can_create) {
807 std::lock_guard<std::recursive_mutex> symtab_guard(symtab->
GetMutex());
830 if (
ConstString object_name = module_sp->GetObjectName())
831 return llvm::formatv(
"{0}({1})",
GetFileSpec().GetFilename().GetString(),
832 object_name.GetString())
842 if (
auto str = value.getAsString()) {
843 type = llvm::StringSwitch<ObjectFile::Type>(*str)
856 path.report(
"invalid object type");
862 path.report(
"expected string");
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOGF(log,...)
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(...)
lldb::SectionSP GetSection() const
Get const accessor for the section.
An architecture specification class.
A uniqued constant string class.
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.
A class that measures elapsed time in an exception safe way.
void SetFile(llvm::StringRef path, Style style)
Change the file specified with a new path.
const ConstString & GetFilename() const
Filename string const get accessor.
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
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.
std::unique_ptr< lldb_private::SectionList > m_sections_up
static bool IsObjectFile(lldb_private::FileSpec file_spec)
static lldb::ObjectFileSP FindPlugin(const lldb::ModuleSP &module_sp, const FileSpec *file_spec, lldb::offset_t file_offset, lldb::offset_t file_size, lldb::DataExtractorSP extractor_sp, lldb::offset_t &data_offset)
Find a ObjectFile plug-in that can parse file_spec.
static lldb::DataBufferSP MapFileData(const FileSpec &file, uint64_t Size, uint64_t Offset)
virtual std::vector< LoadableData > GetLoadableData(Target &target)
Loads this objfile to memory.
~ObjectFile() override
Destructor.
std::unique_ptr< lldb_private::Symtab > m_symtab_up
const lldb::addr_t m_memory_addr
Set if the object file only exists in memory.
static size_t g_initial_bytes_to_read
The number of bytes to read when going through the plugins.
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.
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.
@ eTypeDebugInfo
An object file that contains only debug information.
@ eTypeStubLibrary
A library that can be linked against but not used for execution.
@ eTypeObjectFile
An intermediate object file.
@ eTypeDynamicLinker
The platform's dynamic linker executable.
@ eTypeCoreFile
A core file that has a checkpoint of a program's execution state.
@ eTypeSharedLibrary
A shared library that can be used during execution.
@ eTypeJIT
JIT code that has symbols, sections and possibly debug info.
lldb::addr_t m_file_offset
The offset in bytes into the file, or the address in memory.
static lldb::SymbolType GetSymbolTypeFromName(llvm::StringRef name, lldb::SymbolType symbol_type_hint=lldb::eSymbolTypeUndefined)
virtual size_t GetSectionDataSize(Section *section)
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.
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
virtual SectionList * GetSectionList(bool update_module_section_list=true)
Gets the section list for the currently selected architecture (and object for archives).
ObjectFile(const lldb::ModuleSP &module_sp, const FileSpec *file_spec_ptr, lldb::offset_t file_offset, lldb::offset_t length, lldb::DataExtractorSP extractor_sp, lldb::offset_t data_offset)
Construct with a parent module, offset, and header data.
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.
bool IsInMemory() const
Returns true if the object file exists only in memory.
lldb::ProcessWP m_process_wp
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...
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
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
lldb::SectionSP GetSectionAtIndex(size_t idx) const
uint32_t GetTargetByteSize() const
lldb::offset_t GetFileOffset() const
ObjectFile * GetObjectFile()
lldb::SectionType GetType() const
lldb::addr_t GetLoadBaseAddress(Target *target) const
lldb::addr_t GetByteSize() const
lldb::offset_t GetFileSize() const
llvm::StringRef GetString() const
void Format(const char *format, Args &&... args)
bool ValueIsAddress() const
Address & GetAddressRef()
lldb::SymbolType GetType() const
Symbol * FindSymbolContainingFileAddress(lldb::addr_t file_addr)
std::recursive_mutex & GetMutex()
lldb::addr_t GetSectionLoadAddress(const lldb::SectionSP §ion_sp)
#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.
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::DataExtractorSP extractor_sp, lldb::offset_t data_offset, const FileSpec *file, lldb::offset_t file_offset, lldb::offset_t length)
std::shared_ptr< lldb_private::ObjectFile > ObjectFileSP
std::shared_ptr< lldb_private::Process > ProcessSP
@ eSymbolTypeVariableType
@ eSymbolTypeObjCMetaClass
@ eSymbolTypeAdditional
When symbols take more than one entry, the extra entries get this type.
@ eSymbolTypeInstrumentation
std::shared_ptr< lldb_private::DataBuffer > DataBufferSP
std::shared_ptr< lldb_private::Section > SectionSP
std::shared_ptr< lldb_private::WritableDataBuffer > WritableDataBufferSP
@ eSectionTypeDWARFDebugStrOffsets
@ eSectionTypeELFDynamicSymbols
Elf SHT_DYNSYM section.
@ eSectionTypeDWARFDebugPubNames
@ eSectionTypeDataObjCCFStrings
Objective-C const CFString/NSString objects.
@ eSectionTypeDWARFDebugLocDwo
@ eSectionTypeDWARFDebugFrame
@ 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.
@ eSectionTypeDWARFDebugStrOffsetsDwo
@ eSectionTypeDWARFDebugMacro
@ eSectionTypeDWARFAppleTypes
@ eSectionTypeDWARFDebugInfo
@ eSectionTypeDWARFDebugTypesDwo
@ eSectionTypeDWARFDebugRanges
@ eSectionTypeDWARFDebugRngListsDwo
@ eSectionTypeLLDBTypeSummaries
@ 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
@ eSectionTypeDataCString
Inlined C string data.
@ eSectionTypeELFSymbolTable
Elf SHT_SYMTAB section.
std::shared_ptr< lldb_private::DataExtractor > DataExtractorSP
std::shared_ptr< lldb_private::Module > ModuleSP
llvm::ArrayRef< uint8_t > Contents