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 debugger behavior when the type has ToString method overridden #76780

Merged
merged 11 commits into from
Oct 11, 2022

Conversation

thaystg
Copy link
Member

@thaystg thaystg commented Oct 8, 2022

The description of an object that has ToString implemented should bethe result of the ToString and not the type name.

Fixes #76748

Using this PR:
image

@ghost
Copy link

ghost commented Oct 8, 2022

Tagging subscribers to this area: @thaystg
See info in area-owners.md if you want to be subscribed.

Issue Details

The description of an object that has ToString implemented should bethe result of the ToString and not the type name.

Fixes #76748

Using this PR:
image

Author: thaystg
Assignees: -
Labels:

area-Debugger-mono

Milestone: -

@radical radical changed the title [wasm][debugger] Fix debugger behavior when the type has ToString method overwritten [wasm][debugger] Fix debugger behavior when the type has ToString method overridden Oct 9, 2022
Implement support for value types with ToString overriden.
Fix Debugger* is more relevant than ToString
if (typeInfo.Name == "object")
return null;
Microsoft.WebAssembly.Diagnostics.MethodInfo methodInfo = typeInfo.Info.Methods.FirstOrDefault(m => m.Name == "ToString");
if (!IsEnum && methodInfo == null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be ||?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this method exit early in case of IsEnum==true?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No should be &&, if it's a enum we want to call ToString even if we cannot find the method.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't get the method in case of an enum? Is that the case for other valuetypes? record struct?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only for enum, I added tests for record also.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are no methods returned for enums at all? Is that a debugger-agent thing?

Copy link
Member Author

@thaystg thaystg Oct 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No methods returned for enums at all, not sure if it's a debugger-agent thing or if they are really not implemented in the enum, they are somewhere like in a "base class".

src/mono/wasm/debugger/BrowserDebugProxy/ValueTypeClass.cs Outdated Show resolved Hide resolved
src/mono/wasm/debugger/BrowserDebugProxy/ValueTypeClass.cs Outdated Show resolved Hide resolved
src/mono/wasm/debugger/BrowserDebugProxy/ValueTypeClass.cs Outdated Show resolved Hide resolved
src/mono/wasm/debugger/BrowserDebugProxy/ValueTypeClass.cs Outdated Show resolved Hide resolved
Copy link
Member

@radical radical left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than the minor comments, LGTM 👍

@@ -1839,6 +1839,43 @@ public Task<JObject> InvokeMethod(DotnetObjectId dotnetObjectId, CancellationTok
: throw new ArgumentException($"Cannot invoke method with id {methodId} on {dotnetObjectId}", nameof(dotnetObjectId));
}

public async Task<string> InvokeToStringAsync(List<int> typeIds, bool isValueType, bool isEnum, int objectId, BindingFlags extraFlags, CancellationToken token)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: extraFlags could have BindingFlags.Default as the default value.

src/mono/wasm/debugger/BrowserDebugProxy/MonoSDBHelper.cs Outdated Show resolved Hide resolved
src/mono/wasm/debugger/BrowserDebugProxy/MonoSDBHelper.cs Outdated Show resolved Hide resolved
src/mono/wasm/debugger/BrowserDebugProxy/ValueTypeClass.cs Outdated Show resolved Hide resolved
src/mono/wasm/debugger/BrowserDebugProxy/ValueTypeClass.cs Outdated Show resolved Hide resolved
src/mono/wasm/debugger/BrowserDebugProxy/MonoSDBHelper.cs Outdated Show resolved Hide resolved
src/mono/wasm/debugger/BrowserDebugProxy/ValueTypeClass.cs Outdated Show resolved Hide resolved
thaystg and others added 2 commits October 10, 2022 16:20
Co-authored-by: Ankit Jain <radical@gmail.com>
Copy link
Member

@ilonatommy ilonatommy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, good job👍

foreach (var methodId in methodIds)
{
var methodInfoFromRuntime = await GetMethodInfo(methodId, token);
if (methodInfoFromRuntime.Info.GetParametersInfo().Length > 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MethodInfoWithDebugInformation implements GetParametersInfo(), so we could shorten:

Suggested change
if (methodInfoFromRuntime.Info.GetParametersInfo().Length > 0)
if (methodInfoFromRuntime.GetParametersInfo().Length > 0)

@thaystg thaystg merged commit 26cc618 into dotnet:main Oct 11, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Nov 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
3 participants