With GCC 4.4.0 and GDB 7.0, 7.1, and trunk, accessing thread-local static class variables causes an internal assert to be tripped. $ cat mintest.cpp class A { public: static __thread int num; }; __thread int A::num = 1; int main() { return 0; } $ g++ mintest.cpp -g -lpthread $ ~/gdb-trunk/gdb/gdb ./a.out GNU gdb (GDB) 7.2.50.20100709-cvs Copyright (C) 2010 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> 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 "x86_64-unknown-linux-gnu". For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>... Reading symbols from /home/jpotter/tls/a.out...done. (gdb) break main Breakpoint 1 at 0x400590: file mintest.cpp, line 3. (gdb) run Starting program: /home/jpotter/tls/a.out [Thread debugging using libthread_db enabled] Breakpoint 1, main () at mintest.cpp:3 3 int main() { return 0; } (gdb) print A::num warning: static field's value depends on the current frame - bad debug info? findvar.c:427: internal-error: read_var_value: Assertion `frame' failed. A problem internal to GDB has been detected, further debugging may prove unreliable. Quit this debugging session? (y or n) And sure enough, in dwarf2loc.c: 1057 /* Thread-local accesses do require a frame. */ 1058 static CORE_ADDR 1059 needs_frame_tls_address (void *baton, CORE_ADDR offset) 1060 { 1061 struct needs_frame_baton *nf_baton = baton; 1062 1063 nf_baton->needs_frame = 1; 1064 return 1; 1065 } It seems that this isn't the case, at least on initial-exec GCC on x86_64, and GCC assumes that no frame is needed when producing DWARF info; I'm not familiar enough with DWARF's TLS support to know whether that's the actual issue, though.
From what I can tell, TLS needs registers, but not actually a frame in the gdb internals sense. Looking through the code paths, I don't see anything actually using a frame. And, it seems to me that these frame checks are actually gdb internal consistency checks. So, I think it is probably safe to change needs_frame_tls_address.
(In reply to comment #1) > From what I can tell, TLS needs registers, but not actually a frame > in the gdb internals sense. Looking through the code paths, I don't > see anything actually using a frame. And, it seems to me that these > frame checks are actually gdb internal consistency checks. > So, I think it is probably safe to change needs_frame_tls_address. > I just run into this on i686. I verified test program with gdb 7.2.50.20100913- cvs and gcc-4.5.1 under linux it breaks in the same way. In my case this bug breaks all IDE front ends when debugging wxWidgets they try to access all local variables when stepping through code, and wxString class has thread-local static class variable. Changing needs_frame_tls_address fixes this problem.
Testing a patch.
Subject: Bug 11803 CVSROOT: /cvs/src Module name: src Changes by: tromey@sourceware.org 2010-09-14 19:08:30 Modified files: gdb : ChangeLog value.c gdb/testsuite : ChangeLog gdb/testsuite/gdb.threads: tls.c tls.exp Log message: gdb PR exp/11803: * value.c (value_static_field): Use value_of_variable. gdb/testsuite PR exp/11803: * gdb.threads/tls.exp: Use C++. (check_thread_local): Use K::another_thread_local. * gdb.threads/tls.c (class K): New. (another_thread_local): Now a member of K. (spin): Update. No longer K&R C. Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/ChangeLog.diff?cvsroot=src&r1=1.12180&r2=1.12181 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/value.c.diff?cvsroot=src&r1=1.111&r2=1.112 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/testsuite/ChangeLog.diff?cvsroot=src&r1=1.2447&r2=1.2448 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/testsuite/gdb.threads/tls.c.diff?cvsroot=src&r1=1.3&r2=1.4 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/testsuite/gdb.threads/tls.exp.diff?cvsroot=src&r1=1.12&r2=1.13
Fix checked in.