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