Home | History | Annotate | Line # | Download | only in gdb.dwarf2
      1  1.1.1.2  christos # Copyright 2023-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 # Check that prologue analysis in foo is correct in the presence of a
     17      1.1  christos # prologue_end marker in immediately following function bar.
     18      1.1  christos 
     19      1.1  christos load_lib dwarf.exp
     20      1.1  christos 
     21      1.1  christos # This test can only be run on targets which support DWARF-2 and use gas.
     22  1.1.1.2  christos require dwarf2_support
     23      1.1  christos 
     24      1.1  christos standard_testfile .c .S
     25      1.1  christos 
     26      1.1  christos set asm_file [standard_output_file $srcfile2]
     27      1.1  christos Dwarf::assemble $asm_file {
     28      1.1  christos     global srcdir subdir srcfile srcfile2
     29      1.1  christos     declare_labels lines_label
     30      1.1  christos 
     31      1.1  christos     cu {} {
     32      1.1  christos 	compile_unit {
     33      1.1  christos 	    {language @DW_LANG_C}
     34      1.1  christos 	    {name dw2-prologue-end.c}
     35      1.1  christos 	    {stmt_list ${lines_label} DW_FORM_sec_offset}
     36      1.1  christos 	} {
     37      1.1  christos 	    subprogram {
     38      1.1  christos 		{external 1 flag}
     39      1.1  christos 		{name foo}
     40      1.1  christos 		{low_pc foo_label addr}
     41      1.1  christos 		{high_pc foo_end addr}
     42      1.1  christos 	    }
     43      1.1  christos 	    subprogram {
     44      1.1  christos 		{external 1 flag}
     45      1.1  christos 		{name bar}
     46      1.1  christos 		{low_pc bar_label addr}
     47      1.1  christos 		{high_pc bar_end addr}
     48      1.1  christos 	    }
     49      1.1  christos 	}
     50      1.1  christos     }
     51      1.1  christos 
     52      1.1  christos     lines {version 5} lines_label {
     53      1.1  christos 	set diridx [include_dir "${srcdir}/${subdir}"]
     54      1.1  christos 	file_name "$srcfile" $diridx
     55      1.1  christos 
     56      1.1  christos 	program {
     57      1.1  christos 	    DW_LNS_set_file $diridx
     58      1.1  christos 
     59      1.1  christos 	    DW_LNE_set_address foo_label
     60      1.1  christos 	    line [gdb_get_line_number "Foo body"]
     61      1.1  christos 	    DW_LNS_copy
     62      1.1  christos 
     63      1.1  christos 	    DW_LNE_set_address bar_label
     64      1.1  christos 	    DW_LNS_set_prologue_end
     65      1.1  christos 	    line [gdb_get_line_number "Bar body"]
     66      1.1  christos 	    DW_LNS_copy
     67      1.1  christos 
     68      1.1  christos 	    DW_LNE_set_address bar_end
     69      1.1  christos 	    DW_LNE_end_sequence
     70      1.1  christos 	}
     71      1.1  christos     }
     72      1.1  christos }
     73      1.1  christos 
     74      1.1  christos if { [prepare_for_testing "failed to prepare" ${testfile} \
     75      1.1  christos 	  [list $srcfile $asm_file] {nodebug}] } {
     76      1.1  christos     return -1
     77      1.1  christos }
     78      1.1  christos 
     79      1.1  christos # Don't runto main here, otherwise the following doesn't
     80      1.1  christos # function as regression test for PR30369.
     81      1.1  christos 
     82      1.1  christos # Get the "break foo" address.
     83      1.1  christos 
     84      1.1  christos set break_addr ""
     85      1.1  christos gdb_test_multiple "break foo" "" {
     86      1.1  christos     -re -wrap "at ($hex):\[^\r\n\]*" {
     87      1.1  christos 	set break_addr $expect_out(1,string)
     88      1.1  christos 	pass $gdb_test_name
     89      1.1  christos     }
     90      1.1  christos }
     91      1.1  christos 
     92      1.1  christos if { $break_addr == "" } {
     93      1.1  christos     return
     94      1.1  christos }
     95      1.1  christos 
     96  1.1.1.2  christos # Get the "bar_label" address.
     97      1.1  christos 
     98  1.1.1.2  christos set bar_label_addr ""
     99  1.1.1.2  christos gdb_test_multiple "print /x &bar_label" "" {
    100      1.1  christos     -re -wrap "= ($hex)" {
    101  1.1.1.2  christos 	set bar_label_addr $expect_out(1,string)
    102      1.1  christos 	pass $gdb_test_name
    103      1.1  christos     }
    104      1.1  christos }
    105      1.1  christos 
    106  1.1.1.2  christos if { $bar_label_addr == "" } {
    107      1.1  christos     return
    108      1.1  christos }
    109      1.1  christos 
    110      1.1  christos # Check that bar immediately follows foo.  Otherwise the following doesn't
    111      1.1  christos # function as regression test for PR30369.
    112      1.1  christos 
    113      1.1  christos gdb_test "print &foo_end == &bar_label" " = 1"
    114      1.1  christos 
    115      1.1  christos # Check that the breakpoint is set at the expected address.  Regression test
    116      1.1  christos # for PR30369.
    117      1.1  christos 
    118  1.1.1.2  christos gdb_assert { $break_addr < $bar_label_addr }
    119