vscode-go icon indicating copy to clipboard operation
vscode-go copied to clipboard

Remote debug with substitutePath in subfolder doesn't seem to work

Open Thiht opened this issue 1 year ago • 0 comments

What version of Go, VS Code & VS Code Go extension are you using?

Version Information
  • Run go version to get version of Go from the VS Code integrated terminal.
    • go version go1.22.6 darwin/arm64
  • Run gopls -v version to get version of Gopls from the VS Code integrated terminal.
Build info
----------
golang.org/x/tools/gopls v0.16.1
    golang.org/x/tools/[email protected] h1:1hO/dCeUvjEYx3V0rVvCtOkwnpEpqS29paE+Jw4dcAc=
    github.com/BurntSushi/[email protected] h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak=
    github.com/google/[email protected] h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
    golang.org/x/exp/[email protected] h1:2O2DON6y3XMJiQRAS1UWU+54aec2uopH3x7MAiqGW6Y=
    golang.org/x/[email protected] h1:5+9lSbEzPSdWkH32vYPBwEpX8KwDbM52Ud9xBUvNlb0=
    golang.org/x/[email protected] h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
    golang.org/x/[email protected] h1:3Wt8mZlbFwG8llny+t18kh7AXxyWePFycXMuVdHxnyM=
    golang.org/x/[email protected] h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
    golang.org/x/[email protected] h1:Kd+Z5Pm6uwYx3T2KEkeHMHUMZxDPb/q6b1m+zEcy62c=
    golang.org/x/[email protected] h1:SP0mPeg2PmGCu03V+61EcQiOjmpri2XijexKdzv8Z1I=
    honnef.co/go/[email protected] h1:9MDAWxMoSnB6QoSqiVr7P5mtkT9pOc1kSxchzPCnqJs=
    mvdan.cc/[email protected] h1:G3QvahNDmpD+Aek/bNOLrFR2XC6ZAdo62dZu65gmwGo=
    mvdan.cc/xurls/[email protected] h1:lyBNOm8Wo71UknhUs4QTFUNNMyxy2JEIaKKo0RWOh+8=
go: go1.23.0
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders.
1.92.2
fee1edb8d6d72a0ddff41e5f71a671c23ed924b9
arm64
  • Check your installed extensions to get the version of the VS Code Go extension

    • v0.42.0
  • Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > Go: Locate Configured Go Tools command.

# Tools Configuration


## Environment

GOBIN: undefined
toolsGopath: 
gopath: /Users/thibaut/go
GOROOT: /opt/homebrew/Cellar/go/1.22.6/libexec
PATH: /opt/homebrew/opt/postgresql@16/bin:/Users/thibaut/.nvm/versions/node/v18.16.0/bin:/Users/thibaut/go/bin:/Users/thibaut/.bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Applications/Wireshark.app/Contents/MacOS

## Tools

	go:	/opt/homebrew/bin/go: go version go1.22.6 darwin/arm64

	gopls:	/Users/thibaut/go/bin/gopls	(version: v0.16.1 built with go: go1.23.0)
	gotests:	/Users/thibaut/go/bin/gotests	(version: v1.6.0 built with go: go1.23.0)
	gomodifytags:	/Users/thibaut/go/bin/gomodifytags	(version: v1.16.0 built with go: go1.23.0)
	impl:	/Users/thibaut/go/bin/impl	(version: v1.1.0 built with go: go1.23.0)
	goplay:	/Users/thibaut/go/bin/goplay	(version: v1.0.0 built with go: go1.23.0)
	dlv:	/Users/thibaut/go/bin/dlv	(version: v1.23.0 built with go: go1.23.0)
	golangci-lint:	/Users/thibaut/go/bin/golangci-lint	(version: v1.60.1 built with go: go1.23.0)

## Go env

Workspace Folder (toaster-examples): /Users/thibaut/Developer/toaster-examples

	GO111MODULE=''
	GOARCH='arm64'
	GOBIN=''
	GOCACHE='/Users/thibaut/Library/Caches/go-build'
	GOENV='/Users/thibaut/Library/Application Support/go/env'
	GOEXE=''
	GOEXPERIMENT=''
	GOFLAGS=''
	GOHOSTARCH='arm64'
	GOHOSTOS='darwin'
	GOINSECURE=''
	GOMODCACHE='/Users/thibaut/go/pkg/mod'
	GONOPROXY=''
	GONOSUMDB=''
	GOOS='darwin'
	GOPATH='/Users/thibaut/go'
	GOPRIVATE=''
	GOPROXY='https://proxy.golang.org,direct'
	GOROOT='/opt/homebrew/Cellar/go/1.22.6/libexec'
	GOSUMDB='sum.golang.org'
	GOTMPDIR=''
	GOTOOLCHAIN='auto'
	GOTOOLDIR='/opt/homebrew/Cellar/go/1.22.6/libexec/pkg/tool/darwin_arm64'
	GOVCS=''
	GOVERSION='go1.22.6'
	GCCGO='gccgo'
	AR='ar'
	CC='cc'
	CXX='c++'
	CGO_ENABLED='1'
	GOMOD='/dev/null'
	GOWORK=''
	CGO_CFLAGS='-O2 -g'
	CGO_CPPFLAGS=''
	CGO_CXXFLAGS='-O2 -g'
	CGO_FFLAGS='-O2 -g'
	CGO_LDFLAGS='-O2 -g'
	PKG_CONFIG='pkg-config'
	GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/g3/11k0dg9j3b12pdbsrrjx89240000gn/T/go-build1101834799=/tmp/go-build -gno-record-gcc-switches -fno-common'

Share the Go related settings you have added/edited

Run Preferences: Open Settings (JSON) command to open your settings.json file. Share all the settings with the go. or ["go"] or gopls prefixes.

  "go.toolsManagement.autoUpdate": true,
  "go.lintTool": "golangci-lint",
  "go.inlayHints.compositeLiteralFields": true,
  "go.inlayHints.parameterNames": true,
  "go.coverOnSingleTest": true,
  "go.coverageDecorator": {
    "coveredGutterStyle": "verticalgreen",
    "uncoveredGutterStyle": "verticalyellow"
  },
  "go.formatTool": "gofumpt",
  "gopls": {
    "ui.navigation.importShortcut": "Definition",
    "ui.documentation.linksInHover": false,
  },

Describe the bug

I'm trying to remote debug a go app running inside a container with delve. It works when my Go files are at the root of my repository, but not if they're in a subfolder.

For reference, I tried to do remote debugging using this example repository: https://github.com/ccampo133/go-docker-alpine-remote-debug/ and it worked fine.

But if I do the following changes in the same repository

Steps to reproduce the behavior:

Clone this repository: https://github.com/ccampo133/go-docker-alpine-remote-debug/

Run it with:

docker build ./ -t debug-example:latest -f Dockerfile

docker run \
    --rm \
    -p 8080:8080 \
    -p 40000:40000 \
    -e REMOTE_DEBUG_PORT=40000 \
    -e REMOTE_DEBUG_PAUSE_ON_START=true \
    debug-example:latest

Create this VSCode config:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Connect to server",
            "type": "go",
            "request": "attach",
            "mode": "remote",
            "port": 40000,
            "host": "127.0.0.1",
        }
    ]
}

You can successfully create breakpoints and make them work.

Now, do the following changes:

mkdir go/
mv Dockerfile go.mod go.sum main.go run.sh go/
cd go

# Re-run

docker build ./ -t debug-example:latest -f Dockerfile

docker run \
    --rm \
    -p 8080:8080 \
    -p 40000:40000 \
    -e REMOTE_DEBUG_PORT=40000 \
    -e REMOTE_DEBUG_PAUSE_ON_START=true \
    debug-example:latest

I tried tons of different configs and can't make breakpoints work.

I added this to the debug settings:

            "substitutePath": [
                {
                    "from": "${workspaceFolder}/go",
                    "to": "/app"
                }
            ],

the remote debug attaches successfully, the breakpoints appear in red in the debug view (not in grey), but the breakpoints never hit.

I suspect the substitutePath doesn't work with subfolders but I have no idea how to verify it :(

Screenshots or recordings

Thiht avatar Aug 27 '24 22:08 Thiht