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

Method run

crates/debugger/src/lib.rs:330–409  ·  view source on GitHub ↗

Run the inner body until the next debug event. This method is cancel-safe, and no events will be lost.

(&mut self)

Source from the content-addressed store, hash-verified

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

Callers 8

finishMethod · 0.45
basic_debuggerFunction · 0.45
drop_debuggee_and_storeFunction · 0.45
single_stepMethod · 0.45
continue_Method · 0.45
wasm_mutateFunction · 0.45
evalFunction · 0.45

Calls 3

OkFunction · 0.85
wait_for_initialMethod · 0.80
sendMethod · 0.45

Tested by 1