Home | History | Annotate | Line # | Download | only in gdb.dwarf2
      1 # Copyright 2023-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 dw2-lines.c -dw2.S
     24 
     25 with_shared_gdb {
     26     set func_info_vars [get_func_info bar]
     27 }
     28 
     29 # Helper function.
     30 proc line_for { l } {
     31     global srcfile
     32     set line [gdb_get_line_number "$l:" $srcfile]
     33     return [expr $line + 1]
     34 }
     35 
     36 set asm_file [standard_output_file $srcfile2]
     37 Dwarf::assemble $asm_file {
     38     declare_labels Llines
     39     global srcdir subdir srcfile objdir
     40     global func_info_vars
     41     foreach var $func_info_vars {
     42 	global $var
     43     }
     44 
     45     cu { version 5 } {
     46 	compile_unit {
     47 	    {language @DW_LANG_Mips_Assembler}
     48 	    {name $srcfile}
     49 	    {comp_dir $objdir}
     50 	    {stmt_list $Llines DW_FORM_sec_offset}
     51 	    {producer "GNU AS 2.35.2"}
     52 	} {
     53 	    subprogram {
     54 		{external 1 flag}
     55 		{name bar}
     56 		{low_pc $bar_start addr}
     57 		{high_pc "$bar_start + $bar_len" addr}
     58 	    }
     59 	}
     60     }
     61 
     62     lines [list version 5] Llines {
     63 	set diridx1 [include_dir "${srcdir}/${subdir}"]
     64 	set diridx2 [include_dir "${srcdir}/${subdir}"]
     65 	file_name "$srcfile" $diridx1
     66 	file_name "$srcfile" $diridx2
     67 
     68 	program {
     69 	    DW_LNE_set_address bar_label
     70 	    line [line_for bar_label]
     71 	    DW_LNS_copy
     72 
     73 	    DW_LNE_set_address $bar_end
     74 	    DW_LNE_end_sequence
     75 	}
     76     }
     77 }
     78 
     79 if { [prepare_for_testing "failed to prepare" ${testfile} \
     80 	  [list $srcfile $asm_file] {nodebug}] } {
     81     return -1
     82 }
     83 
     84 gdb_test_no_output "set debug symtab-create 1"
     85 gdb_test_multiple "ptype bar" "" {
     86     -re -wrap "name_for_id = $objdir/$srcfile\r\n.*" {
     87 	fail $gdb_test_name
     88     }
     89     -re -wrap "" {
     90 	pass $gdb_test_name
     91     }
     92 }
     93