1 1.1 christos # Copyright 2019-2020 Free Software Foundation, Inc. 2 1.1 christos 3 1.1 christos # This program is free software; you can redistribute it and/or modify 4 1.1 christos # it under the terms of the GNU General Public License as published by 5 1.1 christos # the Free Software Foundation; either version 3 of the License, or 6 1.1 christos # (at your option) any later version. 7 1.1 christos # 8 1.1 christos # This program is distributed in the hope that it will be useful, 9 1.1 christos # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 1.1 christos # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 1.1 christos # GNU General Public License for more details. 12 1.1 christos # 13 1.1 christos # You should have received a copy of the GNU General Public License 14 1.1 christos # along with this program. If not, see <http://www.gnu.org/licenses/>. 15 1.1 christos 16 1.1 christos # This test shows the importance of not corrupting the order of line 17 1.1 christos # table information. When multiple lines are given for the same 18 1.1 christos # address the compiler usually lists these in the order in which we 19 1.1 christos # would expect to encounter them. When stepping through nested inline 20 1.1 christos # frames the last line given for an address is assumed by GDB to be 21 1.1 christos # the most inner frame, and this is what GDB displays. 22 1.1 christos # 23 1.1 christos # If we corrupt the order of the line table entries then GDB will 24 1.1 christos # display the wrong line as being the inner most frame. 25 1.1 christos 26 1.1 christos load_lib dwarf.exp 27 1.1 christos 28 1.1 christos # This test can only be run on targets which support DWARF-2 and use gas. 29 1.1 christos if {![dwarf2_support]} { 30 1.1 christos return 0 31 1.1 christos } 32 1.1 christos 33 1.1 christos # The .c files use __attribute__. 34 1.1 christos if [get_compiler_info] { 35 1.1 christos return -1 36 1.1 christos } 37 1.1 christos if !$gcc_compiled { 38 1.1 christos return 0 39 1.1 christos } 40 1.1 christos 41 1.1 christos standard_testfile dw2-inline-many-frames.c dw2-inline-many-frames.S 42 1.1 christos 43 1.1 christos set asm_file [standard_output_file $srcfile2] 44 1.1 christos Dwarf::assemble $asm_file { 45 1.1 christos global srcdir subdir srcfile srcfile2 46 1.1 christos declare_labels ranges_label lines_label 47 1.1 christos declare_labels aaa_label bbb_label ccc_label 48 1.1 christos declare_labels ggg_label hhh_label iii_label 49 1.1 christos 50 1.1 christos get_func_info main 51 1.1 christos get_func_info ddd 52 1.1 christos get_func_info eee 53 1.1 christos get_func_info fff 54 1.1 christos get_func_info jjj 55 1.1 christos get_func_info kkk 56 1.1 christos 57 1.1 christos set call_in_main [gdb_get_line_number "main call aaa"] 58 1.1 christos set call_in_aaa [gdb_get_line_number "aaa return"] 59 1.1 christos set call_in_bbb [gdb_get_line_number "bbb return"] 60 1.1 christos set call_in_ccc [gdb_get_line_number "ccc return"] 61 1.1 christos set call_in_fff [gdb_get_line_number "fff return"] 62 1.1 christos set call_in_ggg [gdb_get_line_number "ggg return"] 63 1.1 christos set call_in_hhh [gdb_get_line_number "hhh return"] 64 1.1 christos set call_in_iii [gdb_get_line_number "iii return"] 65 1.1 christos 66 1.1 christos cu {} { 67 1.1 christos compile_unit { 68 1.1 christos {language @DW_LANG_C} 69 1.1 christos {name dw2-inline-stepping.c} 70 1.1 christos {low_pc 0 addr} 71 1.1 christos {stmt_list ${lines_label} DW_FORM_sec_offset} 72 1.1 christos {ranges ${ranges_label} DW_FORM_sec_offset} 73 1.1 christos } { 74 1.1 christos subprogram { 75 1.1 christos {external 1 flag} 76 1.1 christos {name ddd} 77 1.1 christos {low_pc $ddd_start addr} 78 1.1 christos {high_pc "$ddd_start + $ddd_len" addr} 79 1.1 christos } 80 1.1 christos subprogram { 81 1.1 christos {external 1 flag} 82 1.1 christos {name eee} 83 1.1 christos {low_pc $eee_start addr} 84 1.1 christos {high_pc "$eee_start + $eee_len" addr} 85 1.1 christos } 86 1.1 christos subprogram { 87 1.1 christos {external 1 flag} 88 1.1 christos {name jjj} 89 1.1 christos {low_pc $jjj_start addr} 90 1.1 christos {high_pc "$jjj_start + $jjj_len" addr} 91 1.1 christos } 92 1.1 christos subprogram { 93 1.1 christos {external 1 flag} 94 1.1 christos {name kkk} 95 1.1 christos {low_pc $kkk_start addr} 96 1.1 christos {high_pc "$kkk_start + $kkk_len" addr} 97 1.1 christos } 98 1.1 christos aaa_label: subprogram { 99 1.1 christos {name aaa} 100 1.1 christos {inline 3 data1} 101 1.1 christos } 102 1.1 christos bbb_label: subprogram { 103 1.1 christos {name bbb} 104 1.1 christos {inline 3 data1} 105 1.1 christos } 106 1.1 christos ccc_label: subprogram { 107 1.1 christos {name ccc} 108 1.1 christos {inline 3 data1} 109 1.1 christos } 110 1.1 christos ggg_label: subprogram { 111 1.1 christos {name ggg} 112 1.1 christos {inline 3 data1} 113 1.1 christos } 114 1.1 christos hhh_label: subprogram { 115 1.1 christos {name hhh} 116 1.1 christos {inline 3 data1} 117 1.1 christos } 118 1.1 christos iii_label: subprogram { 119 1.1 christos {name iii} 120 1.1 christos {inline 3 data1} 121 1.1 christos } 122 1.1 christos subprogram { 123 1.1 christos {external 1 flag} 124 1.1 christos {name main} 125 1.1 christos {low_pc $main_start addr} 126 1.1 christos {high_pc "$main_start + $main_len" addr} 127 1.1 christos } { 128 1.1 christos inlined_subroutine { 129 1.1 christos {abstract_origin %$aaa_label} 130 1.1 christos {low_pc main_label2 addr} 131 1.1 christos {high_pc main_label3 addr} 132 1.1 christos {call_file 1 data1} 133 1.1 christos {call_line $call_in_main data1} 134 1.1 christos } { 135 1.1 christos inlined_subroutine { 136 1.1 christos {abstract_origin %$bbb_label} 137 1.1 christos {low_pc main_label2 addr} 138 1.1 christos {high_pc main_label3 addr} 139 1.1 christos {call_file 1 data1} 140 1.1 christos {call_line $call_in_aaa data1} 141 1.1 christos } { 142 1.1 christos inlined_subroutine { 143 1.1 christos {abstract_origin %$ccc_label} 144 1.1 christos {low_pc main_label2 addr} 145 1.1 christos {high_pc main_label3 addr} 146 1.1 christos {call_file 1 data1} 147 1.1 christos {call_line $call_in_bbb data1} 148 1.1 christos } 149 1.1 christos } 150 1.1 christos } 151 1.1 christos } 152 1.1 christos subprogram { 153 1.1 christos {external 1 flag} 154 1.1 christos {name fff} 155 1.1 christos {low_pc $fff_start addr} 156 1.1 christos {high_pc "$fff_start + $fff_len" addr} 157 1.1 christos } { 158 1.1 christos inlined_subroutine { 159 1.1 christos {abstract_origin %$ggg_label} 160 1.1 christos {low_pc fff_label addr} 161 1.1 christos {high_pc main_label2 addr} 162 1.1 christos {call_file 1 data1} 163 1.1 christos {call_line $call_in_fff data1} 164 1.1 christos } { 165 1.1 christos inlined_subroutine { 166 1.1 christos {abstract_origin %$hhh_label} 167 1.1 christos {low_pc fff_label addr} 168 1.1 christos {high_pc fff_label2 addr} 169 1.1 christos {call_file 1 data1} 170 1.1 christos {call_line $call_in_ggg data1} 171 1.1 christos } { 172 1.1 christos inlined_subroutine { 173 1.1 christos {abstract_origin %$iii_label} 174 1.1 christos {low_pc fff_label addr} 175 1.1 christos {high_pc fff_label2 addr} 176 1.1 christos {call_file 1 data1} 177 1.1 christos {call_line $call_in_hhh data1} 178 1.1 christos } 179 1.1 christos } 180 1.1 christos } 181 1.1 christos } 182 1.1 christos } 183 1.1 christos } 184 1.1 christos 185 1.1 christos lines {version 2} lines_label { 186 1.1 christos include_dir "${srcdir}/${subdir}" 187 1.1 christos file_name "$srcfile" 1 188 1.1 christos 189 1.1 christos program { 190 1.1 christos {DW_LNE_set_address $main_start} 191 1.1 christos {line [gdb_get_line_number "main prologue"]} 192 1.1 christos {DW_LNS_copy} 193 1.1 christos {DW_LNE_set_address main_label} 194 1.1 christos {line [gdb_get_line_number "main set global_var"]} 195 1.1 christos {DW_LNS_copy} 196 1.1 christos {DW_LNE_set_address main_label2} 197 1.1 christos {line [gdb_get_line_number "main call aaa"]} 198 1.1 christos {DW_LNS_copy} 199 1.1 christos {DW_LNE_set_address main_label2} 200 1.1 christos {line [gdb_get_line_number "aaa return"]} 201 1.1 christos {DW_LNS_copy} 202 1.1 christos {DW_LNE_set_address main_label2} 203 1.1 christos {line [gdb_get_line_number "bbb return"]} 204 1.1 christos {DW_LNS_copy} 205 1.1 christos {DW_LNE_set_address main_label2} 206 1.1 christos {line [gdb_get_line_number "ccc return"]} 207 1.1 christos {DW_LNS_copy} 208 1.1 christos {DW_LNE_set_address main_label3} 209 1.1 christos {line [gdb_get_line_number "main end"]} 210 1.1 christos {DW_LNS_copy} 211 1.1 christos {DW_LNE_set_address $main_end} 212 1.1 christos {DW_LNE_end_sequence} 213 1.1 christos 214 1.1 christos {DW_LNE_set_address $ddd_start} 215 1.1 christos {line [gdb_get_line_number "ddd prologue"]} 216 1.1 christos {DW_LNS_copy} 217 1.1 christos {DW_LNE_set_address ddd_label} 218 1.1 christos {line [gdb_get_line_number "ddd return"]} 219 1.1 christos {DW_LNS_copy} 220 1.1 christos {DW_LNE_set_address ddd_label2} 221 1.1 christos {line [gdb_get_line_number "ddd end"]} 222 1.1 christos {DW_LNS_copy} 223 1.1 christos {DW_LNE_set_address $ddd_end} 224 1.1 christos {DW_LNE_end_sequence} 225 1.1 christos 226 1.1 christos {DW_LNE_set_address $eee_start} 227 1.1 christos {line [gdb_get_line_number "eee prologue"]} 228 1.1 christos {DW_LNS_copy} 229 1.1 christos {DW_LNE_set_address eee_label} 230 1.1 christos {line [gdb_get_line_number "eee return"]} 231 1.1 christos {DW_LNS_copy} 232 1.1 christos {DW_LNE_set_address eee_label2} 233 1.1 christos {line [gdb_get_line_number "eee end"]} 234 1.1 christos {DW_LNS_copy} 235 1.1 christos {DW_LNE_set_address $eee_end} 236 1.1 christos {DW_LNE_end_sequence} 237 1.1 christos 238 1.1 christos {DW_LNE_set_address $fff_start} 239 1.1 christos {line [gdb_get_line_number "fff prologue"]} 240 1.1 christos {DW_LNS_copy} 241 1.1 christos {DW_LNE_set_address fff_label} 242 1.1 christos {line [gdb_get_line_number "fff return"]} 243 1.1 christos {DW_LNS_copy} 244 1.1 christos {DW_LNE_set_address fff_label} 245 1.1 christos {line [gdb_get_line_number "ggg return"]} 246 1.1 christos {DW_LNS_copy} 247 1.1 christos {DW_LNE_set_address fff_label} 248 1.1 christos {line [gdb_get_line_number "hhh return"]} 249 1.1 christos {DW_LNS_copy} 250 1.1 christos {DW_LNE_set_address fff_label} 251 1.1 christos {line [gdb_get_line_number "iii return"]} 252 1.1 christos {DW_LNS_copy} 253 1.1 christos {DW_LNE_set_address fff_label2} 254 1.1 christos {line [gdb_get_line_number "fff end"]} 255 1.1 christos {DW_LNS_copy} 256 1.1 christos {DW_LNE_set_address $fff_end} 257 1.1 christos {DW_LNE_end_sequence} 258 1.1 christos 259 1.1 christos {DW_LNE_set_address $jjj_start} 260 1.1 christos {line [gdb_get_line_number "jjj prologue"]} 261 1.1 christos {DW_LNS_copy} 262 1.1 christos {DW_LNE_set_address jjj_label} 263 1.1 christos {line [gdb_get_line_number "jjj return"]} 264 1.1 christos {DW_LNS_copy} 265 1.1 christos {DW_LNE_set_address jjj_label2} 266 1.1 christos {line [gdb_get_line_number "jjj end"]} 267 1.1 christos {DW_LNS_copy} 268 1.1 christos {DW_LNE_set_address $jjj_end} 269 1.1 christos {DW_LNE_end_sequence} 270 1.1 christos 271 1.1 christos {DW_LNE_set_address $kkk_start} 272 1.1 christos {line [gdb_get_line_number "kkk prologue"]} 273 1.1 christos {DW_LNS_copy} 274 1.1 christos {DW_LNE_set_address kkk_label} 275 1.1 christos {line [gdb_get_line_number "kkk return"]} 276 1.1 christos {DW_LNS_copy} 277 1.1 christos {DW_LNE_set_address $kkk_end} 278 1.1 christos {DW_LNE_end_sequence} 279 1.1 christos } 280 1.1 christos } 281 1.1 christos 282 1.1 christos ranges {is_64 [is_64_target]} { 283 1.1 christos ranges_label: sequence { 284 1.1 christos {range {${main_start}} ${main_end}} 285 1.1 christos {range {${ddd_start}} ${ddd_end}} 286 1.1 christos {range {${eee_start}} ${eee_end}} 287 1.1 christos {range {${fff_start}} ${fff_end}} 288 1.1 christos {range {${jjj_start}} ${jjj_end}} 289 1.1 christos {range {${kkk_start}} ${kkk_end}} 290 1.1 christos } 291 1.1 christos } 292 1.1 christos } 293 1.1 christos 294 1.1 christos if { [prepare_for_testing "failed to prepare" ${testfile} \ 295 1.1 christos [list $srcfile $asm_file] {nodebug}] } { 296 1.1 christos return -1 297 1.1 christos } 298 1.1 christos 299 1.1 christos if ![runto_main] { 300 1.1 christos return -1 301 1.1 christos } 302 1.1 christos 303 1.1 christos # First we step through all of the functions until we get the 'kkk'. 304 1.1 christos set patterns [list "main call aaa" \ 305 1.1 christos "aaa return" \ 306 1.1 christos "bbb return" \ 307 1.1 christos "ccc return" \ 308 1.1 christos "ddd return" \ 309 1.1 christos "eee return" \ 310 1.1 christos "fff return" \ 311 1.1 christos "ggg return" \ 312 1.1 christos "hhh return" \ 313 1.1 christos "iii return" \ 314 1.1 christos "jjj return" \ 315 1.1 christos "kkk return" ] 316 1.1 christos foreach p $patterns { 317 1.1 christos gdb_test "step" "/\\* $p \\*/" \ 318 1.1 christos "step to '$p'" 319 1.1 christos } 320 1.1 christos 321 1.1 christos # Now check the backtrace. 322 1.1 christos set line_in_main [gdb_get_line_number "main call aaa"] 323 1.1 christos set line_in_aaa [gdb_get_line_number "aaa return"] 324 1.1 christos set line_in_bbb [gdb_get_line_number "bbb return"] 325 1.1 christos set line_in_ccc [gdb_get_line_number "ccc return"] 326 1.1 christos set line_in_ddd [gdb_get_line_number "ddd return"] 327 1.1 christos set line_in_eee [gdb_get_line_number "eee return"] 328 1.1 christos set line_in_fff [gdb_get_line_number "fff return"] 329 1.1 christos set line_in_ggg [gdb_get_line_number "ggg return"] 330 1.1 christos set line_in_hhh [gdb_get_line_number "hhh return"] 331 1.1 christos set line_in_iii [gdb_get_line_number "iii return"] 332 1.1 christos set line_in_jjj [gdb_get_line_number "jjj return"] 333 1.1 christos set line_in_kkk [gdb_get_line_number "kkk return"] 334 1.1 christos 335 1.1 christos gdb_test "bt" [multi_line \ 336 1.1 christos "#0 kkk \\(\\) at \[^\r\n\]+${srcfile}:${line_in_kkk}" \ 337 1.1 christos "#1 $hex in jjj \\(\\) at \[^\r\n\]+${srcfile}:${line_in_jjj}" \ 338 1.1 christos "#2 $hex in iii \\(\\) at \[^\r\n\]+${srcfile}:${line_in_iii}" \ 339 1.1 christos "#3 hhh \\(\\) at \[^\r\n\]+${srcfile}:${line_in_hhh}" \ 340 1.1 christos "#4 ggg \\(\\) at \[^\r\n\]+${srcfile}:${line_in_ggg}" \ 341 1.1 christos "#5 fff \\(\\) at \[^\r\n\]+${srcfile}:${line_in_fff}" \ 342 1.1 christos "#6 $hex in eee \\(\\) at \[^\r\n\]+${srcfile}:${line_in_eee}" \ 343 1.1 christos "#7 $hex in ddd \\(\\) at \[^\r\n\]+${srcfile}:${line_in_ddd}" \ 344 1.1 christos "#8 $hex in ccc \\(\\) at \[^\r\n\]+${srcfile}:${line_in_ccc}" \ 345 1.1 christos "#9 bbb \\(\\) at \[^\r\n\]+${srcfile}:${line_in_bbb}" \ 346 1.1 christos "#10 aaa \\(\\) at \[^\r\n\]+${srcfile}:${line_in_aaa}" \ 347 1.1 christos "#11 main \\(\\) at \[^\r\n\]+${srcfile}:${line_in_main}" ] 348 1.1 christos 349 1.1 christos # Now check we can use 'up' to inspect each frame correctly. 350 1.1 christos set patterns [list \ 351 1.1 christos "jjj return" \ 352 1.1 christos "iii return" \ 353 1.1 christos "hhh return" \ 354 1.1 christos "ggg return" \ 355 1.1 christos "fff return" \ 356 1.1 christos "eee return" \ 357 1.1 christos "ddd return" \ 358 1.1 christos "ccc return" \ 359 1.1 christos "bbb return" \ 360 1.1 christos "aaa return" \ 361 1.1 christos "main call aaa" ] 362 1.1 christos foreach p $patterns { 363 1.1 christos gdb_test "up" "/\\* $p \\*/" \ 364 1.1 christos "up to '$p'" 365 1.1 christos } 366