]>
Commit | Line | Data |
---|---|---|
6ed6bacf AM |
1 | http://sourceware.org/ml/gdb-patches/2011-04/msg00154.html |
2 | Subject: [patch] Workaround buggy GCC PR 47510 produced code | |
3 | ||
4 | Hi, | |
5 | ||
6 | GCC PR debug/47510 is already fixed and GDB has the proper support for it: | |
7 | RFC: update for GCC PR 47510 | |
8 | http://sourceware.org/ml/gdb-patches/2011-03/msg00916.html | |
9 | ||
10 | Still FSF GDB HEAD will crash on a binary produced by older/buggy GCC: | |
11 | Reading symbols from .../gcc46.o...dwarf2read.c:9329: internal-error: could not find partial DIE 0x9a in cache [from module .../gcc46.o] | |
12 | ||
13 | Which may not give much clue to the user. | |
14 | ||
15 | The proposed patch could make false warnings if any code out there has | |
16 | DW_TAG_typedef with children, it does not check for specific GCC versions. | |
17 | Still such DWARF is invalid, although in such case complaint() would be more | |
18 | appropriate than warning(). Does it make sense to differentiate it? | |
19 | ||
20 | No regressions on {x86_64,x86_64-m32,i686}-fedora15-linux-gnu. | |
21 | ||
22 | ||
23 | Thanks, | |
24 | Jan | |
25 | ||
26 | ||
27 | gdb/ | |
28 | 2011-04-11 Jan Kratochvil <jan.kratochvil@redhat.com> | |
29 | ||
30 | * dwarf2read.c (struct dwarf2_per_objfile): New field | |
31 | typedef_children_warning_printed. | |
32 | (load_partial_dies): Read in any children of DW_TAG_typedef with | |
33 | a warning in such case. | |
34 | ||
35 | gdb/testsuite/ | |
36 | 2011-04-11 Jan Kratochvil <jan.kratochvil@redhat.com> | |
37 | ||
38 | * gdb.dwarf2/dw2-typedef-children.S: New file. | |
39 | * gdb.dwarf2/dw2-typedef-children.exp: New file. | |
40 | ||
41 | --- a/gdb/dwarf2read.c | |
42 | +++ b/gdb/dwarf2read.c | |
43 | @@ -209,6 +209,9 @@ struct dwarf2_per_objfile | |
44 | or we are faking it for OBJF_READNOW's sake. */ | |
45 | unsigned char using_index; | |
46 | ||
47 | + /* Print the GCC PR debug/47510 warning only once per objfile. */ | |
48 | + unsigned typedef_children_warning_printed : 1; | |
49 | + | |
50 | /* The mapped index, or NULL if .gdb_index is missing or not being used. */ | |
51 | struct mapped_index *index_table; | |
52 | ||
53 | @@ -8951,7 +8954,7 @@ load_partial_dies (bfd *abfd, gdb_byte *buffer, gdb_byte *info_ptr, | |
54 | if (parent_die == NULL | |
55 | && part_die->has_specification == 0 | |
56 | && part_die->is_declaration == 0 | |
57 | - && (part_die->tag == DW_TAG_typedef | |
58 | + && ((part_die->tag == DW_TAG_typedef && !part_die->has_children) | |
59 | || part_die->tag == DW_TAG_base_type | |
60 | || part_die->tag == DW_TAG_subrange_type)) | |
61 | { | |
62 | @@ -8964,6 +8967,20 @@ load_partial_dies (bfd *abfd, gdb_byte *buffer, gdb_byte *info_ptr, | |
63 | continue; | |
64 | } | |
65 | ||
66 | + /* The exception for DW_TAG_typedef with has_children above is | |
67 | + a workaround of GCC PR debug/47510. GDB crashed on broken GCC output | |
68 | + as it skipped children of DW_TAG_typedef by the shortcut above and | |
69 | + then it could not find the child DIEs referenced later. */ | |
70 | + | |
71 | + if (!dwarf2_per_objfile->typedef_children_warning_printed | |
72 | + && part_die->tag == DW_TAG_typedef && part_die->has_children) | |
73 | + { | |
74 | + warning (_("DW_TAG_typedef has childen - GCC PR debug/47510 bug " | |
75 | + "- DIE at 0x%x [in module %s]"), | |
76 | + part_die->offset, cu->objfile->name); | |
77 | + dwarf2_per_objfile->typedef_children_warning_printed = 1; | |
78 | + } | |
79 | + | |
80 | /* If we're at the second level, and we're an enumerator, and | |
81 | our parent has no specification (meaning possibly lives in a | |
82 | namespace elsewhere), then we can add the partial symbol now | |
83 | --- /dev/null | |
84 | +++ b/gdb/testsuite/gdb.dwarf2/dw2-typedef-children.S | |
85 | @@ -0,0 +1,92 @@ | |
86 | +/* This testcase is part of GDB, the GNU debugger. | |
87 | + | |
88 | + Copyright 2011 Free Software Foundation, Inc. | |
89 | + | |
90 | + This program is free software; you can redistribute it and/or modify | |
91 | + it under the terms of the GNU General Public License as published by | |
92 | + the Free Software Foundation; either version 3 of the License, or | |
93 | + (at your option) any later version. | |
94 | + | |
95 | + This program is distributed in the hope that it will be useful, | |
96 | + but WITHOUT ANY WARRANTY; without even the implied warranty of | |
97 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
98 | + GNU General Public License for more details. | |
99 | + | |
100 | + You should have received a copy of the GNU General Public License | |
101 | + along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
102 | + | |
103 | +/* Debug information */ | |
104 | + | |
105 | + .section .debug_info | |
106 | +.Lcu1_begin: | |
107 | + /* CU header */ | |
108 | + .4byte .Lcu1_end - .Lcu1_start /* Length of Compilation Unit */ | |
109 | +.Lcu1_start: | |
110 | + .2byte 2 /* DWARF Version */ | |
111 | + .4byte .Labbrev1_begin /* Offset into abbrev section */ | |
112 | + .byte 4 /* Pointer size */ | |
113 | + | |
114 | + /* CU die */ | |
115 | + .uleb128 1 /* Abbrev: DW_TAG_compile_unit */ | |
116 | + .ascii "file1.txt\0" /* DW_AT_name */ | |
117 | + .ascii "GNU C 3.3.3\0" /* DW_AT_producer */ | |
118 | + .byte 1 /* DW_AT_language (C) */ | |
119 | + | |
120 | +.Ltype_int: | |
121 | + .uleb128 2 /* Abbrev: DW_TAG_base_type */ | |
122 | + .ascii "int\0" /* DW_AT_name */ | |
123 | + .byte 4 /* DW_AT_byte_size */ | |
124 | + .byte 5 /* DW_AT_encoding */ | |
125 | + | |
126 | + .uleb128 0x3 /* (DIE (0x38) DW_TAG_typedef) */ | |
127 | + .ascii "new\0" /* DW_AT_name */ | |
128 | + .long .Ltype_int - .Lcu1_begin /* DW_AT_type */ | |
129 | + | |
130 | + .uleb128 2 /* Abbrev: DW_TAG_base_type */ | |
131 | + .ascii "int\0" /* DW_AT_name */ | |
132 | + .byte 4 /* DW_AT_byte_size */ | |
133 | + .byte 5 /* DW_AT_encoding */ | |
134 | + | |
135 | + .uleb128 0 /* End of DW_TAG_typedef */ | |
136 | + .uleb128 0 /* End of DW_TAG_compile_unit */ | |
137 | +.Lcu1_end: | |
138 | + | |
139 | +/* Abbrev table */ | |
140 | + .section .debug_abbrev | |
141 | +.Labbrev1_begin: | |
142 | + .uleb128 1 /* Abbrev code */ | |
143 | + .uleb128 0x11 /* DW_TAG_compile_unit */ | |
144 | + .byte 1 /* has_children */ | |
145 | + .uleb128 0x3 /* DW_AT_name */ | |
146 | + .uleb128 0x8 /* DW_FORM_string */ | |
147 | + .uleb128 0x25 /* DW_AT_producer */ | |
148 | + .uleb128 0x8 /* DW_FORM_string */ | |
149 | + .uleb128 0x13 /* DW_AT_language */ | |
150 | + .uleb128 0xb /* DW_FORM_data1 */ | |
151 | + .byte 0x0 /* Terminator */ | |
152 | + .byte 0x0 /* Terminator */ | |
153 | + | |
154 | + .uleb128 2 /* Abbrev code */ | |
155 | + .uleb128 0x24 /* DW_TAG_base_type */ | |
156 | + .byte 0 /* has_children */ | |
157 | + .uleb128 0x3 /* DW_AT_name */ | |
158 | + .uleb128 0x8 /* DW_FORM_string */ | |
159 | + .uleb128 0xb /* DW_AT_byte_size */ | |
160 | + .uleb128 0xb /* DW_FORM_data1 */ | |
161 | + .uleb128 0x3e /* DW_AT_encoding */ | |
162 | + .uleb128 0xb /* DW_FORM_data1 */ | |
163 | + .byte 0x0 /* Terminator */ | |
164 | + .byte 0x0 /* Terminator */ | |
165 | + | |
166 | + .uleb128 0x3 /* (abbrev code) */ | |
167 | + .uleb128 0x16 /* (TAG: DW_TAG_typedef) */ | |
168 | + .byte 0x1 /* DW_children_yes */ | |
169 | + .uleb128 0x3 /* (DW_AT_name) */ | |
170 | + .uleb128 0x8 /* (DW_FORM_string) */ | |
171 | + .uleb128 0x49 /* (DW_AT_type) */ | |
172 | + .uleb128 0x13 /* (DW_FORM_ref4) */ | |
173 | + .byte 0x0 | |
174 | + .byte 0x0 | |
175 | + | |
176 | + .byte 0x0 /* Terminator */ | |
177 | + .byte 0x0 /* Terminator */ | |
178 | --- /dev/null | |
179 | +++ b/gdb/testsuite/gdb.dwarf2/dw2-typedef-children.exp | |
180 | @@ -0,0 +1,37 @@ | |
181 | +# Copyright 2011 Free Software Foundation, Inc. | |
182 | + | |
183 | +# This program is free software; you can redistribute it and/or modify | |
184 | +# it under the terms of the GNU General Public License as published by | |
185 | +# the Free Software Foundation; either version 3 of the License, or | |
186 | +# (at your option) any later version. | |
187 | +# | |
188 | +# This program is distributed in the hope that it will be useful, | |
189 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
190 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
191 | +# GNU General Public License for more details. | |
192 | +# | |
193 | +# You should have received a copy of the GNU General Public License | |
194 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
195 | +load_lib dwarf.exp | |
196 | + | |
197 | +# Note: Inspired from dw2-basic.exp. | |
198 | + | |
199 | +# This test can only be run on targets which support DWARF-2 and use gas. | |
200 | +if {![dwarf2_support]} { | |
201 | + return 0 | |
202 | +} | |
203 | + | |
204 | +set testfile "dw2-typedef-children" | |
205 | +set srcfile ${testfile}.S | |
206 | +set binfile ${objdir}/${subdir}/${testfile}.x | |
207 | + | |
208 | +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" object {nodebug}] != "" } { | |
209 | + return -1 | |
210 | +} | |
211 | + | |
212 | +gdb_exit | |
213 | +gdb_start | |
214 | + | |
215 | +gdb_test "file $binfile" \ | |
216 | + "warning: DW_TAG_typedef has childen - GCC PR debug/47510 bug - DIE at .*" \ | |
217 | + "warning message" | |
218 |