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
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"
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"
49 /* Ask stabsread.h to define the vars it normally declares `extern'. */
52 #include "stabsread.h" /* Our own declarations */
55 extern void _initialize_stabsread (void);
57 /* The routines that read and process a complete stabs for a C struct or
58 C++ class pass lists of data member fields and lists of member function
59 fields in an instance of a field_info structure, as defined below.
60 This is part of some reorganization of low level C++ support and is
61 expected to eventually go away... (FIXME) */
67 struct nextfield
*next
;
69 /* This is the raw visibility from the stab. It is not checked
70 for being one of the visibilities we recognize, so code which
71 examines this field better be able to deal. */
77 struct next_fnfieldlist
79 struct next_fnfieldlist
*next
;
80 struct fn_fieldlist fn_fieldlist
;
86 read_one_struct_field (struct field_info
*, char **, char *,
87 struct type
*, struct objfile
*);
89 static char *get_substring (char **, int);
91 static struct type
*dbx_alloc_type (int[2], struct objfile
*);
93 static long read_huge_number (char **, int, int *);
95 static struct type
*error_type (char **, struct objfile
*);
98 patch_block_stabs (struct pending
*, struct pending_stabs
*,
101 static void fix_common_block (struct symbol
*, int);
103 static int read_type_number (char **, int *);
105 static struct type
*read_range_type (char **, int[2], struct objfile
*);
107 static struct type
*read_sun_builtin_type (char **, int[2], struct objfile
*);
109 static struct type
*read_sun_floating_type (char **, int[2],
112 static struct type
*read_enum_type (char **, struct type
*, struct objfile
*);
114 static struct type
*rs6000_builtin_type (int);
117 read_member_functions (struct field_info
*, char **, struct type
*,
121 read_struct_fields (struct field_info
*, char **, struct type
*,
125 read_baseclasses (struct field_info
*, char **, struct type
*,
129 read_tilde_fields (struct field_info
*, char **, struct type
*,
132 static int attach_fn_fields_to_type (struct field_info
*, struct type
*);
135 attach_fields_to_type (struct field_info
*, struct type
*, struct objfile
*);
137 static struct type
*read_struct_type (char **, struct type
*,
140 static struct type
*read_array_type (char **, struct type
*,
143 static struct type
**read_args (char **, int, struct objfile
*);
146 read_cpp_abbrev (struct field_info
*, char **, struct type
*,
149 /* new functions added for cfront support */
152 copy_cfront_struct_fields (struct field_info
*, struct type
*,
155 static char *get_cfront_method_physname (char *);
158 read_cfront_baseclasses (struct field_info
*, char **,
159 struct type
*, struct objfile
*);
162 read_cfront_static_fields (struct field_info
*, char **,
163 struct type
*, struct objfile
*);
165 read_cfront_member_functions (struct field_info
*, char **,
166 struct type
*, struct objfile
*);
168 /* end new functions added for cfront support */
171 add_live_range (struct objfile
*, struct symbol
*, CORE_ADDR
, CORE_ADDR
);
173 static int resolve_live_range (struct objfile
*, struct symbol
*, char *);
175 static int process_reference (char **string
);
177 static CORE_ADDR
ref_search_value (int refnum
);
180 resolve_symbol_reference (struct objfile
*, struct symbol
*, char *);
182 void stabsread_clear_cache (void);
184 static const char vptr_name
[] =
185 {'_', 'v', 'p', 't', 'r', CPLUS_MARKER
, '\0'};
186 static const char vb_name
[] =
187 {'_', 'v', 'b', CPLUS_MARKER
, '\0'};
189 /* Define this as 1 if a pcc declaration of a char or short argument
190 gives the correct address. Otherwise assume pcc gives the
191 address of the corresponding int, which is not the same on a
192 big-endian machine. */
194 #if !defined (BELIEVE_PCC_PROMOTION)
195 #define BELIEVE_PCC_PROMOTION 0
197 #if !defined (BELIEVE_PCC_PROMOTION_TYPE)
198 #define BELIEVE_PCC_PROMOTION_TYPE 0
201 static struct complaint invalid_cpp_abbrev_complaint
=
202 {"invalid C++ abbreviation `%s'", 0, 0};
204 static struct complaint invalid_cpp_type_complaint
=
205 {"C++ abbreviated type name unknown at symtab pos %d", 0, 0};
207 static struct complaint member_fn_complaint
=
208 {"member function type missing, got '%c'", 0, 0};
210 static struct complaint const_vol_complaint
=
211 {"const/volatile indicator missing, got '%c'", 0, 0};
213 static struct complaint error_type_complaint
=
214 {"debug info mismatch between compiler and debugger", 0, 0};
216 static struct complaint invalid_member_complaint
=
217 {"invalid (minimal) member type data format at symtab pos %d.", 0, 0};
219 static struct complaint range_type_base_complaint
=
220 {"base type %d of range type is not defined", 0, 0};
222 static struct complaint reg_value_complaint
=
223 {"register number %d too large (max %d) in symbol %s", 0, 0};
225 static struct complaint vtbl_notfound_complaint
=
226 {"virtual function table pointer not found when defining class `%s'", 0, 0};
228 static struct complaint unrecognized_cplus_name_complaint
=
229 {"Unknown C++ symbol name `%s'", 0, 0};
231 static struct complaint rs6000_builtin_complaint
=
232 {"Unknown builtin type %d", 0, 0};
234 static struct complaint unresolved_sym_chain_complaint
=
235 {"%s: common block `%s' from global_sym_chain unresolved", 0, 0};
237 static struct complaint stabs_general_complaint
=
240 static struct complaint lrs_general_complaint
=
243 /* Make a list of forward references which haven't been defined. */
245 static struct type
**undef_types
;
246 static int undef_types_allocated
;
247 static int undef_types_length
;
248 static struct symbol
*current_symbol
= NULL
;
250 /* Check for and handle cretinous stabs symbol name continuation! */
251 #define STABS_CONTINUE(pp,objfile) \
253 if (**(pp) == '\\' || (**(pp) == '?' && (*(pp))[1] == '\0')) \
254 *(pp) = next_symbol_text (objfile); \
257 /* FIXME: These probably should be our own types (like rs6000_builtin_type
258 has its own types) rather than builtin_type_*. */
259 static struct type
**os9k_type_vector
[] =
266 &builtin_type_unsigned_char
,
267 &builtin_type_unsigned_short
,
268 &builtin_type_unsigned_long
,
269 &builtin_type_unsigned_int
,
271 &builtin_type_double
,
273 &builtin_type_long_double
276 static void os9k_init_type_vector (struct type
**);
279 os9k_init_type_vector (struct type
**tv
)
282 for (i
= 0; i
< sizeof (os9k_type_vector
) / sizeof (struct type
**); i
++)
283 tv
[i
] = (os9k_type_vector
[i
] == 0 ? 0 : *(os9k_type_vector
[i
]));
286 /* Look up a dbx type-number pair. Return the address of the slot
287 where the type for that number-pair is stored.
288 The number-pair is in TYPENUMS.
290 This can be used for finding the type associated with that pair
291 or for associating a new type with the pair. */
294 dbx_lookup_type (int typenums
[2])
296 register int filenum
= typenums
[0];
297 register int index
= typenums
[1];
299 register int real_filenum
;
300 register struct header_file
*f
;
303 if (filenum
== -1) /* -1,-1 is for temporary types. */
306 if (filenum
< 0 || filenum
>= n_this_object_header_files
)
308 static struct complaint msg
=
310 Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.",
312 complain (&msg
, filenum
, index
, symnum
);
320 /* Caller wants address of address of type. We think
321 that negative (rs6k builtin) types will never appear as
322 "lvalues", (nor should they), so we stuff the real type
323 pointer into a temp, and return its address. If referenced,
324 this will do the right thing. */
325 static struct type
*temp_type
;
327 temp_type
= rs6000_builtin_type (index
);
331 /* Type is defined outside of header files.
332 Find it in this object file's type vector. */
333 if (index
>= type_vector_length
)
335 old_len
= type_vector_length
;
338 type_vector_length
= INITIAL_TYPE_VECTOR_LENGTH
;
339 type_vector
= (struct type
**)
340 xmalloc (type_vector_length
* sizeof (struct type
*));
342 while (index
>= type_vector_length
)
344 type_vector_length
*= 2;
346 type_vector
= (struct type
**)
347 xrealloc ((char *) type_vector
,
348 (type_vector_length
* sizeof (struct type
*)));
349 memset (&type_vector
[old_len
], 0,
350 (type_vector_length
- old_len
) * sizeof (struct type
*));
353 /* Deal with OS9000 fundamental types. */
354 os9k_init_type_vector (type_vector
);
356 return (&type_vector
[index
]);
360 real_filenum
= this_object_header_files
[filenum
];
362 if (real_filenum
>= N_HEADER_FILES (current_objfile
))
364 struct type
*temp_type
;
365 struct type
**temp_type_p
;
367 warning ("GDB internal error: bad real_filenum");
370 temp_type
= init_type (TYPE_CODE_ERROR
, 0, 0, NULL
, NULL
);
371 temp_type_p
= (struct type
**) xmalloc (sizeof (struct type
*));
372 *temp_type_p
= temp_type
;
376 f
= HEADER_FILES (current_objfile
) + real_filenum
;
378 f_orig_length
= f
->length
;
379 if (index
>= f_orig_length
)
381 while (index
>= f
->length
)
385 f
->vector
= (struct type
**)
386 xrealloc ((char *) f
->vector
, f
->length
* sizeof (struct type
*));
387 memset (&f
->vector
[f_orig_length
], 0,
388 (f
->length
- f_orig_length
) * sizeof (struct type
*));
390 return (&f
->vector
[index
]);
394 /* Make sure there is a type allocated for type numbers TYPENUMS
395 and return the type object.
396 This can create an empty (zeroed) type object.
397 TYPENUMS may be (-1, -1) to return a new type object that is not
398 put into the type vector, and so may not be referred to by number. */
401 dbx_alloc_type (int typenums
[2], struct objfile
*objfile
)
403 register struct type
**type_addr
;
405 if (typenums
[0] == -1)
407 return (alloc_type (objfile
));
410 type_addr
= dbx_lookup_type (typenums
);
412 /* If we are referring to a type not known at all yet,
413 allocate an empty type for it.
414 We will fill it in later if we find out how. */
417 *type_addr
= alloc_type (objfile
);
423 /* for all the stabs in a given stab vector, build appropriate types
424 and fix their symbols in given symbol vector. */
427 patch_block_stabs (struct pending
*symbols
, struct pending_stabs
*stabs
,
428 struct objfile
*objfile
)
438 /* for all the stab entries, find their corresponding symbols and
439 patch their types! */
441 for (ii
= 0; ii
< stabs
->count
; ++ii
)
443 name
= stabs
->stab
[ii
];
444 pp
= (char *) strchr (name
, ':');
448 pp
= (char *) strchr (pp
, ':');
450 sym
= find_symbol_in_list (symbols
, name
, pp
- name
);
453 /* FIXME-maybe: it would be nice if we noticed whether
454 the variable was defined *anywhere*, not just whether
455 it is defined in this compilation unit. But neither
456 xlc or GCC seem to need such a definition, and until
457 we do psymtabs (so that the minimal symbols from all
458 compilation units are available now), I'm not sure
459 how to get the information. */
461 /* On xcoff, if a global is defined and never referenced,
462 ld will remove it from the executable. There is then
463 a N_GSYM stab for it, but no regular (C_EXT) symbol. */
464 sym
= (struct symbol
*)
465 obstack_alloc (&objfile
->symbol_obstack
,
466 sizeof (struct symbol
));
468 memset (sym
, 0, sizeof (struct symbol
));
469 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
470 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
472 obsavestring (name
, pp
- name
, &objfile
->symbol_obstack
);
474 if (*(pp
- 1) == 'F' || *(pp
- 1) == 'f')
476 /* I don't think the linker does this with functions,
477 so as far as I know this is never executed.
478 But it doesn't hurt to check. */
480 lookup_function_type (read_type (&pp
, objfile
));
484 SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
486 add_symbol_to_list (sym
, &global_symbols
);
491 if (*(pp
- 1) == 'F' || *(pp
- 1) == 'f')
494 lookup_function_type (read_type (&pp
, objfile
));
498 SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
506 /* Read a number by which a type is referred to in dbx data,
507 or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
508 Just a single number N is equivalent to (0,N).
509 Return the two numbers by storing them in the vector TYPENUMS.
510 TYPENUMS will then be used as an argument to dbx_lookup_type.
512 Returns 0 for success, -1 for error. */
515 read_type_number (register char **pp
, register int *typenums
)
521 typenums
[0] = read_huge_number (pp
, ',', &nbits
);
524 typenums
[1] = read_huge_number (pp
, ')', &nbits
);
531 typenums
[1] = read_huge_number (pp
, 0, &nbits
);
539 #define VISIBILITY_PRIVATE '0' /* Stabs character for private field */
540 #define VISIBILITY_PROTECTED '1' /* Stabs character for protected fld */
541 #define VISIBILITY_PUBLIC '2' /* Stabs character for public field */
542 #define VISIBILITY_IGNORE '9' /* Optimized out or zero length */
544 #define CFRONT_VISIBILITY_PRIVATE '2' /* Stabs character for private field */
545 #define CFRONT_VISIBILITY_PUBLIC '1' /* Stabs character for public field */
547 /* This code added to support parsing of ARM/Cfront stabs strings */
549 /* Get substring from string up to char c, advance string pointer past
553 get_substring (char **p
, int c
)
568 /* Physname gets strcat'd onto sname in order to recreate the mangled
569 name (see funtion gdb_mangle_name in gdbtypes.c). For cfront, make
570 the physname look like that of g++ - take out the initial mangling
571 eg: for sname="a" and fname="foo__1aFPFs_i" return "FPFs_i" */
574 get_cfront_method_physname (char *fname
)
577 /* FIXME would like to make this generic for g++ too, but
578 that is already handled in read_member_funcctions */
581 /* search ahead to find the start of the mangled suffix */
582 if (*p
== '_' && *(p
+ 1) == '_') /* compiler generated; probably a ctor/dtor */
584 while (p
&& (unsigned) ((p
+ 1) - fname
) < strlen (fname
) && *(p
+ 1) != '_')
586 if (!(p
&& *p
== '_' && *(p
+ 1) == '_'))
587 error ("Invalid mangled function name %s", fname
);
588 p
+= 2; /* advance past '__' */
590 /* struct name length and name of type should come next; advance past it */
593 len
= len
* 10 + (*p
- '0');
601 /* Read base classes within cfront class definition.
602 eg: A:ZcA;1@Bpub v2@Bvirpri;__ct__1AFv func__1AFv *sfunc__1AFv ;as__1A ;;
605 A:ZcA;;foopri__1AFv foopro__1AFv __ct__1AFv __ct__1AFRC1A foopub__1AFv ;;;
610 read_cfront_baseclasses (struct field_info
*fip
, char **pp
, struct type
*type
,
611 struct objfile
*objfile
)
613 static struct complaint msg_unknown
=
615 Unsupported token in stabs string %s.\n",
617 static struct complaint msg_notfound
=
619 Unable to find base type for %s.\n",
624 struct nextfield
*new;
626 if (**pp
== ';') /* no base classes; return */
632 /* first count base classes so we can allocate space before parsing */
633 for (p
= *pp
; p
&& *p
&& *p
!= ';'; p
++)
638 bnum
++; /* add one more for last one */
640 /* now parse the base classes until we get to the start of the methods
641 (code extracted and munged from read_baseclasses) */
642 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
643 TYPE_N_BASECLASSES (type
) = bnum
;
647 int num_bytes
= B_BYTES (TYPE_N_BASECLASSES (type
));
650 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
651 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
653 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), TYPE_N_BASECLASSES (type
));
655 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
657 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
658 make_cleanup (xfree
, new);
659 memset (new, 0, sizeof (struct nextfield
));
660 new->next
= fip
->list
;
662 FIELD_BITSIZE (new->field
) = 0; /* this should be an unpacked field! */
664 STABS_CONTINUE (pp
, objfile
);
666 /* virtual? eg: v2@Bvir */
669 SET_TYPE_FIELD_VIRTUAL (type
, i
);
673 /* access? eg: 2@Bvir */
674 /* Note: protected inheritance not supported in cfront */
677 case CFRONT_VISIBILITY_PRIVATE
:
678 new->visibility
= VISIBILITY_PRIVATE
;
680 case CFRONT_VISIBILITY_PUBLIC
:
681 new->visibility
= VISIBILITY_PUBLIC
;
684 /* Bad visibility format. Complain and treat it as
687 static struct complaint msg
=
689 "Unknown visibility `%c' for baseclass", 0, 0};
690 complain (&msg
, new->visibility
);
691 new->visibility
= VISIBILITY_PUBLIC
;
695 /* "@" comes next - eg: @Bvir */
698 complain (&msg_unknown
, *pp
);
704 /* Set the bit offset of the portion of the object corresponding
705 to this baseclass. Always zero in the absence of
706 multiple inheritance. */
707 /* Unable to read bit position from stabs;
708 Assuming no multiple inheritance for now FIXME! */
709 /* We may have read this in the structure definition;
710 now we should fixup the members to be the actual base classes */
711 FIELD_BITPOS (new->field
) = 0;
713 /* Get the base class name and type */
715 char *bname
; /* base class name */
716 struct symbol
*bsym
; /* base class */
718 p1
= strchr (*pp
, ' ');
719 p2
= strchr (*pp
, ';');
721 bname
= get_substring (pp
, ' ');
723 bname
= get_substring (pp
, ';');
724 if (!bname
|| !*bname
)
726 complain (&msg_unknown
, *pp
);
729 /* FIXME! attach base info to type */
730 bsym
= lookup_symbol (bname
, 0, STRUCT_NAMESPACE
, 0, 0); /*demangled_name */
733 new->field
.type
= SYMBOL_TYPE (bsym
);
734 new->field
.name
= type_name_no_tag (new->field
.type
);
738 complain (&msg_notfound
, *pp
);
743 /* If more base classes to parse, loop again.
744 We ate the last ' ' or ';' in get_substring,
745 so on exit we will have skipped the trailing ';' */
746 /* if invalid, return 0; add code to detect - FIXME! */
751 /* read cfront member functions.
752 pp points to string starting with list of functions
753 eg: A:ZcA;1@Bpub v2@Bvirpri;__ct__1AFv func__1AFv *sfunc__1AFv ;as__1A ;;
754 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
755 A:ZcA;;foopri__1AFv foopro__1AFv __ct__1AFv __ct__1AFRC1A foopub__1AFv ;;;
756 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
760 read_cfront_member_functions (struct field_info
*fip
, char **pp
,
761 struct type
*type
, struct objfile
*objfile
)
763 /* This code extracted from read_member_functions
764 so as to do the similar thing for our funcs */
768 /* Total number of member functions defined in this class. If the class
769 defines two `f' functions, and one `g' function, then this will have
771 int total_length
= 0;
775 struct next_fnfield
*next
;
776 struct fn_field fn_field
;
779 struct type
*look_ahead_type
;
780 struct next_fnfieldlist
*new_fnlist
;
781 struct next_fnfield
*new_sublist
;
784 struct symbol
*ref_func
= 0;
786 /* Process each list until we find the end of the member functions.
787 eg: p = "__ct__1AFv foo__1AFv ;;;" */
789 STABS_CONTINUE (pp
, objfile
); /* handle \\ */
791 while (**pp
!= ';' && (fname
= get_substring (pp
, ' '), fname
))
794 int sublist_count
= 0;
796 if (fname
[0] == '*') /* static member */
802 ref_func
= lookup_symbol (fname
, 0, VAR_NAMESPACE
, 0, 0); /* demangled name */
805 static struct complaint msg
=
807 Unable to find function symbol for %s\n",
809 complain (&msg
, fname
);
813 look_ahead_type
= NULL
;
816 new_fnlist
= (struct next_fnfieldlist
*)
817 xmalloc (sizeof (struct next_fnfieldlist
));
818 make_cleanup (xfree
, new_fnlist
);
819 memset (new_fnlist
, 0, sizeof (struct next_fnfieldlist
));
821 /* The following is code to work around cfront generated stabs.
822 The stabs contains full mangled name for each field.
823 We try to demangle the name and extract the field name out of it. */
825 char *dem
, *dem_p
, *dem_args
;
827 dem
= cplus_demangle (fname
, DMGL_ANSI
| DMGL_PARAMS
);
830 dem_p
= strrchr (dem
, ':');
831 if (dem_p
!= 0 && *(dem_p
- 1) == ':')
833 /* get rid of args */
834 dem_args
= strchr (dem_p
, '(');
835 if (dem_args
== NULL
)
836 dem_len
= strlen (dem_p
);
838 dem_len
= dem_args
- dem_p
;
840 obsavestring (dem_p
, dem_len
, &objfile
->type_obstack
);
845 obsavestring (fname
, strlen (fname
), &objfile
->type_obstack
);
847 } /* end of code for cfront work around */
849 new_fnlist
->fn_fieldlist
.name
= main_fn_name
;
851 /*-------------------------------------------------*/
852 /* Set up the sublists
853 Sublists are stuff like args, static, visibility, etc.
854 so in ARM, we have to set that info some other way.
855 Multiple sublists happen if overloading
856 eg: foo::26=##1;:;2A.;
857 In g++, we'd loop here thru all the sublists... */
860 (struct next_fnfield
*) xmalloc (sizeof (struct next_fnfield
));
861 make_cleanup (xfree
, new_sublist
);
862 memset (new_sublist
, 0, sizeof (struct next_fnfield
));
864 /* eat 1; from :;2A.; */
865 new_sublist
->fn_field
.type
= SYMBOL_TYPE (ref_func
); /* normally takes a read_type */
866 /* Make this type look like a method stub for gdb */
867 TYPE_FLAGS (new_sublist
->fn_field
.type
) |= TYPE_FLAG_STUB
;
868 TYPE_CODE (new_sublist
->fn_field
.type
) = TYPE_CODE_METHOD
;
870 /* If this is just a stub, then we don't have the real name here. */
871 if (TYPE_FLAGS (new_sublist
->fn_field
.type
) & TYPE_FLAG_STUB
)
873 if (!TYPE_DOMAIN_TYPE (new_sublist
->fn_field
.type
))
874 TYPE_DOMAIN_TYPE (new_sublist
->fn_field
.type
) = type
;
875 new_sublist
->fn_field
.is_stub
= 1;
878 /* physname used later in mangling; eg PFs_i,5 for foo__1aFPFs_i
879 physname gets strcat'd in order to recreate the onto mangled name */
880 pname
= get_cfront_method_physname (fname
);
881 new_sublist
->fn_field
.physname
= savestring (pname
, strlen (pname
));
884 /* Set this member function's visibility fields.
885 Unable to distinguish access from stabs definition!
886 Assuming public for now. FIXME!
887 (for private, set new_sublist->fn_field.is_private = 1,
888 for public, set new_sublist->fn_field.is_protected = 1) */
890 /* Unable to distinguish const/volatile from stabs definition!
891 Assuming normal for now. FIXME! */
893 new_sublist
->fn_field
.is_const
= 0;
894 new_sublist
->fn_field
.is_volatile
= 0; /* volatile not implemented in cfront */
896 /* Set virtual/static function info
897 How to get vtable offsets ?
898 Assuming normal for now FIXME!!
899 For vtables, figure out from whence this virtual function came.
900 It may belong to virtual function table of
901 one of its baseclasses.
903 new_sublist -> fn_field.voffset = vtable offset,
904 new_sublist -> fn_field.fcontext = look_ahead_type;
905 where look_ahead_type is type of baseclass */
907 new_sublist
->fn_field
.voffset
= VOFFSET_STATIC
;
908 else /* normal member function. */
909 new_sublist
->fn_field
.voffset
= 0;
910 new_sublist
->fn_field
.fcontext
= 0;
913 /* Prepare new sublist */
914 new_sublist
->next
= sublist
;
915 sublist
= new_sublist
;
918 /* In g++, we loop thu sublists - now we set from functions. */
919 new_fnlist
->fn_fieldlist
.fn_fields
= (struct fn_field
*)
920 obstack_alloc (&objfile
->type_obstack
,
921 sizeof (struct fn_field
) * length
);
922 memset (new_fnlist
->fn_fieldlist
.fn_fields
, 0,
923 sizeof (struct fn_field
) * length
);
924 for (i
= length
; (i
--, sublist
); sublist
= sublist
->next
)
926 new_fnlist
->fn_fieldlist
.fn_fields
[i
] = sublist
->fn_field
;
929 new_fnlist
->fn_fieldlist
.length
= length
;
930 new_fnlist
->next
= fip
->fnlist
;
931 fip
->fnlist
= new_fnlist
;
933 total_length
+= length
;
934 STABS_CONTINUE (pp
, objfile
); /* handle \\ */
939 /* type should already have space */
940 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
941 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * nfn_fields
);
942 memset (TYPE_FN_FIELDLISTS (type
), 0,
943 sizeof (struct fn_fieldlist
) * nfn_fields
);
944 TYPE_NFN_FIELDS (type
) = nfn_fields
;
945 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
948 /* end of scope for reading member func */
952 /* Skip trailing ';' and bump count of number of fields seen */
960 /* This routine fixes up partial cfront types that were created
961 while parsing the stabs. The main need for this function is
962 to add information such as methods to classes.
963 Examples of "p": "sA;;__ct__1AFv foo__1AFv ;;;" */
965 resolve_cfront_continuation (struct objfile
*objfile
, struct symbol
*sym
,
968 struct symbol
*ref_sym
= 0;
970 /* snarfed from read_struct_type */
971 struct field_info fi
;
973 struct cleanup
*back_to
;
975 /* Need to make sure that fi isn't gunna conflict with struct
976 in case struct already had some fnfs */
979 back_to
= make_cleanup (null_cleanup
, 0);
981 /* We only accept structs, classes and unions at the moment.
982 Other continuation types include t (typedef), r (long dbl), ...
983 We may want to add support for them as well;
984 right now they are handled by duplicating the symbol information
985 into the type information (see define_symbol) */
986 if (*p
!= 's' /* structs */
987 && *p
!= 'c' /* class */
988 && *p
!= 'u') /* union */
989 return 0; /* only handle C++ types */
992 /* Get symbol typs name and validate
993 eg: p = "A;;__ct__1AFv foo__1AFv ;;;" */
994 sname
= get_substring (&p
, ';');
995 if (!sname
|| strcmp (sname
, SYMBOL_NAME (sym
)))
996 error ("Internal error: base symbol type name does not match\n");
998 /* Find symbol's internal gdb reference using demangled_name.
999 This is the real sym that we want;
1000 sym was a temp hack to make debugger happy */
1001 ref_sym
= lookup_symbol (SYMBOL_NAME (sym
), 0, STRUCT_NAMESPACE
, 0, 0);
1002 type
= SYMBOL_TYPE (ref_sym
);
1005 /* Now read the baseclasses, if any, read the regular C struct or C++
1006 class member fields, attach the fields to the type, read the C++
1007 member functions, attach them to the type, and then read any tilde
1008 field (baseclass specifier for the class holding the main vtable). */
1010 if (!read_cfront_baseclasses (&fi
, &p
, type
, objfile
)
1011 /* g++ does this next, but cfront already did this:
1012 || !read_struct_fields (&fi, &p, type, objfile) */
1013 || !copy_cfront_struct_fields (&fi
, type
, objfile
)
1014 || !read_cfront_member_functions (&fi
, &p
, type
, objfile
)
1015 || !read_cfront_static_fields (&fi
, &p
, type
, objfile
)
1016 || !attach_fields_to_type (&fi
, type
, objfile
)
1017 || !attach_fn_fields_to_type (&fi
, type
)
1018 /* g++ does this next, but cfront doesn't seem to have this:
1019 || !read_tilde_fields (&fi, &p, type, objfile) */
1022 type
= error_type (&p
, objfile
);
1025 do_cleanups (back_to
);
1028 /* End of code added to support parsing of ARM/Cfront stabs strings */
1031 /* This routine fixes up symbol references/aliases to point to the original
1032 symbol definition. Returns 0 on failure, non-zero on success. */
1035 resolve_symbol_reference (struct objfile
*objfile
, struct symbol
*sym
, char *p
)
1038 struct symbol
*ref_sym
= 0;
1039 struct alias_list
*alias
;
1041 /* If this is not a symbol reference return now. */
1045 /* Use "#<num>" as the name; we'll fix the name later.
1046 We stored the original symbol name as "#<id>=<name>"
1047 so we can now search for "#<id>" to resolving the reference.
1048 We'll fix the names later by removing the "#<id>" or "#<id>=" */
1050 /*---------------------------------------------------------*/
1051 /* Get the reference id number, and
1052 advance p past the names so we can parse the rest.
1053 eg: id=2 for p : "2=", "2=z:r(0,1)" "2:r(0,1);l(#5,#6),l(#7,#4)" */
1054 /*---------------------------------------------------------*/
1056 /* This gets reference name from string. sym may not have a name. */
1058 /* Get the reference number associated with the reference id in the
1059 gdb stab string. From that reference number, get the main/primary
1060 symbol for this alias. */
1061 refnum
= process_reference (&p
);
1062 ref_sym
= ref_search (refnum
);
1065 complain (&lrs_general_complaint
, "symbol for reference not found");
1069 /* Parse the stab of the referencing symbol
1070 now that we have the referenced symbol.
1071 Add it as a new symbol and a link back to the referenced symbol.
1072 eg: p : "=", "=z:r(0,1)" ":r(0,1);l(#5,#6),l(#7,#4)" */
1075 /* If the stab symbol table and string contain:
1076 RSYM 0 5 00000000 868 #15=z:r(0,1)
1077 LBRAC 0 0 00000000 899 #5=
1078 SLINE 0 16 00000003 923 #6=
1079 Then the same symbols can be later referenced by:
1080 RSYM 0 5 00000000 927 #15:r(0,1);l(#5,#6)
1081 This is used in live range splitting to:
1082 1) specify that a symbol (#15) is actually just a new storage
1083 class for a symbol (#15=z) which was previously defined.
1084 2) specify that the beginning and ending ranges for a symbol
1085 (#15) are the values of the beginning (#5) and ending (#6)
1088 /* Read number as reference id.
1089 eg: p : "=", "=z:r(0,1)" ":r(0,1);l(#5,#6),l(#7,#4)" */
1090 /* FIXME! Might I want to use SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
1091 in case of "l(0,0)"? */
1093 /*--------------------------------------------------*/
1094 /* Add this symbol to the reference list. */
1095 /*--------------------------------------------------*/
1097 alias
= (struct alias_list
*) obstack_alloc (&objfile
->type_obstack
,
1098 sizeof (struct alias_list
));
1101 complain (&lrs_general_complaint
, "Unable to allocate alias list memory");
1108 if (!SYMBOL_ALIASES (ref_sym
))
1110 SYMBOL_ALIASES (ref_sym
) = alias
;
1114 struct alias_list
*temp
;
1116 /* Get to the end of the list. */
1117 for (temp
= SYMBOL_ALIASES (ref_sym
);
1124 /* Want to fix up name so that other functions (eg. valops)
1125 will correctly print the name.
1126 Don't add_symbol_to_list so that lookup_symbol won't find it.
1127 nope... needed for fixups. */
1128 SYMBOL_NAME (sym
) = SYMBOL_NAME (ref_sym
);
1134 /* Structure for storing pointers to reference definitions for fast lookup
1135 during "process_later". */
1144 #define MAX_CHUNK_REFS 100
1145 #define REF_CHUNK_SIZE (MAX_CHUNK_REFS * sizeof (struct ref_map))
1146 #define REF_MAP_SIZE(ref_chunk) ((ref_chunk) * REF_CHUNK_SIZE)
1148 static struct ref_map
*ref_map
;
1150 /* Ptr to free cell in chunk's linked list. */
1151 static int ref_count
= 0;
1153 /* Number of chunks malloced. */
1154 static int ref_chunk
= 0;
1156 /* This file maintains a cache of stabs aliases found in the symbol
1157 table. If the symbol table changes, this cache must be cleared
1158 or we are left holding onto data in invalid obstacks. */
1160 stabsread_clear_cache (void)
1166 /* Create array of pointers mapping refids to symbols and stab strings.
1167 Add pointers to reference definition symbols and/or their values as we
1168 find them, using their reference numbers as our index.
1169 These will be used later when we resolve references. */
1171 ref_add (int refnum
, struct symbol
*sym
, char *stabs
, CORE_ADDR value
)
1175 if (refnum
>= ref_count
)
1176 ref_count
= refnum
+ 1;
1177 if (ref_count
> ref_chunk
* MAX_CHUNK_REFS
)
1179 int new_slots
= ref_count
- ref_chunk
* MAX_CHUNK_REFS
;
1180 int new_chunks
= new_slots
/ MAX_CHUNK_REFS
+ 1;
1181 ref_map
= (struct ref_map
*)
1182 xrealloc (ref_map
, REF_MAP_SIZE (ref_chunk
+ new_chunks
));
1183 memset (ref_map
+ ref_chunk
* MAX_CHUNK_REFS
, 0, new_chunks
* REF_CHUNK_SIZE
);
1184 ref_chunk
+= new_chunks
;
1186 ref_map
[refnum
].stabs
= stabs
;
1187 ref_map
[refnum
].sym
= sym
;
1188 ref_map
[refnum
].value
= value
;
1191 /* Return defined sym for the reference REFNUM. */
1193 ref_search (int refnum
)
1195 if (refnum
< 0 || refnum
> ref_count
)
1197 return ref_map
[refnum
].sym
;
1200 /* Return value for the reference REFNUM. */
1203 ref_search_value (int refnum
)
1205 if (refnum
< 0 || refnum
> ref_count
)
1207 return ref_map
[refnum
].value
;
1210 /* Parse a reference id in STRING and return the resulting
1211 reference number. Move STRING beyond the reference id. */
1214 process_reference (char **string
)
1219 if (**string
!= '#')
1222 /* Advance beyond the initial '#'. */
1225 /* Read number as reference id. */
1226 while (*p
&& isdigit (*p
))
1228 refnum
= refnum
* 10 + *p
- '0';
1235 /* If STRING defines a reference, store away a pointer to the reference
1236 definition for later use. Return the reference number. */
1239 symbol_reference_defined (char **string
)
1244 refnum
= process_reference (&p
);
1246 /* Defining symbols end in '=' */
1249 /* Symbol is being defined here. */
1255 /* Must be a reference. Either the symbol has already been defined,
1256 or this is a forward reference to it. */
1264 define_symbol (CORE_ADDR valu
, char *string
, int desc
, int type
,
1265 struct objfile
*objfile
)
1267 register struct symbol
*sym
;
1268 char *p
= (char *) strchr (string
, ':');
1273 /* We would like to eliminate nameless symbols, but keep their types.
1274 E.g. stab entry ":t10=*2" should produce a type 10, which is a pointer
1275 to type 2, but, should not create a symbol to address that type. Since
1276 the symbol will be nameless, there is no way any user can refer to it. */
1280 /* Ignore syms with empty names. */
1284 /* Ignore old-style symbols from cc -go */
1291 p
= strchr (p
, ':');
1294 /* If a nameless stab entry, all we need is the type, not the symbol.
1295 e.g. ":t10=*2" or a nameless enum like " :T16=ered:0,green:1,blue:2,;" */
1296 nameless
= (p
== string
|| ((string
[0] == ' ') && (string
[1] == ':')));
1298 current_symbol
= sym
= (struct symbol
*)
1299 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct symbol
));
1300 memset (sym
, 0, sizeof (struct symbol
));
1302 switch (type
& N_TYPE
)
1305 SYMBOL_SECTION (sym
) = SECT_OFF_TEXT (objfile
);
1308 SYMBOL_SECTION (sym
) = SECT_OFF_DATA (objfile
);
1311 SYMBOL_SECTION (sym
) = SECT_OFF_BSS (objfile
);
1315 if (processing_gcc_compilation
)
1317 /* GCC 2.x puts the line number in desc. SunOS apparently puts in the
1318 number of bytes occupied by a type or object, which we ignore. */
1319 SYMBOL_LINE (sym
) = desc
;
1323 SYMBOL_LINE (sym
) = 0; /* unknown */
1326 if (is_cplus_marker (string
[0]))
1328 /* Special GNU C++ names. */
1332 SYMBOL_NAME (sym
) = obsavestring ("this", strlen ("this"),
1333 &objfile
->symbol_obstack
);
1336 case 'v': /* $vtbl_ptr_type */
1337 /* Was: SYMBOL_NAME (sym) = "vptr"; */
1341 SYMBOL_NAME (sym
) = obsavestring ("eh_throw", strlen ("eh_throw"),
1342 &objfile
->symbol_obstack
);
1346 /* This was an anonymous type that was never fixed up. */
1349 #ifdef STATIC_TRANSFORM_NAME
1351 /* SunPRO (3.0 at least) static variable encoding. */
1356 complain (&unrecognized_cplus_name_complaint
, string
);
1357 goto normal
; /* Do *something* with it */
1360 else if (string
[0] == '#')
1362 /* Special GNU C extension for referencing symbols. */
1366 /* If STRING defines a new reference id, then add it to the
1367 reference map. Else it must be referring to a previously
1368 defined symbol, so add it to the alias list of the previously
1371 refnum
= symbol_reference_defined (&s
);
1373 ref_add (refnum
, sym
, string
, SYMBOL_VALUE (sym
));
1374 else if (!resolve_symbol_reference (objfile
, sym
, string
))
1377 /* S..P contains the name of the symbol. We need to store
1378 the correct name into SYMBOL_NAME. */
1384 SYMBOL_NAME (sym
) = (char *)
1385 obstack_alloc (&objfile
->symbol_obstack
, nlen
);
1386 strncpy (SYMBOL_NAME (sym
), s
, nlen
);
1387 SYMBOL_NAME (sym
)[nlen
] = '\0';
1388 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
1391 /* FIXME! Want SYMBOL_NAME (sym) = 0;
1392 Get error if leave name 0. So give it something. */
1395 SYMBOL_NAME (sym
) = (char *)
1396 obstack_alloc (&objfile
->symbol_obstack
, nlen
);
1397 strncpy (SYMBOL_NAME (sym
), string
, nlen
);
1398 SYMBOL_NAME (sym
)[nlen
] = '\0';
1399 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
1402 /* Advance STRING beyond the reference id. */
1408 SYMBOL_LANGUAGE (sym
) = current_subfile
->language
;
1409 SYMBOL_NAME (sym
) = (char *)
1410 obstack_alloc (&objfile
->symbol_obstack
, ((p
- string
) + 1));
1411 /* Open-coded memcpy--saves function call time. */
1412 /* FIXME: Does it really? Try replacing with simple strcpy and
1413 try it on an executable with a large symbol table. */
1414 /* FIXME: considering that gcc can open code memcpy anyway, I
1415 doubt it. xoxorich. */
1417 register char *p1
= string
;
1418 register char *p2
= SYMBOL_NAME (sym
);
1426 /* If this symbol is from a C++ compilation, then attempt to cache the
1427 demangled form for future reference. This is a typical time versus
1428 space tradeoff, that was decided in favor of time because it sped up
1429 C++ symbol lookups by a factor of about 20. */
1431 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
1435 /* Determine the type of name being defined. */
1437 /* Getting GDB to correctly skip the symbol on an undefined symbol
1438 descriptor and not ever dump core is a very dodgy proposition if
1439 we do things this way. I say the acorn RISC machine can just
1440 fix their compiler. */
1441 /* The Acorn RISC machine's compiler can put out locals that don't
1442 start with "234=" or "(3,4)=", so assume anything other than the
1443 deftypes we know how to handle is a local. */
1444 if (!strchr ("cfFGpPrStTvVXCR", *p
))
1446 if (isdigit (*p
) || *p
== '(' || *p
== '-')
1455 /* c is a special case, not followed by a type-number.
1456 SYMBOL:c=iVALUE for an integer constant symbol.
1457 SYMBOL:c=rVALUE for a floating constant symbol.
1458 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
1459 e.g. "b:c=e6,0" for "const b = blob1"
1460 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
1463 SYMBOL_CLASS (sym
) = LOC_CONST
;
1464 SYMBOL_TYPE (sym
) = error_type (&p
, objfile
);
1465 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1466 add_symbol_to_list (sym
, &file_symbols
);
1474 double d
= atof (p
);
1477 /* FIXME-if-picky-about-floating-accuracy: Should be using
1478 target arithmetic to get the value. real.c in GCC
1479 probably has the necessary code. */
1481 /* FIXME: lookup_fundamental_type is a hack. We should be
1482 creating a type especially for the type of float constants.
1483 Problem is, what type should it be?
1485 Also, what should the name of this type be? Should we
1486 be using 'S' constants (see stabs.texinfo) instead? */
1488 SYMBOL_TYPE (sym
) = lookup_fundamental_type (objfile
,
1491 obstack_alloc (&objfile
->symbol_obstack
,
1492 TYPE_LENGTH (SYMBOL_TYPE (sym
)));
1493 store_floating (dbl_valu
, TYPE_LENGTH (SYMBOL_TYPE (sym
)), d
);
1494 SYMBOL_VALUE_BYTES (sym
) = dbl_valu
;
1495 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
1500 /* Defining integer constants this way is kind of silly,
1501 since 'e' constants allows the compiler to give not
1502 only the value, but the type as well. C has at least
1503 int, long, unsigned int, and long long as constant
1504 types; other languages probably should have at least
1505 unsigned as well as signed constants. */
1507 /* We just need one int constant type for all objfiles.
1508 It doesn't depend on languages or anything (arguably its
1509 name should be a language-specific name for a type of
1510 that size, but I'm inclined to say that if the compiler
1511 wants a nice name for the type, it can use 'e'). */
1512 static struct type
*int_const_type
;
1514 /* Yes, this is as long as a *host* int. That is because we
1516 if (int_const_type
== NULL
)
1518 init_type (TYPE_CODE_INT
,
1519 sizeof (int) * HOST_CHAR_BIT
/ TARGET_CHAR_BIT
, 0,
1521 (struct objfile
*) NULL
);
1522 SYMBOL_TYPE (sym
) = int_const_type
;
1523 SYMBOL_VALUE (sym
) = atoi (p
);
1524 SYMBOL_CLASS (sym
) = LOC_CONST
;
1528 /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value
1529 can be represented as integral.
1530 e.g. "b:c=e6,0" for "const b = blob1"
1531 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
1533 SYMBOL_CLASS (sym
) = LOC_CONST
;
1534 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1538 SYMBOL_TYPE (sym
) = error_type (&p
, objfile
);
1543 /* If the value is too big to fit in an int (perhaps because
1544 it is unsigned), or something like that, we silently get
1545 a bogus value. The type and everything else about it is
1546 correct. Ideally, we should be using whatever we have
1547 available for parsing unsigned and long long values,
1549 SYMBOL_VALUE (sym
) = atoi (p
);
1554 SYMBOL_CLASS (sym
) = LOC_CONST
;
1555 SYMBOL_TYPE (sym
) = error_type (&p
, objfile
);
1558 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1559 add_symbol_to_list (sym
, &file_symbols
);
1563 /* The name of a caught exception. */
1564 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1565 SYMBOL_CLASS (sym
) = LOC_LABEL
;
1566 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1567 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1568 add_symbol_to_list (sym
, &local_symbols
);
1572 /* A static function definition. */
1573 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1574 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1575 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1576 add_symbol_to_list (sym
, &file_symbols
);
1577 /* fall into process_function_types. */
1579 process_function_types
:
1580 /* Function result types are described as the result type in stabs.
1581 We need to convert this to the function-returning-type-X type
1582 in GDB. E.g. "int" is converted to "function returning int". */
1583 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_FUNC
)
1584 SYMBOL_TYPE (sym
) = lookup_function_type (SYMBOL_TYPE (sym
));
1586 /* All functions in C++ have prototypes. */
1587 if (SYMBOL_LANGUAGE (sym
) == language_cplus
)
1588 TYPE_FLAGS (SYMBOL_TYPE (sym
)) |= TYPE_FLAG_PROTOTYPED
;
1590 /* fall into process_prototype_types */
1592 process_prototype_types
:
1593 /* Sun acc puts declared types of arguments here. */
1596 struct type
*ftype
= SYMBOL_TYPE (sym
);
1601 /* Obtain a worst case guess for the number of arguments
1602 by counting the semicolons. */
1609 /* Allocate parameter information fields and fill them in. */
1610 TYPE_FIELDS (ftype
) = (struct field
*)
1611 TYPE_ALLOC (ftype
, nsemi
* sizeof (struct field
));
1616 /* A type number of zero indicates the start of varargs.
1617 FIXME: GDB currently ignores vararg functions. */
1618 if (p
[0] == '0' && p
[1] == '\0')
1620 ptype
= read_type (&p
, objfile
);
1622 /* The Sun compilers mark integer arguments, which should
1623 be promoted to the width of the calling conventions, with
1624 a type which references itself. This type is turned into
1625 a TYPE_CODE_VOID type by read_type, and we have to turn
1626 it back into builtin_type_int here.
1627 FIXME: Do we need a new builtin_type_promoted_int_arg ? */
1628 if (TYPE_CODE (ptype
) == TYPE_CODE_VOID
)
1629 ptype
= builtin_type_int
;
1630 TYPE_FIELD_TYPE (ftype
, nparams
++) = ptype
;
1632 TYPE_NFIELDS (ftype
) = nparams
;
1633 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
1638 /* A global function definition. */
1639 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1640 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1641 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1642 add_symbol_to_list (sym
, &global_symbols
);
1643 goto process_function_types
;
1646 /* For a class G (global) symbol, it appears that the
1647 value is not correct. It is necessary to search for the
1648 corresponding linker definition to find the value.
1649 These definitions appear at the end of the namelist. */
1650 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1651 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1652 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1653 /* Don't add symbol references to global_sym_chain.
1654 Symbol references don't have valid names and wont't match up with
1655 minimal symbols when the global_sym_chain is relocated.
1656 We'll fixup symbol references when we fixup the defining symbol. */
1657 if (SYMBOL_NAME (sym
) && SYMBOL_NAME (sym
)[0] != '#')
1659 i
= hashname (SYMBOL_NAME (sym
));
1660 SYMBOL_VALUE_CHAIN (sym
) = global_sym_chain
[i
];
1661 global_sym_chain
[i
] = sym
;
1663 add_symbol_to_list (sym
, &global_symbols
);
1666 /* This case is faked by a conditional above,
1667 when there is no code letter in the dbx data.
1668 Dbx data never actually contains 'l'. */
1671 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1672 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1673 SYMBOL_VALUE (sym
) = valu
;
1674 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1675 add_symbol_to_list (sym
, &local_symbols
);
1680 /* pF is a two-letter code that means a function parameter in Fortran.
1681 The type-number specifies the type of the return value.
1682 Translate it into a pointer-to-function type. */
1686 = lookup_pointer_type
1687 (lookup_function_type (read_type (&p
, objfile
)));
1690 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1692 /* Normally this is a parameter, a LOC_ARG. On the i960, it
1693 can also be a LOC_LOCAL_ARG depending on symbol type. */
1694 #ifndef DBX_PARM_SYMBOL_CLASS
1695 #define DBX_PARM_SYMBOL_CLASS(type) LOC_ARG
1698 SYMBOL_CLASS (sym
) = DBX_PARM_SYMBOL_CLASS (type
);
1699 SYMBOL_VALUE (sym
) = valu
;
1700 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1701 add_symbol_to_list (sym
, &local_symbols
);
1703 if (TARGET_BYTE_ORDER
!= BIG_ENDIAN
)
1705 /* On little-endian machines, this crud is never necessary,
1706 and, if the extra bytes contain garbage, is harmful. */
1710 /* If it's gcc-compiled, if it says `short', believe it. */
1711 if (processing_gcc_compilation
|| BELIEVE_PCC_PROMOTION
)
1714 if (!BELIEVE_PCC_PROMOTION
)
1716 /* This is the signed type which arguments get promoted to. */
1717 static struct type
*pcc_promotion_type
;
1718 /* This is the unsigned type which arguments get promoted to. */
1719 static struct type
*pcc_unsigned_promotion_type
;
1721 /* Call it "int" because this is mainly C lossage. */
1722 if (pcc_promotion_type
== NULL
)
1723 pcc_promotion_type
=
1724 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
1727 if (pcc_unsigned_promotion_type
== NULL
)
1728 pcc_unsigned_promotion_type
=
1729 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
1730 TYPE_FLAG_UNSIGNED
, "unsigned int", NULL
);
1732 if (BELIEVE_PCC_PROMOTION_TYPE
)
1734 /* This is defined on machines (e.g. sparc) where we
1735 should believe the type of a PCC 'short' argument,
1736 but shouldn't believe the address (the address is the
1737 address of the corresponding int).
1739 My guess is that this correction, as opposed to
1740 changing the parameter to an 'int' (as done below,
1741 for PCC on most machines), is the right thing to do
1742 on all machines, but I don't want to risk breaking
1743 something that already works. On most PCC machines,
1744 the sparc problem doesn't come up because the calling
1745 function has to zero the top bytes (not knowing
1746 whether the called function wants an int or a short),
1747 so there is little practical difference between an
1748 int and a short (except perhaps what happens when the
1749 GDB user types "print short_arg = 0x10000;").
1751 Hacked for SunOS 4.1 by gnu@cygnus.com. In 4.1, the
1752 compiler actually produces the correct address (we
1753 don't need to fix it up). I made this code adapt so
1754 that it will offset the symbol if it was pointing at
1755 an int-aligned location and not otherwise. This way
1756 you can use the same gdb for 4.0.x and 4.1 systems.
1758 If the parameter is shorter than an int, and is
1759 integral (e.g. char, short, or unsigned equivalent),
1760 and is claimed to be passed on an integer boundary,
1761 don't believe it! Offset the parameter's address to
1762 the tail-end of that integer. */
1764 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (pcc_promotion_type
)
1765 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
1766 && 0 == SYMBOL_VALUE (sym
) % TYPE_LENGTH (pcc_promotion_type
))
1768 SYMBOL_VALUE (sym
) += TYPE_LENGTH (pcc_promotion_type
)
1769 - TYPE_LENGTH (SYMBOL_TYPE (sym
));
1775 /* If PCC says a parameter is a short or a char,
1776 it is really an int. */
1777 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (pcc_promotion_type
)
1778 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
)
1781 TYPE_UNSIGNED (SYMBOL_TYPE (sym
))
1782 ? pcc_unsigned_promotion_type
1783 : pcc_promotion_type
;
1790 /* acc seems to use P to declare the prototypes of functions that
1791 are referenced by this file. gdb is not prepared to deal
1792 with this extra information. FIXME, it ought to. */
1795 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1796 goto process_prototype_types
;
1801 /* Parameter which is in a register. */
1802 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1803 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
1804 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
1805 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
1807 complain (®_value_complaint
, SYMBOL_VALUE (sym
), NUM_REGS
,
1808 SYMBOL_SOURCE_NAME (sym
));
1809 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
1811 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1812 add_symbol_to_list (sym
, &local_symbols
);
1816 /* Register variable (either global or local). */
1817 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1818 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
1819 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
1820 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
1822 complain (®_value_complaint
, SYMBOL_VALUE (sym
), NUM_REGS
,
1823 SYMBOL_SOURCE_NAME (sym
));
1824 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
1826 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1827 if (within_function
)
1829 /* Sun cc uses a pair of symbols, one 'p' and one 'r' with the same
1830 name to represent an argument passed in a register.
1831 GCC uses 'P' for the same case. So if we find such a symbol pair
1832 we combine it into one 'P' symbol. For Sun cc we need to do this
1833 regardless of REG_STRUCT_HAS_ADDR, because the compiler puts out
1834 the 'p' symbol even if it never saves the argument onto the stack.
1836 On most machines, we want to preserve both symbols, so that
1837 we can still get information about what is going on with the
1838 stack (VAX for computing args_printed, using stack slots instead
1839 of saved registers in backtraces, etc.).
1841 Note that this code illegally combines
1842 main(argc) struct foo argc; { register struct foo argc; }
1843 but this case is considered pathological and causes a warning
1844 from a decent compiler. */
1847 && local_symbols
->nsyms
> 0
1848 #ifndef USE_REGISTER_NOT_ARG
1849 && REG_STRUCT_HAS_ADDR_P ()
1850 && REG_STRUCT_HAS_ADDR (processing_gcc_compilation
,
1852 && (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
1853 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
1854 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_SET
1855 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_BITSTRING
)
1859 struct symbol
*prev_sym
;
1860 prev_sym
= local_symbols
->symbol
[local_symbols
->nsyms
- 1];
1861 if ((SYMBOL_CLASS (prev_sym
) == LOC_REF_ARG
1862 || SYMBOL_CLASS (prev_sym
) == LOC_ARG
)
1863 && STREQ (SYMBOL_NAME (prev_sym
), SYMBOL_NAME (sym
)))
1865 SYMBOL_CLASS (prev_sym
) = LOC_REGPARM
;
1866 /* Use the type from the LOC_REGISTER; that is the type
1867 that is actually in that register. */
1868 SYMBOL_TYPE (prev_sym
) = SYMBOL_TYPE (sym
);
1869 SYMBOL_VALUE (prev_sym
) = SYMBOL_VALUE (sym
);
1874 add_symbol_to_list (sym
, &local_symbols
);
1877 add_symbol_to_list (sym
, &file_symbols
);
1881 /* Static symbol at top level of file */
1882 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1883 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1884 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1885 #ifdef STATIC_TRANSFORM_NAME
1886 if (IS_STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym
)))
1888 struct minimal_symbol
*msym
;
1889 msym
= lookup_minimal_symbol (SYMBOL_NAME (sym
), NULL
, objfile
);
1892 SYMBOL_NAME (sym
) = STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym
));
1893 SYMBOL_VALUE_ADDRESS (sym
) = SYMBOL_VALUE_ADDRESS (msym
);
1897 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1898 add_symbol_to_list (sym
, &file_symbols
);
1902 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1904 /* For a nameless type, we don't want a create a symbol, thus we
1905 did not use `sym'. Return without further processing. */
1909 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1910 SYMBOL_VALUE (sym
) = valu
;
1911 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1912 /* C++ vagaries: we may have a type which is derived from
1913 a base type which did not have its name defined when the
1914 derived class was output. We fill in the derived class's
1915 base part member's name here in that case. */
1916 if (TYPE_NAME (SYMBOL_TYPE (sym
)) != NULL
)
1917 if ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
1918 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
)
1919 && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)))
1922 for (j
= TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)) - 1; j
>= 0; j
--)
1923 if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) == 0)
1924 TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) =
1925 type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym
), j
));
1928 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == NULL
)
1930 /* gcc-2.6 or later (when using -fvtable-thunks)
1931 emits a unique named type for a vtable entry.
1932 Some gdb code depends on that specific name. */
1933 extern const char vtbl_ptr_name
[];
1935 if ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_PTR
1936 && strcmp (SYMBOL_NAME (sym
), vtbl_ptr_name
))
1937 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_FUNC
)
1939 /* If we are giving a name to a type such as "pointer to
1940 foo" or "function returning foo", we better not set
1941 the TYPE_NAME. If the program contains "typedef char
1942 *caddr_t;", we don't want all variables of type char
1943 * to print as caddr_t. This is not just a
1944 consequence of GDB's type management; PCC and GCC (at
1945 least through version 2.4) both output variables of
1946 either type char * or caddr_t with the type number
1947 defined in the 't' symbol for caddr_t. If a future
1948 compiler cleans this up it GDB is not ready for it
1949 yet, but if it becomes ready we somehow need to
1950 disable this check (without breaking the PCC/GCC2.4
1955 Fortunately, this check seems not to be necessary
1956 for anything except pointers or functions. */
1957 /* ezannoni: 2000-10-26. This seems to apply for
1958 versions of gcc older than 2.8. This was the original
1959 problem: with the following code gdb would tell that
1960 the type for name1 is caddr_t, and func is char()
1961 typedef char *caddr_t;
1973 /* Pascal accepts names for pointer types. */
1974 if (current_subfile
->language
== language_pascal
)
1976 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_NAME (sym
);
1980 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_NAME (sym
);
1983 add_symbol_to_list (sym
, &file_symbols
);
1987 /* Struct, union, or enum tag. For GNU C++, this can be be followed
1988 by 't' which means we are typedef'ing it as well. */
1989 synonym
= *p
== 't';
1993 /* The semantics of C++ state that "struct foo { ... }" also defines
1994 a typedef for "foo". Unfortunately, cfront never makes the typedef
1995 when translating C++ into C. We make the typedef here so that
1996 "ptype foo" works as expected for cfront translated code. */
1997 else if (current_subfile
->language
== language_cplus
)
2000 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
2002 /* For a nameless type, we don't want a create a symbol, thus we
2003 did not use `sym'. Return without further processing. */
2007 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
2008 SYMBOL_VALUE (sym
) = valu
;
2009 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
2010 if (TYPE_TAG_NAME (SYMBOL_TYPE (sym
)) == 0)
2011 TYPE_TAG_NAME (SYMBOL_TYPE (sym
))
2012 = obconcat (&objfile
->type_obstack
, "", "", SYMBOL_NAME (sym
));
2013 add_symbol_to_list (sym
, &file_symbols
);
2017 /* Clone the sym and then modify it. */
2018 register struct symbol
*typedef_sym
= (struct symbol
*)
2019 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct symbol
));
2020 *typedef_sym
= *sym
;
2021 SYMBOL_CLASS (typedef_sym
) = LOC_TYPEDEF
;
2022 SYMBOL_VALUE (typedef_sym
) = valu
;
2023 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
2024 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
2025 TYPE_NAME (SYMBOL_TYPE (sym
))
2026 = obconcat (&objfile
->type_obstack
, "", "", SYMBOL_NAME (sym
));
2027 add_symbol_to_list (typedef_sym
, &file_symbols
);
2032 /* Static symbol of local scope */
2033 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
2034 SYMBOL_CLASS (sym
) = LOC_STATIC
;
2035 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
2036 #ifdef STATIC_TRANSFORM_NAME
2037 if (IS_STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym
)))
2039 struct minimal_symbol
*msym
;
2040 msym
= lookup_minimal_symbol (SYMBOL_NAME (sym
), NULL
, objfile
);
2043 SYMBOL_NAME (sym
) = STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym
));
2044 SYMBOL_VALUE_ADDRESS (sym
) = SYMBOL_VALUE_ADDRESS (msym
);
2048 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2050 add_symbol_to_list (sym
, &global_symbols
);
2052 add_symbol_to_list (sym
, &local_symbols
);
2056 /* Reference parameter */
2057 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
2058 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
2059 SYMBOL_VALUE (sym
) = valu
;
2060 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2061 add_symbol_to_list (sym
, &local_symbols
);
2065 /* Reference parameter which is in a register. */
2066 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
2067 SYMBOL_CLASS (sym
) = LOC_REGPARM_ADDR
;
2068 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
2069 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
2071 complain (®_value_complaint
, SYMBOL_VALUE (sym
), NUM_REGS
,
2072 SYMBOL_SOURCE_NAME (sym
));
2073 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
2075 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2076 add_symbol_to_list (sym
, &local_symbols
);
2080 /* This is used by Sun FORTRAN for "function result value".
2081 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
2082 that Pascal uses it too, but when I tried it Pascal used
2083 "x:3" (local symbol) instead. */
2084 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
2085 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
2086 SYMBOL_VALUE (sym
) = valu
;
2087 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2088 add_symbol_to_list (sym
, &local_symbols
);
2091 /* New code added to support cfront stabs strings.
2092 Note: case 'P' already handled above */
2094 /* Cfront type continuation coming up!
2095 Find the original definition and add to it.
2096 We'll have to do this for the typedef too,
2097 since we cloned the symbol to define a type in read_type.
2098 Stabs info examples:
2100 foo__1CFv :ZtF (first def foo__1CFv:F(0,3);(0,24))
2101 C:ZsC;;__ct__1CFv func1__1CFv func2__1CFv ... ;;;
2102 where C is the name of the class.
2103 Unfortunately, we can't lookup the original symbol yet 'cuz
2104 we haven't finished reading all the symbols.
2105 Instead, we save it for processing later */
2106 process_later (sym
, p
, resolve_cfront_continuation
);
2107 SYMBOL_TYPE (sym
) = error_type (&p
, objfile
); /* FIXME! change later */
2108 SYMBOL_CLASS (sym
) = LOC_CONST
;
2109 SYMBOL_VALUE (sym
) = 0;
2110 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2111 /* Don't add to list - we'll delete it later when
2112 we add the continuation to the real sym */
2114 /* End of new code added to support cfront stabs strings */
2117 SYMBOL_TYPE (sym
) = error_type (&p
, objfile
);
2118 SYMBOL_CLASS (sym
) = LOC_CONST
;
2119 SYMBOL_VALUE (sym
) = 0;
2120 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2121 add_symbol_to_list (sym
, &file_symbols
);
2125 /* When passing structures to a function, some systems sometimes pass
2126 the address in a register, not the structure itself. */
2128 if (REG_STRUCT_HAS_ADDR_P ()
2129 && REG_STRUCT_HAS_ADDR (processing_gcc_compilation
, SYMBOL_TYPE (sym
))
2130 && (SYMBOL_CLASS (sym
) == LOC_REGPARM
|| SYMBOL_CLASS (sym
) == LOC_ARG
))
2132 struct type
*symbol_type
= check_typedef (SYMBOL_TYPE (sym
));
2134 if ((TYPE_CODE (symbol_type
) == TYPE_CODE_STRUCT
)
2135 || (TYPE_CODE (symbol_type
) == TYPE_CODE_UNION
)
2136 || (TYPE_CODE (symbol_type
) == TYPE_CODE_BITSTRING
)
2137 || (TYPE_CODE (symbol_type
) == TYPE_CODE_SET
))
2139 /* If REG_STRUCT_HAS_ADDR yields non-zero we have to convert
2140 LOC_REGPARM to LOC_REGPARM_ADDR for structures and unions. */
2141 if (SYMBOL_CLASS (sym
) == LOC_REGPARM
)
2142 SYMBOL_CLASS (sym
) = LOC_REGPARM_ADDR
;
2143 /* Likewise for converting LOC_ARG to LOC_REF_ARG (for the 7th
2144 and subsequent arguments on the sparc, for example). */
2145 else if (SYMBOL_CLASS (sym
) == LOC_ARG
)
2146 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
2150 /* Is there more to parse? For example LRS/alias information? */
2151 while (*p
&& *p
== ';')
2154 if (*p
&& p
[0] == 'l' && p
[1] == '(')
2156 /* GNU extensions for live range splitting may be appended to
2157 the end of the stab string. eg. "l(#1,#2);l(#3,#5)" */
2159 /* Resolve the live range and add it to SYM's live range list. */
2160 if (!resolve_live_range (objfile
, sym
, p
))
2163 /* Find end of live range info. */
2164 p
= strchr (p
, ')');
2165 if (!*p
|| *p
!= ')')
2167 complain (&lrs_general_complaint
, "live range format not recognized");
2176 /* Add the live range found in P to the symbol SYM in objfile OBJFILE. Returns
2177 non-zero on success, zero otherwise. */
2180 resolve_live_range (struct objfile
*objfile
, struct symbol
*sym
, char *p
)
2183 CORE_ADDR start
, end
;
2185 /* Sanity check the beginning of the stabs string. */
2186 if (!*p
|| *p
!= 'l')
2188 complain (&lrs_general_complaint
, "live range string 1");
2193 if (!*p
|| *p
!= '(')
2195 complain (&lrs_general_complaint
, "live range string 2");
2200 /* Get starting value of range and advance P past the reference id.
2202 ?!? In theory, the process_reference should never fail, but we should
2203 catch that case just in case the compiler scrogged the stabs. */
2204 refnum
= process_reference (&p
);
2205 start
= ref_search_value (refnum
);
2208 complain (&lrs_general_complaint
, "Live range symbol not found 1");
2212 if (!*p
|| *p
!= ',')
2214 complain (&lrs_general_complaint
, "live range string 3");
2219 /* Get ending value of range and advance P past the reference id.
2221 ?!? In theory, the process_reference should never fail, but we should
2222 catch that case just in case the compiler scrogged the stabs. */
2223 refnum
= process_reference (&p
);
2224 end
= ref_search_value (refnum
);
2227 complain (&lrs_general_complaint
, "Live range symbol not found 2");
2231 if (!*p
|| *p
!= ')')
2233 complain (&lrs_general_complaint
, "live range string 4");
2237 /* Now that we know the bounds of the range, add it to the
2239 add_live_range (objfile
, sym
, start
, end
);
2244 /* Add a new live range defined by START and END to the symbol SYM
2245 in objfile OBJFILE. */
2248 add_live_range (struct objfile
*objfile
, struct symbol
*sym
, CORE_ADDR start
,
2251 struct range_list
*r
, *rs
;
2255 complain (&lrs_general_complaint
, "end of live range follows start");
2259 /* Alloc new live range structure. */
2260 r
= (struct range_list
*)
2261 obstack_alloc (&objfile
->type_obstack
,
2262 sizeof (struct range_list
));
2267 /* Append this range to the symbol's range list. */
2268 if (!SYMBOL_RANGES (sym
))
2269 SYMBOL_RANGES (sym
) = r
;
2272 /* Get the last range for the symbol. */
2273 for (rs
= SYMBOL_RANGES (sym
); rs
->next
; rs
= rs
->next
)
2280 /* Skip rest of this symbol and return an error type.
2282 General notes on error recovery: error_type always skips to the
2283 end of the symbol (modulo cretinous dbx symbol name continuation).
2284 Thus code like this:
2286 if (*(*pp)++ != ';')
2287 return error_type (pp, objfile);
2289 is wrong because if *pp starts out pointing at '\0' (typically as the
2290 result of an earlier error), it will be incremented to point to the
2291 start of the next symbol, which might produce strange results, at least
2292 if you run off the end of the string table. Instead use
2295 return error_type (pp, objfile);
2301 foo = error_type (pp, objfile);
2305 And in case it isn't obvious, the point of all this hair is so the compiler
2306 can define new types and new syntaxes, and old versions of the
2307 debugger will be able to read the new symbol tables. */
2309 static struct type
*
2310 error_type (char **pp
, struct objfile
*objfile
)
2312 complain (&error_type_complaint
);
2315 /* Skip to end of symbol. */
2316 while (**pp
!= '\0')
2321 /* Check for and handle cretinous dbx symbol name continuation! */
2322 if ((*pp
)[-1] == '\\' || (*pp
)[-1] == '?')
2324 *pp
= next_symbol_text (objfile
);
2331 return (builtin_type_error
);
2335 /* Read type information or a type definition; return the type. Even
2336 though this routine accepts either type information or a type
2337 definition, the distinction is relevant--some parts of stabsread.c
2338 assume that type information starts with a digit, '-', or '(' in
2339 deciding whether to call read_type. */
2342 read_type (register char **pp
, struct objfile
*objfile
)
2344 register struct type
*type
= 0;
2347 char type_descriptor
;
2349 /* Size in bits of type if specified by a type attribute, or -1 if
2350 there is no size attribute. */
2353 /* Used to distinguish string and bitstring from char-array and set. */
2356 /* Read type number if present. The type number may be omitted.
2357 for instance in a two-dimensional array declared with type
2358 "ar1;1;10;ar1;1;10;4". */
2359 if ((**pp
>= '0' && **pp
<= '9')
2363 if (read_type_number (pp
, typenums
) != 0)
2364 return error_type (pp
, objfile
);
2366 /* Type is not being defined here. Either it already exists,
2367 or this is a forward reference to it. dbx_alloc_type handles
2370 return dbx_alloc_type (typenums
, objfile
);
2372 /* Type is being defined here. */
2374 Also skip the type descriptor - we get it below with (*pp)[-1]. */
2379 /* 'typenums=' not present, type is anonymous. Read and return
2380 the definition, but don't put it in the type vector. */
2381 typenums
[0] = typenums
[1] = -1;
2386 type_descriptor
= (*pp
)[-1];
2387 switch (type_descriptor
)
2391 enum type_code code
;
2393 /* Used to index through file_symbols. */
2394 struct pending
*ppt
;
2397 /* Name including "struct", etc. */
2401 char *from
, *to
, *p
, *q1
, *q2
;
2403 /* Set the type code according to the following letter. */
2407 code
= TYPE_CODE_STRUCT
;
2410 code
= TYPE_CODE_UNION
;
2413 code
= TYPE_CODE_ENUM
;
2417 /* Complain and keep going, so compilers can invent new
2418 cross-reference types. */
2419 static struct complaint msg
=
2420 {"Unrecognized cross-reference type `%c'", 0, 0};
2421 complain (&msg
, (*pp
)[0]);
2422 code
= TYPE_CODE_STRUCT
;
2427 q1
= strchr (*pp
, '<');
2428 p
= strchr (*pp
, ':');
2430 return error_type (pp
, objfile
);
2431 if (q1
&& p
> q1
&& p
[1] == ':')
2433 int nesting_level
= 0;
2434 for (q2
= q1
; *q2
; q2
++)
2438 else if (*q2
== '>')
2440 else if (*q2
== ':' && nesting_level
== 0)
2445 return error_type (pp
, objfile
);
2448 (char *) obstack_alloc (&objfile
->type_obstack
, p
- *pp
+ 1);
2450 /* Copy the name. */
2456 /* Set the pointer ahead of the name which we just read, and
2461 /* Now check to see whether the type has already been
2462 declared. This was written for arrays of cross-referenced
2463 types before we had TYPE_CODE_TARGET_STUBBED, so I'm pretty
2464 sure it is not necessary anymore. But it might be a good
2465 idea, to save a little memory. */
2467 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
2468 for (i
= 0; i
< ppt
->nsyms
; i
++)
2470 struct symbol
*sym
= ppt
->symbol
[i
];
2472 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
2473 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
2474 && (TYPE_CODE (SYMBOL_TYPE (sym
)) == code
)
2475 && STREQ (SYMBOL_NAME (sym
), type_name
))
2477 obstack_free (&objfile
->type_obstack
, type_name
);
2478 type
= SYMBOL_TYPE (sym
);
2483 /* Didn't find the type to which this refers, so we must
2484 be dealing with a forward reference. Allocate a type
2485 structure for it, and keep track of it so we can
2486 fill in the rest of the fields when we get the full
2488 type
= dbx_alloc_type (typenums
, objfile
);
2489 TYPE_CODE (type
) = code
;
2490 TYPE_TAG_NAME (type
) = type_name
;
2491 INIT_CPLUS_SPECIFIC (type
);
2492 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
2494 add_undefined_type (type
);
2498 case '-': /* RS/6000 built-in type */
2512 /* We deal with something like t(1,2)=(3,4)=... which
2513 the Lucid compiler and recent gcc versions (post 2.7.3) use. */
2515 /* Allocate and enter the typedef type first.
2516 This handles recursive types. */
2517 type
= dbx_alloc_type (typenums
, objfile
);
2518 TYPE_CODE (type
) = TYPE_CODE_TYPEDEF
;
2520 struct type
*xtype
= read_type (pp
, objfile
);
2523 /* It's being defined as itself. That means it is "void". */
2524 TYPE_CODE (type
) = TYPE_CODE_VOID
;
2525 TYPE_LENGTH (type
) = 1;
2527 else if (type_size
>= 0 || is_string
)
2530 TYPE_NAME (type
) = NULL
;
2531 TYPE_TAG_NAME (type
) = NULL
;
2535 TYPE_FLAGS (type
) |= TYPE_FLAG_TARGET_STUB
;
2536 TYPE_TARGET_TYPE (type
) = xtype
;
2541 /* In the following types, we must be sure to overwrite any existing
2542 type that the typenums refer to, rather than allocating a new one
2543 and making the typenums point to the new one. This is because there
2544 may already be pointers to the existing type (if it had been
2545 forward-referenced), and we must change it to a pointer, function,
2546 reference, or whatever, *in-place*. */
2549 type1
= read_type (pp
, objfile
);
2550 type
= make_pointer_type (type1
, dbx_lookup_type (typenums
));
2553 case '&': /* Reference to another type */
2554 type1
= read_type (pp
, objfile
);
2555 type
= make_reference_type (type1
, dbx_lookup_type (typenums
));
2558 case 'f': /* Function returning another type */
2559 if (os9k_stabs
&& **pp
== '(')
2561 /* Function prototype; parse it.
2562 We must conditionalize this on os9k_stabs because otherwise
2563 it could be confused with a Sun-style (1,3) typenumber
2569 t
= read_type (pp
, objfile
);
2574 type1
= read_type (pp
, objfile
);
2575 type
= make_function_type (type1
, dbx_lookup_type (typenums
));
2578 case 'k': /* Const qualifier on some type (Sun) */
2579 case 'c': /* Const qualifier on some type (OS9000) */
2580 /* Because 'c' means other things to AIX and 'k' is perfectly good,
2581 only accept 'c' in the os9k_stabs case. */
2582 if (type_descriptor
== 'c' && !os9k_stabs
)
2583 return error_type (pp
, objfile
);
2584 type
= read_type (pp
, objfile
);
2585 /* FIXME! For now, we ignore const and volatile qualifiers. */
2588 case 'B': /* Volatile qual on some type (Sun) */
2589 case 'i': /* Volatile qual on some type (OS9000) */
2590 /* Because 'i' means other things to AIX and 'B' is perfectly good,
2591 only accept 'i' in the os9k_stabs case. */
2592 if (type_descriptor
== 'i' && !os9k_stabs
)
2593 return error_type (pp
, objfile
);
2594 type
= read_type (pp
, objfile
);
2595 /* FIXME! For now, we ignore const and volatile qualifiers. */
2599 if (isdigit (**pp
) || **pp
== '(' || **pp
== '-')
2600 { /* Member (class & variable) type */
2601 /* FIXME -- we should be doing smash_to_XXX types here. */
2603 struct type
*domain
= read_type (pp
, objfile
);
2604 struct type
*memtype
;
2607 /* Invalid member type data format. */
2608 return error_type (pp
, objfile
);
2611 memtype
= read_type (pp
, objfile
);
2612 type
= dbx_alloc_type (typenums
, objfile
);
2613 smash_to_member_type (type
, domain
, memtype
);
2616 /* type attribute */
2619 /* Skip to the semicolon. */
2620 while (**pp
!= ';' && **pp
!= '\0')
2623 return error_type (pp
, objfile
);
2625 ++ * pp
; /* Skip the semicolon. */
2630 type_size
= atoi (attr
+ 1);
2640 /* Ignore unrecognized type attributes, so future compilers
2641 can invent new ones. */
2649 case '#': /* Method (class & fn) type */
2650 if ((*pp
)[0] == '#')
2652 /* We'll get the parameter types from the name. */
2653 struct type
*return_type
;
2656 return_type
= read_type (pp
, objfile
);
2657 if (*(*pp
)++ != ';')
2658 complain (&invalid_member_complaint
, symnum
);
2659 type
= allocate_stub_method (return_type
);
2660 if (typenums
[0] != -1)
2661 *dbx_lookup_type (typenums
) = type
;
2665 struct type
*domain
= read_type (pp
, objfile
);
2666 struct type
*return_type
;
2670 /* Invalid member type data format. */
2671 return error_type (pp
, objfile
);
2675 return_type
= read_type (pp
, objfile
);
2676 args
= read_args (pp
, ';', objfile
);
2677 type
= dbx_alloc_type (typenums
, objfile
);
2678 smash_to_method_type (type
, domain
, return_type
, args
);
2682 case 'r': /* Range type */
2683 type
= read_range_type (pp
, typenums
, objfile
);
2684 if (typenums
[0] != -1)
2685 *dbx_lookup_type (typenums
) = type
;
2690 /* Const and volatile qualified type. */
2691 type
= read_type (pp
, objfile
);
2694 /* Sun ACC builtin int type */
2695 type
= read_sun_builtin_type (pp
, typenums
, objfile
);
2696 if (typenums
[0] != -1)
2697 *dbx_lookup_type (typenums
) = type
;
2701 case 'R': /* Sun ACC builtin float type */
2702 type
= read_sun_floating_type (pp
, typenums
, objfile
);
2703 if (typenums
[0] != -1)
2704 *dbx_lookup_type (typenums
) = type
;
2707 case 'e': /* Enumeration type */
2708 type
= dbx_alloc_type (typenums
, objfile
);
2709 type
= read_enum_type (pp
, type
, objfile
);
2710 if (typenums
[0] != -1)
2711 *dbx_lookup_type (typenums
) = type
;
2714 case 's': /* Struct type */
2715 case 'u': /* Union type */
2716 type
= dbx_alloc_type (typenums
, objfile
);
2717 switch (type_descriptor
)
2720 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
2723 TYPE_CODE (type
) = TYPE_CODE_UNION
;
2726 type
= read_struct_type (pp
, type
, objfile
);
2729 case 'a': /* Array type */
2731 return error_type (pp
, objfile
);
2734 type
= dbx_alloc_type (typenums
, objfile
);
2735 type
= read_array_type (pp
, type
, objfile
);
2737 TYPE_CODE (type
) = TYPE_CODE_STRING
;
2741 type1
= read_type (pp
, objfile
);
2742 type
= create_set_type ((struct type
*) NULL
, type1
);
2744 TYPE_CODE (type
) = TYPE_CODE_BITSTRING
;
2745 if (typenums
[0] != -1)
2746 *dbx_lookup_type (typenums
) = type
;
2750 --*pp
; /* Go back to the symbol in error */
2751 /* Particularly important if it was \0! */
2752 return error_type (pp
, objfile
);
2757 warning ("GDB internal error, type is NULL in stabsread.c\n");
2758 return error_type (pp
, objfile
);
2761 /* Size specified in a type attribute overrides any other size. */
2762 if (type_size
!= -1)
2763 TYPE_LENGTH (type
) = (type_size
+ TARGET_CHAR_BIT
- 1) / TARGET_CHAR_BIT
;
2768 /* RS/6000 xlc/dbx combination uses a set of builtin types, starting from -1.
2769 Return the proper type node for a given builtin type number. */
2771 static struct type
*
2772 rs6000_builtin_type (int typenum
)
2774 /* We recognize types numbered from -NUMBER_RECOGNIZED to -1. */
2775 #define NUMBER_RECOGNIZED 34
2776 /* This includes an empty slot for type number -0. */
2777 static struct type
*negative_types
[NUMBER_RECOGNIZED
+ 1];
2778 struct type
*rettype
= NULL
;
2780 if (typenum
>= 0 || typenum
< -NUMBER_RECOGNIZED
)
2782 complain (&rs6000_builtin_complaint
, typenum
);
2783 return builtin_type_error
;
2785 if (negative_types
[-typenum
] != NULL
)
2786 return negative_types
[-typenum
];
2788 #if TARGET_CHAR_BIT != 8
2789 #error This code wrong for TARGET_CHAR_BIT not 8
2790 /* These definitions all assume that TARGET_CHAR_BIT is 8. I think
2791 that if that ever becomes not true, the correct fix will be to
2792 make the size in the struct type to be in bits, not in units of
2799 /* The size of this and all the other types are fixed, defined
2800 by the debugging format. If there is a type called "int" which
2801 is other than 32 bits, then it should use a new negative type
2802 number (or avoid negative type numbers for that case).
2803 See stabs.texinfo. */
2804 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "int", NULL
);
2807 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "char", NULL
);
2810 rettype
= init_type (TYPE_CODE_INT
, 2, 0, "short", NULL
);
2813 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "long", NULL
);
2816 rettype
= init_type (TYPE_CODE_INT
, 1, TYPE_FLAG_UNSIGNED
,
2817 "unsigned char", NULL
);
2820 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "signed char", NULL
);
2823 rettype
= init_type (TYPE_CODE_INT
, 2, TYPE_FLAG_UNSIGNED
,
2824 "unsigned short", NULL
);
2827 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
2828 "unsigned int", NULL
);
2831 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
2834 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
2835 "unsigned long", NULL
);
2838 rettype
= init_type (TYPE_CODE_VOID
, 1, 0, "void", NULL
);
2841 /* IEEE single precision (32 bit). */
2842 rettype
= init_type (TYPE_CODE_FLT
, 4, 0, "float", NULL
);
2845 /* IEEE double precision (64 bit). */
2846 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "double", NULL
);
2849 /* This is an IEEE double on the RS/6000, and different machines with
2850 different sizes for "long double" should use different negative
2851 type numbers. See stabs.texinfo. */
2852 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "long double", NULL
);
2855 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "integer", NULL
);
2858 rettype
= init_type (TYPE_CODE_BOOL
, 4, TYPE_FLAG_UNSIGNED
,
2862 rettype
= init_type (TYPE_CODE_FLT
, 4, 0, "short real", NULL
);
2865 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "real", NULL
);
2868 rettype
= init_type (TYPE_CODE_ERROR
, 0, 0, "stringptr", NULL
);
2871 rettype
= init_type (TYPE_CODE_CHAR
, 1, TYPE_FLAG_UNSIGNED
,
2875 rettype
= init_type (TYPE_CODE_BOOL
, 1, TYPE_FLAG_UNSIGNED
,
2879 rettype
= init_type (TYPE_CODE_BOOL
, 2, TYPE_FLAG_UNSIGNED
,
2883 rettype
= init_type (TYPE_CODE_BOOL
, 4, TYPE_FLAG_UNSIGNED
,
2887 rettype
= init_type (TYPE_CODE_BOOL
, 4, TYPE_FLAG_UNSIGNED
,
2891 /* Complex type consisting of two IEEE single precision values. */
2892 rettype
= init_type (TYPE_CODE_COMPLEX
, 8, 0, "complex", NULL
);
2895 /* Complex type consisting of two IEEE double precision values. */
2896 rettype
= init_type (TYPE_CODE_COMPLEX
, 16, 0, "double complex", NULL
);
2899 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "integer*1", NULL
);
2902 rettype
= init_type (TYPE_CODE_INT
, 2, 0, "integer*2", NULL
);
2905 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "integer*4", NULL
);
2908 rettype
= init_type (TYPE_CODE_CHAR
, 2, 0, "wchar", NULL
);
2911 rettype
= init_type (TYPE_CODE_INT
, 8, 0, "long long", NULL
);
2914 rettype
= init_type (TYPE_CODE_INT
, 8, TYPE_FLAG_UNSIGNED
,
2915 "unsigned long long", NULL
);
2918 rettype
= init_type (TYPE_CODE_INT
, 8, TYPE_FLAG_UNSIGNED
,
2922 rettype
= init_type (TYPE_CODE_INT
, 8, 0, "integer*8", NULL
);
2925 negative_types
[-typenum
] = rettype
;
2929 /* This page contains subroutines of read_type. */
2931 /* Read member function stabs info for C++ classes. The form of each member
2934 NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
2936 An example with two member functions is:
2938 afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
2940 For the case of overloaded operators, the format is op$::*.funcs, where
2941 $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
2942 name (such as `+=') and `.' marks the end of the operator name.
2944 Returns 1 for success, 0 for failure. */
2947 read_member_functions (struct field_info
*fip
, char **pp
, struct type
*type
,
2948 struct objfile
*objfile
)
2952 /* Total number of member functions defined in this class. If the class
2953 defines two `f' functions, and one `g' function, then this will have
2955 int total_length
= 0;
2959 struct next_fnfield
*next
;
2960 struct fn_field fn_field
;
2963 struct type
*look_ahead_type
;
2964 struct next_fnfieldlist
*new_fnlist
;
2965 struct next_fnfield
*new_sublist
;
2969 /* Process each list until we find something that is not a member function
2970 or find the end of the functions. */
2974 /* We should be positioned at the start of the function name.
2975 Scan forward to find the first ':' and if it is not the
2976 first of a "::" delimiter, then this is not a member function. */
2988 look_ahead_type
= NULL
;
2991 new_fnlist
= (struct next_fnfieldlist
*)
2992 xmalloc (sizeof (struct next_fnfieldlist
));
2993 make_cleanup (xfree
, new_fnlist
);
2994 memset (new_fnlist
, 0, sizeof (struct next_fnfieldlist
));
2996 if ((*pp
)[0] == 'o' && (*pp
)[1] == 'p' && is_cplus_marker ((*pp
)[2]))
2998 /* This is a completely wierd case. In order to stuff in the
2999 names that might contain colons (the usual name delimiter),
3000 Mike Tiemann defined a different name format which is
3001 signalled if the identifier is "op$". In that case, the
3002 format is "op$::XXXX." where XXXX is the name. This is
3003 used for names like "+" or "=". YUUUUUUUK! FIXME! */
3004 /* This lets the user type "break operator+".
3005 We could just put in "+" as the name, but that wouldn't
3007 static char opname
[32] =
3008 {'o', 'p', CPLUS_MARKER
};
3009 char *o
= opname
+ 3;
3011 /* Skip past '::'. */
3014 STABS_CONTINUE (pp
, objfile
);
3020 main_fn_name
= savestring (opname
, o
- opname
);
3026 main_fn_name
= savestring (*pp
, p
- *pp
);
3027 /* Skip past '::'. */
3030 new_fnlist
->fn_fieldlist
.name
= main_fn_name
;
3035 (struct next_fnfield
*) xmalloc (sizeof (struct next_fnfield
));
3036 make_cleanup (xfree
, new_sublist
);
3037 memset (new_sublist
, 0, sizeof (struct next_fnfield
));
3039 /* Check for and handle cretinous dbx symbol name continuation! */
3040 if (look_ahead_type
== NULL
)
3043 STABS_CONTINUE (pp
, objfile
);
3045 new_sublist
->fn_field
.type
= read_type (pp
, objfile
);
3048 /* Invalid symtab info for member function. */
3054 /* g++ version 1 kludge */
3055 new_sublist
->fn_field
.type
= look_ahead_type
;
3056 look_ahead_type
= NULL
;
3066 /* If this is just a stub, then we don't have the real name here. */
3068 if (TYPE_FLAGS (new_sublist
->fn_field
.type
) & TYPE_FLAG_STUB
)
3070 if (!TYPE_DOMAIN_TYPE (new_sublist
->fn_field
.type
))
3071 TYPE_DOMAIN_TYPE (new_sublist
->fn_field
.type
) = type
;
3072 new_sublist
->fn_field
.is_stub
= 1;
3074 new_sublist
->fn_field
.physname
= savestring (*pp
, p
- *pp
);
3077 /* Set this member function's visibility fields. */
3080 case VISIBILITY_PRIVATE
:
3081 new_sublist
->fn_field
.is_private
= 1;
3083 case VISIBILITY_PROTECTED
:
3084 new_sublist
->fn_field
.is_protected
= 1;
3088 STABS_CONTINUE (pp
, objfile
);
3091 case 'A': /* Normal functions. */
3092 new_sublist
->fn_field
.is_const
= 0;
3093 new_sublist
->fn_field
.is_volatile
= 0;
3096 case 'B': /* `const' member functions. */
3097 new_sublist
->fn_field
.is_const
= 1;
3098 new_sublist
->fn_field
.is_volatile
= 0;
3101 case 'C': /* `volatile' member function. */
3102 new_sublist
->fn_field
.is_const
= 0;
3103 new_sublist
->fn_field
.is_volatile
= 1;
3106 case 'D': /* `const volatile' member function. */
3107 new_sublist
->fn_field
.is_const
= 1;
3108 new_sublist
->fn_field
.is_volatile
= 1;
3111 case '*': /* File compiled with g++ version 1 -- no info */
3116 complain (&const_vol_complaint
, **pp
);
3125 /* virtual member function, followed by index.
3126 The sign bit is set to distinguish pointers-to-methods
3127 from virtual function indicies. Since the array is
3128 in words, the quantity must be shifted left by 1
3129 on 16 bit machine, and by 2 on 32 bit machine, forcing
3130 the sign bit out, and usable as a valid index into
3131 the array. Remove the sign bit here. */
3132 new_sublist
->fn_field
.voffset
=
3133 (0x7fffffff & read_huge_number (pp
, ';', &nbits
)) + 2;
3137 STABS_CONTINUE (pp
, objfile
);
3138 if (**pp
== ';' || **pp
== '\0')
3140 /* Must be g++ version 1. */
3141 new_sublist
->fn_field
.fcontext
= 0;
3145 /* Figure out from whence this virtual function came.
3146 It may belong to virtual function table of
3147 one of its baseclasses. */
3148 look_ahead_type
= read_type (pp
, objfile
);
3151 /* g++ version 1 overloaded methods. */
3155 new_sublist
->fn_field
.fcontext
= look_ahead_type
;
3164 look_ahead_type
= NULL
;
3170 /* static member function. */
3171 new_sublist
->fn_field
.voffset
= VOFFSET_STATIC
;
3172 if (strncmp (new_sublist
->fn_field
.physname
,
3173 main_fn_name
, strlen (main_fn_name
)))
3175 new_sublist
->fn_field
.is_stub
= 1;
3181 complain (&member_fn_complaint
, (*pp
)[-1]);
3182 /* Fall through into normal member function. */
3185 /* normal member function. */
3186 new_sublist
->fn_field
.voffset
= 0;
3187 new_sublist
->fn_field
.fcontext
= 0;
3191 new_sublist
->next
= sublist
;
3192 sublist
= new_sublist
;
3194 STABS_CONTINUE (pp
, objfile
);
3196 while (**pp
!= ';' && **pp
!= '\0');
3200 new_fnlist
->fn_fieldlist
.fn_fields
= (struct fn_field
*)
3201 obstack_alloc (&objfile
->type_obstack
,
3202 sizeof (struct fn_field
) * length
);
3203 memset (new_fnlist
->fn_fieldlist
.fn_fields
, 0,
3204 sizeof (struct fn_field
) * length
);
3205 for (i
= length
; (i
--, sublist
); sublist
= sublist
->next
)
3207 new_fnlist
->fn_fieldlist
.fn_fields
[i
] = sublist
->fn_field
;
3210 new_fnlist
->fn_fieldlist
.length
= length
;
3211 new_fnlist
->next
= fip
->fnlist
;
3212 fip
->fnlist
= new_fnlist
;
3214 total_length
+= length
;
3215 STABS_CONTINUE (pp
, objfile
);
3220 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3221 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
3222 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * nfn_fields
);
3223 memset (TYPE_FN_FIELDLISTS (type
), 0,
3224 sizeof (struct fn_fieldlist
) * nfn_fields
);
3225 TYPE_NFN_FIELDS (type
) = nfn_fields
;
3226 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
3232 /* Special GNU C++ name.
3234 Returns 1 for success, 0 for failure. "failure" means that we can't
3235 keep parsing and it's time for error_type(). */
3238 read_cpp_abbrev (struct field_info
*fip
, char **pp
, struct type
*type
,
3239 struct objfile
*objfile
)
3244 struct type
*context
;
3254 /* At this point, *pp points to something like "22:23=*22...",
3255 where the type number before the ':' is the "context" and
3256 everything after is a regular type definition. Lookup the
3257 type, find it's name, and construct the field name. */
3259 context
= read_type (pp
, objfile
);
3263 case 'f': /* $vf -- a virtual function table pointer */
3264 fip
->list
->field
.name
=
3265 obconcat (&objfile
->type_obstack
, vptr_name
, "", "");
3268 case 'b': /* $vb -- a virtual bsomethingorother */
3269 name
= type_name_no_tag (context
);
3272 complain (&invalid_cpp_type_complaint
, symnum
);
3275 fip
->list
->field
.name
=
3276 obconcat (&objfile
->type_obstack
, vb_name
, name
, "");
3280 complain (&invalid_cpp_abbrev_complaint
, *pp
);
3281 fip
->list
->field
.name
=
3282 obconcat (&objfile
->type_obstack
,
3283 "INVALID_CPLUSPLUS_ABBREV", "", "");
3287 /* At this point, *pp points to the ':'. Skip it and read the
3293 complain (&invalid_cpp_abbrev_complaint
, *pp
);
3296 fip
->list
->field
.type
= read_type (pp
, objfile
);
3298 (*pp
)++; /* Skip the comma. */
3304 FIELD_BITPOS (fip
->list
->field
) = read_huge_number (pp
, ';', &nbits
);
3308 /* This field is unpacked. */
3309 FIELD_BITSIZE (fip
->list
->field
) = 0;
3310 fip
->list
->visibility
= VISIBILITY_PRIVATE
;
3314 complain (&invalid_cpp_abbrev_complaint
, *pp
);
3315 /* We have no idea what syntax an unrecognized abbrev would have, so
3316 better return 0. If we returned 1, we would need to at least advance
3317 *pp to avoid an infinite loop. */
3324 read_one_struct_field (struct field_info
*fip
, char **pp
, char *p
,
3325 struct type
*type
, struct objfile
*objfile
)
3327 /* The following is code to work around cfront generated stabs.
3328 The stabs contains full mangled name for each field.
3329 We try to demangle the name and extract the field name out of it.
3331 if (ARM_DEMANGLING
&& current_subfile
->language
== language_cplus
)
3337 dem
= cplus_demangle (*pp
, DMGL_ANSI
| DMGL_PARAMS
);
3340 dem_p
= strrchr (dem
, ':');
3341 if (dem_p
!= 0 && *(dem_p
- 1) == ':')
3343 FIELD_NAME (fip
->list
->field
) =
3344 obsavestring (dem_p
, strlen (dem_p
), &objfile
->type_obstack
);
3348 FIELD_NAME (fip
->list
->field
) =
3349 obsavestring (*pp
, p
- *pp
, &objfile
->type_obstack
);
3353 /* end of code for cfront work around */
3356 fip
->list
->field
.name
=
3357 obsavestring (*pp
, p
- *pp
, &objfile
->type_obstack
);
3360 /* This means we have a visibility for a field coming. */
3364 fip
->list
->visibility
= *(*pp
)++;
3368 /* normal dbx-style format, no explicit visibility */
3369 fip
->list
->visibility
= VISIBILITY_PUBLIC
;
3372 fip
->list
->field
.type
= read_type (pp
, objfile
);
3377 /* Possible future hook for nested types. */
3380 fip
->list
->field
.bitpos
= (long) -2; /* nested type */
3390 /* Static class member. */
3391 SET_FIELD_PHYSNAME (fip
->list
->field
, savestring (*pp
, p
- *pp
));
3395 else if (**pp
!= ',')
3397 /* Bad structure-type format. */
3398 complain (&stabs_general_complaint
, "bad structure-type format");
3402 (*pp
)++; /* Skip the comma. */
3406 FIELD_BITPOS (fip
->list
->field
) = read_huge_number (pp
, ',', &nbits
);
3409 complain (&stabs_general_complaint
, "bad structure-type format");
3412 FIELD_BITSIZE (fip
->list
->field
) = read_huge_number (pp
, ';', &nbits
);
3415 complain (&stabs_general_complaint
, "bad structure-type format");
3420 if (FIELD_BITPOS (fip
->list
->field
) == 0
3421 && FIELD_BITSIZE (fip
->list
->field
) == 0)
3423 /* This can happen in two cases: (1) at least for gcc 2.4.5 or so,
3424 it is a field which has been optimized out. The correct stab for
3425 this case is to use VISIBILITY_IGNORE, but that is a recent
3426 invention. (2) It is a 0-size array. For example
3427 union { int num; char str[0]; } foo. Printing "<no value>" for
3428 str in "p foo" is OK, since foo.str (and thus foo.str[3])
3429 will continue to work, and a 0-size array as a whole doesn't
3430 have any contents to print.
3432 I suspect this probably could also happen with gcc -gstabs (not
3433 -gstabs+) for static fields, and perhaps other C++ extensions.
3434 Hopefully few people use -gstabs with gdb, since it is intended
3435 for dbx compatibility. */
3437 /* Ignore this field. */
3438 fip
->list
->visibility
= VISIBILITY_IGNORE
;
3442 /* Detect an unpacked field and mark it as such.
3443 dbx gives a bit size for all fields.
3444 Note that forward refs cannot be packed,
3445 and treat enums as if they had the width of ints. */
3447 struct type
*field_type
= check_typedef (FIELD_TYPE (fip
->list
->field
));
3449 if (TYPE_CODE (field_type
) != TYPE_CODE_INT
3450 && TYPE_CODE (field_type
) != TYPE_CODE_RANGE
3451 && TYPE_CODE (field_type
) != TYPE_CODE_BOOL
3452 && TYPE_CODE (field_type
) != TYPE_CODE_ENUM
)
3454 FIELD_BITSIZE (fip
->list
->field
) = 0;
3456 if ((FIELD_BITSIZE (fip
->list
->field
)
3457 == TARGET_CHAR_BIT
* TYPE_LENGTH (field_type
)
3458 || (TYPE_CODE (field_type
) == TYPE_CODE_ENUM
3459 && FIELD_BITSIZE (fip
->list
->field
) == TARGET_INT_BIT
)
3462 FIELD_BITPOS (fip
->list
->field
) % 8 == 0)
3464 FIELD_BITSIZE (fip
->list
->field
) = 0;
3470 /* Read struct or class data fields. They have the form:
3472 NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
3474 At the end, we see a semicolon instead of a field.
3476 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
3479 The optional VISIBILITY is one of:
3481 '/0' (VISIBILITY_PRIVATE)
3482 '/1' (VISIBILITY_PROTECTED)
3483 '/2' (VISIBILITY_PUBLIC)
3484 '/9' (VISIBILITY_IGNORE)
3486 or nothing, for C style fields with public visibility.
3488 Returns 1 for success, 0 for failure. */
3491 read_struct_fields (struct field_info
*fip
, char **pp
, struct type
*type
,
3492 struct objfile
*objfile
)
3495 struct nextfield
*new;
3497 /* We better set p right now, in case there are no fields at all... */
3501 /* Read each data member type until we find the terminating ';' at the end of
3502 the data member list, or break for some other reason such as finding the
3503 start of the member function list. */
3507 if (os9k_stabs
&& **pp
== ',')
3509 STABS_CONTINUE (pp
, objfile
);
3510 /* Get space to record the next field's data. */
3511 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3512 make_cleanup (xfree
, new);
3513 memset (new, 0, sizeof (struct nextfield
));
3514 new->next
= fip
->list
;
3517 /* Get the field name. */
3520 /* If is starts with CPLUS_MARKER it is a special abbreviation,
3521 unless the CPLUS_MARKER is followed by an underscore, in
3522 which case it is just the name of an anonymous type, which we
3523 should handle like any other type name. */
3525 if (is_cplus_marker (p
[0]) && p
[1] != '_')
3527 if (!read_cpp_abbrev (fip
, pp
, type
, objfile
))
3532 /* Look for the ':' that separates the field name from the field
3533 values. Data members are delimited by a single ':', while member
3534 functions are delimited by a pair of ':'s. When we hit the member
3535 functions (if any), terminate scan loop and return. */
3537 while (*p
!= ':' && *p
!= '\0')
3544 /* Check to see if we have hit the member functions yet. */
3549 read_one_struct_field (fip
, pp
, p
, type
, objfile
);
3551 if (p
[0] == ':' && p
[1] == ':')
3553 /* chill the list of fields: the last entry (at the head) is a
3554 partially constructed entry which we now scrub. */
3555 fip
->list
= fip
->list
->next
;
3560 /* The stabs for C++ derived classes contain baseclass information which
3561 is marked by a '!' character after the total size. This function is
3562 called when we encounter the baseclass marker, and slurps up all the
3563 baseclass information.
3565 Immediately following the '!' marker is the number of base classes that
3566 the class is derived from, followed by information for each base class.
3567 For each base class, there are two visibility specifiers, a bit offset
3568 to the base class information within the derived class, a reference to
3569 the type for the base class, and a terminating semicolon.
3571 A typical example, with two base classes, would be "!2,020,19;0264,21;".
3573 Baseclass information marker __________________|| | | | | | |
3574 Number of baseclasses __________________________| | | | | | |
3575 Visibility specifiers (2) ________________________| | | | | |
3576 Offset in bits from start of class _________________| | | | |
3577 Type number for base class ___________________________| | | |
3578 Visibility specifiers (2) _______________________________| | |
3579 Offset in bits from start of class ________________________| |
3580 Type number of base class ____________________________________|
3582 Return 1 for success, 0 for (error-type-inducing) failure. */
3588 read_baseclasses (struct field_info
*fip
, char **pp
, struct type
*type
,
3589 struct objfile
*objfile
)
3592 struct nextfield
*new;
3600 /* Skip the '!' baseclass information marker. */
3604 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3607 TYPE_N_BASECLASSES (type
) = read_huge_number (pp
, ',', &nbits
);
3613 /* Some stupid compilers have trouble with the following, so break
3614 it up into simpler expressions. */
3615 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*)
3616 TYPE_ALLOC (type
, B_BYTES (TYPE_N_BASECLASSES (type
)));
3619 int num_bytes
= B_BYTES (TYPE_N_BASECLASSES (type
));
3622 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
3623 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
3627 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), TYPE_N_BASECLASSES (type
));
3629 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
3631 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3632 make_cleanup (xfree
, new);
3633 memset (new, 0, sizeof (struct nextfield
));
3634 new->next
= fip
->list
;
3636 FIELD_BITSIZE (new->field
) = 0; /* this should be an unpacked field! */
3638 STABS_CONTINUE (pp
, objfile
);
3642 /* Nothing to do. */
3645 SET_TYPE_FIELD_VIRTUAL (type
, i
);
3648 /* Unknown character. Complain and treat it as non-virtual. */
3650 static struct complaint msg
=
3652 "Unknown virtual character `%c' for baseclass", 0, 0};
3653 complain (&msg
, **pp
);
3658 new->visibility
= *(*pp
)++;
3659 switch (new->visibility
)
3661 case VISIBILITY_PRIVATE
:
3662 case VISIBILITY_PROTECTED
:
3663 case VISIBILITY_PUBLIC
:
3666 /* Bad visibility format. Complain and treat it as
3669 static struct complaint msg
=
3671 "Unknown visibility `%c' for baseclass", 0, 0
3673 complain (&msg
, new->visibility
);
3674 new->visibility
= VISIBILITY_PUBLIC
;
3681 /* The remaining value is the bit offset of the portion of the object
3682 corresponding to this baseclass. Always zero in the absence of
3683 multiple inheritance. */
3685 FIELD_BITPOS (new->field
) = read_huge_number (pp
, ',', &nbits
);
3690 /* The last piece of baseclass information is the type of the
3691 base class. Read it, and remember it's type name as this
3694 new->field
.type
= read_type (pp
, objfile
);
3695 new->field
.name
= type_name_no_tag (new->field
.type
);
3697 /* skip trailing ';' and bump count of number of fields seen */
3706 /* The tail end of stabs for C++ classes that contain a virtual function
3707 pointer contains a tilde, a %, and a type number.
3708 The type number refers to the base class (possibly this class itself) which
3709 contains the vtable pointer for the current class.
3711 This function is called when we have parsed all the method declarations,
3712 so we can look for the vptr base class info. */
3715 read_tilde_fields (struct field_info
*fip
, char **pp
, struct type
*type
,
3716 struct objfile
*objfile
)
3720 STABS_CONTINUE (pp
, objfile
);
3722 /* If we are positioned at a ';', then skip it. */
3732 if (**pp
== '=' || **pp
== '+' || **pp
== '-')
3734 /* Obsolete flags that used to indicate the presence
3735 of constructors and/or destructors. */
3739 /* Read either a '%' or the final ';'. */
3740 if (*(*pp
)++ == '%')
3742 /* The next number is the type number of the base class
3743 (possibly our own class) which supplies the vtable for
3744 this class. Parse it out, and search that class to find
3745 its vtable pointer, and install those into TYPE_VPTR_BASETYPE
3746 and TYPE_VPTR_FIELDNO. */
3751 t
= read_type (pp
, objfile
);
3753 while (*p
!= '\0' && *p
!= ';')
3759 /* Premature end of symbol. */
3763 TYPE_VPTR_BASETYPE (type
) = t
;
3764 if (type
== t
) /* Our own class provides vtbl ptr */
3766 for (i
= TYPE_NFIELDS (t
) - 1;
3767 i
>= TYPE_N_BASECLASSES (t
);
3770 if (!strncmp (TYPE_FIELD_NAME (t
, i
), vptr_name
,
3771 sizeof (vptr_name
) - 1))
3773 TYPE_VPTR_FIELDNO (type
) = i
;
3777 /* Virtual function table field not found. */
3778 complain (&vtbl_notfound_complaint
, TYPE_NAME (type
));
3783 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
3794 attach_fn_fields_to_type (struct field_info
*fip
, register struct type
*type
)
3798 for (n
= TYPE_NFN_FIELDS (type
);
3799 fip
->fnlist
!= NULL
;
3800 fip
->fnlist
= fip
->fnlist
->next
)
3802 --n
; /* Circumvent Sun3 compiler bug */
3803 TYPE_FN_FIELDLISTS (type
)[n
] = fip
->fnlist
->fn_fieldlist
;
3808 /* read cfront class static data.
3809 pp points to string starting with the list of static data
3810 eg: A:ZcA;1@Bpub v2@Bvirpri;__ct__1AFv func__1AFv *sfunc__1AFv ;as__1A ;;
3813 A:ZcA;;foopri__1AFv foopro__1AFv __ct__1AFv __ct__1AFRC1A foopub__1AFv ;;;
3818 read_cfront_static_fields (struct field_info
*fip
, char **pp
, struct type
*type
,
3819 struct objfile
*objfile
)
3821 struct nextfield
*new;
3824 struct symbol
*ref_static
= 0;
3826 if (**pp
== ';') /* no static data; return */
3832 /* Process each field in the list until we find the terminating ";" */
3834 /* eg: p = "as__1A ;;;" */
3835 STABS_CONTINUE (pp
, objfile
); /* handle \\ */
3836 while (**pp
!= ';' && (sname
= get_substring (pp
, ' '), sname
))
3838 ref_static
= lookup_symbol (sname
, 0, VAR_NAMESPACE
, 0, 0); /*demangled_name */
3841 static struct complaint msg
=
3843 Unable to find symbol for static data field %s\n",
3845 complain (&msg
, sname
);
3848 stype
= SYMBOL_TYPE (ref_static
);
3850 /* allocate a new fip */
3851 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3852 make_cleanup (xfree
, new);
3853 memset (new, 0, sizeof (struct nextfield
));
3854 new->next
= fip
->list
;
3857 /* set visibility */
3858 /* FIXME! no way to tell visibility from stabs??? */
3859 new->visibility
= VISIBILITY_PUBLIC
;
3861 /* set field info into fip */
3862 fip
->list
->field
.type
= stype
;
3864 /* set bitpos & bitsize */
3865 SET_FIELD_PHYSNAME (fip
->list
->field
, savestring (sname
, strlen (sname
)));
3867 /* set name field */
3868 /* The following is code to work around cfront generated stabs.
3869 The stabs contains full mangled name for each field.
3870 We try to demangle the name and extract the field name out of it.
3875 dem
= cplus_demangle (sname
, DMGL_ANSI
| DMGL_PARAMS
);
3878 dem_p
= strrchr (dem
, ':');
3879 if (dem_p
!= 0 && *(dem_p
- 1) == ':')
3881 fip
->list
->field
.name
=
3882 obsavestring (dem_p
, strlen (dem_p
), &objfile
->type_obstack
);
3886 fip
->list
->field
.name
=
3887 obsavestring (sname
, strlen (sname
), &objfile
->type_obstack
);
3889 } /* end of code for cfront work around */
3890 } /* loop again for next static field */
3894 /* Copy structure fields to fip so attach_fields_to_type will work.
3895 type has already been created with the initial instance data fields.
3896 Now we want to be able to add the other members to the class,
3897 so we want to add them back to the fip and reattach them again
3898 once we have collected all the class members. */
3901 copy_cfront_struct_fields (struct field_info
*fip
, struct type
*type
,
3902 struct objfile
*objfile
)
3904 int nfields
= TYPE_NFIELDS (type
);
3906 struct nextfield
*new;
3908 /* Copy the fields into the list of fips and reset the types
3909 to remove the old fields */
3911 for (i
= 0; i
< nfields
; i
++)
3913 /* allocate a new fip */
3914 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3915 make_cleanup (xfree
, new);
3916 memset (new, 0, sizeof (struct nextfield
));
3917 new->next
= fip
->list
;
3920 /* copy field info into fip */
3921 new->field
= TYPE_FIELD (type
, i
);
3922 /* set visibility */
3923 if (TYPE_FIELD_PROTECTED (type
, i
))
3924 new->visibility
= VISIBILITY_PROTECTED
;
3925 else if (TYPE_FIELD_PRIVATE (type
, i
))
3926 new->visibility
= VISIBILITY_PRIVATE
;
3928 new->visibility
= VISIBILITY_PUBLIC
;
3930 /* Now delete the fields from the type since we will be
3931 allocing new space once we get the rest of the fields
3932 in attach_fields_to_type.
3933 The pointer TYPE_FIELDS(type) is left dangling but should
3934 be freed later by objstack_free */
3935 TYPE_FIELDS (type
) = 0;
3936 TYPE_NFIELDS (type
) = 0;
3941 /* Create the vector of fields, and record how big it is.
3942 We need this info to record proper virtual function table information
3943 for this class's virtual functions. */
3946 attach_fields_to_type (struct field_info
*fip
, register struct type
*type
,
3947 struct objfile
*objfile
)
3949 register int nfields
= 0;
3950 register int non_public_fields
= 0;
3951 register struct nextfield
*scan
;
3953 /* Count up the number of fields that we have, as well as taking note of
3954 whether or not there are any non-public fields, which requires us to
3955 allocate and build the private_field_bits and protected_field_bits
3958 for (scan
= fip
->list
; scan
!= NULL
; scan
= scan
->next
)
3961 if (scan
->visibility
!= VISIBILITY_PUBLIC
)
3963 non_public_fields
++;
3967 /* Now we know how many fields there are, and whether or not there are any
3968 non-public fields. Record the field count, allocate space for the
3969 array of fields, and create blank visibility bitfields if necessary. */
3971 TYPE_NFIELDS (type
) = nfields
;
3972 TYPE_FIELDS (type
) = (struct field
*)
3973 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
3974 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
3976 if (non_public_fields
)
3978 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3980 TYPE_FIELD_PRIVATE_BITS (type
) =
3981 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3982 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
3984 TYPE_FIELD_PROTECTED_BITS (type
) =
3985 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3986 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
3988 TYPE_FIELD_IGNORE_BITS (type
) =
3989 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3990 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
3993 /* Copy the saved-up fields into the field vector. Start from the head
3994 of the list, adding to the tail of the field array, so that they end
3995 up in the same order in the array in which they were added to the list. */
3997 while (nfields
-- > 0)
3999 TYPE_FIELD (type
, nfields
) = fip
->list
->field
;
4000 switch (fip
->list
->visibility
)
4002 case VISIBILITY_PRIVATE
:
4003 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
4006 case VISIBILITY_PROTECTED
:
4007 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
4010 case VISIBILITY_IGNORE
:
4011 SET_TYPE_FIELD_IGNORE (type
, nfields
);
4014 case VISIBILITY_PUBLIC
:
4018 /* Unknown visibility. Complain and treat it as public. */
4020 static struct complaint msg
=
4022 "Unknown visibility `%c' for field", 0, 0};
4023 complain (&msg
, fip
->list
->visibility
);
4027 fip
->list
= fip
->list
->next
;
4032 /* Read the description of a structure (or union type) and return an object
4033 describing the type.
4035 PP points to a character pointer that points to the next unconsumed token
4036 in the the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
4037 *PP will point to "4a:1,0,32;;".
4039 TYPE points to an incomplete type that needs to be filled in.
4041 OBJFILE points to the current objfile from which the stabs information is
4042 being read. (Note that it is redundant in that TYPE also contains a pointer
4043 to this same objfile, so it might be a good idea to eliminate it. FIXME).
4046 static struct type
*
4047 read_struct_type (char **pp
, struct type
*type
, struct objfile
*objfile
)
4049 struct cleanup
*back_to
;
4050 struct field_info fi
;
4055 back_to
= make_cleanup (null_cleanup
, 0);
4057 INIT_CPLUS_SPECIFIC (type
);
4058 TYPE_FLAGS (type
) &= ~TYPE_FLAG_STUB
;
4060 /* First comes the total size in bytes. */
4064 TYPE_LENGTH (type
) = read_huge_number (pp
, 0, &nbits
);
4066 return error_type (pp
, objfile
);
4069 /* Now read the baseclasses, if any, read the regular C struct or C++
4070 class member fields, attach the fields to the type, read the C++
4071 member functions, attach them to the type, and then read any tilde
4072 field (baseclass specifier for the class holding the main vtable). */
4074 if (!read_baseclasses (&fi
, pp
, type
, objfile
)
4075 || !read_struct_fields (&fi
, pp
, type
, objfile
)
4076 || !attach_fields_to_type (&fi
, type
, objfile
)
4077 || !read_member_functions (&fi
, pp
, type
, objfile
)
4078 || !attach_fn_fields_to_type (&fi
, type
)
4079 || !read_tilde_fields (&fi
, pp
, type
, objfile
))
4081 type
= error_type (pp
, objfile
);
4084 do_cleanups (back_to
);
4088 /* Read a definition of an array type,
4089 and create and return a suitable type object.
4090 Also creates a range type which represents the bounds of that
4093 static struct type
*
4094 read_array_type (register char **pp
, register struct type
*type
,
4095 struct objfile
*objfile
)
4097 struct type
*index_type
, *element_type
, *range_type
;
4102 /* Format of an array type:
4103 "ar<index type>;lower;upper;<array_contents_type>".
4104 OS9000: "arlower,upper;<array_contents_type>".
4106 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
4107 for these, produce a type like float[][]. */
4110 index_type
= builtin_type_int
;
4113 index_type
= read_type (pp
, objfile
);
4115 /* Improper format of array type decl. */
4116 return error_type (pp
, objfile
);
4120 if (!(**pp
>= '0' && **pp
<= '9') && **pp
!= '-')
4125 lower
= read_huge_number (pp
, os9k_stabs
? ',' : ';', &nbits
);
4127 return error_type (pp
, objfile
);
4129 if (!(**pp
>= '0' && **pp
<= '9') && **pp
!= '-')
4134 upper
= read_huge_number (pp
, ';', &nbits
);
4136 return error_type (pp
, objfile
);
4138 element_type
= read_type (pp
, objfile
);
4147 create_range_type ((struct type
*) NULL
, index_type
, lower
, upper
);
4148 type
= create_array_type (type
, element_type
, range_type
);
4154 /* Read a definition of an enumeration type,
4155 and create and return a suitable type object.
4156 Also defines the symbols that represent the values of the type. */
4158 static struct type
*
4159 read_enum_type (register char **pp
, register struct type
*type
,
4160 struct objfile
*objfile
)
4165 register struct symbol
*sym
;
4167 struct pending
**symlist
;
4168 struct pending
*osyms
, *syms
;
4171 int unsigned_enum
= 1;
4174 /* FIXME! The stabs produced by Sun CC merrily define things that ought
4175 to be file-scope, between N_FN entries, using N_LSYM. What's a mother
4176 to do? For now, force all enum values to file scope. */
4177 if (within_function
)
4178 symlist
= &local_symbols
;
4181 symlist
= &file_symbols
;
4183 o_nsyms
= osyms
? osyms
->nsyms
: 0;
4187 /* Size. Perhaps this does not have to be conditionalized on
4188 os9k_stabs (assuming the name of an enum constant can't start
4190 read_huge_number (pp
, 0, &nbits
);
4192 return error_type (pp
, objfile
);
4195 /* The aix4 compiler emits an extra field before the enum members;
4196 my guess is it's a type of some sort. Just ignore it. */
4199 /* Skip over the type. */
4203 /* Skip over the colon. */
4207 /* Read the value-names and their values.
4208 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
4209 A semicolon or comma instead of a NAME means the end. */
4210 while (**pp
&& **pp
!= ';' && **pp
!= ',')
4212 STABS_CONTINUE (pp
, objfile
);
4216 name
= obsavestring (*pp
, p
- *pp
, &objfile
->symbol_obstack
);
4218 n
= read_huge_number (pp
, ',', &nbits
);
4220 return error_type (pp
, objfile
);
4222 sym
= (struct symbol
*)
4223 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct symbol
));
4224 memset (sym
, 0, sizeof (struct symbol
));
4225 SYMBOL_NAME (sym
) = name
;
4226 SYMBOL_LANGUAGE (sym
) = current_subfile
->language
;
4227 SYMBOL_CLASS (sym
) = LOC_CONST
;
4228 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4229 SYMBOL_VALUE (sym
) = n
;
4232 add_symbol_to_list (sym
, symlist
);
4237 (*pp
)++; /* Skip the semicolon. */
4239 /* Now fill in the fields of the type-structure. */
4241 TYPE_LENGTH (type
) = TARGET_INT_BIT
/ HOST_CHAR_BIT
;
4242 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
4243 TYPE_FLAGS (type
) &= ~TYPE_FLAG_STUB
;
4245 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
4246 TYPE_NFIELDS (type
) = nsyms
;
4247 TYPE_FIELDS (type
) = (struct field
*)
4248 TYPE_ALLOC (type
, sizeof (struct field
) * nsyms
);
4249 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nsyms
);
4251 /* Find the symbols for the values and put them into the type.
4252 The symbols can be found in the symlist that we put them on
4253 to cause them to be defined. osyms contains the old value
4254 of that symlist; everything up to there was defined by us. */
4255 /* Note that we preserve the order of the enum constants, so
4256 that in something like "enum {FOO, LAST_THING=FOO}" we print
4257 FOO, not LAST_THING. */
4259 for (syms
= *symlist
, n
= nsyms
- 1; syms
; syms
= syms
->next
)
4261 int last
= syms
== osyms
? o_nsyms
: 0;
4262 int j
= syms
->nsyms
;
4263 for (; --j
>= last
; --n
)
4265 struct symbol
*xsym
= syms
->symbol
[j
];
4266 SYMBOL_TYPE (xsym
) = type
;
4267 TYPE_FIELD_NAME (type
, n
) = SYMBOL_NAME (xsym
);
4268 TYPE_FIELD_BITPOS (type
, n
) = SYMBOL_VALUE (xsym
);
4269 TYPE_FIELD_BITSIZE (type
, n
) = 0;
4278 /* Sun's ACC uses a somewhat saner method for specifying the builtin
4279 typedefs in every file (for int, long, etc):
4281 type = b <signed> <width> <format type>; <offset>; <nbits>
4283 optional format type = c or b for char or boolean.
4284 offset = offset from high order bit to start bit of type.
4285 width is # bytes in object of this type, nbits is # bits in type.
4287 The width/offset stuff appears to be for small objects stored in
4288 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
4291 static struct type
*
4292 read_sun_builtin_type (char **pp
, int typenums
[2], struct objfile
*objfile
)
4297 enum type_code code
= TYPE_CODE_INT
;
4308 return error_type (pp
, objfile
);
4312 /* For some odd reason, all forms of char put a c here. This is strange
4313 because no other type has this honor. We can safely ignore this because
4314 we actually determine 'char'acterness by the number of bits specified in
4316 Boolean forms, e.g Fortran logical*X, put a b here. */
4320 else if (**pp
== 'b')
4322 code
= TYPE_CODE_BOOL
;
4326 /* The first number appears to be the number of bytes occupied
4327 by this type, except that unsigned short is 4 instead of 2.
4328 Since this information is redundant with the third number,
4329 we will ignore it. */
4330 read_huge_number (pp
, ';', &nbits
);
4332 return error_type (pp
, objfile
);
4334 /* The second number is always 0, so ignore it too. */
4335 read_huge_number (pp
, ';', &nbits
);
4337 return error_type (pp
, objfile
);
4339 /* The third number is the number of bits for this type. */
4340 type_bits
= read_huge_number (pp
, 0, &nbits
);
4342 return error_type (pp
, objfile
);
4343 /* The type *should* end with a semicolon. If it are embedded
4344 in a larger type the semicolon may be the only way to know where
4345 the type ends. If this type is at the end of the stabstring we
4346 can deal with the omitted semicolon (but we don't have to like
4347 it). Don't bother to complain(), Sun's compiler omits the semicolon
4353 return init_type (TYPE_CODE_VOID
, 1,
4354 signed_type
? 0 : TYPE_FLAG_UNSIGNED
, (char *) NULL
,
4357 return init_type (code
,
4358 type_bits
/ TARGET_CHAR_BIT
,
4359 signed_type
? 0 : TYPE_FLAG_UNSIGNED
, (char *) NULL
,
4363 static struct type
*
4364 read_sun_floating_type (char **pp
, int typenums
[2], struct objfile
*objfile
)
4370 /* The first number has more details about the type, for example
4372 details
= read_huge_number (pp
, ';', &nbits
);
4374 return error_type (pp
, objfile
);
4376 /* The second number is the number of bytes occupied by this type */
4377 nbytes
= read_huge_number (pp
, ';', &nbits
);
4379 return error_type (pp
, objfile
);
4381 if (details
== NF_COMPLEX
|| details
== NF_COMPLEX16
4382 || details
== NF_COMPLEX32
)
4383 /* This is a type we can't handle, but we do know the size.
4384 We also will be able to give it a name. */
4385 return init_type (TYPE_CODE_COMPLEX
, nbytes
, 0, NULL
, objfile
);
4387 return init_type (TYPE_CODE_FLT
, nbytes
, 0, NULL
, objfile
);
4390 /* Read a number from the string pointed to by *PP.
4391 The value of *PP is advanced over the number.
4392 If END is nonzero, the character that ends the
4393 number must match END, or an error happens;
4394 and that character is skipped if it does match.
4395 If END is zero, *PP is left pointing to that character.
4397 If the number fits in a long, set *BITS to 0 and return the value.
4398 If not, set *BITS to be the number of bits in the number and return 0.
4400 If encounter garbage, set *BITS to -1 and return 0. */
4403 read_huge_number (char **pp
, int end
, int *bits
)
4420 /* Leading zero means octal. GCC uses this to output values larger
4421 than an int (because that would be hard in decimal). */
4429 upper_limit
= ULONG_MAX
/ radix
;
4431 upper_limit
= LONG_MAX
/ radix
;
4433 while ((c
= *p
++) >= '0' && c
< ('0' + radix
))
4435 if (n
<= upper_limit
)
4438 n
+= c
- '0'; /* FIXME this overflows anyway */
4443 /* This depends on large values being output in octal, which is
4450 /* Ignore leading zeroes. */
4454 else if (c
== '2' || c
== '3')
4480 /* Large decimal constants are an error (because it is hard to
4481 count how many bits are in them). */
4487 /* -0x7f is the same as 0x80. So deal with it by adding one to
4488 the number of bits. */
4500 /* It's *BITS which has the interesting information. */
4504 static struct type
*
4505 read_range_type (char **pp
, int typenums
[2], struct objfile
*objfile
)
4507 char *orig_pp
= *pp
;
4512 struct type
*result_type
;
4513 struct type
*index_type
= NULL
;
4515 /* First comes a type we are a subrange of.
4516 In C it is usually 0, 1 or the type being defined. */
4517 if (read_type_number (pp
, rangenums
) != 0)
4518 return error_type (pp
, objfile
);
4519 self_subrange
= (rangenums
[0] == typenums
[0] &&
4520 rangenums
[1] == typenums
[1]);
4525 index_type
= read_type (pp
, objfile
);
4528 /* A semicolon should now follow; skip it. */
4532 /* The remaining two operands are usually lower and upper bounds
4533 of the range. But in some special cases they mean something else. */
4534 n2
= read_huge_number (pp
, ';', &n2bits
);
4535 n3
= read_huge_number (pp
, ';', &n3bits
);
4537 if (n2bits
== -1 || n3bits
== -1)
4538 return error_type (pp
, objfile
);
4541 goto handle_true_range
;
4543 /* If limits are huge, must be large integral type. */
4544 if (n2bits
!= 0 || n3bits
!= 0)
4546 char got_signed
= 0;
4547 char got_unsigned
= 0;
4548 /* Number of bits in the type. */
4551 /* Range from 0 to <large number> is an unsigned large integral type. */
4552 if ((n2bits
== 0 && n2
== 0) && n3bits
!= 0)
4557 /* Range from <large number> to <large number>-1 is a large signed
4558 integral type. Take care of the case where <large number> doesn't
4559 fit in a long but <large number>-1 does. */
4560 else if ((n2bits
!= 0 && n3bits
!= 0 && n2bits
== n3bits
+ 1)
4561 || (n2bits
!= 0 && n3bits
== 0
4562 && (n2bits
== sizeof (long) * HOST_CHAR_BIT
)
4569 if (got_signed
|| got_unsigned
)
4571 return init_type (TYPE_CODE_INT
, nbits
/ TARGET_CHAR_BIT
,
4572 got_unsigned
? TYPE_FLAG_UNSIGNED
: 0, NULL
,
4576 return error_type (pp
, objfile
);
4579 /* A type defined as a subrange of itself, with bounds both 0, is void. */
4580 if (self_subrange
&& n2
== 0 && n3
== 0)
4581 return init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
4583 /* If n3 is zero and n2 is positive, we want a floating type, and n2
4584 is the width in bytes.
4586 Fortran programs appear to use this for complex types also. To
4587 distinguish between floats and complex, g77 (and others?) seem
4588 to use self-subranges for the complexes, and subranges of int for
4591 Also note that for complexes, g77 sets n2 to the size of one of
4592 the member floats, not the whole complex beast. My guess is that
4593 this was to work well with pre-COMPLEX versions of gdb. */
4595 if (n3
== 0 && n2
> 0)
4597 struct type
*float_type
4598 = init_type (TYPE_CODE_FLT
, n2
, 0, NULL
, objfile
);
4602 struct type
*complex_type
=
4603 init_type (TYPE_CODE_COMPLEX
, 2 * n2
, 0, NULL
, objfile
);
4604 TYPE_TARGET_TYPE (complex_type
) = float_type
;
4605 return complex_type
;
4611 /* If the upper bound is -1, it must really be an unsigned int. */
4613 else if (n2
== 0 && n3
== -1)
4615 /* It is unsigned int or unsigned long. */
4616 /* GCC 2.3.3 uses this for long long too, but that is just a GDB 3.5
4617 compatibility hack. */
4618 return init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
4619 TYPE_FLAG_UNSIGNED
, NULL
, objfile
);
4622 /* Special case: char is defined (Who knows why) as a subrange of
4623 itself with range 0-127. */
4624 else if (self_subrange
&& n2
== 0 && n3
== 127)
4625 return init_type (TYPE_CODE_INT
, 1, 0, NULL
, objfile
);
4627 else if (current_symbol
&& SYMBOL_LANGUAGE (current_symbol
) == language_chill
4629 goto handle_true_range
;
4631 /* We used to do this only for subrange of self or subrange of int. */
4634 /* -1 is used for the upper bound of (4 byte) "unsigned int" and
4635 "unsigned long", and we already checked for that,
4636 so don't need to test for it here. */
4639 /* n3 actually gives the size. */
4640 return init_type (TYPE_CODE_INT
, -n3
, TYPE_FLAG_UNSIGNED
,
4643 /* Is n3 == 2**(8n)-1 for some integer n? Then it's an
4644 unsigned n-byte integer. But do require n to be a power of
4645 two; we don't want 3- and 5-byte integers flying around. */
4651 for (bytes
= 0; (bits
& 0xff) == 0xff; bytes
++)
4654 && ((bytes
- 1) & bytes
) == 0) /* "bytes is a power of two" */
4655 return init_type (TYPE_CODE_INT
, bytes
, TYPE_FLAG_UNSIGNED
, NULL
,
4659 /* I think this is for Convex "long long". Since I don't know whether
4660 Convex sets self_subrange, I also accept that particular size regardless
4661 of self_subrange. */
4662 else if (n3
== 0 && n2
< 0
4664 || n2
== -TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
))
4665 return init_type (TYPE_CODE_INT
, -n2
, 0, NULL
, objfile
);
4666 else if (n2
== -n3
- 1)
4669 return init_type (TYPE_CODE_INT
, 1, 0, NULL
, objfile
);
4671 return init_type (TYPE_CODE_INT
, 2, 0, NULL
, objfile
);
4672 if (n3
== 0x7fffffff)
4673 return init_type (TYPE_CODE_INT
, 4, 0, NULL
, objfile
);
4676 /* We have a real range type on our hands. Allocate space and
4677 return a real pointer. */
4681 index_type
= builtin_type_int
;
4683 index_type
= *dbx_lookup_type (rangenums
);
4684 if (index_type
== NULL
)
4686 /* Does this actually ever happen? Is that why we are worrying
4687 about dealing with it rather than just calling error_type? */
4689 static struct type
*range_type_index
;
4691 complain (&range_type_base_complaint
, rangenums
[1]);
4692 if (range_type_index
== NULL
)
4694 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
4695 0, "range type index type", NULL
);
4696 index_type
= range_type_index
;
4699 result_type
= create_range_type ((struct type
*) NULL
, index_type
, n2
, n3
);
4700 return (result_type
);
4703 /* Read in an argument list. This is a list of types, separated by commas
4704 and terminated with END. Return the list of types read in, or (struct type
4705 **)-1 if there is an error. */
4707 static struct type
**
4708 read_args (char **pp
, int end
, struct objfile
*objfile
)
4710 /* FIXME! Remove this arbitrary limit! */
4711 struct type
*types
[1024], **rval
; /* allow for fns of 1023 parameters */
4717 /* Invalid argument list: no ','. */
4718 return (struct type
**) -1;
4720 STABS_CONTINUE (pp
, objfile
);
4721 types
[n
++] = read_type (pp
, objfile
);
4723 (*pp
)++; /* get past `end' (the ':' character) */
4727 rval
= (struct type
**) xmalloc (2 * sizeof (struct type
*));
4729 else if (TYPE_CODE (types
[n
- 1]) != TYPE_CODE_VOID
)
4731 rval
= (struct type
**) xmalloc ((n
+ 1) * sizeof (struct type
*));
4732 memset (rval
+ n
, 0, sizeof (struct type
*));
4736 rval
= (struct type
**) xmalloc (n
* sizeof (struct type
*));
4738 memcpy (rval
, types
, n
* sizeof (struct type
*));
4742 /* Common block handling. */
4744 /* List of symbols declared since the last BCOMM. This list is a tail
4745 of local_symbols. When ECOMM is seen, the symbols on the list
4746 are noted so their proper addresses can be filled in later,
4747 using the common block base address gotten from the assembler
4750 static struct pending
*common_block
;
4751 static int common_block_i
;
4753 /* Name of the current common block. We get it from the BCOMM instead of the
4754 ECOMM to match IBM documentation (even though IBM puts the name both places
4755 like everyone else). */
4756 static char *common_block_name
;
4758 /* Process a N_BCOMM symbol. The storage for NAME is not guaranteed
4759 to remain after this function returns. */
4762 common_block_start (char *name
, struct objfile
*objfile
)
4764 if (common_block_name
!= NULL
)
4766 static struct complaint msg
=
4768 "Invalid symbol data: common block within common block",
4772 common_block
= local_symbols
;
4773 common_block_i
= local_symbols
? local_symbols
->nsyms
: 0;
4774 common_block_name
= obsavestring (name
, strlen (name
),
4775 &objfile
->symbol_obstack
);
4778 /* Process a N_ECOMM symbol. */
4781 common_block_end (struct objfile
*objfile
)
4783 /* Symbols declared since the BCOMM are to have the common block
4784 start address added in when we know it. common_block and
4785 common_block_i point to the first symbol after the BCOMM in
4786 the local_symbols list; copy the list and hang it off the
4787 symbol for the common block name for later fixup. */
4790 struct pending
*new = 0;
4791 struct pending
*next
;
4794 if (common_block_name
== NULL
)
4796 static struct complaint msg
=
4797 {"ECOMM symbol unmatched by BCOMM", 0, 0};
4802 sym
= (struct symbol
*)
4803 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct symbol
));
4804 memset (sym
, 0, sizeof (struct symbol
));
4805 /* Note: common_block_name already saved on symbol_obstack */
4806 SYMBOL_NAME (sym
) = common_block_name
;
4807 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
4809 /* Now we copy all the symbols which have been defined since the BCOMM. */
4811 /* Copy all the struct pendings before common_block. */
4812 for (next
= local_symbols
;
4813 next
!= NULL
&& next
!= common_block
;
4816 for (j
= 0; j
< next
->nsyms
; j
++)
4817 add_symbol_to_list (next
->symbol
[j
], &new);
4820 /* Copy however much of COMMON_BLOCK we need. If COMMON_BLOCK is
4821 NULL, it means copy all the local symbols (which we already did
4824 if (common_block
!= NULL
)
4825 for (j
= common_block_i
; j
< common_block
->nsyms
; j
++)
4826 add_symbol_to_list (common_block
->symbol
[j
], &new);
4828 SYMBOL_TYPE (sym
) = (struct type
*) new;
4830 /* Should we be putting local_symbols back to what it was?
4833 i
= hashname (SYMBOL_NAME (sym
));
4834 SYMBOL_VALUE_CHAIN (sym
) = global_sym_chain
[i
];
4835 global_sym_chain
[i
] = sym
;
4836 common_block_name
= NULL
;
4839 /* Add a common block's start address to the offset of each symbol
4840 declared to be in it (by being between a BCOMM/ECOMM pair that uses
4841 the common block name). */
4844 fix_common_block (struct symbol
*sym
, int valu
)
4846 struct pending
*next
= (struct pending
*) SYMBOL_TYPE (sym
);
4847 for (; next
; next
= next
->next
)
4850 for (j
= next
->nsyms
- 1; j
>= 0; j
--)
4851 SYMBOL_VALUE_ADDRESS (next
->symbol
[j
]) += valu
;
4857 /* What about types defined as forward references inside of a small lexical
4859 /* Add a type to the list of undefined types to be checked through
4860 once this file has been read in. */
4863 add_undefined_type (struct type
*type
)
4865 if (undef_types_length
== undef_types_allocated
)
4867 undef_types_allocated
*= 2;
4868 undef_types
= (struct type
**)
4869 xrealloc ((char *) undef_types
,
4870 undef_types_allocated
* sizeof (struct type
*));
4872 undef_types
[undef_types_length
++] = type
;
4875 /* Go through each undefined type, see if it's still undefined, and fix it
4876 up if possible. We have two kinds of undefined types:
4878 TYPE_CODE_ARRAY: Array whose target type wasn't defined yet.
4879 Fix: update array length using the element bounds
4880 and the target type's length.
4881 TYPE_CODE_STRUCT, TYPE_CODE_UNION: Structure whose fields were not
4882 yet defined at the time a pointer to it was made.
4883 Fix: Do a full lookup on the struct/union tag. */
4885 cleanup_undefined_types (void)
4889 for (type
= undef_types
; type
< undef_types
+ undef_types_length
; type
++)
4891 switch (TYPE_CODE (*type
))
4894 case TYPE_CODE_STRUCT
:
4895 case TYPE_CODE_UNION
:
4896 case TYPE_CODE_ENUM
:
4898 /* Check if it has been defined since. Need to do this here
4899 as well as in check_typedef to deal with the (legitimate in
4900 C though not C++) case of several types with the same name
4901 in different source files. */
4902 if (TYPE_FLAGS (*type
) & TYPE_FLAG_STUB
)
4904 struct pending
*ppt
;
4906 /* Name of the type, without "struct" or "union" */
4907 char *typename
= TYPE_TAG_NAME (*type
);
4909 if (typename
== NULL
)
4911 static struct complaint msg
=
4912 {"need a type name", 0, 0};
4916 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
4918 for (i
= 0; i
< ppt
->nsyms
; i
++)
4920 struct symbol
*sym
= ppt
->symbol
[i
];
4922 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
4923 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
4924 && (TYPE_CODE (SYMBOL_TYPE (sym
)) ==
4926 && STREQ (SYMBOL_NAME (sym
), typename
))
4928 memcpy (*type
, SYMBOL_TYPE (sym
),
4929 sizeof (struct type
));
4939 static struct complaint msg
=
4941 GDB internal error. cleanup_undefined_types with bad type %d.", 0, 0};
4942 complain (&msg
, TYPE_CODE (*type
));
4948 undef_types_length
= 0;
4951 /* Scan through all of the global symbols defined in the object file,
4952 assigning values to the debugging symbols that need to be assigned
4953 to. Get these symbols from the minimal symbol table. */
4956 scan_file_globals (struct objfile
*objfile
)
4959 struct minimal_symbol
*msymbol
;
4960 struct symbol
*sym
, *prev
, *rsym
;
4961 struct objfile
*resolve_objfile
;
4963 /* SVR4 based linkers copy referenced global symbols from shared
4964 libraries to the main executable.
4965 If we are scanning the symbols for a shared library, try to resolve
4966 them from the minimal symbols of the main executable first. */
4968 if (symfile_objfile
&& objfile
!= symfile_objfile
)
4969 resolve_objfile
= symfile_objfile
;
4971 resolve_objfile
= objfile
;
4975 /* Avoid expensive loop through all minimal symbols if there are
4976 no unresolved symbols. */
4977 for (hash
= 0; hash
< HASHSIZE
; hash
++)
4979 if (global_sym_chain
[hash
])
4982 if (hash
>= HASHSIZE
)
4985 for (msymbol
= resolve_objfile
->msymbols
;
4986 msymbol
&& SYMBOL_NAME (msymbol
) != NULL
;
4991 /* Skip static symbols. */
4992 switch (MSYMBOL_TYPE (msymbol
))
5004 /* Get the hash index and check all the symbols
5005 under that hash index. */
5007 hash
= hashname (SYMBOL_NAME (msymbol
));
5009 for (sym
= global_sym_chain
[hash
]; sym
;)
5011 if (SYMBOL_NAME (msymbol
)[0] == SYMBOL_NAME (sym
)[0] &&
5012 STREQ (SYMBOL_NAME (msymbol
) + 1, SYMBOL_NAME (sym
) + 1))
5015 struct alias_list
*aliases
;
5017 /* Splice this symbol out of the hash chain and
5018 assign the value we have to it. */
5021 SYMBOL_VALUE_CHAIN (prev
) = SYMBOL_VALUE_CHAIN (sym
);
5025 global_sym_chain
[hash
] = SYMBOL_VALUE_CHAIN (sym
);
5028 /* Check to see whether we need to fix up a common block. */
5029 /* Note: this code might be executed several times for
5030 the same symbol if there are multiple references. */
5032 /* If symbol has aliases, do minimal symbol fixups for each.
5033 These live aliases/references weren't added to
5034 global_sym_chain hash but may also need to be fixed up. */
5035 /* FIXME: Maybe should have added aliases to the global chain, resolved symbol name, then treated aliases as normal
5036 symbols? Still, we wouldn't want to add_to_list. */
5037 /* Now do the same for each alias of this symbol */
5039 aliases
= SYMBOL_ALIASES (sym
);
5042 if (SYMBOL_CLASS (rsym
) == LOC_BLOCK
)
5044 fix_common_block (rsym
,
5045 SYMBOL_VALUE_ADDRESS (msymbol
));
5049 SYMBOL_VALUE_ADDRESS (rsym
)
5050 = SYMBOL_VALUE_ADDRESS (msymbol
);
5052 SYMBOL_SECTION (rsym
) = SYMBOL_SECTION (msymbol
);
5055 rsym
= aliases
->sym
;
5056 aliases
= aliases
->next
;
5065 sym
= SYMBOL_VALUE_CHAIN (prev
);
5069 sym
= global_sym_chain
[hash
];
5075 sym
= SYMBOL_VALUE_CHAIN (sym
);
5079 if (resolve_objfile
== objfile
)
5081 resolve_objfile
= objfile
;
5084 /* Change the storage class of any remaining unresolved globals to
5085 LOC_UNRESOLVED and remove them from the chain. */
5086 for (hash
= 0; hash
< HASHSIZE
; hash
++)
5088 sym
= global_sym_chain
[hash
];
5092 sym
= SYMBOL_VALUE_CHAIN (sym
);
5094 /* Change the symbol address from the misleading chain value
5096 SYMBOL_VALUE_ADDRESS (prev
) = 0;
5098 /* Complain about unresolved common block symbols. */
5099 if (SYMBOL_CLASS (prev
) == LOC_STATIC
)
5100 SYMBOL_CLASS (prev
) = LOC_UNRESOLVED
;
5102 complain (&unresolved_sym_chain_complaint
,
5103 objfile
->name
, SYMBOL_NAME (prev
));
5106 memset (global_sym_chain
, 0, sizeof (global_sym_chain
));
5109 /* Initialize anything that needs initializing when starting to read
5110 a fresh piece of a symbol file, e.g. reading in the stuff corresponding
5114 stabsread_init (void)
5118 /* Initialize anything that needs initializing when a completely new
5119 symbol file is specified (not just adding some symbols from another
5120 file, e.g. a shared library). */
5123 stabsread_new_init (void)
5125 /* Empty the hash table of global syms looking for values. */
5126 memset (global_sym_chain
, 0, sizeof (global_sym_chain
));
5129 /* Initialize anything that needs initializing at the same time as
5130 start_symtab() is called. */
5135 global_stabs
= NULL
; /* AIX COFF */
5136 /* Leave FILENUM of 0 free for builtin types and this file's types. */
5137 n_this_object_header_files
= 1;
5138 type_vector_length
= 0;
5139 type_vector
= (struct type
**) 0;
5141 /* FIXME: If common_block_name is not already NULL, we should complain(). */
5142 common_block_name
= NULL
;
5147 /* Call after end_symtab() */
5154 xfree (type_vector
);
5157 type_vector_length
= 0;
5158 previous_stab_code
= 0;
5162 finish_global_stabs (struct objfile
*objfile
)
5166 patch_block_stabs (global_symbols
, global_stabs
, objfile
);
5167 xfree (global_stabs
);
5168 global_stabs
= NULL
;
5172 /* Initializer for this module */
5175 _initialize_stabsread (void)
5177 undef_types_allocated
= 20;
5178 undef_types_length
= 0;
5179 undef_types
= (struct type
**)
5180 xmalloc (undef_types_allocated
* sizeof (struct type
*));