LibDebug: Use InputMemoryStream instead of BufferStream.

This removes another call to ByteBuffer::wrap(const void*, size_t).
This commit is contained in:
asynts 2020-08-05 10:55:36 +02:00 committed by Andreas Kling
parent 5bfa7749c3
commit ac9f6fd1f8
Notes: sideshowbarker 2024-07-19 04:14:19 +09:00
12 changed files with 125 additions and 106 deletions

View file

@ -26,6 +26,8 @@
#include "DwarfInfo.h"
#include <AK/Stream.h>
namespace Dwarf {
DwarfInfo::DwarfInfo(NonnullRefPtr<const ELF::Loader> elf)
@ -50,22 +52,19 @@ void DwarfInfo::populate_compilation_units()
{
if (m_debug_info_data.is_null())
return;
// We have to const_cast here because there isn't a version of
// BufferStream that accepts a const ByteStream
// We take care not to use BufferStream operations that modify the underlying buffer
// TOOD: Add a variant of BufferStream that operates on a const ByteBuffer to AK
BufferStream stream(const_cast<ByteBuffer&>(m_debug_info_data));
while (!stream.at_end()) {
InputMemoryStream stream(m_debug_info_data.span());
while (!stream.eof()) {
auto unit_offset = stream.offset();
CompilationUnitHeader compilation_unit_header {};
stream.read_raw(reinterpret_cast<u8*>(&compilation_unit_header), sizeof(CompilationUnitHeader));
stream >> Bytes { &compilation_unit_header, sizeof(compilation_unit_header) };
ASSERT(compilation_unit_header.address_size == sizeof(u32));
ASSERT(compilation_unit_header.version == 4);
u32 length_after_header = compilation_unit_header.length - (sizeof(CompilationUnitHeader) - offsetof(CompilationUnitHeader, version));
m_compilation_units.empend(*this, unit_offset, compilation_unit_header);
stream.advance(length_after_header);
stream.discard_or_error(length_after_header);
}
}