Remove superfluous semicolons from testsuite throughout.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / call-sc.exp
CommitLineData
71d7dd7c
AC
1# This testcase is part of GDB, the GNU debugger.
2
28e7fd62 3# Copyright 2004-2013 Free Software Foundation, Inc.
71d7dd7c
AC
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
71d7dd7c 8# (at your option) any later version.
e22f8b7c 9#
71d7dd7c
AC
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#
71d7dd7c 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/>.
71d7dd7c
AC
17
18# Test "return", "finish", and "call" of functions that a scalar (int,
19# float, enum) and/or take a single scalar parameter.
20
71d7dd7c
AC
21
22# Some targets can't call functions, so don't even bother with this
23# test.
24
25if [target_info exists gdb,cannot_call_functions] {
26 setup_xfail "*-*-*"
27 fail "This target can not call functions"
28 continue
29}
30
31set testfile "call-sc"
32set srcfile ${testfile}.c
33set binfile ${objdir}/${subdir}/${testfile}
34
35# Create and source the file that provides information about the
36# compiler used to compile the test case.
37
4c93b1db 38if [get_compiler_info] {
ae59b1da 39 return -1
71d7dd7c
AC
40}
41
71d7dd7c
AC
42# Compile a variant of scalars.c using TYPE to specify the type of the
43# parameter and return-type. Run the compiled program up to "main".
44# Also updates the global "testfile" to reflect the most recent build.
45
46proc start_scalars_test { type } {
47 global testfile
48 global srcfile
49 global binfile
50 global objdir
51 global subdir
52 global srcdir
53 global gdb_prompt
54 global expect_out
55
56 # Create the additional flags
57 set flags "debug additional_flags=-DT=${type}"
58 set testfile "call-sc-${type}"
59
60 set binfile ${objdir}/${subdir}/${testfile}
61 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable "${flags}"] != "" } {
62 # built the second test case since we can't use prototypes
63 warning "Prototypes not supported, rebuilding with -DNO_PROTOTYPES"
64 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable "${flags} additional_flags=-DNO_PROTOTYPES"] != "" } {
b60f0898
JB
65 untested call-sc.exp
66 return -1
71d7dd7c
AC
67 }
68 }
69
70 # Start with a fresh gdb.
71 gdb_exit
72 gdb_start
73 gdb_reinitialize_dir $srcdir/$subdir
74 gdb_load ${binfile}
75
76 # Make certain that the output is consistent
27d3a1a2
MS
77 gdb_test_no_output "set print sevenbit-strings"
78 gdb_test_no_output "set print address off"
79 gdb_test_no_output "set width 0"
71d7dd7c
AC
80
81 # Advance to main
82 if { ![runto_main] } then {
4ec70201 83 gdb_suppress_tests
71d7dd7c
AC
84 }
85
86 # Get the debug format
87 get_debug_format
88
89 # check that type matches what was passed in
90 set test "ptype; ${testfile}"
91 set foo_t "xxx"
bd69fc68 92 gdb_test_multiple "ptype/r ${type}" "${test}" {
0ef32fd9 93 -re "type = (\[^\r\n\]*)\r\n$gdb_prompt $" {
71d7dd7c
AC
94 set foo_t "$expect_out(1,string)"
95 pass "$test (${foo_t})"
96 }
97 }
bd69fc68 98 gdb_test "ptype/r foo" "type = ${foo_t}" "ptype foo; ${testfile} $expect_out(1,string)"
71d7dd7c
AC
99}
100
101
102# Given N (0..25), return the corresponding alphabetic letter in lower
103# or upper case. This is ment to be i18n proof.
104
105proc i2a { n } {
106 return [string range "abcdefghijklmnopqrstuvwxyz" $n $n]
107}
108
109proc I2A { n } {
110 return [string toupper [i2a $n]]
111}
112
113
71d7dd7c
AC
114# Test GDB's ability to make inferior function calls to functions
115# returning (or passing) in a single scalar.
116
117# start_scalars_test() will have previously built a program with a
118# specified scalar type. To ensure robustness of the output, "p/c" is
119# used.
120
121# This tests the code paths "which return-value convention?" and
122# "extract return-value from registers" called by "infcall.c".
123
124proc test_scalar_calls { } {
125 global testfile
126 global gdb_prompt
127
128 # Check that GDB can always extract a scalar-return value from an
129 # inferior function call. Since GDB always knows the location of
130 # an inferior function call's return value these should never fail
131
132 # Implemented by calling the parameterless function "fun" and then
133 # examining the return value printed by GDB.
134
135 set tests "call ${testfile}"
136
137 # Call fun, checking the printed return-value.
138 gdb_test "p/c fun()" "= 49 '1'" "p/c fun(); ${tests}"
139
140 # Check that GDB can always pass a structure to an inferior function.
141 # This test can never fail.
142
143 # Implemented by calling the one parameter function "Fun" which
144 # stores its parameter in the global variable "L". GDB then
145 # examining that global to confirm that the value is as expected.
146
27d3a1a2 147 gdb_test_no_output "call Fun(foo)" "call Fun(foo); ${tests}"
71d7dd7c
AC
148 gdb_test "p/c L" " = 49 '1'" "p/c L; ${tests}"
149}
150
151# Test GDB's ability to both return a function (with "return" or
152# "finish") and correctly extract/store any corresponding
153# return-value.
154
155# Check that GDB can consistently extract/store structure return
156# values. There are two cases - returned in registers and returned in
157# memory. For the latter case, the return value can't be found and a
158# failure is "expected". However GDB must still both return the
159# function and display the final source and line information.
160
161# N identifies the number of elements in the struct that will be used
162# for the test case. FAILS is a list of target tuples that will fail
163# this test.
164
165# This tests the code paths "which return-value convention?", "extract
166# return-value from registers", and "store return-value in registers".
167# Unlike "test struct calls", this test is expected to "fail" when the
168# return-value is in memory (GDB can't find the location). The test
169# is in three parts: test "return"; test "finish"; check that the two
170# are consistent. GDB can sometimes work for one command and not the
171# other.
172
173proc test_scalar_returns { } {
174 global gdb_prompt
175 global testfile
176
177 set tests "return ${testfile}"
178
179
180 # Check that "return" works.
181
182 # GDB must always force the return of a function that has
183 # a struct result. Dependant on the ABI, it may, or may not be
184 # possible to store the return value in a register.
185
186 # The relevant code looks like "L{n} = fun{n}()". The test forces
187 # "fun{n}" to "return" with an explicit value. Since that code
7a9dd1b2 188 # snippet will store the returned value in "L{n}" the return
71d7dd7c
AC
189 # is tested by examining "L{n}". This assumes that the
190 # compiler implemented this as fun{n}(&L{n}) and hence that when
191 # the value isn't stored "L{n}" remains unchanged. Also check for
192 # consistency between this and the "finish" case.
193
194 # Get into a call of fun
195 gdb_test "advance fun" \
196 "fun .*\[\r\n\]+\[0-9\].*return foo.*" \
197 "advance to fun for return; ${tests}"
198
199 # Check that the program invalidated the relevant global.
200 gdb_test "p/c L" " = 90 'Z'" "zed L for return; ${tests}"
201
202 # Force the "return". This checks that the return is always
203 # performed, and that GDB correctly reported this to the user.
204 # GDB 6.0 and earlier, when the return-value's location wasn't
205 # known, both failed to print a final "source and line" and misplaced
206 # the frame ("No frame").
207
208 # The test is writen so that it only reports one FAIL/PASS for the
209 # entire operation. The value returned is checked further down.
210 # "return_value_unknown", if non-empty, records why GDB realised
211 # that it didn't know where the return value was.
212
213 set test "return foo; ${tests}"
214 set return_value_unknown 0
215 set return_value_unimplemented 0
71d7dd7c
AC
216 gdb_test_multiple "return foo" "${test}" {
217 -re "The location" {
218 # Ulgh, a struct return, remember this (still need prompt).
219 set return_value_unknown 1
220 exp_continue
221 }
222 -re "A structure or union" {
223 # Ulgh, a struct return, remember this (still need prompt).
224 set return_value_unknown 1
225 # Double ulgh. Architecture doesn't use return_value and
226 # hence hasn't implemented small structure return.
227 set return_value_unimplemented 1
228 exp_continue
229 }
230 -re "Make fun return now.*y or n. $" {
231 gdb_test_multiple "y" "${test}" {
232 -re "L *= fun.*${gdb_prompt} $" {
233 # Need to step off the function call
234 gdb_test "next" "zed.*" "${test}"
235 }
2f193b69 236 -re "zed \\(\\);.*$gdb_prompt $" {
71d7dd7c
AC
237 pass "${test}"
238 }
239 }
240 }
241 }
242
3a77aa28
MC
243 # If the previous test did not work, the program counter might
244 # still be inside foo() rather than main(). Make sure the program
245 # counter is is main().
246 #
247 # This happens on ppc64 GNU/Linux with gcc 3.4.1 and a buggy GDB
248
249 set test "return foo; synchronize pc to main()"
250 for {set loop_count 0} {$loop_count < 2} {incr loop_count} {
251 gdb_test_multiple "backtrace 1" $test {
252 -re "#0.*main \\(\\).*${gdb_prompt} $" {
253 pass $test
254 set loop_count 2
255 }
256 -re "#0.*fun \\(\\).*${gdb_prompt} $" {
257 if {$loop_count < 1} {
258 gdb_test "finish" ".*" ""
259 } else {
260 fail $test
261 set loop_count 2
262 }
263 }
264 }
265 }
266
71d7dd7c
AC
267 # Check that the return-value is as expected. At this stage we're
268 # just checking that GDB has returned a value consistent with
269 # "return_value_unknown" set above.
270
271 set test "value foo returned; ${tests}"
71d7dd7c
AC
272 gdb_test_multiple "p/c L" "${test}" {
273 -re " = 49 '1'.*${gdb_prompt} $" {
274 if $return_value_unknown {
275 # This contradicts the above claim that GDB didn't
276 # know the location of the return-value.
277 fail "${test}"
278 } else {
279 pass "${test}"
280 }
281 }
282 -re " = 90 .*${gdb_prompt} $" {
283 if $return_value_unknown {
284 # The struct return case. Since any modification
285 # would be by reference, and that can't happen, the
286 # value should be unmodified and hence Z is expected.
287 # Is this a reasonable assumption?
288 pass "${test}"
289 } else {
290 # This contradicts the above claim that GDB knew
291 # the location of the return-value.
292 fail "${test}"
293 }
294 }
295 -re ".*${gdb_prompt} $" {
296 if $return_value_unimplemented {
297 # What a suprize. The architecture hasn't implemented
298 # return_value, and hence has to fail.
299 kfail "$test" gdb/1444
300 } else {
301 fail "$test"
302 }
303 }
304 }
305
306 # Check that a "finish" works.
307
308 # This is almost but not quite the same as "call struct funcs".
309 # Architectures can have subtle differences in the two code paths.
310
311 # The relevant code snippet is "L{n} = fun{n}()". The program is
312 # advanced into a call to "fun{n}" and then that function is
313 # finished. The returned value that GDB prints, reformatted using
314 # "p/c", is checked.
315
316 # Get into "fun()".
317 gdb_test "advance fun" \
318 "fun .*\[\r\n\]+\[0-9\].*return foo.*" \
319 "advance to fun for finish; ${tests}"
320
321 # Check that the program invalidated the relevant global.
322 gdb_test "p/c L" " = 90 'Z'" "zed L for finish; ${tests}"
323
324 # Finish the function, set 'finish_value_unknown" to non-empty if the
325 # return-value was not found.
326 set test "finish foo; ${tests}"
327 set finish_value_unknown 0
328 gdb_test_multiple "finish" "${test}" {
329 -re "Value returned is .*${gdb_prompt} $" {
330 pass "${test}"
331 }
332 -re "Cannot determine contents.*${gdb_prompt} $" {
333 # Expected bad value. For the moment this is ok.
334 set finish_value_unknown 1
335 pass "${test}"
336 }
337 }
338
339 # Re-print the last (return-value) using the more robust
340 # "p/c". If no return value was found, the 'Z' from the previous
341 # check that the variable was cleared, is printed.
342 set test "value foo finished; ${tests}"
343 gdb_test_multiple "p/c" "${test}" {
344 -re " = 49 '1'\[\r\n\]+${gdb_prompt} $" {
345 if $finish_value_unknown {
346 # This contradicts the above claim that GDB didn't
347 # know the location of the return-value.
348 fail "${test}"
349 } else {
350 pass "${test}"
351 }
352 }
353 -re " = 90 'Z'\[\r\n\]+${gdb_prompt} $" {
354 # The value didn't get found. This is "expected".
355 if $finish_value_unknown {
356 pass "${test}"
357 } else {
358 # This contradicts the above claim that GDB did
359 # know the location of the return-value.
360 fail "${test}"
361 }
362 }
363 }
364
365 # Finally, check that "return" and finish" have consistent
366 # behavior.
367
368 # Since both "return" and "finish" use equivalent "which
369 # return-value convention" logic, both commands should have
370 # identical can/can-not find return-value messages.
371
372 # Note that since "call" and "finish" use common code paths, a
373 # failure here is a strong indicator of problems with "store
374 # return-value" code paths. Suggest looking at "return_value"
375 # when investigating a fix.
376
377 set test "return and finish use same convention; ${tests}"
378 if {$finish_value_unknown == $return_value_unknown} {
379 pass "${test}"
380 } else {
381 kfail gdb/1444 "${test}"
382 }
383}
384
385# ABIs pass anything >8 or >16 bytes in memory but below that things
386# randomly use register and/and structure conventions. Check all
387# possible sized char scalars in that range. But only a restricted
388# range of the other types.
389
390# NetBSD/PPC returns "unnatural" (3, 5, 6, 7) sized scalars in memory.
391
392# d10v is weird. 5/6 byte scalars go in memory. 2 or more char
393# scalars go in memory. Everything else is in a register!
394
395# Test every single char struct from 1..17 in size. This is what the
396# original "scalars" test was doing.
397
398start_scalars_test tc
399test_scalar_calls
400test_scalar_returns
401
402
403# Let the fun begin.
404
405# Assuming that any integer struct larger than 8 bytes goes in memory,
406# come up with many and varied combinations of a return struct. For
407# "struct calls" test just beyond that 8 byte boundary, for "struct
408# returns" test up to that boundary.
409
410# For floats, assumed that up to two struct elements can be stored in
411# floating point registers, regardless of their size.
412
413# The approx size of each structure it is computed assumed that tc=1,
414# ts=2, ti=4, tl=4, tll=8, tf=4, td=8, tld=16, and that all fields are
415# naturally aligned. Padding being added where needed. Note that
416# these numbers are just approx, the d10v has ti=2, a 64-bit has has
417# tl=8.
418
419# Approx size: 2, 4, ...
420start_scalars_test ts
421test_scalar_calls
422test_scalar_returns
423
424# Approx size: 4, 8, ...
425start_scalars_test ti
426test_scalar_calls
427test_scalar_returns
428
429# Approx size: 4, 8, ...
430start_scalars_test tl
431test_scalar_calls
432test_scalar_returns
433
434# Approx size: 8, 16, ...
435start_scalars_test tll
436test_scalar_calls
437test_scalar_returns
438
d426f7b4
MS
439if ![target_info exists gdb,skip_float_tests] {
440 # Approx size: 4, 8, ...
441 start_scalars_test tf
442 test_scalar_calls
443 test_scalar_returns
444
445 # Approx size: 8, 16, ...
446 start_scalars_test td
447 test_scalar_calls
448 test_scalar_returns
449
450 # Approx size: 16, 32, ...
451 start_scalars_test tld
452 test_scalar_calls
453 test_scalar_returns
454}
71d7dd7c
AC
455
456# Approx size: 4, 8, ...
457start_scalars_test te
458test_scalar_calls
459test_scalar_returns
460
461return 0
This page took 0.941244 seconds and 4 git commands to generate.