commit 06733c3ff5ed3d7ab0d6a3a6baae6d6699d33f8c (tree)
parent 704444a6e329ee3bb7a99f8b2cc6cebde18b93cd
Author: Andrew Kelley <andrew@ziglang.org>
Date: Tue, 2 Jul 2019 14:48:45 -0400
Merge pull request #2788 from emekoi/pdb-fix
fixed coff header parsing
Diffstat:
2 files changed, 15 insertions(+), 11 deletions(-)
diff --git 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;
@@ -142,10 +154,10 @@ 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;
diff --git a/std/debug.zig b/std/debug.zig
@@ -826,15 +826,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 = undefined,
- .guid = undefined,
- .age = undefined,
- };
+ coff_obj.* = coff.Coff.init(allocator, self_file);
var di = DebugInfo{
.coff = coff_obj,