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

`substitutePath` with forward slashes on Windows breaks remote debugging

Open sibber5 opened this issue 4 months 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.24.5 windows/amd64
  • Run gopls -v version to get version of Gopls from the VS Code integrated terminal.
    • golang.org/x/tools/gopls v0.20.0
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders.
    • 1.102.3 (488a1f239235055e34e673291fb8d8c810886f81) (x64)
  • Check your installed extensions to get the version of the VS Code Go extension
    • 0.48.0
  • Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > Go: Locate Configured Go Tools command.

Tools Configuration

Environment

GOBIN: undefined toolsGopath: gopath: C:\Users<user>\go GOROOT: C:\Program Files\Go PATH: C:\Program Files\Go\bin;C:\Users<user>\go\bin;other things

Tools`

go:	C:\Program Files\Go\bin\go.exe: go version go1.24.5 windows/amd64

gopls:	C:\Users\<user>\go\bin\gopls.exe	(version: v0.20.0 built with go: go1.24.5)
gotests:	not installed
impl:	not installed
goplay:	not installed
dlv:	C:\Users\<user>\go\bin\dlv.exe	(version: v1.25.1 built with go: go1.24.5)
staticcheck:	C:\Users\<user>\go\bin\staticcheck.exe	(version: v0.6.1 built with go: go1.24.5)

Go env

Workspace Folder (api): x:\source\repos\go-kc-sample\api

set AR=ar
set CC=gcc
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_ENABLED=0
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set CXX=g++
set GCCGO=gccgo
set GO111MODULE=
set GOAMD64=v1
set GOARCH=amd64
set GOAUTH=netrc
set GOBIN=
set GOCACHE=C:\Users\<user>\AppData\Local\go-build
set GOCACHEPROG=
set GODEBUG=
set GOENV=C:\Users\<user>\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFIPS140=off
set GOFLAGS=
set GOGCCFLAGS=-m64 -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=C:\Users\<user>\AppData\Local\Temp\go-build2970870649=/tmp/go-build -gno-record-gcc-switches
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMOD=x:\source\repos\go-kc-sample\api\go.mod
set GOMODCACHE=C:\Users\<user>\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\<user>\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTELEMETRY=local
set GOTELEMETRYDIR=C:\Users\<user>\AppData\Roaming\go\telemetry
set GOTMPDIR=
set GOTOOLCHAIN=auto
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.24.5
set GOWORK=
set PKG_CONFIG=pkg-config

Share the Go related settings you have added/edited

None

Describe the bug

On Windows, using substitutePath with forward slashes, or ${workspaceFolder} which seems to also use forward slashes on windows, in launch.json breaks remote debugging.

Steps to reproduce the behavior:

Assuming the path to your project/workspace is D:\source\myproject

  1. Run dlv debug --headless --listen=:4081 --log (arbitrary port) on a linux machine or container
  2. Configure remote debugging in launch.json, using substiturePath and map from ${workspaceFolder}:
{
    "name": "Connect to Docker",
    "type": "go",
    "request": "attach",
    "mode": "remote",
    "port": 4081,
    "host": "127.0.0.1",
    "substitutePath": [
        {
            "from": "${workspaceFolder}",
            "to": "/app"
        }
    ]
}
  1. Start debugging and put a breakpoint in any file, hover your mouse over it and you will see could not find file D:\source\myproject\path\to\file.go

NOTE: using "remotePath": "/app" instead of substitutePath causes the same issue.

However, when you change ${workspaceFolder} to the actual path, assuming its D:\source\myproject as stated earlier, and use backslashes in the path: "from": "D:\\source\\myproject" then remote debugging works. if you use the exact same path (not ${workspaceFolder}) but with forward slashes instead of backslashes then you can the same issue as before ("from": "D:/source/myproject")

Screenshots or recordings

If applicable, add screenshots or recordings to help explain your problem.

sibber5 avatar Aug 07 '25 02:08 sibber5