summaryrefslogtreecommitdiff
path: root/src/cli/show.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/cli/show.zig')
-rw-r--r--src/cli/show.zig40
1 files changed, 36 insertions, 4 deletions
diff --git a/src/cli/show.zig b/src/cli/show.zig
index 032538f..e7c552c 100644
--- a/src/cli/show.zig
+++ b/src/cli/show.zig
@@ -10,7 +10,9 @@ pub const usage =
\\With one (negative counts from the end), the context as of that moment,
\\pwndbg's way: each thread's registers, every one followed as far as it
\\points (a name for code, a string where there is one), the instructions
- \\at the pc, the top of the stack followed likewise, the source line and
+ \\at the pc, the top of the stack followed likewise, each word with what
+ \\it is where the recording says (saved rbp, return address, a local by
+ \\name, the canary's copy, argv[1]), the source line and
\\the open calls; then glibc's heap when it was recorded (record --heap:
\\its chunks, the tcache and the bins, each chunk on a list followed by its
\\link as stored, in brackets, where safe-linking changed it), the live
@@ -82,6 +84,34 @@ fn telescope(m: zt.store.Moment, w: *std.Io.Writer, value: u64, colour: bool) !v
}
}
+/// What a stack word is (`zt.telescope.slots`), after its chain: `saved
+/// rbp`, `return address`, a local by name (`buf+8` a word into it, `i[0..4],
+/// n[4..8]` where it fills part of the word), `argv[1]`; nothing where the
+/// recording does not say. `word` is what it holds: 0 ends argv and envp.
+fn role(w: *std.Io.Writer, slot: zt.telescope.Slot, word: u64, colour: bool) !void {
+ if (slot.role == .none) return;
+ try w.writeAll(if (colour) " \x1b[2m" else " ");
+ switch (slot.role) {
+ .none => {},
+ .saved => |reg| try w.print("saved {s}", .{reg}),
+ .return_address => try w.writeAll("return address"),
+ .local => |first| for ([_]?zt.telescope.Local{first} ++ slot.also, 0..) |each, i| {
+ const l = each orelse break;
+ if (i > 0) try w.writeAll(", ");
+ try w.writeAll(l.name);
+ if (l.offset > 0) try w.print("+{x}", .{l.offset});
+ const from: i64 = @max(0, -l.offset);
+ const to: i64 = if (l.size == 0) 8 else @min(8, @as(i64, l.size) - l.offset);
+ if (from > 0 or to < 8) try w.print("[{d}..{d}]", .{ from, to });
+ },
+ .argc => try w.writeAll("argc"),
+ .argv => |i| if (word == 0) try w.writeAll("argv end") else try w.print("argv[{d}]", .{i}),
+ .envp => |i| if (word == 0) try w.writeAll("envp end") else try w.print("envp[{d}]", .{i}),
+ .auxv => |i| try w.print("auxv[{d}]", .{i}),
+ }
+ if (colour) try w.writeAll("\x1b[0m");
+}
+
pub fn state(arena: std.mem.Allocator, trace: *zt.Trace, index: u64, w: *std.Io.Writer, colour: bool) !void {
const m = try trace.moment(index);
try w.print("moment {d} of {d}, {d} events so far\n", .{ index, trace.len, try m.count() });
@@ -114,16 +144,18 @@ pub fn state(arena: std.mem.Allocator, trace: *zt.Trace, index: u64, w: *std.Io.
if (pc >= regs.rip) below += 1;
pc += insn.len;
}
- // The top of the stack, a word a row.
+ // The top of the stack, a word a row, and what each word is.
var words: [8]u64 = undefined;
var known: [64]bool = undefined;
try m.read(regs.rsp, std.mem.sliceAsBytes(&words), &known);
+ var slots: [8]zt.telescope.Slot = undefined;
+ _ = try zt.telescope.slots(m, &regs, regs.rsp, &slots);
if (known[0]) try w.writeAll("\n");
- for (words, 0..) |word, i| {
+ for (words, slots, 0..) |word, slot, i| {
if (!known[i * 8]) break;
try w.print(" {x:0>2}:{x:0>4}│ {s} ", .{ i, i * 8, if (i == 0) "rsp" else " " });
try telescope(m, w, regs.rsp + i * 8, colour);
- _ = word;
+ try role(w, slot, word, colour);
try w.writeAll("\n");
}
}