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