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