1 # Copyright 2009-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 # Based on a file written by Fred Fish. (fnf@cygnus.com)
17 # This file is part of the GDB testsuite. It tests precord dumpfile
18 # debugging with watchpoints.
20 # This test suitable only for process record-replay
21 require supports_process_record
23 standard_testfile watch-reverse.c
24 set precsave [standard_output_file watch.precsave]
26 if { [prepare_for_testing "failed to prepare" $testfile $srcfile] } {
32 # Activate process record/replay
33 gdb_test_no_output "record" "turn on process record"
35 set end_location [gdb_get_line_number "end of main" ]
36 gdb_test "break $end_location" \
37 "Breakpoint $decimal at .*$srcfile, line $end_location\." \
38 "breakpoint at end of main"
40 gdb_test "continue" "Breakpoint .* end of main .*" "run to end of main"
42 gdb_test "record save $precsave" \
43 "Saved core file $precsave with execution log\." \
44 "save process recfile"
46 gdb_test "kill" "" "kill process, prepare to debug log file" \
47 "Kill the program being debugged\\? \\(y or n\\) " "y"
49 gdb_test "record restore $precsave" \
50 "Restored records from core file .*" \
53 # Only software watchpoints can be used in reverse
54 gdb_test_no_output "set can-use-hw-watchpoints 0" ""
56 gdb_test "break marker1" \
57 "Breakpoint $decimal at $hex: file .*$srcfile, line $decimal.*" \
58 "set breakpoint at marker1"
60 gdb_test "break marker2" \
61 "Breakpoint $decimal at $hex: file .*$srcfile, line $decimal.*" \
62 "set breakpoint at marker2"
64 gdb_continue_to_breakpoint "marker1" ".*$srcfile:.*"
66 gdb_test "watch ival3" \
67 ".*\[Ww\]atchpoint $decimal: ival3.*" \
68 "set watchpoint on ival3"
70 # Continue until first change, from -1 to 0
73 ".*\[Ww\]atchpoint.*ival3.*Old value = -1.*New value = 0.*ival3 = count; ival4 = count;.*" \
74 "watchpoint hit, first time"
76 # Continue until the next change, from 0 to 1.
78 ".*\[Ww\]atchpoint.*ival3.*Old value = 0.*New value = 1.*ival3 = count; ival4 = count;.*" \
79 "watchpoint hit, second time"
81 # Continue until the next change, from 1 to 2.
83 ".*\[Ww\]atchpoint.*ival3.*Old value = 1.*New value = 2.*ival3 = count; ival4 = count;.*" \
84 "watchpoint hit, third time"
86 # Continue until the next change, from 2 to 3.
88 ".*\[Ww\]atchpoint.*ival3.*Old value = 2.*New value = 3.*ival3 = count; ival4 = count;.*" \
89 "watchpoint hit, fourth time"
91 # Continue until the next change, from 3 to 4.
92 # Note that this one is outside the loop.
95 ".*\[Ww\]atchpoint.*ival3.*Old value = 3.*New value = 4.*ival3 = count; ival4 = count;.*" \
96 "watchpoint hit, fifth time"
98 # Continue until we hit the finishing marker function.
99 # Make sure we hit no more watchpoints.
101 gdb_continue_to_breakpoint "marker2" ".*$srcfile:.*"
107 gdb_test_no_output "set exec-direction reverse" \
108 "set reverse, first time"
110 # Reverse until the previous change, from 4 to 3
111 # Note that this one is outside the loop
113 gdb_test "continue" \
114 ".*\[Ww\]atchpoint.*ival3.*Old value = 4.*New value = 3.*ival3 = count; ival4 = count;.*" \
115 "watchpoint hit in reverse, first time"
117 # Reverse until the previous change, from 3 to 2.
118 gdb_test "continue" \
119 ".*\[Ww\]atchpoint.*ival3.*Old value = 3.*New value = 2.*ival3 = count; ival4 = count;.*" \
120 "watchpoint hit in reverse, second time"
122 # Reverse until the previous change, from 2 to 1.
123 gdb_test "continue" \
124 ".*\[Ww\]atchpoint.*ival3.*Old value = 2.*New value = 1.*ival3 = count; ival4 = count;.*" \
125 "watchpoint hit in reverse, third time"
127 # Reverse until the previous change, from 1 to 0.
128 gdb_test "continue" \
129 ".*\[Ww\]atchpoint.*ival3.*Old value = 1.*New value = 0.*ival3 = count; ival4 = count;.*" \
130 "watchpoint hit in reverse, fourth time"
132 # Reverse until first change, from 0 to -1
134 gdb_test "continue" \
135 ".*\[Ww\]atchpoint.*ival3.*Old value = 0.*New value = -1.*ival3 = count; ival4 = count;.*" \
136 "watchpoint hit in reverse, fifth time"
138 gdb_test_no_output "set can-use-hw-watchpoints 1" "enable hw watchpoints"
144 gdb_test_no_output "set exec-direction forward" "set forward"
146 # Continue until first change, from -1 to 0
148 gdb_test "continue" \
149 ".*\[Ww\]atchpoint.*ival3.*Old value = -1.*New value = 0.*ival3 = count; ival4 = count;.*" \
150 "watchpoint hit, forward replay, first time"
152 # Continue until the next change, from 0 to 1.
153 gdb_test "continue" \
154 ".*\[Ww\]atchpoint.*ival3.*Old value = 0.*New value = 1.*ival3 = count; ival4 = count;.*" \
155 "watchpoint hit, forward replay, second time"
157 # Continue until the next change, from 1 to 2.
158 gdb_test "continue" \
159 ".*\[Ww\]atchpoint.*ival3.*Old value = 1.*New value = 2.*ival3 = count; ival4 = count;.*" \
160 "watchpoint hit, forward replay, third time"
162 # Continue until the next change, from 2 to 3.
163 gdb_test "continue" \
164 ".*\[Ww\]atchpoint.*ival3.*Old value = 2.*New value = 3.*ival3 = count; ival4 = count;.*" \
165 "watchpoint hit, forward replay, fourth time"
167 # Continue until the next change, from 3 to 4.
168 # Note that this one is outside the loop.
170 gdb_test "continue" \
171 ".*\[Ww\]atchpoint.*ival3.*Old value = 3.*New value = 4.*ival3 = count; ival4 = count;.*" \
172 "watchpoint hit, forward replay, fifth time"
174 # Continue until we hit the finishing marker function.
175 # Make sure we hit no more watchpoints.
177 gdb_test "continue" "marker2 .*" "replay forward to marker2"
183 gdb_test_no_output "set exec-direction reverse" \
184 "set reverse, second time"
186 # Reverse until the previous change, from 4 to 3
187 # Note that this one is outside the loop
189 gdb_test "continue" \
190 ".*\[Ww\]atchpoint.*ival3.*Old value = 4.*New value = 3.*ival3 = count; ival4 = count;.*" \
191 "watchpoint hit in reverse, HW, first time"
193 # Reverse until the previous change, from 3 to 2.
194 gdb_test "continue" \
195 ".*\[Ww\]atchpoint.*ival3.*Old value = 3.*New value = 2.*ival3 = count; ival4 = count;.*" \
196 "watchpoint hit in reverse, HW, second time"
198 # Reverse until the previous change, from 2 to 1.
199 gdb_test "continue" \
200 ".*\[Ww\]atchpoint.*ival3.*Old value = 2.*New value = 1.*ival3 = count; ival4 = count;.*" \
201 "watchpoint hit in reverse, HW, third time"
203 # Reverse until the previous change, from 1 to 0.
204 gdb_test "continue" \
205 ".*\[Ww\]atchpoint.*ival3.*Old value = 1.*New value = 0.*ival3 = count; ival4 = count;.*" \
206 "watchpoint hit in reverse, HW, fourth time"
208 # Reverse until first change, from 0 to -1
210 gdb_test "continue" \
211 ".*\[Ww\]atchpoint.*ival3.*Old value = 0.*New value = -1.*ival3 = count; ival4 = count;.*" \
212 "watchpoint hit in reverse, HW, fifth time"