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

Allow attaching to a process without pausing the execution #245

Closed
dlsniper opened this issue Sep 20, 2015 · 10 comments · Fixed by #1585
Closed

Allow attaching to a process without pausing the execution #245

dlsniper opened this issue Sep 20, 2015 · 10 comments · Fixed by #1585

Comments

@dlsniper
Copy link
Contributor

Sorry, the issue was created too fast :D
Proper description:
Given the following app:

package main

import (
    "fmt"
    "net/http"
)

func handler(w http.ResponseWriter, r *http.Request) {
    fmt.Fprintln(w, "hello")
}

func main() {

    handlers := http.NewServeMux()
    handlers.HandleFunc("/", handler)
    server := &http.Server{Addr: ":8889", Handler: handlers}

    server.ListenAndServe()
}

When I'm doing the following steps:

go build -gcflags "-N -l" -o demo demo.go
./demo &
dlv attach `pgrep demo`

I can observe a pause in execution until I send the continue command to the debugger.

While I do understand that it might be useful to have that functionality, say for example I want to hook up in a staging app that has traffic on it (sample traffic), attaching to its process and having it paused is not ideal (for example I want to set tracepoints rather that breakpoints).

Do you think it would be useful to have an attach --no-pause flag?

@dlsniper dlsniper changed the title Allow attaching to a process without pausing the execution. Allow attaching to a process without pausing the execution Sep 20, 2015
@derekparker
Copy link
Member

I can't see the value of starting an actual debug session without pausing unless you're simply relying on providing an init file (to load breakpoints / tracepoints) and then want to immediately continue execution, which you could do by writing a continue command at the end of the init file.

You can already set tracepoints without stopping the program indefinitely with the trace subcommand, which takes a pid flag.

@luisgarciaalanis
Copy link

@derekparker I run the code in a docker container and remote debug. So for normal development its nice to auto run, then I could click the play button on VSCODE to attach, add a breakpoint and rerun to hit the breakpoint.

it would be quite convinient to be able to do this.

@luisgarciaalanis
Copy link

reflex -s -r '.go$' -- dlv --listen=:5432 debug --headless=true --init <(printf continue)
this does not auto continue :(

aarzilli added a commit to aarzilli/delve that referenced this issue Jun 22, 2018
…lients

This pull request makes several changes to delve to allow headless
instancess that are started with the --accept-multiclient flag to
keep running even if there is no connected client. Specifically:

1. Makes a headless instance started with --accept-multiclient quit
    after one of the clients sends a Detach request (previously they
    would never ever quit, which was a bug).
2. Changes proc/gdbserial and proc/native so that they mark the
    Process as exited after they detach, even if they did not kill the
    process during detach. This prevents bugs such as go-delve#1231 where we
    attempt to manipulate a target process after we detached from it.
3. On non --accept-multiclient instances do not kill the target
    process unless we started it or the client specifically requests
    it (previously if the client did not Detach before closing the
    connection we would kill the target process unconditionally)
4. Add a -c option to the quit command that detaches from the
    headless server after restarting the target.
5. Change terminal so that, when attached to --accept-multiclient,
    pressing ^C will prompt the user to either disconnect from the
    server or pause the target process. Also extend the exit prompt to
    ask if the user wants to keep the headless server running.

Implements go-delve#245, go-delve#952, go-delve#1159, go-delve#1231
aarzilli added a commit to aarzilli/delve that referenced this issue Jun 22, 2018
…lients

This pull request makes several changes to delve to allow headless
instancess that are started with the --accept-multiclient flag to
keep running even if there is no connected client. Specifically:

1. Makes a headless instance started with --accept-multiclient quit
    after one of the clients sends a Detach request (previously they
    would never ever quit, which was a bug).
2. Changes proc/gdbserial and proc/native so that they mark the
    Process as exited after they detach, even if they did not kill the
    process during detach. This prevents bugs such as go-delve#1231 where we
    attempt to manipulate a target process after we detached from it.
3. On non --accept-multiclient instances do not kill the target
    process unless we started it or the client specifically requests
    it (previously if the client did not Detach before closing the
    connection we would kill the target process unconditionally)
4. Add a -c option to the quit command that detaches from the
    headless server after restarting the target.
5. Change terminal so that, when attached to --accept-multiclient,
    pressing ^C will prompt the user to either disconnect from the
    server or pause the target process. Also extend the exit prompt to
    ask if the user wants to keep the headless server running.

Implements go-delve#245, go-delve#952, go-delve#1159, go-delve#1231
aarzilli added a commit to aarzilli/delve that referenced this issue Jun 26, 2018
…lients

This pull request makes several changes to delve to allow headless
instancess that are started with the --accept-multiclient flag to
keep running even if there is no connected client. Specifically:

1. Makes a headless instance started with --accept-multiclient quit
    after one of the clients sends a Detach request (previously they
    would never ever quit, which was a bug).
2. Changes proc/gdbserial and proc/native so that they mark the
    Process as exited after they detach, even if they did not kill the
    process during detach. This prevents bugs such as go-delve#1231 where we
    attempt to manipulate a target process after we detached from it.
3. On non --accept-multiclient instances do not kill the target
    process unless we started it or the client specifically requests
    it (previously if the client did not Detach before closing the
    connection we would kill the target process unconditionally)
4. Add a -c option to the quit command that detaches from the
    headless server after restarting the target.
5. Change terminal so that, when attached to --accept-multiclient,
    pressing ^C will prompt the user to either disconnect from the
    server or pause the target process. Also extend the exit prompt to
    ask if the user wants to keep the headless server running.

Implements go-delve#245, go-delve#952, go-delve#1159, go-delve#1231
derekparker pushed a commit that referenced this issue Jun 26, 2018
…lients

This pull request makes several changes to delve to allow headless
instancess that are started with the --accept-multiclient flag to
keep running even if there is no connected client. Specifically:

1. Makes a headless instance started with --accept-multiclient quit
    after one of the clients sends a Detach request (previously they
    would never ever quit, which was a bug).
2. Changes proc/gdbserial and proc/native so that they mark the
    Process as exited after they detach, even if they did not kill the
    process during detach. This prevents bugs such as #1231 where we
    attempt to manipulate a target process after we detached from it.
3. On non --accept-multiclient instances do not kill the target
    process unless we started it or the client specifically requests
    it (previously if the client did not Detach before closing the
    connection we would kill the target process unconditionally)
4. Add a -c option to the quit command that detaches from the
    headless server after restarting the target.
5. Change terminal so that, when attached to --accept-multiclient,
    pressing ^C will prompt the user to either disconnect from the
    server or pause the target process. Also extend the exit prompt to
    ask if the user wants to keep the headless server running.

Implements #245, #952, #1159, #1231
@aarzilli
Copy link
Member

Closed by 9a21621

@dlsniper
Copy link
Contributor Author

@aarzilli I read the changelog of the commit that closed this but I'm not sure how to use delve to do it (and I haven't tried it yet either). Is the original reported case possible now? Thank you.

@aarzilli
Copy link
Member

aarzilli commented Jun 27, 2018

--init <(echo continue) does it for normal instances (that don't have the --headless flag). For headless instances invoke dlv a second time like this: dlv --init <(echo "exit -c") connect ...

@gm42
Copy link

gm42 commented Oct 29, 2018

In case of --headless the --init gets ignored with the following message in output:

Warning: init file ignored

Thus a separate client connection is needed to start the process; this is not container friendly and some hack is needed to trigger the operation externally.

@hypnoce
Copy link

hypnoce commented May 27, 2019

I'm not sure if this problem is solved, but in some scenarios it can be nice to start a go binary with delve without pausing the execution, like running java with suspend=n.
Do you see any value into this ?

@derekparker
Copy link
Member

I'm going to reopen this as it technically is not fixed, we currently just support a workaround.

@derekparker derekparker reopened this May 31, 2019
@briandealwis
Copy link
Contributor

Having a no-suspend option is useful for debugging go-based microservices in containers.

cgxxv pushed a commit to cgxxv/delve that referenced this issue Mar 25, 2022
…lients

This pull request makes several changes to delve to allow headless
instancess that are started with the --accept-multiclient flag to
keep running even if there is no connected client. Specifically:

1. Makes a headless instance started with --accept-multiclient quit
    after one of the clients sends a Detach request (previously they
    would never ever quit, which was a bug).
2. Changes proc/gdbserial and proc/native so that they mark the
    Process as exited after they detach, even if they did not kill the
    process during detach. This prevents bugs such as go-delve#1231 where we
    attempt to manipulate a target process after we detached from it.
3. On non --accept-multiclient instances do not kill the target
    process unless we started it or the client specifically requests
    it (previously if the client did not Detach before closing the
    connection we would kill the target process unconditionally)
4. Add a -c option to the quit command that detaches from the
    headless server after restarting the target.
5. Change terminal so that, when attached to --accept-multiclient,
    pressing ^C will prompt the user to either disconnect from the
    server or pause the target process. Also extend the exit prompt to
    ask if the user wants to keep the headless server running.

Implements go-delve#245, go-delve#952, go-delve#1159, go-delve#1231
abner-chenc pushed a commit to loongson/delve that referenced this issue Mar 1, 2024
…lients

This pull request makes several changes to delve to allow headless
instancess that are started with the --accept-multiclient flag to
keep running even if there is no connected client. Specifically:

1. Makes a headless instance started with --accept-multiclient quit
    after one of the clients sends a Detach request (previously they
    would never ever quit, which was a bug).
2. Changes proc/gdbserial and proc/native so that they mark the
    Process as exited after they detach, even if they did not kill the
    process during detach. This prevents bugs such as go-delve#1231 where we
    attempt to manipulate a target process after we detached from it.
3. On non --accept-multiclient instances do not kill the target
    process unless we started it or the client specifically requests
    it (previously if the client did not Detach before closing the
    connection we would kill the target process unconditionally)
4. Add a -c option to the quit command that detaches from the
    headless server after restarting the target.
5. Change terminal so that, when attached to --accept-multiclient,
    pressing ^C will prompt the user to either disconnect from the
    server or pause the target process. Also extend the exit prompt to
    ask if the user wants to keep the headless server running.

Implements go-delve#245, go-delve#952, go-delve#1159, go-delve#1231
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants