1 # Copyright 2021-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 # Check that the ".debug_ranges entry has start address of zero" complaint 17 # is triggered for a loaded shared lib. 18 19 load_lib dwarf.exp 20 21 # This test can only be run on targets which support DWARF-2 and use gas. 22 require dwarf2_support allow_shlib_tests 23 24 standard_testfile .c -shlib.c -dw.S 25 26 # Test for presence of complaint, with the lib relocated. 27 28 proc_with_prefix test_relocated { exec_path lib_path complaint_re readnow_p } { 29 clean_restart $exec_path 30 gdb_load_shlib $lib_path 31 32 if { ![runto_main] } { 33 return 34 } 35 36 gdb_test_no_output "nosharedlibrary" 37 38 # Test for presence of complaint. 39 with_complaints 1 { 40 set have_complaint 0 41 gdb_test_multiple "maint with dwarf synchronous on -- sharedlibrary [file tail $lib_path]" "load shared library" { 42 -re -wrap $complaint_re { 43 set have_complaint 1 44 } 45 -re -wrap "" { 46 } 47 } 48 49 # The complaint won't be seen if an index is in use. 50 if {[have_index $lib_path] == ""} { 51 gdb_assert { $have_complaint } "complaint" 52 } 53 54 if { ! $readnow_p } { 55 gdb_test "maint expand-symtabs $::srcfile2" $complaint_re \ 56 "complaint when expanding symtab" 57 } 58 } 59 } 60 61 # Test for presence of complaint, with the lib unrelocated. 62 63 proc_with_prefix test_unrelocated { exec_path lib_path complaint_re readnow_p } { 64 clean_restart 65 gdb_test_no_output "maint set dwarf synchronous on" 66 67 with_complaints 1 { 68 gdb_load $lib_path 69 set have_complaint [regexp $complaint_re.* $::gdb_file_cmd_msg] 70 71 # The complaint won't be seen if an index is in use. 72 if {[have_index $lib_path] == ""} { 73 gdb_assert { $have_complaint } "complaint" 74 } 75 76 gdb_test_no_output "maint set dwarf synchronous off" 77 78 if { ! $readnow_p } { 79 gdb_test "maint expand-symtabs $::srcfile2" $complaint_re \ 80 "complaint when expanding symtab" 81 } 82 } 83 } 84 85 # Test with both a .debug_ranges section (DWARF 4) and a .debug_rnglists 86 # section (DWARF 5). 87 88 foreach_with_prefix ranges_sect {ranges rnglists} { 89 set asm_file [standard_output_file ${ranges_sect}-$srcfile3] 90 91 if { $ranges_sect == "ranges" } { 92 Dwarf::assemble $asm_file { 93 global srcdir subdir srcfile2 94 declare_labels ranges_label 95 96 cu {} { 97 compile_unit { 98 {language @DW_LANG_C} 99 {name $srcfile2} 100 {ranges ${ranges_label} DW_FORM_sec_offset} 101 } { 102 subprogram { 103 {external 1 flag} 104 {name foo} 105 } 106 } 107 } 108 109 ranges {is_64 [is_64_target]} { 110 ranges_label: sequence { 111 base 0 112 range 0 1 113 } 114 } 115 } 116 } elseif { $ranges_sect == "rnglists" } { 117 Dwarf::assemble $asm_file { 118 global srcdir subdir srcfile2 119 declare_labels rnglists_label 120 121 cu { 122 version 5 123 } { 124 compile_unit { 125 {language @DW_LANG_C} 126 {name $srcfile2} 127 {ranges ${rnglists_label} DW_FORM_sec_offset} 128 } { 129 subprogram { 130 {external 1 flag} 131 {name foo} 132 } 133 } 134 } 135 136 rnglists {} { 137 table {} { 138 rnglists_label: list_ { 139 start_end 0 1 140 } 141 } 142 } 143 } 144 } else { 145 error "invalid ranges section kind" 146 } 147 148 set lib_path [standard_output_file shr1-${ranges_sect}.sl] 149 set lib_sources [list ${srcdir}/${subdir}/$srcfile2 $asm_file] 150 if { [gdb_compile_shlib $lib_sources $lib_path {nodebug}] != "" } { 151 untested "failed to compile" 152 return 153 } 154 155 set exec_sources ${srcdir}/${subdir}/${srcfile} 156 set exec_path ${binfile}-${ranges_sect} 157 set exec_opts [list debug shlib=${lib_path}] 158 if { [gdb_compile $exec_sources $exec_path executable $exec_opts] != ""} { 159 untested "failed to compile" 160 return 161 } 162 163 set complaint_re ".debug_${ranges_sect} entry has start address of zero" 164 set complaint_re \ 165 "During symbol reading: $complaint_re \\\[in module \[^\r\n\]*\\\]" 166 167 set readnow_p [readnow] 168 169 test_relocated $exec_path $lib_path $complaint_re $readnow_p 170 test_unrelocated $exec_path $lib_path $complaint_re $readnow_p 171 } 172