Skip to content

Commit ff5524f

Browse files
committed
std.dwarf: Append the compile dir to relative include dirs
The DWARF spec states that relative include directories are relative to the current compilation unit directory.
1 parent 1829b6e commit ff5524f

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

lib/std/dwarf.zig

+9-3
Original file line numberDiff line numberDiff line change
@@ -478,9 +478,15 @@ const LineNumberProgram = struct {
478478
if (file_entry.dir_index >= self.include_dirs.len) return badDwarf();
479479
const dir_name = self.include_dirs[file_entry.dir_index].path;
480480

481-
const file_name = try fs.path.join(allocator, &[_][]const u8{
482-
dir_name, file_entry.path,
483-
});
481+
// This will break when the system running this code has different
482+
// path separators than what generated the debug info. This was deemed
483+
// acceptable as this code is really only designed to be used in
484+
// combination with std.debug
485+
const parts = if (file_entry.dir_index > 0 and !fs.path.isAbsolute(dir_name))
486+
&[_][]const u8{ self.include_dirs[0].path, dir_name, file_entry.path }
487+
else
488+
&[_][]const u8{ dir_name, file_entry.path };
489+
const file_name = try fs.path.join(allocator, parts);
484490

485491
return debug.LineInfo{
486492
.line = if (self.prev_line >= 0) @intCast(u64, self.prev_line) else 0,

0 commit comments

Comments
 (0)