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