diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-10 23:55:42 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-11 00:06:30 -0300 |
| commit | c94ade9e77a811d3ff75ffc2889a65375262ab1f (patch) | |
| tree | cd6e1da77cae54dc1ff4c35ee9d9262549819770 /src/trace/telescope.zig | |
| parent | 81d97a9e38c740a96af13a8a981878947a508bc0 (diff) | |
| download | computeranim-c94ade9e77a811d3ff75ffc2889a65375262ab1f.tar.gz computeranim-c94ade9e77a811d3ff75ffc2889a65375262ab1f.zip | |
trace: names for PLT stubs and GOT slots; a call followed down; the vDSO is run through
For a disassembly that follows a call into libc. A stub is open@plt and a
slot open@got, from the relocations (libc's own, IFUNC and nameless, by
the function they resolve to); telescope.got says what a slot holds and
whether it is still lazy. A library function's entry is named even when
its mapping was not known yet, by the alias the program imports. The
chain holds through the stub's jump, the callee's first instruction, the
syscall and the loader's resolver: ld.so's unwind section lacks the entry
that ends it, which lost every frame there. A syscall is tied to its
instruction's moment, and each frame's call is recorded with the row
before it. Stepped by instruction, a call into the vDSO is one moment and
its return the next: its clock loop, single-stepped, made three million
moments of three reads.
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNCKgYCGiANnEwcEQxa
Diffstat (limited to 'src/trace/telescope.zig')
| -rw-r--r-- | src/trace/telescope.zig | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/src/trace/telescope.zig b/src/trace/telescope.zig index 61736fd..6ab2929 100644 --- a/src/trace/telescope.zig +++ b/src/trace/telescope.zig @@ -254,10 +254,14 @@ const Memory = struct { } }; -/// A function's frame as the recording has it (`Debugger.emitFunction`): -/// its rows and its locals, each end to end. -const Function = struct { +/// A function's frame as the recording has it (`Debugger.emitFunction`), +/// for every function a recorded walk went through (each frame's): where +/// it begins and how long it is, by its call frame information (a PLT +/// entry's 16 bytes for a stub); what its locals are from +/// (`Symbols.Function.base`); its rows and its locals, each end to end. +pub const Function = struct { start: u64, + len: u64, base: u8, rows: []const u8, locals: []const u8, @@ -276,7 +280,7 @@ const Function = struct { }; /// The recorded frame of the function that holds `pc`. -fn function(m: Moment, pc: u64) ?Function { +pub fn function(m: Moment, pc: u64) ?Function { const found = m.trace.stringBelow(event.frameId(pc)) orelse return null; // Below every function recorded is another kind of string, or the process's start. if (found.id < event.frameId(1)) return null; @@ -284,8 +288,25 @@ fn function(m: Moment, pc: u64) ?Function { if (t.len < 7) return null; const start = found.id - event.frameId(0); const rows = @as(usize, std.mem.readInt(u16, t[5..7], .little)) * @sizeOf(Symbols.Row); - if (pc - start >= std.mem.readInt(u32, t[0..4], .little) or rows == 0 or t.len < 7 + rows) return null; - return .{ .start = start, .base = t[4], .rows = t[7..][0..rows], .locals = t[7 + rows ..] }; + const len = std.mem.readInt(u32, t[0..4], .little); + if (pc - start >= len or rows == 0 or t.len < 7 + rows) return null; + return .{ .start = start, .len = len, .base = t[4], .rows = t[7..][0..rows], .locals = t[7 + rows ..] }; +} + +/// A GOT slot at a moment: what it holds, and whether that is still the way +/// back into the PLT (`lazy`: the next call through it runs the loader's +/// resolver, which binds it) rather than the function. Null where the +/// recording does not have the slot's word; `lazy` null where it has no +/// name for what the word holds. The slot's own name is `open@got` +/// (`Moment.string` of its address), the stub's `open@plt`. +pub fn got(m: Moment, slot: u64) !?struct { value: u64, lazy: ?bool } { + var bytes: [8]u8 = undefined; + var known: [8]bool = undefined; + try m.read(slot, &bytes, &known); + if (std.mem.indexOfScalar(bool, &known, false) != null) return null; + const value = std.mem.readInt(u64, &bytes, .little); + const name = m.trace.strings.get(value) orelse return .{ .value = value, .lazy = null }; + return .{ .value = value, .lazy = std.mem.indexOf(u8, name, "@plt") != null }; } /// At a function's first instruction its frame is not made yet: the @@ -479,7 +500,7 @@ test "frames walked by their call frame information; each stack word's role" { }, try frames(m, ®s, &out)); var words: [16]Slot = undefined; - const got = try slots(m, ®s, 0x7ff100, &words); + const roles = try slots(m, ®s, 0x7ff100, &words); const local = struct { fn of(name: []const u8, size: u32, offset: i32) Role { return .{ .local = .{ .name = name, .size = size, .offset = offset } }; @@ -493,7 +514,7 @@ test "frames walked by their call frame information; each stack word's role" { .{ .{ .argv = 0 }, null }, .{ .{ .argv = 1 }, null }, .{ .{ .envp = 0 }, null }, .{ .{ .envp = 1 }, null }, }; - for (want, got) |w, have| { + for (want, roles) |w, have| { try std.testing.expectEqual(w[1], have.frame); try std.testing.expectEqual(std.meta.activeTag(w[0]), std.meta.activeTag(have.role)); switch (w[0]) { |
