@@ -134,9 +134,7 @@ protected override async Task<bool> AcceptEvent(SessionId sessionId, string meth
134134 {
135135 string exceptionError = args ? [ "exceptionDetails" ] ? [ "exception" ] ? [ "value" ] ? . Value < string > ( ) ;
136136 if ( exceptionError == sPauseOnUncaught || exceptionError == sPauseOnCaught )
137- {
138137 return true ;
139- }
140138 }
141139 break ;
142140 }
@@ -156,17 +154,19 @@ protected override async Task<bool> AcceptEvent(SessionId sessionId, string meth
156154 if ( exceptionError == sPauseOnUncaught )
157155 {
158156 await SendCommand ( sessionId , "Debugger.resume" , new JObject ( ) , token ) ;
159- context . PauseOnUncaught = true ;
157+ if ( context . PauseOnExceptions == PauseOnExceptionsKind . Unset )
158+ context . PauseOnExceptions = PauseOnExceptionsKind . Uncaught ;
160159 return true ;
161160 }
162161 if ( exceptionError == sPauseOnCaught )
163162 {
164163 await SendCommand ( sessionId , "Debugger.resume" , new JObject ( ) , token ) ;
165- context . PauseOnCaught = true ;
164+ context . PauseOnExceptions = PauseOnExceptionsKind . All ;
166165 return true ;
167166 }
168167 }
169168 }
169+
170170 //TODO figure out how to stich out more frames and, in particular what happens when real wasm is on the stack
171171 string top_func = args ? [ "callFrames" ] ? [ 0 ] ? [ "functionName" ] ? . Value < string > ( ) ;
172172 switch ( top_func ) {
@@ -442,23 +442,16 @@ protected override async Task<bool> AcceptCommand(MessageId id, string method, J
442442 case "Debugger.setPauseOnExceptions" :
443443 {
444444 string state = args [ "state" ] . Value < string > ( ) ;
445- if ( ! context . IsRuntimeReady )
445+ context . PauseOnExceptions = state switch
446446 {
447- context . PauseOnCaught = false ;
448- context . PauseOnUncaught = false ;
449- switch ( state )
450- {
451- case "all" :
452- context . PauseOnCaught = true ;
453- context . PauseOnUncaught = true ;
454- break ;
455- case "uncaught" :
456- context . PauseOnUncaught = true ;
457- break ;
458- }
459- }
460- else
461- await SdbHelper . EnableExceptions ( id , state , token ) ;
447+ "all" => PauseOnExceptionsKind . All ,
448+ "uncaught" => PauseOnExceptionsKind . Uncaught ,
449+ "none" => PauseOnExceptionsKind . None ,
450+ _ => PauseOnExceptionsKind . Unset
451+ } ;
452+
453+ if ( context . IsRuntimeReady )
454+ await SdbHelper . EnableExceptions ( id , context . PauseOnExceptions , token ) ;
462455 // Pass this on to JS too
463456 return false ;
464457 }
@@ -875,7 +868,7 @@ private async Task<bool> OnReceiveDebuggerAgentEvent(SessionId sessionId, JObjec
875868 int object_id = retDebuggerCmdReader . ReadInt32 ( ) ;
876869 var caught = retDebuggerCmdReader . ReadByte ( ) ;
877870 var exceptionObject = await SdbHelper . GetObjectValues ( sessionId , object_id , GetObjectCommandOptions . WithProperties | GetObjectCommandOptions . OwnProperties , token ) ;
878- var exceptionObjectMessage = exceptionObject . FirstOrDefault ( attr => attr [ "name" ] . Value < string > ( ) . Equals ( "message " ) ) ;
871+ var exceptionObjectMessage = exceptionObject . FirstOrDefault ( attr => attr [ "name" ] . Value < string > ( ) . Equals ( "_message " ) ) ;
879872 var data = JObject . FromObject ( new
880873 {
881874 type = "object" ,
@@ -965,6 +958,7 @@ private async Task OnDefaultContext(SessionId sessionId, ExecutionContext contex
965958 {
966959 context . BreakpointRequests [ kvp . Key ] = kvp . Value . Clone ( ) ;
967960 }
961+ context . PauseOnExceptions = previousContext . PauseOnExceptions ;
968962 }
969963
970964 if ( await IsRuntimeAlreadyReadyAlready ( sessionId , token ) )
@@ -1228,10 +1222,8 @@ private async Task<DebugStore> RuntimeReady(SessionId sessionId, CancellationTok
12281222 Log ( "verbose" , $ "Failed to clear breakpoints") ;
12291223 }
12301224
1231- if ( context . PauseOnCaught && context . PauseOnUncaught )
1232- await SdbHelper . EnableExceptions ( sessionId , "all" , token ) ;
1233- else if ( context . PauseOnUncaught )
1234- await SdbHelper . EnableExceptions ( sessionId , "uncaught" , token ) ;
1225+ if ( context . PauseOnExceptions != PauseOnExceptionsKind . None && context . PauseOnExceptions != PauseOnExceptionsKind . Unset )
1226+ await SdbHelper . EnableExceptions ( sessionId , context . PauseOnExceptions , token ) ;
12351227
12361228 await SdbHelper . SetProtocolVersion ( sessionId , token ) ;
12371229 await SdbHelper . EnableReceiveRequests ( sessionId , EventKind . UserBreak , token ) ;
@@ -1393,8 +1385,19 @@ private async Task AttachToTarget(SessionId sessionId, CancellationToken token)
13931385 // see https://github.com/mono/mono/issues/19549 for background
13941386 if ( sessions . Add ( sessionId ) )
13951387 {
1396- string checkUncaughtExceptions = $ "throw \" { sPauseOnUncaught } \" ;";
1397- string checkCaughtExceptions = $ "try {{throw \" { sPauseOnCaught } \" ;}} catch {{}}";
1388+ string checkUncaughtExceptions = string . Empty ;
1389+ string checkCaughtExceptions = string . Empty ;
1390+
1391+ //we only need this check if it's a non-vs debugging
1392+ if ( sessionId == SessionId . Null )
1393+ {
1394+ if ( ! contexts . TryGetValue ( sessionId , out ExecutionContext context ) || context . PauseOnExceptions == PauseOnExceptionsKind . Unset )
1395+ {
1396+ checkUncaughtExceptions = $ "throw \" { sPauseOnUncaught } \" ;";
1397+ checkCaughtExceptions = $ "try {{throw \" { sPauseOnCaught } \" ;}} catch {{}}";
1398+ }
1399+ }
1400+
13981401 await SendMonoCommand ( sessionId , new MonoCommands ( "globalThis.dotnetDebugger = true" ) , token ) ;
13991402 Result res = await SendCommand ( sessionId ,
14001403 "Page.addScriptToEvaluateOnNewDocument" ,
0 commit comments