27#include "llvm/Support/DJB.h"
40 std::unique_ptr<ObjectContainer> object_container_up(cbs.create_callback(
41 module_sp, data_sp, data_offset, file, file_offset, file_size));
42 if (object_container_up)
43 return object_container_up->GetObjectFile(file);
55 "ObjectFile::FindPlugin (module = %s, file = %p, file_offset = "
56 "0x%8.8" PRIx64
", file_size = 0x%8.8" PRIx64
")",
57 module_sp->GetFileSpec().GetPath().c_str(),
58 static_cast<const void *
>(file),
static_cast<uint64_t
>(file_offset),
59 static_cast<uint64_t
>(file_size));
67 if (!extractor_sp || !extractor_sp->HasData()) {
72 if (file_exists && module_sp->GetObjectName()) {
74 module_sp, file, file_offset, file_size,
DataBufferSP(), data_offset);
76 return object_file_sp;
87 extractor_sp = std::make_shared<DataExtractor>(buffer_sp);
93 if (!extractor_sp || !extractor_sp->HasData()) {
95 llvm::SmallString<256> path_with_object;
96 module_sp->GetFileSpec().GetPath(path_with_object);
100 const bool must_exist =
true;
102 archive_object, must_exist)) {
105 file = &archive_file;
106 module_sp->SetFileSpecAndObjectName(archive_file, archive_object);
118 return object_file_sp;
123 extractor_sp = std::make_shared<DataExtractor>(buffer_sp);
128 if (extractor_sp && extractor_sp->HasData()) {
136 cbs.create_callback(module_sp, extractor_copy_sp, data_offset, file,
137 file_offset, file_size));
138 if (object_file_sp.get())
139 return object_file_sp;
145 DataBufferSP buffer_sp = extractor_sp->GetSharedDataBuffer();
147 module_sp, file, file_offset, file_size, buffer_sp, data_offset);
149 return object_file_sp;
165 "%s, process = %p, header_addr = "
167 module_sp->GetFileSpec().GetPath().c_str(),
168 static_cast<void *
>(process_sp.get()), header_addr);
173 if (!cbs.create_memory_callback)
175 object_file_sp.reset(cbs.create_memory_callback(module_sp, data_sp,
176 process_sp, header_addr));
177 if (object_file_sp.get())
178 return object_file_sp;
184 object_file_sp.reset();
185 return object_file_sp;
191 ModuleSP module_sp = std::make_shared<Module>(file_spec);
194 extractor_sp, data_offset));
201 extractor_sp = std::make_shared<DataExtractor>();
202 if (!extractor_sp->HasData()) {
205 extractor_sp->SetData(file_data_sp);
207 if (extractor_sp->HasData()) {
208 if (file_size == 0) {
211 if (actual_file_size > file_offset)
212 file_size = actual_file_size - file_offset;
231 file, extractor_sp, file_offset, file_size);
232 if (object_specs.
GetSize() > 0) {
233 specs.
Append(object_specs);
241 file, extractor_sp, file_offset, file_size);
242 if (container_specs.
GetSize() > 0)
243 specs.
Append(container_specs);
262 if (extractor_sp && extractor_sp->HasData()) {
263 m_data_nsp = extractor_sp;
266 m_data_nsp->SetData(extractor_sp->GetSharedDataBuffer(), data_offset,
271 "%p ObjectFile::ObjectFile() module = %p (%s), file = %s, "
272 "file_offset = 0x%8.8" PRIx64
", size = %" PRIu64,
273 static_cast<void *
>(
this),
static_cast<void *
>(module_sp.get()),
274 module_sp->GetSpecificationDescription().c_str(),
287 if (header_extractor_sp && header_extractor_sp->HasData())
291 "%p ObjectFile::ObjectFile() module = %p (%s), process = %p, "
292 "header_addr = 0x%" PRIx64,
293 static_cast<void *
>(
this),
static_cast<void *
>(module_sp.get()),
294 module_sp->GetSpecificationDescription().c_str(),
300 LLDB_LOGF(log,
"%p ObjectFile::~ObjectFile ()\n",
static_cast<void *
>(
this));
306 return module_sp->SetArchitecture(new_arch);
318 const SectionType section_type = section_sp->GetType();
319 switch (section_type) {
402 switch (symbol_type) {
472 std::unique_ptr<DataBufferHeap> data_up(
new DataBufferHeap(byte_size, 0));
474 const size_t bytes_read = process_sp->ReadMemory(
475 addr, data_up->GetBytes(), data_up->GetByteSize(),
error);
476 if (bytes_read == byte_size)
477 data_sp.reset(data_up.release());
486 data_sp =
m_data_nsp->GetSubsetExtractorSP(offset, length);
487 return data_sp->GetByteSize();
494 return m_data_nsp->CopyData(offset, length, dst);
514 const addr_t base_load_addr =
517 return process_sp->ReadMemory(base_load_addr + section_offset, dst,
522 if (section_offset < section_file_size) {
523 const size_t section_bytes_left = section_file_size - section_offset;
524 size_t section_dst_len = dst_len;
525 if (section_dst_len > section_bytes_left)
526 section_dst_len = section_bytes_left;
528 section_dst_len, dst);
531 const uint64_t section_size = section->
GetByteSize();
532 const uint64_t section_bytes_left = section_size - section_offset;
533 uint64_t section_dst_len = dst_len;
534 if (section_dst_len > section_bytes_left)
535 section_dst_len = section_bytes_left;
536 memset(dst, 0, section_dst_len);
537 return section_dst_len;
557 const addr_t base_load_addr =
563 section_data.
SetData(data_sp, 0, data_sp->GetByteSize());
577 section_data = *extractor_sp;
585 size_t len = path_with_object.size();
586 if (len < 2 || path_with_object.back() !=
')')
588 llvm::StringRef archive = path_with_object.substr(0, path_with_object.rfind(
'('));
591 llvm::StringRef
object = path_with_object.substr(archive.size() + 1).drop_back();
592 archive_file.
SetFile(archive, FileSpec::Style::native);
603 LLDB_LOGF(log,
"%p ObjectFile::ClearSymtab () symtab = %p",
604 static_cast<void *
>(
this),
617 if (update_module_section_list) {
619 std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
633 if (name.starts_with(
"_OBJC_")) {
635 if (name.starts_with(
"_OBJC_CLASS_$_"))
637 if (name.starts_with(
"_OBJC_METACLASS_$_"))
639 if (name.starts_with(
"_OBJC_IVAR_$_"))
641 }
else if (name.starts_with(
".objc_class_name_")) {
646 return symbol_type_hint;
651 return llvm::StringSwitch<SectionType>(name)
684std::vector<ObjectFile::LoadableData>
686 std::vector<LoadableData> loadables;
692 for (
size_t i = 0; i < section_count; ++i) {
699 if (section_sp->GetFileSize() == 0)
702 section_sp->GetSectionData(section_data);
704 loadables.push_back(loadable);
722void llvm::format_provider<ObjectFile::Type>::format(
738 OS <<
"dynamic linker";
744 OS <<
"shared library";
747 OS <<
"stub library";
758void llvm::format_provider<ObjectFile::Strata>::format(
784 if (module_sp && can_create) {
801 std::lock_guard<std::recursive_mutex> symtab_guard(symtab->
GetMutex());
824 if (
ConstString object_name = module_sp->GetObjectName())
825 return llvm::formatv(
"{0}({1})",
GetFileSpec().GetFilename(),
826 object_name.GetString())
836 if (
auto str = value.getAsString()) {
837 type = llvm::StringSwitch<ObjectFile::Type>(*str)
850 path.report(
"invalid object type");
856 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.
llvm::StringRef 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.
void Append(const ModuleSpec &spec)
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.
std::recursive_mutex m_sections_mutex
static lldb::WritableDataBufferSP ReadMemory(const lldb::ProcessSP &process_sp, lldb::addr_t addr, size_t byte_size)
@ 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 GetData(lldb::offset_t offset, size_t length, lldb::DataExtractorSP &data_sp) const
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).
static ModuleSpecList GetModuleSpecifications(const FileSpec &file, lldb::offset_t file_offset, lldb::offset_t file_size, lldb::DataExtractorSP=lldb::DataExtractorSP())
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 related 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)
virtual lldb::addr_t GetByteSize() const
static llvm::SmallVector< ObjectFileCallbacks > GetObjectFileCallbacks()
static llvm::SmallVector< ObjectContainerCallbacks > GetObjectContainerCallbacks()
size_t GetNumSections(uint32_t depth) const
lldb::SectionSP GetSectionAtIndex(size_t idx) 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)
Forwards the arguments to llvm::formatv and writes to the stream.
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.
bool fromJSON(const llvm::json::Value &value, SymbolValue &data, 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
@ 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