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