From 908b88db347e932934ee311be8d3920cabbe8886 Mon Sep 17 00:00:00 2001 From: Tim Schumacher Date: Sat, 21 Jan 2023 12:27:24 +0100 Subject: [PATCH] LibDebug: Use `Core::Stream` to read the DWARF abbreviations map --- .../LibDebug/Dwarf/AbbreviationsMap.cpp | 29 ++++++++++--------- .../LibDebug/Dwarf/AbbreviationsMap.h | 2 +- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/Userland/Libraries/LibDebug/Dwarf/AbbreviationsMap.cpp b/Userland/Libraries/LibDebug/Dwarf/AbbreviationsMap.cpp index 01c3505d0d..c112e1878a 100644 --- a/Userland/Libraries/LibDebug/Dwarf/AbbreviationsMap.cpp +++ b/Userland/Libraries/LibDebug/Dwarf/AbbreviationsMap.cpp @@ -7,7 +7,8 @@ #include "AbbreviationsMap.h" #include "DwarfInfo.h" -#include +#include +#include namespace Debug::Dwarf { @@ -15,27 +16,27 @@ AbbreviationsMap::AbbreviationsMap(DwarfInfo const& dwarf_info, u32 offset) : m_dwarf_info(dwarf_info) , m_offset(offset) { - populate_map(); + populate_map().release_value_but_fixme_should_propagate_errors(); } -void AbbreviationsMap::populate_map() +ErrorOr AbbreviationsMap::populate_map() { - InputMemoryStream abbreviation_stream(m_dwarf_info.abbreviation_data()); - abbreviation_stream.discard_or_error(m_offset); + auto abbreviation_stream = TRY(Core::Stream::FixedMemoryStream::construct(m_dwarf_info.abbreviation_data())); + TRY(abbreviation_stream->discard(m_offset)); + Core::Stream::WrapInAKInputStream wrapped_abbreviation_stream { *abbreviation_stream }; - while (!abbreviation_stream.eof()) { + while (!abbreviation_stream->is_eof()) { size_t abbreviation_code = 0; - abbreviation_stream.read_LEB128_unsigned(abbreviation_code); + LEB128::read_unsigned(wrapped_abbreviation_stream, abbreviation_code); // An abbreviation code of 0 marks the end of the // abbreviations for a given compilation unit if (abbreviation_code == 0) break; size_t tag {}; - abbreviation_stream.read_LEB128_unsigned(tag); + LEB128::read_unsigned(wrapped_abbreviation_stream, tag); - u8 has_children = 0; - abbreviation_stream >> has_children; + auto has_children = TRY(abbreviation_stream->read_value()); AbbreviationEntry abbreviation_entry {}; abbreviation_entry.tag = static_cast(tag); @@ -45,15 +46,15 @@ void AbbreviationsMap::populate_map() do { size_t attribute_value = 0; size_t form_value = 0; - abbreviation_stream.read_LEB128_unsigned(attribute_value); - abbreviation_stream.read_LEB128_unsigned(form_value); + LEB128::read_unsigned(wrapped_abbreviation_stream, attribute_value); + LEB128::read_unsigned(wrapped_abbreviation_stream, form_value); current_attribute_specification.attribute = static_cast(attribute_value); current_attribute_specification.form = static_cast(form_value); if (current_attribute_specification.form == AttributeDataForm::ImplicitConst) { ssize_t data_value; - abbreviation_stream.read_LEB128_signed(data_value); + LEB128::read_unsigned(wrapped_abbreviation_stream, data_value); current_attribute_specification.value = data_value; } @@ -64,6 +65,8 @@ void AbbreviationsMap::populate_map() m_entries.set(static_cast(abbreviation_code), move(abbreviation_entry)); } + + return {}; } AbbreviationsMap::AbbreviationEntry const* AbbreviationsMap::get(u32 code) const diff --git a/Userland/Libraries/LibDebug/Dwarf/AbbreviationsMap.h b/Userland/Libraries/LibDebug/Dwarf/AbbreviationsMap.h index 9b5cb74334..64306f5728 100644 --- a/Userland/Libraries/LibDebug/Dwarf/AbbreviationsMap.h +++ b/Userland/Libraries/LibDebug/Dwarf/AbbreviationsMap.h @@ -28,7 +28,7 @@ public: AbbreviationEntry const* get(u32 code) const; private: - void populate_map(); + ErrorOr populate_map(); DwarfInfo const& m_dwarf_info; u32 m_offset { 0 };