Commit | Line | Data |
---|---|---|
dbbb1059 AB |
1 | # This testcase is part of GDB, the GNU debugger. |
2 | ||
b811d2c2 | 3 | # Copyright 2018-2020 Free Software Foundation, Inc. |
dbbb1059 AB |
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 | ||
18 | ||
19 | # Some targets can't call functions, so don't even bother with this | |
20 | # test. | |
21 | ||
22 | if [target_info exists gdb,cannot_call_functions] { | |
23 | unsupported "this target can not call functions" | |
24 | continue | |
25 | } | |
26 | ||
73021deb AH |
27 | # Only test C++ if we are able. Always use C. |
28 | if { [skip_cplus_tests] || [get_compiler_info "c++"] } { | |
29 | set lang {c} | |
30 | } else { | |
31 | set lang {c c++} | |
32 | } | |
33 | ||
34 | foreach l $lang { | |
35 | set dir "$l" | |
36 | remote_exec host "rm -rf [standard_output_file ${dir}]" | |
37 | remote_exec host "mkdir -p [standard_output_file ${dir}]" | |
38 | } | |
39 | ||
40 | ||
dbbb1059 AB |
41 | set int_types { tc ts ti tl tll } |
42 | set float_types { tf td tld } | |
43 | set complex_types { tfc tdc tldc } | |
44 | ||
45 | set compile_flags {debug} | |
46 | if [support_complex_tests] { | |
47 | lappend compile_flags "additional_flags=-DTEST_COMPLEX" | |
73021deb | 48 | lappend compile_flags "additional_flags=-Wno-psabi" |
dbbb1059 AB |
49 | } |
50 | ||
51 | # Given N (0..25), return the corresponding alphabetic letter in upper | |
52 | # case. | |
53 | ||
54 | proc I2A { n } { | |
55 | return [string range "ABCDEFGHIJKLMNOPQRSTUVWXYZ" $n $n] | |
56 | } | |
57 | ||
58 | # Compile a variant of nested-structs.c using TYPES to specify the | |
59 | # types of the struct fields within the source. Run up to main. | |
60 | # Also updates the global "testfile" to reflect the most recent build. | |
61 | ||
73021deb | 62 | proc start_nested_structs_test { lang types } { |
dbbb1059 AB |
63 | global testfile |
64 | global srcfile | |
65 | global binfile | |
66 | global subdir | |
67 | global srcdir | |
68 | global compile_flags | |
69 | ||
70 | standard_testfile .c | |
73021deb | 71 | set dir "$lang" |
dbbb1059 AB |
72 | |
73 | # Create the additional flags | |
74 | set flags $compile_flags | |
73021deb | 75 | lappend flags $lang |
94cb3754 | 76 | lappend flags "additional_flags=-O2" |
dbbb1059 AB |
77 | |
78 | for {set n 0} {$n<[llength ${types}]} {incr n} { | |
79 | set m [I2A ${n}] | |
80 | set t [lindex ${types} $n] | |
81 | lappend flags "additional_flags=-Dt${m}=${t}" | |
82 | append testfile "-" "$t" | |
83 | } | |
84 | ||
73021deb | 85 | set binfile [standard_output_file ${dir}/${testfile}] |
dbbb1059 AB |
86 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable "${flags}"] != "" } { |
87 | unresolved "failed to compile" | |
88 | return 0 | |
89 | } | |
90 | ||
91 | # Start with a fresh gdb. | |
92 | clean_restart ${binfile} | |
93 | ||
94 | # Make certain that the output is consistent | |
95 | gdb_test_no_output "set print sevenbit-strings" | |
96 | gdb_test_no_output "set print address off" | |
97 | gdb_test_no_output "set print pretty off" | |
98 | gdb_test_no_output "set width 0" | |
99 | gdb_test_no_output "set print elements 300" | |
100 | ||
101 | # Advance to main | |
102 | if { ![runto_main] } then { | |
103 | fail "can't run to main" | |
104 | return 0 | |
105 | } | |
106 | ||
107 | # Now continue forward to a suitable location to run the tests. | |
108 | # Some targets only enable the FPU on first use, so ensure that we | |
109 | # have used the FPU before we make calls from GDB to code that | |
110 | # could use the FPU. | |
111 | gdb_breakpoint [gdb_get_line_number "Break Here"] temporary | |
112 | gdb_continue_to_breakpoint "breakpt" ".* Break Here\\. .*" | |
113 | ||
114 | return 1 | |
115 | } | |
116 | ||
117 | # Assuming GDB is stopped at main within a test binary, run some tests | |
118 | # passing structures, and reading return value structures. | |
119 | ||
73021deb | 120 | proc run_tests { lang types } { |
dbbb1059 AB |
121 | global gdb_prompt |
122 | ||
36eb4c5f AH |
123 | foreach {name} {struct_01_01 struct_01_02 struct_01_03 struct_01_04 |
124 | struct_02_01 struct_02_02 struct_02_03 struct_02_04 | |
125 | struct_04_01 struct_04_02 struct_04_03 struct_04_04 | |
353229bf AH |
126 | struct_05_01 struct_05_02 struct_05_03 struct_05_04 |
127 | struct_static_02_01 struct_static_02_02 struct_static_02_03 struct_static_02_04 | |
128 | struct_static_04_01 struct_static_04_02 struct_static_04_03 struct_static_04_04 | |
129 | struct_static_06_01 struct_static_06_02 struct_static_06_03 struct_static_06_04} { | |
130 | ||
131 | # Only run static member tests on C++ | |
132 | if { $lang == "c" && [regexp "static" $name match] } { | |
133 | continue | |
134 | } | |
73021deb | 135 | |
dbbb1059 AB |
136 | gdb_test "p/d check_arg_${name} (ref_val_${name})" "= 1" |
137 | ||
138 | set refval [ get_valueof "" "ref_val_${name}" "" ] | |
139 | verbose -log "Refval: ${refval}" | |
140 | ||
141 | set test "check return value ${name}" | |
142 | if { ${refval} != "" } { | |
73021deb | 143 | |
dbbb1059 AB |
144 | set answer [ get_valueof "" "rtn_str_${name} ()" "XXXX"] |
145 | verbose -log "Answer: ${answer}" | |
73021deb | 146 | |
dbbb1059 AB |
147 | gdb_assert [string eq ${answer} ${refval}] ${test} |
148 | } else { | |
149 | unresolved $test | |
150 | } | |
151 | } | |
152 | } | |
153 | ||
154 | # Set up a test prefix, compile the test binary, run to main, and then | |
155 | # run some tests. | |
156 | ||
73021deb | 157 | proc start_gdb_and_run_tests { lang types } { |
dbbb1059 AB |
158 | set prefix "types" |
159 | ||
160 | foreach t $types { | |
161 | append prefix "-" "${t}" | |
162 | } | |
163 | ||
73021deb AH |
164 | foreach_with_prefix l $lang { |
165 | with_test_prefix $prefix { | |
166 | if { [start_nested_structs_test $l $types] } { | |
167 | run_tests $l $prefix | |
168 | } | |
dbbb1059 AB |
169 | } |
170 | } | |
171 | } | |
172 | ||
173 | foreach ta $int_types { | |
73021deb | 174 | start_gdb_and_run_tests $lang $ta |
dbbb1059 AB |
175 | } |
176 | ||
177 | if [support_complex_tests] { | |
178 | foreach ta $complex_types { | |
73021deb | 179 | start_gdb_and_run_tests $lang $ta |
dbbb1059 AB |
180 | } |
181 | } | |
182 | ||
183 | if ![gdb_skip_float_test] { | |
184 | foreach ta $float_types { | |
73021deb | 185 | start_gdb_and_run_tests $lang $ta |
dbbb1059 AB |
186 | } |
187 | ||
188 | foreach ta $int_types { | |
189 | foreach tb $float_types { | |
73021deb | 190 | start_gdb_and_run_tests $lang [list $ta $tb] |
dbbb1059 AB |
191 | } |
192 | } | |
193 | ||
194 | foreach ta $float_types { | |
195 | foreach tb $int_types { | |
73021deb | 196 | start_gdb_and_run_tests $lang [list $ta $tb] |
dbbb1059 AB |
197 | } |
198 | ||
199 | foreach tb $float_types { | |
73021deb | 200 | start_gdb_and_run_tests $lang [list $ta $tb] |
dbbb1059 AB |
201 | } |
202 | } | |
203 | } |