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

debug: breakpoints don't work when working with symlink #622

Closed
hyangah opened this issue Sep 8, 2020 · 9 comments
Closed

debug: breakpoints don't work when working with symlink #622

hyangah opened this issue Sep 8, 2020 · 9 comments
Labels
Debug Issues related to the debugging functionality of the extension. Documentation FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
Milestone

Comments

@hyangah
Copy link
Contributor

hyangah commented Sep 8, 2020

Continuation of microsoft/vscode-go#2958 (lost during repo migration) and microsoft/vscode-go#1935. If we can't find a fix, we need to document this problem at least.

cc @suzmue @quoctruong

From microsoft/vscode-go#2958:

It is a continuation of an issue #1935

Unfortunately, the conversation there was locked to members only, so I had to open this card.

I have been able to reproduce the behavior (VSCode does not stop at breakpoints, while dlv itself does) for the symlinked GOPATH on two separate Ubuntu 19.10 installations, and I am pretty sure the issue is reproducible in other distros this way as well.

Set up to reproduce:

  1. Install go via package manager (both apt and snap work, mainly tested with snap, version go1.13.5 linux/amd64)
  2. Create a future GOPATH as ~/go
  3. Add GOPATH to your ~/.bashrc:
export GOPATH=`builtin cd ~/go && pwd`
export PATH=$PATH:$GOPATH/bin
  1. Create/clone a project folder in ~/go/src/github.com/<your_github_name>/<your_repo_name>
  2. Symlink ~/go/src/github.com to ~/GitHub
  3. Set up Go support for VSCode just as it is recommended in the guide, or follow the UI recommendations & install all the libraries it now wants
  4. Create a trivial main.go to try out the breakpoints:
package main

import "fmt"

func main() {
	fmt.Println("Hello World!")
	i := 101
	fmt.Println(i)
}

Reproducing

  • If you open ~/go/src/github.com/<your_github_name>/<your_repo_name> folder and set a breakpoint at i := 101, the execution would be successfully paused at it.
  • However, if you open ~/GitHub/<your_github_name>/<your_repo_name> folder and set the breakpoint, it will never be hit.
    No launch configuration was created, all default - debug was in both cases launched just by a press of F5.

Unfortunately, I have not been able to take a look inside the debugger yet, but at least this reproduction scenario might be helpful

@hyangah hyangah added Documentation Debug Issues related to the debugging functionality of the extension. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Sep 8, 2020
@suzmue
Copy link
Contributor

suzmue commented Sep 10, 2020

Logs from reproducing this on darwin:

...
[15:47:50.706 UTC] LaunchRequest
[15:47:50.715 UTC] Using GOPATH: /Users/suzmue/go
[15:47:50.715 UTC] Using GOROOT: /Users/suzmue/sdk/go1.15.2
[15:47:50.716 UTC] Current working directory: /Users/suzmue/Github/suzmue/restart
...
[15:47:53.490 UTC] From client: setBreakpoints({"source":{"name":"main.go","path":"/Users/suzmue/Github/suzmue/restart/main.go"},"lines":[6],"breakpoints":[{"line":6}],"sourceModified":false})
[15:47:53.490 UTC] SetBreakPointsRequest
[15:47:53.872 UTC] All cleared
[15:47:53.872 UTC] Creating on: /Users/suzmue/Github/suzmue/restart/main.go:6
[15:47:53.873 UTC] Error on CreateBreakpoint: could not find file /Users/suzmue/Github/suzmue/restart/main.go
...

Delve does not attempt to resolve symlinks (delve#1808) so when the extension passes a path within ~/Github, it fails to set the breakpoint (since the files used to build the program were actually in ~/go/src/github.com). To fix this we probably need to resolve the path ourselves before passing to delve or use the delve config suggested in delve#1808 (config substitute-path <symlink-dir> <original-dir>). It also seems like passing a relative path to program instead of an absolute path could fix this problem as well.

@hyangah
Copy link
Contributor Author

hyangah commented Sep 10, 2020

I think config substitute-path belongs to the dlv cli. (@polinasok can you please correct me if I am wrong). If true, that
implies this path resolution should be done on our side. Is it possible to swap with the resolved path from src/goDebugConfiguration.ts?

@hyangah hyangah added this to Needs triage in Debug Sep 17, 2020
@hyangah hyangah moved this from Needs triage to High priority in Debug Sep 21, 2020
@polinasok
Copy link
Contributor

polinasok commented Sep 24, 2020

Yes config command is part of the interactive dlv cli and is fully handled in the terminal frontend. I don't think we have a way of doing this interactively, do we? But we could support upfront session-long substitution via launch.json (like when config file is used with dlv). This would be similar to how we approach the functionality of (dlv) config max-string-len 100 with dlvLoadConfig.maxStringLen, which supplies values to the args of the RPC commands that we issue on variables and evaluate requests.

@gopherbot
Copy link
Collaborator

Change https://golang.org/cl/257204 mentions this issue: docs/debugging.md: document lack of symlink support

gopherbot pushed a commit that referenced this issue Sep 25, 2020
This change documents the fact that this extension
does not support debugging symlinked projects.

Updates #622

Change-Id: Iffc3bfb0438a84cc3afbb6aadd00df040b83c14b
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/257204
Trust: Suzy Mueller <suzmue@golang.org>
Run-TryBot: Suzy Mueller <suzmue@golang.org>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Polina Sokolova <polina@google.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
@suzmue
Copy link
Contributor

suzmue commented Oct 26, 2020

We plan to address this issue by providing a user configuration to map directories to each other. This would allow users to specify to and the debug adapter would translate all paths that it sends to delve and receives from delve.

This will not attempt to resolve symlinked paths, but should make debugging more usable for users that are debugging symlinked directories.

@suzmue suzmue moved this from High priority to In progress in Debug Oct 30, 2020
@gopherbot
Copy link
Collaborator

Change https://golang.org/cl/270017 mentions this issue: src/debugAdapter: add substitutePath config for debugging

gopherbot pushed a commit that referenced this issue Dec 11, 2020
This change adds a new configuration option to both launch and
attach requests. substituePath takes an array that maps from string to string
that is used to translate paths passed to the debugger and then
back to the client.

This allows users to translate their symlinked directories to the
files that were actually used to build the binary. In addition this
can also be used for remote debugging, and when the location of the
files has moved since the program was built.

Update #622

Change-Id: I71b081d17a29655c14cd20093dc9f88867fbcc69
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/270017
Trust: Suzy Mueller <suzmue@golang.org>
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
Run-TryBot: Suzy Mueller <suzmue@golang.org>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Polina Sokolova <polina@google.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
@gopherbot
Copy link
Collaborator

Change https://golang.org/cl/277961 mentions this issue: test: remove symlink tests for substitutePath

gopherbot pushed a commit that referenced this issue Dec 14, 2020
Although these tests do work right now, they depend on the implementation
of the go command in a way I do not fully understand. The rest of the tests
are sufficient to test the substitutePath implementation as opposed to
how symlinks are interpreted by go or dlv. substitutePath may not be necessary
for all symlinked projects.

For example, when running on darwin:
$ ls ~/go/src/github.com/user/package
 main.go

$ ln -s ~/go/src/github.com/user ~/githubuser/
$ cd ~/githubuser/package; dlv debug
(dlv) sources
~/go/src/github.com/user/package/main.go

If a go.mod file is added into the package in the GOPATH:

$ ls ~/go/src/github.com/user/package
 main.go
 go.mod
$ ln -s ~/go/src/github.com/user ~/githubuser/
$ cd ~/githubuser/package; dlv debug
(dlv) sources
~/githubuser/package/main.go

Updates #622

Change-Id: Ie9893ac3cdcac3a8efcda95056dca6df271a85bd
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/277961
Trust: Suzy Mueller <suzmue@golang.org>
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
Run-TryBot: Suzy Mueller <suzmue@golang.org>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
@hyangah
Copy link
Contributor Author

hyangah commented Dec 16, 2020

@suzmue Do we need anything more to close this issue?

@hyangah hyangah added this to the v0.20.0 milestone Dec 16, 2020
@suzmue
Copy link
Contributor

suzmue commented Jan 5, 2021

The substitutePath configuration will allow users to configure their projects so they can link from symlinked directories. For more information see the documentation.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Debug Issues related to the debugging functionality of the extension. Documentation FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
No open projects
Debug
  
Closed
Development

No branches or pull requests

4 participants