Skip to content

Commit fcf2f2c

Browse files
star-tek-mbandrewrk
authored andcommitted
windows: fix native build
1 parent a890b8d commit fcf2f2c

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) {
@@ -1142,10 +1148,15 @@ fn printLineFromFileAnyOs(out_stream: anytype, line_info: LineInfo) !void {
11421148
var path = line_info.file_name;
11431149

11441150
if (native_os == .windows) {
1145-
var buffer: [std.fs.MAX_PATH_BYTES*2]u8 = undefined;
1151+
var buffer: [std.fs.MAX_PATH_BYTES * 2]u8 = undefined;
11461152
var fba = std.heap.FixedBufferAllocator.init(&buffer);
11471153
var resolved_path = try std.fs.path.resolve(fba.allocator(), &.{path});
1148-
path = try std.fmt.allocPrint(fba.allocator(), "\\??\\{s}{s}", .{if (resolved_path[0] == '\\') "UNC" else "", resolved_path});
1154+
if (resolved_path[0] == '\\') {
1155+
path = try std.fmt.allocPrint(fba.allocator(), "\\??\\UNC{s}", .{resolved_path});
1156+
} else {
1157+
path = try std.fmt.allocPrint(fba.allocator(), "\\??\\{s}", .{resolved_path});
1158+
}
1159+
// path normalized later in openFile
11491160
}
11501161

11511162
var f = try fs.cwd().openFile(path, .{ .intended_io_mode = .blocking });
@@ -1374,17 +1385,18 @@ pub const DebugInfo = struct {
13741385
windows.PATH_MAX_WIDE,
13751386
);
13761387
assert(len > 0);
1377-
var begin: usize = 0;
1388+
var name_start: usize = 0;
13781389
if (name_buffer[7] != '\\') {
1379-
begin = 3;
1390+
name_start = 3;
13801391
std.mem.copy(u16, name_buffer[3..7], &[_]u16{ '\\', '?', '?', '\\' });
13811392
}
1382-
var name_w16 = std.mem.collapseRepeats(u16, name_buffer[begin..len+7], '\\');
1393+
const name_len = try std.os.windows.normalizePath(u16, name_buffer[name_start .. len + 7]);
1394+
const name = name_buffer[name_start .. name_start + name_len];
13831395

13841396
const obj_di = try self.allocator.create(ModuleDebugInfo);
13851397
errdefer self.allocator.destroy(obj_di);
13861398

1387-
const coff_file = fs.openFileAbsoluteW(name_w16, .{}) catch |err| switch (err) {
1399+
const coff_file = fs.openFileAbsoluteW(name, .{}) catch |err| switch (err) {
13881400
error.FileNotFound => return error.MissingDebugInfo,
13891401
else => return err,
13901402
};

0 commit comments

Comments
 (0)