From: Prosun Niyogi <niyogip@yahoo.com>
To: gdb@sourceware.org
Cc: pniyogi@us.ibm.com
Subject: TLS on powerpc(32/64)
Date: Thu, 21 Sep 2006 23:20:00 -0000 [thread overview]
Message-ID: <20060921232047.2836.qmail@web38908.mail.mud.yahoo.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1279 bytes --]
Hi,
I've been struggling the last few days on getting gdb
to work correctly on a powerpc64 machine. Built as
ppc-64-linux, debugging ppc64 binaries linked against
libpthread. It seems to me that gdb's TLS access does
not work correctly on these platforms. Attempting to
print a variable of type __thread doesnt work.
Here's a paste:
shadows:~/pniyogi # ldd ./tls
linux-vdso64.so.1 => (0x0000000000100000)
libpthread.so.0 => /lib64/libpthread.so.0
libgcc_s.so.1 => /lib64/libgcc_s.so.1
libc.so.6 => /lib64/libc.so.6
/lib64/ld64.so.1 (0x0000040000000000)
shadows:~/pniyogi # ./gdb-new ./tls
GNU gdb 6.5.50.20060811-cvs
***********
(gdb) b 80
Breakpoint 1 at 0x10000d6c: file tls.c, line 80.
(gdb) r
Starting program: /root/pniyogi/tls
[New LWP 8210]
[Switching to LWP 8210]
Breakpoint 1, spin (vp=0x0) at tls.c:80
80 thread_local_val[ me ] = a_thread_local;
(gdb) p a_thread_local
Cannot find thread-local variables on this target
(gdb)
Also attaching a testcase tls.c that I was compiling
with -m64 -g
Any assistance/insight would be appreciated.
-Prosun Niyogi
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 42213221-tls.c --]
[-- Type: text/x-csrc; name="tls.c", Size: 4861 bytes --]
/* BeginSourceFile tls.c
This file creates and deletes threads. It uses thread local storage
variables too. */
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <pthread.h>
#include <semaphore.h>
#include <errno.h>
#define N_THREADS 3
/* Uncomment to turn on debugging output */
/*#define START_DEBUG*/
/* Thread-local storage. */
__thread int a_thread_local;
__thread int another_thread_local;
/* Global variable just for info addr in gdb. */
int a_global;
/* Print the results of thread-local storage. */
int thread_local_val[ N_THREADS ];
int another_thread_local_val[ N_THREADS ];
/* Semaphores to make sure the threads are alive when we print the TLS
variables from gdb. */
sem_t tell_main, tell_thread;
void print_error ()
{
switch (errno)
{
case EAGAIN:
fprintf (stderr, "EAGAIN\n");
break;
case EINTR:
fprintf (stderr, "EINTR\n");
break;
case EINVAL:
fprintf (stderr, "EINVAL\n");
break;
case ENOSYS:
fprintf (stderr, "ENOSYS\n");
break;
case ENOENT:
fprintf (stderr, "ENOENT\n");
break;
case EDEADLK:
fprintf (stderr, "EDEADLK\n");
break;
default:
fprintf (stderr, "Unknown error\n");
break;
}
}
/* Routine for each thread to run, does nothing. */
void *spin( vp )
void * vp;
{
int me = (long) vp;
int i;
/* Use a_global. */
a_global++;
a_thread_local = 0;
another_thread_local = me;
for( i = 0; i <= me; i++ ) {
a_thread_local += i;
printf("Thread local = %d\n", a_thread_local);
}
another_thread_local_val[me] = another_thread_local;
thread_local_val[ me ] = a_thread_local; /* here we know tls value */
if (sem_post (&tell_main) == -1)
{
fprintf (stderr, "th %d post on sem tell_main failed\n", me);
print_error ();
return;
}
#ifdef START_DEBUG
fprintf (stderr, "th %d post on tell main\n", me);
#endif
while (1)
{
#ifdef START_DEBUG
fprintf (stderr, "th %d start wait on tell_thread\n", me);
#endif
if (sem_wait (&tell_thread) == 0)
break;
if (errno == EINTR)
{
#ifdef START_DEBUG
fprintf (stderr, "th %d wait tell_thread got EINTR, rewaiting\n", me);
#endif
continue;
}
else
{
fprintf (stderr, "th %d wait on sem tell_thread failed\n", me);
print_error ();
return;
}
}
#ifdef START_DEBUG
fprintf (stderr, "th %d Wait on tell_thread\n", me);
#endif
}
void
do_pass()
{
int i;
pthread_t t[ N_THREADS ];
int err;
for( i = 0; i < N_THREADS; i++)
{
thread_local_val[i] = 0;
another_thread_local_val[i] = 0;
}
if (sem_init (&tell_main, 0, 0) == -1)
{
fprintf (stderr, "tell_main semaphore init failed\n");
return;
}
if (sem_init (&tell_thread, 0, 0) == -1)
{
fprintf (stderr, "tell_thread semaphore init failed\n");
return;
}
/* Start N_THREADS threads, then join them so that they are terminated. */
for( i = 0; i < N_THREADS; i++ )
{
err = pthread_create( &t[i], NULL, spin, (void *) (long) i );
if( err != 0 ) {
fprintf(stderr, "Error in thread %d create\n", i );
}
}
for( i = 0; i < N_THREADS; i++ )
{
while (1)
{
#ifdef START_DEBUG
fprintf (stderr, "main %d start wait on tell_main\n", i);
#endif
if (sem_wait (&tell_main) == 0)
break;
if (errno == EINTR)
{
#ifdef START_DEBUG
fprintf (stderr, "main %d wait tell_main got EINTR, rewaiting\n", i);
#endif
continue;
}
else
{
fprintf (stderr, "main %d wait on sem tell_main failed\n", i);
print_error ();
return;
}
}
}
#ifdef START_DEBUG
fprintf (stderr, "main done waiting on tell_main\n");
#endif
i = 10; /* Here all threads should be still alive. */
for( i = 0; i < N_THREADS; i++ )
{
if (sem_post (&tell_thread) == -1)
{
fprintf (stderr, "main %d post on sem tell_thread failed\n", i);
print_error ();
return;
}
#ifdef START_DEBUG
fprintf (stderr, "main %d post on tell_thread\n", i);
#endif
}
for( i = 0; i < N_THREADS; i++ )
{
err = pthread_join(t[i], NULL );
if( err != 0 )
{
fprintf (stderr, "error in thread %d join\n", i );
}
}
i = 10; /* Null line for setting bpts on. */
}
int
main()
{
do_pass ();
return 0; /* Set breakpoint here before exit. */
}
/* EndSourceFile */
next reply other threads:[~2006-09-21 23:20 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-09-21 23:20 Prosun Niyogi [this message]
2006-09-21 23:52 ` Daniel Jacobowitz
2006-09-22 13:53 ` Prosun Niyogi
2006-09-22 18:03 ` Michael Snyder
2006-09-22 18:18 ` Prosun Niyogi
2006-09-22 18:43 ` Michael Snyder
2006-09-22 19:01 ` Prosun Niyogi
[not found] ` <20060922025718.19237.qmail@web38906.mail.mud.yahoo.com>
2006-09-22 14:03 ` Daniel Jacobowitz
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=20060921232047.2836.qmail@web38908.mail.mud.yahoo.com \
--to=niyogip@yahoo.com \
--cc=gdb@sourceware.org \
--cc=pniyogi@us.ibm.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