1 # Copyright 2009, 2010, 2011 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.
19 # This test tests some i386 general instructions with a precord dumpfile.
22 # This test suitable only for process record-replay
23 if ![target_info exists gdb,use_precord] {
32 if ![istarget "i?86-*linux*"] then {
33 verbose "Skipping i386 reverse tests."
37 set testfile "i386-reverse"
38 set srcfile ${testfile}.c
39 set binfile ${objdir}/${subdir}/${testfile}
41 # some targets have leading underscores on assembly symbols.
42 # TODO: detect this automatically
43 set additional_flags ""
44 if [istarget "i?86-*-cygwin*"] then {
45 set additional_flags "additional_flags=-DSYMBOL_PREFIX=\"_\""
48 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug $additional_flags]] != "" } {
53 set end_of_main [gdb_get_line_number " end of main "]
54 set end_of_inc_dec_tests [gdb_get_line_number " end inc_dec_tests "]
60 gdb_reinitialize_dir $srcdir/$subdir
64 if [target_info exists gdb,use_precord] {
65 # Activate process record/replay
66 gdb_test_no_output "record" "Turn on process record"
72 gdb_test "break $end_of_main" \
73 "Breakpoint $decimal at .*/$srcfile, line $end_of_main\." \
76 gdb_test "continue" "Breakpoint .* end of main .*" "run to end of main"
78 gdb_test "record save i386.precsave" \
79 "Saved core file i386.precsave with execution log\." \
80 "save process recfile"
82 gdb_test "kill" "" "Kill process, prepare to debug log file" \
83 "Kill the program being debugged\\? \\(y or n\\) " "y"
85 gdb_test "record restore i386.precsave" \
86 "Program terminated with signal .*" \
87 "reload precord save file"
89 gdb_test "step" "inc .eax.*" "step to inc eax 1st time"
90 send_gdb "info reg eax\n"
92 -re "eax *($hex)\t.*$gdb_prompt " {
93 set preinc_eax $expect_out(1,string)
97 gdb_test "step" "inc .ecx.*" "step to inc ecx 1st time"
98 send_gdb "info reg ecx\n"
100 -re "ecx *($hex)\t.*$gdb_prompt " {
101 set preinc_ecx $expect_out(1,string)
105 gdb_test "step" "inc .edx.*" "step to inc edx 1st time"
106 send_gdb "info reg edx\n"
108 -re "edx *($hex)\t.*$gdb_prompt " {
109 set preinc_edx $expect_out(1,string)
113 gdb_test "step" "inc .ebx.*" "step to inc ebx 1st time"
114 send_gdb "info reg ebx\n"
116 -re "ebx *($hex)\t.*$gdb_prompt " {
117 set preinc_ebx $expect_out(1,string)
121 gdb_test "step" "inc .esp.*" "step to inc esp 1st time"
122 send_gdb "info reg esp\n"
124 -re "esp *($hex)\t.*$gdb_prompt " {
125 set preinc_esp $expect_out(1,string)
129 gdb_test "step" "inc .ebp.*" "step to inc ebp 1st time"
130 send_gdb "info reg ebp\n"
132 -re "ebp *($hex)\t.*$gdb_prompt " {
133 set preinc_ebp $expect_out(1,string)
137 gdb_test "step" "inc .esi.*" "step to inc esi 1st time"
138 send_gdb "info reg esi\n"
140 -re "esi *($hex)\t.*$gdb_prompt " {
141 set preinc_esi $expect_out(1,string)
145 gdb_test "step" "inc .edi.*" "step to inc edi 1st time"
146 send_gdb "info reg edi\n"
148 -re "edi *($hex)\t.*$gdb_prompt " {
149 set preinc_edi $expect_out(1,string)
153 gdb_test "step" "dec .eax.*" "step to dec eax 1st time"
154 send_gdb "info reg eax\n"
156 -re "eax *($hex)\t.*$gdb_prompt " {
157 set predec_eax $expect_out(1,string)
161 gdb_test "step" "dec .ecx.*" "step to dec ecx 1st time"
162 send_gdb "info reg ecx\n"
164 -re "ecx *($hex)\t.*$gdb_prompt " {
165 set predec_ecx $expect_out(1,string)
169 gdb_test "step" "dec .edx.*" "step to dec edx 1st time"
170 send_gdb "info reg edx\n"
172 -re "edx *($hex)\t.*$gdb_prompt " {
173 set predec_edx $expect_out(1,string)
177 gdb_test "step" "dec .ebx.*" "step to dec ebx 1st time"
178 send_gdb "info reg ebx\n"
180 -re "ebx *($hex)\t.*$gdb_prompt " {
181 set predec_ebx $expect_out(1,string)
185 gdb_test "step" "dec .esp.*" "step to dec esp 1st time"
186 send_gdb "info reg esp\n"
188 -re "esp *($hex)\t.*$gdb_prompt " {
189 set predec_esp $expect_out(1,string)
193 gdb_test "step" "dec .ebp.*" "step to dec ebp 1st time"
194 send_gdb "info reg ebp\n"
196 -re "ebp *($hex)\t.*$gdb_prompt " {
197 set predec_ebp $expect_out(1,string)
201 gdb_test "step" "dec .esi.*" "step to dec esi 1st time"
202 send_gdb "info reg esi\n"
204 -re "esi *($hex)\t.*$gdb_prompt " {
205 set predec_esi $expect_out(1,string)
209 gdb_test "step" "dec .edi.*" "step to dec edi 1st time"
210 send_gdb "info reg edi\n"
212 -re "edi *($hex)\t.*$gdb_prompt " {
213 set predec_edi $expect_out(1,string)
217 # gdb_test "step" "end inc_dec_tests .*" "step to end inc_dec_tests 1st time"
219 gdb_test "break $end_of_main" \
220 "Breakpoint $decimal at .* line $end_of_main\." \
221 "set breakpoint at end of main"
223 gdb_test "continue" \
225 "continue to end of main"
227 gdb_test "break $end_of_inc_dec_tests" \
228 "Breakpoint $decimal at .* line $end_of_inc_dec_tests\." \
229 "set breakpoint at end of inc_dec_tests"
231 gdb_test "reverse-continue" \
232 " end inc_dec_tests .*" \
233 "reverse to inc_dec_tests"
236 # Now reverse step, and check register values.
239 gdb_test "info reg edi" "edi *$preinc_edi\t.*" "edi before reverse-dec"
240 gdb_test "reverse-step" "dec .edi.*" "reverse-step to dec edi"
241 gdb_test "info reg edi" "edi *$predec_edi\t.*" "edi after reverse-dec"
243 gdb_test "info reg esi" "esi *$preinc_esi\t.*" "esi before reverse-dec"
244 gdb_test "reverse-step" "dec .esi.*" "reverse-step to dec esi"
245 gdb_test "info reg esi" "esi *$predec_esi\t.*" "esi after reverse-dec"
247 gdb_test "info reg ebp" "ebp *$preinc_ebp\t.*" "ebp before reverse-dec"
248 gdb_test "reverse-step" "dec .ebp.*" "reverse-step to dec ebp"
249 gdb_test "info reg ebp" "ebp *$predec_ebp\t.*" "ebp after reverse-dec"
251 gdb_test "info reg esp" "esp *$preinc_esp\t.*" "esp before reverse-dec"
252 gdb_test "reverse-step" "dec .esp.*" "reverse-step to dec esp"
253 gdb_test "info reg esp" "esp *$predec_esp\t.*" "esp after reverse-dec"
255 gdb_test "info reg ebx" "ebx *$preinc_ebx\t.*" "ebx before reverse-dec"
256 gdb_test "reverse-step" "dec .ebx.*" "reverse-step to dec ebx"
257 gdb_test "info reg ebx" "ebx *$predec_ebx\t.*" "ebx after reverse-dec"
259 gdb_test "info reg edx" "edx *$preinc_edx\t.*" "edx before reverse-dec"
260 gdb_test "reverse-step" "dec .edx.*" "reverse-step to dec edx"
261 gdb_test "info reg edx" "edx *$predec_edx\t.*" "edx after reverse-dec"
263 gdb_test "info reg ecx" "ecx *$preinc_ecx\t.*" "ecx before reverse-dec"
264 gdb_test "reverse-step" "dec .ecx.*" "reverse-step to dec ecx"
265 gdb_test "info reg ecx" "ecx *$predec_ecx\t.*" "ecx after reverse-dec"
267 gdb_test "info reg eax" "eax *$preinc_eax\t.*" "eax before reverse-dec"
268 gdb_test "reverse-step" "dec .eax.*" "reverse-step to dec eax"
269 gdb_test "info reg eax" "eax *$predec_eax\t.*" "eax after reverse-dec"
271 gdb_test "info reg edi" "edi *$predec_edi\t.*" "edi before reverse-inc"
272 gdb_test "reverse-step" "inc .edi.*" "reverse-step to inc edi"
273 gdb_test "info reg edi" "edi *$preinc_edi\t.*" "edi after reverse-inc"
275 gdb_test "info reg esi" "esi *$predec_esi\t.*" "esi before reverse-inc"
276 gdb_test "reverse-step" "inc .esi.*" "reverse-step to inc esi"
277 gdb_test "info reg esi" "esi *$preinc_esi\t.*" "esi after reverse-inc"
279 gdb_test "info reg ebp" "ebp *$predec_ebp\t.*" "ebp before reverse-inc"
280 gdb_test "reverse-step" "inc .ebp.*" "reverse-step to inc ebp"
281 gdb_test "info reg ebp" "ebp *$preinc_ebp\t.*" "ebp after reverse-inc"
283 gdb_test "info reg esp" "esp *$predec_esp\t.*" "esp before reverse-inc"
284 gdb_test "reverse-step" "inc .esp.*" "reverse-step to inc esp"
285 gdb_test "info reg esp" "esp *$preinc_esp\t.*" "esp after reverse-inc"
287 gdb_test "info reg ebx" "ebx *$predec_ebx\t.*" "ebx before reverse-inc"
288 gdb_test "reverse-step" "inc .ebx.*" "reverse-step to inc ebx"
289 gdb_test "info reg ebx" "ebx *$preinc_ebx\t.*" "ebx after reverse-inc"
291 gdb_test "info reg edx" "edx *$predec_edx\t.*" "edx before reverse-inc"
292 gdb_test "reverse-step" "inc .edx.*" "reverse-step to inc edx"
293 gdb_test "info reg edx" "edx *$preinc_edx\t.*" "edx after reverse-inc"
295 gdb_test "info reg ecx" "ecx *$predec_ecx\t.*" "ecx before reverse-inc"
296 gdb_test "reverse-step" "inc .ecx.*" "reverse-step to inc ecx"
297 gdb_test "info reg ecx" "ecx *$preinc_ecx\t.*" "ecx after reverse-inc"
299 gdb_test "info reg eax" "eax *$predec_eax\t.*" "eax before reverse-inc"
300 gdb_test "reverse-step" "inc .eax.*" "reverse-step to inc eax"
301 gdb_test "info reg eax" "eax *$preinc_eax\t.*" "eax after reverse-inc"