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 18 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
33 changes: 23 additions & 10 deletions src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,7 @@ internal class MethodInfo
internal LocalScopeHandleCollection localScopes;
public bool IsStatic() => (methodDef.Attributes & MethodAttributes.Static) != 0;
public int IsAsync { get; set; }
public bool IsHiddenFromDebugger { get; }
public bool HasStepThroughAttribute { get; }
public DebuggerAttributesInfo DebuggerAttrInfo { get; set; }
public TypeInfo TypeInfo { get; }

public MethodInfo(AssemblyInfo assembly, MethodDefinitionHandle methodDefHandle, int token, SourceFile source, TypeInfo type, MetadataReader asmMetadataReader, MetadataReader pdbMetadataReader)
Expand Down Expand Up @@ -371,22 +370,28 @@ public MethodInfo(AssemblyInfo assembly, MethodDefinitionHandle methodDefHandle,
StartLocation = new SourceLocation(this, start);
EndLocation = new SourceLocation(this, end);

DebuggerAttrInfo = new DebuggerAttributesInfo();
foreach (var cattr in methodDef.GetCustomAttributes())
{
var ctorHandle = asmMetadataReader.GetCustomAttribute(cattr).Constructor;
if (ctorHandle.Kind == HandleKind.MemberReference)
{
var container = asmMetadataReader.GetMemberReference((MemberReferenceHandle)ctorHandle).Parent;
var name = asmMetadataReader.GetString(asmMetadataReader.GetTypeReference((TypeReferenceHandle)container).Name);
if (name == "DebuggerHiddenAttribute")
switch (name)
{
IsHiddenFromDebugger = true;
break;
}
if (name == "DebuggerStepThroughAttribute")
{
HasStepThroughAttribute = true;
break;
case "DebuggerHiddenAttribute":
DebuggerAttrInfo.HasDebuggerHidden = true;
break;
case "DebuggerStepThroughAttribute":
DebuggerAttrInfo.HasStepThrough = true;
break;
case "DebuggerNonUserCodeAttribute":
DebuggerAttrInfo.HasNonUserCode = true;
break;
case "DebuggerStepperBoundaryAttribute":
DebuggerAttrInfo.HasStepperBoundary = true;
break;
}

}
Expand Down Expand Up @@ -478,6 +483,14 @@ public VarInfo[] GetLiveVarsAt(int offset)
}

public override string ToString() => "MethodInfo(" + Name + ")";

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; }
}
}

internal class TypeInfo
Expand Down
35 changes: 21 additions & 14 deletions src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -853,28 +853,35 @@ private async Task<bool> SendCallStack(SessionId sessionId, ExecutionContext con
if (shouldReturn)
return true;

if (j == 0 && (method?.Info.HasStepThroughAttribute == true || method?.Info.IsHiddenFromDebugger == true))
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.IsHiddenFromDebugger)
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 Expand Up @@ -1443,7 +1450,7 @@ private async Task SetBreakpoint(SessionId sessionId, DebugStore store, Breakpoi
{
SourceLocation loc = sourceId.First();
req.Method = loc.IlLocation.Method;
if (req.Method.IsHiddenFromDebugger)
if (req.Method.DebuggerAttrInfo.HasDebuggerHidden)
continue;

Breakpoint bp = await SetMonoBreakpoint(sessionId, req.Id, loc, req.Condition, token);
Expand Down
Loading