1 # Copyright 2018-2020 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 # Test DW_TAG_variant_part and DW_TAG_variant.
20 # This test can only be run on targets which support DWARF-2 and use
22 if {![dwarf2_support]} {
26 standard_testfile .c variant.S
28 # Make some DWARF for the test.
29 set asm_file [standard_output_file $srcfile2]
30 Dwarf::assemble $asm_file {
33 declare_labels uinteger_label float_label int8_label
34 declare_labels discr_1_label discr_2_label discr_3_label
35 declare_labels one_label two_label
37 # Creating a CU with 4-byte addresses lets this test link on
38 # both 32- and 64-bit machines.
42 {language @DW_LANG_Rust}
44 uinteger_label: DW_TAG_base_type {
45 {DW_AT_byte_size 4 DW_FORM_sdata}
46 {DW_AT_encoding @DW_ATE_unsigned}
47 {DW_AT_name {unsigned integer}}
50 int8_label: DW_TAG_base_type {
51 {DW_AT_byte_size 1 DW_FORM_sdata}
52 {DW_AT_encoding @DW_ATE_signed}
56 float_label: base_type {
58 {encoding @DW_ATE_float}
59 {byte_size 4 DW_FORM_sdata}
62 one_label: structure_type {
64 {byte_size 4 DW_FORM_sdata}
68 {type :$uinteger_label}
69 {data_member_location 0 data1}
73 two_label: structure_type {
75 {byte_size 4 DW_FORM_sdata}
80 {data_member_location 0 data1}
86 {byte_size 8 DW_FORM_sdata}
89 {discr :$discr_1_label DW_FORM_ref4}
91 discr_1_label: member {
92 {type :$uinteger_label}
93 {data_member_location 0 data1}
94 {artificial 1 DW_FORM_flag_present}
98 {discr_value 23 udata}
102 {data_member_location 4 data1}
107 {discr_value 1 udata}
111 {data_member_location 4 data1}
119 {byte_size 8 DW_FORM_sdata}
122 {discr :$discr_2_label DW_FORM_ref4}
124 discr_2_label: member {
125 {type :$uinteger_label}
126 {data_member_location 0 data1}
127 {artificial 1 DW_FORM_flag_present}
134 {data_member_location 4 data1}
139 {discr_value 1 udata}
143 {data_member_location 4 data1}
151 {byte_size 8 DW_FORM_sdata}
159 {data_member_location 4 data1}
165 # Rust won't emit a negative discriminant like this, but
166 # we want to test the code path anyway.
169 {byte_size 8 DW_FORM_sdata}
172 {discr :$discr_3_label DW_FORM_ref4}
174 discr_3_label: member {
176 {data_member_location 0 data1}
177 {artificial 1 DW_FORM_flag_present}
181 {discr_value -1 sdata}
185 {data_member_location 4 data1}
189 # Make this the default value so we'll see an
190 # incorrect result if we mishandle signed
196 {data_member_location 4 data1}
205 if { [prepare_for_testing "failed to prepare" ${testfile} \
206 [list $srcfile $asm_file] debug] } {
214 # Get the values into history so we can use it from Rust.
215 gdb_test "print (void *) buffer" "\\\$1 = .void .. $hex .buffer."
216 gdb_test "print (void *) buffer2" "\\\$2 = .void .. $hex .buffer2."
218 gdb_test "set language rust"
219 gdb_test "print *(\$1 as *mut Simple)" " = One\\(23\\)" \
221 gdb_test "print *(\$1 as *mut Defaulted)" " = One\\(23\\)" \
223 gdb_test "print *(\$1 as *mut Univariant)" " = One\\(23\\)" \
224 "print as Univariant"
226 gdb_test "print *(\$2 as *mut Negative)" " = One\\(23\\)" \