aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.threads/siginfo-threads.c
diff options
context:
space:
mode:
authorPedro Alves <palves@redhat.com>2014-12-29 19:41:04 +0000
committerPedro Alves <palves@redhat.com>2015-01-09 13:58:29 +0000
commit9665ffdd591e9b374b4e5f6aeffe15541346140d (patch)
treea5bd5298c4046265f255a01b84bd1c29d6e92822 /gdb/testsuite/gdb.threads/siginfo-threads.c
parent400cf8cbe9bc48068f1601ea9cd33fbd2f5de36a (diff)
downloadbinutils-9665ffdd591e9b374b4e5f6aeffe15541346140d.zip
binutils-9665ffdd591e9b374b4e5f6aeffe15541346140d.tar.gz
binutils-9665ffdd591e9b374b4e5f6aeffe15541346140d.tar.bz2
gdb.threads/{siginfo-thread.c,watchthreads-reorder.c,ia64-sigill.c} races with GDB
These three test all spawn a few threads and then send a SIGSTOP to their parent GDB in order to pause it while the new threads set things up for the test. With a GDB patch that changes the inferior thread's scheduling a bit, I sometimes see: FAIL: gdb.threads/siginfo-threads.exp: catch signal 0 (timeout) ... FAIL: gdb.threads/watchthreads-reorder.exp: reorder1: continue a (timeout) ... FAIL: gdb.threads/ia64-sigill.exp: continue (timeout) ... The issue is that the test program stops GDB before it had a chance of processing the new thread's clone event: (gdb) PASS: gdb.threads/siginfo-threads.exp: get pid continue Continuing. Stopping GDB PID 21541. Waiting till the threads initialize their TIDs. FAIL: gdb.threads/siginfo-threads.exp: catch signal 0 (timeout) On Linux (at least), new threads start stopped, and the debugger must resume them. The fix is to make the test program wait for the new threads to be running before stopping GDB. gdb/testsuite/ 2015-01-09 Pedro Alves <palves@redhat.com> * gdb.threads/ia64-sigill.c (threads_started_barrier): New global. (thread_func): Wait on barrier. (main): Wait for all threads to start before stopping GDB. * gdb.threads/siginfo-threads.c (threads_started_barrier): New global. (thread1_func, thread2_func): Wait on barrier. (main): Wait for all threads to start before stopping GDB. * gdb.threads/watchthreads-reorder.c (threads_started_barrier): New global. (thread1_func, thread2_func): Wait on barrier. (main): Wait for all threads to start before stopping GDB.
Diffstat (limited to 'gdb/testsuite/gdb.threads/siginfo-threads.c')
-rw-r--r--gdb/testsuite/gdb.threads/siginfo-threads.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.threads/siginfo-threads.c b/gdb/testsuite/gdb.threads/siginfo-threads.c
index 95c3927..a8e5446 100644
--- a/gdb/testsuite/gdb.threads/siginfo-threads.c
+++ b/gdb/testsuite/gdb.threads/siginfo-threads.c
@@ -54,6 +54,8 @@ static int thread2_sigusr2_hit;
static pthread_mutex_t terminate_mutex
= PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP;
+static pthread_barrier_t threads_started_barrier;
+
/* Do not use alarm as it would create a ptrace event which would hang
us up if we are being traced by GDB, which we stopped
ourselves. */
@@ -128,6 +130,8 @@ thread1_func (void *unused)
{
int i;
+ pthread_barrier_wait (&threads_started_barrier);
+
timed_mutex_lock (&thread1_tid_mutex);
/* THREAD1_TID_MUTEX must be already locked to avoid a race. */
@@ -163,6 +167,8 @@ thread2_func (void *unused)
{
int i;
+ pthread_barrier_wait (&threads_started_barrier);
+
timed_mutex_lock (&thread2_tid_mutex);
/* THREAD2_TID_MUTEX must be already locked to avoid a race. */
@@ -354,6 +360,8 @@ main (int argc, char **argv)
assert_perror (errno);
assert (i == 0);
+ pthread_barrier_init (&threads_started_barrier, NULL, 3);
+
i = pthread_create (&thread1, NULL, thread1_func, NULL);
assert (i == 0);
@@ -380,6 +388,11 @@ main (int argc, char **argv)
atexit (cleanup);
+ /* Wait until all threads are seen running. On Linux (at least),
+ new threads start stopped, and the debugger must resume them.
+ Need to wait for that before stopping GDB. */
+ pthread_barrier_wait (&threads_started_barrier);
+
printf ("Stopping GDB PID %lu.\n", (unsigned long) tracer);
if (tracer)