1 1.1 christos # Copyright 2018-2019 Free Software Foundation, Inc. 2 1.1 christos 3 1.1 christos # This program is free software; you can redistribute it and/or modify 4 1.1 christos # it under the terms of the GNU General Public License as published by 5 1.1 christos # the Free Software Foundation; either version 3 of the License, or 6 1.1 christos # (at your option) any later version. 7 1.1 christos # 8 1.1 christos # This program is distributed in the hope that it will be useful, 9 1.1 christos # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 1.1 christos # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 1.1 christos # GNU General Public License for more details. 12 1.1 christos # 13 1.1 christos # You should have received a copy of the GNU General Public License 14 1.1 christos # along with this program. If not, see <http://www.gnu.org/licenses/>. 15 1.1 christos 16 1.1 christos # Test DW_TAG_variant_part and DW_TAG_variant. 17 1.1 christos 18 1.1 christos load_lib dwarf.exp 19 1.1 christos 20 1.1 christos # This test can only be run on targets which support DWARF-2 and use 21 1.1 christos # gas. 22 1.1 christos if {![dwarf2_support]} { 23 1.1 christos return 0 24 1.1 christos } 25 1.1 christos 26 1.1 christos standard_testfile .c variant.S 27 1.1 christos 28 1.1 christos # Make some DWARF for the test. 29 1.1 christos set asm_file [standard_output_file $srcfile2] 30 1.1 christos Dwarf::assemble $asm_file { 31 1.1 christos upvar cu_lang cu_lang 32 1.1 christos 33 1.1 christos declare_labels uinteger_label float_label int8_label 34 1.1 christos declare_labels discr_1_label discr_2_label discr_3_label 35 1.1 christos declare_labels one_label two_label 36 1.1 christos 37 1.1 christos # Creating a CU with 4-byte addresses lets this test link on 38 1.1 christos # both 32- and 64-bit machines. 39 1.1 christos cu { addr_size 4 } { 40 1.1 christos compile_unit { 41 1.1 christos {name file1.txt} 42 1.1 christos {language @DW_LANG_Rust} 43 1.1 christos } { 44 1.1 christos uinteger_label: DW_TAG_base_type { 45 1.1 christos {DW_AT_byte_size 4 DW_FORM_sdata} 46 1.1 christos {DW_AT_encoding @DW_ATE_unsigned} 47 1.1 christos {DW_AT_name {unsigned integer}} 48 1.1 christos } 49 1.1 christos 50 1.1 christos int8_label: DW_TAG_base_type { 51 1.1 christos {DW_AT_byte_size 1 DW_FORM_sdata} 52 1.1 christos {DW_AT_encoding @DW_ATE_signed} 53 1.1 christos {DW_AT_name i8} 54 1.1 christos } 55 1.1 christos 56 1.1 christos float_label: base_type { 57 1.1 christos {name float} 58 1.1 christos {encoding @DW_ATE_float} 59 1.1 christos {byte_size 4 DW_FORM_sdata} 60 1.1 christos } 61 1.1 christos 62 1.1 christos one_label: structure_type { 63 1.1 christos {name One} 64 1.1 christos {byte_size 4 DW_FORM_sdata} 65 1.1 christos } { 66 1.1 christos member { 67 1.1 christos {name __0} 68 1.1 christos {type :$uinteger_label} 69 1.1 christos {data_member_location 0 data1} 70 1.1 christos } 71 1.1 christos } 72 1.1 christos 73 1.1 christos two_label: structure_type { 74 1.1 christos {name Two} 75 1.1 christos {byte_size 4 DW_FORM_sdata} 76 1.1 christos } { 77 1.1 christos member { 78 1.1 christos {name __0} 79 1.1 christos {type :$float_label} 80 1.1 christos {data_member_location 0 data1} 81 1.1 christos } 82 1.1 christos } 83 1.1 christos 84 1.1 christos structure_type { 85 1.1 christos {name Simple} 86 1.1 christos {byte_size 8 DW_FORM_sdata} 87 1.1 christos } { 88 1.1 christos variant_part { 89 1.1 christos {discr :$discr_1_label DW_FORM_ref4} 90 1.1 christos } { 91 1.1 christos discr_1_label: member { 92 1.1 christos {type :$uinteger_label} 93 1.1 christos {data_member_location 0 data1} 94 1.1 christos } 95 1.1 christos 96 1.1 christos variant { 97 1.1 christos {discr_value 23 udata} 98 1.1 christos } { 99 1.1 christos member { 100 1.1 christos {type :$one_label} 101 1.1 christos {data_member_location 4 data1} 102 1.1 christos } 103 1.1 christos } 104 1.1 christos 105 1.1 christos variant { 106 1.1 christos {discr_value 1 udata} 107 1.1 christos } { 108 1.1 christos member { 109 1.1 christos {type :$two_label} 110 1.1 christos {data_member_location 4 data1} 111 1.1 christos } 112 1.1 christos } 113 1.1 christos } 114 1.1 christos } 115 1.1 christos 116 1.1 christos structure_type { 117 1.1 christos {name Defaulted} 118 1.1 christos {byte_size 8 DW_FORM_sdata} 119 1.1 christos } { 120 1.1 christos variant_part { 121 1.1 christos {discr :$discr_2_label DW_FORM_ref4} 122 1.1 christos } { 123 1.1 christos discr_2_label: member { 124 1.1 christos {type :$uinteger_label} 125 1.1 christos {data_member_location 0 data1} 126 1.1 christos } 127 1.1 christos 128 1.1 christos variant { 129 1.1 christos } { 130 1.1 christos member { 131 1.1 christos {type :$one_label} 132 1.1 christos {data_member_location 4 data1} 133 1.1 christos } 134 1.1 christos } 135 1.1 christos 136 1.1 christos variant { 137 1.1 christos {discr_value 1 udata} 138 1.1 christos } { 139 1.1 christos member { 140 1.1 christos {type :$two_label} 141 1.1 christos {data_member_location 4 data1} 142 1.1 christos } 143 1.1 christos } 144 1.1 christos } 145 1.1 christos } 146 1.1 christos 147 1.1 christos structure_type { 148 1.1 christos {name Univariant} 149 1.1 christos {byte_size 8 DW_FORM_sdata} 150 1.1 christos } { 151 1.1 christos variant_part { 152 1.1 christos } { 153 1.1 christos variant { 154 1.1 christos } { 155 1.1 christos member { 156 1.1 christos {type :$one_label} 157 1.1 christos {data_member_location 4 data1} 158 1.1 christos } 159 1.1 christos } 160 1.1 christos } 161 1.1 christos } 162 1.1 christos 163 1.1 christos # Rust won't emit a negative discriminant like this, but 164 1.1 christos # we want to test the code path anyway. 165 1.1 christos structure_type { 166 1.1 christos {name Negative} 167 1.1 christos {byte_size 8 DW_FORM_sdata} 168 1.1 christos } { 169 1.1 christos variant_part { 170 1.1 christos {discr :$discr_3_label DW_FORM_ref4} 171 1.1 christos } { 172 1.1 christos discr_3_label: member { 173 1.1 christos {type :$int8_label} 174 1.1 christos {data_member_location 0 data1} 175 1.1 christos } 176 1.1 christos 177 1.1 christos variant { 178 1.1 christos {discr_value -1 sdata} 179 1.1 christos } { 180 1.1 christos member { 181 1.1 christos {type :$one_label} 182 1.1 christos {data_member_location 4 data1} 183 1.1 christos } 184 1.1 christos } 185 1.1 christos 186 1.1 christos # Make this the default value so we'll see an 187 1.1 christos # incorrect result if we mishandle signed 188 1.1 christos # discriminants. 189 1.1 christos variant { 190 1.1 christos } { 191 1.1 christos member { 192 1.1 christos {type :$two_label} 193 1.1 christos {data_member_location 4 data1} 194 1.1 christos } 195 1.1 christos } 196 1.1 christos } 197 1.1 christos } 198 1.1 christos } 199 1.1 christos } 200 1.1 christos } 201 1.1 christos 202 1.1 christos if { [prepare_for_testing "failed to prepare" ${testfile} \ 203 1.1 christos [list $srcfile $asm_file] debug] } { 204 1.1 christos return -1 205 1.1 christos } 206 1.1 christos 207 1.1 christos if ![runto func] { 208 1.1 christos return -1 209 1.1 christos } 210 1.1 christos 211 1.1 christos # Get the values into history so we can use it from Rust. 212 1.1 christos gdb_test "print (void *) buffer" "\\\$1 = .void .. $hex .buffer." 213 1.1 christos gdb_test "print (void *) buffer2" "\\\$2 = .void .. $hex .buffer2." 214 1.1 christos 215 1.1 christos gdb_test "set language rust" 216 1.1 christos gdb_test "print *(\$1 as *mut Simple)" " = One\\(23\\)" \ 217 1.1 christos "print as Simple" 218 1.1 christos gdb_test "print *(\$1 as *mut Defaulted)" " = One\\(23\\)" \ 219 1.1 christos "print as Defaulted" 220 1.1 christos gdb_test "print *(\$1 as *mut Univariant)" " = One\\(23\\)" \ 221 1.1 christos "print as Univariant" 222 1.1 christos 223 1.1 christos gdb_test "print *(\$2 as *mut Negative)" " = One\\(23\\)" \ 224 1.1 christos "print as Negative" 225