如何在GDB中调试fork-exec进程的入口点? [英] How to debug the entry-point of fork-exec process in GDB?

查看:114
本文介绍了如何在GDB中调试fork-exec进程的入口点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C linux应用程序(A),它启动时产生另一个进程(P)。当我想像往常一样调试PI启动A时,我使用ddd / gdb连接到P。

当我想调试入口点时出现问题(主开始)P.如果我按照通常的方法将调试器连接到P时已经晚了。我找到的解决方案是在P的主开始插入睡眠,所以我有时间与gdb连接,但这不是一个非常优雅的解决方案。



我也尝试过使用 asm(int $ 3),但似乎没有用。



你知道我能如何解决这个问题吗? (最好不要改变A或P的代码)

解决方案

您应该使用此选项:

  set follow-fork-mode   mode  

其中 mode 父,或<$ c
$ b

要跟随父(这是默认值)使用:

 设置后续分支模式父母

跟随孩子:

 设置follow-fork-mode child 

让调试器每次都问你:

  set follow- fork-mode ask 

所以基本上你会开始将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 asm("int $3") but it doesn't seems to work.

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:

set follow-fork-mode mode

Where mode is one of parent, child or ask.

To follow the parent (this is the default) use:

set follow-fork-mode parent

To follow the child:

set follow-fork-mode child

To have the debugger ask you each time:

set follow-fork-mode ask

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆