Home | History | Annotate | Line # | Download | only in gdb.dwarf2
      1  1.1.1.3  christos # Copyright 2019-2024 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.1.3  christos require dwarf2_support
     30      1.1  christos 
     31      1.1  christos # The .c files use __attribute__.
     32  1.1.1.3  christos require is_c_compiler_gcc
     33      1.1  christos 
     34  1.1.1.2  christos standard_testfile .c .S
     35      1.1  christos 
     36      1.1  christos set asm_file [standard_output_file $srcfile2]
     37      1.1  christos Dwarf::assemble $asm_file {
     38      1.1  christos     global srcdir subdir srcfile srcfile2
     39      1.1  christos     declare_labels ranges_label lines_label
     40      1.1  christos     declare_labels aaa_label bbb_label ccc_label
     41      1.1  christos     declare_labels ggg_label hhh_label iii_label
     42      1.1  christos 
     43      1.1  christos     get_func_info main
     44      1.1  christos     get_func_info ddd
     45      1.1  christos     get_func_info eee
     46      1.1  christos     get_func_info fff
     47      1.1  christos     get_func_info jjj
     48      1.1  christos     get_func_info kkk
     49      1.1  christos 
     50      1.1  christos     set call_in_main [gdb_get_line_number "main call aaa"]
     51      1.1  christos     set call_in_aaa [gdb_get_line_number "aaa return"]
     52      1.1  christos     set call_in_bbb [gdb_get_line_number "bbb return"]
     53      1.1  christos     set call_in_ccc [gdb_get_line_number "ccc return"]
     54      1.1  christos     set call_in_fff [gdb_get_line_number "fff return"]
     55      1.1  christos     set call_in_ggg [gdb_get_line_number "ggg return"]
     56      1.1  christos     set call_in_hhh [gdb_get_line_number "hhh return"]
     57      1.1  christos     set call_in_iii [gdb_get_line_number "iii return"]
     58      1.1  christos 
     59      1.1  christos     cu {} {
     60      1.1  christos 	compile_unit {
     61      1.1  christos 	    {language @DW_LANG_C}
     62      1.1  christos 	    {name dw2-inline-stepping.c}
     63      1.1  christos 	    {low_pc 0 addr}
     64      1.1  christos 	    {stmt_list ${lines_label} DW_FORM_sec_offset}
     65      1.1  christos 	    {ranges ${ranges_label} DW_FORM_sec_offset}
     66      1.1  christos 	} {
     67      1.1  christos 	    subprogram {
     68      1.1  christos 		{external 1 flag}
     69      1.1  christos 		{name ddd}
     70      1.1  christos 		{low_pc $ddd_start addr}
     71      1.1  christos 		{high_pc "$ddd_start + $ddd_len" addr}
     72      1.1  christos 	    }
     73      1.1  christos 	    subprogram {
     74      1.1  christos 		{external 1 flag}
     75      1.1  christos 		{name eee}
     76      1.1  christos 		{low_pc $eee_start addr}
     77      1.1  christos 		{high_pc "$eee_start + $eee_len" addr}
     78      1.1  christos 	    }
     79      1.1  christos 	    subprogram {
     80      1.1  christos 		{external 1 flag}
     81      1.1  christos 		{name jjj}
     82      1.1  christos 		{low_pc $jjj_start addr}
     83      1.1  christos 		{high_pc "$jjj_start + $jjj_len" addr}
     84      1.1  christos 	    }
     85      1.1  christos 	    subprogram {
     86      1.1  christos 		{external 1 flag}
     87      1.1  christos 		{name kkk}
     88      1.1  christos 		{low_pc $kkk_start addr}
     89      1.1  christos 		{high_pc "$kkk_start + $kkk_len" addr}
     90      1.1  christos 	    }
     91      1.1  christos 	    aaa_label: subprogram {
     92      1.1  christos 		{name aaa}
     93      1.1  christos 		{inline 3 data1}
     94      1.1  christos 	    }
     95      1.1  christos 	    bbb_label: subprogram {
     96      1.1  christos 		{name bbb}
     97      1.1  christos 		{inline 3 data1}
     98      1.1  christos 	    }
     99      1.1  christos 	    ccc_label: subprogram {
    100      1.1  christos 		{name ccc}
    101      1.1  christos 		{inline 3 data1}
    102      1.1  christos 	    }
    103      1.1  christos 	    ggg_label: subprogram {
    104      1.1  christos 		{name ggg}
    105      1.1  christos 		{inline 3 data1}
    106      1.1  christos 	    }
    107      1.1  christos 	    hhh_label: subprogram {
    108      1.1  christos 		{name hhh}
    109      1.1  christos 		{inline 3 data1}
    110      1.1  christos 	    }
    111      1.1  christos 	    iii_label: subprogram {
    112      1.1  christos 		{name iii}
    113      1.1  christos 		{inline 3 data1}
    114      1.1  christos 	    }
    115      1.1  christos 	    subprogram {
    116      1.1  christos 		{external 1 flag}
    117      1.1  christos 		{name main}
    118      1.1  christos 		{low_pc $main_start addr}
    119      1.1  christos 		{high_pc "$main_start + $main_len" addr}
    120      1.1  christos 	    } {
    121      1.1  christos 		inlined_subroutine {
    122      1.1  christos 		    {abstract_origin %$aaa_label}
    123      1.1  christos 		    {low_pc main_label2 addr}
    124      1.1  christos 		    {high_pc main_label3 addr}
    125      1.1  christos 		    {call_file 1 data1}
    126      1.1  christos 		    {call_line $call_in_main data1}
    127      1.1  christos 		} {
    128      1.1  christos 		    inlined_subroutine {
    129      1.1  christos 			{abstract_origin %$bbb_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_aaa data1}
    134      1.1  christos 		    }  {
    135      1.1  christos 			inlined_subroutine {
    136      1.1  christos 			    {abstract_origin %$ccc_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_bbb data1}
    141      1.1  christos 			}
    142      1.1  christos 		    }
    143      1.1  christos 		}
    144      1.1  christos 	    }
    145      1.1  christos 	    subprogram {
    146      1.1  christos 		{external 1 flag}
    147      1.1  christos 		{name fff}
    148      1.1  christos 		{low_pc $fff_start addr}
    149      1.1  christos 		{high_pc "$fff_start + $fff_len" addr}
    150      1.1  christos 	    }  {
    151      1.1  christos 		inlined_subroutine {
    152      1.1  christos 		    {abstract_origin %$ggg_label}
    153      1.1  christos 		    {low_pc fff_label addr}
    154      1.1  christos 		    {high_pc main_label2 addr}
    155      1.1  christos 		    {call_file 1 data1}
    156      1.1  christos 		    {call_line $call_in_fff data1}
    157      1.1  christos 		} {
    158      1.1  christos 		    inlined_subroutine {
    159      1.1  christos 			{abstract_origin %$hhh_label}
    160      1.1  christos 			{low_pc fff_label addr}
    161      1.1  christos 			{high_pc fff_label2 addr}
    162      1.1  christos 			{call_file 1 data1}
    163      1.1  christos 			{call_line $call_in_ggg data1}
    164      1.1  christos 		    }  {
    165      1.1  christos 			inlined_subroutine {
    166      1.1  christos 			    {abstract_origin %$iii_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_hhh data1}
    171      1.1  christos 			}
    172      1.1  christos 		    }
    173      1.1  christos 		}
    174      1.1  christos 	    }
    175      1.1  christos 	}
    176      1.1  christos     }
    177      1.1  christos 
    178      1.1  christos     lines {version 2} lines_label {
    179      1.1  christos 	include_dir "${srcdir}/${subdir}"
    180      1.1  christos 	file_name "$srcfile" 1
    181      1.1  christos 
    182      1.1  christos 	program {
    183  1.1.1.2  christos 	    DW_LNE_set_address $main_start
    184  1.1.1.2  christos 	    line [gdb_get_line_number "main prologue"]
    185  1.1.1.2  christos 	    DW_LNS_copy
    186  1.1.1.2  christos 	    DW_LNE_set_address main_label
    187  1.1.1.2  christos 	    line [gdb_get_line_number "main set global_var"]
    188  1.1.1.2  christos 	    DW_LNS_copy
    189  1.1.1.2  christos 	    DW_LNE_set_address main_label2
    190  1.1.1.2  christos 	    line [gdb_get_line_number "main call aaa"]
    191  1.1.1.2  christos 	    DW_LNS_copy
    192  1.1.1.2  christos 	    DW_LNE_set_address main_label2
    193  1.1.1.2  christos 	    line [gdb_get_line_number "aaa return"]
    194  1.1.1.2  christos 	    DW_LNS_copy
    195  1.1.1.2  christos 	    DW_LNE_set_address main_label2
    196  1.1.1.2  christos 	    line [gdb_get_line_number "bbb return"]
    197  1.1.1.2  christos 	    DW_LNS_copy
    198  1.1.1.2  christos 	    DW_LNE_set_address main_label2
    199  1.1.1.2  christos 	    line [gdb_get_line_number "ccc return"]
    200  1.1.1.2  christos 	    DW_LNS_copy
    201  1.1.1.2  christos 	    DW_LNE_set_address main_label3
    202  1.1.1.2  christos 	    line [gdb_get_line_number "main end"]
    203  1.1.1.2  christos 	    DW_LNS_copy
    204  1.1.1.2  christos 	    DW_LNE_set_address $main_end
    205  1.1.1.2  christos 	    DW_LNE_end_sequence
    206  1.1.1.2  christos 
    207  1.1.1.2  christos 	    DW_LNE_set_address $ddd_start
    208  1.1.1.2  christos 	    line [gdb_get_line_number "ddd prologue"]
    209  1.1.1.2  christos 	    DW_LNS_copy
    210  1.1.1.2  christos 	    DW_LNE_set_address ddd_label
    211  1.1.1.2  christos 	    line [gdb_get_line_number "ddd return"]
    212  1.1.1.2  christos 	    DW_LNS_copy
    213  1.1.1.2  christos 	    DW_LNE_set_address ddd_label2
    214  1.1.1.2  christos 	    line [gdb_get_line_number "ddd end"]
    215  1.1.1.2  christos 	    DW_LNS_copy
    216  1.1.1.2  christos 	    DW_LNE_set_address $ddd_end
    217  1.1.1.2  christos 	    DW_LNE_end_sequence
    218  1.1.1.2  christos 
    219  1.1.1.2  christos 	    DW_LNE_set_address $eee_start
    220  1.1.1.2  christos 	    line [gdb_get_line_number "eee prologue"]
    221  1.1.1.2  christos 	    DW_LNS_copy
    222  1.1.1.2  christos 	    DW_LNE_set_address eee_label
    223  1.1.1.2  christos 	    line [gdb_get_line_number "eee return"]
    224  1.1.1.2  christos 	    DW_LNS_copy
    225  1.1.1.2  christos 	    DW_LNE_set_address eee_label2
    226  1.1.1.2  christos 	    line [gdb_get_line_number "eee end"]
    227  1.1.1.2  christos 	    DW_LNS_copy
    228  1.1.1.2  christos 	    DW_LNE_set_address $eee_end
    229  1.1.1.2  christos 	    DW_LNE_end_sequence
    230  1.1.1.2  christos 
    231  1.1.1.2  christos 	    DW_LNE_set_address $fff_start
    232  1.1.1.2  christos 	    line [gdb_get_line_number "fff prologue"]
    233  1.1.1.2  christos 	    DW_LNS_copy
    234  1.1.1.2  christos 	    DW_LNE_set_address fff_label
    235  1.1.1.2  christos 	    line [gdb_get_line_number "fff return"]
    236  1.1.1.2  christos 	    DW_LNS_copy
    237  1.1.1.2  christos 	    DW_LNE_set_address fff_label
    238  1.1.1.2  christos 	    line [gdb_get_line_number "ggg return"]
    239  1.1.1.2  christos 	    DW_LNS_copy
    240  1.1.1.2  christos 	    DW_LNE_set_address fff_label
    241  1.1.1.2  christos 	    line [gdb_get_line_number "hhh return"]
    242  1.1.1.2  christos 	    DW_LNS_copy
    243  1.1.1.2  christos 	    DW_LNE_set_address fff_label
    244  1.1.1.2  christos 	    line [gdb_get_line_number "iii return"]
    245  1.1.1.2  christos 	    DW_LNS_copy
    246  1.1.1.2  christos 	    DW_LNE_set_address fff_label2
    247  1.1.1.2  christos 	    line [gdb_get_line_number "fff end"]
    248  1.1.1.2  christos 	    DW_LNS_copy
    249  1.1.1.2  christos 	    DW_LNE_set_address $fff_end
    250  1.1.1.2  christos 	    DW_LNE_end_sequence
    251  1.1.1.2  christos 
    252  1.1.1.2  christos 	    DW_LNE_set_address $jjj_start
    253  1.1.1.2  christos 	    line [gdb_get_line_number "jjj prologue"]
    254  1.1.1.2  christos 	    DW_LNS_copy
    255  1.1.1.2  christos 	    DW_LNE_set_address jjj_label
    256  1.1.1.2  christos 	    line [gdb_get_line_number "jjj return"]
    257  1.1.1.2  christos 	    DW_LNS_copy
    258  1.1.1.2  christos 	    DW_LNE_set_address jjj_label2
    259  1.1.1.2  christos 	    line [gdb_get_line_number "jjj end"]
    260  1.1.1.2  christos 	    DW_LNS_copy
    261  1.1.1.2  christos 	    DW_LNE_set_address $jjj_end
    262  1.1.1.2  christos 	    DW_LNE_end_sequence
    263  1.1.1.2  christos 
    264  1.1.1.2  christos 	    DW_LNE_set_address $kkk_start
    265  1.1.1.2  christos 	    line [gdb_get_line_number "kkk prologue"]
    266  1.1.1.2  christos 	    DW_LNS_copy
    267  1.1.1.2  christos 	    DW_LNE_set_address kkk_label
    268  1.1.1.2  christos 	    line [gdb_get_line_number "kkk return"]
    269  1.1.1.2  christos 	    DW_LNS_copy
    270  1.1.1.2  christos 	    DW_LNE_set_address $kkk_end
    271  1.1.1.2  christos 	    DW_LNE_end_sequence
    272      1.1  christos 	}
    273      1.1  christos     }
    274      1.1  christos 
    275      1.1  christos     ranges {is_64 [is_64_target]} {
    276      1.1  christos 	ranges_label: sequence {
    277  1.1.1.2  christos 	    range ${main_start} ${main_end}
    278  1.1.1.2  christos 	    range ${ddd_start} ${ddd_end}
    279  1.1.1.2  christos 	    range ${eee_start} ${eee_end}
    280  1.1.1.2  christos 	    range ${fff_start} ${fff_end}
    281  1.1.1.2  christos 	    range ${jjj_start} ${jjj_end}
    282  1.1.1.2  christos 	    range ${kkk_start} ${kkk_end}
    283      1.1  christos 	}
    284      1.1  christos     }
    285      1.1  christos }
    286      1.1  christos 
    287      1.1  christos if { [prepare_for_testing "failed to prepare" ${testfile} \
    288      1.1  christos 	  [list $srcfile $asm_file] {nodebug}] } {
    289      1.1  christos     return -1
    290      1.1  christos }
    291      1.1  christos 
    292      1.1  christos if ![runto_main] {
    293      1.1  christos     return -1
    294      1.1  christos }
    295      1.1  christos 
    296      1.1  christos # First we step through all of the functions until we get the 'kkk'.
    297      1.1  christos set patterns [list "main call aaa" \
    298      1.1  christos 		  "aaa return" \
    299      1.1  christos 		  "bbb return" \
    300      1.1  christos 		  "ccc return" \
    301      1.1  christos 		  "ddd return" \
    302      1.1  christos 		  "eee return" \
    303      1.1  christos 		  "fff return" \
    304      1.1  christos 		  "ggg return" \
    305      1.1  christos 		  "hhh return" \
    306      1.1  christos 		  "iii return" \
    307      1.1  christos 		  "jjj return" \
    308      1.1  christos 		  "kkk return" ]
    309      1.1  christos foreach p $patterns {
    310      1.1  christos     gdb_test "step" "/\\* $p \\*/" \
    311      1.1  christos 	"step to '$p'"
    312      1.1  christos }
    313      1.1  christos 
    314      1.1  christos # Now check the backtrace.
    315      1.1  christos set line_in_main [gdb_get_line_number "main call aaa"]
    316      1.1  christos set line_in_aaa [gdb_get_line_number "aaa return"]
    317      1.1  christos set line_in_bbb [gdb_get_line_number "bbb return"]
    318      1.1  christos set line_in_ccc [gdb_get_line_number "ccc return"]
    319      1.1  christos set line_in_ddd [gdb_get_line_number "ddd return"]
    320      1.1  christos set line_in_eee [gdb_get_line_number "eee return"]
    321      1.1  christos set line_in_fff [gdb_get_line_number "fff return"]
    322      1.1  christos set line_in_ggg [gdb_get_line_number "ggg return"]
    323      1.1  christos set line_in_hhh [gdb_get_line_number "hhh return"]
    324      1.1  christos set line_in_iii [gdb_get_line_number "iii return"]
    325      1.1  christos set line_in_jjj [gdb_get_line_number "jjj return"]
    326      1.1  christos set line_in_kkk [gdb_get_line_number "kkk return"]
    327      1.1  christos 
    328      1.1  christos gdb_test "bt" [multi_line \
    329      1.1  christos 		   "#0  kkk \\(\\) at \[^\r\n\]+${srcfile}:${line_in_kkk}" \
    330      1.1  christos 		   "#1  $hex in jjj \\(\\) at \[^\r\n\]+${srcfile}:${line_in_jjj}" \
    331      1.1  christos 		   "#2  $hex in iii \\(\\) at \[^\r\n\]+${srcfile}:${line_in_iii}" \
    332      1.1  christos 		   "#3  hhh \\(\\) at \[^\r\n\]+${srcfile}:${line_in_hhh}" \
    333      1.1  christos 		   "#4  ggg \\(\\) at \[^\r\n\]+${srcfile}:${line_in_ggg}" \
    334      1.1  christos 		   "#5  fff \\(\\) at \[^\r\n\]+${srcfile}:${line_in_fff}" \
    335      1.1  christos 		   "#6  $hex in eee \\(\\) at \[^\r\n\]+${srcfile}:${line_in_eee}" \
    336      1.1  christos 		   "#7  $hex in ddd \\(\\) at \[^\r\n\]+${srcfile}:${line_in_ddd}" \
    337      1.1  christos 		   "#8  $hex in ccc \\(\\) at \[^\r\n\]+${srcfile}:${line_in_ccc}" \
    338      1.1  christos 		   "#9  bbb \\(\\) at \[^\r\n\]+${srcfile}:${line_in_bbb}" \
    339      1.1  christos 		   "#10 aaa \\(\\) at \[^\r\n\]+${srcfile}:${line_in_aaa}" \
    340      1.1  christos 		   "#11 main \\(\\) at \[^\r\n\]+${srcfile}:${line_in_main}" ]
    341      1.1  christos 
    342      1.1  christos # Now check we can use 'up' to inspect each frame correctly.
    343      1.1  christos set patterns [list  \
    344      1.1  christos 		  "jjj return" \
    345      1.1  christos 		  "iii return" \
    346      1.1  christos 		  "hhh return" \
    347      1.1  christos 		  "ggg return" \
    348      1.1  christos 		  "fff return" \
    349      1.1  christos 		  "eee return" \
    350      1.1  christos 		  "ddd return" \
    351      1.1  christos 		  "ccc return" \
    352      1.1  christos 		  "bbb return" \
    353      1.1  christos 		  "aaa return" \
    354      1.1  christos 		  "main call aaa" ]
    355      1.1  christos foreach p $patterns {
    356      1.1  christos     gdb_test "up" "/\\* $p \\*/" \
    357      1.1  christos 	"up to '$p'"
    358      1.1  christos }
    359