This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [patch] Fix TLS access for -static -pthread
- From: Yao Qi <yao at codesourcery dot com>
- To: Jan Kratochvil <jan dot kratochvil at redhat dot com>
- Cc: <gdb-patches at sourceware dot org>, Sergio Durigan Junior <sergiodj at redhat dot com>
- Date: Thu, 5 Jun 2014 17:29:32 +0800
- Subject: Re: [patch] Fix TLS access for -static -pthread
- Authentication-results: sourceware.org; auth=none
- References: <20140410115204 dot GB16411 at host2 dot jankratochvil dot net> <539018F9 dot 5060307 at codesourcery dot com> <20140605080639 dot GA32146 at host2 dot jankratochvil dot net>
On 06/05/2014 04:06 PM, Jan Kratochvil wrote:
>> This patch is to set another breakpoint at the end of main, so that
>> > main thread will hit it, and we can check the value of tlsvar then.
>> > It is safe and we don't have to worry about whether gdb is able to
>> > unwind from pthread library to main function or not.
> I have to warn that it may be a bit weaker test, it never tests both threads
> TLS access during the same stop, it tests only the current thread.
>
> But it still tests the patch works so I am fine with it (not an approval).
>
The patch below is to keep testing TLS access in one stop, and
work around the bug of unwinding clone. WDYT?
--
Yao (éå)
Subject: [PATCH] Fix the race in gdb.threads/staticthreads.exp
The code in gdb.threads/staticthreads.exp about checking the value of
tlsvar in main thread is racy, because when child thread hits
breakpoint, the main thread may not go into pthread_join yet, and
may not be unwind to main.
This patch is to move the line setting breakpoint on after sem_wait,
so that the child thread will hit breakpoint after main thread calls
sem_post. IOW, when child thread hits breakpoint, the main thread is
in either sem_post or pthread_join. "up 10" can unwind main thread to
main.
gdb/testsuite:
2014-06-05 Yao Qi <yao@codesourcery.com>
* gdb.threads/staticthreads.c (thread_function): Move the line
setting breakpoint on forward.
* gdb.threads/staticthreads.exp: Update comments.
---
gdb/testsuite/gdb.threads/staticthreads.c | 2 +-
gdb/testsuite/gdb.threads/staticthreads.exp | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/gdb/testsuite/gdb.threads/staticthreads.c b/gdb/testsuite/gdb.threads/staticthreads.c
index 5c8eabe..db78063 100644
--- a/gdb/testsuite/gdb.threads/staticthreads.c
+++ b/gdb/testsuite/gdb.threads/staticthreads.c
@@ -38,7 +38,6 @@ thread_function (void *arg)
#ifdef HAVE_TLS
tlsvar = 2;
#endif
- printf ("Thread executing\n"); /* tlsvar-is-set */
while (sem_wait (&semaphore) != 0)
{
if (errno != EINTR)
@@ -47,6 +46,7 @@ thread_function (void *arg)
return NULL;
}
}
+ printf ("Thread executing\n"); /* tlsvar-is-set */
return NULL;
}
diff --git a/gdb/testsuite/gdb.threads/staticthreads.exp b/gdb/testsuite/gdb.threads/staticthreads.exp
index 9fa625a..bdc03d4 100644
--- a/gdb/testsuite/gdb.threads/staticthreads.exp
+++ b/gdb/testsuite/gdb.threads/staticthreads.exp
@@ -105,7 +105,7 @@ if { "$have_tls" != "" } {
gdb_continue_to_breakpoint "tlsvar-is-set" ".* tlsvar-is-set .*"
gdb_test "p tlsvar" " = 2" "tlsvar in thread"
gdb_test "thread 1" ".*"
- # Unwind from pthread_join.
+ # Unwind to main.
gdb_test "up 10" " in main .*"
gdb_test "p tlsvar" " = 1" "tlsvar in main"
}
--
1.9.0