Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
33 changes: 26 additions & 7 deletions src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1185,18 +1185,18 @@ internal async Task<DebugStore> 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<string[]>();
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)
Expand All @@ -1207,6 +1207,25 @@ internal async Task<DebugStore> LoadStore(SessionId sessionId, CancellationToken
if (!context.Source.Task.IsCompleted)
context.Source.SetResult(context.store);
return context.store;

async Task<string[]> 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<string[]>();
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<DebugStore> RuntimeReady(SessionId sessionId, CancellationToken token)
Expand Down
70 changes: 70 additions & 0 deletions src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<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_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<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 Task.CompletedTask;
}
);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
</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 @@ -11,6 +11,7 @@
<ItemGroup>
<WasmExtraFilesToDeploy Include="debugger-driver.html" />
<WasmExtraFilesToDeploy Include="non-wasm-page.html" />
<WasmExtraFilesToDeploy Include="wasm-page-without-assets.html" />
<WasmExtraFilesToDeploy Include="other.js" />
<WasmExtraFilesToDeploy Include="runtime-debugger.js" />
<WasmExtraFilesToDeploy Include="weather.json" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!doctype html>
<html lang="en-us">
<head>
</head>
<body>
<script type='text/javascript'>
var App = {
init: function () {
MONO.loaded_files = null;
},
};
function reload_wasm_page () {
window.location.replace("http://localhost:9400/debugger-driver.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>