1 /* Support routines for decoding "stabs" debugging information format.
2 Copyright 1986, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 1997
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, Boston, MA 02111-1307, USA. */
21 /* Support routines for reading and decoding debugging information in
22 the "stabs" format. This format is used with many systems that use
23 the a.out object file format, as well as some systems that use
24 COFF or ELF where the stabs data is placed in a special section.
25 Avoid placing any object file format specific code in this file. */
28 #include "gdb_string.h"
33 #include "expression.h"
36 #include "aout/stab_gnu.h" /* We always use GNU stabs, not native */
38 #include "aout/aout64.h"
39 #include "gdb-stabs.h"
41 #include "complaints.h"
47 /* Ask stabsread.h to define the vars it normally declares `extern'. */
49 #include "stabsread.h" /* Our own declarations */
52 /* The routines that read and process a complete stabs for a C struct or
53 C++ class pass lists of data member fields and lists of member function
54 fields in an instance of a field_info structure, as defined below.
55 This is part of some reorganization of low level C++ support and is
56 expected to eventually go away... (FIXME) */
62 struct nextfield *next;
64 /* This is the raw visibility from the stab. It is not checked
65 for being one of the visibilities we recognize, so code which
66 examines this field better be able to deal. */
71 struct next_fnfieldlist
73 struct next_fnfieldlist *next;
74 struct fn_fieldlist fn_fieldlist;
79 read_one_struct_field PARAMS ((struct field_info *, char **, char *,
80 struct type *, struct objfile *));
83 get_substring PARAMS ((char **, int));
86 dbx_alloc_type PARAMS ((int [2], struct objfile *));
88 static long read_huge_number PARAMS ((char **, int, int *));
90 static struct type *error_type PARAMS ((char **, struct objfile *));
93 patch_block_stabs PARAMS ((struct pending *, struct pending_stabs *,
97 fix_common_block PARAMS ((struct symbol *, int));
100 read_type_number PARAMS ((char **, int *));
103 read_range_type PARAMS ((char **, int [2], struct objfile *));
106 read_sun_builtin_type PARAMS ((char **, int [2], struct objfile *));
109 read_sun_floating_type PARAMS ((char **, int [2], struct objfile *));
112 read_enum_type PARAMS ((char **, struct type *, struct objfile *));
115 rs6000_builtin_type PARAMS ((int));
118 read_member_functions PARAMS ((struct field_info *, char **, struct type *,
122 read_struct_fields PARAMS ((struct field_info *, char **, struct type *,
126 read_baseclasses PARAMS ((struct field_info *, char **, struct type *,
130 read_tilde_fields PARAMS ((struct field_info *, char **, struct type *,
134 attach_fn_fields_to_type PARAMS ((struct field_info *, struct type *));
137 attach_fields_to_type PARAMS ((struct field_info *, struct type *,
141 read_struct_type PARAMS ((char **, struct type *, struct objfile *));
144 read_array_type PARAMS ((char **, struct type *, struct objfile *));
146 static struct type **
147 read_args PARAMS ((char **, int, struct objfile *));
150 read_cpp_abbrev PARAMS ((struct field_info *, char **, struct type *,
153 /* new functions added for cfront support */
156 copy_cfront_struct_fields PARAMS ((struct field_info *, struct type *,
160 get_cfront_method_physname PARAMS ((char *));
163 read_cfront_baseclasses PARAMS ((struct field_info *, char **,
164 struct type *, struct objfile *));
167 read_cfront_static_fields PARAMS ((struct field_info *, char**,
168 struct type *, struct objfile *));
170 read_cfront_member_functions PARAMS ((struct field_info *, char **,
171 struct type *, struct objfile *));
173 /* end new functions added for cfront support */
176 add_live_range PARAMS ((struct objfile *, struct symbol *,
177 CORE_ADDR, CORE_ADDR));
180 resolve_live_range PARAMS ((struct objfile *, struct symbol *, char *));
183 process_reference PARAMS ((char **string));
186 ref_search_value PARAMS ((int refnum));
189 ref_init PARAMS ((void));
192 resolve_symbol_reference PARAMS ((struct objfile *, struct symbol *, char *));
194 static const char vptr_name[] = { '_','v','p','t','r',CPLUS_MARKER,'\0' };
195 static const char vb_name[] = { '_','v','b',CPLUS_MARKER,'\0' };
197 /* Define this as 1 if a pcc declaration of a char or short argument
198 gives the correct address. Otherwise assume pcc gives the
199 address of the corresponding int, which is not the same on a
200 big-endian machine. */
202 #ifndef BELIEVE_PCC_PROMOTION
203 #define BELIEVE_PCC_PROMOTION 0
206 struct complaint invalid_cpp_abbrev_complaint =
207 {"invalid C++ abbreviation `%s'", 0, 0};
209 struct complaint invalid_cpp_type_complaint =
210 {"C++ abbreviated type name unknown at symtab pos %d", 0, 0};
212 struct complaint member_fn_complaint =
213 {"member function type missing, got '%c'", 0, 0};
215 struct complaint const_vol_complaint =
216 {"const/volatile indicator missing, got '%c'", 0, 0};
218 struct complaint error_type_complaint =
219 {"debug info mismatch between compiler and debugger", 0, 0};
221 struct complaint invalid_member_complaint =
222 {"invalid (minimal) member type data format at symtab pos %d.", 0, 0};
224 struct complaint range_type_base_complaint =
225 {"base type %d of range type is not defined", 0, 0};
227 struct complaint reg_value_complaint =
228 {"register number %d too large (max %d) in symbol %s", 0, 0};
230 struct complaint vtbl_notfound_complaint =
231 {"virtual function table pointer not found when defining class `%s'", 0, 0};
233 struct complaint unrecognized_cplus_name_complaint =
234 {"Unknown C++ symbol name `%s'", 0, 0};
236 struct complaint rs6000_builtin_complaint =
237 {"Unknown builtin type %d", 0, 0};
239 struct complaint unresolved_sym_chain_complaint =
240 {"%s: common block `%s' from global_sym_chain unresolved", 0, 0};
242 struct complaint stabs_general_complaint =
245 /* Make a list of forward references which haven't been defined. */
247 static struct type **undef_types;
248 static int undef_types_allocated;
249 static int undef_types_length;
250 static struct symbol *current_symbol = NULL;
252 /* Check for and handle cretinous stabs symbol name continuation! */
253 #define STABS_CONTINUE(pp,objfile) \
255 if (**(pp) == '\\' || (**(pp) == '?' && (*(pp))[1] == '\0')) \
256 *(pp) = next_symbol_text (objfile); \
259 /* FIXME: These probably should be our own types (like rs6000_builtin_type
260 has its own types) rather than builtin_type_*. */
261 static struct type **os9k_type_vector[] = {
267 &builtin_type_unsigned_char,
268 &builtin_type_unsigned_short,
269 &builtin_type_unsigned_long,
270 &builtin_type_unsigned_int,
272 &builtin_type_double,
274 &builtin_type_long_double
277 static void os9k_init_type_vector PARAMS ((struct type **));
280 os9k_init_type_vector(tv)
284 for (i=0; i<sizeof(os9k_type_vector)/sizeof(struct type **); i++)
285 tv[i] = (os9k_type_vector[i] == 0 ? 0 : *(os9k_type_vector[i]));
288 /* Look up a dbx type-number pair. Return the address of the slot
289 where the type for that number-pair is stored.
290 The number-pair is in TYPENUMS.
292 This can be used for finding the type associated with that pair
293 or for associating a new type with the pair. */
296 dbx_lookup_type (typenums)
299 register int filenum = typenums[0];
300 register int index = typenums[1];
302 register int real_filenum;
303 register struct header_file *f;
306 if (filenum == -1) /* -1,-1 is for temporary types. */
309 if (filenum < 0 || filenum >= n_this_object_header_files)
311 static struct complaint msg = {"\
312 Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.",
314 complain (&msg, filenum, index, symnum);
322 /* Caller wants address of address of type. We think
323 that negative (rs6k builtin) types will never appear as
324 "lvalues", (nor should they), so we stuff the real type
325 pointer into a temp, and return its address. If referenced,
326 this will do the right thing. */
327 static struct type *temp_type;
329 temp_type = rs6000_builtin_type(index);
333 /* Type is defined outside of header files.
334 Find it in this object file's type vector. */
335 if (index >= type_vector_length)
337 old_len = type_vector_length;
340 type_vector_length = INITIAL_TYPE_VECTOR_LENGTH;
341 type_vector = (struct type **)
342 xmalloc (type_vector_length * sizeof (struct type *));
344 while (index >= type_vector_length)
346 type_vector_length *= 2;
348 type_vector = (struct type **)
349 xrealloc ((char *) type_vector,
350 (type_vector_length * sizeof (struct type *)));
351 memset (&type_vector[old_len], 0,
352 (type_vector_length - old_len) * sizeof (struct type *));
355 /* Deal with OS9000 fundamental types. */
356 os9k_init_type_vector (type_vector);
358 return (&type_vector[index]);
362 real_filenum = this_object_header_files[filenum];
364 if (real_filenum >= N_HEADER_FILES (current_objfile))
366 struct type *temp_type;
367 struct type **temp_type_p;
369 warning ("GDB internal error: bad real_filenum");
372 temp_type = init_type (TYPE_CODE_ERROR, 0, 0, NULL, NULL);
373 temp_type_p = (struct type **) xmalloc (sizeof (struct type *));
374 *temp_type_p = temp_type;
378 f = HEADER_FILES (current_objfile) + real_filenum;
380 f_orig_length = f->length;
381 if (index >= f_orig_length)
383 while (index >= f->length)
387 f->vector = (struct type **)
388 xrealloc ((char *) f->vector, f->length * sizeof (struct type *));
389 memset (&f->vector[f_orig_length], 0,
390 (f->length - f_orig_length) * sizeof (struct type *));
392 return (&f->vector[index]);
396 /* Make sure there is a type allocated for type numbers TYPENUMS
397 and return the type object.
398 This can create an empty (zeroed) type object.
399 TYPENUMS may be (-1, -1) to return a new type object that is not
400 put into the type vector, and so may not be referred to by number. */
403 dbx_alloc_type (typenums, objfile)
405 struct objfile *objfile;
407 register struct type **type_addr;
409 if (typenums[0] == -1)
411 return (alloc_type (objfile));
414 type_addr = dbx_lookup_type (typenums);
416 /* If we are referring to a type not known at all yet,
417 allocate an empty type for it.
418 We will fill it in later if we find out how. */
421 *type_addr = alloc_type (objfile);
427 /* for all the stabs in a given stab vector, build appropriate types
428 and fix their symbols in given symbol vector. */
431 patch_block_stabs (symbols, stabs, objfile)
432 struct pending *symbols;
433 struct pending_stabs *stabs;
434 struct objfile *objfile;
444 /* for all the stab entries, find their corresponding symbols and
445 patch their types! */
447 for (ii = 0; ii < stabs->count; ++ii)
449 name = stabs->stab[ii];
450 pp = (char*) strchr (name, ':');
454 pp = (char *)strchr(pp, ':');
456 sym = find_symbol_in_list (symbols, name, pp-name);
459 /* FIXME-maybe: it would be nice if we noticed whether
460 the variable was defined *anywhere*, not just whether
461 it is defined in this compilation unit. But neither
462 xlc or GCC seem to need such a definition, and until
463 we do psymtabs (so that the minimal symbols from all
464 compilation units are available now), I'm not sure
465 how to get the information. */
467 /* On xcoff, if a global is defined and never referenced,
468 ld will remove it from the executable. There is then
469 a N_GSYM stab for it, but no regular (C_EXT) symbol. */
470 sym = (struct symbol *)
471 obstack_alloc (&objfile->symbol_obstack,
472 sizeof (struct symbol));
474 memset (sym, 0, sizeof (struct symbol));
475 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
476 SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
478 obsavestring (name, pp - name, &objfile->symbol_obstack);
480 if (*(pp-1) == 'F' || *(pp-1) == 'f')
482 /* I don't think the linker does this with functions,
483 so as far as I know this is never executed.
484 But it doesn't hurt to check. */
486 lookup_function_type (read_type (&pp, objfile));
490 SYMBOL_TYPE (sym) = read_type (&pp, objfile);
492 add_symbol_to_list (sym, &global_symbols);
497 if (*(pp-1) == 'F' || *(pp-1) == 'f')
500 lookup_function_type (read_type (&pp, objfile));
504 SYMBOL_TYPE (sym) = read_type (&pp, objfile);
512 /* Read a number by which a type is referred to in dbx data,
513 or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
514 Just a single number N is equivalent to (0,N).
515 Return the two numbers by storing them in the vector TYPENUMS.
516 TYPENUMS will then be used as an argument to dbx_lookup_type.
518 Returns 0 for success, -1 for error. */
521 read_type_number (pp, typenums)
523 register int *typenums;
529 typenums[0] = read_huge_number (pp, ',', &nbits);
530 if (nbits != 0) return -1;
531 typenums[1] = read_huge_number (pp, ')', &nbits);
532 if (nbits != 0) return -1;
537 typenums[1] = read_huge_number (pp, 0, &nbits);
538 if (nbits != 0) return -1;
544 #if !defined (REG_STRUCT_HAS_ADDR)
545 #define REG_STRUCT_HAS_ADDR(gcc_p,type) 0
548 #define VISIBILITY_PRIVATE '0' /* Stabs character for private field */
549 #define VISIBILITY_PROTECTED '1' /* Stabs character for protected fld */
550 #define VISIBILITY_PUBLIC '2' /* Stabs character for public field */
551 #define VISIBILITY_IGNORE '9' /* Optimized out or zero length */
553 #define CFRONT_VISIBILITY_PRIVATE '2' /* Stabs character for private field */
554 #define CFRONT_VISIBILITY_PUBLIC '1' /* Stabs character for public field */
556 /* This code added to support parsing of ARM/Cfront stabs strings */
558 /* Get substring from string up to char c, advance string pointer past
579 /* Physname gets strcat'd onto sname in order to recreate the mangled
580 name (see funtion gdb_mangle_name in gdbtypes.c). For cfront, make
581 the physname look like that of g++ - take out the initial mangling
582 eg: for sname="a" and fname="foo__1aFPFs_i" return "FPFs_i" */
585 get_cfront_method_physname (fname)
589 /* FIXME would like to make this generic for g++ too, but
590 that is already handled in read_member_funcctions */
593 /* search ahead to find the start of the mangled suffix */
594 if (*p == '_' && *(p+1)=='_') /* compiler generated; probably a ctor/dtor */
596 while (p && (unsigned) ((p+1) - fname) < strlen (fname) && *(p+1) != '_')
598 if (!(p && *p == '_' && *(p+1) == '_'))
599 error ("Invalid mangled function name %s",fname);
600 p += 2; /* advance past '__' */
602 /* struct name length and name of type should come next; advance past it */
605 len = len * 10 + (*p - '0');
613 /* Read base classes within cfront class definition.
614 eg: A:ZcA;1@Bpub v2@Bvirpri;__ct__1AFv func__1AFv *sfunc__1AFv ;as__1A ;;
617 A:ZcA;;foopri__1AFv foopro__1AFv __ct__1AFv __ct__1AFRC1A foopub__1AFv ;;;
622 read_cfront_baseclasses (fip, pp, type, objfile)
623 struct field_info *fip;
624 struct objfile *objfile;
628 static struct complaint msg_unknown = {"\
629 Unsupported token in stabs string %s.\n",
631 static struct complaint msg_notfound = {"\
632 Unable to find base type for %s.\n",
637 struct nextfield *new;
639 if (**pp == ';') /* no base classes; return */
645 /* first count base classes so we can allocate space before parsing */
646 for (p = *pp; p && *p && *p != ';'; p++)
651 bnum++; /* add one more for last one */
653 /* now parse the base classes until we get to the start of the methods
654 (code extracted and munged from read_baseclasses) */
655 ALLOCATE_CPLUS_STRUCT_TYPE (type);
656 TYPE_N_BASECLASSES(type) = bnum;
660 int num_bytes = B_BYTES (TYPE_N_BASECLASSES (type));
663 pointer = (char *) TYPE_ALLOC (type, num_bytes);
664 TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *) pointer;
666 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), TYPE_N_BASECLASSES (type));
668 for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
670 new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
671 make_cleanup (free, new);
672 memset (new, 0, sizeof (struct nextfield));
673 new -> next = fip -> list;
675 FIELD_BITSIZE (new->field) = 0; /* this should be an unpacked field! */
677 STABS_CONTINUE (pp, objfile);
679 /* virtual? eg: v2@Bvir */
682 SET_TYPE_FIELD_VIRTUAL (type, i);
686 /* access? eg: 2@Bvir */
687 /* Note: protected inheritance not supported in cfront */
690 case CFRONT_VISIBILITY_PRIVATE:
691 new -> visibility = VISIBILITY_PRIVATE;
693 case CFRONT_VISIBILITY_PUBLIC:
694 new -> visibility = VISIBILITY_PUBLIC;
697 /* Bad visibility format. Complain and treat it as
700 static struct complaint msg = {
701 "Unknown visibility `%c' for baseclass", 0, 0};
702 complain (&msg, new -> visibility);
703 new -> visibility = VISIBILITY_PUBLIC;
707 /* "@" comes next - eg: @Bvir */
710 complain (&msg_unknown, *pp);
716 /* Set the bit offset of the portion of the object corresponding
717 to this baseclass. Always zero in the absence of
718 multiple inheritance. */
719 /* Unable to read bit position from stabs;
720 Assuming no multiple inheritance for now FIXME! */
721 /* We may have read this in the structure definition;
722 now we should fixup the members to be the actual base classes */
723 FIELD_BITPOS (new->field) = 0;
725 /* Get the base class name and type */
727 char * bname; /* base class name */
728 struct symbol * bsym; /* base class */
730 p1 = strchr (*pp,' ');
731 p2 = strchr (*pp,';');
733 bname = get_substring (pp,' ');
735 bname = get_substring (pp,';');
736 if (!bname || !*bname)
738 complain (&msg_unknown, *pp);
741 /* FIXME! attach base info to type */
742 bsym = lookup_symbol (bname, 0, STRUCT_NAMESPACE, 0, 0); /*demangled_name*/
745 new -> field.type = SYMBOL_TYPE(bsym);
746 new -> field.name = type_name_no_tag (new -> field.type);
750 complain (&msg_notfound, *pp);
755 /* If more base classes to parse, loop again.
756 We ate the last ' ' or ';' in get_substring,
757 so on exit we will have skipped the trailing ';' */
758 /* if invalid, return 0; add code to detect - FIXME! */
763 /* read cfront member functions.
764 pp points to string starting with list of functions
765 eg: A:ZcA;1@Bpub v2@Bvirpri;__ct__1AFv func__1AFv *sfunc__1AFv ;as__1A ;;
766 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
767 A:ZcA;;foopri__1AFv foopro__1AFv __ct__1AFv __ct__1AFRC1A foopub__1AFv ;;;
768 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
772 read_cfront_member_functions (fip, pp, type, objfile)
773 struct field_info *fip;
776 struct objfile *objfile;
778 /* This code extracted from read_member_functions
779 so as to do the similar thing for our funcs */
783 /* Total number of member functions defined in this class. If the class
784 defines two `f' functions, and one `g' function, then this will have
786 int total_length = 0;
790 struct next_fnfield *next;
791 struct fn_field fn_field;
793 struct type *look_ahead_type;
794 struct next_fnfieldlist *new_fnlist;
795 struct next_fnfield *new_sublist;
798 struct symbol * ref_func = 0;
800 /* Process each list until we find the end of the member functions.
801 eg: p = "__ct__1AFv foo__1AFv ;;;" */
803 STABS_CONTINUE (pp, objfile); /* handle \\ */
805 while (**pp != ';' && (fname = get_substring (pp, ' '), fname))
808 int sublist_count = 0;
810 if (fname[0] == '*') /* static member */
816 ref_func = lookup_symbol (fname, 0, VAR_NAMESPACE, 0, 0); /* demangled name */
819 static struct complaint msg = {"\
820 Unable to find function symbol for %s\n",
822 complain (&msg, fname);
826 look_ahead_type = NULL;
829 new_fnlist = (struct next_fnfieldlist *)
830 xmalloc (sizeof (struct next_fnfieldlist));
831 make_cleanup (free, new_fnlist);
832 memset (new_fnlist, 0, sizeof (struct next_fnfieldlist));
834 /* The following is code to work around cfront generated stabs.
835 The stabs contains full mangled name for each field.
836 We try to demangle the name and extract the field name out of it. */
838 char *dem, *dem_p, *dem_args;
840 dem = cplus_demangle (fname, DMGL_ANSI | DMGL_PARAMS);
843 dem_p = strrchr (dem, ':');
844 if (dem_p != 0 && *(dem_p-1) == ':')
846 /* get rid of args */
847 dem_args = strchr (dem_p, '(');
848 if (dem_args == NULL)
849 dem_len = strlen (dem_p);
851 dem_len = dem_args - dem_p;
853 obsavestring (dem_p, dem_len, &objfile -> type_obstack);
858 obsavestring (fname, strlen (fname), &objfile -> type_obstack);
860 } /* end of code for cfront work around */
862 new_fnlist -> fn_fieldlist.name = main_fn_name;
864 /*-------------------------------------------------*/
865 /* Set up the sublists
866 Sublists are stuff like args, static, visibility, etc.
867 so in ARM, we have to set that info some other way.
868 Multiple sublists happen if overloading
869 eg: foo::26=##1;:;2A.;
870 In g++, we'd loop here thru all the sublists... */
873 (struct next_fnfield *) xmalloc (sizeof (struct next_fnfield));
874 make_cleanup (free, new_sublist);
875 memset (new_sublist, 0, sizeof (struct next_fnfield));
877 /* eat 1; from :;2A.; */
878 new_sublist -> fn_field.type = SYMBOL_TYPE(ref_func); /* normally takes a read_type */
879 /* Make this type look like a method stub for gdb */
880 TYPE_FLAGS (new_sublist -> fn_field.type) |= TYPE_FLAG_STUB;
881 TYPE_CODE (new_sublist -> fn_field.type) = TYPE_CODE_METHOD;
883 /* If this is just a stub, then we don't have the real name here. */
884 if (TYPE_FLAGS (new_sublist -> fn_field.type) & TYPE_FLAG_STUB)
886 if (!TYPE_DOMAIN_TYPE (new_sublist -> fn_field.type))
887 TYPE_DOMAIN_TYPE (new_sublist -> fn_field.type) = type;
888 new_sublist -> fn_field.is_stub = 1;
891 /* physname used later in mangling; eg PFs_i,5 for foo__1aFPFs_i
892 physname gets strcat'd in order to recreate the onto mangled name */
893 pname = get_cfront_method_physname (fname);
894 new_sublist -> fn_field.physname = savestring (pname, strlen (pname));
897 /* Set this member function's visibility fields.
898 Unable to distinguish access from stabs definition!
899 Assuming public for now. FIXME!
900 (for private, set new_sublist->fn_field.is_private = 1,
901 for public, set new_sublist->fn_field.is_protected = 1) */
903 /* Unable to distinguish const/volatile from stabs definition!
904 Assuming normal for now. FIXME! */
906 new_sublist -> fn_field.is_const = 0;
907 new_sublist -> fn_field.is_volatile = 0; /* volatile not implemented in cfront */
909 /* Set virtual/static function info
910 How to get vtable offsets ?
911 Assuming normal for now FIXME!!
912 For vtables, figure out from whence this virtual function came.
913 It may belong to virtual function table of
914 one of its baseclasses.
916 new_sublist -> fn_field.voffset = vtable offset,
917 new_sublist -> fn_field.fcontext = look_ahead_type;
918 where look_ahead_type is type of baseclass */
920 new_sublist -> fn_field.voffset = VOFFSET_STATIC;
921 else /* normal member function. */
922 new_sublist -> fn_field.voffset = 0;
923 new_sublist -> fn_field.fcontext = 0;
926 /* Prepare new sublist */
927 new_sublist -> next = sublist;
928 sublist = new_sublist;
931 /* In g++, we loop thu sublists - now we set from functions. */
932 new_fnlist -> fn_fieldlist.fn_fields = (struct fn_field *)
933 obstack_alloc (&objfile -> type_obstack,
934 sizeof (struct fn_field) * length);
935 memset (new_fnlist -> fn_fieldlist.fn_fields, 0,
936 sizeof (struct fn_field) * length);
937 for (i = length; (i--, sublist); sublist = sublist -> next)
939 new_fnlist -> fn_fieldlist.fn_fields[i] = sublist -> fn_field;
942 new_fnlist -> fn_fieldlist.length = length;
943 new_fnlist -> next = fip -> fnlist;
944 fip -> fnlist = new_fnlist;
946 total_length += length;
947 STABS_CONTINUE (pp, objfile); /* handle \\ */
952 /* type should already have space */
953 TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
954 TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * nfn_fields);
955 memset (TYPE_FN_FIELDLISTS (type), 0,
956 sizeof (struct fn_fieldlist) * nfn_fields);
957 TYPE_NFN_FIELDS (type) = nfn_fields;
958 TYPE_NFN_FIELDS_TOTAL (type) = total_length;
961 /* end of scope for reading member func */
965 /* Skip trailing ';' and bump count of number of fields seen */
973 /* This routine fixes up partial cfront types that were created
974 while parsing the stabs. The main need for this function is
975 to add information such as methods to classes.
976 Examples of "p": "sA;;__ct__1AFv foo__1AFv ;;;" */
978 resolve_cfront_continuation (objfile, sym, p)
979 struct objfile * objfile;
983 struct symbol * ref_sym=0;
985 /* snarfed from read_struct_type */
986 struct field_info fi;
988 struct cleanup *back_to;
990 /* Need to make sure that fi isn't gunna conflict with struct
991 in case struct already had some fnfs */
994 back_to = make_cleanup (null_cleanup, 0);
996 /* We only accept structs, classes and unions at the moment.
997 Other continuation types include t (typedef), r (long dbl), ...
998 We may want to add support for them as well;
999 right now they are handled by duplicating the symbol information
1000 into the type information (see define_symbol) */
1001 if (*p != 's' /* structs */
1002 && *p != 'c' /* class */
1003 && *p != 'u') /* union */
1004 return 0; /* only handle C++ types */
1007 /* Get symbol typs name and validate
1008 eg: p = "A;;__ct__1AFv foo__1AFv ;;;" */
1009 sname = get_substring (&p, ';');
1010 if (!sname || strcmp (sname, SYMBOL_NAME(sym)))
1011 error ("Internal error: base symbol type name does not match\n");
1013 /* Find symbol's internal gdb reference using demangled_name.
1014 This is the real sym that we want;
1015 sym was a temp hack to make debugger happy */
1016 ref_sym = lookup_symbol (SYMBOL_NAME(sym), 0, STRUCT_NAMESPACE, 0, 0);
1017 type = SYMBOL_TYPE(ref_sym);
1020 /* Now read the baseclasses, if any, read the regular C struct or C++
1021 class member fields, attach the fields to the type, read the C++
1022 member functions, attach them to the type, and then read any tilde
1023 field (baseclass specifier for the class holding the main vtable). */
1025 if (!read_cfront_baseclasses (&fi, &p, type, objfile)
1026 /* g++ does this next, but cfront already did this:
1027 || !read_struct_fields (&fi, &p, type, objfile) */
1028 || !copy_cfront_struct_fields (&fi, type, objfile)
1029 || !read_cfront_member_functions (&fi, &p, type, objfile)
1030 || !read_cfront_static_fields (&fi, &p, type, objfile)
1031 || !attach_fields_to_type (&fi, type, objfile)
1032 || !attach_fn_fields_to_type (&fi, type)
1033 /* g++ does this next, but cfront doesn't seem to have this:
1034 || !read_tilde_fields (&fi, &p, type, objfile) */
1037 type = error_type (&p, objfile);
1040 do_cleanups (back_to);
1043 /* End of code added to support parsing of ARM/Cfront stabs strings */
1046 /* This routine fixes up symbol references/aliases to point to the original
1047 symbol definition. */
1050 resolve_symbol_reference (objfile, sym, p)
1051 struct objfile *objfile;
1056 struct symbol *ref_sym=0;
1057 struct alias_list *alias;
1059 /* If this is not a symbol reference return now. */
1063 /* Use "#<num>" as the name; we'll fix the name later.
1064 We stored the original symbol name as "#<id>=<name>"
1065 so we can now search for "#<id>" to resolving the reference.
1066 We'll fix the names later by removing the "#<id>" or "#<id>=" */
1068 /*---------------------------------------------------------*/
1069 /* Get the reference id number, and
1070 advance p past the names so we can parse the rest.
1071 eg: id=2 for p : "2=", "2=z:r(0,1)" "2:r(0,1);l(#5,#6),l(#7,#4)" */
1072 /*---------------------------------------------------------*/
1074 /* This gets reference name from string. sym may not have a name. */
1076 /* Get the reference number associated with the reference id in the
1077 gdb stab string. From that reference number, get the main/primary
1078 symbol for this alias. */
1079 refnum = process_reference (&p);
1080 ref_sym = ref_search (refnum);
1082 error ("error: symbol for reference not found.\n");
1085 /* Parse the stab of the referencing symbol
1086 now that we have the referenced symbol.
1087 Add it as a new symbol and a link back to the referenced symbol.
1088 eg: p : "=", "=z:r(0,1)" ":r(0,1);l(#5,#6),l(#7,#4)" */
1091 /* If the stab symbol table and string contain:
1092 RSYM 0 5 00000000 868 #15=z:r(0,1)
1093 LBRAC 0 0 00000000 899 #5=
1094 SLINE 0 16 00000003 923 #6=
1095 Then the same symbols can be later referenced by:
1096 RSYM 0 5 00000000 927 #15:r(0,1);l(#5,#6)
1097 This is used in live range splitting to:
1098 1) specify that a symbol (#15) is actually just a new storage
1099 class for a symbol (#15=z) which was previously defined.
1100 2) specify that the beginning and ending ranges for a symbol
1101 (#15) are the values of the beginning (#5) and ending (#6)
1104 /* Read number as reference id.
1105 eg: p : "=", "=z:r(0,1)" ":r(0,1);l(#5,#6),l(#7,#4)" */
1106 /* FIXME! Might I want to use SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
1107 in case of "l(0,0)"? */
1109 /*--------------------------------------------------*/
1110 /* Add this symbol to the reference list. */
1111 /*--------------------------------------------------*/
1113 alias = (struct alias_list *) obstack_alloc (&objfile->type_obstack,
1114 sizeof (struct alias_list));
1116 error ("Unable to allocate alias list memory");
1121 if (!SYMBOL_ALIASES (ref_sym))
1123 SYMBOL_ALIASES (ref_sym) = alias;
1127 struct alias_list *temp;
1129 /* Get to the end of the list. */
1130 for (temp = SYMBOL_ALIASES (ref_sym);
1137 /* Want to fix up name so that other functions (eg. valops)
1138 will correctly print the name.
1139 Don't add_symbol_to_list so that lookup_symbol won't find it.
1140 nope... needed for fixups. */
1141 SYMBOL_NAME (sym) = SYMBOL_NAME (ref_sym);
1147 #define MAX_CHUNK_REFS 100
1148 #define REF_CHUNK_SIZE \
1149 MAX_CHUNK_REFS * sizeof (struct ref_map_s)
1150 #define REF_MAP_SIZE(ref_chunk) \
1151 ref_chunk * REF_CHUNK_SIZE
1153 /* Structure for storing pointers to reference definitions for fast lookup
1154 during "process_later". */
1155 static struct ref_map_s
1162 /* Ptr to free cell in chunk's linked list. */
1163 static int ref_count = 0;
1165 /* Number of chunks malloced. */
1166 static int ref_chunk = 0;
1168 /* Initialize our list of references.
1169 This should be called before any symbol table is read. */
1178 /* Create array of pointers mapping refids to symbols and stab strings.
1179 Add pointers to reference definition symbols and/or their values as we
1180 find them, using their reference numbers as our index.
1181 These will be used later when we resolve references. */
1183 ref_add (refnum, sym, stabs, value)
1191 if (refnum >= ref_count)
1192 ref_count = refnum + 1;
1193 if (ref_count > ref_chunk * MAX_CHUNK_REFS)
1195 int new_slots = ref_count - ref_chunk * MAX_CHUNK_REFS;
1196 int new_chunks = new_slots / MAX_CHUNK_REFS + 1;
1197 ref_map = xrealloc (ref_map, REF_MAP_SIZE(ref_chunk + new_chunks));
1199 error ("no more free slots in chain\n");
1200 memset (ref_map + REF_MAP_SIZE(ref_chunk), 0, new_chunks * REF_CHUNK_SIZE);
1201 ref_chunk += new_chunks;
1203 ref_map[refnum].stabs = stabs;
1204 ref_map[refnum].sym = sym;
1205 ref_map[refnum].value = value;
1208 /* Return defined sym for the reference REFNUM. */
1213 if (refnum < 0 || refnum > ref_count)
1215 return ref_map[refnum].sym;
1218 /* Return value for the reference REFNUM. */
1221 ref_search_value (refnum)
1224 if (refnum < 0 || refnum > ref_count)
1226 return ref_map[refnum].value;
1229 /* Parse a reference id in STRING and return the resulting
1230 reference number. Move STRING beyond the reference id. */
1233 process_reference (string)
1239 if (**string != '#')
1242 /* Advance beyond the initial '#'. */
1245 /* Read number as reference id. */
1246 while (*p && isdigit (*p))
1248 refnum = refnum * 10 + *p - '0';
1255 /* If STRING defines a reference, store away a pointer to the reference
1256 definition for later use. Return the reference number. */
1259 symbol_reference_defined (string)
1265 refnum = process_reference (&p);
1267 /* Defining symbols end in '=' */
1270 /* Symbol is being defined here. */
1276 /* Must be a reference. Either the symbol has already been defined,
1277 or this is a forward reference to it. */
1285 define_symbol (valu, string, desc, type, objfile)
1290 struct objfile *objfile;
1292 register struct symbol *sym;
1293 char *p = (char *) strchr (string, ':');
1298 /* We would like to eliminate nameless symbols, but keep their types.
1299 E.g. stab entry ":t10=*2" should produce a type 10, which is a pointer
1300 to type 2, but, should not create a symbol to address that type. Since
1301 the symbol will be nameless, there is no way any user can refer to it. */
1305 /* Ignore syms with empty names. */
1309 /* Ignore old-style symbols from cc -go */
1316 p = strchr (p, ':');
1319 /* If a nameless stab entry, all we need is the type, not the symbol.
1320 e.g. ":t10=*2" or a nameless enum like " :T16=ered:0,green:1,blue:2,;" */
1321 nameless = (p == string || ((string[0] == ' ') && (string[1] == ':')));
1323 current_symbol = sym = (struct symbol *)
1324 obstack_alloc (&objfile -> symbol_obstack, sizeof (struct symbol));
1325 memset (sym, 0, sizeof (struct symbol));
1327 switch (type & N_TYPE)
1330 SYMBOL_SECTION(sym) = SECT_OFF_TEXT;
1333 SYMBOL_SECTION(sym) = SECT_OFF_DATA;
1336 SYMBOL_SECTION(sym) = SECT_OFF_BSS;
1340 if (processing_gcc_compilation)
1342 /* GCC 2.x puts the line number in desc. SunOS apparently puts in the
1343 number of bytes occupied by a type or object, which we ignore. */
1344 SYMBOL_LINE(sym) = desc;
1348 SYMBOL_LINE(sym) = 0; /* unknown */
1351 if (is_cplus_marker (string[0]))
1353 /* Special GNU C++ names. */
1357 SYMBOL_NAME (sym) = obsavestring ("this", strlen ("this"),
1358 &objfile -> symbol_obstack);
1361 case 'v': /* $vtbl_ptr_type */
1362 /* Was: SYMBOL_NAME (sym) = "vptr"; */
1366 SYMBOL_NAME (sym) = obsavestring ("eh_throw", strlen ("eh_throw"),
1367 &objfile -> symbol_obstack);
1371 /* This was an anonymous type that was never fixed up. */
1374 #ifdef STATIC_TRANSFORM_NAME
1376 /* SunPRO (3.0 at least) static variable encoding. */
1381 complain (&unrecognized_cplus_name_complaint, string);
1382 goto normal; /* Do *something* with it */
1385 else if (string[0] == '#')
1387 /* Special GNU C extension for referencing symbols. */
1391 /* If STRING defines a new reference id, then add it to the
1392 reference map. Else it must be referring to a previously
1393 defined symbol, so add it to the alias list of the previously
1396 refnum = symbol_reference_defined (&s);
1398 ref_add (refnum, sym, string, SYMBOL_VALUE (sym));
1400 resolve_symbol_reference (objfile, sym, string);
1402 /* S..P contains the name of the symbol. We need to store
1403 the correct name into SYMBOL_NAME. */
1409 SYMBOL_NAME (sym) = (char *)
1410 obstack_alloc (&objfile -> symbol_obstack, nlen);
1411 strncpy (SYMBOL_NAME (sym), s, nlen);
1412 SYMBOL_NAME (sym)[nlen] = '\0';
1413 SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->symbol_obstack);
1416 /* FIXME! Want SYMBOL_NAME (sym) = 0;
1417 Get error if leave name 0. So give it something. */
1420 SYMBOL_NAME (sym) = (char *)
1421 obstack_alloc (&objfile -> symbol_obstack, nlen);
1422 strncpy (SYMBOL_NAME (sym), string, nlen);
1423 SYMBOL_NAME (sym)[nlen] = '\0';
1424 SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->symbol_obstack);
1427 /* Advance STRING beyond the reference id. */
1433 SYMBOL_LANGUAGE (sym) = current_subfile -> language;
1434 SYMBOL_NAME (sym) = (char *)
1435 obstack_alloc (&objfile -> symbol_obstack, ((p - string) + 1));
1436 /* Open-coded memcpy--saves function call time. */
1437 /* FIXME: Does it really? Try replacing with simple strcpy and
1438 try it on an executable with a large symbol table. */
1439 /* FIXME: considering that gcc can open code memcpy anyway, I
1440 doubt it. xoxorich. */
1442 register char *p1 = string;
1443 register char *p2 = SYMBOL_NAME (sym);
1451 /* If this symbol is from a C++ compilation, then attempt to cache the
1452 demangled form for future reference. This is a typical time versus
1453 space tradeoff, that was decided in favor of time because it sped up
1454 C++ symbol lookups by a factor of about 20. */
1456 SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->symbol_obstack);
1460 /* Determine the type of name being defined. */
1462 /* Getting GDB to correctly skip the symbol on an undefined symbol
1463 descriptor and not ever dump core is a very dodgy proposition if
1464 we do things this way. I say the acorn RISC machine can just
1465 fix their compiler. */
1466 /* The Acorn RISC machine's compiler can put out locals that don't
1467 start with "234=" or "(3,4)=", so assume anything other than the
1468 deftypes we know how to handle is a local. */
1469 if (!strchr ("cfFGpPrStTvVXCR", *p))
1471 if (isdigit (*p) || *p == '(' || *p == '-')
1480 /* c is a special case, not followed by a type-number.
1481 SYMBOL:c=iVALUE for an integer constant symbol.
1482 SYMBOL:c=rVALUE for a floating constant symbol.
1483 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
1484 e.g. "b:c=e6,0" for "const b = blob1"
1485 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
1488 SYMBOL_CLASS (sym) = LOC_CONST;
1489 SYMBOL_TYPE (sym) = error_type (&p, objfile);
1490 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1491 add_symbol_to_list (sym, &file_symbols);
1499 double d = atof (p);
1502 /* FIXME-if-picky-about-floating-accuracy: Should be using
1503 target arithmetic to get the value. real.c in GCC
1504 probably has the necessary code. */
1506 /* FIXME: lookup_fundamental_type is a hack. We should be
1507 creating a type especially for the type of float constants.
1508 Problem is, what type should it be?
1510 Also, what should the name of this type be? Should we
1511 be using 'S' constants (see stabs.texinfo) instead? */
1513 SYMBOL_TYPE (sym) = lookup_fundamental_type (objfile,
1516 obstack_alloc (&objfile -> symbol_obstack,
1517 TYPE_LENGTH (SYMBOL_TYPE (sym)));
1518 store_floating (dbl_valu, TYPE_LENGTH (SYMBOL_TYPE (sym)), d);
1519 SYMBOL_VALUE_BYTES (sym) = dbl_valu;
1520 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
1525 /* Defining integer constants this way is kind of silly,
1526 since 'e' constants allows the compiler to give not
1527 only the value, but the type as well. C has at least
1528 int, long, unsigned int, and long long as constant
1529 types; other languages probably should have at least
1530 unsigned as well as signed constants. */
1532 /* We just need one int constant type for all objfiles.
1533 It doesn't depend on languages or anything (arguably its
1534 name should be a language-specific name for a type of
1535 that size, but I'm inclined to say that if the compiler
1536 wants a nice name for the type, it can use 'e'). */
1537 static struct type *int_const_type;
1539 /* Yes, this is as long as a *host* int. That is because we
1541 if (int_const_type == NULL)
1543 init_type (TYPE_CODE_INT,
1544 sizeof (int) * HOST_CHAR_BIT / TARGET_CHAR_BIT, 0,
1546 (struct objfile *)NULL);
1547 SYMBOL_TYPE (sym) = int_const_type;
1548 SYMBOL_VALUE (sym) = atoi (p);
1549 SYMBOL_CLASS (sym) = LOC_CONST;
1553 /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value
1554 can be represented as integral.
1555 e.g. "b:c=e6,0" for "const b = blob1"
1556 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
1558 SYMBOL_CLASS (sym) = LOC_CONST;
1559 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1563 SYMBOL_TYPE (sym) = error_type (&p, objfile);
1568 /* If the value is too big to fit in an int (perhaps because
1569 it is unsigned), or something like that, we silently get
1570 a bogus value. The type and everything else about it is
1571 correct. Ideally, we should be using whatever we have
1572 available for parsing unsigned and long long values,
1574 SYMBOL_VALUE (sym) = atoi (p);
1579 SYMBOL_CLASS (sym) = LOC_CONST;
1580 SYMBOL_TYPE (sym) = error_type (&p, objfile);
1583 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1584 add_symbol_to_list (sym, &file_symbols);
1588 /* The name of a caught exception. */
1589 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1590 SYMBOL_CLASS (sym) = LOC_LABEL;
1591 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1592 SYMBOL_VALUE_ADDRESS (sym) = valu;
1593 add_symbol_to_list (sym, &local_symbols);
1597 /* A static function definition. */
1598 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1599 SYMBOL_CLASS (sym) = LOC_BLOCK;
1600 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1601 add_symbol_to_list (sym, &file_symbols);
1602 /* fall into process_function_types. */
1604 process_function_types:
1605 /* Function result types are described as the result type in stabs.
1606 We need to convert this to the function-returning-type-X type
1607 in GDB. E.g. "int" is converted to "function returning int". */
1608 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_FUNC)
1609 SYMBOL_TYPE (sym) = lookup_function_type (SYMBOL_TYPE (sym));
1611 /* All functions in C++ have prototypes. */
1612 if (SYMBOL_LANGUAGE (sym) == language_cplus)
1613 TYPE_FLAGS (SYMBOL_TYPE (sym)) |= TYPE_FLAG_PROTOTYPED;
1615 /* fall into process_prototype_types */
1617 process_prototype_types:
1618 /* Sun acc puts declared types of arguments here. We don't care
1619 about their actual types (FIXME -- we should remember the whole
1620 function prototype), but the list may define some new types
1621 that we have to remember, so we must scan it now. */
1624 TYPE_FLAGS (SYMBOL_TYPE (sym)) |= TYPE_FLAG_PROTOTYPED;
1628 read_type (&p, objfile);
1634 /* A global function definition. */
1635 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1636 SYMBOL_CLASS (sym) = LOC_BLOCK;
1637 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1638 add_symbol_to_list (sym, &global_symbols);
1639 goto process_function_types;
1642 /* For a class G (global) symbol, it appears that the
1643 value is not correct. It is necessary to search for the
1644 corresponding linker definition to find the value.
1645 These definitions appear at the end of the namelist. */
1646 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1647 SYMBOL_CLASS (sym) = LOC_STATIC;
1648 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1649 /* Don't add symbol references to global_sym_chain.
1650 Symbol references don't have valid names and wont't match up with
1651 minimal symbols when the global_sym_chain is relocated.
1652 We'll fixup symbol references when we fixup the defining symbol. */
1653 if (SYMBOL_NAME (sym) && SYMBOL_NAME (sym)[0] != '#')
1655 i = hashname (SYMBOL_NAME (sym));
1656 SYMBOL_VALUE_CHAIN (sym) = global_sym_chain[i];
1657 global_sym_chain[i] = sym;
1659 add_symbol_to_list (sym, &global_symbols);
1662 /* This case is faked by a conditional above,
1663 when there is no code letter in the dbx data.
1664 Dbx data never actually contains 'l'. */
1667 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1668 SYMBOL_CLASS (sym) = LOC_LOCAL;
1669 SYMBOL_VALUE (sym) = valu;
1670 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1671 add_symbol_to_list (sym, &local_symbols);
1676 /* pF is a two-letter code that means a function parameter in Fortran.
1677 The type-number specifies the type of the return value.
1678 Translate it into a pointer-to-function type. */
1682 = lookup_pointer_type
1683 (lookup_function_type (read_type (&p, objfile)));
1686 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1688 /* Normally this is a parameter, a LOC_ARG. On the i960, it
1689 can also be a LOC_LOCAL_ARG depending on symbol type. */
1690 #ifndef DBX_PARM_SYMBOL_CLASS
1691 #define DBX_PARM_SYMBOL_CLASS(type) LOC_ARG
1694 SYMBOL_CLASS (sym) = DBX_PARM_SYMBOL_CLASS (type);
1695 SYMBOL_VALUE (sym) = valu;
1696 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1697 add_symbol_to_list (sym, &local_symbols);
1699 if (TARGET_BYTE_ORDER != BIG_ENDIAN)
1701 /* On little-endian machines, this crud is never necessary,
1702 and, if the extra bytes contain garbage, is harmful. */
1706 /* If it's gcc-compiled, if it says `short', believe it. */
1707 if (processing_gcc_compilation || BELIEVE_PCC_PROMOTION)
1710 #if !BELIEVE_PCC_PROMOTION
1712 /* This is the signed type which arguments get promoted to. */
1713 static struct type *pcc_promotion_type;
1714 /* This is the unsigned type which arguments get promoted to. */
1715 static struct type *pcc_unsigned_promotion_type;
1717 /* Call it "int" because this is mainly C lossage. */
1718 if (pcc_promotion_type == NULL)
1719 pcc_promotion_type =
1720 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
1723 if (pcc_unsigned_promotion_type == NULL)
1724 pcc_unsigned_promotion_type =
1725 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
1726 TYPE_FLAG_UNSIGNED, "unsigned int", NULL);
1728 #if defined(BELIEVE_PCC_PROMOTION_TYPE)
1729 /* This macro is defined on machines (e.g. sparc) where
1730 we should believe the type of a PCC 'short' argument,
1731 but shouldn't believe the address (the address is
1732 the address of the corresponding int).
1734 My guess is that this correction, as opposed to changing
1735 the parameter to an 'int' (as done below, for PCC
1736 on most machines), is the right thing to do
1737 on all machines, but I don't want to risk breaking
1738 something that already works. On most PCC machines,
1739 the sparc problem doesn't come up because the calling
1740 function has to zero the top bytes (not knowing whether
1741 the called function wants an int or a short), so there
1742 is little practical difference between an int and a short
1743 (except perhaps what happens when the GDB user types
1744 "print short_arg = 0x10000;").
1747 actually produces the correct address (we don't need to fix it
1748 up). I made this code adapt so that it will offset the symbol
1749 if it was pointing at an int-aligned location and not
1750 otherwise. This way you can use the same gdb for 4.0.x and
1753 If the parameter is shorter than an int, and is integral
1754 (e.g. char, short, or unsigned equivalent), and is claimed to
1755 be passed on an integer boundary, don't believe it! Offset the
1756 parameter's address to the tail-end of that integer. */
1758 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) < TYPE_LENGTH (pcc_promotion_type)
1759 && TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_INT
1760 && 0 == SYMBOL_VALUE (sym) % TYPE_LENGTH (pcc_promotion_type))
1762 SYMBOL_VALUE (sym) += TYPE_LENGTH (pcc_promotion_type)
1763 - TYPE_LENGTH (SYMBOL_TYPE (sym));
1767 #else /* no BELIEVE_PCC_PROMOTION_TYPE. */
1769 /* If PCC says a parameter is a short or a char,
1770 it is really an int. */
1771 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) < TYPE_LENGTH (pcc_promotion_type)
1772 && TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_INT)
1775 TYPE_UNSIGNED (SYMBOL_TYPE (sym))
1776 ? pcc_unsigned_promotion_type
1777 : pcc_promotion_type;
1781 #endif /* no BELIEVE_PCC_PROMOTION_TYPE. */
1783 #endif /* !BELIEVE_PCC_PROMOTION. */
1786 /* acc seems to use P to declare the prototypes of functions that
1787 are referenced by this file. gdb is not prepared to deal
1788 with this extra information. FIXME, it ought to. */
1791 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1792 goto process_prototype_types;
1797 /* Parameter which is in a register. */
1798 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1799 SYMBOL_CLASS (sym) = LOC_REGPARM;
1800 SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
1801 if (SYMBOL_VALUE (sym) >= NUM_REGS)
1803 complain (®_value_complaint, SYMBOL_VALUE (sym), NUM_REGS,
1804 SYMBOL_SOURCE_NAME (sym));
1805 SYMBOL_VALUE (sym) = SP_REGNUM; /* Known safe, though useless */
1807 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1808 add_symbol_to_list (sym, &local_symbols);
1812 /* Register variable (either global or local). */
1813 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1814 SYMBOL_CLASS (sym) = LOC_REGISTER;
1815 SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
1816 if (SYMBOL_VALUE (sym) >= NUM_REGS)
1818 complain (®_value_complaint, SYMBOL_VALUE (sym), NUM_REGS,
1819 SYMBOL_SOURCE_NAME (sym));
1820 SYMBOL_VALUE (sym) = SP_REGNUM; /* Known safe, though useless */
1822 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1823 if (within_function)
1825 /* Sun cc uses a pair of symbols, one 'p' and one 'r' with the same
1826 name to represent an argument passed in a register.
1827 GCC uses 'P' for the same case. So if we find such a symbol pair
1828 we combine it into one 'P' symbol. For Sun cc we need to do this
1829 regardless of REG_STRUCT_HAS_ADDR, because the compiler puts out
1830 the 'p' symbol even if it never saves the argument onto the stack.
1832 On most machines, we want to preserve both symbols, so that
1833 we can still get information about what is going on with the
1834 stack (VAX for computing args_printed, using stack slots instead
1835 of saved registers in backtraces, etc.).
1837 Note that this code illegally combines
1838 main(argc) struct foo argc; { register struct foo argc; }
1839 but this case is considered pathological and causes a warning
1840 from a decent compiler. */
1843 && local_symbols->nsyms > 0
1844 #ifndef USE_REGISTER_NOT_ARG
1845 && REG_STRUCT_HAS_ADDR (processing_gcc_compilation,
1847 && (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
1848 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION
1849 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_SET
1850 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_BITSTRING)
1854 struct symbol *prev_sym;
1855 prev_sym = local_symbols->symbol[local_symbols->nsyms - 1];
1856 if ((SYMBOL_CLASS (prev_sym) == LOC_REF_ARG
1857 || SYMBOL_CLASS (prev_sym) == LOC_ARG)
1858 && STREQ (SYMBOL_NAME (prev_sym), SYMBOL_NAME(sym)))
1860 SYMBOL_CLASS (prev_sym) = LOC_REGPARM;
1861 /* Use the type from the LOC_REGISTER; that is the type
1862 that is actually in that register. */
1863 SYMBOL_TYPE (prev_sym) = SYMBOL_TYPE (sym);
1864 SYMBOL_VALUE (prev_sym) = SYMBOL_VALUE (sym);
1869 add_symbol_to_list (sym, &local_symbols);
1872 add_symbol_to_list (sym, &file_symbols);
1876 /* Static symbol at top level of file */
1877 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1878 SYMBOL_CLASS (sym) = LOC_STATIC;
1879 SYMBOL_VALUE_ADDRESS (sym) = valu;
1880 #ifdef STATIC_TRANSFORM_NAME
1881 if (SYMBOL_NAME (sym)[0] == '$')
1883 struct minimal_symbol *msym;
1884 msym = lookup_minimal_symbol (SYMBOL_NAME (sym), NULL, objfile);
1887 SYMBOL_NAME (sym) = STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym));
1888 SYMBOL_VALUE_ADDRESS (sym) = SYMBOL_VALUE_ADDRESS (msym);
1892 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1893 add_symbol_to_list (sym, &file_symbols);
1897 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1899 /* For a nameless type, we don't want a create a symbol, thus we
1900 did not use `sym'. Return without further processing. */
1901 if (nameless) return NULL;
1903 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1904 SYMBOL_VALUE (sym) = valu;
1905 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1906 /* C++ vagaries: we may have a type which is derived from
1907 a base type which did not have its name defined when the
1908 derived class was output. We fill in the derived class's
1909 base part member's name here in that case. */
1910 if (TYPE_NAME (SYMBOL_TYPE (sym)) != NULL)
1911 if ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
1912 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION)
1913 && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)))
1916 for (j = TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)) - 1; j >= 0; j--)
1917 if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) == 0)
1918 TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) =
1919 type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym), j));
1922 if (TYPE_NAME (SYMBOL_TYPE (sym)) == NULL)
1924 /* gcc-2.6 or later (when using -fvtable-thunks)
1925 emits a unique named type for a vtable entry.
1926 Some gdb code depends on that specific name. */
1927 extern const char vtbl_ptr_name[];
1929 if ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_PTR
1930 && strcmp (SYMBOL_NAME (sym), vtbl_ptr_name))
1931 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_FUNC)
1933 /* If we are giving a name to a type such as "pointer to
1934 foo" or "function returning foo", we better not set
1935 the TYPE_NAME. If the program contains "typedef char
1936 *caddr_t;", we don't want all variables of type char
1937 * to print as caddr_t. This is not just a
1938 consequence of GDB's type management; PCC and GCC (at
1939 least through version 2.4) both output variables of
1940 either type char * or caddr_t with the type number
1941 defined in the 't' symbol for caddr_t. If a future
1942 compiler cleans this up it GDB is not ready for it
1943 yet, but if it becomes ready we somehow need to
1944 disable this check (without breaking the PCC/GCC2.4
1949 Fortunately, this check seems not to be necessary
1950 for anything except pointers or functions. */
1953 TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_NAME (sym);
1956 add_symbol_to_list (sym, &file_symbols);
1960 /* Struct, union, or enum tag. For GNU C++, this can be be followed
1961 by 't' which means we are typedef'ing it as well. */
1962 synonym = *p == 't';
1966 /* The semantics of C++ state that "struct foo { ... }" also defines
1967 a typedef for "foo". Unfortunately, cfront never makes the typedef
1968 when translating C++ into C. We make the typedef here so that
1969 "ptype foo" works as expected for cfront translated code. */
1970 else if (current_subfile->language == language_cplus)
1973 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1975 /* For a nameless type, we don't want a create a symbol, thus we
1976 did not use `sym'. Return without further processing. */
1977 if (nameless) return NULL;
1979 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1980 SYMBOL_VALUE (sym) = valu;
1981 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
1982 if (TYPE_TAG_NAME (SYMBOL_TYPE (sym)) == 0)
1983 TYPE_TAG_NAME (SYMBOL_TYPE (sym))
1984 = obconcat (&objfile -> type_obstack, "", "", SYMBOL_NAME (sym));
1985 add_symbol_to_list (sym, &file_symbols);
1989 /* Clone the sym and then modify it. */
1990 register struct symbol *typedef_sym = (struct symbol *)
1991 obstack_alloc (&objfile -> symbol_obstack, sizeof (struct symbol));
1992 *typedef_sym = *sym;
1993 SYMBOL_CLASS (typedef_sym) = LOC_TYPEDEF;
1994 SYMBOL_VALUE (typedef_sym) = valu;
1995 SYMBOL_NAMESPACE (typedef_sym) = VAR_NAMESPACE;
1996 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
1997 TYPE_NAME (SYMBOL_TYPE (sym))
1998 = obconcat (&objfile -> type_obstack, "", "", SYMBOL_NAME (sym));
1999 add_symbol_to_list (typedef_sym, &file_symbols);
2004 /* Static symbol of local scope */
2005 SYMBOL_TYPE (sym) = read_type (&p, objfile);
2006 SYMBOL_CLASS (sym) = LOC_STATIC;
2007 SYMBOL_VALUE_ADDRESS (sym) = valu;
2008 #ifdef STATIC_TRANSFORM_NAME
2009 if (SYMBOL_NAME (sym)[0] == '$')
2011 struct minimal_symbol *msym;
2012 msym = lookup_minimal_symbol (SYMBOL_NAME (sym), NULL, objfile);
2015 SYMBOL_NAME (sym) = STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym));
2016 SYMBOL_VALUE_ADDRESS (sym) = SYMBOL_VALUE_ADDRESS (msym);
2020 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2022 add_symbol_to_list (sym, &global_symbols);
2024 add_symbol_to_list (sym, &local_symbols);
2028 /* Reference parameter */
2029 SYMBOL_TYPE (sym) = read_type (&p, objfile);
2030 SYMBOL_CLASS (sym) = LOC_REF_ARG;
2031 SYMBOL_VALUE (sym) = valu;
2032 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2033 add_symbol_to_list (sym, &local_symbols);
2037 /* Reference parameter which is in a register. */
2038 SYMBOL_TYPE (sym) = read_type (&p, objfile);
2039 SYMBOL_CLASS (sym) = LOC_REGPARM_ADDR;
2040 SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
2041 if (SYMBOL_VALUE (sym) >= NUM_REGS)
2043 complain (®_value_complaint, SYMBOL_VALUE (sym), NUM_REGS,
2044 SYMBOL_SOURCE_NAME (sym));
2045 SYMBOL_VALUE (sym) = SP_REGNUM; /* Known safe, though useless */
2047 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2048 add_symbol_to_list (sym, &local_symbols);
2052 /* This is used by Sun FORTRAN for "function result value".
2053 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
2054 that Pascal uses it too, but when I tried it Pascal used
2055 "x:3" (local symbol) instead. */
2056 SYMBOL_TYPE (sym) = read_type (&p, objfile);
2057 SYMBOL_CLASS (sym) = LOC_LOCAL;
2058 SYMBOL_VALUE (sym) = valu;
2059 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2060 add_symbol_to_list (sym, &local_symbols);
2063 /* New code added to support cfront stabs strings.
2064 Note: case 'P' already handled above */
2066 /* Cfront type continuation coming up!
2067 Find the original definition and add to it.
2068 We'll have to do this for the typedef too,
2069 since we cloned the symbol to define a type in read_type.
2070 Stabs info examples:
2072 foo__1CFv :ZtF (first def foo__1CFv:F(0,3);(0,24))
2073 C:ZsC;;__ct__1CFv func1__1CFv func2__1CFv ... ;;;
2074 where C is the name of the class.
2075 Unfortunately, we can't lookup the original symbol yet 'cuz
2076 we haven't finished reading all the symbols.
2077 Instead, we save it for processing later */
2078 process_later (sym, p, resolve_cfront_continuation);
2079 SYMBOL_TYPE (sym) = error_type (&p, objfile); /* FIXME! change later */
2080 SYMBOL_CLASS (sym) = LOC_CONST;
2081 SYMBOL_VALUE (sym) = 0;
2082 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2083 /* Don't add to list - we'll delete it later when
2084 we add the continuation to the real sym */
2086 /* End of new code added to support cfront stabs strings */
2089 SYMBOL_TYPE (sym) = error_type (&p, objfile);
2090 SYMBOL_CLASS (sym) = LOC_CONST;
2091 SYMBOL_VALUE (sym) = 0;
2092 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2093 add_symbol_to_list (sym, &file_symbols);
2097 /* When passing structures to a function, some systems sometimes pass
2098 the address in a register, not the structure itself. */
2100 if (REG_STRUCT_HAS_ADDR (processing_gcc_compilation, SYMBOL_TYPE (sym))
2101 && (SYMBOL_CLASS (sym) == LOC_REGPARM || SYMBOL_CLASS (sym) == LOC_ARG))
2103 struct type *symbol_type = check_typedef (SYMBOL_TYPE (sym));
2105 if ((TYPE_CODE (symbol_type) == TYPE_CODE_STRUCT)
2106 || (TYPE_CODE (symbol_type) == TYPE_CODE_UNION)
2107 || (TYPE_CODE (symbol_type) == TYPE_CODE_BITSTRING)
2108 || (TYPE_CODE (symbol_type) == TYPE_CODE_SET))
2110 /* If REG_STRUCT_HAS_ADDR yields non-zero we have to convert
2111 LOC_REGPARM to LOC_REGPARM_ADDR for structures and unions. */
2112 if (SYMBOL_CLASS (sym) == LOC_REGPARM)
2113 SYMBOL_CLASS (sym) = LOC_REGPARM_ADDR;
2114 /* Likewise for converting LOC_ARG to LOC_REF_ARG (for the 7th
2115 and subsequent arguments on the sparc, for example). */
2116 else if (SYMBOL_CLASS (sym) == LOC_ARG)
2117 SYMBOL_CLASS (sym) = LOC_REF_ARG;
2121 /* Is there more to parse? For example LRS/alias information? */
2122 while (*p && *p == ';')
2125 if (*p && *p == 'l')
2127 /* GNU extensions for live range splitting may be appended to
2128 the end of the stab string. eg. "l(#1,#2);l(#3,#5)" */
2130 /* Resolve the live range and add it to SYM's live range list. */
2131 resolve_live_range (objfile, sym, p);
2133 /* Find end of live range info. */
2134 p = strchr (p, ')');
2135 if (!*p || *p != ')')
2136 error ("Internal error: live range format not recognized.\n");
2143 /* Add the live range found in P to the symbol SYM in objfile OBJFILE. */
2146 resolve_live_range (objfile, sym, p)
2147 struct objfile * objfile;
2152 CORE_ADDR start, end;
2154 /* Sanity check the beginning of the stabs string. */
2155 if (!*p || *p != 'l')
2156 error ("Internal error: live range string.\n");
2159 if (!*p || *p != '(')
2160 error ("Internal error: live range string.\n");
2163 /* Get starting value of range and advance P past the reference id.
2165 ?!? In theory, the process_reference should never fail, but we should
2166 catch that case just in case the compiler scrogged the stabs. */
2167 refnum = process_reference (&p);
2168 start = ref_search_value (refnum);
2170 error ("Internal error: live range symbol not found.\n");
2172 if (!*p || *p != ',')
2173 error ("Internal error: live range string.\n");
2176 /* Get ending value of range and advance P past the reference id.
2178 ?!? In theory, the process_reference should never fail, but we should
2179 catch that case just in case the compiler scrogged the stabs. */
2180 refnum = process_reference (&p);
2181 end = ref_search_value (refnum);
2183 error ("Internal error: live range symbol not found.\n");
2185 if (!*p || *p != ')')
2186 error ("Internal error: live range string.\n");
2188 /* Now that we know the bounds of the range, add it to the
2190 add_live_range (objfile, sym, start, end);
2193 /* Add a new live range defined by START and END to the symbol SYM
2194 in objfile OBJFILE. */
2197 add_live_range (objfile, sym, start, end)
2198 struct objfile *objfile;
2200 CORE_ADDR start, end;
2202 struct range_list *r, *rs;
2205 error ("Internal error: end of live range follows start.\n");
2207 /* Alloc new live range structure. */
2208 r = (struct range_list *)
2209 obstack_alloc (&objfile->type_obstack,
2210 sizeof (struct range_list));
2215 /* Append this range to the symbol's range list. */
2216 if (!SYMBOL_RANGES (sym))
2218 SYMBOL_RANGES (sym) = r;
2222 /* Get the last range for the symbol. */
2223 for (rs = SYMBOL_RANGES (sym); rs->next; rs = rs->next)
2230 /* Skip rest of this symbol and return an error type.
2232 General notes on error recovery: error_type always skips to the
2233 end of the symbol (modulo cretinous dbx symbol name continuation).
2234 Thus code like this:
2236 if (*(*pp)++ != ';')
2237 return error_type (pp, objfile);
2239 is wrong because if *pp starts out pointing at '\0' (typically as the
2240 result of an earlier error), it will be incremented to point to the
2241 start of the next symbol, which might produce strange results, at least
2242 if you run off the end of the string table. Instead use
2245 return error_type (pp, objfile);
2251 foo = error_type (pp, objfile);
2255 And in case it isn't obvious, the point of all this hair is so the compiler
2256 can define new types and new syntaxes, and old versions of the
2257 debugger will be able to read the new symbol tables. */
2259 static struct type *
2260 error_type (pp, objfile)
2262 struct objfile *objfile;
2264 complain (&error_type_complaint);
2267 /* Skip to end of symbol. */
2268 while (**pp != '\0')
2273 /* Check for and handle cretinous dbx symbol name continuation! */
2274 if ((*pp)[-1] == '\\' || (*pp)[-1] == '?')
2276 *pp = next_symbol_text (objfile);
2283 return (builtin_type_error);
2287 /* Read type information or a type definition; return the type. Even
2288 though this routine accepts either type information or a type
2289 definition, the distinction is relevant--some parts of stabsread.c
2290 assume that type information starts with a digit, '-', or '(' in
2291 deciding whether to call read_type. */
2294 read_type (pp, objfile)
2296 struct objfile *objfile;
2298 register struct type *type = 0;
2301 char type_descriptor;
2303 /* Size in bits of type if specified by a type attribute, or -1 if
2304 there is no size attribute. */
2307 /* Used to distinguish string and bitstring from char-array and set. */
2310 /* Read type number if present. The type number may be omitted.
2311 for instance in a two-dimensional array declared with type
2312 "ar1;1;10;ar1;1;10;4". */
2313 if ((**pp >= '0' && **pp <= '9')
2317 if (read_type_number (pp, typenums) != 0)
2318 return error_type (pp, objfile);
2320 /* Type is not being defined here. Either it already exists,
2321 or this is a forward reference to it. dbx_alloc_type handles
2324 return dbx_alloc_type (typenums, objfile);
2326 /* Type is being defined here. */
2328 Also skip the type descriptor - we get it below with (*pp)[-1]. */
2333 /* 'typenums=' not present, type is anonymous. Read and return
2334 the definition, but don't put it in the type vector. */
2335 typenums[0] = typenums[1] = -1;
2340 type_descriptor = (*pp)[-1];
2341 switch (type_descriptor)
2345 enum type_code code;
2347 /* Used to index through file_symbols. */
2348 struct pending *ppt;
2351 /* Name including "struct", etc. */
2355 char *from, *to, *p, *q1, *q2;
2357 /* Set the type code according to the following letter. */
2361 code = TYPE_CODE_STRUCT;
2364 code = TYPE_CODE_UNION;
2367 code = TYPE_CODE_ENUM;
2371 /* Complain and keep going, so compilers can invent new
2372 cross-reference types. */
2373 static struct complaint msg =
2374 {"Unrecognized cross-reference type `%c'", 0, 0};
2375 complain (&msg, (*pp)[0]);
2376 code = TYPE_CODE_STRUCT;
2381 q1 = strchr (*pp, '<');
2382 p = strchr (*pp, ':');
2384 return error_type (pp, objfile);
2385 if (q1 && p > q1 && p[1] == ':')
2387 int nesting_level = 0;
2388 for (q2 = q1; *q2; q2++)
2392 else if (*q2 == '>')
2394 else if (*q2 == ':' && nesting_level == 0)
2399 return error_type (pp, objfile);
2402 (char *)obstack_alloc (&objfile->type_obstack, p - *pp + 1);
2404 /* Copy the name. */
2410 /* Set the pointer ahead of the name which we just read, and
2415 /* Now check to see whether the type has already been
2416 declared. This was written for arrays of cross-referenced
2417 types before we had TYPE_CODE_TARGET_STUBBED, so I'm pretty
2418 sure it is not necessary anymore. But it might be a good
2419 idea, to save a little memory. */
2421 for (ppt = file_symbols; ppt; ppt = ppt->next)
2422 for (i = 0; i < ppt->nsyms; i++)
2424 struct symbol *sym = ppt->symbol[i];
2426 if (SYMBOL_CLASS (sym) == LOC_TYPEDEF
2427 && SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE
2428 && (TYPE_CODE (SYMBOL_TYPE (sym)) == code)
2429 && STREQ (SYMBOL_NAME (sym), type_name))
2431 obstack_free (&objfile -> type_obstack, type_name);
2432 type = SYMBOL_TYPE (sym);
2437 /* Didn't find the type to which this refers, so we must
2438 be dealing with a forward reference. Allocate a type
2439 structure for it, and keep track of it so we can
2440 fill in the rest of the fields when we get the full
2442 type = dbx_alloc_type (typenums, objfile);
2443 TYPE_CODE (type) = code;
2444 TYPE_TAG_NAME (type) = type_name;
2445 INIT_CPLUS_SPECIFIC(type);
2446 TYPE_FLAGS (type) |= TYPE_FLAG_STUB;
2448 add_undefined_type (type);
2452 case '-': /* RS/6000 built-in type */
2466 /* We deal with something like t(1,2)=(3,4)=... which
2467 the Lucid compiler and recent gcc versions (post 2.7.3) use. */
2469 /* Allocate and enter the typedef type first.
2470 This handles recursive types. */
2471 type = dbx_alloc_type (typenums, objfile);
2472 TYPE_CODE (type) = TYPE_CODE_TYPEDEF;
2473 { struct type *xtype = read_type (pp, objfile);
2476 /* It's being defined as itself. That means it is "void". */
2477 TYPE_CODE (type) = TYPE_CODE_VOID;
2478 TYPE_LENGTH (type) = 1;
2480 else if (type_size >= 0 || is_string)
2483 TYPE_NAME (type) = NULL;
2484 TYPE_TAG_NAME (type) = NULL;
2488 TYPE_FLAGS (type) |= TYPE_FLAG_TARGET_STUB;
2489 TYPE_TARGET_TYPE (type) = xtype;
2494 /* In the following types, we must be sure to overwrite any existing
2495 type that the typenums refer to, rather than allocating a new one
2496 and making the typenums point to the new one. This is because there
2497 may already be pointers to the existing type (if it had been
2498 forward-referenced), and we must change it to a pointer, function,
2499 reference, or whatever, *in-place*. */
2502 type1 = read_type (pp, objfile);
2503 type = make_pointer_type (type1, dbx_lookup_type (typenums));
2506 case '&': /* Reference to another type */
2507 type1 = read_type (pp, objfile);
2508 type = make_reference_type (type1, dbx_lookup_type (typenums));
2511 case 'f': /* Function returning another type */
2512 if (os9k_stabs && **pp == '(')
2514 /* Function prototype; parse it.
2515 We must conditionalize this on os9k_stabs because otherwise
2516 it could be confused with a Sun-style (1,3) typenumber
2522 t = read_type (pp, objfile);
2523 if (**pp == ',') ++*pp;
2526 type1 = read_type (pp, objfile);
2527 type = make_function_type (type1, dbx_lookup_type (typenums));
2530 case 'k': /* Const qualifier on some type (Sun) */
2531 case 'c': /* Const qualifier on some type (OS9000) */
2532 /* Because 'c' means other things to AIX and 'k' is perfectly good,
2533 only accept 'c' in the os9k_stabs case. */
2534 if (type_descriptor == 'c' && !os9k_stabs)
2535 return error_type (pp, objfile);
2536 type = read_type (pp, objfile);
2537 /* FIXME! For now, we ignore const and volatile qualifiers. */
2540 case 'B': /* Volatile qual on some type (Sun) */
2541 case 'i': /* Volatile qual on some type (OS9000) */
2542 /* Because 'i' means other things to AIX and 'B' is perfectly good,
2543 only accept 'i' in the os9k_stabs case. */
2544 if (type_descriptor == 'i' && !os9k_stabs)
2545 return error_type (pp, objfile);
2546 type = read_type (pp, objfile);
2547 /* FIXME! For now, we ignore const and volatile qualifiers. */
2551 if (isdigit (**pp) || **pp == '(' || **pp == '-')
2552 { /* Member (class & variable) type */
2553 /* FIXME -- we should be doing smash_to_XXX types here. */
2555 struct type *domain = read_type (pp, objfile);
2556 struct type *memtype;
2559 /* Invalid member type data format. */
2560 return error_type (pp, objfile);
2563 memtype = read_type (pp, objfile);
2564 type = dbx_alloc_type (typenums, objfile);
2565 smash_to_member_type (type, domain, memtype);
2567 else /* type attribute */
2570 /* Skip to the semicolon. */
2571 while (**pp != ';' && **pp != '\0')
2574 return error_type (pp, objfile);
2576 ++*pp; /* Skip the semicolon. */
2581 type_size = atoi (attr + 1);
2591 /* Ignore unrecognized type attributes, so future compilers
2592 can invent new ones. */
2600 case '#': /* Method (class & fn) type */
2601 if ((*pp)[0] == '#')
2603 /* We'll get the parameter types from the name. */
2604 struct type *return_type;
2607 return_type = read_type (pp, objfile);
2608 if (*(*pp)++ != ';')
2609 complain (&invalid_member_complaint, symnum);
2610 type = allocate_stub_method (return_type);
2611 if (typenums[0] != -1)
2612 *dbx_lookup_type (typenums) = type;
2616 struct type *domain = read_type (pp, objfile);
2617 struct type *return_type;
2621 /* Invalid member type data format. */
2622 return error_type (pp, objfile);
2626 return_type = read_type (pp, objfile);
2627 args = read_args (pp, ';', objfile);
2628 type = dbx_alloc_type (typenums, objfile);
2629 smash_to_method_type (type, domain, return_type, args);
2633 case 'r': /* Range type */
2634 type = read_range_type (pp, typenums, objfile);
2635 if (typenums[0] != -1)
2636 *dbx_lookup_type (typenums) = type;
2641 /* Const and volatile qualified type. */
2642 type = read_type (pp, objfile);
2645 /* Sun ACC builtin int type */
2646 type = read_sun_builtin_type (pp, typenums, objfile);
2647 if (typenums[0] != -1)
2648 *dbx_lookup_type (typenums) = type;
2652 case 'R': /* Sun ACC builtin float type */
2653 type = read_sun_floating_type (pp, typenums, objfile);
2654 if (typenums[0] != -1)
2655 *dbx_lookup_type (typenums) = type;
2658 case 'e': /* Enumeration type */
2659 type = dbx_alloc_type (typenums, objfile);
2660 type = read_enum_type (pp, type, objfile);
2661 if (typenums[0] != -1)
2662 *dbx_lookup_type (typenums) = type;
2665 case 's': /* Struct type */
2666 case 'u': /* Union type */
2667 type = dbx_alloc_type (typenums, objfile);
2668 switch (type_descriptor)
2671 TYPE_CODE (type) = TYPE_CODE_STRUCT;
2674 TYPE_CODE (type) = TYPE_CODE_UNION;
2677 type = read_struct_type (pp, type, objfile);
2680 case 'a': /* Array type */
2682 return error_type (pp, objfile);
2685 type = dbx_alloc_type (typenums, objfile);
2686 type = read_array_type (pp, type, objfile);
2688 TYPE_CODE (type) = TYPE_CODE_STRING;
2692 type1 = read_type (pp, objfile);
2693 type = create_set_type ((struct type*) NULL, type1);
2695 TYPE_CODE (type) = TYPE_CODE_BITSTRING;
2696 if (typenums[0] != -1)
2697 *dbx_lookup_type (typenums) = type;
2701 --*pp; /* Go back to the symbol in error */
2702 /* Particularly important if it was \0! */
2703 return error_type (pp, objfile);
2708 warning ("GDB internal error, type is NULL in stabsread.c\n");
2709 return error_type (pp, objfile);
2712 /* Size specified in a type attribute overrides any other size. */
2713 if (type_size != -1)
2714 TYPE_LENGTH (type) = (type_size + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT;
2719 /* RS/6000 xlc/dbx combination uses a set of builtin types, starting from -1.
2720 Return the proper type node for a given builtin type number. */
2722 static struct type *
2723 rs6000_builtin_type (typenum)
2726 /* We recognize types numbered from -NUMBER_RECOGNIZED to -1. */
2727 #define NUMBER_RECOGNIZED 34
2728 /* This includes an empty slot for type number -0. */
2729 static struct type *negative_types[NUMBER_RECOGNIZED + 1];
2730 struct type *rettype = NULL;
2732 if (typenum >= 0 || typenum < -NUMBER_RECOGNIZED)
2734 complain (&rs6000_builtin_complaint, typenum);
2735 return builtin_type_error;
2737 if (negative_types[-typenum] != NULL)
2738 return negative_types[-typenum];
2740 #if TARGET_CHAR_BIT != 8
2741 #error This code wrong for TARGET_CHAR_BIT not 8
2742 /* These definitions all assume that TARGET_CHAR_BIT is 8. I think
2743 that if that ever becomes not true, the correct fix will be to
2744 make the size in the struct type to be in bits, not in units of
2751 /* The size of this and all the other types are fixed, defined
2752 by the debugging format. If there is a type called "int" which
2753 is other than 32 bits, then it should use a new negative type
2754 number (or avoid negative type numbers for that case).
2755 See stabs.texinfo. */
2756 rettype = init_type (TYPE_CODE_INT, 4, 0, "int", NULL);
2759 rettype = init_type (TYPE_CODE_INT, 1, 0, "char", NULL);
2762 rettype = init_type (TYPE_CODE_INT, 2, 0, "short", NULL);
2765 rettype = init_type (TYPE_CODE_INT, 4, 0, "long", NULL);
2768 rettype = init_type (TYPE_CODE_INT, 1, TYPE_FLAG_UNSIGNED,
2769 "unsigned char", NULL);
2772 rettype = init_type (TYPE_CODE_INT, 1, 0, "signed char", NULL);
2775 rettype = init_type (TYPE_CODE_INT, 2, TYPE_FLAG_UNSIGNED,
2776 "unsigned short", NULL);
2779 rettype = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED,
2780 "unsigned int", NULL);
2783 rettype = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED,
2786 rettype = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED,
2787 "unsigned long", NULL);
2790 rettype = init_type (TYPE_CODE_VOID, 1, 0, "void", NULL);
2793 /* IEEE single precision (32 bit). */
2794 rettype = init_type (TYPE_CODE_FLT, 4, 0, "float", NULL);
2797 /* IEEE double precision (64 bit). */
2798 rettype = init_type (TYPE_CODE_FLT, 8, 0, "double", NULL);
2801 /* This is an IEEE double on the RS/6000, and different machines with
2802 different sizes for "long double" should use different negative
2803 type numbers. See stabs.texinfo. */
2804 rettype = init_type (TYPE_CODE_FLT, 8, 0, "long double", NULL);
2807 rettype = init_type (TYPE_CODE_INT, 4, 0, "integer", NULL);
2810 rettype = init_type (TYPE_CODE_BOOL, 4, TYPE_FLAG_UNSIGNED,
2814 rettype = init_type (TYPE_CODE_FLT, 4, 0, "short real", NULL);
2817 rettype = init_type (TYPE_CODE_FLT, 8, 0, "real", NULL);
2820 rettype = init_type (TYPE_CODE_ERROR, 0, 0, "stringptr", NULL);
2823 rettype = init_type (TYPE_CODE_CHAR, 1, TYPE_FLAG_UNSIGNED,
2827 rettype = init_type (TYPE_CODE_BOOL, 1, TYPE_FLAG_UNSIGNED,
2831 rettype = init_type (TYPE_CODE_BOOL, 2, TYPE_FLAG_UNSIGNED,
2835 rettype = init_type (TYPE_CODE_BOOL, 4, TYPE_FLAG_UNSIGNED,
2839 rettype = init_type (TYPE_CODE_BOOL, 4, TYPE_FLAG_UNSIGNED,
2843 /* Complex type consisting of two IEEE single precision values. */
2844 rettype = init_type (TYPE_CODE_ERROR, 8, 0, "complex", NULL);
2847 /* Complex type consisting of two IEEE double precision values. */
2848 rettype = init_type (TYPE_CODE_ERROR, 16, 0, "double complex", NULL);
2851 rettype = init_type (TYPE_CODE_INT, 1, 0, "integer*1", NULL);
2854 rettype = init_type (TYPE_CODE_INT, 2, 0, "integer*2", NULL);
2857 rettype = init_type (TYPE_CODE_INT, 4, 0, "integer*4", NULL);
2860 rettype = init_type (TYPE_CODE_CHAR, 2, 0, "wchar", NULL);
2863 rettype = init_type (TYPE_CODE_INT, 8, 0, "long long", NULL);
2866 rettype = init_type (TYPE_CODE_INT, 8, TYPE_FLAG_UNSIGNED,
2867 "unsigned long long", NULL);
2870 rettype = init_type (TYPE_CODE_INT, 8, TYPE_FLAG_UNSIGNED,
2874 rettype = init_type (TYPE_CODE_INT, 8, 0, "integer*8", NULL);
2877 negative_types[-typenum] = rettype;
2881 /* This page contains subroutines of read_type. */
2883 /* Read member function stabs info for C++ classes. The form of each member
2886 NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
2888 An example with two member functions is:
2890 afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
2892 For the case of overloaded operators, the format is op$::*.funcs, where
2893 $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
2894 name (such as `+=') and `.' marks the end of the operator name.
2896 Returns 1 for success, 0 for failure. */
2899 read_member_functions (fip, pp, type, objfile)
2900 struct field_info *fip;
2903 struct objfile *objfile;
2907 /* Total number of member functions defined in this class. If the class
2908 defines two `f' functions, and one `g' function, then this will have
2910 int total_length = 0;
2914 struct next_fnfield *next;
2915 struct fn_field fn_field;
2917 struct type *look_ahead_type;
2918 struct next_fnfieldlist *new_fnlist;
2919 struct next_fnfield *new_sublist;
2923 /* Process each list until we find something that is not a member function
2924 or find the end of the functions. */
2928 /* We should be positioned at the start of the function name.
2929 Scan forward to find the first ':' and if it is not the
2930 first of a "::" delimiter, then this is not a member function. */
2942 look_ahead_type = NULL;
2945 new_fnlist = (struct next_fnfieldlist *)
2946 xmalloc (sizeof (struct next_fnfieldlist));
2947 make_cleanup (free, new_fnlist);
2948 memset (new_fnlist, 0, sizeof (struct next_fnfieldlist));
2950 if ((*pp)[0] == 'o' && (*pp)[1] == 'p' && is_cplus_marker ((*pp)[2]))
2952 /* This is a completely wierd case. In order to stuff in the
2953 names that might contain colons (the usual name delimiter),
2954 Mike Tiemann defined a different name format which is
2955 signalled if the identifier is "op$". In that case, the
2956 format is "op$::XXXX." where XXXX is the name. This is
2957 used for names like "+" or "=". YUUUUUUUK! FIXME! */
2958 /* This lets the user type "break operator+".
2959 We could just put in "+" as the name, but that wouldn't
2961 static char opname[32] = {'o', 'p', CPLUS_MARKER};
2962 char *o = opname + 3;
2964 /* Skip past '::'. */
2967 STABS_CONTINUE (pp, objfile);
2973 main_fn_name = savestring (opname, o - opname);
2979 main_fn_name = savestring (*pp, p - *pp);
2980 /* Skip past '::'. */
2983 new_fnlist -> fn_fieldlist.name = main_fn_name;
2988 (struct next_fnfield *) xmalloc (sizeof (struct next_fnfield));
2989 make_cleanup (free, new_sublist);
2990 memset (new_sublist, 0, sizeof (struct next_fnfield));
2992 /* Check for and handle cretinous dbx symbol name continuation! */
2993 if (look_ahead_type == NULL)
2996 STABS_CONTINUE (pp, objfile);
2998 new_sublist -> fn_field.type = read_type (pp, objfile);
3001 /* Invalid symtab info for member function. */
3007 /* g++ version 1 kludge */
3008 new_sublist -> fn_field.type = look_ahead_type;
3009 look_ahead_type = NULL;
3019 /* If this is just a stub, then we don't have the real name here. */
3021 if (TYPE_FLAGS (new_sublist -> fn_field.type) & TYPE_FLAG_STUB)
3023 if (!TYPE_DOMAIN_TYPE (new_sublist -> fn_field.type))
3024 TYPE_DOMAIN_TYPE (new_sublist -> fn_field.type) = type;
3025 new_sublist -> fn_field.is_stub = 1;
3027 new_sublist -> fn_field.physname = savestring (*pp, p - *pp);
3030 /* Set this member function's visibility fields. */
3033 case VISIBILITY_PRIVATE:
3034 new_sublist -> fn_field.is_private = 1;
3036 case VISIBILITY_PROTECTED:
3037 new_sublist -> fn_field.is_protected = 1;
3041 STABS_CONTINUE (pp, objfile);
3044 case 'A': /* Normal functions. */
3045 new_sublist -> fn_field.is_const = 0;
3046 new_sublist -> fn_field.is_volatile = 0;
3049 case 'B': /* `const' member functions. */
3050 new_sublist -> fn_field.is_const = 1;
3051 new_sublist -> fn_field.is_volatile = 0;
3054 case 'C': /* `volatile' member function. */
3055 new_sublist -> fn_field.is_const = 0;
3056 new_sublist -> fn_field.is_volatile = 1;
3059 case 'D': /* `const volatile' member function. */
3060 new_sublist -> fn_field.is_const = 1;
3061 new_sublist -> fn_field.is_volatile = 1;
3064 case '*': /* File compiled with g++ version 1 -- no info */
3069 complain (&const_vol_complaint, **pp);
3078 /* virtual member function, followed by index.
3079 The sign bit is set to distinguish pointers-to-methods
3080 from virtual function indicies. Since the array is
3081 in words, the quantity must be shifted left by 1
3082 on 16 bit machine, and by 2 on 32 bit machine, forcing
3083 the sign bit out, and usable as a valid index into
3084 the array. Remove the sign bit here. */
3085 new_sublist -> fn_field.voffset =
3086 (0x7fffffff & read_huge_number (pp, ';', &nbits)) + 2;
3090 STABS_CONTINUE (pp, objfile);
3091 if (**pp == ';' || **pp == '\0')
3093 /* Must be g++ version 1. */
3094 new_sublist -> fn_field.fcontext = 0;
3098 /* Figure out from whence this virtual function came.
3099 It may belong to virtual function table of
3100 one of its baseclasses. */
3101 look_ahead_type = read_type (pp, objfile);
3104 /* g++ version 1 overloaded methods. */
3108 new_sublist -> fn_field.fcontext = look_ahead_type;
3117 look_ahead_type = NULL;
3123 /* static member function. */
3124 new_sublist -> fn_field.voffset = VOFFSET_STATIC;
3125 if (strncmp (new_sublist -> fn_field.physname,
3126 main_fn_name, strlen (main_fn_name)))
3128 new_sublist -> fn_field.is_stub = 1;
3134 complain (&member_fn_complaint, (*pp)[-1]);
3135 /* Fall through into normal member function. */
3138 /* normal member function. */
3139 new_sublist -> fn_field.voffset = 0;
3140 new_sublist -> fn_field.fcontext = 0;
3144 new_sublist -> next = sublist;
3145 sublist = new_sublist;
3147 STABS_CONTINUE (pp, objfile);
3149 while (**pp != ';' && **pp != '\0');
3153 new_fnlist -> fn_fieldlist.fn_fields = (struct fn_field *)
3154 obstack_alloc (&objfile -> type_obstack,
3155 sizeof (struct fn_field) * length);
3156 memset (new_fnlist -> fn_fieldlist.fn_fields, 0,
3157 sizeof (struct fn_field) * length);
3158 for (i = length; (i--, sublist); sublist = sublist -> next)
3160 new_fnlist -> fn_fieldlist.fn_fields[i] = sublist -> fn_field;
3163 new_fnlist -> fn_fieldlist.length = length;
3164 new_fnlist -> next = fip -> fnlist;
3165 fip -> fnlist = new_fnlist;
3167 total_length += length;
3168 STABS_CONTINUE (pp, objfile);
3173 ALLOCATE_CPLUS_STRUCT_TYPE (type);
3174 TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
3175 TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * nfn_fields);
3176 memset (TYPE_FN_FIELDLISTS (type), 0,
3177 sizeof (struct fn_fieldlist) * nfn_fields);
3178 TYPE_NFN_FIELDS (type) = nfn_fields;
3179 TYPE_NFN_FIELDS_TOTAL (type) = total_length;
3185 /* Special GNU C++ name.
3187 Returns 1 for success, 0 for failure. "failure" means that we can't
3188 keep parsing and it's time for error_type(). */
3191 read_cpp_abbrev (fip, pp, type, objfile)
3192 struct field_info *fip;
3195 struct objfile *objfile;
3200 struct type *context;
3210 /* At this point, *pp points to something like "22:23=*22...",
3211 where the type number before the ':' is the "context" and
3212 everything after is a regular type definition. Lookup the
3213 type, find it's name, and construct the field name. */
3215 context = read_type (pp, objfile);
3219 case 'f': /* $vf -- a virtual function table pointer */
3220 fip->list->field.name =
3221 obconcat (&objfile->type_obstack, vptr_name, "", "");
3224 case 'b': /* $vb -- a virtual bsomethingorother */
3225 name = type_name_no_tag (context);
3228 complain (&invalid_cpp_type_complaint, symnum);
3231 fip->list->field.name =
3232 obconcat (&objfile->type_obstack, vb_name, name, "");
3236 complain (&invalid_cpp_abbrev_complaint, *pp);
3237 fip->list->field.name =
3238 obconcat (&objfile->type_obstack,
3239 "INVALID_CPLUSPLUS_ABBREV", "", "");
3243 /* At this point, *pp points to the ':'. Skip it and read the
3249 complain (&invalid_cpp_abbrev_complaint, *pp);
3252 fip->list->field.type = read_type (pp, objfile);
3254 (*pp)++; /* Skip the comma. */
3260 FIELD_BITPOS (fip->list->field) = read_huge_number (pp, ';', &nbits);
3264 /* This field is unpacked. */
3265 FIELD_BITSIZE (fip->list->field) = 0;
3266 fip->list->visibility = VISIBILITY_PRIVATE;
3270 complain (&invalid_cpp_abbrev_complaint, *pp);
3271 /* We have no idea what syntax an unrecognized abbrev would have, so
3272 better return 0. If we returned 1, we would need to at least advance
3273 *pp to avoid an infinite loop. */
3280 read_one_struct_field (fip, pp, p, type, objfile)
3281 struct field_info *fip;
3285 struct objfile *objfile;
3287 /* The following is code to work around cfront generated stabs.
3288 The stabs contains full mangled name for each field.
3289 We try to demangle the name and extract the field name out of it.
3291 if (ARM_DEMANGLING && current_subfile->language == language_cplus)
3297 dem = cplus_demangle (*pp, DMGL_ANSI | DMGL_PARAMS);
3300 dem_p = strrchr (dem, ':');
3301 if (dem_p != 0 && *(dem_p-1)==':')
3303 FIELD_NAME (fip->list->field) =
3304 obsavestring (dem_p, strlen (dem_p), &objfile -> type_obstack);
3308 FIELD_NAME (fip->list->field) =
3309 obsavestring (*pp, p - *pp, &objfile -> type_obstack);
3313 /* end of code for cfront work around */
3316 fip -> list -> field.name =
3317 obsavestring (*pp, p - *pp, &objfile -> type_obstack);
3320 /* This means we have a visibility for a field coming. */
3324 fip -> list -> visibility = *(*pp)++;
3328 /* normal dbx-style format, no explicit visibility */
3329 fip -> list -> visibility = VISIBILITY_PUBLIC;
3332 fip -> list -> field.type = read_type (pp, objfile);
3337 /* Possible future hook for nested types. */
3340 fip -> list -> field.bitpos = (long)-2; /* nested type */
3349 /* Static class member. */
3350 SET_FIELD_PHYSNAME (fip->list->field, savestring (*pp, p - *pp));
3354 else if (**pp != ',')
3356 /* Bad structure-type format. */
3357 complain (&stabs_general_complaint, "bad structure-type format");
3361 (*pp)++; /* Skip the comma. */
3365 FIELD_BITPOS (fip->list->field) = read_huge_number (pp, ',', &nbits);
3368 complain (&stabs_general_complaint, "bad structure-type format");
3371 FIELD_BITSIZE (fip->list->field) = read_huge_number (pp, ';', &nbits);
3374 complain (&stabs_general_complaint, "bad structure-type format");
3379 if (FIELD_BITPOS (fip->list->field) == 0
3380 && FIELD_BITSIZE (fip->list->field) == 0)
3382 /* This can happen in two cases: (1) at least for gcc 2.4.5 or so,
3383 it is a field which has been optimized out. The correct stab for
3384 this case is to use VISIBILITY_IGNORE, but that is a recent
3385 invention. (2) It is a 0-size array. For example
3386 union { int num; char str[0]; } foo. Printing "<no value>" for
3387 str in "p foo" is OK, since foo.str (and thus foo.str[3])
3388 will continue to work, and a 0-size array as a whole doesn't
3389 have any contents to print.
3391 I suspect this probably could also happen with gcc -gstabs (not
3392 -gstabs+) for static fields, and perhaps other C++ extensions.
3393 Hopefully few people use -gstabs with gdb, since it is intended
3394 for dbx compatibility. */
3396 /* Ignore this field. */
3397 fip -> list-> visibility = VISIBILITY_IGNORE;
3401 /* Detect an unpacked field and mark it as such.
3402 dbx gives a bit size for all fields.
3403 Note that forward refs cannot be packed,
3404 and treat enums as if they had the width of ints. */
3406 if (TYPE_CODE (FIELD_TYPE (fip->list->field)) != TYPE_CODE_INT
3407 && TYPE_CODE (FIELD_TYPE (fip->list->field)) != TYPE_CODE_BOOL
3408 && TYPE_CODE (FIELD_TYPE (fip->list->field)) != TYPE_CODE_ENUM)
3410 FIELD_BITSIZE (fip->list->field) = 0;
3412 if ((FIELD_BITSIZE (fip->list->field)
3413 == TARGET_CHAR_BIT * TYPE_LENGTH (FIELD_TYPE (fip->list->field))
3414 || (TYPE_CODE (FIELD_TYPE (fip->list->field)) == TYPE_CODE_ENUM
3415 && FIELD_BITSIZE (fip->list->field) == TARGET_INT_BIT )
3418 FIELD_BITPOS (fip->list->field) % 8 == 0)
3420 FIELD_BITSIZE (fip->list->field) = 0;
3426 /* Read struct or class data fields. They have the form:
3428 NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
3430 At the end, we see a semicolon instead of a field.
3432 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
3435 The optional VISIBILITY is one of:
3437 '/0' (VISIBILITY_PRIVATE)
3438 '/1' (VISIBILITY_PROTECTED)
3439 '/2' (VISIBILITY_PUBLIC)
3440 '/9' (VISIBILITY_IGNORE)
3442 or nothing, for C style fields with public visibility.
3444 Returns 1 for success, 0 for failure. */
3447 read_struct_fields (fip, pp, type, objfile)
3448 struct field_info *fip;
3451 struct objfile *objfile;
3454 struct nextfield *new;
3456 /* We better set p right now, in case there are no fields at all... */
3460 /* Read each data member type until we find the terminating ';' at the end of
3461 the data member list, or break for some other reason such as finding the
3462 start of the member function list. */
3466 if (os9k_stabs && **pp == ',') break;
3467 STABS_CONTINUE (pp, objfile);
3468 /* Get space to record the next field's data. */
3469 new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
3470 make_cleanup (free, new);
3471 memset (new, 0, sizeof (struct nextfield));
3472 new -> next = fip -> list;
3475 /* Get the field name. */
3478 /* If is starts with CPLUS_MARKER it is a special abbreviation,
3479 unless the CPLUS_MARKER is followed by an underscore, in
3480 which case it is just the name of an anonymous type, which we
3481 should handle like any other type name. */
3483 if (is_cplus_marker (p[0]) && p[1] != '_')
3485 if (!read_cpp_abbrev (fip, pp, type, objfile))
3490 /* Look for the ':' that separates the field name from the field
3491 values. Data members are delimited by a single ':', while member
3492 functions are delimited by a pair of ':'s. When we hit the member
3493 functions (if any), terminate scan loop and return. */
3495 while (*p != ':' && *p != '\0')
3502 /* Check to see if we have hit the member functions yet. */
3507 read_one_struct_field (fip, pp, p, type, objfile);
3509 if (p[0] == ':' && p[1] == ':')
3511 /* chill the list of fields: the last entry (at the head) is a
3512 partially constructed entry which we now scrub. */
3513 fip -> list = fip -> list -> next;
3518 /* The stabs for C++ derived classes contain baseclass information which
3519 is marked by a '!' character after the total size. This function is
3520 called when we encounter the baseclass marker, and slurps up all the
3521 baseclass information.
3523 Immediately following the '!' marker is the number of base classes that
3524 the class is derived from, followed by information for each base class.
3525 For each base class, there are two visibility specifiers, a bit offset
3526 to the base class information within the derived class, a reference to
3527 the type for the base class, and a terminating semicolon.
3529 A typical example, with two base classes, would be "!2,020,19;0264,21;".
3531 Baseclass information marker __________________|| | | | | | |
3532 Number of baseclasses __________________________| | | | | | |
3533 Visibility specifiers (2) ________________________| | | | | |
3534 Offset in bits from start of class _________________| | | | |
3535 Type number for base class ___________________________| | | |
3536 Visibility specifiers (2) _______________________________| | |
3537 Offset in bits from start of class ________________________| |
3538 Type number of base class ____________________________________|
3540 Return 1 for success, 0 for (error-type-inducing) failure. */
3543 read_baseclasses (fip, pp, type, objfile)
3544 struct field_info *fip;
3547 struct objfile *objfile;
3550 struct nextfield *new;
3558 /* Skip the '!' baseclass information marker. */
3562 ALLOCATE_CPLUS_STRUCT_TYPE (type);
3565 TYPE_N_BASECLASSES (type) = read_huge_number (pp, ',', &nbits);
3571 /* Some stupid compilers have trouble with the following, so break
3572 it up into simpler expressions. */
3573 TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *)
3574 TYPE_ALLOC (type, B_BYTES (TYPE_N_BASECLASSES (type)));
3577 int num_bytes = B_BYTES (TYPE_N_BASECLASSES (type));
3580 pointer = (char *) TYPE_ALLOC (type, num_bytes);
3581 TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *) pointer;
3585 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), TYPE_N_BASECLASSES (type));
3587 for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
3589 new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
3590 make_cleanup (free, new);
3591 memset (new, 0, sizeof (struct nextfield));
3592 new -> next = fip -> list;
3594 FIELD_BITSIZE (new->field) = 0; /* this should be an unpacked field! */
3596 STABS_CONTINUE (pp, objfile);
3600 /* Nothing to do. */
3603 SET_TYPE_FIELD_VIRTUAL (type, i);
3606 /* Unknown character. Complain and treat it as non-virtual. */
3608 static struct complaint msg = {
3609 "Unknown virtual character `%c' for baseclass", 0, 0};
3610 complain (&msg, **pp);
3615 new -> visibility = *(*pp)++;
3616 switch (new -> visibility)
3618 case VISIBILITY_PRIVATE:
3619 case VISIBILITY_PROTECTED:
3620 case VISIBILITY_PUBLIC:
3623 /* Bad visibility format. Complain and treat it as
3626 static struct complaint msg = {
3627 "Unknown visibility `%c' for baseclass", 0, 0};
3628 complain (&msg, new -> visibility);
3629 new -> visibility = VISIBILITY_PUBLIC;
3636 /* The remaining value is the bit offset of the portion of the object
3637 corresponding to this baseclass. Always zero in the absence of
3638 multiple inheritance. */
3640 FIELD_BITPOS (new->field) = read_huge_number (pp, ',', &nbits);
3645 /* The last piece of baseclass information is the type of the
3646 base class. Read it, and remember it's type name as this
3649 new -> field.type = read_type (pp, objfile);
3650 new -> field.name = type_name_no_tag (new -> field.type);
3652 /* skip trailing ';' and bump count of number of fields seen */
3661 /* The tail end of stabs for C++ classes that contain a virtual function
3662 pointer contains a tilde, a %, and a type number.
3663 The type number refers to the base class (possibly this class itself) which
3664 contains the vtable pointer for the current class.
3666 This function is called when we have parsed all the method declarations,
3667 so we can look for the vptr base class info. */
3670 read_tilde_fields (fip, pp, type, objfile)
3671 struct field_info *fip;
3674 struct objfile *objfile;
3678 STABS_CONTINUE (pp, objfile);
3680 /* If we are positioned at a ';', then skip it. */
3690 if (**pp == '=' || **pp == '+' || **pp == '-')
3692 /* Obsolete flags that used to indicate the presence
3693 of constructors and/or destructors. */
3697 /* Read either a '%' or the final ';'. */
3698 if (*(*pp)++ == '%')
3700 /* The next number is the type number of the base class
3701 (possibly our own class) which supplies the vtable for
3702 this class. Parse it out, and search that class to find
3703 its vtable pointer, and install those into TYPE_VPTR_BASETYPE
3704 and TYPE_VPTR_FIELDNO. */
3709 t = read_type (pp, objfile);
3711 while (*p != '\0' && *p != ';')
3717 /* Premature end of symbol. */
3721 TYPE_VPTR_BASETYPE (type) = t;
3722 if (type == t) /* Our own class provides vtbl ptr */
3724 for (i = TYPE_NFIELDS (t) - 1;
3725 i >= TYPE_N_BASECLASSES (t);
3728 if (! strncmp (TYPE_FIELD_NAME (t, i), vptr_name,
3729 sizeof (vptr_name) - 1))
3731 TYPE_VPTR_FIELDNO (type) = i;
3735 /* Virtual function table field not found. */
3736 complain (&vtbl_notfound_complaint, TYPE_NAME (type));
3741 TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t);
3752 attach_fn_fields_to_type (fip, type)
3753 struct field_info *fip;
3754 register struct type *type;
3758 for (n = TYPE_NFN_FIELDS (type);
3759 fip -> fnlist != NULL;
3760 fip -> fnlist = fip -> fnlist -> next)
3762 --n; /* Circumvent Sun3 compiler bug */
3763 TYPE_FN_FIELDLISTS (type)[n] = fip -> fnlist -> fn_fieldlist;
3768 /* read cfront class static data.
3769 pp points to string starting with the list of static data
3770 eg: A:ZcA;1@Bpub v2@Bvirpri;__ct__1AFv func__1AFv *sfunc__1AFv ;as__1A ;;
3773 A:ZcA;;foopri__1AFv foopro__1AFv __ct__1AFv __ct__1AFRC1A foopub__1AFv ;;;
3778 read_cfront_static_fields (fip, pp, type, objfile)
3779 struct field_info *fip;
3782 struct objfile *objfile;
3784 struct nextfield * new;
3787 struct symbol * ref_static=0;
3789 if (**pp==';') /* no static data; return */
3795 /* Process each field in the list until we find the terminating ";" */
3797 /* eg: p = "as__1A ;;;" */
3798 STABS_CONTINUE (pp, objfile); /* handle \\ */
3799 while (**pp!=';' && (sname = get_substring (pp, ' '), sname))
3801 ref_static = lookup_symbol (sname, 0, VAR_NAMESPACE, 0, 0); /*demangled_name*/
3804 static struct complaint msg = {"\
3805 Unable to find symbol for static data field %s\n",
3807 complain (&msg, sname);
3810 stype = SYMBOL_TYPE(ref_static);
3812 /* allocate a new fip */
3813 new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
3814 make_cleanup (free, new);
3815 memset (new, 0, sizeof (struct nextfield));
3816 new -> next = fip -> list;
3819 /* set visibility */
3820 /* FIXME! no way to tell visibility from stabs??? */
3821 new -> visibility = VISIBILITY_PUBLIC;
3823 /* set field info into fip */
3824 fip -> list -> field.type = stype;
3826 /* set bitpos & bitsize */
3827 SET_FIELD_PHYSNAME (fip->list->field, savestring (sname, strlen (sname)));
3829 /* set name field */
3830 /* The following is code to work around cfront generated stabs.
3831 The stabs contains full mangled name for each field.
3832 We try to demangle the name and extract the field name out of it.
3837 dem = cplus_demangle (sname, DMGL_ANSI | DMGL_PARAMS);
3840 dem_p = strrchr (dem, ':');
3841 if (dem_p != 0 && *(dem_p-1)==':')
3843 fip->list->field.name =
3844 obsavestring (dem_p, strlen (dem_p), &objfile -> type_obstack);
3848 fip->list->field.name =
3849 obsavestring (sname, strlen (sname), &objfile -> type_obstack);
3851 } /* end of code for cfront work around */
3852 } /* loop again for next static field */
3856 /* Copy structure fields to fip so attach_fields_to_type will work.
3857 type has already been created with the initial instance data fields.
3858 Now we want to be able to add the other members to the class,
3859 so we want to add them back to the fip and reattach them again
3860 once we have collected all the class members. */
3863 copy_cfront_struct_fields (fip, type, objfile)
3864 struct field_info *fip;
3866 struct objfile *objfile;
3868 int nfields = TYPE_NFIELDS(type);
3870 struct nextfield * new;
3872 /* Copy the fields into the list of fips and reset the types
3873 to remove the old fields */
3875 for (i=0; i<nfields; i++)
3877 /* allocate a new fip */
3878 new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
3879 make_cleanup (free, new);
3880 memset (new, 0, sizeof (struct nextfield));
3881 new -> next = fip -> list;
3884 /* copy field info into fip */
3885 new -> field = TYPE_FIELD (type, i);
3886 /* set visibility */
3887 if (TYPE_FIELD_PROTECTED (type, i))
3888 new -> visibility = VISIBILITY_PROTECTED;
3889 else if (TYPE_FIELD_PRIVATE (type, i))
3890 new -> visibility = VISIBILITY_PRIVATE;
3892 new -> visibility = VISIBILITY_PUBLIC;
3894 /* Now delete the fields from the type since we will be
3895 allocing new space once we get the rest of the fields
3896 in attach_fields_to_type.
3897 The pointer TYPE_FIELDS(type) is left dangling but should
3898 be freed later by objstack_free */
3899 TYPE_FIELDS (type)=0;
3900 TYPE_NFIELDS (type) = 0;
3905 /* Create the vector of fields, and record how big it is.
3906 We need this info to record proper virtual function table information
3907 for this class's virtual functions. */
3910 attach_fields_to_type (fip, type, objfile)
3911 struct field_info *fip;
3912 register struct type *type;
3913 struct objfile *objfile;
3915 register int nfields = 0;
3916 register int non_public_fields = 0;
3917 register struct nextfield *scan;
3919 /* Count up the number of fields that we have, as well as taking note of
3920 whether or not there are any non-public fields, which requires us to
3921 allocate and build the private_field_bits and protected_field_bits
3924 for (scan = fip -> list; scan != NULL; scan = scan -> next)
3927 if (scan -> visibility != VISIBILITY_PUBLIC)
3929 non_public_fields++;
3933 /* Now we know how many fields there are, and whether or not there are any
3934 non-public fields. Record the field count, allocate space for the
3935 array of fields, and create blank visibility bitfields if necessary. */
3937 TYPE_NFIELDS (type) = nfields;
3938 TYPE_FIELDS (type) = (struct field *)
3939 TYPE_ALLOC (type, sizeof (struct field) * nfields);
3940 memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields);
3942 if (non_public_fields)
3944 ALLOCATE_CPLUS_STRUCT_TYPE (type);
3946 TYPE_FIELD_PRIVATE_BITS (type) =
3947 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
3948 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
3950 TYPE_FIELD_PROTECTED_BITS (type) =
3951 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
3952 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
3954 TYPE_FIELD_IGNORE_BITS (type) =
3955 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
3956 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields);
3959 /* Copy the saved-up fields into the field vector. Start from the head
3960 of the list, adding to the tail of the field array, so that they end
3961 up in the same order in the array in which they were added to the list. */
3963 while (nfields-- > 0)
3965 TYPE_FIELD (type, nfields) = fip -> list -> field;
3966 switch (fip -> list -> visibility)
3968 case VISIBILITY_PRIVATE:
3969 SET_TYPE_FIELD_PRIVATE (type, nfields);
3972 case VISIBILITY_PROTECTED:
3973 SET_TYPE_FIELD_PROTECTED (type, nfields);
3976 case VISIBILITY_IGNORE:
3977 SET_TYPE_FIELD_IGNORE (type, nfields);
3980 case VISIBILITY_PUBLIC:
3984 /* Unknown visibility. Complain and treat it as public. */
3986 static struct complaint msg = {
3987 "Unknown visibility `%c' for field", 0, 0};
3988 complain (&msg, fip -> list -> visibility);
3992 fip -> list = fip -> list -> next;
3997 /* Read the description of a structure (or union type) and return an object
3998 describing the type.
4000 PP points to a character pointer that points to the next unconsumed token
4001 in the the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
4002 *PP will point to "4a:1,0,32;;".
4004 TYPE points to an incomplete type that needs to be filled in.
4006 OBJFILE points to the current objfile from which the stabs information is
4007 being read. (Note that it is redundant in that TYPE also contains a pointer
4008 to this same objfile, so it might be a good idea to eliminate it. FIXME).
4011 static struct type *
4012 read_struct_type (pp, type, objfile)
4015 struct objfile *objfile;
4017 struct cleanup *back_to;
4018 struct field_info fi;
4023 back_to = make_cleanup (null_cleanup, 0);
4025 INIT_CPLUS_SPECIFIC (type);
4026 TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
4028 /* First comes the total size in bytes. */
4032 TYPE_LENGTH (type) = read_huge_number (pp, 0, &nbits);
4034 return error_type (pp, objfile);
4037 /* Now read the baseclasses, if any, read the regular C struct or C++
4038 class member fields, attach the fields to the type, read the C++
4039 member functions, attach them to the type, and then read any tilde
4040 field (baseclass specifier for the class holding the main vtable). */
4042 if (!read_baseclasses (&fi, pp, type, objfile)
4043 || !read_struct_fields (&fi, pp, type, objfile)
4044 || !attach_fields_to_type (&fi, type, objfile)
4045 || !read_member_functions (&fi, pp, type, objfile)
4046 || !attach_fn_fields_to_type (&fi, type)
4047 || !read_tilde_fields (&fi, pp, type, objfile))
4049 type = error_type (pp, objfile);
4052 do_cleanups (back_to);
4056 /* Read a definition of an array type,
4057 and create and return a suitable type object.
4058 Also creates a range type which represents the bounds of that
4061 static struct type *
4062 read_array_type (pp, type, objfile)
4064 register struct type *type;
4065 struct objfile *objfile;
4067 struct type *index_type, *element_type, *range_type;
4072 /* Format of an array type:
4073 "ar<index type>;lower;upper;<array_contents_type>".
4074 OS9000: "arlower,upper;<array_contents_type>".
4076 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
4077 for these, produce a type like float[][]. */
4080 index_type = builtin_type_int;
4083 index_type = read_type (pp, objfile);
4085 /* Improper format of array type decl. */
4086 return error_type (pp, objfile);
4090 if (!(**pp >= '0' && **pp <= '9') && **pp != '-')
4095 lower = read_huge_number (pp, os9k_stabs ? ',' : ';', &nbits);
4097 return error_type (pp, objfile);
4099 if (!(**pp >= '0' && **pp <= '9') && **pp != '-')
4104 upper = read_huge_number (pp, ';', &nbits);
4106 return error_type (pp, objfile);
4108 element_type = read_type (pp, objfile);
4117 create_range_type ((struct type *) NULL, index_type, lower, upper);
4118 type = create_array_type (type, element_type, range_type);
4124 /* Read a definition of an enumeration type,
4125 and create and return a suitable type object.
4126 Also defines the symbols that represent the values of the type. */
4128 static struct type *
4129 read_enum_type (pp, type, objfile)
4131 register struct type *type;
4132 struct objfile *objfile;
4137 register struct symbol *sym;
4139 struct pending **symlist;
4140 struct pending *osyms, *syms;
4143 int unsigned_enum = 1;
4146 /* FIXME! The stabs produced by Sun CC merrily define things that ought
4147 to be file-scope, between N_FN entries, using N_LSYM. What's a mother
4148 to do? For now, force all enum values to file scope. */
4149 if (within_function)
4150 symlist = &local_symbols;
4153 symlist = &file_symbols;
4155 o_nsyms = osyms ? osyms->nsyms : 0;
4159 /* Size. Perhaps this does not have to be conditionalized on
4160 os9k_stabs (assuming the name of an enum constant can't start
4162 read_huge_number (pp, 0, &nbits);
4164 return error_type (pp, objfile);
4167 /* The aix4 compiler emits an extra field before the enum members;
4168 my guess is it's a type of some sort. Just ignore it. */
4171 /* Skip over the type. */
4175 /* Skip over the colon. */
4179 /* Read the value-names and their values.
4180 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
4181 A semicolon or comma instead of a NAME means the end. */
4182 while (**pp && **pp != ';' && **pp != ',')
4184 STABS_CONTINUE (pp, objfile);
4186 while (*p != ':') p++;
4187 name = obsavestring (*pp, p - *pp, &objfile -> symbol_obstack);
4189 n = read_huge_number (pp, ',', &nbits);
4191 return error_type (pp, objfile);
4193 sym = (struct symbol *)
4194 obstack_alloc (&objfile -> symbol_obstack, sizeof (struct symbol));
4195 memset (sym, 0, sizeof (struct symbol));
4196 SYMBOL_NAME (sym) = name;
4197 SYMBOL_LANGUAGE (sym) = current_subfile -> language;
4198 SYMBOL_CLASS (sym) = LOC_CONST;
4199 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
4200 SYMBOL_VALUE (sym) = n;
4203 add_symbol_to_list (sym, symlist);
4208 (*pp)++; /* Skip the semicolon. */
4210 /* Now fill in the fields of the type-structure. */
4212 TYPE_LENGTH (type) = TARGET_INT_BIT / HOST_CHAR_BIT;
4213 TYPE_CODE (type) = TYPE_CODE_ENUM;
4214 TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
4216 TYPE_FLAGS (type) |= TYPE_FLAG_UNSIGNED;
4217 TYPE_NFIELDS (type) = nsyms;
4218 TYPE_FIELDS (type) = (struct field *)
4219 TYPE_ALLOC (type, sizeof (struct field) * nsyms);
4220 memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nsyms);
4222 /* Find the symbols for the values and put them into the type.
4223 The symbols can be found in the symlist that we put them on
4224 to cause them to be defined. osyms contains the old value
4225 of that symlist; everything up to there was defined by us. */
4226 /* Note that we preserve the order of the enum constants, so
4227 that in something like "enum {FOO, LAST_THING=FOO}" we print
4228 FOO, not LAST_THING. */
4230 for (syms = *symlist, n = nsyms - 1; syms; syms = syms->next)
4232 int last = syms == osyms ? o_nsyms : 0;
4233 int j = syms->nsyms;
4234 for (; --j >= last; --n)
4236 struct symbol *xsym = syms->symbol[j];
4237 SYMBOL_TYPE (xsym) = type;
4238 TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym);
4239 TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (xsym);
4240 TYPE_FIELD_BITSIZE (type, n) = 0;
4249 /* Sun's ACC uses a somewhat saner method for specifying the builtin
4250 typedefs in every file (for int, long, etc):
4252 type = b <signed> <width>; <offset>; <nbits>
4253 signed = u or s. Possible c in addition to u or s (for char?).
4254 offset = offset from high order bit to start bit of type.
4255 width is # bytes in object of this type, nbits is # bits in type.
4257 The width/offset stuff appears to be for small objects stored in
4258 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
4261 static struct type *
4262 read_sun_builtin_type (pp, typenums, objfile)
4265 struct objfile *objfile;
4280 return error_type (pp, objfile);
4284 /* For some odd reason, all forms of char put a c here. This is strange
4285 because no other type has this honor. We can safely ignore this because
4286 we actually determine 'char'acterness by the number of bits specified in
4292 /* The first number appears to be the number of bytes occupied
4293 by this type, except that unsigned short is 4 instead of 2.
4294 Since this information is redundant with the third number,
4295 we will ignore it. */
4296 read_huge_number (pp, ';', &nbits);
4298 return error_type (pp, objfile);
4300 /* The second number is always 0, so ignore it too. */
4301 read_huge_number (pp, ';', &nbits);
4303 return error_type (pp, objfile);
4305 /* The third number is the number of bits for this type. */
4306 type_bits = read_huge_number (pp, 0, &nbits);
4308 return error_type (pp, objfile);
4309 /* The type *should* end with a semicolon. If it are embedded
4310 in a larger type the semicolon may be the only way to know where
4311 the type ends. If this type is at the end of the stabstring we
4312 can deal with the omitted semicolon (but we don't have to like
4313 it). Don't bother to complain(), Sun's compiler omits the semicolon
4319 return init_type (TYPE_CODE_VOID, 1,
4320 signed_type ? 0 : TYPE_FLAG_UNSIGNED, (char *)NULL,
4323 return init_type (TYPE_CODE_INT,
4324 type_bits / TARGET_CHAR_BIT,
4325 signed_type ? 0 : TYPE_FLAG_UNSIGNED, (char *)NULL,
4329 static struct type *
4330 read_sun_floating_type (pp, typenums, objfile)
4333 struct objfile *objfile;
4339 /* The first number has more details about the type, for example
4341 details = read_huge_number (pp, ';', &nbits);
4343 return error_type (pp, objfile);
4345 /* The second number is the number of bytes occupied by this type */
4346 nbytes = read_huge_number (pp, ';', &nbits);
4348 return error_type (pp, objfile);
4350 if (details == NF_COMPLEX || details == NF_COMPLEX16
4351 || details == NF_COMPLEX32)
4352 /* This is a type we can't handle, but we do know the size.
4353 We also will be able to give it a name. */
4354 return init_type (TYPE_CODE_ERROR, nbytes, 0, NULL, objfile);
4356 return init_type (TYPE_CODE_FLT, nbytes, 0, NULL, objfile);
4359 /* Read a number from the string pointed to by *PP.
4360 The value of *PP is advanced over the number.
4361 If END is nonzero, the character that ends the
4362 number must match END, or an error happens;
4363 and that character is skipped if it does match.
4364 If END is zero, *PP is left pointing to that character.
4366 If the number fits in a long, set *BITS to 0 and return the value.
4367 If not, set *BITS to be the number of bits in the number and return 0.
4369 If encounter garbage, set *BITS to -1 and return 0. */
4372 read_huge_number (pp, end, bits)
4392 /* Leading zero means octal. GCC uses this to output values larger
4393 than an int (because that would be hard in decimal). */
4401 upper_limit = ULONG_MAX / radix;
4403 upper_limit = LONG_MAX / radix;
4405 while ((c = *p++) >= '0' && c < ('0' + radix))
4407 if (n <= upper_limit)
4410 n += c - '0'; /* FIXME this overflows anyway */
4415 /* This depends on large values being output in octal, which is
4422 /* Ignore leading zeroes. */
4426 else if (c == '2' || c == '3')
4452 /* Large decimal constants are an error (because it is hard to
4453 count how many bits are in them). */
4459 /* -0x7f is the same as 0x80. So deal with it by adding one to
4460 the number of bits. */
4472 /* It's *BITS which has the interesting information. */
4476 static struct type *
4477 read_range_type (pp, typenums, objfile)
4480 struct objfile *objfile;
4482 char *orig_pp = *pp;
4487 struct type *result_type;
4488 struct type *index_type = NULL;
4490 /* First comes a type we are a subrange of.
4491 In C it is usually 0, 1 or the type being defined. */
4492 if (read_type_number (pp, rangenums) != 0)
4493 return error_type (pp, objfile);
4494 self_subrange = (rangenums[0] == typenums[0] &&
4495 rangenums[1] == typenums[1]);
4500 index_type = read_type (pp, objfile);
4503 /* A semicolon should now follow; skip it. */
4507 /* The remaining two operands are usually lower and upper bounds
4508 of the range. But in some special cases they mean something else. */
4509 n2 = read_huge_number (pp, ';', &n2bits);
4510 n3 = read_huge_number (pp, ';', &n3bits);
4512 if (n2bits == -1 || n3bits == -1)
4513 return error_type (pp, objfile);
4516 goto handle_true_range;
4518 /* If limits are huge, must be large integral type. */
4519 if (n2bits != 0 || n3bits != 0)
4521 char got_signed = 0;
4522 char got_unsigned = 0;
4523 /* Number of bits in the type. */
4526 /* Range from 0 to <large number> is an unsigned large integral type. */
4527 if ((n2bits == 0 && n2 == 0) && n3bits != 0)
4532 /* Range from <large number> to <large number>-1 is a large signed
4533 integral type. Take care of the case where <large number> doesn't
4534 fit in a long but <large number>-1 does. */
4535 else if ((n2bits != 0 && n3bits != 0 && n2bits == n3bits + 1)
4536 || (n2bits != 0 && n3bits == 0
4537 && (n2bits == sizeof (long) * HOST_CHAR_BIT)
4544 if (got_signed || got_unsigned)
4546 return init_type (TYPE_CODE_INT, nbits / TARGET_CHAR_BIT,
4547 got_unsigned ? TYPE_FLAG_UNSIGNED : 0, NULL,
4551 return error_type (pp, objfile);
4554 /* A type defined as a subrange of itself, with bounds both 0, is void. */
4555 if (self_subrange && n2 == 0 && n3 == 0)
4556 return init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile);
4558 /* If n3 is zero and n2 is positive, we want a floating type,
4559 and n2 is the width in bytes.
4561 Fortran programs appear to use this for complex types also,
4562 and they give no way to distinguish between double and single-complex!
4564 GDB does not have complex types.
4566 Just return the complex as a float of that size. It won't work right
4567 for the complex values, but at least it makes the file loadable. */
4569 if (n3 == 0 && n2 > 0)
4571 return init_type (TYPE_CODE_FLT, n2, 0, NULL, objfile);
4574 /* If the upper bound is -1, it must really be an unsigned int. */
4576 else if (n2 == 0 && n3 == -1)
4578 /* It is unsigned int or unsigned long. */
4579 /* GCC 2.3.3 uses this for long long too, but that is just a GDB 3.5
4580 compatibility hack. */
4581 return init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
4582 TYPE_FLAG_UNSIGNED, NULL, objfile);
4585 /* Special case: char is defined (Who knows why) as a subrange of
4586 itself with range 0-127. */
4587 else if (self_subrange && n2 == 0 && n3 == 127)
4588 return init_type (TYPE_CODE_INT, 1, 0, NULL, objfile);
4590 else if (current_symbol && SYMBOL_LANGUAGE (current_symbol) == language_chill
4592 goto handle_true_range;
4594 /* We used to do this only for subrange of self or subrange of int. */
4598 /* n3 actually gives the size. */
4599 return init_type (TYPE_CODE_INT, - n3, TYPE_FLAG_UNSIGNED,
4602 return init_type (TYPE_CODE_INT, 1, TYPE_FLAG_UNSIGNED, NULL, objfile);
4604 return init_type (TYPE_CODE_INT, 2, TYPE_FLAG_UNSIGNED, NULL, objfile);
4606 /* -1 is used for the upper bound of (4 byte) "unsigned int" and
4607 "unsigned long", and we already checked for that,
4608 so don't need to test for it here. */
4610 /* I think this is for Convex "long long". Since I don't know whether
4611 Convex sets self_subrange, I also accept that particular size regardless
4612 of self_subrange. */
4613 else if (n3 == 0 && n2 < 0
4615 || n2 == - TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT))
4616 return init_type (TYPE_CODE_INT, - n2, 0, NULL, objfile);
4617 else if (n2 == -n3 -1)
4620 return init_type (TYPE_CODE_INT, 1, 0, NULL, objfile);
4622 return init_type (TYPE_CODE_INT, 2, 0, NULL, objfile);
4623 if (n3 == 0x7fffffff)
4624 return init_type (TYPE_CODE_INT, 4, 0, NULL, objfile);
4627 /* We have a real range type on our hands. Allocate space and
4628 return a real pointer. */
4632 index_type = builtin_type_int;
4634 index_type = *dbx_lookup_type (rangenums);
4635 if (index_type == NULL)
4637 /* Does this actually ever happen? Is that why we are worrying
4638 about dealing with it rather than just calling error_type? */
4640 static struct type *range_type_index;
4642 complain (&range_type_base_complaint, rangenums[1]);
4643 if (range_type_index == NULL)
4645 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
4646 0, "range type index type", NULL);
4647 index_type = range_type_index;
4650 result_type = create_range_type ((struct type *) NULL, index_type, n2, n3);
4651 return (result_type);
4654 /* Read in an argument list. This is a list of types, separated by commas
4655 and terminated with END. Return the list of types read in, or (struct type
4656 **)-1 if there is an error. */
4658 static struct type **
4659 read_args (pp, end, objfile)
4662 struct objfile *objfile;
4664 /* FIXME! Remove this arbitrary limit! */
4665 struct type *types[1024], **rval; /* allow for fns of 1023 parameters */
4671 /* Invalid argument list: no ','. */
4672 return (struct type **)-1;
4674 STABS_CONTINUE (pp, objfile);
4675 types[n++] = read_type (pp, objfile);
4677 (*pp)++; /* get past `end' (the ':' character) */
4681 rval = (struct type **) xmalloc (2 * sizeof (struct type *));
4683 else if (TYPE_CODE (types[n-1]) != TYPE_CODE_VOID)
4685 rval = (struct type **) xmalloc ((n + 1) * sizeof (struct type *));
4686 memset (rval + n, 0, sizeof (struct type *));
4690 rval = (struct type **) xmalloc (n * sizeof (struct type *));
4692 memcpy (rval, types, n * sizeof (struct type *));
4696 /* Common block handling. */
4698 /* List of symbols declared since the last BCOMM. This list is a tail
4699 of local_symbols. When ECOMM is seen, the symbols on the list
4700 are noted so their proper addresses can be filled in later,
4701 using the common block base address gotten from the assembler
4704 static struct pending *common_block;
4705 static int common_block_i;
4707 /* Name of the current common block. We get it from the BCOMM instead of the
4708 ECOMM to match IBM documentation (even though IBM puts the name both places
4709 like everyone else). */
4710 static char *common_block_name;
4712 /* Process a N_BCOMM symbol. The storage for NAME is not guaranteed
4713 to remain after this function returns. */
4716 common_block_start (name, objfile)
4718 struct objfile *objfile;
4720 if (common_block_name != NULL)
4722 static struct complaint msg = {
4723 "Invalid symbol data: common block within common block",
4727 common_block = local_symbols;
4728 common_block_i = local_symbols ? local_symbols->nsyms : 0;
4729 common_block_name = obsavestring (name, strlen (name),
4730 &objfile -> symbol_obstack);
4733 /* Process a N_ECOMM symbol. */
4736 common_block_end (objfile)
4737 struct objfile *objfile;
4739 /* Symbols declared since the BCOMM are to have the common block
4740 start address added in when we know it. common_block and
4741 common_block_i point to the first symbol after the BCOMM in
4742 the local_symbols list; copy the list and hang it off the
4743 symbol for the common block name for later fixup. */
4746 struct pending *new = 0;
4747 struct pending *next;
4750 if (common_block_name == NULL)
4752 static struct complaint msg = {"ECOMM symbol unmatched by BCOMM", 0, 0};
4757 sym = (struct symbol *)
4758 obstack_alloc (&objfile -> symbol_obstack, sizeof (struct symbol));
4759 memset (sym, 0, sizeof (struct symbol));
4760 /* Note: common_block_name already saved on symbol_obstack */
4761 SYMBOL_NAME (sym) = common_block_name;
4762 SYMBOL_CLASS (sym) = LOC_BLOCK;
4764 /* Now we copy all the symbols which have been defined since the BCOMM. */
4766 /* Copy all the struct pendings before common_block. */
4767 for (next = local_symbols;
4768 next != NULL && next != common_block;
4771 for (j = 0; j < next->nsyms; j++)
4772 add_symbol_to_list (next->symbol[j], &new);
4775 /* Copy however much of COMMON_BLOCK we need. If COMMON_BLOCK is
4776 NULL, it means copy all the local symbols (which we already did
4779 if (common_block != NULL)
4780 for (j = common_block_i; j < common_block->nsyms; j++)
4781 add_symbol_to_list (common_block->symbol[j], &new);
4783 SYMBOL_TYPE (sym) = (struct type *) new;
4785 /* Should we be putting local_symbols back to what it was?
4788 i = hashname (SYMBOL_NAME (sym));
4789 SYMBOL_VALUE_CHAIN (sym) = global_sym_chain[i];
4790 global_sym_chain[i] = sym;
4791 common_block_name = NULL;
4794 /* Add a common block's start address to the offset of each symbol
4795 declared to be in it (by being between a BCOMM/ECOMM pair that uses
4796 the common block name). */
4799 fix_common_block (sym, valu)
4803 struct pending *next = (struct pending *) SYMBOL_TYPE (sym);
4804 for ( ; next; next = next->next)
4807 for (j = next->nsyms - 1; j >= 0; j--)
4808 SYMBOL_VALUE_ADDRESS (next->symbol[j]) += valu;
4814 /* What about types defined as forward references inside of a small lexical
4816 /* Add a type to the list of undefined types to be checked through
4817 once this file has been read in. */
4820 add_undefined_type (type)
4823 if (undef_types_length == undef_types_allocated)
4825 undef_types_allocated *= 2;
4826 undef_types = (struct type **)
4827 xrealloc ((char *) undef_types,
4828 undef_types_allocated * sizeof (struct type *));
4830 undef_types[undef_types_length++] = type;
4833 /* Go through each undefined type, see if it's still undefined, and fix it
4834 up if possible. We have two kinds of undefined types:
4836 TYPE_CODE_ARRAY: Array whose target type wasn't defined yet.
4837 Fix: update array length using the element bounds
4838 and the target type's length.
4839 TYPE_CODE_STRUCT, TYPE_CODE_UNION: Structure whose fields were not
4840 yet defined at the time a pointer to it was made.
4841 Fix: Do a full lookup on the struct/union tag. */
4843 cleanup_undefined_types ()
4847 for (type = undef_types; type < undef_types + undef_types_length; type++)
4849 switch (TYPE_CODE (*type))
4852 case TYPE_CODE_STRUCT:
4853 case TYPE_CODE_UNION:
4854 case TYPE_CODE_ENUM:
4856 /* Check if it has been defined since. Need to do this here
4857 as well as in check_typedef to deal with the (legitimate in
4858 C though not C++) case of several types with the same name
4859 in different source files. */
4860 if (TYPE_FLAGS (*type) & TYPE_FLAG_STUB)
4862 struct pending *ppt;
4864 /* Name of the type, without "struct" or "union" */
4865 char *typename = TYPE_TAG_NAME (*type);
4867 if (typename == NULL)
4869 static struct complaint msg = {"need a type name", 0, 0};
4873 for (ppt = file_symbols; ppt; ppt = ppt->next)
4875 for (i = 0; i < ppt->nsyms; i++)
4877 struct symbol *sym = ppt->symbol[i];
4879 if (SYMBOL_CLASS (sym) == LOC_TYPEDEF
4880 && SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE
4881 && (TYPE_CODE (SYMBOL_TYPE (sym)) ==
4883 && STREQ (SYMBOL_NAME (sym), typename))
4885 memcpy (*type, SYMBOL_TYPE (sym),
4886 sizeof (struct type));
4896 static struct complaint msg = {"\
4897 GDB internal error. cleanup_undefined_types with bad type %d.", 0, 0};
4898 complain (&msg, TYPE_CODE (*type));
4904 undef_types_length = 0;
4907 /* Scan through all of the global symbols defined in the object file,
4908 assigning values to the debugging symbols that need to be assigned
4909 to. Get these symbols from the minimal symbol table. */
4912 scan_file_globals (objfile)
4913 struct objfile *objfile;
4916 struct minimal_symbol *msymbol;
4917 struct symbol *sym, *prev, *rsym;
4918 struct objfile *resolve_objfile;
4920 /* SVR4 based linkers copy referenced global symbols from shared
4921 libraries to the main executable.
4922 If we are scanning the symbols for a shared library, try to resolve
4923 them from the minimal symbols of the main executable first. */
4925 if (symfile_objfile && objfile != symfile_objfile)
4926 resolve_objfile = symfile_objfile;
4928 resolve_objfile = objfile;
4932 /* Avoid expensive loop through all minimal symbols if there are
4933 no unresolved symbols. */
4934 for (hash = 0; hash < HASHSIZE; hash++)
4936 if (global_sym_chain[hash])
4939 if (hash >= HASHSIZE)
4942 for (msymbol = resolve_objfile -> msymbols;
4943 msymbol && SYMBOL_NAME (msymbol) != NULL;
4948 /* Skip static symbols. */
4949 switch (MSYMBOL_TYPE (msymbol))
4961 /* Get the hash index and check all the symbols
4962 under that hash index. */
4964 hash = hashname (SYMBOL_NAME (msymbol));
4966 for (sym = global_sym_chain[hash]; sym;)
4968 if (SYMBOL_NAME (msymbol)[0] == SYMBOL_NAME (sym)[0] &&
4969 STREQ(SYMBOL_NAME (msymbol) + 1, SYMBOL_NAME (sym) + 1))
4972 struct alias_list *aliases;
4974 /* Splice this symbol out of the hash chain and
4975 assign the value we have to it. */
4978 SYMBOL_VALUE_CHAIN (prev) = SYMBOL_VALUE_CHAIN (sym);
4982 global_sym_chain[hash] = SYMBOL_VALUE_CHAIN (sym);
4985 /* Check to see whether we need to fix up a common block. */
4986 /* Note: this code might be executed several times for
4987 the same symbol if there are multiple references. */
4989 /* If symbol has aliases, do minimal symbol fixups for each.
4990 These live aliases/references weren't added to
4991 global_sym_chain hash but may also need to be fixed up. */
4992 /* FIXME: Maybe should have added aliases to the global chain, resolved symbol name, then treated aliases as normal
4993 symbols? Still, we wouldn't want to add_to_list. */
4994 /* Now do the same for each alias of this symbol */
4996 aliases = SYMBOL_ALIASES (sym);
4999 if (SYMBOL_CLASS (rsym) == LOC_BLOCK)
5001 fix_common_block (rsym,
5002 SYMBOL_VALUE_ADDRESS (msymbol));
5006 SYMBOL_VALUE_ADDRESS (rsym)
5007 = SYMBOL_VALUE_ADDRESS (msymbol);
5009 SYMBOL_SECTION (rsym) = SYMBOL_SECTION (msymbol);
5012 rsym = aliases->sym;
5013 aliases = aliases->next;
5022 sym = SYMBOL_VALUE_CHAIN (prev);
5026 sym = global_sym_chain[hash];
5032 sym = SYMBOL_VALUE_CHAIN (sym);
5036 if (resolve_objfile == objfile)
5038 resolve_objfile = objfile;
5041 /* Change the storage class of any remaining unresolved globals to
5042 LOC_UNRESOLVED and remove them from the chain. */
5043 for (hash = 0; hash < HASHSIZE; hash++)
5045 sym = global_sym_chain[hash];
5049 sym = SYMBOL_VALUE_CHAIN (sym);
5051 /* Change the symbol address from the misleading chain value
5053 SYMBOL_VALUE_ADDRESS (prev) = 0;
5055 /* Complain about unresolved common block symbols. */
5056 if (SYMBOL_CLASS (prev) == LOC_STATIC)
5057 SYMBOL_CLASS (prev) = LOC_UNRESOLVED;
5059 complain (&unresolved_sym_chain_complaint,
5060 objfile -> name, SYMBOL_NAME (prev));
5063 memset (global_sym_chain, 0, sizeof (global_sym_chain));
5066 /* Initialize anything that needs initializing when starting to read
5067 a fresh piece of a symbol file, e.g. reading in the stuff corresponding
5075 /* Initialize anything that needs initializing when a completely new
5076 symbol file is specified (not just adding some symbols from another
5077 file, e.g. a shared library). */
5080 stabsread_new_init ()
5082 /* Empty the hash table of global syms looking for values. */
5083 memset (global_sym_chain, 0, sizeof (global_sym_chain));
5086 /* Initialize anything that needs initializing at the same time as
5087 start_symtab() is called. */
5091 global_stabs = NULL; /* AIX COFF */
5092 /* Leave FILENUM of 0 free for builtin types and this file's types. */
5093 n_this_object_header_files = 1;
5094 type_vector_length = 0;
5095 type_vector = (struct type **) 0;
5097 /* FIXME: If common_block_name is not already NULL, we should complain(). */
5098 common_block_name = NULL;
5103 /* Call after end_symtab() */
5109 free ((char *) type_vector);
5112 type_vector_length = 0;
5113 previous_stab_code = 0;
5117 finish_global_stabs (objfile)
5118 struct objfile *objfile;
5122 patch_block_stabs (global_symbols, global_stabs, objfile);
5123 free ((PTR) global_stabs);
5124 global_stabs = NULL;
5128 /* Initializer for this module */
5131 _initialize_stabsread ()
5133 undef_types_allocated = 20;
5134 undef_types_length = 0;
5135 undef_types = (struct type **)
5136 xmalloc (undef_types_allocated * sizeof (struct type *));