]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.dwarf2/opaque-type-lookup.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.dwarf2 / opaque-type-lookup.exp
1 # Copyright 2013-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 # Test PR 18258.
17
18 load_lib dwarf.exp
19
20 # This test can only be run on targets which support DWARF-2 and use gas.
21 require dwarf2_support
22
23 standard_testfile main.c -1.S -2.c
24
25 # Create the DWARF.
26 set asm_file [standard_output_file $srcfile2]
27 Dwarf::assemble $asm_file {
28 declare_labels partial_unit_defining_a partial_unit_defining_b
29 declare_labels partial_unit_with_opaque
30 declare_labels struct_a_label struct_b_label
31 declare_labels opaque_struct_a_label opaque_struct_b_label
32 declare_labels char_type1_label char_type2_label
33
34 # The partial units are laid out so we're not dependent on the order that
35 # they appear in compunit_symtab.includes. We need the one with the
36 # opaque definition to appear first to gdb, so we put it in the middle.
37 # Either the handling of variable_a or variable_b will be broken (in an
38 # unpatched gdb).
39 #
40 # However, once a partial unit with a non-opaque type is read in we can
41 # no longer see the bug as gdb will keep looking until it eventually gets
42 # to the defining partial unit, setting aside the symbol lookup cache.
43 # So heads up!
44
45 cu {} {
46 compile_unit {
47 {language @DW_LANG_C}
48 {name opaque_before}
49 } {
50 imported_unit {
51 {import $partial_unit_with_opaque ref_addr}
52 }
53
54 imported_unit {
55 {import $partial_unit_defining_a ref_addr}
56 }
57 }
58 }
59
60 cu {} {
61 compile_unit {
62 {language @DW_LANG_C}
63 {name opaque_after}
64 } {
65 imported_unit {
66 {import $partial_unit_defining_b ref_addr}
67 }
68
69 imported_unit {
70 {import $partial_unit_with_opaque ref_addr}
71 }
72 }
73 }
74
75 cu {} {
76 partial_unit_with_opaque: partial_unit {
77 {name "partial_unit_with_opaque"}
78 } {
79 # Normally gdb doesn't add opaque types to the symbol table
80 # but there are times when it will, and in order to exercise
81 # this bug we need this entry in the symbol table.
82 # By giving it a size of 1 we achieve this.
83
84 opaque_struct_a_label: structure_type {
85 {name struct_a}
86 {declaration 1 flag}
87 {byte_size 1 DW_FORM_sdata}
88 }
89
90 opaque_struct_b_label: structure_type {
91 {name struct_b}
92 {declaration 1 flag}
93 {byte_size 1 DW_FORM_sdata}
94 }
95
96 DW_TAG_variable {
97 {name variable_a}
98 {type :$opaque_struct_a_label}
99 {external 1 flag}
100 {declaration 1 flag}
101 }
102
103 DW_TAG_variable {
104 {name variable_b}
105 {type :$opaque_struct_b_label}
106 {external 1 flag}
107 {declaration 1 flag}
108 }
109 }
110 }
111
112 cu {} {
113 partial_unit_defining_a: partial_unit {
114 {name "partial_unit_defining_a"}
115 } {
116 char_type1_label: base_type {
117 {name "signed char"}
118 {encoding @DW_ATE_signed}
119 {byte_size 1 DW_FORM_sdata}
120 }
121
122 struct_a_label: structure_type {
123 {name struct_a}
124 {byte_size 1 DW_FORM_sdata}
125 } {
126 member {
127 {name xyz}
128 {type :$char_type1_label}
129 {data_member_location 0 DW_FORM_sdata}
130 }
131 }
132
133 DW_TAG_variable {
134 {name variable_a}
135 {type :$struct_a_label}
136 {external 1 flag}
137 {linkage_name variable_a}
138 }
139 }
140 }
141
142 cu {} {
143 partial_unit_defining_b: partial_unit {
144 {name "partial_unit_defining_b"}
145 } {
146 char_type2_label: base_type {
147 {name "signed char"}
148 {encoding @DW_ATE_signed}
149 {byte_size 1 DW_FORM_sdata}
150 }
151
152 struct_b_label: structure_type {
153 {name struct_b}
154 {byte_size 1 DW_FORM_sdata}
155 } {
156 member {
157 {name xyz}
158 {type :$char_type2_label}
159 {data_member_location 0 DW_FORM_sdata}
160 }
161 }
162
163 DW_TAG_variable {
164 {name variable_b}
165 {type :$struct_b_label}
166 {external 1 flag}
167 {linkage_name variable_b}
168 }
169 }
170 }
171
172 # GDB expands the symbol table with main at start up,
173 # so keep this separate.
174 cu {} {
175 compile_unit {
176 {language @DW_LANG_C}
177 {name main}
178 } {
179 subprogram {
180 {MACRO_AT_func { main }}
181 }
182 }
183 }
184 }
185
186 if [prepare_for_testing "failed to prepare" $testfile "${asm_file} ${srcfile} ${srcfile3}" {nodebug}] {
187 return -1
188 }
189
190 if ![runto_main] {
191 return -1
192 }
193
194 gdb_test "p variable_a" " = {xyz = 97 'a'}"
195 gdb_test "p variable_b" " = {xyz = 98 'b'}"