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]

Incorrect GDB backtrace for pthreads


Hi,
Here is simple multi threaded program:

------------------------ snip ----------------------------

//
// threads.c
//

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

static void* thread(void* p)
{
        int i;
        char* name=p;
        int n = name[6]-'0';

        for (i = 0;; i++)
        {
                sleep(1+n);
                printf("%s: count=%d\n", (char*) p, i);
        }
}


int main ()
{
        pthread_t t1,t2,t3;

        pthread_create( &t1, 0, thread, "Thread1" );
        pthread_create( &t2, 0, thread, "Thread2" );
        pthread_create( &t3, 0, thread, "Thread3" );

        pthread_join(t1, 0);
        // never reached
}

------------------------ snip ----------------------------

Here is the transcript of compile and debug session:

zoka@mujo:~/gdb$ uname -r
2.6.22.3-dist
zoka@mujo:~/gdb$ gcc --version
gcc (GCC) 4.2.1
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

zoka@mujo:~/gdb$ ls /lib/libc-*
/lib/libc-2.6.1.so

zoka@mujo:~/gdb$ gcc -g -o threads threads.c -lpthread
zoka@mujo:~/gdb$ gdb threads
GNU gdb 6.6
Copyright (C) 2006 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-t2-linux-gnu"...
Using host libthread_db library "/lib/libthread_db.so.1".
(gdb) r
Starting program: /home/zoka/gdb/threads
Failed to read a valid object file image from memory.
Thread1: count=0
Thread2: count=0
Thread3: count=0
Thread1: count=1
Thread2: count=1
Thread1: count=2
Thread3: count=1
Thread1: count=3
Thread2: count=2

Program received signal SIGINT, Interrupt.
0xffffe410 in ?? ()
(gdb) bt
#0  0xffffe410 in ?? ()                          # backtrace incorrect
#1  0xbfcef2b8 in ?? ()
#2  0x0000169f in ?? ()
#3  0x00000000 in ?? ()
(gdb) info threads                                # GDB knows no threads ?!
(gdb) b 21                                          # set breakpoint at
printf in thread()
Breakpoint 1 at 0x804849b: file threads.c, line 21.
(gdb) c
Continuing.
[New LWP 5793]
[Switching to LWP 5793]

Breakpoint 1, thread (p=0x8048626) at threads.c:21
21                      printf("%s: count=%d\n", (char*) p, i);
(gdb) d 1                                              # delete breakpoint
(gdb) c
Continuing.
Thread2: count=3
Thread1: count=4
Thread3: count=2
Thread1: count=5
[New LWP 5788]
Thread2: count=4

Program received signal SIGINT, Interrupt.        # result of ctrl-C
[Switching to LWP 5788]
0xffffe410 in ?? ()
(gdb) bt
#0  0xffffe410 in ?? ()                                   # same incorrect
backtrace
#1  0xbfcef2b8 in ?? ()
#2  0x0000169f in ?? ()
#3  0x00000000 in ?? ()
(gdb) info threads
* 2 LWP 5788  0xffffe410 in ?? ()                    # there should be 4
threads:
  1 LWP 5793  0xffffe410 in ?? ()                     # main + t1,t2,t3
(gdb)

------------------------ snip ----------------------------







                                                              1,1          
All

-- 
View this message in context: http://www.nabble.com/Incorrect-GDB-backtrace-for-pthreads-tf4435749.html#a12654909
Sent from the Sourceware - gdb list mailing list archive at Nabble.com.


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