Stream: git-wasmtime

Topic: wasmtime / issue #15333 Guest debug: `set_fuel` in a watc...


view this post on Zulip Wasmtime GitHub notifications bot (Nov 17 2026 at 21:48):

alexcrichton opened issue #15333:

This test, added to tests/all/debug.rs:

#[tokio::test]
async fn watchpoint_set_fuel() -> wasmtime::Result<()> {
    let mut config = Config::default();
    config.guest_debug(true).consume_fuel(true);
    let engine = Engine::new(&config)?;
    let module = Module::new(
        &engine,
        r#"
    (module
      (memory (export "memory") 1)
      (func (export "store") (param $n i32)
        (loop $l
          (i32.store8 (i32.const 0) (local.get $n))
          (local.tee $n (i32.sub (local.get $n) (i32.const 1)))
          br_if $l))
      (func (export "fill") (param $n i32)
        (loop $l
          (memory.fill (i32.const 0) (local.get $n) (i32.const 1))
          (local.tee $n (i32.sub (local.get $n) (i32.const 1)))
          br_if $l)))
    "#,
    )?;

    #[derive(Clone)]
    struct ZeroFuel;
    impl DebugHandler for ZeroFuel {
        type Data = ();
        async fn handle(&self, mut store: StoreContextMut<'_, ()>, event: DebugEvent<'_>) {
            if let DebugEvent::Watchpoint(_) = event {
                store.set_fuel(0).unwrap();
            }
        }
    }

    for export in ["store", "fill"] {
        let mut store = Store::new(&engine, ());
        store.set_fuel(1_000_000)?;
        store.set_debug_handler(ZeroFuel);
        let instance = Instance::new_async(&mut store, &module, &[]).await?;
        let memory = instance.get_memory(&mut store, "memory").unwrap();
        store.edit_breakpoints().unwrap().watch(memory, 0..1)?;
        let func = instance.get_typed_func::<i32, ()>(&mut store, export)?;
        let result = func.call_async(&mut store, 100).await;
        println!("{export}: {result:?}, fuel left: {}", store.get_fuel()?);
    }
    Ok(())
}

prints:

$ cargo test --test all -- debug::watchpoint_set_fuel --nocapture
store: Ok(()), fuel left: 999199
fill: Ok(()), fuel left: 998999

Both calls should trap with "all fuel consumed", as the same set_fuel(0) does from a DebugEvent::Breakpoint (#14594).

view this post on Zulip Wasmtime GitHub notifications bot (Nov 17 2026 at 21:48):

alexcrichton added the wasmtime:debugging label to Issue #15333.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 19 2026 at 15:59):

alexcrichton closed issue #15333:

This test, added to tests/all/debug.rs:

#[tokio::test]
async fn watchpoint_set_fuel() -> wasmtime::Result<()> {
    let mut config = Config::default();
    config.guest_debug(true).consume_fuel(true);
    let engine = Engine::new(&config)?;
    let module = Module::new(
        &engine,
        r#"
    (module
      (memory (export "memory") 1)
      (func (export "store") (param $n i32)
        (loop $l
          (i32.store8 (i32.const 0) (local.get $n))
          (local.tee $n (i32.sub (local.get $n) (i32.const 1)))
          br_if $l))
      (func (export "fill") (param $n i32)
        (loop $l
          (memory.fill (i32.const 0) (local.get $n) (i32.const 1))
          (local.tee $n (i32.sub (local.get $n) (i32.const 1)))
          br_if $l)))
    "#,
    )?;

    #[derive(Clone)]
    struct ZeroFuel;
    impl DebugHandler for ZeroFuel {
        type Data = ();
        async fn handle(&self, mut store: StoreContextMut<'_, ()>, event: DebugEvent<'_>) {
            if let DebugEvent::Watchpoint(_) = event {
                store.set_fuel(0).unwrap();
            }
        }
    }

    for export in ["store", "fill"] {
        let mut store = Store::new(&engine, ());
        store.set_fuel(1_000_000)?;
        store.set_debug_handler(ZeroFuel);
        let instance = Instance::new_async(&mut store, &module, &[]).await?;
        let memory = instance.get_memory(&mut store, "memory").unwrap();
        store.edit_breakpoints().unwrap().watch(memory, 0..1)?;
        let func = instance.get_typed_func::<i32, ()>(&mut store, export)?;
        let result = func.call_async(&mut store, 100).await;
        println!("{export}: {result:?}, fuel left: {}", store.get_fuel()?);
    }
    Ok(())
}

prints:

$ cargo test --test all -- debug::watchpoint_set_fuel --nocapture
store: Ok(()), fuel left: 999199
fill: Ok(()), fuel left: 998999

Both calls should trap with "all fuel consumed", as the same set_fuel(0) does from a DebugEvent::Breakpoint (#14594).


Last updated: Nov 19 2026 at 20:05 UTC