From ec59f65100d741539b00e308294cc53f04fc326b Mon Sep 17 00:00:00 2001 From: Ankit Jain Date: Sat, 22 Aug 2020 14:34:59 -0400 Subject: [PATCH] [wasm][debugger] Fix expression evaluation when it is a reference (#41135) * [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();` - which is incorrect, and we need to return `memberAccessValues[0]`, which is the value itself. --- .../BrowserDebugProxy/EvaluateExpression.cs | 5 ++- .../wasm/debugger/BrowserDebugProxy/MonoProxy.cs | 2 +- .../DebuggerTestSuite/EvaluateOnCallFrameTests.cs | 43 +++++++++++++--------- 3 files changed, 30 insertions(+), 20 deletions(-) diff --git a/src/mono/wasm/debugger/BrowserDebugProxy/EvaluateExpression.cs b/src/mono/wasm/debugger/BrowserDebugProxy/EvaluateExpression.cs index 8d43bda..f863a3c 100644 --- a/src/mono/wasm/debugger/BrowserDebugProxy/EvaluateExpression.cs +++ b/src/mono/wasm/debugger/BrowserDebugProxy/EvaluateExpression.cs @@ -213,6 +213,7 @@ namespace Microsoft.WebAssembly.Diagnostics internal static async Task CompileAndRunTheExpression(string expression, MemberReferenceResolver resolver, CancellationToken token) { + expression = expression.Trim(); SyntaxTree syntaxTree = CSharpSyntaxTree.ParseText(@" using System; public class CompileAndRunTheExpression @@ -245,10 +246,10 @@ namespace Microsoft.WebAssembly.Diagnostics 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(); + return memberAccessValues[0]; } var identifierValues = await ResolveIdentifiers(findVarNMethodCall.identifiers, resolver, token); diff --git a/src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs b/src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs index afd7d96..1ecd6ee 100644 --- a/src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs +++ b/src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs @@ -700,7 +700,7 @@ namespace Microsoft.WebAssembly.Diagnostics } else { - SendResponse(msg_id, Result.Err($"Unable to evaluate {expression}"), token); + SendResponse(msg_id, Result.Err($"Unable to evaluate '{expression}'"), token); } } catch (ReturnAsErrorException ree) diff --git a/src/mono/wasm/debugger/DebuggerTestSuite/EvaluateOnCallFrameTests.cs b/src/mono/wasm/debugger/DebuggerTestSuite/EvaluateOnCallFrameTests.cs index 8721810..14da2b0 100644 --- a/src/mono/wasm/debugger/DebuggerTestSuite/EvaluateOnCallFrameTests.cs +++ b/src/mono/wasm/debugger/DebuggerTestSuite/EvaluateOnCallFrameTests.cs @@ -49,22 +49,26 @@ namespace DebuggerTests 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] @@ -104,12 +108,15 @@ namespace DebuggerTests 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] @@ -212,8 +219,10 @@ namespace DebuggerTests // "((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)), -- 2.7.4