1 /* Support routines for decoding "stabs" debugging information format.
2 Copyright 1986, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 1998
3 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* Support routines for reading and decoding debugging information in
23 the "stabs" format. This format is used with many systems that use
24 the a.out object file format, as well as some systems that use
25 COFF or ELF where the stabs data is placed in a special section.
26 Avoid placing any object file format specific code in this file. */
29 #include "gdb_string.h"
34 #include "expression.h"
37 #include "aout/stab_gnu.h" /* We always use GNU stabs, not native */
39 #include "aout/aout64.h"
40 #include "gdb-stabs.h"
42 #include "complaints.h"
48 /* Ask stabsread.h to define the vars it normally declares `extern'. */
51 #include "stabsread.h" /* Our own declarations */
54 extern void _initialize_stabsread (void);
56 /* The routines that read and process a complete stabs for a C struct or
57 C++ class pass lists of data member fields and lists of member function
58 fields in an instance of a field_info structure, as defined below.
59 This is part of some reorganization of low level C++ support and is
60 expected to eventually go away... (FIXME) */
66 struct nextfield *next;
68 /* This is the raw visibility from the stab. It is not checked
69 for being one of the visibilities we recognize, so code which
70 examines this field better be able to deal. */
76 struct next_fnfieldlist
78 struct next_fnfieldlist *next;
79 struct fn_fieldlist fn_fieldlist;
85 read_one_struct_field (struct field_info *, char **, char *,
86 struct type *, struct objfile *);
88 static char *get_substring (char **, int);
90 static struct type *dbx_alloc_type (int[2], struct objfile *);
92 static long read_huge_number (char **, int, int *);
94 static struct type *error_type (char **, struct objfile *);
97 patch_block_stabs (struct pending *, struct pending_stabs *,
100 static void fix_common_block (struct symbol *, int);
102 static int read_type_number (char **, int *);
104 static struct type *read_range_type (char **, int[2], struct objfile *);
106 static struct type *read_sun_builtin_type (char **, int[2], struct objfile *);
108 static struct type *read_sun_floating_type (char **, int[2],
111 static struct type *read_enum_type (char **, struct type *, struct objfile *);
113 static struct type *rs6000_builtin_type (int);
116 read_member_functions (struct field_info *, char **, struct type *,
120 read_struct_fields (struct field_info *, char **, struct type *,
124 read_baseclasses (struct field_info *, char **, struct type *,
128 read_tilde_fields (struct field_info *, char **, struct type *,
131 static int attach_fn_fields_to_type (struct field_info *, struct type *);
134 attach_fields_to_type (struct field_info *, struct type *, struct objfile *);
136 static struct type *read_struct_type (char **, struct type *,
139 static struct type *read_array_type (char **, struct type *,
142 static struct type **read_args (char **, int, struct objfile *);
145 read_cpp_abbrev (struct field_info *, char **, struct type *,
148 /* new functions added for cfront support */
151 copy_cfront_struct_fields (struct field_info *, struct type *,
154 static char *get_cfront_method_physname (char *);
157 read_cfront_baseclasses (struct field_info *, char **,
158 struct type *, struct objfile *);
161 read_cfront_static_fields (struct field_info *, char **,
162 struct type *, struct objfile *);
164 read_cfront_member_functions (struct field_info *, char **,
165 struct type *, struct objfile *);
167 /* end new functions added for cfront support */
170 add_live_range (struct objfile *, struct symbol *, CORE_ADDR, CORE_ADDR);
172 static int resolve_live_range (struct objfile *, struct symbol *, char *);
174 static int process_reference (char **string);
176 static CORE_ADDR ref_search_value (int refnum);
179 resolve_symbol_reference (struct objfile *, struct symbol *, char *);
181 void stabsread_clear_cache (void);
183 static const char vptr_name[] =
184 {'_', 'v', 'p', 't', 'r', CPLUS_MARKER, '\0'};
185 static const char vb_name[] =
186 {'_', 'v', 'b', CPLUS_MARKER, '\0'};
188 /* Define this as 1 if a pcc declaration of a char or short argument
189 gives the correct address. Otherwise assume pcc gives the
190 address of the corresponding int, which is not the same on a
191 big-endian machine. */
193 #if !defined (BELIEVE_PCC_PROMOTION)
194 #define BELIEVE_PCC_PROMOTION 0
196 #if !defined (BELIEVE_PCC_PROMOTION_TYPE)
197 #define BELIEVE_PCC_PROMOTION_TYPE 0
200 static struct complaint invalid_cpp_abbrev_complaint =
201 {"invalid C++ abbreviation `%s'", 0, 0};
203 static struct complaint invalid_cpp_type_complaint =
204 {"C++ abbreviated type name unknown at symtab pos %d", 0, 0};
206 static struct complaint member_fn_complaint =
207 {"member function type missing, got '%c'", 0, 0};
209 static struct complaint const_vol_complaint =
210 {"const/volatile indicator missing, got '%c'", 0, 0};
212 static struct complaint error_type_complaint =
213 {"debug info mismatch between compiler and debugger", 0, 0};
215 static struct complaint invalid_member_complaint =
216 {"invalid (minimal) member type data format at symtab pos %d.", 0, 0};
218 static struct complaint range_type_base_complaint =
219 {"base type %d of range type is not defined", 0, 0};
221 static struct complaint reg_value_complaint =
222 {"register number %d too large (max %d) in symbol %s", 0, 0};
224 static struct complaint vtbl_notfound_complaint =
225 {"virtual function table pointer not found when defining class `%s'", 0, 0};
227 static struct complaint unrecognized_cplus_name_complaint =
228 {"Unknown C++ symbol name `%s'", 0, 0};
230 static struct complaint rs6000_builtin_complaint =
231 {"Unknown builtin type %d", 0, 0};
233 static struct complaint unresolved_sym_chain_complaint =
234 {"%s: common block `%s' from global_sym_chain unresolved", 0, 0};
236 static struct complaint stabs_general_complaint =
239 static struct complaint lrs_general_complaint =
242 /* Make a list of forward references which haven't been defined. */
244 static struct type **undef_types;
245 static int undef_types_allocated;
246 static int undef_types_length;
247 static struct symbol *current_symbol = NULL;
249 /* Check for and handle cretinous stabs symbol name continuation! */
250 #define STABS_CONTINUE(pp,objfile) \
252 if (**(pp) == '\\' || (**(pp) == '?' && (*(pp))[1] == '\0')) \
253 *(pp) = next_symbol_text (objfile); \
256 /* FIXME: These probably should be our own types (like rs6000_builtin_type
257 has its own types) rather than builtin_type_*. */
258 static struct type **os9k_type_vector[] =
265 &builtin_type_unsigned_char,
266 &builtin_type_unsigned_short,
267 &builtin_type_unsigned_long,
268 &builtin_type_unsigned_int,
270 &builtin_type_double,
272 &builtin_type_long_double
275 static void os9k_init_type_vector (struct type **);
278 os9k_init_type_vector (struct type **tv)
281 for (i = 0; i < sizeof (os9k_type_vector) / sizeof (struct type **); i++)
282 tv[i] = (os9k_type_vector[i] == 0 ? 0 : *(os9k_type_vector[i]));
285 /* Look up a dbx type-number pair. Return the address of the slot
286 where the type for that number-pair is stored.
287 The number-pair is in TYPENUMS.
289 This can be used for finding the type associated with that pair
290 or for associating a new type with the pair. */
293 dbx_lookup_type (int typenums[2])
295 register int filenum = typenums[0];
296 register int index = typenums[1];
298 register int real_filenum;
299 register struct header_file *f;
302 if (filenum == -1) /* -1,-1 is for temporary types. */
305 if (filenum < 0 || filenum >= n_this_object_header_files)
307 static struct complaint msg =
309 Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.",
311 complain (&msg, filenum, index, symnum);
319 /* Caller wants address of address of type. We think
320 that negative (rs6k builtin) types will never appear as
321 "lvalues", (nor should they), so we stuff the real type
322 pointer into a temp, and return its address. If referenced,
323 this will do the right thing. */
324 static struct type *temp_type;
326 temp_type = rs6000_builtin_type (index);
330 /* Type is defined outside of header files.
331 Find it in this object file's type vector. */
332 if (index >= type_vector_length)
334 old_len = type_vector_length;
337 type_vector_length = INITIAL_TYPE_VECTOR_LENGTH;
338 type_vector = (struct type **)
339 xmalloc (type_vector_length * sizeof (struct type *));
341 while (index >= type_vector_length)
343 type_vector_length *= 2;
345 type_vector = (struct type **)
346 xrealloc ((char *) type_vector,
347 (type_vector_length * sizeof (struct type *)));
348 memset (&type_vector[old_len], 0,
349 (type_vector_length - old_len) * sizeof (struct type *));
352 /* Deal with OS9000 fundamental types. */
353 os9k_init_type_vector (type_vector);
355 return (&type_vector[index]);
359 real_filenum = this_object_header_files[filenum];
361 if (real_filenum >= N_HEADER_FILES (current_objfile))
363 struct type *temp_type;
364 struct type **temp_type_p;
366 warning ("GDB internal error: bad real_filenum");
369 temp_type = init_type (TYPE_CODE_ERROR, 0, 0, NULL, NULL);
370 temp_type_p = (struct type **) xmalloc (sizeof (struct type *));
371 *temp_type_p = temp_type;
375 f = HEADER_FILES (current_objfile) + real_filenum;
377 f_orig_length = f->length;
378 if (index >= f_orig_length)
380 while (index >= f->length)
384 f->vector = (struct type **)
385 xrealloc ((char *) f->vector, f->length * sizeof (struct type *));
386 memset (&f->vector[f_orig_length], 0,
387 (f->length - f_orig_length) * sizeof (struct type *));
389 return (&f->vector[index]);
393 /* Make sure there is a type allocated for type numbers TYPENUMS
394 and return the type object.
395 This can create an empty (zeroed) type object.
396 TYPENUMS may be (-1, -1) to return a new type object that is not
397 put into the type vector, and so may not be referred to by number. */
400 dbx_alloc_type (int typenums[2], struct objfile *objfile)
402 register struct type **type_addr;
404 if (typenums[0] == -1)
406 return (alloc_type (objfile));
409 type_addr = dbx_lookup_type (typenums);
411 /* If we are referring to a type not known at all yet,
412 allocate an empty type for it.
413 We will fill it in later if we find out how. */
416 *type_addr = alloc_type (objfile);
422 /* for all the stabs in a given stab vector, build appropriate types
423 and fix their symbols in given symbol vector. */
426 patch_block_stabs (struct pending *symbols, struct pending_stabs *stabs,
427 struct objfile *objfile)
437 /* for all the stab entries, find their corresponding symbols and
438 patch their types! */
440 for (ii = 0; ii < stabs->count; ++ii)
442 name = stabs->stab[ii];
443 pp = (char *) strchr (name, ':');
447 pp = (char *) strchr (pp, ':');
449 sym = find_symbol_in_list (symbols, name, pp - name);
452 /* FIXME-maybe: it would be nice if we noticed whether
453 the variable was defined *anywhere*, not just whether
454 it is defined in this compilation unit. But neither
455 xlc or GCC seem to need such a definition, and until
456 we do psymtabs (so that the minimal symbols from all
457 compilation units are available now), I'm not sure
458 how to get the information. */
460 /* On xcoff, if a global is defined and never referenced,
461 ld will remove it from the executable. There is then
462 a N_GSYM stab for it, but no regular (C_EXT) symbol. */
463 sym = (struct symbol *)
464 obstack_alloc (&objfile->symbol_obstack,
465 sizeof (struct symbol));
467 memset (sym, 0, sizeof (struct symbol));
468 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
469 SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
471 obsavestring (name, pp - name, &objfile->symbol_obstack);
473 if (*(pp - 1) == 'F' || *(pp - 1) == 'f')
475 /* I don't think the linker does this with functions,
476 so as far as I know this is never executed.
477 But it doesn't hurt to check. */
479 lookup_function_type (read_type (&pp, objfile));
483 SYMBOL_TYPE (sym) = read_type (&pp, objfile);
485 add_symbol_to_list (sym, &global_symbols);
490 if (*(pp - 1) == 'F' || *(pp - 1) == 'f')
493 lookup_function_type (read_type (&pp, objfile));
497 SYMBOL_TYPE (sym) = read_type (&pp, objfile);
505 /* Read a number by which a type is referred to in dbx data,
506 or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
507 Just a single number N is equivalent to (0,N).
508 Return the two numbers by storing them in the vector TYPENUMS.
509 TYPENUMS will then be used as an argument to dbx_lookup_type.
511 Returns 0 for success, -1 for error. */
514 read_type_number (register char **pp, register int *typenums)
520 typenums[0] = read_huge_number (pp, ',', &nbits);
523 typenums[1] = read_huge_number (pp, ')', &nbits);
530 typenums[1] = read_huge_number (pp, 0, &nbits);
538 #define VISIBILITY_PRIVATE '0' /* Stabs character for private field */
539 #define VISIBILITY_PROTECTED '1' /* Stabs character for protected fld */
540 #define VISIBILITY_PUBLIC '2' /* Stabs character for public field */
541 #define VISIBILITY_IGNORE '9' /* Optimized out or zero length */
543 #define CFRONT_VISIBILITY_PRIVATE '2' /* Stabs character for private field */
544 #define CFRONT_VISIBILITY_PUBLIC '1' /* Stabs character for public field */
546 /* This code added to support parsing of ARM/Cfront stabs strings */
548 /* Get substring from string up to char c, advance string pointer past
552 get_substring (char **p, int c)
567 /* Physname gets strcat'd onto sname in order to recreate the mangled
568 name (see funtion gdb_mangle_name in gdbtypes.c). For cfront, make
569 the physname look like that of g++ - take out the initial mangling
570 eg: for sname="a" and fname="foo__1aFPFs_i" return "FPFs_i" */
573 get_cfront_method_physname (char *fname)
576 /* FIXME would like to make this generic for g++ too, but
577 that is already handled in read_member_funcctions */
580 /* search ahead to find the start of the mangled suffix */
581 if (*p == '_' && *(p + 1) == '_') /* compiler generated; probably a ctor/dtor */
583 while (p && (unsigned) ((p + 1) - fname) < strlen (fname) && *(p + 1) != '_')
585 if (!(p && *p == '_' && *(p + 1) == '_'))
586 error ("Invalid mangled function name %s", fname);
587 p += 2; /* advance past '__' */
589 /* struct name length and name of type should come next; advance past it */
592 len = len * 10 + (*p - '0');
600 /* Read base classes within cfront class definition.
601 eg: A:ZcA;1@Bpub v2@Bvirpri;__ct__1AFv func__1AFv *sfunc__1AFv ;as__1A ;;
604 A:ZcA;;foopri__1AFv foopro__1AFv __ct__1AFv __ct__1AFRC1A foopub__1AFv ;;;
609 read_cfront_baseclasses (struct field_info *fip, char **pp, struct type *type,
610 struct objfile *objfile)
612 static struct complaint msg_unknown =
614 Unsupported token in stabs string %s.\n",
616 static struct complaint msg_notfound =
618 Unable to find base type for %s.\n",
623 struct nextfield *new;
625 if (**pp == ';') /* no base classes; return */
631 /* first count base classes so we can allocate space before parsing */
632 for (p = *pp; p && *p && *p != ';'; p++)
637 bnum++; /* add one more for last one */
639 /* now parse the base classes until we get to the start of the methods
640 (code extracted and munged from read_baseclasses) */
641 ALLOCATE_CPLUS_STRUCT_TYPE (type);
642 TYPE_N_BASECLASSES (type) = bnum;
646 int num_bytes = B_BYTES (TYPE_N_BASECLASSES (type));
649 pointer = (char *) TYPE_ALLOC (type, num_bytes);
650 TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *) pointer;
652 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), TYPE_N_BASECLASSES (type));
654 for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
656 new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
657 make_cleanup (free, new);
658 memset (new, 0, sizeof (struct nextfield));
659 new->next = fip->list;
661 FIELD_BITSIZE (new->field) = 0; /* this should be an unpacked field! */
663 STABS_CONTINUE (pp, objfile);
665 /* virtual? eg: v2@Bvir */
668 SET_TYPE_FIELD_VIRTUAL (type, i);
672 /* access? eg: 2@Bvir */
673 /* Note: protected inheritance not supported in cfront */
676 case CFRONT_VISIBILITY_PRIVATE:
677 new->visibility = VISIBILITY_PRIVATE;
679 case CFRONT_VISIBILITY_PUBLIC:
680 new->visibility = VISIBILITY_PUBLIC;
683 /* Bad visibility format. Complain and treat it as
686 static struct complaint msg =
688 "Unknown visibility `%c' for baseclass", 0, 0};
689 complain (&msg, new->visibility);
690 new->visibility = VISIBILITY_PUBLIC;
694 /* "@" comes next - eg: @Bvir */
697 complain (&msg_unknown, *pp);
703 /* Set the bit offset of the portion of the object corresponding
704 to this baseclass. Always zero in the absence of
705 multiple inheritance. */
706 /* Unable to read bit position from stabs;
707 Assuming no multiple inheritance for now FIXME! */
708 /* We may have read this in the structure definition;
709 now we should fixup the members to be the actual base classes */
710 FIELD_BITPOS (new->field) = 0;
712 /* Get the base class name and type */
714 char *bname; /* base class name */
715 struct symbol *bsym; /* base class */
717 p1 = strchr (*pp, ' ');
718 p2 = strchr (*pp, ';');
720 bname = get_substring (pp, ' ');
722 bname = get_substring (pp, ';');
723 if (!bname || !*bname)
725 complain (&msg_unknown, *pp);
728 /* FIXME! attach base info to type */
729 bsym = lookup_symbol (bname, 0, STRUCT_NAMESPACE, 0, 0); /*demangled_name */
732 new->field.type = SYMBOL_TYPE (bsym);
733 new->field.name = type_name_no_tag (new->field.type);
737 complain (&msg_notfound, *pp);
742 /* If more base classes to parse, loop again.
743 We ate the last ' ' or ';' in get_substring,
744 so on exit we will have skipped the trailing ';' */
745 /* if invalid, return 0; add code to detect - FIXME! */
750 /* read cfront member functions.
751 pp points to string starting with list of functions
752 eg: A:ZcA;1@Bpub v2@Bvirpri;__ct__1AFv func__1AFv *sfunc__1AFv ;as__1A ;;
753 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
754 A:ZcA;;foopri__1AFv foopro__1AFv __ct__1AFv __ct__1AFRC1A foopub__1AFv ;;;
755 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
759 read_cfront_member_functions (struct field_info *fip, char **pp,
760 struct type *type, struct objfile *objfile)
762 /* This code extracted from read_member_functions
763 so as to do the similar thing for our funcs */
767 /* Total number of member functions defined in this class. If the class
768 defines two `f' functions, and one `g' function, then this will have
770 int total_length = 0;
774 struct next_fnfield *next;
775 struct fn_field fn_field;
778 struct type *look_ahead_type;
779 struct next_fnfieldlist *new_fnlist;
780 struct next_fnfield *new_sublist;
783 struct symbol *ref_func = 0;
785 /* Process each list until we find the end of the member functions.
786 eg: p = "__ct__1AFv foo__1AFv ;;;" */
788 STABS_CONTINUE (pp, objfile); /* handle \\ */
790 while (**pp != ';' && (fname = get_substring (pp, ' '), fname))
793 int sublist_count = 0;
795 if (fname[0] == '*') /* static member */
801 ref_func = lookup_symbol (fname, 0, VAR_NAMESPACE, 0, 0); /* demangled name */
804 static struct complaint msg =
806 Unable to find function symbol for %s\n",
808 complain (&msg, fname);
812 look_ahead_type = NULL;
815 new_fnlist = (struct next_fnfieldlist *)
816 xmalloc (sizeof (struct next_fnfieldlist));
817 make_cleanup (free, new_fnlist);
818 memset (new_fnlist, 0, sizeof (struct next_fnfieldlist));
820 /* The following is code to work around cfront generated stabs.
821 The stabs contains full mangled name for each field.
822 We try to demangle the name and extract the field name out of it. */
824 char *dem, *dem_p, *dem_args;
826 dem = cplus_demangle (fname, DMGL_ANSI | DMGL_PARAMS);
829 dem_p = strrchr (dem, ':');
830 if (dem_p != 0 && *(dem_p - 1) == ':')
832 /* get rid of args */
833 dem_args = strchr (dem_p, '(');
834 if (dem_args == NULL)
835 dem_len = strlen (dem_p);
837 dem_len = dem_args - dem_p;
839 obsavestring (dem_p, dem_len, &objfile->type_obstack);
844 obsavestring (fname, strlen (fname), &objfile->type_obstack);
846 } /* end of code for cfront work around */
848 new_fnlist->fn_fieldlist.name = main_fn_name;
850 /*-------------------------------------------------*/
851 /* Set up the sublists
852 Sublists are stuff like args, static, visibility, etc.
853 so in ARM, we have to set that info some other way.
854 Multiple sublists happen if overloading
855 eg: foo::26=##1;:;2A.;
856 In g++, we'd loop here thru all the sublists... */
859 (struct next_fnfield *) xmalloc (sizeof (struct next_fnfield));
860 make_cleanup (free, new_sublist);
861 memset (new_sublist, 0, sizeof (struct next_fnfield));
863 /* eat 1; from :;2A.; */
864 new_sublist->fn_field.type = SYMBOL_TYPE (ref_func); /* normally takes a read_type */
865 /* Make this type look like a method stub for gdb */
866 TYPE_FLAGS (new_sublist->fn_field.type) |= TYPE_FLAG_STUB;
867 TYPE_CODE (new_sublist->fn_field.type) = TYPE_CODE_METHOD;
869 /* If this is just a stub, then we don't have the real name here. */
870 if (TYPE_FLAGS (new_sublist->fn_field.type) & TYPE_FLAG_STUB)
872 if (!TYPE_DOMAIN_TYPE (new_sublist->fn_field.type))
873 TYPE_DOMAIN_TYPE (new_sublist->fn_field.type) = type;
874 new_sublist->fn_field.is_stub = 1;
877 /* physname used later in mangling; eg PFs_i,5 for foo__1aFPFs_i
878 physname gets strcat'd in order to recreate the onto mangled name */
879 pname = get_cfront_method_physname (fname);
880 new_sublist->fn_field.physname = savestring (pname, strlen (pname));
883 /* Set this member function's visibility fields.
884 Unable to distinguish access from stabs definition!
885 Assuming public for now. FIXME!
886 (for private, set new_sublist->fn_field.is_private = 1,
887 for public, set new_sublist->fn_field.is_protected = 1) */
889 /* Unable to distinguish const/volatile from stabs definition!
890 Assuming normal for now. FIXME! */
892 new_sublist->fn_field.is_const = 0;
893 new_sublist->fn_field.is_volatile = 0; /* volatile not implemented in cfront */
895 /* Set virtual/static function info
896 How to get vtable offsets ?
897 Assuming normal for now FIXME!!
898 For vtables, figure out from whence this virtual function came.
899 It may belong to virtual function table of
900 one of its baseclasses.
902 new_sublist -> fn_field.voffset = vtable offset,
903 new_sublist -> fn_field.fcontext = look_ahead_type;
904 where look_ahead_type is type of baseclass */
906 new_sublist->fn_field.voffset = VOFFSET_STATIC;
907 else /* normal member function. */
908 new_sublist->fn_field.voffset = 0;
909 new_sublist->fn_field.fcontext = 0;
912 /* Prepare new sublist */
913 new_sublist->next = sublist;
914 sublist = new_sublist;
917 /* In g++, we loop thu sublists - now we set from functions. */
918 new_fnlist->fn_fieldlist.fn_fields = (struct fn_field *)
919 obstack_alloc (&objfile->type_obstack,
920 sizeof (struct fn_field) * length);
921 memset (new_fnlist->fn_fieldlist.fn_fields, 0,
922 sizeof (struct fn_field) * length);
923 for (i = length; (i--, sublist); sublist = sublist->next)
925 new_fnlist->fn_fieldlist.fn_fields[i] = sublist->fn_field;
928 new_fnlist->fn_fieldlist.length = length;
929 new_fnlist->next = fip->fnlist;
930 fip->fnlist = new_fnlist;
932 total_length += length;
933 STABS_CONTINUE (pp, objfile); /* handle \\ */
938 /* type should already have space */
939 TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
940 TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * nfn_fields);
941 memset (TYPE_FN_FIELDLISTS (type), 0,
942 sizeof (struct fn_fieldlist) * nfn_fields);
943 TYPE_NFN_FIELDS (type) = nfn_fields;
944 TYPE_NFN_FIELDS_TOTAL (type) = total_length;
947 /* end of scope for reading member func */
951 /* Skip trailing ';' and bump count of number of fields seen */
959 /* This routine fixes up partial cfront types that were created
960 while parsing the stabs. The main need for this function is
961 to add information such as methods to classes.
962 Examples of "p": "sA;;__ct__1AFv foo__1AFv ;;;" */
964 resolve_cfront_continuation (struct objfile *objfile, struct symbol *sym,
967 struct symbol *ref_sym = 0;
969 /* snarfed from read_struct_type */
970 struct field_info fi;
972 struct cleanup *back_to;
974 /* Need to make sure that fi isn't gunna conflict with struct
975 in case struct already had some fnfs */
978 back_to = make_cleanup (null_cleanup, 0);
980 /* We only accept structs, classes and unions at the moment.
981 Other continuation types include t (typedef), r (long dbl), ...
982 We may want to add support for them as well;
983 right now they are handled by duplicating the symbol information
984 into the type information (see define_symbol) */
985 if (*p != 's' /* structs */
986 && *p != 'c' /* class */
987 && *p != 'u') /* union */
988 return 0; /* only handle C++ types */
991 /* Get symbol typs name and validate
992 eg: p = "A;;__ct__1AFv foo__1AFv ;;;" */
993 sname = get_substring (&p, ';');
994 if (!sname || strcmp (sname, SYMBOL_NAME (sym)))
995 error ("Internal error: base symbol type name does not match\n");
997 /* Find symbol's internal gdb reference using demangled_name.
998 This is the real sym that we want;
999 sym was a temp hack to make debugger happy */
1000 ref_sym = lookup_symbol (SYMBOL_NAME (sym), 0, STRUCT_NAMESPACE, 0, 0);
1001 type = SYMBOL_TYPE (ref_sym);
1004 /* Now read the baseclasses, if any, read the regular C struct or C++
1005 class member fields, attach the fields to the type, read the C++
1006 member functions, attach them to the type, and then read any tilde
1007 field (baseclass specifier for the class holding the main vtable). */
1009 if (!read_cfront_baseclasses (&fi, &p, type, objfile)
1010 /* g++ does this next, but cfront already did this:
1011 || !read_struct_fields (&fi, &p, type, objfile) */
1012 || !copy_cfront_struct_fields (&fi, type, objfile)
1013 || !read_cfront_member_functions (&fi, &p, type, objfile)
1014 || !read_cfront_static_fields (&fi, &p, type, objfile)
1015 || !attach_fields_to_type (&fi, type, objfile)
1016 || !attach_fn_fields_to_type (&fi, type)
1017 /* g++ does this next, but cfront doesn't seem to have this:
1018 || !read_tilde_fields (&fi, &p, type, objfile) */
1021 type = error_type (&p, objfile);
1024 do_cleanups (back_to);
1027 /* End of code added to support parsing of ARM/Cfront stabs strings */
1030 /* This routine fixes up symbol references/aliases to point to the original
1031 symbol definition. Returns 0 on failure, non-zero on success. */
1034 resolve_symbol_reference (struct objfile *objfile, struct symbol *sym, char *p)
1037 struct symbol *ref_sym = 0;
1038 struct alias_list *alias;
1040 /* If this is not a symbol reference return now. */
1044 /* Use "#<num>" as the name; we'll fix the name later.
1045 We stored the original symbol name as "#<id>=<name>"
1046 so we can now search for "#<id>" to resolving the reference.
1047 We'll fix the names later by removing the "#<id>" or "#<id>=" */
1049 /*---------------------------------------------------------*/
1050 /* Get the reference id number, and
1051 advance p past the names so we can parse the rest.
1052 eg: id=2 for p : "2=", "2=z:r(0,1)" "2:r(0,1);l(#5,#6),l(#7,#4)" */
1053 /*---------------------------------------------------------*/
1055 /* This gets reference name from string. sym may not have a name. */
1057 /* Get the reference number associated with the reference id in the
1058 gdb stab string. From that reference number, get the main/primary
1059 symbol for this alias. */
1060 refnum = process_reference (&p);
1061 ref_sym = ref_search (refnum);
1064 complain (&lrs_general_complaint, "symbol for reference not found");
1068 /* Parse the stab of the referencing symbol
1069 now that we have the referenced symbol.
1070 Add it as a new symbol and a link back to the referenced symbol.
1071 eg: p : "=", "=z:r(0,1)" ":r(0,1);l(#5,#6),l(#7,#4)" */
1074 /* If the stab symbol table and string contain:
1075 RSYM 0 5 00000000 868 #15=z:r(0,1)
1076 LBRAC 0 0 00000000 899 #5=
1077 SLINE 0 16 00000003 923 #6=
1078 Then the same symbols can be later referenced by:
1079 RSYM 0 5 00000000 927 #15:r(0,1);l(#5,#6)
1080 This is used in live range splitting to:
1081 1) specify that a symbol (#15) is actually just a new storage
1082 class for a symbol (#15=z) which was previously defined.
1083 2) specify that the beginning and ending ranges for a symbol
1084 (#15) are the values of the beginning (#5) and ending (#6)
1087 /* Read number as reference id.
1088 eg: p : "=", "=z:r(0,1)" ":r(0,1);l(#5,#6),l(#7,#4)" */
1089 /* FIXME! Might I want to use SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
1090 in case of "l(0,0)"? */
1092 /*--------------------------------------------------*/
1093 /* Add this symbol to the reference list. */
1094 /*--------------------------------------------------*/
1096 alias = (struct alias_list *) obstack_alloc (&objfile->type_obstack,
1097 sizeof (struct alias_list));
1100 complain (&lrs_general_complaint, "Unable to allocate alias list memory");
1107 if (!SYMBOL_ALIASES (ref_sym))
1109 SYMBOL_ALIASES (ref_sym) = alias;
1113 struct alias_list *temp;
1115 /* Get to the end of the list. */
1116 for (temp = SYMBOL_ALIASES (ref_sym);
1123 /* Want to fix up name so that other functions (eg. valops)
1124 will correctly print the name.
1125 Don't add_symbol_to_list so that lookup_symbol won't find it.
1126 nope... needed for fixups. */
1127 SYMBOL_NAME (sym) = SYMBOL_NAME (ref_sym);
1133 /* Structure for storing pointers to reference definitions for fast lookup
1134 during "process_later". */
1143 #define MAX_CHUNK_REFS 100
1144 #define REF_CHUNK_SIZE (MAX_CHUNK_REFS * sizeof (struct ref_map))
1145 #define REF_MAP_SIZE(ref_chunk) ((ref_chunk) * REF_CHUNK_SIZE)
1147 static struct ref_map *ref_map;
1149 /* Ptr to free cell in chunk's linked list. */
1150 static int ref_count = 0;
1152 /* Number of chunks malloced. */
1153 static int ref_chunk = 0;
1155 /* This file maintains a cache of stabs aliases found in the symbol
1156 table. If the symbol table changes, this cache must be cleared
1157 or we are left holding onto data in invalid obstacks. */
1159 stabsread_clear_cache (void)
1165 /* Create array of pointers mapping refids to symbols and stab strings.
1166 Add pointers to reference definition symbols and/or their values as we
1167 find them, using their reference numbers as our index.
1168 These will be used later when we resolve references. */
1170 ref_add (int refnum, struct symbol *sym, char *stabs, CORE_ADDR value)
1174 if (refnum >= ref_count)
1175 ref_count = refnum + 1;
1176 if (ref_count > ref_chunk * MAX_CHUNK_REFS)
1178 int new_slots = ref_count - ref_chunk * MAX_CHUNK_REFS;
1179 int new_chunks = new_slots / MAX_CHUNK_REFS + 1;
1180 ref_map = (struct ref_map *)
1181 xrealloc (ref_map, REF_MAP_SIZE (ref_chunk + new_chunks));
1182 memset (ref_map + ref_chunk * MAX_CHUNK_REFS, 0, new_chunks * REF_CHUNK_SIZE);
1183 ref_chunk += new_chunks;
1185 ref_map[refnum].stabs = stabs;
1186 ref_map[refnum].sym = sym;
1187 ref_map[refnum].value = value;
1190 /* Return defined sym for the reference REFNUM. */
1192 ref_search (int refnum)
1194 if (refnum < 0 || refnum > ref_count)
1196 return ref_map[refnum].sym;
1199 /* Return value for the reference REFNUM. */
1202 ref_search_value (int refnum)
1204 if (refnum < 0 || refnum > ref_count)
1206 return ref_map[refnum].value;
1209 /* Parse a reference id in STRING and return the resulting
1210 reference number. Move STRING beyond the reference id. */
1213 process_reference (char **string)
1218 if (**string != '#')
1221 /* Advance beyond the initial '#'. */
1224 /* Read number as reference id. */
1225 while (*p && isdigit (*p))
1227 refnum = refnum * 10 + *p - '0';
1234 /* If STRING defines a reference, store away a pointer to the reference
1235 definition for later use. Return the reference number. */
1238 symbol_reference_defined (char **string)
1243 refnum = process_reference (&p);
1245 /* Defining symbols end in '=' */
1248 /* Symbol is being defined here. */
1254 /* Must be a reference. Either the symbol has already been defined,
1255 or this is a forward reference to it. */
1263 define_symbol (CORE_ADDR valu, char *string, int desc, int type,
1264 struct objfile *objfile)
1266 register struct symbol *sym;
1267 char *p = (char *) strchr (string, ':');
1272 /* We would like to eliminate nameless symbols, but keep their types.
1273 E.g. stab entry ":t10=*2" should produce a type 10, which is a pointer
1274 to type 2, but, should not create a symbol to address that type. Since
1275 the symbol will be nameless, there is no way any user can refer to it. */
1279 /* Ignore syms with empty names. */
1283 /* Ignore old-style symbols from cc -go */
1290 p = strchr (p, ':');
1293 /* If a nameless stab entry, all we need is the type, not the symbol.
1294 e.g. ":t10=*2" or a nameless enum like " :T16=ered:0,green:1,blue:2,;" */
1295 nameless = (p == string || ((string[0] == ' ') && (string[1] == ':')));
1297 current_symbol = sym = (struct symbol *)
1298 obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol));
1299 memset (sym, 0, sizeof (struct symbol));
1301 switch (type & N_TYPE)
1304 SYMBOL_SECTION (sym) = SECT_OFF_TEXT (objfile);
1307 SYMBOL_SECTION (sym) = SECT_OFF_DATA (objfile);
1310 SYMBOL_SECTION (sym) = SECT_OFF_BSS (objfile);
1314 if (processing_gcc_compilation)
1316 /* GCC 2.x puts the line number in desc. SunOS apparently puts in the
1317 number of bytes occupied by a type or object, which we ignore. */
1318 SYMBOL_LINE (sym) = desc;
1322 SYMBOL_LINE (sym) = 0; /* unknown */
1325 if (is_cplus_marker (string[0]))
1327 /* Special GNU C++ names. */
1331 SYMBOL_NAME (sym) = obsavestring ("this", strlen ("this"),
1332 &objfile->symbol_obstack);
1335 case 'v': /* $vtbl_ptr_type */
1336 /* Was: SYMBOL_NAME (sym) = "vptr"; */
1340 SYMBOL_NAME (sym) = obsavestring ("eh_throw", strlen ("eh_throw"),
1341 &objfile->symbol_obstack);
1345 /* This was an anonymous type that was never fixed up. */
1348 #ifdef STATIC_TRANSFORM_NAME
1350 /* SunPRO (3.0 at least) static variable encoding. */
1355 complain (&unrecognized_cplus_name_complaint, string);
1356 goto normal; /* Do *something* with it */
1359 else if (string[0] == '#')
1361 /* Special GNU C extension for referencing symbols. */
1365 /* If STRING defines a new reference id, then add it to the
1366 reference map. Else it must be referring to a previously
1367 defined symbol, so add it to the alias list of the previously
1370 refnum = symbol_reference_defined (&s);
1372 ref_add (refnum, sym, string, SYMBOL_VALUE (sym));
1373 else if (!resolve_symbol_reference (objfile, sym, string))
1376 /* S..P contains the name of the symbol. We need to store
1377 the correct name into SYMBOL_NAME. */
1383 SYMBOL_NAME (sym) = (char *)
1384 obstack_alloc (&objfile->symbol_obstack, nlen);
1385 strncpy (SYMBOL_NAME (sym), s, nlen);
1386 SYMBOL_NAME (sym)[nlen] = '\0';
1387 SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->symbol_obstack);
1390 /* FIXME! Want SYMBOL_NAME (sym) = 0;
1391 Get error if leave name 0. So give it something. */
1394 SYMBOL_NAME (sym) = (char *)
1395 obstack_alloc (&objfile->symbol_obstack, nlen);
1396 strncpy (SYMBOL_NAME (sym), string, nlen);
1397 SYMBOL_NAME (sym)[nlen] = '\0';
1398 SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->symbol_obstack);
1401 /* Advance STRING beyond the reference id. */
1407 SYMBOL_LANGUAGE (sym) = current_subfile->language;
1408 SYMBOL_NAME (sym) = (char *)
1409 obstack_alloc (&objfile->symbol_obstack, ((p - string) + 1));
1410 /* Open-coded memcpy--saves function call time. */
1411 /* FIXME: Does it really? Try replacing with simple strcpy and
1412 try it on an executable with a large symbol table. */
1413 /* FIXME: considering that gcc can open code memcpy anyway, I
1414 doubt it. xoxorich. */
1416 register char *p1 = string;
1417 register char *p2 = SYMBOL_NAME (sym);
1425 /* If this symbol is from a C++ compilation, then attempt to cache the
1426 demangled form for future reference. This is a typical time versus
1427 space tradeoff, that was decided in favor of time because it sped up
1428 C++ symbol lookups by a factor of about 20. */
1430 SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->symbol_obstack);
1434 /* Determine the type of name being defined. */
1436 /* Getting GDB to correctly skip the symbol on an undefined symbol
1437 descriptor and not ever dump core is a very dodgy proposition if
1438 we do things this way. I say the acorn RISC machine can just
1439 fix their compiler. */
1440 /* The Acorn RISC machine's compiler can put out locals that don't
1441 start with "234=" or "(3,4)=", so assume anything other than the
1442 deftypes we know how to handle is a local. */
1443 if (!strchr ("cfFGpPrStTvVXCR", *p))
1445 if (isdigit (*p) || *p == '(' || *p == '-')
1454 /* c is a special case, not followed by a type-number.
1455 SYMBOL:c=iVALUE for an integer constant symbol.
1456 SYMBOL:c=rVALUE for a floating constant symbol.
1457 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
1458 e.g. "b:c=e6,0" for "const b = blob1"
1459 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
1462 SYMBOL_CLASS (sym) = LOC_CONST;
1463 SYMBOL_TYPE (sym) = error_type (&p, objfile);
1464 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1465 add_symbol_to_list (sym, &file_symbols);
1473 double d = atof (p);
1476 /* FIXME-if-picky-about-floating-accuracy: Should be using
1477 target arithmetic to get the value. real.c in GCC
1478 probably has the necessary code. */
1480 /* FIXME: lookup_fundamental_type is a hack. We should be
1481 creating a type especially for the type of float constants.
1482 Problem is, what type should it be?
1484 Also, what should the name of this type be? Should we
1485 be using 'S' constants (see stabs.texinfo) instead? */
1487 SYMBOL_TYPE (sym) = lookup_fundamental_type (objfile,
1490 obstack_alloc (&objfile->symbol_obstack,
1491 TYPE_LENGTH (SYMBOL_TYPE (sym)));
1492 store_floating (dbl_valu, TYPE_LENGTH (SYMBOL_TYPE (sym)), d);
1493 SYMBOL_VALUE_BYTES (sym) = dbl_valu;
1494 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
1499 /* Defining integer constants this way is kind of silly,
1500 since 'e' constants allows the compiler to give not
1501 only the value, but the type as well. C has at least
1502 int, long, unsigned int, and long long as constant
1503 types; other languages probably should have at least
1504 unsigned as well as signed constants. */
1506 /* We just need one int constant type for all objfiles.
1507 It doesn't depend on languages or anything (arguably its
1508 name should be a language-specific name for a type of
1509 that size, but I'm inclined to say that if the compiler
1510 wants a nice name for the type, it can use 'e'). */
1511 static struct type *int_const_type;
1513 /* Yes, this is as long as a *host* int. That is because we
1515 if (int_const_type == NULL)
1517 init_type (TYPE_CODE_INT,
1518 sizeof (int) * HOST_CHAR_BIT / TARGET_CHAR_BIT, 0,
1520 (struct objfile *) NULL);
1521 SYMBOL_TYPE (sym) = int_const_type;
1522 SYMBOL_VALUE (sym) = atoi (p);
1523 SYMBOL_CLASS (sym) = LOC_CONST;
1527 /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value
1528 can be represented as integral.
1529 e.g. "b:c=e6,0" for "const b = blob1"
1530 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
1532 SYMBOL_CLASS (sym) = LOC_CONST;
1533 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1537 SYMBOL_TYPE (sym) = error_type (&p, objfile);
1542 /* If the value is too big to fit in an int (perhaps because
1543 it is unsigned), or something like that, we silently get
1544 a bogus value. The type and everything else about it is
1545 correct. Ideally, we should be using whatever we have
1546 available for parsing unsigned and long long values,
1548 SYMBOL_VALUE (sym) = atoi (p);
1553 SYMBOL_CLASS (sym) = LOC_CONST;
1554 SYMBOL_TYPE (sym) = error_type (&p, objfile);
1557 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1558 add_symbol_to_list (sym, &file_symbols);
1562 /* The name of a caught exception. */
1563 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1564 SYMBOL_CLASS (sym) = LOC_LABEL;
1565 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1566 SYMBOL_VALUE_ADDRESS (sym) = valu;
1567 add_symbol_to_list (sym, &local_symbols);
1571 /* A static function definition. */
1572 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1573 SYMBOL_CLASS (sym) = LOC_BLOCK;
1574 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1575 add_symbol_to_list (sym, &file_symbols);
1576 /* fall into process_function_types. */
1578 process_function_types:
1579 /* Function result types are described as the result type in stabs.
1580 We need to convert this to the function-returning-type-X type
1581 in GDB. E.g. "int" is converted to "function returning int". */
1582 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_FUNC)
1583 SYMBOL_TYPE (sym) = lookup_function_type (SYMBOL_TYPE (sym));
1585 /* All functions in C++ have prototypes. */
1586 if (SYMBOL_LANGUAGE (sym) == language_cplus)
1587 TYPE_FLAGS (SYMBOL_TYPE (sym)) |= TYPE_FLAG_PROTOTYPED;
1589 /* fall into process_prototype_types */
1591 process_prototype_types:
1592 /* Sun acc puts declared types of arguments here. */
1595 struct type *ftype = SYMBOL_TYPE (sym);
1600 /* Obtain a worst case guess for the number of arguments
1601 by counting the semicolons. */
1608 /* Allocate parameter information fields and fill them in. */
1609 TYPE_FIELDS (ftype) = (struct field *)
1610 TYPE_ALLOC (ftype, nsemi * sizeof (struct field));
1615 /* A type number of zero indicates the start of varargs.
1616 FIXME: GDB currently ignores vararg functions. */
1617 if (p[0] == '0' && p[1] == '\0')
1619 ptype = read_type (&p, objfile);
1621 /* The Sun compilers mark integer arguments, which should
1622 be promoted to the width of the calling conventions, with
1623 a type which references itself. This type is turned into
1624 a TYPE_CODE_VOID type by read_type, and we have to turn
1625 it back into builtin_type_int here.
1626 FIXME: Do we need a new builtin_type_promoted_int_arg ? */
1627 if (TYPE_CODE (ptype) == TYPE_CODE_VOID)
1628 ptype = builtin_type_int;
1629 TYPE_FIELD_TYPE (ftype, nparams++) = ptype;
1631 TYPE_NFIELDS (ftype) = nparams;
1632 TYPE_FLAGS (ftype) |= TYPE_FLAG_PROTOTYPED;
1637 /* A global function definition. */
1638 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1639 SYMBOL_CLASS (sym) = LOC_BLOCK;
1640 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1641 add_symbol_to_list (sym, &global_symbols);
1642 goto process_function_types;
1645 /* For a class G (global) symbol, it appears that the
1646 value is not correct. It is necessary to search for the
1647 corresponding linker definition to find the value.
1648 These definitions appear at the end of the namelist. */
1649 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1650 SYMBOL_CLASS (sym) = LOC_STATIC;
1651 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1652 /* Don't add symbol references to global_sym_chain.
1653 Symbol references don't have valid names and wont't match up with
1654 minimal symbols when the global_sym_chain is relocated.
1655 We'll fixup symbol references when we fixup the defining symbol. */
1656 if (SYMBOL_NAME (sym) && SYMBOL_NAME (sym)[0] != '#')
1658 i = hashname (SYMBOL_NAME (sym));
1659 SYMBOL_VALUE_CHAIN (sym) = global_sym_chain[i];
1660 global_sym_chain[i] = sym;
1662 add_symbol_to_list (sym, &global_symbols);
1665 /* This case is faked by a conditional above,
1666 when there is no code letter in the dbx data.
1667 Dbx data never actually contains 'l'. */
1670 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1671 SYMBOL_CLASS (sym) = LOC_LOCAL;
1672 SYMBOL_VALUE (sym) = valu;
1673 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1674 add_symbol_to_list (sym, &local_symbols);
1679 /* pF is a two-letter code that means a function parameter in Fortran.
1680 The type-number specifies the type of the return value.
1681 Translate it into a pointer-to-function type. */
1685 = lookup_pointer_type
1686 (lookup_function_type (read_type (&p, objfile)));
1689 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1691 /* Normally this is a parameter, a LOC_ARG. On the i960, it
1692 can also be a LOC_LOCAL_ARG depending on symbol type. */
1693 #ifndef DBX_PARM_SYMBOL_CLASS
1694 #define DBX_PARM_SYMBOL_CLASS(type) LOC_ARG
1697 SYMBOL_CLASS (sym) = DBX_PARM_SYMBOL_CLASS (type);
1698 SYMBOL_VALUE (sym) = valu;
1699 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1700 add_symbol_to_list (sym, &local_symbols);
1702 if (TARGET_BYTE_ORDER != BIG_ENDIAN)
1704 /* On little-endian machines, this crud is never necessary,
1705 and, if the extra bytes contain garbage, is harmful. */
1709 /* If it's gcc-compiled, if it says `short', believe it. */
1710 if (processing_gcc_compilation || BELIEVE_PCC_PROMOTION)
1713 if (!BELIEVE_PCC_PROMOTION)
1715 /* This is the signed type which arguments get promoted to. */
1716 static struct type *pcc_promotion_type;
1717 /* This is the unsigned type which arguments get promoted to. */
1718 static struct type *pcc_unsigned_promotion_type;
1720 /* Call it "int" because this is mainly C lossage. */
1721 if (pcc_promotion_type == NULL)
1722 pcc_promotion_type =
1723 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
1726 if (pcc_unsigned_promotion_type == NULL)
1727 pcc_unsigned_promotion_type =
1728 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
1729 TYPE_FLAG_UNSIGNED, "unsigned int", NULL);
1731 if (BELIEVE_PCC_PROMOTION_TYPE)
1733 /* This is defined on machines (e.g. sparc) where we
1734 should believe the type of a PCC 'short' argument,
1735 but shouldn't believe the address (the address is the
1736 address of the corresponding int).
1738 My guess is that this correction, as opposed to
1739 changing the parameter to an 'int' (as done below,
1740 for PCC on most machines), is the right thing to do
1741 on all machines, but I don't want to risk breaking
1742 something that already works. On most PCC machines,
1743 the sparc problem doesn't come up because the calling
1744 function has to zero the top bytes (not knowing
1745 whether the called function wants an int or a short),
1746 so there is little practical difference between an
1747 int and a short (except perhaps what happens when the
1748 GDB user types "print short_arg = 0x10000;").
1750 Hacked for SunOS 4.1 by gnu@cygnus.com. In 4.1, the
1751 compiler actually produces the correct address (we
1752 don't need to fix it up). I made this code adapt so
1753 that it will offset the symbol if it was pointing at
1754 an int-aligned location and not otherwise. This way
1755 you can use the same gdb for 4.0.x and 4.1 systems.
1757 If the parameter is shorter than an int, and is
1758 integral (e.g. char, short, or unsigned equivalent),
1759 and is claimed to be passed on an integer boundary,
1760 don't believe it! Offset the parameter's address to
1761 the tail-end of that integer. */
1763 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) < TYPE_LENGTH (pcc_promotion_type)
1764 && TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_INT
1765 && 0 == SYMBOL_VALUE (sym) % TYPE_LENGTH (pcc_promotion_type))
1767 SYMBOL_VALUE (sym) += TYPE_LENGTH (pcc_promotion_type)
1768 - TYPE_LENGTH (SYMBOL_TYPE (sym));
1774 /* If PCC says a parameter is a short or a char,
1775 it is really an int. */
1776 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) < TYPE_LENGTH (pcc_promotion_type)
1777 && TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_INT)
1780 TYPE_UNSIGNED (SYMBOL_TYPE (sym))
1781 ? pcc_unsigned_promotion_type
1782 : pcc_promotion_type;
1789 /* acc seems to use P to declare the prototypes of functions that
1790 are referenced by this file. gdb is not prepared to deal
1791 with this extra information. FIXME, it ought to. */
1794 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1795 goto process_prototype_types;
1800 /* Parameter which is in a register. */
1801 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1802 SYMBOL_CLASS (sym) = LOC_REGPARM;
1803 SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
1804 if (SYMBOL_VALUE (sym) >= NUM_REGS)
1806 complain (®_value_complaint, SYMBOL_VALUE (sym), NUM_REGS,
1807 SYMBOL_SOURCE_NAME (sym));
1808 SYMBOL_VALUE (sym) = SP_REGNUM; /* Known safe, though useless */
1810 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1811 add_symbol_to_list (sym, &local_symbols);
1815 /* Register variable (either global or local). */
1816 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1817 SYMBOL_CLASS (sym) = LOC_REGISTER;
1818 SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
1819 if (SYMBOL_VALUE (sym) >= NUM_REGS)
1821 complain (®_value_complaint, SYMBOL_VALUE (sym), NUM_REGS,
1822 SYMBOL_SOURCE_NAME (sym));
1823 SYMBOL_VALUE (sym) = SP_REGNUM; /* Known safe, though useless */
1825 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1826 if (within_function)
1828 /* Sun cc uses a pair of symbols, one 'p' and one 'r' with the same
1829 name to represent an argument passed in a register.
1830 GCC uses 'P' for the same case. So if we find such a symbol pair
1831 we combine it into one 'P' symbol. For Sun cc we need to do this
1832 regardless of REG_STRUCT_HAS_ADDR, because the compiler puts out
1833 the 'p' symbol even if it never saves the argument onto the stack.
1835 On most machines, we want to preserve both symbols, so that
1836 we can still get information about what is going on with the
1837 stack (VAX for computing args_printed, using stack slots instead
1838 of saved registers in backtraces, etc.).
1840 Note that this code illegally combines
1841 main(argc) struct foo argc; { register struct foo argc; }
1842 but this case is considered pathological and causes a warning
1843 from a decent compiler. */
1846 && local_symbols->nsyms > 0
1847 #ifndef USE_REGISTER_NOT_ARG
1848 && REG_STRUCT_HAS_ADDR_P ()
1849 && REG_STRUCT_HAS_ADDR (processing_gcc_compilation,
1851 && (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
1852 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION
1853 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_SET
1854 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_BITSTRING)
1858 struct symbol *prev_sym;
1859 prev_sym = local_symbols->symbol[local_symbols->nsyms - 1];
1860 if ((SYMBOL_CLASS (prev_sym) == LOC_REF_ARG
1861 || SYMBOL_CLASS (prev_sym) == LOC_ARG)
1862 && STREQ (SYMBOL_NAME (prev_sym), SYMBOL_NAME (sym)))
1864 SYMBOL_CLASS (prev_sym) = LOC_REGPARM;
1865 /* Use the type from the LOC_REGISTER; that is the type
1866 that is actually in that register. */
1867 SYMBOL_TYPE (prev_sym) = SYMBOL_TYPE (sym);
1868 SYMBOL_VALUE (prev_sym) = SYMBOL_VALUE (sym);
1873 add_symbol_to_list (sym, &local_symbols);
1876 add_symbol_to_list (sym, &file_symbols);
1880 /* Static symbol at top level of file */
1881 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1882 SYMBOL_CLASS (sym) = LOC_STATIC;
1883 SYMBOL_VALUE_ADDRESS (sym) = valu;
1884 #ifdef STATIC_TRANSFORM_NAME
1885 if (IS_STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym)))
1887 struct minimal_symbol *msym;
1888 msym = lookup_minimal_symbol (SYMBOL_NAME (sym), NULL, objfile);
1891 SYMBOL_NAME (sym) = STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym));
1892 SYMBOL_VALUE_ADDRESS (sym) = SYMBOL_VALUE_ADDRESS (msym);
1896 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1897 add_symbol_to_list (sym, &file_symbols);
1901 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1903 /* For a nameless type, we don't want a create a symbol, thus we
1904 did not use `sym'. Return without further processing. */
1908 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1909 SYMBOL_VALUE (sym) = valu;
1910 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1911 /* C++ vagaries: we may have a type which is derived from
1912 a base type which did not have its name defined when the
1913 derived class was output. We fill in the derived class's
1914 base part member's name here in that case. */
1915 if (TYPE_NAME (SYMBOL_TYPE (sym)) != NULL)
1916 if ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
1917 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION)
1918 && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)))
1921 for (j = TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)) - 1; j >= 0; j--)
1922 if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) == 0)
1923 TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) =
1924 type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym), j));
1927 if (TYPE_NAME (SYMBOL_TYPE (sym)) == NULL)
1929 /* gcc-2.6 or later (when using -fvtable-thunks)
1930 emits a unique named type for a vtable entry.
1931 Some gdb code depends on that specific name. */
1932 extern const char vtbl_ptr_name[];
1934 if ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_PTR
1935 && strcmp (SYMBOL_NAME (sym), vtbl_ptr_name))
1936 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_FUNC)
1938 /* If we are giving a name to a type such as "pointer to
1939 foo" or "function returning foo", we better not set
1940 the TYPE_NAME. If the program contains "typedef char
1941 *caddr_t;", we don't want all variables of type char
1942 * to print as caddr_t. This is not just a
1943 consequence of GDB's type management; PCC and GCC (at
1944 least through version 2.4) both output variables of
1945 either type char * or caddr_t with the type number
1946 defined in the 't' symbol for caddr_t. If a future
1947 compiler cleans this up it GDB is not ready for it
1948 yet, but if it becomes ready we somehow need to
1949 disable this check (without breaking the PCC/GCC2.4
1954 Fortunately, this check seems not to be necessary
1955 for anything except pointers or functions. */
1958 TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_NAME (sym);
1961 add_symbol_to_list (sym, &file_symbols);
1965 /* Struct, union, or enum tag. For GNU C++, this can be be followed
1966 by 't' which means we are typedef'ing it as well. */
1967 synonym = *p == 't';
1971 /* The semantics of C++ state that "struct foo { ... }" also defines
1972 a typedef for "foo". Unfortunately, cfront never makes the typedef
1973 when translating C++ into C. We make the typedef here so that
1974 "ptype foo" works as expected for cfront translated code. */
1975 else if (current_subfile->language == language_cplus)
1978 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1980 /* For a nameless type, we don't want a create a symbol, thus we
1981 did not use `sym'. Return without further processing. */
1985 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1986 SYMBOL_VALUE (sym) = valu;
1987 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
1988 if (TYPE_TAG_NAME (SYMBOL_TYPE (sym)) == 0)
1989 TYPE_TAG_NAME (SYMBOL_TYPE (sym))
1990 = obconcat (&objfile->type_obstack, "", "", SYMBOL_NAME (sym));
1991 add_symbol_to_list (sym, &file_symbols);
1995 /* Clone the sym and then modify it. */
1996 register struct symbol *typedef_sym = (struct symbol *)
1997 obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol));
1998 *typedef_sym = *sym;
1999 SYMBOL_CLASS (typedef_sym) = LOC_TYPEDEF;
2000 SYMBOL_VALUE (typedef_sym) = valu;
2001 SYMBOL_NAMESPACE (typedef_sym) = VAR_NAMESPACE;
2002 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
2003 TYPE_NAME (SYMBOL_TYPE (sym))
2004 = obconcat (&objfile->type_obstack, "", "", SYMBOL_NAME (sym));
2005 add_symbol_to_list (typedef_sym, &file_symbols);
2010 /* Static symbol of local scope */
2011 SYMBOL_TYPE (sym) = read_type (&p, objfile);
2012 SYMBOL_CLASS (sym) = LOC_STATIC;
2013 SYMBOL_VALUE_ADDRESS (sym) = valu;
2014 #ifdef STATIC_TRANSFORM_NAME
2015 if (IS_STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym)))
2017 struct minimal_symbol *msym;
2018 msym = lookup_minimal_symbol (SYMBOL_NAME (sym), NULL, objfile);
2021 SYMBOL_NAME (sym) = STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym));
2022 SYMBOL_VALUE_ADDRESS (sym) = SYMBOL_VALUE_ADDRESS (msym);
2026 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2028 add_symbol_to_list (sym, &global_symbols);
2030 add_symbol_to_list (sym, &local_symbols);
2034 /* Reference parameter */
2035 SYMBOL_TYPE (sym) = read_type (&p, objfile);
2036 SYMBOL_CLASS (sym) = LOC_REF_ARG;
2037 SYMBOL_VALUE (sym) = valu;
2038 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2039 add_symbol_to_list (sym, &local_symbols);
2043 /* Reference parameter which is in a register. */
2044 SYMBOL_TYPE (sym) = read_type (&p, objfile);
2045 SYMBOL_CLASS (sym) = LOC_REGPARM_ADDR;
2046 SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
2047 if (SYMBOL_VALUE (sym) >= NUM_REGS)
2049 complain (®_value_complaint, SYMBOL_VALUE (sym), NUM_REGS,
2050 SYMBOL_SOURCE_NAME (sym));
2051 SYMBOL_VALUE (sym) = SP_REGNUM; /* Known safe, though useless */
2053 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2054 add_symbol_to_list (sym, &local_symbols);
2058 /* This is used by Sun FORTRAN for "function result value".
2059 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
2060 that Pascal uses it too, but when I tried it Pascal used
2061 "x:3" (local symbol) instead. */
2062 SYMBOL_TYPE (sym) = read_type (&p, objfile);
2063 SYMBOL_CLASS (sym) = LOC_LOCAL;
2064 SYMBOL_VALUE (sym) = valu;
2065 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2066 add_symbol_to_list (sym, &local_symbols);
2069 /* New code added to support cfront stabs strings.
2070 Note: case 'P' already handled above */
2072 /* Cfront type continuation coming up!
2073 Find the original definition and add to it.
2074 We'll have to do this for the typedef too,
2075 since we cloned the symbol to define a type in read_type.
2076 Stabs info examples:
2078 foo__1CFv :ZtF (first def foo__1CFv:F(0,3);(0,24))
2079 C:ZsC;;__ct__1CFv func1__1CFv func2__1CFv ... ;;;
2080 where C is the name of the class.
2081 Unfortunately, we can't lookup the original symbol yet 'cuz
2082 we haven't finished reading all the symbols.
2083 Instead, we save it for processing later */
2084 process_later (sym, p, resolve_cfront_continuation);
2085 SYMBOL_TYPE (sym) = error_type (&p, objfile); /* FIXME! change later */
2086 SYMBOL_CLASS (sym) = LOC_CONST;
2087 SYMBOL_VALUE (sym) = 0;
2088 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2089 /* Don't add to list - we'll delete it later when
2090 we add the continuation to the real sym */
2092 /* End of new code added to support cfront stabs strings */
2095 SYMBOL_TYPE (sym) = error_type (&p, objfile);
2096 SYMBOL_CLASS (sym) = LOC_CONST;
2097 SYMBOL_VALUE (sym) = 0;
2098 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2099 add_symbol_to_list (sym, &file_symbols);
2103 /* When passing structures to a function, some systems sometimes pass
2104 the address in a register, not the structure itself. */
2106 if (REG_STRUCT_HAS_ADDR_P ()
2107 && REG_STRUCT_HAS_ADDR (processing_gcc_compilation, SYMBOL_TYPE (sym))
2108 && (SYMBOL_CLASS (sym) == LOC_REGPARM || SYMBOL_CLASS (sym) == LOC_ARG))
2110 struct type *symbol_type = check_typedef (SYMBOL_TYPE (sym));
2112 if ((TYPE_CODE (symbol_type) == TYPE_CODE_STRUCT)
2113 || (TYPE_CODE (symbol_type) == TYPE_CODE_UNION)
2114 || (TYPE_CODE (symbol_type) == TYPE_CODE_BITSTRING)
2115 || (TYPE_CODE (symbol_type) == TYPE_CODE_SET))
2117 /* If REG_STRUCT_HAS_ADDR yields non-zero we have to convert
2118 LOC_REGPARM to LOC_REGPARM_ADDR for structures and unions. */
2119 if (SYMBOL_CLASS (sym) == LOC_REGPARM)
2120 SYMBOL_CLASS (sym) = LOC_REGPARM_ADDR;
2121 /* Likewise for converting LOC_ARG to LOC_REF_ARG (for the 7th
2122 and subsequent arguments on the sparc, for example). */
2123 else if (SYMBOL_CLASS (sym) == LOC_ARG)
2124 SYMBOL_CLASS (sym) = LOC_REF_ARG;
2128 /* Is there more to parse? For example LRS/alias information? */
2129 while (*p && *p == ';')
2132 if (*p && p[0] == 'l' && p[1] == '(')
2134 /* GNU extensions for live range splitting may be appended to
2135 the end of the stab string. eg. "l(#1,#2);l(#3,#5)" */
2137 /* Resolve the live range and add it to SYM's live range list. */
2138 if (!resolve_live_range (objfile, sym, p))
2141 /* Find end of live range info. */
2142 p = strchr (p, ')');
2143 if (!*p || *p != ')')
2145 complain (&lrs_general_complaint, "live range format not recognized");
2154 /* Add the live range found in P to the symbol SYM in objfile OBJFILE. Returns
2155 non-zero on success, zero otherwise. */
2158 resolve_live_range (struct objfile *objfile, struct symbol *sym, char *p)
2161 CORE_ADDR start, end;
2163 /* Sanity check the beginning of the stabs string. */
2164 if (!*p || *p != 'l')
2166 complain (&lrs_general_complaint, "live range string 1");
2171 if (!*p || *p != '(')
2173 complain (&lrs_general_complaint, "live range string 2");
2178 /* Get starting value of range and advance P past the reference id.
2180 ?!? In theory, the process_reference should never fail, but we should
2181 catch that case just in case the compiler scrogged the stabs. */
2182 refnum = process_reference (&p);
2183 start = ref_search_value (refnum);
2186 complain (&lrs_general_complaint, "Live range symbol not found 1");
2190 if (!*p || *p != ',')
2192 complain (&lrs_general_complaint, "live range string 3");
2197 /* Get ending value of range and advance P past the reference id.
2199 ?!? In theory, the process_reference should never fail, but we should
2200 catch that case just in case the compiler scrogged the stabs. */
2201 refnum = process_reference (&p);
2202 end = ref_search_value (refnum);
2205 complain (&lrs_general_complaint, "Live range symbol not found 2");
2209 if (!*p || *p != ')')
2211 complain (&lrs_general_complaint, "live range string 4");
2215 /* Now that we know the bounds of the range, add it to the
2217 add_live_range (objfile, sym, start, end);
2222 /* Add a new live range defined by START and END to the symbol SYM
2223 in objfile OBJFILE. */
2226 add_live_range (struct objfile *objfile, struct symbol *sym, CORE_ADDR start,
2229 struct range_list *r, *rs;
2233 complain (&lrs_general_complaint, "end of live range follows start");
2237 /* Alloc new live range structure. */
2238 r = (struct range_list *)
2239 obstack_alloc (&objfile->type_obstack,
2240 sizeof (struct range_list));
2245 /* Append this range to the symbol's range list. */
2246 if (!SYMBOL_RANGES (sym))
2247 SYMBOL_RANGES (sym) = r;
2250 /* Get the last range for the symbol. */
2251 for (rs = SYMBOL_RANGES (sym); rs->next; rs = rs->next)
2258 /* Skip rest of this symbol and return an error type.
2260 General notes on error recovery: error_type always skips to the
2261 end of the symbol (modulo cretinous dbx symbol name continuation).
2262 Thus code like this:
2264 if (*(*pp)++ != ';')
2265 return error_type (pp, objfile);
2267 is wrong because if *pp starts out pointing at '\0' (typically as the
2268 result of an earlier error), it will be incremented to point to the
2269 start of the next symbol, which might produce strange results, at least
2270 if you run off the end of the string table. Instead use
2273 return error_type (pp, objfile);
2279 foo = error_type (pp, objfile);
2283 And in case it isn't obvious, the point of all this hair is so the compiler
2284 can define new types and new syntaxes, and old versions of the
2285 debugger will be able to read the new symbol tables. */
2287 static struct type *
2288 error_type (char **pp, struct objfile *objfile)
2290 complain (&error_type_complaint);
2293 /* Skip to end of symbol. */
2294 while (**pp != '\0')
2299 /* Check for and handle cretinous dbx symbol name continuation! */
2300 if ((*pp)[-1] == '\\' || (*pp)[-1] == '?')
2302 *pp = next_symbol_text (objfile);
2309 return (builtin_type_error);
2313 /* Read type information or a type definition; return the type. Even
2314 though this routine accepts either type information or a type
2315 definition, the distinction is relevant--some parts of stabsread.c
2316 assume that type information starts with a digit, '-', or '(' in
2317 deciding whether to call read_type. */
2320 read_type (register char **pp, struct objfile *objfile)
2322 register struct type *type = 0;
2325 char type_descriptor;
2327 /* Size in bits of type if specified by a type attribute, or -1 if
2328 there is no size attribute. */
2331 /* Used to distinguish string and bitstring from char-array and set. */
2334 /* Read type number if present. The type number may be omitted.
2335 for instance in a two-dimensional array declared with type
2336 "ar1;1;10;ar1;1;10;4". */
2337 if ((**pp >= '0' && **pp <= '9')
2341 if (read_type_number (pp, typenums) != 0)
2342 return error_type (pp, objfile);
2344 /* Type is not being defined here. Either it already exists,
2345 or this is a forward reference to it. dbx_alloc_type handles
2348 return dbx_alloc_type (typenums, objfile);
2350 /* Type is being defined here. */
2352 Also skip the type descriptor - we get it below with (*pp)[-1]. */
2357 /* 'typenums=' not present, type is anonymous. Read and return
2358 the definition, but don't put it in the type vector. */
2359 typenums[0] = typenums[1] = -1;
2364 type_descriptor = (*pp)[-1];
2365 switch (type_descriptor)
2369 enum type_code code;
2371 /* Used to index through file_symbols. */
2372 struct pending *ppt;
2375 /* Name including "struct", etc. */
2379 char *from, *to, *p, *q1, *q2;
2381 /* Set the type code according to the following letter. */
2385 code = TYPE_CODE_STRUCT;
2388 code = TYPE_CODE_UNION;
2391 code = TYPE_CODE_ENUM;
2395 /* Complain and keep going, so compilers can invent new
2396 cross-reference types. */
2397 static struct complaint msg =
2398 {"Unrecognized cross-reference type `%c'", 0, 0};
2399 complain (&msg, (*pp)[0]);
2400 code = TYPE_CODE_STRUCT;
2405 q1 = strchr (*pp, '<');
2406 p = strchr (*pp, ':');
2408 return error_type (pp, objfile);
2409 if (q1 && p > q1 && p[1] == ':')
2411 int nesting_level = 0;
2412 for (q2 = q1; *q2; q2++)
2416 else if (*q2 == '>')
2418 else if (*q2 == ':' && nesting_level == 0)
2423 return error_type (pp, objfile);
2426 (char *) obstack_alloc (&objfile->type_obstack, p - *pp + 1);
2428 /* Copy the name. */
2434 /* Set the pointer ahead of the name which we just read, and
2439 /* Now check to see whether the type has already been
2440 declared. This was written for arrays of cross-referenced
2441 types before we had TYPE_CODE_TARGET_STUBBED, so I'm pretty
2442 sure it is not necessary anymore. But it might be a good
2443 idea, to save a little memory. */
2445 for (ppt = file_symbols; ppt; ppt = ppt->next)
2446 for (i = 0; i < ppt->nsyms; i++)
2448 struct symbol *sym = ppt->symbol[i];
2450 if (SYMBOL_CLASS (sym) == LOC_TYPEDEF
2451 && SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE
2452 && (TYPE_CODE (SYMBOL_TYPE (sym)) == code)
2453 && STREQ (SYMBOL_NAME (sym), type_name))
2455 obstack_free (&objfile->type_obstack, type_name);
2456 type = SYMBOL_TYPE (sym);
2461 /* Didn't find the type to which this refers, so we must
2462 be dealing with a forward reference. Allocate a type
2463 structure for it, and keep track of it so we can
2464 fill in the rest of the fields when we get the full
2466 type = dbx_alloc_type (typenums, objfile);
2467 TYPE_CODE (type) = code;
2468 TYPE_TAG_NAME (type) = type_name;
2469 INIT_CPLUS_SPECIFIC (type);
2470 TYPE_FLAGS (type) |= TYPE_FLAG_STUB;
2472 add_undefined_type (type);
2476 case '-': /* RS/6000 built-in type */
2490 /* We deal with something like t(1,2)=(3,4)=... which
2491 the Lucid compiler and recent gcc versions (post 2.7.3) use. */
2493 /* Allocate and enter the typedef type first.
2494 This handles recursive types. */
2495 type = dbx_alloc_type (typenums, objfile);
2496 TYPE_CODE (type) = TYPE_CODE_TYPEDEF;
2498 struct type *xtype = read_type (pp, objfile);
2501 /* It's being defined as itself. That means it is "void". */
2502 TYPE_CODE (type) = TYPE_CODE_VOID;
2503 TYPE_LENGTH (type) = 1;
2505 else if (type_size >= 0 || is_string)
2508 TYPE_NAME (type) = NULL;
2509 TYPE_TAG_NAME (type) = NULL;
2513 TYPE_FLAGS (type) |= TYPE_FLAG_TARGET_STUB;
2514 TYPE_TARGET_TYPE (type) = xtype;
2519 /* In the following types, we must be sure to overwrite any existing
2520 type that the typenums refer to, rather than allocating a new one
2521 and making the typenums point to the new one. This is because there
2522 may already be pointers to the existing type (if it had been
2523 forward-referenced), and we must change it to a pointer, function,
2524 reference, or whatever, *in-place*. */
2527 type1 = read_type (pp, objfile);
2528 type = make_pointer_type (type1, dbx_lookup_type (typenums));
2531 case '&': /* Reference to another type */
2532 type1 = read_type (pp, objfile);
2533 type = make_reference_type (type1, dbx_lookup_type (typenums));
2536 case 'f': /* Function returning another type */
2537 if (os9k_stabs && **pp == '(')
2539 /* Function prototype; parse it.
2540 We must conditionalize this on os9k_stabs because otherwise
2541 it could be confused with a Sun-style (1,3) typenumber
2547 t = read_type (pp, objfile);
2552 type1 = read_type (pp, objfile);
2553 type = make_function_type (type1, dbx_lookup_type (typenums));
2556 case 'k': /* Const qualifier on some type (Sun) */
2557 case 'c': /* Const qualifier on some type (OS9000) */
2558 /* Because 'c' means other things to AIX and 'k' is perfectly good,
2559 only accept 'c' in the os9k_stabs case. */
2560 if (type_descriptor == 'c' && !os9k_stabs)
2561 return error_type (pp, objfile);
2562 type = read_type (pp, objfile);
2563 /* FIXME! For now, we ignore const and volatile qualifiers. */
2566 case 'B': /* Volatile qual on some type (Sun) */
2567 case 'i': /* Volatile qual on some type (OS9000) */
2568 /* Because 'i' means other things to AIX and 'B' is perfectly good,
2569 only accept 'i' in the os9k_stabs case. */
2570 if (type_descriptor == 'i' && !os9k_stabs)
2571 return error_type (pp, objfile);
2572 type = read_type (pp, objfile);
2573 /* FIXME! For now, we ignore const and volatile qualifiers. */
2577 if (isdigit (**pp) || **pp == '(' || **pp == '-')
2578 { /* Member (class & variable) type */
2579 /* FIXME -- we should be doing smash_to_XXX types here. */
2581 struct type *domain = read_type (pp, objfile);
2582 struct type *memtype;
2585 /* Invalid member type data format. */
2586 return error_type (pp, objfile);
2589 memtype = read_type (pp, objfile);
2590 type = dbx_alloc_type (typenums, objfile);
2591 smash_to_member_type (type, domain, memtype);
2594 /* type attribute */
2597 /* Skip to the semicolon. */
2598 while (**pp != ';' && **pp != '\0')
2601 return error_type (pp, objfile);
2603 ++ * pp; /* Skip the semicolon. */
2608 type_size = atoi (attr + 1);
2618 /* Ignore unrecognized type attributes, so future compilers
2619 can invent new ones. */
2627 case '#': /* Method (class & fn) type */
2628 if ((*pp)[0] == '#')
2630 /* We'll get the parameter types from the name. */
2631 struct type *return_type;
2634 return_type = read_type (pp, objfile);
2635 if (*(*pp)++ != ';')
2636 complain (&invalid_member_complaint, symnum);
2637 type = allocate_stub_method (return_type);
2638 if (typenums[0] != -1)
2639 *dbx_lookup_type (typenums) = type;
2643 struct type *domain = read_type (pp, objfile);
2644 struct type *return_type;
2648 /* Invalid member type data format. */
2649 return error_type (pp, objfile);
2653 return_type = read_type (pp, objfile);
2654 args = read_args (pp, ';', objfile);
2655 type = dbx_alloc_type (typenums, objfile);
2656 smash_to_method_type (type, domain, return_type, args);
2660 case 'r': /* Range type */
2661 type = read_range_type (pp, typenums, objfile);
2662 if (typenums[0] != -1)
2663 *dbx_lookup_type (typenums) = type;
2668 /* Const and volatile qualified type. */
2669 type = read_type (pp, objfile);
2672 /* Sun ACC builtin int type */
2673 type = read_sun_builtin_type (pp, typenums, objfile);
2674 if (typenums[0] != -1)
2675 *dbx_lookup_type (typenums) = type;
2679 case 'R': /* Sun ACC builtin float type */
2680 type = read_sun_floating_type (pp, typenums, objfile);
2681 if (typenums[0] != -1)
2682 *dbx_lookup_type (typenums) = type;
2685 case 'e': /* Enumeration type */
2686 type = dbx_alloc_type (typenums, objfile);
2687 type = read_enum_type (pp, type, objfile);
2688 if (typenums[0] != -1)
2689 *dbx_lookup_type (typenums) = type;
2692 case 's': /* Struct type */
2693 case 'u': /* Union type */
2694 type = dbx_alloc_type (typenums, objfile);
2695 switch (type_descriptor)
2698 TYPE_CODE (type) = TYPE_CODE_STRUCT;
2701 TYPE_CODE (type) = TYPE_CODE_UNION;
2704 type = read_struct_type (pp, type, objfile);
2707 case 'a': /* Array type */
2709 return error_type (pp, objfile);
2712 type = dbx_alloc_type (typenums, objfile);
2713 type = read_array_type (pp, type, objfile);
2715 TYPE_CODE (type) = TYPE_CODE_STRING;
2719 type1 = read_type (pp, objfile);
2720 type = create_set_type ((struct type *) NULL, type1);
2722 TYPE_CODE (type) = TYPE_CODE_BITSTRING;
2723 if (typenums[0] != -1)
2724 *dbx_lookup_type (typenums) = type;
2728 --*pp; /* Go back to the symbol in error */
2729 /* Particularly important if it was \0! */
2730 return error_type (pp, objfile);
2735 warning ("GDB internal error, type is NULL in stabsread.c\n");
2736 return error_type (pp, objfile);
2739 /* Size specified in a type attribute overrides any other size. */
2740 if (type_size != -1)
2741 TYPE_LENGTH (type) = (type_size + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT;
2746 /* RS/6000 xlc/dbx combination uses a set of builtin types, starting from -1.
2747 Return the proper type node for a given builtin type number. */
2749 static struct type *
2750 rs6000_builtin_type (int typenum)
2752 /* We recognize types numbered from -NUMBER_RECOGNIZED to -1. */
2753 #define NUMBER_RECOGNIZED 34
2754 /* This includes an empty slot for type number -0. */
2755 static struct type *negative_types[NUMBER_RECOGNIZED + 1];
2756 struct type *rettype = NULL;
2758 if (typenum >= 0 || typenum < -NUMBER_RECOGNIZED)
2760 complain (&rs6000_builtin_complaint, typenum);
2761 return builtin_type_error;
2763 if (negative_types[-typenum] != NULL)
2764 return negative_types[-typenum];
2766 #if TARGET_CHAR_BIT != 8
2767 #error This code wrong for TARGET_CHAR_BIT not 8
2768 /* These definitions all assume that TARGET_CHAR_BIT is 8. I think
2769 that if that ever becomes not true, the correct fix will be to
2770 make the size in the struct type to be in bits, not in units of
2777 /* The size of this and all the other types are fixed, defined
2778 by the debugging format. If there is a type called "int" which
2779 is other than 32 bits, then it should use a new negative type
2780 number (or avoid negative type numbers for that case).
2781 See stabs.texinfo. */
2782 rettype = init_type (TYPE_CODE_INT, 4, 0, "int", NULL);
2785 rettype = init_type (TYPE_CODE_INT, 1, 0, "char", NULL);
2788 rettype = init_type (TYPE_CODE_INT, 2, 0, "short", NULL);
2791 rettype = init_type (TYPE_CODE_INT, 4, 0, "long", NULL);
2794 rettype = init_type (TYPE_CODE_INT, 1, TYPE_FLAG_UNSIGNED,
2795 "unsigned char", NULL);
2798 rettype = init_type (TYPE_CODE_INT, 1, 0, "signed char", NULL);
2801 rettype = init_type (TYPE_CODE_INT, 2, TYPE_FLAG_UNSIGNED,
2802 "unsigned short", NULL);
2805 rettype = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED,
2806 "unsigned int", NULL);
2809 rettype = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED,
2812 rettype = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED,
2813 "unsigned long", NULL);
2816 rettype = init_type (TYPE_CODE_VOID, 1, 0, "void", NULL);
2819 /* IEEE single precision (32 bit). */
2820 rettype = init_type (TYPE_CODE_FLT, 4, 0, "float", NULL);
2823 /* IEEE double precision (64 bit). */
2824 rettype = init_type (TYPE_CODE_FLT, 8, 0, "double", NULL);
2827 /* This is an IEEE double on the RS/6000, and different machines with
2828 different sizes for "long double" should use different negative
2829 type numbers. See stabs.texinfo. */
2830 rettype = init_type (TYPE_CODE_FLT, 8, 0, "long double", NULL);
2833 rettype = init_type (TYPE_CODE_INT, 4, 0, "integer", NULL);
2836 rettype = init_type (TYPE_CODE_BOOL, 4, TYPE_FLAG_UNSIGNED,
2840 rettype = init_type (TYPE_CODE_FLT, 4, 0, "short real", NULL);
2843 rettype = init_type (TYPE_CODE_FLT, 8, 0, "real", NULL);
2846 rettype = init_type (TYPE_CODE_ERROR, 0, 0, "stringptr", NULL);
2849 rettype = init_type (TYPE_CODE_CHAR, 1, TYPE_FLAG_UNSIGNED,
2853 rettype = init_type (TYPE_CODE_BOOL, 1, TYPE_FLAG_UNSIGNED,
2857 rettype = init_type (TYPE_CODE_BOOL, 2, TYPE_FLAG_UNSIGNED,
2861 rettype = init_type (TYPE_CODE_BOOL, 4, TYPE_FLAG_UNSIGNED,
2865 rettype = init_type (TYPE_CODE_BOOL, 4, TYPE_FLAG_UNSIGNED,
2869 /* Complex type consisting of two IEEE single precision values. */
2870 rettype = init_type (TYPE_CODE_COMPLEX, 8, 0, "complex", NULL);
2873 /* Complex type consisting of two IEEE double precision values. */
2874 rettype = init_type (TYPE_CODE_COMPLEX, 16, 0, "double complex", NULL);
2877 rettype = init_type (TYPE_CODE_INT, 1, 0, "integer*1", NULL);
2880 rettype = init_type (TYPE_CODE_INT, 2, 0, "integer*2", NULL);
2883 rettype = init_type (TYPE_CODE_INT, 4, 0, "integer*4", NULL);
2886 rettype = init_type (TYPE_CODE_CHAR, 2, 0, "wchar", NULL);
2889 rettype = init_type (TYPE_CODE_INT, 8, 0, "long long", NULL);
2892 rettype = init_type (TYPE_CODE_INT, 8, TYPE_FLAG_UNSIGNED,
2893 "unsigned long long", NULL);
2896 rettype = init_type (TYPE_CODE_INT, 8, TYPE_FLAG_UNSIGNED,
2900 rettype = init_type (TYPE_CODE_INT, 8, 0, "integer*8", NULL);
2903 negative_types[-typenum] = rettype;
2907 /* This page contains subroutines of read_type. */
2909 /* Read member function stabs info for C++ classes. The form of each member
2912 NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
2914 An example with two member functions is:
2916 afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
2918 For the case of overloaded operators, the format is op$::*.funcs, where
2919 $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
2920 name (such as `+=') and `.' marks the end of the operator name.
2922 Returns 1 for success, 0 for failure. */
2925 read_member_functions (struct field_info *fip, char **pp, struct type *type,
2926 struct objfile *objfile)
2930 /* Total number of member functions defined in this class. If the class
2931 defines two `f' functions, and one `g' function, then this will have
2933 int total_length = 0;
2937 struct next_fnfield *next;
2938 struct fn_field fn_field;
2941 struct type *look_ahead_type;
2942 struct next_fnfieldlist *new_fnlist;
2943 struct next_fnfield *new_sublist;
2947 /* Process each list until we find something that is not a member function
2948 or find the end of the functions. */
2952 /* We should be positioned at the start of the function name.
2953 Scan forward to find the first ':' and if it is not the
2954 first of a "::" delimiter, then this is not a member function. */
2966 look_ahead_type = NULL;
2969 new_fnlist = (struct next_fnfieldlist *)
2970 xmalloc (sizeof (struct next_fnfieldlist));
2971 make_cleanup (free, new_fnlist);
2972 memset (new_fnlist, 0, sizeof (struct next_fnfieldlist));
2974 if ((*pp)[0] == 'o' && (*pp)[1] == 'p' && is_cplus_marker ((*pp)[2]))
2976 /* This is a completely wierd case. In order to stuff in the
2977 names that might contain colons (the usual name delimiter),
2978 Mike Tiemann defined a different name format which is
2979 signalled if the identifier is "op$". In that case, the
2980 format is "op$::XXXX." where XXXX is the name. This is
2981 used for names like "+" or "=". YUUUUUUUK! FIXME! */
2982 /* This lets the user type "break operator+".
2983 We could just put in "+" as the name, but that wouldn't
2985 static char opname[32] =
2986 {'o', 'p', CPLUS_MARKER};
2987 char *o = opname + 3;
2989 /* Skip past '::'. */
2992 STABS_CONTINUE (pp, objfile);
2998 main_fn_name = savestring (opname, o - opname);
3004 main_fn_name = savestring (*pp, p - *pp);
3005 /* Skip past '::'. */
3008 new_fnlist->fn_fieldlist.name = main_fn_name;
3013 (struct next_fnfield *) xmalloc (sizeof (struct next_fnfield));
3014 make_cleanup (free, new_sublist);
3015 memset (new_sublist, 0, sizeof (struct next_fnfield));
3017 /* Check for and handle cretinous dbx symbol name continuation! */
3018 if (look_ahead_type == NULL)
3021 STABS_CONTINUE (pp, objfile);
3023 new_sublist->fn_field.type = read_type (pp, objfile);
3026 /* Invalid symtab info for member function. */
3032 /* g++ version 1 kludge */
3033 new_sublist->fn_field.type = look_ahead_type;
3034 look_ahead_type = NULL;
3044 /* If this is just a stub, then we don't have the real name here. */
3046 if (TYPE_FLAGS (new_sublist->fn_field.type) & TYPE_FLAG_STUB)
3048 if (!TYPE_DOMAIN_TYPE (new_sublist->fn_field.type))
3049 TYPE_DOMAIN_TYPE (new_sublist->fn_field.type) = type;
3050 new_sublist->fn_field.is_stub = 1;
3052 new_sublist->fn_field.physname = savestring (*pp, p - *pp);
3055 /* Set this member function's visibility fields. */
3058 case VISIBILITY_PRIVATE:
3059 new_sublist->fn_field.is_private = 1;
3061 case VISIBILITY_PROTECTED:
3062 new_sublist->fn_field.is_protected = 1;
3066 STABS_CONTINUE (pp, objfile);
3069 case 'A': /* Normal functions. */
3070 new_sublist->fn_field.is_const = 0;
3071 new_sublist->fn_field.is_volatile = 0;
3074 case 'B': /* `const' member functions. */
3075 new_sublist->fn_field.is_const = 1;
3076 new_sublist->fn_field.is_volatile = 0;
3079 case 'C': /* `volatile' member function. */
3080 new_sublist->fn_field.is_const = 0;
3081 new_sublist->fn_field.is_volatile = 1;
3084 case 'D': /* `const volatile' member function. */
3085 new_sublist->fn_field.is_const = 1;
3086 new_sublist->fn_field.is_volatile = 1;
3089 case '*': /* File compiled with g++ version 1 -- no info */
3094 complain (&const_vol_complaint, **pp);
3103 /* virtual member function, followed by index.
3104 The sign bit is set to distinguish pointers-to-methods
3105 from virtual function indicies. Since the array is
3106 in words, the quantity must be shifted left by 1
3107 on 16 bit machine, and by 2 on 32 bit machine, forcing
3108 the sign bit out, and usable as a valid index into
3109 the array. Remove the sign bit here. */
3110 new_sublist->fn_field.voffset =
3111 (0x7fffffff & read_huge_number (pp, ';', &nbits)) + 2;
3115 STABS_CONTINUE (pp, objfile);
3116 if (**pp == ';' || **pp == '\0')
3118 /* Must be g++ version 1. */
3119 new_sublist->fn_field.fcontext = 0;
3123 /* Figure out from whence this virtual function came.
3124 It may belong to virtual function table of
3125 one of its baseclasses. */
3126 look_ahead_type = read_type (pp, objfile);
3129 /* g++ version 1 overloaded methods. */
3133 new_sublist->fn_field.fcontext = look_ahead_type;
3142 look_ahead_type = NULL;
3148 /* static member function. */
3149 new_sublist->fn_field.voffset = VOFFSET_STATIC;
3150 if (strncmp (new_sublist->fn_field.physname,
3151 main_fn_name, strlen (main_fn_name)))
3153 new_sublist->fn_field.is_stub = 1;
3159 complain (&member_fn_complaint, (*pp)[-1]);
3160 /* Fall through into normal member function. */
3163 /* normal member function. */
3164 new_sublist->fn_field.voffset = 0;
3165 new_sublist->fn_field.fcontext = 0;
3169 new_sublist->next = sublist;
3170 sublist = new_sublist;
3172 STABS_CONTINUE (pp, objfile);
3174 while (**pp != ';' && **pp != '\0');
3178 new_fnlist->fn_fieldlist.fn_fields = (struct fn_field *)
3179 obstack_alloc (&objfile->type_obstack,
3180 sizeof (struct fn_field) * length);
3181 memset (new_fnlist->fn_fieldlist.fn_fields, 0,
3182 sizeof (struct fn_field) * length);
3183 for (i = length; (i--, sublist); sublist = sublist->next)
3185 new_fnlist->fn_fieldlist.fn_fields[i] = sublist->fn_field;
3188 new_fnlist->fn_fieldlist.length = length;
3189 new_fnlist->next = fip->fnlist;
3190 fip->fnlist = new_fnlist;
3192 total_length += length;
3193 STABS_CONTINUE (pp, objfile);
3198 ALLOCATE_CPLUS_STRUCT_TYPE (type);
3199 TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
3200 TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * nfn_fields);
3201 memset (TYPE_FN_FIELDLISTS (type), 0,
3202 sizeof (struct fn_fieldlist) * nfn_fields);
3203 TYPE_NFN_FIELDS (type) = nfn_fields;
3204 TYPE_NFN_FIELDS_TOTAL (type) = total_length;
3210 /* Special GNU C++ name.
3212 Returns 1 for success, 0 for failure. "failure" means that we can't
3213 keep parsing and it's time for error_type(). */
3216 read_cpp_abbrev (struct field_info *fip, char **pp, struct type *type,
3217 struct objfile *objfile)
3222 struct type *context;
3232 /* At this point, *pp points to something like "22:23=*22...",
3233 where the type number before the ':' is the "context" and
3234 everything after is a regular type definition. Lookup the
3235 type, find it's name, and construct the field name. */
3237 context = read_type (pp, objfile);
3241 case 'f': /* $vf -- a virtual function table pointer */
3242 fip->list->field.name =
3243 obconcat (&objfile->type_obstack, vptr_name, "", "");
3246 case 'b': /* $vb -- a virtual bsomethingorother */
3247 name = type_name_no_tag (context);
3250 complain (&invalid_cpp_type_complaint, symnum);
3253 fip->list->field.name =
3254 obconcat (&objfile->type_obstack, vb_name, name, "");
3258 complain (&invalid_cpp_abbrev_complaint, *pp);
3259 fip->list->field.name =
3260 obconcat (&objfile->type_obstack,
3261 "INVALID_CPLUSPLUS_ABBREV", "", "");
3265 /* At this point, *pp points to the ':'. Skip it and read the
3271 complain (&invalid_cpp_abbrev_complaint, *pp);
3274 fip->list->field.type = read_type (pp, objfile);
3276 (*pp)++; /* Skip the comma. */
3282 FIELD_BITPOS (fip->list->field) = read_huge_number (pp, ';', &nbits);
3286 /* This field is unpacked. */
3287 FIELD_BITSIZE (fip->list->field) = 0;
3288 fip->list->visibility = VISIBILITY_PRIVATE;
3292 complain (&invalid_cpp_abbrev_complaint, *pp);
3293 /* We have no idea what syntax an unrecognized abbrev would have, so
3294 better return 0. If we returned 1, we would need to at least advance
3295 *pp to avoid an infinite loop. */
3302 read_one_struct_field (struct field_info *fip, char **pp, char *p,
3303 struct type *type, struct objfile *objfile)
3305 /* The following is code to work around cfront generated stabs.
3306 The stabs contains full mangled name for each field.
3307 We try to demangle the name and extract the field name out of it.
3309 if (ARM_DEMANGLING && current_subfile->language == language_cplus)
3315 dem = cplus_demangle (*pp, DMGL_ANSI | DMGL_PARAMS);
3318 dem_p = strrchr (dem, ':');
3319 if (dem_p != 0 && *(dem_p - 1) == ':')
3321 FIELD_NAME (fip->list->field) =
3322 obsavestring (dem_p, strlen (dem_p), &objfile->type_obstack);
3326 FIELD_NAME (fip->list->field) =
3327 obsavestring (*pp, p - *pp, &objfile->type_obstack);
3331 /* end of code for cfront work around */
3334 fip->list->field.name =
3335 obsavestring (*pp, p - *pp, &objfile->type_obstack);
3338 /* This means we have a visibility for a field coming. */
3342 fip->list->visibility = *(*pp)++;
3346 /* normal dbx-style format, no explicit visibility */
3347 fip->list->visibility = VISIBILITY_PUBLIC;
3350 fip->list->field.type = read_type (pp, objfile);
3355 /* Possible future hook for nested types. */
3358 fip->list->field.bitpos = (long) -2; /* nested type */
3368 /* Static class member. */
3369 SET_FIELD_PHYSNAME (fip->list->field, savestring (*pp, p - *pp));
3373 else if (**pp != ',')
3375 /* Bad structure-type format. */
3376 complain (&stabs_general_complaint, "bad structure-type format");
3380 (*pp)++; /* Skip the comma. */
3384 FIELD_BITPOS (fip->list->field) = read_huge_number (pp, ',', &nbits);
3387 complain (&stabs_general_complaint, "bad structure-type format");
3390 FIELD_BITSIZE (fip->list->field) = read_huge_number (pp, ';', &nbits);
3393 complain (&stabs_general_complaint, "bad structure-type format");
3398 if (FIELD_BITPOS (fip->list->field) == 0
3399 && FIELD_BITSIZE (fip->list->field) == 0)
3401 /* This can happen in two cases: (1) at least for gcc 2.4.5 or so,
3402 it is a field which has been optimized out. The correct stab for
3403 this case is to use VISIBILITY_IGNORE, but that is a recent
3404 invention. (2) It is a 0-size array. For example
3405 union { int num; char str[0]; } foo. Printing "<no value>" for
3406 str in "p foo" is OK, since foo.str (and thus foo.str[3])
3407 will continue to work, and a 0-size array as a whole doesn't
3408 have any contents to print.
3410 I suspect this probably could also happen with gcc -gstabs (not
3411 -gstabs+) for static fields, and perhaps other C++ extensions.
3412 Hopefully few people use -gstabs with gdb, since it is intended
3413 for dbx compatibility. */
3415 /* Ignore this field. */
3416 fip->list->visibility = VISIBILITY_IGNORE;
3420 /* Detect an unpacked field and mark it as such.
3421 dbx gives a bit size for all fields.
3422 Note that forward refs cannot be packed,
3423 and treat enums as if they had the width of ints. */
3425 struct type *field_type = check_typedef (FIELD_TYPE (fip->list->field));
3427 if (TYPE_CODE (field_type) != TYPE_CODE_INT
3428 && TYPE_CODE (field_type) != TYPE_CODE_RANGE
3429 && TYPE_CODE (field_type) != TYPE_CODE_BOOL
3430 && TYPE_CODE (field_type) != TYPE_CODE_ENUM)
3432 FIELD_BITSIZE (fip->list->field) = 0;
3434 if ((FIELD_BITSIZE (fip->list->field)
3435 == TARGET_CHAR_BIT * TYPE_LENGTH (field_type)
3436 || (TYPE_CODE (field_type) == TYPE_CODE_ENUM
3437 && FIELD_BITSIZE (fip->list->field) == TARGET_INT_BIT)
3440 FIELD_BITPOS (fip->list->field) % 8 == 0)
3442 FIELD_BITSIZE (fip->list->field) = 0;
3448 /* Read struct or class data fields. They have the form:
3450 NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
3452 At the end, we see a semicolon instead of a field.
3454 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
3457 The optional VISIBILITY is one of:
3459 '/0' (VISIBILITY_PRIVATE)
3460 '/1' (VISIBILITY_PROTECTED)
3461 '/2' (VISIBILITY_PUBLIC)
3462 '/9' (VISIBILITY_IGNORE)
3464 or nothing, for C style fields with public visibility.
3466 Returns 1 for success, 0 for failure. */
3469 read_struct_fields (struct field_info *fip, char **pp, struct type *type,
3470 struct objfile *objfile)
3473 struct nextfield *new;
3475 /* We better set p right now, in case there are no fields at all... */
3479 /* Read each data member type until we find the terminating ';' at the end of
3480 the data member list, or break for some other reason such as finding the
3481 start of the member function list. */
3485 if (os9k_stabs && **pp == ',')
3487 STABS_CONTINUE (pp, objfile);
3488 /* Get space to record the next field's data. */
3489 new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
3490 make_cleanup (free, new);
3491 memset (new, 0, sizeof (struct nextfield));
3492 new->next = fip->list;
3495 /* Get the field name. */
3498 /* If is starts with CPLUS_MARKER it is a special abbreviation,
3499 unless the CPLUS_MARKER is followed by an underscore, in
3500 which case it is just the name of an anonymous type, which we
3501 should handle like any other type name. */
3503 if (is_cplus_marker (p[0]) && p[1] != '_')
3505 if (!read_cpp_abbrev (fip, pp, type, objfile))
3510 /* Look for the ':' that separates the field name from the field
3511 values. Data members are delimited by a single ':', while member
3512 functions are delimited by a pair of ':'s. When we hit the member
3513 functions (if any), terminate scan loop and return. */
3515 while (*p != ':' && *p != '\0')
3522 /* Check to see if we have hit the member functions yet. */
3527 read_one_struct_field (fip, pp, p, type, objfile);
3529 if (p[0] == ':' && p[1] == ':')
3531 /* chill the list of fields: the last entry (at the head) is a
3532 partially constructed entry which we now scrub. */
3533 fip->list = fip->list->next;
3538 /* The stabs for C++ derived classes contain baseclass information which
3539 is marked by a '!' character after the total size. This function is
3540 called when we encounter the baseclass marker, and slurps up all the
3541 baseclass information.
3543 Immediately following the '!' marker is the number of base classes that
3544 the class is derived from, followed by information for each base class.
3545 For each base class, there are two visibility specifiers, a bit offset
3546 to the base class information within the derived class, a reference to
3547 the type for the base class, and a terminating semicolon.
3549 A typical example, with two base classes, would be "!2,020,19;0264,21;".
3551 Baseclass information marker __________________|| | | | | | |
3552 Number of baseclasses __________________________| | | | | | |
3553 Visibility specifiers (2) ________________________| | | | | |
3554 Offset in bits from start of class _________________| | | | |
3555 Type number for base class ___________________________| | | |
3556 Visibility specifiers (2) _______________________________| | |
3557 Offset in bits from start of class ________________________| |
3558 Type number of base class ____________________________________|
3560 Return 1 for success, 0 for (error-type-inducing) failure. */
3566 read_baseclasses (struct field_info *fip, char **pp, struct type *type,
3567 struct objfile *objfile)
3570 struct nextfield *new;
3578 /* Skip the '!' baseclass information marker. */
3582 ALLOCATE_CPLUS_STRUCT_TYPE (type);
3585 TYPE_N_BASECLASSES (type) = read_huge_number (pp, ',', &nbits);
3591 /* Some stupid compilers have trouble with the following, so break
3592 it up into simpler expressions. */
3593 TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *)
3594 TYPE_ALLOC (type, B_BYTES (TYPE_N_BASECLASSES (type)));
3597 int num_bytes = B_BYTES (TYPE_N_BASECLASSES (type));
3600 pointer = (char *) TYPE_ALLOC (type, num_bytes);
3601 TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *) pointer;
3605 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), TYPE_N_BASECLASSES (type));
3607 for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
3609 new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
3610 make_cleanup (free, new);
3611 memset (new, 0, sizeof (struct nextfield));
3612 new->next = fip->list;
3614 FIELD_BITSIZE (new->field) = 0; /* this should be an unpacked field! */
3616 STABS_CONTINUE (pp, objfile);
3620 /* Nothing to do. */
3623 SET_TYPE_FIELD_VIRTUAL (type, i);
3626 /* Unknown character. Complain and treat it as non-virtual. */
3628 static struct complaint msg =
3630 "Unknown virtual character `%c' for baseclass", 0, 0};
3631 complain (&msg, **pp);
3636 new->visibility = *(*pp)++;
3637 switch (new->visibility)
3639 case VISIBILITY_PRIVATE:
3640 case VISIBILITY_PROTECTED:
3641 case VISIBILITY_PUBLIC:
3644 /* Bad visibility format. Complain and treat it as
3647 static struct complaint msg =
3649 "Unknown visibility `%c' for baseclass", 0, 0
3651 complain (&msg, new->visibility);
3652 new->visibility = VISIBILITY_PUBLIC;
3659 /* The remaining value is the bit offset of the portion of the object
3660 corresponding to this baseclass. Always zero in the absence of
3661 multiple inheritance. */
3663 FIELD_BITPOS (new->field) = read_huge_number (pp, ',', &nbits);
3668 /* The last piece of baseclass information is the type of the
3669 base class. Read it, and remember it's type name as this
3672 new->field.type = read_type (pp, objfile);
3673 new->field.name = type_name_no_tag (new->field.type);
3675 /* skip trailing ';' and bump count of number of fields seen */
3684 /* The tail end of stabs for C++ classes that contain a virtual function
3685 pointer contains a tilde, a %, and a type number.
3686 The type number refers to the base class (possibly this class itself) which
3687 contains the vtable pointer for the current class.
3689 This function is called when we have parsed all the method declarations,
3690 so we can look for the vptr base class info. */
3693 read_tilde_fields (struct field_info *fip, char **pp, struct type *type,
3694 struct objfile *objfile)
3698 STABS_CONTINUE (pp, objfile);
3700 /* If we are positioned at a ';', then skip it. */
3710 if (**pp == '=' || **pp == '+' || **pp == '-')
3712 /* Obsolete flags that used to indicate the presence
3713 of constructors and/or destructors. */
3717 /* Read either a '%' or the final ';'. */
3718 if (*(*pp)++ == '%')
3720 /* The next number is the type number of the base class
3721 (possibly our own class) which supplies the vtable for
3722 this class. Parse it out, and search that class to find
3723 its vtable pointer, and install those into TYPE_VPTR_BASETYPE
3724 and TYPE_VPTR_FIELDNO. */
3729 t = read_type (pp, objfile);
3731 while (*p != '\0' && *p != ';')
3737 /* Premature end of symbol. */
3741 TYPE_VPTR_BASETYPE (type) = t;
3742 if (type == t) /* Our own class provides vtbl ptr */
3744 for (i = TYPE_NFIELDS (t) - 1;
3745 i >= TYPE_N_BASECLASSES (t);
3748 if (!strncmp (TYPE_FIELD_NAME (t, i), vptr_name,
3749 sizeof (vptr_name) - 1))
3751 TYPE_VPTR_FIELDNO (type) = i;
3755 /* Virtual function table field not found. */
3756 complain (&vtbl_notfound_complaint, TYPE_NAME (type));
3761 TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t);
3772 attach_fn_fields_to_type (struct field_info *fip, register struct type *type)
3776 for (n = TYPE_NFN_FIELDS (type);
3777 fip->fnlist != NULL;
3778 fip->fnlist = fip->fnlist->next)
3780 --n; /* Circumvent Sun3 compiler bug */
3781 TYPE_FN_FIELDLISTS (type)[n] = fip->fnlist->fn_fieldlist;
3786 /* read cfront class static data.
3787 pp points to string starting with the list of static data
3788 eg: A:ZcA;1@Bpub v2@Bvirpri;__ct__1AFv func__1AFv *sfunc__1AFv ;as__1A ;;
3791 A:ZcA;;foopri__1AFv foopro__1AFv __ct__1AFv __ct__1AFRC1A foopub__1AFv ;;;
3796 read_cfront_static_fields (struct field_info *fip, char **pp, struct type *type,
3797 struct objfile *objfile)
3799 struct nextfield *new;
3802 struct symbol *ref_static = 0;
3804 if (**pp == ';') /* no static data; return */
3810 /* Process each field in the list until we find the terminating ";" */
3812 /* eg: p = "as__1A ;;;" */
3813 STABS_CONTINUE (pp, objfile); /* handle \\ */
3814 while (**pp != ';' && (sname = get_substring (pp, ' '), sname))
3816 ref_static = lookup_symbol (sname, 0, VAR_NAMESPACE, 0, 0); /*demangled_name */
3819 static struct complaint msg =
3821 Unable to find symbol for static data field %s\n",
3823 complain (&msg, sname);
3826 stype = SYMBOL_TYPE (ref_static);
3828 /* allocate a new fip */
3829 new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
3830 make_cleanup (free, new);
3831 memset (new, 0, sizeof (struct nextfield));
3832 new->next = fip->list;
3835 /* set visibility */
3836 /* FIXME! no way to tell visibility from stabs??? */
3837 new->visibility = VISIBILITY_PUBLIC;
3839 /* set field info into fip */
3840 fip->list->field.type = stype;
3842 /* set bitpos & bitsize */
3843 SET_FIELD_PHYSNAME (fip->list->field, savestring (sname, strlen (sname)));
3845 /* set name field */
3846 /* The following is code to work around cfront generated stabs.
3847 The stabs contains full mangled name for each field.
3848 We try to demangle the name and extract the field name out of it.
3853 dem = cplus_demangle (sname, DMGL_ANSI | DMGL_PARAMS);
3856 dem_p = strrchr (dem, ':');
3857 if (dem_p != 0 && *(dem_p - 1) == ':')
3859 fip->list->field.name =
3860 obsavestring (dem_p, strlen (dem_p), &objfile->type_obstack);
3864 fip->list->field.name =
3865 obsavestring (sname, strlen (sname), &objfile->type_obstack);
3867 } /* end of code for cfront work around */
3868 } /* loop again for next static field */
3872 /* Copy structure fields to fip so attach_fields_to_type will work.
3873 type has already been created with the initial instance data fields.
3874 Now we want to be able to add the other members to the class,
3875 so we want to add them back to the fip and reattach them again
3876 once we have collected all the class members. */
3879 copy_cfront_struct_fields (struct field_info *fip, struct type *type,
3880 struct objfile *objfile)
3882 int nfields = TYPE_NFIELDS (type);
3884 struct nextfield *new;
3886 /* Copy the fields into the list of fips and reset the types
3887 to remove the old fields */
3889 for (i = 0; i < nfields; i++)
3891 /* allocate a new fip */
3892 new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
3893 make_cleanup (free, new);
3894 memset (new, 0, sizeof (struct nextfield));
3895 new->next = fip->list;
3898 /* copy field info into fip */
3899 new->field = TYPE_FIELD (type, i);
3900 /* set visibility */
3901 if (TYPE_FIELD_PROTECTED (type, i))
3902 new->visibility = VISIBILITY_PROTECTED;
3903 else if (TYPE_FIELD_PRIVATE (type, i))
3904 new->visibility = VISIBILITY_PRIVATE;
3906 new->visibility = VISIBILITY_PUBLIC;
3908 /* Now delete the fields from the type since we will be
3909 allocing new space once we get the rest of the fields
3910 in attach_fields_to_type.
3911 The pointer TYPE_FIELDS(type) is left dangling but should
3912 be freed later by objstack_free */
3913 TYPE_FIELDS (type) = 0;
3914 TYPE_NFIELDS (type) = 0;
3919 /* Create the vector of fields, and record how big it is.
3920 We need this info to record proper virtual function table information
3921 for this class's virtual functions. */
3924 attach_fields_to_type (struct field_info *fip, register struct type *type,
3925 struct objfile *objfile)
3927 register int nfields = 0;
3928 register int non_public_fields = 0;
3929 register struct nextfield *scan;
3931 /* Count up the number of fields that we have, as well as taking note of
3932 whether or not there are any non-public fields, which requires us to
3933 allocate and build the private_field_bits and protected_field_bits
3936 for (scan = fip->list; scan != NULL; scan = scan->next)
3939 if (scan->visibility != VISIBILITY_PUBLIC)
3941 non_public_fields++;
3945 /* Now we know how many fields there are, and whether or not there are any
3946 non-public fields. Record the field count, allocate space for the
3947 array of fields, and create blank visibility bitfields if necessary. */
3949 TYPE_NFIELDS (type) = nfields;
3950 TYPE_FIELDS (type) = (struct field *)
3951 TYPE_ALLOC (type, sizeof (struct field) * nfields);
3952 memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields);
3954 if (non_public_fields)
3956 ALLOCATE_CPLUS_STRUCT_TYPE (type);
3958 TYPE_FIELD_PRIVATE_BITS (type) =
3959 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
3960 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
3962 TYPE_FIELD_PROTECTED_BITS (type) =
3963 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
3964 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
3966 TYPE_FIELD_IGNORE_BITS (type) =
3967 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
3968 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields);
3971 /* Copy the saved-up fields into the field vector. Start from the head
3972 of the list, adding to the tail of the field array, so that they end
3973 up in the same order in the array in which they were added to the list. */
3975 while (nfields-- > 0)
3977 TYPE_FIELD (type, nfields) = fip->list->field;
3978 switch (fip->list->visibility)
3980 case VISIBILITY_PRIVATE:
3981 SET_TYPE_FIELD_PRIVATE (type, nfields);
3984 case VISIBILITY_PROTECTED:
3985 SET_TYPE_FIELD_PROTECTED (type, nfields);
3988 case VISIBILITY_IGNORE:
3989 SET_TYPE_FIELD_IGNORE (type, nfields);
3992 case VISIBILITY_PUBLIC:
3996 /* Unknown visibility. Complain and treat it as public. */
3998 static struct complaint msg =
4000 "Unknown visibility `%c' for field", 0, 0};
4001 complain (&msg, fip->list->visibility);
4005 fip->list = fip->list->next;
4010 /* Read the description of a structure (or union type) and return an object
4011 describing the type.
4013 PP points to a character pointer that points to the next unconsumed token
4014 in the the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
4015 *PP will point to "4a:1,0,32;;".
4017 TYPE points to an incomplete type that needs to be filled in.
4019 OBJFILE points to the current objfile from which the stabs information is
4020 being read. (Note that it is redundant in that TYPE also contains a pointer
4021 to this same objfile, so it might be a good idea to eliminate it. FIXME).
4024 static struct type *
4025 read_struct_type (char **pp, struct type *type, struct objfile *objfile)
4027 struct cleanup *back_to;
4028 struct field_info fi;
4033 back_to = make_cleanup (null_cleanup, 0);
4035 INIT_CPLUS_SPECIFIC (type);
4036 TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
4038 /* First comes the total size in bytes. */
4042 TYPE_LENGTH (type) = read_huge_number (pp, 0, &nbits);
4044 return error_type (pp, objfile);
4047 /* Now read the baseclasses, if any, read the regular C struct or C++
4048 class member fields, attach the fields to the type, read the C++
4049 member functions, attach them to the type, and then read any tilde
4050 field (baseclass specifier for the class holding the main vtable). */
4052 if (!read_baseclasses (&fi, pp, type, objfile)
4053 || !read_struct_fields (&fi, pp, type, objfile)
4054 || !attach_fields_to_type (&fi, type, objfile)
4055 || !read_member_functions (&fi, pp, type, objfile)
4056 || !attach_fn_fields_to_type (&fi, type)
4057 || !read_tilde_fields (&fi, pp, type, objfile))
4059 type = error_type (pp, objfile);
4062 do_cleanups (back_to);
4066 /* Read a definition of an array type,
4067 and create and return a suitable type object.
4068 Also creates a range type which represents the bounds of that
4071 static struct type *
4072 read_array_type (register char **pp, register struct type *type,
4073 struct objfile *objfile)
4075 struct type *index_type, *element_type, *range_type;
4080 /* Format of an array type:
4081 "ar<index type>;lower;upper;<array_contents_type>".
4082 OS9000: "arlower,upper;<array_contents_type>".
4084 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
4085 for these, produce a type like float[][]. */
4088 index_type = builtin_type_int;
4091 index_type = read_type (pp, objfile);
4093 /* Improper format of array type decl. */
4094 return error_type (pp, objfile);
4098 if (!(**pp >= '0' && **pp <= '9') && **pp != '-')
4103 lower = read_huge_number (pp, os9k_stabs ? ',' : ';', &nbits);
4105 return error_type (pp, objfile);
4107 if (!(**pp >= '0' && **pp <= '9') && **pp != '-')
4112 upper = read_huge_number (pp, ';', &nbits);
4114 return error_type (pp, objfile);
4116 element_type = read_type (pp, objfile);
4125 create_range_type ((struct type *) NULL, index_type, lower, upper);
4126 type = create_array_type (type, element_type, range_type);
4132 /* Read a definition of an enumeration type,
4133 and create and return a suitable type object.
4134 Also defines the symbols that represent the values of the type. */
4136 static struct type *
4137 read_enum_type (register char **pp, register struct type *type,
4138 struct objfile *objfile)
4143 register struct symbol *sym;
4145 struct pending **symlist;
4146 struct pending *osyms, *syms;
4149 int unsigned_enum = 1;
4152 /* FIXME! The stabs produced by Sun CC merrily define things that ought
4153 to be file-scope, between N_FN entries, using N_LSYM. What's a mother
4154 to do? For now, force all enum values to file scope. */
4155 if (within_function)
4156 symlist = &local_symbols;
4159 symlist = &file_symbols;
4161 o_nsyms = osyms ? osyms->nsyms : 0;
4165 /* Size. Perhaps this does not have to be conditionalized on
4166 os9k_stabs (assuming the name of an enum constant can't start
4168 read_huge_number (pp, 0, &nbits);
4170 return error_type (pp, objfile);
4173 /* The aix4 compiler emits an extra field before the enum members;
4174 my guess is it's a type of some sort. Just ignore it. */
4177 /* Skip over the type. */
4181 /* Skip over the colon. */
4185 /* Read the value-names and their values.
4186 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
4187 A semicolon or comma instead of a NAME means the end. */
4188 while (**pp && **pp != ';' && **pp != ',')
4190 STABS_CONTINUE (pp, objfile);
4194 name = obsavestring (*pp, p - *pp, &objfile->symbol_obstack);
4196 n = read_huge_number (pp, ',', &nbits);
4198 return error_type (pp, objfile);
4200 sym = (struct symbol *)
4201 obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol));
4202 memset (sym, 0, sizeof (struct symbol));
4203 SYMBOL_NAME (sym) = name;
4204 SYMBOL_LANGUAGE (sym) = current_subfile->language;
4205 SYMBOL_CLASS (sym) = LOC_CONST;
4206 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
4207 SYMBOL_VALUE (sym) = n;
4210 add_symbol_to_list (sym, symlist);
4215 (*pp)++; /* Skip the semicolon. */
4217 /* Now fill in the fields of the type-structure. */
4219 TYPE_LENGTH (type) = TARGET_INT_BIT / HOST_CHAR_BIT;
4220 TYPE_CODE (type) = TYPE_CODE_ENUM;
4221 TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
4223 TYPE_FLAGS (type) |= TYPE_FLAG_UNSIGNED;
4224 TYPE_NFIELDS (type) = nsyms;
4225 TYPE_FIELDS (type) = (struct field *)
4226 TYPE_ALLOC (type, sizeof (struct field) * nsyms);
4227 memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nsyms);
4229 /* Find the symbols for the values and put them into the type.
4230 The symbols can be found in the symlist that we put them on
4231 to cause them to be defined. osyms contains the old value
4232 of that symlist; everything up to there was defined by us. */
4233 /* Note that we preserve the order of the enum constants, so
4234 that in something like "enum {FOO, LAST_THING=FOO}" we print
4235 FOO, not LAST_THING. */
4237 for (syms = *symlist, n = nsyms - 1; syms; syms = syms->next)
4239 int last = syms == osyms ? o_nsyms : 0;
4240 int j = syms->nsyms;
4241 for (; --j >= last; --n)
4243 struct symbol *xsym = syms->symbol[j];
4244 SYMBOL_TYPE (xsym) = type;
4245 TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym);
4246 TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (xsym);
4247 TYPE_FIELD_BITSIZE (type, n) = 0;
4256 /* Sun's ACC uses a somewhat saner method for specifying the builtin
4257 typedefs in every file (for int, long, etc):
4259 type = b <signed> <width> <format type>; <offset>; <nbits>
4261 optional format type = c or b for char or boolean.
4262 offset = offset from high order bit to start bit of type.
4263 width is # bytes in object of this type, nbits is # bits in type.
4265 The width/offset stuff appears to be for small objects stored in
4266 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
4269 static struct type *
4270 read_sun_builtin_type (char **pp, int typenums[2], struct objfile *objfile)
4275 enum type_code code = TYPE_CODE_INT;
4286 return error_type (pp, objfile);
4290 /* For some odd reason, all forms of char put a c here. This is strange
4291 because no other type has this honor. We can safely ignore this because
4292 we actually determine 'char'acterness by the number of bits specified in
4294 Boolean forms, e.g Fortran logical*X, put a b here. */
4298 else if (**pp == 'b')
4300 code = TYPE_CODE_BOOL;
4304 /* The first number appears to be the number of bytes occupied
4305 by this type, except that unsigned short is 4 instead of 2.
4306 Since this information is redundant with the third number,
4307 we will ignore it. */
4308 read_huge_number (pp, ';', &nbits);
4310 return error_type (pp, objfile);
4312 /* The second number is always 0, so ignore it too. */
4313 read_huge_number (pp, ';', &nbits);
4315 return error_type (pp, objfile);
4317 /* The third number is the number of bits for this type. */
4318 type_bits = read_huge_number (pp, 0, &nbits);
4320 return error_type (pp, objfile);
4321 /* The type *should* end with a semicolon. If it are embedded
4322 in a larger type the semicolon may be the only way to know where
4323 the type ends. If this type is at the end of the stabstring we
4324 can deal with the omitted semicolon (but we don't have to like
4325 it). Don't bother to complain(), Sun's compiler omits the semicolon
4331 return init_type (TYPE_CODE_VOID, 1,
4332 signed_type ? 0 : TYPE_FLAG_UNSIGNED, (char *) NULL,
4335 return init_type (code,
4336 type_bits / TARGET_CHAR_BIT,
4337 signed_type ? 0 : TYPE_FLAG_UNSIGNED, (char *) NULL,
4341 static struct type *
4342 read_sun_floating_type (char **pp, int typenums[2], struct objfile *objfile)
4348 /* The first number has more details about the type, for example
4350 details = read_huge_number (pp, ';', &nbits);
4352 return error_type (pp, objfile);
4354 /* The second number is the number of bytes occupied by this type */
4355 nbytes = read_huge_number (pp, ';', &nbits);
4357 return error_type (pp, objfile);
4359 if (details == NF_COMPLEX || details == NF_COMPLEX16
4360 || details == NF_COMPLEX32)
4361 /* This is a type we can't handle, but we do know the size.
4362 We also will be able to give it a name. */
4363 return init_type (TYPE_CODE_COMPLEX, nbytes, 0, NULL, objfile);
4365 return init_type (TYPE_CODE_FLT, nbytes, 0, NULL, objfile);
4368 /* Read a number from the string pointed to by *PP.
4369 The value of *PP is advanced over the number.
4370 If END is nonzero, the character that ends the
4371 number must match END, or an error happens;
4372 and that character is skipped if it does match.
4373 If END is zero, *PP is left pointing to that character.
4375 If the number fits in a long, set *BITS to 0 and return the value.
4376 If not, set *BITS to be the number of bits in the number and return 0.
4378 If encounter garbage, set *BITS to -1 and return 0. */
4381 read_huge_number (char **pp, int end, int *bits)
4398 /* Leading zero means octal. GCC uses this to output values larger
4399 than an int (because that would be hard in decimal). */
4407 upper_limit = ULONG_MAX / radix;
4409 upper_limit = LONG_MAX / radix;
4411 while ((c = *p++) >= '0' && c < ('0' + radix))
4413 if (n <= upper_limit)
4416 n += c - '0'; /* FIXME this overflows anyway */
4421 /* This depends on large values being output in octal, which is
4428 /* Ignore leading zeroes. */
4432 else if (c == '2' || c == '3')
4458 /* Large decimal constants are an error (because it is hard to
4459 count how many bits are in them). */
4465 /* -0x7f is the same as 0x80. So deal with it by adding one to
4466 the number of bits. */
4478 /* It's *BITS which has the interesting information. */
4482 static struct type *
4483 read_range_type (char **pp, int typenums[2], struct objfile *objfile)
4485 char *orig_pp = *pp;
4490 struct type *result_type;
4491 struct type *index_type = NULL;
4493 /* First comes a type we are a subrange of.
4494 In C it is usually 0, 1 or the type being defined. */
4495 if (read_type_number (pp, rangenums) != 0)
4496 return error_type (pp, objfile);
4497 self_subrange = (rangenums[0] == typenums[0] &&
4498 rangenums[1] == typenums[1]);
4503 index_type = read_type (pp, objfile);
4506 /* A semicolon should now follow; skip it. */
4510 /* The remaining two operands are usually lower and upper bounds
4511 of the range. But in some special cases they mean something else. */
4512 n2 = read_huge_number (pp, ';', &n2bits);
4513 n3 = read_huge_number (pp, ';', &n3bits);
4515 if (n2bits == -1 || n3bits == -1)
4516 return error_type (pp, objfile);
4519 goto handle_true_range;
4521 /* If limits are huge, must be large integral type. */
4522 if (n2bits != 0 || n3bits != 0)
4524 char got_signed = 0;
4525 char got_unsigned = 0;
4526 /* Number of bits in the type. */
4529 /* Range from 0 to <large number> is an unsigned large integral type. */
4530 if ((n2bits == 0 && n2 == 0) && n3bits != 0)
4535 /* Range from <large number> to <large number>-1 is a large signed
4536 integral type. Take care of the case where <large number> doesn't
4537 fit in a long but <large number>-1 does. */
4538 else if ((n2bits != 0 && n3bits != 0 && n2bits == n3bits + 1)
4539 || (n2bits != 0 && n3bits == 0
4540 && (n2bits == sizeof (long) * HOST_CHAR_BIT)
4547 if (got_signed || got_unsigned)
4549 return init_type (TYPE_CODE_INT, nbits / TARGET_CHAR_BIT,
4550 got_unsigned ? TYPE_FLAG_UNSIGNED : 0, NULL,
4554 return error_type (pp, objfile);
4557 /* A type defined as a subrange of itself, with bounds both 0, is void. */
4558 if (self_subrange && n2 == 0 && n3 == 0)
4559 return init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile);
4561 /* If n3 is zero and n2 is positive, we want a floating type, and n2
4562 is the width in bytes.
4564 Fortran programs appear to use this for complex types also. To
4565 distinguish between floats and complex, g77 (and others?) seem
4566 to use self-subranges for the complexes, and subranges of int for
4569 Also note that for complexes, g77 sets n2 to the size of one of
4570 the member floats, not the whole complex beast. My guess is that
4571 this was to work well with pre-COMPLEX versions of gdb. */
4573 if (n3 == 0 && n2 > 0)
4577 return init_type (TYPE_CODE_COMPLEX, 2 * n2, 0, NULL, objfile);
4581 return init_type (TYPE_CODE_FLT, n2, 0, NULL, objfile);
4585 /* If the upper bound is -1, it must really be an unsigned int. */
4587 else if (n2 == 0 && n3 == -1)
4589 /* It is unsigned int or unsigned long. */
4590 /* GCC 2.3.3 uses this for long long too, but that is just a GDB 3.5
4591 compatibility hack. */
4592 return init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
4593 TYPE_FLAG_UNSIGNED, NULL, objfile);
4596 /* Special case: char is defined (Who knows why) as a subrange of
4597 itself with range 0-127. */
4598 else if (self_subrange && n2 == 0 && n3 == 127)
4599 return init_type (TYPE_CODE_INT, 1, 0, NULL, objfile);
4601 else if (current_symbol && SYMBOL_LANGUAGE (current_symbol) == language_chill
4603 goto handle_true_range;
4605 /* We used to do this only for subrange of self or subrange of int. */
4608 /* -1 is used for the upper bound of (4 byte) "unsigned int" and
4609 "unsigned long", and we already checked for that,
4610 so don't need to test for it here. */
4613 /* n3 actually gives the size. */
4614 return init_type (TYPE_CODE_INT, -n3, TYPE_FLAG_UNSIGNED,
4617 /* Is n3 == 2**(8n)-1 for some integer n? Then it's an
4618 unsigned n-byte integer. But do require n to be a power of
4619 two; we don't want 3- and 5-byte integers flying around. */
4625 for (bytes = 0; (bits & 0xff) == 0xff; bytes++)
4628 && ((bytes - 1) & bytes) == 0) /* "bytes is a power of two" */
4629 return init_type (TYPE_CODE_INT, bytes, TYPE_FLAG_UNSIGNED, NULL,
4633 /* I think this is for Convex "long long". Since I don't know whether
4634 Convex sets self_subrange, I also accept that particular size regardless
4635 of self_subrange. */
4636 else if (n3 == 0 && n2 < 0
4638 || n2 == -TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT))
4639 return init_type (TYPE_CODE_INT, -n2, 0, NULL, objfile);
4640 else if (n2 == -n3 - 1)
4643 return init_type (TYPE_CODE_INT, 1, 0, NULL, objfile);
4645 return init_type (TYPE_CODE_INT, 2, 0, NULL, objfile);
4646 if (n3 == 0x7fffffff)
4647 return init_type (TYPE_CODE_INT, 4, 0, NULL, objfile);
4650 /* We have a real range type on our hands. Allocate space and
4651 return a real pointer. */
4655 index_type = builtin_type_int;
4657 index_type = *dbx_lookup_type (rangenums);
4658 if (index_type == NULL)
4660 /* Does this actually ever happen? Is that why we are worrying
4661 about dealing with it rather than just calling error_type? */
4663 static struct type *range_type_index;
4665 complain (&range_type_base_complaint, rangenums[1]);
4666 if (range_type_index == NULL)
4668 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
4669 0, "range type index type", NULL);
4670 index_type = range_type_index;
4673 result_type = create_range_type ((struct type *) NULL, index_type, n2, n3);
4674 return (result_type);
4677 /* Read in an argument list. This is a list of types, separated by commas
4678 and terminated with END. Return the list of types read in, or (struct type
4679 **)-1 if there is an error. */
4681 static struct type **
4682 read_args (char **pp, int end, struct objfile *objfile)
4684 /* FIXME! Remove this arbitrary limit! */
4685 struct type *types[1024], **rval; /* allow for fns of 1023 parameters */
4691 /* Invalid argument list: no ','. */
4692 return (struct type **) -1;
4694 STABS_CONTINUE (pp, objfile);
4695 types[n++] = read_type (pp, objfile);
4697 (*pp)++; /* get past `end' (the ':' character) */
4701 rval = (struct type **) xmalloc (2 * sizeof (struct type *));
4703 else if (TYPE_CODE (types[n - 1]) != TYPE_CODE_VOID)
4705 rval = (struct type **) xmalloc ((n + 1) * sizeof (struct type *));
4706 memset (rval + n, 0, sizeof (struct type *));
4710 rval = (struct type **) xmalloc (n * sizeof (struct type *));
4712 memcpy (rval, types, n * sizeof (struct type *));
4716 /* Common block handling. */
4718 /* List of symbols declared since the last BCOMM. This list is a tail
4719 of local_symbols. When ECOMM is seen, the symbols on the list
4720 are noted so their proper addresses can be filled in later,
4721 using the common block base address gotten from the assembler
4724 static struct pending *common_block;
4725 static int common_block_i;
4727 /* Name of the current common block. We get it from the BCOMM instead of the
4728 ECOMM to match IBM documentation (even though IBM puts the name both places
4729 like everyone else). */
4730 static char *common_block_name;
4732 /* Process a N_BCOMM symbol. The storage for NAME is not guaranteed
4733 to remain after this function returns. */
4736 common_block_start (char *name, struct objfile *objfile)
4738 if (common_block_name != NULL)
4740 static struct complaint msg =
4742 "Invalid symbol data: common block within common block",
4746 common_block = local_symbols;
4747 common_block_i = local_symbols ? local_symbols->nsyms : 0;
4748 common_block_name = obsavestring (name, strlen (name),
4749 &objfile->symbol_obstack);
4752 /* Process a N_ECOMM symbol. */
4755 common_block_end (struct objfile *objfile)
4757 /* Symbols declared since the BCOMM are to have the common block
4758 start address added in when we know it. common_block and
4759 common_block_i point to the first symbol after the BCOMM in
4760 the local_symbols list; copy the list and hang it off the
4761 symbol for the common block name for later fixup. */
4764 struct pending *new = 0;
4765 struct pending *next;
4768 if (common_block_name == NULL)
4770 static struct complaint msg =
4771 {"ECOMM symbol unmatched by BCOMM", 0, 0};
4776 sym = (struct symbol *)
4777 obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol));
4778 memset (sym, 0, sizeof (struct symbol));
4779 /* Note: common_block_name already saved on symbol_obstack */
4780 SYMBOL_NAME (sym) = common_block_name;
4781 SYMBOL_CLASS (sym) = LOC_BLOCK;
4783 /* Now we copy all the symbols which have been defined since the BCOMM. */
4785 /* Copy all the struct pendings before common_block. */
4786 for (next = local_symbols;
4787 next != NULL && next != common_block;
4790 for (j = 0; j < next->nsyms; j++)
4791 add_symbol_to_list (next->symbol[j], &new);
4794 /* Copy however much of COMMON_BLOCK we need. If COMMON_BLOCK is
4795 NULL, it means copy all the local symbols (which we already did
4798 if (common_block != NULL)
4799 for (j = common_block_i; j < common_block->nsyms; j++)
4800 add_symbol_to_list (common_block->symbol[j], &new);
4802 SYMBOL_TYPE (sym) = (struct type *) new;
4804 /* Should we be putting local_symbols back to what it was?
4807 i = hashname (SYMBOL_NAME (sym));
4808 SYMBOL_VALUE_CHAIN (sym) = global_sym_chain[i];
4809 global_sym_chain[i] = sym;
4810 common_block_name = NULL;
4813 /* Add a common block's start address to the offset of each symbol
4814 declared to be in it (by being between a BCOMM/ECOMM pair that uses
4815 the common block name). */
4818 fix_common_block (struct symbol *sym, int valu)
4820 struct pending *next = (struct pending *) SYMBOL_TYPE (sym);
4821 for (; next; next = next->next)
4824 for (j = next->nsyms - 1; j >= 0; j--)
4825 SYMBOL_VALUE_ADDRESS (next->symbol[j]) += valu;
4831 /* What about types defined as forward references inside of a small lexical
4833 /* Add a type to the list of undefined types to be checked through
4834 once this file has been read in. */
4837 add_undefined_type (struct type *type)
4839 if (undef_types_length == undef_types_allocated)
4841 undef_types_allocated *= 2;
4842 undef_types = (struct type **)
4843 xrealloc ((char *) undef_types,
4844 undef_types_allocated * sizeof (struct type *));
4846 undef_types[undef_types_length++] = type;
4849 /* Go through each undefined type, see if it's still undefined, and fix it
4850 up if possible. We have two kinds of undefined types:
4852 TYPE_CODE_ARRAY: Array whose target type wasn't defined yet.
4853 Fix: update array length using the element bounds
4854 and the target type's length.
4855 TYPE_CODE_STRUCT, TYPE_CODE_UNION: Structure whose fields were not
4856 yet defined at the time a pointer to it was made.
4857 Fix: Do a full lookup on the struct/union tag. */
4859 cleanup_undefined_types (void)
4863 for (type = undef_types; type < undef_types + undef_types_length; type++)
4865 switch (TYPE_CODE (*type))
4868 case TYPE_CODE_STRUCT:
4869 case TYPE_CODE_UNION:
4870 case TYPE_CODE_ENUM:
4872 /* Check if it has been defined since. Need to do this here
4873 as well as in check_typedef to deal with the (legitimate in
4874 C though not C++) case of several types with the same name
4875 in different source files. */
4876 if (TYPE_FLAGS (*type) & TYPE_FLAG_STUB)
4878 struct pending *ppt;
4880 /* Name of the type, without "struct" or "union" */
4881 char *typename = TYPE_TAG_NAME (*type);
4883 if (typename == NULL)
4885 static struct complaint msg =
4886 {"need a type name", 0, 0};
4890 for (ppt = file_symbols; ppt; ppt = ppt->next)
4892 for (i = 0; i < ppt->nsyms; i++)
4894 struct symbol *sym = ppt->symbol[i];
4896 if (SYMBOL_CLASS (sym) == LOC_TYPEDEF
4897 && SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE
4898 && (TYPE_CODE (SYMBOL_TYPE (sym)) ==
4900 && STREQ (SYMBOL_NAME (sym), typename))
4902 memcpy (*type, SYMBOL_TYPE (sym),
4903 sizeof (struct type));
4913 static struct complaint msg =
4915 GDB internal error. cleanup_undefined_types with bad type %d.", 0, 0};
4916 complain (&msg, TYPE_CODE (*type));
4922 undef_types_length = 0;
4925 /* Scan through all of the global symbols defined in the object file,
4926 assigning values to the debugging symbols that need to be assigned
4927 to. Get these symbols from the minimal symbol table. */
4930 scan_file_globals (struct objfile *objfile)
4933 struct minimal_symbol *msymbol;
4934 struct symbol *sym, *prev, *rsym;
4935 struct objfile *resolve_objfile;
4937 /* SVR4 based linkers copy referenced global symbols from shared
4938 libraries to the main executable.
4939 If we are scanning the symbols for a shared library, try to resolve
4940 them from the minimal symbols of the main executable first. */
4942 if (symfile_objfile && objfile != symfile_objfile)
4943 resolve_objfile = symfile_objfile;
4945 resolve_objfile = objfile;
4949 /* Avoid expensive loop through all minimal symbols if there are
4950 no unresolved symbols. */
4951 for (hash = 0; hash < HASHSIZE; hash++)
4953 if (global_sym_chain[hash])
4956 if (hash >= HASHSIZE)
4959 for (msymbol = resolve_objfile->msymbols;
4960 msymbol && SYMBOL_NAME (msymbol) != NULL;
4965 /* Skip static symbols. */
4966 switch (MSYMBOL_TYPE (msymbol))
4978 /* Get the hash index and check all the symbols
4979 under that hash index. */
4981 hash = hashname (SYMBOL_NAME (msymbol));
4983 for (sym = global_sym_chain[hash]; sym;)
4985 if (SYMBOL_NAME (msymbol)[0] == SYMBOL_NAME (sym)[0] &&
4986 STREQ (SYMBOL_NAME (msymbol) + 1, SYMBOL_NAME (sym) + 1))
4989 struct alias_list *aliases;
4991 /* Splice this symbol out of the hash chain and
4992 assign the value we have to it. */
4995 SYMBOL_VALUE_CHAIN (prev) = SYMBOL_VALUE_CHAIN (sym);
4999 global_sym_chain[hash] = SYMBOL_VALUE_CHAIN (sym);
5002 /* Check to see whether we need to fix up a common block. */
5003 /* Note: this code might be executed several times for
5004 the same symbol if there are multiple references. */
5006 /* If symbol has aliases, do minimal symbol fixups for each.
5007 These live aliases/references weren't added to
5008 global_sym_chain hash but may also need to be fixed up. */
5009 /* FIXME: Maybe should have added aliases to the global chain, resolved symbol name, then treated aliases as normal
5010 symbols? Still, we wouldn't want to add_to_list. */
5011 /* Now do the same for each alias of this symbol */
5013 aliases = SYMBOL_ALIASES (sym);
5016 if (SYMBOL_CLASS (rsym) == LOC_BLOCK)
5018 fix_common_block (rsym,
5019 SYMBOL_VALUE_ADDRESS (msymbol));
5023 SYMBOL_VALUE_ADDRESS (rsym)
5024 = SYMBOL_VALUE_ADDRESS (msymbol);
5026 SYMBOL_SECTION (rsym) = SYMBOL_SECTION (msymbol);
5029 rsym = aliases->sym;
5030 aliases = aliases->next;
5039 sym = SYMBOL_VALUE_CHAIN (prev);
5043 sym = global_sym_chain[hash];
5049 sym = SYMBOL_VALUE_CHAIN (sym);
5053 if (resolve_objfile == objfile)
5055 resolve_objfile = objfile;
5058 /* Change the storage class of any remaining unresolved globals to
5059 LOC_UNRESOLVED and remove them from the chain. */
5060 for (hash = 0; hash < HASHSIZE; hash++)
5062 sym = global_sym_chain[hash];
5066 sym = SYMBOL_VALUE_CHAIN (sym);
5068 /* Change the symbol address from the misleading chain value
5070 SYMBOL_VALUE_ADDRESS (prev) = 0;
5072 /* Complain about unresolved common block symbols. */
5073 if (SYMBOL_CLASS (prev) == LOC_STATIC)
5074 SYMBOL_CLASS (prev) = LOC_UNRESOLVED;
5076 complain (&unresolved_sym_chain_complaint,
5077 objfile->name, SYMBOL_NAME (prev));
5080 memset (global_sym_chain, 0, sizeof (global_sym_chain));
5083 /* Initialize anything that needs initializing when starting to read
5084 a fresh piece of a symbol file, e.g. reading in the stuff corresponding
5088 stabsread_init (void)
5092 /* Initialize anything that needs initializing when a completely new
5093 symbol file is specified (not just adding some symbols from another
5094 file, e.g. a shared library). */
5097 stabsread_new_init (void)
5099 /* Empty the hash table of global syms looking for values. */
5100 memset (global_sym_chain, 0, sizeof (global_sym_chain));
5103 /* Initialize anything that needs initializing at the same time as
5104 start_symtab() is called. */
5109 global_stabs = NULL; /* AIX COFF */
5110 /* Leave FILENUM of 0 free for builtin types and this file's types. */
5111 n_this_object_header_files = 1;
5112 type_vector_length = 0;
5113 type_vector = (struct type **) 0;
5115 /* FIXME: If common_block_name is not already NULL, we should complain(). */
5116 common_block_name = NULL;
5121 /* Call after end_symtab() */
5128 free ((char *) type_vector);
5131 type_vector_length = 0;
5132 previous_stab_code = 0;
5136 finish_global_stabs (struct objfile *objfile)
5140 patch_block_stabs (global_symbols, global_stabs, objfile);
5141 free ((PTR) global_stabs);
5142 global_stabs = NULL;
5146 /* Initializer for this module */
5149 _initialize_stabsread (void)
5151 undef_types_allocated = 20;
5152 undef_types_length = 0;
5153 undef_types = (struct type **)
5154 xmalloc (undef_types_allocated * sizeof (struct type *));