From fbb0c8d639ec205848f03099413c57f686c2d05d Mon Sep 17 00:00:00 2001 From: emekoi Date: Fri, 28 Jun 2019 17:59:34 -0500 Subject: [PATCH 1/3] fixed debug info on windows --- std/coff.zig | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/std/coff.zig b/std/coff.zig index 97d286f0e6..ceb6050055 100644 --- a/std/coff.zig +++ b/std/coff.zig @@ -142,10 +142,11 @@ pub const Coff = struct { } pub fn loadSections(self: *Coff) !void { - if (self.sections.len != 0) + if (self.sections.len == self.coff_header.number_of_sections) return; self.sections = ArrayList(Section).init(self.allocator); + try self.sections.ensureCapacity(self.coff_header.number_of_sections); var file_stream = self.in_file.inStream(); const in = &file_stream.stream; From b780dee3e845f5c8fb8ea7b7906685d5196261a4 Mon Sep 17 00:00:00 2001 From: emekoi Date: Fri, 28 Jun 2019 18:22:02 -0500 Subject: [PATCH 2/3] initialize sections in openSelfDebugInfoWindows --- std/coff.zig | 1 - std/debug.zig | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/std/coff.zig b/std/coff.zig index ceb6050055..2c65da5e9e 100644 --- a/std/coff.zig +++ b/std/coff.zig @@ -145,7 +145,6 @@ pub const Coff = struct { if (self.sections.len == self.coff_header.number_of_sections) return; - self.sections = ArrayList(Section).init(self.allocator); try self.sections.ensureCapacity(self.coff_header.number_of_sections); var file_stream = self.in_file.inStream(); diff --git a/std/debug.zig b/std/debug.zig index 223f93d1ad..09c89befed 100644 --- a/std/debug.zig +++ b/std/debug.zig @@ -805,7 +805,7 @@ fn openSelfDebugInfoWindows(allocator: *mem.Allocator) !DebugInfo { .allocator = allocator, .coff_header = undefined, .pe_header = undefined, - .sections = undefined, + .sections = ArrayList(coff.Section).init(allocator), .guid = undefined, .age = undefined, }; From 027517a0c933f7c07497497c1e8cc0700b7f02bb Mon Sep 17 00:00:00 2001 From: emekoi Date: Sat, 29 Jun 2019 13:56:23 -0500 Subject: [PATCH 3/3] added init function for `Coff` --- std/coff.zig | 12 ++++++++++++ std/debug.zig | 10 +--------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/std/coff.zig b/std/coff.zig index 2c65da5e9e..9fdc368878 100644 --- a/std/coff.zig +++ b/std/coff.zig @@ -39,6 +39,18 @@ pub const Coff = struct { guid: [16]u8, age: u32, + pub fn init(allocator: *mem.Allocator, in_file: File) Coff { + return Coff{ + .in_file = in_file, + .allocator = allocator, + .coff_header = undefined, + .pe_header = undefined, + .sections = ArrayList(Section).init(allocator), + .guid = undefined, + .age = undefined, + }; + } + pub fn loadHeader(self: *Coff) !void { const pe_pointer_offset = 0x3C; diff --git a/std/debug.zig b/std/debug.zig index 09c89befed..c802f06c04 100644 --- a/std/debug.zig +++ b/std/debug.zig @@ -800,15 +800,7 @@ fn openSelfDebugInfoWindows(allocator: *mem.Allocator) !DebugInfo { defer self_file.close(); const coff_obj = try allocator.create(coff.Coff); - coff_obj.* = coff.Coff{ - .in_file = self_file, - .allocator = allocator, - .coff_header = undefined, - .pe_header = undefined, - .sections = ArrayList(coff.Section).init(allocator), - .guid = undefined, - .age = undefined, - }; + coff_obj.* = coff.Coff.init(allocator, self_file); var di = DebugInfo{ .coff = coff_obj,