]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.threads/watchpoint-fork.exp
Fix stepping past unwritable kernel helper on nios2-linux-gnu.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.threads / watchpoint-fork.exp
1 # Copyright 2012-2019 Free Software Foundation, Inc.
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
18 set testfile watchpoint-fork
19
20 proc test {type symbol} {
21 with_test_prefix "$type" {
22 global testfile subdir srcdir gdb_prompt
23
24 set srcfile_type ${srcdir}/${subdir}/${testfile}-${type}.c
25
26 # no threads
27
28 with_test_prefix "singlethreaded" {
29 set executable ${testfile}-${type}-st
30 set srcfile_main ${testfile}-st.c
31 if {[build_executable $testfile.exp $executable \
32 [list $srcfile_main ${testfile}-${type}.c] \
33 [list debug additional_flags=-D$symbol]] == -1} {
34 return -1
35 }
36
37 clean_restart $executable
38
39 if [target_info exists gdb,no_hardware_watchpoints] {
40 # The software watchpoint functionality is in GDB an unrelated test.
41 gdb_test_no_output "set can-use-hw-watchpoints 0"
42 # Software watchpoints can be quite slow on remote targets
43 # on this test because it ends up single-stepping through
44 # code to initialize dynamic libraries, etc.
45 set factor 20
46 } else {
47 set factor 1
48 }
49
50 gdb_test "show detach-on-fork" "Whether gdb will detach the child of a fork is on\\."
51 gdb_test_no_output "set follow-fork-mode $type"
52 gdb_test "show follow-fork-mode" "Debugger response to a program call of fork or vfork is \"$type\"\\."
53 # Testcase uses it for the `follow-fork-mode child' type.
54 gdb_test "handle SIGUSR1 nostop noprint pass" "No\[ \t\]+No\[ \t\]+Yes.*"
55
56 if ![runto_main] {
57 return
58 }
59
60 gdb_test "watch var" "atchpoint \[0-9\]+: var" "set the watchpoint"
61
62 # It is never hit but it should not be left over in the fork()ed-off child.
63 if [skip_hw_breakpoint_tests] {
64 set hbreak "break"
65 } else {
66 set hbreak "hbreak"
67 }
68 gdb_test "$hbreak marker"
69
70 gdb_breakpoint "mark_exit"
71
72 with_timeout_factor $factor {
73 gdb_test "continue" \
74 "reakpoint \[0-9\]+, marker.*" "hardware breakpoints work"
75 gdb_test "continue" \
76 "atchpoint \[0-9\]+: var.*Old value = 0.*New value = 1.*forkoff *\\(1\\).*" "watchpoints work"
77 gdb_test "continue" \
78 "reakpoint \[0-9\]+, marker.*" "breakpoint after the first fork"
79 gdb_test "continue" \
80 "atchpoint \[0-9\]+: var.*Old value = 1.*New value = 2.*forkoff *\\(2\\).*" "watchpoint after the first fork"
81 gdb_test "continue" \
82 "reakpoint \[0-9\]+, marker.*" "breakpoint after the second fork"
83 gdb_test "continue" \
84 "atchpoint \[0-9\]+: var.*Old value = 2.*New value = 3.*mark_exit \\(\\);" "watchpoint after the second fork"
85 gdb_test "continue" "Continuing\\..*\r\n(Thread .* hit )?Breakpoint \[0-9\]+, mark_exit .*" "finish"
86 }
87 }
88
89 # threads
90
91 if [target_info exists gdb,no_hardware_watchpoints] {
92 # Watchpoint hits would get detected in unexpected threads.
93 return
94 }
95
96 with_test_prefix "multithreaded" {
97 set executable ${testfile}-${type}-mt
98 set srcfile_main ${srcdir}/${subdir}/${testfile}-mt.c
99 if { [gdb_compile_pthreads "${srcfile_main} ${srcfile_type}" [standard_output_file ${executable}] executable [list debug "additional_flags=-D$symbol -DTHREAD"]] != "" } {
100 untested "failed to compile"
101 return
102 }
103 clean_restart $executable
104
105 gdb_test_no_output "set follow-fork-mode $type"
106 # Testcase uses it for the `follow-fork-mode child' type.
107 gdb_test "handle SIGUSR1 nostop noprint pass" "No\[ \t\]+No\[ \t\]+Yes.*"
108
109 if ![runto_main] {
110 return
111 }
112
113 gdb_test "watch var" "atchpoint \[0-9\]+: var" "set the watchpoint"
114
115 # It should not be left over in the fork()ed-off child.
116 gdb_test "$hbreak marker" {reakpoint [0-9]+.*}
117
118 gdb_breakpoint "mark_exit"
119
120 gdb_test "continue" \
121 "reakpoint \[0-9\]+, marker.*" "hardware breakpoints work"
122 gdb_test "continue" \
123 "atchpoint \[0-9\]+: var.*Old value = 0.*New value = 1.*validity-first.*" "singlethread watchpoints work"
124 gdb_test "continue" \
125 "atchpoint \[0-9\]+: var.*Old value = 1.*New value = 2.*validity-thread-A.*" "multithreaded watchpoints work at A"
126 gdb_test "continue" \
127 "atchpoint \[0-9\]+: var.*Old value = 2.*New value = 3.*validity-thread-B.*" "multithreaded watchpoints work at B"
128 gdb_test "continue" \
129 "reakpoint \[0-9\]+, marker.*" "breakpoint (A) after the first fork"
130 gdb_test "continue" \
131 "atchpoint \[0-9\]+: var.*Old value = 3.*New value = 4.*after-fork1-A.*" "watchpoint A after the first fork"
132 gdb_test "continue" \
133 "atchpoint \[0-9\]+: var.*Old value = 4.*New value = 5.*after-fork1-B.*" "watchpoint B after the first fork"
134 gdb_test "continue" \
135 "reakpoint \[0-9\]+, marker.*" "breakpoint (A) after the second fork"
136 gdb_test "continue" \
137 "atchpoint \[0-9\]+: var.*Old value = 5.*New value = 6.*after-fork2-A.*" "watchpoint A after the second fork"
138 gdb_test "continue" \
139 "atchpoint \[0-9\]+: var.*Old value = 6.*New value = 7.*after-fork2-B.*" "watchpoint B after the second fork"
140 gdb_test "continue" "Continuing\\..*\r\nThread .* hit Breakpoint \[0-9\]+, mark_exit .*" "finish"
141 }
142 }
143 }
144
145 test parent FOLLOW_PARENT
146
147 # Only GNU/Linux is known to support `set follow-fork-mode child'.
148 if [istarget "*-*-linux*"] {
149 test child FOLLOW_CHILD
150 } else {
151 untested "${testfile}: child"
152 }