Wed Dec 16 16:17:22 1998 Dave Brolley <brolley@cygnus.com>
[deliverable/binutils-gdb.git] / gdb / gdbtypes.c
CommitLineData
1ab3bf1b 1/* Support routines for manipulating internal types for GDB.
24418cfb 2 Copyright (C) 1992, 93, 94, 95, 96, 1998 Free Software Foundation, Inc.
1ab3bf1b
JG
3 Contributed by Cygnus Support, using pieces from other GDB modules.
4
5This file is part of GDB.
6
7This program is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with this program; if not, write to the Free Software
6c9638b4 19Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
1ab3bf1b 20
1ab3bf1b 21#include "defs.h"
2b576293 22#include "gdb_string.h"
1ab3bf1b
JG
23#include "bfd.h"
24#include "symtab.h"
25#include "symfile.h"
5e2e79f8 26#include "objfiles.h"
1ab3bf1b
JG
27#include "gdbtypes.h"
28#include "expression.h"
29#include "language.h"
30#include "target.h"
31#include "value.h"
8f793aa5 32#include "demangle.h"
51b80b00 33#include "complaints.h"
1ab3bf1b 34
c4413e2c
FF
35/* These variables point to the objects
36 representing the predefined C data types. */
37
38struct type *builtin_type_void;
39struct type *builtin_type_char;
40struct type *builtin_type_short;
41struct type *builtin_type_int;
42struct type *builtin_type_long;
43struct type *builtin_type_long_long;
44struct type *builtin_type_signed_char;
45struct type *builtin_type_unsigned_char;
46struct type *builtin_type_unsigned_short;
47struct type *builtin_type_unsigned_int;
48struct type *builtin_type_unsigned_long;
49struct type *builtin_type_unsigned_long_long;
50struct type *builtin_type_float;
51struct type *builtin_type_double;
52struct type *builtin_type_long_double;
53struct type *builtin_type_complex;
54struct type *builtin_type_double_complex;
55struct type *builtin_type_string;
980714f9
AC
56struct type *builtin_type_int8;
57struct type *builtin_type_uint8;
58struct type *builtin_type_int16;
59struct type *builtin_type_uint16;
60struct type *builtin_type_int32;
61struct type *builtin_type_uint32;
62struct type *builtin_type_int64;
63struct type *builtin_type_uint64;
64/* start-sanitize-r5900 */
65struct type *builtin_type_int128;
66struct type *builtin_type_uint128;
67/* end-sanitize-r5900 */
c4413e2c 68
b607efe7
FF
69struct extra { char str[128]; int len; }; /* maximum extention is 128! FIXME */
70
71static void add_name PARAMS ((struct extra *, char *));
72static void add_mangled_type PARAMS ((struct extra *, struct type *));
73#if 0
74static void cfront_mangle_name PARAMS ((struct type *, int, int));
75#endif
76static void print_bit_vector PARAMS ((B_TYPE *, int));
77static void print_arg_types PARAMS ((struct type **, int));
78static void dump_fn_fieldlists PARAMS ((struct type *, int));
79static void print_cplus_stuff PARAMS ((struct type *, int));
80
1ab3bf1b
JG
81/* Alloc a new type structure and fill it with some defaults. If
82 OBJFILE is non-NULL, then allocate the space for the type structure
83 in that objfile's type_obstack. */
84
85struct type *
86alloc_type (objfile)
87 struct objfile *objfile;
88{
89 register struct type *type;
90
91 /* Alloc the structure and start off with all fields zeroed. */
92
93 if (objfile == NULL)
94 {
95 type = (struct type *) xmalloc (sizeof (struct type));
96 }
97 else
98 {
99 type = (struct type *) obstack_alloc (&objfile -> type_obstack,
100 sizeof (struct type));
2dd30c72 101 OBJSTAT (objfile, n_types++);
1ab3bf1b 102 }
dac9734e 103 memset ((char *) type, 0, sizeof (struct type));
1ab3bf1b
JG
104
105 /* Initialize the fields that might not be zero. */
106
107 TYPE_CODE (type) = TYPE_CODE_UNDEF;
108 TYPE_OBJFILE (type) = objfile;
109 TYPE_VPTR_FIELDNO (type) = -1;
110
111 return (type);
112}
113
ea1549b3
JG
114/* Lookup a pointer to a type TYPE. TYPEPTR, if nonzero, points
115 to a pointer to memory where the pointer type should be stored.
116 If *TYPEPTR is zero, update it to point to the pointer type we return.
117 We allocate new memory if needed. */
118
119struct type *
120make_pointer_type (type, typeptr)
121 struct type *type;
122 struct type **typeptr;
123{
124 register struct type *ntype; /* New type */
125 struct objfile *objfile;
126
127 ntype = TYPE_POINTER_TYPE (type);
128
129 if (ntype)
24418cfb
JM
130 {
131 if (typeptr == 0)
132 return ntype; /* Don't care about alloc, and have new type. */
133 else if (*typeptr == 0)
134 {
135 *typeptr = ntype; /* Tracking alloc, and we have new type. */
136 return ntype;
137 }
138 }
ea1549b3
JG
139
140 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
141 {
142 ntype = alloc_type (TYPE_OBJFILE (type));
143 if (typeptr)
144 *typeptr = ntype;
145 }
146 else /* We have storage, but need to reset it. */
147 {
148 ntype = *typeptr;
149 objfile = TYPE_OBJFILE (ntype);
dac9734e 150 memset ((char *) ntype, 0, sizeof (struct type));
ea1549b3
JG
151 TYPE_OBJFILE (ntype) = objfile;
152 }
153
154 TYPE_TARGET_TYPE (ntype) = type;
155 TYPE_POINTER_TYPE (type) = ntype;
156
157 /* FIXME! Assume the machine has only one representation for pointers! */
158
159 TYPE_LENGTH (ntype) = TARGET_PTR_BIT / TARGET_CHAR_BIT;
160 TYPE_CODE (ntype) = TYPE_CODE_PTR;
161
162 /* pointers are unsigned */
163 TYPE_FLAGS (ntype) |= TYPE_FLAG_UNSIGNED;
164
165 if (!TYPE_POINTER_TYPE (type)) /* Remember it, if don't have one. */
166 TYPE_POINTER_TYPE (type) = ntype;
167
168 return ntype;
169}
170
1ab3bf1b
JG
171/* Given a type TYPE, return a type of pointers to that type.
172 May need to construct such a type if this is the first use. */
173
174struct type *
175lookup_pointer_type (type)
176 struct type *type;
177{
ea1549b3
JG
178 return make_pointer_type (type, (struct type **)0);
179}
180
181/* Lookup a C++ `reference' to a type TYPE. TYPEPTR, if nonzero, points
182 to a pointer to memory where the reference type should be stored.
183 If *TYPEPTR is zero, update it to point to the reference type we return.
184 We allocate new memory if needed. */
185
186struct type *
187make_reference_type (type, typeptr)
188 struct type *type;
189 struct type **typeptr;
190{
191 register struct type *ntype; /* New type */
192 struct objfile *objfile;
193
194 ntype = TYPE_REFERENCE_TYPE (type);
1ab3bf1b 195
ea1549b3 196 if (ntype)
24418cfb
JM
197 {
198 if (typeptr == 0)
199 return ntype; /* Don't care about alloc, and have new type. */
200 else if (*typeptr == 0)
201 {
202 *typeptr = ntype; /* Tracking alloc, and we have new type. */
203 return ntype;
204 }
205 }
ea1549b3
JG
206
207 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
208 {
209 ntype = alloc_type (TYPE_OBJFILE (type));
210 if (typeptr)
211 *typeptr = ntype;
212 }
213 else /* We have storage, but need to reset it. */
1ab3bf1b 214 {
ea1549b3
JG
215 ntype = *typeptr;
216 objfile = TYPE_OBJFILE (ntype);
dac9734e 217 memset ((char *) ntype, 0, sizeof (struct type));
ea1549b3 218 TYPE_OBJFILE (ntype) = objfile;
1ab3bf1b 219 }
ea1549b3
JG
220
221 TYPE_TARGET_TYPE (ntype) = type;
222 TYPE_REFERENCE_TYPE (type) = ntype;
223
224 /* FIXME! Assume the machine has only one representation for references,
225 and that it matches the (only) representation for pointers! */
226
227 TYPE_LENGTH (ntype) = TARGET_PTR_BIT / TARGET_CHAR_BIT;
228 TYPE_CODE (ntype) = TYPE_CODE_REF;
229
230 if (!TYPE_REFERENCE_TYPE (type)) /* Remember it, if don't have one. */
231 TYPE_REFERENCE_TYPE (type) = ntype;
232
233 return ntype;
1ab3bf1b
JG
234}
235
ea1549b3
JG
236/* Same as above, but caller doesn't care about memory allocation details. */
237
1ab3bf1b
JG
238struct type *
239lookup_reference_type (type)
240 struct type *type;
241{
ea1549b3
JG
242 return make_reference_type (type, (struct type **)0);
243}
244
245/* Lookup a function type that returns type TYPE. TYPEPTR, if nonzero, points
246 to a pointer to memory where the function type should be stored.
247 If *TYPEPTR is zero, update it to point to the function type we return.
248 We allocate new memory if needed. */
1ab3bf1b 249
ea1549b3
JG
250struct type *
251make_function_type (type, typeptr)
252 struct type *type;
253 struct type **typeptr;
254{
255 register struct type *ntype; /* New type */
256 struct objfile *objfile;
257
ea1549b3 258 if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
1ab3bf1b 259 {
ea1549b3
JG
260 ntype = alloc_type (TYPE_OBJFILE (type));
261 if (typeptr)
262 *typeptr = ntype;
1ab3bf1b 263 }
ea1549b3
JG
264 else /* We have storage, but need to reset it. */
265 {
266 ntype = *typeptr;
267 objfile = TYPE_OBJFILE (ntype);
dac9734e 268 memset ((char *) ntype, 0, sizeof (struct type));
ea1549b3
JG
269 TYPE_OBJFILE (ntype) = objfile;
270 }
271
272 TYPE_TARGET_TYPE (ntype) = type;
ea1549b3
JG
273
274 TYPE_LENGTH (ntype) = 1;
275 TYPE_CODE (ntype) = TYPE_CODE_FUNC;
276
ea1549b3 277 return ntype;
1ab3bf1b
JG
278}
279
ea1549b3 280
1ab3bf1b
JG
281/* Given a type TYPE, return a type of functions that return that type.
282 May need to construct such a type if this is the first use. */
283
284struct type *
285lookup_function_type (type)
286 struct type *type;
287{
ea1549b3 288 return make_function_type (type, (struct type **)0);
1ab3bf1b
JG
289}
290
291/* Implement direct support for MEMBER_TYPE in GNU C++.
292 May need to construct such a type if this is the first use.
293 The TYPE is the type of the member. The DOMAIN is the type
294 of the aggregate that the member belongs to. */
295
296struct type *
297lookup_member_type (type, domain)
298 struct type *type;
299 struct type *domain;
300{
301 register struct type *mtype;
302
303 mtype = alloc_type (TYPE_OBJFILE (type));
304 smash_to_member_type (mtype, domain, type);
305 return (mtype);
306}
307
308/* Allocate a stub method whose return type is TYPE.
309 This apparently happens for speed of symbol reading, since parsing
310 out the arguments to the method is cpu-intensive, the way we are doing
311 it. So, we will fill in arguments later.
312 This always returns a fresh type. */
313
314struct type *
315allocate_stub_method (type)
316 struct type *type;
317{
318 struct type *mtype;
319
320 mtype = alloc_type (TYPE_OBJFILE (type));
321 TYPE_TARGET_TYPE (mtype) = type;
322 /* _DOMAIN_TYPE (mtype) = unknown yet */
323 /* _ARG_TYPES (mtype) = unknown yet */
324 TYPE_FLAGS (mtype) = TYPE_FLAG_STUB;
325 TYPE_CODE (mtype) = TYPE_CODE_METHOD;
326 TYPE_LENGTH (mtype) = 1;
327 return (mtype);
328}
329
a8a69e63 330/* Create a range type using either a blank type supplied in RESULT_TYPE,
ec16f701
FF
331 or creating a new type, inheriting the objfile from INDEX_TYPE.
332
333 Indices will be of type INDEX_TYPE, and will range from LOW_BOUND to
334 HIGH_BOUND, inclusive.
a8a69e63
FF
335
336 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
337 sure it is TYPE_CODE_UNDEF before we bash it into a range type? */
338
339struct type *
340create_range_type (result_type, index_type, low_bound, high_bound)
341 struct type *result_type;
342 struct type *index_type;
343 int low_bound;
344 int high_bound;
345{
346 if (result_type == NULL)
347 {
348 result_type = alloc_type (TYPE_OBJFILE (index_type));
349 }
350 TYPE_CODE (result_type) = TYPE_CODE_RANGE;
351 TYPE_TARGET_TYPE (result_type) = index_type;
e55a5796
PB
352 if (TYPE_FLAGS (index_type) & TYPE_FLAG_STUB)
353 TYPE_FLAGS (result_type) |= TYPE_FLAG_TARGET_STUB;
354 else
d1f4065e 355 TYPE_LENGTH (result_type) = TYPE_LENGTH (check_typedef (index_type));
a8a69e63
FF
356 TYPE_NFIELDS (result_type) = 2;
357 TYPE_FIELDS (result_type) = (struct field *)
358 TYPE_ALLOC (result_type, 2 * sizeof (struct field));
359 memset (TYPE_FIELDS (result_type), 0, 2 * sizeof (struct field));
360 TYPE_FIELD_BITPOS (result_type, 0) = low_bound;
361 TYPE_FIELD_BITPOS (result_type, 1) = high_bound;
362 TYPE_FIELD_TYPE (result_type, 0) = builtin_type_int; /* FIXME */
363 TYPE_FIELD_TYPE (result_type, 1) = builtin_type_int; /* FIXME */
364
ce225290
FCE
365 if(low_bound >= 0)
366 TYPE_FLAGS (result_type) |= TYPE_FLAG_UNSIGNED;
367
a8a69e63
FF
368 return (result_type);
369}
370
706bfe5a
PB
371/* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type TYPE.
372 Return 1 of type is a range type, 0 if it is discrete (and bounds
373 will fit in LONGEST), or -1 otherwise. */
374
375int
376get_discrete_bounds (type, lowp, highp)
377 struct type *type;
378 LONGEST *lowp, *highp;
379{
d1f4065e 380 CHECK_TYPEDEF (type);
706bfe5a
PB
381 switch (TYPE_CODE (type))
382 {
4dda8ef3 383 case TYPE_CODE_RANGE:
706bfe5a
PB
384 *lowp = TYPE_LOW_BOUND (type);
385 *highp = TYPE_HIGH_BOUND (type);
386 return 1;
387 case TYPE_CODE_ENUM:
d1f4065e
PB
388 if (TYPE_NFIELDS (type) > 0)
389 {
d221b17e
WM
390 /* The enums may not be sorted by value, so search all
391 entries */
392 int i;
393
394 *lowp = *highp = TYPE_FIELD_BITPOS (type, 0);
395 for (i = 0; i < TYPE_NFIELDS (type); i++)
396 {
397 if (TYPE_FIELD_BITPOS (type, i) < *lowp)
398 *lowp = TYPE_FIELD_BITPOS (type, i);
399 if (TYPE_FIELD_BITPOS (type, i) > *highp)
400 *highp = TYPE_FIELD_BITPOS (type, i);
401 }
7924771e
FCE
402
403 /* Set unsigned indicator if warranted. */
404 if(*lowp >= 0)
405 {
406 TYPE_FLAGS (type) |= TYPE_FLAG_UNSIGNED;
407 }
d1f4065e
PB
408 }
409 else
410 {
411 *lowp = 0;
412 *highp = -1;
413 }
706bfe5a
PB
414 return 0;
415 case TYPE_CODE_BOOL:
416 *lowp = 0;
417 *highp = 1;
418 return 0;
419 case TYPE_CODE_INT:
f6d16585 420 if (TYPE_LENGTH (type) > sizeof (LONGEST)) /* Too big */
706bfe5a
PB
421 return -1;
422 if (!TYPE_UNSIGNED (type))
423 {
424 *lowp = - (1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1));
425 *highp = -*lowp - 1;
426 return 0;
427 }
428 /* ... fall through for unsigned ints ... */
429 case TYPE_CODE_CHAR:
430 *lowp = 0;
f6d16585
PB
431 /* This round-about calculation is to avoid shifting by
432 TYPE_LENGTH (type) * TARGET_CHAR_BIT, which will not work
433 if TYPE_LENGTH (type) == sizeof (LONGEST). */
434 *highp = 1 << (TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1);
435 *highp = (*highp - 1) | *highp;
706bfe5a
PB
436 return 0;
437 default:
438 return -1;
439 }
440}
441
85f0a848 442/* Create an array type using either a blank type supplied in RESULT_TYPE,
ec16f701
FF
443 or creating a new type, inheriting the objfile from RANGE_TYPE.
444
445 Elements will be of type ELEMENT_TYPE, the indices will be of type
446 RANGE_TYPE.
1ab3bf1b 447
85f0a848
FF
448 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
449 sure it is TYPE_CODE_UNDEF before we bash it into an array type? */
1ab3bf1b
JG
450
451struct type *
a8a69e63 452create_array_type (result_type, element_type, range_type)
85f0a848 453 struct type *result_type;
1ab3bf1b 454 struct type *element_type;
a8a69e63 455 struct type *range_type;
1ab3bf1b 456{
d1f4065e 457 LONGEST low_bound, high_bound;
1ab3bf1b 458
85f0a848
FF
459 if (result_type == NULL)
460 {
ec16f701 461 result_type = alloc_type (TYPE_OBJFILE (range_type));
85f0a848 462 }
1ab3bf1b
JG
463 TYPE_CODE (result_type) = TYPE_CODE_ARRAY;
464 TYPE_TARGET_TYPE (result_type) = element_type;
d1f4065e
PB
465 if (get_discrete_bounds (range_type, &low_bound, &high_bound) < 0)
466 low_bound = high_bound = 0;
467 CHECK_TYPEDEF (element_type);
85f0a848
FF
468 TYPE_LENGTH (result_type) =
469 TYPE_LENGTH (element_type) * (high_bound - low_bound + 1);
1ab3bf1b 470 TYPE_NFIELDS (result_type) = 1;
a8a69e63
FF
471 TYPE_FIELDS (result_type) =
472 (struct field *) TYPE_ALLOC (result_type, sizeof (struct field));
85f0a848 473 memset (TYPE_FIELDS (result_type), 0, sizeof (struct field));
8050a57b 474 TYPE_FIELD_TYPE (result_type, 0) = range_type;
1ab3bf1b
JG
475 TYPE_VPTR_FIELDNO (result_type) = -1;
476
81508b27
WM
477 /* TYPE_FLAG_TARGET_STUB will take care of zero length arrays */
478 if (TYPE_LENGTH (result_type) == 0)
479 TYPE_FLAGS (result_type) |= TYPE_FLAG_TARGET_STUB;
480
1ab3bf1b
JG
481 return (result_type);
482}
483
c4413e2c
FF
484/* Create a string type using either a blank type supplied in RESULT_TYPE,
485 or creating a new type. String types are similar enough to array of
486 char types that we can use create_array_type to build the basic type
487 and then bash it into a string type.
488
489 For fixed length strings, the range type contains 0 as the lower
490 bound and the length of the string minus one as the upper bound.
491
492 FIXME: Maybe we should check the TYPE_CODE of RESULT_TYPE to make
493 sure it is TYPE_CODE_UNDEF before we bash it into a string type? */
494
495struct type *
496create_string_type (result_type, range_type)
497 struct type *result_type;
498 struct type *range_type;
499{
ead95f8a
PB
500 result_type = create_array_type (result_type,
501 *current_language->string_char_type,
502 range_type);
c4413e2c
FF
503 TYPE_CODE (result_type) = TYPE_CODE_STRING;
504 return (result_type);
505}
1ab3bf1b 506
e909f287
PB
507struct type *
508create_set_type (result_type, domain_type)
509 struct type *result_type;
510 struct type *domain_type;
511{
d1f4065e 512 LONGEST low_bound, high_bound, bit_length;
e909f287
PB
513 if (result_type == NULL)
514 {
515 result_type = alloc_type (TYPE_OBJFILE (domain_type));
516 }
517 TYPE_CODE (result_type) = TYPE_CODE_SET;
518 TYPE_NFIELDS (result_type) = 1;
519 TYPE_FIELDS (result_type) = (struct field *)
520 TYPE_ALLOC (result_type, 1 * sizeof (struct field));
521 memset (TYPE_FIELDS (result_type), 0, sizeof (struct field));
576f9770
PB
522
523 if (! (TYPE_FLAGS (domain_type) & TYPE_FLAG_STUB))
524 {
d1f4065e
PB
525 if (get_discrete_bounds (domain_type, &low_bound, &high_bound) < 0)
526 low_bound = high_bound = 0;
576f9770
PB
527 bit_length = high_bound - low_bound + 1;
528 TYPE_LENGTH (result_type)
b4680522 529 = (bit_length + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT;
576f9770 530 }
e909f287 531 TYPE_FIELD_TYPE (result_type, 0) = domain_type;
7924771e
FCE
532
533 if(low_bound >= 0)
534 TYPE_FLAGS (result_type) |= TYPE_FLAG_UNSIGNED;
535
e909f287
PB
536 return (result_type);
537}
538
1ab3bf1b
JG
539/* Smash TYPE to be a type of members of DOMAIN with type TO_TYPE.
540 A MEMBER is a wierd thing -- it amounts to a typed offset into
541 a struct, e.g. "an int at offset 8". A MEMBER TYPE doesn't
542 include the offset (that's the value of the MEMBER itself), but does
543 include the structure type into which it points (for some reason).
544
c2e4669f 545 When "smashing" the type, we preserve the objfile that the
1ab3bf1b 546 old type pointed to, since we aren't changing where the type is actually
c2e4669f 547 allocated. */
1ab3bf1b
JG
548
549void
550smash_to_member_type (type, domain, to_type)
551 struct type *type;
552 struct type *domain;
553 struct type *to_type;
554{
555 struct objfile *objfile;
556
557 objfile = TYPE_OBJFILE (type);
558
dac9734e 559 memset ((char *) type, 0, sizeof (struct type));
1ab3bf1b
JG
560 TYPE_OBJFILE (type) = objfile;
561 TYPE_TARGET_TYPE (type) = to_type;
562 TYPE_DOMAIN_TYPE (type) = domain;
563 TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */
564 TYPE_CODE (type) = TYPE_CODE_MEMBER;
565}
566
567/* Smash TYPE to be a type of method of DOMAIN with type TO_TYPE.
568 METHOD just means `function that gets an extra "this" argument'.
569
c2e4669f 570 When "smashing" the type, we preserve the objfile that the
1ab3bf1b 571 old type pointed to, since we aren't changing where the type is actually
c2e4669f 572 allocated. */
1ab3bf1b
JG
573
574void
575smash_to_method_type (type, domain, to_type, args)
576 struct type *type;
577 struct type *domain;
578 struct type *to_type;
579 struct type **args;
580{
581 struct objfile *objfile;
582
583 objfile = TYPE_OBJFILE (type);
584
dac9734e 585 memset ((char *) type, 0, sizeof (struct type));
1ab3bf1b
JG
586 TYPE_OBJFILE (type) = objfile;
587 TYPE_TARGET_TYPE (type) = to_type;
588 TYPE_DOMAIN_TYPE (type) = domain;
589 TYPE_ARG_TYPES (type) = args;
590 TYPE_LENGTH (type) = 1; /* In practice, this is never needed. */
591 TYPE_CODE (type) = TYPE_CODE_METHOD;
592}
593
b2bebdb0
JK
594/* Return a typename for a struct/union/enum type without "struct ",
595 "union ", or "enum ". If the type has a NULL name, return NULL. */
1ab3bf1b
JG
596
597char *
598type_name_no_tag (type)
599 register const struct type *type;
600{
b2bebdb0
JK
601 if (TYPE_TAG_NAME (type) != NULL)
602 return TYPE_TAG_NAME (type);
1ab3bf1b 603
b2bebdb0
JK
604 /* Is there code which expects this to return the name if there is no
605 tag name? My guess is that this is mainly used for C++ in cases where
606 the two will always be the same. */
607 return TYPE_NAME (type);
1ab3bf1b
JG
608}
609
610/* Lookup a primitive type named NAME.
611 Return zero if NAME is not a primitive type.*/
612
613struct type *
614lookup_primitive_typename (name)
615 char *name;
616{
617 struct type ** const *p;
618
619 for (p = current_language -> la_builtin_type_vector; *p != NULL; p++)
620 {
2e4964ad 621 if (STREQ ((**p) -> name, name))
1ab3bf1b
JG
622 {
623 return (**p);
624 }
625 }
626 return (NULL);
627}
628
629/* Lookup a typedef or primitive type named NAME,
630 visible in lexical block BLOCK.
631 If NOERR is nonzero, return zero if NAME is not suitably defined. */
632
633struct type *
634lookup_typename (name, block, noerr)
635 char *name;
636 struct block *block;
637 int noerr;
638{
639 register struct symbol *sym;
640 register struct type *tmp;
641
642 sym = lookup_symbol (name, block, VAR_NAMESPACE, 0, (struct symtab **) NULL);
643 if (sym == NULL || SYMBOL_CLASS (sym) != LOC_TYPEDEF)
644 {
645 tmp = lookup_primitive_typename (name);
646 if (tmp)
647 {
648 return (tmp);
649 }
650 else if (!tmp && noerr)
651 {
652 return (NULL);
653 }
654 else
655 {
656 error ("No type named %s.", name);
657 }
658 }
659 return (SYMBOL_TYPE (sym));
660}
661
662struct type *
663lookup_unsigned_typename (name)
664 char *name;
665{
666 char *uns = alloca (strlen (name) + 10);
667
668 strcpy (uns, "unsigned ");
669 strcpy (uns + 9, name);
670 return (lookup_typename (uns, (struct block *) NULL, 0));
671}
672
a252e715
PB
673struct type *
674lookup_signed_typename (name)
675 char *name;
676{
677 struct type *t;
678 char *uns = alloca (strlen (name) + 8);
679
680 strcpy (uns, "signed ");
681 strcpy (uns + 7, name);
682 t = lookup_typename (uns, (struct block *) NULL, 1);
683 /* If we don't find "signed FOO" just try again with plain "FOO". */
684 if (t != NULL)
685 return t;
686 return lookup_typename (name, (struct block *) NULL, 0);
687}
688
1ab3bf1b
JG
689/* Lookup a structure type named "struct NAME",
690 visible in lexical block BLOCK. */
691
692struct type *
693lookup_struct (name, block)
694 char *name;
695 struct block *block;
696{
697 register struct symbol *sym;
698
699 sym = lookup_symbol (name, block, STRUCT_NAMESPACE, 0,
700 (struct symtab **) NULL);
701
702 if (sym == NULL)
703 {
704 error ("No struct type named %s.", name);
705 }
2640f7e1
JG
706 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
707 {
708 error ("This context has class, union or enum %s, not a struct.", name);
709 }
710 return (SYMBOL_TYPE (sym));
1ab3bf1b
JG
711}
712
713/* Lookup a union type named "union NAME",
714 visible in lexical block BLOCK. */
715
716struct type *
717lookup_union (name, block)
718 char *name;
719 struct block *block;
720{
721 register struct symbol *sym;
722
723 sym = lookup_symbol (name, block, STRUCT_NAMESPACE, 0,
724 (struct symtab **) NULL);
725
726 if (sym == NULL)
727 {
728 error ("No union type named %s.", name);
729 }
2640f7e1
JG
730 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_UNION)
731 {
732 error ("This context has class, struct or enum %s, not a union.", name);
733 }
734 return (SYMBOL_TYPE (sym));
1ab3bf1b
JG
735}
736
737/* Lookup an enum type named "enum NAME",
738 visible in lexical block BLOCK. */
739
740struct type *
741lookup_enum (name, block)
742 char *name;
743 struct block *block;
744{
745 register struct symbol *sym;
746
747 sym = lookup_symbol (name, block, STRUCT_NAMESPACE, 0,
748 (struct symtab **) NULL);
749 if (sym == NULL)
750 {
751 error ("No enum type named %s.", name);
752 }
2640f7e1
JG
753 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_ENUM)
754 {
755 error ("This context has class, struct or union %s, not an enum.", name);
756 }
757 return (SYMBOL_TYPE (sym));
1ab3bf1b
JG
758}
759
760/* Lookup a template type named "template NAME<TYPE>",
761 visible in lexical block BLOCK. */
762
763struct type *
764lookup_template_type (name, type, block)
765 char *name;
766 struct type *type;
767 struct block *block;
768{
769 struct symbol *sym;
770 char *nam = (char*) alloca(strlen(name) + strlen(type->name) + 4);
771 strcpy (nam, name);
772 strcat (nam, "<");
773 strcat (nam, type->name);
774 strcat (nam, " >"); /* FIXME, extra space still introduced in gcc? */
775
776 sym = lookup_symbol (nam, block, VAR_NAMESPACE, 0, (struct symtab **)NULL);
777
778 if (sym == NULL)
779 {
780 error ("No template type named %s.", name);
781 }
782 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_STRUCT)
783 {
784 error ("This context has class, union or enum %s, not a struct.", name);
785 }
786 return (SYMBOL_TYPE (sym));
787}
788
edf67bd1 789/* Given a type TYPE, lookup the type of the component of type named NAME.
45364c8a
FF
790
791 TYPE can be either a struct or union, or a pointer or reference to a struct or
792 union. If it is a pointer or reference, its target type is automatically used.
793 Thus '.' and '->' are interchangable, as specified for the definitions of the
794 expression element types STRUCTOP_STRUCT and STRUCTOP_PTR.
795
edf67bd1
MT
796 If NOERR is nonzero, return zero if NAME is not suitably defined.
797 If NAME is the name of a baseclass type, return that type. */
1ab3bf1b
JG
798
799struct type *
800lookup_struct_elt_type (type, name, noerr)
801 struct type *type;
802 char *name;
803 int noerr;
804{
805 int i;
806
d1f4065e
PB
807 for (;;)
808 {
809 CHECK_TYPEDEF (type);
810 if (TYPE_CODE (type) != TYPE_CODE_PTR
811 && TYPE_CODE (type) != TYPE_CODE_REF)
812 break;
5c5b5d4b 813 type = TYPE_TARGET_TYPE (type);
d1f4065e 814 }
5c5b5d4b 815
1ab3bf1b
JG
816 if (TYPE_CODE (type) != TYPE_CODE_STRUCT &&
817 TYPE_CODE (type) != TYPE_CODE_UNION)
818 {
819 target_terminal_ours ();
199b2450
TL
820 gdb_flush (gdb_stdout);
821 fprintf_unfiltered (gdb_stderr, "Type ");
822 type_print (type, "", gdb_stderr, -1);
1ab3bf1b
JG
823 error (" is not a structure or union type.");
824 }
825
45364c8a
FF
826#if 0
827 /* FIXME: This change put in by Michael seems incorrect for the case where
828 the structure tag name is the same as the member name. I.E. when doing
829 "ptype bell->bar" for "struct foo { int bar; int foo; } bell;"
830 Disabled by fnf. */
e7bf1152
RP
831 {
832 char *typename;
833
834 typename = type_name_no_tag (type);
835 if (typename != NULL && STREQ (typename, name))
836 return type;
837 }
45364c8a 838#endif
edf67bd1 839
1ab3bf1b
JG
840 for (i = TYPE_NFIELDS (type) - 1; i >= TYPE_N_BASECLASSES (type); i--)
841 {
842 char *t_field_name = TYPE_FIELD_NAME (type, i);
843
2e4964ad 844 if (t_field_name && STREQ (t_field_name, name))
1ab3bf1b
JG
845 {
846 return TYPE_FIELD_TYPE (type, i);
847 }
848 }
849
850 /* OK, it's not in this class. Recursively check the baseclasses. */
851 for (i = TYPE_N_BASECLASSES (type) - 1; i >= 0; i--)
852 {
853 struct type *t;
854
d112a0c6 855 t = lookup_struct_elt_type (TYPE_BASECLASS (type, i), name, noerr);
1ab3bf1b
JG
856 if (t != NULL)
857 {
858 return t;
859 }
860 }
861
862 if (noerr)
863 {
864 return NULL;
865 }
866
867 target_terminal_ours ();
199b2450
TL
868 gdb_flush (gdb_stdout);
869 fprintf_unfiltered (gdb_stderr, "Type ");
870 type_print (type, "", gdb_stderr, -1);
871 fprintf_unfiltered (gdb_stderr, " has no component named ");
872 fputs_filtered (name, gdb_stderr);
1ab3bf1b
JG
873 error (".");
874 return (struct type *)-1; /* For lint */
875}
876
ac88287f
JK
877/* If possible, make the vptr_fieldno and vptr_basetype fields of TYPE
878 valid. Callers should be aware that in some cases (for example,
879 the type or one of its baseclasses is a stub type and we are
880 debugging a .o file), this function will not be able to find the virtual
881 function table pointer, and vptr_fieldno will remain -1 and vptr_basetype
882 will remain NULL. */
1ab3bf1b
JG
883
884void
885fill_in_vptr_fieldno (type)
886 struct type *type;
887{
d1f4065e 888 CHECK_TYPEDEF (type);
ac88287f 889
1ab3bf1b
JG
890 if (TYPE_VPTR_FIELDNO (type) < 0)
891 {
892 int i;
edf67bd1
MT
893
894 /* We must start at zero in case the first (and only) baseclass is
895 virtual (and hence we cannot share the table pointer). */
896 for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
1ab3bf1b
JG
897 {
898 fill_in_vptr_fieldno (TYPE_BASECLASS (type, i));
899 if (TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type, i)) >= 0)
900 {
901 TYPE_VPTR_FIELDNO (type)
902 = TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type, i));
903 TYPE_VPTR_BASETYPE (type)
904 = TYPE_VPTR_BASETYPE (TYPE_BASECLASS (type, i));
905 break;
906 }
907 }
908 }
909}
910
a46d92a7
PS
911/* Find the method and field indices for the destructor in class type T.
912 Return 1 if the destructor was found, otherwise, return 0. */
913
914int
915get_destructor_fn_field (t, method_indexp, field_indexp)
916 struct type *t;
917 int *method_indexp;
918 int *field_indexp;
919{
920 int i;
921
922 for (i = 0; i < TYPE_NFN_FIELDS (t); i++)
923 {
924 int j;
925 struct fn_field *f = TYPE_FN_FIELDLIST1 (t, i);
926
927 for (j = 0; j < TYPE_FN_FIELDLIST_LENGTH (t, i); j++)
928 {
929 if (DESTRUCTOR_PREFIX_P (TYPE_FN_FIELD_PHYSNAME (f, j)))
930 {
931 *method_indexp = i;
932 *field_indexp = j;
933 return 1;
934 }
935 }
936 }
937 return 0;
938}
939
1ab3bf1b
JG
940/* Added by Bryan Boreham, Kewill, Sun Sep 17 18:07:17 1989.
941
942 If this is a stubbed struct (i.e. declared as struct foo *), see if
943 we can find a full definition in some other file. If so, copy this
dda398c3
JK
944 definition, so we can use it in future. There used to be a comment (but
945 not any code) that if we don't find a full definition, we'd set a flag
946 so we don't spend time in the future checking the same type. That would
947 be a mistake, though--we might load in more symbols which contain a
948 full definition for the type.
1ab3bf1b
JG
949
950 This used to be coded as a macro, but I don't think it is called
dda398c3 951 often enough to merit such treatment. */
1ab3bf1b
JG
952
953struct complaint stub_noname_complaint =
954 {"stub type has NULL name", 0, 0};
955
d1f4065e
PB
956struct type *
957check_typedef (type)
958 register struct type *type;
959{
960 struct type *orig_type = type;
961 while (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
962 {
963 if (!TYPE_TARGET_TYPE (type))
964 {
7ef89313
PB
965 char* name;
966 struct symbol *sym;
967
968 /* It is dangerous to call lookup_symbol if we are currently
969 reading a symtab. Infinite recursion is one danger. */
970 if (currently_reading_symtab)
971 return type;
972
973 name = type_name_no_tag (type);
d1f4065e
PB
974 /* FIXME: shouldn't we separately check the TYPE_NAME and the
975 TYPE_TAG_NAME, and look in STRUCT_NAMESPACE and/or VAR_NAMESPACE
976 as appropriate? (this code was written before TYPE_NAME and
977 TYPE_TAG_NAME were separate). */
d1f4065e
PB
978 if (name == NULL)
979 {
980 complain (&stub_noname_complaint);
981 return type;
982 }
983 sym = lookup_symbol (name, 0, STRUCT_NAMESPACE, 0,
984 (struct symtab **) NULL);
985 if (sym)
986 TYPE_TARGET_TYPE (type) = SYMBOL_TYPE (sym);
987 else
988 TYPE_TARGET_TYPE (type) = alloc_type (NULL); /* TYPE_CODE_UNDEF */
989 }
990 type = TYPE_TARGET_TYPE (type);
991 }
992
7ef89313 993 if ((TYPE_FLAGS(type) & TYPE_FLAG_STUB) && ! currently_reading_symtab)
1ab3bf1b
JG
994 {
995 char* name = type_name_no_tag (type);
065525e3
JK
996 /* FIXME: shouldn't we separately check the TYPE_NAME and the
997 TYPE_TAG_NAME, and look in STRUCT_NAMESPACE and/or VAR_NAMESPACE
998 as appropriate? (this code was written before TYPE_NAME and
999 TYPE_TAG_NAME were separate). */
1ab3bf1b
JG
1000 struct symbol *sym;
1001 if (name == NULL)
1002 {
51b80b00 1003 complain (&stub_noname_complaint);
d1f4065e 1004 return type;
1ab3bf1b
JG
1005 }
1006 sym = lookup_symbol (name, 0, STRUCT_NAMESPACE, 0,
1007 (struct symtab **) NULL);
1008 if (sym)
1009 {
dda398c3
JK
1010 memcpy ((char *)type,
1011 (char *)SYMBOL_TYPE(sym),
1012 sizeof (struct type));
1013 }
1014 }
1015
1016 if (TYPE_FLAGS (type) & TYPE_FLAG_TARGET_STUB)
1017 {
1018 struct type *range_type;
d1f4065e 1019 struct type *target_type = check_typedef (TYPE_TARGET_TYPE (type));
dda398c3 1020
dd600735 1021 if (TYPE_FLAGS (target_type) & (TYPE_FLAG_STUB | TYPE_FLAG_TARGET_STUB))
e55a5796
PB
1022 { }
1023 else if (TYPE_CODE (type) == TYPE_CODE_ARRAY
1024 && TYPE_NFIELDS (type) == 1
1025 && (TYPE_CODE (range_type = TYPE_FIELD_TYPE (type, 0))
1026 == TYPE_CODE_RANGE))
dda398c3
JK
1027 {
1028 /* Now recompute the length of the array type, based on its
1029 number of elements and the target type's length. */
1030 TYPE_LENGTH (type) =
1031 ((TYPE_FIELD_BITPOS (range_type, 1)
1032 - TYPE_FIELD_BITPOS (range_type, 0)
1033 + 1)
d1f4065e 1034 * TYPE_LENGTH (target_type));
dda398c3 1035 TYPE_FLAGS (type) &= ~TYPE_FLAG_TARGET_STUB;
1ab3bf1b 1036 }
e55a5796
PB
1037 else if (TYPE_CODE (type) == TYPE_CODE_RANGE)
1038 {
d1f4065e 1039 TYPE_LENGTH (type) = TYPE_LENGTH (target_type);
e55a5796
PB
1040 TYPE_FLAGS (type) &= ~TYPE_FLAG_TARGET_STUB;
1041 }
1ab3bf1b 1042 }
d1f4065e
PB
1043 /* Cache TYPE_LENGTH for future use. */
1044 TYPE_LENGTH (orig_type) = TYPE_LENGTH (type);
1045 return type;
1ab3bf1b
JG
1046}
1047
94f5a25f
DP
1048/* New code added to support parsing of Cfront stabs strings */
1049#include <ctype.h>
1050#define INIT_EXTRA { pextras->len=0; pextras->str[0]='\0'; }
1051#define ADD_EXTRA(c) { pextras->str[pextras->len++]=c; }
b607efe7
FF
1052
1053static void
94f5a25f
DP
1054add_name(pextras,n)
1055 struct extra * pextras;
1056 char * n;
1057{
b607efe7
FF
1058 int nlen;
1059
94f5a25f
DP
1060 if ((nlen = (n ? strlen(n) : 0))==0)
1061 return;
1062 sprintf(pextras->str+pextras->len,"%d%s",nlen,n);
1063 pextras->len=strlen(pextras->str);
1064}
1065
b607efe7 1066static void
94f5a25f
DP
1067add_mangled_type(pextras,t)
1068 struct extra * pextras;
1069 struct type * t;
1070{
1071 enum type_code tcode;
1072 int tlen, tflags;
1073 char * tname;
1074
1075 tcode = TYPE_CODE(t);
1076 tlen = TYPE_LENGTH(t);
1077 tflags = TYPE_FLAGS(t);
1078 tname = TYPE_NAME(t);
1079 /* args of "..." seem to get mangled as "e" */
1080
1081 switch (tcode)
1082 {
1083 case TYPE_CODE_INT:
1084 if (tflags==1)
1085 ADD_EXTRA('U');
1086 switch (tlen)
1087 {
1088 case 1:
1089 ADD_EXTRA('c');
1090 break;
1091 case 2:
1092 ADD_EXTRA('s');
1093 break;
1094 case 4:
1095 {
1096 char* pname;
1097 if ((pname=strrchr(tname,'l'),pname) && !strcmp(pname,"long"))
1098 ADD_EXTRA('l')
1099 else
1100 ADD_EXTRA('i')
1101 }
1102 break;
1103 default:
1104 {
1105
1106 static struct complaint msg = {"Bad int type code length x%x\n",0,0};
1107
1108 complain (&msg, tlen);
1109
1110 }
1111 }
1112 break;
1113 case TYPE_CODE_FLT:
1114 switch (tlen)
1115 {
1116 case 4:
1117 ADD_EXTRA('f');
1118 break;
1119 case 8:
1120 ADD_EXTRA('d');
1121 break;
1122 case 16:
1123 ADD_EXTRA('r');
1124 break;
1125 default:
1126 {
1127 static struct complaint msg = {"Bad float type code length x%x\n",0,0};
1128 complain (&msg, tlen);
1129 }
1130 }
1131 break;
1132 case TYPE_CODE_REF:
1133 ADD_EXTRA('R');
1134 /* followed by what it's a ref to */
1135 break;
1136 case TYPE_CODE_PTR:
1137 ADD_EXTRA('P');
1138 /* followed by what it's a ptr to */
1139 break;
1140 case TYPE_CODE_TYPEDEF:
1141 {
1142 static struct complaint msg = {"Typedefs in overloaded functions not yet supported\n",0,0};
1143 complain (&msg);
1144 }
1145 /* followed by type bytes & name */
1146 break;
1147 case TYPE_CODE_FUNC:
1148 ADD_EXTRA('F');
1149 /* followed by func's arg '_' & ret types */
1150 break;
1151 case TYPE_CODE_VOID:
1152 ADD_EXTRA('v');
1153 break;
1154 case TYPE_CODE_METHOD:
1155 ADD_EXTRA('M');
1156 /* followed by name of class and func's arg '_' & ret types */
1157 add_name(pextras,tname);
1158 ADD_EXTRA('F'); /* then mangle function */
1159 break;
1160 case TYPE_CODE_STRUCT: /* C struct */
1161 case TYPE_CODE_UNION: /* C union */
1162 case TYPE_CODE_ENUM: /* Enumeration type */
1163 /* followed by name of type */
1164 add_name(pextras,tname);
1165 break;
1166
1167 /* errors possible types/not supported */
1168 case TYPE_CODE_CHAR:
1169 case TYPE_CODE_ARRAY: /* Array type */
1170 case TYPE_CODE_MEMBER: /* Member type */
1171 case TYPE_CODE_BOOL:
1172 case TYPE_CODE_COMPLEX: /* Complex float */
1173 case TYPE_CODE_UNDEF:
1174 case TYPE_CODE_SET: /* Pascal sets */
1175 case TYPE_CODE_RANGE:
1176 case TYPE_CODE_STRING:
1177 case TYPE_CODE_BITSTRING:
1178 case TYPE_CODE_ERROR:
1179 default:
1180 {
1181 static struct complaint msg = {"Unknown type code x%x\n",0,0};
1182 complain (&msg, tcode);
1183 }
1184 }
1185 if (t->target_type)
1186 add_mangled_type(pextras,t->target_type);
1187}
1188
b607efe7
FF
1189#if 0
1190void
94f5a25f
DP
1191cfront_mangle_name(type, i, j)
1192 struct type *type;
1193 int i;
1194 int j;
1195{
1196 struct fn_field *f;
1197 char *mangled_name = gdb_mangle_name (type, i, j);
1198
1199 f = TYPE_FN_FIELDLIST1 (type, i); /* moved from below */
1200
1201 /* kludge to support cfront methods - gdb expects to find "F" for
1202 ARM_mangled names, so when we mangle, we have to add it here */
1203 if (ARM_DEMANGLING)
1204 {
1205 int k;
1206 char * arm_mangled_name;
1207 struct fn_field *method = &f[j];
1208 char *field_name = TYPE_FN_FIELDLIST_NAME (type, i);
1209 char *physname = TYPE_FN_FIELD_PHYSNAME (f, j);
1210 char *newname = type_name_no_tag (type);
1211
1212 struct type *ftype = TYPE_FN_FIELD_TYPE (f, j);
1213 int nargs = TYPE_NFIELDS(ftype); /* number of args */
1214 struct extra extras, * pextras = &extras;
1215 INIT_EXTRA
1216
1217 if (TYPE_FN_FIELD_STATIC_P (f, j)) /* j for sublist within this list */
1218 ADD_EXTRA('S')
1219 ADD_EXTRA('F')
1220 /* add args here! */
1221 if (nargs <= 1) /* no args besides this */
1222 ADD_EXTRA('v')
1223 else {
1224 for (k=1; k<nargs; k++)
1225 {
1226 struct type * t;
1227 t = TYPE_FIELD_TYPE(ftype,k);
1228 add_mangled_type(pextras,t);
1229 }
1230 }
1231 ADD_EXTRA('\0')
1232 printf("add_mangled_type: %s\n",extras.str); /* FIXME */
1233 arm_mangled_name = malloc(strlen(mangled_name)+extras.len);
1234 sprintf(arm_mangled_name,"%s%s",mangled_name,extras.str);
1235 free(mangled_name);
1236 mangled_name = arm_mangled_name;
1237 }
1238}
b607efe7
FF
1239#endif /* 0 */
1240
94f5a25f
DP
1241#undef ADD_EXTRA
1242/* End of new code added to support parsing of Cfront stabs strings */
1243
1ab3bf1b
JG
1244/* Ugly hack to convert method stubs into method types.
1245
1246 He ain't kiddin'. This demangles the name of the method into a string
1247 including argument types, parses out each argument type, generates
1248 a string casting a zero to that type, evaluates the string, and stuffs
1249 the resulting type into an argtype vector!!! Then it knows the type
1250 of the whole function (including argument types for overloading),
1251 which info used to be in the stab's but was removed to hack back
1252 the space required for them. */
1253
1254void
f6d23b6f 1255check_stub_method (type, method_id, signature_id)
1ab3bf1b 1256 struct type *type;
f6d23b6f
SG
1257 int method_id;
1258 int signature_id;
1ab3bf1b
JG
1259{
1260 struct fn_field *f;
f6d23b6f 1261 char *mangled_name = gdb_mangle_name (type, method_id, signature_id);
8050a57b
FF
1262 char *demangled_name = cplus_demangle (mangled_name,
1263 DMGL_PARAMS | DMGL_ANSI);
1ab3bf1b
JG
1264 char *argtypetext, *p;
1265 int depth = 0, argcount = 1;
1266 struct type **argtypes;
1267 struct type *mtype;
1268
e045712f
BK
1269 /* Make sure we got back a function string that we can use. */
1270 if (demangled_name)
1271 p = strchr (demangled_name, '(');
1272
1273 if (demangled_name == NULL || p == NULL)
1274 error ("Internal: Cannot demangle mangled name `%s'.", mangled_name);
1ab3bf1b
JG
1275
1276 /* Now, read in the parameters that define this type. */
e045712f
BK
1277 p += 1;
1278 argtypetext = p;
1ab3bf1b
JG
1279 while (*p)
1280 {
1281 if (*p == '(')
1282 {
1283 depth += 1;
1284 }
1285 else if (*p == ')')
1286 {
1287 depth -= 1;
1288 }
1289 else if (*p == ',' && depth == 0)
1290 {
1291 argcount += 1;
1292 }
1293
1294 p += 1;
1295 }
1296
1297 /* We need two more slots: one for the THIS pointer, and one for the
1298 NULL [...] or void [end of arglist]. */
1299
1300 argtypes = (struct type **)
dac9734e 1301 TYPE_ALLOC (type, (argcount + 2) * sizeof (struct type *));
1ab3bf1b 1302 p = argtypetext;
e552788b 1303 /* FIXME: This is wrong for static member functions. */
1ab3bf1b
JG
1304 argtypes[0] = lookup_pointer_type (type);
1305 argcount = 1;
1306
1307 if (*p != ')') /* () means no args, skip while */
1308 {
1309 depth = 0;
1310 while (*p)
1311 {
1312 if (depth <= 0 && (*p == ',' || *p == ')'))
1313 {
393e55ba
JK
1314 /* Avoid parsing of ellipsis, they will be handled below. */
1315 if (strncmp (argtypetext, "...", p - argtypetext) != 0)
1316 {
1317 argtypes[argcount] =
1318 parse_and_eval_type (argtypetext, p - argtypetext);
1319 argcount += 1;
1320 }
1ab3bf1b
JG
1321 argtypetext = p + 1;
1322 }
1323
1324 if (*p == '(')
1325 {
1326 depth += 1;
1327 }
1328 else if (*p == ')')
1329 {
1330 depth -= 1;
1331 }
1332
1333 p += 1;
1334 }
1335 }
1336
c0f1085b 1337 if (p[-2] != '.') /* Not '...' */
1ab3bf1b 1338 {
c0f1085b 1339 argtypes[argcount] = builtin_type_void; /* List terminator */
1ab3bf1b
JG
1340 }
1341 else
1342 {
c0f1085b 1343 argtypes[argcount] = NULL; /* Ellist terminator */
1ab3bf1b
JG
1344 }
1345
1346 free (demangled_name);
1347
f6d23b6f 1348 f = TYPE_FN_FIELDLIST1 (type, method_id);
94f5a25f 1349
f6d23b6f 1350 TYPE_FN_FIELD_PHYSNAME (f, signature_id) = mangled_name;
1ab3bf1b
JG
1351
1352 /* Now update the old "stub" type into a real type. */
f6d23b6f 1353 mtype = TYPE_FN_FIELD_TYPE (f, signature_id);
1ab3bf1b
JG
1354 TYPE_DOMAIN_TYPE (mtype) = type;
1355 TYPE_ARG_TYPES (mtype) = argtypes;
1356 TYPE_FLAGS (mtype) &= ~TYPE_FLAG_STUB;
f6d23b6f 1357 TYPE_FN_FIELD_STUB (f, signature_id) = 0;
1ab3bf1b
JG
1358}
1359
0213d96f 1360const struct cplus_struct_type cplus_struct_default;
1ab3bf1b
JG
1361
1362void
1363allocate_cplus_struct_type (type)
1364 struct type *type;
1365{
1366 if (!HAVE_CPLUS_STRUCT (type))
1367 {
1368 TYPE_CPLUS_SPECIFIC (type) = (struct cplus_struct_type *)
dac9734e 1369 TYPE_ALLOC (type, sizeof (struct cplus_struct_type));
1ab3bf1b
JG
1370 *(TYPE_CPLUS_SPECIFIC(type)) = cplus_struct_default;
1371 }
1372}
1373
50e0dc41
FF
1374/* Helper function to initialize the standard scalar types.
1375
1376 If NAME is non-NULL and OBJFILE is non-NULL, then we make a copy
1377 of the string pointed to by name in the type_obstack for that objfile,
1378 and initialize the type name to that copy. There are places (mipsread.c
1379 in particular, where init_type is called with a NULL value for NAME). */
1ab3bf1b
JG
1380
1381struct type *
1382init_type (code, length, flags, name, objfile)
1383 enum type_code code;
1384 int length;
1385 int flags;
1386 char *name;
1387 struct objfile *objfile;
1388{
1389 register struct type *type;
1390
1391 type = alloc_type (objfile);
1392 TYPE_CODE (type) = code;
1393 TYPE_LENGTH (type) = length;
1394 TYPE_FLAGS (type) |= flags;
50e0dc41
FF
1395 if ((name != NULL) && (objfile != NULL))
1396 {
1397 TYPE_NAME (type) =
1398 obsavestring (name, strlen (name), &objfile -> type_obstack);
1399 }
1400 else
1401 {
1402 TYPE_NAME (type) = name;
1403 }
1ab3bf1b
JG
1404
1405 /* C++ fancies. */
1406
1407 if (code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION)
1408 {
1409 INIT_CPLUS_SPECIFIC (type);
1410 }
1411 return (type);
1412}
1413
1414/* Look up a fundamental type for the specified objfile.
1415 May need to construct such a type if this is the first use.
1416
1417 Some object file formats (ELF, COFF, etc) do not define fundamental
1418 types such as "int" or "double". Others (stabs for example), do
1419 define fundamental types.
1420
1421 For the formats which don't provide fundamental types, gdb can create
bf229b4e
FF
1422 such types, using defaults reasonable for the current language and
1423 the current target machine.
1424
1425 NOTE: This routine is obsolescent. Each debugging format reader
1426 should manage it's own fundamental types, either creating them from
1427 suitable defaults or reading them from the debugging information,
1428 whichever is appropriate. The DWARF reader has already been
1429 fixed to do this. Once the other readers are fixed, this routine
1430 will go away. Also note that fundamental types should be managed
1431 on a compilation unit basis in a multi-language environment, not
1432 on a linkage unit basis as is done here. */
1433
1ab3bf1b
JG
1434
1435struct type *
1436lookup_fundamental_type (objfile, typeid)
1437 struct objfile *objfile;
1438 int typeid;
1439{
1ab3bf1b
JG
1440 register struct type **typep;
1441 register int nbytes;
1442
1443 if (typeid < 0 || typeid >= FT_NUM_MEMBERS)
1444 {
1445 error ("internal error - invalid fundamental type id %d", typeid);
1446 }
bf229b4e
FF
1447
1448 /* If this is the first time we need a fundamental type for this objfile
1449 then we need to initialize the vector of type pointers. */
1450
1451 if (objfile -> fundamental_types == NULL)
1ab3bf1b 1452 {
bf229b4e
FF
1453 nbytes = FT_NUM_MEMBERS * sizeof (struct type *);
1454 objfile -> fundamental_types = (struct type **)
1455 obstack_alloc (&objfile -> type_obstack, nbytes);
1456 memset ((char *) objfile -> fundamental_types, 0, nbytes);
2dd30c72 1457 OBJSTAT (objfile, n_types += FT_NUM_MEMBERS);
1ab3bf1b 1458 }
bf229b4e
FF
1459
1460 /* Look for this particular type in the fundamental type vector. If one is
1461 not found, create and install one appropriate for the current language. */
1462
1463 typep = objfile -> fundamental_types + typeid;
1464 if (*typep == NULL)
1465 {
1466 *typep = create_fundamental_type (objfile, typeid);
1467 }
1468
1469 return (*typep);
1ab3bf1b
JG
1470}
1471
9c036bd8
JK
1472int
1473can_dereference (t)
1474 struct type *t;
1475{
1476 /* FIXME: Should we return true for references as well as pointers? */
d1f4065e 1477 CHECK_TYPEDEF (t);
9c036bd8
JK
1478 return
1479 (t != NULL
1480 && TYPE_CODE (t) == TYPE_CODE_PTR
1481 && TYPE_CODE (TYPE_TARGET_TYPE (t)) != TYPE_CODE_VOID);
1482}
1483
f91a9e05
PB
1484/* Chill varying string and arrays are represented as follows:
1485
1486 struct { int __var_length; ELEMENT_TYPE[MAX_SIZE] __var_data};
1487
1488 Return true if TYPE is such a Chill varying type. */
1489
1490int
1491chill_varying_type (type)
1492 struct type *type;
1493{
1494 if (TYPE_CODE (type) != TYPE_CODE_STRUCT
1495 || TYPE_NFIELDS (type) != 2
1496 || strcmp (TYPE_FIELD_NAME (type, 0), "__var_length") != 0)
1497 return 0;
1498 return 1;
1499}
1500
0239d9b3
FF
1501#if MAINTENANCE_CMDS
1502
8050a57b
FF
1503static void
1504print_bit_vector (bits, nbits)
1505 B_TYPE *bits;
1506 int nbits;
0239d9b3 1507{
8050a57b
FF
1508 int bitno;
1509
1510 for (bitno = 0; bitno < nbits; bitno++)
0239d9b3 1511 {
8050a57b
FF
1512 if ((bitno % 8) == 0)
1513 {
1514 puts_filtered (" ");
1515 }
1516 if (B_TST (bits, bitno))
1517 {
1518 printf_filtered ("1");
1519 }
1520 else
1521 {
1522 printf_filtered ("0");
1523 }
0239d9b3 1524 }
8050a57b
FF
1525}
1526
c0f1085b
FF
1527/* The args list is a strange beast. It is either terminated by a NULL
1528 pointer for varargs functions, or by a pointer to a TYPE_CODE_VOID
1529 type for normal fixed argcount functions. (FIXME someday)
1530 Also note the first arg should be the "this" pointer, we may not want to
1531 include it since we may get into a infinitely recursive situation. */
1532
1533static void
1534print_arg_types (args, spaces)
1535 struct type **args;
1536 int spaces;
1537{
1538 if (args != NULL)
1539 {
1540 while (*args != NULL)
1541 {
1542 recursive_dump_type (*args, spaces + 2);
1543 if ((*args++) -> code == TYPE_CODE_VOID)
1544 {
1545 break;
1546 }
1547 }
1548 }
1549}
1550
1551static void
1552dump_fn_fieldlists (type, spaces)
1553 struct type *type;
1554 int spaces;
1555{
1556 int method_idx;
1557 int overload_idx;
1558 struct fn_field *f;
1559
833e0d94
JK
1560 printfi_filtered (spaces, "fn_fieldlists ");
1561 gdb_print_address (TYPE_FN_FIELDLISTS (type), gdb_stdout);
1562 printf_filtered ("\n");
c0f1085b
FF
1563 for (method_idx = 0; method_idx < TYPE_NFN_FIELDS (type); method_idx++)
1564 {
1565 f = TYPE_FN_FIELDLIST1 (type, method_idx);
833e0d94 1566 printfi_filtered (spaces + 2, "[%d] name '%s' (",
c0f1085b 1567 method_idx,
833e0d94
JK
1568 TYPE_FN_FIELDLIST_NAME (type, method_idx));
1569 gdb_print_address (TYPE_FN_FIELDLIST_NAME (type, method_idx),
1570 gdb_stdout);
1571 printf_filtered (") length %d\n",
1572 TYPE_FN_FIELDLIST_LENGTH (type, method_idx));
c0f1085b
FF
1573 for (overload_idx = 0;
1574 overload_idx < TYPE_FN_FIELDLIST_LENGTH (type, method_idx);
1575 overload_idx++)
1576 {
833e0d94 1577 printfi_filtered (spaces + 4, "[%d] physname '%s' (",
c0f1085b 1578 overload_idx,
833e0d94 1579 TYPE_FN_FIELD_PHYSNAME (f, overload_idx));
5e678752
JK
1580 gdb_print_address (TYPE_FN_FIELD_PHYSNAME (f, overload_idx),
1581 gdb_stdout);
833e0d94
JK
1582 printf_filtered (")\n");
1583 printfi_filtered (spaces + 8, "type ");
1584 gdb_print_address (TYPE_FN_FIELD_TYPE (f, overload_idx), gdb_stdout);
1585 printf_filtered ("\n");
1586
c0f1085b
FF
1587 recursive_dump_type (TYPE_FN_FIELD_TYPE (f, overload_idx),
1588 spaces + 8 + 2);
833e0d94
JK
1589
1590 printfi_filtered (spaces + 8, "args ");
1591 gdb_print_address (TYPE_FN_FIELD_ARGS (f, overload_idx), gdb_stdout);
1592 printf_filtered ("\n");
1593
c0f1085b 1594 print_arg_types (TYPE_FN_FIELD_ARGS (f, overload_idx), spaces);
833e0d94
JK
1595 printfi_filtered (spaces + 8, "fcontext ");
1596 gdb_print_address (TYPE_FN_FIELD_FCONTEXT (f, overload_idx),
1597 gdb_stdout);
1598 printf_filtered ("\n");
1599
c0f1085b
FF
1600 printfi_filtered (spaces + 8, "is_const %d\n",
1601 TYPE_FN_FIELD_CONST (f, overload_idx));
1602 printfi_filtered (spaces + 8, "is_volatile %d\n",
1603 TYPE_FN_FIELD_VOLATILE (f, overload_idx));
1604 printfi_filtered (spaces + 8, "is_private %d\n",
1605 TYPE_FN_FIELD_PRIVATE (f, overload_idx));
1606 printfi_filtered (spaces + 8, "is_protected %d\n",
1607 TYPE_FN_FIELD_PROTECTED (f, overload_idx));
1608 printfi_filtered (spaces + 8, "is_stub %d\n",
1609 TYPE_FN_FIELD_STUB (f, overload_idx));
d07734e3 1610 printfi_filtered (spaces + 8, "voffset %u\n",
c0f1085b
FF
1611 TYPE_FN_FIELD_VOFFSET (f, overload_idx));
1612 }
1613 }
1614}
1615
8050a57b
FF
1616static void
1617print_cplus_stuff (type, spaces)
1618 struct type *type;
1619 int spaces;
1620{
c0f1085b 1621 printfi_filtered (spaces, "n_baseclasses %d\n",
8050a57b 1622 TYPE_N_BASECLASSES (type));
c0f1085b
FF
1623 printfi_filtered (spaces, "nfn_fields %d\n",
1624 TYPE_NFN_FIELDS (type));
1625 printfi_filtered (spaces, "nfn_fields_total %d\n",
1626 TYPE_NFN_FIELDS_TOTAL (type));
8050a57b 1627 if (TYPE_N_BASECLASSES (type) > 0)
0239d9b3 1628 {
833e0d94
JK
1629 printfi_filtered (spaces, "virtual_field_bits (%d bits at *",
1630 TYPE_N_BASECLASSES (type));
1631 gdb_print_address (TYPE_FIELD_VIRTUAL_BITS (type), gdb_stdout);
1632 printf_filtered (")");
1633
8050a57b
FF
1634 print_bit_vector (TYPE_FIELD_VIRTUAL_BITS (type),
1635 TYPE_N_BASECLASSES (type));
1636 puts_filtered ("\n");
0239d9b3 1637 }
8050a57b 1638 if (TYPE_NFIELDS (type) > 0)
0239d9b3 1639 {
8050a57b
FF
1640 if (TYPE_FIELD_PRIVATE_BITS (type) != NULL)
1641 {
833e0d94
JK
1642 printfi_filtered (spaces, "private_field_bits (%d bits at *",
1643 TYPE_NFIELDS (type));
1644 gdb_print_address (TYPE_FIELD_PRIVATE_BITS (type), gdb_stdout);
1645 printf_filtered (")");
8050a57b
FF
1646 print_bit_vector (TYPE_FIELD_PRIVATE_BITS (type),
1647 TYPE_NFIELDS (type));
1648 puts_filtered ("\n");
1649 }
1650 if (TYPE_FIELD_PROTECTED_BITS (type) != NULL)
0239d9b3 1651 {
833e0d94
JK
1652 printfi_filtered (spaces, "protected_field_bits (%d bits at *",
1653 TYPE_NFIELDS (type));
1654 gdb_print_address (TYPE_FIELD_PROTECTED_BITS (type), gdb_stdout);
1655 printf_filtered (")");
8050a57b
FF
1656 print_bit_vector (TYPE_FIELD_PROTECTED_BITS (type),
1657 TYPE_NFIELDS (type));
1658 puts_filtered ("\n");
0239d9b3
FF
1659 }
1660 }
c0f1085b
FF
1661 if (TYPE_NFN_FIELDS (type) > 0)
1662 {
1663 dump_fn_fieldlists (type, spaces);
1664 }
8050a57b
FF
1665}
1666
2447e9af
PS
1667static struct obstack dont_print_type_obstack;
1668
8050a57b
FF
1669void
1670recursive_dump_type (type, spaces)
1671 struct type *type;
1672 int spaces;
1673{
1674 int idx;
0239d9b3 1675
2447e9af
PS
1676 if (spaces == 0)
1677 obstack_begin (&dont_print_type_obstack, 0);
1678
1679 if (TYPE_NFIELDS (type) > 0
1680 || (TYPE_CPLUS_SPECIFIC (type) && TYPE_NFN_FIELDS (type) > 0))
1681 {
1682 struct type **first_dont_print
1683 = (struct type **)obstack_base (&dont_print_type_obstack);
1684
1685 int i = (struct type **)obstack_next_free (&dont_print_type_obstack)
1686 - first_dont_print;
1687
1688 while (--i >= 0)
1689 {
1690 if (type == first_dont_print[i])
1691 {
1692 printfi_filtered (spaces, "type node ");
1693 gdb_print_address (type, gdb_stdout);
1694 printf_filtered (" <same as already seen type>\n");
1695 return;
1696 }
1697 }
1698
1699 obstack_ptr_grow (&dont_print_type_obstack, type);
1700 }
1701
833e0d94
JK
1702 printfi_filtered (spaces, "type node ");
1703 gdb_print_address (type, gdb_stdout);
1704 printf_filtered ("\n");
1705 printfi_filtered (spaces, "name '%s' (",
1706 TYPE_NAME (type) ? TYPE_NAME (type) : "<NULL>");
1707 gdb_print_address (TYPE_NAME (type), gdb_stdout);
1708 printf_filtered (")\n");
85999c05 1709 if (TYPE_TAG_NAME (type) != NULL)
833e0d94
JK
1710 {
1711 printfi_filtered (spaces, "tagname '%s' (",
1712 TYPE_TAG_NAME (type));
1713 gdb_print_address (TYPE_TAG_NAME (type), gdb_stdout);
1714 printf_filtered (")\n");
1715 }
c0f1085b 1716 printfi_filtered (spaces, "code 0x%x ", TYPE_CODE (type));
8050a57b 1717 switch (TYPE_CODE (type))
0239d9b3 1718 {
8050a57b 1719 case TYPE_CODE_UNDEF:
c0f1085b 1720 printf_filtered ("(TYPE_CODE_UNDEF)");
8050a57b
FF
1721 break;
1722 case TYPE_CODE_PTR:
c0f1085b 1723 printf_filtered ("(TYPE_CODE_PTR)");
8050a57b
FF
1724 break;
1725 case TYPE_CODE_ARRAY:
c0f1085b 1726 printf_filtered ("(TYPE_CODE_ARRAY)");
8050a57b
FF
1727 break;
1728 case TYPE_CODE_STRUCT:
c0f1085b 1729 printf_filtered ("(TYPE_CODE_STRUCT)");
8050a57b
FF
1730 break;
1731 case TYPE_CODE_UNION:
c0f1085b 1732 printf_filtered ("(TYPE_CODE_UNION)");
8050a57b
FF
1733 break;
1734 case TYPE_CODE_ENUM:
c0f1085b 1735 printf_filtered ("(TYPE_CODE_ENUM)");
8050a57b
FF
1736 break;
1737 case TYPE_CODE_FUNC:
c0f1085b 1738 printf_filtered ("(TYPE_CODE_FUNC)");
8050a57b
FF
1739 break;
1740 case TYPE_CODE_INT:
c0f1085b 1741 printf_filtered ("(TYPE_CODE_INT)");
8050a57b
FF
1742 break;
1743 case TYPE_CODE_FLT:
c0f1085b 1744 printf_filtered ("(TYPE_CODE_FLT)");
8050a57b
FF
1745 break;
1746 case TYPE_CODE_VOID:
c0f1085b 1747 printf_filtered ("(TYPE_CODE_VOID)");
8050a57b
FF
1748 break;
1749 case TYPE_CODE_SET:
c0f1085b 1750 printf_filtered ("(TYPE_CODE_SET)");
8050a57b
FF
1751 break;
1752 case TYPE_CODE_RANGE:
c0f1085b 1753 printf_filtered ("(TYPE_CODE_RANGE)");
8050a57b 1754 break;
c4413e2c
FF
1755 case TYPE_CODE_STRING:
1756 printf_filtered ("(TYPE_CODE_STRING)");
8050a57b
FF
1757 break;
1758 case TYPE_CODE_ERROR:
c0f1085b 1759 printf_filtered ("(TYPE_CODE_ERROR)");
8050a57b
FF
1760 break;
1761 case TYPE_CODE_MEMBER:
c0f1085b 1762 printf_filtered ("(TYPE_CODE_MEMBER)");
8050a57b
FF
1763 break;
1764 case TYPE_CODE_METHOD:
c0f1085b 1765 printf_filtered ("(TYPE_CODE_METHOD)");
8050a57b
FF
1766 break;
1767 case TYPE_CODE_REF:
c0f1085b 1768 printf_filtered ("(TYPE_CODE_REF)");
8050a57b
FF
1769 break;
1770 case TYPE_CODE_CHAR:
c0f1085b 1771 printf_filtered ("(TYPE_CODE_CHAR)");
8050a57b
FF
1772 break;
1773 case TYPE_CODE_BOOL:
c0f1085b 1774 printf_filtered ("(TYPE_CODE_BOOL)");
8050a57b 1775 break;
d1f4065e
PB
1776 case TYPE_CODE_TYPEDEF:
1777 printf_filtered ("(TYPE_CODE_TYPEDEF)");
1778 break;
8050a57b 1779 default:
c0f1085b 1780 printf_filtered ("(UNKNOWN TYPE CODE)");
8050a57b 1781 break;
0239d9b3 1782 }
8050a57b 1783 puts_filtered ("\n");
c0f1085b 1784 printfi_filtered (spaces, "length %d\n", TYPE_LENGTH (type));
833e0d94
JK
1785 printfi_filtered (spaces, "objfile ");
1786 gdb_print_address (TYPE_OBJFILE (type), gdb_stdout);
1787 printf_filtered ("\n");
1788 printfi_filtered (spaces, "target_type ");
1789 gdb_print_address (TYPE_TARGET_TYPE (type), gdb_stdout);
1790 printf_filtered ("\n");
8050a57b
FF
1791 if (TYPE_TARGET_TYPE (type) != NULL)
1792 {
1793 recursive_dump_type (TYPE_TARGET_TYPE (type), spaces + 2);
1794 }
833e0d94
JK
1795 printfi_filtered (spaces, "pointer_type ");
1796 gdb_print_address (TYPE_POINTER_TYPE (type), gdb_stdout);
1797 printf_filtered ("\n");
1798 printfi_filtered (spaces, "reference_type ");
1799 gdb_print_address (TYPE_REFERENCE_TYPE (type), gdb_stdout);
1800 printf_filtered ("\n");
c0f1085b 1801 printfi_filtered (spaces, "flags 0x%x", TYPE_FLAGS (type));
8050a57b
FF
1802 if (TYPE_FLAGS (type) & TYPE_FLAG_UNSIGNED)
1803 {
1804 puts_filtered (" TYPE_FLAG_UNSIGNED");
1805 }
8050a57b
FF
1806 if (TYPE_FLAGS (type) & TYPE_FLAG_STUB)
1807 {
1808 puts_filtered (" TYPE_FLAG_STUB");
1809 }
1810 puts_filtered ("\n");
833e0d94 1811 printfi_filtered (spaces, "nfields %d ", TYPE_NFIELDS (type));
5e678752 1812 gdb_print_address (TYPE_FIELDS (type), gdb_stdout);
833e0d94 1813 puts_filtered ("\n");
8050a57b
FF
1814 for (idx = 0; idx < TYPE_NFIELDS (type); idx++)
1815 {
1816 printfi_filtered (spaces + 2,
5e678752 1817 "[%d] bitpos %d bitsize %d type ",
8050a57b 1818 idx, TYPE_FIELD_BITPOS (type, idx),
833e0d94
JK
1819 TYPE_FIELD_BITSIZE (type, idx));
1820 gdb_print_address (TYPE_FIELD_TYPE (type, idx), gdb_stdout);
1821 printf_filtered (" name '%s' (",
1822 TYPE_FIELD_NAME (type, idx) != NULL
1823 ? TYPE_FIELD_NAME (type, idx)
1824 : "<NULL>");
5e678752 1825 gdb_print_address (TYPE_FIELD_NAME (type, idx), gdb_stdout);
833e0d94 1826 printf_filtered (")\n");
8050a57b
FF
1827 if (TYPE_FIELD_TYPE (type, idx) != NULL)
1828 {
1829 recursive_dump_type (TYPE_FIELD_TYPE (type, idx), spaces + 4);
1830 }
1831 }
833e0d94
JK
1832 printfi_filtered (spaces, "vptr_basetype ");
1833 gdb_print_address (TYPE_VPTR_BASETYPE (type), gdb_stdout);
1834 puts_filtered ("\n");
8050a57b
FF
1835 if (TYPE_VPTR_BASETYPE (type) != NULL)
1836 {
1837 recursive_dump_type (TYPE_VPTR_BASETYPE (type), spaces + 2);
1838 }
c0f1085b 1839 printfi_filtered (spaces, "vptr_fieldno %d\n", TYPE_VPTR_FIELDNO (type));
8050a57b 1840 switch (TYPE_CODE (type))
0239d9b3
FF
1841 {
1842 case TYPE_CODE_METHOD:
1843 case TYPE_CODE_FUNC:
833e0d94 1844 printfi_filtered (spaces, "arg_types ");
5e678752 1845 gdb_print_address (TYPE_ARG_TYPES (type), gdb_stdout);
833e0d94 1846 puts_filtered ("\n");
c0f1085b 1847 print_arg_types (TYPE_ARG_TYPES (type), spaces);
0239d9b3
FF
1848 break;
1849
1850 case TYPE_CODE_STRUCT:
833e0d94 1851 printfi_filtered (spaces, "cplus_stuff ");
5e678752 1852 gdb_print_address (TYPE_CPLUS_SPECIFIC (type), gdb_stdout);
833e0d94 1853 puts_filtered ("\n");
8050a57b 1854 print_cplus_stuff (type, spaces);
0239d9b3 1855 break;
d07734e3
FF
1856
1857 default:
1858 /* We have to pick one of the union types to be able print and test
1859 the value. Pick cplus_struct_type, even though we know it isn't
1860 any particular one. */
833e0d94 1861 printfi_filtered (spaces, "type_specific ");
5e678752 1862 gdb_print_address (TYPE_CPLUS_SPECIFIC (type), gdb_stdout);
d07734e3
FF
1863 if (TYPE_CPLUS_SPECIFIC (type) != NULL)
1864 {
1865 printf_filtered (" (unknown data form)");
1866 }
1867 printf_filtered ("\n");
1868 break;
1869
0239d9b3 1870 }
2447e9af
PS
1871 if (spaces == 0)
1872 obstack_free (&dont_print_type_obstack, NULL);
0239d9b3
FF
1873}
1874
1875#endif /* MAINTENANCE_CMDS */
c4413e2c 1876
e81bad50
AC
1877
1878static void build_gdbtypes PARAMS ((void));
1879static void
1880build_gdbtypes ()
c4413e2c
FF
1881{
1882 builtin_type_void =
1883 init_type (TYPE_CODE_VOID, 1,
1884 0,
1885 "void", (struct objfile *) NULL);
1886 builtin_type_char =
1887 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
1888 0,
1889 "char", (struct objfile *) NULL);
1890 builtin_type_signed_char =
1891 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
dda398c3 1892 0,
c4413e2c
FF
1893 "signed char", (struct objfile *) NULL);
1894 builtin_type_unsigned_char =
1895 init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
1896 TYPE_FLAG_UNSIGNED,
1897 "unsigned char", (struct objfile *) NULL);
1898 builtin_type_short =
1899 init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT,
1900 0,
1901 "short", (struct objfile *) NULL);
1902 builtin_type_unsigned_short =
1903 init_type (TYPE_CODE_INT, TARGET_SHORT_BIT / TARGET_CHAR_BIT,
1904 TYPE_FLAG_UNSIGNED,
1905 "unsigned short", (struct objfile *) NULL);
1906 builtin_type_int =
1907 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
1908 0,
1909 "int", (struct objfile *) NULL);
1910 builtin_type_unsigned_int =
1911 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
1912 TYPE_FLAG_UNSIGNED,
1913 "unsigned int", (struct objfile *) NULL);
1914 builtin_type_long =
1915 init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT,
1916 0,
1917 "long", (struct objfile *) NULL);
1918 builtin_type_unsigned_long =
1919 init_type (TYPE_CODE_INT, TARGET_LONG_BIT / TARGET_CHAR_BIT,
1920 TYPE_FLAG_UNSIGNED,
1921 "unsigned long", (struct objfile *) NULL);
1922 builtin_type_long_long =
1923 init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
1924 0,
1925 "long long", (struct objfile *) NULL);
1926 builtin_type_unsigned_long_long =
1927 init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
1928 TYPE_FLAG_UNSIGNED,
1929 "unsigned long long", (struct objfile *) NULL);
1930 builtin_type_float =
1931 init_type (TYPE_CODE_FLT, TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
1932 0,
1933 "float", (struct objfile *) NULL);
1934 builtin_type_double =
1935 init_type (TYPE_CODE_FLT, TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
1936 0,
1937 "double", (struct objfile *) NULL);
1938 builtin_type_long_double =
1939 init_type (TYPE_CODE_FLT, TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT,
1940 0,
1941 "long double", (struct objfile *) NULL);
1942 builtin_type_complex =
ead95f8a 1943 init_type (TYPE_CODE_COMPLEX, 2 * TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
c4413e2c
FF
1944 0,
1945 "complex", (struct objfile *) NULL);
ead95f8a 1946 TYPE_TARGET_TYPE (builtin_type_complex) = builtin_type_float;
c4413e2c 1947 builtin_type_double_complex =
ead95f8a 1948 init_type (TYPE_CODE_COMPLEX, 2 * TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
c4413e2c
FF
1949 0,
1950 "double complex", (struct objfile *) NULL);
ead95f8a 1951 TYPE_TARGET_TYPE (builtin_type_double_complex) = builtin_type_double;
c4413e2c
FF
1952 builtin_type_string =
1953 init_type (TYPE_CODE_STRING, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
1954 0,
1955 "string", (struct objfile *) NULL);
980714f9
AC
1956 builtin_type_int8 =
1957 init_type (TYPE_CODE_INT, 8 / 8,
1958 0,
1959 "int8_t", (struct objfile *) NULL);
1960 builtin_type_uint8 =
1961 init_type (TYPE_CODE_INT, 8 / 8,
1962 TYPE_FLAG_UNSIGNED,
1963 "uint8_t", (struct objfile *) NULL);
1964 builtin_type_int16 =
1965 init_type (TYPE_CODE_INT, 16 / 8,
1966 0,
1967 "int16_t", (struct objfile *) NULL);
1968 builtin_type_uint16 =
1969 init_type (TYPE_CODE_INT, 16 / 8,
1970 TYPE_FLAG_UNSIGNED,
1971 "uint16_t", (struct objfile *) NULL);
1972 builtin_type_int32 =
1973 init_type (TYPE_CODE_INT, 32 / 8,
1974 0,
1975 "int32_t", (struct objfile *) NULL);
1976 builtin_type_uint32 =
1977 init_type (TYPE_CODE_INT, 32 / 8,
1978 TYPE_FLAG_UNSIGNED,
1979 "uint32_t", (struct objfile *) NULL);
1980 builtin_type_int64 =
1981 init_type (TYPE_CODE_INT, 64 / 8,
1982 0,
1983 "int64_t", (struct objfile *) NULL);
1984 builtin_type_uint64 =
1985 init_type (TYPE_CODE_INT, 64 / 8,
1986 TYPE_FLAG_UNSIGNED,
1987 "uint64_t", (struct objfile *) NULL);
1988 /* start-sanitize-r5900 */
1989 builtin_type_int128 =
1990 init_type (TYPE_CODE_INT, 128 / 8,
1991 0,
1992 "int128_t", (struct objfile *) NULL);
1993 builtin_type_uint128 =
1994 init_type (TYPE_CODE_INT, 128 / 8,
1995 TYPE_FLAG_UNSIGNED,
1996 "uint128_t", (struct objfile *) NULL);
1997 /* end-sanitize-r5900 */
c4413e2c 1998}
e81bad50
AC
1999
2000
2001extern void _initialize_gdbtypes PARAMS ((void));
2002void
2003_initialize_gdbtypes ()
2004{
2005 build_gdbtypes ();
115c338d
AC
2006 /* start-sanitize-carp start-sanitize-vr4xxx */
2007 /* FIXME - For the moment, handle types by swapping them in and out.
2008 Should be using the per-architecture data-pointer and a large
2009 struct. */
2010 register_gdbarch_swap (&builtin_type_void, sizeof (struct type*), NULL);
2011 register_gdbarch_swap (&builtin_type_char, sizeof (struct type*), NULL);
2012 register_gdbarch_swap (&builtin_type_short, sizeof (struct type*), NULL);
2013 register_gdbarch_swap (&builtin_type_int, sizeof (struct type*), NULL);
2014 register_gdbarch_swap (&builtin_type_long, sizeof (struct type*), NULL);
2015 register_gdbarch_swap (&builtin_type_long_long, sizeof (struct type*), NULL);
2016 register_gdbarch_swap (&builtin_type_signed_char, sizeof (struct type*), NULL);
2017 register_gdbarch_swap (&builtin_type_unsigned_char, sizeof (struct type*), NULL);
2018 register_gdbarch_swap (&builtin_type_unsigned_short, sizeof (struct type*), NULL);
2019 register_gdbarch_swap (&builtin_type_unsigned_int, sizeof (struct type*), NULL);
2020 register_gdbarch_swap (&builtin_type_unsigned_long, sizeof (struct type*), NULL);
2021 register_gdbarch_swap (&builtin_type_unsigned_long_long, sizeof (struct type*), NULL);
2022 register_gdbarch_swap (&builtin_type_float, sizeof (struct type*), NULL);
2023 register_gdbarch_swap (&builtin_type_double, sizeof (struct type*), NULL);
2024 register_gdbarch_swap (&builtin_type_long_double, sizeof (struct type*), NULL);
2025 register_gdbarch_swap (&builtin_type_complex, sizeof (struct type*), NULL);
2026 register_gdbarch_swap (&builtin_type_double_complex, sizeof (struct type*), NULL);
2027 register_gdbarch_swap (&builtin_type_string, sizeof (struct type*), NULL);
2028 register_gdbarch_swap (&builtin_type_int8, sizeof (struct type*), NULL);
2029 register_gdbarch_swap (&builtin_type_uint8, sizeof (struct type*), NULL);
2030 register_gdbarch_swap (&builtin_type_int16, sizeof (struct type*), NULL);
2031 register_gdbarch_swap (&builtin_type_uint16, sizeof (struct type*), NULL);
2032 register_gdbarch_swap (&builtin_type_int32, sizeof (struct type*), NULL);
2033 register_gdbarch_swap (&builtin_type_uint32, sizeof (struct type*), NULL);
2034 register_gdbarch_swap (&builtin_type_int64, sizeof (struct type*), NULL);
2035 register_gdbarch_swap (&builtin_type_uint64, sizeof (struct type*), NULL);
2036 /* start-sanitize-r5900 */
2037 register_gdbarch_swap (&builtin_type_int128, sizeof (struct type*), NULL);
2038 register_gdbarch_swap (&builtin_type_uint128, sizeof (struct type*), NULL);
2039 /* end-sanitize-r5900 */
2040 register_gdbarch_swap (NULL, 0, build_gdbtypes);
2041 /* end-sanitize-carp end-sanitize-vr4xxx */
e81bad50 2042}
This page took 0.389488 seconds and 4 git commands to generate.