Create a new Debugger that attaches to the given Store and runs the given inner body. The debugger is always in one of two states: running or paused. When paused, the holder of this object can invoke `Debuggee::run` to enter the running state. The inner body will run until paused by a debug event. While running, the future returned by either of these methods owns the `Debuggee` and hence no othe
(mut store: Store<T>, inner: F)
| 239 | /// When paused, the holder of this object can access the `Store` |
| 240 | /// indirectly by providing a closure |
| 241 | pub fn new<F>(mut store: Store<T>, inner: F) -> Debuggee<T> |
| 242 | where |
| 243 | F: for<'a> FnOnce( |
| 244 | &'a mut Store<T>, |
| 245 | ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'a>> |
| 246 | + Send |
| 247 | + 'static, |
| 248 | { |
| 249 | let engine = store.engine().clone(); |
| 250 | let (in_tx, in_rx) = mpsc::channel(1); |
| 251 | let (out_tx, out_rx) = mpsc::channel(1); |
| 252 | let interrupt_pending = Arc::new(AtomicBool::new(false)); |
| 253 | |
| 254 | let handle = tokio::spawn({ |
| 255 | let interrupt_pending = interrupt_pending.clone(); |
| 256 | async move { |
| 257 | // Create the handler that's invoked from within the async |
| 258 | // debug-event callback. |
| 259 | let out_tx_clone = out_tx.clone(); |
| 260 | let handler = Handler(Arc::new(HandlerInner { |
| 261 | in_rx: Mutex::new(in_rx), |
| 262 | out_tx, |
| 263 | interrupt_pending, |
| 264 | })); |
| 265 | |
| 266 | // Emulate a breakpoint at startup. |
| 267 | log::trace!("inner debuggee task: first breakpoint"); |
| 268 | handler |
| 269 | .handle(store.as_context_mut(), DebugEvent::Breakpoint) |
| 270 | .await; |
| 271 | log::trace!("inner debuggee task: first breakpoint resumed"); |
| 272 | |
| 273 | // Now invoke the actual inner body. |
| 274 | store.set_debug_handler(handler); |
| 275 | log::trace!("inner debuggee task: running `inner`"); |
| 276 | let result = inner(&mut store).await; |
| 277 | log::trace!("inner debuggee task: done with `inner`"); |
| 278 | let _ = out_tx_clone.send(Response::Finished(store)).await; |
| 279 | result |
| 280 | } |
| 281 | }); |
| 282 | |
| 283 | Debuggee { |
| 284 | engine, |
| 285 | state: DebuggeeState::Initial, |
| 286 | store: None, |
| 287 | in_tx, |
| 288 | out_rx, |
| 289 | interrupt_pending, |
| 290 | handle: Some(handle), |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | /// Is the inner body done running? |
| 295 | pub fn is_complete(&self) -> bool { |
nothing calls this directly
no test coverage detected