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