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