Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: Jim Blandy <jimb@codesourcery.com>
To: "John Bates" <johnnybates@gmail.com>
Cc: gdb@sourceware.org
Subject: Re: thread local storage (__thread) variables aren't working in gdb 6.5/6.6?
Date: Tue, 26 Jun 2007 17:06:00 -0000	[thread overview]
Message-ID: <m3tzsuhci3.fsf@codesourcery.com> (raw)
In-Reply-To: <a4c7fade0706251620j7b526855r87b374c257fbd7d0@mail.gmail.com> (John Bates's message of "Mon, 25 Jun 2007 16:20:34 -0700")


"John Bates" <johnnybates@gmail.com> 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.


  reply	other threads:[~2007-06-26 17:06 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-06-19 20:22 John Bates
2007-06-19 20:28 ` Daniel Jacobowitz
2007-06-19 20:56   ` John Bates
2007-06-19 21:04     ` Daniel Jacobowitz
2007-06-25 23:20 ` John Bates
2007-06-26 17:06   ` Jim Blandy [this message]
2007-06-26 18:48     ` John Bates
2007-06-26 23:52       ` Jim Blandy
2009-04-09 18:48       ` ajitnayak
     [not found]         ` <20090409200657.GA22217@host0.dyn.jankratochvil.net>
     [not found]           ` <b1bfafd50904130735x32d369a0ub4005758d7d9e2c8@mail.gmail.com>
2009-04-13 19:00             ` Jan Kratochvil

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=m3tzsuhci3.fsf@codesourcery.com \
    --to=jimb@codesourcery.com \
    --cc=gdb@sourceware.org \
    --cc=johnnybates@gmail.com \
    /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