Skip to content

Commit 271e129

Browse files
authored
[wasm][debugger] Clear cache after don't stop in a conditional breakpoint (#58908)
* Clear cache after don't stop in a conditional breakpoint. Fixes https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1390250?src=WorkItemMention&src-action=artifact_link * Adding more tests as suggested by @radical.
1 parent ad0c361 commit 271e129

File tree

3 files changed

+142
-0
lines changed

3 files changed

+142
-0
lines changed

src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,7 @@ private async Task<bool> SendCallStack(SessionId sessionId, ExecutionContext con
821821
});
822822
if (!await EvaluateCondition(sessionId, context, context.CallStack.First(), bp, token))
823823
{
824+
context.ClearState();
824825
await SendCommand(sessionId, "Debugger.resume", new JObject(), token);
825826
return true;
826827
}

src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,5 +448,134 @@ await StepAndCheck(StepKind.Over, "dotnet://ApplyUpdateReferencedAssembly.dll/Me
448448
pause_location = await SendCommandAndCheck(JObject.FromObject(new { }), "Debugger.resume", "dotnet://ApplyUpdateReferencedAssembly.dll/MethodBody1.cs", 38, 8, "StaticMethod4");
449449
locals = await GetProperties(pause_location["callFrames"][0]["callFrameId"].Value<string>());
450450
}
451+
452+
[Fact]
453+
public async Task ConditionalBreakpointInALoop()
454+
{
455+
var bp_conditional = await SetBreakpointInMethod("debugger-test.dll", "LoopClass", "LoopToBreak", 4, condition:"i == 3");
456+
var bp_check = await SetBreakpointInMethod("debugger-test.dll", "LoopClass", "LoopToBreak", 5);
457+
await EvaluateAndCheck(
458+
"window.setTimeout(function() { invoke_static_method('[debugger-test] LoopClass:LoopToBreak'); }, 1);",
459+
"dotnet://debugger-test.dll/debugger-test.cs",
460+
bp_conditional.Value["locations"][0]["lineNumber"].Value<int>(),
461+
bp_conditional.Value["locations"][0]["columnNumber"].Value<int>(),
462+
"LoopToBreak",
463+
locals_fn: (locals) =>
464+
{
465+
CheckNumber(locals, "i", 3);
466+
}
467+
);
468+
469+
await SendCommandAndCheck(null, "Debugger.resume",
470+
null,
471+
bp_check.Value["locations"][0]["lineNumber"].Value<int>(),
472+
bp_check.Value["locations"][0]["columnNumber"].Value<int>(),
473+
"LoopToBreak");
474+
}
475+
476+
[Fact]
477+
public async Task ConditionalBreakpointInALoopStopMoreThanOnce()
478+
{
479+
var bp_conditional = await SetBreakpointInMethod("debugger-test.dll", "LoopClass", "LoopToBreak", 4, condition:"i % 3 == 0");
480+
var bp_check = await SetBreakpointInMethod("debugger-test.dll", "LoopClass", "LoopToBreak", 5);
481+
await EvaluateAndCheck(
482+
"window.setTimeout(function() { invoke_static_method('[debugger-test] LoopClass:LoopToBreak'); }, 1);",
483+
"dotnet://debugger-test.dll/debugger-test.cs",
484+
bp_conditional.Value["locations"][0]["lineNumber"].Value<int>(),
485+
bp_conditional.Value["locations"][0]["columnNumber"].Value<int>(),
486+
"LoopToBreak",
487+
locals_fn: (locals) =>
488+
{
489+
CheckNumber(locals, "i", 0);
490+
}
491+
);
492+
493+
await SendCommandAndCheck(null, "Debugger.resume",
494+
null,
495+
bp_conditional.Value["locations"][0]["lineNumber"].Value<int>(),
496+
bp_conditional.Value["locations"][0]["columnNumber"].Value<int>(),
497+
"LoopToBreak",
498+
locals_fn: (locals) =>
499+
{
500+
CheckNumber(locals, "i", 3);
501+
});
502+
503+
await SendCommandAndCheck(null, "Debugger.resume",
504+
null,
505+
bp_conditional.Value["locations"][0]["lineNumber"].Value<int>(),
506+
bp_conditional.Value["locations"][0]["columnNumber"].Value<int>(),
507+
"LoopToBreak",
508+
locals_fn: (locals) =>
509+
{
510+
CheckNumber(locals, "i", 6);
511+
});
512+
513+
await SendCommandAndCheck(null, "Debugger.resume",
514+
null,
515+
bp_conditional.Value["locations"][0]["lineNumber"].Value<int>(),
516+
bp_conditional.Value["locations"][0]["columnNumber"].Value<int>(),
517+
"LoopToBreak",
518+
locals_fn: (locals) =>
519+
{
520+
CheckNumber(locals, "i", 9);
521+
});
522+
523+
await SendCommandAndCheck(null, "Debugger.resume",
524+
null,
525+
bp_check.Value["locations"][0]["lineNumber"].Value<int>(),
526+
bp_check.Value["locations"][0]["columnNumber"].Value<int>(),
527+
"LoopToBreak");
528+
}
529+
530+
[Fact]
531+
public async Task ConditionalBreakpointNoStopInALoop()
532+
{
533+
var bp_conditional = await SetBreakpointInMethod("debugger-test.dll", "LoopClass", "LoopToBreak", 4, condition:"i == \"10\"");
534+
var bp_check = await SetBreakpointInMethod("debugger-test.dll", "LoopClass", "LoopToBreak", 5);
535+
await EvaluateAndCheck(
536+
"window.setTimeout(function() { invoke_static_method('[debugger-test] LoopClass:LoopToBreak'); }, 1);",
537+
"dotnet://debugger-test.dll/debugger-test.cs",
538+
bp_check.Value["locations"][0]["lineNumber"].Value<int>(),
539+
bp_check.Value["locations"][0]["columnNumber"].Value<int>(),
540+
"LoopToBreak"
541+
);
542+
}
543+
544+
[Fact]
545+
public async Task ConditionalBreakpointNotBooleanInALoop()
546+
{
547+
var bp_conditional = await SetBreakpointInMethod("debugger-test.dll", "LoopClass", "LoopToBreak", 4, condition:"i + 4");
548+
await EvaluateAndCheck(
549+
"window.setTimeout(function() { invoke_static_method('[debugger-test] LoopClass:LoopToBreak'); }, 1);",
550+
"dotnet://debugger-test.dll/debugger-test.cs",
551+
bp_conditional.Value["locations"][0]["lineNumber"].Value<int>(),
552+
bp_conditional.Value["locations"][0]["columnNumber"].Value<int>(),
553+
"LoopToBreak",
554+
locals_fn: (locals) =>
555+
{
556+
CheckNumber(locals, "i", 0);
557+
}
558+
);
559+
560+
await SendCommandAndCheck(null, "Debugger.resume",
561+
null,
562+
bp_conditional.Value["locations"][0]["lineNumber"].Value<int>(),
563+
bp_conditional.Value["locations"][0]["columnNumber"].Value<int>(),
564+
"LoopToBreak",
565+
locals_fn: (locals) =>
566+
{
567+
CheckNumber(locals, "i", 1);
568+
});
569+
570+
await SendCommandAndCheck(null, "Debugger.resume",
571+
null,
572+
bp_conditional.Value["locations"][0]["lineNumber"].Value<int>(),
573+
bp_conditional.Value["locations"][0]["columnNumber"].Value<int>(),
574+
"LoopToBreak",
575+
locals_fn: (locals) =>
576+
{
577+
CheckNumber(locals, "i", 2);
578+
});
579+
}
451580
}
452581
}

src/mono/wasm/debugger/tests/debugger-test/debugger-test.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,3 +770,15 @@ public static void CallSetValue()
770770
}
771771
}
772772

773+
public class LoopClass
774+
{
775+
public static void LoopToBreak()
776+
{
777+
for (int i = 0; i < 10; i++)
778+
{
779+
Console.WriteLine($"should pause only on i == 3");
780+
}
781+
Console.WriteLine("breakpoint to check");
782+
}
783+
}
784+

0 commit comments

Comments
 (0)