Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable builtin_split_dwarf_loader for Windows #269

Merged
merged 1 commit into from
Feb 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 0 additions & 4 deletions examples/addr2line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ fn main() {
dwarf.load_sup(&mut load_sup_section).unwrap();
}

#[cfg(unix)]
let mut split_dwarf_loader = addr2line::builtin_split_dwarf_loader::SplitDwarfLoader::new(
|data, endian| {
gimli::EndianSlice::new(arena_data.alloc(Cow::Owned(data.into_owned())), endian)
Expand Down Expand Up @@ -244,10 +243,7 @@ fn main() {
let mut printed_anything = false;
if let Some(probe) = probe {
let frames = ctx.find_frames(probe);
#[cfg(unix)]
let frames = split_dwarf_loader.run(frames).unwrap();
#[cfg(not(unix))]
let frames = frames.skip_all_loads().unwrap();
let mut frames = frames.enumerate();
while let Some((i, frame)) = frames.next().unwrap() {
if opts.pretty && i != 0 {
Expand Down
9 changes: 9 additions & 0 deletions src/builtin_split_dwarf_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ fn convert_path<R: gimli::Reader<Endian = gimli::RunTimeEndian>>(
Ok(PathBuf::from(s))
}

#[cfg(not(unix))]
fn convert_path<R: gimli::Reader<Endian = gimli::RunTimeEndian>>(
r: &R,
) -> Result<PathBuf, gimli::Error> {
let bytes = r.to_slice()?;
let s = std::str::from_utf8(&bytes).map_err(|_| gimli::Error::BadUtf8)?;
Ok(PathBuf::from(s))
}

fn load_section<'data: 'file, 'file, O, R, F>(
id: gimli::SectionId,
file: &'file O,
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ mod maybe_small {
pub type IntoIter<T> = alloc::vec::IntoIter<T>;
}

#[cfg(all(unix, feature = "std", feature = "object", feature = "memmap2"))]
#[cfg(all(feature = "std", feature = "object", feature = "memmap2"))]
/// A simple builtin split DWARF loader.
pub mod builtin_split_dwarf_loader;
mod function;
Expand Down
4 changes: 0 additions & 4 deletions tests/correctness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ fn correctness() {

let dwarf = gimli::Dwarf::load(|id| load_section(id, file, endian)).unwrap();
let ctx = Context::from_dwarf(dwarf).unwrap();
#[cfg(unix)]
let mut split_dwarf_loader = addr2line::builtin_split_dwarf_loader::SplitDwarfLoader::new(
|data, endian| gimli::EndianArcSlice::new(Arc::from(&*data), endian),
None,
Expand All @@ -81,10 +80,7 @@ fn correctness() {
let ip = sym.wrapping_sub(bias.unwrap());

let frames = ctx.find_frames(ip);
#[cfg(unix)]
let frames = split_dwarf_loader.run(frames).unwrap();
#[cfg(not(unix))]
let frames = frames.skip_all_loads().unwrap();
let frame = frames.last().unwrap().unwrap();
let name = frame.function.as_ref().unwrap().demangle().unwrap();
// Old rust versions generate DWARF with wrong linkage name,
Expand Down