Skip to content

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant

Debug: handle `Store::debug_frames()` with no activation. (#11899)

Chris Fallin0f43b497d3be
diff --git a/crates/wasmtime/src/runtime/vm/traphandlers/backtrace.rs b/crates/wasmtime/src/runtime/vm/traphandlers/backtrace.rs
index 781eaac6f5..be9403e97f 100644
--- a/crates/wasmtime/src/runtime/vm/traphandlers/backtrace.rs
+++ b/crates/wasmtime/src/runtime/vm/traphandlers/backtrace.rs
@@ -366,11 +366,16 @@ impl<'a, T: 'static> CurrentActivationBacktrace<'a, T> {
let exit_pc = unsafe { *(*vm_store_context).last_wasm_exit_pc.get() };
let exit_fp = unsafe { (*vm_store_context).last_wasm_exit_fp() };
let trampoline_fp = unsafe { *(*vm_store_context).last_wasm_entry_fp.get() };
- let unwind = store.0.unwinder();
- // Establish the iterator.
- let inner = Box::new(unsafe {
- wasmtime_unwinder::frame_iterator(unwind, exit_pc, exit_fp, trampoline_fp)
- });
+ let inner: Box<dyn Iterator<Item = Frame>> = if exit_fp == 0 {
+ // No activations on this Store; return an empty iterator.
+ Box::new(core::iter::empty())
+ } else {
+ let unwind = store.0.unwinder();
+ // Establish the iterator.
+ Box::new(unsafe {
+ wasmtime_unwinder::frame_iterator(unwind, exit_pc, exit_fp, trampoline_fp)
+ })
+ };
CurrentActivationBacktrace { store, inner }
}
diff --git a/tests/all/debug.rs b/tests/all/debug.rs
index 303a9129b6..c4f3e66f0f 100644
--- a/tests/all/debug.rs
+++ b/tests/all/debug.rs
@@ -186,3 +186,17 @@ fn gc_access_during_call() -> anyhow::Result<()> {
},
)
}
+
+#[test]
+#[cfg_attr(miri, ignore)]
+fn debug_frames_on_store_with_no_wasm_activation() -> anyhow::Result<()> {
+ let mut config = Config::default();
+ config.guest_debug(true);
+ let engine = Engine::new(&config)?;
+ let mut store = Store::new(&engine, ());
+ let frames = store
+ .debug_frames()
+ .expect("Debug frames should be available");
+ assert!(frames.done());
+ Ok(())
+}