-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Changes from 6 commits
38368ca
24a3cbe
8b59dab
e46fe72
79255ae
19ef4a8
ec07dd1
3a80364
1d9162a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -358,6 +358,55 @@ internal enum StepSize | |
Line | ||
} | ||
|
||
internal class ArrayDimensions | ||
{ | ||
public int Rank { get; } | ||
public List<int> Bounds { get; } | ||
|
||
public ArrayDimensions(int rank) | ||
{ | ||
Rank = rank; | ||
Bounds = new List<int>(rank); | ||
} | ||
public int TotalLength() | ||
{ | ||
int ret = 1; | ||
for (int i = 0 ; i < Rank ; i++) | ||
{ | ||
ret *= Bounds[i]; | ||
} | ||
return ret; | ||
} | ||
public override string ToString() | ||
{ | ||
return $"{string.Join(", ", Bounds.ToArray())}"; | ||
} | ||
public string GetArrayIndexString(int idx) | ||
{ | ||
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 +1449,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 +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) | ||
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. rename to |
||
{ | ||
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); | ||
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. should this be 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. And populate 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. done. |
||
for (int i = 0 ; i < length; i++) | ||
{ | ||
arrDimensions.Bounds.Add(retDebuggerCmdReader.ReadInt32()); | ||
retDebuggerCmdReader.ReadInt32(); | ||
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. What is this reading? comment would be helpful |
||
} | ||
return arrDimensions; | ||
} | ||
public async Task<List<int>> GetTypeIdFromObject(SessionId sessionId, int object_id, bool withParents, CancellationToken token) | ||
{ | ||
|
@@ -1778,9 +1833,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 className = await GetClassNameFromObject(sessionId, objectId, token); | ||
var arrayType = className.ToString(); | ||
var length = await GetArrayLength(sessionId, objectId, token); | ||
return CreateJObject<string>(null, "object", $"{value.ToString()}({length})", false, value.ToString(), "dotnet:array:" + objectId, null, "array"); | ||
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", arrayType, false, className.ToString(), "dotnet:array:" + objectId, null, length.Rank == 1 ? "array" : null); | ||
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. nit: param names, a bit confusing to read otherwise |
||
} | ||
|
||
public async Task<JObject> CreateJObjectForObject(SessionId sessionId, MonoBinaryReader retDebuggerCmdReader, int typeIdFromAttribute, bool forDebuggerDisplayAttribute, CancellationToken token) | ||
|
@@ -2211,16 +2271,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()); | ||
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 < length.TotalLength(); i++) | ||
{ | ||
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); | ||
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. nit: param name for the bools at least |
||
array.Add(var_json); | ||
} | ||
return array; | ||
} | ||
|
||
public async Task<JObject> GetArrayValuesProxy(SessionId sessionId, int arrayId, CancellationToken token) | ||
{ | ||
var length = await GetArrayLength(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.ToArray() | ||
}); | ||
return arrayProxy; | ||
} | ||
|
||
public async Task<bool> EnableExceptions(SessionId sessionId, PauseOnExceptionsKind state, CancellationToken token) | ||
{ | ||
if (state == PauseOnExceptionsKind.Unset) | ||
|
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