Chris G.
Chris G.

Reputation: 25984

How to remote debug with Delve debugger in Visual Studio Code

I have already asked, and got a very good answer for debugging locally with delve(golang debugger).

Now I am trying to remote debug with Delve using VS Code.

I have got a sample app mentioned here, and further github linked to source code here. Note: The debug project is in a branch called debugging.

Are you able to make it work?

I have also created/opened an issue in the repo.

Upvotes: 4

Views: 3584

Answers (2)

hmmftg
hmmftg

Reputation: 1754

To remotely debug a go project in 2025 here is the updated solution, I assume you got ssh access to your server and your source code is on server:

Based on your server restrictions if:

  1. Remote server has internet(easy)
  • open vscode locally and install Remote - SSH extension
  • now on welcome page choose Connect to...
  • add your server to list and connect to it(enter user password if you didn't save your ssh key)
  • it takes time to download and prepare the server(for me it took nearly 30 minutes because of low internet speed)
  • finally you'll be able to remotely open vscode on server
  • install go extension on vscode
  • install golang on remote server
  • open a folder containing golang project sources(this will trigger gopls and dlv and other tools to be installed on remote machine)
  • now you can run, attach and debug just as local development env.
  1. Remote server has no internet(harder but possible)
  • follow above steps until install golang, do it with downloading golang binary and scp to your server and follow install instructions on go download page
  • if your local os is linux tar you local /usr/local/go/bin folder and scp to server, else download precompiled binaries of gopls dlv errcheck gofmt golangci-lint and any binary which is needed by extension
  • now you can open your project and gopls and dlv should be working

Upvotes: 0

Chris G.
Chris G.

Reputation: 25984

The following worked:

  1. Remove line 3 in launch.json "debugServer": 4711,"
  2. Changed line 29 in launch.json ""host": "192.168.99.100" // Docker IP " to "127.0.0.1".

I was sure I tried this before, but apparently not bout at the same time. Anyways happy go' lucky!

Upvotes: 5

Related Questions