commit a726e09389aceff39f4478f215f4991a5f148e8d (tree)
parent 022bca9b0600da3dda8b30fefe8eb817647b0f08
Author: Andrew Kelley <andrew@ziglang.org>
Date: Tue, 13 Aug 2024 19:29:55 -0700
std.debug.Coverage.resolveAddressesDwarf: assert sorted
Diffstat:
2 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/lib/std/debug/Coverage.zig b/lib/std/debug/Coverage.zig
@@ -145,6 +145,7 @@ pub const ResolveAddressesDwarfError = Dwarf.ScanError;
pub fn resolveAddressesDwarf(
cov: *Coverage,
gpa: Allocator,
+ /// Asserts the addresses are in ascending order.
sorted_pc_addrs: []const u64,
/// Asserts its length equals length of `sorted_pc_addrs`.
output: []SourceLocation,
@@ -156,11 +157,15 @@ pub fn resolveAddressesDwarf(
var range_i: usize = 0;
var range: *std.debug.Dwarf.Range = &d.ranges.items[0];
var line_table_i: usize = undefined;
+ var prev_pc: u64 = 0;
var prev_cu: ?*std.debug.Dwarf.CompileUnit = null;
// Protects directories and files tables from other threads.
cov.mutex.lock();
defer cov.mutex.unlock();
next_pc: for (sorted_pc_addrs, output) |pc, *out| {
+ assert(pc >= prev_pc);
+ prev_pc = pc;
+
while (pc >= range.end) {
range_i += 1;
if (range_i >= d.ranges.items.len) {
diff --git a/lib/std/debug/Info.zig b/lib/std/debug/Info.zig
@@ -51,6 +51,7 @@ pub const ResolveAddressesError = Coverage.ResolveAddressesDwarfError;
pub fn resolveAddresses(
info: *Info,
gpa: Allocator,
+ /// Asserts the addresses are in ascending order.
sorted_pc_addrs: []const u64,
/// Asserts its length equals length of `sorted_pc_addrs`.
output: []SourceLocation,