Skip to content

Commit caaf788

Browse files
authored
[release/6.0] [wasm][debugger] Fixing error after receiving loaded_files = null (#63739)
* Backporting #63591 * Fix merge error. * Fixing html page.
1 parent c4c4bc9 commit caaf788

File tree

5 files changed

+122
-8
lines changed

5 files changed

+122
-8
lines changed

src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,18 +1185,18 @@ internal async Task<DebugStore> LoadStore(SessionId sessionId, CancellationToken
11851185

11861186
try
11871187
{
1188-
string[] loaded_files = context.LoadedFiles;
1188+
string[] loaded_files = await GetLoadedFiles(sessionId, context, token);
11891189

11901190
if (loaded_files == null)
11911191
{
1192-
Result loaded = await SendMonoCommand(sessionId, MonoCommands.GetLoadedFiles(), token);
1193-
loaded_files = loaded.Value?["result"]?["value"]?.ToObject<string[]>();
1192+
Console.WriteLine($"Failed to get the list of loaded files. Managed code debugging won't work due to this.");
11941193
}
1195-
1196-
await
1197-
foreach (SourceFile source in context.store.Load(sessionId, loaded_files, token).WithCancellation(token))
1194+
else
11981195
{
1199-
await OnSourceFileAdded(sessionId, source, context, token);
1196+
await foreach (SourceFile source in context.store.Load(sessionId, loaded_files, token).WithCancellation(token))
1197+
{
1198+
await OnSourceFileAdded(sessionId, source, context, token);
1199+
}
12001200
}
12011201
}
12021202
catch (Exception e)
@@ -1207,6 +1207,25 @@ internal async Task<DebugStore> LoadStore(SessionId sessionId, CancellationToken
12071207
if (!context.Source.Task.IsCompleted)
12081208
context.Source.SetResult(context.store);
12091209
return context.store;
1210+
1211+
async Task<string[]> GetLoadedFiles(SessionId sessionId, ExecutionContext context, CancellationToken token)
1212+
{
1213+
if (context.LoadedFiles != null)
1214+
return context.LoadedFiles;
1215+
1216+
Result loaded = await SendMonoCommand(sessionId, MonoCommands.GetLoadedFiles(), token);
1217+
if (!loaded.IsOk)
1218+
{
1219+
Console.WriteLine($"Error on mono_wasm_get_loaded_files {loaded}");
1220+
return null;
1221+
}
1222+
1223+
string[] files = loaded.Value?["result"]?["value"]?.ToObject<string[]>();
1224+
if (files == null)
1225+
Console.WriteLine($"Error extracting the list of loaded_files from the result of mono_wasm_get_loaded_files: {loaded}");
1226+
1227+
return files;
1228+
}
12101229
}
12111230

12121231
private async Task<DebugStore> RuntimeReady(SessionId sessionId, CancellationToken token)

src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,5 +642,75 @@ await EvaluateAndCheck(
642642
}
643643
);
644644
}
645+
646+
[Fact]
647+
public async Task CreateGoodBreakpointAndHitGoToWasmPageWithoutAssetsComeBackAndHitAgain()
648+
{
649+
var bp = await SetBreakpoint("dotnet://debugger-test.dll/debugger-test.cs", 10, 8);
650+
var pause_location = await EvaluateAndCheck(
651+
"window.setTimeout(function() { invoke_add(); }, 1);",
652+
"dotnet://debugger-test.dll/debugger-test.cs", 10, 8,
653+
"IntAdd");
654+
Assert.Equal("other", pause_location["reason"]?.Value<string>());
655+
Assert.Equal(bp.Value["breakpointId"]?.ToString(), pause_location["hitBreakpoints"]?[0]?.Value<string>());
656+
657+
var top_frame = pause_location["callFrames"][0];
658+
Assert.Equal("IntAdd", top_frame["functionName"].Value<string>());
659+
Assert.Contains("debugger-test.cs", top_frame["url"].Value<string>());
660+
661+
CheckLocation("dotnet://debugger-test.dll/debugger-test.cs", 8, 4, scripts, top_frame["functionLocation"]);
662+
663+
//now check the scope
664+
var scope = top_frame["scopeChain"][0];
665+
Assert.Equal("local", scope["type"]);
666+
Assert.Equal("IntAdd", scope["name"]);
667+
668+
Assert.Equal("object", scope["object"]["type"]);
669+
CheckLocation("dotnet://debugger-test.dll/debugger-test.cs", 8, 4, scripts, scope["startLocation"]);
670+
CheckLocation("dotnet://debugger-test.dll/debugger-test.cs", 14, 4, scripts, scope["endLocation"]);
671+
672+
await cli.SendCommand("Debugger.resume", null, token);
673+
674+
var run_method = JObject.FromObject(new
675+
{
676+
expression = "window.setTimeout(function() { load_wasm_page_without_assets(); }, 1);"
677+
});
678+
await cli.SendCommand("Runtime.evaluate", run_method, token);
679+
await Task.Delay(1000, token);
680+
run_method = JObject.FromObject(new
681+
{
682+
expression = "window.setTimeout(function() { reload_wasm_page(); }, 1);"
683+
});
684+
await cli.SendCommand("Runtime.evaluate", run_method, token);
685+
await Task.Delay(1000, token);
686+
await insp.WaitFor(Inspector.READY);
687+
await EvaluateAndCheck(
688+
"window.setTimeout(function() { invoke_add(); }, 1);",
689+
"dotnet://debugger-test.dll/debugger-test.cs", 10, 8,
690+
"IntAdd",
691+
wait_for_event_fn: async (pause_location) =>
692+
{
693+
Assert.Equal("other", pause_location["reason"]?.Value<string>());
694+
Assert.Equal(bp.Value["breakpointId"]?.ToString(), pause_location["hitBreakpoints"]?[0]?.Value<string>());
695+
696+
var top_frame = pause_location["callFrames"][0];
697+
Assert.Equal("IntAdd", top_frame["functionName"].Value<string>());
698+
Assert.Contains("debugger-test.cs", top_frame["url"].Value<string>());
699+
700+
CheckLocation("dotnet://debugger-test.dll/debugger-test.cs", 8, 4, scripts, top_frame["functionLocation"]);
701+
702+
//now check the scope
703+
var scope = top_frame["scopeChain"][0];
704+
Assert.Equal("local", scope["type"]);
705+
Assert.Equal("IntAdd", scope["name"]);
706+
707+
Assert.Equal("object", scope["object"]["type"]);
708+
CheckLocation("dotnet://debugger-test.dll/debugger-test.cs", 8, 4, scripts, scope["startLocation"]);
709+
CheckLocation("dotnet://debugger-test.dll/debugger-test.cs", 14, 4, scripts, scope["endLocation"]);
710+
await Task.CompletedTask;
711+
}
712+
);
713+
}
714+
645715
}
646716
}

src/mono/wasm/debugger/tests/debugger-test/debugger-driver.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,14 @@
8282
function invoke_add_with_parms (a, b) {
8383
return App.int_add (a, b);
8484
}
85-
8685
function load_non_wasm_page () {
8786
console.log("load_non_wasm_page")
8887
window.location.replace("http://localhost:9400/non-wasm-page.html");
8988
}
89+
function load_wasm_page_without_assets () {
90+
console.log("load_wasm_page_without_assets")
91+
window.location.replace("http://localhost:9400/wasm-page-without-assets.html");
92+
}
9093
</script>
9194
<script type="text/javascript" src="runtime-debugger.js"></script>
9295
<script type="text/javascript" src="other.js"></script>

src/mono/wasm/debugger/tests/debugger-test/debugger-test.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<ItemGroup>
1212
<WasmExtraFilesToDeploy Include="debugger-driver.html" />
1313
<WasmExtraFilesToDeploy Include="non-wasm-page.html" />
14+
<WasmExtraFilesToDeploy Include="wasm-page-without-assets.html" />
1415
<WasmExtraFilesToDeploy Include="other.js" />
1516
<WasmExtraFilesToDeploy Include="runtime-debugger.js" />
1617
<WasmExtraFilesToDeploy Include="weather.json" />
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<!doctype html>
2+
<html lang="en-us">
3+
<head>
4+
</head>
5+
<body>
6+
<script type='text/javascript'>
7+
var App = {
8+
init: function () {
9+
MONO.loaded_files = null;
10+
},
11+
};
12+
function reload_wasm_page () {
13+
window.location.replace("http://localhost:9400/debugger-driver.html");
14+
}
15+
</script>
16+
<script type="text/javascript" src="runtime-debugger.js"></script>
17+
<script type="text/javascript" src="other.js"></script>
18+
<script async type="text/javascript" src="dotnet.js"></script>
19+
Stuff goes here
20+
</body>
21+
</html>

0 commit comments

Comments
 (0)