Commit | Line | Data |
---|---|---|
f2dd3617 EZ |
1 | # Copyright 1997, 1998, 1999, 2000, 2002, 2001, 2003 |
2 | # Free Software Foundation, Inc. | |
c906108c SS |
3 | |
4 | # This program is free software; you can redistribute it and/or modify | |
5 | # it under the terms of the GNU General Public License as published by | |
6 | # the Free Software Foundation; either version 2 of the License, or | |
7 | # (at your option) any later version. | |
8 | # | |
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. | |
13 | # | |
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | |
17 | ||
18 | # Please email any bugs, comments, and/or additions to this file to: | |
19 | # bug-gdb@prep.ai.mit.edu | |
20 | ||
21 | # use this to debug: | |
22 | # | |
23 | #log_user 1 | |
24 | ||
25 | # step-test.exp -- Expect script to test stepping in gdb | |
26 | ||
27 | if $tracelevel then { | |
28 | strace $tracelevel | |
29 | } | |
30 | ||
31 | set testfile step-test | |
f2dd3617 | 32 | set srcfile ${testfile}.c |
c906108c SS |
33 | set binfile ${objdir}/${subdir}/${testfile} |
34 | ||
35 | remote_exec build "rm -f ${binfile}" | |
f2dd3617 | 36 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { |
c906108c SS |
37 | gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail." |
38 | } | |
39 | ||
40 | gdb_exit | |
41 | gdb_start | |
42 | gdb_reinitialize_dir $srcdir/$subdir | |
43 | gdb_load ${binfile} | |
44 | ||
45 | if ![runto_main] then { | |
46 | fail "Can't run to main" | |
47 | return 0 | |
48 | } | |
49 | ||
7a292a7a SS |
50 | # Set a breakpoint at line 45, if stepi then finish fails, we would |
51 | # run to the end of the program, which would mess up the rest of the tests. | |
52 | ||
c906108c SS |
53 | # Vanilla step/next |
54 | # | |
55 | gdb_test "next" ".*${decimal}.*x = 1;.*" "next 1" | |
56 | gdb_test "step" ".*${decimal}.*y = 2;.*" "step 1" | |
57 | ||
58 | # With count | |
59 | # | |
60 | gdb_test "next 2" ".*${decimal}.*w = w.*2;.*" "next 2" | |
61 | gdb_test "step 3" ".*${decimal}.*z = z.*5;.*" "step 3" | |
62 | gdb_test "next" ".*${decimal}.*callee.*OVER.*" "next 3" | |
63 | ||
64 | # Step over call | |
65 | # | |
66 | gdb_test "next" ".*${decimal}.*callee.*INTO.*" "next over" | |
67 | ||
68 | # Step into call | |
69 | # | |
085dd6e6 | 70 | gdb_test "step" ".*${decimal}.*myglob.*" "step into" |
c906108c SS |
71 | |
72 | # Step out of call | |
73 | # | |
74 | # I wonder if this is really portable. Are there any caller-saves | |
75 | # platforms, on which `finish' will return you to some kind of pop | |
76 | # instruction, which is attributed to the line containing the function | |
77 | # call? | |
085dd6e6 | 78 | |
8216cda9 KB |
79 | # On PA64, we end up at a different instruction than PA32. |
80 | # On IA-64, we also end up on callee instead of on the next line due | |
81 | # to the restoration of the global pointer (which is a caller-save). | |
f4f00b1f DJ |
82 | # Similarly on MIPS PIC targets. |
83 | if { [istarget "hppa2.0w-hp-hpux*"] || [istarget "ia64-*-*"] || [istarget "mips*-*-*"]} { | |
085dd6e6 JM |
84 | send_gdb "finish\n" |
85 | gdb_expect { | |
86 | -re ".*${decimal}.*a.*5.*= a.*3.*$gdb_prompt $" { pass "step out 1" } | |
87 | -re ".*${decimal}.*callee.*INTO.*$gdb_prompt $" { pass "step out 2" } | |
88 | timeout { fail "step out" } | |
89 | } | |
90 | } else { | |
91 | gdb_test "finish" ".*${decimal}.*a.*5.*= a.*3.*" "step out" | |
92 | } | |
c906108c SS |
93 | |
94 | ### Testing nexti and stepi. | |
95 | ### | |
96 | ### test_i NAME COMMAND HERE THERE | |
97 | ### | |
98 | ### Send COMMAND to gdb over and over, while the output matches the | |
99 | ### regexp HERE, followed by the gdb prompt. Pass if the output | |
100 | ### eventually matches the regexp THERE, followed by the gdb prompt; | |
101 | ### fail if we have to iterate more than a hundred times, we time out | |
102 | ### talking to gdb, or we get output which is neither HERE nor THERE. :) | |
103 | ### | |
104 | ### Use NAME as the name of the test. | |
105 | ### | |
106 | ### The exact regexps used are "$HERE.*$gdb_prompt $" | |
107 | ### and "$THERE.*$gdb_prompt $" | |
108 | ### | |
109 | proc test_i {name command here there} { | |
110 | global gdb_prompt | |
111 | ||
112 | set i 0 | |
113 | while 1 { | |
114 | send_gdb "${command}\n" | |
115 | gdb_expect { | |
116 | -re "$here.*$gdb_prompt $" { | |
117 | # Okay, we're still on the same line. Just step again. | |
118 | } | |
119 | -re "$there.*$gdb_prompt $" { | |
120 | # We've reached the next line. Rah. | |
121 | pass "$name" | |
122 | return | |
123 | } | |
124 | -re "$gdb_prompt $" { | |
125 | # We got something else. Fail. | |
126 | fail "$name" | |
127 | return | |
128 | } | |
129 | timeout { | |
130 | fail "$name (timeout)" | |
131 | return | |
132 | } | |
133 | } | |
134 | ||
135 | # Have we gone for too many steps without seeing any progress? | |
136 | if {[incr i] >= 100} { | |
137 | fail "$name (no progress after 100 steps)" | |
138 | return | |
139 | } | |
140 | } | |
141 | } | |
142 | ||
143 | test_i "stepi to next line" "stepi" \ | |
144 | ".*${decimal}.*a.*5.* = a.*3" \ | |
145 | ".*${decimal}.*callee.*STEPI" | |
146 | test_i "stepi into function" "stepi" \ | |
147 | ".*${decimal}.*callee.*STEPI" \ | |
7a292a7a | 148 | ".*callee \\(\\) at .*step-test\\.c" |
dfcd3bfb JM |
149 | |
150 | # Continue to step until we reach the function's body. This makes it | |
151 | # more likely that we've actually completed the prologue, so "finish" | |
152 | # will work. | |
153 | test_i "stepi into function's first source line" "stepi" \ | |
154 | ".*${decimal}.*int callee" \ | |
155 | ".*${decimal}.*myglob.*; return 0;" | |
156 | ||
7a292a7a SS |
157 | # Have to be careful here, if the finish does not work, |
158 | # then we may run to the end of the program, which | |
159 | # will cause erroneous failures in the rest of the tests | |
7a292a7a SS |
160 | send_gdb "finish\n" |
161 | gdb_expect { | |
162 | -re ".*(Program received|Program exited).*$gdb_prompt $" { | |
7a292a7a SS |
163 | # Oops... We ran to the end of the program... Better reset |
164 | if {![runto_main]} then { | |
165 | fail "Can't run to main" | |
166 | return 0 | |
167 | } | |
168 | if {![runto step-test.c:45]} { | |
169 | fail "Can't run to line 45" | |
170 | return 0 | |
171 | } | |
172 | fail "stepi: finish call" | |
173 | } | |
174 | -re ".*${decimal}.*callee.*NEXTI.*$gdb_prompt $" { | |
7a292a7a SS |
175 | pass "stepi: finish call" |
176 | } | |
085dd6e6 | 177 | -re ".*${decimal}.*callee.*STEPI.*$gdb_prompt $" { |
8216cda9 KB |
178 | # On PA64, we end up at a different instruction than PA32. |
179 | # On IA-64, we end up on callee instead of on the following line due | |
180 | # to the restoration of the global pointer. | |
f4f00b1f DJ |
181 | # Similarly on MIPS PIC targets. |
182 | if { [istarget "hppa2.0w-hp-hpux*"] || [istarget "ia64-*-*"] || [istarget "mips*-*-*"] } { | |
085dd6e6 | 183 | pass "stepi: finish call 2" |
f4f00b1f DJ |
184 | test_i "stepi: past call" "stepi" \ |
185 | ".*${decimal}.*callee.*STEPI" ".*${decimal}.*callee.*NEXTI" | |
085dd6e6 JM |
186 | } else { |
187 | fail "stepi: finish call 2" | |
188 | return | |
189 | } | |
190 | } | |
7a292a7a SS |
191 | -re "$gdb_prompt $" { |
192 | # We got something else. Fail. | |
193 | fail "stepi: finish call" | |
194 | return | |
195 | } | |
196 | timeout { | |
8b93c638 | 197 | fail "stepi: finish call (timeout)" |
7a292a7a SS |
198 | return |
199 | } | |
200 | } | |
201 | ||
c906108c SS |
202 | test_i "nexti over function" "nexti" \ |
203 | ".*${decimal}.*callee.*NEXTI" \ | |
204 | ".*${decimal}.*y = w \\+ z;" | |
205 | ||
206 | # On some platforms, if we try to step into a function call that | |
207 | # passes a large structure by value, then we actually end up stepping | |
208 | # into memcpy, bcopy, or some such --- GCC emits the call to pass the | |
209 | # argument. Opinion is bitterly divided about whether this is the | |
210 | # right behavior for GDB or not, but we'll catch it here, so folks | |
211 | # won't forget about it. | |
cd721503 FF |
212 | # Update 4/4/2002 - Regardless of which opinion you have, you would |
213 | # probably have to agree that gdb is currently behaving as designed, | |
214 | # in the absence of additional code to not stop in functions used | |
215 | # internally by the compiler. Since the testsuite should be checking | |
216 | # for conformance to the design, the correct behavior is to accept the | |
217 | # cases where gdb stops in memcpy/bcopy. | |
c906108c | 218 | |
c2d11a7d JM |
219 | gdb_test \ |
220 | "break [gdb_get_line_number "step-test.exp: large struct by value"]" \ | |
221 | ".*Breakpoint.* at .*" \ | |
222 | "set breakpoint at call to large_struct_by_value" | |
c906108c SS |
223 | gdb_test "continue" \ |
224 | ".*Breakpoint ${decimal},.*large_struct_by_value.*" \ | |
225 | "run to pass large struct" | |
05b4d525 FF |
226 | send_gdb "step\n" |
227 | gdb_expect { | |
228 | -re ".*step-test.exp: arrive here 1.*$gdb_prompt $" { | |
229 | pass "large struct by value" | |
230 | } | |
231 | -re ".*(memcpy|bcopy).*$gdb_prompt $" { | |
232 | send_gdb "finish\n" ; gdb_expect -re "$gdb_prompt $" | |
233 | send_gdb "step\n" | |
234 | exp_continue | |
235 | } | |
236 | -re ".*$gdb_prompt $" { | |
237 | fail "large struct by value" | |
238 | } | |
239 | timeout { | |
240 | fail "large struct by value (timeout)" | |
241 | } | |
242 | } | |
c906108c | 243 | |
7a292a7a | 244 | gdb_continue_to_end "step-test.exp" |
c906108c SS |
245 | |
246 | return 0 |