Skip to content

add DWARF Wasm locations #43

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
18 changes: 13 additions & 5 deletions parser/src/file/dwarf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3680,11 +3680,14 @@ where
// Skip and Call could be implemented if needed.
return Ok(pieces);
}
gimli::Operation::WasmLocal { .. }
| gimli::Operation::WasmGlobal { .. }
| gimli::Operation::WasmStack { .. } => {
// Unimplemented.
location = Some((Location::Other, false));
gimli::Operation::WasmLocal { index } => {
location = Some((Location::WasmLocal { index }, false));
}
gimli::Operation::WasmGlobal { index } => {
location = Some((Location::WasmGlobal { index }, false));
}
gimli::Operation::WasmStack { index } => {
location = Some((Location::WasmStack { index }, false));
}
}
if let Some((location, is_value)) = location {
Expand All @@ -3707,6 +3710,11 @@ where
Size::new(size_in_bits),
);
}
// https://docs.rs/gimli/latest/gimli/read/enum.Operation.html#variant.StackValue
// Commonly used for Wasm to terminate the expression.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I must admit I'm not familiar enough with DWARF and not sure about that.
My understanding is that Wasm emits something like this: DW_OP_WASM_location ..., DW_OP_stack_value. Where DW_OP_stack_value is used to terminate the expression. Does this make sense?

I'm curious why this seems to be specific to Wasm.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It appears to me that this is because DW_OP_WASM_location is only an address for the case for where wasm-op is wasm-local-indirect. For the other wasm-op values, the semantics are that it pushes the value of the local/global/operand onto the DWARF stack, so the result of the expression must be an implicit stack value rather than a location description. In my view this is a strange design, but I don't have much to do with Wasm so I don't know the reasons.

So rather than adding a case for Operation::StackValue here, what you need to do is change the gimli::Operation::Wasm* support to push a value onto the stack instead of setting location.

Also, it looks like gimli needs to be updated to add gimli::Operation::WasmLocalIndirect. I'm happy for that to be done later though if you don't need it yet.

gimli::Operation::StackValue => {
add_piece(&mut pieces, location, 0, is_value, Size::none());
}
_ => {
return Err(gimli::Error::InvalidPiece.into());
}
Expand Down
15 changes: 15 additions & 0 deletions parser/src/location.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,21 @@ pub enum Location {
/// The offset.
offset: u64,
},
/// The value is stored in a Wasm local
WasmLocal {
/// The index of the local
index: u32,
},
/// The value is stored in a Wasm global
WasmGlobal {
/// The index of the global
index: u32,
},
/// The value is stored on the Wasm stack
WasmStack {
/// The index in the stack
index: u32,
},
/// The value is more complex than any of the above variants.
Other,
}
Expand Down