]>
Commit | Line | Data |
---|---|---|
51a5ef0f PS |
1 | http://sourceware.org/ml/gdb-patches/2010-09/msg00440.html |
2 | Subject: [patch] Fix infinite loop crash on self-referencing class | |
3 | ||
4 | Hi, | |
5 | ||
6 | class C { static C s; }; is a problem for GDB as it references itself and it | |
7 | can crash. Downstream Bug: | |
8 | https://bugzilla.redhat.com/show_bug.cgi?id=627432 | |
9 | ||
10 | #3 0x00000000005b2cc5 in gnuv3_pass_by_reference (type=0x1044d3c8) at ../../gdb/gnu-v3-abi.c:840 | |
11 | #4 0x00000000005b2cc5 in gnuv3_pass_by_reference (type=0x1044d3c8) at ../../gdb/gnu-v3-abi.c:840 | |
12 | [...] | |
13 | ||
14 | No regressions on {x86_64,x86_64-m32,i686}-fedora13-linux-gnu. | |
15 | ||
16 | FYI the .cc file is not reproducible on - and only on - Fedora 14 GCC, filed: | |
17 | https://bugzilla.redhat.com/show_bug.cgi?id=637315 | |
18 | ||
19 | I would even check it in in some time. | |
20 | ||
21 | ||
22 | Thanks, | |
23 | Jan | |
24 | ||
25 | ||
26 | gdb/ | |
27 | 2010-09-24 Jan Kratochvil <jan.kratochvil@redhat.com> | |
28 | ||
29 | Fix GDB crash on inferior calls with self-referencing classes. | |
30 | * gnu-v3-abi.c (gnuv3_pass_by_reference): Do not call itself on static | |
31 | member fields. | |
32 | ||
33 | gdb/testsuite/ | |
34 | 2010-09-24 Jan Kratochvil <jan.kratochvil@redhat.com> | |
35 | ||
36 | Fix GDB crash on inferior calls with self-referencing classes. | |
37 | * gdb.dwarf2/dw2-cp-infcall-ref-static.exp: New file. | |
38 | * gdb.dwarf2/dw2-cp-infcall-ref-static-main.c: New file. | |
39 | * gdb.dwarf2/dw2-cp-infcall-ref-static.S: New file. | |
40 | ||
41 | --- a/gdb/gnu-v3-abi.c | |
42 | +++ b/gdb/gnu-v3-abi.c | |
43 | @@ -835,9 +835,10 @@ gnuv3_pass_by_reference (struct type *type) | |
44 | by reference, so does this class. Similarly for members, which | |
45 | are constructed whenever this class is. We do not need to worry | |
46 | about recursive loops here, since we are only looking at members | |
47 | - of complete class type. */ | |
48 | + of complete class type. Also ignore any static members. */ | |
49 | for (fieldnum = 0; fieldnum < TYPE_NFIELDS (type); fieldnum++) | |
50 | - if (gnuv3_pass_by_reference (TYPE_FIELD_TYPE (type, fieldnum))) | |
51 | + if (TYPE_FIELD_LOC_KIND (type, fieldnum) == FIELD_LOC_KIND_BITPOS | |
52 | + && gnuv3_pass_by_reference (TYPE_FIELD_TYPE (type, fieldnum))) | |
53 | return 1; | |
54 | ||
55 | return 0; | |
56 | --- /dev/null | |
57 | +++ b/gdb/testsuite/gdb.dwarf2/dw2-cp-infcall-ref-static-main.c | |
58 | @@ -0,0 +1,51 @@ | |
59 | +/* This testcase is part of GDB, the GNU debugger. | |
60 | + | |
61 | + Copyright 2010 Free Software Foundation, Inc. | |
62 | + | |
63 | + This program is free software; you can redistribute it and/or modify | |
64 | + it under the terms of the GNU General Public License as published by | |
65 | + the Free Software Foundation; either version 3 of the License, or | |
66 | + (at your option) any later version. | |
67 | + | |
68 | + This program is distributed in the hope that it will be useful, | |
69 | + but WITHOUT ANY WARRANTY; without even the implied warranty of | |
70 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
71 | + GNU General Public License for more details. | |
72 | + | |
73 | + You should have received a copy of the GNU General Public License | |
74 | + along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
75 | + | |
76 | +/* class C | |
77 | + { | |
78 | + public: | |
79 | + static C s; | |
80 | + }; | |
81 | + C C::s; | |
82 | + C f() | |
83 | + { | |
84 | + return C::s; | |
85 | + } */ | |
86 | + | |
87 | +asm (".globl cu_text_start"); | |
88 | +asm ("cu_text_start:"); | |
89 | + | |
90 | +asm (".globl f_start"); | |
91 | +asm ("f_start:"); | |
92 | + | |
93 | +void | |
94 | +f (void) | |
95 | +{ | |
96 | +} | |
97 | + | |
98 | +asm (".globl f_end"); | |
99 | +asm ("f_end:"); | |
100 | + | |
101 | +int | |
102 | +main (void) | |
103 | +{ | |
104 | + f (); | |
105 | + return 0; | |
106 | +} | |
107 | + | |
108 | +asm (".globl cu_text_end"); | |
109 | +asm ("cu_text_end:"); | |
110 | --- /dev/null | |
111 | +++ b/gdb/testsuite/gdb.dwarf2/dw2-cp-infcall-ref-static.S | |
112 | @@ -0,0 +1,115 @@ | |
113 | +/* This testcase is part of GDB, the GNU debugger. | |
114 | + | |
115 | + Copyright 2010 Free Software Foundation, Inc. | |
116 | + | |
117 | + This program is free software; you can redistribute it and/or modify | |
118 | + it under the terms of the GNU General Public License as published by | |
119 | + the Free Software Foundation; either version 3 of the License, or | |
120 | + (at your option) any later version. | |
121 | + | |
122 | + This program is distributed in the hope that it will be useful, | |
123 | + but WITHOUT ANY WARRANTY; without even the implied warranty of | |
124 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
125 | + GNU General Public License for more details. | |
126 | + | |
127 | + You should have received a copy of the GNU General Public License | |
128 | + along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
129 | + | |
130 | +/* Debug information */ | |
131 | + | |
132 | + .section .debug_info | |
133 | +.Lcu1_begin: | |
134 | + /* CU header */ | |
135 | + .4byte .Lcu1_end - .Lcu1_start /* Length of Compilation Unit */ | |
136 | +.Lcu1_start: | |
137 | + .2byte 2 /* DWARF Version */ | |
138 | + .4byte .Labbrev1_begin /* Offset into abbrev section */ | |
139 | + .byte 4 /* Pointer size */ | |
140 | + | |
141 | + /* CU die */ | |
142 | + .uleb128 1 /* Abbrev: DW_TAG_compile_unit */ | |
143 | + .4byte cu_text_start /* DW_AT_low_pc */ | |
144 | + .4byte cu_text_end /* DW_AT_high_pc */ | |
145 | + .ascii "file1.txt\0" /* DW_AT_name */ | |
146 | + .ascii "GNU C 3.3.3\0" /* DW_AT_producer */ | |
147 | + .byte 4 /* DW_AT_language (DW_LANG_C_plus_plus) */ | |
148 | + | |
149 | +.Ltype_class: | |
150 | + .uleb128 3 /* Abbrev: DW_TAG_class_type */ | |
151 | + .ascii "C\0" /* DW_AT_name */ | |
152 | + | |
153 | + .uleb128 4 /* Abbrev: DW_TAG_member */ | |
154 | + .ascii "s\0" /* DW_AT_name */ | |
155 | + .4byte .Ltype_class-.Lcu1_begin /* DW_AT_type */ | |
156 | + .byte 1 /* DW_AT_declaration */ | |
157 | + .byte 1 /* DW_AT_external */ | |
158 | + | |
159 | + .byte 0 /* End of children of DW_TAG_class_type */ | |
160 | + | |
161 | + .uleb128 5 /* Abbrev: DW_TAG_subprogram */ | |
162 | + .ascii "f\0" /* DW_AT_name */ | |
163 | + .4byte .Ltype_class-.Lcu1_begin /* DW_AT_type */ | |
164 | + .4byte f_start /* DW_AT_low_pc */ | |
165 | + .4byte f_end /* DW_AT_high_pc */ | |
166 | + | |
167 | + .byte 0 /* End of children of CU */ | |
168 | + | |
169 | +.Lcu1_end: | |
170 | + | |
171 | +/* Abbrev table */ | |
172 | + .section .debug_abbrev | |
173 | +.Labbrev1_begin: | |
174 | + .uleb128 1 /* Abbrev code */ | |
175 | + .uleb128 0x11 /* DW_TAG_compile_unit */ | |
176 | + .byte 1 /* has_children */ | |
177 | + .uleb128 0x11 /* DW_AT_low_pc */ | |
178 | + .uleb128 0x1 /* DW_FORM_addr */ | |
179 | + .uleb128 0x12 /* DW_AT_high_pc */ | |
180 | + .uleb128 0x1 /* DW_FORM_addr */ | |
181 | + .uleb128 0x3 /* DW_AT_name */ | |
182 | + .uleb128 0x8 /* DW_FORM_string */ | |
183 | + .uleb128 0x25 /* DW_AT_producer */ | |
184 | + .uleb128 0x8 /* DW_FORM_string */ | |
185 | + .uleb128 0x13 /* DW_AT_language */ | |
186 | + .uleb128 0xb /* DW_FORM_data1 */ | |
187 | + .byte 0x0 /* Terminator */ | |
188 | + .byte 0x0 /* Terminator */ | |
189 | + | |
190 | + .uleb128 3 /* Abbrev code */ | |
191 | + .uleb128 0x2 /* DW_TAG_class_type */ | |
192 | + .byte 1 /* has_children */ | |
193 | + .uleb128 0x3 /* DW_AT_name */ | |
194 | + .uleb128 0x8 /* DW_FORM_string */ | |
195 | + .byte 0x0 /* Terminator */ | |
196 | + .byte 0x0 /* Terminator */ | |
197 | + | |
198 | + .uleb128 4 /* Abbrev code */ | |
199 | + .uleb128 0xd /* DW_TAG_member */ | |
200 | + .byte 0 /* has_children */ | |
201 | + .uleb128 0x3 /* DW_AT_name */ | |
202 | + .uleb128 0x8 /* DW_FORM_string */ | |
203 | + .uleb128 0x49 /* DW_AT_type */ | |
204 | + .uleb128 0x13 /* DW_FORM_ref4 */ | |
205 | + .uleb128 0x3c /* DW_AT_declaration */ | |
206 | + .uleb128 0xc /* DW_FORM_flag */ | |
207 | + .uleb128 0x3f /* DW_AT_external */ | |
208 | + .uleb128 0xc /* DW_FORM_flag */ | |
209 | + .byte 0x0 /* Terminator */ | |
210 | + .byte 0x0 /* Terminator */ | |
211 | + | |
212 | + .uleb128 5 /* Abbrev code */ | |
213 | + .uleb128 0x2e /* DW_TAG_subprogram */ | |
214 | + .byte 0 /* has_children */ | |
215 | + .uleb128 0x3 /* DW_AT_name */ | |
216 | + .uleb128 0x8 /* DW_FORM_string */ | |
217 | + .uleb128 0x49 /* DW_AT_type */ | |
218 | + .uleb128 0x13 /* DW_FORM_ref4 */ | |
219 | + .uleb128 0x11 /* DW_AT_low_pc */ | |
220 | + .uleb128 0x1 /* DW_FORM_addr */ | |
221 | + .uleb128 0x12 /* DW_AT_high_pc */ | |
222 | + .uleb128 0x1 /* DW_FORM_addr */ | |
223 | + .byte 0x0 /* Terminator */ | |
224 | + .byte 0x0 /* Terminator */ | |
225 | + | |
226 | + .byte 0x0 /* Terminator */ | |
227 | + .byte 0x0 /* Terminator */ | |
228 | --- /dev/null | |
229 | +++ b/gdb/testsuite/gdb.dwarf2/dw2-cp-infcall-ref-static.exp | |
230 | @@ -0,0 +1,49 @@ | |
231 | +# Copyright 2010 Free Software Foundation, Inc. | |
232 | + | |
233 | +# This program is free software; you can redistribute it and/or modify | |
234 | +# it under the terms of the GNU General Public License as published by | |
235 | +# the Free Software Foundation; either version 3 of the License, or | |
236 | +# (at your option) any later version. | |
237 | +# | |
238 | +# This program is distributed in the hope that it will be useful, | |
239 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
240 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
241 | +# GNU General Public License for more details. | |
242 | +# | |
243 | +# You should have received a copy of the GNU General Public License | |
244 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
245 | + | |
246 | +# Check that GDB can call C++ functions whose parameters or return values have | |
247 | +# type containing a static member of the same type. | |
248 | + | |
249 | +# Still no C++ compiler is used. | |
250 | +if { [skip_cplus_tests] } { continue } | |
251 | + | |
252 | +# This test can only be run on targets which support DWARF-2 and use gas. | |
253 | +# For now pick a sampling of likely targets. | |
254 | +if {![istarget *-*-linux*] | |
255 | + && ![istarget *-*-gnu*] | |
256 | + && ![istarget *-*-elf*] | |
257 | + && ![istarget *-*-openbsd*] | |
258 | + && ![istarget arm-*-eabi*] | |
259 | + && ![istarget powerpc-*-eabi*]} { | |
260 | + return 0 | |
261 | +} | |
262 | + | |
263 | +set testfile "dw2-cp-infcall-ref-static" | |
264 | +if { [prepare_for_testing ${testfile}.exp ${testfile} [list ${testfile}-main.c ${testfile}.S] {}] } { | |
265 | + return -1 | |
266 | +} | |
267 | + | |
268 | +if ![runto_main] then { | |
269 | + return -1 | |
270 | +} | |
271 | + | |
272 | +# main is not provided by DWARF. | |
273 | +gdb_test_no_output "set language c++" | |
274 | + | |
275 | +# There are no mangled names in DWARF to suggest the v3 ABI. | |
276 | +gdb_test_no_output "set cp-abi gnu-v3" | |
277 | + | |
278 | +# GDB could crash. There is no DW_AT_location so it is <optimized out>. | |
279 | +gdb_test "p f()" { = {static s = <optimized out>}} | |
280 |