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