* stabsread.c (REG_STRUCT_HAS_ADDR): Accept additional argument
[deliverable/binutils-gdb.git] / gdb / stabsread.c
1 /* Support routines for decoding "stabs" debugging information format.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994
3 Free Software Foundation, Inc.
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., 675 Mass Ave, Cambridge, MA 02139, USA. */
20
21 /* Support routines for reading and decoding debugging information in
22 the "stabs" format. This format is used with many systems that use
23 the a.out object file format, as well as some systems that use
24 COFF or ELF where the stabs data is placed in a special section.
25 Avoid placing any object file format specific code in this file. */
26
27 #include "defs.h"
28 #include <string.h>
29 #include "bfd.h"
30 #include "obstack.h"
31 #include "symtab.h"
32 #include "gdbtypes.h"
33 #include "symfile.h"
34 #include "objfiles.h"
35 #include "aout/stab_gnu.h" /* We always use GNU stabs, not native */
36 #include "buildsym.h"
37 #include "complaints.h"
38 #include "demangle.h"
39
40 #include <ctype.h>
41
42 /* Ask stabsread.h to define the vars it normally declares `extern'. */
43 #define EXTERN /**/
44 #include "stabsread.h" /* Our own declarations */
45 #undef EXTERN
46
47 /* The routines that read and process a complete stabs for a C struct or
48 C++ class pass lists of data member fields and lists of member function
49 fields in an instance of a field_info structure, as defined below.
50 This is part of some reorganization of low level C++ support and is
51 expected to eventually go away... (FIXME) */
52
53 struct field_info
54 {
55 struct nextfield
56 {
57 struct nextfield *next;
58
59 /* This is the raw visibility from the stab. It is not checked
60 for being one of the visibilities we recognize, so code which
61 examines this field better be able to deal. */
62 int visibility;
63
64 struct field field;
65 } *list;
66 struct next_fnfieldlist
67 {
68 struct next_fnfieldlist *next;
69 struct fn_fieldlist fn_fieldlist;
70 } *fnlist;
71 };
72
73 static struct type *
74 dbx_alloc_type PARAMS ((int [2], struct objfile *));
75
76 static long read_huge_number PARAMS ((char **, int, int *));
77
78 static struct type *error_type PARAMS ((char **));
79
80 static void
81 patch_block_stabs PARAMS ((struct pending *, struct pending_stabs *,
82 struct objfile *));
83
84 static void
85 fix_common_block PARAMS ((struct symbol *, int));
86
87 static int
88 read_type_number PARAMS ((char **, int *));
89
90 static struct type *
91 read_range_type PARAMS ((char **, int [2], struct objfile *));
92
93 static struct type *
94 read_sun_builtin_type PARAMS ((char **, int [2], struct objfile *));
95
96 static struct type *
97 read_sun_floating_type PARAMS ((char **, int [2], struct objfile *));
98
99 static struct type *
100 read_enum_type PARAMS ((char **, struct type *, struct objfile *));
101
102 static struct type *
103 rs6000_builtin_type PARAMS ((int));
104
105 static int
106 read_member_functions PARAMS ((struct field_info *, char **, struct type *,
107 struct objfile *));
108
109 static int
110 read_struct_fields PARAMS ((struct field_info *, char **, struct type *,
111 struct objfile *));
112
113 static int
114 read_baseclasses PARAMS ((struct field_info *, char **, struct type *,
115 struct objfile *));
116
117 static int
118 read_tilde_fields PARAMS ((struct field_info *, char **, struct type *,
119 struct objfile *));
120
121 static int
122 attach_fn_fields_to_type PARAMS ((struct field_info *, struct type *));
123
124 static int
125 attach_fields_to_type PARAMS ((struct field_info *, struct type *,
126 struct objfile *));
127
128 static struct type *
129 read_struct_type PARAMS ((char **, struct type *, struct objfile *));
130
131 static struct type *
132 read_array_type PARAMS ((char **, struct type *, struct objfile *));
133
134 static struct type **
135 read_args PARAMS ((char **, int, struct objfile *));
136
137 static int
138 read_cpp_abbrev PARAMS ((struct field_info *, char **, struct type *,
139 struct objfile *));
140
141 static const char vptr_name[] = { '_','v','p','t','r',CPLUS_MARKER,'\0' };
142 static const char vb_name[] = { '_','v','b',CPLUS_MARKER,'\0' };
143
144 /* Define this as 1 if a pcc declaration of a char or short argument
145 gives the correct address. Otherwise assume pcc gives the
146 address of the corresponding int, which is not the same on a
147 big-endian machine. */
148
149 #ifndef BELIEVE_PCC_PROMOTION
150 #define BELIEVE_PCC_PROMOTION 0
151 #endif
152
153 struct complaint invalid_cpp_abbrev_complaint =
154 {"invalid C++ abbreviation `%s'", 0, 0};
155
156 struct complaint invalid_cpp_type_complaint =
157 {"C++ abbreviated type name unknown at symtab pos %d", 0, 0};
158
159 struct complaint member_fn_complaint =
160 {"member function type missing, got '%c'", 0, 0};
161
162 struct complaint const_vol_complaint =
163 {"const/volatile indicator missing, got '%c'", 0, 0};
164
165 struct complaint error_type_complaint =
166 {"debug info mismatch between compiler and debugger", 0, 0};
167
168 struct complaint invalid_member_complaint =
169 {"invalid (minimal) member type data format at symtab pos %d.", 0, 0};
170
171 struct complaint range_type_base_complaint =
172 {"base type %d of range type is not defined", 0, 0};
173
174 struct complaint reg_value_complaint =
175 {"register number too large in symbol %s", 0, 0};
176
177 struct complaint vtbl_notfound_complaint =
178 {"virtual function table pointer not found when defining class `%s'", 0, 0};
179
180 struct complaint unrecognized_cplus_name_complaint =
181 {"Unknown C++ symbol name `%s'", 0, 0};
182
183 struct complaint rs6000_builtin_complaint =
184 {"Unknown builtin type %d", 0, 0};
185
186 struct complaint stabs_general_complaint =
187 {"%s", 0, 0};
188
189 /* Make a list of forward references which haven't been defined. */
190
191 static struct type **undef_types;
192 static int undef_types_allocated;
193 static int undef_types_length;
194
195 /* Check for and handle cretinous stabs symbol name continuation! */
196 #define STABS_CONTINUE(pp) \
197 do { \
198 if (**(pp) == '\\' || (**(pp) == '?' && (*(pp))[1] == '\0')) \
199 *(pp) = next_symbol_text (); \
200 } while (0)
201 \f
202 /* FIXME: These probably should be our own types (like rs6000_builtin_type
203 has its own types) rather than builtin_type_*. */
204 static struct type **os9k_type_vector[] = {
205 0,
206 &builtin_type_int,
207 &builtin_type_char,
208 &builtin_type_long,
209 &builtin_type_short,
210 &builtin_type_unsigned_char,
211 &builtin_type_unsigned_short,
212 &builtin_type_unsigned_long,
213 &builtin_type_unsigned_int,
214 &builtin_type_float,
215 &builtin_type_double,
216 &builtin_type_void,
217 &builtin_type_long_double
218 };
219
220 static void os9k_init_type_vector PARAMS ((struct type **));
221
222 static void
223 os9k_init_type_vector(tv)
224 struct type **tv;
225 {
226 int i;
227 for (i=0; i<sizeof(os9k_type_vector)/sizeof(struct type **); i++)
228 tv[i] = (os9k_type_vector[i] == 0 ? 0 : *(os9k_type_vector[i]));
229 }
230
231 /* Look up a dbx type-number pair. Return the address of the slot
232 where the type for that number-pair is stored.
233 The number-pair is in TYPENUMS.
234
235 This can be used for finding the type associated with that pair
236 or for associating a new type with the pair. */
237
238 struct type **
239 dbx_lookup_type (typenums)
240 int typenums[2];
241 {
242 register int filenum = typenums[0];
243 register int index = typenums[1];
244 unsigned old_len;
245 register int real_filenum;
246 register struct header_file *f;
247 int f_orig_length;
248
249 if (filenum == -1) /* -1,-1 is for temporary types. */
250 return 0;
251
252 if (filenum < 0 || filenum >= n_this_object_header_files)
253 {
254 static struct complaint msg = {"\
255 Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.",
256 0, 0};
257 complain (&msg, filenum, index, symnum);
258 goto error_return;
259 }
260
261 if (filenum == 0)
262 {
263 if (index < 0)
264 {
265 /* Caller wants address of address of type. We think
266 that negative (rs6k builtin) types will never appear as
267 "lvalues", (nor should they), so we stuff the real type
268 pointer into a temp, and return its address. If referenced,
269 this will do the right thing. */
270 static struct type *temp_type;
271
272 temp_type = rs6000_builtin_type(index);
273 return &temp_type;
274 }
275
276 /* Type is defined outside of header files.
277 Find it in this object file's type vector. */
278 if (index >= type_vector_length)
279 {
280 old_len = type_vector_length;
281 if (old_len == 0)
282 {
283 type_vector_length = INITIAL_TYPE_VECTOR_LENGTH;
284 type_vector = (struct type **)
285 malloc (type_vector_length * sizeof (struct type *));
286 }
287 while (index >= type_vector_length)
288 {
289 type_vector_length *= 2;
290 }
291 type_vector = (struct type **)
292 xrealloc ((char *) type_vector,
293 (type_vector_length * sizeof (struct type *)));
294 memset (&type_vector[old_len], 0,
295 (type_vector_length - old_len) * sizeof (struct type *));
296
297 if (os9k_stabs)
298 /* Deal with OS9000 fundamental types. */
299 os9k_init_type_vector (type_vector);
300 }
301 return (&type_vector[index]);
302 }
303 else
304 {
305 real_filenum = this_object_header_files[filenum];
306
307 if (real_filenum >= n_header_files)
308 {
309 struct type *temp_type;
310 struct type **temp_type_p;
311
312 warning ("GDB internal error: bad real_filenum");
313
314 error_return:
315 temp_type = init_type (TYPE_CODE_ERROR, 0, 0, NULL, NULL);
316 temp_type_p = (struct type **) xmalloc (sizeof (struct type *));
317 *temp_type_p = temp_type;
318 return temp_type_p;
319 }
320
321 f = &header_files[real_filenum];
322
323 f_orig_length = f->length;
324 if (index >= f_orig_length)
325 {
326 while (index >= f->length)
327 {
328 f->length *= 2;
329 }
330 f->vector = (struct type **)
331 xrealloc ((char *) f->vector, f->length * sizeof (struct type *));
332 memset (&f->vector[f_orig_length], 0,
333 (f->length - f_orig_length) * sizeof (struct type *));
334 }
335 return (&f->vector[index]);
336 }
337 }
338
339 /* Make sure there is a type allocated for type numbers TYPENUMS
340 and return the type object.
341 This can create an empty (zeroed) type object.
342 TYPENUMS may be (-1, -1) to return a new type object that is not
343 put into the type vector, and so may not be referred to by number. */
344
345 static struct type *
346 dbx_alloc_type (typenums, objfile)
347 int typenums[2];
348 struct objfile *objfile;
349 {
350 register struct type **type_addr;
351
352 if (typenums[0] == -1)
353 {
354 return (alloc_type (objfile));
355 }
356
357 type_addr = dbx_lookup_type (typenums);
358
359 /* If we are referring to a type not known at all yet,
360 allocate an empty type for it.
361 We will fill it in later if we find out how. */
362 if (*type_addr == 0)
363 {
364 *type_addr = alloc_type (objfile);
365 }
366
367 return (*type_addr);
368 }
369
370 /* for all the stabs in a given stab vector, build appropriate types
371 and fix their symbols in given symbol vector. */
372
373 static void
374 patch_block_stabs (symbols, stabs, objfile)
375 struct pending *symbols;
376 struct pending_stabs *stabs;
377 struct objfile *objfile;
378 {
379 int ii;
380 char *name;
381 char *pp;
382 struct symbol *sym;
383
384 if (stabs)
385 {
386
387 /* for all the stab entries, find their corresponding symbols and
388 patch their types! */
389
390 for (ii = 0; ii < stabs->count; ++ii)
391 {
392 name = stabs->stab[ii];
393 pp = (char*) strchr (name, ':');
394 while (pp[1] == ':')
395 {
396 pp += 2;
397 pp = (char *)strchr(pp, ':');
398 }
399 sym = find_symbol_in_list (symbols, name, pp-name);
400 if (!sym)
401 {
402 /* On xcoff, if a global is defined and never referenced,
403 ld will remove it from the executable. There is then
404 a N_GSYM stab for it, but no regular (C_EXT) symbol. */
405 sym = (struct symbol *)
406 obstack_alloc (&objfile->symbol_obstack,
407 sizeof (struct symbol));
408
409 memset (sym, 0, sizeof (struct symbol));
410 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
411 SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
412 SYMBOL_NAME (sym) =
413 obstack_copy0 (&objfile->symbol_obstack, name, pp - name);
414 pp += 2;
415 if (*(pp-1) == 'F' || *(pp-1) == 'f')
416 {
417 /* I don't think the linker does this with functions,
418 so as far as I know this is never executed.
419 But it doesn't hurt to check. */
420 SYMBOL_TYPE (sym) =
421 lookup_function_type (read_type (&pp, objfile));
422 }
423 else
424 {
425 SYMBOL_TYPE (sym) = read_type (&pp, objfile);
426 }
427 add_symbol_to_list (sym, &global_symbols);
428 }
429 else
430 {
431 pp += 2;
432 if (*(pp-1) == 'F' || *(pp-1) == 'f')
433 {
434 SYMBOL_TYPE (sym) =
435 lookup_function_type (read_type (&pp, objfile));
436 }
437 else
438 {
439 SYMBOL_TYPE (sym) = read_type (&pp, objfile);
440 }
441 }
442 }
443 }
444 }
445
446 \f
447 /* Read a number by which a type is referred to in dbx data,
448 or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
449 Just a single number N is equivalent to (0,N).
450 Return the two numbers by storing them in the vector TYPENUMS.
451 TYPENUMS will then be used as an argument to dbx_lookup_type.
452
453 Returns 0 for success, -1 for error. */
454
455 static int
456 read_type_number (pp, typenums)
457 register char **pp;
458 register int *typenums;
459 {
460 int nbits;
461 if (**pp == '(')
462 {
463 (*pp)++;
464 typenums[0] = read_huge_number (pp, ',', &nbits);
465 if (nbits != 0) return -1;
466 typenums[1] = read_huge_number (pp, ')', &nbits);
467 if (nbits != 0) return -1;
468 }
469 else
470 {
471 typenums[0] = 0;
472 typenums[1] = read_huge_number (pp, 0, &nbits);
473 if (nbits != 0) return -1;
474 }
475 return 0;
476 }
477
478 \f
479 /* To handle GNU C++ typename abbreviation, we need to be able to
480 fill in a type's name as soon as space for that type is allocated.
481 `type_synonym_name' is the name of the type being allocated.
482 It is cleared as soon as it is used (lest all allocated types
483 get this name). */
484
485 static char *type_synonym_name;
486
487 #if !defined (REG_STRUCT_HAS_ADDR)
488 #define REG_STRUCT_HAS_ADDR(gcc_p,type) 0
489 #endif
490
491 /* ARGSUSED */
492 struct symbol *
493 define_symbol (valu, string, desc, type, objfile)
494 CORE_ADDR valu;
495 char *string;
496 int desc;
497 int type;
498 struct objfile *objfile;
499 {
500 register struct symbol *sym;
501 char *p = (char *) strchr (string, ':');
502 int deftype;
503 int synonym = 0;
504 register int i;
505
506 /* We would like to eliminate nameless symbols, but keep their types.
507 E.g. stab entry ":t10=*2" should produce a type 10, which is a pointer
508 to type 2, but, should not create a symbol to address that type. Since
509 the symbol will be nameless, there is no way any user can refer to it. */
510
511 int nameless;
512
513 /* Ignore syms with empty names. */
514 if (string[0] == 0)
515 return 0;
516
517 /* Ignore old-style symbols from cc -go */
518 if (p == 0)
519 return 0;
520
521 while (p[1] == ':')
522 {
523 p += 2;
524 p = strchr(p, ':');
525 }
526
527 /* If a nameless stab entry, all we need is the type, not the symbol.
528 e.g. ":t10=*2" or a nameless enum like " :T16=ered:0,green:1,blue:2,;" */
529 nameless = (p == string || ((string[0] == ' ') && (string[1] == ':')));
530
531 sym = (struct symbol *)
532 obstack_alloc (&objfile -> symbol_obstack, sizeof (struct symbol));
533 memset (sym, 0, sizeof (struct symbol));
534
535 if (processing_gcc_compilation)
536 {
537 /* GCC 2.x puts the line number in desc. SunOS apparently puts in the
538 number of bytes occupied by a type or object, which we ignore. */
539 SYMBOL_LINE(sym) = desc;
540 }
541 else
542 {
543 SYMBOL_LINE(sym) = 0; /* unknown */
544 }
545
546 if (string[0] == CPLUS_MARKER)
547 {
548 /* Special GNU C++ names. */
549 switch (string[1])
550 {
551 case 't':
552 SYMBOL_NAME (sym) = obsavestring ("this", strlen ("this"),
553 &objfile -> symbol_obstack);
554 break;
555
556 case 'v': /* $vtbl_ptr_type */
557 /* Was: SYMBOL_NAME (sym) = "vptr"; */
558 goto normal;
559
560 case 'e':
561 SYMBOL_NAME (sym) = obsavestring ("eh_throw", strlen ("eh_throw"),
562 &objfile -> symbol_obstack);
563 break;
564
565 case '_':
566 /* This was an anonymous type that was never fixed up. */
567 goto normal;
568
569 default:
570 complain (&unrecognized_cplus_name_complaint, string);
571 goto normal; /* Do *something* with it */
572 }
573 }
574 else
575 {
576 normal:
577 SYMBOL_LANGUAGE (sym) = current_subfile -> language;
578 SYMBOL_NAME (sym) = (char *)
579 obstack_alloc (&objfile -> symbol_obstack, ((p - string) + 1));
580 /* Open-coded memcpy--saves function call time. */
581 /* FIXME: Does it really? Try replacing with simple strcpy and
582 try it on an executable with a large symbol table. */
583 /* FIXME: considering that gcc can open code memcpy anyway, I
584 doubt it. xoxorich. */
585 {
586 register char *p1 = string;
587 register char *p2 = SYMBOL_NAME (sym);
588 while (p1 != p)
589 {
590 *p2++ = *p1++;
591 }
592 *p2++ = '\0';
593 }
594
595 /* If this symbol is from a C++ compilation, then attempt to cache the
596 demangled form for future reference. This is a typical time versus
597 space tradeoff, that was decided in favor of time because it sped up
598 C++ symbol lookups by a factor of about 20. */
599
600 SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->symbol_obstack);
601 }
602 p++;
603
604 /* Determine the type of name being defined. */
605 #if 0
606 /* Getting GDB to correctly skip the symbol on an undefined symbol
607 descriptor and not ever dump core is a very dodgy proposition if
608 we do things this way. I say the acorn RISC machine can just
609 fix their compiler. */
610 /* The Acorn RISC machine's compiler can put out locals that don't
611 start with "234=" or "(3,4)=", so assume anything other than the
612 deftypes we know how to handle is a local. */
613 if (!strchr ("cfFGpPrStTvVXCR", *p))
614 #else
615 if (isdigit (*p) || *p == '(' || *p == '-')
616 #endif
617 deftype = 'l';
618 else
619 deftype = *p++;
620
621 switch (deftype)
622 {
623 case 'c':
624 /* c is a special case, not followed by a type-number.
625 SYMBOL:c=iVALUE for an integer constant symbol.
626 SYMBOL:c=rVALUE for a floating constant symbol.
627 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
628 e.g. "b:c=e6,0" for "const b = blob1"
629 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
630 if (*p != '=')
631 {
632 SYMBOL_CLASS (sym) = LOC_CONST;
633 SYMBOL_TYPE (sym) = error_type (&p);
634 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
635 add_symbol_to_list (sym, &file_symbols);
636 return sym;
637 }
638 ++p;
639 switch (*p++)
640 {
641 case 'r':
642 {
643 double d = atof (p);
644 char *dbl_valu;
645
646 /* FIXME-if-picky-about-floating-accuracy: Should be using
647 target arithmetic to get the value. real.c in GCC
648 probably has the necessary code. */
649
650 /* FIXME: lookup_fundamental_type is a hack. We should be
651 creating a type especially for the type of float constants.
652 Problem is, what type should it be?
653
654 Also, what should the name of this type be? Should we
655 be using 'S' constants (see stabs.texinfo) instead? */
656
657 SYMBOL_TYPE (sym) = lookup_fundamental_type (objfile,
658 FT_DBL_PREC_FLOAT);
659 dbl_valu = (char *)
660 obstack_alloc (&objfile -> symbol_obstack,
661 TYPE_LENGTH (SYMBOL_TYPE (sym)));
662 store_floating (dbl_valu, TYPE_LENGTH (SYMBOL_TYPE (sym)), d);
663 SYMBOL_VALUE_BYTES (sym) = dbl_valu;
664 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
665 }
666 break;
667 case 'i':
668 {
669 /* Defining integer constants this way is kind of silly,
670 since 'e' constants allows the compiler to give not
671 only the value, but the type as well. C has at least
672 int, long, unsigned int, and long long as constant
673 types; other languages probably should have at least
674 unsigned as well as signed constants. */
675
676 /* We just need one int constant type for all objfiles.
677 It doesn't depend on languages or anything (arguably its
678 name should be a language-specific name for a type of
679 that size, but I'm inclined to say that if the compiler
680 wants a nice name for the type, it can use 'e'). */
681 static struct type *int_const_type;
682
683 /* Yes, this is as long as a *host* int. That is because we
684 use atoi. */
685 if (int_const_type == NULL)
686 int_const_type =
687 init_type (TYPE_CODE_INT,
688 sizeof (int) * HOST_CHAR_BIT / TARGET_CHAR_BIT, 0,
689 "integer constant",
690 (struct objfile *)NULL);
691 SYMBOL_TYPE (sym) = int_const_type;
692 SYMBOL_VALUE (sym) = atoi (p);
693 SYMBOL_CLASS (sym) = LOC_CONST;
694 }
695 break;
696 case 'e':
697 /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value
698 can be represented as integral.
699 e.g. "b:c=e6,0" for "const b = blob1"
700 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
701 {
702 SYMBOL_CLASS (sym) = LOC_CONST;
703 SYMBOL_TYPE (sym) = read_type (&p, objfile);
704
705 if (*p != ',')
706 {
707 SYMBOL_TYPE (sym) = error_type (&p);
708 break;
709 }
710 ++p;
711
712 /* If the value is too big to fit in an int (perhaps because
713 it is unsigned), or something like that, we silently get
714 a bogus value. The type and everything else about it is
715 correct. Ideally, we should be using whatever we have
716 available for parsing unsigned and long long values,
717 however. */
718 SYMBOL_VALUE (sym) = atoi (p);
719 }
720 break;
721 default:
722 {
723 SYMBOL_CLASS (sym) = LOC_CONST;
724 SYMBOL_TYPE (sym) = error_type (&p);
725 }
726 }
727 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
728 add_symbol_to_list (sym, &file_symbols);
729 return sym;
730
731 case 'C':
732 /* The name of a caught exception. */
733 SYMBOL_TYPE (sym) = read_type (&p, objfile);
734 SYMBOL_CLASS (sym) = LOC_LABEL;
735 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
736 SYMBOL_VALUE_ADDRESS (sym) = valu;
737 add_symbol_to_list (sym, &local_symbols);
738 break;
739
740 case 'f':
741 /* A static function definition. */
742 SYMBOL_TYPE (sym) = read_type (&p, objfile);
743 SYMBOL_CLASS (sym) = LOC_BLOCK;
744 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
745 add_symbol_to_list (sym, &file_symbols);
746 /* fall into process_function_types. */
747
748 process_function_types:
749 /* Function result types are described as the result type in stabs.
750 We need to convert this to the function-returning-type-X type
751 in GDB. E.g. "int" is converted to "function returning int". */
752 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_FUNC)
753 {
754 #if 0
755 /* This code doesn't work -- it needs to realloc and can't. */
756 /* Attempt to set up to record a function prototype... */
757 struct type *new = alloc_type (objfile);
758
759 /* Generate a template for the type of this function. The
760 types of the arguments will be added as we read the symbol
761 table. */
762 *new = *lookup_function_type (SYMBOL_TYPE(sym));
763 SYMBOL_TYPE(sym) = new;
764 TYPE_OBJFILE (new) = objfile;
765 in_function_type = new;
766 #else
767 SYMBOL_TYPE (sym) = lookup_function_type (SYMBOL_TYPE (sym));
768 #endif
769 }
770 /* fall into process_prototype_types */
771
772 process_prototype_types:
773 /* Sun acc puts declared types of arguments here. We don't care
774 about their actual types (FIXME -- we should remember the whole
775 function prototype), but the list may define some new types
776 that we have to remember, so we must scan it now. */
777 while (*p == ';') {
778 p++;
779 read_type (&p, objfile);
780 }
781 break;
782
783 case 'F':
784 /* A global function definition. */
785 SYMBOL_TYPE (sym) = read_type (&p, objfile);
786 SYMBOL_CLASS (sym) = LOC_BLOCK;
787 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
788 add_symbol_to_list (sym, &global_symbols);
789 goto process_function_types;
790
791 case 'G':
792 /* For a class G (global) symbol, it appears that the
793 value is not correct. It is necessary to search for the
794 corresponding linker definition to find the value.
795 These definitions appear at the end of the namelist. */
796 SYMBOL_TYPE (sym) = read_type (&p, objfile);
797 i = hashname (SYMBOL_NAME (sym));
798 SYMBOL_VALUE_CHAIN (sym) = global_sym_chain[i];
799 global_sym_chain[i] = sym;
800 SYMBOL_CLASS (sym) = LOC_STATIC;
801 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
802 add_symbol_to_list (sym, &global_symbols);
803 break;
804
805 /* This case is faked by a conditional above,
806 when there is no code letter in the dbx data.
807 Dbx data never actually contains 'l'. */
808 case 's':
809 case 'l':
810 SYMBOL_TYPE (sym) = read_type (&p, objfile);
811 SYMBOL_CLASS (sym) = LOC_LOCAL;
812 SYMBOL_VALUE (sym) = valu;
813 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
814 add_symbol_to_list (sym, &local_symbols);
815 break;
816
817 case 'p':
818 if (*p == 'F')
819 /* pF is a two-letter code that means a function parameter in Fortran.
820 The type-number specifies the type of the return value.
821 Translate it into a pointer-to-function type. */
822 {
823 p++;
824 SYMBOL_TYPE (sym)
825 = lookup_pointer_type
826 (lookup_function_type (read_type (&p, objfile)));
827 }
828 else
829 SYMBOL_TYPE (sym) = read_type (&p, objfile);
830
831 /* Normally this is a parameter, a LOC_ARG. On the i960, it
832 can also be a LOC_LOCAL_ARG depending on symbol type. */
833 #ifndef DBX_PARM_SYMBOL_CLASS
834 #define DBX_PARM_SYMBOL_CLASS(type) LOC_ARG
835 #endif
836
837 SYMBOL_CLASS (sym) = DBX_PARM_SYMBOL_CLASS (type);
838 SYMBOL_VALUE (sym) = valu;
839 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
840 #if 0
841 /* This doesn't work yet. */
842 add_param_to_type (&in_function_type, sym);
843 #endif
844 add_symbol_to_list (sym, &local_symbols);
845
846 #if TARGET_BYTE_ORDER == LITTLE_ENDIAN
847 /* On little-endian machines, this crud is never necessary, and,
848 if the extra bytes contain garbage, is harmful. */
849 break;
850 #else /* Big endian. */
851 /* If it's gcc-compiled, if it says `short', believe it. */
852 if (processing_gcc_compilation || BELIEVE_PCC_PROMOTION)
853 break;
854
855 #if !BELIEVE_PCC_PROMOTION
856 {
857 /* This is the signed type which arguments get promoted to. */
858 static struct type *pcc_promotion_type;
859 /* This is the unsigned type which arguments get promoted to. */
860 static struct type *pcc_unsigned_promotion_type;
861
862 /* Call it "int" because this is mainly C lossage. */
863 if (pcc_promotion_type == NULL)
864 pcc_promotion_type =
865 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
866 0, "int", NULL);
867
868 if (pcc_unsigned_promotion_type == NULL)
869 pcc_unsigned_promotion_type =
870 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
871 TYPE_FLAG_UNSIGNED, "unsigned int", NULL);
872
873 #if defined(BELIEVE_PCC_PROMOTION_TYPE)
874 /* This macro is defined on machines (e.g. sparc) where
875 we should believe the type of a PCC 'short' argument,
876 but shouldn't believe the address (the address is
877 the address of the corresponding int).
878
879 My guess is that this correction, as opposed to changing
880 the parameter to an 'int' (as done below, for PCC
881 on most machines), is the right thing to do
882 on all machines, but I don't want to risk breaking
883 something that already works. On most PCC machines,
884 the sparc problem doesn't come up because the calling
885 function has to zero the top bytes (not knowing whether
886 the called function wants an int or a short), so there
887 is little practical difference between an int and a short
888 (except perhaps what happens when the GDB user types
889 "print short_arg = 0x10000;").
890
891 Hacked for SunOS 4.1 by gnu@cygnus.com. In 4.1, the compiler
892 actually produces the correct address (we don't need to fix it
893 up). I made this code adapt so that it will offset the symbol
894 if it was pointing at an int-aligned location and not
895 otherwise. This way you can use the same gdb for 4.0.x and
896 4.1 systems.
897
898 If the parameter is shorter than an int, and is integral
899 (e.g. char, short, or unsigned equivalent), and is claimed to
900 be passed on an integer boundary, don't believe it! Offset the
901 parameter's address to the tail-end of that integer. */
902
903 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) < TYPE_LENGTH (pcc_promotion_type)
904 && TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_INT
905 && 0 == SYMBOL_VALUE (sym) % TYPE_LENGTH (pcc_promotion_type))
906 {
907 SYMBOL_VALUE (sym) += TYPE_LENGTH (pcc_promotion_type)
908 - TYPE_LENGTH (SYMBOL_TYPE (sym));
909 }
910 break;
911
912 #else /* no BELIEVE_PCC_PROMOTION_TYPE. */
913
914 /* If PCC says a parameter is a short or a char,
915 it is really an int. */
916 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) < TYPE_LENGTH (pcc_promotion_type)
917 && TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_INT)
918 {
919 SYMBOL_TYPE (sym) =
920 TYPE_UNSIGNED (SYMBOL_TYPE (sym))
921 ? pcc_unsigned_promotion_type
922 : pcc_promotion_type;
923 }
924 break;
925
926 #endif /* no BELIEVE_PCC_PROMOTION_TYPE. */
927 }
928 #endif /* !BELIEVE_PCC_PROMOTION. */
929 #endif /* Big endian. */
930
931 case 'P':
932 /* acc seems to use P to delare the prototypes of functions that
933 are referenced by this file. gdb is not prepared to deal
934 with this extra information. FIXME, it ought to. */
935 if (type == N_FUN)
936 {
937 read_type (&p, objfile);
938 goto process_prototype_types;
939 }
940 /*FALLTHROUGH*/
941
942 case 'R':
943 /* Parameter which is in a register. */
944 SYMBOL_TYPE (sym) = read_type (&p, objfile);
945 SYMBOL_CLASS (sym) = LOC_REGPARM;
946 SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
947 if (SYMBOL_VALUE (sym) >= NUM_REGS)
948 {
949 complain (&reg_value_complaint, SYMBOL_SOURCE_NAME (sym));
950 SYMBOL_VALUE (sym) = SP_REGNUM; /* Known safe, though useless */
951 }
952 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
953 add_symbol_to_list (sym, &local_symbols);
954 break;
955
956 case 'r':
957 /* Register variable (either global or local). */
958 SYMBOL_TYPE (sym) = read_type (&p, objfile);
959 SYMBOL_CLASS (sym) = LOC_REGISTER;
960 SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
961 if (SYMBOL_VALUE (sym) >= NUM_REGS)
962 {
963 complain (&reg_value_complaint, SYMBOL_SOURCE_NAME (sym));
964 SYMBOL_VALUE (sym) = SP_REGNUM; /* Known safe, though useless */
965 }
966 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
967 if (within_function)
968 {
969 /* Sun cc uses a pair of symbols, one 'p' and one 'r' with the same
970 name to represent an argument passed in a register.
971 GCC uses 'P' for the same case. So if we find such a symbol pair
972 we combine it into one 'P' symbol.
973
974 But we only do this in the REG_STRUCT_HAS_ADDR case, so that
975 we can still get information about what is going on with the
976 stack (VAX for computing args_printed, using stack slots instead
977 of saved registers in backtraces, etc.).
978
979 Note that this code illegally combines
980 main(argc) struct foo argc; { register struct foo argc; }
981 but this case is considered pathological and causes a warning
982 from a decent compiler. */
983
984 if (local_symbols
985 && local_symbols->nsyms > 0
986 && REG_STRUCT_HAS_ADDR (processing_gcc_compilation,
987 SYMBOL_TYPE (sym))
988 && (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
989 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION))
990 {
991 struct symbol *prev_sym;
992 prev_sym = local_symbols->symbol[local_symbols->nsyms - 1];
993 if (SYMBOL_CLASS (prev_sym) == LOC_REF_ARG
994 && STREQ (SYMBOL_NAME (prev_sym), SYMBOL_NAME(sym)))
995 {
996 SYMBOL_CLASS (prev_sym) = LOC_REGPARM;
997 /* Use the type from the LOC_REGISTER; that is the type
998 that is actually in that register. */
999 SYMBOL_TYPE (prev_sym) = SYMBOL_TYPE (sym);
1000 SYMBOL_VALUE (prev_sym) = SYMBOL_VALUE (sym);
1001 sym = prev_sym;
1002 break;
1003 }
1004 }
1005 add_symbol_to_list (sym, &local_symbols);
1006 }
1007 else
1008 add_symbol_to_list (sym, &file_symbols);
1009 break;
1010
1011 case 'S':
1012 /* Static symbol at top level of file */
1013 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1014 SYMBOL_CLASS (sym) = LOC_STATIC;
1015 SYMBOL_VALUE_ADDRESS (sym) = valu;
1016 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1017 add_symbol_to_list (sym, &file_symbols);
1018 break;
1019
1020 case 't':
1021 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1022
1023 /* For a nameless type, we don't want a create a symbol, thus we
1024 did not use `sym'. Return without further processing. */
1025 if (nameless) return NULL;
1026
1027 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1028 SYMBOL_VALUE (sym) = valu;
1029 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1030 /* C++ vagaries: we may have a type which is derived from
1031 a base type which did not have its name defined when the
1032 derived class was output. We fill in the derived class's
1033 base part member's name here in that case. */
1034 if (TYPE_NAME (SYMBOL_TYPE (sym)) != NULL)
1035 if ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
1036 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION)
1037 && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)))
1038 {
1039 int j;
1040 for (j = TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)) - 1; j >= 0; j--)
1041 if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) == 0)
1042 TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) =
1043 type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym), j));
1044 }
1045
1046 if (TYPE_NAME (SYMBOL_TYPE (sym)) == NULL)
1047 {
1048 if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_PTR
1049 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_FUNC)
1050 {
1051 /* If we are giving a name to a type such as "pointer to
1052 foo" or "function returning foo", we better not set
1053 the TYPE_NAME. If the program contains "typedef char
1054 *caddr_t;", we don't want all variables of type char
1055 * to print as caddr_t. This is not just a
1056 consequence of GDB's type management; PCC and GCC (at
1057 least through version 2.4) both output variables of
1058 either type char * or caddr_t with the type number
1059 defined in the 't' symbol for caddr_t. If a future
1060 compiler cleans this up it GDB is not ready for it
1061 yet, but if it becomes ready we somehow need to
1062 disable this check (without breaking the PCC/GCC2.4
1063 case).
1064
1065 Sigh.
1066
1067 Fortunately, this check seems not to be necessary
1068 for anything except pointers or functions. */
1069 }
1070 else
1071 TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_NAME (sym);
1072 }
1073
1074 add_symbol_to_list (sym, &file_symbols);
1075 break;
1076
1077 case 'T':
1078 /* Struct, union, or enum tag. For GNU C++, this can be be followed
1079 by 't' which means we are typedef'ing it as well. */
1080 synonym = *p == 't';
1081
1082 if (synonym)
1083 {
1084 p++;
1085 type_synonym_name = obsavestring (SYMBOL_NAME (sym),
1086 strlen (SYMBOL_NAME (sym)),
1087 &objfile -> symbol_obstack);
1088 }
1089 /* The semantics of C++ state that "struct foo { ... }" also defines
1090 a typedef for "foo". Unfortunately, cfront never makes the typedef
1091 when translating C++ into C. We make the typedef here so that
1092 "ptype foo" works as expected for cfront translated code. */
1093 else if (current_subfile->language == language_cplus)
1094 {
1095 synonym = 1;
1096 type_synonym_name = obsavestring (SYMBOL_NAME (sym),
1097 strlen (SYMBOL_NAME (sym)),
1098 &objfile -> symbol_obstack);
1099 }
1100
1101 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1102
1103 /* For a nameless type, we don't want a create a symbol, thus we
1104 did not use `sym'. Return without further processing. */
1105 if (nameless) return NULL;
1106
1107 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1108 SYMBOL_VALUE (sym) = valu;
1109 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
1110 if (TYPE_TAG_NAME (SYMBOL_TYPE (sym)) == 0)
1111 TYPE_TAG_NAME (SYMBOL_TYPE (sym))
1112 = obconcat (&objfile -> type_obstack, "", "", SYMBOL_NAME (sym));
1113 add_symbol_to_list (sym, &file_symbols);
1114
1115 if (synonym)
1116 {
1117 /* Clone the sym and then modify it. */
1118 register struct symbol *typedef_sym = (struct symbol *)
1119 obstack_alloc (&objfile -> symbol_obstack, sizeof (struct symbol));
1120 *typedef_sym = *sym;
1121 SYMBOL_CLASS (typedef_sym) = LOC_TYPEDEF;
1122 SYMBOL_VALUE (typedef_sym) = valu;
1123 SYMBOL_NAMESPACE (typedef_sym) = VAR_NAMESPACE;
1124 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
1125 TYPE_NAME (SYMBOL_TYPE (sym))
1126 = obconcat (&objfile -> type_obstack, "", "", SYMBOL_NAME (sym));
1127 add_symbol_to_list (typedef_sym, &file_symbols);
1128 }
1129 break;
1130
1131 case 'V':
1132 /* Static symbol of local scope */
1133 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1134 SYMBOL_CLASS (sym) = LOC_STATIC;
1135 SYMBOL_VALUE_ADDRESS (sym) = valu;
1136 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1137 if (os9k_stabs)
1138 add_symbol_to_list (sym, &global_symbols);
1139 else
1140 add_symbol_to_list (sym, &local_symbols);
1141 break;
1142
1143 case 'v':
1144 /* Reference parameter */
1145 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1146 SYMBOL_CLASS (sym) = LOC_REF_ARG;
1147 SYMBOL_VALUE (sym) = valu;
1148 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1149 add_symbol_to_list (sym, &local_symbols);
1150 break;
1151
1152 case 'X':
1153 /* This is used by Sun FORTRAN for "function result value".
1154 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
1155 that Pascal uses it too, but when I tried it Pascal used
1156 "x:3" (local symbol) instead. */
1157 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1158 SYMBOL_CLASS (sym) = LOC_LOCAL;
1159 SYMBOL_VALUE (sym) = valu;
1160 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1161 add_symbol_to_list (sym, &local_symbols);
1162 break;
1163
1164 default:
1165 SYMBOL_TYPE (sym) = error_type (&p);
1166 SYMBOL_CLASS (sym) = LOC_CONST;
1167 SYMBOL_VALUE (sym) = 0;
1168 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1169 add_symbol_to_list (sym, &file_symbols);
1170 break;
1171 }
1172
1173 /* When passing structures to a function, some systems sometimes pass
1174 the address in a register, not the structure itself.
1175
1176 If REG_STRUCT_HAS_ADDR yields non-zero we have to convert LOC_REGPARM
1177 to LOC_REGPARM_ADDR for structures and unions. */
1178
1179 if (SYMBOL_CLASS (sym) == LOC_REGPARM
1180 && REG_STRUCT_HAS_ADDR (processing_gcc_compilation,
1181 SYMBOL_TYPE (sym))
1182 && ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT)
1183 || (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION)))
1184 SYMBOL_CLASS (sym) = LOC_REGPARM_ADDR;
1185
1186 /* Likewise for converting LOC_ARG to LOC_REF_ARG (for the 7th and
1187 subsequent arguments on the sparc, for example). */
1188 if (SYMBOL_CLASS (sym) == LOC_ARG
1189 && REG_STRUCT_HAS_ADDR (processing_gcc_compilation,
1190 SYMBOL_TYPE (sym))
1191 && ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT)
1192 || (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION)))
1193 SYMBOL_CLASS (sym) = LOC_REF_ARG;
1194
1195 return sym;
1196 }
1197
1198 \f
1199 /* Skip rest of this symbol and return an error type.
1200
1201 General notes on error recovery: error_type always skips to the
1202 end of the symbol (modulo cretinous dbx symbol name continuation).
1203 Thus code like this:
1204
1205 if (*(*pp)++ != ';')
1206 return error_type (pp);
1207
1208 is wrong because if *pp starts out pointing at '\0' (typically as the
1209 result of an earlier error), it will be incremented to point to the
1210 start of the next symbol, which might produce strange results, at least
1211 if you run off the end of the string table. Instead use
1212
1213 if (**pp != ';')
1214 return error_type (pp);
1215 ++*pp;
1216
1217 or
1218
1219 if (**pp != ';')
1220 foo = error_type (pp);
1221 else
1222 ++*pp;
1223
1224 And in case it isn't obvious, the point of all this hair is so the compiler
1225 can define new types and new syntaxes, and old versions of the
1226 debugger will be able to read the new symbol tables. */
1227
1228 static struct type *
1229 error_type (pp)
1230 char **pp;
1231 {
1232 complain (&error_type_complaint);
1233 while (1)
1234 {
1235 /* Skip to end of symbol. */
1236 while (**pp != '\0')
1237 {
1238 (*pp)++;
1239 }
1240
1241 /* Check for and handle cretinous dbx symbol name continuation! */
1242 if ((*pp)[-1] == '\\' || (*pp)[-1] == '?')
1243 {
1244 *pp = next_symbol_text ();
1245 }
1246 else
1247 {
1248 break;
1249 }
1250 }
1251 return (builtin_type_error);
1252 }
1253
1254 \f
1255 /* Read type information or a type definition; return the type. Even
1256 though this routine accepts either type information or a type
1257 definition, the distinction is relevant--some parts of stabsread.c
1258 assume that type information starts with a digit, '-', or '(' in
1259 deciding whether to call read_type. */
1260
1261 struct type *
1262 read_type (pp, objfile)
1263 register char **pp;
1264 struct objfile *objfile;
1265 {
1266 register struct type *type = 0;
1267 struct type *type1;
1268 int typenums[2];
1269 int xtypenums[2];
1270 char type_descriptor;
1271
1272 /* Size in bits of type if specified by a type attribute, or -1 if
1273 there is no size attribute. */
1274 int type_size = -1;
1275
1276 /* Used to distinguish string and bitstring from char-array and set. */
1277 int is_string = 0;
1278
1279 /* Read type number if present. The type number may be omitted.
1280 for instance in a two-dimensional array declared with type
1281 "ar1;1;10;ar1;1;10;4". */
1282 if ((**pp >= '0' && **pp <= '9')
1283 || **pp == '('
1284 || **pp == '-')
1285 {
1286 if (read_type_number (pp, typenums) != 0)
1287 return error_type (pp);
1288
1289 /* Type is not being defined here. Either it already exists,
1290 or this is a forward reference to it. dbx_alloc_type handles
1291 both cases. */
1292 if (**pp != '=')
1293 return dbx_alloc_type (typenums, objfile);
1294
1295 /* Type is being defined here. */
1296 /* Skip the '='. */
1297 ++(*pp);
1298
1299 while (**pp == '@')
1300 {
1301 char *p = *pp + 1;
1302 /* It might be a type attribute or a member type. */
1303 if (isdigit (*p) || *p == '(' || *p == '-')
1304 /* Member type. */
1305 break;
1306 else
1307 {
1308 /* Type attributes. */
1309 char *attr = p;
1310
1311 /* Skip to the semicolon. */
1312 while (*p != ';' && *p != '\0')
1313 ++p;
1314 *pp = p;
1315 if (*p == '\0')
1316 return error_type (pp);
1317 else
1318 /* Skip the semicolon. */
1319 ++*pp;
1320
1321 switch (*attr)
1322 {
1323 case 's':
1324 type_size = atoi (attr + 1);
1325 if (type_size <= 0)
1326 type_size = -1;
1327 break;
1328
1329 case 'S':
1330 is_string = 1;
1331 break;
1332
1333 default:
1334 /* Ignore unrecognized type attributes, so future compilers
1335 can invent new ones. */
1336 break;
1337 }
1338 }
1339 }
1340 /* Skip the type descriptor, we get it below with (*pp)[-1]. */
1341 ++(*pp);
1342 }
1343 else
1344 {
1345 /* 'typenums=' not present, type is anonymous. Read and return
1346 the definition, but don't put it in the type vector. */
1347 typenums[0] = typenums[1] = -1;
1348 (*pp)++;
1349 }
1350
1351 type_descriptor = (*pp)[-1];
1352 switch (type_descriptor)
1353 {
1354 case 'x':
1355 {
1356 enum type_code code;
1357
1358 /* Used to index through file_symbols. */
1359 struct pending *ppt;
1360 int i;
1361
1362 /* Name including "struct", etc. */
1363 char *type_name;
1364
1365 {
1366 char *from, *to, *p, *q1, *q2;
1367
1368 /* Set the type code according to the following letter. */
1369 switch ((*pp)[0])
1370 {
1371 case 's':
1372 code = TYPE_CODE_STRUCT;
1373 break;
1374 case 'u':
1375 code = TYPE_CODE_UNION;
1376 break;
1377 case 'e':
1378 code = TYPE_CODE_ENUM;
1379 break;
1380 default:
1381 {
1382 /* Complain and keep going, so compilers can invent new
1383 cross-reference types. */
1384 static struct complaint msg =
1385 {"Unrecognized cross-reference type `%c'", 0, 0};
1386 complain (&msg, (*pp)[0]);
1387 code = TYPE_CODE_STRUCT;
1388 break;
1389 }
1390 }
1391
1392 q1 = strchr(*pp, '<');
1393 p = strchr(*pp, ':');
1394 if (p == NULL)
1395 return error_type (pp);
1396 while (q1 && p > q1 && p[1] == ':')
1397 {
1398 q2 = strchr(q1, '>');
1399 if (!q2 || q2 < p)
1400 break;
1401 p += 2;
1402 p = strchr(p, ':');
1403 if (p == NULL)
1404 return error_type (pp);
1405 }
1406 to = type_name =
1407 (char *)obstack_alloc (&objfile->type_obstack, p - *pp + 1);
1408
1409 /* Copy the name. */
1410 from = *pp + 1;
1411 while (from < p)
1412 *to++ = *from++;
1413 *to = '\0';
1414
1415 /* Set the pointer ahead of the name which we just read, and
1416 the colon. */
1417 *pp = from + 1;
1418 }
1419
1420 /* Now check to see whether the type has already been
1421 declared. This was written for arrays of cross-referenced
1422 types before we had TYPE_CODE_TARGET_STUBBED, so I'm pretty
1423 sure it is not necessary anymore. But it might be a good
1424 idea, to save a little memory. */
1425
1426 for (ppt = file_symbols; ppt; ppt = ppt->next)
1427 for (i = 0; i < ppt->nsyms; i++)
1428 {
1429 struct symbol *sym = ppt->symbol[i];
1430
1431 if (SYMBOL_CLASS (sym) == LOC_TYPEDEF
1432 && SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE
1433 && (TYPE_CODE (SYMBOL_TYPE (sym)) == code)
1434 && STREQ (SYMBOL_NAME (sym), type_name))
1435 {
1436 obstack_free (&objfile -> type_obstack, type_name);
1437 type = SYMBOL_TYPE (sym);
1438 return type;
1439 }
1440 }
1441
1442 /* Didn't find the type to which this refers, so we must
1443 be dealing with a forward reference. Allocate a type
1444 structure for it, and keep track of it so we can
1445 fill in the rest of the fields when we get the full
1446 type. */
1447 type = dbx_alloc_type (typenums, objfile);
1448 TYPE_CODE (type) = code;
1449 TYPE_TAG_NAME (type) = type_name;
1450 INIT_CPLUS_SPECIFIC(type);
1451 TYPE_FLAGS (type) |= TYPE_FLAG_STUB;
1452
1453 add_undefined_type (type);
1454 return type;
1455 }
1456
1457 case '-': /* RS/6000 built-in type */
1458 case '0':
1459 case '1':
1460 case '2':
1461 case '3':
1462 case '4':
1463 case '5':
1464 case '6':
1465 case '7':
1466 case '8':
1467 case '9':
1468 case '(':
1469
1470 {
1471 char *pp_saved;
1472
1473 (*pp)--;
1474 pp_saved = *pp;
1475
1476 /* Peek ahead at the number to detect void. */
1477 if (read_type_number (pp, xtypenums) != 0)
1478 return error_type (pp);
1479
1480 if (typenums[0] == xtypenums[0] && typenums[1] == xtypenums[1])
1481 /* It's being defined as itself. That means it is "void". */
1482 type = init_type (TYPE_CODE_VOID, 0, 0, NULL, objfile);
1483 else
1484 {
1485 struct type *xtype;
1486
1487 /* Go back to the number and have read_type get it. This means
1488 that we can deal with something like t(1,2)=(3,4)=... which
1489 the Lucid compiler uses. */
1490 *pp = pp_saved;
1491 xtype = read_type (pp, objfile);
1492
1493 /* The type is being defined to another type. So we copy the type.
1494 This loses if we copy a C++ class and so we lose track of how
1495 the names are mangled (but g++ doesn't output stabs like this
1496 now anyway). */
1497
1498 type = alloc_type (objfile);
1499 memcpy (type, xtype, sizeof (struct type));
1500
1501 /* The idea behind clearing the names is that the only purpose
1502 for defining a type to another type is so that the name of
1503 one can be different. So we probably don't need to worry much
1504 about the case where the compiler doesn't give a name to the
1505 new type. */
1506 TYPE_NAME (type) = NULL;
1507 TYPE_TAG_NAME (type) = NULL;
1508 }
1509 if (typenums[0] != -1)
1510 *dbx_lookup_type (typenums) = type;
1511 break;
1512 }
1513
1514 /* In the following types, we must be sure to overwrite any existing
1515 type that the typenums refer to, rather than allocating a new one
1516 and making the typenums point to the new one. This is because there
1517 may already be pointers to the existing type (if it had been
1518 forward-referenced), and we must change it to a pointer, function,
1519 reference, or whatever, *in-place*. */
1520
1521 case '*':
1522 type1 = read_type (pp, objfile);
1523 type = make_pointer_type (type1, dbx_lookup_type (typenums));
1524 break;
1525
1526 case '&': /* Reference to another type */
1527 type1 = read_type (pp, objfile);
1528 type = make_reference_type (type1, dbx_lookup_type (typenums));
1529 break;
1530
1531 case 'f': /* Function returning another type */
1532 if (os9k_stabs && **pp == '(')
1533 {
1534 /* Function prototype; skip it.
1535 We must conditionalize this on os9k_stabs because otherwise
1536 it could be confused with a Sun-style (1,3) typenumber
1537 (I think). */
1538 while (**pp != ')')
1539 ++*pp;
1540 ++*pp;
1541 }
1542 type1 = read_type (pp, objfile);
1543 type = make_function_type (type1, dbx_lookup_type (typenums));
1544 break;
1545
1546 case 'k': /* Const qualifier on some type (Sun) */
1547 case 'c': /* Const qualifier on some type (OS9000) */
1548 /* Because 'c' means other things to AIX and 'k' is perfectly good,
1549 only accept 'c' in the os9k_stabs case. */
1550 if (type_descriptor == 'c' && !os9k_stabs)
1551 return error_type (pp);
1552 type = read_type (pp, objfile);
1553 /* FIXME! For now, we ignore const and volatile qualifiers. */
1554 break;
1555
1556 case 'B': /* Volatile qual on some type (Sun) */
1557 case 'i': /* Volatile qual on some type (OS9000) */
1558 /* Because 'i' means other things to AIX and 'B' is perfectly good,
1559 only accept 'i' in the os9k_stabs case. */
1560 if (type_descriptor == 'i' && !os9k_stabs)
1561 return error_type (pp);
1562 type = read_type (pp, objfile);
1563 /* FIXME! For now, we ignore const and volatile qualifiers. */
1564 break;
1565
1566 /* FIXME -- we should be doing smash_to_XXX types here. */
1567 case '@': /* Member (class & variable) type */
1568 {
1569 struct type *domain = read_type (pp, objfile);
1570 struct type *memtype;
1571
1572 if (**pp != ',')
1573 /* Invalid member type data format. */
1574 return error_type (pp);
1575 ++*pp;
1576
1577 memtype = read_type (pp, objfile);
1578 type = dbx_alloc_type (typenums, objfile);
1579 smash_to_member_type (type, domain, memtype);
1580 }
1581 break;
1582
1583 case '#': /* Method (class & fn) type */
1584 if ((*pp)[0] == '#')
1585 {
1586 /* We'll get the parameter types from the name. */
1587 struct type *return_type;
1588
1589 (*pp)++;
1590 return_type = read_type (pp, objfile);
1591 if (*(*pp)++ != ';')
1592 complain (&invalid_member_complaint, symnum);
1593 type = allocate_stub_method (return_type);
1594 if (typenums[0] != -1)
1595 *dbx_lookup_type (typenums) = type;
1596 }
1597 else
1598 {
1599 struct type *domain = read_type (pp, objfile);
1600 struct type *return_type;
1601 struct type **args;
1602
1603 if (**pp != ',')
1604 /* Invalid member type data format. */
1605 return error_type (pp);
1606 else
1607 ++(*pp);
1608
1609 return_type = read_type (pp, objfile);
1610 args = read_args (pp, ';', objfile);
1611 type = dbx_alloc_type (typenums, objfile);
1612 smash_to_method_type (type, domain, return_type, args);
1613 }
1614 break;
1615
1616 case 'r': /* Range type */
1617 type = read_range_type (pp, typenums, objfile);
1618 if (typenums[0] != -1)
1619 *dbx_lookup_type (typenums) = type;
1620 break;
1621
1622 case 'b':
1623 if (os9k_stabs)
1624 /* Const and volatile qualified type. */
1625 type = read_type (pp, objfile);
1626 else
1627 {
1628 /* Sun ACC builtin int type */
1629 type = read_sun_builtin_type (pp, typenums, objfile);
1630 if (typenums[0] != -1)
1631 *dbx_lookup_type (typenums) = type;
1632 }
1633 break;
1634
1635 case 'R': /* Sun ACC builtin float type */
1636 type = read_sun_floating_type (pp, typenums, objfile);
1637 if (typenums[0] != -1)
1638 *dbx_lookup_type (typenums) = type;
1639 break;
1640
1641 case 'e': /* Enumeration type */
1642 type = dbx_alloc_type (typenums, objfile);
1643 type = read_enum_type (pp, type, objfile);
1644 if (typenums[0] != -1)
1645 *dbx_lookup_type (typenums) = type;
1646 break;
1647
1648 case 's': /* Struct type */
1649 case 'u': /* Union type */
1650 type = dbx_alloc_type (typenums, objfile);
1651 if (!TYPE_NAME (type))
1652 {
1653 TYPE_NAME (type) = type_synonym_name;
1654 }
1655 type_synonym_name = NULL;
1656 switch (type_descriptor)
1657 {
1658 case 's':
1659 TYPE_CODE (type) = TYPE_CODE_STRUCT;
1660 break;
1661 case 'u':
1662 TYPE_CODE (type) = TYPE_CODE_UNION;
1663 break;
1664 }
1665 type = read_struct_type (pp, type, objfile);
1666 break;
1667
1668 case 'a': /* Array type */
1669 if (**pp != 'r')
1670 return error_type (pp);
1671 ++*pp;
1672
1673 type = dbx_alloc_type (typenums, objfile);
1674 type = read_array_type (pp, type, objfile);
1675 if (is_string)
1676 TYPE_CODE (type) = TYPE_CODE_STRING;
1677 break;
1678
1679 case 'S':
1680 type1 = read_type (pp, objfile);
1681 type = create_set_type ((struct type*) NULL, type1);
1682 if (is_string)
1683 TYPE_CODE (type) = TYPE_CODE_BITSTRING;
1684 if (typenums[0] != -1)
1685 *dbx_lookup_type (typenums) = type;
1686 break;
1687
1688 default:
1689 --*pp; /* Go back to the symbol in error */
1690 /* Particularly important if it was \0! */
1691 return error_type (pp);
1692 }
1693
1694 if (type == 0)
1695 {
1696 warning ("GDB internal error, type is NULL in stabsread.c\n");
1697 return error_type (pp);
1698 }
1699
1700 /* Size specified in a type attribute overrides any other size. */
1701 if (type_size != -1)
1702 TYPE_LENGTH (type) = type_size / TARGET_CHAR_BIT;
1703
1704 return type;
1705 }
1706 \f
1707 /* RS/6000 xlc/dbx combination uses a set of builtin types, starting from -1.
1708 Return the proper type node for a given builtin type number. */
1709
1710 static struct type *
1711 rs6000_builtin_type (typenum)
1712 int typenum;
1713 {
1714 /* We recognize types numbered from -NUMBER_RECOGNIZED to -1. */
1715 #define NUMBER_RECOGNIZED 30
1716 /* This includes an empty slot for type number -0. */
1717 static struct type *negative_types[NUMBER_RECOGNIZED + 1];
1718 struct type *rettype = NULL;
1719
1720 if (typenum >= 0 || typenum < -NUMBER_RECOGNIZED)
1721 {
1722 complain (&rs6000_builtin_complaint, typenum);
1723 return builtin_type_error;
1724 }
1725 if (negative_types[-typenum] != NULL)
1726 return negative_types[-typenum];
1727
1728 #if TARGET_CHAR_BIT != 8
1729 #error This code wrong for TARGET_CHAR_BIT not 8
1730 /* These definitions all assume that TARGET_CHAR_BIT is 8. I think
1731 that if that ever becomes not true, the correct fix will be to
1732 make the size in the struct type to be in bits, not in units of
1733 TARGET_CHAR_BIT. */
1734 #endif
1735
1736 switch (-typenum)
1737 {
1738 case 1:
1739 /* The size of this and all the other types are fixed, defined
1740 by the debugging format. If there is a type called "int" which
1741 is other than 32 bits, then it should use a new negative type
1742 number (or avoid negative type numbers for that case).
1743 See stabs.texinfo. */
1744 rettype = init_type (TYPE_CODE_INT, 4, 0, "int", NULL);
1745 break;
1746 case 2:
1747 rettype = init_type (TYPE_CODE_INT, 1, 0, "char", NULL);
1748 break;
1749 case 3:
1750 rettype = init_type (TYPE_CODE_INT, 2, 0, "short", NULL);
1751 break;
1752 case 4:
1753 rettype = init_type (TYPE_CODE_INT, 4, 0, "long", NULL);
1754 break;
1755 case 5:
1756 rettype = init_type (TYPE_CODE_INT, 1, TYPE_FLAG_UNSIGNED,
1757 "unsigned char", NULL);
1758 break;
1759 case 6:
1760 rettype = init_type (TYPE_CODE_INT, 1, 0, "signed char", NULL);
1761 break;
1762 case 7:
1763 rettype = init_type (TYPE_CODE_INT, 2, TYPE_FLAG_UNSIGNED,
1764 "unsigned short", NULL);
1765 break;
1766 case 8:
1767 rettype = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED,
1768 "unsigned int", NULL);
1769 break;
1770 case 9:
1771 rettype = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED,
1772 "unsigned", NULL);
1773 case 10:
1774 rettype = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED,
1775 "unsigned long", NULL);
1776 break;
1777 case 11:
1778 rettype = init_type (TYPE_CODE_VOID, 0, 0, "void", NULL);
1779 break;
1780 case 12:
1781 /* IEEE single precision (32 bit). */
1782 rettype = init_type (TYPE_CODE_FLT, 4, 0, "float", NULL);
1783 break;
1784 case 13:
1785 /* IEEE double precision (64 bit). */
1786 rettype = init_type (TYPE_CODE_FLT, 8, 0, "double", NULL);
1787 break;
1788 case 14:
1789 /* This is an IEEE double on the RS/6000, and different machines with
1790 different sizes for "long double" should use different negative
1791 type numbers. See stabs.texinfo. */
1792 rettype = init_type (TYPE_CODE_FLT, 8, 0, "long double", NULL);
1793 break;
1794 case 15:
1795 rettype = init_type (TYPE_CODE_INT, 4, 0, "integer", NULL);
1796 break;
1797 case 16:
1798 rettype = init_type (TYPE_CODE_BOOL, 4, 0, "boolean", NULL);
1799 break;
1800 case 17:
1801 rettype = init_type (TYPE_CODE_FLT, 4, 0, "short real", NULL);
1802 break;
1803 case 18:
1804 rettype = init_type (TYPE_CODE_FLT, 8, 0, "real", NULL);
1805 break;
1806 case 19:
1807 rettype = init_type (TYPE_CODE_ERROR, 0, 0, "stringptr", NULL);
1808 break;
1809 case 20:
1810 rettype = init_type (TYPE_CODE_CHAR, 1, TYPE_FLAG_UNSIGNED,
1811 "character", NULL);
1812 break;
1813 case 21:
1814 rettype = init_type (TYPE_CODE_BOOL, 1, TYPE_FLAG_UNSIGNED,
1815 "logical*1", NULL);
1816 break;
1817 case 22:
1818 rettype = init_type (TYPE_CODE_BOOL, 2, TYPE_FLAG_UNSIGNED,
1819 "logical*2", NULL);
1820 break;
1821 case 23:
1822 rettype = init_type (TYPE_CODE_BOOL, 4, TYPE_FLAG_UNSIGNED,
1823 "logical*4", NULL);
1824 break;
1825 case 24:
1826 rettype = init_type (TYPE_CODE_BOOL, 4, TYPE_FLAG_UNSIGNED,
1827 "logical", NULL);
1828 break;
1829 case 25:
1830 /* Complex type consisting of two IEEE single precision values. */
1831 rettype = init_type (TYPE_CODE_ERROR, 8, 0, "complex", NULL);
1832 break;
1833 case 26:
1834 /* Complex type consisting of two IEEE double precision values. */
1835 rettype = init_type (TYPE_CODE_ERROR, 16, 0, "double complex", NULL);
1836 break;
1837 case 27:
1838 rettype = init_type (TYPE_CODE_INT, 1, 0, "integer*1", NULL);
1839 break;
1840 case 28:
1841 rettype = init_type (TYPE_CODE_INT, 2, 0, "integer*2", NULL);
1842 break;
1843 case 29:
1844 rettype = init_type (TYPE_CODE_INT, 4, 0, "integer*4", NULL);
1845 break;
1846 case 30:
1847 rettype = init_type (TYPE_CODE_CHAR, 2, 0, "wchar", NULL);
1848 break;
1849 }
1850 negative_types[-typenum] = rettype;
1851 return rettype;
1852 }
1853 \f
1854 /* This page contains subroutines of read_type. */
1855
1856 #define VISIBILITY_PRIVATE '0' /* Stabs character for private field */
1857 #define VISIBILITY_PROTECTED '1' /* Stabs character for protected fld */
1858 #define VISIBILITY_PUBLIC '2' /* Stabs character for public field */
1859 #define VISIBILITY_IGNORE '9' /* Optimized out or zero length */
1860
1861 /* Read member function stabs info for C++ classes. The form of each member
1862 function data is:
1863
1864 NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
1865
1866 An example with two member functions is:
1867
1868 afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
1869
1870 For the case of overloaded operators, the format is op$::*.funcs, where
1871 $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
1872 name (such as `+=') and `.' marks the end of the operator name.
1873
1874 Returns 1 for success, 0 for failure. */
1875
1876 static int
1877 read_member_functions (fip, pp, type, objfile)
1878 struct field_info *fip;
1879 char **pp;
1880 struct type *type;
1881 struct objfile *objfile;
1882 {
1883 int nfn_fields = 0;
1884 int length = 0;
1885 /* Total number of member functions defined in this class. If the class
1886 defines two `f' functions, and one `g' function, then this will have
1887 the value 3. */
1888 int total_length = 0;
1889 int i;
1890 struct next_fnfield
1891 {
1892 struct next_fnfield *next;
1893 struct fn_field fn_field;
1894 } *sublist;
1895 struct type *look_ahead_type;
1896 struct next_fnfieldlist *new_fnlist;
1897 struct next_fnfield *new_sublist;
1898 char *main_fn_name;
1899 register char *p;
1900
1901 /* Process each list until we find something that is not a member function
1902 or find the end of the functions. */
1903
1904 while (**pp != ';')
1905 {
1906 /* We should be positioned at the start of the function name.
1907 Scan forward to find the first ':' and if it is not the
1908 first of a "::" delimiter, then this is not a member function. */
1909 p = *pp;
1910 while (*p != ':')
1911 {
1912 p++;
1913 }
1914 if (p[1] != ':')
1915 {
1916 break;
1917 }
1918
1919 sublist = NULL;
1920 look_ahead_type = NULL;
1921 length = 0;
1922
1923 new_fnlist = (struct next_fnfieldlist *)
1924 xmalloc (sizeof (struct next_fnfieldlist));
1925 make_cleanup (free, new_fnlist);
1926 memset (new_fnlist, 0, sizeof (struct next_fnfieldlist));
1927
1928 if ((*pp)[0] == 'o' && (*pp)[1] == 'p' && (*pp)[2] == CPLUS_MARKER)
1929 {
1930 /* This is a completely wierd case. In order to stuff in the
1931 names that might contain colons (the usual name delimiter),
1932 Mike Tiemann defined a different name format which is
1933 signalled if the identifier is "op$". In that case, the
1934 format is "op$::XXXX." where XXXX is the name. This is
1935 used for names like "+" or "=". YUUUUUUUK! FIXME! */
1936 /* This lets the user type "break operator+".
1937 We could just put in "+" as the name, but that wouldn't
1938 work for "*". */
1939 static char opname[32] = {'o', 'p', CPLUS_MARKER};
1940 char *o = opname + 3;
1941
1942 /* Skip past '::'. */
1943 *pp = p + 2;
1944
1945 STABS_CONTINUE (pp);
1946 p = *pp;
1947 while (*p != '.')
1948 {
1949 *o++ = *p++;
1950 }
1951 main_fn_name = savestring (opname, o - opname);
1952 /* Skip past '.' */
1953 *pp = p + 1;
1954 }
1955 else
1956 {
1957 main_fn_name = savestring (*pp, p - *pp);
1958 /* Skip past '::'. */
1959 *pp = p + 2;
1960 }
1961 new_fnlist -> fn_fieldlist.name = main_fn_name;
1962
1963 do
1964 {
1965 new_sublist =
1966 (struct next_fnfield *) xmalloc (sizeof (struct next_fnfield));
1967 make_cleanup (free, new_sublist);
1968 memset (new_sublist, 0, sizeof (struct next_fnfield));
1969
1970 /* Check for and handle cretinous dbx symbol name continuation! */
1971 if (look_ahead_type == NULL)
1972 {
1973 /* Normal case. */
1974 STABS_CONTINUE (pp);
1975
1976 new_sublist -> fn_field.type = read_type (pp, objfile);
1977 if (**pp != ':')
1978 {
1979 /* Invalid symtab info for member function. */
1980 return 0;
1981 }
1982 }
1983 else
1984 {
1985 /* g++ version 1 kludge */
1986 new_sublist -> fn_field.type = look_ahead_type;
1987 look_ahead_type = NULL;
1988 }
1989
1990 (*pp)++;
1991 p = *pp;
1992 while (*p != ';')
1993 {
1994 p++;
1995 }
1996
1997 /* If this is just a stub, then we don't have the real name here. */
1998
1999 if (TYPE_FLAGS (new_sublist -> fn_field.type) & TYPE_FLAG_STUB)
2000 {
2001 if (!TYPE_DOMAIN_TYPE (new_sublist -> fn_field.type))
2002 TYPE_DOMAIN_TYPE (new_sublist -> fn_field.type) = type;
2003 new_sublist -> fn_field.is_stub = 1;
2004 }
2005 new_sublist -> fn_field.physname = savestring (*pp, p - *pp);
2006 *pp = p + 1;
2007
2008 /* Set this member function's visibility fields. */
2009 switch (*(*pp)++)
2010 {
2011 case VISIBILITY_PRIVATE:
2012 new_sublist -> fn_field.is_private = 1;
2013 break;
2014 case VISIBILITY_PROTECTED:
2015 new_sublist -> fn_field.is_protected = 1;
2016 break;
2017 }
2018
2019 STABS_CONTINUE (pp);
2020 switch (**pp)
2021 {
2022 case 'A': /* Normal functions. */
2023 new_sublist -> fn_field.is_const = 0;
2024 new_sublist -> fn_field.is_volatile = 0;
2025 (*pp)++;
2026 break;
2027 case 'B': /* `const' member functions. */
2028 new_sublist -> fn_field.is_const = 1;
2029 new_sublist -> fn_field.is_volatile = 0;
2030 (*pp)++;
2031 break;
2032 case 'C': /* `volatile' member function. */
2033 new_sublist -> fn_field.is_const = 0;
2034 new_sublist -> fn_field.is_volatile = 1;
2035 (*pp)++;
2036 break;
2037 case 'D': /* `const volatile' member function. */
2038 new_sublist -> fn_field.is_const = 1;
2039 new_sublist -> fn_field.is_volatile = 1;
2040 (*pp)++;
2041 break;
2042 case '*': /* File compiled with g++ version 1 -- no info */
2043 case '?':
2044 case '.':
2045 break;
2046 default:
2047 complain (&const_vol_complaint, **pp);
2048 break;
2049 }
2050
2051 switch (*(*pp)++)
2052 {
2053 case '*':
2054 {
2055 int nbits;
2056 /* virtual member function, followed by index.
2057 The sign bit is set to distinguish pointers-to-methods
2058 from virtual function indicies. Since the array is
2059 in words, the quantity must be shifted left by 1
2060 on 16 bit machine, and by 2 on 32 bit machine, forcing
2061 the sign bit out, and usable as a valid index into
2062 the array. Remove the sign bit here. */
2063 new_sublist -> fn_field.voffset =
2064 (0x7fffffff & read_huge_number (pp, ';', &nbits)) + 2;
2065 if (nbits != 0)
2066 return 0;
2067
2068 STABS_CONTINUE (pp);
2069 if (**pp == ';' || **pp == '\0')
2070 {
2071 /* Must be g++ version 1. */
2072 new_sublist -> fn_field.fcontext = 0;
2073 }
2074 else
2075 {
2076 /* Figure out from whence this virtual function came.
2077 It may belong to virtual function table of
2078 one of its baseclasses. */
2079 look_ahead_type = read_type (pp, objfile);
2080 if (**pp == ':')
2081 {
2082 /* g++ version 1 overloaded methods. */
2083 }
2084 else
2085 {
2086 new_sublist -> fn_field.fcontext = look_ahead_type;
2087 if (**pp != ';')
2088 {
2089 return 0;
2090 }
2091 else
2092 {
2093 ++*pp;
2094 }
2095 look_ahead_type = NULL;
2096 }
2097 }
2098 break;
2099 }
2100 case '?':
2101 /* static member function. */
2102 new_sublist -> fn_field.voffset = VOFFSET_STATIC;
2103 if (strncmp (new_sublist -> fn_field.physname,
2104 main_fn_name, strlen (main_fn_name)))
2105 {
2106 new_sublist -> fn_field.is_stub = 1;
2107 }
2108 break;
2109
2110 default:
2111 /* error */
2112 complain (&member_fn_complaint, (*pp)[-1]);
2113 /* Fall through into normal member function. */
2114
2115 case '.':
2116 /* normal member function. */
2117 new_sublist -> fn_field.voffset = 0;
2118 new_sublist -> fn_field.fcontext = 0;
2119 break;
2120 }
2121
2122 new_sublist -> next = sublist;
2123 sublist = new_sublist;
2124 length++;
2125 STABS_CONTINUE (pp);
2126 }
2127 while (**pp != ';' && **pp != '\0');
2128
2129 (*pp)++;
2130
2131 new_fnlist -> fn_fieldlist.fn_fields = (struct fn_field *)
2132 obstack_alloc (&objfile -> type_obstack,
2133 sizeof (struct fn_field) * length);
2134 memset (new_fnlist -> fn_fieldlist.fn_fields, 0,
2135 sizeof (struct fn_field) * length);
2136 for (i = length; (i--, sublist); sublist = sublist -> next)
2137 {
2138 new_fnlist -> fn_fieldlist.fn_fields[i] = sublist -> fn_field;
2139 }
2140
2141 new_fnlist -> fn_fieldlist.length = length;
2142 new_fnlist -> next = fip -> fnlist;
2143 fip -> fnlist = new_fnlist;
2144 nfn_fields++;
2145 total_length += length;
2146 STABS_CONTINUE (pp);
2147 }
2148
2149 if (nfn_fields)
2150 {
2151 ALLOCATE_CPLUS_STRUCT_TYPE (type);
2152 TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
2153 TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * nfn_fields);
2154 memset (TYPE_FN_FIELDLISTS (type), 0,
2155 sizeof (struct fn_fieldlist) * nfn_fields);
2156 TYPE_NFN_FIELDS (type) = nfn_fields;
2157 TYPE_NFN_FIELDS_TOTAL (type) = total_length;
2158 }
2159
2160 return 1;
2161 }
2162
2163 /* Special GNU C++ name.
2164
2165 Returns 1 for success, 0 for failure. "failure" means that we can't
2166 keep parsing and it's time for error_type(). */
2167
2168 static int
2169 read_cpp_abbrev (fip, pp, type, objfile)
2170 struct field_info *fip;
2171 char **pp;
2172 struct type *type;
2173 struct objfile *objfile;
2174 {
2175 register char *p;
2176 char *name;
2177 char cpp_abbrev;
2178 struct type *context;
2179
2180 p = *pp;
2181 if (*++p == 'v')
2182 {
2183 name = NULL;
2184 cpp_abbrev = *++p;
2185
2186 *pp = p + 1;
2187
2188 /* At this point, *pp points to something like "22:23=*22...",
2189 where the type number before the ':' is the "context" and
2190 everything after is a regular type definition. Lookup the
2191 type, find it's name, and construct the field name. */
2192
2193 context = read_type (pp, objfile);
2194
2195 switch (cpp_abbrev)
2196 {
2197 case 'f': /* $vf -- a virtual function table pointer */
2198 fip->list->field.name =
2199 obconcat (&objfile->type_obstack, vptr_name, "", "");
2200 break;
2201
2202 case 'b': /* $vb -- a virtual bsomethingorother */
2203 name = type_name_no_tag (context);
2204 if (name == NULL)
2205 {
2206 complain (&invalid_cpp_type_complaint, symnum);
2207 name = "FOO";
2208 }
2209 fip->list->field.name =
2210 obconcat (&objfile->type_obstack, vb_name, name, "");
2211 break;
2212
2213 default:
2214 complain (&invalid_cpp_abbrev_complaint, *pp);
2215 fip->list->field.name =
2216 obconcat (&objfile->type_obstack,
2217 "INVALID_CPLUSPLUS_ABBREV", "", "");
2218 break;
2219 }
2220
2221 /* At this point, *pp points to the ':'. Skip it and read the
2222 field type. */
2223
2224 p = ++(*pp);
2225 if (p[-1] != ':')
2226 {
2227 complain (&invalid_cpp_abbrev_complaint, *pp);
2228 return 0;
2229 }
2230 fip->list->field.type = read_type (pp, objfile);
2231 if (**pp == ',')
2232 (*pp)++; /* Skip the comma. */
2233 else
2234 return 0;
2235
2236 {
2237 int nbits;
2238 fip->list->field.bitpos = read_huge_number (pp, ';', &nbits);
2239 if (nbits != 0)
2240 return 0;
2241 }
2242 /* This field is unpacked. */
2243 fip->list->field.bitsize = 0;
2244 fip->list->visibility = VISIBILITY_PRIVATE;
2245 }
2246 else
2247 {
2248 complain (&invalid_cpp_abbrev_complaint, *pp);
2249 /* We have no idea what syntax an unrecognized abbrev would have, so
2250 better return 0. If we returned 1, we would need to at least advance
2251 *pp to avoid an infinite loop. */
2252 return 0;
2253 }
2254 return 1;
2255 }
2256
2257 static void
2258 read_one_struct_field (fip, pp, p, type, objfile)
2259 struct field_info *fip;
2260 char **pp;
2261 char *p;
2262 struct type *type;
2263 struct objfile *objfile;
2264 {
2265 fip -> list -> field.name =
2266 obsavestring (*pp, p - *pp, &objfile -> type_obstack);
2267 *pp = p + 1;
2268
2269 /* This means we have a visibility for a field coming. */
2270 if (**pp == '/')
2271 {
2272 (*pp)++;
2273 fip -> list -> visibility = *(*pp)++;
2274 }
2275 else
2276 {
2277 /* normal dbx-style format, no explicit visibility */
2278 fip -> list -> visibility = VISIBILITY_PUBLIC;
2279 }
2280
2281 fip -> list -> field.type = read_type (pp, objfile);
2282 if (**pp == ':')
2283 {
2284 p = ++(*pp);
2285 #if 0
2286 /* Possible future hook for nested types. */
2287 if (**pp == '!')
2288 {
2289 fip -> list -> field.bitpos = (long)-2; /* nested type */
2290 p = ++(*pp);
2291 }
2292 else
2293 #endif
2294 {
2295 /* Static class member. */
2296 fip -> list -> field.bitpos = (long) -1;
2297 }
2298 while (*p != ';')
2299 {
2300 p++;
2301 }
2302 fip -> list -> field.bitsize = (long) savestring (*pp, p - *pp);
2303 *pp = p + 1;
2304 return;
2305 }
2306 else if (**pp != ',')
2307 {
2308 /* Bad structure-type format. */
2309 complain (&stabs_general_complaint, "bad structure-type format");
2310 return;
2311 }
2312
2313 (*pp)++; /* Skip the comma. */
2314
2315 {
2316 int nbits;
2317 fip -> list -> field.bitpos = read_huge_number (pp, ',', &nbits);
2318 if (nbits != 0)
2319 {
2320 complain (&stabs_general_complaint, "bad structure-type format");
2321 return;
2322 }
2323 fip -> list -> field.bitsize = read_huge_number (pp, ';', &nbits);
2324 if (nbits != 0)
2325 {
2326 complain (&stabs_general_complaint, "bad structure-type format");
2327 return;
2328 }
2329 }
2330
2331 if (fip -> list -> field.bitpos == 0 && fip -> list -> field.bitsize == 0)
2332 {
2333 /* This can happen in two cases: (1) at least for gcc 2.4.5 or so,
2334 it is a field which has been optimized out. The correct stab for
2335 this case is to use VISIBILITY_IGNORE, but that is a recent
2336 invention. (2) It is a 0-size array. For example
2337 union { int num; char str[0]; } foo. Printing "<no value>" for
2338 str in "p foo" is OK, since foo.str (and thus foo.str[3])
2339 will continue to work, and a 0-size array as a whole doesn't
2340 have any contents to print.
2341
2342 I suspect this probably could also happen with gcc -gstabs (not
2343 -gstabs+) for static fields, and perhaps other C++ extensions.
2344 Hopefully few people use -gstabs with gdb, since it is intended
2345 for dbx compatibility. */
2346
2347 /* Ignore this field. */
2348 fip -> list-> visibility = VISIBILITY_IGNORE;
2349 }
2350 else
2351 {
2352 /* Detect an unpacked field and mark it as such.
2353 dbx gives a bit size for all fields.
2354 Note that forward refs cannot be packed,
2355 and treat enums as if they had the width of ints. */
2356
2357 if (TYPE_CODE (fip -> list -> field.type) != TYPE_CODE_INT
2358 && TYPE_CODE (fip -> list -> field.type) != TYPE_CODE_ENUM)
2359 {
2360 fip -> list -> field.bitsize = 0;
2361 }
2362 if ((fip -> list -> field.bitsize
2363 == TARGET_CHAR_BIT * TYPE_LENGTH (fip -> list -> field.type)
2364 || (TYPE_CODE (fip -> list -> field.type) == TYPE_CODE_ENUM
2365 && (fip -> list -> field.bitsize
2366 == TARGET_INT_BIT)
2367 )
2368 )
2369 &&
2370 fip -> list -> field.bitpos % 8 == 0)
2371 {
2372 fip -> list -> field.bitsize = 0;
2373 }
2374 }
2375 }
2376
2377
2378 /* Read struct or class data fields. They have the form:
2379
2380 NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
2381
2382 At the end, we see a semicolon instead of a field.
2383
2384 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
2385 a static field.
2386
2387 The optional VISIBILITY is one of:
2388
2389 '/0' (VISIBILITY_PRIVATE)
2390 '/1' (VISIBILITY_PROTECTED)
2391 '/2' (VISIBILITY_PUBLIC)
2392 '/9' (VISIBILITY_IGNORE)
2393
2394 or nothing, for C style fields with public visibility.
2395
2396 Returns 1 for success, 0 for failure. */
2397
2398 static int
2399 read_struct_fields (fip, pp, type, objfile)
2400 struct field_info *fip;
2401 char **pp;
2402 struct type *type;
2403 struct objfile *objfile;
2404 {
2405 register char *p;
2406 struct nextfield *new;
2407
2408 /* We better set p right now, in case there are no fields at all... */
2409
2410 p = *pp;
2411
2412 /* Read each data member type until we find the terminating ';' at the end of
2413 the data member list, or break for some other reason such as finding the
2414 start of the member function list. */
2415
2416 while (**pp != ';')
2417 {
2418 STABS_CONTINUE (pp);
2419 /* Get space to record the next field's data. */
2420 new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
2421 make_cleanup (free, new);
2422 memset (new, 0, sizeof (struct nextfield));
2423 new -> next = fip -> list;
2424 fip -> list = new;
2425
2426 /* Get the field name. */
2427 p = *pp;
2428
2429 /* If is starts with CPLUS_MARKER it is a special abbreviation,
2430 unless the CPLUS_MARKER is followed by an underscore, in
2431 which case it is just the name of an anonymous type, which we
2432 should handle like any other type name. We accept either '$'
2433 or '.', because a field name can never contain one of these
2434 characters except as a CPLUS_MARKER (we probably should be
2435 doing that in most parts of GDB). */
2436
2437 if ((*p == '$' || *p == '.') && p[1] != '_')
2438 {
2439 if (!read_cpp_abbrev (fip, pp, type, objfile))
2440 return 0;
2441 continue;
2442 }
2443
2444 /* Look for the ':' that separates the field name from the field
2445 values. Data members are delimited by a single ':', while member
2446 functions are delimited by a pair of ':'s. When we hit the member
2447 functions (if any), terminate scan loop and return. */
2448
2449 while (*p != ':' && *p != '\0')
2450 {
2451 p++;
2452 }
2453 if (*p == '\0')
2454 return 0;
2455
2456 /* Check to see if we have hit the member functions yet. */
2457 if (p[1] == ':')
2458 {
2459 break;
2460 }
2461 read_one_struct_field (fip, pp, p, type, objfile);
2462 }
2463 if (p[0] == ':' && p[1] == ':')
2464 {
2465 /* chill the list of fields: the last entry (at the head) is a
2466 partially constructed entry which we now scrub. */
2467 fip -> list = fip -> list -> next;
2468 }
2469 return 1;
2470 }
2471
2472 /* The stabs for C++ derived classes contain baseclass information which
2473 is marked by a '!' character after the total size. This function is
2474 called when we encounter the baseclass marker, and slurps up all the
2475 baseclass information.
2476
2477 Immediately following the '!' marker is the number of base classes that
2478 the class is derived from, followed by information for each base class.
2479 For each base class, there are two visibility specifiers, a bit offset
2480 to the base class information within the derived class, a reference to
2481 the type for the base class, and a terminating semicolon.
2482
2483 A typical example, with two base classes, would be "!2,020,19;0264,21;".
2484 ^^ ^ ^ ^ ^ ^ ^
2485 Baseclass information marker __________________|| | | | | | |
2486 Number of baseclasses __________________________| | | | | | |
2487 Visibility specifiers (2) ________________________| | | | | |
2488 Offset in bits from start of class _________________| | | | |
2489 Type number for base class ___________________________| | | |
2490 Visibility specifiers (2) _______________________________| | |
2491 Offset in bits from start of class ________________________| |
2492 Type number of base class ____________________________________|
2493
2494 Return 1 for success, 0 for (error-type-inducing) failure. */
2495
2496 static int
2497 read_baseclasses (fip, pp, type, objfile)
2498 struct field_info *fip;
2499 char **pp;
2500 struct type *type;
2501 struct objfile *objfile;
2502 {
2503 int i;
2504 struct nextfield *new;
2505
2506 if (**pp != '!')
2507 {
2508 return 1;
2509 }
2510 else
2511 {
2512 /* Skip the '!' baseclass information marker. */
2513 (*pp)++;
2514 }
2515
2516 ALLOCATE_CPLUS_STRUCT_TYPE (type);
2517 {
2518 int nbits;
2519 TYPE_N_BASECLASSES (type) = read_huge_number (pp, ',', &nbits);
2520 if (nbits != 0)
2521 return 0;
2522 }
2523
2524 #if 0
2525 /* Some stupid compilers have trouble with the following, so break
2526 it up into simpler expressions. */
2527 TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *)
2528 TYPE_ALLOC (type, B_BYTES (TYPE_N_BASECLASSES (type)));
2529 #else
2530 {
2531 int num_bytes = B_BYTES (TYPE_N_BASECLASSES (type));
2532 char *pointer;
2533
2534 pointer = (char *) TYPE_ALLOC (type, num_bytes);
2535 TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *) pointer;
2536 }
2537 #endif /* 0 */
2538
2539 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), TYPE_N_BASECLASSES (type));
2540
2541 for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
2542 {
2543 new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
2544 make_cleanup (free, new);
2545 memset (new, 0, sizeof (struct nextfield));
2546 new -> next = fip -> list;
2547 fip -> list = new;
2548 new -> field.bitsize = 0; /* this should be an unpacked field! */
2549
2550 STABS_CONTINUE (pp);
2551 switch (**pp)
2552 {
2553 case '0':
2554 /* Nothing to do. */
2555 break;
2556 case '1':
2557 SET_TYPE_FIELD_VIRTUAL (type, i);
2558 break;
2559 default:
2560 /* Unknown character. Complain and treat it as non-virtual. */
2561 {
2562 static struct complaint msg = {
2563 "Unknown virtual character `%c' for baseclass", 0, 0};
2564 complain (&msg, **pp);
2565 }
2566 }
2567 ++(*pp);
2568
2569 new -> visibility = *(*pp)++;
2570 switch (new -> visibility)
2571 {
2572 case VISIBILITY_PRIVATE:
2573 case VISIBILITY_PROTECTED:
2574 case VISIBILITY_PUBLIC:
2575 break;
2576 default:
2577 /* Bad visibility format. Complain and treat it as
2578 public. */
2579 {
2580 static struct complaint msg = {
2581 "Unknown visibility `%c' for baseclass", 0, 0};
2582 complain (&msg, new -> visibility);
2583 new -> visibility = VISIBILITY_PUBLIC;
2584 }
2585 }
2586
2587 {
2588 int nbits;
2589
2590 /* The remaining value is the bit offset of the portion of the object
2591 corresponding to this baseclass. Always zero in the absence of
2592 multiple inheritance. */
2593
2594 new -> field.bitpos = read_huge_number (pp, ',', &nbits);
2595 if (nbits != 0)
2596 return 0;
2597 }
2598
2599 /* The last piece of baseclass information is the type of the
2600 base class. Read it, and remember it's type name as this
2601 field's name. */
2602
2603 new -> field.type = read_type (pp, objfile);
2604 new -> field.name = type_name_no_tag (new -> field.type);
2605
2606 /* skip trailing ';' and bump count of number of fields seen */
2607 if (**pp == ';')
2608 (*pp)++;
2609 else
2610 return 0;
2611 }
2612 return 1;
2613 }
2614
2615 /* The tail end of stabs for C++ classes that contain a virtual function
2616 pointer contains a tilde, a %, and a type number.
2617 The type number refers to the base class (possibly this class itself) which
2618 contains the vtable pointer for the current class.
2619
2620 This function is called when we have parsed all the method declarations,
2621 so we can look for the vptr base class info. */
2622
2623 static int
2624 read_tilde_fields (fip, pp, type, objfile)
2625 struct field_info *fip;
2626 char **pp;
2627 struct type *type;
2628 struct objfile *objfile;
2629 {
2630 register char *p;
2631
2632 STABS_CONTINUE (pp);
2633
2634 /* If we are positioned at a ';', then skip it. */
2635 if (**pp == ';')
2636 {
2637 (*pp)++;
2638 }
2639
2640 if (**pp == '~')
2641 {
2642 (*pp)++;
2643
2644 if (**pp == '=' || **pp == '+' || **pp == '-')
2645 {
2646 /* Obsolete flags that used to indicate the presence
2647 of constructors and/or destructors. */
2648 (*pp)++;
2649 }
2650
2651 /* Read either a '%' or the final ';'. */
2652 if (*(*pp)++ == '%')
2653 {
2654 /* The next number is the type number of the base class
2655 (possibly our own class) which supplies the vtable for
2656 this class. Parse it out, and search that class to find
2657 its vtable pointer, and install those into TYPE_VPTR_BASETYPE
2658 and TYPE_VPTR_FIELDNO. */
2659
2660 struct type *t;
2661 int i;
2662
2663 t = read_type (pp, objfile);
2664 p = (*pp)++;
2665 while (*p != '\0' && *p != ';')
2666 {
2667 p++;
2668 }
2669 if (*p == '\0')
2670 {
2671 /* Premature end of symbol. */
2672 return 0;
2673 }
2674
2675 TYPE_VPTR_BASETYPE (type) = t;
2676 if (type == t) /* Our own class provides vtbl ptr */
2677 {
2678 for (i = TYPE_NFIELDS (t) - 1;
2679 i >= TYPE_N_BASECLASSES (t);
2680 --i)
2681 {
2682 if (! strncmp (TYPE_FIELD_NAME (t, i), vptr_name,
2683 sizeof (vptr_name) - 1))
2684 {
2685 TYPE_VPTR_FIELDNO (type) = i;
2686 goto gotit;
2687 }
2688 }
2689 /* Virtual function table field not found. */
2690 complain (&vtbl_notfound_complaint, TYPE_NAME (type));
2691 return 0;
2692 }
2693 else
2694 {
2695 TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t);
2696 }
2697
2698 gotit:
2699 *pp = p + 1;
2700 }
2701 }
2702 return 1;
2703 }
2704
2705 static int
2706 attach_fn_fields_to_type (fip, type)
2707 struct field_info *fip;
2708 register struct type *type;
2709 {
2710 register int n;
2711
2712 for (n = 0; n < TYPE_N_BASECLASSES (type); n++)
2713 {
2714 if (TYPE_CODE (TYPE_BASECLASS (type, n)) == TYPE_CODE_UNDEF)
2715 {
2716 /* @@ Memory leak on objfile -> type_obstack? */
2717 return 0;
2718 }
2719 TYPE_NFN_FIELDS_TOTAL (type) +=
2720 TYPE_NFN_FIELDS_TOTAL (TYPE_BASECLASS (type, n));
2721 }
2722
2723 for (n = TYPE_NFN_FIELDS (type);
2724 fip -> fnlist != NULL;
2725 fip -> fnlist = fip -> fnlist -> next)
2726 {
2727 --n; /* Circumvent Sun3 compiler bug */
2728 TYPE_FN_FIELDLISTS (type)[n] = fip -> fnlist -> fn_fieldlist;
2729 }
2730 return 1;
2731 }
2732
2733 /* Create the vector of fields, and record how big it is.
2734 We need this info to record proper virtual function table information
2735 for this class's virtual functions. */
2736
2737 static int
2738 attach_fields_to_type (fip, type, objfile)
2739 struct field_info *fip;
2740 register struct type *type;
2741 struct objfile *objfile;
2742 {
2743 register int nfields = 0;
2744 register int non_public_fields = 0;
2745 register struct nextfield *scan;
2746
2747 /* Count up the number of fields that we have, as well as taking note of
2748 whether or not there are any non-public fields, which requires us to
2749 allocate and build the private_field_bits and protected_field_bits
2750 bitfields. */
2751
2752 for (scan = fip -> list; scan != NULL; scan = scan -> next)
2753 {
2754 nfields++;
2755 if (scan -> visibility != VISIBILITY_PUBLIC)
2756 {
2757 non_public_fields++;
2758 }
2759 }
2760
2761 /* Now we know how many fields there are, and whether or not there are any
2762 non-public fields. Record the field count, allocate space for the
2763 array of fields, and create blank visibility bitfields if necessary. */
2764
2765 TYPE_NFIELDS (type) = nfields;
2766 TYPE_FIELDS (type) = (struct field *)
2767 TYPE_ALLOC (type, sizeof (struct field) * nfields);
2768 memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields);
2769
2770 if (non_public_fields)
2771 {
2772 ALLOCATE_CPLUS_STRUCT_TYPE (type);
2773
2774 TYPE_FIELD_PRIVATE_BITS (type) =
2775 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
2776 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
2777
2778 TYPE_FIELD_PROTECTED_BITS (type) =
2779 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
2780 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
2781
2782 TYPE_FIELD_IGNORE_BITS (type) =
2783 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
2784 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields);
2785 }
2786
2787 /* Copy the saved-up fields into the field vector. Start from the head
2788 of the list, adding to the tail of the field array, so that they end
2789 up in the same order in the array in which they were added to the list. */
2790
2791 while (nfields-- > 0)
2792 {
2793 TYPE_FIELD (type, nfields) = fip -> list -> field;
2794 switch (fip -> list -> visibility)
2795 {
2796 case VISIBILITY_PRIVATE:
2797 SET_TYPE_FIELD_PRIVATE (type, nfields);
2798 break;
2799
2800 case VISIBILITY_PROTECTED:
2801 SET_TYPE_FIELD_PROTECTED (type, nfields);
2802 break;
2803
2804 case VISIBILITY_IGNORE:
2805 SET_TYPE_FIELD_IGNORE (type, nfields);
2806 break;
2807
2808 case VISIBILITY_PUBLIC:
2809 break;
2810
2811 default:
2812 /* Unknown visibility. Complain and treat it as public. */
2813 {
2814 static struct complaint msg = {
2815 "Unknown visibility `%c' for field", 0, 0};
2816 complain (&msg, fip -> list -> visibility);
2817 }
2818 break;
2819 }
2820 fip -> list = fip -> list -> next;
2821 }
2822 return 1;
2823 }
2824
2825 /* Read the description of a structure (or union type) and return an object
2826 describing the type.
2827
2828 PP points to a character pointer that points to the next unconsumed token
2829 in the the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
2830 *PP will point to "4a:1,0,32;;".
2831
2832 TYPE points to an incomplete type that needs to be filled in.
2833
2834 OBJFILE points to the current objfile from which the stabs information is
2835 being read. (Note that it is redundant in that TYPE also contains a pointer
2836 to this same objfile, so it might be a good idea to eliminate it. FIXME).
2837 */
2838
2839 static struct type *
2840 read_struct_type (pp, type, objfile)
2841 char **pp;
2842 struct type *type;
2843 struct objfile *objfile;
2844 {
2845 struct cleanup *back_to;
2846 struct field_info fi;
2847
2848 fi.list = NULL;
2849 fi.fnlist = NULL;
2850
2851 back_to = make_cleanup (null_cleanup, 0);
2852
2853 INIT_CPLUS_SPECIFIC (type);
2854 TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
2855
2856 /* First comes the total size in bytes. */
2857
2858 {
2859 int nbits;
2860 TYPE_LENGTH (type) = read_huge_number (pp, 0, &nbits);
2861 if (nbits != 0)
2862 return error_type (pp);
2863 }
2864
2865 /* Now read the baseclasses, if any, read the regular C struct or C++
2866 class member fields, attach the fields to the type, read the C++
2867 member functions, attach them to the type, and then read any tilde
2868 field (baseclass specifier for the class holding the main vtable). */
2869
2870 if (!read_baseclasses (&fi, pp, type, objfile)
2871 || !read_struct_fields (&fi, pp, type, objfile)
2872 || !attach_fields_to_type (&fi, type, objfile)
2873 || !read_member_functions (&fi, pp, type, objfile)
2874 || !attach_fn_fields_to_type (&fi, type)
2875 || !read_tilde_fields (&fi, pp, type, objfile))
2876 {
2877 do_cleanups (back_to);
2878 return (error_type (pp));
2879 }
2880
2881 do_cleanups (back_to);
2882 return (type);
2883 }
2884
2885 /* Read a definition of an array type,
2886 and create and return a suitable type object.
2887 Also creates a range type which represents the bounds of that
2888 array. */
2889
2890 static struct type *
2891 read_array_type (pp, type, objfile)
2892 register char **pp;
2893 register struct type *type;
2894 struct objfile *objfile;
2895 {
2896 struct type *index_type, *element_type, *range_type;
2897 int lower, upper;
2898 int adjustable = 0;
2899 int nbits;
2900
2901 /* Format of an array type:
2902 "ar<index type>;lower;upper;<array_contents_type>".
2903 OS9000: "arlower,upper;<array_contents_type>".
2904
2905 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
2906 for these, produce a type like float[][]. */
2907
2908 if (os9k_stabs)
2909 index_type = builtin_type_int;
2910 else
2911 {
2912 index_type = read_type (pp, objfile);
2913 if (**pp != ';')
2914 /* Improper format of array type decl. */
2915 return error_type (pp);
2916 ++*pp;
2917 }
2918
2919 if (!(**pp >= '0' && **pp <= '9') && **pp != '-')
2920 {
2921 (*pp)++;
2922 adjustable = 1;
2923 }
2924 lower = read_huge_number (pp, os9k_stabs ? ',' : ';', &nbits);
2925 if (nbits != 0)
2926 return error_type (pp);
2927
2928 if (!(**pp >= '0' && **pp <= '9') && **pp != '-')
2929 {
2930 (*pp)++;
2931 adjustable = 1;
2932 }
2933 upper = read_huge_number (pp, ';', &nbits);
2934 if (nbits != 0)
2935 return error_type (pp);
2936
2937 element_type = read_type (pp, objfile);
2938
2939 if (adjustable)
2940 {
2941 lower = 0;
2942 upper = -1;
2943 }
2944
2945 range_type =
2946 create_range_type ((struct type *) NULL, index_type, lower, upper);
2947 type = create_array_type (type, element_type, range_type);
2948
2949 /* If we have an array whose element type is not yet known, but whose
2950 bounds *are* known, record it to be adjusted at the end of the file. */
2951 /* FIXME: Why check for zero length rather than TYPE_FLAG_STUB? I think
2952 the two have the same effect except that the latter is cleaner and the
2953 former would be wrong for types which really are zero-length (if we
2954 have any). */
2955
2956 if (TYPE_LENGTH (element_type) == 0 && !adjustable)
2957 {
2958 TYPE_FLAGS (type) |= TYPE_FLAG_TARGET_STUB;
2959 add_undefined_type (type);
2960 }
2961
2962 return type;
2963 }
2964
2965
2966 /* Read a definition of an enumeration type,
2967 and create and return a suitable type object.
2968 Also defines the symbols that represent the values of the type. */
2969
2970 static struct type *
2971 read_enum_type (pp, type, objfile)
2972 register char **pp;
2973 register struct type *type;
2974 struct objfile *objfile;
2975 {
2976 register char *p;
2977 char *name;
2978 register long n;
2979 register struct symbol *sym;
2980 int nsyms = 0;
2981 struct pending **symlist;
2982 struct pending *osyms, *syms;
2983 int o_nsyms;
2984 int nbits;
2985
2986 #if 0
2987 /* FIXME! The stabs produced by Sun CC merrily define things that ought
2988 to be file-scope, between N_FN entries, using N_LSYM. What's a mother
2989 to do? For now, force all enum values to file scope. */
2990 if (within_function)
2991 symlist = &local_symbols;
2992 else
2993 #endif
2994 symlist = &file_symbols;
2995 osyms = *symlist;
2996 o_nsyms = osyms ? osyms->nsyms : 0;
2997
2998 if (os9k_stabs)
2999 {
3000 /* Size. Perhaps this does not have to be conditionalized on
3001 os9k_stabs (assuming the name of an enum constant can't start
3002 with a digit). */
3003 read_huge_number (pp, 0, &nbits);
3004 if (nbits != 0)
3005 return error_type (pp);
3006 }
3007
3008 /* Read the value-names and their values.
3009 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
3010 A semicolon or comma instead of a NAME means the end. */
3011 while (**pp && **pp != ';' && **pp != ',')
3012 {
3013 STABS_CONTINUE (pp);
3014 p = *pp;
3015 while (*p != ':') p++;
3016 name = obsavestring (*pp, p - *pp, &objfile -> symbol_obstack);
3017 *pp = p + 1;
3018 n = read_huge_number (pp, ',', &nbits);
3019 if (nbits != 0)
3020 return error_type (pp);
3021
3022 sym = (struct symbol *)
3023 obstack_alloc (&objfile -> symbol_obstack, sizeof (struct symbol));
3024 memset (sym, 0, sizeof (struct symbol));
3025 SYMBOL_NAME (sym) = name;
3026 SYMBOL_LANGUAGE (sym) = current_subfile -> language;
3027 SYMBOL_CLASS (sym) = LOC_CONST;
3028 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
3029 SYMBOL_VALUE (sym) = n;
3030 add_symbol_to_list (sym, symlist);
3031 nsyms++;
3032 }
3033
3034 if (**pp == ';')
3035 (*pp)++; /* Skip the semicolon. */
3036
3037 /* Now fill in the fields of the type-structure. */
3038
3039 TYPE_LENGTH (type) = TARGET_INT_BIT / HOST_CHAR_BIT;
3040 TYPE_CODE (type) = TYPE_CODE_ENUM;
3041 TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
3042 TYPE_NFIELDS (type) = nsyms;
3043 TYPE_FIELDS (type) = (struct field *)
3044 TYPE_ALLOC (type, sizeof (struct field) * nsyms);
3045 memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nsyms);
3046
3047 /* Find the symbols for the values and put them into the type.
3048 The symbols can be found in the symlist that we put them on
3049 to cause them to be defined. osyms contains the old value
3050 of that symlist; everything up to there was defined by us. */
3051 /* Note that we preserve the order of the enum constants, so
3052 that in something like "enum {FOO, LAST_THING=FOO}" we print
3053 FOO, not LAST_THING. */
3054
3055 for (syms = *symlist, n = 0; syms; syms = syms->next)
3056 {
3057 int j = 0;
3058 if (syms == osyms)
3059 j = o_nsyms;
3060 for (; j < syms->nsyms; j++,n++)
3061 {
3062 struct symbol *xsym = syms->symbol[j];
3063 SYMBOL_TYPE (xsym) = type;
3064 TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym);
3065 TYPE_FIELD_VALUE (type, n) = 0;
3066 TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (xsym);
3067 TYPE_FIELD_BITSIZE (type, n) = 0;
3068 }
3069 if (syms == osyms)
3070 break;
3071 }
3072
3073 return type;
3074 }
3075
3076 /* Sun's ACC uses a somewhat saner method for specifying the builtin
3077 typedefs in every file (for int, long, etc):
3078
3079 type = b <signed> <width>; <offset>; <nbits>
3080 signed = u or s. Possible c in addition to u or s (for char?).
3081 offset = offset from high order bit to start bit of type.
3082 width is # bytes in object of this type, nbits is # bits in type.
3083
3084 The width/offset stuff appears to be for small objects stored in
3085 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
3086 FIXME. */
3087
3088 static struct type *
3089 read_sun_builtin_type (pp, typenums, objfile)
3090 char **pp;
3091 int typenums[2];
3092 struct objfile *objfile;
3093 {
3094 int type_bits;
3095 int nbits;
3096 int signed_type;
3097
3098 switch (**pp)
3099 {
3100 case 's':
3101 signed_type = 1;
3102 break;
3103 case 'u':
3104 signed_type = 0;
3105 break;
3106 default:
3107 return error_type (pp);
3108 }
3109 (*pp)++;
3110
3111 /* For some odd reason, all forms of char put a c here. This is strange
3112 because no other type has this honor. We can safely ignore this because
3113 we actually determine 'char'acterness by the number of bits specified in
3114 the descriptor. */
3115
3116 if (**pp == 'c')
3117 (*pp)++;
3118
3119 /* The first number appears to be the number of bytes occupied
3120 by this type, except that unsigned short is 4 instead of 2.
3121 Since this information is redundant with the third number,
3122 we will ignore it. */
3123 read_huge_number (pp, ';', &nbits);
3124 if (nbits != 0)
3125 return error_type (pp);
3126
3127 /* The second number is always 0, so ignore it too. */
3128 read_huge_number (pp, ';', &nbits);
3129 if (nbits != 0)
3130 return error_type (pp);
3131
3132 /* The third number is the number of bits for this type. */
3133 type_bits = read_huge_number (pp, 0, &nbits);
3134 if (nbits != 0)
3135 return error_type (pp);
3136 /* The type *should* end with a semicolon. If it are embedded
3137 in a larger type the semicolon may be the only way to know where
3138 the type ends. If this type is at the end of the stabstring we
3139 can deal with the omitted semicolon (but we don't have to like
3140 it). Don't bother to complain(), Sun's compiler omits the semicolon
3141 for "void". */
3142 if (**pp == ';')
3143 ++(*pp);
3144
3145 return init_type (type_bits == 0 ? TYPE_CODE_VOID : TYPE_CODE_INT,
3146 type_bits / TARGET_CHAR_BIT,
3147 signed_type ? 0 : TYPE_FLAG_UNSIGNED, (char *)NULL,
3148 objfile);
3149 }
3150
3151 static struct type *
3152 read_sun_floating_type (pp, typenums, objfile)
3153 char **pp;
3154 int typenums[2];
3155 struct objfile *objfile;
3156 {
3157 int nbits;
3158 int details;
3159 int nbytes;
3160
3161 /* The first number has more details about the type, for example
3162 FN_COMPLEX. */
3163 details = read_huge_number (pp, ';', &nbits);
3164 if (nbits != 0)
3165 return error_type (pp);
3166
3167 /* The second number is the number of bytes occupied by this type */
3168 nbytes = read_huge_number (pp, ';', &nbits);
3169 if (nbits != 0)
3170 return error_type (pp);
3171
3172 if (details == NF_COMPLEX || details == NF_COMPLEX16
3173 || details == NF_COMPLEX32)
3174 /* This is a type we can't handle, but we do know the size.
3175 We also will be able to give it a name. */
3176 return init_type (TYPE_CODE_ERROR, nbytes, 0, NULL, objfile);
3177
3178 return init_type (TYPE_CODE_FLT, nbytes, 0, NULL, objfile);
3179 }
3180
3181 /* Read a number from the string pointed to by *PP.
3182 The value of *PP is advanced over the number.
3183 If END is nonzero, the character that ends the
3184 number must match END, or an error happens;
3185 and that character is skipped if it does match.
3186 If END is zero, *PP is left pointing to that character.
3187
3188 If the number fits in a long, set *BITS to 0 and return the value.
3189 If not, set *BITS to be the number of bits in the number and return 0.
3190
3191 If encounter garbage, set *BITS to -1 and return 0. */
3192
3193 static long
3194 read_huge_number (pp, end, bits)
3195 char **pp;
3196 int end;
3197 int *bits;
3198 {
3199 char *p = *pp;
3200 int sign = 1;
3201 long n = 0;
3202 int radix = 10;
3203 char overflow = 0;
3204 int nbits = 0;
3205 int c;
3206 long upper_limit;
3207
3208 if (*p == '-')
3209 {
3210 sign = -1;
3211 p++;
3212 }
3213
3214 /* Leading zero means octal. GCC uses this to output values larger
3215 than an int (because that would be hard in decimal). */
3216 if (*p == '0')
3217 {
3218 radix = 8;
3219 p++;
3220 }
3221
3222 upper_limit = LONG_MAX / radix;
3223 while ((c = *p++) >= '0' && c < ('0' + radix))
3224 {
3225 if (n <= upper_limit)
3226 {
3227 n *= radix;
3228 n += c - '0'; /* FIXME this overflows anyway */
3229 }
3230 else
3231 overflow = 1;
3232
3233 /* This depends on large values being output in octal, which is
3234 what GCC does. */
3235 if (radix == 8)
3236 {
3237 if (nbits == 0)
3238 {
3239 if (c == '0')
3240 /* Ignore leading zeroes. */
3241 ;
3242 else if (c == '1')
3243 nbits = 1;
3244 else if (c == '2' || c == '3')
3245 nbits = 2;
3246 else
3247 nbits = 3;
3248 }
3249 else
3250 nbits += 3;
3251 }
3252 }
3253 if (end)
3254 {
3255 if (c && c != end)
3256 {
3257 if (bits != NULL)
3258 *bits = -1;
3259 return 0;
3260 }
3261 }
3262 else
3263 --p;
3264
3265 *pp = p;
3266 if (overflow)
3267 {
3268 if (nbits == 0)
3269 {
3270 /* Large decimal constants are an error (because it is hard to
3271 count how many bits are in them). */
3272 if (bits != NULL)
3273 *bits = -1;
3274 return 0;
3275 }
3276
3277 /* -0x7f is the same as 0x80. So deal with it by adding one to
3278 the number of bits. */
3279 if (sign == -1)
3280 ++nbits;
3281 if (bits)
3282 *bits = nbits;
3283 }
3284 else
3285 {
3286 if (bits)
3287 *bits = 0;
3288 return n * sign;
3289 }
3290 /* It's *BITS which has the interesting information. */
3291 return 0;
3292 }
3293
3294 static struct type *
3295 read_range_type (pp, typenums, objfile)
3296 char **pp;
3297 int typenums[2];
3298 struct objfile *objfile;
3299 {
3300 int rangenums[2];
3301 long n2, n3;
3302 int n2bits, n3bits;
3303 int self_subrange;
3304 struct type *result_type;
3305 struct type *index_type;
3306
3307 /* First comes a type we are a subrange of.
3308 In C it is usually 0, 1 or the type being defined. */
3309 /* FIXME: according to stabs.texinfo and AIX doc, this can be a type-id
3310 not just a type number. */
3311 if (read_type_number (pp, rangenums) != 0)
3312 return error_type (pp);
3313 self_subrange = (rangenums[0] == typenums[0] &&
3314 rangenums[1] == typenums[1]);
3315
3316 /* A semicolon should now follow; skip it. */
3317 if (**pp == ';')
3318 (*pp)++;
3319
3320 /* The remaining two operands are usually lower and upper bounds
3321 of the range. But in some special cases they mean something else. */
3322 n2 = read_huge_number (pp, ';', &n2bits);
3323 n3 = read_huge_number (pp, ';', &n3bits);
3324
3325 if (n2bits == -1 || n3bits == -1)
3326 return error_type (pp);
3327
3328 /* If limits are huge, must be large integral type. */
3329 if (n2bits != 0 || n3bits != 0)
3330 {
3331 char got_signed = 0;
3332 char got_unsigned = 0;
3333 /* Number of bits in the type. */
3334 int nbits = 0;
3335
3336 /* Range from 0 to <large number> is an unsigned large integral type. */
3337 if ((n2bits == 0 && n2 == 0) && n3bits != 0)
3338 {
3339 got_unsigned = 1;
3340 nbits = n3bits;
3341 }
3342 /* Range from <large number> to <large number>-1 is a large signed
3343 integral type. Take care of the case where <large number> doesn't
3344 fit in a long but <large number>-1 does. */
3345 else if ((n2bits != 0 && n3bits != 0 && n2bits == n3bits + 1)
3346 || (n2bits != 0 && n3bits == 0
3347 && (n2bits == sizeof (long) * HOST_CHAR_BIT)
3348 && n3 == LONG_MAX))
3349 {
3350 got_signed = 1;
3351 nbits = n2bits;
3352 }
3353
3354 if (got_signed || got_unsigned)
3355 {
3356 return init_type (TYPE_CODE_INT, nbits / TARGET_CHAR_BIT,
3357 got_unsigned ? TYPE_FLAG_UNSIGNED : 0, NULL,
3358 objfile);
3359 }
3360 else
3361 return error_type (pp);
3362 }
3363
3364 /* A type defined as a subrange of itself, with bounds both 0, is void. */
3365 if (self_subrange && n2 == 0 && n3 == 0)
3366 return init_type (TYPE_CODE_VOID, 0, 0, NULL, objfile);
3367
3368 /* If n3 is zero and n2 is not, we want a floating type,
3369 and n2 is the width in bytes.
3370
3371 Fortran programs appear to use this for complex types also,
3372 and they give no way to distinguish between double and single-complex!
3373
3374 GDB does not have complex types.
3375
3376 Just return the complex as a float of that size. It won't work right
3377 for the complex values, but at least it makes the file loadable. */
3378
3379 if (n3 == 0 && n2 > 0)
3380 {
3381 return init_type (TYPE_CODE_FLT, n2, 0, NULL, objfile);
3382 }
3383
3384 /* If the upper bound is -1, it must really be an unsigned int. */
3385
3386 else if (n2 == 0 && n3 == -1)
3387 {
3388 /* It is unsigned int or unsigned long. */
3389 /* GCC 2.3.3 uses this for long long too, but that is just a GDB 3.5
3390 compatibility hack. */
3391 return init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
3392 TYPE_FLAG_UNSIGNED, NULL, objfile);
3393 }
3394
3395 /* Special case: char is defined (Who knows why) as a subrange of
3396 itself with range 0-127. */
3397 else if (self_subrange && n2 == 0 && n3 == 127)
3398 return init_type (TYPE_CODE_INT, 1, 0, NULL, objfile);
3399
3400 /* We used to do this only for subrange of self or subrange of int. */
3401 else if (n2 == 0)
3402 {
3403 if (n3 < 0)
3404 /* n3 actually gives the size. */
3405 return init_type (TYPE_CODE_INT, - n3, TYPE_FLAG_UNSIGNED,
3406 NULL, objfile);
3407 if (n3 == 0xff)
3408 return init_type (TYPE_CODE_INT, 1, TYPE_FLAG_UNSIGNED, NULL, objfile);
3409 if (n3 == 0xffff)
3410 return init_type (TYPE_CODE_INT, 2, TYPE_FLAG_UNSIGNED, NULL, objfile);
3411
3412 /* -1 is used for the upper bound of (4 byte) "unsigned int" and
3413 "unsigned long", and we already checked for that,
3414 so don't need to test for it here. */
3415 }
3416 /* I think this is for Convex "long long". Since I don't know whether
3417 Convex sets self_subrange, I also accept that particular size regardless
3418 of self_subrange. */
3419 else if (n3 == 0 && n2 < 0
3420 && (self_subrange
3421 || n2 == - TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT))
3422 return init_type (TYPE_CODE_INT, - n2, 0, NULL, objfile);
3423 else if (n2 == -n3 -1)
3424 {
3425 if (n3 == 0x7f)
3426 return init_type (TYPE_CODE_INT, 1, 0, NULL, objfile);
3427 if (n3 == 0x7fff)
3428 return init_type (TYPE_CODE_INT, 2, 0, NULL, objfile);
3429 if (n3 == 0x7fffffff)
3430 return init_type (TYPE_CODE_INT, 4, 0, NULL, objfile);
3431 }
3432
3433 /* We have a real range type on our hands. Allocate space and
3434 return a real pointer. */
3435
3436 /* At this point I don't have the faintest idea how to deal with
3437 a self_subrange type; I'm going to assume that this is used
3438 as an idiom, and that all of them are special cases. So . . . */
3439 if (self_subrange)
3440 return error_type (pp);
3441
3442 index_type = *dbx_lookup_type (rangenums);
3443 if (index_type == NULL)
3444 {
3445 /* Does this actually ever happen? Is that why we are worrying
3446 about dealing with it rather than just calling error_type? */
3447
3448 static struct type *range_type_index;
3449
3450 complain (&range_type_base_complaint, rangenums[1]);
3451 if (range_type_index == NULL)
3452 range_type_index =
3453 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
3454 0, "range type index type", NULL);
3455 index_type = range_type_index;
3456 }
3457
3458 result_type = create_range_type ((struct type *) NULL, index_type, n2, n3);
3459 return (result_type);
3460 }
3461
3462 /* Read in an argument list. This is a list of types, separated by commas
3463 and terminated with END. Return the list of types read in, or (struct type
3464 **)-1 if there is an error. */
3465
3466 static struct type **
3467 read_args (pp, end, objfile)
3468 char **pp;
3469 int end;
3470 struct objfile *objfile;
3471 {
3472 /* FIXME! Remove this arbitrary limit! */
3473 struct type *types[1024], **rval; /* allow for fns of 1023 parameters */
3474 int n = 0;
3475
3476 while (**pp != end)
3477 {
3478 if (**pp != ',')
3479 /* Invalid argument list: no ','. */
3480 return (struct type **)-1;
3481 (*pp)++;
3482 STABS_CONTINUE (pp);
3483 types[n++] = read_type (pp, objfile);
3484 }
3485 (*pp)++; /* get past `end' (the ':' character) */
3486
3487 if (n == 1)
3488 {
3489 rval = (struct type **) xmalloc (2 * sizeof (struct type *));
3490 }
3491 else if (TYPE_CODE (types[n-1]) != TYPE_CODE_VOID)
3492 {
3493 rval = (struct type **) xmalloc ((n + 1) * sizeof (struct type *));
3494 memset (rval + n, 0, sizeof (struct type *));
3495 }
3496 else
3497 {
3498 rval = (struct type **) xmalloc (n * sizeof (struct type *));
3499 }
3500 memcpy (rval, types, n * sizeof (struct type *));
3501 return rval;
3502 }
3503 \f
3504 /* Common block handling. */
3505
3506 /* List of symbols declared since the last BCOMM. This list is a tail
3507 of local_symbols. When ECOMM is seen, the symbols on the list
3508 are noted so their proper addresses can be filled in later,
3509 using the common block base address gotten from the assembler
3510 stabs. */
3511
3512 static struct pending *common_block;
3513 static int common_block_i;
3514
3515 /* Name of the current common block. We get it from the BCOMM instead of the
3516 ECOMM to match IBM documentation (even though IBM puts the name both places
3517 like everyone else). */
3518 static char *common_block_name;
3519
3520 /* Process a N_BCOMM symbol. The storage for NAME is not guaranteed
3521 to remain after this function returns. */
3522
3523 void
3524 common_block_start (name, objfile)
3525 char *name;
3526 struct objfile *objfile;
3527 {
3528 if (common_block_name != NULL)
3529 {
3530 static struct complaint msg = {
3531 "Invalid symbol data: common block within common block",
3532 0, 0};
3533 complain (&msg);
3534 }
3535 common_block = local_symbols;
3536 common_block_i = local_symbols ? local_symbols->nsyms : 0;
3537 common_block_name = obsavestring (name, strlen (name),
3538 &objfile -> symbol_obstack);
3539 }
3540
3541 /* Process a N_ECOMM symbol. */
3542
3543 void
3544 common_block_end (objfile)
3545 struct objfile *objfile;
3546 {
3547 /* Symbols declared since the BCOMM are to have the common block
3548 start address added in when we know it. common_block and
3549 common_block_i point to the first symbol after the BCOMM in
3550 the local_symbols list; copy the list and hang it off the
3551 symbol for the common block name for later fixup. */
3552 int i;
3553 struct symbol *sym;
3554 struct pending *new = 0;
3555 struct pending *next;
3556 int j;
3557
3558 if (common_block_name == NULL)
3559 {
3560 static struct complaint msg = {"ECOMM symbol unmatched by BCOMM", 0, 0};
3561 complain (&msg);
3562 return;
3563 }
3564
3565 sym = (struct symbol *)
3566 obstack_alloc (&objfile -> symbol_obstack, sizeof (struct symbol));
3567 memset (sym, 0, sizeof (struct symbol));
3568 SYMBOL_NAME (sym) = common_block_name;
3569 SYMBOL_CLASS (sym) = LOC_BLOCK;
3570
3571 /* Now we copy all the symbols which have been defined since the BCOMM. */
3572
3573 /* Copy all the struct pendings before common_block. */
3574 for (next = local_symbols;
3575 next != NULL && next != common_block;
3576 next = next->next)
3577 {
3578 for (j = 0; j < next->nsyms; j++)
3579 add_symbol_to_list (next->symbol[j], &new);
3580 }
3581
3582 /* Copy however much of COMMON_BLOCK we need. If COMMON_BLOCK is
3583 NULL, it means copy all the local symbols (which we already did
3584 above). */
3585
3586 if (common_block != NULL)
3587 for (j = common_block_i; j < common_block->nsyms; j++)
3588 add_symbol_to_list (common_block->symbol[j], &new);
3589
3590 SYMBOL_TYPE (sym) = (struct type *) new;
3591
3592 /* Should we be putting local_symbols back to what it was?
3593 Does it matter? */
3594
3595 i = hashname (SYMBOL_NAME (sym));
3596 SYMBOL_VALUE_CHAIN (sym) = global_sym_chain[i];
3597 global_sym_chain[i] = sym;
3598 common_block_name = NULL;
3599 }
3600
3601 /* Add a common block's start address to the offset of each symbol
3602 declared to be in it (by being between a BCOMM/ECOMM pair that uses
3603 the common block name). */
3604
3605 static void
3606 fix_common_block (sym, valu)
3607 struct symbol *sym;
3608 int valu;
3609 {
3610 struct pending *next = (struct pending *) SYMBOL_TYPE (sym);
3611 for ( ; next; next = next->next)
3612 {
3613 register int j;
3614 for (j = next->nsyms - 1; j >= 0; j--)
3615 SYMBOL_VALUE_ADDRESS (next->symbol[j]) += valu;
3616 }
3617 }
3618
3619
3620 \f
3621 /* What about types defined as forward references inside of a small lexical
3622 scope? */
3623 /* Add a type to the list of undefined types to be checked through
3624 once this file has been read in. */
3625
3626 void
3627 add_undefined_type (type)
3628 struct type *type;
3629 {
3630 if (undef_types_length == undef_types_allocated)
3631 {
3632 undef_types_allocated *= 2;
3633 undef_types = (struct type **)
3634 xrealloc ((char *) undef_types,
3635 undef_types_allocated * sizeof (struct type *));
3636 }
3637 undef_types[undef_types_length++] = type;
3638 }
3639
3640 /* Go through each undefined type, see if it's still undefined, and fix it
3641 up if possible. We have two kinds of undefined types:
3642
3643 TYPE_CODE_ARRAY: Array whose target type wasn't defined yet.
3644 Fix: update array length using the element bounds
3645 and the target type's length.
3646 TYPE_CODE_STRUCT, TYPE_CODE_UNION: Structure whose fields were not
3647 yet defined at the time a pointer to it was made.
3648 Fix: Do a full lookup on the struct/union tag. */
3649 void
3650 cleanup_undefined_types ()
3651 {
3652 struct type **type;
3653
3654 for (type = undef_types; type < undef_types + undef_types_length; type++)
3655 {
3656 switch (TYPE_CODE (*type))
3657 {
3658
3659 case TYPE_CODE_STRUCT:
3660 case TYPE_CODE_UNION:
3661 case TYPE_CODE_ENUM:
3662 {
3663 /* Check if it has been defined since. Need to do this here
3664 as well as in check_stub_type to deal with the (legitimate in
3665 C though not C++) case of several types with the same name
3666 in different source files. */
3667 if (TYPE_FLAGS (*type) & TYPE_FLAG_STUB)
3668 {
3669 struct pending *ppt;
3670 int i;
3671 /* Name of the type, without "struct" or "union" */
3672 char *typename = TYPE_TAG_NAME (*type);
3673
3674 if (typename == NULL)
3675 {
3676 static struct complaint msg = {"need a type name", 0, 0};
3677 complain (&msg);
3678 break;
3679 }
3680 for (ppt = file_symbols; ppt; ppt = ppt->next)
3681 {
3682 for (i = 0; i < ppt->nsyms; i++)
3683 {
3684 struct symbol *sym = ppt->symbol[i];
3685
3686 if (SYMBOL_CLASS (sym) == LOC_TYPEDEF
3687 && SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE
3688 && (TYPE_CODE (SYMBOL_TYPE (sym)) ==
3689 TYPE_CODE (*type))
3690 && STREQ (SYMBOL_NAME (sym), typename))
3691 {
3692 memcpy (*type, SYMBOL_TYPE (sym),
3693 sizeof (struct type));
3694 }
3695 }
3696 }
3697 }
3698 }
3699 break;
3700
3701 case TYPE_CODE_ARRAY:
3702 {
3703 /* This is a kludge which is here for historical reasons
3704 because I suspect that check_stub_type does not get
3705 called everywhere it needs to be called for arrays. Even
3706 with this kludge, those places are broken for the case
3707 where the stub type is defined in another compilation
3708 unit, but this kludge at least deals with it for the case
3709 in which it is the same compilation unit.
3710
3711 Don't try to do this by calling check_stub_type; it might
3712 cause symbols to be read in lookup_symbol, and the symbol
3713 reader is not reentrant. */
3714
3715 struct type *range_type;
3716 int lower, upper;
3717
3718 if (TYPE_LENGTH (*type) != 0) /* Better be unknown */
3719 goto badtype;
3720 if (TYPE_NFIELDS (*type) != 1)
3721 goto badtype;
3722 range_type = TYPE_FIELD_TYPE (*type, 0);
3723 if (TYPE_CODE (range_type) != TYPE_CODE_RANGE)
3724 goto badtype;
3725
3726 /* Now recompute the length of the array type, based on its
3727 number of elements and the target type's length. */
3728 lower = TYPE_FIELD_BITPOS (range_type, 0);
3729 upper = TYPE_FIELD_BITPOS (range_type, 1);
3730 TYPE_LENGTH (*type) = (upper - lower + 1)
3731 * TYPE_LENGTH (TYPE_TARGET_TYPE (*type));
3732
3733 /* If the target type is not a stub, we could be clearing
3734 TYPE_FLAG_TARGET_STUB for *type. */
3735 }
3736 break;
3737
3738 default:
3739 badtype:
3740 {
3741 static struct complaint msg = {"\
3742 GDB internal error. cleanup_undefined_types with bad type %d.", 0, 0};
3743 complain (&msg, TYPE_CODE (*type));
3744 }
3745 break;
3746 }
3747 }
3748
3749 undef_types_length = 0;
3750 }
3751
3752 /* Scan through all of the global symbols defined in the object file,
3753 assigning values to the debugging symbols that need to be assigned
3754 to. Get these symbols from the minimal symbol table. */
3755
3756 void
3757 scan_file_globals (objfile)
3758 struct objfile *objfile;
3759 {
3760 int hash;
3761 struct minimal_symbol *msymbol;
3762 struct symbol *sym, *prev;
3763
3764 if (objfile->msymbols == 0) /* Beware the null file. */
3765 return;
3766
3767 for (msymbol = objfile -> msymbols; SYMBOL_NAME (msymbol) != NULL; msymbol++)
3768 {
3769 QUIT;
3770
3771 prev = NULL;
3772
3773 /* Get the hash index and check all the symbols
3774 under that hash index. */
3775
3776 hash = hashname (SYMBOL_NAME (msymbol));
3777
3778 for (sym = global_sym_chain[hash]; sym;)
3779 {
3780 if (SYMBOL_NAME (msymbol)[0] == SYMBOL_NAME (sym)[0] &&
3781 STREQ(SYMBOL_NAME (msymbol) + 1, SYMBOL_NAME (sym) + 1))
3782 {
3783 /* Splice this symbol out of the hash chain and
3784 assign the value we have to it. */
3785 if (prev)
3786 {
3787 SYMBOL_VALUE_CHAIN (prev) = SYMBOL_VALUE_CHAIN (sym);
3788 }
3789 else
3790 {
3791 global_sym_chain[hash] = SYMBOL_VALUE_CHAIN (sym);
3792 }
3793
3794 /* Check to see whether we need to fix up a common block. */
3795 /* Note: this code might be executed several times for
3796 the same symbol if there are multiple references. */
3797
3798 if (SYMBOL_CLASS (sym) == LOC_BLOCK)
3799 {
3800 fix_common_block (sym, SYMBOL_VALUE_ADDRESS (msymbol));
3801 }
3802 else
3803 {
3804 SYMBOL_VALUE_ADDRESS (sym) = SYMBOL_VALUE_ADDRESS (msymbol);
3805 }
3806
3807 if (prev)
3808 {
3809 sym = SYMBOL_VALUE_CHAIN (prev);
3810 }
3811 else
3812 {
3813 sym = global_sym_chain[hash];
3814 }
3815 }
3816 else
3817 {
3818 prev = sym;
3819 sym = SYMBOL_VALUE_CHAIN (sym);
3820 }
3821 }
3822 }
3823 }
3824
3825 /* Initialize anything that needs initializing when starting to read
3826 a fresh piece of a symbol file, e.g. reading in the stuff corresponding
3827 to a psymtab. */
3828
3829 void
3830 stabsread_init ()
3831 {
3832 }
3833
3834 /* Initialize anything that needs initializing when a completely new
3835 symbol file is specified (not just adding some symbols from another
3836 file, e.g. a shared library). */
3837
3838 void
3839 stabsread_new_init ()
3840 {
3841 /* Empty the hash table of global syms looking for values. */
3842 memset (global_sym_chain, 0, sizeof (global_sym_chain));
3843 }
3844
3845 /* Initialize anything that needs initializing at the same time as
3846 start_symtab() is called. */
3847
3848 void start_stabs ()
3849 {
3850 global_stabs = NULL; /* AIX COFF */
3851 /* Leave FILENUM of 0 free for builtin types and this file's types. */
3852 n_this_object_header_files = 1;
3853 type_vector_length = 0;
3854 type_vector = (struct type **) 0;
3855
3856 /* FIXME: If common_block_name is not already NULL, we should complain(). */
3857 common_block_name = NULL;
3858
3859 os9k_stabs = 0;
3860 }
3861
3862 /* Call after end_symtab() */
3863
3864 void end_stabs ()
3865 {
3866 if (type_vector)
3867 {
3868 free ((char *) type_vector);
3869 }
3870 type_vector = 0;
3871 type_vector_length = 0;
3872 previous_stab_code = 0;
3873 }
3874
3875 void
3876 finish_global_stabs (objfile)
3877 struct objfile *objfile;
3878 {
3879 if (global_stabs)
3880 {
3881 patch_block_stabs (global_symbols, global_stabs, objfile);
3882 free ((PTR) global_stabs);
3883 global_stabs = NULL;
3884 }
3885 }
3886
3887 /* Initializer for this module */
3888
3889 void
3890 _initialize_stabsread ()
3891 {
3892 undef_types_allocated = 20;
3893 undef_types_length = 0;
3894 undef_types = (struct type **)
3895 xmalloc (undef_types_allocated * sizeof (struct type *));
3896 }
This page took 0.112722 seconds and 4 git commands to generate.