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