summaryrefslogtreecommitdiff
path: root/src/trace/telescope.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/trace/telescope.zig')
-rw-r--r--src/trace/telescope.zig37
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, &regs, &out));
var words: [16]Slot = undefined;
- const got = try slots(m, &regs, 0x7ff100, &words);
+ const roles = try slots(m, &regs, 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]) {