]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.threads/watchpoint-fork-parent.c
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.threads / watchpoint-fork-parent.c
CommitLineData
4403d8e9
JK
1/* Test case for forgotten hw-watchpoints after fork()-off of a process.
2
1d506c26 3 Copyright 2012-2024 Free Software Foundation, Inc.
4403d8e9
JK
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
7785b880 9 the Free Software Foundation; either version 3 of the License, or
4403d8e9
JK
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
7785b880 18 along with this program; if not, see <http://www.gnu.org/licenses/>. */
4403d8e9
JK
19
20#include <string.h>
21#include <errno.h>
22#include <sys/types.h>
23#include <unistd.h>
24#include <assert.h>
25#include <stdio.h>
26#include <sys/wait.h>
27
28#include "watchpoint-fork.h"
29
30void
31forkoff (int nr)
32{
33 pid_t child, pid_got;
34 int exit_code = 42 + nr;
35 int status, i;
36
37 child = fork ();
38 switch (child)
39 {
40 case -1:
41 assert (0);
42 case 0:
ee2a6fc6 43#if DEBUG
4403d8e9
JK
44 printf ("child%d: %d\n", nr, (int) getpid ());
45 /* Delay to get both the "child%d" and "parent%d" message printed without
46 a race breaking expect by its endless wait on `$gdb_prompt$':
47 Breakpoint 3, marker () at ../../../gdb/testsuite/gdb.threads/watchpoint-fork.c:33
48 33 }
49 (gdb) parent2: 14223 */
50 i = sleep (1);
51 assert (i == 0);
ee2a6fc6 52#endif
4403d8e9
JK
53
54 /* We must not get caught here (against a forgotten breakpoint). */
55 var++;
56 marker ();
57
58 _exit (exit_code);
59 default:
ee2a6fc6 60#if DEBUG
4403d8e9
JK
61 printf ("parent%d: %d\n", nr, (int) child);
62 /* Delay to get both the "child%d" and "parent%d" message printed, see
63 above. */
64 i = sleep (1);
65 assert (i == 0);
ee2a6fc6 66#endif
4403d8e9
JK
67
68 pid_got = wait (&status);
69 assert (pid_got == child);
70 assert (WIFEXITED (status));
71 assert (WEXITSTATUS (status) == exit_code);
72
73 /* We must get caught here (against a false watchpoint removal). */
74 marker ();
75 }
76}