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