authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-07-02 14:48:45-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2019-07-02 14:48:45-04:00
log06733c3ff5ed3d7ab0d6a3a6baae6d6699d33f8c
treea8a81037d96f586797ebe650620d91c35e688265
parent704444a6e329ee3bb7a99f8b2cc6cebde18b93cd
parent027517a0c933f7c07497497c1e8cc0700b7f02bb
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #2788 from emekoi/pdb-fix

fixed coff header parsing

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

std/coff.zig+14-2
...@@ -39,6 +39,18 @@ pub const Coff = struct {...@@ -39,6 +39,18 @@ pub const Coff = struct {
39 guid: [16]u8,39 guid: [16]u8,
40 age: u32,40 age: u32,
4141
42 pub fn init(allocator: *mem.Allocator, in_file: File) Coff {
43 return Coff{
44 .in_file = in_file,
45 .allocator = allocator,
46 .coff_header = undefined,
47 .pe_header = undefined,
48 .sections = ArrayList(Section).init(allocator),
49 .guid = undefined,
50 .age = undefined,
51 };
52 }
53
42 pub fn loadHeader(self: *Coff) !void {54 pub fn loadHeader(self: *Coff) !void {
43 const pe_pointer_offset = 0x3C;55 const pe_pointer_offset = 0x3C;
4456
...@@ -142,10 +154,10 @@ pub const Coff = struct {...@@ -142,10 +154,10 @@ pub const Coff = struct {
142 }154 }
143155
144 pub fn loadSections(self: *Coff) !void {156 pub fn loadSections(self: *Coff) !void {
145 if (self.sections.len != 0)157 if (self.sections.len == self.coff_header.number_of_sections)
146 return;158 return;
147159
148 self.sections = ArrayList(Section).init(self.allocator);160 try self.sections.ensureCapacity(self.coff_header.number_of_sections);
149161
150 var file_stream = self.in_file.inStream();162 var file_stream = self.in_file.inStream();
151 const in = &file_stream.stream;163 const in = &file_stream.stream;
std/debug.zig+1-9
...@@ -826,15 +826,7 @@ fn openSelfDebugInfoWindows(allocator: *mem.Allocator) !DebugInfo {...@@ -826,15 +826,7 @@ fn openSelfDebugInfoWindows(allocator: *mem.Allocator) !DebugInfo {
826 defer self_file.close();826 defer self_file.close();
827827
828 const coff_obj = try allocator.create(coff.Coff);828 const coff_obj = try allocator.create(coff.Coff);
829 coff_obj.* = coff.Coff{829 coff_obj.* = coff.Coff.init(allocator, self_file);
830 .in_file = self_file,
831 .allocator = allocator,
832 .coff_header = undefined,
833 .pe_header = undefined,
834 .sections = undefined,
835 .guid = undefined,
836 .age = undefined,
837 };
838830
839 var di = DebugInfo{831 var di = DebugInfo{
840 .coff = coff_obj,832 .coff = coff_obj,