5ab08c18f77e8a7d2a8391de7f17fa66a31d4a86
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.dwarf2 / dw2-bad-elf.exp
1 # Copyright 2019-2021 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 # 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.
19 #
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.
24 #
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.
29
30 load_lib dwarf.exp
31
32 # This test can only be run on targets which support DWARF-2 and use gas.
33 if {![dwarf2_support]} {
34 return 0
35 }
36
37 standard_testfile main.c -other.S -dwarf.S
38
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
43
44 declare_labels ranges_label_1 ranges_label_2 L1 L2
45
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]
49
50 set int_size [get_sizeof "int" 4]
51
52 cu {} {
53 DW_TAG_compile_unit {
54 {DW_AT_language @DW_LANG_C}
55 {DW_AT_name $srcfile}
56 {DW_AT_comp_dir ${srcdir}/${subdir}}
57 {stmt_list $L1 DW_FORM_sec_offset}
58 {ranges ${ranges_label_1} DW_FORM_sec_offset}
59 {DW_AT_low_pc 0 addr}
60 } {
61 declare_labels integer_label
62
63 DW_TAG_subprogram {
64 {name main}
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}
70 }
71
72 integer_label: DW_TAG_base_type {
73 {DW_AT_byte_size $int_size DW_FORM_sdata}
74 {DW_AT_encoding @DW_ATE_signed}
75 {DW_AT_name integer}
76 }
77 }
78 }
79
80 cu {} {
81 DW_TAG_compile_unit {
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}
87 {DW_AT_low_pc 0 addr}
88 } {
89 declare_labels integer_label
90
91 DW_TAG_subprogram {
92 {name some_func}
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}
98 }
99
100 integer_label: DW_TAG_base_type {
101 {DW_AT_byte_size $int_size DW_FORM_sdata}
102 {DW_AT_encoding @DW_ATE_signed}
103 {DW_AT_name integer}
104 }
105 }
106 }
107
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]
112 }
113 ranges_label_2: sequence {
114 base some_func
115 range 0 64
116 }
117 }
118
119 lines {version 2} L1 {
120 include_dir "${srcdir}/${subdir}"
121 file_name "$srcfile" 1
122
123 # Line data doens't need to be correct, just present.
124 program {
125 {DW_LNE_set_address [lindex $main_result 0]}
126 {DW_LNS_advance_line 10}
127 {DW_LNS_copy}
128 {DW_LNS_advance_pc [lindex $main_result 1]}
129 {DW_LNS_advance_line 19}
130 {DW_LNS_copy}
131 {DW_LNE_end_sequence}
132 }
133 }
134
135 lines {version 2} L2 {
136 include_dir "${srcdir}/${subdir}"
137 file_name "dw2-bad-elf-other.c" 1
138
139 # Line data doens't need to be correct, just present.
140 program {
141 {DW_LNE_set_address some_func}
142 {DW_LNS_advance_line 5}
143 {DW_LNS_copy}
144 {DW_LNS_advance_pc 64}
145 {DW_LNS_advance_line 8}
146 {DW_LNS_copy}
147 {DW_LNE_end_sequence}
148 }
149 }
150 }
151
152 if { [build_executable ${testfile}.exp ${testfile} \
153 [list $srcfile $srcfile2 $asm_file] {nodebug}] } {
154 return -1
155 }
156
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
163
164 clean_restart ${binfile}
165
166 if { $goto_main } {
167 if ![runto_main] {
168 return -1
169 }
170 }
171
172 # Place a breakpoint.
173 gdb_test "break some_func" \
174 "Breakpoint $decimal at $hex: file .*dw2-bad-elf-other\\.c, line 6\\."
175
176 # Check GDB is still alive.
177 gdb_test "echo hello\\n" "hello"
178 }
179
180 # Run the tests.
181 foreach_with_prefix goto_main { 0 1 } {
182 run_test $goto_main
183 }
This page took 0.034588 seconds and 3 git commands to generate.