1 # Copyright 2020 Free Software Foundation, Inc.
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.
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.
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/>.
16 # Test DW_AT_location attributes referencing the .debug_loclists section using
17 # the DW_FORM_sec_offset form.
21 if {![dwarf2_support]} {
25 # Test with 32-bit and 64-bit DWARF.
26 foreach_with_prefix is_64 {false true} {
28 standard_testfile .c -dw64.S
29 set testfile ${testfile}-dw64
31 standard_testfile .c -dw32.S
32 set testfile ${testfile}-dw32
35 # Get the addresses / lengths of functions.
36 lassign [function_range func1 $srcdir/$subdir/$srcfile] func1_addr func1_len
37 lassign [function_range func2 $srcdir/$subdir/$srcfile] func2_addr func2_len
38 lassign [function_range func3 $srcdir/$subdir/$srcfile] func3_addr func3_len
39 lassign [function_range func4 $srcdir/$subdir/$srcfile] func4_addr func4_len
40 lassign [function_range func5 $srcdir/$subdir/$srcfile] func5_addr func5_len
41 lassign [function_range func6 $srcdir/$subdir/$srcfile] func6_addr func6_len
43 set asm_file [standard_output_file $srcfile2]
44 Dwarf::assemble $asm_file {
45 global func1_addr func1_len
46 global func2_addr func2_len
47 global func3_addr func3_len
48 global func4_addr func4_len
49 global func5_addr func5_len
50 global func6_addr func6_len
53 declare_labels cu_range_list foo_range_list
55 # This CU uses the DW_FORM_sec_offset form to refer to the .debug_rnglists
61 declare_labels int_type1
62 declare_labels int_type2
63 declare_labels int_type3
64 declare_labels foo_location_list
65 declare_labels bar_location_list
66 declare_labels baz_location_list
70 int_type1: DW_TAG_base_type {
71 {DW_AT_byte_size 4 DW_FORM_data1}
72 {DW_AT_encoding @DW_ATE_signed}
78 {DW_AT_location $foo_location_list DW_FORM_sec_offset}
79 {DW_AT_type :$int_type1}
84 {DW_AT_low_pc $func1_addr}
85 {DW_AT_high_pc $func1_len DW_FORM_udata}
90 {DW_AT_low_pc $func2_addr}
91 {DW_AT_high_pc $func2_len DW_FORM_udata}
96 # This CU uses the DW_FORM_sec_offset form to refer to the
97 # .debug_loclists section, but also has the DW_AT_loclists_base
98 # attribute present. The DW_AT_loclists_base is not used to interpret
99 # the DW_AT_location value, but it should also do no harm.
104 DW_TAG_compile_unit {
105 {DW_AT_loclists_base cu2_table DW_FORM_sec_offset}
107 int_type2: DW_TAG_base_type {
108 {DW_AT_byte_size 4 DW_FORM_data1}
109 {DW_AT_encoding @DW_ATE_signed}
115 {DW_AT_location $bar_location_list DW_FORM_sec_offset}
116 {DW_AT_type :$int_type2}
121 {DW_AT_low_pc $func3_addr}
122 {DW_AT_high_pc $func3_len DW_FORM_udata}
127 {DW_AT_low_pc $func4_addr}
128 {DW_AT_high_pc $func4_len DW_FORM_udata}
133 # This CU uses the DW_FORM_sec_offset form to refer to the
134 # .debug_loclists section. The corresponding contribution in the
135 # .debug_loclists section has no offset array.
140 DW_TAG_compile_unit {
142 int_type3: DW_TAG_base_type {
143 {DW_AT_byte_size 4 DW_FORM_data1}
144 {DW_AT_encoding @DW_ATE_signed}
150 {DW_AT_location $baz_location_list DW_FORM_sec_offset}
151 {DW_AT_type :$int_type3}
156 {DW_AT_low_pc $func5_addr}
157 {DW_AT_high_pc $func5_len DW_FORM_udata}
162 {DW_AT_low_pc $func6_addr}
163 {DW_AT_high_pc $func6_len DW_FORM_udata}
168 loclists -is-64 $is_64 {
169 # The lists in this table are accessed by direct offset
170 # (DW_FORM_sec_offset).
172 foo_location_list: list_ {
173 start_length $func1_addr $func1_len {
174 DW_OP_constu 0x123456
178 start_length $func2_addr $func2_len {
179 DW_OP_constu 0x234567
185 table -post-header-label cu2_table {
186 bar_location_list: list_ {
187 start_length $func3_addr $func3_len {
188 DW_OP_constu 0x345678
192 start_length $func4_addr $func4_len {
193 DW_OP_constu 0x456789
199 table -with-offset-array false {
200 baz_location_list: list_ {
201 start_length $func5_addr $func5_len {
202 DW_OP_constu 0x567890
206 start_length $func6_addr $func6_len {
207 DW_OP_constu 0x678901
215 if { [prepare_for_testing "failed to prepare" ${testfile} \
216 [list $srcfile $asm_file] {nodebug}] } {
220 if { ![runto_main] } {
221 fail "can't run to main"
225 gdb_breakpoint "func1"
226 gdb_breakpoint "func2"
227 gdb_breakpoint "func3"
228 gdb_breakpoint "func4"
229 gdb_breakpoint "func5"
230 gdb_breakpoint "func6"
232 gdb_continue_to_breakpoint "func1"
233 with_test_prefix "at func1" {
234 gdb_test "print /x foo" " = 0x123456"
237 gdb_continue_to_breakpoint "func2"
238 with_test_prefix "at func2" {
239 gdb_test "print /x foo" " = 0x234567"
242 gdb_continue_to_breakpoint "func3"
243 with_test_prefix "at func3" {
244 gdb_test "print /x bar" " = 0x345678"
247 gdb_continue_to_breakpoint "func4"
248 with_test_prefix "at func4" {
249 gdb_test "print /x bar" " = 0x456789"
252 gdb_continue_to_breakpoint "func5"
253 with_test_prefix "at func5" {
254 gdb_test "print /x baz" " = 0x567890"
257 gdb_continue_to_breakpoint "func6"
258 with_test_prefix "at func6" {
259 gdb_test "print /x baz" " = 0x678901"