1 # This testcase is part of GDB, the GNU debugger.
3 # Copyright 1997-2000, 2002, 2001, 2003-2004, 2007-2012 Free Software
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 3 of the License, or
9 # (at your option) any later version.
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.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 # step-test.exp -- Expect script to test stepping in gdb
20 set testfile step-test
21 set srcfile ${testfile}.c
22 set binfile ${objdir}/${subdir}/${testfile}
24 remote_exec build "rm -f ${binfile}"
25 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
26 untested step-test.exp
32 gdb_reinitialize_dir $srcdir/$subdir
35 if ![runto_main] then {
36 fail "Can't run to main"
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.
45 gdb_test "next" ".*${decimal}.*x = 1;.*" "next 1"
46 gdb_test "step" ".*${decimal}.*y = 2;.*" "step 1"
50 gdb_test "next 2" ".*${decimal}.*w = w.*2;.*" "next 2"
51 gdb_test "step 3" ".*${decimal}.*z = z.*5;.*" "step 3"
52 gdb_test "next" ".*${decimal}.*callee.*OVER.*" "next 3"
56 gdb_test "next" ".*${decimal}.*callee.*INTO.*" "next over"
60 gdb_test "step" ".*${decimal}.*myglob.*" "step into"
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
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).
72 # Similarly on MIPS PIC targets.
74 if { [istarget "hppa2.0w-hp-hpux*"] || [istarget "ia64-*-*"] || [istarget "mips*-*-*"]} {
75 gdb_test_multiple "finish" "$test" {
76 -re ".*${decimal}.*a.*5.*= a.*3.*$gdb_prompt $" {
79 -re ".*${decimal}.*callee.*INTO.*$gdb_prompt $" {
84 gdb_test "finish" ".*${decimal}.*a.*5.*= a.*3.*" "step out"
87 ### Testing nexti and stepi.
89 ### test_i NAME COMMAND HERE THERE
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. :)
97 ### Use NAME as the name of the test.
99 ### The exact regexps used are "$HERE.*$gdb_prompt $"
100 ### and "$THERE.*$gdb_prompt $"
102 proc test_i {name command here there} {
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)"
113 send_gdb "$command\n"
116 -re "$there.*$gdb_prompt $" {
117 # We've reached the next line. Rah.
124 test_i "stepi to next line" "stepi" \
125 ".*${decimal}.*a.*5.* = a.*3" \
126 ".*${decimal}.*callee.*STEPI"
128 # Continue to step until we enter the function. Also keep stepping
129 # if this passes through a (useless) PLT entry.
130 test_i "stepi into function" "stepi" \
131 "(.*${decimal}.*callee.*STEPI|.* in callee@plt)" \
132 ".*callee \\(\\) at .*step-test\\.c"
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"
137 test_i "stepi into function's first source line" "stepi" \
138 ".*${decimal}.*int callee" \
139 ".*${decimal}.*myglob.*; return 0;"
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
144 set test "stepi: finish call"
145 gdb_test_multiple "finish" "$test" {
146 -re ".*${decimal}.*callee.*NEXTI.*$gdb_prompt $" {
149 -re ".*(Program received|$inferior_exited_re).*$gdb_prompt $" {
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)"
155 if {![runto step-test.c:45]} {
156 fail "$test (Can't run to line 45)"
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"
175 test_i "nexti over function" "nexti" \
176 ".*${decimal}.*callee.*NEXTI" \
177 ".*${decimal}.*y = w \\+ z;"
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.
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.
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"
196 gdb_test "continue" \
197 ".*Breakpoint ${decimal},.*large_struct_by_value.*" \
198 "run to pass large struct"
199 set test "large struct by value"
200 gdb_test_multiple "step" "$test" {
201 -re ".*step-test.exp: arrive here 1.*$gdb_prompt $" {
204 -re ".*(memcpy|bcopy).*$gdb_prompt $" {
205 send_gdb "finish\n" ; gdb_expect -re "$gdb_prompt $"
211 gdb_continue_to_end "step-test.exp"