1 # Copyright 2008-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 # 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 require supports_process_record
41 standard_testfile machinestate.c ms1.c
42 set precsave [standard_output_file machinestate.precsave]
44 if { [prepare_for_testing "failed to prepare" $testfile \
45 [list $srcfile $srcfile2]] } {
49 set newline "\[\r\n\]+"
51 set beginmain [gdb_get_line_number " begin main " $srcfile]
52 set endmain [gdb_get_line_number " end main " $srcfile]
58 # Activate process record/replay
59 gdb_test_no_output "record" "turn on process record"
61 gdb_test "break $endmain" \
62 "Breakpoint $decimal at .*$srcfile, line $endmain\." \
63 "breakpoint at end of main"
65 gdb_test "continue" "Breakpoint .* end main .*" "run to end of main"
67 gdb_test "record save $precsave" \
68 "Saved core file $precsave with execution log\." \
69 "save process recfile"
71 gdb_test "kill" "" "kill process, prepare to debug log file" \
72 "Kill the program being debugged\\? \\(y or n\\) " "y"
74 gdb_test "record restore $precsave" \
75 "Restored records from core file .*" \
76 "reload prec save file"
78 # Proceed to end of main
80 gdb_test "break $endmain" \
81 "Breakpoint.* file .*$srcfile, line $endmain.*" \
82 "break at end of main"
84 gdb_test_multiple "continue" "go to end of main forward" {
85 -re ".*Breakpoint $decimal,.*$srcfile:$endmain.*$gdb_prompt $" {
86 pass "go to end of main forward"
88 -re -wrap "Reached end of recorded history.*Following forward.*" {
89 pass "go to end of main forward"
97 # Now run backward to each of several points where data is changed.
100 # Module global variable, reverse
101 with_test_prefix "module global variable, reverse" {
102 set breakloc [gdb_get_line_number \
103 "module_global_state: set breakpoint here" $srcfile]
105 gdb_test "tbreak $breakloc" "$srcfile, line $breakloc.*"
106 gdb_test "reverse-continue" "$srcfile:$breakloc.*" "reverse to $breakloc"
108 gdb_test "print aglobal" " = 0" "module global reverse-breakpoint"
109 gdb_test "step" " module global post-change .*"
110 gdb_test "print aglobal" " = 1" "module global forward past bp"
111 gdb_test "reverse-step" "$newline$breakloc.*"
112 gdb_test "print aglobal" " = 0" "module global reverse-step to bp"
115 # Module static variable, reverse
116 with_test_prefix "module static variable, reverse" {
117 set breakloc [gdb_get_line_number \
118 "module_static_state: set breakpoint here" $srcfile]
120 gdb_test "tbreak $breakloc" "$srcfile, line $breakloc.*"
121 gdb_test "reverse-continue" "$srcfile:$breakloc.*" "reverse to $breakloc"
123 gdb_test "print astatic" " = 0" "module static reverse-breakpoint"
124 gdb_test "step" " module static post-change .*"
125 gdb_test "print astatic" " = 1" "module static forward"
126 gdb_test "reverse-step" "$newline$breakloc.*"
127 gdb_test "print astatic" " = 0" "module static reverse-step"
130 # Function static variable, reverse
131 with_test_prefix "function static variable, reverse" {
132 set breakloc [gdb_get_line_number \
133 "function_static_state: set breakpoint here" $srcfile]
135 gdb_test "tbreak $breakloc" "$srcfile, line $breakloc.*"
136 gdb_test "reverse-continue" "$srcfile:$breakloc.*" "reverse to $breakloc"
138 gdb_test "print a" " = 0" "function static reverse-breakpoint"
139 gdb_test "step" " function static post-change .*"
140 gdb_test "print a" " = 1" "function static forward"
141 gdb_test "reverse-step" "$newline$breakloc.*"
142 gdb_test "print a" " = 0" "function static reverse-step"
145 # Auto variable, reverse
146 with_test_prefix "auto variable, reverse" {
147 set breakloc [gdb_get_line_number \
148 "auto_state: set breakpoint here" $srcfile]
150 gdb_test "tbreak $breakloc" "$srcfile, line $breakloc.*"
151 gdb_test "reverse-continue" "$srcfile:$breakloc.*" "reverse to $breakloc"
153 gdb_test "print a" " = 0" "auto var reverse-breakpoint"
154 gdb_test "step" " auto post-change .*"
155 gdb_test "print a" " = 1" "auto var forward"
156 gdb_test "reverse-step" "$newline$breakloc.*"
157 gdb_test "print a" " = 0" "auto var reverse-step"
160 # Register variable, reverse
161 with_test_prefix "register variable, reverse" {
162 set breakloc [gdb_get_line_number \
163 "register_state: set breakpoint here" $srcfile]
165 gdb_test "tbreak $breakloc" "$srcfile, line $breakloc.*"
166 gdb_test "reverse-continue" "$srcfile:$breakloc.*" "reverse to $breakloc"
168 gdb_test "print a" " = 0" "register var reverse-breakpoint"
169 gdb_test "step" " register post-change .*"
170 gdb_test "print a" " = 1" \
171 "register var step post-change, first time"
172 gdb_test "reverse-step" "$newline$breakloc.*"
173 gdb_test "print a" " = 0" "register var reverse step-to"
176 # Proceed to beginning of main
178 gdb_test "tbreak $beginmain" ".*$srcfile, line $beginmain.*" \
179 "tbreak at beginning of main"
180 gdb_test "reverse-continue" ".*$srcfile:$beginmain.*" "reverse to main"
182 # Now repeat tests while replaying forward.
184 # Register variable, forward
185 with_test_prefix "register variable, forward" {
186 set breakloc [gdb_get_line_number \
187 "register_state: set breakpoint here" $srcfile]
189 gdb_test "tbreak $breakloc" "$srcfile, line $breakloc.*"
190 gdb_test "continue" "$srcfile:$breakloc.*" "forward to $breakloc"
192 gdb_test "print a" " = 0" "register var forward-breakpoint"
193 gdb_test "reverse-step" "hide.*"
194 gdb_test "step" "$newline$breakloc.*" "step, 1"
195 gdb_test "print a" " = 0" "register var forward step-to"
196 gdb_test "step" " register post-change .*" "step, 2"
197 gdb_test "print a" " = 1" \
198 "register var step post-change, second time"
201 # Auto variable, forward
202 with_test_prefix "auto variable, forward" {
203 set breakloc [gdb_get_line_number \
204 "auto_state: set breakpoint here" $srcfile]
206 gdb_test "tbreak $breakloc" "$srcfile, line $breakloc.*"
207 gdb_test "continue" "$srcfile:$breakloc.*" "forward to $breakloc"
209 gdb_test "print a" " = 0" "auto var forward-breakpoint"
210 gdb_test "reverse-step" "hide.*"
211 gdb_test "step" "$newline$breakloc.*" "step, 1"
212 gdb_test "print a" " = 0" "auto var forward step-to"
213 gdb_test "step" " auto post-change .*" "step, 2"
214 gdb_test "print a" " = 1" "auto var step post-change"
217 # Function static variable, forward
218 with_test_prefix "function static variable, forward" {
219 set breakloc [gdb_get_line_number \
220 "function_static_state: set breakpoint here" $srcfile]
222 gdb_test "tbreak $breakloc" "$srcfile, line $breakloc.*"
223 gdb_test "continue" "$srcfile:$breakloc.*" "forward to $breakloc"
225 gdb_test "print a" " = 0" "function static forward-breakpoint"
226 gdb_test "reverse-step" "hide.*"
227 gdb_test "step" "$newline$breakloc.*" "step, 1"
228 gdb_test "print a" " = 0" "function static forward step-to"
229 gdb_test "step" " function static post-change .*" "step, 2"
230 gdb_test "print a" " = 1" "function static step post-change"
233 # Module static variable, forward
234 with_test_prefix "module static variable, forward" {
235 set breakloc [gdb_get_line_number \
236 "module_static_state: set breakpoint here" $srcfile]
238 gdb_test "tbreak $breakloc" "$srcfile, line $breakloc.*"
239 gdb_test "continue" "$srcfile:$breakloc.*" "forward to $breakloc"
241 gdb_test "print astatic" " = 0" "module static forward-breakpoint"
242 gdb_test "reverse-step" "hide.*"
243 gdb_test "step" "$newline$breakloc.*" "step, 1"
244 gdb_test "print astatic" " = 0" "module static forward step-to"
245 gdb_test "step" " module static post-change .*" "step, 2"
246 gdb_test "print astatic" " = 1" "module static step post-change"
249 # Module global variable, forward
250 with_test_prefix "module global variable, forward" {
251 set breakloc [gdb_get_line_number \
252 "module_global_state: set breakpoint here" $srcfile]
254 gdb_test "tbreak $breakloc" "$srcfile, line $breakloc.*"
255 gdb_test "continue" "$srcfile:$breakloc.*" "forward to $breakloc"
257 gdb_test "print aglobal" " = 0" "module global forward-breakpoint"
258 gdb_test "reverse-step" "hide.*"
259 gdb_test "step" "$newline$breakloc.*" "step, 1"
260 gdb_test "print aglobal" " = 0" "module global forward step-to"
261 gdb_test "step" " module global post-change .*" "step, 2"
262 gdb_test "print aglobal" " = 1" "module global step post-change"