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]

re-run of program does not kill all inferiors


 If I re-run a program that forks multiple processes only main process
is getting terminated. All the other children continue to execute together
with a new main program and new children as nothing happened. I am setting
the following:

(gdb) set target-async on
(gdb) set detach-on-fork off
(gdb) set non-stop on

Is this a normal behavior related to multi-process support? Here is
an example:

nenad@screamer[152]% cat t.c
#include <stdio.h>

int gate = 1;

main()
{
  if (fork())
    {
      printf ("parent\n");
      if (fork()) printf ("parent\n");
      else  printf ("child 2\n");
    }
  else
      printf ("child 1\n");
  while (gate) sleep (1);

printf ("done\n");
}
nenad@screamer[153]% gdb t
GNU gdb (GDB) 7.2.50.20100729-cvs
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-unknown-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /a/gdb/gdb-cvs/wrk/gdb/t...done.
(gdb) set target-async on
(gdb) set detach-on-fork off
(gdb) set non-stop on
(gdb) r&
Starting program: /a/gdb/gdb-cvs/wrk/gdb/t
(gdb) [New process 22763]
parent
child 1
[New process 22764]
parent
child 2
interrupt -a
(gdb)
[process 22764] #3 stopped.
0x0000003d50ca6a50 in __nanosleep_nocancel () from /lib64/libc.so.6


[process 22763] #2 stopped.
0x0000003d50ca6a50 in __nanosleep_nocancel () from /lib64/libc.so.6

[process 22736] #1 stopped.
0x0000003d50ca6a50 in __nanosleep_nocancel () from /lib64/libc.so.6
(gdb) b 17
Breakpoint 1 at 0x4005b1: file t.c, line 17. (3 locations)
(gdb) thread apply all set gate=0

Thread 3 (process 22764):

Thread 2 (process 22763):

Thread 1 (process 22736):
(gdb) c -a
Continuing.

Breakpoint 1, main () at t.c:17
17      printf ("done\n");
(gdb)
Breakpoint 1, main () at t.c:17
17      printf ("done\n");

Breakpoint 1, main () at t.c:17
17      printf ("done\n");
info threads
  3 process 22764  main () at t.c:17
  2 process 22763  main () at t.c:17
* 1 process 22736  main () at t.c:17
(gdb) info inferiors
  Num  Description       Executable
  3    process 22764     /a/gdb/gdb-cvs/wrk/gdb/t
  2    process 22763     /a/gdb/gdb-cvs/wrk/gdb/t
* 1    process 22736     /a/gdb/gdb-cvs/wrk/gdb/t
(gdb) r&
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program: /a/gdb/gdb-cvs/wrk/gdb/t
(gdb) [New process 22849]
parent
child 1
[New process 22850]
Error in re-setting breakpoint 1: Cannot access memory at address 0x400554
Error in re-setting breakpoint 1: Cannot access memory at address 0x400554
parent
child 2
interrupt -a
(gdb)
[process 22850] #6 stopped.
0x0000003d50ca6a50 in __nanosleep_nocancel () from /lib64/libc.so.6

[process 22849] #5 stopped.
0x0000003d50ca6a50 in __nanosleep_nocancel () from /lib64/libc.so.6

[process 22824] #4 stopped.
0x0000003d50ca6a50 in __nanosleep_nocancel () from /lib64/libc.so.6
info threads
6 process 22850 0x0000003d50ca6a50 in __nanosleep_nocancel () from /lib64/libc.so.6
5 process 22849 0x0000003d50ca6a50 in __nanosleep_nocancel () from /lib64/libc.so.6
* 4 process 22824 0x0000003d50ca6a50 in __nanosleep_nocancel () from /lib64/libc.so.6
3 process 22764 main () at t.c:17
2 process 22763 main () at t.c:17
(gdb)


-------------------

At this point I have two processes from the old run and three new ones. Is it possible to easily
cleanup and terminate all inferiors on re-run?


Thanks,
Nenad




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