1/* Test case for forgotten hw-watchpoints after fork()-off of a process. 2 3 Copyright 2012-2020 Free Software Foundation, Inc. 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 9 the Free Software Foundation; either version 3 of the License, or 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 18 along with this program; if not, see <http://www.gnu.org/licenses/>. */ 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#if DEBUG 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); 52#endif 53 54 /* We must not get caught here (against a forgotten breakpoint). */ 55 var++; 56 marker (); 57 58 _exit (exit_code); 59 default: 60#if DEBUG 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); 66#endif 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} 77