@@ -42,6 +42,7 @@ internal class UnityDebugSession : DebugSession
42
42
private Mono . Debugging . Client . StackFrame _activeFrame ;
43
43
private long _nextBreakpointId = 0 ;
44
44
private SortedDictionary < long , BreakEvent > _breakpoints ;
45
+ SourceBreakpoint [ ] breakpoints = new SourceBreakpoint [ 0 ] ;
45
46
private List < Catchpoint > _catchpoints ;
46
47
private DebuggerSessionOptions _debuggerSessionOptions ;
47
48
@@ -434,7 +435,7 @@ public override void SetBreakpoints(Response response, dynamic args)
434
435
{
435
436
string path = null ;
436
437
if ( args . source != null ) {
437
- string p = ( string ) args . source . path ;
438
+ var p = ( string ) args . source . path ;
438
439
if ( p != null && p . Trim ( ) . Length > 0 ) {
439
440
path = p ;
440
441
}
@@ -443,68 +444,44 @@ public override void SetBreakpoints(Response response, dynamic args)
443
444
SendErrorResponse ( response , 3010 , "setBreakpoints: property 'source' is empty or misformed" , null , false , true ) ;
444
445
return ;
445
446
}
446
- path = ConvertClientPathToDebugger ( path ) ;
447
447
448
448
if ( ! HasMonoExtension ( path ) ) {
449
449
// we only support breakpoints in files mono can handle
450
450
SendResponse ( response , new SetBreakpointsResponseBody ( ) ) ;
451
451
return ;
452
452
}
453
453
454
- var clientLines = args . lines . ToObject < int [ ] > ( ) ;
455
- HashSet < int > lin = new HashSet < int > ( ) ;
456
- for ( int i = 0 ; i < clientLines . Length ; i ++ ) {
457
- lin . Add ( ConvertClientLineToDebugger ( clientLines [ i ] ) ) ;
458
- }
459
-
460
- // find all breakpoints for the given path and remember their id and line number
461
- var bpts = new List < Tuple < int , int > > ( ) ;
462
- foreach ( var be in _breakpoints ) {
463
- var bp = be . Value as Mono . Debugging . Client . Breakpoint ;
464
- if ( bp != null && bp . FileName == path ) {
465
- bpts . Add ( new Tuple < int , int > ( ( int ) be . Key , ( int ) bp . Line ) ) ;
454
+ SourceBreakpoint [ ] newBreakpoints = getBreakpoints ( args , "breakpoints" ) ;
455
+ var lines = newBreakpoints . Select ( bp => bp . line ) ;
456
+ var breakpointsToRemove = breakpoints . Where ( bp => ! lines . Contains ( bp . line ) ) . ToArray ( ) ;
457
+ foreach ( Breakpoint breakpoint in _session . Breakpoints )
458
+ {
459
+ if ( breakpointsToRemove . Any ( bp => bp . line == breakpoint . Line ) )
460
+ {
461
+ _session . Breakpoints . Remove ( breakpoint ) ;
466
462
}
467
463
}
468
464
469
- HashSet < int > lin2 = new HashSet < int > ( ) ;
470
- foreach ( var bpt in bpts ) {
471
- if ( lin . Contains ( bpt . Item2 ) ) {
472
- lin2 . Add ( bpt . Item2 ) ;
473
- }
474
- else {
475
- // Program.WriteLine("cleared bpt #{0} for line {1}", bpt.Item1, bpt.Item2);
476
-
477
- BreakEvent b ;
478
- if ( _breakpoints . TryGetValue ( bpt . Item1 , out b ) ) {
479
- _breakpoints . Remove ( bpt . Item1 ) ;
480
- _session . Breakpoints . Remove ( b ) ;
481
- }
465
+ foreach ( var sourceBreakpoint in newBreakpoints )
466
+ {
467
+ var breakEvents = _session . Breakpoints . Where ( bp => ( ( Breakpoint ) bp ) . Line == sourceBreakpoint . line ) ;
468
+ var enumerable = breakEvents as BreakEvent [ ] ?? breakEvents . ToArray ( ) ;
469
+ if ( enumerable . Any ( ) )
470
+ {
471
+ enumerable . First ( ) . ConditionExpression = sourceBreakpoint . condition ;
482
472
}
483
- }
484
-
485
- for ( int i = 0 ; i < clientLines . Length ; i ++ ) {
486
- var l = ConvertClientLineToDebugger ( clientLines [ i ] ) ;
487
- if ( ! lin2 . Contains ( l ) ) {
488
- var id = _nextBreakpointId ;
489
- _breakpoints [ id ] = _session . Breakpoints . Add ( path , l ) ;
490
- // Program.WriteLine("added bpt #{0} for line {1}", id, l);
473
+ else
474
+ {
475
+ var breakpoint = _session . Breakpoints . Add ( path , sourceBreakpoint . line ) ;
476
+ breakpoint . ConditionExpression = sourceBreakpoint . condition ;
491
477
}
492
478
}
493
479
494
- var breakpoints = new List < VSCodeDebug . Breakpoint > ( ) ;
495
- foreach ( var l in clientLines )
496
- {
497
- breakpoints . Add ( new VSCodeDebug . Breakpoint ( true , l ) ) ;
498
- }
499
-
500
- SourceBreakpoint [ ] breaks = getBreakpoints ( args , "breakpoints" ) ;
501
- foreach ( Breakpoint breakpoint in _session . Breakpoints )
502
- {
503
- var sourceBreakpoint = breaks . First ( bp => bp . line == breakpoint . Line ) ;
504
- breakpoint . ConditionExpression = sourceBreakpoint . condition ;
505
- }
480
+ breakpoints = newBreakpoints ;
506
481
507
- SendResponse ( response , new SetBreakpointsResponseBody ( breakpoints ) ) ;
482
+ var responseBreakpoints = newBreakpoints . Select ( sourceBreakpoint =>
483
+ new VSCodeDebug . Breakpoint ( true , sourceBreakpoint . line , sourceBreakpoint . column , sourceBreakpoint . logMessage ) ) . ToList ( ) ;
484
+ SendResponse ( response , new SetBreakpointsResponseBody ( responseBreakpoints ) ) ; // TODO: Start here!!!
508
485
}
509
486
510
487
public override void StackTrace ( Response response , dynamic args )
0 commit comments