Add translations for various sub-directories
[binutils-gdb.git] / gdb / testsuite / gdb.dwarf2 / dw2-inline-many-frames.exp
blobcffe59493d92298f969d7a7eaedb59870c9d75d6
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.
26 load_lib dwarf.exp
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
43     get_func_info main
44     get_func_info ddd
45     get_func_info eee
46     get_func_info fff
47     get_func_info jjj
48     get_func_info kkk
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"]
59     cu {} {
60         compile_unit {
61             {language @DW_LANG_C}
62             {name dw2-inline-stepping.c}
63             {low_pc 0 addr}
64             {stmt_list ${lines_label} DW_FORM_sec_offset}
65             {ranges ${ranges_label} DW_FORM_sec_offset}
66         } {
67             subprogram {
68                 {external 1 flag}
69                 {name ddd}
70                 {low_pc $ddd_start addr}
71                 {high_pc "$ddd_start + $ddd_len" addr}
72             }
73             subprogram {
74                 {external 1 flag}
75                 {name eee}
76                 {low_pc $eee_start addr}
77                 {high_pc "$eee_start + $eee_len" addr}
78             }
79             subprogram {
80                 {external 1 flag}
81                 {name jjj}
82                 {low_pc $jjj_start addr}
83                 {high_pc "$jjj_start + $jjj_len" addr}
84             }
85             subprogram {
86                 {external 1 flag}
87                 {name kkk}
88                 {low_pc $kkk_start addr}
89                 {high_pc "$kkk_start + $kkk_len" addr}
90             }
91             aaa_label: subprogram {
92                 {name aaa}
93                 {inline 3 data1}
94             }
95             bbb_label: subprogram {
96                 {name bbb}
97                 {inline 3 data1}
98             }
99             ccc_label: subprogram {
100                 {name ccc}
101                 {inline 3 data1}
102             }
103             ggg_label: subprogram {
104                 {name ggg}
105                 {inline 3 data1}
106             }
107             hhh_label: subprogram {
108                 {name hhh}
109                 {inline 3 data1}
110             }
111             iii_label: subprogram {
112                 {name iii}
113                 {inline 3 data1}
114             }
115             subprogram {
116                 {external 1 flag}
117                 {name main}
118                 {low_pc $main_start addr}
119                 {high_pc "$main_start + $main_len" addr}
120             } {
121                 inlined_subroutine {
122                     {abstract_origin %$aaa_label}
123                     {low_pc main_label2 addr}
124                     {high_pc main_label3 addr}
125                     {call_file 1 data1}
126                     {call_line $call_in_main data1}
127                 } {
128                     inlined_subroutine {
129                         {abstract_origin %$bbb_label}
130                         {low_pc main_label2 addr}
131                         {high_pc main_label3 addr}
132                         {call_file 1 data1}
133                         {call_line $call_in_aaa data1}
134                     }  {
135                         inlined_subroutine {
136                             {abstract_origin %$ccc_label}
137                             {low_pc main_label2 addr}
138                             {high_pc main_label3 addr}
139                             {call_file 1 data1}
140                             {call_line $call_in_bbb data1}
141                         }
142                     }
143                 }
144             }
145             subprogram {
146                 {external 1 flag}
147                 {name fff}
148                 {low_pc $fff_start addr}
149                 {high_pc "$fff_start + $fff_len" addr}
150             }  {
151                 inlined_subroutine {
152                     {abstract_origin %$ggg_label}
153                     {low_pc fff_label addr}
154                     {high_pc main_label2 addr}
155                     {call_file 1 data1}
156                     {call_line $call_in_fff data1}
157                 } {
158                     inlined_subroutine {
159                         {abstract_origin %$hhh_label}
160                         {low_pc fff_label addr}
161                         {high_pc fff_label2 addr}
162                         {call_file 1 data1}
163                         {call_line $call_in_ggg data1}
164                     }  {
165                         inlined_subroutine {
166                             {abstract_origin %$iii_label}
167                             {low_pc fff_label addr}
168                             {high_pc fff_label2 addr}
169                             {call_file 1 data1}
170                             {call_line $call_in_hhh data1}
171                         }
172                     }
173                 }
174             }
175         }
176     }
178     lines {version 2} lines_label {
179         include_dir "${srcdir}/${subdir}"
180         file_name "$srcfile" 1
182         program {
183             DW_LNE_set_address $main_start
184             line [gdb_get_line_number "main prologue"]
185             DW_LNS_copy
186             DW_LNE_set_address main_label
187             line [gdb_get_line_number "main set global_var"]
188             DW_LNS_copy
189             DW_LNE_set_address main_label2
190             line [gdb_get_line_number "main call aaa"]
191             DW_LNS_copy
192             DW_LNE_set_address main_label2
193             line [gdb_get_line_number "aaa return"]
194             DW_LNS_copy
195             DW_LNE_set_address main_label2
196             line [gdb_get_line_number "bbb return"]
197             DW_LNS_copy
198             DW_LNE_set_address main_label2
199             line [gdb_get_line_number "ccc return"]
200             DW_LNS_copy
201             DW_LNE_set_address main_label3
202             line [gdb_get_line_number "main end"]
203             DW_LNS_copy
204             DW_LNE_set_address $main_end
205             DW_LNE_end_sequence
207             DW_LNE_set_address $ddd_start
208             line [gdb_get_line_number "ddd prologue"]
209             DW_LNS_copy
210             DW_LNE_set_address ddd_label
211             line [gdb_get_line_number "ddd return"]
212             DW_LNS_copy
213             DW_LNE_set_address ddd_label2
214             line [gdb_get_line_number "ddd end"]
215             DW_LNS_copy
216             DW_LNE_set_address $ddd_end
217             DW_LNE_end_sequence
219             DW_LNE_set_address $eee_start
220             line [gdb_get_line_number "eee prologue"]
221             DW_LNS_copy
222             DW_LNE_set_address eee_label
223             line [gdb_get_line_number "eee return"]
224             DW_LNS_copy
225             DW_LNE_set_address eee_label2
226             line [gdb_get_line_number "eee end"]
227             DW_LNS_copy
228             DW_LNE_set_address $eee_end
229             DW_LNE_end_sequence
231             DW_LNE_set_address $fff_start
232             line [gdb_get_line_number "fff prologue"]
233             DW_LNS_copy
234             DW_LNE_set_address fff_label
235             line [gdb_get_line_number "fff return"]
236             DW_LNS_copy
237             DW_LNE_set_address fff_label
238             line [gdb_get_line_number "ggg return"]
239             DW_LNS_copy
240             DW_LNE_set_address fff_label
241             line [gdb_get_line_number "hhh return"]
242             DW_LNS_copy
243             DW_LNE_set_address fff_label
244             line [gdb_get_line_number "iii return"]
245             DW_LNS_copy
246             DW_LNE_set_address fff_label2
247             line [gdb_get_line_number "fff end"]
248             DW_LNS_copy
249             DW_LNE_set_address $fff_end
250             DW_LNE_end_sequence
252             DW_LNE_set_address $jjj_start
253             line [gdb_get_line_number "jjj prologue"]
254             DW_LNS_copy
255             DW_LNE_set_address jjj_label
256             line [gdb_get_line_number "jjj return"]
257             DW_LNS_copy
258             DW_LNE_set_address jjj_label2
259             line [gdb_get_line_number "jjj end"]
260             DW_LNS_copy
261             DW_LNE_set_address $jjj_end
262             DW_LNE_end_sequence
264             DW_LNE_set_address $kkk_start
265             line [gdb_get_line_number "kkk prologue"]
266             DW_LNS_copy
267             DW_LNE_set_address kkk_label
268             line [gdb_get_line_number "kkk return"]
269             DW_LNS_copy
270             DW_LNE_set_address $kkk_end
271             DW_LNE_end_sequence
272         }
273     }
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}
283         }
284     }
287 if { [prepare_for_testing "failed to prepare" ${testfile} \
288           [list $srcfile $asm_file] {nodebug}] } {
289     return -1
292 if ![runto_main] {
293     return -1
296 # First we step through all of the functions until we get the 'kkk'.
297 set patterns [list "main call aaa" \
298                   "aaa return" \
299                   "bbb return" \
300                   "ccc return" \
301                   "ddd return" \
302                   "eee return" \
303                   "fff return" \
304                   "ggg return" \
305                   "hhh return" \
306                   "iii return" \
307                   "jjj return" \
308                   "kkk return" ]
309 foreach p $patterns {
310     gdb_test "step" "/\\* $p \\*/" \
311         "step to '$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.
343 set patterns [list  \
344                   "jjj return" \
345                   "iii return" \
346                   "hhh return" \
347                   "ggg return" \
348                   "fff return" \
349                   "eee return" \
350                   "ddd return" \
351                   "ccc return" \
352                   "bbb return" \
353                   "aaa return" \
354                   "main call aaa" ]
355 foreach p $patterns {
356     gdb_test "up" "/\\* $p \\*/" \
357         "up to '$p'"