xref: /netbsd-src/external/gpl3/gdb.old/dist/gdb/testsuite/gdb.multi/watchpoint-multi-exit.c (revision 6881a4007f077b54e5f51159c52b9b25f57deb0d)
1 /* This testcase is part of GDB, the GNU debugger.
2 
3    Copyright 2016-2023 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 <unistd.h>
19 #include <stdlib.h>
20 #include <sys/types.h>
21 #include <sys/wait.h>
22 
23 /* GDB sets watchpoint here.  */
24 static volatile int __attribute__ ((used)) globalvar;
25 
26 /* Whether it's expected that the child exits with a signal, vs
27    exiting normally.  GDB sets this.  */
28 static volatile int expect_signaled;
29 
30 static void
31 marker (void)
32 {
33 }
34 
35 static void
36 child_function (void)
37 {
38 }
39 
40 int
41 main (void)
42 {
43   pid_t child;
44 
45   child = fork ();
46   if (child == -1)
47     exit (1);
48   else if (child != 0)
49     {
50       int status, ret;
51 
52       ret = waitpid (child, &status, 0);
53       if (ret == -1)
54 	exit (2);
55       else if (expect_signaled && !WIFSIGNALED (status))
56 	exit (3);
57       else if (!expect_signaled && !WIFEXITED (status))
58 	exit (4);
59       else
60 	marker ();
61     }
62   else
63     child_function ();
64 
65   exit (0);
66 }
67