diff options
| author | Jason Molenda <jmolenda@apple.com> | 2026-02-05 15:10:54 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-02-05 15:10:54 -0800 |
| commit | af3cc148c39e4e7d91250962019745c4bc1d37b3 (patch) | |
| tree | f909f2dddca4ca3f5e6bd7f221132820bdcb8b65 /lldb/source/Plugins/ObjectFile | |
| parent | 124c8b4054fd4fe8234611a367d50b5a62f5903e (diff) | |
| download | llvm-af3cc148c39e4e7d91250962019745c4bc1d37b3.tar.gz llvm-af3cc148c39e4e7d91250962019745c4bc1d37b3.tar.bz2 llvm-af3cc148c39e4e7d91250962019745c4bc1d37b3.zip | |
[lldb][NFC] Add some override methods to VirtualDataExtractor (#179858)
This changes VirtualDataExtractor's GetByteSize to return the virtual
byte size of the buffer (external users only understand the data
contents in terms of the virtual sizes & offsets). There are check
methods in DataExtractor that check they are not going off the end of a
buffer, they usually use the BytesLeft() method. There are a couple of
callers of BytesLeft() externally, but it is predominantly an internal
use API. I have BytesLeft() use the physical size of the buffer, not the
virtual size, for the benefit of the DataExtractor methods. (and to
avoid duplicating all of them down in VirtualDataExtractor)
Another problem is the we call SetData on DataExtractorSP's (e.g. see
the ObjectFile ctor) with the DataBuffer it already has, an offset of 0,
and the GetByteSize. A no-op for a DataExtractor that is already using
that DataBuffer. But SetData would try to use that length as a physical
size, and truncate the buffer that the DataExtractor would accept.
I added VirtualDataExtractor subclass methods for the SetData's, detect
(1) data being added to an uninitialized DataExtractor, (2) the same
data / offset / length as currently being used is added to the
DataExtractor (a no-op), or (3) we're genuinely changing the data source
or setting an offset / length that is different. This final case we're
not ready to handle today, I added asserts for them so we can catch it
in debug builds, and then I clear the LookupTable and add a no-op entry
so this extractor will behave like a plain DataExtractor -- because I
don't know better to do. If we genuinely need to handle this case, and
I'm pretty sure we don't need to, I'd have to assume that we're taking a
subset of the original data source (an offset & length), so we'd need to
update all of the LookupTable entries to reflect the new offsets, and
remove entries that are no longer referring to the subsetted range. I'll
leave that until there's any evidence it's actually needed.
rdar://148939795
Diffstat (limited to 'lldb/source/Plugins/ObjectFile')
| -rw-r--r-- | lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp | 10 | ||||
| -rw-r--r-- | lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h | 2 | ||||
| -rw-r--r-- | lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp | 2 |
3 files changed, 7 insertions, 7 deletions
diff --git a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp index 90afd5b2dc93..292907f4a8d4 100644 --- a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp +++ b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp @@ -481,7 +481,7 @@ ObjectFile *ObjectFileELF::CreateMemoryInstance( return nullptr; } -bool ObjectFileELF::MagicBytesMatch(DataBufferSP &data_sp, +bool ObjectFileELF::MagicBytesMatch(DataBufferSP data_sp, lldb::addr_t data_offset, lldb::addr_t data_length) { if (data_sp && @@ -2768,7 +2768,7 @@ static void ApplyELF64ABS64Relocation(Symtab *symtab, ELFRelocation &rel, symtab->FindSymbolByID(ELFRelocation::RelocSymbol64(rel)); if (symbol) { addr_t value = symbol->GetAddressRef().GetFileAddress(); - DataBufferSP &data_buffer_sp = debug_data.GetSharedDataBuffer(); + DataBufferSP data_buffer_sp = debug_data.GetSharedDataBuffer(); // ObjectFileELF creates a WritableDataBuffer in CreateInstance. WritableDataBuffer *data_buffer = llvm::cast<WritableDataBuffer>(data_buffer_sp.get()); @@ -2795,7 +2795,7 @@ static void ApplyELF64ABS32Relocation(Symtab *symtab, ELFRelocation &rel, return; } uint32_t truncated_addr = (value & 0xFFFFFFFF); - DataBufferSP &data_buffer_sp = debug_data.GetSharedDataBuffer(); + DataBufferSP data_buffer_sp = debug_data.GetSharedDataBuffer(); // ObjectFileELF creates a WritableDataBuffer in CreateInstance. WritableDataBuffer *data_buffer = llvm::cast<WritableDataBuffer>(data_buffer_sp.get()); @@ -2819,7 +2819,7 @@ static void ApplyELF32ABS32RelRelocation(Symtab *symtab, ELFRelocation &rel, return; } assert(llvm::isUInt<32>(value) && "Valid addresses are 32-bit"); - DataBufferSP &data_buffer_sp = debug_data.GetSharedDataBuffer(); + DataBufferSP data_buffer_sp = debug_data.GetSharedDataBuffer(); // ObjectFileELF creates a WritableDataBuffer in CreateInstance. WritableDataBuffer *data_buffer = llvm::cast<WritableDataBuffer>(data_buffer_sp.get()); @@ -2896,7 +2896,7 @@ unsigned ObjectFileELF::ApplyRelocations( if (symbol) { addr_t f_offset = rel_section->GetFileOffset() + ELFRelocation::RelocOffset32(rel); - DataBufferSP &data_buffer_sp = debug_data.GetSharedDataBuffer(); + DataBufferSP data_buffer_sp = debug_data.GetSharedDataBuffer(); // ObjectFileELF creates a WritableDataBuffer in CreateInstance. WritableDataBuffer *data_buffer = llvm::cast<WritableDataBuffer>(data_buffer_sp.get()); diff --git a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h index 4992e9e2482f..9fc19bcd07f3 100644 --- a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h +++ b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h @@ -85,7 +85,7 @@ public: lldb::offset_t length, lldb_private::ModuleSpecList &specs); - static bool MagicBytesMatch(lldb::DataBufferSP &data_sp, lldb::addr_t offset, + static bool MagicBytesMatch(lldb::DataBufferSP data_sp, lldb::addr_t offset, lldb::addr_t length); // PluginInterface protocol diff --git a/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp b/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp index 0bcccfc059bb..b34c03ea56a0 100644 --- a/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp +++ b/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp @@ -167,7 +167,7 @@ bool ObjectFileXCOFF::MagicBytesMatch(DataExtractorSP &extractor_sp, lldb::addr_t data_offset, lldb::addr_t data_length) { DataExtractorSP magic_extractor_sp = - extractor_sp->GetSubsetExtractorSP(data_offset, data_length); + extractor_sp->GetSubsetExtractorSP(data_offset); // Need to set this as XCOFF is only compatible with Big Endian magic_extractor_sp->SetByteOrder(eByteOrderBig); lldb::offset_t offset = 0; |
