Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/dotnet/runtime.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgithub-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>2021-10-22 23:21:03 +0300
committerGitHub <noreply@github.com>2021-10-22 23:21:03 +0300
commitbf20df1d51db45ee6ae1931e9ef5eb6bf97d6b57 (patch)
treef34e14701b58d164bb38a5c39221f8cd7e1dead9
parentde751593a53e9ccaffef2420ad3d74727cad47aa (diff)
[release/6.0] [wasm][debugger] Fix loading a non wasm page and then returning to a wasm page. (#60777)
* Fix loading a non wasm page and then returning to a wasm page. * Adding non-wasm-page.html * fixing other method * addressing @radical comments * adding last empty line Co-authored-by: DESKTOP-GEPIA6N\Thays <thaystg@gmail.com>
-rw-r--r--src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs8
-rw-r--r--src/mono/wasm/debugger/BrowserDebugProxy/MonoSDBHelper.cs46
-rw-r--r--src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs75
-rw-r--r--src/mono/wasm/debugger/tests/debugger-test/debugger-driver.html25
-rw-r--r--src/mono/wasm/debugger/tests/debugger-test/debugger-test.csproj1
-rw-r--r--src/mono/wasm/debugger/tests/debugger-test/non-wasm-page.html12
6 files changed, 124 insertions, 43 deletions
diff --git a/src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs b/src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs
index 6c1ad7cf757..013fd92970a 100644
--- a/src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs
+++ b/src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs
@@ -1216,11 +1216,7 @@ namespace Microsoft.WebAssembly.Diagnostics
return await context.ready.Task;
var commandParams = new MemoryStream();
- var retDebuggerCmdReader = await SdbHelper.SendDebuggerAgentCommand<CmdEventRequest>(sessionId, CmdEventRequest.ClearAllBreakpoints, commandParams, token);
- if (retDebuggerCmdReader == null)
- {
- Log("verbose", $"Failed to clear breakpoints");
- }
+ await SdbHelper.SendDebuggerAgentCommand<CmdEventRequest>(sessionId, CmdEventRequest.ClearAllBreakpoints, commandParams, token);
if (context.PauseOnExceptions != PauseOnExceptionsKind.None && context.PauseOnExceptions != PauseOnExceptionsKind.Unset)
await SdbHelper.EnableExceptions(sessionId, context.PauseOnExceptions, token);
@@ -1233,7 +1229,7 @@ namespace Microsoft.WebAssembly.Diagnostics
DebugStore store = await LoadStore(sessionId, token);
context.ready.SetResult(store);
SendEvent(sessionId, "Mono.runtimeReady", new JObject(), token);
- SdbHelper.SetStore(store);
+ SdbHelper.ResetStore(store);
return store;
}
diff --git a/src/mono/wasm/debugger/BrowserDebugProxy/MonoSDBHelper.cs b/src/mono/wasm/debugger/BrowserDebugProxy/MonoSDBHelper.cs
index 9534d306eef..dee4b5ac0f5 100644
--- a/src/mono/wasm/debugger/BrowserDebugProxy/MonoSDBHelper.cs
+++ b/src/mono/wasm/debugger/BrowserDebugProxy/MonoSDBHelper.cs
@@ -379,7 +379,11 @@ namespace Microsoft.WebAssembly.Diagnostics
internal class MonoBinaryReader : BinaryReader
{
- public MonoBinaryReader(Stream stream) : base(stream) {}
+ public bool HasError { get; }
+ public MonoBinaryReader(Stream stream, bool hasError = false) : base(stream)
+ {
+ HasError = hasError;
+ }
internal static unsafe void PutBytesBE (byte *dest, byte *src, int count)
{
@@ -656,9 +660,9 @@ namespace Microsoft.WebAssembly.Diagnostics
private static int MINOR_VERSION = 61;
private static int MAJOR_VERSION = 2;
- private Dictionary<int, MethodInfoWithDebugInformation> methods = new();
- private Dictionary<int, AssemblyInfo> assemblies = new();
- private Dictionary<int, TypeInfoWithDebugInformation> types = new();
+ private Dictionary<int, MethodInfoWithDebugInformation> methods;
+ private Dictionary<int, AssemblyInfo> assemblies;
+ private Dictionary<int, TypeInfoWithDebugInformation> types;
internal Dictionary<int, ValueTypeClass> valueTypes = new Dictionary<int, ValueTypeClass>();
internal Dictionary<int, PointerValue> pointerValues = new Dictionary<int, PointerValue>();
@@ -673,12 +677,16 @@ namespace Microsoft.WebAssembly.Diagnostics
{
this.proxy = proxy;
this.logger = logger;
- this.store = null;
+ ResetStore(null);
}
- public void SetStore(DebugStore store)
+ public void ResetStore(DebugStore store)
{
this.store = store;
+ this.methods = new();
+ this.assemblies = new();
+ this.types = new();
+ ClearCache();
}
public async Task<AssemblyInfo> GetAssemblyInfo(SessionId sessionId, int assemblyId, CancellationToken token)
@@ -816,12 +824,12 @@ namespace Microsoft.WebAssembly.Diagnostics
internal async Task<MonoBinaryReader> SendDebuggerAgentCommandInternal(SessionId sessionId, int command_set, int command, MemoryStream parms, CancellationToken token)
{
Result res = await proxy.SendMonoCommand(sessionId, MonoCommands.SendDebuggerAgentCommand(GetId(), command_set, command, Convert.ToBase64String(parms.ToArray())), token);
- if (res.IsErr) {
- throw new Exception($"SendDebuggerAgentCommand Error - {(CommandSet)command_set} - {command}");
+ byte[] newBytes = Array.Empty<byte>();
+ if (!res.IsErr) {
+ newBytes = Convert.FromBase64String(res.Value?["result"]?["value"]?["value"]?.Value<string>());
}
- byte[] newBytes = Convert.FromBase64String(res.Value?["result"]?["value"]?["value"]?.Value<string>());
var retDebuggerCmd = new MemoryStream(newBytes);
- var retDebuggerCmdReader = new MonoBinaryReader(retDebuggerCmd);
+ var retDebuggerCmdReader = new MonoBinaryReader(retDebuggerCmd, res.IsErr);
return retDebuggerCmdReader;
}
@@ -854,12 +862,12 @@ namespace Microsoft.WebAssembly.Diagnostics
internal async Task<MonoBinaryReader> SendDebuggerAgentCommandWithParmsInternal(SessionId sessionId, int command_set, int command, MemoryStream parms, int type, string extraParm, CancellationToken token)
{
Result res = await proxy.SendMonoCommand(sessionId, MonoCommands.SendDebuggerAgentCommandWithParms(GetId(), command_set, command, Convert.ToBase64String(parms.ToArray()), parms.ToArray().Length, type, extraParm), token);
- if (res.IsErr) {
- throw new Exception("SendDebuggerAgentCommandWithParms Error");
+ byte[] newBytes = Array.Empty<byte>();
+ if (!res.IsErr) {
+ newBytes = Convert.FromBase64String(res.Value?["result"]?["value"]?["value"]?.Value<string>());
}
- byte[] newBytes = Convert.FromBase64String(res.Value?["result"]?["value"]?["value"]?.Value<string>());
var retDebuggerCmd = new MemoryStream(newBytes);
- var retDebuggerCmdReader = new MonoBinaryReader(retDebuggerCmd);
+ var retDebuggerCmdReader = new MonoBinaryReader(retDebuggerCmd, res.IsErr);
return retDebuggerCmdReader;
}
@@ -2530,15 +2538,9 @@ namespace Microsoft.WebAssembly.Diagnostics
JArray locals = new JArray();
retDebuggerCmdReader = await SendDebuggerAgentCommand<CmdFrame>(sessionId, CmdFrame.GetValues, commandParams, token);
int etype = retDebuggerCmdReader.ReadByte();
- try
- {
- retDebuggerCmdReader = await SendDebuggerAgentCommandWithParms<CmdFrame>(sessionId, CmdFrame.SetValues, commandParams, etype, newValue, token);
- }
- catch (Exception)
- {
+ retDebuggerCmdReader = await SendDebuggerAgentCommandWithParms<CmdFrame>(sessionId, CmdFrame.SetValues, commandParams, etype, newValue, token);
+ if (retDebuggerCmdReader.HasError)
return false;
- }
-
return true;
}
}
diff --git a/src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs b/src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs
index 6e9d420801d..60cd0242bfd 100644
--- a/src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs
+++ b/src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs
@@ -8,6 +8,7 @@ using Microsoft.WebAssembly.Diagnostics;
using Newtonsoft.Json.Linq;
using System.IO;
using Xunit;
+using System.Threading;
namespace DebuggerTests
{
@@ -131,11 +132,6 @@ namespace DebuggerTests
{
var bp = await SetBreakpoint("dotnet://debugger-test.dll/debugger-test.cs", 10, 8);
- var eval_req = JObject.FromObject(new
- {
- expression = "window.setTimeout(function() { invoke_add(); }, 1);",
- });
-
await EvaluateAndCheck(
"window.setTimeout(function() { invoke_add(); }, 1);",
"dotnet://debugger-test.dll/debugger-test.cs", 10, 8,
@@ -577,5 +573,74 @@ namespace DebuggerTests
CheckNumber(locals, "i", 2);
});
}
+
+ [Fact]
+ public async Task CreateGoodBreakpointAndHitGoToNonWasmPageComeBackAndHitAgain()
+ {
+ 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<string>());
+ Assert.Equal(bp.Value["breakpointId"]?.ToString(), pause_location["hitBreakpoints"]?[0]?.Value<string>());
+
+ var top_frame = pause_location["callFrames"][0];
+ Assert.Equal("IntAdd", top_frame["functionName"].Value<string>());
+ Assert.Contains("debugger-test.cs", top_frame["url"].Value<string>());
+
+ 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_non_wasm_page(); }, 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 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: (pause_location) =>
+ {
+ Assert.Equal("other", pause_location["reason"]?.Value<string>());
+ Assert.Equal(bp.Value["breakpointId"]?.ToString(), pause_location["hitBreakpoints"]?[0]?.Value<string>());
+
+ var top_frame = pause_location["callFrames"][0];
+ Assert.Equal("IntAdd", top_frame["functionName"].Value<string>());
+ Assert.Contains("debugger-test.cs", top_frame["url"].Value<string>());
+
+ 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"]);
+ return 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 b1bfcd859d0..ddf5dc54e48 100644
--- a/src/mono/wasm/debugger/tests/debugger-test/debugger-driver.html
+++ b/src/mono/wasm/debugger/tests/debugger-test/debugger-driver.html
@@ -1,8 +1,8 @@
<!doctype html>
<html lang="en-us">
- <head>
- </head>
- <body>
+ <head>
+ </head>
+ <body>
<script type='text/javascript'>
var App = {
init: function () {
@@ -82,10 +82,15 @@
function invoke_add_with_parms (a, b) {
return App.int_add (a, b);
}
- </script>
- <script type="text/javascript" src="runtime-debugger.js"></script>
- <script type="text/javascript" src="other.js"></script>
- <script async type="text/javascript" src="dotnet.js"></script>
- Stuff goes here
- </body>
- </html>
+
+ function load_non_wasm_page () {
+ console.log("load_non_wasm_page")
+ window.location.replace("http://localhost:9400/non-wasm-page.html");
+ }
+ </script>
+ <script type="text/javascript" src="runtime-debugger.js"></script>
+ <script type="text/javascript" src="other.js"></script>
+ <script async type="text/javascript" src="dotnet.js"></script>
+ Stuff goes here
+</body>
+</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 bf098dd83f5..145c80e8c20 100644
--- a/src/mono/wasm/debugger/tests/debugger-test/debugger-test.csproj
+++ b/src/mono/wasm/debugger/tests/debugger-test/debugger-test.csproj
@@ -10,6 +10,7 @@
<ItemGroup>
<WasmExtraFilesToDeploy Include="debugger-driver.html" />
+ <WasmExtraFilesToDeploy Include="non-wasm-page.html" />
<WasmExtraFilesToDeploy Include="other.js" />
<WasmExtraFilesToDeploy Include="runtime-debugger.js" />
<WasmExtraFilesToDeploy Include="weather.json" />
diff --git a/src/mono/wasm/debugger/tests/debugger-test/non-wasm-page.html b/src/mono/wasm/debugger/tests/debugger-test/non-wasm-page.html
new file mode 100644
index 00000000000..2894375a79c
--- /dev/null
+++ b/src/mono/wasm/debugger/tests/debugger-test/non-wasm-page.html
@@ -0,0 +1,12 @@
+<!doctype html>
+<html lang="en-us">
+ <head>
+ </head>
+ <body>
+ <script type='text/javascript'>
+ function reload_wasm_page () {
+ window.location.replace("http://localhost:9400/debugger-driver.html");
+ }
+ </script>
+ </body>
+</html>