summaryrefslogtreecommitdiff
path: root/src/trace/debugger_test.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-10 16:03:43 -0300
committerGabriel Schneider <[email protected]>2026-11-10 16:05:20 -0300
commit66a2a7cf733f6abc1f79561c52d901ce67019fb1 (patch)
treeb261d533887b37fb5287ad384d4f845348b35d81 /src/trace/debugger_test.zig
parente0c4bfcc0395a561804e33942028c519f4e267f7 (diff)
downloadcomputeranim-66a2a7cf733f6abc1f79561c52d901ce67019fb1.tar.gz
computeranim-66a2a7cf733f6abc1f79561c52d901ce67019fb1.zip
trace: what the context draws is in the recording; SQLite on the ladder
An instruction's string carries its source line and, for a direct call, how many parameters the callee takes (DWARF); telescope.frames gives each frame's extent on the stack; with --alloc the debugger watches each live allocation and the allocator's header before it, changes only, 256 KiB a stop at most. C++ names are shown and found as the source has them (the command links the C++ runtime for its demangler). SQLite 3.50.4 through every backend, measured (README, bench/sqlite.sh). It found two faults: a file compiled by its full path was recorded under a path joined onto the compile directory, and ztrace run noticed a target's exit up to 10 ms late. Co-Authored-By: Claude Fable 5.2 <[email protected]>
Diffstat (limited to 'src/trace/debugger_test.zig')
-rw-r--r--src/trace/debugger_test.zig35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/trace/debugger_test.zig b/src/trace/debugger_test.zig
index e1191a9..bfee1d6 100644
--- a/src/trace/debugger_test.zig
+++ b/src/trace/debugger_test.zig
@@ -97,6 +97,41 @@ test "a breakpoint on fib is hit once a call, in a position-independent executab
try std.testing.expectEqual(@as(u8, 0), code);
}
+test "DWARF says how many parameters a function takes" {
+ var d = try spawn(targets.list, "2", null);
+ defer d.deinit();
+ for ([_][]const u8{ "push", "reverse", "list_done", "main" }, [_]u8{ 2, 1, 1, 2 }) |name, n| {
+ try std.testing.expectEqual(@as(?u8, n), d.syms.parameters(d.symbol(name).?.addr));
+ }
+ // Only where a function begins; nor in a library without debug info.
+ try std.testing.expectEqual(@as(?u8, null), d.syms.parameters(d.symbol("push").?.addr + 1));
+ try std.testing.expectEqual(@as(?u8, null), d.syms.parameters(d.regs.rip));
+}
+
+test "a recording by `ztrace record` has the line of each instruction round the pc, and a call's parameters" {
+ var trace = try zt.Trace.open(gpa, io, targets.fib_recording);
+ defer trace.close();
+ // The first stop at the breakpoint on fib, and the instructions from there.
+ const m, const pc = find: for (0..trace.len) |i| {
+ const m = try trace.moment(i);
+ var events = try m.events(gpa);
+ defer events.deinit(gpa);
+ while (events.next()) |item| if (item.ev.kind == .breakpoint) break :find .{ m, item.ev.a[0] };
+ } else return error.NoBreakpoint;
+ var text: [256]u8 = undefined;
+ const here = (try zt.telescope.instruction(m, pc, &text)).?;
+ try std.testing.expectEqual(@as(u32, 4), here.line.?.line);
+ var name: [std.Io.Dir.max_path_bytes]u8 = undefined;
+ try std.testing.expect(std.mem.endsWith(u8, (try m.string(here.line.?.file, &name)).?, "fib.c"));
+ // fib calls itself once (-O1 made the other call a loop): with its one parameter.
+ var at = pc;
+ const call = while (try zt.telescope.instruction(m, at, &text)) |insn| : (at += insn.len) {
+ if (std.mem.startsWith(u8, insn.text, "call")) break insn;
+ } else return error.NoCall;
+ try std.testing.expectEqual(@as(?u8, 1), call.params);
+ try std.testing.expectEqual(@as(u32, 5), call.line.?.line);
+}
+
test "step walks the source lines, in and out of calls, as gdb does" {
var d = try spawn(targets.list, "2", null);
defer d.deinit();