1 1.1.1.3 christos # Copyright 2019-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 16 1.1 christos # Checks for a bug where a baddly formed ELF would cause GDB to crash. 17 1.1 christos # A section containing executable code, for which there was DWARF is 18 1.1 christos # accidentally marked as non-alloctable, GDB becomes unhappy. 19 1.1 christos # 20 1.1 christos # This test creates some fake DWARF pointing at some symbols in a 21 1.1 christos # non-allocatable section that is still marked as executable. We then 22 1.1 christos # start GDB and try to place a breakpoint on the symbol in the 23 1.1 christos # non-allocatable section. 24 1.1 christos # 25 1.1 christos # It is not expected that the final debug experience really makes 26 1.1 christos # sense, the symbol is in a non-allocatable section after all, but GDB 27 1.1 christos # absolutely shouldn't crash. All we try to do after placing the 28 1.1 christos # breakpoint is check that GDB is still alive. 29 1.1 christos 30 1.1 christos load_lib dwarf.exp 31 1.1 christos 32 1.1 christos # This test can only be run on targets which support DWARF-2 and use gas. 33 1.1.1.3 christos require dwarf2_support 34 1.1 christos 35 1.1.1.2 christos standard_testfile main.c -other.S -dwarf.S 36 1.1.1.2 christos 37 1.1.1.2 christos if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] } { 38 1.1.1.2 christos untested "failed to compile" 39 1.1.1.2 christos return -1 40 1.1.1.2 christos } 41 1.1.1.2 christos 42 1.1.1.2 christos set int_size [get_sizeof "int" 4] 43 1.1 christos 44 1.1 christos # Make some DWARF for the test. 45 1.1 christos set asm_file [standard_output_file $srcfile3] 46 1.1 christos Dwarf::assemble $asm_file { 47 1.1.1.2 christos global srcdir subdir srcfile srcfile2 int_size 48 1.1 christos 49 1.1 christos declare_labels ranges_label_1 ranges_label_2 L1 L2 50 1.1 christos 51 1.1 christos set main_result [function_range main ${srcdir}/${subdir}/${srcfile}] 52 1.1 christos set main_start [lindex $main_result 0] 53 1.1 christos set main_length [lindex $main_result 1] 54 1.1 christos 55 1.1 christos cu {} { 56 1.1 christos DW_TAG_compile_unit { 57 1.1 christos {DW_AT_language @DW_LANG_C} 58 1.1.1.2 christos {DW_AT_name $srcfile} 59 1.1 christos {DW_AT_comp_dir ${srcdir}/${subdir}} 60 1.1 christos {stmt_list $L1 DW_FORM_sec_offset} 61 1.1 christos {ranges ${ranges_label_1} DW_FORM_sec_offset} 62 1.1 christos {DW_AT_low_pc 0 addr} 63 1.1 christos } { 64 1.1 christos declare_labels integer_label 65 1.1 christos 66 1.1 christos DW_TAG_subprogram { 67 1.1 christos {name main} 68 1.1 christos {low_pc $main_start addr} 69 1.1 christos {high_pc $main_length data8} 70 1.1 christos {DW_AT_type :$integer_label} 71 1.1 christos {DW_AT_decl_file 1 data1} 72 1.1 christos {DW_AT_decl_line 10 data1} 73 1.1 christos } 74 1.1 christos 75 1.1 christos integer_label: DW_TAG_base_type { 76 1.1 christos {DW_AT_byte_size $int_size DW_FORM_sdata} 77 1.1 christos {DW_AT_encoding @DW_ATE_signed} 78 1.1 christos {DW_AT_name integer} 79 1.1 christos } 80 1.1 christos } 81 1.1 christos } 82 1.1 christos 83 1.1 christos cu {} { 84 1.1 christos DW_TAG_compile_unit { 85 1.1 christos {DW_AT_language @DW_LANG_C} 86 1.1.1.2 christos {DW_AT_name $srcfile2} 87 1.1 christos {DW_AT_comp_dir ${srcdir}/${subdir}} 88 1.1 christos {stmt_list $L2 DW_FORM_sec_offset} 89 1.1 christos {ranges ${ranges_label_2} DW_FORM_sec_offset} 90 1.1 christos {DW_AT_low_pc 0 addr} 91 1.1 christos } { 92 1.1 christos declare_labels integer_label 93 1.1 christos 94 1.1 christos DW_TAG_subprogram { 95 1.1 christos {name some_func} 96 1.1 christos {low_pc some_func addr} 97 1.1 christos {high_pc some_func_end addr} 98 1.1 christos {DW_AT_type :$integer_label} 99 1.1 christos {DW_AT_decl_file 2 data1} 100 1.1 christos {DW_AT_decl_line 5 data1} 101 1.1 christos } 102 1.1 christos 103 1.1 christos integer_label: DW_TAG_base_type { 104 1.1 christos {DW_AT_byte_size $int_size DW_FORM_sdata} 105 1.1 christos {DW_AT_encoding @DW_ATE_signed} 106 1.1 christos {DW_AT_name integer} 107 1.1 christos } 108 1.1 christos } 109 1.1 christos } 110 1.1 christos 111 1.1 christos ranges {is_64 [is_64_target]} { 112 1.1 christos ranges_label_1: sequence { 113 1.1.1.2 christos base [lindex $main_result 0] 114 1.1.1.2 christos range 0 [lindex $main_result 1] 115 1.1 christos } 116 1.1 christos ranges_label_2: sequence { 117 1.1.1.2 christos base some_func 118 1.1.1.2 christos range 0 64 119 1.1 christos } 120 1.1 christos } 121 1.1 christos 122 1.1 christos lines {version 2} L1 { 123 1.1 christos include_dir "${srcdir}/${subdir}" 124 1.1 christos file_name "$srcfile" 1 125 1.1 christos 126 1.1.1.4 christos # Line data doesn't need to be correct, just present. 127 1.1 christos program { 128 1.1.1.2 christos DW_LNE_set_address [lindex $main_result 0] 129 1.1.1.2 christos DW_LNS_advance_line 10 130 1.1.1.2 christos DW_LNS_copy 131 1.1.1.3 christos 132 1.1.1.2 christos DW_LNS_advance_pc [lindex $main_result 1] 133 1.1.1.2 christos DW_LNS_advance_line 19 134 1.1.1.2 christos DW_LNS_copy 135 1.1.1.3 christos 136 1.1.1.3 christos DW_LNS_advance_pc 0 137 1.1.1.2 christos DW_LNE_end_sequence 138 1.1 christos } 139 1.1 christos } 140 1.1 christos 141 1.1 christos lines {version 2} L2 { 142 1.1 christos include_dir "${srcdir}/${subdir}" 143 1.1 christos file_name "dw2-bad-elf-other.c" 1 144 1.1 christos 145 1.1.1.4 christos # Line data doesn't need to be correct, just present. 146 1.1 christos program { 147 1.1.1.2 christos DW_LNE_set_address some_func 148 1.1.1.2 christos DW_LNS_advance_line 5 149 1.1.1.2 christos DW_LNS_copy 150 1.1.1.3 christos 151 1.1.1.2 christos DW_LNS_advance_pc 64 152 1.1.1.2 christos DW_LNS_advance_line 8 153 1.1.1.2 christos DW_LNS_copy 154 1.1.1.3 christos 155 1.1.1.3 christos DW_LNS_advance_pc 0 156 1.1.1.2 christos DW_LNE_end_sequence 157 1.1 christos } 158 1.1 christos } 159 1.1 christos } 160 1.1 christos 161 1.1 christos if { [build_executable ${testfile}.exp ${testfile} \ 162 1.1 christos [list $srcfile $srcfile2 $asm_file] {nodebug}] } { 163 1.1 christos return -1 164 1.1 christos } 165 1.1 christos 166 1.1 christos # Attempt to place a breakpoint on 'some_func', then check GDB is 167 1.1 christos # still alive. This test can optionally set a breakpoint on 'main' 168 1.1 christos # first (based on GOTO_MAIN), the original bug behaved differently 169 1.1 christos # when there was already a breakpoint set. 170 1.1 christos proc run_test { goto_main } { 171 1.1 christos global binfile decimal hex 172 1.1 christos 173 1.1 christos clean_restart ${binfile} 174 1.1 christos 175 1.1 christos if { $goto_main } { 176 1.1 christos if ![runto_main] { 177 1.1 christos return -1 178 1.1 christos } 179 1.1 christos } 180 1.1 christos 181 1.1 christos # Place a breakpoint. 182 1.1 christos gdb_test "break some_func" \ 183 1.1 christos "Breakpoint $decimal at $hex: file .*dw2-bad-elf-other\\.c, line 6\\." 184 1.1 christos 185 1.1 christos # Check GDB is still alive. 186 1.1 christos gdb_test "echo hello\\n" "hello" 187 1.1 christos } 188 1.1 christos 189 1.1 christos # Run the tests. 190 1.1 christos foreach_with_prefix goto_main { 0 1 } { 191 1.1 christos run_test $goto_main 192 1.1 christos } 193