authorgravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2023-08-15 02:44:34-04:00
committergravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2023-08-15 10:20:11-04:00
log8a5f331ec832201c6e4bdf211cdd37ca5eb4347b
tree06edb434b2d1df8d7de41c07b8f631ff8c7fb550
parent5b86180ae3b451288bbc1aed5cf8040d4fcb65fd

coff: handle the case of there being no PDB path


2 files changed, 11 insertions(+), 12 deletions(-)

lib/std/coff.zig+6-5
......@@ -1101,12 +1101,13 @@ pub const Coff = struct {
11011101 return coff;
11021102 }
11031103
1104 pub fn getPdbPath(self: *Coff, buffer: []u8) !usize {
1104 pub fn getPdbPath(self: *Coff, buffer: []u8) !?usize {
11051105 assert(self.is_image);
11061106
11071107 const data_dirs = self.getDataDirectories();
1108 const debug_dir = data_dirs[@intFromEnum(DirectoryEntry.DEBUG)];
1108 if (@intFromEnum(DirectoryEntry.DEBUG) >= data_dirs.len) return null;
11091109
1110 const debug_dir = data_dirs[@intFromEnum(DirectoryEntry.DEBUG)];
11101111 var stream = std.io.fixedBufferStream(self.data);
11111112 const reader = stream.reader();
11121113
......@@ -1126,14 +1127,14 @@ pub const Coff = struct {
11261127 // It can be in any section.
11271128 const debug_dir_entry_count = debug_dir.size / @sizeOf(DebugDirectoryEntry);
11281129 var i: u32 = 0;
1129 blk: while (i < debug_dir_entry_count) : (i += 1) {
1130 while (i < debug_dir_entry_count) : (i += 1) {
11301131 const debug_dir_entry = try reader.readStruct(DebugDirectoryEntry);
11311132 if (debug_dir_entry.type == .CODEVIEW) {
11321133 const dir_offset = if (self.is_loaded) debug_dir_entry.address_of_raw_data else debug_dir_entry.pointer_to_raw_data;
11331134 try stream.seekTo(dir_offset);
1134 break :blk;
1135 break;
11351136 }
1136 }
1137 } else return null;
11371138
11381139 var cv_signature: [4]u8 = undefined; // CodeView signature
11391140 try reader.readNoEof(cv_signature[0..]);
lib/std/debug.zig+5-7
......@@ -1024,12 +1024,8 @@ fn readCoffDebugInfo(allocator: mem.Allocator, coff_obj: *coff.Coff) !ModuleDebu
10241024 di.dwarf = dwarf;
10251025 }
10261026
1027 // Only used by the pdb path
1028 di.coff_section_headers = try coff_obj.getSectionHeadersAlloc(allocator);
1029 errdefer allocator.free(di.coff_section_headers);
1030
10311027 var path_buf: [windows.MAX_PATH]u8 = undefined;
1032 const len = try coff_obj.getPdbPath(path_buf[0..]);
1028 const len = try coff_obj.getPdbPath(path_buf[0..]) orelse return di;
10331029 const raw_path = path_buf[0..len];
10341030
10351031 const path = try fs.path.resolve(allocator, &[_][]const u8{raw_path});
......@@ -1038,8 +1034,6 @@ fn readCoffDebugInfo(allocator: mem.Allocator, coff_obj: *coff.Coff) !ModuleDebu
10381034 di.pdb = pdb.Pdb.init(allocator, path) catch |err| switch (err) {
10391035 error.FileNotFound, error.IsDir => {
10401036 if (di.dwarf == null) return error.MissingDebugInfo;
1041 allocator.free(di.coff_section_headers);
1042 di.coff_section_headers = undefined;
10431037 return di;
10441038 },
10451039 else => return err,
......@@ -1050,6 +1044,10 @@ fn readCoffDebugInfo(allocator: mem.Allocator, coff_obj: *coff.Coff) !ModuleDebu
10501044 if (!mem.eql(u8, &coff_obj.guid, &di.pdb.?.guid) or coff_obj.age != di.pdb.?.age)
10511045 return error.InvalidDebugInfo;
10521046
1047 // Only used by the pdb path
1048 di.coff_section_headers = try coff_obj.getSectionHeadersAlloc(allocator);
1049 errdefer allocator.free(di.coff_section_headers);
1050
10531051 return di;
10541052 }
10551053}