|
Home > Archive > Unix Programming > February 2006 > how to debug forked child in eclipse CDT
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
how to debug forked child in eclipse CDT
|
|
| metaosp 2006-02-17, 10:40 pm |
| Hi, how can I set break point in forked child code using eclipse CDT
with gdb? For example, in the following code:
int main() {
pid_t PID = fork();
if (PID>0) {
cout << "parent proc" << endl; // break point works
....
} else {
cout << "child proc" << endl; // break point doesn't work
....
}
}
I also tried step by step from the beginning but the child process ran
away right after fork(). I'm using Eclipse 3.1.2.
Thanks,
--
Metaosp
| |
| Paul Pluzhnikov 2006-02-17, 10:40 pm |
| metaosp <metaosp@gmail.com> writes:
> Hi, how can I set break point in forked child code using eclipse CDT
> with gdb?
(gdb) help set follow-fork-mode
Set debugger response to a program call of fork or vfork.
A fork or vfork creates a new process. follow-fork-mode can be:
parent - the original process is debugged after a fork
child - the new process is debugged after a fork
The unfollowed process will continue to run.
By default, the debugger will follow the parent process.
However, I have had mixed experience with this: it works on some
platform/gdb-version combinations, but not others.
Another alternative:
> int main() {
> pid_t PID = fork();
> if (PID>0) {
> cout << "parent proc" << endl; // break point works
> ....
> } else {
> cout << "child proc" << endl; // break point doesn't work
cout << "child proc " << getpid() << " waiting for debugger" << endl;
while (true) {
sleep(1);
}
> ....
> }
> }
With the code above, the child will wait until you attach with a
debugger (from another window) and manually "make it go" with gdb
"jump line-after-loop" command.
Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.
|
|
|
|
|