diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-10 13:36:32 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-10 14:12:08 -0300 |
| commit | 02aa51a6f54235cf18e627dbbfe21f21e502eb0b (patch) | |
| tree | a53416bdf0e5bb0ce80da63176fe13393c502a2c /src/trace/Symbols.zig | |
| parent | 16895292becf82f493aaced2b10f889bad436156 (diff) | |
| download | computeranim-02aa51a6f54235cf18e627dbbfe21f21e502eb0b.tar.gz computeranim-02aa51a6f54235cf18e627dbbfe21f21e502eb0b.zip | |
context: disassembly, telescopes and names in every stop; strings as one table
For a viewer to show what pwndbg's context shows, the debugger records it
while the memory is there: each register and the top of the stack followed
as pointers three deep (--telescope), every code address met named, eight
instructions from the pc disassembled by capstone (built from source for
x86, into the command only; pinned as in 03-codenomicom). zt.telescope
reads a chain back with the kind of memory each link points into, and
ztrace show prints the context, coloured on a terminal as pwndbg colours.
The thirty thousand strings of a small run showed that a string map in
each keyframe costs 700 bytes of tree a string: strings are now one table
for the recording, appended a batch and read whole at open. fib(12) by
instruction with everything on: 9 MB, 71 000 moments/s.
Diffstat (limited to 'src/trace/Symbols.zig')
| -rw-r--r-- | src/trace/Symbols.zig | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/trace/Symbols.zig b/src/trace/Symbols.zig index 7c1e345..ace4c41 100644 --- a/src/trace/Symbols.zig +++ b/src/trace/Symbols.zig @@ -351,15 +351,23 @@ pub fn lineAddress(s: *Symbols, file: []const u8, wanted: u32) ?u64 { /// `addr` for a reader: "fib+12 (fib.c:5)", "libc.so.6!write+18", /// "libc.so.6!27781" where no symbol covers it, "[stack]+1f40". pub fn describe(s: *Symbols, w: *std.Io.Writer, addr: u64) !void { - try w.print("{x}", .{addr}); + try w.print("{x} ", .{addr}); + if (!try s.label(w, addr)) w.undo(1); + if (s.lineAt(addr)) |l| try w.print(" ({s}:{d})", .{ std.fs.path.basename(l.name), l.line }); +} + +/// The name of `addr` alone: "fib+12", "libc.so.6!write+18", "[stack]+1f40". +/// False, and nothing written, for an address with none. +pub fn label(s: *Symbols, w: *std.Io.Writer, addr: u64) !bool { if (s.moduleAt(addr)) |m| { const sym = s.symbolAt(addr); - try w.writeAll(" "); // The executable is the first module mapped: its symbols need no prefix. if (sym == null or m != &s.modules.items[0]) try w.print("{s}!", .{std.fs.path.basename(m.path)}); if (sym) |found| try w.print("{s}+{d}", .{ found.name, addr - found.addr }) else try w.print("{x}", .{addr - m.bias}); - } else if (s.mappingAt(addr)) |m| { - if (m.name.len > 0) try w.print(" {s}+{x}", .{ m.name, addr - m.start }); + return true; } - if (s.lineAt(addr)) |l| try w.print(" ({s}:{d})", .{ std.fs.path.basename(l.name), l.line }); + const m = s.mappingAt(addr) orelse return false; + if (m.name.len == 0) return false; + try w.print("{s}+{x}", .{ m.name, addr - m.start }); + return true; } |
