Run the inner body until the next debug event. This method is cancel-safe, and no events will be lost.
(&mut self)
| 328 | /// |
| 329 | /// This method is cancel-safe, and no events will be lost. |
| 330 | pub async fn run(&mut self) -> Result<DebugRunResult> { |
| 331 | log::trace!("running: state is {:?}", self.state); |
| 332 | |
| 333 | self.wait_for_initial().await?; |
| 334 | |
| 335 | match self.state { |
| 336 | DebuggeeState::Initial => unreachable!(), |
| 337 | DebuggeeState::Paused => { |
| 338 | log::trace!("sending Continue"); |
| 339 | self.in_tx |
| 340 | .send(Command::Continue) |
| 341 | .await |
| 342 | .map_err(|_| wasmtime::format_err!("Failed to send over debug channel"))?; |
| 343 | log::trace!("sent Continue"); |
| 344 | |
| 345 | // If that `send` was canceled, the command was not |
| 346 | // sent, so it's fine to remain in `Paused`. If it |
| 347 | // succeeded and we reached here, transition to |
| 348 | // `Running` so we don't re-send. |
| 349 | self.state = DebuggeeState::Running; |
| 350 | } |
| 351 | DebuggeeState::Running => { |
| 352 | // Previous `run()` must have been canceled; no action |
| 353 | // to take here. |
| 354 | } |
| 355 | DebuggeeState::Queried => { |
| 356 | // We expect to receive a `QueryResponse`; drop it if |
| 357 | // the query was canceled, then transition back to |
| 358 | // `Paused`. |
| 359 | log::trace!("in Queried; receiving"); |
| 360 | let response = |
| 361 | self.out_rx.recv().await.ok_or_else(|| { |
| 362 | wasmtime::format_err!("Premature close of debugger channel") |
| 363 | })?; |
| 364 | log::trace!("in Queried; received, dropping"); |
| 365 | assert!(matches!(response, Response::QueryResponse(_))); |
| 366 | self.state = DebuggeeState::Paused; |
| 367 | |
| 368 | // Now send a `Continue`, as above. |
| 369 | log::trace!("in Paused; sending Continue"); |
| 370 | self.in_tx |
| 371 | .send(Command::Continue) |
| 372 | .await |
| 373 | .map_err(|_| wasmtime::format_err!("Failed to send over debug channel"))?; |
| 374 | self.state = DebuggeeState::Running; |
| 375 | } |
| 376 | DebuggeeState::Complete => { |
| 377 | panic!("Cannot `run()` an already-complete Debuggee"); |
| 378 | } |
| 379 | } |
| 380 | |
| 381 | // At this point, the inner task is in Running state. We |
| 382 | // expect to receive a message when it next pauses or |
| 383 | // completes. If this `recv()` is canceled, no message is |
| 384 | // lost, and the state above accurately reflects what must be |
| 385 | // done on the next `run()`. |
| 386 | log::trace!("waiting for response"); |
| 387 | let response = self |