mirror of
https://github.com/RGBCube/serenity
synced 2025-05-16 23:15:07 +00:00
HackStudio: Use ProcessInspector instead of DebugSession where possible
This commit is contained in:
parent
7950f5cb51
commit
94d68583fb
8 changed files with 29 additions and 21 deletions
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -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 {};
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue