Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.reverse / insn-reverse.exp
CommitLineData
88b9d363 1# Copyright (C) 2015-2022 Free Software Foundation, Inc.
f6bb7db3
YQ
2#
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.
7#
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.
12#
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/>.
15
16if ![supports_reverse] {
17 return
18}
19
f6bb7db3
YQ
20standard_testfile
21
5b362f04 22if {[prepare_for_testing "failed to prepare" $testfile $srcfile \
f6bb7db3 23 [list debug]]} {
f6bb7db3
YQ
24 return -1
25}
50441f0f 26if { ![runto_main] } then {
f6bb7db3
YQ
27 fail "run to main"
28 return
29}
30
3263bceb
YQ
31# Read function name from testcases[N].
32
33proc read_testcase { n } {
34 global gdb_prompt
35
36 set result -1
37 gdb_test_multiple "print testcases\[${n}\]" "read name of test case ${n}" {
38 -re "\[$\].*= .*<(.*)>.*$gdb_prompt $" {
39 set result $expect_out(1,string)
40 }
41 -re "$gdb_prompt $" { }
42 }
43
44 return $result
45}
46
f6bb7db3
YQ
47# In each function FUNC, GDB turns on process record, and single step
48# until program goes to the end of the function. Then, single step
49# backward. In each of forward single step and backward single step,
50# the contents of registers are saved, and test compares them. If
51# there is any differences, a FAIL is emitted.
52
9c027c2f 53proc test { func testcase_nr } {
f6bb7db3
YQ
54 global hex decimal
55 global gdb_prompt
56
57 with_test_prefix "$func" {
9c027c2f
TV
58 gdb_start_cmd $testcase_nr
59 gdb_test "" "" "wait for prompt"
60
f6bb7db3
YQ
61 gdb_breakpoint $func
62 gdb_test "continue"
63
64 set last_insn ""
65 set test "disassemble $func"
66 gdb_test_multiple $test $test {
67 -re ".*($hex) <\\+$decimal>:\[^\r\n\]+\r\nEnd of assembler dump\.\r\n$gdb_prompt $" {
68 set last_insn $expect_out(1,string)
69 }
70 }
71 if { $last_insn == "" } {
72 fail "find the last instruction of function $func"
73 }
74
75 # Activate process record/replay
9f058c10 76 gdb_test_no_output "record" "turn on process record"
f6bb7db3
YQ
77
78 # Registers contents before each forward single step.
79 set count 0
9c027c2f 80 set insn_addr ""
f6bb7db3 81 for {} {$count < 500} {incr count} {
a8d13675
TV
82 set prev_insn_addr $insn_addr
83 set insn_addr ""
f6bb7db3
YQ
84 gdb_test_multiple "x/i \$pc" "" {
85 -re ".* ($hex) <.*>:\[ \t\]*(.*)\r\n$gdb_prompt $" {
86 set insn_addr $expect_out(1,string)
a8d13675
TV
87 set insn_array($count) $expect_out(2,string)
88 }
89 }
f6bb7db3 90
a8d13675
TV
91 if { $insn_addr == "" } {
92 break
93 }
f6bb7db3 94
a8d13675
TV
95 if { $last_insn == $insn_addr } {
96 break
97 }
9c027c2f 98
a8d13675
TV
99 if { $prev_insn_addr == $insn_addr } {
100 # Failed to make progress, might have run into SIGILL.
101 unsupported "no progress at: $expect_out(2,string)"
102 break
f6bb7db3
YQ
103 }
104
105 set pre_regs($count) [capture_command_output "info all-registers" ""]
106 gdb_test "si" "" ""
107 }
108
f6bb7db3 109 # Registers contents after each backward single step.
f17727b3 110 for {set i [expr $count - 1]} {$i >= 0} {incr i -1} {
f6bb7db3
YQ
111 gdb_test "reverse-stepi" "" ""
112 set post_regs($i) [capture_command_output "info all-registers" ""]
113 }
114
115 # Compare the register contents.
116 for {set i 0} {$i < $count} {incr i} {
117 if { ![gdb_assert { [string compare $pre_regs($i) $post_regs($i)] == 0 } \
118 "compare registers on insn $i:$insn_array($i)"] } {
119
120 foreach pre_line [split $pre_regs($i) \n] post_line [split $post_regs($i) \n] {
121 if { [string compare $pre_line $post_line] } {
122 verbose -log " -:$pre_line"
123 verbose -log " +:$post_line"
124 }
125 }
126 }
127 }
128 gdb_test "record stop"
129 }
130}
131
3263bceb
YQ
132set n_testcases [get_integer_valueof "n_testcases" 0]
133
134if { ${n_testcases} == 0 } {
bc6c7af4 135 untested "no test"
3263bceb
YQ
136 return 1
137}
138
139for { set i 0 } { ${i} < ${n_testcases} } { incr i } {
140 set testcase [read_testcase $i]
141
9c027c2f 142 test $testcase $i
3263bceb 143}
This page took 0.743936 seconds and 4 git commands to generate.