1 /* Support routines for decoding "stabs" debugging information format.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996
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 **, char));
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
)
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
[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
542 advance string pointer past suibstring */
561 /* Physname gets strcat'd onto sname in order to recreate the mangled name
562 (see funtion gdb_mangle_name in gdbtypes.c). For cfront, make the physname
563 look like that of g++ - take out the initial mangling
564 eg: for sname="a" and fname="foo__1aFPFs_i" return "FPFs_i" */
566 get_cfront_method_physname(fname
)
570 /* FIXME would like to make this generic for g++ too, but
571 that is already handled in read_member_funcctions */
574 /* search ahead to find the start of the mangled suffix */
575 if (*p
== '_' && *(p
+1)=='_') /* compiler generated; probably a ctor/dtor */
577 while (p
&& ((p
+1) - fname
) < strlen(fname
) && *(p
+1)!='_')
579 if (!(p
&& *p
=='_' && *(p
+1)=='_'))
580 error("Invalid mangled function name %s",fname
);
581 p
+=2; /* advance past '__' */
583 /* struct name length and name of type should come next; advance past it */
586 len
= len
*10 + (*p
- '0');
594 /* Read base classes within cfront class definition.
595 eg: A:ZcA;1@Bpub v2@Bvirpri;__ct__1AFv func__1AFv *sfunc__1AFv ;as__1A ;;
598 A:ZcA;;foopri__1AFv foopro__1AFv __ct__1AFv __ct__1AFRC1A foopub__1AFv ;;;
602 read_cfront_baseclasses(fip
, pp
, type
, objfile
)
603 struct field_info
*fip
;
604 struct objfile
* objfile
;
608 static struct complaint msg_unknown
= {"\
609 Unsupported token in stabs string %s.\n",
611 static struct complaint msg_notfound
= {"\
612 Unable to find base type for %s.\n",
617 struct nextfield
*new;
619 if (**pp
==';') /* no base classes; return */
625 /* first count base classes so we can allocate space before parsing */
626 for (p
= *pp
; p
&& *p
&& *p
!=';'; p
++)
630 bnum
++; /* add one more for last one */
632 /* now parse the base classes until we get to the start of the methods
633 (code extracted and munged from read_baseclasses) */
634 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
635 TYPE_N_BASECLASSES(type
) = bnum
;
639 int num_bytes
= B_BYTES (TYPE_N_BASECLASSES (type
));
641 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
642 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
644 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), TYPE_N_BASECLASSES (type
));
647 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
649 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
650 make_cleanup (free
, new);
651 memset (new, 0, sizeof (struct nextfield
));
652 new -> next
= fip
-> list
;
654 new -> field
.bitsize
= 0; /* this should be an unpacked field! */
656 STABS_CONTINUE (pp
, objfile
);
658 /* virtual? eg: v2@Bvir */
661 SET_TYPE_FIELD_VIRTUAL (type
, i
);
665 /* access? eg: 2@Bvir */
666 /* Note: protected inheritance not supported in cfront */
669 case CFRONT_VISIBILITY_PRIVATE
:
670 new -> visibility
= VISIBILITY_PRIVATE
;
672 case CFRONT_VISIBILITY_PUBLIC
:
673 new -> visibility
= VISIBILITY_PUBLIC
;
676 /* Bad visibility format. Complain and treat it as
679 static struct complaint msg
= {
680 "Unknown visibility `%c' for baseclass", 0, 0};
681 complain (&msg
, new -> visibility
);
682 new -> visibility
= VISIBILITY_PUBLIC
;
686 /* "@" comes next - eg: @Bvir */
689 complain (&msg_unknown
, *pp
);
695 /* Set the bit offset of the portion of the object corresponding
696 to this baseclass. Always zero in the absence of
697 multiple inheritance. */
698 /* Unable to read bit position from stabs;
699 Assuming no multiple inheritance for now FIXME! */
700 /* We may have read this in the structure definition;
701 now we should fixup the members to be the actual base classes */
702 new -> field
.bitpos
= 0;
704 /* Get the base class name and type */
706 char * bname
; /* base class name */
707 struct symbol
* bsym
; /* base class */
709 p1
= strchr(*pp
,' ');
710 p2
= strchr(*pp
,';');
712 bname
= get_substring(pp
,' ');
714 bname
= get_substring(pp
,';');
715 if (!bname
|| !*bname
)
717 complain (&msg_unknown
, *pp
);
720 /* FIXME! attach base info to type */
721 bsym
= lookup_symbol (bname
, 0, STRUCT_NAMESPACE
, 0, 0); /*demangled_name*/
724 new -> field
.type
= SYMBOL_TYPE(bsym
);
725 new -> field
.name
= type_name_no_tag (new -> field
.type
);
729 complain (&msg_notfound
, *pp
);
734 /* If more base classes to parse, loop again.
735 We ate the last ' ' or ';' in get_substring,
736 so on exit we will have skipped the trailing ';' */
737 /* if invalid, return 0; add code to detect - FIXME! */
742 /* read cfront member functions.
743 pp points to string starting with list of functions
744 eg: A:ZcA;1@Bpub v2@Bvirpri;__ct__1AFv func__1AFv *sfunc__1AFv ;as__1A ;;
745 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
746 A:ZcA;;foopri__1AFv foopro__1AFv __ct__1AFv __ct__1AFRC1A foopub__1AFv ;;;
747 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
751 read_cfront_member_functions(fip
, pp
, type
, objfile
)
752 struct field_info
*fip
;
755 struct objfile
*objfile
;
757 /* This code extracted from read_member_functions
758 so as to do the similar thing for our funcs */
762 /* Total number of member functions defined in this class. If the class
763 defines two `f' functions, and one `g' function, then this will have
765 int total_length
= 0;
769 struct next_fnfield
*next
;
770 struct fn_field fn_field
;
772 struct type
*look_ahead_type
;
773 struct next_fnfieldlist
*new_fnlist
;
774 struct next_fnfield
*new_sublist
;
777 struct symbol
* ref_func
=0;
779 /* Process each list until we find something that is not a member function
780 or find the end of the functions. */
782 /* eg: p = "__ct__1AFv foo__1AFv ;;;" */
783 STABS_CONTINUE (pp
, objfile
); /* handle \\ */
784 while (**pp
!=';' && (fname
= get_substring(pp
,' '),fname
))
789 if (fname
[0]=='*') /* static member */
795 ref_func
= lookup_symbol (fname
, 0, VAR_NAMESPACE
, 0, 0); /*demangled_name*/
798 static struct complaint msg
= {"\
799 Unable to find function symbol for %s\n",
801 complain (&msg
, fname
);
805 look_ahead_type
= NULL
;
808 new_fnlist
= (struct next_fnfieldlist
*)
809 xmalloc (sizeof (struct next_fnfieldlist
));
810 make_cleanup (free
, new_fnlist
);
811 memset (new_fnlist
, 0, sizeof (struct next_fnfieldlist
));
813 /* The following is code to work around cfront generated stabs.
814 The stabs contains full mangled name for each field.
815 We try to demangle the name and extract the field name out of it. */
817 char *dem
, *dem_p
, *dem_args
;
819 dem
= cplus_demangle (fname
, DMGL_ANSI
| DMGL_PARAMS
);
822 dem_p
= strrchr (dem
, ':');
823 if (dem_p
!= 0 && *(dem_p
-1)==':')
825 /* get rid of args */
826 dem_args
= strchr (dem_p
, '(');
827 if (dem_args
== NULL
)
828 dem_len
= strlen(dem_p
);
830 dem_len
= dem_args
- dem_p
;
832 obsavestring (dem_p
, dem_len
, &objfile
-> type_obstack
);
837 obsavestring (fname
, strlen(fname
), &objfile
-> type_obstack
);
839 } /* end of code for cfront work around */
841 new_fnlist
-> fn_fieldlist
.name
= main_fn_name
;
843 /*-------------------------------------------------*/
844 /* Set up the sublists
845 Sublists are stuff like args, static, visibility, etc.
846 so in ARM, we have to set that info some other way.
847 Multiple sublists happen if overloading
848 eg: foo::26=##1;:;2A.;
849 In g++, we'd loop here thru all the sublists... */
851 (struct next_fnfield
*) xmalloc (sizeof (struct next_fnfield
));
852 make_cleanup (free
, new_sublist
);
853 memset (new_sublist
, 0, sizeof (struct next_fnfield
));
855 /* eat 1; from :;2A.; */
856 new_sublist
-> fn_field
.type
= SYMBOL_TYPE(ref_func
); /* normally takes a read_type */
857 /* make this type look like a method stub for gdb */
858 TYPE_FLAGS (new_sublist
-> fn_field
.type
) |= TYPE_FLAG_STUB
;
859 TYPE_CODE (new_sublist
-> fn_field
.type
) = TYPE_CODE_METHOD
;
861 /* If this is just a stub, then we don't have the real name here. */
862 if (TYPE_FLAGS (new_sublist
-> fn_field
.type
) & TYPE_FLAG_STUB
)
864 if (!TYPE_DOMAIN_TYPE (new_sublist
-> fn_field
.type
))
865 TYPE_DOMAIN_TYPE (new_sublist
-> fn_field
.type
) = type
;
866 new_sublist
-> fn_field
.is_stub
= 1;
868 /* physname used later in mangling; eg PFs_i,5 for foo__1aFPFs_i
869 physname gets strcat'd in order to recreate the onto mangled name */
870 pname
= get_cfront_method_physname(fname
);
871 new_sublist
-> fn_field
.physname
= savestring (pname
, strlen(pname
));
874 /* Set this member function's visibility fields.
875 Unable to distinguish access from stabs definition!
876 Assuming public for now. FIXME!
877 (for private, set new_sublist->fn_field.is_private = 1,
878 for public, set new_sublist->fn_field.is_protected = 1) */
880 /* Unable to distinguish const/volatile from stabs definition!
881 Assuming normal for now. FIXME! */
883 new_sublist
-> fn_field
.is_const
= 0;
884 new_sublist
-> fn_field
.is_volatile
= 0; /* volatile not implemented in cfront */
886 /* set virtual/static function info
887 How to get vtable offsets ?
888 Assuming normal for now FIXME!!
889 For vtables, figure out from whence this virtual function came.
890 It may belong to virtual function table of
891 one of its baseclasses.
893 new_sublist -> fn_field.voffset = vtable offset,
894 new_sublist -> fn_field.fcontext = look_ahead_type;
895 where look_ahead_type is type of baseclass */
897 new_sublist
-> fn_field
.voffset
= VOFFSET_STATIC
;
898 else /* normal member function. */
899 new_sublist
-> fn_field
.voffset
= 0;
900 new_sublist
-> fn_field
.fcontext
= 0;
903 /* prepare new sublist */
904 new_sublist
-> next
= sublist
;
905 sublist
= new_sublist
;
907 /* In g++, we loop thu sublists - now we set from function */
909 new_fnlist
-> fn_fieldlist
.fn_fields
= (struct fn_field
*)
910 obstack_alloc (&objfile
-> type_obstack
,
911 sizeof (struct fn_field
) * length
);
912 memset (new_fnlist
-> fn_fieldlist
.fn_fields
, 0,
913 sizeof (struct fn_field
) * length
);
914 for (i
= length
; (i
--, sublist
); sublist
= sublist
-> next
)
916 new_fnlist
-> fn_fieldlist
.fn_fields
[i
] = sublist
-> fn_field
;
919 new_fnlist
-> fn_fieldlist
.length
= length
;
920 new_fnlist
-> next
= fip
-> fnlist
;
921 fip
-> fnlist
= new_fnlist
;
923 total_length
+= length
;
924 STABS_CONTINUE (pp
, objfile
); /* handle \\ */
929 /* type should already have space */
930 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
931 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * nfn_fields
);
932 memset (TYPE_FN_FIELDLISTS (type
), 0,
933 sizeof (struct fn_fieldlist
) * nfn_fields
);
934 TYPE_NFN_FIELDS (type
) = nfn_fields
;
935 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
938 /* end of scope for reading member func */
941 /* skip trailing ';' and bump count of number of fields seen */
949 /* This routine fixes up partial cfront types that were created
950 while parsing the stabs. The main need for this function is
951 to add information such as methods to classes.
952 Examples of "p": "sA;;__ct__1AFv foo__1AFv ;;;" */
954 resolve_cfront_continuation(objfile
, sym
, p
)
955 struct objfile
* objfile
;
959 struct symbol
* ref_sym
=0;
961 /* snarfed from read_struct_type */
962 struct field_info fi
;
964 struct cleanup
*back_to
;
966 /* need to make sure that fi isn't gunna conflict with struct
967 in case struct already had some fnfs */
970 back_to
= make_cleanup (null_cleanup
, 0);
972 /* we only accept structs, classes and unions at the moment.
973 Other continuation types include t (typedef), r (long dbl), ...
974 We may want to add support for them as well;
975 right now they are handled by duplicating the symbol information
976 into the type information (see define_symbol) */
977 if (*p
!= 's' /* structs */
978 && *p
!= 'c' /* class */
979 && *p
!= 'u') /* union */
980 return; /* only handle C++ types */
983 /* get symbol typs name and validate
984 eg: p = "A;;__ct__1AFv foo__1AFv ;;;" */
985 sname
= get_substring(&p
,';');
986 if (!sname
|| strcmp(sname
,SYMBOL_NAME(sym
)))
987 error("Internal error: base symbol type name does not match\n");
989 /* find symbol's internal gdb reference */
990 ref_sym
= lookup_symbol (SYMBOL_NAME(sym
), 0, STRUCT_NAMESPACE
, 0, 0); /*demangled_name*/
991 /* This is the real sym that we want;
992 sym was a temp hack to make debugger happy */
993 /* ref_sym should already have space */
994 type
= SYMBOL_TYPE(ref_sym
);
997 /* Now read the baseclasses, if any, read the regular C struct or C++
998 class member fields, attach the fields to the type, read the C++
999 member functions, attach them to the type, and then read any tilde
1000 field (baseclass specifier for the class holding the main vtable). */
1002 if (!read_cfront_baseclasses (&fi
, &p
, type
, objfile
)
1003 /* g++ does this next, but cfront already did this:
1004 || !read_struct_fields (&fi, &p, type, objfile) */
1005 || !copy_cfront_struct_fields (&fi
, type
, objfile
)
1006 || !read_cfront_member_functions (&fi
, &p
, type
, objfile
)
1007 || !read_cfront_static_fields(&fi
, &p
, type
, objfile
)
1008 || !attach_fields_to_type (&fi
, type
, objfile
)
1009 || !attach_fn_fields_to_type (&fi
, type
)
1010 /* g++ does this next, but cfront doesn't seem to have this:
1011 || !read_tilde_fields (&fi, &p, type, objfile) */
1014 type
= error_type (&p
, objfile
);
1017 do_cleanups (back_to
);
1019 /* End of code added to support parsing of ARM/Cfront stabs strings */
1024 define_symbol (valu
, string
, desc
, type
, objfile
)
1029 struct objfile
*objfile
;
1031 register struct symbol
*sym
;
1032 char *p
= (char *) strchr (string
, ':');
1037 /* We would like to eliminate nameless symbols, but keep their types.
1038 E.g. stab entry ":t10=*2" should produce a type 10, which is a pointer
1039 to type 2, but, should not create a symbol to address that type. Since
1040 the symbol will be nameless, there is no way any user can refer to it. */
1044 /* Ignore syms with empty names. */
1048 /* Ignore old-style symbols from cc -go */
1058 /* If a nameless stab entry, all we need is the type, not the symbol.
1059 e.g. ":t10=*2" or a nameless enum like " :T16=ered:0,green:1,blue:2,;" */
1060 nameless
= (p
== string
|| ((string
[0] == ' ') && (string
[1] == ':')));
1062 current_symbol
= sym
= (struct symbol
*)
1063 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
1064 memset (sym
, 0, sizeof (struct symbol
));
1066 switch (type
& N_TYPE
)
1069 SYMBOL_SECTION(sym
) = SECT_OFF_TEXT
;
1072 SYMBOL_SECTION(sym
) = SECT_OFF_DATA
;
1075 SYMBOL_SECTION(sym
) = SECT_OFF_BSS
;
1079 if (processing_gcc_compilation
)
1081 /* GCC 2.x puts the line number in desc. SunOS apparently puts in the
1082 number of bytes occupied by a type or object, which we ignore. */
1083 SYMBOL_LINE(sym
) = desc
;
1087 SYMBOL_LINE(sym
) = 0; /* unknown */
1090 if (is_cplus_marker (string
[0]))
1092 /* Special GNU C++ names. */
1096 SYMBOL_NAME (sym
) = obsavestring ("this", strlen ("this"),
1097 &objfile
-> symbol_obstack
);
1100 case 'v': /* $vtbl_ptr_type */
1101 /* Was: SYMBOL_NAME (sym) = "vptr"; */
1105 SYMBOL_NAME (sym
) = obsavestring ("eh_throw", strlen ("eh_throw"),
1106 &objfile
-> symbol_obstack
);
1110 /* This was an anonymous type that was never fixed up. */
1113 #ifdef STATIC_TRANSFORM_NAME
1115 /* SunPRO (3.0 at least) static variable encoding. */
1120 complain (&unrecognized_cplus_name_complaint
, string
);
1121 goto normal
; /* Do *something* with it */
1127 SYMBOL_LANGUAGE (sym
) = current_subfile
-> language
;
1128 SYMBOL_NAME (sym
) = (char *)
1129 obstack_alloc (&objfile
-> symbol_obstack
, ((p
- string
) + 1));
1130 /* Open-coded memcpy--saves function call time. */
1131 /* FIXME: Does it really? Try replacing with simple strcpy and
1132 try it on an executable with a large symbol table. */
1133 /* FIXME: considering that gcc can open code memcpy anyway, I
1134 doubt it. xoxorich. */
1136 register char *p1
= string
;
1137 register char *p2
= SYMBOL_NAME (sym
);
1145 /* If this symbol is from a C++ compilation, then attempt to cache the
1146 demangled form for future reference. This is a typical time versus
1147 space tradeoff, that was decided in favor of time because it sped up
1148 C++ symbol lookups by a factor of about 20. */
1150 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
1154 /* Determine the type of name being defined. */
1156 /* Getting GDB to correctly skip the symbol on an undefined symbol
1157 descriptor and not ever dump core is a very dodgy proposition if
1158 we do things this way. I say the acorn RISC machine can just
1159 fix their compiler. */
1160 /* The Acorn RISC machine's compiler can put out locals that don't
1161 start with "234=" or "(3,4)=", so assume anything other than the
1162 deftypes we know how to handle is a local. */
1163 if (!strchr ("cfFGpPrStTvVXCR", *p
))
1165 if (isdigit (*p
) || *p
== '(' || *p
== '-')
1174 /* c is a special case, not followed by a type-number.
1175 SYMBOL:c=iVALUE for an integer constant symbol.
1176 SYMBOL:c=rVALUE for a floating constant symbol.
1177 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
1178 e.g. "b:c=e6,0" for "const b = blob1"
1179 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
1182 SYMBOL_CLASS (sym
) = LOC_CONST
;
1183 SYMBOL_TYPE (sym
) = error_type (&p
, objfile
);
1184 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1185 add_symbol_to_list (sym
, &file_symbols
);
1193 double d
= atof (p
);
1196 /* FIXME-if-picky-about-floating-accuracy: Should be using
1197 target arithmetic to get the value. real.c in GCC
1198 probably has the necessary code. */
1200 /* FIXME: lookup_fundamental_type is a hack. We should be
1201 creating a type especially for the type of float constants.
1202 Problem is, what type should it be?
1204 Also, what should the name of this type be? Should we
1205 be using 'S' constants (see stabs.texinfo) instead? */
1207 SYMBOL_TYPE (sym
) = lookup_fundamental_type (objfile
,
1210 obstack_alloc (&objfile
-> symbol_obstack
,
1211 TYPE_LENGTH (SYMBOL_TYPE (sym
)));
1212 store_floating (dbl_valu
, TYPE_LENGTH (SYMBOL_TYPE (sym
)), d
);
1213 SYMBOL_VALUE_BYTES (sym
) = dbl_valu
;
1214 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
1219 /* Defining integer constants this way is kind of silly,
1220 since 'e' constants allows the compiler to give not
1221 only the value, but the type as well. C has at least
1222 int, long, unsigned int, and long long as constant
1223 types; other languages probably should have at least
1224 unsigned as well as signed constants. */
1226 /* We just need one int constant type for all objfiles.
1227 It doesn't depend on languages or anything (arguably its
1228 name should be a language-specific name for a type of
1229 that size, but I'm inclined to say that if the compiler
1230 wants a nice name for the type, it can use 'e'). */
1231 static struct type
*int_const_type
;
1233 /* Yes, this is as long as a *host* int. That is because we
1235 if (int_const_type
== NULL
)
1237 init_type (TYPE_CODE_INT
,
1238 sizeof (int) * HOST_CHAR_BIT
/ TARGET_CHAR_BIT
, 0,
1240 (struct objfile
*)NULL
);
1241 SYMBOL_TYPE (sym
) = int_const_type
;
1242 SYMBOL_VALUE (sym
) = atoi (p
);
1243 SYMBOL_CLASS (sym
) = LOC_CONST
;
1247 /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value
1248 can be represented as integral.
1249 e.g. "b:c=e6,0" for "const b = blob1"
1250 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
1252 SYMBOL_CLASS (sym
) = LOC_CONST
;
1253 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1257 SYMBOL_TYPE (sym
) = error_type (&p
, objfile
);
1262 /* If the value is too big to fit in an int (perhaps because
1263 it is unsigned), or something like that, we silently get
1264 a bogus value. The type and everything else about it is
1265 correct. Ideally, we should be using whatever we have
1266 available for parsing unsigned and long long values,
1268 SYMBOL_VALUE (sym
) = atoi (p
);
1273 SYMBOL_CLASS (sym
) = LOC_CONST
;
1274 SYMBOL_TYPE (sym
) = error_type (&p
, objfile
);
1277 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1278 add_symbol_to_list (sym
, &file_symbols
);
1282 /* The name of a caught exception. */
1283 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1284 SYMBOL_CLASS (sym
) = LOC_LABEL
;
1285 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1286 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1287 add_symbol_to_list (sym
, &local_symbols
);
1291 /* A static function definition. */
1292 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1293 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1294 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1295 add_symbol_to_list (sym
, &file_symbols
);
1296 /* fall into process_function_types. */
1298 process_function_types
:
1299 /* Function result types are described as the result type in stabs.
1300 We need to convert this to the function-returning-type-X type
1301 in GDB. E.g. "int" is converted to "function returning int". */
1302 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_FUNC
)
1303 SYMBOL_TYPE (sym
) = lookup_function_type (SYMBOL_TYPE (sym
));
1304 /* fall into process_prototype_types */
1306 process_prototype_types
:
1307 /* Sun acc puts declared types of arguments here. We don't care
1308 about their actual types (FIXME -- we should remember the whole
1309 function prototype), but the list may define some new types
1310 that we have to remember, so we must scan it now. */
1313 read_type (&p
, objfile
);
1318 /* A global function definition. */
1319 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1320 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1321 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1322 add_symbol_to_list (sym
, &global_symbols
);
1323 goto process_function_types
;
1326 /* For a class G (global) symbol, it appears that the
1327 value is not correct. It is necessary to search for the
1328 corresponding linker definition to find the value.
1329 These definitions appear at the end of the namelist. */
1330 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1331 i
= hashname (SYMBOL_NAME (sym
));
1332 SYMBOL_VALUE_CHAIN (sym
) = global_sym_chain
[i
];
1333 global_sym_chain
[i
] = sym
;
1334 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1335 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1336 add_symbol_to_list (sym
, &global_symbols
);
1339 /* This case is faked by a conditional above,
1340 when there is no code letter in the dbx data.
1341 Dbx data never actually contains 'l'. */
1344 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1345 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1346 SYMBOL_VALUE (sym
) = valu
;
1347 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1348 add_symbol_to_list (sym
, &local_symbols
);
1353 /* pF is a two-letter code that means a function parameter in Fortran.
1354 The type-number specifies the type of the return value.
1355 Translate it into a pointer-to-function type. */
1359 = lookup_pointer_type
1360 (lookup_function_type (read_type (&p
, objfile
)));
1363 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1365 /* Normally this is a parameter, a LOC_ARG. On the i960, it
1366 can also be a LOC_LOCAL_ARG depending on symbol type. */
1367 #ifndef DBX_PARM_SYMBOL_CLASS
1368 #define DBX_PARM_SYMBOL_CLASS(type) LOC_ARG
1371 SYMBOL_CLASS (sym
) = DBX_PARM_SYMBOL_CLASS (type
);
1372 SYMBOL_VALUE (sym
) = valu
;
1373 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1374 add_symbol_to_list (sym
, &local_symbols
);
1376 if (TARGET_BYTE_ORDER
!= BIG_ENDIAN
)
1378 /* On little-endian machines, this crud is never necessary,
1379 and, if the extra bytes contain garbage, is harmful. */
1383 /* If it's gcc-compiled, if it says `short', believe it. */
1384 if (processing_gcc_compilation
|| BELIEVE_PCC_PROMOTION
)
1387 #if !BELIEVE_PCC_PROMOTION
1389 /* This is the signed type which arguments get promoted to. */
1390 static struct type
*pcc_promotion_type
;
1391 /* This is the unsigned type which arguments get promoted to. */
1392 static struct type
*pcc_unsigned_promotion_type
;
1394 /* Call it "int" because this is mainly C lossage. */
1395 if (pcc_promotion_type
== NULL
)
1396 pcc_promotion_type
=
1397 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
1400 if (pcc_unsigned_promotion_type
== NULL
)
1401 pcc_unsigned_promotion_type
=
1402 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
1403 TYPE_FLAG_UNSIGNED
, "unsigned int", NULL
);
1405 #if defined(BELIEVE_PCC_PROMOTION_TYPE)
1406 /* This macro is defined on machines (e.g. sparc) where
1407 we should believe the type of a PCC 'short' argument,
1408 but shouldn't believe the address (the address is
1409 the address of the corresponding int).
1411 My guess is that this correction, as opposed to changing
1412 the parameter to an 'int' (as done below, for PCC
1413 on most machines), is the right thing to do
1414 on all machines, but I don't want to risk breaking
1415 something that already works. On most PCC machines,
1416 the sparc problem doesn't come up because the calling
1417 function has to zero the top bytes (not knowing whether
1418 the called function wants an int or a short), so there
1419 is little practical difference between an int and a short
1420 (except perhaps what happens when the GDB user types
1421 "print short_arg = 0x10000;").
1423 Hacked for SunOS 4.1 by gnu@cygnus.com. In 4.1, the compiler
1424 actually produces the correct address (we don't need to fix it
1425 up). I made this code adapt so that it will offset the symbol
1426 if it was pointing at an int-aligned location and not
1427 otherwise. This way you can use the same gdb for 4.0.x and
1430 If the parameter is shorter than an int, and is integral
1431 (e.g. char, short, or unsigned equivalent), and is claimed to
1432 be passed on an integer boundary, don't believe it! Offset the
1433 parameter's address to the tail-end of that integer. */
1435 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (pcc_promotion_type
)
1436 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
1437 && 0 == SYMBOL_VALUE (sym
) % TYPE_LENGTH (pcc_promotion_type
))
1439 SYMBOL_VALUE (sym
) += TYPE_LENGTH (pcc_promotion_type
)
1440 - TYPE_LENGTH (SYMBOL_TYPE (sym
));
1444 #else /* no BELIEVE_PCC_PROMOTION_TYPE. */
1446 /* If PCC says a parameter is a short or a char,
1447 it is really an int. */
1448 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (pcc_promotion_type
)
1449 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
)
1452 TYPE_UNSIGNED (SYMBOL_TYPE (sym
))
1453 ? pcc_unsigned_promotion_type
1454 : pcc_promotion_type
;
1458 #endif /* no BELIEVE_PCC_PROMOTION_TYPE. */
1460 #endif /* !BELIEVE_PCC_PROMOTION. */
1463 /* acc seems to use P to declare the prototypes of functions that
1464 are referenced by this file. gdb is not prepared to deal
1465 with this extra information. FIXME, it ought to. */
1468 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1469 goto process_prototype_types
;
1474 /* Parameter which is in a register. */
1475 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1476 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
1477 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
1478 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
1480 complain (®_value_complaint
, SYMBOL_VALUE (sym
), NUM_REGS
,
1481 SYMBOL_SOURCE_NAME (sym
));
1482 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
1484 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1485 add_symbol_to_list (sym
, &local_symbols
);
1489 /* Register variable (either global or local). */
1490 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1491 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
1492 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
1493 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
1495 complain (®_value_complaint
, SYMBOL_VALUE (sym
), NUM_REGS
,
1496 SYMBOL_SOURCE_NAME (sym
));
1497 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
1499 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1500 if (within_function
)
1502 /* Sun cc uses a pair of symbols, one 'p' and one 'r' with the same
1503 name to represent an argument passed in a register.
1504 GCC uses 'P' for the same case. So if we find such a symbol pair
1505 we combine it into one 'P' symbol. For Sun cc we need to do this
1506 regardless of REG_STRUCT_HAS_ADDR, because the compiler puts out
1507 the 'p' symbol even if it never saves the argument onto the stack.
1509 On most machines, we want to preserve both symbols, so that
1510 we can still get information about what is going on with the
1511 stack (VAX for computing args_printed, using stack slots instead
1512 of saved registers in backtraces, etc.).
1514 Note that this code illegally combines
1515 main(argc) struct foo argc; { register struct foo argc; }
1516 but this case is considered pathological and causes a warning
1517 from a decent compiler. */
1520 && local_symbols
->nsyms
> 0
1521 #ifndef USE_REGISTER_NOT_ARG
1522 && REG_STRUCT_HAS_ADDR (processing_gcc_compilation
,
1524 && (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
1525 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
1526 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_SET
1527 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_BITSTRING
)
1531 struct symbol
*prev_sym
;
1532 prev_sym
= local_symbols
->symbol
[local_symbols
->nsyms
- 1];
1533 if ((SYMBOL_CLASS (prev_sym
) == LOC_REF_ARG
1534 || SYMBOL_CLASS (prev_sym
) == LOC_ARG
)
1535 && STREQ (SYMBOL_NAME (prev_sym
), SYMBOL_NAME(sym
)))
1537 SYMBOL_CLASS (prev_sym
) = LOC_REGPARM
;
1538 /* Use the type from the LOC_REGISTER; that is the type
1539 that is actually in that register. */
1540 SYMBOL_TYPE (prev_sym
) = SYMBOL_TYPE (sym
);
1541 SYMBOL_VALUE (prev_sym
) = SYMBOL_VALUE (sym
);
1546 add_symbol_to_list (sym
, &local_symbols
);
1549 add_symbol_to_list (sym
, &file_symbols
);
1553 /* Static symbol at top level of file */
1554 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1555 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1556 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1557 #ifdef STATIC_TRANSFORM_NAME
1558 if (SYMBOL_NAME (sym
)[0] == '$')
1560 struct minimal_symbol
*msym
;
1561 msym
= lookup_minimal_symbol (SYMBOL_NAME (sym
), NULL
, objfile
);
1564 SYMBOL_NAME (sym
) = STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym
));
1565 SYMBOL_VALUE_ADDRESS (sym
) = SYMBOL_VALUE_ADDRESS (msym
);
1569 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1570 add_symbol_to_list (sym
, &file_symbols
);
1574 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1576 /* For a nameless type, we don't want a create a symbol, thus we
1577 did not use `sym'. Return without further processing. */
1578 if (nameless
) return NULL
;
1580 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1581 SYMBOL_VALUE (sym
) = valu
;
1582 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1583 /* C++ vagaries: we may have a type which is derived from
1584 a base type which did not have its name defined when the
1585 derived class was output. We fill in the derived class's
1586 base part member's name here in that case. */
1587 if (TYPE_NAME (SYMBOL_TYPE (sym
)) != NULL
)
1588 if ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
1589 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
)
1590 && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)))
1593 for (j
= TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)) - 1; j
>= 0; j
--)
1594 if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) == 0)
1595 TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) =
1596 type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym
), j
));
1599 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == NULL
)
1601 /* gcc-2.6 or later (when using -fvtable-thunks)
1602 emits a unique named type for a vtable entry.
1603 Some gdb code depends on that specific name. */
1604 extern const char vtbl_ptr_name
[];
1606 if ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_PTR
1607 && strcmp (SYMBOL_NAME (sym
), vtbl_ptr_name
))
1608 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_FUNC
)
1610 /* If we are giving a name to a type such as "pointer to
1611 foo" or "function returning foo", we better not set
1612 the TYPE_NAME. If the program contains "typedef char
1613 *caddr_t;", we don't want all variables of type char
1614 * to print as caddr_t. This is not just a
1615 consequence of GDB's type management; PCC and GCC (at
1616 least through version 2.4) both output variables of
1617 either type char * or caddr_t with the type number
1618 defined in the 't' symbol for caddr_t. If a future
1619 compiler cleans this up it GDB is not ready for it
1620 yet, but if it becomes ready we somehow need to
1621 disable this check (without breaking the PCC/GCC2.4
1626 Fortunately, this check seems not to be necessary
1627 for anything except pointers or functions. */
1630 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_NAME (sym
);
1633 add_symbol_to_list (sym
, &file_symbols
);
1637 /* Struct, union, or enum tag. For GNU C++, this can be be followed
1638 by 't' which means we are typedef'ing it as well. */
1639 synonym
= *p
== 't';
1643 /* The semantics of C++ state that "struct foo { ... }" also defines
1644 a typedef for "foo". Unfortunately, cfront never makes the typedef
1645 when translating C++ into C. We make the typedef here so that
1646 "ptype foo" works as expected for cfront translated code. */
1647 else if (current_subfile
->language
== language_cplus
)
1650 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1652 /* For a nameless type, we don't want a create a symbol, thus we
1653 did not use `sym'. Return without further processing. */
1654 if (nameless
) return NULL
;
1656 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1657 SYMBOL_VALUE (sym
) = valu
;
1658 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
1659 if (TYPE_TAG_NAME (SYMBOL_TYPE (sym
)) == 0)
1660 TYPE_TAG_NAME (SYMBOL_TYPE (sym
))
1661 = obconcat (&objfile
-> type_obstack
, "", "", SYMBOL_NAME (sym
));
1662 add_symbol_to_list (sym
, &file_symbols
);
1666 /* Clone the sym and then modify it. */
1667 register struct symbol
*typedef_sym
= (struct symbol
*)
1668 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
1669 *typedef_sym
= *sym
;
1670 SYMBOL_CLASS (typedef_sym
) = LOC_TYPEDEF
;
1671 SYMBOL_VALUE (typedef_sym
) = valu
;
1672 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
1673 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
1674 TYPE_NAME (SYMBOL_TYPE (sym
))
1675 = obconcat (&objfile
-> type_obstack
, "", "", SYMBOL_NAME (sym
));
1676 add_symbol_to_list (typedef_sym
, &file_symbols
);
1681 /* Static symbol of local scope */
1682 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1683 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1684 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1685 #ifdef STATIC_TRANSFORM_NAME
1686 if (SYMBOL_NAME (sym
)[0] == '$')
1688 struct minimal_symbol
*msym
;
1689 msym
= lookup_minimal_symbol (SYMBOL_NAME (sym
), NULL
, objfile
);
1692 SYMBOL_NAME (sym
) = STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym
));
1693 SYMBOL_VALUE_ADDRESS (sym
) = SYMBOL_VALUE_ADDRESS (msym
);
1697 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1699 add_symbol_to_list (sym
, &global_symbols
);
1701 add_symbol_to_list (sym
, &local_symbols
);
1705 /* Reference parameter */
1706 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1707 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
1708 SYMBOL_VALUE (sym
) = valu
;
1709 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1710 add_symbol_to_list (sym
, &local_symbols
);
1714 /* Reference parameter which is in a register. */
1715 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1716 SYMBOL_CLASS (sym
) = LOC_REGPARM_ADDR
;
1717 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
1718 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
1720 complain (®_value_complaint
, SYMBOL_VALUE (sym
), NUM_REGS
,
1721 SYMBOL_SOURCE_NAME (sym
));
1722 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
1724 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1725 add_symbol_to_list (sym
, &local_symbols
);
1729 /* This is used by Sun FORTRAN for "function result value".
1730 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
1731 that Pascal uses it too, but when I tried it Pascal used
1732 "x:3" (local symbol) instead. */
1733 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1734 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1735 SYMBOL_VALUE (sym
) = valu
;
1736 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1737 add_symbol_to_list (sym
, &local_symbols
);
1740 /* New code added to support cfront stabs strings */
1741 /* Note: case 'P' already handled above */
1743 /* Cfront type continuation coming up!
1744 find the original definition and add to it.
1745 We'll have to do this for the typedef too,
1746 since we clloned the symbol to define a type in read_type.
1747 Stabs info examples:
1749 foo__1CFv :ZtF (first def foo__1CFv:F(0,3);(0,24))
1750 C:ZsC;;__ct__1CFv func1__1CFv func2__1CFv ... ;;;
1751 where C is the name of the class. */
1752 /* can't lookup symbol yet 'cuz symbols not read yet
1753 so we save it for processing later */
1754 process_later(sym
,p
);
1755 SYMBOL_TYPE (sym
) = error_type (&p
, objfile
); /* FIXME! change later */
1756 SYMBOL_CLASS (sym
) = LOC_CONST
;
1757 SYMBOL_VALUE (sym
) = 0;
1758 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1759 /* don't add to list - we'll delete it later when
1760 we add the continuation to the real sym */
1762 /* End of new code added to support cfront stabs strings */
1765 SYMBOL_TYPE (sym
) = error_type (&p
, objfile
);
1766 SYMBOL_CLASS (sym
) = LOC_CONST
;
1767 SYMBOL_VALUE (sym
) = 0;
1768 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1769 add_symbol_to_list (sym
, &file_symbols
);
1773 /* When passing structures to a function, some systems sometimes pass
1774 the address in a register, not the structure itself. */
1776 if (REG_STRUCT_HAS_ADDR (processing_gcc_compilation
,
1778 && ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
)
1779 || (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
)
1780 || (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_BITSTRING
)
1781 || (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_SET
)))
1783 /* If REG_STRUCT_HAS_ADDR yields non-zero we have to
1784 convert LOC_REGPARM to LOC_REGPARM_ADDR for structures and unions. */
1785 if (SYMBOL_CLASS (sym
) == LOC_REGPARM
)
1786 SYMBOL_CLASS (sym
) = LOC_REGPARM_ADDR
;
1787 /* Likewise for converting LOC_ARG to LOC_REF_ARG (for the 7th and
1788 subsequent arguments on the sparc, for example). */
1789 else if (SYMBOL_CLASS (sym
) == LOC_ARG
)
1790 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
1797 /* Skip rest of this symbol and return an error type.
1799 General notes on error recovery: error_type always skips to the
1800 end of the symbol (modulo cretinous dbx symbol name continuation).
1801 Thus code like this:
1803 if (*(*pp)++ != ';')
1804 return error_type (pp, objfile);
1806 is wrong because if *pp starts out pointing at '\0' (typically as the
1807 result of an earlier error), it will be incremented to point to the
1808 start of the next symbol, which might produce strange results, at least
1809 if you run off the end of the string table. Instead use
1812 return error_type (pp, objfile);
1818 foo = error_type (pp, objfile);
1822 And in case it isn't obvious, the point of all this hair is so the compiler
1823 can define new types and new syntaxes, and old versions of the
1824 debugger will be able to read the new symbol tables. */
1826 static struct type
*
1827 error_type (pp
, objfile
)
1829 struct objfile
*objfile
;
1831 complain (&error_type_complaint
);
1834 /* Skip to end of symbol. */
1835 while (**pp
!= '\0')
1840 /* Check for and handle cretinous dbx symbol name continuation! */
1841 if ((*pp
)[-1] == '\\' || (*pp
)[-1] == '?')
1843 *pp
= next_symbol_text (objfile
);
1850 return (builtin_type_error
);
1854 /* Read type information or a type definition; return the type. Even
1855 though this routine accepts either type information or a type
1856 definition, the distinction is relevant--some parts of stabsread.c
1857 assume that type information starts with a digit, '-', or '(' in
1858 deciding whether to call read_type. */
1861 read_type (pp
, objfile
)
1863 struct objfile
*objfile
;
1865 register struct type
*type
= 0;
1868 char type_descriptor
;
1870 /* Size in bits of type if specified by a type attribute, or -1 if
1871 there is no size attribute. */
1874 /* Used to distinguish string and bitstring from char-array and set. */
1877 /* Read type number if present. The type number may be omitted.
1878 for instance in a two-dimensional array declared with type
1879 "ar1;1;10;ar1;1;10;4". */
1880 if ((**pp
>= '0' && **pp
<= '9')
1884 if (read_type_number (pp
, typenums
) != 0)
1885 return error_type (pp
, objfile
);
1887 /* Type is not being defined here. Either it already exists,
1888 or this is a forward reference to it. dbx_alloc_type handles
1891 return dbx_alloc_type (typenums
, objfile
);
1893 /* Type is being defined here. */
1895 Also skip the type descriptor - we get it below with (*pp)[-1]. */
1900 /* 'typenums=' not present, type is anonymous. Read and return
1901 the definition, but don't put it in the type vector. */
1902 typenums
[0] = typenums
[1] = -1;
1907 type_descriptor
= (*pp
)[-1];
1908 switch (type_descriptor
)
1912 enum type_code code
;
1914 /* Used to index through file_symbols. */
1915 struct pending
*ppt
;
1918 /* Name including "struct", etc. */
1922 char *from
, *to
, *p
, *q1
, *q2
;
1924 /* Set the type code according to the following letter. */
1928 code
= TYPE_CODE_STRUCT
;
1931 code
= TYPE_CODE_UNION
;
1934 code
= TYPE_CODE_ENUM
;
1938 /* Complain and keep going, so compilers can invent new
1939 cross-reference types. */
1940 static struct complaint msg
=
1941 {"Unrecognized cross-reference type `%c'", 0, 0};
1942 complain (&msg
, (*pp
)[0]);
1943 code
= TYPE_CODE_STRUCT
;
1948 q1
= strchr(*pp
, '<');
1949 p
= strchr(*pp
, ':');
1951 return error_type (pp
, objfile
);
1952 while (q1
&& p
> q1
&& p
[1] == ':')
1954 q2
= strchr(q1
, '>');
1960 return error_type (pp
, objfile
);
1963 (char *)obstack_alloc (&objfile
->type_obstack
, p
- *pp
+ 1);
1965 /* Copy the name. */
1971 /* Set the pointer ahead of the name which we just read, and
1976 /* Now check to see whether the type has already been
1977 declared. This was written for arrays of cross-referenced
1978 types before we had TYPE_CODE_TARGET_STUBBED, so I'm pretty
1979 sure it is not necessary anymore. But it might be a good
1980 idea, to save a little memory. */
1982 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
1983 for (i
= 0; i
< ppt
->nsyms
; i
++)
1985 struct symbol
*sym
= ppt
->symbol
[i
];
1987 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
1988 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
1989 && (TYPE_CODE (SYMBOL_TYPE (sym
)) == code
)
1990 && STREQ (SYMBOL_NAME (sym
), type_name
))
1992 obstack_free (&objfile
-> type_obstack
, type_name
);
1993 type
= SYMBOL_TYPE (sym
);
1998 /* Didn't find the type to which this refers, so we must
1999 be dealing with a forward reference. Allocate a type
2000 structure for it, and keep track of it so we can
2001 fill in the rest of the fields when we get the full
2003 type
= dbx_alloc_type (typenums
, objfile
);
2004 TYPE_CODE (type
) = code
;
2005 TYPE_TAG_NAME (type
) = type_name
;
2006 INIT_CPLUS_SPECIFIC(type
);
2007 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
2009 add_undefined_type (type
);
2013 case '-': /* RS/6000 built-in type */
2027 /* We deal with something like t(1,2)=(3,4)=... which
2028 the Lucid compiler and recent gcc versions (post 2.7.3) use. */
2030 /* Allocate and enter the typedef type first.
2031 This handles recursive types. */
2032 type
= dbx_alloc_type (typenums
, objfile
);
2033 TYPE_CODE (type
) = TYPE_CODE_TYPEDEF
;
2034 { struct type
*xtype
= read_type (pp
, objfile
);
2037 /* It's being defined as itself. That means it is "void". */
2038 TYPE_CODE (type
) = TYPE_CODE_VOID
;
2039 TYPE_LENGTH (type
) = 1;
2041 else if (type_size
>= 0 || is_string
)
2044 TYPE_NAME (type
) = NULL
;
2045 TYPE_TAG_NAME (type
) = NULL
;
2049 TYPE_FLAGS (type
) |= TYPE_FLAG_TARGET_STUB
;
2050 TYPE_TARGET_TYPE (type
) = xtype
;
2055 /* In the following types, we must be sure to overwrite any existing
2056 type that the typenums refer to, rather than allocating a new one
2057 and making the typenums point to the new one. This is because there
2058 may already be pointers to the existing type (if it had been
2059 forward-referenced), and we must change it to a pointer, function,
2060 reference, or whatever, *in-place*. */
2063 type1
= read_type (pp
, objfile
);
2064 type
= make_pointer_type (type1
, dbx_lookup_type (typenums
));
2067 case '&': /* Reference to another type */
2068 type1
= read_type (pp
, objfile
);
2069 type
= make_reference_type (type1
, dbx_lookup_type (typenums
));
2072 case 'f': /* Function returning another type */
2073 if (os9k_stabs
&& **pp
== '(')
2075 /* Function prototype; parse it.
2076 We must conditionalize this on os9k_stabs because otherwise
2077 it could be confused with a Sun-style (1,3) typenumber
2083 t
= read_type(pp
, objfile
);
2084 if (**pp
== ',') ++*pp
;
2087 type1
= read_type (pp
, objfile
);
2088 type
= make_function_type (type1
, dbx_lookup_type (typenums
));
2091 case 'k': /* Const qualifier on some type (Sun) */
2092 case 'c': /* Const qualifier on some type (OS9000) */
2093 /* Because 'c' means other things to AIX and 'k' is perfectly good,
2094 only accept 'c' in the os9k_stabs case. */
2095 if (type_descriptor
== 'c' && !os9k_stabs
)
2096 return error_type (pp
, objfile
);
2097 type
= read_type (pp
, objfile
);
2098 /* FIXME! For now, we ignore const and volatile qualifiers. */
2101 case 'B': /* Volatile qual on some type (Sun) */
2102 case 'i': /* Volatile qual on some type (OS9000) */
2103 /* Because 'i' means other things to AIX and 'B' is perfectly good,
2104 only accept 'i' in the os9k_stabs case. */
2105 if (type_descriptor
== 'i' && !os9k_stabs
)
2106 return error_type (pp
, objfile
);
2107 type
= read_type (pp
, objfile
);
2108 /* FIXME! For now, we ignore const and volatile qualifiers. */
2112 if (isdigit (**pp
) || **pp
== '(' || **pp
== '-')
2113 { /* Member (class & variable) type */
2114 /* FIXME -- we should be doing smash_to_XXX types here. */
2116 struct type
*domain
= read_type (pp
, objfile
);
2117 struct type
*memtype
;
2120 /* Invalid member type data format. */
2121 return error_type (pp
, objfile
);
2124 memtype
= read_type (pp
, objfile
);
2125 type
= dbx_alloc_type (typenums
, objfile
);
2126 smash_to_member_type (type
, domain
, memtype
);
2128 else /* type attribute */
2131 /* Skip to the semicolon. */
2132 while (**pp
!= ';' && **pp
!= '\0')
2135 return error_type (pp
, objfile
);
2137 ++*pp
; /* Skip the semicolon. */
2142 type_size
= atoi (attr
+ 1);
2152 /* Ignore unrecognized type attributes, so future compilers
2153 can invent new ones. */
2161 case '#': /* Method (class & fn) type */
2162 if ((*pp
)[0] == '#')
2164 /* We'll get the parameter types from the name. */
2165 struct type
*return_type
;
2168 return_type
= read_type (pp
, objfile
);
2169 if (*(*pp
)++ != ';')
2170 complain (&invalid_member_complaint
, symnum
);
2171 type
= allocate_stub_method (return_type
);
2172 if (typenums
[0] != -1)
2173 *dbx_lookup_type (typenums
) = type
;
2177 struct type
*domain
= read_type (pp
, objfile
);
2178 struct type
*return_type
;
2182 /* Invalid member type data format. */
2183 return error_type (pp
, objfile
);
2187 return_type
= read_type (pp
, objfile
);
2188 args
= read_args (pp
, ';', objfile
);
2189 type
= dbx_alloc_type (typenums
, objfile
);
2190 smash_to_method_type (type
, domain
, return_type
, args
);
2194 case 'r': /* Range type */
2195 type
= read_range_type (pp
, typenums
, objfile
);
2196 if (typenums
[0] != -1)
2197 *dbx_lookup_type (typenums
) = type
;
2202 /* Const and volatile qualified type. */
2203 type
= read_type (pp
, objfile
);
2206 /* Sun ACC builtin int type */
2207 type
= read_sun_builtin_type (pp
, typenums
, objfile
);
2208 if (typenums
[0] != -1)
2209 *dbx_lookup_type (typenums
) = type
;
2213 case 'R': /* Sun ACC builtin float type */
2214 type
= read_sun_floating_type (pp
, typenums
, objfile
);
2215 if (typenums
[0] != -1)
2216 *dbx_lookup_type (typenums
) = type
;
2219 case 'e': /* Enumeration type */
2220 type
= dbx_alloc_type (typenums
, objfile
);
2221 type
= read_enum_type (pp
, type
, objfile
);
2222 if (typenums
[0] != -1)
2223 *dbx_lookup_type (typenums
) = type
;
2226 case 's': /* Struct type */
2227 case 'u': /* Union type */
2228 type
= dbx_alloc_type (typenums
, objfile
);
2229 switch (type_descriptor
)
2232 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
2235 TYPE_CODE (type
) = TYPE_CODE_UNION
;
2238 type
= read_struct_type (pp
, type
, objfile
);
2241 case 'a': /* Array type */
2243 return error_type (pp
, objfile
);
2246 type
= dbx_alloc_type (typenums
, objfile
);
2247 type
= read_array_type (pp
, type
, objfile
);
2249 TYPE_CODE (type
) = TYPE_CODE_STRING
;
2253 type1
= read_type (pp
, objfile
);
2254 type
= create_set_type ((struct type
*) NULL
, type1
);
2256 TYPE_CODE (type
) = TYPE_CODE_BITSTRING
;
2257 if (typenums
[0] != -1)
2258 *dbx_lookup_type (typenums
) = type
;
2262 --*pp
; /* Go back to the symbol in error */
2263 /* Particularly important if it was \0! */
2264 return error_type (pp
, objfile
);
2269 warning ("GDB internal error, type is NULL in stabsread.c\n");
2270 return error_type (pp
, objfile
);
2273 /* Size specified in a type attribute overrides any other size. */
2274 if (type_size
!= -1)
2275 TYPE_LENGTH (type
) = (type_size
+ TARGET_CHAR_BIT
- 1) / TARGET_CHAR_BIT
;
2280 /* RS/6000 xlc/dbx combination uses a set of builtin types, starting from -1.
2281 Return the proper type node for a given builtin type number. */
2283 static struct type
*
2284 rs6000_builtin_type (typenum
)
2287 /* We recognize types numbered from -NUMBER_RECOGNIZED to -1. */
2288 #define NUMBER_RECOGNIZED 34
2289 /* This includes an empty slot for type number -0. */
2290 static struct type
*negative_types
[NUMBER_RECOGNIZED
+ 1];
2291 struct type
*rettype
= NULL
;
2293 if (typenum
>= 0 || typenum
< -NUMBER_RECOGNIZED
)
2295 complain (&rs6000_builtin_complaint
, typenum
);
2296 return builtin_type_error
;
2298 if (negative_types
[-typenum
] != NULL
)
2299 return negative_types
[-typenum
];
2301 #if TARGET_CHAR_BIT != 8
2302 #error This code wrong for TARGET_CHAR_BIT not 8
2303 /* These definitions all assume that TARGET_CHAR_BIT is 8. I think
2304 that if that ever becomes not true, the correct fix will be to
2305 make the size in the struct type to be in bits, not in units of
2312 /* The size of this and all the other types are fixed, defined
2313 by the debugging format. If there is a type called "int" which
2314 is other than 32 bits, then it should use a new negative type
2315 number (or avoid negative type numbers for that case).
2316 See stabs.texinfo. */
2317 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "int", NULL
);
2320 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "char", NULL
);
2323 rettype
= init_type (TYPE_CODE_INT
, 2, 0, "short", NULL
);
2326 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "long", NULL
);
2329 rettype
= init_type (TYPE_CODE_INT
, 1, TYPE_FLAG_UNSIGNED
,
2330 "unsigned char", NULL
);
2333 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "signed char", NULL
);
2336 rettype
= init_type (TYPE_CODE_INT
, 2, TYPE_FLAG_UNSIGNED
,
2337 "unsigned short", NULL
);
2340 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
2341 "unsigned int", NULL
);
2344 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
2347 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
2348 "unsigned long", NULL
);
2351 rettype
= init_type (TYPE_CODE_VOID
, 1, 0, "void", NULL
);
2354 /* IEEE single precision (32 bit). */
2355 rettype
= init_type (TYPE_CODE_FLT
, 4, 0, "float", NULL
);
2358 /* IEEE double precision (64 bit). */
2359 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "double", NULL
);
2362 /* This is an IEEE double on the RS/6000, and different machines with
2363 different sizes for "long double" should use different negative
2364 type numbers. See stabs.texinfo. */
2365 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "long double", NULL
);
2368 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "integer", NULL
);
2371 rettype
= init_type (TYPE_CODE_BOOL
, 4, TYPE_FLAG_UNSIGNED
,
2375 rettype
= init_type (TYPE_CODE_FLT
, 4, 0, "short real", NULL
);
2378 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "real", NULL
);
2381 rettype
= init_type (TYPE_CODE_ERROR
, 0, 0, "stringptr", NULL
);
2384 rettype
= init_type (TYPE_CODE_CHAR
, 1, TYPE_FLAG_UNSIGNED
,
2388 rettype
= init_type (TYPE_CODE_BOOL
, 1, TYPE_FLAG_UNSIGNED
,
2392 rettype
= init_type (TYPE_CODE_BOOL
, 2, TYPE_FLAG_UNSIGNED
,
2396 rettype
= init_type (TYPE_CODE_BOOL
, 4, TYPE_FLAG_UNSIGNED
,
2400 rettype
= init_type (TYPE_CODE_BOOL
, 4, TYPE_FLAG_UNSIGNED
,
2404 /* Complex type consisting of two IEEE single precision values. */
2405 rettype
= init_type (TYPE_CODE_ERROR
, 8, 0, "complex", NULL
);
2408 /* Complex type consisting of two IEEE double precision values. */
2409 rettype
= init_type (TYPE_CODE_ERROR
, 16, 0, "double complex", NULL
);
2412 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "integer*1", NULL
);
2415 rettype
= init_type (TYPE_CODE_INT
, 2, 0, "integer*2", NULL
);
2418 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "integer*4", NULL
);
2421 rettype
= init_type (TYPE_CODE_CHAR
, 2, 0, "wchar", NULL
);
2424 rettype
= init_type (TYPE_CODE_INT
, 8, 0, "long long", NULL
);
2427 rettype
= init_type (TYPE_CODE_INT
, 8, TYPE_FLAG_UNSIGNED
,
2428 "unsigned long long", NULL
);
2431 rettype
= init_type (TYPE_CODE_INT
, 8, TYPE_FLAG_UNSIGNED
,
2435 rettype
= init_type (TYPE_CODE_INT
, 8, 0, "integer*8", NULL
);
2438 negative_types
[-typenum
] = rettype
;
2442 /* This page contains subroutines of read_type. */
2444 /* Read member function stabs info for C++ classes. The form of each member
2447 NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
2449 An example with two member functions is:
2451 afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
2453 For the case of overloaded operators, the format is op$::*.funcs, where
2454 $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
2455 name (such as `+=') and `.' marks the end of the operator name.
2457 Returns 1 for success, 0 for failure. */
2460 read_member_functions (fip
, pp
, type
, objfile
)
2461 struct field_info
*fip
;
2464 struct objfile
*objfile
;
2468 /* Total number of member functions defined in this class. If the class
2469 defines two `f' functions, and one `g' function, then this will have
2471 int total_length
= 0;
2475 struct next_fnfield
*next
;
2476 struct fn_field fn_field
;
2478 struct type
*look_ahead_type
;
2479 struct next_fnfieldlist
*new_fnlist
;
2480 struct next_fnfield
*new_sublist
;
2484 /* Process each list until we find something that is not a member function
2485 or find the end of the functions. */
2489 /* We should be positioned at the start of the function name.
2490 Scan forward to find the first ':' and if it is not the
2491 first of a "::" delimiter, then this is not a member function. */
2503 look_ahead_type
= NULL
;
2506 new_fnlist
= (struct next_fnfieldlist
*)
2507 xmalloc (sizeof (struct next_fnfieldlist
));
2508 make_cleanup (free
, new_fnlist
);
2509 memset (new_fnlist
, 0, sizeof (struct next_fnfieldlist
));
2511 if ((*pp
)[0] == 'o' && (*pp
)[1] == 'p' && is_cplus_marker ((*pp
)[2]))
2513 /* This is a completely wierd case. In order to stuff in the
2514 names that might contain colons (the usual name delimiter),
2515 Mike Tiemann defined a different name format which is
2516 signalled if the identifier is "op$". In that case, the
2517 format is "op$::XXXX." where XXXX is the name. This is
2518 used for names like "+" or "=". YUUUUUUUK! FIXME! */
2519 /* This lets the user type "break operator+".
2520 We could just put in "+" as the name, but that wouldn't
2522 static char opname
[32] = {'o', 'p', CPLUS_MARKER
};
2523 char *o
= opname
+ 3;
2525 /* Skip past '::'. */
2528 STABS_CONTINUE (pp
, objfile
);
2534 main_fn_name
= savestring (opname
, o
- opname
);
2540 main_fn_name
= savestring (*pp
, p
- *pp
);
2541 /* Skip past '::'. */
2544 new_fnlist
-> fn_fieldlist
.name
= main_fn_name
;
2549 (struct next_fnfield
*) xmalloc (sizeof (struct next_fnfield
));
2550 make_cleanup (free
, new_sublist
);
2551 memset (new_sublist
, 0, sizeof (struct next_fnfield
));
2553 /* Check for and handle cretinous dbx symbol name continuation! */
2554 if (look_ahead_type
== NULL
)
2557 STABS_CONTINUE (pp
, objfile
);
2559 new_sublist
-> fn_field
.type
= read_type (pp
, objfile
);
2562 /* Invalid symtab info for member function. */
2568 /* g++ version 1 kludge */
2569 new_sublist
-> fn_field
.type
= look_ahead_type
;
2570 look_ahead_type
= NULL
;
2580 /* If this is just a stub, then we don't have the real name here. */
2582 if (TYPE_FLAGS (new_sublist
-> fn_field
.type
) & TYPE_FLAG_STUB
)
2584 if (!TYPE_DOMAIN_TYPE (new_sublist
-> fn_field
.type
))
2585 TYPE_DOMAIN_TYPE (new_sublist
-> fn_field
.type
) = type
;
2586 new_sublist
-> fn_field
.is_stub
= 1;
2588 new_sublist
-> fn_field
.physname
= savestring (*pp
, p
- *pp
);
2591 /* Set this member function's visibility fields. */
2594 case VISIBILITY_PRIVATE
:
2595 new_sublist
-> fn_field
.is_private
= 1;
2597 case VISIBILITY_PROTECTED
:
2598 new_sublist
-> fn_field
.is_protected
= 1;
2602 STABS_CONTINUE (pp
, objfile
);
2605 case 'A': /* Normal functions. */
2606 new_sublist
-> fn_field
.is_const
= 0;
2607 new_sublist
-> fn_field
.is_volatile
= 0;
2610 case 'B': /* `const' member functions. */
2611 new_sublist
-> fn_field
.is_const
= 1;
2612 new_sublist
-> fn_field
.is_volatile
= 0;
2615 case 'C': /* `volatile' member function. */
2616 new_sublist
-> fn_field
.is_const
= 0;
2617 new_sublist
-> fn_field
.is_volatile
= 1;
2620 case 'D': /* `const volatile' member function. */
2621 new_sublist
-> fn_field
.is_const
= 1;
2622 new_sublist
-> fn_field
.is_volatile
= 1;
2625 case '*': /* File compiled with g++ version 1 -- no info */
2630 complain (&const_vol_complaint
, **pp
);
2639 /* virtual member function, followed by index.
2640 The sign bit is set to distinguish pointers-to-methods
2641 from virtual function indicies. Since the array is
2642 in words, the quantity must be shifted left by 1
2643 on 16 bit machine, and by 2 on 32 bit machine, forcing
2644 the sign bit out, and usable as a valid index into
2645 the array. Remove the sign bit here. */
2646 new_sublist
-> fn_field
.voffset
=
2647 (0x7fffffff & read_huge_number (pp
, ';', &nbits
)) + 2;
2651 STABS_CONTINUE (pp
, objfile
);
2652 if (**pp
== ';' || **pp
== '\0')
2654 /* Must be g++ version 1. */
2655 new_sublist
-> fn_field
.fcontext
= 0;
2659 /* Figure out from whence this virtual function came.
2660 It may belong to virtual function table of
2661 one of its baseclasses. */
2662 look_ahead_type
= read_type (pp
, objfile
);
2665 /* g++ version 1 overloaded methods. */
2669 new_sublist
-> fn_field
.fcontext
= look_ahead_type
;
2678 look_ahead_type
= NULL
;
2684 /* static member function. */
2685 new_sublist
-> fn_field
.voffset
= VOFFSET_STATIC
;
2686 if (strncmp (new_sublist
-> fn_field
.physname
,
2687 main_fn_name
, strlen (main_fn_name
)))
2689 new_sublist
-> fn_field
.is_stub
= 1;
2695 complain (&member_fn_complaint
, (*pp
)[-1]);
2696 /* Fall through into normal member function. */
2699 /* normal member function. */
2700 new_sublist
-> fn_field
.voffset
= 0;
2701 new_sublist
-> fn_field
.fcontext
= 0;
2705 new_sublist
-> next
= sublist
;
2706 sublist
= new_sublist
;
2708 STABS_CONTINUE (pp
, objfile
);
2710 while (**pp
!= ';' && **pp
!= '\0');
2714 new_fnlist
-> fn_fieldlist
.fn_fields
= (struct fn_field
*)
2715 obstack_alloc (&objfile
-> type_obstack
,
2716 sizeof (struct fn_field
) * length
);
2717 memset (new_fnlist
-> fn_fieldlist
.fn_fields
, 0,
2718 sizeof (struct fn_field
) * length
);
2719 for (i
= length
; (i
--, sublist
); sublist
= sublist
-> next
)
2721 new_fnlist
-> fn_fieldlist
.fn_fields
[i
] = sublist
-> fn_field
;
2724 new_fnlist
-> fn_fieldlist
.length
= length
;
2725 new_fnlist
-> next
= fip
-> fnlist
;
2726 fip
-> fnlist
= new_fnlist
;
2728 total_length
+= length
;
2729 STABS_CONTINUE (pp
, objfile
);
2734 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2735 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2736 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * nfn_fields
);
2737 memset (TYPE_FN_FIELDLISTS (type
), 0,
2738 sizeof (struct fn_fieldlist
) * nfn_fields
);
2739 TYPE_NFN_FIELDS (type
) = nfn_fields
;
2740 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2746 /* Special GNU C++ name.
2748 Returns 1 for success, 0 for failure. "failure" means that we can't
2749 keep parsing and it's time for error_type(). */
2752 read_cpp_abbrev (fip
, pp
, type
, objfile
)
2753 struct field_info
*fip
;
2756 struct objfile
*objfile
;
2761 struct type
*context
;
2771 /* At this point, *pp points to something like "22:23=*22...",
2772 where the type number before the ':' is the "context" and
2773 everything after is a regular type definition. Lookup the
2774 type, find it's name, and construct the field name. */
2776 context
= read_type (pp
, objfile
);
2780 case 'f': /* $vf -- a virtual function table pointer */
2781 fip
->list
->field
.name
=
2782 obconcat (&objfile
->type_obstack
, vptr_name
, "", "");
2785 case 'b': /* $vb -- a virtual bsomethingorother */
2786 name
= type_name_no_tag (context
);
2789 complain (&invalid_cpp_type_complaint
, symnum
);
2792 fip
->list
->field
.name
=
2793 obconcat (&objfile
->type_obstack
, vb_name
, name
, "");
2797 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2798 fip
->list
->field
.name
=
2799 obconcat (&objfile
->type_obstack
,
2800 "INVALID_CPLUSPLUS_ABBREV", "", "");
2804 /* At this point, *pp points to the ':'. Skip it and read the
2810 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2813 fip
->list
->field
.type
= read_type (pp
, objfile
);
2815 (*pp
)++; /* Skip the comma. */
2821 fip
->list
->field
.bitpos
= read_huge_number (pp
, ';', &nbits
);
2825 /* This field is unpacked. */
2826 fip
->list
->field
.bitsize
= 0;
2827 fip
->list
->visibility
= VISIBILITY_PRIVATE
;
2831 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2832 /* We have no idea what syntax an unrecognized abbrev would have, so
2833 better return 0. If we returned 1, we would need to at least advance
2834 *pp to avoid an infinite loop. */
2841 read_one_struct_field (fip
, pp
, p
, type
, objfile
)
2842 struct field_info
*fip
;
2846 struct objfile
*objfile
;
2848 /* The following is code to work around cfront generated stabs.
2849 The stabs contains full mangled name for each field.
2850 We try to demangle the name and extract the field name out of it.
2852 if (ARM_DEMANGLING
&& current_subfile
->language
== language_cplus
)
2858 dem
= cplus_demangle (*pp
, DMGL_ANSI
| DMGL_PARAMS
);
2861 dem_p
= strrchr (dem
, ':');
2862 if (dem_p
!= 0 && *(dem_p
-1)==':')
2864 fip
->list
->field
.name
=
2865 obsavestring (dem_p
, strlen(dem_p
), &objfile
-> type_obstack
);
2869 fip
->list
->field
.name
=
2870 obsavestring (*pp
, p
- *pp
, &objfile
-> type_obstack
);
2874 /* end of code for cfront work around */
2877 fip
-> list
-> field
.name
=
2878 obsavestring (*pp
, p
- *pp
, &objfile
-> type_obstack
);
2881 /* This means we have a visibility for a field coming. */
2885 fip
-> list
-> visibility
= *(*pp
)++;
2889 /* normal dbx-style format, no explicit visibility */
2890 fip
-> list
-> visibility
= VISIBILITY_PUBLIC
;
2893 fip
-> list
-> field
.type
= read_type (pp
, objfile
);
2898 /* Possible future hook for nested types. */
2901 fip
-> list
-> field
.bitpos
= (long)-2; /* nested type */
2907 /* Static class member. */
2908 fip
-> list
-> field
.bitpos
= (long) -1;
2914 fip
-> list
-> field
.bitsize
= (long) savestring (*pp
, p
- *pp
);
2918 else if (**pp
!= ',')
2920 /* Bad structure-type format. */
2921 complain (&stabs_general_complaint
, "bad structure-type format");
2925 (*pp
)++; /* Skip the comma. */
2929 fip
-> list
-> field
.bitpos
= read_huge_number (pp
, ',', &nbits
);
2932 complain (&stabs_general_complaint
, "bad structure-type format");
2935 fip
-> list
-> field
.bitsize
= read_huge_number (pp
, ';', &nbits
);
2938 complain (&stabs_general_complaint
, "bad structure-type format");
2943 if (fip
-> list
-> field
.bitpos
== 0 && fip
-> list
-> field
.bitsize
== 0)
2945 /* This can happen in two cases: (1) at least for gcc 2.4.5 or so,
2946 it is a field which has been optimized out. The correct stab for
2947 this case is to use VISIBILITY_IGNORE, but that is a recent
2948 invention. (2) It is a 0-size array. For example
2949 union { int num; char str[0]; } foo. Printing "<no value>" for
2950 str in "p foo" is OK, since foo.str (and thus foo.str[3])
2951 will continue to work, and a 0-size array as a whole doesn't
2952 have any contents to print.
2954 I suspect this probably could also happen with gcc -gstabs (not
2955 -gstabs+) for static fields, and perhaps other C++ extensions.
2956 Hopefully few people use -gstabs with gdb, since it is intended
2957 for dbx compatibility. */
2959 /* Ignore this field. */
2960 fip
-> list
-> visibility
= VISIBILITY_IGNORE
;
2964 /* Detect an unpacked field and mark it as such.
2965 dbx gives a bit size for all fields.
2966 Note that forward refs cannot be packed,
2967 and treat enums as if they had the width of ints. */
2969 if (TYPE_CODE (fip
-> list
-> field
.type
) != TYPE_CODE_INT
2970 && TYPE_CODE (fip
-> list
-> field
.type
) != TYPE_CODE_BOOL
2971 && TYPE_CODE (fip
-> list
-> field
.type
) != TYPE_CODE_ENUM
)
2973 fip
-> list
-> field
.bitsize
= 0;
2975 if ((fip
-> list
-> field
.bitsize
2976 == TARGET_CHAR_BIT
* TYPE_LENGTH (fip
-> list
-> field
.type
)
2977 || (TYPE_CODE (fip
-> list
-> field
.type
) == TYPE_CODE_ENUM
2978 && (fip
-> list
-> field
.bitsize
2983 fip
-> list
-> field
.bitpos
% 8 == 0)
2985 fip
-> list
-> field
.bitsize
= 0;
2991 /* Read struct or class data fields. They have the form:
2993 NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
2995 At the end, we see a semicolon instead of a field.
2997 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
3000 The optional VISIBILITY is one of:
3002 '/0' (VISIBILITY_PRIVATE)
3003 '/1' (VISIBILITY_PROTECTED)
3004 '/2' (VISIBILITY_PUBLIC)
3005 '/9' (VISIBILITY_IGNORE)
3007 or nothing, for C style fields with public visibility.
3009 Returns 1 for success, 0 for failure. */
3012 read_struct_fields (fip
, pp
, type
, objfile
)
3013 struct field_info
*fip
;
3016 struct objfile
*objfile
;
3019 struct nextfield
*new;
3021 /* We better set p right now, in case there are no fields at all... */
3025 /* Read each data member type until we find the terminating ';' at the end of
3026 the data member list, or break for some other reason such as finding the
3027 start of the member function list. */
3031 if (os9k_stabs
&& **pp
== ',') break;
3032 STABS_CONTINUE (pp
, objfile
);
3033 /* Get space to record the next field's data. */
3034 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3035 make_cleanup (free
, new);
3036 memset (new, 0, sizeof (struct nextfield
));
3037 new -> next
= fip
-> list
;
3040 /* Get the field name. */
3043 /* If is starts with CPLUS_MARKER it is a special abbreviation,
3044 unless the CPLUS_MARKER is followed by an underscore, in
3045 which case it is just the name of an anonymous type, which we
3046 should handle like any other type name. */
3048 if (is_cplus_marker (p
[0]) && p
[1] != '_')
3050 if (!read_cpp_abbrev (fip
, pp
, type
, objfile
))
3055 /* Look for the ':' that separates the field name from the field
3056 values. Data members are delimited by a single ':', while member
3057 functions are delimited by a pair of ':'s. When we hit the member
3058 functions (if any), terminate scan loop and return. */
3060 while (*p
!= ':' && *p
!= '\0')
3067 /* Check to see if we have hit the member functions yet. */
3072 read_one_struct_field (fip
, pp
, p
, type
, objfile
);
3074 if (p
[0] == ':' && p
[1] == ':')
3076 /* chill the list of fields: the last entry (at the head) is a
3077 partially constructed entry which we now scrub. */
3078 fip
-> list
= fip
-> list
-> next
;
3083 /* The stabs for C++ derived classes contain baseclass information which
3084 is marked by a '!' character after the total size. This function is
3085 called when we encounter the baseclass marker, and slurps up all the
3086 baseclass information.
3088 Immediately following the '!' marker is the number of base classes that
3089 the class is derived from, followed by information for each base class.
3090 For each base class, there are two visibility specifiers, a bit offset
3091 to the base class information within the derived class, a reference to
3092 the type for the base class, and a terminating semicolon.
3094 A typical example, with two base classes, would be "!2,020,19;0264,21;".
3096 Baseclass information marker __________________|| | | | | | |
3097 Number of baseclasses __________________________| | | | | | |
3098 Visibility specifiers (2) ________________________| | | | | |
3099 Offset in bits from start of class _________________| | | | |
3100 Type number for base class ___________________________| | | |
3101 Visibility specifiers (2) _______________________________| | |
3102 Offset in bits from start of class ________________________| |
3103 Type number of base class ____________________________________|
3105 Return 1 for success, 0 for (error-type-inducing) failure. */
3108 read_baseclasses (fip
, pp
, type
, objfile
)
3109 struct field_info
*fip
;
3112 struct objfile
*objfile
;
3115 struct nextfield
*new;
3123 /* Skip the '!' baseclass information marker. */
3127 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3130 TYPE_N_BASECLASSES (type
) = read_huge_number (pp
, ',', &nbits
);
3136 /* Some stupid compilers have trouble with the following, so break
3137 it up into simpler expressions. */
3138 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*)
3139 TYPE_ALLOC (type
, B_BYTES (TYPE_N_BASECLASSES (type
)));
3142 int num_bytes
= B_BYTES (TYPE_N_BASECLASSES (type
));
3145 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
3146 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
3150 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), TYPE_N_BASECLASSES (type
));
3152 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
3154 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3155 make_cleanup (free
, new);
3156 memset (new, 0, sizeof (struct nextfield
));
3157 new -> next
= fip
-> list
;
3159 new -> field
.bitsize
= 0; /* this should be an unpacked field! */
3161 STABS_CONTINUE (pp
, objfile
);
3165 /* Nothing to do. */
3168 SET_TYPE_FIELD_VIRTUAL (type
, i
);
3171 /* Unknown character. Complain and treat it as non-virtual. */
3173 static struct complaint msg
= {
3174 "Unknown virtual character `%c' for baseclass", 0, 0};
3175 complain (&msg
, **pp
);
3180 new -> visibility
= *(*pp
)++;
3181 switch (new -> visibility
)
3183 case VISIBILITY_PRIVATE
:
3184 case VISIBILITY_PROTECTED
:
3185 case VISIBILITY_PUBLIC
:
3188 /* Bad visibility format. Complain and treat it as
3191 static struct complaint msg
= {
3192 "Unknown visibility `%c' for baseclass", 0, 0};
3193 complain (&msg
, new -> visibility
);
3194 new -> visibility
= VISIBILITY_PUBLIC
;
3201 /* The remaining value is the bit offset of the portion of the object
3202 corresponding to this baseclass. Always zero in the absence of
3203 multiple inheritance. */
3205 new -> field
.bitpos
= read_huge_number (pp
, ',', &nbits
);
3210 /* The last piece of baseclass information is the type of the
3211 base class. Read it, and remember it's type name as this
3214 new -> field
.type
= read_type (pp
, objfile
);
3215 new -> field
.name
= type_name_no_tag (new -> field
.type
);
3217 /* skip trailing ';' and bump count of number of fields seen */
3226 /* The tail end of stabs for C++ classes that contain a virtual function
3227 pointer contains a tilde, a %, and a type number.
3228 The type number refers to the base class (possibly this class itself) which
3229 contains the vtable pointer for the current class.
3231 This function is called when we have parsed all the method declarations,
3232 so we can look for the vptr base class info. */
3235 read_tilde_fields (fip
, pp
, type
, objfile
)
3236 struct field_info
*fip
;
3239 struct objfile
*objfile
;
3243 STABS_CONTINUE (pp
, objfile
);
3245 /* If we are positioned at a ';', then skip it. */
3255 if (**pp
== '=' || **pp
== '+' || **pp
== '-')
3257 /* Obsolete flags that used to indicate the presence
3258 of constructors and/or destructors. */
3262 /* Read either a '%' or the final ';'. */
3263 if (*(*pp
)++ == '%')
3265 /* The next number is the type number of the base class
3266 (possibly our own class) which supplies the vtable for
3267 this class. Parse it out, and search that class to find
3268 its vtable pointer, and install those into TYPE_VPTR_BASETYPE
3269 and TYPE_VPTR_FIELDNO. */
3274 t
= read_type (pp
, objfile
);
3276 while (*p
!= '\0' && *p
!= ';')
3282 /* Premature end of symbol. */
3286 TYPE_VPTR_BASETYPE (type
) = t
;
3287 if (type
== t
) /* Our own class provides vtbl ptr */
3289 for (i
= TYPE_NFIELDS (t
) - 1;
3290 i
>= TYPE_N_BASECLASSES (t
);
3293 if (! strncmp (TYPE_FIELD_NAME (t
, i
), vptr_name
,
3294 sizeof (vptr_name
) - 1))
3296 TYPE_VPTR_FIELDNO (type
) = i
;
3300 /* Virtual function table field not found. */
3301 complain (&vtbl_notfound_complaint
, TYPE_NAME (type
));
3306 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
3317 attach_fn_fields_to_type (fip
, type
)
3318 struct field_info
*fip
;
3319 register struct type
*type
;
3323 for (n
= TYPE_NFN_FIELDS (type
);
3324 fip
-> fnlist
!= NULL
;
3325 fip
-> fnlist
= fip
-> fnlist
-> next
)
3327 --n
; /* Circumvent Sun3 compiler bug */
3328 TYPE_FN_FIELDLISTS (type
)[n
] = fip
-> fnlist
-> fn_fieldlist
;
3333 /* read cfront class static data.
3334 pp points to string starting with the list of static data
3335 eg: A:ZcA;1@Bpub v2@Bvirpri;__ct__1AFv func__1AFv *sfunc__1AFv ;as__1A ;;
3338 A:ZcA;;foopri__1AFv foopro__1AFv __ct__1AFv __ct__1AFRC1A foopub__1AFv ;;;
3343 read_cfront_static_fields(fip
, pp
, type
, objfile
)
3344 struct field_info
*fip
;
3347 struct objfile
*objfile
;
3349 struct nextfield
* new;
3352 struct symbol
* ref_static
=0;
3354 if (**pp
==';') /* no static data; return */
3360 /* Process each field in the list until we find the terminating ";" */
3362 /* eg: p = "as__1A ;;;" */
3363 STABS_CONTINUE (pp
, objfile
); /* handle \\ */
3364 while (**pp
!=';' && (sname
= get_substring(pp
,' '),sname
))
3366 ref_static
= lookup_symbol (sname
, 0, VAR_NAMESPACE
, 0, 0); /*demangled_name*/
3369 static struct complaint msg
= {"\
3370 Unable to find symbol for static data field %s\n",
3372 complain (&msg
, sname
);
3375 stype
= SYMBOL_TYPE(ref_static
);
3377 /* allocate a new fip */
3378 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3379 make_cleanup (free
, new);
3380 memset (new, 0, sizeof (struct nextfield
));
3381 new -> next
= fip
-> list
;
3384 /* set visibility */
3385 /* FIXME! no way to tell visibility from stabs??? */
3386 new -> visibility
= VISIBILITY_PUBLIC
;
3388 /* set field info into fip */
3389 fip
-> list
-> field
.type
= stype
;
3391 /* set bitpos & bitsize */
3392 fip
-> list
-> field
.bitpos
= (long) -1; /* -1 signifies a static member */
3393 /* YUK! what a hack! bitsize used for physname when field is static */
3394 fip
-> list
-> field
.bitsize
= (long) savestring (sname
, strlen(sname
));
3396 /* set name field */
3397 /* The following is code to work around cfront generated stabs.
3398 The stabs contains full mangled name for each field.
3399 We try to demangle the name and extract the field name out of it.
3404 dem
= cplus_demangle (sname
, DMGL_ANSI
| DMGL_PARAMS
);
3407 dem_p
= strrchr (dem
, ':');
3408 if (dem_p
!= 0 && *(dem_p
-1)==':')
3410 fip
->list
->field
.name
=
3411 obsavestring (dem_p
, strlen(dem_p
), &objfile
-> type_obstack
);
3415 fip
->list
->field
.name
=
3416 obsavestring (sname
, strlen(sname
), &objfile
-> type_obstack
);
3418 } /* end of code for cfront work around */
3419 } /* loop again for next static field */
3423 /* Copy structure fields to fip so attach_fields_to_type will work.
3424 type has already been created with the initial instance data fields.
3425 Now we want to be able to add the other members to the class,
3426 so we want to add them back to the fip and reattach them again
3427 once we have collected all the class members. */
3430 copy_cfront_struct_fields(fip
, type
, objfile
)
3431 struct field_info
*fip
;
3433 struct objfile
*objfile
;
3435 int nfields
= TYPE_NFIELDS(type
);
3437 struct nextfield
* new;
3439 /* Copy the fields into the list of fips and reset the types
3440 to remove the old fields */
3442 for (i
=0; i
<nfields
; i
++)
3444 /* allocate a new fip */
3445 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3446 make_cleanup (free
, new);
3447 memset (new, 0, sizeof (struct nextfield
));
3448 new -> next
= fip
-> list
;
3451 /* copy field info into fip */
3452 new -> field
= TYPE_FIELD (type
, i
);
3453 /* set visibility */
3454 if (TYPE_FIELD_PROTECTED (type
, i
))
3455 new -> visibility
= VISIBILITY_PROTECTED
;
3456 else if (TYPE_FIELD_PRIVATE (type
, i
))
3457 new -> visibility
= VISIBILITY_PRIVATE
;
3459 new -> visibility
= VISIBILITY_PUBLIC
;
3461 /* Now delete the fields from the type since we will be
3462 allocing new space once we get the rest of the fields
3463 in attach_fields_to_type.
3464 The pointer TYPE_FIELDS(type) is left dangling but should
3465 be freed later by objstack_free */
3466 TYPE_FIELDS (type
)=0;
3467 TYPE_NFIELDS (type
) = 0;
3472 /* Create the vector of fields, and record how big it is.
3473 We need this info to record proper virtual function table information
3474 for this class's virtual functions. */
3477 attach_fields_to_type (fip
, type
, objfile
)
3478 struct field_info
*fip
;
3479 register struct type
*type
;
3480 struct objfile
*objfile
;
3482 register int nfields
= 0;
3483 register int non_public_fields
= 0;
3484 register struct nextfield
*scan
;
3486 /* Count up the number of fields that we have, as well as taking note of
3487 whether or not there are any non-public fields, which requires us to
3488 allocate and build the private_field_bits and protected_field_bits
3491 for (scan
= fip
-> list
; scan
!= NULL
; scan
= scan
-> next
)
3494 if (scan
-> visibility
!= VISIBILITY_PUBLIC
)
3496 non_public_fields
++;
3500 /* Now we know how many fields there are, and whether or not there are any
3501 non-public fields. Record the field count, allocate space for the
3502 array of fields, and create blank visibility bitfields if necessary. */
3504 TYPE_NFIELDS (type
) = nfields
;
3505 TYPE_FIELDS (type
) = (struct field
*)
3506 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
3507 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
3509 if (non_public_fields
)
3511 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3513 TYPE_FIELD_PRIVATE_BITS (type
) =
3514 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3515 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
3517 TYPE_FIELD_PROTECTED_BITS (type
) =
3518 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3519 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
3521 TYPE_FIELD_IGNORE_BITS (type
) =
3522 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3523 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
3526 /* Copy the saved-up fields into the field vector. Start from the head
3527 of the list, adding to the tail of the field array, so that they end
3528 up in the same order in the array in which they were added to the list. */
3530 while (nfields
-- > 0)
3532 TYPE_FIELD (type
, nfields
) = fip
-> list
-> field
;
3533 switch (fip
-> list
-> visibility
)
3535 case VISIBILITY_PRIVATE
:
3536 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
3539 case VISIBILITY_PROTECTED
:
3540 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
3543 case VISIBILITY_IGNORE
:
3544 SET_TYPE_FIELD_IGNORE (type
, nfields
);
3547 case VISIBILITY_PUBLIC
:
3551 /* Unknown visibility. Complain and treat it as public. */
3553 static struct complaint msg
= {
3554 "Unknown visibility `%c' for field", 0, 0};
3555 complain (&msg
, fip
-> list
-> visibility
);
3559 fip
-> list
= fip
-> list
-> next
;
3564 /* Read the description of a structure (or union type) and return an object
3565 describing the type.
3567 PP points to a character pointer that points to the next unconsumed token
3568 in the the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
3569 *PP will point to "4a:1,0,32;;".
3571 TYPE points to an incomplete type that needs to be filled in.
3573 OBJFILE points to the current objfile from which the stabs information is
3574 being read. (Note that it is redundant in that TYPE also contains a pointer
3575 to this same objfile, so it might be a good idea to eliminate it. FIXME).
3578 static struct type
*
3579 read_struct_type (pp
, type
, objfile
)
3582 struct objfile
*objfile
;
3584 struct cleanup
*back_to
;
3585 struct field_info fi
;
3590 back_to
= make_cleanup (null_cleanup
, 0);
3592 INIT_CPLUS_SPECIFIC (type
);
3593 TYPE_FLAGS (type
) &= ~TYPE_FLAG_STUB
;
3595 /* First comes the total size in bytes. */
3599 TYPE_LENGTH (type
) = read_huge_number (pp
, 0, &nbits
);
3601 return error_type (pp
, objfile
);
3604 /* Now read the baseclasses, if any, read the regular C struct or C++
3605 class member fields, attach the fields to the type, read the C++
3606 member functions, attach them to the type, and then read any tilde
3607 field (baseclass specifier for the class holding the main vtable). */
3609 if (!read_baseclasses (&fi
, pp
, type
, objfile
)
3610 || !read_struct_fields (&fi
, pp
, type
, objfile
)
3611 || !attach_fields_to_type (&fi
, type
, objfile
)
3612 || !read_member_functions (&fi
, pp
, type
, objfile
)
3613 || !attach_fn_fields_to_type (&fi
, type
)
3614 || !read_tilde_fields (&fi
, pp
, type
, objfile
))
3616 type
= error_type (pp
, objfile
);
3619 do_cleanups (back_to
);
3623 /* Read a definition of an array type,
3624 and create and return a suitable type object.
3625 Also creates a range type which represents the bounds of that
3628 static struct type
*
3629 read_array_type (pp
, type
, objfile
)
3631 register struct type
*type
;
3632 struct objfile
*objfile
;
3634 struct type
*index_type
, *element_type
, *range_type
;
3639 /* Format of an array type:
3640 "ar<index type>;lower;upper;<array_contents_type>".
3641 OS9000: "arlower,upper;<array_contents_type>".
3643 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
3644 for these, produce a type like float[][]. */
3647 index_type
= builtin_type_int
;
3650 index_type
= read_type (pp
, objfile
);
3652 /* Improper format of array type decl. */
3653 return error_type (pp
, objfile
);
3657 if (!(**pp
>= '0' && **pp
<= '9') && **pp
!= '-')
3662 lower
= read_huge_number (pp
, os9k_stabs
? ',' : ';', &nbits
);
3664 return error_type (pp
, objfile
);
3666 if (!(**pp
>= '0' && **pp
<= '9') && **pp
!= '-')
3671 upper
= read_huge_number (pp
, ';', &nbits
);
3673 return error_type (pp
, objfile
);
3675 element_type
= read_type (pp
, objfile
);
3684 create_range_type ((struct type
*) NULL
, index_type
, lower
, upper
);
3685 type
= create_array_type (type
, element_type
, range_type
);
3691 /* Read a definition of an enumeration type,
3692 and create and return a suitable type object.
3693 Also defines the symbols that represent the values of the type. */
3695 static struct type
*
3696 read_enum_type (pp
, type
, objfile
)
3698 register struct type
*type
;
3699 struct objfile
*objfile
;
3704 register struct symbol
*sym
;
3706 struct pending
**symlist
;
3707 struct pending
*osyms
, *syms
;
3710 int unsigned_enum
= 1;
3713 /* FIXME! The stabs produced by Sun CC merrily define things that ought
3714 to be file-scope, between N_FN entries, using N_LSYM. What's a mother
3715 to do? For now, force all enum values to file scope. */
3716 if (within_function
)
3717 symlist
= &local_symbols
;
3720 symlist
= &file_symbols
;
3722 o_nsyms
= osyms
? osyms
->nsyms
: 0;
3726 /* Size. Perhaps this does not have to be conditionalized on
3727 os9k_stabs (assuming the name of an enum constant can't start
3729 read_huge_number (pp
, 0, &nbits
);
3731 return error_type (pp
, objfile
);
3734 /* The aix4 compiler emits an extra field before the enum members;
3735 my guess is it's a type of some sort. Just ignore it. */
3738 /* Skip over the type. */
3742 /* Skip over the colon. */
3746 /* Read the value-names and their values.
3747 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
3748 A semicolon or comma instead of a NAME means the end. */
3749 while (**pp
&& **pp
!= ';' && **pp
!= ',')
3751 STABS_CONTINUE (pp
, objfile
);
3753 while (*p
!= ':') p
++;
3754 name
= obsavestring (*pp
, p
- *pp
, &objfile
-> symbol_obstack
);
3756 n
= read_huge_number (pp
, ',', &nbits
);
3758 return error_type (pp
, objfile
);
3760 sym
= (struct symbol
*)
3761 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
3762 memset (sym
, 0, sizeof (struct symbol
));
3763 SYMBOL_NAME (sym
) = name
;
3764 SYMBOL_LANGUAGE (sym
) = current_subfile
-> language
;
3765 SYMBOL_CLASS (sym
) = LOC_CONST
;
3766 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
3767 SYMBOL_VALUE (sym
) = n
;
3770 add_symbol_to_list (sym
, symlist
);
3775 (*pp
)++; /* Skip the semicolon. */
3777 /* Now fill in the fields of the type-structure. */
3779 TYPE_LENGTH (type
) = TARGET_INT_BIT
/ HOST_CHAR_BIT
;
3780 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
3781 TYPE_FLAGS (type
) &= ~TYPE_FLAG_STUB
;
3783 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
3784 TYPE_NFIELDS (type
) = nsyms
;
3785 TYPE_FIELDS (type
) = (struct field
*)
3786 TYPE_ALLOC (type
, sizeof (struct field
) * nsyms
);
3787 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nsyms
);
3789 /* Find the symbols for the values and put them into the type.
3790 The symbols can be found in the symlist that we put them on
3791 to cause them to be defined. osyms contains the old value
3792 of that symlist; everything up to there was defined by us. */
3793 /* Note that we preserve the order of the enum constants, so
3794 that in something like "enum {FOO, LAST_THING=FOO}" we print
3795 FOO, not LAST_THING. */
3797 for (syms
= *symlist
, n
= nsyms
- 1; syms
; syms
= syms
->next
)
3799 int last
= syms
== osyms
? o_nsyms
: 0;
3800 int j
= syms
->nsyms
;
3801 for (; --j
>= last
; --n
)
3803 struct symbol
*xsym
= syms
->symbol
[j
];
3804 SYMBOL_TYPE (xsym
) = type
;
3805 TYPE_FIELD_NAME (type
, n
) = SYMBOL_NAME (xsym
);
3806 TYPE_FIELD_VALUE (type
, n
) = 0;
3807 TYPE_FIELD_BITPOS (type
, n
) = SYMBOL_VALUE (xsym
);
3808 TYPE_FIELD_BITSIZE (type
, n
) = 0;
3817 /* Sun's ACC uses a somewhat saner method for specifying the builtin
3818 typedefs in every file (for int, long, etc):
3820 type = b <signed> <width>; <offset>; <nbits>
3821 signed = u or s. Possible c in addition to u or s (for char?).
3822 offset = offset from high order bit to start bit of type.
3823 width is # bytes in object of this type, nbits is # bits in type.
3825 The width/offset stuff appears to be for small objects stored in
3826 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
3829 static struct type
*
3830 read_sun_builtin_type (pp
, typenums
, objfile
)
3833 struct objfile
*objfile
;
3848 return error_type (pp
, objfile
);
3852 /* For some odd reason, all forms of char put a c here. This is strange
3853 because no other type has this honor. We can safely ignore this because
3854 we actually determine 'char'acterness by the number of bits specified in
3860 /* The first number appears to be the number of bytes occupied
3861 by this type, except that unsigned short is 4 instead of 2.
3862 Since this information is redundant with the third number,
3863 we will ignore it. */
3864 read_huge_number (pp
, ';', &nbits
);
3866 return error_type (pp
, objfile
);
3868 /* The second number is always 0, so ignore it too. */
3869 read_huge_number (pp
, ';', &nbits
);
3871 return error_type (pp
, objfile
);
3873 /* The third number is the number of bits for this type. */
3874 type_bits
= read_huge_number (pp
, 0, &nbits
);
3876 return error_type (pp
, objfile
);
3877 /* The type *should* end with a semicolon. If it are embedded
3878 in a larger type the semicolon may be the only way to know where
3879 the type ends. If this type is at the end of the stabstring we
3880 can deal with the omitted semicolon (but we don't have to like
3881 it). Don't bother to complain(), Sun's compiler omits the semicolon
3887 return init_type (TYPE_CODE_VOID
, 1,
3888 signed_type
? 0 : TYPE_FLAG_UNSIGNED
, (char *)NULL
,
3891 return init_type (TYPE_CODE_INT
,
3892 type_bits
/ TARGET_CHAR_BIT
,
3893 signed_type
? 0 : TYPE_FLAG_UNSIGNED
, (char *)NULL
,
3897 static struct type
*
3898 read_sun_floating_type (pp
, typenums
, objfile
)
3901 struct objfile
*objfile
;
3907 /* The first number has more details about the type, for example
3909 details
= read_huge_number (pp
, ';', &nbits
);
3911 return error_type (pp
, objfile
);
3913 /* The second number is the number of bytes occupied by this type */
3914 nbytes
= read_huge_number (pp
, ';', &nbits
);
3916 return error_type (pp
, objfile
);
3918 if (details
== NF_COMPLEX
|| details
== NF_COMPLEX16
3919 || details
== NF_COMPLEX32
)
3920 /* This is a type we can't handle, but we do know the size.
3921 We also will be able to give it a name. */
3922 return init_type (TYPE_CODE_ERROR
, nbytes
, 0, NULL
, objfile
);
3924 return init_type (TYPE_CODE_FLT
, nbytes
, 0, NULL
, objfile
);
3927 /* Read a number from the string pointed to by *PP.
3928 The value of *PP is advanced over the number.
3929 If END is nonzero, the character that ends the
3930 number must match END, or an error happens;
3931 and that character is skipped if it does match.
3932 If END is zero, *PP is left pointing to that character.
3934 If the number fits in a long, set *BITS to 0 and return the value.
3935 If not, set *BITS to be the number of bits in the number and return 0.
3937 If encounter garbage, set *BITS to -1 and return 0. */
3940 read_huge_number (pp
, end
, bits
)
3960 /* Leading zero means octal. GCC uses this to output values larger
3961 than an int (because that would be hard in decimal). */
3969 upper_limit
= ULONG_MAX
/ radix
;
3971 upper_limit
= LONG_MAX
/ radix
;
3973 while ((c
= *p
++) >= '0' && c
< ('0' + radix
))
3975 if (n
<= upper_limit
)
3978 n
+= c
- '0'; /* FIXME this overflows anyway */
3983 /* This depends on large values being output in octal, which is
3990 /* Ignore leading zeroes. */
3994 else if (c
== '2' || c
== '3')
4020 /* Large decimal constants are an error (because it is hard to
4021 count how many bits are in them). */
4027 /* -0x7f is the same as 0x80. So deal with it by adding one to
4028 the number of bits. */
4040 /* It's *BITS which has the interesting information. */
4044 static struct type
*
4045 read_range_type (pp
, typenums
, objfile
)
4048 struct objfile
*objfile
;
4050 char *orig_pp
= *pp
;
4055 struct type
*result_type
;
4056 struct type
*index_type
= NULL
;
4058 /* First comes a type we are a subrange of.
4059 In C it is usually 0, 1 or the type being defined. */
4060 if (read_type_number (pp
, rangenums
) != 0)
4061 return error_type (pp
, objfile
);
4062 self_subrange
= (rangenums
[0] == typenums
[0] &&
4063 rangenums
[1] == typenums
[1]);
4068 index_type
= read_type (pp
, objfile
);
4071 /* A semicolon should now follow; skip it. */
4075 /* The remaining two operands are usually lower and upper bounds
4076 of the range. But in some special cases they mean something else. */
4077 n2
= read_huge_number (pp
, ';', &n2bits
);
4078 n3
= read_huge_number (pp
, ';', &n3bits
);
4080 if (n2bits
== -1 || n3bits
== -1)
4081 return error_type (pp
, objfile
);
4084 goto handle_true_range
;
4086 /* If limits are huge, must be large integral type. */
4087 if (n2bits
!= 0 || n3bits
!= 0)
4089 char got_signed
= 0;
4090 char got_unsigned
= 0;
4091 /* Number of bits in the type. */
4094 /* Range from 0 to <large number> is an unsigned large integral type. */
4095 if ((n2bits
== 0 && n2
== 0) && n3bits
!= 0)
4100 /* Range from <large number> to <large number>-1 is a large signed
4101 integral type. Take care of the case where <large number> doesn't
4102 fit in a long but <large number>-1 does. */
4103 else if ((n2bits
!= 0 && n3bits
!= 0 && n2bits
== n3bits
+ 1)
4104 || (n2bits
!= 0 && n3bits
== 0
4105 && (n2bits
== sizeof (long) * HOST_CHAR_BIT
)
4112 if (got_signed
|| got_unsigned
)
4114 return init_type (TYPE_CODE_INT
, nbits
/ TARGET_CHAR_BIT
,
4115 got_unsigned
? TYPE_FLAG_UNSIGNED
: 0, NULL
,
4119 return error_type (pp
, objfile
);
4122 /* A type defined as a subrange of itself, with bounds both 0, is void. */
4123 if (self_subrange
&& n2
== 0 && n3
== 0)
4124 return init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
4126 /* If n3 is zero and n2 is positive, we want a floating type,
4127 and n2 is the width in bytes.
4129 Fortran programs appear to use this for complex types also,
4130 and they give no way to distinguish between double and single-complex!
4132 GDB does not have complex types.
4134 Just return the complex as a float of that size. It won't work right
4135 for the complex values, but at least it makes the file loadable. */
4137 if (n3
== 0 && n2
> 0)
4139 return init_type (TYPE_CODE_FLT
, n2
, 0, NULL
, objfile
);
4142 /* If the upper bound is -1, it must really be an unsigned int. */
4144 else if (n2
== 0 && n3
== -1)
4146 /* It is unsigned int or unsigned long. */
4147 /* GCC 2.3.3 uses this for long long too, but that is just a GDB 3.5
4148 compatibility hack. */
4149 return init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
4150 TYPE_FLAG_UNSIGNED
, NULL
, objfile
);
4153 /* Special case: char is defined (Who knows why) as a subrange of
4154 itself with range 0-127. */
4155 else if (self_subrange
&& n2
== 0 && n3
== 127)
4156 return init_type (TYPE_CODE_INT
, 1, 0, NULL
, objfile
);
4158 else if (current_symbol
&& SYMBOL_LANGUAGE (current_symbol
) == language_chill
4160 goto handle_true_range
;
4162 /* We used to do this only for subrange of self or subrange of int. */
4166 /* n3 actually gives the size. */
4167 return init_type (TYPE_CODE_INT
, - n3
, TYPE_FLAG_UNSIGNED
,
4170 return init_type (TYPE_CODE_INT
, 1, TYPE_FLAG_UNSIGNED
, NULL
, objfile
);
4172 return init_type (TYPE_CODE_INT
, 2, TYPE_FLAG_UNSIGNED
, NULL
, objfile
);
4174 /* -1 is used for the upper bound of (4 byte) "unsigned int" and
4175 "unsigned long", and we already checked for that,
4176 so don't need to test for it here. */
4178 /* I think this is for Convex "long long". Since I don't know whether
4179 Convex sets self_subrange, I also accept that particular size regardless
4180 of self_subrange. */
4181 else if (n3
== 0 && n2
< 0
4183 || n2
== - TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
))
4184 return init_type (TYPE_CODE_INT
, - n2
, 0, NULL
, objfile
);
4185 else if (n2
== -n3
-1)
4188 return init_type (TYPE_CODE_INT
, 1, 0, NULL
, objfile
);
4190 return init_type (TYPE_CODE_INT
, 2, 0, NULL
, objfile
);
4191 if (n3
== 0x7fffffff)
4192 return init_type (TYPE_CODE_INT
, 4, 0, NULL
, objfile
);
4195 /* We have a real range type on our hands. Allocate space and
4196 return a real pointer. */
4200 index_type
= builtin_type_int
;
4202 index_type
= *dbx_lookup_type (rangenums
);
4203 if (index_type
== NULL
)
4205 /* Does this actually ever happen? Is that why we are worrying
4206 about dealing with it rather than just calling error_type? */
4208 static struct type
*range_type_index
;
4210 complain (&range_type_base_complaint
, rangenums
[1]);
4211 if (range_type_index
== NULL
)
4213 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
4214 0, "range type index type", NULL
);
4215 index_type
= range_type_index
;
4218 result_type
= create_range_type ((struct type
*) NULL
, index_type
, n2
, n3
);
4219 return (result_type
);
4222 /* Read in an argument list. This is a list of types, separated by commas
4223 and terminated with END. Return the list of types read in, or (struct type
4224 **)-1 if there is an error. */
4226 static struct type
**
4227 read_args (pp
, end
, objfile
)
4230 struct objfile
*objfile
;
4232 /* FIXME! Remove this arbitrary limit! */
4233 struct type
*types
[1024], **rval
; /* allow for fns of 1023 parameters */
4239 /* Invalid argument list: no ','. */
4240 return (struct type
**)-1;
4242 STABS_CONTINUE (pp
, objfile
);
4243 types
[n
++] = read_type (pp
, objfile
);
4245 (*pp
)++; /* get past `end' (the ':' character) */
4249 rval
= (struct type
**) xmalloc (2 * sizeof (struct type
*));
4251 else if (TYPE_CODE (types
[n
-1]) != TYPE_CODE_VOID
)
4253 rval
= (struct type
**) xmalloc ((n
+ 1) * sizeof (struct type
*));
4254 memset (rval
+ n
, 0, sizeof (struct type
*));
4258 rval
= (struct type
**) xmalloc (n
* sizeof (struct type
*));
4260 memcpy (rval
, types
, n
* sizeof (struct type
*));
4264 /* Common block handling. */
4266 /* List of symbols declared since the last BCOMM. This list is a tail
4267 of local_symbols. When ECOMM is seen, the symbols on the list
4268 are noted so their proper addresses can be filled in later,
4269 using the common block base address gotten from the assembler
4272 static struct pending
*common_block
;
4273 static int common_block_i
;
4275 /* Name of the current common block. We get it from the BCOMM instead of the
4276 ECOMM to match IBM documentation (even though IBM puts the name both places
4277 like everyone else). */
4278 static char *common_block_name
;
4280 /* Process a N_BCOMM symbol. The storage for NAME is not guaranteed
4281 to remain after this function returns. */
4284 common_block_start (name
, objfile
)
4286 struct objfile
*objfile
;
4288 if (common_block_name
!= NULL
)
4290 static struct complaint msg
= {
4291 "Invalid symbol data: common block within common block",
4295 common_block
= local_symbols
;
4296 common_block_i
= local_symbols
? local_symbols
->nsyms
: 0;
4297 common_block_name
= obsavestring (name
, strlen (name
),
4298 &objfile
-> symbol_obstack
);
4301 /* Process a N_ECOMM symbol. */
4304 common_block_end (objfile
)
4305 struct objfile
*objfile
;
4307 /* Symbols declared since the BCOMM are to have the common block
4308 start address added in when we know it. common_block and
4309 common_block_i point to the first symbol after the BCOMM in
4310 the local_symbols list; copy the list and hang it off the
4311 symbol for the common block name for later fixup. */
4314 struct pending
*new = 0;
4315 struct pending
*next
;
4318 if (common_block_name
== NULL
)
4320 static struct complaint msg
= {"ECOMM symbol unmatched by BCOMM", 0, 0};
4325 sym
= (struct symbol
*)
4326 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
4327 memset (sym
, 0, sizeof (struct symbol
));
4328 /* Note: common_block_name already saved on symbol_obstack */
4329 SYMBOL_NAME (sym
) = common_block_name
;
4330 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
4332 /* Now we copy all the symbols which have been defined since the BCOMM. */
4334 /* Copy all the struct pendings before common_block. */
4335 for (next
= local_symbols
;
4336 next
!= NULL
&& next
!= common_block
;
4339 for (j
= 0; j
< next
->nsyms
; j
++)
4340 add_symbol_to_list (next
->symbol
[j
], &new);
4343 /* Copy however much of COMMON_BLOCK we need. If COMMON_BLOCK is
4344 NULL, it means copy all the local symbols (which we already did
4347 if (common_block
!= NULL
)
4348 for (j
= common_block_i
; j
< common_block
->nsyms
; j
++)
4349 add_symbol_to_list (common_block
->symbol
[j
], &new);
4351 SYMBOL_TYPE (sym
) = (struct type
*) new;
4353 /* Should we be putting local_symbols back to what it was?
4356 i
= hashname (SYMBOL_NAME (sym
));
4357 SYMBOL_VALUE_CHAIN (sym
) = global_sym_chain
[i
];
4358 global_sym_chain
[i
] = sym
;
4359 common_block_name
= NULL
;
4362 /* Add a common block's start address to the offset of each symbol
4363 declared to be in it (by being between a BCOMM/ECOMM pair that uses
4364 the common block name). */
4367 fix_common_block (sym
, valu
)
4371 struct pending
*next
= (struct pending
*) SYMBOL_TYPE (sym
);
4372 for ( ; next
; next
= next
->next
)
4375 for (j
= next
->nsyms
- 1; j
>= 0; j
--)
4376 SYMBOL_VALUE_ADDRESS (next
->symbol
[j
]) += valu
;
4382 /* What about types defined as forward references inside of a small lexical
4384 /* Add a type to the list of undefined types to be checked through
4385 once this file has been read in. */
4388 add_undefined_type (type
)
4391 if (undef_types_length
== undef_types_allocated
)
4393 undef_types_allocated
*= 2;
4394 undef_types
= (struct type
**)
4395 xrealloc ((char *) undef_types
,
4396 undef_types_allocated
* sizeof (struct type
*));
4398 undef_types
[undef_types_length
++] = type
;
4401 /* Go through each undefined type, see if it's still undefined, and fix it
4402 up if possible. We have two kinds of undefined types:
4404 TYPE_CODE_ARRAY: Array whose target type wasn't defined yet.
4405 Fix: update array length using the element bounds
4406 and the target type's length.
4407 TYPE_CODE_STRUCT, TYPE_CODE_UNION: Structure whose fields were not
4408 yet defined at the time a pointer to it was made.
4409 Fix: Do a full lookup on the struct/union tag. */
4411 cleanup_undefined_types ()
4415 for (type
= undef_types
; type
< undef_types
+ undef_types_length
; type
++)
4417 switch (TYPE_CODE (*type
))
4420 case TYPE_CODE_STRUCT
:
4421 case TYPE_CODE_UNION
:
4422 case TYPE_CODE_ENUM
:
4424 /* Check if it has been defined since. Need to do this here
4425 as well as in check_typedef to deal with the (legitimate in
4426 C though not C++) case of several types with the same name
4427 in different source files. */
4428 if (TYPE_FLAGS (*type
) & TYPE_FLAG_STUB
)
4430 struct pending
*ppt
;
4432 /* Name of the type, without "struct" or "union" */
4433 char *typename
= TYPE_TAG_NAME (*type
);
4435 if (typename
== NULL
)
4437 static struct complaint msg
= {"need a type name", 0, 0};
4441 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
4443 for (i
= 0; i
< ppt
->nsyms
; i
++)
4445 struct symbol
*sym
= ppt
->symbol
[i
];
4447 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
4448 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
4449 && (TYPE_CODE (SYMBOL_TYPE (sym
)) ==
4451 && STREQ (SYMBOL_NAME (sym
), typename
))
4453 memcpy (*type
, SYMBOL_TYPE (sym
),
4454 sizeof (struct type
));
4464 static struct complaint msg
= {"\
4465 GDB internal error. cleanup_undefined_types with bad type %d.", 0, 0};
4466 complain (&msg
, TYPE_CODE (*type
));
4472 undef_types_length
= 0;
4475 /* Scan through all of the global symbols defined in the object file,
4476 assigning values to the debugging symbols that need to be assigned
4477 to. Get these symbols from the minimal symbol table. */
4480 scan_file_globals (objfile
)
4481 struct objfile
*objfile
;
4484 struct minimal_symbol
*msymbol
;
4485 struct symbol
*sym
, *prev
;
4487 /* Avoid expensive loop through all minimal symbols if there are
4488 no unresolved symbols. */
4489 for (hash
= 0; hash
< HASHSIZE
; hash
++)
4491 if (global_sym_chain
[hash
])
4494 if (hash
>= HASHSIZE
)
4497 for (msymbol
= objfile
-> msymbols
;
4498 msymbol
&& SYMBOL_NAME (msymbol
) != NULL
;
4503 /* Skip static symbols. */
4504 switch (MSYMBOL_TYPE (msymbol
))
4516 /* Get the hash index and check all the symbols
4517 under that hash index. */
4519 hash
= hashname (SYMBOL_NAME (msymbol
));
4521 for (sym
= global_sym_chain
[hash
]; sym
;)
4523 if (SYMBOL_NAME (msymbol
)[0] == SYMBOL_NAME (sym
)[0] &&
4524 STREQ(SYMBOL_NAME (msymbol
) + 1, SYMBOL_NAME (sym
) + 1))
4526 /* Splice this symbol out of the hash chain and
4527 assign the value we have to it. */
4530 SYMBOL_VALUE_CHAIN (prev
) = SYMBOL_VALUE_CHAIN (sym
);
4534 global_sym_chain
[hash
] = SYMBOL_VALUE_CHAIN (sym
);
4537 /* Check to see whether we need to fix up a common block. */
4538 /* Note: this code might be executed several times for
4539 the same symbol if there are multiple references. */
4541 if (SYMBOL_CLASS (sym
) == LOC_BLOCK
)
4543 fix_common_block (sym
, SYMBOL_VALUE_ADDRESS (msymbol
));
4547 SYMBOL_VALUE_ADDRESS (sym
) = SYMBOL_VALUE_ADDRESS (msymbol
);
4550 SYMBOL_SECTION (sym
) = SYMBOL_SECTION (msymbol
);
4554 sym
= SYMBOL_VALUE_CHAIN (prev
);
4558 sym
= global_sym_chain
[hash
];
4564 sym
= SYMBOL_VALUE_CHAIN (sym
);
4569 /* Change the storage class of any remaining unresolved globals to
4570 LOC_UNRESOLVED and remove them from the chain. */
4571 for (hash
= 0; hash
< HASHSIZE
; hash
++)
4573 sym
= global_sym_chain
[hash
];
4577 sym
= SYMBOL_VALUE_CHAIN (sym
);
4579 /* Change the symbol address from the misleading chain value
4581 SYMBOL_VALUE_ADDRESS (prev
) = 0;
4583 /* Complain about unresolved common block symbols. */
4584 if (SYMBOL_CLASS (prev
) == LOC_STATIC
)
4585 SYMBOL_CLASS (prev
) = LOC_UNRESOLVED
;
4587 complain (&unresolved_sym_chain_complaint
,
4588 objfile
->name
, SYMBOL_NAME (prev
));
4591 memset (global_sym_chain
, 0, sizeof (global_sym_chain
));
4594 /* Initialize anything that needs initializing when starting to read
4595 a fresh piece of a symbol file, e.g. reading in the stuff corresponding
4603 /* Initialize anything that needs initializing when a completely new
4604 symbol file is specified (not just adding some symbols from another
4605 file, e.g. a shared library). */
4608 stabsread_new_init ()
4610 /* Empty the hash table of global syms looking for values. */
4611 memset (global_sym_chain
, 0, sizeof (global_sym_chain
));
4614 /* Initialize anything that needs initializing at the same time as
4615 start_symtab() is called. */
4619 global_stabs
= NULL
; /* AIX COFF */
4620 /* Leave FILENUM of 0 free for builtin types and this file's types. */
4621 n_this_object_header_files
= 1;
4622 type_vector_length
= 0;
4623 type_vector
= (struct type
**) 0;
4625 /* FIXME: If common_block_name is not already NULL, we should complain(). */
4626 common_block_name
= NULL
;
4631 /* Call after end_symtab() */
4637 free ((char *) type_vector
);
4640 type_vector_length
= 0;
4641 previous_stab_code
= 0;
4645 finish_global_stabs (objfile
)
4646 struct objfile
*objfile
;
4650 patch_block_stabs (global_symbols
, global_stabs
, objfile
);
4651 free ((PTR
) global_stabs
);
4652 global_stabs
= NULL
;
4656 /* Initializer for this module */
4659 _initialize_stabsread ()
4661 undef_types_allocated
= 20;
4662 undef_types_length
= 0;
4663 undef_types
= (struct type
**)
4664 xmalloc (undef_types_allocated
* sizeof (struct type
*));