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
|
# Copyright (C) 2015-2018 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/>.
if ![supports_reverse] {
return
}
standard_testfile
if {[prepare_for_testing "failed to prepare" $testfile $srcfile \
[list debug]]} {
return -1
}
if { ![runto main] } then {
fail "run to main"
return
}
# Read function name from testcases[N].
proc read_testcase { n } {
global gdb_prompt
set result -1
gdb_test_multiple "print testcases\[${n}\]" "read name of test case ${n}" {
-re "\[$\].*= .*<(.*)>.*$gdb_prompt $" {
set result $expect_out(1,string)
}
-re "$gdb_prompt $" { }
}
return $result
}
# In each function FUNC, GDB turns on process record, and single step
# until program goes to the end of the function. Then, single step
# backward. In each of forward single step and backward single step,
# the contents of registers are saved, and test compares them. If
# there is any differences, a FAIL is emitted.
proc test { func } {
global hex decimal
global gdb_prompt
with_test_prefix "$func" {
gdb_breakpoint $func
gdb_test "continue"
set last_insn ""
set test "disassemble $func"
gdb_test_multiple $test $test {
-re ".*($hex) <\\+$decimal>:\[^\r\n\]+\r\nEnd of assembler dump\.\r\n$gdb_prompt $" {
set last_insn $expect_out(1,string)
}
}
if { $last_insn == "" } {
fail "find the last instruction of function $func"
}
# Activate process record/replay
gdb_test_no_output "record" "turn on process record"
# Registers contents before each forward single step.
set count 0
for {} {$count < 500} {incr count} {
gdb_test_multiple "x/i \$pc" "" {
-re ".* ($hex) <.*>:\[ \t\]*(.*)\r\n$gdb_prompt $" {
set insn_addr $expect_out(1,string)
if [expr {$last_insn == $insn_addr}] {
break
}
set insn_array($count) $expect_out(2,string)
}
}
set pre_regs($count) [capture_command_output "info all-registers" ""]
gdb_test "si" "" ""
}
incr count -1
# Registers contents after each backward single step.
for {set i $count} {$i >= 0} {incr i -1} {
gdb_test "reverse-stepi" "" ""
set post_regs($i) [capture_command_output "info all-registers" ""]
}
# Compare the register contents.
for {set i 0} {$i < $count} {incr i} {
if { ![gdb_assert { [string compare $pre_regs($i) $post_regs($i)] == 0 } \
"compare registers on insn $i:$insn_array($i)"] } {
foreach pre_line [split $pre_regs($i) \n] post_line [split $post_regs($i) \n] {
if { [string compare $pre_line $post_line] } {
verbose -log " -:$pre_line"
verbose -log " +:$post_line"
}
}
}
}
gdb_test "record stop"
}
}
set n_testcases [get_integer_valueof "n_testcases" 0]
if { ${n_testcases} == 0 } {
untested "no test"
return 1
}
for { set i 0 } { ${i} < ${n_testcases} } { incr i } {
set testcase [read_testcase $i]
test $testcase
}
|