1 # Copyright 2019-2020 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 # 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. 22 # 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. 25 26 load_lib dwarf.exp 27 28 # This test can only be run on targets which support DWARF-2 and use gas. 29 if {![dwarf2_support]} { 30 return 0 31 } 32 33 # The .c files use __attribute__. 34 if [get_compiler_info] { 35 return -1 36 } 37 if !$gcc_compiled { 38 return 0 39 } 40 41 standard_testfile dw2-inline-many-frames.c dw2-inline-many-frames.S 42 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 49 50 get_func_info main 51 get_func_info ddd 52 get_func_info eee 53 get_func_info fff 54 get_func_info jjj 55 get_func_info kkk 56 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"] 65 66 cu {} { 67 compile_unit { 68 {language @DW_LANG_C} 69 {name dw2-inline-stepping.c} 70 {low_pc 0 addr} 71 {stmt_list ${lines_label} DW_FORM_sec_offset} 72 {ranges ${ranges_label} DW_FORM_sec_offset} 73 } { 74 subprogram { 75 {external 1 flag} 76 {name ddd} 77 {low_pc $ddd_start addr} 78 {high_pc "$ddd_start + $ddd_len" addr} 79 } 80 subprogram { 81 {external 1 flag} 82 {name eee} 83 {low_pc $eee_start addr} 84 {high_pc "$eee_start + $eee_len" addr} 85 } 86 subprogram { 87 {external 1 flag} 88 {name jjj} 89 {low_pc $jjj_start addr} 90 {high_pc "$jjj_start + $jjj_len" addr} 91 } 92 subprogram { 93 {external 1 flag} 94 {name kkk} 95 {low_pc $kkk_start addr} 96 {high_pc "$kkk_start + $kkk_len" addr} 97 } 98 aaa_label: subprogram { 99 {name aaa} 100 {inline 3 data1} 101 } 102 bbb_label: subprogram { 103 {name bbb} 104 {inline 3 data1} 105 } 106 ccc_label: subprogram { 107 {name ccc} 108 {inline 3 data1} 109 } 110 ggg_label: subprogram { 111 {name ggg} 112 {inline 3 data1} 113 } 114 hhh_label: subprogram { 115 {name hhh} 116 {inline 3 data1} 117 } 118 iii_label: subprogram { 119 {name iii} 120 {inline 3 data1} 121 } 122 subprogram { 123 {external 1 flag} 124 {name main} 125 {low_pc $main_start addr} 126 {high_pc "$main_start + $main_len" addr} 127 } { 128 inlined_subroutine { 129 {abstract_origin %$aaa_label} 130 {low_pc main_label2 addr} 131 {high_pc main_label3 addr} 132 {call_file 1 data1} 133 {call_line $call_in_main data1} 134 } { 135 inlined_subroutine { 136 {abstract_origin %$bbb_label} 137 {low_pc main_label2 addr} 138 {high_pc main_label3 addr} 139 {call_file 1 data1} 140 {call_line $call_in_aaa data1} 141 } { 142 inlined_subroutine { 143 {abstract_origin %$ccc_label} 144 {low_pc main_label2 addr} 145 {high_pc main_label3 addr} 146 {call_file 1 data1} 147 {call_line $call_in_bbb data1} 148 } 149 } 150 } 151 } 152 subprogram { 153 {external 1 flag} 154 {name fff} 155 {low_pc $fff_start addr} 156 {high_pc "$fff_start + $fff_len" addr} 157 } { 158 inlined_subroutine { 159 {abstract_origin %$ggg_label} 160 {low_pc fff_label addr} 161 {high_pc main_label2 addr} 162 {call_file 1 data1} 163 {call_line $call_in_fff data1} 164 } { 165 inlined_subroutine { 166 {abstract_origin %$hhh_label} 167 {low_pc fff_label addr} 168 {high_pc fff_label2 addr} 169 {call_file 1 data1} 170 {call_line $call_in_ggg data1} 171 } { 172 inlined_subroutine { 173 {abstract_origin %$iii_label} 174 {low_pc fff_label addr} 175 {high_pc fff_label2 addr} 176 {call_file 1 data1} 177 {call_line $call_in_hhh data1} 178 } 179 } 180 } 181 } 182 } 183 } 184 185 lines {version 2} lines_label { 186 include_dir "${srcdir}/${subdir}" 187 file_name "$srcfile" 1 188 189 program { 190 {DW_LNE_set_address $main_start} 191 {line [gdb_get_line_number "main prologue"]} 192 {DW_LNS_copy} 193 {DW_LNE_set_address main_label} 194 {line [gdb_get_line_number "main set global_var"]} 195 {DW_LNS_copy} 196 {DW_LNE_set_address main_label2} 197 {line [gdb_get_line_number "main call aaa"]} 198 {DW_LNS_copy} 199 {DW_LNE_set_address main_label2} 200 {line [gdb_get_line_number "aaa return"]} 201 {DW_LNS_copy} 202 {DW_LNE_set_address main_label2} 203 {line [gdb_get_line_number "bbb return"]} 204 {DW_LNS_copy} 205 {DW_LNE_set_address main_label2} 206 {line [gdb_get_line_number "ccc return"]} 207 {DW_LNS_copy} 208 {DW_LNE_set_address main_label3} 209 {line [gdb_get_line_number "main end"]} 210 {DW_LNS_copy} 211 {DW_LNE_set_address $main_end} 212 {DW_LNE_end_sequence} 213 214 {DW_LNE_set_address $ddd_start} 215 {line [gdb_get_line_number "ddd prologue"]} 216 {DW_LNS_copy} 217 {DW_LNE_set_address ddd_label} 218 {line [gdb_get_line_number "ddd return"]} 219 {DW_LNS_copy} 220 {DW_LNE_set_address ddd_label2} 221 {line [gdb_get_line_number "ddd end"]} 222 {DW_LNS_copy} 223 {DW_LNE_set_address $ddd_end} 224 {DW_LNE_end_sequence} 225 226 {DW_LNE_set_address $eee_start} 227 {line [gdb_get_line_number "eee prologue"]} 228 {DW_LNS_copy} 229 {DW_LNE_set_address eee_label} 230 {line [gdb_get_line_number "eee return"]} 231 {DW_LNS_copy} 232 {DW_LNE_set_address eee_label2} 233 {line [gdb_get_line_number "eee end"]} 234 {DW_LNS_copy} 235 {DW_LNE_set_address $eee_end} 236 {DW_LNE_end_sequence} 237 238 {DW_LNE_set_address $fff_start} 239 {line [gdb_get_line_number "fff prologue"]} 240 {DW_LNS_copy} 241 {DW_LNE_set_address fff_label} 242 {line [gdb_get_line_number "fff return"]} 243 {DW_LNS_copy} 244 {DW_LNE_set_address fff_label} 245 {line [gdb_get_line_number "ggg return"]} 246 {DW_LNS_copy} 247 {DW_LNE_set_address fff_label} 248 {line [gdb_get_line_number "hhh return"]} 249 {DW_LNS_copy} 250 {DW_LNE_set_address fff_label} 251 {line [gdb_get_line_number "iii return"]} 252 {DW_LNS_copy} 253 {DW_LNE_set_address fff_label2} 254 {line [gdb_get_line_number "fff end"]} 255 {DW_LNS_copy} 256 {DW_LNE_set_address $fff_end} 257 {DW_LNE_end_sequence} 258 259 {DW_LNE_set_address $jjj_start} 260 {line [gdb_get_line_number "jjj prologue"]} 261 {DW_LNS_copy} 262 {DW_LNE_set_address jjj_label} 263 {line [gdb_get_line_number "jjj return"]} 264 {DW_LNS_copy} 265 {DW_LNE_set_address jjj_label2} 266 {line [gdb_get_line_number "jjj end"]} 267 {DW_LNS_copy} 268 {DW_LNE_set_address $jjj_end} 269 {DW_LNE_end_sequence} 270 271 {DW_LNE_set_address $kkk_start} 272 {line [gdb_get_line_number "kkk prologue"]} 273 {DW_LNS_copy} 274 {DW_LNE_set_address kkk_label} 275 {line [gdb_get_line_number "kkk return"]} 276 {DW_LNS_copy} 277 {DW_LNE_set_address $kkk_end} 278 {DW_LNE_end_sequence} 279 } 280 } 281 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}} 290 } 291 } 292 } 293 294 if { [prepare_for_testing "failed to prepare" ${testfile} \ 295 [list $srcfile $asm_file] {nodebug}] } { 296 return -1 297 } 298 299 if ![runto_main] { 300 return -1 301 } 302 303 # First we step through all of the functions until we get the 'kkk'. 304 set patterns [list "main call aaa" \ 305 "aaa return" \ 306 "bbb return" \ 307 "ccc return" \ 308 "ddd return" \ 309 "eee return" \ 310 "fff return" \ 311 "ggg return" \ 312 "hhh return" \ 313 "iii return" \ 314 "jjj return" \ 315 "kkk return" ] 316 foreach p $patterns { 317 gdb_test "step" "/\\* $p \\*/" \ 318 "step to '$p'" 319 } 320 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"] 334 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}" ] 348 349 # Now check we can use 'up' to inspect each frame correctly. 350 set patterns [list \ 351 "jjj return" \ 352 "iii return" \ 353 "hhh return" \ 354 "ggg return" \ 355 "fff return" \ 356 "eee return" \ 357 "ddd return" \ 358 "ccc return" \ 359 "bbb return" \ 360 "aaa return" \ 361 "main call aaa" ] 362 foreach p $patterns { 363 gdb_test "up" "/\\* $p \\*/" \ 364 "up to '$p'" 365 } 366