]>
Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Support routines for manipulating internal types for GDB. |
4f2aea11 MK |
2 | |
3 | Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002, | |
6aba47ca | 4 | 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc. |
4f2aea11 | 5 | |
c906108c SS |
6 | Contributed by Cygnus Support, using pieces from other GDB modules. |
7 | ||
c5aa993b | 8 | This file is part of GDB. |
c906108c | 9 | |
c5aa993b JM |
10 | This program is free software; you can redistribute it and/or modify |
11 | it under the terms of the GNU General Public License as published by | |
12 | the Free Software Foundation; either version 2 of the License, or | |
13 | (at your option) any later version. | |
c906108c | 14 | |
c5aa993b JM |
15 | This program is distributed in the hope that it will be useful, |
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | GNU General Public License for more details. | |
c906108c | 19 | |
c5aa993b JM |
20 | You should have received a copy of the GNU General Public License |
21 | along with this program; if not, write to the Free Software | |
197e01b6 EZ |
22 | Foundation, Inc., 51 Franklin Street, Fifth Floor, |
23 | Boston, MA 02110-1301, USA. */ | |
c906108c SS |
24 | |
25 | #include "defs.h" | |
26 | #include "gdb_string.h" | |
27 | #include "bfd.h" | |
28 | #include "symtab.h" | |
29 | #include "symfile.h" | |
30 | #include "objfiles.h" | |
31 | #include "gdbtypes.h" | |
32 | #include "expression.h" | |
33 | #include "language.h" | |
34 | #include "target.h" | |
35 | #include "value.h" | |
36 | #include "demangle.h" | |
37 | #include "complaints.h" | |
38 | #include "gdbcmd.h" | |
c91ecb25 | 39 | #include "wrapper.h" |
015a42b4 | 40 | #include "cp-abi.h" |
a02fd225 | 41 | #include "gdb_assert.h" |
ae5a43e0 | 42 | #include "hashtab.h" |
c906108c SS |
43 | |
44 | /* These variables point to the objects | |
45 | representing the predefined C data types. */ | |
46 | ||
47 | struct type *builtin_type_void; | |
48 | struct type *builtin_type_char; | |
9e0b60a8 | 49 | struct type *builtin_type_true_char; |
c906108c SS |
50 | struct type *builtin_type_short; |
51 | struct type *builtin_type_int; | |
52 | struct type *builtin_type_long; | |
53 | struct type *builtin_type_long_long; | |
54 | struct type *builtin_type_signed_char; | |
55 | struct type *builtin_type_unsigned_char; | |
56 | struct type *builtin_type_unsigned_short; | |
57 | struct type *builtin_type_unsigned_int; | |
58 | struct type *builtin_type_unsigned_long; | |
59 | struct type *builtin_type_unsigned_long_long; | |
60 | struct type *builtin_type_float; | |
61 | struct type *builtin_type_double; | |
62 | struct type *builtin_type_long_double; | |
63 | struct type *builtin_type_complex; | |
64 | struct type *builtin_type_double_complex; | |
65 | struct type *builtin_type_string; | |
449a5da4 | 66 | struct type *builtin_type_int0; |
c906108c SS |
67 | struct type *builtin_type_int8; |
68 | struct type *builtin_type_uint8; | |
69 | struct type *builtin_type_int16; | |
70 | struct type *builtin_type_uint16; | |
71 | struct type *builtin_type_int32; | |
72 | struct type *builtin_type_uint32; | |
73 | struct type *builtin_type_int64; | |
74 | struct type *builtin_type_uint64; | |
8b982acf EZ |
75 | struct type *builtin_type_int128; |
76 | struct type *builtin_type_uint128; | |
c906108c | 77 | struct type *builtin_type_bool; |
ac3aafc7 EZ |
78 | |
79 | /* 128 bit long vector types */ | |
3139facc | 80 | struct type *builtin_type_v2_double; |
ac3aafc7 | 81 | struct type *builtin_type_v4_float; |
3139facc | 82 | struct type *builtin_type_v2_int64; |
ac3aafc7 EZ |
83 | struct type *builtin_type_v4_int32; |
84 | struct type *builtin_type_v8_int16; | |
85 | struct type *builtin_type_v16_int8; | |
86 | /* 64 bit long vector types */ | |
6599f021 | 87 | struct type *builtin_type_v2_float; |
ac3aafc7 EZ |
88 | struct type *builtin_type_v2_int32; |
89 | struct type *builtin_type_v4_int16; | |
90 | struct type *builtin_type_v8_int8; | |
91 | ||
917317f4 | 92 | struct type *builtin_type_v4sf; |
c2d11a7d | 93 | struct type *builtin_type_v4si; |
08cf96df | 94 | struct type *builtin_type_v16qi; |
c2d11a7d | 95 | struct type *builtin_type_v8qi; |
08cf96df | 96 | struct type *builtin_type_v8hi; |
c2d11a7d JM |
97 | struct type *builtin_type_v4hi; |
98 | struct type *builtin_type_v2si; | |
b063e7a2 | 99 | struct type *builtin_type_vec64; |
08cf96df | 100 | struct type *builtin_type_vec128; |
8da61cc4 DJ |
101 | |
102 | /* Floatformat pairs. */ | |
103 | const struct floatformat *floatformats_ieee_single[BFD_ENDIAN_UNKNOWN] = { | |
104 | &floatformat_ieee_single_big, | |
105 | &floatformat_ieee_single_little | |
106 | }; | |
107 | const struct floatformat *floatformats_ieee_double[BFD_ENDIAN_UNKNOWN] = { | |
108 | &floatformat_ieee_double_big, | |
109 | &floatformat_ieee_double_little | |
110 | }; | |
111 | const struct floatformat *floatformats_ieee_double_littlebyte_bigword[BFD_ENDIAN_UNKNOWN] = { | |
112 | &floatformat_ieee_double_big, | |
113 | &floatformat_ieee_double_littlebyte_bigword | |
114 | }; | |
115 | const struct floatformat *floatformats_i387_ext[BFD_ENDIAN_UNKNOWN] = { | |
116 | &floatformat_i387_ext, | |
117 | &floatformat_i387_ext | |
118 | }; | |
119 | const struct floatformat *floatformats_m68881_ext[BFD_ENDIAN_UNKNOWN] = { | |
120 | &floatformat_m68881_ext, | |
121 | &floatformat_m68881_ext | |
122 | }; | |
123 | const struct floatformat *floatformats_arm_ext[BFD_ENDIAN_UNKNOWN] = { | |
124 | &floatformat_arm_ext_big, | |
125 | &floatformat_arm_ext_littlebyte_bigword | |
126 | }; | |
127 | const struct floatformat *floatformats_ia64_spill[BFD_ENDIAN_UNKNOWN] = { | |
128 | &floatformat_ia64_spill_big, | |
129 | &floatformat_ia64_spill_little | |
130 | }; | |
131 | const struct floatformat *floatformats_ia64_quad[BFD_ENDIAN_UNKNOWN] = { | |
132 | &floatformat_ia64_quad_big, | |
133 | &floatformat_ia64_quad_little | |
134 | }; | |
135 | const struct floatformat *floatformats_vax_f[BFD_ENDIAN_UNKNOWN] = { | |
136 | &floatformat_vax_f, | |
137 | &floatformat_vax_f | |
138 | }; | |
139 | const struct floatformat *floatformats_vax_d[BFD_ENDIAN_UNKNOWN] = { | |
140 | &floatformat_vax_d, | |
141 | &floatformat_vax_d | |
142 | }; | |
143 | ||
144 | struct type *builtin_type_ieee_single; | |
145 | struct type *builtin_type_ieee_double; | |
598f52df AC |
146 | struct type *builtin_type_i387_ext; |
147 | struct type *builtin_type_m68881_ext; | |
8da61cc4 DJ |
148 | struct type *builtin_type_arm_ext; |
149 | struct type *builtin_type_ia64_spill; | |
150 | struct type *builtin_type_ia64_quad; | |
151 | ||
090a2205 | 152 | struct type *builtin_type_void_data_ptr; |
ee3a7b7f | 153 | struct type *builtin_type_void_func_ptr; |
c4093a6a JM |
154 | struct type *builtin_type_CORE_ADDR; |
155 | struct type *builtin_type_bfd_vma; | |
c906108c SS |
156 | |
157 | int opaque_type_resolution = 1; | |
920d2a44 AC |
158 | static void |
159 | show_opaque_type_resolution (struct ui_file *file, int from_tty, | |
160 | struct cmd_list_element *c, const char *value) | |
161 | { | |
162 | fprintf_filtered (file, _("\ | |
163 | Resolution of opaque struct/class/union types (if set before loading symbols) is %s.\n"), | |
164 | value); | |
165 | } | |
166 | ||
5d161b24 | 167 | int overload_debug = 0; |
920d2a44 AC |
168 | static void |
169 | show_overload_debug (struct ui_file *file, int from_tty, | |
170 | struct cmd_list_element *c, const char *value) | |
171 | { | |
172 | fprintf_filtered (file, _("Debugging of C++ overloading is %s.\n"), value); | |
173 | } | |
c906108c | 174 | |
c5aa993b JM |
175 | struct extra |
176 | { | |
177 | char str[128]; | |
178 | int len; | |
8c990f3c | 179 | }; /* maximum extension is 128! FIXME */ |
c906108c | 180 | |
a14ed312 | 181 | static void print_bit_vector (B_TYPE *, int); |
ad2f7632 | 182 | static void print_arg_types (struct field *, int, int); |
a14ed312 KB |
183 | static void dump_fn_fieldlists (struct type *, int); |
184 | static void print_cplus_stuff (struct type *, int); | |
185 | static void virtual_base_list_aux (struct type *dclass); | |
7a292a7a | 186 | |
c906108c SS |
187 | |
188 | /* Alloc a new type structure and fill it with some defaults. If | |
189 | OBJFILE is non-NULL, then allocate the space for the type structure | |
b99607ea | 190 | in that objfile's objfile_obstack. Otherwise allocate the new type structure |
2fdde8f8 | 191 | by xmalloc () (for permanent types). */ |
c906108c SS |
192 | |
193 | struct type * | |
fba45db2 | 194 | alloc_type (struct objfile *objfile) |
c906108c | 195 | { |
52f0bd74 | 196 | struct type *type; |
c906108c SS |
197 | |
198 | /* Alloc the structure and start off with all fields zeroed. */ | |
199 | ||
200 | if (objfile == NULL) | |
201 | { | |
2fdde8f8 DJ |
202 | type = xmalloc (sizeof (struct type)); |
203 | memset (type, 0, sizeof (struct type)); | |
204 | TYPE_MAIN_TYPE (type) = xmalloc (sizeof (struct main_type)); | |
c906108c SS |
205 | } |
206 | else | |
207 | { | |
b99607ea | 208 | type = obstack_alloc (&objfile->objfile_obstack, |
2fdde8f8 DJ |
209 | sizeof (struct type)); |
210 | memset (type, 0, sizeof (struct type)); | |
b99607ea | 211 | TYPE_MAIN_TYPE (type) = obstack_alloc (&objfile->objfile_obstack, |
2fdde8f8 | 212 | sizeof (struct main_type)); |
c906108c SS |
213 | OBJSTAT (objfile, n_types++); |
214 | } | |
2fdde8f8 | 215 | memset (TYPE_MAIN_TYPE (type), 0, sizeof (struct main_type)); |
c906108c SS |
216 | |
217 | /* Initialize the fields that might not be zero. */ | |
218 | ||
219 | TYPE_CODE (type) = TYPE_CODE_UNDEF; | |
220 | TYPE_OBJFILE (type) = objfile; | |
221 | TYPE_VPTR_FIELDNO (type) = -1; | |
2fdde8f8 | 222 | TYPE_CHAIN (type) = type; /* Chain back to itself. */ |
c906108c SS |
223 | |
224 | return (type); | |
225 | } | |
226 | ||
2fdde8f8 DJ |
227 | /* Alloc a new type instance structure, fill it with some defaults, |
228 | and point it at OLDTYPE. Allocate the new type instance from the | |
229 | same place as OLDTYPE. */ | |
230 | ||
231 | static struct type * | |
232 | alloc_type_instance (struct type *oldtype) | |
233 | { | |
234 | struct type *type; | |
235 | ||
236 | /* Allocate the structure. */ | |
237 | ||
238 | if (TYPE_OBJFILE (oldtype) == NULL) | |
239 | { | |
240 | type = xmalloc (sizeof (struct type)); | |
241 | memset (type, 0, sizeof (struct type)); | |
242 | } | |
243 | else | |
244 | { | |
b99607ea | 245 | type = obstack_alloc (&TYPE_OBJFILE (oldtype)->objfile_obstack, |
2fdde8f8 DJ |
246 | sizeof (struct type)); |
247 | memset (type, 0, sizeof (struct type)); | |
248 | } | |
249 | TYPE_MAIN_TYPE (type) = TYPE_MAIN_TYPE (oldtype); | |
250 | ||
251 | TYPE_CHAIN (type) = type; /* Chain back to itself for now. */ | |
252 | ||
253 | return (type); | |
254 | } | |
255 | ||
256 | /* Clear all remnants of the previous type at TYPE, in preparation for | |
257 | replacing it with something else. */ | |
258 | static void | |
259 | smash_type (struct type *type) | |
260 | { | |
261 | memset (TYPE_MAIN_TYPE (type), 0, sizeof (struct main_type)); | |
262 | ||
263 | /* For now, delete the rings. */ | |
264 | TYPE_CHAIN (type) = type; | |
265 | ||
266 | /* For now, leave the pointer/reference types alone. */ | |
267 | } | |
268 | ||
c906108c SS |
269 | /* Lookup a pointer to a type TYPE. TYPEPTR, if nonzero, points |
270 | to a pointer to memory where the pointer type should be stored. | |
271 | If *TYPEPTR is zero, update it to point to the pointer type we return. | |
272 | We allocate new memory if needed. */ | |
273 | ||
274 | struct type * | |
fba45db2 | 275 | make_pointer_type (struct type *type, struct type **typeptr) |
c906108c | 276 | { |
52f0bd74 | 277 | struct type *ntype; /* New type */ |
c906108c | 278 | struct objfile *objfile; |
053cb41b | 279 | struct type *chain; |
c906108c SS |
280 | |
281 | ntype = TYPE_POINTER_TYPE (type); | |
282 | ||
c5aa993b | 283 | if (ntype) |
c906108c | 284 | { |
c5aa993b JM |
285 | if (typeptr == 0) |
286 | return ntype; /* Don't care about alloc, and have new type. */ | |
c906108c | 287 | else if (*typeptr == 0) |
c5aa993b | 288 | { |
c906108c SS |
289 | *typeptr = ntype; /* Tracking alloc, and we have new type. */ |
290 | return ntype; | |
c5aa993b | 291 | } |
c906108c SS |
292 | } |
293 | ||
294 | if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */ | |
295 | { | |
296 | ntype = alloc_type (TYPE_OBJFILE (type)); | |
297 | if (typeptr) | |
298 | *typeptr = ntype; | |
299 | } | |
c5aa993b JM |
300 | else |
301 | /* We have storage, but need to reset it. */ | |
c906108c SS |
302 | { |
303 | ntype = *typeptr; | |
304 | objfile = TYPE_OBJFILE (ntype); | |
053cb41b | 305 | chain = TYPE_CHAIN (ntype); |
2fdde8f8 | 306 | smash_type (ntype); |
053cb41b | 307 | TYPE_CHAIN (ntype) = chain; |
c906108c SS |
308 | TYPE_OBJFILE (ntype) = objfile; |
309 | } | |
310 | ||
311 | TYPE_TARGET_TYPE (ntype) = type; | |
312 | TYPE_POINTER_TYPE (type) = ntype; | |
313 | ||
314 | /* FIXME! Assume the machine has only one representation for pointers! */ | |
315 | ||
819844ad | 316 | TYPE_LENGTH (ntype) = gdbarch_ptr_bit (current_gdbarch) / TARGET_CHAR_BIT; |
c906108c SS |
317 | TYPE_CODE (ntype) = TYPE_CODE_PTR; |
318 | ||
67b2adb2 | 319 | /* Mark pointers as unsigned. The target converts between pointers |
76e71323 UW |
320 | and addresses (CORE_ADDRs) using gdbarch_pointer_to_address and |
321 | gdbarch_address_to_pointer. */ | |
c906108c | 322 | TYPE_FLAGS (ntype) |= TYPE_FLAG_UNSIGNED; |
c5aa993b | 323 | |
c906108c SS |
324 | if (!TYPE_POINTER_TYPE (type)) /* Remember it, if don't have one. */ |
325 | TYPE_POINTER_TYPE (type) = ntype; | |
326 | ||
053cb41b JB |
327 | /* Update the length of all the other variants of this type. */ |
328 | chain = TYPE_CHAIN (ntype); | |
329 | while (chain != ntype) | |
330 | { | |
331 | TYPE_LENGTH (chain) = TYPE_LENGTH (ntype); | |
332 | chain = TYPE_CHAIN (chain); | |
333 | } | |
334 | ||
c906108c SS |
335 | return ntype; |
336 | } | |
337 | ||
338 | /* Given a type TYPE, return a type of pointers to that type. | |
339 | May need to construct such a type if this is the first use. */ | |
340 | ||
341 | struct type * | |
fba45db2 | 342 | lookup_pointer_type (struct type *type) |
c906108c | 343 | { |
c5aa993b | 344 | return make_pointer_type (type, (struct type **) 0); |
c906108c SS |
345 | } |
346 | ||
347 | /* Lookup a C++ `reference' to a type TYPE. TYPEPTR, if nonzero, points | |
348 | to a pointer to memory where the reference type should be stored. | |
349 | If *TYPEPTR is zero, update it to point to the reference type we return. | |
350 | We allocate new memory if needed. */ | |
351 | ||
352 | struct type * | |
fba45db2 | 353 | make_reference_type (struct type *type, struct type **typeptr) |
c906108c | 354 | { |
52f0bd74 | 355 | struct type *ntype; /* New type */ |
c906108c | 356 | struct objfile *objfile; |
1e98b326 | 357 | struct type *chain; |
c906108c SS |
358 | |
359 | ntype = TYPE_REFERENCE_TYPE (type); | |
360 | ||
c5aa993b | 361 | if (ntype) |
c906108c | 362 | { |
c5aa993b JM |
363 | if (typeptr == 0) |
364 | return ntype; /* Don't care about alloc, and have new type. */ | |
c906108c | 365 | else if (*typeptr == 0) |
c5aa993b | 366 | { |
c906108c SS |
367 | *typeptr = ntype; /* Tracking alloc, and we have new type. */ |
368 | return ntype; | |
c5aa993b | 369 | } |
c906108c SS |
370 | } |
371 | ||
372 | if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */ | |
373 | { | |
374 | ntype = alloc_type (TYPE_OBJFILE (type)); | |
375 | if (typeptr) | |
376 | *typeptr = ntype; | |
377 | } | |
c5aa993b JM |
378 | else |
379 | /* We have storage, but need to reset it. */ | |
c906108c SS |
380 | { |
381 | ntype = *typeptr; | |
382 | objfile = TYPE_OBJFILE (ntype); | |
1e98b326 | 383 | chain = TYPE_CHAIN (ntype); |
2fdde8f8 | 384 | smash_type (ntype); |
1e98b326 | 385 | TYPE_CHAIN (ntype) = chain; |
c906108c SS |
386 | TYPE_OBJFILE (ntype) = objfile; |
387 | } | |
388 | ||
389 | TYPE_TARGET_TYPE (ntype) = type; | |
390 | TYPE_REFERENCE_TYPE (type) = ntype; | |
391 | ||
392 | /* FIXME! Assume the machine has only one representation for references, | |
393 | and that it matches the (only) representation for pointers! */ | |
394 | ||
819844ad | 395 | TYPE_LENGTH (ntype) = gdbarch_ptr_bit (current_gdbarch) / TARGET_CHAR_BIT; |
c906108c | 396 | TYPE_CODE (ntype) = TYPE_CODE_REF; |
c5aa993b | 397 | |
c906108c SS |
398 | if (!TYPE_REFERENCE_TYPE (type)) /* Remember it, if don't have one. */ |
399 | TYPE_REFERENCE_TYPE (type) = ntype; | |
400 | ||
1e98b326 JB |
401 | /* Update the length of all the other variants of this type. */ |
402 | chain = TYPE_CHAIN (ntype); | |
403 | while (chain != ntype) | |
404 | { | |
405 | TYPE_LENGTH (chain) = TYPE_LENGTH (ntype); | |
406 | chain = TYPE_CHAIN (chain); | |
407 | } | |
408 | ||
c906108c SS |
409 | return ntype; |
410 | } | |
411 | ||
412 | /* Same as above, but caller doesn't care about memory allocation details. */ | |
413 | ||
414 | struct type * | |
fba45db2 | 415 | lookup_reference_type (struct type *type) |
c906108c | 416 | { |
c5aa993b | 417 | return make_reference_type (type, (struct type **) 0); |
c906108c SS |
418 | } |
419 | ||
420 | /* Lookup a function type that returns type TYPE. TYPEPTR, if nonzero, points | |
421 | to a pointer to memory where the function type should be stored. | |
422 | If *TYPEPTR is zero, update it to point to the function type we return. | |
423 | We allocate new memory if needed. */ | |
424 | ||
425 | struct type * | |
fba45db2 | 426 | make_function_type (struct type *type, struct type **typeptr) |
c906108c | 427 | { |
52f0bd74 | 428 | struct type *ntype; /* New type */ |
c906108c SS |
429 | struct objfile *objfile; |
430 | ||
431 | if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */ | |
432 | { | |
433 | ntype = alloc_type (TYPE_OBJFILE (type)); | |
434 | if (typeptr) | |
435 | *typeptr = ntype; | |
436 | } | |
c5aa993b JM |
437 | else |
438 | /* We have storage, but need to reset it. */ | |
c906108c SS |
439 | { |
440 | ntype = *typeptr; | |
441 | objfile = TYPE_OBJFILE (ntype); | |
2fdde8f8 | 442 | smash_type (ntype); |
c906108c SS |
443 | TYPE_OBJFILE (ntype) = objfile; |
444 | } | |
445 | ||
446 | TYPE_TARGET_TYPE (ntype) = type; | |
447 | ||
448 | TYPE_LENGTH (ntype) = 1; | |
449 | TYPE_CODE (ntype) = TYPE_CODE_FUNC; | |
c5aa993b | 450 | |
c906108c SS |
451 | return ntype; |
452 | } | |
453 | ||
454 | ||
455 | /* Given a type TYPE, return a type of functions that return that type. | |
456 | May need to construct such a type if this is the first use. */ | |
457 | ||
458 | struct type * | |
fba45db2 | 459 | lookup_function_type (struct type *type) |
c906108c | 460 | { |
c5aa993b | 461 | return make_function_type (type, (struct type **) 0); |
c906108c SS |
462 | } |
463 | ||
47663de5 MS |
464 | /* Identify address space identifier by name -- |
465 | return the integer flag defined in gdbtypes.h. */ | |
466 | extern int | |
467 | address_space_name_to_int (char *space_identifier) | |
468 | { | |
5f11f355 | 469 | struct gdbarch *gdbarch = current_gdbarch; |
8b2dbe47 | 470 | int type_flags; |
47663de5 MS |
471 | /* Check for known address space delimiters. */ |
472 | if (!strcmp (space_identifier, "code")) | |
473 | return TYPE_FLAG_CODE_SPACE; | |
474 | else if (!strcmp (space_identifier, "data")) | |
475 | return TYPE_FLAG_DATA_SPACE; | |
5f11f355 AC |
476 | else if (gdbarch_address_class_name_to_type_flags_p (gdbarch) |
477 | && gdbarch_address_class_name_to_type_flags (gdbarch, | |
478 | space_identifier, | |
479 | &type_flags)) | |
8b2dbe47 | 480 | return type_flags; |
47663de5 | 481 | else |
8a3fe4f8 | 482 | error (_("Unknown address space specifier: \"%s\""), space_identifier); |
47663de5 MS |
483 | } |
484 | ||
485 | /* Identify address space identifier by integer flag as defined in | |
486 | gdbtypes.h -- return the string version of the adress space name. */ | |
487 | ||
321432c0 | 488 | const char * |
47663de5 MS |
489 | address_space_int_to_name (int space_flag) |
490 | { | |
5f11f355 | 491 | struct gdbarch *gdbarch = current_gdbarch; |
47663de5 MS |
492 | if (space_flag & TYPE_FLAG_CODE_SPACE) |
493 | return "code"; | |
494 | else if (space_flag & TYPE_FLAG_DATA_SPACE) | |
495 | return "data"; | |
8b2dbe47 | 496 | else if ((space_flag & TYPE_FLAG_ADDRESS_CLASS_ALL) |
5f11f355 AC |
497 | && gdbarch_address_class_type_flags_to_name_p (gdbarch)) |
498 | return gdbarch_address_class_type_flags_to_name (gdbarch, space_flag); | |
47663de5 MS |
499 | else |
500 | return NULL; | |
501 | } | |
502 | ||
2fdde8f8 | 503 | /* Create a new type with instance flags NEW_FLAGS, based on TYPE. |
ad766c0a JB |
504 | |
505 | If STORAGE is non-NULL, create the new type instance there. | |
506 | STORAGE must be in the same obstack as TYPE. */ | |
47663de5 | 507 | |
b9362cc7 | 508 | static struct type * |
2fdde8f8 DJ |
509 | make_qualified_type (struct type *type, int new_flags, |
510 | struct type *storage) | |
47663de5 MS |
511 | { |
512 | struct type *ntype; | |
513 | ||
514 | ntype = type; | |
515 | do { | |
2fdde8f8 | 516 | if (TYPE_INSTANCE_FLAGS (ntype) == new_flags) |
47663de5 | 517 | return ntype; |
2fdde8f8 | 518 | ntype = TYPE_CHAIN (ntype); |
47663de5 MS |
519 | } while (ntype != type); |
520 | ||
2fdde8f8 DJ |
521 | /* Create a new type instance. */ |
522 | if (storage == NULL) | |
523 | ntype = alloc_type_instance (type); | |
524 | else | |
525 | { | |
ad766c0a JB |
526 | /* If STORAGE was provided, it had better be in the same objfile as |
527 | TYPE. Otherwise, we can't link it into TYPE's cv chain: if one | |
528 | objfile is freed and the other kept, we'd have dangling | |
529 | pointers. */ | |
530 | gdb_assert (TYPE_OBJFILE (type) == TYPE_OBJFILE (storage)); | |
531 | ||
2fdde8f8 DJ |
532 | ntype = storage; |
533 | TYPE_MAIN_TYPE (ntype) = TYPE_MAIN_TYPE (type); | |
534 | TYPE_CHAIN (ntype) = ntype; | |
535 | } | |
47663de5 MS |
536 | |
537 | /* Pointers or references to the original type are not relevant to | |
2fdde8f8 | 538 | the new type. */ |
47663de5 MS |
539 | TYPE_POINTER_TYPE (ntype) = (struct type *) 0; |
540 | TYPE_REFERENCE_TYPE (ntype) = (struct type *) 0; | |
47663de5 | 541 | |
2fdde8f8 DJ |
542 | /* Chain the new qualified type to the old type. */ |
543 | TYPE_CHAIN (ntype) = TYPE_CHAIN (type); | |
544 | TYPE_CHAIN (type) = ntype; | |
545 | ||
546 | /* Now set the instance flags and return the new type. */ | |
547 | TYPE_INSTANCE_FLAGS (ntype) = new_flags; | |
47663de5 | 548 | |
ab5d3da6 KB |
549 | /* Set length of new type to that of the original type. */ |
550 | TYPE_LENGTH (ntype) = TYPE_LENGTH (type); | |
551 | ||
47663de5 MS |
552 | return ntype; |
553 | } | |
554 | ||
2fdde8f8 DJ |
555 | /* Make an address-space-delimited variant of a type -- a type that |
556 | is identical to the one supplied except that it has an address | |
557 | space attribute attached to it (such as "code" or "data"). | |
558 | ||
8b2dbe47 KB |
559 | The space attributes "code" and "data" are for Harvard architectures. |
560 | The address space attributes are for architectures which have | |
561 | alternately sized pointers or pointers with alternate representations. */ | |
2fdde8f8 DJ |
562 | |
563 | struct type * | |
564 | make_type_with_address_space (struct type *type, int space_flag) | |
565 | { | |
566 | struct type *ntype; | |
567 | int new_flags = ((TYPE_INSTANCE_FLAGS (type) | |
8b2dbe47 KB |
568 | & ~(TYPE_FLAG_CODE_SPACE | TYPE_FLAG_DATA_SPACE |
569 | | TYPE_FLAG_ADDRESS_CLASS_ALL)) | |
2fdde8f8 DJ |
570 | | space_flag); |
571 | ||
572 | return make_qualified_type (type, new_flags, NULL); | |
573 | } | |
c906108c SS |
574 | |
575 | /* Make a "c-v" variant of a type -- a type that is identical to the | |
576 | one supplied except that it may have const or volatile attributes | |
577 | CNST is a flag for setting the const attribute | |
578 | VOLTL is a flag for setting the volatile attribute | |
579 | TYPE is the base type whose variant we are creating. | |
c906108c | 580 | |
ad766c0a JB |
581 | If TYPEPTR and *TYPEPTR are non-zero, then *TYPEPTR points to |
582 | storage to hold the new qualified type; *TYPEPTR and TYPE must be | |
583 | in the same objfile. Otherwise, allocate fresh memory for the new | |
584 | type whereever TYPE lives. If TYPEPTR is non-zero, set it to the | |
585 | new type we construct. */ | |
c906108c | 586 | struct type * |
fba45db2 | 587 | make_cv_type (int cnst, int voltl, struct type *type, struct type **typeptr) |
c906108c | 588 | { |
52f0bd74 AC |
589 | struct type *ntype; /* New type */ |
590 | struct type *tmp_type = type; /* tmp type */ | |
c906108c SS |
591 | struct objfile *objfile; |
592 | ||
2fdde8f8 DJ |
593 | int new_flags = (TYPE_INSTANCE_FLAGS (type) |
594 | & ~(TYPE_FLAG_CONST | TYPE_FLAG_VOLATILE)); | |
c906108c | 595 | |
c906108c | 596 | if (cnst) |
2fdde8f8 | 597 | new_flags |= TYPE_FLAG_CONST; |
c906108c SS |
598 | |
599 | if (voltl) | |
2fdde8f8 | 600 | new_flags |= TYPE_FLAG_VOLATILE; |
a02fd225 | 601 | |
2fdde8f8 | 602 | if (typeptr && *typeptr != NULL) |
a02fd225 | 603 | { |
ad766c0a JB |
604 | /* TYPE and *TYPEPTR must be in the same objfile. We can't have |
605 | a C-V variant chain that threads across objfiles: if one | |
606 | objfile gets freed, then the other has a broken C-V chain. | |
607 | ||
608 | This code used to try to copy over the main type from TYPE to | |
609 | *TYPEPTR if they were in different objfiles, but that's | |
610 | wrong, too: TYPE may have a field list or member function | |
611 | lists, which refer to types of their own, etc. etc. The | |
612 | whole shebang would need to be copied over recursively; you | |
613 | can't have inter-objfile pointers. The only thing to do is | |
614 | to leave stub types as stub types, and look them up afresh by | |
615 | name each time you encounter them. */ | |
616 | gdb_assert (TYPE_OBJFILE (*typeptr) == TYPE_OBJFILE (type)); | |
2fdde8f8 DJ |
617 | } |
618 | ||
619 | ntype = make_qualified_type (type, new_flags, typeptr ? *typeptr : NULL); | |
c906108c | 620 | |
2fdde8f8 DJ |
621 | if (typeptr != NULL) |
622 | *typeptr = ntype; | |
a02fd225 | 623 | |
2fdde8f8 | 624 | return ntype; |
a02fd225 | 625 | } |
c906108c | 626 | |
2fdde8f8 DJ |
627 | /* Replace the contents of ntype with the type *type. This changes the |
628 | contents, rather than the pointer for TYPE_MAIN_TYPE (ntype); thus | |
629 | the changes are propogated to all types in the TYPE_CHAIN. | |
dd6bda65 | 630 | |
cda6c68a JB |
631 | In order to build recursive types, it's inevitable that we'll need |
632 | to update types in place --- but this sort of indiscriminate | |
633 | smashing is ugly, and needs to be replaced with something more | |
2fdde8f8 DJ |
634 | controlled. TYPE_MAIN_TYPE is a step in this direction; it's not |
635 | clear if more steps are needed. */ | |
dd6bda65 DJ |
636 | void |
637 | replace_type (struct type *ntype, struct type *type) | |
638 | { | |
ab5d3da6 | 639 | struct type *chain; |
dd6bda65 | 640 | |
ad766c0a JB |
641 | /* These two types had better be in the same objfile. Otherwise, |
642 | the assignment of one type's main type structure to the other | |
643 | will produce a type with references to objects (names; field | |
644 | lists; etc.) allocated on an objfile other than its own. */ | |
645 | gdb_assert (TYPE_OBJFILE (ntype) == TYPE_OBJFILE (ntype)); | |
646 | ||
2fdde8f8 | 647 | *TYPE_MAIN_TYPE (ntype) = *TYPE_MAIN_TYPE (type); |
dd6bda65 | 648 | |
ab5d3da6 KB |
649 | /* The type length is not a part of the main type. Update it for each |
650 | type on the variant chain. */ | |
651 | chain = ntype; | |
652 | do { | |
653 | /* Assert that this element of the chain has no address-class bits | |
654 | set in its flags. Such type variants might have type lengths | |
655 | which are supposed to be different from the non-address-class | |
656 | variants. This assertion shouldn't ever be triggered because | |
657 | symbol readers which do construct address-class variants don't | |
658 | call replace_type(). */ | |
659 | gdb_assert (TYPE_ADDRESS_CLASS_ALL (chain) == 0); | |
660 | ||
787cbe14 | 661 | TYPE_LENGTH (chain) = TYPE_LENGTH (type); |
ab5d3da6 KB |
662 | chain = TYPE_CHAIN (chain); |
663 | } while (ntype != chain); | |
664 | ||
2fdde8f8 DJ |
665 | /* Assert that the two types have equivalent instance qualifiers. |
666 | This should be true for at least all of our debug readers. */ | |
667 | gdb_assert (TYPE_INSTANCE_FLAGS (ntype) == TYPE_INSTANCE_FLAGS (type)); | |
dd6bda65 DJ |
668 | } |
669 | ||
c906108c SS |
670 | /* Implement direct support for MEMBER_TYPE in GNU C++. |
671 | May need to construct such a type if this is the first use. | |
672 | The TYPE is the type of the member. The DOMAIN is the type | |
673 | of the aggregate that the member belongs to. */ | |
674 | ||
675 | struct type * | |
0d5de010 | 676 | lookup_memberptr_type (struct type *type, struct type *domain) |
c906108c | 677 | { |
52f0bd74 | 678 | struct type *mtype; |
c906108c SS |
679 | |
680 | mtype = alloc_type (TYPE_OBJFILE (type)); | |
0d5de010 | 681 | smash_to_memberptr_type (mtype, domain, type); |
c906108c SS |
682 | return (mtype); |
683 | } | |
684 | ||
0d5de010 DJ |
685 | /* Return a pointer-to-method type, for a method of type TO_TYPE. */ |
686 | ||
687 | struct type * | |
688 | lookup_methodptr_type (struct type *to_type) | |
689 | { | |
690 | struct type *mtype; | |
691 | ||
692 | mtype = alloc_type (TYPE_OBJFILE (to_type)); | |
693 | TYPE_TARGET_TYPE (mtype) = to_type; | |
694 | TYPE_DOMAIN_TYPE (mtype) = TYPE_DOMAIN_TYPE (to_type); | |
695 | TYPE_LENGTH (mtype) = cplus_method_ptr_size (); | |
696 | TYPE_CODE (mtype) = TYPE_CODE_METHODPTR; | |
697 | return mtype; | |
698 | } | |
699 | ||
7b83ea04 | 700 | /* Allocate a stub method whose return type is TYPE. |
c906108c SS |
701 | This apparently happens for speed of symbol reading, since parsing |
702 | out the arguments to the method is cpu-intensive, the way we are doing | |
703 | it. So, we will fill in arguments later. | |
704 | This always returns a fresh type. */ | |
705 | ||
706 | struct type * | |
fba45db2 | 707 | allocate_stub_method (struct type *type) |
c906108c SS |
708 | { |
709 | struct type *mtype; | |
710 | ||
7e956337 FF |
711 | mtype = init_type (TYPE_CODE_METHOD, 1, TYPE_FLAG_STUB, NULL, |
712 | TYPE_OBJFILE (type)); | |
c906108c SS |
713 | TYPE_TARGET_TYPE (mtype) = type; |
714 | /* _DOMAIN_TYPE (mtype) = unknown yet */ | |
c906108c SS |
715 | return (mtype); |
716 | } | |
717 | ||
718 | /* Create a range type using either a blank type supplied in RESULT_TYPE, | |
719 | or creating a new type, inheriting the objfile from INDEX_TYPE. | |
720 | ||
721 | Indices will be of type INDEX_TYPE, and will range from LOW_BOUND to | |
722 | HIGH_BOUND, inclusive. | |
723 | ||
724 | FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make | |
725 | sure it is TYPE_CODE_UNDEF before we bash it into a range type? */ | |
726 | ||
727 | struct type * | |
fba45db2 KB |
728 | create_range_type (struct type *result_type, struct type *index_type, |
729 | int low_bound, int high_bound) | |
c906108c SS |
730 | { |
731 | if (result_type == NULL) | |
732 | { | |
733 | result_type = alloc_type (TYPE_OBJFILE (index_type)); | |
734 | } | |
735 | TYPE_CODE (result_type) = TYPE_CODE_RANGE; | |
736 | TYPE_TARGET_TYPE (result_type) = index_type; | |
74a9bb82 | 737 | if (TYPE_STUB (index_type)) |
c906108c SS |
738 | TYPE_FLAGS (result_type) |= TYPE_FLAG_TARGET_STUB; |
739 | else | |
740 | TYPE_LENGTH (result_type) = TYPE_LENGTH (check_typedef (index_type)); | |
741 | TYPE_NFIELDS (result_type) = 2; | |
742 | TYPE_FIELDS (result_type) = (struct field *) | |
743 | TYPE_ALLOC (result_type, 2 * sizeof (struct field)); | |
744 | memset (TYPE_FIELDS (result_type), 0, 2 * sizeof (struct field)); | |
745 | TYPE_FIELD_BITPOS (result_type, 0) = low_bound; | |
746 | TYPE_FIELD_BITPOS (result_type, 1) = high_bound; | |
c5aa993b JM |
747 | TYPE_FIELD_TYPE (result_type, 0) = builtin_type_int; /* FIXME */ |
748 | TYPE_FIELD_TYPE (result_type, 1) = builtin_type_int; /* FIXME */ | |
c906108c | 749 | |
c5aa993b | 750 | if (low_bound >= 0) |
c906108c SS |
751 | TYPE_FLAGS (result_type) |= TYPE_FLAG_UNSIGNED; |
752 | ||
753 | return (result_type); | |
754 | } | |
755 | ||
756 | /* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type TYPE. | |
c54d24cb | 757 | Return 1 if type is a range type, 0 if it is discrete (and bounds |
c906108c SS |
758 | will fit in LONGEST), or -1 otherwise. */ |
759 | ||
760 | int | |
fba45db2 | 761 | get_discrete_bounds (struct type *type, LONGEST *lowp, LONGEST *highp) |
c906108c SS |
762 | { |
763 | CHECK_TYPEDEF (type); | |
764 | switch (TYPE_CODE (type)) | |
765 | { | |
766 | case TYPE_CODE_RANGE: | |
767 | *lowp = TYPE_LOW_BOUND (type); | |
768 | *highp = TYPE_HIGH_BOUND (type); | |
769 | return 1; | |
770 | case TYPE_CODE_ENUM: | |
771 | if (TYPE_NFIELDS (type) > 0) | |
772 | { | |
773 | /* The enums may not be sorted by value, so search all | |
774 | entries */ | |
775 | int i; | |
776 | ||
777 | *lowp = *highp = TYPE_FIELD_BITPOS (type, 0); | |
778 | for (i = 0; i < TYPE_NFIELDS (type); i++) | |
779 | { | |
780 | if (TYPE_FIELD_BITPOS (type, i) < *lowp) | |
781 | *lowp = TYPE_FIELD_BITPOS (type, i); | |
782 | if (TYPE_FIELD_BITPOS (type, i) > *highp) | |
783 | *highp = TYPE_FIELD_BITPOS (type, i); | |
784 | } | |
785 | ||
786 | /* Set unsigned indicator if warranted. */ | |
c5aa993b | 787 | if (*lowp >= 0) |
c906108c SS |
788 | { |
789 | TYPE_FLAGS (type) |= TYPE_FLAG_UNSIGNED; | |
790 | } | |
791 | } | |
792 | else | |
793 | { | |
794 | *lowp = 0; | |
795 | *highp = -1; | |
796 | } | |
797 | return 0; | |
798 | case TYPE_CODE_BOOL: | |
799 | *lowp = 0; | |
800 | *highp = 1; | |
801 | return 0; | |
802 | case TYPE_CODE_INT: | |
c5aa993b | 803 | if (TYPE_LENGTH (type) > sizeof (LONGEST)) /* Too big */ |
c906108c SS |
804 | return -1; |
805 | if (!TYPE_UNSIGNED (type)) | |
806 | { | |
c5aa993b | 807 | *lowp = -(1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1)); |
c906108c SS |
808 | *highp = -*lowp - 1; |
809 | return 0; | |
810 | } | |
811 | /* ... fall through for unsigned ints ... */ | |
812 | case TYPE_CODE_CHAR: | |
813 | *lowp = 0; | |
814 | /* This round-about calculation is to avoid shifting by | |
7b83ea04 AC |
815 | TYPE_LENGTH (type) * TARGET_CHAR_BIT, which will not work |
816 | if TYPE_LENGTH (type) == sizeof (LONGEST). */ | |
c906108c SS |
817 | *highp = 1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1); |
818 | *highp = (*highp - 1) | *highp; | |
819 | return 0; | |
820 | default: | |
821 | return -1; | |
822 | } | |
823 | } | |
824 | ||
825 | /* Create an array type using either a blank type supplied in RESULT_TYPE, | |
826 | or creating a new type, inheriting the objfile from RANGE_TYPE. | |
827 | ||
828 | Elements will be of type ELEMENT_TYPE, the indices will be of type | |
829 | RANGE_TYPE. | |
830 | ||
831 | FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make | |
832 | sure it is TYPE_CODE_UNDEF before we bash it into an array type? */ | |
833 | ||
834 | struct type * | |
fba45db2 KB |
835 | create_array_type (struct type *result_type, struct type *element_type, |
836 | struct type *range_type) | |
c906108c SS |
837 | { |
838 | LONGEST low_bound, high_bound; | |
839 | ||
840 | if (result_type == NULL) | |
841 | { | |
842 | result_type = alloc_type (TYPE_OBJFILE (range_type)); | |
843 | } | |
844 | TYPE_CODE (result_type) = TYPE_CODE_ARRAY; | |
845 | TYPE_TARGET_TYPE (result_type) = element_type; | |
846 | if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0) | |
847 | low_bound = high_bound = 0; | |
848 | CHECK_TYPEDEF (element_type); | |
849 | TYPE_LENGTH (result_type) = | |
850 | TYPE_LENGTH (element_type) * (high_bound - low_bound + 1); | |
851 | TYPE_NFIELDS (result_type) = 1; | |
852 | TYPE_FIELDS (result_type) = | |
853 | (struct field *) TYPE_ALLOC (result_type, sizeof (struct field)); | |
854 | memset (TYPE_FIELDS (result_type), 0, sizeof (struct field)); | |
855 | TYPE_FIELD_TYPE (result_type, 0) = range_type; | |
856 | TYPE_VPTR_FIELDNO (result_type) = -1; | |
857 | ||
858 | /* TYPE_FLAG_TARGET_STUB will take care of zero length arrays */ | |
859 | if (TYPE_LENGTH (result_type) == 0) | |
860 | TYPE_FLAGS (result_type) |= TYPE_FLAG_TARGET_STUB; | |
861 | ||
862 | return (result_type); | |
863 | } | |
864 | ||
865 | /* Create a string type using either a blank type supplied in RESULT_TYPE, | |
866 | or creating a new type. String types are similar enough to array of | |
867 | char types that we can use create_array_type to build the basic type | |
868 | and then bash it into a string type. | |
869 | ||
870 | For fixed length strings, the range type contains 0 as the lower | |
871 | bound and the length of the string minus one as the upper bound. | |
872 | ||
873 | FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make | |
874 | sure it is TYPE_CODE_UNDEF before we bash it into a string type? */ | |
875 | ||
876 | struct type * | |
fba45db2 | 877 | create_string_type (struct type *result_type, struct type *range_type) |
c906108c | 878 | { |
f290d38e AC |
879 | struct type *string_char_type; |
880 | ||
881 | string_char_type = language_string_char_type (current_language, | |
882 | current_gdbarch); | |
c906108c | 883 | result_type = create_array_type (result_type, |
f290d38e | 884 | string_char_type, |
c906108c SS |
885 | range_type); |
886 | TYPE_CODE (result_type) = TYPE_CODE_STRING; | |
887 | return (result_type); | |
888 | } | |
889 | ||
890 | struct type * | |
fba45db2 | 891 | create_set_type (struct type *result_type, struct type *domain_type) |
c906108c SS |
892 | { |
893 | LONGEST low_bound, high_bound, bit_length; | |
894 | if (result_type == NULL) | |
895 | { | |
896 | result_type = alloc_type (TYPE_OBJFILE (domain_type)); | |
897 | } | |
898 | TYPE_CODE (result_type) = TYPE_CODE_SET; | |
899 | TYPE_NFIELDS (result_type) = 1; | |
900 | TYPE_FIELDS (result_type) = (struct field *) | |
901 | TYPE_ALLOC (result_type, 1 * sizeof (struct field)); | |
902 | memset (TYPE_FIELDS (result_type), 0, sizeof (struct field)); | |
903 | ||
74a9bb82 | 904 | if (!TYPE_STUB (domain_type)) |
c906108c SS |
905 | { |
906 | if (get_discrete_bounds (domain_type, &low_bound, &high_bound) < 0) | |
907 | low_bound = high_bound = 0; | |
908 | bit_length = high_bound - low_bound + 1; | |
909 | TYPE_LENGTH (result_type) | |
910 | = (bit_length + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT; | |
911 | } | |
912 | TYPE_FIELD_TYPE (result_type, 0) = domain_type; | |
913 | ||
c5aa993b | 914 | if (low_bound >= 0) |
c906108c SS |
915 | TYPE_FLAGS (result_type) |= TYPE_FLAG_UNSIGNED; |
916 | ||
917 | return (result_type); | |
918 | } | |
919 | ||
4f2aea11 MK |
920 | void |
921 | append_flags_type_flag (struct type *type, int bitpos, char *name) | |
922 | { | |
923 | gdb_assert (TYPE_CODE (type) == TYPE_CODE_FLAGS); | |
924 | gdb_assert (bitpos < TYPE_NFIELDS (type)); | |
925 | gdb_assert (bitpos >= 0); | |
926 | ||
927 | if (name) | |
928 | { | |
929 | TYPE_FIELD_NAME (type, bitpos) = xstrdup (name); | |
930 | TYPE_FIELD_BITPOS (type, bitpos) = bitpos; | |
931 | } | |
932 | else | |
933 | { | |
934 | /* Don't show this field to the user. */ | |
935 | TYPE_FIELD_BITPOS (type, bitpos) = -1; | |
936 | } | |
937 | } | |
938 | ||
939 | struct type * | |
940 | init_flags_type (char *name, int length) | |
941 | { | |
942 | int nfields = length * TARGET_CHAR_BIT; | |
943 | struct type *type; | |
944 | ||
945 | type = init_type (TYPE_CODE_FLAGS, length, TYPE_FLAG_UNSIGNED, name, NULL); | |
946 | TYPE_NFIELDS (type) = nfields; | |
947 | TYPE_FIELDS (type) = TYPE_ALLOC (type, nfields * sizeof (struct field)); | |
76b7178d | 948 | memset (TYPE_FIELDS (type), 0, nfields * sizeof (struct field)); |
4f2aea11 MK |
949 | |
950 | return type; | |
951 | } | |
952 | ||
917317f4 JM |
953 | /* Construct and return a type of the form: |
954 | struct NAME { ELT_TYPE ELT_NAME[N]; } | |
955 | We use these types for SIMD registers. For example, the type of | |
956 | the SSE registers on the late x86-family processors is: | |
957 | struct __builtin_v4sf { float f[4]; } | |
958 | built by the function call: | |
959 | init_simd_type ("__builtin_v4sf", builtin_type_float, "f", 4) | |
960 | The type returned is a permanent type, allocated using malloc; it | |
961 | doesn't live in any objfile's obstack. */ | |
c2d11a7d | 962 | static struct type * |
917317f4 JM |
963 | init_simd_type (char *name, |
964 | struct type *elt_type, | |
965 | char *elt_name, | |
966 | int n) | |
967 | { | |
73d322b1 EZ |
968 | struct type *simd_type; |
969 | struct type *array_type; | |
970 | ||
971 | simd_type = init_composite_type (name, TYPE_CODE_STRUCT); | |
972 | array_type = create_array_type (0, elt_type, | |
973 | create_range_type (0, builtin_type_int, | |
974 | 0, n-1)); | |
975 | append_composite_type_field (simd_type, elt_name, array_type); | |
976 | return simd_type; | |
917317f4 JM |
977 | } |
978 | ||
ac3aafc7 EZ |
979 | static struct type * |
980 | init_vector_type (struct type *elt_type, int n) | |
981 | { | |
982 | struct type *array_type; | |
983 | ||
984 | array_type = create_array_type (0, elt_type, | |
985 | create_range_type (0, builtin_type_int, | |
986 | 0, n-1)); | |
987 | TYPE_FLAGS (array_type) |= TYPE_FLAG_VECTOR; | |
988 | return array_type; | |
989 | } | |
990 | ||
b063e7a2 AC |
991 | static struct type * |
992 | build_builtin_type_vec64 (void) | |
993 | { | |
994 | /* Construct a type for the 64 bit registers. The type we're | |
995 | building is this: */ | |
996 | #if 0 | |
997 | union __gdb_builtin_type_vec64 | |
998 | { | |
999 | int64_t uint64; | |
1000 | float v2_float[2]; | |
1001 | int32_t v2_int32[2]; | |
1002 | int16_t v4_int16[4]; | |
1003 | int8_t v8_int8[8]; | |
1004 | }; | |
1005 | #endif | |
1006 | ||
1007 | struct type *t; | |
1008 | ||
1009 | t = init_composite_type ("__gdb_builtin_type_vec64", TYPE_CODE_UNION); | |
1010 | append_composite_type_field (t, "uint64", builtin_type_int64); | |
1011 | append_composite_type_field (t, "v2_float", builtin_type_v2_float); | |
1012 | append_composite_type_field (t, "v2_int32", builtin_type_v2_int32); | |
1013 | append_composite_type_field (t, "v4_int16", builtin_type_v4_int16); | |
1014 | append_composite_type_field (t, "v8_int8", builtin_type_v8_int8); | |
1015 | ||
1016 | TYPE_FLAGS (t) |= TYPE_FLAG_VECTOR; | |
216b504f | 1017 | TYPE_NAME (t) = "builtin_type_vec64"; |
b063e7a2 AC |
1018 | return t; |
1019 | } | |
1020 | ||
08cf96df EZ |
1021 | static struct type * |
1022 | build_builtin_type_vec128 (void) | |
1023 | { | |
1024 | /* Construct a type for the 128 bit registers. The type we're | |
1025 | building is this: */ | |
1026 | #if 0 | |
ac3aafc7 | 1027 | union __gdb_builtin_type_vec128 |
08cf96df | 1028 | { |
ac3aafc7 EZ |
1029 | int128_t uint128; |
1030 | float v4_float[4]; | |
1031 | int32_t v4_int32[4]; | |
1032 | int16_t v8_int16[8]; | |
1033 | int8_t v16_int8[16]; | |
08cf96df EZ |
1034 | }; |
1035 | #endif | |
1036 | ||
1037 | struct type *t; | |
08cf96df | 1038 | |
73d322b1 EZ |
1039 | t = init_composite_type ("__gdb_builtin_type_vec128", TYPE_CODE_UNION); |
1040 | append_composite_type_field (t, "uint128", builtin_type_int128); | |
ac3aafc7 EZ |
1041 | append_composite_type_field (t, "v4_float", builtin_type_v4_float); |
1042 | append_composite_type_field (t, "v4_int32", builtin_type_v4_int32); | |
1043 | append_composite_type_field (t, "v8_int16", builtin_type_v8_int16); | |
1044 | append_composite_type_field (t, "v16_int8", builtin_type_v16_int8); | |
08cf96df | 1045 | |
b063e7a2 | 1046 | TYPE_FLAGS (t) |= TYPE_FLAG_VECTOR; |
216b504f | 1047 | TYPE_NAME (t) = "builtin_type_vec128"; |
08cf96df EZ |
1048 | return t; |
1049 | } | |
917317f4 | 1050 | |
0d5de010 DJ |
1051 | /* Smash TYPE to be a type of pointers to members of DOMAIN with type |
1052 | TO_TYPE. A member pointer is a wierd thing -- it amounts to a | |
1053 | typed offset into a struct, e.g. "an int at offset 8". A MEMBER | |
1054 | TYPE doesn't include the offset (that's the value of the MEMBER | |
1055 | itself), but does include the structure type into which it points | |
1056 | (for some reason). | |
c906108c SS |
1057 | |
1058 | When "smashing" the type, we preserve the objfile that the | |
1059 | old type pointed to, since we aren't changing where the type is actually | |
1060 | allocated. */ | |
1061 | ||
1062 | void | |
0d5de010 DJ |
1063 | smash_to_memberptr_type (struct type *type, struct type *domain, |
1064 | struct type *to_type) | |
c906108c SS |
1065 | { |
1066 | struct objfile *objfile; | |
1067 | ||
1068 | objfile = TYPE_OBJFILE (type); | |
1069 | ||
2fdde8f8 | 1070 | smash_type (type); |
c906108c SS |
1071 | TYPE_OBJFILE (type) = objfile; |
1072 | TYPE_TARGET_TYPE (type) = to_type; | |
1073 | TYPE_DOMAIN_TYPE (type) = domain; | |
0d5de010 DJ |
1074 | /* Assume that a data member pointer is the same size as a normal |
1075 | pointer. */ | |
819844ad | 1076 | TYPE_LENGTH (type) = gdbarch_ptr_bit (current_gdbarch) / TARGET_CHAR_BIT; |
0d5de010 | 1077 | TYPE_CODE (type) = TYPE_CODE_MEMBERPTR; |
c906108c SS |
1078 | } |
1079 | ||
1080 | /* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE. | |
1081 | METHOD just means `function that gets an extra "this" argument'. | |
1082 | ||
1083 | When "smashing" the type, we preserve the objfile that the | |
1084 | old type pointed to, since we aren't changing where the type is actually | |
1085 | allocated. */ | |
1086 | ||
1087 | void | |
fba45db2 | 1088 | smash_to_method_type (struct type *type, struct type *domain, |
ad2f7632 DJ |
1089 | struct type *to_type, struct field *args, |
1090 | int nargs, int varargs) | |
c906108c SS |
1091 | { |
1092 | struct objfile *objfile; | |
1093 | ||
1094 | objfile = TYPE_OBJFILE (type); | |
1095 | ||
2fdde8f8 | 1096 | smash_type (type); |
c906108c SS |
1097 | TYPE_OBJFILE (type) = objfile; |
1098 | TYPE_TARGET_TYPE (type) = to_type; | |
1099 | TYPE_DOMAIN_TYPE (type) = domain; | |
ad2f7632 DJ |
1100 | TYPE_FIELDS (type) = args; |
1101 | TYPE_NFIELDS (type) = nargs; | |
1102 | if (varargs) | |
1103 | TYPE_FLAGS (type) |= TYPE_FLAG_VARARGS; | |
c906108c SS |
1104 | TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */ |
1105 | TYPE_CODE (type) = TYPE_CODE_METHOD; | |
1106 | } | |
1107 | ||
1108 | /* Return a typename for a struct/union/enum type without "struct ", | |
1109 | "union ", or "enum ". If the type has a NULL name, return NULL. */ | |
1110 | ||
1111 | char * | |
aa1ee363 | 1112 | type_name_no_tag (const struct type *type) |
c906108c SS |
1113 | { |
1114 | if (TYPE_TAG_NAME (type) != NULL) | |
1115 | return TYPE_TAG_NAME (type); | |
1116 | ||
1117 | /* Is there code which expects this to return the name if there is no | |
1118 | tag name? My guess is that this is mainly used for C++ in cases where | |
1119 | the two will always be the same. */ | |
1120 | return TYPE_NAME (type); | |
1121 | } | |
1122 | ||
c906108c SS |
1123 | /* Lookup a typedef or primitive type named NAME, |
1124 | visible in lexical block BLOCK. | |
1125 | If NOERR is nonzero, return zero if NAME is not suitably defined. */ | |
1126 | ||
1127 | struct type * | |
fba45db2 | 1128 | lookup_typename (char *name, struct block *block, int noerr) |
c906108c | 1129 | { |
52f0bd74 AC |
1130 | struct symbol *sym; |
1131 | struct type *tmp; | |
c906108c | 1132 | |
176620f1 | 1133 | sym = lookup_symbol (name, block, VAR_DOMAIN, 0, (struct symtab **) NULL); |
c906108c SS |
1134 | if (sym == NULL || SYMBOL_CLASS (sym) != LOC_TYPEDEF) |
1135 | { | |
54a5b07d AC |
1136 | tmp = language_lookup_primitive_type_by_name (current_language, |
1137 | current_gdbarch, | |
1138 | name); | |
c906108c SS |
1139 | if (tmp) |
1140 | { | |
1141 | return (tmp); | |
1142 | } | |
1143 | else if (!tmp && noerr) | |
1144 | { | |
1145 | return (NULL); | |
1146 | } | |
1147 | else | |
1148 | { | |
8a3fe4f8 | 1149 | error (_("No type named %s."), name); |
c906108c SS |
1150 | } |
1151 | } | |
1152 | return (SYMBOL_TYPE (sym)); | |
1153 | } | |
1154 | ||
1155 | struct type * | |
fba45db2 | 1156 | lookup_unsigned_typename (char *name) |
c906108c SS |
1157 | { |
1158 | char *uns = alloca (strlen (name) + 10); | |
1159 | ||
1160 | strcpy (uns, "unsigned "); | |
1161 | strcpy (uns + 9, name); | |
1162 | return (lookup_typename (uns, (struct block *) NULL, 0)); | |
1163 | } | |
1164 | ||
1165 | struct type * | |
fba45db2 | 1166 | lookup_signed_typename (char *name) |
c906108c SS |
1167 | { |
1168 | struct type *t; | |
1169 | char *uns = alloca (strlen (name) + 8); | |
1170 | ||
1171 | strcpy (uns, "signed "); | |
1172 | strcpy (uns + 7, name); | |
1173 | t = lookup_typename (uns, (struct block *) NULL, 1); | |
1174 | /* If we don't find "signed FOO" just try again with plain "FOO". */ | |
1175 | if (t != NULL) | |
1176 | return t; | |
1177 | return lookup_typename (name, (struct block *) NULL, 0); | |
1178 | } | |
1179 | ||
1180 | /* Lookup a structure type named "struct NAME", | |
1181 | visible in lexical block BLOCK. */ | |
1182 | ||
1183 | struct type * | |
fba45db2 | 1184 | lookup_struct (char *name, struct block *block) |
c906108c | 1185 | { |
52f0bd74 | 1186 | struct symbol *sym; |
c906108c | 1187 | |
176620f1 | 1188 | sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0, |
c906108c SS |
1189 | (struct symtab **) NULL); |
1190 | ||
1191 | if (sym == NULL) | |
1192 | { | |
8a3fe4f8 | 1193 | error (_("No struct type named %s."), name); |
c906108c SS |
1194 | } |
1195 | if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT) | |
1196 | { | |
8a3fe4f8 | 1197 | error (_("This context has class, union or enum %s, not a struct."), name); |
c906108c SS |
1198 | } |
1199 | return (SYMBOL_TYPE (sym)); | |
1200 | } | |
1201 | ||
1202 | /* Lookup a union type named "union NAME", | |
1203 | visible in lexical block BLOCK. */ | |
1204 | ||
1205 | struct type * | |
fba45db2 | 1206 | lookup_union (char *name, struct block *block) |
c906108c | 1207 | { |
52f0bd74 | 1208 | struct symbol *sym; |
c5aa993b | 1209 | struct type *t; |
c906108c | 1210 | |
176620f1 | 1211 | sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0, |
c906108c SS |
1212 | (struct symtab **) NULL); |
1213 | ||
1214 | if (sym == NULL) | |
8a3fe4f8 | 1215 | error (_("No union type named %s."), name); |
c906108c | 1216 | |
c5aa993b | 1217 | t = SYMBOL_TYPE (sym); |
c906108c SS |
1218 | |
1219 | if (TYPE_CODE (t) == TYPE_CODE_UNION) | |
1220 | return (t); | |
1221 | ||
1222 | /* C++ unions may come out with TYPE_CODE_CLASS, but we look at | |
1223 | * a further "declared_type" field to discover it is really a union. | |
1224 | */ | |
c5aa993b JM |
1225 | if (HAVE_CPLUS_STRUCT (t)) |
1226 | if (TYPE_DECLARED_TYPE (t) == DECLARED_TYPE_UNION) | |
c906108c SS |
1227 | return (t); |
1228 | ||
1229 | /* If we get here, it's not a union */ | |
8a3fe4f8 | 1230 | error (_("This context has class, struct or enum %s, not a union."), name); |
c906108c SS |
1231 | } |
1232 | ||
1233 | ||
1234 | /* Lookup an enum type named "enum NAME", | |
1235 | visible in lexical block BLOCK. */ | |
1236 | ||
1237 | struct type * | |
fba45db2 | 1238 | lookup_enum (char *name, struct block *block) |
c906108c | 1239 | { |
52f0bd74 | 1240 | struct symbol *sym; |
c906108c | 1241 | |
176620f1 | 1242 | sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0, |
c906108c SS |
1243 | (struct symtab **) NULL); |
1244 | if (sym == NULL) | |
1245 | { | |
8a3fe4f8 | 1246 | error (_("No enum type named %s."), name); |
c906108c SS |
1247 | } |
1248 | if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_ENUM) | |
1249 | { | |
8a3fe4f8 | 1250 | error (_("This context has class, struct or union %s, not an enum."), name); |
c906108c SS |
1251 | } |
1252 | return (SYMBOL_TYPE (sym)); | |
1253 | } | |
1254 | ||
1255 | /* Lookup a template type named "template NAME<TYPE>", | |
1256 | visible in lexical block BLOCK. */ | |
1257 | ||
1258 | struct type * | |
fba45db2 | 1259 | lookup_template_type (char *name, struct type *type, struct block *block) |
c906108c SS |
1260 | { |
1261 | struct symbol *sym; | |
0004e5a2 | 1262 | char *nam = (char *) alloca (strlen (name) + strlen (TYPE_NAME (type)) + 4); |
c906108c SS |
1263 | strcpy (nam, name); |
1264 | strcat (nam, "<"); | |
0004e5a2 | 1265 | strcat (nam, TYPE_NAME (type)); |
c5aa993b | 1266 | strcat (nam, " >"); /* FIXME, extra space still introduced in gcc? */ |
c906108c | 1267 | |
176620f1 | 1268 | sym = lookup_symbol (nam, block, VAR_DOMAIN, 0, (struct symtab **) NULL); |
c906108c SS |
1269 | |
1270 | if (sym == NULL) | |
1271 | { | |
8a3fe4f8 | 1272 | error (_("No template type named %s."), name); |
c906108c SS |
1273 | } |
1274 | if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT) | |
1275 | { | |
8a3fe4f8 | 1276 | error (_("This context has class, union or enum %s, not a struct."), name); |
c906108c SS |
1277 | } |
1278 | return (SYMBOL_TYPE (sym)); | |
1279 | } | |
1280 | ||
7b83ea04 | 1281 | /* Given a type TYPE, lookup the type of the component of type named NAME. |
c906108c SS |
1282 | |
1283 | TYPE can be either a struct or union, or a pointer or reference to a struct or | |
1284 | union. If it is a pointer or reference, its target type is automatically used. | |
1285 | Thus '.' and '->' are interchangable, as specified for the definitions of the | |
1286 | expression element types STRUCTOP_STRUCT and STRUCTOP_PTR. | |
1287 | ||
1288 | If NOERR is nonzero, return zero if NAME is not suitably defined. | |
1289 | If NAME is the name of a baseclass type, return that type. */ | |
1290 | ||
1291 | struct type * | |
fba45db2 | 1292 | lookup_struct_elt_type (struct type *type, char *name, int noerr) |
c906108c SS |
1293 | { |
1294 | int i; | |
1295 | ||
1296 | for (;;) | |
1297 | { | |
1298 | CHECK_TYPEDEF (type); | |
1299 | if (TYPE_CODE (type) != TYPE_CODE_PTR | |
1300 | && TYPE_CODE (type) != TYPE_CODE_REF) | |
1301 | break; | |
1302 | type = TYPE_TARGET_TYPE (type); | |
1303 | } | |
1304 | ||
1305 | if (TYPE_CODE (type) != TYPE_CODE_STRUCT && | |
1306 | TYPE_CODE (type) != TYPE_CODE_UNION) | |
1307 | { | |
1308 | target_terminal_ours (); | |
1309 | gdb_flush (gdb_stdout); | |
1310 | fprintf_unfiltered (gdb_stderr, "Type "); | |
1311 | type_print (type, "", gdb_stderr, -1); | |
8a3fe4f8 | 1312 | error (_(" is not a structure or union type.")); |
c906108c SS |
1313 | } |
1314 | ||
1315 | #if 0 | |
1316 | /* FIXME: This change put in by Michael seems incorrect for the case where | |
1317 | the structure tag name is the same as the member name. I.E. when doing | |
1318 | "ptype bell->bar" for "struct foo { int bar; int foo; } bell;" | |
1319 | Disabled by fnf. */ | |
1320 | { | |
1321 | char *typename; | |
1322 | ||
1323 | typename = type_name_no_tag (type); | |
762f08a3 | 1324 | if (typename != NULL && strcmp (typename, name) == 0) |
c906108c SS |
1325 | return type; |
1326 | } | |
1327 | #endif | |
1328 | ||
1329 | for (i = TYPE_NFIELDS (type) - 1; i >= TYPE_N_BASECLASSES (type); i--) | |
1330 | { | |
1331 | char *t_field_name = TYPE_FIELD_NAME (type, i); | |
1332 | ||
db577aea | 1333 | if (t_field_name && (strcmp_iw (t_field_name, name) == 0)) |
c906108c SS |
1334 | { |
1335 | return TYPE_FIELD_TYPE (type, i); | |
1336 | } | |
1337 | } | |
1338 | ||
1339 | /* OK, it's not in this class. Recursively check the baseclasses. */ | |
1340 | for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--) | |
1341 | { | |
1342 | struct type *t; | |
1343 | ||
9733fc94 | 1344 | t = lookup_struct_elt_type (TYPE_BASECLASS (type, i), name, 1); |
c906108c SS |
1345 | if (t != NULL) |
1346 | { | |
1347 | return t; | |
1348 | } | |
1349 | } | |
1350 | ||
1351 | if (noerr) | |
1352 | { | |
1353 | return NULL; | |
1354 | } | |
c5aa993b | 1355 | |
c906108c SS |
1356 | target_terminal_ours (); |
1357 | gdb_flush (gdb_stdout); | |
1358 | fprintf_unfiltered (gdb_stderr, "Type "); | |
1359 | type_print (type, "", gdb_stderr, -1); | |
1360 | fprintf_unfiltered (gdb_stderr, " has no component named "); | |
1361 | fputs_filtered (name, gdb_stderr); | |
8a3fe4f8 | 1362 | error ((".")); |
c5aa993b | 1363 | return (struct type *) -1; /* For lint */ |
c906108c SS |
1364 | } |
1365 | ||
1366 | /* If possible, make the vptr_fieldno and vptr_basetype fields of TYPE | |
1367 | valid. Callers should be aware that in some cases (for example, | |
1368 | the type or one of its baseclasses is a stub type and we are | |
1369 | debugging a .o file), this function will not be able to find the virtual | |
1370 | function table pointer, and vptr_fieldno will remain -1 and vptr_basetype | |
1371 | will remain NULL. */ | |
1372 | ||
1373 | void | |
fba45db2 | 1374 | fill_in_vptr_fieldno (struct type *type) |
c906108c SS |
1375 | { |
1376 | CHECK_TYPEDEF (type); | |
1377 | ||
1378 | if (TYPE_VPTR_FIELDNO (type) < 0) | |
1379 | { | |
1380 | int i; | |
1381 | ||
1382 | /* We must start at zero in case the first (and only) baseclass is | |
7b83ea04 | 1383 | virtual (and hence we cannot share the table pointer). */ |
c906108c SS |
1384 | for (i = 0; i < TYPE_N_BASECLASSES (type); i++) |
1385 | { | |
cef4f5dd DJ |
1386 | struct type *baseclass = check_typedef (TYPE_BASECLASS (type, i)); |
1387 | fill_in_vptr_fieldno (baseclass); | |
1388 | if (TYPE_VPTR_FIELDNO (baseclass) >= 0) | |
c906108c | 1389 | { |
cef4f5dd DJ |
1390 | TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (baseclass); |
1391 | TYPE_VPTR_BASETYPE (type) = TYPE_VPTR_BASETYPE (baseclass); | |
c906108c SS |
1392 | break; |
1393 | } | |
1394 | } | |
1395 | } | |
1396 | } | |
1397 | ||
1398 | /* Find the method and field indices for the destructor in class type T. | |
1399 | Return 1 if the destructor was found, otherwise, return 0. */ | |
1400 | ||
1401 | int | |
fba45db2 | 1402 | get_destructor_fn_field (struct type *t, int *method_indexp, int *field_indexp) |
c906108c SS |
1403 | { |
1404 | int i; | |
1405 | ||
1406 | for (i = 0; i < TYPE_NFN_FIELDS (t); i++) | |
1407 | { | |
1408 | int j; | |
1409 | struct fn_field *f = TYPE_FN_FIELDLIST1 (t, i); | |
1410 | ||
1411 | for (j = 0; j < TYPE_FN_FIELDLIST_LENGTH (t, i); j++) | |
1412 | { | |
015a42b4 | 1413 | if (is_destructor_name (TYPE_FN_FIELD_PHYSNAME (f, j)) != 0) |
c906108c SS |
1414 | { |
1415 | *method_indexp = i; | |
1416 | *field_indexp = j; | |
1417 | return 1; | |
1418 | } | |
1419 | } | |
1420 | } | |
1421 | return 0; | |
1422 | } | |
1423 | ||
44e1a9eb DJ |
1424 | static void |
1425 | stub_noname_complaint (void) | |
1426 | { | |
e2e0b3e5 | 1427 | complaint (&symfile_complaints, _("stub type has NULL name")); |
44e1a9eb DJ |
1428 | } |
1429 | ||
c906108c SS |
1430 | /* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989. |
1431 | ||
1432 | If this is a stubbed struct (i.e. declared as struct foo *), see if | |
1433 | we can find a full definition in some other file. If so, copy this | |
1434 | definition, so we can use it in future. There used to be a comment (but | |
1435 | not any code) that if we don't find a full definition, we'd set a flag | |
1436 | so we don't spend time in the future checking the same type. That would | |
1437 | be a mistake, though--we might load in more symbols which contain a | |
1438 | full definition for the type. | |
1439 | ||
7b83ea04 | 1440 | This used to be coded as a macro, but I don't think it is called |
c906108c SS |
1441 | often enough to merit such treatment. */ |
1442 | ||
44e1a9eb DJ |
1443 | /* Find the real type of TYPE. This function returns the real type, after |
1444 | removing all layers of typedefs and completing opaque or stub types. | |
1445 | Completion changes the TYPE argument, but stripping of typedefs does | |
1446 | not. */ | |
c906108c SS |
1447 | |
1448 | struct type * | |
a02fd225 | 1449 | check_typedef (struct type *type) |
c906108c SS |
1450 | { |
1451 | struct type *orig_type = type; | |
a02fd225 DJ |
1452 | int is_const, is_volatile; |
1453 | ||
c906108c SS |
1454 | while (TYPE_CODE (type) == TYPE_CODE_TYPEDEF) |
1455 | { | |
1456 | if (!TYPE_TARGET_TYPE (type)) | |
1457 | { | |
c5aa993b | 1458 | char *name; |
c906108c SS |
1459 | struct symbol *sym; |
1460 | ||
1461 | /* It is dangerous to call lookup_symbol if we are currently | |
1462 | reading a symtab. Infinite recursion is one danger. */ | |
1463 | if (currently_reading_symtab) | |
1464 | return type; | |
1465 | ||
1466 | name = type_name_no_tag (type); | |
1467 | /* FIXME: shouldn't we separately check the TYPE_NAME and the | |
176620f1 | 1468 | TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or VAR_DOMAIN |
c906108c SS |
1469 | as appropriate? (this code was written before TYPE_NAME and |
1470 | TYPE_TAG_NAME were separate). */ | |
1471 | if (name == NULL) | |
1472 | { | |
23136709 | 1473 | stub_noname_complaint (); |
c906108c SS |
1474 | return type; |
1475 | } | |
176620f1 | 1476 | sym = lookup_symbol (name, 0, STRUCT_DOMAIN, 0, |
c906108c SS |
1477 | (struct symtab **) NULL); |
1478 | if (sym) | |
1479 | TYPE_TARGET_TYPE (type) = SYMBOL_TYPE (sym); | |
1480 | else | |
c5aa993b | 1481 | TYPE_TARGET_TYPE (type) = alloc_type (NULL); /* TYPE_CODE_UNDEF */ |
c906108c SS |
1482 | } |
1483 | type = TYPE_TARGET_TYPE (type); | |
1484 | } | |
1485 | ||
a02fd225 DJ |
1486 | is_const = TYPE_CONST (type); |
1487 | is_volatile = TYPE_VOLATILE (type); | |
1488 | ||
c906108c SS |
1489 | /* If this is a struct/class/union with no fields, then check whether a |
1490 | full definition exists somewhere else. This is for systems where a | |
1491 | type definition with no fields is issued for such types, instead of | |
c5aa993b JM |
1492 | identifying them as stub types in the first place */ |
1493 | ||
c906108c SS |
1494 | if (TYPE_IS_OPAQUE (type) && opaque_type_resolution && !currently_reading_symtab) |
1495 | { | |
c5aa993b JM |
1496 | char *name = type_name_no_tag (type); |
1497 | struct type *newtype; | |
c906108c SS |
1498 | if (name == NULL) |
1499 | { | |
23136709 | 1500 | stub_noname_complaint (); |
c906108c SS |
1501 | return type; |
1502 | } | |
1503 | newtype = lookup_transparent_type (name); | |
ad766c0a | 1504 | |
c906108c | 1505 | if (newtype) |
ad766c0a JB |
1506 | { |
1507 | /* If the resolved type and the stub are in the same objfile, | |
1508 | then replace the stub type with the real deal. But if | |
1509 | they're in separate objfiles, leave the stub alone; we'll | |
1510 | just look up the transparent type every time we call | |
1511 | check_typedef. We can't create pointers between types | |
1512 | allocated to different objfiles, since they may have | |
1513 | different lifetimes. Trying to copy NEWTYPE over to TYPE's | |
1514 | objfile is pointless, too, since you'll have to move over any | |
1515 | other types NEWTYPE refers to, which could be an unbounded | |
1516 | amount of stuff. */ | |
1517 | if (TYPE_OBJFILE (newtype) == TYPE_OBJFILE (type)) | |
1518 | make_cv_type (is_const, is_volatile, newtype, &type); | |
1519 | else | |
1520 | type = newtype; | |
1521 | } | |
c906108c SS |
1522 | } |
1523 | /* Otherwise, rely on the stub flag being set for opaque/stubbed types */ | |
74a9bb82 | 1524 | else if (TYPE_STUB (type) && !currently_reading_symtab) |
c906108c | 1525 | { |
c5aa993b | 1526 | char *name = type_name_no_tag (type); |
c906108c | 1527 | /* FIXME: shouldn't we separately check the TYPE_NAME and the |
176620f1 | 1528 | TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or VAR_DOMAIN |
7b83ea04 AC |
1529 | as appropriate? (this code was written before TYPE_NAME and |
1530 | TYPE_TAG_NAME were separate). */ | |
c906108c SS |
1531 | struct symbol *sym; |
1532 | if (name == NULL) | |
1533 | { | |
23136709 | 1534 | stub_noname_complaint (); |
c906108c SS |
1535 | return type; |
1536 | } | |
176620f1 | 1537 | sym = lookup_symbol (name, 0, STRUCT_DOMAIN, 0, (struct symtab **) NULL); |
c906108c | 1538 | if (sym) |
c26f2453 JB |
1539 | { |
1540 | /* Same as above for opaque types, we can replace the stub | |
1541 | with the complete type only if they are int the same | |
1542 | objfile. */ | |
1543 | if (TYPE_OBJFILE (SYMBOL_TYPE(sym)) == TYPE_OBJFILE (type)) | |
1544 | make_cv_type (is_const, is_volatile, SYMBOL_TYPE (sym), &type); | |
1545 | else | |
1546 | type = SYMBOL_TYPE (sym); | |
1547 | } | |
c906108c SS |
1548 | } |
1549 | ||
74a9bb82 | 1550 | if (TYPE_TARGET_STUB (type)) |
c906108c SS |
1551 | { |
1552 | struct type *range_type; | |
1553 | struct type *target_type = check_typedef (TYPE_TARGET_TYPE (type)); | |
1554 | ||
74a9bb82 | 1555 | if (TYPE_STUB (target_type) || TYPE_TARGET_STUB (target_type)) |
c5aa993b JM |
1556 | { |
1557 | } | |
c906108c SS |
1558 | else if (TYPE_CODE (type) == TYPE_CODE_ARRAY |
1559 | && TYPE_NFIELDS (type) == 1 | |
1560 | && (TYPE_CODE (range_type = TYPE_FIELD_TYPE (type, 0)) | |
1561 | == TYPE_CODE_RANGE)) | |
1562 | { | |
1563 | /* Now recompute the length of the array type, based on its | |
1564 | number of elements and the target type's length. */ | |
1565 | TYPE_LENGTH (type) = | |
1566 | ((TYPE_FIELD_BITPOS (range_type, 1) | |
1567 | - TYPE_FIELD_BITPOS (range_type, 0) | |
1568 | + 1) | |
1569 | * TYPE_LENGTH (target_type)); | |
1570 | TYPE_FLAGS (type) &= ~TYPE_FLAG_TARGET_STUB; | |
1571 | } | |
1572 | else if (TYPE_CODE (type) == TYPE_CODE_RANGE) | |
1573 | { | |
1574 | TYPE_LENGTH (type) = TYPE_LENGTH (target_type); | |
1575 | TYPE_FLAGS (type) &= ~TYPE_FLAG_TARGET_STUB; | |
1576 | } | |
1577 | } | |
1578 | /* Cache TYPE_LENGTH for future use. */ | |
1579 | TYPE_LENGTH (orig_type) = TYPE_LENGTH (type); | |
1580 | return type; | |
1581 | } | |
1582 | ||
c91ecb25 ND |
1583 | /* Parse a type expression in the string [P..P+LENGTH). If an error occurs, |
1584 | silently return builtin_type_void. */ | |
1585 | ||
b9362cc7 | 1586 | static struct type * |
c91ecb25 ND |
1587 | safe_parse_type (char *p, int length) |
1588 | { | |
1589 | struct ui_file *saved_gdb_stderr; | |
1590 | struct type *type; | |
1591 | ||
1592 | /* Suppress error messages. */ | |
1593 | saved_gdb_stderr = gdb_stderr; | |
1594 | gdb_stderr = ui_file_new (); | |
1595 | ||
1596 | /* Call parse_and_eval_type() without fear of longjmp()s. */ | |
1597 | if (!gdb_parse_and_eval_type (p, length, &type)) | |
1598 | type = builtin_type_void; | |
1599 | ||
1600 | /* Stop suppressing error messages. */ | |
1601 | ui_file_delete (gdb_stderr); | |
1602 | gdb_stderr = saved_gdb_stderr; | |
1603 | ||
1604 | return type; | |
1605 | } | |
1606 | ||
c906108c SS |
1607 | /* Ugly hack to convert method stubs into method types. |
1608 | ||
1609 | He ain't kiddin'. This demangles the name of the method into a string | |
1610 | including argument types, parses out each argument type, generates | |
1611 | a string casting a zero to that type, evaluates the string, and stuffs | |
1612 | the resulting type into an argtype vector!!! Then it knows the type | |
1613 | of the whole function (including argument types for overloading), | |
1614 | which info used to be in the stab's but was removed to hack back | |
1615 | the space required for them. */ | |
1616 | ||
de17c821 | 1617 | static void |
fba45db2 | 1618 | check_stub_method (struct type *type, int method_id, int signature_id) |
c906108c SS |
1619 | { |
1620 | struct fn_field *f; | |
1621 | char *mangled_name = gdb_mangle_name (type, method_id, signature_id); | |
1622 | char *demangled_name = cplus_demangle (mangled_name, | |
1623 | DMGL_PARAMS | DMGL_ANSI); | |
1624 | char *argtypetext, *p; | |
1625 | int depth = 0, argcount = 1; | |
ad2f7632 | 1626 | struct field *argtypes; |
c906108c SS |
1627 | struct type *mtype; |
1628 | ||
1629 | /* Make sure we got back a function string that we can use. */ | |
1630 | if (demangled_name) | |
1631 | p = strchr (demangled_name, '('); | |
502dcf4e AC |
1632 | else |
1633 | p = NULL; | |
c906108c SS |
1634 | |
1635 | if (demangled_name == NULL || p == NULL) | |
8a3fe4f8 | 1636 | error (_("Internal: Cannot demangle mangled name `%s'."), mangled_name); |
c906108c SS |
1637 | |
1638 | /* Now, read in the parameters that define this type. */ | |
1639 | p += 1; | |
1640 | argtypetext = p; | |
1641 | while (*p) | |
1642 | { | |
070ad9f0 | 1643 | if (*p == '(' || *p == '<') |
c906108c SS |
1644 | { |
1645 | depth += 1; | |
1646 | } | |
070ad9f0 | 1647 | else if (*p == ')' || *p == '>') |
c906108c SS |
1648 | { |
1649 | depth -= 1; | |
1650 | } | |
1651 | else if (*p == ',' && depth == 0) | |
1652 | { | |
1653 | argcount += 1; | |
1654 | } | |
1655 | ||
1656 | p += 1; | |
1657 | } | |
1658 | ||
ad2f7632 DJ |
1659 | /* If we read one argument and it was ``void'', don't count it. */ |
1660 | if (strncmp (argtypetext, "(void)", 6) == 0) | |
1661 | argcount -= 1; | |
c906108c | 1662 | |
ad2f7632 DJ |
1663 | /* We need one extra slot, for the THIS pointer. */ |
1664 | ||
1665 | argtypes = (struct field *) | |
1666 | TYPE_ALLOC (type, (argcount + 1) * sizeof (struct field)); | |
c906108c | 1667 | p = argtypetext; |
4a1970e4 DJ |
1668 | |
1669 | /* Add THIS pointer for non-static methods. */ | |
1670 | f = TYPE_FN_FIELDLIST1 (type, method_id); | |
1671 | if (TYPE_FN_FIELD_STATIC_P (f, signature_id)) | |
1672 | argcount = 0; | |
1673 | else | |
1674 | { | |
ad2f7632 | 1675 | argtypes[0].type = lookup_pointer_type (type); |
4a1970e4 DJ |
1676 | argcount = 1; |
1677 | } | |
c906108c | 1678 | |
c5aa993b | 1679 | if (*p != ')') /* () means no args, skip while */ |
c906108c SS |
1680 | { |
1681 | depth = 0; | |
1682 | while (*p) | |
1683 | { | |
1684 | if (depth <= 0 && (*p == ',' || *p == ')')) | |
1685 | { | |
ad2f7632 DJ |
1686 | /* Avoid parsing of ellipsis, they will be handled below. |
1687 | Also avoid ``void'' as above. */ | |
1688 | if (strncmp (argtypetext, "...", p - argtypetext) != 0 | |
1689 | && strncmp (argtypetext, "void", p - argtypetext) != 0) | |
c906108c | 1690 | { |
ad2f7632 | 1691 | argtypes[argcount].type = |
c91ecb25 | 1692 | safe_parse_type (argtypetext, p - argtypetext); |
c906108c SS |
1693 | argcount += 1; |
1694 | } | |
1695 | argtypetext = p + 1; | |
1696 | } | |
1697 | ||
070ad9f0 | 1698 | if (*p == '(' || *p == '<') |
c906108c SS |
1699 | { |
1700 | depth += 1; | |
1701 | } | |
070ad9f0 | 1702 | else if (*p == ')' || *p == '>') |
c906108c SS |
1703 | { |
1704 | depth -= 1; | |
1705 | } | |
1706 | ||
1707 | p += 1; | |
1708 | } | |
1709 | } | |
1710 | ||
c906108c SS |
1711 | TYPE_FN_FIELD_PHYSNAME (f, signature_id) = mangled_name; |
1712 | ||
1713 | /* Now update the old "stub" type into a real type. */ | |
1714 | mtype = TYPE_FN_FIELD_TYPE (f, signature_id); | |
1715 | TYPE_DOMAIN_TYPE (mtype) = type; | |
ad2f7632 DJ |
1716 | TYPE_FIELDS (mtype) = argtypes; |
1717 | TYPE_NFIELDS (mtype) = argcount; | |
c906108c SS |
1718 | TYPE_FLAGS (mtype) &= ~TYPE_FLAG_STUB; |
1719 | TYPE_FN_FIELD_STUB (f, signature_id) = 0; | |
ad2f7632 DJ |
1720 | if (p[-2] == '.') |
1721 | TYPE_FLAGS (mtype) |= TYPE_FLAG_VARARGS; | |
1722 | ||
1723 | xfree (demangled_name); | |
c906108c SS |
1724 | } |
1725 | ||
de17c821 DJ |
1726 | /* This is the external interface to check_stub_method, above. This function |
1727 | unstubs all of the signatures for TYPE's METHOD_ID method name. After | |
1728 | calling this function TYPE_FN_FIELD_STUB will be cleared for each signature | |
1729 | and TYPE_FN_FIELDLIST_NAME will be correct. | |
1730 | ||
1731 | This function unfortunately can not die until stabs do. */ | |
1732 | ||
1733 | void | |
1734 | check_stub_method_group (struct type *type, int method_id) | |
1735 | { | |
1736 | int len = TYPE_FN_FIELDLIST_LENGTH (type, method_id); | |
1737 | struct fn_field *f = TYPE_FN_FIELDLIST1 (type, method_id); | |
f710f4fc | 1738 | int j, found_stub = 0; |
de17c821 DJ |
1739 | |
1740 | for (j = 0; j < len; j++) | |
1741 | if (TYPE_FN_FIELD_STUB (f, j)) | |
1742 | { | |
1743 | found_stub = 1; | |
1744 | check_stub_method (type, method_id, j); | |
1745 | } | |
1746 | ||
1747 | /* GNU v3 methods with incorrect names were corrected when we read in | |
1748 | type information, because it was cheaper to do it then. The only GNU v2 | |
1749 | methods with incorrect method names are operators and destructors; | |
1750 | destructors were also corrected when we read in type information. | |
1751 | ||
1752 | Therefore the only thing we need to handle here are v2 operator | |
1753 | names. */ | |
1754 | if (found_stub && strncmp (TYPE_FN_FIELD_PHYSNAME (f, 0), "_Z", 2) != 0) | |
1755 | { | |
1756 | int ret; | |
1757 | char dem_opname[256]; | |
1758 | ||
1759 | ret = cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type, method_id), | |
1760 | dem_opname, DMGL_ANSI); | |
1761 | if (!ret) | |
1762 | ret = cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type, method_id), | |
1763 | dem_opname, 0); | |
1764 | if (ret) | |
1765 | TYPE_FN_FIELDLIST_NAME (type, method_id) = xstrdup (dem_opname); | |
1766 | } | |
1767 | } | |
1768 | ||
c906108c SS |
1769 | const struct cplus_struct_type cplus_struct_default; |
1770 | ||
1771 | void | |
fba45db2 | 1772 | allocate_cplus_struct_type (struct type *type) |
c906108c SS |
1773 | { |
1774 | if (!HAVE_CPLUS_STRUCT (type)) | |
1775 | { | |
1776 | TYPE_CPLUS_SPECIFIC (type) = (struct cplus_struct_type *) | |
1777 | TYPE_ALLOC (type, sizeof (struct cplus_struct_type)); | |
c5aa993b | 1778 | *(TYPE_CPLUS_SPECIFIC (type)) = cplus_struct_default; |
c906108c SS |
1779 | } |
1780 | } | |
1781 | ||
1782 | /* Helper function to initialize the standard scalar types. | |
1783 | ||
1784 | If NAME is non-NULL and OBJFILE is non-NULL, then we make a copy | |
b99607ea | 1785 | of the string pointed to by name in the objfile_obstack for that objfile, |
c906108c SS |
1786 | and initialize the type name to that copy. There are places (mipsread.c |
1787 | in particular, where init_type is called with a NULL value for NAME). */ | |
1788 | ||
1789 | struct type * | |
fba45db2 KB |
1790 | init_type (enum type_code code, int length, int flags, char *name, |
1791 | struct objfile *objfile) | |
c906108c | 1792 | { |
52f0bd74 | 1793 | struct type *type; |
c906108c SS |
1794 | |
1795 | type = alloc_type (objfile); | |
1796 | TYPE_CODE (type) = code; | |
1797 | TYPE_LENGTH (type) = length; | |
1798 | TYPE_FLAGS (type) |= flags; | |
1799 | if ((name != NULL) && (objfile != NULL)) | |
1800 | { | |
1801 | TYPE_NAME (type) = | |
b99607ea | 1802 | obsavestring (name, strlen (name), &objfile->objfile_obstack); |
c906108c SS |
1803 | } |
1804 | else | |
1805 | { | |
1806 | TYPE_NAME (type) = name; | |
1807 | } | |
1808 | ||
1809 | /* C++ fancies. */ | |
1810 | ||
973ccf8b DJ |
1811 | if (name && strcmp (name, "char") == 0) |
1812 | TYPE_FLAGS (type) |= TYPE_FLAG_NOSIGN; | |
1813 | ||
5c4e30ca DC |
1814 | if (code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION |
1815 | || code == TYPE_CODE_NAMESPACE) | |
c906108c SS |
1816 | { |
1817 | INIT_CPLUS_SPECIFIC (type); | |
1818 | } | |
1819 | return (type); | |
1820 | } | |
1821 | ||
0e101458 AC |
1822 | /* Helper function. Create an empty composite type. */ |
1823 | ||
1824 | struct type * | |
1825 | init_composite_type (char *name, enum type_code code) | |
1826 | { | |
1827 | struct type *t; | |
1828 | gdb_assert (code == TYPE_CODE_STRUCT | |
1829 | || code == TYPE_CODE_UNION); | |
1830 | t = init_type (code, 0, 0, NULL, NULL); | |
1831 | TYPE_TAG_NAME (t) = name; | |
1832 | return t; | |
1833 | } | |
1834 | ||
1835 | /* Helper function. Append a field to a composite type. */ | |
1836 | ||
1837 | void | |
1838 | append_composite_type_field (struct type *t, char *name, struct type *field) | |
1839 | { | |
1840 | struct field *f; | |
1841 | TYPE_NFIELDS (t) = TYPE_NFIELDS (t) + 1; | |
1842 | TYPE_FIELDS (t) = xrealloc (TYPE_FIELDS (t), | |
1843 | sizeof (struct field) * TYPE_NFIELDS (t)); | |
1844 | f = &(TYPE_FIELDS (t)[TYPE_NFIELDS (t) - 1]); | |
1845 | memset (f, 0, sizeof f[0]); | |
1846 | FIELD_TYPE (f[0]) = field; | |
1847 | FIELD_NAME (f[0]) = name; | |
1848 | if (TYPE_CODE (t) == TYPE_CODE_UNION) | |
1849 | { | |
73d322b1 | 1850 | if (TYPE_LENGTH (t) < TYPE_LENGTH (field)) |
0e101458 AC |
1851 | TYPE_LENGTH (t) = TYPE_LENGTH (field); |
1852 | } | |
1853 | else if (TYPE_CODE (t) == TYPE_CODE_STRUCT) | |
1854 | { | |
1855 | TYPE_LENGTH (t) = TYPE_LENGTH (t) + TYPE_LENGTH (field); | |
1856 | if (TYPE_NFIELDS (t) > 1) | |
1857 | { | |
1858 | FIELD_BITPOS (f[0]) = (FIELD_BITPOS (f[-1]) | |
1859 | + TYPE_LENGTH (field) * TARGET_CHAR_BIT); | |
1860 | } | |
1861 | } | |
1862 | } | |
1863 | ||
c906108c SS |
1864 | /* Look up a fundamental type for the specified objfile. |
1865 | May need to construct such a type if this is the first use. | |
1866 | ||
1867 | Some object file formats (ELF, COFF, etc) do not define fundamental | |
1868 | types such as "int" or "double". Others (stabs for example), do | |
1869 | define fundamental types. | |
1870 | ||
1871 | For the formats which don't provide fundamental types, gdb can create | |
1872 | such types, using defaults reasonable for the current language and | |
1873 | the current target machine. | |
1874 | ||
1875 | NOTE: This routine is obsolescent. Each debugging format reader | |
1876 | should manage it's own fundamental types, either creating them from | |
1877 | suitable defaults or reading them from the debugging information, | |
1878 | whichever is appropriate. The DWARF reader has already been | |
1879 | fixed to do this. Once the other readers are fixed, this routine | |
1880 | will go away. Also note that fundamental types should be managed | |
1881 | on a compilation unit basis in a multi-language environment, not | |
1882 | on a linkage unit basis as is done here. */ | |
1883 | ||
1884 | ||
1885 | struct type * | |
fba45db2 | 1886 | lookup_fundamental_type (struct objfile *objfile, int typeid) |
c906108c | 1887 | { |
52f0bd74 AC |
1888 | struct type **typep; |
1889 | int nbytes; | |
c906108c SS |
1890 | |
1891 | if (typeid < 0 || typeid >= FT_NUM_MEMBERS) | |
1892 | { | |
8a3fe4f8 | 1893 | error (_("internal error - invalid fundamental type id %d"), typeid); |
c906108c SS |
1894 | } |
1895 | ||
1896 | /* If this is the first time we need a fundamental type for this objfile | |
1897 | then we need to initialize the vector of type pointers. */ | |
c5aa993b JM |
1898 | |
1899 | if (objfile->fundamental_types == NULL) | |
c906108c SS |
1900 | { |
1901 | nbytes = FT_NUM_MEMBERS * sizeof (struct type *); | |
c5aa993b | 1902 | objfile->fundamental_types = (struct type **) |
b99607ea | 1903 | obstack_alloc (&objfile->objfile_obstack, nbytes); |
c5aa993b | 1904 | memset ((char *) objfile->fundamental_types, 0, nbytes); |
c906108c SS |
1905 | OBJSTAT (objfile, n_types += FT_NUM_MEMBERS); |
1906 | } | |
1907 | ||
1908 | /* Look for this particular type in the fundamental type vector. If one is | |
1909 | not found, create and install one appropriate for the current language. */ | |
1910 | ||
c5aa993b | 1911 | typep = objfile->fundamental_types + typeid; |
c906108c SS |
1912 | if (*typep == NULL) |
1913 | { | |
1914 | *typep = create_fundamental_type (objfile, typeid); | |
1915 | } | |
1916 | ||
1917 | return (*typep); | |
1918 | } | |
1919 | ||
1920 | int | |
fba45db2 | 1921 | can_dereference (struct type *t) |
c906108c SS |
1922 | { |
1923 | /* FIXME: Should we return true for references as well as pointers? */ | |
1924 | CHECK_TYPEDEF (t); | |
1925 | return | |
1926 | (t != NULL | |
1927 | && TYPE_CODE (t) == TYPE_CODE_PTR | |
1928 | && TYPE_CODE (TYPE_TARGET_TYPE (t)) != TYPE_CODE_VOID); | |
1929 | } | |
1930 | ||
adf40b2e | 1931 | int |
fba45db2 | 1932 | is_integral_type (struct type *t) |
adf40b2e JM |
1933 | { |
1934 | CHECK_TYPEDEF (t); | |
1935 | return | |
1936 | ((t != NULL) | |
d4f3574e SS |
1937 | && ((TYPE_CODE (t) == TYPE_CODE_INT) |
1938 | || (TYPE_CODE (t) == TYPE_CODE_ENUM) | |
4f2aea11 | 1939 | || (TYPE_CODE (t) == TYPE_CODE_FLAGS) |
d4f3574e SS |
1940 | || (TYPE_CODE (t) == TYPE_CODE_CHAR) |
1941 | || (TYPE_CODE (t) == TYPE_CODE_RANGE) | |
1942 | || (TYPE_CODE (t) == TYPE_CODE_BOOL))); | |
adf40b2e JM |
1943 | } |
1944 | ||
7b83ea04 | 1945 | /* Check whether BASE is an ancestor or base class or DCLASS |
c906108c SS |
1946 | Return 1 if so, and 0 if not. |
1947 | Note: callers may want to check for identity of the types before | |
1948 | calling this function -- identical types are considered to satisfy | |
1949 | the ancestor relationship even if they're identical */ | |
1950 | ||
1951 | int | |
fba45db2 | 1952 | is_ancestor (struct type *base, struct type *dclass) |
c906108c SS |
1953 | { |
1954 | int i; | |
c5aa993b | 1955 | |
c906108c SS |
1956 | CHECK_TYPEDEF (base); |
1957 | CHECK_TYPEDEF (dclass); | |
1958 | ||
1959 | if (base == dclass) | |
1960 | return 1; | |
6b1ba9a0 ND |
1961 | if (TYPE_NAME (base) && TYPE_NAME (dclass) && |
1962 | !strcmp (TYPE_NAME (base), TYPE_NAME (dclass))) | |
1963 | return 1; | |
c906108c SS |
1964 | |
1965 | for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++) | |
1966 | if (is_ancestor (base, TYPE_BASECLASS (dclass, i))) | |
1967 | return 1; | |
1968 | ||
1969 | return 0; | |
1970 | } | |
1971 | ||
1972 | ||
1973 | ||
1974 | /* See whether DCLASS has a virtual table. This routine is aimed at | |
1975 | the HP/Taligent ANSI C++ runtime model, and may not work with other | |
1976 | runtime models. Return 1 => Yes, 0 => No. */ | |
1977 | ||
1978 | int | |
fba45db2 | 1979 | has_vtable (struct type *dclass) |
c906108c SS |
1980 | { |
1981 | /* In the HP ANSI C++ runtime model, a class has a vtable only if it | |
1982 | has virtual functions or virtual bases. */ | |
1983 | ||
52f0bd74 | 1984 | int i; |
c906108c | 1985 | |
c5aa993b | 1986 | if (TYPE_CODE (dclass) != TYPE_CODE_CLASS) |
c906108c | 1987 | return 0; |
c5aa993b | 1988 | |
c906108c | 1989 | /* First check for the presence of virtual bases */ |
c5aa993b JM |
1990 | if (TYPE_FIELD_VIRTUAL_BITS (dclass)) |
1991 | for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++) | |
1992 | if (B_TST (TYPE_FIELD_VIRTUAL_BITS (dclass), i)) | |
1993 | return 1; | |
1994 | ||
c906108c | 1995 | /* Next check for virtual functions */ |
c5aa993b JM |
1996 | if (TYPE_FN_FIELDLISTS (dclass)) |
1997 | for (i = 0; i < TYPE_NFN_FIELDS (dclass); i++) | |
1998 | if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (dclass, i), 0)) | |
c906108c | 1999 | return 1; |
c5aa993b JM |
2000 | |
2001 | /* Recurse on non-virtual bases to see if any of them needs a vtable */ | |
2002 | if (TYPE_FIELD_VIRTUAL_BITS (dclass)) | |
2003 | for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++) | |
2004 | if ((!B_TST (TYPE_FIELD_VIRTUAL_BITS (dclass), i)) && | |
2005 | (has_vtable (TYPE_FIELD_TYPE (dclass, i)))) | |
2006 | return 1; | |
2007 | ||
2008 | /* Well, maybe we don't need a virtual table */ | |
c906108c SS |
2009 | return 0; |
2010 | } | |
2011 | ||
2012 | /* Return a pointer to the "primary base class" of DCLASS. | |
c5aa993b | 2013 | |
c906108c SS |
2014 | A NULL return indicates that DCLASS has no primary base, or that it |
2015 | couldn't be found (insufficient information). | |
c5aa993b | 2016 | |
c906108c SS |
2017 | This routine is aimed at the HP/Taligent ANSI C++ runtime model, |
2018 | and may not work with other runtime models. */ | |
2019 | ||
2020 | struct type * | |
fba45db2 | 2021 | primary_base_class (struct type *dclass) |
c906108c SS |
2022 | { |
2023 | /* In HP ANSI C++'s runtime model, a "primary base class" of a class | |
2024 | is the first directly inherited, non-virtual base class that | |
2025 | requires a virtual table */ | |
2026 | ||
52f0bd74 | 2027 | int i; |
c906108c | 2028 | |
c5aa993b | 2029 | if (TYPE_CODE (dclass) != TYPE_CODE_CLASS) |
c906108c SS |
2030 | return NULL; |
2031 | ||
c5aa993b JM |
2032 | for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++) |
2033 | if (!TYPE_FIELD_VIRTUAL (dclass, i) && | |
2034 | has_vtable (TYPE_FIELD_TYPE (dclass, i))) | |
2035 | return TYPE_FIELD_TYPE (dclass, i); | |
c906108c SS |
2036 | |
2037 | return NULL; | |
2038 | } | |
2039 | ||
2040 | /* Global manipulated by virtual_base_list[_aux]() */ | |
2041 | ||
c5aa993b | 2042 | static struct vbase *current_vbase_list = NULL; |
c906108c SS |
2043 | |
2044 | /* Return a pointer to a null-terminated list of struct vbase | |
2045 | items. The vbasetype pointer of each item in the list points to the | |
2046 | type information for a virtual base of the argument DCLASS. | |
c5aa993b | 2047 | |
7b83ea04 | 2048 | Helper function for virtual_base_list(). |
c906108c SS |
2049 | Note: the list goes backward, right-to-left. virtual_base_list() |
2050 | copies the items out in reverse order. */ | |
2051 | ||
7a292a7a | 2052 | static void |
fba45db2 | 2053 | virtual_base_list_aux (struct type *dclass) |
c906108c | 2054 | { |
c5aa993b | 2055 | struct vbase *tmp_vbase; |
52f0bd74 | 2056 | int i; |
c906108c | 2057 | |
c5aa993b | 2058 | if (TYPE_CODE (dclass) != TYPE_CODE_CLASS) |
7a292a7a | 2059 | return; |
c906108c SS |
2060 | |
2061 | for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++) | |
2062 | { | |
2063 | /* Recurse on this ancestor, first */ | |
c5aa993b | 2064 | virtual_base_list_aux (TYPE_FIELD_TYPE (dclass, i)); |
c906108c SS |
2065 | |
2066 | /* If this current base is itself virtual, add it to the list */ | |
c5aa993b JM |
2067 | if (BASETYPE_VIA_VIRTUAL (dclass, i)) |
2068 | { | |
2069 | struct type *basetype = TYPE_FIELD_TYPE (dclass, i); | |
2070 | ||
2071 | /* Check if base already recorded */ | |
2072 | tmp_vbase = current_vbase_list; | |
2073 | while (tmp_vbase) | |
2074 | { | |
2075 | if (tmp_vbase->vbasetype == basetype) | |
2076 | break; /* found it */ | |
2077 | tmp_vbase = tmp_vbase->next; | |
2078 | } | |
2079 | ||
2080 | if (!tmp_vbase) /* normal exit from loop */ | |
2081 | { | |
2082 | /* Allocate new item for this virtual base */ | |
2083 | tmp_vbase = (struct vbase *) xmalloc (sizeof (struct vbase)); | |
2084 | ||
2085 | /* Stick it on at the end of the list */ | |
2086 | tmp_vbase->vbasetype = basetype; | |
2087 | tmp_vbase->next = current_vbase_list; | |
2088 | current_vbase_list = tmp_vbase; | |
2089 | } | |
2090 | } /* if virtual */ | |
2091 | } /* for loop over bases */ | |
c906108c SS |
2092 | } |
2093 | ||
2094 | ||
2095 | /* Compute the list of virtual bases in the right order. Virtual | |
2096 | bases are laid out in the object's memory area in order of their | |
2097 | occurrence in a depth-first, left-to-right search through the | |
2098 | ancestors. | |
c5aa993b | 2099 | |
c906108c SS |
2100 | Argument DCLASS is the type whose virtual bases are required. |
2101 | Return value is the address of a null-terminated array of pointers | |
2102 | to struct type items. | |
c5aa993b | 2103 | |
c906108c SS |
2104 | This routine is aimed at the HP/Taligent ANSI C++ runtime model, |
2105 | and may not work with other runtime models. | |
c5aa993b | 2106 | |
c906108c SS |
2107 | This routine merely hands off the argument to virtual_base_list_aux() |
2108 | and then copies the result into an array to save space. */ | |
2109 | ||
2110 | struct type ** | |
fba45db2 | 2111 | virtual_base_list (struct type *dclass) |
c906108c | 2112 | { |
52f0bd74 AC |
2113 | struct vbase *tmp_vbase; |
2114 | struct vbase *tmp_vbase_2; | |
2115 | int i; | |
c906108c | 2116 | int count; |
c5aa993b | 2117 | struct type **vbase_array; |
c906108c SS |
2118 | |
2119 | current_vbase_list = NULL; | |
c5aa993b | 2120 | virtual_base_list_aux (dclass); |
c906108c | 2121 | |
c5aa993b | 2122 | for (i = 0, tmp_vbase = current_vbase_list; tmp_vbase != NULL; i++, tmp_vbase = tmp_vbase->next) |
c906108c SS |
2123 | /* no body */ ; |
2124 | ||
2125 | count = i; | |
2126 | ||
c5aa993b | 2127 | vbase_array = (struct type **) xmalloc ((count + 1) * sizeof (struct type *)); |
c906108c | 2128 | |
c5aa993b | 2129 | for (i = count - 1, tmp_vbase = current_vbase_list; i >= 0; i--, tmp_vbase = tmp_vbase->next) |
c906108c SS |
2130 | vbase_array[i] = tmp_vbase->vbasetype; |
2131 | ||
2132 | /* Get rid of constructed chain */ | |
2133 | tmp_vbase_2 = tmp_vbase = current_vbase_list; | |
2134 | while (tmp_vbase) | |
2135 | { | |
2136 | tmp_vbase = tmp_vbase->next; | |
b8c9b27d | 2137 | xfree (tmp_vbase_2); |
c906108c SS |
2138 | tmp_vbase_2 = tmp_vbase; |
2139 | } | |
c5aa993b | 2140 | |
c906108c SS |
2141 | vbase_array[count] = NULL; |
2142 | return vbase_array; | |
2143 | } | |
2144 | ||
2145 | /* Return the length of the virtual base list of the type DCLASS. */ | |
2146 | ||
2147 | int | |
fba45db2 | 2148 | virtual_base_list_length (struct type *dclass) |
c906108c | 2149 | { |
52f0bd74 AC |
2150 | int i; |
2151 | struct vbase *tmp_vbase; | |
c5aa993b | 2152 | |
c906108c | 2153 | current_vbase_list = NULL; |
c5aa993b | 2154 | virtual_base_list_aux (dclass); |
c906108c | 2155 | |
c5aa993b | 2156 | for (i = 0, tmp_vbase = current_vbase_list; tmp_vbase != NULL; i++, tmp_vbase = tmp_vbase->next) |
c906108c SS |
2157 | /* no body */ ; |
2158 | return i; | |
2159 | } | |
2160 | ||
2161 | /* Return the number of elements of the virtual base list of the type | |
2162 | DCLASS, ignoring those appearing in the primary base (and its | |
2163 | primary base, recursively). */ | |
2164 | ||
2165 | int | |
fba45db2 | 2166 | virtual_base_list_length_skip_primaries (struct type *dclass) |
c906108c | 2167 | { |
52f0bd74 AC |
2168 | int i; |
2169 | struct vbase *tmp_vbase; | |
c5aa993b | 2170 | struct type *primary; |
c906108c SS |
2171 | |
2172 | primary = TYPE_RUNTIME_PTR (dclass) ? TYPE_PRIMARY_BASE (dclass) : NULL; | |
2173 | ||
2174 | if (!primary) | |
2175 | return virtual_base_list_length (dclass); | |
2176 | ||
2177 | current_vbase_list = NULL; | |
c5aa993b | 2178 | virtual_base_list_aux (dclass); |
c906108c | 2179 | |
c5aa993b | 2180 | for (i = 0, tmp_vbase = current_vbase_list; tmp_vbase != NULL; tmp_vbase = tmp_vbase->next) |
c906108c SS |
2181 | { |
2182 | if (virtual_base_index (tmp_vbase->vbasetype, primary) >= 0) | |
c5aa993b | 2183 | continue; |
c906108c SS |
2184 | i++; |
2185 | } | |
2186 | return i; | |
2187 | } | |
2188 | ||
2189 | ||
2190 | /* Return the index (position) of type BASE, which is a virtual base | |
2191 | class of DCLASS, in the latter's virtual base list. A return of -1 | |
2192 | indicates "not found" or a problem. */ | |
2193 | ||
2194 | int | |
fba45db2 | 2195 | virtual_base_index (struct type *base, struct type *dclass) |
c906108c | 2196 | { |
52f0bd74 AC |
2197 | struct type *vbase; |
2198 | int i; | |
c906108c | 2199 | |
c5aa993b JM |
2200 | if ((TYPE_CODE (dclass) != TYPE_CODE_CLASS) || |
2201 | (TYPE_CODE (base) != TYPE_CODE_CLASS)) | |
c906108c SS |
2202 | return -1; |
2203 | ||
2204 | i = 0; | |
015a42b4 | 2205 | vbase = virtual_base_list (dclass)[0]; |
c906108c SS |
2206 | while (vbase) |
2207 | { | |
2208 | if (vbase == base) | |
c5aa993b | 2209 | break; |
015a42b4 | 2210 | vbase = virtual_base_list (dclass)[++i]; |
c906108c SS |
2211 | } |
2212 | ||
2213 | return vbase ? i : -1; | |
2214 | } | |
2215 | ||
2216 | ||
2217 | ||
2218 | /* Return the index (position) of type BASE, which is a virtual base | |
2219 | class of DCLASS, in the latter's virtual base list. Skip over all | |
2220 | bases that may appear in the virtual base list of the primary base | |
2221 | class of DCLASS (recursively). A return of -1 indicates "not | |
2222 | found" or a problem. */ | |
2223 | ||
2224 | int | |
fba45db2 | 2225 | virtual_base_index_skip_primaries (struct type *base, struct type *dclass) |
c906108c | 2226 | { |
52f0bd74 AC |
2227 | struct type *vbase; |
2228 | int i, j; | |
c5aa993b | 2229 | struct type *primary; |
c906108c | 2230 | |
c5aa993b JM |
2231 | if ((TYPE_CODE (dclass) != TYPE_CODE_CLASS) || |
2232 | (TYPE_CODE (base) != TYPE_CODE_CLASS)) | |
c906108c SS |
2233 | return -1; |
2234 | ||
c5aa993b | 2235 | primary = TYPE_RUNTIME_PTR (dclass) ? TYPE_PRIMARY_BASE (dclass) : NULL; |
c906108c SS |
2236 | |
2237 | j = -1; | |
2238 | i = 0; | |
015a42b4 | 2239 | vbase = virtual_base_list (dclass)[0]; |
c906108c SS |
2240 | while (vbase) |
2241 | { | |
c5aa993b JM |
2242 | if (!primary || (virtual_base_index_skip_primaries (vbase, primary) < 0)) |
2243 | j++; | |
c906108c | 2244 | if (vbase == base) |
c5aa993b | 2245 | break; |
015a42b4 | 2246 | vbase = virtual_base_list (dclass)[++i]; |
c906108c SS |
2247 | } |
2248 | ||
2249 | return vbase ? j : -1; | |
2250 | } | |
2251 | ||
2252 | /* Return position of a derived class DCLASS in the list of | |
2253 | * primary bases starting with the remotest ancestor. | |
2254 | * Position returned is 0-based. */ | |
2255 | ||
2256 | int | |
fba45db2 | 2257 | class_index_in_primary_list (struct type *dclass) |
c906108c | 2258 | { |
c5aa993b | 2259 | struct type *pbc; /* primary base class */ |
c906108c | 2260 | |
c5aa993b | 2261 | /* Simply recurse on primary base */ |
c906108c SS |
2262 | pbc = TYPE_PRIMARY_BASE (dclass); |
2263 | if (pbc) | |
2264 | return 1 + class_index_in_primary_list (pbc); | |
2265 | else | |
2266 | return 0; | |
2267 | } | |
2268 | ||
2269 | /* Return a count of the number of virtual functions a type has. | |
2270 | * This includes all the virtual functions it inherits from its | |
2271 | * base classes too. | |
2272 | */ | |
2273 | ||
2274 | /* pai: FIXME This doesn't do the right thing: count redefined virtual | |
2275 | * functions only once (latest redefinition) | |
2276 | */ | |
2277 | ||
2278 | int | |
fba45db2 | 2279 | count_virtual_fns (struct type *dclass) |
c906108c | 2280 | { |
c5aa993b | 2281 | int fn, oi; /* function and overloaded instance indices */ |
c5aa993b JM |
2282 | int vfuncs; /* count to return */ |
2283 | ||
2284 | /* recurse on bases that can share virtual table */ | |
2285 | struct type *pbc = primary_base_class (dclass); | |
c906108c SS |
2286 | if (pbc) |
2287 | vfuncs = count_virtual_fns (pbc); | |
7f7e9482 AC |
2288 | else |
2289 | vfuncs = 0; | |
c5aa993b | 2290 | |
c906108c SS |
2291 | for (fn = 0; fn < TYPE_NFN_FIELDS (dclass); fn++) |
2292 | for (oi = 0; oi < TYPE_FN_FIELDLIST_LENGTH (dclass, fn); oi++) | |
2293 | if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (dclass, fn), oi)) | |
c5aa993b | 2294 | vfuncs++; |
c906108c SS |
2295 | |
2296 | return vfuncs; | |
2297 | } | |
c906108c SS |
2298 | \f |
2299 | ||
c5aa993b | 2300 | |
c906108c SS |
2301 | /* Functions for overload resolution begin here */ |
2302 | ||
2303 | /* Compare two badness vectors A and B and return the result. | |
2304 | * 0 => A and B are identical | |
2305 | * 1 => A and B are incomparable | |
2306 | * 2 => A is better than B | |
2307 | * 3 => A is worse than B */ | |
2308 | ||
2309 | int | |
fba45db2 | 2310 | compare_badness (struct badness_vector *a, struct badness_vector *b) |
c906108c SS |
2311 | { |
2312 | int i; | |
2313 | int tmp; | |
c5aa993b JM |
2314 | short found_pos = 0; /* any positives in c? */ |
2315 | short found_neg = 0; /* any negatives in c? */ | |
2316 | ||
2317 | /* differing lengths => incomparable */ | |
c906108c SS |
2318 | if (a->length != b->length) |
2319 | return 1; | |
2320 | ||
c5aa993b JM |
2321 | /* Subtract b from a */ |
2322 | for (i = 0; i < a->length; i++) | |
c906108c SS |
2323 | { |
2324 | tmp = a->rank[i] - b->rank[i]; | |
2325 | if (tmp > 0) | |
c5aa993b | 2326 | found_pos = 1; |
c906108c | 2327 | else if (tmp < 0) |
c5aa993b | 2328 | found_neg = 1; |
c906108c SS |
2329 | } |
2330 | ||
2331 | if (found_pos) | |
2332 | { | |
2333 | if (found_neg) | |
c5aa993b | 2334 | return 1; /* incomparable */ |
c906108c | 2335 | else |
c5aa993b | 2336 | return 3; /* A > B */ |
c906108c | 2337 | } |
c5aa993b JM |
2338 | else |
2339 | /* no positives */ | |
c906108c SS |
2340 | { |
2341 | if (found_neg) | |
c5aa993b | 2342 | return 2; /* A < B */ |
c906108c | 2343 | else |
c5aa993b | 2344 | return 0; /* A == B */ |
c906108c SS |
2345 | } |
2346 | } | |
2347 | ||
2348 | /* Rank a function by comparing its parameter types (PARMS, length NPARMS), | |
2349 | * to the types of an argument list (ARGS, length NARGS). | |
2350 | * Return a pointer to a badness vector. This has NARGS + 1 entries. */ | |
2351 | ||
2352 | struct badness_vector * | |
fba45db2 | 2353 | rank_function (struct type **parms, int nparms, struct type **args, int nargs) |
c906108c SS |
2354 | { |
2355 | int i; | |
c5aa993b | 2356 | struct badness_vector *bv; |
c906108c SS |
2357 | int min_len = nparms < nargs ? nparms : nargs; |
2358 | ||
2359 | bv = xmalloc (sizeof (struct badness_vector)); | |
c5aa993b | 2360 | bv->length = nargs + 1; /* add 1 for the length-match rank */ |
c906108c SS |
2361 | bv->rank = xmalloc ((nargs + 1) * sizeof (int)); |
2362 | ||
2363 | /* First compare the lengths of the supplied lists. | |
2364 | * If there is a mismatch, set it to a high value. */ | |
c5aa993b | 2365 | |
c906108c SS |
2366 | /* pai/1997-06-03 FIXME: when we have debug info about default |
2367 | * arguments and ellipsis parameter lists, we should consider those | |
2368 | * and rank the length-match more finely. */ | |
2369 | ||
2370 | LENGTH_MATCH (bv) = (nargs != nparms) ? LENGTH_MISMATCH_BADNESS : 0; | |
2371 | ||
2372 | /* Now rank all the parameters of the candidate function */ | |
74cc24b0 DB |
2373 | for (i = 1; i <= min_len; i++) |
2374 | bv->rank[i] = rank_one_type (parms[i-1], args[i-1]); | |
c906108c | 2375 | |
c5aa993b JM |
2376 | /* If more arguments than parameters, add dummy entries */ |
2377 | for (i = min_len + 1; i <= nargs; i++) | |
c906108c SS |
2378 | bv->rank[i] = TOO_FEW_PARAMS_BADNESS; |
2379 | ||
2380 | return bv; | |
2381 | } | |
2382 | ||
973ccf8b DJ |
2383 | /* Compare the names of two integer types, assuming that any sign |
2384 | qualifiers have been checked already. We do it this way because | |
2385 | there may be an "int" in the name of one of the types. */ | |
2386 | ||
2387 | static int | |
2388 | integer_types_same_name_p (const char *first, const char *second) | |
2389 | { | |
2390 | int first_p, second_p; | |
2391 | ||
2392 | /* If both are shorts, return 1; if neither is a short, keep checking. */ | |
2393 | first_p = (strstr (first, "short") != NULL); | |
2394 | second_p = (strstr (second, "short") != NULL); | |
2395 | if (first_p && second_p) | |
2396 | return 1; | |
2397 | if (first_p || second_p) | |
2398 | return 0; | |
2399 | ||
2400 | /* Likewise for long. */ | |
2401 | first_p = (strstr (first, "long") != NULL); | |
2402 | second_p = (strstr (second, "long") != NULL); | |
2403 | if (first_p && second_p) | |
2404 | return 1; | |
2405 | if (first_p || second_p) | |
2406 | return 0; | |
2407 | ||
2408 | /* Likewise for char. */ | |
2409 | first_p = (strstr (first, "char") != NULL); | |
2410 | second_p = (strstr (second, "char") != NULL); | |
2411 | if (first_p && second_p) | |
2412 | return 1; | |
2413 | if (first_p || second_p) | |
2414 | return 0; | |
2415 | ||
2416 | /* They must both be ints. */ | |
2417 | return 1; | |
2418 | } | |
2419 | ||
c906108c SS |
2420 | /* Compare one type (PARM) for compatibility with another (ARG). |
2421 | * PARM is intended to be the parameter type of a function; and | |
2422 | * ARG is the supplied argument's type. This function tests if | |
2423 | * the latter can be converted to the former. | |
2424 | * | |
2425 | * Return 0 if they are identical types; | |
2426 | * Otherwise, return an integer which corresponds to how compatible | |
2427 | * PARM is to ARG. The higher the return value, the worse the match. | |
2428 | * Generally the "bad" conversions are all uniformly assigned a 100 */ | |
2429 | ||
2430 | int | |
fba45db2 | 2431 | rank_one_type (struct type *parm, struct type *arg) |
c906108c SS |
2432 | { |
2433 | /* Identical type pointers */ | |
2434 | /* However, this still doesn't catch all cases of same type for arg | |
2435 | * and param. The reason is that builtin types are different from | |
2436 | * the same ones constructed from the object. */ | |
2437 | if (parm == arg) | |
2438 | return 0; | |
2439 | ||
2440 | /* Resolve typedefs */ | |
2441 | if (TYPE_CODE (parm) == TYPE_CODE_TYPEDEF) | |
2442 | parm = check_typedef (parm); | |
2443 | if (TYPE_CODE (arg) == TYPE_CODE_TYPEDEF) | |
2444 | arg = check_typedef (arg); | |
2445 | ||
070ad9f0 DB |
2446 | /* |
2447 | Well, damnit, if the names are exactly the same, | |
2448 | i'll say they are exactly the same. This happens when we generate | |
2449 | method stubs. The types won't point to the same address, but they | |
2450 | really are the same. | |
2451 | */ | |
2452 | ||
6b1ba9a0 ND |
2453 | if (TYPE_NAME (parm) && TYPE_NAME (arg) && |
2454 | !strcmp (TYPE_NAME (parm), TYPE_NAME (arg))) | |
070ad9f0 DB |
2455 | return 0; |
2456 | ||
c906108c SS |
2457 | /* Check if identical after resolving typedefs */ |
2458 | if (parm == arg) | |
2459 | return 0; | |
2460 | ||
db577aea AC |
2461 | /* See through references, since we can almost make non-references |
2462 | references. */ | |
2463 | if (TYPE_CODE (arg) == TYPE_CODE_REF) | |
6b1ba9a0 | 2464 | return (rank_one_type (parm, TYPE_TARGET_TYPE (arg)) |
db577aea AC |
2465 | + REFERENCE_CONVERSION_BADNESS); |
2466 | if (TYPE_CODE (parm) == TYPE_CODE_REF) | |
6b1ba9a0 | 2467 | return (rank_one_type (TYPE_TARGET_TYPE (parm), arg) |
db577aea | 2468 | + REFERENCE_CONVERSION_BADNESS); |
5d161b24 | 2469 | if (overload_debug) |
db577aea | 2470 | /* Debugging only. */ |
5d161b24 DB |
2471 | fprintf_filtered (gdb_stderr,"------ Arg is %s [%d], parm is %s [%d]\n", |
2472 | TYPE_NAME (arg), TYPE_CODE (arg), TYPE_NAME (parm), TYPE_CODE (parm)); | |
c906108c SS |
2473 | |
2474 | /* x -> y means arg of type x being supplied for parameter of type y */ | |
2475 | ||
2476 | switch (TYPE_CODE (parm)) | |
2477 | { | |
c5aa993b JM |
2478 | case TYPE_CODE_PTR: |
2479 | switch (TYPE_CODE (arg)) | |
2480 | { | |
2481 | case TYPE_CODE_PTR: | |
2482 | if (TYPE_CODE (TYPE_TARGET_TYPE (parm)) == TYPE_CODE_VOID) | |
2483 | return VOID_PTR_CONVERSION_BADNESS; | |
2484 | else | |
2485 | return rank_one_type (TYPE_TARGET_TYPE (parm), TYPE_TARGET_TYPE (arg)); | |
2486 | case TYPE_CODE_ARRAY: | |
2487 | return rank_one_type (TYPE_TARGET_TYPE (parm), TYPE_TARGET_TYPE (arg)); | |
2488 | case TYPE_CODE_FUNC: | |
2489 | return rank_one_type (TYPE_TARGET_TYPE (parm), arg); | |
2490 | case TYPE_CODE_INT: | |
2491 | case TYPE_CODE_ENUM: | |
4f2aea11 | 2492 | case TYPE_CODE_FLAGS: |
c5aa993b JM |
2493 | case TYPE_CODE_CHAR: |
2494 | case TYPE_CODE_RANGE: | |
2495 | case TYPE_CODE_BOOL: | |
2496 | return POINTER_CONVERSION_BADNESS; | |
2497 | default: | |
2498 | return INCOMPATIBLE_TYPE_BADNESS; | |
2499 | } | |
2500 | case TYPE_CODE_ARRAY: | |
2501 | switch (TYPE_CODE (arg)) | |
2502 | { | |
2503 | case TYPE_CODE_PTR: | |
2504 | case TYPE_CODE_ARRAY: | |
2505 | return rank_one_type (TYPE_TARGET_TYPE (parm), TYPE_TARGET_TYPE (arg)); | |
2506 | default: | |
2507 | return INCOMPATIBLE_TYPE_BADNESS; | |
2508 | } | |
2509 | case TYPE_CODE_FUNC: | |
2510 | switch (TYPE_CODE (arg)) | |
2511 | { | |
2512 | case TYPE_CODE_PTR: /* funcptr -> func */ | |
2513 | return rank_one_type (parm, TYPE_TARGET_TYPE (arg)); | |
2514 | default: | |
2515 | return INCOMPATIBLE_TYPE_BADNESS; | |
2516 | } | |
2517 | case TYPE_CODE_INT: | |
2518 | switch (TYPE_CODE (arg)) | |
2519 | { | |
2520 | case TYPE_CODE_INT: | |
2521 | if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm)) | |
2522 | { | |
2523 | /* Deal with signed, unsigned, and plain chars and | |
7b83ea04 | 2524 | signed and unsigned ints */ |
c5aa993b JM |
2525 | if (TYPE_NOSIGN (parm)) |
2526 | { | |
2527 | /* This case only for character types */ | |
2528 | if (TYPE_NOSIGN (arg)) /* plain char -> plain char */ | |
2529 | return 0; | |
2530 | else | |
1c5cb38e | 2531 | return INTEGER_CONVERSION_BADNESS; /* signed/unsigned char -> plain char */ |
c5aa993b JM |
2532 | } |
2533 | else if (TYPE_UNSIGNED (parm)) | |
2534 | { | |
2535 | if (TYPE_UNSIGNED (arg)) | |
2536 | { | |
973ccf8b DJ |
2537 | /* unsigned int -> unsigned int, or unsigned long -> unsigned long */ |
2538 | if (integer_types_same_name_p (TYPE_NAME (parm), TYPE_NAME (arg))) | |
2539 | return 0; | |
2540 | else if (integer_types_same_name_p (TYPE_NAME (arg), "int") | |
2541 | && integer_types_same_name_p (TYPE_NAME (parm), "long")) | |
c5aa993b JM |
2542 | return INTEGER_PROMOTION_BADNESS; /* unsigned int -> unsigned long */ |
2543 | else | |
1c5cb38e | 2544 | return INTEGER_CONVERSION_BADNESS; /* unsigned long -> unsigned int */ |
c5aa993b JM |
2545 | } |
2546 | else | |
2547 | { | |
973ccf8b DJ |
2548 | if (integer_types_same_name_p (TYPE_NAME (arg), "long") |
2549 | && integer_types_same_name_p (TYPE_NAME (parm), "int")) | |
1c5cb38e | 2550 | return INTEGER_CONVERSION_BADNESS; /* signed long -> unsigned int */ |
c5aa993b JM |
2551 | else |
2552 | return INTEGER_CONVERSION_BADNESS; /* signed int/long -> unsigned int/long */ | |
2553 | } | |
2554 | } | |
2555 | else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg)) | |
2556 | { | |
973ccf8b | 2557 | if (integer_types_same_name_p (TYPE_NAME (parm), TYPE_NAME (arg))) |
c5aa993b | 2558 | return 0; |
973ccf8b DJ |
2559 | else if (integer_types_same_name_p (TYPE_NAME (arg), "int") |
2560 | && integer_types_same_name_p (TYPE_NAME (parm), "long")) | |
c5aa993b JM |
2561 | return INTEGER_PROMOTION_BADNESS; |
2562 | else | |
1c5cb38e | 2563 | return INTEGER_CONVERSION_BADNESS; |
c5aa993b JM |
2564 | } |
2565 | else | |
1c5cb38e | 2566 | return INTEGER_CONVERSION_BADNESS; |
c5aa993b JM |
2567 | } |
2568 | else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm)) | |
2569 | return INTEGER_PROMOTION_BADNESS; | |
2570 | else | |
1c5cb38e | 2571 | return INTEGER_CONVERSION_BADNESS; |
c5aa993b | 2572 | case TYPE_CODE_ENUM: |
4f2aea11 | 2573 | case TYPE_CODE_FLAGS: |
c5aa993b JM |
2574 | case TYPE_CODE_CHAR: |
2575 | case TYPE_CODE_RANGE: | |
2576 | case TYPE_CODE_BOOL: | |
2577 | return INTEGER_PROMOTION_BADNESS; | |
2578 | case TYPE_CODE_FLT: | |
2579 | return INT_FLOAT_CONVERSION_BADNESS; | |
2580 | case TYPE_CODE_PTR: | |
2581 | return NS_POINTER_CONVERSION_BADNESS; | |
2582 | default: | |
2583 | return INCOMPATIBLE_TYPE_BADNESS; | |
2584 | } | |
2585 | break; | |
2586 | case TYPE_CODE_ENUM: | |
2587 | switch (TYPE_CODE (arg)) | |
2588 | { | |
2589 | case TYPE_CODE_INT: | |
2590 | case TYPE_CODE_CHAR: | |
2591 | case TYPE_CODE_RANGE: | |
2592 | case TYPE_CODE_BOOL: | |
2593 | case TYPE_CODE_ENUM: | |
1c5cb38e | 2594 | return INTEGER_CONVERSION_BADNESS; |
c5aa993b JM |
2595 | case TYPE_CODE_FLT: |
2596 | return INT_FLOAT_CONVERSION_BADNESS; | |
2597 | default: | |
2598 | return INCOMPATIBLE_TYPE_BADNESS; | |
2599 | } | |
2600 | break; | |
2601 | case TYPE_CODE_CHAR: | |
2602 | switch (TYPE_CODE (arg)) | |
2603 | { | |
2604 | case TYPE_CODE_RANGE: | |
2605 | case TYPE_CODE_BOOL: | |
2606 | case TYPE_CODE_ENUM: | |
1c5cb38e | 2607 | return INTEGER_CONVERSION_BADNESS; |
c5aa993b JM |
2608 | case TYPE_CODE_FLT: |
2609 | return INT_FLOAT_CONVERSION_BADNESS; | |
2610 | case TYPE_CODE_INT: | |
2611 | if (TYPE_LENGTH (arg) > TYPE_LENGTH (parm)) | |
1c5cb38e | 2612 | return INTEGER_CONVERSION_BADNESS; |
c5aa993b JM |
2613 | else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm)) |
2614 | return INTEGER_PROMOTION_BADNESS; | |
2615 | /* >>> !! else fall through !! <<< */ | |
2616 | case TYPE_CODE_CHAR: | |
2617 | /* Deal with signed, unsigned, and plain chars for C++ | |
2618 | and with int cases falling through from previous case */ | |
2619 | if (TYPE_NOSIGN (parm)) | |
2620 | { | |
2621 | if (TYPE_NOSIGN (arg)) | |
2622 | return 0; | |
2623 | else | |
1c5cb38e | 2624 | return INTEGER_CONVERSION_BADNESS; |
c5aa993b JM |
2625 | } |
2626 | else if (TYPE_UNSIGNED (parm)) | |
2627 | { | |
2628 | if (TYPE_UNSIGNED (arg)) | |
2629 | return 0; | |
2630 | else | |
2631 | return INTEGER_PROMOTION_BADNESS; | |
2632 | } | |
2633 | else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg)) | |
2634 | return 0; | |
2635 | else | |
1c5cb38e | 2636 | return INTEGER_CONVERSION_BADNESS; |
c5aa993b JM |
2637 | default: |
2638 | return INCOMPATIBLE_TYPE_BADNESS; | |
2639 | } | |
2640 | break; | |
2641 | case TYPE_CODE_RANGE: | |
2642 | switch (TYPE_CODE (arg)) | |
2643 | { | |
2644 | case TYPE_CODE_INT: | |
2645 | case TYPE_CODE_CHAR: | |
2646 | case TYPE_CODE_RANGE: | |
2647 | case TYPE_CODE_BOOL: | |
2648 | case TYPE_CODE_ENUM: | |
1c5cb38e | 2649 | return INTEGER_CONVERSION_BADNESS; |
c5aa993b JM |
2650 | case TYPE_CODE_FLT: |
2651 | return INT_FLOAT_CONVERSION_BADNESS; | |
2652 | default: | |
2653 | return INCOMPATIBLE_TYPE_BADNESS; | |
2654 | } | |
2655 | break; | |
2656 | case TYPE_CODE_BOOL: | |
2657 | switch (TYPE_CODE (arg)) | |
2658 | { | |
2659 | case TYPE_CODE_INT: | |
2660 | case TYPE_CODE_CHAR: | |
2661 | case TYPE_CODE_RANGE: | |
2662 | case TYPE_CODE_ENUM: | |
2663 | case TYPE_CODE_FLT: | |
2664 | case TYPE_CODE_PTR: | |
2665 | return BOOLEAN_CONVERSION_BADNESS; | |
2666 | case TYPE_CODE_BOOL: | |
2667 | return 0; | |
2668 | default: | |
2669 | return INCOMPATIBLE_TYPE_BADNESS; | |
2670 | } | |
2671 | break; | |
2672 | case TYPE_CODE_FLT: | |
2673 | switch (TYPE_CODE (arg)) | |
2674 | { | |
2675 | case TYPE_CODE_FLT: | |
2676 | if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm)) | |
2677 | return FLOAT_PROMOTION_BADNESS; | |
2678 | else if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm)) | |
2679 | return 0; | |
2680 | else | |
2681 | return FLOAT_CONVERSION_BADNESS; | |
2682 | case TYPE_CODE_INT: | |
2683 | case TYPE_CODE_BOOL: | |
2684 | case TYPE_CODE_ENUM: | |
2685 | case TYPE_CODE_RANGE: | |
2686 | case TYPE_CODE_CHAR: | |
2687 | return INT_FLOAT_CONVERSION_BADNESS; | |
2688 | default: | |
2689 | return INCOMPATIBLE_TYPE_BADNESS; | |
2690 | } | |
2691 | break; | |
2692 | case TYPE_CODE_COMPLEX: | |
2693 | switch (TYPE_CODE (arg)) | |
2694 | { /* Strictly not needed for C++, but... */ | |
2695 | case TYPE_CODE_FLT: | |
2696 | return FLOAT_PROMOTION_BADNESS; | |
2697 | case TYPE_CODE_COMPLEX: | |
2698 | return 0; | |
2699 | default: | |
2700 | return INCOMPATIBLE_TYPE_BADNESS; | |
2701 | } | |
2702 | break; | |
2703 | case TYPE_CODE_STRUCT: | |
c906108c | 2704 | /* currently same as TYPE_CODE_CLASS */ |
c5aa993b JM |
2705 | switch (TYPE_CODE (arg)) |
2706 | { | |
2707 | case TYPE_CODE_STRUCT: | |
2708 | /* Check for derivation */ | |
2709 | if (is_ancestor (parm, arg)) | |
2710 | return BASE_CONVERSION_BADNESS; | |
2711 | /* else fall through */ | |
2712 | default: | |
2713 | return INCOMPATIBLE_TYPE_BADNESS; | |
2714 | } | |
2715 | break; | |
2716 | case TYPE_CODE_UNION: | |
2717 | switch (TYPE_CODE (arg)) | |
2718 | { | |
2719 | case TYPE_CODE_UNION: | |
2720 | default: | |
2721 | return INCOMPATIBLE_TYPE_BADNESS; | |
2722 | } | |
2723 | break; | |
0d5de010 | 2724 | case TYPE_CODE_MEMBERPTR: |
c5aa993b JM |
2725 | switch (TYPE_CODE (arg)) |
2726 | { | |
2727 | default: | |
2728 | return INCOMPATIBLE_TYPE_BADNESS; | |
2729 | } | |
2730 | break; | |
2731 | case TYPE_CODE_METHOD: | |
2732 | switch (TYPE_CODE (arg)) | |
2733 | { | |
2734 | ||
2735 | default: | |
2736 | return INCOMPATIBLE_TYPE_BADNESS; | |
2737 | } | |
2738 | break; | |
2739 | case TYPE_CODE_REF: | |
2740 | switch (TYPE_CODE (arg)) | |
2741 | { | |
2742 | ||
2743 | default: | |
2744 | return INCOMPATIBLE_TYPE_BADNESS; | |
2745 | } | |
2746 | ||
2747 | break; | |
2748 | case TYPE_CODE_SET: | |
2749 | switch (TYPE_CODE (arg)) | |
2750 | { | |
2751 | /* Not in C++ */ | |
2752 | case TYPE_CODE_SET: | |
2753 | return rank_one_type (TYPE_FIELD_TYPE (parm, 0), TYPE_FIELD_TYPE (arg, 0)); | |
2754 | default: | |
2755 | return INCOMPATIBLE_TYPE_BADNESS; | |
2756 | } | |
2757 | break; | |
2758 | case TYPE_CODE_VOID: | |
2759 | default: | |
2760 | return INCOMPATIBLE_TYPE_BADNESS; | |
2761 | } /* switch (TYPE_CODE (arg)) */ | |
c906108c SS |
2762 | } |
2763 | ||
c5aa993b JM |
2764 | |
2765 | /* End of functions for overload resolution */ | |
c906108c | 2766 | |
c906108c | 2767 | static void |
fba45db2 | 2768 | print_bit_vector (B_TYPE *bits, int nbits) |
c906108c SS |
2769 | { |
2770 | int bitno; | |
2771 | ||
2772 | for (bitno = 0; bitno < nbits; bitno++) | |
2773 | { | |
2774 | if ((bitno % 8) == 0) | |
2775 | { | |
2776 | puts_filtered (" "); | |
2777 | } | |
2778 | if (B_TST (bits, bitno)) | |
a3f17187 | 2779 | printf_filtered (("1")); |
c906108c | 2780 | else |
a3f17187 | 2781 | printf_filtered (("0")); |
c906108c SS |
2782 | } |
2783 | } | |
2784 | ||
ad2f7632 DJ |
2785 | /* Note the first arg should be the "this" pointer, we may not want to |
2786 | include it since we may get into a infinitely recursive situation. */ | |
c906108c SS |
2787 | |
2788 | static void | |
ad2f7632 | 2789 | print_arg_types (struct field *args, int nargs, int spaces) |
c906108c SS |
2790 | { |
2791 | if (args != NULL) | |
2792 | { | |
ad2f7632 DJ |
2793 | int i; |
2794 | ||
2795 | for (i = 0; i < nargs; i++) | |
2796 | recursive_dump_type (args[i].type, spaces + 2); | |
c906108c SS |
2797 | } |
2798 | } | |
2799 | ||
2800 | static void | |
fba45db2 | 2801 | dump_fn_fieldlists (struct type *type, int spaces) |
c906108c SS |
2802 | { |
2803 | int method_idx; | |
2804 | int overload_idx; | |
2805 | struct fn_field *f; | |
2806 | ||
2807 | printfi_filtered (spaces, "fn_fieldlists "); | |
d4f3574e | 2808 | gdb_print_host_address (TYPE_FN_FIELDLISTS (type), gdb_stdout); |
c906108c SS |
2809 | printf_filtered ("\n"); |
2810 | for (method_idx = 0; method_idx < TYPE_NFN_FIELDS (type); method_idx++) | |
2811 | { | |
2812 | f = TYPE_FN_FIELDLIST1 (type, method_idx); | |
2813 | printfi_filtered (spaces + 2, "[%d] name '%s' (", | |
2814 | method_idx, | |
2815 | TYPE_FN_FIELDLIST_NAME (type, method_idx)); | |
d4f3574e SS |
2816 | gdb_print_host_address (TYPE_FN_FIELDLIST_NAME (type, method_idx), |
2817 | gdb_stdout); | |
a3f17187 | 2818 | printf_filtered (_(") length %d\n"), |
c906108c SS |
2819 | TYPE_FN_FIELDLIST_LENGTH (type, method_idx)); |
2820 | for (overload_idx = 0; | |
2821 | overload_idx < TYPE_FN_FIELDLIST_LENGTH (type, method_idx); | |
2822 | overload_idx++) | |
2823 | { | |
2824 | printfi_filtered (spaces + 4, "[%d] physname '%s' (", | |
2825 | overload_idx, | |
2826 | TYPE_FN_FIELD_PHYSNAME (f, overload_idx)); | |
d4f3574e SS |
2827 | gdb_print_host_address (TYPE_FN_FIELD_PHYSNAME (f, overload_idx), |
2828 | gdb_stdout); | |
c906108c SS |
2829 | printf_filtered (")\n"); |
2830 | printfi_filtered (spaces + 8, "type "); | |
d4f3574e | 2831 | gdb_print_host_address (TYPE_FN_FIELD_TYPE (f, overload_idx), gdb_stdout); |
c906108c SS |
2832 | printf_filtered ("\n"); |
2833 | ||
2834 | recursive_dump_type (TYPE_FN_FIELD_TYPE (f, overload_idx), | |
2835 | spaces + 8 + 2); | |
2836 | ||
2837 | printfi_filtered (spaces + 8, "args "); | |
d4f3574e | 2838 | gdb_print_host_address (TYPE_FN_FIELD_ARGS (f, overload_idx), gdb_stdout); |
c906108c SS |
2839 | printf_filtered ("\n"); |
2840 | ||
ad2f7632 DJ |
2841 | print_arg_types (TYPE_FN_FIELD_ARGS (f, overload_idx), |
2842 | TYPE_NFIELDS (TYPE_FN_FIELD_TYPE (f, overload_idx)), | |
2843 | spaces); | |
c906108c | 2844 | printfi_filtered (spaces + 8, "fcontext "); |
d4f3574e SS |
2845 | gdb_print_host_address (TYPE_FN_FIELD_FCONTEXT (f, overload_idx), |
2846 | gdb_stdout); | |
c906108c SS |
2847 | printf_filtered ("\n"); |
2848 | ||
2849 | printfi_filtered (spaces + 8, "is_const %d\n", | |
2850 | TYPE_FN_FIELD_CONST (f, overload_idx)); | |
2851 | printfi_filtered (spaces + 8, "is_volatile %d\n", | |
2852 | TYPE_FN_FIELD_VOLATILE (f, overload_idx)); | |
2853 | printfi_filtered (spaces + 8, "is_private %d\n", | |
2854 | TYPE_FN_FIELD_PRIVATE (f, overload_idx)); | |
2855 | printfi_filtered (spaces + 8, "is_protected %d\n", | |
2856 | TYPE_FN_FIELD_PROTECTED (f, overload_idx)); | |
2857 | printfi_filtered (spaces + 8, "is_stub %d\n", | |
2858 | TYPE_FN_FIELD_STUB (f, overload_idx)); | |
2859 | printfi_filtered (spaces + 8, "voffset %u\n", | |
2860 | TYPE_FN_FIELD_VOFFSET (f, overload_idx)); | |
2861 | } | |
2862 | } | |
2863 | } | |
2864 | ||
2865 | static void | |
fba45db2 | 2866 | print_cplus_stuff (struct type *type, int spaces) |
c906108c SS |
2867 | { |
2868 | printfi_filtered (spaces, "n_baseclasses %d\n", | |
2869 | TYPE_N_BASECLASSES (type)); | |
2870 | printfi_filtered (spaces, "nfn_fields %d\n", | |
2871 | TYPE_NFN_FIELDS (type)); | |
2872 | printfi_filtered (spaces, "nfn_fields_total %d\n", | |
2873 | TYPE_NFN_FIELDS_TOTAL (type)); | |
2874 | if (TYPE_N_BASECLASSES (type) > 0) | |
2875 | { | |
2876 | printfi_filtered (spaces, "virtual_field_bits (%d bits at *", | |
2877 | TYPE_N_BASECLASSES (type)); | |
d4f3574e | 2878 | gdb_print_host_address (TYPE_FIELD_VIRTUAL_BITS (type), gdb_stdout); |
c906108c SS |
2879 | printf_filtered (")"); |
2880 | ||
2881 | print_bit_vector (TYPE_FIELD_VIRTUAL_BITS (type), | |
2882 | TYPE_N_BASECLASSES (type)); | |
2883 | puts_filtered ("\n"); | |
2884 | } | |
2885 | if (TYPE_NFIELDS (type) > 0) | |
2886 | { | |
2887 | if (TYPE_FIELD_PRIVATE_BITS (type) != NULL) | |
2888 | { | |
2889 | printfi_filtered (spaces, "private_field_bits (%d bits at *", | |
2890 | TYPE_NFIELDS (type)); | |
d4f3574e | 2891 | gdb_print_host_address (TYPE_FIELD_PRIVATE_BITS (type), gdb_stdout); |
c906108c SS |
2892 | printf_filtered (")"); |
2893 | print_bit_vector (TYPE_FIELD_PRIVATE_BITS (type), | |
2894 | TYPE_NFIELDS (type)); | |
2895 | puts_filtered ("\n"); | |
2896 | } | |
2897 | if (TYPE_FIELD_PROTECTED_BITS (type) != NULL) | |
2898 | { | |
2899 | printfi_filtered (spaces, "protected_field_bits (%d bits at *", | |
2900 | TYPE_NFIELDS (type)); | |
d4f3574e | 2901 | gdb_print_host_address (TYPE_FIELD_PROTECTED_BITS (type), gdb_stdout); |
c906108c SS |
2902 | printf_filtered (")"); |
2903 | print_bit_vector (TYPE_FIELD_PROTECTED_BITS (type), | |
2904 | TYPE_NFIELDS (type)); | |
2905 | puts_filtered ("\n"); | |
2906 | } | |
2907 | } | |
2908 | if (TYPE_NFN_FIELDS (type) > 0) | |
2909 | { | |
2910 | dump_fn_fieldlists (type, spaces); | |
2911 | } | |
2912 | } | |
2913 | ||
e9e79dd9 FF |
2914 | static void |
2915 | print_bound_type (int bt) | |
2916 | { | |
2917 | switch (bt) | |
2918 | { | |
2919 | case BOUND_CANNOT_BE_DETERMINED: | |
2920 | printf_filtered ("(BOUND_CANNOT_BE_DETERMINED)"); | |
2921 | break; | |
2922 | case BOUND_BY_REF_ON_STACK: | |
2923 | printf_filtered ("(BOUND_BY_REF_ON_STACK)"); | |
2924 | break; | |
2925 | case BOUND_BY_VALUE_ON_STACK: | |
2926 | printf_filtered ("(BOUND_BY_VALUE_ON_STACK)"); | |
2927 | break; | |
2928 | case BOUND_BY_REF_IN_REG: | |
2929 | printf_filtered ("(BOUND_BY_REF_IN_REG)"); | |
2930 | break; | |
2931 | case BOUND_BY_VALUE_IN_REG: | |
2932 | printf_filtered ("(BOUND_BY_VALUE_IN_REG)"); | |
2933 | break; | |
2934 | case BOUND_SIMPLE: | |
2935 | printf_filtered ("(BOUND_SIMPLE)"); | |
2936 | break; | |
2937 | default: | |
a3f17187 | 2938 | printf_filtered (_("(unknown bound type)")); |
e9e79dd9 FF |
2939 | break; |
2940 | } | |
2941 | } | |
2942 | ||
c906108c SS |
2943 | static struct obstack dont_print_type_obstack; |
2944 | ||
2945 | void | |
fba45db2 | 2946 | recursive_dump_type (struct type *type, int spaces) |
c906108c SS |
2947 | { |
2948 | int idx; | |
2949 | ||
2950 | if (spaces == 0) | |
2951 | obstack_begin (&dont_print_type_obstack, 0); | |
2952 | ||
2953 | if (TYPE_NFIELDS (type) > 0 | |
2954 | || (TYPE_CPLUS_SPECIFIC (type) && TYPE_NFN_FIELDS (type) > 0)) | |
2955 | { | |
2956 | struct type **first_dont_print | |
c5aa993b | 2957 | = (struct type **) obstack_base (&dont_print_type_obstack); |
c906108c | 2958 | |
c5aa993b JM |
2959 | int i = (struct type **) obstack_next_free (&dont_print_type_obstack) |
2960 | - first_dont_print; | |
c906108c SS |
2961 | |
2962 | while (--i >= 0) | |
2963 | { | |
2964 | if (type == first_dont_print[i]) | |
2965 | { | |
2966 | printfi_filtered (spaces, "type node "); | |
d4f3574e | 2967 | gdb_print_host_address (type, gdb_stdout); |
a3f17187 | 2968 | printf_filtered (_(" <same as already seen type>\n")); |
c906108c SS |
2969 | return; |
2970 | } | |
2971 | } | |
2972 | ||
2973 | obstack_ptr_grow (&dont_print_type_obstack, type); | |
2974 | } | |
2975 | ||
2976 | printfi_filtered (spaces, "type node "); | |
d4f3574e | 2977 | gdb_print_host_address (type, gdb_stdout); |
c906108c SS |
2978 | printf_filtered ("\n"); |
2979 | printfi_filtered (spaces, "name '%s' (", | |
2980 | TYPE_NAME (type) ? TYPE_NAME (type) : "<NULL>"); | |
d4f3574e | 2981 | gdb_print_host_address (TYPE_NAME (type), gdb_stdout); |
c906108c | 2982 | printf_filtered (")\n"); |
e9e79dd9 FF |
2983 | printfi_filtered (spaces, "tagname '%s' (", |
2984 | TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : "<NULL>"); | |
2985 | gdb_print_host_address (TYPE_TAG_NAME (type), gdb_stdout); | |
2986 | printf_filtered (")\n"); | |
c906108c SS |
2987 | printfi_filtered (spaces, "code 0x%x ", TYPE_CODE (type)); |
2988 | switch (TYPE_CODE (type)) | |
2989 | { | |
c5aa993b JM |
2990 | case TYPE_CODE_UNDEF: |
2991 | printf_filtered ("(TYPE_CODE_UNDEF)"); | |
2992 | break; | |
2993 | case TYPE_CODE_PTR: | |
2994 | printf_filtered ("(TYPE_CODE_PTR)"); | |
2995 | break; | |
2996 | case TYPE_CODE_ARRAY: | |
2997 | printf_filtered ("(TYPE_CODE_ARRAY)"); | |
2998 | break; | |
2999 | case TYPE_CODE_STRUCT: | |
3000 | printf_filtered ("(TYPE_CODE_STRUCT)"); | |
3001 | break; | |
3002 | case TYPE_CODE_UNION: | |
3003 | printf_filtered ("(TYPE_CODE_UNION)"); | |
3004 | break; | |
3005 | case TYPE_CODE_ENUM: | |
3006 | printf_filtered ("(TYPE_CODE_ENUM)"); | |
3007 | break; | |
4f2aea11 MK |
3008 | case TYPE_CODE_FLAGS: |
3009 | printf_filtered ("(TYPE_CODE_FLAGS)"); | |
3010 | break; | |
c5aa993b JM |
3011 | case TYPE_CODE_FUNC: |
3012 | printf_filtered ("(TYPE_CODE_FUNC)"); | |
3013 | break; | |
3014 | case TYPE_CODE_INT: | |
3015 | printf_filtered ("(TYPE_CODE_INT)"); | |
3016 | break; | |
3017 | case TYPE_CODE_FLT: | |
3018 | printf_filtered ("(TYPE_CODE_FLT)"); | |
3019 | break; | |
3020 | case TYPE_CODE_VOID: | |
3021 | printf_filtered ("(TYPE_CODE_VOID)"); | |
3022 | break; | |
3023 | case TYPE_CODE_SET: | |
3024 | printf_filtered ("(TYPE_CODE_SET)"); | |
3025 | break; | |
3026 | case TYPE_CODE_RANGE: | |
3027 | printf_filtered ("(TYPE_CODE_RANGE)"); | |
3028 | break; | |
3029 | case TYPE_CODE_STRING: | |
3030 | printf_filtered ("(TYPE_CODE_STRING)"); | |
3031 | break; | |
e9e79dd9 FF |
3032 | case TYPE_CODE_BITSTRING: |
3033 | printf_filtered ("(TYPE_CODE_BITSTRING)"); | |
3034 | break; | |
c5aa993b JM |
3035 | case TYPE_CODE_ERROR: |
3036 | printf_filtered ("(TYPE_CODE_ERROR)"); | |
3037 | break; | |
0d5de010 DJ |
3038 | case TYPE_CODE_MEMBERPTR: |
3039 | printf_filtered ("(TYPE_CODE_MEMBERPTR)"); | |
3040 | break; | |
3041 | case TYPE_CODE_METHODPTR: | |
3042 | printf_filtered ("(TYPE_CODE_METHODPTR)"); | |
c5aa993b JM |
3043 | break; |
3044 | case TYPE_CODE_METHOD: | |
3045 | printf_filtered ("(TYPE_CODE_METHOD)"); | |
3046 | break; | |
3047 | case TYPE_CODE_REF: | |
3048 | printf_filtered ("(TYPE_CODE_REF)"); | |
3049 | break; | |
3050 | case TYPE_CODE_CHAR: | |
3051 | printf_filtered ("(TYPE_CODE_CHAR)"); | |
3052 | break; | |
3053 | case TYPE_CODE_BOOL: | |
3054 | printf_filtered ("(TYPE_CODE_BOOL)"); | |
3055 | break; | |
e9e79dd9 FF |
3056 | case TYPE_CODE_COMPLEX: |
3057 | printf_filtered ("(TYPE_CODE_COMPLEX)"); | |
3058 | break; | |
c5aa993b JM |
3059 | case TYPE_CODE_TYPEDEF: |
3060 | printf_filtered ("(TYPE_CODE_TYPEDEF)"); | |
3061 | break; | |
e9e79dd9 FF |
3062 | case TYPE_CODE_TEMPLATE: |
3063 | printf_filtered ("(TYPE_CODE_TEMPLATE)"); | |
3064 | break; | |
3065 | case TYPE_CODE_TEMPLATE_ARG: | |
3066 | printf_filtered ("(TYPE_CODE_TEMPLATE_ARG)"); | |
3067 | break; | |
5c4e30ca DC |
3068 | case TYPE_CODE_NAMESPACE: |
3069 | printf_filtered ("(TYPE_CODE_NAMESPACE)"); | |
3070 | break; | |
c5aa993b JM |
3071 | default: |
3072 | printf_filtered ("(UNKNOWN TYPE CODE)"); | |
3073 | break; | |
c906108c SS |
3074 | } |
3075 | puts_filtered ("\n"); | |
3076 | printfi_filtered (spaces, "length %d\n", TYPE_LENGTH (type)); | |
e9e79dd9 FF |
3077 | printfi_filtered (spaces, "upper_bound_type 0x%x ", |
3078 | TYPE_ARRAY_UPPER_BOUND_TYPE (type)); | |
3079 | print_bound_type (TYPE_ARRAY_UPPER_BOUND_TYPE (type)); | |
3080 | puts_filtered ("\n"); | |
3081 | printfi_filtered (spaces, "lower_bound_type 0x%x ", | |
3082 | TYPE_ARRAY_LOWER_BOUND_TYPE (type)); | |
3083 | print_bound_type (TYPE_ARRAY_LOWER_BOUND_TYPE (type)); | |
3084 | puts_filtered ("\n"); | |
c906108c | 3085 | printfi_filtered (spaces, "objfile "); |
d4f3574e | 3086 | gdb_print_host_address (TYPE_OBJFILE (type), gdb_stdout); |
c906108c SS |
3087 | printf_filtered ("\n"); |
3088 | printfi_filtered (spaces, "target_type "); | |
d4f3574e | 3089 | gdb_print_host_address (TYPE_TARGET_TYPE (type), gdb_stdout); |
c906108c SS |
3090 | printf_filtered ("\n"); |
3091 | if (TYPE_TARGET_TYPE (type) != NULL) | |
3092 | { | |
3093 | recursive_dump_type (TYPE_TARGET_TYPE (type), spaces + 2); | |
3094 | } | |
3095 | printfi_filtered (spaces, "pointer_type "); | |
d4f3574e | 3096 | gdb_print_host_address (TYPE_POINTER_TYPE (type), gdb_stdout); |
c906108c SS |
3097 | printf_filtered ("\n"); |
3098 | printfi_filtered (spaces, "reference_type "); | |
d4f3574e | 3099 | gdb_print_host_address (TYPE_REFERENCE_TYPE (type), gdb_stdout); |
c906108c | 3100 | printf_filtered ("\n"); |
2fdde8f8 DJ |
3101 | printfi_filtered (spaces, "type_chain "); |
3102 | gdb_print_host_address (TYPE_CHAIN (type), gdb_stdout); | |
e9e79dd9 | 3103 | printf_filtered ("\n"); |
2fdde8f8 DJ |
3104 | printfi_filtered (spaces, "instance_flags 0x%x", TYPE_INSTANCE_FLAGS (type)); |
3105 | if (TYPE_CONST (type)) | |
3106 | { | |
3107 | puts_filtered (" TYPE_FLAG_CONST"); | |
3108 | } | |
3109 | if (TYPE_VOLATILE (type)) | |
3110 | { | |
3111 | puts_filtered (" TYPE_FLAG_VOLATILE"); | |
3112 | } | |
3113 | if (TYPE_CODE_SPACE (type)) | |
3114 | { | |
3115 | puts_filtered (" TYPE_FLAG_CODE_SPACE"); | |
3116 | } | |
3117 | if (TYPE_DATA_SPACE (type)) | |
3118 | { | |
3119 | puts_filtered (" TYPE_FLAG_DATA_SPACE"); | |
3120 | } | |
8b2dbe47 KB |
3121 | if (TYPE_ADDRESS_CLASS_1 (type)) |
3122 | { | |
3123 | puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_1"); | |
3124 | } | |
3125 | if (TYPE_ADDRESS_CLASS_2 (type)) | |
3126 | { | |
3127 | puts_filtered (" TYPE_FLAG_ADDRESS_CLASS_2"); | |
3128 | } | |
2fdde8f8 | 3129 | puts_filtered ("\n"); |
c906108c | 3130 | printfi_filtered (spaces, "flags 0x%x", TYPE_FLAGS (type)); |
762a036f | 3131 | if (TYPE_UNSIGNED (type)) |
c906108c SS |
3132 | { |
3133 | puts_filtered (" TYPE_FLAG_UNSIGNED"); | |
3134 | } | |
762a036f FF |
3135 | if (TYPE_NOSIGN (type)) |
3136 | { | |
3137 | puts_filtered (" TYPE_FLAG_NOSIGN"); | |
3138 | } | |
3139 | if (TYPE_STUB (type)) | |
c906108c SS |
3140 | { |
3141 | puts_filtered (" TYPE_FLAG_STUB"); | |
3142 | } | |
762a036f FF |
3143 | if (TYPE_TARGET_STUB (type)) |
3144 | { | |
3145 | puts_filtered (" TYPE_FLAG_TARGET_STUB"); | |
3146 | } | |
3147 | if (TYPE_STATIC (type)) | |
3148 | { | |
3149 | puts_filtered (" TYPE_FLAG_STATIC"); | |
3150 | } | |
762a036f FF |
3151 | if (TYPE_PROTOTYPED (type)) |
3152 | { | |
3153 | puts_filtered (" TYPE_FLAG_PROTOTYPED"); | |
3154 | } | |
3155 | if (TYPE_INCOMPLETE (type)) | |
3156 | { | |
3157 | puts_filtered (" TYPE_FLAG_INCOMPLETE"); | |
3158 | } | |
762a036f FF |
3159 | if (TYPE_VARARGS (type)) |
3160 | { | |
3161 | puts_filtered (" TYPE_FLAG_VARARGS"); | |
3162 | } | |
f5f8a009 EZ |
3163 | /* This is used for things like AltiVec registers on ppc. Gcc emits |
3164 | an attribute for the array type, which tells whether or not we | |
3165 | have a vector, instead of a regular array. */ | |
3166 | if (TYPE_VECTOR (type)) | |
3167 | { | |
3168 | puts_filtered (" TYPE_FLAG_VECTOR"); | |
3169 | } | |
c906108c SS |
3170 | puts_filtered ("\n"); |
3171 | printfi_filtered (spaces, "nfields %d ", TYPE_NFIELDS (type)); | |
d4f3574e | 3172 | gdb_print_host_address (TYPE_FIELDS (type), gdb_stdout); |
c906108c SS |
3173 | puts_filtered ("\n"); |
3174 | for (idx = 0; idx < TYPE_NFIELDS (type); idx++) | |
3175 | { | |
3176 | printfi_filtered (spaces + 2, | |
3177 | "[%d] bitpos %d bitsize %d type ", | |
3178 | idx, TYPE_FIELD_BITPOS (type, idx), | |
3179 | TYPE_FIELD_BITSIZE (type, idx)); | |
d4f3574e | 3180 | gdb_print_host_address (TYPE_FIELD_TYPE (type, idx), gdb_stdout); |
c906108c SS |
3181 | printf_filtered (" name '%s' (", |
3182 | TYPE_FIELD_NAME (type, idx) != NULL | |
3183 | ? TYPE_FIELD_NAME (type, idx) | |
3184 | : "<NULL>"); | |
d4f3574e | 3185 | gdb_print_host_address (TYPE_FIELD_NAME (type, idx), gdb_stdout); |
c906108c SS |
3186 | printf_filtered (")\n"); |
3187 | if (TYPE_FIELD_TYPE (type, idx) != NULL) | |
3188 | { | |
3189 | recursive_dump_type (TYPE_FIELD_TYPE (type, idx), spaces + 4); | |
3190 | } | |
3191 | } | |
3192 | printfi_filtered (spaces, "vptr_basetype "); | |
d4f3574e | 3193 | gdb_print_host_address (TYPE_VPTR_BASETYPE (type), gdb_stdout); |
c906108c SS |
3194 | puts_filtered ("\n"); |
3195 | if (TYPE_VPTR_BASETYPE (type) != NULL) | |
3196 | { | |
3197 | recursive_dump_type (TYPE_VPTR_BASETYPE (type), spaces + 2); | |
3198 | } | |
3199 | printfi_filtered (spaces, "vptr_fieldno %d\n", TYPE_VPTR_FIELDNO (type)); | |
3200 | switch (TYPE_CODE (type)) | |
3201 | { | |
c5aa993b JM |
3202 | case TYPE_CODE_STRUCT: |
3203 | printfi_filtered (spaces, "cplus_stuff "); | |
d4f3574e | 3204 | gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type), gdb_stdout); |
c5aa993b JM |
3205 | puts_filtered ("\n"); |
3206 | print_cplus_stuff (type, spaces); | |
3207 | break; | |
c906108c | 3208 | |
701c159d AC |
3209 | case TYPE_CODE_FLT: |
3210 | printfi_filtered (spaces, "floatformat "); | |
8da61cc4 | 3211 | if (TYPE_FLOATFORMAT (type) == NULL) |
701c159d AC |
3212 | puts_filtered ("(null)"); |
3213 | else | |
8da61cc4 DJ |
3214 | { |
3215 | puts_filtered ("{ "); | |
3216 | if (TYPE_FLOATFORMAT (type)[0] == NULL | |
3217 | || TYPE_FLOATFORMAT (type)[0]->name == NULL) | |
3218 | puts_filtered ("(null)"); | |
3219 | else | |
3220 | puts_filtered (TYPE_FLOATFORMAT (type)[0]->name); | |
3221 | ||
3222 | puts_filtered (", "); | |
3223 | if (TYPE_FLOATFORMAT (type)[1] == NULL | |
3224 | || TYPE_FLOATFORMAT (type)[1]->name == NULL) | |
3225 | puts_filtered ("(null)"); | |
3226 | else | |
3227 | puts_filtered (TYPE_FLOATFORMAT (type)[1]->name); | |
3228 | ||
3229 | puts_filtered (" }"); | |
3230 | } | |
701c159d AC |
3231 | puts_filtered ("\n"); |
3232 | break; | |
3233 | ||
c5aa993b JM |
3234 | default: |
3235 | /* We have to pick one of the union types to be able print and test | |
7b83ea04 AC |
3236 | the value. Pick cplus_struct_type, even though we know it isn't |
3237 | any particular one. */ | |
c5aa993b | 3238 | printfi_filtered (spaces, "type_specific "); |
d4f3574e | 3239 | gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type), gdb_stdout); |
c5aa993b JM |
3240 | if (TYPE_CPLUS_SPECIFIC (type) != NULL) |
3241 | { | |
a3f17187 | 3242 | printf_filtered (_(" (unknown data form)")); |
c5aa993b JM |
3243 | } |
3244 | printf_filtered ("\n"); | |
3245 | break; | |
c906108c SS |
3246 | |
3247 | } | |
3248 | if (spaces == 0) | |
3249 | obstack_free (&dont_print_type_obstack, NULL); | |
3250 | } | |
3251 | ||
ae5a43e0 DJ |
3252 | /* Trivial helpers for the libiberty hash table, for mapping one |
3253 | type to another. */ | |
3254 | ||
3255 | struct type_pair | |
3256 | { | |
3257 | struct type *old, *new; | |
3258 | }; | |
3259 | ||
3260 | static hashval_t | |
3261 | type_pair_hash (const void *item) | |
3262 | { | |
3263 | const struct type_pair *pair = item; | |
3264 | return htab_hash_pointer (pair->old); | |
3265 | } | |
3266 | ||
3267 | static int | |
3268 | type_pair_eq (const void *item_lhs, const void *item_rhs) | |
3269 | { | |
3270 | const struct type_pair *lhs = item_lhs, *rhs = item_rhs; | |
3271 | return lhs->old == rhs->old; | |
3272 | } | |
3273 | ||
3274 | /* Allocate the hash table used by copy_type_recursive to walk | |
3275 | types without duplicates. We use OBJFILE's obstack, because | |
3276 | OBJFILE is about to be deleted. */ | |
3277 | ||
3278 | htab_t | |
3279 | create_copied_types_hash (struct objfile *objfile) | |
3280 | { | |
3281 | return htab_create_alloc_ex (1, type_pair_hash, type_pair_eq, | |
3282 | NULL, &objfile->objfile_obstack, | |
3283 | hashtab_obstack_allocate, | |
3284 | dummy_obstack_deallocate); | |
3285 | } | |
3286 | ||
3287 | /* Recursively copy (deep copy) TYPE, if it is associated with OBJFILE. | |
3288 | Return a new type allocated using malloc, a saved type if we have already | |
3289 | visited TYPE (using COPIED_TYPES), or TYPE if it is not associated with | |
3290 | OBJFILE. */ | |
3291 | ||
3292 | struct type * | |
3293 | copy_type_recursive (struct objfile *objfile, struct type *type, | |
3294 | htab_t copied_types) | |
3295 | { | |
3296 | struct type_pair *stored, pair; | |
3297 | void **slot; | |
3298 | struct type *new_type; | |
3299 | ||
3300 | if (TYPE_OBJFILE (type) == NULL) | |
3301 | return type; | |
3302 | ||
3303 | /* This type shouldn't be pointing to any types in other objfiles; if | |
3304 | it did, the type might disappear unexpectedly. */ | |
3305 | gdb_assert (TYPE_OBJFILE (type) == objfile); | |
3306 | ||
3307 | pair.old = type; | |
3308 | slot = htab_find_slot (copied_types, &pair, INSERT); | |
3309 | if (*slot != NULL) | |
3310 | return ((struct type_pair *) *slot)->new; | |
3311 | ||
3312 | new_type = alloc_type (NULL); | |
3313 | ||
3314 | /* We must add the new type to the hash table immediately, in case | |
3315 | we encounter this type again during a recursive call below. */ | |
3316 | stored = xmalloc (sizeof (struct type_pair)); | |
3317 | stored->old = type; | |
3318 | stored->new = new_type; | |
3319 | *slot = stored; | |
3320 | ||
3321 | /* Copy the common fields of types. */ | |
3322 | TYPE_CODE (new_type) = TYPE_CODE (type); | |
3323 | TYPE_ARRAY_UPPER_BOUND_TYPE (new_type) = TYPE_ARRAY_UPPER_BOUND_TYPE (type); | |
3324 | TYPE_ARRAY_LOWER_BOUND_TYPE (new_type) = TYPE_ARRAY_LOWER_BOUND_TYPE (type); | |
3325 | if (TYPE_NAME (type)) | |
3326 | TYPE_NAME (new_type) = xstrdup (TYPE_NAME (type)); | |
3327 | if (TYPE_TAG_NAME (type)) | |
3328 | TYPE_TAG_NAME (new_type) = xstrdup (TYPE_TAG_NAME (type)); | |
3329 | TYPE_FLAGS (new_type) = TYPE_FLAGS (type); | |
3330 | TYPE_VPTR_FIELDNO (new_type) = TYPE_VPTR_FIELDNO (type); | |
3331 | ||
3332 | TYPE_INSTANCE_FLAGS (new_type) = TYPE_INSTANCE_FLAGS (type); | |
3333 | TYPE_LENGTH (new_type) = TYPE_LENGTH (type); | |
3334 | ||
3335 | /* Copy the fields. */ | |
3336 | TYPE_NFIELDS (new_type) = TYPE_NFIELDS (type); | |
3337 | if (TYPE_NFIELDS (type)) | |
3338 | { | |
3339 | int i, nfields; | |
3340 | ||
3341 | nfields = TYPE_NFIELDS (type); | |
3342 | TYPE_FIELDS (new_type) = xmalloc (sizeof (struct field) * nfields); | |
3343 | for (i = 0; i < nfields; i++) | |
3344 | { | |
3345 | TYPE_FIELD_ARTIFICIAL (new_type, i) = TYPE_FIELD_ARTIFICIAL (type, i); | |
3346 | TYPE_FIELD_BITSIZE (new_type, i) = TYPE_FIELD_BITSIZE (type, i); | |
3347 | if (TYPE_FIELD_TYPE (type, i)) | |
3348 | TYPE_FIELD_TYPE (new_type, i) | |
3349 | = copy_type_recursive (objfile, TYPE_FIELD_TYPE (type, i), | |
3350 | copied_types); | |
3351 | if (TYPE_FIELD_NAME (type, i)) | |
3352 | TYPE_FIELD_NAME (new_type, i) = xstrdup (TYPE_FIELD_NAME (type, i)); | |
3353 | if (TYPE_FIELD_STATIC_HAS_ADDR (type, i)) | |
3354 | SET_FIELD_PHYSADDR (TYPE_FIELD (new_type, i), | |
3355 | TYPE_FIELD_STATIC_PHYSADDR (type, i)); | |
3356 | else if (TYPE_FIELD_STATIC (type, i)) | |
3357 | SET_FIELD_PHYSNAME (TYPE_FIELD (new_type, i), | |
3358 | xstrdup (TYPE_FIELD_STATIC_PHYSNAME (type, i))); | |
3359 | else | |
3360 | { | |
3361 | TYPE_FIELD_BITPOS (new_type, i) = TYPE_FIELD_BITPOS (type, i); | |
3362 | TYPE_FIELD_STATIC_KIND (new_type, i) = 0; | |
3363 | } | |
3364 | } | |
3365 | } | |
3366 | ||
3367 | /* Copy pointers to other types. */ | |
3368 | if (TYPE_TARGET_TYPE (type)) | |
3369 | TYPE_TARGET_TYPE (new_type) = copy_type_recursive (objfile, | |
3370 | TYPE_TARGET_TYPE (type), | |
3371 | copied_types); | |
3372 | if (TYPE_VPTR_BASETYPE (type)) | |
3373 | TYPE_VPTR_BASETYPE (new_type) = copy_type_recursive (objfile, | |
3374 | TYPE_VPTR_BASETYPE (type), | |
3375 | copied_types); | |
3376 | /* Maybe copy the type_specific bits. | |
3377 | ||
3378 | NOTE drow/2005-12-09: We do not copy the C++-specific bits like | |
3379 | base classes and methods. There's no fundamental reason why we | |
3380 | can't, but at the moment it is not needed. */ | |
3381 | ||
3382 | if (TYPE_CODE (type) == TYPE_CODE_FLT) | |
d5d6fca5 | 3383 | TYPE_FLOATFORMAT (new_type) = TYPE_FLOATFORMAT (type); |
ae5a43e0 DJ |
3384 | else if (TYPE_CODE (type) == TYPE_CODE_STRUCT |
3385 | || TYPE_CODE (type) == TYPE_CODE_UNION | |
3386 | || TYPE_CODE (type) == TYPE_CODE_TEMPLATE | |
3387 | || TYPE_CODE (type) == TYPE_CODE_NAMESPACE) | |
3388 | INIT_CPLUS_SPECIFIC (new_type); | |
3389 | ||
3390 | return new_type; | |
3391 | } | |
3392 | ||
8da61cc4 DJ |
3393 | static struct type * |
3394 | build_flt (int bit, char *name, const struct floatformat **floatformats) | |
3395 | { | |
3396 | struct type *t; | |
3397 | ||
3398 | if (bit == -1) | |
3399 | { | |
3400 | gdb_assert (floatformats != NULL); | |
3401 | gdb_assert (floatformats[0] != NULL && floatformats[1] != NULL); | |
3402 | bit = floatformats[0]->totalsize; | |
3403 | } | |
3404 | gdb_assert (bit >= 0); | |
3405 | ||
3406 | t = init_type (TYPE_CODE_FLT, bit / TARGET_CHAR_BIT, 0, name, NULL); | |
3407 | TYPE_FLOATFORMAT (t) = floatformats; | |
3408 | return t; | |
3409 | } | |
3410 | ||
c906108c | 3411 | static void |
fba45db2 | 3412 | build_gdbtypes (void) |
c906108c | 3413 | { |
2372d65a JB |
3414 | builtin_type_void = |
3415 | init_type (TYPE_CODE_VOID, 1, | |
3416 | 0, | |
3417 | "void", (struct objfile *) NULL); | |
c906108c SS |
3418 | builtin_type_char = |
3419 | init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT, | |
4e409299 | 3420 | (TYPE_FLAG_NOSIGN |
6c6b19fd UW |
3421 | | (gdbarch_char_signed (current_gdbarch) ? |
3422 | 0 : TYPE_FLAG_UNSIGNED)), | |
c906108c | 3423 | "char", (struct objfile *) NULL); |
c5aa993b | 3424 | builtin_type_true_char = |
9e0b60a8 JM |
3425 | init_type (TYPE_CODE_CHAR, TARGET_CHAR_BIT / TARGET_CHAR_BIT, |
3426 | 0, | |
3427 | "true character", (struct objfile *) NULL); | |
c906108c SS |
3428 | builtin_type_signed_char = |
3429 | init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT, | |
3430 | 0, | |
3431 | "signed char", (struct objfile *) NULL); | |
3432 | builtin_type_unsigned_char = | |
3433 | init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT, | |
3434 | TYPE_FLAG_UNSIGNED, | |
3435 | "unsigned char", (struct objfile *) NULL); | |
3436 | builtin_type_short = | |
9a76efb6 UW |
3437 | init_type (TYPE_CODE_INT, |
3438 | gdbarch_short_bit (current_gdbarch) / TARGET_CHAR_BIT, | |
3439 | 0, "short", (struct objfile *) NULL); | |
c906108c | 3440 | builtin_type_unsigned_short = |
9a76efb6 UW |
3441 | init_type (TYPE_CODE_INT, |
3442 | gdbarch_short_bit (current_gdbarch) / TARGET_CHAR_BIT, | |
3443 | TYPE_FLAG_UNSIGNED, "unsigned short", (struct objfile *) NULL); | |
c906108c | 3444 | builtin_type_int = |
9a76efb6 UW |
3445 | init_type (TYPE_CODE_INT, |
3446 | gdbarch_int_bit (current_gdbarch) / TARGET_CHAR_BIT, | |
3447 | 0, "int", (struct objfile *) NULL); | |
c906108c | 3448 | builtin_type_unsigned_int = |
9a76efb6 UW |
3449 | init_type (TYPE_CODE_INT, |
3450 | gdbarch_int_bit (current_gdbarch) / TARGET_CHAR_BIT, | |
3451 | TYPE_FLAG_UNSIGNED, "unsigned int", (struct objfile *) NULL); | |
c906108c | 3452 | builtin_type_long = |
9a76efb6 UW |
3453 | init_type (TYPE_CODE_INT, |
3454 | gdbarch_long_bit (current_gdbarch) / TARGET_CHAR_BIT, | |
3455 | 0, "long", (struct objfile *) NULL); | |
c906108c | 3456 | builtin_type_unsigned_long = |
9a76efb6 UW |
3457 | init_type (TYPE_CODE_INT, |
3458 | gdbarch_long_bit (current_gdbarch) / TARGET_CHAR_BIT, | |
3459 | TYPE_FLAG_UNSIGNED, "unsigned long", (struct objfile *) NULL); | |
c906108c | 3460 | builtin_type_long_long = |
9a76efb6 UW |
3461 | init_type (TYPE_CODE_INT, |
3462 | gdbarch_long_long_bit (current_gdbarch) / TARGET_CHAR_BIT, | |
3463 | 0, "long long", (struct objfile *) NULL); | |
c5aa993b | 3464 | builtin_type_unsigned_long_long = |
9a76efb6 UW |
3465 | init_type (TYPE_CODE_INT, |
3466 | gdbarch_long_long_bit (current_gdbarch) / TARGET_CHAR_BIT, | |
3467 | TYPE_FLAG_UNSIGNED, | |
c906108c | 3468 | "unsigned long long", (struct objfile *) NULL); |
ea06eb3d UW |
3469 | |
3470 | builtin_type_float | |
3471 | = build_flt (gdbarch_float_bit (current_gdbarch), "float", | |
3472 | gdbarch_float_format (current_gdbarch)); | |
3473 | builtin_type_double | |
3474 | = build_flt (gdbarch_double_bit (current_gdbarch), "double", | |
3475 | gdbarch_double_format (current_gdbarch)); | |
3476 | builtin_type_long_double | |
3477 | = build_flt (gdbarch_long_double_bit (current_gdbarch), "long double", | |
3478 | gdbarch_long_double_format | |
3479 | (current_gdbarch)); | |
8da61cc4 | 3480 | |
c906108c | 3481 | builtin_type_complex = |
ea06eb3d UW |
3482 | init_type (TYPE_CODE_COMPLEX, |
3483 | 2 * gdbarch_float_bit (current_gdbarch) / TARGET_CHAR_BIT, | |
c906108c SS |
3484 | 0, |
3485 | "complex", (struct objfile *) NULL); | |
3486 | TYPE_TARGET_TYPE (builtin_type_complex) = builtin_type_float; | |
3487 | builtin_type_double_complex = | |
ea06eb3d UW |
3488 | init_type (TYPE_CODE_COMPLEX, |
3489 | 2 * gdbarch_double_bit (current_gdbarch) / TARGET_CHAR_BIT, | |
c906108c SS |
3490 | 0, |
3491 | "double complex", (struct objfile *) NULL); | |
3492 | TYPE_TARGET_TYPE (builtin_type_double_complex) = builtin_type_double; | |
3493 | builtin_type_string = | |
3494 | init_type (TYPE_CODE_STRING, TARGET_CHAR_BIT / TARGET_CHAR_BIT, | |
3495 | 0, | |
3496 | "string", (struct objfile *) NULL); | |
c906108c SS |
3497 | builtin_type_bool = |
3498 | init_type (TYPE_CODE_BOOL, TARGET_CHAR_BIT / TARGET_CHAR_BIT, | |
3499 | 0, | |
3500 | "bool", (struct objfile *) NULL); | |
3501 | ||
c5aa993b | 3502 | /* Add user knob for controlling resolution of opaque types */ |
5bf193a2 AC |
3503 | add_setshow_boolean_cmd ("opaque-type-resolution", class_support, |
3504 | &opaque_type_resolution, _("\ | |
3505 | Set resolution of opaque struct/class/union types (if set before loading symbols)."), _("\ | |
3506 | Show resolution of opaque struct/class/union types (if set before loading symbols)."), NULL, | |
3507 | NULL, | |
920d2a44 | 3508 | show_opaque_type_resolution, |
5bf193a2 | 3509 | &setlist, &showlist); |
c906108c SS |
3510 | opaque_type_resolution = 1; |
3511 | ||
917317f4 JM |
3512 | /* Build SIMD types. */ |
3513 | builtin_type_v4sf | |
3514 | = init_simd_type ("__builtin_v4sf", builtin_type_float, "f", 4); | |
c2d11a7d JM |
3515 | builtin_type_v4si |
3516 | = init_simd_type ("__builtin_v4si", builtin_type_int32, "f", 4); | |
08cf96df EZ |
3517 | builtin_type_v16qi |
3518 | = init_simd_type ("__builtin_v16qi", builtin_type_int8, "f", 16); | |
c2d11a7d JM |
3519 | builtin_type_v8qi |
3520 | = init_simd_type ("__builtin_v8qi", builtin_type_int8, "f", 8); | |
08cf96df EZ |
3521 | builtin_type_v8hi |
3522 | = init_simd_type ("__builtin_v8hi", builtin_type_int16, "f", 8); | |
c2d11a7d JM |
3523 | builtin_type_v4hi |
3524 | = init_simd_type ("__builtin_v4hi", builtin_type_int16, "f", 4); | |
3525 | builtin_type_v2si | |
3526 | = init_simd_type ("__builtin_v2si", builtin_type_int32, "f", 2); | |
c4093a6a | 3527 | |
ac3aafc7 | 3528 | /* 128 bit vectors. */ |
3139facc | 3529 | builtin_type_v2_double = init_vector_type (builtin_type_double, 2); |
ac3aafc7 | 3530 | builtin_type_v4_float = init_vector_type (builtin_type_float, 4); |
3139facc | 3531 | builtin_type_v2_int64 = init_vector_type (builtin_type_int64, 2); |
ac3aafc7 EZ |
3532 | builtin_type_v4_int32 = init_vector_type (builtin_type_int32, 4); |
3533 | builtin_type_v8_int16 = init_vector_type (builtin_type_int16, 8); | |
3534 | builtin_type_v16_int8 = init_vector_type (builtin_type_int8, 16); | |
3535 | /* 64 bit vectors. */ | |
6599f021 | 3536 | builtin_type_v2_float = init_vector_type (builtin_type_float, 2); |
ac3aafc7 EZ |
3537 | builtin_type_v2_int32 = init_vector_type (builtin_type_int32, 2); |
3538 | builtin_type_v4_int16 = init_vector_type (builtin_type_int16, 4); | |
3539 | builtin_type_v8_int8 = init_vector_type (builtin_type_int8, 8); | |
3540 | ||
b063e7a2 AC |
3541 | /* Vector types. */ |
3542 | builtin_type_vec64 = build_builtin_type_vec64 (); | |
ac3aafc7 | 3543 | builtin_type_vec128 = build_builtin_type_vec128 (); |
08cf96df | 3544 | |
c4093a6a | 3545 | /* Pointer/Address types. */ |
ee3a7b7f JB |
3546 | |
3547 | /* NOTE: on some targets, addresses and pointers are not necessarily | |
3548 | the same --- for example, on the D10V, pointers are 16 bits long, | |
3549 | but addresses are 32 bits long. See doc/gdbint.texinfo, | |
3550 | ``Pointers Are Not Always Addresses''. | |
3551 | ||
3552 | The upshot is: | |
3553 | - gdb's `struct type' always describes the target's | |
3554 | representation. | |
3555 | - gdb's `struct value' objects should always hold values in | |
3556 | target form. | |
3557 | - gdb's CORE_ADDR values are addresses in the unified virtual | |
3558 | address space that the assembler and linker work with. Thus, | |
3559 | since target_read_memory takes a CORE_ADDR as an argument, it | |
3560 | can access any memory on the target, even if the processor has | |
3561 | separate code and data address spaces. | |
3562 | ||
3563 | So, for example: | |
3564 | - If v is a value holding a D10V code pointer, its contents are | |
3565 | in target form: a big-endian address left-shifted two bits. | |
3566 | - If p is a D10V pointer type, TYPE_LENGTH (p) == 2, just as | |
3567 | sizeof (void *) == 2 on the target. | |
3568 | ||
3569 | In this context, builtin_type_CORE_ADDR is a bit odd: it's a | |
3570 | target type for a value the target will never see. It's only | |
3571 | used to hold the values of (typeless) linker symbols, which are | |
3572 | indeed in the unified virtual address space. */ | |
090a2205 | 3573 | builtin_type_void_data_ptr = make_pointer_type (builtin_type_void, NULL); |
ee3a7b7f JB |
3574 | builtin_type_void_func_ptr |
3575 | = lookup_pointer_type (lookup_function_type (builtin_type_void)); | |
c4093a6a | 3576 | builtin_type_CORE_ADDR = |
52204a0b | 3577 | init_type (TYPE_CODE_INT, TARGET_ADDR_BIT / 8, |
c4093a6a JM |
3578 | TYPE_FLAG_UNSIGNED, |
3579 | "__CORE_ADDR", (struct objfile *) NULL); | |
3580 | builtin_type_bfd_vma = | |
3581 | init_type (TYPE_CODE_INT, TARGET_BFD_VMA_BIT / 8, | |
3582 | TYPE_FLAG_UNSIGNED, | |
3583 | "__bfd_vma", (struct objfile *) NULL); | |
c906108c SS |
3584 | } |
3585 | ||
000177f0 AC |
3586 | static struct gdbarch_data *gdbtypes_data; |
3587 | ||
3588 | const struct builtin_type * | |
3589 | builtin_type (struct gdbarch *gdbarch) | |
3590 | { | |
3591 | return gdbarch_data (gdbarch, gdbtypes_data); | |
3592 | } | |
3593 | ||
70bd8e24 | 3594 | |
70bd8e24 AC |
3595 | static struct type * |
3596 | build_complex (int bit, char *name, struct type *target_type) | |
3597 | { | |
3598 | struct type *t; | |
3599 | if (bit <= 0 || target_type == builtin_type_error) | |
3600 | { | |
3601 | gdb_assert (builtin_type_error != NULL); | |
3602 | return builtin_type_error; | |
3603 | } | |
3604 | t = init_type (TYPE_CODE_COMPLEX, 2 * bit / TARGET_CHAR_BIT, | |
3605 | 0, name, (struct objfile *) NULL); | |
3606 | TYPE_TARGET_TYPE (t) = target_type; | |
3607 | return t; | |
3608 | } | |
3609 | ||
000177f0 AC |
3610 | static void * |
3611 | gdbtypes_post_init (struct gdbarch *gdbarch) | |
3612 | { | |
3613 | struct builtin_type *builtin_type | |
3614 | = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct builtin_type); | |
3615 | ||
3616 | builtin_type->builtin_void = | |
3617 | init_type (TYPE_CODE_VOID, 1, | |
3618 | 0, | |
3619 | "void", (struct objfile *) NULL); | |
3620 | builtin_type->builtin_char = | |
3621 | init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT, | |
3622 | (TYPE_FLAG_NOSIGN | |
6c6b19fd UW |
3623 | | (gdbarch_char_signed (current_gdbarch) ? |
3624 | 0 : TYPE_FLAG_UNSIGNED)), | |
000177f0 | 3625 | "char", (struct objfile *) NULL); |
685419e2 | 3626 | builtin_type->builtin_true_char = |
000177f0 AC |
3627 | init_type (TYPE_CODE_CHAR, TARGET_CHAR_BIT / TARGET_CHAR_BIT, |
3628 | 0, | |
3629 | "true character", (struct objfile *) NULL); | |
3630 | builtin_type->builtin_signed_char = | |
3631 | init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT, | |
3632 | 0, | |
3633 | "signed char", (struct objfile *) NULL); | |
3634 | builtin_type->builtin_unsigned_char = | |
3635 | init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT, | |
3636 | TYPE_FLAG_UNSIGNED, | |
3637 | "unsigned char", (struct objfile *) NULL); | |
3638 | builtin_type->builtin_short = | |
9a76efb6 UW |
3639 | init_type |
3640 | (TYPE_CODE_INT, gdbarch_short_bit (current_gdbarch) / TARGET_CHAR_BIT, | |
3641 | 0, "short", (struct objfile *) NULL); | |
000177f0 | 3642 | builtin_type->builtin_unsigned_short = |
9a76efb6 UW |
3643 | init_type |
3644 | (TYPE_CODE_INT, gdbarch_short_bit (current_gdbarch) / TARGET_CHAR_BIT, | |
3645 | TYPE_FLAG_UNSIGNED, "unsigned short", (struct objfile *) NULL); | |
000177f0 | 3646 | builtin_type->builtin_int = |
9a76efb6 UW |
3647 | init_type |
3648 | (TYPE_CODE_INT, gdbarch_int_bit (current_gdbarch) / TARGET_CHAR_BIT, | |
3649 | 0, "int", (struct objfile *) NULL); | |
000177f0 | 3650 | builtin_type->builtin_unsigned_int = |
9a76efb6 UW |
3651 | init_type |
3652 | (TYPE_CODE_INT, gdbarch_int_bit (current_gdbarch) / TARGET_CHAR_BIT, | |
3653 | TYPE_FLAG_UNSIGNED, "unsigned int", (struct objfile *) NULL); | |
000177f0 | 3654 | builtin_type->builtin_long = |
9a76efb6 UW |
3655 | init_type |
3656 | (TYPE_CODE_INT, gdbarch_long_bit (current_gdbarch) / TARGET_CHAR_BIT, | |
3657 | 0, "long", (struct objfile *) NULL); | |
000177f0 | 3658 | builtin_type->builtin_unsigned_long = |
9a76efb6 UW |
3659 | init_type |
3660 | (TYPE_CODE_INT, gdbarch_long_bit (current_gdbarch) / TARGET_CHAR_BIT, | |
3661 | TYPE_FLAG_UNSIGNED, "unsigned long", (struct objfile *) NULL); | |
000177f0 | 3662 | builtin_type->builtin_long_long = |
9a76efb6 UW |
3663 | init_type (TYPE_CODE_INT, |
3664 | gdbarch_long_long_bit (current_gdbarch) / TARGET_CHAR_BIT, | |
3665 | 0, "long long", (struct objfile *) NULL); | |
000177f0 | 3666 | builtin_type->builtin_unsigned_long_long = |
9a76efb6 UW |
3667 | init_type (TYPE_CODE_INT, |
3668 | gdbarch_long_long_bit (current_gdbarch) / TARGET_CHAR_BIT, | |
3669 | TYPE_FLAG_UNSIGNED, "unsigned long long", | |
3670 | (struct objfile *) NULL); | |
70bd8e24 AC |
3671 | builtin_type->builtin_float |
3672 | = build_flt (gdbarch_float_bit (gdbarch), "float", | |
3673 | gdbarch_float_format (gdbarch)); | |
3674 | builtin_type->builtin_double | |
3675 | = build_flt (gdbarch_double_bit (gdbarch), "double", | |
3676 | gdbarch_double_format (gdbarch)); | |
3677 | builtin_type->builtin_long_double | |
3678 | = build_flt (gdbarch_long_double_bit (gdbarch), "long double", | |
3679 | gdbarch_long_double_format (gdbarch)); | |
3680 | builtin_type->builtin_complex | |
3681 | = build_complex (gdbarch_float_bit (gdbarch), "complex", | |
3682 | builtin_type->builtin_float); | |
3683 | builtin_type->builtin_double_complex | |
3684 | = build_complex (gdbarch_double_bit (gdbarch), "double complex", | |
3685 | builtin_type->builtin_double); | |
000177f0 AC |
3686 | builtin_type->builtin_string = |
3687 | init_type (TYPE_CODE_STRING, TARGET_CHAR_BIT / TARGET_CHAR_BIT, | |
3688 | 0, | |
3689 | "string", (struct objfile *) NULL); | |
000177f0 AC |
3690 | builtin_type->builtin_bool = |
3691 | init_type (TYPE_CODE_BOOL, TARGET_CHAR_BIT / TARGET_CHAR_BIT, | |
3692 | 0, | |
3693 | "bool", (struct objfile *) NULL); | |
3694 | ||
3695 | /* Pointer/Address types. */ | |
3696 | ||
3697 | /* NOTE: on some targets, addresses and pointers are not necessarily | |
3698 | the same --- for example, on the D10V, pointers are 16 bits long, | |
3699 | but addresses are 32 bits long. See doc/gdbint.texinfo, | |
3700 | ``Pointers Are Not Always Addresses''. | |
3701 | ||
3702 | The upshot is: | |
3703 | - gdb's `struct type' always describes the target's | |
3704 | representation. | |
3705 | - gdb's `struct value' objects should always hold values in | |
3706 | target form. | |
3707 | - gdb's CORE_ADDR values are addresses in the unified virtual | |
3708 | address space that the assembler and linker work with. Thus, | |
3709 | since target_read_memory takes a CORE_ADDR as an argument, it | |
3710 | can access any memory on the target, even if the processor has | |
3711 | separate code and data address spaces. | |
3712 | ||
3713 | So, for example: | |
3714 | - If v is a value holding a D10V code pointer, its contents are | |
3715 | in target form: a big-endian address left-shifted two bits. | |
3716 | - If p is a D10V pointer type, TYPE_LENGTH (p) == 2, just as | |
3717 | sizeof (void *) == 2 on the target. | |
3718 | ||
3719 | In this context, builtin_type->CORE_ADDR is a bit odd: it's a | |
3720 | target type for a value the target will never see. It's only | |
3721 | used to hold the values of (typeless) linker symbols, which are | |
3722 | indeed in the unified virtual address space. */ | |
3723 | builtin_type->builtin_data_ptr | |
3724 | = make_pointer_type (builtin_type->builtin_void, NULL); | |
3725 | builtin_type->builtin_func_ptr | |
3726 | = lookup_pointer_type (lookup_function_type (builtin_type->builtin_void)); | |
3727 | builtin_type->builtin_core_addr = | |
3728 | init_type (TYPE_CODE_INT, TARGET_ADDR_BIT / 8, | |
3729 | TYPE_FLAG_UNSIGNED, | |
3730 | "__CORE_ADDR", (struct objfile *) NULL); | |
3731 | ||
3732 | return builtin_type; | |
3733 | } | |
3734 | ||
a14ed312 | 3735 | extern void _initialize_gdbtypes (void); |
c906108c | 3736 | void |
fba45db2 | 3737 | _initialize_gdbtypes (void) |
c906108c | 3738 | { |
5d161b24 | 3739 | struct cmd_list_element *c; |
7ad6570d | 3740 | |
2372d65a JB |
3741 | /* FIXME: Why don't the following types need to be arch-swapped? |
3742 | See the comment at the top of the calls to | |
3743 | DEPRECATED_REGISTER_GDBARCH_SWAP below. */ | |
7ad6570d AC |
3744 | builtin_type_int0 = |
3745 | init_type (TYPE_CODE_INT, 0 / 8, | |
3746 | 0, | |
3747 | "int0_t", (struct objfile *) NULL); | |
3748 | builtin_type_int8 = | |
3749 | init_type (TYPE_CODE_INT, 8 / 8, | |
3750 | 0, | |
3751 | "int8_t", (struct objfile *) NULL); | |
3752 | builtin_type_uint8 = | |
3753 | init_type (TYPE_CODE_INT, 8 / 8, | |
3754 | TYPE_FLAG_UNSIGNED, | |
3755 | "uint8_t", (struct objfile *) NULL); | |
3756 | builtin_type_int16 = | |
3757 | init_type (TYPE_CODE_INT, 16 / 8, | |
3758 | 0, | |
3759 | "int16_t", (struct objfile *) NULL); | |
3760 | builtin_type_uint16 = | |
3761 | init_type (TYPE_CODE_INT, 16 / 8, | |
3762 | TYPE_FLAG_UNSIGNED, | |
3763 | "uint16_t", (struct objfile *) NULL); | |
3764 | builtin_type_int32 = | |
3765 | init_type (TYPE_CODE_INT, 32 / 8, | |
3766 | 0, | |
3767 | "int32_t", (struct objfile *) NULL); | |
3768 | builtin_type_uint32 = | |
3769 | init_type (TYPE_CODE_INT, 32 / 8, | |
3770 | TYPE_FLAG_UNSIGNED, | |
3771 | "uint32_t", (struct objfile *) NULL); | |
3772 | builtin_type_int64 = | |
3773 | init_type (TYPE_CODE_INT, 64 / 8, | |
3774 | 0, | |
3775 | "int64_t", (struct objfile *) NULL); | |
3776 | builtin_type_uint64 = | |
3777 | init_type (TYPE_CODE_INT, 64 / 8, | |
3778 | TYPE_FLAG_UNSIGNED, | |
3779 | "uint64_t", (struct objfile *) NULL); | |
3780 | builtin_type_int128 = | |
3781 | init_type (TYPE_CODE_INT, 128 / 8, | |
3782 | 0, | |
3783 | "int128_t", (struct objfile *) NULL); | |
3784 | builtin_type_uint128 = | |
3785 | init_type (TYPE_CODE_INT, 128 / 8, | |
3786 | TYPE_FLAG_UNSIGNED, | |
3787 | "uint128_t", (struct objfile *) NULL); | |
3788 | ||
c906108c | 3789 | build_gdbtypes (); |
0f71a2f6 | 3790 | |
000177f0 AC |
3791 | gdbtypes_data = gdbarch_data_register_post_init (gdbtypes_post_init); |
3792 | ||
0f71a2f6 JM |
3793 | /* FIXME - For the moment, handle types by swapping them in and out. |
3794 | Should be using the per-architecture data-pointer and a large | |
2372d65a JB |
3795 | struct. |
3796 | ||
3797 | Note that any type T that we might create a 'T *' type for must | |
3798 | be arch-swapped: we cache a type's 'T *' type in the pointer_type | |
3799 | field, so if we change architectures but don't swap T, then | |
3800 | lookup_pointer_type will start handing out pointer types made for | |
3801 | a different architecture. */ | |
3802 | DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_void); | |
046a4708 AC |
3803 | DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_char); |
3804 | DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_short); | |
3805 | DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_int); | |
3806 | DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_long); | |
3807 | DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_long_long); | |
3808 | DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_signed_char); | |
3809 | DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_unsigned_char); | |
3810 | DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_unsigned_short); | |
3811 | DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_unsigned_int); | |
3812 | DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_unsigned_long); | |
3813 | DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_unsigned_long_long); | |
3814 | DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_float); | |
3815 | DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_double); | |
3816 | DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_long_double); | |
3817 | DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_complex); | |
3818 | DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_double_complex); | |
3819 | DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_string); | |
046a4708 AC |
3820 | DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v4sf); |
3821 | DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v4si); | |
3822 | DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v16qi); | |
3823 | DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v8qi); | |
3824 | DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v8hi); | |
3825 | DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v4hi); | |
3826 | DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v2si); | |
3827 | DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v2_double); | |
3828 | DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v4_float); | |
3829 | DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v2_int64); | |
3830 | DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v4_int32); | |
3831 | DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v8_int16); | |
3832 | DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v16_int8); | |
3833 | DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v2_float); | |
3834 | DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v2_int32); | |
3835 | DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v8_int8); | |
3836 | DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_v4_int16); | |
3837 | DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_vec128); | |
046a4708 AC |
3838 | DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_void_data_ptr); |
3839 | DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_void_func_ptr); | |
3840 | DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_CORE_ADDR); | |
3841 | DEPRECATED_REGISTER_GDBARCH_SWAP (builtin_type_bfd_vma); | |
3842 | deprecated_register_gdbarch_swap (NULL, 0, build_gdbtypes); | |
5d161b24 | 3843 | |
598f52df | 3844 | /* Note: These types do not need to be swapped - they are target |
2372d65a JB |
3845 | neutral. FIXME: Are you sure? See the comment above the calls |
3846 | to DEPRECATED_REGISTER_GDBARCH_SWAP above. */ | |
8da61cc4 DJ |
3847 | builtin_type_ieee_single |
3848 | = build_flt (-1, "builtin_type_ieee_single", floatformats_ieee_single); | |
3849 | builtin_type_ieee_double | |
3850 | = build_flt (-1, "builtin_type_ieee_double", floatformats_ieee_double); | |
3851 | builtin_type_i387_ext | |
3852 | = build_flt (-1, "builtin_type_i387_ext", floatformats_i387_ext); | |
3853 | builtin_type_m68881_ext | |
3854 | = build_flt (-1, "builtin_type_m68881_ext", floatformats_m68881_ext); | |
3855 | builtin_type_arm_ext | |
3856 | = build_flt (-1, "builtin_type_arm_ext", floatformats_arm_ext); | |
3857 | builtin_type_ia64_spill | |
3858 | = build_flt (-1, "builtin_type_ia64_spill", floatformats_ia64_spill); | |
3859 | builtin_type_ia64_quad | |
3860 | = build_flt (-1, "builtin_type_ia64_quad", floatformats_ia64_quad); | |
598f52df | 3861 | |
85c07804 AC |
3862 | add_setshow_zinteger_cmd ("overload", no_class, &overload_debug, _("\ |
3863 | Set debugging of C++ overloading."), _("\ | |
3864 | Show debugging of C++ overloading."), _("\ | |
3865 | When enabled, ranking of the functions is displayed."), | |
3866 | NULL, | |
920d2a44 | 3867 | show_overload_debug, |
85c07804 | 3868 | &setdebuglist, &showdebuglist); |
c906108c | 3869 | } |