55//! stderr to communicate success.
66
77use std:: time:: Duration ;
8- use wstd:: runtime:: AsyncPollable ;
98
109mod api {
1110 wit_bindgen:: generate!( {
@@ -49,53 +48,44 @@ api::export!(Component with_types_in api);
4948
5049impl api:: exports:: bytecodealliance:: wasmtime:: debugger:: Guest for Component {
5150 fn debug ( d : & Debuggee , args : Vec < String > ) {
52- wstd:: runtime:: block_on ( async {
53- match args. get ( 1 ) . map ( |s| s. as_str ( ) ) {
54- Some ( "simple" ) => test_simple ( d) . await ,
55- Some ( "loop" ) => test_loop ( d) . await ,
56- other => panic ! ( "unknown test mode: {other:?}" ) ,
51+ match args. get ( 1 ) . map ( |s| s. as_str ( ) ) {
52+ Some ( "simple" ) => {
53+ test_simple ( d) ;
5754 }
58- } ) ;
55+ Some ( "loop" ) => {
56+ test_loop ( d) ;
57+ }
58+ other => panic ! ( "unknown test mode: {other:?}" ) ,
59+ }
5960 }
6061}
6162
6263struct Resumption {
6364 future : EventFuture ,
64- pollable : Option < AsyncPollable > ,
6565}
6666
6767impl Resumption {
6868 fn single_step ( d : & Debuggee ) -> Self {
6969 let future = d. single_step ( ResumptionValue :: Normal ) ;
70- let pollable = Some ( AsyncPollable :: new ( future. subscribe ( ) ) ) ;
71- Self { future, pollable }
70+ Self { future }
7271 }
7372
7473 fn continue_ ( d : & Debuggee ) -> Self {
7574 let future = d. continue_ ( ResumptionValue :: Normal ) ;
76- let pollable = Some ( AsyncPollable :: new ( future. subscribe ( ) ) ) ;
77- Self { future, pollable }
78- }
79-
80- async fn wait ( & mut self ) {
81- if let Some ( p) = self . pollable . as_mut ( ) {
82- p. wait_for ( ) . await ;
83- }
75+ Self { future }
8476 }
8577
86- fn result ( mut self , d : & Debuggee ) -> Result < Event , Error > {
87- let _ = self . pollable . take ( ) ;
78+ fn result ( self , d : & Debuggee ) -> Result < Event , Error > {
8879 EventFuture :: finish ( self . future , d)
8980 }
9081}
9182
9283/// Tests single-stepping.
9384///
9485/// Tests against `debugger_debuggee_simple.wat`.
95- async fn test_simple ( d : & Debuggee ) {
86+ fn test_simple ( d : & Debuggee ) {
9687 // Step once to reach the first instruction.
97- let mut r = Resumption :: single_step ( d) ;
98- r. wait ( ) . await ;
88+ let r = Resumption :: single_step ( d) ;
9989 let _event = r. result ( d) . unwrap ( ) ;
10090
10191 let mut pcs = vec ! [ ] ;
@@ -105,8 +95,7 @@ async fn test_simple(d: &Debuggee) {
10595 let pc = frames[ 0 ] . get_pc ( d) . unwrap ( ) ;
10696 pcs. push ( pc) ;
10797
108- let mut r = Resumption :: single_step ( d) ;
109- r. wait ( ) . await ;
98+ let r = Resumption :: single_step ( d) ;
11099 match r. result ( d) . unwrap ( ) {
111100 Event :: Breakpoint => { }
112101 other => panic ! ( "unexpected event: {other:?}" ) ,
@@ -125,9 +114,9 @@ async fn test_simple(d: &Debuggee) {
125114/// to completion.
126115///
127116/// Tests against `debugger_debuggee_loop.wat`.
128- async fn test_loop ( d : & Debuggee ) {
117+ fn test_loop ( d : & Debuggee ) {
129118 // Continue execution (the debuggee should loop).
130- let mut r = Resumption :: continue_ ( d) ;
119+ let r = Resumption :: continue_ ( d) ;
131120
132121 // Yield to the event loop and let it run for a bit.
133122 std:: thread:: sleep ( Duration :: from_millis ( 100 ) ) ;
@@ -136,7 +125,6 @@ async fn test_loop(d: &Debuggee) {
136125 d. interrupt ( ) ;
137126
138127 // Wait for the interrupt event.
139- r. wait ( ) . await ;
140128 let event = r. result ( d) . unwrap ( ) ;
141129 assert ! (
142130 matches!( event, Event :: Interrupted ) ,
@@ -153,8 +141,7 @@ async fn test_loop(d: &Debuggee) {
153141 }
154142
155143 // Continue; the debuggee should exit normally now.
156- let mut r = Resumption :: continue_ ( d) ;
157- r. wait ( ) . await ;
144+ let r = Resumption :: continue_ ( d) ;
158145 let event = r. result ( d) . unwrap ( ) ;
159146 assert ! (
160147 matches!( event, Event :: Complete ) ,
0 commit comments