From: zoka <zoran@microtrol.com.au>
To: gdb@sourceware.org
Subject: Incorrect GDB backtrace for pthreads
Date: Thu, 13 Sep 2007 14:56:00 -0000 [thread overview]
Message-ID: <12654909.post@talk.nabble.com> (raw)
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.
next reply other threads:[~2007-09-13 14:39 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-09-13 14:56 zoka [this message]
2007-09-13 16:49 ` Daniel Jacobowitz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=12654909.post@talk.nabble.com \
--to=zoran@microtrol.com.au \
--cc=gdb@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox