Commit | Line | Data |
---|---|---|
9107fc8d PA |
1 | /* This testcase is part of GDB, the GNU debugger. |
2 | ||
3666a048 | 3 | Copyright 2012-2021 Free Software Foundation, Inc. |
9107fc8d PA |
4 | |
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. | |
9 | ||
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. | |
14 | ||
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/>. */ | |
17 | ||
762f7747 | 18 | #include <stdlib.h> |
9107fc8d PA |
19 | #include <stdio.h> |
20 | #include <unistd.h> | |
31d913c7 YQ |
21 | #include <limits.h> |
22 | #include <string.h> | |
cbd2b4e3 PA |
23 | #include <pthread.h> |
24 | ||
25 | #define NUM_THREADS 1 | |
26 | ||
27 | static pthread_barrier_t barrier; | |
28 | ||
29 | static void * | |
30 | thread_start (void *arg) | |
31 | { | |
32 | pthread_barrier_wait (&barrier); | |
4483a8e7 SM |
33 | pthread_barrier_wait (&barrier); |
34 | pthread_barrier_wait (&barrier); | |
cbd2b4e3 PA |
35 | |
36 | while (1) | |
37 | sleep (1); | |
38 | return NULL; | |
39 | } | |
40 | ||
41 | static void | |
42 | all_started (void) | |
43 | { | |
44 | } | |
9107fc8d PA |
45 | |
46 | int | |
31d913c7 | 47 | main (int argc, char ** argv) |
9107fc8d | 48 | { |
31d913c7 | 49 | char prog[PATH_MAX]; |
cbd2b4e3 | 50 | pthread_t thread; |
31d913c7 YQ |
51 | int len; |
52 | ||
53 | strcpy (prog, argv[0]); | |
54 | len = strlen (prog); | |
55 | /* Replace "multi-arch-exec" with "multi-arch-exec-hello". */ | |
56 | memcpy (prog + len - 15, "multi-arch-exec-hello", 21); | |
57 | prog[len + 6] = 0; | |
58 | ||
cbd2b4e3 PA |
59 | pthread_barrier_init (&barrier, NULL, NUM_THREADS + 1); |
60 | pthread_create (&thread, NULL, thread_start, NULL); | |
61 | ||
62 | pthread_barrier_wait (&barrier); | |
63 | all_started (); | |
64 | ||
4483a8e7 SM |
65 | /* Avoid races with GDB ptrace-resuming the threads and the exec: ensure |
66 | both threads were resumed by GDB before going into the exec. */ | |
67 | pthread_barrier_wait (&barrier); | |
68 | pthread_barrier_wait (&barrier); | |
69 | ||
31d913c7 YQ |
70 | execl (prog, |
71 | prog, | |
9107fc8d PA |
72 | (char *) NULL); |
73 | perror ("execl failed"); | |
74 | exit (1); | |
75 | } |