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