[release/6.0] [wasm][debugger] Clear cache after don't stop in a conditional breakpoi...
authorgithub-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Mon, 13 Sep 2021 17:35:30 +0000 (13:35 -0400)
committerGitHub <noreply@github.com>
Mon, 13 Sep 2021 17:35:30 +0000 (13:35 -0400)
Backport of #58908 to release/6.0

Fixes https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1390250?src=WorkItemMention&src-action=artifact_link

src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs
src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs
src/mono/wasm/debugger/tests/debugger-test/debugger-test.cs

index 1f8c498..f6a7385 100644 (file)
@@ -828,6 +828,7 @@ namespace Microsoft.WebAssembly.Diagnostics
             });
             if (!await EvaluateCondition(sessionId, context, context.CallStack.First(), bp, token))
             {
+                context.ClearState();
                 await SendCommand(sessionId, "Debugger.resume", new JObject(), token);
                 return true;
             }
index db5fbf3..6e9d420 100644 (file)
@@ -448,5 +448,134 @@ namespace DebuggerTests
             pause_location = await SendCommandAndCheck(JObject.FromObject(new { }), "Debugger.resume", "dotnet://ApplyUpdateReferencedAssembly.dll/MethodBody1.cs", 38, 8, "StaticMethod4");
             locals = await GetProperties(pause_location["callFrames"][0]["callFrameId"].Value<string>());
         }
+
+        [Fact]
+        public async Task ConditionalBreakpointInALoop()
+        {
+            var bp_conditional = await SetBreakpointInMethod("debugger-test.dll", "LoopClass", "LoopToBreak", 4, condition:"i == 3");
+            var bp_check = await SetBreakpointInMethod("debugger-test.dll", "LoopClass", "LoopToBreak", 5);
+            await EvaluateAndCheck(
+                "window.setTimeout(function() { invoke_static_method('[debugger-test] LoopClass:LoopToBreak'); }, 1);",
+                "dotnet://debugger-test.dll/debugger-test.cs",
+                bp_conditional.Value["locations"][0]["lineNumber"].Value<int>(),
+                bp_conditional.Value["locations"][0]["columnNumber"].Value<int>(),
+                "LoopToBreak",
+                locals_fn: (locals) =>
+                {
+                    CheckNumber(locals, "i", 3);
+                }
+            );
+
+            await SendCommandAndCheck(null, "Debugger.resume",
+                null,
+                bp_check.Value["locations"][0]["lineNumber"].Value<int>(),
+                bp_check.Value["locations"][0]["columnNumber"].Value<int>(),
+                "LoopToBreak");
+        }
+
+        [Fact]
+        public async Task ConditionalBreakpointInALoopStopMoreThanOnce()
+        {
+            var bp_conditional = await SetBreakpointInMethod("debugger-test.dll", "LoopClass", "LoopToBreak", 4, condition:"i % 3 == 0");
+            var bp_check = await SetBreakpointInMethod("debugger-test.dll", "LoopClass", "LoopToBreak", 5);
+            await EvaluateAndCheck(
+                "window.setTimeout(function() { invoke_static_method('[debugger-test] LoopClass:LoopToBreak'); }, 1);",
+                "dotnet://debugger-test.dll/debugger-test.cs",
+                bp_conditional.Value["locations"][0]["lineNumber"].Value<int>(),
+                bp_conditional.Value["locations"][0]["columnNumber"].Value<int>(),
+                "LoopToBreak",
+                locals_fn: (locals) =>
+                {
+                    CheckNumber(locals, "i", 0);
+                }
+            );
+
+            await SendCommandAndCheck(null, "Debugger.resume",
+                null,
+                bp_conditional.Value["locations"][0]["lineNumber"].Value<int>(),
+                bp_conditional.Value["locations"][0]["columnNumber"].Value<int>(),
+                "LoopToBreak",
+                locals_fn: (locals) =>
+                {
+                    CheckNumber(locals, "i", 3);
+                });
+
+            await SendCommandAndCheck(null, "Debugger.resume",
+                null,
+                bp_conditional.Value["locations"][0]["lineNumber"].Value<int>(),
+                bp_conditional.Value["locations"][0]["columnNumber"].Value<int>(),
+                "LoopToBreak",
+                locals_fn: (locals) =>
+                {
+                    CheckNumber(locals, "i", 6);
+                });
+
+            await SendCommandAndCheck(null, "Debugger.resume",
+                null,
+                bp_conditional.Value["locations"][0]["lineNumber"].Value<int>(),
+                bp_conditional.Value["locations"][0]["columnNumber"].Value<int>(),
+                "LoopToBreak",
+                locals_fn: (locals) =>
+                {
+                    CheckNumber(locals, "i", 9);
+                });
+
+            await SendCommandAndCheck(null, "Debugger.resume",
+                null,
+                bp_check.Value["locations"][0]["lineNumber"].Value<int>(),
+                bp_check.Value["locations"][0]["columnNumber"].Value<int>(),
+                "LoopToBreak");
+        }
+
+        [Fact]
+        public async Task ConditionalBreakpointNoStopInALoop()
+        {
+            var bp_conditional = await SetBreakpointInMethod("debugger-test.dll", "LoopClass", "LoopToBreak", 4, condition:"i == \"10\"");
+            var bp_check = await SetBreakpointInMethod("debugger-test.dll", "LoopClass", "LoopToBreak", 5);
+            await EvaluateAndCheck(
+                "window.setTimeout(function() { invoke_static_method('[debugger-test] LoopClass:LoopToBreak'); }, 1);",
+                "dotnet://debugger-test.dll/debugger-test.cs",
+                bp_check.Value["locations"][0]["lineNumber"].Value<int>(),
+                bp_check.Value["locations"][0]["columnNumber"].Value<int>(),
+                "LoopToBreak"
+            );
+        }
+
+        [Fact]
+        public async Task ConditionalBreakpointNotBooleanInALoop()
+        {
+            var bp_conditional = await SetBreakpointInMethod("debugger-test.dll", "LoopClass", "LoopToBreak", 4, condition:"i + 4");
+            await EvaluateAndCheck(
+                "window.setTimeout(function() { invoke_static_method('[debugger-test] LoopClass:LoopToBreak'); }, 1);",
+                "dotnet://debugger-test.dll/debugger-test.cs",
+                bp_conditional.Value["locations"][0]["lineNumber"].Value<int>(),
+                bp_conditional.Value["locations"][0]["columnNumber"].Value<int>(),
+                "LoopToBreak",
+                locals_fn: (locals) =>
+                {
+                    CheckNumber(locals, "i", 0);
+                }
+            );
+
+            await SendCommandAndCheck(null, "Debugger.resume",
+                null,
+                bp_conditional.Value["locations"][0]["lineNumber"].Value<int>(),
+                bp_conditional.Value["locations"][0]["columnNumber"].Value<int>(),
+                "LoopToBreak",
+                locals_fn: (locals) =>
+                {
+                    CheckNumber(locals, "i", 1);
+                });
+
+            await SendCommandAndCheck(null, "Debugger.resume",
+                null,
+                bp_conditional.Value["locations"][0]["lineNumber"].Value<int>(),
+                bp_conditional.Value["locations"][0]["columnNumber"].Value<int>(),
+                "LoopToBreak",
+                locals_fn: (locals) =>
+                {
+                    CheckNumber(locals, "i", 2);
+                });
+        }
     }
 }
index a826d97..4ef8045 100644 (file)
@@ -770,3 +770,15 @@ public class MainPage
     }
 }
 
+public class LoopClass
+{
+    public static void LoopToBreak()
+    {
+        for (int i = 0; i < 10; i++)
+        {
+            Console.WriteLine($"should pause only on i == 3");
+        }
+        Console.WriteLine("breakpoint to check");
+    }
+}
+