Mirror of the gdb mailing list
 help / color / mirror / Atom feed
* Incorrect GDB backtrace for pthreads
@ 2007-09-13 14:56 zoka
  2007-09-13 16:49 ` Daniel Jacobowitz
  0 siblings, 1 reply; 2+ messages in thread
From: zoka @ 2007-09-13 14:56 UTC (permalink / raw)
  To: gdb


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.


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Incorrect GDB backtrace for pthreads
  2007-09-13 14:56 Incorrect GDB backtrace for pthreads zoka
@ 2007-09-13 16:49 ` Daniel Jacobowitz
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel Jacobowitz @ 2007-09-13 16:49 UTC (permalink / raw)
  To: zoka; +Cc: gdb

On Thu, Sep 13, 2007 at 07:39:05AM -0700, zoka wrote:
> Starting program: /home/zoka/gdb/threads
> Failed to read a valid object file image from memory.

> #0  0xffffe410 in ?? ()                          # backtrace incorrect

This is a kernel bug.

> (gdb) info threads                                # GDB knows no threads ?!

It sounds like either shared library debugging doesn't work on your
system, or thread debugging doesn't.  ld.so and libpthread.so are
probably stripped.  They need a symbol table for GDB to work.

-- 
Daniel Jacobowitz
CodeSourcery


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-09-13 14:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-09-13 14:56 Incorrect GDB backtrace for pthreads zoka
2007-09-13 16:49 ` Daniel Jacobowitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox