Skip to content

Commit d71b827

Browse files
committed
windows: fix native build
1 parent eedcfd3 commit d71b827

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

lib/std/debug.zig

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -884,8 +884,14 @@ fn readCoffDebugInfo(allocator: mem.Allocator, coff_file: File) !ModuleDebugInfo
884884
const path = try fs.path.resolve(allocator, &[_][]const u8{raw_path});
885885
defer allocator.free(path);
886886

887-
const unc_path = try std.fmt.allocPrint(allocator, "\\??\\{s}{s}", .{if (path[0] == '\\') "UNC" else "", path});
887+
var unc_path: []const u8 = undefined;
888+
if (path[0] == '\\') {
889+
unc_path = try std.fmt.allocPrint(allocator, "\\??\\UNC{s}", .{path});
890+
} else {
891+
unc_path = try std.fmt.allocPrint(allocator, "\\??\\{s}", .{path});
892+
}
888893
defer allocator.free(unc_path);
894+
// path normalized later in openFile
889895

890896
di.debug_data = PdbOrDwarf{ .pdb = undefined };
891897
di.debug_data.pdb = pdb.Pdb.init(allocator, unc_path) catch |err| switch (err) {
@@ -1137,10 +1143,15 @@ fn printLineFromFileAnyOs(out_stream: anytype, line_info: LineInfo) !void {
11371143
var path = line_info.file_name;
11381144

11391145
if (native_os == .windows) {
1140-
var buffer: [std.fs.MAX_PATH_BYTES*2]u8 = undefined;
1146+
var buffer: [std.fs.MAX_PATH_BYTES * 2]u8 = undefined;
11411147
var fba = std.heap.FixedBufferAllocator.init(&buffer);
11421148
var resolved_path = try std.fs.path.resolve(fba.allocator(), &.{path});
1143-
path = try std.fmt.allocPrint(fba.allocator(), "\\??\\{s}{s}", .{if (resolved_path[0] == '\\') "UNC" else "", resolved_path});
1149+
if (resolved_path[0] == '\\') {
1150+
path = try std.fmt.allocPrint(fba.allocator(), "\\??\\UNC{s}", .{resolved_path});
1151+
} else {
1152+
path = try std.fmt.allocPrint(fba.allocator(), "\\??\\{s}", .{resolved_path});
1153+
}
1154+
// path normalized later in openFile
11441155
}
11451156

11461157
var f = try fs.cwd().openFile(path, .{ .intended_io_mode = .blocking });
@@ -1369,17 +1380,18 @@ pub const DebugInfo = struct {
13691380
windows.PATH_MAX_WIDE,
13701381
);
13711382
assert(len > 0);
1372-
var begin: usize = 0;
1383+
var name_start: usize = 0;
13731384
if (name_buffer[7] != '\\') {
1374-
begin = 3;
1385+
name_start = 3;
13751386
std.mem.copy(u16, name_buffer[3..7], &[_]u16{ '\\', '?', '?', '\\' });
13761387
}
1377-
var name_w16 = std.mem.collapseRepeats(u16, name_buffer[begin..len+7], '\\');
1388+
const name_len = try std.os.windows.normalizePath(u16, name_buffer[name_start .. len + 7]);
1389+
const name = name_buffer[name_start .. name_start + name_len];
13781390

13791391
const obj_di = try self.allocator.create(ModuleDebugInfo);
13801392
errdefer self.allocator.destroy(obj_di);
13811393

1382-
const coff_file = fs.openFileAbsoluteW(name_w16, .{}) catch |err| switch (err) {
1394+
const coff_file = fs.openFileAbsoluteW(name, .{}) catch |err| switch (err) {
13831395
error.FileNotFound => return error.MissingDebugInfo,
13841396
else => return err,
13851397
};

0 commit comments

Comments
 (0)