Approved by Jim Blandy:
[deliverable/binutils-gdb.git] / gdb / gdbtypes.c
1 /* Support routines for manipulating internal types for GDB.
2 Copyright 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000
3 Free Software Foundation, Inc.
4 Contributed by Cygnus Support, using pieces from other GDB modules.
5
6 This file is part of GDB.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
22
23 #include "defs.h"
24 #include "gdb_string.h"
25 #include "bfd.h"
26 #include "symtab.h"
27 #include "symfile.h"
28 #include "objfiles.h"
29 #include "gdbtypes.h"
30 #include "expression.h"
31 #include "language.h"
32 #include "target.h"
33 #include "value.h"
34 #include "demangle.h"
35 #include "complaints.h"
36 #include "gdbcmd.h"
37 #include "wrapper.h"
38 #include "cp-abi.h"
39 #include "gdb_assert.h"
40
41 /* These variables point to the objects
42 representing the predefined C data types. */
43
44 struct type *builtin_type_void;
45 struct type *builtin_type_char;
46 struct type *builtin_type_true_char;
47 struct type *builtin_type_short;
48 struct type *builtin_type_int;
49 struct type *builtin_type_long;
50 struct type *builtin_type_long_long;
51 struct type *builtin_type_signed_char;
52 struct type *builtin_type_unsigned_char;
53 struct type *builtin_type_unsigned_short;
54 struct type *builtin_type_unsigned_int;
55 struct type *builtin_type_unsigned_long;
56 struct type *builtin_type_unsigned_long_long;
57 struct type *builtin_type_float;
58 struct type *builtin_type_double;
59 struct type *builtin_type_long_double;
60 struct type *builtin_type_complex;
61 struct type *builtin_type_double_complex;
62 struct type *builtin_type_string;
63 struct type *builtin_type_int8;
64 struct type *builtin_type_uint8;
65 struct type *builtin_type_int16;
66 struct type *builtin_type_uint16;
67 struct type *builtin_type_int32;
68 struct type *builtin_type_uint32;
69 struct type *builtin_type_int64;
70 struct type *builtin_type_uint64;
71 struct type *builtin_type_int128;
72 struct type *builtin_type_uint128;
73 struct type *builtin_type_bool;
74 struct type *builtin_type_v4sf;
75 struct type *builtin_type_v4si;
76 struct type *builtin_type_v8qi;
77 struct type *builtin_type_v4hi;
78 struct type *builtin_type_v2si;
79 struct type *builtin_type_ieee_single_big;
80 struct type *builtin_type_ieee_single_little;
81 struct type *builtin_type_ieee_double_big;
82 struct type *builtin_type_ieee_double_little;
83 struct type *builtin_type_ieee_double_littlebyte_bigword;
84 struct type *builtin_type_i387_ext;
85 struct type *builtin_type_m68881_ext;
86 struct type *builtin_type_i960_ext;
87 struct type *builtin_type_m88110_ext;
88 struct type *builtin_type_m88110_harris_ext;
89 struct type *builtin_type_arm_ext_big;
90 struct type *builtin_type_arm_ext_littlebyte_bigword;
91 struct type *builtin_type_ia64_spill_big;
92 struct type *builtin_type_ia64_spill_little;
93 struct type *builtin_type_ia64_quad_big;
94 struct type *builtin_type_ia64_quad_little;
95 struct type *builtin_type_void_data_ptr;
96 struct type *builtin_type_void_func_ptr;
97 struct type *builtin_type_CORE_ADDR;
98 struct type *builtin_type_bfd_vma;
99
100 int opaque_type_resolution = 1;
101 int overload_debug = 0;
102
103 struct extra
104 {
105 char str[128];
106 int len;
107 }; /* maximum extension is 128! FIXME */
108
109 static void add_name (struct extra *, char *);
110 static void add_mangled_type (struct extra *, struct type *);
111 #if 0
112 static void cfront_mangle_name (struct type *, int, int);
113 #endif
114 static void print_bit_vector (B_TYPE *, int);
115 static void print_arg_types (struct type **, int);
116 static void dump_fn_fieldlists (struct type *, int);
117 static void print_cplus_stuff (struct type *, int);
118 static void virtual_base_list_aux (struct type *dclass);
119
120
121 /* Alloc a new type structure and fill it with some defaults. If
122 OBJFILE is non-NULL, then allocate the space for the type structure
123 in that objfile's type_obstack. */
124
125 struct type *
126 alloc_type (struct objfile *objfile)
127 {
128 register struct type *type;
129
130 /* Alloc the structure and start off with all fields zeroed. */
131
132 if (objfile == NULL)
133 {
134 type = (struct type *) xmalloc (sizeof (struct type));
135 }
136 else
137 {
138 type = (struct type *) obstack_alloc (&objfile->type_obstack,
139 sizeof (struct type));
140 OBJSTAT (objfile, n_types++);
141 }
142 memset ((char *) type, 0, sizeof (struct type));
143
144 /* Initialize the fields that might not be zero. */
145
146 TYPE_CODE (type) = TYPE_CODE_UNDEF;
147 TYPE_OBJFILE (type) = objfile;
148 TYPE_VPTR_FIELDNO (type) = -1;
149 TYPE_CV_TYPE (type) = type; /* chain back to itself */
150 TYPE_AS_TYPE (type) = type; /* ditto */
151
152 return (type);
153 }
154
155 /* Lookup a pointer to a type TYPE. TYPEPTR, if nonzero, points
156 to a pointer to memory where the pointer type should be stored.
157 If *TYPEPTR is zero, update it to point to the pointer type we return.
158 We allocate new memory if needed. */
159
160 struct type *
161 make_pointer_type (struct type *type, struct type **typeptr)
162 {
163 register struct type *ntype; /* New type */
164 struct objfile *objfile;
165
166 ntype = TYPE_POINTER_TYPE (type);
167
168 if (ntype)
169 {
170 if (typeptr == 0)
171 return ntype; /* Don't care about alloc, and have new type. */
172 else if (*typeptr == 0)
173 {
174 *typeptr = ntype; /* Tracking alloc, and we have new type. */
175 return ntype;
176 }
177 }
178
179 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
180 {
181 ntype = alloc_type (TYPE_OBJFILE (type));
182 if (typeptr)
183 *typeptr = ntype;
184 }
185 else
186 /* We have storage, but need to reset it. */
187 {
188 ntype = *typeptr;
189 objfile = TYPE_OBJFILE (ntype);
190 memset ((char *) ntype, 0, sizeof (struct type));
191 TYPE_OBJFILE (ntype) = objfile;
192 }
193
194 TYPE_TARGET_TYPE (ntype) = type;
195 TYPE_POINTER_TYPE (type) = ntype;
196
197 /* FIXME! Assume the machine has only one representation for pointers! */
198
199 TYPE_LENGTH (ntype) = TARGET_PTR_BIT / TARGET_CHAR_BIT;
200 TYPE_CODE (ntype) = TYPE_CODE_PTR;
201
202 /* Mark pointers as unsigned. The target converts between pointers
203 and addresses (CORE_ADDRs) using POINTER_TO_ADDRESS() and
204 ADDRESS_TO_POINTER(). */
205 TYPE_FLAGS (ntype) |= TYPE_FLAG_UNSIGNED;
206
207 if (!TYPE_POINTER_TYPE (type)) /* Remember it, if don't have one. */
208 TYPE_POINTER_TYPE (type) = ntype;
209
210 return ntype;
211 }
212
213 /* Given a type TYPE, return a type of pointers to that type.
214 May need to construct such a type if this is the first use. */
215
216 struct type *
217 lookup_pointer_type (struct type *type)
218 {
219 return make_pointer_type (type, (struct type **) 0);
220 }
221
222 /* Lookup a C++ `reference' to a type TYPE. TYPEPTR, if nonzero, points
223 to a pointer to memory where the reference type should be stored.
224 If *TYPEPTR is zero, update it to point to the reference type we return.
225 We allocate new memory if needed. */
226
227 struct type *
228 make_reference_type (struct type *type, struct type **typeptr)
229 {
230 register struct type *ntype; /* New type */
231 struct objfile *objfile;
232
233 ntype = TYPE_REFERENCE_TYPE (type);
234
235 if (ntype)
236 {
237 if (typeptr == 0)
238 return ntype; /* Don't care about alloc, and have new type. */
239 else if (*typeptr == 0)
240 {
241 *typeptr = ntype; /* Tracking alloc, and we have new type. */
242 return ntype;
243 }
244 }
245
246 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
247 {
248 ntype = alloc_type (TYPE_OBJFILE (type));
249 if (typeptr)
250 *typeptr = ntype;
251 }
252 else
253 /* We have storage, but need to reset it. */
254 {
255 ntype = *typeptr;
256 objfile = TYPE_OBJFILE (ntype);
257 memset ((char *) ntype, 0, sizeof (struct type));
258 TYPE_OBJFILE (ntype) = objfile;
259 }
260
261 TYPE_TARGET_TYPE (ntype) = type;
262 TYPE_REFERENCE_TYPE (type) = ntype;
263
264 /* FIXME! Assume the machine has only one representation for references,
265 and that it matches the (only) representation for pointers! */
266
267 TYPE_LENGTH (ntype) = TARGET_PTR_BIT / TARGET_CHAR_BIT;
268 TYPE_CODE (ntype) = TYPE_CODE_REF;
269
270 if (!TYPE_REFERENCE_TYPE (type)) /* Remember it, if don't have one. */
271 TYPE_REFERENCE_TYPE (type) = ntype;
272
273 return ntype;
274 }
275
276 /* Same as above, but caller doesn't care about memory allocation details. */
277
278 struct type *
279 lookup_reference_type (struct type *type)
280 {
281 return make_reference_type (type, (struct type **) 0);
282 }
283
284 /* Lookup a function type that returns type TYPE. TYPEPTR, if nonzero, points
285 to a pointer to memory where the function type should be stored.
286 If *TYPEPTR is zero, update it to point to the function type we return.
287 We allocate new memory if needed. */
288
289 struct type *
290 make_function_type (struct type *type, struct type **typeptr)
291 {
292 register struct type *ntype; /* New type */
293 struct objfile *objfile;
294
295 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
296 {
297 ntype = alloc_type (TYPE_OBJFILE (type));
298 if (typeptr)
299 *typeptr = ntype;
300 }
301 else
302 /* We have storage, but need to reset it. */
303 {
304 ntype = *typeptr;
305 objfile = TYPE_OBJFILE (ntype);
306 memset ((char *) ntype, 0, sizeof (struct type));
307 TYPE_OBJFILE (ntype) = objfile;
308 }
309
310 TYPE_TARGET_TYPE (ntype) = type;
311
312 TYPE_LENGTH (ntype) = 1;
313 TYPE_CODE (ntype) = TYPE_CODE_FUNC;
314
315 return ntype;
316 }
317
318
319 /* Given a type TYPE, return a type of functions that return that type.
320 May need to construct such a type if this is the first use. */
321
322 struct type *
323 lookup_function_type (struct type *type)
324 {
325 return make_function_type (type, (struct type **) 0);
326 }
327
328 /* Identify address space identifier by name --
329 return the integer flag defined in gdbtypes.h. */
330 extern int
331 address_space_name_to_int (char *space_identifier)
332 {
333 /* Check for known address space delimiters. */
334 if (!strcmp (space_identifier, "code"))
335 return TYPE_FLAG_CODE_SPACE;
336 else if (!strcmp (space_identifier, "data"))
337 return TYPE_FLAG_DATA_SPACE;
338 else
339 error ("Unknown address space specifier: \"%s\"", space_identifier);
340 }
341
342 /* Identify address space identifier by integer flag as defined in
343 gdbtypes.h -- return the string version of the adress space name. */
344
345 extern char *
346 address_space_int_to_name (int space_flag)
347 {
348 if (space_flag & TYPE_FLAG_CODE_SPACE)
349 return "code";
350 else if (space_flag & TYPE_FLAG_DATA_SPACE)
351 return "data";
352 else
353 return NULL;
354 }
355
356 /* Make an address-space-delimited variant of a type -- a type that
357 is identical to the one supplied except that it has an address
358 space attribute attached to it (such as "code" or "data").
359
360 This is for Harvard architectures. */
361
362 struct type *
363 make_type_with_address_space (struct type *type, int space_flag)
364 {
365 struct type *ntype;
366
367 ntype = type;
368 do {
369 if ((ntype->flags & space_flag) != 0)
370 return ntype;
371 ntype = TYPE_AS_TYPE (ntype);
372 } while (ntype != type);
373
374 /* Create a new, duplicate type. */
375 ntype = alloc_type (TYPE_OBJFILE (type));
376 /* Copy original type. */
377 memcpy ((char *) ntype, (char *) type, sizeof (struct type));
378
379 /* Pointers or references to the original type are not relevant to
380 the new type; but if the original type is a pointer, the new type
381 points to the same thing (so TYPE_TARGET_TYPE remains unchanged). */
382 TYPE_POINTER_TYPE (ntype) = (struct type *) 0;
383 TYPE_REFERENCE_TYPE (ntype) = (struct type *) 0;
384 TYPE_CV_TYPE (ntype) = ntype;
385
386 /* Chain the new address-space-specific type to the old type. */
387 ntype->as_type = type->as_type;
388 type->as_type = ntype;
389
390 /* Now set the address-space flag, and return the new type. */
391 ntype->flags |= space_flag;
392 return ntype;
393 }
394
395
396 /* Make a "c-v" variant of a type -- a type that is identical to the
397 one supplied except that it may have const or volatile attributes
398 CNST is a flag for setting the const attribute
399 VOLTL is a flag for setting the volatile attribute
400 TYPE is the base type whose variant we are creating.
401 TYPEPTR, if nonzero, points
402 to a pointer to memory where the reference type should be stored.
403 If *TYPEPTR is zero, update it to point to the reference type we return.
404 We allocate new memory if needed. */
405
406 struct type *
407 make_cv_type (int cnst, int voltl, struct type *type, struct type **typeptr)
408 {
409 register struct type *ntype; /* New type */
410 register struct type *tmp_type = type; /* tmp type */
411 struct objfile *objfile;
412
413 ntype = TYPE_CV_TYPE (type);
414
415 while (ntype != type)
416 {
417 if ((TYPE_CONST (ntype) == cnst) &&
418 (TYPE_VOLATILE (ntype) == voltl))
419 {
420 if (typeptr == 0)
421 return ntype;
422 else if (*typeptr == 0)
423 {
424 *typeptr = ntype; /* Tracking alloc, and we have new type. */
425 return ntype;
426 }
427 }
428 tmp_type = ntype;
429 ntype = TYPE_CV_TYPE (ntype);
430 }
431
432 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
433 {
434 ntype = alloc_type (TYPE_OBJFILE (type));
435 if (typeptr)
436 *typeptr = ntype;
437 }
438 else
439 /* We have storage, but need to reset it. */
440 {
441 ntype = *typeptr;
442 objfile = TYPE_OBJFILE (ntype);
443 /* memset ((char *) ntype, 0, sizeof (struct type)); */
444 TYPE_OBJFILE (ntype) = objfile;
445 }
446
447 /* Copy original type */
448 memcpy ((char *) ntype, (char *) type, sizeof (struct type));
449 /* But zero out fields that shouldn't be copied */
450 TYPE_POINTER_TYPE (ntype) = (struct type *) 0; /* Need new pointer kind */
451 TYPE_REFERENCE_TYPE (ntype) = (struct type *) 0; /* Need new referene kind */
452 TYPE_AS_TYPE (ntype) = ntype; /* Need new address-space kind. */
453 /* Note: TYPE_TARGET_TYPE can be left as is */
454
455 /* Set flags appropriately */
456 if (cnst)
457 TYPE_FLAGS (ntype) |= TYPE_FLAG_CONST;
458 else
459 TYPE_FLAGS (ntype) &= ~TYPE_FLAG_CONST;
460
461 if (voltl)
462 TYPE_FLAGS (ntype) |= TYPE_FLAG_VOLATILE;
463 else
464 TYPE_FLAGS (ntype) &= ~TYPE_FLAG_VOLATILE;
465
466 /* Fix the chain of cv variants */
467 TYPE_CV_TYPE (ntype) = type;
468 TYPE_CV_TYPE (tmp_type) = ntype;
469
470 return ntype;
471 }
472
473 /* When reading in a class type, we may have created references to
474 cv-qualified versions of the type (in method arguments, for
475 instance). Update everything on the cv ring from the primary
476 type TYPE.
477
478 The only reason we do not need to do the same thing for address
479 spaces is that type readers do not create address space qualified
480 types. */
481 void
482 finish_cv_type (struct type *type)
483 {
484 struct type *ntype, *cv_type, *ptr_type, *ref_type;
485 int cv_flags;
486
487 gdb_assert (!TYPE_CONST (type) && !TYPE_VOLATILE (type));
488
489 ntype = type;
490 while ((ntype = TYPE_CV_TYPE (ntype)) != type)
491 {
492 /* Save cv_flags. */
493 cv_flags = TYPE_FLAGS (ntype) & (TYPE_FLAG_VOLATILE | TYPE_FLAG_CONST);
494
495 /* If any reference or pointer types were created, save them too. */
496 ptr_type = TYPE_POINTER_TYPE (ntype);
497 ref_type = TYPE_REFERENCE_TYPE (ntype);
498
499 /* Don't disturb the CV chain. */
500 cv_type = TYPE_CV_TYPE (ntype);
501
502 /* Verify that we haven't added any address-space qualified types,
503 for the future. */
504 gdb_assert (ntype == TYPE_AS_TYPE (ntype));
505
506 /* Copy original type */
507 memcpy ((char *) ntype, (char *) type, sizeof (struct type));
508
509 /* Restore everything. */
510 TYPE_POINTER_TYPE (ntype) = ptr_type;
511 TYPE_REFERENCE_TYPE (ntype) = ref_type;
512 TYPE_CV_TYPE (ntype) = cv_type;
513 TYPE_FLAGS (ntype) = TYPE_FLAGS (ntype) | cv_flags;
514
515 TYPE_AS_TYPE (ntype) = ntype;
516 }
517 }
518
519 /* Implement direct support for MEMBER_TYPE in GNU C++.
520 May need to construct such a type if this is the first use.
521 The TYPE is the type of the member. The DOMAIN is the type
522 of the aggregate that the member belongs to. */
523
524 struct type *
525 lookup_member_type (struct type *type, struct type *domain)
526 {
527 register struct type *mtype;
528
529 mtype = alloc_type (TYPE_OBJFILE (type));
530 smash_to_member_type (mtype, domain, type);
531 return (mtype);
532 }
533
534 /* Allocate a stub method whose return type is TYPE.
535 This apparently happens for speed of symbol reading, since parsing
536 out the arguments to the method is cpu-intensive, the way we are doing
537 it. So, we will fill in arguments later.
538 This always returns a fresh type. */
539
540 struct type *
541 allocate_stub_method (struct type *type)
542 {
543 struct type *mtype;
544
545 mtype = init_type (TYPE_CODE_METHOD, 1, TYPE_FLAG_STUB, NULL,
546 TYPE_OBJFILE (type));
547 TYPE_TARGET_TYPE (mtype) = type;
548 /* _DOMAIN_TYPE (mtype) = unknown yet */
549 /* _ARG_TYPES (mtype) = unknown yet */
550 return (mtype);
551 }
552
553 /* Create a range type using either a blank type supplied in RESULT_TYPE,
554 or creating a new type, inheriting the objfile from INDEX_TYPE.
555
556 Indices will be of type INDEX_TYPE, and will range from LOW_BOUND to
557 HIGH_BOUND, inclusive.
558
559 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
560 sure it is TYPE_CODE_UNDEF before we bash it into a range type? */
561
562 struct type *
563 create_range_type (struct type *result_type, struct type *index_type,
564 int low_bound, int high_bound)
565 {
566 if (result_type == NULL)
567 {
568 result_type = alloc_type (TYPE_OBJFILE (index_type));
569 }
570 TYPE_CODE (result_type) = TYPE_CODE_RANGE;
571 TYPE_TARGET_TYPE (result_type) = index_type;
572 if (TYPE_STUB (index_type))
573 TYPE_FLAGS (result_type) |= TYPE_FLAG_TARGET_STUB;
574 else
575 TYPE_LENGTH (result_type) = TYPE_LENGTH (check_typedef (index_type));
576 TYPE_NFIELDS (result_type) = 2;
577 TYPE_FIELDS (result_type) = (struct field *)
578 TYPE_ALLOC (result_type, 2 * sizeof (struct field));
579 memset (TYPE_FIELDS (result_type), 0, 2 * sizeof (struct field));
580 TYPE_FIELD_BITPOS (result_type, 0) = low_bound;
581 TYPE_FIELD_BITPOS (result_type, 1) = high_bound;
582 TYPE_FIELD_TYPE (result_type, 0) = builtin_type_int; /* FIXME */
583 TYPE_FIELD_TYPE (result_type, 1) = builtin_type_int; /* FIXME */
584
585 if (low_bound >= 0)
586 TYPE_FLAGS (result_type) |= TYPE_FLAG_UNSIGNED;
587
588 return (result_type);
589 }
590
591 /* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type TYPE.
592 Return 1 of type is a range type, 0 if it is discrete (and bounds
593 will fit in LONGEST), or -1 otherwise. */
594
595 int
596 get_discrete_bounds (struct type *type, LONGEST *lowp, LONGEST *highp)
597 {
598 CHECK_TYPEDEF (type);
599 switch (TYPE_CODE (type))
600 {
601 case TYPE_CODE_RANGE:
602 *lowp = TYPE_LOW_BOUND (type);
603 *highp = TYPE_HIGH_BOUND (type);
604 return 1;
605 case TYPE_CODE_ENUM:
606 if (TYPE_NFIELDS (type) > 0)
607 {
608 /* The enums may not be sorted by value, so search all
609 entries */
610 int i;
611
612 *lowp = *highp = TYPE_FIELD_BITPOS (type, 0);
613 for (i = 0; i < TYPE_NFIELDS (type); i++)
614 {
615 if (TYPE_FIELD_BITPOS (type, i) < *lowp)
616 *lowp = TYPE_FIELD_BITPOS (type, i);
617 if (TYPE_FIELD_BITPOS (type, i) > *highp)
618 *highp = TYPE_FIELD_BITPOS (type, i);
619 }
620
621 /* Set unsigned indicator if warranted. */
622 if (*lowp >= 0)
623 {
624 TYPE_FLAGS (type) |= TYPE_FLAG_UNSIGNED;
625 }
626 }
627 else
628 {
629 *lowp = 0;
630 *highp = -1;
631 }
632 return 0;
633 case TYPE_CODE_BOOL:
634 *lowp = 0;
635 *highp = 1;
636 return 0;
637 case TYPE_CODE_INT:
638 if (TYPE_LENGTH (type) > sizeof (LONGEST)) /* Too big */
639 return -1;
640 if (!TYPE_UNSIGNED (type))
641 {
642 *lowp = -(1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1));
643 *highp = -*lowp - 1;
644 return 0;
645 }
646 /* ... fall through for unsigned ints ... */
647 case TYPE_CODE_CHAR:
648 *lowp = 0;
649 /* This round-about calculation is to avoid shifting by
650 TYPE_LENGTH (type) * TARGET_CHAR_BIT, which will not work
651 if TYPE_LENGTH (type) == sizeof (LONGEST). */
652 *highp = 1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1);
653 *highp = (*highp - 1) | *highp;
654 return 0;
655 default:
656 return -1;
657 }
658 }
659
660 /* Create an array type using either a blank type supplied in RESULT_TYPE,
661 or creating a new type, inheriting the objfile from RANGE_TYPE.
662
663 Elements will be of type ELEMENT_TYPE, the indices will be of type
664 RANGE_TYPE.
665
666 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
667 sure it is TYPE_CODE_UNDEF before we bash it into an array type? */
668
669 struct type *
670 create_array_type (struct type *result_type, struct type *element_type,
671 struct type *range_type)
672 {
673 LONGEST low_bound, high_bound;
674
675 if (result_type == NULL)
676 {
677 result_type = alloc_type (TYPE_OBJFILE (range_type));
678 }
679 TYPE_CODE (result_type) = TYPE_CODE_ARRAY;
680 TYPE_TARGET_TYPE (result_type) = element_type;
681 if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
682 low_bound = high_bound = 0;
683 CHECK_TYPEDEF (element_type);
684 TYPE_LENGTH (result_type) =
685 TYPE_LENGTH (element_type) * (high_bound - low_bound + 1);
686 TYPE_NFIELDS (result_type) = 1;
687 TYPE_FIELDS (result_type) =
688 (struct field *) TYPE_ALLOC (result_type, sizeof (struct field));
689 memset (TYPE_FIELDS (result_type), 0, sizeof (struct field));
690 TYPE_FIELD_TYPE (result_type, 0) = range_type;
691 TYPE_VPTR_FIELDNO (result_type) = -1;
692
693 /* TYPE_FLAG_TARGET_STUB will take care of zero length arrays */
694 if (TYPE_LENGTH (result_type) == 0)
695 TYPE_FLAGS (result_type) |= TYPE_FLAG_TARGET_STUB;
696
697 return (result_type);
698 }
699
700 /* Create a string type using either a blank type supplied in RESULT_TYPE,
701 or creating a new type. String types are similar enough to array of
702 char types that we can use create_array_type to build the basic type
703 and then bash it into a string type.
704
705 For fixed length strings, the range type contains 0 as the lower
706 bound and the length of the string minus one as the upper bound.
707
708 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
709 sure it is TYPE_CODE_UNDEF before we bash it into a string type? */
710
711 struct type *
712 create_string_type (struct type *result_type, struct type *range_type)
713 {
714 result_type = create_array_type (result_type,
715 *current_language->string_char_type,
716 range_type);
717 TYPE_CODE (result_type) = TYPE_CODE_STRING;
718 return (result_type);
719 }
720
721 struct type *
722 create_set_type (struct type *result_type, struct type *domain_type)
723 {
724 LONGEST low_bound, high_bound, bit_length;
725 if (result_type == NULL)
726 {
727 result_type = alloc_type (TYPE_OBJFILE (domain_type));
728 }
729 TYPE_CODE (result_type) = TYPE_CODE_SET;
730 TYPE_NFIELDS (result_type) = 1;
731 TYPE_FIELDS (result_type) = (struct field *)
732 TYPE_ALLOC (result_type, 1 * sizeof (struct field));
733 memset (TYPE_FIELDS (result_type), 0, sizeof (struct field));
734
735 if (!TYPE_STUB (domain_type))
736 {
737 if (get_discrete_bounds (domain_type, &low_bound, &high_bound) < 0)
738 low_bound = high_bound = 0;
739 bit_length = high_bound - low_bound + 1;
740 TYPE_LENGTH (result_type)
741 = (bit_length + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT;
742 }
743 TYPE_FIELD_TYPE (result_type, 0) = domain_type;
744
745 if (low_bound >= 0)
746 TYPE_FLAGS (result_type) |= TYPE_FLAG_UNSIGNED;
747
748 return (result_type);
749 }
750
751
752 /* Construct and return a type of the form:
753 struct NAME { ELT_TYPE ELT_NAME[N]; }
754 We use these types for SIMD registers. For example, the type of
755 the SSE registers on the late x86-family processors is:
756 struct __builtin_v4sf { float f[4]; }
757 built by the function call:
758 init_simd_type ("__builtin_v4sf", builtin_type_float, "f", 4)
759 The type returned is a permanent type, allocated using malloc; it
760 doesn't live in any objfile's obstack. */
761 static struct type *
762 init_simd_type (char *name,
763 struct type *elt_type,
764 char *elt_name,
765 int n)
766 {
767 struct type *t;
768 struct field *f;
769
770 /* Build the field structure. */
771 f = xmalloc (sizeof (*f));
772 memset (f, 0, sizeof (*f));
773 f->loc.bitpos = 0;
774 f->type = create_array_type (0, elt_type,
775 create_range_type (0, builtin_type_int,
776 0, n-1));
777 f->name = elt_name;
778
779 /* Build a struct type with that field. */
780 t = init_type (TYPE_CODE_STRUCT, n * TYPE_LENGTH (elt_type), 0, 0, 0);
781 t->nfields = 1;
782 t->fields = f;
783 t->tag_name = name;
784
785 return t;
786 }
787
788
789 /* Smash TYPE to be a type of members of DOMAIN with type TO_TYPE.
790 A MEMBER is a wierd thing -- it amounts to a typed offset into
791 a struct, e.g. "an int at offset 8". A MEMBER TYPE doesn't
792 include the offset (that's the value of the MEMBER itself), but does
793 include the structure type into which it points (for some reason).
794
795 When "smashing" the type, we preserve the objfile that the
796 old type pointed to, since we aren't changing where the type is actually
797 allocated. */
798
799 void
800 smash_to_member_type (struct type *type, struct type *domain,
801 struct type *to_type)
802 {
803 struct objfile *objfile;
804
805 objfile = TYPE_OBJFILE (type);
806
807 memset ((char *) type, 0, sizeof (struct type));
808 TYPE_OBJFILE (type) = objfile;
809 TYPE_TARGET_TYPE (type) = to_type;
810 TYPE_DOMAIN_TYPE (type) = domain;
811 TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */
812 TYPE_CODE (type) = TYPE_CODE_MEMBER;
813 }
814
815 /* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE.
816 METHOD just means `function that gets an extra "this" argument'.
817
818 When "smashing" the type, we preserve the objfile that the
819 old type pointed to, since we aren't changing where the type is actually
820 allocated. */
821
822 void
823 smash_to_method_type (struct type *type, struct type *domain,
824 struct type *to_type, struct type **args)
825 {
826 struct objfile *objfile;
827
828 objfile = TYPE_OBJFILE (type);
829
830 memset ((char *) type, 0, sizeof (struct type));
831 TYPE_OBJFILE (type) = objfile;
832 TYPE_TARGET_TYPE (type) = to_type;
833 TYPE_DOMAIN_TYPE (type) = domain;
834 TYPE_ARG_TYPES (type) = args;
835 TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */
836 TYPE_CODE (type) = TYPE_CODE_METHOD;
837 }
838
839 /* Return a typename for a struct/union/enum type without "struct ",
840 "union ", or "enum ". If the type has a NULL name, return NULL. */
841
842 char *
843 type_name_no_tag (register const struct type *type)
844 {
845 if (TYPE_TAG_NAME (type) != NULL)
846 return TYPE_TAG_NAME (type);
847
848 /* Is there code which expects this to return the name if there is no
849 tag name? My guess is that this is mainly used for C++ in cases where
850 the two will always be the same. */
851 return TYPE_NAME (type);
852 }
853
854 /* Lookup a primitive type named NAME.
855 Return zero if NAME is not a primitive type. */
856
857 struct type *
858 lookup_primitive_typename (char *name)
859 {
860 struct type **const *p;
861
862 for (p = current_language->la_builtin_type_vector; *p != NULL; p++)
863 {
864 if (STREQ ((**p)->name, name))
865 {
866 return (**p);
867 }
868 }
869 return (NULL);
870 }
871
872 /* Lookup a typedef or primitive type named NAME,
873 visible in lexical block BLOCK.
874 If NOERR is nonzero, return zero if NAME is not suitably defined. */
875
876 struct type *
877 lookup_typename (char *name, struct block *block, int noerr)
878 {
879 register struct symbol *sym;
880 register struct type *tmp;
881
882 sym = lookup_symbol (name, block, VAR_NAMESPACE, 0, (struct symtab **) NULL);
883 if (sym == NULL || SYMBOL_CLASS (sym) != LOC_TYPEDEF)
884 {
885 tmp = lookup_primitive_typename (name);
886 if (tmp)
887 {
888 return (tmp);
889 }
890 else if (!tmp && noerr)
891 {
892 return (NULL);
893 }
894 else
895 {
896 error ("No type named %s.", name);
897 }
898 }
899 return (SYMBOL_TYPE (sym));
900 }
901
902 struct type *
903 lookup_unsigned_typename (char *name)
904 {
905 char *uns = alloca (strlen (name) + 10);
906
907 strcpy (uns, "unsigned ");
908 strcpy (uns + 9, name);
909 return (lookup_typename (uns, (struct block *) NULL, 0));
910 }
911
912 struct type *
913 lookup_signed_typename (char *name)
914 {
915 struct type *t;
916 char *uns = alloca (strlen (name) + 8);
917
918 strcpy (uns, "signed ");
919 strcpy (uns + 7, name);
920 t = lookup_typename (uns, (struct block *) NULL, 1);
921 /* If we don't find "signed FOO" just try again with plain "FOO". */
922 if (t != NULL)
923 return t;
924 return lookup_typename (name, (struct block *) NULL, 0);
925 }
926
927 /* Lookup a structure type named "struct NAME",
928 visible in lexical block BLOCK. */
929
930 struct type *
931 lookup_struct (char *name, struct block *block)
932 {
933 register struct symbol *sym;
934
935 sym = lookup_symbol (name, block, STRUCT_NAMESPACE, 0,
936 (struct symtab **) NULL);
937
938 if (sym == NULL)
939 {
940 error ("No struct type named %s.", name);
941 }
942 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
943 {
944 error ("This context has class, union or enum %s, not a struct.", name);
945 }
946 return (SYMBOL_TYPE (sym));
947 }
948
949 /* Lookup a union type named "union NAME",
950 visible in lexical block BLOCK. */
951
952 struct type *
953 lookup_union (char *name, struct block *block)
954 {
955 register struct symbol *sym;
956 struct type *t;
957
958 sym = lookup_symbol (name, block, STRUCT_NAMESPACE, 0,
959 (struct symtab **) NULL);
960
961 if (sym == NULL)
962 error ("No union type named %s.", name);
963
964 t = SYMBOL_TYPE (sym);
965
966 if (TYPE_CODE (t) == TYPE_CODE_UNION)
967 return (t);
968
969 /* C++ unions may come out with TYPE_CODE_CLASS, but we look at
970 * a further "declared_type" field to discover it is really a union.
971 */
972 if (HAVE_CPLUS_STRUCT (t))
973 if (TYPE_DECLARED_TYPE (t) == DECLARED_TYPE_UNION)
974 return (t);
975
976 /* If we get here, it's not a union */
977 error ("This context has class, struct or enum %s, not a union.", name);
978 }
979
980
981 /* Lookup an enum type named "enum NAME",
982 visible in lexical block BLOCK. */
983
984 struct type *
985 lookup_enum (char *name, struct block *block)
986 {
987 register struct symbol *sym;
988
989 sym = lookup_symbol (name, block, STRUCT_NAMESPACE, 0,
990 (struct symtab **) NULL);
991 if (sym == NULL)
992 {
993 error ("No enum type named %s.", name);
994 }
995 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_ENUM)
996 {
997 error ("This context has class, struct or union %s, not an enum.", name);
998 }
999 return (SYMBOL_TYPE (sym));
1000 }
1001
1002 /* Lookup a template type named "template NAME<TYPE>",
1003 visible in lexical block BLOCK. */
1004
1005 struct type *
1006 lookup_template_type (char *name, struct type *type, struct block *block)
1007 {
1008 struct symbol *sym;
1009 char *nam = (char *) alloca (strlen (name) + strlen (type->name) + 4);
1010 strcpy (nam, name);
1011 strcat (nam, "<");
1012 strcat (nam, type->name);
1013 strcat (nam, " >"); /* FIXME, extra space still introduced in gcc? */
1014
1015 sym = lookup_symbol (nam, block, VAR_NAMESPACE, 0, (struct symtab **) NULL);
1016
1017 if (sym == NULL)
1018 {
1019 error ("No template type named %s.", name);
1020 }
1021 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
1022 {
1023 error ("This context has class, union or enum %s, not a struct.", name);
1024 }
1025 return (SYMBOL_TYPE (sym));
1026 }
1027
1028 /* Given a type TYPE, lookup the type of the component of type named NAME.
1029
1030 TYPE can be either a struct or union, or a pointer or reference to a struct or
1031 union. If it is a pointer or reference, its target type is automatically used.
1032 Thus '.' and '->' are interchangable, as specified for the definitions of the
1033 expression element types STRUCTOP_STRUCT and STRUCTOP_PTR.
1034
1035 If NOERR is nonzero, return zero if NAME is not suitably defined.
1036 If NAME is the name of a baseclass type, return that type. */
1037
1038 struct type *
1039 lookup_struct_elt_type (struct type *type, char *name, int noerr)
1040 {
1041 int i;
1042
1043 for (;;)
1044 {
1045 CHECK_TYPEDEF (type);
1046 if (TYPE_CODE (type) != TYPE_CODE_PTR
1047 && TYPE_CODE (type) != TYPE_CODE_REF)
1048 break;
1049 type = TYPE_TARGET_TYPE (type);
1050 }
1051
1052 if (TYPE_CODE (type) != TYPE_CODE_STRUCT &&
1053 TYPE_CODE (type) != TYPE_CODE_UNION)
1054 {
1055 target_terminal_ours ();
1056 gdb_flush (gdb_stdout);
1057 fprintf_unfiltered (gdb_stderr, "Type ");
1058 type_print (type, "", gdb_stderr, -1);
1059 error (" is not a structure or union type.");
1060 }
1061
1062 #if 0
1063 /* FIXME: This change put in by Michael seems incorrect for the case where
1064 the structure tag name is the same as the member name. I.E. when doing
1065 "ptype bell->bar" for "struct foo { int bar; int foo; } bell;"
1066 Disabled by fnf. */
1067 {
1068 char *typename;
1069
1070 typename = type_name_no_tag (type);
1071 if (typename != NULL && STREQ (typename, name))
1072 return type;
1073 }
1074 #endif
1075
1076 for (i = TYPE_NFIELDS (type) - 1; i >= TYPE_N_BASECLASSES (type); i--)
1077 {
1078 char *t_field_name = TYPE_FIELD_NAME (type, i);
1079
1080 if (t_field_name && (strcmp_iw (t_field_name, name) == 0))
1081 {
1082 return TYPE_FIELD_TYPE (type, i);
1083 }
1084 }
1085
1086 /* OK, it's not in this class. Recursively check the baseclasses. */
1087 for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--)
1088 {
1089 struct type *t;
1090
1091 t = lookup_struct_elt_type (TYPE_BASECLASS (type, i), name, noerr);
1092 if (t != NULL)
1093 {
1094 return t;
1095 }
1096 }
1097
1098 if (noerr)
1099 {
1100 return NULL;
1101 }
1102
1103 target_terminal_ours ();
1104 gdb_flush (gdb_stdout);
1105 fprintf_unfiltered (gdb_stderr, "Type ");
1106 type_print (type, "", gdb_stderr, -1);
1107 fprintf_unfiltered (gdb_stderr, " has no component named ");
1108 fputs_filtered (name, gdb_stderr);
1109 error (".");
1110 return (struct type *) -1; /* For lint */
1111 }
1112
1113 /* If possible, make the vptr_fieldno and vptr_basetype fields of TYPE
1114 valid. Callers should be aware that in some cases (for example,
1115 the type or one of its baseclasses is a stub type and we are
1116 debugging a .o file), this function will not be able to find the virtual
1117 function table pointer, and vptr_fieldno will remain -1 and vptr_basetype
1118 will remain NULL. */
1119
1120 void
1121 fill_in_vptr_fieldno (struct type *type)
1122 {
1123 CHECK_TYPEDEF (type);
1124
1125 if (TYPE_VPTR_FIELDNO (type) < 0)
1126 {
1127 int i;
1128
1129 /* We must start at zero in case the first (and only) baseclass is
1130 virtual (and hence we cannot share the table pointer). */
1131 for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
1132 {
1133 fill_in_vptr_fieldno (TYPE_BASECLASS (type, i));
1134 if (TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type, i)) >= 0)
1135 {
1136 TYPE_VPTR_FIELDNO (type)
1137 = TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type, i));
1138 TYPE_VPTR_BASETYPE (type)
1139 = TYPE_VPTR_BASETYPE (TYPE_BASECLASS (type, i));
1140 break;
1141 }
1142 }
1143 }
1144 }
1145
1146 /* Find the method and field indices for the destructor in class type T.
1147 Return 1 if the destructor was found, otherwise, return 0. */
1148
1149 int
1150 get_destructor_fn_field (struct type *t, int *method_indexp, int *field_indexp)
1151 {
1152 int i;
1153
1154 for (i = 0; i < TYPE_NFN_FIELDS (t); i++)
1155 {
1156 int j;
1157 struct fn_field *f = TYPE_FN_FIELDLIST1 (t, i);
1158
1159 for (j = 0; j < TYPE_FN_FIELDLIST_LENGTH (t, i); j++)
1160 {
1161 if (is_destructor_name (TYPE_FN_FIELD_PHYSNAME (f, j)) != 0)
1162 {
1163 *method_indexp = i;
1164 *field_indexp = j;
1165 return 1;
1166 }
1167 }
1168 }
1169 return 0;
1170 }
1171
1172 /* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989.
1173
1174 If this is a stubbed struct (i.e. declared as struct foo *), see if
1175 we can find a full definition in some other file. If so, copy this
1176 definition, so we can use it in future. There used to be a comment (but
1177 not any code) that if we don't find a full definition, we'd set a flag
1178 so we don't spend time in the future checking the same type. That would
1179 be a mistake, though--we might load in more symbols which contain a
1180 full definition for the type.
1181
1182 This used to be coded as a macro, but I don't think it is called
1183 often enough to merit such treatment. */
1184
1185 struct complaint stub_noname_complaint =
1186 {"stub type has NULL name", 0, 0};
1187
1188 struct type *
1189 check_typedef (struct type *type)
1190 {
1191 struct type *orig_type = type;
1192 int is_const, is_volatile;
1193
1194 while (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
1195 {
1196 if (!TYPE_TARGET_TYPE (type))
1197 {
1198 char *name;
1199 struct symbol *sym;
1200
1201 /* It is dangerous to call lookup_symbol if we are currently
1202 reading a symtab. Infinite recursion is one danger. */
1203 if (currently_reading_symtab)
1204 return type;
1205
1206 name = type_name_no_tag (type);
1207 /* FIXME: shouldn't we separately check the TYPE_NAME and the
1208 TYPE_TAG_NAME, and look in STRUCT_NAMESPACE and/or VAR_NAMESPACE
1209 as appropriate? (this code was written before TYPE_NAME and
1210 TYPE_TAG_NAME were separate). */
1211 if (name == NULL)
1212 {
1213 complain (&stub_noname_complaint);
1214 return type;
1215 }
1216 sym = lookup_symbol (name, 0, STRUCT_NAMESPACE, 0,
1217 (struct symtab **) NULL);
1218 if (sym)
1219 TYPE_TARGET_TYPE (type) = SYMBOL_TYPE (sym);
1220 else
1221 TYPE_TARGET_TYPE (type) = alloc_type (NULL); /* TYPE_CODE_UNDEF */
1222 }
1223 type = TYPE_TARGET_TYPE (type);
1224 }
1225
1226 is_const = TYPE_CONST (type);
1227 is_volatile = TYPE_VOLATILE (type);
1228
1229 /* If this is a struct/class/union with no fields, then check whether a
1230 full definition exists somewhere else. This is for systems where a
1231 type definition with no fields is issued for such types, instead of
1232 identifying them as stub types in the first place */
1233
1234 if (TYPE_IS_OPAQUE (type) && opaque_type_resolution && !currently_reading_symtab)
1235 {
1236 char *name = type_name_no_tag (type);
1237 struct type *newtype;
1238 if (name == NULL)
1239 {
1240 complain (&stub_noname_complaint);
1241 return type;
1242 }
1243 newtype = lookup_transparent_type (name);
1244 if (newtype)
1245 make_cv_type (is_const, is_volatile, newtype, &type);
1246 }
1247 /* Otherwise, rely on the stub flag being set for opaque/stubbed types */
1248 else if (TYPE_STUB (type) && !currently_reading_symtab)
1249 {
1250 char *name = type_name_no_tag (type);
1251 /* FIXME: shouldn't we separately check the TYPE_NAME and the
1252 TYPE_TAG_NAME, and look in STRUCT_NAMESPACE and/or VAR_NAMESPACE
1253 as appropriate? (this code was written before TYPE_NAME and
1254 TYPE_TAG_NAME were separate). */
1255 struct symbol *sym;
1256 if (name == NULL)
1257 {
1258 complain (&stub_noname_complaint);
1259 return type;
1260 }
1261 sym = lookup_symbol (name, 0, STRUCT_NAMESPACE, 0, (struct symtab **) NULL);
1262 if (sym)
1263 make_cv_type (is_const, is_volatile, SYMBOL_TYPE (sym), &type);
1264 }
1265
1266 if (TYPE_TARGET_STUB (type))
1267 {
1268 struct type *range_type;
1269 struct type *target_type = check_typedef (TYPE_TARGET_TYPE (type));
1270
1271 if (TYPE_STUB (target_type) || TYPE_TARGET_STUB (target_type))
1272 {
1273 }
1274 else if (TYPE_CODE (type) == TYPE_CODE_ARRAY
1275 && TYPE_NFIELDS (type) == 1
1276 && (TYPE_CODE (range_type = TYPE_FIELD_TYPE (type, 0))
1277 == TYPE_CODE_RANGE))
1278 {
1279 /* Now recompute the length of the array type, based on its
1280 number of elements and the target type's length. */
1281 TYPE_LENGTH (type) =
1282 ((TYPE_FIELD_BITPOS (range_type, 1)
1283 - TYPE_FIELD_BITPOS (range_type, 0)
1284 + 1)
1285 * TYPE_LENGTH (target_type));
1286 TYPE_FLAGS (type) &= ~TYPE_FLAG_TARGET_STUB;
1287 }
1288 else if (TYPE_CODE (type) == TYPE_CODE_RANGE)
1289 {
1290 TYPE_LENGTH (type) = TYPE_LENGTH (target_type);
1291 TYPE_FLAGS (type) &= ~TYPE_FLAG_TARGET_STUB;
1292 }
1293 }
1294 /* Cache TYPE_LENGTH for future use. */
1295 TYPE_LENGTH (orig_type) = TYPE_LENGTH (type);
1296 return type;
1297 }
1298
1299 /* New code added to support parsing of Cfront stabs strings */
1300 #define INIT_EXTRA { pextras->len=0; pextras->str[0]='\0'; }
1301 #define ADD_EXTRA(c) { pextras->str[pextras->len++]=c; }
1302
1303 static void
1304 add_name (struct extra *pextras, char *n)
1305 {
1306 int nlen;
1307
1308 if ((nlen = (n ? strlen (n) : 0)) == 0)
1309 return;
1310 sprintf (pextras->str + pextras->len, "%d%s", nlen, n);
1311 pextras->len = strlen (pextras->str);
1312 }
1313
1314 static void
1315 add_mangled_type (struct extra *pextras, struct type *t)
1316 {
1317 enum type_code tcode;
1318 int tlen, tflags;
1319 char *tname;
1320
1321 tcode = TYPE_CODE (t);
1322 tlen = TYPE_LENGTH (t);
1323 tflags = TYPE_FLAGS (t);
1324 tname = TYPE_NAME (t);
1325 /* args of "..." seem to get mangled as "e" */
1326
1327 switch (tcode)
1328 {
1329 case TYPE_CODE_INT:
1330 if (tflags == 1)
1331 ADD_EXTRA ('U');
1332 switch (tlen)
1333 {
1334 case 1:
1335 ADD_EXTRA ('c');
1336 break;
1337 case 2:
1338 ADD_EXTRA ('s');
1339 break;
1340 case 4:
1341 {
1342 char *pname;
1343 if ((pname = strrchr (tname, 'l'), pname) && !strcmp (pname, "long"))
1344 {
1345 ADD_EXTRA ('l');
1346 }
1347 else
1348 {
1349 ADD_EXTRA ('i');
1350 }
1351 }
1352 break;
1353 default:
1354 {
1355
1356 static struct complaint msg =
1357 {"Bad int type code length x%x\n", 0, 0};
1358
1359 complain (&msg, tlen);
1360
1361 }
1362 }
1363 break;
1364 case TYPE_CODE_FLT:
1365 switch (tlen)
1366 {
1367 case 4:
1368 ADD_EXTRA ('f');
1369 break;
1370 case 8:
1371 ADD_EXTRA ('d');
1372 break;
1373 case 16:
1374 ADD_EXTRA ('r');
1375 break;
1376 default:
1377 {
1378 static struct complaint msg =
1379 {"Bad float type code length x%x\n", 0, 0};
1380 complain (&msg, tlen);
1381 }
1382 }
1383 break;
1384 case TYPE_CODE_REF:
1385 ADD_EXTRA ('R');
1386 /* followed by what it's a ref to */
1387 break;
1388 case TYPE_CODE_PTR:
1389 ADD_EXTRA ('P');
1390 /* followed by what it's a ptr to */
1391 break;
1392 case TYPE_CODE_TYPEDEF:
1393 {
1394 static struct complaint msg =
1395 {"Typedefs in overloaded functions not yet supported\n", 0, 0};
1396 complain (&msg);
1397 }
1398 /* followed by type bytes & name */
1399 break;
1400 case TYPE_CODE_FUNC:
1401 ADD_EXTRA ('F');
1402 /* followed by func's arg '_' & ret types */
1403 break;
1404 case TYPE_CODE_VOID:
1405 ADD_EXTRA ('v');
1406 break;
1407 case TYPE_CODE_METHOD:
1408 ADD_EXTRA ('M');
1409 /* followed by name of class and func's arg '_' & ret types */
1410 add_name (pextras, tname);
1411 ADD_EXTRA ('F'); /* then mangle function */
1412 break;
1413 case TYPE_CODE_STRUCT: /* C struct */
1414 case TYPE_CODE_UNION: /* C union */
1415 case TYPE_CODE_ENUM: /* Enumeration type */
1416 /* followed by name of type */
1417 add_name (pextras, tname);
1418 break;
1419
1420 /* errors possible types/not supported */
1421 case TYPE_CODE_CHAR:
1422 case TYPE_CODE_ARRAY: /* Array type */
1423 case TYPE_CODE_MEMBER: /* Member type */
1424 case TYPE_CODE_BOOL:
1425 case TYPE_CODE_COMPLEX: /* Complex float */
1426 case TYPE_CODE_UNDEF:
1427 case TYPE_CODE_SET: /* Pascal sets */
1428 case TYPE_CODE_RANGE:
1429 case TYPE_CODE_STRING:
1430 case TYPE_CODE_BITSTRING:
1431 case TYPE_CODE_ERROR:
1432 default:
1433 {
1434 static struct complaint msg =
1435 {"Unknown type code x%x\n", 0, 0};
1436 complain (&msg, tcode);
1437 }
1438 }
1439 if (t->target_type)
1440 add_mangled_type (pextras, t->target_type);
1441 }
1442
1443 #if 0
1444 void
1445 cfront_mangle_name (struct type *type, int i, int j)
1446 {
1447 struct fn_field *f;
1448 char *mangled_name = gdb_mangle_name (type, i, j);
1449
1450 f = TYPE_FN_FIELDLIST1 (type, i); /* moved from below */
1451
1452 /* kludge to support cfront methods - gdb expects to find "F" for
1453 ARM_mangled names, so when we mangle, we have to add it here */
1454 if (ARM_DEMANGLING)
1455 {
1456 int k;
1457 char *arm_mangled_name;
1458 struct fn_field *method = &f[j];
1459 char *field_name = TYPE_FN_FIELDLIST_NAME (type, i);
1460 char *physname = TYPE_FN_FIELD_PHYSNAME (f, j);
1461 char *newname = type_name_no_tag (type);
1462
1463 struct type *ftype = TYPE_FN_FIELD_TYPE (f, j);
1464 int nargs = TYPE_NFIELDS (ftype); /* number of args */
1465 struct extra extras, *pextras = &extras;
1466 INIT_EXTRA
1467
1468 if (TYPE_FN_FIELD_STATIC_P (f, j)) /* j for sublist within this list */
1469 ADD_EXTRA ('S')
1470 ADD_EXTRA ('F')
1471 /* add args here! */
1472 if (nargs <= 1) /* no args besides this */
1473 ADD_EXTRA ('v')
1474 else
1475 {
1476 for (k = 1; k < nargs; k++)
1477 {
1478 struct type *t;
1479 t = TYPE_FIELD_TYPE (ftype, k);
1480 add_mangled_type (pextras, t);
1481 }
1482 }
1483 ADD_EXTRA ('\0')
1484 printf ("add_mangled_type: %s\n", extras.str); /* FIXME */
1485 xasprintf (&arm_mangled_name, "%s%s", mangled_name, extras.str);
1486 xfree (mangled_name);
1487 mangled_name = arm_mangled_name;
1488 }
1489 }
1490 #endif /* 0 */
1491
1492 #undef ADD_EXTRA
1493 /* End of new code added to support parsing of Cfront stabs strings */
1494
1495 /* Parse a type expression in the string [P..P+LENGTH). If an error occurs,
1496 silently return builtin_type_void. */
1497
1498 struct type *
1499 safe_parse_type (char *p, int length)
1500 {
1501 struct ui_file *saved_gdb_stderr;
1502 struct type *type;
1503
1504 /* Suppress error messages. */
1505 saved_gdb_stderr = gdb_stderr;
1506 gdb_stderr = ui_file_new ();
1507
1508 /* Call parse_and_eval_type() without fear of longjmp()s. */
1509 if (!gdb_parse_and_eval_type (p, length, &type))
1510 type = builtin_type_void;
1511
1512 /* Stop suppressing error messages. */
1513 ui_file_delete (gdb_stderr);
1514 gdb_stderr = saved_gdb_stderr;
1515
1516 return type;
1517 }
1518
1519 /* Ugly hack to convert method stubs into method types.
1520
1521 He ain't kiddin'. This demangles the name of the method into a string
1522 including argument types, parses out each argument type, generates
1523 a string casting a zero to that type, evaluates the string, and stuffs
1524 the resulting type into an argtype vector!!! Then it knows the type
1525 of the whole function (including argument types for overloading),
1526 which info used to be in the stab's but was removed to hack back
1527 the space required for them. */
1528
1529 void
1530 check_stub_method (struct type *type, int method_id, int signature_id)
1531 {
1532 struct fn_field *f;
1533 char *mangled_name = gdb_mangle_name (type, method_id, signature_id);
1534 char *demangled_name = cplus_demangle (mangled_name,
1535 DMGL_PARAMS | DMGL_ANSI);
1536 char *argtypetext, *p;
1537 int depth = 0, argcount = 1;
1538 struct type **argtypes;
1539 struct type *mtype;
1540
1541 /* Make sure we got back a function string that we can use. */
1542 if (demangled_name)
1543 p = strchr (demangled_name, '(');
1544 else
1545 p = NULL;
1546
1547 if (demangled_name == NULL || p == NULL)
1548 error ("Internal: Cannot demangle mangled name `%s'.", mangled_name);
1549
1550 /* Now, read in the parameters that define this type. */
1551 p += 1;
1552 argtypetext = p;
1553 while (*p)
1554 {
1555 if (*p == '(' || *p == '<')
1556 {
1557 depth += 1;
1558 }
1559 else if (*p == ')' || *p == '>')
1560 {
1561 depth -= 1;
1562 }
1563 else if (*p == ',' && depth == 0)
1564 {
1565 argcount += 1;
1566 }
1567
1568 p += 1;
1569 }
1570
1571 /* We need two more slots: one for the THIS pointer, and one for the
1572 NULL [...] or void [end of arglist]. */
1573
1574 argtypes = (struct type **)
1575 TYPE_ALLOC (type, (argcount + 2) * sizeof (struct type *));
1576 p = argtypetext;
1577 /* FIXME: This is wrong for static member functions. */
1578 argtypes[0] = lookup_pointer_type (type);
1579 argcount = 1;
1580
1581 if (*p != ')') /* () means no args, skip while */
1582 {
1583 depth = 0;
1584 while (*p)
1585 {
1586 if (depth <= 0 && (*p == ',' || *p == ')'))
1587 {
1588 /* Avoid parsing of ellipsis, they will be handled below. */
1589 if (strncmp (argtypetext, "...", p - argtypetext) != 0)
1590 {
1591 argtypes[argcount] =
1592 safe_parse_type (argtypetext, p - argtypetext);
1593 argcount += 1;
1594 }
1595 argtypetext = p + 1;
1596 }
1597
1598 if (*p == '(' || *p == '<')
1599 {
1600 depth += 1;
1601 }
1602 else if (*p == ')' || *p == '>')
1603 {
1604 depth -= 1;
1605 }
1606
1607 p += 1;
1608 }
1609 }
1610
1611 if (p[-2] != '.') /* Not '...' */
1612 {
1613 argtypes[argcount] = builtin_type_void; /* List terminator */
1614 }
1615 else
1616 {
1617 argtypes[argcount] = NULL; /* Ellist terminator */
1618 }
1619
1620 xfree (demangled_name);
1621
1622 f = TYPE_FN_FIELDLIST1 (type, method_id);
1623
1624 TYPE_FN_FIELD_PHYSNAME (f, signature_id) = mangled_name;
1625
1626 /* Now update the old "stub" type into a real type. */
1627 mtype = TYPE_FN_FIELD_TYPE (f, signature_id);
1628 TYPE_DOMAIN_TYPE (mtype) = type;
1629 TYPE_ARG_TYPES (mtype) = argtypes;
1630 TYPE_FLAGS (mtype) &= ~TYPE_FLAG_STUB;
1631 TYPE_FN_FIELD_STUB (f, signature_id) = 0;
1632 }
1633
1634 const struct cplus_struct_type cplus_struct_default;
1635
1636 void
1637 allocate_cplus_struct_type (struct type *type)
1638 {
1639 if (!HAVE_CPLUS_STRUCT (type))
1640 {
1641 TYPE_CPLUS_SPECIFIC (type) = (struct cplus_struct_type *)
1642 TYPE_ALLOC (type, sizeof (struct cplus_struct_type));
1643 *(TYPE_CPLUS_SPECIFIC (type)) = cplus_struct_default;
1644 }
1645 }
1646
1647 /* Helper function to initialize the standard scalar types.
1648
1649 If NAME is non-NULL and OBJFILE is non-NULL, then we make a copy
1650 of the string pointed to by name in the type_obstack for that objfile,
1651 and initialize the type name to that copy. There are places (mipsread.c
1652 in particular, where init_type is called with a NULL value for NAME). */
1653
1654 struct type *
1655 init_type (enum type_code code, int length, int flags, char *name,
1656 struct objfile *objfile)
1657 {
1658 register struct type *type;
1659
1660 type = alloc_type (objfile);
1661 TYPE_CODE (type) = code;
1662 TYPE_LENGTH (type) = length;
1663 TYPE_FLAGS (type) |= flags;
1664 if ((name != NULL) && (objfile != NULL))
1665 {
1666 TYPE_NAME (type) =
1667 obsavestring (name, strlen (name), &objfile->type_obstack);
1668 }
1669 else
1670 {
1671 TYPE_NAME (type) = name;
1672 }
1673
1674 /* C++ fancies. */
1675
1676 if (code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION)
1677 {
1678 INIT_CPLUS_SPECIFIC (type);
1679 }
1680 return (type);
1681 }
1682
1683 /* Look up a fundamental type for the specified objfile.
1684 May need to construct such a type if this is the first use.
1685
1686 Some object file formats (ELF, COFF, etc) do not define fundamental
1687 types such as "int" or "double". Others (stabs for example), do
1688 define fundamental types.
1689
1690 For the formats which don't provide fundamental types, gdb can create
1691 such types, using defaults reasonable for the current language and
1692 the current target machine.
1693
1694 NOTE: This routine is obsolescent. Each debugging format reader
1695 should manage it's own fundamental types, either creating them from
1696 suitable defaults or reading them from the debugging information,
1697 whichever is appropriate. The DWARF reader has already been
1698 fixed to do this. Once the other readers are fixed, this routine
1699 will go away. Also note that fundamental types should be managed
1700 on a compilation unit basis in a multi-language environment, not
1701 on a linkage unit basis as is done here. */
1702
1703
1704 struct type *
1705 lookup_fundamental_type (struct objfile *objfile, int typeid)
1706 {
1707 register struct type **typep;
1708 register int nbytes;
1709
1710 if (typeid < 0 || typeid >= FT_NUM_MEMBERS)
1711 {
1712 error ("internal error - invalid fundamental type id %d", typeid);
1713 }
1714
1715 /* If this is the first time we need a fundamental type for this objfile
1716 then we need to initialize the vector of type pointers. */
1717
1718 if (objfile->fundamental_types == NULL)
1719 {
1720 nbytes = FT_NUM_MEMBERS * sizeof (struct type *);
1721 objfile->fundamental_types = (struct type **)
1722 obstack_alloc (&objfile->type_obstack, nbytes);
1723 memset ((char *) objfile->fundamental_types, 0, nbytes);
1724 OBJSTAT (objfile, n_types += FT_NUM_MEMBERS);
1725 }
1726
1727 /* Look for this particular type in the fundamental type vector. If one is
1728 not found, create and install one appropriate for the current language. */
1729
1730 typep = objfile->fundamental_types + typeid;
1731 if (*typep == NULL)
1732 {
1733 *typep = create_fundamental_type (objfile, typeid);
1734 }
1735
1736 return (*typep);
1737 }
1738
1739 int
1740 can_dereference (struct type *t)
1741 {
1742 /* FIXME: Should we return true for references as well as pointers? */
1743 CHECK_TYPEDEF (t);
1744 return
1745 (t != NULL
1746 && TYPE_CODE (t) == TYPE_CODE_PTR
1747 && TYPE_CODE (TYPE_TARGET_TYPE (t)) != TYPE_CODE_VOID);
1748 }
1749
1750 int
1751 is_integral_type (struct type *t)
1752 {
1753 CHECK_TYPEDEF (t);
1754 return
1755 ((t != NULL)
1756 && ((TYPE_CODE (t) == TYPE_CODE_INT)
1757 || (TYPE_CODE (t) == TYPE_CODE_ENUM)
1758 || (TYPE_CODE (t) == TYPE_CODE_CHAR)
1759 || (TYPE_CODE (t) == TYPE_CODE_RANGE)
1760 || (TYPE_CODE (t) == TYPE_CODE_BOOL)));
1761 }
1762
1763 /* Chill varying string and arrays are represented as follows:
1764
1765 struct { int __var_length; ELEMENT_TYPE[MAX_SIZE] __var_data};
1766
1767 Return true if TYPE is such a Chill varying type. */
1768
1769 int
1770 chill_varying_type (struct type *type)
1771 {
1772 if (TYPE_CODE (type) != TYPE_CODE_STRUCT
1773 || TYPE_NFIELDS (type) != 2
1774 || strcmp (TYPE_FIELD_NAME (type, 0), "__var_length") != 0)
1775 return 0;
1776 return 1;
1777 }
1778
1779 /* Check whether BASE is an ancestor or base class or DCLASS
1780 Return 1 if so, and 0 if not.
1781 Note: callers may want to check for identity of the types before
1782 calling this function -- identical types are considered to satisfy
1783 the ancestor relationship even if they're identical */
1784
1785 int
1786 is_ancestor (struct type *base, struct type *dclass)
1787 {
1788 int i;
1789
1790 CHECK_TYPEDEF (base);
1791 CHECK_TYPEDEF (dclass);
1792
1793 if (base == dclass)
1794 return 1;
1795 if (TYPE_NAME (base) && TYPE_NAME (dclass) &&
1796 !strcmp (TYPE_NAME (base), TYPE_NAME (dclass)))
1797 return 1;
1798
1799 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
1800 if (is_ancestor (base, TYPE_BASECLASS (dclass, i)))
1801 return 1;
1802
1803 return 0;
1804 }
1805
1806
1807
1808 /* See whether DCLASS has a virtual table. This routine is aimed at
1809 the HP/Taligent ANSI C++ runtime model, and may not work with other
1810 runtime models. Return 1 => Yes, 0 => No. */
1811
1812 int
1813 has_vtable (struct type *dclass)
1814 {
1815 /* In the HP ANSI C++ runtime model, a class has a vtable only if it
1816 has virtual functions or virtual bases. */
1817
1818 register int i;
1819
1820 if (TYPE_CODE (dclass) != TYPE_CODE_CLASS)
1821 return 0;
1822
1823 /* First check for the presence of virtual bases */
1824 if (TYPE_FIELD_VIRTUAL_BITS (dclass))
1825 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
1826 if (B_TST (TYPE_FIELD_VIRTUAL_BITS (dclass), i))
1827 return 1;
1828
1829 /* Next check for virtual functions */
1830 if (TYPE_FN_FIELDLISTS (dclass))
1831 for (i = 0; i < TYPE_NFN_FIELDS (dclass); i++)
1832 if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (dclass, i), 0))
1833 return 1;
1834
1835 /* Recurse on non-virtual bases to see if any of them needs a vtable */
1836 if (TYPE_FIELD_VIRTUAL_BITS (dclass))
1837 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
1838 if ((!B_TST (TYPE_FIELD_VIRTUAL_BITS (dclass), i)) &&
1839 (has_vtable (TYPE_FIELD_TYPE (dclass, i))))
1840 return 1;
1841
1842 /* Well, maybe we don't need a virtual table */
1843 return 0;
1844 }
1845
1846 /* Return a pointer to the "primary base class" of DCLASS.
1847
1848 A NULL return indicates that DCLASS has no primary base, or that it
1849 couldn't be found (insufficient information).
1850
1851 This routine is aimed at the HP/Taligent ANSI C++ runtime model,
1852 and may not work with other runtime models. */
1853
1854 struct type *
1855 primary_base_class (struct type *dclass)
1856 {
1857 /* In HP ANSI C++'s runtime model, a "primary base class" of a class
1858 is the first directly inherited, non-virtual base class that
1859 requires a virtual table */
1860
1861 register int i;
1862
1863 if (TYPE_CODE (dclass) != TYPE_CODE_CLASS)
1864 return NULL;
1865
1866 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
1867 if (!TYPE_FIELD_VIRTUAL (dclass, i) &&
1868 has_vtable (TYPE_FIELD_TYPE (dclass, i)))
1869 return TYPE_FIELD_TYPE (dclass, i);
1870
1871 return NULL;
1872 }
1873
1874 /* Global manipulated by virtual_base_list[_aux]() */
1875
1876 static struct vbase *current_vbase_list = NULL;
1877
1878 /* Return a pointer to a null-terminated list of struct vbase
1879 items. The vbasetype pointer of each item in the list points to the
1880 type information for a virtual base of the argument DCLASS.
1881
1882 Helper function for virtual_base_list().
1883 Note: the list goes backward, right-to-left. virtual_base_list()
1884 copies the items out in reverse order. */
1885
1886 static void
1887 virtual_base_list_aux (struct type *dclass)
1888 {
1889 struct vbase *tmp_vbase;
1890 register int i;
1891
1892 if (TYPE_CODE (dclass) != TYPE_CODE_CLASS)
1893 return;
1894
1895 for (i = 0; i < TYPE_N_BASECLASSES (dclass); i++)
1896 {
1897 /* Recurse on this ancestor, first */
1898 virtual_base_list_aux (TYPE_FIELD_TYPE (dclass, i));
1899
1900 /* If this current base is itself virtual, add it to the list */
1901 if (BASETYPE_VIA_VIRTUAL (dclass, i))
1902 {
1903 struct type *basetype = TYPE_FIELD_TYPE (dclass, i);
1904
1905 /* Check if base already recorded */
1906 tmp_vbase = current_vbase_list;
1907 while (tmp_vbase)
1908 {
1909 if (tmp_vbase->vbasetype == basetype)
1910 break; /* found it */
1911 tmp_vbase = tmp_vbase->next;
1912 }
1913
1914 if (!tmp_vbase) /* normal exit from loop */
1915 {
1916 /* Allocate new item for this virtual base */
1917 tmp_vbase = (struct vbase *) xmalloc (sizeof (struct vbase));
1918
1919 /* Stick it on at the end of the list */
1920 tmp_vbase->vbasetype = basetype;
1921 tmp_vbase->next = current_vbase_list;
1922 current_vbase_list = tmp_vbase;
1923 }
1924 } /* if virtual */
1925 } /* for loop over bases */
1926 }
1927
1928
1929 /* Compute the list of virtual bases in the right order. Virtual
1930 bases are laid out in the object's memory area in order of their
1931 occurrence in a depth-first, left-to-right search through the
1932 ancestors.
1933
1934 Argument DCLASS is the type whose virtual bases are required.
1935 Return value is the address of a null-terminated array of pointers
1936 to struct type items.
1937
1938 This routine is aimed at the HP/Taligent ANSI C++ runtime model,
1939 and may not work with other runtime models.
1940
1941 This routine merely hands off the argument to virtual_base_list_aux()
1942 and then copies the result into an array to save space. */
1943
1944 struct type **
1945 virtual_base_list (struct type *dclass)
1946 {
1947 register struct vbase *tmp_vbase;
1948 register struct vbase *tmp_vbase_2;
1949 register int i;
1950 int count;
1951 struct type **vbase_array;
1952
1953 current_vbase_list = NULL;
1954 virtual_base_list_aux (dclass);
1955
1956 for (i = 0, tmp_vbase = current_vbase_list; tmp_vbase != NULL; i++, tmp_vbase = tmp_vbase->next)
1957 /* no body */ ;
1958
1959 count = i;
1960
1961 vbase_array = (struct type **) xmalloc ((count + 1) * sizeof (struct type *));
1962
1963 for (i = count - 1, tmp_vbase = current_vbase_list; i >= 0; i--, tmp_vbase = tmp_vbase->next)
1964 vbase_array[i] = tmp_vbase->vbasetype;
1965
1966 /* Get rid of constructed chain */
1967 tmp_vbase_2 = tmp_vbase = current_vbase_list;
1968 while (tmp_vbase)
1969 {
1970 tmp_vbase = tmp_vbase->next;
1971 xfree (tmp_vbase_2);
1972 tmp_vbase_2 = tmp_vbase;
1973 }
1974
1975 vbase_array[count] = NULL;
1976 return vbase_array;
1977 }
1978
1979 /* Return the length of the virtual base list of the type DCLASS. */
1980
1981 int
1982 virtual_base_list_length (struct type *dclass)
1983 {
1984 register int i;
1985 register struct vbase *tmp_vbase;
1986
1987 current_vbase_list = NULL;
1988 virtual_base_list_aux (dclass);
1989
1990 for (i = 0, tmp_vbase = current_vbase_list; tmp_vbase != NULL; i++, tmp_vbase = tmp_vbase->next)
1991 /* no body */ ;
1992 return i;
1993 }
1994
1995 /* Return the number of elements of the virtual base list of the type
1996 DCLASS, ignoring those appearing in the primary base (and its
1997 primary base, recursively). */
1998
1999 int
2000 virtual_base_list_length_skip_primaries (struct type *dclass)
2001 {
2002 register int i;
2003 register struct vbase *tmp_vbase;
2004 struct type *primary;
2005
2006 primary = TYPE_RUNTIME_PTR (dclass) ? TYPE_PRIMARY_BASE (dclass) : NULL;
2007
2008 if (!primary)
2009 return virtual_base_list_length (dclass);
2010
2011 current_vbase_list = NULL;
2012 virtual_base_list_aux (dclass);
2013
2014 for (i = 0, tmp_vbase = current_vbase_list; tmp_vbase != NULL; tmp_vbase = tmp_vbase->next)
2015 {
2016 if (virtual_base_index (tmp_vbase->vbasetype, primary) >= 0)
2017 continue;
2018 i++;
2019 }
2020 return i;
2021 }
2022
2023
2024 /* Return the index (position) of type BASE, which is a virtual base
2025 class of DCLASS, in the latter's virtual base list. A return of -1
2026 indicates "not found" or a problem. */
2027
2028 int
2029 virtual_base_index (struct type *base, struct type *dclass)
2030 {
2031 register struct type *vbase;
2032 register int i;
2033
2034 if ((TYPE_CODE (dclass) != TYPE_CODE_CLASS) ||
2035 (TYPE_CODE (base) != TYPE_CODE_CLASS))
2036 return -1;
2037
2038 i = 0;
2039 vbase = virtual_base_list (dclass)[0];
2040 while (vbase)
2041 {
2042 if (vbase == base)
2043 break;
2044 vbase = virtual_base_list (dclass)[++i];
2045 }
2046
2047 return vbase ? i : -1;
2048 }
2049
2050
2051
2052 /* Return the index (position) of type BASE, which is a virtual base
2053 class of DCLASS, in the latter's virtual base list. Skip over all
2054 bases that may appear in the virtual base list of the primary base
2055 class of DCLASS (recursively). A return of -1 indicates "not
2056 found" or a problem. */
2057
2058 int
2059 virtual_base_index_skip_primaries (struct type *base, struct type *dclass)
2060 {
2061 register struct type *vbase;
2062 register int i, j;
2063 struct type *primary;
2064
2065 if ((TYPE_CODE (dclass) != TYPE_CODE_CLASS) ||
2066 (TYPE_CODE (base) != TYPE_CODE_CLASS))
2067 return -1;
2068
2069 primary = TYPE_RUNTIME_PTR (dclass) ? TYPE_PRIMARY_BASE (dclass) : NULL;
2070
2071 j = -1;
2072 i = 0;
2073 vbase = virtual_base_list (dclass)[0];
2074 while (vbase)
2075 {
2076 if (!primary || (virtual_base_index_skip_primaries (vbase, primary) < 0))
2077 j++;
2078 if (vbase == base)
2079 break;
2080 vbase = virtual_base_list (dclass)[++i];
2081 }
2082
2083 return vbase ? j : -1;
2084 }
2085
2086 /* Return position of a derived class DCLASS in the list of
2087 * primary bases starting with the remotest ancestor.
2088 * Position returned is 0-based. */
2089
2090 int
2091 class_index_in_primary_list (struct type *dclass)
2092 {
2093 struct type *pbc; /* primary base class */
2094
2095 /* Simply recurse on primary base */
2096 pbc = TYPE_PRIMARY_BASE (dclass);
2097 if (pbc)
2098 return 1 + class_index_in_primary_list (pbc);
2099 else
2100 return 0;
2101 }
2102
2103 /* Return a count of the number of virtual functions a type has.
2104 * This includes all the virtual functions it inherits from its
2105 * base classes too.
2106 */
2107
2108 /* pai: FIXME This doesn't do the right thing: count redefined virtual
2109 * functions only once (latest redefinition)
2110 */
2111
2112 int
2113 count_virtual_fns (struct type *dclass)
2114 {
2115 int fn, oi; /* function and overloaded instance indices */
2116 int vfuncs; /* count to return */
2117
2118 /* recurse on bases that can share virtual table */
2119 struct type *pbc = primary_base_class (dclass);
2120 if (pbc)
2121 vfuncs = count_virtual_fns (pbc);
2122 else
2123 vfuncs = 0;
2124
2125 for (fn = 0; fn < TYPE_NFN_FIELDS (dclass); fn++)
2126 for (oi = 0; oi < TYPE_FN_FIELDLIST_LENGTH (dclass, fn); oi++)
2127 if (TYPE_FN_FIELD_VIRTUAL_P (TYPE_FN_FIELDLIST1 (dclass, fn), oi))
2128 vfuncs++;
2129
2130 return vfuncs;
2131 }
2132 \f
2133
2134
2135 /* Functions for overload resolution begin here */
2136
2137 /* Compare two badness vectors A and B and return the result.
2138 * 0 => A and B are identical
2139 * 1 => A and B are incomparable
2140 * 2 => A is better than B
2141 * 3 => A is worse than B */
2142
2143 int
2144 compare_badness (struct badness_vector *a, struct badness_vector *b)
2145 {
2146 int i;
2147 int tmp;
2148 short found_pos = 0; /* any positives in c? */
2149 short found_neg = 0; /* any negatives in c? */
2150
2151 /* differing lengths => incomparable */
2152 if (a->length != b->length)
2153 return 1;
2154
2155 /* Subtract b from a */
2156 for (i = 0; i < a->length; i++)
2157 {
2158 tmp = a->rank[i] - b->rank[i];
2159 if (tmp > 0)
2160 found_pos = 1;
2161 else if (tmp < 0)
2162 found_neg = 1;
2163 }
2164
2165 if (found_pos)
2166 {
2167 if (found_neg)
2168 return 1; /* incomparable */
2169 else
2170 return 3; /* A > B */
2171 }
2172 else
2173 /* no positives */
2174 {
2175 if (found_neg)
2176 return 2; /* A < B */
2177 else
2178 return 0; /* A == B */
2179 }
2180 }
2181
2182 /* Rank a function by comparing its parameter types (PARMS, length NPARMS),
2183 * to the types of an argument list (ARGS, length NARGS).
2184 * Return a pointer to a badness vector. This has NARGS + 1 entries. */
2185
2186 struct badness_vector *
2187 rank_function (struct type **parms, int nparms, struct type **args, int nargs)
2188 {
2189 int i;
2190 struct badness_vector *bv;
2191 int min_len = nparms < nargs ? nparms : nargs;
2192
2193 bv = xmalloc (sizeof (struct badness_vector));
2194 bv->length = nargs + 1; /* add 1 for the length-match rank */
2195 bv->rank = xmalloc ((nargs + 1) * sizeof (int));
2196
2197 /* First compare the lengths of the supplied lists.
2198 * If there is a mismatch, set it to a high value. */
2199
2200 /* pai/1997-06-03 FIXME: when we have debug info about default
2201 * arguments and ellipsis parameter lists, we should consider those
2202 * and rank the length-match more finely. */
2203
2204 LENGTH_MATCH (bv) = (nargs != nparms) ? LENGTH_MISMATCH_BADNESS : 0;
2205
2206 /* Now rank all the parameters of the candidate function */
2207 for (i = 1; i <= min_len; i++)
2208 bv->rank[i] = rank_one_type (parms[i-1], args[i-1]);
2209
2210 /* If more arguments than parameters, add dummy entries */
2211 for (i = min_len + 1; i <= nargs; i++)
2212 bv->rank[i] = TOO_FEW_PARAMS_BADNESS;
2213
2214 return bv;
2215 }
2216
2217 /* Compare one type (PARM) for compatibility with another (ARG).
2218 * PARM is intended to be the parameter type of a function; and
2219 * ARG is the supplied argument's type. This function tests if
2220 * the latter can be converted to the former.
2221 *
2222 * Return 0 if they are identical types;
2223 * Otherwise, return an integer which corresponds to how compatible
2224 * PARM is to ARG. The higher the return value, the worse the match.
2225 * Generally the "bad" conversions are all uniformly assigned a 100 */
2226
2227 int
2228 rank_one_type (struct type *parm, struct type *arg)
2229 {
2230 /* Identical type pointers */
2231 /* However, this still doesn't catch all cases of same type for arg
2232 * and param. The reason is that builtin types are different from
2233 * the same ones constructed from the object. */
2234 if (parm == arg)
2235 return 0;
2236
2237 /* Resolve typedefs */
2238 if (TYPE_CODE (parm) == TYPE_CODE_TYPEDEF)
2239 parm = check_typedef (parm);
2240 if (TYPE_CODE (arg) == TYPE_CODE_TYPEDEF)
2241 arg = check_typedef (arg);
2242
2243 /*
2244 Well, damnit, if the names are exactly the same,
2245 i'll say they are exactly the same. This happens when we generate
2246 method stubs. The types won't point to the same address, but they
2247 really are the same.
2248 */
2249
2250 if (TYPE_NAME (parm) && TYPE_NAME (arg) &&
2251 !strcmp (TYPE_NAME (parm), TYPE_NAME (arg)))
2252 return 0;
2253
2254 /* Check if identical after resolving typedefs */
2255 if (parm == arg)
2256 return 0;
2257
2258 /* See through references, since we can almost make non-references
2259 references. */
2260 if (TYPE_CODE (arg) == TYPE_CODE_REF)
2261 return (rank_one_type (parm, TYPE_TARGET_TYPE (arg))
2262 + REFERENCE_CONVERSION_BADNESS);
2263 if (TYPE_CODE (parm) == TYPE_CODE_REF)
2264 return (rank_one_type (TYPE_TARGET_TYPE (parm), arg)
2265 + REFERENCE_CONVERSION_BADNESS);
2266 if (overload_debug)
2267 /* Debugging only. */
2268 fprintf_filtered (gdb_stderr,"------ Arg is %s [%d], parm is %s [%d]\n",
2269 TYPE_NAME (arg), TYPE_CODE (arg), TYPE_NAME (parm), TYPE_CODE (parm));
2270
2271 /* x -> y means arg of type x being supplied for parameter of type y */
2272
2273 switch (TYPE_CODE (parm))
2274 {
2275 case TYPE_CODE_PTR:
2276 switch (TYPE_CODE (arg))
2277 {
2278 case TYPE_CODE_PTR:
2279 if (TYPE_CODE (TYPE_TARGET_TYPE (parm)) == TYPE_CODE_VOID)
2280 return VOID_PTR_CONVERSION_BADNESS;
2281 else
2282 return rank_one_type (TYPE_TARGET_TYPE (parm), TYPE_TARGET_TYPE (arg));
2283 case TYPE_CODE_ARRAY:
2284 return rank_one_type (TYPE_TARGET_TYPE (parm), TYPE_TARGET_TYPE (arg));
2285 case TYPE_CODE_FUNC:
2286 return rank_one_type (TYPE_TARGET_TYPE (parm), arg);
2287 case TYPE_CODE_INT:
2288 case TYPE_CODE_ENUM:
2289 case TYPE_CODE_CHAR:
2290 case TYPE_CODE_RANGE:
2291 case TYPE_CODE_BOOL:
2292 return POINTER_CONVERSION_BADNESS;
2293 default:
2294 return INCOMPATIBLE_TYPE_BADNESS;
2295 }
2296 case TYPE_CODE_ARRAY:
2297 switch (TYPE_CODE (arg))
2298 {
2299 case TYPE_CODE_PTR:
2300 case TYPE_CODE_ARRAY:
2301 return rank_one_type (TYPE_TARGET_TYPE (parm), TYPE_TARGET_TYPE (arg));
2302 default:
2303 return INCOMPATIBLE_TYPE_BADNESS;
2304 }
2305 case TYPE_CODE_FUNC:
2306 switch (TYPE_CODE (arg))
2307 {
2308 case TYPE_CODE_PTR: /* funcptr -> func */
2309 return rank_one_type (parm, TYPE_TARGET_TYPE (arg));
2310 default:
2311 return INCOMPATIBLE_TYPE_BADNESS;
2312 }
2313 case TYPE_CODE_INT:
2314 switch (TYPE_CODE (arg))
2315 {
2316 case TYPE_CODE_INT:
2317 if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm))
2318 {
2319 /* Deal with signed, unsigned, and plain chars and
2320 signed and unsigned ints */
2321 if (TYPE_NOSIGN (parm))
2322 {
2323 /* This case only for character types */
2324 if (TYPE_NOSIGN (arg)) /* plain char -> plain char */
2325 return 0;
2326 else
2327 return INTEGER_COERCION_BADNESS; /* signed/unsigned char -> plain char */
2328 }
2329 else if (TYPE_UNSIGNED (parm))
2330 {
2331 if (TYPE_UNSIGNED (arg))
2332 {
2333 if (!strcmp_iw (TYPE_NAME (parm), TYPE_NAME (arg)))
2334 return 0; /* unsigned int -> unsigned int, or unsigned long -> unsigned long */
2335 else if (!strcmp_iw (TYPE_NAME (arg), "int") && !strcmp_iw (TYPE_NAME (parm), "long"))
2336 return INTEGER_PROMOTION_BADNESS; /* unsigned int -> unsigned long */
2337 else
2338 return INTEGER_COERCION_BADNESS; /* unsigned long -> unsigned int */
2339 }
2340 else
2341 {
2342 if (!strcmp_iw (TYPE_NAME (arg), "long") && !strcmp_iw (TYPE_NAME (parm), "int"))
2343 return INTEGER_COERCION_BADNESS; /* signed long -> unsigned int */
2344 else
2345 return INTEGER_CONVERSION_BADNESS; /* signed int/long -> unsigned int/long */
2346 }
2347 }
2348 else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg))
2349 {
2350 if (!strcmp_iw (TYPE_NAME (parm), TYPE_NAME (arg)))
2351 return 0;
2352 else if (!strcmp_iw (TYPE_NAME (arg), "int") && !strcmp_iw (TYPE_NAME (parm), "long"))
2353 return INTEGER_PROMOTION_BADNESS;
2354 else
2355 return INTEGER_COERCION_BADNESS;
2356 }
2357 else
2358 return INTEGER_COERCION_BADNESS;
2359 }
2360 else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
2361 return INTEGER_PROMOTION_BADNESS;
2362 else
2363 return INTEGER_COERCION_BADNESS;
2364 case TYPE_CODE_ENUM:
2365 case TYPE_CODE_CHAR:
2366 case TYPE_CODE_RANGE:
2367 case TYPE_CODE_BOOL:
2368 return INTEGER_PROMOTION_BADNESS;
2369 case TYPE_CODE_FLT:
2370 return INT_FLOAT_CONVERSION_BADNESS;
2371 case TYPE_CODE_PTR:
2372 return NS_POINTER_CONVERSION_BADNESS;
2373 default:
2374 return INCOMPATIBLE_TYPE_BADNESS;
2375 }
2376 break;
2377 case TYPE_CODE_ENUM:
2378 switch (TYPE_CODE (arg))
2379 {
2380 case TYPE_CODE_INT:
2381 case TYPE_CODE_CHAR:
2382 case TYPE_CODE_RANGE:
2383 case TYPE_CODE_BOOL:
2384 case TYPE_CODE_ENUM:
2385 return INTEGER_COERCION_BADNESS;
2386 case TYPE_CODE_FLT:
2387 return INT_FLOAT_CONVERSION_BADNESS;
2388 default:
2389 return INCOMPATIBLE_TYPE_BADNESS;
2390 }
2391 break;
2392 case TYPE_CODE_CHAR:
2393 switch (TYPE_CODE (arg))
2394 {
2395 case TYPE_CODE_RANGE:
2396 case TYPE_CODE_BOOL:
2397 case TYPE_CODE_ENUM:
2398 return INTEGER_COERCION_BADNESS;
2399 case TYPE_CODE_FLT:
2400 return INT_FLOAT_CONVERSION_BADNESS;
2401 case TYPE_CODE_INT:
2402 if (TYPE_LENGTH (arg) > TYPE_LENGTH (parm))
2403 return INTEGER_COERCION_BADNESS;
2404 else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
2405 return INTEGER_PROMOTION_BADNESS;
2406 /* >>> !! else fall through !! <<< */
2407 case TYPE_CODE_CHAR:
2408 /* Deal with signed, unsigned, and plain chars for C++
2409 and with int cases falling through from previous case */
2410 if (TYPE_NOSIGN (parm))
2411 {
2412 if (TYPE_NOSIGN (arg))
2413 return 0;
2414 else
2415 return INTEGER_COERCION_BADNESS;
2416 }
2417 else if (TYPE_UNSIGNED (parm))
2418 {
2419 if (TYPE_UNSIGNED (arg))
2420 return 0;
2421 else
2422 return INTEGER_PROMOTION_BADNESS;
2423 }
2424 else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg))
2425 return 0;
2426 else
2427 return INTEGER_COERCION_BADNESS;
2428 default:
2429 return INCOMPATIBLE_TYPE_BADNESS;
2430 }
2431 break;
2432 case TYPE_CODE_RANGE:
2433 switch (TYPE_CODE (arg))
2434 {
2435 case TYPE_CODE_INT:
2436 case TYPE_CODE_CHAR:
2437 case TYPE_CODE_RANGE:
2438 case TYPE_CODE_BOOL:
2439 case TYPE_CODE_ENUM:
2440 return INTEGER_COERCION_BADNESS;
2441 case TYPE_CODE_FLT:
2442 return INT_FLOAT_CONVERSION_BADNESS;
2443 default:
2444 return INCOMPATIBLE_TYPE_BADNESS;
2445 }
2446 break;
2447 case TYPE_CODE_BOOL:
2448 switch (TYPE_CODE (arg))
2449 {
2450 case TYPE_CODE_INT:
2451 case TYPE_CODE_CHAR:
2452 case TYPE_CODE_RANGE:
2453 case TYPE_CODE_ENUM:
2454 case TYPE_CODE_FLT:
2455 case TYPE_CODE_PTR:
2456 return BOOLEAN_CONVERSION_BADNESS;
2457 case TYPE_CODE_BOOL:
2458 return 0;
2459 default:
2460 return INCOMPATIBLE_TYPE_BADNESS;
2461 }
2462 break;
2463 case TYPE_CODE_FLT:
2464 switch (TYPE_CODE (arg))
2465 {
2466 case TYPE_CODE_FLT:
2467 if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
2468 return FLOAT_PROMOTION_BADNESS;
2469 else if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm))
2470 return 0;
2471 else
2472 return FLOAT_CONVERSION_BADNESS;
2473 case TYPE_CODE_INT:
2474 case TYPE_CODE_BOOL:
2475 case TYPE_CODE_ENUM:
2476 case TYPE_CODE_RANGE:
2477 case TYPE_CODE_CHAR:
2478 return INT_FLOAT_CONVERSION_BADNESS;
2479 default:
2480 return INCOMPATIBLE_TYPE_BADNESS;
2481 }
2482 break;
2483 case TYPE_CODE_COMPLEX:
2484 switch (TYPE_CODE (arg))
2485 { /* Strictly not needed for C++, but... */
2486 case TYPE_CODE_FLT:
2487 return FLOAT_PROMOTION_BADNESS;
2488 case TYPE_CODE_COMPLEX:
2489 return 0;
2490 default:
2491 return INCOMPATIBLE_TYPE_BADNESS;
2492 }
2493 break;
2494 case TYPE_CODE_STRUCT:
2495 /* currently same as TYPE_CODE_CLASS */
2496 switch (TYPE_CODE (arg))
2497 {
2498 case TYPE_CODE_STRUCT:
2499 /* Check for derivation */
2500 if (is_ancestor (parm, arg))
2501 return BASE_CONVERSION_BADNESS;
2502 /* else fall through */
2503 default:
2504 return INCOMPATIBLE_TYPE_BADNESS;
2505 }
2506 break;
2507 case TYPE_CODE_UNION:
2508 switch (TYPE_CODE (arg))
2509 {
2510 case TYPE_CODE_UNION:
2511 default:
2512 return INCOMPATIBLE_TYPE_BADNESS;
2513 }
2514 break;
2515 case TYPE_CODE_MEMBER:
2516 switch (TYPE_CODE (arg))
2517 {
2518 default:
2519 return INCOMPATIBLE_TYPE_BADNESS;
2520 }
2521 break;
2522 case TYPE_CODE_METHOD:
2523 switch (TYPE_CODE (arg))
2524 {
2525
2526 default:
2527 return INCOMPATIBLE_TYPE_BADNESS;
2528 }
2529 break;
2530 case TYPE_CODE_REF:
2531 switch (TYPE_CODE (arg))
2532 {
2533
2534 default:
2535 return INCOMPATIBLE_TYPE_BADNESS;
2536 }
2537
2538 break;
2539 case TYPE_CODE_SET:
2540 switch (TYPE_CODE (arg))
2541 {
2542 /* Not in C++ */
2543 case TYPE_CODE_SET:
2544 return rank_one_type (TYPE_FIELD_TYPE (parm, 0), TYPE_FIELD_TYPE (arg, 0));
2545 default:
2546 return INCOMPATIBLE_TYPE_BADNESS;
2547 }
2548 break;
2549 case TYPE_CODE_VOID:
2550 default:
2551 return INCOMPATIBLE_TYPE_BADNESS;
2552 } /* switch (TYPE_CODE (arg)) */
2553 }
2554
2555
2556 /* End of functions for overload resolution */
2557
2558 static void
2559 print_bit_vector (B_TYPE *bits, int nbits)
2560 {
2561 int bitno;
2562
2563 for (bitno = 0; bitno < nbits; bitno++)
2564 {
2565 if ((bitno % 8) == 0)
2566 {
2567 puts_filtered (" ");
2568 }
2569 if (B_TST (bits, bitno))
2570 {
2571 printf_filtered ("1");
2572 }
2573 else
2574 {
2575 printf_filtered ("0");
2576 }
2577 }
2578 }
2579
2580 /* The args list is a strange beast. It is either terminated by a NULL
2581 pointer for varargs functions, or by a pointer to a TYPE_CODE_VOID
2582 type for normal fixed argcount functions. (FIXME someday)
2583 Also note the first arg should be the "this" pointer, we may not want to
2584 include it since we may get into a infinitely recursive situation. */
2585
2586 static void
2587 print_arg_types (struct type **args, int spaces)
2588 {
2589 if (args != NULL)
2590 {
2591 while (*args != NULL)
2592 {
2593 recursive_dump_type (*args, spaces + 2);
2594 if ((*args++)->code == TYPE_CODE_VOID)
2595 {
2596 break;
2597 }
2598 }
2599 }
2600 }
2601
2602 static void
2603 dump_fn_fieldlists (struct type *type, int spaces)
2604 {
2605 int method_idx;
2606 int overload_idx;
2607 struct fn_field *f;
2608
2609 printfi_filtered (spaces, "fn_fieldlists ");
2610 gdb_print_host_address (TYPE_FN_FIELDLISTS (type), gdb_stdout);
2611 printf_filtered ("\n");
2612 for (method_idx = 0; method_idx < TYPE_NFN_FIELDS (type); method_idx++)
2613 {
2614 f = TYPE_FN_FIELDLIST1 (type, method_idx);
2615 printfi_filtered (spaces + 2, "[%d] name '%s' (",
2616 method_idx,
2617 TYPE_FN_FIELDLIST_NAME (type, method_idx));
2618 gdb_print_host_address (TYPE_FN_FIELDLIST_NAME (type, method_idx),
2619 gdb_stdout);
2620 printf_filtered (") length %d\n",
2621 TYPE_FN_FIELDLIST_LENGTH (type, method_idx));
2622 for (overload_idx = 0;
2623 overload_idx < TYPE_FN_FIELDLIST_LENGTH (type, method_idx);
2624 overload_idx++)
2625 {
2626 printfi_filtered (spaces + 4, "[%d] physname '%s' (",
2627 overload_idx,
2628 TYPE_FN_FIELD_PHYSNAME (f, overload_idx));
2629 gdb_print_host_address (TYPE_FN_FIELD_PHYSNAME (f, overload_idx),
2630 gdb_stdout);
2631 printf_filtered (")\n");
2632 printfi_filtered (spaces + 8, "type ");
2633 gdb_print_host_address (TYPE_FN_FIELD_TYPE (f, overload_idx), gdb_stdout);
2634 printf_filtered ("\n");
2635
2636 recursive_dump_type (TYPE_FN_FIELD_TYPE (f, overload_idx),
2637 spaces + 8 + 2);
2638
2639 printfi_filtered (spaces + 8, "args ");
2640 gdb_print_host_address (TYPE_FN_FIELD_ARGS (f, overload_idx), gdb_stdout);
2641 printf_filtered ("\n");
2642
2643 print_arg_types (TYPE_FN_FIELD_ARGS (f, overload_idx), spaces);
2644 printfi_filtered (spaces + 8, "fcontext ");
2645 gdb_print_host_address (TYPE_FN_FIELD_FCONTEXT (f, overload_idx),
2646 gdb_stdout);
2647 printf_filtered ("\n");
2648
2649 printfi_filtered (spaces + 8, "is_const %d\n",
2650 TYPE_FN_FIELD_CONST (f, overload_idx));
2651 printfi_filtered (spaces + 8, "is_volatile %d\n",
2652 TYPE_FN_FIELD_VOLATILE (f, overload_idx));
2653 printfi_filtered (spaces + 8, "is_private %d\n",
2654 TYPE_FN_FIELD_PRIVATE (f, overload_idx));
2655 printfi_filtered (spaces + 8, "is_protected %d\n",
2656 TYPE_FN_FIELD_PROTECTED (f, overload_idx));
2657 printfi_filtered (spaces + 8, "is_stub %d\n",
2658 TYPE_FN_FIELD_STUB (f, overload_idx));
2659 printfi_filtered (spaces + 8, "voffset %u\n",
2660 TYPE_FN_FIELD_VOFFSET (f, overload_idx));
2661 }
2662 }
2663 }
2664
2665 static void
2666 print_cplus_stuff (struct type *type, int spaces)
2667 {
2668 printfi_filtered (spaces, "n_baseclasses %d\n",
2669 TYPE_N_BASECLASSES (type));
2670 printfi_filtered (spaces, "nfn_fields %d\n",
2671 TYPE_NFN_FIELDS (type));
2672 printfi_filtered (spaces, "nfn_fields_total %d\n",
2673 TYPE_NFN_FIELDS_TOTAL (type));
2674 if (TYPE_N_BASECLASSES (type) > 0)
2675 {
2676 printfi_filtered (spaces, "virtual_field_bits (%d bits at *",
2677 TYPE_N_BASECLASSES (type));
2678 gdb_print_host_address (TYPE_FIELD_VIRTUAL_BITS (type), gdb_stdout);
2679 printf_filtered (")");
2680
2681 print_bit_vector (TYPE_FIELD_VIRTUAL_BITS (type),
2682 TYPE_N_BASECLASSES (type));
2683 puts_filtered ("\n");
2684 }
2685 if (TYPE_NFIELDS (type) > 0)
2686 {
2687 if (TYPE_FIELD_PRIVATE_BITS (type) != NULL)
2688 {
2689 printfi_filtered (spaces, "private_field_bits (%d bits at *",
2690 TYPE_NFIELDS (type));
2691 gdb_print_host_address (TYPE_FIELD_PRIVATE_BITS (type), gdb_stdout);
2692 printf_filtered (")");
2693 print_bit_vector (TYPE_FIELD_PRIVATE_BITS (type),
2694 TYPE_NFIELDS (type));
2695 puts_filtered ("\n");
2696 }
2697 if (TYPE_FIELD_PROTECTED_BITS (type) != NULL)
2698 {
2699 printfi_filtered (spaces, "protected_field_bits (%d bits at *",
2700 TYPE_NFIELDS (type));
2701 gdb_print_host_address (TYPE_FIELD_PROTECTED_BITS (type), gdb_stdout);
2702 printf_filtered (")");
2703 print_bit_vector (TYPE_FIELD_PROTECTED_BITS (type),
2704 TYPE_NFIELDS (type));
2705 puts_filtered ("\n");
2706 }
2707 }
2708 if (TYPE_NFN_FIELDS (type) > 0)
2709 {
2710 dump_fn_fieldlists (type, spaces);
2711 }
2712 }
2713
2714 static void
2715 print_bound_type (int bt)
2716 {
2717 switch (bt)
2718 {
2719 case BOUND_CANNOT_BE_DETERMINED:
2720 printf_filtered ("(BOUND_CANNOT_BE_DETERMINED)");
2721 break;
2722 case BOUND_BY_REF_ON_STACK:
2723 printf_filtered ("(BOUND_BY_REF_ON_STACK)");
2724 break;
2725 case BOUND_BY_VALUE_ON_STACK:
2726 printf_filtered ("(BOUND_BY_VALUE_ON_STACK)");
2727 break;
2728 case BOUND_BY_REF_IN_REG:
2729 printf_filtered ("(BOUND_BY_REF_IN_REG)");
2730 break;
2731 case BOUND_BY_VALUE_IN_REG:
2732 printf_filtered ("(BOUND_BY_VALUE_IN_REG)");
2733 break;
2734 case BOUND_SIMPLE:
2735 printf_filtered ("(BOUND_SIMPLE)");
2736 break;
2737 default:
2738 printf_filtered ("(unknown bound type)");
2739 break;
2740 }
2741 }
2742
2743 static struct obstack dont_print_type_obstack;
2744
2745 void
2746 recursive_dump_type (struct type *type, int spaces)
2747 {
2748 int idx;
2749
2750 if (spaces == 0)
2751 obstack_begin (&dont_print_type_obstack, 0);
2752
2753 if (TYPE_NFIELDS (type) > 0
2754 || (TYPE_CPLUS_SPECIFIC (type) && TYPE_NFN_FIELDS (type) > 0))
2755 {
2756 struct type **first_dont_print
2757 = (struct type **) obstack_base (&dont_print_type_obstack);
2758
2759 int i = (struct type **) obstack_next_free (&dont_print_type_obstack)
2760 - first_dont_print;
2761
2762 while (--i >= 0)
2763 {
2764 if (type == first_dont_print[i])
2765 {
2766 printfi_filtered (spaces, "type node ");
2767 gdb_print_host_address (type, gdb_stdout);
2768 printf_filtered (" <same as already seen type>\n");
2769 return;
2770 }
2771 }
2772
2773 obstack_ptr_grow (&dont_print_type_obstack, type);
2774 }
2775
2776 printfi_filtered (spaces, "type node ");
2777 gdb_print_host_address (type, gdb_stdout);
2778 printf_filtered ("\n");
2779 printfi_filtered (spaces, "name '%s' (",
2780 TYPE_NAME (type) ? TYPE_NAME (type) : "<NULL>");
2781 gdb_print_host_address (TYPE_NAME (type), gdb_stdout);
2782 printf_filtered (")\n");
2783 printfi_filtered (spaces, "tagname '%s' (",
2784 TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : "<NULL>");
2785 gdb_print_host_address (TYPE_TAG_NAME (type), gdb_stdout);
2786 printf_filtered (")\n");
2787 printfi_filtered (spaces, "code 0x%x ", TYPE_CODE (type));
2788 switch (TYPE_CODE (type))
2789 {
2790 case TYPE_CODE_UNDEF:
2791 printf_filtered ("(TYPE_CODE_UNDEF)");
2792 break;
2793 case TYPE_CODE_PTR:
2794 printf_filtered ("(TYPE_CODE_PTR)");
2795 break;
2796 case TYPE_CODE_ARRAY:
2797 printf_filtered ("(TYPE_CODE_ARRAY)");
2798 break;
2799 case TYPE_CODE_STRUCT:
2800 printf_filtered ("(TYPE_CODE_STRUCT)");
2801 break;
2802 case TYPE_CODE_UNION:
2803 printf_filtered ("(TYPE_CODE_UNION)");
2804 break;
2805 case TYPE_CODE_ENUM:
2806 printf_filtered ("(TYPE_CODE_ENUM)");
2807 break;
2808 case TYPE_CODE_FUNC:
2809 printf_filtered ("(TYPE_CODE_FUNC)");
2810 break;
2811 case TYPE_CODE_INT:
2812 printf_filtered ("(TYPE_CODE_INT)");
2813 break;
2814 case TYPE_CODE_FLT:
2815 printf_filtered ("(TYPE_CODE_FLT)");
2816 break;
2817 case TYPE_CODE_VOID:
2818 printf_filtered ("(TYPE_CODE_VOID)");
2819 break;
2820 case TYPE_CODE_SET:
2821 printf_filtered ("(TYPE_CODE_SET)");
2822 break;
2823 case TYPE_CODE_RANGE:
2824 printf_filtered ("(TYPE_CODE_RANGE)");
2825 break;
2826 case TYPE_CODE_STRING:
2827 printf_filtered ("(TYPE_CODE_STRING)");
2828 break;
2829 case TYPE_CODE_BITSTRING:
2830 printf_filtered ("(TYPE_CODE_BITSTRING)");
2831 break;
2832 case TYPE_CODE_ERROR:
2833 printf_filtered ("(TYPE_CODE_ERROR)");
2834 break;
2835 case TYPE_CODE_MEMBER:
2836 printf_filtered ("(TYPE_CODE_MEMBER)");
2837 break;
2838 case TYPE_CODE_METHOD:
2839 printf_filtered ("(TYPE_CODE_METHOD)");
2840 break;
2841 case TYPE_CODE_REF:
2842 printf_filtered ("(TYPE_CODE_REF)");
2843 break;
2844 case TYPE_CODE_CHAR:
2845 printf_filtered ("(TYPE_CODE_CHAR)");
2846 break;
2847 case TYPE_CODE_BOOL:
2848 printf_filtered ("(TYPE_CODE_BOOL)");
2849 break;
2850 case TYPE_CODE_COMPLEX:
2851 printf_filtered ("(TYPE_CODE_COMPLEX)");
2852 break;
2853 case TYPE_CODE_TYPEDEF:
2854 printf_filtered ("(TYPE_CODE_TYPEDEF)");
2855 break;
2856 case TYPE_CODE_TEMPLATE:
2857 printf_filtered ("(TYPE_CODE_TEMPLATE)");
2858 break;
2859 case TYPE_CODE_TEMPLATE_ARG:
2860 printf_filtered ("(TYPE_CODE_TEMPLATE_ARG)");
2861 break;
2862 default:
2863 printf_filtered ("(UNKNOWN TYPE CODE)");
2864 break;
2865 }
2866 puts_filtered ("\n");
2867 printfi_filtered (spaces, "length %d\n", TYPE_LENGTH (type));
2868 printfi_filtered (spaces, "upper_bound_type 0x%x ",
2869 TYPE_ARRAY_UPPER_BOUND_TYPE (type));
2870 print_bound_type (TYPE_ARRAY_UPPER_BOUND_TYPE (type));
2871 puts_filtered ("\n");
2872 printfi_filtered (spaces, "lower_bound_type 0x%x ",
2873 TYPE_ARRAY_LOWER_BOUND_TYPE (type));
2874 print_bound_type (TYPE_ARRAY_LOWER_BOUND_TYPE (type));
2875 puts_filtered ("\n");
2876 printfi_filtered (spaces, "objfile ");
2877 gdb_print_host_address (TYPE_OBJFILE (type), gdb_stdout);
2878 printf_filtered ("\n");
2879 printfi_filtered (spaces, "target_type ");
2880 gdb_print_host_address (TYPE_TARGET_TYPE (type), gdb_stdout);
2881 printf_filtered ("\n");
2882 if (TYPE_TARGET_TYPE (type) != NULL)
2883 {
2884 recursive_dump_type (TYPE_TARGET_TYPE (type), spaces + 2);
2885 }
2886 printfi_filtered (spaces, "pointer_type ");
2887 gdb_print_host_address (TYPE_POINTER_TYPE (type), gdb_stdout);
2888 printf_filtered ("\n");
2889 printfi_filtered (spaces, "reference_type ");
2890 gdb_print_host_address (TYPE_REFERENCE_TYPE (type), gdb_stdout);
2891 printf_filtered ("\n");
2892 printfi_filtered (spaces, "cv_type ");
2893 gdb_print_host_address (TYPE_CV_TYPE (type), gdb_stdout);
2894 printf_filtered ("\n");
2895 printfi_filtered (spaces, "as_type ");
2896 gdb_print_host_address (TYPE_AS_TYPE (type), gdb_stdout);
2897 printf_filtered ("\n");
2898 printfi_filtered (spaces, "flags 0x%x", TYPE_FLAGS (type));
2899 if (TYPE_UNSIGNED (type))
2900 {
2901 puts_filtered (" TYPE_FLAG_UNSIGNED");
2902 }
2903 if (TYPE_NOSIGN (type))
2904 {
2905 puts_filtered (" TYPE_FLAG_NOSIGN");
2906 }
2907 if (TYPE_STUB (type))
2908 {
2909 puts_filtered (" TYPE_FLAG_STUB");
2910 }
2911 if (TYPE_TARGET_STUB (type))
2912 {
2913 puts_filtered (" TYPE_FLAG_TARGET_STUB");
2914 }
2915 if (TYPE_STATIC (type))
2916 {
2917 puts_filtered (" TYPE_FLAG_STATIC");
2918 }
2919 if (TYPE_CONST (type))
2920 {
2921 puts_filtered (" TYPE_FLAG_CONST");
2922 }
2923 if (TYPE_VOLATILE (type))
2924 {
2925 puts_filtered (" TYPE_FLAG_VOLATILE");
2926 }
2927 if (TYPE_PROTOTYPED (type))
2928 {
2929 puts_filtered (" TYPE_FLAG_PROTOTYPED");
2930 }
2931 if (TYPE_INCOMPLETE (type))
2932 {
2933 puts_filtered (" TYPE_FLAG_INCOMPLETE");
2934 }
2935 if (TYPE_CODE_SPACE (type))
2936 {
2937 puts_filtered (" TYPE_FLAG_CODE_SPACE");
2938 }
2939 if (TYPE_DATA_SPACE (type))
2940 {
2941 puts_filtered (" TYPE_FLAG_DATA_SPACE");
2942 }
2943 if (TYPE_VARARGS (type))
2944 {
2945 puts_filtered (" TYPE_FLAG_VARARGS");
2946 }
2947 puts_filtered ("\n");
2948 printfi_filtered (spaces, "nfields %d ", TYPE_NFIELDS (type));
2949 gdb_print_host_address (TYPE_FIELDS (type), gdb_stdout);
2950 puts_filtered ("\n");
2951 for (idx = 0; idx < TYPE_NFIELDS (type); idx++)
2952 {
2953 printfi_filtered (spaces + 2,
2954 "[%d] bitpos %d bitsize %d type ",
2955 idx, TYPE_FIELD_BITPOS (type, idx),
2956 TYPE_FIELD_BITSIZE (type, idx));
2957 gdb_print_host_address (TYPE_FIELD_TYPE (type, idx), gdb_stdout);
2958 printf_filtered (" name '%s' (",
2959 TYPE_FIELD_NAME (type, idx) != NULL
2960 ? TYPE_FIELD_NAME (type, idx)
2961 : "<NULL>");
2962 gdb_print_host_address (TYPE_FIELD_NAME (type, idx), gdb_stdout);
2963 printf_filtered (")\n");
2964 if (TYPE_FIELD_TYPE (type, idx) != NULL)
2965 {
2966 recursive_dump_type (TYPE_FIELD_TYPE (type, idx), spaces + 4);
2967 }
2968 }
2969 printfi_filtered (spaces, "vptr_basetype ");
2970 gdb_print_host_address (TYPE_VPTR_BASETYPE (type), gdb_stdout);
2971 puts_filtered ("\n");
2972 if (TYPE_VPTR_BASETYPE (type) != NULL)
2973 {
2974 recursive_dump_type (TYPE_VPTR_BASETYPE (type), spaces + 2);
2975 }
2976 printfi_filtered (spaces, "vptr_fieldno %d\n", TYPE_VPTR_FIELDNO (type));
2977 switch (TYPE_CODE (type))
2978 {
2979 case TYPE_CODE_METHOD:
2980 case TYPE_CODE_FUNC:
2981 printfi_filtered (spaces, "arg_types ");
2982 gdb_print_host_address (TYPE_ARG_TYPES (type), gdb_stdout);
2983 puts_filtered ("\n");
2984 print_arg_types (TYPE_ARG_TYPES (type), spaces);
2985 break;
2986
2987 case TYPE_CODE_STRUCT:
2988 printfi_filtered (spaces, "cplus_stuff ");
2989 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type), gdb_stdout);
2990 puts_filtered ("\n");
2991 print_cplus_stuff (type, spaces);
2992 break;
2993
2994 case TYPE_CODE_FLT:
2995 printfi_filtered (spaces, "floatformat ");
2996 if (TYPE_FLOATFORMAT (type) == NULL
2997 || TYPE_FLOATFORMAT (type)->name == NULL)
2998 puts_filtered ("(null)");
2999 else
3000 puts_filtered (TYPE_FLOATFORMAT (type)->name);
3001 puts_filtered ("\n");
3002 break;
3003
3004 default:
3005 /* We have to pick one of the union types to be able print and test
3006 the value. Pick cplus_struct_type, even though we know it isn't
3007 any particular one. */
3008 printfi_filtered (spaces, "type_specific ");
3009 gdb_print_host_address (TYPE_CPLUS_SPECIFIC (type), gdb_stdout);
3010 if (TYPE_CPLUS_SPECIFIC (type) != NULL)
3011 {
3012 printf_filtered (" (unknown data form)");
3013 }
3014 printf_filtered ("\n");
3015 break;
3016
3017 }
3018 if (spaces == 0)
3019 obstack_free (&dont_print_type_obstack, NULL);
3020 }
3021
3022 static void build_gdbtypes (void);
3023 static void
3024 build_gdbtypes (void)
3025 {
3026 builtin_type_void =
3027 init_type (TYPE_CODE_VOID, 1,
3028 0,
3029 "void", (struct objfile *) NULL);
3030 builtin_type_char =
3031 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3032 TYPE_FLAG_NOSIGN,
3033 "char", (struct objfile *) NULL);
3034 builtin_type_true_char =
3035 init_type (TYPE_CODE_CHAR, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3036 0,
3037 "true character", (struct objfile *) NULL);
3038 builtin_type_signed_char =
3039 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3040 0,
3041 "signed char", (struct objfile *) NULL);
3042 builtin_type_unsigned_char =
3043 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3044 TYPE_FLAG_UNSIGNED,
3045 "unsigned char", (struct objfile *) NULL);
3046 builtin_type_short =
3047 init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT,
3048 0,
3049 "short", (struct objfile *) NULL);
3050 builtin_type_unsigned_short =
3051 init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT,
3052 TYPE_FLAG_UNSIGNED,
3053 "unsigned short", (struct objfile *) NULL);
3054 builtin_type_int =
3055 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
3056 0,
3057 "int", (struct objfile *) NULL);
3058 builtin_type_unsigned_int =
3059 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
3060 TYPE_FLAG_UNSIGNED,
3061 "unsigned int", (struct objfile *) NULL);
3062 builtin_type_long =
3063 init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT,
3064 0,
3065 "long", (struct objfile *) NULL);
3066 builtin_type_unsigned_long =
3067 init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT,
3068 TYPE_FLAG_UNSIGNED,
3069 "unsigned long", (struct objfile *) NULL);
3070 builtin_type_long_long =
3071 init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
3072 0,
3073 "long long", (struct objfile *) NULL);
3074 builtin_type_unsigned_long_long =
3075 init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
3076 TYPE_FLAG_UNSIGNED,
3077 "unsigned long long", (struct objfile *) NULL);
3078 builtin_type_float =
3079 init_type (TYPE_CODE_FLT, TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
3080 0,
3081 "float", (struct objfile *) NULL);
3082 TYPE_FLOATFORMAT (builtin_type_float) = TARGET_FLOAT_FORMAT;
3083 builtin_type_double =
3084 init_type (TYPE_CODE_FLT, TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
3085 0,
3086 "double", (struct objfile *) NULL);
3087 TYPE_FLOATFORMAT (builtin_type_double) = TARGET_DOUBLE_FORMAT;
3088 builtin_type_long_double =
3089 init_type (TYPE_CODE_FLT, TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT,
3090 0,
3091 "long double", (struct objfile *) NULL);
3092 TYPE_FLOATFORMAT (builtin_type_long_double) = TARGET_LONG_DOUBLE_FORMAT;
3093 builtin_type_complex =
3094 init_type (TYPE_CODE_COMPLEX, 2 * TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
3095 0,
3096 "complex", (struct objfile *) NULL);
3097 TYPE_TARGET_TYPE (builtin_type_complex) = builtin_type_float;
3098 builtin_type_double_complex =
3099 init_type (TYPE_CODE_COMPLEX, 2 * TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
3100 0,
3101 "double complex", (struct objfile *) NULL);
3102 TYPE_TARGET_TYPE (builtin_type_double_complex) = builtin_type_double;
3103 builtin_type_string =
3104 init_type (TYPE_CODE_STRING, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3105 0,
3106 "string", (struct objfile *) NULL);
3107 builtin_type_int8 =
3108 init_type (TYPE_CODE_INT, 8 / 8,
3109 0,
3110 "int8_t", (struct objfile *) NULL);
3111 builtin_type_uint8 =
3112 init_type (TYPE_CODE_INT, 8 / 8,
3113 TYPE_FLAG_UNSIGNED,
3114 "uint8_t", (struct objfile *) NULL);
3115 builtin_type_int16 =
3116 init_type (TYPE_CODE_INT, 16 / 8,
3117 0,
3118 "int16_t", (struct objfile *) NULL);
3119 builtin_type_uint16 =
3120 init_type (TYPE_CODE_INT, 16 / 8,
3121 TYPE_FLAG_UNSIGNED,
3122 "uint16_t", (struct objfile *) NULL);
3123 builtin_type_int32 =
3124 init_type (TYPE_CODE_INT, 32 / 8,
3125 0,
3126 "int32_t", (struct objfile *) NULL);
3127 builtin_type_uint32 =
3128 init_type (TYPE_CODE_INT, 32 / 8,
3129 TYPE_FLAG_UNSIGNED,
3130 "uint32_t", (struct objfile *) NULL);
3131 builtin_type_int64 =
3132 init_type (TYPE_CODE_INT, 64 / 8,
3133 0,
3134 "int64_t", (struct objfile *) NULL);
3135 builtin_type_uint64 =
3136 init_type (TYPE_CODE_INT, 64 / 8,
3137 TYPE_FLAG_UNSIGNED,
3138 "uint64_t", (struct objfile *) NULL);
3139 builtin_type_int128 =
3140 init_type (TYPE_CODE_INT, 128 / 8,
3141 0,
3142 "int128_t", (struct objfile *) NULL);
3143 builtin_type_uint128 =
3144 init_type (TYPE_CODE_INT, 128 / 8,
3145 TYPE_FLAG_UNSIGNED,
3146 "uint128_t", (struct objfile *) NULL);
3147 builtin_type_bool =
3148 init_type (TYPE_CODE_BOOL, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3149 0,
3150 "bool", (struct objfile *) NULL);
3151
3152 /* Add user knob for controlling resolution of opaque types */
3153 add_show_from_set
3154 (add_set_cmd ("opaque-type-resolution", class_support, var_boolean, (char *) &opaque_type_resolution,
3155 "Set resolution of opaque struct/class/union types (if set before loading symbols).",
3156 &setlist),
3157 &showlist);
3158 opaque_type_resolution = 1;
3159
3160 /* Build SIMD types. */
3161 builtin_type_v4sf
3162 = init_simd_type ("__builtin_v4sf", builtin_type_float, "f", 4);
3163 builtin_type_v4si
3164 = init_simd_type ("__builtin_v4si", builtin_type_int32, "f", 4);
3165 builtin_type_v8qi
3166 = init_simd_type ("__builtin_v8qi", builtin_type_int8, "f", 8);
3167 builtin_type_v4hi
3168 = init_simd_type ("__builtin_v4hi", builtin_type_int16, "f", 4);
3169 builtin_type_v2si
3170 = init_simd_type ("__builtin_v2si", builtin_type_int32, "f", 2);
3171
3172 /* Pointer/Address types. */
3173
3174 /* NOTE: on some targets, addresses and pointers are not necessarily
3175 the same --- for example, on the D10V, pointers are 16 bits long,
3176 but addresses are 32 bits long. See doc/gdbint.texinfo,
3177 ``Pointers Are Not Always Addresses''.
3178
3179 The upshot is:
3180 - gdb's `struct type' always describes the target's
3181 representation.
3182 - gdb's `struct value' objects should always hold values in
3183 target form.
3184 - gdb's CORE_ADDR values are addresses in the unified virtual
3185 address space that the assembler and linker work with. Thus,
3186 since target_read_memory takes a CORE_ADDR as an argument, it
3187 can access any memory on the target, even if the processor has
3188 separate code and data address spaces.
3189
3190 So, for example:
3191 - If v is a value holding a D10V code pointer, its contents are
3192 in target form: a big-endian address left-shifted two bits.
3193 - If p is a D10V pointer type, TYPE_LENGTH (p) == 2, just as
3194 sizeof (void *) == 2 on the target.
3195
3196 In this context, builtin_type_CORE_ADDR is a bit odd: it's a
3197 target type for a value the target will never see. It's only
3198 used to hold the values of (typeless) linker symbols, which are
3199 indeed in the unified virtual address space. */
3200 builtin_type_void_data_ptr = make_pointer_type (builtin_type_void, NULL);
3201 builtin_type_void_func_ptr
3202 = lookup_pointer_type (lookup_function_type (builtin_type_void));
3203 builtin_type_CORE_ADDR =
3204 init_type (TYPE_CODE_INT, TARGET_ADDR_BIT / 8,
3205 TYPE_FLAG_UNSIGNED,
3206 "__CORE_ADDR", (struct objfile *) NULL);
3207 builtin_type_bfd_vma =
3208 init_type (TYPE_CODE_INT, TARGET_BFD_VMA_BIT / 8,
3209 TYPE_FLAG_UNSIGNED,
3210 "__bfd_vma", (struct objfile *) NULL);
3211 }
3212
3213
3214 extern void _initialize_gdbtypes (void);
3215 void
3216 _initialize_gdbtypes (void)
3217 {
3218 struct cmd_list_element *c;
3219 build_gdbtypes ();
3220
3221 /* FIXME - For the moment, handle types by swapping them in and out.
3222 Should be using the per-architecture data-pointer and a large
3223 struct. */
3224 register_gdbarch_swap (&builtin_type_void, sizeof (struct type *), NULL);
3225 register_gdbarch_swap (&builtin_type_char, sizeof (struct type *), NULL);
3226 register_gdbarch_swap (&builtin_type_short, sizeof (struct type *), NULL);
3227 register_gdbarch_swap (&builtin_type_int, sizeof (struct type *), NULL);
3228 register_gdbarch_swap (&builtin_type_long, sizeof (struct type *), NULL);
3229 register_gdbarch_swap (&builtin_type_long_long, sizeof (struct type *), NULL);
3230 register_gdbarch_swap (&builtin_type_signed_char, sizeof (struct type *), NULL);
3231 register_gdbarch_swap (&builtin_type_unsigned_char, sizeof (struct type *), NULL);
3232 register_gdbarch_swap (&builtin_type_unsigned_short, sizeof (struct type *), NULL);
3233 register_gdbarch_swap (&builtin_type_unsigned_int, sizeof (struct type *), NULL);
3234 register_gdbarch_swap (&builtin_type_unsigned_long, sizeof (struct type *), NULL);
3235 register_gdbarch_swap (&builtin_type_unsigned_long_long, sizeof (struct type *), NULL);
3236 register_gdbarch_swap (&builtin_type_float, sizeof (struct type *), NULL);
3237 register_gdbarch_swap (&builtin_type_double, sizeof (struct type *), NULL);
3238 register_gdbarch_swap (&builtin_type_long_double, sizeof (struct type *), NULL);
3239 register_gdbarch_swap (&builtin_type_complex, sizeof (struct type *), NULL);
3240 register_gdbarch_swap (&builtin_type_double_complex, sizeof (struct type *), NULL);
3241 register_gdbarch_swap (&builtin_type_string, sizeof (struct type *), NULL);
3242 register_gdbarch_swap (&builtin_type_int8, sizeof (struct type *), NULL);
3243 register_gdbarch_swap (&builtin_type_uint8, sizeof (struct type *), NULL);
3244 register_gdbarch_swap (&builtin_type_int16, sizeof (struct type *), NULL);
3245 register_gdbarch_swap (&builtin_type_uint16, sizeof (struct type *), NULL);
3246 register_gdbarch_swap (&builtin_type_int32, sizeof (struct type *), NULL);
3247 register_gdbarch_swap (&builtin_type_uint32, sizeof (struct type *), NULL);
3248 register_gdbarch_swap (&builtin_type_int64, sizeof (struct type *), NULL);
3249 register_gdbarch_swap (&builtin_type_uint64, sizeof (struct type *), NULL);
3250 register_gdbarch_swap (&builtin_type_int128, sizeof (struct type *), NULL);
3251 register_gdbarch_swap (&builtin_type_uint128, sizeof (struct type *), NULL);
3252 register_gdbarch_swap (&builtin_type_v4sf, sizeof (struct type *), NULL);
3253 register_gdbarch_swap (&builtin_type_v4si, sizeof (struct type *), NULL);
3254 register_gdbarch_swap (&builtin_type_v8qi, sizeof (struct type *), NULL);
3255 register_gdbarch_swap (&builtin_type_v4hi, sizeof (struct type *), NULL);
3256 register_gdbarch_swap (&builtin_type_v2si, sizeof (struct type *), NULL);
3257 REGISTER_GDBARCH_SWAP (builtin_type_void_data_ptr);
3258 REGISTER_GDBARCH_SWAP (builtin_type_void_func_ptr);
3259 REGISTER_GDBARCH_SWAP (builtin_type_CORE_ADDR);
3260 REGISTER_GDBARCH_SWAP (builtin_type_bfd_vma);
3261 register_gdbarch_swap (NULL, 0, build_gdbtypes);
3262
3263 /* Note: These types do not need to be swapped - they are target
3264 neutral. */
3265 builtin_type_ieee_single_big =
3266 init_type (TYPE_CODE_FLT, floatformat_ieee_single_big.totalsize / 8,
3267 0, "builtin_type_ieee_single_big", NULL);
3268 TYPE_FLOATFORMAT (builtin_type_ieee_single_big) = &floatformat_ieee_single_big;
3269 builtin_type_ieee_single_little =
3270 init_type (TYPE_CODE_FLT, floatformat_ieee_single_little.totalsize / 8,
3271 0, "builtin_type_ieee_single_little", NULL);
3272 builtin_type_ieee_double_big =
3273 init_type (TYPE_CODE_FLT, floatformat_ieee_double_big.totalsize / 8,
3274 0, "builtin_type_ieee_double_big", NULL);
3275 builtin_type_ieee_double_little =
3276 init_type (TYPE_CODE_FLT, floatformat_ieee_double_little.totalsize / 8,
3277 0, "builtin_type_ieee_double_little", NULL);
3278 builtin_type_ieee_double_littlebyte_bigword =
3279 init_type (TYPE_CODE_FLT, floatformat_ieee_double_littlebyte_bigword.totalsize / 8,
3280 0, "builtin_type_ieee_double_littlebyte_bigword", NULL);
3281 builtin_type_i387_ext =
3282 init_type (TYPE_CODE_FLT, floatformat_i387_ext.totalsize / 8,
3283 0, "builtin_type_i387_ext", NULL);
3284 TYPE_FLOATFORMAT (builtin_type_i387_ext) = &floatformat_i387_ext;
3285 builtin_type_m68881_ext =
3286 init_type (TYPE_CODE_FLT, floatformat_m68881_ext.totalsize / 8,
3287 0, "builtin_type_m68881_ext", NULL);
3288 builtin_type_i960_ext =
3289 init_type (TYPE_CODE_FLT, floatformat_i960_ext.totalsize / 8,
3290 0, "builtin_type_i960_ext", NULL);
3291 builtin_type_m88110_ext =
3292 init_type (TYPE_CODE_FLT, floatformat_m88110_ext.totalsize / 8,
3293 0, "builtin_type_m88110_ext", NULL);
3294 builtin_type_m88110_harris_ext =
3295 init_type (TYPE_CODE_FLT, floatformat_m88110_harris_ext.totalsize / 8,
3296 0, "builtin_type_m88110_harris_ext", NULL);
3297 builtin_type_arm_ext_big =
3298 init_type (TYPE_CODE_FLT, floatformat_arm_ext_big.totalsize / 8,
3299 0, "builtin_type_arm_ext_big", NULL);
3300 builtin_type_arm_ext_littlebyte_bigword =
3301 init_type (TYPE_CODE_FLT, floatformat_arm_ext_littlebyte_bigword.totalsize / 8,
3302 0, "builtin_type_arm_ext_littlebyte_bigword", NULL);
3303 builtin_type_ia64_spill_big =
3304 init_type (TYPE_CODE_FLT, floatformat_ia64_spill_big.totalsize / 8,
3305 0, "builtin_type_ia64_spill_big", NULL);
3306 builtin_type_ia64_spill_little =
3307 init_type (TYPE_CODE_FLT, floatformat_ia64_spill_little.totalsize / 8,
3308 0, "builtin_type_ia64_spill_little", NULL);
3309 builtin_type_ia64_quad_big =
3310 init_type (TYPE_CODE_FLT, floatformat_ia64_quad_big.totalsize / 8,
3311 0, "builtin_type_ia64_quad_big", NULL);
3312 builtin_type_ia64_quad_little =
3313 init_type (TYPE_CODE_FLT, floatformat_ia64_quad_little.totalsize / 8,
3314 0, "builtin_type_ia64_quad_little", NULL);
3315
3316 add_show_from_set (
3317 add_set_cmd ("overload", no_class, var_zinteger, (char *) &overload_debug,
3318 "Set debugging of C++ overloading.\n\
3319 When enabled, ranking of the functions\n\
3320 is displayed.", &setdebuglist),
3321 &showdebuglist);
3322 }
This page took 0.106855 seconds and 4 git commands to generate.