HackStudio: Reorganize debugger-related files

The debugger's files are now placed under HackStudio/Debugger
This commit is contained in:
Itamar 2020-05-08 13:32:55 +03:00 committed by Andreas Kling
parent ce36071447
commit b9f0f402f4
Notes: sideshowbarker 2024-07-19 06:48:11 +09:00
11 changed files with 127 additions and 62 deletions

View File

@ -0,0 +1,52 @@
/*
* Copyright (c) 2020, Itamar S. <itamar8910@gmail.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "DebugInfoWidget.h"
#include "Debugger.h"
#include "VariablesModel.h"
#include <AK/StringBuilder.h>
#include <LibGUI/BoxLayout.h>
#include <LibGUI/Model.h>
#include <LibGUI/TableView.h>
#include <LibGUI/TreeView.h>
DebugInfoWidget::DebugInfoWidget()
{
set_layout<GUI::HorizontalBoxLayout>();
m_info_view = add<GUI::TreeView>();
m_backtrace_view = add<GUI::TableView>();
}
void DebugInfoWidget::update_state(const PtraceRegisters& regs)
{
auto model = VariablesModel::create(regs);
m_info_view->set_model(model);
}
void DebugInfoWidget::program_stopped()
{
m_info_view->set_model({});
}

View File

@ -0,0 +1,48 @@
/*
* Copyright (c) 2020, Itamar S. <itamar8910@gmail.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include "Debugger.h"
#include <AK/NonnullOwnPtr.h>
#include <LibGUI/Model.h>
#include <LibGUI/Widget.h>
#include <sys/arch/i386/regs.h>
class DebugInfoWidget final : public GUI::Widget {
C_OBJECT(DebugInfoWidget)
public:
virtual ~DebugInfoWidget() override {}
void update_state(const PtraceRegisters&);
void program_stopped();
private:
explicit DebugInfoWidget();
RefPtr<GUI::TreeView> m_info_view;
RefPtr<GUI::TableView> m_backtrace_view;
};

View File

@ -24,14 +24,9 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "DebugInfoWidget.h"
#include "Debugger.h"
#include <AK/StringBuilder.h>
#include <LibGUI/BoxLayout.h>
#include <LibGUI/Model.h>
#include <LibGUI/TreeView.h>
#include "VariablesModel.h"
GUI::ModelIndex DebugInfoModel::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())
return create_index(row, column, &m_variables[row]);
@ -40,7 +35,7 @@ GUI::ModelIndex DebugInfoModel::index(int row, int column, const GUI::ModelIndex
return create_index(row, column, child);
}
GUI::ModelIndex DebugInfoModel::parent_index(const GUI::ModelIndex& index) const
GUI::ModelIndex VariablesModel::parent_index(const GUI::ModelIndex& index) const
{
if (!index.is_valid())
return {};
@ -63,7 +58,7 @@ GUI::ModelIndex DebugInfoModel::parent_index(const GUI::ModelIndex& index) const
ASSERT_NOT_REACHED();
}
int DebugInfoModel::row_count(const GUI::ModelIndex& index) const
int VariablesModel::row_count(const GUI::ModelIndex& index) const
{
if (!index.is_valid())
return m_variables.size();
@ -93,7 +88,7 @@ String variable_value_as_string(const DebugInfo::VariableInfo& variable)
return String::format("type: %s @ %08x, ", variable.type.characters(), variable_address);
}
GUI::Variant DebugInfoModel::data(const GUI::ModelIndex& index, Role role) const
GUI::Variant VariablesModel::data(const GUI::ModelIndex& index, Role role) const
{
auto* variable = static_cast<const DebugInfo::VariableInfo*>(index.internal_data());
switch (role) {
@ -108,30 +103,13 @@ GUI::Variant DebugInfoModel::data(const GUI::ModelIndex& index, Role role) const
}
}
void DebugInfoModel::update()
void VariablesModel::update()
{
did_update();
}
static RefPtr<DebugInfoModel> create_model(const PtraceRegisters& regs)
RefPtr<VariablesModel> VariablesModel::create(const PtraceRegisters& regs)
{
auto variables = Debugger::the().session()->debug_info().get_variables_in_current_scope(regs);
return adopt(*new DebugInfoModel(move(variables), regs));
}
DebugInfoWidget::DebugInfoWidget()
{
set_layout<GUI::VerticalBoxLayout>();
m_info_view = add<GUI::TreeView>();
}
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({});
return adopt(*new VariablesModel(move(variables), regs));
}

View File

@ -25,21 +25,15 @@
*/
#pragma once
#include "Debugger.h"
#include <AK/NonnullOwnPtr.h>
#include <LibGUI/Model.h>
#include <LibGUI/Widget.h>
#include <LibGUI/TreeView.h>
#include <sys/arch/i386/regs.h>
class DebugInfoModel final : public GUI::Model {
class VariablesModel final : public GUI::Model {
public:
explicit DebugInfoModel(NonnullOwnPtrVector<DebugInfo::VariableInfo>&& variables, const PtraceRegisters& regs)
: m_variables(move(variables))
, m_regs(regs)
{
m_variable_icon.set_bitmap_for_size(16, Gfx::Bitmap::load_from_file("/res/icons/16x16/inspector-object.png"));
}
static RefPtr<VariablesModel> create(const PtraceRegisters& regs);
virtual int row_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override;
virtual int column_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override { return 1; }
@ -49,22 +43,14 @@ public:
virtual GUI::ModelIndex index(int row, int column = 0, const GUI::ModelIndex& = GUI::ModelIndex()) const override;
private:
explicit VariablesModel(NonnullOwnPtrVector<DebugInfo::VariableInfo>&& variables, const PtraceRegisters& regs)
: m_variables(move(variables))
, m_regs(regs)
{
m_variable_icon.set_bitmap_for_size(16, Gfx::Bitmap::load_from_file("/res/icons/16x16/inspector-object.png"));
}
NonnullOwnPtrVector<DebugInfo::VariableInfo> m_variables;
PtraceRegisters m_regs;
GUI::Icon m_variable_icon;
};
class DebugInfoWidget final : public GUI::Widget {
C_OBJECT(DebugInfoWidget)
public:
virtual ~DebugInfoWidget() override {}
void update_variables(const PtraceRegisters&);
void program_stopped();
private:
explicit DebugInfoWidget();
RefPtr<GUI::TreeView> m_info_view;
};

View File

@ -26,7 +26,7 @@
#pragma once
#include "BreakpointCallback.h"
#include "Debugger/BreakpointCallback.h"
#include <AK/Optional.h>
#include <LibGUI/TextEditor.h>
#include <LibWeb/Forward.h>

View File

@ -26,7 +26,7 @@
#pragma once
#include "BreakpointCallback.h"
#include "Debugger/BreakpointCallback.h"
#include <AK/Function.h>
#include <AK/Vector.h>
#include <LibGUI/Widget.h>

View File

@ -6,7 +6,6 @@ OBJS = \
ProcessStateWidget.o \
FormEditorWidget.o \
FormWidget.o \
DebugInfoWidget.o \
Editor.o \
EditorWrapper.o \
Locator.o \
@ -14,8 +13,10 @@ OBJS = \
CursorTool.o \
WidgetTool.o \
WidgetTreeModel.o \
Debugger.o \
main.o
main.o \
Debugger/DebugInfoWidget.o \
Debugger/Debugger.o \
Debugger/VariablesModel.o
PROGRAM = HackStudio

View File

@ -25,8 +25,8 @@
*/
#include "CursorTool.h"
#include "DebugInfoWidget.h"
#include "Debugger.h"
#include "Debugger/DebugInfoWidget.h"
#include "Debugger/Debugger.h"
#include "Editor.h"
#include "EditorWrapper.h"
#include "FindInFilesWidget.h"
@ -48,9 +48,9 @@
#include <LibGUI/Application.h>
#include <LibGUI/BoxLayout.h>
#include <LibGUI/Button.h>
#include <LibGUI/INISyntaxHighlighter.h>
#include <LibGUI/CppSyntaxHighlighter.h>
#include <LibGUI/FilePicker.h>
#include <LibGUI/INISyntaxHighlighter.h>
#include <LibGUI/InputBox.h>
#include <LibGUI/JSSyntaxHighlighter.h>
#include <LibGUI/Label.h>
@ -615,7 +615,7 @@ int main(int argc, char** argv)
}
current_editor_in_execution = get_editor_of_file(source_position.value().file_path);
current_editor_in_execution->editor().set_execution_position(source_position.value().line_number - 1);
debug_info_widget.update_variables(regs);
debug_info_widget.update_state(regs);
continue_action->set_enabled(true);
single_step_action->set_enabled(true);
reveal_action_tab(debug_info_widget);