Skip to content

Commit 159f3cf

Browse files
committed
dwarfdump: display indexed addresses in expressions
1 parent 552cb89 commit 159f3cf

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

crates/examples/src/bin/dwarfdump.rs

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,7 +1259,7 @@ fn dump_attr_value<R: Reader, W: Write>(
12591259
}
12601260
write!(w, ": ")?;
12611261
}
1262-
dump_exprloc(w, unit.encoding(), data)?;
1262+
dump_exprloc(w, unit, data)?;
12631263
writeln!(w)?;
12641264
}
12651265
gimli::AttributeValue::Flag(true) => {
@@ -1463,21 +1463,21 @@ fn dump_file_index<R: Reader, W: Write>(
14631463

14641464
fn dump_exprloc<R: Reader, W: Write>(
14651465
w: &mut W,
1466-
encoding: gimli::Encoding,
1466+
unit: gimli::UnitRef<R>,
14671467
data: &gimli::Expression<R>,
14681468
) -> Result<()> {
14691469
let mut pc = data.0.clone();
14701470
let mut space = false;
14711471
while pc.len() != 0 {
14721472
let pc_clone = pc.clone();
1473-
match gimli::Operation::parse(&mut pc, encoding) {
1473+
match gimli::Operation::parse(&mut pc, unit.encoding()) {
14741474
Ok(op) => {
14751475
if space {
14761476
write!(w, " ")?;
14771477
} else {
14781478
space = true;
14791479
}
1480-
dump_op(w, encoding, pc_clone, op)?;
1480+
dump_op(w, unit, pc_clone, op)?;
14811481
}
14821482
Err(gimli::Error::InvalidExpression(op)) => {
14831483
writeln!(w, "WARNING: unsupported operation 0x{:02x}", op.0)?;
@@ -1502,7 +1502,7 @@ fn dump_exprloc<R: Reader, W: Write>(
15021502

15031503
fn dump_op<R: Reader, W: Write>(
15041504
w: &mut W,
1505-
encoding: gimli::Encoding,
1505+
unit: gimli::UnitRef<R>,
15061506
mut pc: R,
15071507
op: gimli::Operation<R>,
15081508
) -> Result<()> {
@@ -1602,7 +1602,7 @@ fn dump_op<R: Reader, W: Write>(
16021602
}
16031603
gimli::Operation::ImplicitValue { data } => {
16041604
let data = data.to_slice()?;
1605-
write!(w, " 0x{:08x} contents 0x", data.len())?;
1605+
write!(w, " len {:#x} contents 0x", data.len())?;
16061606
for byte in data.iter() {
16071607
write!(w, "{:02x}", byte)?;
16081608
}
@@ -1612,20 +1612,24 @@ fn dump_op<R: Reader, W: Write>(
16121612
}
16131613
gimli::Operation::EntryValue { expression } => {
16141614
write!(w, "(")?;
1615-
dump_exprloc(w, encoding, &gimli::Expression(expression))?;
1615+
dump_exprloc(w, unit, &gimli::Expression(expression))?;
16161616
write!(w, ")")?;
16171617
}
16181618
gimli::Operation::ParameterRef { offset } => {
16191619
write!(w, " 0x{:08x}", offset.0)?;
16201620
}
16211621
gimli::Operation::Address { address } => {
1622-
write!(w, " 0x{:08x}", address)?;
1622+
write!(w, " {:#x}", address)?;
16231623
}
16241624
gimli::Operation::AddressIndex { index } => {
1625-
write!(w, " 0x{:08x}", index.0)?;
1625+
write!(w, " {:#x}", index.0)?;
1626+
let address = unit.address(index)?;
1627+
write!(w, " ({:#x})", address)?;
16261628
}
16271629
gimli::Operation::ConstantIndex { index } => {
1628-
write!(w, " 0x{:08x}", index.0)?;
1630+
write!(w, " {:#x}", index.0)?;
1631+
let address = unit.address(index)?;
1632+
write!(w, " ({:#x})", address)?;
16291633
}
16301634
gimli::Operation::TypedLiteral { base_type, value } => {
16311635
write!(w, " type 0x{:08x} contents 0x", base_type.0)?;
@@ -1730,7 +1734,7 @@ fn dump_loc_list<R: Reader, W: Write>(
17301734
begin.0, begin_val, end.0, end_val,
17311735
)?;
17321736
dump_range(w, range)?;
1733-
dump_exprloc(w, unit.encoding(), data)?;
1737+
dump_exprloc(w, unit, data)?;
17341738
writeln!(w)?;
17351739
}
17361740
gimli::RawLocListEntry::StartxLength {
@@ -1745,7 +1749,7 @@ fn dump_loc_list<R: Reader, W: Write>(
17451749
begin.0, begin_val, length,
17461750
)?;
17471751
dump_range(w, range)?;
1748-
dump_exprloc(w, unit.encoding(), data)?;
1752+
dump_exprloc(w, unit, data)?;
17491753
writeln!(w)?;
17501754
}
17511755
gimli::RawLocListEntry::AddressOrOffsetPair {
@@ -1760,12 +1764,12 @@ fn dump_loc_list<R: Reader, W: Write>(
17601764
} => {
17611765
write!(w, "<offset-pair 0x{:08x}, 0x{:08x}>", begin, end)?;
17621766
dump_range(w, range)?;
1763-
dump_exprloc(w, unit.encoding(), data)?;
1767+
dump_exprloc(w, unit, data)?;
17641768
writeln!(w)?;
17651769
}
17661770
gimli::RawLocListEntry::DefaultLocation { ref data } => {
17671771
write!(w, "<default location>")?;
1768-
dump_exprloc(w, unit.encoding(), data)?;
1772+
dump_exprloc(w, unit, data)?;
17691773
writeln!(w)?;
17701774
}
17711775
gimli::RawLocListEntry::StartEnd {
@@ -1775,7 +1779,7 @@ fn dump_loc_list<R: Reader, W: Write>(
17751779
} => {
17761780
write!(w, "<start-end 0x{:08x}, 0x{:08x}>", begin, end)?;
17771781
dump_range(w, range)?;
1778-
dump_exprloc(w, unit.encoding(), data)?;
1782+
dump_exprloc(w, unit, data)?;
17791783
writeln!(w)?;
17801784
}
17811785
gimli::RawLocListEntry::StartLength {
@@ -1785,7 +1789,7 @@ fn dump_loc_list<R: Reader, W: Write>(
17851789
} => {
17861790
write!(w, "<start-length 0x{:08x}, 0x{:08x}>", begin, length)?;
17871791
dump_range(w, range)?;
1788-
dump_exprloc(w, unit.encoding(), data)?;
1792+
dump_exprloc(w, unit, data)?;
17891793
writeln!(w)?;
17901794
}
17911795
};

0 commit comments

Comments
 (0)