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