From 5cc4aae9acb6049a372a8e328b4e692338f5bac0 Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz Date: Mon, 8 Nov 2021 15:14:34 +0100 Subject: [PATCH 01/13] Add test for ignoring stepping into hidden function. --- .../DebuggerTestSuite/BreakpointTests.cs | 2 +- .../DebuggerTestSuite/SteppingTests.cs | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs b/src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs index 398df51a299dd2..5d540e752e2eb1 100644 --- a/src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs +++ b/src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs @@ -651,7 +651,7 @@ public async Task DebuggerAttributeNoStopInDebuggerHidden() var bp_visible = await SetBreakpointInMethod("debugger-test.dll", "DebuggerAttribute", "VisibleMethod", 1); Assert.Empty(bp_hidden.Value["locations"]); await EvaluateAndCheck( - "window.setTimeout(function() { invoke_static_method('[debugger-test] DebuggerAttribute:VisibleMethod'); }, 1);", + "window.setTimeout(function() { invoke_static_method('[debugger-test] DebuggerAttribute:Run'); }, 1);", "dotnet://debugger-test.dll/debugger-test.cs", bp_visible.Value["locations"][0]["lineNumber"].Value(), bp_visible.Value["locations"][0]["columnNumber"].Value(), diff --git a/src/mono/wasm/debugger/DebuggerTestSuite/SteppingTests.cs b/src/mono/wasm/debugger/DebuggerTestSuite/SteppingTests.cs index de1bd7a829b2a4..b0d3a29f896d95 100644 --- a/src/mono/wasm/debugger/DebuggerTestSuite/SteppingTests.cs +++ b/src/mono/wasm/debugger/DebuggerTestSuite/SteppingTests.cs @@ -948,5 +948,25 @@ await EvaluateAndCheck( pause_location = await StepAndCheck(StepKind.Over, "dotnet://debugger-test.dll/debugger-test.cs", 806, 8, "Increment"); Assert.Equal(pause_location["callFrames"][0]["callFrameId"], "dotnet:scope:1"); } + + [Fact] + public async Task DebuggerAttributeIgnoreStepIntoDebuggerHidden() + { + var pause_location = await SetBreakpointInMethod("debugger-test.dll", "DebuggerAttribute", "Run", 1); + await EvaluateAndCheck( + "window.setTimeout(function() { invoke_static_method('[debugger-test] DebuggerAttribute:Run'); }, 1);", + "dotnet://debugger-test.dll/debugger-test.cs", + pause_location.Value["locations"][0]["lineNumber"].Value(), + pause_location.Value["locations"][0]["columnNumber"].Value(), + "Run" + ); + var step_into = await SendCommandAndCheck(null, $"Debugger.stepInto", null, -1, -1, null); + + Assert.Equal( + step_into["callFrames"][0]["location"]["lineNumber"].Value(), + pause_location.Value["locations"][0]["lineNumber"].Value() + ); + + } } } From 83036e7cb29096bef327b26444907ec7696eb35c Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz Date: Fri, 19 Nov 2021 15:38:13 +0100 Subject: [PATCH 02/13] Corrected test to match Console App behaviour. --- src/mono/wasm/debugger/DebuggerTestSuite/SteppingTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/wasm/debugger/DebuggerTestSuite/SteppingTests.cs b/src/mono/wasm/debugger/DebuggerTestSuite/SteppingTests.cs index c02fe1ef8ed46c..40cdfbe9206eea 100644 --- a/src/mono/wasm/debugger/DebuggerTestSuite/SteppingTests.cs +++ b/src/mono/wasm/debugger/DebuggerTestSuite/SteppingTests.cs @@ -963,7 +963,7 @@ await EvaluateAndCheck( var step_into = await SendCommandAndCheck(null, $"Debugger.stepInto", null, -1, -1, null); Assert.Equal( - step_into["callFrames"][0]["location"]["lineNumber"].Value(), + step_into["callFrames"][0]["location"]["lineNumber"].Value() + 1, pause_location.Value["locations"][0]["lineNumber"].Value() ); From dbdf6eaffb68661b62374c5bc3422510bfee1e8e Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz Date: Mon, 22 Nov 2021 11:40:46 +0100 Subject: [PATCH 03/13] Corrected test logic. --- src/mono/wasm/debugger/DebuggerTestSuite/SteppingTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mono/wasm/debugger/DebuggerTestSuite/SteppingTests.cs b/src/mono/wasm/debugger/DebuggerTestSuite/SteppingTests.cs index 40cdfbe9206eea..9c19cdd33bcff8 100644 --- a/src/mono/wasm/debugger/DebuggerTestSuite/SteppingTests.cs +++ b/src/mono/wasm/debugger/DebuggerTestSuite/SteppingTests.cs @@ -963,8 +963,8 @@ await EvaluateAndCheck( var step_into = await SendCommandAndCheck(null, $"Debugger.stepInto", null, -1, -1, null); Assert.Equal( - step_into["callFrames"][0]["location"]["lineNumber"].Value() + 1, - pause_location.Value["locations"][0]["lineNumber"].Value() + step_into["callFrames"][0]["location"]["lineNumber"].Value(), + pause_location.Value["locations"][0]["lineNumber"].Value() + 1 ); } From faf1e3c1a0a1af84ed2822f9e5fccf787bd14886 Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz Date: Mon, 22 Nov 2021 11:42:12 +0100 Subject: [PATCH 04/13] Applied Thays's fix so that step into would work as step over in a hidden method. --- .../BrowserDebugProxy/DevToolsHelper.cs | 2 +- .../debugger/BrowserDebugProxy/MonoProxy.cs | 33 ++++++++++++++++++- .../BrowserDebugProxy/MonoSDBHelper.cs | 2 +- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/mono/wasm/debugger/BrowserDebugProxy/DevToolsHelper.cs b/src/mono/wasm/debugger/BrowserDebugProxy/DevToolsHelper.cs index 3e7cfd87f010d3..b5baaab2f7e6aa 100644 --- a/src/mono/wasm/debugger/BrowserDebugProxy/DevToolsHelper.cs +++ b/src/mono/wasm/debugger/BrowserDebugProxy/DevToolsHelper.cs @@ -287,7 +287,7 @@ public ExecutionContext(MonoSDBHelper sdbAgent, int id, object auxData) public TaskCompletionSource ready; public bool IsRuntimeReady => ready != null && ready.Task.IsCompleted; - + public bool IsSkippingHiddenMethod { get; set; } public int ThreadId { get; set; } public int Id { get; set; } public object AuxData { get; set; } diff --git a/src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs b/src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs index 8b1265d866d4d6..65f9f244f2fa0a 100644 --- a/src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs +++ b/src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs @@ -751,6 +751,21 @@ private async Task SendCallStack(SessionId sessionId, ExecutionContext con DebugStore store = await LoadStore(sessionId, token); var method = await context.SdbAgent.GetMethodInfo(methodId, token); + if (context.IsSkippingHiddenMethod == true) + { + context.IsSkippingHiddenMethod = false; + await context.SdbAgent.Step(context.ThreadId, StepKind.Over, token); + await SendCommand(sessionId, "Debugger.resume", new JObject(), token); + return true; + } + if (j == 0 && method?.Info.IsHiddenFromDebugger == true) + { + context.IsSkippingHiddenMethod = true; + await context.SdbAgent.Step(context.ThreadId, StepKind.Out, token); + await SendCommand(sessionId, "Debugger.resume", new JObject(), token); + return true; + } + SourceLocation location = method?.Info.GetLocationByIl(il_pos); // When hitting a breakpoint on the "IncrementCount" method in the standard @@ -979,6 +994,7 @@ private async Task OnResume(MessageId msg_id, CancellationToken token) private async Task Step(MessageId msgId, StepKind kind, CancellationToken token) { + var stepKind = kind; ExecutionContext context = GetContext(msgId); if (context.CallStack == null) return false; @@ -986,12 +1002,27 @@ private async Task Step(MessageId msgId, StepKind kind, CancellationToken if (context.CallStack.Count <= 1 && kind == StepKind.Out) return false; - var step = await context.SdbAgent.Step(context.ThreadId, kind, token); + var a = context.store; + var b = context.CallStack.FirstOrDefault(); + var loc = b.Location; + var sId = loc.IlLocation.Method.SourceId; + var c = loc.IlLocation.Method; //RUN, how to get location of HiddenMethod? + if (c.IsHiddenFromDebugger) + stepKind = StepKind.Over; + + var step = await context.SdbAgent.Step(context.ThreadId, stepKind, token); if (step == false) { context.ClearState(); await SendCommand(msgId, "Debugger.stepOut", new JObject(), token); return false; } + var frameTop = context.CallStack.FirstOrDefault(); + var loc2 = frameTop.Location; + if (loc.Equals(loc2)) + { + var sthWrong = true; + step = sthWrong; + } SendResponse(msgId, Result.Ok(new JObject()), token); diff --git a/src/mono/wasm/debugger/BrowserDebugProxy/MonoSDBHelper.cs b/src/mono/wasm/debugger/BrowserDebugProxy/MonoSDBHelper.cs index 4ad3f6a45cb71d..bce8bff42f6307 100644 --- a/src/mono/wasm/debugger/BrowserDebugProxy/MonoSDBHelper.cs +++ b/src/mono/wasm/debugger/BrowserDebugProxy/MonoSDBHelper.cs @@ -1147,7 +1147,7 @@ public async Task Step(int thread_id, StepKind kind, CancellationToken tok commandParamsWriter.Write(thread_id); commandParamsWriter.Write((int)StepSize.Line); commandParamsWriter.Write((int)kind); - commandParamsWriter.Write((int)(StepFilter.StaticCtor | StepFilter.DebuggerHidden)); //filter + commandParamsWriter.Write((int)(StepFilter.StaticCtor)); //filter using var retDebuggerCmdReader = await SendDebuggerAgentCommand(CmdEventRequest.Set, commandParamsWriter, token); if (retDebuggerCmdReader.HasError) return false; From 4b08a7df59ff1c2a8bef09a634ca475e027a1751 Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz Date: Mon, 22 Nov 2021 11:45:36 +0100 Subject: [PATCH 05/13] Revert debugging changes. --- .../debugger/BrowserDebugProxy/MonoProxy.cs | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs b/src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs index 65f9f244f2fa0a..75a603746c8baf 100644 --- a/src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs +++ b/src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs @@ -994,7 +994,6 @@ private async Task OnResume(MessageId msg_id, CancellationToken token) private async Task Step(MessageId msgId, StepKind kind, CancellationToken token) { - var stepKind = kind; ExecutionContext context = GetContext(msgId); if (context.CallStack == null) return false; @@ -1002,27 +1001,12 @@ private async Task Step(MessageId msgId, StepKind kind, CancellationToken if (context.CallStack.Count <= 1 && kind == StepKind.Out) return false; - var a = context.store; - var b = context.CallStack.FirstOrDefault(); - var loc = b.Location; - var sId = loc.IlLocation.Method.SourceId; - var c = loc.IlLocation.Method; //RUN, how to get location of HiddenMethod? - if (c.IsHiddenFromDebugger) - stepKind = StepKind.Over; - - var step = await context.SdbAgent.Step(context.ThreadId, stepKind, token); + var step = await context.SdbAgent.Step(context.ThreadId, kind, token); if (step == false) { context.ClearState(); await SendCommand(msgId, "Debugger.stepOut", new JObject(), token); return false; } - var frameTop = context.CallStack.FirstOrDefault(); - var loc2 = frameTop.Location; - if (loc.Equals(loc2)) - { - var sthWrong = true; - step = sthWrong; - } SendResponse(msgId, Result.Ok(new JObject()), token); From 064b4e257e2380c1f64ecf95fb9834cfd4c74294 Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz Date: Mon, 22 Nov 2021 12:29:16 +0100 Subject: [PATCH 06/13] Test for Debugger.Break(). --- .../DebuggerTestSuite/BreakpointTests.cs | 23 +++++++++++++++++++ .../tests/debugger-test/debugger-test.cs | 19 +++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs b/src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs index b5d2ea913fab1b..4f83b8aae3af2f 100644 --- a/src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs +++ b/src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs @@ -658,5 +658,28 @@ await EvaluateAndCheck( "VisibleMethod" ); } + + [Fact] + public async Task DebuggerAttributeStopOnDebuggerHiddenCallWithDebuggerBreakCall() + { + var bp_init = await SetBreakpointInMethod("debugger-test.dll", "DebuggerAttribute", "RunDebuggerBreak", 1); + await EvaluateAndCheck( + "window.setTimeout(function() { invoke_static_method('[debugger-test] DebuggerAttribute:RunDebuggerBreak'); }, 1);", + "dotnet://debugger-test.dll/debugger-test.cs", + bp_init.Value["locations"][0]["lineNumber"].Value(), + bp_init.Value["locations"][0]["columnNumber"].Value(), + "RunDebuggerBreak" + ); + await SendCommandAndCheck(null, "Debugger.resume", + null, + bp_init.Value["locations"][0]["lineNumber"].Value() + 1, + bp_init.Value["locations"][0]["lineNumber"].Value() + 1, + "RunDebuggerBreak"); + await SendCommandAndCheck(null, "Debugger.resume", + null, + 835, + 8, + "VisibleMethodDebuggerBreak"); + } } } diff --git a/src/mono/wasm/debugger/tests/debugger-test/debugger-test.cs b/src/mono/wasm/debugger/tests/debugger-test/debugger-test.cs index 4a029949d156d0..4a88dce2231ba5 100644 --- a/src/mono/wasm/debugger/tests/debugger-test/debugger-test.cs +++ b/src/mono/wasm/debugger/tests/debugger-test/debugger-test.cs @@ -818,14 +818,33 @@ public static void HiddenMethod() currentCount++; } + [System.Diagnostics.DebuggerHidden] + public static void HiddenMethodDebuggerBreak() + { + System.Diagnostics.Debugger.Break(); + currentCount++; + } + public static void VisibleMethod() { currentCount++; } + public static void VisibleMethodDebuggerBreak() + { + System.Diagnostics.Debugger.Break(); + currentCount++; + } + public static void Run() { HiddenMethod(); VisibleMethod(); } + + public static void RunDebuggerBreak() + { + HiddenMethodDebuggerBreak(); + VisibleMethodDebuggerBreak(); + } } From c68505aac0c879f0f3b9ad1c6bf03d4bea636f5c Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz Date: Mon, 22 Nov 2021 12:39:00 +0100 Subject: [PATCH 07/13] Col fix + checing the location after command execution. --- src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs b/src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs index 4f83b8aae3af2f..7de6a4e11cf18a 100644 --- a/src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs +++ b/src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs @@ -671,12 +671,12 @@ await EvaluateAndCheck( "RunDebuggerBreak" ); await SendCommandAndCheck(null, "Debugger.resume", - null, - bp_init.Value["locations"][0]["lineNumber"].Value() + 1, + "dotnet://debugger-test.dll/debugger-test.cs", bp_init.Value["locations"][0]["lineNumber"].Value() + 1, + bp_init.Value["locations"][0]["columnNumber"].Value(), "RunDebuggerBreak"); await SendCommandAndCheck(null, "Debugger.resume", - null, + "dotnet://debugger-test.dll/debugger-test.cs", 835, 8, "VisibleMethodDebuggerBreak"); From a64cdee8c3d28f0ddbf69b172bdf406ed80776a9 Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz Date: Mon, 22 Nov 2021 12:40:49 +0100 Subject: [PATCH 08/13] Correct value of VisibleMethod entry line. --- 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 7de6a4e11cf18a..baa12ae1cebab2 100644 --- a/src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs +++ b/src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs @@ -677,7 +677,7 @@ await SendCommandAndCheck(null, "Debugger.resume", "RunDebuggerBreak"); await SendCommandAndCheck(null, "Debugger.resume", "dotnet://debugger-test.dll/debugger-test.cs", - 835, + 834, 8, "VisibleMethodDebuggerBreak"); } From 809c443da09f821552589e0a5e2ea28b1e1b9faa Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz Date: Mon, 22 Nov 2021 13:42:29 +0100 Subject: [PATCH 09/13] Move the breakpoint to the line 846. --- src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs b/src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs index baa12ae1cebab2..37ed5c035d9b98 100644 --- a/src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs +++ b/src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs @@ -662,7 +662,7 @@ await EvaluateAndCheck( [Fact] public async Task DebuggerAttributeStopOnDebuggerHiddenCallWithDebuggerBreakCall() { - var bp_init = await SetBreakpointInMethod("debugger-test.dll", "DebuggerAttribute", "RunDebuggerBreak", 1); + var bp_init = await SetBreakpointInMethod("debugger-test.dll", "DebuggerAttribute", "RunDebuggerBreak", 0); await EvaluateAndCheck( "window.setTimeout(function() { invoke_static_method('[debugger-test] DebuggerAttribute:RunDebuggerBreak'); }, 1);", "dotnet://debugger-test.dll/debugger-test.cs", @@ -670,11 +670,13 @@ await EvaluateAndCheck( bp_init.Value["locations"][0]["columnNumber"].Value(), "RunDebuggerBreak" ); - await SendCommandAndCheck(null, "Debugger.resume", + Console.WriteLine(bp_init.Value["locations"][0]["lineNumber"].Value()); + var pause_location = await SendCommandAndCheck(null, "Debugger.resume", "dotnet://debugger-test.dll/debugger-test.cs", bp_init.Value["locations"][0]["lineNumber"].Value() + 1, bp_init.Value["locations"][0]["columnNumber"].Value(), "RunDebuggerBreak"); + Console.WriteLine(pause_location["callFrames"][0]["location"]["lineNumber"]); await SendCommandAndCheck(null, "Debugger.resume", "dotnet://debugger-test.dll/debugger-test.cs", 834, From 02cbfd3c67fd0280f039b9a62eb11feca7672536 Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz Date: Tue, 23 Nov 2021 12:42:00 +0100 Subject: [PATCH 10/13] Create tests that match behaviour of Console App. --- .../DebuggerTestSuite/BreakpointTests.cs | 7 +- .../DebuggerTestSuite/SteppingTests.cs | 67 +++++++++++++++++++ .../tests/debugger-test/debugger-test.cs | 1 + 3 files changed, 72 insertions(+), 3 deletions(-) diff --git a/src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs b/src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs index 37ed5c035d9b98..04c8c648f925c6 100644 --- a/src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs +++ b/src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs @@ -663,20 +663,21 @@ await EvaluateAndCheck( public async Task DebuggerAttributeStopOnDebuggerHiddenCallWithDebuggerBreakCall() { var bp_init = await SetBreakpointInMethod("debugger-test.dll", "DebuggerAttribute", "RunDebuggerBreak", 0); - await EvaluateAndCheck( + var init_location = await EvaluateAndCheck( "window.setTimeout(function() { invoke_static_method('[debugger-test] DebuggerAttribute:RunDebuggerBreak'); }, 1);", "dotnet://debugger-test.dll/debugger-test.cs", bp_init.Value["locations"][0]["lineNumber"].Value(), bp_init.Value["locations"][0]["columnNumber"].Value(), "RunDebuggerBreak" ); - Console.WriteLine(bp_init.Value["locations"][0]["lineNumber"].Value()); var pause_location = await SendCommandAndCheck(null, "Debugger.resume", "dotnet://debugger-test.dll/debugger-test.cs", bp_init.Value["locations"][0]["lineNumber"].Value() + 1, bp_init.Value["locations"][0]["columnNumber"].Value(), "RunDebuggerBreak"); - Console.WriteLine(pause_location["callFrames"][0]["location"]["lineNumber"]); + Assert.Equal(init_location["callFrames"][0]["functionName"], pause_location["callFrames"][0]["functionName"]); + var id = pause_location["callFrames"][0]["callFrameId"].Value(); + await EvaluateOnCallFrame(id, "local_var", false); await SendCommandAndCheck(null, "Debugger.resume", "dotnet://debugger-test.dll/debugger-test.cs", 834, diff --git a/src/mono/wasm/debugger/DebuggerTestSuite/SteppingTests.cs b/src/mono/wasm/debugger/DebuggerTestSuite/SteppingTests.cs index 9c19cdd33bcff8..aeedff48d17f34 100644 --- a/src/mono/wasm/debugger/DebuggerTestSuite/SteppingTests.cs +++ b/src/mono/wasm/debugger/DebuggerTestSuite/SteppingTests.cs @@ -968,5 +968,72 @@ await EvaluateAndCheck( ); } + + [Fact] + public async Task DebuggerAttributeIgnoreStepIntoDebuggerHiddenWithDebuggerBreakCall() + { + var pause_location = await SetBreakpointInMethod("debugger-test.dll", "DebuggerAttribute", "RunDebuggerBreak", 1); + await EvaluateAndCheck( + "window.setTimeout(function() { invoke_static_method('[debugger-test] DebuggerAttribute:RunDebuggerBreak'); }, 1);", + "dotnet://debugger-test.dll/debugger-test.cs", + pause_location.Value["locations"][0]["lineNumber"].Value(), + pause_location.Value["locations"][0]["columnNumber"].Value(), + "RunDebuggerBreak" + ); + var step_into1 = await SendCommandAndCheck(null, $"Debugger.stepInto", null, -1, -1, null); + + Assert.Equal( + pause_location.Value["locations"][0]["lineNumber"].Value(), + step_into1["callFrames"][0]["location"]["lineNumber"].Value() + ); + + var step_into2 = await SendCommandAndCheck(null, $"Debugger.stepInto", null, -1, -1, null); + + Assert.Equal( + pause_location.Value["locations"][0]["lineNumber"].Value(), + step_into2["callFrames"][0]["location"]["lineNumber"].Value() + ); + + var step_into3 = await SendCommandAndCheck(null, $"Debugger.stepInto", null, -1, -1, null); + + Assert.Equal( + pause_location.Value["locations"][0]["lineNumber"].Value() + 1, + step_into3["callFrames"][0]["location"]["lineNumber"].Value() + ); + + } + + [Fact] + public async Task DebuggerAttributeIgnoreStepOverDebuggerHiddenWithDebuggerBreakCall() + { + var pause_location = await SetBreakpointInMethod("debugger-test.dll", "DebuggerAttribute", "RunDebuggerBreak", 1); + await EvaluateAndCheck( + "window.setTimeout(function() { invoke_static_method('[debugger-test] DebuggerAttribute:RunDebuggerBreak'); 1});", + "dotnet://debugger-test.dll/debugger-test.cs", + pause_location.Value["locations"][0]["lineNumber"].Value(), + pause_location.Value["locations"][0]["columnNumber"].Value(), + "RunDebuggerBreak" + ); + var step_over1 = await SendCommandAndCheck(null, $"Debugger.stepOver", null, -1, -1, null); + Assert.Equal( + pause_location.Value["locations"][0]["lineNumber"].Value(), + step_over1["callFrames"][0]["location"]["lineNumber"].Value() + ); + + var step_over2 = await SendCommandAndCheck(null, $"Debugger.stepOver", null, -1, -1, null); + + Assert.Equal( + pause_location.Value["locations"][0]["lineNumber"].Value(), + step_over2["callFrames"][0]["location"]["lineNumber"].Value() + ); + + var step_over3 = await SendCommandAndCheck(null, $"Debugger.stepOver", null, -1, -1, null); + + Assert.Equal( + pause_location.Value["locations"][0]["lineNumber"].Value() + 1, + step_over3["callFrames"][0]["location"]["lineNumber"].Value() + ); + + } } } diff --git a/src/mono/wasm/debugger/tests/debugger-test/debugger-test.cs b/src/mono/wasm/debugger/tests/debugger-test/debugger-test.cs index 4a88dce2231ba5..813102bbbc047d 100644 --- a/src/mono/wasm/debugger/tests/debugger-test/debugger-test.cs +++ b/src/mono/wasm/debugger/tests/debugger-test/debugger-test.cs @@ -821,6 +821,7 @@ public static void HiddenMethod() [System.Diagnostics.DebuggerHidden] public static void HiddenMethodDebuggerBreak() { + var local_var = 12; System.Diagnostics.Debugger.Break(); currentCount++; } From 3c6a5c23cebea1e3e46a8ca76c9f5587331984d3 Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz Date: Tue, 23 Nov 2021 15:44:40 +0100 Subject: [PATCH 11/13] Draft of Debugger.Break behaviour correction. --- src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs | 10 ++++++---- .../wasm/debugger/DebuggerTestSuite/BreakpointTests.cs | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs b/src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs index 75a603746c8baf..5950c5402f270a 100644 --- a/src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs +++ b/src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs @@ -732,7 +732,7 @@ private async Task SendBreakpointsOfMethodUpdated(SessionId sessionId, Exe return true; } - private async Task SendCallStack(SessionId sessionId, ExecutionContext context, string reason, int thread_id, Breakpoint bp, JObject data, IEnumerable orig_callframes, CancellationToken token) + private async Task SendCallStack(SessionId sessionId, ExecutionContext context, string reason, int thread_id, Breakpoint bp, JObject data, IEnumerable orig_callframes, EventKind event_kind, CancellationToken token) { var callFrames = new List(); var frames = new List(); @@ -758,9 +758,11 @@ private async Task SendCallStack(SessionId sessionId, ExecutionContext con await SendCommand(sessionId, "Debugger.resume", new JObject(), token); return true; } + if (j == 0 && method?.Info.IsHiddenFromDebugger == true) { - context.IsSkippingHiddenMethod = true; + if (event_kind == EventKind.Step) + context.IsSkippingHiddenMethod = true; await context.SdbAgent.Step(context.ThreadId, StepKind.Out, token); await SendCommand(sessionId, "Debugger.resume", new JObject(), token); return true; @@ -893,7 +895,7 @@ private async Task OnReceiveDebuggerAgentEvent(SessionId sessionId, JObjec objectId = $"dotnet:object:{object_id}" }); - var ret = await SendCallStack(sessionId, context, reason, thread_id, null, data, args?["callFrames"]?.Values(), token); + var ret = await SendCallStack(sessionId, context, reason, thread_id, null, data, args?["callFrames"]?.Values(), event_kind, token); return ret; } case EventKind.UserBreak: @@ -905,7 +907,7 @@ private async Task OnReceiveDebuggerAgentEvent(SessionId sessionId, JObjec int methodId = 0; if (event_kind != EventKind.UserBreak) methodId = retDebuggerCmdReader.ReadInt32(); - var ret = await SendCallStack(sessionId, context, reason, thread_id, bp, null, args?["callFrames"]?.Values(), token); + var ret = await SendCallStack(sessionId, context, reason, thread_id, bp, null, args?["callFrames"]?.Values(), event_kind, token); return ret; } } diff --git a/src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs b/src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs index 04c8c648f925c6..09f0f6b2e86670 100644 --- a/src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs +++ b/src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs @@ -673,14 +673,14 @@ public async Task DebuggerAttributeStopOnDebuggerHiddenCallWithDebuggerBreakCall var pause_location = await SendCommandAndCheck(null, "Debugger.resume", "dotnet://debugger-test.dll/debugger-test.cs", bp_init.Value["locations"][0]["lineNumber"].Value() + 1, - bp_init.Value["locations"][0]["columnNumber"].Value(), + 8, "RunDebuggerBreak"); Assert.Equal(init_location["callFrames"][0]["functionName"], pause_location["callFrames"][0]["functionName"]); var id = pause_location["callFrames"][0]["callFrameId"].Value(); await EvaluateOnCallFrame(id, "local_var", false); await SendCommandAndCheck(null, "Debugger.resume", "dotnet://debugger-test.dll/debugger-test.cs", - 834, + 835, 8, "VisibleMethodDebuggerBreak"); } From 3dc2a56b8e09fea60786d5e8318877fdd4a8ddac Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz Date: Tue, 23 Nov 2021 16:09:30 +0100 Subject: [PATCH 12/13] Draft: 2 pauses on hidden method with Debugger.Break inside. --- src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs b/src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs index 5950c5402f270a..c258cf1eb9bd61 100644 --- a/src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs +++ b/src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs @@ -754,9 +754,12 @@ private async Task SendCallStack(SessionId sessionId, ExecutionContext con if (context.IsSkippingHiddenMethod == true) { context.IsSkippingHiddenMethod = false; - await context.SdbAgent.Step(context.ThreadId, StepKind.Over, token); - await SendCommand(sessionId, "Debugger.resume", new JObject(), token); - return true; + if (event_kind != EventKind.UserBreak) + { + await context.SdbAgent.Step(context.ThreadId, StepKind.Over, token); + await SendCommand(sessionId, "Debugger.resume", new JObject(), token); + return true; + } } if (j == 0 && method?.Info.IsHiddenFromDebugger == true) From 3b1b047098b5bd25e3309e214c1b98d6e0e9d407 Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz Date: Tue, 23 Nov 2021 16:14:51 +0100 Subject: [PATCH 13/13] Changed required behaviour to 2 pauses on the hidden method call. --- .../DebuggerTestSuite/SteppingTests.cs | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/src/mono/wasm/debugger/DebuggerTestSuite/SteppingTests.cs b/src/mono/wasm/debugger/DebuggerTestSuite/SteppingTests.cs index aeedff48d17f34..bec62b77f97545 100644 --- a/src/mono/wasm/debugger/DebuggerTestSuite/SteppingTests.cs +++ b/src/mono/wasm/debugger/DebuggerTestSuite/SteppingTests.cs @@ -989,16 +989,9 @@ await EvaluateAndCheck( var step_into2 = await SendCommandAndCheck(null, $"Debugger.stepInto", null, -1, -1, null); - Assert.Equal( - pause_location.Value["locations"][0]["lineNumber"].Value(), - step_into2["callFrames"][0]["location"]["lineNumber"].Value() - ); - - var step_into3 = await SendCommandAndCheck(null, $"Debugger.stepInto", null, -1, -1, null); - Assert.Equal( pause_location.Value["locations"][0]["lineNumber"].Value() + 1, - step_into3["callFrames"][0]["location"]["lineNumber"].Value() + step_into2["callFrames"][0]["location"]["lineNumber"].Value() ); } @@ -1022,18 +1015,10 @@ await EvaluateAndCheck( var step_over2 = await SendCommandAndCheck(null, $"Debugger.stepOver", null, -1, -1, null); - Assert.Equal( - pause_location.Value["locations"][0]["lineNumber"].Value(), - step_over2["callFrames"][0]["location"]["lineNumber"].Value() - ); - - var step_over3 = await SendCommandAndCheck(null, $"Debugger.stepOver", null, -1, -1, null); - Assert.Equal( pause_location.Value["locations"][0]["lineNumber"].Value() + 1, - step_over3["callFrames"][0]["location"]["lineNumber"].Value() + step_over2["callFrames"][0]["location"]["lineNumber"].Value() ); - } } }