From cf79df0edb78abae8d8b7f77513b60af9a02c513 Mon Sep 17 00:00:00 2001 From: MacDue Date: Sat, 6 May 2023 19:33:53 +0100 Subject: [PATCH] LibDebug: Stub out LocListX and remove stub expression evaluator The expression evaluator is dead code that does nothing but crash on all paths, as no opcodes are implemented. Stubbing out the LocListX form fixes a crash while reading DWARF 5 debug data that contains location lists. These are just a new way to store location expressions, and since we never implemented expressions, we can just ignore these too. As far as I can tell this is enough for DWARF 5 to work for us (since we mainly just use the line tables). --- Userland/Libraries/LibDebug/CMakeLists.txt | 1 - Userland/Libraries/LibDebug/DebugInfo.cpp | 18 +++------ .../Libraries/LibDebug/Dwarf/DwarfInfo.cpp | 1 + .../Libraries/LibDebug/Dwarf/Expression.cpp | 33 ----------------- .../Libraries/LibDebug/Dwarf/Expression.h | 37 ------------------- 5 files changed, 6 insertions(+), 84 deletions(-) delete mode 100644 Userland/Libraries/LibDebug/Dwarf/Expression.cpp delete mode 100644 Userland/Libraries/LibDebug/Dwarf/Expression.h diff --git a/Userland/Libraries/LibDebug/CMakeLists.txt b/Userland/Libraries/LibDebug/CMakeLists.txt index fbfc578171..b708019722 100644 --- a/Userland/Libraries/LibDebug/CMakeLists.txt +++ b/Userland/Libraries/LibDebug/CMakeLists.txt @@ -7,7 +7,6 @@ set(SOURCES Dwarf/CompilationUnit.cpp Dwarf/DIE.cpp Dwarf/DwarfInfo.cpp - Dwarf/Expression.cpp Dwarf/LineProgram.cpp ProcessInspector.cpp StackFrameUtils.cpp diff --git a/Userland/Libraries/LibDebug/DebugInfo.cpp b/Userland/Libraries/LibDebug/DebugInfo.cpp index b437a063f3..88eb5a7044 100644 --- a/Userland/Libraries/LibDebug/DebugInfo.cpp +++ b/Userland/Libraries/LibDebug/DebugInfo.cpp @@ -10,7 +10,6 @@ #include #include #include -#include namespace Debug { @@ -207,7 +206,7 @@ static ErrorOr> parse_variable_type_die(Dwarf::DIE const& v return type_die; } -static ErrorOr parse_variable_location(Dwarf::DIE const& variable_die, DebugInfo::VariableInfo& variable_info, PtraceRegisters const& regs) +static ErrorOr parse_variable_location(Dwarf::DIE const& variable_die, DebugInfo::VariableInfo& variable_info, PtraceRegisters const&) { auto location_info = TRY(variable_die.get_attribute(Dwarf::Attribute::Location)); if (!location_info.has_value()) { @@ -219,20 +218,13 @@ static ErrorOr parse_variable_location(Dwarf::DIE const& variable_die, Deb switch (location_info.value().type()) { case Dwarf::AttributeValue::Type::UnsignedNumber: - variable_info.location_type = DebugInfo::VariableInfo::LocationType::Address; - variable_info.location_data.address = location_info.value().as_unsigned(); - break; - case Dwarf::AttributeValue::Type::DwarfExpression: { - auto expression_bytes = location_info.value().as_raw_bytes(); - auto value = TRY(Dwarf::Expression::evaluate(expression_bytes, regs)); - - if (value.type != Dwarf::Expression::Type::None) { - VERIFY(value.type == Dwarf::Expression::Type::UnsignedInteger); + if (location_info->form() != Dwarf::AttributeDataForm::LocListX) { variable_info.location_type = DebugInfo::VariableInfo::LocationType::Address; - variable_info.location_data.address = value.data.as_addr; + variable_info.location_data.address = location_info.value().as_unsigned(); + } else { + dbgln("Warning: unsupported Dwarf 5 loclist"); } break; - } default: dbgln("Warning: unhandled Dwarf location type: {}", to_underlying(location_info.value().type())); } diff --git a/Userland/Libraries/LibDebug/Dwarf/DwarfInfo.cpp b/Userland/Libraries/LibDebug/Dwarf/DwarfInfo.cpp index 9f73930468..230ac015b7 100644 --- a/Userland/Libraries/LibDebug/Dwarf/DwarfInfo.cpp +++ b/Userland/Libraries/LibDebug/Dwarf/DwarfInfo.cpp @@ -272,6 +272,7 @@ ErrorOr DwarfInfo::get_attribute_value(AttributeDataForm form, s value.m_data.as_unsigned = index; break; } + case AttributeDataForm::LocListX: case AttributeDataForm::RngListX: { size_t index = TRY(debug_info_stream.read_value>()); value.m_type = AttributeValue::Type::UnsignedNumber; diff --git a/Userland/Libraries/LibDebug/Dwarf/Expression.cpp b/Userland/Libraries/LibDebug/Dwarf/Expression.cpp deleted file mode 100644 index 30f45f6e4b..0000000000 --- a/Userland/Libraries/LibDebug/Dwarf/Expression.cpp +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2020, Itamar S. - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#include "Expression.h" - -#include -#include -#include - -namespace Debug::Dwarf::Expression { - -ErrorOr evaluate(ReadonlyBytes bytes, [[maybe_unused]] PtraceRegisters const& regs) -{ - FixedMemoryStream stream { bytes }; - - while (!stream.is_eof()) { - auto opcode = TRY(stream.read_value()); - - switch (static_cast(opcode)) { - - default: - dbgln("DWARF expr addr: {:p}", bytes.data()); - dbgln("unsupported opcode: {}", opcode); - VERIFY_NOT_REACHED(); - } - } - VERIFY_NOT_REACHED(); -} - -} diff --git a/Userland/Libraries/LibDebug/Dwarf/Expression.h b/Userland/Libraries/LibDebug/Dwarf/Expression.h deleted file mode 100644 index 44652afa90..0000000000 --- a/Userland/Libraries/LibDebug/Dwarf/Expression.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2020, Itamar S. - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#pragma once - -#include -#include - -struct PtraceRegisters; - -namespace Debug::Dwarf::Expression { - -enum class Type { - None, - UnsignedInteger, - Register, -}; - -struct Value { - Type type; - union { - FlatPtr as_addr; - u32 as_u32; - } data { 0 }; -}; - -enum class Operations : u8 { - RegEbp = 0x75, - FbReg = 0x91, -}; - -ErrorOr evaluate(ReadonlyBytes, PtraceRegisters const&); - -}