Skip to content

[release/7.0-rc1] [wasm][debugger] Hide members from classes that don't have debug information #74029

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

Merged
merged 5 commits into from
Aug 17, 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
13 changes: 11 additions & 2 deletions src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,9 @@ internal sealed class TypeInfo
internal int Token { get; }
internal string Namespace { get; }
internal bool IsCompilerGenerated { get; }
private bool NonUserCode { get; }
public string FullName { get; }
internal bool IsNonUserCode => assembly.pdbMetadataReader == null || NonUserCode;
public List<MethodInfo> Methods { get; } = new();
public Dictionary<string, DebuggerBrowsableState?> DebuggerBrowsableFields = new();
public Dictionary<string, DebuggerBrowsableState?> DebuggerBrowsableProperties = new();
Expand Down Expand Up @@ -769,8 +771,15 @@ internal TypeInfo(AssemblyInfo assembly, TypeDefinitionHandle typeHandle, TypeDe
continue;
var container = metadataReader.GetMemberReference((MemberReferenceHandle)ctorHandle).Parent;
var attributeName = assembly.EnCGetString(metadataReader.GetTypeReference((TypeReferenceHandle)container).Name);
if (attributeName == nameof(CompilerGeneratedAttribute))
IsCompilerGenerated = true;
switch (attributeName)
{
case nameof(CompilerGeneratedAttribute):
IsCompilerGenerated = true;
break;
case nameof(DebuggerNonUserCodeAttribute):
NonUserCode = true;
break;
}
}

void AppendToBrowsable(Dictionary<string, DebuggerBrowsableState?> dict, CustomAttributeHandleCollection customAttrs, string fieldName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ private static async Task<JObject> ReadFieldValue(
FieldAttributes.Public => "result",
_ => "internal"
};

if (field.IsBackingField)
{
fieldValue["__isBackingField"] = true;
Expand Down Expand Up @@ -567,13 +568,20 @@ public static async Task<GetMembersResult> GetObjectMemberValues(
for (int i = 0; i < typeIdsCnt; i++)
{
int typeId = typeIdsIncludingParents[i];
var typeInfo = await sdbHelper.GetTypeInfo(typeId, token);

if (typeInfo.Info.IsNonUserCode && getCommandType.HasFlag(GetObjectCommandOptions.JustMyCode))
continue;

int parentTypeId = i + 1 < typeIdsCnt ? typeIdsIncludingParents[i + 1] : -1;
string typeName = await sdbHelper.GetTypeName(typeId, token);
// 0th id is for the object itself, and then its ancestors
bool isOwn = i == 0;

IReadOnlyList<FieldTypeClass> thisTypeFields = await sdbHelper.GetTypeFields(typeId, token);
if (!includeStatic)
thisTypeFields = thisTypeFields.Where(f => !f.Attributes.HasFlag(FieldAttributes.Static)).ToList();

if (thisTypeFields.Count > 0)
{
var allFields = await ExpandFieldValues(
Expand Down
2 changes: 2 additions & 0 deletions src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,8 @@ internal async Task<ValueOrError<GetMembersResult>> RuntimeGetObjectMembers(Sess
if (args["forDebuggerDisplayAttribute"]?.Value<bool>() == true)
getObjectOptions |= GetObjectCommandOptions.ForDebuggerDisplayAttribute;
}
if (JustMyCode)
getObjectOptions |= GetObjectCommandOptions.JustMyCode;
try
{
switch (objectId.Scheme)
Expand Down
3 changes: 2 additions & 1 deletion src/mono/wasm/debugger/BrowserDebugProxy/MonoSDBHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ internal enum GetObjectCommandOptions
OwnProperties = 4,
ForDebuggerProxyAttribute = 8,
ForDebuggerDisplayAttribute = 16,
WithProperties = 32
WithProperties = 32,
JustMyCode = 64
}

internal enum CommandSet {
Expand Down
47 changes: 47 additions & 0 deletions src/mono/wasm/debugger/DebuggerTestSuite/MiscTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1039,5 +1039,52 @@ await EvaluateAndCheck(
}
);
}

[Theory]
[InlineData("ClassInheritsFromClassWithoutDebugSymbols", 1287, true)]
[InlineData("ClassInheritsFromClassWithoutDebugSymbols", 1287, false)]
[InlineData("ClassInheritsFromNonUserCodeClass", 1335, true)]
[InlineData("ClassInheritsFromNonUserCodeClass", 1335, false)]
[InlineData("ClassInheritsFromNonUserCodeClassThatInheritsFromNormalClass", 1352, true)]
[InlineData("ClassInheritsFromNonUserCodeClassThatInheritsFromNormalClass", 1352, false)]
public async Task InspectThisThatInheritsFromClassNonUserCode(string class_name, int line, bool jmc)
{
await SetJustMyCode(jmc);
var expression = "{{ invoke_static_method('[debugger-test] " + class_name + ":Run'); }}";

await EvaluateAndCheck(
"window.setTimeout(function() {" + expression + "; }, 1);",
"dotnet://debugger-test.dll/debugger-test.cs", line, 8,
$"{class_name}.CallMethod",
locals_fn: async (locals) =>
{
var this_props = await GetObjectOnLocals(locals, "this");
if (jmc)
{
await CheckProps(this_props, new
{
myField = TNumber(0),
myField2 = TNumber(0),
}, "this_props", num_fields: 2);
}
else
{
await CheckProps(this_props, new
{
propA = TNumber(10),
propB = TNumber(20),
propC = TNumber(30),
d = TNumber(40),
e = TNumber(50),
f = TNumber(60),
G = TGetter("G"),
H = TGetter("H"),
myField = TNumber(0),
myField2 = TNumber(0),
}, "this_props", num_fields: 10);
}
}
);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;

namespace DebuggerTests
{
public class NormalClass
{
public int myField2;
}

[System.Diagnostics.DebuggerNonUserCode]
public class ClassNonUserCodeToInheritThatInheritsFromNormalClass : NormalClass
{
private int propA {get;}
public int propB {get;}
protected int propC {get;}
private int d;
public int e;
protected int f;
public int G
{
get {return f + 1;}
}
public int H => f;

public ClassNonUserCodeToInheritThatInheritsFromNormalClass()
{
propA = 10;
propB = 20;
propC = 30;
d = 40;
e = 50;
f = 60;
Console.WriteLine(propA);
Console.WriteLine(propB);
Console.WriteLine(propC);
Console.WriteLine(d);
Console.WriteLine(e);
Console.WriteLine(f);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<DebugType>none</DebugType>
<DebugSymbols>false</DebugSymbols>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;

namespace DebuggerTests
{
public class ClassWithoutDebugSymbolsToInherit
{
private int propA {get;}
public int propB {get;}
protected int propC {get;}
private int d;
public int e;
protected int f;
public int G
{
get {return f + 1;}
}
public int H => f;

public ClassWithoutDebugSymbolsToInherit()
{
propA = 10;
propB = 20;
propC = 30;
d = 40;
e = 50;
f = 60;
Console.WriteLine(propA);
Console.WriteLine(propB);
Console.WriteLine(propC);
Console.WriteLine(d);
Console.WriteLine(e);
Console.WriteLine(f);
}
}
}
80 changes: 80 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 @@ -1275,3 +1275,83 @@ public static void MethodWithHiddenLinesAtTheEnd3()
#line default
}

public class ClassInheritsFromClassWithoutDebugSymbols : DebuggerTests.ClassWithoutDebugSymbolsToInherit
{
public static void Run()
{
var myVar = new ClassInheritsFromClassWithoutDebugSymbols();
myVar.CallMethod();
}

public void CallMethod()
{
System.Diagnostics.Debugger.Break();
}
public int myField2;
public int myField;
}

[System.Diagnostics.DebuggerNonUserCode]
public class ClassNonUserCodeToInherit
{
private int propA {get;}
public int propB {get;}
protected int propC {get;}
private int d;
public int e;
protected int f;
public int G
{
get {return f + 1;}
}
public int H => f;

public ClassNonUserCodeToInherit()
{
propA = 10;
propB = 20;
propC = 30;
d = 40;
e = 50;
f = 60;
Console.WriteLine(propA);
Console.WriteLine(propB);
Console.WriteLine(propC);
Console.WriteLine(d);
Console.WriteLine(e);
Console.WriteLine(f);
}
}

public class ClassInheritsFromNonUserCodeClass : ClassNonUserCodeToInherit
{
public static void Run()
{
var myVar = new ClassInheritsFromNonUserCodeClass();
myVar.CallMethod();
}

public void CallMethod()
{
System.Diagnostics.Debugger.Break();
}

public int myField2;
public int myField;
}

public class ClassInheritsFromNonUserCodeClassThatInheritsFromNormalClass : DebuggerTests.ClassNonUserCodeToInheritThatInheritsFromNormalClass
{
public static void Run()
{
var myVar = new ClassInheritsFromNonUserCodeClassThatInheritsFromNormalClass();
myVar.CallMethod();
}

public void CallMethod()
{
System.Diagnostics.Debugger.Break();
}

public int myField;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
<ProjectReference Include="..\ApplyUpdateReferencedAssembly\ApplyUpdateReferencedAssembly.csproj" />
<ProjectReference Include="..\debugger-test-special-char-in-path-#@\debugger-test-special-char-in-path.csproj" ReferenceOutputAssembly="false" />
<ProjectReference Include="..\debugger-test-with-source-link\debugger-test-with-source-link.csproj" ReferenceOutputAssembly="false" Private="true" />
<ProjectReference Include="..\debugger-test-without-debug-symbols-to-load\debugger-test-without-debug-symbols-to-load.csproj" Private="true" />
<ProjectReference Include="..\debugger-test-with-non-user-code-class\debugger-test-with-non-user-code-class.csproj" Private="true" />
<!-- loaded by *tests*, and not the test app -->
<ProjectReference Include="..\lazy-debugger-test-embedded\lazy-debugger-test-embedded.csproj" ReferenceOutputAssembly="false" Private="true" />

Expand All @@ -44,14 +46,15 @@
<WasmMainJSPath>debugger-main.js</WasmMainJSPath>
<!-- -1 enabled debugging and disables debug logging. -->
<WasmDebugLevel Condition="'$(WasmDebugLevel)'==''">-1</WasmDebugLevel>

<WasmResolveAssembliesBeforeBuild>true</WasmResolveAssembliesBeforeBuild>
</PropertyGroup>

<ItemGroup>
<WasmAssembliesToBundle Include="$(OutDir)\$(TargetFileName)" />
<WasmAssembliesToBundle Include="$(OutDir)\debugger-test-special-char-in-path.dll" />
<WasmAssembliesToBundle Include="$(OutDir)\debugger-test-with-source-link.dll" />
<WasmAssembliesToBundle Include="$(OutDir)\debugger-test-without-debug-symbols-to-load.dll" />
<WasmAssembliesToBundle Include="$(OutDir)\debugger-test-with-non-user-code-class.dll" />
<WasmAssembliesToBundle Include="$(MicrosoftNetCoreAppRuntimePackRidDir)\lib\$(NetCoreappCurrent)\System.Runtime.InteropServices.JavaScript.dll" />

<!-- Assemblies only dynamically loaded -->
Expand All @@ -63,6 +66,7 @@

<WasmAssemblySearchPaths Include="$(MicrosoftNetCoreAppRuntimePackRidDir)native"/>
<WasmAssemblySearchPaths Include="$(MicrosoftNetCoreAppRuntimePackRidDir)lib\$(NetCoreAppCurrent)"/>
<WasmAssemblySearchPaths Include="$(OutDir)"/>
</ItemGroup>
</Target>
<Target Name="PreserveEnCAssembliesFromLinking"
Expand Down