This is the mail archive of the gdb-prs@sources.redhat.com 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]

gdb/10: Multithreading problem: Program runs ok without gdb, but stops with SIGTRAP in gdb on thread termination.



>Number:         10
>Category:       gdb
>Synopsis:       Multithreading problem: Program runs ok without gdb, but stops with SIGTRAP in gdb on thread termination.
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Nov 25 08:38:00 PST 2000
>Closed-Date:
>Last-Modified:
>Originator:     Joachim Eibl
>Release:        unknown-1.0
>Organization:
>Environment:
Linux (Suse 7.0)
>Description:
/* 
Multithreading problem: Program runs ok without gdb, but stops with
SIGTRAP in gdb on thread termination.

Test program:  t.c
Compile via:   gcc t.c -lpthread -g3
gcc version:   2.95.2 19991024 (release)
libpthread version: very new, Suse Linux 7.0
               290918 Aug  6 00:27 /lib/libpthread.so.0
gdb version:   5.0 (compiled on my own machine)

Test program: 
   main() starts thread_main() and counts 0,1,2,3,4 in 1 second intervals.
   thread_main() counts 0,1,2 with 1 second intervals and returns.

The test without gdb shows how it should be.              
# a.out
main: 0
thread_main: 0
main: 1
thread_main: 1
main: 2
thread_main: 2
main: 3
main: 4

Second test with gdb shows that gdb stops when thread_main() returns although
no breakpoints were set.
# gdb a.out
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 "i586-pc-linux-gnu"...
(gdb) run
Starting program: /home/joachim/c/a.out
[New Thread 1024 (runnable)]
[New Thread 2049 (runnable)]
[New Thread 1026 (runnable)]
thread_main: 0
thread_main: 1
main: 0
main: 1
thread_main: 2
main: 2
 
Program received signal SIGTRAP, Trace/breakpoint trap.
[Switching to Thread 1026 (runnable)]
0x0 in ?? ()
(gdb)    


Here is the source:
*/


#include <pthread.h>
#include <stdio.h>
#include <unistd.h>

void* thread_main(void* pv)
{
   int i;
   for ( i=0; i<3; ++i )
   {
      printf("thread_main: %d\n",i);
      sleep(1);
   }
}

int main()
{
   int i;
   pthread_t thread;
   pthread_create(&thread, 0, thread_main, 0 );

   for ( i=0; i<5; ++i )
   {
      printf("main: %d\n",i);
      sleep(1);
   }
   
   return 0;
}
>How-To-Repeat:
See Description.
>Fix:
Avoid debugging multithreaded programs. :-(
>Release-Note:
>Audit-Trail:
>Unformatted:

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