1# Copyright 2015-2023 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/>. 15load_lib dwarf.exp 16 17# Test DW_TAG_compile_unit with no children and with neither DW_AT_low_pc nor 18# DW_AT_high_pc but with DW_AT_ranges instead. 19 20# This test can only be run on targets which support DWARF-2 and use gas. 21if {![dwarf2_support]} { 22 verbose "Skipping $gdb_test_file_name." 23 return 0 24} 25 26# The .c files use __attribute__. 27if ![is_c_compiler_gcc] { 28 verbose "Skipping $gdb_test_file_name." 29 return 0 30} 31 32standard_testfile .c -dw.S 33 34set asm_file [standard_output_file $srcfile2] 35Dwarf::assemble $asm_file { 36 global srcdir subdir srcfile srcfile2 37 declare_labels ranges_label 38 declare_labels L 39 40 # Find start address and length for our functions. 41 set main_func \ 42 [function_range main [list ${srcdir}/${subdir}/$srcfile]] 43 set frame2_func \ 44 [function_range frame2 [list ${srcdir}/${subdir}/$srcfile]] 45 set frame3_func \ 46 [function_range frame3 [list ${srcdir}/${subdir}/$srcfile]] 47 48 # Very simple info for this test program. We don't care about 49 # this information being correct (w.r.t. funtion / argument types) 50 # just so long as the compilation using makes use of the 51 # .debug_ranges data then the test achieves its objective. 52 cu { label cu_label } { 53 compile_unit { 54 {language @DW_LANG_C} 55 {name dw-ranges-base.c} 56 {stmt_list $L DW_FORM_sec_offset} 57 {ranges ${ranges_label} DW_FORM_sec_offset} 58 } { 59 subprogram { 60 {external 1 flag} 61 {name main} 62 } 63 subprogram { 64 {external 1 flag} 65 {name frame2} 66 } 67 subprogram { 68 {external 1 flag} 69 {name frame3} 70 } 71 } 72 } 73 74 lines {version 2} L { 75 include_dir "${srcdir}/${subdir}" 76 file_name "$srcfile" 1 77 78 # Generate simple line table program. The line table 79 # information contained here is not correct, and we really 80 # don't care, just so long as each function has some line 81 # table data associated with it. We do make use of the fake 82 # line numbers that we pick here in the tests below. 83 program { 84 DW_LNE_set_address [lindex $main_func 0] 85 DW_LNS_advance_line 10 86 DW_LNS_copy 87 DW_LNS_advance_pc [lindex $main_func 1] 88 DW_LNS_advance_line 19 89 DW_LNS_copy 90 DW_LNE_end_sequence 91 92 DW_LNE_set_address [lindex $frame2_func 0] 93 DW_LNS_advance_line 20 94 DW_LNS_copy 95 DW_LNS_advance_pc [lindex $frame2_func 1] 96 DW_LNS_advance_line 29 97 DW_LNS_copy 98 DW_LNE_end_sequence 99 100 DW_LNE_set_address [lindex $frame3_func 0] 101 DW_LNS_advance_line 30 102 DW_LNS_copy 103 DW_LNS_advance_pc [lindex $frame3_func 1] 104 DW_LNS_advance_line 39 105 DW_LNS_copy 106 DW_LNE_end_sequence 107 } 108 } 109 110 # Generate ranges data. This is the point of this whole test 111 # file, we must have multiple bases specified, so we use a new 112 # base for each function. 113 ranges {is_64 [is_64_target]} { 114 ranges_label: sequence { 115 base [lindex $main_func 0] 116 range 0 [lindex $main_func 1] 117 base [lindex $frame2_func 0] 118 range 0 [lindex $frame2_func 1] 119 base [lindex $frame3_func 0] 120 range 0 [lindex $frame3_func 1] 121 } 122 } 123 124 aranges {} cu_label { 125 arange {} [lindex $main_func 0] [lindex $main_func 1] 126 arange {} [lindex $frame2_func 0] [lindex $frame2_func 1] 127 arange {} [lindex $frame3_func 0] [lindex $frame3_func 1] 128 } 129} 130 131if { [prepare_for_testing "failed to prepare" ${testfile} \ 132 [list $srcfile $asm_file] {nodebug}] } { 133 return -1 134} 135 136if ![runto_main] { 137 return -1 138} 139 140# Make use of the line numbers we faked in the .debug_line table above. 141gdb_test "info line main" \ 142 "Line 11 of .* starts at address .* and ends at .*" 143gdb_test "info line frame2" \ 144 "Line 21 of .* starts at address .* and ends at .*" 145gdb_test "info line frame3" \ 146 "Line 31 of .* starts at address .* and ends at .*" 147 148# Ensure that the line table correctly tracks the end of sequence markers. 149set end_seq_count 0 150set prev -1 151set seq_count 0 152gdb_test_multiple "maint info line-table gdb.dwarf2/dw2-ranges-base.c" \ 153 "count END markers in line table" { 154 -re "^$decimal\[ \t\]+$decimal\[ \t\]+$hex\(\[ \t\]+Y\)? *\r\n" { 155 if { $prev != -1 } { 156 gdb_assert "$prev == 1" \ 157 "prev of normal entry at $seq_count is end marker" 158 } 159 set prev 0 160 incr seq_count 161 exp_continue 162 } 163 -re "^$decimal\[ \t\]+END\[ \t\]+$hex\(\[ \t\]+Y\)? *\r\n" { 164 if { $prev != -1 } { 165 gdb_assert "$prev == 0" \ 166 "prev of end marker at $seq_count is normal entry" 167 } 168 set prev 1 169 incr seq_count 170 incr end_seq_count 171 exp_continue 172 } 173 -re "^\r\n" { 174 # Empty lines between tables. 175 exp_continue 176 } 177 -re "^$gdb_prompt $" { 178 gdb_assert [expr $end_seq_count == 3] $gdb_test_name 179 } 180 -re ".*linetable: \\(\\(struct linetable \\*\\) 0x0\\):\r\nNo line table.\r\n" { 181 exp_continue 182 } 183 -re ".*linetable: \\(\\(struct linetable \\*\\) $hex\\):\r\nINDEX\[ \t\]+LINE\[ \t\]+ADDRESS\[ \t\]+IS-STMT\[ \t\]PROLOGUE-END *\r\n" { 184 exp_continue 185 } 186 } 187