From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16545 invoked by alias); 9 Apr 2009 16:34:56 -0000 Received: (qmail 16513 invoked by uid 22791); 9 Apr 2009 16:34:52 -0000 X-SWARE-Spam-Status: No, hits=-2.6 required=5.0 tests=BAYES_00,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: sourceware.org Received: from kuber.nabble.com (HELO kuber.nabble.com) (216.139.236.158) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 09 Apr 2009 16:34:43 +0000 Received: from isper.nabble.com ([192.168.236.156]) by kuber.nabble.com with esmtp (Exim 4.63) (envelope-from ) id 1LrxD7-0004Dh-9n for gdb@sourceware.org; Thu, 09 Apr 2009 09:34:41 -0700 Message-ID: <22974723.post@talk.nabble.com> Date: Thu, 09 Apr 2009 18:48:00 -0000 From: ajitnayak To: gdb@sourceware.org Subject: Re: thread local storage (__thread) variables aren't working in gdb 6.5/6.6? In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit References: 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: 2009-04/txt/msg00092.txt.bz2 I was trying the same program(tls.cpp) with gdb-6.7 and ran into the same problem. In C++ gdb-6.7 can not access _thread variables , however it works fine with C. I had linked my tls.cpp with pthread lib. I was wondering if there is any update on this or, if I am missing something. Below is my program and gdb output. threads$ cat tls.cpp __thread int i; int main (int argc, char **argv) { i = 5; return i; } threads$ g++ -g tls.cpp -o tls -lpthread threads$ gdb tls GNU gdb 6.7 Copyright (C) 2007 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "i686-pc-linux-gnu"... Using host libthread_db library "/lib/tls/libthread_db.so.1". (gdb) start Breakpoint 1 at 0x80483a8: file tls.cpp, line 6. Starting program: /tmp/threads/tls [Thread debugging using libthread_db enabled] [New Thread 0xb7fdbac0 (LWP 26922)] [Switching to Thread 0xb7fdbac0 (LWP 26922)] main (argc=1, argv=0xbfea87a4) at tls.cpp:6 6 i = 5; (gdb) p i Cannot access memory at address 0x0 (gdb) Will appreciate any help. thanks, Ajit. John Bates wrote: > > Interesting.. it does work with C, but not with C++. I tried -lpthread > in all cases with a C++ build (on fedora core and debian) with the > same problem. > > jbates@psycho:~/test/gdbtls$ mv tls.c tls.cpp > jbates@psycho:~/test/gdbtls$ gcc -g tls.cpp -o tls -lpthread > jbates@psycho:~/test/gdbtls$ gdb tls > GNU gdb 6.4.90-debian > 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 "i486-linux-gnu"...Using host libthread_db > library "/lib/tls/libthread_db.so.1". > > (gdb) start > Breakpoint 1 at 0x8048392: file tls.cpp, line 6. > Starting program: /home/jbates/test/gdbtls/tls > Failed to read a valid object file image from memory. > [Thread debugging using libthread_db enabled] > [New Thread -1209833792 (LWP 4199)] > [Switching to Thread -1209833792 (LWP 4199)] > main () at tls.cpp:6 > 6 i = 5; > (gdb) p i > Cannot access memory at address 0x0 > (gdb) > > On 6/26/07, Jim Blandy wrote: >> >> "John Bates" writes: >> > It would be helpful to update the GDB man/info/docs to state that >> > thread local storage is not supported. It would also help to print an >> > error when attempting to access TLS __thread variable that says >> > "thread local storage is not supported." Currently, GDB implies that >> > __thread variables are bad addresses--for example, "Cannot access >> > memory at address 0x0". I have verified the same result in GDB 6.4, >> > 6.5 and 6.6, with and without libpthread linked with the ELF. A simple >> > test case is in the email below if anyone is interested in checking >> > this. >> >> GDB does support thread-local storage --- but you need to link your >> program against -lpthread. >> >> $ cat tls.c >> __thread int i; >> >> int >> main (int argc, char **argv) >> { >> i = 5; >> return i; >> } >> $ gcc -g tls.c -o tls -lpthread >> $ gdb tls >> GNU gdb Red Hat Linux (6.5-15.fc6rh) >> 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 "i386-redhat-linux-gnu"...Using host >> libthread_db library "/lib/libthread_db.so.1". >> >> (gdb) start >> Breakpoint 1 at 0x8048382: file tls.c, line 6. >> Starting program: /home/jimb/play/tls >> [Thread debugging using libthread_db enabled] >> [New Thread -1208985920 (LWP 7664)] >> [Switching to Thread -1208985920 (LWP 7664)] >> main () at tls.c:6 >> 6 i = 5; >> (gdb) p i >> $1 = 0 >> (gdb) step >> 7 return i; >> (gdb) p i >> $2 = 5 >> (gdb) info address i >> Symbol "i" is a thread-local variable at offset 0 in the thread-local >> storage for `/home/jimb/play/tls'. >> (gdb) >> >> The current GDB sources do print a slightly more helpful error message >> when they can't do this: >> >> $ gcc -g tls.c -o tls >> $ gdb tls >> GNU gdb Red Hat Linux (6.5-15.fc6rh) >> 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 "i386-redhat-linux-gnu"...Using host >> libthread_db library "/lib/libthread_db.so.1". >> >> (gdb) start >> Breakpoint 1 at 0x8048352: file tls.c, line 6. >> Starting program: /home/jimb/play/tls >> main () at tls.c:6 >> 6 i = 5; >> (gdb) print i >> Cannot find thread-local variables on this target >> (gdb) >> >> This doesn't suggest the workaround of linking against -lpthread. >> > > -- View this message in context: http://www.nabble.com/thread-local-storage-%28__thread%29-variables-aren%27t-working-in-gdb-6.5-6.6--tp11202198p22974723.html Sent from the Sourceware - gdb list mailing list archive at Nabble.com.