/* This testcase is part of GDB, the GNU debugger.
Copyright 2015 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see . */
#include
#include
#include
#include
#include
#include
#include
/* Number of threads. Each thread continuously spawns a fork and wait
for it. If we have another thread continuously start a step over,
gdbserver should end up finding new forks while suspending
threads. */
#define NTHREADS 10
pthread_t threads[NTHREADS];
static void *
thread_func (void *arg)
{
while (1)
{
pid_t pid;
pid = fork ();
if (pid > 0)
{
int status;
/* Parent. */
pid = waitpid (pid, &status, 0);
if (pid == -1)
{
perror ("wait");
exit (1);
}
if (!WIFEXITED (status))
{
printf ("Unexpected wait status 0x%x from child %d\n",
status, pid);
}
}
else if (pid == 0)
{
/* Child. */
exit (0);
}
else
{
perror ("fork");
exit (1);
}
}
}
int
main (void)
{
int i;
int ret;
for (i = 0; i < NTHREADS; i++)
{
ret = pthread_create (&threads[i], NULL, thread_func, NULL);
assert (ret == 0);
}
for (i = 0; i < NTHREADS; i++)
{
ret = pthread_join (threads[i], NULL);
assert (ret == 0);
}
/* Don't run forever. */
sleep (180);
return 0;
}