Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix loading a non wasm page and then returning to a wasm page.
  • Loading branch information
thaystg authored and github-actions committed Oct 22, 2021
commit 266bcbc6bf1cb153806f0bc6d264e7e78e3ce740
9 changes: 6 additions & 3 deletions src/mono/wasm/debugger/BrowserDebugProxy/MonoSDBHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,9 @@ public MonoSDBHelper(MonoProxy proxy, ILogger logger)
public void SetStore(DebugStore store)
{
this.store = store;
this.methods = new();
this.assemblies = new();
this.types = new();
}

public async Task<AssemblyInfo> GetAssemblyInfo(SessionId sessionId, int assemblyId, CancellationToken token)
Expand Down Expand Up @@ -816,10 +819,10 @@ public async Task<bool> EnableReceiveRequests(SessionId sessionId, EventKind eve
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);
return retDebuggerCmdReader;
Expand Down
75 changes: 70 additions & 5 deletions src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Newtonsoft.Json.Linq;
using System.IO;
using Xunit;
using System.Threading;

namespace DebuggerTests
{
Expand Down Expand Up @@ -131,11 +132,6 @@ public async Task CreateGoodBreakpointAndHit()
{
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,
Expand Down Expand Up @@ -577,5 +573,74 @@ await SendCommandAndCheck(null, "Debugger.resume",
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);
Thread.Sleep(1000);

run_method = JObject.FromObject(new
{
expression = "window.setTimeout(function() { reload_wasm_page(); }, 1);"
});
await cli.SendCommand("Runtime.evaluate", run_method, token);
Thread.Sleep(1000);
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;
}
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@
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");
}
</script>
<script type="text/javascript" src="runtime-debugger.js"></script>
<script type="text/javascript" src="other.js"></script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down