summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/cli/record.zig5
-rw-r--r--src/trace/Debugger.zig21
2 files changed, 18 insertions, 8 deletions
diff --git a/src/cli/record.zig b/src/cli/record.zig
index 91b17d2..8f002f4 100644
--- a/src/cli/record.zig
+++ b/src/cli/record.zig
@@ -30,12 +30,13 @@ pub const usage =
\\prints them, a line each.
\\Of memory, only what is asked for is recorded, and of that the words
\\that changed since the stop before: the --stack bytes above the stack
- \\pointer (default 128) and each -w region, an address or a symbol, as
+ \\pointer (default 128; and the 128 under it) and each -w region, an address or a symbol, as
\\long as the symbol unless LEN says.
\\At every stop the registers and the top of the stack are also followed
\\as pointers, --telescope deep (default 3, 0 for not at all): what they
\\lead to is recorded with --around bytes each side of it (default 0:
- \\the 32 at the place), code they lead to is named, and the instructions
+ \\the 32 at the place; what an instruction reads or writes likewise),
+ \\code they lead to is named, and the instructions
\\at the pc are disassembled, --disasm rows above it and below (default
\\8), so that a viewer can show what pwndbg's context shows.
\\--steps ends the recording after N moments, and --max-size when the
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;