From af616a407627d87a787ae78cc36c58ac4ed3ccad Mon Sep 17 00:00:00 2001 From: hachem Date: Fri, 28 Aug 2026 15:54:34 +0200 Subject: add: process execution --- src/ui/ui.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ src/ui/ui.h | 6 ++++++ 2 files changed, 55 insertions(+) (limited to 'src/ui') diff --git a/src/ui/ui.cpp b/src/ui/ui.cpp index bc7c910..8ba1155 100644 --- a/src/ui/ui.cpp +++ b/src/ui/ui.cpp @@ -11,8 +11,10 @@ #include #include +#include #include #include +#include namespace Hsdbg { @@ -137,6 +139,48 @@ namespace Hsdbg } } + auto Ui::follow_stop(Debugger& debugger) -> void + { + if (!debugger.is_stopped()) + { + if (debugger.is_running()) + m_source_view.set_highlighted_line(0); + + return; + } + + if (debugger.stop_count() == m_followed_stop) + return; + + m_followed_stop = debugger.stop_count(); + + const std::span stack = debugger.call_stack(); + + // the innermost frames are often runtime internals with no source, and + // pointing at them tells the user nothing + const auto frame = std::ranges::find_if(stack, [](const StackFrame& candidate) + { + return candidate.line != 0 && !candidate.file.empty(); + }); + + if (frame == stack.end()) + return; + + debugger.select_frame(frame->index); + show_frame(*frame); + } + + auto Ui::show_frame(const StackFrame& frame) -> void + { + if (frame.file.empty() || frame.line == 0) + return; + + if (m_source_view.path() != frame.file) + open_source(frame.file); + + m_source_view.set_highlighted_line(frame.line); + } + auto Ui::draw(Debugger& debugger) -> void { const ImGuiViewport* viewport = ImGui::GetMainViewport(); @@ -161,6 +205,8 @@ namespace Hsdbg draw_menu_bar(debugger); draw_toolbar(debugger); + follow_stop(debugger); + const ImGuiID dockspace_id = ImGui::GetID("##hsdbg_dockspace"); const float status_bar_height = ImGui::GetTextLineHeight() + ImGui::GetStyle().ItemSpacing.y * 3.0f; @@ -571,7 +617,10 @@ namespace Hsdbg const std::string label = std::format("{:>2} {}", frame.index, frame.function); if (ImGui::Selectable(label.c_str(), selected)) + { debugger.select_frame(frame.index); + show_frame(frame); + } if (frame.line == 0) continue; diff --git a/src/ui/ui.h b/src/ui/ui.h index 90c314d..df6f7bd 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -13,6 +13,7 @@ namespace Hsdbg { class Debugger; class Window; + struct StackFrame; class Ui { @@ -64,6 +65,9 @@ namespace Hsdbg auto push_console(std::string line) -> void; auto report(const Result& result, std::string_view action) -> void; + auto follow_stop(Debugger& debugger) -> void; + auto show_frame(const StackFrame& frame) -> void; + Window* m_window = nullptr; SourceView m_source_view; PanelVisibility m_visible; @@ -72,6 +76,8 @@ namespace Hsdbg std::string m_console_input; std::string m_target_input; + uint64_t m_followed_stop = 0; + bool m_layout_built = false; bool m_console_scroll_pending = false; bool m_load_target_pending = false; -- cgit v1.3