1 # Copyright 2008-2022 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 # This file is part of the GDB testsuite.
17 # This test tests the restoration of various kinds of machine state
18 # to their original values with a process record log. We will execute
19 # the program forward while it changes various types of data, and
20 # then execute it backward to see if their values get restored.
22 # The types of machine state (data) that are tested are:
25 # function static variable
26 # module static variable
27 # module global variable
30 # various, possibly including...
31 # .bss variable, .data variable, ...
32 # shared library variable
33 # heap variable (pointer)...
34 # overlay variables...
38 # This test suitable only for process record-replay
39 if ![supports_process_record] {
43 standard_testfile machinestate.c ms1.c
44 set precsave [standard_output_file machinestate.precsave]
46 if { [prepare_for_testing "failed to prepare" $testfile \
47 [list $srcfile $srcfile2]] } {
51 set newline "\[\r\n\]+"
53 set beginmain [gdb_get_line_number " begin main " $srcfile]
54 set endmain [gdb_get_line_number " end main " $srcfile]
60 if [supports_process_record] {
61 # Activate process record/replay
62 gdb_test_no_output "record" "turn on process record"
65 gdb_test "break $endmain" \
66 "Breakpoint $decimal at .*$srcfile, line $endmain\." \
67 "breakpoint at end of main"
69 gdb_test "continue" "Breakpoint .* end main .*" "run to end of main"
71 gdb_test "record save $precsave" \
72 "Saved core file $precsave with execution log\." \
73 "save process recfile"
75 gdb_test "kill" "" "kill process, prepare to debug log file" \
76 "Kill the program being debugged\\? \\(y or n\\) " "y"
78 gdb_test "record restore $precsave" \
79 "Restored records from core file .*" \
80 "reload prec save file"
82 # Proceed to end of main
84 gdb_test "break $endmain" \
85 "Breakpoint.* file .*$srcfile, line $endmain.*" \
86 "break at end of main"
88 gdb_test_multiple "continue" "go to end of main forward" {
89 -re ".*Breakpoint $decimal,.*$srcfile:$endmain.*$gdb_prompt $" {
90 pass "go to end of main forward"
92 -re "No more reverse-execution history.* end main .*$gdb_prompt $" {
93 pass "go to end of main forward"
101 # Now run backward to each of several points where data is changed.
104 # Module global variable, reverse
105 with_test_prefix "module global variable, reverse" {
106 set breakloc [gdb_get_line_number \
107 "module_global_state: set breakpoint here" $srcfile]
109 gdb_test "tbreak $breakloc" "$srcfile, line $breakloc.*"
110 gdb_test "reverse-continue" "$srcfile:$breakloc.*" "reverse to $breakloc"
112 gdb_test "print aglobal" " = 0$newline" "module global reverse-breakpoint"
113 gdb_test "step" " module global post-change .*"
114 gdb_test "print aglobal" " = 1$newline" "module global forward past bp"
115 gdb_test "reverse-step" "$newline$breakloc.*"
116 gdb_test "print aglobal" " = 0$newline" "module global reverse-step to bp"
119 # Module static variable, reverse
120 with_test_prefix "module static variable, reverse" {
121 set breakloc [gdb_get_line_number \
122 "module_static_state: set breakpoint here" $srcfile]
124 gdb_test "tbreak $breakloc" "$srcfile, line $breakloc.*"
125 gdb_test "reverse-continue" "$srcfile:$breakloc.*" "reverse to $breakloc"
127 gdb_test "print astatic" " = 0$newline" "module static reverse-breakpoint"
128 gdb_test "step" " module static post-change .*"
129 gdb_test "print astatic" " = 1$newline" "module static forward"
130 gdb_test "reverse-step" "$newline$breakloc.*"
131 gdb_test "print astatic" " = 0$newline" "module static reverse-step"
134 # Function static variable, reverse
135 with_test_prefix "function static variable, reverse" {
136 set breakloc [gdb_get_line_number \
137 "function_static_state: set breakpoint here" $srcfile]
139 gdb_test "tbreak $breakloc" "$srcfile, line $breakloc.*"
140 gdb_test "reverse-continue" "$srcfile:$breakloc.*" "reverse to $breakloc"
142 gdb_test "print a" " = 0$newline" "function static reverse-breakpoint"
143 gdb_test "step" " function static post-change .*"
144 gdb_test "print a" " = 1$newline" "function static forward"
145 gdb_test "reverse-step" "$newline$breakloc.*"
146 gdb_test "print a" " = 0$newline" "function static reverse-step"
149 # Auto variable, reverse
150 with_test_prefix "auto variable, reverse" {
151 set breakloc [gdb_get_line_number \
152 "auto_state: set breakpoint here" $srcfile]
154 gdb_test "tbreak $breakloc" "$srcfile, line $breakloc.*"
155 gdb_test "reverse-continue" "$srcfile:$breakloc.*" "reverse to $breakloc"
157 gdb_test "print a" " = 0$newline" "auto var reverse-breakpoint"
158 gdb_test "step" " auto post-change .*"
159 gdb_test "print a" " = 1$newline" "auto var forward"
160 gdb_test "reverse-step" "$newline$breakloc.*"
161 gdb_test "print a" " = 0$newline" "auto var reverse-step"
164 # Register variable, reverse
165 with_test_prefix "register variable, reverse" {
166 set breakloc [gdb_get_line_number \
167 "register_state: set breakpoint here" $srcfile]
169 gdb_test "tbreak $breakloc" "$srcfile, line $breakloc.*"
170 gdb_test "reverse-continue" "$srcfile:$breakloc.*" "reverse to $breakloc"
172 gdb_test "print a" " = 0$newline" "register var reverse-breakpoint"
173 gdb_test "step" " register post-change .*"
174 gdb_test "print a" " = 1$newline" \
175 "register var step post-change, first time"
176 gdb_test "reverse-step" "$newline$breakloc.*"
177 gdb_test "print a" " = 0$newline" "register var reverse step-to"
180 # Proceed to beginning of main
182 gdb_test "tbreak $beginmain" ".*$srcfile, line $beginmain.*" \
183 "tbreak at beginning of main"
184 gdb_test "reverse-continue" ".*$srcfile:$beginmain.*" "reverse to main"
186 # Now repeat tests while replaying forward.
188 # Register variable, forward
189 with_test_prefix "register variable, forward" {
190 set breakloc [gdb_get_line_number \
191 "register_state: set breakpoint here" $srcfile]
193 gdb_test "tbreak $breakloc" "$srcfile, line $breakloc.*"
194 gdb_test "continue" "$srcfile:$breakloc.*" "forward to $breakloc"
196 gdb_test "print a" " = 0$newline" "register var forward-breakpoint"
197 gdb_test "reverse-step" "hide.*"
198 gdb_test "step" "$newline$breakloc.*" "step, 1"
199 gdb_test "print a" " = 0$newline" "register var forward step-to"
200 gdb_test "step" " register post-change .*" "step, 2"
201 gdb_test "print a" " = 1$newline" \
202 "register var step post-change, second time"
205 # Auto variable, forward
206 with_test_prefix "auto variable, forward" {
207 set breakloc [gdb_get_line_number \
208 "auto_state: set breakpoint here" $srcfile]
210 gdb_test "tbreak $breakloc" "$srcfile, line $breakloc.*"
211 gdb_test "continue" "$srcfile:$breakloc.*" "forward to $breakloc"
213 gdb_test "print a" " = 0$newline" "auto var forward-breakpoint"
214 gdb_test "reverse-step" "hide.*"
215 gdb_test "step" "$newline$breakloc.*" "step, 1"
216 gdb_test "print a" " = 0$newline" "auto var forward step-to"
217 gdb_test "step" " auto post-change .*" "step, 2"
218 gdb_test "print a" " = 1$newline" "auto var step post-change"
221 # Function static variable, forward
222 with_test_prefix "function static variable, forward" {
223 set breakloc [gdb_get_line_number \
224 "function_static_state: set breakpoint here" $srcfile]
226 gdb_test "tbreak $breakloc" "$srcfile, line $breakloc.*"
227 gdb_test "continue" "$srcfile:$breakloc.*" "forward to $breakloc"
229 gdb_test "print a" " = 0$newline" "function static forward-breakpoint"
230 gdb_test "reverse-step" "hide.*"
231 gdb_test "step" "$newline$breakloc.*" "step, 1"
232 gdb_test "print a" " = 0$newline" "function static forward step-to"
233 gdb_test "step" " function static post-change .*" "step, 2"
234 gdb_test "print a" " = 1$newline" "function static step post-change"
237 # Module static variable, forward
238 with_test_prefix "module static variable, forward" {
239 set breakloc [gdb_get_line_number \
240 "module_static_state: set breakpoint here" $srcfile]
242 gdb_test "tbreak $breakloc" "$srcfile, line $breakloc.*"
243 gdb_test "continue" "$srcfile:$breakloc.*" "forward to $breakloc"
245 gdb_test "print astatic" " = 0$newline" "module static forward-breakpoint"
246 gdb_test "reverse-step" "hide.*"
247 gdb_test "step" "$newline$breakloc.*" "step, 1"
248 gdb_test "print astatic" " = 0$newline" "module static forward step-to"
249 gdb_test "step" " module static post-change .*" "step, 2"
250 gdb_test "print astatic" " = 1$newline" "module static step post-change"
253 # Module global variable, forward
254 with_test_prefix "module global variable, forward" {
255 set breakloc [gdb_get_line_number \
256 "module_global_state: set breakpoint here" $srcfile]
258 gdb_test "tbreak $breakloc" "$srcfile, line $breakloc.*"
259 gdb_test "continue" "$srcfile:$breakloc.*" "forward to $breakloc"
261 gdb_test "print aglobal" " = 0$newline" "module global forward-breakpoint"
262 gdb_test "reverse-step" "hide.*"
263 gdb_test "step" "$newline$breakloc.*" "step, 1"
264 gdb_test "print aglobal" " = 0$newline" "module global forward step-to"
265 gdb_test "step" " module global post-change .*" "step, 2"
266 gdb_test "print aglobal" " = 1$newline" "module global step post-change"