From c778164f6457ef7a14f0331b80d33b0b6908f170 Mon Sep 17 00:00:00 2001 From: FalseHonesty Date: Sun, 11 Apr 2021 22:03:42 -0400 Subject: [PATCH] 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. --- Userland/DevTools/HackStudio/Debugger/Debugger.cpp | 10 +++++----- Userland/DevTools/HackStudio/Debugger/Debugger.h | 6 ++++-- Userland/DevTools/HackStudio/Editor.cpp | 4 ++-- Userland/DevTools/HackStudio/HackStudioWidget.cpp | 4 +++- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/Userland/DevTools/HackStudio/Debugger/Debugger.cpp b/Userland/DevTools/HackStudio/Debugger/Debugger.cpp index 55bc4faef3..7f8ef8eada 100644 --- a/Userland/DevTools/HackStudio/Debugger/Debugger.cpp +++ b/Userland/DevTools/HackStudio/Debugger/Debugger.cpp @@ -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() diff --git a/Userland/DevTools/HackStudio/Debugger/Debugger.h b/Userland/DevTools/HackStudio/Debugger/Debugger.h index 0d2371f86e..1228a1ac0e 100644 --- a/Userland/DevTools/HackStudio/Debugger/Debugger.h +++ b/Userland/DevTools/HackStudio/Debugger/Debugger.h @@ -28,6 +28,7 @@ #include "BreakpointCallback.h" #include +#include #include #include #include @@ -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 on_continue_callback, Function 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(); diff --git a/Userland/DevTools/HackStudio/Editor.cpp b/Userland/DevTools/HackStudio/Editor.cpp index e4b1c8bf74..6cdbca9cfa 100644 --- a/Userland/DevTools/HackStudio/Editor.cpp +++ b/Userland/DevTools/HackStudio/Editor.cpp @@ -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); } } diff --git a/Userland/DevTools/HackStudio/HackStudioWidget.cpp b/Userland/DevTools/HackStudio/HackStudioWidget.cpp index 9529edb9d8..5d64f8a5d8 100644 --- a/Userland/DevTools/HackStudio/HackStudioWidget.cpp +++ b/Userland/DevTools/HackStudio/HackStudioWidget.cpp @@ -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()); } }