]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.dwarf2/dw2-ranges-base.exp
Automatic Copyright Year update after running gdb/copyright.py
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.dwarf2 / dw2-ranges-base.exp
CommitLineData
4a94e368 1# Copyright 2015-2022 Free Software Foundation, Inc.
28d2bfb9
AB
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/>.
15load_lib dwarf.exp
16
17# Test DW_TAG_compile_unit with no children and with neither DW_AT_low_pc nor
18# DW_AT_high_pc but with DW_AT_ranges instead.
19
20# This test can only be run on targets which support DWARF-2 and use gas.
21if {![dwarf2_support]} {
0cd2ad78 22 verbose "Skipping $gdb_test_file_name."
28d2bfb9
AB
23 return 0
24}
25
26# The .c files use __attribute__.
27if [get_compiler_info] {
28 return -1
29}
30if !$gcc_compiled {
0cd2ad78 31 verbose "Skipping $gdb_test_file_name."
28d2bfb9
AB
32 return 0
33}
34
d1c8a76d 35standard_testfile .c -dw.S
28d2bfb9
AB
36
37set asm_file [standard_output_file $srcfile2]
38Dwarf::assemble $asm_file {
39 global srcdir subdir srcfile srcfile2
40 declare_labels ranges_label
41 declare_labels L
42
43 # Find start address and length for our functions.
44 set main_func \
45 [function_range main [list ${srcdir}/${subdir}/$srcfile]]
46 set frame2_func \
47 [function_range frame2 [list ${srcdir}/${subdir}/$srcfile]]
48 set frame3_func \
49 [function_range frame3 [list ${srcdir}/${subdir}/$srcfile]]
50
51 # Very simple info for this test program. We don't care about
52 # this information being correct (w.r.t. funtion / argument types)
53 # just so long as the compilation using makes use of the
54 # .debug_ranges data then the test achieves its objective.
1d4a20b5 55 cu { label cu_label } {
28d2bfb9
AB
56 compile_unit {
57 {language @DW_LANG_C}
58 {name dw-ranges-base.c}
59 {stmt_list $L DW_FORM_sec_offset}
60 {ranges ${ranges_label} DW_FORM_sec_offset}
61 } {
62 subprogram {
63 {external 1 flag}
64 {name main}
65 }
66 subprogram {
67 {external 1 flag}
68 {name frame2}
69 }
70 subprogram {
71 {external 1 flag}
72 {name frame3}
73 }
74 }
75 }
76
77 lines {version 2} L {
78 include_dir "${srcdir}/${subdir}"
79 file_name "$srcfile" 1
80
81 # Generate simple line table program. The line table
82 # information contained here is not correct, and we really
83 # don't care, just so long as each function has some line
84 # table data associated with it. We do make use of the fake
85 # line numbers that we pick here in the tests below.
86 program {
87 {DW_LNE_set_address [lindex $main_func 0]}
88 {DW_LNS_advance_line 10}
89 {DW_LNS_copy}
90 {DW_LNS_advance_pc [lindex $main_func 1]}
91 {DW_LNS_advance_line 19}
92 {DW_LNS_copy}
93 {DW_LNE_end_sequence}
94
95 {DW_LNE_set_address [lindex $frame2_func 0]}
96 {DW_LNS_advance_line 20}
97 {DW_LNS_copy}
98 {DW_LNS_advance_pc [lindex $frame2_func 1]}
99 {DW_LNS_advance_line 29}
100 {DW_LNS_copy}
101 {DW_LNE_end_sequence}
102
103 {DW_LNE_set_address [lindex $frame3_func 0]}
104 {DW_LNS_advance_line 30}
105 {DW_LNS_copy}
106 {DW_LNS_advance_pc [lindex $frame3_func 1]}
107 {DW_LNS_advance_line 39}
108 {DW_LNS_copy}
109 {DW_LNE_end_sequence}
110 }
111 }
112
113 # Generate ranges data. This is the point of this whole test
114 # file, we must have multiple bases specified, so we use a new
115 # base for each function.
116 ranges {is_64 [is_64_target]} {
117 ranges_label: sequence {
a1945bd4
SM
118 base [lindex $main_func 0]
119 range 0 [lindex $main_func 1]
120 base [lindex $frame2_func 0]
121 range 0 [lindex $frame2_func 1]
122 base [lindex $frame3_func 0]
123 range 0 [lindex $frame3_func 1]
28d2bfb9
AB
124 }
125 }
1d4a20b5
TV
126
127 aranges {} cu_label {
590d3faa
TV
128 arange {} [lindex $main_func 0] [lindex $main_func 1]
129 arange {} [lindex $frame2_func 0] [lindex $frame2_func 1]
130 arange {} [lindex $frame3_func 0] [lindex $frame3_func 1]
1d4a20b5 131 }
28d2bfb9
AB
132}
133
5b362f04 134if { [prepare_for_testing "failed to prepare" ${testfile} \
28d2bfb9
AB
135 [list $srcfile $asm_file] {nodebug}] } {
136 return -1
137}
138
139if ![runto_main] {
140 return -1
141}
142
143# Make use of the line numbers we faked in the .debug_line table above.
144gdb_test "info line main" \
145 "Line 11 of .* starts at address .* and ends at .*"
146gdb_test "info line frame2" \
147 "Line 21 of .* starts at address .* and ends at .*"
148gdb_test "info line frame3" \
149 "Line 31 of .* starts at address .* and ends at .*"
94a72be7
AB
150
151# Ensure that the line table correctly tracks the end of sequence markers.
152set end_seq_count 0
d8cc8af6
TV
153set prev -1
154set seq_count 0
307eafd8 155gdb_test_multiple "maint info line-table gdb.dwarf2/dw2-ranges-base.c" \
94a72be7 156 "count END markers in line table" {
1773be9e 157 -re "^$decimal\[ \t\]+$decimal\[ \t\]+$hex\(\[ \t\]+Y\)? *\r\n" {
d8cc8af6
TV
158 if { $prev != -1 } {
159 gdb_assert "$prev == 1" \
160 "prev of normal entry at $seq_count is end marker"
161 }
162 set prev 0
163 incr seq_count
94a72be7
AB
164 exp_continue
165 }
1773be9e 166 -re "^$decimal\[ \t\]+END\[ \t\]+$hex\(\[ \t\]+Y\)? *\r\n" {
d8cc8af6
TV
167 if { $prev != -1 } {
168 gdb_assert "$prev == 0" \
169 "prev of end marker at $seq_count is normal entry"
170 }
171 set prev 1
172 incr seq_count
94a72be7
AB
173 incr end_seq_count
174 exp_continue
175 }
a3e9c2f9
SM
176 -re "^\r\n" {
177 # Empty lines between tables.
178 exp_continue
179 }
94a72be7
AB
180 -re "^$gdb_prompt $" {
181 gdb_assert [expr $end_seq_count == 3] $gdb_test_name
182 }
183 -re ".*linetable: \\(\\(struct linetable \\*\\) 0x0\\):\r\nNo line table.\r\n" {
184 exp_continue
185 }
1773be9e 186 -re ".*linetable: \\(\\(struct linetable \\*\\) $hex\\):\r\nINDEX\[ \t\]+LINE\[ \t\]+ADDRESS\[ \t\]+IS-STMT *\r\n" {
94a72be7
AB
187 exp_continue
188 }
189 }