1 /* Support routines for decoding "stabs" debugging information format.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
3 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
4 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
23 /* Support routines for reading and decoding debugging information in
24 the "stabs" format. This format is used with many systems that use
25 the a.out object file format, as well as some systems that use
26 COFF or ELF where the stabs data is placed in a special section.
27 Avoid placing any object file format specific code in this file. */
30 #include "gdb_string.h"
32 #include "gdb_obstack.h"
35 #include "expression.h"
38 #include "aout/stab_gnu.h" /* We always use GNU stabs, not native */
40 #include "aout/aout64.h"
41 #include "gdb-stabs.h"
43 #include "complaints.h"
48 #include "cp-support.h"
52 /* Ask stabsread.h to define the vars it normally declares `extern'. */
55 #include "stabsread.h" /* Our own declarations */
58 extern void _initialize_stabsread (void);
60 /* The routines that read and process a complete stabs for a C struct or
61 C++ class pass lists of data member fields and lists of member function
62 fields in an instance of a field_info structure, as defined below.
63 This is part of some reorganization of low level C++ support and is
64 expected to eventually go away... (FIXME) */
70 struct nextfield *next;
72 /* This is the raw visibility from the stab. It is not checked
73 for being one of the visibilities we recognize, so code which
74 examines this field better be able to deal. */
80 struct next_fnfieldlist
82 struct next_fnfieldlist *next;
83 struct fn_fieldlist fn_fieldlist;
89 read_one_struct_field (struct field_info *, char **, char *,
90 struct type *, struct objfile *);
92 static char *get_substring (char **, int);
94 static struct type *dbx_alloc_type (int[2], struct objfile *);
96 static long read_huge_number (char **, int, int *);
98 static struct type *error_type (char **, struct objfile *);
101 patch_block_stabs (struct pending *, struct pending_stabs *,
104 static void fix_common_block (struct symbol *, int);
106 static int read_type_number (char **, int *);
108 static struct type *read_range_type (char **, int[2], struct objfile *);
110 static struct type *read_sun_builtin_type (char **, int[2], struct objfile *);
112 static struct type *read_sun_floating_type (char **, int[2],
115 static struct type *read_enum_type (char **, struct type *, struct objfile *);
117 static struct type *rs6000_builtin_type (int);
120 read_member_functions (struct field_info *, char **, struct type *,
124 read_struct_fields (struct field_info *, char **, struct type *,
128 read_baseclasses (struct field_info *, char **, struct type *,
132 read_tilde_fields (struct field_info *, char **, struct type *,
135 static int attach_fn_fields_to_type (struct field_info *, struct type *);
137 static int attach_fields_to_type (struct field_info *, struct type *,
140 static struct type *read_struct_type (char **, struct type *,
144 static struct type *read_array_type (char **, struct type *,
147 static struct field *read_args (char **, int, struct objfile *, int *, int *);
150 read_cpp_abbrev (struct field_info *, char **, struct type *,
152 #if 0 /* OBSOLETE CFront */
153 // OBSOLETE /* new functions added for cfront support */
155 // OBSOLETE static int
156 // OBSOLETE copy_cfront_struct_fields (struct field_info *, struct type *,
157 // OBSOLETE struct objfile *);
159 // OBSOLETE static char *get_cfront_method_physname (char *);
161 // OBSOLETE static int
162 // OBSOLETE read_cfront_baseclasses (struct field_info *, char **,
163 // OBSOLETE struct type *, struct objfile *);
165 // OBSOLETE static int
166 // OBSOLETE read_cfront_static_fields (struct field_info *, char **,
167 // OBSOLETE struct type *, struct objfile *);
168 // OBSOLETE static int
169 // OBSOLETE read_cfront_member_functions (struct field_info *, char **,
170 // OBSOLETE struct type *, struct objfile *);
172 // OBSOLETE /* end new functions added for cfront support */
173 #endif /* OBSOLETE CFront */
175 static char *find_name_end (char *name);
177 static void add_live_range (struct objfile *, struct symbol *, CORE_ADDR,
180 static int resolve_live_range (struct objfile *, struct symbol *, char *);
182 static int process_reference (char **string);
184 static CORE_ADDR ref_search_value (int refnum);
186 static int resolve_symbol_reference (struct objfile *, struct symbol *,
189 void stabsread_clear_cache (void);
191 static const char vptr_name[] = "_vptr$";
192 static const char vb_name[] = "_vb$";
194 /* Define this as 1 if a pcc declaration of a char or short argument
195 gives the correct address. Otherwise assume pcc gives the
196 address of the corresponding int, which is not the same on a
197 big-endian machine. */
199 #if !defined (BELIEVE_PCC_PROMOTION)
200 #define BELIEVE_PCC_PROMOTION 0
204 invalid_cpp_abbrev_complaint (const char *arg1)
206 complaint (&symfile_complaints, "invalid C++ abbreviation `%s'", arg1);
210 reg_value_complaint (int arg1, int arg2, const char *arg3)
212 complaint (&symfile_complaints,
213 "register number %d too large (max %d) in symbol %s", arg1, arg2,
218 stabs_general_complaint (const char *arg1)
220 complaint (&symfile_complaints, "%s", arg1);
224 lrs_general_complaint (const char *arg1)
226 complaint (&symfile_complaints, "%s", arg1);
229 /* Make a list of forward references which haven't been defined. */
231 static struct type **undef_types;
232 static int undef_types_allocated;
233 static int undef_types_length;
234 static struct symbol *current_symbol = NULL;
236 /* Check for and handle cretinous stabs symbol name continuation! */
237 #define STABS_CONTINUE(pp,objfile) \
239 if (**(pp) == '\\' || (**(pp) == '?' && (*(pp))[1] == '\0')) \
240 *(pp) = next_symbol_text (objfile); \
244 /* Look up a dbx type-number pair. Return the address of the slot
245 where the type for that number-pair is stored.
246 The number-pair is in TYPENUMS.
248 This can be used for finding the type associated with that pair
249 or for associating a new type with the pair. */
252 dbx_lookup_type (int typenums[2])
254 register int filenum = typenums[0];
255 register int index = typenums[1];
257 register int real_filenum;
258 register struct header_file *f;
261 if (filenum == -1) /* -1,-1 is for temporary types. */
264 if (filenum < 0 || filenum >= n_this_object_header_files)
266 complaint (&symfile_complaints,
267 "Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.",
268 filenum, index, symnum);
276 /* Caller wants address of address of type. We think
277 that negative (rs6k builtin) types will never appear as
278 "lvalues", (nor should they), so we stuff the real type
279 pointer into a temp, and return its address. If referenced,
280 this will do the right thing. */
281 static struct type *temp_type;
283 temp_type = rs6000_builtin_type (index);
287 /* Type is defined outside of header files.
288 Find it in this object file's type vector. */
289 if (index >= type_vector_length)
291 old_len = type_vector_length;
294 type_vector_length = INITIAL_TYPE_VECTOR_LENGTH;
295 type_vector = (struct type **)
296 xmalloc (type_vector_length * sizeof (struct type *));
298 while (index >= type_vector_length)
300 type_vector_length *= 2;
302 type_vector = (struct type **)
303 xrealloc ((char *) type_vector,
304 (type_vector_length * sizeof (struct type *)));
305 memset (&type_vector[old_len], 0,
306 (type_vector_length - old_len) * sizeof (struct type *));
308 return (&type_vector[index]);
312 real_filenum = this_object_header_files[filenum];
314 if (real_filenum >= N_HEADER_FILES (current_objfile))
316 struct type *temp_type;
317 struct type **temp_type_p;
319 warning ("GDB internal error: bad real_filenum");
322 temp_type = init_type (TYPE_CODE_ERROR, 0, 0, NULL, NULL);
323 temp_type_p = (struct type **) xmalloc (sizeof (struct type *));
324 *temp_type_p = temp_type;
328 f = HEADER_FILES (current_objfile) + real_filenum;
330 f_orig_length = f->length;
331 if (index >= f_orig_length)
333 while (index >= f->length)
337 f->vector = (struct type **)
338 xrealloc ((char *) f->vector, f->length * sizeof (struct type *));
339 memset (&f->vector[f_orig_length], 0,
340 (f->length - f_orig_length) * sizeof (struct type *));
342 return (&f->vector[index]);
346 /* Make sure there is a type allocated for type numbers TYPENUMS
347 and return the type object.
348 This can create an empty (zeroed) type object.
349 TYPENUMS may be (-1, -1) to return a new type object that is not
350 put into the type vector, and so may not be referred to by number. */
353 dbx_alloc_type (int typenums[2], struct objfile *objfile)
355 register struct type **type_addr;
357 if (typenums[0] == -1)
359 return (alloc_type (objfile));
362 type_addr = dbx_lookup_type (typenums);
364 /* If we are referring to a type not known at all yet,
365 allocate an empty type for it.
366 We will fill it in later if we find out how. */
369 *type_addr = alloc_type (objfile);
375 /* for all the stabs in a given stab vector, build appropriate types
376 and fix their symbols in given symbol vector. */
379 patch_block_stabs (struct pending *symbols, struct pending_stabs *stabs,
380 struct objfile *objfile)
390 /* for all the stab entries, find their corresponding symbols and
391 patch their types! */
393 for (ii = 0; ii < stabs->count; ++ii)
395 name = stabs->stab[ii];
396 pp = (char *) strchr (name, ':');
400 pp = (char *) strchr (pp, ':');
402 sym = find_symbol_in_list (symbols, name, pp - name);
405 /* FIXME-maybe: it would be nice if we noticed whether
406 the variable was defined *anywhere*, not just whether
407 it is defined in this compilation unit. But neither
408 xlc or GCC seem to need such a definition, and until
409 we do psymtabs (so that the minimal symbols from all
410 compilation units are available now), I'm not sure
411 how to get the information. */
413 /* On xcoff, if a global is defined and never referenced,
414 ld will remove it from the executable. There is then
415 a N_GSYM stab for it, but no regular (C_EXT) symbol. */
416 sym = (struct symbol *)
417 obstack_alloc (&objfile->symbol_obstack,
418 sizeof (struct symbol));
420 memset (sym, 0, sizeof (struct symbol));
421 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
422 SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
424 obsavestring (name, pp - name, &objfile->symbol_obstack);
426 if (*(pp - 1) == 'F' || *(pp - 1) == 'f')
428 /* I don't think the linker does this with functions,
429 so as far as I know this is never executed.
430 But it doesn't hurt to check. */
432 lookup_function_type (read_type (&pp, objfile));
436 SYMBOL_TYPE (sym) = read_type (&pp, objfile);
438 add_symbol_to_list (sym, &global_symbols);
443 if (*(pp - 1) == 'F' || *(pp - 1) == 'f')
446 lookup_function_type (read_type (&pp, objfile));
450 SYMBOL_TYPE (sym) = read_type (&pp, objfile);
458 /* Read a number by which a type is referred to in dbx data,
459 or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
460 Just a single number N is equivalent to (0,N).
461 Return the two numbers by storing them in the vector TYPENUMS.
462 TYPENUMS will then be used as an argument to dbx_lookup_type.
464 Returns 0 for success, -1 for error. */
467 read_type_number (register char **pp, register int *typenums)
473 typenums[0] = read_huge_number (pp, ',', &nbits);
476 typenums[1] = read_huge_number (pp, ')', &nbits);
483 typenums[1] = read_huge_number (pp, 0, &nbits);
491 #define VISIBILITY_PRIVATE '0' /* Stabs character for private field */
492 #define VISIBILITY_PROTECTED '1' /* Stabs character for protected fld */
493 #define VISIBILITY_PUBLIC '2' /* Stabs character for public field */
494 #define VISIBILITY_IGNORE '9' /* Optimized out or zero length */
496 #if 0 /* OBSOLETE CFront */
497 // OBSOLETE #define CFRONT_VISIBILITY_PRIVATE '2' /* Stabs character for private field */
498 // OBSOLETE #define CFRONT_VISIBILITY_PUBLIC '1' /* Stabs character for public field */
500 // OBSOLETE /* This code added to support parsing of ARM/Cfront stabs strings */
502 // OBSOLETE /* Get substring from string up to char c, advance string pointer past
503 // OBSOLETE suibstring. */
505 // OBSOLETE static char *
506 // OBSOLETE get_substring (char **p, int c)
508 // OBSOLETE char *str;
509 // OBSOLETE str = *p;
510 // OBSOLETE *p = strchr (*p, c);
518 // OBSOLETE return str;
521 // OBSOLETE /* Physname gets strcat'd onto sname in order to recreate the mangled
522 // OBSOLETE name (see funtion gdb_mangle_name in gdbtypes.c). For cfront, make
523 // OBSOLETE the physname look like that of g++ - take out the initial mangling
524 // OBSOLETE eg: for sname="a" and fname="foo__1aFPFs_i" return "FPFs_i" */
526 // OBSOLETE static char *
527 // OBSOLETE get_cfront_method_physname (char *fname)
529 // OBSOLETE int len = 0;
530 // OBSOLETE /* FIXME would like to make this generic for g++ too, but
531 // OBSOLETE that is already handled in read_member_funcctions */
532 // OBSOLETE char *p = fname;
534 // OBSOLETE /* search ahead to find the start of the mangled suffix */
535 // OBSOLETE if (*p == '_' && *(p + 1) == '_') /* compiler generated; probably a ctor/dtor */
537 // OBSOLETE while (p && (unsigned) ((p + 1) - fname) < strlen (fname) && *(p + 1) != '_')
538 // OBSOLETE p = strchr (p, '_');
539 // OBSOLETE if (!(p && *p == '_' && *(p + 1) == '_'))
540 // OBSOLETE error ("Invalid mangled function name %s", fname);
541 // OBSOLETE p += 2; /* advance past '__' */
543 // OBSOLETE /* struct name length and name of type should come next; advance past it */
544 // OBSOLETE while (isdigit (*p))
546 // OBSOLETE len = len * 10 + (*p - '0');
549 // OBSOLETE p += len;
551 // OBSOLETE return p;
554 // OBSOLETE static void
555 // OBSOLETE msg_unknown_complaint (const char *arg1)
557 // OBSOLETE complaint (&symfile_complaints, "Unsupported token in stabs string %s", arg1);
560 // OBSOLETE /* Read base classes within cfront class definition.
561 // OBSOLETE eg: A:ZcA;1@Bpub v2@Bvirpri;__ct__1AFv func__1AFv *sfunc__1AFv ;as__1A ;;
562 // OBSOLETE ^^^^^^^^^^^^^^^^^^
564 // OBSOLETE A:ZcA;;foopri__1AFv foopro__1AFv __ct__1AFv __ct__1AFRC1A foopub__1AFv ;;;
568 // OBSOLETE static int
569 // OBSOLETE read_cfront_baseclasses (struct field_info *fip, char **pp, struct type *type,
570 // OBSOLETE struct objfile *objfile)
572 // OBSOLETE int bnum = 0;
575 // OBSOLETE struct nextfield *new;
577 // OBSOLETE if (**pp == ';') /* no base classes; return */
580 // OBSOLETE return 1;
583 // OBSOLETE /* first count base classes so we can allocate space before parsing */
584 // OBSOLETE for (p = *pp; p && *p && *p != ';'; p++)
586 // OBSOLETE if (*p == ' ')
589 // OBSOLETE bnum++; /* add one more for last one */
591 // OBSOLETE /* now parse the base classes until we get to the start of the methods
592 // OBSOLETE (code extracted and munged from read_baseclasses) */
593 // OBSOLETE ALLOCATE_CPLUS_STRUCT_TYPE (type);
594 // OBSOLETE TYPE_N_BASECLASSES (type) = bnum;
596 // OBSOLETE /* allocate space */
598 // OBSOLETE int num_bytes = B_BYTES (TYPE_N_BASECLASSES (type));
599 // OBSOLETE char *pointer;
601 // OBSOLETE pointer = (char *) TYPE_ALLOC (type, num_bytes);
602 // OBSOLETE TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *) pointer;
604 // OBSOLETE B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), TYPE_N_BASECLASSES (type));
606 // OBSOLETE for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
608 // OBSOLETE new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
609 // OBSOLETE make_cleanup (xfree, new);
610 // OBSOLETE memset (new, 0, sizeof (struct nextfield));
611 // OBSOLETE new->next = fip->list;
612 // OBSOLETE fip->list = new;
613 // OBSOLETE FIELD_BITSIZE (new->field) = 0; /* this should be an unpacked field! */
615 // OBSOLETE STABS_CONTINUE (pp, objfile);
617 // OBSOLETE /* virtual? eg: v2@Bvir */
618 // OBSOLETE if (**pp == 'v')
620 // OBSOLETE SET_TYPE_FIELD_VIRTUAL (type, i);
624 // OBSOLETE /* access? eg: 2@Bvir */
625 // OBSOLETE /* Note: protected inheritance not supported in cfront */
626 // OBSOLETE switch (*(*pp)++)
628 // OBSOLETE case CFRONT_VISIBILITY_PRIVATE:
629 // OBSOLETE new->visibility = VISIBILITY_PRIVATE;
631 // OBSOLETE case CFRONT_VISIBILITY_PUBLIC:
632 // OBSOLETE new->visibility = VISIBILITY_PUBLIC;
635 // OBSOLETE /* Bad visibility format. Complain and treat it as
636 // OBSOLETE public. */
638 // OBSOLETE complaint (&symfile_complaints,
639 // OBSOLETE "Unknown visibility `%c' for baseclass",
640 // OBSOLETE new->visibility);
641 // OBSOLETE new->visibility = VISIBILITY_PUBLIC;
645 // OBSOLETE /* "@" comes next - eg: @Bvir */
646 // OBSOLETE if (**pp != '@')
648 // OBSOLETE msg_unknown_complaint (*pp);
649 // OBSOLETE return 1;
654 // OBSOLETE /* Set the bit offset of the portion of the object corresponding
655 // OBSOLETE to this baseclass. Always zero in the absence of
656 // OBSOLETE multiple inheritance. */
657 // OBSOLETE /* Unable to read bit position from stabs;
658 // OBSOLETE Assuming no multiple inheritance for now FIXME! */
659 // OBSOLETE /* We may have read this in the structure definition;
660 // OBSOLETE now we should fixup the members to be the actual base classes */
661 // OBSOLETE FIELD_BITPOS (new->field) = 0;
663 // OBSOLETE /* Get the base class name and type */
665 // OBSOLETE char *bname; /* base class name */
666 // OBSOLETE struct symbol *bsym; /* base class */
667 // OBSOLETE char *p1, *p2;
668 // OBSOLETE p1 = strchr (*pp, ' ');
669 // OBSOLETE p2 = strchr (*pp, ';');
670 // OBSOLETE if (p1 < p2)
671 // OBSOLETE bname = get_substring (pp, ' ');
673 // OBSOLETE bname = get_substring (pp, ';');
674 // OBSOLETE if (!bname || !*bname)
676 // OBSOLETE msg_unknown_complaint (*pp);
677 // OBSOLETE return 1;
679 // OBSOLETE /* FIXME! attach base info to type */
680 // OBSOLETE bsym = lookup_symbol (bname, 0, STRUCT_NAMESPACE, 0, 0); /*demangled_name */
681 // OBSOLETE if (bsym)
683 // OBSOLETE new->field.type = SYMBOL_TYPE (bsym);
684 // OBSOLETE new->field.name = type_name_no_tag (new->field.type);
688 // OBSOLETE complaint (&symfile_complaints, "Unable to find base type for %s",
690 // OBSOLETE return 1;
694 // OBSOLETE /* If more base classes to parse, loop again.
695 // OBSOLETE We ate the last ' ' or ';' in get_substring,
696 // OBSOLETE so on exit we will have skipped the trailing ';' */
697 // OBSOLETE /* if invalid, return 0; add code to detect - FIXME! */
699 // OBSOLETE return 1;
702 // OBSOLETE /* read cfront member functions.
703 // OBSOLETE pp points to string starting with list of functions
704 // OBSOLETE eg: A:ZcA;1@Bpub v2@Bvirpri;__ct__1AFv func__1AFv *sfunc__1AFv ;as__1A ;;
705 // OBSOLETE ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
706 // OBSOLETE A:ZcA;;foopri__1AFv foopro__1AFv __ct__1AFv __ct__1AFRC1A foopub__1AFv ;;;
707 // OBSOLETE ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
710 // OBSOLETE static int
711 // OBSOLETE read_cfront_member_functions (struct field_info *fip, char **pp,
712 // OBSOLETE struct type *type, struct objfile *objfile)
714 // OBSOLETE /* This code extracted from read_member_functions
715 // OBSOLETE so as to do the similar thing for our funcs */
717 // OBSOLETE int nfn_fields = 0;
718 // OBSOLETE int length = 0;
719 // OBSOLETE /* Total number of member functions defined in this class. If the class
720 // OBSOLETE defines two `f' functions, and one `g' function, then this will have
721 // OBSOLETE the value 3. */
722 // OBSOLETE int total_length = 0;
724 // OBSOLETE struct next_fnfield
726 // OBSOLETE struct next_fnfield *next;
727 // OBSOLETE struct fn_field fn_field;
729 // OBSOLETE *sublist;
730 // OBSOLETE struct type *look_ahead_type;
731 // OBSOLETE struct next_fnfieldlist *new_fnlist;
732 // OBSOLETE struct next_fnfield *new_sublist;
733 // OBSOLETE char *main_fn_name;
734 // OBSOLETE char *fname;
735 // OBSOLETE struct symbol *ref_func = 0;
737 // OBSOLETE /* Process each list until we find the end of the member functions.
738 // OBSOLETE eg: p = "__ct__1AFv foo__1AFv ;;;" */
740 // OBSOLETE STABS_CONTINUE (pp, objfile); /* handle \\ */
742 // OBSOLETE while (**pp != ';' && (fname = get_substring (pp, ' '), fname))
744 // OBSOLETE int is_static = 0;
745 // OBSOLETE int sublist_count = 0;
746 // OBSOLETE char *pname;
747 // OBSOLETE if (fname[0] == '*') /* static member */
749 // OBSOLETE is_static = 1;
750 // OBSOLETE sublist_count++;
753 // OBSOLETE ref_func = lookup_symbol (fname, 0, VAR_NAMESPACE, 0, 0); /* demangled name */
754 // OBSOLETE if (!ref_func)
756 // OBSOLETE complaint (&symfile_complaints,
757 // OBSOLETE "Unable to find function symbol for %s", fname);
758 // OBSOLETE continue;
760 // OBSOLETE sublist = NULL;
761 // OBSOLETE look_ahead_type = NULL;
762 // OBSOLETE length = 0;
764 // OBSOLETE new_fnlist = (struct next_fnfieldlist *)
765 // OBSOLETE xmalloc (sizeof (struct next_fnfieldlist));
766 // OBSOLETE make_cleanup (xfree, new_fnlist);
767 // OBSOLETE memset (new_fnlist, 0, sizeof (struct next_fnfieldlist));
769 // OBSOLETE /* The following is code to work around cfront generated stabs.
770 // OBSOLETE The stabs contains full mangled name for each field.
771 // OBSOLETE We try to demangle the name and extract the field name out of it. */
773 // OBSOLETE char *dem, *dem_p, *dem_args;
774 // OBSOLETE int dem_len;
775 // OBSOLETE dem = cplus_demangle (fname, DMGL_ANSI | DMGL_PARAMS);
776 // OBSOLETE if (dem != NULL)
778 // OBSOLETE dem_p = strrchr (dem, ':');
779 // OBSOLETE if (dem_p != 0 && *(dem_p - 1) == ':')
781 // OBSOLETE /* get rid of args */
782 // OBSOLETE dem_args = strchr (dem_p, '(');
783 // OBSOLETE if (dem_args == NULL)
784 // OBSOLETE dem_len = strlen (dem_p);
786 // OBSOLETE dem_len = dem_args - dem_p;
787 // OBSOLETE main_fn_name =
788 // OBSOLETE obsavestring (dem_p, dem_len, &objfile->type_obstack);
792 // OBSOLETE main_fn_name =
793 // OBSOLETE obsavestring (fname, strlen (fname), &objfile->type_obstack);
795 // OBSOLETE } /* end of code for cfront work around */
797 // OBSOLETE new_fnlist->fn_fieldlist.name = main_fn_name;
799 // OBSOLETE /*-------------------------------------------------*/
800 // OBSOLETE /* Set up the sublists
801 // OBSOLETE Sublists are stuff like args, static, visibility, etc.
802 // OBSOLETE so in ARM, we have to set that info some other way.
803 // OBSOLETE Multiple sublists happen if overloading
804 // OBSOLETE eg: foo::26=##1;:;2A.;
805 // OBSOLETE In g++, we'd loop here thru all the sublists... */
807 // OBSOLETE new_sublist =
808 // OBSOLETE (struct next_fnfield *) xmalloc (sizeof (struct next_fnfield));
809 // OBSOLETE make_cleanup (xfree, new_sublist);
810 // OBSOLETE memset (new_sublist, 0, sizeof (struct next_fnfield));
812 // OBSOLETE /* eat 1; from :;2A.; */
813 // OBSOLETE new_sublist->fn_field.type = SYMBOL_TYPE (ref_func); /* normally takes a read_type */
814 // OBSOLETE /* Make this type look like a method stub for gdb */
815 // OBSOLETE TYPE_FLAGS (new_sublist->fn_field.type) |= TYPE_FLAG_STUB;
816 // OBSOLETE TYPE_CODE (new_sublist->fn_field.type) = TYPE_CODE_METHOD;
818 // OBSOLETE /* If this is just a stub, then we don't have the real name here. */
819 // OBSOLETE if (TYPE_STUB (new_sublist->fn_field.type))
821 // OBSOLETE if (!TYPE_DOMAIN_TYPE (new_sublist->fn_field.type))
822 // OBSOLETE TYPE_DOMAIN_TYPE (new_sublist->fn_field.type) = type;
823 // OBSOLETE new_sublist->fn_field.is_stub = 1;
826 // OBSOLETE /* physname used later in mangling; eg PFs_i,5 for foo__1aFPFs_i
827 // OBSOLETE physname gets strcat'd in order to recreate the onto mangled name */
828 // OBSOLETE pname = get_cfront_method_physname (fname);
829 // OBSOLETE new_sublist->fn_field.physname = savestring (pname, strlen (pname));
832 // OBSOLETE /* Set this member function's visibility fields.
833 // OBSOLETE Unable to distinguish access from stabs definition!
834 // OBSOLETE Assuming public for now. FIXME!
835 // OBSOLETE (for private, set new_sublist->fn_field.is_private = 1,
836 // OBSOLETE for public, set new_sublist->fn_field.is_protected = 1) */
838 // OBSOLETE /* Unable to distinguish const/volatile from stabs definition!
839 // OBSOLETE Assuming normal for now. FIXME! */
841 // OBSOLETE new_sublist->fn_field.is_const = 0;
842 // OBSOLETE new_sublist->fn_field.is_volatile = 0; /* volatile not implemented in cfront */
844 // OBSOLETE /* Set virtual/static function info
845 // OBSOLETE How to get vtable offsets ?
846 // OBSOLETE Assuming normal for now FIXME!!
847 // OBSOLETE For vtables, figure out from whence this virtual function came.
848 // OBSOLETE It may belong to virtual function table of
849 // OBSOLETE one of its baseclasses.
851 // OBSOLETE new_sublist -> fn_field.voffset = vtable offset,
852 // OBSOLETE new_sublist -> fn_field.fcontext = look_ahead_type;
853 // OBSOLETE where look_ahead_type is type of baseclass */
854 // OBSOLETE if (is_static)
855 // OBSOLETE new_sublist->fn_field.voffset = VOFFSET_STATIC;
856 // OBSOLETE else /* normal member function. */
857 // OBSOLETE new_sublist->fn_field.voffset = 0;
858 // OBSOLETE new_sublist->fn_field.fcontext = 0;
861 // OBSOLETE /* Prepare new sublist */
862 // OBSOLETE new_sublist->next = sublist;
863 // OBSOLETE sublist = new_sublist;
864 // OBSOLETE length++;
866 // OBSOLETE /* In g++, we loop thu sublists - now we set from functions. */
867 // OBSOLETE new_fnlist->fn_fieldlist.fn_fields = (struct fn_field *)
868 // OBSOLETE obstack_alloc (&objfile->type_obstack,
869 // OBSOLETE sizeof (struct fn_field) * length);
870 // OBSOLETE memset (new_fnlist->fn_fieldlist.fn_fields, 0,
871 // OBSOLETE sizeof (struct fn_field) * length);
872 // OBSOLETE for (i = length; (i--, sublist); sublist = sublist->next)
874 // OBSOLETE new_fnlist->fn_fieldlist.fn_fields[i] = sublist->fn_field;
877 // OBSOLETE new_fnlist->fn_fieldlist.length = length;
878 // OBSOLETE new_fnlist->next = fip->fnlist;
879 // OBSOLETE fip->fnlist = new_fnlist;
880 // OBSOLETE nfn_fields++;
881 // OBSOLETE total_length += length;
882 // OBSOLETE STABS_CONTINUE (pp, objfile); /* handle \\ */
883 // OBSOLETE } /* end of loop */
885 // OBSOLETE if (nfn_fields)
887 // OBSOLETE /* type should already have space */
888 // OBSOLETE TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
889 // OBSOLETE TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * nfn_fields);
890 // OBSOLETE memset (TYPE_FN_FIELDLISTS (type), 0,
891 // OBSOLETE sizeof (struct fn_fieldlist) * nfn_fields);
892 // OBSOLETE TYPE_NFN_FIELDS (type) = nfn_fields;
893 // OBSOLETE TYPE_NFN_FIELDS_TOTAL (type) = total_length;
896 // OBSOLETE /* end of scope for reading member func */
898 // OBSOLETE /* eg: ";;" */
900 // OBSOLETE /* Skip trailing ';' and bump count of number of fields seen */
901 // OBSOLETE if (**pp == ';')
904 // OBSOLETE return 0;
905 // OBSOLETE return 1;
908 // OBSOLETE /* This routine fixes up partial cfront types that were created
909 // OBSOLETE while parsing the stabs. The main need for this function is
910 // OBSOLETE to add information such as methods to classes.
911 // OBSOLETE Examples of "p": "sA;;__ct__1AFv foo__1AFv ;;;" */
913 // OBSOLETE resolve_cfront_continuation (struct objfile *objfile, struct symbol *sym,
916 // OBSOLETE struct symbol *ref_sym = 0;
917 // OBSOLETE char *sname;
918 // OBSOLETE /* snarfed from read_struct_type */
919 // OBSOLETE struct field_info fi;
920 // OBSOLETE struct type *type;
921 // OBSOLETE struct cleanup *back_to;
923 // OBSOLETE /* Need to make sure that fi isn't gunna conflict with struct
924 // OBSOLETE in case struct already had some fnfs */
925 // OBSOLETE fi.list = NULL;
926 // OBSOLETE fi.fnlist = NULL;
927 // OBSOLETE back_to = make_cleanup (null_cleanup, 0);
929 // OBSOLETE /* We only accept structs, classes and unions at the moment.
930 // OBSOLETE Other continuation types include t (typedef), r (long dbl), ...
931 // OBSOLETE We may want to add support for them as well;
932 // OBSOLETE right now they are handled by duplicating the symbol information
933 // OBSOLETE into the type information (see define_symbol) */
934 // OBSOLETE if (*p != 's' /* structs */
935 // OBSOLETE && *p != 'c' /* class */
936 // OBSOLETE && *p != 'u') /* union */
937 // OBSOLETE return 0; /* only handle C++ types */
940 // OBSOLETE /* Get symbol typs name and validate
941 // OBSOLETE eg: p = "A;;__ct__1AFv foo__1AFv ;;;" */
942 // OBSOLETE sname = get_substring (&p, ';');
943 // OBSOLETE if (!sname || strcmp (sname, SYMBOL_NAME (sym)))
944 // OBSOLETE error ("Internal error: base symbol type name does not match\n");
946 // OBSOLETE /* Find symbol's internal gdb reference using demangled_name.
947 // OBSOLETE This is the real sym that we want;
948 // OBSOLETE sym was a temp hack to make debugger happy */
949 // OBSOLETE ref_sym = lookup_symbol (SYMBOL_NAME (sym), 0, STRUCT_NAMESPACE, 0, 0);
950 // OBSOLETE type = SYMBOL_TYPE (ref_sym);
953 // OBSOLETE /* Now read the baseclasses, if any, read the regular C struct or C++
954 // OBSOLETE class member fields, attach the fields to the type, read the C++
955 // OBSOLETE member functions, attach them to the type, and then read any tilde
956 // OBSOLETE field (baseclass specifier for the class holding the main vtable). */
958 // OBSOLETE if (!read_cfront_baseclasses (&fi, &p, type, objfile)
959 // OBSOLETE /* g++ does this next, but cfront already did this:
960 // OBSOLETE || !read_struct_fields (&fi, &p, type, objfile) */
961 // OBSOLETE || !copy_cfront_struct_fields (&fi, type, objfile)
962 // OBSOLETE || !read_cfront_member_functions (&fi, &p, type, objfile)
963 // OBSOLETE || !read_cfront_static_fields (&fi, &p, type, objfile)
964 // OBSOLETE || !attach_fields_to_type (&fi, type, objfile)
965 // OBSOLETE || !attach_fn_fields_to_type (&fi, type)
966 // OBSOLETE /* g++ does this next, but cfront doesn't seem to have this:
967 // OBSOLETE || !read_tilde_fields (&fi, &p, type, objfile) */
970 // OBSOLETE type = error_type (&p, objfile);
973 // OBSOLETE do_cleanups (back_to);
974 // OBSOLETE return 0;
976 // OBSOLETE /* End of code added to support parsing of ARM/Cfront stabs strings */
977 #endif /* OBSOLETE CFront */
979 /* This routine fixes up symbol references/aliases to point to the original
980 symbol definition. Returns 0 on failure, non-zero on success. */
983 resolve_symbol_reference (struct objfile *objfile, struct symbol *sym, char *p)
986 struct symbol *ref_sym = 0;
987 struct alias_list *alias;
989 /* If this is not a symbol reference return now. */
993 /* Use "#<num>" as the name; we'll fix the name later.
994 We stored the original symbol name as "#<id>=<name>"
995 so we can now search for "#<id>" to resolving the reference.
996 We'll fix the names later by removing the "#<id>" or "#<id>=" */
998 /*---------------------------------------------------------*/
999 /* Get the reference id number, and
1000 advance p past the names so we can parse the rest.
1001 eg: id=2 for p : "2=", "2=z:r(0,1)" "2:r(0,1);l(#5,#6),l(#7,#4)" */
1002 /*---------------------------------------------------------*/
1004 /* This gets reference name from string. sym may not have a name. */
1006 /* Get the reference number associated with the reference id in the
1007 gdb stab string. From that reference number, get the main/primary
1008 symbol for this alias. */
1009 refnum = process_reference (&p);
1010 ref_sym = ref_search (refnum);
1013 lrs_general_complaint ("symbol for reference not found");
1017 /* Parse the stab of the referencing symbol
1018 now that we have the referenced symbol.
1019 Add it as a new symbol and a link back to the referenced symbol.
1020 eg: p : "=", "=z:r(0,1)" ":r(0,1);l(#5,#6),l(#7,#4)" */
1023 /* If the stab symbol table and string contain:
1024 RSYM 0 5 00000000 868 #15=z:r(0,1)
1025 LBRAC 0 0 00000000 899 #5=
1026 SLINE 0 16 00000003 923 #6=
1027 Then the same symbols can be later referenced by:
1028 RSYM 0 5 00000000 927 #15:r(0,1);l(#5,#6)
1029 This is used in live range splitting to:
1030 1) specify that a symbol (#15) is actually just a new storage
1031 class for a symbol (#15=z) which was previously defined.
1032 2) specify that the beginning and ending ranges for a symbol
1033 (#15) are the values of the beginning (#5) and ending (#6)
1036 /* Read number as reference id.
1037 eg: p : "=", "=z:r(0,1)" ":r(0,1);l(#5,#6),l(#7,#4)" */
1038 /* FIXME! Might I want to use SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
1039 in case of "l(0,0)"? */
1041 /*--------------------------------------------------*/
1042 /* Add this symbol to the reference list. */
1043 /*--------------------------------------------------*/
1045 alias = (struct alias_list *) obstack_alloc (&objfile->type_obstack,
1046 sizeof (struct alias_list));
1049 lrs_general_complaint ("Unable to allocate alias list memory");
1056 if (!SYMBOL_ALIASES (ref_sym))
1058 SYMBOL_ALIASES (ref_sym) = alias;
1062 struct alias_list *temp;
1064 /* Get to the end of the list. */
1065 for (temp = SYMBOL_ALIASES (ref_sym);
1072 /* Want to fix up name so that other functions (eg. valops)
1073 will correctly print the name.
1074 Don't add_symbol_to_list so that lookup_symbol won't find it.
1075 nope... needed for fixups. */
1076 SYMBOL_NAME (sym) = SYMBOL_NAME (ref_sym);
1082 /* Structure for storing pointers to reference definitions for fast lookup
1083 during "process_later". */
1092 #define MAX_CHUNK_REFS 100
1093 #define REF_CHUNK_SIZE (MAX_CHUNK_REFS * sizeof (struct ref_map))
1094 #define REF_MAP_SIZE(ref_chunk) ((ref_chunk) * REF_CHUNK_SIZE)
1096 static struct ref_map *ref_map;
1098 /* Ptr to free cell in chunk's linked list. */
1099 static int ref_count = 0;
1101 /* Number of chunks malloced. */
1102 static int ref_chunk = 0;
1104 /* This file maintains a cache of stabs aliases found in the symbol
1105 table. If the symbol table changes, this cache must be cleared
1106 or we are left holding onto data in invalid obstacks. */
1108 stabsread_clear_cache (void)
1114 /* Create array of pointers mapping refids to symbols and stab strings.
1115 Add pointers to reference definition symbols and/or their values as we
1116 find them, using their reference numbers as our index.
1117 These will be used later when we resolve references. */
1119 ref_add (int refnum, struct symbol *sym, char *stabs, CORE_ADDR value)
1123 if (refnum >= ref_count)
1124 ref_count = refnum + 1;
1125 if (ref_count > ref_chunk * MAX_CHUNK_REFS)
1127 int new_slots = ref_count - ref_chunk * MAX_CHUNK_REFS;
1128 int new_chunks = new_slots / MAX_CHUNK_REFS + 1;
1129 ref_map = (struct ref_map *)
1130 xrealloc (ref_map, REF_MAP_SIZE (ref_chunk + new_chunks));
1131 memset (ref_map + ref_chunk * MAX_CHUNK_REFS, 0, new_chunks * REF_CHUNK_SIZE);
1132 ref_chunk += new_chunks;
1134 ref_map[refnum].stabs = stabs;
1135 ref_map[refnum].sym = sym;
1136 ref_map[refnum].value = value;
1139 /* Return defined sym for the reference REFNUM. */
1141 ref_search (int refnum)
1143 if (refnum < 0 || refnum > ref_count)
1145 return ref_map[refnum].sym;
1148 /* Return value for the reference REFNUM. */
1151 ref_search_value (int refnum)
1153 if (refnum < 0 || refnum > ref_count)
1155 return ref_map[refnum].value;
1158 /* Parse a reference id in STRING and return the resulting
1159 reference number. Move STRING beyond the reference id. */
1162 process_reference (char **string)
1167 if (**string != '#')
1170 /* Advance beyond the initial '#'. */
1173 /* Read number as reference id. */
1174 while (*p && isdigit (*p))
1176 refnum = refnum * 10 + *p - '0';
1183 /* If STRING defines a reference, store away a pointer to the reference
1184 definition for later use. Return the reference number. */
1187 symbol_reference_defined (char **string)
1192 refnum = process_reference (&p);
1194 /* Defining symbols end in '=' */
1197 /* Symbol is being defined here. */
1203 /* Must be a reference. Either the symbol has already been defined,
1204 or this is a forward reference to it. */
1212 define_symbol (CORE_ADDR valu, char *string, int desc, int type,
1213 struct objfile *objfile)
1215 register struct symbol *sym;
1216 char *p = (char *) find_name_end (string);
1221 /* We would like to eliminate nameless symbols, but keep their types.
1222 E.g. stab entry ":t10=*2" should produce a type 10, which is a pointer
1223 to type 2, but, should not create a symbol to address that type. Since
1224 the symbol will be nameless, there is no way any user can refer to it. */
1228 /* Ignore syms with empty names. */
1232 /* Ignore old-style symbols from cc -go */
1239 p = strchr (p, ':');
1242 /* If a nameless stab entry, all we need is the type, not the symbol.
1243 e.g. ":t10=*2" or a nameless enum like " :T16=ered:0,green:1,blue:2,;" */
1244 nameless = (p == string || ((string[0] == ' ') && (string[1] == ':')));
1246 current_symbol = sym = (struct symbol *)
1247 obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol));
1248 memset (sym, 0, sizeof (struct symbol));
1250 switch (type & N_TYPE)
1253 SYMBOL_SECTION (sym) = SECT_OFF_TEXT (objfile);
1256 SYMBOL_SECTION (sym) = SECT_OFF_DATA (objfile);
1259 SYMBOL_SECTION (sym) = SECT_OFF_BSS (objfile);
1263 if (processing_gcc_compilation)
1265 /* GCC 2.x puts the line number in desc. SunOS apparently puts in the
1266 number of bytes occupied by a type or object, which we ignore. */
1267 SYMBOL_LINE (sym) = desc;
1271 SYMBOL_LINE (sym) = 0; /* unknown */
1274 if (is_cplus_marker (string[0]))
1276 /* Special GNU C++ names. */
1280 SYMBOL_NAME (sym) = obsavestring ("this", strlen ("this"),
1281 &objfile->symbol_obstack);
1284 case 'v': /* $vtbl_ptr_type */
1285 /* Was: SYMBOL_NAME (sym) = "vptr"; */
1289 SYMBOL_NAME (sym) = obsavestring ("eh_throw", strlen ("eh_throw"),
1290 &objfile->symbol_obstack);
1294 /* This was an anonymous type that was never fixed up. */
1297 #ifdef STATIC_TRANSFORM_NAME
1299 /* SunPRO (3.0 at least) static variable encoding. */
1304 complaint (&symfile_complaints, "Unknown C++ symbol name `%s'",
1306 goto normal; /* Do *something* with it */
1309 else if (string[0] == '#')
1311 /* Special GNU C extension for referencing symbols. */
1315 /* If STRING defines a new reference id, then add it to the
1316 reference map. Else it must be referring to a previously
1317 defined symbol, so add it to the alias list of the previously
1320 refnum = symbol_reference_defined (&s);
1322 ref_add (refnum, sym, string, SYMBOL_VALUE (sym));
1323 else if (!resolve_symbol_reference (objfile, sym, string))
1326 /* S..P contains the name of the symbol. We need to store
1327 the correct name into SYMBOL_NAME. */
1333 SYMBOL_NAME (sym) = (char *)
1334 obstack_alloc (&objfile->symbol_obstack, nlen);
1335 strncpy (SYMBOL_NAME (sym), s, nlen);
1336 SYMBOL_NAME (sym)[nlen] = '\0';
1337 SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->symbol_obstack);
1340 /* FIXME! Want SYMBOL_NAME (sym) = 0;
1341 Get error if leave name 0. So give it something. */
1344 SYMBOL_NAME (sym) = (char *)
1345 obstack_alloc (&objfile->symbol_obstack, nlen);
1346 strncpy (SYMBOL_NAME (sym), string, nlen);
1347 SYMBOL_NAME (sym)[nlen] = '\0';
1348 SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->symbol_obstack);
1351 /* Advance STRING beyond the reference id. */
1357 SYMBOL_LANGUAGE (sym) = current_subfile->language;
1358 SYMBOL_NAME (sym) = (char *)
1359 obstack_alloc (&objfile->symbol_obstack, ((p - string) + 1));
1360 /* Open-coded memcpy--saves function call time. */
1361 /* FIXME: Does it really? Try replacing with simple strcpy and
1362 try it on an executable with a large symbol table. */
1363 /* FIXME: considering that gcc can open code memcpy anyway, I
1364 doubt it. xoxorich. */
1366 register char *p1 = string;
1367 register char *p2 = SYMBOL_NAME (sym);
1375 /* If this symbol is from a C++ compilation, then attempt to cache the
1376 demangled form for future reference. This is a typical time versus
1377 space tradeoff, that was decided in favor of time because it sped up
1378 C++ symbol lookups by a factor of about 20. */
1380 SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->symbol_obstack);
1384 /* Determine the type of name being defined. */
1386 /* Getting GDB to correctly skip the symbol on an undefined symbol
1387 descriptor and not ever dump core is a very dodgy proposition if
1388 we do things this way. I say the acorn RISC machine can just
1389 fix their compiler. */
1390 /* The Acorn RISC machine's compiler can put out locals that don't
1391 start with "234=" or "(3,4)=", so assume anything other than the
1392 deftypes we know how to handle is a local. */
1393 if (!strchr ("cfFGpPrStTvVXCR", *p))
1395 if (isdigit (*p) || *p == '(' || *p == '-')
1404 /* c is a special case, not followed by a type-number.
1405 SYMBOL:c=iVALUE for an integer constant symbol.
1406 SYMBOL:c=rVALUE for a floating constant symbol.
1407 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
1408 e.g. "b:c=e6,0" for "const b = blob1"
1409 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
1412 SYMBOL_CLASS (sym) = LOC_CONST;
1413 SYMBOL_TYPE (sym) = error_type (&p, objfile);
1414 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1415 add_symbol_to_list (sym, &file_symbols);
1423 double d = atof (p);
1426 /* FIXME-if-picky-about-floating-accuracy: Should be using
1427 target arithmetic to get the value. real.c in GCC
1428 probably has the necessary code. */
1430 /* FIXME: lookup_fundamental_type is a hack. We should be
1431 creating a type especially for the type of float constants.
1432 Problem is, what type should it be?
1434 Also, what should the name of this type be? Should we
1435 be using 'S' constants (see stabs.texinfo) instead? */
1437 SYMBOL_TYPE (sym) = lookup_fundamental_type (objfile,
1440 obstack_alloc (&objfile->symbol_obstack,
1441 TYPE_LENGTH (SYMBOL_TYPE (sym)));
1442 store_typed_floating (dbl_valu, SYMBOL_TYPE (sym), d);
1443 SYMBOL_VALUE_BYTES (sym) = dbl_valu;
1444 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
1449 /* Defining integer constants this way is kind of silly,
1450 since 'e' constants allows the compiler to give not
1451 only the value, but the type as well. C has at least
1452 int, long, unsigned int, and long long as constant
1453 types; other languages probably should have at least
1454 unsigned as well as signed constants. */
1456 /* We just need one int constant type for all objfiles.
1457 It doesn't depend on languages or anything (arguably its
1458 name should be a language-specific name for a type of
1459 that size, but I'm inclined to say that if the compiler
1460 wants a nice name for the type, it can use 'e'). */
1461 static struct type *int_const_type;
1463 /* Yes, this is as long as a *host* int. That is because we
1465 if (int_const_type == NULL)
1467 init_type (TYPE_CODE_INT,
1468 sizeof (int) * HOST_CHAR_BIT / TARGET_CHAR_BIT, 0,
1470 (struct objfile *) NULL);
1471 SYMBOL_TYPE (sym) = int_const_type;
1472 SYMBOL_VALUE (sym) = atoi (p);
1473 SYMBOL_CLASS (sym) = LOC_CONST;
1477 /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value
1478 can be represented as integral.
1479 e.g. "b:c=e6,0" for "const b = blob1"
1480 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
1482 SYMBOL_CLASS (sym) = LOC_CONST;
1483 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1487 SYMBOL_TYPE (sym) = error_type (&p, objfile);
1492 /* If the value is too big to fit in an int (perhaps because
1493 it is unsigned), or something like that, we silently get
1494 a bogus value. The type and everything else about it is
1495 correct. Ideally, we should be using whatever we have
1496 available for parsing unsigned and long long values,
1498 SYMBOL_VALUE (sym) = atoi (p);
1503 SYMBOL_CLASS (sym) = LOC_CONST;
1504 SYMBOL_TYPE (sym) = error_type (&p, objfile);
1507 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1508 add_symbol_to_list (sym, &file_symbols);
1512 /* The name of a caught exception. */
1513 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1514 SYMBOL_CLASS (sym) = LOC_LABEL;
1515 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1516 SYMBOL_VALUE_ADDRESS (sym) = valu;
1517 add_symbol_to_list (sym, &local_symbols);
1521 /* A static function definition. */
1522 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1523 SYMBOL_CLASS (sym) = LOC_BLOCK;
1524 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1525 add_symbol_to_list (sym, &file_symbols);
1526 /* fall into process_function_types. */
1528 process_function_types:
1529 /* Function result types are described as the result type in stabs.
1530 We need to convert this to the function-returning-type-X type
1531 in GDB. E.g. "int" is converted to "function returning int". */
1532 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_FUNC)
1533 SYMBOL_TYPE (sym) = lookup_function_type (SYMBOL_TYPE (sym));
1535 /* All functions in C++ have prototypes. Stabs does not offer an
1536 explicit way to identify prototyped or unprototyped functions,
1537 but both GCC and Sun CC emit stabs for the "call-as" type rather
1538 than the "declared-as" type for unprototyped functions, so
1539 we treat all functions as if they were prototyped. This is used
1540 primarily for promotion when calling the function from GDB. */
1541 TYPE_FLAGS (SYMBOL_TYPE (sym)) |= TYPE_FLAG_PROTOTYPED;
1543 /* fall into process_prototype_types */
1545 process_prototype_types:
1546 /* Sun acc puts declared types of arguments here. */
1549 struct type *ftype = SYMBOL_TYPE (sym);
1554 /* Obtain a worst case guess for the number of arguments
1555 by counting the semicolons. */
1562 /* Allocate parameter information fields and fill them in. */
1563 TYPE_FIELDS (ftype) = (struct field *)
1564 TYPE_ALLOC (ftype, nsemi * sizeof (struct field));
1569 /* A type number of zero indicates the start of varargs.
1570 FIXME: GDB currently ignores vararg functions. */
1571 if (p[0] == '0' && p[1] == '\0')
1573 ptype = read_type (&p, objfile);
1575 /* The Sun compilers mark integer arguments, which should
1576 be promoted to the width of the calling conventions, with
1577 a type which references itself. This type is turned into
1578 a TYPE_CODE_VOID type by read_type, and we have to turn
1579 it back into builtin_type_int here.
1580 FIXME: Do we need a new builtin_type_promoted_int_arg ? */
1581 if (TYPE_CODE (ptype) == TYPE_CODE_VOID)
1582 ptype = builtin_type_int;
1583 TYPE_FIELD_TYPE (ftype, nparams) = ptype;
1584 TYPE_FIELD_ARTIFICIAL (ftype, nparams++) = 0;
1586 TYPE_NFIELDS (ftype) = nparams;
1587 TYPE_FLAGS (ftype) |= TYPE_FLAG_PROTOTYPED;
1592 /* A global function definition. */
1593 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1594 SYMBOL_CLASS (sym) = LOC_BLOCK;
1595 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1596 add_symbol_to_list (sym, &global_symbols);
1597 goto process_function_types;
1600 /* For a class G (global) symbol, it appears that the
1601 value is not correct. It is necessary to search for the
1602 corresponding linker definition to find the value.
1603 These definitions appear at the end of the namelist. */
1604 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1605 SYMBOL_CLASS (sym) = LOC_STATIC;
1606 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1607 /* Don't add symbol references to global_sym_chain.
1608 Symbol references don't have valid names and wont't match up with
1609 minimal symbols when the global_sym_chain is relocated.
1610 We'll fixup symbol references when we fixup the defining symbol. */
1611 if (SYMBOL_NAME (sym) && SYMBOL_NAME (sym)[0] != '#')
1613 i = hashname (SYMBOL_NAME (sym));
1614 SYMBOL_VALUE_CHAIN (sym) = global_sym_chain[i];
1615 global_sym_chain[i] = sym;
1617 add_symbol_to_list (sym, &global_symbols);
1620 /* This case is faked by a conditional above,
1621 when there is no code letter in the dbx data.
1622 Dbx data never actually contains 'l'. */
1625 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1626 SYMBOL_CLASS (sym) = LOC_LOCAL;
1627 SYMBOL_VALUE (sym) = valu;
1628 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1629 add_symbol_to_list (sym, &local_symbols);
1634 /* pF is a two-letter code that means a function parameter in Fortran.
1635 The type-number specifies the type of the return value.
1636 Translate it into a pointer-to-function type. */
1640 = lookup_pointer_type
1641 (lookup_function_type (read_type (&p, objfile)));
1644 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1646 SYMBOL_CLASS (sym) = LOC_ARG;
1647 SYMBOL_VALUE (sym) = valu;
1648 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1649 add_symbol_to_list (sym, &local_symbols);
1651 if (TARGET_BYTE_ORDER != BFD_ENDIAN_BIG)
1653 /* On little-endian machines, this crud is never necessary,
1654 and, if the extra bytes contain garbage, is harmful. */
1658 /* If it's gcc-compiled, if it says `short', believe it. */
1659 if (processing_gcc_compilation || BELIEVE_PCC_PROMOTION)
1662 if (!BELIEVE_PCC_PROMOTION)
1664 /* This is the signed type which arguments get promoted to. */
1665 static struct type *pcc_promotion_type;
1666 /* This is the unsigned type which arguments get promoted to. */
1667 static struct type *pcc_unsigned_promotion_type;
1669 /* Call it "int" because this is mainly C lossage. */
1670 if (pcc_promotion_type == NULL)
1671 pcc_promotion_type =
1672 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
1675 if (pcc_unsigned_promotion_type == NULL)
1676 pcc_unsigned_promotion_type =
1677 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
1678 TYPE_FLAG_UNSIGNED, "unsigned int", NULL);
1680 if (BELIEVE_PCC_PROMOTION_TYPE)
1682 /* This is defined on machines (e.g. sparc) where we
1683 should believe the type of a PCC 'short' argument,
1684 but shouldn't believe the address (the address is the
1685 address of the corresponding int).
1687 My guess is that this correction, as opposed to
1688 changing the parameter to an 'int' (as done below,
1689 for PCC on most machines), is the right thing to do
1690 on all machines, but I don't want to risk breaking
1691 something that already works. On most PCC machines,
1692 the sparc problem doesn't come up because the calling
1693 function has to zero the top bytes (not knowing
1694 whether the called function wants an int or a short),
1695 so there is little practical difference between an
1696 int and a short (except perhaps what happens when the
1697 GDB user types "print short_arg = 0x10000;").
1699 Hacked for SunOS 4.1 by gnu@cygnus.com. In 4.1, the
1700 compiler actually produces the correct address (we
1701 don't need to fix it up). I made this code adapt so
1702 that it will offset the symbol if it was pointing at
1703 an int-aligned location and not otherwise. This way
1704 you can use the same gdb for 4.0.x and 4.1 systems.
1706 If the parameter is shorter than an int, and is
1707 integral (e.g. char, short, or unsigned equivalent),
1708 and is claimed to be passed on an integer boundary,
1709 don't believe it! Offset the parameter's address to
1710 the tail-end of that integer. */
1712 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) < TYPE_LENGTH (pcc_promotion_type)
1713 && TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_INT
1714 && 0 == SYMBOL_VALUE (sym) % TYPE_LENGTH (pcc_promotion_type))
1716 SYMBOL_VALUE (sym) += TYPE_LENGTH (pcc_promotion_type)
1717 - TYPE_LENGTH (SYMBOL_TYPE (sym));
1723 /* If PCC says a parameter is a short or a char,
1724 it is really an int. */
1725 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) < TYPE_LENGTH (pcc_promotion_type)
1726 && TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_INT)
1729 TYPE_UNSIGNED (SYMBOL_TYPE (sym))
1730 ? pcc_unsigned_promotion_type
1731 : pcc_promotion_type;
1738 /* acc seems to use P to declare the prototypes of functions that
1739 are referenced by this file. gdb is not prepared to deal
1740 with this extra information. FIXME, it ought to. */
1743 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1744 goto process_prototype_types;
1749 /* Parameter which is in a register. */
1750 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1751 SYMBOL_CLASS (sym) = LOC_REGPARM;
1752 SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
1753 if (SYMBOL_VALUE (sym) >= NUM_REGS + NUM_PSEUDO_REGS)
1755 reg_value_complaint (SYMBOL_VALUE (sym),
1756 NUM_REGS + NUM_PSEUDO_REGS,
1757 SYMBOL_SOURCE_NAME (sym));
1758 SYMBOL_VALUE (sym) = SP_REGNUM; /* Known safe, though useless */
1760 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1761 add_symbol_to_list (sym, &local_symbols);
1765 /* Register variable (either global or local). */
1766 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1767 SYMBOL_CLASS (sym) = LOC_REGISTER;
1768 SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
1769 if (SYMBOL_VALUE (sym) >= NUM_REGS + NUM_PSEUDO_REGS)
1771 reg_value_complaint (SYMBOL_VALUE (sym),
1772 NUM_REGS + NUM_PSEUDO_REGS,
1773 SYMBOL_SOURCE_NAME (sym));
1774 SYMBOL_VALUE (sym) = SP_REGNUM; /* Known safe, though useless */
1776 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1777 if (within_function)
1779 /* Sun cc uses a pair of symbols, one 'p' and one 'r' with the same
1780 name to represent an argument passed in a register.
1781 GCC uses 'P' for the same case. So if we find such a symbol pair
1782 we combine it into one 'P' symbol. For Sun cc we need to do this
1783 regardless of REG_STRUCT_HAS_ADDR, because the compiler puts out
1784 the 'p' symbol even if it never saves the argument onto the stack.
1786 On most machines, we want to preserve both symbols, so that
1787 we can still get information about what is going on with the
1788 stack (VAX for computing args_printed, using stack slots instead
1789 of saved registers in backtraces, etc.).
1791 Note that this code illegally combines
1792 main(argc) struct foo argc; { register struct foo argc; }
1793 but this case is considered pathological and causes a warning
1794 from a decent compiler. */
1797 && local_symbols->nsyms > 0
1798 #ifndef USE_REGISTER_NOT_ARG
1799 && REG_STRUCT_HAS_ADDR_P ()
1800 && REG_STRUCT_HAS_ADDR (processing_gcc_compilation,
1802 && (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
1803 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION
1804 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_SET
1805 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_BITSTRING)
1809 struct symbol *prev_sym;
1810 prev_sym = local_symbols->symbol[local_symbols->nsyms - 1];
1811 if ((SYMBOL_CLASS (prev_sym) == LOC_REF_ARG
1812 || SYMBOL_CLASS (prev_sym) == LOC_ARG)
1813 && STREQ (SYMBOL_NAME (prev_sym), SYMBOL_NAME (sym)))
1815 SYMBOL_CLASS (prev_sym) = LOC_REGPARM;
1816 /* Use the type from the LOC_REGISTER; that is the type
1817 that is actually in that register. */
1818 SYMBOL_TYPE (prev_sym) = SYMBOL_TYPE (sym);
1819 SYMBOL_VALUE (prev_sym) = SYMBOL_VALUE (sym);
1824 add_symbol_to_list (sym, &local_symbols);
1827 add_symbol_to_list (sym, &file_symbols);
1831 /* Static symbol at top level of file */
1832 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1833 SYMBOL_CLASS (sym) = LOC_STATIC;
1834 SYMBOL_VALUE_ADDRESS (sym) = valu;
1835 #ifdef STATIC_TRANSFORM_NAME
1836 if (IS_STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym)))
1838 struct minimal_symbol *msym;
1839 msym = lookup_minimal_symbol (SYMBOL_NAME (sym), NULL, objfile);
1842 SYMBOL_NAME (sym) = STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym));
1843 SYMBOL_VALUE_ADDRESS (sym) = SYMBOL_VALUE_ADDRESS (msym);
1847 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1848 add_symbol_to_list (sym, &file_symbols);
1853 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1855 /* For a nameless type, we don't want a create a symbol, thus we
1856 did not use `sym'. Return without further processing. */
1860 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1861 SYMBOL_VALUE (sym) = valu;
1862 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1863 /* C++ vagaries: we may have a type which is derived from
1864 a base type which did not have its name defined when the
1865 derived class was output. We fill in the derived class's
1866 base part member's name here in that case. */
1867 if (TYPE_NAME (SYMBOL_TYPE (sym)) != NULL)
1868 if ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
1869 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION)
1870 && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)))
1873 for (j = TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)) - 1; j >= 0; j--)
1874 if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) == 0)
1875 TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) =
1876 type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym), j));
1879 if (TYPE_NAME (SYMBOL_TYPE (sym)) == NULL)
1881 /* gcc-2.6 or later (when using -fvtable-thunks)
1882 emits a unique named type for a vtable entry.
1883 Some gdb code depends on that specific name. */
1884 extern const char vtbl_ptr_name[];
1886 if ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_PTR
1887 && strcmp (SYMBOL_NAME (sym), vtbl_ptr_name))
1888 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_FUNC)
1890 /* If we are giving a name to a type such as "pointer to
1891 foo" or "function returning foo", we better not set
1892 the TYPE_NAME. If the program contains "typedef char
1893 *caddr_t;", we don't want all variables of type char
1894 * to print as caddr_t. This is not just a
1895 consequence of GDB's type management; PCC and GCC (at
1896 least through version 2.4) both output variables of
1897 either type char * or caddr_t with the type number
1898 defined in the 't' symbol for caddr_t. If a future
1899 compiler cleans this up it GDB is not ready for it
1900 yet, but if it becomes ready we somehow need to
1901 disable this check (without breaking the PCC/GCC2.4
1906 Fortunately, this check seems not to be necessary
1907 for anything except pointers or functions. */
1908 /* ezannoni: 2000-10-26. This seems to apply for
1909 versions of gcc older than 2.8. This was the original
1910 problem: with the following code gdb would tell that
1911 the type for name1 is caddr_t, and func is char()
1912 typedef char *caddr_t;
1924 /* Pascal accepts names for pointer types. */
1925 if (current_subfile->language == language_pascal)
1927 TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_NAME (sym);
1931 TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_NAME (sym);
1934 add_symbol_to_list (sym, &file_symbols);
1938 /* Struct, union, or enum tag. For GNU C++, this can be be followed
1939 by 't' which means we are typedef'ing it as well. */
1940 synonym = *p == 't';
1944 #if 0 /* OBSOLETE CFront */
1945 // OBSOLETE /* The semantics of C++ state that "struct foo { ... }" also defines
1946 // OBSOLETE a typedef for "foo". Unfortunately, cfront never makes the typedef
1947 // OBSOLETE when translating C++ into C. We make the typedef here so that
1948 // OBSOLETE "ptype foo" works as expected for cfront translated code. */
1949 // OBSOLETE else if ((current_subfile->language == language_cplus)
1950 // OBSOLETE || (current_subfile->language == language_objc))
1951 // OBSOLETE synonym = 1;
1952 #endif /* OBSOLETE CFront */
1954 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1956 /* For a nameless type, we don't want a create a symbol, thus we
1957 did not use `sym'. Return without further processing. */
1961 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1962 SYMBOL_VALUE (sym) = valu;
1963 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
1964 if (TYPE_TAG_NAME (SYMBOL_TYPE (sym)) == 0)
1965 TYPE_TAG_NAME (SYMBOL_TYPE (sym))
1966 = obconcat (&objfile->type_obstack, "", "", SYMBOL_NAME (sym));
1967 add_symbol_to_list (sym, &file_symbols);
1971 /* Clone the sym and then modify it. */
1972 register struct symbol *typedef_sym = (struct symbol *)
1973 obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol));
1974 *typedef_sym = *sym;
1975 SYMBOL_CLASS (typedef_sym) = LOC_TYPEDEF;
1976 SYMBOL_VALUE (typedef_sym) = valu;
1977 SYMBOL_NAMESPACE (typedef_sym) = VAR_NAMESPACE;
1978 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
1979 TYPE_NAME (SYMBOL_TYPE (sym))
1980 = obconcat (&objfile->type_obstack, "", "", SYMBOL_NAME (sym));
1981 add_symbol_to_list (typedef_sym, &file_symbols);
1986 /* Static symbol of local scope */
1987 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1988 SYMBOL_CLASS (sym) = LOC_STATIC;
1989 SYMBOL_VALUE_ADDRESS (sym) = valu;
1990 #ifdef STATIC_TRANSFORM_NAME
1991 if (IS_STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym)))
1993 struct minimal_symbol *msym;
1994 msym = lookup_minimal_symbol (SYMBOL_NAME (sym), NULL, objfile);
1997 SYMBOL_NAME (sym) = STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym));
1998 SYMBOL_VALUE_ADDRESS (sym) = SYMBOL_VALUE_ADDRESS (msym);
2002 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2003 add_symbol_to_list (sym, &local_symbols);
2007 /* Reference parameter */
2008 SYMBOL_TYPE (sym) = read_type (&p, objfile);
2009 SYMBOL_CLASS (sym) = LOC_REF_ARG;
2010 SYMBOL_VALUE (sym) = valu;
2011 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2012 add_symbol_to_list (sym, &local_symbols);
2016 /* Reference parameter which is in a register. */
2017 SYMBOL_TYPE (sym) = read_type (&p, objfile);
2018 SYMBOL_CLASS (sym) = LOC_REGPARM_ADDR;
2019 SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
2020 if (SYMBOL_VALUE (sym) >= NUM_REGS + NUM_PSEUDO_REGS)
2022 reg_value_complaint (SYMBOL_VALUE (sym),
2023 NUM_REGS + NUM_PSEUDO_REGS,
2024 SYMBOL_SOURCE_NAME (sym));
2025 SYMBOL_VALUE (sym) = SP_REGNUM; /* Known safe, though useless */
2027 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2028 add_symbol_to_list (sym, &local_symbols);
2032 /* This is used by Sun FORTRAN for "function result value".
2033 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
2034 that Pascal uses it too, but when I tried it Pascal used
2035 "x:3" (local symbol) instead. */
2036 SYMBOL_TYPE (sym) = read_type (&p, objfile);
2037 SYMBOL_CLASS (sym) = LOC_LOCAL;
2038 SYMBOL_VALUE (sym) = valu;
2039 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2040 add_symbol_to_list (sym, &local_symbols);
2042 #if 0 /* OBSOLETE CFront */
2043 // OBSOLETE /* New code added to support cfront stabs strings.
2044 // OBSOLETE Note: case 'P' already handled above */
2045 // OBSOLETE case 'Z':
2046 // OBSOLETE /* Cfront type continuation coming up!
2047 // OBSOLETE Find the original definition and add to it.
2048 // OBSOLETE We'll have to do this for the typedef too,
2049 // OBSOLETE since we cloned the symbol to define a type in read_type.
2050 // OBSOLETE Stabs info examples:
2051 // OBSOLETE __1C :Ztl
2052 // OBSOLETE foo__1CFv :ZtF (first def foo__1CFv:F(0,3);(0,24))
2053 // OBSOLETE C:ZsC;;__ct__1CFv func1__1CFv func2__1CFv ... ;;;
2054 // OBSOLETE where C is the name of the class.
2055 // OBSOLETE Unfortunately, we can't lookup the original symbol yet 'cuz
2056 // OBSOLETE we haven't finished reading all the symbols.
2057 // OBSOLETE Instead, we save it for processing later */
2058 // OBSOLETE process_later (sym, p, resolve_cfront_continuation);
2059 // OBSOLETE SYMBOL_TYPE (sym) = error_type (&p, objfile); /* FIXME! change later */
2060 // OBSOLETE SYMBOL_CLASS (sym) = LOC_CONST;
2061 // OBSOLETE SYMBOL_VALUE (sym) = 0;
2062 // OBSOLETE SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2063 // OBSOLETE /* Don't add to list - we'll delete it later when
2064 // OBSOLETE we add the continuation to the real sym */
2065 // OBSOLETE return sym;
2066 // OBSOLETE /* End of new code added to support cfront stabs strings */
2067 #endif /* OBSOLETE CFront */
2070 SYMBOL_TYPE (sym) = error_type (&p, objfile);
2071 SYMBOL_CLASS (sym) = LOC_CONST;
2072 SYMBOL_VALUE (sym) = 0;
2073 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2074 add_symbol_to_list (sym, &file_symbols);
2078 /* When passing structures to a function, some systems sometimes pass
2079 the address in a register, not the structure itself. */
2081 if (REG_STRUCT_HAS_ADDR_P ()
2082 && REG_STRUCT_HAS_ADDR (processing_gcc_compilation, SYMBOL_TYPE (sym))
2083 && (SYMBOL_CLASS (sym) == LOC_REGPARM || SYMBOL_CLASS (sym) == LOC_ARG))
2085 struct type *symbol_type = check_typedef (SYMBOL_TYPE (sym));
2087 if ((TYPE_CODE (symbol_type) == TYPE_CODE_STRUCT)
2088 || (TYPE_CODE (symbol_type) == TYPE_CODE_UNION)
2089 || (TYPE_CODE (symbol_type) == TYPE_CODE_BITSTRING)
2090 || (TYPE_CODE (symbol_type) == TYPE_CODE_SET))
2092 /* If REG_STRUCT_HAS_ADDR yields non-zero we have to convert
2093 LOC_REGPARM to LOC_REGPARM_ADDR for structures and unions. */
2094 if (SYMBOL_CLASS (sym) == LOC_REGPARM)
2095 SYMBOL_CLASS (sym) = LOC_REGPARM_ADDR;
2096 /* Likewise for converting LOC_ARG to LOC_REF_ARG (for the 7th
2097 and subsequent arguments on the sparc, for example). */
2098 else if (SYMBOL_CLASS (sym) == LOC_ARG)
2099 SYMBOL_CLASS (sym) = LOC_REF_ARG;
2103 /* Is there more to parse? For example LRS/alias information? */
2104 while (*p && *p == ';')
2107 if (*p && p[0] == 'l' && p[1] == '(')
2109 /* GNU extensions for live range splitting may be appended to
2110 the end of the stab string. eg. "l(#1,#2);l(#3,#5)" */
2112 /* Resolve the live range and add it to SYM's live range list. */
2113 if (!resolve_live_range (objfile, sym, p))
2116 /* Find end of live range info. */
2117 p = strchr (p, ')');
2118 if (!*p || *p != ')')
2120 lrs_general_complaint ("live range format not recognized");
2129 /* Add the live range found in P to the symbol SYM in objfile OBJFILE. Returns
2130 non-zero on success, zero otherwise. */
2133 resolve_live_range (struct objfile *objfile, struct symbol *sym, char *p)
2136 CORE_ADDR start, end;
2138 /* Sanity check the beginning of the stabs string. */
2139 if (!*p || *p != 'l')
2141 lrs_general_complaint ("live range string 1");
2146 if (!*p || *p != '(')
2148 lrs_general_complaint ("live range string 2");
2153 /* Get starting value of range and advance P past the reference id.
2155 ?!? In theory, the process_reference should never fail, but we should
2156 catch that case just in case the compiler scrogged the stabs. */
2157 refnum = process_reference (&p);
2158 start = ref_search_value (refnum);
2161 lrs_general_complaint ("Live range symbol not found 1");
2165 if (!*p || *p != ',')
2167 lrs_general_complaint ("live range string 3");
2172 /* Get ending value of range and advance P past the reference id.
2174 ?!? In theory, the process_reference should never fail, but we should
2175 catch that case just in case the compiler scrogged the stabs. */
2176 refnum = process_reference (&p);
2177 end = ref_search_value (refnum);
2180 lrs_general_complaint ("Live range symbol not found 2");
2184 if (!*p || *p != ')')
2186 lrs_general_complaint ("live range string 4");
2190 /* Now that we know the bounds of the range, add it to the
2192 add_live_range (objfile, sym, start, end);
2197 /* Add a new live range defined by START and END to the symbol SYM
2198 in objfile OBJFILE. */
2201 add_live_range (struct objfile *objfile, struct symbol *sym, CORE_ADDR start,
2204 struct range_list *r, *rs;
2208 lrs_general_complaint ("end of live range follows start");
2212 /* Alloc new live range structure. */
2213 r = (struct range_list *)
2214 obstack_alloc (&objfile->type_obstack,
2215 sizeof (struct range_list));
2220 /* Append this range to the symbol's range list. */
2221 if (!SYMBOL_RANGES (sym))
2222 SYMBOL_RANGES (sym) = r;
2225 /* Get the last range for the symbol. */
2226 for (rs = SYMBOL_RANGES (sym); rs->next; rs = rs->next)
2233 /* Skip rest of this symbol and return an error type.
2235 General notes on error recovery: error_type always skips to the
2236 end of the symbol (modulo cretinous dbx symbol name continuation).
2237 Thus code like this:
2239 if (*(*pp)++ != ';')
2240 return error_type (pp, objfile);
2242 is wrong because if *pp starts out pointing at '\0' (typically as the
2243 result of an earlier error), it will be incremented to point to the
2244 start of the next symbol, which might produce strange results, at least
2245 if you run off the end of the string table. Instead use
2248 return error_type (pp, objfile);
2254 foo = error_type (pp, objfile);
2258 And in case it isn't obvious, the point of all this hair is so the compiler
2259 can define new types and new syntaxes, and old versions of the
2260 debugger will be able to read the new symbol tables. */
2262 static struct type *
2263 error_type (char **pp, struct objfile *objfile)
2265 complaint (&symfile_complaints, "couldn't parse type; debugger out of date?");
2268 /* Skip to end of symbol. */
2269 while (**pp != '\0')
2274 /* Check for and handle cretinous dbx symbol name continuation! */
2275 if ((*pp)[-1] == '\\' || (*pp)[-1] == '?')
2277 *pp = next_symbol_text (objfile);
2284 return (builtin_type_error);
2288 /* Read type information or a type definition; return the type. Even
2289 though this routine accepts either type information or a type
2290 definition, the distinction is relevant--some parts of stabsread.c
2291 assume that type information starts with a digit, '-', or '(' in
2292 deciding whether to call read_type. */
2295 read_type (register char **pp, struct objfile *objfile)
2297 register struct type *type = 0;
2300 char type_descriptor;
2302 /* Size in bits of type if specified by a type attribute, or -1 if
2303 there is no size attribute. */
2306 /* Used to distinguish string and bitstring from char-array and set. */
2309 /* Used to distinguish vector from array. */
2312 /* Read type number if present. The type number may be omitted.
2313 for instance in a two-dimensional array declared with type
2314 "ar1;1;10;ar1;1;10;4". */
2315 if ((**pp >= '0' && **pp <= '9')
2319 if (read_type_number (pp, typenums) != 0)
2320 return error_type (pp, objfile);
2322 /* Type is not being defined here. Either it already exists,
2323 or this is a forward reference to it. dbx_alloc_type handles
2326 return dbx_alloc_type (typenums, objfile);
2328 /* Type is being defined here. */
2330 Also skip the type descriptor - we get it below with (*pp)[-1]. */
2335 /* 'typenums=' not present, type is anonymous. Read and return
2336 the definition, but don't put it in the type vector. */
2337 typenums[0] = typenums[1] = -1;
2342 type_descriptor = (*pp)[-1];
2343 switch (type_descriptor)
2347 enum type_code code;
2349 /* Used to index through file_symbols. */
2350 struct pending *ppt;
2353 /* Name including "struct", etc. */
2357 char *from, *to, *p, *q1, *q2;
2359 /* Set the type code according to the following letter. */
2363 code = TYPE_CODE_STRUCT;
2366 code = TYPE_CODE_UNION;
2369 code = TYPE_CODE_ENUM;
2373 /* Complain and keep going, so compilers can invent new
2374 cross-reference types. */
2375 complaint (&symfile_complaints,
2376 "Unrecognized cross-reference type `%c'", (*pp)[0]);
2377 code = TYPE_CODE_STRUCT;
2382 q1 = strchr (*pp, '<');
2383 p = strchr (*pp, ':');
2385 return error_type (pp, objfile);
2386 if (q1 && p > q1 && p[1] == ':')
2388 int nesting_level = 0;
2389 for (q2 = q1; *q2; q2++)
2393 else if (*q2 == '>')
2395 else if (*q2 == ':' && nesting_level == 0)
2400 return error_type (pp, objfile);
2403 (char *) obstack_alloc (&objfile->type_obstack, p - *pp + 1);
2405 /* Copy the name. */
2411 /* Set the pointer ahead of the name which we just read, and
2416 /* Now check to see whether the type has already been
2417 declared. This was written for arrays of cross-referenced
2418 types before we had TYPE_CODE_TARGET_STUBBED, so I'm pretty
2419 sure it is not necessary anymore. But it might be a good
2420 idea, to save a little memory. */
2422 for (ppt = file_symbols; ppt; ppt = ppt->next)
2423 for (i = 0; i < ppt->nsyms; i++)
2425 struct symbol *sym = ppt->symbol[i];
2427 if (SYMBOL_CLASS (sym) == LOC_TYPEDEF
2428 && SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE
2429 && (TYPE_CODE (SYMBOL_TYPE (sym)) == code)
2430 && STREQ (SYMBOL_NAME (sym), type_name))
2432 obstack_free (&objfile->type_obstack, type_name);
2433 type = SYMBOL_TYPE (sym);
2438 /* Didn't find the type to which this refers, so we must
2439 be dealing with a forward reference. Allocate a type
2440 structure for it, and keep track of it so we can
2441 fill in the rest of the fields when we get the full
2443 type = dbx_alloc_type (typenums, objfile);
2444 TYPE_CODE (type) = code;
2445 TYPE_TAG_NAME (type) = type_name;
2446 INIT_CPLUS_SPECIFIC (type);
2447 TYPE_FLAGS (type) |= TYPE_FLAG_STUB;
2449 add_undefined_type (type);
2453 case '-': /* RS/6000 built-in type */
2467 /* We deal with something like t(1,2)=(3,4)=... which
2468 the Lucid compiler and recent gcc versions (post 2.7.3) use. */
2470 /* Allocate and enter the typedef type first.
2471 This handles recursive types. */
2472 type = dbx_alloc_type (typenums, objfile);
2473 TYPE_CODE (type) = TYPE_CODE_TYPEDEF;
2475 struct type *xtype = read_type (pp, objfile);
2478 /* It's being defined as itself. That means it is "void". */
2479 TYPE_CODE (type) = TYPE_CODE_VOID;
2480 TYPE_LENGTH (type) = 1;
2482 else if (type_size >= 0 || is_string)
2484 /* This is the absolute wrong way to construct types. Every
2485 other debug format has found a way around this problem and
2486 the related problems with unnecessarily stubbed types;
2487 someone motivated should attempt to clean up the issue
2488 here as well. Once a type pointed to has been created it
2489 should not be modified.
2491 Well, it's not *absolutely* wrong. Constructing recursive
2492 types (trees, linked lists) necessarily entails modifying
2493 types after creating them. Constructing any loop structure
2494 entails side effects. The Dwarf 2 reader does handle this
2495 more gracefully (it never constructs more than once
2496 instance of a type object, so it doesn't have to copy type
2497 objects wholesale), but it still mutates type objects after
2498 other folks have references to them.
2500 Keep in mind that this circularity/mutation issue shows up
2501 at the source language level, too: C's "incomplete types",
2502 for example. So the proper cleanup, I think, would be to
2503 limit GDB's type smashing to match exactly those required
2504 by the source language. So GDB could have a
2505 "complete_this_type" function, but never create unnecessary
2506 copies of a type otherwise. */
2507 replace_type (type, xtype);
2508 TYPE_NAME (type) = NULL;
2509 TYPE_TAG_NAME (type) = NULL;
2513 TYPE_FLAGS (type) |= TYPE_FLAG_TARGET_STUB;
2514 TYPE_TARGET_TYPE (type) = xtype;
2519 /* In the following types, we must be sure to overwrite any existing
2520 type that the typenums refer to, rather than allocating a new one
2521 and making the typenums point to the new one. This is because there
2522 may already be pointers to the existing type (if it had been
2523 forward-referenced), and we must change it to a pointer, function,
2524 reference, or whatever, *in-place*. */
2526 case '*': /* Pointer to another type */
2527 type1 = read_type (pp, objfile);
2528 type = make_pointer_type (type1, dbx_lookup_type (typenums));
2531 case '&': /* Reference to another type */
2532 type1 = read_type (pp, objfile);
2533 type = make_reference_type (type1, dbx_lookup_type (typenums));
2536 case 'f': /* Function returning another type */
2537 type1 = read_type (pp, objfile);
2538 type = make_function_type (type1, dbx_lookup_type (typenums));
2541 case 'g': /* Prototyped function. (Sun) */
2543 /* Unresolved questions:
2545 - According to Sun's ``STABS Interface Manual'', for 'f'
2546 and 'F' symbol descriptors, a `0' in the argument type list
2547 indicates a varargs function. But it doesn't say how 'g'
2548 type descriptors represent that info. Someone with access
2549 to Sun's toolchain should try it out.
2551 - According to the comment in define_symbol (search for
2552 `process_prototype_types:'), Sun emits integer arguments as
2553 types which ref themselves --- like `void' types. Do we
2554 have to deal with that here, too? Again, someone with
2555 access to Sun's toolchain should try it out and let us
2558 const char *type_start = (*pp) - 1;
2559 struct type *return_type = read_type (pp, objfile);
2560 struct type *func_type
2561 = make_function_type (return_type, dbx_lookup_type (typenums));
2564 struct type_list *next;
2568 while (**pp && **pp != '#')
2570 struct type *arg_type = read_type (pp, objfile);
2571 struct type_list *new = alloca (sizeof (*new));
2572 new->type = arg_type;
2573 new->next = arg_types;
2581 complaint (&symfile_complaints,
2582 "Prototyped function type didn't end arguments with `#':\n%s",
2586 /* If there is just one argument whose type is `void', then
2587 that's just an empty argument list. */
2589 && ! arg_types->next
2590 && TYPE_CODE (arg_types->type) == TYPE_CODE_VOID)
2593 TYPE_FIELDS (func_type)
2594 = (struct field *) TYPE_ALLOC (func_type,
2595 num_args * sizeof (struct field));
2596 memset (TYPE_FIELDS (func_type), 0, num_args * sizeof (struct field));
2599 struct type_list *t;
2601 /* We stuck each argument type onto the front of the list
2602 when we read it, so the list is reversed. Build the
2603 fields array right-to-left. */
2604 for (t = arg_types, i = num_args - 1; t; t = t->next, i--)
2605 TYPE_FIELD_TYPE (func_type, i) = t->type;
2607 TYPE_NFIELDS (func_type) = num_args;
2608 TYPE_FLAGS (func_type) |= TYPE_FLAG_PROTOTYPED;
2614 case 'k': /* Const qualifier on some type (Sun) */
2615 type = read_type (pp, objfile);
2616 type = make_cv_type (1, TYPE_VOLATILE (type), type,
2617 dbx_lookup_type (typenums));
2620 case 'B': /* Volatile qual on some type (Sun) */
2621 type = read_type (pp, objfile);
2622 type = make_cv_type (TYPE_CONST (type), 1, type,
2623 dbx_lookup_type (typenums));
2627 if (isdigit (**pp) || **pp == '(' || **pp == '-')
2628 { /* Member (class & variable) type */
2629 /* FIXME -- we should be doing smash_to_XXX types here. */
2631 struct type *domain = read_type (pp, objfile);
2632 struct type *memtype;
2635 /* Invalid member type data format. */
2636 return error_type (pp, objfile);
2639 memtype = read_type (pp, objfile);
2640 type = dbx_alloc_type (typenums, objfile);
2641 smash_to_member_type (type, domain, memtype);
2644 /* type attribute */
2647 /* Skip to the semicolon. */
2648 while (**pp != ';' && **pp != '\0')
2651 return error_type (pp, objfile);
2653 ++ * pp; /* Skip the semicolon. */
2657 case 's': /* Size attribute */
2658 type_size = atoi (attr + 1);
2663 case 'S': /* String attribute */
2664 /* FIXME: check to see if following type is array? */
2668 case 'V': /* Vector attribute */
2669 /* FIXME: check to see if following type is array? */
2674 /* Ignore unrecognized type attributes, so future compilers
2675 can invent new ones. */
2683 case '#': /* Method (class & fn) type */
2684 if ((*pp)[0] == '#')
2686 /* We'll get the parameter types from the name. */
2687 struct type *return_type;
2690 return_type = read_type (pp, objfile);
2691 if (*(*pp)++ != ';')
2692 complaint (&symfile_complaints,
2693 "invalid (minimal) member type data format at symtab pos %d.",
2695 type = allocate_stub_method (return_type);
2696 if (typenums[0] != -1)
2697 *dbx_lookup_type (typenums) = type;
2701 struct type *domain = read_type (pp, objfile);
2702 struct type *return_type;
2707 /* Invalid member type data format. */
2708 return error_type (pp, objfile);
2712 return_type = read_type (pp, objfile);
2713 args = read_args (pp, ';', objfile, &nargs, &varargs);
2714 type = dbx_alloc_type (typenums, objfile);
2715 smash_to_method_type (type, domain, return_type, args,
2720 case 'r': /* Range type */
2721 type = read_range_type (pp, typenums, objfile);
2722 if (typenums[0] != -1)
2723 *dbx_lookup_type (typenums) = type;
2728 /* Sun ACC builtin int type */
2729 type = read_sun_builtin_type (pp, typenums, objfile);
2730 if (typenums[0] != -1)
2731 *dbx_lookup_type (typenums) = type;
2735 case 'R': /* Sun ACC builtin float type */
2736 type = read_sun_floating_type (pp, typenums, objfile);
2737 if (typenums[0] != -1)
2738 *dbx_lookup_type (typenums) = type;
2741 case 'e': /* Enumeration type */
2742 type = dbx_alloc_type (typenums, objfile);
2743 type = read_enum_type (pp, type, objfile);
2744 if (typenums[0] != -1)
2745 *dbx_lookup_type (typenums) = type;
2748 case 's': /* Struct type */
2749 case 'u': /* Union type */
2751 enum type_code type_code = TYPE_CODE_UNDEF;
2752 type = dbx_alloc_type (typenums, objfile);
2753 switch (type_descriptor)
2756 type_code = TYPE_CODE_STRUCT;
2759 type_code = TYPE_CODE_UNION;
2762 type = read_struct_type (pp, type, type_code, objfile);
2766 case 'a': /* Array type */
2768 return error_type (pp, objfile);
2771 type = dbx_alloc_type (typenums, objfile);
2772 type = read_array_type (pp, type, objfile);
2774 TYPE_CODE (type) = TYPE_CODE_STRING;
2776 TYPE_FLAGS (type) |= TYPE_FLAG_VECTOR;
2779 case 'S': /* Set or bitstring type */
2780 type1 = read_type (pp, objfile);
2781 type = create_set_type ((struct type *) NULL, type1);
2783 TYPE_CODE (type) = TYPE_CODE_BITSTRING;
2784 if (typenums[0] != -1)
2785 *dbx_lookup_type (typenums) = type;
2789 --*pp; /* Go back to the symbol in error */
2790 /* Particularly important if it was \0! */
2791 return error_type (pp, objfile);
2796 warning ("GDB internal error, type is NULL in stabsread.c\n");
2797 return error_type (pp, objfile);
2800 /* Size specified in a type attribute overrides any other size. */
2801 if (type_size != -1)
2802 TYPE_LENGTH (type) = (type_size + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT;
2807 /* RS/6000 xlc/dbx combination uses a set of builtin types, starting from -1.
2808 Return the proper type node for a given builtin type number. */
2810 static struct type *
2811 rs6000_builtin_type (int typenum)
2813 /* We recognize types numbered from -NUMBER_RECOGNIZED to -1. */
2814 #define NUMBER_RECOGNIZED 34
2815 /* This includes an empty slot for type number -0. */
2816 static struct type *negative_types[NUMBER_RECOGNIZED + 1];
2817 struct type *rettype = NULL;
2819 if (typenum >= 0 || typenum < -NUMBER_RECOGNIZED)
2821 complaint (&symfile_complaints, "Unknown builtin type %d", typenum);
2822 return builtin_type_error;
2824 if (negative_types[-typenum] != NULL)
2825 return negative_types[-typenum];
2827 #if TARGET_CHAR_BIT != 8
2828 #error This code wrong for TARGET_CHAR_BIT not 8
2829 /* These definitions all assume that TARGET_CHAR_BIT is 8. I think
2830 that if that ever becomes not true, the correct fix will be to
2831 make the size in the struct type to be in bits, not in units of
2838 /* The size of this and all the other types are fixed, defined
2839 by the debugging format. If there is a type called "int" which
2840 is other than 32 bits, then it should use a new negative type
2841 number (or avoid negative type numbers for that case).
2842 See stabs.texinfo. */
2843 rettype = init_type (TYPE_CODE_INT, 4, 0, "int", NULL);
2846 rettype = init_type (TYPE_CODE_INT, 1, 0, "char", NULL);
2849 rettype = init_type (TYPE_CODE_INT, 2, 0, "short", NULL);
2852 rettype = init_type (TYPE_CODE_INT, 4, 0, "long", NULL);
2855 rettype = init_type (TYPE_CODE_INT, 1, TYPE_FLAG_UNSIGNED,
2856 "unsigned char", NULL);
2859 rettype = init_type (TYPE_CODE_INT, 1, 0, "signed char", NULL);
2862 rettype = init_type (TYPE_CODE_INT, 2, TYPE_FLAG_UNSIGNED,
2863 "unsigned short", NULL);
2866 rettype = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED,
2867 "unsigned int", NULL);
2870 rettype = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED,
2873 rettype = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED,
2874 "unsigned long", NULL);
2877 rettype = init_type (TYPE_CODE_VOID, 1, 0, "void", NULL);
2880 /* IEEE single precision (32 bit). */
2881 rettype = init_type (TYPE_CODE_FLT, 4, 0, "float", NULL);
2884 /* IEEE double precision (64 bit). */
2885 rettype = init_type (TYPE_CODE_FLT, 8, 0, "double", NULL);
2888 /* This is an IEEE double on the RS/6000, and different machines with
2889 different sizes for "long double" should use different negative
2890 type numbers. See stabs.texinfo. */
2891 rettype = init_type (TYPE_CODE_FLT, 8, 0, "long double", NULL);
2894 rettype = init_type (TYPE_CODE_INT, 4, 0, "integer", NULL);
2897 rettype = init_type (TYPE_CODE_BOOL, 4, TYPE_FLAG_UNSIGNED,
2901 rettype = init_type (TYPE_CODE_FLT, 4, 0, "short real", NULL);
2904 rettype = init_type (TYPE_CODE_FLT, 8, 0, "real", NULL);
2907 rettype = init_type (TYPE_CODE_ERROR, 0, 0, "stringptr", NULL);
2910 rettype = init_type (TYPE_CODE_CHAR, 1, TYPE_FLAG_UNSIGNED,
2914 rettype = init_type (TYPE_CODE_BOOL, 1, TYPE_FLAG_UNSIGNED,
2918 rettype = init_type (TYPE_CODE_BOOL, 2, TYPE_FLAG_UNSIGNED,
2922 rettype = init_type (TYPE_CODE_BOOL, 4, TYPE_FLAG_UNSIGNED,
2926 rettype = init_type (TYPE_CODE_BOOL, 4, TYPE_FLAG_UNSIGNED,
2930 /* Complex type consisting of two IEEE single precision values. */
2931 rettype = init_type (TYPE_CODE_COMPLEX, 8, 0, "complex", NULL);
2932 TYPE_TARGET_TYPE (rettype) = init_type (TYPE_CODE_FLT, 4, 0, "float",
2936 /* Complex type consisting of two IEEE double precision values. */
2937 rettype = init_type (TYPE_CODE_COMPLEX, 16, 0, "double complex", NULL);
2938 TYPE_TARGET_TYPE (rettype) = init_type (TYPE_CODE_FLT, 8, 0, "double",
2942 rettype = init_type (TYPE_CODE_INT, 1, 0, "integer*1", NULL);
2945 rettype = init_type (TYPE_CODE_INT, 2, 0, "integer*2", NULL);
2948 rettype = init_type (TYPE_CODE_INT, 4, 0, "integer*4", NULL);
2951 rettype = init_type (TYPE_CODE_CHAR, 2, 0, "wchar", NULL);
2954 rettype = init_type (TYPE_CODE_INT, 8, 0, "long long", NULL);
2957 rettype = init_type (TYPE_CODE_INT, 8, TYPE_FLAG_UNSIGNED,
2958 "unsigned long long", NULL);
2961 rettype = init_type (TYPE_CODE_INT, 8, TYPE_FLAG_UNSIGNED,
2965 rettype = init_type (TYPE_CODE_INT, 8, 0, "integer*8", NULL);
2968 negative_types[-typenum] = rettype;
2972 /* This page contains subroutines of read_type. */
2974 /* Replace *OLD_NAME with the method name portion of PHYSNAME. */
2977 update_method_name_from_physname (char **old_name, char *physname)
2981 method_name = method_name_from_physname (physname);
2983 if (method_name == NULL)
2985 complaint (&symfile_complaints,
2986 "Method has bad physname %s\n", physname);
2990 if (strcmp (*old_name, method_name) != 0)
2993 *old_name = method_name;
2996 xfree (method_name);
2999 /* Read member function stabs info for C++ classes. The form of each member
3002 NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
3004 An example with two member functions is:
3006 afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
3008 For the case of overloaded operators, the format is op$::*.funcs, where
3009 $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
3010 name (such as `+=') and `.' marks the end of the operator name.
3012 Returns 1 for success, 0 for failure. */
3015 read_member_functions (struct field_info *fip, char **pp, struct type *type,
3016 struct objfile *objfile)
3020 /* Total number of member functions defined in this class. If the class
3021 defines two `f' functions, and one `g' function, then this will have
3023 int total_length = 0;
3027 struct next_fnfield *next;
3028 struct fn_field fn_field;
3031 struct type *look_ahead_type;
3032 struct next_fnfieldlist *new_fnlist;
3033 struct next_fnfield *new_sublist;
3037 /* Process each list until we find something that is not a member function
3038 or find the end of the functions. */
3042 /* We should be positioned at the start of the function name.
3043 Scan forward to find the first ':' and if it is not the
3044 first of a "::" delimiter, then this is not a member function. */
3056 look_ahead_type = NULL;
3059 new_fnlist = (struct next_fnfieldlist *)
3060 xmalloc (sizeof (struct next_fnfieldlist));
3061 make_cleanup (xfree, new_fnlist);
3062 memset (new_fnlist, 0, sizeof (struct next_fnfieldlist));
3064 if ((*pp)[0] == 'o' && (*pp)[1] == 'p' && is_cplus_marker ((*pp)[2]))
3066 /* This is a completely wierd case. In order to stuff in the
3067 names that might contain colons (the usual name delimiter),
3068 Mike Tiemann defined a different name format which is
3069 signalled if the identifier is "op$". In that case, the
3070 format is "op$::XXXX." where XXXX is the name. This is
3071 used for names like "+" or "=". YUUUUUUUK! FIXME! */
3072 /* This lets the user type "break operator+".
3073 We could just put in "+" as the name, but that wouldn't
3075 static char opname[32] = "op$";
3076 char *o = opname + 3;
3078 /* Skip past '::'. */
3081 STABS_CONTINUE (pp, objfile);
3087 main_fn_name = savestring (opname, o - opname);
3093 main_fn_name = savestring (*pp, p - *pp);
3094 /* Skip past '::'. */
3097 new_fnlist->fn_fieldlist.name = main_fn_name;
3102 (struct next_fnfield *) xmalloc (sizeof (struct next_fnfield));
3103 make_cleanup (xfree, new_sublist);
3104 memset (new_sublist, 0, sizeof (struct next_fnfield));
3106 /* Check for and handle cretinous dbx symbol name continuation! */
3107 if (look_ahead_type == NULL)
3110 STABS_CONTINUE (pp, objfile);
3112 new_sublist->fn_field.type = read_type (pp, objfile);
3115 /* Invalid symtab info for member function. */
3121 /* g++ version 1 kludge */
3122 new_sublist->fn_field.type = look_ahead_type;
3123 look_ahead_type = NULL;
3133 /* If this is just a stub, then we don't have the real name here. */
3135 if (TYPE_STUB (new_sublist->fn_field.type))
3137 if (!TYPE_DOMAIN_TYPE (new_sublist->fn_field.type))
3138 TYPE_DOMAIN_TYPE (new_sublist->fn_field.type) = type;
3139 new_sublist->fn_field.is_stub = 1;
3141 new_sublist->fn_field.physname = savestring (*pp, p - *pp);
3144 /* Set this member function's visibility fields. */
3147 case VISIBILITY_PRIVATE:
3148 new_sublist->fn_field.is_private = 1;
3150 case VISIBILITY_PROTECTED:
3151 new_sublist->fn_field.is_protected = 1;
3155 STABS_CONTINUE (pp, objfile);
3158 case 'A': /* Normal functions. */
3159 new_sublist->fn_field.is_const = 0;
3160 new_sublist->fn_field.is_volatile = 0;
3163 case 'B': /* `const' member functions. */
3164 new_sublist->fn_field.is_const = 1;
3165 new_sublist->fn_field.is_volatile = 0;
3168 case 'C': /* `volatile' member function. */
3169 new_sublist->fn_field.is_const = 0;
3170 new_sublist->fn_field.is_volatile = 1;
3173 case 'D': /* `const volatile' member function. */
3174 new_sublist->fn_field.is_const = 1;
3175 new_sublist->fn_field.is_volatile = 1;
3178 case '*': /* File compiled with g++ version 1 -- no info */
3183 complaint (&symfile_complaints,
3184 "const/volatile indicator missing, got '%c'", **pp);
3193 /* virtual member function, followed by index.
3194 The sign bit is set to distinguish pointers-to-methods
3195 from virtual function indicies. Since the array is
3196 in words, the quantity must be shifted left by 1
3197 on 16 bit machine, and by 2 on 32 bit machine, forcing
3198 the sign bit out, and usable as a valid index into
3199 the array. Remove the sign bit here. */
3200 new_sublist->fn_field.voffset =
3201 (0x7fffffff & read_huge_number (pp, ';', &nbits)) + 2;
3205 STABS_CONTINUE (pp, objfile);
3206 if (**pp == ';' || **pp == '\0')
3208 /* Must be g++ version 1. */
3209 new_sublist->fn_field.fcontext = 0;
3213 /* Figure out from whence this virtual function came.
3214 It may belong to virtual function table of
3215 one of its baseclasses. */
3216 look_ahead_type = read_type (pp, objfile);
3219 /* g++ version 1 overloaded methods. */
3223 new_sublist->fn_field.fcontext = look_ahead_type;
3232 look_ahead_type = NULL;
3238 /* static member function. */
3240 int slen = strlen (main_fn_name);
3242 new_sublist->fn_field.voffset = VOFFSET_STATIC;
3244 /* For static member functions, we can't tell if they
3245 are stubbed, as they are put out as functions, and not as
3247 GCC v2 emits the fully mangled name if
3248 dbxout.c:flag_minimal_debug is not set, so we have to
3249 detect a fully mangled physname here and set is_stub
3250 accordingly. Fully mangled physnames in v2 start with
3251 the member function name, followed by two underscores.
3252 GCC v3 currently always emits stubbed member functions,
3253 but with fully mangled physnames, which start with _Z. */
3254 if (!(strncmp (new_sublist->fn_field.physname,
3255 main_fn_name, slen) == 0
3256 && new_sublist->fn_field.physname[slen] == '_'
3257 && new_sublist->fn_field.physname[slen + 1] == '_'))
3259 new_sublist->fn_field.is_stub = 1;
3266 complaint (&symfile_complaints,
3267 "member function type missing, got '%c'", (*pp)[-1]);
3268 /* Fall through into normal member function. */
3271 /* normal member function. */
3272 new_sublist->fn_field.voffset = 0;
3273 new_sublist->fn_field.fcontext = 0;
3277 new_sublist->next = sublist;
3278 sublist = new_sublist;
3280 STABS_CONTINUE (pp, objfile);
3282 while (**pp != ';' && **pp != '\0');
3285 STABS_CONTINUE (pp, objfile);
3287 /* Skip GCC 3.X member functions which are duplicates of the callable
3288 constructor/destructor. */
3289 if (strcmp (main_fn_name, "__base_ctor") == 0
3290 || strcmp (main_fn_name, "__base_dtor") == 0
3291 || strcmp (main_fn_name, "__deleting_dtor") == 0)
3293 xfree (main_fn_name);
3298 int has_destructor = 0, has_other = 0;
3300 struct next_fnfield *tmp_sublist;
3302 /* Various versions of GCC emit various mostly-useless
3303 strings in the name field for special member functions.
3305 For stub methods, we need to defer correcting the name
3306 until we are ready to unstub the method, because the current
3307 name string is used by gdb_mangle_name. The only stub methods
3308 of concern here are GNU v2 operators; other methods have their
3309 names correct (see caveat below).
3311 For non-stub methods, in GNU v3, we have a complete physname.
3312 Therefore we can safely correct the name now. This primarily
3313 affects constructors and destructors, whose name will be
3314 __comp_ctor or __comp_dtor instead of Foo or ~Foo. Cast
3315 operators will also have incorrect names; for instance,
3316 "operator int" will be named "operator i" (i.e. the type is
3319 For non-stub methods in GNU v2, we have no easy way to
3320 know if we have a complete physname or not. For most
3321 methods the result depends on the platform (if CPLUS_MARKER
3322 can be `$' or `.', it will use minimal debug information, or
3323 otherwise the full physname will be included).
3325 Rather than dealing with this, we take a different approach.
3326 For v3 mangled names, we can use the full physname; for v2,
3327 we use cplus_demangle_opname (which is actually v2 specific),
3328 because the only interesting names are all operators - once again
3329 barring the caveat below. Skip this process if any method in the
3330 group is a stub, to prevent our fouling up the workings of
3333 The caveat: GCC 2.95.x (and earlier?) put constructors and
3334 destructors in the same method group. We need to split this
3335 into two groups, because they should have different names.
3336 So for each method group we check whether it contains both
3337 routines whose physname appears to be a destructor (the physnames
3338 for and destructors are always provided, due to quirks in v2
3339 mangling) and routines whose physname does not appear to be a
3340 destructor. If so then we break up the list into two halves.
3341 Even if the constructors and destructors aren't in the same group
3342 the destructor will still lack the leading tilde, so that also
3345 So, to summarize what we expect and handle here:
3347 Given Given Real Real Action
3348 method name physname physname method name
3350 __opi [none] __opi__3Foo operator int opname
3352 Foo _._3Foo _._3Foo ~Foo separate and
3354 operator i _ZN3FoocviEv _ZN3FoocviEv operator int demangle
3355 __comp_ctor _ZN3FooC1ERKS_ _ZN3FooC1ERKS_ Foo demangle
3358 tmp_sublist = sublist;
3359 while (tmp_sublist != NULL)
3361 if (tmp_sublist->fn_field.is_stub)
3363 if (tmp_sublist->fn_field.physname[0] == '_'
3364 && tmp_sublist->fn_field.physname[1] == 'Z')
3367 if (is_destructor_name (tmp_sublist->fn_field.physname))
3372 tmp_sublist = tmp_sublist->next;
3375 if (has_destructor && has_other)
3377 struct next_fnfieldlist *destr_fnlist;
3378 struct next_fnfield *last_sublist;
3380 /* Create a new fn_fieldlist for the destructors. */
3382 destr_fnlist = (struct next_fnfieldlist *)
3383 xmalloc (sizeof (struct next_fnfieldlist));
3384 make_cleanup (xfree, destr_fnlist);
3385 memset (destr_fnlist, 0, sizeof (struct next_fnfieldlist));
3386 destr_fnlist->fn_fieldlist.name
3387 = obconcat (&objfile->type_obstack, "", "~",
3388 new_fnlist->fn_fieldlist.name);
3390 destr_fnlist->fn_fieldlist.fn_fields = (struct fn_field *)
3391 obstack_alloc (&objfile->type_obstack,
3392 sizeof (struct fn_field) * has_destructor);
3393 memset (destr_fnlist->fn_fieldlist.fn_fields, 0,
3394 sizeof (struct fn_field) * has_destructor);
3395 tmp_sublist = sublist;
3396 last_sublist = NULL;
3398 while (tmp_sublist != NULL)
3400 if (!is_destructor_name (tmp_sublist->fn_field.physname))
3402 tmp_sublist = tmp_sublist->next;
3406 destr_fnlist->fn_fieldlist.fn_fields[i++]
3407 = tmp_sublist->fn_field;
3409 last_sublist->next = tmp_sublist->next;
3411 sublist = tmp_sublist->next;
3412 last_sublist = tmp_sublist;
3413 tmp_sublist = tmp_sublist->next;
3416 destr_fnlist->fn_fieldlist.length = has_destructor;
3417 destr_fnlist->next = fip->fnlist;
3418 fip->fnlist = destr_fnlist;
3420 total_length += has_destructor;
3421 length -= has_destructor;
3425 /* v3 mangling prevents the use of abbreviated physnames,
3426 so we can do this here. There are stubbed methods in v3
3428 - in -gstabs instead of -gstabs+
3429 - or for static methods, which are output as a function type
3430 instead of a method type. */
3432 update_method_name_from_physname (&new_fnlist->fn_fieldlist.name,
3433 sublist->fn_field.physname);
3435 else if (has_destructor && new_fnlist->fn_fieldlist.name[0] != '~')
3437 new_fnlist->fn_fieldlist.name = concat ("~", main_fn_name, NULL);
3438 xfree (main_fn_name);
3442 char dem_opname[256];
3444 ret = cplus_demangle_opname (new_fnlist->fn_fieldlist.name,
3445 dem_opname, DMGL_ANSI);
3447 ret = cplus_demangle_opname (new_fnlist->fn_fieldlist.name,
3450 new_fnlist->fn_fieldlist.name
3451 = obsavestring (dem_opname, strlen (dem_opname),
3452 &objfile->type_obstack);
3455 new_fnlist->fn_fieldlist.fn_fields = (struct fn_field *)
3456 obstack_alloc (&objfile->type_obstack,
3457 sizeof (struct fn_field) * length);
3458 memset (new_fnlist->fn_fieldlist.fn_fields, 0,
3459 sizeof (struct fn_field) * length);
3460 for (i = length; (i--, sublist); sublist = sublist->next)
3462 new_fnlist->fn_fieldlist.fn_fields[i] = sublist->fn_field;
3465 new_fnlist->fn_fieldlist.length = length;
3466 new_fnlist->next = fip->fnlist;
3467 fip->fnlist = new_fnlist;
3469 total_length += length;
3475 ALLOCATE_CPLUS_STRUCT_TYPE (type);
3476 TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
3477 TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * nfn_fields);
3478 memset (TYPE_FN_FIELDLISTS (type), 0,
3479 sizeof (struct fn_fieldlist) * nfn_fields);
3480 TYPE_NFN_FIELDS (type) = nfn_fields;
3481 TYPE_NFN_FIELDS_TOTAL (type) = total_length;
3487 /* Special GNU C++ name.
3489 Returns 1 for success, 0 for failure. "failure" means that we can't
3490 keep parsing and it's time for error_type(). */
3493 read_cpp_abbrev (struct field_info *fip, char **pp, struct type *type,
3494 struct objfile *objfile)
3499 struct type *context;
3509 /* At this point, *pp points to something like "22:23=*22...",
3510 where the type number before the ':' is the "context" and
3511 everything after is a regular type definition. Lookup the
3512 type, find it's name, and construct the field name. */
3514 context = read_type (pp, objfile);
3518 case 'f': /* $vf -- a virtual function table pointer */
3519 name = type_name_no_tag (context);
3524 fip->list->field.name =
3525 obconcat (&objfile->type_obstack, vptr_name, name, "");
3528 case 'b': /* $vb -- a virtual bsomethingorother */
3529 name = type_name_no_tag (context);
3532 complaint (&symfile_complaints,
3533 "C++ abbreviated type name unknown at symtab pos %d",
3537 fip->list->field.name =
3538 obconcat (&objfile->type_obstack, vb_name, name, "");
3542 invalid_cpp_abbrev_complaint (*pp);
3543 fip->list->field.name =
3544 obconcat (&objfile->type_obstack,
3545 "INVALID_CPLUSPLUS_ABBREV", "", "");
3549 /* At this point, *pp points to the ':'. Skip it and read the
3555 invalid_cpp_abbrev_complaint (*pp);
3558 fip->list->field.type = read_type (pp, objfile);
3560 (*pp)++; /* Skip the comma. */
3566 FIELD_BITPOS (fip->list->field) = read_huge_number (pp, ';', &nbits);
3570 /* This field is unpacked. */
3571 FIELD_BITSIZE (fip->list->field) = 0;
3572 fip->list->visibility = VISIBILITY_PRIVATE;
3576 invalid_cpp_abbrev_complaint (*pp);
3577 /* We have no idea what syntax an unrecognized abbrev would have, so
3578 better return 0. If we returned 1, we would need to at least advance
3579 *pp to avoid an infinite loop. */
3586 read_one_struct_field (struct field_info *fip, char **pp, char *p,
3587 struct type *type, struct objfile *objfile)
3589 #if 0 /* OBSOLETE CFront */
3590 // OBSOLETE /* The following is code to work around cfront generated stabs.
3591 // OBSOLETE The stabs contains full mangled name for each field.
3592 // OBSOLETE We try to demangle the name and extract the field name out of it.
3594 // OBSOLETE if (ARM_DEMANGLING && current_subfile->language == language_cplus)
3596 // OBSOLETE char save_p;
3597 // OBSOLETE char *dem, *dem_p;
3598 // OBSOLETE save_p = *p;
3599 // OBSOLETE *p = '\0';
3600 // OBSOLETE dem = cplus_demangle (*pp, DMGL_ANSI | DMGL_PARAMS);
3601 // OBSOLETE if (dem != NULL)
3603 // OBSOLETE dem_p = strrchr (dem, ':');
3604 // OBSOLETE if (dem_p != 0 && *(dem_p - 1) == ':')
3605 // OBSOLETE dem_p++;
3606 // OBSOLETE FIELD_NAME (fip->list->field) =
3607 // OBSOLETE obsavestring (dem_p, strlen (dem_p), &objfile->type_obstack);
3611 // OBSOLETE FIELD_NAME (fip->list->field) =
3612 // OBSOLETE obsavestring (*pp, p - *pp, &objfile->type_obstack);
3614 // OBSOLETE *p = save_p;
3616 // OBSOLETE /* end of code for cfront work around */
3619 #endif /* OBSOLETE CFront */
3620 fip->list->field.name =
3621 obsavestring (*pp, p - *pp, &objfile->type_obstack);
3624 /* This means we have a visibility for a field coming. */
3628 fip->list->visibility = *(*pp)++;
3632 /* normal dbx-style format, no explicit visibility */
3633 fip->list->visibility = VISIBILITY_PUBLIC;
3636 fip->list->field.type = read_type (pp, objfile);
3641 /* Possible future hook for nested types. */
3644 fip->list->field.bitpos = (long) -2; /* nested type */
3654 /* Static class member. */
3655 SET_FIELD_PHYSNAME (fip->list->field, savestring (*pp, p - *pp));
3659 else if (**pp != ',')
3661 /* Bad structure-type format. */
3662 stabs_general_complaint ("bad structure-type format");
3666 (*pp)++; /* Skip the comma. */
3670 FIELD_BITPOS (fip->list->field) = read_huge_number (pp, ',', &nbits);
3673 stabs_general_complaint ("bad structure-type format");
3676 FIELD_BITSIZE (fip->list->field) = read_huge_number (pp, ';', &nbits);
3679 stabs_general_complaint ("bad structure-type format");
3684 if (FIELD_BITPOS (fip->list->field) == 0
3685 && FIELD_BITSIZE (fip->list->field) == 0)
3687 /* This can happen in two cases: (1) at least for gcc 2.4.5 or so,
3688 it is a field which has been optimized out. The correct stab for
3689 this case is to use VISIBILITY_IGNORE, but that is a recent
3690 invention. (2) It is a 0-size array. For example
3691 union { int num; char str[0]; } foo. Printing "<no value>" for
3692 str in "p foo" is OK, since foo.str (and thus foo.str[3])
3693 will continue to work, and a 0-size array as a whole doesn't
3694 have any contents to print.
3696 I suspect this probably could also happen with gcc -gstabs (not
3697 -gstabs+) for static fields, and perhaps other C++ extensions.
3698 Hopefully few people use -gstabs with gdb, since it is intended
3699 for dbx compatibility. */
3701 /* Ignore this field. */
3702 fip->list->visibility = VISIBILITY_IGNORE;
3706 /* Detect an unpacked field and mark it as such.
3707 dbx gives a bit size for all fields.
3708 Note that forward refs cannot be packed,
3709 and treat enums as if they had the width of ints. */
3711 struct type *field_type = check_typedef (FIELD_TYPE (fip->list->field));
3713 if (TYPE_CODE (field_type) != TYPE_CODE_INT
3714 && TYPE_CODE (field_type) != TYPE_CODE_RANGE
3715 && TYPE_CODE (field_type) != TYPE_CODE_BOOL
3716 && TYPE_CODE (field_type) != TYPE_CODE_ENUM)
3718 FIELD_BITSIZE (fip->list->field) = 0;
3720 if ((FIELD_BITSIZE (fip->list->field)
3721 == TARGET_CHAR_BIT * TYPE_LENGTH (field_type)
3722 || (TYPE_CODE (field_type) == TYPE_CODE_ENUM
3723 && FIELD_BITSIZE (fip->list->field) == TARGET_INT_BIT)
3726 FIELD_BITPOS (fip->list->field) % 8 == 0)
3728 FIELD_BITSIZE (fip->list->field) = 0;
3734 /* Read struct or class data fields. They have the form:
3736 NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
3738 At the end, we see a semicolon instead of a field.
3740 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
3743 The optional VISIBILITY is one of:
3745 '/0' (VISIBILITY_PRIVATE)
3746 '/1' (VISIBILITY_PROTECTED)
3747 '/2' (VISIBILITY_PUBLIC)
3748 '/9' (VISIBILITY_IGNORE)
3750 or nothing, for C style fields with public visibility.
3752 Returns 1 for success, 0 for failure. */
3755 read_struct_fields (struct field_info *fip, char **pp, struct type *type,
3756 struct objfile *objfile)
3759 struct nextfield *new;
3761 /* We better set p right now, in case there are no fields at all... */
3765 /* Read each data member type until we find the terminating ';' at the end of
3766 the data member list, or break for some other reason such as finding the
3767 start of the member function list. */
3768 /* Stab string for structure/union does not end with two ';' in
3769 SUN C compiler 5.3 i.e. F6U2, hence check for end of string. */
3771 while (**pp != ';' && **pp != '\0')
3773 STABS_CONTINUE (pp, objfile);
3774 /* Get space to record the next field's data. */
3775 new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
3776 make_cleanup (xfree, new);
3777 memset (new, 0, sizeof (struct nextfield));
3778 new->next = fip->list;
3781 /* Get the field name. */
3784 /* If is starts with CPLUS_MARKER it is a special abbreviation,
3785 unless the CPLUS_MARKER is followed by an underscore, in
3786 which case it is just the name of an anonymous type, which we
3787 should handle like any other type name. */
3789 if (is_cplus_marker (p[0]) && p[1] != '_')
3791 if (!read_cpp_abbrev (fip, pp, type, objfile))
3796 /* Look for the ':' that separates the field name from the field
3797 values. Data members are delimited by a single ':', while member
3798 functions are delimited by a pair of ':'s. When we hit the member
3799 functions (if any), terminate scan loop and return. */
3801 while (*p != ':' && *p != '\0')
3808 /* Check to see if we have hit the member functions yet. */
3813 read_one_struct_field (fip, pp, p, type, objfile);
3815 if (p[0] == ':' && p[1] == ':')
3817 /* (the deleted) chill the list of fields: the last entry (at
3818 the head) is a partially constructed entry which we now
3820 fip->list = fip->list->next;
3825 /* The stabs for C++ derived classes contain baseclass information which
3826 is marked by a '!' character after the total size. This function is
3827 called when we encounter the baseclass marker, and slurps up all the
3828 baseclass information.
3830 Immediately following the '!' marker is the number of base classes that
3831 the class is derived from, followed by information for each base class.
3832 For each base class, there are two visibility specifiers, a bit offset
3833 to the base class information within the derived class, a reference to
3834 the type for the base class, and a terminating semicolon.
3836 A typical example, with two base classes, would be "!2,020,19;0264,21;".
3838 Baseclass information marker __________________|| | | | | | |
3839 Number of baseclasses __________________________| | | | | | |
3840 Visibility specifiers (2) ________________________| | | | | |
3841 Offset in bits from start of class _________________| | | | |
3842 Type number for base class ___________________________| | | |
3843 Visibility specifiers (2) _______________________________| | |
3844 Offset in bits from start of class ________________________| |
3845 Type number of base class ____________________________________|
3847 Return 1 for success, 0 for (error-type-inducing) failure. */
3853 read_baseclasses (struct field_info *fip, char **pp, struct type *type,
3854 struct objfile *objfile)
3857 struct nextfield *new;
3865 /* Skip the '!' baseclass information marker. */
3869 ALLOCATE_CPLUS_STRUCT_TYPE (type);
3872 TYPE_N_BASECLASSES (type) = read_huge_number (pp, ',', &nbits);
3878 /* Some stupid compilers have trouble with the following, so break
3879 it up into simpler expressions. */
3880 TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *)
3881 TYPE_ALLOC (type, B_BYTES (TYPE_N_BASECLASSES (type)));
3884 int num_bytes = B_BYTES (TYPE_N_BASECLASSES (type));
3887 pointer = (char *) TYPE_ALLOC (type, num_bytes);
3888 TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *) pointer;
3892 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), TYPE_N_BASECLASSES (type));
3894 for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
3896 new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
3897 make_cleanup (xfree, new);
3898 memset (new, 0, sizeof (struct nextfield));
3899 new->next = fip->list;
3901 FIELD_BITSIZE (new->field) = 0; /* this should be an unpacked field! */
3903 STABS_CONTINUE (pp, objfile);
3907 /* Nothing to do. */
3910 SET_TYPE_FIELD_VIRTUAL (type, i);
3913 /* Unknown character. Complain and treat it as non-virtual. */
3915 complaint (&symfile_complaints,
3916 "Unknown virtual character `%c' for baseclass", **pp);
3921 new->visibility = *(*pp)++;
3922 switch (new->visibility)
3924 case VISIBILITY_PRIVATE:
3925 case VISIBILITY_PROTECTED:
3926 case VISIBILITY_PUBLIC:
3929 /* Bad visibility format. Complain and treat it as
3932 complaint (&symfile_complaints,
3933 "Unknown visibility `%c' for baseclass",
3935 new->visibility = VISIBILITY_PUBLIC;
3942 /* The remaining value is the bit offset of the portion of the object
3943 corresponding to this baseclass. Always zero in the absence of
3944 multiple inheritance. */
3946 FIELD_BITPOS (new->field) = read_huge_number (pp, ',', &nbits);
3951 /* The last piece of baseclass information is the type of the
3952 base class. Read it, and remember it's type name as this
3955 new->field.type = read_type (pp, objfile);
3956 new->field.name = type_name_no_tag (new->field.type);
3958 /* skip trailing ';' and bump count of number of fields seen */
3967 /* The tail end of stabs for C++ classes that contain a virtual function
3968 pointer contains a tilde, a %, and a type number.
3969 The type number refers to the base class (possibly this class itself) which
3970 contains the vtable pointer for the current class.
3972 This function is called when we have parsed all the method declarations,
3973 so we can look for the vptr base class info. */
3976 read_tilde_fields (struct field_info *fip, char **pp, struct type *type,
3977 struct objfile *objfile)
3981 STABS_CONTINUE (pp, objfile);
3983 /* If we are positioned at a ';', then skip it. */
3993 if (**pp == '=' || **pp == '+' || **pp == '-')
3995 /* Obsolete flags that used to indicate the presence
3996 of constructors and/or destructors. */
4000 /* Read either a '%' or the final ';'. */
4001 if (*(*pp)++ == '%')
4003 /* The next number is the type number of the base class
4004 (possibly our own class) which supplies the vtable for
4005 this class. Parse it out, and search that class to find
4006 its vtable pointer, and install those into TYPE_VPTR_BASETYPE
4007 and TYPE_VPTR_FIELDNO. */
4012 t = read_type (pp, objfile);
4014 while (*p != '\0' && *p != ';')
4020 /* Premature end of symbol. */
4024 TYPE_VPTR_BASETYPE (type) = t;
4025 if (type == t) /* Our own class provides vtbl ptr */
4027 for (i = TYPE_NFIELDS (t) - 1;
4028 i >= TYPE_N_BASECLASSES (t);
4031 char *name = TYPE_FIELD_NAME (t, i);
4032 if (!strncmp (name, vptr_name, sizeof (vptr_name) - 2)
4033 && is_cplus_marker (name[sizeof (vptr_name) - 2]))
4035 TYPE_VPTR_FIELDNO (type) = i;
4039 /* Virtual function table field not found. */
4040 complaint (&symfile_complaints,
4041 "virtual function table pointer not found when defining class `%s'",
4047 TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t);
4058 attach_fn_fields_to_type (struct field_info *fip, register struct type *type)
4062 for (n = TYPE_NFN_FIELDS (type);
4063 fip->fnlist != NULL;
4064 fip->fnlist = fip->fnlist->next)
4066 --n; /* Circumvent Sun3 compiler bug */
4067 TYPE_FN_FIELDLISTS (type)[n] = fip->fnlist->fn_fieldlist;
4072 #if 0 /* OBSOLETE CFront */
4073 // OBSOLETE /* read cfront class static data.
4074 // OBSOLETE pp points to string starting with the list of static data
4075 // OBSOLETE eg: A:ZcA;1@Bpub v2@Bvirpri;__ct__1AFv func__1AFv *sfunc__1AFv ;as__1A ;;
4076 // OBSOLETE ^^^^^^^^
4078 // OBSOLETE A:ZcA;;foopri__1AFv foopro__1AFv __ct__1AFv __ct__1AFRC1A foopub__1AFv ;;;
4082 // OBSOLETE static int
4083 // OBSOLETE read_cfront_static_fields (struct field_info *fip, char **pp, struct type *type,
4084 // OBSOLETE struct objfile *objfile)
4086 // OBSOLETE struct nextfield *new;
4087 // OBSOLETE struct type *stype;
4088 // OBSOLETE char *sname;
4089 // OBSOLETE struct symbol *ref_static = 0;
4091 // OBSOLETE if (**pp == ';') /* no static data; return */
4093 // OBSOLETE ++(*pp);
4094 // OBSOLETE return 1;
4097 // OBSOLETE /* Process each field in the list until we find the terminating ";" */
4099 // OBSOLETE /* eg: p = "as__1A ;;;" */
4100 // OBSOLETE STABS_CONTINUE (pp, objfile); /* handle \\ */
4101 // OBSOLETE while (**pp != ';' && (sname = get_substring (pp, ' '), sname))
4103 // OBSOLETE ref_static = lookup_symbol (sname, 0, VAR_NAMESPACE, 0, 0); /*demangled_name */
4104 // OBSOLETE if (!ref_static)
4106 // OBSOLETE complaint (&symfile_complaints,
4107 // OBSOLETE "Unable to find symbol for static data field %s", sname);
4108 // OBSOLETE continue;
4110 // OBSOLETE stype = SYMBOL_TYPE (ref_static);
4112 // OBSOLETE /* allocate a new fip */
4113 // OBSOLETE new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
4114 // OBSOLETE make_cleanup (xfree, new);
4115 // OBSOLETE memset (new, 0, sizeof (struct nextfield));
4116 // OBSOLETE new->next = fip->list;
4117 // OBSOLETE fip->list = new;
4119 // OBSOLETE /* set visibility */
4120 // OBSOLETE /* FIXME! no way to tell visibility from stabs??? */
4121 // OBSOLETE new->visibility = VISIBILITY_PUBLIC;
4123 // OBSOLETE /* set field info into fip */
4124 // OBSOLETE fip->list->field.type = stype;
4126 // OBSOLETE /* set bitpos & bitsize */
4127 // OBSOLETE SET_FIELD_PHYSNAME (fip->list->field, savestring (sname, strlen (sname)));
4129 // OBSOLETE /* set name field */
4130 // OBSOLETE /* The following is code to work around cfront generated stabs.
4131 // OBSOLETE The stabs contains full mangled name for each field.
4132 // OBSOLETE We try to demangle the name and extract the field name out of it.
4134 // OBSOLETE if (ARM_DEMANGLING)
4136 // OBSOLETE char *dem, *dem_p;
4137 // OBSOLETE dem = cplus_demangle (sname, DMGL_ANSI | DMGL_PARAMS);
4138 // OBSOLETE if (dem != NULL)
4140 // OBSOLETE dem_p = strrchr (dem, ':');
4141 // OBSOLETE if (dem_p != 0 && *(dem_p - 1) == ':')
4142 // OBSOLETE dem_p++;
4143 // OBSOLETE fip->list->field.name =
4144 // OBSOLETE obsavestring (dem_p, strlen (dem_p), &objfile->type_obstack);
4148 // OBSOLETE fip->list->field.name =
4149 // OBSOLETE obsavestring (sname, strlen (sname), &objfile->type_obstack);
4151 // OBSOLETE } /* end of code for cfront work around */
4152 // OBSOLETE } /* loop again for next static field */
4153 // OBSOLETE return 1;
4156 // OBSOLETE /* Copy structure fields to fip so attach_fields_to_type will work.
4157 // OBSOLETE type has already been created with the initial instance data fields.
4158 // OBSOLETE Now we want to be able to add the other members to the class,
4159 // OBSOLETE so we want to add them back to the fip and reattach them again
4160 // OBSOLETE once we have collected all the class members. */
4162 // OBSOLETE static int
4163 // OBSOLETE copy_cfront_struct_fields (struct field_info *fip, struct type *type,
4164 // OBSOLETE struct objfile *objfile)
4166 // OBSOLETE int nfields = TYPE_NFIELDS (type);
4168 // OBSOLETE struct nextfield *new;
4170 // OBSOLETE /* Copy the fields into the list of fips and reset the types
4171 // OBSOLETE to remove the old fields */
4173 // OBSOLETE for (i = 0; i < nfields; i++)
4175 // OBSOLETE /* allocate a new fip */
4176 // OBSOLETE new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
4177 // OBSOLETE make_cleanup (xfree, new);
4178 // OBSOLETE memset (new, 0, sizeof (struct nextfield));
4179 // OBSOLETE new->next = fip->list;
4180 // OBSOLETE fip->list = new;
4182 // OBSOLETE /* copy field info into fip */
4183 // OBSOLETE new->field = TYPE_FIELD (type, i);
4184 // OBSOLETE /* set visibility */
4185 // OBSOLETE if (TYPE_FIELD_PROTECTED (type, i))
4186 // OBSOLETE new->visibility = VISIBILITY_PROTECTED;
4187 // OBSOLETE else if (TYPE_FIELD_PRIVATE (type, i))
4188 // OBSOLETE new->visibility = VISIBILITY_PRIVATE;
4190 // OBSOLETE new->visibility = VISIBILITY_PUBLIC;
4192 // OBSOLETE /* Now delete the fields from the type since we will be
4193 // OBSOLETE allocing new space once we get the rest of the fields
4194 // OBSOLETE in attach_fields_to_type.
4195 // OBSOLETE The pointer TYPE_FIELDS(type) is left dangling but should
4196 // OBSOLETE be freed later by objstack_free */
4197 // OBSOLETE TYPE_FIELDS (type) = 0;
4198 // OBSOLETE TYPE_NFIELDS (type) = 0;
4200 // OBSOLETE return 1;
4202 #endif /* OBSOLETE CFront */
4204 /* Create the vector of fields, and record how big it is.
4205 We need this info to record proper virtual function table information
4206 for this class's virtual functions. */
4209 attach_fields_to_type (struct field_info *fip, register struct type *type,
4210 struct objfile *objfile)
4212 register int nfields = 0;
4213 register int non_public_fields = 0;
4214 register struct nextfield *scan;
4216 /* Count up the number of fields that we have, as well as taking note of
4217 whether or not there are any non-public fields, which requires us to
4218 allocate and build the private_field_bits and protected_field_bits
4221 for (scan = fip->list; scan != NULL; scan = scan->next)
4224 if (scan->visibility != VISIBILITY_PUBLIC)
4226 non_public_fields++;
4230 /* Now we know how many fields there are, and whether or not there are any
4231 non-public fields. Record the field count, allocate space for the
4232 array of fields, and create blank visibility bitfields if necessary. */
4234 TYPE_NFIELDS (type) = nfields;
4235 TYPE_FIELDS (type) = (struct field *)
4236 TYPE_ALLOC (type, sizeof (struct field) * nfields);
4237 memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields);
4239 if (non_public_fields)
4241 ALLOCATE_CPLUS_STRUCT_TYPE (type);
4243 TYPE_FIELD_PRIVATE_BITS (type) =
4244 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
4245 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
4247 TYPE_FIELD_PROTECTED_BITS (type) =
4248 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
4249 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
4251 TYPE_FIELD_IGNORE_BITS (type) =
4252 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
4253 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields);
4256 /* Copy the saved-up fields into the field vector. Start from the head
4257 of the list, adding to the tail of the field array, so that they end
4258 up in the same order in the array in which they were added to the list. */
4260 while (nfields-- > 0)
4262 TYPE_FIELD (type, nfields) = fip->list->field;
4263 switch (fip->list->visibility)
4265 case VISIBILITY_PRIVATE:
4266 SET_TYPE_FIELD_PRIVATE (type, nfields);
4269 case VISIBILITY_PROTECTED:
4270 SET_TYPE_FIELD_PROTECTED (type, nfields);
4273 case VISIBILITY_IGNORE:
4274 SET_TYPE_FIELD_IGNORE (type, nfields);
4277 case VISIBILITY_PUBLIC:
4281 /* Unknown visibility. Complain and treat it as public. */
4283 complaint (&symfile_complaints, "Unknown visibility `%c' for field",
4284 fip->list->visibility);
4288 fip->list = fip->list->next;
4294 /* Complain that the compiler has emitted more than one definition for the
4295 structure type TYPE. */
4297 complain_about_struct_wipeout (struct type *type)
4302 if (TYPE_TAG_NAME (type))
4304 name = TYPE_TAG_NAME (type);
4305 switch (TYPE_CODE (type))
4307 case TYPE_CODE_STRUCT: kind = "struct "; break;
4308 case TYPE_CODE_UNION: kind = "union "; break;
4309 case TYPE_CODE_ENUM: kind = "enum "; break;
4313 else if (TYPE_NAME (type))
4315 name = TYPE_NAME (type);
4324 complaint (&symfile_complaints,
4325 "struct/union type gets multiply defined: %s%s", kind, name);
4329 /* Read the description of a structure (or union type) and return an object
4330 describing the type.
4332 PP points to a character pointer that points to the next unconsumed token
4333 in the the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
4334 *PP will point to "4a:1,0,32;;".
4336 TYPE points to an incomplete type that needs to be filled in.
4338 OBJFILE points to the current objfile from which the stabs information is
4339 being read. (Note that it is redundant in that TYPE also contains a pointer
4340 to this same objfile, so it might be a good idea to eliminate it. FIXME).
4343 static struct type *
4344 read_struct_type (char **pp, struct type *type, enum type_code type_code,
4345 struct objfile *objfile)
4347 struct cleanup *back_to;
4348 struct field_info fi;
4353 /* When describing struct/union/class types in stabs, G++ always drops
4354 all qualifications from the name. So if you've got:
4355 struct A { ... struct B { ... }; ... };
4356 then G++ will emit stabs for `struct A::B' that call it simply
4357 `struct B'. Obviously, if you've got a real top-level definition for
4358 `struct B', or other nested definitions, this is going to cause
4361 Obviously, GDB can't fix this by itself, but it can at least avoid
4362 scribbling on existing structure type objects when new definitions
4364 if (! (TYPE_CODE (type) == TYPE_CODE_UNDEF
4365 || TYPE_STUB (type)))
4367 complain_about_struct_wipeout (type);
4369 /* It's probably best to return the type unchanged. */
4373 back_to = make_cleanup (null_cleanup, 0);
4375 INIT_CPLUS_SPECIFIC (type);
4376 TYPE_CODE (type) = type_code;
4377 TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
4379 /* First comes the total size in bytes. */
4383 TYPE_LENGTH (type) = read_huge_number (pp, 0, &nbits);
4385 return error_type (pp, objfile);
4388 /* Now read the baseclasses, if any, read the regular C struct or C++
4389 class member fields, attach the fields to the type, read the C++
4390 member functions, attach them to the type, and then read any tilde
4391 field (baseclass specifier for the class holding the main vtable). */
4393 if (!read_baseclasses (&fi, pp, type, objfile)
4394 || !read_struct_fields (&fi, pp, type, objfile)
4395 || !attach_fields_to_type (&fi, type, objfile)
4396 || !read_member_functions (&fi, pp, type, objfile)
4397 || !attach_fn_fields_to_type (&fi, type)
4398 || !read_tilde_fields (&fi, pp, type, objfile))
4400 type = error_type (pp, objfile);
4403 do_cleanups (back_to);
4407 /* Read a definition of an array type,
4408 and create and return a suitable type object.
4409 Also creates a range type which represents the bounds of that
4412 static struct type *
4413 read_array_type (register char **pp, register struct type *type,
4414 struct objfile *objfile)
4416 struct type *index_type, *element_type, *range_type;
4421 /* Format of an array type:
4422 "ar<index type>;lower;upper;<array_contents_type>".
4423 OS9000: "arlower,upper;<array_contents_type>".
4425 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
4426 for these, produce a type like float[][]. */
4429 index_type = read_type (pp, objfile);
4431 /* Improper format of array type decl. */
4432 return error_type (pp, objfile);
4436 if (!(**pp >= '0' && **pp <= '9') && **pp != '-')
4441 lower = read_huge_number (pp, ';', &nbits);
4444 return error_type (pp, objfile);
4446 if (!(**pp >= '0' && **pp <= '9') && **pp != '-')
4451 upper = read_huge_number (pp, ';', &nbits);
4453 return error_type (pp, objfile);
4455 element_type = read_type (pp, objfile);
4464 create_range_type ((struct type *) NULL, index_type, lower, upper);
4465 type = create_array_type (type, element_type, range_type);
4471 /* Read a definition of an enumeration type,
4472 and create and return a suitable type object.
4473 Also defines the symbols that represent the values of the type. */
4475 static struct type *
4476 read_enum_type (register char **pp, register struct type *type,
4477 struct objfile *objfile)
4482 register struct symbol *sym;
4484 struct pending **symlist;
4485 struct pending *osyms, *syms;
4488 int unsigned_enum = 1;
4491 /* FIXME! The stabs produced by Sun CC merrily define things that ought
4492 to be file-scope, between N_FN entries, using N_LSYM. What's a mother
4493 to do? For now, force all enum values to file scope. */
4494 if (within_function)
4495 symlist = &local_symbols;
4498 symlist = &file_symbols;
4500 o_nsyms = osyms ? osyms->nsyms : 0;
4502 /* The aix4 compiler emits an extra field before the enum members;
4503 my guess is it's a type of some sort. Just ignore it. */
4506 /* Skip over the type. */
4510 /* Skip over the colon. */
4514 /* Read the value-names and their values.
4515 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
4516 A semicolon or comma instead of a NAME means the end. */
4517 while (**pp && **pp != ';' && **pp != ',')
4519 STABS_CONTINUE (pp, objfile);
4523 name = obsavestring (*pp, p - *pp, &objfile->symbol_obstack);
4525 n = read_huge_number (pp, ',', &nbits);
4527 return error_type (pp, objfile);
4529 sym = (struct symbol *)
4530 obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol));
4531 memset (sym, 0, sizeof (struct symbol));
4532 SYMBOL_NAME (sym) = name;
4533 SYMBOL_LANGUAGE (sym) = current_subfile->language;
4534 SYMBOL_CLASS (sym) = LOC_CONST;
4535 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
4536 SYMBOL_VALUE (sym) = n;
4539 add_symbol_to_list (sym, symlist);
4544 (*pp)++; /* Skip the semicolon. */
4546 /* Now fill in the fields of the type-structure. */
4548 TYPE_LENGTH (type) = TARGET_INT_BIT / HOST_CHAR_BIT;
4549 TYPE_CODE (type) = TYPE_CODE_ENUM;
4550 TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
4552 TYPE_FLAGS (type) |= TYPE_FLAG_UNSIGNED;
4553 TYPE_NFIELDS (type) = nsyms;
4554 TYPE_FIELDS (type) = (struct field *)
4555 TYPE_ALLOC (type, sizeof (struct field) * nsyms);
4556 memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nsyms);
4558 /* Find the symbols for the values and put them into the type.
4559 The symbols can be found in the symlist that we put them on
4560 to cause them to be defined. osyms contains the old value
4561 of that symlist; everything up to there was defined by us. */
4562 /* Note that we preserve the order of the enum constants, so
4563 that in something like "enum {FOO, LAST_THING=FOO}" we print
4564 FOO, not LAST_THING. */
4566 for (syms = *symlist, n = nsyms - 1; syms; syms = syms->next)
4568 int last = syms == osyms ? o_nsyms : 0;
4569 int j = syms->nsyms;
4570 for (; --j >= last; --n)
4572 struct symbol *xsym = syms->symbol[j];
4573 SYMBOL_TYPE (xsym) = type;
4574 TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym);
4575 TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (xsym);
4576 TYPE_FIELD_BITSIZE (type, n) = 0;
4585 /* Sun's ACC uses a somewhat saner method for specifying the builtin
4586 typedefs in every file (for int, long, etc):
4588 type = b <signed> <width> <format type>; <offset>; <nbits>
4590 optional format type = c or b for char or boolean.
4591 offset = offset from high order bit to start bit of type.
4592 width is # bytes in object of this type, nbits is # bits in type.
4594 The width/offset stuff appears to be for small objects stored in
4595 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
4598 static struct type *
4599 read_sun_builtin_type (char **pp, int typenums[2], struct objfile *objfile)
4604 enum type_code code = TYPE_CODE_INT;
4615 return error_type (pp, objfile);
4619 /* For some odd reason, all forms of char put a c here. This is strange
4620 because no other type has this honor. We can safely ignore this because
4621 we actually determine 'char'acterness by the number of bits specified in
4623 Boolean forms, e.g Fortran logical*X, put a b here. */
4627 else if (**pp == 'b')
4629 code = TYPE_CODE_BOOL;
4633 /* The first number appears to be the number of bytes occupied
4634 by this type, except that unsigned short is 4 instead of 2.
4635 Since this information is redundant with the third number,
4636 we will ignore it. */
4637 read_huge_number (pp, ';', &nbits);
4639 return error_type (pp, objfile);
4641 /* The second number is always 0, so ignore it too. */
4642 read_huge_number (pp, ';', &nbits);
4644 return error_type (pp, objfile);
4646 /* The third number is the number of bits for this type. */
4647 type_bits = read_huge_number (pp, 0, &nbits);
4649 return error_type (pp, objfile);
4650 /* The type *should* end with a semicolon. If it are embedded
4651 in a larger type the semicolon may be the only way to know where
4652 the type ends. If this type is at the end of the stabstring we
4653 can deal with the omitted semicolon (but we don't have to like
4654 it). Don't bother to complain(), Sun's compiler omits the semicolon
4660 return init_type (TYPE_CODE_VOID, 1,
4661 signed_type ? 0 : TYPE_FLAG_UNSIGNED, (char *) NULL,
4664 return init_type (code,
4665 type_bits / TARGET_CHAR_BIT,
4666 signed_type ? 0 : TYPE_FLAG_UNSIGNED, (char *) NULL,
4670 static struct type *
4671 read_sun_floating_type (char **pp, int typenums[2], struct objfile *objfile)
4676 struct type *rettype;
4678 /* The first number has more details about the type, for example
4680 details = read_huge_number (pp, ';', &nbits);
4682 return error_type (pp, objfile);
4684 /* The second number is the number of bytes occupied by this type */
4685 nbytes = read_huge_number (pp, ';', &nbits);
4687 return error_type (pp, objfile);
4689 if (details == NF_COMPLEX || details == NF_COMPLEX16
4690 || details == NF_COMPLEX32)
4692 rettype = init_type (TYPE_CODE_COMPLEX, nbytes, 0, NULL, objfile);
4693 TYPE_TARGET_TYPE (rettype)
4694 = init_type (TYPE_CODE_FLT, nbytes / 2, 0, NULL, objfile);
4698 return init_type (TYPE_CODE_FLT, nbytes, 0, NULL, objfile);
4701 /* Read a number from the string pointed to by *PP.
4702 The value of *PP is advanced over the number.
4703 If END is nonzero, the character that ends the
4704 number must match END, or an error happens;
4705 and that character is skipped if it does match.
4706 If END is zero, *PP is left pointing to that character.
4708 If the number fits in a long, set *BITS to 0 and return the value.
4709 If not, set *BITS to be the number of bits in the number and return 0.
4711 If encounter garbage, set *BITS to -1 and return 0. */
4714 read_huge_number (char **pp, int end, int *bits)
4731 /* Leading zero means octal. GCC uses this to output values larger
4732 than an int (because that would be hard in decimal). */
4739 upper_limit = LONG_MAX / radix;
4741 while ((c = *p++) >= '0' && c < ('0' + radix))
4743 if (n <= upper_limit)
4746 n += c - '0'; /* FIXME this overflows anyway */
4751 /* This depends on large values being output in octal, which is
4758 /* Ignore leading zeroes. */
4762 else if (c == '2' || c == '3')
4788 /* Large decimal constants are an error (because it is hard to
4789 count how many bits are in them). */
4795 /* -0x7f is the same as 0x80. So deal with it by adding one to
4796 the number of bits. */
4808 /* It's *BITS which has the interesting information. */
4812 static struct type *
4813 read_range_type (char **pp, int typenums[2], struct objfile *objfile)
4815 char *orig_pp = *pp;
4820 struct type *result_type;
4821 struct type *index_type = NULL;
4823 /* First comes a type we are a subrange of.
4824 In C it is usually 0, 1 or the type being defined. */
4825 if (read_type_number (pp, rangenums) != 0)
4826 return error_type (pp, objfile);
4827 self_subrange = (rangenums[0] == typenums[0] &&
4828 rangenums[1] == typenums[1]);
4833 index_type = read_type (pp, objfile);
4836 /* A semicolon should now follow; skip it. */
4840 /* The remaining two operands are usually lower and upper bounds
4841 of the range. But in some special cases they mean something else. */
4842 n2 = read_huge_number (pp, ';', &n2bits);
4843 n3 = read_huge_number (pp, ';', &n3bits);
4845 if (n2bits == -1 || n3bits == -1)
4846 return error_type (pp, objfile);
4849 goto handle_true_range;
4851 /* If limits are huge, must be large integral type. */
4852 if (n2bits != 0 || n3bits != 0)
4854 char got_signed = 0;
4855 char got_unsigned = 0;
4856 /* Number of bits in the type. */
4859 /* Range from 0 to <large number> is an unsigned large integral type. */
4860 if ((n2bits == 0 && n2 == 0) && n3bits != 0)
4865 /* Range from <large number> to <large number>-1 is a large signed
4866 integral type. Take care of the case where <large number> doesn't
4867 fit in a long but <large number>-1 does. */
4868 else if ((n2bits != 0 && n3bits != 0 && n2bits == n3bits + 1)
4869 || (n2bits != 0 && n3bits == 0
4870 && (n2bits == sizeof (long) * HOST_CHAR_BIT)
4877 if (got_signed || got_unsigned)
4879 return init_type (TYPE_CODE_INT, nbits / TARGET_CHAR_BIT,
4880 got_unsigned ? TYPE_FLAG_UNSIGNED : 0, NULL,
4884 return error_type (pp, objfile);
4887 /* A type defined as a subrange of itself, with bounds both 0, is void. */
4888 if (self_subrange && n2 == 0 && n3 == 0)
4889 return init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile);
4891 /* If n3 is zero and n2 is positive, we want a floating type, and n2
4892 is the width in bytes.
4894 Fortran programs appear to use this for complex types also. To
4895 distinguish between floats and complex, g77 (and others?) seem
4896 to use self-subranges for the complexes, and subranges of int for
4899 Also note that for complexes, g77 sets n2 to the size of one of
4900 the member floats, not the whole complex beast. My guess is that
4901 this was to work well with pre-COMPLEX versions of gdb. */
4903 if (n3 == 0 && n2 > 0)
4905 struct type *float_type
4906 = init_type (TYPE_CODE_FLT, n2, 0, NULL, objfile);
4910 struct type *complex_type =
4911 init_type (TYPE_CODE_COMPLEX, 2 * n2, 0, NULL, objfile);
4912 TYPE_TARGET_TYPE (complex_type) = float_type;
4913 return complex_type;
4919 /* If the upper bound is -1, it must really be an unsigned int. */
4921 else if (n2 == 0 && n3 == -1)
4923 /* It is unsigned int or unsigned long. */
4924 /* GCC 2.3.3 uses this for long long too, but that is just a GDB 3.5
4925 compatibility hack. */
4926 return init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
4927 TYPE_FLAG_UNSIGNED, NULL, objfile);
4930 /* Special case: char is defined (Who knows why) as a subrange of
4931 itself with range 0-127. */
4932 else if (self_subrange && n2 == 0 && n3 == 127)
4933 return init_type (TYPE_CODE_INT, 1, TYPE_FLAG_NOSIGN, NULL, objfile);
4935 /* We used to do this only for subrange of self or subrange of int. */
4938 /* -1 is used for the upper bound of (4 byte) "unsigned int" and
4939 "unsigned long", and we already checked for that,
4940 so don't need to test for it here. */
4943 /* n3 actually gives the size. */
4944 return init_type (TYPE_CODE_INT, -n3, TYPE_FLAG_UNSIGNED,
4947 /* Is n3 == 2**(8n)-1 for some integer n? Then it's an
4948 unsigned n-byte integer. But do require n to be a power of
4949 two; we don't want 3- and 5-byte integers flying around. */
4955 for (bytes = 0; (bits & 0xff) == 0xff; bytes++)
4958 && ((bytes - 1) & bytes) == 0) /* "bytes is a power of two" */
4959 return init_type (TYPE_CODE_INT, bytes, TYPE_FLAG_UNSIGNED, NULL,
4963 /* I think this is for Convex "long long". Since I don't know whether
4964 Convex sets self_subrange, I also accept that particular size regardless
4965 of self_subrange. */
4966 else if (n3 == 0 && n2 < 0
4968 || n2 == -TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT))
4969 return init_type (TYPE_CODE_INT, -n2, 0, NULL, objfile);
4970 else if (n2 == -n3 - 1)
4973 return init_type (TYPE_CODE_INT, 1, 0, NULL, objfile);
4975 return init_type (TYPE_CODE_INT, 2, 0, NULL, objfile);
4976 if (n3 == 0x7fffffff)
4977 return init_type (TYPE_CODE_INT, 4, 0, NULL, objfile);
4980 /* We have a real range type on our hands. Allocate space and
4981 return a real pointer. */
4985 index_type = builtin_type_int;
4987 index_type = *dbx_lookup_type (rangenums);
4988 if (index_type == NULL)
4990 /* Does this actually ever happen? Is that why we are worrying
4991 about dealing with it rather than just calling error_type? */
4993 static struct type *range_type_index;
4995 complaint (&symfile_complaints,
4996 "base type %d of range type is not defined", rangenums[1]);
4997 if (range_type_index == NULL)
4999 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
5000 0, "range type index type", NULL);
5001 index_type = range_type_index;
5004 result_type = create_range_type ((struct type *) NULL, index_type, n2, n3);
5005 return (result_type);
5008 /* Read in an argument list. This is a list of types, separated by commas
5009 and terminated with END. Return the list of types read in, or (struct type
5010 **)-1 if there is an error. */
5012 static struct field *
5013 read_args (char **pp, int end, struct objfile *objfile, int *nargsp,
5016 /* FIXME! Remove this arbitrary limit! */
5017 struct type *types[1024]; /* allow for fns of 1023 parameters */
5024 /* Invalid argument list: no ','. */
5025 return (struct field *) -1;
5027 STABS_CONTINUE (pp, objfile);
5028 types[n++] = read_type (pp, objfile);
5030 (*pp)++; /* get past `end' (the ':' character) */
5032 if (TYPE_CODE (types[n - 1]) != TYPE_CODE_VOID)
5040 rval = (struct field *) xmalloc (n * sizeof (struct field));
5041 memset (rval, 0, n * sizeof (struct field));
5042 for (i = 0; i < n; i++)
5043 rval[i].type = types[i];
5048 /* Common block handling. */
5050 /* List of symbols declared since the last BCOMM. This list is a tail
5051 of local_symbols. When ECOMM is seen, the symbols on the list
5052 are noted so their proper addresses can be filled in later,
5053 using the common block base address gotten from the assembler
5056 static struct pending *common_block;
5057 static int common_block_i;
5059 /* Name of the current common block. We get it from the BCOMM instead of the
5060 ECOMM to match IBM documentation (even though IBM puts the name both places
5061 like everyone else). */
5062 static char *common_block_name;
5064 /* Process a N_BCOMM symbol. The storage for NAME is not guaranteed
5065 to remain after this function returns. */
5068 common_block_start (char *name, struct objfile *objfile)
5070 if (common_block_name != NULL)
5072 complaint (&symfile_complaints,
5073 "Invalid symbol data: common block within common block");
5075 common_block = local_symbols;
5076 common_block_i = local_symbols ? local_symbols->nsyms : 0;
5077 common_block_name = obsavestring (name, strlen (name),
5078 &objfile->symbol_obstack);
5081 /* Process a N_ECOMM symbol. */
5084 common_block_end (struct objfile *objfile)
5086 /* Symbols declared since the BCOMM are to have the common block
5087 start address added in when we know it. common_block and
5088 common_block_i point to the first symbol after the BCOMM in
5089 the local_symbols list; copy the list and hang it off the
5090 symbol for the common block name for later fixup. */
5093 struct pending *new = 0;
5094 struct pending *next;
5097 if (common_block_name == NULL)
5099 complaint (&symfile_complaints, "ECOMM symbol unmatched by BCOMM");
5103 sym = (struct symbol *)
5104 obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol));
5105 memset (sym, 0, sizeof (struct symbol));
5106 /* Note: common_block_name already saved on symbol_obstack */
5107 SYMBOL_NAME (sym) = common_block_name;
5108 SYMBOL_CLASS (sym) = LOC_BLOCK;
5110 /* Now we copy all the symbols which have been defined since the BCOMM. */
5112 /* Copy all the struct pendings before common_block. */
5113 for (next = local_symbols;
5114 next != NULL && next != common_block;
5117 for (j = 0; j < next->nsyms; j++)
5118 add_symbol_to_list (next->symbol[j], &new);
5121 /* Copy however much of COMMON_BLOCK we need. If COMMON_BLOCK is
5122 NULL, it means copy all the local symbols (which we already did
5125 if (common_block != NULL)
5126 for (j = common_block_i; j < common_block->nsyms; j++)
5127 add_symbol_to_list (common_block->symbol[j], &new);
5129 SYMBOL_TYPE (sym) = (struct type *) new;
5131 /* Should we be putting local_symbols back to what it was?
5134 i = hashname (SYMBOL_NAME (sym));
5135 SYMBOL_VALUE_CHAIN (sym) = global_sym_chain[i];
5136 global_sym_chain[i] = sym;
5137 common_block_name = NULL;
5140 /* Add a common block's start address to the offset of each symbol
5141 declared to be in it (by being between a BCOMM/ECOMM pair that uses
5142 the common block name). */
5145 fix_common_block (struct symbol *sym, int valu)
5147 struct pending *next = (struct pending *) SYMBOL_TYPE (sym);
5148 for (; next; next = next->next)
5151 for (j = next->nsyms - 1; j >= 0; j--)
5152 SYMBOL_VALUE_ADDRESS (next->symbol[j]) += valu;
5158 /* What about types defined as forward references inside of a small lexical
5160 /* Add a type to the list of undefined types to be checked through
5161 once this file has been read in. */
5164 add_undefined_type (struct type *type)
5166 if (undef_types_length == undef_types_allocated)
5168 undef_types_allocated *= 2;
5169 undef_types = (struct type **)
5170 xrealloc ((char *) undef_types,
5171 undef_types_allocated * sizeof (struct type *));
5173 undef_types[undef_types_length++] = type;
5176 /* Go through each undefined type, see if it's still undefined, and fix it
5177 up if possible. We have two kinds of undefined types:
5179 TYPE_CODE_ARRAY: Array whose target type wasn't defined yet.
5180 Fix: update array length using the element bounds
5181 and the target type's length.
5182 TYPE_CODE_STRUCT, TYPE_CODE_UNION: Structure whose fields were not
5183 yet defined at the time a pointer to it was made.
5184 Fix: Do a full lookup on the struct/union tag. */
5186 cleanup_undefined_types (void)
5190 for (type = undef_types; type < undef_types + undef_types_length; type++)
5192 switch (TYPE_CODE (*type))
5195 case TYPE_CODE_STRUCT:
5196 case TYPE_CODE_UNION:
5197 case TYPE_CODE_ENUM:
5199 /* Check if it has been defined since. Need to do this here
5200 as well as in check_typedef to deal with the (legitimate in
5201 C though not C++) case of several types with the same name
5202 in different source files. */
5203 if (TYPE_STUB (*type))
5205 struct pending *ppt;
5207 /* Name of the type, without "struct" or "union" */
5208 char *typename = TYPE_TAG_NAME (*type);
5210 if (typename == NULL)
5212 complaint (&symfile_complaints, "need a type name");
5215 for (ppt = file_symbols; ppt; ppt = ppt->next)
5217 for (i = 0; i < ppt->nsyms; i++)
5219 struct symbol *sym = ppt->symbol[i];
5221 if (SYMBOL_CLASS (sym) == LOC_TYPEDEF
5222 && SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE
5223 && (TYPE_CODE (SYMBOL_TYPE (sym)) ==
5225 && STREQ (SYMBOL_NAME (sym), typename))
5226 replace_type (*type, SYMBOL_TYPE (sym));
5235 complaint (&symfile_complaints,
5236 "GDB internal error. cleanup_undefined_types with bad type %d.",
5243 undef_types_length = 0;
5246 /* Scan through all of the global symbols defined in the object file,
5247 assigning values to the debugging symbols that need to be assigned
5248 to. Get these symbols from the minimal symbol table. */
5251 scan_file_globals (struct objfile *objfile)
5254 struct minimal_symbol *msymbol;
5255 struct symbol *sym, *prev, *rsym;
5256 struct objfile *resolve_objfile;
5258 /* SVR4 based linkers copy referenced global symbols from shared
5259 libraries to the main executable.
5260 If we are scanning the symbols for a shared library, try to resolve
5261 them from the minimal symbols of the main executable first. */
5263 if (symfile_objfile && objfile != symfile_objfile)
5264 resolve_objfile = symfile_objfile;
5266 resolve_objfile = objfile;
5270 /* Avoid expensive loop through all minimal symbols if there are
5271 no unresolved symbols. */
5272 for (hash = 0; hash < HASHSIZE; hash++)
5274 if (global_sym_chain[hash])
5277 if (hash >= HASHSIZE)
5280 for (msymbol = resolve_objfile->msymbols;
5281 msymbol && SYMBOL_NAME (msymbol) != NULL;
5286 /* Skip static symbols. */
5287 switch (MSYMBOL_TYPE (msymbol))
5299 /* Get the hash index and check all the symbols
5300 under that hash index. */
5302 hash = hashname (SYMBOL_NAME (msymbol));
5304 for (sym = global_sym_chain[hash]; sym;)
5306 if (SYMBOL_NAME (msymbol)[0] == SYMBOL_NAME (sym)[0] &&
5307 STREQ (SYMBOL_NAME (msymbol) + 1, SYMBOL_NAME (sym) + 1))
5310 struct alias_list *aliases;
5312 /* Splice this symbol out of the hash chain and
5313 assign the value we have to it. */
5316 SYMBOL_VALUE_CHAIN (prev) = SYMBOL_VALUE_CHAIN (sym);
5320 global_sym_chain[hash] = SYMBOL_VALUE_CHAIN (sym);
5323 /* Check to see whether we need to fix up a common block. */
5324 /* Note: this code might be executed several times for
5325 the same symbol if there are multiple references. */
5327 /* If symbol has aliases, do minimal symbol fixups for each.
5328 These live aliases/references weren't added to
5329 global_sym_chain hash but may also need to be fixed up. */
5330 /* FIXME: Maybe should have added aliases to the global chain, resolved symbol name, then treated aliases as normal
5331 symbols? Still, we wouldn't want to add_to_list. */
5332 /* Now do the same for each alias of this symbol */
5334 aliases = SYMBOL_ALIASES (sym);
5337 if (SYMBOL_CLASS (rsym) == LOC_BLOCK)
5339 fix_common_block (rsym,
5340 SYMBOL_VALUE_ADDRESS (msymbol));
5344 SYMBOL_VALUE_ADDRESS (rsym)
5345 = SYMBOL_VALUE_ADDRESS (msymbol);
5347 SYMBOL_SECTION (rsym) = SYMBOL_SECTION (msymbol);
5350 rsym = aliases->sym;
5351 aliases = aliases->next;
5360 sym = SYMBOL_VALUE_CHAIN (prev);
5364 sym = global_sym_chain[hash];
5370 sym = SYMBOL_VALUE_CHAIN (sym);
5374 if (resolve_objfile == objfile)
5376 resolve_objfile = objfile;
5379 /* Change the storage class of any remaining unresolved globals to
5380 LOC_UNRESOLVED and remove them from the chain. */
5381 for (hash = 0; hash < HASHSIZE; hash++)
5383 sym = global_sym_chain[hash];
5387 sym = SYMBOL_VALUE_CHAIN (sym);
5389 /* Change the symbol address from the misleading chain value
5391 SYMBOL_VALUE_ADDRESS (prev) = 0;
5393 /* Complain about unresolved common block symbols. */
5394 if (SYMBOL_CLASS (prev) == LOC_STATIC)
5395 SYMBOL_CLASS (prev) = LOC_UNRESOLVED;
5397 complaint (&symfile_complaints,
5398 "%s: common block `%s' from global_sym_chain unresolved",
5399 objfile->name, SYMBOL_NAME (prev));
5402 memset (global_sym_chain, 0, sizeof (global_sym_chain));
5405 /* Initialize anything that needs initializing when starting to read
5406 a fresh piece of a symbol file, e.g. reading in the stuff corresponding
5410 stabsread_init (void)
5414 /* Initialize anything that needs initializing when a completely new
5415 symbol file is specified (not just adding some symbols from another
5416 file, e.g. a shared library). */
5419 stabsread_new_init (void)
5421 /* Empty the hash table of global syms looking for values. */
5422 memset (global_sym_chain, 0, sizeof (global_sym_chain));
5425 /* Initialize anything that needs initializing at the same time as
5426 start_symtab() is called. */
5431 global_stabs = NULL; /* AIX COFF */
5432 /* Leave FILENUM of 0 free for builtin types and this file's types. */
5433 n_this_object_header_files = 1;
5434 type_vector_length = 0;
5435 type_vector = (struct type **) 0;
5437 /* FIXME: If common_block_name is not already NULL, we should complain(). */
5438 common_block_name = NULL;
5441 /* Call after end_symtab() */
5448 xfree (type_vector);
5451 type_vector_length = 0;
5452 previous_stab_code = 0;
5456 finish_global_stabs (struct objfile *objfile)
5460 patch_block_stabs (global_symbols, global_stabs, objfile);
5461 xfree (global_stabs);
5462 global_stabs = NULL;
5466 /* Find the end of the name, delimited by a ':', but don't match
5467 ObjC symbols which look like -[Foo bar::]:bla. */
5469 find_name_end (char *name)
5472 if (s[0] == '-' || *s == '+')
5474 /* Must be an ObjC method symbol. */
5477 error ("invalid symbol name \"%s\"", name);
5479 s = strchr (s, ']');
5482 error ("invalid symbol name \"%s\"", name);
5484 return strchr (s, ':');
5488 return strchr (s, ':');
5492 /* Initializer for this module */
5495 _initialize_stabsread (void)
5497 undef_types_allocated = 20;
5498 undef_types_length = 0;
5499 undef_types = (struct type **)
5500 xmalloc (undef_types_allocated * sizeof (struct type *));