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]Add hidden attribute support #61143

Merged
merged 7 commits into from
Nov 3, 2021
13 changes: 13 additions & 0 deletions src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,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 MethodInfo(AssemblyInfo assembly, MethodDefinitionHandle methodDefHandle, int token, SourceFile source, TypeInfo type, MetadataReader asmMetadataReader, MetadataReader pdbMetadataReader)
{
this.IsAsync = -1;
Expand Down Expand Up @@ -363,6 +364,18 @@ public MethodInfo(AssemblyInfo assembly, MethodDefinitionHandle methodDefHandle,

StartLocation = new SourceLocation(this, start);
EndLocation = new SourceLocation(this, end);

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")
this.IsHiddenFromDebugger = true;
ilonatommy marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
localScopes = pdbMetadataReader.GetLocalScopes(methodDefHandle);
}
Expand Down
5 changes: 5 additions & 0 deletions src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1301,6 +1301,11 @@ private async Task SetBreakpoint(SessionId sessionId, DebugStore store, Breakpoi
{
SourceLocation loc = sourceId.First();
req.Method = loc.CliLocation.Method;
if (req.Method.IsHiddenFromDebugger)
{
ilonatommy marked this conversation as resolved.
Show resolved Hide resolved
continue;
}

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

// If we didn't successfully enable the breakpoint
Expand Down
16 changes: 16 additions & 0 deletions src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -642,5 +642,21 @@ await EvaluateAndCheck(
}
);
}


[Fact]
public async Task DebuggerAttributeNoStopInDebuggerHidden()
{
var bp_hidden = await SetBreakpointInMethod("debugger-test.dll", "DebuggerAttribute", "HiddenMethod", 1);
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);",
"dotnet://debugger-test.dll/debugger-test.cs",
bp_visible.Value["locations"][0]["lineNumber"].Value<int>(),
bp_visible.Value["locations"][0]["columnNumber"].Value<int>(),
"VisibleMethod"
);
}
}
}
22 changes: 22 additions & 0 deletions src/mono/wasm/debugger/tests/debugger-test/debugger-test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -807,3 +807,25 @@ public int Increment(int count)
return count + 1;
}
}

public class DebuggerAttribute
{
static int currentCount = 0;

[System.Diagnostics.DebuggerHidden]
public static void HiddenMethod()
{
currentCount++;
}

public static void VisibleMethod()
{
currentCount++;
}

public static void Run()
{
HiddenMethod();
VisibleMethod();
}
}