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