| author | |
| committer | |
| log | 8a5f331ec832201c6e4bdf211cdd37ca5eb4347b |
| tree | 06edb434b2d1df8d7de41c07b8f631ff8c7fb550 |
| parent | 5b86180ae3b451288bbc1aed5cf8040d4fcb65fd |
2 files changed, 11 insertions(+), 12 deletions(-)
lib/std/coff.zig+6-5| ... | @@ -1101,12 +1101,13 @@ pub const Coff = struct { | ... | @@ -1101,12 +1101,13 @@ pub const Coff = struct { |
| 1101 | return coff; | 1101 | return coff; |
| 1102 | } | 1102 | } |
| 1103 | 1103 | ||
| 1104 | pub fn getPdbPath(self: *Coff, buffer: []u8) !usize { | 1104 | pub fn getPdbPath(self: *Coff, buffer: []u8) !?usize { |
| 1105 | assert(self.is_image); | 1105 | assert(self.is_image); |
| 1106 | 1106 | ||
| 1107 | const data_dirs = self.getDataDirectories(); | 1107 | const data_dirs = self.getDataDirectories(); |
| 1108 | const debug_dir = data_dirs[@intFromEnum(DirectoryEntry.DEBUG)]; | 1108 | if (@intFromEnum(DirectoryEntry.DEBUG) >= data_dirs.len) return null; |
| 1109 | 1109 | ||
| 1110 | const debug_dir = data_dirs[@intFromEnum(DirectoryEntry.DEBUG)]; | ||
| 1110 | var stream = std.io.fixedBufferStream(self.data); | 1111 | var stream = std.io.fixedBufferStream(self.data); |
| 1111 | const reader = stream.reader(); | 1112 | const reader = stream.reader(); |
| 1112 | 1113 | ||
| ... | @@ -1126,14 +1127,14 @@ pub const Coff = struct { | ... | @@ -1126,14 +1127,14 @@ pub const Coff = struct { |
| 1126 | // It can be in any section. | 1127 | // It can be in any section. |
| 1127 | const debug_dir_entry_count = debug_dir.size / @sizeOf(DebugDirectoryEntry); | 1128 | const debug_dir_entry_count = debug_dir.size / @sizeOf(DebugDirectoryEntry); |
| 1128 | var i: u32 = 0; | 1129 | var i: u32 = 0; |
| 1129 | blk: while (i < debug_dir_entry_count) : (i += 1) { | 1130 | while (i < debug_dir_entry_count) : (i += 1) { |
| 1130 | const debug_dir_entry = try reader.readStruct(DebugDirectoryEntry); | 1131 | const debug_dir_entry = try reader.readStruct(DebugDirectoryEntry); |
| 1131 | if (debug_dir_entry.type == .CODEVIEW) { | 1132 | if (debug_dir_entry.type == .CODEVIEW) { |
| 1132 | const dir_offset = if (self.is_loaded) debug_dir_entry.address_of_raw_data else debug_dir_entry.pointer_to_raw_data; | 1133 | const dir_offset = if (self.is_loaded) debug_dir_entry.address_of_raw_data else debug_dir_entry.pointer_to_raw_data; |
| 1133 | try stream.seekTo(dir_offset); | 1134 | try stream.seekTo(dir_offset); |
| 1134 | break :blk; | 1135 | break; |
| 1135 | } | 1136 | } |
| 1136 | } | 1137 | } else return null; |
| 1137 | 1138 | ||
| 1138 | var cv_signature: [4]u8 = undefined; // CodeView signature | 1139 | var cv_signature: [4]u8 = undefined; // CodeView signature |
| 1139 | try reader.readNoEof(cv_signature[0..]); | 1140 | 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 | ... | @@ -1024,12 +1024,8 @@ fn readCoffDebugInfo(allocator: mem.Allocator, coff_obj: *coff.Coff) !ModuleDebu |
| 1024 | di.dwarf = dwarf; | 1024 | di.dwarf = dwarf; |
| 1025 | } | 1025 | } |
| 1026 | 1026 | ||
| 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 | |||
| 1031 | var path_buf: [windows.MAX_PATH]u8 = undefined; | 1027 | 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; |
| 1033 | const raw_path = path_buf[0..len]; | 1029 | const raw_path = path_buf[0..len]; |
| 1034 | 1030 | ||
| 1035 | const path = try fs.path.resolve(allocator, &[_][]const u8{raw_path}); | 1031 | 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 | ... | @@ -1038,8 +1034,6 @@ fn readCoffDebugInfo(allocator: mem.Allocator, coff_obj: *coff.Coff) !ModuleDebu |
| 1038 | di.pdb = pdb.Pdb.init(allocator, path) catch |err| switch (err) { | 1034 | di.pdb = pdb.Pdb.init(allocator, path) catch |err| switch (err) { |
| 1039 | error.FileNotFound, error.IsDir => { | 1035 | error.FileNotFound, error.IsDir => { |
| 1040 | if (di.dwarf == null) return error.MissingDebugInfo; | 1036 | if (di.dwarf == null) return error.MissingDebugInfo; |
| 1041 | allocator.free(di.coff_section_headers); | ||
| 1042 | di.coff_section_headers = undefined; | ||
| 1043 | return di; | 1037 | return di; |
| 1044 | }, | 1038 | }, |
| 1045 | else => return err, | 1039 | else => return err, |
| ... | @@ -1050,6 +1044,10 @@ fn readCoffDebugInfo(allocator: mem.Allocator, coff_obj: *coff.Coff) !ModuleDebu | ... | @@ -1050,6 +1044,10 @@ fn readCoffDebugInfo(allocator: mem.Allocator, coff_obj: *coff.Coff) !ModuleDebu |
| 1050 | if (!mem.eql(u8, &coff_obj.guid, &di.pdb.?.guid) or coff_obj.age != di.pdb.?.age) | 1044 | if (!mem.eql(u8, &coff_obj.guid, &di.pdb.?.guid) or coff_obj.age != di.pdb.?.age) |
| 1051 | return error.InvalidDebugInfo; | 1045 | return error.InvalidDebugInfo; |
| 1052 | 1046 | ||
| 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 | |||
| 1053 | return di; | 1051 | return di; |
| 1054 | } | 1052 | } |
| 1055 | } | 1053 | } |