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}
97 {discr_value 23 udata}
101 {data_member_location 4 data1}
106 {discr_value 1 udata}
110 {data_member_location 4 data1}
118 {byte_size 8 DW_FORM_sdata}
121 {discr :$discr_2_label DW_FORM_ref4}
123 discr_2_label: member {
124 {type :$uinteger_label}
125 {data_member_location 0 data1}
132 {data_member_location 4 data1}
137 {discr_value 1 udata}
141 {data_member_location 4 data1}
149 {byte_size 8 DW_FORM_sdata}
157 {data_member_location 4 data1}
163 # Rust won't emit a negative discriminant like this, but
164 # we want to test the code path anyway.
167 {byte_size 8 DW_FORM_sdata}
170 {discr :$discr_3_label DW_FORM_ref4}
172 discr_3_label: member {
174 {data_member_location 0 data1}
178 {discr_value -1 sdata}
182 {data_member_location 4 data1}
186 # Make this the default value so we'll see an
187 # incorrect result if we mishandle signed
193 {data_member_location 4 data1}
202 if { [prepare_for_testing "failed to prepare" ${testfile} \
203 [list $srcfile $asm_file] debug] } {
211 # Get the values into history so we can use it from Rust.
212 gdb_test "print (void *) buffer" "\\\$1 = .void .. $hex .buffer."
213 gdb_test "print (void *) buffer2" "\\\$2 = .void .. $hex .buffer2."
215 gdb_test "set language rust"
216 gdb_test "print *(\$1 as *mut Simple)" " = One\\(23\\)" \
218 gdb_test "print *(\$1 as *mut Defaulted)" " = One\\(23\\)" \
220 gdb_test "print *(\$1 as *mut Univariant)" " = One\\(23\\)" \
221 "print as Univariant"
223 gdb_test "print *(\$2 as *mut Negative)" " = One\\(23\\)" \