diff options
8 files changed, 29 insertions, 21 deletions
diff --git a/Userland/DevTools/HackStudio/Debugger/BacktraceModel.cpp b/Userland/DevTools/HackStudio/Debugger/BacktraceModel.cpp index 6191a81fa4..0440fc028e 100644 --- a/Userland/DevTools/HackStudio/Debugger/BacktraceModel.cpp +++ b/Userland/DevTools/HackStudio/Debugger/BacktraceModel.cpp @@ -10,9 +10,9 @@ namespace HackStudio { -NonnullRefPtr<BacktraceModel> BacktraceModel::create(const Debug::DebugSession& debug_session, const PtraceRegisters& regs) +NonnullRefPtr<BacktraceModel> BacktraceModel::create(Debug::ProcessInspector const& inspector, const PtraceRegisters& regs) { - return adopt_ref(*new BacktraceModel(create_backtrace(debug_session, regs))); + return adopt_ref(*new BacktraceModel(create_backtrace(inspector, regs))); } GUI::Variant BacktraceModel::data(const GUI::ModelIndex& index, GUI::ModelRole role) const @@ -31,13 +31,13 @@ GUI::ModelIndex BacktraceModel::index(int row, int column, const GUI::ModelIndex return create_index(row, column, &m_frames.at(row)); } -Vector<BacktraceModel::FrameInfo> BacktraceModel::create_backtrace(const Debug::DebugSession& debug_session, const PtraceRegisters& regs) +Vector<BacktraceModel::FrameInfo> BacktraceModel::create_backtrace(Debug::ProcessInspector const& inspector, PtraceRegisters const& regs) { FlatPtr current_ebp = regs.bp(); FlatPtr current_instruction = regs.ip(); Vector<BacktraceModel::FrameInfo> frames; do { - auto lib = debug_session.library_at(regs.ip()); + auto lib = inspector.library_at(regs.ip()); if (!lib) continue; String name = lib->debug_info->name_of_containing_function(current_instruction - lib->base_address); @@ -47,7 +47,7 @@ Vector<BacktraceModel::FrameInfo> BacktraceModel::create_backtrace(const Debug:: } frames.append({ name, current_instruction, current_ebp }); - auto frame_info = Debug::StackFrameUtils::get_info(*Debugger::the().session(), current_ebp); + auto frame_info = Debug::StackFrameUtils::get_info(inspector, current_ebp); VERIFY(frame_info.has_value()); current_instruction = frame_info.value().return_address; current_ebp = frame_info.value().next_ebp; diff --git a/Userland/DevTools/HackStudio/Debugger/BacktraceModel.h b/Userland/DevTools/HackStudio/Debugger/BacktraceModel.h index cc4512aaee..a335b3c58e 100644 --- a/Userland/DevTools/HackStudio/Debugger/BacktraceModel.h +++ b/Userland/DevTools/HackStudio/Debugger/BacktraceModel.h @@ -7,6 +7,7 @@ #pragma once #include <AK/Vector.h> +#include <LibDebug/ProcessInspector.h> #include <LibGUI/ListView.h> #include <LibGUI/Model.h> #include <sys/arch/i386/regs.h> @@ -21,7 +22,7 @@ namespace HackStudio { class BacktraceModel final : public GUI::Model { public: - static NonnullRefPtr<BacktraceModel> create(const Debug::DebugSession&, const PtraceRegisters& regs); + static NonnullRefPtr<BacktraceModel> create(Debug::ProcessInspector const&, PtraceRegisters const& regs); virtual int row_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override { return m_frames.size(); } virtual int column_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override { return 1; } @@ -49,7 +50,7 @@ private: { } - static Vector<FrameInfo> create_backtrace(const Debug::DebugSession&, const PtraceRegisters&); + static Vector<FrameInfo> create_backtrace(Debug::ProcessInspector const&, PtraceRegisters const&); Vector<FrameInfo> m_frames; }; diff --git a/Userland/DevTools/HackStudio/Debugger/DebugInfoWidget.cpp b/Userland/DevTools/HackStudio/Debugger/DebugInfoWidget.cpp index 1095c1035e..4c13ff71b6 100644 --- a/Userland/DevTools/HackStudio/Debugger/DebugInfoWidget.cpp +++ b/Userland/DevTools/HackStudio/Debugger/DebugInfoWidget.cpp @@ -13,7 +13,6 @@ #include <LibGUI/Action.h> #include <LibGUI/BoxLayout.h> #include <LibGUI/InputBox.h> -#include <LibGUI/Layout.h> #include <LibGUI/ListView.h> #include <LibGUI/Menu.h> #include <LibGUI/Model.h> @@ -150,10 +149,10 @@ NonnullRefPtr<GUI::Widget> DebugInfoWidget::build_registers_tab() return registers_widget; } -void DebugInfoWidget::update_state(const Debug::DebugSession& debug_session, const PtraceRegisters& regs) +void DebugInfoWidget::update_state(const Debug::ProcessInspector& inspector, const PtraceRegisters& regs) { m_variables_view->set_model(VariablesModel::create(regs)); - m_backtrace_view->set_model(BacktraceModel::create(debug_session, regs)); + m_backtrace_view->set_model(BacktraceModel::create(inspector, regs)); if (m_registers_view->model()) { auto& previous_registers = static_cast<RegistersModel*>(m_registers_view->model())->raw_registers(); m_registers_view->set_model(RegistersModel::create(regs, previous_registers)); diff --git a/Userland/DevTools/HackStudio/Debugger/DebugInfoWidget.h b/Userland/DevTools/HackStudio/Debugger/DebugInfoWidget.h index 2fc66fac16..0e3f06b628 100644 --- a/Userland/DevTools/HackStudio/Debugger/DebugInfoWidget.h +++ b/Userland/DevTools/HackStudio/Debugger/DebugInfoWidget.h @@ -26,7 +26,7 @@ class DebugInfoWidget final : public GUI::Widget { public: virtual ~DebugInfoWidget() override { } - void update_state(const Debug::DebugSession&, const PtraceRegisters&); + void update_state(Debug::ProcessInspector const&, PtraceRegisters const&); void program_stopped(); void set_debug_actions_enabled(bool enabled); diff --git a/Userland/DevTools/HackStudio/Debugger/VariablesModel.cpp b/Userland/DevTools/HackStudio/Debugger/VariablesModel.cpp index 06f00c1034..7cbc3d5de8 100644 --- a/Userland/DevTools/HackStudio/Debugger/VariablesModel.cpp +++ b/Userland/DevTools/HackStudio/Debugger/VariablesModel.cpp @@ -12,9 +12,14 @@ namespace HackStudio { GUI::ModelIndex VariablesModel::index(int row, int column, const GUI::ModelIndex& parent_index) const { - if (!parent_index.is_valid()) + if (!parent_index.is_valid()) { + if (static_cast<size_t>(row) >= m_variables.size()) + return {}; return create_index(row, column, &m_variables[row]); + } auto* parent = static_cast<const Debug::DebugInfo::VariableInfo*>(parent_index.internal_data()); + if (static_cast<size_t>(row) >= parent->members.size()) + return {}; auto* child = &parent->members[row]; return create_index(row, column, child); } @@ -158,13 +163,13 @@ GUI::Variant VariablesModel::data(const GUI::ModelIndex& index, GUI::ModelRole r } } -RefPtr<VariablesModel> VariablesModel::create(const PtraceRegisters& regs) +RefPtr<VariablesModel> VariablesModel::create(Debug::ProcessInspector& inspector, PtraceRegisters const& regs) { - auto lib = Debugger::the().session()->library_at(regs.ip()); + auto lib = inspector.library_at(regs.ip()); if (!lib) return nullptr; auto variables = lib->debug_info->get_variables_in_current_scope(regs); - return adopt_ref(*new VariablesModel(move(variables), regs)); + return adopt_ref(*new VariablesModel(inspector, move(variables), regs)); } } diff --git a/Userland/DevTools/HackStudio/Debugger/VariablesModel.h b/Userland/DevTools/HackStudio/Debugger/VariablesModel.h index b088dfee3c..a46a7641ed 100644 --- a/Userland/DevTools/HackStudio/Debugger/VariablesModel.h +++ b/Userland/DevTools/HackStudio/Debugger/VariablesModel.h @@ -16,7 +16,7 @@ namespace HackStudio { class VariablesModel final : public GUI::Model { public: - static RefPtr<VariablesModel> create(const PtraceRegisters& regs); + static RefPtr<VariablesModel> create(Debug::ProcessInspector&, PtraceRegisters const& regs); void set_variable_value(const GUI::ModelIndex&, StringView, GUI::Window*); @@ -25,11 +25,13 @@ public: virtual GUI::Variant data(const GUI::ModelIndex& index, GUI::ModelRole role) const override; virtual GUI::ModelIndex parent_index(const GUI::ModelIndex&) const override; virtual GUI::ModelIndex index(int row, int column = 0, const GUI::ModelIndex& = GUI::ModelIndex()) const override; + Debug::ProcessInspector& inspector() { return m_inspector; } private: - explicit VariablesModel(NonnullOwnPtrVector<Debug::DebugInfo::VariableInfo>&& variables, const PtraceRegisters& regs) + explicit VariablesModel(Debug::ProcessInspector& inspector, NonnullOwnPtrVector<Debug::DebugInfo::VariableInfo>&& variables, const PtraceRegisters& regs) : m_variables(move(variables)) , m_regs(regs) + , m_inspector(inspector) { m_variable_icon.set_bitmap_for_size(16, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/inspector-object.png").release_value_but_fixme_should_propagate_errors()); } @@ -37,6 +39,7 @@ private: PtraceRegisters m_regs; GUI::Icon m_variable_icon; + Debug::ProcessInspector& m_inspector; }; } diff --git a/Userland/Libraries/LibDebug/StackFrameUtils.cpp b/Userland/Libraries/LibDebug/StackFrameUtils.cpp index 379de82ec8..e5cccff5ab 100644 --- a/Userland/Libraries/LibDebug/StackFrameUtils.cpp +++ b/Userland/Libraries/LibDebug/StackFrameUtils.cpp @@ -8,10 +8,10 @@ namespace Debug::StackFrameUtils { -Optional<StackFrameInfo> get_info(DebugSession const& session, FlatPtr current_ebp) +Optional<StackFrameInfo> get_info(ProcessInspector const& inspector, FlatPtr current_ebp) { - auto return_address = session.peek(reinterpret_cast<u32*>(current_ebp + sizeof(FlatPtr))); - auto next_ebp = session.peek(reinterpret_cast<u32*>(current_ebp)); + auto return_address = inspector.peek(reinterpret_cast<u32*>(current_ebp + sizeof(FlatPtr))); + auto next_ebp = inspector.peek(reinterpret_cast<u32*>(current_ebp)); if (!return_address.has_value() || !next_ebp.has_value()) return {}; diff --git a/Userland/Libraries/LibDebug/StackFrameUtils.h b/Userland/Libraries/LibDebug/StackFrameUtils.h index 3c4ab0804a..2247518780 100644 --- a/Userland/Libraries/LibDebug/StackFrameUtils.h +++ b/Userland/Libraries/LibDebug/StackFrameUtils.h @@ -18,6 +18,6 @@ struct StackFrameInfo { FlatPtr next_ebp; }; -Optional<StackFrameInfo> get_info(DebugSession const&, FlatPtr current_ebp); +Optional<StackFrameInfo> get_info(ProcessInspector const&, FlatPtr current_ebp); } |