Skip to content

Commit

Permalink
[wasm][debugger] Move the breakpoint line after applying changes (#64359
Browse files Browse the repository at this point in the history
)

When hot-reloading code with new lines added, VS automatically updates the breakpoints by sending Remove/SetBreakpoint commands.

Add a test case for the reload, with simulated VS part.
  • Loading branch information
thaystg authored Jan 28, 2022
1 parent 8766a1c commit 1092617
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 4 deletions.
26 changes: 26 additions & 0 deletions src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1124,5 +1124,31 @@ await EvaluateAndCheck(
}
);
}

[Fact]
public async Task DebugHotReloadMethod_CheckBreakpointLineUpdated_ByVS_Simulated()
{
string asm_file = Path.Combine(DebuggerTestAppPath, "ApplyUpdateReferencedAssembly.dll");
string pdb_file = Path.Combine(DebuggerTestAppPath, "ApplyUpdateReferencedAssembly.pdb");
string asm_file_hot_reload = Path.Combine(DebuggerTestAppPath, "../wasm/ApplyUpdateReferencedAssembly.dll");

var bp = await SetBreakpoint(".*/MethodBody1.cs$", 48, 12, use_regex: true);
var pause_location = await LoadAssemblyAndTestHotReloadUsingSDBWithoutChanges(
asm_file, pdb_file, "MethodBody5", "StaticMethod1");

//apply first update
pause_location = await LoadAssemblyAndTestHotReloadUsingSDB(
asm_file_hot_reload, "MethodBody5", "StaticMethod1", 1,
rebindBreakpoint : async () =>
{
await RemoveBreakpoint(bp.Value["breakpointId"].Value<string>());
await SetBreakpoint(".*/MethodBody1.cs$", 49, 12, use_regex: true);
});

JToken top_frame = pause_location["callFrames"]?[0];
AssertEqual("StaticMethod1", top_frame?["functionName"]?.Value<string>(), top_frame?.ToString());
CheckLocation("dotnet://ApplyUpdateReferencedAssembly.dll/MethodBody1.cs", 49, 12, scripts, top_frame["location"]);

}
}
}
6 changes: 5 additions & 1 deletion src/mono/wasm/debugger/DebuggerTestSuite/DebuggerTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1215,7 +1215,7 @@ internal async Task<JObject> LoadAssemblyAndTestHotReloadUsingSDBWithoutChanges(
return await insp.WaitFor(Inspector.PAUSE);
}

internal async Task<JObject> LoadAssemblyAndTestHotReloadUsingSDB(string asm_file_hot_reload, string class_name, string method_name, int id)
internal async Task<JObject> LoadAssemblyAndTestHotReloadUsingSDB(string asm_file_hot_reload, string class_name, string method_name, int id, Func<Task> rebindBreakpoint = null)
{
await cli.SendCommand("Debugger.resume", null, token);
var bytes = File.ReadAllBytes($"{asm_file_hot_reload}.{id}.dmeta");
Expand Down Expand Up @@ -1245,6 +1245,10 @@ internal async Task<JObject> LoadAssemblyAndTestHotReloadUsingSDB(string asm_fil
dpdb = dpdb1
});
await cli.SendCommand("DotnetDebugger.applyUpdates", applyUpdates, token);

if (rebindBreakpoint != null)
await rebindBreakpoint();

run_method = JObject.FromObject(new
{
expression = "window.setTimeout(function() { invoke_static_method('[debugger-test] TestHotReloadUsingSDB:RunMethod', '" + class_name + "', '" + method_name + "'); }, 1);"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using System.Diagnostics;
using System;

//keep the same line number for class in the original file and the updates ones
namespace ApplyUpdateReferencedAssembly
{
public class MethodBody1 {
Expand Down Expand Up @@ -38,4 +38,15 @@ public class MethodBody4 {
public static void StaticMethod4 () {
}
}






public class MethodBody5 {
public static void StaticMethod1 () {
Console.WriteLine("original");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using System.Diagnostics;
using System;

//keep the same line number for class in the original file and the updates ones
namespace ApplyUpdateReferencedAssembly
{
public class MethodBody1 {
Expand Down Expand Up @@ -43,4 +43,11 @@ public static void StaticMethod4 () {
Console.WriteLine(a + b);
}
}

public class MethodBody5 {
public static void StaticMethod1 () {
Console.WriteLine("beforeoriginal");
Console.WriteLine("original");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
using System.Diagnostics;
using System;

//keep the same line number for class in the original file and the updates ones
namespace ApplyUpdateReferencedAssembly
{
public class MethodBody1 {
Expand Down Expand Up @@ -38,4 +38,16 @@ public class MethodBody4 {
public static void StaticMethod4 () {
}
}






public class MethodBody5 {
public static void StaticMethod1 () {
Console.WriteLine("beforeoriginal");
Console.WriteLine("original");
}
}
}

0 comments on commit 1092617

Please sign in to comment.