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