Merge branch code-window: separate top-level code window with red paused line + automatic variable inspection

This commit is contained in:
Muse committed 2026-11-25 14:31:43 -05:00
commit f30b285b00
12 files changed
+944 -21

No files matched your search

+1
View File
@@ -3,3 +3,4 @@ fdesigner
tests/gen_matrix
tests/debugger/work/
tests/out/
tests/codewin/work/
+212 -13
View File
@@ -287,10 +287,19 @@ struct CodeViewData {
std::set<int> folded; // 0-based region start lines
std::set<int> breakpoints; // 1-based file lines
int current_line = 0; // 1-based, 0 = none
int paused_line = 0; // 1-based, 0 = none (debugger paused here)
CodeTheme theme;
std::function<bool(const std::string&, int)> bp_cb;
GtkTextTag* fold_tag = nullptr;
GtkTextTag* cur_tag = nullptr;
GtkTextTag* paused_tag = nullptr;
// Automatic inspection pane (bottom of the window).
CodeViewInspectState inspect_state = CodeViewInspectState::NoTarget;
std::string inspect_scope;
std::vector<Variable> inspect_vars;
GtkWidget* inspect_frame = nullptr;
GtkWidget* scope_label = nullptr;
GtkListStore* vars_store = nullptr;
};
CodeViewData* data_of(GtkWidget* cv) {
@@ -343,30 +352,109 @@ void apply_folds(CodeViewData* d) {
}
}
void apply_current_line(CodeViewData* d) {
// (Re)apply the current-line and paused-line tags. The paused tag has
// higher priority than the current-line tag (set at creation), so when
// both mark the same line the red paused background wins — exactly the
// Lazarus distinction between "execution is here" and "current line".
void apply_line_marks(CodeViewData* d) {
GtkTextBuffer* buf =
gtk_text_view_get_buffer(GTK_TEXT_VIEW(d->view));
if (!d->cur_tag) return;
GtkTextIter a, b;
gtk_text_buffer_get_bounds(buf, &a, &b);
gtk_text_buffer_remove_tag(buf, d->cur_tag, &a, &b);
if (d->current_line >= 1 &&
d->current_line <= gtk_text_buffer_get_line_count(buf)) {
if (d->cur_tag) gtk_text_buffer_remove_tag(buf, d->cur_tag, &a, &b);
if (d->paused_tag)
gtk_text_buffer_remove_tag(buf, d->paused_tag, &a, &b);
auto apply_one = [&](GtkTextTag* tag, int line1) {
if (!tag || line1 < 1 ||
line1 > gtk_text_buffer_get_line_count(buf))
return;
GtkTextIter sa, sb;
gtk_text_buffer_get_iter_at_line(buf, &sa, d->current_line - 1);
if (d->current_line < gtk_text_buffer_get_line_count(buf))
gtk_text_buffer_get_iter_at_line(buf, &sb, d->current_line);
gtk_text_buffer_get_iter_at_line(buf, &sa, line1 - 1);
if (line1 < gtk_text_buffer_get_line_count(buf))
gtk_text_buffer_get_iter_at_line(buf, &sb, line1);
else
gtk_text_buffer_get_end_iter(buf, &sb);
gtk_text_buffer_apply_tag(buf, d->cur_tag, &sa, &sb);
gtk_text_buffer_apply_tag(buf, tag, &sa, &sb);
};
apply_one(d->cur_tag, d->current_line);
if (d->paused_tag && d->paused_line >= 1) {
GtkTextTagTable* table = gtk_text_buffer_get_tag_table(buf);
gtk_text_tag_set_priority(
d->paused_tag, gtk_text_tag_table_get_size(table) - 1);
}
apply_one(d->paused_tag, d->paused_line);
}
// The paused-line tag: solid red background, white text — readable on
// any theme, unmistakable next to the theme's current-line highlight.
// Created (or re-pointed) whenever the buffer's tags are (re)built.
void ensure_paused_tag(CodeViewData* d, GtkTextBuffer* buf) {
GtkTextTagTable* table = gtk_text_buffer_get_tag_table(buf);
d->paused_tag = gtk_text_tag_table_lookup(table, "theme-paused-line");
if (!d->paused_tag)
d->paused_tag = gtk_text_buffer_create_tag(
buf, "theme-paused-line", "background", "#c00000",
"foreground", "white", NULL);
else
g_object_set(d->paused_tag, "background", "#c00000",
"foreground", "white", NULL);
// Outrank every other tag on the line (current-line tag and any
// syntax tag): top priority in the table is always valid, while
// cur_priority+1 can exceed the table size when the current-line
// tag was created last.
gtk_text_tag_set_priority(
d->paused_tag, gtk_text_tag_table_get_size(table) - 1);
}
void apply_current_line(CodeViewData* d) { apply_line_marks(d); }
void queue_redraw(CodeViewData* d) {
gtk_widget_queue_draw(d->gutter);
gtk_widget_queue_draw(d->view);
}
// Repaint the inspection pane from the stored snapshot. While the
// target runs the pane shows the running state and NO values, so stale
// locals are never presented as current.
void refresh_inspection_ui(CodeViewData* d) {
if (!d->scope_label || !d->vars_store) return;
std::string scope;
switch (d->inspect_state) {
case CodeViewInspectState::NoTarget:
scope = "No target running \u2014 start the debugger to "
"inspect variables.";
break;
case CodeViewInspectState::Running:
scope = "Running \u2014 variables will appear when the "
"target stops.";
break;
case CodeViewInspectState::Stopped:
scope = d->inspect_scope.empty() ? "Stopped."
: d->inspect_scope;
break;
case CodeViewInspectState::Exited:
scope = d->inspect_scope.empty() ? "Target exited."
: d->inspect_scope;
break;
}
gtk_label_set_text(GTK_LABEL(d->scope_label), scope.c_str());
gtk_list_store_clear(d->vars_store);
if (d->inspect_state == CodeViewInspectState::Stopped) {
for (const auto& v : d->inspect_vars) {
GtkTreeIter it;
gtk_list_store_append(d->vars_store, &it);
gtk_list_store_set(d->vars_store, &it, 0, v.name.c_str(), 1,
v.type.c_str(), 2, v.value.c_str(), -1);
}
if (d->inspect_vars.empty()) {
GtkTreeIter it;
gtk_list_store_append(d->vars_store, &it);
gtk_list_store_set(d->vars_store, &it, 0,
"(no locals in scope)", 1, "", 2, "", -1);
}
}
}
bool region_starts_at(CodeViewData* d, int line0) {
for (const auto& r : d->regions)
if (r.start_line == line0) return true;
@@ -437,7 +525,21 @@ gboolean on_gutter_draw(GtkWidget* gutter, cairo_t* cr, gpointer user) {
gint y, h;
gtk_text_view_get_line_yrange(GTK_TEXT_VIEW(d->view), &it, &y, &h);
if (h <= 0) continue; // folded away
if (d->current_line == ln + 1) {
bool paused = (d->paused_line == ln + 1);
if (paused) {
// Red gutter strip to match the red paused-line background.
cairo_set_source_rgb(cr, 0.75, 0.0, 0.0);
cairo_rectangle(cr, 0, y, alloc.width, h);
cairo_fill(cr);
// White right-pointing execution arrow (Lazarus-style).
double yc = y + h / 2.0;
cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
cairo_move_to(cr, 14, yc - 5);
cairo_line_to(cr, 14, yc + 5);
cairo_line_to(cr, 22, yc);
cairo_close_path(cr);
cairo_fill(cr);
} else if (d->current_line == ln + 1) {
cairo_set_source_rgb(cr, cr_, cg, cb);
cairo_rectangle(cr, 0, y, alloc.width, h);
cairo_fill(cr);
@@ -461,7 +563,10 @@ gboolean on_gutter_draw(GtkWidget* gutter, cairo_t* cr, gpointer user) {
std::snprintf(num, sizeof num, "%d", ln + 1);
cairo_text_extents_t ext;
cairo_text_extents(cr, num, &ext);
cairo_set_source_rgba(cr, fr, fg, fb, 0.65);
if (paused)
cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 1.0);
else
cairo_set_source_rgba(cr, fr, fg, fb, 0.65);
cairo_move_to(cr, alloc.width - 6 - ext.width, y + h - 4);
cairo_show_text(cr, num);
}
@@ -499,7 +604,12 @@ void on_scroll_changed(GtkAdjustment*, gpointer user) {
GtkWidget* codeview_new() {
CodeViewData* d = new CodeViewData();
d->theme = theme_current();
GtkWidget* box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
// Outer box is vertical: code area on top, automatic-inspection
// pane at the bottom. The inner box keeps the old horizontal
// gutter + text view layout.
GtkWidget* box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
GtkWidget* code_box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
gtk_box_pack_start(GTK_BOX(box), code_box, TRUE, TRUE, 0);
d->box = box;
d->gutter = gtk_drawing_area_new();
gtk_widget_set_size_request(d->gutter, 76, 100);
@@ -520,7 +630,43 @@ GtkWidget* codeview_new() {
gtk_box_pack_start(GTK_BOX(inner), d->gutter, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(inner), d->view, TRUE, TRUE, 0);
gtk_container_add(GTK_CONTAINER(d->scroll), inner);
gtk_box_pack_start(GTK_BOX(box), d->scroll, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(code_box), d->scroll, TRUE, TRUE, 0);
// Inspection pane: scope label + name/type/value list.
d->inspect_frame =
gtk_frame_new("Variables in scope \u2014 automatic inspection");
GtkWidget* ivbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 4);
gtk_container_set_border_width(GTK_CONTAINER(ivbox), 6);
d->scope_label = gtk_label_new(
"No target running \u2014 start the debugger to inspect "
"variables.");
gtk_label_set_xalign(GTK_LABEL(d->scope_label), 0.0);
gtk_label_set_ellipsize(GTK_LABEL(d->scope_label),
PANGO_ELLIPSIZE_END);
gtk_box_pack_start(GTK_BOX(ivbox), d->scope_label, FALSE, FALSE, 0);
d->vars_store =
gtk_list_store_new(3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
GtkWidget* vars_view =
gtk_tree_view_new_with_model(GTK_TREE_MODEL(d->vars_store));
{
auto add_col = [&](const char* title, int col, bool expand) {
GtkCellRenderer* r = gtk_cell_renderer_text_new();
GtkTreeViewColumn* c = gtk_tree_view_column_new_with_attributes(
title, r, "text", col, NULL);
gtk_tree_view_column_set_expand(c, expand);
gtk_tree_view_append_column(GTK_TREE_VIEW(vars_view), c);
};
add_col("Name", 0, FALSE);
add_col("Type", 1, FALSE);
add_col("Value", 2, TRUE);
}
GtkWidget* vscroll = gtk_scrolled_window_new(NULL, NULL);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(vscroll),
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
gtk_widget_set_size_request(vscroll, -1, 140);
gtk_container_add(GTK_CONTAINER(vscroll), vars_view);
gtk_box_pack_start(GTK_BOX(ivbox), vscroll, TRUE, TRUE, 0);
gtk_container_add(GTK_CONTAINER(d->inspect_frame), ivbox);
gtk_box_pack_start(GTK_BOX(box), d->inspect_frame, FALSE, FALSE, 0);
g_signal_connect(d->view, "size-allocate",
G_CALLBACK(on_view_size_allocate), d);
GtkAdjustment* vadj = gtk_scrolled_window_get_vadjustment(
@@ -545,6 +691,7 @@ void codeview_set_text(GtkWidget* cv, const std::string& text,
d->folded.clear();
d->breakpoints.clear();
d->current_line = 0;
d->paused_line = 0; // new file: no paused line until the next stop
GtkTextBuffer* buf =
gtk_text_view_get_buffer(GTK_TEXT_VIEW(d->view));
gtk_text_buffer_set_text(buf, text.c_str(), -1);
@@ -561,6 +708,7 @@ void codeview_set_text(GtkWidget* cv, const std::string& text,
else
g_object_set(d->cur_tag, "background", d->theme.current_line.c_str(),
NULL);
ensure_paused_tag(d, buf);
theme_highlight_buffer(buf, d->theme);
theme_apply_to_view(d->view, d->theme);
apply_folds(d);
@@ -589,6 +737,8 @@ void codeview_set_theme(GtkWidget* cv, const CodeTheme& theme) {
if (d->cur_tag)
g_object_set(d->cur_tag, "background", theme.current_line.c_str(),
NULL);
ensure_paused_tag(d, buf); // paused red is theme-independent
apply_line_marks(d);
theme_highlight_buffer(buf, theme);
theme_apply_to_view(d->view, theme);
queue_redraw(d);
@@ -612,6 +762,55 @@ int codeview_current_line(GtkWidget* cv) {
return d ? d->current_line : 0;
}
void codeview_set_paused_line(GtkWidget* cv, int line_1based) {
CodeViewData* d = data_of(cv);
if (!d) return;
d->paused_line = line_1based;
apply_line_marks(d);
queue_redraw(d);
if (line_1based >= 1) {
GtkTextBuffer* buf =
gtk_text_view_get_buffer(GTK_TEXT_VIEW(d->view));
if (line_1based <= gtk_text_buffer_get_line_count(buf)) {
GtkTextIter it;
gtk_text_buffer_get_iter_at_line(buf, &it, line_1based - 1);
gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(d->view), &it, 0.0,
TRUE, 0.0, 0.5);
}
}
}
int codeview_paused_line(GtkWidget* cv) {
CodeViewData* d = data_of(cv);
return d ? d->paused_line : 0;
}
void codeview_set_inspection(GtkWidget* cv, CodeViewInspectState state,
const std::string& scope_label,
const std::vector<Variable>& vars) {
CodeViewData* d = data_of(cv);
if (!d) return;
d->inspect_state = state;
d->inspect_scope = scope_label;
d->inspect_vars = vars;
refresh_inspection_ui(d);
}
CodeViewInspectState codeview_inspection_state(GtkWidget* cv) {
CodeViewData* d = data_of(cv);
return d ? d->inspect_state : CodeViewInspectState::NoTarget;
}
std::string codeview_inspection_scope(GtkWidget* cv) {
CodeViewData* d = data_of(cv);
return d ? d->inspect_scope : std::string();
}
std::vector<Variable> codeview_inspection_vars(GtkWidget* cv) {
CodeViewData* d = data_of(cv);
return d ? d->inspect_vars : std::vector<Variable>();
}
void codeview_set_breakpoint_callback(
GtkWidget* cv,
const std::function<bool(const std::string&, int)>& cb) {
+28
View File
@@ -33,6 +33,7 @@
#include <string>
#include <vector>
#include "debugger.h" // Variable (name/type/value) for the inspection pane
#include "theme.h"
// One foldable span. Lines are 0-based, inclusive at both ends; only
@@ -74,6 +75,18 @@ CodeTheme codeview_theme(GtkWidget* cv);
// Highlight this file line as the current execution line (0 = none).
void codeview_set_current_line(GtkWidget* cv, int line_1based);
int codeview_current_line(GtkWidget* cv);
// Paused line (0 = none): the line the debugger is paused on. Rendered
// with a RED full-line background (white text) plus a gutter arrow, in
// the Lazarus manner: Lazarus marks the execution point with a full-line
// background highlight (ahaExecutionPoint) and a gutter arrow, distinct
// from the breakpoint marker (red dot / red highlight). Here the user
// asked for the paused line in red, so the execution-point background
// is solid red (#c00000) with white text — readable on any theme —
// while a breakpoint stays just the red dot in the gutter. The paused
// tag outranks the current-line tag, so when both point at the same
// line the red background wins. Clears when execution resumes.
void codeview_set_paused_line(GtkWidget* cv, int line_1based);
int codeview_paused_line(GtkWidget* cv);
// Breakpoint dots (1-based file lines). The widget does not own the
// debugger; toggling goes through the callback, which returns true
// when the breakpoint is now set. With no callback, toggling just
@@ -84,6 +97,21 @@ void codeview_set_breakpoint_callback(
void codeview_set_breakpoint_lines(GtkWidget* cv,
const std::set<int>& lines_1based);
std::set<int> codeview_breakpoint_lines(GtkWidget* cv);
// Automatic variable inspection (pane at the bottom of the code
// window). The host (main) pushes a fresh snapshot whenever the
// debugger stops / steps / runs / exits; the widget only displays.
// NoTarget: no debug session / no target — "start the debugger"
// Running: target is running — NEVER show stale values as current
// Stopped: scope_label names the scope ("func() — file:line
// (reason)") and vars are the locals of that frame
// Exited: target exited — scope_label carries the exit code
enum class CodeViewInspectState { NoTarget, Running, Stopped, Exited };
void codeview_set_inspection(GtkWidget* cv, CodeViewInspectState state,
const std::string& scope_label,
const std::vector<Variable>& vars);
CodeViewInspectState codeview_inspection_state(GtkWidget* cv);
std::string codeview_inspection_scope(GtkWidget* cv);
std::vector<Variable> codeview_inspection_vars(GtkWidget* cv);
// Fold state (0-based start lines in the pure API; 1-based here).
std::vector<FoldRegion> codeview_regions(GtkWidget* cv);
bool codeview_toggle_fold_at(GtkWidget* cv, int line_1based);
+3
View File
@@ -171,6 +171,9 @@ public:
// Non-blocking drain of pending MI output (used by the GUI poll tick).
void poll_events();
const StopInfo& last_stop() const { return last_stop_; }
// Monotonic stop counter (incremented on every *stopped event).
// Lets a UI poll tell a fresh stop apart from a stale Stopped state.
unsigned long stop_seq() const { return stop_seq_; }
// Breakpoints.
// Remember a breakpoint before gdb is running (e.g. typed in the UI
+76
View File
@@ -770,6 +770,31 @@ void debugger_window_open(GtkWidget* parent) {
if (parent) gtk_window_set_transient_for(GTK_WINDOW(win),
GTK_WINDOW(parent));
g_dbg_window = win;
// Keyboard shortcuts matching the toolbar tooltips: F5 Continue,
// F10 Step Over, F11 Step Into. (Also lets scripted tests drive
// stepping with xdotool key.)
g_signal_connect(win, "key-press-event",
G_CALLBACK(+[](GtkWidget*, GdkEventKey* e,
gpointer) -> gboolean {
if (!g_session) return FALSE;
std::string err;
const char* w = nullptr;
if (e->keyval == GDK_KEY_F5) w = "cont";
else if (e->keyval == GDK_KEY_F10) w = "over";
else if (e->keyval == GDK_KEY_F11) w = "into";
else return FALSE;
bool ok = false;
if (!std::strcmp(w, "cont"))
ok = g_session->cont(err);
else if (!std::strcmp(w, "over"))
ok = g_session->step_over(err);
else if (!std::strcmp(w, "into"))
ok = g_session->step_into(err);
if (ok) sync_ui_from_session();
else show_error(g_dbg_window, err);
return TRUE;
}),
nullptr);
g_signal_connect(win, "destroy", G_CALLBACK(+[](GtkWidget*) {
g_dbg_window = nullptr;
// Keep the session alive for the menu toggles;
@@ -1032,3 +1057,54 @@ std::vector<int> debugger_breakpoint_lines(const std::string& file) {
out.push_back(b.line);
return out;
}
// --- code-window integration: the code window reads the SAME session ---
// (never a second gdb) through these accessors, on its own poll tick.
void debugger_poll_events() {
if (g_session) g_session->poll_events();
}
DbgState debugger_session_state() {
return g_session ? g_session->state() : DbgState::Idle;
}
unsigned long debugger_stop_seq() {
return g_session ? g_session->stop_seq() : 0;
}
StopInfo debugger_last_stop() {
return g_session ? g_session->last_stop() : StopInfo();
}
std::vector<Variable> debugger_locals() {
return g_session ? g_session->locals() : std::vector<Variable>();
}
void debugger_refresh_on_stop() {
if (g_session) g_session->refresh_on_stop();
}
bool debugger_autorun(const std::string& exe, const std::string& bp_loc,
std::string& err) {
if (!ensure_session(err)) return false;
if (g_target_entry)
gtk_entry_set_text(GTK_ENTRY(g_target_entry), exe.c_str());
if (!bp_loc.empty()) {
if (g_session->is_alive()) {
Breakpoint b;
if (!g_session->add_breakpoint(bp_loc, b, err)) return false;
} else if (!g_session->stage_breakpoint(bp_loc)) {
err = "not a breakpoint location: " + bp_loc;
return false;
}
g_session->save_breakpoints();
}
if (g_session->state() == DbgState::Stopped ||
g_session->state() == DbgState::Exited) {
if (!g_session->restart(err)) return false;
} else {
if (!g_session->start(exe, "", err)) return false;
}
if (g_dbg_window) sync_ui_from_session();
return true;
}
+24 -1
View File
@@ -7,6 +7,8 @@
#include <string>
#include <vector>
#include "debugger.h" // DbgState, StopInfo, Variable, DebuggerSettings
// Show the debugger window (creates it on first call, raises it after).
void debugger_window_open(GtkWidget* parent);
// Open the debugger settings dialog (also reachable from the Debug menu's
@@ -21,8 +23,29 @@ bool debugger_toggle_breakpoint(const std::string& file, int line);
bool debugger_has_breakpoint(const std::string& file, int line);
// 1-based lines in `file` that currently have breakpoints.
std::vector<int> debugger_breakpoint_lines(const std::string& file);
// --- code-window integration (same shared session, no second gdb) ---
// Drain pending gdb events without needing the debugger window open.
// Safe to call from another UI poll; the debugger window's own poll
// drains the same queue.
void debugger_poll_events();
// Session state as seen by the code window's poll.
DbgState debugger_session_state();
// Monotonic stop counter; changes on every fresh *stopped event.
unsigned long debugger_stop_seq();
// Copy of the last stop record (frame, reason, exit code).
StopInfo debugger_last_stop();
// Locals of the current frame (refreshed by debugger_refresh_on_stop).
std::vector<Variable> debugger_locals();
// Refresh locals/frames/watches after a stop (best effort, no-op
// unless stopped). The debugger window's poll does this too; calling
// twice is harmless.
void debugger_refresh_on_stop();
// Test hook: start `exe` under the debugger, staging a breakpoint at
// `bp_loc` ("file:line", may be empty) first. Opens the debugger
// window if needed. Returns false + err when gdb refuses to start.
bool debugger_autorun(const std::string& exe, const std::string& bp_loc,
std::string& err);
// True once the debugger window has been created (used by the GUI smoke test).
bool debugger_window_is_open();
// For tests: the settings currently in effect (loaded from disk at open).
#include "debugger.h"
DebuggerSettings debugger_current_settings();
+259 -5
View File
@@ -27,6 +27,7 @@
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#include "model.h"
@@ -2486,19 +2487,170 @@ static void refresh_code_view() {
status("Code view - " + path);
}
// --- code window <-> debugger sync ------------------------------------
// Polls the SHARED GdbSession (owned by the debugger window) and keeps
// the code window's paused line + inspection pane in step with it:
// Running -> inspection shows "running", paused line cleared (never
// present stale values as current)
// Stopped -> refresh locals, load the stopped file into the code view
// if it is not already shown, red paused-line background,
// scope label + locals in the inspection pane
// Exited -> paused line cleared, inspection shows the exit code
// Idle -> inspection shows "no target"
// Only acts when (state, stop_seq) changed, or when `force` is set
// (reopen / theme change / startup). The debugger window's own poll
// drains the same gdb queue; this poll just reads the shared session.
static unsigned long s_cw_last_seq = 0;
static DbgState s_cw_last_state = DbgState::Idle;
static const char* cw_state_name(DbgState st) {
switch (st) {
case DbgState::Idle: return "Idle";
case DbgState::Starting: return "Starting";
case DbgState::Running: return "Running";
case DbgState::Stopped: return "Stopped";
case DbgState::Exited: return "Exited";
case DbgState::Error: return "Error";
}
return "Idle";
}
// Test hook: FDESIGNER_CODEWIN_DUMP=<path> writes a snapshot of the
// code window's debug state (state, scope, file, paused line, locals)
// every time the sync applies a change. Used by
// tests/code_window_tests.sh to assert on the live app.
static void codewin_dump_snapshot(DbgState st) {
const char* path = std::getenv("FDESIGNER_CODEWIN_DUMP");
if (!path || !*path || !g_codeview) return;
std::string out = "state=";
out += cw_state_name(st);
out += "\n";
out += "scope=" + codeview_inspection_scope(g_codeview) + "\n";
out += "file=" + codeview_file_path(g_codeview) + "\n";
out += "paused_line=" +
std::to_string(codeview_paused_line(g_codeview)) + "\n";
out += "current_line=" +
std::to_string(codeview_current_line(g_codeview)) + "\n";
for (const auto& v : codeview_inspection_vars(g_codeview))
out += "var=" + v.name + "|" + v.type + "|" + v.value + "\n";
std::string tmp = std::string(path) + ".tmp";
std::ofstream f(tmp, std::ios::trunc);
if (!f) return;
f << out;
f.close();
std::rename(tmp.c_str(), path);
}
static void codewin_sync_from_debugger(bool force) {
if (!g_codeview) return;
debugger_poll_events();
DbgState st = debugger_session_state();
unsigned long seq = debugger_stop_seq();
bool changed = force || st != s_cw_last_state || seq != s_cw_last_seq;
if (!changed) return;
s_cw_last_state = st;
s_cw_last_seq = seq;
StopInfo stop = debugger_last_stop();
switch (st) {
case DbgState::Running:
codeview_set_paused_line(g_codeview, 0);
codeview_set_current_line(g_codeview, 0);
codeview_set_inspection(g_codeview,
CodeViewInspectState::Running, "", {});
break;
case DbgState::Stopped: {
debugger_refresh_on_stop();
stop = debugger_last_stop();
if (!stop.frame.file.empty() &&
stop.frame.file != codeview_file_path(g_codeview)) {
gchar* c = nullptr;
if (g_file_get_contents(stop.frame.file.c_str(), &c,
nullptr, nullptr) &&
c) {
codeview_set_text(g_codeview, c, stop.frame.file);
g_free(c);
std::set<int> bps;
for (int ln :
debugger_breakpoint_lines(stop.frame.file))
bps.insert(ln);
codeview_set_breakpoint_lines(g_codeview, bps);
}
}
std::string scope =
stop.frame.function + "() \u2014 " + stop.frame.file +
":" + std::to_string(stop.frame.line);
if (!stop.reason.empty()) scope += " (" + stop.reason + ")";
codeview_set_inspection(g_codeview,
CodeViewInspectState::Stopped, scope,
debugger_locals());
// Red paused-line background only on the file actually
// shown; otherwise the line number would be meaningless.
if (!stop.frame.file.empty() &&
stop.frame.file == codeview_file_path(g_codeview)) {
// Unfold any region hiding the paused line.
int l0 = stop.frame.line - 1;
for (const auto& r : codeview_regions(g_codeview))
if (r.start_line < l0 && l0 < r.end_line &&
codeview_is_folded(g_codeview, r.start_line + 1))
codeview_toggle_fold_at(g_codeview,
r.start_line + 1);
codeview_set_current_line(g_codeview, stop.frame.line);
codeview_set_paused_line(g_codeview, stop.frame.line);
} else {
codeview_set_current_line(g_codeview, 0);
codeview_set_paused_line(g_codeview, 0);
}
break;
}
case DbgState::Exited: {
codeview_set_paused_line(g_codeview, 0);
codeview_set_current_line(g_codeview, 0);
std::string scope = "Target exited";
if (stop.exit_code >= 0)
scope += " (code " + std::to_string(stop.exit_code) + ")";
scope += ".";
codeview_set_inspection(g_codeview,
CodeViewInspectState::Exited, scope, {});
break;
}
default:
codeview_set_paused_line(g_codeview, 0);
codeview_set_current_line(g_codeview, 0);
codeview_set_inspection(g_codeview,
CodeViewInspectState::NoTarget, "", {});
break;
}
codewin_dump_snapshot(st);
}
static gboolean on_codewin_poll(gpointer) {
codewin_sync_from_debugger(false);
return G_SOURCE_CONTINUE;
}
static void open_code_view() {
if (!g_codeview_window) {
g_codeview_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(g_codeview_window),
"Code - generated C++");
gtk_window_set_default_size(GTK_WINDOW(g_codeview_window), 900, 600);
gtk_window_set_transient_for(GTK_WINDOW(g_codeview_window),
GTK_WINDOW(g_window));
"FDesigner \u2014 Code");
gtk_window_set_default_size(GTK_WINDOW(g_codeview_window), 1000,
700);
// Deliberately NOT transient for the designer: this is its own
// top-level window, listed separately by the window manager.
g_codeview = codeview_new();
codeview_set_theme(g_codeview, theme_current());
codeview_set_breakpoint_callback(g_codeview,
debugger_toggle_breakpoint);
gtk_container_add(GTK_CONTAINER(g_codeview_window), g_codeview);
// Closing the window hides it (the app keeps running);
// reopening from View -> Code View restores it, refreshed.
g_signal_connect(
g_codeview_window, "delete-event",
G_CALLBACK(+[](GtkWidget* w, GdkEvent*, gpointer) -> gboolean {
gtk_widget_hide(w);
return TRUE;
}),
nullptr);
g_signal_connect(
g_codeview_window, "destroy",
G_CALLBACK(+[](GtkWidget*, gpointer) {
@@ -2508,9 +2660,19 @@ static void open_code_view() {
nullptr);
gtk_widget_show_all(g_codeview_window);
} else {
gtk_widget_show(g_codeview_window);
gtk_window_present(GTK_WINDOW(g_codeview_window));
}
refresh_code_view();
codewin_sync_from_debugger(true);
}
// View -> Code View toggles the separate top-level code window.
static void toggle_code_view() {
if (g_codeview_window && gtk_widget_get_visible(g_codeview_window))
gtk_widget_hide(g_codeview_window);
else
open_code_view();
}
static void on_generate(GtkMenuItem*, gpointer) {
GtkWidget* dlg = gtk_file_chooser_dialog_new(
@@ -3670,6 +3832,71 @@ static gboolean selftest_step(gpointer) {
check(codeview_breakpoint_lines(cv).empty());
codeview_set_current_line(cv, 4);
check(codeview_current_line(cv) == 4);
// Round 3: red paused line (Lazarus-style execution-point
// background) + automatic inspection pane.
codeview_set_paused_line(cv, 5);
check(codeview_paused_line(cv) == 5);
{
GtkTextBuffer* pbuf = gtk_text_view_get_buffer(
GTK_TEXT_VIEW(codeview_text_view(cv)));
GtkTextTagTable* ptab =
gtk_text_buffer_get_tag_table(pbuf);
GtkTextTag* paused = gtk_text_tag_table_lookup(
ptab, "theme-paused-line");
check(paused != nullptr);
if (paused) {
// "background"/"foreground" are write-only; the
// readable form is "background-gdk"/"foreground-gdk"
// (boxed GdkColor*, 16-bit channels), as for the
// keyword tag below.
GdkColor* bg = nullptr;
GdkColor* fg = nullptr;
g_object_get(paused, "background-gdk", &bg,
"foreground-gdk", &fg, NULL);
// #c00000: red dominant; white text for readability.
check(bg && fg && bg->red > 40000 && bg->green < 8000 &&
bg->blue < 8000);
check(bg && fg && fg->red > 60000 && fg->green > 60000 &&
fg->blue > 60000);
if (bg)
g_boxed_free(g_type_from_name("GdkColor"), bg);
if (fg)
g_boxed_free(g_type_from_name("GdkColor"), fg);
// Paused tag outranks the current-line tag, so red
// wins when both mark the same line.
GtkTextTag* cur = gtk_text_tag_table_lookup(
ptab, "theme-current-line");
check(cur != nullptr);
if (cur)
check(gtk_text_tag_get_priority(paused) >
gtk_text_tag_get_priority(cur));
}
}
codeview_set_paused_line(cv, 0);
check(codeview_paused_line(cv) == 0);
// Inspection pane: states + scope + vars round-trip, and the
// running state carries no (stale) values.
check(codeview_inspection_state(cv) ==
CodeViewInspectState::NoTarget);
std::vector<Variable> ivars = {
{"a", "int", "42"}, {"msg", "const char *", "\"hello\""}};
codeview_set_inspection(cv, CodeViewInspectState::Stopped,
"main() \u2014 /tmp/x.c:8 (breakpoint-hit)",
ivars);
check(codeview_inspection_state(cv) ==
CodeViewInspectState::Stopped);
check(codeview_inspection_scope(cv) ==
"main() \u2014 /tmp/x.c:8 (breakpoint-hit)");
check(codeview_inspection_vars(cv).size() == 2);
check(codeview_inspection_vars(cv)[0].name == "a");
check(codeview_inspection_vars(cv)[0].value == "42");
check(codeview_inspection_vars(cv)[1].name == "msg");
codeview_set_inspection(cv, CodeViewInspectState::Running, "", {});
check(codeview_inspection_state(cv) ==
CodeViewInspectState::Running);
check(codeview_inspection_vars(cv).empty());
codeview_set_inspection(cv, CodeViewInspectState::NoTarget, "",
{});
codeview_set_theme(cv, dark);
GtkTextBuffer* cbuf = gtk_text_view_get_buffer(
GTK_TEXT_VIEW(codeview_text_view(cv)));
@@ -3821,7 +4048,7 @@ int main(int argc, char** argv) {
if (mi_code)
g_signal_connect(mi_code, "activate",
G_CALLBACK(+[](GtkMenuItem*, gpointer) {
open_code_view();
toggle_code_view();
}),
nullptr);
GObject* mi_theme = gtk_builder_get_object(builder, "mi_view_theme");
@@ -3901,6 +4128,13 @@ int main(int argc, char** argv) {
status("Phase 2 — pick a widget from the palette to place it");
gtk_widget_show_all(g_window);
// The code window is a separate top-level window that opens
// together with the designer (View -> Code View toggles it).
open_code_view();
// Keep the code window's paused line + inspection pane in step
// with the shared debugger session (200 ms poll).
g_timeout_add(200, on_codewin_poll, nullptr);
if (std::getenv("FDESIGNER_OPEN_DEBUGGER") != nullptr)
g_idle_add(+[](gpointer) -> gboolean {
debugger_window_open(g_window);
@@ -3925,6 +4159,26 @@ int main(int argc, char** argv) {
},
nullptr);
// Test hook (used by tests/code_window_tests.sh): start a target
// under the debugger at startup, staging a breakpoint first.
// FDESIGNER_DEBUG_TARGET=<exe> FDESIGNER_DEBUG_BREAK=<file:line>
const char* dbg_target = std::getenv("FDESIGNER_DEBUG_TARGET");
if (dbg_target != nullptr) {
std::string exe = dbg_target;
const char* bp = std::getenv("FDESIGNER_DEBUG_BREAK");
std::string loc = bp ? bp : "";
g_idle_add(
+[](gpointer data) -> gboolean {
auto* pair = (std::pair<std::string, std::string>*)data;
debugger_window_open(g_window);
std::string err;
if (!debugger_autorun(pair->first, pair->second, err))
status("Debug autorun failed: " + err);
delete pair;
return G_SOURCE_REMOVE;
},
new std::pair<std::string, std::string>(exe, loc));
}
// Test hooks (also used by tests/theme_tests.sh): open the code
// view / theme picker at startup.
if (std::getenv("FDESIGNER_OPEN_CODEVIEW") != nullptr)
+281
View File
@@ -0,0 +1,281 @@
#!/bin/sh
# FDesigner code-window tests (round 3).
# tests/code_window_tests.sh
# Verifies, against the REAL app under Xvfb:
# (a) the code window is a separate top-level window with its own
# title, opened together with the designer at startup;
# (b) red dots render on breakpoint lines set via the debugger
# (and via a gutter click, which must stage a breakpoint in
# the backend);
# (c) the inspection pane auto-populates on a breakpoint hit with
# the CORRECT locals for that scope, and stepping into another
# function changes the shown scope;
# (d) the red paused-line background appears on a breakpoint pause,
# clears on resume, and moves on step (pixel-checked);
# (e) while the target runs, the inspection pane shows "running",
# not stale values;
# (f) closing the code window does not kill the app, and View ->
# Code View reopens it.
# The app is driven through FDESIGNER_DEBUG_TARGET / BREAK (autorun)
# and the FDESIGNER_CODEWIN_DUMP snapshot; stepping uses the debugger
# window's F5/F10/F11 shortcuts. Prints a PASS/FAIL summary; exits
# non-zero if anything fails. Run from the repo root.
set -u
ROOT=$(cd "$(dirname "$0")/.." && pwd)
cd "$ROOT"
FAIL=0
WORK="$ROOT/tests/codewin/work"
rm -rf "$WORK"
mkdir -p "$WORK/homeA" "$WORK/homeB" "$WORK/homeC"
say() { printf '%s\n' "$*"; }
pass() { say "PASS $1"; }
fail() { say "FAIL $1"; FAIL=1; }
note() { say " -- $1"; }
# --- build ---------------------------------------------------------------
say "== building fdesigner =="
make >"$WORK/make.log" 2>&1 || { say "FAIL fdesigner build"; cat "$WORK/make.log"; exit 1; }
if grep -q "warning" "$WORK/make.log"; then
say "FAIL fdesigner build has warnings"; grep "warning" "$WORK/make.log"; FAIL=1
fi
say "== building test targets =="
cp "$ROOT/tests/codewin/prog.c" "$WORK/prog.c"
gcc -g -O0 -o "$WORK/prog" "$WORK/prog.c" || fail "build-prog"
gcc -g -O0 -o "$WORK/spin" "$ROOT/tests/debugger/spin.cpp" || fail "build-spin"
# Sanity: the break lines must hold the statements the test expects.
sed -n '16p' "$WORK/prog.c" | grep -q "helper(a)" || fail "prog.c:16 is not the helper call"
sed -n '11p' "$WORK/prog.c" | grep -q "return z" || fail "prog.c:11 is not return z"
sed -n '14p' "$WORK/prog.c" | grep -q "int a = 42" || fail "prog.c:14 is not a=42"
# --- self-test (unit: paused tag colours, inspection API) ----------------
say "== fdesigner self-test (paused line + inspection block) =="
if FDESIGNER_SELFTEST=1 xvfb-run -a timeout 120 ./fdesigner >"$WORK/selftest.log" 2>&1; then
grep -q "SELFTEST PASS" "$WORK/selftest.log" && pass "selftest" || fail "selftest-no-pass-line"
else
fail "selftest"; cat "$WORK/selftest.log"
fi
# --- GUI helpers ----------------------------------------------------------
XDISP=":99"
export DISPLAY="$XDISP"
codewin_id() { xdotool search --name "FDesigner — Code" 2>/dev/null | head -1; }
dbgwin_id() { xdotool search --name "FDesigner Debugger" 2>/dev/null | head -1; }
mainwin_id() { xdotool search --name '^FDesigner — C\+\+/GTK$' 2>/dev/null | head -1; }
dump_has() { grep -q "$1" "$WORK/dump.txt" 2>/dev/null; }
wait_dump() { # $1=pattern $2=timeout-secs
i=0
while [ $i -lt $(( $2 * 5 )) ]; do
dump_has "$1" && return 0
sleep 0.2; i=$((i+1))
done
return 1
}
wait_win() { # $1=which(codewin|dbgwin|mainwin) $2=timeout-secs
i=0
while [ $i -lt $(( $2 * 5 )) ]; do
[ -n "$(${1}_id)" ] && return 0
sleep 0.2; i=$((i+1))
done
return 1
}
launch() { # $1=target $2=breakloc-or-empty $3=home-dir
rm -f "$WORK/dump.txt"
(cd "$ROOT" && HOME="$3" DISPLAY="$XDISP" \
FDESIGNER_DEBUG_TARGET="$1" FDESIGNER_DEBUG_BREAK="$2" \
FDESIGNER_CODEWIN_DUMP="$WORK/dump.txt" \
timeout 120 ./fdesigner >"$WORK/app.log" 2>&1) &
APP=$!
}
kill_app() {
kill $APP 2>/dev/null
pkill -x fdesigner 2>/dev/null
wait $APP 2>/dev/null
sleep 1
}
count_red() { # $1=png $2=x0 $3=x1 [$4=band] -> stdout count (+band line)
python3 "$ROOT/tests/codewin/count_red.py" "$1" "$2" "$3" "${4:-}"
}
if ! command -v xdotool >/dev/null 2>&1 || ! command -v import >/dev/null 2>&1; then
say "SKIP GUI e2e (xdotool/import not installed)"
[ "$FAIL" = "0" ] && say "CODE-WINDOW TESTS: ALL PASS" || say "CODE-WINDOW TESTS: FAILURES"
exit "$FAIL"
fi
Xvfb $XDISP -screen 0 1920x1080x24 >/dev/null 2>&1 &
XVPID=$!
sleep 2
trap 'kill_app; kill $XVPID 2>/dev/null' EXIT
# === Run A: breakpoint in main ============================================
say "== Run A: breakpoint in main (prog.c:16) =="
launch "$WORK/prog" "$WORK/prog.c:16" "$WORK/homeA"
if wait_win codewin 20; then
CW=$(codewin_id); pass "code-window-opens-at-startup (id $CW)"
else
fail "code-window-opens-at-startup"; kill_app; kill $XVPID 2>/dev/null; exit 1
fi
MW=$(mainwin_id)
if [ -n "$MW" ] && [ "$MW" != "$CW" ]; then
pass "code-window-is-separate-toplevel (main $MW, code $CW)"
else
fail "code-window-is-separate-toplevel (main=$MW code=$CW)"
fi
if wait_win dbgwin 20; then
DW=$(dbgwin_id); pass "debugger-window-open (id $DW)"
else
fail "debugger-window-open"
fi
if wait_dump "^state=Stopped" 20; then pass "stops-at-breakpoint"; else fail "stops-at-breakpoint"; cat "$WORK/dump.txt" 2>/dev/null; cat "$WORK/app.log"; fi
dump_has "^file=$WORK/prog.c" && pass "code-view-loads-stopped-file" || fail "code-view-loads-stopped-file"
dump_has "^paused_line=16" && pass "paused-line-16" || fail "paused-line-16"
dump_has "^current_line=16" && pass "current-line-16" || fail "current-line-16"
dump_has "main()" && pass "scope-is-main" || fail "scope-is-main"
dump_has "^var=a|int|42" && pass "local-a-42" || fail "local-a-42"
dump_has "^var=msg|" && grep "^var=msg|" "$WORK/dump.txt" | grep -q "hello" && pass "local-msg-hello" || fail "local-msg-hello"
note "dump after stop:"; sed 's/^/ dump: /' "$WORK/dump.txt" 2>/dev/null
# (d) red paused-line background, pixel-checked. Raise the code window
# first: Xvfb has no compositor, so an obscured window reads back wrong.
sleep 1
DISPLAY="$XDISP" xdotool windowraise "$CW" 2>/dev/null
sleep 0.5
DISPLAY="$XDISP" import -window "$CW" "$WORK/shot_paused.png" 2>/dev/null
RED_ALL=$(count_red "$WORK/shot_paused.png" 0 10000)
RED_TEXT=$(count_red "$WORK/shot_paused.png" 150 10000)
BAND=$(count_red "$WORK/shot_paused.png" 0 10000 band | tail -1)
note "paused screenshot: red_all=$RED_ALL red_text_area=$RED_TEXT ($BAND)"
if [ "${RED_TEXT:-0}" -ge 500 ]; then pass "red-paused-band-present"; else fail "red-paused-band-present (red_text=$RED_TEXT)"; fi
# Band geometry (screenshot coords) for the gutter-click test below.
BAND_TOP=$(echo "$BAND" | sed 's/.*band_top=\([0-9-]*\).*/\1/')
BAND_BOT=$(echo "$BAND" | sed 's/.*band_bottom=\([0-9-]*\).*/\1/')
BAND_H=0
if [ "${BAND_TOP:- -1}" -ge 0 ] && [ "${BAND_BOT:-0}" -gt "${BAND_TOP:-0}" ]; then
BAND_H=$((BAND_BOT - BAND_TOP + 1))
fi
note "band_top=$BAND_TOP band_bottom=$BAND_BOT line_h~$BAND_H"
# (c2) Step Over (F10) -> line 16, scope still main, locals still correct.
DISPLAY="$XDISP" xdotool windowfocus --sync "$DW" key F10 2>/dev/null
if wait_dump "^paused_line=17" 15; then pass "step-over-moves-paused-line-to-17"; else fail "step-over-moves-paused-line-to-17"; cat "$WORK/dump.txt" 2>/dev/null; fi
dump_has "main()" && pass "scope-still-main-after-step" || fail "scope-still-main-after-step"
sleep 1
DISPLAY="$XDISP" xdotool windowraise "$CW" 2>/dev/null
sleep 0.5
DISPLAY="$XDISP" import -window "$CW" "$WORK/shot_stepped.png" 2>/dev/null
RED_STEP=$(count_red "$WORK/shot_stepped.png" 150 10000)
[ "${RED_STEP:-0}" -ge 500 ] && pass "red-band-follows-step" || fail "red-band-follows-step (red=$RED_STEP)"
# (d2) Continue (F5) -> target exits, red background clears.
DISPLAY="$XDISP" xdotool windowfocus --sync "$DW" key F5 2>/dev/null
if wait_dump "^state=Exited" 15; then pass "continue-exits-target"; else fail "continue-exits-target"; cat "$WORK/dump.txt" 2>/dev/null; fi
dump_has "^paused_line=0" && pass "paused-line-clears-on-resume" || fail "paused-line-clears-on-resume"
sleep 1
DISPLAY="$XDISP" xdotool windowraise "$CW" 2>/dev/null
sleep 0.5
DISPLAY="$XDISP" import -window "$CW" "$WORK/shot_exited.png" 2>/dev/null
RED_EXIT_TEXT=$(count_red "$WORK/shot_exited.png" 150 10000)
RED_EXIT_GUTTER=$(count_red "$WORK/shot_exited.png" 0 110)
note "exited screenshot: red_text=$RED_EXIT_TEXT red_gutter=$RED_EXIT_GUTTER"
[ "${RED_EXIT_TEXT:-9999}" -lt 200 ] && pass "red-band-clears-on-resume" || fail "red-band-clears-on-resume (red=$RED_EXIT_TEXT)"
# (b) the debugger-set breakpoint dot is still drawn in the gutter.
[ "${RED_EXIT_GUTTER:-0}" -ge 20 ] && pass "breakpoint-dot-still-drawn" || fail "breakpoint-dot-still-drawn (gutter_red=$RED_EXIT_GUTTER)"
# (b2) Gutter click stages a breakpoint in the backend: line 14 is two
# lines above the (old) paused line 16. Click the gutter dot zone.
if [ "${BAND_H:-0}" -gt 5 ] && [ "${BAND_TOP:- -1}" -ge 0 ]; then
GEOM=$(DISPLAY="$XDISP" xdotool getwindowgeometry --shell "$CW" 2>/dev/null)
SHOT_H=$(python3 -c "from PIL import Image; print(Image.open('$WORK/shot_paused.png').size[1])")
WIN_H=$(echo "$GEOM" | sed -n 's/^HEIGHT=//p')
TITLE_OFF=0
if [ -n "$SHOT_H" ] && [ -n "$WIN_H" ] && [ "$SHOT_H" -gt "$WIN_H" ]; then
TITLE_OFF=$((SHOT_H - WIN_H))
fi
Y16=$(( (BAND_TOP + BAND_BOT) / 2 - TITLE_OFF ))
Y14=$(( Y16 - 2 * BAND_H ))
note "gutter-click geometry: win_h=$WIN_H shot_h=$SHOT_H title_off=$TITLE_OFF y16=$Y16 y14=$Y14"
BPS="$WORK/homeA/.config/fdesigner/debugger_bps.conf"
GUT_OK=0
for TRY in 0 1 2; do
case $TRY in
0) YY=$Y14;;
1) YY=$((Y14 - BAND_H));;
2) YY=$((Y14 + BAND_H));;
esac
DISPLAY="$XDISP" xdotool windowraise "$CW" windowfocus --sync "$CW" mousemove --window "$CW" 40 "$YY" click 1 2>/dev/null
sleep 1
if grep -q "prog.c:14|" "$BPS" 2>/dev/null; then GUT_OK=1; break; fi
# Wrong line? remove whatever that click staged, then retry.
if grep -q "prog.c:" "$BPS" 2>/dev/null; then
DISPLAY="$XDISP" xdotool windowraise "$CW" windowfocus --sync "$CW" mousemove --window "$CW" 40 "$YY" click 1 2>/dev/null
sleep 1
fi
done
if [ "$GUT_OK" = "1" ]; then
pass "gutter-click-stages-breakpoint (prog.c:14 in bps conf)"
# Click again: the breakpoint must go away.
DISPLAY="$XDISP" xdotool windowraise "$CW" windowfocus --sync "$CW" mousemove --window "$CW" 40 "$YY" click 1 2>/dev/null
sleep 1
grep -q "prog.c:14|" "$BPS" 2>/dev/null && fail "gutter-click-removes-breakpoint" || pass "gutter-click-removes-breakpoint"
else
fail "gutter-click-stages-breakpoint"
grep "prog.c:" "$BPS" 2>/dev/null | sed 's/^/ bps: /' || note "no bps conf"
fi
else
fail "gutter-click-stages-breakpoint (no band geometry)"
fi
kill_app
# === Run B: breakpoint in helper — scope must change =======================
say "== Run B: breakpoint in helper (prog.c:11) =="
launch "$WORK/prog" "$WORK/prog.c:11" "$WORK/homeB"
wait_win codewin 20 || fail "runB-code-window-opens"
if wait_dump "^state=Stopped" 20; then pass "runB-stops-at-breakpoint"; else fail "runB-stops-at-breakpoint"; fi
dump_has "^paused_line=11" && pass "runB-paused-line-11" || fail "runB-paused-line-11"
dump_has "helper()" && pass "scope-is-helper" || fail "scope-is-helper"
dump_has "^var=x|int|42" && pass "runB-local-x-42" || fail "runB-local-x-42"
dump_has "^var=y|double|3.5" && pass "runB-local-y-3.5" || fail "runB-local-y-3.5"
dump_has "^var=z|int|44" && pass "runB-local-z-44" || fail "runB-local-z-44"
dump_has "^var=a|" && fail "runB-no-main-locals-leak" || pass "runB-no-main-locals-leak"
note "dump run B:"; sed 's/^/ dump: /' "$WORK/dump.txt" 2>/dev/null
kill_app
# === Run C: spinning target — "running", never stale =======================
say "== Run C: spinning target, no breakpoint =="
launch "$WORK/spin" "" "$WORK/homeC"
wait_win codewin 20 || fail "runC-code-window-opens"
if wait_dump "^state=Running" 20; then pass "running-state-shown"; else fail "running-state-shown"; cat "$WORK/dump.txt" 2>/dev/null; fi
dump_has "^paused_line=0" && pass "runC-no-paused-line" || fail "runC-no-paused-line"
if grep -q "^var=" "$WORK/dump.txt" 2>/dev/null; then fail "runC-no-stale-values"; else pass "runC-no-stale-values"; fi
note "dump run C:"; sed 's/^/ dump: /' "$WORK/dump.txt" 2>/dev/null
# (f) close the code window: app must survive; View -> Code View reopens.
CW=$(codewin_id); MW=$(mainwin_id)
DISPLAY="$XDISP" xdotool windowclose "$CW" 2>/dev/null
sleep 1
if kill -0 $APP 2>/dev/null && [ -n "$(mainwin_id)" ]; then
pass "close-code-window-keeps-app-alive"
else
fail "close-code-window-keeps-app-alive"
fi
[ -z "$(codewin_id)" ] && pass "code-window-actually-closed" || fail "code-window-actually-closed"
DISPLAY="$XDISP" xdotool windowfocus --sync "$MW" key F10 Right Right Down Return 2>/dev/null
if wait_win codewin 10; then
pass "view-menu-reopens-code-window"
else
# Fallback: click the View menu, then its first item.
GEOM=$(DISPLAY="$XDISP" xdotool getwindowgeometry --shell "$MW" 2>/dev/null)
WX=$(echo "$GEOM" | sed -n 's/^X=//p'); WY=$(echo "$GEOM" | sed -n 's/^Y=//p')
DISPLAY="$XDISP" xdotool windowraise "$MW" mousemove --window "$MW" 130 12 click 1 2>/dev/null
sleep 0.7
DISPLAY="$XDISP" xdotool mousemove --window "$MW" 140 55 click 1 2>/dev/null
if wait_win codewin 10; then pass "view-menu-reopens-code-window (click fallback)"; else fail "view-menu-reopens-code-window"; fi
fi
kill_app
kill $XVPID 2>/dev/null
trap - EXIT
if [ "$FAIL" = "0" ]; then say "CODE-WINDOW TESTS: ALL PASS"; else say "CODE-WINDOW TESTS: FAILURES (see above)"; fi
exit "$FAIL"
+39
View File
@@ -0,0 +1,39 @@
#!/usr/bin/env python3
"""Count red-ish pixels in a screenshot (the paused-line band is
#c00000, breakpoint dots are the same red).
Usage: count_red.py <png> [x0 x1] [band]
Prints the red pixel count in columns [x0, x1).
With "band": also prints the top/bottom row of the densest run of
rows that each contain >100 red pixels (the full-line paused band),
as band_top=.. band_bottom=.. band_rows=..
"""
import sys
from PIL import Image
im = Image.open(sys.argv[1]).convert("RGB")
px = im.load()
w, h = im.size
x0 = int(sys.argv[2]) if len(sys.argv) > 2 else 0
x1 = int(sys.argv[3]) if len(sys.argv) > 3 else w
x1 = min(x1, w)
n = 0
band_rows = []
for y in range(h):
row = 0
for x in range(x0, x1):
r, g, b = px[x, y]
if r > 150 and g < 70 and b < 70:
n += 1
row += 1
if row > 100:
band_rows.append(y)
print(n)
if len(sys.argv) > 4 and sys.argv[4] == "band":
if band_rows:
print("band_top=%d band_bottom=%d band_rows=%d"
% (band_rows[0], band_rows[-1], len(band_rows)))
else:
print("band_top=-1 band_bottom=-1 band_rows=0")
+19
View File
@@ -0,0 +1,19 @@
// FDesigner code-window test target: known locals in two scopes.
// Compile with: gcc -g -O0 -o prog prog.c (from the work dir, so the
// DWARF paths match the FDESIGNER_DEBUG_BREAK locations used by
// tests/code_window_tests.sh). Line numbers are load-bearing:
// main: a=42 at line 14, msg="hello" at line 15
// helper: x=42, y=3.5, z=44 at line 11 (return)
#include <stdio.h>
static int helper(int x) {
double y = 3.5;
int z = x + 2;
return z;
}
int main(void) {
int a = 42;
const char *msg = "hello";
int r = helper(a);
printf("%d %s\n", r, msg);
return 0;
}
+1 -1
View File
@@ -60,7 +60,7 @@ else
FOUND=""
i=0
while [ $i -lt 50 ]; do
FOUND=$(xdotool search --name "Code - generated C\+\+" 2>/dev/null | head -1)
FOUND=$(xdotool search --name "FDesigner — Code" 2>/dev/null | head -1)
[ -n "$FOUND" ] && break
sleep 0.2; i=$((i+1))
done
+1 -1
View File
@@ -108,7 +108,7 @@
<property name="visible">True</property>
<child>
<object class="GtkMenuItem" id="mi_view_code">
<property name="label">Code View…</property>
<property name="label">Code View</property>
<property name="visible">True</property>
</object>
</child>