且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

gdb 附加到进程而不停止

更新时间:2023-09-30 15:38:10

你不能让它不停.但是,您可以立即继续...创建一个简单的批处理脚本,该脚本将附加到特定进程并在附加后立即继续执行:

gdb attach $1 -x 

./附加PID

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.

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