New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dwarf on windows #8717
Dwarf on windows #8717
Conversation
Also it has been compiled and tested on Windows and Linux |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! I've left a few trivial comments here and there (and please run zig fmt
).
@@ -143,6 +147,7 @@ pub fn start(self: *Progress, name: []const u8, estimated_total_items: usize) !* | |||
self.terminal = stderr; | |||
self.supports_ansi_escape_codes = true; | |||
} else if (std.builtin.os.tag == .windows and stderr.isTty()) { | |||
self.is_windows_terminal = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do you get here? isCygwinPty
and supportsAnsiEscapeCodes
should detect this case and use escape sequences instead of WinAPI functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that is the case. I was just trying to make it more explicit. The first case of the if/else if chain there is:
if (stderr.supportsAnsiEscapeCodes()
which is just isCygwinPty()
on windows.
I didn't add a comment but supports_ansi_escapse_codes
and is_windows_terminal
are mutually exclusive.
lib/std/coff.zig
Outdated
@@ -162,20 +163,51 @@ pub const Coff = struct { | |||
try self.loadOptionalHeader(); | |||
} | |||
|
|||
fn readStringFromTable(self: *Coff, offset: u32, buff: []u8) !u32 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fn readStringFromTable(self: *Coff, offset: u32, buff: []u8) !u32 { | |
fn readStringFromTable(self: *Coff, offset: usize, buf: []u8) ![]const u8 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch
// No symbol table therefore no string table | ||
return error.MissingStringTable; | ||
} | ||
const string_table_offset = self.coff_header.pointer_to_symbol_table + (self.coff_header.number_of_symbols * 18) + offset; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a comment explaining what 18
is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do
lib/std/coff.zig
Outdated
try self.in_file.seekTo(string_table_offset); | ||
|
||
var i: u8 = 0; | ||
while (i < buff.len) : (i+=1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This loop can be simplified down to:
const str = try in.readUntilDelimiterOrEof(buf, 0)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to know. I'm still getting used to the stdlib
lib/std/coff.zig
Outdated
} | ||
buff[i] = byte; | ||
} | ||
try self.in_file.seekTo(old_pos); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd place this in a defer
block below the other seekTo
, this way you're also rewinding the stream in case of error.
lib/std/coff.zig
Outdated
skip_size = 2 * @sizeOf(u8) + 8 * @sizeOf(u16) + 18 * @sizeOf(u32); | ||
num_rva_pos = opt_header_pos + 92; | ||
|
||
try self.in_file.seekTo(opt_header_pos+28); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please format all the files you're touching with zig fmt
.
lib/std/coff.zig
Outdated
@@ -277,6 +309,19 @@ pub const Coff = struct { | |||
.characteristics = try in.readIntLittle(u32), | |||
}, | |||
}); | |||
const sec = &self.sections.items[self.sections.items.len-1]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not move the name expansion logic before the append
call?
lib/std/coff.zig
Outdated
const in = self.in_file.reader(); | ||
try self.in_file.seekTo(sec.header.pointer_to_raw_data); | ||
const out_buff = try allocator.alloc(u8, sec.header.misc.virtual_size); | ||
const readBytes = in.read(out_buff); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const readBytes = in.read(out_buff); | |
in.readNoEof(out_buff); |
lib/std/debug.zig
Outdated
@@ -1525,6 +1548,7 @@ pub const ModuleDebugInfo = switch (builtin.os.tag) { | |||
.uefi, .windows => struct { | |||
base_address: usize, | |||
pdb: pdb.Pdb, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pdb
/dwarf
can be consolidated into a union (enum) { pdb: pdb.Pdb, dwarf: DW.Dwarfinfo }
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea
Thanks for the quick review and constructive comments. I'll fix everything you recommended and I'll include one more commit if it's alright: |
Sure thing, go ahead. Many functions take |
Okay, all changes discussed are pushed. Let me know if there's anything else. |
d26a20c
to
2258be5
Compare
Looking back on the commits in this PR, this is kind of a mess. Let me know if you'd prefer I rework it into fewer, tighter commits. |
2258be5
to
bfd2378
Compare
I rebased these changes onto a post 0.8 master so they will be much easier to merge. |
bfd2378
to
24b1a00
Compare
This PR does 3 things but can be split up if needed.