Home | History | Annotate | Line # | Download | only in gdb.dwarf2
      1 # Copyright 2020-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 # Setup a line table where:
     17 #
     18 # | Addr | File | Line | Stmt | Inline |
     19 # |------|------|------|------|--------|
     20 # | 1    | 1    | 16   | Y    |        |
     21 # | 2    | 1    | 17   | Y    |        |
     22 # | 3    | 2    | 21   | Y    | X      |
     23 # | 4    | 2    | 22   | Y    | X      |
     24 # | 4    | 1    | 18   | N    | X      |
     25 # | 5    | 1    | 19   | Y    |        |
     26 # | 6    | 1    | 20   | Y    |        |
     27 # | 7    | 1    | END  | Y    |        |
     28 # |------|------|------|------|--------|
     29 #
     30 #
     31 # Place the first brekpoint at file 2, line 22 and a second breakpoint
     32 # at file 1, line 19.  A third breakpoint is placed at file 1, line
     33 # 18, but as this line table entry will have been discarded[1] the
     34 # third breakpoint will actually be placed at the same location as the
     35 # second breakpoint.
     36 #
     37 # This test is designed to test GDB's internal behavior with respect
     38 # to discarding particular line table entries.  GCC and DWARF are
     39 # starting to introduce the idea of line table views.  As the views
     40 # information becomes better supported within GDB it is likely that
     41 # this will become out of date.  This is fine, the test will have
     42 # served its purpose by that point and can be deleted.
     43 #
     44 # [1] The entry for file 1, line 18 is discarded because it is at the
     45 # same address as the previous entry, but the previous entry is-stmt,
     46 # while line 18 is a non-stmt.
     47 
     48 load_lib dwarf.exp
     49 
     50 # This test can only be run on targets which support DWARF-2 and use gas.
     51 require dwarf2_support
     52 
     53 # The .c files use __attribute__.
     54 require is_c_compiler_gcc
     55 
     56 standard_testfile dw2-inline-header-lbls.c dw2-inline-header.S \
     57     dw2-inline-header.c dw2-inline-header.h
     58 
     59 set build_options {nodebug optimize=-O1}
     60 
     61 set asm_file [standard_output_file $srcfile2]
     62 Dwarf::assemble $asm_file {
     63     global srcdir subdir srcfile srcfile3 srcfile4
     64     global build_options
     65     declare_labels lines_label callee_subprog_label
     66 
     67     get_func_info main $build_options
     68 
     69     cu {} {
     70 	compile_unit {
     71 	    {producer "gcc" }
     72 	    {language @DW_LANG_C}
     73 	    {name ${srcfile3}}
     74 	    {low_pc 0 addr}
     75 	    {stmt_list ${lines_label} DW_FORM_sec_offset}
     76 	} {
     77 	    callee_subprog_label: subprogram {
     78 		{external 1 flag}
     79 		{name callee}
     80 		{inline 3 data1}
     81 	    }
     82 	    subprogram {
     83 		{external 1 flag}
     84 		{name main}
     85 		{low_pc $main_start addr}
     86 		{high_pc "$main_start + $main_len" addr}
     87 	    } {
     88 		inlined_subroutine {
     89 		    {abstract_origin %$callee_subprog_label}
     90 		    {low_pc line_label_3 addr}
     91 		    {high_pc line_label_5 addr}
     92 		    {call_file 1 data1}
     93 		    {call_line 18 data1}
     94 		}
     95 	    }
     96 	}
     97     }
     98 
     99     lines {version 2 default_is_stmt 1} lines_label {
    100 	include_dir "${srcdir}/${subdir}"
    101 	file_name "$srcfile3" 1
    102 	file_name "$srcfile4" 1
    103 
    104 	program {
    105 	    DW_LNE_set_address line_label_1
    106 	    DW_LNS_advance_line 15
    107 	    DW_LNS_copy
    108 
    109 	    DW_LNE_set_address line_label_2
    110 	    DW_LNS_advance_line 1
    111 	    DW_LNS_copy
    112 
    113 	    DW_LNS_set_file 2
    114 	    DW_LNE_set_address line_label_3
    115 	    DW_LNS_advance_line 4
    116 	    DW_LNS_copy
    117 
    118 	    DW_LNE_set_address line_label_4
    119 	    DW_LNS_advance_line 1
    120 	    DW_LNS_copy
    121 
    122 	    DW_LNS_advance_pc 0
    123 	    DW_LNS_advance_line -4
    124 	    DW_LNS_set_file 1
    125 	    DW_LNS_negate_stmt
    126 	    DW_LNS_copy
    127 
    128 	    DW_LNE_set_address line_label_5
    129 	    DW_LNS_advance_line 1
    130 	    DW_LNS_negate_stmt
    131 	    DW_LNS_copy
    132 
    133 	    DW_LNE_set_address line_label_6
    134 	    DW_LNS_advance_line 1
    135 	    DW_LNS_copy
    136 
    137 	    DW_LNE_set_address "$main_start + $main_len"
    138 	    DW_LNE_end_sequence
    139 	}
    140     }
    141 }
    142 
    143 if { [prepare_for_testing "failed to prepare" ${testfile} \
    144 	  [list $srcfile $asm_file] $build_options] } {
    145     return -1
    146 }
    147 
    148 if ![runto_main] {
    149     return -1
    150 }
    151 
    152 # Delete all breakpoints, watchpoints, tracepoints, and catchpoints so that
    153 # the output of "info breakpoints" below will only contain a single breakpoint.
    154 delete_breakpoints
    155 
    156 # Place a breakpoint within the function in the header file.
    157 gdb_breakpoint "${srcfile4}:22"
    158 
    159 # Check that the breakpoint was placed where we expected.  It should
    160 # appear at the requested line.  When the bug in GDB was present the
    161 # breakpoint would be placed on one of the following lines instead.
    162 gdb_test "info breakpoints" \
    163     ".* in callee at \[^\r\n\]+${srcfile4}:22\\y.*" \
    164     "check for breakpoint at ${srcfile4}"
    165 
    166 # Delete all breakpoints, watchpoints, tracepoints, and catchpoints so that
    167 # the output of "info breakpoints" below will only contain a single breakpoint.
    168 delete_breakpoints
    169 
    170 # Place a breakpoint within the function in the header file.
    171 gdb_breakpoint "${srcfile3}:19"
    172 
    173 # Check that the breakpoint was placed where we expected.  It should
    174 # appear at the requested line.  When the bug in GDB was present the
    175 # breakpoint would be placed on one of the following lines instead.
    176 gdb_test "info breakpoints" \
    177     ".* in main at \[^\r\n\]+${srcfile3}:19\\y.*" \
    178     "check for breakpoint at ${srcfile3}"
    179 
    180 # Line table entry for line 18 will have been discarded, so this
    181 # brekpoint will be at the same location as line 19.
    182 gdb_test "break ${srcfile3}:18" \
    183     "Note: breakpoint $decimal also set at pc $hex.*"
    184