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] View multidimensional array when debugging #60983

Merged
merged 9 commits into from
Nov 16, 2021

Conversation

thaystg
Copy link
Member

@thaystg thaystg commented Oct 28, 2021

Unfortunatelly as JS doesn't have mutidimensional arrays, I have to threat mutidimensional array as an object, as far as I understood for the user experience there isn't any difference in the behavior.

Before PR:
image

After PR on VS:
image

After PR on Chrome:
image

Fixes https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1417072

@ghost
Copy link

ghost commented Oct 28, 2021

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

Issue Details

It's working when debug from chrome but not when debug from VS, because it uses callFunctionOn

Author: thaystg
Assignees: -
Labels:

area-Debugger-mono

Milestone: -

@radical radical added the arch-wasm WebAssembly architecture label Oct 28, 2021
@ghost
Copy link

ghost commented Oct 28, 2021

Tagging subscribers to 'arch-wasm': @lewing
See info in area-owners.md if you want to be subscribed.

Issue Details

It's working when debug from chrome but not when debug from VS, because it uses callFunctionOn

Author: thaystg
Assignees: -
Labels:

arch-wasm, area-Debugger-mono

Milestone: -

@lewing
Copy link
Member

lewing commented Oct 28, 2021

I really wonder why vscode-js-debug uses callFunctionOn rather than the protocol bits.

@thaystg thaystg marked this pull request as ready for review November 3, 2021 15:06
@thaystg thaystg requested a review from marek-safar as a code owner November 3, 2021 15:06
@thaystg thaystg requested review from lewing and radical November 3, 2021 15:07
{
var commandParams = new MemoryStream();
var commandParamsWriter = new MonoBinaryWriter(commandParams);
commandParamsWriter.Write(object_id);
var retDebuggerCmdReader = await SendDebuggerAgentCommand<CmdArray>(sessionId, CmdArray.GetLength, commandParams, token);
var length = retDebuggerCmdReader.ReadInt32();
length = retDebuggerCmdReader.ReadInt32();
return length;
var arrDimensions = new ArrayDimensions(length);
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 var rank = new int[length] then new ArrayDimensions(rank) and forgo the resizing?

Copy link
Member

Choose a reason for hiding this comment

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

And populate rank, before new ArrayDimensions, so TotalLength can be precomputed too. And ArrayDimensions can be a record.

Copy link
Member Author

Choose a reason for hiding this comment

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

done.

@@ -1451,15 +1501,20 @@ public async Task<string> GetStringValue(SessionId sessionId, int string_id, Can
}
return null;
}
public async Task<int> GetArrayLength(SessionId sessionId, int object_id, CancellationToken token)
public async Task<ArrayDimensions> GetArrayLength(SessionId sessionId, int object_id, 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.

rename to GetArrayDimensions

for (int i = 0 ; i < length; i++)
{
rank[i] = retDebuggerCmdReader.ReadInt32();
retDebuggerCmdReader.ReadInt32();
Copy link
Member

Choose a reason for hiding this comment

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

What is this reading? comment would be helpful

@@ -2211,16 +2266,28 @@ public async Task<JArray> GetArrayValues(SessionId sessionId, int arrayId, Cance
var commandParamsWriter = new MonoBinaryWriter(commandParams);
commandParamsWriter.Write(arrayId);
commandParamsWriter.Write(0);
commandParamsWriter.Write(length);
commandParamsWriter.Write(length.TotalLength);
Copy link
Member

Choose a reason for hiding this comment

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

nit: length -> dimensions?

{
var var_json = await CreateJObjectForVariableValue(sessionId, retDebuggerCmdReader, i.ToString(), false, -1, false, token);
var var_json = await CreateJObjectForVariableValue(sessionId, retDebuggerCmdReader, length.GetArrayIndexString(i), false, -1, false, 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: param name for the bools at least

arrayType = arrayType.Insert(arrayType.LastIndexOf('[')+1, length.ToString());
if (className.LastIndexOf('[') > 0)
className = className.Insert(arrayType.LastIndexOf('[')+1, new string(',', length.Rank-1));
return CreateJObject<string>(null, "object", arrayType, false, className.ToString(), "dotnet:array:" + objectId, null, length.Rank == 1 ? "array" : null);
Copy link
Member

Choose a reason for hiding this comment

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

nit: param names, a bit confusing to read otherwise

var length = await GetArrayLength(sessionId, arrayId, token);
var arrayProxy = JObject.FromObject(new
{
items = await GetArrayValues(sessionId, arrayId, token),
Copy link
Member

Choose a reason for hiding this comment

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

GetArrayValues also calls GetArrayLength. Instead maybe GetArrayValues can return (JArray, ArrayDimensions), or it can take a `ArrayDimensions argument?

int boundLimit = 1;
int lastBoundLimit = 1;
int[] arrayStr = new int[Rank];
int rankStart = 0;
Copy link
Member

Choose a reason for hiding this comment

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

Check for idx < 0, and idx >= TotalLength

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.

LGTM! thank you for your patience :)

@thaystg
Copy link
Member Author

thaystg commented Dec 1, 2021

/backport to release/6.0

@github-actions
Copy link
Contributor

github-actions bot commented Dec 1, 2021

Started backporting to release/6.0: https://github.com/dotnet/runtime/actions/runs/1527691382

@github-actions
Copy link
Contributor

github-actions bot commented Dec 1, 2021

@thaystg backporting to release/6.0 failed, the patch most likely resulted in conflicts:

$ git am --3way --ignore-whitespace --keep-non-patch changes.patch

Applying: It's working when debug from chrome but not when debug from VS, because it uses callFunctionOn
Applying: Remove unrelated change.
Applying: Working also on VS.
Applying: Working also on VS.
Using index info to reconstruct a base tree...
A	src/mono/wasm/runtime/debug.ts
Falling back to patching base and 3-way merge...
CONFLICT (modify/delete): src/mono/wasm/runtime/debug.ts deleted in HEAD and modified in Working also on VS.. Version Working also on VS. of src/mono/wasm/runtime/debug.ts left in tree.
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0004 Working also on VS.
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
Error: The process '/usr/bin/git' failed with exit code 128

Please backport manually!

@ghost ghost locked as resolved and limited conversation to collaborators Jan 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
arch-wasm WebAssembly architecture area-Debugger-mono
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants