dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.26k stars 1.58k forks source link

Provide a vmservice method for getting the package config url for an isolate(group) #56784

Open sigurdm opened 1 month ago

sigurdm commented 1 month ago

There seems to be no such method yet

Currently devtools is jumping through a lot of hoops to do this. It looks for package configs from the library containing the main file of the current root isolate.

This is not always correct (the main file might be exported from an imported package)

Also finding the .dart_tool/package_config.json via the dtd protocol is also troublesome, given that it has limited file access (cannot reach files outside the IDE root, which is not guaranteed to contain the package config if the ide is scoped to only parts of a pub workspace.)

Here is the current code:

https://github.com/flutter/devtools/blob/b77c98038700521c4b6da9183fd356674bd42a1a/packages/devtools_shared/lib/src/utils/file_utils.dart#L31

dart-github-bot commented 1 month ago

Summary: The vmservice API lacks a method to retrieve the package configuration URL for an isolate, forcing devtools to use workarounds that are unreliable and limited by file access restrictions. This issue proposes adding such a method for improved accuracy and reliability.

mkustermann commented 1 month ago

The concept of a package root may not actually exist. For example if an App was AOT compiled and run on the VM in AOT mode there's no source code anymore, no package dependencies, just an AOT-compiled ELF file the VM can run (profile builds are AOT and can also be inspected via vm-service)

Then there's the question if the VM runs on another device (e.g. in android phone) and the code is pushed to it in the form of a kernel file. Then there may also not be a concept of package root anymore (that's a concept on the host device that compiled to kernel).

So the API would only work for a subset of scenarios. We already expose this programmatically via dart:isolates Isolate.packageConfigSync property (which works in those subset of scenarios).

Could one just invoke this getter via vm-service protocol?

sigurdm commented 1 month ago

The concept of a package root may not actually exist.

Good point. I wonder if we need service extensions when debugging aot compiled binaries... I guess we do.

Could one just invoke this getter via vm-service protocol?

Possibly - can we do this while the debugged code is running?

sigurdm commented 1 month ago

Maybe the dtd protocol should be the one providing this...

sigurdm commented 1 month ago

cc @kenzieschmoll

sigurdm commented 1 month ago

In debugging an aot binary, can we resolve package-uris? Is the package config baked in, or is it stored separately somewhere? Maybe it would make sense for aot-compiled binaries to hold on to the packageConfigUri (when not stripped) as it was during compilation.

a-siva commented 1 month ago

//cc @bkonyi (something to look into for VM service)