Skip to content

Commit

Permalink
read/op: add ExpressionKind
Browse files Browse the repository at this point in the history
DWARF expressions can be used to either compute a value or
a location description, depending on context, and this affects
the result of the evaluation, and which operations are valid
within them.

Use the attribute tag to determine the expression kind for
expressions in DIE attributes.
  • Loading branch information
philipc committed Aug 14, 2023
1 parent 3947879 commit 5d2b0af
Show file tree
Hide file tree
Showing 6 changed files with 257 additions and 141 deletions.
4 changes: 2 additions & 2 deletions crates/examples/src/bin/dwarfdump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1434,8 +1434,8 @@ fn dump_attr_value<R: Reader, W: Write>(
}
};
}
gimli::AttributeValue::Exprloc(ref data) => {
if let gimli::AttributeValue::Exprloc(_) = attr.raw_value() {
gimli::AttributeValue::Exprloc(ref data, _kind) => {
if let gimli::AttributeValue::Exprloc(..) = attr.raw_value() {
write!(w, "len 0x{:04x}: ", data.0.len())?;
for byte in data.0.to_slice()?.iter() {
write!(w, "{:02x}", byte)?;
Expand Down
12 changes: 12 additions & 0 deletions src/read/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,11 @@ pub enum Error {
/// An expression-terminating operation was followed by something
/// other than the end of the expression or a piece operation.
InvalidExpressionTerminator(u64),
/// An expression for a value contained an operation that is only valid for location
/// descriptions.
InvalidValueExpression,
/// Cannot evaluate an expression without knowing its kind.
UnknownExpressionKind,
/// Division or modulus by zero when evaluating an expression.
DivisionByZero,
/// An expression operation used mismatching types.
Expand Down Expand Up @@ -520,6 +525,13 @@ impl Error {
"DWARF expression has piece followed by non-piece expression at end"
}
Error::InvalidExpressionTerminator(_) => "Expected DW_OP_piece or DW_OP_bit_piece",
Error::InvalidValueExpression => {
"An expression for a value contained an operation that is only valid for location \
descriptions"
}
Error::UnknownExpressionKind => {
"Cannot evaluate an expression without knowing its kind"
}
Error::DivisionByZero => "Division or modulus by zero when evaluating expression",
Error::TypeMismatch => "Type mismatch when evaluating expression",
Error::IntegralTypeRequired => "Integral type expected when evaluating expression",
Expand Down
Loading

0 comments on commit 5d2b0af

Please sign in to comment.