From 0b9d6ad04246a3aa87ed63a699a25910020bff48 Mon Sep 17 00:00:00 2001 From: Loris Cro Date: Sat, 3 May 2025 18:37:52 +0200 Subject: [PATCH] std.debug: handle static library paths correctly when reading SelfInfo On macOS ofile entries will not be clean file paths when the entry points at a static archive, like `libfoo.a(libfoo.a.o)` for example. Previously the code for loading debug info would fail resulting in missing frames in stack traces. TODO: fix memory leak, add test case --- lib/std/debug/SelfInfo.zig | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/std/debug/SelfInfo.zig b/lib/std/debug/SelfInfo.zig index ea7ecac4ed..a05a31a6ad 100644 --- a/lib/std/debug/SelfInfo.zig +++ b/lib/std/debug/SelfInfo.zig @@ -686,7 +686,21 @@ pub const Module = switch (native_os) { }; // Check if its debug infos are already in the cache - const o_file_path = mem.sliceTo(self.strings[symbol.ofile..], 0); + const o_file_path = path: { + const raw_path = mem.sliceTo(self.strings[symbol.ofile..], 0); + + if (!std.mem.endsWith(u8, raw_path, ")")) break :path raw_path; + + const last_paren_index = std.mem.lastIndexOfScalar(u8, raw_path, '(') orelse break :path raw_path; + + const basename = raw_path[last_paren_index + 1 .. raw_path.len - 1]; + + const path = raw_path[0..last_paren_index]; + const dirname = std.fs.path.dirname(path) orelse break :path basename; + + break :path try std.fs.path.resolve(allocator, &.{ dirname, basename }); + }; + const o_file_info = self.ofiles.getPtr(o_file_path) orelse (self.loadOFile(allocator, o_file_path) catch |err| switch (err) { error.FileNotFound,