]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.dwarf2/imported-unit.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.dwarf2 / imported-unit.exp
1 # Copyright 2019-2023 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 # Import a CU into an "artificial" CU. For each DW_TAG DIE in the
17 # artificial CU, use DW_AT_abstract_origin to refer to a DIE in the
18 # imported CU. This DWARF file organization is frequently found in
19 # programs compiled with -flto (and -g) using GCC.
20 #
21 # This test reproduces the bug described in BZ 25065 without relying
22 # on specific compiler versions or use of optimization switches, in
23 # this case -flto.
24
25 if [skip_cplus_tests] {
26 return
27 }
28
29 load_lib dwarf.exp
30
31 # This test can only be run on targets which support DWARF-2 and use gas.
32 if {![dwarf2_support]} {
33 return 0
34 };
35
36 standard_testfile .c .S
37
38 # ${testfile} is now "implref-struct". srcfile2 is "implref-struct.S".
39 set executable ${testfile}
40 set asm_file [standard_output_file ${srcfile2}]
41
42 # We need to know the size of integer and address types in order
43 # to write some of the debugging info we'd like to generate.
44 if [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} {debug c++}] {
45 return -1
46 }
47
48 # Create the DWARF.
49 Dwarf::assemble $asm_file {
50 declare_labels cu_label main_label doit_label int_label
51 declare_labels Foo_label Foo_pointer_type doit_self_label
52 declare_labels foo_label Foo_destructor_obj_pointer_label
53 declare_labels Foo_constructor_obj_pointer_label
54 set int_size [get_sizeof "int" 4]
55 set addr_size [get_sizeof "void *" 8]
56
57 cu {} {
58 compile_unit {
59 {language @DW_LANG_C_plus_plus}
60 {name "<artificial>"}
61 } {
62 imported_unit {
63 {import %$cu_label}
64 }
65 subprogram {
66 {abstract_origin %$main_label}
67 {MACRO_AT_range {main}}
68 } {
69 subprogram {
70 {abstract_origin %$doit_label}
71 {MACRO_AT_range {doit}}
72 } {
73 formal_parameter {
74 {abstract_origin %$doit_self_label}
75 }
76 }
77 DW_TAG_variable {
78 {abstract_origin %$foo_label}
79 {location 4 data1}
80 }
81 }
82 }
83 }
84
85 cu {} {
86 cu_label: compile_unit {
87 {language @DW_LANG_C_plus_plus}
88 {name "imported_unit.c"}
89 } {
90 int_label: base_type {
91 {byte_size $int_size sdata}
92 {encoding @DW_ATE_signed}
93 {name int}
94 }
95
96 main_label: subprogram {
97 {name main}
98 {type :$int_label}
99 {external 1 flag}
100 } {
101 Foo_label: class_type {
102 {name Foo}
103 {byte_size 1 sdata}
104 } {
105 doit_label: subprogram {
106 {name doit}
107 {type :$int_label}
108 {accessibility 1 DW_FORM_data1}
109 } {
110 doit_self_label: formal_parameter {
111 {name this}
112 {artificial 1 DW_FORM_flag_present}
113 {type :$Foo_pointer_type}
114 }
115 }
116 Foo_pointer_type: pointer_type {
117 {byte_size $addr_size sdata}
118 {type :$Foo_label}
119 }
120 }
121 foo_label: DW_TAG_variable {
122 {name foo}
123 {type :$Foo_label}
124 }
125 }
126 }
127 }
128 }
129
130 if { [prepare_for_testing "failed to prepare" ${testfile} \
131 [list $srcfile $asm_file] {nodebug}] } {
132 return -1
133 }
134
135 gdb_test_no_output "set language c++"
136
137 set psymtabs_p [psymtabs_p]
138
139 # Verify that the partial symtab for CU "<artificial>" does
140 # not contain the static partial symbol int, which is defined in the
141 # CU "imported_unit.c". Test-case for PR25646.
142 set test "no static partial symbols in importing unit"
143 if { $psymtabs_p } {
144 gdb_test "main print psymbols" \
145 [multi_line \
146 " Depends on 0 other partial symtabs\." \
147 " Global partial symbols:" \
148 " `main', function, $hex" \
149 "" \
150 ".*"] \
151 $test
152 } else {
153 unsupported $test
154 }
155
156 # Verify that there's only one partial symtab for imported_unit.c. Test-case
157 # for PR25700.
158 set test "no duplicate psymtab for imported_unit.c"
159 if { $psymtabs_p } {
160 set line "Partial symtab for source file imported_unit.c"
161 gdb_test_multiple "maint print psymbols" $test {
162 -re -wrap "$line.*$line.*" {
163 fail $gdb_test_name
164 }
165 -re -wrap "$line.*" {
166 pass $gdb_test_name
167 }
168 }
169 } else {
170 unsupported $test
171 }
172
173 gdb_test "l imported_unit.c:1" \
174 "1\timported_unit.c: No such file or directory\."
175
176 gdb_test "info source" "\r\nCurrent source file is imported_unit.c\r\n.*" \
177 "info source for imported_unit.c"
178
179 # Sanity check
180 gdb_test "ptype main" "= int \\(void\\)"
181
182 # Each of these tests caused a segfault prior to fixing BZ 25065.
183 gdb_test "ptype main::Foo" "= class Foo \{\\s+public:\\s+int doit\\(void\\);\\s+\}"
184 gdb_test "ptype main::foo" "= class Foo \{\\s+public:\\s+int doit\\(void\\);\\s+\}"