summaryrefslogtreecommitdiff
path: root/src/trace
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-10 22:02:01 -0300
committerGabriel Schneider <[email protected]>2026-11-10 22:02:01 -0300
commit36bb1c332a124cb4d437dd8386b267ee58310a5d (patch)
treec6760488e17ab443c63b730e6ec70ed43a010634 /src/trace
parent0a13f5210756e5a42ebf983943d87a1922cda0e3 (diff)
downloadcomputeranim-36bb1c332a124cb4d437dd8386b267ee58310a5d.tar.gz
computeranim-36bb1c332a124cb4d437dd8386b267ee58310a5d.zip
record: how much of the context a stop keeps is asked for
--around BYTES of memory each side of what a pointer leads to, for a viewer that shows the region and not the word; --disasm ROWS above and below the pc; and every word of the --stack bytes is followed as a pointer, not the first sixteen. Co-Authored-By: Claude Fable 5.2 <[email protected]>
Diffstat (limited to 'src/trace')
-rw-r--r--src/trace/Debugger.zig11
-rw-r--r--src/trace/debugger_test.zig25
2 files changed, 33 insertions, 3 deletions
diff --git a/src/trace/Debugger.zig b/src/trace/Debugger.zig
index a38c337..bdcc4cc 100644
--- a/src/trace/Debugger.zig
+++ b/src/trace/Debugger.zig
@@ -93,6 +93,10 @@ functions: std.AutoHashMapUnmanaged(u64, []const u32) = .empty,
/// default: not at all (the commands ask for 3).
telescope: u8 = 0,
telescope_words: usize = 16,
+/// The bytes recorded each side of a place the telescope reaches, beside
+/// the 32 at it and no further than its mapping: the region a viewer
+/// shows round what a pointer leads to.
+telescope_around: usize = 0,
/// The addresses already named, and the instructions already recorded
/// with the length of each.
described: std.AutoHashMapUnmanaged(u64, void) = .empty,
@@ -605,7 +609,7 @@ fn emitTelescope(d: *Debugger) !void {
if (d.telescope == 0) return;
const r = &d.regs;
for ([_]u64{ r.rip, r.rax, r.rbx, r.rcx, r.rdx, r.rsi, r.rdi, r.rbp, r.rsp, r.r8, r.r9, r.r10, r.r11, r.r12, r.r13, r.r14, r.r15 }) |value| try d.chase(value);
- var words: [64]u64 = undefined;
+ var words: [256]u64 = undefined;
const n = d.read(r.rsp, std.mem.sliceAsBytes(words[0..@min(words.len, d.telescope_words)])) / 8;
for (words[0..n]) |value| try d.chase(value);
// The call chain: each frame's saved pointer and return address
@@ -651,8 +655,9 @@ fn chase(d: *Debugger, value: u64) !void {
const m = d.syms.mappingAt(v) orelse return;
if (m.prot & 1 == 0) return;
if (m.prot & 4 != 0) return d.nameAddress(v);
- const bytes = try d.snap(v, 32);
- const off: usize = @intCast(v & 7);
+ const lo = @max(m.start, v -| d.telescope_around) & ~@as(u64, 7);
+ const bytes = try d.snap(lo, @min(m.end, v + 32 + d.telescope_around) - lo);
+ const off: usize = @intCast(v - lo);
if (bytes.len < off + 8) return;
v = std.mem.readInt(u64, bytes[off..][0..8], .little);
}
diff --git a/src/trace/debugger_test.zig b/src/trace/debugger_test.zig
index 512dc6f..5d43d8c 100644
--- a/src/trace/debugger_test.zig
+++ b/src/trace/debugger_test.zig
@@ -173,6 +173,31 @@ test "step walks the source lines, in and out of calls, as gdb does" {
try std.testing.expectEqualStrings("main", d2.syms.symbolAt(chain[1]).?.name);
}
+test "the telescope records the region round what a pointer leads to" {
+ var log: Log = .{};
+ defer log.deinit();
+ var d = try spawn(targets.list, "3", log.sink());
+ defer d.deinit();
+ d.telescope = 1;
+ d.telescope_around = 16;
+ // The heap is a mapping the debugger learns of from the program's brk.
+ d.syscalls = .record;
+ // At `list_done(head)`: rdi leads to a node on the heap, malloc's header before it.
+ _ = try d.breakAt(try d.resolve("list_done"), null);
+ _ = try d.cont();
+ const node = d.regs.rdi;
+ // Sixteen bytes before it to sixteen past its 32, in however many writes.
+ var seen: u64 = 0;
+ for (log.events.items) |e| {
+ if (e.ev.kind != .mem_write) continue;
+ for (0..64) |i| {
+ const at = node - 16 + i;
+ if (at >= e.ev.a[0] and at < e.ev.a[0] + e.payload.len) seen |= @as(u64, 1) << @intCast(i);
+ }
+ }
+ try std.testing.expectEqual(~@as(u64, 0), seen);
+}
+
test "a hook snapshots the linked list; the recording's last moment has what the program built" {
var tmp = std.testing.tmpDir(.{});
defer tmp.cleanup();