1 /* Test case for forgotten hw-watchpoints after fork()-off of a process.
3 Copyright 2012-2016 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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/>. */
20 #include "watchpoint-fork.h"
29 #include <asm/unistd.h>
31 #define gettid() syscall (__NR_gettid)
33 /* Non-atomic `var++' should not hurt as we synchronize the threads by the STEP
34 variable. Hit-comments need to be duplicated there to catch both at-stops
35 and behind-stops, depending on the target. */
71 var++; /* validity-thread-B */
72 empty (); /* validity-thread-B */
87 var++; /* after-fork1-B */
88 empty (); /* after-fork1-B */
100 var++; /* after-fork2-B */
101 empty (); /* after-fork2-B */
105 /* We must not get caught here (against a forgotten breakpoint). */
108 return (void *) 99UL;
117 setbuf (stdout, NULL);
118 printf ("main: %d\n", (int) gettid ());
120 /* General hardware breakpoints and watchpoints validity. */
122 var++; /* validity-first */
123 empty (); /* validity-first */
125 i = pthread_create (&thread, NULL, start, NULL);
128 var++; /* validity-thread-A */
129 empty (); /* validity-thread-A */
133 i = pthread_yield ();
137 /* Hardware watchpoints got disarmed here. */
140 var++; /* after-fork1-A */
141 empty (); /* after-fork1-A */
144 /* Spawn new thread as it was deleted in the child of FORK. */
145 i = pthread_create (&thread, NULL, start, NULL);
150 i = pthread_yield ();
154 /* A sanity check for double hardware watchpoints removal. */
157 var++; /* after-fork2-A */
158 empty (); /* after-fork2-A */
161 /* Spawn new thread as it was deleted in the child of FORK. */
162 i = pthread_create (&thread, NULL, start, NULL);
166 i = pthread_join (thread, &thread_result);
168 assert (thread_result == (void *) 5UL);