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