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