Update year range in copyright notice of all files owned by the GDB project.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.threads / watchpoint-fork.exp
CommitLineData
32d0add0 1# Copyright 2012-2015 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
18set testfile watchpoint-fork
19
20if [is_remote target] {
21 kfail "remote/13584" "gdbserver does not support debugging across fork"
22 return
23}
24
0a251e08
YQ
25proc test {type symbol} {
26 with_test_prefix "$type" {
27 global testfile subdir srcdir gdb_prompt
28
29 set srcfile_type ${srcdir}/${subdir}/${testfile}-${type}.c
30
31 # no threads
32
33 with_test_prefix "singlethreaded" {
34 set executable ${testfile}-${type}-st
35 set srcfile_main ${testfile}-st.c
36 if {[build_executable $testfile.exp $executable \
37 [list $srcfile_main ${testfile}-${type}.c] \
38 [list debug additional_flags=-D$symbol]] == -1} {
39 return -1
40 }
41
42 clean_restart $executable
43
44 if [target_info exists gdb,no_hardware_watchpoints] {
45 # The software watchpoint functionality is in GDB an unrelated test.
46 gdb_test_no_output "set can-use-hw-watchpoints 0"
47 }
48
49 gdb_test "show detach-on-fork" "Whether gdb will detach the child of a fork is on\\."
50 gdb_test_no_output "set follow-fork-mode $type"
51 gdb_test "show follow-fork-mode" "Debugger response to a program call of fork or vfork is \"$type\"\\."
52 # Testcase uses it for the `follow-fork-mode child' type.
53 gdb_test "handle SIGUSR1 nostop noprint pass" "No\[ \t\]+No\[ \t\]+Yes.*"
54
55 if ![runto_main] {
56 return
57 }
58
59 gdb_test "watch var" "atchpoint \[0-9\]+: var" "Set the watchpoint"
60
61 # It is never hit but it should not be left over in the fork()ed-off child.
62 if [skip_hw_breakpoint_tests] {
63 set hbreak "break"
64 } else {
65 set hbreak "hbreak"
66 }
67 gdb_test "$hbreak marker"
68
69 gdb_breakpoint "mark_exit"
70
71 gdb_test "continue" \
72 "reakpoint \[0-9\]+, marker.*" "hardware breakpoints work"
73 gdb_test "continue" \
74 "atchpoint \[0-9\]+: var.*Old value = 0.*New value = 1.*forkoff *\\(1\\).*" "watchpoints work"
75 gdb_test "continue" \
76 "reakpoint \[0-9\]+, marker.*" "breakpoint after the first fork"
77 gdb_test "continue" \
78 "atchpoint \[0-9\]+: var.*Old value = 1.*New value = 2.*forkoff *\\(2\\).*" "watchpoint after the first fork"
79 gdb_test "continue" \
80 "reakpoint \[0-9\]+, marker.*" "breakpoint after the second fork"
81 gdb_test "continue" \
82 "atchpoint \[0-9\]+: var.*Old value = 2.*New value = 3.*mark_exit \\(\\);" "watchpoint after the second fork"
83 gdb_test "continue" "Continuing\\..*\r\nBreakpoint \[0-9\]+, mark_exit .*" "finish"
aed555c9 84 }
0efbbabc 85
0a251e08 86 # threads
aed555c9
PA
87
88 if [target_info exists gdb,no_hardware_watchpoints] {
0a251e08 89 # Watchpoint hits would get detected in unexpected threads.
aed555c9
PA
90 return
91 }
aed555c9 92
0a251e08
YQ
93 with_test_prefix "multithreaded" {
94 set executable ${testfile}-${type}-mt
95 set srcfile_main ${srcdir}/${subdir}/${testfile}-mt.c
96 if { [gdb_compile_pthreads "${srcfile_main} ${srcfile_type}" [standard_output_file ${executable}] executable [list debug "additional_flags=-D$symbol -DTHREAD"]] != "" } {
97 untested ${testfile}.exp
98 return
99 }
100 clean_restart $executable
101
102 gdb_test_no_output "set follow-fork-mode $type"
103 # Testcase uses it for the `follow-fork-mode child' type.
104 gdb_test "handle SIGUSR1 nostop noprint pass" "No\[ \t\]+No\[ \t\]+Yes.*"
105
106 if ![runto_main] {
107 return
108 }
109
110 gdb_test "watch var" "atchpoint \[0-9\]+: var" "Set the watchpoint"
111
112 # It should not be left over in the fork()ed-off child.
113 gdb_test "$hbreak marker" {reakpoint [0-9]+.*}
114
115 gdb_breakpoint "mark_exit"
116
117 gdb_test "continue" \
118 "reakpoint \[0-9\]+, marker.*" "hardware breakpoints work"
119 gdb_test "continue" \
120 "atchpoint \[0-9\]+: var.*Old value = 0.*New value = 1.*validity-first.*" "singlethread watchpoints work"
121 gdb_test "continue" \
122 "atchpoint \[0-9\]+: var.*Old value = 1.*New value = 2.*validity-thread-A.*" "multithreaded watchpoints work at A"
123 gdb_test "continue" \
124 "atchpoint \[0-9\]+: var.*Old value = 2.*New value = 3.*validity-thread-B.*" "multithreaded watchpoints work at B"
125 gdb_test "continue" \
126 "reakpoint \[0-9\]+, marker.*" "breakpoint (A) after the first fork"
127 gdb_test "continue" \
128 "atchpoint \[0-9\]+: var.*Old value = 3.*New value = 4.*after-fork1-A.*" "watchpoint A after the first fork"
129 gdb_test "continue" \
130 "atchpoint \[0-9\]+: var.*Old value = 4.*New value = 5.*after-fork1-B.*" "watchpoint B after the first fork"
131 gdb_test "continue" \
132 "reakpoint \[0-9\]+, marker.*" "breakpoint (A) after the second fork"
133 gdb_test "continue" \
134 "atchpoint \[0-9\]+: var.*Old value = 5.*New value = 6.*after-fork2-A.*" "watchpoint A after the second fork"
135 gdb_test "continue" \
136 "atchpoint \[0-9\]+: var.*Old value = 6.*New value = 7.*after-fork2-B.*" "watchpoint B after the second fork"
137 gdb_test "continue" "Continuing\\..*\r\nBreakpoint \[0-9\]+, mark_exit .*" "finish"
aed555c9 138 }
4403d8e9 139 }
0a251e08 140}
4403d8e9
JK
141
142test parent FOLLOW_PARENT
143
144# Only GNU/Linux is known to support `set follow-fork-mode child'.
145if [istarget "*-*-linux*"] {
146 test child FOLLOW_CHILD
147} else {
148 untested "${testfile}: child"
149}
This page took 0.640237 seconds and 4 git commands to generate.