1 # This testcase is part of GDB, the GNU debugger.
3 # Copyright 2018-2020 Free Software Foundation, Inc.
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.
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.
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/>.
18 # Some targets can't call functions, so don't even bother with this
21 if [target_info exists gdb
,cannot_call_functions
] {
22 unsupported
"this target can not call functions"
26 set int_types
{ tc ts ti tl tll
}
27 set float_types
{ tf td tld
}
28 set complex_types
{ tfc tdc tldc
}
30 set compile_flags
{debug
}
31 if [support_complex_tests
] {
32 lappend compile_flags
"additional_flags=-DTEST_COMPLEX"
33 lappend compile_flags
"additional_flags=-Wno-psabi"
36 # Given N (0..25), return the corresponding alphabetic letter in upper
40 return [string range
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" $n $n]
43 # Compile a variant of nested-structs.c using TYPES to specify the
44 # types of the struct fields within the source. Run up to main.
45 # Also updates the global "testfile" to reflect the most recent build.
47 proc start_nested_structs_test
{ lang types
} {
55 standard_testfile infcall-nested-structs.c
57 # Create the additional flags
58 set flags
$compile_flags
60 lappend flags
"additional_flags=-O2"
62 for {set n
0} {$n<[llength ${types
}]} {incr n
} {
64 set t
[lindex ${types
} $n]
65 lappend flags
"additional_flags=-Dt${m}=${t}"
66 append testfile
"-" "$t"
69 if { [gdb_compile
"${srcdir}/${subdir}/${srcfile}" "${binfile}" executable
"${flags}"] != "" } {
70 unresolved
"failed to compile"
74 # Start with a fresh gdb.
75 clean_restart
${binfile
}
77 # Make certain that the output is consistent
78 gdb_test_no_output
"set print sevenbit-strings"
79 gdb_test_no_output
"set print address off"
80 gdb_test_no_output
"set print pretty off"
81 gdb_test_no_output
"set width 0"
82 gdb_test_no_output
"set print elements 300"
85 if { ![runto_main
] } then
{
86 fail
"can't run to main"
90 # Now continue forward to a suitable location to run the tests.
91 # Some targets only enable the FPU on first use, so ensure that we
92 # have used the FPU before we make calls from GDB to code that
94 gdb_breakpoint
[gdb_get_line_number
"Break Here"] temporary
95 gdb_continue_to_breakpoint
"breakpt" ".* Break Here\\. .*"
100 # Assuming GDB is stopped at main within a test binary, run some tests
101 # passing structures, and reading return value structures.
103 proc run_tests
{ lang types
} {
106 foreach {name
} {struct_01_01 struct_01_02 struct_01_03 struct_01_04
107 struct_02_01 struct_02_02 struct_02_03 struct_02_04
108 struct_04_01 struct_04_02 struct_04_03 struct_04_04
109 struct_05_01 struct_05_02 struct_05_03 struct_05_04
110 struct_static_02_01 struct_static_02_02 struct_static_02_03 struct_static_02_04
111 struct_static_04_01 struct_static_04_02 struct_static_04_03 struct_static_04_04
112 struct_static_06_01 struct_static_06_02 struct_static_06_03 struct_static_06_04
} {
114 # Only run static member tests on C++
115 if { $lang == "c" && [regexp "static" $name match
] } {
119 gdb_test
"p/d check_arg_${name} (ref_val_${name})" "= 1"
121 set refval
[ get_valueof
"" "ref_val_${name}" "" ]
122 verbose
-log "Refval: ${refval}"
124 set test
"check return value ${name}"
125 if { ${refval
} != "" } {
127 set answer
[ get_valueof
"" "rtn_str_${name} ()" "XXXX"]
128 verbose
-log "Answer: ${answer}"
130 gdb_assert
[string eq
${answer
} ${refval
}] ${test
}
137 # Set up a test prefix, compile the test binary, run to main, and then
140 proc start_gdb_and_run_tests
{ lang types
} {
144 append prefix
"-" "${t}"
147 with_test_prefix
$prefix {
148 if { [start_nested_structs_test
$lang $types] } {
149 run_tests
$lang $prefix
154 foreach ta
$int_types {
155 start_gdb_and_run_tests
$lang $ta
158 if [support_complex_tests
] {
159 foreach ta
$complex_types {
160 start_gdb_and_run_tests
$lang $ta
164 if ![gdb_skip_float_test
] {
165 foreach ta
$float_types {
166 start_gdb_and_run_tests
$lang $ta
169 foreach ta
$int_types {
170 foreach tb
$float_types {
171 start_gdb_and_run_tests
$lang [list $ta $tb]
175 foreach ta
$float_types {
176 foreach tb
$int_types {
177 start_gdb_and_run_tests
$lang [list $ta $tb]
180 foreach tb
$float_types {
181 start_gdb_and_run_tests
$lang [list $ta $tb]