Reputation: 8797
Everytime I attach to a process using gdb, it will stop the target program, and I need to type 'cont' to let it go. Is there a way to attach to a process without stopping it? This makes things easier if the process will behave differently if it stops for a while.
Upvotes: 33
Views: 30498
Reputation: 11
Here is a unified command for recent versions of GDB that include debuginfod
support (also see a related question). Without this additional step, it was still hanging my remote terminal, which was hard to detect while I was attempting to debug a window-manager issue. In this example, <BINARY-NAME>
is the process binary name, in case you don't know/don't want to find the PID.
echo 'set debuginfod enabled on' >> ~/.gdbinit
gdb -iex "set pagination off" -q -ex cont -p $(pidof <BINARY-NAME>)
Upvotes: 1
Reputation: 1162
For when you don't know the PID of the process...
gdb attach $(pgrep -f myApp) -ex cont
Upvotes: 3
Reputation: 1546
You can't make it not stop. You can however instantly continue... Create a simple batch script which will attach to a specific process and instantly continuing execution after attaching:
gdb attach $1 -x <(echo "cont")
./attach PID
Upvotes: 15
Reputation: 2643
I know there is already a fine answer for this, but I prefer not using an additional file.
Here is another answer:
gdb attach $(pidof process_name) -ex cont
Upvotes: 48