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

"Global evaluation is not supported", possible regression #52574

Closed
techvx opened this issue May 31, 2023 · 7 comments
Closed

"Global evaluation is not supported", possible regression #52574

techvx opened this issue May 31, 2023 · 7 comments
Assignees
Labels
area-pkg Used for miscellaneous pkg/ packages not associated with specific area- teams. pkg-dds For issues related to the Dart Development Service

Comments

@techvx
Copy link

techvx commented May 31, 2023

Updating via flutter upgrade to the latest version breaks the ability to inspect global variables - in VS Code, at least. Impossible to inspect any global state outside of the immediate local scope even when the execution is paused, i.g. at a breakpoint, either.

The minimal example from the thread of 5 years ago when the feature appears to have been first discussed:

image

Fails with "global evaluation is not supported".

Possibly related to #52430 and #4555.

Downgrading to Flutter 3.7.6 / Dart 2.19.3 solves the issue.

Will experiment with other attempts to upgrade and reproducible examples of my own, when I find the time.

flutter doctor

[√] Flutter (Channel stable, 3.7.6, on Microsoft Windows [Version 10.0.19045.2965], locale en-US)
[√] Windows Version (Installed version of Windows is version 10 or higher)
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[√] Chrome - develop for the web
[√] Visual Studio - develop for Windows (Visual Studio Community 2019 16.11.21)
[√] Android Studio (version 4.2)
[√] Connected device (3 available)
[√] HTTP Host Availability

• No issues found!

flutter --version

Flutter 3.7.6 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 12cb4eb7a0 (3 months ago) • 2023-03-01 10:29:26 -0800
Engine • revision ada363ee93
Tools • Dart 2.19.3 • DevTools 2.20.1

@stevemessick stevemessick added the area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. label May 31, 2023
@a-siva
Copy link
Contributor

a-siva commented May 31, 2023

This example seems to work fine in devtools, I am able to print the value of counter when stopped at a breakpoint inside the while loop. Haven't tried with VS code.

@bkonyi
Copy link
Contributor

bkonyi commented May 31, 2023

cc @DanTup

@derekxu16
Copy link
Member

derekxu16 commented May 31, 2023

I am seeing the issue on the latest stable channel release of Flutter (3.10.2) when debugging with VSCode.

@a-siva a-siva added pkg-dds For issues related to the Dart Development Service and removed area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. vm-debugger labels May 31, 2023
@DanTup
Copy link
Collaborator

DanTup commented May 31, 2023

Impossible to inspect any global state outside of the immediate local scope even when the execution is paused

Do you see this with your example above? I can reproduce "Global evaluation is not supported" when not paused, but using the example above and being paused I can evaluate count:

Screenshot 2023-05-31 at 19 44 51

There are two known (but distinct) issues I can reproduce:

1. In the latest SDKs, some variables cannot be evaluated and show "OptimizedOut"

There's an issue about that at #52430. I think that might be a VM issue as it occurs in both legacy and SDK debug adapters (although how the error appears is slightly different)

2. Global evaluation is not supported (that is, you cannot evaluate expressions if execution is not paused)

This has never been properly supported, but in the legacy debug adapters there were some hacks to try and make it work for some cases. We would pick an arbitrary isolate and its root library (eg. lib/main.dart) and evaluate the expression in that context. This would work for some expressions, but not others. This hack was not reproduced in the new SDK debug adapters - the hope was to implement this in a better way (allowing you to choose which script/isolate the expression is being evaluated in the context of) but it requires some changes in VS Code.

We could consider implementing the same behaviour in the new SDK DAPs, although I'm not sure how useful it really is outside of single-file scripts/trivial apps, as I don't think you'd be able to access most of the globals you want.

FWIW, if you're using the new debug adapters, Globals will now show up in the Variables pane alongside Locals, which might provide some of the value of global evaluation.

Edit: In the short-term, if you want to force yourself back on to the legacy debug adapters you can add this to your VS Code settings - but be aware that these debug adapters won't necessarily be updated with future language features and in some future update they might not be available.

"dart.previewSdkDaps": false

@lrhn lrhn added the area-pkg Used for miscellaneous pkg/ packages not associated with specific area- teams. label May 31, 2023
@techvx
Copy link
Author

techvx commented Jun 1, 2023

Do you see this with your example above?

The standalone loop in the main.dart does allow to inspect the count both in the globals panel and the debug console itself, when paused / during a breakpoint.

Details

image

An actual widget tree only allows for the inspection of local global variables:

Details

image

Referring to them during any other breakpoint, however, is a futile endeavour:

Details

image

Those hacks - in whatever way they had been implemented - were, are, and will be needed for a long time.

That single exposed root isolate kept things flexible enough to allow setups of this kind:

Code

final debug = Debugger();

void main() {
  final scope = Reactor(
    child: const App(),
    debugger: debug,
  );
  runApp(scope);
}

...

class Debugger {

  late final WidgetState? state;

  void link(WidgetState state) {
    this.state = state;
  }

  call(String i) => state.inspect(i);
}

These expose and bring to light any relevant state through a simple debug("inspectable"), which can easily be made into debug.inspectable as well - without any tedious lookups through the whole Widget Details Tree.

Even when a value-holding InheritedWidget or Provider (which not every state management solution is based on) is there to look into, inspecting a large List or a nested tree of Maps and Sets without getting lost is virtually impossible.

And this is just one use case I stumbled upon while putting together a few of my own ideas.

@DanTup
Copy link
Collaborator

DanTup commented Jun 1, 2023

I think there's some confusion between two different issues. Supporting "global evaluation" in the new debug adapters in the same way as the old one will not resolve any issues where you're seeing "" or are paused at a breakpoint. Those evaluation errors are a different issue being tracked in #52430 (which I'm less familiar with as they're from the VM).

You can check this using the setting noted above. Setting "dart.previewSdkDaps": false will force you back onto the legacy debug adapters which will support "global evaluation" (in the limited way described above), but won't resolve the other issue (eg. inside build methods when at breakpoints) - which I suspect is the one you probably care about most.

I'll have a look at handling global evaluation in the same way for now, but to avoid confusion let's keep these two issues separate - this one specifically for where you see "Global evaluation is not supported" errors, and #52430 for failures like "OptimizedOut" when executing is paused and evaluating is failing.

copybara-service bot pushed a commit that referenced this issue Jul 11, 2023
This provides support for basic global evaluation matching the legacy DAPs. The first available thread is used (because there's currently no way for the user to select a thread) and we look up a library from a file URI provided in the `context` field.

In future I hope there's a standard DAP way of getting a file from the client (see microsoft/vscode#134452).

See #52574
See Dart-Code/Dart-Code#4636

Change-Id: I7bfa466001142e7e39ebb270ce65f4746a9affcd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/312980
Commit-Queue: Ben Konyi <bkonyi@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
@DanTup
Copy link
Collaborator

DanTup commented Jul 11, 2023

I've pushed some changes to the new debug adapters (80a6670) and Dart-Code (Dart-Code/Dart-Code@7389b2c) to add some basic global eval support.

It works similar to the legacy DAPs (picking the first available isolate), but it does use your current open file as the target (instead of just the root library as the legacy DAP did).

You'll need both the SDK change and the VS Code extension change for this to work. We'll need some VS Code changes (microsoft/vscode#134452) to be implemented to allow you to select which isolate to evaluate in - but I suspect for the majority of cases the one we pick automatically will be sufficient.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-pkg Used for miscellaneous pkg/ packages not associated with specific area- teams. pkg-dds For issues related to the Dart Development Service
Projects
None yet
Development

No branches or pull requests

7 participants