Skip to content

Commit

Permalink
read: handle indexed addresses in range lists
Browse files Browse the repository at this point in the history
  • Loading branch information
philipc committed Jan 14, 2019
1 parent ff5d135 commit db16150
Show file tree
Hide file tree
Showing 4 changed files with 301 additions and 46 deletions.
12 changes: 11 additions & 1 deletion benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,9 @@ fn bench_parsing_debug_ranges(b: &mut test::Bencher) {
let debug_abbrev = read_section("debug_abbrev");
let debug_abbrev = DebugAbbrev::new(&debug_abbrev, LittleEndian);

let debug_addr = DebugAddr::from(EndianSlice::new(&[], LittleEndian));
let debug_addr_base = DebugAddrBase(0);

let debug_ranges = read_section("debug_ranges");
let debug_ranges = DebugRanges::new(&debug_ranges, LittleEndian);
let debug_rnglists = DebugRngLists::new(&[], LittleEndian);
Expand Down Expand Up @@ -336,7 +339,14 @@ fn bench_parsing_debug_ranges(b: &mut test::Bencher) {
b.iter(|| {
for &(offset, version, address_size, base_address) in &*offsets {
let mut ranges = rnglists
.ranges(offset, version, address_size, base_address)
.ranges(
offset,
version,
address_size,
base_address,
&debug_addr,
debug_addr_base,
)
.expect("Should parse ranges OK");
while let Some(range) = ranges.next().expect("Should parse next range") {
test::black_box(range);
Expand Down
68 changes: 60 additions & 8 deletions examples/dwarfdump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1251,15 +1251,15 @@ fn dump_attr_value<R: Reader, W: Write>(
}
gimli::AttributeValue::RangeListsRef(offset) => {
writeln!(w, "0x{:08x}", offset.0)?;
dump_range_list(w, &dwarf.ranges, offset, unit)?;
dump_range_list(w, offset, unit, dwarf)?;
}
gimli::AttributeValue::DebugRngListsBase(base) => {
writeln!(w, "<.debug_rnglists+0x{:08x}>", base.0)?;
}
gimli::AttributeValue::DebugRngListsIndex(index) => {
let offset = dwarf.ranges.get_offset(unit.rnglists_base, index)?;
writeln!(w, "0x{:08x}", offset.0)?;
dump_range_list(w, &dwarf.ranges, offset, unit)?;
dump_range_list(w, offset, unit, dwarf)?;
}
gimli::AttributeValue::DebugTypesRef(signature) => {
dump_type_signature(w, signature, dwarf.endian)?;
Expand Down Expand Up @@ -1722,13 +1722,22 @@ fn dump_loc_list<R: Reader, W: Write>(

fn dump_range_list<R: Reader, W: Write>(
w: &mut W,
rnglists: &gimli::RangeLists<R>,
offset: gimli::RangeListsOffset<R::Offset>,
unit: &Unit<R>,
dwarf: &gimli::Dwarf<R, R::Endian>,
) -> Result<()> {
let raw_ranges = rnglists.raw_ranges(offset, unit.version, unit.address_size)?;
let raw_ranges = dwarf
.ranges
.raw_ranges(offset, unit.version, unit.address_size)?;
let raw_ranges: Vec<_> = raw_ranges.collect()?;
let mut ranges = rnglists.ranges(offset, unit.version, unit.address_size, unit.base_address)?;
let mut ranges = dwarf.ranges.ranges(
offset,
unit.version,
unit.address_size,
unit.base_address,
&dwarf.debug_addr,
unit.addr_base,
)?;
writeln!(
w,
"\t\tranges: {} at {} offset {} (0x{:08x})",
Expand All @@ -1747,6 +1756,52 @@ fn dump_range_list<R: Reader, W: Write>(
gimli::RawRngListEntry::BaseAddress { addr } => {
writeln!(w, "<new base address 0x{:08x}>", addr)?;
}
gimli::RawRngListEntry::BaseAddressx { addr } => {
let addr_val =
dwarf
.debug_addr
.get_address(unit.address_size, unit.addr_base, addr)?;
writeln!(w, "<new base addressx [{}]0x{:08x}>", addr.0, addr_val)?;
}
gimli::RawRngListEntry::StartxEndx { begin, end } => {
let begin_val =
dwarf
.debug_addr
.get_address(unit.address_size, unit.addr_base, begin)?;
let end_val =
dwarf
.debug_addr
.get_address(unit.address_size, unit.addr_base, end)?;
let range = if begin_val == end_val {
gimli::Range {
begin: begin_val,
end: end_val,
}
} else {
ranges.next()?.unwrap()
};
writeln!(
w,
"<startx-endx \
low-off: [{}]0x{:08x} addr 0x{:08x} \
high-off: [{}]0x{:08x} addr 0x{:08x}>",
begin.0, begin_val, range.begin, end.0, end_val, range.end
)?;
}
gimli::RawRngListEntry::StartxLength { begin, length } => {
let begin_val =
dwarf
.debug_addr
.get_address(unit.address_size, unit.addr_base, begin)?;
let range = ranges.next()?.unwrap();
writeln!(
w,
"<startx-length \
low-off: [{}]0x{:08x} addr 0x{:08x} \
high-off: 0x{:08x} addr 0x{:08x}>",
begin.0, begin_val, range.begin, length, range.end
)?;
}
gimli::RawRngListEntry::OffsetPair { begin, end } => {
let range = ranges.next()?.unwrap();
writeln!(
Expand Down Expand Up @@ -1781,9 +1836,6 @@ fn dump_range_list<R: Reader, W: Write>(
begin, range.begin, length, range.end
)?;
}
_ => {
panic!("AddressIndex not handled, should already have errored out");
}
};
}
Ok(())
Expand Down
Loading

0 comments on commit db16150

Please sign in to comment.