1 /* This testcase is part of GDB, the GNU debugger.
3 Copyright 2016-2024 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>
28 /* This barrier ensures we only reach the initial breakpoint after all
29 threads have started. */
30 pthread_barrier_t start_threads_barrier
;
32 /* Many threads in order to be fairly sure the process exits while GDB
33 is detaching from each thread in the process, on targets that need
34 to detach from each thread individually. */
37 /* GDB sets a watchpoint here. */
43 /* Threads' entry point. */
46 thread_function (void *arg
)
48 pthread_barrier_wait (&start_threads_barrier
);
52 /* The fork child's entry point. */
57 pthread_t threads
[NTHREADS
];
60 pthread_barrier_init (&start_threads_barrier
, NULL
, NTHREADS
+ 1);
62 for (i
= 0; i
< NTHREADS
; i
++)
63 pthread_create (&threads
[i
], NULL
, thread_function
, NULL
);
64 pthread_barrier_wait (&start_threads_barrier
);
69 /* This is defined by the .exp file if testing the multi-process
73 /* The fork parent's entry point. */
76 parent_function (pid_t child
)
82 ret
= waitpid (child
, &status
, 0);
86 printf ("waitpid, errno=%d (%s)\n", errno
, strerror (errno
));
89 else if (WIFEXITED (status
))
91 printf ("exited, status=%d\n", WEXITSTATUS (status
));
94 else if (WIFSIGNALED (status
))
96 printf ("signaled, sig=%d\n", WTERMSIG (status
));
101 printf ("unexpected, status=%x\n", status
);
123 parent_function (child
);