aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSahnvour <sahnvour@pm.me>2019-03-15 21:44:12 +0100
committerSahnvour <sahnvour@pm.me>2019-03-16 15:34:14 +0100
commit704dfaaabf2cf2253a6d58cc25f6cd8eff8c87bd (patch)
tree15b997c992ce539d6dac8f7f1877543179e74eb8
parent094d40fb1a816a02e9f193f856049cf50503fdc4 (diff)
downloadzig-704dfaaabf2cf2253a6d58cc25f6cd8eff8c87bd.tar.gz
zig-704dfaaabf2cf2253a6d58cc25f6cd8eff8c87bd.zip
avoid reading LineBlockFragmentHeader at all if the address is not in range, thus simplifying code and improving speed of execution
-rw-r--r--std/debug.zig34
1 files changed, 18 insertions, 16 deletions
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 => {},