Skip to content

Commit 88bdf79

Browse files
authored
Debugging: add event for epoch yields. (#12194)
This will almost certainly be needed to implement "Ctrl-C" behavior for a gdbstub server or other user-facing debugger top-half, so the user can interrupt the debuggee and return control to the debugger.
1 parent df618ea commit 88bdf79

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

crates/wasmtime/src/runtime/debug.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,8 @@ pub enum DebugEvent<'a> {
527527
Trap(Trap),
528528
/// A breakpoint was reached.
529529
Breakpoint,
530+
/// An epoch yield occurred.
531+
EpochYield,
530532
}
531533

532534
/// A handler for debug events.

crates/wasmtime/src/runtime/vm/libcalls.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,6 +1256,11 @@ fn out_of_gas(store: &mut dyn VMStore, _instance: InstanceId) -> Result<()> {
12561256
fn new_epoch(store: &mut dyn VMStore, _instance: InstanceId) -> Result<NextEpoch> {
12571257
use crate::UpdateDeadline;
12581258

1259+
#[cfg(feature = "debug")]
1260+
{
1261+
store.block_on_debug_handler(crate::DebugEvent::EpochYield)?;
1262+
}
1263+
12591264
let update_deadline = store.new_epoch_updated_deadline()?;
12601265
block_on!(store, async move |store| {
12611266
let delta = match update_deadline {

tests/all/debug.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,3 +753,48 @@ async fn breakpoints_in_inlined_code() -> anyhow::Result<()> {
753753

754754
Ok(())
755755
}
756+
757+
#[tokio::test]
758+
#[cfg_attr(miri, ignore)]
759+
async fn epoch_events() -> anyhow::Result<()> {
760+
let _ = env_logger::try_init();
761+
762+
let (module, mut store) = get_module_and_store(
763+
|config| {
764+
config.async_support(true);
765+
config.epoch_interruption(true);
766+
},
767+
r#"
768+
(module
769+
(func $f (export "f") (param i32 i32) (result i32)
770+
local.get 0
771+
local.get 1
772+
i32.add))
773+
"#,
774+
)?;
775+
776+
debug_event_checker!(
777+
D, store,
778+
{ 0 ;
779+
wasmtime::DebugEvent::EpochYield => {}
780+
}
781+
);
782+
783+
let (handler, counter) = D::new_and_counter();
784+
store.set_debug_handler(handler);
785+
786+
store.set_epoch_deadline(1);
787+
store.epoch_deadline_async_yield_and_update(1);
788+
store.engine().increment_epoch();
789+
790+
let instance = Instance::new_async(&mut store, &module, &[]).await?;
791+
let func_f = instance.get_func(&mut store, "f").unwrap();
792+
let mut results = [Val::I32(0)];
793+
func_f
794+
.call_async(&mut store, &[Val::I32(1), Val::I32(2)], &mut results)
795+
.await?;
796+
assert_eq!(counter.load(Ordering::Relaxed), 1);
797+
assert_eq!(results[0].unwrap_i32(), 3);
798+
799+
Ok(())
800+
}

0 commit comments

Comments
 (0)