diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-10 22:51:17 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-10 23:04:17 -0300 |
| commit | b4ab1d770edb06d3eeebfd290bbf97725e55b7fa (patch) | |
| tree | 75c0b876f4dde764e50e21c4faf9963887f63b44 /src/trace/store.zig | |
| parent | fa5d150ac6977264f0704e9af664f8150bd25127 (diff) | |
| download | computeranim-b4ab1d770edb06d3eeebfd290bbf97725e55b7fa.tar.gz computeranim-b4ab1d770edb06d3eeebfd290bbf97725e55b7fa.zip | |
trace: the call chain by the unwind tables; what each word of the stack is
backtrace and frames follow .debug_frame or .eh_frame where there is
one (PLT entries expanded into exact rows) and the frame pointer where
there is none: the caller is no longer lost in a prologue, in a function
that keeps no frame, in a PLT entry or inside libc's syscall wrappers.
Against gdb: the same chains on fib and on SQLite, where the old walk
lost __sbrk and unixSync.
A recording holds, once a function, its unwind rows and its locals on
the stack (DW_OP_fbreg, with the block each lives in), and the process's
first stack pointer. telescope.slots says of each word what it is: a
saved register and which, a return address, a local by name, argc, argv,
envp, auxv. Four bytes a moment on the list by instruction, and no
slower.
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNCKgYCGiANnEwcEQxa
Diffstat (limited to 'src/trace/store.zig')
| -rw-r--r-- | src/trace/store.zig | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/trace/store.zig b/src/trace/store.zig index 0b7e8fe..e4546c2 100644 --- a/src/trace/store.zig +++ b/src/trace/store.zig @@ -566,6 +566,8 @@ pub const Trace = struct { key_moments: []u64, /// Every string the recording defines, by id. strings: std.AutoHashMapUnmanaged(u64, []const u8) = .empty, + /// Their ids, in order: for `stringBelow`. + ids: []u64 = &.{}, strings_arena: std.heap.ArenaAllocator, cache: *Cache, @@ -618,6 +620,10 @@ pub const Trace = struct { } } } + t.ids = try t.strings_arena.allocator().alloc(u64, t.strings.count()); + var ids = t.strings.keyIterator(); + for (t.ids) |*id| id.* = ids.next().?.*; + std.mem.sortUnstable(u64, t.ids, {}, std.sort.asc(u64)); const root = try Map.init(db.rootCursor().readOnly()); if (try root.getCursor(key(.moments))) |cursor| t.len = try (try List.init(cursor)).count(); var key_moments: std.ArrayList(u64) = .empty; @@ -634,6 +640,20 @@ pub const Trace = struct { return t; } + /// The string with the greatest id at or below `id`, and that id: where + /// strings are keyed by where a range of addresses begins + /// (`event.frameId`), the one whose range may hold `id`. + pub fn stringBelow(t: *const Trace, id: u64) ?struct { id: u64, text: []const u8 } { + const after = std.sort.upperBound(u64, t.ids, id, struct { + fn order(want: u64, have: u64) std.math.Order { + return std.math.order(want, have); + } + }.order); + if (after == 0) return null; + const found = t.ids[after - 1]; + return .{ .id = found, .text = t.strings.get(found).? }; + } + fn root0(db: *ReadDB) Map { // An empty file has no root map yet: a map that holds nothing. return Map.init(db.rootCursor().readOnly()) catch unreachable; |
