MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / single_step_before_instantiation

Function single_step_before_instantiation

tests/all/debug.rs:1338–1388  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1336#[tokio::test]
1337#[cfg_attr(miri, ignore)]
1338async fn single_step_before_instantiation() -> wasmtime::Result<()> {
1339 let _ = env_logger::try_init();
1340
1341 let mut config = Config::default();
1342 config.guest_debug(true);
1343 let engine = Engine::new(&config)?;
1344 let module = Module::new(
1345 &engine,
1346 r#"
1347 (module
1348 (func (export "main") (param i32 i32) (result i32)
1349 local.get 0
1350 local.get 1
1351 i32.add))
1352 "#,
1353 )?;
1354 let mut store = Store::new(&engine, ());
1355
1356 // Enable single-stepping *before* instantiation. The module has not
1357 // been registered with this store yet.
1358 store.edit_breakpoints().unwrap().single_step(true).unwrap();
1359 assert!(store.is_single_step());
1360
1361 #[derive(Clone)]
1362 struct CountingHandler(Arc<AtomicUsize>);
1363 impl DebugHandler for CountingHandler {
1364 type Data = ();
1365 async fn handle(&self, _store: StoreContextMut<'_, ()>, event: DebugEvent<'_>) {
1366 match event {
1367 DebugEvent::Breakpoint => {
1368 self.0.fetch_add(1, Ordering::Relaxed);
1369 }
1370 _ => {}
1371 }
1372 }
1373 }
1374
1375 let counter = Arc::new(AtomicUsize::new(0));
1376 store.set_debug_handler(CountingHandler(counter.clone()));
1377
1378 let instance = Instance::new_async(&mut store, &module, &[]).await?;
1379 let func = instance.get_func(&mut store, "main").unwrap();
1380 let mut results = [Val::I32(0)];
1381 func.call_async(&mut store, &[Val::I32(1), Val::I32(2)], &mut results)
1382 .await?;
1383 assert_eq!(results[0].unwrap_i32(), 3);
1384
1385 assert_eq!(counter.load(Ordering::Relaxed), 4);
1386
1387 Ok(())
1388}
1389
1390#[tokio::test]
1391#[cfg_attr(miri, ignore)]

Callers

nothing calls this directly

Calls 11

CountingHandlerClass · 0.85
OkFunction · 0.85
guest_debugMethod · 0.80
edit_breakpointsMethod · 0.80
set_debug_handlerMethod · 0.80
newFunction · 0.50
unwrapMethod · 0.45
single_stepMethod · 0.45
cloneMethod · 0.45
get_funcMethod · 0.45
call_asyncMethod · 0.45

Tested by

no test coverage detected