]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.base/step-test.exp
daily update
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / step-test.exp
CommitLineData
05b4d525 1# Copyright 1997, 1998, 1999, 2000, 2002 Free Software Foundation, Inc.
c906108c
SS
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 2 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, write to the Free Software
15# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
16
17# Please email any bugs, comments, and/or additions to this file to:
18# bug-gdb@prep.ai.mit.edu
19
20# use this to debug:
21#
22#log_user 1
23
24# step-test.exp -- Expect script to test stepping in gdb
25
26if $tracelevel then {
27 strace $tracelevel
28}
29
30set testfile step-test
31set srcfile ${srcdir}/${subdir}/${testfile}.c
32set binfile ${objdir}/${subdir}/${testfile}
33
34remote_exec build "rm -f ${binfile}"
35if { [gdb_compile "${srcfile}" "${binfile}" executable {debug}] != "" } {
36 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
37}
38
39gdb_exit
40gdb_start
41gdb_reinitialize_dir $srcdir/$subdir
42gdb_load ${binfile}
43
44if ![runto_main] then {
45 fail "Can't run to main"
46 return 0
47}
48
7a292a7a
SS
49# Set a breakpoint at line 45, if stepi then finish fails, we would
50# run to the end of the program, which would mess up the rest of the tests.
51
c906108c
SS
52# Vanilla step/next
53#
54gdb_test "next" ".*${decimal}.*x = 1;.*" "next 1"
55gdb_test "step" ".*${decimal}.*y = 2;.*" "step 1"
56
57# With count
58#
59gdb_test "next 2" ".*${decimal}.*w = w.*2;.*" "next 2"
60gdb_test "step 3" ".*${decimal}.*z = z.*5;.*" "step 3"
61gdb_test "next" ".*${decimal}.*callee.*OVER.*" "next 3"
62
63# Step over call
64#
65gdb_test "next" ".*${decimal}.*callee.*INTO.*" "next over"
66
67# Step into call
68#
085dd6e6 69gdb_test "step" ".*${decimal}.*myglob.*" "step into"
c906108c
SS
70
71# Step out of call
72#
73# I wonder if this is really portable. Are there any caller-saves
74# platforms, on which `finish' will return you to some kind of pop
75# instruction, which is attributed to the line containing the function
76# call?
085dd6e6 77
8216cda9
KB
78# On PA64, we end up at a different instruction than PA32.
79# On IA-64, we also end up on callee instead of on the next line due
80# to the restoration of the global pointer (which is a caller-save).
81if { [istarget "hppa2.0w-hp-hpux*"] || [istarget "ia64-*-*"]} {
085dd6e6
JM
82 send_gdb "finish\n"
83 gdb_expect {
84 -re ".*${decimal}.*a.*5.*= a.*3.*$gdb_prompt $" { pass "step out 1" }
85 -re ".*${decimal}.*callee.*INTO.*$gdb_prompt $" { pass "step out 2" }
86 timeout { fail "step out" }
87 }
88} else {
89 gdb_test "finish" ".*${decimal}.*a.*5.*= a.*3.*" "step out"
90}
c906108c
SS
91
92### Testing nexti and stepi.
93###
94### test_i NAME COMMAND HERE THERE
95###
96### Send COMMAND to gdb over and over, while the output matches the
97### regexp HERE, followed by the gdb prompt. Pass if the output
98### eventually matches the regexp THERE, followed by the gdb prompt;
99### fail if we have to iterate more than a hundred times, we time out
100### talking to gdb, or we get output which is neither HERE nor THERE. :)
101###
102### Use NAME as the name of the test.
103###
104### The exact regexps used are "$HERE.*$gdb_prompt $"
105### and "$THERE.*$gdb_prompt $"
106###
107proc test_i {name command here there} {
108 global gdb_prompt
109
110 set i 0
111 while 1 {
112 send_gdb "${command}\n"
113 gdb_expect {
114 -re "$here.*$gdb_prompt $" {
115 # Okay, we're still on the same line. Just step again.
116 }
117 -re "$there.*$gdb_prompt $" {
118 # We've reached the next line. Rah.
119 pass "$name"
120 return
121 }
122 -re "$gdb_prompt $" {
123 # We got something else. Fail.
124 fail "$name"
125 return
126 }
127 timeout {
128 fail "$name (timeout)"
129 return
130 }
131 }
132
133 # Have we gone for too many steps without seeing any progress?
134 if {[incr i] >= 100} {
135 fail "$name (no progress after 100 steps)"
136 return
137 }
138 }
139}
140
141test_i "stepi to next line" "stepi" \
142 ".*${decimal}.*a.*5.* = a.*3" \
143 ".*${decimal}.*callee.*STEPI"
144test_i "stepi into function" "stepi" \
145 ".*${decimal}.*callee.*STEPI" \
7a292a7a 146 ".*callee \\(\\) at .*step-test\\.c"
dfcd3bfb
JM
147
148# Continue to step until we reach the function's body. This makes it
149# more likely that we've actually completed the prologue, so "finish"
150# will work.
151test_i "stepi into function's first source line" "stepi" \
152 ".*${decimal}.*int callee" \
153 ".*${decimal}.*myglob.*; return 0;"
154
7a292a7a
SS
155# Have to be careful here, if the finish does not work,
156# then we may run to the end of the program, which
157# will cause erroneous failures in the rest of the tests
7a292a7a
SS
158send_gdb "finish\n"
159gdb_expect {
160 -re ".*(Program received|Program exited).*$gdb_prompt $" {
7a292a7a
SS
161 # Oops... We ran to the end of the program... Better reset
162 if {![runto_main]} then {
163 fail "Can't run to main"
164 return 0
165 }
166 if {![runto step-test.c:45]} {
167 fail "Can't run to line 45"
168 return 0
169 }
170 fail "stepi: finish call"
171 }
172 -re ".*${decimal}.*callee.*NEXTI.*$gdb_prompt $" {
7a292a7a
SS
173 pass "stepi: finish call"
174 }
085dd6e6 175 -re ".*${decimal}.*callee.*STEPI.*$gdb_prompt $" {
8216cda9
KB
176 # On PA64, we end up at a different instruction than PA32.
177 # On IA-64, we end up on callee instead of on the following line due
178 # to the restoration of the global pointer.
179 if { [istarget "hppa2.0w-hp-hpux*"] || [istarget "ia64-*-*"] } {
085dd6e6
JM
180 pass "stepi: finish call 2"
181 } else {
182 fail "stepi: finish call 2"
183 return
184 }
185 }
7a292a7a
SS
186 -re "$gdb_prompt $" {
187 # We got something else. Fail.
188 fail "stepi: finish call"
189 return
190 }
191 timeout {
8b93c638 192 fail "stepi: finish call (timeout)"
7a292a7a
SS
193 return
194 }
195}
196
c906108c
SS
197test_i "nexti over function" "nexti" \
198 ".*${decimal}.*callee.*NEXTI" \
199 ".*${decimal}.*y = w \\+ z;"
200
201# On some platforms, if we try to step into a function call that
202# passes a large structure by value, then we actually end up stepping
203# into memcpy, bcopy, or some such --- GCC emits the call to pass the
204# argument. Opinion is bitterly divided about whether this is the
205# right behavior for GDB or not, but we'll catch it here, so folks
206# won't forget about it.
207
c2d11a7d
JM
208gdb_test \
209 "break [gdb_get_line_number "step-test.exp: large struct by value"]" \
210 ".*Breakpoint.* at .*" \
211 "set breakpoint at call to large_struct_by_value"
c906108c
SS
212gdb_test "continue" \
213 ".*Breakpoint ${decimal},.*large_struct_by_value.*" \
214 "run to pass large struct"
05b4d525
FF
215send_gdb "step\n"
216gdb_expect {
217 -re ".*step-test.exp: arrive here 1.*$gdb_prompt $" {
218 pass "large struct by value"
219 }
220 -re ".*(memcpy|bcopy).*$gdb_prompt $" {
221 send_gdb "finish\n" ; gdb_expect -re "$gdb_prompt $"
222 send_gdb "step\n"
223 exp_continue
224 }
225 -re ".*$gdb_prompt $" {
226 fail "large struct by value"
227 }
228 timeout {
229 fail "large struct by value (timeout)"
230 }
231}
c906108c 232
7a292a7a 233gdb_continue_to_end "step-test.exp"
c906108c
SS
234
235return 0