Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wasm][debugger] Added support for stepper boundary attribute #63991

Merged
merged 19 commits into from
Jan 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,6 @@ public MethodInfo(AssemblyInfo assembly, MethodDefinitionHandle methodDefHandle,
{
var container = asmMetadataReader.GetMemberReference((MemberReferenceHandle)ctorHandle).Parent;
var name = asmMetadataReader.GetString(asmMetadataReader.GetTypeReference((TypeReferenceHandle)container).Name);
var stopSearch = true;
switch (name)
{
case "DebuggerHiddenAttribute":
Expand All @@ -390,12 +389,10 @@ public MethodInfo(AssemblyInfo assembly, MethodDefinitionHandle methodDefHandle,
case "DebuggerNonUserCodeAttribute":
DebuggerAttrInfo.HasNonUserCode = true;
break;
default:
stopSearch = false;
case "DebuggerStepperBoundaryAttribute":
DebuggerAttrInfo.HasStepperBoundary = true;
break;
}
if (stopSearch)
break;

}
}
Expand Down Expand Up @@ -492,6 +489,7 @@ public class DebuggerAttributesInfo
public bool HasDebuggerHidden { get; internal set; }
public bool HasStepThrough { get; internal set; }
public bool HasNonUserCode { get; internal set; }
public bool HasStepperBoundary { get; internal set; }
}
}

Expand Down
28 changes: 16 additions & 12 deletions src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -856,28 +856,32 @@ private async Task<bool> SendCallStack(SessionId sessionId, ExecutionContext con
if (j == 0 &&
(method?.Info.DebuggerAttrInfo.HasStepThrough == true ||
method?.Info.DebuggerAttrInfo.HasDebuggerHidden == true ||
method?.Info.DebuggerAttrInfo.HasStepperBoundary == true ||
(method?.Info.DebuggerAttrInfo.HasNonUserCode == true && JustMyCode)))
{
if (method.Info.DebuggerAttrInfo.HasDebuggerHidden)
if (method.Info.DebuggerAttrInfo.HasDebuggerHidden ||
(method.Info.DebuggerAttrInfo.HasStepperBoundary && event_kind == EventKind.Step))
{
if (event_kind == EventKind.Step)
context.IsSkippingHiddenMethod = true;
if (await SkipMethod(isSkippable: true, shouldBeSkipped: true, StepKind.Out))
return true;
}

if (event_kind == EventKind.Step ||
(JustMyCode && (event_kind == EventKind.Breakpoint || event_kind == EventKind.UserBreak)))
if (!method.Info.DebuggerAttrInfo.HasStepperBoundary)
{
if (context.IsResumedAfterBp)
context.IsResumedAfterBp = false;
else if (event_kind != EventKind.UserBreak)
context.IsSteppingThroughMethod = true;
if (await SkipMethod(isSkippable: true, shouldBeSkipped: true, StepKind.Out))
return true;
if (event_kind == EventKind.Step ||
(JustMyCode && (event_kind == EventKind.Breakpoint || event_kind == EventKind.UserBreak)))
{
if (context.IsResumedAfterBp)
context.IsResumedAfterBp = false;
else if (event_kind != EventKind.UserBreak)
context.IsSteppingThroughMethod = true;
if (await SkipMethod(isSkippable: true, shouldBeSkipped: true, StepKind.Out))
return true;
}
if (event_kind == EventKind.Breakpoint)
context.IsResumedAfterBp = true;
}
if (event_kind == EventKind.Breakpoint)
context.IsResumedAfterBp = true;
}

SourceLocation location = method?.Info.GetLocationByIl(il_pos);
Expand Down
35 changes: 35 additions & 0 deletions src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,41 @@ public async Task StepThroughOrNonUserCodAttributeWithUserBp(bool justMyCodeEnab
await SendCommandAndCheck(null, debuggingFunction, "dotnet://debugger-test.dll/debugger-test.cs", line2, col2, function_name2);
}

[Theory]
[InlineData("Debugger.stepInto", 1, 2, false)]
[InlineData("Debugger.stepInto", 1, 2, true)]
[InlineData("Debugger.resume", 1, 2, true)]
[InlineData("Debugger.stepInto", 2, 3, false)]
[InlineData("Debugger.resume", 2, 3, false)]
public async Task StepperBoundary(string debuggingAction, int lineBpInit, int lineBpFinal, bool hasBpInDecoratedFun)
{
// behavior of StepperBoundary is the same for JMC enabled and disabled
// but the effect of NonUserCode escape is better visible for JMC: enabled
await SetJustMyCode(true);
var bp_init = await SetBreakpointInMethod("debugger-test.dll", "DebuggerAttribute", "RunNoBoundary", lineBpInit);
var init_location = await EvaluateAndCheck(
$"window.setTimeout(function() {{ invoke_static_method('[debugger-test] DebuggerAttribute:RunNoBoundary'); }}, {lineBpInit});",
"dotnet://debugger-test.dll/debugger-test.cs",
bp_init.Value["locations"][0]["lineNumber"].Value<int>(),
bp_init.Value["locations"][0]["columnNumber"].Value<int>(),
"RunNoBoundary"
);
var bp_final = await SetBreakpointInMethod("debugger-test.dll", "DebuggerAttribute", "RunNoBoundary", lineBpFinal);
if (hasBpInDecoratedFun)
{
var bp_decorated_fun = await SetBreakpointInMethod("debugger-test.dll", "DebuggerAttribute", "BoundaryBp", 2);
var line_decorated_fun = bp_decorated_fun.Value["locations"][0]["lineNumber"].Value<int>();
var col_decorated_fun = bp_decorated_fun.Value["locations"][0]["columnNumber"].Value<int>();
await SendCommandAndCheck(null, debuggingAction, "dotnet://debugger-test.dll/debugger-test.cs", line_decorated_fun, col_decorated_fun, "BoundaryBp");
}
if (lineBpInit == 2)
await SendCommandAndCheck(null, debuggingAction, "dotnet://debugger-test.dll/debugger-test.cs", 900, 8, "BoundaryUserBp");

var line = bp_final.Value["locations"][0]["lineNumber"].Value<int>();
var col = bp_final.Value["locations"][0]["columnNumber"].Value<int>();
await SendCommandAndCheck(null, debuggingAction, "dotnet://debugger-test.dll/debugger-test.cs", line, col, "RunNoBoundary");
}

[Fact]
public async Task CreateGoodBreakpointAndHitGoToWasmPageWithoutAssetsComeBackAndHitAgain()
{
Expand Down
2 changes: 1 addition & 1 deletion src/mono/wasm/debugger/DebuggerTestSuite/MiscTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -913,7 +913,7 @@ public async Task InspectLocalsUsingClassFromLibraryUsingDebugTypeFull()

await EvaluateAndCheck(
"window.setTimeout(function() {" + expression + "; }, 1);",
"dotnet://debugger-test.dll/debugger-test.cs", 900, 8,
"dotnet://debugger-test.dll/debugger-test.cs", 924, 8,
"CallToEvaluateLocal",
wait_for_event_fn: async (pause_location) =>
{
Expand Down
26 changes: 25 additions & 1 deletion src/mono/wasm/debugger/tests/debugger-test/debugger-test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,7 @@ public static void RunStepThrough()
}

[System.Diagnostics.DebuggerNonUserCode]
public static void NonUserCodeBp()
public static void NonUserCodeBp(Action boundaryTestFun=null)
{
var a = 0;
currentCount++;
Expand All @@ -888,6 +888,30 @@ public static void RunNonUserCode()
NonUserCodeBp();
NonUserCodeUserBp();
}

[System.Diagnostics.DebuggerStepperBoundary]
public static void BoundaryBp()
{
var a = 5;
}

[System.Diagnostics.DebuggerStepperBoundary]
public static void BoundaryUserBp()
{
System.Diagnostics.Debugger.Break();
}

[System.Diagnostics.DebuggerNonUserCode]
public static void NonUserCodeForBoundaryEscape(Action boundaryTestFun)
{
boundaryTestFun();
}

public static void RunNoBoundary()
{
NonUserCodeForBoundaryEscape(DebuggerAttribute.BoundaryBp);
NonUserCodeForBoundaryEscape(DebuggerAttribute.BoundaryUserBp);
}
}

public class DebugTypeFull
Expand Down