1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:18:11 +00:00

LibDebug: Keep going when parent's location info could not be computed

Previously, when trying to parse the location info of a member
variable, we asserted that the location info of its parent is of type
'Address'.

However, there are cases where we cannot compute the location info of
the parent (for example - because we do not yet support the type of
debug info generated for it).
In those cases, it is better to just leave the location info of the
member variable empty instead of crashing.
This commit is contained in:
Itamar 2021-01-08 12:16:34 +02:00 committed by Andreas Kling
parent e318a3d3d4
commit 20974b0772

View file

@ -225,25 +225,31 @@ static Optional<Dwarf::DIE> parse_variable_type_die(const Dwarf::DIE& variable_d
static void parse_variable_location(const Dwarf::DIE& variable_die, DebugInfo::VariableInfo& variable_info, const PtraceRegisters& regs)
{
auto location_info = variable_die.get_attribute(Dwarf::Attribute::Location);
if (!location_info.has_value())
if (!location_info.has_value()) {
location_info = variable_die.get_attribute(Dwarf::Attribute::MemberLocation);
}
if (location_info.has_value()) {
if (location_info.value().type == Dwarf::DIE::AttributeValue::Type::UnsignedNumber) {
if (!location_info.has_value())
return;
switch (location_info.value().type) {
case Dwarf::DIE::AttributeValue::Type::UnsignedNumber:
variable_info.location_type = DebugInfo::VariableInfo::LocationType::Address;
variable_info.location_data.address = location_info.value().data.as_u32;
break;
case Dwarf::DIE::AttributeValue::Type::DwarfExpression: {
auto expression_bytes = ReadonlyBytes { location_info.value().data.as_raw_bytes.bytes, location_info.value().data.as_raw_bytes.length };
auto value = Dwarf::Expression::evaluate(expression_bytes, regs);
if (value.type != Dwarf::Expression::Type::None) {
ASSERT(value.type == Dwarf::Expression::Type::UnsignedIntetger);
variable_info.location_type = DebugInfo::VariableInfo::LocationType::Address;
variable_info.location_data.address = location_info.value().data.as_u32;
}
if (location_info.value().type == Dwarf::DIE::AttributeValue::Type::DwarfExpression) {
auto expression_bytes = ReadonlyBytes { location_info.value().data.as_raw_bytes.bytes, location_info.value().data.as_raw_bytes.length };
auto value = Dwarf::Expression::evaluate(expression_bytes, regs);
if (value.type != Dwarf::Expression::Type::None) {
ASSERT(value.type == Dwarf::Expression::Type::UnsignedIntetger);
variable_info.location_type = DebugInfo::VariableInfo::LocationType::Address;
variable_info.location_data.address = value.data.as_u32;
}
variable_info.location_data.address = value.data.as_u32;
}
break;
}
default:
dbgln("Warninig: unhandled Dwarf location type: {}", (int)location_info.value().type);
}
}
@ -297,13 +303,15 @@ OwnPtr<DebugInfo::VariableInfo> DebugInfo::create_variable_info(const Dwarf::DIE
if (member.is_null())
return;
auto member_variable = create_variable_info(member, regs);
ASSERT(member_variable);
if (type_die.value().tag() == Dwarf::EntryTag::EnumerationType) {
member_variable->parent = type_info.ptr();
type_info->members.append(member_variable.release_nonnull());
} else {
if (variable_info->location_type == DebugInfo::VariableInfo::LocationType::None) {
return;
}
ASSERT(variable_info->location_type == DebugInfo::VariableInfo::LocationType::Address);
if (member_variable->location_type == DebugInfo::VariableInfo::LocationType::Address)