1# This testcase is part of GDB, the GNU debugger. 2 3# Copyright 1996, 1997, 1999, 2003, 2004, 2007, 2008, 2009, 2010, 2011 4# Free Software Foundation, Inc. 5 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. 10# 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. 15# 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 19if $tracelevel then { 20 strace $tracelevel 21} 22 23 24# Some targets can't call functions, so don't even bother with this 25# test. 26 27if [target_info exists gdb,cannot_call_functions] { 28 setup_xfail "*-*-*" 29 fail "This target can not call functions" 30 continue 31} 32 33set testfile "structs" 34set srcfile ${testfile}.c 35set binfile ${objdir}/${subdir}/${testfile} 36 37# Regex matching any value of `char' type like: a = 65 'A' 38set anychar_re {-?[0-9]{1,3} '(.|\\([0-7]{3}|[a-z]|\\|'))'} 39 40# Create and source the file that provides information about the 41# compiler used to compile the test case. 42 43if [get_compiler_info ${binfile}] { 44 return -1; 45} 46 47# Compile a variant of structs.c using TYPES to specify the type of 48# the first N struct elements (the remaining elements take the type of 49# the last TYPES field). Run the compmiled program up to "main". 50# Also updates the global "testfile" to reflect the most recent build. 51 52set first 1 53proc start_structs_test { types } { 54 global testfile 55 global srcfile 56 global binfile 57 global objdir 58 global subdir 59 global srcdir 60 global gdb_prompt 61 global anychar_re 62 global first 63 64 # Create the additional flags 65 set flags "debug" 66 set testfile "structs" 67 set n 0 68 for {set n 0} {$n<[llength ${types}]} {incr n} { 69 set m [I2A ${n}] 70 set t [lindex ${types} $n] 71 lappend flags "additional_flags=-Dt${m}=${t}" 72 append testfile "-" "$t" 73 } 74 75 set binfile ${objdir}/${subdir}/${testfile} 76 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable "${flags}"] != "" } { 77 # built the second test case since we can't use prototypes 78 warning "Prototypes not supported, rebuilding with -DNO_PROTOTYPES" 79 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable "${flags} additional_flags=-DNO_PROTOTYPES"] != "" } { 80 untested structs.exp 81 return -1 82 } 83 } 84 85 # Start with a fresh gdb. 86 gdb_exit 87 gdb_start 88 gdb_reinitialize_dir $srcdir/$subdir 89 gdb_load ${binfile} 90 91 # Make certain that the output is consistent 92 gdb_test_no_output "set print sevenbit-strings" 93 gdb_test_no_output "set print address off" 94 gdb_test_no_output "set width 0" 95 gdb_test_no_output "set print elements 300" 96 97 # Advance to main 98 if { ![runto_main] } then { 99 gdb_suppress_tests; 100 } 101 102 # Get the debug format 103 get_debug_format 104 105 # Limit the slow $anychar_re{256} matching for better performance. 106 if $first { 107 set first 0 108 109 # Verify $anychar_re can match all the values of `char' type. 110 gdb_breakpoint [gdb_get_line_number "chartest-done"] 111 gdb_continue_to_breakpoint "chartest-done" ".*chartest-done.*" 112 gdb_test "p chartest" "= {({c = ${anychar_re}}, ){255}{c = ${anychar_re}}}" 113 } 114 115 # check that at the struct containing all the relevant types is correct 116 set foo_t "type = struct struct[llength ${types}] \{" 117 for {set n 0} {$n<[llength ${types}]} {incr n} { 118 append foo_t "\[\r\n \]+[lindex ${types} $n] [i2a $n];" 119 } 120 append foo_t "\[\r\n \]+\}" 121 gdb_test "ptype foo[llength ${types}]" "${foo_t}" \ 122 "ptype foo[llength ${types}]; ${testfile}" 123} 124 125# The expected value for fun${n}, L${n} and foo${n}. First element is 126# empty to make indexing easier. "foo" returns the modified value, 127# "zed" returns the invalid value. 128 129proc foo { n } { 130 return [lindex { 131 "{}" 132 "{a = 49 '1'}" 133 "{a = 97 'a', b = 50 '2'}" 134 "{a = 49 '1', b = 98 'b', c = 51 '3'}" 135 "{a = 97 'a', b = 50 '2', c = 99 'c', d = 52 '4'}" 136 "{a = 49 '1', b = 98 'b', c = 51 '3', d = 100 'd', e = 53 '5'}" 137 "{a = 97 'a', b = 50 '2', c = 99 'c', d = 52 '4', e = 101 'e', f = 54 '6'}" 138 "{a = 49 '1', b = 98 'b', c = 51 '3', d = 100 'd', e = 53 '5', f = 102 'f', g = 55 '7'}" 139 "{a = 97 'a', b = 50 '2', c = 99 'c', d = 52 '4', e = 101 'e', f = 54 '6', g = 103 'g', h = 56 '8'}" 140 "{a = 49 '1', b = 98 'b', c = 51 '3', d = 100 'd', e = 53 '5', f = 102 'f', g = 55 '7', h = 104 'h', i = 57 '9'}" 141 "{a = 97 'a', b = 50 '2', c = 99 'c', d = 52 '4', e = 101 'e', f = 54 '6', g = 103 'g', h = 56 '8', i = 105 'i', j = 65 'A'}" 142 "{a = 49 '1', b = 98 'b', c = 51 '3', d = 100 'd', e = 53 '5', f = 102 'f', g = 55 '7', h = 104 'h', i = 57 '9', j = 106 'j', k = 66 'B'}" 143 "{a = 97 'a', b = 50 '2', c = 99 'c', d = 52 '4', e = 101 'e', f = 54 '6', g = 103 'g', h = 56 '8', i = 105 'i', j = 65 'A', k = 107 'k', l = 67 'C'}" 144 "{a = 49 '1', b = 98 'b', c = 51 '3', d = 100 'd', e = 53 '5', f = 102 'f', g = 55 '7', h = 104 'h', i = 57 '9', j = 106 'j', k = 66 'B', l = 108 'l', m = 68 'D'}" 145 "{a = 97 'a', b = 50 '2', c = 99 'c', d = 52 '4', e = 101 'e', f = 54 '6', g = 103 'g', h = 56 '8', i = 105 'i', j = 65 'A', k = 107 'k', l = 67 'C', m = 109 'm', n = 69 'E'}" 146 "{a = 49 '1', b = 98 'b', c = 51 '3', d = 100 'd', e = 53 '5', f = 102 'f', g = 55 '7', h = 104 'h', i = 57 '9', j = 106 'j', k = 66 'B', l = 108 'l', m = 68 'D', n = 110 'n', o = 70 'F'}" 147 "{a = 97 'a', b = 50 '2', c = 99 'c', d = 52 '4', e = 101 'e', f = 54 '6', g = 103 'g', h = 56 '8', i = 105 'i', j = 65 'A', k = 107 'k', l = 67 'C', m = 109 'm', n = 69 'E', o = 111 'o', p = 71 'G'}" 148 "{a = 49 '1', b = 98 'b', c = 51 '3', d = 100 'd', e = 53 '5', f = 102 'f', g = 55 '7', h = 104 'h', i = 57 '9', j = 106 'j', k = 66 'B', l = 108 'l', m = 68 'D', n = 110 'n', o = 70 'F', p = 112 'p', q = 72 'H'}" 149 } $n] 150} 151 152proc zed { n } { 153 return [lindex { 154 "{}" 155 "{a = 90 'Z'}" 156 "{a = 90 'Z', b = 90 'Z'}" 157 "{a = 90 'Z', b = 90 'Z', c = 90 'Z'}" 158 "{a = 90 'Z', b = 90 'Z', c = 90 'Z', d = 90 'Z'}" 159 "{a = 90 'Z', b = 90 'Z', c = 90 'Z', d = 90 'Z', e = 90 'Z'}" 160 "{a = 90 'Z', b = 90 'Z', c = 90 'Z', d = 90 'Z', e = 90 'Z', f = 90 'Z'}" 161 "{a = 90 'Z', b = 90 'Z', c = 90 'Z', d = 90 'Z', e = 90 'Z', f = 90 'Z', g = 90 'Z'}" 162 "{a = 90 'Z', b = 90 'Z', c = 90 'Z', d = 90 'Z', e = 90 'Z', f = 90 'Z', g = 90 'Z', h = 90 'Z'}" 163 "{a = 90 'Z', b = 90 'Z', c = 90 'Z', d = 90 'Z', e = 90 'Z', f = 90 'Z', g = 90 'Z', h = 90 'Z', i = 90 'Z'}" 164 "{a = 90 'Z', b = 90 'Z', c = 90 'Z', d = 90 'Z', e = 90 'Z', f = 90 'Z', g = 90 'Z', h = 90 'Z', i = 90 'Z', j = 90 'Z'}" 165 "{a = 90 'Z', b = 90 'Z', c = 90 'Z', d = 90 'Z', e = 90 'Z', f = 90 'Z', g = 90 'Z', h = 90 'Z', i = 90 'Z', j = 90 'Z', k = 90 'Z'}" 166 "{a = 90 'Z', b = 90 'Z', c = 90 'Z', d = 90 'Z', e = 90 'Z', f = 90 'Z', g = 90 'Z', h = 90 'Z', i = 90 'Z', j = 90 'Z', k = 90 'Z', l = 90 'Z'}" 167 "{a = 90 'Z', b = 90 'Z', c = 90 'Z', d = 90 'Z', e = 90 'Z', f = 90 'Z', g = 90 'Z', h = 90 'Z', i = 90 'Z', j = 90 'Z', k = 90 'Z', l = 90 'Z', m = 90 'Z'}" 168 "{a = 90 'Z', b = 90 'Z', c = 90 'Z', d = 90 'Z', e = 90 'Z', f = 90 'Z', g = 90 'Z', h = 90 'Z', i = 90 'Z', j = 90 'Z', k = 90 'Z', l = 90 'Z', m = 90 'Z', n = 90 'Z'}" 169 "{a = 90 'Z', b = 90 'Z', c = 90 'Z', d = 90 'Z', e = 90 'Z', f = 90 'Z', g = 90 'Z', h = 90 'Z', i = 90 'Z', j = 90 'Z', k = 90 'Z', l = 90 'Z', m = 90 'Z', n = 90 'Z', o = 90 'Z'}" 170 "{a = 90 'Z', b = 90 'Z', c = 90 'Z', d = 90 'Z', e = 90 'Z', f = 90 'Z', g = 90 'Z', h = 90 'Z', i = 90 'Z', j = 90 'Z', k = 90 'Z', l = 90 'Z', m = 90 'Z', n = 90 'Z', o = 90 'Z', p = 90 'Z'}" 171 "{a = 90 'Z', b = 90 'Z', c = 90 'Z', d = 90 'Z', e = 90 'Z', f = 90 'Z', g = 90 'Z', h = 90 'Z', i = 90 'Z', j = 90 'Z', k = 90 'Z', l = 90 'Z', m = 90 'Z', n = 90 'Z', o = 90 'Z', p = 90 'Z', q = 90 'Z'}" 172 } $n] 173} 174 175proc any { n } { 176 global anychar_re 177 set ac $anychar_re 178 return [lindex [list \ 179 "{}" \ 180 "{a = ${ac}}" \ 181 "{a = ${ac}, b = ${ac}}" \ 182 "{a = ${ac}, b = ${ac}, c = ${ac}}" \ 183 "{a = ${ac}, b = ${ac}, c = ${ac}, d = ${ac}}" \ 184 "{a = ${ac}, b = ${ac}, c = ${ac}, d = ${ac}, e = ${ac}}" \ 185 "{a = ${ac}, b = ${ac}, c = ${ac}, d = ${ac}, e = ${ac}, f = ${ac}}" \ 186 "{a = ${ac}, b = ${ac}, c = ${ac}, d = ${ac}, e = ${ac}, f = ${ac}, g = ${ac}}" \ 187 "{a = ${ac}, b = ${ac}, c = ${ac}, d = ${ac}, e = ${ac}, f = ${ac}, g = ${ac}, h = ${ac}}" \ 188 "{a = ${ac}, b = ${ac}, c = ${ac}, d = ${ac}, e = ${ac}, f = ${ac}, g = ${ac}, h = ${ac}, i = ${ac}}" \ 189 "{a = ${ac}, b = ${ac}, c = ${ac}, d = ${ac}, e = ${ac}, f = ${ac}, g = ${ac}, h = ${ac}, i = ${ac}, j = ${ac}}" \ 190 "{a = ${ac}, b = ${ac}, c = ${ac}, d = ${ac}, e = ${ac}, f = ${ac}, g = ${ac}, h = ${ac}, i = ${ac}, j = ${ac}, k = ${ac}}" \ 191 "{a = ${ac}, b = ${ac}, c = ${ac}, d = ${ac}, e = ${ac}, f = ${ac}, g = ${ac}, h = ${ac}, i = ${ac}, j = ${ac}, k = ${ac}, l = ${ac}}" \ 192 "{a = ${ac}, b = ${ac}, c = ${ac}, d = ${ac}, e = ${ac}, f = ${ac}, g = ${ac}, h = ${ac}, i = ${ac}, j = ${ac}, k = ${ac}, l = ${ac}, m = ${ac}}" \ 193 "{a = ${ac}, b = ${ac}, c = ${ac}, d = ${ac}, e = ${ac}, f = ${ac}, g = ${ac}, h = ${ac}, i = ${ac}, j = ${ac}, k = ${ac}, l = ${ac}, m = ${ac}, n = ${ac}}" \ 194 "{a = ${ac}, b = ${ac}, c = ${ac}, d = ${ac}, e = ${ac}, f = ${ac}, g = ${ac}, h = ${ac}, i = ${ac}, j = ${ac}, k = ${ac}, l = ${ac}, m = ${ac}, n = ${ac}, o = ${ac}}" \ 195 "{a = ${ac}, b = ${ac}, c = ${ac}, d = ${ac}, e = ${ac}, f = ${ac}, g = ${ac}, h = ${ac}, i = ${ac}, j = ${ac}, k = ${ac}, l = ${ac}, m = ${ac}, n = ${ac}, o = ${ac}, p = ${ac}}" \ 196 "{a = ${ac}, b = ${ac}, c = ${ac}, d = ${ac}, e = ${ac}, f = ${ac}, g = ${ac}, h = ${ac}, i = ${ac}, j = ${ac}, k = ${ac}, l = ${ac}, m = ${ac}, n = ${ac}, o = ${ac}, p = ${ac}, q = ${ac}}" \ 197 ] $n] 198} 199 200# Given N (0..25), return the corresponding alphabetic letter in lower 201# or upper case. This is ment to be i18n proof. 202 203proc i2a { n } { 204 return [string range "abcdefghijklmnopqrstuvwxyz" $n $n] 205} 206 207proc I2A { n } { 208 return [string toupper [i2a $n]] 209} 210 211 212# Use the file name, compiler and tuples to set up any needed KFAILs. 213 214proc setup_compiler_kfails { file compiler format tuples bug } { 215 global testfile 216 if {[string match $file $testfile] && [test_compiler_info $compiler] && [test_debug_format $format]} { 217 foreach f $tuples { setup_kfail $bug $f } 218 } 219} 220 221# Test GDB's ability to make inferior function calls to functions 222# returning (or passing in a single structs. 223 224# N identifies the number of elements in the struct that will be used 225# for the test case. FAILS is a list of target tuples that will fail 226# this test. 227 228# start_structs_test() will have previously built a program with a 229# specified combination of types for those elements. To ensure 230# robustness of the output, "p/c" is used. 231 232# This tests the code paths "which return-value convention?" and 233# "extract return-value from registers" called by "infcall.c". 234 235proc test_struct_calls { n } { 236 global testfile 237 global gdb_prompt 238 239 # Check that GDB can always extract a struct-return value from an 240 # inferior function call. Since GDB always knows the location of an 241 # inferior function call's return value these should never fail 242 243 # Implemented by calling the parameterless function "fun$N" and then 244 # examining the return value printed by GDB. 245 246 set tests "call $n ${testfile}" 247 248 # Call fun${n}, checking the printed return-value. 249 setup_compiler_kfails structs-tc-tll gcc-3-3-* "DWARF 2" i*86-*-* gdb/1455 250 setup_compiler_kfails structs-tc-td gcc-3-3-* "DWARF 2" i*86-*-* gdb/1455 251 gdb_test "p/c fun${n}()" "[foo ${n}]" "p/c fun<n>(); ${tests}" 252 253 # Check that GDB can always pass a structure to an inferior function. 254 # This test can never fail. 255 256 # Implemented by calling the one parameter function "Fun$N" which 257 # stores its parameter in the global variable "L$N". GDB then 258 # examining that global to confirm that the value is as expected. 259 260 gdb_test_no_output "call Fun${n}(foo${n})" "call Fun<n>(foo<n>); ${tests}" 261 setup_compiler_kfails structs-tc-tll gcc-3-3-* "DWARF 2" i*86-*-* gdb/1455 262 setup_compiler_kfails structs-tc-td gcc-3-3-* "DWARF 2" i*86-*-* gdb/1455 263 gdb_test "p/c L${n}" [foo ${n}] "p/c L<n>; ${tests}" 264} 265 266# Test GDB's ability to both return a function (with "return" or 267# "finish") and correctly extract/store any corresponding 268# return-value. 269 270# Check that GDB can consistently extract/store structure return 271# values. There are two cases - returned in registers and returned in 272# memory. For the latter case, the return value can't be found and a 273# failure is "expected". However GDB must still both return the 274# function and display the final source and line information. 275 276# N identifies the number of elements in the struct that will be used 277# for the test case. FAILS is a list of target tuples that will fail 278# this test. 279 280# This tests the code paths "which return-value convention?", "extract 281# return-value from registers", and "store return-value in registers". 282# Unlike "test struct calls", this test is expected to "fail" when the 283# return-value is in memory (GDB can't find the location). The test 284# is in three parts: test "return"; test "finish"; check that the two 285# are consistent. GDB can sometimes work for one command and not the 286# other. 287 288proc test_struct_returns { n } { 289 global gdb_prompt 290 global testfile 291 292 set tests "return $n ${testfile}" 293 294 295 # Check that "return" works. 296 297 # GDB must always force the return of a function that has 298 # a struct result. Dependant on the ABI, it may, or may not be 299 # possible to store the return value in a register. 300 301 # The relevant code looks like "L{n} = fun{n}()". The test forces 302 # "fun{n}" to "return" with an explicit value. Since that code 303 # snippet will store the the returned value in "L{n}" the return 304 # is tested by examining "L{n}". This assumes that the 305 # compiler implemented this as fun{n}(&L{n}) and hence that when 306 # the value isn't stored "L{n}" remains unchanged. Also check for 307 # consistency between this and the "finish" case. 308 309 # Get into a call of fun${n} 310 gdb_test "advance fun${n}" \ 311 "fun${n} .*\[\r\n\]+\[0-9\].*return foo${n}.*" \ 312 "advance to fun<n> for return; ${tests}" 313 314 # Check that the program invalidated the relevant global. 315 gdb_test "p/c L${n}" " = [zed $n]" "zed L<n> for return; ${tests}" 316 317 # Force the "return". This checks that the return is always 318 # performed, and that GDB correctly reported this to the user. 319 # GDB 6.0 and earlier, when the return-value's location wasn't 320 # known, both failed to print a final "source and line" and misplaced 321 # the frame ("No frame"). 322 323 # The test is writen so that it only reports one FAIL/PASS for the 324 # entire operation. The value returned is checked further down. 325 # "return_value_known", if non-zero, indicates that GDB knew where 326 # the return value was located. 327 328 set test "return foo<n>; ${tests}" 329 set return_value_known 1 330 set return_value_unimplemented 0 331 gdb_test_multiple "return foo${n}" "${test}" { 332 -re "The location" { 333 # Ulgh, a struct return, remember this (still need prompt). 334 set return_value_known 0 335 exp_continue 336 } 337 -re "A structure or union" { 338 # Ulgh, a struct return, remember this (still need prompt). 339 set return_value_known 0 340 # Double ulgh. Architecture doesn't use return_value and 341 # hence hasn't implemented small structure return. 342 set return_value_unimplemented 1 343 exp_continue 344 } 345 -re "Make fun${n} return now.*y or n. $" { 346 gdb_test_multiple "y" "${test}" { 347 -re "L${n} *= fun${n}.*${gdb_prompt} $" { 348 # Need to step off the function call 349 gdb_test "next" "L.* *= fun.*" "${test}" 350 } 351 -re "L[expr ${n} + 1] *= fun[expr ${n} + 1].*${gdb_prompt} $" { 352 pass "${test}" 353 } 354 } 355 } 356 } 357 358 # Check that the return-value is as expected. At this stage we're 359 # just checking that GDB has returned a value consistent with 360 # "return_value_known" set above. 361 # 362 # Note that, when return_value_known is false, we can't make any 363 # assumptions at all about the value L<n>: 364 # 365 # - If the caller passed the address of L<n> directly as fun<n>'s 366 # return value buffer, then L<n> will be unchanged, because we 367 # forced fun<n> to return before it could store anything in it. 368 # 369 # - If the caller passed the address of some temporary buffer to 370 # fun<n>, and then copied the buffer into L<n>, then L<n> will 371 # have been overwritten with whatever garbage was in the 372 # uninitialized buffer. 373 # 374 # - However, if the temporary buffer just happened to have the 375 # "right" value of foo<n> in it, then L<n> will, in fact, have 376 # the value you'd expect to see if the 'return' had worked! 377 # This has actually been observed to happen on the Renesas M32C. 378 # 379 # So, really, anything is acceptable unless return_value_known is 380 # true. 381 382 set test "value foo<n> returned; ${tests}" 383 gdb_test_multiple "p/c L${n}" "${test}" { 384 -re " = [foo ${n}].*${gdb_prompt} $" { 385 # This answer is okay regardless of whether GDB claims to 386 # have set the return value: if it did, then this is what 387 # we expected; and if it didn't, then any answer is okay. 388 pass "${test}" 389 } 390 -re " = [any $n].*${gdb_prompt} $" { 391 if $return_value_known { 392 # This contradicts the above claim that GDB knew 393 # the location of the return value. 394 fail "${test}" 395 } else { 396 # We expected L${n} to be set to garbage, so any 397 # answer is acceptable. 398 pass "${test}" 399 } 400 } 401 -re ".*${gdb_prompt} $" { 402 if $return_value_unimplemented { 403 # What a suprize. The architecture hasn't implemented 404 # return_value, and hence has to fail. 405 kfail "$test" gdb/1444 406 } else { 407 fail "$test" 408 } 409 } 410 } 411 412 # Check that a "finish" works. 413 414 # This is almost but not quite the same as "call struct funcs". 415 # Architectures can have subtle differences in the two code paths. 416 417 # The relevant code snippet is "L{n} = fun{n}()". The program is 418 # advanced into a call to "fun{n}" and then that function is 419 # finished. The returned value that GDB prints, reformatted using 420 # "p/c", is checked. 421 422 # Get into "fun${n}()". 423 gdb_test "advance fun${n}" \ 424 "fun${n} .*\[\r\n\]+\[0-9\].*return foo${n}.*" \ 425 "advance to fun<n> for finish; ${tests}" 426 427 # Check that the program invalidated the relevant global. 428 gdb_test "p/c L${n}" " = [zed $n]" "zed L<n> for finish; ${tests}" 429 430 # Finish the function, set 'finish_value_known" to non-empty if 431 # the return-value was found. 432 433 set test "finish foo<n>; ${tests}" 434 set finish_value_known 1 435 gdb_test_multiple "finish" "${test}" { 436 -re "Value returned is .*${gdb_prompt} $" { 437 pass "${test}" 438 } 439 -re "Cannot determine contents.*${gdb_prompt} $" { 440 # Expected bad value. For the moment this is ok. 441 set finish_value_known 0 442 pass "${test}" 443 } 444 } 445 446 # Re-print the last (return-value) using the more robust 447 # "p/c". If no return value was found, the 'Z' from the previous 448 # check that the variable was cleared, is printed. 449 set test "value foo<n> finished; ${tests}" 450 gdb_test_multiple "p/c" "${test}" { 451 -re "[foo ${n}]\[\r\n\]+${gdb_prompt} $" { 452 if $finish_value_known { 453 pass "${test}" 454 } else { 455 # This contradicts the above claim that GDB didn't 456 # know the location of the return-value. 457 fail "${test}" 458 } 459 } 460 -re "[zed ${n}]\[\r\n\]+${gdb_prompt} $" { 461 # The value didn't get found. This is "expected". 462 if $finish_value_known { 463 # This contradicts the above claim that GDB did 464 # know the location of the return-value. 465 fail "${test}" 466 } else { 467 pass "${test}" 468 } 469 } 470 } 471 472 # Finally, check that "return" and finish" have consistent 473 # behavior. 474 475 # Since "finish" works in more cases than "return" (see 476 # RETURN_VALUE_ABI_RETURNS_ADDRESS and 477 # RETURN_VALUE_ABI_PRESERVES_ADDRESS), the "return" value being 478 # known implies that the "finish" value is known (but not the 479 # reverse). 480 481 set test "return value known implies finish value known; ${tests}" 482 if {$return_value_known && ! $finish_value_known} { 483 kfail gdb/1444 "${test}" 484 } else { 485 pass "${test}" 486 } 487} 488 489# ABIs pass anything >8 or >16 bytes in memory but below that things 490# randomly use register and/and structure conventions. Check all 491# possible sized char structs in that range. But only a restricted 492# range of the other types. 493 494# NetBSD/PPC returns "unnatural" (3, 5, 6, 7) sized structs in memory. 495 496# d10v is weird. 5/6 byte structs go in memory. 2 or more char 497# structs go in memory. Everything else is in a register! 498 499# Test every single char struct from 1..17 in size. This is what the 500# original "structs" test was doing. 501 502start_structs_test { tc } 503test_struct_calls 1 504test_struct_calls 2 505test_struct_calls 3 506test_struct_calls 4 507test_struct_calls 5 508test_struct_calls 6 509test_struct_calls 7 510test_struct_calls 8 511test_struct_calls 9 512test_struct_calls 10 513test_struct_calls 11 514test_struct_calls 12 515test_struct_calls 13 516test_struct_calls 14 517test_struct_calls 15 518test_struct_calls 16 519test_struct_calls 17 520test_struct_returns 1 521test_struct_returns 2 522test_struct_returns 3 523test_struct_returns 4 524test_struct_returns 5 525test_struct_returns 6 526test_struct_returns 7 527test_struct_returns 8 528 529 530# Let the fun begin. 531 532# Assuming that any integer struct larger than 8 bytes goes in memory, 533# come up with many and varied combinations of a return struct. For 534# "struct calls" test just beyond that 8 byte boundary, for "struct 535# returns" test up to that boundary. 536 537# For floats, assumed that up to two struct elements can be stored in 538# floating point registers, regardless of their size. 539 540# The approx size of each structure it is computed assumed that tc=1, 541# ts=2, ti=4, tl=4, tll=8, tf=4, td=8, tld=16, and that all fields are 542# naturally aligned. Padding being added where needed. Note that 543# these numbers are just approx, the d10v has ti=2, a 64-bit has has 544# tl=8. 545 546# Approx size: 2, 4, ... 547start_structs_test { ts } 548test_struct_calls 1 549test_struct_calls 2 550test_struct_calls 3 551test_struct_calls 4 552test_struct_calls 5 553test_struct_returns 1 554test_struct_returns 2 555test_struct_returns 3 556test_struct_returns 4 557 558# Approx size: 4, 8, ... 559start_structs_test { ti } 560test_struct_calls 1 561test_struct_calls 2 562test_struct_calls 3 563test_struct_returns 1 564test_struct_returns 2 565 566# Approx size: 4, 8, ... 567start_structs_test { tl } 568test_struct_calls 1 569test_struct_calls 2 570test_struct_calls 3 571test_struct_returns 1 572test_struct_returns 2 573 574# Approx size: 8, 16, ... 575start_structs_test { tll } 576test_struct_calls 1 577test_struct_calls 2 578test_struct_returns 1 579 580# Approx size: 4, 8, ... 581start_structs_test { tf } 582test_struct_calls 1 583test_struct_calls 2 584test_struct_calls 3 585test_struct_returns 1 586test_struct_returns 2 587 588# Approx size: 8, 16, ... 589start_structs_test { td } 590test_struct_calls 1 591test_struct_calls 2 592test_struct_returns 1 593 594# Approx size: 16, 32, ... 595start_structs_test { tld } 596test_struct_calls 1 597test_struct_calls 2 598test_struct_returns 1 599 600# Approx size: 2+1=3, 4, ... 601start_structs_test { ts tc } 602test_struct_calls 2 603test_struct_calls 3 604test_struct_calls 4 605test_struct_calls 5 606test_struct_calls 6 607test_struct_calls 7 608test_struct_calls 8 609test_struct_returns 2 610 611# Approx size: 4+1=5, 6, ... 612start_structs_test { ti tc } 613test_struct_calls 2 614test_struct_calls 3 615test_struct_calls 4 616test_struct_calls 5 617test_struct_calls 6 618test_struct_returns 2 619 620# Approx size: 4+1=5, 6, ... 621start_structs_test { tl tc } 622test_struct_calls 2 623test_struct_calls 3 624test_struct_calls 4 625test_struct_calls 5 626test_struct_calls 6 627test_struct_returns 2 628 629# Approx size: 8+1=9, 10, ... 630start_structs_test { tll tc } 631test_struct_calls 2 632 633# Approx size: 4+1=5, 6, ... 634start_structs_test { tf tc } 635test_struct_calls 2 636test_struct_calls 3 637test_struct_calls 4 638test_struct_calls 5 639test_struct_calls 6 640test_struct_returns 2 641 642# Approx size: 8+1=9, 10, ... 643start_structs_test { td tc } 644test_struct_calls 2 645 646# Approx size: 16+1=17, 18, ... 647start_structs_test { tld tc } 648test_struct_calls 2 649 650# Approx size: (1+1)+2=4, 6, ... 651start_structs_test { tc ts } 652test_struct_calls 2 653test_struct_calls 3 654test_struct_calls 4 655test_struct_calls 5 656test_struct_calls 6 657test_struct_returns 2 658 659# Approx size: (1+3)+4=8, 12, ... 660start_structs_test { tc ti } 661test_struct_calls 2 662test_struct_calls 3 663test_struct_calls 4 664test_struct_returns 2 665 666# Approx size: (1+3)+4=8, 12, ... 667start_structs_test { tc tl } 668test_struct_calls 2 669test_struct_calls 3 670test_struct_calls 4 671test_struct_returns 2 672 673# Approx size: (1+7)+8=16, 24, ... 674start_structs_test { tc tll } 675test_struct_calls 2 676 677# Approx size: (1+3)+4=8, 12, ... 678start_structs_test { tc tf } 679test_struct_calls 2 680test_struct_calls 3 681test_struct_calls 4 682 683# Approx size: (1+7)+8=16, 24, ... 684start_structs_test { tc td } 685test_struct_calls 2 686 687# Approx size: (1+15)+16=32, 48, ... 688start_structs_test { tc tld } 689test_struct_calls 2 690 691# Some float combinations 692 693# Approx size: 8+4=12, 16, ... 694# d10v: 4+4=8, 12, ... 695start_structs_test { td tf } 696test_struct_calls 2 697test_struct_returns 2 698 699# Approx size: (4+4)+8=16, 32, ... 700# d10v: 4+4=8, 12, ... 701start_structs_test { tf td } 702test_struct_calls 2 703test_struct_returns 2 704 705return 0 706