1# Copyright 2014-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# Tests to cover DW_AT_count attribute in subranges. 17 18load_lib dwarf.exp 19 20# Only run on targets which support dwarf and gas. 21require dwarf2_support 22 23standard_testfile main.c .S 24 25set asm_file [standard_output_file $srcfile2] 26Dwarf::assemble $asm_file { 27 cu {} { 28 compile_unit {{language @DW_LANG_C99}} { 29 declare_labels char_label \ 30 array_size_type_label long_unsigned_int_label \ 31 array_label array_label2 static_array_label \ 32 vla_length_label vla_array_label 33 34 char_label: base_type { 35 {name char} 36 {encoding @DW_ATE_signed} 37 {byte_size 1 DW_FORM_sdata} 38 } 39 40 array_size_type_label: base_type { 41 {byte_size 8 DW_FORM_sdata} 42 {encoding @DW_ATE_unsigned} 43 {name __ARRAY_SIZE_TYPE__} 44 } 45 46 long_unsigned_int_label: base_type { 47 {byte_size 8 DW_FORM_sdata} 48 {encoding @DW_ATE_unsigned} 49 {name "long unsigned int"} 50 } 51 52 array_label: array_type { 53 {type :$char_label} 54 } { 55 subrange_type { 56 {count {DW_OP_lit5} SPECIAL_expr} 57 {type :$char_label} 58 } 59 } 60 61 array_label2: array_type { 62 {type :$char_label} 63 } { 64 subrange_type { 65 {count {DW_OP_lit1} SPECIAL_expr} 66 {type :$char_label} 67 } 68 } 69 70 static_array_label: array_type { 71 {type :$char_label} 72 } { 73 subrange_type { 74 {count 5 DW_FORM_sdata} 75 {type :$char_label} 76 } 77 } 78 79 vla_length_label: 80 DW_TAG_variable { 81 {location 82 { 83 lit6 84 stack_value 85 } SPECIAL_expr} 86 {name "__vla_array_length"} 87 {type :$long_unsigned_int_label} 88 {artificial 1 DW_FORM_flag_present} 89 } 90 91 vla_array_label: array_type { 92 {type :$char_label} 93 } { 94 subrange_type { 95 {type :$array_size_type_label} 96 {count :$vla_length_label} 97 } 98 } 99 100 DW_TAG_variable { 101 {name array2} 102 {type :$array_label2} 103 {const_value 65 DW_FORM_udata} 104 } 105 106 DW_TAG_variable { 107 {name array} 108 {type :$array_label} 109 {const_value hello DW_FORM_block1} 110 } 111 112 DW_TAG_variable { 113 {name static_array} 114 {type :$static_array_label} 115 {const_value world DW_FORM_block1} 116 } 117 118 DW_TAG_variable { 119 {name vla_array} 120 {type :$vla_array_label} 121 {const_value saluton DW_FORM_block1} 122 } 123 } 124 } 125} 126 127if { [gdb_compile ${srcdir}/${subdir}/${srcfile} ${binfile}1.o \ 128 object {nodebug}] != "" } { 129 return -1 130} 131 132if { [gdb_compile $asm_file ${binfile}2.o object {nodebug}] != "" } { 133 return -1 134} 135 136if { [gdb_compile [list ${binfile}1.o ${binfile}2.o] \ 137 "${binfile}" executable {}] != "" } { 138 return -1 139} 140 141save_vars { GDBFLAGS } { 142 set GDBFLAGS [concat $GDBFLAGS " -readnow"] 143 clean_restart ${testfile} 144} 145 146if ![runto_main] { 147 return -1 148} 149 150gdb_test "ptype array" "type = char \\\[5\\\]" 151gdb_test "whatis array" "type = char \\\[5\\\]" 152gdb_test "print array" " = \"hello\"" 153gdb_test "print sizeof array" " = 5" 154 155gdb_test "ptype array2" "type = char \\\[1\\\]" 156gdb_test "whatis array2" "type = char \\\[1\\\]" 157gdb_test "print array2" " = \"A\"" 158gdb_test "print sizeof array2" " = 1" 159 160gdb_test "ptype static_array" "type = char \\\[5\\\]" 161gdb_test "whatis static_array" "type = char \\\[5\\\]" 162gdb_test "print static_array" " = \"world\"" 163gdb_test "print sizeof static_array" " = 5" 164 165gdb_test "ptype vla_array" "type = char \\\[6\\\]" 166gdb_test "whatis vla_array" "type = char \\\[6\\\]" 167gdb_test "print vla_array" " = \"saluto\"" 168gdb_test "print sizeof vla_array" " = 6" 169