This is the mail archive of the gdb@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Can not switch processes after a process exits


Hello!

I have the following problem:

I debug the following code:

 1 #include <sys/wait.h>
 2 #include <stdlib.h>
 3 #include <unistd.h>
 4 #include <stdio.h>
 5
 6 int main(void)
 7 {
 8      pid_t pids[10];
 9      int i, n=2;
10
11 	 printf("Enter number of processes \n");
12      for (i = n; i >= 0; --i) {
13          pids[i] = fork();
14                 if (pids[i] == 0) {
15                     sleep(i+1);
16                     _exit(0);
17                 }
18      }
19
20      for (i = n; i >= 0; --i)
21            waitpid(pids[i], NULL, 0);
22
23      return 0;
24 }


(gdb) set target-async on
(gdb) set detach-on-fork off
(gdb) b main
Breakpoint 1 at 0x80484de: file zombie.c, line 9.
(gdb) r

I step the first process with step& until I get to line 21. At that
moment there are
4 threads in gdb session. Say I switch to thread 2. Step it with step&
until it gets to
line 16 and exits. After this I can not switch to any of the remaining threads.

(gdb) thread 1
Thread ID 1 not known.
(gdb) thread 3
Thread ID 3 not known.
(gdb) thread 4
Thread ID 4 not known.

Info inferiors says:
  Num  Description       Executable
  4    process 4056
/home/sasha/share/facultet/diploma/inspectos/examples/zombie/zombie
  3    process 4055
/home/sasha/share/facultet/diploma/inspectos/examples/zombie/zombie
* 2    <null>
/home/sasha/share/facultet/diploma/inspectos/examples/zombie/zombie
  1    process 4045
/home/sasha/share/facultet/diploma/inspectos/examples/zombie/zombie

If I switch to an inferior it says:
(gdb) inferior 3
[Switching to inferior 3 [process 4055]
(/home/sasha/share/facultet/diploma/inspectos/examples/zombie/zombie)]
Inferior has no threads.


Is this a bug? Or am I doing something wrong?

Thanks a lot,
Alex.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]