Skip to content

locspec.SubstitutePath doesn't convert path separators between systems (Windows/Linux) #3447

Closed
@bavis-m

Description

  1. What version of Delve are you using (dlv version)?
    1.21.0 (both in golang docker and windows)

  2. What version of Go are you using? (go version)?
    go version go1.20.6 linux/amd64 (building in docker with golang)
    go version go1.20.6 windows/amd64 (connecting to debugger from vs code)

  3. What operating system and processor architecture are you using?
    VS Code in Windows 10, amd64
    golang docker image, linux amd64

  4. What did you do?
    Debugging a linux go executable from windows can't set breakpoints, as locspec.SubstitutePath doesn't correctly convert path separators between systems

Relevant .vscode/launch.json snippet:

"substitutePath": [
  {"from":"C:\\some\\repo"}, "to":"/go/src/github.com/some/repo/"}
]

dlv output:
2023-07-20T05:57:40Z debug layer=dap client path=c:\some\repo\folder\file.go converted to server path=/go/src/github.com/some/repo\folder\file.go

Followed by an error: 2023-07-20T06:14:28Z debug layer=dap [-> to client]{"seq":0,"type":"response","request_seq":7,"success":true,"command":"setBreakpoints","body":{"breakpoints":[{"verified":false,"message":"could not find file /go/src/github.com/some/repo\\folder\\file.go"}]}}

  1. What did you expect to see?
    The converted path should be /go/src/github.com/some/repo/folder/file.go (with the backslash from suffix part of the client path, \folder\file.go translated to the appropriate path separator for the dlv server system)

I've verified that this test patch, which just always uses backslash path separators in SubstitutePath does cause breakpoints to start working again:

diff --git a/pkg/locspec/locations.go b/pkg/locspec/locations.go
index 92d83181..dd3ac741 100644
--- a/pkg/locspec/locations.go
+++ b/pkg/locspec/locations.go
@@ -510,6 +510,9 @@ func hasPathSeparatorPrefix(path string) bool {

 // SubstitutePath applies the specified path substitution rules to path.
 func SubstitutePath(path string, rules [][2]string) string {
+    return strings.Replace(SubstitutePathInternal(path, rules), "\\", "/", -1)
+}
+func SubstitutePathInternal(path string, rules [][2]string) string {
     // Look for evidence that we are dealing with windows somewhere, if we are use case-insensitive matching
     caseInsensitive := windowsAbsPath(path)
     if !caseInsensitive {
  1. What did you see instead?
    See error reports above

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions