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] Fix evaluation of a static class attribute; using current namespace for evaluation #61252

Merged
merged 24 commits into from
Nov 17, 2021
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
fab24e5
Using current namespace as the default place to serach for the resolv…
ilonatommy Nov 5, 2021
66b56a7
Add tests for static class, static fields and pausing in async method.
ilonatommy Nov 5, 2021
782a107
Added tests for class evaluation.
ilonatommy Nov 8, 2021
4119de3
Fixing support to the current namespace and adding tests for it
thaystg Nov 8, 2021
e275144
Merge branch 'add-static-attribute-support' of https://github.com/ilo…
ilonatommy Nov 9, 2021
ee19014
Assuing that we search within the current assembly first. Removed tes…
ilonatommy Nov 9, 2021
89bdc49
Remove a test-duplicate that was not testing static class or static f…
ilonatommy Nov 9, 2021
5ce0f57
Fixing indentation.
ilonatommy Nov 9, 2021
62d18b6
Refixing indentation.
ilonatommy Nov 9, 2021
ce177fd
Refix indentations again.
ilonatommy Nov 9, 2021
cb32402
Applied the advice about adding new blank lines.
ilonatommy Nov 10, 2021
ed2577e
Changed the current assembly check.
ilonatommy Nov 10, 2021
01f46d5
Extracting the check from the loop. One time check is enough.
ilonatommy Nov 10, 2021
d14367d
Simplifying multiple test cases into one call.
ilonatommy Nov 10, 2021
8a82380
Using local function as per review suggestion.
ilonatommy Nov 11, 2021
7f24d47
Added test that was skipped by mistake.
ilonatommy Nov 11, 2021
367c431
Added looking for the namespace in all assemblies because there is a …
ilonatommy Nov 11, 2021
55479c8
Extracting value based on the current frame, not the top of stack loc…
ilonatommy Nov 11, 2021
5f5cdf6
Test for classes evaluated from different frames.
ilonatommy Nov 11, 2021
7151177
Fixing indentation and spaces.
ilonatommy Nov 15, 2021
5fc759e
Applied review comments for values evaluation.
ilonatommy Nov 15, 2021
3661c0e
Compressed two tests into one with MemberData.
ilonatommy Nov 15, 2021
66ed5c2
Added test case of type without namespace (failing).
ilonatommy Nov 15, 2021
136f69a
Addressed Ankit advices from the review.
ilonatommy Nov 16, 2021
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
18 changes: 10 additions & 8 deletions src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ internal class MethodInfo
public bool IsStatic() => (methodDef.Attributes & MethodAttributes.Static) != 0;
public int IsAsync { get; set; }
public bool IsHiddenFromDebugger { get; }
public TypeInfo TypeInfo { get; }
public MethodInfo(AssemblyInfo assembly, MethodDefinitionHandle methodDefHandle, int token, SourceFile source, TypeInfo type, MetadataReader asmMetadataReader, MetadataReader pdbMetadataReader)
ilonatommy marked this conversation as resolved.
Show resolved Hide resolved
{
this.IsAsync = -1;
Expand All @@ -343,6 +344,7 @@ public MethodInfo(AssemblyInfo assembly, MethodDefinitionHandle methodDefHandle,
this.Name = asmMetadataReader.GetString(methodDef.Name);
this.pdbMetadataReader = pdbMetadataReader;
this.IsEnCMethod = false;
this.TypeInfo = type;
if (!DebugInformation.SequencePointsBlob.IsNil)
{
var sps = DebugInformation.GetSequencePoints();
Expand Down Expand Up @@ -475,7 +477,7 @@ internal class TypeInfo
private TypeDefinition type;
private List<MethodInfo> methods;
internal int Token { get; }

internal string Namespace { get; }
public TypeInfo(AssemblyInfo assembly, TypeDefinitionHandle typeHandle, TypeDefinition type)
ilonatommy marked this conversation as resolved.
Show resolved Hide resolved
{
this.assembly = assembly;
Expand All @@ -484,21 +486,21 @@ public TypeInfo(AssemblyInfo assembly, TypeDefinitionHandle typeHandle, TypeDefi
this.type = type;
methods = new List<MethodInfo>();
Name = metadataReader.GetString(type.Name);
var namespaceName = "";
Namespace = "";
ilonatommy marked this conversation as resolved.
Show resolved Hide resolved
if (type.IsNested)
{
var declaringType = metadataReader.GetTypeDefinition(type.GetDeclaringType());
Name = metadataReader.GetString(declaringType.Name) + "/" + Name;
namespaceName = metadataReader.GetString(declaringType.Namespace);
Namespace = metadataReader.GetString(declaringType.Namespace);
ilonatommy marked this conversation as resolved.
Show resolved Hide resolved
}
else
{
namespaceName = metadataReader.GetString(type.Namespace);
Namespace = metadataReader.GetString(type.Namespace);
}

if (namespaceName.Length > 0)
namespaceName += ".";
FullName = namespaceName + Name;
if (Namespace.Length > 0)
FullName = Namespace + "." + Name;
else
FullName = Name;
}

public TypeInfo(AssemblyInfo assembly, string name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,23 @@ public async Task<JObject> TryToRunOnLoadedClasses(string varName, CancellationT
}
}
var store = await proxy.LoadStore(sessionId, token);
var info = ctx.CallStack.FirstOrDefault().Method.Info;
ilonatommy marked this conversation as resolved.
Show resolved Hide resolved
ilonatommy marked this conversation as resolved.
Show resolved Hide resolved
var currentAssembly = info.Assembly;
var namespaceName = info.TypeInfo.Namespace;
var classNameToFindWithNamespace = namespaceName + "." + classNameToFind;
var type = currentAssembly.GetTypeByName(classNameToFindWithNamespace);
ilonatommy marked this conversation as resolved.
Show resolved Hide resolved
ilonatommy marked this conversation as resolved.
Show resolved Hide resolved
if (type != null)
{
typeId = await sdbHelper.GetTypeIdFromToken(sessionId, currentAssembly.DebugId, type.Token, token);
continue;
}
foreach (var asm in store.assemblies)
{
var type = asm.GetTypeByName(classNameToFind);
type = asm.GetTypeByName(classNameToFind);
if (type != null)
{
typeId = await sdbHelper.GetTypeIdFromToken(sessionId, asm.DebugId, type.Token, token);
break;
}
}
}
Expand Down Expand Up @@ -201,6 +212,11 @@ public async Task<JObject> Resolve(string varName, CancellationToken token)
}
}
}
else if (rootObject == null)
ilonatommy marked this conversation as resolved.
Show resolved Hide resolved
{
rootObject = await TryToRunOnLoadedClasses(varName, token);
return rootObject;
}
}
scopeCache.MemberReferences[varName] = rootObject;
return rootObject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ public static IEnumerable<object[]> InstanceMethodForTypeMembersTestData(string
}
}

public static IEnumerable<object[]> EvaluateStaticClassFromAsyncMethodTestData(string type_name)
{
yield return new object[] { type_name, "EvaluateAsyncMethods", "EvaluateAsyncMethods", true };
}

[Theory]
[MemberData(nameof(InstanceMethodForTypeMembersTestData), parameters: "DebuggerTests.EvaluateTestsStructWithProperties")]
[MemberData(nameof(InstanceMethodForTypeMembersTestData), parameters: "DebuggerTests.EvaluateTestsClassWithProperties")]
Expand Down Expand Up @@ -695,6 +700,80 @@ await EvaluateOnCallFrameAndCheck(id,
("DebuggerTests.EvaluateStaticClass.StaticPropertyWithError", TString("System.Exception: not implemented")));
});

[Fact]
public async Task EvaluateStaticClassFromStaticMethod() => await CheckInspectLocalsAtBreakpointSite(
ilonatommy marked this conversation as resolved.
Show resolved Hide resolved
"DebuggerTests.EvaluateMethodTestsClass", "EvaluateMethods", 1, "EvaluateMethods",
"window.setTimeout(function() { invoke_static_method ('[debugger-test] DebuggerTests.EvaluateMethodTestsClass:EvaluateMethods'); })",
wait_for_event_fn: async (pause_location) =>
{
var id = pause_location["callFrames"][0]["callFrameId"].Value<string>();

var frame = pause_location["callFrames"][0];

await EvaluateOnCallFrameAndCheck(id,
("EvaluateStaticClass.StaticField1", TNumber(10)));
ilonatommy marked this conversation as resolved.
Show resolved Hide resolved
await EvaluateOnCallFrameAndCheck(id,
("EvaluateStaticClass.StaticProperty1", TString("StaticProperty1")));
await EvaluateOnCallFrameAndCheck(id,
("EvaluateStaticClass.StaticPropertyWithError", TString("System.Exception: not implemented")));
await EvaluateOnCallFrameAndCheck(id,
("DebuggerTests.EvaluateStaticClass.StaticField1", TNumber(10)));
await EvaluateOnCallFrameAndCheck(id,
("DebuggerTests.EvaluateStaticClass.StaticProperty1", TString("StaticProperty1")));
await EvaluateOnCallFrameAndCheck(id,
("DebuggerTests.EvaluateStaticClass.StaticPropertyWithError", TString("System.Exception: not implemented")));
});

[Theory]
[MemberData(nameof(EvaluateStaticClassFromAsyncMethodTestData), parameters: "DebuggerTests.EvaluateMethodTestsClass")]
public async Task EvaluateStaticClassFromAsyncMethod(string type, string method, string bp_function_name, bool is_async)
ilonatommy marked this conversation as resolved.
Show resolved Hide resolved
=> await CheckInspectLocalsAtBreakpointSite(
type, method, 1, bp_function_name,
"window.setTimeout(function() { invoke_static_method ('[debugger-test] DebuggerTests.EvaluateMethodTestsClass:EvaluateAsyncMethods'); })",
wait_for_event_fn: async (pause_location) =>
{
var id = pause_location["callFrames"][0]["callFrameId"].Value<string>();

var frame = pause_location["callFrames"][0];

await EvaluateOnCallFrameAndCheck(id,
("EvaluateStaticClass.StaticField1", TNumber(10)));
await EvaluateOnCallFrameAndCheck(id,
("EvaluateStaticClass.StaticProperty1", TString("StaticProperty1")));
await EvaluateOnCallFrameAndCheck(id,
("EvaluateStaticClass.StaticPropertyWithError", TString("System.Exception: not implemented")));
await EvaluateOnCallFrameAndCheck(id,
("DebuggerTests.EvaluateStaticClass.StaticField1", TNumber(10)));
await EvaluateOnCallFrameAndCheck(id,
("DebuggerTests.EvaluateStaticClass.StaticProperty1", TString("StaticProperty1")));
await EvaluateOnCallFrameAndCheck(id,
("DebuggerTests.EvaluateStaticClass.StaticPropertyWithError", TString("System.Exception: not implemented")));
});

[Fact]
public async Task EvaluateNonStaticClassWithStaticFields() => await CheckInspectLocalsAtBreakpointSite(
"DebuggerTests.EvaluateMethodTestsClass", "EvaluateAsyncMethods", 3, "EvaluateAsyncMethods",
"window.setTimeout(function() { invoke_static_method ('[debugger-test] DebuggerTests.EvaluateMethodTestsClass:EvaluateAsyncMethods'); })",
wait_for_event_fn: async (pause_location) =>
{
var id = pause_location["callFrames"][0]["callFrameId"].Value<string>();

var frame = pause_location["callFrames"][0];

await EvaluateOnCallFrameAndCheck(id,
("DebuggerTests.EvaluateNonStaticClassWithStaticFields.StaticField1", TNumber(10)));
await EvaluateOnCallFrameAndCheck(id,
("DebuggerTests.EvaluateNonStaticClassWithStaticFields.StaticProperty1", TString("StaticProperty1")));
await EvaluateOnCallFrameAndCheck(id,
("DebuggerTests.EvaluateNonStaticClassWithStaticFields.StaticPropertyWithError", TString("System.Exception: not implemented")));
await EvaluateOnCallFrameAndCheck(id,
("EvaluateNonStaticClassWithStaticFields.StaticField1", TNumber(10)));
await EvaluateOnCallFrameAndCheck(id,
("EvaluateNonStaticClassWithStaticFields.StaticProperty1", TString("StaticProperty1")));
await EvaluateOnCallFrameAndCheck(id,
("EvaluateNonStaticClassWithStaticFields.StaticPropertyWithError", TString("System.Exception: not implemented")));
});
ilonatommy marked this conversation as resolved.
Show resolved Hide resolved

[Fact]
public async Task EvaluateStaticClassInvalidField() => await CheckInspectLocalsAtBreakpointSite(
"DebuggerTests.EvaluateMethodTestsClass/TestEvaluate", "run", 9, "run",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,12 @@ public static void EvaluateMethods()
f.run(100, 200, "9000", "test", 45);
}

public static void EvaluateAsyncMethods()
{
var staticClass = new EvaluateNonStaticClassWithStaticFields();
staticClass.run();
}

}

public static class EvaluateStaticClass
Expand All @@ -414,6 +420,23 @@ public static class EvaluateStaticClass
public static string StaticPropertyWithError => throw new Exception("not implemented");
}

public class EvaluateNonStaticClassWithStaticFields
{
public static int StaticField1 = 10;
public static string StaticProperty1 => "StaticProperty1";
public static string StaticPropertyWithError => throw new Exception("not implemented");

private int HelperMethod()
{
return 5;
}

public async void run()
{
var makeAwaitable = await Task.Run(() => HelperMethod());
}
}

public class EvaluateLocalsWithElementAccessTests
{
public class TestEvaluate
Expand Down