Home | History | Annotate | Line # | Download | only in gdb.dwarf2
dw2-lines.exp revision 1.1.1.2
      1 # Copyright 2021-2024 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 # Test line number information in various configurations.
     17 
     18 load_lib dwarf.exp
     19 
     20 # This test can only be run on targets which support DWARF-2 and use gas.
     21 require dwarf2_support
     22 
     23 standard_testfile .c
     24 
     25 with_shared_gdb {
     26     set func_info_vars \
     27 	[concat \
     28 	     [get_func_info main] \
     29 	     [get_func_info bar]]
     30 }
     31 
     32 # Helper function.
     33 proc line_for { l } {
     34     global srcfile
     35     set line [gdb_get_line_number "$l:" $srcfile]
     36     return [expr $line + 1]
     37 }
     38 
     39 # Execute test.
     40 proc test_1 { _cv _cdw64 _lv _ldw64 {_string_form ""}} {
     41     global srcfile srcfile2 testfile
     42     global cv cdw64 lv ldw64 string_form
     43     set cv $_cv
     44     set cdw64 $_cdw64
     45     set lv $_lv
     46     set ldw64 $_ldw64
     47     set string_form $_string_form
     48 
     49     standard_testfile .c [prefix_id]-dw.S
     50 
     51     set asm_file [standard_output_file $srcfile2]
     52     Dwarf::assemble $asm_file {
     53 	declare_labels Llines
     54 	global srcdir subdir srcfile cv cdw64 lv ldw64 string_form
     55 	global func_info_vars
     56 	foreach var $func_info_vars {
     57 	    global $var
     58 	}
     59 
     60 	cu { version $cv is_64 $cdw64 } {
     61 	    compile_unit {
     62 		{language @DW_LANG_C}
     63 		{name $srcfile}
     64 		{stmt_list $Llines DW_FORM_sec_offset}
     65 	    } {
     66 		subprogram {
     67 		    {external 1 flag}
     68 		    {name main}
     69 		    {low_pc $main_start addr}
     70 		    {high_pc "$main_start + $main_len" addr}
     71 		}
     72 		subprogram {
     73 		    {external 1 flag}
     74 		    {name bar}
     75 		    {low_pc $bar_start addr}
     76 		    {high_pc "$bar_start + $bar_len" addr}
     77 		}
     78 	    }
     79 	}
     80 
     81 	lines [list version $lv is_64 $ldw64 string_form $string_form] Llines {
     82 	    set diridx [include_dir "${srcdir}/${subdir}"]
     83 	    file_name "$srcfile" $diridx
     84 
     85 	    program {
     86 		# If using DWARF 5, we want to refer to file 0, but the LNP
     87 		# state machine is still initialized with file 1.  So we need
     88 		# to set the current file explicitly.
     89 		DW_LNS_set_file $diridx
     90 
     91 		DW_LNE_set_address bar_label
     92 		line [line_for bar_label]
     93 		DW_LNS_copy
     94 
     95 		DW_LNE_set_address bar_label_2
     96 		line [line_for bar_label_2]
     97 		DW_LNS_copy
     98 
     99 		DW_LNE_set_address bar_label_3
    100 		line [line_for bar_label_3]
    101 		DW_LNS_copy
    102 
    103 		DW_LNE_set_address bar_label_4
    104 		line [line_for bar_label_4]
    105 		DW_LNS_copy
    106 
    107 		DW_LNE_set_address "$bar_start + $bar_len"
    108 		DW_LNE_end_sequence
    109 	    }
    110 	}
    111     }
    112 
    113     if { [prepare_for_testing "failed to prepare" ${testfile}.[prefix_id] \
    114 	      [list $srcfile $asm_file] {nodebug}] } {
    115 	return -1
    116     }
    117 
    118     if ![runto_main] {
    119 	return -1
    120     }
    121 
    122     gdb_breakpoint "bar_label"
    123     gdb_continue_to_breakpoint "foo \\(1\\)"
    124 
    125     gdb_test "next" "foo \\(2\\).*" "next to foo (2)"
    126     gdb_test "next" "foo \\(3\\).*" "next to foo (3)"
    127     gdb_test "next" "foo \\(4\\).*" "next to foo (4)"
    128 }
    129 
    130 
    131 # Add unique test prefix.
    132 proc test { cv cdw64 lv ldw64 {string_form ""}} {
    133     with_test_prefix cv=$cv {
    134 	with_test_prefix cdw=[expr $cdw64 ? 64 : 32] {
    135 	    with_test_prefix lv=$lv {
    136 		with_test_prefix ldw=[expr $ldw64 ? 64 : 32] {
    137 		    if { $string_form == "" } {
    138 			test_1 $cv $cdw64 $lv $ldw64
    139 		    } else {
    140 			with_test_prefix string_form=$string_form {
    141 			    test_1 $cv $cdw64 $lv $ldw64 $string_form
    142 			}
    143 		    }
    144 		}
    145 	    }
    146 	}
    147     }
    148 }
    149 
    150 set cv_low 2
    151 set cv_high 4
    152 
    153 set lv_low 2
    154 set lv_high 4
    155 
    156 for { set cv $cv_low } { $cv <= $cv_high } { incr cv } {
    157     for { set lv $lv_low } { $lv <= $lv_high } { incr lv } {
    158 	# I'm not sure if it makes sense to have a dwarf vx CU with
    159 	# a dwarf vx+1 line unit.
    160 	if { $lv > $lv } {
    161 	    continue
    162 	}
    163 
    164 	foreach cdw64 { 0 1 } {
    165 	    foreach ldw64 { 0 1 } {
    166 		test $cv $cdw64 $lv $ldw64
    167 	    }
    168 	}
    169     }
    170 }
    171 
    172 foreach cdw64 { 0 1 } {
    173     foreach ldw64 { 0 1 } {
    174 	test 5 $cdw64 5 $ldw64 string
    175 	test 5 $cdw64 5 $ldw64 line_strp
    176     }
    177 }
    178