]> Git Repo - binutils.git/blob - gdb/testsuite/gdb.threads/multiple-step-overs.c
Automatic date update in version.in
[binutils.git] / gdb / testsuite / gdb.threads / multiple-step-overs.c
1 /* This testcase is part of GDB, the GNU debugger.
2
3    Copyright 2009-2022 Free Software Foundation, Inc.
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
18 #include <pthread.h>
19 #include <unistd.h>
20 #include <stdlib.h>
21 #include <signal.h>
22
23 unsigned int args[2];
24
25 pthread_barrier_t barrier;
26 pthread_t child_thread_2, child_thread_3;
27
28 void
29 sigusr1_handler (int signo)
30 {
31 }
32
33 void
34 callme (void)
35 {
36 }
37
38 void *
39 child_function_3 (void *arg)
40 {
41   int my_number =  (long) arg;
42   volatile int *myp = (int *) &args[my_number];
43
44   pthread_barrier_wait (&barrier);
45
46   while (*myp > 0)
47     {
48       (*myp) ++;
49       callme (); /* set breakpoint thread 3 here */
50     }
51
52   pthread_exit (NULL);
53 }
54
55 void *
56 child_function_2 (void *arg)
57 {
58   int my_number =  (long) arg;
59   volatile int *myp = (int *) &args[my_number];
60
61   pthread_barrier_wait (&barrier);
62
63   while (*myp > 0)
64     {
65       (*myp) ++;
66       callme (); /* set breakpoint thread 2 here */
67     }
68
69   pthread_exit (NULL);
70 }
71
72 static int
73 wait_threads (void)
74 {
75   return 1; /* in wait_threads */
76 }
77
78 int
79 main ()
80 {
81   int res;
82   long i;
83
84   signal (SIGUSR1, sigusr1_handler);
85
86   /* Call these early so that PLTs for these are resolved soon,
87      instead of in the threads.  RTLD_NOW should work as well.  */
88   usleep (0);
89   pthread_barrier_init (&barrier, NULL, 1);
90   pthread_barrier_wait (&barrier);
91
92   pthread_barrier_init (&barrier, NULL, 2);
93
94   i = 0;
95   args[i] = 1;
96   res = pthread_create (&child_thread_2,
97                         NULL, child_function_2, (void *) i);
98   pthread_barrier_wait (&barrier);
99   callme ();
100
101   i = 1;
102   args[i] = 1;
103   res = pthread_create (&child_thread_3,
104                         NULL, child_function_3, (void *) i);
105   pthread_barrier_wait (&barrier);
106   wait_threads (); /* set wait-threads breakpoint here */
107
108   pthread_join (child_thread_2, NULL);
109   pthread_join (child_thread_3, NULL);
110
111   exit(EXIT_SUCCESS);
112 }
This page took 0.030528 seconds and 4 git commands to generate.