From 0d4a5c40bc97d65ede1923577b2ca9dac3a6c24f Mon Sep 17 00:00:00 2001 From: Sahnvour Date: Fri, 15 Mar 2019 20:16:42 +0100 Subject: correct padding handling between std.pdb.ModInfo entries in DbiStream --- std/debug.zig | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'std/debug.zig') diff --git a/std/debug.zig b/std/debug.zig index b666e816af..0b5fc97f87 100644 --- a/std/debug.zig +++ b/std/debug.zig @@ -881,8 +881,9 @@ fn openSelfDebugInfoWindows(allocator: *mem.Allocator) !DebugInfo { const obj_file_name = try dbi.readNullTermString(allocator); this_record_len += obj_file_name.len + 1; - const march_forward_bytes = this_record_len % 4; - if (march_forward_bytes != 0) { + if (this_record_len % 4 != 0) { + const round_to_next_4 = (this_record_len | 0x3) + 1; + const march_forward_bytes = round_to_next_4 - this_record_len; try dbi.seekForward(march_forward_bytes); this_record_len += march_forward_bytes; } -- cgit v1.2.3 From 094d40fb1a816a02e9f193f856049cf50503fdc4 Mon Sep 17 00:00:00 2001 From: Sahnvour Date: Fri, 15 Mar 2019 21:11:27 +0100 Subject: allow pdb modules to have no C13 data, this happens if the module is stripped --- std/debug.zig | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'std/debug.zig') diff --git a/std/debug.zig b/std/debug.zig index 0b5fc97f87..2cd6f697d9 100644 --- a/std/debug.zig +++ b/std/debug.zig @@ -565,11 +565,12 @@ fn populateModule(di: *DebugInfo, mod: *Module) !void { return; const allocator = getDebugInfoAllocator(); - if (mod.mod_info.C11ByteSize != 0) + // At most one can be non-zero. + if (mod.mod_info.C11ByteSize != 0 and mod.mod_info.C13ByteSize != 0) return error.InvalidDebugInfo; if (mod.mod_info.C13ByteSize == 0) - return error.MissingDebugInfo; + return; const modi = di.pdb.getStreamById(mod.mod_info.ModuleSymStream) orelse return error.MissingDebugInfo; -- cgit v1.2.3 From 704dfaaabf2cf2253a6d58cc25f6cd8eff8c87bd Mon Sep 17 00:00:00 2001 From: Sahnvour Date: Fri, 15 Mar 2019 21:44:12 +0100 Subject: avoid reading LineBlockFragmentHeader at all if the address is not in range, thus simplifying code and improving speed of execution --- std/debug.zig | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) (limited to 'std/debug.zig') diff --git a/std/debug.zig b/std/debug.zig index 2cd6f697d9..96b861e4a7 100644 --- a/std/debug.zig +++ b/std/debug.zig @@ -372,18 +372,20 @@ fn printSourceAtAddressWindows(di: *DebugInfo, out_stream: var, relocated_addres const frag_vaddr_start = coff_section.header.virtual_address + line_hdr.RelocOffset; const frag_vaddr_end = frag_vaddr_start + line_hdr.CodeSize; - // There is an unknown number of LineBlockFragmentHeaders (and their accompanying line and column records) - // from now on. We will iterate through them, and eventually find a LineInfo that we're interested in, - // breaking out to :subsections. If not, we will make sure to not read anything outside of this subsection. - const subsection_end_index = sect_offset + subsect_hdr.Length; - while (line_index < subsection_end_index) { - const block_hdr = @ptrCast(*pdb.LineBlockFragmentHeader, &subsect_info[line_index]); - line_index += @sizeOf(pdb.LineBlockFragmentHeader); - const start_line_index = line_index; - - const has_column = line_hdr.Flags.LF_HaveColumns; - - if (relative_address >= frag_vaddr_start and relative_address < frag_vaddr_end) { + if (relative_address >= frag_vaddr_start and relative_address < frag_vaddr_end) { + // There is an unknown number of LineBlockFragmentHeaders (and their accompanying line and column records) + // from now on. We will iterate through them, and eventually find a LineInfo that we're interested in, + // breaking out to :subsections. If not, we will make sure to not read anything outside of this subsection. + + const subsection_end_index = sect_offset + subsect_hdr.Length; + + while (line_index < subsection_end_index) { + const block_hdr = @ptrCast(*pdb.LineBlockFragmentHeader, &subsect_info[line_index]); + line_index += @sizeOf(pdb.LineBlockFragmentHeader); + const start_line_index = line_index; + + const has_column = line_hdr.Flags.LF_HaveColumns; + // All line entries are stored inside their line block by ascending start address. // Heuristic: we want to find the last line entry that has a vaddr_start <= relative_address. // This is done with a simple linear search. @@ -427,11 +429,11 @@ fn printSourceAtAddressWindows(di: *DebugInfo, out_stream: var, relocated_addres }; } } - } - // Checking that we are not reading garbage after the (possibly) multiple block fragments. - if (line_index != subsection_end_index) { - return error.InvalidDebugInfo; + // Checking that we are not reading garbage after the (possibly) multiple block fragments. + if (line_index != subsection_end_index) { + return error.InvalidDebugInfo; + } } }, else => {}, -- cgit v1.2.3 From ae9b90cf6ea1d3f214a9058be8e147911b745f00 Mon Sep 17 00:00:00 2001 From: Sahnvour Date: Fri, 15 Mar 2019 21:45:38 +0100 Subject: print a message instead of returning an error when debug info comes from a source file not found (for example compiled on another computer) --- std/debug.zig | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'std/debug.zig') diff --git a/std/debug.zig b/std/debug.zig index 96b861e4a7..c85a982059 100644 --- a/std/debug.zig +++ b/std/debug.zig @@ -478,6 +478,11 @@ fn printSourceAtAddressWindows(di: *DebugInfo, out_stream: var, relocated_addres } } else |err| switch (err) { error.EndOfFile => {}, + error.FileNotFound => { + setTtyColor(TtyColor.Dim); + try out_stream.write("file not found\n\n"); + setTtyColor(TtyColor.White); + }, else => return err, } } else { -- cgit v1.2.3