1 /* Support routines for decoding "stabs" debugging information format.
2 Copyright 1986, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 1997
3 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21 /* Support routines for reading and decoding debugging information in
22 the "stabs" format. This format is used with many systems that use
23 the a.out object file format, as well as some systems that use
24 COFF or ELF where the stabs data is placed in a special section.
25 Avoid placing any object file format specific code in this file. */
28 #include "gdb_string.h"
33 #include "expression.h"
36 #include "aout/stab_gnu.h" /* We always use GNU stabs, not native */
38 #include "aout/aout64.h"
39 #include "gdb-stabs.h"
41 #include "complaints.h"
47 /* Ask stabsread.h to define the vars it normally declares `extern'. */
49 #include "stabsread.h" /* Our own declarations */
52 /* The routines that read and process a complete stabs for a C struct or
53 C++ class pass lists of data member fields and lists of member function
54 fields in an instance of a field_info structure, as defined below.
55 This is part of some reorganization of low level C++ support and is
56 expected to eventually go away... (FIXME) */
62 struct nextfield
*next
;
64 /* This is the raw visibility from the stab. It is not checked
65 for being one of the visibilities we recognize, so code which
66 examines this field better be able to deal. */
71 struct next_fnfieldlist
73 struct next_fnfieldlist
*next
;
74 struct fn_fieldlist fn_fieldlist
;
79 read_one_struct_field
PARAMS ((struct field_info
*, char **, char *,
80 struct type
*, struct objfile
*));
83 get_substring
PARAMS ((char **, int));
86 dbx_alloc_type
PARAMS ((int [2], struct objfile
*));
88 static long read_huge_number
PARAMS ((char **, int, int *));
90 static struct type
*error_type
PARAMS ((char **, struct objfile
*));
93 patch_block_stabs
PARAMS ((struct pending
*, struct pending_stabs
*,
97 fix_common_block
PARAMS ((struct symbol
*, int));
100 read_type_number
PARAMS ((char **, int *));
103 read_range_type
PARAMS ((char **, int [2], struct objfile
*));
106 read_sun_builtin_type
PARAMS ((char **, int [2], struct objfile
*));
109 read_sun_floating_type
PARAMS ((char **, int [2], struct objfile
*));
112 read_enum_type
PARAMS ((char **, struct type
*, struct objfile
*));
115 rs6000_builtin_type
PARAMS ((int));
118 read_member_functions
PARAMS ((struct field_info
*, char **, struct type
*,
122 read_struct_fields
PARAMS ((struct field_info
*, char **, struct type
*,
126 read_baseclasses
PARAMS ((struct field_info
*, char **, struct type
*,
130 read_tilde_fields
PARAMS ((struct field_info
*, char **, struct type
*,
134 attach_fn_fields_to_type
PARAMS ((struct field_info
*, struct type
*));
137 attach_fields_to_type
PARAMS ((struct field_info
*, struct type
*,
141 read_struct_type
PARAMS ((char **, struct type
*, struct objfile
*));
144 read_array_type
PARAMS ((char **, struct type
*, struct objfile
*));
146 static struct type
**
147 read_args
PARAMS ((char **, int, struct objfile
*));
150 read_cpp_abbrev
PARAMS ((struct field_info
*, char **, struct type
*,
153 /* new functions added for cfront support */
156 copy_cfront_struct_fields
PARAMS ((struct field_info
*, struct type
*,
160 get_cfront_method_physname
PARAMS ((char *));
163 read_cfront_baseclasses
PARAMS ((struct field_info
*, char **,
164 struct type
*, struct objfile
*));
167 read_cfront_static_fields
PARAMS ((struct field_info
*, char**,
168 struct type
*, struct objfile
*));
170 read_cfront_member_functions
PARAMS ((struct field_info
*, char **,
171 struct type
*, struct objfile
*));
173 /* end new functions added for cfront support */
177 static const char vptr_name
[] = { '_','v','p','t','r',CPLUS_MARKER
,'\0' };
178 static const char vb_name
[] = { '_','v','b',CPLUS_MARKER
,'\0' };
180 /* Define this as 1 if a pcc declaration of a char or short argument
181 gives the correct address. Otherwise assume pcc gives the
182 address of the corresponding int, which is not the same on a
183 big-endian machine. */
185 #ifndef BELIEVE_PCC_PROMOTION
186 #define BELIEVE_PCC_PROMOTION 0
189 struct complaint invalid_cpp_abbrev_complaint
=
190 {"invalid C++ abbreviation `%s'", 0, 0};
192 struct complaint invalid_cpp_type_complaint
=
193 {"C++ abbreviated type name unknown at symtab pos %d", 0, 0};
195 struct complaint member_fn_complaint
=
196 {"member function type missing, got '%c'", 0, 0};
198 struct complaint const_vol_complaint
=
199 {"const/volatile indicator missing, got '%c'", 0, 0};
201 struct complaint error_type_complaint
=
202 {"debug info mismatch between compiler and debugger", 0, 0};
204 struct complaint invalid_member_complaint
=
205 {"invalid (minimal) member type data format at symtab pos %d.", 0, 0};
207 struct complaint range_type_base_complaint
=
208 {"base type %d of range type is not defined", 0, 0};
210 struct complaint reg_value_complaint
=
211 {"register number %d too large (max %d) in symbol %s", 0, 0};
213 struct complaint vtbl_notfound_complaint
=
214 {"virtual function table pointer not found when defining class `%s'", 0, 0};
216 struct complaint unrecognized_cplus_name_complaint
=
217 {"Unknown C++ symbol name `%s'", 0, 0};
219 struct complaint rs6000_builtin_complaint
=
220 {"Unknown builtin type %d", 0, 0};
222 struct complaint unresolved_sym_chain_complaint
=
223 {"%s: common block `%s' from global_sym_chain unresolved", 0, 0};
225 struct complaint stabs_general_complaint
=
228 /* Make a list of forward references which haven't been defined. */
230 static struct type
**undef_types
;
231 static int undef_types_allocated
;
232 static int undef_types_length
;
233 static struct symbol
*current_symbol
= NULL
;
235 /* Check for and handle cretinous stabs symbol name continuation! */
236 #define STABS_CONTINUE(pp,objfile) \
238 if (**(pp) == '\\' || (**(pp) == '?' && (*(pp))[1] == '\0')) \
239 *(pp) = next_symbol_text (objfile); \
242 /* FIXME: These probably should be our own types (like rs6000_builtin_type
243 has its own types) rather than builtin_type_*. */
244 static struct type
**os9k_type_vector
[] = {
250 &builtin_type_unsigned_char
,
251 &builtin_type_unsigned_short
,
252 &builtin_type_unsigned_long
,
253 &builtin_type_unsigned_int
,
255 &builtin_type_double
,
257 &builtin_type_long_double
260 static void os9k_init_type_vector
PARAMS ((struct type
**));
263 os9k_init_type_vector(tv
)
267 for (i
=0; i
<sizeof(os9k_type_vector
)/sizeof(struct type
**); i
++)
268 tv
[i
] = (os9k_type_vector
[i
] == 0 ? 0 : *(os9k_type_vector
[i
]));
271 /* Look up a dbx type-number pair. Return the address of the slot
272 where the type for that number-pair is stored.
273 The number-pair is in TYPENUMS.
275 This can be used for finding the type associated with that pair
276 or for associating a new type with the pair. */
279 dbx_lookup_type (typenums
)
282 register int filenum
= typenums
[0];
283 register int index
= typenums
[1];
285 register int real_filenum
;
286 register struct header_file
*f
;
289 if (filenum
== -1) /* -1,-1 is for temporary types. */
292 if (filenum
< 0 || filenum
>= n_this_object_header_files
)
294 static struct complaint msg
= {"\
295 Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.",
297 complain (&msg
, filenum
, index
, symnum
);
305 /* Caller wants address of address of type. We think
306 that negative (rs6k builtin) types will never appear as
307 "lvalues", (nor should they), so we stuff the real type
308 pointer into a temp, and return its address. If referenced,
309 this will do the right thing. */
310 static struct type
*temp_type
;
312 temp_type
= rs6000_builtin_type(index
);
316 /* Type is defined outside of header files.
317 Find it in this object file's type vector. */
318 if (index
>= type_vector_length
)
320 old_len
= type_vector_length
;
323 type_vector_length
= INITIAL_TYPE_VECTOR_LENGTH
;
324 type_vector
= (struct type
**)
325 xmalloc (type_vector_length
* sizeof (struct type
*));
327 while (index
>= type_vector_length
)
329 type_vector_length
*= 2;
331 type_vector
= (struct type
**)
332 xrealloc ((char *) type_vector
,
333 (type_vector_length
* sizeof (struct type
*)));
334 memset (&type_vector
[old_len
], 0,
335 (type_vector_length
- old_len
) * sizeof (struct type
*));
338 /* Deal with OS9000 fundamental types. */
339 os9k_init_type_vector (type_vector
);
341 return (&type_vector
[index
]);
345 real_filenum
= this_object_header_files
[filenum
];
347 if (real_filenum
>= N_HEADER_FILES (current_objfile
))
349 struct type
*temp_type
;
350 struct type
**temp_type_p
;
352 warning ("GDB internal error: bad real_filenum");
355 temp_type
= init_type (TYPE_CODE_ERROR
, 0, 0, NULL
, NULL
);
356 temp_type_p
= (struct type
**) xmalloc (sizeof (struct type
*));
357 *temp_type_p
= temp_type
;
361 f
= HEADER_FILES (current_objfile
) + real_filenum
;
363 f_orig_length
= f
->length
;
364 if (index
>= f_orig_length
)
366 while (index
>= f
->length
)
370 f
->vector
= (struct type
**)
371 xrealloc ((char *) f
->vector
, f
->length
* sizeof (struct type
*));
372 memset (&f
->vector
[f_orig_length
], 0,
373 (f
->length
- f_orig_length
) * sizeof (struct type
*));
375 return (&f
->vector
[index
]);
379 /* Make sure there is a type allocated for type numbers TYPENUMS
380 and return the type object.
381 This can create an empty (zeroed) type object.
382 TYPENUMS may be (-1, -1) to return a new type object that is not
383 put into the type vector, and so may not be referred to by number. */
386 dbx_alloc_type (typenums
, objfile
)
388 struct objfile
*objfile
;
390 register struct type
**type_addr
;
392 if (typenums
[0] == -1)
394 return (alloc_type (objfile
));
397 type_addr
= dbx_lookup_type (typenums
);
399 /* If we are referring to a type not known at all yet,
400 allocate an empty type for it.
401 We will fill it in later if we find out how. */
404 *type_addr
= alloc_type (objfile
);
410 /* for all the stabs in a given stab vector, build appropriate types
411 and fix their symbols in given symbol vector. */
414 patch_block_stabs (symbols
, stabs
, objfile
)
415 struct pending
*symbols
;
416 struct pending_stabs
*stabs
;
417 struct objfile
*objfile
;
427 /* for all the stab entries, find their corresponding symbols and
428 patch their types! */
430 for (ii
= 0; ii
< stabs
->count
; ++ii
)
432 name
= stabs
->stab
[ii
];
433 pp
= (char*) strchr (name
, ':');
437 pp
= (char *)strchr(pp
, ':');
439 sym
= find_symbol_in_list (symbols
, name
, pp
-name
);
442 /* FIXME-maybe: it would be nice if we noticed whether
443 the variable was defined *anywhere*, not just whether
444 it is defined in this compilation unit. But neither
445 xlc or GCC seem to need such a definition, and until
446 we do psymtabs (so that the minimal symbols from all
447 compilation units are available now), I'm not sure
448 how to get the information. */
450 /* On xcoff, if a global is defined and never referenced,
451 ld will remove it from the executable. There is then
452 a N_GSYM stab for it, but no regular (C_EXT) symbol. */
453 sym
= (struct symbol
*)
454 obstack_alloc (&objfile
->symbol_obstack
,
455 sizeof (struct symbol
));
457 memset (sym
, 0, sizeof (struct symbol
));
458 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
459 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
461 obsavestring (name
, pp
- name
, &objfile
->symbol_obstack
);
463 if (*(pp
-1) == 'F' || *(pp
-1) == 'f')
465 /* I don't think the linker does this with functions,
466 so as far as I know this is never executed.
467 But it doesn't hurt to check. */
469 lookup_function_type (read_type (&pp
, objfile
));
473 SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
475 add_symbol_to_list (sym
, &global_symbols
);
480 if (*(pp
-1) == 'F' || *(pp
-1) == 'f')
483 lookup_function_type (read_type (&pp
, objfile
));
487 SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
495 /* Read a number by which a type is referred to in dbx data,
496 or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
497 Just a single number N is equivalent to (0,N).
498 Return the two numbers by storing them in the vector TYPENUMS.
499 TYPENUMS will then be used as an argument to dbx_lookup_type.
501 Returns 0 for success, -1 for error. */
504 read_type_number (pp
, typenums
)
506 register int *typenums
;
512 typenums
[0] = read_huge_number (pp
, ',', &nbits
);
513 if (nbits
!= 0) return -1;
514 typenums
[1] = read_huge_number (pp
, ')', &nbits
);
515 if (nbits
!= 0) return -1;
520 typenums
[1] = read_huge_number (pp
, 0, &nbits
);
521 if (nbits
!= 0) return -1;
527 #if !defined (REG_STRUCT_HAS_ADDR)
528 #define REG_STRUCT_HAS_ADDR(gcc_p,type) 0
531 #define VISIBILITY_PRIVATE '0' /* Stabs character for private field */
532 #define VISIBILITY_PROTECTED '1' /* Stabs character for protected fld */
533 #define VISIBILITY_PUBLIC '2' /* Stabs character for public field */
534 #define VISIBILITY_IGNORE '9' /* Optimized out or zero length */
536 #define CFRONT_VISIBILITY_PRIVATE '2' /* Stabs character for private field */
537 #define CFRONT_VISIBILITY_PUBLIC '1' /* Stabs character for public field */
539 /* This code added to support parsing of ARM/Cfront stabs strings */
541 /* Get substring from string up to char c, advance string pointer past
562 /* Physname gets strcat'd onto sname in order to recreate the mangled
563 name (see funtion gdb_mangle_name in gdbtypes.c). For cfront, make
564 the physname look like that of g++ - take out the initial mangling
565 eg: for sname="a" and fname="foo__1aFPFs_i" return "FPFs_i" */
568 get_cfront_method_physname (fname
)
572 /* FIXME would like to make this generic for g++ too, but
573 that is already handled in read_member_funcctions */
576 /* search ahead to find the start of the mangled suffix */
577 if (*p
== '_' && *(p
+1)=='_') /* compiler generated; probably a ctor/dtor */
579 while (p
&& ((p
+1) - fname
) < strlen (fname
) && *(p
+1) != '_')
581 if (!(p
&& *p
== '_' && *(p
+1) == '_'))
582 error ("Invalid mangled function name %s",fname
);
583 p
+= 2; /* advance past '__' */
585 /* struct name length and name of type should come next; advance past it */
588 len
= len
* 10 + (*p
- '0');
596 /* Read base classes within cfront class definition.
597 eg: A:ZcA;1@Bpub v2@Bvirpri;__ct__1AFv func__1AFv *sfunc__1AFv ;as__1A ;;
600 A:ZcA;;foopri__1AFv foopro__1AFv __ct__1AFv __ct__1AFRC1A foopub__1AFv ;;;
605 read_cfront_baseclasses (fip
, pp
, type
, objfile
)
606 struct field_info
*fip
;
607 struct objfile
*objfile
;
611 static struct complaint msg_unknown
= {"\
612 Unsupported token in stabs string %s.\n",
614 static struct complaint msg_notfound
= {"\
615 Unable to find base type for %s.\n",
620 struct nextfield
*new;
622 if (**pp
== ';') /* no base classes; return */
628 /* first count base classes so we can allocate space before parsing */
629 for (p
= *pp
; p
&& *p
&& *p
!= ';'; p
++)
634 bnum
++; /* add one more for last one */
636 /* now parse the base classes until we get to the start of the methods
637 (code extracted and munged from read_baseclasses) */
638 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
639 TYPE_N_BASECLASSES(type
) = bnum
;
643 int num_bytes
= B_BYTES (TYPE_N_BASECLASSES (type
));
646 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
647 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
649 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), TYPE_N_BASECLASSES (type
));
651 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
653 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
654 make_cleanup (free
, new);
655 memset (new, 0, sizeof (struct nextfield
));
656 new -> next
= fip
-> list
;
658 FIELD_BITSIZE (new->field
) = 0; /* this should be an unpacked field! */
660 STABS_CONTINUE (pp
, objfile
);
662 /* virtual? eg: v2@Bvir */
665 SET_TYPE_FIELD_VIRTUAL (type
, i
);
669 /* access? eg: 2@Bvir */
670 /* Note: protected inheritance not supported in cfront */
673 case CFRONT_VISIBILITY_PRIVATE
:
674 new -> visibility
= VISIBILITY_PRIVATE
;
676 case CFRONT_VISIBILITY_PUBLIC
:
677 new -> visibility
= VISIBILITY_PUBLIC
;
680 /* Bad visibility format. Complain and treat it as
683 static struct complaint msg
= {
684 "Unknown visibility `%c' for baseclass", 0, 0};
685 complain (&msg
, new -> visibility
);
686 new -> visibility
= VISIBILITY_PUBLIC
;
690 /* "@" comes next - eg: @Bvir */
693 complain (&msg_unknown
, *pp
);
699 /* Set the bit offset of the portion of the object corresponding
700 to this baseclass. Always zero in the absence of
701 multiple inheritance. */
702 /* Unable to read bit position from stabs;
703 Assuming no multiple inheritance for now FIXME! */
704 /* We may have read this in the structure definition;
705 now we should fixup the members to be the actual base classes */
706 FIELD_BITPOS (new->field
) = 0;
708 /* Get the base class name and type */
710 char * bname
; /* base class name */
711 struct symbol
* bsym
; /* base class */
713 p1
= strchr(*pp
,' ');
714 p2
= strchr(*pp
,';');
716 bname
= get_substring(pp
,' ');
718 bname
= get_substring(pp
,';');
719 if (!bname
|| !*bname
)
721 complain (&msg_unknown
, *pp
);
724 /* FIXME! attach base info to type */
725 bsym
= lookup_symbol (bname
, 0, STRUCT_NAMESPACE
, 0, 0); /*demangled_name*/
728 new -> field
.type
= SYMBOL_TYPE(bsym
);
729 new -> field
.name
= type_name_no_tag (new -> field
.type
);
733 complain (&msg_notfound
, *pp
);
738 /* If more base classes to parse, loop again.
739 We ate the last ' ' or ';' in get_substring,
740 so on exit we will have skipped the trailing ';' */
741 /* if invalid, return 0; add code to detect - FIXME! */
746 /* read cfront member functions.
747 pp points to string starting with list of functions
748 eg: A:ZcA;1@Bpub v2@Bvirpri;__ct__1AFv func__1AFv *sfunc__1AFv ;as__1A ;;
749 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
750 A:ZcA;;foopri__1AFv foopro__1AFv __ct__1AFv __ct__1AFRC1A foopub__1AFv ;;;
751 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
755 read_cfront_member_functions(fip
, pp
, type
, objfile
)
756 struct field_info
*fip
;
759 struct objfile
*objfile
;
761 /* This code extracted from read_member_functions
762 so as to do the similar thing for our funcs */
766 /* Total number of member functions defined in this class. If the class
767 defines two `f' functions, and one `g' function, then this will have
769 int total_length
= 0;
773 struct next_fnfield
*next
;
774 struct fn_field fn_field
;
776 struct type
*look_ahead_type
;
777 struct next_fnfieldlist
*new_fnlist
;
778 struct next_fnfield
*new_sublist
;
781 struct symbol
* ref_func
=0;
783 /* Process each list until we find something that is not a member function
784 or find the end of the functions. */
786 /* eg: p = "__ct__1AFv foo__1AFv ;;;" */
787 STABS_CONTINUE (pp
, objfile
); /* handle \\ */
788 while (**pp
!=';' && (fname
= get_substring(pp
,' '),fname
))
793 if (fname
[0]=='*') /* static member */
799 ref_func
= lookup_symbol (fname
, 0, VAR_NAMESPACE
, 0, 0); /*demangled_name*/
802 static struct complaint msg
= {"\
803 Unable to find function symbol for %s\n",
805 complain (&msg
, fname
);
809 look_ahead_type
= NULL
;
812 new_fnlist
= (struct next_fnfieldlist
*)
813 xmalloc (sizeof (struct next_fnfieldlist
));
814 make_cleanup (free
, new_fnlist
);
815 memset (new_fnlist
, 0, sizeof (struct next_fnfieldlist
));
817 /* The following is code to work around cfront generated stabs.
818 The stabs contains full mangled name for each field.
819 We try to demangle the name and extract the field name out of it. */
821 char *dem
, *dem_p
, *dem_args
;
823 dem
= cplus_demangle (fname
, DMGL_ANSI
| DMGL_PARAMS
);
826 dem_p
= strrchr (dem
, ':');
827 if (dem_p
!= 0 && *(dem_p
-1)==':')
829 /* get rid of args */
830 dem_args
= strchr (dem_p
, '(');
831 if (dem_args
== NULL
)
832 dem_len
= strlen(dem_p
);
834 dem_len
= dem_args
- dem_p
;
836 obsavestring (dem_p
, dem_len
, &objfile
-> type_obstack
);
841 obsavestring (fname
, strlen(fname
), &objfile
-> type_obstack
);
843 } /* end of code for cfront work around */
845 new_fnlist
-> fn_fieldlist
.name
= main_fn_name
;
847 /*-------------------------------------------------*/
848 /* Set up the sublists
849 Sublists are stuff like args, static, visibility, etc.
850 so in ARM, we have to set that info some other way.
851 Multiple sublists happen if overloading
852 eg: foo::26=##1;:;2A.;
853 In g++, we'd loop here thru all the sublists... */
855 (struct next_fnfield
*) xmalloc (sizeof (struct next_fnfield
));
856 make_cleanup (free
, new_sublist
);
857 memset (new_sublist
, 0, sizeof (struct next_fnfield
));
859 /* eat 1; from :;2A.; */
860 new_sublist
-> fn_field
.type
= SYMBOL_TYPE(ref_func
); /* normally takes a read_type */
861 /* make this type look like a method stub for gdb */
862 TYPE_FLAGS (new_sublist
-> fn_field
.type
) |= TYPE_FLAG_STUB
;
863 TYPE_CODE (new_sublist
-> fn_field
.type
) = TYPE_CODE_METHOD
;
865 /* If this is just a stub, then we don't have the real name here. */
866 if (TYPE_FLAGS (new_sublist
-> fn_field
.type
) & TYPE_FLAG_STUB
)
868 if (!TYPE_DOMAIN_TYPE (new_sublist
-> fn_field
.type
))
869 TYPE_DOMAIN_TYPE (new_sublist
-> fn_field
.type
) = type
;
870 new_sublist
-> fn_field
.is_stub
= 1;
872 /* physname used later in mangling; eg PFs_i,5 for foo__1aFPFs_i
873 physname gets strcat'd in order to recreate the onto mangled name */
874 pname
= get_cfront_method_physname(fname
);
875 new_sublist
-> fn_field
.physname
= savestring (pname
, strlen(pname
));
878 /* Set this member function's visibility fields.
879 Unable to distinguish access from stabs definition!
880 Assuming public for now. FIXME!
881 (for private, set new_sublist->fn_field.is_private = 1,
882 for public, set new_sublist->fn_field.is_protected = 1) */
884 /* Unable to distinguish const/volatile from stabs definition!
885 Assuming normal for now. FIXME! */
887 new_sublist
-> fn_field
.is_const
= 0;
888 new_sublist
-> fn_field
.is_volatile
= 0; /* volatile not implemented in cfront */
890 /* set virtual/static function info
891 How to get vtable offsets ?
892 Assuming normal for now FIXME!!
893 For vtables, figure out from whence this virtual function came.
894 It may belong to virtual function table of
895 one of its baseclasses.
897 new_sublist -> fn_field.voffset = vtable offset,
898 new_sublist -> fn_field.fcontext = look_ahead_type;
899 where look_ahead_type is type of baseclass */
901 new_sublist
-> fn_field
.voffset
= VOFFSET_STATIC
;
902 else /* normal member function. */
903 new_sublist
-> fn_field
.voffset
= 0;
904 new_sublist
-> fn_field
.fcontext
= 0;
907 /* prepare new sublist */
908 new_sublist
-> next
= sublist
;
909 sublist
= new_sublist
;
911 /* In g++, we loop thu sublists - now we set from function */
913 new_fnlist
-> fn_fieldlist
.fn_fields
= (struct fn_field
*)
914 obstack_alloc (&objfile
-> type_obstack
,
915 sizeof (struct fn_field
) * length
);
916 memset (new_fnlist
-> fn_fieldlist
.fn_fields
, 0,
917 sizeof (struct fn_field
) * length
);
918 for (i
= length
; (i
--, sublist
); sublist
= sublist
-> next
)
920 new_fnlist
-> fn_fieldlist
.fn_fields
[i
] = sublist
-> fn_field
;
923 new_fnlist
-> fn_fieldlist
.length
= length
;
924 new_fnlist
-> next
= fip
-> fnlist
;
925 fip
-> fnlist
= new_fnlist
;
927 total_length
+= length
;
928 STABS_CONTINUE (pp
, objfile
); /* handle \\ */
933 /* type should already have space */
934 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
935 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * nfn_fields
);
936 memset (TYPE_FN_FIELDLISTS (type
), 0,
937 sizeof (struct fn_fieldlist
) * nfn_fields
);
938 TYPE_NFN_FIELDS (type
) = nfn_fields
;
939 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
942 /* end of scope for reading member func */
945 /* skip trailing ';' and bump count of number of fields seen */
953 /* This routine fixes up partial cfront types that were created
954 while parsing the stabs. The main need for this function is
955 to add information such as methods to classes.
956 Examples of "p": "sA;;__ct__1AFv foo__1AFv ;;;" */
958 resolve_cfront_continuation(objfile
, sym
, p
)
959 struct objfile
* objfile
;
963 struct symbol
* ref_sym
=0;
965 /* snarfed from read_struct_type */
966 struct field_info fi
;
968 struct cleanup
*back_to
;
970 /* need to make sure that fi isn't gunna conflict with struct
971 in case struct already had some fnfs */
974 back_to
= make_cleanup (null_cleanup
, 0);
976 /* we only accept structs, classes and unions at the moment.
977 Other continuation types include t (typedef), r (long dbl), ...
978 We may want to add support for them as well;
979 right now they are handled by duplicating the symbol information
980 into the type information (see define_symbol) */
981 if (*p
!= 's' /* structs */
982 && *p
!= 'c' /* class */
983 && *p
!= 'u') /* union */
984 return; /* only handle C++ types */
987 /* get symbol typs name and validate
988 eg: p = "A;;__ct__1AFv foo__1AFv ;;;" */
989 sname
= get_substring(&p
,';');
990 if (!sname
|| strcmp(sname
,SYMBOL_NAME(sym
)))
991 error("Internal error: base symbol type name does not match\n");
993 /* find symbol's internal gdb reference */
994 ref_sym
= lookup_symbol (SYMBOL_NAME(sym
), 0, STRUCT_NAMESPACE
, 0, 0); /*demangled_name*/
995 /* This is the real sym that we want;
996 sym was a temp hack to make debugger happy */
997 /* ref_sym should already have space */
998 type
= SYMBOL_TYPE(ref_sym
);
1001 /* Now read the baseclasses, if any, read the regular C struct or C++
1002 class member fields, attach the fields to the type, read the C++
1003 member functions, attach them to the type, and then read any tilde
1004 field (baseclass specifier for the class holding the main vtable). */
1006 if (!read_cfront_baseclasses (&fi
, &p
, type
, objfile
)
1007 /* g++ does this next, but cfront already did this:
1008 || !read_struct_fields (&fi, &p, type, objfile) */
1009 || !copy_cfront_struct_fields (&fi
, type
, objfile
)
1010 || !read_cfront_member_functions (&fi
, &p
, type
, objfile
)
1011 || !read_cfront_static_fields(&fi
, &p
, type
, objfile
)
1012 || !attach_fields_to_type (&fi
, type
, objfile
)
1013 || !attach_fn_fields_to_type (&fi
, type
)
1014 /* g++ does this next, but cfront doesn't seem to have this:
1015 || !read_tilde_fields (&fi, &p, type, objfile) */
1018 type
= error_type (&p
, objfile
);
1021 do_cleanups (back_to
);
1023 /* End of code added to support parsing of ARM/Cfront stabs strings */
1028 define_symbol (valu
, string
, desc
, type
, objfile
)
1033 struct objfile
*objfile
;
1035 register struct symbol
*sym
;
1036 char *p
= (char *) strchr (string
, ':');
1041 /* We would like to eliminate nameless symbols, but keep their types.
1042 E.g. stab entry ":t10=*2" should produce a type 10, which is a pointer
1043 to type 2, but, should not create a symbol to address that type. Since
1044 the symbol will be nameless, there is no way any user can refer to it. */
1048 /* Ignore syms with empty names. */
1052 /* Ignore old-style symbols from cc -go */
1062 /* If a nameless stab entry, all we need is the type, not the symbol.
1063 e.g. ":t10=*2" or a nameless enum like " :T16=ered:0,green:1,blue:2,;" */
1064 nameless
= (p
== string
|| ((string
[0] == ' ') && (string
[1] == ':')));
1066 current_symbol
= sym
= (struct symbol
*)
1067 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
1068 memset (sym
, 0, sizeof (struct symbol
));
1070 switch (type
& N_TYPE
)
1073 SYMBOL_SECTION(sym
) = SECT_OFF_TEXT
;
1076 SYMBOL_SECTION(sym
) = SECT_OFF_DATA
;
1079 SYMBOL_SECTION(sym
) = SECT_OFF_BSS
;
1083 if (processing_gcc_compilation
)
1085 /* GCC 2.x puts the line number in desc. SunOS apparently puts in the
1086 number of bytes occupied by a type or object, which we ignore. */
1087 SYMBOL_LINE(sym
) = desc
;
1091 SYMBOL_LINE(sym
) = 0; /* unknown */
1094 if (is_cplus_marker (string
[0]))
1096 /* Special GNU C++ names. */
1100 SYMBOL_NAME (sym
) = obsavestring ("this", strlen ("this"),
1101 &objfile
-> symbol_obstack
);
1104 case 'v': /* $vtbl_ptr_type */
1105 /* Was: SYMBOL_NAME (sym) = "vptr"; */
1109 SYMBOL_NAME (sym
) = obsavestring ("eh_throw", strlen ("eh_throw"),
1110 &objfile
-> symbol_obstack
);
1114 /* This was an anonymous type that was never fixed up. */
1117 #ifdef STATIC_TRANSFORM_NAME
1119 /* SunPRO (3.0 at least) static variable encoding. */
1124 complain (&unrecognized_cplus_name_complaint
, string
);
1125 goto normal
; /* Do *something* with it */
1131 SYMBOL_LANGUAGE (sym
) = current_subfile
-> language
;
1132 SYMBOL_NAME (sym
) = (char *)
1133 obstack_alloc (&objfile
-> symbol_obstack
, ((p
- string
) + 1));
1134 /* Open-coded memcpy--saves function call time. */
1135 /* FIXME: Does it really? Try replacing with simple strcpy and
1136 try it on an executable with a large symbol table. */
1137 /* FIXME: considering that gcc can open code memcpy anyway, I
1138 doubt it. xoxorich. */
1140 register char *p1
= string
;
1141 register char *p2
= SYMBOL_NAME (sym
);
1149 /* If this symbol is from a C++ compilation, then attempt to cache the
1150 demangled form for future reference. This is a typical time versus
1151 space tradeoff, that was decided in favor of time because it sped up
1152 C++ symbol lookups by a factor of about 20. */
1154 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
1158 /* Determine the type of name being defined. */
1160 /* Getting GDB to correctly skip the symbol on an undefined symbol
1161 descriptor and not ever dump core is a very dodgy proposition if
1162 we do things this way. I say the acorn RISC machine can just
1163 fix their compiler. */
1164 /* The Acorn RISC machine's compiler can put out locals that don't
1165 start with "234=" or "(3,4)=", so assume anything other than the
1166 deftypes we know how to handle is a local. */
1167 if (!strchr ("cfFGpPrStTvVXCR", *p
))
1169 if (isdigit (*p
) || *p
== '(' || *p
== '-')
1178 /* c is a special case, not followed by a type-number.
1179 SYMBOL:c=iVALUE for an integer constant symbol.
1180 SYMBOL:c=rVALUE for a floating constant symbol.
1181 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
1182 e.g. "b:c=e6,0" for "const b = blob1"
1183 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
1186 SYMBOL_CLASS (sym
) = LOC_CONST
;
1187 SYMBOL_TYPE (sym
) = error_type (&p
, objfile
);
1188 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1189 add_symbol_to_list (sym
, &file_symbols
);
1197 double d
= atof (p
);
1200 /* FIXME-if-picky-about-floating-accuracy: Should be using
1201 target arithmetic to get the value. real.c in GCC
1202 probably has the necessary code. */
1204 /* FIXME: lookup_fundamental_type is a hack. We should be
1205 creating a type especially for the type of float constants.
1206 Problem is, what type should it be?
1208 Also, what should the name of this type be? Should we
1209 be using 'S' constants (see stabs.texinfo) instead? */
1211 SYMBOL_TYPE (sym
) = lookup_fundamental_type (objfile
,
1214 obstack_alloc (&objfile
-> symbol_obstack
,
1215 TYPE_LENGTH (SYMBOL_TYPE (sym
)));
1216 store_floating (dbl_valu
, TYPE_LENGTH (SYMBOL_TYPE (sym
)), d
);
1217 SYMBOL_VALUE_BYTES (sym
) = dbl_valu
;
1218 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
1223 /* Defining integer constants this way is kind of silly,
1224 since 'e' constants allows the compiler to give not
1225 only the value, but the type as well. C has at least
1226 int, long, unsigned int, and long long as constant
1227 types; other languages probably should have at least
1228 unsigned as well as signed constants. */
1230 /* We just need one int constant type for all objfiles.
1231 It doesn't depend on languages or anything (arguably its
1232 name should be a language-specific name for a type of
1233 that size, but I'm inclined to say that if the compiler
1234 wants a nice name for the type, it can use 'e'). */
1235 static struct type
*int_const_type
;
1237 /* Yes, this is as long as a *host* int. That is because we
1239 if (int_const_type
== NULL
)
1241 init_type (TYPE_CODE_INT
,
1242 sizeof (int) * HOST_CHAR_BIT
/ TARGET_CHAR_BIT
, 0,
1244 (struct objfile
*)NULL
);
1245 SYMBOL_TYPE (sym
) = int_const_type
;
1246 SYMBOL_VALUE (sym
) = atoi (p
);
1247 SYMBOL_CLASS (sym
) = LOC_CONST
;
1251 /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value
1252 can be represented as integral.
1253 e.g. "b:c=e6,0" for "const b = blob1"
1254 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
1256 SYMBOL_CLASS (sym
) = LOC_CONST
;
1257 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1261 SYMBOL_TYPE (sym
) = error_type (&p
, objfile
);
1266 /* If the value is too big to fit in an int (perhaps because
1267 it is unsigned), or something like that, we silently get
1268 a bogus value. The type and everything else about it is
1269 correct. Ideally, we should be using whatever we have
1270 available for parsing unsigned and long long values,
1272 SYMBOL_VALUE (sym
) = atoi (p
);
1277 SYMBOL_CLASS (sym
) = LOC_CONST
;
1278 SYMBOL_TYPE (sym
) = error_type (&p
, objfile
);
1281 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1282 add_symbol_to_list (sym
, &file_symbols
);
1286 /* The name of a caught exception. */
1287 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1288 SYMBOL_CLASS (sym
) = LOC_LABEL
;
1289 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1290 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1291 add_symbol_to_list (sym
, &local_symbols
);
1295 /* A static function definition. */
1296 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1297 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1298 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1299 add_symbol_to_list (sym
, &file_symbols
);
1300 /* fall into process_function_types. */
1302 process_function_types
:
1303 /* Function result types are described as the result type in stabs.
1304 We need to convert this to the function-returning-type-X type
1305 in GDB. E.g. "int" is converted to "function returning int". */
1306 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_FUNC
)
1307 SYMBOL_TYPE (sym
) = lookup_function_type (SYMBOL_TYPE (sym
));
1308 /* fall into process_prototype_types */
1310 process_prototype_types
:
1311 /* Sun acc puts declared types of arguments here. We don't care
1312 about their actual types (FIXME -- we should remember the whole
1313 function prototype), but the list may define some new types
1314 that we have to remember, so we must scan it now. */
1317 read_type (&p
, objfile
);
1322 /* A global function definition. */
1323 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1324 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1325 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1326 add_symbol_to_list (sym
, &global_symbols
);
1327 goto process_function_types
;
1330 /* For a class G (global) symbol, it appears that the
1331 value is not correct. It is necessary to search for the
1332 corresponding linker definition to find the value.
1333 These definitions appear at the end of the namelist. */
1334 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1335 i
= hashname (SYMBOL_NAME (sym
));
1336 SYMBOL_VALUE_CHAIN (sym
) = global_sym_chain
[i
];
1337 global_sym_chain
[i
] = sym
;
1338 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1339 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1340 add_symbol_to_list (sym
, &global_symbols
);
1343 /* This case is faked by a conditional above,
1344 when there is no code letter in the dbx data.
1345 Dbx data never actually contains 'l'. */
1348 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1349 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1350 SYMBOL_VALUE (sym
) = valu
;
1351 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1352 add_symbol_to_list (sym
, &local_symbols
);
1357 /* pF is a two-letter code that means a function parameter in Fortran.
1358 The type-number specifies the type of the return value.
1359 Translate it into a pointer-to-function type. */
1363 = lookup_pointer_type
1364 (lookup_function_type (read_type (&p
, objfile
)));
1367 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1369 /* Normally this is a parameter, a LOC_ARG. On the i960, it
1370 can also be a LOC_LOCAL_ARG depending on symbol type. */
1371 #ifndef DBX_PARM_SYMBOL_CLASS
1372 #define DBX_PARM_SYMBOL_CLASS(type) LOC_ARG
1375 SYMBOL_CLASS (sym
) = DBX_PARM_SYMBOL_CLASS (type
);
1376 SYMBOL_VALUE (sym
) = valu
;
1377 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1378 add_symbol_to_list (sym
, &local_symbols
);
1380 if (TARGET_BYTE_ORDER
!= BIG_ENDIAN
)
1382 /* On little-endian machines, this crud is never necessary,
1383 and, if the extra bytes contain garbage, is harmful. */
1387 /* If it's gcc-compiled, if it says `short', believe it. */
1388 if (processing_gcc_compilation
|| BELIEVE_PCC_PROMOTION
)
1391 #if !BELIEVE_PCC_PROMOTION
1393 /* This is the signed type which arguments get promoted to. */
1394 static struct type
*pcc_promotion_type
;
1395 /* This is the unsigned type which arguments get promoted to. */
1396 static struct type
*pcc_unsigned_promotion_type
;
1398 /* Call it "int" because this is mainly C lossage. */
1399 if (pcc_promotion_type
== NULL
)
1400 pcc_promotion_type
=
1401 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
1404 if (pcc_unsigned_promotion_type
== NULL
)
1405 pcc_unsigned_promotion_type
=
1406 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
1407 TYPE_FLAG_UNSIGNED
, "unsigned int", NULL
);
1409 #if defined(BELIEVE_PCC_PROMOTION_TYPE)
1410 /* This macro is defined on machines (e.g. sparc) where
1411 we should believe the type of a PCC 'short' argument,
1412 but shouldn't believe the address (the address is
1413 the address of the corresponding int).
1415 My guess is that this correction, as opposed to changing
1416 the parameter to an 'int' (as done below, for PCC
1417 on most machines), is the right thing to do
1418 on all machines, but I don't want to risk breaking
1419 something that already works. On most PCC machines,
1420 the sparc problem doesn't come up because the calling
1421 function has to zero the top bytes (not knowing whether
1422 the called function wants an int or a short), so there
1423 is little practical difference between an int and a short
1424 (except perhaps what happens when the GDB user types
1425 "print short_arg = 0x10000;").
1427 Hacked for SunOS 4.1 by gnu@cygnus.com. In 4.1, the compiler
1428 actually produces the correct address (we don't need to fix it
1429 up). I made this code adapt so that it will offset the symbol
1430 if it was pointing at an int-aligned location and not
1431 otherwise. This way you can use the same gdb for 4.0.x and
1434 If the parameter is shorter than an int, and is integral
1435 (e.g. char, short, or unsigned equivalent), and is claimed to
1436 be passed on an integer boundary, don't believe it! Offset the
1437 parameter's address to the tail-end of that integer. */
1439 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (pcc_promotion_type
)
1440 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
1441 && 0 == SYMBOL_VALUE (sym
) % TYPE_LENGTH (pcc_promotion_type
))
1443 SYMBOL_VALUE (sym
) += TYPE_LENGTH (pcc_promotion_type
)
1444 - TYPE_LENGTH (SYMBOL_TYPE (sym
));
1448 #else /* no BELIEVE_PCC_PROMOTION_TYPE. */
1450 /* If PCC says a parameter is a short or a char,
1451 it is really an int. */
1452 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (pcc_promotion_type
)
1453 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
)
1456 TYPE_UNSIGNED (SYMBOL_TYPE (sym
))
1457 ? pcc_unsigned_promotion_type
1458 : pcc_promotion_type
;
1462 #endif /* no BELIEVE_PCC_PROMOTION_TYPE. */
1464 #endif /* !BELIEVE_PCC_PROMOTION. */
1467 /* acc seems to use P to declare the prototypes of functions that
1468 are referenced by this file. gdb is not prepared to deal
1469 with this extra information. FIXME, it ought to. */
1472 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1473 goto process_prototype_types
;
1478 /* Parameter which is in a register. */
1479 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1480 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
1481 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
1482 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
1484 complain (®_value_complaint
, SYMBOL_VALUE (sym
), NUM_REGS
,
1485 SYMBOL_SOURCE_NAME (sym
));
1486 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
1488 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1489 add_symbol_to_list (sym
, &local_symbols
);
1493 /* Register variable (either global or local). */
1494 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1495 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
1496 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
1497 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
1499 complain (®_value_complaint
, SYMBOL_VALUE (sym
), NUM_REGS
,
1500 SYMBOL_SOURCE_NAME (sym
));
1501 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
1503 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1504 if (within_function
)
1506 /* Sun cc uses a pair of symbols, one 'p' and one 'r' with the same
1507 name to represent an argument passed in a register.
1508 GCC uses 'P' for the same case. So if we find such a symbol pair
1509 we combine it into one 'P' symbol. For Sun cc we need to do this
1510 regardless of REG_STRUCT_HAS_ADDR, because the compiler puts out
1511 the 'p' symbol even if it never saves the argument onto the stack.
1513 On most machines, we want to preserve both symbols, so that
1514 we can still get information about what is going on with the
1515 stack (VAX for computing args_printed, using stack slots instead
1516 of saved registers in backtraces, etc.).
1518 Note that this code illegally combines
1519 main(argc) struct foo argc; { register struct foo argc; }
1520 but this case is considered pathological and causes a warning
1521 from a decent compiler. */
1524 && local_symbols
->nsyms
> 0
1525 #ifndef USE_REGISTER_NOT_ARG
1526 && REG_STRUCT_HAS_ADDR (processing_gcc_compilation
,
1528 && (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
1529 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
1530 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_SET
1531 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_BITSTRING
)
1535 struct symbol
*prev_sym
;
1536 prev_sym
= local_symbols
->symbol
[local_symbols
->nsyms
- 1];
1537 if ((SYMBOL_CLASS (prev_sym
) == LOC_REF_ARG
1538 || SYMBOL_CLASS (prev_sym
) == LOC_ARG
)
1539 && STREQ (SYMBOL_NAME (prev_sym
), SYMBOL_NAME(sym
)))
1541 SYMBOL_CLASS (prev_sym
) = LOC_REGPARM
;
1542 /* Use the type from the LOC_REGISTER; that is the type
1543 that is actually in that register. */
1544 SYMBOL_TYPE (prev_sym
) = SYMBOL_TYPE (sym
);
1545 SYMBOL_VALUE (prev_sym
) = SYMBOL_VALUE (sym
);
1550 add_symbol_to_list (sym
, &local_symbols
);
1553 add_symbol_to_list (sym
, &file_symbols
);
1557 /* Static symbol at top level of file */
1558 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1559 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1560 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1561 #ifdef STATIC_TRANSFORM_NAME
1562 if (SYMBOL_NAME (sym
)[0] == '$')
1564 struct minimal_symbol
*msym
;
1565 msym
= lookup_minimal_symbol (SYMBOL_NAME (sym
), NULL
, objfile
);
1568 SYMBOL_NAME (sym
) = STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym
));
1569 SYMBOL_VALUE_ADDRESS (sym
) = SYMBOL_VALUE_ADDRESS (msym
);
1573 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1574 add_symbol_to_list (sym
, &file_symbols
);
1578 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1580 /* For a nameless type, we don't want a create a symbol, thus we
1581 did not use `sym'. Return without further processing. */
1582 if (nameless
) return NULL
;
1584 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1585 SYMBOL_VALUE (sym
) = valu
;
1586 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1587 /* C++ vagaries: we may have a type which is derived from
1588 a base type which did not have its name defined when the
1589 derived class was output. We fill in the derived class's
1590 base part member's name here in that case. */
1591 if (TYPE_NAME (SYMBOL_TYPE (sym
)) != NULL
)
1592 if ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
1593 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
)
1594 && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)))
1597 for (j
= TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)) - 1; j
>= 0; j
--)
1598 if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) == 0)
1599 TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) =
1600 type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym
), j
));
1603 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == NULL
)
1605 /* gcc-2.6 or later (when using -fvtable-thunks)
1606 emits a unique named type for a vtable entry.
1607 Some gdb code depends on that specific name. */
1608 extern const char vtbl_ptr_name
[];
1610 if ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_PTR
1611 && strcmp (SYMBOL_NAME (sym
), vtbl_ptr_name
))
1612 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_FUNC
)
1614 /* If we are giving a name to a type such as "pointer to
1615 foo" or "function returning foo", we better not set
1616 the TYPE_NAME. If the program contains "typedef char
1617 *caddr_t;", we don't want all variables of type char
1618 * to print as caddr_t. This is not just a
1619 consequence of GDB's type management; PCC and GCC (at
1620 least through version 2.4) both output variables of
1621 either type char * or caddr_t with the type number
1622 defined in the 't' symbol for caddr_t. If a future
1623 compiler cleans this up it GDB is not ready for it
1624 yet, but if it becomes ready we somehow need to
1625 disable this check (without breaking the PCC/GCC2.4
1630 Fortunately, this check seems not to be necessary
1631 for anything except pointers or functions. */
1634 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_NAME (sym
);
1637 add_symbol_to_list (sym
, &file_symbols
);
1641 /* Struct, union, or enum tag. For GNU C++, this can be be followed
1642 by 't' which means we are typedef'ing it as well. */
1643 synonym
= *p
== 't';
1647 /* The semantics of C++ state that "struct foo { ... }" also defines
1648 a typedef for "foo". Unfortunately, cfront never makes the typedef
1649 when translating C++ into C. We make the typedef here so that
1650 "ptype foo" works as expected for cfront translated code. */
1651 else if (current_subfile
->language
== language_cplus
)
1654 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1656 /* For a nameless type, we don't want a create a symbol, thus we
1657 did not use `sym'. Return without further processing. */
1658 if (nameless
) return NULL
;
1660 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1661 SYMBOL_VALUE (sym
) = valu
;
1662 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
1663 if (TYPE_TAG_NAME (SYMBOL_TYPE (sym
)) == 0)
1664 TYPE_TAG_NAME (SYMBOL_TYPE (sym
))
1665 = obconcat (&objfile
-> type_obstack
, "", "", SYMBOL_NAME (sym
));
1666 add_symbol_to_list (sym
, &file_symbols
);
1670 /* Clone the sym and then modify it. */
1671 register struct symbol
*typedef_sym
= (struct symbol
*)
1672 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
1673 *typedef_sym
= *sym
;
1674 SYMBOL_CLASS (typedef_sym
) = LOC_TYPEDEF
;
1675 SYMBOL_VALUE (typedef_sym
) = valu
;
1676 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
1677 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
1678 TYPE_NAME (SYMBOL_TYPE (sym
))
1679 = obconcat (&objfile
-> type_obstack
, "", "", SYMBOL_NAME (sym
));
1680 add_symbol_to_list (typedef_sym
, &file_symbols
);
1685 /* Static symbol of local scope */
1686 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1687 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1688 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1689 #ifdef STATIC_TRANSFORM_NAME
1690 if (SYMBOL_NAME (sym
)[0] == '$')
1692 struct minimal_symbol
*msym
;
1693 msym
= lookup_minimal_symbol (SYMBOL_NAME (sym
), NULL
, objfile
);
1696 SYMBOL_NAME (sym
) = STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym
));
1697 SYMBOL_VALUE_ADDRESS (sym
) = SYMBOL_VALUE_ADDRESS (msym
);
1701 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1703 add_symbol_to_list (sym
, &global_symbols
);
1705 add_symbol_to_list (sym
, &local_symbols
);
1709 /* Reference parameter */
1710 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1711 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
1712 SYMBOL_VALUE (sym
) = valu
;
1713 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1714 add_symbol_to_list (sym
, &local_symbols
);
1718 /* Reference parameter which is in a register. */
1719 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1720 SYMBOL_CLASS (sym
) = LOC_REGPARM_ADDR
;
1721 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
1722 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
1724 complain (®_value_complaint
, SYMBOL_VALUE (sym
), NUM_REGS
,
1725 SYMBOL_SOURCE_NAME (sym
));
1726 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
1728 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1729 add_symbol_to_list (sym
, &local_symbols
);
1733 /* This is used by Sun FORTRAN for "function result value".
1734 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
1735 that Pascal uses it too, but when I tried it Pascal used
1736 "x:3" (local symbol) instead. */
1737 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1738 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1739 SYMBOL_VALUE (sym
) = valu
;
1740 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1741 add_symbol_to_list (sym
, &local_symbols
);
1744 /* New code added to support cfront stabs strings */
1745 /* Note: case 'P' already handled above */
1747 /* Cfront type continuation coming up!
1748 find the original definition and add to it.
1749 We'll have to do this for the typedef too,
1750 since we clloned the symbol to define a type in read_type.
1751 Stabs info examples:
1753 foo__1CFv :ZtF (first def foo__1CFv:F(0,3);(0,24))
1754 C:ZsC;;__ct__1CFv func1__1CFv func2__1CFv ... ;;;
1755 where C is the name of the class. */
1756 /* can't lookup symbol yet 'cuz symbols not read yet
1757 so we save it for processing later */
1758 process_later(sym
,p
);
1759 SYMBOL_TYPE (sym
) = error_type (&p
, objfile
); /* FIXME! change later */
1760 SYMBOL_CLASS (sym
) = LOC_CONST
;
1761 SYMBOL_VALUE (sym
) = 0;
1762 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1763 /* don't add to list - we'll delete it later when
1764 we add the continuation to the real sym */
1766 /* End of new code added to support cfront stabs strings */
1769 SYMBOL_TYPE (sym
) = error_type (&p
, objfile
);
1770 SYMBOL_CLASS (sym
) = LOC_CONST
;
1771 SYMBOL_VALUE (sym
) = 0;
1772 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1773 add_symbol_to_list (sym
, &file_symbols
);
1777 /* When passing structures to a function, some systems sometimes pass
1778 the address in a register, not the structure itself. */
1780 if (REG_STRUCT_HAS_ADDR (processing_gcc_compilation
, SYMBOL_TYPE (sym
))
1781 && (SYMBOL_CLASS (sym
) == LOC_REGPARM
|| SYMBOL_CLASS (sym
) == LOC_ARG
))
1783 struct type
*symbol_type
= check_typedef (SYMBOL_TYPE (sym
));
1785 if ((TYPE_CODE (symbol_type
) == TYPE_CODE_STRUCT
)
1786 || (TYPE_CODE (symbol_type
) == TYPE_CODE_UNION
)
1787 || (TYPE_CODE (symbol_type
) == TYPE_CODE_BITSTRING
)
1788 || (TYPE_CODE (symbol_type
) == TYPE_CODE_SET
))
1790 /* If REG_STRUCT_HAS_ADDR yields non-zero we have to convert
1791 LOC_REGPARM to LOC_REGPARM_ADDR for structures and unions. */
1792 if (SYMBOL_CLASS (sym
) == LOC_REGPARM
)
1793 SYMBOL_CLASS (sym
) = LOC_REGPARM_ADDR
;
1794 /* Likewise for converting LOC_ARG to LOC_REF_ARG (for the 7th
1795 and subsequent arguments on the sparc, for example). */
1796 else if (SYMBOL_CLASS (sym
) == LOC_ARG
)
1797 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
1805 /* Skip rest of this symbol and return an error type.
1807 General notes on error recovery: error_type always skips to the
1808 end of the symbol (modulo cretinous dbx symbol name continuation).
1809 Thus code like this:
1811 if (*(*pp)++ != ';')
1812 return error_type (pp, objfile);
1814 is wrong because if *pp starts out pointing at '\0' (typically as the
1815 result of an earlier error), it will be incremented to point to the
1816 start of the next symbol, which might produce strange results, at least
1817 if you run off the end of the string table. Instead use
1820 return error_type (pp, objfile);
1826 foo = error_type (pp, objfile);
1830 And in case it isn't obvious, the point of all this hair is so the compiler
1831 can define new types and new syntaxes, and old versions of the
1832 debugger will be able to read the new symbol tables. */
1834 static struct type
*
1835 error_type (pp
, objfile
)
1837 struct objfile
*objfile
;
1839 complain (&error_type_complaint
);
1842 /* Skip to end of symbol. */
1843 while (**pp
!= '\0')
1848 /* Check for and handle cretinous dbx symbol name continuation! */
1849 if ((*pp
)[-1] == '\\' || (*pp
)[-1] == '?')
1851 *pp
= next_symbol_text (objfile
);
1858 return (builtin_type_error
);
1862 /* Read type information or a type definition; return the type. Even
1863 though this routine accepts either type information or a type
1864 definition, the distinction is relevant--some parts of stabsread.c
1865 assume that type information starts with a digit, '-', or '(' in
1866 deciding whether to call read_type. */
1869 read_type (pp
, objfile
)
1871 struct objfile
*objfile
;
1873 register struct type
*type
= 0;
1876 char type_descriptor
;
1878 /* Size in bits of type if specified by a type attribute, or -1 if
1879 there is no size attribute. */
1882 /* Used to distinguish string and bitstring from char-array and set. */
1885 /* Read type number if present. The type number may be omitted.
1886 for instance in a two-dimensional array declared with type
1887 "ar1;1;10;ar1;1;10;4". */
1888 if ((**pp
>= '0' && **pp
<= '9')
1892 if (read_type_number (pp
, typenums
) != 0)
1893 return error_type (pp
, objfile
);
1895 /* Type is not being defined here. Either it already exists,
1896 or this is a forward reference to it. dbx_alloc_type handles
1899 return dbx_alloc_type (typenums
, objfile
);
1901 /* Type is being defined here. */
1903 Also skip the type descriptor - we get it below with (*pp)[-1]. */
1908 /* 'typenums=' not present, type is anonymous. Read and return
1909 the definition, but don't put it in the type vector. */
1910 typenums
[0] = typenums
[1] = -1;
1915 type_descriptor
= (*pp
)[-1];
1916 switch (type_descriptor
)
1920 enum type_code code
;
1922 /* Used to index through file_symbols. */
1923 struct pending
*ppt
;
1926 /* Name including "struct", etc. */
1930 char *from
, *to
, *p
, *q1
, *q2
;
1932 /* Set the type code according to the following letter. */
1936 code
= TYPE_CODE_STRUCT
;
1939 code
= TYPE_CODE_UNION
;
1942 code
= TYPE_CODE_ENUM
;
1946 /* Complain and keep going, so compilers can invent new
1947 cross-reference types. */
1948 static struct complaint msg
=
1949 {"Unrecognized cross-reference type `%c'", 0, 0};
1950 complain (&msg
, (*pp
)[0]);
1951 code
= TYPE_CODE_STRUCT
;
1956 q1
= strchr(*pp
, '<');
1957 p
= strchr(*pp
, ':');
1959 return error_type (pp
, objfile
);
1960 if (q1
&& p
> q1
&& p
[1] == ':')
1962 int nesting_level
= 0;
1963 for (q2
= q1
; *q2
; q2
++)
1967 else if (*q2
== '>')
1969 else if (*q2
== ':' && nesting_level
== 0)
1974 return error_type (pp
, objfile
);
1977 (char *)obstack_alloc (&objfile
->type_obstack
, p
- *pp
+ 1);
1979 /* Copy the name. */
1985 /* Set the pointer ahead of the name which we just read, and
1990 /* Now check to see whether the type has already been
1991 declared. This was written for arrays of cross-referenced
1992 types before we had TYPE_CODE_TARGET_STUBBED, so I'm pretty
1993 sure it is not necessary anymore. But it might be a good
1994 idea, to save a little memory. */
1996 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
1997 for (i
= 0; i
< ppt
->nsyms
; i
++)
1999 struct symbol
*sym
= ppt
->symbol
[i
];
2001 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
2002 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
2003 && (TYPE_CODE (SYMBOL_TYPE (sym
)) == code
)
2004 && STREQ (SYMBOL_NAME (sym
), type_name
))
2006 obstack_free (&objfile
-> type_obstack
, type_name
);
2007 type
= SYMBOL_TYPE (sym
);
2012 /* Didn't find the type to which this refers, so we must
2013 be dealing with a forward reference. Allocate a type
2014 structure for it, and keep track of it so we can
2015 fill in the rest of the fields when we get the full
2017 type
= dbx_alloc_type (typenums
, objfile
);
2018 TYPE_CODE (type
) = code
;
2019 TYPE_TAG_NAME (type
) = type_name
;
2020 INIT_CPLUS_SPECIFIC(type
);
2021 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
2023 add_undefined_type (type
);
2027 case '-': /* RS/6000 built-in type */
2041 /* We deal with something like t(1,2)=(3,4)=... which
2042 the Lucid compiler and recent gcc versions (post 2.7.3) use. */
2044 /* Allocate and enter the typedef type first.
2045 This handles recursive types. */
2046 type
= dbx_alloc_type (typenums
, objfile
);
2047 TYPE_CODE (type
) = TYPE_CODE_TYPEDEF
;
2048 { struct type
*xtype
= read_type (pp
, objfile
);
2051 /* It's being defined as itself. That means it is "void". */
2052 TYPE_CODE (type
) = TYPE_CODE_VOID
;
2053 TYPE_LENGTH (type
) = 1;
2055 else if (type_size
>= 0 || is_string
)
2058 TYPE_NAME (type
) = NULL
;
2059 TYPE_TAG_NAME (type
) = NULL
;
2063 TYPE_FLAGS (type
) |= TYPE_FLAG_TARGET_STUB
;
2064 TYPE_TARGET_TYPE (type
) = xtype
;
2069 /* In the following types, we must be sure to overwrite any existing
2070 type that the typenums refer to, rather than allocating a new one
2071 and making the typenums point to the new one. This is because there
2072 may already be pointers to the existing type (if it had been
2073 forward-referenced), and we must change it to a pointer, function,
2074 reference, or whatever, *in-place*. */
2077 type1
= read_type (pp
, objfile
);
2078 type
= make_pointer_type (type1
, dbx_lookup_type (typenums
));
2081 case '&': /* Reference to another type */
2082 type1
= read_type (pp
, objfile
);
2083 type
= make_reference_type (type1
, dbx_lookup_type (typenums
));
2086 case 'f': /* Function returning another type */
2087 if (os9k_stabs
&& **pp
== '(')
2089 /* Function prototype; parse it.
2090 We must conditionalize this on os9k_stabs because otherwise
2091 it could be confused with a Sun-style (1,3) typenumber
2097 t
= read_type(pp
, objfile
);
2098 if (**pp
== ',') ++*pp
;
2101 type1
= read_type (pp
, objfile
);
2102 type
= make_function_type (type1
, dbx_lookup_type (typenums
));
2105 case 'k': /* Const qualifier on some type (Sun) */
2106 case 'c': /* Const qualifier on some type (OS9000) */
2107 /* Because 'c' means other things to AIX and 'k' is perfectly good,
2108 only accept 'c' in the os9k_stabs case. */
2109 if (type_descriptor
== 'c' && !os9k_stabs
)
2110 return error_type (pp
, objfile
);
2111 type
= read_type (pp
, objfile
);
2112 /* FIXME! For now, we ignore const and volatile qualifiers. */
2115 case 'B': /* Volatile qual on some type (Sun) */
2116 case 'i': /* Volatile qual on some type (OS9000) */
2117 /* Because 'i' means other things to AIX and 'B' is perfectly good,
2118 only accept 'i' in the os9k_stabs case. */
2119 if (type_descriptor
== 'i' && !os9k_stabs
)
2120 return error_type (pp
, objfile
);
2121 type
= read_type (pp
, objfile
);
2122 /* FIXME! For now, we ignore const and volatile qualifiers. */
2126 if (isdigit (**pp
) || **pp
== '(' || **pp
== '-')
2127 { /* Member (class & variable) type */
2128 /* FIXME -- we should be doing smash_to_XXX types here. */
2130 struct type
*domain
= read_type (pp
, objfile
);
2131 struct type
*memtype
;
2134 /* Invalid member type data format. */
2135 return error_type (pp
, objfile
);
2138 memtype
= read_type (pp
, objfile
);
2139 type
= dbx_alloc_type (typenums
, objfile
);
2140 smash_to_member_type (type
, domain
, memtype
);
2142 else /* type attribute */
2145 /* Skip to the semicolon. */
2146 while (**pp
!= ';' && **pp
!= '\0')
2149 return error_type (pp
, objfile
);
2151 ++*pp
; /* Skip the semicolon. */
2156 type_size
= atoi (attr
+ 1);
2166 /* Ignore unrecognized type attributes, so future compilers
2167 can invent new ones. */
2175 case '#': /* Method (class & fn) type */
2176 if ((*pp
)[0] == '#')
2178 /* We'll get the parameter types from the name. */
2179 struct type
*return_type
;
2182 return_type
= read_type (pp
, objfile
);
2183 if (*(*pp
)++ != ';')
2184 complain (&invalid_member_complaint
, symnum
);
2185 type
= allocate_stub_method (return_type
);
2186 if (typenums
[0] != -1)
2187 *dbx_lookup_type (typenums
) = type
;
2191 struct type
*domain
= read_type (pp
, objfile
);
2192 struct type
*return_type
;
2196 /* Invalid member type data format. */
2197 return error_type (pp
, objfile
);
2201 return_type
= read_type (pp
, objfile
);
2202 args
= read_args (pp
, ';', objfile
);
2203 type
= dbx_alloc_type (typenums
, objfile
);
2204 smash_to_method_type (type
, domain
, return_type
, args
);
2208 case 'r': /* Range type */
2209 type
= read_range_type (pp
, typenums
, objfile
);
2210 if (typenums
[0] != -1)
2211 *dbx_lookup_type (typenums
) = type
;
2216 /* Const and volatile qualified type. */
2217 type
= read_type (pp
, objfile
);
2220 /* Sun ACC builtin int type */
2221 type
= read_sun_builtin_type (pp
, typenums
, objfile
);
2222 if (typenums
[0] != -1)
2223 *dbx_lookup_type (typenums
) = type
;
2227 case 'R': /* Sun ACC builtin float type */
2228 type
= read_sun_floating_type (pp
, typenums
, objfile
);
2229 if (typenums
[0] != -1)
2230 *dbx_lookup_type (typenums
) = type
;
2233 case 'e': /* Enumeration type */
2234 type
= dbx_alloc_type (typenums
, objfile
);
2235 type
= read_enum_type (pp
, type
, objfile
);
2236 if (typenums
[0] != -1)
2237 *dbx_lookup_type (typenums
) = type
;
2240 case 's': /* Struct type */
2241 case 'u': /* Union type */
2242 type
= dbx_alloc_type (typenums
, objfile
);
2243 switch (type_descriptor
)
2246 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
2249 TYPE_CODE (type
) = TYPE_CODE_UNION
;
2252 type
= read_struct_type (pp
, type
, objfile
);
2255 case 'a': /* Array type */
2257 return error_type (pp
, objfile
);
2260 type
= dbx_alloc_type (typenums
, objfile
);
2261 type
= read_array_type (pp
, type
, objfile
);
2263 TYPE_CODE (type
) = TYPE_CODE_STRING
;
2267 type1
= read_type (pp
, objfile
);
2268 type
= create_set_type ((struct type
*) NULL
, type1
);
2270 TYPE_CODE (type
) = TYPE_CODE_BITSTRING
;
2271 if (typenums
[0] != -1)
2272 *dbx_lookup_type (typenums
) = type
;
2276 --*pp
; /* Go back to the symbol in error */
2277 /* Particularly important if it was \0! */
2278 return error_type (pp
, objfile
);
2283 warning ("GDB internal error, type is NULL in stabsread.c\n");
2284 return error_type (pp
, objfile
);
2287 /* Size specified in a type attribute overrides any other size. */
2288 if (type_size
!= -1)
2289 TYPE_LENGTH (type
) = (type_size
+ TARGET_CHAR_BIT
- 1) / TARGET_CHAR_BIT
;
2294 /* RS/6000 xlc/dbx combination uses a set of builtin types, starting from -1.
2295 Return the proper type node for a given builtin type number. */
2297 static struct type
*
2298 rs6000_builtin_type (typenum
)
2301 /* We recognize types numbered from -NUMBER_RECOGNIZED to -1. */
2302 #define NUMBER_RECOGNIZED 34
2303 /* This includes an empty slot for type number -0. */
2304 static struct type
*negative_types
[NUMBER_RECOGNIZED
+ 1];
2305 struct type
*rettype
= NULL
;
2307 if (typenum
>= 0 || typenum
< -NUMBER_RECOGNIZED
)
2309 complain (&rs6000_builtin_complaint
, typenum
);
2310 return builtin_type_error
;
2312 if (negative_types
[-typenum
] != NULL
)
2313 return negative_types
[-typenum
];
2315 #if TARGET_CHAR_BIT != 8
2316 #error This code wrong for TARGET_CHAR_BIT not 8
2317 /* These definitions all assume that TARGET_CHAR_BIT is 8. I think
2318 that if that ever becomes not true, the correct fix will be to
2319 make the size in the struct type to be in bits, not in units of
2326 /* The size of this and all the other types are fixed, defined
2327 by the debugging format. If there is a type called "int" which
2328 is other than 32 bits, then it should use a new negative type
2329 number (or avoid negative type numbers for that case).
2330 See stabs.texinfo. */
2331 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "int", NULL
);
2334 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "char", NULL
);
2337 rettype
= init_type (TYPE_CODE_INT
, 2, 0, "short", NULL
);
2340 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "long", NULL
);
2343 rettype
= init_type (TYPE_CODE_INT
, 1, TYPE_FLAG_UNSIGNED
,
2344 "unsigned char", NULL
);
2347 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "signed char", NULL
);
2350 rettype
= init_type (TYPE_CODE_INT
, 2, TYPE_FLAG_UNSIGNED
,
2351 "unsigned short", NULL
);
2354 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
2355 "unsigned int", NULL
);
2358 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
2361 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
2362 "unsigned long", NULL
);
2365 rettype
= init_type (TYPE_CODE_VOID
, 1, 0, "void", NULL
);
2368 /* IEEE single precision (32 bit). */
2369 rettype
= init_type (TYPE_CODE_FLT
, 4, 0, "float", NULL
);
2372 /* IEEE double precision (64 bit). */
2373 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "double", NULL
);
2376 /* This is an IEEE double on the RS/6000, and different machines with
2377 different sizes for "long double" should use different negative
2378 type numbers. See stabs.texinfo. */
2379 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "long double", NULL
);
2382 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "integer", NULL
);
2385 rettype
= init_type (TYPE_CODE_BOOL
, 4, TYPE_FLAG_UNSIGNED
,
2389 rettype
= init_type (TYPE_CODE_FLT
, 4, 0, "short real", NULL
);
2392 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "real", NULL
);
2395 rettype
= init_type (TYPE_CODE_ERROR
, 0, 0, "stringptr", NULL
);
2398 rettype
= init_type (TYPE_CODE_CHAR
, 1, TYPE_FLAG_UNSIGNED
,
2402 rettype
= init_type (TYPE_CODE_BOOL
, 1, TYPE_FLAG_UNSIGNED
,
2406 rettype
= init_type (TYPE_CODE_BOOL
, 2, TYPE_FLAG_UNSIGNED
,
2410 rettype
= init_type (TYPE_CODE_BOOL
, 4, TYPE_FLAG_UNSIGNED
,
2414 rettype
= init_type (TYPE_CODE_BOOL
, 4, TYPE_FLAG_UNSIGNED
,
2418 /* Complex type consisting of two IEEE single precision values. */
2419 rettype
= init_type (TYPE_CODE_ERROR
, 8, 0, "complex", NULL
);
2422 /* Complex type consisting of two IEEE double precision values. */
2423 rettype
= init_type (TYPE_CODE_ERROR
, 16, 0, "double complex", NULL
);
2426 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "integer*1", NULL
);
2429 rettype
= init_type (TYPE_CODE_INT
, 2, 0, "integer*2", NULL
);
2432 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "integer*4", NULL
);
2435 rettype
= init_type (TYPE_CODE_CHAR
, 2, 0, "wchar", NULL
);
2438 rettype
= init_type (TYPE_CODE_INT
, 8, 0, "long long", NULL
);
2441 rettype
= init_type (TYPE_CODE_INT
, 8, TYPE_FLAG_UNSIGNED
,
2442 "unsigned long long", NULL
);
2445 rettype
= init_type (TYPE_CODE_INT
, 8, TYPE_FLAG_UNSIGNED
,
2449 rettype
= init_type (TYPE_CODE_INT
, 8, 0, "integer*8", NULL
);
2452 negative_types
[-typenum
] = rettype
;
2456 /* This page contains subroutines of read_type. */
2458 /* Read member function stabs info for C++ classes. The form of each member
2461 NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
2463 An example with two member functions is:
2465 afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
2467 For the case of overloaded operators, the format is op$::*.funcs, where
2468 $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
2469 name (such as `+=') and `.' marks the end of the operator name.
2471 Returns 1 for success, 0 for failure. */
2474 read_member_functions (fip
, pp
, type
, objfile
)
2475 struct field_info
*fip
;
2478 struct objfile
*objfile
;
2482 /* Total number of member functions defined in this class. If the class
2483 defines two `f' functions, and one `g' function, then this will have
2485 int total_length
= 0;
2489 struct next_fnfield
*next
;
2490 struct fn_field fn_field
;
2492 struct type
*look_ahead_type
;
2493 struct next_fnfieldlist
*new_fnlist
;
2494 struct next_fnfield
*new_sublist
;
2498 /* Process each list until we find something that is not a member function
2499 or find the end of the functions. */
2503 /* We should be positioned at the start of the function name.
2504 Scan forward to find the first ':' and if it is not the
2505 first of a "::" delimiter, then this is not a member function. */
2517 look_ahead_type
= NULL
;
2520 new_fnlist
= (struct next_fnfieldlist
*)
2521 xmalloc (sizeof (struct next_fnfieldlist
));
2522 make_cleanup (free
, new_fnlist
);
2523 memset (new_fnlist
, 0, sizeof (struct next_fnfieldlist
));
2525 if ((*pp
)[0] == 'o' && (*pp
)[1] == 'p' && is_cplus_marker ((*pp
)[2]))
2527 /* This is a completely wierd case. In order to stuff in the
2528 names that might contain colons (the usual name delimiter),
2529 Mike Tiemann defined a different name format which is
2530 signalled if the identifier is "op$". In that case, the
2531 format is "op$::XXXX." where XXXX is the name. This is
2532 used for names like "+" or "=". YUUUUUUUK! FIXME! */
2533 /* This lets the user type "break operator+".
2534 We could just put in "+" as the name, but that wouldn't
2536 static char opname
[32] = {'o', 'p', CPLUS_MARKER
};
2537 char *o
= opname
+ 3;
2539 /* Skip past '::'. */
2542 STABS_CONTINUE (pp
, objfile
);
2548 main_fn_name
= savestring (opname
, o
- opname
);
2554 main_fn_name
= savestring (*pp
, p
- *pp
);
2555 /* Skip past '::'. */
2558 new_fnlist
-> fn_fieldlist
.name
= main_fn_name
;
2563 (struct next_fnfield
*) xmalloc (sizeof (struct next_fnfield
));
2564 make_cleanup (free
, new_sublist
);
2565 memset (new_sublist
, 0, sizeof (struct next_fnfield
));
2567 /* Check for and handle cretinous dbx symbol name continuation! */
2568 if (look_ahead_type
== NULL
)
2571 STABS_CONTINUE (pp
, objfile
);
2573 new_sublist
-> fn_field
.type
= read_type (pp
, objfile
);
2576 /* Invalid symtab info for member function. */
2582 /* g++ version 1 kludge */
2583 new_sublist
-> fn_field
.type
= look_ahead_type
;
2584 look_ahead_type
= NULL
;
2594 /* If this is just a stub, then we don't have the real name here. */
2596 if (TYPE_FLAGS (new_sublist
-> fn_field
.type
) & TYPE_FLAG_STUB
)
2598 if (!TYPE_DOMAIN_TYPE (new_sublist
-> fn_field
.type
))
2599 TYPE_DOMAIN_TYPE (new_sublist
-> fn_field
.type
) = type
;
2600 new_sublist
-> fn_field
.is_stub
= 1;
2602 new_sublist
-> fn_field
.physname
= savestring (*pp
, p
- *pp
);
2605 /* Set this member function's visibility fields. */
2608 case VISIBILITY_PRIVATE
:
2609 new_sublist
-> fn_field
.is_private
= 1;
2611 case VISIBILITY_PROTECTED
:
2612 new_sublist
-> fn_field
.is_protected
= 1;
2616 STABS_CONTINUE (pp
, objfile
);
2619 case 'A': /* Normal functions. */
2620 new_sublist
-> fn_field
.is_const
= 0;
2621 new_sublist
-> fn_field
.is_volatile
= 0;
2624 case 'B': /* `const' member functions. */
2625 new_sublist
-> fn_field
.is_const
= 1;
2626 new_sublist
-> fn_field
.is_volatile
= 0;
2629 case 'C': /* `volatile' member function. */
2630 new_sublist
-> fn_field
.is_const
= 0;
2631 new_sublist
-> fn_field
.is_volatile
= 1;
2634 case 'D': /* `const volatile' member function. */
2635 new_sublist
-> fn_field
.is_const
= 1;
2636 new_sublist
-> fn_field
.is_volatile
= 1;
2639 case '*': /* File compiled with g++ version 1 -- no info */
2644 complain (&const_vol_complaint
, **pp
);
2653 /* virtual member function, followed by index.
2654 The sign bit is set to distinguish pointers-to-methods
2655 from virtual function indicies. Since the array is
2656 in words, the quantity must be shifted left by 1
2657 on 16 bit machine, and by 2 on 32 bit machine, forcing
2658 the sign bit out, and usable as a valid index into
2659 the array. Remove the sign bit here. */
2660 new_sublist
-> fn_field
.voffset
=
2661 (0x7fffffff & read_huge_number (pp
, ';', &nbits
)) + 2;
2665 STABS_CONTINUE (pp
, objfile
);
2666 if (**pp
== ';' || **pp
== '\0')
2668 /* Must be g++ version 1. */
2669 new_sublist
-> fn_field
.fcontext
= 0;
2673 /* Figure out from whence this virtual function came.
2674 It may belong to virtual function table of
2675 one of its baseclasses. */
2676 look_ahead_type
= read_type (pp
, objfile
);
2679 /* g++ version 1 overloaded methods. */
2683 new_sublist
-> fn_field
.fcontext
= look_ahead_type
;
2692 look_ahead_type
= NULL
;
2698 /* static member function. */
2699 new_sublist
-> fn_field
.voffset
= VOFFSET_STATIC
;
2700 if (strncmp (new_sublist
-> fn_field
.physname
,
2701 main_fn_name
, strlen (main_fn_name
)))
2703 new_sublist
-> fn_field
.is_stub
= 1;
2709 complain (&member_fn_complaint
, (*pp
)[-1]);
2710 /* Fall through into normal member function. */
2713 /* normal member function. */
2714 new_sublist
-> fn_field
.voffset
= 0;
2715 new_sublist
-> fn_field
.fcontext
= 0;
2719 new_sublist
-> next
= sublist
;
2720 sublist
= new_sublist
;
2722 STABS_CONTINUE (pp
, objfile
);
2724 while (**pp
!= ';' && **pp
!= '\0');
2728 new_fnlist
-> fn_fieldlist
.fn_fields
= (struct fn_field
*)
2729 obstack_alloc (&objfile
-> type_obstack
,
2730 sizeof (struct fn_field
) * length
);
2731 memset (new_fnlist
-> fn_fieldlist
.fn_fields
, 0,
2732 sizeof (struct fn_field
) * length
);
2733 for (i
= length
; (i
--, sublist
); sublist
= sublist
-> next
)
2735 new_fnlist
-> fn_fieldlist
.fn_fields
[i
] = sublist
-> fn_field
;
2738 new_fnlist
-> fn_fieldlist
.length
= length
;
2739 new_fnlist
-> next
= fip
-> fnlist
;
2740 fip
-> fnlist
= new_fnlist
;
2742 total_length
+= length
;
2743 STABS_CONTINUE (pp
, objfile
);
2748 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2749 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2750 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * nfn_fields
);
2751 memset (TYPE_FN_FIELDLISTS (type
), 0,
2752 sizeof (struct fn_fieldlist
) * nfn_fields
);
2753 TYPE_NFN_FIELDS (type
) = nfn_fields
;
2754 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2760 /* Special GNU C++ name.
2762 Returns 1 for success, 0 for failure. "failure" means that we can't
2763 keep parsing and it's time for error_type(). */
2766 read_cpp_abbrev (fip
, pp
, type
, objfile
)
2767 struct field_info
*fip
;
2770 struct objfile
*objfile
;
2775 struct type
*context
;
2785 /* At this point, *pp points to something like "22:23=*22...",
2786 where the type number before the ':' is the "context" and
2787 everything after is a regular type definition. Lookup the
2788 type, find it's name, and construct the field name. */
2790 context
= read_type (pp
, objfile
);
2794 case 'f': /* $vf -- a virtual function table pointer */
2795 fip
->list
->field
.name
=
2796 obconcat (&objfile
->type_obstack
, vptr_name
, "", "");
2799 case 'b': /* $vb -- a virtual bsomethingorother */
2800 name
= type_name_no_tag (context
);
2803 complain (&invalid_cpp_type_complaint
, symnum
);
2806 fip
->list
->field
.name
=
2807 obconcat (&objfile
->type_obstack
, vb_name
, name
, "");
2811 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2812 fip
->list
->field
.name
=
2813 obconcat (&objfile
->type_obstack
,
2814 "INVALID_CPLUSPLUS_ABBREV", "", "");
2818 /* At this point, *pp points to the ':'. Skip it and read the
2824 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2827 fip
->list
->field
.type
= read_type (pp
, objfile
);
2829 (*pp
)++; /* Skip the comma. */
2835 FIELD_BITPOS (fip
->list
->field
) = read_huge_number (pp
, ';', &nbits
);
2839 /* This field is unpacked. */
2840 FIELD_BITSIZE (fip
->list
->field
) = 0;
2841 fip
->list
->visibility
= VISIBILITY_PRIVATE
;
2845 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2846 /* We have no idea what syntax an unrecognized abbrev would have, so
2847 better return 0. If we returned 1, we would need to at least advance
2848 *pp to avoid an infinite loop. */
2855 read_one_struct_field (fip
, pp
, p
, type
, objfile
)
2856 struct field_info
*fip
;
2860 struct objfile
*objfile
;
2862 /* The following is code to work around cfront generated stabs.
2863 The stabs contains full mangled name for each field.
2864 We try to demangle the name and extract the field name out of it.
2866 if (ARM_DEMANGLING
&& current_subfile
->language
== language_cplus
)
2872 dem
= cplus_demangle (*pp
, DMGL_ANSI
| DMGL_PARAMS
);
2875 dem_p
= strrchr (dem
, ':');
2876 if (dem_p
!= 0 && *(dem_p
-1)==':')
2878 FIELD_NAME (fip
->list
->field
) =
2879 obsavestring (dem_p
, strlen(dem_p
), &objfile
-> type_obstack
);
2883 FIELD_NAME (fip
->list
->field
) =
2884 obsavestring (*pp
, p
- *pp
, &objfile
-> type_obstack
);
2888 /* end of code for cfront work around */
2891 fip
-> list
-> field
.name
=
2892 obsavestring (*pp
, p
- *pp
, &objfile
-> type_obstack
);
2895 /* This means we have a visibility for a field coming. */
2899 fip
-> list
-> visibility
= *(*pp
)++;
2903 /* normal dbx-style format, no explicit visibility */
2904 fip
-> list
-> visibility
= VISIBILITY_PUBLIC
;
2907 fip
-> list
-> field
.type
= read_type (pp
, objfile
);
2912 /* Possible future hook for nested types. */
2915 fip
-> list
-> field
.bitpos
= (long)-2; /* nested type */
2924 /* Static class member. */
2925 SET_FIELD_PHYSNAME (fip
->list
->field
, savestring (*pp
, p
- *pp
));
2929 else if (**pp
!= ',')
2931 /* Bad structure-type format. */
2932 complain (&stabs_general_complaint
, "bad structure-type format");
2936 (*pp
)++; /* Skip the comma. */
2940 FIELD_BITPOS (fip
->list
->field
) = read_huge_number (pp
, ',', &nbits
);
2943 complain (&stabs_general_complaint
, "bad structure-type format");
2946 FIELD_BITSIZE (fip
->list
->field
) = read_huge_number (pp
, ';', &nbits
);
2949 complain (&stabs_general_complaint
, "bad structure-type format");
2954 if (FIELD_BITPOS (fip
->list
->field
) == 0
2955 && FIELD_BITSIZE (fip
->list
->field
) == 0)
2957 /* This can happen in two cases: (1) at least for gcc 2.4.5 or so,
2958 it is a field which has been optimized out. The correct stab for
2959 this case is to use VISIBILITY_IGNORE, but that is a recent
2960 invention. (2) It is a 0-size array. For example
2961 union { int num; char str[0]; } foo. Printing "<no value>" for
2962 str in "p foo" is OK, since foo.str (and thus foo.str[3])
2963 will continue to work, and a 0-size array as a whole doesn't
2964 have any contents to print.
2966 I suspect this probably could also happen with gcc -gstabs (not
2967 -gstabs+) for static fields, and perhaps other C++ extensions.
2968 Hopefully few people use -gstabs with gdb, since it is intended
2969 for dbx compatibility. */
2971 /* Ignore this field. */
2972 fip
-> list
-> visibility
= VISIBILITY_IGNORE
;
2976 /* Detect an unpacked field and mark it as such.
2977 dbx gives a bit size for all fields.
2978 Note that forward refs cannot be packed,
2979 and treat enums as if they had the width of ints. */
2981 if (TYPE_CODE (FIELD_TYPE (fip
->list
->field
)) != TYPE_CODE_INT
2982 && TYPE_CODE (FIELD_TYPE (fip
->list
->field
)) != TYPE_CODE_BOOL
2983 && TYPE_CODE (FIELD_TYPE (fip
->list
->field
)) != TYPE_CODE_ENUM
)
2985 FIELD_BITSIZE (fip
->list
->field
) = 0;
2987 if ((FIELD_BITSIZE (fip
->list
->field
)
2988 == TARGET_CHAR_BIT
* TYPE_LENGTH (FIELD_TYPE (fip
->list
->field
))
2989 || (TYPE_CODE (FIELD_TYPE (fip
->list
->field
)) == TYPE_CODE_ENUM
2990 && FIELD_BITSIZE (fip
->list
->field
) == TARGET_INT_BIT
)
2993 FIELD_BITPOS (fip
->list
->field
) % 8 == 0)
2995 FIELD_BITSIZE (fip
->list
->field
) = 0;
3001 /* Read struct or class data fields. They have the form:
3003 NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
3005 At the end, we see a semicolon instead of a field.
3007 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
3010 The optional VISIBILITY is one of:
3012 '/0' (VISIBILITY_PRIVATE)
3013 '/1' (VISIBILITY_PROTECTED)
3014 '/2' (VISIBILITY_PUBLIC)
3015 '/9' (VISIBILITY_IGNORE)
3017 or nothing, for C style fields with public visibility.
3019 Returns 1 for success, 0 for failure. */
3022 read_struct_fields (fip
, pp
, type
, objfile
)
3023 struct field_info
*fip
;
3026 struct objfile
*objfile
;
3029 struct nextfield
*new;
3031 /* We better set p right now, in case there are no fields at all... */
3035 /* Read each data member type until we find the terminating ';' at the end of
3036 the data member list, or break for some other reason such as finding the
3037 start of the member function list. */
3041 if (os9k_stabs
&& **pp
== ',') break;
3042 STABS_CONTINUE (pp
, objfile
);
3043 /* Get space to record the next field's data. */
3044 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3045 make_cleanup (free
, new);
3046 memset (new, 0, sizeof (struct nextfield
));
3047 new -> next
= fip
-> list
;
3050 /* Get the field name. */
3053 /* If is starts with CPLUS_MARKER it is a special abbreviation,
3054 unless the CPLUS_MARKER is followed by an underscore, in
3055 which case it is just the name of an anonymous type, which we
3056 should handle like any other type name. */
3058 if (is_cplus_marker (p
[0]) && p
[1] != '_')
3060 if (!read_cpp_abbrev (fip
, pp
, type
, objfile
))
3065 /* Look for the ':' that separates the field name from the field
3066 values. Data members are delimited by a single ':', while member
3067 functions are delimited by a pair of ':'s. When we hit the member
3068 functions (if any), terminate scan loop and return. */
3070 while (*p
!= ':' && *p
!= '\0')
3077 /* Check to see if we have hit the member functions yet. */
3082 read_one_struct_field (fip
, pp
, p
, type
, objfile
);
3084 if (p
[0] == ':' && p
[1] == ':')
3086 /* chill the list of fields: the last entry (at the head) is a
3087 partially constructed entry which we now scrub. */
3088 fip
-> list
= fip
-> list
-> next
;
3093 /* The stabs for C++ derived classes contain baseclass information which
3094 is marked by a '!' character after the total size. This function is
3095 called when we encounter the baseclass marker, and slurps up all the
3096 baseclass information.
3098 Immediately following the '!' marker is the number of base classes that
3099 the class is derived from, followed by information for each base class.
3100 For each base class, there are two visibility specifiers, a bit offset
3101 to the base class information within the derived class, a reference to
3102 the type for the base class, and a terminating semicolon.
3104 A typical example, with two base classes, would be "!2,020,19;0264,21;".
3106 Baseclass information marker __________________|| | | | | | |
3107 Number of baseclasses __________________________| | | | | | |
3108 Visibility specifiers (2) ________________________| | | | | |
3109 Offset in bits from start of class _________________| | | | |
3110 Type number for base class ___________________________| | | |
3111 Visibility specifiers (2) _______________________________| | |
3112 Offset in bits from start of class ________________________| |
3113 Type number of base class ____________________________________|
3115 Return 1 for success, 0 for (error-type-inducing) failure. */
3118 read_baseclasses (fip
, pp
, type
, objfile
)
3119 struct field_info
*fip
;
3122 struct objfile
*objfile
;
3125 struct nextfield
*new;
3133 /* Skip the '!' baseclass information marker. */
3137 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3140 TYPE_N_BASECLASSES (type
) = read_huge_number (pp
, ',', &nbits
);
3146 /* Some stupid compilers have trouble with the following, so break
3147 it up into simpler expressions. */
3148 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*)
3149 TYPE_ALLOC (type
, B_BYTES (TYPE_N_BASECLASSES (type
)));
3152 int num_bytes
= B_BYTES (TYPE_N_BASECLASSES (type
));
3155 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
3156 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
3160 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), TYPE_N_BASECLASSES (type
));
3162 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
3164 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3165 make_cleanup (free
, new);
3166 memset (new, 0, sizeof (struct nextfield
));
3167 new -> next
= fip
-> list
;
3169 FIELD_BITSIZE (new->field
) = 0; /* this should be an unpacked field! */
3171 STABS_CONTINUE (pp
, objfile
);
3175 /* Nothing to do. */
3178 SET_TYPE_FIELD_VIRTUAL (type
, i
);
3181 /* Unknown character. Complain and treat it as non-virtual. */
3183 static struct complaint msg
= {
3184 "Unknown virtual character `%c' for baseclass", 0, 0};
3185 complain (&msg
, **pp
);
3190 new -> visibility
= *(*pp
)++;
3191 switch (new -> visibility
)
3193 case VISIBILITY_PRIVATE
:
3194 case VISIBILITY_PROTECTED
:
3195 case VISIBILITY_PUBLIC
:
3198 /* Bad visibility format. Complain and treat it as
3201 static struct complaint msg
= {
3202 "Unknown visibility `%c' for baseclass", 0, 0};
3203 complain (&msg
, new -> visibility
);
3204 new -> visibility
= VISIBILITY_PUBLIC
;
3211 /* The remaining value is the bit offset of the portion of the object
3212 corresponding to this baseclass. Always zero in the absence of
3213 multiple inheritance. */
3215 FIELD_BITPOS (new->field
) = read_huge_number (pp
, ',', &nbits
);
3220 /* The last piece of baseclass information is the type of the
3221 base class. Read it, and remember it's type name as this
3224 new -> field
.type
= read_type (pp
, objfile
);
3225 new -> field
.name
= type_name_no_tag (new -> field
.type
);
3227 /* skip trailing ';' and bump count of number of fields seen */
3236 /* The tail end of stabs for C++ classes that contain a virtual function
3237 pointer contains a tilde, a %, and a type number.
3238 The type number refers to the base class (possibly this class itself) which
3239 contains the vtable pointer for the current class.
3241 This function is called when we have parsed all the method declarations,
3242 so we can look for the vptr base class info. */
3245 read_tilde_fields (fip
, pp
, type
, objfile
)
3246 struct field_info
*fip
;
3249 struct objfile
*objfile
;
3253 STABS_CONTINUE (pp
, objfile
);
3255 /* If we are positioned at a ';', then skip it. */
3265 if (**pp
== '=' || **pp
== '+' || **pp
== '-')
3267 /* Obsolete flags that used to indicate the presence
3268 of constructors and/or destructors. */
3272 /* Read either a '%' or the final ';'. */
3273 if (*(*pp
)++ == '%')
3275 /* The next number is the type number of the base class
3276 (possibly our own class) which supplies the vtable for
3277 this class. Parse it out, and search that class to find
3278 its vtable pointer, and install those into TYPE_VPTR_BASETYPE
3279 and TYPE_VPTR_FIELDNO. */
3284 t
= read_type (pp
, objfile
);
3286 while (*p
!= '\0' && *p
!= ';')
3292 /* Premature end of symbol. */
3296 TYPE_VPTR_BASETYPE (type
) = t
;
3297 if (type
== t
) /* Our own class provides vtbl ptr */
3299 for (i
= TYPE_NFIELDS (t
) - 1;
3300 i
>= TYPE_N_BASECLASSES (t
);
3303 if (! strncmp (TYPE_FIELD_NAME (t
, i
), vptr_name
,
3304 sizeof (vptr_name
) - 1))
3306 TYPE_VPTR_FIELDNO (type
) = i
;
3310 /* Virtual function table field not found. */
3311 complain (&vtbl_notfound_complaint
, TYPE_NAME (type
));
3316 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
3327 attach_fn_fields_to_type (fip
, type
)
3328 struct field_info
*fip
;
3329 register struct type
*type
;
3333 for (n
= TYPE_NFN_FIELDS (type
);
3334 fip
-> fnlist
!= NULL
;
3335 fip
-> fnlist
= fip
-> fnlist
-> next
)
3337 --n
; /* Circumvent Sun3 compiler bug */
3338 TYPE_FN_FIELDLISTS (type
)[n
] = fip
-> fnlist
-> fn_fieldlist
;
3343 /* read cfront class static data.
3344 pp points to string starting with the list of static data
3345 eg: A:ZcA;1@Bpub v2@Bvirpri;__ct__1AFv func__1AFv *sfunc__1AFv ;as__1A ;;
3348 A:ZcA;;foopri__1AFv foopro__1AFv __ct__1AFv __ct__1AFRC1A foopub__1AFv ;;;
3353 read_cfront_static_fields(fip
, pp
, type
, objfile
)
3354 struct field_info
*fip
;
3357 struct objfile
*objfile
;
3359 struct nextfield
* new;
3362 struct symbol
* ref_static
=0;
3364 if (**pp
==';') /* no static data; return */
3370 /* Process each field in the list until we find the terminating ";" */
3372 /* eg: p = "as__1A ;;;" */
3373 STABS_CONTINUE (pp
, objfile
); /* handle \\ */
3374 while (**pp
!=';' && (sname
= get_substring(pp
,' '),sname
))
3376 ref_static
= lookup_symbol (sname
, 0, VAR_NAMESPACE
, 0, 0); /*demangled_name*/
3379 static struct complaint msg
= {"\
3380 Unable to find symbol for static data field %s\n",
3382 complain (&msg
, sname
);
3385 stype
= SYMBOL_TYPE(ref_static
);
3387 /* allocate a new fip */
3388 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3389 make_cleanup (free
, new);
3390 memset (new, 0, sizeof (struct nextfield
));
3391 new -> next
= fip
-> list
;
3394 /* set visibility */
3395 /* FIXME! no way to tell visibility from stabs??? */
3396 new -> visibility
= VISIBILITY_PUBLIC
;
3398 /* set field info into fip */
3399 fip
-> list
-> field
.type
= stype
;
3401 /* set bitpos & bitsize */
3402 SET_FIELD_PHYSNAME (fip
->list
->field
, savestring (sname
, strlen(sname
)));
3404 /* set name field */
3405 /* The following is code to work around cfront generated stabs.
3406 The stabs contains full mangled name for each field.
3407 We try to demangle the name and extract the field name out of it.
3412 dem
= cplus_demangle (sname
, DMGL_ANSI
| DMGL_PARAMS
);
3415 dem_p
= strrchr (dem
, ':');
3416 if (dem_p
!= 0 && *(dem_p
-1)==':')
3418 fip
->list
->field
.name
=
3419 obsavestring (dem_p
, strlen(dem_p
), &objfile
-> type_obstack
);
3423 fip
->list
->field
.name
=
3424 obsavestring (sname
, strlen(sname
), &objfile
-> type_obstack
);
3426 } /* end of code for cfront work around */
3427 } /* loop again for next static field */
3431 /* Copy structure fields to fip so attach_fields_to_type will work.
3432 type has already been created with the initial instance data fields.
3433 Now we want to be able to add the other members to the class,
3434 so we want to add them back to the fip and reattach them again
3435 once we have collected all the class members. */
3438 copy_cfront_struct_fields(fip
, type
, objfile
)
3439 struct field_info
*fip
;
3441 struct objfile
*objfile
;
3443 int nfields
= TYPE_NFIELDS(type
);
3445 struct nextfield
* new;
3447 /* Copy the fields into the list of fips and reset the types
3448 to remove the old fields */
3450 for (i
=0; i
<nfields
; i
++)
3452 /* allocate a new fip */
3453 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3454 make_cleanup (free
, new);
3455 memset (new, 0, sizeof (struct nextfield
));
3456 new -> next
= fip
-> list
;
3459 /* copy field info into fip */
3460 new -> field
= TYPE_FIELD (type
, i
);
3461 /* set visibility */
3462 if (TYPE_FIELD_PROTECTED (type
, i
))
3463 new -> visibility
= VISIBILITY_PROTECTED
;
3464 else if (TYPE_FIELD_PRIVATE (type
, i
))
3465 new -> visibility
= VISIBILITY_PRIVATE
;
3467 new -> visibility
= VISIBILITY_PUBLIC
;
3469 /* Now delete the fields from the type since we will be
3470 allocing new space once we get the rest of the fields
3471 in attach_fields_to_type.
3472 The pointer TYPE_FIELDS(type) is left dangling but should
3473 be freed later by objstack_free */
3474 TYPE_FIELDS (type
)=0;
3475 TYPE_NFIELDS (type
) = 0;
3480 /* Create the vector of fields, and record how big it is.
3481 We need this info to record proper virtual function table information
3482 for this class's virtual functions. */
3485 attach_fields_to_type (fip
, type
, objfile
)
3486 struct field_info
*fip
;
3487 register struct type
*type
;
3488 struct objfile
*objfile
;
3490 register int nfields
= 0;
3491 register int non_public_fields
= 0;
3492 register struct nextfield
*scan
;
3494 /* Count up the number of fields that we have, as well as taking note of
3495 whether or not there are any non-public fields, which requires us to
3496 allocate and build the private_field_bits and protected_field_bits
3499 for (scan
= fip
-> list
; scan
!= NULL
; scan
= scan
-> next
)
3502 if (scan
-> visibility
!= VISIBILITY_PUBLIC
)
3504 non_public_fields
++;
3508 /* Now we know how many fields there are, and whether or not there are any
3509 non-public fields. Record the field count, allocate space for the
3510 array of fields, and create blank visibility bitfields if necessary. */
3512 TYPE_NFIELDS (type
) = nfields
;
3513 TYPE_FIELDS (type
) = (struct field
*)
3514 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
3515 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
3517 if (non_public_fields
)
3519 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3521 TYPE_FIELD_PRIVATE_BITS (type
) =
3522 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3523 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
3525 TYPE_FIELD_PROTECTED_BITS (type
) =
3526 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3527 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
3529 TYPE_FIELD_IGNORE_BITS (type
) =
3530 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3531 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
3534 /* Copy the saved-up fields into the field vector. Start from the head
3535 of the list, adding to the tail of the field array, so that they end
3536 up in the same order in the array in which they were added to the list. */
3538 while (nfields
-- > 0)
3540 TYPE_FIELD (type
, nfields
) = fip
-> list
-> field
;
3541 switch (fip
-> list
-> visibility
)
3543 case VISIBILITY_PRIVATE
:
3544 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
3547 case VISIBILITY_PROTECTED
:
3548 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
3551 case VISIBILITY_IGNORE
:
3552 SET_TYPE_FIELD_IGNORE (type
, nfields
);
3555 case VISIBILITY_PUBLIC
:
3559 /* Unknown visibility. Complain and treat it as public. */
3561 static struct complaint msg
= {
3562 "Unknown visibility `%c' for field", 0, 0};
3563 complain (&msg
, fip
-> list
-> visibility
);
3567 fip
-> list
= fip
-> list
-> next
;
3572 /* Read the description of a structure (or union type) and return an object
3573 describing the type.
3575 PP points to a character pointer that points to the next unconsumed token
3576 in the the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
3577 *PP will point to "4a:1,0,32;;".
3579 TYPE points to an incomplete type that needs to be filled in.
3581 OBJFILE points to the current objfile from which the stabs information is
3582 being read. (Note that it is redundant in that TYPE also contains a pointer
3583 to this same objfile, so it might be a good idea to eliminate it. FIXME).
3586 static struct type
*
3587 read_struct_type (pp
, type
, objfile
)
3590 struct objfile
*objfile
;
3592 struct cleanup
*back_to
;
3593 struct field_info fi
;
3598 back_to
= make_cleanup (null_cleanup
, 0);
3600 INIT_CPLUS_SPECIFIC (type
);
3601 TYPE_FLAGS (type
) &= ~TYPE_FLAG_STUB
;
3603 /* First comes the total size in bytes. */
3607 TYPE_LENGTH (type
) = read_huge_number (pp
, 0, &nbits
);
3609 return error_type (pp
, objfile
);
3612 /* Now read the baseclasses, if any, read the regular C struct or C++
3613 class member fields, attach the fields to the type, read the C++
3614 member functions, attach them to the type, and then read any tilde
3615 field (baseclass specifier for the class holding the main vtable). */
3617 if (!read_baseclasses (&fi
, pp
, type
, objfile
)
3618 || !read_struct_fields (&fi
, pp
, type
, objfile
)
3619 || !attach_fields_to_type (&fi
, type
, objfile
)
3620 || !read_member_functions (&fi
, pp
, type
, objfile
)
3621 || !attach_fn_fields_to_type (&fi
, type
)
3622 || !read_tilde_fields (&fi
, pp
, type
, objfile
))
3624 type
= error_type (pp
, objfile
);
3627 do_cleanups (back_to
);
3631 /* Read a definition of an array type,
3632 and create and return a suitable type object.
3633 Also creates a range type which represents the bounds of that
3636 static struct type
*
3637 read_array_type (pp
, type
, objfile
)
3639 register struct type
*type
;
3640 struct objfile
*objfile
;
3642 struct type
*index_type
, *element_type
, *range_type
;
3647 /* Format of an array type:
3648 "ar<index type>;lower;upper;<array_contents_type>".
3649 OS9000: "arlower,upper;<array_contents_type>".
3651 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
3652 for these, produce a type like float[][]. */
3655 index_type
= builtin_type_int
;
3658 index_type
= read_type (pp
, objfile
);
3660 /* Improper format of array type decl. */
3661 return error_type (pp
, objfile
);
3665 if (!(**pp
>= '0' && **pp
<= '9') && **pp
!= '-')
3670 lower
= read_huge_number (pp
, os9k_stabs
? ',' : ';', &nbits
);
3672 return error_type (pp
, objfile
);
3674 if (!(**pp
>= '0' && **pp
<= '9') && **pp
!= '-')
3679 upper
= read_huge_number (pp
, ';', &nbits
);
3681 return error_type (pp
, objfile
);
3683 element_type
= read_type (pp
, objfile
);
3692 create_range_type ((struct type
*) NULL
, index_type
, lower
, upper
);
3693 type
= create_array_type (type
, element_type
, range_type
);
3699 /* Read a definition of an enumeration type,
3700 and create and return a suitable type object.
3701 Also defines the symbols that represent the values of the type. */
3703 static struct type
*
3704 read_enum_type (pp
, type
, objfile
)
3706 register struct type
*type
;
3707 struct objfile
*objfile
;
3712 register struct symbol
*sym
;
3714 struct pending
**symlist
;
3715 struct pending
*osyms
, *syms
;
3718 int unsigned_enum
= 1;
3721 /* FIXME! The stabs produced by Sun CC merrily define things that ought
3722 to be file-scope, between N_FN entries, using N_LSYM. What's a mother
3723 to do? For now, force all enum values to file scope. */
3724 if (within_function
)
3725 symlist
= &local_symbols
;
3728 symlist
= &file_symbols
;
3730 o_nsyms
= osyms
? osyms
->nsyms
: 0;
3734 /* Size. Perhaps this does not have to be conditionalized on
3735 os9k_stabs (assuming the name of an enum constant can't start
3737 read_huge_number (pp
, 0, &nbits
);
3739 return error_type (pp
, objfile
);
3742 /* The aix4 compiler emits an extra field before the enum members;
3743 my guess is it's a type of some sort. Just ignore it. */
3746 /* Skip over the type. */
3750 /* Skip over the colon. */
3754 /* Read the value-names and their values.
3755 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
3756 A semicolon or comma instead of a NAME means the end. */
3757 while (**pp
&& **pp
!= ';' && **pp
!= ',')
3759 STABS_CONTINUE (pp
, objfile
);
3761 while (*p
!= ':') p
++;
3762 name
= obsavestring (*pp
, p
- *pp
, &objfile
-> symbol_obstack
);
3764 n
= read_huge_number (pp
, ',', &nbits
);
3766 return error_type (pp
, objfile
);
3768 sym
= (struct symbol
*)
3769 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
3770 memset (sym
, 0, sizeof (struct symbol
));
3771 SYMBOL_NAME (sym
) = name
;
3772 SYMBOL_LANGUAGE (sym
) = current_subfile
-> language
;
3773 SYMBOL_CLASS (sym
) = LOC_CONST
;
3774 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
3775 SYMBOL_VALUE (sym
) = n
;
3778 add_symbol_to_list (sym
, symlist
);
3783 (*pp
)++; /* Skip the semicolon. */
3785 /* Now fill in the fields of the type-structure. */
3787 TYPE_LENGTH (type
) = TARGET_INT_BIT
/ HOST_CHAR_BIT
;
3788 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
3789 TYPE_FLAGS (type
) &= ~TYPE_FLAG_STUB
;
3791 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
3792 TYPE_NFIELDS (type
) = nsyms
;
3793 TYPE_FIELDS (type
) = (struct field
*)
3794 TYPE_ALLOC (type
, sizeof (struct field
) * nsyms
);
3795 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nsyms
);
3797 /* Find the symbols for the values and put them into the type.
3798 The symbols can be found in the symlist that we put them on
3799 to cause them to be defined. osyms contains the old value
3800 of that symlist; everything up to there was defined by us. */
3801 /* Note that we preserve the order of the enum constants, so
3802 that in something like "enum {FOO, LAST_THING=FOO}" we print
3803 FOO, not LAST_THING. */
3805 for (syms
= *symlist
, n
= nsyms
- 1; syms
; syms
= syms
->next
)
3807 int last
= syms
== osyms
? o_nsyms
: 0;
3808 int j
= syms
->nsyms
;
3809 for (; --j
>= last
; --n
)
3811 struct symbol
*xsym
= syms
->symbol
[j
];
3812 SYMBOL_TYPE (xsym
) = type
;
3813 TYPE_FIELD_NAME (type
, n
) = SYMBOL_NAME (xsym
);
3814 TYPE_FIELD_BITPOS (type
, n
) = SYMBOL_VALUE (xsym
);
3815 TYPE_FIELD_BITSIZE (type
, n
) = 0;
3824 /* Sun's ACC uses a somewhat saner method for specifying the builtin
3825 typedefs in every file (for int, long, etc):
3827 type = b <signed> <width>; <offset>; <nbits>
3828 signed = u or s. Possible c in addition to u or s (for char?).
3829 offset = offset from high order bit to start bit of type.
3830 width is # bytes in object of this type, nbits is # bits in type.
3832 The width/offset stuff appears to be for small objects stored in
3833 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
3836 static struct type
*
3837 read_sun_builtin_type (pp
, typenums
, objfile
)
3840 struct objfile
*objfile
;
3855 return error_type (pp
, objfile
);
3859 /* For some odd reason, all forms of char put a c here. This is strange
3860 because no other type has this honor. We can safely ignore this because
3861 we actually determine 'char'acterness by the number of bits specified in
3867 /* The first number appears to be the number of bytes occupied
3868 by this type, except that unsigned short is 4 instead of 2.
3869 Since this information is redundant with the third number,
3870 we will ignore it. */
3871 read_huge_number (pp
, ';', &nbits
);
3873 return error_type (pp
, objfile
);
3875 /* The second number is always 0, so ignore it too. */
3876 read_huge_number (pp
, ';', &nbits
);
3878 return error_type (pp
, objfile
);
3880 /* The third number is the number of bits for this type. */
3881 type_bits
= read_huge_number (pp
, 0, &nbits
);
3883 return error_type (pp
, objfile
);
3884 /* The type *should* end with a semicolon. If it are embedded
3885 in a larger type the semicolon may be the only way to know where
3886 the type ends. If this type is at the end of the stabstring we
3887 can deal with the omitted semicolon (but we don't have to like
3888 it). Don't bother to complain(), Sun's compiler omits the semicolon
3894 return init_type (TYPE_CODE_VOID
, 1,
3895 signed_type
? 0 : TYPE_FLAG_UNSIGNED
, (char *)NULL
,
3898 return init_type (TYPE_CODE_INT
,
3899 type_bits
/ TARGET_CHAR_BIT
,
3900 signed_type
? 0 : TYPE_FLAG_UNSIGNED
, (char *)NULL
,
3904 static struct type
*
3905 read_sun_floating_type (pp
, typenums
, objfile
)
3908 struct objfile
*objfile
;
3914 /* The first number has more details about the type, for example
3916 details
= read_huge_number (pp
, ';', &nbits
);
3918 return error_type (pp
, objfile
);
3920 /* The second number is the number of bytes occupied by this type */
3921 nbytes
= read_huge_number (pp
, ';', &nbits
);
3923 return error_type (pp
, objfile
);
3925 if (details
== NF_COMPLEX
|| details
== NF_COMPLEX16
3926 || details
== NF_COMPLEX32
)
3927 /* This is a type we can't handle, but we do know the size.
3928 We also will be able to give it a name. */
3929 return init_type (TYPE_CODE_ERROR
, nbytes
, 0, NULL
, objfile
);
3931 return init_type (TYPE_CODE_FLT
, nbytes
, 0, NULL
, objfile
);
3934 /* Read a number from the string pointed to by *PP.
3935 The value of *PP is advanced over the number.
3936 If END is nonzero, the character that ends the
3937 number must match END, or an error happens;
3938 and that character is skipped if it does match.
3939 If END is zero, *PP is left pointing to that character.
3941 If the number fits in a long, set *BITS to 0 and return the value.
3942 If not, set *BITS to be the number of bits in the number and return 0.
3944 If encounter garbage, set *BITS to -1 and return 0. */
3947 read_huge_number (pp
, end
, bits
)
3967 /* Leading zero means octal. GCC uses this to output values larger
3968 than an int (because that would be hard in decimal). */
3976 upper_limit
= ULONG_MAX
/ radix
;
3978 upper_limit
= LONG_MAX
/ radix
;
3980 while ((c
= *p
++) >= '0' && c
< ('0' + radix
))
3982 if (n
<= upper_limit
)
3985 n
+= c
- '0'; /* FIXME this overflows anyway */
3990 /* This depends on large values being output in octal, which is
3997 /* Ignore leading zeroes. */
4001 else if (c
== '2' || c
== '3')
4027 /* Large decimal constants are an error (because it is hard to
4028 count how many bits are in them). */
4034 /* -0x7f is the same as 0x80. So deal with it by adding one to
4035 the number of bits. */
4047 /* It's *BITS which has the interesting information. */
4051 static struct type
*
4052 read_range_type (pp
, typenums
, objfile
)
4055 struct objfile
*objfile
;
4057 char *orig_pp
= *pp
;
4062 struct type
*result_type
;
4063 struct type
*index_type
= NULL
;
4065 /* First comes a type we are a subrange of.
4066 In C it is usually 0, 1 or the type being defined. */
4067 if (read_type_number (pp
, rangenums
) != 0)
4068 return error_type (pp
, objfile
);
4069 self_subrange
= (rangenums
[0] == typenums
[0] &&
4070 rangenums
[1] == typenums
[1]);
4075 index_type
= read_type (pp
, objfile
);
4078 /* A semicolon should now follow; skip it. */
4082 /* The remaining two operands are usually lower and upper bounds
4083 of the range. But in some special cases they mean something else. */
4084 n2
= read_huge_number (pp
, ';', &n2bits
);
4085 n3
= read_huge_number (pp
, ';', &n3bits
);
4087 if (n2bits
== -1 || n3bits
== -1)
4088 return error_type (pp
, objfile
);
4091 goto handle_true_range
;
4093 /* If limits are huge, must be large integral type. */
4094 if (n2bits
!= 0 || n3bits
!= 0)
4096 char got_signed
= 0;
4097 char got_unsigned
= 0;
4098 /* Number of bits in the type. */
4101 /* Range from 0 to <large number> is an unsigned large integral type. */
4102 if ((n2bits
== 0 && n2
== 0) && n3bits
!= 0)
4107 /* Range from <large number> to <large number>-1 is a large signed
4108 integral type. Take care of the case where <large number> doesn't
4109 fit in a long but <large number>-1 does. */
4110 else if ((n2bits
!= 0 && n3bits
!= 0 && n2bits
== n3bits
+ 1)
4111 || (n2bits
!= 0 && n3bits
== 0
4112 && (n2bits
== sizeof (long) * HOST_CHAR_BIT
)
4119 if (got_signed
|| got_unsigned
)
4121 return init_type (TYPE_CODE_INT
, nbits
/ TARGET_CHAR_BIT
,
4122 got_unsigned
? TYPE_FLAG_UNSIGNED
: 0, NULL
,
4126 return error_type (pp
, objfile
);
4129 /* A type defined as a subrange of itself, with bounds both 0, is void. */
4130 if (self_subrange
&& n2
== 0 && n3
== 0)
4131 return init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
4133 /* If n3 is zero and n2 is positive, we want a floating type,
4134 and n2 is the width in bytes.
4136 Fortran programs appear to use this for complex types also,
4137 and they give no way to distinguish between double and single-complex!
4139 GDB does not have complex types.
4141 Just return the complex as a float of that size. It won't work right
4142 for the complex values, but at least it makes the file loadable. */
4144 if (n3
== 0 && n2
> 0)
4146 return init_type (TYPE_CODE_FLT
, n2
, 0, NULL
, objfile
);
4149 /* If the upper bound is -1, it must really be an unsigned int. */
4151 else if (n2
== 0 && n3
== -1)
4153 /* It is unsigned int or unsigned long. */
4154 /* GCC 2.3.3 uses this for long long too, but that is just a GDB 3.5
4155 compatibility hack. */
4156 return init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
4157 TYPE_FLAG_UNSIGNED
, NULL
, objfile
);
4160 /* Special case: char is defined (Who knows why) as a subrange of
4161 itself with range 0-127. */
4162 else if (self_subrange
&& n2
== 0 && n3
== 127)
4163 return init_type (TYPE_CODE_INT
, 1, 0, NULL
, objfile
);
4165 else if (current_symbol
&& SYMBOL_LANGUAGE (current_symbol
) == language_chill
4167 goto handle_true_range
;
4169 /* We used to do this only for subrange of self or subrange of int. */
4173 /* n3 actually gives the size. */
4174 return init_type (TYPE_CODE_INT
, - n3
, TYPE_FLAG_UNSIGNED
,
4177 return init_type (TYPE_CODE_INT
, 1, TYPE_FLAG_UNSIGNED
, NULL
, objfile
);
4179 return init_type (TYPE_CODE_INT
, 2, TYPE_FLAG_UNSIGNED
, NULL
, objfile
);
4181 /* -1 is used for the upper bound of (4 byte) "unsigned int" and
4182 "unsigned long", and we already checked for that,
4183 so don't need to test for it here. */
4185 /* I think this is for Convex "long long". Since I don't know whether
4186 Convex sets self_subrange, I also accept that particular size regardless
4187 of self_subrange. */
4188 else if (n3
== 0 && n2
< 0
4190 || n2
== - TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
))
4191 return init_type (TYPE_CODE_INT
, - n2
, 0, NULL
, objfile
);
4192 else if (n2
== -n3
-1)
4195 return init_type (TYPE_CODE_INT
, 1, 0, NULL
, objfile
);
4197 return init_type (TYPE_CODE_INT
, 2, 0, NULL
, objfile
);
4198 if (n3
== 0x7fffffff)
4199 return init_type (TYPE_CODE_INT
, 4, 0, NULL
, objfile
);
4202 /* We have a real range type on our hands. Allocate space and
4203 return a real pointer. */
4207 index_type
= builtin_type_int
;
4209 index_type
= *dbx_lookup_type (rangenums
);
4210 if (index_type
== NULL
)
4212 /* Does this actually ever happen? Is that why we are worrying
4213 about dealing with it rather than just calling error_type? */
4215 static struct type
*range_type_index
;
4217 complain (&range_type_base_complaint
, rangenums
[1]);
4218 if (range_type_index
== NULL
)
4220 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
4221 0, "range type index type", NULL
);
4222 index_type
= range_type_index
;
4225 result_type
= create_range_type ((struct type
*) NULL
, index_type
, n2
, n3
);
4226 return (result_type
);
4229 /* Read in an argument list. This is a list of types, separated by commas
4230 and terminated with END. Return the list of types read in, or (struct type
4231 **)-1 if there is an error. */
4233 static struct type
**
4234 read_args (pp
, end
, objfile
)
4237 struct objfile
*objfile
;
4239 /* FIXME! Remove this arbitrary limit! */
4240 struct type
*types
[1024], **rval
; /* allow for fns of 1023 parameters */
4246 /* Invalid argument list: no ','. */
4247 return (struct type
**)-1;
4249 STABS_CONTINUE (pp
, objfile
);
4250 types
[n
++] = read_type (pp
, objfile
);
4252 (*pp
)++; /* get past `end' (the ':' character) */
4256 rval
= (struct type
**) xmalloc (2 * sizeof (struct type
*));
4258 else if (TYPE_CODE (types
[n
-1]) != TYPE_CODE_VOID
)
4260 rval
= (struct type
**) xmalloc ((n
+ 1) * sizeof (struct type
*));
4261 memset (rval
+ n
, 0, sizeof (struct type
*));
4265 rval
= (struct type
**) xmalloc (n
* sizeof (struct type
*));
4267 memcpy (rval
, types
, n
* sizeof (struct type
*));
4271 /* Common block handling. */
4273 /* List of symbols declared since the last BCOMM. This list is a tail
4274 of local_symbols. When ECOMM is seen, the symbols on the list
4275 are noted so their proper addresses can be filled in later,
4276 using the common block base address gotten from the assembler
4279 static struct pending
*common_block
;
4280 static int common_block_i
;
4282 /* Name of the current common block. We get it from the BCOMM instead of the
4283 ECOMM to match IBM documentation (even though IBM puts the name both places
4284 like everyone else). */
4285 static char *common_block_name
;
4287 /* Process a N_BCOMM symbol. The storage for NAME is not guaranteed
4288 to remain after this function returns. */
4291 common_block_start (name
, objfile
)
4293 struct objfile
*objfile
;
4295 if (common_block_name
!= NULL
)
4297 static struct complaint msg
= {
4298 "Invalid symbol data: common block within common block",
4302 common_block
= local_symbols
;
4303 common_block_i
= local_symbols
? local_symbols
->nsyms
: 0;
4304 common_block_name
= obsavestring (name
, strlen (name
),
4305 &objfile
-> symbol_obstack
);
4308 /* Process a N_ECOMM symbol. */
4311 common_block_end (objfile
)
4312 struct objfile
*objfile
;
4314 /* Symbols declared since the BCOMM are to have the common block
4315 start address added in when we know it. common_block and
4316 common_block_i point to the first symbol after the BCOMM in
4317 the local_symbols list; copy the list and hang it off the
4318 symbol for the common block name for later fixup. */
4321 struct pending
*new = 0;
4322 struct pending
*next
;
4325 if (common_block_name
== NULL
)
4327 static struct complaint msg
= {"ECOMM symbol unmatched by BCOMM", 0, 0};
4332 sym
= (struct symbol
*)
4333 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
4334 memset (sym
, 0, sizeof (struct symbol
));
4335 /* Note: common_block_name already saved on symbol_obstack */
4336 SYMBOL_NAME (sym
) = common_block_name
;
4337 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
4339 /* Now we copy all the symbols which have been defined since the BCOMM. */
4341 /* Copy all the struct pendings before common_block. */
4342 for (next
= local_symbols
;
4343 next
!= NULL
&& next
!= common_block
;
4346 for (j
= 0; j
< next
->nsyms
; j
++)
4347 add_symbol_to_list (next
->symbol
[j
], &new);
4350 /* Copy however much of COMMON_BLOCK we need. If COMMON_BLOCK is
4351 NULL, it means copy all the local symbols (which we already did
4354 if (common_block
!= NULL
)
4355 for (j
= common_block_i
; j
< common_block
->nsyms
; j
++)
4356 add_symbol_to_list (common_block
->symbol
[j
], &new);
4358 SYMBOL_TYPE (sym
) = (struct type
*) new;
4360 /* Should we be putting local_symbols back to what it was?
4363 i
= hashname (SYMBOL_NAME (sym
));
4364 SYMBOL_VALUE_CHAIN (sym
) = global_sym_chain
[i
];
4365 global_sym_chain
[i
] = sym
;
4366 common_block_name
= NULL
;
4369 /* Add a common block's start address to the offset of each symbol
4370 declared to be in it (by being between a BCOMM/ECOMM pair that uses
4371 the common block name). */
4374 fix_common_block (sym
, valu
)
4378 struct pending
*next
= (struct pending
*) SYMBOL_TYPE (sym
);
4379 for ( ; next
; next
= next
->next
)
4382 for (j
= next
->nsyms
- 1; j
>= 0; j
--)
4383 SYMBOL_VALUE_ADDRESS (next
->symbol
[j
]) += valu
;
4389 /* What about types defined as forward references inside of a small lexical
4391 /* Add a type to the list of undefined types to be checked through
4392 once this file has been read in. */
4395 add_undefined_type (type
)
4398 if (undef_types_length
== undef_types_allocated
)
4400 undef_types_allocated
*= 2;
4401 undef_types
= (struct type
**)
4402 xrealloc ((char *) undef_types
,
4403 undef_types_allocated
* sizeof (struct type
*));
4405 undef_types
[undef_types_length
++] = type
;
4408 /* Go through each undefined type, see if it's still undefined, and fix it
4409 up if possible. We have two kinds of undefined types:
4411 TYPE_CODE_ARRAY: Array whose target type wasn't defined yet.
4412 Fix: update array length using the element bounds
4413 and the target type's length.
4414 TYPE_CODE_STRUCT, TYPE_CODE_UNION: Structure whose fields were not
4415 yet defined at the time a pointer to it was made.
4416 Fix: Do a full lookup on the struct/union tag. */
4418 cleanup_undefined_types ()
4422 for (type
= undef_types
; type
< undef_types
+ undef_types_length
; type
++)
4424 switch (TYPE_CODE (*type
))
4427 case TYPE_CODE_STRUCT
:
4428 case TYPE_CODE_UNION
:
4429 case TYPE_CODE_ENUM
:
4431 /* Check if it has been defined since. Need to do this here
4432 as well as in check_typedef to deal with the (legitimate in
4433 C though not C++) case of several types with the same name
4434 in different source files. */
4435 if (TYPE_FLAGS (*type
) & TYPE_FLAG_STUB
)
4437 struct pending
*ppt
;
4439 /* Name of the type, without "struct" or "union" */
4440 char *typename
= TYPE_TAG_NAME (*type
);
4442 if (typename
== NULL
)
4444 static struct complaint msg
= {"need a type name", 0, 0};
4448 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
4450 for (i
= 0; i
< ppt
->nsyms
; i
++)
4452 struct symbol
*sym
= ppt
->symbol
[i
];
4454 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
4455 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
4456 && (TYPE_CODE (SYMBOL_TYPE (sym
)) ==
4458 && STREQ (SYMBOL_NAME (sym
), typename
))
4460 memcpy (*type
, SYMBOL_TYPE (sym
),
4461 sizeof (struct type
));
4471 static struct complaint msg
= {"\
4472 GDB internal error. cleanup_undefined_types with bad type %d.", 0, 0};
4473 complain (&msg
, TYPE_CODE (*type
));
4479 undef_types_length
= 0;
4482 /* Scan through all of the global symbols defined in the object file,
4483 assigning values to the debugging symbols that need to be assigned
4484 to. Get these symbols from the minimal symbol table. */
4487 scan_file_globals (objfile
)
4488 struct objfile
*objfile
;
4491 struct minimal_symbol
*msymbol
;
4492 struct symbol
*sym
, *prev
;
4493 struct objfile
*resolve_objfile
;
4495 /* SVR4 based linkers copy referenced global symbols from shared
4496 libraries to the main executable.
4497 If we are scanning the symbols for a shared library, try to resolve
4498 them from the minimal symbols of the main executable first. */
4500 if (symfile_objfile
&& objfile
!= symfile_objfile
)
4501 resolve_objfile
= symfile_objfile
;
4503 resolve_objfile
= objfile
;
4507 /* Avoid expensive loop through all minimal symbols if there are
4508 no unresolved symbols. */
4509 for (hash
= 0; hash
< HASHSIZE
; hash
++)
4511 if (global_sym_chain
[hash
])
4514 if (hash
>= HASHSIZE
)
4517 for (msymbol
= resolve_objfile
-> msymbols
;
4518 msymbol
&& SYMBOL_NAME (msymbol
) != NULL
;
4523 /* Skip static symbols. */
4524 switch (MSYMBOL_TYPE (msymbol
))
4536 /* Get the hash index and check all the symbols
4537 under that hash index. */
4539 hash
= hashname (SYMBOL_NAME (msymbol
));
4541 for (sym
= global_sym_chain
[hash
]; sym
;)
4543 if (SYMBOL_NAME (msymbol
)[0] == SYMBOL_NAME (sym
)[0] &&
4544 STREQ(SYMBOL_NAME (msymbol
) + 1, SYMBOL_NAME (sym
) + 1))
4546 /* Splice this symbol out of the hash chain and
4547 assign the value we have to it. */
4550 SYMBOL_VALUE_CHAIN (prev
) = SYMBOL_VALUE_CHAIN (sym
);
4554 global_sym_chain
[hash
] = SYMBOL_VALUE_CHAIN (sym
);
4557 /* Check to see whether we need to fix up a common block. */
4558 /* Note: this code might be executed several times for
4559 the same symbol if there are multiple references. */
4561 if (SYMBOL_CLASS (sym
) == LOC_BLOCK
)
4563 fix_common_block (sym
, SYMBOL_VALUE_ADDRESS (msymbol
));
4567 SYMBOL_VALUE_ADDRESS (sym
)
4568 = SYMBOL_VALUE_ADDRESS (msymbol
);
4571 SYMBOL_SECTION (sym
) = SYMBOL_SECTION (msymbol
);
4575 sym
= SYMBOL_VALUE_CHAIN (prev
);
4579 sym
= global_sym_chain
[hash
];
4585 sym
= SYMBOL_VALUE_CHAIN (sym
);
4589 if (resolve_objfile
== objfile
)
4591 resolve_objfile
= objfile
;
4594 /* Change the storage class of any remaining unresolved globals to
4595 LOC_UNRESOLVED and remove them from the chain. */
4596 for (hash
= 0; hash
< HASHSIZE
; hash
++)
4598 sym
= global_sym_chain
[hash
];
4602 sym
= SYMBOL_VALUE_CHAIN (sym
);
4604 /* Change the symbol address from the misleading chain value
4606 SYMBOL_VALUE_ADDRESS (prev
) = 0;
4608 /* Complain about unresolved common block symbols. */
4609 if (SYMBOL_CLASS (prev
) == LOC_STATIC
)
4610 SYMBOL_CLASS (prev
) = LOC_UNRESOLVED
;
4612 complain (&unresolved_sym_chain_complaint
,
4613 objfile
-> name
, SYMBOL_NAME (prev
));
4616 memset (global_sym_chain
, 0, sizeof (global_sym_chain
));
4619 /* Initialize anything that needs initializing when starting to read
4620 a fresh piece of a symbol file, e.g. reading in the stuff corresponding
4628 /* Initialize anything that needs initializing when a completely new
4629 symbol file is specified (not just adding some symbols from another
4630 file, e.g. a shared library). */
4633 stabsread_new_init ()
4635 /* Empty the hash table of global syms looking for values. */
4636 memset (global_sym_chain
, 0, sizeof (global_sym_chain
));
4639 /* Initialize anything that needs initializing at the same time as
4640 start_symtab() is called. */
4644 global_stabs
= NULL
; /* AIX COFF */
4645 /* Leave FILENUM of 0 free for builtin types and this file's types. */
4646 n_this_object_header_files
= 1;
4647 type_vector_length
= 0;
4648 type_vector
= (struct type
**) 0;
4650 /* FIXME: If common_block_name is not already NULL, we should complain(). */
4651 common_block_name
= NULL
;
4656 /* Call after end_symtab() */
4662 free ((char *) type_vector
);
4665 type_vector_length
= 0;
4666 previous_stab_code
= 0;
4670 finish_global_stabs (objfile
)
4671 struct objfile
*objfile
;
4675 patch_block_stabs (global_symbols
, global_stabs
, objfile
);
4676 free ((PTR
) global_stabs
);
4677 global_stabs
= NULL
;
4681 /* Initializer for this module */
4684 _initialize_stabsread ()
4686 undef_types_allocated
= 20;
4687 undef_types_length
= 0;
4688 undef_types
= (struct type
**)
4689 xmalloc (undef_types_allocated
* sizeof (struct type
*));