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

Function basic_debugger

crates/debugger/src/lib.rs:529–717  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

527 #[tokio::test]
528 #[cfg_attr(miri, ignore)]
529 async fn basic_debugger() -> wasmtime::Result<()> {
530 let _ = env_logger::try_init();
531
532 let mut config = Config::new();
533 config.guest_debug(true);
534 let engine = Engine::new(&config)?;
535 let module = Module::new(
536 &engine,
537 r#"
538 (module
539 (func (export "main") (param i32 i32) (result i32)
540 local.get 0
541 local.get 1
542 i32.add))
543 "#,
544 )?;
545
546 let mut store = Store::new(&engine, ());
547 let instance = Instance::new_async(&mut store, &module, &[]).await?;
548 let main = instance.get_func(&mut store, "main").unwrap();
549
550 let mut debuggee = Debuggee::new(store, move |store| {
551 Box::pin(async move {
552 let mut results = [Val::I32(0)];
553 store.edit_breakpoints().unwrap().single_step(true).unwrap();
554 main.call_async(&mut *store, &[Val::I32(1), Val::I32(2)], &mut results[..])
555 .await?;
556 assert_eq!(results[0].unwrap_i32(), 3);
557 main.call_async(&mut *store, &[Val::I32(3), Val::I32(4)], &mut results[..])
558 .await?;
559 assert_eq!(results[0].unwrap_i32(), 7);
560 Ok(())
561 })
562 });
563
564 let event = debuggee.run().await?;
565 assert!(matches!(event, DebugRunResult::Breakpoint));
566 // At (before executing) first `local.get`.
567 debuggee
568 .with_store(|mut store| {
569 let frame = store.debug_exit_frames().next().unwrap();
570 assert_eq!(
571 frame
572 .wasm_function_index_and_pc(&mut store)
573 .unwrap()
574 .unwrap()
575 .0
576 .as_u32(),
577 0
578 );
579 assert_eq!(
580 frame
581 .wasm_function_index_and_pc(&mut store)
582 .unwrap()
583 .unwrap()
584 .1
585 .raw(),
586 36

Callers

nothing calls this directly

Calls 13

OkFunction · 0.85
guest_debugMethod · 0.80
edit_breakpointsMethod · 0.80
with_storeMethod · 0.80
debug_exit_framesMethod · 0.80
newFunction · 0.50
unwrapMethod · 0.45
get_funcMethod · 0.45
single_stepMethod · 0.45
call_asyncMethod · 0.45
runMethod · 0.45
nextMethod · 0.45

Tested by

no test coverage detected