如何调试叉EXEC过程的入口点? [英] How to debug the entry-point of fork-exec process?

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

问题描述

我有产卵,当它启动另一个进程(P)是C Linux应用程序(A)。当我要调试P I一开始像往常一样,我和DDD / GDB为P连接。

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.

问题出现时,我要调试P的入口点(主要的开始)。如果我按照通常的做法,当我在调试器连接到P是已到晚期。我找到的解决方案是在主磷的开头插入一个睡觉,所以我有时间使用gdb连接,但这并不是一个很优雅的解决方案。

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.

我已经使用 ASM(INT $ 3)也尝试过,但似乎并不工作。

I've also tried using asm("int $3") but it doesn't seems to work.

你有什么想法,我怎么能解决这个问题? (preferably不改变A或P的code)

Do you have any idea how I could solve this problem? (preferably without altering the code of A or P)

推荐答案

您应该使用此选项:

set follow-fork-mode mode

其中的模式的是孩子问。

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

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

set follow-fork-mode parent

要遵循孩子:

set follow-fork-mode child

要具备调试器问你每次:

To have the debugger ask you each time:

set follow-fork-mode ask

所以基本上你会开始了GDB连接到A,然后设置GDB跟随孩子,然后当A产卵P,广发行将连接到P和从A分离。

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.

这篇关于如何调试叉EXEC过程的入口点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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