-
Notifications
You must be signed in to change notification settings - Fork 5.3k
[wasm] [debugger] Support method calls #55458
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
Changes from 5 commits
d3b52af
43257f3
acf758c
4039ce6
198ab2b
7f5ee6c
044bbf9
5c0f419
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 |
|---|---|---|
|
|
@@ -9,6 +9,8 @@ | |
| using Newtonsoft.Json; | ||
| using Newtonsoft.Json.Linq; | ||
| using System.IO; | ||
| using Microsoft.CodeAnalysis.CSharp.Syntax; | ||
| using System.Collections.Generic; | ||
|
|
||
| namespace Microsoft.WebAssembly.Diagnostics | ||
| { | ||
|
|
@@ -64,6 +66,10 @@ public async Task<JObject> GetValueFromObject(JToken objRet, CancellationToken t | |
| // Checks Locals, followed by `this` | ||
| public async Task<JObject> Resolve(string var_name, CancellationToken token) | ||
| { | ||
| //has method calls | ||
| if (var_name.Contains('(')) | ||
| return null; | ||
|
|
||
| string[] parts = var_name.Split("."); | ||
| JObject rootObject = null; | ||
|
|
||
|
|
@@ -126,5 +132,60 @@ public async Task<JObject> Resolve(string var_name, CancellationToken token) | |
| return rootObject; | ||
| } | ||
|
|
||
| public async Task<JObject> Resolve(InvocationExpressionSyntax method, Dictionary<string, JObject> memberAccessValues, CancellationToken token) | ||
| { | ||
| JObject rootObject = null; | ||
|
|
||
| var expr = method.Expression; | ||
| var methodName = ""; | ||
| if (expr is MemberAccessExpressionSyntax) | ||
| { | ||
| MemberAccessExpressionSyntax memberAccessExpressionSyntax = expr as MemberAccessExpressionSyntax; | ||
thaystg marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| rootObject = await Resolve(memberAccessExpressionSyntax.Expression.ToString(), token); | ||
| methodName = memberAccessExpressionSyntax.Name.ToString(); | ||
| } | ||
| if (rootObject != null) | ||
| { | ||
| DotnetObjectId.TryParse(rootObject?["objectId"]?.Value<string>(), out DotnetObjectId objectId); | ||
| var typeId = await proxy.sdbHelper.GetTypeIdFromObject(sessionId, int.Parse(objectId.Value), true, token); | ||
|
||
| int method_id = await proxy.sdbHelper.GetMethodIdByName(sessionId, typeId[0], methodName, token); | ||
| if (method_id == 0) { | ||
| var typeName = await proxy.sdbHelper.GetTypeName(sessionId, typeId[0], token); | ||
| throw new Exception($"Method '{methodName}' not found in type '{typeName}'"); | ||
| } | ||
| var command_params_obj = new MemoryStream(); | ||
|
||
| var command_params_obj_writer = new MonoBinaryWriter(command_params_obj); | ||
| command_params_obj_writer.WriteObj(objectId, proxy.sdbHelper); | ||
| if (method.ArgumentList != null) | ||
| { | ||
| command_params_obj_writer.Write((int)method.ArgumentList.Arguments.Count); | ||
| foreach (var arg in method.ArgumentList.Arguments) | ||
| { | ||
| if (arg.Expression is LiteralExpressionSyntax) | ||
| { | ||
| if (!await command_params_obj_writer.WriteConst(sessionId, arg.Expression as LiteralExpressionSyntax, proxy.sdbHelper, token)) | ||
| return null; | ||
| } | ||
| if (arg.Expression is IdentifierNameSyntax) | ||
| { | ||
| var argParm = arg.Expression as IdentifierNameSyntax; | ||
| if (!await command_params_obj_writer.WriteJsonValue(sessionId, memberAccessValues[argParm.Identifier.Text], proxy.sdbHelper, token)) | ||
| return null; | ||
| } | ||
| } | ||
| } | ||
| try | ||
thaystg marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| var retMethod = await proxy.sdbHelper.InvokeMethod(sessionId, command_params_obj.ToArray(), method_id, "methodRet", token); | ||
| return await GetValueFromObject(retMethod, token); | ||
| } | ||
| catch (Exception) | ||
| { | ||
| throw new Exception($"Unable to evaluate method '{methodName}'"); | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.