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