From f3d54443f6d8d485f0b480cf3719d9f65f4f64cc Mon Sep 17 00:00:00 2001 From: Samuel Moelius Date: Thu, 22 May 2025 10:29:00 +0000 Subject: [PATCH 1/2] Simplify `build_vaddr_entry_map` --- src/lib.rs | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index a2ce84a..2ef2384 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,7 +5,7 @@ use cargo_metadata::MetadataCommand; use std::{ collections::BTreeMap, env::var_os, - fs::{metadata, File, OpenOptions}, + fs::{File, OpenOptions}, io::Write, path::{Path, PathBuf}, }; @@ -160,7 +160,7 @@ fn build_dwarf(debug_path: &Path) -> Result { let loader = Box::leak(Box::new(loader)); - let vaddr_entry_map = build_vaddr_entry_map(loader, debug_path)?; + let vaddr_entry_map = build_vaddr_entry_map(loader)?; Ok(Dwarf { path: debug_path.to_path_buf(), @@ -227,19 +227,18 @@ static CARGO_HOME: std::sync::LazyLock = std::sync::LazyLock::new(|| { } }); -fn build_vaddr_entry_map<'a>(loader: &'a Loader, debug_path: &Path) -> Result> { +fn build_vaddr_entry_map<'a>(loader: &'a Loader) -> Result> { let mut vaddr_entry_map = VaddrEntryMap::new(); - let metadata = metadata(debug_path)?; - for vaddr in (0..metadata.len()).step_by(size_of::()) { - let location = loader.find_location(vaddr).map_err(|error| { - anyhow!( - "failed to find location for address 0x{vaddr:x}: {}", - error.to_string() - ) - })?; - let Some(location) = location else { - continue; - }; + // smoelius: Based on `addr2line`'s `--all` option. See: + // - https://github.com/gimli-rs/addr2line/blob/632348701feda978e324c5f5bd342b3ce974d589/src/bin/addr2line.rs#L185 + // - https://github.com/gimli-rs/addr2line/blob/632348701feda978e324c5f5bd342b3ce974d589/src/bin/addr2line.rs#L34 + let iter = loader.find_location_range(0, !0).map_err(|error| { + anyhow!( + "failed to construct location range iterator: {}", + error.to_string() + ) + })?; + for (vaddr, _len, location) in iter { let Some(file) = location.file else { continue; }; From 69f75dedcdd9e91578b5bd578c5986836196281b Mon Sep 17 00:00:00 2001 From: Samuel Moelius Date: Thu, 21 Aug 2025 13:26:07 -0400 Subject: [PATCH 2/2] Update lcov files --- snapshots/basic_full/should_increment_x.lcov | 2 +- snapshots/basic_full/should_increment_y.lcov | 2 +- snapshots/basic_just_increment_x/should_increment_x.lcov | 2 +- snapshots/basic_just_increment_y/should_increment_y.lcov | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/snapshots/basic_full/should_increment_x.lcov b/snapshots/basic_full/should_increment_x.lcov index 605a6e8..508323f 100644 --- a/snapshots/basic_full/should_increment_x.lcov +++ b/snapshots/basic_full/should_increment_x.lcov @@ -1,5 +1,5 @@ SF:$DIR/fixtures/basic/programs/basic/src/lib.rs -DA:5,11 +DA:5,17 DA:10,0 DA:15,3 DA:20,0 diff --git a/snapshots/basic_full/should_increment_y.lcov b/snapshots/basic_full/should_increment_y.lcov index b8cdec7..61bd9e8 100644 --- a/snapshots/basic_full/should_increment_y.lcov +++ b/snapshots/basic_full/should_increment_y.lcov @@ -1,5 +1,5 @@ SF:$DIR/fixtures/basic/programs/basic/src/lib.rs -DA:5,12 +DA:5,18 DA:10,0 DA:15,0 DA:20,3 diff --git a/snapshots/basic_just_increment_x/should_increment_x.lcov b/snapshots/basic_just_increment_x/should_increment_x.lcov index 605a6e8..508323f 100644 --- a/snapshots/basic_just_increment_x/should_increment_x.lcov +++ b/snapshots/basic_just_increment_x/should_increment_x.lcov @@ -1,5 +1,5 @@ SF:$DIR/fixtures/basic/programs/basic/src/lib.rs -DA:5,11 +DA:5,17 DA:10,0 DA:15,3 DA:20,0 diff --git a/snapshots/basic_just_increment_y/should_increment_y.lcov b/snapshots/basic_just_increment_y/should_increment_y.lcov index b8cdec7..61bd9e8 100644 --- a/snapshots/basic_just_increment_y/should_increment_y.lcov +++ b/snapshots/basic_just_increment_y/should_increment_y.lcov @@ -1,5 +1,5 @@ SF:$DIR/fixtures/basic/programs/basic/src/lib.rs -DA:5,12 +DA:5,18 DA:10,0 DA:15,0 DA:20,3