1 # Copyright 2019-2020 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 if {![dwarf2_support]} {
33 # The .c files use __attribute__.
34 if [get_compiler_info] {
41 standard_testfile dw2-inline-many-frames.c dw2-inline-many-frames.S
43 set asm_file [standard_output_file $srcfile2]
44 Dwarf::assemble $asm_file {
45 global srcdir subdir srcfile srcfile2
46 declare_labels ranges_label lines_label
47 declare_labels aaa_label bbb_label ccc_label
48 declare_labels ggg_label hhh_label iii_label
57 set call_in_main [gdb_get_line_number "main call aaa"]
58 set call_in_aaa [gdb_get_line_number "aaa return"]
59 set call_in_bbb [gdb_get_line_number "bbb return"]
60 set call_in_ccc [gdb_get_line_number "ccc return"]
61 set call_in_fff [gdb_get_line_number "fff return"]
62 set call_in_ggg [gdb_get_line_number "ggg return"]
63 set call_in_hhh [gdb_get_line_number "hhh return"]
64 set call_in_iii [gdb_get_line_number "iii return"]
69 {name dw2-inline-stepping.c}
71 {stmt_list ${lines_label} DW_FORM_sec_offset}
72 {ranges ${ranges_label} DW_FORM_sec_offset}
77 {low_pc $ddd_start addr}
78 {high_pc "$ddd_start + $ddd_len" addr}
83 {low_pc $eee_start addr}
84 {high_pc "$eee_start + $eee_len" addr}
89 {low_pc $jjj_start addr}
90 {high_pc "$jjj_start + $jjj_len" addr}
95 {low_pc $kkk_start addr}
96 {high_pc "$kkk_start + $kkk_len" addr}
98 aaa_label: subprogram {
102 bbb_label: subprogram {
106 ccc_label: subprogram {
110 ggg_label: subprogram {
114 hhh_label: subprogram {
118 iii_label: subprogram {
125 {low_pc $main_start addr}
126 {high_pc "$main_start + $main_len" addr}
129 {abstract_origin %$aaa_label}
130 {low_pc main_label2 addr}
131 {high_pc main_label3 addr}
133 {call_line $call_in_main data1}
136 {abstract_origin %$bbb_label}
137 {low_pc main_label2 addr}
138 {high_pc main_label3 addr}
140 {call_line $call_in_aaa data1}
143 {abstract_origin %$ccc_label}
144 {low_pc main_label2 addr}
145 {high_pc main_label3 addr}
147 {call_line $call_in_bbb data1}
155 {low_pc $fff_start addr}
156 {high_pc "$fff_start + $fff_len" addr}
159 {abstract_origin %$ggg_label}
160 {low_pc fff_label addr}
161 {high_pc main_label2 addr}
163 {call_line $call_in_fff data1}
166 {abstract_origin %$hhh_label}
167 {low_pc fff_label addr}
168 {high_pc fff_label2 addr}
170 {call_line $call_in_ggg data1}
173 {abstract_origin %$iii_label}
174 {low_pc fff_label addr}
175 {high_pc fff_label2 addr}
177 {call_line $call_in_hhh data1}
185 lines {version 2} lines_label {
186 include_dir "${srcdir}/${subdir}"
187 file_name "$srcfile" 1
190 {DW_LNE_set_address $main_start}
191 {DW_LNS_advance_line [expr [gdb_get_line_number "main prologue"] - 1]}
193 {DW_LNE_set_address main_label}
194 {DW_LNS_advance_line [expr [gdb_get_line_number "main set global_var"] - [gdb_get_line_number "main prologue"]]}
196 {DW_LNE_set_address main_label2}
197 {DW_LNS_advance_line [expr [gdb_get_line_number "main call aaa"] - [gdb_get_line_number "main set global_var"]]}
199 {DW_LNE_set_address main_label2}
200 {DW_LNS_advance_line [expr [gdb_get_line_number "aaa return"] - [gdb_get_line_number "main call aaa"]]}
202 {DW_LNE_set_address main_label2}
203 {DW_LNS_advance_line [expr [gdb_get_line_number "bbb return"] - [gdb_get_line_number "aaa return"]]}
205 {DW_LNE_set_address main_label2}
206 {DW_LNS_advance_line [expr [gdb_get_line_number "ccc return"] - [gdb_get_line_number "bbb return"]]}
208 {DW_LNE_set_address main_label3}
209 {DW_LNS_advance_line [expr [gdb_get_line_number "main end"] - [gdb_get_line_number "ccc return"]]}
211 {DW_LNE_set_address $main_end}
212 {DW_LNE_end_sequence}
214 {DW_LNE_set_address $ddd_start}
215 {DW_LNS_advance_line [expr [gdb_get_line_number "ddd prologue"] - 1]}
217 {DW_LNE_set_address ddd_label}
218 {DW_LNS_advance_line [expr [gdb_get_line_number "ddd return"] - [gdb_get_line_number "ddd prologue"]]}
220 {DW_LNE_set_address ddd_label2}
221 {DW_LNS_advance_line [expr [gdb_get_line_number "ddd end"] - [gdb_get_line_number "ddd return"]]}
223 {DW_LNE_set_address $ddd_end}
224 {DW_LNE_end_sequence}
226 {DW_LNE_set_address $eee_start}
227 {DW_LNS_advance_line [expr [gdb_get_line_number "eee prologue"] - 1]}
229 {DW_LNE_set_address eee_label}
230 {DW_LNS_advance_line [expr [gdb_get_line_number "eee return"] - [gdb_get_line_number "eee prologue"]]}
232 {DW_LNE_set_address eee_label2}
233 {DW_LNS_advance_line [expr [gdb_get_line_number "eee end"] - [gdb_get_line_number "eee return"]]}
235 {DW_LNE_set_address $eee_end}
236 {DW_LNE_end_sequence}
238 {DW_LNE_set_address $fff_start}
239 {DW_LNS_advance_line [expr [gdb_get_line_number "fff prologue"] - 1]}
241 {DW_LNE_set_address fff_label}
242 {DW_LNS_advance_line [expr [gdb_get_line_number "fff return"] - [gdb_get_line_number "fff prologue"]]}
244 {DW_LNE_set_address fff_label}
245 {DW_LNS_advance_line [expr [gdb_get_line_number "ggg return"] - [gdb_get_line_number "fff return"]]}
247 {DW_LNE_set_address fff_label}
248 {DW_LNS_advance_line [expr [gdb_get_line_number "hhh return"] - [gdb_get_line_number "ggg return"]]}
250 {DW_LNE_set_address fff_label}
251 {DW_LNS_advance_line [expr [gdb_get_line_number "iii return"] - [gdb_get_line_number "hhh return"]]}
253 {DW_LNE_set_address fff_label2}
254 {DW_LNS_advance_line [expr [gdb_get_line_number "fff end"] - [gdb_get_line_number "fff return"]]}
256 {DW_LNE_set_address $fff_end}
257 {DW_LNE_end_sequence}
259 {DW_LNE_set_address $jjj_start}
260 {DW_LNS_advance_line [expr [gdb_get_line_number "jjj prologue"] - 1]}
262 {DW_LNE_set_address jjj_label}
263 {DW_LNS_advance_line [expr [gdb_get_line_number "jjj return"] - [gdb_get_line_number "jjj prologue"]]}
265 {DW_LNE_set_address jjj_label2}
266 {DW_LNS_advance_line [expr [gdb_get_line_number "jjj end"] - [gdb_get_line_number "jjj return"]]}
268 {DW_LNE_set_address $jjj_end}
269 {DW_LNE_end_sequence}
271 {DW_LNE_set_address $kkk_start}
272 {DW_LNS_advance_line [expr [gdb_get_line_number "kkk prologue"] - 1]}
274 {DW_LNE_set_address kkk_label}
275 {DW_LNS_advance_line [expr [gdb_get_line_number "kkk return"] - [gdb_get_line_number "kkk prologue"]]}
277 {DW_LNE_set_address $kkk_end}
278 {DW_LNE_end_sequence}
282 ranges {is_64 [is_64_target]} {
283 ranges_label: sequence {
284 {range {${main_start}} ${main_end}}
285 {range {${ddd_start}} ${ddd_end}}
286 {range {${eee_start}} ${eee_end}}
287 {range {${fff_start}} ${fff_end}}
288 {range {${jjj_start}} ${jjj_end}}
289 {range {${kkk_start}} ${kkk_end}}
294 if { [prepare_for_testing "failed to prepare" ${testfile} \
295 [list $srcfile $asm_file] {nodebug}] } {
303 # First we step through all of the functions until we get the 'kkk'.
304 set patterns [list "main call aaa" \
316 foreach p $patterns {
317 gdb_test "step" "/\\* $p \\*/" \
321 # Now check the backtrace.
322 set line_in_main [gdb_get_line_number "main call aaa"]
323 set line_in_aaa [gdb_get_line_number "aaa return"]
324 set line_in_bbb [gdb_get_line_number "bbb return"]
325 set line_in_ccc [gdb_get_line_number "ccc return"]
326 set line_in_ddd [gdb_get_line_number "ddd return"]
327 set line_in_eee [gdb_get_line_number "eee return"]
328 set line_in_fff [gdb_get_line_number "fff return"]
329 set line_in_ggg [gdb_get_line_number "ggg return"]
330 set line_in_hhh [gdb_get_line_number "hhh return"]
331 set line_in_iii [gdb_get_line_number "iii return"]
332 set line_in_jjj [gdb_get_line_number "jjj return"]
333 set line_in_kkk [gdb_get_line_number "kkk return"]
335 gdb_test "bt" [multi_line \
336 "#0 kkk \\(\\) at \[^\r\n\]+${srcfile}:${line_in_kkk}" \
337 "#1 $hex in jjj \\(\\) at \[^\r\n\]+${srcfile}:${line_in_jjj}" \
338 "#2 $hex in iii \\(\\) at \[^\r\n\]+${srcfile}:${line_in_iii}" \
339 "#3 hhh \\(\\) at \[^\r\n\]+${srcfile}:${line_in_hhh}" \
340 "#4 ggg \\(\\) at \[^\r\n\]+${srcfile}:${line_in_ggg}" \
341 "#5 fff \\(\\) at \[^\r\n\]+${srcfile}:${line_in_fff}" \
342 "#6 $hex in eee \\(\\) at \[^\r\n\]+${srcfile}:${line_in_eee}" \
343 "#7 $hex in ddd \\(\\) at \[^\r\n\]+${srcfile}:${line_in_ddd}" \
344 "#8 $hex in ccc \\(\\) at \[^\r\n\]+${srcfile}:${line_in_ccc}" \
345 "#9 bbb \\(\\) at \[^\r\n\]+${srcfile}:${line_in_bbb}" \
346 "#10 aaa \\(\\) at \[^\r\n\]+${srcfile}:${line_in_aaa}" \
347 "#11 main \\(\\) at \[^\r\n\]+${srcfile}:${line_in_main}" ]
349 # Now check we can use 'up' to inspect each frame correctly.
362 foreach p $patterns {
363 gdb_test "up" "/\\* $p \\*/" \