xref: /netbsd-src/external/gpl3/gdb.old/dist/gdb/testsuite/gdb.dwarf2/dw2-prologue-end.exp (revision 8e33eff89e26cf71871ead62f0d5063e1313c33a)
1# Copyright 2022-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 GDB can honor the prologue_end flag the compiler can place
17# in the line-table data.
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    get_func_info main
34
35    cu {} {
36	compile_unit {
37	    {language @DW_LANG_C}
38	    {name dw2-prologue-end.c}
39	    {stmt_list ${lines_label} DW_FORM_sec_offset}
40	} {
41	    subprogram {
42		{external 1 flag}
43		{name main}
44		{low_pc $main_start addr}
45		{high_pc "$main_start + $main_len" addr}
46	    }
47	}
48    }
49
50    lines {version 5} lines_label {
51	set diridx [include_dir "${srcdir}/${subdir}"]
52	file_name "$srcfile" $diridx
53
54	program {
55	    DW_LNS_set_file $diridx
56	    DW_LNE_set_address $main_start
57	    line [gdb_get_line_number "main prologue"]
58	    DW_LNS_copy
59
60	    DW_LNE_set_address main_label
61	    line [gdb_get_line_number "main assign m"]
62	    DW_LNS_copy
63
64	    DW_LNE_set_address main_assign_n
65	    line [gdb_get_line_number "main assign n"]
66	    DW_LNS_copy
67
68	    DW_LNE_set_address main_end_prologue
69	    line [gdb_get_line_number "main assign o"]
70	    DW_LNS_set_prologue_end
71	    DW_LNS_copy
72
73	    DW_LNE_set_address main_end
74	    line [gdb_get_line_number "main end"]
75	    DW_LNS_copy
76
77	    DW_LNE_end_sequence
78	}
79    }
80}
81
82if { [prepare_for_testing "failed to prepare" ${testfile} \
83	  [list $srcfile $asm_file] {nodebug}] } {
84    return -1
85}
86
87if ![runto_main] {
88    return -1
89}
90
91set prologue_end_line [gdb_get_line_number "main assign o"]
92gdb_test "frame" ".*main \\\(\\\) at \[^\r\n\]*:$prologue_end_line\r\n.*"
93
94with_test_prefix "ignore-prologue-end" {
95    clean_restart $binfile
96    gdb_test_no_output "maintenance set ignore-prologue-end-flag on"
97
98    if ![runto_main] {
99	return -1
100    }
101
102    # If we ignore the prologue-end flag, we should stop at the first statement
103    # of main which assigns m.
104    set prologue_end_line [gdb_get_line_number "main assign m"]
105    gdb_test "frame" ".*main \\\(\\\) at \[^\r\n\]*:$prologue_end_line\r\n.*"
106}
107