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