1 # Copyright 2022-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 load_lib dwarf.exp 16 17 # This test can only be run on targets which support DWARF-2 and use gas. 18 require dwarf2_support 19 20 standard_testfile .c -dw.S 21 22 # We need to know the size of integer and address types in order 23 # to write some of the debugging info we'd like to generate. 24 # 25 # For that, we ask GDB by debugging our dynarr-ptr.c program. 26 # Any program would do, but since we already have dynarr-ptr.c 27 # specifically for this testcase, might as well use that. 28 29 if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } { 30 return -1 31 } 32 33 # Make some DWARF for the test. 34 set asm_file [standard_output_file $srcfile2] 35 Dwarf::assemble $asm_file { 36 set int_size [get_sizeof "int" 4] 37 38 get_func_info main 39 get_func_info main_helper 40 41 cu {} { 42 DW_TAG_compile_unit { 43 {DW_AT_language @DW_LANG_Fortran90} 44 {DW_AT_name fortran-var-string.f90} 45 {DW_AT_comp_dir /tmp} 46 } { 47 declare_labels integer_label string_label array_lb_label \ 48 array_ub_label 49 50 DW_TAG_subprogram { 51 {name main} 52 {low_pc $main_helper_start addr} 53 {high_pc $main_helper_len data8} 54 {DW_AT_type :$integer_label} 55 {DW_AT_decl_file 1 data1} 56 {DW_AT_decl_line 1 data1} 57 } 58 59 DW_TAG_subprogram { 60 {name test_1_func} 61 {low_pc $main_start addr} 62 {high_pc $main_len data8} 63 {DW_AT_type :$integer_label} 64 {DW_AT_decl_file 1 data1} 65 {DW_AT_decl_line 2 data1} 66 } { 67 formal_parameter { 68 {name arg1} 69 {type :$string_label} 70 } 71 } 72 73 DW_TAG_subprogram { 74 {name test_2_func} 75 {low_pc $main_start addr} 76 {high_pc $main_len data8} 77 {DW_AT_type :$integer_label} 78 {DW_AT_decl_file 1 data1} 79 {DW_AT_decl_line 3 data1} 80 } { 81 formal_parameter { 82 {name arg1} 83 {type :$array_ub_label} 84 } 85 } 86 87 DW_TAG_subprogram { 88 {name test_3_func} 89 {low_pc $main_start addr} 90 {high_pc $main_len data8} 91 {DW_AT_type :$integer_label} 92 {DW_AT_decl_file 1 data1} 93 {DW_AT_decl_line 4 data1} 94 } { 95 formal_parameter { 96 {name arg1} 97 {type :$array_lb_label} 98 } 99 } 100 101 integer_label: DW_TAG_base_type { 102 {DW_AT_byte_size $int_size DW_FORM_sdata} 103 {DW_AT_encoding @DW_ATE_signed} 104 {DW_AT_name integer} 105 } 106 107 string_label: DW_TAG_string_type { 108 {DW_AT_byte_size $int_size DW_FORM_sdata} 109 {DW_AT_name .str.arg} 110 {DW_AT_string_length {} DW_FORM_block1} 111 } 112 113 array_lb_label: DW_TAG_array_type { 114 {DW_AT_ordering 1 data1} 115 {DW_AT_type :$integer_label} 116 } { 117 DW_TAG_subrange_type { 118 {DW_AT_lower_bound {} DW_FORM_block1} 119 {DW_AT_upper_bound 10 DW_FORM_data1} 120 } 121 } 122 123 array_ub_label: DW_TAG_array_type { 124 {DW_AT_ordering 1 data1} 125 {DW_AT_type :$integer_label} 126 } { 127 DW_TAG_subrange_type { 128 {DW_AT_upper_bound {} DW_FORM_block1} 129 } 130 } 131 } 132 } 133 } 134 135 # Now that we've generated the DWARF debugging info, rebuild our 136 # program using our debug info instead of the info generated by 137 # the compiler. 138 139 if { [prepare_for_testing "failed to prepare" ${testfile} \ 140 [list $srcfile $asm_file] {nodebug}] } { 141 return -1 142 } 143 144 if ![runto_main] { 145 return -1 146 } 147 148 gdb_test_no_output "set language fortran" 149 150 gdb_test "info functions test_1_func" \ 151 "2:\\s+integer test_1_func\\(character\\*\\(\\*\\)\\);" 152 153 # We print `1` here as the bound because GDB treats this as an assumed 154 # size array, and just reports the lower bound value for the upper 155 # bound. 156 # 157 # We might, in the future, decide that there's a better way we could 158 # tell the user about the type of this array argument, when that 159 # happens it's OK to change the expected results here. 160 gdb_test "info functions test_2_func" \ 161 "3:\\s+integer test_2_func\\(integer \\(1\\)\\);" 162 163 # It's not completely clear that this error is correct here. Why 164 # can't the lower bound be a dynamic expression? 165 # 166 # This test was initially added to guard against the case where GDB 167 # was crashing if/when it saw this situation. 168 # 169 # If later on, GDB's handling of array types with a dynamic loewr 170 # bound changes, then it is possible that the expected result here 171 # should change. 172 gdb_test "info functions test_3_func" \ 173 "4:\\s+Lower bound may not be '\\*' in F77" 174