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