@@ -361,37 +361,44 @@ protected override async Task<bool> AcceptCommand(MessageId id, JObject parms, C
361361 SendResponse ( id , resp , token ) ;
362362 return true ;
363363 }
364+ try
365+ {
366+ string bpid = resp . Value [ "breakpointId" ] ? . ToString ( ) ;
367+ IEnumerable < object > locations = resp . Value [ "locations" ] ? . Values < object > ( ) ;
368+ var request = BreakpointRequest . Parse ( bpid , args ) ;
364369
365- string bpid = resp . Value [ "breakpointId" ] ? . ToString ( ) ;
366- IEnumerable < object > locations = resp . Value [ "locations" ] ? . Values < object > ( ) ;
367- var request = BreakpointRequest . Parse ( bpid , args ) ;
370+ // is the store done loading?
371+ bool loaded = context . Source . Task . IsCompleted ;
372+ if ( ! loaded )
373+ {
374+ // Send and empty response immediately if not
375+ // and register the breakpoint for resolution
376+ context . BreakpointRequests [ bpid ] = request ;
377+ SendResponse ( id , resp , token ) ;
378+ }
368379
369- // is the store done loading?
370- bool loaded = context . Source . Task . IsCompleted ;
371- if ( ! loaded )
372- {
373- // Send and empty response immediately if not
374- // and register the breakpoint for resolution
375- context . BreakpointRequests [ bpid ] = request ;
376- SendResponse ( id , resp , token ) ;
377- }
380+ if ( await IsRuntimeAlreadyReadyAlready ( id , token ) )
381+ {
382+ DebugStore store = await RuntimeReady ( id , token ) ;
378383
379- if ( await IsRuntimeAlreadyReadyAlready ( id , token ) )
380- {
381- DebugStore store = await RuntimeReady ( id , token ) ;
384+ Log ( "verbose" , $ "BP req { args } " ) ;
385+ await SetBreakpoint ( id , store , request , ! loaded , false , token ) ;
386+ }
382387
383- Log ( "verbose" , $ "BP req { args } ") ;
384- await SetBreakpoint ( id , store , request , ! loaded , false , token ) ;
385- }
388+ if ( loaded )
389+ {
390+ // we were already loaded so we should send a response
391+ // with the locations included and register the request
392+ context . BreakpointRequests [ bpid ] = request ;
393+ var result = Result . OkFromObject ( request . AsSetBreakpointByUrlResponse ( locations ) ) ;
394+ SendResponse ( id , result , token ) ;
386395
387- if ( loaded )
396+ }
397+ }
398+ catch ( Exception e )
388399 {
389- // we were already loaded so we should send a response
390- // with the locations included and register the request
391- context . BreakpointRequests [ bpid ] = request ;
392- var result = Result . OkFromObject ( request . AsSetBreakpointByUrlResponse ( locations ) ) ;
393- SendResponse ( id , result , token ) ;
394-
400+ logger . LogDebug ( $ "Debugger.setBreakpointByUrl - { args } - failed with exception: { e } ") ;
401+ SendResponse ( id , Result . Err ( $ "Debugger.setBreakpointByUrl - { args } - failed with exception: { e } ") , token ) ;
395402 }
396403 return true ;
397404 }
@@ -1449,7 +1456,8 @@ private async Task<Breakpoint> SetMonoBreakpoint(SessionId sessionId, string req
14491456
14501457 var assembly_id = await context . SdbAgent . GetAssemblyId ( asm_name , token ) ;
14511458 var methodId = await context . SdbAgent . GetMethodIdByToken ( assembly_id , method_token , token ) ;
1452- var breakpoint_id = await context . SdbAgent . SetBreakpoint ( methodId , il_offset , token ) ;
1459+ //the breakpoint can be invalid because a race condition between the changes already applied on runtime and not applied yet on debugger side
1460+ var breakpoint_id = await context . SdbAgent . SetBreakpointNoThrow ( methodId , il_offset , token ) ;
14531461
14541462 if ( breakpoint_id > 0 )
14551463 {
@@ -1726,7 +1734,10 @@ private async Task<bool> OnSetNextIP(MessageId sessionId, SourceLocation targetL
17261734 if ( ! ret )
17271735 return false ;
17281736
1729- var breakpointId = await context . SdbAgent . SetBreakpoint ( scope . Method . DebugId , ilOffset . Offset , token ) ;
1737+ var breakpointId = await context . SdbAgent . SetBreakpointNoThrow ( scope . Method . DebugId , ilOffset . Offset , token ) ;
1738+ if ( breakpointId == - 1 )
1739+ return false ;
1740+
17301741 context . TempBreakpointForSetNextIP = breakpointId ;
17311742 await SendResume ( sessionId , token ) ;
17321743 return true ;
0 commit comments