diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-10 23:04:17 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-10 23:25:40 -0300 |
| commit | 58643dab07a803dbb579d84f68419911f5a2a16d (patch) | |
| tree | b97c9ab4f5ccd27448ecb609ea8879a42a8fe992 /src/cli/show.zig | |
| parent | b4ab1d770edb06d3eeebfd290bbf97725e55b7fa (diff) | |
| download | computeranim-58643dab07a803dbb579d84f68419911f5a2a16d.tar.gz computeranim-58643dab07a803dbb579d84f68419911f5a2a16d.zip | |
trace: glibc's heap, read from a recording at any moment
record --heap keeps the arena, the tcache and, of every chunk, its size
word and the links of those on a list: free chunks stay readable, which
--alloc dropped at the free. zt.heap.glibc gives the chunks in address
order, the tcache's and the bins' chains (safe-linking as the stored
value and the pointer it protects), the top; each with the address of
the word it was read from, each chain saying how it ended. ztrace show
prints it. Layouts for glibc 2.44 (no fastbins; a tcache made at the
first free, counting the slots left) and 2.40; the arena found by symbol
or by the struct whose next points at itself. Against pwndbg on 2.40:
the same at every stop. Three bytes a moment and a sixth slower on the
list by instruction.
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNCKgYCGiANnEwcEQxa
Diffstat (limited to 'src/cli/show.zig')
| -rw-r--r-- | src/cli/show.zig | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/cli/show.zig b/src/cli/show.zig index 1657644..7019113 100644 --- a/src/cli/show.zig +++ b/src/cli/show.zig @@ -11,7 +11,10 @@ pub const usage = \\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 - \\the open calls; then the live heap, the named variables with their + \\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 + \\allocations, the named variables with their \\bytes, and the mapped regions. On a terminal a pointer is coloured by \\where it points: code red, stack yellow, heap blue, data purple, \\writable-and-executable underlined. @@ -140,6 +143,12 @@ pub fn state(arena: std.mem.Allocator, trace: *zt.Trace, index: u64, w: *std.Io. } } + // glibc's heap (`record --heap`), with the tcache of the thread that stopped. + var last_tid: u32 = 0; + var events = try m.events(arena); + while (events.next()) |item| last_tid = item.ev.tid; + if (try zt.heap.glibc(arena, m, last_tid)) |h| try zt.heap.print(h, w); + const heap = try m.heap(arena); if (heap.len > 0) try w.print("\nheap: {d} live\n", .{heap.len}); for (heap) |a| try w.print(" {x:0>12} {d:>8} bytes, by {x}, event {d}\n", .{ a.ptr, a.size, a.pc, a.born }); |
