1 # Copyright 2019-2021 Free Software Foundation, Inc.
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.
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.
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/>.
16 # Checks for a bug where a baddly formed ELF would cause GDB to crash.
17 # A section containing executable code, for which there was DWARF is
18 # accidentally marked as non-alloctable, GDB becomes unhappy.
20 # This test creates some fake DWARF pointing at some symbols in a
21 # non-allocatable section that is still marked as executable. We then
22 # start GDB and try to place a breakpoint on the symbol in the
23 # non-allocatable section.
25 # It is not expected that the final debug experience really makes
26 # sense, the symbol is in a non-allocatable section after all, but GDB
27 # absolutely shouldn't crash. All we try to do after placing the
28 # breakpoint is check that GDB is still alive.
32 # This test can only be run on targets which support DWARF-2 and use gas.
33 if {![dwarf2_support]} {
37 standard_testfile main.c -other.S -dwarf.S
39 # Make some DWARF for the test.
40 set asm_file [standard_output_file $srcfile3]
41 Dwarf::assemble $asm_file {
42 global srcdir subdir srcfile srcfile2
44 declare_labels ranges_label_1 ranges_label_2 L1 L2
46 set main_result [function_range main ${srcdir}/${subdir}/${srcfile}]
47 set main_start [lindex $main_result 0]
48 set main_length [lindex $main_result 1]
50 set int_size [get_sizeof "int" 4]
54 {DW_AT_language @DW_LANG_C}
56 {DW_AT_comp_dir ${srcdir}/${subdir}}
57 {stmt_list $L1 DW_FORM_sec_offset}
58 {ranges ${ranges_label_1} DW_FORM_sec_offset}
61 declare_labels integer_label
65 {low_pc $main_start addr}
66 {high_pc $main_length data8}
67 {DW_AT_type :$integer_label}
68 {DW_AT_decl_file 1 data1}
69 {DW_AT_decl_line 10 data1}
72 integer_label: DW_TAG_base_type {
73 {DW_AT_byte_size $int_size DW_FORM_sdata}
74 {DW_AT_encoding @DW_ATE_signed}
82 {DW_AT_language @DW_LANG_C}
83 {DW_AT_name $srcfile2}
84 {DW_AT_comp_dir ${srcdir}/${subdir}}
85 {stmt_list $L2 DW_FORM_sec_offset}
86 {ranges ${ranges_label_2} DW_FORM_sec_offset}
89 declare_labels integer_label
93 {low_pc some_func addr}
94 {high_pc some_func_end addr}
95 {DW_AT_type :$integer_label}
96 {DW_AT_decl_file 2 data1}
97 {DW_AT_decl_line 5 data1}
100 integer_label: DW_TAG_base_type {
101 {DW_AT_byte_size $int_size DW_FORM_sdata}
102 {DW_AT_encoding @DW_ATE_signed}
108 ranges {is_64 [is_64_target]} {
109 ranges_label_1: sequence {
110 base [lindex $main_result 0]
111 range 0 [lindex $main_result 1]
113 ranges_label_2: sequence {
119 lines {version 2} L1 {
120 include_dir "${srcdir}/${subdir}"
121 file_name "$srcfile" 1
123 # Line data doens't need to be correct, just present.
125 {DW_LNE_set_address [lindex $main_result 0]}
126 {DW_LNS_advance_line 10}
128 {DW_LNS_advance_pc [lindex $main_result 1]}
129 {DW_LNS_advance_line 19}
131 {DW_LNE_end_sequence}
135 lines {version 2} L2 {
136 include_dir "${srcdir}/${subdir}"
137 file_name "dw2-bad-elf-other.c" 1
139 # Line data doens't need to be correct, just present.
141 {DW_LNE_set_address some_func}
142 {DW_LNS_advance_line 5}
144 {DW_LNS_advance_pc 64}
145 {DW_LNS_advance_line 8}
147 {DW_LNE_end_sequence}
152 if { [build_executable ${testfile}.exp ${testfile} \
153 [list $srcfile $srcfile2 $asm_file] {nodebug}] } {
157 # Attempt to place a breakpoint on 'some_func', then check GDB is
158 # still alive. This test can optionally set a breakpoint on 'main'
159 # first (based on GOTO_MAIN), the original bug behaved differently
160 # when there was already a breakpoint set.
161 proc run_test { goto_main } {
162 global binfile decimal hex
164 clean_restart ${binfile}
172 # Place a breakpoint.
173 gdb_test "break some_func" \
174 "Breakpoint $decimal at $hex: file .*dw2-bad-elf-other\\.c, line 6\\."
176 # Check GDB is still alive.
177 gdb_test "echo hello\\n" "hello"
181 foreach_with_prefix goto_main { 0 1 } {