From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25814 invoked by alias); 26 Jun 2007 23:52:12 -0000 Received: (qmail 25805 invoked by uid 22791); 26 Jun 2007 23:52:11 -0000 X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (65.74.133.4) by sourceware.org (qpsmtpd/0.31) with ESMTP; Tue, 26 Jun 2007 23:52:09 +0000 Received: (qmail 16616 invoked from network); 26 Jun 2007 23:52:07 -0000 Received: from unknown (HELO localhost) (jimb@127.0.0.2) by mail.codesourcery.com with ESMTPA; 26 Jun 2007 23:52:07 -0000 To: "John Bates" Cc: gdb@sourceware.org Subject: Re: thread local storage (__thread) variables aren't working in gdb 6.5/6.6? References: From: Jim Blandy Date: Tue, 26 Jun 2007 23:52:00 -0000 In-Reply-To: (John Bates's message of "Tue, 26 Jun 2007 11:48:06 -0700") Message-ID: User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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-06/txt/msg00326.txt.bz2 "John Bates" writes: > 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. Yes, quite interesting. Filed as GDB bug 2279: ---- Description: See how-to-repeat. GDB seems to create two symbol table entries for 'i', one with LOC_UNRESOLVED and one with LOC_COMPUTED; it doesn't recognize that the first die is just a specification for the second. If you remove the __thread qualifier, GDB still creates the two symtab entries, but can print its value. I think this is because GDB tries to handle LOC_UNRESOLVED symbols by falling back to the minsyms, but in the TLS case the minsym's value is the variable's TLS offset. So there may be two bugs to fix here: - dwarf2read shouldn't be creating two symtab entries for 'i'. - the LOC_UNRESOLVED fallback code shouldn't try to use STT_TLS minsym values as addresses. How-To-Repeat: $ cat tls.c __thread int i; int main (int argc, char **argv) { i = 5; return i; } $ g++ -g tls.c -o tls -lpthread $ readelf -d tls Dynamic section at offset 0x508 contains 24 entries: Tag Type Name/Value 0x00000001 (NEEDED) Shared library: [libpthread.so.0] 0x00000001 (NEEDED) Shared library: [libstdc++.so.6] 0x00000001 (NEEDED) Shared library: [libm.so.6] 0x00000001 (NEEDED) Shared library: [libgcc_s.so.1] 0x00000001 (NEEDED) Shared library: [libc.so.6] 0x0000000c (INIT) 0x80482fc 0x0000000d (FINI) 0x80484c8 0x6ffffef5 (GNU_HASH) 0x8048168 0x00000005 (STRTAB) 0x80481e8 0x00000006 (SYMTAB) 0x8048188 0x0000000a (STRSZ) 176 (bytes) 0x0000000b (SYMENT) 16 (bytes) 0x00000015 (DEBUG) 0x0 0x00000003 (PLTGOT) 0x80495f4 0x00000002 (PLTRELSZ) 16 (bytes) 0x00000014 (PLTREL) REL 0x00000017 (JMPREL) 0x80482ec 0x00000011 (REL) 0x80482e4 0x00000012 (RELSZ) 8 (bytes) 0x00000013 (RELENT) 8 (bytes) 0x6ffffffe (VERNEED) 0x80482a4 0x6fffffff (VERNEEDNUM) 2 0x6ffffff0 (VERSYM) 0x8048298 0x00000000 (NULL) 0x0 $ ~/gdb/pub/bin/gdb tls GNU gdb 6.6.50.20070625-cvs Copyright (C) 2007 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-pc-linux-gnu"... Using host libthread_db library "/lib/libthread_db.so.1". (gdb) start Breakpoint 1 at 0x8048402: file tls.c, line 6. Starting program: /home/jimb/play/tls [Thread debugging using libthread_db enabled] [New Thread 0xb7feb6d0 (LWP 9387)] [Switching to Thread 0xb7feb6d0 (LWP 9387)] main () at tls.c:6 6 i = 5; Current language: auto; currently c++ (gdb) print i Cannot access memory at address 0x0 (gdb) quit The program is running. Exit anyway? (y or n) y $ readelf -wi tls The section .debug_info contains: Compilation Unit @ offset 0x0: Length: 201 Version: 2 Abbrev Offset: 0 Pointer Size: 4 <0>: Abbrev Number: 1 (DW_TAG_compile_unit) DW_AT_stmt_list : 0 DW_AT_high_pc : 0x8048419 DW_AT_low_pc : 0x80483f4 DW_AT_producer : GNU C++ 4.1.1 20070105 (Red Hat 4.1.1-51) DW_AT_language : 4 (C++) DW_AT_name : tls.c DW_AT_comp_dir : /home/jimb/play <1><59>: Abbrev Number: 2 (DW_TAG_subprogram) DW_AT_sibling : <8f> DW_AT_external : 1 DW_AT_name : main DW_AT_decl_file : 1 DW_AT_decl_line : 4 DW_AT_type : <8f> DW_AT_low_pc : 0x80483f4 DW_AT_high_pc : 0x8048419 DW_AT_frame_base : 0 (location list) <2><76>: Abbrev Number: 3 (DW_TAG_formal_parameter) DW_AT_name : argc DW_AT_decl_file : 1 DW_AT_decl_line : 4 DW_AT_type : <8f> <2><82>: Abbrev Number: 3 (DW_TAG_formal_parameter) DW_AT_name : argv DW_AT_decl_file : 1 DW_AT_decl_line : 4 DW_AT_type : <96> <1><8f>: Abbrev Number: 4 (DW_TAG_base_type) DW_AT_name : int DW_AT_byte_size : 4 DW_AT_encoding : 5 (signed) <1><96>: Abbrev Number: 5 (DW_TAG_pointer_type) DW_AT_byte_size : 4 DW_AT_type : <9c> <1><9c>: Abbrev Number: 5 (DW_TAG_pointer_type) DW_AT_byte_size : 4 DW_AT_type : <1>: Abbrev Number: 4 (DW_TAG_base_type) DW_AT_name : char DW_AT_byte_size : 1 DW_AT_encoding : 6 (signed char) <1>: Abbrev Number: 6 (DW_TAG_namespace) DW_AT_sibling : DW_AT_name : :: DW_AT_decl_file : 2 DW_AT_decl_line : 0 <2>: Abbrev Number: 7 (DW_TAG_variable) DW_AT_name : i DW_AT_decl_file : 1 DW_AT_decl_line : 1 DW_AT_type : <8f> DW_AT_external : 1 DW_AT_declaration : 1 <1>: Abbrev Number: 8 (DW_TAG_variable) DW_AT_specification: DW_AT_location : 6 byte block: 3 0 0 0 0 e0 (DW_OP_addr: 0; DW_OP_GNU_push_tls_address) $