authorgravatar for sahnvour@pm.meSahnvour <sahnvour@pm.me> 2019-03-15 21:44:12+01:00
committergravatar for sahnvour@pm.meSahnvour <sahnvour@pm.me> 2019-03-16 15:34:14+01:00
log704dfaaabf2cf2253a6d58cc25f6cd8eff8c87bd
tree15b997c992ce539d6dac8f7f1877543179e74eb8
parent094d40fb1a816a02e9f193f856049cf50503fdc4

avoid reading LineBlockFragmentHeader at all if the address is not in range, thus simplifying code and improving speed of execution


1 files changed, 18 insertions(+), 16 deletions(-)

std/debug.zig+18-16
...@@ -372,18 +372,20 @@ fn printSourceAtAddressWindows(di: *DebugInfo, out_stream: var, relocated_addres...@@ -372,18 +372,20 @@ fn printSourceAtAddressWindows(di: *DebugInfo, out_stream: var, relocated_addres
372 const frag_vaddr_start = coff_section.header.virtual_address + line_hdr.RelocOffset;372 const frag_vaddr_start = coff_section.header.virtual_address + line_hdr.RelocOffset;
373 const frag_vaddr_end = frag_vaddr_start + line_hdr.CodeSize;373 const frag_vaddr_end = frag_vaddr_start + line_hdr.CodeSize;
374374
375 // There is an unknown number of LineBlockFragmentHeaders (and their accompanying line and column records)375 if (relative_address >= frag_vaddr_start and relative_address < frag_vaddr_end) {
376 // from now on. We will iterate through them, and eventually find a LineInfo that we're interested in,376 // There is an unknown number of LineBlockFragmentHeaders (and their accompanying line and column records)
377 // breaking out to :subsections. If not, we will make sure to not read anything outside of this subsection.377 // from now on. We will iterate through them, and eventually find a LineInfo that we're interested in,
378 const subsection_end_index = sect_offset + subsect_hdr.Length;378 // breaking out to :subsections. If not, we will make sure to not read anything outside of this subsection.
379 while (line_index < subsection_end_index) {379
380 const block_hdr = @ptrCast(*pdb.LineBlockFragmentHeader, &subsect_info[line_index]);380 const subsection_end_index = sect_offset + subsect_hdr.Length;
381 line_index += @sizeOf(pdb.LineBlockFragmentHeader);381
382 const start_line_index = line_index;382 while (line_index < subsection_end_index) {
383383 const block_hdr = @ptrCast(*pdb.LineBlockFragmentHeader, &subsect_info[line_index]);
384 const has_column = line_hdr.Flags.LF_HaveColumns;384 line_index += @sizeOf(pdb.LineBlockFragmentHeader);
385385 const start_line_index = line_index;
386 if (relative_address >= frag_vaddr_start and relative_address < frag_vaddr_end) {386
387 const has_column = line_hdr.Flags.LF_HaveColumns;
388
387 // All line entries are stored inside their line block by ascending start address.389 // All line entries are stored inside their line block by ascending start address.
388 // Heuristic: we want to find the last line entry that has a vaddr_start <= relative_address.390 // Heuristic: we want to find the last line entry that has a vaddr_start <= relative_address.
389 // This is done with a simple linear search.391 // This is done with a simple linear search.
...@@ -427,11 +429,11 @@ fn printSourceAtAddressWindows(di: *DebugInfo, out_stream: var, relocated_addres...@@ -427,11 +429,11 @@ fn printSourceAtAddressWindows(di: *DebugInfo, out_stream: var, relocated_addres
427 };429 };
428 }430 }
429 }431 }
430 }
431432
432 // Checking that we are not reading garbage after the (possibly) multiple block fragments.433 // Checking that we are not reading garbage after the (possibly) multiple block fragments.
433 if (line_index != subsection_end_index) {434 if (line_index != subsection_end_index) {
434 return error.InvalidDebugInfo;435 return error.InvalidDebugInfo;
436 }
435 }437 }
436 },438 },
437 else => {},439 else => {},