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