Post by Roman MashakHello, Maxim!
MY> Reading info gdb "4.10 Debugging programs with multiple processes"
MY> might help you.
MY> See follow-fork-mode
Thanks for reply, I checked through the documentation, but setting
'follow-fork-mode' didn't work for me, may be problem is version of GDB
(it's 5.3post-0.20021129.18rh) ? I still can't follow the child's code
It may be your gdb.
I compiled it
$ g++ -Wall -ggdb -c exp.cpp -o exp.o
and run
$ gdb exp
Current directory is /home/max/src/exp/
GNU gdb Red Hat Linux (6.3.0.0-1.21rh)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and
you are
welcome to change it and/or distribute copies of it under certain
conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for
details.
This GDB was configured as "i386-redhat-linux-gnu"...Using host
libthread_db library "/lib/libthread_db.so.1".
(gdb) l main
3 #include <unistd.h>
4 #include <stdio.h>
5 #include <stdlib.h>
6
7
8 int main(void)
9 {
10 int pid; /* process PID */
11 int child, parent;
12 int status;
(gdb)
13
14
15 /* create new process to handle client */
16 if ( (pid = fork()) == -1 ) {
17 perror("fork() error");
18 exit(1);
19 }
20
21
22 /* here is child process running */
(gdb)
23 if (pid == 0) {
24 printf("child process, pid=%d ppid=%d\n", getpid(), getppid());
25 int i;
26 while (i) {
27 fprintf( stdout, "i=%d\n",(i == 100000) ? i-- : i++ );
28 }
29 exit(10);
30 }
31
32
(gdb) show follow-fork-mode
Debugger response to a program call of fork or vfork is "parent".
(gdb) set follow-fork-mode child
(gdb) b 24
Breakpoint 1 at 0x8048610: file exp.cpp, line 24.
(gdb) r
Starting program: /home/max/src/exp/exp
Reading symbols from shared object read from target memory...done.
Loaded system supplied DSO at 0xa42000
Attaching after fork to child process 9999.
[Switching to process 9999]
Breakpoint 1, main () at exp.cpp:24
(gdb) q
The program is running. Exit anyway? (y or n) y
Debugger finished