1 # Copyright 2020-2025 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 # Test DW_AT_ranges attributes referencing the .debug_rnglists section using the 17 # DW_FORM_sec_offset form. 18 19 load_lib dwarf.exp 20 21 require dwarf2_support 22 23 foreach_with_prefix is_64 {false true} { 24 if { $is_64 } { 25 standard_testfile main.c -dw64.S 26 set testfile ${testfile}-dw64 27 } else { 28 standard_testfile main.c -dw32.S 29 set testfile ${testfile}-dw32 30 } 31 32 set asm_file [standard_output_file $srcfile2] 33 Dwarf::assemble $asm_file { 34 global is_64 35 36 declare_labels cu1_range_list cu2_range_list cu3_range_list 37 declare_labels foo_range_list bar_range_list baz_range_list 38 39 # This CU uses the DW_FORM_sec_offset form to refer to the .debug_rnglists 40 # section. 41 cu { 42 version 5 43 is_64 $is_64 44 } { 45 DW_TAG_compile_unit { 46 {DW_AT_ranges $cu1_range_list DW_FORM_sec_offset} 47 } { 48 DW_TAG_subprogram { 49 {DW_AT_name "foo"} 50 {DW_AT_ranges $foo_range_list DW_FORM_sec_offset} 51 } 52 } 53 } 54 55 # This CU uses the DW_FORM_sec_offset form to refer to the 56 # .debug_rnglists section, but also has the DW_AT_rnglists_base 57 # attribute present. The DW_AT_rnglists_base attribute is not used to 58 # interpret the DW_AT_ranges value, but it should also do no harm. 59 cu { 60 version 5 61 is_64 $is_64 62 } { 63 DW_TAG_compile_unit { 64 {DW_AT_ranges $cu2_range_list DW_FORM_sec_offset} 65 {DW_AT_rnglists_base cu2_table DW_FORM_sec_offset} 66 } { 67 DW_TAG_subprogram { 68 {DW_AT_name "bar"} 69 {DW_AT_ranges $bar_range_list DW_FORM_sec_offset} 70 } 71 } 72 } 73 74 # This CU uses the DW_FORM_sec_offset form to refer to the .debug_rnglists 75 # section. The corresponding contribution in the .debug_rnglists has no 76 # offset array. 77 cu { 78 version 5 79 is_64 $is_64 80 } { 81 DW_TAG_compile_unit { 82 {DW_AT_ranges $cu3_range_list DW_FORM_sec_offset} 83 } { 84 DW_TAG_subprogram { 85 {DW_AT_name "baz"} 86 {DW_AT_ranges $baz_range_list DW_FORM_sec_offset} 87 } 88 } 89 } 90 91 rnglists {is-64 $is_64} { 92 # The lists in this table are accessed by direct offset 93 # (DW_FORM_sec_offset). 94 table {} { 95 # For the first CU. 96 cu1_range_list: list_ { 97 start_end 0x4000 0x5000 98 } 99 100 # For function foo. 101 foo_range_list: list_ { 102 start_end 0x4000 0x4010 103 } 104 } 105 106 table {post-header-label cu2_table} { 107 # For the second CU. 108 cu2_range_list: list_ { 109 start_end 0x5000 0x6000 110 } 111 112 # For the bar function. 113 bar_range_list: list_ { 114 start_end 0x5000 0x5010 115 } 116 } 117 118 table {with-offset-array false} { 119 # For the third CU. 120 cu3_range_list: list_ { 121 start_end 0x6000 0x7000 122 } 123 124 # For the baz function. 125 baz_range_list: list_ { 126 start_end 0x6000 0x6010 127 } 128 } 129 } 130 } 131 132 if { [prepare_for_testing "failed to prepare" ${testfile} \ 133 [list $srcfile $asm_file] {nodebug}] } { 134 return -1 135 } 136 137 # Sanity checks to make sure GDB slurped the symbols correctly. 138 gdb_test "p/x &foo" " = 0x4000" 139 gdb_test "p/x &bar" " = 0x5000" 140 gdb_test "p/x &baz" " = 0x6000" 141 } 142