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