]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.base/step-test.exp
This commit was manufactured by cvs2svn to create branch
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / step-test.exp
CommitLineData
c4ffd4c0
AC
1# This testcase is part of GDB, the GNU debugger.
2
9b254dd1 3# Copyright 1997, 1998, 1999, 2000, 2002, 2001, 2003, 2004, 2007, 2008
6aba47ca 4# Free Software Foundation, Inc.
c906108c
SS
5
6# This program is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
e22f8b7c 8# the Free Software Foundation; either version 3 of the License, or
c906108c 9# (at your option) any later version.
e22f8b7c 10#
c906108c
SS
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
e22f8b7c 15#
c906108c 16# You should have received a copy of the GNU General Public License
e22f8b7c 17# along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c
SS
18# step-test.exp -- Expect script to test stepping in gdb
19
20if $tracelevel then {
21 strace $tracelevel
22}
23
24set testfile step-test
f2dd3617 25set srcfile ${testfile}.c
c906108c
SS
26set binfile ${objdir}/${subdir}/${testfile}
27
28remote_exec build "rm -f ${binfile}"
f2dd3617 29if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
b60f0898
JB
30 untested step-test.exp
31 return -1
c906108c
SS
32}
33
34gdb_exit
35gdb_start
36gdb_reinitialize_dir $srcdir/$subdir
37gdb_load ${binfile}
38
39if ![runto_main] then {
40 fail "Can't run to main"
41 return 0
42}
43
7a292a7a
SS
44# Set a breakpoint at line 45, if stepi then finish fails, we would
45# run to the end of the program, which would mess up the rest of the tests.
46
c906108c
SS
47# Vanilla step/next
48#
49gdb_test "next" ".*${decimal}.*x = 1;.*" "next 1"
50gdb_test "step" ".*${decimal}.*y = 2;.*" "step 1"
51
52# With count
53#
54gdb_test "next 2" ".*${decimal}.*w = w.*2;.*" "next 2"
55gdb_test "step 3" ".*${decimal}.*z = z.*5;.*" "step 3"
56gdb_test "next" ".*${decimal}.*callee.*OVER.*" "next 3"
57
58# Step over call
59#
60gdb_test "next" ".*${decimal}.*callee.*INTO.*" "next over"
61
62# Step into call
63#
085dd6e6 64gdb_test "step" ".*${decimal}.*myglob.*" "step into"
c906108c
SS
65
66# Step out of call
67#
68# I wonder if this is really portable. Are there any caller-saves
69# platforms, on which `finish' will return you to some kind of pop
70# instruction, which is attributed to the line containing the function
71# call?
085dd6e6 72
8216cda9
KB
73# On PA64, we end up at a different instruction than PA32.
74# On IA-64, we also end up on callee instead of on the next line due
75# to the restoration of the global pointer (which is a caller-save).
f4f00b1f 76# Similarly on MIPS PIC targets.
c4ffd4c0 77set test "step out"
f4f00b1f 78if { [istarget "hppa2.0w-hp-hpux*"] || [istarget "ia64-*-*"] || [istarget "mips*-*-*"]} {
c4ffd4c0
AC
79 gdb_test_multiple "finish" "$test" {
80 -re ".*${decimal}.*a.*5.*= a.*3.*$gdb_prompt $" {
81 pass "$test"
82 }
83 -re ".*${decimal}.*callee.*INTO.*$gdb_prompt $" {
84 pass "$test"
85 }
085dd6e6
JM
86 }
87} else {
88 gdb_test "finish" ".*${decimal}.*a.*5.*= a.*3.*" "step out"
89}
c906108c
SS
90
91### Testing nexti and stepi.
92###
93### test_i NAME COMMAND HERE THERE
94###
95### Send COMMAND to gdb over and over, while the output matches the
96### regexp HERE, followed by the gdb prompt. Pass if the output
97### eventually matches the regexp THERE, followed by the gdb prompt;
98### fail if we have to iterate more than a hundred times, we time out
99### talking to gdb, or we get output which is neither HERE nor THERE. :)
100###
101### Use NAME as the name of the test.
102###
103### The exact regexps used are "$HERE.*$gdb_prompt $"
104### and "$THERE.*$gdb_prompt $"
105###
106proc test_i {name command here there} {
107 global gdb_prompt
108
109 set i 0
c4ffd4c0
AC
110 gdb_test_multiple "$command" "$name" {
111 -re "$here.*$gdb_prompt $" {
112 # Have we gone for too many steps without seeing any progress?
113 if {[incr i] >= 100} {
114 fail "$name (no progress after 100 steps)"
c906108c
SS
115 return
116 }
c4ffd4c0
AC
117 send_gdb "$command\n"
118 exp_continue
c906108c 119 }
c4ffd4c0
AC
120 -re "$there.*$gdb_prompt $" {
121 # We've reached the next line. Rah.
122 pass "$name"
c906108c
SS
123 return
124 }
125 }
126}
127
128test_i "stepi to next line" "stepi" \
129 ".*${decimal}.*a.*5.* = a.*3" \
130 ".*${decimal}.*callee.*STEPI"
bd5ddfe8
DJ
131
132# Continue to step until we enter the function. Also keep stepping
133# if this passes through a (useless) PLT entry.
c906108c 134test_i "stepi into function" "stepi" \
bd5ddfe8 135 "(.*${decimal}.*callee.*STEPI|.* in callee@plt)" \
7a292a7a 136 ".*callee \\(\\) at .*step-test\\.c"
dfcd3bfb
JM
137
138# Continue to step until we reach the function's body. This makes it
139# more likely that we've actually completed the prologue, so "finish"
140# will work.
141test_i "stepi into function's first source line" "stepi" \
142 ".*${decimal}.*int callee" \
143 ".*${decimal}.*myglob.*; return 0;"
144
7a292a7a
SS
145# Have to be careful here, if the finish does not work,
146# then we may run to the end of the program, which
147# will cause erroneous failures in the rest of the tests
c4ffd4c0
AC
148set test "stepi: finish call"
149gdb_test_multiple "finish" "$test" {
150 -re ".*${decimal}.*callee.*NEXTI.*$gdb_prompt $" {
151 pass "$test"
7a292a7a 152 }
c4ffd4c0
AC
153 -re ".*(Program received|Program exited).*$gdb_prompt $" {
154 # Oops... We ran to the end of the program... Better reset
155 if {![runto_main]} then {
156 fail "$test (Can't run to main)"
157 return 0
158 }
159 if {![runto step-test.c:45]} {
160 fail "$test (Can't run to line 45)"
161 return 0
162 }
163 fail "$test"
7a292a7a 164 }
c4ffd4c0
AC
165 -re ".*${decimal}.*callee.*STEPI.*$gdb_prompt $" {
166 # On PA64, we end up at a different instruction than PA32.
167 # On IA-64, we end up on callee instead of on the following line due
168 # to the restoration of the global pointer.
169 # Similarly on MIPS PIC targets.
170 if { [istarget "hppa2.0w-hp-hpux*"] || [istarget "ia64-*-*"] || [istarget "mips*-*-*"] } {
171 test_i "$test" "stepi" \
172 ".*${decimal}.*callee.*STEPI" ".*${decimal}.*callee.*NEXTI"
173 } else {
174 fail "$test"
175 }
085dd6e6 176 }
7a292a7a
SS
177}
178
c906108c
SS
179test_i "nexti over function" "nexti" \
180 ".*${decimal}.*callee.*NEXTI" \
181 ".*${decimal}.*y = w \\+ z;"
182
183# On some platforms, if we try to step into a function call that
184# passes a large structure by value, then we actually end up stepping
185# into memcpy, bcopy, or some such --- GCC emits the call to pass the
186# argument. Opinion is bitterly divided about whether this is the
187# right behavior for GDB or not, but we'll catch it here, so folks
188# won't forget about it.
cd721503
FF
189# Update 4/4/2002 - Regardless of which opinion you have, you would
190# probably have to agree that gdb is currently behaving as designed,
191# in the absence of additional code to not stop in functions used
192# internally by the compiler. Since the testsuite should be checking
193# for conformance to the design, the correct behavior is to accept the
194# cases where gdb stops in memcpy/bcopy.
c906108c 195
c2d11a7d
JM
196gdb_test \
197 "break [gdb_get_line_number "step-test.exp: large struct by value"]" \
198 ".*Breakpoint.* at .*" \
199 "set breakpoint at call to large_struct_by_value"
c906108c
SS
200gdb_test "continue" \
201 ".*Breakpoint ${decimal},.*large_struct_by_value.*" \
202 "run to pass large struct"
c4ffd4c0
AC
203set test "large struct by value"
204gdb_test_multiple "step" "$test" {
05b4d525 205 -re ".*step-test.exp: arrive here 1.*$gdb_prompt $" {
c4ffd4c0 206 pass "$test"
05b4d525
FF
207 }
208 -re ".*(memcpy|bcopy).*$gdb_prompt $" {
209 send_gdb "finish\n" ; gdb_expect -re "$gdb_prompt $"
210 send_gdb "step\n"
211 exp_continue
212 }
05b4d525 213}
c906108c 214
7a292a7a 215gdb_continue_to_end "step-test.exp"
c906108c
SS
216
217return 0