1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 01:07:35 +00:00

LibDebug+HackStudio: Fix crashes relating to debugger variable preview

For one, viewing a variable who's type contained a subprogram will
no longer crash HackStudio. Additionally, the variable view will
handle invalid enum values gracefully now, fixing another crash.
Finally, deeply nested (nest count > 1) structures will have their
memory addresses properly set, fixing the final crash I found.
This commit is contained in:
FalseHonesty 2021-04-12 01:30:57 -04:00 committed by Andreas Kling
parent c778164f64
commit d295095993
3 changed files with 10 additions and 9 deletions

View file

@ -83,7 +83,8 @@ static String variable_value_as_string(const Debug::DebugInfo::VariableInfo& var
auto it = variable.type->members.find_if([&enumerator_value = value.value()](const auto& enumerator) { auto it = variable.type->members.find_if([&enumerator_value = value.value()](const auto& enumerator) {
return enumerator->constant_data.as_u32 == enumerator_value; return enumerator->constant_data.as_u32 == enumerator_value;
}); });
VERIFY(!it.is_end()); if (it.is_end())
return String::formatted("Unknown ({})", value.value());
return String::formatted("{}::{}", variable.type_name, (*it)->name); return String::formatted("{}::{}", variable.type_name, (*it)->name);
} }

View file

@ -252,7 +252,7 @@ static void parse_variable_location(const Dwarf::DIE& variable_die, DebugInfo::V
} }
} }
OwnPtr<DebugInfo::VariableInfo> DebugInfo::create_variable_info(const Dwarf::DIE& variable_die, const PtraceRegisters& regs) const OwnPtr<DebugInfo::VariableInfo> DebugInfo::create_variable_info(const Dwarf::DIE& variable_die, const PtraceRegisters& regs, u32 address_offset) const
{ {
VERIFY(variable_die.tag() == Dwarf::EntryTag::Variable VERIFY(variable_die.tag() == Dwarf::EntryTag::Variable
|| variable_die.tag() == Dwarf::EntryTag::Member || variable_die.tag() == Dwarf::EntryTag::Member
@ -290,6 +290,7 @@ OwnPtr<DebugInfo::VariableInfo> DebugInfo::create_variable_info(const Dwarf::DIE
} }
} else { } else {
parse_variable_location(variable_die, *variable_info, regs); parse_variable_location(variable_die, *variable_info, regs);
variable_info->location_data.address += address_offset;
} }
if (type_die.has_value()) { if (type_die.has_value()) {
@ -301,21 +302,20 @@ OwnPtr<DebugInfo::VariableInfo> DebugInfo::create_variable_info(const Dwarf::DIE
type_die.value().for_each_child([&](const Dwarf::DIE& member) { type_die.value().for_each_child([&](const Dwarf::DIE& member) {
if (member.is_null()) if (member.is_null())
return; return;
auto member_variable = create_variable_info(member, regs); if (member.tag() == Dwarf::EntryTag::SubProgram)
return;
auto member_variable = create_variable_info(member, regs, variable_info->location_data.address);
VERIFY(member_variable); VERIFY(member_variable);
if (type_die.value().tag() == Dwarf::EntryTag::EnumerationType) { if (type_die.value().tag() == Dwarf::EntryTag::EnumerationType) {
member_variable->parent = type_info.ptr(); member_variable->parent = type_info.ptr();
type_info->members.append(member_variable.release_nonnull()); type_info->members.append(member_variable.release_nonnull());
} else { } else {
if (variable_info->location_type == DebugInfo::VariableInfo::LocationType::None) { if (variable_info->location_type == DebugInfo::VariableInfo::LocationType::None)
return; return;
}
VERIFY(variable_info->location_type == DebugInfo::VariableInfo::LocationType::Address); VERIFY(variable_info->location_type == DebugInfo::VariableInfo::LocationType::Address);
if (member_variable->location_type == DebugInfo::VariableInfo::LocationType::Address)
member_variable->location_data.address += variable_info->location_data.address;
member_variable->parent = variable_info.ptr(); member_variable->parent = variable_info.ptr();
variable_info->members.append(member_variable.release_nonnull()); variable_info->members.append(member_variable.release_nonnull());
} }

View file

@ -140,7 +140,7 @@ private:
void prepare_variable_scopes(); void prepare_variable_scopes();
void prepare_lines(); void prepare_lines();
void parse_scopes_impl(const Dwarf::DIE& die); void parse_scopes_impl(const Dwarf::DIE& die);
OwnPtr<VariableInfo> create_variable_info(const Dwarf::DIE& variable_die, const PtraceRegisters&) const; OwnPtr<VariableInfo> create_variable_info(const Dwarf::DIE& variable_die, const PtraceRegisters&, u32 address_offset = 0) const;
NonnullOwnPtr<const ELF::Image> m_elf; NonnullOwnPtr<const ELF::Image> m_elf;
String m_source_root; String m_source_root;