authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-08-11 15:08:43-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-08-13 15:02:53-07:00
loga9e7fb0e0189e01ebf67b144aca3fd8c318925c3
tree3809f63bdc8902b8119805a2be7f07b3f37767d4
parente8e49efe211f85d854388e95c6fe0344f133ea2d

avoid a branch in resolveAddressesDwarf


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

lib/std/Build/Fuzz/WebServer.zig+2-2
...@@ -664,8 +664,8 @@ fn addEntryPoint(ws: *WebServer, coverage_id: u64, addr: u64) error{ AlreadyRepo...@@ -664,8 +664,8 @@ fn addEntryPoint(ws: *WebServer, coverage_id: u64, addr: u64) error{ AlreadyRepo
664 if (false) {664 if (false) {
665 const sl = coverage_map.source_locations[index];665 const sl = coverage_map.source_locations[index];
666 const file_name = coverage_map.coverage.stringAt(coverage_map.coverage.fileAt(sl.file).basename);666 const file_name = coverage_map.coverage.stringAt(coverage_map.coverage.fileAt(sl.file).basename);
667 log.debug("server found entry point {s}:{d}:{d}", .{667 log.debug("server found entry point for 0x{x} at {s}:{d}:{d}", .{
668 file_name, sl.line, sl.column,668 addr, file_name, sl.line, sl.column,
669 });669 });
670 }670 }
671 const gpa = ws.gpa;671 const gpa = ws.gpa;
lib/std/debug/Coverage.zig+16-14
...@@ -174,28 +174,30 @@ pub fn resolveAddressesDwarf(...@@ -174,28 +174,30 @@ pub fn resolveAddressesDwarf(
174 continue :next_pc;174 continue :next_pc;
175 }175 }
176 const cu = &d.compile_unit_list.items[range.compile_unit_index];176 const cu = &d.compile_unit_list.items[range.compile_unit_index];
177 if (cu.src_loc_cache == null) {
178 cov.mutex.unlock();
179 defer cov.mutex.lock();
180 d.populateSrcLocCache(gpa, cu) catch |err| switch (err) {
181 error.MissingDebugInfo, error.InvalidDebugInfo => {
182 out.* = SourceLocation.invalid;
183 continue :next_pc;
184 },
185 else => |e| return e,
186 };
187 }
188 const slc = &cu.src_loc_cache.?;
189 const table_addrs = slc.line_table.keys();
190 if (cu != prev_cu) {177 if (cu != prev_cu) {
191 prev_cu = cu;178 prev_cu = cu;
179 if (cu.src_loc_cache == null) {
180 cov.mutex.unlock();
181 defer cov.mutex.lock();
182 d.populateSrcLocCache(gpa, cu) catch |err| switch (err) {
183 error.MissingDebugInfo, error.InvalidDebugInfo => {
184 out.* = SourceLocation.invalid;
185 continue :next_pc;
186 },
187 else => |e| return e,
188 };
189 }
190 const slc = &cu.src_loc_cache.?;
191 const table_addrs = slc.line_table.keys();
192 line_table_i = std.sort.upperBound(u64, table_addrs, pc, struct {192 line_table_i = std.sort.upperBound(u64, table_addrs, pc, struct {
193 fn order(context: u64, item: u64) std.math.Order {193 fn order(context: u64, item: u64) std.math.Order {
194 return std.math.order(item, context);194 return std.math.order(item, context);
195 }195 }
196 }.order);196 }.order);
197 }197 }
198 while (line_table_i < table_addrs.len and table_addrs[line_table_i] < pc) line_table_i += 1;198 const slc = &cu.src_loc_cache.?;
199 const table_addrs = slc.line_table.keys();
200 while (line_table_i < table_addrs.len and table_addrs[line_table_i] <= pc) line_table_i += 1;
199201
200 const entry = slc.line_table.values()[line_table_i - 1];202 const entry = slc.line_table.values()[line_table_i - 1];
201 const corrected_file_index = entry.file - @intFromBool(slc.version < 5);203 const corrected_file_index = entry.file - @intFromBool(slc.version < 5);