Skip to content

Conversation

@thaystg
Copy link
Member

@thaystg thaystg commented Sep 16, 2022

To reproduce:

Run();
static void Run()
{
    Invoke(new string[] { "TEST" });
}
static void Invoke(object[] parameters)
{
    CheckArguments(parameters);
}
static void CheckArguments(ReadOnlySpan<object> parameters)
{
    System.Diagnostics.Debugger.Break();
}

Attach debugger and try to inspect parameters parameter, mono runtime will crash.

While decoding a object / valuetype that has a byref field, it was dereferencing the pointer twice when it was trying to use it, and then the address was invalid.

@lambdageek do I need to free the new memory that I allocated or it will be freed when the object is freed?

On wasm we don't have the exception because we don't try to access the synchronisation field that was the one that become invalid.
But while trying to create a test for wasm I found another issue related and it's fixed here.

Also created a issue to support Format Specifiers in C# while debugging on wasm:
#75773

@ghost
Copy link

ghost commented Sep 16, 2022

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

Issue Details

To reproduce:

Run();
static void Run()
{
    Invoke(new string[] { "TEST" });
}
static void Invoke(object[] parameters)
{
    CheckArguments(parameters);
}
static void CheckArguments(ReadOnlySpan<object> parameters)
{
    System.Diagnostics.Debugger.Break();
}

Attach debugger and try to inspect parameters parameter, mono runtime will crash.

While decoding a object / valuetype that has a byref field, it was dereferencing the pointer twice when it was trying to use it, and then the address was invalid.

@lambdageek do I need to free the new memory that I allocated or it will be freed when the object is freed?

On wasm we don't have the exception because we don't try to access the synchronisation field that was the one that become invalid.
But while trying to create a test for wasm I found another issue related and it's fixed here.

Also created a issue to support Format Specifiers in C# while debugging on wasm:
#75773

Author: thaystg
Assignees: -
Labels:

area-Debugger-mono

Milestone: -

Copy link
Member

@lewing lewing left a comment

Choose a reason for hiding this comment

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

Minor feedback

{
dispAttrStr = dispAttrStr.Replace(",nq", "");
}
if (dispAttrStr.Contains(", raw"))
Copy link
Member

Choose a reason for hiding this comment

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

maybe turn all these into a regex (and or use ordinal)

@thaystg
Copy link
Member Author

thaystg commented Sep 23, 2022

/backport to release/7.0

@github-actions
Copy link
Contributor

Started backporting to release/7.0: https://github.com/dotnet/runtime/actions/runs/3114596965

@lambdageek
Copy link
Member

The current fix is kind of a stopgap because it leaks memory. The real issue is that debugger method invokes dont' handle ref fields in ref structs (which may appear as this or as arguments).

Thays is working on another approach where we precalculate the extra space needed for values that the ref fields can point at and then use g_alloca to grab the needed temporary space before calling decode_value (which will use the passed-in extra buffer). Depending on how complex the fix becomes, we shoudl consider it for servicing net7. /cc @lewing

@ghost ghost locked as resolved and limited conversation to collaborators Oct 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants