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