golang / vscode-go

Go extension for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=golang.Go
Other
3.89k stars 753 forks source link

Improve automated path mapping in dlv debug adapter #3193

Open suzmue opened 8 months ago

suzmue commented 8 months ago

Is your feature request related to a problem? Please describe.

The legacy debug adapter implemented some support for automatic path mapping (#45). We want to deprecate the legacy debug adapter so should provide some automatic path mapping, which will likely take a different form than the legacy.

dlv dap uses the substitutePath setting in the launch.json attributes to configure mappings when the local and debugger paths do not match (such as with symlinked dirs, remote debugging, trimpath).

A lot of times users don’t know that they have to provide path mapping for the breakpoints to hit. Even if they do, they don’t provide the correct path mappings. So what happens is that the debugger appears to be running but no breakpoints are hit. This can cause a lot of confusion to the users.

Describe the solution you'd like We can use the local configuration of the main modules, module cache, and GOROOT, to help automate this configuration.

This will need implementation work in github.com/go-delve/delve to do the mapping and modifications to the extension to provide the necessary data from the client.

Additional context Related issues include #3175, #45

gm0stache commented 8 months ago

-> related? https://github.com/golang/vscode-go/issues/3096

hyangah commented 8 months ago

@suzmue Things seem complicated if Windows or case-insensitive OS is involved, since VS Code (DAP client) uses the absolute file paths instead of file uri or relative paths. In this case, I think we need more than Delve's substitutePath.

dlipovetsky commented 2 months ago

This will need implementation work in github.com/go-delve/delve to do the mapping and modifications to the extension to provide the necessary data from the client.

Can you please elaborate on this? Does delve need to support the supportsLoadedSourcesRequest DAP capability?

I would like to help implement this, but am looking for some more context.

(I suppose the legacy implementation is not possible with DAP? As far as I understand it, the legacy implementation sends the sources command to the delve server. The delve server responds with a list of paths stored in the target executable debug info. Vscode-go then uses this list, together with information about local source paths, to generate a set of substitute paths, and submit them to the server using the config substitute-path command.)