Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion snapshots/basic_full/should_increment_x.lcov
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion snapshots/basic_full/should_increment_y.lcov
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion snapshots/basic_just_increment_x/should_increment_x.lcov
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion snapshots/basic_just_increment_y/should_increment_y.lcov
Original file line number Diff line number Diff line change
@@ -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
Expand Down
27 changes: 13 additions & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};
Expand Down Expand Up @@ -160,7 +160,7 @@ fn build_dwarf(debug_path: &Path) -> Result<Dwarf> {

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(),
Expand Down Expand Up @@ -227,19 +227,18 @@ static CARGO_HOME: std::sync::LazyLock<PathBuf> = std::sync::LazyLock::new(|| {
}
});

fn build_vaddr_entry_map<'a>(loader: &'a Loader, debug_path: &Path) -> Result<VaddrEntryMap<'a>> {
fn build_vaddr_entry_map<'a>(loader: &'a Loader) -> Result<VaddrEntryMap<'a>> {
let mut vaddr_entry_map = VaddrEntryMap::new();
let metadata = metadata(debug_path)?;
for vaddr in (0..metadata.len()).step_by(size_of::<u64>()) {
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;
};
Expand Down
Loading