]>
Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Support routines for manipulating internal types for GDB. |
4f2aea11 | 2 | |
32d0add0 | 3 | Copyright (C) 1992-2015 Free Software Foundation, Inc. |
4f2aea11 | 4 | |
c906108c SS |
5 | Contributed by Cygnus Support, using pieces from other GDB modules. |
6 | ||
c5aa993b | 7 | This file is part of GDB. |
c906108c | 8 | |
c5aa993b JM |
9 | This program is free software; you can redistribute it and/or modify |
10 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 11 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 12 | (at your option) any later version. |
c906108c | 13 | |
c5aa993b JM |
14 | This program is distributed in the hope that it will be useful, |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | GNU General Public License for more details. | |
c906108c | 18 | |
c5aa993b | 19 | You should have received a copy of the GNU General Public License |
a9762ec7 | 20 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
21 | |
22 | #include "defs.h" | |
c906108c SS |
23 | #include "bfd.h" |
24 | #include "symtab.h" | |
25 | #include "symfile.h" | |
26 | #include "objfiles.h" | |
27 | #include "gdbtypes.h" | |
28 | #include "expression.h" | |
29 | #include "language.h" | |
30 | #include "target.h" | |
31 | #include "value.h" | |
32 | #include "demangle.h" | |
33 | #include "complaints.h" | |
34 | #include "gdbcmd.h" | |
015a42b4 | 35 | #include "cp-abi.h" |
ae5a43e0 | 36 | #include "hashtab.h" |
8de20a37 | 37 | #include "cp-support.h" |
ca092b61 DE |
38 | #include "bcache.h" |
39 | #include "dwarf2loc.h" | |
80180f79 | 40 | #include "gdbcore.h" |
ac3aafc7 | 41 | |
6403aeea SW |
42 | /* Initialize BADNESS constants. */ |
43 | ||
a9d5ef47 | 44 | const struct rank LENGTH_MISMATCH_BADNESS = {100,0}; |
6403aeea | 45 | |
a9d5ef47 SW |
46 | const struct rank TOO_FEW_PARAMS_BADNESS = {100,0}; |
47 | const struct rank INCOMPATIBLE_TYPE_BADNESS = {100,0}; | |
6403aeea | 48 | |
a9d5ef47 | 49 | const struct rank EXACT_MATCH_BADNESS = {0,0}; |
6403aeea | 50 | |
a9d5ef47 SW |
51 | const struct rank INTEGER_PROMOTION_BADNESS = {1,0}; |
52 | const struct rank FLOAT_PROMOTION_BADNESS = {1,0}; | |
53 | const struct rank BASE_PTR_CONVERSION_BADNESS = {1,0}; | |
54 | const struct rank INTEGER_CONVERSION_BADNESS = {2,0}; | |
55 | const struct rank FLOAT_CONVERSION_BADNESS = {2,0}; | |
56 | const struct rank INT_FLOAT_CONVERSION_BADNESS = {2,0}; | |
57 | const struct rank VOID_PTR_CONVERSION_BADNESS = {2,0}; | |
5b4f6e25 | 58 | const struct rank BOOL_CONVERSION_BADNESS = {3,0}; |
a9d5ef47 SW |
59 | const struct rank BASE_CONVERSION_BADNESS = {2,0}; |
60 | const struct rank REFERENCE_CONVERSION_BADNESS = {2,0}; | |
da096638 | 61 | const struct rank NULL_POINTER_CONVERSION_BADNESS = {2,0}; |
a9d5ef47 | 62 | const struct rank NS_POINTER_CONVERSION_BADNESS = {10,0}; |
a451cb65 | 63 | const struct rank NS_INTEGER_POINTER_CONVERSION_BADNESS = {3,0}; |
6403aeea | 64 | |
8da61cc4 | 65 | /* Floatformat pairs. */ |
f9e9243a UW |
66 | const struct floatformat *floatformats_ieee_half[BFD_ENDIAN_UNKNOWN] = { |
67 | &floatformat_ieee_half_big, | |
68 | &floatformat_ieee_half_little | |
69 | }; | |
8da61cc4 DJ |
70 | const struct floatformat *floatformats_ieee_single[BFD_ENDIAN_UNKNOWN] = { |
71 | &floatformat_ieee_single_big, | |
72 | &floatformat_ieee_single_little | |
73 | }; | |
74 | const struct floatformat *floatformats_ieee_double[BFD_ENDIAN_UNKNOWN] = { | |
75 | &floatformat_ieee_double_big, | |
76 | &floatformat_ieee_double_little | |
77 | }; | |
78 | const struct floatformat *floatformats_ieee_double_littlebyte_bigword[BFD_ENDIAN_UNKNOWN] = { | |
79 | &floatformat_ieee_double_big, | |
80 | &floatformat_ieee_double_littlebyte_bigword | |
81 | }; | |
82 | const struct floatformat *floatformats_i387_ext[BFD_ENDIAN_UNKNOWN] = { | |
83 | &floatformat_i387_ext, | |
84 | &floatformat_i387_ext | |
85 | }; | |
86 | const struct floatformat *floatformats_m68881_ext[BFD_ENDIAN_UNKNOWN] = { | |
87 | &floatformat_m68881_ext, | |
88 | &floatformat_m68881_ext | |
89 | }; | |
90 | const struct floatformat *floatformats_arm_ext[BFD_ENDIAN_UNKNOWN] = { | |
91 | &floatformat_arm_ext_big, | |
92 | &floatformat_arm_ext_littlebyte_bigword | |
93 | }; | |
94 | const struct floatformat *floatformats_ia64_spill[BFD_ENDIAN_UNKNOWN] = { | |
95 | &floatformat_ia64_spill_big, | |
96 | &floatformat_ia64_spill_little | |
97 | }; | |
98 | const struct floatformat *floatformats_ia64_quad[BFD_ENDIAN_UNKNOWN] = { | |
99 | &floatformat_ia64_quad_big, | |
100 | &floatformat_ia64_quad_little | |
101 | }; | |
102 | const struct floatformat *floatformats_vax_f[BFD_ENDIAN_UNKNOWN] = { | |
103 | &floatformat_vax_f, | |
104 | &floatformat_vax_f | |
105 | }; | |
106 | const struct floatformat *floatformats_vax_d[BFD_ENDIAN_UNKNOWN] = { | |
107 | &floatformat_vax_d, | |
108 | &floatformat_vax_d | |
109 | }; | |
b14d30e1 | 110 | const struct floatformat *floatformats_ibm_long_double[BFD_ENDIAN_UNKNOWN] = { |
f5aee5ee AM |
111 | &floatformat_ibm_long_double_big, |
112 | &floatformat_ibm_long_double_little | |
b14d30e1 | 113 | }; |
8da61cc4 | 114 | |
2873700e KS |
115 | /* Should opaque types be resolved? */ |
116 | ||
117 | static int opaque_type_resolution = 1; | |
118 | ||
119 | /* A flag to enable printing of debugging information of C++ | |
120 | overloading. */ | |
121 | ||
122 | unsigned int overload_debug = 0; | |
123 | ||
a451cb65 KS |
124 | /* A flag to enable strict type checking. */ |
125 | ||
126 | static int strict_type_checking = 1; | |
127 | ||
2873700e | 128 | /* A function to show whether opaque types are resolved. */ |
5212577a | 129 | |
920d2a44 AC |
130 | static void |
131 | show_opaque_type_resolution (struct ui_file *file, int from_tty, | |
7ba81444 MS |
132 | struct cmd_list_element *c, |
133 | const char *value) | |
920d2a44 | 134 | { |
3e43a32a MS |
135 | fprintf_filtered (file, _("Resolution of opaque struct/class/union types " |
136 | "(if set before loading symbols) is %s.\n"), | |
920d2a44 AC |
137 | value); |
138 | } | |
139 | ||
2873700e | 140 | /* A function to show whether C++ overload debugging is enabled. */ |
5212577a | 141 | |
920d2a44 AC |
142 | static void |
143 | show_overload_debug (struct ui_file *file, int from_tty, | |
144 | struct cmd_list_element *c, const char *value) | |
145 | { | |
7ba81444 MS |
146 | fprintf_filtered (file, _("Debugging of C++ overloading is %s.\n"), |
147 | value); | |
920d2a44 | 148 | } |
c906108c | 149 | |
a451cb65 KS |
150 | /* A function to show the status of strict type checking. */ |
151 | ||
152 | static void | |
153 | show_strict_type_checking (struct ui_file *file, int from_tty, | |
154 | struct cmd_list_element *c, const char *value) | |
155 | { | |
156 | fprintf_filtered (file, _("Strict type checking is %s.\n"), value); | |
157 | } | |
158 | ||
5212577a | 159 | \f |
e9bb382b UW |
160 | /* Allocate a new OBJFILE-associated type structure and fill it |
161 | with some defaults. Space for the type structure is allocated | |
162 | on the objfile's objfile_obstack. */ | |
c906108c SS |
163 | |
164 | struct type * | |
fba45db2 | 165 | alloc_type (struct objfile *objfile) |
c906108c | 166 | { |
52f0bd74 | 167 | struct type *type; |
c906108c | 168 | |
e9bb382b UW |
169 | gdb_assert (objfile != NULL); |
170 | ||
7ba81444 | 171 | /* Alloc the structure and start off with all fields zeroed. */ |
e9bb382b UW |
172 | type = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct type); |
173 | TYPE_MAIN_TYPE (type) = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
174 | struct main_type); | |
175 | OBJSTAT (objfile, n_types++); | |
c906108c | 176 | |
e9bb382b UW |
177 | TYPE_OBJFILE_OWNED (type) = 1; |
178 | TYPE_OWNER (type).objfile = objfile; | |
c906108c | 179 | |
7ba81444 | 180 | /* Initialize the fields that might not be zero. */ |
c906108c SS |
181 | |
182 | TYPE_CODE (type) = TYPE_CODE_UNDEF; | |
2fdde8f8 | 183 | TYPE_CHAIN (type) = type; /* Chain back to itself. */ |
c906108c | 184 | |
c16abbde | 185 | return type; |
c906108c SS |
186 | } |
187 | ||
e9bb382b UW |
188 | /* Allocate a new GDBARCH-associated type structure and fill it |
189 | with some defaults. Space for the type structure is allocated | |
190 | on the heap. */ | |
191 | ||
192 | struct type * | |
193 | alloc_type_arch (struct gdbarch *gdbarch) | |
194 | { | |
195 | struct type *type; | |
196 | ||
197 | gdb_assert (gdbarch != NULL); | |
198 | ||
199 | /* Alloc the structure and start off with all fields zeroed. */ | |
200 | ||
41bf6aca TT |
201 | type = XCNEW (struct type); |
202 | TYPE_MAIN_TYPE (type) = XCNEW (struct main_type); | |
e9bb382b UW |
203 | |
204 | TYPE_OBJFILE_OWNED (type) = 0; | |
205 | TYPE_OWNER (type).gdbarch = gdbarch; | |
206 | ||
207 | /* Initialize the fields that might not be zero. */ | |
208 | ||
209 | TYPE_CODE (type) = TYPE_CODE_UNDEF; | |
e9bb382b UW |
210 | TYPE_CHAIN (type) = type; /* Chain back to itself. */ |
211 | ||
212 | return type; | |
213 | } | |
214 | ||
215 | /* If TYPE is objfile-associated, allocate a new type structure | |
216 | associated with the same objfile. If TYPE is gdbarch-associated, | |
217 | allocate a new type structure associated with the same gdbarch. */ | |
218 | ||
219 | struct type * | |
220 | alloc_type_copy (const struct type *type) | |
221 | { | |
222 | if (TYPE_OBJFILE_OWNED (type)) | |
223 | return alloc_type (TYPE_OWNER (type).objfile); | |
224 | else | |
225 | return alloc_type_arch (TYPE_OWNER (type).gdbarch); | |
226 | } | |
227 | ||
228 | /* If TYPE is gdbarch-associated, return that architecture. | |
229 | If TYPE is objfile-associated, return that objfile's architecture. */ | |
230 | ||
231 | struct gdbarch * | |
232 | get_type_arch (const struct type *type) | |
233 | { | |
234 | if (TYPE_OBJFILE_OWNED (type)) | |
235 | return get_objfile_arch (TYPE_OWNER (type).objfile); | |
236 | else | |
237 | return TYPE_OWNER (type).gdbarch; | |
238 | } | |
239 | ||
99ad9427 YQ |
240 | /* See gdbtypes.h. */ |
241 | ||
242 | struct type * | |
243 | get_target_type (struct type *type) | |
244 | { | |
245 | if (type != NULL) | |
246 | { | |
247 | type = TYPE_TARGET_TYPE (type); | |
248 | if (type != NULL) | |
249 | type = check_typedef (type); | |
250 | } | |
251 | ||
252 | return type; | |
253 | } | |
254 | ||
2e056931 SM |
255 | /* See gdbtypes.h. */ |
256 | ||
257 | unsigned int | |
258 | type_length_units (struct type *type) | |
259 | { | |
260 | struct gdbarch *arch = get_type_arch (type); | |
261 | int unit_size = gdbarch_addressable_memory_unit_size (arch); | |
262 | ||
263 | return TYPE_LENGTH (type) / unit_size; | |
264 | } | |
265 | ||
2fdde8f8 DJ |
266 | /* Alloc a new type instance structure, fill it with some defaults, |
267 | and point it at OLDTYPE. Allocate the new type instance from the | |
268 | same place as OLDTYPE. */ | |
269 | ||
270 | static struct type * | |
271 | alloc_type_instance (struct type *oldtype) | |
272 | { | |
273 | struct type *type; | |
274 | ||
275 | /* Allocate the structure. */ | |
276 | ||
e9bb382b | 277 | if (! TYPE_OBJFILE_OWNED (oldtype)) |
41bf6aca | 278 | type = XCNEW (struct type); |
2fdde8f8 | 279 | else |
1deafd4e PA |
280 | type = OBSTACK_ZALLOC (&TYPE_OBJFILE (oldtype)->objfile_obstack, |
281 | struct type); | |
282 | ||
2fdde8f8 DJ |
283 | TYPE_MAIN_TYPE (type) = TYPE_MAIN_TYPE (oldtype); |
284 | ||
285 | TYPE_CHAIN (type) = type; /* Chain back to itself for now. */ | |
286 | ||
c16abbde | 287 | return type; |
2fdde8f8 DJ |
288 | } |
289 | ||
290 | /* Clear all remnants of the previous type at TYPE, in preparation for | |
e9bb382b | 291 | replacing it with something else. Preserve owner information. */ |
5212577a | 292 | |
2fdde8f8 DJ |
293 | static void |
294 | smash_type (struct type *type) | |
295 | { | |
e9bb382b UW |
296 | int objfile_owned = TYPE_OBJFILE_OWNED (type); |
297 | union type_owner owner = TYPE_OWNER (type); | |
298 | ||
2fdde8f8 DJ |
299 | memset (TYPE_MAIN_TYPE (type), 0, sizeof (struct main_type)); |
300 | ||
e9bb382b UW |
301 | /* Restore owner information. */ |
302 | TYPE_OBJFILE_OWNED (type) = objfile_owned; | |
303 | TYPE_OWNER (type) = owner; | |
304 | ||
2fdde8f8 DJ |
305 | /* For now, delete the rings. */ |
306 | TYPE_CHAIN (type) = type; | |
307 | ||
308 | /* For now, leave the pointer/reference types alone. */ | |
309 | } | |
310 | ||
c906108c SS |
311 | /* Lookup a pointer to a type TYPE. TYPEPTR, if nonzero, points |
312 | to a pointer to memory where the pointer type should be stored. | |
313 | If *TYPEPTR is zero, update it to point to the pointer type we return. | |
314 | We allocate new memory if needed. */ | |
315 | ||
316 | struct type * | |
fba45db2 | 317 | make_pointer_type (struct type *type, struct type **typeptr) |
c906108c | 318 | { |
52f0bd74 | 319 | struct type *ntype; /* New type */ |
053cb41b | 320 | struct type *chain; |
c906108c SS |
321 | |
322 | ntype = TYPE_POINTER_TYPE (type); | |
323 | ||
c5aa993b | 324 | if (ntype) |
c906108c | 325 | { |
c5aa993b | 326 | if (typeptr == 0) |
7ba81444 MS |
327 | return ntype; /* Don't care about alloc, |
328 | and have new type. */ | |
c906108c | 329 | else if (*typeptr == 0) |
c5aa993b | 330 | { |
7ba81444 | 331 | *typeptr = ntype; /* Tracking alloc, and have new type. */ |
c906108c | 332 | return ntype; |
c5aa993b | 333 | } |
c906108c SS |
334 | } |
335 | ||
336 | if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */ | |
337 | { | |
e9bb382b | 338 | ntype = alloc_type_copy (type); |
c906108c SS |
339 | if (typeptr) |
340 | *typeptr = ntype; | |
341 | } | |
7ba81444 | 342 | else /* We have storage, but need to reset it. */ |
c906108c SS |
343 | { |
344 | ntype = *typeptr; | |
053cb41b | 345 | chain = TYPE_CHAIN (ntype); |
2fdde8f8 | 346 | smash_type (ntype); |
053cb41b | 347 | TYPE_CHAIN (ntype) = chain; |
c906108c SS |
348 | } |
349 | ||
350 | TYPE_TARGET_TYPE (ntype) = type; | |
351 | TYPE_POINTER_TYPE (type) = ntype; | |
352 | ||
5212577a | 353 | /* FIXME! Assumes the machine has only one representation for pointers! */ |
c906108c | 354 | |
50810684 UW |
355 | TYPE_LENGTH (ntype) |
356 | = gdbarch_ptr_bit (get_type_arch (type)) / TARGET_CHAR_BIT; | |
c906108c SS |
357 | TYPE_CODE (ntype) = TYPE_CODE_PTR; |
358 | ||
67b2adb2 | 359 | /* Mark pointers as unsigned. The target converts between pointers |
76e71323 | 360 | and addresses (CORE_ADDRs) using gdbarch_pointer_to_address and |
7ba81444 | 361 | gdbarch_address_to_pointer. */ |
876cecd0 | 362 | TYPE_UNSIGNED (ntype) = 1; |
c5aa993b | 363 | |
053cb41b JB |
364 | /* Update the length of all the other variants of this type. */ |
365 | chain = TYPE_CHAIN (ntype); | |
366 | while (chain != ntype) | |
367 | { | |
368 | TYPE_LENGTH (chain) = TYPE_LENGTH (ntype); | |
369 | chain = TYPE_CHAIN (chain); | |
370 | } | |
371 | ||
c906108c SS |
372 | return ntype; |
373 | } | |
374 | ||
375 | /* Given a type TYPE, return a type of pointers to that type. | |
376 | May need to construct such a type if this is the first use. */ | |
377 | ||
378 | struct type * | |
fba45db2 | 379 | lookup_pointer_type (struct type *type) |
c906108c | 380 | { |
c5aa993b | 381 | return make_pointer_type (type, (struct type **) 0); |
c906108c SS |
382 | } |
383 | ||
7ba81444 MS |
384 | /* Lookup a C++ `reference' to a type TYPE. TYPEPTR, if nonzero, |
385 | points to a pointer to memory where the reference type should be | |
386 | stored. If *TYPEPTR is zero, update it to point to the reference | |
387 | type we return. We allocate new memory if needed. */ | |
c906108c SS |
388 | |
389 | struct type * | |
fba45db2 | 390 | make_reference_type (struct type *type, struct type **typeptr) |
c906108c | 391 | { |
52f0bd74 | 392 | struct type *ntype; /* New type */ |
1e98b326 | 393 | struct type *chain; |
c906108c SS |
394 | |
395 | ntype = TYPE_REFERENCE_TYPE (type); | |
396 | ||
c5aa993b | 397 | if (ntype) |
c906108c | 398 | { |
c5aa993b | 399 | if (typeptr == 0) |
7ba81444 MS |
400 | return ntype; /* Don't care about alloc, |
401 | and have new type. */ | |
c906108c | 402 | else if (*typeptr == 0) |
c5aa993b | 403 | { |
7ba81444 | 404 | *typeptr = ntype; /* Tracking alloc, and have new type. */ |
c906108c | 405 | return ntype; |
c5aa993b | 406 | } |
c906108c SS |
407 | } |
408 | ||
409 | if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */ | |
410 | { | |
e9bb382b | 411 | ntype = alloc_type_copy (type); |
c906108c SS |
412 | if (typeptr) |
413 | *typeptr = ntype; | |
414 | } | |
7ba81444 | 415 | else /* We have storage, but need to reset it. */ |
c906108c SS |
416 | { |
417 | ntype = *typeptr; | |
1e98b326 | 418 | chain = TYPE_CHAIN (ntype); |
2fdde8f8 | 419 | smash_type (ntype); |
1e98b326 | 420 | TYPE_CHAIN (ntype) = chain; |
c906108c SS |
421 | } |
422 | ||
423 | TYPE_TARGET_TYPE (ntype) = type; | |
424 | TYPE_REFERENCE_TYPE (type) = ntype; | |
425 | ||
7ba81444 MS |
426 | /* FIXME! Assume the machine has only one representation for |
427 | references, and that it matches the (only) representation for | |
428 | pointers! */ | |
c906108c | 429 | |
50810684 UW |
430 | TYPE_LENGTH (ntype) = |
431 | gdbarch_ptr_bit (get_type_arch (type)) / TARGET_CHAR_BIT; | |
c906108c | 432 | TYPE_CODE (ntype) = TYPE_CODE_REF; |
c5aa993b | 433 | |
c906108c SS |
434 | if (!TYPE_REFERENCE_TYPE (type)) /* Remember it, if don't have one. */ |
435 | TYPE_REFERENCE_TYPE (type) = ntype; | |
436 | ||
1e98b326 JB |
437 | /* Update the length of all the other variants of this type. */ |
438 | chain = TYPE_CHAIN (ntype); | |
439 | while (chain != ntype) | |
440 | { | |
441 | TYPE_LENGTH (chain) = TYPE_LENGTH (ntype); | |
442 | chain = TYPE_CHAIN (chain); | |
443 | } | |
444 | ||
c906108c SS |
445 | return ntype; |
446 | } | |
447 | ||
7ba81444 MS |
448 | /* Same as above, but caller doesn't care about memory allocation |
449 | details. */ | |
c906108c SS |
450 | |
451 | struct type * | |
fba45db2 | 452 | lookup_reference_type (struct type *type) |
c906108c | 453 | { |
c5aa993b | 454 | return make_reference_type (type, (struct type **) 0); |
c906108c SS |
455 | } |
456 | ||
7ba81444 MS |
457 | /* Lookup a function type that returns type TYPE. TYPEPTR, if |
458 | nonzero, points to a pointer to memory where the function type | |
459 | should be stored. If *TYPEPTR is zero, update it to point to the | |
0c8b41f1 | 460 | function type we return. We allocate new memory if needed. */ |
c906108c SS |
461 | |
462 | struct type * | |
0c8b41f1 | 463 | make_function_type (struct type *type, struct type **typeptr) |
c906108c | 464 | { |
52f0bd74 | 465 | struct type *ntype; /* New type */ |
c906108c SS |
466 | |
467 | if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */ | |
468 | { | |
e9bb382b | 469 | ntype = alloc_type_copy (type); |
c906108c SS |
470 | if (typeptr) |
471 | *typeptr = ntype; | |
472 | } | |
7ba81444 | 473 | else /* We have storage, but need to reset it. */ |
c906108c SS |
474 | { |
475 | ntype = *typeptr; | |
2fdde8f8 | 476 | smash_type (ntype); |
c906108c SS |
477 | } |
478 | ||
479 | TYPE_TARGET_TYPE (ntype) = type; | |
480 | ||
481 | TYPE_LENGTH (ntype) = 1; | |
482 | TYPE_CODE (ntype) = TYPE_CODE_FUNC; | |
c5aa993b | 483 | |
b6cdc2c1 JK |
484 | INIT_FUNC_SPECIFIC (ntype); |
485 | ||
c906108c SS |
486 | return ntype; |
487 | } | |
488 | ||
c906108c SS |
489 | /* Given a type TYPE, return a type of functions that return that type. |
490 | May need to construct such a type if this is the first use. */ | |
491 | ||
492 | struct type * | |
fba45db2 | 493 | lookup_function_type (struct type *type) |
c906108c | 494 | { |
0c8b41f1 | 495 | return make_function_type (type, (struct type **) 0); |
c906108c SS |
496 | } |
497 | ||
71918a86 | 498 | /* Given a type TYPE and argument types, return the appropriate |
a6fb9c08 TT |
499 | function type. If the final type in PARAM_TYPES is NULL, make a |
500 | varargs function. */ | |
71918a86 TT |
501 | |
502 | struct type * | |
503 | lookup_function_type_with_arguments (struct type *type, | |
504 | int nparams, | |
505 | struct type **param_types) | |
506 | { | |
507 | struct type *fn = make_function_type (type, (struct type **) 0); | |
508 | int i; | |
509 | ||
e314d629 | 510 | if (nparams > 0) |
a6fb9c08 | 511 | { |
e314d629 TT |
512 | if (param_types[nparams - 1] == NULL) |
513 | { | |
514 | --nparams; | |
515 | TYPE_VARARGS (fn) = 1; | |
516 | } | |
517 | else if (TYPE_CODE (check_typedef (param_types[nparams - 1])) | |
518 | == TYPE_CODE_VOID) | |
519 | { | |
520 | --nparams; | |
521 | /* Caller should have ensured this. */ | |
522 | gdb_assert (nparams == 0); | |
523 | TYPE_PROTOTYPED (fn) = 1; | |
524 | } | |
a6fb9c08 TT |
525 | } |
526 | ||
71918a86 TT |
527 | TYPE_NFIELDS (fn) = nparams; |
528 | TYPE_FIELDS (fn) = TYPE_ZALLOC (fn, nparams * sizeof (struct field)); | |
529 | for (i = 0; i < nparams; ++i) | |
530 | TYPE_FIELD_TYPE (fn, i) = param_types[i]; | |
531 | ||
532 | return fn; | |
533 | } | |
534 | ||
47663de5 MS |
535 | /* Identify address space identifier by name -- |
536 | return the integer flag defined in gdbtypes.h. */ | |
5212577a DE |
537 | |
538 | int | |
50810684 | 539 | address_space_name_to_int (struct gdbarch *gdbarch, char *space_identifier) |
47663de5 | 540 | { |
8b2dbe47 | 541 | int type_flags; |
d8734c88 | 542 | |
7ba81444 | 543 | /* Check for known address space delimiters. */ |
47663de5 | 544 | if (!strcmp (space_identifier, "code")) |
876cecd0 | 545 | return TYPE_INSTANCE_FLAG_CODE_SPACE; |
47663de5 | 546 | else if (!strcmp (space_identifier, "data")) |
876cecd0 | 547 | return TYPE_INSTANCE_FLAG_DATA_SPACE; |
5f11f355 AC |
548 | else if (gdbarch_address_class_name_to_type_flags_p (gdbarch) |
549 | && gdbarch_address_class_name_to_type_flags (gdbarch, | |
550 | space_identifier, | |
551 | &type_flags)) | |
8b2dbe47 | 552 | return type_flags; |
47663de5 | 553 | else |
8a3fe4f8 | 554 | error (_("Unknown address space specifier: \"%s\""), space_identifier); |
47663de5 MS |
555 | } |
556 | ||
557 | /* Identify address space identifier by integer flag as defined in | |
7ba81444 | 558 | gdbtypes.h -- return the string version of the adress space name. */ |
47663de5 | 559 | |
321432c0 | 560 | const char * |
50810684 | 561 | address_space_int_to_name (struct gdbarch *gdbarch, int space_flag) |
47663de5 | 562 | { |
876cecd0 | 563 | if (space_flag & TYPE_INSTANCE_FLAG_CODE_SPACE) |
47663de5 | 564 | return "code"; |
876cecd0 | 565 | else if (space_flag & TYPE_INSTANCE_FLAG_DATA_SPACE) |
47663de5 | 566 | return "data"; |
876cecd0 | 567 | else if ((space_flag & TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL) |
5f11f355 AC |
568 | && gdbarch_address_class_type_flags_to_name_p (gdbarch)) |
569 | return gdbarch_address_class_type_flags_to_name (gdbarch, space_flag); | |
47663de5 MS |
570 | else |
571 | return NULL; | |
572 | } | |
573 | ||
2fdde8f8 | 574 | /* Create a new type with instance flags NEW_FLAGS, based on TYPE. |
ad766c0a JB |
575 | |
576 | If STORAGE is non-NULL, create the new type instance there. | |
577 | STORAGE must be in the same obstack as TYPE. */ | |
47663de5 | 578 | |
b9362cc7 | 579 | static struct type * |
2fdde8f8 DJ |
580 | make_qualified_type (struct type *type, int new_flags, |
581 | struct type *storage) | |
47663de5 MS |
582 | { |
583 | struct type *ntype; | |
584 | ||
585 | ntype = type; | |
5f61c20e JK |
586 | do |
587 | { | |
588 | if (TYPE_INSTANCE_FLAGS (ntype) == new_flags) | |
589 | return ntype; | |
590 | ntype = TYPE_CHAIN (ntype); | |
591 | } | |
592 | while (ntype != type); | |
47663de5 | 593 | |
2fdde8f8 DJ |
594 | /* Create a new type instance. */ |
595 | if (storage == NULL) | |
596 | ntype = alloc_type_instance (type); | |
597 | else | |
598 | { | |
7ba81444 MS |
599 | /* If STORAGE was provided, it had better be in the same objfile |
600 | as TYPE. Otherwise, we can't link it into TYPE's cv chain: | |
601 | if one objfile is freed and the other kept, we'd have | |
602 | dangling pointers. */ | |
ad766c0a JB |
603 | gdb_assert (TYPE_OBJFILE (type) == TYPE_OBJFILE (storage)); |
604 | ||
2fdde8f8 DJ |
605 | ntype = storage; |
606 | TYPE_MAIN_TYPE (ntype) = TYPE_MAIN_TYPE (type); | |
607 | TYPE_CHAIN (ntype) = ntype; | |
608 | } | |
47663de5 MS |
609 | |
610 | /* Pointers or references to the original type are not relevant to | |
2fdde8f8 | 611 | the new type. */ |
47663de5 MS |
612 | TYPE_POINTER_TYPE (ntype) = (struct type *) 0; |
613 | TYPE_REFERENCE_TYPE (ntype) = (struct type *) 0; | |
47663de5 | 614 | |
2fdde8f8 DJ |
615 | /* Chain the new qualified type to the old type. */ |
616 | TYPE_CHAIN (ntype) = TYPE_CHAIN (type); | |
617 | TYPE_CHAIN (type) = ntype; | |
618 | ||
619 | /* Now set the instance flags and return the new type. */ | |
620 | TYPE_INSTANCE_FLAGS (ntype) = new_flags; | |
47663de5 | 621 | |
ab5d3da6 KB |
622 | /* Set length of new type to that of the original type. */ |
623 | TYPE_LENGTH (ntype) = TYPE_LENGTH (type); | |
624 | ||
47663de5 MS |
625 | return ntype; |
626 | } | |
627 | ||
2fdde8f8 DJ |
628 | /* Make an address-space-delimited variant of a type -- a type that |
629 | is identical to the one supplied except that it has an address | |
630 | space attribute attached to it (such as "code" or "data"). | |
631 | ||
7ba81444 MS |
632 | The space attributes "code" and "data" are for Harvard |
633 | architectures. The address space attributes are for architectures | |
634 | which have alternately sized pointers or pointers with alternate | |
635 | representations. */ | |
2fdde8f8 DJ |
636 | |
637 | struct type * | |
638 | make_type_with_address_space (struct type *type, int space_flag) | |
639 | { | |
2fdde8f8 | 640 | int new_flags = ((TYPE_INSTANCE_FLAGS (type) |
876cecd0 TT |
641 | & ~(TYPE_INSTANCE_FLAG_CODE_SPACE |
642 | | TYPE_INSTANCE_FLAG_DATA_SPACE | |
643 | | TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL)) | |
2fdde8f8 DJ |
644 | | space_flag); |
645 | ||
646 | return make_qualified_type (type, new_flags, NULL); | |
647 | } | |
c906108c SS |
648 | |
649 | /* Make a "c-v" variant of a type -- a type that is identical to the | |
650 | one supplied except that it may have const or volatile attributes | |
651 | CNST is a flag for setting the const attribute | |
652 | VOLTL is a flag for setting the volatile attribute | |
653 | TYPE is the base type whose variant we are creating. | |
c906108c | 654 | |
ad766c0a JB |
655 | If TYPEPTR and *TYPEPTR are non-zero, then *TYPEPTR points to |
656 | storage to hold the new qualified type; *TYPEPTR and TYPE must be | |
657 | in the same objfile. Otherwise, allocate fresh memory for the new | |
658 | type whereever TYPE lives. If TYPEPTR is non-zero, set it to the | |
659 | new type we construct. */ | |
5212577a | 660 | |
c906108c | 661 | struct type * |
7ba81444 MS |
662 | make_cv_type (int cnst, int voltl, |
663 | struct type *type, | |
664 | struct type **typeptr) | |
c906108c | 665 | { |
52f0bd74 | 666 | struct type *ntype; /* New type */ |
c906108c | 667 | |
2fdde8f8 | 668 | int new_flags = (TYPE_INSTANCE_FLAGS (type) |
308d96ed MS |
669 | & ~(TYPE_INSTANCE_FLAG_CONST |
670 | | TYPE_INSTANCE_FLAG_VOLATILE)); | |
c906108c | 671 | |
c906108c | 672 | if (cnst) |
876cecd0 | 673 | new_flags |= TYPE_INSTANCE_FLAG_CONST; |
c906108c SS |
674 | |
675 | if (voltl) | |
876cecd0 | 676 | new_flags |= TYPE_INSTANCE_FLAG_VOLATILE; |
a02fd225 | 677 | |
2fdde8f8 | 678 | if (typeptr && *typeptr != NULL) |
a02fd225 | 679 | { |
ad766c0a JB |
680 | /* TYPE and *TYPEPTR must be in the same objfile. We can't have |
681 | a C-V variant chain that threads across objfiles: if one | |
682 | objfile gets freed, then the other has a broken C-V chain. | |
683 | ||
684 | This code used to try to copy over the main type from TYPE to | |
685 | *TYPEPTR if they were in different objfiles, but that's | |
686 | wrong, too: TYPE may have a field list or member function | |
687 | lists, which refer to types of their own, etc. etc. The | |
688 | whole shebang would need to be copied over recursively; you | |
689 | can't have inter-objfile pointers. The only thing to do is | |
690 | to leave stub types as stub types, and look them up afresh by | |
691 | name each time you encounter them. */ | |
692 | gdb_assert (TYPE_OBJFILE (*typeptr) == TYPE_OBJFILE (type)); | |
2fdde8f8 DJ |
693 | } |
694 | ||
7ba81444 MS |
695 | ntype = make_qualified_type (type, new_flags, |
696 | typeptr ? *typeptr : NULL); | |
c906108c | 697 | |
2fdde8f8 DJ |
698 | if (typeptr != NULL) |
699 | *typeptr = ntype; | |
a02fd225 | 700 | |
2fdde8f8 | 701 | return ntype; |
a02fd225 | 702 | } |
c906108c | 703 | |
06d66ee9 TT |
704 | /* Make a 'restrict'-qualified version of TYPE. */ |
705 | ||
706 | struct type * | |
707 | make_restrict_type (struct type *type) | |
708 | { | |
709 | return make_qualified_type (type, | |
710 | (TYPE_INSTANCE_FLAGS (type) | |
711 | | TYPE_INSTANCE_FLAG_RESTRICT), | |
712 | NULL); | |
713 | } | |
714 | ||
f1660027 TT |
715 | /* Make a type without const, volatile, or restrict. */ |
716 | ||
717 | struct type * | |
718 | make_unqualified_type (struct type *type) | |
719 | { | |
720 | return make_qualified_type (type, | |
721 | (TYPE_INSTANCE_FLAGS (type) | |
722 | & ~(TYPE_INSTANCE_FLAG_CONST | |
723 | | TYPE_INSTANCE_FLAG_VOLATILE | |
724 | | TYPE_INSTANCE_FLAG_RESTRICT)), | |
725 | NULL); | |
726 | } | |
727 | ||
a2c2acaf MW |
728 | /* Make a '_Atomic'-qualified version of TYPE. */ |
729 | ||
730 | struct type * | |
731 | make_atomic_type (struct type *type) | |
732 | { | |
733 | return make_qualified_type (type, | |
734 | (TYPE_INSTANCE_FLAGS (type) | |
735 | | TYPE_INSTANCE_FLAG_ATOMIC), | |
736 | NULL); | |
737 | } | |
738 | ||
2fdde8f8 DJ |
739 | /* Replace the contents of ntype with the type *type. This changes the |
740 | contents, rather than the pointer for TYPE_MAIN_TYPE (ntype); thus | |
741 | the changes are propogated to all types in the TYPE_CHAIN. | |
dd6bda65 | 742 | |
cda6c68a JB |
743 | In order to build recursive types, it's inevitable that we'll need |
744 | to update types in place --- but this sort of indiscriminate | |
745 | smashing is ugly, and needs to be replaced with something more | |
2fdde8f8 DJ |
746 | controlled. TYPE_MAIN_TYPE is a step in this direction; it's not |
747 | clear if more steps are needed. */ | |
5212577a | 748 | |
dd6bda65 DJ |
749 | void |
750 | replace_type (struct type *ntype, struct type *type) | |
751 | { | |
ab5d3da6 | 752 | struct type *chain; |
dd6bda65 | 753 | |
ad766c0a JB |
754 | /* These two types had better be in the same objfile. Otherwise, |
755 | the assignment of one type's main type structure to the other | |
756 | will produce a type with references to objects (names; field | |
757 | lists; etc.) allocated on an objfile other than its own. */ | |
758 | gdb_assert (TYPE_OBJFILE (ntype) == TYPE_OBJFILE (ntype)); | |
759 | ||
2fdde8f8 | 760 | *TYPE_MAIN_TYPE (ntype) = *TYPE_MAIN_TYPE (type); |
dd6bda65 | 761 | |
7ba81444 MS |
762 | /* The type length is not a part of the main type. Update it for |
763 | each type on the variant chain. */ | |
ab5d3da6 | 764 | chain = ntype; |
5f61c20e JK |
765 | do |
766 | { | |
767 | /* Assert that this element of the chain has no address-class bits | |
768 | set in its flags. Such type variants might have type lengths | |
769 | which are supposed to be different from the non-address-class | |
770 | variants. This assertion shouldn't ever be triggered because | |
771 | symbol readers which do construct address-class variants don't | |
772 | call replace_type(). */ | |
773 | gdb_assert (TYPE_ADDRESS_CLASS_ALL (chain) == 0); | |
774 | ||
775 | TYPE_LENGTH (chain) = TYPE_LENGTH (type); | |
776 | chain = TYPE_CHAIN (chain); | |
777 | } | |
778 | while (ntype != chain); | |
ab5d3da6 | 779 | |
2fdde8f8 DJ |
780 | /* Assert that the two types have equivalent instance qualifiers. |
781 | This should be true for at least all of our debug readers. */ | |
782 | gdb_assert (TYPE_INSTANCE_FLAGS (ntype) == TYPE_INSTANCE_FLAGS (type)); | |
dd6bda65 DJ |
783 | } |
784 | ||
c906108c SS |
785 | /* Implement direct support for MEMBER_TYPE in GNU C++. |
786 | May need to construct such a type if this is the first use. | |
787 | The TYPE is the type of the member. The DOMAIN is the type | |
788 | of the aggregate that the member belongs to. */ | |
789 | ||
790 | struct type * | |
0d5de010 | 791 | lookup_memberptr_type (struct type *type, struct type *domain) |
c906108c | 792 | { |
52f0bd74 | 793 | struct type *mtype; |
c906108c | 794 | |
e9bb382b | 795 | mtype = alloc_type_copy (type); |
0d5de010 | 796 | smash_to_memberptr_type (mtype, domain, type); |
c16abbde | 797 | return mtype; |
c906108c SS |
798 | } |
799 | ||
0d5de010 DJ |
800 | /* Return a pointer-to-method type, for a method of type TO_TYPE. */ |
801 | ||
802 | struct type * | |
803 | lookup_methodptr_type (struct type *to_type) | |
804 | { | |
805 | struct type *mtype; | |
806 | ||
e9bb382b | 807 | mtype = alloc_type_copy (to_type); |
0b92b5bb | 808 | smash_to_methodptr_type (mtype, to_type); |
0d5de010 DJ |
809 | return mtype; |
810 | } | |
811 | ||
7ba81444 MS |
812 | /* Allocate a stub method whose return type is TYPE. This apparently |
813 | happens for speed of symbol reading, since parsing out the | |
814 | arguments to the method is cpu-intensive, the way we are doing it. | |
815 | So, we will fill in arguments later. This always returns a fresh | |
816 | type. */ | |
c906108c SS |
817 | |
818 | struct type * | |
fba45db2 | 819 | allocate_stub_method (struct type *type) |
c906108c SS |
820 | { |
821 | struct type *mtype; | |
822 | ||
e9bb382b UW |
823 | mtype = alloc_type_copy (type); |
824 | TYPE_CODE (mtype) = TYPE_CODE_METHOD; | |
825 | TYPE_LENGTH (mtype) = 1; | |
826 | TYPE_STUB (mtype) = 1; | |
c906108c | 827 | TYPE_TARGET_TYPE (mtype) = type; |
4bfb94b8 | 828 | /* TYPE_SELF_TYPE (mtype) = unknown yet */ |
c16abbde | 829 | return mtype; |
c906108c SS |
830 | } |
831 | ||
729efb13 SA |
832 | /* Create a range type with a dynamic range from LOW_BOUND to |
833 | HIGH_BOUND, inclusive. See create_range_type for further details. */ | |
c906108c SS |
834 | |
835 | struct type * | |
729efb13 SA |
836 | create_range_type (struct type *result_type, struct type *index_type, |
837 | const struct dynamic_prop *low_bound, | |
838 | const struct dynamic_prop *high_bound) | |
c906108c SS |
839 | { |
840 | if (result_type == NULL) | |
e9bb382b | 841 | result_type = alloc_type_copy (index_type); |
c906108c SS |
842 | TYPE_CODE (result_type) = TYPE_CODE_RANGE; |
843 | TYPE_TARGET_TYPE (result_type) = index_type; | |
74a9bb82 | 844 | if (TYPE_STUB (index_type)) |
876cecd0 | 845 | TYPE_TARGET_STUB (result_type) = 1; |
c906108c SS |
846 | else |
847 | TYPE_LENGTH (result_type) = TYPE_LENGTH (check_typedef (index_type)); | |
729efb13 | 848 | |
43bbcdc2 PH |
849 | TYPE_RANGE_DATA (result_type) = (struct range_bounds *) |
850 | TYPE_ZALLOC (result_type, sizeof (struct range_bounds)); | |
729efb13 SA |
851 | TYPE_RANGE_DATA (result_type)->low = *low_bound; |
852 | TYPE_RANGE_DATA (result_type)->high = *high_bound; | |
c906108c | 853 | |
729efb13 | 854 | if (low_bound->kind == PROP_CONST && low_bound->data.const_val >= 0) |
876cecd0 | 855 | TYPE_UNSIGNED (result_type) = 1; |
c906108c | 856 | |
45e44d27 JB |
857 | /* Ada allows the declaration of range types whose upper bound is |
858 | less than the lower bound, so checking the lower bound is not | |
859 | enough. Make sure we do not mark a range type whose upper bound | |
860 | is negative as unsigned. */ | |
861 | if (high_bound->kind == PROP_CONST && high_bound->data.const_val < 0) | |
862 | TYPE_UNSIGNED (result_type) = 0; | |
863 | ||
262452ec | 864 | return result_type; |
c906108c SS |
865 | } |
866 | ||
729efb13 SA |
867 | /* Create a range type using either a blank type supplied in |
868 | RESULT_TYPE, or creating a new type, inheriting the objfile from | |
869 | INDEX_TYPE. | |
870 | ||
871 | Indices will be of type INDEX_TYPE, and will range from LOW_BOUND | |
872 | to HIGH_BOUND, inclusive. | |
873 | ||
874 | FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make | |
875 | sure it is TYPE_CODE_UNDEF before we bash it into a range type? */ | |
876 | ||
877 | struct type * | |
878 | create_static_range_type (struct type *result_type, struct type *index_type, | |
879 | LONGEST low_bound, LONGEST high_bound) | |
880 | { | |
881 | struct dynamic_prop low, high; | |
882 | ||
883 | low.kind = PROP_CONST; | |
884 | low.data.const_val = low_bound; | |
885 | ||
886 | high.kind = PROP_CONST; | |
887 | high.data.const_val = high_bound; | |
888 | ||
889 | result_type = create_range_type (result_type, index_type, &low, &high); | |
890 | ||
891 | return result_type; | |
892 | } | |
893 | ||
80180f79 SA |
894 | /* Predicate tests whether BOUNDS are static. Returns 1 if all bounds values |
895 | are static, otherwise returns 0. */ | |
896 | ||
897 | static int | |
898 | has_static_range (const struct range_bounds *bounds) | |
899 | { | |
900 | return (bounds->low.kind == PROP_CONST | |
901 | && bounds->high.kind == PROP_CONST); | |
902 | } | |
903 | ||
904 | ||
7ba81444 MS |
905 | /* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type |
906 | TYPE. Return 1 if type is a range type, 0 if it is discrete (and | |
907 | bounds will fit in LONGEST), or -1 otherwise. */ | |
c906108c SS |
908 | |
909 | int | |
fba45db2 | 910 | get_discrete_bounds (struct type *type, LONGEST *lowp, LONGEST *highp) |
c906108c | 911 | { |
f168693b | 912 | type = check_typedef (type); |
c906108c SS |
913 | switch (TYPE_CODE (type)) |
914 | { | |
915 | case TYPE_CODE_RANGE: | |
916 | *lowp = TYPE_LOW_BOUND (type); | |
917 | *highp = TYPE_HIGH_BOUND (type); | |
918 | return 1; | |
919 | case TYPE_CODE_ENUM: | |
920 | if (TYPE_NFIELDS (type) > 0) | |
921 | { | |
922 | /* The enums may not be sorted by value, so search all | |
0963b4bd | 923 | entries. */ |
c906108c SS |
924 | int i; |
925 | ||
14e75d8e | 926 | *lowp = *highp = TYPE_FIELD_ENUMVAL (type, 0); |
c906108c SS |
927 | for (i = 0; i < TYPE_NFIELDS (type); i++) |
928 | { | |
14e75d8e JK |
929 | if (TYPE_FIELD_ENUMVAL (type, i) < *lowp) |
930 | *lowp = TYPE_FIELD_ENUMVAL (type, i); | |
931 | if (TYPE_FIELD_ENUMVAL (type, i) > *highp) | |
932 | *highp = TYPE_FIELD_ENUMVAL (type, i); | |
c906108c SS |
933 | } |
934 | ||
7ba81444 | 935 | /* Set unsigned indicator if warranted. */ |
c5aa993b | 936 | if (*lowp >= 0) |
c906108c | 937 | { |
876cecd0 | 938 | TYPE_UNSIGNED (type) = 1; |
c906108c SS |
939 | } |
940 | } | |
941 | else | |
942 | { | |
943 | *lowp = 0; | |
944 | *highp = -1; | |
945 | } | |
946 | return 0; | |
947 | case TYPE_CODE_BOOL: | |
948 | *lowp = 0; | |
949 | *highp = 1; | |
950 | return 0; | |
951 | case TYPE_CODE_INT: | |
c5aa993b | 952 | if (TYPE_LENGTH (type) > sizeof (LONGEST)) /* Too big */ |
c906108c SS |
953 | return -1; |
954 | if (!TYPE_UNSIGNED (type)) | |
955 | { | |
c5aa993b | 956 | *lowp = -(1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1)); |
c906108c SS |
957 | *highp = -*lowp - 1; |
958 | return 0; | |
959 | } | |
7ba81444 | 960 | /* ... fall through for unsigned ints ... */ |
c906108c SS |
961 | case TYPE_CODE_CHAR: |
962 | *lowp = 0; | |
963 | /* This round-about calculation is to avoid shifting by | |
7b83ea04 | 964 | TYPE_LENGTH (type) * TARGET_CHAR_BIT, which will not work |
7ba81444 | 965 | if TYPE_LENGTH (type) == sizeof (LONGEST). */ |
c906108c SS |
966 | *highp = 1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1); |
967 | *highp = (*highp - 1) | *highp; | |
968 | return 0; | |
969 | default: | |
970 | return -1; | |
971 | } | |
972 | } | |
973 | ||
dbc98a8b KW |
974 | /* Assuming TYPE is a simple, non-empty array type, compute its upper |
975 | and lower bound. Save the low bound into LOW_BOUND if not NULL. | |
976 | Save the high bound into HIGH_BOUND if not NULL. | |
977 | ||
0963b4bd | 978 | Return 1 if the operation was successful. Return zero otherwise, |
dbc98a8b KW |
979 | in which case the values of LOW_BOUND and HIGH_BOUNDS are unmodified. |
980 | ||
981 | We now simply use get_discrete_bounds call to get the values | |
982 | of the low and high bounds. | |
983 | get_discrete_bounds can return three values: | |
984 | 1, meaning that index is a range, | |
985 | 0, meaning that index is a discrete type, | |
986 | or -1 for failure. */ | |
987 | ||
988 | int | |
989 | get_array_bounds (struct type *type, LONGEST *low_bound, LONGEST *high_bound) | |
990 | { | |
991 | struct type *index = TYPE_INDEX_TYPE (type); | |
992 | LONGEST low = 0; | |
993 | LONGEST high = 0; | |
994 | int res; | |
995 | ||
996 | if (index == NULL) | |
997 | return 0; | |
998 | ||
999 | res = get_discrete_bounds (index, &low, &high); | |
1000 | if (res == -1) | |
1001 | return 0; | |
1002 | ||
1003 | /* Check if the array bounds are undefined. */ | |
1004 | if (res == 1 | |
1005 | && ((low_bound && TYPE_ARRAY_LOWER_BOUND_IS_UNDEFINED (type)) | |
1006 | || (high_bound && TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type)))) | |
1007 | return 0; | |
1008 | ||
1009 | if (low_bound) | |
1010 | *low_bound = low; | |
1011 | ||
1012 | if (high_bound) | |
1013 | *high_bound = high; | |
1014 | ||
1015 | return 1; | |
1016 | } | |
1017 | ||
aa715135 JG |
1018 | /* Assuming that TYPE is a discrete type and VAL is a valid integer |
1019 | representation of a value of this type, save the corresponding | |
1020 | position number in POS. | |
1021 | ||
1022 | Its differs from VAL only in the case of enumeration types. In | |
1023 | this case, the position number of the value of the first listed | |
1024 | enumeration literal is zero; the position number of the value of | |
1025 | each subsequent enumeration literal is one more than that of its | |
1026 | predecessor in the list. | |
1027 | ||
1028 | Return 1 if the operation was successful. Return zero otherwise, | |
1029 | in which case the value of POS is unmodified. | |
1030 | */ | |
1031 | ||
1032 | int | |
1033 | discrete_position (struct type *type, LONGEST val, LONGEST *pos) | |
1034 | { | |
1035 | if (TYPE_CODE (type) == TYPE_CODE_ENUM) | |
1036 | { | |
1037 | int i; | |
1038 | ||
1039 | for (i = 0; i < TYPE_NFIELDS (type); i += 1) | |
1040 | { | |
1041 | if (val == TYPE_FIELD_ENUMVAL (type, i)) | |
1042 | { | |
1043 | *pos = i; | |
1044 | return 1; | |
1045 | } | |
1046 | } | |
1047 | /* Invalid enumeration value. */ | |
1048 | return 0; | |
1049 | } | |
1050 | else | |
1051 | { | |
1052 | *pos = val; | |
1053 | return 1; | |
1054 | } | |
1055 | } | |
1056 | ||
7ba81444 MS |
1057 | /* Create an array type using either a blank type supplied in |
1058 | RESULT_TYPE, or creating a new type, inheriting the objfile from | |
1059 | RANGE_TYPE. | |
c906108c SS |
1060 | |
1061 | Elements will be of type ELEMENT_TYPE, the indices will be of type | |
1062 | RANGE_TYPE. | |
1063 | ||
dc53a7ad JB |
1064 | If BIT_STRIDE is not zero, build a packed array type whose element |
1065 | size is BIT_STRIDE. Otherwise, ignore this parameter. | |
1066 | ||
7ba81444 MS |
1067 | FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make |
1068 | sure it is TYPE_CODE_UNDEF before we bash it into an array | |
1069 | type? */ | |
c906108c SS |
1070 | |
1071 | struct type * | |
dc53a7ad JB |
1072 | create_array_type_with_stride (struct type *result_type, |
1073 | struct type *element_type, | |
1074 | struct type *range_type, | |
1075 | unsigned int bit_stride) | |
c906108c | 1076 | { |
c906108c | 1077 | if (result_type == NULL) |
e9bb382b UW |
1078 | result_type = alloc_type_copy (range_type); |
1079 | ||
c906108c SS |
1080 | TYPE_CODE (result_type) = TYPE_CODE_ARRAY; |
1081 | TYPE_TARGET_TYPE (result_type) = element_type; | |
80180f79 SA |
1082 | if (has_static_range (TYPE_RANGE_DATA (range_type))) |
1083 | { | |
1084 | LONGEST low_bound, high_bound; | |
1085 | ||
1086 | if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0) | |
1087 | low_bound = high_bound = 0; | |
f168693b | 1088 | element_type = check_typedef (element_type); |
80180f79 SA |
1089 | /* Be careful when setting the array length. Ada arrays can be |
1090 | empty arrays with the high_bound being smaller than the low_bound. | |
1091 | In such cases, the array length should be zero. */ | |
1092 | if (high_bound < low_bound) | |
1093 | TYPE_LENGTH (result_type) = 0; | |
1094 | else if (bit_stride > 0) | |
1095 | TYPE_LENGTH (result_type) = | |
1096 | (bit_stride * (high_bound - low_bound + 1) + 7) / 8; | |
1097 | else | |
1098 | TYPE_LENGTH (result_type) = | |
1099 | TYPE_LENGTH (element_type) * (high_bound - low_bound + 1); | |
1100 | } | |
ab0d6e0d | 1101 | else |
80180f79 SA |
1102 | { |
1103 | /* This type is dynamic and its length needs to be computed | |
1104 | on demand. In the meantime, avoid leaving the TYPE_LENGTH | |
1105 | undefined by setting it to zero. Although we are not expected | |
1106 | to trust TYPE_LENGTH in this case, setting the size to zero | |
1107 | allows us to avoid allocating objects of random sizes in case | |
1108 | we accidently do. */ | |
1109 | TYPE_LENGTH (result_type) = 0; | |
1110 | } | |
1111 | ||
c906108c SS |
1112 | TYPE_NFIELDS (result_type) = 1; |
1113 | TYPE_FIELDS (result_type) = | |
1deafd4e | 1114 | (struct field *) TYPE_ZALLOC (result_type, sizeof (struct field)); |
262452ec | 1115 | TYPE_INDEX_TYPE (result_type) = range_type; |
dc53a7ad JB |
1116 | if (bit_stride > 0) |
1117 | TYPE_FIELD_BITSIZE (result_type, 0) = bit_stride; | |
c906108c | 1118 | |
0963b4bd | 1119 | /* TYPE_FLAG_TARGET_STUB will take care of zero length arrays. */ |
c906108c | 1120 | if (TYPE_LENGTH (result_type) == 0) |
876cecd0 | 1121 | TYPE_TARGET_STUB (result_type) = 1; |
c906108c | 1122 | |
c16abbde | 1123 | return result_type; |
c906108c SS |
1124 | } |
1125 | ||
dc53a7ad JB |
1126 | /* Same as create_array_type_with_stride but with no bit_stride |
1127 | (BIT_STRIDE = 0), thus building an unpacked array. */ | |
1128 | ||
1129 | struct type * | |
1130 | create_array_type (struct type *result_type, | |
1131 | struct type *element_type, | |
1132 | struct type *range_type) | |
1133 | { | |
1134 | return create_array_type_with_stride (result_type, element_type, | |
1135 | range_type, 0); | |
1136 | } | |
1137 | ||
e3506a9f UW |
1138 | struct type * |
1139 | lookup_array_range_type (struct type *element_type, | |
63375b74 | 1140 | LONGEST low_bound, LONGEST high_bound) |
e3506a9f | 1141 | { |
50810684 | 1142 | struct gdbarch *gdbarch = get_type_arch (element_type); |
e3506a9f UW |
1143 | struct type *index_type = builtin_type (gdbarch)->builtin_int; |
1144 | struct type *range_type | |
0c9c3474 | 1145 | = create_static_range_type (NULL, index_type, low_bound, high_bound); |
d8734c88 | 1146 | |
e3506a9f UW |
1147 | return create_array_type (NULL, element_type, range_type); |
1148 | } | |
1149 | ||
7ba81444 MS |
1150 | /* Create a string type using either a blank type supplied in |
1151 | RESULT_TYPE, or creating a new type. String types are similar | |
1152 | enough to array of char types that we can use create_array_type to | |
1153 | build the basic type and then bash it into a string type. | |
c906108c SS |
1154 | |
1155 | For fixed length strings, the range type contains 0 as the lower | |
1156 | bound and the length of the string minus one as the upper bound. | |
1157 | ||
7ba81444 MS |
1158 | FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make |
1159 | sure it is TYPE_CODE_UNDEF before we bash it into a string | |
1160 | type? */ | |
c906108c SS |
1161 | |
1162 | struct type * | |
3b7538c0 UW |
1163 | create_string_type (struct type *result_type, |
1164 | struct type *string_char_type, | |
7ba81444 | 1165 | struct type *range_type) |
c906108c SS |
1166 | { |
1167 | result_type = create_array_type (result_type, | |
f290d38e | 1168 | string_char_type, |
c906108c SS |
1169 | range_type); |
1170 | TYPE_CODE (result_type) = TYPE_CODE_STRING; | |
c16abbde | 1171 | return result_type; |
c906108c SS |
1172 | } |
1173 | ||
e3506a9f UW |
1174 | struct type * |
1175 | lookup_string_range_type (struct type *string_char_type, | |
63375b74 | 1176 | LONGEST low_bound, LONGEST high_bound) |
e3506a9f UW |
1177 | { |
1178 | struct type *result_type; | |
d8734c88 | 1179 | |
e3506a9f UW |
1180 | result_type = lookup_array_range_type (string_char_type, |
1181 | low_bound, high_bound); | |
1182 | TYPE_CODE (result_type) = TYPE_CODE_STRING; | |
1183 | return result_type; | |
1184 | } | |
1185 | ||
c906108c | 1186 | struct type * |
fba45db2 | 1187 | create_set_type (struct type *result_type, struct type *domain_type) |
c906108c | 1188 | { |
c906108c | 1189 | if (result_type == NULL) |
e9bb382b UW |
1190 | result_type = alloc_type_copy (domain_type); |
1191 | ||
c906108c SS |
1192 | TYPE_CODE (result_type) = TYPE_CODE_SET; |
1193 | TYPE_NFIELDS (result_type) = 1; | |
1deafd4e | 1194 | TYPE_FIELDS (result_type) = TYPE_ZALLOC (result_type, sizeof (struct field)); |
c906108c | 1195 | |
74a9bb82 | 1196 | if (!TYPE_STUB (domain_type)) |
c906108c | 1197 | { |
f9780d5b | 1198 | LONGEST low_bound, high_bound, bit_length; |
d8734c88 | 1199 | |
c906108c SS |
1200 | if (get_discrete_bounds (domain_type, &low_bound, &high_bound) < 0) |
1201 | low_bound = high_bound = 0; | |
1202 | bit_length = high_bound - low_bound + 1; | |
1203 | TYPE_LENGTH (result_type) | |
1204 | = (bit_length + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT; | |
f9780d5b | 1205 | if (low_bound >= 0) |
876cecd0 | 1206 | TYPE_UNSIGNED (result_type) = 1; |
c906108c SS |
1207 | } |
1208 | TYPE_FIELD_TYPE (result_type, 0) = domain_type; | |
1209 | ||
c16abbde | 1210 | return result_type; |
c906108c SS |
1211 | } |
1212 | ||
ea37ba09 DJ |
1213 | /* Convert ARRAY_TYPE to a vector type. This may modify ARRAY_TYPE |
1214 | and any array types nested inside it. */ | |
1215 | ||
1216 | void | |
1217 | make_vector_type (struct type *array_type) | |
1218 | { | |
1219 | struct type *inner_array, *elt_type; | |
1220 | int flags; | |
1221 | ||
1222 | /* Find the innermost array type, in case the array is | |
1223 | multi-dimensional. */ | |
1224 | inner_array = array_type; | |
1225 | while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array)) == TYPE_CODE_ARRAY) | |
1226 | inner_array = TYPE_TARGET_TYPE (inner_array); | |
1227 | ||
1228 | elt_type = TYPE_TARGET_TYPE (inner_array); | |
1229 | if (TYPE_CODE (elt_type) == TYPE_CODE_INT) | |
1230 | { | |
2844d6b5 | 1231 | flags = TYPE_INSTANCE_FLAGS (elt_type) | TYPE_INSTANCE_FLAG_NOTTEXT; |
ea37ba09 DJ |
1232 | elt_type = make_qualified_type (elt_type, flags, NULL); |
1233 | TYPE_TARGET_TYPE (inner_array) = elt_type; | |
1234 | } | |
1235 | ||
876cecd0 | 1236 | TYPE_VECTOR (array_type) = 1; |
ea37ba09 DJ |
1237 | } |
1238 | ||
794ac428 | 1239 | struct type * |
ac3aafc7 EZ |
1240 | init_vector_type (struct type *elt_type, int n) |
1241 | { | |
1242 | struct type *array_type; | |
d8734c88 | 1243 | |
e3506a9f | 1244 | array_type = lookup_array_range_type (elt_type, 0, n - 1); |
ea37ba09 | 1245 | make_vector_type (array_type); |
ac3aafc7 EZ |
1246 | return array_type; |
1247 | } | |
1248 | ||
09e2d7c7 DE |
1249 | /* Internal routine called by TYPE_SELF_TYPE to return the type that TYPE |
1250 | belongs to. In c++ this is the class of "this", but TYPE_THIS_TYPE is too | |
1251 | confusing. "self" is a common enough replacement for "this". | |
1252 | TYPE must be one of TYPE_CODE_METHODPTR, TYPE_CODE_MEMBERPTR, or | |
1253 | TYPE_CODE_METHOD. */ | |
1254 | ||
1255 | struct type * | |
1256 | internal_type_self_type (struct type *type) | |
1257 | { | |
1258 | switch (TYPE_CODE (type)) | |
1259 | { | |
1260 | case TYPE_CODE_METHODPTR: | |
1261 | case TYPE_CODE_MEMBERPTR: | |
eaaf76ab DE |
1262 | if (TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_NONE) |
1263 | return NULL; | |
09e2d7c7 DE |
1264 | gdb_assert (TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_SELF_TYPE); |
1265 | return TYPE_MAIN_TYPE (type)->type_specific.self_type; | |
1266 | case TYPE_CODE_METHOD: | |
eaaf76ab DE |
1267 | if (TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_NONE) |
1268 | return NULL; | |
09e2d7c7 DE |
1269 | gdb_assert (TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_FUNC); |
1270 | return TYPE_MAIN_TYPE (type)->type_specific.func_stuff->self_type; | |
1271 | default: | |
1272 | gdb_assert_not_reached ("bad type"); | |
1273 | } | |
1274 | } | |
1275 | ||
1276 | /* Set the type of the class that TYPE belongs to. | |
1277 | In c++ this is the class of "this". | |
1278 | TYPE must be one of TYPE_CODE_METHODPTR, TYPE_CODE_MEMBERPTR, or | |
1279 | TYPE_CODE_METHOD. */ | |
1280 | ||
1281 | void | |
1282 | set_type_self_type (struct type *type, struct type *self_type) | |
1283 | { | |
1284 | switch (TYPE_CODE (type)) | |
1285 | { | |
1286 | case TYPE_CODE_METHODPTR: | |
1287 | case TYPE_CODE_MEMBERPTR: | |
1288 | if (TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_NONE) | |
1289 | TYPE_SPECIFIC_FIELD (type) = TYPE_SPECIFIC_SELF_TYPE; | |
1290 | gdb_assert (TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_SELF_TYPE); | |
1291 | TYPE_MAIN_TYPE (type)->type_specific.self_type = self_type; | |
1292 | break; | |
1293 | case TYPE_CODE_METHOD: | |
1294 | if (TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_NONE) | |
1295 | INIT_FUNC_SPECIFIC (type); | |
1296 | gdb_assert (TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_FUNC); | |
1297 | TYPE_MAIN_TYPE (type)->type_specific.func_stuff->self_type = self_type; | |
1298 | break; | |
1299 | default: | |
1300 | gdb_assert_not_reached ("bad type"); | |
1301 | } | |
1302 | } | |
1303 | ||
1304 | /* Smash TYPE to be a type of pointers to members of SELF_TYPE with type | |
0d5de010 DJ |
1305 | TO_TYPE. A member pointer is a wierd thing -- it amounts to a |
1306 | typed offset into a struct, e.g. "an int at offset 8". A MEMBER | |
1307 | TYPE doesn't include the offset (that's the value of the MEMBER | |
1308 | itself), but does include the structure type into which it points | |
1309 | (for some reason). | |
c906108c | 1310 | |
7ba81444 MS |
1311 | When "smashing" the type, we preserve the objfile that the old type |
1312 | pointed to, since we aren't changing where the type is actually | |
c906108c SS |
1313 | allocated. */ |
1314 | ||
1315 | void | |
09e2d7c7 | 1316 | smash_to_memberptr_type (struct type *type, struct type *self_type, |
0d5de010 | 1317 | struct type *to_type) |
c906108c | 1318 | { |
2fdde8f8 | 1319 | smash_type (type); |
09e2d7c7 | 1320 | TYPE_CODE (type) = TYPE_CODE_MEMBERPTR; |
c906108c | 1321 | TYPE_TARGET_TYPE (type) = to_type; |
09e2d7c7 | 1322 | set_type_self_type (type, self_type); |
0d5de010 DJ |
1323 | /* Assume that a data member pointer is the same size as a normal |
1324 | pointer. */ | |
50810684 UW |
1325 | TYPE_LENGTH (type) |
1326 | = gdbarch_ptr_bit (get_type_arch (to_type)) / TARGET_CHAR_BIT; | |
c906108c SS |
1327 | } |
1328 | ||
0b92b5bb TT |
1329 | /* Smash TYPE to be a type of pointer to methods type TO_TYPE. |
1330 | ||
1331 | When "smashing" the type, we preserve the objfile that the old type | |
1332 | pointed to, since we aren't changing where the type is actually | |
1333 | allocated. */ | |
1334 | ||
1335 | void | |
1336 | smash_to_methodptr_type (struct type *type, struct type *to_type) | |
1337 | { | |
1338 | smash_type (type); | |
09e2d7c7 | 1339 | TYPE_CODE (type) = TYPE_CODE_METHODPTR; |
0b92b5bb | 1340 | TYPE_TARGET_TYPE (type) = to_type; |
09e2d7c7 | 1341 | set_type_self_type (type, TYPE_SELF_TYPE (to_type)); |
0b92b5bb | 1342 | TYPE_LENGTH (type) = cplus_method_ptr_size (to_type); |
0b92b5bb TT |
1343 | } |
1344 | ||
09e2d7c7 | 1345 | /* Smash TYPE to be a type of method of SELF_TYPE with type TO_TYPE. |
c906108c SS |
1346 | METHOD just means `function that gets an extra "this" argument'. |
1347 | ||
7ba81444 MS |
1348 | When "smashing" the type, we preserve the objfile that the old type |
1349 | pointed to, since we aren't changing where the type is actually | |
c906108c SS |
1350 | allocated. */ |
1351 | ||
1352 | void | |
09e2d7c7 | 1353 | smash_to_method_type (struct type *type, struct type *self_type, |
ad2f7632 DJ |
1354 | struct type *to_type, struct field *args, |
1355 | int nargs, int varargs) | |
c906108c | 1356 | { |
2fdde8f8 | 1357 | smash_type (type); |
09e2d7c7 | 1358 | TYPE_CODE (type) = TYPE_CODE_METHOD; |
c906108c | 1359 | TYPE_TARGET_TYPE (type) = to_type; |
09e2d7c7 | 1360 | set_type_self_type (type, self_type); |
ad2f7632 DJ |
1361 | TYPE_FIELDS (type) = args; |
1362 | TYPE_NFIELDS (type) = nargs; | |
1363 | if (varargs) | |
876cecd0 | 1364 | TYPE_VARARGS (type) = 1; |
c906108c | 1365 | TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */ |
c906108c SS |
1366 | } |
1367 | ||
1368 | /* Return a typename for a struct/union/enum type without "struct ", | |
1369 | "union ", or "enum ". If the type has a NULL name, return NULL. */ | |
1370 | ||
0d5cff50 | 1371 | const char * |
aa1ee363 | 1372 | type_name_no_tag (const struct type *type) |
c906108c SS |
1373 | { |
1374 | if (TYPE_TAG_NAME (type) != NULL) | |
1375 | return TYPE_TAG_NAME (type); | |
1376 | ||
7ba81444 MS |
1377 | /* Is there code which expects this to return the name if there is |
1378 | no tag name? My guess is that this is mainly used for C++ in | |
1379 | cases where the two will always be the same. */ | |
c906108c SS |
1380 | return TYPE_NAME (type); |
1381 | } | |
1382 | ||
d8228535 JK |
1383 | /* A wrapper of type_name_no_tag which calls error if the type is anonymous. |
1384 | Since GCC PR debug/47510 DWARF provides associated information to detect the | |
1385 | anonymous class linkage name from its typedef. | |
1386 | ||
1387 | Parameter TYPE should not yet have CHECK_TYPEDEF applied, this function will | |
1388 | apply it itself. */ | |
1389 | ||
1390 | const char * | |
1391 | type_name_no_tag_or_error (struct type *type) | |
1392 | { | |
1393 | struct type *saved_type = type; | |
1394 | const char *name; | |
1395 | struct objfile *objfile; | |
1396 | ||
f168693b | 1397 | type = check_typedef (type); |
d8228535 JK |
1398 | |
1399 | name = type_name_no_tag (type); | |
1400 | if (name != NULL) | |
1401 | return name; | |
1402 | ||
1403 | name = type_name_no_tag (saved_type); | |
1404 | objfile = TYPE_OBJFILE (saved_type); | |
1405 | error (_("Invalid anonymous type %s [in module %s], GCC PR debug/47510 bug?"), | |
4262abfb JK |
1406 | name ? name : "<anonymous>", |
1407 | objfile ? objfile_name (objfile) : "<arch>"); | |
d8228535 JK |
1408 | } |
1409 | ||
7ba81444 MS |
1410 | /* Lookup a typedef or primitive type named NAME, visible in lexical |
1411 | block BLOCK. If NOERR is nonzero, return zero if NAME is not | |
1412 | suitably defined. */ | |
c906108c SS |
1413 | |
1414 | struct type * | |
e6c014f2 | 1415 | lookup_typename (const struct language_defn *language, |
ddd49eee | 1416 | struct gdbarch *gdbarch, const char *name, |
34eaf542 | 1417 | const struct block *block, int noerr) |
c906108c | 1418 | { |
52f0bd74 | 1419 | struct symbol *sym; |
659c9f3a | 1420 | struct type *type; |
c906108c | 1421 | |
1994afbf | 1422 | sym = lookup_symbol_in_language (name, block, VAR_DOMAIN, |
d12307c1 | 1423 | language->la_language, NULL).symbol; |
c51fe631 DE |
1424 | if (sym != NULL && SYMBOL_CLASS (sym) == LOC_TYPEDEF) |
1425 | return SYMBOL_TYPE (sym); | |
1426 | ||
c51fe631 DE |
1427 | if (noerr) |
1428 | return NULL; | |
1429 | error (_("No type named %s."), name); | |
c906108c SS |
1430 | } |
1431 | ||
1432 | struct type * | |
e6c014f2 | 1433 | lookup_unsigned_typename (const struct language_defn *language, |
0d5cff50 | 1434 | struct gdbarch *gdbarch, const char *name) |
c906108c SS |
1435 | { |
1436 | char *uns = alloca (strlen (name) + 10); | |
1437 | ||
1438 | strcpy (uns, "unsigned "); | |
1439 | strcpy (uns + 9, name); | |
e6c014f2 | 1440 | return lookup_typename (language, gdbarch, uns, (struct block *) NULL, 0); |
c906108c SS |
1441 | } |
1442 | ||
1443 | struct type * | |
e6c014f2 | 1444 | lookup_signed_typename (const struct language_defn *language, |
0d5cff50 | 1445 | struct gdbarch *gdbarch, const char *name) |
c906108c SS |
1446 | { |
1447 | struct type *t; | |
1448 | char *uns = alloca (strlen (name) + 8); | |
1449 | ||
1450 | strcpy (uns, "signed "); | |
1451 | strcpy (uns + 7, name); | |
e6c014f2 | 1452 | t = lookup_typename (language, gdbarch, uns, (struct block *) NULL, 1); |
7ba81444 | 1453 | /* If we don't find "signed FOO" just try again with plain "FOO". */ |
c906108c SS |
1454 | if (t != NULL) |
1455 | return t; | |
e6c014f2 | 1456 | return lookup_typename (language, gdbarch, name, (struct block *) NULL, 0); |
c906108c SS |
1457 | } |
1458 | ||
1459 | /* Lookup a structure type named "struct NAME", | |
1460 | visible in lexical block BLOCK. */ | |
1461 | ||
1462 | struct type * | |
270140bd | 1463 | lookup_struct (const char *name, const struct block *block) |
c906108c | 1464 | { |
52f0bd74 | 1465 | struct symbol *sym; |
c906108c | 1466 | |
d12307c1 | 1467 | sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0).symbol; |
c906108c SS |
1468 | |
1469 | if (sym == NULL) | |
1470 | { | |
8a3fe4f8 | 1471 | error (_("No struct type named %s."), name); |
c906108c SS |
1472 | } |
1473 | if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT) | |
1474 | { | |
7ba81444 MS |
1475 | error (_("This context has class, union or enum %s, not a struct."), |
1476 | name); | |
c906108c SS |
1477 | } |
1478 | return (SYMBOL_TYPE (sym)); | |
1479 | } | |
1480 | ||
1481 | /* Lookup a union type named "union NAME", | |
1482 | visible in lexical block BLOCK. */ | |
1483 | ||
1484 | struct type * | |
270140bd | 1485 | lookup_union (const char *name, const struct block *block) |
c906108c | 1486 | { |
52f0bd74 | 1487 | struct symbol *sym; |
c5aa993b | 1488 | struct type *t; |
c906108c | 1489 | |
d12307c1 | 1490 | sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0).symbol; |
c906108c SS |
1491 | |
1492 | if (sym == NULL) | |
8a3fe4f8 | 1493 | error (_("No union type named %s."), name); |
c906108c | 1494 | |
c5aa993b | 1495 | t = SYMBOL_TYPE (sym); |
c906108c SS |
1496 | |
1497 | if (TYPE_CODE (t) == TYPE_CODE_UNION) | |
c16abbde | 1498 | return t; |
c906108c | 1499 | |
7ba81444 MS |
1500 | /* If we get here, it's not a union. */ |
1501 | error (_("This context has class, struct or enum %s, not a union."), | |
1502 | name); | |
c906108c SS |
1503 | } |
1504 | ||
c906108c SS |
1505 | /* Lookup an enum type named "enum NAME", |
1506 | visible in lexical block BLOCK. */ | |
1507 | ||
1508 | struct type * | |
270140bd | 1509 | lookup_enum (const char *name, const struct block *block) |
c906108c | 1510 | { |
52f0bd74 | 1511 | struct symbol *sym; |
c906108c | 1512 | |
d12307c1 | 1513 | sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0).symbol; |
c906108c SS |
1514 | if (sym == NULL) |
1515 | { | |
8a3fe4f8 | 1516 | error (_("No enum type named %s."), name); |
c906108c SS |
1517 | } |
1518 | if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_ENUM) | |
1519 | { | |
7ba81444 MS |
1520 | error (_("This context has class, struct or union %s, not an enum."), |
1521 | name); | |
c906108c SS |
1522 | } |
1523 | return (SYMBOL_TYPE (sym)); | |
1524 | } | |
1525 | ||
1526 | /* Lookup a template type named "template NAME<TYPE>", | |
1527 | visible in lexical block BLOCK. */ | |
1528 | ||
1529 | struct type * | |
7ba81444 | 1530 | lookup_template_type (char *name, struct type *type, |
270140bd | 1531 | const struct block *block) |
c906108c SS |
1532 | { |
1533 | struct symbol *sym; | |
7ba81444 MS |
1534 | char *nam = (char *) |
1535 | alloca (strlen (name) + strlen (TYPE_NAME (type)) + 4); | |
d8734c88 | 1536 | |
c906108c SS |
1537 | strcpy (nam, name); |
1538 | strcat (nam, "<"); | |
0004e5a2 | 1539 | strcat (nam, TYPE_NAME (type)); |
0963b4bd | 1540 | strcat (nam, " >"); /* FIXME, extra space still introduced in gcc? */ |
c906108c | 1541 | |
d12307c1 | 1542 | sym = lookup_symbol (nam, block, VAR_DOMAIN, 0).symbol; |
c906108c SS |
1543 | |
1544 | if (sym == NULL) | |
1545 | { | |
8a3fe4f8 | 1546 | error (_("No template type named %s."), name); |
c906108c SS |
1547 | } |
1548 | if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT) | |
1549 | { | |
7ba81444 MS |
1550 | error (_("This context has class, union or enum %s, not a struct."), |
1551 | name); | |
c906108c SS |
1552 | } |
1553 | return (SYMBOL_TYPE (sym)); | |
1554 | } | |
1555 | ||
7ba81444 MS |
1556 | /* Given a type TYPE, lookup the type of the component of type named |
1557 | NAME. | |
c906108c | 1558 | |
7ba81444 MS |
1559 | TYPE can be either a struct or union, or a pointer or reference to |
1560 | a struct or union. If it is a pointer or reference, its target | |
1561 | type is automatically used. Thus '.' and '->' are interchangable, | |
1562 | as specified for the definitions of the expression element types | |
1563 | STRUCTOP_STRUCT and STRUCTOP_PTR. | |
c906108c SS |
1564 | |
1565 | If NOERR is nonzero, return zero if NAME is not suitably defined. | |
1566 | If NAME is the name of a baseclass type, return that type. */ | |
1567 | ||
1568 | struct type * | |
d7561cbb | 1569 | lookup_struct_elt_type (struct type *type, const char *name, int noerr) |
c906108c SS |
1570 | { |
1571 | int i; | |
fe978cb0 | 1572 | char *type_name; |
c906108c SS |
1573 | |
1574 | for (;;) | |
1575 | { | |
f168693b | 1576 | type = check_typedef (type); |
c906108c SS |
1577 | if (TYPE_CODE (type) != TYPE_CODE_PTR |
1578 | && TYPE_CODE (type) != TYPE_CODE_REF) | |
1579 | break; | |
1580 | type = TYPE_TARGET_TYPE (type); | |
1581 | } | |
1582 | ||
687d6395 MS |
1583 | if (TYPE_CODE (type) != TYPE_CODE_STRUCT |
1584 | && TYPE_CODE (type) != TYPE_CODE_UNION) | |
c906108c | 1585 | { |
fe978cb0 PA |
1586 | type_name = type_to_string (type); |
1587 | make_cleanup (xfree, type_name); | |
1588 | error (_("Type %s is not a structure or union type."), type_name); | |
c906108c SS |
1589 | } |
1590 | ||
1591 | #if 0 | |
7ba81444 MS |
1592 | /* FIXME: This change put in by Michael seems incorrect for the case |
1593 | where the structure tag name is the same as the member name. | |
0963b4bd | 1594 | I.e. when doing "ptype bell->bar" for "struct foo { int bar; int |
7ba81444 | 1595 | foo; } bell;" Disabled by fnf. */ |
c906108c | 1596 | { |
fe978cb0 | 1597 | char *type_name; |
c906108c | 1598 | |
fe978cb0 PA |
1599 | type_name = type_name_no_tag (type); |
1600 | if (type_name != NULL && strcmp (type_name, name) == 0) | |
c906108c SS |
1601 | return type; |
1602 | } | |
1603 | #endif | |
1604 | ||
1605 | for (i = TYPE_NFIELDS (type) - 1; i >= TYPE_N_BASECLASSES (type); i--) | |
1606 | { | |
0d5cff50 | 1607 | const char *t_field_name = TYPE_FIELD_NAME (type, i); |
c906108c | 1608 | |
db577aea | 1609 | if (t_field_name && (strcmp_iw (t_field_name, name) == 0)) |
c906108c SS |
1610 | { |
1611 | return TYPE_FIELD_TYPE (type, i); | |
1612 | } | |
f5a010c0 PM |
1613 | else if (!t_field_name || *t_field_name == '\0') |
1614 | { | |
d8734c88 MS |
1615 | struct type *subtype |
1616 | = lookup_struct_elt_type (TYPE_FIELD_TYPE (type, i), name, 1); | |
1617 | ||
f5a010c0 PM |
1618 | if (subtype != NULL) |
1619 | return subtype; | |
1620 | } | |
c906108c SS |
1621 | } |
1622 | ||
1623 | /* OK, it's not in this class. Recursively check the baseclasses. */ | |
1624 | for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--) | |
1625 | { | |
1626 | struct type *t; | |
1627 | ||
9733fc94 | 1628 | t = lookup_struct_elt_type (TYPE_BASECLASS (type, i), name, 1); |
c906108c SS |
1629 | if (t != NULL) |
1630 | { | |
1631 | return t; | |
1632 | } | |
1633 | } | |
1634 | ||
1635 | if (noerr) | |
1636 | { | |
1637 | return NULL; | |
1638 | } | |
c5aa993b | 1639 | |
fe978cb0 PA |
1640 | type_name = type_to_string (type); |
1641 | make_cleanup (xfree, type_name); | |
1642 | error (_("Type %s has no component named %s."), type_name, name); | |
c906108c SS |
1643 | } |
1644 | ||
ed3ef339 DE |
1645 | /* Store in *MAX the largest number representable by unsigned integer type |
1646 | TYPE. */ | |
1647 | ||
1648 | void | |
1649 | get_unsigned_type_max (struct type *type, ULONGEST *max) | |
1650 | { | |
1651 | unsigned int n; | |
1652 | ||
f168693b | 1653 | type = check_typedef (type); |
ed3ef339 DE |
1654 | gdb_assert (TYPE_CODE (type) == TYPE_CODE_INT && TYPE_UNSIGNED (type)); |
1655 | gdb_assert (TYPE_LENGTH (type) <= sizeof (ULONGEST)); | |
1656 | ||
1657 | /* Written this way to avoid overflow. */ | |
1658 | n = TYPE_LENGTH (type) * TARGET_CHAR_BIT; | |
1659 | *max = ((((ULONGEST) 1 << (n - 1)) - 1) << 1) | 1; | |
1660 | } | |
1661 | ||
1662 | /* Store in *MIN, *MAX the smallest and largest numbers representable by | |
1663 | signed integer type TYPE. */ | |
1664 | ||
1665 | void | |
1666 | get_signed_type_minmax (struct type *type, LONGEST *min, LONGEST *max) | |
1667 | { | |
1668 | unsigned int n; | |
1669 | ||
f168693b | 1670 | type = check_typedef (type); |
ed3ef339 DE |
1671 | gdb_assert (TYPE_CODE (type) == TYPE_CODE_INT && !TYPE_UNSIGNED (type)); |
1672 | gdb_assert (TYPE_LENGTH (type) <= sizeof (LONGEST)); | |
1673 | ||
1674 | n = TYPE_LENGTH (type) * TARGET_CHAR_BIT; | |
1675 | *min = -((ULONGEST) 1 << (n - 1)); | |
1676 | *max = ((ULONGEST) 1 << (n - 1)) - 1; | |
1677 | } | |
1678 | ||
ae6ae975 DE |
1679 | /* Internal routine called by TYPE_VPTR_FIELDNO to return the value of |
1680 | cplus_stuff.vptr_fieldno. | |
1681 | ||
1682 | cplus_stuff is initialized to cplus_struct_default which does not | |
1683 | set vptr_fieldno to -1 for portability reasons (IWBN to use C99 | |
1684 | designated initializers). We cope with that here. */ | |
1685 | ||
1686 | int | |
1687 | internal_type_vptr_fieldno (struct type *type) | |
1688 | { | |
f168693b | 1689 | type = check_typedef (type); |
ae6ae975 DE |
1690 | gdb_assert (TYPE_CODE (type) == TYPE_CODE_STRUCT |
1691 | || TYPE_CODE (type) == TYPE_CODE_UNION); | |
1692 | if (!HAVE_CPLUS_STRUCT (type)) | |
1693 | return -1; | |
1694 | return TYPE_RAW_CPLUS_SPECIFIC (type)->vptr_fieldno; | |
1695 | } | |
1696 | ||
1697 | /* Set the value of cplus_stuff.vptr_fieldno. */ | |
1698 | ||
1699 | void | |
1700 | set_type_vptr_fieldno (struct type *type, int fieldno) | |
1701 | { | |
f168693b | 1702 | type = check_typedef (type); |
ae6ae975 DE |
1703 | gdb_assert (TYPE_CODE (type) == TYPE_CODE_STRUCT |
1704 | || TYPE_CODE (type) == TYPE_CODE_UNION); | |
1705 | if (!HAVE_CPLUS_STRUCT (type)) | |
1706 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
1707 | TYPE_RAW_CPLUS_SPECIFIC (type)->vptr_fieldno = fieldno; | |
1708 | } | |
1709 | ||
1710 | /* Internal routine called by TYPE_VPTR_BASETYPE to return the value of | |
1711 | cplus_stuff.vptr_basetype. */ | |
1712 | ||
1713 | struct type * | |
1714 | internal_type_vptr_basetype (struct type *type) | |
1715 | { | |
f168693b | 1716 | type = check_typedef (type); |
ae6ae975 DE |
1717 | gdb_assert (TYPE_CODE (type) == TYPE_CODE_STRUCT |
1718 | || TYPE_CODE (type) == TYPE_CODE_UNION); | |
1719 | gdb_assert (TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_CPLUS_STUFF); | |
1720 | return TYPE_RAW_CPLUS_SPECIFIC (type)->vptr_basetype; | |
1721 | } | |
1722 | ||
1723 | /* Set the value of cplus_stuff.vptr_basetype. */ | |
1724 | ||
1725 | void | |
1726 | set_type_vptr_basetype (struct type *type, struct type *basetype) | |
1727 | { | |
f168693b | 1728 | type = check_typedef (type); |
ae6ae975 DE |
1729 | gdb_assert (TYPE_CODE (type) == TYPE_CODE_STRUCT |
1730 | || TYPE_CODE (type) == TYPE_CODE_UNION); | |
1731 | if (!HAVE_CPLUS_STRUCT (type)) | |
1732 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
1733 | TYPE_RAW_CPLUS_SPECIFIC (type)->vptr_basetype = basetype; | |
1734 | } | |
1735 | ||
81fe8080 DE |
1736 | /* Lookup the vptr basetype/fieldno values for TYPE. |
1737 | If found store vptr_basetype in *BASETYPEP if non-NULL, and return | |
1738 | vptr_fieldno. Also, if found and basetype is from the same objfile, | |
1739 | cache the results. | |
1740 | If not found, return -1 and ignore BASETYPEP. | |
1741 | Callers should be aware that in some cases (for example, | |
c906108c | 1742 | the type or one of its baseclasses is a stub type and we are |
d48cc9dd DJ |
1743 | debugging a .o file, or the compiler uses DWARF-2 and is not GCC), |
1744 | this function will not be able to find the | |
7ba81444 | 1745 | virtual function table pointer, and vptr_fieldno will remain -1 and |
81fe8080 | 1746 | vptr_basetype will remain NULL or incomplete. */ |
c906108c | 1747 | |
81fe8080 DE |
1748 | int |
1749 | get_vptr_fieldno (struct type *type, struct type **basetypep) | |
c906108c | 1750 | { |
f168693b | 1751 | type = check_typedef (type); |
c906108c SS |
1752 | |
1753 | if (TYPE_VPTR_FIELDNO (type) < 0) | |
1754 | { | |
1755 | int i; | |
1756 | ||
7ba81444 MS |
1757 | /* We must start at zero in case the first (and only) baseclass |
1758 | is virtual (and hence we cannot share the table pointer). */ | |
c906108c SS |
1759 | for (i = 0; i < TYPE_N_BASECLASSES (type); i++) |
1760 | { | |
81fe8080 DE |
1761 | struct type *baseclass = check_typedef (TYPE_BASECLASS (type, i)); |
1762 | int fieldno; | |
1763 | struct type *basetype; | |
1764 | ||
1765 | fieldno = get_vptr_fieldno (baseclass, &basetype); | |
1766 | if (fieldno >= 0) | |
c906108c | 1767 | { |
81fe8080 | 1768 | /* If the type comes from a different objfile we can't cache |
0963b4bd | 1769 | it, it may have a different lifetime. PR 2384 */ |
5ef73790 | 1770 | if (TYPE_OBJFILE (type) == TYPE_OBJFILE (basetype)) |
81fe8080 | 1771 | { |
ae6ae975 DE |
1772 | set_type_vptr_fieldno (type, fieldno); |
1773 | set_type_vptr_basetype (type, basetype); | |
81fe8080 DE |
1774 | } |
1775 | if (basetypep) | |
1776 | *basetypep = basetype; | |
1777 | return fieldno; | |
c906108c SS |
1778 | } |
1779 | } | |
81fe8080 DE |
1780 | |
1781 | /* Not found. */ | |
1782 | return -1; | |
1783 | } | |
1784 | else | |
1785 | { | |
1786 | if (basetypep) | |
1787 | *basetypep = TYPE_VPTR_BASETYPE (type); | |
1788 | return TYPE_VPTR_FIELDNO (type); | |
c906108c SS |
1789 | } |
1790 | } | |
1791 | ||
44e1a9eb DJ |
1792 | static void |
1793 | stub_noname_complaint (void) | |
1794 | { | |
e2e0b3e5 | 1795 | complaint (&symfile_complaints, _("stub type has NULL name")); |
44e1a9eb DJ |
1796 | } |
1797 | ||
d98b7a16 | 1798 | /* Worker for is_dynamic_type. */ |
80180f79 | 1799 | |
d98b7a16 | 1800 | static int |
ee715b5a | 1801 | is_dynamic_type_internal (struct type *type, int top_level) |
80180f79 SA |
1802 | { |
1803 | type = check_typedef (type); | |
1804 | ||
e771e4be PMR |
1805 | /* We only want to recognize references at the outermost level. */ |
1806 | if (top_level && TYPE_CODE (type) == TYPE_CODE_REF) | |
1807 | type = check_typedef (TYPE_TARGET_TYPE (type)); | |
1808 | ||
3cdcd0ce JB |
1809 | /* Types that have a dynamic TYPE_DATA_LOCATION are considered |
1810 | dynamic, even if the type itself is statically defined. | |
1811 | From a user's point of view, this may appear counter-intuitive; | |
1812 | but it makes sense in this context, because the point is to determine | |
1813 | whether any part of the type needs to be resolved before it can | |
1814 | be exploited. */ | |
1815 | if (TYPE_DATA_LOCATION (type) != NULL | |
1816 | && (TYPE_DATA_LOCATION_KIND (type) == PROP_LOCEXPR | |
1817 | || TYPE_DATA_LOCATION_KIND (type) == PROP_LOCLIST)) | |
1818 | return 1; | |
1819 | ||
80180f79 SA |
1820 | switch (TYPE_CODE (type)) |
1821 | { | |
6f8a3220 | 1822 | case TYPE_CODE_RANGE: |
ddb87a81 JB |
1823 | { |
1824 | /* A range type is obviously dynamic if it has at least one | |
1825 | dynamic bound. But also consider the range type to be | |
1826 | dynamic when its subtype is dynamic, even if the bounds | |
1827 | of the range type are static. It allows us to assume that | |
1828 | the subtype of a static range type is also static. */ | |
1829 | return (!has_static_range (TYPE_RANGE_DATA (type)) | |
ee715b5a | 1830 | || is_dynamic_type_internal (TYPE_TARGET_TYPE (type), 0)); |
ddb87a81 | 1831 | } |
6f8a3220 | 1832 | |
80180f79 SA |
1833 | case TYPE_CODE_ARRAY: |
1834 | { | |
80180f79 | 1835 | gdb_assert (TYPE_NFIELDS (type) == 1); |
6f8a3220 JB |
1836 | |
1837 | /* The array is dynamic if either the bounds are dynamic, | |
1838 | or the elements it contains have a dynamic contents. */ | |
ee715b5a | 1839 | if (is_dynamic_type_internal (TYPE_INDEX_TYPE (type), 0)) |
80180f79 | 1840 | return 1; |
ee715b5a | 1841 | return is_dynamic_type_internal (TYPE_TARGET_TYPE (type), 0); |
80180f79 | 1842 | } |
012370f6 TT |
1843 | |
1844 | case TYPE_CODE_STRUCT: | |
1845 | case TYPE_CODE_UNION: | |
1846 | { | |
1847 | int i; | |
1848 | ||
1849 | for (i = 0; i < TYPE_NFIELDS (type); ++i) | |
1850 | if (!field_is_static (&TYPE_FIELD (type, i)) | |
ee715b5a | 1851 | && is_dynamic_type_internal (TYPE_FIELD_TYPE (type, i), 0)) |
012370f6 TT |
1852 | return 1; |
1853 | } | |
1854 | break; | |
80180f79 | 1855 | } |
92e2a17f TT |
1856 | |
1857 | return 0; | |
80180f79 SA |
1858 | } |
1859 | ||
d98b7a16 TT |
1860 | /* See gdbtypes.h. */ |
1861 | ||
1862 | int | |
1863 | is_dynamic_type (struct type *type) | |
1864 | { | |
ee715b5a | 1865 | return is_dynamic_type_internal (type, 1); |
d98b7a16 TT |
1866 | } |
1867 | ||
df25ebbd | 1868 | static struct type *resolve_dynamic_type_internal |
ee715b5a | 1869 | (struct type *type, struct property_addr_info *addr_stack, int top_level); |
d98b7a16 | 1870 | |
df25ebbd JB |
1871 | /* Given a dynamic range type (dyn_range_type) and a stack of |
1872 | struct property_addr_info elements, return a static version | |
1873 | of that type. */ | |
d190df30 | 1874 | |
80180f79 | 1875 | static struct type * |
df25ebbd JB |
1876 | resolve_dynamic_range (struct type *dyn_range_type, |
1877 | struct property_addr_info *addr_stack) | |
80180f79 SA |
1878 | { |
1879 | CORE_ADDR value; | |
ddb87a81 | 1880 | struct type *static_range_type, *static_target_type; |
80180f79 SA |
1881 | const struct dynamic_prop *prop; |
1882 | const struct dwarf2_locexpr_baton *baton; | |
1883 | struct dynamic_prop low_bound, high_bound; | |
1884 | ||
6f8a3220 | 1885 | gdb_assert (TYPE_CODE (dyn_range_type) == TYPE_CODE_RANGE); |
80180f79 | 1886 | |
6f8a3220 | 1887 | prop = &TYPE_RANGE_DATA (dyn_range_type)->low; |
df25ebbd | 1888 | if (dwarf2_evaluate_property (prop, addr_stack, &value)) |
80180f79 SA |
1889 | { |
1890 | low_bound.kind = PROP_CONST; | |
1891 | low_bound.data.const_val = value; | |
1892 | } | |
1893 | else | |
1894 | { | |
1895 | low_bound.kind = PROP_UNDEFINED; | |
1896 | low_bound.data.const_val = 0; | |
1897 | } | |
1898 | ||
6f8a3220 | 1899 | prop = &TYPE_RANGE_DATA (dyn_range_type)->high; |
df25ebbd | 1900 | if (dwarf2_evaluate_property (prop, addr_stack, &value)) |
80180f79 SA |
1901 | { |
1902 | high_bound.kind = PROP_CONST; | |
1903 | high_bound.data.const_val = value; | |
c451ebe5 | 1904 | |
6f8a3220 | 1905 | if (TYPE_RANGE_DATA (dyn_range_type)->flag_upper_bound_is_count) |
c451ebe5 SA |
1906 | high_bound.data.const_val |
1907 | = low_bound.data.const_val + high_bound.data.const_val - 1; | |
80180f79 SA |
1908 | } |
1909 | else | |
1910 | { | |
1911 | high_bound.kind = PROP_UNDEFINED; | |
1912 | high_bound.data.const_val = 0; | |
1913 | } | |
1914 | ||
ddb87a81 JB |
1915 | static_target_type |
1916 | = resolve_dynamic_type_internal (TYPE_TARGET_TYPE (dyn_range_type), | |
ee715b5a | 1917 | addr_stack, 0); |
6f8a3220 | 1918 | static_range_type = create_range_type (copy_type (dyn_range_type), |
ddb87a81 | 1919 | static_target_type, |
6f8a3220 JB |
1920 | &low_bound, &high_bound); |
1921 | TYPE_RANGE_DATA (static_range_type)->flag_bound_evaluated = 1; | |
1922 | return static_range_type; | |
1923 | } | |
1924 | ||
1925 | /* Resolves dynamic bound values of an array type TYPE to static ones. | |
df25ebbd JB |
1926 | ADDR_STACK is a stack of struct property_addr_info to be used |
1927 | if needed during the dynamic resolution. */ | |
6f8a3220 JB |
1928 | |
1929 | static struct type * | |
df25ebbd JB |
1930 | resolve_dynamic_array (struct type *type, |
1931 | struct property_addr_info *addr_stack) | |
6f8a3220 JB |
1932 | { |
1933 | CORE_ADDR value; | |
1934 | struct type *elt_type; | |
1935 | struct type *range_type; | |
1936 | struct type *ary_dim; | |
1937 | ||
1938 | gdb_assert (TYPE_CODE (type) == TYPE_CODE_ARRAY); | |
1939 | ||
1940 | elt_type = type; | |
1941 | range_type = check_typedef (TYPE_INDEX_TYPE (elt_type)); | |
df25ebbd | 1942 | range_type = resolve_dynamic_range (range_type, addr_stack); |
6f8a3220 | 1943 | |
80180f79 SA |
1944 | ary_dim = check_typedef (TYPE_TARGET_TYPE (elt_type)); |
1945 | ||
1946 | if (ary_dim != NULL && TYPE_CODE (ary_dim) == TYPE_CODE_ARRAY) | |
d0d84780 | 1947 | elt_type = resolve_dynamic_array (ary_dim, addr_stack); |
80180f79 SA |
1948 | else |
1949 | elt_type = TYPE_TARGET_TYPE (type); | |
1950 | ||
75ea5859 JB |
1951 | return create_array_type_with_stride (copy_type (type), |
1952 | elt_type, range_type, | |
1953 | TYPE_FIELD_BITSIZE (type, 0)); | |
80180f79 SA |
1954 | } |
1955 | ||
012370f6 | 1956 | /* Resolve dynamic bounds of members of the union TYPE to static |
df25ebbd JB |
1957 | bounds. ADDR_STACK is a stack of struct property_addr_info |
1958 | to be used if needed during the dynamic resolution. */ | |
012370f6 TT |
1959 | |
1960 | static struct type * | |
df25ebbd JB |
1961 | resolve_dynamic_union (struct type *type, |
1962 | struct property_addr_info *addr_stack) | |
012370f6 TT |
1963 | { |
1964 | struct type *resolved_type; | |
1965 | int i; | |
1966 | unsigned int max_len = 0; | |
1967 | ||
1968 | gdb_assert (TYPE_CODE (type) == TYPE_CODE_UNION); | |
1969 | ||
1970 | resolved_type = copy_type (type); | |
1971 | TYPE_FIELDS (resolved_type) | |
1972 | = TYPE_ALLOC (resolved_type, | |
1973 | TYPE_NFIELDS (resolved_type) * sizeof (struct field)); | |
1974 | memcpy (TYPE_FIELDS (resolved_type), | |
1975 | TYPE_FIELDS (type), | |
1976 | TYPE_NFIELDS (resolved_type) * sizeof (struct field)); | |
1977 | for (i = 0; i < TYPE_NFIELDS (resolved_type); ++i) | |
1978 | { | |
1979 | struct type *t; | |
1980 | ||
1981 | if (field_is_static (&TYPE_FIELD (type, i))) | |
1982 | continue; | |
1983 | ||
d98b7a16 | 1984 | t = resolve_dynamic_type_internal (TYPE_FIELD_TYPE (resolved_type, i), |
ee715b5a | 1985 | addr_stack, 0); |
012370f6 TT |
1986 | TYPE_FIELD_TYPE (resolved_type, i) = t; |
1987 | if (TYPE_LENGTH (t) > max_len) | |
1988 | max_len = TYPE_LENGTH (t); | |
1989 | } | |
1990 | ||
1991 | TYPE_LENGTH (resolved_type) = max_len; | |
1992 | return resolved_type; | |
1993 | } | |
1994 | ||
1995 | /* Resolve dynamic bounds of members of the struct TYPE to static | |
df25ebbd JB |
1996 | bounds. ADDR_STACK is a stack of struct property_addr_info to |
1997 | be used if needed during the dynamic resolution. */ | |
012370f6 TT |
1998 | |
1999 | static struct type * | |
df25ebbd JB |
2000 | resolve_dynamic_struct (struct type *type, |
2001 | struct property_addr_info *addr_stack) | |
012370f6 TT |
2002 | { |
2003 | struct type *resolved_type; | |
2004 | int i; | |
6908c509 | 2005 | unsigned resolved_type_bit_length = 0; |
012370f6 TT |
2006 | |
2007 | gdb_assert (TYPE_CODE (type) == TYPE_CODE_STRUCT); | |
2008 | gdb_assert (TYPE_NFIELDS (type) > 0); | |
2009 | ||
2010 | resolved_type = copy_type (type); | |
2011 | TYPE_FIELDS (resolved_type) | |
2012 | = TYPE_ALLOC (resolved_type, | |
2013 | TYPE_NFIELDS (resolved_type) * sizeof (struct field)); | |
2014 | memcpy (TYPE_FIELDS (resolved_type), | |
2015 | TYPE_FIELDS (type), | |
2016 | TYPE_NFIELDS (resolved_type) * sizeof (struct field)); | |
2017 | for (i = 0; i < TYPE_NFIELDS (resolved_type); ++i) | |
2018 | { | |
6908c509 | 2019 | unsigned new_bit_length; |
df25ebbd | 2020 | struct property_addr_info pinfo; |
012370f6 TT |
2021 | |
2022 | if (field_is_static (&TYPE_FIELD (type, i))) | |
2023 | continue; | |
2024 | ||
6908c509 JB |
2025 | /* As we know this field is not a static field, the field's |
2026 | field_loc_kind should be FIELD_LOC_KIND_BITPOS. Verify | |
2027 | this is the case, but only trigger a simple error rather | |
2028 | than an internal error if that fails. While failing | |
2029 | that verification indicates a bug in our code, the error | |
2030 | is not severe enough to suggest to the user he stops | |
2031 | his debugging session because of it. */ | |
df25ebbd | 2032 | if (TYPE_FIELD_LOC_KIND (type, i) != FIELD_LOC_KIND_BITPOS) |
6908c509 JB |
2033 | error (_("Cannot determine struct field location" |
2034 | " (invalid location kind)")); | |
df25ebbd JB |
2035 | |
2036 | pinfo.type = check_typedef (TYPE_FIELD_TYPE (type, i)); | |
c3345124 | 2037 | pinfo.valaddr = addr_stack->valaddr; |
df25ebbd JB |
2038 | pinfo.addr = addr_stack->addr; |
2039 | pinfo.next = addr_stack; | |
2040 | ||
2041 | TYPE_FIELD_TYPE (resolved_type, i) | |
2042 | = resolve_dynamic_type_internal (TYPE_FIELD_TYPE (resolved_type, i), | |
ee715b5a | 2043 | &pinfo, 0); |
df25ebbd JB |
2044 | gdb_assert (TYPE_FIELD_LOC_KIND (resolved_type, i) |
2045 | == FIELD_LOC_KIND_BITPOS); | |
2046 | ||
6908c509 JB |
2047 | new_bit_length = TYPE_FIELD_BITPOS (resolved_type, i); |
2048 | if (TYPE_FIELD_BITSIZE (resolved_type, i) != 0) | |
2049 | new_bit_length += TYPE_FIELD_BITSIZE (resolved_type, i); | |
2050 | else | |
2051 | new_bit_length += (TYPE_LENGTH (TYPE_FIELD_TYPE (resolved_type, i)) | |
2052 | * TARGET_CHAR_BIT); | |
2053 | ||
2054 | /* Normally, we would use the position and size of the last field | |
2055 | to determine the size of the enclosing structure. But GCC seems | |
2056 | to be encoding the position of some fields incorrectly when | |
2057 | the struct contains a dynamic field that is not placed last. | |
2058 | So we compute the struct size based on the field that has | |
2059 | the highest position + size - probably the best we can do. */ | |
2060 | if (new_bit_length > resolved_type_bit_length) | |
2061 | resolved_type_bit_length = new_bit_length; | |
012370f6 TT |
2062 | } |
2063 | ||
012370f6 | 2064 | TYPE_LENGTH (resolved_type) |
6908c509 JB |
2065 | = (resolved_type_bit_length + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT; |
2066 | ||
9e195661 PMR |
2067 | /* The Ada language uses this field as a cache for static fixed types: reset |
2068 | it as RESOLVED_TYPE must have its own static fixed type. */ | |
2069 | TYPE_TARGET_TYPE (resolved_type) = NULL; | |
2070 | ||
012370f6 TT |
2071 | return resolved_type; |
2072 | } | |
2073 | ||
d98b7a16 | 2074 | /* Worker for resolved_dynamic_type. */ |
80180f79 | 2075 | |
d98b7a16 | 2076 | static struct type * |
df25ebbd | 2077 | resolve_dynamic_type_internal (struct type *type, |
ee715b5a PMR |
2078 | struct property_addr_info *addr_stack, |
2079 | int top_level) | |
80180f79 SA |
2080 | { |
2081 | struct type *real_type = check_typedef (type); | |
6f8a3220 | 2082 | struct type *resolved_type = type; |
d9823cbb | 2083 | struct dynamic_prop *prop; |
3cdcd0ce | 2084 | CORE_ADDR value; |
80180f79 | 2085 | |
ee715b5a | 2086 | if (!is_dynamic_type_internal (real_type, top_level)) |
80180f79 SA |
2087 | return type; |
2088 | ||
5537b577 | 2089 | if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF) |
6f8a3220 | 2090 | { |
cac9b138 JK |
2091 | resolved_type = copy_type (type); |
2092 | TYPE_TARGET_TYPE (resolved_type) | |
ee715b5a PMR |
2093 | = resolve_dynamic_type_internal (TYPE_TARGET_TYPE (type), addr_stack, |
2094 | top_level); | |
5537b577 JK |
2095 | } |
2096 | else | |
2097 | { | |
2098 | /* Before trying to resolve TYPE, make sure it is not a stub. */ | |
2099 | type = real_type; | |
012370f6 | 2100 | |
5537b577 JK |
2101 | switch (TYPE_CODE (type)) |
2102 | { | |
e771e4be PMR |
2103 | case TYPE_CODE_REF: |
2104 | { | |
2105 | struct property_addr_info pinfo; | |
2106 | ||
2107 | pinfo.type = check_typedef (TYPE_TARGET_TYPE (type)); | |
c3345124 JB |
2108 | pinfo.valaddr = NULL; |
2109 | if (addr_stack->valaddr != NULL) | |
2110 | pinfo.addr = extract_typed_address (addr_stack->valaddr, type); | |
2111 | else | |
2112 | pinfo.addr = read_memory_typed_address (addr_stack->addr, type); | |
e771e4be PMR |
2113 | pinfo.next = addr_stack; |
2114 | ||
2115 | resolved_type = copy_type (type); | |
2116 | TYPE_TARGET_TYPE (resolved_type) | |
2117 | = resolve_dynamic_type_internal (TYPE_TARGET_TYPE (type), | |
2118 | &pinfo, top_level); | |
2119 | break; | |
2120 | } | |
2121 | ||
5537b577 | 2122 | case TYPE_CODE_ARRAY: |
df25ebbd | 2123 | resolved_type = resolve_dynamic_array (type, addr_stack); |
5537b577 JK |
2124 | break; |
2125 | ||
2126 | case TYPE_CODE_RANGE: | |
df25ebbd | 2127 | resolved_type = resolve_dynamic_range (type, addr_stack); |
5537b577 JK |
2128 | break; |
2129 | ||
2130 | case TYPE_CODE_UNION: | |
df25ebbd | 2131 | resolved_type = resolve_dynamic_union (type, addr_stack); |
5537b577 JK |
2132 | break; |
2133 | ||
2134 | case TYPE_CODE_STRUCT: | |
df25ebbd | 2135 | resolved_type = resolve_dynamic_struct (type, addr_stack); |
5537b577 JK |
2136 | break; |
2137 | } | |
6f8a3220 | 2138 | } |
80180f79 | 2139 | |
3cdcd0ce JB |
2140 | /* Resolve data_location attribute. */ |
2141 | prop = TYPE_DATA_LOCATION (resolved_type); | |
d9823cbb | 2142 | if (prop != NULL && dwarf2_evaluate_property (prop, addr_stack, &value)) |
3cdcd0ce | 2143 | { |
d9823cbb KB |
2144 | TYPE_DYN_PROP_ADDR (prop) = value; |
2145 | TYPE_DYN_PROP_KIND (prop) = PROP_CONST; | |
3cdcd0ce | 2146 | } |
3cdcd0ce | 2147 | |
80180f79 SA |
2148 | return resolved_type; |
2149 | } | |
2150 | ||
d98b7a16 TT |
2151 | /* See gdbtypes.h */ |
2152 | ||
2153 | struct type * | |
c3345124 JB |
2154 | resolve_dynamic_type (struct type *type, const gdb_byte *valaddr, |
2155 | CORE_ADDR addr) | |
d98b7a16 | 2156 | { |
c3345124 JB |
2157 | struct property_addr_info pinfo |
2158 | = {check_typedef (type), valaddr, addr, NULL}; | |
df25ebbd | 2159 | |
ee715b5a | 2160 | return resolve_dynamic_type_internal (type, &pinfo, 1); |
d98b7a16 TT |
2161 | } |
2162 | ||
d9823cbb KB |
2163 | /* See gdbtypes.h */ |
2164 | ||
2165 | struct dynamic_prop * | |
2166 | get_dyn_prop (enum dynamic_prop_node_kind prop_kind, const struct type *type) | |
2167 | { | |
2168 | struct dynamic_prop_list *node = TYPE_DYN_PROP_LIST (type); | |
2169 | ||
2170 | while (node != NULL) | |
2171 | { | |
2172 | if (node->prop_kind == prop_kind) | |
283a9958 | 2173 | return &node->prop; |
d9823cbb KB |
2174 | node = node->next; |
2175 | } | |
2176 | return NULL; | |
2177 | } | |
2178 | ||
2179 | /* See gdbtypes.h */ | |
2180 | ||
2181 | void | |
2182 | add_dyn_prop (enum dynamic_prop_node_kind prop_kind, struct dynamic_prop prop, | |
2183 | struct type *type, struct objfile *objfile) | |
2184 | { | |
2185 | struct dynamic_prop_list *temp; | |
2186 | ||
2187 | gdb_assert (TYPE_OBJFILE_OWNED (type)); | |
2188 | ||
2189 | temp = obstack_alloc (&objfile->objfile_obstack, | |
2190 | sizeof (struct dynamic_prop_list)); | |
2191 | temp->prop_kind = prop_kind; | |
283a9958 | 2192 | temp->prop = prop; |
d9823cbb KB |
2193 | temp->next = TYPE_DYN_PROP_LIST (type); |
2194 | ||
2195 | TYPE_DYN_PROP_LIST (type) = temp; | |
2196 | } | |
2197 | ||
2198 | ||
92163a10 JK |
2199 | /* Find the real type of TYPE. This function returns the real type, |
2200 | after removing all layers of typedefs, and completing opaque or stub | |
2201 | types. Completion changes the TYPE argument, but stripping of | |
2202 | typedefs does not. | |
2203 | ||
2204 | Instance flags (e.g. const/volatile) are preserved as typedefs are | |
2205 | stripped. If necessary a new qualified form of the underlying type | |
2206 | is created. | |
2207 | ||
2208 | NOTE: This will return a typedef if TYPE_TARGET_TYPE for the typedef has | |
2209 | not been computed and we're either in the middle of reading symbols, or | |
2210 | there was no name for the typedef in the debug info. | |
2211 | ||
9bc118a5 DE |
2212 | NOTE: Lookup of opaque types can throw errors for invalid symbol files. |
2213 | QUITs in the symbol reading code can also throw. | |
2214 | Thus this function can throw an exception. | |
2215 | ||
92163a10 JK |
2216 | If TYPE is a TYPE_CODE_TYPEDEF, its length is updated to the length of |
2217 | the target type. | |
c906108c SS |
2218 | |
2219 | If this is a stubbed struct (i.e. declared as struct foo *), see if | |
0963b4bd | 2220 | we can find a full definition in some other file. If so, copy this |
7ba81444 MS |
2221 | definition, so we can use it in future. There used to be a comment |
2222 | (but not any code) that if we don't find a full definition, we'd | |
2223 | set a flag so we don't spend time in the future checking the same | |
2224 | type. That would be a mistake, though--we might load in more | |
92163a10 | 2225 | symbols which contain a full definition for the type. */ |
c906108c SS |
2226 | |
2227 | struct type * | |
a02fd225 | 2228 | check_typedef (struct type *type) |
c906108c SS |
2229 | { |
2230 | struct type *orig_type = type; | |
92163a10 JK |
2231 | /* While we're removing typedefs, we don't want to lose qualifiers. |
2232 | E.g., const/volatile. */ | |
2233 | int instance_flags = TYPE_INSTANCE_FLAGS (type); | |
a02fd225 | 2234 | |
423c0af8 MS |
2235 | gdb_assert (type); |
2236 | ||
c906108c SS |
2237 | while (TYPE_CODE (type) == TYPE_CODE_TYPEDEF) |
2238 | { | |
2239 | if (!TYPE_TARGET_TYPE (type)) | |
2240 | { | |
0d5cff50 | 2241 | const char *name; |
c906108c SS |
2242 | struct symbol *sym; |
2243 | ||
2244 | /* It is dangerous to call lookup_symbol if we are currently | |
7ba81444 | 2245 | reading a symtab. Infinite recursion is one danger. */ |
c906108c | 2246 | if (currently_reading_symtab) |
92163a10 | 2247 | return make_qualified_type (type, instance_flags, NULL); |
c906108c SS |
2248 | |
2249 | name = type_name_no_tag (type); | |
7ba81444 MS |
2250 | /* FIXME: shouldn't we separately check the TYPE_NAME and |
2251 | the TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or | |
2252 | VAR_DOMAIN as appropriate? (this code was written before | |
2253 | TYPE_NAME and TYPE_TAG_NAME were separate). */ | |
c906108c SS |
2254 | if (name == NULL) |
2255 | { | |
23136709 | 2256 | stub_noname_complaint (); |
92163a10 | 2257 | return make_qualified_type (type, instance_flags, NULL); |
c906108c | 2258 | } |
d12307c1 | 2259 | sym = lookup_symbol (name, 0, STRUCT_DOMAIN, 0).symbol; |
c906108c SS |
2260 | if (sym) |
2261 | TYPE_TARGET_TYPE (type) = SYMBOL_TYPE (sym); | |
7ba81444 | 2262 | else /* TYPE_CODE_UNDEF */ |
e9bb382b | 2263 | TYPE_TARGET_TYPE (type) = alloc_type_arch (get_type_arch (type)); |
c906108c SS |
2264 | } |
2265 | type = TYPE_TARGET_TYPE (type); | |
c906108c | 2266 | |
92163a10 JK |
2267 | /* Preserve the instance flags as we traverse down the typedef chain. |
2268 | ||
2269 | Handling address spaces/classes is nasty, what do we do if there's a | |
2270 | conflict? | |
2271 | E.g., what if an outer typedef marks the type as class_1 and an inner | |
2272 | typedef marks the type as class_2? | |
2273 | This is the wrong place to do such error checking. We leave it to | |
2274 | the code that created the typedef in the first place to flag the | |
2275 | error. We just pick the outer address space (akin to letting the | |
2276 | outer cast in a chain of casting win), instead of assuming | |
2277 | "it can't happen". */ | |
2278 | { | |
2279 | const int ALL_SPACES = (TYPE_INSTANCE_FLAG_CODE_SPACE | |
2280 | | TYPE_INSTANCE_FLAG_DATA_SPACE); | |
2281 | const int ALL_CLASSES = TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL; | |
2282 | int new_instance_flags = TYPE_INSTANCE_FLAGS (type); | |
2283 | ||
2284 | /* Treat code vs data spaces and address classes separately. */ | |
2285 | if ((instance_flags & ALL_SPACES) != 0) | |
2286 | new_instance_flags &= ~ALL_SPACES; | |
2287 | if ((instance_flags & ALL_CLASSES) != 0) | |
2288 | new_instance_flags &= ~ALL_CLASSES; | |
2289 | ||
2290 | instance_flags |= new_instance_flags; | |
2291 | } | |
2292 | } | |
a02fd225 | 2293 | |
7ba81444 MS |
2294 | /* If this is a struct/class/union with no fields, then check |
2295 | whether a full definition exists somewhere else. This is for | |
2296 | systems where a type definition with no fields is issued for such | |
2297 | types, instead of identifying them as stub types in the first | |
2298 | place. */ | |
c5aa993b | 2299 | |
7ba81444 MS |
2300 | if (TYPE_IS_OPAQUE (type) |
2301 | && opaque_type_resolution | |
2302 | && !currently_reading_symtab) | |
c906108c | 2303 | { |
0d5cff50 | 2304 | const char *name = type_name_no_tag (type); |
c5aa993b | 2305 | struct type *newtype; |
d8734c88 | 2306 | |
c906108c SS |
2307 | if (name == NULL) |
2308 | { | |
23136709 | 2309 | stub_noname_complaint (); |
92163a10 | 2310 | return make_qualified_type (type, instance_flags, NULL); |
c906108c SS |
2311 | } |
2312 | newtype = lookup_transparent_type (name); | |
ad766c0a | 2313 | |
c906108c | 2314 | if (newtype) |
ad766c0a | 2315 | { |
7ba81444 MS |
2316 | /* If the resolved type and the stub are in the same |
2317 | objfile, then replace the stub type with the real deal. | |
2318 | But if they're in separate objfiles, leave the stub | |
2319 | alone; we'll just look up the transparent type every time | |
2320 | we call check_typedef. We can't create pointers between | |
2321 | types allocated to different objfiles, since they may | |
2322 | have different lifetimes. Trying to copy NEWTYPE over to | |
2323 | TYPE's objfile is pointless, too, since you'll have to | |
2324 | move over any other types NEWTYPE refers to, which could | |
2325 | be an unbounded amount of stuff. */ | |
ad766c0a | 2326 | if (TYPE_OBJFILE (newtype) == TYPE_OBJFILE (type)) |
92163a10 JK |
2327 | type = make_qualified_type (newtype, |
2328 | TYPE_INSTANCE_FLAGS (type), | |
2329 | type); | |
ad766c0a JB |
2330 | else |
2331 | type = newtype; | |
2332 | } | |
c906108c | 2333 | } |
7ba81444 MS |
2334 | /* Otherwise, rely on the stub flag being set for opaque/stubbed |
2335 | types. */ | |
74a9bb82 | 2336 | else if (TYPE_STUB (type) && !currently_reading_symtab) |
c906108c | 2337 | { |
0d5cff50 | 2338 | const char *name = type_name_no_tag (type); |
c906108c | 2339 | /* FIXME: shouldn't we separately check the TYPE_NAME and the |
176620f1 | 2340 | TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or VAR_DOMAIN |
7b83ea04 AC |
2341 | as appropriate? (this code was written before TYPE_NAME and |
2342 | TYPE_TAG_NAME were separate). */ | |
c906108c | 2343 | struct symbol *sym; |
d8734c88 | 2344 | |
c906108c SS |
2345 | if (name == NULL) |
2346 | { | |
23136709 | 2347 | stub_noname_complaint (); |
92163a10 | 2348 | return make_qualified_type (type, instance_flags, NULL); |
c906108c | 2349 | } |
d12307c1 | 2350 | sym = lookup_symbol (name, 0, STRUCT_DOMAIN, 0).symbol; |
c906108c | 2351 | if (sym) |
c26f2453 JB |
2352 | { |
2353 | /* Same as above for opaque types, we can replace the stub | |
92163a10 | 2354 | with the complete type only if they are in the same |
c26f2453 JB |
2355 | objfile. */ |
2356 | if (TYPE_OBJFILE (SYMBOL_TYPE(sym)) == TYPE_OBJFILE (type)) | |
92163a10 JK |
2357 | type = make_qualified_type (SYMBOL_TYPE (sym), |
2358 | TYPE_INSTANCE_FLAGS (type), | |
2359 | type); | |
c26f2453 JB |
2360 | else |
2361 | type = SYMBOL_TYPE (sym); | |
2362 | } | |
c906108c SS |
2363 | } |
2364 | ||
74a9bb82 | 2365 | if (TYPE_TARGET_STUB (type)) |
c906108c SS |
2366 | { |
2367 | struct type *range_type; | |
2368 | struct type *target_type = check_typedef (TYPE_TARGET_TYPE (type)); | |
2369 | ||
74a9bb82 | 2370 | if (TYPE_STUB (target_type) || TYPE_TARGET_STUB (target_type)) |
c5aa993b | 2371 | { |
73e2eb35 | 2372 | /* Nothing we can do. */ |
c5aa993b | 2373 | } |
c906108c SS |
2374 | else if (TYPE_CODE (type) == TYPE_CODE_RANGE) |
2375 | { | |
2376 | TYPE_LENGTH (type) = TYPE_LENGTH (target_type); | |
876cecd0 | 2377 | TYPE_TARGET_STUB (type) = 0; |
c906108c SS |
2378 | } |
2379 | } | |
92163a10 JK |
2380 | |
2381 | type = make_qualified_type (type, instance_flags, NULL); | |
2382 | ||
7ba81444 | 2383 | /* Cache TYPE_LENGTH for future use. */ |
c906108c | 2384 | TYPE_LENGTH (orig_type) = TYPE_LENGTH (type); |
92163a10 | 2385 | |
c906108c SS |
2386 | return type; |
2387 | } | |
2388 | ||
7ba81444 | 2389 | /* Parse a type expression in the string [P..P+LENGTH). If an error |
48319d1f | 2390 | occurs, silently return a void type. */ |
c91ecb25 | 2391 | |
b9362cc7 | 2392 | static struct type * |
48319d1f | 2393 | safe_parse_type (struct gdbarch *gdbarch, char *p, int length) |
c91ecb25 ND |
2394 | { |
2395 | struct ui_file *saved_gdb_stderr; | |
34365054 | 2396 | struct type *type = NULL; /* Initialize to keep gcc happy. */ |
c91ecb25 | 2397 | |
7ba81444 | 2398 | /* Suppress error messages. */ |
c91ecb25 ND |
2399 | saved_gdb_stderr = gdb_stderr; |
2400 | gdb_stderr = ui_file_new (); | |
2401 | ||
7ba81444 | 2402 | /* Call parse_and_eval_type() without fear of longjmp()s. */ |
492d29ea | 2403 | TRY |
8e7b59a5 KS |
2404 | { |
2405 | type = parse_and_eval_type (p, length); | |
2406 | } | |
492d29ea PA |
2407 | CATCH (except, RETURN_MASK_ERROR) |
2408 | { | |
2409 | type = builtin_type (gdbarch)->builtin_void; | |
2410 | } | |
2411 | END_CATCH | |
c91ecb25 | 2412 | |
7ba81444 | 2413 | /* Stop suppressing error messages. */ |
c91ecb25 ND |
2414 | ui_file_delete (gdb_stderr); |
2415 | gdb_stderr = saved_gdb_stderr; | |
2416 | ||
2417 | return type; | |
2418 | } | |
2419 | ||
c906108c SS |
2420 | /* Ugly hack to convert method stubs into method types. |
2421 | ||
7ba81444 MS |
2422 | He ain't kiddin'. This demangles the name of the method into a |
2423 | string including argument types, parses out each argument type, | |
2424 | generates a string casting a zero to that type, evaluates the | |
2425 | string, and stuffs the resulting type into an argtype vector!!! | |
2426 | Then it knows the type of the whole function (including argument | |
2427 | types for overloading), which info used to be in the stab's but was | |
2428 | removed to hack back the space required for them. */ | |
c906108c | 2429 | |
de17c821 | 2430 | static void |
fba45db2 | 2431 | check_stub_method (struct type *type, int method_id, int signature_id) |
c906108c | 2432 | { |
50810684 | 2433 | struct gdbarch *gdbarch = get_type_arch (type); |
c906108c SS |
2434 | struct fn_field *f; |
2435 | char *mangled_name = gdb_mangle_name (type, method_id, signature_id); | |
8de20a37 TT |
2436 | char *demangled_name = gdb_demangle (mangled_name, |
2437 | DMGL_PARAMS | DMGL_ANSI); | |
c906108c SS |
2438 | char *argtypetext, *p; |
2439 | int depth = 0, argcount = 1; | |
ad2f7632 | 2440 | struct field *argtypes; |
c906108c SS |
2441 | struct type *mtype; |
2442 | ||
2443 | /* Make sure we got back a function string that we can use. */ | |
2444 | if (demangled_name) | |
2445 | p = strchr (demangled_name, '('); | |
502dcf4e AC |
2446 | else |
2447 | p = NULL; | |
c906108c SS |
2448 | |
2449 | if (demangled_name == NULL || p == NULL) | |
7ba81444 MS |
2450 | error (_("Internal: Cannot demangle mangled name `%s'."), |
2451 | mangled_name); | |
c906108c SS |
2452 | |
2453 | /* Now, read in the parameters that define this type. */ | |
2454 | p += 1; | |
2455 | argtypetext = p; | |
2456 | while (*p) | |
2457 | { | |
070ad9f0 | 2458 | if (*p == '(' || *p == '<') |
c906108c SS |
2459 | { |
2460 | depth += 1; | |
2461 | } | |
070ad9f0 | 2462 | else if (*p == ')' || *p == '>') |
c906108c SS |
2463 | { |
2464 | depth -= 1; | |
2465 | } | |
2466 | else if (*p == ',' && depth == 0) | |
2467 | { | |
2468 | argcount += 1; | |
2469 | } | |
2470 | ||
2471 | p += 1; | |
2472 | } | |
2473 | ||
ad2f7632 | 2474 | /* If we read one argument and it was ``void'', don't count it. */ |
61012eef | 2475 | if (startswith (argtypetext, "(void)")) |
ad2f7632 | 2476 | argcount -= 1; |
c906108c | 2477 | |
ad2f7632 DJ |
2478 | /* We need one extra slot, for the THIS pointer. */ |
2479 | ||
2480 | argtypes = (struct field *) | |
2481 | TYPE_ALLOC (type, (argcount + 1) * sizeof (struct field)); | |
c906108c | 2482 | p = argtypetext; |
4a1970e4 DJ |
2483 | |
2484 | /* Add THIS pointer for non-static methods. */ | |
2485 | f = TYPE_FN_FIELDLIST1 (type, method_id); | |
2486 | if (TYPE_FN_FIELD_STATIC_P (f, signature_id)) | |
2487 | argcount = 0; | |
2488 | else | |
2489 | { | |
ad2f7632 | 2490 | argtypes[0].type = lookup_pointer_type (type); |
4a1970e4 DJ |
2491 | argcount = 1; |
2492 | } | |
c906108c | 2493 | |
0963b4bd | 2494 | if (*p != ')') /* () means no args, skip while. */ |
c906108c SS |
2495 | { |
2496 | depth = 0; | |
2497 | while (*p) | |
2498 | { | |
2499 | if (depth <= 0 && (*p == ',' || *p == ')')) | |
2500 | { | |
ad2f7632 DJ |
2501 | /* Avoid parsing of ellipsis, they will be handled below. |
2502 | Also avoid ``void'' as above. */ | |
2503 | if (strncmp (argtypetext, "...", p - argtypetext) != 0 | |
2504 | && strncmp (argtypetext, "void", p - argtypetext) != 0) | |
c906108c | 2505 | { |
ad2f7632 | 2506 | argtypes[argcount].type = |
48319d1f | 2507 | safe_parse_type (gdbarch, argtypetext, p - argtypetext); |
c906108c SS |
2508 | argcount += 1; |
2509 | } | |
2510 | argtypetext = p + 1; | |
2511 | } | |
2512 | ||
070ad9f0 | 2513 | if (*p == '(' || *p == '<') |
c906108c SS |
2514 | { |
2515 | depth += 1; | |
2516 | } | |
070ad9f0 | 2517 | else if (*p == ')' || *p == '>') |
c906108c SS |
2518 | { |
2519 | depth -= 1; | |
2520 | } | |
2521 | ||
2522 | p += 1; | |
2523 | } | |
2524 | } | |
2525 | ||
c906108c SS |
2526 | TYPE_FN_FIELD_PHYSNAME (f, signature_id) = mangled_name; |
2527 | ||
2528 | /* Now update the old "stub" type into a real type. */ | |
2529 | mtype = TYPE_FN_FIELD_TYPE (f, signature_id); | |
09e2d7c7 DE |
2530 | /* MTYPE may currently be a function (TYPE_CODE_FUNC). |
2531 | We want a method (TYPE_CODE_METHOD). */ | |
2532 | smash_to_method_type (mtype, type, TYPE_TARGET_TYPE (mtype), | |
2533 | argtypes, argcount, p[-2] == '.'); | |
876cecd0 | 2534 | TYPE_STUB (mtype) = 0; |
c906108c | 2535 | TYPE_FN_FIELD_STUB (f, signature_id) = 0; |
ad2f7632 DJ |
2536 | |
2537 | xfree (demangled_name); | |
c906108c SS |
2538 | } |
2539 | ||
7ba81444 MS |
2540 | /* This is the external interface to check_stub_method, above. This |
2541 | function unstubs all of the signatures for TYPE's METHOD_ID method | |
2542 | name. After calling this function TYPE_FN_FIELD_STUB will be | |
2543 | cleared for each signature and TYPE_FN_FIELDLIST_NAME will be | |
2544 | correct. | |
de17c821 DJ |
2545 | |
2546 | This function unfortunately can not die until stabs do. */ | |
2547 | ||
2548 | void | |
2549 | check_stub_method_group (struct type *type, int method_id) | |
2550 | { | |
2551 | int len = TYPE_FN_FIELDLIST_LENGTH (type, method_id); | |
2552 | struct fn_field *f = TYPE_FN_FIELDLIST1 (type, method_id); | |
f710f4fc | 2553 | int j, found_stub = 0; |
de17c821 DJ |
2554 | |
2555 | for (j = 0; j < len; j++) | |
2556 | if (TYPE_FN_FIELD_STUB (f, j)) | |
2557 | { | |
2558 | found_stub = 1; | |
2559 | check_stub_method (type, method_id, j); | |
2560 | } | |
2561 | ||
7ba81444 MS |
2562 | /* GNU v3 methods with incorrect names were corrected when we read |
2563 | in type information, because it was cheaper to do it then. The | |
2564 | only GNU v2 methods with incorrect method names are operators and | |
2565 | destructors; destructors were also corrected when we read in type | |
2566 | information. | |
de17c821 DJ |
2567 | |
2568 | Therefore the only thing we need to handle here are v2 operator | |
2569 | names. */ | |
61012eef | 2570 | if (found_stub && !startswith (TYPE_FN_FIELD_PHYSNAME (f, 0), "_Z")) |
de17c821 DJ |
2571 | { |
2572 | int ret; | |
2573 | char dem_opname[256]; | |
2574 | ||
7ba81444 MS |
2575 | ret = cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type, |
2576 | method_id), | |
de17c821 DJ |
2577 | dem_opname, DMGL_ANSI); |
2578 | if (!ret) | |
7ba81444 MS |
2579 | ret = cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type, |
2580 | method_id), | |
de17c821 DJ |
2581 | dem_opname, 0); |
2582 | if (ret) | |
2583 | TYPE_FN_FIELDLIST_NAME (type, method_id) = xstrdup (dem_opname); | |
2584 | } | |
2585 | } | |
2586 | ||
9655fd1a JK |
2587 | /* Ensure it is in .rodata (if available) by workarounding GCC PR 44690. */ |
2588 | const struct cplus_struct_type cplus_struct_default = { }; | |
c906108c SS |
2589 | |
2590 | void | |
fba45db2 | 2591 | allocate_cplus_struct_type (struct type *type) |
c906108c | 2592 | { |
b4ba55a1 JB |
2593 | if (HAVE_CPLUS_STRUCT (type)) |
2594 | /* Structure was already allocated. Nothing more to do. */ | |
2595 | return; | |
2596 | ||
2597 | TYPE_SPECIFIC_FIELD (type) = TYPE_SPECIFIC_CPLUS_STUFF; | |
2598 | TYPE_RAW_CPLUS_SPECIFIC (type) = (struct cplus_struct_type *) | |
2599 | TYPE_ALLOC (type, sizeof (struct cplus_struct_type)); | |
2600 | *(TYPE_RAW_CPLUS_SPECIFIC (type)) = cplus_struct_default; | |
ae6ae975 | 2601 | set_type_vptr_fieldno (type, -1); |
c906108c SS |
2602 | } |
2603 | ||
b4ba55a1 JB |
2604 | const struct gnat_aux_type gnat_aux_default = |
2605 | { NULL }; | |
2606 | ||
2607 | /* Set the TYPE's type-specific kind to TYPE_SPECIFIC_GNAT_STUFF, | |
2608 | and allocate the associated gnat-specific data. The gnat-specific | |
2609 | data is also initialized to gnat_aux_default. */ | |
5212577a | 2610 | |
b4ba55a1 JB |
2611 | void |
2612 | allocate_gnat_aux_type (struct type *type) | |
2613 | { | |
2614 | TYPE_SPECIFIC_FIELD (type) = TYPE_SPECIFIC_GNAT_STUFF; | |
2615 | TYPE_GNAT_SPECIFIC (type) = (struct gnat_aux_type *) | |
2616 | TYPE_ALLOC (type, sizeof (struct gnat_aux_type)); | |
2617 | *(TYPE_GNAT_SPECIFIC (type)) = gnat_aux_default; | |
2618 | } | |
2619 | ||
c906108c SS |
2620 | /* Helper function to initialize the standard scalar types. |
2621 | ||
86f62fd7 TT |
2622 | If NAME is non-NULL, then it is used to initialize the type name. |
2623 | Note that NAME is not copied; it is required to have a lifetime at | |
2624 | least as long as OBJFILE. */ | |
c906108c SS |
2625 | |
2626 | struct type * | |
7ba81444 | 2627 | init_type (enum type_code code, int length, int flags, |
748e18ae | 2628 | const char *name, struct objfile *objfile) |
c906108c | 2629 | { |
52f0bd74 | 2630 | struct type *type; |
c906108c SS |
2631 | |
2632 | type = alloc_type (objfile); | |
2633 | TYPE_CODE (type) = code; | |
2634 | TYPE_LENGTH (type) = length; | |
876cecd0 TT |
2635 | |
2636 | gdb_assert (!(flags & (TYPE_FLAG_MIN - 1))); | |
2637 | if (flags & TYPE_FLAG_UNSIGNED) | |
2638 | TYPE_UNSIGNED (type) = 1; | |
2639 | if (flags & TYPE_FLAG_NOSIGN) | |
2640 | TYPE_NOSIGN (type) = 1; | |
2641 | if (flags & TYPE_FLAG_STUB) | |
2642 | TYPE_STUB (type) = 1; | |
2643 | if (flags & TYPE_FLAG_TARGET_STUB) | |
2644 | TYPE_TARGET_STUB (type) = 1; | |
2645 | if (flags & TYPE_FLAG_STATIC) | |
2646 | TYPE_STATIC (type) = 1; | |
2647 | if (flags & TYPE_FLAG_PROTOTYPED) | |
2648 | TYPE_PROTOTYPED (type) = 1; | |
2649 | if (flags & TYPE_FLAG_INCOMPLETE) | |
2650 | TYPE_INCOMPLETE (type) = 1; | |
2651 | if (flags & TYPE_FLAG_VARARGS) | |
2652 | TYPE_VARARGS (type) = 1; | |
2653 | if (flags & TYPE_FLAG_VECTOR) | |
2654 | TYPE_VECTOR (type) = 1; | |
2655 | if (flags & TYPE_FLAG_STUB_SUPPORTED) | |
2656 | TYPE_STUB_SUPPORTED (type) = 1; | |
876cecd0 TT |
2657 | if (flags & TYPE_FLAG_FIXED_INSTANCE) |
2658 | TYPE_FIXED_INSTANCE (type) = 1; | |
0875794a JK |
2659 | if (flags & TYPE_FLAG_GNU_IFUNC) |
2660 | TYPE_GNU_IFUNC (type) = 1; | |
876cecd0 | 2661 | |
86f62fd7 | 2662 | TYPE_NAME (type) = name; |
c906108c SS |
2663 | |
2664 | /* C++ fancies. */ | |
2665 | ||
973ccf8b | 2666 | if (name && strcmp (name, "char") == 0) |
876cecd0 | 2667 | TYPE_NOSIGN (type) = 1; |
973ccf8b | 2668 | |
b4ba55a1 | 2669 | switch (code) |
c906108c | 2670 | { |
b4ba55a1 JB |
2671 | case TYPE_CODE_STRUCT: |
2672 | case TYPE_CODE_UNION: | |
2673 | case TYPE_CODE_NAMESPACE: | |
2674 | INIT_CPLUS_SPECIFIC (type); | |
2675 | break; | |
2676 | case TYPE_CODE_FLT: | |
2677 | TYPE_SPECIFIC_FIELD (type) = TYPE_SPECIFIC_FLOATFORMAT; | |
2678 | break; | |
2679 | case TYPE_CODE_FUNC: | |
b6cdc2c1 | 2680 | INIT_FUNC_SPECIFIC (type); |
b4ba55a1 | 2681 | break; |
c906108c | 2682 | } |
c16abbde | 2683 | return type; |
c906108c | 2684 | } |
5212577a DE |
2685 | \f |
2686 | /* Queries on types. */ | |
c906108c | 2687 | |
c906108c | 2688 | int |
fba45db2 | 2689 | can_dereference (struct type *t) |
c906108c | 2690 | { |
7ba81444 MS |
2691 | /* FIXME: Should we return true for references as well as |
2692 | pointers? */ | |
f168693b | 2693 | t = check_typedef (t); |
c906108c SS |
2694 | return |
2695 | (t != NULL | |
2696 | && TYPE_CODE (t) == TYPE_CODE_PTR | |
2697 | && TYPE_CODE (TYPE_TARGET_TYPE (t)) != TYPE_CODE_VOID); | |
2698 | } | |
2699 | ||
adf40b2e | 2700 | int |
fba45db2 | 2701 | is_integral_type (struct type *t) |
adf40b2e | 2702 | { |
f168693b | 2703 | t = check_typedef (t); |
adf40b2e JM |
2704 | return |
2705 | ((t != NULL) | |
d4f3574e SS |
2706 | && ((TYPE_CODE (t) == TYPE_CODE_INT) |
2707 | || (TYPE_CODE (t) == TYPE_CODE_ENUM) | |
4f2aea11 | 2708 | || (TYPE_CODE (t) == TYPE_CODE_FLAGS) |
d4f3574e SS |
2709 | || (TYPE_CODE (t) == TYPE_CODE_CHAR) |
2710 | || (TYPE_CODE (t) == TYPE_CODE_RANGE) | |
2711 | || (TYPE_CODE (t) == TYPE_CODE_BOOL))); | |
adf40b2e JM |
2712 | } |
2713 | ||
e09342b5 TJB |
2714 | /* Return true if TYPE is scalar. */ |
2715 | ||
2716 | static int | |
2717 | is_scalar_type (struct type *type) | |
2718 | { | |
f168693b | 2719 | type = check_typedef (type); |
e09342b5 TJB |
2720 | |
2721 | switch (TYPE_CODE (type)) | |
2722 | { | |
2723 | case TYPE_CODE_ARRAY: | |
2724 | case TYPE_CODE_STRUCT: | |
2725 | case TYPE_CODE_UNION: | |
2726 | case TYPE_CODE_SET: | |
2727 | case TYPE_CODE_STRING: | |
e09342b5 TJB |
2728 | return 0; |
2729 | default: | |
2730 | return 1; | |
2731 | } | |
2732 | } | |
2733 | ||
2734 | /* Return true if T is scalar, or a composite type which in practice has | |
90e4670f TJB |
2735 | the memory layout of a scalar type. E.g., an array or struct with only |
2736 | one scalar element inside it, or a union with only scalar elements. */ | |
e09342b5 TJB |
2737 | |
2738 | int | |
2739 | is_scalar_type_recursive (struct type *t) | |
2740 | { | |
f168693b | 2741 | t = check_typedef (t); |
e09342b5 TJB |
2742 | |
2743 | if (is_scalar_type (t)) | |
2744 | return 1; | |
2745 | /* Are we dealing with an array or string of known dimensions? */ | |
2746 | else if ((TYPE_CODE (t) == TYPE_CODE_ARRAY | |
2747 | || TYPE_CODE (t) == TYPE_CODE_STRING) && TYPE_NFIELDS (t) == 1 | |
2748 | && TYPE_CODE (TYPE_INDEX_TYPE (t)) == TYPE_CODE_RANGE) | |
2749 | { | |
2750 | LONGEST low_bound, high_bound; | |
2751 | struct type *elt_type = check_typedef (TYPE_TARGET_TYPE (t)); | |
2752 | ||
2753 | get_discrete_bounds (TYPE_INDEX_TYPE (t), &low_bound, &high_bound); | |
2754 | ||
2755 | return high_bound == low_bound && is_scalar_type_recursive (elt_type); | |
2756 | } | |
2757 | /* Are we dealing with a struct with one element? */ | |
2758 | else if (TYPE_CODE (t) == TYPE_CODE_STRUCT && TYPE_NFIELDS (t) == 1) | |
2759 | return is_scalar_type_recursive (TYPE_FIELD_TYPE (t, 0)); | |
2760 | else if (TYPE_CODE (t) == TYPE_CODE_UNION) | |
2761 | { | |
2762 | int i, n = TYPE_NFIELDS (t); | |
2763 | ||
2764 | /* If all elements of the union are scalar, then the union is scalar. */ | |
2765 | for (i = 0; i < n; i++) | |
2766 | if (!is_scalar_type_recursive (TYPE_FIELD_TYPE (t, i))) | |
2767 | return 0; | |
2768 | ||
2769 | return 1; | |
2770 | } | |
2771 | ||
2772 | return 0; | |
2773 | } | |
2774 | ||
6c659fc2 SC |
2775 | /* Return true is T is a class or a union. False otherwise. */ |
2776 | ||
2777 | int | |
2778 | class_or_union_p (const struct type *t) | |
2779 | { | |
2780 | return (TYPE_CODE (t) == TYPE_CODE_STRUCT | |
2781 | || TYPE_CODE (t) == TYPE_CODE_UNION); | |
2782 | } | |
2783 | ||
4e8f195d TT |
2784 | /* A helper function which returns true if types A and B represent the |
2785 | "same" class type. This is true if the types have the same main | |
2786 | type, or the same name. */ | |
2787 | ||
2788 | int | |
2789 | class_types_same_p (const struct type *a, const struct type *b) | |
2790 | { | |
2791 | return (TYPE_MAIN_TYPE (a) == TYPE_MAIN_TYPE (b) | |
2792 | || (TYPE_NAME (a) && TYPE_NAME (b) | |
2793 | && !strcmp (TYPE_NAME (a), TYPE_NAME (b)))); | |
2794 | } | |
2795 | ||
a9d5ef47 SW |
2796 | /* If BASE is an ancestor of DCLASS return the distance between them. |
2797 | otherwise return -1; | |
2798 | eg: | |
2799 | ||
2800 | class A {}; | |
2801 | class B: public A {}; | |
2802 | class C: public B {}; | |
2803 | class D: C {}; | |
2804 | ||
2805 | distance_to_ancestor (A, A, 0) = 0 | |
2806 | distance_to_ancestor (A, B, 0) = 1 | |
2807 | distance_to_ancestor (A, C, 0) = 2 | |
2808 | distance_to_ancestor (A, D, 0) = 3 | |
2809 | ||
2810 | If PUBLIC is 1 then only public ancestors are considered, | |
2811 | and the function returns the distance only if BASE is a public ancestor | |
2812 | of DCLASS. | |
2813 | Eg: | |
2814 | ||
0963b4bd | 2815 | distance_to_ancestor (A, D, 1) = -1. */ |
c906108c | 2816 | |
0526b37a | 2817 | static int |
fe978cb0 | 2818 | distance_to_ancestor (struct type *base, struct type *dclass, int is_public) |
c906108c SS |
2819 | { |
2820 | int i; | |
a9d5ef47 | 2821 | int d; |
c5aa993b | 2822 | |
f168693b SM |
2823 | base = check_typedef (base); |
2824 | dclass = check_typedef (dclass); | |
c906108c | 2825 | |
4e8f195d | 2826 | if (class_types_same_p (base, dclass)) |
a9d5ef47 | 2827 | return 0; |
c906108c SS |
2828 | |
2829 | for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++) | |
4e8f195d | 2830 | { |
fe978cb0 | 2831 | if (is_public && ! BASETYPE_VIA_PUBLIC (dclass, i)) |
0526b37a SW |
2832 | continue; |
2833 | ||
fe978cb0 | 2834 | d = distance_to_ancestor (base, TYPE_BASECLASS (dclass, i), is_public); |
a9d5ef47 SW |
2835 | if (d >= 0) |
2836 | return 1 + d; | |
4e8f195d | 2837 | } |
c906108c | 2838 | |
a9d5ef47 | 2839 | return -1; |
c906108c | 2840 | } |
4e8f195d | 2841 | |
0526b37a SW |
2842 | /* Check whether BASE is an ancestor or base class or DCLASS |
2843 | Return 1 if so, and 0 if not. | |
2844 | Note: If BASE and DCLASS are of the same type, this function | |
2845 | will return 1. So for some class A, is_ancestor (A, A) will | |
2846 | return 1. */ | |
2847 | ||
2848 | int | |
2849 | is_ancestor (struct type *base, struct type *dclass) | |
2850 | { | |
a9d5ef47 | 2851 | return distance_to_ancestor (base, dclass, 0) >= 0; |
0526b37a SW |
2852 | } |
2853 | ||
4e8f195d TT |
2854 | /* Like is_ancestor, but only returns true when BASE is a public |
2855 | ancestor of DCLASS. */ | |
2856 | ||
2857 | int | |
2858 | is_public_ancestor (struct type *base, struct type *dclass) | |
2859 | { | |
a9d5ef47 | 2860 | return distance_to_ancestor (base, dclass, 1) >= 0; |
4e8f195d TT |
2861 | } |
2862 | ||
2863 | /* A helper function for is_unique_ancestor. */ | |
2864 | ||
2865 | static int | |
2866 | is_unique_ancestor_worker (struct type *base, struct type *dclass, | |
2867 | int *offset, | |
8af8e3bc PA |
2868 | const gdb_byte *valaddr, int embedded_offset, |
2869 | CORE_ADDR address, struct value *val) | |
4e8f195d TT |
2870 | { |
2871 | int i, count = 0; | |
2872 | ||
f168693b SM |
2873 | base = check_typedef (base); |
2874 | dclass = check_typedef (dclass); | |
4e8f195d TT |
2875 | |
2876 | for (i = 0; i < TYPE_N_BASECLASSES (dclass) && count < 2; ++i) | |
2877 | { | |
8af8e3bc PA |
2878 | struct type *iter; |
2879 | int this_offset; | |
4e8f195d | 2880 | |
8af8e3bc PA |
2881 | iter = check_typedef (TYPE_BASECLASS (dclass, i)); |
2882 | ||
2883 | this_offset = baseclass_offset (dclass, i, valaddr, embedded_offset, | |
2884 | address, val); | |
4e8f195d TT |
2885 | |
2886 | if (class_types_same_p (base, iter)) | |
2887 | { | |
2888 | /* If this is the first subclass, set *OFFSET and set count | |
2889 | to 1. Otherwise, if this is at the same offset as | |
2890 | previous instances, do nothing. Otherwise, increment | |
2891 | count. */ | |
2892 | if (*offset == -1) | |
2893 | { | |
2894 | *offset = this_offset; | |
2895 | count = 1; | |
2896 | } | |
2897 | else if (this_offset == *offset) | |
2898 | { | |
2899 | /* Nothing. */ | |
2900 | } | |
2901 | else | |
2902 | ++count; | |
2903 | } | |
2904 | else | |
2905 | count += is_unique_ancestor_worker (base, iter, offset, | |
8af8e3bc PA |
2906 | valaddr, |
2907 | embedded_offset + this_offset, | |
2908 | address, val); | |
4e8f195d TT |
2909 | } |
2910 | ||
2911 | return count; | |
2912 | } | |
2913 | ||
2914 | /* Like is_ancestor, but only returns true if BASE is a unique base | |
2915 | class of the type of VAL. */ | |
2916 | ||
2917 | int | |
2918 | is_unique_ancestor (struct type *base, struct value *val) | |
2919 | { | |
2920 | int offset = -1; | |
2921 | ||
2922 | return is_unique_ancestor_worker (base, value_type (val), &offset, | |
8af8e3bc PA |
2923 | value_contents_for_printing (val), |
2924 | value_embedded_offset (val), | |
2925 | value_address (val), val) == 1; | |
4e8f195d TT |
2926 | } |
2927 | ||
c906108c | 2928 | \f |
5212577a | 2929 | /* Overload resolution. */ |
c906108c | 2930 | |
6403aeea SW |
2931 | /* Return the sum of the rank of A with the rank of B. */ |
2932 | ||
2933 | struct rank | |
2934 | sum_ranks (struct rank a, struct rank b) | |
2935 | { | |
2936 | struct rank c; | |
2937 | c.rank = a.rank + b.rank; | |
a9d5ef47 | 2938 | c.subrank = a.subrank + b.subrank; |
6403aeea SW |
2939 | return c; |
2940 | } | |
2941 | ||
2942 | /* Compare rank A and B and return: | |
2943 | 0 if a = b | |
2944 | 1 if a is better than b | |
2945 | -1 if b is better than a. */ | |
2946 | ||
2947 | int | |
2948 | compare_ranks (struct rank a, struct rank b) | |
2949 | { | |
2950 | if (a.rank == b.rank) | |
a9d5ef47 SW |
2951 | { |
2952 | if (a.subrank == b.subrank) | |
2953 | return 0; | |
2954 | if (a.subrank < b.subrank) | |
2955 | return 1; | |
2956 | if (a.subrank > b.subrank) | |
2957 | return -1; | |
2958 | } | |
6403aeea SW |
2959 | |
2960 | if (a.rank < b.rank) | |
2961 | return 1; | |
2962 | ||
0963b4bd | 2963 | /* a.rank > b.rank */ |
6403aeea SW |
2964 | return -1; |
2965 | } | |
c5aa993b | 2966 | |
0963b4bd | 2967 | /* Functions for overload resolution begin here. */ |
c906108c SS |
2968 | |
2969 | /* Compare two badness vectors A and B and return the result. | |
7ba81444 MS |
2970 | 0 => A and B are identical |
2971 | 1 => A and B are incomparable | |
2972 | 2 => A is better than B | |
2973 | 3 => A is worse than B */ | |
c906108c SS |
2974 | |
2975 | int | |
fba45db2 | 2976 | compare_badness (struct badness_vector *a, struct badness_vector *b) |
c906108c SS |
2977 | { |
2978 | int i; | |
2979 | int tmp; | |
c5aa993b JM |
2980 | short found_pos = 0; /* any positives in c? */ |
2981 | short found_neg = 0; /* any negatives in c? */ | |
2982 | ||
2983 | /* differing lengths => incomparable */ | |
c906108c SS |
2984 | if (a->length != b->length) |
2985 | return 1; | |
2986 | ||
c5aa993b JM |
2987 | /* Subtract b from a */ |
2988 | for (i = 0; i < a->length; i++) | |
c906108c | 2989 | { |
6403aeea | 2990 | tmp = compare_ranks (b->rank[i], a->rank[i]); |
c906108c | 2991 | if (tmp > 0) |
c5aa993b | 2992 | found_pos = 1; |
c906108c | 2993 | else if (tmp < 0) |
c5aa993b | 2994 | found_neg = 1; |
c906108c SS |
2995 | } |
2996 | ||
2997 | if (found_pos) | |
2998 | { | |
2999 | if (found_neg) | |
c5aa993b | 3000 | return 1; /* incomparable */ |
c906108c | 3001 | else |
c5aa993b | 3002 | return 3; /* A > B */ |
c906108c | 3003 | } |
c5aa993b JM |
3004 | else |
3005 | /* no positives */ | |
c906108c SS |
3006 | { |
3007 | if (found_neg) | |
c5aa993b | 3008 | return 2; /* A < B */ |
c906108c | 3009 | else |
c5aa993b | 3010 | return 0; /* A == B */ |
c906108c SS |
3011 | } |
3012 | } | |
3013 | ||
7ba81444 MS |
3014 | /* Rank a function by comparing its parameter types (PARMS, length |
3015 | NPARMS), to the types of an argument list (ARGS, length NARGS). | |
3016 | Return a pointer to a badness vector. This has NARGS + 1 | |
3017 | entries. */ | |
c906108c SS |
3018 | |
3019 | struct badness_vector * | |
7ba81444 | 3020 | rank_function (struct type **parms, int nparms, |
da096638 | 3021 | struct value **args, int nargs) |
c906108c SS |
3022 | { |
3023 | int i; | |
c5aa993b | 3024 | struct badness_vector *bv; |
c906108c SS |
3025 | int min_len = nparms < nargs ? nparms : nargs; |
3026 | ||
3027 | bv = xmalloc (sizeof (struct badness_vector)); | |
0963b4bd | 3028 | bv->length = nargs + 1; /* add 1 for the length-match rank. */ |
c4e54771 | 3029 | bv->rank = XNEWVEC (struct rank, nargs + 1); |
c906108c SS |
3030 | |
3031 | /* First compare the lengths of the supplied lists. | |
7ba81444 | 3032 | If there is a mismatch, set it to a high value. */ |
c5aa993b | 3033 | |
c906108c | 3034 | /* pai/1997-06-03 FIXME: when we have debug info about default |
7ba81444 MS |
3035 | arguments and ellipsis parameter lists, we should consider those |
3036 | and rank the length-match more finely. */ | |
c906108c | 3037 | |
6403aeea SW |
3038 | LENGTH_MATCH (bv) = (nargs != nparms) |
3039 | ? LENGTH_MISMATCH_BADNESS | |
3040 | : EXACT_MATCH_BADNESS; | |
c906108c | 3041 | |
0963b4bd | 3042 | /* Now rank all the parameters of the candidate function. */ |
74cc24b0 | 3043 | for (i = 1; i <= min_len; i++) |
da096638 KS |
3044 | bv->rank[i] = rank_one_type (parms[i - 1], value_type (args[i - 1]), |
3045 | args[i - 1]); | |
c906108c | 3046 | |
0963b4bd | 3047 | /* If more arguments than parameters, add dummy entries. */ |
c5aa993b | 3048 | for (i = min_len + 1; i <= nargs; i++) |
c906108c SS |
3049 | bv->rank[i] = TOO_FEW_PARAMS_BADNESS; |
3050 | ||
3051 | return bv; | |
3052 | } | |
3053 | ||
973ccf8b DJ |
3054 | /* Compare the names of two integer types, assuming that any sign |
3055 | qualifiers have been checked already. We do it this way because | |
3056 | there may be an "int" in the name of one of the types. */ | |
3057 | ||
3058 | static int | |
3059 | integer_types_same_name_p (const char *first, const char *second) | |
3060 | { | |
3061 | int first_p, second_p; | |
3062 | ||
7ba81444 MS |
3063 | /* If both are shorts, return 1; if neither is a short, keep |
3064 | checking. */ | |
973ccf8b DJ |
3065 | first_p = (strstr (first, "short") != NULL); |
3066 | second_p = (strstr (second, "short") != NULL); | |
3067 | if (first_p && second_p) | |
3068 | return 1; | |
3069 | if (first_p || second_p) | |
3070 | return 0; | |
3071 | ||
3072 | /* Likewise for long. */ | |
3073 | first_p = (strstr (first, "long") != NULL); | |
3074 | second_p = (strstr (second, "long") != NULL); | |
3075 | if (first_p && second_p) | |
3076 | return 1; | |
3077 | if (first_p || second_p) | |
3078 | return 0; | |
3079 | ||
3080 | /* Likewise for char. */ | |
3081 | first_p = (strstr (first, "char") != NULL); | |
3082 | second_p = (strstr (second, "char") != NULL); | |
3083 | if (first_p && second_p) | |
3084 | return 1; | |
3085 | if (first_p || second_p) | |
3086 | return 0; | |
3087 | ||
3088 | /* They must both be ints. */ | |
3089 | return 1; | |
3090 | } | |
3091 | ||
7062b0a0 SW |
3092 | /* Compares type A to type B returns 1 if the represent the same type |
3093 | 0 otherwise. */ | |
3094 | ||
bd69fc68 | 3095 | int |
7062b0a0 SW |
3096 | types_equal (struct type *a, struct type *b) |
3097 | { | |
3098 | /* Identical type pointers. */ | |
3099 | /* However, this still doesn't catch all cases of same type for b | |
3100 | and a. The reason is that builtin types are different from | |
3101 | the same ones constructed from the object. */ | |
3102 | if (a == b) | |
3103 | return 1; | |
3104 | ||
3105 | /* Resolve typedefs */ | |
3106 | if (TYPE_CODE (a) == TYPE_CODE_TYPEDEF) | |
3107 | a = check_typedef (a); | |
3108 | if (TYPE_CODE (b) == TYPE_CODE_TYPEDEF) | |
3109 | b = check_typedef (b); | |
3110 | ||
3111 | /* If after resolving typedefs a and b are not of the same type | |
3112 | code then they are not equal. */ | |
3113 | if (TYPE_CODE (a) != TYPE_CODE (b)) | |
3114 | return 0; | |
3115 | ||
3116 | /* If a and b are both pointers types or both reference types then | |
3117 | they are equal of the same type iff the objects they refer to are | |
3118 | of the same type. */ | |
3119 | if (TYPE_CODE (a) == TYPE_CODE_PTR | |
3120 | || TYPE_CODE (a) == TYPE_CODE_REF) | |
3121 | return types_equal (TYPE_TARGET_TYPE (a), | |
3122 | TYPE_TARGET_TYPE (b)); | |
3123 | ||
0963b4bd | 3124 | /* Well, damnit, if the names are exactly the same, I'll say they |
7062b0a0 SW |
3125 | are exactly the same. This happens when we generate method |
3126 | stubs. The types won't point to the same address, but they | |
0963b4bd | 3127 | really are the same. */ |
7062b0a0 SW |
3128 | |
3129 | if (TYPE_NAME (a) && TYPE_NAME (b) | |
3130 | && strcmp (TYPE_NAME (a), TYPE_NAME (b)) == 0) | |
3131 | return 1; | |
3132 | ||
3133 | /* Check if identical after resolving typedefs. */ | |
3134 | if (a == b) | |
3135 | return 1; | |
3136 | ||
9ce98649 TT |
3137 | /* Two function types are equal if their argument and return types |
3138 | are equal. */ | |
3139 | if (TYPE_CODE (a) == TYPE_CODE_FUNC) | |
3140 | { | |
3141 | int i; | |
3142 | ||
3143 | if (TYPE_NFIELDS (a) != TYPE_NFIELDS (b)) | |
3144 | return 0; | |
3145 | ||
3146 | if (!types_equal (TYPE_TARGET_TYPE (a), TYPE_TARGET_TYPE (b))) | |
3147 | return 0; | |
3148 | ||
3149 | for (i = 0; i < TYPE_NFIELDS (a); ++i) | |
3150 | if (!types_equal (TYPE_FIELD_TYPE (a, i), TYPE_FIELD_TYPE (b, i))) | |
3151 | return 0; | |
3152 | ||
3153 | return 1; | |
3154 | } | |
3155 | ||
7062b0a0 SW |
3156 | return 0; |
3157 | } | |
ca092b61 DE |
3158 | \f |
3159 | /* Deep comparison of types. */ | |
3160 | ||
3161 | /* An entry in the type-equality bcache. */ | |
3162 | ||
3163 | typedef struct type_equality_entry | |
3164 | { | |
3165 | struct type *type1, *type2; | |
3166 | } type_equality_entry_d; | |
3167 | ||
3168 | DEF_VEC_O (type_equality_entry_d); | |
3169 | ||
3170 | /* A helper function to compare two strings. Returns 1 if they are | |
3171 | the same, 0 otherwise. Handles NULLs properly. */ | |
3172 | ||
3173 | static int | |
3174 | compare_maybe_null_strings (const char *s, const char *t) | |
3175 | { | |
3176 | if (s == NULL && t != NULL) | |
3177 | return 0; | |
3178 | else if (s != NULL && t == NULL) | |
3179 | return 0; | |
3180 | else if (s == NULL && t== NULL) | |
3181 | return 1; | |
3182 | return strcmp (s, t) == 0; | |
3183 | } | |
3184 | ||
3185 | /* A helper function for check_types_worklist that checks two types for | |
3186 | "deep" equality. Returns non-zero if the types are considered the | |
3187 | same, zero otherwise. */ | |
3188 | ||
3189 | static int | |
3190 | check_types_equal (struct type *type1, struct type *type2, | |
3191 | VEC (type_equality_entry_d) **worklist) | |
3192 | { | |
f168693b SM |
3193 | type1 = check_typedef (type1); |
3194 | type2 = check_typedef (type2); | |
ca092b61 DE |
3195 | |
3196 | if (type1 == type2) | |
3197 | return 1; | |
3198 | ||
3199 | if (TYPE_CODE (type1) != TYPE_CODE (type2) | |
3200 | || TYPE_LENGTH (type1) != TYPE_LENGTH (type2) | |
3201 | || TYPE_UNSIGNED (type1) != TYPE_UNSIGNED (type2) | |
3202 | || TYPE_NOSIGN (type1) != TYPE_NOSIGN (type2) | |
3203 | || TYPE_VARARGS (type1) != TYPE_VARARGS (type2) | |
3204 | || TYPE_VECTOR (type1) != TYPE_VECTOR (type2) | |
3205 | || TYPE_NOTTEXT (type1) != TYPE_NOTTEXT (type2) | |
3206 | || TYPE_INSTANCE_FLAGS (type1) != TYPE_INSTANCE_FLAGS (type2) | |
3207 | || TYPE_NFIELDS (type1) != TYPE_NFIELDS (type2)) | |
3208 | return 0; | |
3209 | ||
3210 | if (!compare_maybe_null_strings (TYPE_TAG_NAME (type1), | |
3211 | TYPE_TAG_NAME (type2))) | |
3212 | return 0; | |
3213 | if (!compare_maybe_null_strings (TYPE_NAME (type1), TYPE_NAME (type2))) | |
3214 | return 0; | |
3215 | ||
3216 | if (TYPE_CODE (type1) == TYPE_CODE_RANGE) | |
3217 | { | |
3218 | if (memcmp (TYPE_RANGE_DATA (type1), TYPE_RANGE_DATA (type2), | |
3219 | sizeof (*TYPE_RANGE_DATA (type1))) != 0) | |
3220 | return 0; | |
3221 | } | |
3222 | else | |
3223 | { | |
3224 | int i; | |
3225 | ||
3226 | for (i = 0; i < TYPE_NFIELDS (type1); ++i) | |
3227 | { | |
3228 | const struct field *field1 = &TYPE_FIELD (type1, i); | |
3229 | const struct field *field2 = &TYPE_FIELD (type2, i); | |
3230 | struct type_equality_entry entry; | |
3231 | ||
3232 | if (FIELD_ARTIFICIAL (*field1) != FIELD_ARTIFICIAL (*field2) | |
3233 | || FIELD_BITSIZE (*field1) != FIELD_BITSIZE (*field2) | |
3234 | || FIELD_LOC_KIND (*field1) != FIELD_LOC_KIND (*field2)) | |
3235 | return 0; | |
3236 | if (!compare_maybe_null_strings (FIELD_NAME (*field1), | |
3237 | FIELD_NAME (*field2))) | |
3238 | return 0; | |
3239 | switch (FIELD_LOC_KIND (*field1)) | |
3240 | { | |
3241 | case FIELD_LOC_KIND_BITPOS: | |
3242 | if (FIELD_BITPOS (*field1) != FIELD_BITPOS (*field2)) | |
3243 | return 0; | |
3244 | break; | |
3245 | case FIELD_LOC_KIND_ENUMVAL: | |
3246 | if (FIELD_ENUMVAL (*field1) != FIELD_ENUMVAL (*field2)) | |
3247 | return 0; | |
3248 | break; | |
3249 | case FIELD_LOC_KIND_PHYSADDR: | |
3250 | if (FIELD_STATIC_PHYSADDR (*field1) | |
3251 | != FIELD_STATIC_PHYSADDR (*field2)) | |
3252 | return 0; | |
3253 | break; | |
3254 | case FIELD_LOC_KIND_PHYSNAME: | |
3255 | if (!compare_maybe_null_strings (FIELD_STATIC_PHYSNAME (*field1), | |
3256 | FIELD_STATIC_PHYSNAME (*field2))) | |
3257 | return 0; | |
3258 | break; | |
3259 | case FIELD_LOC_KIND_DWARF_BLOCK: | |
3260 | { | |
3261 | struct dwarf2_locexpr_baton *block1, *block2; | |
3262 | ||
3263 | block1 = FIELD_DWARF_BLOCK (*field1); | |
3264 | block2 = FIELD_DWARF_BLOCK (*field2); | |
3265 | if (block1->per_cu != block2->per_cu | |
3266 | || block1->size != block2->size | |
3267 | || memcmp (block1->data, block2->data, block1->size) != 0) | |
3268 | return 0; | |
3269 | } | |
3270 | break; | |
3271 | default: | |
3272 | internal_error (__FILE__, __LINE__, _("Unsupported field kind " | |
3273 | "%d by check_types_equal"), | |
3274 | FIELD_LOC_KIND (*field1)); | |
3275 | } | |
3276 | ||
3277 | entry.type1 = FIELD_TYPE (*field1); | |
3278 | entry.type2 = FIELD_TYPE (*field2); | |
3279 | VEC_safe_push (type_equality_entry_d, *worklist, &entry); | |
3280 | } | |
3281 | } | |
3282 | ||
3283 | if (TYPE_TARGET_TYPE (type1) != NULL) | |
3284 | { | |
3285 | struct type_equality_entry entry; | |
3286 | ||
3287 | if (TYPE_TARGET_TYPE (type2) == NULL) | |
3288 | return 0; | |
3289 | ||
3290 | entry.type1 = TYPE_TARGET_TYPE (type1); | |
3291 | entry.type2 = TYPE_TARGET_TYPE (type2); | |
3292 | VEC_safe_push (type_equality_entry_d, *worklist, &entry); | |
3293 | } | |
3294 | else if (TYPE_TARGET_TYPE (type2) != NULL) | |
3295 | return 0; | |
3296 | ||
3297 | return 1; | |
3298 | } | |
3299 | ||
3300 | /* Check types on a worklist for equality. Returns zero if any pair | |
3301 | is not equal, non-zero if they are all considered equal. */ | |
3302 | ||
3303 | static int | |
3304 | check_types_worklist (VEC (type_equality_entry_d) **worklist, | |
3305 | struct bcache *cache) | |
3306 | { | |
3307 | while (!VEC_empty (type_equality_entry_d, *worklist)) | |
3308 | { | |
3309 | struct type_equality_entry entry; | |
3310 | int added; | |
3311 | ||
3312 | entry = *VEC_last (type_equality_entry_d, *worklist); | |
3313 | VEC_pop (type_equality_entry_d, *worklist); | |
3314 | ||
3315 | /* If the type pair has already been visited, we know it is | |
3316 | ok. */ | |
3317 | bcache_full (&entry, sizeof (entry), cache, &added); | |
3318 | if (!added) | |
3319 | continue; | |
3320 | ||
3321 | if (check_types_equal (entry.type1, entry.type2, worklist) == 0) | |
3322 | return 0; | |
3323 | } | |
7062b0a0 | 3324 | |
ca092b61 DE |
3325 | return 1; |
3326 | } | |
3327 | ||
3328 | /* Return non-zero if types TYPE1 and TYPE2 are equal, as determined by a | |
3329 | "deep comparison". Otherwise return zero. */ | |
3330 | ||
3331 | int | |
3332 | types_deeply_equal (struct type *type1, struct type *type2) | |
3333 | { | |
6c63c96a | 3334 | struct gdb_exception except = exception_none; |
ca092b61 DE |
3335 | int result = 0; |
3336 | struct bcache *cache; | |
3337 | VEC (type_equality_entry_d) *worklist = NULL; | |
3338 | struct type_equality_entry entry; | |
3339 | ||
3340 | gdb_assert (type1 != NULL && type2 != NULL); | |
3341 | ||
3342 | /* Early exit for the simple case. */ | |
3343 | if (type1 == type2) | |
3344 | return 1; | |
3345 | ||
3346 | cache = bcache_xmalloc (NULL, NULL); | |
3347 | ||
3348 | entry.type1 = type1; | |
3349 | entry.type2 = type2; | |
3350 | VEC_safe_push (type_equality_entry_d, worklist, &entry); | |
3351 | ||
6c63c96a PA |
3352 | /* check_types_worklist calls several nested helper functions, some |
3353 | of which can raise a GDB exception, so we just check and rethrow | |
3354 | here. If there is a GDB exception, a comparison is not capable | |
3355 | (or trusted), so exit. */ | |
492d29ea | 3356 | TRY |
ca092b61 DE |
3357 | { |
3358 | result = check_types_worklist (&worklist, cache); | |
3359 | } | |
6c63c96a | 3360 | CATCH (ex, RETURN_MASK_ALL) |
492d29ea | 3361 | { |
6c63c96a | 3362 | except = ex; |
492d29ea PA |
3363 | } |
3364 | END_CATCH | |
ca092b61 | 3365 | |
6c63c96a PA |
3366 | bcache_xfree (cache); |
3367 | VEC_free (type_equality_entry_d, worklist); | |
3368 | ||
3369 | /* Rethrow if there was a problem. */ | |
3370 | if (except.reason < 0) | |
3371 | throw_exception (except); | |
3372 | ||
ca092b61 DE |
3373 | return result; |
3374 | } | |
3375 | \f | |
c906108c SS |
3376 | /* Compare one type (PARM) for compatibility with another (ARG). |
3377 | * PARM is intended to be the parameter type of a function; and | |
3378 | * ARG is the supplied argument's type. This function tests if | |
3379 | * the latter can be converted to the former. | |
da096638 | 3380 | * VALUE is the argument's value or NULL if none (or called recursively) |
c906108c SS |
3381 | * |
3382 | * Return 0 if they are identical types; | |
3383 | * Otherwise, return an integer which corresponds to how compatible | |
7ba81444 MS |
3384 | * PARM is to ARG. The higher the return value, the worse the match. |
3385 | * Generally the "bad" conversions are all uniformly assigned a 100. */ | |
c906108c | 3386 | |
6403aeea | 3387 | struct rank |
da096638 | 3388 | rank_one_type (struct type *parm, struct type *arg, struct value *value) |
c906108c | 3389 | { |
a9d5ef47 | 3390 | struct rank rank = {0,0}; |
7062b0a0 SW |
3391 | |
3392 | if (types_equal (parm, arg)) | |
6403aeea | 3393 | return EXACT_MATCH_BADNESS; |
c906108c SS |
3394 | |
3395 | /* Resolve typedefs */ | |
3396 | if (TYPE_CODE (parm) == TYPE_CODE_TYPEDEF) | |
3397 | parm = check_typedef (parm); | |
3398 | if (TYPE_CODE (arg) == TYPE_CODE_TYPEDEF) | |
3399 | arg = check_typedef (arg); | |
3400 | ||
db577aea | 3401 | /* See through references, since we can almost make non-references |
7ba81444 | 3402 | references. */ |
db577aea | 3403 | if (TYPE_CODE (arg) == TYPE_CODE_REF) |
da096638 | 3404 | return (sum_ranks (rank_one_type (parm, TYPE_TARGET_TYPE (arg), NULL), |
6403aeea | 3405 | REFERENCE_CONVERSION_BADNESS)); |
db577aea | 3406 | if (TYPE_CODE (parm) == TYPE_CODE_REF) |
da096638 | 3407 | return (sum_ranks (rank_one_type (TYPE_TARGET_TYPE (parm), arg, NULL), |
6403aeea | 3408 | REFERENCE_CONVERSION_BADNESS)); |
5d161b24 | 3409 | if (overload_debug) |
7ba81444 MS |
3410 | /* Debugging only. */ |
3411 | fprintf_filtered (gdb_stderr, | |
3412 | "------ Arg is %s [%d], parm is %s [%d]\n", | |
3413 | TYPE_NAME (arg), TYPE_CODE (arg), | |
3414 | TYPE_NAME (parm), TYPE_CODE (parm)); | |
c906108c | 3415 | |
0963b4bd | 3416 | /* x -> y means arg of type x being supplied for parameter of type y. */ |
c906108c SS |
3417 | |
3418 | switch (TYPE_CODE (parm)) | |
3419 | { | |
c5aa993b JM |
3420 | case TYPE_CODE_PTR: |
3421 | switch (TYPE_CODE (arg)) | |
3422 | { | |
3423 | case TYPE_CODE_PTR: | |
7062b0a0 SW |
3424 | |
3425 | /* Allowed pointer conversions are: | |
3426 | (a) pointer to void-pointer conversion. */ | |
3427 | if (TYPE_CODE (TYPE_TARGET_TYPE (parm)) == TYPE_CODE_VOID) | |
c5aa993b | 3428 | return VOID_PTR_CONVERSION_BADNESS; |
7062b0a0 SW |
3429 | |
3430 | /* (b) pointer to ancestor-pointer conversion. */ | |
a9d5ef47 SW |
3431 | rank.subrank = distance_to_ancestor (TYPE_TARGET_TYPE (parm), |
3432 | TYPE_TARGET_TYPE (arg), | |
3433 | 0); | |
3434 | if (rank.subrank >= 0) | |
3435 | return sum_ranks (BASE_PTR_CONVERSION_BADNESS, rank); | |
7062b0a0 SW |
3436 | |
3437 | return INCOMPATIBLE_TYPE_BADNESS; | |
c5aa993b | 3438 | case TYPE_CODE_ARRAY: |
7062b0a0 SW |
3439 | if (types_equal (TYPE_TARGET_TYPE (parm), |
3440 | TYPE_TARGET_TYPE (arg))) | |
6403aeea | 3441 | return EXACT_MATCH_BADNESS; |
7062b0a0 | 3442 | return INCOMPATIBLE_TYPE_BADNESS; |
c5aa993b | 3443 | case TYPE_CODE_FUNC: |
da096638 | 3444 | return rank_one_type (TYPE_TARGET_TYPE (parm), arg, NULL); |
c5aa993b | 3445 | case TYPE_CODE_INT: |
a451cb65 | 3446 | if (value != NULL && TYPE_CODE (value_type (value)) == TYPE_CODE_INT) |
da096638 | 3447 | { |
a451cb65 KS |
3448 | if (value_as_long (value) == 0) |
3449 | { | |
3450 | /* Null pointer conversion: allow it to be cast to a pointer. | |
3451 | [4.10.1 of C++ standard draft n3290] */ | |
3452 | return NULL_POINTER_CONVERSION_BADNESS; | |
3453 | } | |
3454 | else | |
3455 | { | |
3456 | /* If type checking is disabled, allow the conversion. */ | |
3457 | if (!strict_type_checking) | |
3458 | return NS_INTEGER_POINTER_CONVERSION_BADNESS; | |
3459 | } | |
da096638 KS |
3460 | } |
3461 | /* fall through */ | |
c5aa993b | 3462 | case TYPE_CODE_ENUM: |
4f2aea11 | 3463 | case TYPE_CODE_FLAGS: |
c5aa993b JM |
3464 | case TYPE_CODE_CHAR: |
3465 | case TYPE_CODE_RANGE: | |
3466 | case TYPE_CODE_BOOL: | |
c5aa993b JM |
3467 | default: |
3468 | return INCOMPATIBLE_TYPE_BADNESS; | |
3469 | } | |
3470 | case TYPE_CODE_ARRAY: | |
3471 | switch (TYPE_CODE (arg)) | |
3472 | { | |
3473 | case TYPE_CODE_PTR: | |
3474 | case TYPE_CODE_ARRAY: | |
7ba81444 | 3475 | return rank_one_type (TYPE_TARGET_TYPE (parm), |
da096638 | 3476 | TYPE_TARGET_TYPE (arg), NULL); |
c5aa993b JM |
3477 | default: |
3478 | return INCOMPATIBLE_TYPE_BADNESS; | |
3479 | } | |
3480 | case TYPE_CODE_FUNC: | |
3481 | switch (TYPE_CODE (arg)) | |
3482 | { | |
3483 | case TYPE_CODE_PTR: /* funcptr -> func */ | |
da096638 | 3484 | return rank_one_type (parm, TYPE_TARGET_TYPE (arg), NULL); |
c5aa993b JM |
3485 | default: |
3486 | return INCOMPATIBLE_TYPE_BADNESS; | |
3487 | } | |
3488 | case TYPE_CODE_INT: | |
3489 | switch (TYPE_CODE (arg)) | |
3490 | { | |
3491 | case TYPE_CODE_INT: | |
3492 | if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm)) | |
3493 | { | |
3494 | /* Deal with signed, unsigned, and plain chars and | |
7ba81444 | 3495 | signed and unsigned ints. */ |
c5aa993b JM |
3496 | if (TYPE_NOSIGN (parm)) |
3497 | { | |
0963b4bd | 3498 | /* This case only for character types. */ |
7ba81444 | 3499 | if (TYPE_NOSIGN (arg)) |
6403aeea | 3500 | return EXACT_MATCH_BADNESS; /* plain char -> plain char */ |
7ba81444 MS |
3501 | else /* signed/unsigned char -> plain char */ |
3502 | return INTEGER_CONVERSION_BADNESS; | |
c5aa993b JM |
3503 | } |
3504 | else if (TYPE_UNSIGNED (parm)) | |
3505 | { | |
3506 | if (TYPE_UNSIGNED (arg)) | |
3507 | { | |
7ba81444 MS |
3508 | /* unsigned int -> unsigned int, or |
3509 | unsigned long -> unsigned long */ | |
3510 | if (integer_types_same_name_p (TYPE_NAME (parm), | |
3511 | TYPE_NAME (arg))) | |
6403aeea | 3512 | return EXACT_MATCH_BADNESS; |
7ba81444 MS |
3513 | else if (integer_types_same_name_p (TYPE_NAME (arg), |
3514 | "int") | |
3515 | && integer_types_same_name_p (TYPE_NAME (parm), | |
3516 | "long")) | |
3e43a32a MS |
3517 | /* unsigned int -> unsigned long */ |
3518 | return INTEGER_PROMOTION_BADNESS; | |
c5aa993b | 3519 | else |
3e43a32a MS |
3520 | /* unsigned long -> unsigned int */ |
3521 | return INTEGER_CONVERSION_BADNESS; | |
c5aa993b JM |
3522 | } |
3523 | else | |
3524 | { | |
7ba81444 MS |
3525 | if (integer_types_same_name_p (TYPE_NAME (arg), |
3526 | "long") | |
3527 | && integer_types_same_name_p (TYPE_NAME (parm), | |
3528 | "int")) | |
3e43a32a MS |
3529 | /* signed long -> unsigned int */ |
3530 | return INTEGER_CONVERSION_BADNESS; | |
c5aa993b | 3531 | else |
3e43a32a MS |
3532 | /* signed int/long -> unsigned int/long */ |
3533 | return INTEGER_CONVERSION_BADNESS; | |
c5aa993b JM |
3534 | } |
3535 | } | |
3536 | else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg)) | |
3537 | { | |
7ba81444 MS |
3538 | if (integer_types_same_name_p (TYPE_NAME (parm), |
3539 | TYPE_NAME (arg))) | |
6403aeea | 3540 | return EXACT_MATCH_BADNESS; |
7ba81444 MS |
3541 | else if (integer_types_same_name_p (TYPE_NAME (arg), |
3542 | "int") | |
3543 | && integer_types_same_name_p (TYPE_NAME (parm), | |
3544 | "long")) | |
c5aa993b JM |
3545 | return INTEGER_PROMOTION_BADNESS; |
3546 | else | |
1c5cb38e | 3547 | return INTEGER_CONVERSION_BADNESS; |
c5aa993b JM |
3548 | } |
3549 | else | |
1c5cb38e | 3550 | return INTEGER_CONVERSION_BADNESS; |
c5aa993b JM |
3551 | } |
3552 | else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm)) | |
3553 | return INTEGER_PROMOTION_BADNESS; | |
3554 | else | |
1c5cb38e | 3555 | return INTEGER_CONVERSION_BADNESS; |
c5aa993b | 3556 | case TYPE_CODE_ENUM: |
4f2aea11 | 3557 | case TYPE_CODE_FLAGS: |
c5aa993b JM |
3558 | case TYPE_CODE_CHAR: |
3559 | case TYPE_CODE_RANGE: | |
3560 | case TYPE_CODE_BOOL: | |
3d567982 TT |
3561 | if (TYPE_DECLARED_CLASS (arg)) |
3562 | return INCOMPATIBLE_TYPE_BADNESS; | |
c5aa993b JM |
3563 | return INTEGER_PROMOTION_BADNESS; |
3564 | case TYPE_CODE_FLT: | |
3565 | return INT_FLOAT_CONVERSION_BADNESS; | |
3566 | case TYPE_CODE_PTR: | |
3567 | return NS_POINTER_CONVERSION_BADNESS; | |
3568 | default: | |
3569 | return INCOMPATIBLE_TYPE_BADNESS; | |
3570 | } | |
3571 | break; | |
3572 | case TYPE_CODE_ENUM: | |
3573 | switch (TYPE_CODE (arg)) | |
3574 | { | |
3575 | case TYPE_CODE_INT: | |
3576 | case TYPE_CODE_CHAR: | |
3577 | case TYPE_CODE_RANGE: | |
3578 | case TYPE_CODE_BOOL: | |
3579 | case TYPE_CODE_ENUM: | |
3d567982 TT |
3580 | if (TYPE_DECLARED_CLASS (parm) || TYPE_DECLARED_CLASS (arg)) |
3581 | return INCOMPATIBLE_TYPE_BADNESS; | |
1c5cb38e | 3582 | return INTEGER_CONVERSION_BADNESS; |
c5aa993b JM |
3583 | case TYPE_CODE_FLT: |
3584 | return INT_FLOAT_CONVERSION_BADNESS; | |
3585 | default: | |
3586 | return INCOMPATIBLE_TYPE_BADNESS; | |
3587 | } | |
3588 | break; | |
3589 | case TYPE_CODE_CHAR: | |
3590 | switch (TYPE_CODE (arg)) | |
3591 | { | |
3592 | case TYPE_CODE_RANGE: | |
3593 | case TYPE_CODE_BOOL: | |
3594 | case TYPE_CODE_ENUM: | |
3d567982 TT |
3595 | if (TYPE_DECLARED_CLASS (arg)) |
3596 | return INCOMPATIBLE_TYPE_BADNESS; | |
1c5cb38e | 3597 | return INTEGER_CONVERSION_BADNESS; |
c5aa993b JM |
3598 | case TYPE_CODE_FLT: |
3599 | return INT_FLOAT_CONVERSION_BADNESS; | |
3600 | case TYPE_CODE_INT: | |
3601 | if (TYPE_LENGTH (arg) > TYPE_LENGTH (parm)) | |
1c5cb38e | 3602 | return INTEGER_CONVERSION_BADNESS; |
c5aa993b JM |
3603 | else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm)) |
3604 | return INTEGER_PROMOTION_BADNESS; | |
3605 | /* >>> !! else fall through !! <<< */ | |
3606 | case TYPE_CODE_CHAR: | |
7ba81444 MS |
3607 | /* Deal with signed, unsigned, and plain chars for C++ and |
3608 | with int cases falling through from previous case. */ | |
c5aa993b JM |
3609 | if (TYPE_NOSIGN (parm)) |
3610 | { | |
3611 | if (TYPE_NOSIGN (arg)) | |
6403aeea | 3612 | return EXACT_MATCH_BADNESS; |
c5aa993b | 3613 | else |
1c5cb38e | 3614 | return INTEGER_CONVERSION_BADNESS; |
c5aa993b JM |
3615 | } |
3616 | else if (TYPE_UNSIGNED (parm)) | |
3617 | { | |
3618 | if (TYPE_UNSIGNED (arg)) | |
6403aeea | 3619 | return EXACT_MATCH_BADNESS; |
c5aa993b JM |
3620 | else |
3621 | return INTEGER_PROMOTION_BADNESS; | |
3622 | } | |
3623 | else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg)) | |
6403aeea | 3624 | return EXACT_MATCH_BADNESS; |
c5aa993b | 3625 | else |
1c5cb38e | 3626 | return INTEGER_CONVERSION_BADNESS; |
c5aa993b JM |
3627 | default: |
3628 | return INCOMPATIBLE_TYPE_BADNESS; | |
3629 | } | |
3630 | break; | |
3631 | case TYPE_CODE_RANGE: | |
3632 | switch (TYPE_CODE (arg)) | |
3633 | { | |
3634 | case TYPE_CODE_INT: | |
3635 | case TYPE_CODE_CHAR: | |
3636 | case TYPE_CODE_RANGE: | |
3637 | case TYPE_CODE_BOOL: | |
3638 | case TYPE_CODE_ENUM: | |
1c5cb38e | 3639 | return INTEGER_CONVERSION_BADNESS; |
c5aa993b JM |
3640 | case TYPE_CODE_FLT: |
3641 | return INT_FLOAT_CONVERSION_BADNESS; | |
3642 | default: | |
3643 | return INCOMPATIBLE_TYPE_BADNESS; | |
3644 | } | |
3645 | break; | |
3646 | case TYPE_CODE_BOOL: | |
3647 | switch (TYPE_CODE (arg)) | |
3648 | { | |
5b4f6e25 KS |
3649 | /* n3290 draft, section 4.12.1 (conv.bool): |
3650 | ||
3651 | "A prvalue of arithmetic, unscoped enumeration, pointer, or | |
3652 | pointer to member type can be converted to a prvalue of type | |
3653 | bool. A zero value, null pointer value, or null member pointer | |
3654 | value is converted to false; any other value is converted to | |
3655 | true. A prvalue of type std::nullptr_t can be converted to a | |
3656 | prvalue of type bool; the resulting value is false." */ | |
c5aa993b JM |
3657 | case TYPE_CODE_INT: |
3658 | case TYPE_CODE_CHAR: | |
c5aa993b JM |
3659 | case TYPE_CODE_ENUM: |
3660 | case TYPE_CODE_FLT: | |
5b4f6e25 | 3661 | case TYPE_CODE_MEMBERPTR: |
c5aa993b | 3662 | case TYPE_CODE_PTR: |
5b4f6e25 KS |
3663 | return BOOL_CONVERSION_BADNESS; |
3664 | case TYPE_CODE_RANGE: | |
3665 | return INCOMPATIBLE_TYPE_BADNESS; | |
c5aa993b | 3666 | case TYPE_CODE_BOOL: |
6403aeea | 3667 | return EXACT_MATCH_BADNESS; |
c5aa993b JM |
3668 | default: |
3669 | return INCOMPATIBLE_TYPE_BADNESS; | |
3670 | } | |
3671 | break; | |
3672 | case TYPE_CODE_FLT: | |
3673 | switch (TYPE_CODE (arg)) | |
3674 | { | |
3675 | case TYPE_CODE_FLT: | |
3676 | if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm)) | |
3677 | return FLOAT_PROMOTION_BADNESS; | |
3678 | else if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm)) | |
6403aeea | 3679 | return EXACT_MATCH_BADNESS; |
c5aa993b JM |
3680 | else |
3681 | return FLOAT_CONVERSION_BADNESS; | |
3682 | case TYPE_CODE_INT: | |
3683 | case TYPE_CODE_BOOL: | |
3684 | case TYPE_CODE_ENUM: | |
3685 | case TYPE_CODE_RANGE: | |
3686 | case TYPE_CODE_CHAR: | |
3687 | return INT_FLOAT_CONVERSION_BADNESS; | |
3688 | default: | |
3689 | return INCOMPATIBLE_TYPE_BADNESS; | |
3690 | } | |
3691 | break; | |
3692 | case TYPE_CODE_COMPLEX: | |
3693 | switch (TYPE_CODE (arg)) | |
7ba81444 | 3694 | { /* Strictly not needed for C++, but... */ |
c5aa993b JM |
3695 | case TYPE_CODE_FLT: |
3696 | return FLOAT_PROMOTION_BADNESS; | |
3697 | case TYPE_CODE_COMPLEX: | |
6403aeea | 3698 | return EXACT_MATCH_BADNESS; |
c5aa993b JM |
3699 | default: |
3700 | return INCOMPATIBLE_TYPE_BADNESS; | |
3701 | } | |
3702 | break; | |
3703 | case TYPE_CODE_STRUCT: | |
c5aa993b JM |
3704 | switch (TYPE_CODE (arg)) |
3705 | { | |
3706 | case TYPE_CODE_STRUCT: | |
3707 | /* Check for derivation */ | |
a9d5ef47 SW |
3708 | rank.subrank = distance_to_ancestor (parm, arg, 0); |
3709 | if (rank.subrank >= 0) | |
3710 | return sum_ranks (BASE_CONVERSION_BADNESS, rank); | |
c5aa993b JM |
3711 | /* else fall through */ |
3712 | default: | |
3713 | return INCOMPATIBLE_TYPE_BADNESS; | |
3714 | } | |
3715 | break; | |
3716 | case TYPE_CODE_UNION: | |
3717 | switch (TYPE_CODE (arg)) | |
3718 | { | |
3719 | case TYPE_CODE_UNION: | |
3720 | default: | |
3721 | return INCOMPATIBLE_TYPE_BADNESS; | |
3722 | } | |
3723 | break; | |
0d5de010 | 3724 | case TYPE_CODE_MEMBERPTR: |
c5aa993b JM |
3725 | switch (TYPE_CODE (arg)) |
3726 | { | |
3727 | default: | |
3728 | return INCOMPATIBLE_TYPE_BADNESS; | |
3729 | } | |
3730 | break; | |
3731 | case TYPE_CODE_METHOD: | |
3732 | switch (TYPE_CODE (arg)) | |
3733 | { | |
3734 | ||
3735 | default: | |
3736 | return INCOMPATIBLE_TYPE_BADNESS; | |
3737 | } | |
3738 | break; | |
3739 | case TYPE_CODE_REF: | |
3740 | switch (TYPE_CODE (arg)) | |
3741 | { | |
3742 | ||
3743 | default: | |
3744 | return INCOMPATIBLE_TYPE_BADNESS; | |
3745 | } | |
3746 | ||
3747 | break; | |
3748 | case TYPE_CODE_SET: | |
3749 | switch (TYPE_CODE (arg)) | |
3750 | { | |
3751 | /* Not in C++ */ | |
3752 | case TYPE_CODE_SET: | |
7ba81444 | 3753 | return rank_one_type (TYPE_FIELD_TYPE (parm, 0), |
da096638 | 3754 | TYPE_FIELD_TYPE (arg, 0), NULL); |
c5aa993b JM |
3755 | default: |
3756 | return INCOMPATIBLE_TYPE_BADNESS; | |
3757 | } | |
3758 | break; | |
3759 | case TYPE_CODE_VOID: | |
3760 | default: | |
3761 | return INCOMPATIBLE_TYPE_BADNESS; | |
3762 | } /* switch (TYPE_CODE (arg)) */ | |
c906108c SS |
3763 | } |
3764 | ||
0963b4bd | 3765 | /* End of functions for overload resolution. */ |
5212577a DE |
3766 | \f |
3767 | /* Routines to pretty-print types. */ | |
c906108c | 3768 | |
c906108c | 3769 | static void |
fba45db2 | 3770 | print_bit_vector (B_TYPE *bits, int nbits) |
c906108c SS |
3771 | { |
3772 | int bitno; | |
3773 | ||
3774 | for (bitno = 0; bitno < nbits; bitno++) | |
3775 | { | |
3776 | if ((bitno % 8) == 0) | |
3777 | { | |
3778 | puts_filtered (" "); | |
3779 | } | |
3780 | if (B_TST (bits, bitno)) | |
a3f17187 | 3781 | printf_filtered (("1")); |
c906108c | 3782 | else |
a3f17187 | 3783 | printf_filtered (("0")); |
c906108c SS |
3784 | } |
3785 | } | |
3786 | ||
ad2f7632 | 3787 | /* Note the first arg should be the "this" pointer, we may not want to |
7ba81444 MS |
3788 | include it since we may get into a infinitely recursive |
3789 | situation. */ | |
c906108c SS |
3790 | |
3791 | static void | |
4c9e8482 | 3792 | print_args (struct field *args, int nargs, int spaces) |
c906108c SS |
3793 | { |
3794 | if (args != NULL) | |
3795 | { | |
ad2f7632 DJ |
3796 | int i; |
3797 | ||
3798 | for (i = 0; i < nargs; i++) | |
4c9e8482 DE |
3799 | { |
3800 | printfi_filtered (spaces, "[%d] name '%s'\n", i, | |
3801 | args[i].name != NULL ? args[i].name : "<NULL>"); | |
3802 | recursive_dump_type (args[i].type, spaces + 2); | |
3803 | } | |
c906108c SS |
3804 | } |
3805 | } | |
3806 | ||
d6a843b5 JK |
3807 | int |
3808 | field_is_static (struct field *f) | |
3809 | { | |
3810 | /* "static" fields are the fields whose location is not relative | |
3811 | to the address of the enclosing struct. It would be nice to | |
3812 | have a dedicated flag that would be set for static fields when | |
3813 | the type is being created. But in practice, checking the field | |
254e6b9e | 3814 | loc_kind should give us an accurate answer. */ |
d6a843b5 JK |
3815 | return (FIELD_LOC_KIND (*f) == FIELD_LOC_KIND_PHYSNAME |
3816 | || FIELD_LOC_KIND (*f) == FIELD_LOC_KIND_PHYSADDR); | |
3817 | } | |
3818 | ||
c906108c | 3819 | static void |
fba45db2 | 3820 | dump_fn_fieldlists (struct type *type, int spaces) |
c906108c SS |
3821 | { |
3822 | int method_idx; | |
3823 | int overload_idx; | |
3824 | struct fn_field *f; | |
3825 | ||
3826 | printfi_filtered (spaces, "fn_fieldlists "); | |
d4f3574e | 3827 | gdb_print_host_address (TYPE_FN_FIELDLISTS (type), gdb_stdout); |
c906108c SS |
3828 | printf_filtered ("\n"); |
3829 | for (method_idx = 0; method_idx < TYPE_NFN_FIELDS (type); method_idx++) | |
3830 | { | |
3831 | f = TYPE_FN_FIELDLIST1 (type, method_idx); | |
3832 | printfi_filtered (spaces + 2, "[%d] name '%s' (", | |
3833 | method_idx, | |
3834 | TYPE_FN_FIELDLIST_NAME (type, method_idx)); | |
d4f3574e SS |
3835 | gdb_print_host_address (TYPE_FN_FIELDLIST_NAME (type, method_idx), |
3836 | gdb_stdout); | |
a3f17187 | 3837 | printf_filtered (_(") length %d\n"), |
c906108c SS |
3838 | TYPE_FN_FIELDLIST_LENGTH (type, method_idx)); |
3839 | for (overload_idx = 0; | |
3840 | overload_idx < TYPE_FN_FIELDLIST_LENGTH (type, method_idx); | |
3841 | overload_idx++) | |
3842 | { | |
3843 | printfi_filtered (spaces + 4, "[%d] physname '%s' (", | |
3844 | overload_idx, | |
3845 | TYPE_FN_FIELD_PHYSNAME (f, overload_idx)); | |
d4f3574e SS |
3846 | gdb_print_host_address (TYPE_FN_FIELD_PHYSNAME (f, overload_idx), |
3847 | gdb_stdout); | |
c906108c SS |
3848 | printf_filtered (")\n"); |
3849 | printfi_filtered (spaces + 8, "type "); | |
7ba81444 MS |
3850 | gdb_print_host_address (TYPE_FN_FIELD_TYPE (f, overload_idx), |
3851 | gdb_stdout); | |
c906108c SS |
3852 | printf_filtered ("\n"); |
3853 | ||
3854 | recursive_dump_type (TYPE_FN_FIELD_TYPE (f, overload_idx), | |
3855 | spaces + 8 + 2); | |
3856 | ||
3857 | printfi_filtered (spaces + 8, "args "); | |
7ba81444 MS |
3858 | gdb_print_host_address (TYPE_FN_FIELD_ARGS (f, overload_idx), |
3859 | gdb_stdout); | |
c906108c | 3860 | printf_filtered ("\n"); |
4c9e8482 DE |
3861 | print_args (TYPE_FN_FIELD_ARGS (f, overload_idx), |
3862 | TYPE_NFIELDS (TYPE_FN_FIELD_TYPE (f, overload_idx)), | |
3863 | spaces + 8 + 2); | |
c906108c | 3864 | printfi_filtered (spaces + 8, "fcontext "); |
d4f3574e SS |
3865 | gdb_print_host_address (TYPE_FN_FIELD_FCONTEXT (f, overload_idx), |
3866 | gdb_stdout); | |
c906108c SS |
3867 | printf_filtered ("\n"); |
3868 | ||
3869 | printfi_filtered (spaces + 8, "is_const %d\n", | |
3870 | TYPE_FN_FIELD_CONST (f, overload_idx)); | |
3871 | printfi_filtered (spaces + 8, "is_volatile %d\n", | |
3872 | TYPE_FN_FIELD_VOLATILE (f, overload_idx)); | |
3873 | printfi_filtered (spaces + 8, "is_private %d\n", | |
3874 | TYPE_FN_FIELD_PRIVATE (f, overload_idx)); | |
3875 | printfi_filtered (spaces + 8, "is_protected %d\n", | |
3876 | TYPE_FN_FIELD_PROTECTED (f, overload_idx)); | |
3877 | printfi_filtered (spaces + 8, "is_stub %d\n", | |
3878 | TYPE_FN_FIELD_STUB (f, overload_idx)); | |
3879 | printfi_filtered (spaces + 8, "voffset %u\n", | |
3880 | TYPE_FN_FIELD_VOFFSET (f, overload_idx)); | |
3881 | } | |
3882 | } | |
3883 | } | |
3884 | ||
3885 | static void | |
fba45db2 | 3886 | print_cplus_stuff (struct type *type, int spaces) |
c906108c | 3887 | { |
ae6ae975 DE |
3888 | printfi_filtered (spaces, "vptr_fieldno %d\n", TYPE_VPTR_FIELDNO (type)); |
3889 | printfi_filtered (spaces, "vptr_basetype "); | |
3890 | gdb_print_host_address (TYPE_VPTR_BASETYPE (type), gdb_stdout); | |
3891 | puts_filtered ("\n"); | |
3892 | if (TYPE_VPTR_BASETYPE (type) != NULL) | |
3893 | recursive_dump_type (TYPE_VPTR_BASETYPE (type), spaces + 2); | |
3894 | ||
c906108c SS |
3895 | printfi_filtered (spaces, "n_baseclasses %d\n", |
3896 | TYPE_N_BASECLASSES (type)); | |
3897 | printfi_filtered (spaces, "nfn_fields %d\n", | |
3898 | TYPE_NFN_FIELDS (type)); | |
c906108c SS |
3899 | if (TYPE_N_BASECLASSES (type) > 0) |
3900 | { | |
3901 | printfi_filtered (spaces, "virtual_field_bits (%d bits at *", | |
3902 | TYPE_N_BASECLASSES (type)); | |
7ba81444 MS |
3903 | gdb_print_host_address (TYPE_FIELD_VIRTUAL_BITS (type), |
3904 | gdb_stdout); | |
c906108c SS |
3905 | printf_filtered (")"); |
3906 | ||
3907 | print_bit_vector (TYPE_FIELD_VIRTUAL_BITS (type), | |
3908 | TYPE_N_BASECLASSES (type)); | |
3909 | puts_filtered ("\n"); | |
3910 | } | |
3911 | if (TYPE_NFIELDS (type) > 0) | |
3912 | { | |
3913 | if (TYPE_FIELD_PRIVATE_BITS (type) != NULL) | |
3914 | { | |
7ba81444 MS |
3915 | printfi_filtered (spaces, |
3916 | "private_field_bits (%d bits at *", | |
c906108c | 3917 | TYPE_NFIELDS (type)); |
7ba81444 MS |
3918 | gdb_print_host_address (TYPE_FIELD_PRIVATE_BITS (type), |
3919 | gdb_stdout); | |
c906108c SS |
3920 | printf_filtered (")"); |
3921 | print_bit_vector (TYPE_FIELD_PRIVATE_BITS (type), | |
3922 | TYPE_NFIELDS (type)); | |
3923 | puts_filtered ("\n"); | |
3924 | } | |
3925 | if (TYPE_FIELD_PROTECTED_BITS (type) != NULL) | |
3926 | { | |
7ba81444 MS |
3927 | printfi_filtered (spaces, |
3928 | "protected_field_bits (%d bits at *", | |
c906108c | 3929 | TYPE_NFIELDS (type)); |
7ba81444 MS |
3930 | gdb_print_host_address (TYPE_FIELD_PROTECTED_BITS (type), |
3931 | gdb_stdout); | |
c906108c SS |
3932 | printf_filtered (")"); |
3933 | print_bit_vector (TYPE_FIELD_PROTECTED_BITS (type), | |
3934 | TYPE_NFIELDS (type)); | |
3935 | puts_filtered ("\n"); | |
3936 | } | |
3937 | } | |
3938 | if (TYPE_NFN_FIELDS (type) > 0) | |
3939 | { | |
3940 | dump_fn_fieldlists (type, spaces); | |
3941 | } | |
3942 | } | |
3943 | ||
b4ba55a1 JB |
3944 | /* Print the contents of the TYPE's type_specific union, assuming that |
3945 | its type-specific kind is TYPE_SPECIFIC_GNAT_STUFF. */ | |
3946 | ||
3947 | static void | |
3948 | print_gnat_stuff (struct type *type, int spaces) | |
3949 | { | |
3950 | struct type *descriptive_type = TYPE_DESCRIPTIVE_TYPE (type); | |
3951 | ||
8cd00c59 PMR |
3952 | if (descriptive_type == NULL) |
3953 | printfi_filtered (spaces + 2, "no descriptive type\n"); | |
3954 | else | |
3955 | { | |
3956 | printfi_filtered (spaces + 2, "descriptive type\n"); | |
3957 | recursive_dump_type (descriptive_type, spaces + 4); | |
3958 | } | |
b4ba55a1 JB |
3959 | } |
3960 | ||
c906108c SS |
3961 | static struct obstack dont_print_type_obstack; |
3962 | ||
3963 | void | |
fba45db2 | 3964 | recursive_dump_type (struct type *type, int spaces) |
c906108c SS |
3965 | { |
3966 | int idx; | |
3967 | ||
3968 | if (spaces == 0) | |
3969 | obstack_begin (&dont_print_type_obstack, 0); | |
3970 | ||
3971 | if (TYPE_NFIELDS (type) > 0 | |
b4ba55a1 | 3972 | || (HAVE_CPLUS_STRUCT (type) && TYPE_NFN_FIELDS (type) > 0)) |
c906108c SS |
3973 | { |
3974 | struct type **first_dont_print | |
7ba81444 | 3975 | = (struct type **) obstack_base (&dont_print_type_obstack); |
c906108c | 3976 | |
7ba81444 MS |
3977 | int i = (struct type **) |
3978 | obstack_next_free (&dont_print_type_obstack) - first_dont_print; | |
c906108c SS |
3979 | |
3980 | while (--i >= 0) | |
3981 | { | |
3982 | if (type == first_dont_print[i]) | |
3983 | { | |
3984 | printfi_filtered (spaces, "type node "); | |
d4f3574e | 3985 | gdb_print_host_address (type, gdb_stdout); |
a3f17187 | 3986 | printf_filtered (_(" <same as already seen type>\n")); |
c906108c SS |
3987 | return; |
3988 | } | |
3989 | } | |
3990 | ||
3991 | obstack_ptr_grow (&dont_print_type_obstack, type); | |
3992 | } | |
3993 | ||
3994 | printfi_filtered (spaces, "type node "); | |
d4f3574e | 3995 | gdb_print_host_address (type, gdb_stdout); |
c906108c SS |
3996 | printf_filtered ("\n"); |
3997 | printfi_filtered (spaces, "name '%s' (", | |
3998 | TYPE_NAME (type) ? TYPE_NAME (type) : "<NULL>"); | |
d4f3574e | 3999 | gdb_print_host_address (TYPE_NAME (type), gdb_stdout); |
c906108c | 4000 | printf_filtered (")\n"); |
e9e79dd9 FF |
4001 | printfi_filtered (spaces, "tagname '%s' (", |
4002 | TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : "<NULL>"); | |
4003 | gdb_print_host_address (TYPE_TAG_NAME (type), gdb_stdout); | |
4004 | printf_filtered (")\n"); | |
c906108c SS |
4005 | printfi_filtered (spaces, "code 0x%x ", TYPE_CODE (type)); |
4006 | switch (TYPE_CODE (type)) | |
4007 | { | |
c5aa993b JM |
4008 | case TYPE_CODE_UNDEF: |
4009 | printf_filtered ("(TYPE_CODE_UNDEF)"); | |
4010 | break; | |
4011 | case TYPE_CODE_PTR: | |
4012 | printf_filtered ("(TYPE_CODE_PTR)"); | |
4013 | break; | |
4014 | case TYPE_CODE_ARRAY: | |
4015 | printf_filtered ("(TYPE_CODE_ARRAY)"); | |
4016 | break; | |
4017 | case TYPE_CODE_STRUCT: | |
4018 | printf_filtered ("(TYPE_CODE_STRUCT)"); | |
4019 | break; | |
4020 | case TYPE_CODE_UNION: | |
4021 | printf_filtered ("(TYPE_CODE_UNION)"); | |
4022 | break; | |
4023 | case TYPE_CODE_ENUM: | |
4024 | printf_filtered ("(TYPE_CODE_ENUM)"); | |
4025 | break; | |
4f2aea11 MK |
4026 | case TYPE_CODE_FLAGS: |
4027 | printf_filtered ("(TYPE_CODE_FLAGS)"); | |
4028 | break; | |
c5aa993b JM |
4029 | case TYPE_CODE_FUNC: |
4030 | printf_filtered ("(TYPE_CODE_FUNC)"); | |
4031 | break; | |
4032 | case TYPE_CODE_INT: | |
4033 | printf_filtered ("(TYPE_CODE_INT)"); | |
4034 | break; | |
4035 | case TYPE_CODE_FLT: | |
4036 | printf_filtered ("(TYPE_CODE_FLT)"); | |
4037 | break; | |
4038 | case TYPE_CODE_VOID: | |
4039 | printf_filtered ("(TYPE_CODE_VOID)"); | |
4040 | break; | |
4041 | case TYPE_CODE_SET: | |
4042 | printf_filtered ("(TYPE_CODE_SET)"); | |
4043 | break; | |
4044 | case TYPE_CODE_RANGE: | |
4045 | printf_filtered ("(TYPE_CODE_RANGE)"); | |
4046 | break; | |
4047 | case TYPE_CODE_STRING: | |
4048 | printf_filtered ("(TYPE_CODE_STRING)"); | |
4049 | break; | |
4050 | case TYPE_CODE_ERROR: | |
4051 | printf_filtered ("(TYPE_CODE_ERROR)"); | |
4052 | break; | |
0d5de010 DJ |
4053 | case TYPE_CODE_MEMBERPTR: |
4054 | printf_filtered ("(TYPE_CODE_MEMBERPTR)"); | |
4055 | break; | |
4056 | case TYPE_CODE_METHODPTR: | |
4057 | printf_filtered ("(TYPE_CODE_METHODPTR)"); | |
c5aa993b JM |
4058 | break; |
4059 | case TYPE_CODE_METHOD: | |
4060 | printf_filtered ("(TYPE_CODE_METHOD)"); | |
4061 | break; | |
4062 | case TYPE_CODE_REF: | |
4063 | printf_filtered ("(TYPE_CODE_REF)"); | |
4064 | break; | |
4065 | case TYPE_CODE_CHAR: | |
4066 | printf_filtered ("(TYPE_CODE_CHAR)"); | |
4067 | break; | |
4068 | case TYPE_CODE_BOOL: | |
4069 | printf_filtered ("(TYPE_CODE_BOOL)"); | |
4070 | break; | |
e9e79dd9 FF |
4071 | case TYPE_CODE_COMPLEX: |
4072 | printf_filtered ("(TYPE_CODE_COMPLEX)"); | |
4073 | break; | |
c5aa993b JM |
4074 | case TYPE_CODE_TYPEDEF: |
4075 | printf_filtered ("(TYPE_CODE_TYPEDEF)"); | |
4076 | break; | |
5c4e30ca DC |
4077 | case TYPE_CODE_NAMESPACE: |
4078 | printf_filtered ("(TYPE_CODE_NAMESPACE)"); | |
4079 | break; | |
c5aa993b JM |
4080 | default: |
4081 | printf_filtered ("(UNKNOWN TYPE CODE)"); | |
4082 | break; | |
c906108c SS |
4083 | } |
4084 | puts_filtered ("\n"); | |
4085 | printfi_filtered (spaces, "length %d\n", TYPE_LENGTH (type)); | |
e9bb382b UW |
4086 | if (TYPE_OBJFILE_OWNED (type)) |
4087 | { | |
4088 | printfi_filtered (spaces, "objfile "); | |
4089 | gdb_print_host_address (TYPE_OWNER (type).objfile, gdb_stdout); | |
4090 | } | |
4091 | else | |
4092 | { | |
4093 | printfi_filtered (spaces, "gdbarch "); | |
4094 | gdb_print_host_address (TYPE_OWNER (type).gdbarch, gdb_stdout); | |
4095 | } | |
c906108c SS |
4096 | printf_filtered ("\n"); |
4097 | printfi_filtered (spaces, "target_type "); | |
d4f3574e | 4098 | gdb_print_host_address (TYPE_TARGET_TYPE (type), gdb_stdout); |
c906108c SS |
4099 | printf_filtered ("\n"); |
4100 | if (TYPE_TARGET_TYPE (type) != NULL) | |
4101 | { | |
4102 | recursive_dump_type (TYPE_TARGET_TYPE (type), spaces + 2); | |
4103 | } | |
4104 | printfi_filtered (spaces, "pointer_type "); | |
d4f3574e | 4105 | gdb_print_host_address (TYPE_POINTER_TYPE (type), gdb_stdout); |
c906108c SS |
4106 | printf_filtered ("\n"); |
4107 | printfi_filtered (spaces, "reference_type "); | |
d4f3574e | 4108 | gdb_print_host_address (TYPE_REFERENCE_TYPE (type), gdb_stdout); |
c906108c | 4109 | printf_filtered ("\n"); |
2fdde8f8 DJ |
4110 | printfi_filtered (spaces, "type_chain "); |
4111 | gdb_print_host_address (TYPE_CHAIN (type), gdb_stdout); | |
e9e79dd9 | 4112 | printf_filtered ("\n"); |
7ba81444 MS |
4113 | printfi_filtered (spaces, "instance_flags 0x%x", |
4114 | TYPE_INSTANCE_FLAGS (type)); | |
2fdde8f8 DJ |
4115 | if (TYPE_CONST (type)) |
4116 | { | |
4117 | puts_filtered (" TYPE_FLAG_CONST"); | |
4118 | } | |
4119 | if (TYPE_VOLATILE (type)) | |
4120 | { | |
4121 | puts_filtered (" TYPE_FLAG_VOLATILE"); | |
4122 | } | |
4123 | if (TYPE_CODE_SPACE (type)) | |
4124 | { | |
4125 | puts_filtered (" TYPE_FLAG_CODE_SPACE"); | |
4126 | } | |
4127 | if (TYPE_DATA_SPACE (type)) | |
4128 | { | |
4129 | puts_filtered (" TYPE_FLAG_DATA_SPACE"); | |
4130 | } | |
8b2dbe47 KB |
4131 | if (TYPE_ADDRESS_CLASS_1 (type)) |
4132 | { | |
4133 | puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_1"); | |
4134 | } | |
4135 | if (TYPE_ADDRESS_CLASS_2 (type)) | |
4136 | { | |
4137 | puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_2"); | |
4138 | } | |
06d66ee9 TT |
4139 | if (TYPE_RESTRICT (type)) |
4140 | { | |
4141 | puts_filtered (" TYPE_FLAG_RESTRICT"); | |
4142 | } | |
a2c2acaf MW |
4143 | if (TYPE_ATOMIC (type)) |
4144 | { | |
4145 | puts_filtered (" TYPE_FLAG_ATOMIC"); | |
4146 | } | |
2fdde8f8 | 4147 | puts_filtered ("\n"); |
876cecd0 TT |
4148 | |
4149 | printfi_filtered (spaces, "flags"); | |
762a036f | 4150 | if (TYPE_UNSIGNED (type)) |
c906108c SS |
4151 | { |
4152 | puts_filtered (" TYPE_FLAG_UNSIGNED"); | |
4153 | } | |
762a036f FF |
4154 | if (TYPE_NOSIGN (type)) |
4155 | { | |
4156 | puts_filtered (" TYPE_FLAG_NOSIGN"); | |
4157 | } | |
4158 | if (TYPE_STUB (type)) | |
c906108c SS |
4159 | { |
4160 | puts_filtered (" TYPE_FLAG_STUB"); | |
4161 | } | |
762a036f FF |
4162 | if (TYPE_TARGET_STUB (type)) |
4163 | { | |
4164 | puts_filtered (" TYPE_FLAG_TARGET_STUB"); | |
4165 | } | |
4166 | if (TYPE_STATIC (type)) | |
4167 | { | |
4168 | puts_filtered (" TYPE_FLAG_STATIC"); | |
4169 | } | |
762a036f FF |
4170 | if (TYPE_PROTOTYPED (type)) |
4171 | { | |
4172 | puts_filtered (" TYPE_FLAG_PROTOTYPED"); | |
4173 | } | |
4174 | if (TYPE_INCOMPLETE (type)) | |
4175 | { | |
4176 | puts_filtered (" TYPE_FLAG_INCOMPLETE"); | |
4177 | } | |
762a036f FF |
4178 | if (TYPE_VARARGS (type)) |
4179 | { | |
4180 | puts_filtered (" TYPE_FLAG_VARARGS"); | |
4181 | } | |
f5f8a009 EZ |
4182 | /* This is used for things like AltiVec registers on ppc. Gcc emits |
4183 | an attribute for the array type, which tells whether or not we | |
4184 | have a vector, instead of a regular array. */ | |
4185 | if (TYPE_VECTOR (type)) | |
4186 | { | |
4187 | puts_filtered (" TYPE_FLAG_VECTOR"); | |
4188 | } | |
876cecd0 TT |
4189 | if (TYPE_FIXED_INSTANCE (type)) |
4190 | { | |
4191 | puts_filtered (" TYPE_FIXED_INSTANCE"); | |
4192 | } | |
4193 | if (TYPE_STUB_SUPPORTED (type)) | |
4194 | { | |
4195 | puts_filtered (" TYPE_STUB_SUPPORTED"); | |
4196 | } | |
4197 | if (TYPE_NOTTEXT (type)) | |
4198 | { | |
4199 | puts_filtered (" TYPE_NOTTEXT"); | |
4200 | } | |
c906108c SS |
4201 | puts_filtered ("\n"); |
4202 | printfi_filtered (spaces, "nfields %d ", TYPE_NFIELDS (type)); | |
d4f3574e | 4203 | gdb_print_host_address (TYPE_FIELDS (type), gdb_stdout); |
c906108c SS |
4204 | puts_filtered ("\n"); |
4205 | for (idx = 0; idx < TYPE_NFIELDS (type); idx++) | |
4206 | { | |
14e75d8e JK |
4207 | if (TYPE_CODE (type) == TYPE_CODE_ENUM) |
4208 | printfi_filtered (spaces + 2, | |
4209 | "[%d] enumval %s type ", | |
4210 | idx, plongest (TYPE_FIELD_ENUMVAL (type, idx))); | |
4211 | else | |
4212 | printfi_filtered (spaces + 2, | |
4213 | "[%d] bitpos %d bitsize %d type ", | |
4214 | idx, TYPE_FIELD_BITPOS (type, idx), | |
4215 | TYPE_FIELD_BITSIZE (type, idx)); | |
d4f3574e | 4216 | gdb_print_host_address (TYPE_FIELD_TYPE (type, idx), gdb_stdout); |
c906108c SS |
4217 | printf_filtered (" name '%s' (", |
4218 | TYPE_FIELD_NAME (type, idx) != NULL | |
4219 | ? TYPE_FIELD_NAME (type, idx) | |
4220 | : "<NULL>"); | |
d4f3574e | 4221 | gdb_print_host_address (TYPE_FIELD_NAME (type, idx), gdb_stdout); |
c906108c SS |
4222 | printf_filtered (")\n"); |
4223 | if (TYPE_FIELD_TYPE (type, idx) != NULL) | |
4224 | { | |
4225 | recursive_dump_type (TYPE_FIELD_TYPE (type, idx), spaces + 4); | |
4226 | } | |
4227 | } | |
43bbcdc2 PH |
4228 | if (TYPE_CODE (type) == TYPE_CODE_RANGE) |
4229 | { | |
4230 | printfi_filtered (spaces, "low %s%s high %s%s\n", | |
4231 | plongest (TYPE_LOW_BOUND (type)), | |
4232 | TYPE_LOW_BOUND_UNDEFINED (type) ? " (undefined)" : "", | |
4233 | plongest (TYPE_HIGH_BOUND (type)), | |
3e43a32a MS |
4234 | TYPE_HIGH_BOUND_UNDEFINED (type) |
4235 | ? " (undefined)" : ""); | |
43bbcdc2 | 4236 | } |
c906108c | 4237 | |
b4ba55a1 JB |
4238 | switch (TYPE_SPECIFIC_FIELD (type)) |
4239 | { | |
4240 | case TYPE_SPECIFIC_CPLUS_STUFF: | |
4241 | printfi_filtered (spaces, "cplus_stuff "); | |
4242 | gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type), | |
4243 | gdb_stdout); | |
4244 | puts_filtered ("\n"); | |
4245 | print_cplus_stuff (type, spaces); | |
4246 | break; | |
8da61cc4 | 4247 | |
b4ba55a1 JB |
4248 | case TYPE_SPECIFIC_GNAT_STUFF: |
4249 | printfi_filtered (spaces, "gnat_stuff "); | |
4250 | gdb_print_host_address (TYPE_GNAT_SPECIFIC (type), gdb_stdout); | |
4251 | puts_filtered ("\n"); | |
4252 | print_gnat_stuff (type, spaces); | |
4253 | break; | |
701c159d | 4254 | |
b4ba55a1 JB |
4255 | case TYPE_SPECIFIC_FLOATFORMAT: |
4256 | printfi_filtered (spaces, "floatformat "); | |
4257 | if (TYPE_FLOATFORMAT (type) == NULL) | |
4258 | puts_filtered ("(null)"); | |
4259 | else | |
4260 | { | |
4261 | puts_filtered ("{ "); | |
4262 | if (TYPE_FLOATFORMAT (type)[0] == NULL | |
4263 | || TYPE_FLOATFORMAT (type)[0]->name == NULL) | |
4264 | puts_filtered ("(null)"); | |
4265 | else | |
4266 | puts_filtered (TYPE_FLOATFORMAT (type)[0]->name); | |
4267 | ||
4268 | puts_filtered (", "); | |
4269 | if (TYPE_FLOATFORMAT (type)[1] == NULL | |
4270 | || TYPE_FLOATFORMAT (type)[1]->name == NULL) | |
4271 | puts_filtered ("(null)"); | |
4272 | else | |
4273 | puts_filtered (TYPE_FLOATFORMAT (type)[1]->name); | |
4274 | ||
4275 | puts_filtered (" }"); | |
4276 | } | |
4277 | puts_filtered ("\n"); | |
4278 | break; | |
c906108c | 4279 | |
b6cdc2c1 | 4280 | case TYPE_SPECIFIC_FUNC: |
b4ba55a1 JB |
4281 | printfi_filtered (spaces, "calling_convention %d\n", |
4282 | TYPE_CALLING_CONVENTION (type)); | |
b6cdc2c1 | 4283 | /* tail_call_list is not printed. */ |
b4ba55a1 | 4284 | break; |
09e2d7c7 DE |
4285 | |
4286 | case TYPE_SPECIFIC_SELF_TYPE: | |
4287 | printfi_filtered (spaces, "self_type "); | |
4288 | gdb_print_host_address (TYPE_SELF_TYPE (type), gdb_stdout); | |
4289 | puts_filtered ("\n"); | |
4290 | break; | |
c906108c | 4291 | } |
b4ba55a1 | 4292 | |
c906108c SS |
4293 | if (spaces == 0) |
4294 | obstack_free (&dont_print_type_obstack, NULL); | |
4295 | } | |
5212577a | 4296 | \f |
ae5a43e0 DJ |
4297 | /* Trivial helpers for the libiberty hash table, for mapping one |
4298 | type to another. */ | |
4299 | ||
4300 | struct type_pair | |
4301 | { | |
fe978cb0 | 4302 | struct type *old, *newobj; |
ae5a43e0 DJ |
4303 | }; |
4304 | ||
4305 | static hashval_t | |
4306 | type_pair_hash (const void *item) | |
4307 | { | |
4308 | const struct type_pair *pair = item; | |
d8734c88 | 4309 | |
ae5a43e0 DJ |
4310 | return htab_hash_pointer (pair->old); |
4311 | } | |
4312 | ||
4313 | static int | |
4314 | type_pair_eq (const void *item_lhs, const void *item_rhs) | |
4315 | { | |
4316 | const struct type_pair *lhs = item_lhs, *rhs = item_rhs; | |
d8734c88 | 4317 | |
ae5a43e0 DJ |
4318 | return lhs->old == rhs->old; |
4319 | } | |
4320 | ||
4321 | /* Allocate the hash table used by copy_type_recursive to walk | |
4322 | types without duplicates. We use OBJFILE's obstack, because | |
4323 | OBJFILE is about to be deleted. */ | |
4324 | ||
4325 | htab_t | |
4326 | create_copied_types_hash (struct objfile *objfile) | |
4327 | { | |
4328 | return htab_create_alloc_ex (1, type_pair_hash, type_pair_eq, | |
4329 | NULL, &objfile->objfile_obstack, | |
4330 | hashtab_obstack_allocate, | |
4331 | dummy_obstack_deallocate); | |
4332 | } | |
4333 | ||
d9823cbb KB |
4334 | /* Recursively copy (deep copy) a dynamic attribute list of a type. */ |
4335 | ||
4336 | static struct dynamic_prop_list * | |
4337 | copy_dynamic_prop_list (struct obstack *objfile_obstack, | |
4338 | struct dynamic_prop_list *list) | |
4339 | { | |
4340 | struct dynamic_prop_list *copy = list; | |
4341 | struct dynamic_prop_list **node_ptr = © | |
4342 | ||
4343 | while (*node_ptr != NULL) | |
4344 | { | |
4345 | struct dynamic_prop_list *node_copy; | |
4346 | ||
4347 | node_copy = obstack_copy (objfile_obstack, *node_ptr, | |
4348 | sizeof (struct dynamic_prop_list)); | |
283a9958 | 4349 | node_copy->prop = (*node_ptr)->prop; |
d9823cbb KB |
4350 | *node_ptr = node_copy; |
4351 | ||
4352 | node_ptr = &node_copy->next; | |
4353 | } | |
4354 | ||
4355 | return copy; | |
4356 | } | |
4357 | ||
7ba81444 MS |
4358 | /* Recursively copy (deep copy) TYPE, if it is associated with |
4359 | OBJFILE. Return a new type allocated using malloc, a saved type if | |
4360 | we have already visited TYPE (using COPIED_TYPES), or TYPE if it is | |
4361 | not associated with OBJFILE. */ | |
ae5a43e0 DJ |
4362 | |
4363 | struct type * | |
7ba81444 MS |
4364 | copy_type_recursive (struct objfile *objfile, |
4365 | struct type *type, | |
ae5a43e0 DJ |
4366 | htab_t copied_types) |
4367 | { | |
4368 | struct type_pair *stored, pair; | |
4369 | void **slot; | |
4370 | struct type *new_type; | |
4371 | ||
e9bb382b | 4372 | if (! TYPE_OBJFILE_OWNED (type)) |
ae5a43e0 DJ |
4373 | return type; |
4374 | ||
7ba81444 MS |
4375 | /* This type shouldn't be pointing to any types in other objfiles; |
4376 | if it did, the type might disappear unexpectedly. */ | |
ae5a43e0 DJ |
4377 | gdb_assert (TYPE_OBJFILE (type) == objfile); |
4378 | ||
4379 | pair.old = type; | |
4380 | slot = htab_find_slot (copied_types, &pair, INSERT); | |
4381 | if (*slot != NULL) | |
fe978cb0 | 4382 | return ((struct type_pair *) *slot)->newobj; |
ae5a43e0 | 4383 | |
e9bb382b | 4384 | new_type = alloc_type_arch (get_type_arch (type)); |
ae5a43e0 DJ |
4385 | |
4386 | /* We must add the new type to the hash table immediately, in case | |
4387 | we encounter this type again during a recursive call below. */ | |
3e43a32a MS |
4388 | stored |
4389 | = obstack_alloc (&objfile->objfile_obstack, sizeof (struct type_pair)); | |
ae5a43e0 | 4390 | stored->old = type; |
fe978cb0 | 4391 | stored->newobj = new_type; |
ae5a43e0 DJ |
4392 | *slot = stored; |
4393 | ||
876cecd0 TT |
4394 | /* Copy the common fields of types. For the main type, we simply |
4395 | copy the entire thing and then update specific fields as needed. */ | |
4396 | *TYPE_MAIN_TYPE (new_type) = *TYPE_MAIN_TYPE (type); | |
e9bb382b UW |
4397 | TYPE_OBJFILE_OWNED (new_type) = 0; |
4398 | TYPE_OWNER (new_type).gdbarch = get_type_arch (type); | |
876cecd0 | 4399 | |
ae5a43e0 DJ |
4400 | if (TYPE_NAME (type)) |
4401 | TYPE_NAME (new_type) = xstrdup (TYPE_NAME (type)); | |
4402 | if (TYPE_TAG_NAME (type)) | |
4403 | TYPE_TAG_NAME (new_type) = xstrdup (TYPE_TAG_NAME (type)); | |
ae5a43e0 DJ |
4404 | |
4405 | TYPE_INSTANCE_FLAGS (new_type) = TYPE_INSTANCE_FLAGS (type); | |
4406 | TYPE_LENGTH (new_type) = TYPE_LENGTH (type); | |
4407 | ||
4408 | /* Copy the fields. */ | |
ae5a43e0 DJ |
4409 | if (TYPE_NFIELDS (type)) |
4410 | { | |
4411 | int i, nfields; | |
4412 | ||
4413 | nfields = TYPE_NFIELDS (type); | |
fc270c35 | 4414 | TYPE_FIELDS (new_type) = XCNEWVEC (struct field, nfields); |
ae5a43e0 DJ |
4415 | for (i = 0; i < nfields; i++) |
4416 | { | |
7ba81444 MS |
4417 | TYPE_FIELD_ARTIFICIAL (new_type, i) = |
4418 | TYPE_FIELD_ARTIFICIAL (type, i); | |
ae5a43e0 DJ |
4419 | TYPE_FIELD_BITSIZE (new_type, i) = TYPE_FIELD_BITSIZE (type, i); |
4420 | if (TYPE_FIELD_TYPE (type, i)) | |
4421 | TYPE_FIELD_TYPE (new_type, i) | |
4422 | = copy_type_recursive (objfile, TYPE_FIELD_TYPE (type, i), | |
4423 | copied_types); | |
4424 | if (TYPE_FIELD_NAME (type, i)) | |
7ba81444 MS |
4425 | TYPE_FIELD_NAME (new_type, i) = |
4426 | xstrdup (TYPE_FIELD_NAME (type, i)); | |
d6a843b5 | 4427 | switch (TYPE_FIELD_LOC_KIND (type, i)) |
ae5a43e0 | 4428 | { |
d6a843b5 JK |
4429 | case FIELD_LOC_KIND_BITPOS: |
4430 | SET_FIELD_BITPOS (TYPE_FIELD (new_type, i), | |
4431 | TYPE_FIELD_BITPOS (type, i)); | |
4432 | break; | |
14e75d8e JK |
4433 | case FIELD_LOC_KIND_ENUMVAL: |
4434 | SET_FIELD_ENUMVAL (TYPE_FIELD (new_type, i), | |
4435 | TYPE_FIELD_ENUMVAL (type, i)); | |
4436 | break; | |
d6a843b5 JK |
4437 | case FIELD_LOC_KIND_PHYSADDR: |
4438 | SET_FIELD_PHYSADDR (TYPE_FIELD (new_type, i), | |
4439 | TYPE_FIELD_STATIC_PHYSADDR (type, i)); | |
4440 | break; | |
4441 | case FIELD_LOC_KIND_PHYSNAME: | |
4442 | SET_FIELD_PHYSNAME (TYPE_FIELD (new_type, i), | |
4443 | xstrdup (TYPE_FIELD_STATIC_PHYSNAME (type, | |
4444 | i))); | |
4445 | break; | |
4446 | default: | |
4447 | internal_error (__FILE__, __LINE__, | |
4448 | _("Unexpected type field location kind: %d"), | |
4449 | TYPE_FIELD_LOC_KIND (type, i)); | |
ae5a43e0 DJ |
4450 | } |
4451 | } | |
4452 | } | |
4453 | ||
0963b4bd | 4454 | /* For range types, copy the bounds information. */ |
43bbcdc2 PH |
4455 | if (TYPE_CODE (type) == TYPE_CODE_RANGE) |
4456 | { | |
4457 | TYPE_RANGE_DATA (new_type) = xmalloc (sizeof (struct range_bounds)); | |
4458 | *TYPE_RANGE_DATA (new_type) = *TYPE_RANGE_DATA (type); | |
4459 | } | |
4460 | ||
d9823cbb KB |
4461 | if (TYPE_DYN_PROP_LIST (type) != NULL) |
4462 | TYPE_DYN_PROP_LIST (new_type) | |
4463 | = copy_dynamic_prop_list (&objfile->objfile_obstack, | |
4464 | TYPE_DYN_PROP_LIST (type)); | |
4465 | ||
3cdcd0ce | 4466 | |
ae5a43e0 DJ |
4467 | /* Copy pointers to other types. */ |
4468 | if (TYPE_TARGET_TYPE (type)) | |
7ba81444 MS |
4469 | TYPE_TARGET_TYPE (new_type) = |
4470 | copy_type_recursive (objfile, | |
4471 | TYPE_TARGET_TYPE (type), | |
4472 | copied_types); | |
f6b3afbf | 4473 | |
ae5a43e0 DJ |
4474 | /* Maybe copy the type_specific bits. |
4475 | ||
4476 | NOTE drow/2005-12-09: We do not copy the C++-specific bits like | |
4477 | base classes and methods. There's no fundamental reason why we | |
4478 | can't, but at the moment it is not needed. */ | |
4479 | ||
f6b3afbf DE |
4480 | switch (TYPE_SPECIFIC_FIELD (type)) |
4481 | { | |
4482 | case TYPE_SPECIFIC_NONE: | |
4483 | break; | |
4484 | case TYPE_SPECIFIC_FUNC: | |
4485 | INIT_FUNC_SPECIFIC (new_type); | |
4486 | TYPE_CALLING_CONVENTION (new_type) = TYPE_CALLING_CONVENTION (type); | |
4487 | TYPE_NO_RETURN (new_type) = TYPE_NO_RETURN (type); | |
4488 | TYPE_TAIL_CALL_LIST (new_type) = NULL; | |
4489 | break; | |
4490 | case TYPE_SPECIFIC_FLOATFORMAT: | |
4491 | TYPE_FLOATFORMAT (new_type) = TYPE_FLOATFORMAT (type); | |
4492 | break; | |
4493 | case TYPE_SPECIFIC_CPLUS_STUFF: | |
4494 | INIT_CPLUS_SPECIFIC (new_type); | |
4495 | break; | |
4496 | case TYPE_SPECIFIC_GNAT_STUFF: | |
4497 | INIT_GNAT_SPECIFIC (new_type); | |
4498 | break; | |
09e2d7c7 DE |
4499 | case TYPE_SPECIFIC_SELF_TYPE: |
4500 | set_type_self_type (new_type, | |
4501 | copy_type_recursive (objfile, TYPE_SELF_TYPE (type), | |
4502 | copied_types)); | |
4503 | break; | |
f6b3afbf DE |
4504 | default: |
4505 | gdb_assert_not_reached ("bad type_specific_kind"); | |
4506 | } | |
ae5a43e0 DJ |
4507 | |
4508 | return new_type; | |
4509 | } | |
4510 | ||
4af88198 JB |
4511 | /* Make a copy of the given TYPE, except that the pointer & reference |
4512 | types are not preserved. | |
4513 | ||
4514 | This function assumes that the given type has an associated objfile. | |
4515 | This objfile is used to allocate the new type. */ | |
4516 | ||
4517 | struct type * | |
4518 | copy_type (const struct type *type) | |
4519 | { | |
4520 | struct type *new_type; | |
4521 | ||
e9bb382b | 4522 | gdb_assert (TYPE_OBJFILE_OWNED (type)); |
4af88198 | 4523 | |
e9bb382b | 4524 | new_type = alloc_type_copy (type); |
4af88198 JB |
4525 | TYPE_INSTANCE_FLAGS (new_type) = TYPE_INSTANCE_FLAGS (type); |
4526 | TYPE_LENGTH (new_type) = TYPE_LENGTH (type); | |
4527 | memcpy (TYPE_MAIN_TYPE (new_type), TYPE_MAIN_TYPE (type), | |
4528 | sizeof (struct main_type)); | |
d9823cbb KB |
4529 | if (TYPE_DYN_PROP_LIST (type) != NULL) |
4530 | TYPE_DYN_PROP_LIST (new_type) | |
4531 | = copy_dynamic_prop_list (&TYPE_OBJFILE (type) -> objfile_obstack, | |
4532 | TYPE_DYN_PROP_LIST (type)); | |
4af88198 JB |
4533 | |
4534 | return new_type; | |
4535 | } | |
5212577a | 4536 | \f |
e9bb382b UW |
4537 | /* Helper functions to initialize architecture-specific types. */ |
4538 | ||
4539 | /* Allocate a type structure associated with GDBARCH and set its | |
4540 | CODE, LENGTH, and NAME fields. */ | |
5212577a | 4541 | |
e9bb382b UW |
4542 | struct type * |
4543 | arch_type (struct gdbarch *gdbarch, | |
4544 | enum type_code code, int length, char *name) | |
4545 | { | |
4546 | struct type *type; | |
4547 | ||
4548 | type = alloc_type_arch (gdbarch); | |
4549 | TYPE_CODE (type) = code; | |
4550 | TYPE_LENGTH (type) = length; | |
4551 | ||
4552 | if (name) | |
4553 | TYPE_NAME (type) = xstrdup (name); | |
4554 | ||
4555 | return type; | |
4556 | } | |
4557 | ||
4558 | /* Allocate a TYPE_CODE_INT type structure associated with GDBARCH. | |
4559 | BIT is the type size in bits. If UNSIGNED_P is non-zero, set | |
4560 | the type's TYPE_UNSIGNED flag. NAME is the type name. */ | |
5212577a | 4561 | |
e9bb382b UW |
4562 | struct type * |
4563 | arch_integer_type (struct gdbarch *gdbarch, | |
4564 | int bit, int unsigned_p, char *name) | |
4565 | { | |
4566 | struct type *t; | |
4567 | ||
4568 | t = arch_type (gdbarch, TYPE_CODE_INT, bit / TARGET_CHAR_BIT, name); | |
4569 | if (unsigned_p) | |
4570 | TYPE_UNSIGNED (t) = 1; | |
4571 | if (name && strcmp (name, "char") == 0) | |
4572 | TYPE_NOSIGN (t) = 1; | |
4573 | ||
4574 | return t; | |
4575 | } | |
4576 | ||
4577 | /* Allocate a TYPE_CODE_CHAR type structure associated with GDBARCH. | |
4578 | BIT is the type size in bits. If UNSIGNED_P is non-zero, set | |
4579 | the type's TYPE_UNSIGNED flag. NAME is the type name. */ | |
5212577a | 4580 | |
e9bb382b UW |
4581 | struct type * |
4582 | arch_character_type (struct gdbarch *gdbarch, | |
4583 | int bit, int unsigned_p, char *name) | |
4584 | { | |
4585 | struct type *t; | |
4586 | ||
4587 | t = arch_type (gdbarch, TYPE_CODE_CHAR, bit / TARGET_CHAR_BIT, name); | |
4588 | if (unsigned_p) | |
4589 | TYPE_UNSIGNED (t) = 1; | |
4590 | ||
4591 | return t; | |
4592 | } | |
4593 | ||
4594 | /* Allocate a TYPE_CODE_BOOL type structure associated with GDBARCH. | |
4595 | BIT is the type size in bits. If UNSIGNED_P is non-zero, set | |
4596 | the type's TYPE_UNSIGNED flag. NAME is the type name. */ | |
5212577a | 4597 | |
e9bb382b UW |
4598 | struct type * |
4599 | arch_boolean_type (struct gdbarch *gdbarch, | |
4600 | int bit, int unsigned_p, char *name) | |
4601 | { | |
4602 | struct type *t; | |
4603 | ||
4604 | t = arch_type (gdbarch, TYPE_CODE_BOOL, bit / TARGET_CHAR_BIT, name); | |
4605 | if (unsigned_p) | |
4606 | TYPE_UNSIGNED (t) = 1; | |
4607 | ||
4608 | return t; | |
4609 | } | |
4610 | ||
4611 | /* Allocate a TYPE_CODE_FLT type structure associated with GDBARCH. | |
4612 | BIT is the type size in bits; if BIT equals -1, the size is | |
4613 | determined by the floatformat. NAME is the type name. Set the | |
4614 | TYPE_FLOATFORMAT from FLOATFORMATS. */ | |
5212577a | 4615 | |
27067745 | 4616 | struct type * |
e9bb382b UW |
4617 | arch_float_type (struct gdbarch *gdbarch, |
4618 | int bit, char *name, const struct floatformat **floatformats) | |
8da61cc4 DJ |
4619 | { |
4620 | struct type *t; | |
4621 | ||
4622 | if (bit == -1) | |
4623 | { | |
4624 | gdb_assert (floatformats != NULL); | |
4625 | gdb_assert (floatformats[0] != NULL && floatformats[1] != NULL); | |
4626 | bit = floatformats[0]->totalsize; | |
4627 | } | |
4628 | gdb_assert (bit >= 0); | |
4629 | ||
e9bb382b | 4630 | t = arch_type (gdbarch, TYPE_CODE_FLT, bit / TARGET_CHAR_BIT, name); |
8da61cc4 DJ |
4631 | TYPE_FLOATFORMAT (t) = floatformats; |
4632 | return t; | |
4633 | } | |
4634 | ||
e9bb382b UW |
4635 | /* Allocate a TYPE_CODE_COMPLEX type structure associated with GDBARCH. |
4636 | NAME is the type name. TARGET_TYPE is the component float type. */ | |
5212577a | 4637 | |
27067745 | 4638 | struct type * |
e9bb382b UW |
4639 | arch_complex_type (struct gdbarch *gdbarch, |
4640 | char *name, struct type *target_type) | |
27067745 UW |
4641 | { |
4642 | struct type *t; | |
d8734c88 | 4643 | |
e9bb382b UW |
4644 | t = arch_type (gdbarch, TYPE_CODE_COMPLEX, |
4645 | 2 * TYPE_LENGTH (target_type), name); | |
27067745 UW |
4646 | TYPE_TARGET_TYPE (t) = target_type; |
4647 | return t; | |
4648 | } | |
4649 | ||
e9bb382b | 4650 | /* Allocate a TYPE_CODE_FLAGS type structure associated with GDBARCH. |
eb90ce83 | 4651 | NAME is the type name. LENGTH is the size of the flag word in bytes. */ |
5212577a | 4652 | |
e9bb382b UW |
4653 | struct type * |
4654 | arch_flags_type (struct gdbarch *gdbarch, char *name, int length) | |
4655 | { | |
4656 | int nfields = length * TARGET_CHAR_BIT; | |
4657 | struct type *type; | |
4658 | ||
4659 | type = arch_type (gdbarch, TYPE_CODE_FLAGS, length, name); | |
4660 | TYPE_UNSIGNED (type) = 1; | |
4661 | TYPE_NFIELDS (type) = nfields; | |
4662 | TYPE_FIELDS (type) = TYPE_ZALLOC (type, nfields * sizeof (struct field)); | |
4663 | ||
4664 | return type; | |
4665 | } | |
4666 | ||
4667 | /* Add field to TYPE_CODE_FLAGS type TYPE to indicate the bit at | |
4668 | position BITPOS is called NAME. */ | |
5212577a | 4669 | |
e9bb382b UW |
4670 | void |
4671 | append_flags_type_flag (struct type *type, int bitpos, char *name) | |
4672 | { | |
4673 | gdb_assert (TYPE_CODE (type) == TYPE_CODE_FLAGS); | |
4674 | gdb_assert (bitpos < TYPE_NFIELDS (type)); | |
4675 | gdb_assert (bitpos >= 0); | |
4676 | ||
4677 | if (name) | |
4678 | { | |
4679 | TYPE_FIELD_NAME (type, bitpos) = xstrdup (name); | |
945b3a32 | 4680 | SET_FIELD_BITPOS (TYPE_FIELD (type, bitpos), bitpos); |
e9bb382b UW |
4681 | } |
4682 | else | |
4683 | { | |
4684 | /* Don't show this field to the user. */ | |
945b3a32 | 4685 | SET_FIELD_BITPOS (TYPE_FIELD (type, bitpos), -1); |
e9bb382b UW |
4686 | } |
4687 | } | |
4688 | ||
4689 | /* Allocate a TYPE_CODE_STRUCT or TYPE_CODE_UNION type structure (as | |
4690 | specified by CODE) associated with GDBARCH. NAME is the type name. */ | |
5212577a | 4691 | |
e9bb382b UW |
4692 | struct type * |
4693 | arch_composite_type (struct gdbarch *gdbarch, char *name, enum type_code code) | |
4694 | { | |
4695 | struct type *t; | |
d8734c88 | 4696 | |
e9bb382b UW |
4697 | gdb_assert (code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION); |
4698 | t = arch_type (gdbarch, code, 0, NULL); | |
4699 | TYPE_TAG_NAME (t) = name; | |
4700 | INIT_CPLUS_SPECIFIC (t); | |
4701 | return t; | |
4702 | } | |
4703 | ||
4704 | /* Add new field with name NAME and type FIELD to composite type T. | |
f5dff777 DJ |
4705 | Do not set the field's position or adjust the type's length; |
4706 | the caller should do so. Return the new field. */ | |
5212577a | 4707 | |
f5dff777 DJ |
4708 | struct field * |
4709 | append_composite_type_field_raw (struct type *t, char *name, | |
4710 | struct type *field) | |
e9bb382b UW |
4711 | { |
4712 | struct field *f; | |
d8734c88 | 4713 | |
e9bb382b UW |
4714 | TYPE_NFIELDS (t) = TYPE_NFIELDS (t) + 1; |
4715 | TYPE_FIELDS (t) = xrealloc (TYPE_FIELDS (t), | |
4716 | sizeof (struct field) * TYPE_NFIELDS (t)); | |
4717 | f = &(TYPE_FIELDS (t)[TYPE_NFIELDS (t) - 1]); | |
4718 | memset (f, 0, sizeof f[0]); | |
4719 | FIELD_TYPE (f[0]) = field; | |
4720 | FIELD_NAME (f[0]) = name; | |
f5dff777 DJ |
4721 | return f; |
4722 | } | |
4723 | ||
4724 | /* Add new field with name NAME and type FIELD to composite type T. | |
4725 | ALIGNMENT (if non-zero) specifies the minimum field alignment. */ | |
5212577a | 4726 | |
f5dff777 DJ |
4727 | void |
4728 | append_composite_type_field_aligned (struct type *t, char *name, | |
4729 | struct type *field, int alignment) | |
4730 | { | |
4731 | struct field *f = append_composite_type_field_raw (t, name, field); | |
d8734c88 | 4732 | |
e9bb382b UW |
4733 | if (TYPE_CODE (t) == TYPE_CODE_UNION) |
4734 | { | |
4735 | if (TYPE_LENGTH (t) < TYPE_LENGTH (field)) | |
4736 | TYPE_LENGTH (t) = TYPE_LENGTH (field); | |
4737 | } | |
4738 | else if (TYPE_CODE (t) == TYPE_CODE_STRUCT) | |
4739 | { | |
4740 | TYPE_LENGTH (t) = TYPE_LENGTH (t) + TYPE_LENGTH (field); | |
4741 | if (TYPE_NFIELDS (t) > 1) | |
4742 | { | |
f41f5e61 PA |
4743 | SET_FIELD_BITPOS (f[0], |
4744 | (FIELD_BITPOS (f[-1]) | |
4745 | + (TYPE_LENGTH (FIELD_TYPE (f[-1])) | |
4746 | * TARGET_CHAR_BIT))); | |
e9bb382b UW |
4747 | |
4748 | if (alignment) | |
4749 | { | |
86c3c1fc AB |
4750 | int left; |
4751 | ||
4752 | alignment *= TARGET_CHAR_BIT; | |
4753 | left = FIELD_BITPOS (f[0]) % alignment; | |
d8734c88 | 4754 | |
e9bb382b UW |
4755 | if (left) |
4756 | { | |
f41f5e61 | 4757 | SET_FIELD_BITPOS (f[0], FIELD_BITPOS (f[0]) + (alignment - left)); |
86c3c1fc | 4758 | TYPE_LENGTH (t) += (alignment - left) / TARGET_CHAR_BIT; |
e9bb382b UW |
4759 | } |
4760 | } | |
4761 | } | |
4762 | } | |
4763 | } | |
4764 | ||
4765 | /* Add new field with name NAME and type FIELD to composite type T. */ | |
5212577a | 4766 | |
e9bb382b UW |
4767 | void |
4768 | append_composite_type_field (struct type *t, char *name, | |
4769 | struct type *field) | |
4770 | { | |
4771 | append_composite_type_field_aligned (t, name, field, 0); | |
4772 | } | |
4773 | ||
000177f0 AC |
4774 | static struct gdbarch_data *gdbtypes_data; |
4775 | ||
4776 | const struct builtin_type * | |
4777 | builtin_type (struct gdbarch *gdbarch) | |
4778 | { | |
4779 | return gdbarch_data (gdbarch, gdbtypes_data); | |
4780 | } | |
4781 | ||
4782 | static void * | |
4783 | gdbtypes_post_init (struct gdbarch *gdbarch) | |
4784 | { | |
4785 | struct builtin_type *builtin_type | |
4786 | = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct builtin_type); | |
4787 | ||
46bf5051 | 4788 | /* Basic types. */ |
e9bb382b UW |
4789 | builtin_type->builtin_void |
4790 | = arch_type (gdbarch, TYPE_CODE_VOID, 1, "void"); | |
4791 | builtin_type->builtin_char | |
4792 | = arch_integer_type (gdbarch, TARGET_CHAR_BIT, | |
4793 | !gdbarch_char_signed (gdbarch), "char"); | |
4794 | builtin_type->builtin_signed_char | |
4795 | = arch_integer_type (gdbarch, TARGET_CHAR_BIT, | |
4796 | 0, "signed char"); | |
4797 | builtin_type->builtin_unsigned_char | |
4798 | = arch_integer_type (gdbarch, TARGET_CHAR_BIT, | |
4799 | 1, "unsigned char"); | |
4800 | builtin_type->builtin_short | |
4801 | = arch_integer_type (gdbarch, gdbarch_short_bit (gdbarch), | |
4802 | 0, "short"); | |
4803 | builtin_type->builtin_unsigned_short | |
4804 | = arch_integer_type (gdbarch, gdbarch_short_bit (gdbarch), | |
4805 | 1, "unsigned short"); | |
4806 | builtin_type->builtin_int | |
4807 | = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch), | |
4808 | 0, "int"); | |
4809 | builtin_type->builtin_unsigned_int | |
4810 | = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch), | |
4811 | 1, "unsigned int"); | |
4812 | builtin_type->builtin_long | |
4813 | = arch_integer_type (gdbarch, gdbarch_long_bit (gdbarch), | |
4814 | 0, "long"); | |
4815 | builtin_type->builtin_unsigned_long | |
4816 | = arch_integer_type (gdbarch, gdbarch_long_bit (gdbarch), | |
4817 | 1, "unsigned long"); | |
4818 | builtin_type->builtin_long_long | |
4819 | = arch_integer_type (gdbarch, gdbarch_long_long_bit (gdbarch), | |
4820 | 0, "long long"); | |
4821 | builtin_type->builtin_unsigned_long_long | |
4822 | = arch_integer_type (gdbarch, gdbarch_long_long_bit (gdbarch), | |
4823 | 1, "unsigned long long"); | |
70bd8e24 | 4824 | builtin_type->builtin_float |
e9bb382b | 4825 | = arch_float_type (gdbarch, gdbarch_float_bit (gdbarch), |
27067745 | 4826 | "float", gdbarch_float_format (gdbarch)); |
70bd8e24 | 4827 | builtin_type->builtin_double |
e9bb382b | 4828 | = arch_float_type (gdbarch, gdbarch_double_bit (gdbarch), |
27067745 | 4829 | "double", gdbarch_double_format (gdbarch)); |
70bd8e24 | 4830 | builtin_type->builtin_long_double |
e9bb382b | 4831 | = arch_float_type (gdbarch, gdbarch_long_double_bit (gdbarch), |
27067745 | 4832 | "long double", gdbarch_long_double_format (gdbarch)); |
70bd8e24 | 4833 | builtin_type->builtin_complex |
e9bb382b UW |
4834 | = arch_complex_type (gdbarch, "complex", |
4835 | builtin_type->builtin_float); | |
70bd8e24 | 4836 | builtin_type->builtin_double_complex |
e9bb382b UW |
4837 | = arch_complex_type (gdbarch, "double complex", |
4838 | builtin_type->builtin_double); | |
4839 | builtin_type->builtin_string | |
4840 | = arch_type (gdbarch, TYPE_CODE_STRING, 1, "string"); | |
4841 | builtin_type->builtin_bool | |
4842 | = arch_type (gdbarch, TYPE_CODE_BOOL, 1, "bool"); | |
000177f0 | 4843 | |
7678ef8f TJB |
4844 | /* The following three are about decimal floating point types, which |
4845 | are 32-bits, 64-bits and 128-bits respectively. */ | |
4846 | builtin_type->builtin_decfloat | |
e9bb382b | 4847 | = arch_type (gdbarch, TYPE_CODE_DECFLOAT, 32 / 8, "_Decimal32"); |
7678ef8f | 4848 | builtin_type->builtin_decdouble |
e9bb382b | 4849 | = arch_type (gdbarch, TYPE_CODE_DECFLOAT, 64 / 8, "_Decimal64"); |
7678ef8f | 4850 | builtin_type->builtin_declong |
e9bb382b | 4851 | = arch_type (gdbarch, TYPE_CODE_DECFLOAT, 128 / 8, "_Decimal128"); |
7678ef8f | 4852 | |
69feb676 | 4853 | /* "True" character types. */ |
e9bb382b UW |
4854 | builtin_type->builtin_true_char |
4855 | = arch_character_type (gdbarch, TARGET_CHAR_BIT, 0, "true character"); | |
4856 | builtin_type->builtin_true_unsigned_char | |
4857 | = arch_character_type (gdbarch, TARGET_CHAR_BIT, 1, "true character"); | |
69feb676 | 4858 | |
df4df182 | 4859 | /* Fixed-size integer types. */ |
e9bb382b UW |
4860 | builtin_type->builtin_int0 |
4861 | = arch_integer_type (gdbarch, 0, 0, "int0_t"); | |
4862 | builtin_type->builtin_int8 | |
4863 | = arch_integer_type (gdbarch, 8, 0, "int8_t"); | |
4864 | builtin_type->builtin_uint8 | |
4865 | = arch_integer_type (gdbarch, 8, 1, "uint8_t"); | |
4866 | builtin_type->builtin_int16 | |
4867 | = arch_integer_type (gdbarch, 16, 0, "int16_t"); | |
4868 | builtin_type->builtin_uint16 | |
4869 | = arch_integer_type (gdbarch, 16, 1, "uint16_t"); | |
4870 | builtin_type->builtin_int32 | |
4871 | = arch_integer_type (gdbarch, 32, 0, "int32_t"); | |
4872 | builtin_type->builtin_uint32 | |
4873 | = arch_integer_type (gdbarch, 32, 1, "uint32_t"); | |
4874 | builtin_type->builtin_int64 | |
4875 | = arch_integer_type (gdbarch, 64, 0, "int64_t"); | |
4876 | builtin_type->builtin_uint64 | |
4877 | = arch_integer_type (gdbarch, 64, 1, "uint64_t"); | |
4878 | builtin_type->builtin_int128 | |
4879 | = arch_integer_type (gdbarch, 128, 0, "int128_t"); | |
4880 | builtin_type->builtin_uint128 | |
4881 | = arch_integer_type (gdbarch, 128, 1, "uint128_t"); | |
2844d6b5 KW |
4882 | TYPE_INSTANCE_FLAGS (builtin_type->builtin_int8) |= |
4883 | TYPE_INSTANCE_FLAG_NOTTEXT; | |
4884 | TYPE_INSTANCE_FLAGS (builtin_type->builtin_uint8) |= | |
4885 | TYPE_INSTANCE_FLAG_NOTTEXT; | |
df4df182 | 4886 | |
9a22f0d0 PM |
4887 | /* Wide character types. */ |
4888 | builtin_type->builtin_char16 | |
4889 | = arch_integer_type (gdbarch, 16, 0, "char16_t"); | |
4890 | builtin_type->builtin_char32 | |
4891 | = arch_integer_type (gdbarch, 32, 0, "char32_t"); | |
4892 | ||
4893 | ||
46bf5051 | 4894 | /* Default data/code pointer types. */ |
e9bb382b UW |
4895 | builtin_type->builtin_data_ptr |
4896 | = lookup_pointer_type (builtin_type->builtin_void); | |
4897 | builtin_type->builtin_func_ptr | |
4898 | = lookup_pointer_type (lookup_function_type (builtin_type->builtin_void)); | |
0875794a JK |
4899 | builtin_type->builtin_func_func |
4900 | = lookup_function_type (builtin_type->builtin_func_ptr); | |
46bf5051 | 4901 | |
78267919 | 4902 | /* This type represents a GDB internal function. */ |
e9bb382b UW |
4903 | builtin_type->internal_fn |
4904 | = arch_type (gdbarch, TYPE_CODE_INTERNAL_FUNCTION, 0, | |
4905 | "<internal function>"); | |
78267919 | 4906 | |
e81e7f5e SC |
4907 | /* This type represents an xmethod. */ |
4908 | builtin_type->xmethod | |
4909 | = arch_type (gdbarch, TYPE_CODE_XMETHOD, 0, "<xmethod>"); | |
4910 | ||
46bf5051 UW |
4911 | return builtin_type; |
4912 | } | |
4913 | ||
46bf5051 UW |
4914 | /* This set of objfile-based types is intended to be used by symbol |
4915 | readers as basic types. */ | |
4916 | ||
4917 | static const struct objfile_data *objfile_type_data; | |
4918 | ||
4919 | const struct objfile_type * | |
4920 | objfile_type (struct objfile *objfile) | |
4921 | { | |
4922 | struct gdbarch *gdbarch; | |
4923 | struct objfile_type *objfile_type | |
4924 | = objfile_data (objfile, objfile_type_data); | |
4925 | ||
4926 | if (objfile_type) | |
4927 | return objfile_type; | |
4928 | ||
4929 | objfile_type = OBSTACK_CALLOC (&objfile->objfile_obstack, | |
4930 | 1, struct objfile_type); | |
4931 | ||
4932 | /* Use the objfile architecture to determine basic type properties. */ | |
4933 | gdbarch = get_objfile_arch (objfile); | |
4934 | ||
4935 | /* Basic types. */ | |
4936 | objfile_type->builtin_void | |
4937 | = init_type (TYPE_CODE_VOID, 1, | |
4938 | 0, | |
4939 | "void", objfile); | |
4940 | ||
4941 | objfile_type->builtin_char | |
4942 | = init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT, | |
4943 | (TYPE_FLAG_NOSIGN | |
4944 | | (gdbarch_char_signed (gdbarch) ? 0 : TYPE_FLAG_UNSIGNED)), | |
4945 | "char", objfile); | |
4946 | objfile_type->builtin_signed_char | |
4947 | = init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT, | |
4948 | 0, | |
4949 | "signed char", objfile); | |
4950 | objfile_type->builtin_unsigned_char | |
4951 | = init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT, | |
4952 | TYPE_FLAG_UNSIGNED, | |
4953 | "unsigned char", objfile); | |
4954 | objfile_type->builtin_short | |
4955 | = init_type (TYPE_CODE_INT, | |
4956 | gdbarch_short_bit (gdbarch) / TARGET_CHAR_BIT, | |
4957 | 0, "short", objfile); | |
4958 | objfile_type->builtin_unsigned_short | |
4959 | = init_type (TYPE_CODE_INT, | |
4960 | gdbarch_short_bit (gdbarch) / TARGET_CHAR_BIT, | |
4961 | TYPE_FLAG_UNSIGNED, "unsigned short", objfile); | |
4962 | objfile_type->builtin_int | |
4963 | = init_type (TYPE_CODE_INT, | |
4964 | gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT, | |
4965 | 0, "int", objfile); | |
4966 | objfile_type->builtin_unsigned_int | |
4967 | = init_type (TYPE_CODE_INT, | |
4968 | gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT, | |
4969 | TYPE_FLAG_UNSIGNED, "unsigned int", objfile); | |
4970 | objfile_type->builtin_long | |
4971 | = init_type (TYPE_CODE_INT, | |
4972 | gdbarch_long_bit (gdbarch) / TARGET_CHAR_BIT, | |
4973 | 0, "long", objfile); | |
4974 | objfile_type->builtin_unsigned_long | |
4975 | = init_type (TYPE_CODE_INT, | |
4976 | gdbarch_long_bit (gdbarch) / TARGET_CHAR_BIT, | |
4977 | TYPE_FLAG_UNSIGNED, "unsigned long", objfile); | |
4978 | objfile_type->builtin_long_long | |
4979 | = init_type (TYPE_CODE_INT, | |
4980 | gdbarch_long_long_bit (gdbarch) / TARGET_CHAR_BIT, | |
4981 | 0, "long long", objfile); | |
4982 | objfile_type->builtin_unsigned_long_long | |
4983 | = init_type (TYPE_CODE_INT, | |
4984 | gdbarch_long_long_bit (gdbarch) / TARGET_CHAR_BIT, | |
4985 | TYPE_FLAG_UNSIGNED, "unsigned long long", objfile); | |
4986 | ||
4987 | objfile_type->builtin_float | |
4988 | = init_type (TYPE_CODE_FLT, | |
4989 | gdbarch_float_bit (gdbarch) / TARGET_CHAR_BIT, | |
4990 | 0, "float", objfile); | |
4991 | TYPE_FLOATFORMAT (objfile_type->builtin_float) | |
4992 | = gdbarch_float_format (gdbarch); | |
4993 | objfile_type->builtin_double | |
4994 | = init_type (TYPE_CODE_FLT, | |
4995 | gdbarch_double_bit (gdbarch) / TARGET_CHAR_BIT, | |
4996 | 0, "double", objfile); | |
4997 | TYPE_FLOATFORMAT (objfile_type->builtin_double) | |
4998 | = gdbarch_double_format (gdbarch); | |
4999 | objfile_type->builtin_long_double | |
5000 | = init_type (TYPE_CODE_FLT, | |
5001 | gdbarch_long_double_bit (gdbarch) / TARGET_CHAR_BIT, | |
5002 | 0, "long double", objfile); | |
5003 | TYPE_FLOATFORMAT (objfile_type->builtin_long_double) | |
5004 | = gdbarch_long_double_format (gdbarch); | |
5005 | ||
5006 | /* This type represents a type that was unrecognized in symbol read-in. */ | |
5007 | objfile_type->builtin_error | |
5008 | = init_type (TYPE_CODE_ERROR, 0, 0, "<unknown type>", objfile); | |
5009 | ||
5010 | /* The following set of types is used for symbols with no | |
5011 | debug information. */ | |
5012 | objfile_type->nodebug_text_symbol | |
5013 | = init_type (TYPE_CODE_FUNC, 1, 0, | |
5014 | "<text variable, no debug info>", objfile); | |
5015 | TYPE_TARGET_TYPE (objfile_type->nodebug_text_symbol) | |
5016 | = objfile_type->builtin_int; | |
0875794a JK |
5017 | objfile_type->nodebug_text_gnu_ifunc_symbol |
5018 | = init_type (TYPE_CODE_FUNC, 1, TYPE_FLAG_GNU_IFUNC, | |
5019 | "<text gnu-indirect-function variable, no debug info>", | |
5020 | objfile); | |
5021 | TYPE_TARGET_TYPE (objfile_type->nodebug_text_gnu_ifunc_symbol) | |
5022 | = objfile_type->nodebug_text_symbol; | |
5023 | objfile_type->nodebug_got_plt_symbol | |
5024 | = init_type (TYPE_CODE_PTR, gdbarch_addr_bit (gdbarch) / 8, 0, | |
5025 | "<text from jump slot in .got.plt, no debug info>", | |
5026 | objfile); | |
5027 | TYPE_TARGET_TYPE (objfile_type->nodebug_got_plt_symbol) | |
5028 | = objfile_type->nodebug_text_symbol; | |
46bf5051 UW |
5029 | objfile_type->nodebug_data_symbol |
5030 | = init_type (TYPE_CODE_INT, | |
5031 | gdbarch_int_bit (gdbarch) / HOST_CHAR_BIT, 0, | |
5032 | "<data variable, no debug info>", objfile); | |
5033 | objfile_type->nodebug_unknown_symbol | |
5034 | = init_type (TYPE_CODE_INT, 1, 0, | |
5035 | "<variable (not text or data), no debug info>", objfile); | |
5036 | objfile_type->nodebug_tls_symbol | |
5037 | = init_type (TYPE_CODE_INT, | |
5038 | gdbarch_int_bit (gdbarch) / HOST_CHAR_BIT, 0, | |
5039 | "<thread local variable, no debug info>", objfile); | |
000177f0 AC |
5040 | |
5041 | /* NOTE: on some targets, addresses and pointers are not necessarily | |
0a7cfe2c | 5042 | the same. |
000177f0 AC |
5043 | |
5044 | The upshot is: | |
5045 | - gdb's `struct type' always describes the target's | |
5046 | representation. | |
5047 | - gdb's `struct value' objects should always hold values in | |
5048 | target form. | |
5049 | - gdb's CORE_ADDR values are addresses in the unified virtual | |
5050 | address space that the assembler and linker work with. Thus, | |
5051 | since target_read_memory takes a CORE_ADDR as an argument, it | |
5052 | can access any memory on the target, even if the processor has | |
5053 | separate code and data address spaces. | |
5054 | ||
46bf5051 UW |
5055 | In this context, objfile_type->builtin_core_addr is a bit odd: |
5056 | it's a target type for a value the target will never see. It's | |
5057 | only used to hold the values of (typeless) linker symbols, which | |
5058 | are indeed in the unified virtual address space. */ | |
000177f0 | 5059 | |
46bf5051 UW |
5060 | objfile_type->builtin_core_addr |
5061 | = init_type (TYPE_CODE_INT, | |
5062 | gdbarch_addr_bit (gdbarch) / 8, | |
5063 | TYPE_FLAG_UNSIGNED, "__CORE_ADDR", objfile); | |
64c50499 | 5064 | |
46bf5051 UW |
5065 | set_objfile_data (objfile, objfile_type_data, objfile_type); |
5066 | return objfile_type; | |
000177f0 AC |
5067 | } |
5068 | ||
5212577a | 5069 | extern initialize_file_ftype _initialize_gdbtypes; |
46bf5051 | 5070 | |
c906108c | 5071 | void |
fba45db2 | 5072 | _initialize_gdbtypes (void) |
c906108c | 5073 | { |
5674de60 | 5074 | gdbtypes_data = gdbarch_data_register_post_init (gdbtypes_post_init); |
46bf5051 | 5075 | objfile_type_data = register_objfile_data (); |
5674de60 | 5076 | |
ccce17b0 YQ |
5077 | add_setshow_zuinteger_cmd ("overload", no_class, &overload_debug, |
5078 | _("Set debugging of C++ overloading."), | |
5079 | _("Show debugging of C++ overloading."), | |
5080 | _("When enabled, ranking of the " | |
5081 | "functions is displayed."), | |
5082 | NULL, | |
5083 | show_overload_debug, | |
5084 | &setdebuglist, &showdebuglist); | |
5674de60 | 5085 | |
7ba81444 | 5086 | /* Add user knob for controlling resolution of opaque types. */ |
5674de60 | 5087 | add_setshow_boolean_cmd ("opaque-type-resolution", class_support, |
3e43a32a MS |
5088 | &opaque_type_resolution, |
5089 | _("Set resolution of opaque struct/class/union" | |
5090 | " types (if set before loading symbols)."), | |
5091 | _("Show resolution of opaque struct/class/union" | |
5092 | " types (if set before loading symbols)."), | |
5093 | NULL, NULL, | |
5674de60 UW |
5094 | show_opaque_type_resolution, |
5095 | &setlist, &showlist); | |
a451cb65 KS |
5096 | |
5097 | /* Add an option to permit non-strict type checking. */ | |
5098 | add_setshow_boolean_cmd ("type", class_support, | |
5099 | &strict_type_checking, | |
5100 | _("Set strict type checking."), | |
5101 | _("Show strict type checking."), | |
5102 | NULL, NULL, | |
5103 | show_strict_type_checking, | |
5104 | &setchecklist, &showchecklist); | |
c906108c | 5105 | } |