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.
+
+2015-01-09 Pedro Alves <palves@redhat.com>
+
* gdb.threads/attach-many-short-lived-threads.c: New file.
* gdb.threads/attach-many-short-lived-threads.exp: New file.
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 up us if
we are being traced by GDB which we stopped ourselves. */
int threadno = (intptr_t) threadno_voidp;
int i;
+ pthread_barrier_wait (&threads_started_barrier);
+
switch (threadno)
{
case 1:
timed_mutex_lock (&terminate_mutex);
+ pthread_barrier_init (&threads_started_barrier, NULL, 3);
+
i = pthread_create (&thread1, NULL, thread_func, (void *) (intptr_t) 1);
assert (i == 0);
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)
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. */
{
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. */
{
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. */
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);
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)
static pthread_mutex_t terminate_mutex = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP;
+static pthread_barrier_t threads_started_barrier;
+
/* These variables must have lower in-memory addresses than thread1_rwatch and
thread2_rwatch so that they take their watchpoint slots. */
int i;
volatile int rwatch_store;
+ pthread_barrier_wait (&threads_started_barrier);
+
timed_mutex_lock (&thread1_tid_mutex);
/* THREAD1_TID_MUTEX must be already locked to avoid race. */
int i;
volatile int rwatch_store;
+ pthread_barrier_wait (&threads_started_barrier);
+
timed_mutex_lock (&thread2_tid_mutex);
/* THREAD2_TID_MUTEX must be already locked to avoid race. */
timed_mutex_lock (&terminate_mutex);
+ pthread_barrier_init (&threads_started_barrier, NULL, 3);
+
i = pthread_create (&thread1, NULL, thread1_func, NULL);
assert (i == 0);
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)