@@ -24,7 +24,7 @@ internal class MonoProxy : DevToolsProxy
24
24
internal string CachePathSymbolServer { get ; private set ; }
25
25
private readonly HashSet < SessionId > sessions = new HashSet < SessionId > ( ) ;
26
26
private static readonly string [ ] s_executionContextIndependentCDPCommandNames = { "DotnetDebugger.setDebuggerProperty" , "DotnetDebugger.runTests" } ;
27
- protected Dictionary < SessionId , ExecutionContext > contexts = new Dictionary < SessionId , ExecutionContext > ( ) ;
27
+ protected Dictionary < SessionId , List < ExecutionContext > > contexts = new Dictionary < SessionId , List < ExecutionContext > > ( ) ;
28
28
29
29
public static HttpClient HttpClient => new HttpClient ( ) ;
30
30
@@ -45,24 +45,37 @@ public MonoProxy(ILogger logger, int runtimeId = 0, string loggerId = "", ProxyO
45
45
46
46
internal ExecutionContext GetContext ( SessionId sessionId )
47
47
{
48
- if ( contexts . TryGetValue ( sessionId , out ExecutionContext context ) )
48
+ if ( TryGetCurrentExecutionContextValue ( sessionId , out ExecutionContext context ) )
49
49
return context ;
50
50
51
51
throw new ArgumentException ( $ "Invalid Session: \" { sessionId } \" ", nameof ( sessionId ) ) ;
52
52
}
53
53
54
54
private bool UpdateContext ( SessionId sessionId , ExecutionContext executionContext , out ExecutionContext previousExecutionContext )
55
55
{
56
- bool previous = contexts . TryGetValue ( sessionId , out previousExecutionContext ) ;
57
- contexts [ sessionId ] = executionContext ;
56
+ bool previous = TryGetCurrentExecutionContextValue ( sessionId , out previousExecutionContext ) ;
57
+ if ( ! previous )
58
+ contexts [ sessionId ] = new ( ) ;
59
+ contexts [ sessionId ] . Add ( executionContext ) ;
58
60
return previous ;
59
61
}
60
62
63
+ internal bool TryGetCurrentExecutionContextValue ( SessionId id , out ExecutionContext executionContext )
64
+ {
65
+ executionContext = null ;
66
+ if ( ! contexts . TryGetValue ( id , out List < ExecutionContext > contextList ) )
67
+ return false ;
68
+ if ( contextList . Count == 0 )
69
+ return false ;
70
+ executionContext = contextList . Last < ExecutionContext > ( ) ;
71
+ return true ;
72
+ }
73
+
61
74
internal virtual Task < Result > SendMonoCommand ( SessionId id , MonoCommands cmd , CancellationToken token ) => SendCommand ( id , "Runtime.evaluate" , JObject . FromObject ( cmd ) , token ) ;
62
75
63
76
internal void SendLog ( SessionId sessionId , string message , CancellationToken token , string type = "warning" )
64
77
{
65
- if ( ! contexts . TryGetValue ( sessionId , out ExecutionContext context ) )
78
+ if ( ! TryGetCurrentExecutionContextValue ( sessionId , out ExecutionContext context ) )
66
79
return ;
67
80
/*var o = JObject.FromObject(new
68
81
{
@@ -151,6 +164,16 @@ protected override async Task<bool> AcceptEvent(SessionId sessionId, JObject par
151
164
}
152
165
return true ;
153
166
}
167
+ case "Runtime.executionContextDestroyed" :
168
+ {
169
+ int id = args [ "executionContextId" ] . Value < int > ( ) ;
170
+ if ( ! contexts . TryGetValue ( sessionId , out var contextList ) )
171
+ return false ;
172
+ contextList . RemoveAll ( x => x . Id == id ) ;
173
+ if ( contextList . Count == 0 )
174
+ contexts . Remove ( sessionId ) ;
175
+ return false ;
176
+ }
154
177
155
178
case "Debugger.paused" :
156
179
{
@@ -188,7 +211,7 @@ protected async Task<bool> OnDebuggerPaused(SessionId sessionId, JObject args, C
188
211
189
212
if ( args [ "asyncStackTraceId" ] != null )
190
213
{
191
- if ( ! contexts . TryGetValue ( sessionId , out ExecutionContext context ) )
214
+ if ( ! TryGetCurrentExecutionContextValue ( sessionId , out ExecutionContext context ) )
192
215
return false ;
193
216
if ( context . CopyDataFromParentContext ( ) )
194
217
{
@@ -254,7 +277,7 @@ protected async Task<bool> OnDebuggerPaused(SessionId sessionId, JObject args, C
254
277
255
278
protected void CreateWorkerExecutionContext ( SessionId workerSessionId , SessionId originSessionId )
256
279
{
257
- if ( ! contexts . TryGetValue ( originSessionId , out ExecutionContext context ) )
280
+ if ( ! TryGetCurrentExecutionContextValue ( originSessionId , out ExecutionContext context ) )
258
281
{
259
282
logger . LogDebug ( $ "Origin sessionId does not exist - { originSessionId } ") ;
260
283
return ;
@@ -264,7 +287,8 @@ protected void CreateWorkerExecutionContext(SessionId workerSessionId, SessionId
264
287
logger . LogDebug ( $ "Worker sessionId already exists - { originSessionId } ") ;
265
288
return ;
266
289
}
267
- contexts [ workerSessionId ] = context . CreateChildAsyncExecutionContext ( workerSessionId ) ;
290
+ contexts [ workerSessionId ] = new ( ) ;
291
+ contexts [ workerSessionId ] . Add ( context . CreateChildAsyncExecutionContext ( workerSessionId ) ) ;
268
292
}
269
293
270
294
protected virtual async Task SendResume ( SessionId id , CancellationToken token )
@@ -273,7 +297,7 @@ protected virtual async Task SendResume(SessionId id, CancellationToken token)
273
297
}
274
298
protected async Task < bool > IsRuntimeAlreadyReadyAlready ( SessionId sessionId , CancellationToken token )
275
299
{
276
- if ( contexts . TryGetValue ( sessionId , out ExecutionContext context ) && context . IsRuntimeReady )
300
+ if ( TryGetCurrentExecutionContextValue ( sessionId , out ExecutionContext context ) && context . IsRuntimeReady )
277
301
return true ;
278
302
279
303
Result res = await SendMonoCommand ( sessionId , MonoCommands . IsRuntimeReady ( RuntimeId ) , token ) ;
@@ -298,7 +322,7 @@ protected override async Task<bool> AcceptCommand(MessageId id, JObject parms, C
298
322
if ( id == SessionId . Null )
299
323
await AttachToTarget ( id , token ) ;
300
324
301
- if ( ! contexts . TryGetValue ( id , out ExecutionContext context ) && ! s_executionContextIndependentCDPCommandNames . Contains ( method ) )
325
+ if ( ! TryGetCurrentExecutionContextValue ( id , out ExecutionContext context ) && ! s_executionContextIndependentCDPCommandNames . Contains ( method ) )
302
326
{
303
327
if ( method == "Debugger.setPauseOnExceptions" )
304
328
{
0 commit comments