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

.debug_aranges improvements #539

Merged
merged 5 commits into from
Dec 24, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,12 @@ fn bench_parsing_debug_aranges(b: &mut test::Bencher) {
let debug_aranges = DebugAranges::new(&debug_aranges, LittleEndian);

b.iter(|| {
let mut aranges = debug_aranges.items();
while let Some(arange) = aranges.next().expect("Should parse arange OK") {
test::black_box(arange);
let mut headers = debug_aranges.headers();
while let Some(header) = headers.next().expect("Should parse arange header OK") {
let mut entries = header.entries();
while let Some(arange) = entries.next().expect("Should parse arange entry OK") {
test::black_box(arange);
}
}
});
}
Expand Down
47 changes: 22 additions & 25 deletions examples/dwarfdump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ where
}
if flags.aranges {
let debug_aranges = &gimli::Section::load(&mut load_section).unwrap();
dump_aranges(w, debug_aranges, &dwarf.debug_info)?;
dump_aranges(w, debug_aranges)?;
}
if flags.pubtypes {
let debug_pubtypes = &gimli::Section::load(&mut load_section).unwrap();
Expand Down Expand Up @@ -2108,36 +2108,33 @@ fn dump_pubtypes<R: Reader, W: Write>(
fn dump_aranges<R: Reader, W: Write>(
w: &mut W,
debug_aranges: &gimli::DebugAranges<R>,
debug_info: &gimli::DebugInfo<R>,
) -> Result<()> {
writeln!(w, "\n.debug_aranges")?;

let mut cu_die_offset = gimli::DebugInfoOffset(0);
let mut prev_cu_offset = None;
let mut aranges = debug_aranges.items();
while let Some(arange) = aranges.next()? {
let cu_offset = arange.debug_info_offset();
if Some(cu_offset) != prev_cu_offset {
let cu = debug_info.header_from_offset(cu_offset)?;
cu_die_offset = gimli::DebugInfoOffset(cu_offset.0 + cu.header_size());
prev_cu_offset = Some(cu_offset);
}
if let Some(segment) = arange.segment() {
write!(
w,
"arange starts at seg,off 0x{:08x},0x{:08x}, ",
segment,
arange.address()
)?;
} else {
write!(w, "arange starts at 0x{:08x}, ", arange.address())?;
}
let mut headers = debug_aranges.headers();
while let Some(header) = headers.next()? {
writeln!(
w,
"length of 0x{:08x}, cu_die_offset = 0x{:08x}",
arange.length(),
cu_die_offset.0
"Address Range Header: length = 0x{:08x}, version = 0x{:04x}, cu_offset = 0x{:08x}, addr_size = 0x{:02x}, seg_size = 0x{:02x}",
header.length(),
header.encoding().version,
header.debug_info_offset().0,
header.encoding().address_size,
header.segment_size(),
)?;
let mut aranges = header.entries();
while let Some(arange) = aranges.next()? {
let range = arange.range();
if let Some(segment) = arange.segment() {
writeln!(
w,
"[0x{:016x}, 0x{:016x}) segment 0x{:x}",
range.begin, range.end, segment
)?;
} else {
writeln!(w, "[0x{:016x}, 0x{:016x})", range.begin, range.end)?;
}
}
}
Ok(())
}
9 changes: 6 additions & 3 deletions fuzz/fuzz_targets/debug_aranges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ use libfuzzer_sys::fuzz_target;

fuzz_target!(|debug_aranges: &[u8]| {
let debug_aranges = DebugAranges::new(&debug_aranges, LittleEndian);
let mut items = debug_aranges.items();
while let Ok(Some(_entry)) = items.next() {
continue;
let mut headers = debug_aranges.headers();
while let Ok(Some(header)) = headers.next() {
let mut entries = header.entries();
while let Ok(Some(_entry)) = entries.next() {
continue;
}
}
});
4 changes: 4 additions & 0 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ pub struct DebugAddrBase<T = usize>(pub T);
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct DebugAddrIndex<T = usize>(pub T);

/// An offset into the `.debug_aranges` section.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct DebugArangesOffset<T = usize>(pub T);

/// An offset into the `.debug_info` section.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Ord, PartialOrd, Hash)]
pub struct DebugInfoOffset<T = usize>(pub T);
Expand Down
Loading