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