Skip to content

Commit

Permalink
[stable] [VM/Debugger] Fix behaviour of ActivationFrame::EvaluateComp…
Browse files Browse the repository at this point in the history
…iledExpression when paused inside a closure

TEST=pkg/vm_service/test/evaluate_inside_closures_test.dart, pkg tryjob

Fixes: #52430
Cherry-pick: https://dart-review.googlesource.com/c/sdk/+/313001
Cherry-pick-request: #53747
Change-Id: Ib3479a0b39377ea20765752fd91fef26e8f46454
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/330248
Reviewed-by: Derek Xu <derekx@google.com>
Commit-Queue: Kevin Chisholm <kevinjchisholm@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
  • Loading branch information
a-siva authored and Commit Queue committed Oct 17, 2023
1 parent 5f1e0c2 commit 1ce0cc8
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 1 deletion.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 3.1.4 -

- Fixes an issue in the Dart VM, users are not being able to see
value of variables while debugging code (issue [#53654]).

[#53654]: https://github.com/dart-lang/sdk/issues/53654

## 3.1.3 - 2023-09-27

This is a patch release that:
Expand Down
92 changes: 92 additions & 0 deletions pkg/vm_service/test/evaluate_inside_closures_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// Regression test for https://dartbug.com/52430.

import 'dart:developer';

import 'package:test/test.dart';
import 'package:vm_service/vm_service.dart';

import 'common/service_test_common.dart';
import 'common/test_helper.dart';

class C {
static int staticField = 12;
int instanceField = 34;

static void staticMethod() {
((int x) {
debugger();
})(56);
}

void instanceMethod() {
((int y) {
debugger();
})(78);
}
}

testMain() {
C c = C();
C.staticMethod();
c.instanceMethod();
}

final tests = <IsolateTest>[
hasStoppedAtBreakpoint,
stoppedAtLine(21),
(VmService service, IsolateRef isolateRef) async {
final isolateId = isolateRef.id!;

final xRef =
await service.evaluateInFrame(isolateId, 0, 'x') as InstanceRef;
expect(xRef.valueAsString, '56');

InstanceRef staticFieldRef = await service.evaluateInFrame(
isolateId, 0, 'staticField += 1') as InstanceRef;
expect(staticFieldRef.valueAsString, '13');
staticFieldRef = await service.evaluateInFrame(isolateId, 0, 'staticField')
as InstanceRef;
expect(staticFieldRef.valueAsString, '13');

// Evaluating 'instanceField' should fail since we are paused in the context
// of a static method.
try {
await service.evaluateInFrame(isolateId, 0, 'instanceField');
fail('Expected RPCError');
} catch (e) {
final rpcError = e as RPCError;
expect(rpcError.code, RPCErrorKind.kExpressionCompilationError.code);
}
},
resumeIsolate,
stoppedAtLine(27),
(VmService service, IsolateRef isolateRef) async {
final isolateId = isolateRef.id!;

final yRef =
await service.evaluateInFrame(isolateId, 0, 'y') as InstanceRef;
expect(yRef.valueAsString, '78');

InstanceRef staticFieldRef = await service.evaluateInFrame(
isolateId, 0, 'staticField += 1') as InstanceRef;
expect(staticFieldRef.valueAsString, '14');
staticFieldRef = await service.evaluateInFrame(isolateId, 0, 'staticField')
as InstanceRef;
expect(staticFieldRef.valueAsString, '14');

InstanceRef instanceFieldRef = await service.evaluateInFrame(
isolateId, 0, 'instanceField += 1') as InstanceRef;
expect(instanceFieldRef.valueAsString, '35');
instanceFieldRef = await service.evaluateInFrame(
isolateId, 0, 'instanceField') as InstanceRef;
expect(instanceFieldRef.valueAsString, '35');
}
];

main([args = const <String>[]]) async =>
runIsolateTests(args, tests, 'evaluate_inside_closures_test.dart',
testeeConcurrent: testMain);
5 changes: 4 additions & 1 deletion runtime/vm/debugger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1084,7 +1084,10 @@ ObjectPtr ActivationFrame::EvaluateCompiledExpression(
const Array& type_definitions,
const Array& arguments,
const TypeArguments& type_arguments) {
if (function().is_static()) {
if (function().IsClosureFunction()) {
return Library::Handle(Library()).EvaluateCompiledExpression(
kernel_buffer, type_definitions, arguments, type_arguments);
} else if (function().is_static()) {
const Class& cls = Class::Handle(function().Owner());
return cls.EvaluateCompiledExpression(kernel_buffer, type_definitions,
arguments, type_arguments);
Expand Down

0 comments on commit 1ce0cc8

Please sign in to comment.