From 14ee090f25cec713f02dd9a027b461982a2a5a51 Mon Sep 17 00:00:00 2001 From: Itamar Date: Fri, 8 May 2020 10:59:28 +0300 Subject: HackStudio: Support variable inspection in nested scopes --- DevTools/HackStudio/DebugInfoWidget.cpp | 7 ++++++- Libraries/LibDebug/DebugInfo.cpp | 24 ++++-------------------- Libraries/LibDebug/DebugInfo.h | 1 - 3 files changed, 10 insertions(+), 22 deletions(-) diff --git a/DevTools/HackStudio/DebugInfoWidget.cpp b/DevTools/HackStudio/DebugInfoWidget.cpp index c84bd8325e..6e73b1a0ec 100644 --- a/DevTools/HackStudio/DebugInfoWidget.cpp +++ b/DevTools/HackStudio/DebugInfoWidget.cpp @@ -90,7 +90,7 @@ String variable_value_as_string(const DebugInfo::VariableInfo& variable) return String::format("'%c' (%d)", static_cast(value.value()), static_cast(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({}); +} diff --git a/Libraries/LibDebug/DebugInfo.cpp b/Libraries/LibDebug/DebugInfo.cpp index 14ee1cf0e4..a541e6de74 100644 --- a/Libraries/LibDebug/DebugInfo.cpp +++ b/Libraries/LibDebug/DebugInfo.cpp @@ -140,34 +140,18 @@ Optional DebugInfo::get_instruction_from_source(const String& file, size_t NonnullOwnPtrVector DebugInfo::get_variables_in_current_scope(const PtraceRegisters& regs) const { - auto scope = get_scope(regs.eip); - if (!scope.has_value()) - return {}; - NonnullOwnPtrVector variables; - for (const auto& die_entry : scope.value().dies_of_variables) { - variables.append(create_variable_info(die_entry, regs)); - } - return variables; -} - -Optional DebugInfo::get_scope(u32 instruction_pointer) const -{ - Optional 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::create_variable_info(const Dwarf::DIE& variable_die, const PtraceRegisters& regs) const diff --git a/Libraries/LibDebug/DebugInfo.h b/Libraries/LibDebug/DebugInfo.h index 06289c76e7..af928b6a97 100644 --- a/Libraries/LibDebug/DebugInfo.h +++ b/Libraries/LibDebug/DebugInfo.h @@ -97,7 +97,6 @@ private: void prepare_variable_scopes(); void prepare_lines(); void parse_scopes_impl(const Dwarf::DIE& die); - Optional get_scope(u32 instruction_pointer) const; NonnullOwnPtr create_variable_info(const Dwarf::DIE& variable_die, const PtraceRegisters&) const; NonnullRefPtr m_elf; -- cgit v1.2.3