Просмотр исходного кода

HackStudio: Use ProcessInspector instead of DebugSession where possible

Itamar 3 лет назад
Родитель
Сommit
94d68583fb

+ 5 - 5
Userland/DevTools/HackStudio/Debugger/BacktraceModel.cpp

@@ -10,9 +10,9 @@
 
 
 namespace HackStudio {
 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
 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));
     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_ebp = regs.bp();
     FlatPtr current_instruction = regs.ip();
     FlatPtr current_instruction = regs.ip();
     Vector<BacktraceModel::FrameInfo> frames;
     Vector<BacktraceModel::FrameInfo> frames;
     do {
     do {
-        auto lib = debug_session.library_at(regs.ip());
+        auto lib = inspector.library_at(regs.ip());
         if (!lib)
         if (!lib)
             continue;
             continue;
         String name = lib->debug_info->name_of_containing_function(current_instruction - lib->base_address);
         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 });
         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());
         VERIFY(frame_info.has_value());
         current_instruction = frame_info.value().return_address;
         current_instruction = frame_info.value().return_address;
         current_ebp = frame_info.value().next_ebp;
         current_ebp = frame_info.value().next_ebp;

+ 3 - 2
Userland/DevTools/HackStudio/Debugger/BacktraceModel.h

@@ -7,6 +7,7 @@
 #pragma once
 #pragma once
 
 
 #include <AK/Vector.h>
 #include <AK/Vector.h>
+#include <LibDebug/ProcessInspector.h>
 #include <LibGUI/ListView.h>
 #include <LibGUI/ListView.h>
 #include <LibGUI/Model.h>
 #include <LibGUI/Model.h>
 #include <sys/arch/i386/regs.h>
 #include <sys/arch/i386/regs.h>
@@ -21,7 +22,7 @@ namespace HackStudio {
 
 
 class BacktraceModel final : public GUI::Model {
 class BacktraceModel final : public GUI::Model {
 public:
 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 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; }
     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;
     Vector<FrameInfo> m_frames;
 };
 };

+ 2 - 3
Userland/DevTools/HackStudio/Debugger/DebugInfoWidget.cpp

@@ -13,7 +13,6 @@
 #include <LibGUI/Action.h>
 #include <LibGUI/Action.h>
 #include <LibGUI/BoxLayout.h>
 #include <LibGUI/BoxLayout.h>
 #include <LibGUI/InputBox.h>
 #include <LibGUI/InputBox.h>
-#include <LibGUI/Layout.h>
 #include <LibGUI/ListView.h>
 #include <LibGUI/ListView.h>
 #include <LibGUI/Menu.h>
 #include <LibGUI/Menu.h>
 #include <LibGUI/Model.h>
 #include <LibGUI/Model.h>
@@ -150,10 +149,10 @@ NonnullRefPtr<GUI::Widget> DebugInfoWidget::build_registers_tab()
     return registers_widget;
     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_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()) {
     if (m_registers_view->model()) {
         auto& previous_registers = static_cast<RegistersModel*>(m_registers_view->model())->raw_registers();
         auto& previous_registers = static_cast<RegistersModel*>(m_registers_view->model())->raw_registers();
         m_registers_view->set_model(RegistersModel::create(regs, previous_registers));
         m_registers_view->set_model(RegistersModel::create(regs, previous_registers));

+ 1 - 1
Userland/DevTools/HackStudio/Debugger/DebugInfoWidget.h

@@ -26,7 +26,7 @@ class DebugInfoWidget final : public GUI::Widget {
 public:
 public:
     virtual ~DebugInfoWidget() override { }
     virtual ~DebugInfoWidget() override { }
 
 
-    void update_state(const Debug::DebugSession&, const PtraceRegisters&);
+    void update_state(Debug::ProcessInspector const&, PtraceRegisters const&);
     void program_stopped();
     void program_stopped();
     void set_debug_actions_enabled(bool enabled);
     void set_debug_actions_enabled(bool enabled);
 
 

+ 9 - 4
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
 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]);
         return create_index(row, column, &m_variables[row]);
+    }
     auto* parent = static_cast<const Debug::DebugInfo::VariableInfo*>(parent_index.internal_data());
     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];
     auto* child = &parent->members[row];
     return create_index(row, column, child);
     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)
     if (!lib)
         return nullptr;
         return nullptr;
     auto variables = lib->debug_info->get_variables_in_current_scope(regs);
     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));
 }
 }
 
 
 }
 }

+ 5 - 2
Userland/DevTools/HackStudio/Debugger/VariablesModel.h

@@ -16,7 +16,7 @@ namespace HackStudio {
 
 
 class VariablesModel final : public GUI::Model {
 class VariablesModel final : public GUI::Model {
 public:
 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*);
     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::Variant data(const GUI::ModelIndex& index, GUI::ModelRole role) const override;
     virtual GUI::ModelIndex parent_index(const GUI::ModelIndex&) 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;
     virtual GUI::ModelIndex index(int row, int column = 0, const GUI::ModelIndex& = GUI::ModelIndex()) const override;
+    Debug::ProcessInspector& inspector() { return m_inspector; }
 
 
 private:
 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_variables(move(variables))
         , m_regs(regs)
         , 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());
         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;
     PtraceRegisters m_regs;
 
 
     GUI::Icon m_variable_icon;
     GUI::Icon m_variable_icon;
+    Debug::ProcessInspector& m_inspector;
 };
 };
 
 
 }
 }

+ 3 - 3
Userland/Libraries/LibDebug/StackFrameUtils.cpp

@@ -8,10 +8,10 @@
 
 
 namespace Debug::StackFrameUtils {
 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())
     if (!return_address.has_value() || !next_ebp.has_value())
         return {};
         return {};
 
 

+ 1 - 1
Userland/Libraries/LibDebug/StackFrameUtils.h

@@ -18,6 +18,6 @@ struct StackFrameInfo {
     FlatPtr next_ebp;
     FlatPtr next_ebp;
 };
 };
 
 
-Optional<StackFrameInfo> get_info(DebugSession const&, FlatPtr current_ebp);
+Optional<StackFrameInfo> get_info(ProcessInspector const&, FlatPtr current_ebp);
 
 
 }
 }