Skip to content

Commit

Permalink
[wasm][debugger]Add hidden attribute support (#61143)
Browse files Browse the repository at this point in the history
* Draft of hidden attribute decorator use.

* Removed checking custom attributes in the runtime each time the breakpoint is set and moved it to the constructor which is more efficient.

* Added test for DebuggerHidden decorator.

* By adding a line: using System.Diagnostics; IntAdd method moved down one line what resulted in CreateGoodBreakpoint tests failures. All row numbers in these tests had to be incremented.

* Reverted edition of tests not connected with HiddenAttribute.

* Added visible method to the HiddenAttribute test.

* Applying thaystg review suggestion.
  • Loading branch information
ilonatommy authored Nov 3, 2021
1 parent 1486f66 commit 39f3470
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
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;
}
}
}
localScopes = pdbMetadataReader.GetLocalScopes(methodDefHandle);
}
Expand Down
3 changes: 3 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,9 @@ private async Task SetBreakpoint(SessionId sessionId, DebugStore store, Breakpoi
{
SourceLocation loc = sourceId.First();
req.Method = loc.CliLocation.Method;
if (req.Method.IsHiddenFromDebugger)
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();
}
}

0 comments on commit 39f3470

Please sign in to comment.