Commit | Line | Data |
---|---|---|
b811d2c2 | 1 | # Copyright 2019-2020 Free Software Foundation, Inc. |
d22670f0 KB |
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 | continue | |
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 | global srcdir subdir srcfile | |
58 | ||
59 | extern main | |
60 | extern doit | |
61 | ||
62 | set main_range [function_range main ${srcdir}/${subdir}/${srcfile}] | |
63 | set main_start [lindex $main_range 0] | |
64 | set main_length [lindex $main_range 1] | |
65 | ||
66 | set doit_range [function_range doit ${srcdir}/${subdir}/${srcfile}] | |
67 | set doit_start [lindex $doit_range 0] | |
68 | set doit_length [lindex $doit_range 1] | |
69 | ||
70 | cu {} { | |
71 | compile_unit { | |
72 | {language @DW_LANG_C_plus_plus} | |
73 | {name "<artificial>"} | |
74 | } { | |
75 | imported_unit { | |
c14aab8c | 76 | {import %$cu_label} |
d22670f0 KB |
77 | } |
78 | subprogram { | |
c14aab8c | 79 | {abstract_origin %$main_label} |
d22670f0 KB |
80 | {low_pc $main_start addr} |
81 | {high_pc "$main_start + $main_length" addr} | |
82 | } { | |
83 | subprogram { | |
c14aab8c | 84 | {abstract_origin %$doit_label} |
d22670f0 KB |
85 | {low_pc $doit_start addr} |
86 | {high_pc "$doit_start + $doit_length" addr} | |
87 | } { | |
88 | formal_parameter { | |
c14aab8c | 89 | {abstract_origin %$doit_self_label} |
d22670f0 KB |
90 | } |
91 | } | |
92 | DW_TAG_variable { | |
c14aab8c | 93 | {abstract_origin %$foo_label} |
d22670f0 KB |
94 | {location 4 data1} |
95 | } | |
96 | } | |
97 | } | |
98 | } | |
99 | ||
100 | cu {} { | |
101 | cu_label: compile_unit { | |
102 | {language @DW_LANG_C_plus_plus} | |
103 | {name "imported_unit.c"} | |
104 | } { | |
105 | int_label: base_type { | |
106 | {byte_size $int_size sdata} | |
107 | {encoding @DW_ATE_signed} | |
108 | {name int} | |
109 | } | |
110 | ||
111 | main_label: subprogram { | |
112 | {name main} | |
113 | {type :$int_label} | |
114 | {external 1 flag} | |
115 | } { | |
116 | Foo_label: class_type { | |
117 | {name Foo} | |
118 | {byte_size 1 sdata} | |
119 | } { | |
120 | doit_label: subprogram { | |
121 | {name doit} | |
122 | {type :$int_label} | |
123 | {accessibility 1 DW_FORM_data1} | |
124 | } { | |
125 | doit_self_label: formal_parameter { | |
126 | {name this} | |
127 | {artificial 1 DW_FORM_flag_present} | |
128 | {type :$Foo_pointer_type} | |
129 | } | |
130 | } | |
131 | Foo_pointer_type: pointer_type { | |
132 | {byte_size $addr_size sdata} | |
133 | {type :$Foo_label} | |
134 | } | |
135 | } | |
136 | foo_label: DW_TAG_variable { | |
137 | {name foo} | |
138 | {type :$Foo_label} | |
139 | } | |
140 | } | |
141 | } | |
142 | } | |
143 | } | |
144 | ||
145 | if { [prepare_for_testing "failed to prepare" ${testfile} \ | |
146 | [list $srcfile $asm_file] {nodebug}] } { | |
147 | return -1 | |
148 | } | |
149 | ||
150 | gdb_test_no_output "set language c++" | |
151 | ||
14ca8ecf TV |
152 | set psymtabs_p [psymtabs_p] |
153 | ||
96c7f873 TV |
154 | # Verify that the partial symtab for the unit importing the partial unit does |
155 | # not contain the static partial symbol int, which is defined in the partial | |
156 | # unit. Test-case for PR25646. | |
14ca8ecf TV |
157 | set test "no static partial symbols in importing unit" |
158 | if { $psymtabs_p } { | |
159 | gdb_test "main print psymbols" \ | |
160 | [multi_line \ | |
161 | " Depends on 1 other partial symtabs\." \ | |
162 | "\[^\r\n\]*" \ | |
163 | " Global partial symbols:" \ | |
164 | " `main', function, $hex" \ | |
165 | "" \ | |
166 | ".*"] \ | |
167 | $test | |
168 | } else { | |
169 | unsupported $test | |
170 | } | |
3d5afab3 TV |
171 | |
172 | # Verify that there's only one partial symtab for imported_unit.c. Test-case | |
173 | # for PR25700. | |
174 | set test "no duplicate psymtab for imported_unit.c" | |
175 | if { $psymtabs_p } { | |
176 | set line "Partial symtab for source file imported_unit.c" | |
177 | gdb_test_multiple "maint print psymbols" $test { | |
178 | -re -wrap "$line.*$line.*" { | |
179 | fail $gdb_test_name | |
180 | } | |
181 | -re -wrap "$line.*" { | |
182 | pass $gdb_test_name | |
183 | } | |
184 | } | |
185 | } else { | |
186 | unsupported $test | |
187 | } | |
188 | ||
eea9e357 TV |
189 | gdb_test "l imported_unit.c:1" \ |
190 | "1\timported_unit.c: No such file or directory\." | |
191 | ||
192 | gdb_test "info source" "\r\nCurrent source file is imported_unit.c\r\n.*" \ | |
193 | "info source for imported_unit.c" | |
194 | ||
d22670f0 KB |
195 | # Sanity check |
196 | gdb_test "ptype main" "= int \\(void\\)" | |
197 | ||
198 | # Each of these tests caused a segfault prior to fixing BZ 25065. | |
199 | gdb_test "ptype main::Foo" "= class Foo \{\\s+public:\\s+int doit\\(void\\);\\s+\}" | |
200 | gdb_test "ptype main::foo" "= class Foo \{\\s+public:\\s+int doit\\(void\\);\\s+\}" |