How to exit dlv connected to a headless server without killing remote process
Asked Answered
D

1

7

This question is about remote debugging of golang code using the delve debugger. Specifically, how to disconnect the client debugger without killing the remote process.

I run a process inside a docker container that needs to be debugged. The process is started in the docker's entrypoint via dlv debug /go/src/path/to/package --headless --listen=:2345 --log

The docker container is started via docker run --rm -it -p 2345:2345 my_image:tag

From my workstation I connect to the delve headless server via

$dlv connect :2345
Type 'help' for list of commands.
(dlv)

At that point I do some debugging. When I'm done I'd like the ability to disconnect from the headless server without killing the process being debugged.

(dlv) exit

Unfortunately the above command disconnects the delve client from the headless server and also kills the remote process I was debugging, and since that was the docker container's entrypoint, the container stops. I'd like to avoid disconnecting from killing the remote process, how?

I've looked at the arguments to (dlv) exit, and cannot see one that would help.

(dlv) help exit
Exit the debugger.

        exit [-c]

When connected to a headless instance started with the --accept-multiclient, pass -c to resume the execution of the target process before disconnecting.
(dlv) exit -c
Command failed: not connected to an --accept-multiclient server
Daytoday answered 8/1, 2020 at 18:37 Comment(0)
M
0

Start delve with the following args:

dlv debug /go/src/path/to/package --headless --listen=:2345 --log --continue --accept-multiclient

This will continue the debugged process on start and allow you to use exit -c from a delve client. Ensure you clear any breakpoints otherwise your process will get stuck.

Source: https://github.com/go-delve/delve/issues/2324#issuecomment-1024700094

Marlinmarline answered 10/11, 2022 at 19:0 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.