1 # Copyright 2019-2024 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 # This test shows the importance of not corrupting the order of line
17 # table information. When multiple lines are given for the same
18 # address the compiler usually lists these in the order in which we
19 # would expect to encounter them. When stepping through nested inline
20 # frames the last line given for an address is assumed by GDB to be
21 # the most inner frame, and this is what GDB displays.
23 # If we corrupt the order of the line table entries then GDB will
24 # display the wrong line as being the inner most frame.
28 # This test can only be run on targets which support DWARF-2 and use gas.
29 require dwarf2_support
31 # The .c files use __attribute__.
32 require is_c_compiler_gcc
34 standard_testfile .c .S
36 set asm_file [standard_output_file $srcfile2]
37 Dwarf::assemble $asm_file {
38 global srcdir subdir srcfile srcfile2
39 declare_labels ranges_label lines_label
40 declare_labels aaa_label bbb_label ccc_label
41 declare_labels ggg_label hhh_label iii_label
50 set call_in_main [gdb_get_line_number "main call aaa"]
51 set call_in_aaa [gdb_get_line_number "aaa return"]
52 set call_in_bbb [gdb_get_line_number "bbb return"]
53 set call_in_ccc [gdb_get_line_number "ccc return"]
54 set call_in_fff [gdb_get_line_number "fff return"]
55 set call_in_ggg [gdb_get_line_number "ggg return"]
56 set call_in_hhh [gdb_get_line_number "hhh return"]
57 set call_in_iii [gdb_get_line_number "iii return"]
62 {name dw2-inline-stepping.c}
64 {stmt_list ${lines_label} DW_FORM_sec_offset}
65 {ranges ${ranges_label} DW_FORM_sec_offset}
70 {low_pc $ddd_start addr}
71 {high_pc "$ddd_start + $ddd_len" addr}
76 {low_pc $eee_start addr}
77 {high_pc "$eee_start + $eee_len" addr}
82 {low_pc $jjj_start addr}
83 {high_pc "$jjj_start + $jjj_len" addr}
88 {low_pc $kkk_start addr}
89 {high_pc "$kkk_start + $kkk_len" addr}
91 aaa_label: subprogram {
95 bbb_label: subprogram {
99 ccc_label: subprogram {
103 ggg_label: subprogram {
107 hhh_label: subprogram {
111 iii_label: subprogram {
118 {low_pc $main_start addr}
119 {high_pc "$main_start + $main_len" addr}
122 {abstract_origin %$aaa_label}
123 {low_pc main_label2 addr}
124 {high_pc main_label3 addr}
126 {call_line $call_in_main data1}
129 {abstract_origin %$bbb_label}
130 {low_pc main_label2 addr}
131 {high_pc main_label3 addr}
133 {call_line $call_in_aaa data1}
136 {abstract_origin %$ccc_label}
137 {low_pc main_label2 addr}
138 {high_pc main_label3 addr}
140 {call_line $call_in_bbb data1}
148 {low_pc $fff_start addr}
149 {high_pc "$fff_start + $fff_len" addr}
152 {abstract_origin %$ggg_label}
153 {low_pc fff_label addr}
154 {high_pc main_label2 addr}
156 {call_line $call_in_fff data1}
159 {abstract_origin %$hhh_label}
160 {low_pc fff_label addr}
161 {high_pc fff_label2 addr}
163 {call_line $call_in_ggg data1}
166 {abstract_origin %$iii_label}
167 {low_pc fff_label addr}
168 {high_pc fff_label2 addr}
170 {call_line $call_in_hhh data1}
178 lines {version 2} lines_label {
179 include_dir "${srcdir}/${subdir}"
180 file_name "$srcfile" 1
183 DW_LNE_set_address $main_start
184 line [gdb_get_line_number "main prologue"]
186 DW_LNE_set_address main_label
187 line [gdb_get_line_number "main set global_var"]
189 DW_LNE_set_address main_label2
190 line [gdb_get_line_number "main call aaa"]
192 DW_LNE_set_address main_label2
193 line [gdb_get_line_number "aaa return"]
195 DW_LNE_set_address main_label2
196 line [gdb_get_line_number "bbb return"]
198 DW_LNE_set_address main_label2
199 line [gdb_get_line_number "ccc return"]
201 DW_LNE_set_address main_label3
202 line [gdb_get_line_number "main end"]
204 DW_LNE_set_address $main_end
207 DW_LNE_set_address $ddd_start
208 line [gdb_get_line_number "ddd prologue"]
210 DW_LNE_set_address ddd_label
211 line [gdb_get_line_number "ddd return"]
213 DW_LNE_set_address ddd_label2
214 line [gdb_get_line_number "ddd end"]
216 DW_LNE_set_address $ddd_end
219 DW_LNE_set_address $eee_start
220 line [gdb_get_line_number "eee prologue"]
222 DW_LNE_set_address eee_label
223 line [gdb_get_line_number "eee return"]
225 DW_LNE_set_address eee_label2
226 line [gdb_get_line_number "eee end"]
228 DW_LNE_set_address $eee_end
231 DW_LNE_set_address $fff_start
232 line [gdb_get_line_number "fff prologue"]
234 DW_LNE_set_address fff_label
235 line [gdb_get_line_number "fff return"]
237 DW_LNE_set_address fff_label
238 line [gdb_get_line_number "ggg return"]
240 DW_LNE_set_address fff_label
241 line [gdb_get_line_number "hhh return"]
243 DW_LNE_set_address fff_label
244 line [gdb_get_line_number "iii return"]
246 DW_LNE_set_address fff_label2
247 line [gdb_get_line_number "fff end"]
249 DW_LNE_set_address $fff_end
252 DW_LNE_set_address $jjj_start
253 line [gdb_get_line_number "jjj prologue"]
255 DW_LNE_set_address jjj_label
256 line [gdb_get_line_number "jjj return"]
258 DW_LNE_set_address jjj_label2
259 line [gdb_get_line_number "jjj end"]
261 DW_LNE_set_address $jjj_end
264 DW_LNE_set_address $kkk_start
265 line [gdb_get_line_number "kkk prologue"]
267 DW_LNE_set_address kkk_label
268 line [gdb_get_line_number "kkk return"]
270 DW_LNE_set_address $kkk_end
275 ranges {is_64 [is_64_target]} {
276 ranges_label: sequence {
277 range ${main_start} ${main_end}
278 range ${ddd_start} ${ddd_end}
279 range ${eee_start} ${eee_end}
280 range ${fff_start} ${fff_end}
281 range ${jjj_start} ${jjj_end}
282 range ${kkk_start} ${kkk_end}
287 if { [prepare_for_testing "failed to prepare" ${testfile} \
288 [list $srcfile $asm_file] {nodebug}] } {
296 # First we step through all of the functions until we get the 'kkk'.
297 set patterns [list "main call aaa" \
309 foreach p $patterns {
310 gdb_test "step" "/\\* $p \\*/" \
314 # Now check the backtrace.
315 set line_in_main [gdb_get_line_number "main call aaa"]
316 set line_in_aaa [gdb_get_line_number "aaa return"]
317 set line_in_bbb [gdb_get_line_number "bbb return"]
318 set line_in_ccc [gdb_get_line_number "ccc return"]
319 set line_in_ddd [gdb_get_line_number "ddd return"]
320 set line_in_eee [gdb_get_line_number "eee return"]
321 set line_in_fff [gdb_get_line_number "fff return"]
322 set line_in_ggg [gdb_get_line_number "ggg return"]
323 set line_in_hhh [gdb_get_line_number "hhh return"]
324 set line_in_iii [gdb_get_line_number "iii return"]
325 set line_in_jjj [gdb_get_line_number "jjj return"]
326 set line_in_kkk [gdb_get_line_number "kkk return"]
328 gdb_test "bt" [multi_line \
329 "#0 kkk \\(\\) at \[^\r\n\]+${srcfile}:${line_in_kkk}" \
330 "#1 $hex in jjj \\(\\) at \[^\r\n\]+${srcfile}:${line_in_jjj}" \
331 "#2 $hex in iii \\(\\) at \[^\r\n\]+${srcfile}:${line_in_iii}" \
332 "#3 hhh \\(\\) at \[^\r\n\]+${srcfile}:${line_in_hhh}" \
333 "#4 ggg \\(\\) at \[^\r\n\]+${srcfile}:${line_in_ggg}" \
334 "#5 fff \\(\\) at \[^\r\n\]+${srcfile}:${line_in_fff}" \
335 "#6 $hex in eee \\(\\) at \[^\r\n\]+${srcfile}:${line_in_eee}" \
336 "#7 $hex in ddd \\(\\) at \[^\r\n\]+${srcfile}:${line_in_ddd}" \
337 "#8 $hex in ccc \\(\\) at \[^\r\n\]+${srcfile}:${line_in_ccc}" \
338 "#9 bbb \\(\\) at \[^\r\n\]+${srcfile}:${line_in_bbb}" \
339 "#10 aaa \\(\\) at \[^\r\n\]+${srcfile}:${line_in_aaa}" \
340 "#11 main \\(\\) at \[^\r\n\]+${srcfile}:${line_in_main}" ]
342 # Now check we can use 'up' to inspect each frame correctly.
355 foreach p $patterns {
356 gdb_test "up" "/\\* $p \\*/" \