aboutsummaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/ui.cpp49
-rw-r--r--src/ui/ui.h6
2 files changed, 55 insertions, 0 deletions
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 <backends/imgui_impl_glfw.h>
#include <backends/imgui_impl_opengl3.h>
+#include <algorithm>
#include <filesystem>
#include <format>
+#include <span>
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<const StackFrame> 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<void>& 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;