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

Method with_store

crates/debugger/src/lib.rs:442–497  ·  view source on GitHub ↗

Perform some action on the contained `Store` while not running. This may only be invoked before the inner body finishes and when it is paused; that is, when the `Debuggee` is initially created and after any call to `run()` returns a result other than `DebugRunResult::Finished`. If an earlier `run()` invocation was canceled, it must be re-invoked and return successfully before a query is made. Th

(
        &mut self,
        f: F,
    )

Source from the content-addressed store, hash-verified

440 /// This is cancel-safe; if canceled, the result of the query will
441 /// be dropped.
442 pub async fn with_store<
443 F: FnOnce(StoreContextMut<'_, T>) -> R + Send + 'static,
444 R: Send + 'static,
445 >(
446 &mut self,
447 f: F,
448 ) -> Result<R> {
449 if let Some(store) = self.store.as_mut() {
450 return Ok(f(store.as_context_mut()));
451 }
452
453 self.wait_for_initial().await?;
454
455 match self.state {
456 DebuggeeState::Initial => unreachable!(),
457 DebuggeeState::Queried => {
458 // Earlier query canceled; drop its response first.
459 let response =
460 self.out_rx.recv().await.ok_or_else(|| {
461 wasmtime::format_err!("Premature close of debugger channel")
462 })?;
463 assert!(matches!(response, Response::QueryResponse(_)));
464 self.state = DebuggeeState::Paused;
465 }
466 DebuggeeState::Running => {
467 // Results from a canceled `run()`; `run()` must
468 // complete before this can be invoked.
469 panic!("Cannot query in Running state");
470 }
471 DebuggeeState::Complete => {
472 panic!("Cannot query when complete");
473 }
474 DebuggeeState::Paused => {
475 // OK -- this is the state we want.
476 }
477 }
478
479 log::trace!("sending query in with_store");
480 self.in_tx
481 .send(Command::Query(Box::new(|store| Box::new(f(store)))))
482 .await
483 .map_err(|_| wasmtime::format_err!("Premature close of debugger channel"))?;
484 self.state = DebuggeeState::Queried;
485
486 let response = self
487 .out_rx
488 .recv()
489 .await
490 .ok_or_else(|| wasmtime::format_err!("Premature close of debugger channel"))?;
491 let Response::QueryResponse(resp) = response else {
492 wasmtime::bail!("Incorrect response from debugger task");
493 };
494 self.state = DebuggeeState::Paused;
495
496 Ok(*resp.downcast::<R>().expect("type mismatch"))
497 }
498}
499

Callers 15

basic_debuggerFunction · 0.80
all_instancesMethod · 0.80
all_modulesMethod · 0.80
single_stepMethod · 0.80
continue_Method · 0.80
exit_framesMethod · 0.80
get_instance_moduleMethod · 0.80
instance_get_memoryMethod · 0.80
instance_get_globalMethod · 0.80
instance_get_tableMethod · 0.80
instance_get_funcMethod · 0.80
instance_get_tagMethod · 0.80

Calls 8

OkFunction · 0.85
wait_for_initialMethod · 0.80
fFunction · 0.50
newFunction · 0.50
as_mutMethod · 0.45
as_context_mutMethod · 0.45
sendMethod · 0.45
expectMethod · 0.45

Tested by

no test coverage detected