Skip to content

Commit

Permalink
[wasm][debugger] Fix expression evaluation when it is a reference (#4…
Browse files Browse the repository at this point in the history
…1135)

* [wasm][debugger] Fix expression evaluation when it is a reference

.. preceded by spaces. Eg: `"  foo.dateTime", or `"  foo.count"`

* Explanation of the fix:

- these particular expressions end up in the code path where we get a
SimpleMemberAccessExpression, and only one member access (like `a.b.c`)
was found.

- that code path had
    `return memberAccessValues[0]?["value"]?.Value<JObject>();`

  - which is incorrect, and we need to return `memberAccessValues[0]`,
  which is the value itself.
  • Loading branch information
radical authored Aug 22, 2020
1 parent 9f75120 commit ec59f65
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ private static async Task<IList<JObject>> ResolveIdentifiers(IEnumerable<Identif

internal static async Task<JObject> CompileAndRunTheExpression(string expression, MemberReferenceResolver resolver, CancellationToken token)
{
expression = expression.Trim();
SyntaxTree syntaxTree = CSharpSyntaxTree.ParseText(@"
using System;
public class CompileAndRunTheExpression
Expand Down Expand Up @@ -245,10 +246,10 @@ public static object Evaluate()

var memberAccessValues = await ResolveMemberAccessExpressions(findVarNMethodCall.memberAccesses, resolver, token);

// this.dateTime
// eg. "this.dateTime", " dateTime.TimeOfDay"
if (expressionTree.Kind() == SyntaxKind.SimpleMemberAccessExpression && findVarNMethodCall.memberAccesses.Count == 1)
{
return memberAccessValues[0]?["value"]?.Value<JObject>();
return memberAccessValues[0];
}

var identifierValues = await ResolveIdentifiers(findVarNMethodCall.identifiers, resolver, token);
Expand Down
2 changes: 1 addition & 1 deletion src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ async Task<bool> OnEvaluateOnCallFrame(MessageId msg_id, int scope_id, string ex
}
else
{
SendResponse(msg_id, Result.Err($"Unable to evaluate {expression}"), token);
SendResponse(msg_id, Result.Err($"Unable to evaluate '{expression}'"), token);
}
}
catch (ReturnAsErrorException ree)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,26 @@ public async Task EvaluateTypeInstanceMembers(string prefix, int bias, string ty
var dateTime = new DateTime(2010, 9, 8, 7, 6, 5 + bias);
var DTProp = dateTime.AddMinutes(10);

await EvaluateOnCallFrameAndCheck(id,
(prefix + "a", TNumber(4)),

// fields
(prefix + "dateTime.TimeOfDay", TValueType("System.TimeSpan", dateTime.TimeOfDay.ToString())),
(prefix + "dateTime", TDateTime(dateTime)),
(prefix + "dateTime.TimeOfDay.Minutes", TNumber(dateTime.TimeOfDay.Minutes)),

// properties
(prefix + "DTProp.TimeOfDay.Minutes", TNumber(DTProp.TimeOfDay.Minutes)),
(prefix + "DTProp", TDateTime(DTProp)),
(prefix + "DTProp.TimeOfDay", TValueType("System.TimeSpan", DTProp.TimeOfDay.ToString())),

(prefix + "IntProp", TNumber(9)),
(prefix + "NullIfAIsNotZero", TObject("DebuggerTests.EvaluateTestsClassWithProperties", is_null: true))
);
foreach (var pad in new[] { String.Empty, " " })
{
var padded_prefix = pad + prefix;
await EvaluateOnCallFrameAndCheck(id,
($"{padded_prefix}a", TNumber(4)),

// fields
($"{padded_prefix}dateTime.TimeOfDay", TValueType("System.TimeSpan", dateTime.TimeOfDay.ToString())),
($"{padded_prefix}dateTime", TDateTime(dateTime)),
($"{padded_prefix}dateTime.TimeOfDay.Minutes", TNumber(dateTime.TimeOfDay.Minutes)),

// properties
($"{padded_prefix}DTProp.TimeOfDay.Minutes", TNumber(DTProp.TimeOfDay.Minutes)),
($"{padded_prefix}DTProp", TDateTime(DTProp)),
($"{padded_prefix}DTProp.TimeOfDay", TValueType("System.TimeSpan", DTProp.TimeOfDay.ToString())),

($"{padded_prefix}IntProp", TNumber(9)),
($"{padded_prefix}NullIfAIsNotZero", TObject("DebuggerTests.EvaluateTestsClassWithProperties", is_null: true))
);
}
});

[Theory]
Expand Down Expand Up @@ -104,12 +108,15 @@ public async Task EvaluateMethodLocals(string type, string method, string bp_fun
var dt = new DateTime(2025, 3, 5, 7, 9, 11);
await EvaluateOnCallFrameAndCheck(id,
("d", TNumber(401)),
(" d", TNumber(401)),
("e", TNumber(402)),
("f", TNumber(403)),

// property on a local
("local_dt", TDateTime(dt)),
("local_dt.Date", TDateTime(dt.Date)));
(" local_dt", TDateTime(dt)),
("local_dt.Date", TDateTime(dt.Date)),
(" local_dt.Date", TDateTime(dt.Date)));
});

[Fact]
Expand Down Expand Up @@ -212,8 +219,10 @@ await EvaluateOnCallFrameAndCheck(id,
// "((dt))", TObject("foo")); //FIXME:

("this", TObject("DebuggerTests.EvaluateTestsClass.TestEvaluate")),
(" this", TObject("DebuggerTests.EvaluateTestsClass.TestEvaluate")),

("5", TNumber(5)),
(" 5", TNumber(5)),
("d + e", TNumber(203)),
("e + 10", TNumber(112)),

Expand Down

0 comments on commit ec59f65

Please sign in to comment.