aboutsummaryrefslogtreecommitdiff
path: root/lib/std/Build/Fuzz/WebServer.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2024-08-14 04:55:32 -0700
committerGitHub <noreply@github.com>2024-08-14 04:55:32 -0700
commitb7a1ef3e19039690b182a295dff7cffe5fcc521f (patch)
treed62b8bdee5b8f332941cd846435bddf667853341 /lib/std/Build/Fuzz/WebServer.zig
parentb470d2a7de20f8036c8976ec18ed1fb16a15c662 (diff)
parent72768bddcd815f84ac6d40ffd80258ceaa511cb9 (diff)
downloadzig-b7a1ef3e19039690b182a295dff7cffe5fcc521f.tar.gz
zig-b7a1ef3e19039690b182a295dff7cffe5fcc521f.zip
Merge pull request #21075 from ziglang/fuzz
fix several debug info bugs
Diffstat (limited to 'lib/std/Build/Fuzz/WebServer.zig')
-rw-r--r--lib/std/Build/Fuzz/WebServer.zig24
1 files changed, 21 insertions, 3 deletions
diff --git a/lib/std/Build/Fuzz/WebServer.zig b/lib/std/Build/Fuzz/WebServer.zig
index 17bc2c918f..950f3645ba 100644
--- a/lib/std/Build/Fuzz/WebServer.zig
+++ b/lib/std/Build/Fuzz/WebServer.zig
@@ -634,10 +634,28 @@ fn prepareTables(
const pcs = header.pcAddrs();
const source_locations = try gpa.alloc(Coverage.SourceLocation, pcs.len);
errdefer gpa.free(source_locations);
- debug_info.resolveAddresses(gpa, pcs, source_locations) catch |err| {
+
+ // Unfortunately the PCs array that LLVM gives us from the 8-bit PC
+ // counters feature is not sorted.
+ var sorted_pcs: std.MultiArrayList(struct { pc: u64, index: u32, sl: Coverage.SourceLocation }) = .{};
+ defer sorted_pcs.deinit(gpa);
+ try sorted_pcs.resize(gpa, pcs.len);
+ @memcpy(sorted_pcs.items(.pc), pcs);
+ for (sorted_pcs.items(.index), 0..) |*v, i| v.* = @intCast(i);
+ sorted_pcs.sortUnstable(struct {
+ addrs: []const u64,
+
+ pub fn lessThan(ctx: @This(), a_index: usize, b_index: usize) bool {
+ return ctx.addrs[a_index] < ctx.addrs[b_index];
+ }
+ }{ .addrs = sorted_pcs.items(.pc) });
+
+ debug_info.resolveAddresses(gpa, sorted_pcs.items(.pc), sorted_pcs.items(.sl)) catch |err| {
log.err("failed to resolve addresses to source locations: {s}", .{@errorName(err)});
return error.AlreadyReported;
};
+
+ for (sorted_pcs.items(.index), sorted_pcs.items(.sl)) |i, sl| source_locations[i] = sl;
gop.value_ptr.source_locations = source_locations;
ws.coverage_condition.broadcast();
@@ -664,8 +682,8 @@ fn addEntryPoint(ws: *WebServer, coverage_id: u64, addr: u64) error{ AlreadyRepo
if (false) {
const sl = coverage_map.source_locations[index];
const file_name = coverage_map.coverage.stringAt(coverage_map.coverage.fileAt(sl.file).basename);
- log.debug("server found entry point {s}:{d}:{d}", .{
- file_name, sl.line, sl.column,
+ log.debug("server found entry point for 0x{x} at {s}:{d}:{d}", .{
+ addr, file_name, sl.line, sl.column,
});
}
const gpa = ws.gpa;