From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27936 invoked by alias); 13 Sep 2007 14:39:20 -0000 Received: (qmail 27926 invoked by uid 22791); 13 Sep 2007 14:39:19 -0000 X-Spam-Check-By: sourceware.org Received: from kuber.nabble.com (HELO kuber.nabble.com) (216.139.236.158) by sourceware.org (qpsmtpd/0.31) with ESMTP; Thu, 13 Sep 2007 14:39:06 +0000 Received: from isper.nabble.com ([192.168.236.156]) by kuber.nabble.com with esmtp (Exim 4.63) (envelope-from ) id 1IVpqT-0000BK-Gy for gdb@sourceware.org; Thu, 13 Sep 2007 07:39:05 -0700 Message-ID: <12654909.post@talk.nabble.com> Date: Thu, 13 Sep 2007 14:56:00 -0000 From: zoka To: gdb@sourceware.org Subject: Incorrect GDB backtrace for pthreads MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Nabble-From: zoran@microtrol.com.au X-IsSubscribed: yes Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org X-SW-Source: 2007-09/txt/msg00119.txt.bz2 Hi, Here is simple multi threaded program: ------------------------ snip ---------------------------- // // threads.c // #include #include #include #include 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.