1 # Copyright 2019-2023 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/>.
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.
21 # This test reproduces the bug described in BZ 25065 without relying
22 # on specific compiler versions or use of optimization switches, in
25 if [skip_cplus_tests] {
31 # This test can only be run on targets which support DWARF-2 and use gas.
32 if {![dwarf2_support]} {
36 standard_testfile .c .S
38 # ${testfile} is now "implref-struct". srcfile2 is "implref-struct.S".
39 set executable ${testfile}
40 set asm_file [standard_output_file ${srcfile2}]
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++}] {
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]
59 {language @DW_LANG_C_plus_plus}
66 {abstract_origin %$main_label}
67 {MACRO_AT_range {main}}
70 {abstract_origin %$doit_label}
71 {MACRO_AT_range {doit}}
74 {abstract_origin %$doit_self_label}
78 {abstract_origin %$foo_label}
86 cu_label: compile_unit {
87 {language @DW_LANG_C_plus_plus}
88 {name "imported_unit.c"}
90 int_label: base_type {
91 {byte_size $int_size sdata}
92 {encoding @DW_ATE_signed}
96 main_label: subprogram {
101 Foo_label: class_type {
105 doit_label: subprogram {
108 {accessibility 1 DW_FORM_data1}
110 doit_self_label: formal_parameter {
112 {artificial 1 DW_FORM_flag_present}
113 {type :$Foo_pointer_type}
116 Foo_pointer_type: pointer_type {
117 {byte_size $addr_size sdata}
121 foo_label: DW_TAG_variable {
130 if { [prepare_for_testing "failed to prepare" ${testfile} \
131 [list $srcfile $asm_file] {nodebug}] } {
135 gdb_test_no_output "set language c++"
137 set psymtabs_p [psymtabs_p]
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"
144 gdb_test "main print psymbols" \
146 " Depends on 0 other partial symtabs\." \
147 " Global partial symbols:" \
148 " `main', function, $hex" \
156 # Verify that there's only one partial symtab for imported_unit.c. Test-case
158 set test "no duplicate psymtab for imported_unit.c"
160 set line "Partial symtab for source file imported_unit.c"
161 gdb_test_multiple "maint print psymbols" $test {
162 -re -wrap "$line.*$line.*" {
165 -re -wrap "$line.*" {
173 gdb_test "l imported_unit.c:1" \
174 "1\timported_unit.c: No such file or directory\."
176 gdb_test "info source" "\r\nCurrent source file is imported_unit.c\r\n.*" \
177 "info source for imported_unit.c"
180 gdb_test "ptype main" "= int \\(void\\)"
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+\}"