From 66a2a7cf733f6abc1f79561c52d901ce67019fb1 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 10 Nov 2026 16:03:43 -0300 Subject: 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 --- src/trace/debugger_test.zig | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'src/trace/debugger_test.zig') 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(); -- cgit v1.3