| ... | @@ -634,10 +634,28 @@ fn prepareTables( | ... | @@ -634,10 +634,28 @@ fn prepareTables( |
| 634 | const pcs = header.pcAddrs(); | 634 | const pcs = header.pcAddrs(); |
| 635 | const source_locations = try gpa.alloc(Coverage.SourceLocation, pcs.len); | 635 | const source_locations = try gpa.alloc(Coverage.SourceLocation, pcs.len); |
| 636 | errdefer gpa.free(source_locations); | 636 | errdefer gpa.free(source_locations); |
| 637 | debug_info.resolveAddresses(gpa, pcs, source_locations) catch |err| { | 637 | |
| | 638 | // Unfortunately the PCs array that LLVM gives us from the 8-bit PC |
| | 639 | // counters feature is not sorted. |
| | 640 | var sorted_pcs: std.MultiArrayList(struct { pc: u64, index: u32, sl: Coverage.SourceLocation }) = .{}; |
| | 641 | defer sorted_pcs.deinit(gpa); |
| | 642 | try sorted_pcs.resize(gpa, pcs.len); |
| | 643 | @memcpy(sorted_pcs.items(.pc), pcs); |
| | 644 | for (sorted_pcs.items(.index), 0..) |*v, i| v.* = @intCast(i); |
| | 645 | sorted_pcs.sortUnstable(struct { |
| | 646 | addrs: []const u64, |
| | 647 | |
| | 648 | pub fn lessThan(ctx: @This(), a_index: usize, b_index: usize) bool { |
| | 649 | return ctx.addrs[a_index] < ctx.addrs[b_index]; |
| | 650 | } |
| | 651 | }{ .addrs = sorted_pcs.items(.pc) }); |
| | 652 | |
| | 653 | debug_info.resolveAddresses(gpa, sorted_pcs.items(.pc), sorted_pcs.items(.sl)) catch |err| { |
| 638 | log.err("failed to resolve addresses to source locations: {s}", .{@errorName(err)}); | 654 | log.err("failed to resolve addresses to source locations: {s}", .{@errorName(err)}); |
| 639 | return error.AlreadyReported; | 655 | return error.AlreadyReported; |
| 640 | }; | 656 | }; |
| | 657 | |
| | 658 | for (sorted_pcs.items(.index), sorted_pcs.items(.sl)) |i, sl| source_locations[i] = sl; |
| 641 | gop.value_ptr.source_locations = source_locations; | 659 | gop.value_ptr.source_locations = source_locations; |
| 642 | | 660 | |
| 643 | ws.coverage_condition.broadcast(); | 661 | ws.coverage_condition.broadcast(); |