bug-gdb
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GDB 5.0] Early termination of multi-threaded program


From: Hyung-Taek Lim
Subject: [GDB 5.0] Early termination of multi-threaded program
Date: Wed, 30 May 2001 13:46:16 +0900

Hi,

I'm not sure whether this is a bug of gdb 5.0.
I made a very simple multi-threaded program in RedHat 7.1 and
tried to debug it with gdb 5.0 that is distributed on May 2000.
When I run the program in gdb 5.0 without any breakpoints
it shows "Program exits normally" in the middle of execution of the program.
However, I found that the program is debugged as I expected
if I use gdb 5.0rh-5 that comes with RedHat 7.1.
Maybe RedHat has modified some bugs in earlier version of gdb 5.0.
Unfortunately, I failed to get source code of newly updated gdb 5.0 or gdb
5.0rh-5.
^^

Following is my multi-threaded program.
It creates five pthreads. Each thread prints a digit received via argument
every second.
Initial threads waits for termination of all five threads and exits.
#include's are omitted.
==BEGIN==================================================================
#define THR_NUM 5
#define THR_LOOP 5

void* print_digit(void* arg);

pthread_t thrid[10];

main()
{
  int i;
  int retcode;
  void * retval;

  printf("\nmain thread:PID[%d],THR[%d]\n",getpid(),pthread_self());

  for (i=0; i< THR_NUM; i++) {
     pthread_create(&thrid[i],NULL,print_digit,(void *)i);
  }

  for (i=0; i< THR_NUM; i++) {
    retcode = pthread_join(thrid[i], &retval);
    printf("THR[%d] terminated\n",thrid[i]);
  }
  printf("\n**** Test program terminates ****\n");
  exit(0);
}

void* print_digit(void* arg)
{
  int i,j,digit;
  digit = (int)arg;
  printf("\nPID[%d],THR[%d]: digit=%d\n",getpid(),pthread_self(),digit);

  for (i=0; i < THR_LOOP; i++) {
     sleep(1);
     printf("%d",digit);
     fflush(NULL);
  }
}
==END====================================================================


Following is the result of debugging my program with gdb 5.0.

==BEGIN==================================================================
address@hidden testgdb]$ ./gdb mthrtest1
GNU gdb 5.0
Copyright 2000 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 "i686-pc-linux-gnu"...
(gdb) run
Starting program: /home/htlim/testgdb/mthrtest1
[New Thread 1024 (LWP 31944)]

  ** main thread:PID[31944],THR[1024]
[New Thread 2049 (LWP 31945)]
[New Thread 1026 (LWP 31946)]

  ** PID[31946],THR[1026]: digit=0
0[New Thread 2051 (LWP 31947)]
00
  ** PID[31947],THR[2051]: digit=1
01[New Thread 3076 (LWP 31948)]
011
  ** PID[31948],THR[3076]: digit=2
12
Program exited normally.
(gdb) 12222
(gdb) info threads
No stack.
(gdb) bt
No stack.
(gdb) quit
address@hidden testgdb]$
==END====================================================================

Only three pthreads are created and my program dies without creating fourth
and fifth pthreads.

But debugging my program with a gdb that comes with RedHat 7.1 works nicely.
Following is the result of debugging my program with gdb in RedHat 7.1.

==BEGIN==================================================================
address@hidden testgdb]$ gdb mthrtest1
GNU gdb 5.0rh-5 Red Hat Linux 7.1
Copyright 2001 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"...
(gdb) run
Starting program: /home/htlim/testgdb/mthrtest1
[New Thread 1024 (LWP 31951)]

  ** main thread:PID[31951],THR[1024]
[New Thread 2049 (LWP 31952)]
Delayed SIGSTOP caught for LWP 31952.
[New Thread 1026 (LWP 31953)]
Delayed SIGSTOP caught for LWP 31953.

  ** PID[31953],THR[1026]: digit=0
[New Thread 2051 (LWP 31954)]
Delayed SIGSTOP caught for LWP 31954.
0
  ** PID[31954],THR[2051]: digit=1
[New Thread 3076 (LWP 31955)]
Delayed SIGSTOP caught for LWP 31955.
10
  ** PID[31955],THR[3076]: digit=2
[New Thread 4101 (LWP 31956)]
Delayed SIGSTOP caught for LWP 31956.
210
  ** PID[31956],THR[4101]: digit=3
[New Thread 5126 (LWP 31957)]
Delayed SIGSTOP caught for LWP 31957.
3210
  ** PID[31957],THR[5126]: digit=4
01234LWP 31953 exited.
  ** THR[1026] terminated
1234LWP 31954 exited.
  ** THR[2051] terminated
234LWP 31955 exited.
  ** THR[3076] terminated
34LWP 31956 exited.
  ** THR[4101] terminated
4LWP 31957 exited.
  ** THR[5126] terminated

**** Test program terminates ****
LWP 31952 exited.

Program exited normally.
(gdb) quit
address@hidden testgdb]$
==END====================================================================





reply via email to

[Prev in Thread] Current Thread [Next in Thread]