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 dbx_alloc_type
PARAMS ((int [2], struct objfile
*));
81 static long read_huge_number
PARAMS ((char **, int, int *));
83 static struct type
*error_type
PARAMS ((char **, struct objfile
*));
86 patch_block_stabs
PARAMS ((struct pending
*, struct pending_stabs
*,
90 fix_common_block
PARAMS ((struct symbol
*, int));
93 read_type_number
PARAMS ((char **, int *));
96 read_range_type
PARAMS ((char **, int [2], struct objfile
*));
99 read_sun_builtin_type
PARAMS ((char **, int [2], struct objfile
*));
102 read_sun_floating_type
PARAMS ((char **, int [2], struct objfile
*));
105 read_enum_type
PARAMS ((char **, struct type
*, struct objfile
*));
108 rs6000_builtin_type
PARAMS ((int));
111 read_member_functions
PARAMS ((struct field_info
*, char **, struct type
*,
115 read_struct_fields
PARAMS ((struct field_info
*, char **, struct type
*,
119 read_baseclasses
PARAMS ((struct field_info
*, char **, struct type
*,
123 read_tilde_fields
PARAMS ((struct field_info
*, char **, struct type
*,
127 attach_fn_fields_to_type
PARAMS ((struct field_info
*, struct type
*));
130 attach_fields_to_type
PARAMS ((struct field_info
*, struct type
*,
134 read_struct_type
PARAMS ((char **, struct type
*, struct objfile
*));
137 read_array_type
PARAMS ((char **, struct type
*, struct objfile
*));
139 static struct type
**
140 read_args
PARAMS ((char **, int, struct objfile
*));
143 read_cpp_abbrev
PARAMS ((struct field_info
*, char **, struct type
*,
146 /* new functions added for cfront support */
149 resolve_cfront_continuation
PARAMS ((struct objfile
*, struct symbol
*,
153 copy_cfront_struct_fields
PARAMS ((struct field_info
*, struct type
*,
157 get_cfront_method_physname
PARAMS ((char *));
160 read_cfront_baseclasses
PARAMS ((struct field_info
*, char **,
161 struct type
*, struct objfile
*));
164 read_cfront_static_fields
PARAMS ((struct field_info
*, char**,
165 struct type
*, struct objfile
*));
167 read_cfront_member_functions
PARAMS ((struct field_info
*, char **,
168 struct type
*, struct objfile
*));
170 /* end new functions added for cfront support */
174 static const char vptr_name
[] = { '_','v','p','t','r',CPLUS_MARKER
,'\0' };
175 static const char vb_name
[] = { '_','v','b',CPLUS_MARKER
,'\0' };
177 /* Define this as 1 if a pcc declaration of a char or short argument
178 gives the correct address. Otherwise assume pcc gives the
179 address of the corresponding int, which is not the same on a
180 big-endian machine. */
182 #ifndef BELIEVE_PCC_PROMOTION
183 #define BELIEVE_PCC_PROMOTION 0
186 struct complaint invalid_cpp_abbrev_complaint
=
187 {"invalid C++ abbreviation `%s'", 0, 0};
189 struct complaint invalid_cpp_type_complaint
=
190 {"C++ abbreviated type name unknown at symtab pos %d", 0, 0};
192 struct complaint member_fn_complaint
=
193 {"member function type missing, got '%c'", 0, 0};
195 struct complaint const_vol_complaint
=
196 {"const/volatile indicator missing, got '%c'", 0, 0};
198 struct complaint error_type_complaint
=
199 {"debug info mismatch between compiler and debugger", 0, 0};
201 struct complaint invalid_member_complaint
=
202 {"invalid (minimal) member type data format at symtab pos %d.", 0, 0};
204 struct complaint range_type_base_complaint
=
205 {"base type %d of range type is not defined", 0, 0};
207 struct complaint reg_value_complaint
=
208 {"register number %d too large (max %d) in symbol %s", 0, 0};
210 struct complaint vtbl_notfound_complaint
=
211 {"virtual function table pointer not found when defining class `%s'", 0, 0};
213 struct complaint unrecognized_cplus_name_complaint
=
214 {"Unknown C++ symbol name `%s'", 0, 0};
216 struct complaint rs6000_builtin_complaint
=
217 {"Unknown builtin type %d", 0, 0};
219 struct complaint unresolved_sym_chain_complaint
=
220 {"%s: common block `%s' from global_sym_chain unresolved", 0, 0};
222 struct complaint stabs_general_complaint
=
225 /* Make a list of forward references which haven't been defined. */
227 static struct type
**undef_types
;
228 static int undef_types_allocated
;
229 static int undef_types_length
;
230 static struct symbol
*current_symbol
= NULL
;
232 /* Check for and handle cretinous stabs symbol name continuation! */
233 #define STABS_CONTINUE(pp,objfile) \
235 if (**(pp) == '\\' || (**(pp) == '?' && (*(pp))[1] == '\0')) \
236 *(pp) = next_symbol_text (objfile); \
239 /* FIXME: These probably should be our own types (like rs6000_builtin_type
240 has its own types) rather than builtin_type_*. */
241 static struct type
**os9k_type_vector
[] = {
247 &builtin_type_unsigned_char
,
248 &builtin_type_unsigned_short
,
249 &builtin_type_unsigned_long
,
250 &builtin_type_unsigned_int
,
252 &builtin_type_double
,
254 &builtin_type_long_double
257 static void os9k_init_type_vector
PARAMS ((struct type
**));
260 os9k_init_type_vector(tv
)
264 for (i
=0; i
<sizeof(os9k_type_vector
)/sizeof(struct type
**); i
++)
265 tv
[i
] = (os9k_type_vector
[i
] == 0 ? 0 : *(os9k_type_vector
[i
]));
268 /* Look up a dbx type-number pair. Return the address of the slot
269 where the type for that number-pair is stored.
270 The number-pair is in TYPENUMS.
272 This can be used for finding the type associated with that pair
273 or for associating a new type with the pair. */
276 dbx_lookup_type (typenums
)
279 register int filenum
= typenums
[0];
280 register int index
= typenums
[1];
282 register int real_filenum
;
283 register struct header_file
*f
;
286 if (filenum
== -1) /* -1,-1 is for temporary types. */
289 if (filenum
< 0 || filenum
>= n_this_object_header_files
)
291 static struct complaint msg
= {"\
292 Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.",
294 complain (&msg
, filenum
, index
, symnum
);
302 /* Caller wants address of address of type. We think
303 that negative (rs6k builtin) types will never appear as
304 "lvalues", (nor should they), so we stuff the real type
305 pointer into a temp, and return its address. If referenced,
306 this will do the right thing. */
307 static struct type
*temp_type
;
309 temp_type
= rs6000_builtin_type(index
);
313 /* Type is defined outside of header files.
314 Find it in this object file's type vector. */
315 if (index
>= type_vector_length
)
317 old_len
= type_vector_length
;
320 type_vector_length
= INITIAL_TYPE_VECTOR_LENGTH
;
321 type_vector
= (struct type
**)
322 xmalloc (type_vector_length
* sizeof (struct type
*));
324 while (index
>= type_vector_length
)
326 type_vector_length
*= 2;
328 type_vector
= (struct type
**)
329 xrealloc ((char *) type_vector
,
330 (type_vector_length
* sizeof (struct type
*)));
331 memset (&type_vector
[old_len
], 0,
332 (type_vector_length
- old_len
) * sizeof (struct type
*));
335 /* Deal with OS9000 fundamental types. */
336 os9k_init_type_vector (type_vector
);
338 return (&type_vector
[index
]);
342 real_filenum
= this_object_header_files
[filenum
];
344 if (real_filenum
>= n_header_files
)
346 struct type
*temp_type
;
347 struct type
**temp_type_p
;
349 warning ("GDB internal error: bad real_filenum");
352 temp_type
= init_type (TYPE_CODE_ERROR
, 0, 0, NULL
, NULL
);
353 temp_type_p
= (struct type
**) xmalloc (sizeof (struct type
*));
354 *temp_type_p
= temp_type
;
358 f
= &header_files
[real_filenum
];
360 f_orig_length
= f
->length
;
361 if (index
>= f_orig_length
)
363 while (index
>= f
->length
)
367 f
->vector
= (struct type
**)
368 xrealloc ((char *) f
->vector
, f
->length
* sizeof (struct type
*));
369 memset (&f
->vector
[f_orig_length
], 0,
370 (f
->length
- f_orig_length
) * sizeof (struct type
*));
372 return (&f
->vector
[index
]);
376 /* Make sure there is a type allocated for type numbers TYPENUMS
377 and return the type object.
378 This can create an empty (zeroed) type object.
379 TYPENUMS may be (-1, -1) to return a new type object that is not
380 put into the type vector, and so may not be referred to by number. */
383 dbx_alloc_type (typenums
, objfile
)
385 struct objfile
*objfile
;
387 register struct type
**type_addr
;
389 if (typenums
[0] == -1)
391 return (alloc_type (objfile
));
394 type_addr
= dbx_lookup_type (typenums
);
396 /* If we are referring to a type not known at all yet,
397 allocate an empty type for it.
398 We will fill it in later if we find out how. */
401 *type_addr
= alloc_type (objfile
);
407 /* for all the stabs in a given stab vector, build appropriate types
408 and fix their symbols in given symbol vector. */
411 patch_block_stabs (symbols
, stabs
, objfile
)
412 struct pending
*symbols
;
413 struct pending_stabs
*stabs
;
414 struct objfile
*objfile
;
424 /* for all the stab entries, find their corresponding symbols and
425 patch their types! */
427 for (ii
= 0; ii
< stabs
->count
; ++ii
)
429 name
= stabs
->stab
[ii
];
430 pp
= (char*) strchr (name
, ':');
434 pp
= (char *)strchr(pp
, ':');
436 sym
= find_symbol_in_list (symbols
, name
, pp
-name
);
439 /* FIXME-maybe: it would be nice if we noticed whether
440 the variable was defined *anywhere*, not just whether
441 it is defined in this compilation unit. But neither
442 xlc or GCC seem to need such a definition, and until
443 we do psymtabs (so that the minimal symbols from all
444 compilation units are available now), I'm not sure
445 how to get the information. */
447 /* On xcoff, if a global is defined and never referenced,
448 ld will remove it from the executable. There is then
449 a N_GSYM stab for it, but no regular (C_EXT) symbol. */
450 sym
= (struct symbol
*)
451 obstack_alloc (&objfile
->symbol_obstack
,
452 sizeof (struct symbol
));
454 memset (sym
, 0, sizeof (struct symbol
));
455 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
456 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
458 obsavestring (name
, pp
- name
, &objfile
->symbol_obstack
);
460 if (*(pp
-1) == 'F' || *(pp
-1) == 'f')
462 /* I don't think the linker does this with functions,
463 so as far as I know this is never executed.
464 But it doesn't hurt to check. */
466 lookup_function_type (read_type (&pp
, objfile
));
470 SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
472 add_symbol_to_list (sym
, &global_symbols
);
477 if (*(pp
-1) == 'F' || *(pp
-1) == 'f')
480 lookup_function_type (read_type (&pp
, objfile
));
484 SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
492 /* Read a number by which a type is referred to in dbx data,
493 or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
494 Just a single number N is equivalent to (0,N).
495 Return the two numbers by storing them in the vector TYPENUMS.
496 TYPENUMS will then be used as an argument to dbx_lookup_type.
498 Returns 0 for success, -1 for error. */
501 read_type_number (pp
, typenums
)
503 register int *typenums
;
509 typenums
[0] = read_huge_number (pp
, ',', &nbits
);
510 if (nbits
!= 0) return -1;
511 typenums
[1] = read_huge_number (pp
, ')', &nbits
);
512 if (nbits
!= 0) return -1;
517 typenums
[1] = read_huge_number (pp
, 0, &nbits
);
518 if (nbits
!= 0) return -1;
524 #if !defined (REG_STRUCT_HAS_ADDR)
525 #define REG_STRUCT_HAS_ADDR(gcc_p,type) 0
528 #define VISIBILITY_PRIVATE '0' /* Stabs character for private field */
529 #define VISIBILITY_PROTECTED '1' /* Stabs character for protected fld */
530 #define VISIBILITY_PUBLIC '2' /* Stabs character for public field */
531 #define VISIBILITY_IGNORE '9' /* Optimized out or zero length */
533 #define CFRONT_VISIBILITY_PRIVATE '2' /* Stabs character for private field */
534 #define CFRONT_VISIBILITY_PUBLIC '1' /* Stabs character for public field */
536 /* This code added to support parsing of ARM/Cfront stabs strings */
538 /* get substring from string up to char c
539 advance string pointer past suibstring */
558 /* Physname gets strcat'd onto sname in order to recreate the mangled name
559 (see funtion gdb_mangle_name in gdbtypes.c). For cfront, make the physname
560 look like that of g++ - take out the initial mangling
561 eg: for sname="a" and fname="foo__1aFPFs_i" return "FPFs_i" */
563 get_cfront_method_physname(fname
)
567 /* FIXME would like to make this generic for g++ too, but
568 that is already handled in read_member_funcctions */
571 /* search ahead to find the start of the mangled suffix */
572 if (*p
== '_' && *(p
+1)=='_') /* compiler generated; probably a ctor/dtor */
574 while (p
&& ((p
+1) - fname
) < strlen(fname
) && *(p
+1)!='_')
576 if (!(p
&& *p
=='_' && *(p
+1)=='_'))
577 error("Invalid mangled function name %s",fname
);
578 p
+=2; /* advance past '__' */
580 /* struct name length and name of type should come next; advance past it */
583 len
= len
*10 + (*p
- '0');
591 /* Read base classes within cfront class definition.
592 eg: A:ZcA;1@Bpub v2@Bvirpri;__ct__1AFv func__1AFv *sfunc__1AFv ;as__1A ;;
595 A:ZcA;;foopri__1AFv foopro__1AFv __ct__1AFv __ct__1AFRC1A foopub__1AFv ;;;
599 read_cfront_baseclasses(fip
, pp
, type
, objfile
)
600 struct field_info
*fip
;
601 struct objfile
* objfile
;
605 static struct complaint msg_noterm
= {"\
606 Base classes not terminated while reading stabs string %s.\n",
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!
882 new_sublist -> fn_field.is_const = 0;
883 new_sublist -> fn_field.is_volatile = 0; /* volatile not implemented in cfront */
885 /* set virtual/static function info
886 How to get vtable offsets ?
887 Assuming normal for now FIXME!!
888 For vtables, figure out from whence this virtual function came.
889 It may belong to virtual function table of
890 one of its baseclasses.
892 new_sublist -> fn_field.voffset = vtable offset,
893 new_sublist -> fn_field.fcontext = look_ahead_type;
894 where look_ahead_type is type of baseclass */
896 new_sublist
-> fn_field
.voffset
= VOFFSET_STATIC
;
897 else /* normal member function. */
898 new_sublist
-> fn_field
.voffset
= 0;
899 new_sublist
-> fn_field
.fcontext
= 0;
902 /* prepare new sublist */
903 new_sublist
-> next
= sublist
;
904 sublist
= new_sublist
;
906 /* In g++, we loop thu sublists - now we set from function */
908 new_fnlist
-> fn_fieldlist
.fn_fields
= (struct fn_field
*)
909 obstack_alloc (&objfile
-> type_obstack
,
910 sizeof (struct fn_field
) * length
);
911 memset (new_fnlist
-> fn_fieldlist
.fn_fields
, 0,
912 sizeof (struct fn_field
) * length
);
913 for (i
= length
; (i
--, sublist
); sublist
= sublist
-> next
)
915 new_fnlist
-> fn_fieldlist
.fn_fields
[i
] = sublist
-> fn_field
;
918 new_fnlist
-> fn_fieldlist
.length
= length
;
919 new_fnlist
-> next
= fip
-> fnlist
;
920 fip
-> fnlist
= new_fnlist
;
922 total_length
+= length
;
923 STABS_CONTINUE (pp
, objfile
); /* handle \\ */
928 /* type should already have space */
929 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
930 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * nfn_fields
);
931 memset (TYPE_FN_FIELDLISTS (type
), 0,
932 sizeof (struct fn_fieldlist
) * nfn_fields
);
933 TYPE_NFN_FIELDS (type
) = nfn_fields
;
934 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
937 /* end of scope for reading member func */
940 /* skip trailing ';' and bump count of number of fields seen */
948 /* This routine fixes up partial cfront types that were created
949 while parsing the stabs. The main need for this function is
950 to add information such as methods to classes.
951 Examples of "p": "sA;;__ct__1AFv foo__1AFv ;;;" */
953 resolve_cfront_continuation(objfile
, sym
, p
)
954 struct objfile
* objfile
;
958 struct symbol
* ref_sym
=0;
960 /* snarfed from read_struct_type */
961 struct field_info fi
;
962 struct field_info
* fip
= &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;
1869 char type_descriptor
;
1871 /* Size in bits of type if specified by a type attribute, or -1 if
1872 there is no size attribute. */
1875 /* Used to distinguish string and bitstring from char-array and set. */
1878 /* Read type number if present. The type number may be omitted.
1879 for instance in a two-dimensional array declared with type
1880 "ar1;1;10;ar1;1;10;4". */
1881 if ((**pp
>= '0' && **pp
<= '9')
1885 if (read_type_number (pp
, typenums
) != 0)
1886 return error_type (pp
, objfile
);
1888 /* Type is not being defined here. Either it already exists,
1889 or this is a forward reference to it. dbx_alloc_type handles
1892 return dbx_alloc_type (typenums
, objfile
);
1894 /* Type is being defined here. */
1896 Also skip the type descriptor - we get it below with (*pp)[-1]. */
1901 /* 'typenums=' not present, type is anonymous. Read and return
1902 the definition, but don't put it in the type vector. */
1903 typenums
[0] = typenums
[1] = -1;
1908 type_descriptor
= (*pp
)[-1];
1909 switch (type_descriptor
)
1913 enum type_code code
;
1915 /* Used to index through file_symbols. */
1916 struct pending
*ppt
;
1919 /* Name including "struct", etc. */
1923 char *from
, *to
, *p
, *q1
, *q2
;
1925 /* Set the type code according to the following letter. */
1929 code
= TYPE_CODE_STRUCT
;
1932 code
= TYPE_CODE_UNION
;
1935 code
= TYPE_CODE_ENUM
;
1939 /* Complain and keep going, so compilers can invent new
1940 cross-reference types. */
1941 static struct complaint msg
=
1942 {"Unrecognized cross-reference type `%c'", 0, 0};
1943 complain (&msg
, (*pp
)[0]);
1944 code
= TYPE_CODE_STRUCT
;
1949 q1
= strchr(*pp
, '<');
1950 p
= strchr(*pp
, ':');
1952 return error_type (pp
, objfile
);
1953 while (q1
&& p
> q1
&& p
[1] == ':')
1955 q2
= strchr(q1
, '>');
1961 return error_type (pp
, objfile
);
1964 (char *)obstack_alloc (&objfile
->type_obstack
, p
- *pp
+ 1);
1966 /* Copy the name. */
1972 /* Set the pointer ahead of the name which we just read, and
1977 /* Now check to see whether the type has already been
1978 declared. This was written for arrays of cross-referenced
1979 types before we had TYPE_CODE_TARGET_STUBBED, so I'm pretty
1980 sure it is not necessary anymore. But it might be a good
1981 idea, to save a little memory. */
1983 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
1984 for (i
= 0; i
< ppt
->nsyms
; i
++)
1986 struct symbol
*sym
= ppt
->symbol
[i
];
1988 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
1989 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
1990 && (TYPE_CODE (SYMBOL_TYPE (sym
)) == code
)
1991 && STREQ (SYMBOL_NAME (sym
), type_name
))
1993 obstack_free (&objfile
-> type_obstack
, type_name
);
1994 type
= SYMBOL_TYPE (sym
);
1999 /* Didn't find the type to which this refers, so we must
2000 be dealing with a forward reference. Allocate a type
2001 structure for it, and keep track of it so we can
2002 fill in the rest of the fields when we get the full
2004 type
= dbx_alloc_type (typenums
, objfile
);
2005 TYPE_CODE (type
) = code
;
2006 TYPE_TAG_NAME (type
) = type_name
;
2007 INIT_CPLUS_SPECIFIC(type
);
2008 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
2010 add_undefined_type (type
);
2014 case '-': /* RS/6000 built-in type */
2028 /* We deal with something like t(1,2)=(3,4)=... which
2029 the Lucid compiler and recent gcc versions (post 2.7.3) use. */
2031 /* Allocate and enter the typedef type first.
2032 This handles recursive types. */
2033 type
= dbx_alloc_type (typenums
, objfile
);
2034 TYPE_CODE (type
) = TYPE_CODE_TYPEDEF
;
2035 { struct type
*xtype
= read_type (pp
, objfile
);
2038 /* It's being defined as itself. That means it is "void". */
2039 TYPE_CODE (type
) = TYPE_CODE_VOID
;
2040 TYPE_LENGTH (type
) = 1;
2042 else if (type_size
>= 0 || is_string
)
2045 TYPE_NAME (type
) = NULL
;
2046 TYPE_TAG_NAME (type
) = NULL
;
2050 TYPE_FLAGS (type
) |= TYPE_FLAG_TARGET_STUB
;
2051 TYPE_TARGET_TYPE (type
) = xtype
;
2056 /* In the following types, we must be sure to overwrite any existing
2057 type that the typenums refer to, rather than allocating a new one
2058 and making the typenums point to the new one. This is because there
2059 may already be pointers to the existing type (if it had been
2060 forward-referenced), and we must change it to a pointer, function,
2061 reference, or whatever, *in-place*. */
2064 type1
= read_type (pp
, objfile
);
2065 type
= make_pointer_type (type1
, dbx_lookup_type (typenums
));
2068 case '&': /* Reference to another type */
2069 type1
= read_type (pp
, objfile
);
2070 type
= make_reference_type (type1
, dbx_lookup_type (typenums
));
2073 case 'f': /* Function returning another type */
2074 if (os9k_stabs
&& **pp
== '(')
2076 /* Function prototype; parse it.
2077 We must conditionalize this on os9k_stabs because otherwise
2078 it could be confused with a Sun-style (1,3) typenumber
2084 t
= read_type(pp
, objfile
);
2085 if (**pp
== ',') ++*pp
;
2088 type1
= read_type (pp
, objfile
);
2089 type
= make_function_type (type1
, dbx_lookup_type (typenums
));
2092 case 'k': /* Const qualifier on some type (Sun) */
2093 case 'c': /* Const qualifier on some type (OS9000) */
2094 /* Because 'c' means other things to AIX and 'k' is perfectly good,
2095 only accept 'c' in the os9k_stabs case. */
2096 if (type_descriptor
== 'c' && !os9k_stabs
)
2097 return error_type (pp
, objfile
);
2098 type
= read_type (pp
, objfile
);
2099 /* FIXME! For now, we ignore const and volatile qualifiers. */
2102 case 'B': /* Volatile qual on some type (Sun) */
2103 case 'i': /* Volatile qual on some type (OS9000) */
2104 /* Because 'i' means other things to AIX and 'B' is perfectly good,
2105 only accept 'i' in the os9k_stabs case. */
2106 if (type_descriptor
== 'i' && !os9k_stabs
)
2107 return error_type (pp
, objfile
);
2108 type
= read_type (pp
, objfile
);
2109 /* FIXME! For now, we ignore const and volatile qualifiers. */
2113 if (isdigit (**pp
) || **pp
== '(' || **pp
== '-')
2114 { /* Member (class & variable) type */
2115 /* FIXME -- we should be doing smash_to_XXX types here. */
2117 struct type
*domain
= read_type (pp
, objfile
);
2118 struct type
*memtype
;
2121 /* Invalid member type data format. */
2122 return error_type (pp
, objfile
);
2125 memtype
= read_type (pp
, objfile
);
2126 type
= dbx_alloc_type (typenums
, objfile
);
2127 smash_to_member_type (type
, domain
, memtype
);
2129 else /* type attribute */
2132 /* Skip to the semicolon. */
2133 while (**pp
!= ';' && **pp
!= '\0')
2136 return error_type (pp
, objfile
);
2138 ++*pp
; /* Skip the semicolon. */
2143 type_size
= atoi (attr
+ 1);
2153 /* Ignore unrecognized type attributes, so future compilers
2154 can invent new ones. */
2162 case '#': /* Method (class & fn) type */
2163 if ((*pp
)[0] == '#')
2165 /* We'll get the parameter types from the name. */
2166 struct type
*return_type
;
2169 return_type
= read_type (pp
, objfile
);
2170 if (*(*pp
)++ != ';')
2171 complain (&invalid_member_complaint
, symnum
);
2172 type
= allocate_stub_method (return_type
);
2173 if (typenums
[0] != -1)
2174 *dbx_lookup_type (typenums
) = type
;
2178 struct type
*domain
= read_type (pp
, objfile
);
2179 struct type
*return_type
;
2183 /* Invalid member type data format. */
2184 return error_type (pp
, objfile
);
2188 return_type
= read_type (pp
, objfile
);
2189 args
= read_args (pp
, ';', objfile
);
2190 type
= dbx_alloc_type (typenums
, objfile
);
2191 smash_to_method_type (type
, domain
, return_type
, args
);
2195 case 'r': /* Range type */
2196 type
= read_range_type (pp
, typenums
, objfile
);
2197 if (typenums
[0] != -1)
2198 *dbx_lookup_type (typenums
) = type
;
2203 /* Const and volatile qualified type. */
2204 type
= read_type (pp
, objfile
);
2207 /* Sun ACC builtin int type */
2208 type
= read_sun_builtin_type (pp
, typenums
, objfile
);
2209 if (typenums
[0] != -1)
2210 *dbx_lookup_type (typenums
) = type
;
2214 case 'R': /* Sun ACC builtin float type */
2215 type
= read_sun_floating_type (pp
, typenums
, objfile
);
2216 if (typenums
[0] != -1)
2217 *dbx_lookup_type (typenums
) = type
;
2220 case 'e': /* Enumeration type */
2221 type
= dbx_alloc_type (typenums
, objfile
);
2222 type
= read_enum_type (pp
, type
, objfile
);
2223 if (typenums
[0] != -1)
2224 *dbx_lookup_type (typenums
) = type
;
2227 case 's': /* Struct type */
2228 case 'u': /* Union type */
2229 type
= dbx_alloc_type (typenums
, objfile
);
2230 switch (type_descriptor
)
2233 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
2236 TYPE_CODE (type
) = TYPE_CODE_UNION
;
2239 type
= read_struct_type (pp
, type
, objfile
);
2242 case 'a': /* Array type */
2244 return error_type (pp
, objfile
);
2247 type
= dbx_alloc_type (typenums
, objfile
);
2248 type
= read_array_type (pp
, type
, objfile
);
2250 TYPE_CODE (type
) = TYPE_CODE_STRING
;
2254 type1
= read_type (pp
, objfile
);
2255 type
= create_set_type ((struct type
*) NULL
, type1
);
2257 TYPE_CODE (type
) = TYPE_CODE_BITSTRING
;
2258 if (typenums
[0] != -1)
2259 *dbx_lookup_type (typenums
) = type
;
2263 --*pp
; /* Go back to the symbol in error */
2264 /* Particularly important if it was \0! */
2265 return error_type (pp
, objfile
);
2270 warning ("GDB internal error, type is NULL in stabsread.c\n");
2271 return error_type (pp
, objfile
);
2274 /* Size specified in a type attribute overrides any other size. */
2275 if (type_size
!= -1)
2276 TYPE_LENGTH (type
) = (type_size
+ TARGET_CHAR_BIT
- 1) / TARGET_CHAR_BIT
;
2281 /* RS/6000 xlc/dbx combination uses a set of builtin types, starting from -1.
2282 Return the proper type node for a given builtin type number. */
2284 static struct type
*
2285 rs6000_builtin_type (typenum
)
2288 /* We recognize types numbered from -NUMBER_RECOGNIZED to -1. */
2289 #define NUMBER_RECOGNIZED 34
2290 /* This includes an empty slot for type number -0. */
2291 static struct type
*negative_types
[NUMBER_RECOGNIZED
+ 1];
2292 struct type
*rettype
= NULL
;
2294 if (typenum
>= 0 || typenum
< -NUMBER_RECOGNIZED
)
2296 complain (&rs6000_builtin_complaint
, typenum
);
2297 return builtin_type_error
;
2299 if (negative_types
[-typenum
] != NULL
)
2300 return negative_types
[-typenum
];
2302 #if TARGET_CHAR_BIT != 8
2303 #error This code wrong for TARGET_CHAR_BIT not 8
2304 /* These definitions all assume that TARGET_CHAR_BIT is 8. I think
2305 that if that ever becomes not true, the correct fix will be to
2306 make the size in the struct type to be in bits, not in units of
2313 /* The size of this and all the other types are fixed, defined
2314 by the debugging format. If there is a type called "int" which
2315 is other than 32 bits, then it should use a new negative type
2316 number (or avoid negative type numbers for that case).
2317 See stabs.texinfo. */
2318 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "int", NULL
);
2321 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "char", NULL
);
2324 rettype
= init_type (TYPE_CODE_INT
, 2, 0, "short", NULL
);
2327 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "long", NULL
);
2330 rettype
= init_type (TYPE_CODE_INT
, 1, TYPE_FLAG_UNSIGNED
,
2331 "unsigned char", NULL
);
2334 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "signed char", NULL
);
2337 rettype
= init_type (TYPE_CODE_INT
, 2, TYPE_FLAG_UNSIGNED
,
2338 "unsigned short", NULL
);
2341 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
2342 "unsigned int", NULL
);
2345 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
2348 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
2349 "unsigned long", NULL
);
2352 rettype
= init_type (TYPE_CODE_VOID
, 1, 0, "void", NULL
);
2355 /* IEEE single precision (32 bit). */
2356 rettype
= init_type (TYPE_CODE_FLT
, 4, 0, "float", NULL
);
2359 /* IEEE double precision (64 bit). */
2360 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "double", NULL
);
2363 /* This is an IEEE double on the RS/6000, and different machines with
2364 different sizes for "long double" should use different negative
2365 type numbers. See stabs.texinfo. */
2366 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "long double", NULL
);
2369 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "integer", NULL
);
2372 rettype
= init_type (TYPE_CODE_BOOL
, 4, TYPE_FLAG_UNSIGNED
,
2376 rettype
= init_type (TYPE_CODE_FLT
, 4, 0, "short real", NULL
);
2379 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "real", NULL
);
2382 rettype
= init_type (TYPE_CODE_ERROR
, 0, 0, "stringptr", NULL
);
2385 rettype
= init_type (TYPE_CODE_CHAR
, 1, TYPE_FLAG_UNSIGNED
,
2389 rettype
= init_type (TYPE_CODE_BOOL
, 1, TYPE_FLAG_UNSIGNED
,
2393 rettype
= init_type (TYPE_CODE_BOOL
, 2, TYPE_FLAG_UNSIGNED
,
2397 rettype
= init_type (TYPE_CODE_BOOL
, 4, TYPE_FLAG_UNSIGNED
,
2401 rettype
= init_type (TYPE_CODE_BOOL
, 4, TYPE_FLAG_UNSIGNED
,
2405 /* Complex type consisting of two IEEE single precision values. */
2406 rettype
= init_type (TYPE_CODE_ERROR
, 8, 0, "complex", NULL
);
2409 /* Complex type consisting of two IEEE double precision values. */
2410 rettype
= init_type (TYPE_CODE_ERROR
, 16, 0, "double complex", NULL
);
2413 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "integer*1", NULL
);
2416 rettype
= init_type (TYPE_CODE_INT
, 2, 0, "integer*2", NULL
);
2419 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "integer*4", NULL
);
2422 rettype
= init_type (TYPE_CODE_CHAR
, 2, 0, "wchar", NULL
);
2425 rettype
= init_type (TYPE_CODE_INT
, 8, 0, "long long", NULL
);
2428 rettype
= init_type (TYPE_CODE_INT
, 8, TYPE_FLAG_UNSIGNED
,
2429 "unsigned long long", NULL
);
2432 rettype
= init_type (TYPE_CODE_INT
, 8, TYPE_FLAG_UNSIGNED
,
2436 rettype
= init_type (TYPE_CODE_INT
, 8, 0, "integer*8", NULL
);
2439 negative_types
[-typenum
] = rettype
;
2443 /* This page contains subroutines of read_type. */
2445 /* Read member function stabs info for C++ classes. The form of each member
2448 NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
2450 An example with two member functions is:
2452 afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
2454 For the case of overloaded operators, the format is op$::*.funcs, where
2455 $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
2456 name (such as `+=') and `.' marks the end of the operator name.
2458 Returns 1 for success, 0 for failure. */
2461 read_member_functions (fip
, pp
, type
, objfile
)
2462 struct field_info
*fip
;
2465 struct objfile
*objfile
;
2469 /* Total number of member functions defined in this class. If the class
2470 defines two `f' functions, and one `g' function, then this will have
2472 int total_length
= 0;
2476 struct next_fnfield
*next
;
2477 struct fn_field fn_field
;
2479 struct type
*look_ahead_type
;
2480 struct next_fnfieldlist
*new_fnlist
;
2481 struct next_fnfield
*new_sublist
;
2485 /* Process each list until we find something that is not a member function
2486 or find the end of the functions. */
2490 /* We should be positioned at the start of the function name.
2491 Scan forward to find the first ':' and if it is not the
2492 first of a "::" delimiter, then this is not a member function. */
2504 look_ahead_type
= NULL
;
2507 new_fnlist
= (struct next_fnfieldlist
*)
2508 xmalloc (sizeof (struct next_fnfieldlist
));
2509 make_cleanup (free
, new_fnlist
);
2510 memset (new_fnlist
, 0, sizeof (struct next_fnfieldlist
));
2512 if ((*pp
)[0] == 'o' && (*pp
)[1] == 'p' && is_cplus_marker ((*pp
)[2]))
2514 /* This is a completely wierd case. In order to stuff in the
2515 names that might contain colons (the usual name delimiter),
2516 Mike Tiemann defined a different name format which is
2517 signalled if the identifier is "op$". In that case, the
2518 format is "op$::XXXX." where XXXX is the name. This is
2519 used for names like "+" or "=". YUUUUUUUK! FIXME! */
2520 /* This lets the user type "break operator+".
2521 We could just put in "+" as the name, but that wouldn't
2523 static char opname
[32] = {'o', 'p', CPLUS_MARKER
};
2524 char *o
= opname
+ 3;
2526 /* Skip past '::'. */
2529 STABS_CONTINUE (pp
, objfile
);
2535 main_fn_name
= savestring (opname
, o
- opname
);
2541 main_fn_name
= savestring (*pp
, p
- *pp
);
2542 /* Skip past '::'. */
2545 new_fnlist
-> fn_fieldlist
.name
= main_fn_name
;
2550 (struct next_fnfield
*) xmalloc (sizeof (struct next_fnfield
));
2551 make_cleanup (free
, new_sublist
);
2552 memset (new_sublist
, 0, sizeof (struct next_fnfield
));
2554 /* Check for and handle cretinous dbx symbol name continuation! */
2555 if (look_ahead_type
== NULL
)
2558 STABS_CONTINUE (pp
, objfile
);
2560 new_sublist
-> fn_field
.type
= read_type (pp
, objfile
);
2563 /* Invalid symtab info for member function. */
2569 /* g++ version 1 kludge */
2570 new_sublist
-> fn_field
.type
= look_ahead_type
;
2571 look_ahead_type
= NULL
;
2581 /* If this is just a stub, then we don't have the real name here. */
2583 if (TYPE_FLAGS (new_sublist
-> fn_field
.type
) & TYPE_FLAG_STUB
)
2585 if (!TYPE_DOMAIN_TYPE (new_sublist
-> fn_field
.type
))
2586 TYPE_DOMAIN_TYPE (new_sublist
-> fn_field
.type
) = type
;
2587 new_sublist
-> fn_field
.is_stub
= 1;
2589 new_sublist
-> fn_field
.physname
= savestring (*pp
, p
- *pp
);
2592 /* Set this member function's visibility fields. */
2595 case VISIBILITY_PRIVATE
:
2596 new_sublist
-> fn_field
.is_private
= 1;
2598 case VISIBILITY_PROTECTED
:
2599 new_sublist
-> fn_field
.is_protected
= 1;
2603 STABS_CONTINUE (pp
, objfile
);
2606 case 'A': /* Normal functions. */
2607 new_sublist
-> fn_field
.is_const
= 0;
2608 new_sublist
-> fn_field
.is_volatile
= 0;
2611 case 'B': /* `const' member functions. */
2612 new_sublist
-> fn_field
.is_const
= 1;
2613 new_sublist
-> fn_field
.is_volatile
= 0;
2616 case 'C': /* `volatile' member function. */
2617 new_sublist
-> fn_field
.is_const
= 0;
2618 new_sublist
-> fn_field
.is_volatile
= 1;
2621 case 'D': /* `const volatile' member function. */
2622 new_sublist
-> fn_field
.is_const
= 1;
2623 new_sublist
-> fn_field
.is_volatile
= 1;
2626 case '*': /* File compiled with g++ version 1 -- no info */
2631 complain (&const_vol_complaint
, **pp
);
2640 /* virtual member function, followed by index.
2641 The sign bit is set to distinguish pointers-to-methods
2642 from virtual function indicies. Since the array is
2643 in words, the quantity must be shifted left by 1
2644 on 16 bit machine, and by 2 on 32 bit machine, forcing
2645 the sign bit out, and usable as a valid index into
2646 the array. Remove the sign bit here. */
2647 new_sublist
-> fn_field
.voffset
=
2648 (0x7fffffff & read_huge_number (pp
, ';', &nbits
)) + 2;
2652 STABS_CONTINUE (pp
, objfile
);
2653 if (**pp
== ';' || **pp
== '\0')
2655 /* Must be g++ version 1. */
2656 new_sublist
-> fn_field
.fcontext
= 0;
2660 /* Figure out from whence this virtual function came.
2661 It may belong to virtual function table of
2662 one of its baseclasses. */
2663 look_ahead_type
= read_type (pp
, objfile
);
2666 /* g++ version 1 overloaded methods. */
2670 new_sublist
-> fn_field
.fcontext
= look_ahead_type
;
2679 look_ahead_type
= NULL
;
2685 /* static member function. */
2686 new_sublist
-> fn_field
.voffset
= VOFFSET_STATIC
;
2687 if (strncmp (new_sublist
-> fn_field
.physname
,
2688 main_fn_name
, strlen (main_fn_name
)))
2690 new_sublist
-> fn_field
.is_stub
= 1;
2696 complain (&member_fn_complaint
, (*pp
)[-1]);
2697 /* Fall through into normal member function. */
2700 /* normal member function. */
2701 new_sublist
-> fn_field
.voffset
= 0;
2702 new_sublist
-> fn_field
.fcontext
= 0;
2706 new_sublist
-> next
= sublist
;
2707 sublist
= new_sublist
;
2709 STABS_CONTINUE (pp
, objfile
);
2711 while (**pp
!= ';' && **pp
!= '\0');
2715 new_fnlist
-> fn_fieldlist
.fn_fields
= (struct fn_field
*)
2716 obstack_alloc (&objfile
-> type_obstack
,
2717 sizeof (struct fn_field
) * length
);
2718 memset (new_fnlist
-> fn_fieldlist
.fn_fields
, 0,
2719 sizeof (struct fn_field
) * length
);
2720 for (i
= length
; (i
--, sublist
); sublist
= sublist
-> next
)
2722 new_fnlist
-> fn_fieldlist
.fn_fields
[i
] = sublist
-> fn_field
;
2725 new_fnlist
-> fn_fieldlist
.length
= length
;
2726 new_fnlist
-> next
= fip
-> fnlist
;
2727 fip
-> fnlist
= new_fnlist
;
2729 total_length
+= length
;
2730 STABS_CONTINUE (pp
, objfile
);
2735 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2736 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2737 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * nfn_fields
);
2738 memset (TYPE_FN_FIELDLISTS (type
), 0,
2739 sizeof (struct fn_fieldlist
) * nfn_fields
);
2740 TYPE_NFN_FIELDS (type
) = nfn_fields
;
2741 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2747 /* Special GNU C++ name.
2749 Returns 1 for success, 0 for failure. "failure" means that we can't
2750 keep parsing and it's time for error_type(). */
2753 read_cpp_abbrev (fip
, pp
, type
, objfile
)
2754 struct field_info
*fip
;
2757 struct objfile
*objfile
;
2762 struct type
*context
;
2772 /* At this point, *pp points to something like "22:23=*22...",
2773 where the type number before the ':' is the "context" and
2774 everything after is a regular type definition. Lookup the
2775 type, find it's name, and construct the field name. */
2777 context
= read_type (pp
, objfile
);
2781 case 'f': /* $vf -- a virtual function table pointer */
2782 fip
->list
->field
.name
=
2783 obconcat (&objfile
->type_obstack
, vptr_name
, "", "");
2786 case 'b': /* $vb -- a virtual bsomethingorother */
2787 name
= type_name_no_tag (context
);
2790 complain (&invalid_cpp_type_complaint
, symnum
);
2793 fip
->list
->field
.name
=
2794 obconcat (&objfile
->type_obstack
, vb_name
, name
, "");
2798 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2799 fip
->list
->field
.name
=
2800 obconcat (&objfile
->type_obstack
,
2801 "INVALID_CPLUSPLUS_ABBREV", "", "");
2805 /* At this point, *pp points to the ':'. Skip it and read the
2811 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2814 fip
->list
->field
.type
= read_type (pp
, objfile
);
2816 (*pp
)++; /* Skip the comma. */
2822 fip
->list
->field
.bitpos
= read_huge_number (pp
, ';', &nbits
);
2826 /* This field is unpacked. */
2827 fip
->list
->field
.bitsize
= 0;
2828 fip
->list
->visibility
= VISIBILITY_PRIVATE
;
2832 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2833 /* We have no idea what syntax an unrecognized abbrev would have, so
2834 better return 0. If we returned 1, we would need to at least advance
2835 *pp to avoid an infinite loop. */
2842 read_one_struct_field (fip
, pp
, p
, type
, objfile
)
2843 struct field_info
*fip
;
2847 struct objfile
*objfile
;
2849 /* The following is code to work around cfront generated stabs.
2850 The stabs contains full mangled name for each field.
2851 We try to demangle the name and extract the field name out of it.
2853 if (ARM_DEMANGLING
&& current_subfile
->language
== language_cplus
)
2859 dem
= cplus_demangle (*pp
, DMGL_ANSI
| DMGL_PARAMS
);
2862 dem_p
= strrchr (dem
, ':');
2863 if (dem_p
!= 0 && *(dem_p
-1)==':')
2865 fip
->list
->field
.name
=
2866 obsavestring (dem_p
, strlen(dem_p
), &objfile
-> type_obstack
);
2870 fip
->list
->field
.name
=
2871 obsavestring (*pp
, p
- *pp
, &objfile
-> type_obstack
);
2875 /* end of code for cfront work around */
2878 fip
-> list
-> field
.name
=
2879 obsavestring (*pp
, p
- *pp
, &objfile
-> type_obstack
);
2882 /* This means we have a visibility for a field coming. */
2886 fip
-> list
-> visibility
= *(*pp
)++;
2890 /* normal dbx-style format, no explicit visibility */
2891 fip
-> list
-> visibility
= VISIBILITY_PUBLIC
;
2894 fip
-> list
-> field
.type
= read_type (pp
, objfile
);
2899 /* Possible future hook for nested types. */
2902 fip
-> list
-> field
.bitpos
= (long)-2; /* nested type */
2908 /* Static class member. */
2909 fip
-> list
-> field
.bitpos
= (long) -1;
2915 fip
-> list
-> field
.bitsize
= (long) savestring (*pp
, p
- *pp
);
2919 else if (**pp
!= ',')
2921 /* Bad structure-type format. */
2922 complain (&stabs_general_complaint
, "bad structure-type format");
2926 (*pp
)++; /* Skip the comma. */
2930 fip
-> list
-> field
.bitpos
= read_huge_number (pp
, ',', &nbits
);
2933 complain (&stabs_general_complaint
, "bad structure-type format");
2936 fip
-> list
-> field
.bitsize
= read_huge_number (pp
, ';', &nbits
);
2939 complain (&stabs_general_complaint
, "bad structure-type format");
2944 if (fip
-> list
-> field
.bitpos
== 0 && fip
-> list
-> field
.bitsize
== 0)
2946 /* This can happen in two cases: (1) at least for gcc 2.4.5 or so,
2947 it is a field which has been optimized out. The correct stab for
2948 this case is to use VISIBILITY_IGNORE, but that is a recent
2949 invention. (2) It is a 0-size array. For example
2950 union { int num; char str[0]; } foo. Printing "<no value>" for
2951 str in "p foo" is OK, since foo.str (and thus foo.str[3])
2952 will continue to work, and a 0-size array as a whole doesn't
2953 have any contents to print.
2955 I suspect this probably could also happen with gcc -gstabs (not
2956 -gstabs+) for static fields, and perhaps other C++ extensions.
2957 Hopefully few people use -gstabs with gdb, since it is intended
2958 for dbx compatibility. */
2960 /* Ignore this field. */
2961 fip
-> list
-> visibility
= VISIBILITY_IGNORE
;
2965 /* Detect an unpacked field and mark it as such.
2966 dbx gives a bit size for all fields.
2967 Note that forward refs cannot be packed,
2968 and treat enums as if they had the width of ints. */
2970 if (TYPE_CODE (fip
-> list
-> field
.type
) != TYPE_CODE_INT
2971 && TYPE_CODE (fip
-> list
-> field
.type
) != TYPE_CODE_BOOL
2972 && TYPE_CODE (fip
-> list
-> field
.type
) != TYPE_CODE_ENUM
)
2974 fip
-> list
-> field
.bitsize
= 0;
2976 if ((fip
-> list
-> field
.bitsize
2977 == TARGET_CHAR_BIT
* TYPE_LENGTH (fip
-> list
-> field
.type
)
2978 || (TYPE_CODE (fip
-> list
-> field
.type
) == TYPE_CODE_ENUM
2979 && (fip
-> list
-> field
.bitsize
2984 fip
-> list
-> field
.bitpos
% 8 == 0)
2986 fip
-> list
-> field
.bitsize
= 0;
2992 /* Read struct or class data fields. They have the form:
2994 NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
2996 At the end, we see a semicolon instead of a field.
2998 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
3001 The optional VISIBILITY is one of:
3003 '/0' (VISIBILITY_PRIVATE)
3004 '/1' (VISIBILITY_PROTECTED)
3005 '/2' (VISIBILITY_PUBLIC)
3006 '/9' (VISIBILITY_IGNORE)
3008 or nothing, for C style fields with public visibility.
3010 Returns 1 for success, 0 for failure. */
3013 read_struct_fields (fip
, pp
, type
, objfile
)
3014 struct field_info
*fip
;
3017 struct objfile
*objfile
;
3020 struct nextfield
*new;
3022 /* We better set p right now, in case there are no fields at all... */
3026 /* Read each data member type until we find the terminating ';' at the end of
3027 the data member list, or break for some other reason such as finding the
3028 start of the member function list. */
3032 if (os9k_stabs
&& **pp
== ',') break;
3033 STABS_CONTINUE (pp
, objfile
);
3034 /* Get space to record the next field's data. */
3035 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3036 make_cleanup (free
, new);
3037 memset (new, 0, sizeof (struct nextfield
));
3038 new -> next
= fip
-> list
;
3041 /* Get the field name. */
3044 /* If is starts with CPLUS_MARKER it is a special abbreviation,
3045 unless the CPLUS_MARKER is followed by an underscore, in
3046 which case it is just the name of an anonymous type, which we
3047 should handle like any other type name. */
3049 if (is_cplus_marker (p
[0]) && p
[1] != '_')
3051 if (!read_cpp_abbrev (fip
, pp
, type
, objfile
))
3056 /* Look for the ':' that separates the field name from the field
3057 values. Data members are delimited by a single ':', while member
3058 functions are delimited by a pair of ':'s. When we hit the member
3059 functions (if any), terminate scan loop and return. */
3061 while (*p
!= ':' && *p
!= '\0')
3068 /* Check to see if we have hit the member functions yet. */
3073 read_one_struct_field (fip
, pp
, p
, type
, objfile
);
3075 if (p
[0] == ':' && p
[1] == ':')
3077 /* chill the list of fields: the last entry (at the head) is a
3078 partially constructed entry which we now scrub. */
3079 fip
-> list
= fip
-> list
-> next
;
3084 /* The stabs for C++ derived classes contain baseclass information which
3085 is marked by a '!' character after the total size. This function is
3086 called when we encounter the baseclass marker, and slurps up all the
3087 baseclass information.
3089 Immediately following the '!' marker is the number of base classes that
3090 the class is derived from, followed by information for each base class.
3091 For each base class, there are two visibility specifiers, a bit offset
3092 to the base class information within the derived class, a reference to
3093 the type for the base class, and a terminating semicolon.
3095 A typical example, with two base classes, would be "!2,020,19;0264,21;".
3097 Baseclass information marker __________________|| | | | | | |
3098 Number of baseclasses __________________________| | | | | | |
3099 Visibility specifiers (2) ________________________| | | | | |
3100 Offset in bits from start of class _________________| | | | |
3101 Type number for base class ___________________________| | | |
3102 Visibility specifiers (2) _______________________________| | |
3103 Offset in bits from start of class ________________________| |
3104 Type number of base class ____________________________________|
3106 Return 1 for success, 0 for (error-type-inducing) failure. */
3109 read_baseclasses (fip
, pp
, type
, objfile
)
3110 struct field_info
*fip
;
3113 struct objfile
*objfile
;
3116 struct nextfield
*new;
3124 /* Skip the '!' baseclass information marker. */
3128 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3131 TYPE_N_BASECLASSES (type
) = read_huge_number (pp
, ',', &nbits
);
3137 /* Some stupid compilers have trouble with the following, so break
3138 it up into simpler expressions. */
3139 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*)
3140 TYPE_ALLOC (type
, B_BYTES (TYPE_N_BASECLASSES (type
)));
3143 int num_bytes
= B_BYTES (TYPE_N_BASECLASSES (type
));
3146 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
3147 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
3151 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), TYPE_N_BASECLASSES (type
));
3153 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
3155 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3156 make_cleanup (free
, new);
3157 memset (new, 0, sizeof (struct nextfield
));
3158 new -> next
= fip
-> list
;
3160 new -> field
.bitsize
= 0; /* this should be an unpacked field! */
3162 STABS_CONTINUE (pp
, objfile
);
3166 /* Nothing to do. */
3169 SET_TYPE_FIELD_VIRTUAL (type
, i
);
3172 /* Unknown character. Complain and treat it as non-virtual. */
3174 static struct complaint msg
= {
3175 "Unknown virtual character `%c' for baseclass", 0, 0};
3176 complain (&msg
, **pp
);
3181 new -> visibility
= *(*pp
)++;
3182 switch (new -> visibility
)
3184 case VISIBILITY_PRIVATE
:
3185 case VISIBILITY_PROTECTED
:
3186 case VISIBILITY_PUBLIC
:
3189 /* Bad visibility format. Complain and treat it as
3192 static struct complaint msg
= {
3193 "Unknown visibility `%c' for baseclass", 0, 0};
3194 complain (&msg
, new -> visibility
);
3195 new -> visibility
= VISIBILITY_PUBLIC
;
3202 /* The remaining value is the bit offset of the portion of the object
3203 corresponding to this baseclass. Always zero in the absence of
3204 multiple inheritance. */
3206 new -> field
.bitpos
= read_huge_number (pp
, ',', &nbits
);
3211 /* The last piece of baseclass information is the type of the
3212 base class. Read it, and remember it's type name as this
3215 new -> field
.type
= read_type (pp
, objfile
);
3216 new -> field
.name
= type_name_no_tag (new -> field
.type
);
3218 /* skip trailing ';' and bump count of number of fields seen */
3227 /* The tail end of stabs for C++ classes that contain a virtual function
3228 pointer contains a tilde, a %, and a type number.
3229 The type number refers to the base class (possibly this class itself) which
3230 contains the vtable pointer for the current class.
3232 This function is called when we have parsed all the method declarations,
3233 so we can look for the vptr base class info. */
3236 read_tilde_fields (fip
, pp
, type
, objfile
)
3237 struct field_info
*fip
;
3240 struct objfile
*objfile
;
3244 STABS_CONTINUE (pp
, objfile
);
3246 /* If we are positioned at a ';', then skip it. */
3256 if (**pp
== '=' || **pp
== '+' || **pp
== '-')
3258 /* Obsolete flags that used to indicate the presence
3259 of constructors and/or destructors. */
3263 /* Read either a '%' or the final ';'. */
3264 if (*(*pp
)++ == '%')
3266 /* The next number is the type number of the base class
3267 (possibly our own class) which supplies the vtable for
3268 this class. Parse it out, and search that class to find
3269 its vtable pointer, and install those into TYPE_VPTR_BASETYPE
3270 and TYPE_VPTR_FIELDNO. */
3275 t
= read_type (pp
, objfile
);
3277 while (*p
!= '\0' && *p
!= ';')
3283 /* Premature end of symbol. */
3287 TYPE_VPTR_BASETYPE (type
) = t
;
3288 if (type
== t
) /* Our own class provides vtbl ptr */
3290 for (i
= TYPE_NFIELDS (t
) - 1;
3291 i
>= TYPE_N_BASECLASSES (t
);
3294 if (! strncmp (TYPE_FIELD_NAME (t
, i
), vptr_name
,
3295 sizeof (vptr_name
) - 1))
3297 TYPE_VPTR_FIELDNO (type
) = i
;
3301 /* Virtual function table field not found. */
3302 complain (&vtbl_notfound_complaint
, TYPE_NAME (type
));
3307 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
3318 attach_fn_fields_to_type (fip
, type
)
3319 struct field_info
*fip
;
3320 register struct type
*type
;
3324 for (n
= TYPE_NFN_FIELDS (type
);
3325 fip
-> fnlist
!= NULL
;
3326 fip
-> fnlist
= fip
-> fnlist
-> next
)
3328 --n
; /* Circumvent Sun3 compiler bug */
3329 TYPE_FN_FIELDLISTS (type
)[n
] = fip
-> fnlist
-> fn_fieldlist
;
3334 /* read cfront class static data.
3335 pp points to string starting with the list of static data
3336 eg: A:ZcA;1@Bpub v2@Bvirpri;__ct__1AFv func__1AFv *sfunc__1AFv ;as__1A ;;
3339 A:ZcA;;foopri__1AFv foopro__1AFv __ct__1AFv __ct__1AFRC1A foopub__1AFv ;;;
3344 read_cfront_static_fields(fip
, pp
, type
, objfile
)
3345 struct field_info
*fip
;
3348 struct objfile
*objfile
;
3350 int nfields
= TYPE_NFIELDS(type
);
3352 struct nextfield
* new;
3355 struct symbol
* ref_static
=0;
3357 if (**pp
==';') /* no static data; return */
3363 /* Process each field in the list until we find the terminating ";" */
3365 /* eg: p = "as__1A ;;;" */
3366 STABS_CONTINUE (pp
, objfile
); /* handle \\ */
3367 while (**pp
!=';' && (sname
= get_substring(pp
,' '),sname
))
3369 ref_static
= lookup_symbol (sname
, 0, VAR_NAMESPACE
, 0, 0); /*demangled_name*/
3372 static struct complaint msg
= {"\
3373 Unable to find symbol for static data field %s\n",
3375 complain (&msg
, sname
);
3378 stype
= SYMBOL_TYPE(ref_static
);
3380 /* allocate a new fip */
3381 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3382 make_cleanup (free
, new);
3383 memset (new, 0, sizeof (struct nextfield
));
3384 new -> next
= fip
-> list
;
3387 /* set visibility */
3388 /* FIXME! no way to tell visibility from stabs??? */
3389 new -> visibility
= VISIBILITY_PUBLIC
;
3391 /* set field info into fip */
3392 fip
-> list
-> field
.type
= stype
;
3394 /* set bitpos & bitsize */
3395 fip
-> list
-> field
.bitpos
= (long) -1; /* -1 signifies a static member */
3396 /* YUK! what a hack! bitsize used for physname when field is static */
3397 fip
-> list
-> field
.bitsize
= (long) savestring (sname
, strlen(sname
));
3399 /* set name field */
3400 /* The following is code to work around cfront generated stabs.
3401 The stabs contains full mangled name for each field.
3402 We try to demangle the name and extract the field name out of it.
3407 dem
= cplus_demangle (sname
, DMGL_ANSI
| DMGL_PARAMS
);
3410 dem_p
= strrchr (dem
, ':');
3411 if (dem_p
!= 0 && *(dem_p
-1)==':')
3413 fip
->list
->field
.name
=
3414 obsavestring (dem_p
, strlen(dem_p
), &objfile
-> type_obstack
);
3418 fip
->list
->field
.name
=
3419 obsavestring (sname
, strlen(sname
), &objfile
-> type_obstack
);
3421 } /* end of code for cfront work around */
3422 } /* loop again for next static field */
3426 /* Copy structure fields to fip so attach_fields_to_type will work.
3427 type has already been created with the initial instance data fields.
3428 Now we want to be able to add the other members to the class,
3429 so we want to add them back to the fip and reattach them again
3430 once we have collected all the class members. */
3433 copy_cfront_struct_fields(fip
, type
, objfile
)
3434 struct field_info
*fip
;
3436 struct objfile
*objfile
;
3438 int nfields
= TYPE_NFIELDS(type
);
3440 struct nextfield
* new;
3442 /* Copy the fields into the list of fips and reset the types
3443 to remove the old fields */
3445 for (i
=0; i
<nfields
; i
++)
3447 /* allocate a new fip */
3448 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3449 make_cleanup (free
, new);
3450 memset (new, 0, sizeof (struct nextfield
));
3451 new -> next
= fip
-> list
;
3454 /* copy field info into fip */
3455 new -> field
= TYPE_FIELD (type
, i
);
3456 /* set visibility */
3457 if (TYPE_FIELD_PROTECTED (type
, i
))
3458 new -> visibility
= VISIBILITY_PROTECTED
;
3459 else if (TYPE_FIELD_PRIVATE (type
, i
))
3460 new -> visibility
= VISIBILITY_PRIVATE
;
3462 new -> visibility
= VISIBILITY_PUBLIC
;
3464 /* Now delete the fields from the type since we will be
3465 allocing new space once we get the rest of the fields
3466 in attach_fields_to_type.
3467 The pointer TYPE_FIELDS(type) is left dangling but should
3468 be freed later by objstack_free */
3469 TYPE_FIELDS (type
)=0;
3470 TYPE_NFIELDS (type
) = 0;
3475 /* Create the vector of fields, and record how big it is.
3476 We need this info to record proper virtual function table information
3477 for this class's virtual functions. */
3480 attach_fields_to_type (fip
, type
, objfile
)
3481 struct field_info
*fip
;
3482 register struct type
*type
;
3483 struct objfile
*objfile
;
3485 register int nfields
= 0;
3486 register int non_public_fields
= 0;
3487 register struct nextfield
*scan
;
3489 /* Count up the number of fields that we have, as well as taking note of
3490 whether or not there are any non-public fields, which requires us to
3491 allocate and build the private_field_bits and protected_field_bits
3494 for (scan
= fip
-> list
; scan
!= NULL
; scan
= scan
-> next
)
3497 if (scan
-> visibility
!= VISIBILITY_PUBLIC
)
3499 non_public_fields
++;
3503 /* Now we know how many fields there are, and whether or not there are any
3504 non-public fields. Record the field count, allocate space for the
3505 array of fields, and create blank visibility bitfields if necessary. */
3507 TYPE_NFIELDS (type
) = nfields
;
3508 TYPE_FIELDS (type
) = (struct field
*)
3509 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
3510 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
3512 if (non_public_fields
)
3514 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3516 TYPE_FIELD_PRIVATE_BITS (type
) =
3517 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3518 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
3520 TYPE_FIELD_PROTECTED_BITS (type
) =
3521 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3522 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
3524 TYPE_FIELD_IGNORE_BITS (type
) =
3525 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3526 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
3529 /* Copy the saved-up fields into the field vector. Start from the head
3530 of the list, adding to the tail of the field array, so that they end
3531 up in the same order in the array in which they were added to the list. */
3533 while (nfields
-- > 0)
3535 TYPE_FIELD (type
, nfields
) = fip
-> list
-> field
;
3536 switch (fip
-> list
-> visibility
)
3538 case VISIBILITY_PRIVATE
:
3539 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
3542 case VISIBILITY_PROTECTED
:
3543 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
3546 case VISIBILITY_IGNORE
:
3547 SET_TYPE_FIELD_IGNORE (type
, nfields
);
3550 case VISIBILITY_PUBLIC
:
3554 /* Unknown visibility. Complain and treat it as public. */
3556 static struct complaint msg
= {
3557 "Unknown visibility `%c' for field", 0, 0};
3558 complain (&msg
, fip
-> list
-> visibility
);
3562 fip
-> list
= fip
-> list
-> next
;
3567 /* Read the description of a structure (or union type) and return an object
3568 describing the type.
3570 PP points to a character pointer that points to the next unconsumed token
3571 in the the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
3572 *PP will point to "4a:1,0,32;;".
3574 TYPE points to an incomplete type that needs to be filled in.
3576 OBJFILE points to the current objfile from which the stabs information is
3577 being read. (Note that it is redundant in that TYPE also contains a pointer
3578 to this same objfile, so it might be a good idea to eliminate it. FIXME).
3581 static struct type
*
3582 read_struct_type (pp
, type
, objfile
)
3585 struct objfile
*objfile
;
3587 struct cleanup
*back_to
;
3588 struct field_info fi
;
3593 back_to
= make_cleanup (null_cleanup
, 0);
3595 INIT_CPLUS_SPECIFIC (type
);
3596 TYPE_FLAGS (type
) &= ~TYPE_FLAG_STUB
;
3598 /* First comes the total size in bytes. */
3602 TYPE_LENGTH (type
) = read_huge_number (pp
, 0, &nbits
);
3604 return error_type (pp
, objfile
);
3607 /* Now read the baseclasses, if any, read the regular C struct or C++
3608 class member fields, attach the fields to the type, read the C++
3609 member functions, attach them to the type, and then read any tilde
3610 field (baseclass specifier for the class holding the main vtable). */
3612 if (!read_baseclasses (&fi
, pp
, type
, objfile
)
3613 || !read_struct_fields (&fi
, pp
, type
, objfile
)
3614 || !attach_fields_to_type (&fi
, type
, objfile
)
3615 || !read_member_functions (&fi
, pp
, type
, objfile
)
3616 || !attach_fn_fields_to_type (&fi
, type
)
3617 || !read_tilde_fields (&fi
, pp
, type
, objfile
))
3619 type
= error_type (pp
, objfile
);
3622 do_cleanups (back_to
);
3626 /* Read a definition of an array type,
3627 and create and return a suitable type object.
3628 Also creates a range type which represents the bounds of that
3631 static struct type
*
3632 read_array_type (pp
, type
, objfile
)
3634 register struct type
*type
;
3635 struct objfile
*objfile
;
3637 struct type
*index_type
, *element_type
, *range_type
;
3642 /* Format of an array type:
3643 "ar<index type>;lower;upper;<array_contents_type>".
3644 OS9000: "arlower,upper;<array_contents_type>".
3646 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
3647 for these, produce a type like float[][]. */
3650 index_type
= builtin_type_int
;
3653 index_type
= read_type (pp
, objfile
);
3655 /* Improper format of array type decl. */
3656 return error_type (pp
, objfile
);
3660 if (!(**pp
>= '0' && **pp
<= '9') && **pp
!= '-')
3665 lower
= read_huge_number (pp
, os9k_stabs
? ',' : ';', &nbits
);
3667 return error_type (pp
, objfile
);
3669 if (!(**pp
>= '0' && **pp
<= '9') && **pp
!= '-')
3674 upper
= read_huge_number (pp
, ';', &nbits
);
3676 return error_type (pp
, objfile
);
3678 element_type
= read_type (pp
, objfile
);
3687 create_range_type ((struct type
*) NULL
, index_type
, lower
, upper
);
3688 type
= create_array_type (type
, element_type
, range_type
);
3694 /* Read a definition of an enumeration type,
3695 and create and return a suitable type object.
3696 Also defines the symbols that represent the values of the type. */
3698 static struct type
*
3699 read_enum_type (pp
, type
, objfile
)
3701 register struct type
*type
;
3702 struct objfile
*objfile
;
3707 register struct symbol
*sym
;
3709 struct pending
**symlist
;
3710 struct pending
*osyms
, *syms
;
3713 int unsigned_enum
= 1;
3716 /* FIXME! The stabs produced by Sun CC merrily define things that ought
3717 to be file-scope, between N_FN entries, using N_LSYM. What's a mother
3718 to do? For now, force all enum values to file scope. */
3719 if (within_function
)
3720 symlist
= &local_symbols
;
3723 symlist
= &file_symbols
;
3725 o_nsyms
= osyms
? osyms
->nsyms
: 0;
3729 /* Size. Perhaps this does not have to be conditionalized on
3730 os9k_stabs (assuming the name of an enum constant can't start
3732 read_huge_number (pp
, 0, &nbits
);
3734 return error_type (pp
, objfile
);
3737 /* The aix4 compiler emits an extra field before the enum members;
3738 my guess is it's a type of some sort. Just ignore it. */
3741 /* Skip over the type. */
3745 /* Skip over the colon. */
3749 /* Read the value-names and their values.
3750 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
3751 A semicolon or comma instead of a NAME means the end. */
3752 while (**pp
&& **pp
!= ';' && **pp
!= ',')
3754 STABS_CONTINUE (pp
, objfile
);
3756 while (*p
!= ':') p
++;
3757 name
= obsavestring (*pp
, p
- *pp
, &objfile
-> symbol_obstack
);
3759 n
= read_huge_number (pp
, ',', &nbits
);
3761 return error_type (pp
, objfile
);
3763 sym
= (struct symbol
*)
3764 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
3765 memset (sym
, 0, sizeof (struct symbol
));
3766 SYMBOL_NAME (sym
) = name
;
3767 SYMBOL_LANGUAGE (sym
) = current_subfile
-> language
;
3768 SYMBOL_CLASS (sym
) = LOC_CONST
;
3769 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
3770 SYMBOL_VALUE (sym
) = n
;
3773 add_symbol_to_list (sym
, symlist
);
3778 (*pp
)++; /* Skip the semicolon. */
3780 /* Now fill in the fields of the type-structure. */
3782 TYPE_LENGTH (type
) = TARGET_INT_BIT
/ HOST_CHAR_BIT
;
3783 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
3784 TYPE_FLAGS (type
) &= ~TYPE_FLAG_STUB
;
3786 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
3787 TYPE_NFIELDS (type
) = nsyms
;
3788 TYPE_FIELDS (type
) = (struct field
*)
3789 TYPE_ALLOC (type
, sizeof (struct field
) * nsyms
);
3790 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nsyms
);
3792 /* Find the symbols for the values and put them into the type.
3793 The symbols can be found in the symlist that we put them on
3794 to cause them to be defined. osyms contains the old value
3795 of that symlist; everything up to there was defined by us. */
3796 /* Note that we preserve the order of the enum constants, so
3797 that in something like "enum {FOO, LAST_THING=FOO}" we print
3798 FOO, not LAST_THING. */
3800 for (syms
= *symlist
, n
= nsyms
- 1; syms
; syms
= syms
->next
)
3802 int last
= syms
== osyms
? o_nsyms
: 0;
3803 int j
= syms
->nsyms
;
3804 for (; --j
>= last
; --n
)
3806 struct symbol
*xsym
= syms
->symbol
[j
];
3807 SYMBOL_TYPE (xsym
) = type
;
3808 TYPE_FIELD_NAME (type
, n
) = SYMBOL_NAME (xsym
);
3809 TYPE_FIELD_VALUE (type
, n
) = 0;
3810 TYPE_FIELD_BITPOS (type
, n
) = SYMBOL_VALUE (xsym
);
3811 TYPE_FIELD_BITSIZE (type
, n
) = 0;
3820 /* Sun's ACC uses a somewhat saner method for specifying the builtin
3821 typedefs in every file (for int, long, etc):
3823 type = b <signed> <width>; <offset>; <nbits>
3824 signed = u or s. Possible c in addition to u or s (for char?).
3825 offset = offset from high order bit to start bit of type.
3826 width is # bytes in object of this type, nbits is # bits in type.
3828 The width/offset stuff appears to be for small objects stored in
3829 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
3832 static struct type
*
3833 read_sun_builtin_type (pp
, typenums
, objfile
)
3836 struct objfile
*objfile
;
3851 return error_type (pp
, objfile
);
3855 /* For some odd reason, all forms of char put a c here. This is strange
3856 because no other type has this honor. We can safely ignore this because
3857 we actually determine 'char'acterness by the number of bits specified in
3863 /* The first number appears to be the number of bytes occupied
3864 by this type, except that unsigned short is 4 instead of 2.
3865 Since this information is redundant with the third number,
3866 we will ignore it. */
3867 read_huge_number (pp
, ';', &nbits
);
3869 return error_type (pp
, objfile
);
3871 /* The second number is always 0, so ignore it too. */
3872 read_huge_number (pp
, ';', &nbits
);
3874 return error_type (pp
, objfile
);
3876 /* The third number is the number of bits for this type. */
3877 type_bits
= read_huge_number (pp
, 0, &nbits
);
3879 return error_type (pp
, objfile
);
3880 /* The type *should* end with a semicolon. If it are embedded
3881 in a larger type the semicolon may be the only way to know where
3882 the type ends. If this type is at the end of the stabstring we
3883 can deal with the omitted semicolon (but we don't have to like
3884 it). Don't bother to complain(), Sun's compiler omits the semicolon
3890 return init_type (TYPE_CODE_VOID
, 1,
3891 signed_type
? 0 : TYPE_FLAG_UNSIGNED
, (char *)NULL
,
3894 return init_type (TYPE_CODE_INT
,
3895 type_bits
/ TARGET_CHAR_BIT
,
3896 signed_type
? 0 : TYPE_FLAG_UNSIGNED
, (char *)NULL
,
3900 static struct type
*
3901 read_sun_floating_type (pp
, typenums
, objfile
)
3904 struct objfile
*objfile
;
3910 /* The first number has more details about the type, for example
3912 details
= read_huge_number (pp
, ';', &nbits
);
3914 return error_type (pp
, objfile
);
3916 /* The second number is the number of bytes occupied by this type */
3917 nbytes
= read_huge_number (pp
, ';', &nbits
);
3919 return error_type (pp
, objfile
);
3921 if (details
== NF_COMPLEX
|| details
== NF_COMPLEX16
3922 || details
== NF_COMPLEX32
)
3923 /* This is a type we can't handle, but we do know the size.
3924 We also will be able to give it a name. */
3925 return init_type (TYPE_CODE_ERROR
, nbytes
, 0, NULL
, objfile
);
3927 return init_type (TYPE_CODE_FLT
, nbytes
, 0, NULL
, objfile
);
3930 /* Read a number from the string pointed to by *PP.
3931 The value of *PP is advanced over the number.
3932 If END is nonzero, the character that ends the
3933 number must match END, or an error happens;
3934 and that character is skipped if it does match.
3935 If END is zero, *PP is left pointing to that character.
3937 If the number fits in a long, set *BITS to 0 and return the value.
3938 If not, set *BITS to be the number of bits in the number and return 0.
3940 If encounter garbage, set *BITS to -1 and return 0. */
3943 read_huge_number (pp
, end
, bits
)
3963 /* Leading zero means octal. GCC uses this to output values larger
3964 than an int (because that would be hard in decimal). */
3972 upper_limit
= ULONG_MAX
/ radix
;
3974 upper_limit
= LONG_MAX
/ radix
;
3976 while ((c
= *p
++) >= '0' && c
< ('0' + radix
))
3978 if (n
<= upper_limit
)
3981 n
+= c
- '0'; /* FIXME this overflows anyway */
3986 /* This depends on large values being output in octal, which is
3993 /* Ignore leading zeroes. */
3997 else if (c
== '2' || c
== '3')
4023 /* Large decimal constants are an error (because it is hard to
4024 count how many bits are in them). */
4030 /* -0x7f is the same as 0x80. So deal with it by adding one to
4031 the number of bits. */
4043 /* It's *BITS which has the interesting information. */
4047 static struct type
*
4048 read_range_type (pp
, typenums
, objfile
)
4051 struct objfile
*objfile
;
4053 char *orig_pp
= *pp
;
4058 struct type
*result_type
;
4059 struct type
*index_type
= NULL
;
4061 /* First comes a type we are a subrange of.
4062 In C it is usually 0, 1 or the type being defined. */
4063 if (read_type_number (pp
, rangenums
) != 0)
4064 return error_type (pp
, objfile
);
4065 self_subrange
= (rangenums
[0] == typenums
[0] &&
4066 rangenums
[1] == typenums
[1]);
4071 index_type
= read_type (pp
, objfile
);
4074 /* A semicolon should now follow; skip it. */
4078 /* The remaining two operands are usually lower and upper bounds
4079 of the range. But in some special cases they mean something else. */
4080 n2
= read_huge_number (pp
, ';', &n2bits
);
4081 n3
= read_huge_number (pp
, ';', &n3bits
);
4083 if (n2bits
== -1 || n3bits
== -1)
4084 return error_type (pp
, objfile
);
4087 goto handle_true_range
;
4089 /* If limits are huge, must be large integral type. */
4090 if (n2bits
!= 0 || n3bits
!= 0)
4092 char got_signed
= 0;
4093 char got_unsigned
= 0;
4094 /* Number of bits in the type. */
4097 /* Range from 0 to <large number> is an unsigned large integral type. */
4098 if ((n2bits
== 0 && n2
== 0) && n3bits
!= 0)
4103 /* Range from <large number> to <large number>-1 is a large signed
4104 integral type. Take care of the case where <large number> doesn't
4105 fit in a long but <large number>-1 does. */
4106 else if ((n2bits
!= 0 && n3bits
!= 0 && n2bits
== n3bits
+ 1)
4107 || (n2bits
!= 0 && n3bits
== 0
4108 && (n2bits
== sizeof (long) * HOST_CHAR_BIT
)
4115 if (got_signed
|| got_unsigned
)
4117 return init_type (TYPE_CODE_INT
, nbits
/ TARGET_CHAR_BIT
,
4118 got_unsigned
? TYPE_FLAG_UNSIGNED
: 0, NULL
,
4122 return error_type (pp
, objfile
);
4125 /* A type defined as a subrange of itself, with bounds both 0, is void. */
4126 if (self_subrange
&& n2
== 0 && n3
== 0)
4127 return init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
4129 /* If n3 is zero and n2 is positive, we want a floating type,
4130 and n2 is the width in bytes.
4132 Fortran programs appear to use this for complex types also,
4133 and they give no way to distinguish between double and single-complex!
4135 GDB does not have complex types.
4137 Just return the complex as a float of that size. It won't work right
4138 for the complex values, but at least it makes the file loadable. */
4140 if (n3
== 0 && n2
> 0)
4142 return init_type (TYPE_CODE_FLT
, n2
, 0, NULL
, objfile
);
4145 /* If the upper bound is -1, it must really be an unsigned int. */
4147 else if (n2
== 0 && n3
== -1)
4149 /* It is unsigned int or unsigned long. */
4150 /* GCC 2.3.3 uses this for long long too, but that is just a GDB 3.5
4151 compatibility hack. */
4152 return init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
4153 TYPE_FLAG_UNSIGNED
, NULL
, objfile
);
4156 /* Special case: char is defined (Who knows why) as a subrange of
4157 itself with range 0-127. */
4158 else if (self_subrange
&& n2
== 0 && n3
== 127)
4159 return init_type (TYPE_CODE_INT
, 1, 0, NULL
, objfile
);
4161 else if (current_symbol
&& SYMBOL_LANGUAGE (current_symbol
) == language_chill
4163 goto handle_true_range
;
4165 /* We used to do this only for subrange of self or subrange of int. */
4169 /* n3 actually gives the size. */
4170 return init_type (TYPE_CODE_INT
, - n3
, TYPE_FLAG_UNSIGNED
,
4173 return init_type (TYPE_CODE_INT
, 1, TYPE_FLAG_UNSIGNED
, NULL
, objfile
);
4175 return init_type (TYPE_CODE_INT
, 2, TYPE_FLAG_UNSIGNED
, NULL
, objfile
);
4177 /* -1 is used for the upper bound of (4 byte) "unsigned int" and
4178 "unsigned long", and we already checked for that,
4179 so don't need to test for it here. */
4181 /* I think this is for Convex "long long". Since I don't know whether
4182 Convex sets self_subrange, I also accept that particular size regardless
4183 of self_subrange. */
4184 else if (n3
== 0 && n2
< 0
4186 || n2
== - TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
))
4187 return init_type (TYPE_CODE_INT
, - n2
, 0, NULL
, objfile
);
4188 else if (n2
== -n3
-1)
4191 return init_type (TYPE_CODE_INT
, 1, 0, NULL
, objfile
);
4193 return init_type (TYPE_CODE_INT
, 2, 0, NULL
, objfile
);
4194 if (n3
== 0x7fffffff)
4195 return init_type (TYPE_CODE_INT
, 4, 0, NULL
, objfile
);
4198 /* We have a real range type on our hands. Allocate space and
4199 return a real pointer. */
4203 index_type
= builtin_type_int
;
4205 index_type
= *dbx_lookup_type (rangenums
);
4206 if (index_type
== NULL
)
4208 /* Does this actually ever happen? Is that why we are worrying
4209 about dealing with it rather than just calling error_type? */
4211 static struct type
*range_type_index
;
4213 complain (&range_type_base_complaint
, rangenums
[1]);
4214 if (range_type_index
== NULL
)
4216 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
4217 0, "range type index type", NULL
);
4218 index_type
= range_type_index
;
4221 result_type
= create_range_type ((struct type
*) NULL
, index_type
, n2
, n3
);
4222 return (result_type
);
4225 /* Read in an argument list. This is a list of types, separated by commas
4226 and terminated with END. Return the list of types read in, or (struct type
4227 **)-1 if there is an error. */
4229 static struct type
**
4230 read_args (pp
, end
, objfile
)
4233 struct objfile
*objfile
;
4235 /* FIXME! Remove this arbitrary limit! */
4236 struct type
*types
[1024], **rval
; /* allow for fns of 1023 parameters */
4242 /* Invalid argument list: no ','. */
4243 return (struct type
**)-1;
4245 STABS_CONTINUE (pp
, objfile
);
4246 types
[n
++] = read_type (pp
, objfile
);
4248 (*pp
)++; /* get past `end' (the ':' character) */
4252 rval
= (struct type
**) xmalloc (2 * sizeof (struct type
*));
4254 else if (TYPE_CODE (types
[n
-1]) != TYPE_CODE_VOID
)
4256 rval
= (struct type
**) xmalloc ((n
+ 1) * sizeof (struct type
*));
4257 memset (rval
+ n
, 0, sizeof (struct type
*));
4261 rval
= (struct type
**) xmalloc (n
* sizeof (struct type
*));
4263 memcpy (rval
, types
, n
* sizeof (struct type
*));
4267 /* Common block handling. */
4269 /* List of symbols declared since the last BCOMM. This list is a tail
4270 of local_symbols. When ECOMM is seen, the symbols on the list
4271 are noted so their proper addresses can be filled in later,
4272 using the common block base address gotten from the assembler
4275 static struct pending
*common_block
;
4276 static int common_block_i
;
4278 /* Name of the current common block. We get it from the BCOMM instead of the
4279 ECOMM to match IBM documentation (even though IBM puts the name both places
4280 like everyone else). */
4281 static char *common_block_name
;
4283 /* Process a N_BCOMM symbol. The storage for NAME is not guaranteed
4284 to remain after this function returns. */
4287 common_block_start (name
, objfile
)
4289 struct objfile
*objfile
;
4291 if (common_block_name
!= NULL
)
4293 static struct complaint msg
= {
4294 "Invalid symbol data: common block within common block",
4298 common_block
= local_symbols
;
4299 common_block_i
= local_symbols
? local_symbols
->nsyms
: 0;
4300 common_block_name
= obsavestring (name
, strlen (name
),
4301 &objfile
-> symbol_obstack
);
4304 /* Process a N_ECOMM symbol. */
4307 common_block_end (objfile
)
4308 struct objfile
*objfile
;
4310 /* Symbols declared since the BCOMM are to have the common block
4311 start address added in when we know it. common_block and
4312 common_block_i point to the first symbol after the BCOMM in
4313 the local_symbols list; copy the list and hang it off the
4314 symbol for the common block name for later fixup. */
4317 struct pending
*new = 0;
4318 struct pending
*next
;
4321 if (common_block_name
== NULL
)
4323 static struct complaint msg
= {"ECOMM symbol unmatched by BCOMM", 0, 0};
4328 sym
= (struct symbol
*)
4329 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
4330 memset (sym
, 0, sizeof (struct symbol
));
4331 /* Note: common_block_name already saved on symbol_obstack */
4332 SYMBOL_NAME (sym
) = common_block_name
;
4333 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
4335 /* Now we copy all the symbols which have been defined since the BCOMM. */
4337 /* Copy all the struct pendings before common_block. */
4338 for (next
= local_symbols
;
4339 next
!= NULL
&& next
!= common_block
;
4342 for (j
= 0; j
< next
->nsyms
; j
++)
4343 add_symbol_to_list (next
->symbol
[j
], &new);
4346 /* Copy however much of COMMON_BLOCK we need. If COMMON_BLOCK is
4347 NULL, it means copy all the local symbols (which we already did
4350 if (common_block
!= NULL
)
4351 for (j
= common_block_i
; j
< common_block
->nsyms
; j
++)
4352 add_symbol_to_list (common_block
->symbol
[j
], &new);
4354 SYMBOL_TYPE (sym
) = (struct type
*) new;
4356 /* Should we be putting local_symbols back to what it was?
4359 i
= hashname (SYMBOL_NAME (sym
));
4360 SYMBOL_VALUE_CHAIN (sym
) = global_sym_chain
[i
];
4361 global_sym_chain
[i
] = sym
;
4362 common_block_name
= NULL
;
4365 /* Add a common block's start address to the offset of each symbol
4366 declared to be in it (by being between a BCOMM/ECOMM pair that uses
4367 the common block name). */
4370 fix_common_block (sym
, valu
)
4374 struct pending
*next
= (struct pending
*) SYMBOL_TYPE (sym
);
4375 for ( ; next
; next
= next
->next
)
4378 for (j
= next
->nsyms
- 1; j
>= 0; j
--)
4379 SYMBOL_VALUE_ADDRESS (next
->symbol
[j
]) += valu
;
4385 /* What about types defined as forward references inside of a small lexical
4387 /* Add a type to the list of undefined types to be checked through
4388 once this file has been read in. */
4391 add_undefined_type (type
)
4394 if (undef_types_length
== undef_types_allocated
)
4396 undef_types_allocated
*= 2;
4397 undef_types
= (struct type
**)
4398 xrealloc ((char *) undef_types
,
4399 undef_types_allocated
* sizeof (struct type
*));
4401 undef_types
[undef_types_length
++] = type
;
4404 /* Go through each undefined type, see if it's still undefined, and fix it
4405 up if possible. We have two kinds of undefined types:
4407 TYPE_CODE_ARRAY: Array whose target type wasn't defined yet.
4408 Fix: update array length using the element bounds
4409 and the target type's length.
4410 TYPE_CODE_STRUCT, TYPE_CODE_UNION: Structure whose fields were not
4411 yet defined at the time a pointer to it was made.
4412 Fix: Do a full lookup on the struct/union tag. */
4414 cleanup_undefined_types ()
4418 for (type
= undef_types
; type
< undef_types
+ undef_types_length
; type
++)
4420 switch (TYPE_CODE (*type
))
4423 case TYPE_CODE_STRUCT
:
4424 case TYPE_CODE_UNION
:
4425 case TYPE_CODE_ENUM
:
4427 /* Check if it has been defined since. Need to do this here
4428 as well as in check_typedef to deal with the (legitimate in
4429 C though not C++) case of several types with the same name
4430 in different source files. */
4431 if (TYPE_FLAGS (*type
) & TYPE_FLAG_STUB
)
4433 struct pending
*ppt
;
4435 /* Name of the type, without "struct" or "union" */
4436 char *typename
= TYPE_TAG_NAME (*type
);
4438 if (typename
== NULL
)
4440 static struct complaint msg
= {"need a type name", 0, 0};
4444 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
4446 for (i
= 0; i
< ppt
->nsyms
; i
++)
4448 struct symbol
*sym
= ppt
->symbol
[i
];
4450 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
4451 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
4452 && (TYPE_CODE (SYMBOL_TYPE (sym
)) ==
4454 && STREQ (SYMBOL_NAME (sym
), typename
))
4456 memcpy (*type
, SYMBOL_TYPE (sym
),
4457 sizeof (struct type
));
4467 static struct complaint msg
= {"\
4468 GDB internal error. cleanup_undefined_types with bad type %d.", 0, 0};
4469 complain (&msg
, TYPE_CODE (*type
));
4475 undef_types_length
= 0;
4478 /* Scan through all of the global symbols defined in the object file,
4479 assigning values to the debugging symbols that need to be assigned
4480 to. Get these symbols from the minimal symbol table. */
4483 scan_file_globals (objfile
)
4484 struct objfile
*objfile
;
4487 struct minimal_symbol
*msymbol
;
4488 struct symbol
*sym
, *prev
;
4490 /* Avoid expensive loop through all minimal symbols if there are
4491 no unresolved symbols. */
4492 for (hash
= 0; hash
< HASHSIZE
; hash
++)
4494 if (global_sym_chain
[hash
])
4497 if (hash
>= HASHSIZE
)
4500 for (msymbol
= objfile
-> msymbols
;
4501 msymbol
&& SYMBOL_NAME (msymbol
) != NULL
;
4506 /* Skip static symbols. */
4507 switch (MSYMBOL_TYPE (msymbol
))
4519 /* Get the hash index and check all the symbols
4520 under that hash index. */
4522 hash
= hashname (SYMBOL_NAME (msymbol
));
4524 for (sym
= global_sym_chain
[hash
]; sym
;)
4526 if (SYMBOL_NAME (msymbol
)[0] == SYMBOL_NAME (sym
)[0] &&
4527 STREQ(SYMBOL_NAME (msymbol
) + 1, SYMBOL_NAME (sym
) + 1))
4529 /* Splice this symbol out of the hash chain and
4530 assign the value we have to it. */
4533 SYMBOL_VALUE_CHAIN (prev
) = SYMBOL_VALUE_CHAIN (sym
);
4537 global_sym_chain
[hash
] = SYMBOL_VALUE_CHAIN (sym
);
4540 /* Check to see whether we need to fix up a common block. */
4541 /* Note: this code might be executed several times for
4542 the same symbol if there are multiple references. */
4544 if (SYMBOL_CLASS (sym
) == LOC_BLOCK
)
4546 fix_common_block (sym
, SYMBOL_VALUE_ADDRESS (msymbol
));
4550 SYMBOL_VALUE_ADDRESS (sym
) = SYMBOL_VALUE_ADDRESS (msymbol
);
4553 SYMBOL_SECTION (sym
) = SYMBOL_SECTION (msymbol
);
4557 sym
= SYMBOL_VALUE_CHAIN (prev
);
4561 sym
= global_sym_chain
[hash
];
4567 sym
= SYMBOL_VALUE_CHAIN (sym
);
4572 /* Change the storage class of any remaining unresolved globals to
4573 LOC_UNRESOLVED and remove them from the chain. */
4574 for (hash
= 0; hash
< HASHSIZE
; hash
++)
4576 sym
= global_sym_chain
[hash
];
4580 sym
= SYMBOL_VALUE_CHAIN (sym
);
4582 /* Change the symbol address from the misleading chain value
4584 SYMBOL_VALUE_ADDRESS (prev
) = 0;
4586 /* Complain about unresolved common block symbols. */
4587 if (SYMBOL_CLASS (prev
) == LOC_STATIC
)
4588 SYMBOL_CLASS (prev
) = LOC_UNRESOLVED
;
4590 complain (&unresolved_sym_chain_complaint
,
4591 objfile
->name
, SYMBOL_NAME (prev
));
4594 memset (global_sym_chain
, 0, sizeof (global_sym_chain
));
4597 /* Initialize anything that needs initializing when starting to read
4598 a fresh piece of a symbol file, e.g. reading in the stuff corresponding
4606 /* Initialize anything that needs initializing when a completely new
4607 symbol file is specified (not just adding some symbols from another
4608 file, e.g. a shared library). */
4611 stabsread_new_init ()
4613 /* Empty the hash table of global syms looking for values. */
4614 memset (global_sym_chain
, 0, sizeof (global_sym_chain
));
4617 /* Initialize anything that needs initializing at the same time as
4618 start_symtab() is called. */
4622 global_stabs
= NULL
; /* AIX COFF */
4623 /* Leave FILENUM of 0 free for builtin types and this file's types. */
4624 n_this_object_header_files
= 1;
4625 type_vector_length
= 0;
4626 type_vector
= (struct type
**) 0;
4628 /* FIXME: If common_block_name is not already NULL, we should complain(). */
4629 common_block_name
= NULL
;
4634 /* Call after end_symtab() */
4640 free ((char *) type_vector
);
4643 type_vector_length
= 0;
4644 previous_stab_code
= 0;
4648 finish_global_stabs (objfile
)
4649 struct objfile
*objfile
;
4653 patch_block_stabs (global_symbols
, global_stabs
, objfile
);
4654 free ((PTR
) global_stabs
);
4655 global_stabs
= NULL
;
4659 /* Initializer for this module */
4662 _initialize_stabsread ()
4664 undef_types_allocated
= 20;
4665 undef_types_length
= 0;
4666 undef_types
= (struct type
**)
4667 xmalloc (undef_types_allocated
* sizeof (struct type
*));