0

Here we are trying to modify our own version of GDB to support multi-threaded environment.

Till now I could able to read the data associated with registers with respect to every thread but need to find out the way with which we can read thread local variable.

For reading the thread local variable i need to know how to calculate the offset using ptrace command. If anyone here know it would be really helpful to me.

=Thanks.

1 Answers1

1

ptrace(2) doesn't support for TLS (thread local storage).

It's always a good idea to see how GDB handles process management issues. In this case, GDB uses libthread_db. This is a library (man page) that manages access to TLS according to the (platform-specific) API.

See Ulrich Drepper's Elf Handling for Threading Local Storage for details on how TLS is implemented in Linux.

mkfs
  • 346
  • 1
  • 6
  • Your answer is good overall, but I am not sure I trust that manpage to be accurate for Linux. It has a Solaris smell to it. – zwol Feb 12 '13 at 19:51
  • Yeah the only manpages I could find for that library were the Solaris ones. Function protos look similar to the ones gdb invokes, though, and the poster didn't specify what platform this is for. – mkfs Feb 12 '13 at 20:37
  • I'm pretty sure it's _not_ Solaris, because Solaris replaced `ptrace` with procfs stuff many years ago. – zwol Feb 12 '13 at 23:25
  • THanks All for your opinion, I will try libthread_db lib. and will get back to you if i have any more queries. – user2064119 Feb 13 '13 at 10:32
  • Eh, Solaris, SunOS, whatever. The online man pages are all effectively the same as the one from 1998 hosted by Oracle these days: http://docs.oracle.com/cd/E19455-01/806-0630/6j9vkb8dk/index.html . Looking at /usr/include/thread_db.h, it seems Linux went for API compatibility. – mkfs Feb 15 '13 at 07:09