@@ -10,11 +10,12 @@ use runtime_tracing::{CallKey, EventLogKind, Line, PathId, StepId, VariableId, N
1010
1111use crate :: calltrace:: Calltrace ;
1212use crate :: dap:: { self , DapClient , DapMessage } ;
13- use crate :: db:: { Db , DbCall , DbRecordEvent , DbStep } ;
13+ use crate :: db:: { Db , DbCall , DbRecordEvent , DbReplay , DbStep } ;
1414use crate :: event_db:: { EventDb , SingleTableId } ;
1515use crate :: expr_loader:: ExprLoader ;
1616use crate :: flow_preloader:: FlowPreloader ;
1717use crate :: program_search_tool:: ProgramSearchTool ;
18+ use crate :: replay:: Replay ;
1819use crate :: rr_dispatcher:: { CtRRArgs , RRDispatcher } ;
1920// use crate::response::{};
2021use crate :: dap_types;
@@ -53,11 +54,13 @@ pub struct Handler {
5354 pub previous_step_id : StepId ,
5455
5556 pub trace_kind : TraceKind ,
56- pub rr : RRDispatcher ,
57+ // pub rr: RRDispatcher,
58+ pub replay : Box < dyn Replay > ,
59+
5760 pub breakpoint_list : Vec < HashMap < usize , BreakpointRecord > > ,
5861}
5962
60- #[ derive( Debug , Clone ) ]
63+ #[ derive( Debug , Clone , PartialEq ) ]
6164pub enum TraceKind {
6265 DB ,
6366 RR ,
@@ -100,10 +103,15 @@ impl Handler {
100103 let mut breakpoint_list: Vec < HashMap < usize , BreakpointRecord > > = Default :: default ( ) ;
101104 breakpoint_list. resize_with ( db. paths . len ( ) , HashMap :: new) ;
102105 let step_lines_loader = StepLinesLoader :: new ( & db, & mut expr_loader) ;
106+ let replay: Box < dyn Replay > = if trace_kind == TraceKind :: DB {
107+ Box :: new ( DbReplay :: new ( db. clone ( ) ) )
108+ } else {
109+ Box :: new ( RRDispatcher :: new ( ct_rr_args) )
110+ } ;
103111 // let sender = sender::Sender::new();
104112 Handler {
105113 trace_kind,
106- db,
114+ db : db . clone ( ) ,
107115 step_id : StepId ( 0 ) ,
108116 last_call_key : CallKey ( 0 ) ,
109117 indirect_send,
@@ -117,7 +125,8 @@ impl Handler {
117125 step_lines_loader,
118126 dap_client : DapClient :: default ( ) ,
119127 previous_step_id : StepId ( 0 ) ,
120- rr : RRDispatcher :: new ( ct_rr_args) ,
128+ // rr: RRDispatcher::new(ct_rr_args),
129+ replay,
121130 resulting_dap_messages : vec ! [ ] ,
122131 raw_diff_index : None ,
123132 }
@@ -215,29 +224,28 @@ impl Handler {
215224 self . send_dap ( & response)
216225 }
217226
218- fn complete_move ( & mut self , is_main : bool ) -> Result < ( ) , Box < dyn Error > > {
219- let call_key = self . db . call_key_for_step ( self . step_id ) ;
220- let reset_flow = is_main || call_key != self . last_call_key ;
221- self . last_call_key = call_key;
222- info ! ( "complete move: step_id: {:?}" , self . step_id) ;
223- let move_state = MoveState {
224- status : "" . to_string ( ) ,
225- location : self . db . load_location ( self . step_id , call_key, & mut self . expr_loader ) ,
226- c_location : Location :: default ( ) ,
227- main : is_main,
228- reset_flow,
229- stop_signal : RRGDBStopSignal :: OtherStopSignal ,
230- frame_info : FrameInfo :: default ( ) ,
231- } ;
232-
233- // info!("move_state {:?}", move_state);
227+ // will be sent after completion of query
228+ fn prepare_stopped_event ( & mut self , is_main : bool ) -> Result < ( ) , Box < dyn Error > > {
234229 let reason = if is_main { "entry" } else { "step" } ;
235230 info ! ( "generate stopped event" ) ;
236231 let raw_event = self . dap_client . stopped_event ( reason) ?;
237232 info ! ( "raw stopped event: {:?}" , raw_event) ;
238233 self . send_dap ( & raw_event) ?;
239- let raw_complete_move_event = self . dap_client . complete_move_event ( & move_state) ?;
234+ Ok ( ( ) )
235+ }
236+
237+ fn prepare_complete_move_event ( & mut self , move_state : & MoveState ) -> Result < ( ) , Box < dyn Error > > {
238+ let raw_complete_move_event = self . dap_client . complete_move_event ( move_state) ?;
240239 self . send_dap ( & raw_complete_move_event) ?;
240+ Ok ( ( ) )
241+ }
242+
243+ fn prepare_output_events ( & mut self ) -> Result < ( ) , Box < dyn Error > > {
244+ if self . trace_kind == TraceKind :: RR {
245+ warn ! ( "prepare_output_events not implemented for rr" ) ;
246+ return Ok ( ( ) ) ; // TODO
247+ }
248+
241249 if self . step_id . 0 > self . previous_step_id . 0 {
242250 let mut raw_output_events: Vec < dap:: DapMessage > = vec ! [ ] ;
243251 for event in self . db . events . iter ( ) {
@@ -264,9 +272,14 @@ impl Handler {
264272 self . send_dap ( raw_output_event) ?;
265273 }
266274 }
267- self . previous_step_id = self . step_id ;
275+ Ok ( ( ) )
276+ }
268277
269- // self.send_notification(NotificationKind::Success, "Complete move!", true)?;
278+ fn prepare_eventual_error_event ( & mut self ) -> Result < ( ) , Box < dyn Error > > {
279+ if self . trace_kind == TraceKind :: RR {
280+ warn ! ( "prepare_eventual_error_event not implemented for rr" ) ;
281+ return Ok ( ( ) ) ; // TODO
282+ }
270283
271284 let exact = false ; // or for now try as flow // true just for this exact step
272285 let step_events = self . db . load_step_events ( self . step_id , exact) ;
@@ -283,15 +296,44 @@ impl Handler {
283296 Ok ( ( ) )
284297 }
285298
299+ fn complete_move ( & mut self , is_main : bool ) -> Result < ( ) , Box < dyn Error > > {
300+ info ! ( "complete_move" ) ;
301+
302+ // self.db.load_location(self.step_id, call_key, &mut self.expr_loader),
303+ let location = self . replay . load_location ( & mut self . expr_loader ) ?;
304+ // let call_key = location.call_key; // self.db.call_key_for_step(self.step_id);
305+ // TODO: change if we need to support non-int keys
306+ let call_key = CallKey ( location. key . parse :: < i64 > ( ) ?) ;
307+ let reset_flow = is_main || call_key != self . last_call_key ;
308+ self . last_call_key = call_key;
309+ info ! ( " location: {location:?}" ) ;
310+
311+ let move_state = MoveState {
312+ status : "" . to_string ( ) ,
313+ location,
314+ c_location : Location :: default ( ) ,
315+ main : is_main,
316+ reset_flow,
317+ stop_signal : RRGDBStopSignal :: OtherStopSignal ,
318+ frame_info : FrameInfo :: default ( ) ,
319+ } ;
320+
321+ self . prepare_stopped_event ( is_main) ?;
322+ self . prepare_complete_move_event ( & move_state) ?;
323+ self . prepare_output_events ( ) ?;
324+
325+ self . previous_step_id = self . step_id ;
326+
327+ // self.send_notification(NotificationKind::Success, "Complete move!", true)?;
328+
329+ self . prepare_eventual_error_event ( ) ?;
330+
331+ Ok ( ( ) )
332+ }
333+
286334 pub fn run_to_entry ( & mut self , _req : dap:: Request ) -> Result < ( ) , Box < dyn Error > > {
287- match self . trace_kind {
288- TraceKind :: DB => {
289- self . step_id_jump ( StepId ( 0 ) ) ;
290- }
291- TraceKind :: RR => {
292- self . rr . run_to_entry ( ) ?;
293- }
294- }
335+ self . replay . run_to_entry ( ) ?;
336+ self . step_id = StepId ( 0 ) ; // TODO: use only db replay step_id or another workaround?
295337 self . complete_move ( true ) ?;
296338 Ok ( ( ) )
297339 }
0 commit comments