1 /* This testcase is part of GDB, the GNU debugger.
3 Copyright 2015 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 #include <sys/types.h>
26 /* Number of threads. Each thread continuously spawns a fork and wait
27 for it. If we have another thread continuously start a step over,
28 gdbserver should end up finding new forks while suspending
32 pthread_t threads
[NTHREADS
];
34 pthread_barrier_t barrier
;
38 /* Used to create a conditional breakpoint that always fails. */
42 thread_forks (void *arg
)
46 pthread_barrier_wait (&barrier
);
48 for (i
= 0; i
< NFORKS
; i
++)
59 pid
= waitpid (pid
, &status
, 0);
66 if (!WIFEXITED (status
))
68 printf ("Unexpected wait status 0x%x from child %d\n",
85 /* Set this to tell the thread_breakpoint thread to exit. */
86 volatile int break_out
;
89 thread_breakpoint (void *arg
)
91 pthread_barrier_wait (&barrier
);
95 usleep (1); /* set break here */
101 pthread_barrier_t barrier
;
110 /* Don't run forever. */
113 pthread_barrier_init (&barrier
, NULL
, NTHREADS
+ 1);
115 /* Start the threads that constantly fork. */
116 for (i
= 0; i
< NTHREADS
; i
++)
118 ret
= pthread_create (&threads
[i
], NULL
, thread_forks
, NULL
);
122 /* Start the thread that constantly hit a conditional breakpoint
123 that needs to be stepped over. */
124 ret
= pthread_create (&bp_thread
, NULL
, thread_breakpoint
, NULL
);
127 /* Wait for forking to stop. */
128 for (i
= 0; i
< NTHREADS
; i
++)
130 ret
= pthread_join (threads
[i
], NULL
);
135 pthread_join (bp_thread
, NULL
);