]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.threads/watchpoint-fork-parent.c
Update years in copyright notice for the GDB files.
[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
8acc9f48 3 Copyright 2012-2013 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:
43 printf ("child%d: %d\n", nr, (int) getpid ());
44 /* Delay to get both the "child%d" and "parent%d" message printed without
45 a race breaking expect by its endless wait on `$gdb_prompt$':
46 Breakpoint 3, marker () at ../../../gdb/testsuite/gdb.threads/watchpoint-fork.c:33
47 33 }
48 (gdb) parent2: 14223 */
49 i = sleep (1);
50 assert (i == 0);
51
52 /* We must not get caught here (against a forgotten breakpoint). */
53 var++;
54 marker ();
55
56 _exit (exit_code);
57 default:
58 printf ("parent%d: %d\n", nr, (int) child);
59 /* Delay to get both the "child%d" and "parent%d" message printed, see
60 above. */
61 i = sleep (1);
62 assert (i == 0);
63
64 pid_got = wait (&status);
65 assert (pid_got == child);
66 assert (WIFEXITED (status));
67 assert (WEXITSTATUS (status) == exit_code);
68
69 /* We must get caught here (against a false watchpoint removal). */
70 marker ();
71 }
72}