authorgravatar for kappaloris@gmail.comLoris Cro <kappaloris@gmail.com> 2025-05-03 18:37:52+02:00
committergravatar for kappaloris@gmail.comLoris Cro <kappaloris@gmail.com> 2025-05-03 18:42:00+02:00
log0b9d6ad04246a3aa87ed63a699a25910020bff48
treecaf3cb0a88ca46319e37041bb3336b56c0501282
parentbf9b15ee67fb7577e30d66fda879b8af84f84b54

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

1 files changed, 15 insertions(+), 1 deletions(-)

lib/std/debug/SelfInfo.zig+15-1
......@@ -686,7 +686,21 @@ pub const Module = switch (native_os) {
686686 };
687687
688688 // Check if its debug infos are already in the cache
689 const o_file_path = mem.sliceTo(self.strings[symbol.ofile..], 0);
689 const o_file_path = path: {
690 const raw_path = mem.sliceTo(self.strings[symbol.ofile..], 0);
691
692 if (!std.mem.endsWith(u8, raw_path, ")")) break :path raw_path;
693
694 const last_paren_index = std.mem.lastIndexOfScalar(u8, raw_path, '(') orelse break :path raw_path;
695
696 const basename = raw_path[last_paren_index + 1 .. raw_path.len - 1];
697
698 const path = raw_path[0..last_paren_index];
699 const dirname = std.fs.path.dirname(path) orelse break :path basename;
700
701 break :path try std.fs.path.resolve(allocator, &.{ dirname, basename });
702 };
703
690704 const o_file_info = self.ofiles.getPtr(o_file_path) orelse
691705 (self.loadOFile(allocator, o_file_path) catch |err| switch (err) {
692706 error.FileNotFound,