-
Notifications
You must be signed in to change notification settings - Fork 5.5k
[wasm][debugger] Support calling get_Item passing decimal, float or double as parameter.
#90260
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9d8b122
Support calling get_Item using decimal, float and double as parameter.
thaystg 73eb91f
Update src/mono/wasm/debugger/BrowserDebugProxy/SignatureTypeProvider.cs
thaystg ff26650
Addressing some comments.
thaystg e6db9cc
Merge branch 'thays_fix_76014' of github.com:thaystg/runtime into tha…
thaystg 9d296e0
fix compilation
thaystg b5c37f9
Fix wrong cast.
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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -439,15 +439,15 @@ public async Task<JObject> Resolve(ElementAccessExpressionSyntax elementAccess, | |
| { | ||
| MethodInfoWithDebugInformation methodInfo = await context.SdbAgent.GetMethodInfo(methodIds[i], token); | ||
| ParameterInfo[] paramInfo = methodInfo.GetParametersInfo(); | ||
|
|
||
| // get_Item should not have an overload, but if user defined it, take the default one: with one param (key) | ||
| if (paramInfo.Length == 1) | ||
| { | ||
| try | ||
| { | ||
| if (indexObject != null && !CheckParametersCompatibility(paramInfo[0].TypeCode, indexObject)) | ||
| continue; | ||
| ArraySegment<byte> buffer = indexObject is null ? | ||
| await WriteLiteralExpressionAsIndex(objectId, elementIdxInfo.IndexingExpression, elementIdxInfo.ElementIdxStr) : | ||
| await WriteJObjectAsIndex(objectId, indexObject, elementIdxInfo.ElementIdxStr); | ||
| await WriteLiteralExpressionAsIndex(objectId, elementIdxInfo.IndexingExpression, elementIdxInfo.ElementIdxStr) : | ||
| await WriteJObjectAsIndex(objectId, indexObject, elementIdxInfo.ElementIdxStr, paramInfo[0].TypeCode); | ||
| JObject getItemRetObj = await context.SdbAgent.InvokeMethod(buffer, methodIds[i], token); | ||
| return (JObject)getItemRetObj["value"]; | ||
| } | ||
|
|
@@ -524,12 +524,12 @@ async Task<ElementIndexInfo> GetElementIndexInfo() | |
| IndexingExpression: indexingExpression); | ||
| } | ||
|
|
||
| async Task<ArraySegment<byte>> WriteJObjectAsIndex(DotnetObjectId rootObjId, JObject indexObject, string elementIdxStr) | ||
| async Task<ArraySegment<byte>> WriteJObjectAsIndex(DotnetObjectId rootObjId, JObject indexObject, string elementIdxStr, ElementType? expectedType) | ||
| { | ||
| using var writer = new MonoBinaryWriter(); | ||
| writer.WriteObj(rootObjId, context.SdbAgent); | ||
| writer.Write(1); // number of method args | ||
| if (!await writer.WriteJsonValue(indexObject, context.SdbAgent, token)) | ||
| if (!await writer.WriteJsonValue(indexObject, context.SdbAgent, expectedType, token)) | ||
| throw new InternalErrorException($"Parsing index of type {indexObject["type"].Value<string>()} to write it into the buffer failed."); | ||
| return writer.GetParameterBuffer(); | ||
| } | ||
|
|
@@ -545,6 +545,56 @@ async Task<ArraySegment<byte>> WriteLiteralExpressionAsIndex(DotnetObjectId root | |
| } | ||
| } | ||
|
|
||
| private static bool CheckParametersCompatibility(ElementType? paramTypeCode, JObject value) | ||
| { | ||
|
radical marked this conversation as resolved.
|
||
| if (!paramTypeCode.HasValue) | ||
| return true; | ||
| var argumentType = value["type"]?.Value<string>(); | ||
| var argumentClassName = value["className"]?.Value<string>(); | ||
|
|
||
| switch (paramTypeCode.Value) | ||
| { | ||
| case ElementType.Object: | ||
| if (argumentType != "object") | ||
| return false; | ||
| break; | ||
| case ElementType.I2: | ||
| case ElementType.I4: | ||
| case ElementType.I8: | ||
| case ElementType.R4: | ||
| case ElementType.R8: | ||
| case ElementType.U2: | ||
| case ElementType.U4: | ||
| case ElementType.U8: | ||
| if (argumentType != "number") | ||
| return false; | ||
| if (argumentType == "object") | ||
| return false; | ||
|
ilonatommy marked this conversation as resolved.
|
||
| break; | ||
| case ElementType.Char: | ||
| if (argumentType != "string" && argumentType != "symbol") | ||
| return false; | ||
| if (argumentType == "object") | ||
| return false; | ||
| break; | ||
| case ElementType.Boolean: | ||
| if (argumentType == "boolean") | ||
| return true; | ||
| if (argumentType == "number" && (argumentClassName == "Single" || argumentClassName == "Double")) | ||
| return false; | ||
| if (argumentType == "object") | ||
| return false; | ||
| break; | ||
| case ElementType.String: | ||
| if (argumentType != "string") | ||
| return false; | ||
| break; | ||
| default: | ||
|
ilonatommy marked this conversation as resolved.
|
||
| return true; | ||
|
Member
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. We're missing on this list:
|
||
| } | ||
| return true; | ||
| } | ||
|
|
||
| public async Task<(JObject, string)> ResolveInvocationInfo(InvocationExpressionSyntax method, CancellationToken token) | ||
| { | ||
| var methodName = ""; | ||
|
|
@@ -664,7 +714,7 @@ public async Task<JObject> Resolve(InvocationExpressionSyntax method, Dictionary | |
| } | ||
| else if (arg.Expression is IdentifierNameSyntax identifierName) | ||
| { | ||
| if (!await commandParamsObjWriter.WriteJsonValue(memberAccessValues[identifierName.Identifier.Text], context.SdbAgent, token)) | ||
| if (!await commandParamsObjWriter.WriteJsonValue(memberAccessValues[identifierName.Identifier.Text], context.SdbAgent, methodParamsInfo[argIndex].TypeCode, token)) | ||
| throw new InternalErrorException($"Unable to evaluate method '{methodName}'. Unable to write IdentifierNameSyntax into binary writer."); | ||
| } | ||
| else | ||
|
|
||
This file contains hidden or 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
54 changes: 54 additions & 0 deletions
54
src/mono/wasm/debugger/BrowserDebugProxy/SignatureTypeProvider.cs
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Collections.Immutable; | ||
| using System.Linq; | ||
| using System.Reflection.Metadata; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
| using Microsoft.WebAssembly.Diagnostics; | ||
|
|
||
| namespace Microsoft.WebAssembly.Diagnostics; | ||
|
|
||
| internal sealed class SignatureTypeProvider : ISignatureTypeProvider<ElementType, object> | ||
| { | ||
| public ElementType GetPrimitiveType(PrimitiveTypeCode typeCode) | ||
| => typeCode switch | ||
| { | ||
| PrimitiveTypeCode.Boolean => ElementType.Boolean, | ||
| PrimitiveTypeCode.Byte => ElementType.U1, | ||
| PrimitiveTypeCode.Char => ElementType.Char, | ||
| PrimitiveTypeCode.Double => ElementType.R8, | ||
| PrimitiveTypeCode.Int16 => ElementType.I2, | ||
| PrimitiveTypeCode.Int32 => ElementType.I4, | ||
| PrimitiveTypeCode.Int64 => ElementType.I8, | ||
| PrimitiveTypeCode.IntPtr => ElementType.Ptr, | ||
| PrimitiveTypeCode.Object => ElementType.Object, | ||
| PrimitiveTypeCode.SByte => ElementType.I1, | ||
| PrimitiveTypeCode.Single => ElementType.R4, | ||
| PrimitiveTypeCode.String => ElementType.String, | ||
| PrimitiveTypeCode.TypedReference => ElementType.ValueType, | ||
| PrimitiveTypeCode.UInt16 => ElementType.U2, | ||
| PrimitiveTypeCode.UInt32 => ElementType.U4, | ||
| PrimitiveTypeCode.UInt64 => ElementType.U8, | ||
| PrimitiveTypeCode.UIntPtr => ElementType.Ptr, | ||
| PrimitiveTypeCode.Void => ElementType.Void, | ||
| _ => ElementType.End, | ||
| }; | ||
|
|
||
| ElementType ISignatureTypeProvider<ElementType, object>.GetFunctionPointerType(MethodSignature<ElementType> signature) => ElementType.FnPtr; | ||
| ElementType ISignatureTypeProvider<ElementType, object>.GetModifiedType(ElementType modifier, ElementType unmodifiedType, bool isRequired) => ElementType.Object; | ||
| ElementType ISignatureTypeProvider<ElementType, object>.GetPinnedType(ElementType elementType) => ElementType.Object; | ||
| ElementType IConstructedTypeProvider<ElementType>.GetArrayType(ElementType elementType, ArrayShape shape) => ElementType.Array; | ||
| ElementType IConstructedTypeProvider<ElementType>.GetByReferenceType(ElementType elementType) => ElementType.Object; | ||
| ElementType IConstructedTypeProvider<ElementType>.GetGenericInstantiation(ElementType genericType, ImmutableArray<ElementType> typeArguments) => ElementType.Object; | ||
| ElementType IConstructedTypeProvider<ElementType>.GetPointerType(ElementType elementType) => ElementType.Ptr; | ||
| ElementType ISZArrayTypeProvider<ElementType>.GetSZArrayType(ElementType elementType) => ElementType.SzArray; | ||
| ElementType ISignatureTypeProvider<ElementType, object>.GetGenericMethodParameter(object genericContext, int index) => ElementType.Object; | ||
| ElementType ISignatureTypeProvider<ElementType, object>.GetGenericTypeParameter(object genericContext, int index) => ElementType.Object; | ||
| ElementType ISignatureTypeProvider<ElementType, object>.GetTypeFromSpecification(MetadataReader reader, object genericContext, TypeSpecificationHandle handle, byte rawTypeKind) => ElementType.Object; | ||
| ElementType ISimpleTypeProvider<ElementType>.GetTypeFromDefinition(MetadataReader reader, TypeDefinitionHandle handle, byte rawTypeKind) => ElementType.Object; | ||
| ElementType ISimpleTypeProvider<ElementType>.GetTypeFromReference(MetadataReader reader, TypeReferenceHandle handle, byte rawTypeKind) => ElementType.Object; | ||
| } |
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -659,12 +659,10 @@ await EvaluateOnCallFrameAndCheck(id, | |
| ("f[longString]", TBool(true)), | ||
| ("f[aBool]", TString("True")), | ||
| ("f[aChar]", TString("res_9")), | ||
| ("f[shortString]", TBool(false)) | ||
| // ("f[aFloat]", TNumber(1)), | ||
| // ("f[aDouble]", TNumber(2)), | ||
|
|
||
| // FixMe: https://github.com/dotnet/runtime/issues/76014 | ||
| // ("f[aDecimal]", TNumber(3)) // object | ||
| ("f[shortString]", TBool(false)), | ||
| ("f[aFloat]", TNumber(1)), | ||
| ("f[aDouble]", TNumber(2)), | ||
| ("f[aDecimal]", TNumber(3)) // object | ||
|
Member
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. Tests corresponding to the comment in MonoSDBHelper. |
||
| ); | ||
| }); | ||
|
|
||
|
|
||
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.
genericContext: null- 👍 for adding the param name!