A lightweight WebAssembly runtime that is fast, secure, and standards-compliant
Debugging: add event for epoch yields. (#12194)
Chris Fallin88bdf79148fc
diff --git a/crates/wasmtime/src/runtime/debug.rs b/crates/wasmtime/src/runtime/debug.rsindex 89d11d0bba..17a7b473da 100644--- a/crates/wasmtime/src/runtime/debug.rs+++ b/crates/wasmtime/src/runtime/debug.rs@@ -527,6 +527,8 @@ pub enum DebugEvent<'a> {Trap(Trap),/// A breakpoint was reached.Breakpoint,+ /// An epoch yield occurred.+ EpochYield,}/// A handler for debug events.diff --git a/crates/wasmtime/src/runtime/vm/libcalls.rs b/crates/wasmtime/src/runtime/vm/libcalls.rsindex cf5b4a07f2..7fe172f172 100644--- a/crates/wasmtime/src/runtime/vm/libcalls.rs+++ b/crates/wasmtime/src/runtime/vm/libcalls.rs@@ -1256,6 +1256,11 @@ fn out_of_gas(store: &mut dyn VMStore, _instance: InstanceId) -> Result<()> {fn new_epoch(store: &mut dyn VMStore, _instance: InstanceId) -> Result<NextEpoch> {use crate::UpdateDeadline;+ #[cfg(feature = "debug")]+ {+ store.block_on_debug_handler(crate::DebugEvent::EpochYield)?;+ }+let update_deadline = store.new_epoch_updated_deadline()?;block_on!(store, async move |store| {let delta = match update_deadline {diff --git a/tests/all/debug.rs b/tests/all/debug.rsindex dc40326c72..20407fc78b 100644--- a/tests/all/debug.rs+++ b/tests/all/debug.rs@@ -753,3 +753,48 @@ async fn breakpoints_in_inlined_code() -> anyhow::Result<()> {Ok(())}++#[tokio::test]+#[cfg_attr(miri, ignore)]+async fn epoch_events() -> anyhow::Result<()> {+ let _ = env_logger::try_init();++ let (module, mut store) = get_module_and_store(+ |config| {+ config.async_support(true);+ config.epoch_interruption(true);+ },+ r#"+ (module+ (func $f (export "f") (param i32 i32) (result i32)+ local.get 0+ local.get 1+ i32.add))+ "#,+ )?;++ debug_event_checker!(+ D, store,+ { 0 ;+ wasmtime::DebugEvent::EpochYield => {}+ }+ );++ let (handler, counter) = D::new_and_counter();+ store.set_debug_handler(handler);++ store.set_epoch_deadline(1);+ store.epoch_deadline_async_yield_and_update(1);+ store.engine().increment_epoch();++ let instance = Instance::new_async(&mut store, &module, &[]).await?;+ let func_f = instance.get_func(&mut store, "f").unwrap();+ let mut results = [Val::I32(0)];+ func_f+ .call_async(&mut store, &[Val::I32(1), Val::I32(2)], &mut results)+ .await?;+ assert_eq!(counter.load(Ordering::Relaxed), 1);+ assert_eq!(results[0].unwrap_i32(), 3);++ Ok(())+}