golang / vscode-go

Go extension for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=golang.Go
Other
3.78k stars 727 forks source link

Specify processId When Debugging with dlv-dap #3413

Closed wknclizu closed 3 weeks ago

wknclizu commented 1 month ago

I am encountering an issue when trying to debug my Go application using dlv dap. The process ID is identified, and I have set up port forwarding, but I am still getting an error when starting the debug session.

Here is the relevant part of my launch.json configuration:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Attach to remote process",
            "type": "go",
            "debugAdapter": "dlv-dap",
            "request": "attach",
            "mode": "remote",
            "program": "/usr/local/trpc/bin/api-svr",
            "processId": 14,
            "host": "127.0.0.1",
            "port": 11458,
        }
    ]
}

I have also posted this issue on Stack Overflow with more details: link

hyangah commented 1 month ago

For remote debugging, you need to start a headless delve process on the remote side. https://github.com/golang/vscode-go/wiki/debugging#remote-debugging

wknclizu commented 1 month ago

For remote debugging, you need to start a headless delve process on the remote side. https://github.com/golang/vscode-go/wiki/debugging#remote-debugging

The documentation mentions that there are two options for remote debugging. While the first option, headless delve, is already working correctly for me, I would now like to explore using the second option, delve dap. https://github.com/golang/vscode-go/wiki/debugging#connect-to-delve-dap-with-target-specified-at-client-start-up

hyangah commented 4 weeks ago

The most popular setup is the first option. But you can also use the delve dap too - just be aware of the limitations listed in the doc. I saw some users configure a task that runs a script to launch the dlv dap process remotely and wire it as a prelaunch task of their launch config to workaround the limitation.

findleyr commented 3 weeks ago

Hi, it sounds like this is a question that has been answered, so I'm going to close. Please comment if I'm misunderstanding.