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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
|
# Copyright 2009 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 some i386 general instructions for reverse execution.
#
if ![target_info exists gdb,can_reverse] {
return
}
if $tracelevel {
strace $tracelevel
}
set prms_id 0
set bug_id 0
if ![istarget "i?86-*linux*"] then {
verbose "Skipping i386 reverse tests."
return
}
set testfile "i386-reverse"
set srcfile ${testfile}.c
set binfile ${objdir}/${subdir}/${testfile}
# some targets have leading underscores on assembly symbols.
# TODO: detect this automatically
set additional_flags ""
if [istarget "i?86-*-cygwin*"] then {
set additional_flags "additional_flags=-DSYMBOL_PREFIX=\"_\""
}
if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable [list debug $additional_flags]] != "" } {
untested i386-reverse
return -1
}
set end_of_main [gdb_get_line_number " end of main "]
set end_of_inc_dec_tests [gdb_get_line_number " end inc_dec_tests "]
# Get things started.
gdb_exit
gdb_start
gdb_reinitialize_dir $srcdir/$subdir
gdb_load ${binfile}
runto main
if [target_info exists gdb,use_precord] {
# Activate process record/replay
gdb_test "record" "" "Turn on process record"
# FIXME: command ought to acknowledge, so we can test if it succeeded.
}
global hex
global decimal
gdb_test "step" "inc .eax.*" "step to inc eax 1st time"
send_gdb "info reg eax\n"
gdb_expect {
-re "eax *($hex)\t.*$gdb_prompt " {
set preinc_eax $expect_out(1,string)
}
}
gdb_test "step" "inc .ecx.*" "step to inc ecx 1st time"
send_gdb "info reg ecx\n"
gdb_expect {
-re "ecx *($hex)\t.*$gdb_prompt " {
set preinc_ecx $expect_out(1,string)
}
}
gdb_test "step" "inc .edx.*" "step to inc edx 1st time"
send_gdb "info reg edx\n"
gdb_expect {
-re "edx *($hex)\t.*$gdb_prompt " {
set preinc_edx $expect_out(1,string)
}
}
gdb_test "step" "inc .ebx.*" "step to inc ebx 1st time"
send_gdb "info reg ebx\n"
gdb_expect {
-re "ebx *($hex)\t.*$gdb_prompt " {
set preinc_ebx $expect_out(1,string)
}
}
gdb_test "step" "inc .esp.*" "step to inc esp 1st time"
send_gdb "info reg esp\n"
gdb_expect {
-re "esp *($hex)\t.*$gdb_prompt " {
set preinc_esp $expect_out(1,string)
}
}
gdb_test "step" "inc .ebp.*" "step to inc ebp 1st time"
send_gdb "info reg ebp\n"
gdb_expect {
-re "ebp *($hex)\t.*$gdb_prompt " {
set preinc_ebp $expect_out(1,string)
}
}
gdb_test "step" "inc .esi.*" "step to inc esi 1st time"
send_gdb "info reg esi\n"
gdb_expect {
-re "esi *($hex)\t.*$gdb_prompt " {
set preinc_esi $expect_out(1,string)
}
}
gdb_test "step" "inc .edi.*" "step to inc edi 1st time"
send_gdb "info reg edi\n"
gdb_expect {
-re "edi *($hex)\t.*$gdb_prompt " {
set preinc_edi $expect_out(1,string)
}
}
gdb_test "step" "dec .eax.*" "step to dec eax 1st time"
send_gdb "info reg eax\n"
gdb_expect {
-re "eax *($hex)\t.*$gdb_prompt " {
set predec_eax $expect_out(1,string)
}
}
gdb_test "step" "dec .ecx.*" "step to dec ecx 1st time"
send_gdb "info reg ecx\n"
gdb_expect {
-re "ecx *($hex)\t.*$gdb_prompt " {
set predec_ecx $expect_out(1,string)
}
}
gdb_test "step" "dec .edx.*" "step to dec edx 1st time"
send_gdb "info reg edx\n"
gdb_expect {
-re "edx *($hex)\t.*$gdb_prompt " {
set predec_edx $expect_out(1,string)
}
}
gdb_test "step" "dec .ebx.*" "step to dec ebx 1st time"
send_gdb "info reg ebx\n"
gdb_expect {
-re "ebx *($hex)\t.*$gdb_prompt " {
set predec_ebx $expect_out(1,string)
}
}
gdb_test "step" "dec .esp.*" "step to dec esp 1st time"
send_gdb "info reg esp\n"
gdb_expect {
-re "esp *($hex)\t.*$gdb_prompt " {
set predec_esp $expect_out(1,string)
}
}
gdb_test "step" "dec .ebp.*" "step to dec ebp 1st time"
send_gdb "info reg ebp\n"
gdb_expect {
-re "ebp *($hex)\t.*$gdb_prompt " {
set predec_ebp $expect_out(1,string)
}
}
gdb_test "step" "dec .esi.*" "step to dec esi 1st time"
send_gdb "info reg esi\n"
gdb_expect {
-re "esi *($hex)\t.*$gdb_prompt " {
set predec_esi $expect_out(1,string)
}
}
gdb_test "step" "dec .edi.*" "step to dec edi 1st time"
send_gdb "info reg edi\n"
gdb_expect {
-re "edi *($hex)\t.*$gdb_prompt " {
set predec_edi $expect_out(1,string)
}
}
# gdb_test "step" "end inc_dec_tests .*" "step to end inc_dec_tests 1st time"
gdb_test "break $end_of_main" \
"Breakpoint $decimal at .* line $end_of_main\." \
"set breakpoint at end of main"
gdb_test "continue" \
" end of main .*" \
"continue to end of main"
gdb_test "break $end_of_inc_dec_tests" \
"Breakpoint $decimal at .* line $end_of_inc_dec_tests\." \
"set breakpoint at end of inc_dec_tests"
gdb_test "reverse-continue" \
" end inc_dec_tests .*" \
"reverse to inc_dec_tests"
#
# Now reverse step, and check register values.
#
gdb_test "info reg edi" "edi *$preinc_edi\t.*" "edi before reverse-dec"
gdb_test "reverse-step" "dec .edi.*" "reverse-step to dec edi"
gdb_test "info reg edi" "edi *$predec_edi\t.*" "edi after reverse-dec"
gdb_test "info reg esi" "esi *$preinc_esi\t.*" "esi before reverse-dec"
gdb_test "reverse-step" "dec .esi.*" "reverse-step to dec esi"
gdb_test "info reg esi" "esi *$predec_esi\t.*" "esi after reverse-dec"
gdb_test "info reg ebp" "ebp *$preinc_ebp\t.*" "ebp before reverse-dec"
gdb_test "reverse-step" "dec .ebp.*" "reverse-step to dec ebp"
gdb_test "info reg ebp" "ebp *$predec_ebp\t.*" "ebp after reverse-dec"
gdb_test "info reg esp" "esp *$preinc_esp\t.*" "esp before reverse-dec"
gdb_test "reverse-step" "dec .esp.*" "reverse-step to dec esp"
gdb_test "info reg esp" "esp *$predec_esp\t.*" "esp after reverse-dec"
gdb_test "info reg ebx" "ebx *$preinc_ebx\t.*" "ebx before reverse-dec"
gdb_test "reverse-step" "dec .ebx.*" "reverse-step to dec ebx"
gdb_test "info reg ebx" "ebx *$predec_ebx\t.*" "ebx after reverse-dec"
gdb_test "info reg edx" "edx *$preinc_edx\t.*" "edx before reverse-dec"
gdb_test "reverse-step" "dec .edx.*" "reverse-step to dec edx"
gdb_test "info reg edx" "edx *$predec_edx\t.*" "edx after reverse-dec"
gdb_test "info reg ecx" "ecx *$preinc_ecx\t.*" "ecx before reverse-dec"
gdb_test "reverse-step" "dec .ecx.*" "reverse-step to dec ecx"
gdb_test "info reg ecx" "ecx *$predec_ecx\t.*" "ecx after reverse-dec"
gdb_test "info reg eax" "eax *$preinc_eax\t.*" "eax before reverse-dec"
gdb_test "reverse-step" "dec .eax.*" "reverse-step to dec eax"
gdb_test "info reg eax" "eax *$predec_eax\t.*" "eax after reverse-dec"
gdb_test "info reg edi" "edi *$predec_edi\t.*" "edi before reverse-inc"
gdb_test "reverse-step" "inc .edi.*" "reverse-step to inc edi"
gdb_test "info reg edi" "edi *$preinc_edi\t.*" "edi after reverse-inc"
gdb_test "info reg esi" "esi *$predec_esi\t.*" "esi before reverse-inc"
gdb_test "reverse-step" "inc .esi.*" "reverse-step to inc esi"
gdb_test "info reg esi" "esi *$preinc_esi\t.*" "esi after reverse-inc"
gdb_test "info reg ebp" "ebp *$predec_ebp\t.*" "ebp before reverse-inc"
gdb_test "reverse-step" "inc .ebp.*" "reverse-step to inc ebp"
gdb_test "info reg ebp" "ebp *$preinc_ebp\t.*" "ebp after reverse-inc"
gdb_test "info reg esp" "esp *$predec_esp\t.*" "esp before reverse-inc"
gdb_test "reverse-step" "inc .esp.*" "reverse-step to inc esp"
gdb_test "info reg esp" "esp *$preinc_esp\t.*" "esp after reverse-inc"
gdb_test "info reg ebx" "ebx *$predec_ebx\t.*" "ebx before reverse-inc"
gdb_test "reverse-step" "inc .ebx.*" "reverse-step to inc ebx"
gdb_test "info reg ebx" "ebx *$preinc_ebx\t.*" "ebx after reverse-inc"
gdb_test "info reg edx" "edx *$predec_edx\t.*" "edx before reverse-inc"
gdb_test "reverse-step" "inc .edx.*" "reverse-step to inc edx"
gdb_test "info reg edx" "edx *$preinc_edx\t.*" "edx after reverse-inc"
gdb_test "info reg ecx" "ecx *$predec_ecx\t.*" "ecx before reverse-inc"
gdb_test "reverse-step" "inc .ecx.*" "reverse-step to inc ecx"
gdb_test "info reg ecx" "ecx *$preinc_ecx\t.*" "ecx after reverse-inc"
gdb_test "info reg eax" "eax *$predec_eax\t.*" "eax before reverse-inc"
gdb_test "reverse-step" "inc .eax.*" "reverse-step to inc eax"
gdb_test "info reg eax" "eax *$preinc_eax\t.*" "eax after reverse-inc"
|