11use indexmap:: IndexMap ;
2- use std:: collections:: { HashMap , HashSet } ;
2+ use std:: collections:: HashMap ;
33use std:: error:: Error ;
44
55use log:: { error, info, warn} ;
@@ -23,7 +23,7 @@ use crate::dap_types;
2323use crate :: step_lines_loader:: StepLinesLoader ;
2424use crate :: task;
2525use crate :: task:: {
26- Action , Call , CallArgsUpdateResults , CallLine , CallSearchArg , CalltraceLoadArgs , CalltraceNonExpandedKind ,
26+ Action , Breakpoint , Call , CallArgsUpdateResults , CallLine , CallSearchArg , CalltraceLoadArgs , CalltraceNonExpandedKind ,
2727 CollapseCallsArgs , CoreTrace , DbEventKind , FrameInfo , FunctionLocation , FlowMode , HistoryResult , HistoryUpdate , Instruction ,
2828 CtLoadFlowArguments , FlowUpdate , Instructions , LoadHistoryArg , LoadStepLinesArg , LoadStepLinesUpdate , LocalStepJump , Location , MoveState ,
2929 Notification , NotificationKind , ProgramEvent , RRGDBStopSignal , RRTicks , RegisterEventsArg , RunTracepointsArg ,
@@ -52,7 +52,7 @@ pub struct Handler {
5252 pub resulting_dap_messages : Vec < DapMessage > ,
5353 pub raw_diff_index : Option < String > ,
5454 pub previous_step_id : StepId ,
55- pub breakpoints : HashMap < String , HashSet < i64 > > ,
55+ pub breakpoints : HashMap < ( String , i64 ) , Vec < Breakpoint > > ,
5656
5757 pub trace_kind : TraceKind ,
5858 pub replay : Box < dyn Replay > ,
@@ -897,6 +897,7 @@ impl Handler {
897897
898898 pub fn set_breakpoints ( & mut self , request : dap:: Request , args : dap_types:: SetBreakpointsArguments ) -> Result < ( ) , Box < dyn Error > > {
899899 let mut results = Vec :: new ( ) ;
900+ // for now simples to redo them every time: TODO possible optimizations
900901 self . clear_breakpoints ( ) ?;
901902 if let Some ( path) = args. source . path . clone ( ) {
902903 let lines: Vec < i64 > = if let Some ( bps) = args. breakpoints {
@@ -906,10 +907,6 @@ impl Handler {
906907 } ;
907908
908909 for line in lines {
909- {
910- let entry = self . breakpoints . entry ( path. clone ( ) ) . or_default ( ) ;
911- entry. insert ( line) ;
912- }
913910 let _ = self . add_breakpoint (
914911 SourceLocation {
915912 path : path. clone ( ) ,
@@ -967,18 +964,24 @@ impl Handler {
967964 }
968965
969966 pub fn add_breakpoint ( & mut self , loc : SourceLocation ) -> Result < ( ) , Box < dyn Error > > {
970- let _breakpoint = self . replay . add_breakpoint ( & loc. path , loc. line as i64 ) ?;
971- // TODO: map them to id-s in handler so we can do the reverse on delete and let replay work with breakpoints?
967+ let breakpoint = self . replay . add_breakpoint ( & loc. path , loc. line as i64 ) ?;
968+ let entry = self . breakpoints . entry ( ( loc. path . clone ( ) , loc. line as i64 ) ) . or_default ( ) ;
969+ entry. push ( breakpoint) ;
972970 Ok ( ( ) )
973971 }
974972
975- pub fn delete_breakpoint ( & mut self , _loc : SourceLocation , _task : Task ) -> Result < ( ) , Box < dyn Error > > {
976- // TODO: load themfrom handler id map: self.replay.delete_breakpoint(loc)
973+ pub fn delete_breakpoints_for_location ( & mut self , loc : SourceLocation , _task : Task ) -> Result < ( ) , Box < dyn Error > > {
974+ if self . breakpoints . contains_key ( & ( loc. path . clone ( ) , loc. line as i64 ) ) {
975+ for breakpoint in & self . breakpoints [ & ( loc. path . clone ( ) , loc. line as i64 ) ] {
976+ self . replay . delete_breakpoint ( breakpoint) ?;
977+ }
978+ }
977979 Ok ( ( ) )
978980 }
979981
980982 pub fn clear_breakpoints ( & mut self ) -> Result < ( ) , Box < dyn Error > > {
981983 let _ = self . replay . delete_breakpoints ( ) ?;
984+ self . breakpoints . clear ( ) ;
982985 Ok ( ( ) )
983986 }
984987
0 commit comments