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

SubstitutePath doesn't work well when debugging remotely #3265

Closed
tttoad opened this issue Feb 2, 2023 · 13 comments
Closed

SubstitutePath doesn't work well when debugging remotely #3265

tttoad opened this issue Feb 2, 2023 · 13 comments
Labels

Comments

@tttoad
Copy link
Contributor

tttoad commented Feb 2, 2023

  1. What version of Delve are you using (dlv version)?
    v1.20.1

  2. What version of Go are you using? (go version)?
    v1.19

  3. What operating system and processor architecture are you using?
    client: MacOS arm64
    server: windows amd64

  4. What did you do?
    Set SubstitutePath value to

{
  "from": "/Users/toad/work",
  "to":"C:\\Users\\toad\\work\\"
}

The client's program in "/Users/toad/work/demo/main.go".
The server's program in "C:\Users\toad\work\demo\main.go".

  1. What did you expect to see?
    "/Users/toad/work/demo/main.go” is changed to "C:\Users\toad\work\demo\main.go" instead of "C:\Users\toad\work\/demo/main.go"
@derekparker
Copy link
Member

If I'm understanding correctly you are trying to replace the local source location with the remote source location, is that right? This is the incorrect way to use the substitute path rule. The source files are read by the client, not the server, so substituting the path to the sources on the remote server will not work.

Please comment if my understanding is incorrect and I can reopen and investigate.

@tttoad
Copy link
Contributor Author

tttoad commented Feb 6, 2023

Not really.
The dlv server is running on a remote windows system.
My project is on the '/Users/toad/work/demo/main.go' directory of my mac system.
This directory was synced to a remote system machine with the path "C:\Users\toad\work\demo\main.go".
I set the value of SubstitutePath when I start the dap client.

{
  "from": "/Users/toad/work",
  "to":"C:\\Users\\toad\\work\\"
}

When I set a breakpoint and start it, the breakpoint does not work.

log:

2023-02-07T02:05:21+08:00 warning layer=rpc Listening for remote connections (connections are not authenticated nor encrypted)
2023-02-07T02:05:21+08:00 debug layer=dap DAP server pid = 16856
2023-02-07T02:05:23+08:00 debug layer=dap DAP connection 1 started
2023-02-07T02:05:23+08:00 debug layer=dap [<- from client]{"seq":0,"type":"request","command":"initialize","arguments":{"clientID":"neovim","clientName":"neovim","adapterID":"nvim-dap","locale":"zh_CN.UTF-8","linesStartAt1":true,"columnsStartAt1":true,"pathFormat":"path","supportsVariableType":true,"supportsRunInTerminalRequest":true,"supportsProgressReporting":true}}
2023-02-07T02:05:23+08:00 debug layer=dap [-> to client]{"seq":0,"type":"response","request_seq":0,"success":true,"command":"initialize","body":{"supportsConfigurationDoneRequest":true,"supportsFunctionBreakpoints":true,"supportsConditionalBreakpoints":true,"supportsEvaluateForHovers":true,"supportsSetVariable":true,"supportsExceptionInfoRequest":true,"supportsDelayedStackTraceLoading":true,"supportsLogPoints":true,"supportsDisassembleRequest":true,"supportsClipboardContext":true,"supportsSteppingGranularity":true,"supportsInstructionBreakpoints":true}}
2023-02-07T02:05:23+08:00 debug layer=dap [<- from client]{"seq":1,"type":"request","command":"launch","arguments":{"program":"C:\\Users\\lx\\work\\demo3\\main.go","outputMode":"remote","substitutePath":[{"from":"\/Users\/toad\/work","to":"C:\\Users\\lx\\work\\"}],"mode":"debug","type":"delve","request":"launch","name":"remote","args":[]}}
2023-02-07T02:05:23+08:00 debug layer=dap parsed launch config: {
        "mode": "debug",
        "program": "C:\\Users\\lx\\work\\demo3\\main.go",
        "outputMode": "remote",
        "backend": "default",
        "stackTraceDepth": 50,
        "substitutePath": [
                {
                        "from": "/Users/toad/work",
                        "to": "C:\\Users\\lx\\work\\"
                }
        ]
}
2023-02-07T02:05:26+08:00 debug layer=dap building from "C:\\Users\\lx\\work\\delve": [go build -o C:\Users\lx\work\delve\__debug_bin.exe -gcflags all=-N -l C:\Users\lx\work\demo3\main.go]
2023-02-07T02:05:26+08:00 debug layer=dap launching binary 'C:\Users\lx\work\delve\__debug_bin.exe' with config: {
        "mode": "debug",
        "program": "C:\\Users\\lx\\work\\demo3\\main.go",
        "cwd": "C:\\Users\\lx\\work\\delve",
        "output": "C:\\Users\\lx\\work\\delve\\__debug_bin.exe",
        "dlvCwd": "C:\\Users\\lx\\work\\delve",
        "outputMode": "remote",
        "backend": "default",
        "stackTraceDepth": 50,
        "substitutePath": [
                {
                        "from": "/Users/toad/work",
                        "to": "C:\\Users\\lx\\work\\"
                }
        ]
}
2023-02-07T02:05:30+08:00 debug layer=dap [-> to client]{"seq":0,"type":"event","event":"initialized"}
2023-02-07T02:05:30+08:00 debug layer=dap [-> to client]{"seq":0,"type":"response","request_seq":1,"success":true,"command":"launch"}
2023-02-07T02:05:30+08:00 debug layer=dap [<- from client]{"seq":2,"type":"request","command":"setBreakpoints","arguments":{"source":{"name":"main.go","path":"/Users/toad/work/demo3/main.go"},"breakpoints":[{"line":13}],"lines":[13]}}
2023-02-07T02:05:30+08:00 debug layer=dap client path=/Users/toad/work/demo3/main.go converted to server path=C:\Users\lx\work\/demo3/main.go

2023-02-07T02:05:30+08:00 debug layer=dap [-> to client]{"seq":0,"type":"response","request_seq":2,"success":true,"command":"setBreakpoints","body":{"breakpoints":[{"verified":false,"message":"could not find file C:\\Users\\lx\\work\\/demo3/main.go"}]}}

I think dlv should convert the path to a path that is recognized by the current system.
/Users/toad/work/demo3/main.go should be converted to C:\Users\lx\work\demo3\main.go

I can provide PR for this.

@tttoad
Copy link
Contributor Author

tttoad commented Feb 16, 2023

@derekparker PTAL.

@derekparker
Copy link
Member

@tttoad where is the source code during compilation? That is what's going to be stored in the binary and what Delve will use to set a breakpoint. If you type sources and get the list of source files used during compilation what paths do you see?

@tttoad
Copy link
Contributor Author

tttoad commented Feb 17, 2023

@derekparker Both Mac and windows.
The client uses nvim-dap to run on mac. It sees the source path as /Users/toad/work/demo3/main.go.So the breakpoint path is "source":{"name":"main.go","path":"/Users/toad/work/demo3/main.go"},"breakpoints":[{"line":13}],"lines":[13]}.
The delve runs on windows. It sees the source path as C:\Users\lx\work\demo3\main.go.So I want to do the path conversion by using the substitutePath configuration.
The delve converts paths with text replacement only, and does not convert other / symbols.(mac and linux use /,, but windows uses \ ).
If you type sources and get the list of source files used during compilation what paths do you see?
It will not be available until I get home.(My windows laptop is at home.

@derekparker
Copy link
Member

@tttoad Ah, ok. I think what you want is to change the substitutePath rule in your DAP launch config rather than in the Delve config. See: https://github.com/golang/vscode-go/blob/master/docs/debugging.md (I know it's not VSCode but vim but I assume nvim-dap has a launch config you can modify?).

@tttoad
Copy link
Contributor Author

tttoad commented Feb 17, 2023

@derekparker
I set the substitutePath configuration correctly.
But it does not work as I expected.

@derekparker
Copy link
Member

Alright, reopening and labeling as a bug, sorry for my misunderstanding. It seems you have configured everything correctly, but the path is not being formatted correctly.

@derekparker
Copy link
Member

@tttoad can you try not using backslahes? Windows should accept forward slash for path separation as well.

@tttoad
Copy link
Contributor Author

tttoad commented Feb 18, 2023

@tttoad can you try not using backslahes? Windows should accept forward slash for path separation as well.

Thank you, it works.

@derekparker
Copy link
Member

@tttoad great, going to close this as resolved then.

@nnarayen
Copy link

nnarayen commented Apr 7, 2023

@tttoad I have a similar issue with nvim-dap running locally on my machine and connecting to dlv running in headless mode on a remote server. Could you provide more detail on how you set up substitutePath correctly on the client side? Thanks!

@tttoad
Copy link
Contributor Author

tttoad commented Apr 8, 2023

If the local project path is /Users/xxx/work/demo/main.go and the remote project path is /root/demo/main.go, then the configuration should look like this:

	substitutePath = {
			{
				from = "/Users/xxx/work"; 
				to = "/root";
			}
		}

Full configuration:

{
		type = 'delve';
		name = 'remote-default';
		request = 'launch';
		mode = "debug";
		program = function()
			return vim.fn.input('Program: ')
		end;
		outputMode = 'remote';
		substitutePath = {
			{
				from = "/Users/toad/work";
				to = "/root";
			}
		},
		args = function()
			local args_string = vim.fn.input('arguments: ')
			-- return vim.split(args_string, " +")
			return util.splitArgs(args_string)
		end
},
{
		type = 'delve';
		name = 'remote';
		request = 'launch';
		mode = "debug";
		program = function()
			return vim.fn.input('Program: ')
		end;
		outputMode = 'remote';
		substitutePath = {
			function()
				local from_to = vim.split(vim.fn.input('localWorkspace/remoteWorkspace:'), " +")
				return {
					from = from_to[1];
					to = from_to[2];
				}
			end;
		},
		args = function()
			local args_string = vim.fn.input('Arguments: ')
			-- return vim.split(args_string, " +")
			return util.splitArgs(args_string)
		end
	}

You can use -log to view dlv's logs.
It displays the result of the conversion.

2023-02-07T02:05:30+08:00 debug layer=dap [<- from client]{"seq":2,"type":"request","command":"setBreakpoints","arguments":{"source":{"name":"main.go","path":"/Users/toad/work/demo3/main.go"},"breakpoints":[{"line":13}],"lines":[13]}}
2023-02-07T02:05:30+08:00 debug layer=dap client path=/Users/toad/work/demo3/main.go converted to server path=C:\Users\lx\work\/demo3/main.go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants