From a9eea2e0c4765887d0f3f21c79ffa0a84953967f Mon Sep 17 00:00:00 2001 From: Tim Schumacher Date: Sun, 22 Jan 2023 00:51:45 +0100 Subject: [PATCH] LibDebug: Use `Core::Stream` to read opcodes for expression evaluation --- Userland/Libraries/LibDebug/DebugInfo.cpp | 2 +- Userland/Libraries/LibDebug/Dwarf/Expression.cpp | 11 +++++------ Userland/Libraries/LibDebug/Dwarf/Expression.h | 2 +- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/Userland/Libraries/LibDebug/DebugInfo.cpp b/Userland/Libraries/LibDebug/DebugInfo.cpp index d1c69120fe..6d6994cdfc 100644 --- a/Userland/Libraries/LibDebug/DebugInfo.cpp +++ b/Userland/Libraries/LibDebug/DebugInfo.cpp @@ -231,7 +231,7 @@ static ErrorOr parse_variable_location(Dwarf::DIE const& variable_die, Deb break; case Dwarf::AttributeValue::Type::DwarfExpression: { auto expression_bytes = location_info.value().as_raw_bytes(); - auto value = Dwarf::Expression::evaluate(expression_bytes, regs); + auto value = TRY(Dwarf::Expression::evaluate(expression_bytes, regs)); if (value.type != Dwarf::Expression::Type::None) { VERIFY(value.type == Dwarf::Expression::Type::UnsignedInteger); diff --git a/Userland/Libraries/LibDebug/Dwarf/Expression.cpp b/Userland/Libraries/LibDebug/Dwarf/Expression.cpp index 11acb72b53..74ae6f5149 100644 --- a/Userland/Libraries/LibDebug/Dwarf/Expression.cpp +++ b/Userland/Libraries/LibDebug/Dwarf/Expression.cpp @@ -7,18 +7,17 @@ #include "Expression.h" #include -#include +#include #include namespace Debug::Dwarf::Expression { -Value evaluate(ReadonlyBytes bytes, [[maybe_unused]] PtraceRegisters const& regs) +ErrorOr evaluate(ReadonlyBytes bytes, [[maybe_unused]] PtraceRegisters const& regs) { - InputMemoryStream stream(bytes); + auto stream = TRY(Core::Stream::FixedMemoryStream::construct(bytes)); - while (!stream.eof()) { - u8 opcode = 0; - stream >> opcode; + while (!stream->is_eof()) { + auto opcode = TRY(stream->read_value()); switch (static_cast(opcode)) { diff --git a/Userland/Libraries/LibDebug/Dwarf/Expression.h b/Userland/Libraries/LibDebug/Dwarf/Expression.h index ce98787d07..44652afa90 100644 --- a/Userland/Libraries/LibDebug/Dwarf/Expression.h +++ b/Userland/Libraries/LibDebug/Dwarf/Expression.h @@ -32,6 +32,6 @@ enum class Operations : u8 { FbReg = 0x91, }; -Value evaluate(ReadonlyBytes, PtraceRegisters const&); +ErrorOr evaluate(ReadonlyBytes, PtraceRegisters const&); }