Skip to content
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] Implement Runtime.evaluate. #62142

Merged
merged 1 commit into from
Nov 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ internal static async Task<JObject> CompileAndRunTheExpression(string expression
expression = expression.Trim();
if (!expression.StartsWith('('))
{
expression = "(" + expression + ")";
expression = "(" + expression + "\n)";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this just for readability?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No! The code that VS tries to evaluate is like I added in the test case.
Something like this:
15 //evaluate from VS
So I added this \n to avoid to comment the ")".

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add that as a code comment here? And maybe a \n before the expression too?

}
SyntaxTree syntaxTree = CSharpSyntaxTree.ParseText(expression + @";", cancellationToken: token);

Expand Down
12 changes: 11 additions & 1 deletion src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,17 @@ protected override async Task<bool> AcceptCommand(MessageId id, string method, J
{
return await Step(id, StepKind.Over, token);
}

case "Runtime.evaluate":
{
if (context.CallStack != null)
{
Frame scope = context.CallStack.First<Frame>();
return await OnEvaluateOnCallFrame(id,
scope.Id,
args?["expression"]?.Value<string>(), token);
Comment on lines +406 to +411
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

super-nit:

Suggested change
if (context.CallStack != null)
{
Frame scope = context.CallStack.First<Frame>();
return await OnEvaluateOnCallFrame(id,
scope.Id,
args?["expression"]?.Value<string>(), token);
if (context.CallStack?.Length > 0)
{
return await OnEvaluateOnCallFrame(id,
context.CallStack[0].Id,
args?["expression"]?.Value<string>(), token);

}
break;
}
case "Debugger.evaluateOnCallFrame":
{
if (!DotnetObjectId.TryParse(args?["callFrameId"], out DotnetObjectId objectId))
Expand Down
31 changes: 31 additions & 0 deletions src/mono/wasm/debugger/DebuggerTestSuite/DebuggerTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,37 @@ internal async Task<JToken> GetProperties(string id, JToken fn_args = null, bool
return (null, res);
}

internal async Task RuntimeEvaluateAndCheck(params (string expression, JObject expected)[] args)
{
foreach (var arg in args)
{
var (eval_val, _) = await RuntimeEvaluate(arg.expression);
try
{
await CheckValue(eval_val, arg.expected, arg.expression);
}
catch
{
Console.WriteLine($"CheckValue failed for {arg.expression}. Expected: {arg.expected}, vs {eval_val}");
throw;
}
}
}
internal async Task<(JToken, Result)> RuntimeEvaluate(string expression, bool expect_ok = true)
{
var evaluate_req = JObject.FromObject(new
{
expression = expression
});

var res = await cli.SendCommand("Runtime.evaluate", evaluate_req, token);
AssertEqual(expect_ok, res.IsOk, $"Runtime.evaluate ('{expression}') returned {res.IsOk} instead of {expect_ok}, with Result: {res}");
if (res.IsOk)
return (res.Value["result"], res);

return (null, res);
}

internal async Task<(JToken, Result)> SetVariableValueOnCallFrame(JObject parms, bool expect_ok = true)
{
var res = await cli.SendCommand("Debugger.setVariableValue", parms, token);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,20 @@ await EvaluateOnCallFrameFail(id,
(" str", "ReferenceError")
);
});

[Fact]
public async Task EvaluateConstantValueUsingRuntimeEvaluate() => await CheckInspectLocalsAtBreakpointSite(
"DebuggerTests.EvaluateTestsClass", "EvaluateLocals", 9, "EvaluateLocals",
"window.setTimeout(function() { invoke_static_method ('[debugger-test] DebuggerTests.EvaluateTestsClass:EvaluateLocals'); })",
wait_for_event_fn: async (pause_location) =>
{
var dt = new DateTime(2020, 1, 2, 3, 4, 5);
await RuntimeEvaluateAndCheck(
("15\n//comment as vs does\n", TNumber(15)),
("15", TNumber(15)),
("\"15\"\n//comment as vs does\n", TString("15")),
("\"15\"", TString("15")));
});

}

Expand Down