Search code examples
cgdbeclipse-cdtzabbixgdbinit

How to configure GDB in Eclipse such that all prcoesses keep on running including the process being debugged?


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:

debug configuration

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:

gdbinit file content

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.

enter image description here

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

Thanks in advance.


Solution

  • 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

    enter image description here

    enter image description here

    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. :)