如何在Eclipse中配置GDB,使所有程序包继续运行,包括正在调试的进程? [英] How to configure GDB in Eclipse such that all prcoesses keep on running including the process being debugged?

查看:218
本文介绍了如何在Eclipse中配置GDB,使所有程序包继续运行,包括正在调试的进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是C编程新手,我一直在努力根据自己的组织需要定制一个用C语言编写的开源工具。

IDE:Eclipse,
调试器:GDB,
操作系统:RHEL



该工具本质上是多进程的(主进程首次执行并使用fork生成多个子进程)),它们在运行时共享值。
在Eclipse中调试时(使用GDB),我发现正在调试的进程只在其他进程处于挂起模式时运行。因此,唯一正在运行的进程无法执行其预期的工作,因为其他进程已暂停。



我在某处看到,在GDB中使用MI命令作为停止可以使其他进程运行。我在gdbinit文件中使用了相同的命令: debug configuration>

注意:我已经用另一个gdbinit覆盖了上面的.gdbinit文件,因为.gdbinit不会让我调试子进程,因为调试器在执行主进程。

但不幸的是调试器在使用此命令后停止响应。



请参阅下面的命令I我在gdbinit文件中使用:





注释不间断使Eclipse能够继续对当前进程进行常规调试。



添加:您可以在下图中看到,只有一个进程正在运行,而其他进程正在运行,而其他进程正在运行。





任何人都可以帮我配置GDB ac按照我的要求吗?



在此先感谢您。 确定@nm:其实,你是对的。我应该有更多时间来了解代码的流程。
该工具首先创建3个进程,然后第三个进程创建5个线程,并继续等待()任何子线程终止。


$ b $ p

下图中显示的前5个线程(以蓝色突出显示)是线程,它们是进程ID的子进程:17991



< img src =https://i.stack.imgur.com/qhYHl.pngalt =在这里输入图片描述>



启动工具的基本功能,因此他们只是等待退出(0)。您可以在下面看到。



pre $ if(0!=(pid = zbx_fork()))
exit(0) ;

setsid();

信号(SIGHUP,SIG_IGN);

if(0!=(pid = zbx_fork()))
exit(0);

这就是我实际上没有能力参与这三个过程的原因。每当我试图这样做,整个主进程立即终止,并因此导致终止所有其他进程。
所以,我了解到我应该只进入线程。是的,实际上我现在可以调试:)

这可以实现,因为我必须删除MI命令set follow-fork-mode child。所以,我只使用了默认的.gdbinit文件,并启用了自动调试分叉进程。



感谢大家的意见。 Stackoverflow是一个很好的学习和分享的地方。 :)

I am new in C programming and I have been trying hard to customize an opensource tool written in C according to my organizational needs.

IDE: Eclipse, Debugger: GDB, OS: RHEL

The tool is multi-process in nature (main process executes first time and spawns several child processes using fork() ) and they share values in run time. While debugging in Eclipse (using GDB), I find that the process being debugged is only running while other processes are in suspended mode. Thus, the only running process is not able to do its intended job because the other processes are suspended.

I saw somewhere that using MI command in GDB as "set non-stop on" could make other processes running. I used the same command in the gdbinit file shown below:

Note: I have overridden above .gdbinit file with an another gdbinit because the .gdbinit is not letting me to debug child processes as debugger terminates after the execution of main process.

But unfortunately debugger stops responding after using this command.

Please see below commands I am using in the gdbinit file:

Commenting non-stop enables Eclipse to continue usual debugging of the current process.

Adding: You can see in below image that only one process is running while others are suspended.

Can anyone please help me to configure GDB according to my requirement?

Thanks in advance.

解决方案

OK @n.m.: Actually, You were right. I should have given more time to understand the flow of the code. The tool creates 3 processes first and then the third process creates 5 threads and keeps on wait() for any child thread to terminate.

Top 5 threads (highlighted in blue) shown in the below image are threads and they are children of Process ID: 17991

The first two processes are intended to initiate basic functionality of the tool and hence they just wait to get exit(0). You can see below.

if (0 != (pid = zbx_fork()))
        exit(0);

    setsid(); 

    signal(SIGHUP, SIG_IGN);

    if (0 != (pid = zbx_fork()))
        exit(0);

That was the reason I was not actually able to step in these 3 processes. Whenever, I tried to do so, the whole main process terminated immediately and consequently leaded to terminate all other processes. So, I learned that I was supposed to "step-into" threads only. And yes, actually I can now debug :)

And this could be achieved because I had to remove the MI command "set follow-fork-mode child". So, I just used the default " .gdbinit" file with enabled "Automatically debug forked process".

Thanks everyone for your input. Stackoverflow is an awesome place to learn and share. :)

这篇关于如何在Eclipse中配置GDB,使所有程序包继续运行,包括正在调试的进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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