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

LibDebug: Add support for creating VariableInfo for paramters

This commit is contained in:
Itamar 2020-05-08 15:38:54 +03:00 committed by Andreas Kling
parent 2acce56ac1
commit b28ca9fad1
3 changed files with 21 additions and 6 deletions

View file

@ -74,7 +74,8 @@ void DebugInfo::parse_scopes_impl(const Dwarf::DIE& die)
scope.address_high = scope.address_low + child.get_attribute(Dwarf::Attribute::HighPc).value().data.as_u32; scope.address_high = scope.address_low + child.get_attribute(Dwarf::Attribute::HighPc).value().data.as_u32;
child.for_each_child([&](const Dwarf::DIE& variable_entry) { child.for_each_child([&](const Dwarf::DIE& variable_entry) {
if (variable_entry.tag() != Dwarf::EntryTag::Variable) if (!(variable_entry.tag() == Dwarf::EntryTag::Variable
|| variable_entry.tag() == Dwarf::EntryTag::FormalParameter))
return; return;
scope.dies_of_variables.append(variable_entry); scope.dies_of_variables.append(variable_entry);
}); });
@ -148,15 +149,26 @@ NonnullOwnPtrVector<DebugInfo::VariableInfo> DebugInfo::get_variables_in_current
continue; continue;
for (const auto& die_entry : scope.dies_of_variables) { for (const auto& die_entry : scope.dies_of_variables) {
variables.append(create_variable_info(die_entry, regs)); auto variable_info = create_variable_info(die_entry, regs);
if (!variable_info)
continue;
variables.append(variable_info.release_nonnull());
} }
} }
return variables; return variables;
} }
NonnullOwnPtr<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) const
{ {
ASSERT(variable_die.tag() == Dwarf::EntryTag::Variable || variable_die.tag() == Dwarf::EntryTag::Member); ASSERT(variable_die.tag() == Dwarf::EntryTag::Variable
|| variable_die.tag() == Dwarf::EntryTag::Member
|| variable_die.tag() == Dwarf::EntryTag::FormalParameter);
if (variable_die.tag() == Dwarf::EntryTag::FormalParameter
&& !variable_die.get_attribute(Dwarf::Attribute::Name).has_value()) {
// We don't want to display info for unused paramters
return {};
}
NonnullOwnPtr<VariableInfo> variable_info = make<VariableInfo>(); NonnullOwnPtr<VariableInfo> variable_info = make<VariableInfo>();
@ -201,13 +213,15 @@ NonnullOwnPtr<DebugInfo::VariableInfo> DebugInfo::create_variable_info(const Dwa
if (member.is_null()) if (member.is_null())
return; return;
auto member_variable = create_variable_info(member, regs); auto member_variable = create_variable_info(member, regs);
ASSERT(member_variable);
ASSERT(member_variable->location_type == DebugInfo::VariableInfo::LocationType::Address); ASSERT(member_variable->location_type == DebugInfo::VariableInfo::LocationType::Address);
ASSERT(variable_info->location_type == DebugInfo::VariableInfo::LocationType::Address); ASSERT(variable_info->location_type == DebugInfo::VariableInfo::LocationType::Address);
member_variable->location_data.address += variable_info->location_data.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(move(member_variable)); variable_info->members.append(member_variable.release_nonnull());
}); });
return variable_info; return variable_info;

View file

@ -99,7 +99,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);
NonnullOwnPtr<VariableInfo> create_variable_info(const Dwarf::DIE& variable_die, const PtraceRegisters&) const; OwnPtr<VariableInfo> create_variable_info(const Dwarf::DIE& variable_die, const PtraceRegisters&) const;
NonnullRefPtr<const ELF::Loader> m_elf; NonnullRefPtr<const ELF::Loader> m_elf;
NonnullRefPtr<Dwarf::DwarfInfo> m_dwarf_info; NonnullRefPtr<Dwarf::DwarfInfo> m_dwarf_info;

View file

@ -38,6 +38,7 @@ struct [[gnu::packed]] CompilationUnitHeader
enum class EntryTag : u32 { enum class EntryTag : u32 {
None = 0, None = 0,
FormalParameter = 0x5,
LexicalBlock = 0xb, LexicalBlock = 0xb,
Member = 0xd, Member = 0xd,
SubProgram = 0x2e, SubProgram = 0x2e,