1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 17:07:34 +00:00

HackStudio: Properly support Debugger's new source root concept

HackStudio's debugger instance has its source root property updated
when switching projects, and breakpoints will properly canonicalize
their file paths as the Debugger now expects.
This commit is contained in:
FalseHonesty 2021-04-11 22:03:42 -04:00 committed by Andreas Kling
parent 0f98569617
commit c778164f64
4 changed files with 14 additions and 10 deletions

View file

@ -70,9 +70,9 @@ void Debugger::on_breakpoint_change(const String& file, size_t line, BreakpointC
auto position = create_source_position(file, line);
if (change_type == BreakpointChange::Added) {
Debugger::the().m_breakpoints.append(position);
m_breakpoints.append(position);
} else {
Debugger::the().m_breakpoints.remove_all_matching([&](Debug::DebugInfo::SourcePosition val) { return val == position; });
m_breakpoints.remove_all_matching([&](const Debug::DebugInfo::SourcePosition& val) { return val == position; });
}
auto session = Debugger::the().session();
@ -99,9 +99,9 @@ void Debugger::on_breakpoint_change(const String& file, size_t line, BreakpointC
Debug::DebugInfo::SourcePosition Debugger::create_source_position(const String& file, size_t line)
{
if (!file.starts_with('/') && !file.starts_with("./"))
return { String::formatted("./{}", file), line + 1 };
return { file, line + 1 };
if (file.starts_with("/"))
return { file, line + 1 };
return { LexicalPath::canonicalized_path(String::formatted("{}/{}", m_source_root, file)), line + 1 };
}
int Debugger::start_static()

View file

@ -28,6 +28,7 @@
#include "BreakpointCallback.h"
#include <AK/Function.h>
#include <AK/LexicalPath.h>
#include <AK/Vector.h>
#include <LibDebug/DebugSession.h>
#include <LibThread/Lock.h>
@ -52,9 +53,10 @@ public:
static bool is_initialized();
static void on_breakpoint_change(const String& file, size_t line, BreakpointChange change_type);
void on_breakpoint_change(const String& file, size_t line, BreakpointChange change_type);
void set_executable_path(const String& path) { m_executable_path = path; }
void set_source_root(const String& source_root) { m_source_root = source_root; }
Debug::DebugSession* session() { return m_debug_session.ptr(); }
@ -108,7 +110,7 @@ private:
Function<void()> on_continue_callback,
Function<void()> on_exit_callback);
static Debug::DebugInfo::SourcePosition create_source_position(const String& file, size_t line);
Debug::DebugInfo::SourcePosition create_source_position(const String& file, size_t line);
void start();
int debugger_loop();

View file

@ -272,10 +272,10 @@ void Editor::mousedown_event(GUI::MouseEvent& event)
if (event.button() == GUI::MouseButton::Left && event.position().x() < ruler_line_rect.width()) {
if (!breakpoint_lines().contains_slow(text_position.line())) {
breakpoint_lines().append(text_position.line());
Debugger::on_breakpoint_change(wrapper().filename_label().text(), text_position.line(), BreakpointChange::Added);
Debugger::the().on_breakpoint_change(wrapper().filename_label().text(), text_position.line(), BreakpointChange::Added);
} else {
breakpoint_lines().remove_first_matching([&](size_t line) { return line == text_position.line(); });
Debugger::on_breakpoint_change(wrapper().filename_label().text(), text_position.line(), BreakpointChange::Removed);
Debugger::the().on_breakpoint_change(wrapper().filename_label().text(), text_position.line(), BreakpointChange::Removed);
}
}

View file

@ -198,7 +198,9 @@ void HackStudioWidget::open_project(const String& root_path)
m_project_tree_view->update();
}
if (Debugger::is_initialized()) {
Debugger::the().reset_breakpoints();
auto& debugger = Debugger::the();
debugger.reset_breakpoints();
debugger.set_source_root(m_project->root_path());
}
}