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).
This commit is contained in:
MacDue 2023-05-06 19:33:53 +01:00 committed by Andreas Kling
parent ce634957c1
commit cf79df0edb
5 changed files with 6 additions and 84 deletions

View file

@ -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

View file

@ -10,7 +10,6 @@
#include <AK/QuickSort.h>
#include <LibDebug/Dwarf/CompilationUnit.h>
#include <LibDebug/Dwarf/DwarfInfo.h>
#include <LibDebug/Dwarf/Expression.h>
namespace Debug {
@ -207,7 +206,7 @@ static ErrorOr<Optional<Dwarf::DIE>> parse_variable_type_die(Dwarf::DIE const& v
return type_die;
}
static ErrorOr<void> parse_variable_location(Dwarf::DIE const& variable_die, DebugInfo::VariableInfo& variable_info, PtraceRegisters const& regs)
static ErrorOr<void> 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<void> 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()));
}

View file

@ -272,6 +272,7 @@ ErrorOr<AttributeValue> 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<LEB128<size_t>>());
value.m_type = AttributeValue::Type::UnsignedNumber;

View file

@ -1,33 +0,0 @@
/*
* Copyright (c) 2020, Itamar S. <itamar8910@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "Expression.h"
#include <AK/Format.h>
#include <AK/MemoryStream.h>
#include <sys/arch/regs.h>
namespace Debug::Dwarf::Expression {
ErrorOr<Value> evaluate(ReadonlyBytes bytes, [[maybe_unused]] PtraceRegisters const& regs)
{
FixedMemoryStream stream { bytes };
while (!stream.is_eof()) {
auto opcode = TRY(stream.read_value<u8>());
switch (static_cast<Operations>(opcode)) {
default:
dbgln("DWARF expr addr: {:p}", bytes.data());
dbgln("unsupported opcode: {}", opcode);
VERIFY_NOT_REACHED();
}
}
VERIFY_NOT_REACHED();
}
}

View file

@ -1,37 +0,0 @@
/*
* Copyright (c) 2020, Itamar S. <itamar8910@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/ByteBuffer.h>
#include <AK/Types.h>
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<Value> evaluate(ReadonlyBytes, PtraceRegisters const&);
}