diff --git a/crates/debug/src/transform/expression.rs b/crates/debug/src/transform/expression.rs index a1a651586b..8544a9678f 100644 --- a/crates/debug/src/transform/expression.rs +++ b/crates/debug/src/transform/expression.rs @@ -600,13 +600,25 @@ impl<'a, 'b> ValueLabelRangesBuilder<'a, 'b> { mod tests { use super::compile_expression; use super::{AddressTransform, FunctionFrameInfo, ValueLabel, ValueLabelsRanges}; - use gimli::{self, Encoding, EndianSlice, Expression, RunTimeEndian}; + use gimli::{self, constants, Encoding, EndianSlice, Expression, RunTimeEndian}; use wasmtime_environ::CompiledFunction; + macro_rules! dw_op { + (DW_OP_WASM_location) => { + 0xed + }; + ($i:literal) => { + $i + }; + ($d:ident) => { + constants::$d.0 as u8 + }; + } + macro_rules! expression { - ($($i:literal),*) => { + ($($t:tt),*) => { Expression(EndianSlice::new( - &[$($i),*], + &[$(dw_op!($t)),*], RunTimeEndian::Little, )) } @@ -625,8 +637,7 @@ mod tests { let (val1, val3, val20) = (ValueLabel::new(1), ValueLabel::new(3), ValueLabel::new(20)); - // DW_OP_WASM_location 0x0 +20, DW_OP_stack_value - let e = expression!(0xed, 0x00, 0x14, 0x9f); + let e = expression!(DW_OP_WASM_location, 0x0, 20, DW_OP_stack_value); let ce = compile_expression(&e, DWARF_ENCODING, None) .expect("non-error") .expect("expression"); @@ -641,8 +652,14 @@ mod tests { } ); - // DW_OP_WASM_location 0x0 +1, DW_OP_plus_uconst 0x10, DW_OP_stack_value - let e = expression!(0xed, 0x00, 0x01, 0x23, 0x10, 0x9f); + let e = expression!( + DW_OP_WASM_location, + 0x0, + 1, + DW_OP_plus_uconst, + 0x10, + DW_OP_stack_value + ); let ce = compile_expression(&e, DWARF_ENCODING, None) .expect("non-error") .expect("expression"); @@ -660,8 +677,7 @@ mod tests { } ); - // Frame base: DW_OP_WASM_location 0x0 +3, DW_OP_stack_value - let e = expression!(0xed, 0x00, 0x03, 0x9f); + let e = expression!(DW_OP_WASM_location, 0x0, 3, DW_OP_stack_value); let fe = compile_expression(&e, DWARF_ENCODING, None).expect("non-error"); // DW_OP_fpreg 0x12 let e = expression!(0x91, 0x12); @@ -681,6 +697,34 @@ mod tests { need_deref: true } ); + + let e = expression!( + DW_OP_WASM_location, + 0x0, + 1, + DW_OP_plus_uconst, + 5, + DW_OP_deref, + DW_OP_stack_value + ); + let ce = compile_expression(&e, DWARF_ENCODING, None) + .expect("non-error") + .expect("expression"); + assert_eq!( + ce, + CompiledExpression { + parts: vec![ + CompiledExpressionPart::Local { + label: val1, + trailing: false + }, + CompiledExpressionPart::Code(vec![35, 5]), + CompiledExpressionPart::Deref, + CompiledExpressionPart::Code(vec![6, 159]) + ], + need_deref: false + } + ); } fn create_mock_address_transform() -> AddressTransform { diff --git a/crates/debug/src/transform/utils.rs b/crates/debug/src/transform/utils.rs index 0ebcba15b6..1864f7d40e 100644 --- a/crates/debug/src/transform/utils.rs +++ b/crates/debug/src/transform/utils.rs @@ -10,7 +10,7 @@ use wasmtime_environ::{CompiledFunctions, ModuleMemoryOffset}; /// WasmtimeVMContext. /// /// For unwrapping Wasm pointer, the WasmtimeVMContext has the `set()` method -/// that allows to contol current Wasm memory to inspect. +/// that allows to control current Wasm memory to inspect. /// Notice that "set_vmctx_memory" is an external/builtin subprogram that /// is not part of Wasm code. pub(crate) fn add_internal_types(