diff --git a/src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs b/src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs index f5e6a5b9c2b93e..30c9417b6e484f 100644 --- a/src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs +++ b/src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs @@ -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()); + await SetBreakpoint(".*/MethodBody1.cs$", 49, 12, use_regex: true); + }); + + JToken top_frame = pause_location["callFrames"]?[0]; + AssertEqual("StaticMethod1", top_frame?["functionName"]?.Value(), top_frame?.ToString()); + CheckLocation("dotnet://ApplyUpdateReferencedAssembly.dll/MethodBody1.cs", 49, 12, scripts, top_frame["location"]); + + } } } diff --git a/src/mono/wasm/debugger/DebuggerTestSuite/DebuggerTestBase.cs b/src/mono/wasm/debugger/DebuggerTestSuite/DebuggerTestBase.cs index cf4eade5a81936..23ac172cf69b17 100644 --- a/src/mono/wasm/debugger/DebuggerTestSuite/DebuggerTestBase.cs +++ b/src/mono/wasm/debugger/DebuggerTestSuite/DebuggerTestBase.cs @@ -1215,7 +1215,7 @@ internal async Task LoadAssemblyAndTestHotReloadUsingSDBWithoutChanges( return await insp.WaitFor(Inspector.PAUSE); } - internal async Task LoadAssemblyAndTestHotReloadUsingSDB(string asm_file_hot_reload, string class_name, string method_name, int id) + internal async Task LoadAssemblyAndTestHotReloadUsingSDB(string asm_file_hot_reload, string class_name, string method_name, int id, Func rebindBreakpoint = null) { await cli.SendCommand("Debugger.resume", null, token); var bytes = File.ReadAllBytes($"{asm_file_hot_reload}.{id}.dmeta"); @@ -1245,6 +1245,10 @@ internal async Task 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);" diff --git a/src/mono/wasm/debugger/tests/ApplyUpdateReferencedAssembly/MethodBody1.cs b/src/mono/wasm/debugger/tests/ApplyUpdateReferencedAssembly/MethodBody1.cs index d092ec07cf7e5d..047e293c082363 100644 --- a/src/mono/wasm/debugger/tests/ApplyUpdateReferencedAssembly/MethodBody1.cs +++ b/src/mono/wasm/debugger/tests/ApplyUpdateReferencedAssembly/MethodBody1.cs @@ -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 { @@ -38,4 +38,15 @@ public class MethodBody4 { public static void StaticMethod4 () { } } + + + + + + + public class MethodBody5 { + public static void StaticMethod1 () { + Console.WriteLine("original"); + } + } } diff --git a/src/mono/wasm/debugger/tests/ApplyUpdateReferencedAssembly/MethodBody1_v1.cs b/src/mono/wasm/debugger/tests/ApplyUpdateReferencedAssembly/MethodBody1_v1.cs index 6ce229dff59668..ce9d974b8bf160 100644 --- a/src/mono/wasm/debugger/tests/ApplyUpdateReferencedAssembly/MethodBody1_v1.cs +++ b/src/mono/wasm/debugger/tests/ApplyUpdateReferencedAssembly/MethodBody1_v1.cs @@ -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 { @@ -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"); + } + } } diff --git a/src/mono/wasm/debugger/tests/ApplyUpdateReferencedAssembly/MethodBody1_v2.cs b/src/mono/wasm/debugger/tests/ApplyUpdateReferencedAssembly/MethodBody1_v2.cs index 1ced5fd3826e1f..8850f85956d303 100644 --- a/src/mono/wasm/debugger/tests/ApplyUpdateReferencedAssembly/MethodBody1_v2.cs +++ b/src/mono/wasm/debugger/tests/ApplyUpdateReferencedAssembly/MethodBody1_v2.cs @@ -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 { @@ -38,4 +38,16 @@ public class MethodBody4 { public static void StaticMethod4 () { } } + + + + + + + public class MethodBody5 { + public static void StaticMethod1 () { + Console.WriteLine("beforeoriginal"); + Console.WriteLine("original"); + } + } }