Home | History | Annotate | Line # | Download | only in gdb.dwarf2
dw2-lines.exp revision 1.1.1.3
      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_start
     92 		line [line_for bar]
     93 		DW_LNS_copy
     94 
     95 		DW_LNE_set_address bar_label
     96 		line [line_for bar_label]
     97 		DW_LNS_copy
     98 
     99 		DW_LNE_set_address bar_label_2
    100 		line [line_for bar_label_2]
    101 		DW_LNS_copy
    102 
    103 		DW_LNE_set_address bar_label_3
    104 		line [line_for bar_label_3]
    105 		DW_LNS_copy
    106 
    107 		DW_LNE_set_address bar_label_4
    108 		line [line_for bar_label_4]
    109 		DW_LNS_copy
    110 
    111 		DW_LNE_set_address "$bar_start + $bar_len"
    112 		DW_LNE_end_sequence
    113 	    }
    114 	}
    115     }
    116 
    117     if { [prepare_for_testing "failed to prepare" ${testfile}.[prefix_id] \
    118 	      [list $srcfile $asm_file] {nodebug}] } {
    119 	return -1
    120     }
    121 
    122     if ![runto_main] {
    123 	return -1
    124     }
    125 
    126     gdb_breakpoint "bar_label"
    127     gdb_continue_to_breakpoint "foo \\(1\\)"
    128 
    129     gdb_test "next" "foo \\(2\\).*" "next to foo(2)"
    130     gdb_test "next" "foo \\(3\\).*" "next to foo(3)"
    131     gdb_test "next" "foo \\(4\\).*" "next to foo(4)"
    132 }
    133 
    134 
    135 # Add unique test prefix.
    136 proc test { cv cdw64 lv ldw64 {string_form ""}} {
    137     with_test_prefix cv=$cv {
    138 	with_test_prefix cdw=[expr $cdw64 ? 64 : 32] {
    139 	    with_test_prefix lv=$lv {
    140 		with_test_prefix ldw=[expr $ldw64 ? 64 : 32] {
    141 		    if { $string_form == "" } {
    142 			test_1 $cv $cdw64 $lv $ldw64
    143 		    } else {
    144 			with_test_prefix string_form=$string_form {
    145 			    test_1 $cv $cdw64 $lv $ldw64 $string_form
    146 			}
    147 		    }
    148 		}
    149 	    }
    150 	}
    151     }
    152 }
    153 
    154 set cv_low 2
    155 set cv_high 4
    156 
    157 set lv_low 2
    158 set lv_high 4
    159 
    160 for { set cv $cv_low } { $cv <= $cv_high } { incr cv } {
    161     for { set lv $lv_low } { $lv <= $lv_high } { incr lv } {
    162 	# I'm not sure if it makes sense to have a dwarf vx CU with
    163 	# a dwarf vx+1 line unit.
    164 	if { $lv > $lv } {
    165 	    continue
    166 	}
    167 
    168 	foreach cdw64 { 0 1 } {
    169 	    foreach ldw64 { 0 1 } {
    170 		test $cv $cdw64 $lv $ldw64
    171 	    }
    172 	}
    173     }
    174 }
    175 
    176 foreach cdw64 { 0 1 } {
    177     foreach ldw64 { 0 1 } {
    178 	test 5 $cdw64 5 $ldw64 string
    179 	test 5 $cdw64 5 $ldw64 line_strp
    180     }
    181 }
    182