如何在GDB中调试fork-exec进程的入口点? [英] How to debug the entry-point of fork-exec process in GDB?
问题描述
我有一个C linux应用程序(A),它启动时产生另一个进程(P)。当我想像往常一样调试PI启动A时,我使用ddd / gdb连接到P。
当我想调试入口点时出现问题(主开始)P.如果我按照通常的方法将调试器连接到P时已经晚了。我找到的解决方案是在P的主开始插入睡眠,所以我有时间与gdb连接,但这不是一个非常优雅的解决方案。
我也尝试过使用 asm(int $ 3)
,但似乎没有用。
你知道我能如何解决这个问题吗? (最好不要改变A或P的代码)
您应该使用此选项:
set follow-fork-mode
mode
其中 mode 是 要跟随父(这是默认值)使用: 跟随孩子: 让调试器每次都问你: 所以基本上你会开始将gdb连接到A,然后设置gdb孩子,然后当A产生P时,gdb将连接到P并从A分离。 I have a C linux application (A) that spawns another process (P) when it is started. When I want to debug P I start A as usual and I connect with ddd/gdb to P. Problems appear when I want to debug the entry-point (start of main) of P. If I follow the usual approach when I connect the debugger to P is already to late. The solution I've found was to insert a sleep at the begining of the main of P so I have time to connect with gdb but this is not a very elegant solution. I've also tried using Do you have any idea how I could solve this problem? (preferably without altering the code of A or P) You should use this option: Where mode is one of To follow the parent (this is the default) use: To follow the child: To have the debugger ask you each time: So basically you'd start out connecting gdb to A, then set gdb to follow the child, and then when A spawns P, gdb will connect to P and detach from A. 这篇关于如何在GDB中调试fork-exec进程的入口点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!父,
子
或<$ c
$ b
设置后续分支模式父母
设置follow-fork-mode child
set follow- fork-mode ask
asm("int $3")
but it doesn't seems to work.set follow-fork-mode
modeparent
, child
or ask
.set follow-fork-mode parent
set follow-fork-mode child
set follow-fork-mode ask