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,
)
| 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 |
no test coverage detected