From 66a2a7cf733f6abc1f79561c52d901ce67019fb1 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 10 Nov 2026 16:03:43 -0300 Subject: trace: what the context draws is in the recording; SQLite on the ladder An instruction's string carries its source line and, for a direct call, how many parameters the callee takes (DWARF); telescope.frames gives each frame's extent on the stack; with --alloc the debugger watches each live allocation and the allocator's header before it, changes only, 256 KiB a stop at most. C++ names are shown and found as the source has them (the command links the C++ runtime for its demangler). SQLite 3.50.4 through every backend, measured (README, bench/sqlite.sh). It found two faults: a file compiled by its full path was recorded under a path joined onto the compile directory, and ztrace run noticed a target's exit up to 10 ms late. Co-Authored-By: Claude Fable 5.2 --- src/cli/util.zig | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/cli/util.zig') diff --git a/src/cli/util.zig b/src/cli/util.zig index 1d7ee4c..652956d 100644 --- a/src/cli/util.zig +++ b/src/cli/util.zig @@ -62,6 +62,22 @@ pub const Producer = struct { } }; +extern fn __cxa_demangle(name: [*:0]const u8, out: ?[*]u8, len: ?*usize, status: *c_int) ?[*:0]u8; + +/// What `Symbols.demangle` is set to: the C++ runtime's demangler. +pub fn demangle(name: []const u8, buf: []u8) ?[]const u8 { + if (!std.mem.startsWith(u8, name, "_Z") or name.len >= buf.len) return null; + @memcpy(buf[0..name.len], name); + buf[name.len] = 0; + var status: c_int = 0; + const out = __cxa_demangle(buf[0..name.len :0], null, null, &status) orelse return null; + defer std.c.free(out); + const text = std.mem.span(out); + if (text.len > buf.len) return null; + @memcpy(buf[0..text.len], text); + return buf[0..text.len]; +} + /// The arguments after a command's own, as the target's argv. pub fn targetArgv(arena: std.mem.Allocator, args: []const [:0]const u8) ![:null]?[*:0]const u8 { const argv = try arena.allocSentinel(?[*:0]const u8, args.len, null); -- cgit v1.3