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