pmverma
pmverma

Reputation: 1703

How to attach a process in eclipse for debugging of muiti-process program

As my title say, I am having trouble in debugging my source code which is multi-process program. This is as following: 1. The program is written to be daemon process, so the parent/main process is a daemon process. 2. It forks a number of child processes, around 5 to 7 or 8 process.

I use eclipse to develop my code, and I want to debug my program from eclipse. As far as I tried, the debugger does not know the breakpoints from child process.

Thus I would like to know, Is there any option available by which I can debug my program, including child processes? Is there any setting in eclipse by which I can attach the child pid so that debugger switch to that child process?

Such as, assume child pids 4523, 4562, 5462.Then during debug time, can I attach debugger to 5462 ?

Thanks in advance.

Upvotes: 2

Views: 1730

Answers (1)

Pavel Davydov
Pavel Davydov

Reputation: 3569

See the gdb follow-fork-mode setting. With this option you can control gdb behavior when the process forks. You can set it from gdb console

gdb> set follow-fork-mode child

So in fork gdb will switch to the child process. Another possible value here is to follow parent. If you want to debug them both from one gdb session, use this option:

gdb> set detach-on-fork off

This will make the debugger open a new inferior for the child process. Later you can switch between them like this:

gdb> inferior 1

Another way to do this is just to attach to a new process from another gdb session.

Update: I always use gdb from console, so I don't know if there any gdb settings in eclipse, maybe someone else will help you with gui options. If you have a gdb console in eclipse, you can try this commands there.

Update 2: see this link about gdb fork options.

Upvotes: 4

Related Questions