]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.threads/watchpoint-fork.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.threads / watchpoint-fork.exp
CommitLineData
213516ef 1# Copyright 2012-2023 Free Software Foundation, Inc.
4403d8e9
JK
2#
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation; either version 3 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16# Test case for forgotten hw-watchpoints after fork()-off of a process.
17
f760c4f2
CL
18# The skip_hw_watchpoint_tests checks if watchpoints are supported by the
19# processor. On PowerPC, the check runs a small test program under gdb
20# to determine if the Power processor supports HW watchpoints. The check
21# must be done before starting the test so as to not disrupt the execution
22# of the actual test.
23
24set skip_hw_watchpoint_tests_p [skip_hw_watchpoint_tests]
25
4403d8e9
JK
26set testfile watchpoint-fork
27
ee2a6fc6
TV
28# Set DEBUG to 0 or 1 in sources
29set debug 0
30
0a251e08 31proc test {type symbol} {
f760c4f2 32 global skip_hw_watchpoint_tests_p
ee2a6fc6 33 global debug
0a251e08
YQ
34 with_test_prefix "$type" {
35 global testfile subdir srcdir gdb_prompt
36
37 set srcfile_type ${srcdir}/${subdir}/${testfile}-${type}.c
38
39 # no threads
40
41 with_test_prefix "singlethreaded" {
42 set executable ${testfile}-${type}-st
43 set srcfile_main ${testfile}-st.c
44 if {[build_executable $testfile.exp $executable \
45 [list $srcfile_main ${testfile}-${type}.c] \
ee2a6fc6
TV
46 [list debug additional_flags=-D$symbol \
47 additional_flags=-DDEBUG=$debug]] == -1} {
0a251e08
YQ
48 return -1
49 }
50
51 clean_restart $executable
52
f760c4f2 53 if {$skip_hw_watchpoint_tests_p} {
0a251e08
YQ
54 # The software watchpoint functionality is in GDB an unrelated test.
55 gdb_test_no_output "set can-use-hw-watchpoints 0"
f489207e
SL
56 # Software watchpoints can be quite slow on remote targets
57 # on this test because it ends up single-stepping through
58 # code to initialize dynamic libraries, etc.
59 set factor 20
60 } else {
61 set factor 1
0a251e08
YQ
62 }
63
64 gdb_test "show detach-on-fork" "Whether gdb will detach the child of a fork is on\\."
65 gdb_test_no_output "set follow-fork-mode $type"
66 gdb_test "show follow-fork-mode" "Debugger response to a program call of fork or vfork is \"$type\"\\."
67 # Testcase uses it for the `follow-fork-mode child' type.
68 gdb_test "handle SIGUSR1 nostop noprint pass" "No\[ \t\]+No\[ \t\]+Yes.*"
69
70 if ![runto_main] {
71 return
72 }
73
cdc7edd7 74 gdb_test "watch var" "atchpoint \[0-9\]+: var" "set the watchpoint"
0a251e08
YQ
75
76 # It is never hit but it should not be left over in the fork()ed-off child.
77 if [skip_hw_breakpoint_tests] {
78 set hbreak "break"
79 } else {
80 set hbreak "hbreak"
81 }
82 gdb_test "$hbreak marker"
83
84 gdb_breakpoint "mark_exit"
85
f489207e
SL
86 with_timeout_factor $factor {
87 gdb_test "continue" \
88 "reakpoint \[0-9\]+, marker.*" "hardware breakpoints work"
89 gdb_test "continue" \
90 "atchpoint \[0-9\]+: var.*Old value = 0.*New value = 1.*forkoff *\\(1\\).*" "watchpoints work"
91 gdb_test "continue" \
92 "reakpoint \[0-9\]+, marker.*" "breakpoint after the first fork"
93 gdb_test "continue" \
94 "atchpoint \[0-9\]+: var.*Old value = 1.*New value = 2.*forkoff *\\(2\\).*" "watchpoint after the first fork"
95 gdb_test "continue" \
96 "reakpoint \[0-9\]+, marker.*" "breakpoint after the second fork"
97 gdb_test "continue" \
98 "atchpoint \[0-9\]+: var.*Old value = 2.*New value = 3.*mark_exit \\(\\);" "watchpoint after the second fork"
99 gdb_test "continue" "Continuing\\..*\r\n(Thread .* hit )?Breakpoint \[0-9\]+, mark_exit .*" "finish"
100 }
aed555c9 101 }
0efbbabc 102
0a251e08 103 # threads
aed555c9 104
f760c4f2 105 if {$skip_hw_watchpoint_tests_p} {
0a251e08 106 # Watchpoint hits would get detected in unexpected threads.
aed555c9
PA
107 return
108 }
aed555c9 109
0a251e08
YQ
110 with_test_prefix "multithreaded" {
111 set executable ${testfile}-${type}-mt
112 set srcfile_main ${srcdir}/${subdir}/${testfile}-mt.c
ee2a6fc6
TV
113 if { [gdb_compile_pthreads "${srcfile_main} ${srcfile_type}" \
114 [standard_output_file ${executable}] executable \
115 [list debug "additional_flags=-D$symbol" \
116 "additional_flags=-DDEBUG=$debug" \
117 "-DTHREAD"]] != "" } {
5b362f04 118 untested "failed to compile"
0a251e08
YQ
119 return
120 }
121 clean_restart $executable
122
123 gdb_test_no_output "set follow-fork-mode $type"
124 # Testcase uses it for the `follow-fork-mode child' type.
125 gdb_test "handle SIGUSR1 nostop noprint pass" "No\[ \t\]+No\[ \t\]+Yes.*"
126
127 if ![runto_main] {
128 return
129 }
130
cdc7edd7 131 gdb_test "watch var" "atchpoint \[0-9\]+: var" "set the watchpoint"
0a251e08
YQ
132
133 # It should not be left over in the fork()ed-off child.
134 gdb_test "$hbreak marker" {reakpoint [0-9]+.*}
135
136 gdb_breakpoint "mark_exit"
137
138 gdb_test "continue" \
139 "reakpoint \[0-9\]+, marker.*" "hardware breakpoints work"
140 gdb_test "continue" \
141 "atchpoint \[0-9\]+: var.*Old value = 0.*New value = 1.*validity-first.*" "singlethread watchpoints work"
142 gdb_test "continue" \
143 "atchpoint \[0-9\]+: var.*Old value = 1.*New value = 2.*validity-thread-A.*" "multithreaded watchpoints work at A"
144 gdb_test "continue" \
145 "atchpoint \[0-9\]+: var.*Old value = 2.*New value = 3.*validity-thread-B.*" "multithreaded watchpoints work at B"
146 gdb_test "continue" \
147 "reakpoint \[0-9\]+, marker.*" "breakpoint (A) after the first fork"
148 gdb_test "continue" \
149 "atchpoint \[0-9\]+: var.*Old value = 3.*New value = 4.*after-fork1-A.*" "watchpoint A after the first fork"
150 gdb_test "continue" \
151 "atchpoint \[0-9\]+: var.*Old value = 4.*New value = 5.*after-fork1-B.*" "watchpoint B after the first fork"
152 gdb_test "continue" \
153 "reakpoint \[0-9\]+, marker.*" "breakpoint (A) after the second fork"
154 gdb_test "continue" \
155 "atchpoint \[0-9\]+: var.*Old value = 5.*New value = 6.*after-fork2-A.*" "watchpoint A after the second fork"
156 gdb_test "continue" \
157 "atchpoint \[0-9\]+: var.*Old value = 6.*New value = 7.*after-fork2-B.*" "watchpoint B after the second fork"
f303dbd6 158 gdb_test "continue" "Continuing\\..*\r\nThread .* hit Breakpoint \[0-9\]+, mark_exit .*" "finish"
aed555c9 159 }
4403d8e9 160 }
0a251e08 161}
4403d8e9
JK
162
163test parent FOLLOW_PARENT
164
165# Only GNU/Linux is known to support `set follow-fork-mode child'.
166if [istarget "*-*-linux*"] {
167 test child FOLLOW_CHILD
168} else {
169 untested "${testfile}: child"
170}