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);
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));
74 if (file_exists && module_sp->GetObjectName()) {
76 module_sp, file, file_offset, file_size, data_sp, data_offset);
78 return object_file_sp;
91 if (!data_sp || data_sp->GetByteSize() == 0) {
93 llvm::SmallString<256> path_with_object;
94 module_sp->GetFileSpec().GetPath(path_with_object);
98 const bool must_exist =
true;
100 archive_object, must_exist)) {
103 file = &archive_file;
104 module_sp->SetFileSpecAndObjectName(archive_file, archive_object);
113 module_sp, file, file_offset, file_size, data_sp, data_offset);
115 return object_file_sp;
124 if (data_sp && data_sp->GetByteSize() > 0) {
128 for (uint32_t idx = 0;
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;
142 module_sp, file, file_offset, file_size, data_sp, data_offset);
144 return object_file_sp;
160 "%s, process = %p, header_addr = "
162 module_sp->GetFileSpec().GetPath().c_str(),
163 static_cast<void *
>(process_sp.get()), header_addr);
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;
183 object_file_sp.reset();
184 return object_file_sp;
190 ModuleSP module_sp = std::make_shared<Module>(file_spec);
193 data_sp, data_offset));
205 if (file_size == 0) {
208 if (actual_file_size > file_offset)
209 file_size = actual_file_size - file_offset;
225 const size_t initial_count = specs.
GetSize();
234 if (callback(file, data_sp, data_offset, file_offset, file_size, specs) > 0)
235 return specs.
GetSize() - initial_count;
244 if (callback(file, data_sp, data_offset, file_offset, file_size, specs) > 0)
245 return specs.
GetSize() - initial_count;
256 m_type(eTypeInvalid), m_strata(eStrataInvalid),
257 m_file_offset(file_offset), m_length(length), m_data(), m_process_wp(),
259 m_symtab_once_up(new
llvm::once_flag()) {
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(),
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()) {
282 m_data.
SetData(header_data_sp, 0, header_data_sp->GetByteSize());
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(),
294 LLDB_LOGF(log,
"%p ObjectFile::~ObjectFile ()\n",
static_cast<void *
>(
this));
300 return module_sp->SetArchitecture(new_arch);
312 const SectionType section_type = section_sp->GetType();
313 switch (section_type) {
392 switch (symbol_type) {
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());
504 const addr_t base_load_addr =
507 return process_sp->ReadMemory(base_load_addr + section_offset, dst,
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;
518 section_dst_len, dst);
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;
547 const addr_t base_load_addr =
553 section_data.
SetData(data_sp, 0, data_sp->GetByteSize());
572 size_t len = path_with_object.size();
573 if (len < 2 || path_with_object.back() !=
')')
575 llvm::StringRef archive = path_with_object.substr(0, path_with_object.rfind(
'('));
578 llvm::StringRef
object = path_with_object.substr(archive.size() + 1).drop_back();
579 archive_file.
SetFile(archive, FileSpec::Style::native);
590 LLDB_LOGF(log,
"%p ObjectFile::ClearSymtab () symtab = %p",
591 static_cast<void *
>(
this),
602 if (update_module_section_list) {
605 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
620 if (name.starts_with(
"_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_")) {
633 return symbol_type_hint;
636std::vector<ObjectFile::LoadableData>
638 std::vector<LoadableData> loadables;
644 for (
size_t i = 0; i < section_count; ++i) {
652 if (section_sp->GetFileSize() == 0)
655 section_sp->GetSectionData(section_data);
658 loadables.push_back(loadable);
676void llvm::format_provider<ObjectFile::Type>::format(
692 OS <<
"dynamic linker";
698 OS <<
"shared library";
701 OS <<
"stub library";
712void llvm::format_provider<ObjectFile::Strata>::format(
756 std::lock_guard<std::recursive_mutex> symtab_guard(symtab->
GetMutex());
782 if (
auto str = value.getAsString()) {
783 type = llvm::StringSwitch<ObjectFile::Type>(*str)
796 path.report(
"invalid object type");
802 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.
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.
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.
A mix in class that contains a pointer back to the module that owns the object which inherits from it...
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.
DataExtractor m_data
The data for this object file so things can be parsed lazily.
Symtab * GetSymtab()
Gets the symbol table for the currently selected architecture (and object for archives).
std::unique_ptr< lldb_private::SectionList > m_sections_up
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
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.
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.
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.
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).
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
lldb::addr_t GetSectionLoadAddress(const lldb::SectionSP §ion_sp) 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()
SectionLoadList & GetSectionLoadList()
#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)
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)
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
@ eSectionTypeDWARFDebugNames
DWARF v5 .debug_names.
@ eSectionTypeDWARFDebugRngLists
DWARF v5 .debug_rnglists.
@ eSectionTypeDWARFDebugStrOffsetsDwo
@ eSectionTypeDWARFDebugMacro
@ eSectionTypeDWARFAppleTypes
@ eSectionTypeDWARFDebugInfo
@ eSectionTypeDWARFDebugTypesDwo
@ eSectionTypeDWARFDebugRanges
@ eSectionTypeDWARFDebugRngListsDwo
@ 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::Module > ModuleSP
llvm::ArrayRef< uint8_t > Contents