From 5c15820d6c660673f0a0a2db55d246a05eaa9c9f Mon Sep 17 00:00:00 2001 From: Thays Grazia Date: Wed, 26 Oct 2022 13:20:03 -0300 Subject: [PATCH 1/2] Fixing when trying to call mono functions in a non wasm page --- .../debugger/BrowserDebugProxy/MonoProxy.cs | 47 ++++++++++++------- 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs b/src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs index b34437b7238ccd..78768a209546b1 100644 --- a/src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs +++ b/src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs @@ -1546,27 +1546,38 @@ async Task GetLoadedFiles(SessionId sessionId, ExecutionContext contex protected async Task RuntimeReady(SessionId sessionId, CancellationToken token) { - ExecutionContext context = GetContext(sessionId); - if (Interlocked.CompareExchange(ref context.ready, new TaskCompletionSource(), null) != null) - return await context.ready.Task; - var res = await context.SdbAgent.SendDebuggerAgentCommand(CmdEventRequest.ClearAllBreakpoints, null, token, false); - if (res.HasError) //it's not a wasm page then the command returns an error - return null; + try + { + ExecutionContext context = GetContext(sessionId); + if (Interlocked.CompareExchange(ref context.ready, new TaskCompletionSource(), null) != null) + return await context.ready.Task; + await context.SdbAgent.SendDebuggerAgentCommand(CmdEventRequest.ClearAllBreakpoints, null, token); - if (context.PauseOnExceptions != PauseOnExceptionsKind.None && context.PauseOnExceptions != PauseOnExceptionsKind.Unset) - await context.SdbAgent.EnableExceptions(context.PauseOnExceptions, token); + if (context.PauseOnExceptions != PauseOnExceptionsKind.None && context.PauseOnExceptions != PauseOnExceptionsKind.Unset) + await context.SdbAgent.EnableExceptions(context.PauseOnExceptions, token); - await context.SdbAgent.SetProtocolVersion(token); - await context.SdbAgent.EnableReceiveRequests(EventKind.UserBreak, token); - await context.SdbAgent.EnableReceiveRequests(EventKind.EnC, token); - await context.SdbAgent.EnableReceiveRequests(EventKind.MethodUpdate, token); + await context.SdbAgent.SetProtocolVersion(token); + await context.SdbAgent.EnableReceiveRequests(EventKind.UserBreak, token); + await context.SdbAgent.EnableReceiveRequests(EventKind.EnC, token); + await context.SdbAgent.EnableReceiveRequests(EventKind.MethodUpdate, token); - DebugStore store = await LoadStore(sessionId, true, token); - context.ready.SetResult(store); - await SendEvent(sessionId, "Mono.runtimeReady", new JObject(), token); - await SendMonoCommand(sessionId, MonoCommands.SetDebuggerAttached(RuntimeId), token); - context.SdbAgent.ResetStore(store); - return store; + DebugStore store = await LoadStore(sessionId, true, token); + context.ready.SetResult(store); + await SendEvent(sessionId, "Mono.runtimeReady", new JObject(), token); + await SendMonoCommand(sessionId, MonoCommands.SetDebuggerAttached(RuntimeId), token); + context.SdbAgent.ResetStore(store); + return store; + } + catch (DebuggerAgentException) + { + //it's not a wasm page then the command throws an error + return null; + } + catch (Exception e) + { + logger.LogDebug($"Unexpected error on RuntimeReady {e}"); + return null; + } } private static IEnumerable> GetBPReqLocations(DebugStore store, BreakpointRequest req, bool ifNoneFoundThenFindNext = false) From 5ca32a54fb18f77fd76ee4b4e55d0e6b5048bdce Mon Sep 17 00:00:00 2001 From: Thays Grazia Date: Wed, 26 Oct 2022 14:54:25 -0300 Subject: [PATCH 2/2] Adding a log message as suggested by @radical --- src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs b/src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs index 78768a209546b1..1cdeb0dfe222cc 100644 --- a/src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs +++ b/src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs @@ -1568,9 +1568,11 @@ protected async Task RuntimeReady(SessionId sessionId, CancellationT context.SdbAgent.ResetStore(store); return store; } - catch (DebuggerAgentException) + catch (DebuggerAgentException e) { //it's not a wasm page then the command throws an error + if (!e.Message.Contains("getDotnetRuntime is not defined")) + logger.LogDebug($"Unexpected error on RuntimeReady {e}"); return null; } catch (Exception e)