@@ -10,7 +10,7 @@ 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 , DbReplay , DbStep } ;
13+ use crate :: db:: { BreakpointRecord , Db , DbCall , DbRecordEvent , DbReplay , DbStep } ;
1414use crate :: event_db:: { EventDb , SingleTableId } ;
1515use crate :: expr_loader:: ExprLoader ;
1616use crate :: flow_preloader:: FlowPreloader ;
@@ -66,13 +66,6 @@ pub enum TraceKind {
6666 RR ,
6767}
6868
69- #[ derive( Debug , Clone , Serialize , Deserialize ) ]
70- pub struct BreakpointRecord {
71- pub is_active : bool ,
72- }
73-
74- type LineTraceMap = HashMap < usize , Vec < ( usize , String ) > > ;
75-
7669// two choices:
7770// return results and potentially
7871// generate multiple events as a generator
@@ -338,44 +331,17 @@ impl Handler {
338331 Ok ( ( ) )
339332 }
340333
341- pub fn load_locals ( & mut self , req : dap:: Request , _args : task:: CtLoadLocalsArguments ) -> Result < ( ) , Box < dyn Error > > {
342- if self . trace_kind == TraceKind :: RR {
343- let locals: Vec < Variable > = vec ! [ ] ;
344- warn ! ( "load_locals not implemented for rr yet" ) ;
334+ pub fn load_locals ( & mut self , req : dap:: Request , args : task:: CtLoadLocalsArguments ) -> Result < ( ) , Box < dyn Error > > {
335+ // if self.trace_kind == TraceKind::RR {
336+ // let locals: Vec<Variable> = vec![];
337+ // warn!("load_locals not implemented for rr yet");
338+ let locals = self . replay . load_locals ( args) ?;
345339 self . respond_dap ( req, task:: CtLoadLocalsResponseBody { locals } ) ?;
346- return Ok ( ( ) ) ;
347- }
348-
349- let full_value_locals: Vec < Variable > = self . db . variables [ self . step_id ]
350- . iter ( )
351- . map ( |v| Variable {
352- expression : self . db . variable_name ( v. variable_id ) . to_string ( ) ,
353- value : self . db . to_ct_value ( & v. value ) ,
354- } )
355- . collect ( ) ;
356-
357- // TODO: fix random order here as well: ensure order(or in final locals?)
358- let value_tracking_locals: Vec < Variable > = self . db . variable_cells [ self . step_id ]
359- . iter ( )
360- . map ( |( variable_id, place) | {
361- let name = self . db . variable_name ( * variable_id) ;
362- info ! ( "log local {variable_id:?} {name} place: {place:?}" ) ;
363- let value = self . db . load_value_for_place ( * place, self . step_id ) ;
364- Variable {
365- expression : self . db . variable_name ( * variable_id) . to_string ( ) ,
366- value : self . db . to_ct_value ( & value) ,
367- }
368- } )
369- . collect ( ) ;
370- // based on https://stackoverflow.com/a/56490417/438099
371- let mut locals: Vec < Variable > = full_value_locals. into_iter ( ) . chain ( value_tracking_locals) . collect ( ) ;
372-
373- locals. sort_by ( |left, right| Ord :: cmp ( & left. expression , & right. expression ) ) ;
374- // for now just removing duplicated variables/expressions: even if storing different values
375- locals. dedup_by ( |a, b| a. expression == b. expression ) ;
340+ Ok ( ( ) )
341+ // }
376342
377- self . respond_dap ( req, task:: CtLoadLocalsResponseBody { locals } ) ?;
378- Ok ( ( ) )
343+ // self.respond_dap(req, task::CtLoadLocalsResponseBody { locals })?;
344+ // Ok(())
379345 }
380346
381347 // pub fn load_callstack(&mut self, task: Task) -> Result<(), Box<dyn Error>> {
@@ -563,7 +529,7 @@ impl Handler {
563529 }
564530
565531 pub fn step_in ( & mut self , forward : bool ) -> Result < ( ) , Box < dyn Error > > {
566- self . replay . step_in ( forward) ?;
532+ self . replay . step ( Action :: StepIn , forward) ?;
567533 self . step_id = self . replay . current_step_id ( ) ;
568534
569535 Ok ( ( ) )
@@ -596,57 +562,23 @@ impl Handler {
596562 }
597563
598564 pub fn next ( & mut self , forward : bool ) -> Result < ( ) , Box < dyn Error > > {
599- let step_to_different_line = true ; // which is better/should be let the user configure it?
600- ( self . step_id , _) = self
601- . db
602- . next_step_id_relative_to ( self . step_id , forward, step_to_different_line) ;
565+ self . replay . step ( Action :: Next , forward) ?;
566+ self . step_id = self . replay . current_step_id ( ) ;
603567 Ok ( ( ) )
604568 }
605569
606570 pub fn step_out ( & mut self , forward : bool ) -> Result < ( ) , Box < dyn Error > > {
607- ( self . step_id , _) = self . db . step_out_step_id_relative_to ( self . step_id , forward) ;
571+ self . replay . step ( Action :: StepOut , forward) ?;
572+ self . step_id = self . replay . current_step_id ( ) ;
608573 Ok ( ( ) )
609574 }
610575
611576 #[ allow( clippy:: expect_used) ]
612577 pub fn step_continue ( & mut self , forward : bool ) -> Result < ( ) , Box < dyn Error > > {
613- for step in self . db . step_from ( self . step_id , forward) {
614- if !self . breakpoint_list . is_empty ( ) {
615- if let Some ( is_active) = self . breakpoint_list [ step. path_id . 0 ]
616- . get ( & step. line . into ( ) )
617- . map ( |bp| bp. is_active )
618- {
619- if is_active {
620- self . step_id_jump ( step. step_id ) ;
621- self . complete_move ( false ) ?;
622- return Ok ( ( ) ) ;
623- }
624- }
625- } else {
626- break ;
627- }
578+ if !self . replay . step ( Action :: Continue , forward) ? {
579+ self . send_notification ( NotificationKind :: Info , "No breakpoints were hit!" , false ) ?;
628580 }
629-
630- // If the continue step doesn't find a valid breakpoint.
631- if forward {
632- self . step_id_jump (
633- self . db
634- . steps
635- . last ( )
636- . expect ( "unexpected 0 steps in trace for step_continue" )
637- . step_id ,
638- ) ;
639- } else {
640- self . step_id_jump (
641- self . db
642- . steps
643- . first ( )
644- . expect ( "unexpected 0 steps in trace for step_continue" )
645- . step_id ,
646- )
647- }
648- self . complete_move ( false ) ?;
649- self . send_notification ( NotificationKind :: Info , "No breakpoints were hit!" , false ) ?;
581+ self . step_id = self . replay . current_step_id ( ) ;
650582 Ok ( ( ) )
651583 }
652584
@@ -663,21 +595,23 @@ impl Handler {
663595 Action :: Continue => self . step_continue ( !arg. reverse ) ?,
664596 _ => error ! ( "action {:?} not implemented" , arg. action) ,
665597 }
666- if arg. complete && arg. action != Action :: Continue {
598+ if arg. complete { // && arg.action != Action::Continue {
667599 self . complete_move ( false ) ?;
668600 }
669601
670- if original_step_id == self . step_id {
671- let location = if self . step_id == StepId ( 0 ) { "beginning" } else { "end" } ;
672- self . send_notification (
673- NotificationKind :: Warning ,
674- & format ! ( "Limit of record at the {location} already reached!" ) ,
675- false ,
676- ) ?;
677- } else if self . step_id == StepId ( 0 ) {
678- self . send_notification ( NotificationKind :: Info , "Beginning of record reached" , false ) ?;
679- } else if self . step_id . 0 as usize == self . db . steps . len ( ) - 1 {
680- self . send_notification ( NotificationKind :: Info , "End of record reached" , false ) ?;
602+ if self . trace_kind == TraceKind :: DB {
603+ if original_step_id == self . step_id {
604+ let location = if self . step_id == StepId ( 0 ) { "beginning" } else { "end" } ;
605+ self . send_notification (
606+ NotificationKind :: Warning ,
607+ & format ! ( "Limit of record at the {location} already reached!" ) ,
608+ false ,
609+ ) ?;
610+ } else if self . step_id == StepId ( 0 ) {
611+ self . send_notification ( NotificationKind :: Info , "Beginning of record reached" , false ) ?;
612+ } else if self . step_id . 0 as usize == self . db . steps . len ( ) - 1 {
613+ self . send_notification ( NotificationKind :: Info , "End of record reached" , false ) ?;
614+ }
681615 }
682616 // } else if arg.action == Action::Next {
683617 // let new_step = self.db.steps[self.step_id];
0 commit comments