1 # Copyright 2023-2024 Free Software Foundation, Inc. 2 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. 7 # 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. 12 # 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/>. 15 16 load_lib dwarf.exp 17 18 # This test can only be run on targets which support DWARF-2 and use gas. 19 require dwarf2_support 20 21 standard_testfile main.c -dw.S 22 23 # Make some DWARF for the test. 24 set asm_file [standard_output_file $srcfile2] 25 Dwarf::assemble $asm_file { 26 upvar cu_lang cu_lang 27 28 declare_labels uinteger_label discr_1_label 29 declare_labels one_label two_label simple_label 30 31 cu { addr_size 4 } { 32 compile_unit { 33 {name file1.txt} 34 {language @DW_LANG_Rust} 35 } { 36 uinteger_label: DW_TAG_base_type { 37 {DW_AT_byte_size 1 DW_FORM_sdata} 38 {DW_AT_encoding @DW_ATE_unsigned} 39 {DW_AT_name {unsigned integer}} 40 } 41 42 one_label: structure_type { 43 {name One} 44 {byte_size 1 DW_FORM_sdata} 45 } { 46 member { 47 {name __0} 48 {type :$uinteger_label} 49 {data_member_location 0 data1} 50 } 51 } 52 53 two_label: structure_type { 54 {name Two} 55 {byte_size 1 DW_FORM_sdata} 56 } { 57 member { 58 {name __0} 59 {type :$uinteger_label} 60 {data_member_location 0 data1} 61 } 62 } 63 64 simple_label: structure_type { 65 {name Simple} 66 {byte_size 2 DW_FORM_sdata} 67 } { 68 variant_part { 69 {discr :$discr_1_label DW_FORM_ref4} 70 } { 71 discr_1_label: member { 72 {type :$uinteger_label} 73 {data_member_location 0 data1} 74 {artificial 1 DW_FORM_flag_present} 75 } 76 77 variant { 78 {discr_value 65 udata} 79 } { 80 member { 81 {type :$one_label} 82 {data_member_location 1 data1} 83 } 84 } 85 86 variant { 87 } { 88 member { 89 {type :$two_label} 90 {data_member_location 1 data1} 91 } 92 } 93 } 94 } 95 96 # In PR rust/31005, a constant Rust enum value could not 97 # be correctly resolved. 98 DW_TAG_variable { 99 {name constant_variable} 100 {const_value 0x4141 udata} 101 {type :$simple_label} 102 } 103 DW_TAG_variable { 104 {name constant_variable2} 105 {const_value "AA" DW_FORM_block1} 106 {type :$simple_label} 107 } 108 } 109 } 110 } 111 112 if { [prepare_for_testing "failed to prepare" ${testfile} \ 113 [list $srcfile $asm_file] {nodebug}] } { 114 return -1 115 } 116 117 gdb_test_no_output "set language rust" 118 119 gdb_test "print constant_variable" [string_to_regexp "One(65)"] 120 gdb_test "print constant_variable2" [string_to_regexp "One(65)"] 121