From 8beab959b633e6641d07aba053a55e6e8e61eb00 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 10 Nov 2026 11:58:00 -0300 Subject: targets, test-debugger, bench-debugger A linked list, a graph search in Zig, the same C under glibc and musl, two threads. The tests drive the debugger over them: breakpoint counts, the lines a step walks (as gdb), a list snapshotted by a hook, a watch's words, the syscalls that tell glibc from musl, threads, attach, and scripted dbg and record sessions. The bench measures steps, stops and memory access from bare ptrace up to a recording. Co-Authored-By: Claude Fable 5.2 --- targets/graph.zig | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 targets/graph.zig (limited to 'targets/graph.zig') diff --git a/targets/graph.zig b/targets/graph.zig new file mode 100644 index 0000000..987eaa5 --- /dev/null +++ b/targets/graph.zig @@ -0,0 +1,41 @@ +//! A small graph and a breadth-first search over it. `dist` and `queue` are +//! exported globals, so a tracer finds them by name and watches them fill. +//! Exits with the sum of the distances from node 0 (18). +const n = 8; +const unreached = 0xff; + +const edges = [_][2]u8{ .{ 0, 1 }, .{ 0, 2 }, .{ 1, 3 }, .{ 2, 3 }, .{ 3, 4 }, .{ 4, 5 }, .{ 5, 6 }, .{ 2, 7 } }; + +/// Aligned so that it is one machine word to a watcher. +export var dist: [n]u8 align(8) = @splat(unreached); +export var queue: [n]u8 = @splat(0); + +fn linked(a: u8, b: u8) bool { + for (edges) |e| { + if ((e[0] == a and e[1] == b) or (e[0] == b and e[1] == a)) return true; + } + return false; +} + +fn bfs(start: u8) void { + var head: usize = 0; + var tail: usize = 1; + queue[0] = start; + dist[start] = 0; + while (head < tail) : (head += 1) { + const at = queue[head]; + for (0..n) |next| { + if (dist[next] != unreached or !linked(at, @intCast(next))) continue; + dist[next] = dist[at] + 1; + queue[tail] = @intCast(next); + tail += 1; + } + } +} + +pub fn main() u8 { + bfs(0); + var sum: u8 = 0; + for (dist) |d| sum += d; + return sum; +} -- cgit v1.3