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