1 # Copyright 2013-2024 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/>.
20 # This test can only be run on targets which support DWARF-2 and use gas.
21 require dwarf2_support
23 standard_testfile main.c -1.S -2.c
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
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
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.
51 {import $partial_unit_with_opaque ref_addr}
55 {import $partial_unit_defining_a ref_addr}
66 {import $partial_unit_defining_b ref_addr}
70 {import $partial_unit_with_opaque ref_addr}
76 partial_unit_with_opaque: partial_unit {
77 {name "partial_unit_with_opaque"}
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.
84 opaque_struct_a_label: structure_type {
87 {byte_size 1 DW_FORM_sdata}
90 opaque_struct_b_label: structure_type {
93 {byte_size 1 DW_FORM_sdata}
98 {type :$opaque_struct_a_label}
105 {type :$opaque_struct_b_label}
113 partial_unit_defining_a: partial_unit {
114 {name "partial_unit_defining_a"}
116 char_type1_label: base_type {
118 {encoding @DW_ATE_signed}
119 {byte_size 1 DW_FORM_sdata}
122 struct_a_label: structure_type {
124 {byte_size 1 DW_FORM_sdata}
128 {type :$char_type1_label}
129 {data_member_location 0 DW_FORM_sdata}
135 {type :$struct_a_label}
137 {linkage_name variable_a}
143 partial_unit_defining_b: partial_unit {
144 {name "partial_unit_defining_b"}
146 char_type2_label: base_type {
148 {encoding @DW_ATE_signed}
149 {byte_size 1 DW_FORM_sdata}
152 struct_b_label: structure_type {
154 {byte_size 1 DW_FORM_sdata}
158 {type :$char_type2_label}
159 {data_member_location 0 DW_FORM_sdata}
165 {type :$struct_b_label}
167 {linkage_name variable_b}
172 # GDB expands the symbol table with main at start up,
173 # so keep this separate.
176 {language @DW_LANG_C}
180 {MACRO_AT_func { main }}
186 if [prepare_for_testing "failed to prepare" $testfile "${asm_file} ${srcfile} ${srcfile3}" {nodebug}] {
194 gdb_test "p variable_a" " = {xyz = 97 'a'}"
195 gdb_test "p variable_b" " = {xyz = 98 'b'}"