使用 gdb 调试正在运行的守护进程 [英] Debugging a running daemon using gdb
问题描述
我正在开发一个作为守护进程运行的高流量网络 C 服务器应用程序.在某些情况下,应用程序崩溃(总是没有核心).如何使用 gdb 调试正在运行的守护程序以找到生成 SIGSEGV 的位置?
I am developing a high traffic network C server application that runs as a daemon. Under some circumstances, the app crashes (always without core). How I can debug the running daemon with gdb to find the place that generates the SIGSEGV?
解释性说明:
我知道如何使用附加命令将 gdb 附加到正在运行的进程
I know how to attach using gdb to a running process using attach command
附加到进程后,它会停止.如果我运行然后继续",如果程序没有崩溃,gdb 将保持阻塞状态.如果我按 CTRL-C,进程将退出,我无法简单地分离 gdb.
After attaching to the process, it stops. If I run then "continue", gdb remains blocked if the program does not crash. If I press CTRL-C, the process is exiting and I am unable to simply detach gdb.
所以问题是:有没有办法在不卡住 gdb 的情况下继续进程,但如果进程没有崩溃则能够分离?
So the question is: is there a way to continue the process without the gdb being stuck but being able to detach if the process does not crash?
推荐答案
尝试异步模式并continue &":
保存到non-stop.gdb
set target-async on
set pagination off
set non-stop on
然后运行:
$ gdb -x non-top.gdb
(gdb) !pgrep YOUR-DAEMON
1234
(gdb) attach 1234
(gdb) continue -a &
(gdb)
这篇关于使用 gdb 调试正在运行的守护进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!