Remove obsolete test from gdb.cp/var-tag.exp
[binutils-gdb.git] / gdb / testsuite / gdb.threads / watchpoint-fork.exp
blobb9f21b5a4078de952ca7a953a824426575c40da5
1 # Copyright 2012-2024 Free Software Foundation, Inc.
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.
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.
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/>.
16 # Test case for forgotten hw-watchpoints after fork()-off of a process.
18 # The allow_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.
24 set allow_hw_watchpoint_tests_p [allow_hw_watchpoint_tests]
26 set testfile watchpoint-fork
28 # Set DEBUG to 0 or 1 in sources
29 set debug 0
31 proc test {type symbol} {
32     global allow_hw_watchpoint_tests_p
33     global debug
34     with_test_prefix "$type" {
35         global testfile subdir srcdir gdb_prompt
37         set srcfile_type ${srcdir}/${subdir}/${testfile}-${type}.c
39         # no threads
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] \
46                      [list debug additional_flags=-D$symbol \
47                           additional_flags=-DDEBUG=$debug]] == -1} {
48                 return -1
49             }
51             clean_restart $executable
53             if {!$allow_hw_watchpoint_tests_p} {
54                 # The software watchpoint functionality is in GDB an unrelated test.
55                 gdb_test_no_output "set can-use-hw-watchpoints 0"
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
62             }
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.*"
70             if ![runto_main] {
71                 return
72             }
74             gdb_test "watch var" "atchpoint \[0-9\]+: var" "set the watchpoint"
76             # It is never hit but it should not be left over in the fork()ed-off child.
77             if {![allow_hw_breakpoint_tests]} {
78                 set hbreak "break"
79             } else {
80                 set hbreak "hbreak"
81             }
82             gdb_test "$hbreak marker"
84             gdb_breakpoint "mark_exit"
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             }
101         }
103         # threads
105         if {!$allow_hw_watchpoint_tests_p} {
106             # Watchpoint hits would get detected in unexpected threads.
107             return
108         }
110         with_test_prefix "multithreaded" {
111             set executable ${testfile}-${type}-mt
112             set srcfile_main ${srcdir}/${subdir}/${testfile}-mt.c
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"]] != "" } {
118                 untested "failed to compile"
119                 return
120             }
121             clean_restart $executable
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.*"
127             if ![runto_main] {
128                 return
129             }
131             gdb_test "watch var" "atchpoint \[0-9\]+: var" "set the watchpoint"
133             # It should not be left over in the fork()ed-off child.
134             gdb_test "$hbreak marker" {reakpoint [0-9]+.*}
136             gdb_breakpoint "mark_exit"
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"
158             gdb_test "continue" "Continuing\\..*\r\nThread .* hit Breakpoint \[0-9\]+, mark_exit .*" "finish"
159         }
160     }
163 test parent FOLLOW_PARENT
165 # Only GNU/Linux is known to support `set follow-fork-mode child'.
166 if [istarget "*-*-linux*"] {
167     test child FOLLOW_CHILD
168 } else {
169     untested "${testfile}: child"