1 # Copyright
2019-2022 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 if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] } {
40 untested "failed to compile"
44 set int_size [get_sizeof "int" 4]
46 # Make some DWARF for the test.
47 set asm_file [standard_output_file $srcfile3]
48 Dwarf::assemble $asm_file {
49 global srcdir subdir srcfile srcfile2 int_size
51 declare_labels ranges_label_1 ranges_label_2 L1 L2
53 set main_result [function_range main ${srcdir}/${subdir}/${srcfile}]
54 set main_start [lindex $main_result 0]
55 set main_length [lindex $main_result 1]
59 {DW_AT_language @DW_LANG_C}
61 {DW_AT_comp_dir ${srcdir}/${subdir}}
62 {stmt_list $L1 DW_FORM_sec_offset}
63 {ranges ${ranges_label_1} DW_FORM_sec_offset}
66 declare_labels integer_label
70 {low_pc $main_start addr}
71 {high_pc $main_length data8}
72 {DW_AT_type :$integer_label}
73 {DW_AT_decl_file 1 data1}
74 {DW_AT_decl_line 10 data1}
77 integer_label: DW_TAG_base_type {
78 {DW_AT_byte_size $int_size DW_FORM_sdata}
79 {DW_AT_encoding @DW_ATE_signed}
87 {DW_AT_language @DW_LANG_C}
88 {DW_AT_name $srcfile2}
89 {DW_AT_comp_dir ${srcdir}/${subdir}}
90 {stmt_list $L2 DW_FORM_sec_offset}
91 {ranges ${ranges_label_2} DW_FORM_sec_offset}
94 declare_labels integer_label
98 {low_pc some_func addr}
99 {high_pc some_func_end addr}
100 {DW_AT_type :$integer_label}
101 {DW_AT_decl_file 2 data1}
102 {DW_AT_decl_line 5 data1}
105 integer_label: DW_TAG_base_type {
106 {DW_AT_byte_size $int_size DW_FORM_sdata}
107 {DW_AT_encoding @DW_ATE_signed}
113 ranges {is_64 [is_64_target]} {
114 ranges_label_1: sequence {
115 base [lindex $main_result 0]
116 range 0 [lindex $main_result 1]
118 ranges_label_2: sequence {
124 lines {version 2} L1 {
125 include_dir "${srcdir}/${subdir}"
126 file_name "$srcfile" 1
128 # Line data doens't need to be correct
, just present.
130 DW_LNE_set_address
[lindex $main_result
0]
131 DW_LNS_advance_line
10
133 DW_LNS_advance_pc
[lindex $main_result
1]
134 DW_LNS_advance_line
19
140 lines
{version
2} L2
{
141 include_dir
"${srcdir}/${subdir}"
142 file_name
"dw2-bad-elf-other.c" 1
144 # Line data doens
't need to be correct, just present.
146 DW_LNE_set_address some_func
147 DW_LNS_advance_line 5
150 DW_LNS_advance_line 8
157 if { [build_executable ${testfile}.exp ${testfile} \
158 [list $srcfile $srcfile2 $asm_file] {nodebug}] } {
162 # Attempt to place a breakpoint on 'some_func
', then check GDB is
163 # still alive. This test can optionally set a breakpoint on 'main
'
164 # first (based on GOTO_MAIN), the original bug behaved differently
165 # when there was already a breakpoint set.
166 proc run_test { goto_main } {
167 global binfile decimal hex
169 clean_restart ${binfile}
177 # Place a breakpoint.
178 gdb_test "break some_func" \
179 "Breakpoint $decimal at $hex: file .*dw2-bad-elf-other\\.c, line 6\\."
181 # Check GDB is still alive.
182 gdb_test "echo hello\\n" "hello"
186 foreach_with_prefix goto_main { 0 1 } {