]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.base/step-test.exp
* gdb.base/step-test.exp: Allow MIPS to return to the line of a
[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).
f4f00b1f
DJ
81# Similarly on MIPS PIC targets.
82if { [istarget "hppa2.0w-hp-hpux*"] || [istarget "ia64-*-*"] || [istarget "mips*-*-*"]} {
085dd6e6
JM
83 send_gdb "finish\n"
84 gdb_expect {
85 -re ".*${decimal}.*a.*5.*= a.*3.*$gdb_prompt $" { pass "step out 1" }
86 -re ".*${decimal}.*callee.*INTO.*$gdb_prompt $" { pass "step out 2" }
87 timeout { fail "step out" }
88 }
89} else {
90 gdb_test "finish" ".*${decimal}.*a.*5.*= a.*3.*" "step out"
91}
c906108c
SS
92
93### Testing nexti and stepi.
94###
95### test_i NAME COMMAND HERE THERE
96###
97### Send COMMAND to gdb over and over, while the output matches the
98### regexp HERE, followed by the gdb prompt. Pass if the output
99### eventually matches the regexp THERE, followed by the gdb prompt;
100### fail if we have to iterate more than a hundred times, we time out
101### talking to gdb, or we get output which is neither HERE nor THERE. :)
102###
103### Use NAME as the name of the test.
104###
105### The exact regexps used are "$HERE.*$gdb_prompt $"
106### and "$THERE.*$gdb_prompt $"
107###
108proc test_i {name command here there} {
109 global gdb_prompt
110
111 set i 0
112 while 1 {
113 send_gdb "${command}\n"
114 gdb_expect {
115 -re "$here.*$gdb_prompt $" {
116 # Okay, we're still on the same line. Just step again.
117 }
118 -re "$there.*$gdb_prompt $" {
119 # We've reached the next line. Rah.
120 pass "$name"
121 return
122 }
123 -re "$gdb_prompt $" {
124 # We got something else. Fail.
125 fail "$name"
126 return
127 }
128 timeout {
129 fail "$name (timeout)"
130 return
131 }
132 }
133
134 # Have we gone for too many steps without seeing any progress?
135 if {[incr i] >= 100} {
136 fail "$name (no progress after 100 steps)"
137 return
138 }
139 }
140}
141
142test_i "stepi to next line" "stepi" \
143 ".*${decimal}.*a.*5.* = a.*3" \
144 ".*${decimal}.*callee.*STEPI"
145test_i "stepi into function" "stepi" \
146 ".*${decimal}.*callee.*STEPI" \
7a292a7a 147 ".*callee \\(\\) at .*step-test\\.c"
dfcd3bfb
JM
148
149# Continue to step until we reach the function's body. This makes it
150# more likely that we've actually completed the prologue, so "finish"
151# will work.
152test_i "stepi into function's first source line" "stepi" \
153 ".*${decimal}.*int callee" \
154 ".*${decimal}.*myglob.*; return 0;"
155
7a292a7a
SS
156# Have to be careful here, if the finish does not work,
157# then we may run to the end of the program, which
158# will cause erroneous failures in the rest of the tests
7a292a7a
SS
159send_gdb "finish\n"
160gdb_expect {
161 -re ".*(Program received|Program exited).*$gdb_prompt $" {
7a292a7a
SS
162 # Oops... We ran to the end of the program... Better reset
163 if {![runto_main]} then {
164 fail "Can't run to main"
165 return 0
166 }
167 if {![runto step-test.c:45]} {
168 fail "Can't run to line 45"
169 return 0
170 }
171 fail "stepi: finish call"
172 }
173 -re ".*${decimal}.*callee.*NEXTI.*$gdb_prompt $" {
7a292a7a
SS
174 pass "stepi: finish call"
175 }
085dd6e6 176 -re ".*${decimal}.*callee.*STEPI.*$gdb_prompt $" {
8216cda9
KB
177 # On PA64, we end up at a different instruction than PA32.
178 # On IA-64, we end up on callee instead of on the following line due
179 # to the restoration of the global pointer.
f4f00b1f
DJ
180 # Similarly on MIPS PIC targets.
181 if { [istarget "hppa2.0w-hp-hpux*"] || [istarget "ia64-*-*"] || [istarget "mips*-*-*"] } {
085dd6e6 182 pass "stepi: finish call 2"
f4f00b1f
DJ
183 test_i "stepi: past call" "stepi" \
184 ".*${decimal}.*callee.*STEPI" ".*${decimal}.*callee.*NEXTI"
085dd6e6
JM
185 } else {
186 fail "stepi: finish call 2"
187 return
188 }
189 }
7a292a7a
SS
190 -re "$gdb_prompt $" {
191 # We got something else. Fail.
192 fail "stepi: finish call"
193 return
194 }
195 timeout {
8b93c638 196 fail "stepi: finish call (timeout)"
7a292a7a
SS
197 return
198 }
199}
200
c906108c
SS
201test_i "nexti over function" "nexti" \
202 ".*${decimal}.*callee.*NEXTI" \
203 ".*${decimal}.*y = w \\+ z;"
204
205# On some platforms, if we try to step into a function call that
206# passes a large structure by value, then we actually end up stepping
207# into memcpy, bcopy, or some such --- GCC emits the call to pass the
208# argument. Opinion is bitterly divided about whether this is the
209# right behavior for GDB or not, but we'll catch it here, so folks
210# won't forget about it.
cd721503
FF
211# Update 4/4/2002 - Regardless of which opinion you have, you would
212# probably have to agree that gdb is currently behaving as designed,
213# in the absence of additional code to not stop in functions used
214# internally by the compiler. Since the testsuite should be checking
215# for conformance to the design, the correct behavior is to accept the
216# cases where gdb stops in memcpy/bcopy.
c906108c 217
c2d11a7d
JM
218gdb_test \
219 "break [gdb_get_line_number "step-test.exp: large struct by value"]" \
220 ".*Breakpoint.* at .*" \
221 "set breakpoint at call to large_struct_by_value"
c906108c
SS
222gdb_test "continue" \
223 ".*Breakpoint ${decimal},.*large_struct_by_value.*" \
224 "run to pass large struct"
05b4d525
FF
225send_gdb "step\n"
226gdb_expect {
227 -re ".*step-test.exp: arrive here 1.*$gdb_prompt $" {
228 pass "large struct by value"
229 }
230 -re ".*(memcpy|bcopy).*$gdb_prompt $" {
231 send_gdb "finish\n" ; gdb_expect -re "$gdb_prompt $"
232 send_gdb "step\n"
233 exp_continue
234 }
235 -re ".*$gdb_prompt $" {
236 fail "large struct by value"
237 }
238 timeout {
239 fail "large struct by value (timeout)"
240 }
241}
c906108c 242
7a292a7a 243gdb_continue_to_end "step-test.exp"
c906108c
SS
244
245return 0