-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Incorrect file paths in DWARF debug info #17482
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Right now I was affected by the same issue. It looks like some directories are duplicated in the DWARF debug info:
|
I'd dare to say this is the problematic commit, since it's the one touching file paths for LLVM codegen debug information: |
This, or something like it, affects DWARF debug info more generally, here's a minimal reproduction: pub fn main() !void {
return error.Something;
} $ zig build-exe test.zig
$ ./test
error: Something
???:?:?: 0x21db38 in main (test) It seems to have regressed in #17392 as @davidgm94 suggested. Reverting to before that PR was merged fixes it: $ zig build-exe test.zig
$ ./test
error: Something
/home/ryan/Programming/zig/tmp/test.zig:4:5: 0x21db38 in main (test)
return error.Something;
^ |
Another caveat: this only seems to affect certain files, for example if you panic during a test, then source lines get printed for zig lib files but not the local file: test "error" {
@panic("oh no");
} $ zig test test.zig
Test [1/1] test.error... thread 227764 panic: oh no
/home/ryan/Programming/zig/zig/lib/test.zig:2:5: 0x223825 in test.error (test)
/home/ryan/Programming/zig/zig/lib/test_runner.zig:181:28: 0x22c90d in mainTerminal (test)
} else test_fn.func();
^
/home/ryan/Programming/zig/zig/lib/test_runner.zig:36:28: 0x22485a in main (test)
return mainTerminal();
^
/home/ryan/Programming/zig/zig/lib/std/start.zig:573:22: 0x223d5c in posixCallMainAndExit (test)
root.main();
^
/home/ryan/Programming/zig/zig/lib/std/start.zig:251:5: 0x2238b1 in _start (test)
asm volatile (switch (native_arch) {
^
???:?:?: 0x0 in ??? (???) Before #17392: $ zig test test.zig
Test [1/1] test.error... thread 227895 panic: oh no
/home/ryan/Programming/zig/tmp/test.zig:2:5: 0x223825 in test.error (test)
@panic("oh no");
^
/home/ryan/Programming/zig/zig/lib/test_runner.zig:181:28: 0x22c90d in mainTerminal (test)
} else test_fn.func();
^
/home/ryan/Programming/zig/zig/lib/test_runner.zig:36:28: 0x22485a in main (test)
return mainTerminal();
^
/home/ryan/Programming/zig/zig/lib/std/start.zig:369:22: 0x223d5c in posixCallMainAndExit (test)
while (envp_optional[envp_count]) |_| : (envp_count += 1) {}
^
/home/ryan/Programming/zig/zig/lib/std/start.zig:251:5: 0x2238b1 in _start (test)
asm volatile (switch (native_arch) {
^
???:?:?: 0x0 in ??? (???) |
I noticed --- a/src/codegen/llvm.zig
+++ b/src/codegen/llvm.zig
@@ -1840,7 +1840,8 @@ pub const Object = struct {
const dir_path = try file.mod.root.joinStringZ(gpa, sub_path);
if (std.fs.path.isAbsolute(dir_path)) break :d dir_path;
const abs = std.fs.realpath(dir_path, &buffer) catch break :d dir_path;
- break :d try std.fs.path.joinZ(gpa, &.{ abs, sub_path });
+ gpa.free(dir_path);
+ break :d try gpa.dupeZ(u8, abs);
};
defer gpa.free(dir_path_z);
const sub_file_path_z = try gpa.dupeZ(u8, std.fs.path.basename(file.sub_file_path)); but that does not seem to be the full story since stack traces are still broken after this fix. |
@@ -911,6 +911,9 @@ pub const Object = struct {
break :blk try builder.gpa.dupeZ(u8, cwd);
};
defer builder.gpa.free(compile_unit_dir_z);
+ std.debug.print("di compile unit = '{s}'\n", .{
+ compile_unit_dir_z,
+ });
builder.llvm.di_compile_unit = builder.llvm.di_builder.?.createCompileUnit(
DW.LANG.C99, With this line traced we see before/after: -di compile unit = '/home/andy/dev/zig/build-release'
-di compile unit = '/home/andy/dev/zig/lib'
+di compile unit = ''
+di compile unit = '/home/andy/dev/zig/lib' So it looks like the remaining issue is that empty string needs to get resolved to an absolute path. I still don't necessarily agree with using absolute paths here, but let me fix the regression and then deal with that idea separately. |
The previous code incorrectly added `sub_path` twice. Also for the compilation unit, it was passing empty string to realpath, resulting in the error handling codepath being used. closes #17482
Oh, I already wrote this up: #16571 |
The previous code incorrectly added `sub_path` twice. Also for the compilation unit, it was passing empty string to realpath, resulting in the error handling codepath being used. closes #17482
Zig Version
0.12.0-dev.878+7abf9b3a8
Steps to Reproduce and Observed Behavior
Sorry, I was unable to replicate the issue with a reduction.
With 0.12.0-dev.878+7abf9b3a8:
With 0.12.0-dev.819+75b48ef50:
The issue only seems to affect files in subdirectories.
Expected Behavior
Correct file paths in debug info.
The text was updated successfully, but these errors were encountered: