diff options
Diffstat (limited to 'src/trace')
| -rw-r--r-- | src/trace/Debugger.zig | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/src/trace/Debugger.zig b/src/trace/Debugger.zig index bdcc4cc..da7a73b 100644 --- a/src/trace/Debugger.zig +++ b/src/trace/Debugger.zig @@ -93,9 +93,9 @@ 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. +/// The bytes recorded each side of a place the telescope reaches (beside +/// the 32 at it) or an instruction touches, 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. @@ -479,7 +479,8 @@ fn report(d: *Debugger, stop: Stop) !Stop { if (d.sink == null) return stop; if (!d.done) { try d.emitLine(); - if (d.stack_watch > 0) try d.snapshot(d.regs.rsp, d.stack_watch); + // With the 128 bytes under the stack pointer: the red zone, a leaf's locals. + if (d.stack_watch > 0) try d.snapshot(d.regs.rsp -| 128, d.stack_watch + 128); for (d.watches.items) |w| try d.snapshot(w.addr, w.len); for (d.declared.items) |w| try d.snapshot(w.addr, w.len); try d.snapshotAllocations(); @@ -490,12 +491,20 @@ fn report(d: *Debugger, stop: Stop) !Stop { return stop; } +/// `snapshot` of what an instruction touches, with the region round it +/// (`telescope_around`) as far as its mapping goes. +fn snapshotRound(d: *Debugger, addr: u64, size: usize) !void { + const m = d.syms.mappingAt(addr) orelse return d.snapshot(addr, size); + const lo = @max(m.start, addr -| d.telescope_around); + try d.snapshot(lo, @min(m.end, addr + size + d.telescope_around) - lo); +} + /// The instructions at the pc and after it, each a string (`event.codeId`) /// recorded once: what a viewer shows as the disassembly. fn emitCode(d: *Debugger) !void { const insnAt = d.disasm orelse return; // What the instruction before wrote is there to read now. - for (d.written[0..d.written_count]) |t| try d.snapshot(t.addr, t.size); + for (d.written[0..d.written_count]) |t| try d.snapshotRound(t.addr, t.size); d.written_count = 0; var code: [256]u8 = undefined; var text: [192]u8 = undefined; @@ -506,7 +515,7 @@ fn emitCode(d: *Debugger) !void { var touches: [2]Touch = undefined; if (insnAt(code[0..15], d.regs.rip, text[1..], &d.regs, &touches)) |insn| { for (insn.touches) |t| { - try d.snapshot(t.addr, t.size); + try d.snapshotRound(t.addr, t.size); try d.emit(.{ .kind = .touch, .aux = t.how, .a = .{ t.addr, t.size, d.regs.rip, 0, 0, 0 } }, ""); if (t.how & 2 != 0) { d.written[d.written_count] = t; |
