diff --git a/src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs b/src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs index 450a789ad6806d..af4707ae7b8cfe 100644 --- a/src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs +++ b/src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs @@ -1185,18 +1185,18 @@ internal async Task LoadStore(SessionId sessionId, CancellationToken try { - string[] loaded_files = context.LoadedFiles; + string[] loaded_files = await GetLoadedFiles(sessionId, context, token); if (loaded_files == null) { - Result loaded = await SendMonoCommand(sessionId, MonoCommands.GetLoadedFiles(), token); - loaded_files = loaded.Value?["result"]?["value"]?.ToObject(); + Console.WriteLine($"Failed to get the list of loaded files. Managed code debugging won't work due to this."); } - - await - foreach (SourceFile source in context.store.Load(sessionId, loaded_files, token).WithCancellation(token)) + else { - await OnSourceFileAdded(sessionId, source, context, token); + await foreach (SourceFile source in context.store.Load(sessionId, loaded_files, token).WithCancellation(token)) + { + await OnSourceFileAdded(sessionId, source, context, token); + } } } catch (Exception e) @@ -1207,6 +1207,25 @@ internal async Task LoadStore(SessionId sessionId, CancellationToken if (!context.Source.Task.IsCompleted) context.Source.SetResult(context.store); return context.store; + + async Task GetLoadedFiles(SessionId sessionId, ExecutionContext context, CancellationToken token) + { + if (context.LoadedFiles != null) + return context.LoadedFiles; + + Result loaded = await SendMonoCommand(sessionId, MonoCommands.GetLoadedFiles(), token); + if (!loaded.IsOk) + { + Console.WriteLine($"Error on mono_wasm_get_loaded_files {loaded}"); + return null; + } + + string[] files = loaded.Value?["result"]?["value"]?.ToObject(); + if (files == null) + Console.WriteLine($"Error extracting the list of loaded_files from the result of mono_wasm_get_loaded_files: {loaded}"); + + return files; + } } private async Task RuntimeReady(SessionId sessionId, CancellationToken token) diff --git a/src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs b/src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs index 60cd0242bfddcc..2c95d68eec9b22 100644 --- a/src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs +++ b/src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs @@ -642,5 +642,75 @@ await EvaluateAndCheck( } ); } + + [Fact] + public async Task CreateGoodBreakpointAndHitGoToWasmPageWithoutAssetsComeBackAndHitAgain() + { + var bp = await SetBreakpoint("dotnet://debugger-test.dll/debugger-test.cs", 10, 8); + var pause_location = await EvaluateAndCheck( + "window.setTimeout(function() { invoke_add(); }, 1);", + "dotnet://debugger-test.dll/debugger-test.cs", 10, 8, + "IntAdd"); + Assert.Equal("other", pause_location["reason"]?.Value()); + Assert.Equal(bp.Value["breakpointId"]?.ToString(), pause_location["hitBreakpoints"]?[0]?.Value()); + + var top_frame = pause_location["callFrames"][0]; + Assert.Equal("IntAdd", top_frame["functionName"].Value()); + Assert.Contains("debugger-test.cs", top_frame["url"].Value()); + + CheckLocation("dotnet://debugger-test.dll/debugger-test.cs", 8, 4, scripts, top_frame["functionLocation"]); + + //now check the scope + var scope = top_frame["scopeChain"][0]; + Assert.Equal("local", scope["type"]); + Assert.Equal("IntAdd", scope["name"]); + + Assert.Equal("object", scope["object"]["type"]); + CheckLocation("dotnet://debugger-test.dll/debugger-test.cs", 8, 4, scripts, scope["startLocation"]); + CheckLocation("dotnet://debugger-test.dll/debugger-test.cs", 14, 4, scripts, scope["endLocation"]); + + await cli.SendCommand("Debugger.resume", null, token); + + var run_method = JObject.FromObject(new + { + expression = "window.setTimeout(function() { load_wasm_page_without_assets(); }, 1);" + }); + await cli.SendCommand("Runtime.evaluate", run_method, token); + await Task.Delay(1000, token); + run_method = JObject.FromObject(new + { + expression = "window.setTimeout(function() { reload_wasm_page(); }, 1);" + }); + await cli.SendCommand("Runtime.evaluate", run_method, token); + await Task.Delay(1000, token); + await insp.WaitFor(Inspector.READY); + await EvaluateAndCheck( + "window.setTimeout(function() { invoke_add(); }, 1);", + "dotnet://debugger-test.dll/debugger-test.cs", 10, 8, + "IntAdd", + wait_for_event_fn: async (pause_location) => + { + Assert.Equal("other", pause_location["reason"]?.Value()); + Assert.Equal(bp.Value["breakpointId"]?.ToString(), pause_location["hitBreakpoints"]?[0]?.Value()); + + var top_frame = pause_location["callFrames"][0]; + Assert.Equal("IntAdd", top_frame["functionName"].Value()); + Assert.Contains("debugger-test.cs", top_frame["url"].Value()); + + CheckLocation("dotnet://debugger-test.dll/debugger-test.cs", 8, 4, scripts, top_frame["functionLocation"]); + + //now check the scope + var scope = top_frame["scopeChain"][0]; + Assert.Equal("local", scope["type"]); + Assert.Equal("IntAdd", scope["name"]); + + Assert.Equal("object", scope["object"]["type"]); + CheckLocation("dotnet://debugger-test.dll/debugger-test.cs", 8, 4, scripts, scope["startLocation"]); + CheckLocation("dotnet://debugger-test.dll/debugger-test.cs", 14, 4, scripts, scope["endLocation"]); + await Task.CompletedTask; + } + ); + } + } } diff --git a/src/mono/wasm/debugger/tests/debugger-test/debugger-driver.html b/src/mono/wasm/debugger/tests/debugger-test/debugger-driver.html index ddf5dc54e48ead..21e1f156966b73 100644 --- a/src/mono/wasm/debugger/tests/debugger-test/debugger-driver.html +++ b/src/mono/wasm/debugger/tests/debugger-test/debugger-driver.html @@ -82,11 +82,14 @@ function invoke_add_with_parms (a, b) { return App.int_add (a, b); } - function load_non_wasm_page () { console.log("load_non_wasm_page") window.location.replace("http://localhost:9400/non-wasm-page.html"); } + function load_wasm_page_without_assets () { + console.log("load_wasm_page_without_assets") + window.location.replace("http://localhost:9400/wasm-page-without-assets.html"); + } diff --git a/src/mono/wasm/debugger/tests/debugger-test/debugger-test.csproj b/src/mono/wasm/debugger/tests/debugger-test/debugger-test.csproj index 7e8478cfc07b25..89a81f1b7cf094 100644 --- a/src/mono/wasm/debugger/tests/debugger-test/debugger-test.csproj +++ b/src/mono/wasm/debugger/tests/debugger-test/debugger-test.csproj @@ -11,6 +11,7 @@ + diff --git a/src/mono/wasm/debugger/tests/debugger-test/wasm-page-without-assets.html b/src/mono/wasm/debugger/tests/debugger-test/wasm-page-without-assets.html new file mode 100644 index 00000000000000..d8bfb820c0d427 --- /dev/null +++ b/src/mono/wasm/debugger/tests/debugger-test/wasm-page-without-assets.html @@ -0,0 +1,21 @@ + + + + + + + + + + Stuff goes here + + \ No newline at end of file