From 318e16181a28725e218121363555580725d6d0d4 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 10 Nov 2026 17:56:05 -0300 Subject: symbols: an address no symbol holds is named by how far into its module it is It was the address in the file, which in a program that is not relocated is the address again: list!402c89 for 402c89. Now list+2c89. Co-Authored-By: Claude Fable 5.2 --- src/trace/Symbols.zig | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'src/trace') diff --git a/src/trace/Symbols.zig b/src/trace/Symbols.zig index 3c37040..abc0ec1 100644 --- a/src/trace/Symbols.zig +++ b/src/trace/Symbols.zig @@ -478,7 +478,7 @@ fn skip(r: *std.Io.Reader, n: usize) !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". +/// "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}); if (!try s.label(w, addr)) w.undo(1); @@ -519,15 +519,21 @@ test "a C++ name is shown without its parameters" { }) |case| try std.testing.expectEqualStrings(case[1], s.sourceName(case[0], &buf).?); } -/// The name of `addr` alone: "fib+12", "libc.so.6!write+18", "[stack]+1f40". -/// False, and nothing written, for an address with none. +/// The name of `addr` alone: "fib+12", "libc.so.6!write+18", and where no +/// symbol holds it how far into its module or mapping it is, in hex: +/// "libc.so.6+2a1c9", "[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); + const found = s.symbolAt(addr) orelse { + // From where the module is mapped, not its address in the file: that is the address itself where it is not relocated. + try w.print("{s}+{x}", .{ std.fs.path.basename(m.path), addr - m.start }); + return true; + }; // 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 (m != &s.modules.items[0]) try w.print("{s}!", .{std.fs.path.basename(m.path)}); var buf: [1024]u8 = undefined; - if (sym) |found| try w.print("{s}+{d}", .{ s.sourceName(found.name, &buf) orelse found.name, addr - found.addr }) else try w.print("{x}", .{addr - m.bias}); + try w.print("{s}+{d}", .{ s.sourceName(found.name, &buf) orelse found.name, addr - found.addr }); return true; } const m = s.mappingAt(addr) orelse return false; -- cgit v1.3