From b46bb9bc4a661947fb06cd036ef565dc8d8228d8 Mon Sep 17 00:00:00 2001 From: "DESKTOP-GEPIA6N\\Thays" Date: Wed, 26 Jan 2022 20:22:58 -0300 Subject: [PATCH 1/4] Add test case to prove that changing a line and moving the breakpoint to the next line as it's done by VS will work. --- .../DebuggerTestSuite/BreakpointTests.cs | 21 +++++++++++++++++++ .../DebuggerTestSuite/DebuggerTestBase.cs | 9 +++++++- .../MethodBody1.cs | 11 ++++++++++ .../MethodBody1_v1.cs | 7 +++++++ .../MethodBody1_v2.cs | 12 +++++++++++ 5 files changed, 59 insertions(+), 1 deletion(-) diff --git a/src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs b/src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs index f5e6a5b9c2b93e..84bd058c11d3fb 100644 --- a/src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs +++ b/src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs @@ -1124,5 +1124,26 @@ await EvaluateAndCheck( } ); } + + [Fact] + public async Task DebugHotReloadMethodAddBreakpointUsingSDBChangeBreakpointPosition() + { + 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, bp.Value["breakpointId"].Value(), 49, 12); + + 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..2ffea4e956e12e 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, string bpId = null, int newLine = 0, int newColumn = 0) { await cli.SendCommand("Debugger.resume", null, token); var bytes = File.ReadAllBytes($"{asm_file_hot_reload}.{id}.dmeta"); @@ -1245,6 +1245,13 @@ internal async Task LoadAssemblyAndTestHotReloadUsingSDB(string asm_fil dpdb = dpdb1 }); await cli.SendCommand("DotnetDebugger.applyUpdates", applyUpdates, token); + + if (bpId != null) + { + await RemoveBreakpoint(bpId); + await SetBreakpoint(".*/MethodBody1.cs$", 49, 12, use_regex: true); + } + 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..348bcc0317d037 100644 --- a/src/mono/wasm/debugger/tests/ApplyUpdateReferencedAssembly/MethodBody1.cs +++ b/src/mono/wasm/debugger/tests/ApplyUpdateReferencedAssembly/MethodBody1.cs @@ -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..b7d3c63e528b7d 100644 --- a/src/mono/wasm/debugger/tests/ApplyUpdateReferencedAssembly/MethodBody1_v1.cs +++ b/src/mono/wasm/debugger/tests/ApplyUpdateReferencedAssembly/MethodBody1_v1.cs @@ -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..a27f9c37e065d1 100644 --- a/src/mono/wasm/debugger/tests/ApplyUpdateReferencedAssembly/MethodBody1_v2.cs +++ b/src/mono/wasm/debugger/tests/ApplyUpdateReferencedAssembly/MethodBody1_v2.cs @@ -38,4 +38,16 @@ public class MethodBody4 { public static void StaticMethod4 () { } } + + + + + + + public class MethodBody5 { + public static void StaticMethod1 () { + Console.WriteLine("beforeoriginal"); + Console.WriteLine("original"); + } + } } From e0b27671946da230ba37e0751f56cc8046b164b8 Mon Sep 17 00:00:00 2001 From: "DESKTOP-GEPIA6N\\Thays" Date: Thu, 27 Jan 2022 13:00:11 -0300 Subject: [PATCH 2/4] Fixing hardcoded line number. --- src/mono/wasm/debugger/DebuggerTestSuite/DebuggerTestBase.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/wasm/debugger/DebuggerTestSuite/DebuggerTestBase.cs b/src/mono/wasm/debugger/DebuggerTestSuite/DebuggerTestBase.cs index 2ffea4e956e12e..27da2aa250bf78 100644 --- a/src/mono/wasm/debugger/DebuggerTestSuite/DebuggerTestBase.cs +++ b/src/mono/wasm/debugger/DebuggerTestSuite/DebuggerTestBase.cs @@ -1249,7 +1249,7 @@ internal async Task LoadAssemblyAndTestHotReloadUsingSDB(string asm_fil if (bpId != null) { await RemoveBreakpoint(bpId); - await SetBreakpoint(".*/MethodBody1.cs$", 49, 12, use_regex: true); + await SetBreakpoint(".*/MethodBody1.cs$", newLine, newColumn, use_regex: true); } run_method = JObject.FromObject(new From 4460869e66d3058824b0b96e86c22f56252dc264 Mon Sep 17 00:00:00 2001 From: "DESKTOP-GEPIA6N\\Thays" Date: Thu, 27 Jan 2022 13:54:27 -0300 Subject: [PATCH 3/4] Addressing @radical comments offline. --- src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs b/src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs index 84bd058c11d3fb..c390d7950514e6 100644 --- a/src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs +++ b/src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs @@ -1126,7 +1126,7 @@ await EvaluateAndCheck( } [Fact] - public async Task DebugHotReloadMethodAddBreakpointUsingSDBChangeBreakpointPosition() + public async Task DebugHotReloadMethod_CheckBreakpointLineUpdated_ByVS_Simulated() { string asm_file = Path.Combine(DebuggerTestAppPath, "ApplyUpdateReferencedAssembly.dll"); string pdb_file = Path.Combine(DebuggerTestAppPath, "ApplyUpdateReferencedAssembly.pdb"); From c8adda4fbf6ba69c9a3b436c915cbefb223e6b8e Mon Sep 17 00:00:00 2001 From: "DESKTOP-GEPIA6N\\Thays" Date: Thu, 27 Jan 2022 17:03:21 -0300 Subject: [PATCH 4/4] Changing what was discussed with @radical offline. --- .../wasm/debugger/DebuggerTestSuite/BreakpointTests.cs | 7 ++++++- .../wasm/debugger/DebuggerTestSuite/DebuggerTestBase.cs | 9 +++------ .../tests/ApplyUpdateReferencedAssembly/MethodBody1.cs | 2 +- .../ApplyUpdateReferencedAssembly/MethodBody1_v1.cs | 2 +- .../ApplyUpdateReferencedAssembly/MethodBody1_v2.cs | 2 +- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs b/src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs index c390d7950514e6..30c9417b6e484f 100644 --- a/src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs +++ b/src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs @@ -1138,7 +1138,12 @@ public async Task DebugHotReloadMethod_CheckBreakpointLineUpdated_ByVS_Simulated //apply first update pause_location = await LoadAssemblyAndTestHotReloadUsingSDB( - asm_file_hot_reload, "MethodBody5", "StaticMethod1", 1, bp.Value["breakpointId"].Value(), 49, 12); + 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()); diff --git a/src/mono/wasm/debugger/DebuggerTestSuite/DebuggerTestBase.cs b/src/mono/wasm/debugger/DebuggerTestSuite/DebuggerTestBase.cs index 27da2aa250bf78..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, string bpId = null, int newLine = 0, int newColumn = 0) + 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"); @@ -1246,11 +1246,8 @@ internal async Task LoadAssemblyAndTestHotReloadUsingSDB(string asm_fil }); await cli.SendCommand("DotnetDebugger.applyUpdates", applyUpdates, token); - if (bpId != null) - { - await RemoveBreakpoint(bpId); - await SetBreakpoint(".*/MethodBody1.cs$", newLine, newColumn, use_regex: true); - } + if (rebindBreakpoint != null) + await rebindBreakpoint(); run_method = JObject.FromObject(new { diff --git a/src/mono/wasm/debugger/tests/ApplyUpdateReferencedAssembly/MethodBody1.cs b/src/mono/wasm/debugger/tests/ApplyUpdateReferencedAssembly/MethodBody1.cs index 348bcc0317d037..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 { diff --git a/src/mono/wasm/debugger/tests/ApplyUpdateReferencedAssembly/MethodBody1_v1.cs b/src/mono/wasm/debugger/tests/ApplyUpdateReferencedAssembly/MethodBody1_v1.cs index b7d3c63e528b7d..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 { diff --git a/src/mono/wasm/debugger/tests/ApplyUpdateReferencedAssembly/MethodBody1_v2.cs b/src/mono/wasm/debugger/tests/ApplyUpdateReferencedAssembly/MethodBody1_v2.cs index a27f9c37e065d1..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 {