-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
38368ca
It's working when debug from chrome but not when debug from VS, becau…
thaystg 24a3cbe
Remove unrelated change.
thaystg 8b59dab
Working also on VS.
thaystg e46fe72
Merge branch 'dotnet:main' into thays_multidimensional_array
thaystg 79255ae
Working also on VS.
thaystg 19ef4a8
merge main
thaystg ec07dd1
Addressing @lewing and @radical comments
thaystg 3a80364
Change ArrayDimensions to be a record and not a class as suggested by…
thaystg 1d9162a
Addressing @radical comments.
thaystg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -358,6 +358,52 @@ internal enum StepSize | |
Line | ||
} | ||
|
||
internal record ArrayDimensions | ||
{ | ||
internal int Rank { get; } | ||
internal int [] Bounds { get; } | ||
internal int TotalLength { get; } | ||
public ArrayDimensions(int [] rank) | ||
{ | ||
Rank = rank.Length; | ||
Bounds = rank; | ||
TotalLength = 1; | ||
for (int i = 0 ; i < Rank ; i++) | ||
TotalLength *= Bounds[i]; | ||
} | ||
|
||
public override string ToString() | ||
{ | ||
return $"{string.Join(", ", Bounds)}"; | ||
} | ||
internal string GetArrayIndexString(int idx) | ||
{ | ||
if (idx < 0 || idx >= TotalLength) | ||
return "Invalid Index"; | ||
int boundLimit = 1; | ||
int lastBoundLimit = 1; | ||
int[] arrayStr = new int[Rank]; | ||
int rankStart = 0; | ||
while (idx > 0) | ||
{ | ||
boundLimit = 1; | ||
for (int i = Rank - 1; i >= rankStart; i--) | ||
{ | ||
lastBoundLimit = boundLimit; | ||
boundLimit *= Bounds[i]; | ||
if (idx < boundLimit) | ||
{ | ||
arrayStr[i] = (int)(idx / lastBoundLimit); | ||
idx -= arrayStr[i] * lastBoundLimit; | ||
rankStart = i; | ||
break; | ||
} | ||
} | ||
} | ||
return $"{string.Join(", ", arrayStr)}"; | ||
} | ||
} | ||
|
||
internal record MethodInfoWithDebugInformation(MethodInfo Info, int DebugId, string Name); | ||
|
||
internal class TypeInfoWithDebugInformation | ||
|
@@ -1400,7 +1446,8 @@ public async Task<string> GetTypeName(SessionId sessionId, int typeId, Cancellat | |
string className = await GetTypeNameOriginal(sessionId, typeId, token); | ||
className = className.Replace("+", "."); | ||
className = Regex.Replace(className, @"`\d+", ""); | ||
className = className.Replace("[]", "__SQUARED_BRACKETS__"); | ||
className = Regex.Replace(className, @"[[, ]+]", "__SQUARED_BRACKETS__"); | ||
//className = className.Replace("[]", "__SQUARED_BRACKETS__"); | ||
className = className.Replace("[", "<"); | ||
className = className.Replace("]", ">"); | ||
className = className.Replace("__SQUARED_BRACKETS__", "[]"); | ||
|
@@ -1451,15 +1498,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> GetArrayDimensions(SessionId sessionId, int object_id, CancellationToken token) | ||
{ | ||
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 rank = new int[length]; | ||
for (int i = 0 ; i < length; i++) | ||
{ | ||
rank[i] = retDebuggerCmdReader.ReadInt32(); | ||
retDebuggerCmdReader.ReadInt32(); //lower_bound | ||
} | ||
return new ArrayDimensions(rank); | ||
} | ||
public async Task<List<int>> GetTypeIdFromObject(SessionId sessionId, int object_id, bool withParents, CancellationToken token) | ||
{ | ||
|
@@ -1778,9 +1830,14 @@ public async Task<JObject> CreateJObjectForString(SessionId sessionId, MonoBinar | |
public async Task<JObject> CreateJObjectForArray(SessionId sessionId, MonoBinaryReader retDebuggerCmdReader, CancellationToken token) | ||
{ | ||
var objectId = retDebuggerCmdReader.ReadInt32(); | ||
var value = await GetClassNameFromObject(sessionId, objectId, token); | ||
var length = await GetArrayLength(sessionId, objectId, token); | ||
return CreateJObject<string>(null, "object", $"{value.ToString()}({length})", false, value.ToString(), "dotnet:array:" + objectId, null, "array"); | ||
var className = await GetClassNameFromObject(sessionId, objectId, token); | ||
var arrayType = className.ToString(); | ||
var length = await GetArrayDimensions(sessionId, objectId, token); | ||
if (arrayType.LastIndexOf('[') > 0) | ||
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", description : arrayType, writable : false, className.ToString(), "dotnet:array:" + objectId, null, subtype : length.Rank == 1 ? "array" : null); | ||
} | ||
|
||
public async Task<JObject> CreateJObjectForObject(SessionId sessionId, MonoBinaryReader retDebuggerCmdReader, int typeIdFromAttribute, bool forDebuggerDisplayAttribute, CancellationToken token) | ||
|
@@ -2206,21 +2263,33 @@ public async Task<JArray> GetValueTypeProxy(SessionId sessionId, int valueTypeId | |
|
||
public async Task<JArray> GetArrayValues(SessionId sessionId, int arrayId, CancellationToken token) | ||
{ | ||
var length = await GetArrayLength(sessionId, arrayId, token); | ||
var dimensions = await GetArrayDimensions(sessionId, arrayId, token); | ||
var commandParams = new MemoryStream(); | ||
var commandParamsWriter = new MonoBinaryWriter(commandParams); | ||
commandParamsWriter.Write(arrayId); | ||
commandParamsWriter.Write(0); | ||
commandParamsWriter.Write(length); | ||
commandParamsWriter.Write(dimensions.TotalLength); | ||
var retDebuggerCmdReader = await SendDebuggerAgentCommand<CmdArray>(sessionId, CmdArray.GetValues, commandParams, token); | ||
JArray array = new JArray(); | ||
for (int i = 0 ; i < length ; i++) | ||
for (int i = 0 ; i < dimensions.TotalLength; i++) | ||
{ | ||
var var_json = await CreateJObjectForVariableValue(sessionId, retDebuggerCmdReader, i.ToString(), false, -1, false, token); | ||
var var_json = await CreateJObjectForVariableValue(sessionId, retDebuggerCmdReader, dimensions.GetArrayIndexString(i), isOwn : false, -1, forDebuggerDisplayAttribute : false, token); | ||
array.Add(var_json); | ||
} | ||
return array; | ||
} | ||
|
||
public async Task<JObject> GetArrayValuesProxy(SessionId sessionId, int arrayId, CancellationToken token) | ||
{ | ||
var length = await GetArrayDimensions(sessionId, arrayId, token); | ||
var arrayProxy = JObject.FromObject(new | ||
{ | ||
items = await GetArrayValues(sessionId, arrayId, token), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
dimensionsDetails = length.Bounds | ||
}); | ||
return arrayProxy; | ||
} | ||
|
||
public async Task<bool> EnableExceptions(SessionId sessionId, PauseOnExceptionsKind state, CancellationToken token) | ||
{ | ||
if (state == PauseOnExceptionsKind.Unset) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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