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

HackStudio: Support variable inspection in nested scopes

This commit is contained in:
Itamar 2020-05-08 10:59:28 +03:00 committed by Andreas Kling
parent f0cbaf453c
commit 14ee090f25
3 changed files with 10 additions and 22 deletions

View file

@ -90,7 +90,7 @@ String variable_value_as_string(const DebugInfo::VariableInfo& variable)
return String::format("'%c' (%d)", static_cast<char>(value.value()), static_cast<char>(value.value()));
}
return String::format("address: %08x, ", variable_address);
return String::format("type: %s @ %08x, ", variable.type.characters(), variable_address);
}
GUI::Variant DebugInfoModel::data(const GUI::ModelIndex& index, Role role) const
@ -130,3 +130,8 @@ void DebugInfoWidget::update_variables(const PtraceRegisters& regs)
auto model = create_model(regs);
m_info_view->set_model(model);
}
void DebugInfoWidget::program_stopped()
{
m_info_view->set_model({});
}

View file

@ -140,34 +140,18 @@ Optional<u32> DebugInfo::get_instruction_from_source(const String& file, size_t
NonnullOwnPtrVector<DebugInfo::VariableInfo> DebugInfo::get_variables_in_current_scope(const PtraceRegisters& regs) const
{
auto scope = get_scope(regs.eip);
if (!scope.has_value())
return {};
NonnullOwnPtrVector<DebugInfo::VariableInfo> variables;
for (const auto& die_entry : scope.value().dies_of_variables) {
variables.append(create_variable_info(die_entry, regs));
}
return variables;
}
Optional<DebugInfo::VariablesScope> DebugInfo::get_scope(u32 instruction_pointer) const
{
Optional<VariablesScope> best_matching_scope;
// TODO: We can store the scopes in a better data strucutre
for (const auto& scope : m_scopes) {
if (instruction_pointer < scope.address_low || instruction_pointer >= scope.address_high)
if (regs.eip < scope.address_low || regs.eip >= scope.address_high)
continue;
if (!best_matching_scope.has_value()) {
best_matching_scope = scope;
} else if (scope.address_low > best_matching_scope.value().address_low || scope.address_high < best_matching_scope.value().address_high) {
best_matching_scope = scope;
for (const auto& die_entry : scope.dies_of_variables) {
variables.append(create_variable_info(die_entry, regs));
}
}
return best_matching_scope;
return variables;
}
NonnullOwnPtr<DebugInfo::VariableInfo> DebugInfo::create_variable_info(const Dwarf::DIE& variable_die, const PtraceRegisters& regs) const

View file

@ -97,7 +97,6 @@ private:
void prepare_variable_scopes();
void prepare_lines();
void parse_scopes_impl(const Dwarf::DIE& die);
Optional<VariablesScope> get_scope(u32 instruction_pointer) const;
NonnullOwnPtr<VariableInfo> create_variable_info(const Dwarf::DIE& variable_die, const PtraceRegisters&) const;
NonnullRefPtr<const ELF::Loader> m_elf;