1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
|
# Copyright 2008-2016 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# This file is part of the GDB testsuite.
# This test tests the restoration of various kinds of machine state
# to their original values with a process record log. We will execute
# the program forward while it changes various types of data, and
# then execute it backward to see if their values get restored.
#
# The types of machine state (data) that are tested are:
# register variable
# auto variable
# function static variable
# module static variable
# module global variable
#
# TODO:
# various, possibly including...
# .bss variable, .data variable, ...
# shared library variable
# heap variable (pointer)...
# overlay variables...
# Test forward replay
#
# This test suitable only for process record-replay
if ![supports_process_record] {
return
}
standard_testfile machinestate.c ms1.c
set precsave [standard_output_file machinestate.precsave]
if { [prepare_for_testing $testfile.exp $testfile \
[list $srcfile $srcfile2]] } {
return -1
}
set newline "\[\r\n\]+"
set beginmain [gdb_get_line_number " begin main " $srcfile]
set endmain [gdb_get_line_number " end main " $srcfile]
# Test begins
runto main
if [supports_process_record] {
# Activate process record/replay
gdb_test_no_output "record" "turn on process record"
}
gdb_test "break $endmain" \
"Breakpoint $decimal at .*$srcfile, line $endmain\." \
"breakpoint at end of main"
gdb_test "continue" "Breakpoint .* end main .*" "run to end of main"
gdb_test "record save $precsave" \
"Saved core file $precsave with execution log\." \
"save process recfile"
gdb_test "kill" "" "kill process, prepare to debug log file" \
"Kill the program being debugged\\? \\(y or n\\) " "y"
gdb_test "record restore $precsave" \
"Restored records from core file .*" \
"reload prec save file"
# Proceed to end of main
gdb_test "break $endmain" \
"Breakpoint.* file .*$srcfile, line $endmain.*" ""
gdb_test_multiple "continue" "go to end of main forward" {
-re ".*Breakpoint $decimal,.*$srcfile:$endmain.*$gdb_prompt $" {
pass "go to end of main forward"
}
-re "No more reverse-execution history.* end main .*$gdb_prompt $" {
pass "go to end of main forward"
}
}
###
###
###
# Now run backward to each of several points where data is changed.
#
# Module global variable, reverse
set breakloc [gdb_get_line_number \
"module_global_state: set breakpoint here" $srcfile]
gdb_test "tbreak $breakloc" ".*$srcfile, line $breakloc.*" ""
gdb_test "reverse-continue" ".*$srcfile:$breakloc.*" "reverse to $breakloc"
gdb_test "print aglobal" ".* = 0$newline" "module global reverse-breakpoint"
gdb_test "step" ".* module global post-change .*" ""
gdb_test "print aglobal" ".* = 1$newline" "module global forward past bp"
gdb_test "reverse-step" ".*$newline$breakloc.*" ""
gdb_test "print aglobal" ".* = 0$newline" "module global reverse-step to bp"
# Module static variable, reverse
set breakloc [gdb_get_line_number \
"module_static_state: set breakpoint here" $srcfile]
gdb_test "tbreak $breakloc" ".*$srcfile, line $breakloc.*" ""
gdb_test "reverse-continue" ".*$srcfile:$breakloc.*" "reverse to $breakloc"
gdb_test "print astatic" ".* = 0$newline" "module static reverse-breakpoint"
gdb_test "step" ".* module static post-change .*" ""
gdb_test "print astatic" ".* = 1$newline" "module static forward"
gdb_test "reverse-step" ".*$newline$breakloc.*" ""
gdb_test "print astatic" ".* = 0$newline" "module static reverse-step"
# Function static variable, reverse
set breakloc [gdb_get_line_number \
"function_static_state: set breakpoint here" $srcfile]
gdb_test "tbreak $breakloc" ".*$srcfile, line $breakloc.*" ""
gdb_test "reverse-continue" ".*$srcfile:$breakloc.*" "reverse to $breakloc"
gdb_test "print a" ".* = 0$newline" "function static reverse-breakpoint"
gdb_test "step" ".* function static post-change .*" ""
gdb_test "print a" ".* = 1$newline" "function static forward"
gdb_test "reverse-step" ".*$newline$breakloc.*" ""
gdb_test "print a" ".* = 0$newline" "function static reverse-step"
# Auto variable, reverse
set breakloc [gdb_get_line_number \
"auto_state: set breakpoint here" $srcfile]
gdb_test "tbreak $breakloc" ".*$srcfile, line $breakloc.*" ""
gdb_test "reverse-continue" ".*$srcfile:$breakloc.*" "reverse to $breakloc"
gdb_test "print a" ".* = 0$newline" "auto var reverse-breakpoint"
gdb_test "step" ".* auto post-change .*" ""
gdb_test "print a" ".* = 1$newline" "auto var forward"
gdb_test "reverse-step" ".*$newline$breakloc.*" ""
gdb_test "print a" ".* = 0$newline" "auto var reverse-step"
# Register variable, reverse
set breakloc [gdb_get_line_number \
"register_state: set breakpoint here" $srcfile]
gdb_test "tbreak $breakloc" ".*$srcfile, line $breakloc.*" ""
gdb_test "reverse-continue" ".*$srcfile:$breakloc.*" "reverse to $breakloc"
gdb_test "print a" ".* = 0$newline" "register var reverse-breakpoint"
gdb_test "step" ".* register post-change .*" ""
gdb_test "print a" ".* = 1$newline" "register var step post-change"
gdb_test "reverse-step" ".*$newline$breakloc.*" ""
gdb_test "print a" ".* = 0$newline" "register var reverse step-to"
# Proceed to beginning of main
gdb_test "tbreak $beginmain" ".*$srcfile, line $beginmain.*" ""
gdb_test "reverse-continue" ".*$srcfile:$beginmain.*" "reverse to main"
# Now repeat tests while replaying forward.
# Register variable, forward
set breakloc [gdb_get_line_number \
"register_state: set breakpoint here" $srcfile]
gdb_test "tbreak $breakloc" ".*$srcfile, line $breakloc.*" ""
gdb_test "continue" ".*$srcfile:$breakloc.*" "forward to $breakloc"
gdb_test "print a" ".* = 0$newline" "register var forward-breakpoint"
gdb_test "reverse-step" ".*hide.*" ""
gdb_test "step" ".*$newline$breakloc.*" ""
gdb_test "print a" ".* = 0$newline" "register var forward step-to"
gdb_test "step" ".* register post-change .*" ""
gdb_test "print a" ".* = 1$newline" "register var step post-change"
# Auto variable, forward
set breakloc [gdb_get_line_number \
"auto_state: set breakpoint here" $srcfile]
gdb_test "tbreak $breakloc" ".*$srcfile, line $breakloc.*" ""
gdb_test "continue" ".*$srcfile:$breakloc.*" "forward to $breakloc"
gdb_test "print a" ".* = 0$newline" "auto var forward-breakpoint"
gdb_test "reverse-step" ".*hide.*" ""
gdb_test "step" ".*$newline$breakloc.*" ""
gdb_test "print a" ".* = 0$newline" "auto var forward step-to"
gdb_test "step" ".* auto post-change .*" ""
gdb_test "print a" ".* = 1$newline" "auto var step post-change"
# Function static variable, forward
set breakloc [gdb_get_line_number \
"function_static_state: set breakpoint here" $srcfile]
gdb_test "tbreak $breakloc" ".*$srcfile, line $breakloc.*" ""
gdb_test "continue" ".*$srcfile:$breakloc.*" "forward to $breakloc"
gdb_test "print a" ".* = 0$newline" "function static forward-breakpoint"
gdb_test "reverse-step" ".*hide.*" ""
gdb_test "step" ".*$newline$breakloc.*" ""
gdb_test "print a" ".* = 0$newline" "function static forward step-to"
gdb_test "step" ".* function static post-change .*" ""
gdb_test "print a" ".* = 1$newline" "function static step post-change"
# Module static variable, forward
set breakloc [gdb_get_line_number \
"module_static_state: set breakpoint here" $srcfile]
gdb_test "tbreak $breakloc" ".*$srcfile, line $breakloc.*" ""
gdb_test "continue" ".*$srcfile:$breakloc.*" "forward to $breakloc"
gdb_test "print astatic" ".* = 0$newline" "module static forward-breakpoint"
gdb_test "reverse-step" ".*hide.*" ""
gdb_test "step" ".*$newline$breakloc.*" ""
gdb_test "print astatic" ".* = 0$newline" "module static forward step-to"
gdb_test "step" ".* module static post-change .*" ""
gdb_test "print astatic" ".* = 1$newline" "module static step post-change"
# Module global variable, forward
set breakloc [gdb_get_line_number \
"module_global_state: set breakpoint here" $srcfile]
gdb_test "tbreak $breakloc" ".*$srcfile, line $breakloc.*" ""
gdb_test "continue" ".*$srcfile:$breakloc.*" "forward to $breakloc"
gdb_test "print aglobal" ".* = 0$newline" "module global forward-breakpoint"
gdb_test "reverse-step" ".*hide.*" ""
gdb_test "step" ".*$newline$breakloc.*" ""
gdb_test "print aglobal" ".* = 0$newline" "module global forward step-to"
gdb_test "step" ".* module global post-change .*" ""
gdb_test "print aglobal" ".* = 1$newline" "module global step post-change"
|