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 obstack_copy0 (&objfile
->symbol_obstack
, name
, pp
- name
);
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 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
750 read_cfront_member_functions(fip
, pp
, type
, objfile
)
751 struct field_info
*fip
;
754 struct objfile
*objfile
;
756 /* This code extracted from read_member_functions
757 so as to do the similar thing for our funcs */
761 /* Total number of member functions defined in this class. If the class
762 defines two `f' functions, and one `g' function, then this will have
764 int total_length
= 0;
768 struct next_fnfield
*next
;
769 struct fn_field fn_field
;
771 struct type
*look_ahead_type
;
772 struct next_fnfieldlist
*new_fnlist
;
773 struct next_fnfield
*new_sublist
;
776 struct symbol
* ref_func
=0;
778 /* Process each list until we find something that is not a member function
779 or find the end of the functions. */
781 /* eg: p = "__ct__1AFv foo__1AFv ;;;" */
782 STABS_CONTINUE (pp
, objfile
); /* handle \\ */
783 while (**pp
!=';' && (fname
= get_substring(pp
,' '),fname
))
788 if (fname
[0]=='*') /* static member */
794 ref_func
= lookup_symbol (fname
, 0, VAR_NAMESPACE
, 0, 0); /*demangled_name*/
797 static struct complaint msg
= {"\
798 Unable to find function symbol for %s\n",
800 complain (&msg
, fname
);
804 look_ahead_type
= NULL
;
807 new_fnlist
= (struct next_fnfieldlist
*)
808 xmalloc (sizeof (struct next_fnfieldlist
));
809 make_cleanup (free
, new_fnlist
);
810 memset (new_fnlist
, 0, sizeof (struct next_fnfieldlist
));
812 /* The following is code to work around cfront generated stabs.
813 The stabs contains full mangled name for each field.
814 We try to demangle the name and extract the field name out of it. */
816 char *dem
, *dem_p
, *dem_args
;
818 dem
= cplus_demangle (fname
, DMGL_ANSI
| DMGL_PARAMS
);
821 dem_p
= strrchr (dem
, ':');
822 if (dem_p
!= 0 && *(dem_p
-1)==':')
824 /* get rid of args */
825 dem_args
= strchr (dem_p
, '(');
826 if (dem_args
== NULL
)
827 dem_len
= strlen(dem_p
);
829 dem_len
= dem_args
- dem_p
;
831 obsavestring (dem_p
, dem_len
, &objfile
-> type_obstack
);
836 obsavestring (fname
, strlen(fname
), &objfile
-> type_obstack
);
838 } /* end of code for cfront work around */
840 new_fnlist
-> fn_fieldlist
.name
= main_fn_name
;
842 /*-------------------------------------------------*/
843 /* Set up the sublists
844 Sublists are stuff like args, static, visibility, etc.
845 so in ARM, we have to set that info some other way.
846 Multiple sublists happen if overloading
847 eg: foo::26=##1;:;2A.;
848 In g++, we'd loop here thru all the sublists... */
850 (struct next_fnfield
*) xmalloc (sizeof (struct next_fnfield
));
851 make_cleanup (free
, new_sublist
);
852 memset (new_sublist
, 0, sizeof (struct next_fnfield
));
854 /* eat 1; from :;2A.; */
855 new_sublist
-> fn_field
.type
= SYMBOL_TYPE(ref_func
); /* normally takes a read_type */
856 /* make this type look like a method stub for gdb */
857 TYPE_FLAGS (new_sublist
-> fn_field
.type
) |= TYPE_FLAG_STUB
;
858 TYPE_CODE (new_sublist
-> fn_field
.type
) = TYPE_CODE_METHOD
;
860 /* If this is just a stub, then we don't have the real name here. */
861 if (TYPE_FLAGS (new_sublist
-> fn_field
.type
) & TYPE_FLAG_STUB
)
863 if (!TYPE_DOMAIN_TYPE (new_sublist
-> fn_field
.type
))
864 TYPE_DOMAIN_TYPE (new_sublist
-> fn_field
.type
) = type
;
865 new_sublist
-> fn_field
.is_stub
= 1;
867 /* physname used later in mangling; eg PFs_i,5 for foo__1aFPFs_i
868 physname gets strcat'd in order to recreate the onto mangled name */
869 pname
= get_cfront_method_physname(fname
);
870 new_sublist
-> fn_field
.physname
= savestring (pname
, strlen(pname
));
873 /* Set this member function's visibility fields.
874 Unable to distinguish access from stabs definition!
875 Assuming public for now. FIXME!
876 (for private, set new_sublist->fn_field.is_private = 1,
877 for public, set new_sublist->fn_field.is_protected = 1) */
879 /* Unable to distinguish const/volatile from stabs definition!
880 Assuming normal for now. FIXME!
881 new_sublist -> fn_field.is_const = 0;
882 new_sublist -> fn_field.is_volatile = 0; /* volatile not implemented in cfront */
884 /* set virtual/static function info
885 How to get vtable offsets ?
886 Assuming normal for now FIXME!!
887 For vtables, figure out from whence this virtual function came.
888 It may belong to virtual function table of
889 one of its baseclasses.
891 new_sublist -> fn_field.voffset = vtable offset,
892 new_sublist -> fn_field.fcontext = look_ahead_type;
893 where look_ahead_type is type of baseclass */
895 new_sublist
-> fn_field
.voffset
= VOFFSET_STATIC
;
896 else /* normal member function. */
897 new_sublist
-> fn_field
.voffset
= 0;
898 new_sublist
-> fn_field
.fcontext
= 0;
901 /* prepare new sublist */
902 new_sublist
-> next
= sublist
;
903 sublist
= new_sublist
;
905 /* In g++, we loop thu sublists - now we set from function */
907 new_fnlist
-> fn_fieldlist
.fn_fields
= (struct fn_field
*)
908 obstack_alloc (&objfile
-> type_obstack
,
909 sizeof (struct fn_field
) * length
);
910 memset (new_fnlist
-> fn_fieldlist
.fn_fields
, 0,
911 sizeof (struct fn_field
) * length
);
912 for (i
= length
; (i
--, sublist
); sublist
= sublist
-> next
)
914 new_fnlist
-> fn_fieldlist
.fn_fields
[i
] = sublist
-> fn_field
;
917 new_fnlist
-> fn_fieldlist
.length
= length
;
918 new_fnlist
-> next
= fip
-> fnlist
;
919 fip
-> fnlist
= new_fnlist
;
921 total_length
+= length
;
922 STABS_CONTINUE (pp
, objfile
); /* handle \\ */
927 /* type should already have space */
928 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
929 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * nfn_fields
);
930 memset (TYPE_FN_FIELDLISTS (type
), 0,
931 sizeof (struct fn_fieldlist
) * nfn_fields
);
932 TYPE_NFN_FIELDS (type
) = nfn_fields
;
933 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
936 /* end of scope for reading member func */
939 /* skip trailing ';' and bump count of number of fields seen */
947 /* This routine fixes up partial cfront types that were created
948 while parsing the stabs. The main need for this function is
949 to add information such as methods to classes.
950 Examples of "p": "sA;;__ct__1AFv foo__1AFv ;;;" */
952 resolve_cfront_continuation(objfile
, sym
, p
)
953 struct objfile
* objfile
;
957 struct symbol
* ref_sym
=0;
959 /* snarfed from read_struct_type */
960 struct field_info fi
;
961 struct field_info
* fip
= &fi
;
963 struct cleanup
*back_to
;
965 /* need to make sure that fi isn't gunna conflict with struct
966 in case struct already had some fnfs */
969 back_to
= make_cleanup (null_cleanup
, 0);
971 /* we only accept structs, classes and unions at the moment.
972 Other continuation types include t (typedef), r (long dbl), ...
973 We may want to add support for them as well;
974 right now they are handled by duplicating the symbol information
975 into the type information (see define_symbol) */
976 if (*p
!= 's' /* structs */
977 && *p
!= 'c' /* class */
978 && *p
!= 'u') /* union */
979 return; /* only handle C++ types */
982 /* get symbol typs name and validate
983 eg: p = "A;;__ct__1AFv foo__1AFv ;;;" */
984 sname
= get_substring(&p
,';');
985 if (!sname
|| strcmp(sname
,SYMBOL_NAME(sym
)))
986 error("Internal error: base symbol type name does not match\n");
988 /* find symbol's internal gdb reference */
989 ref_sym
= lookup_symbol (SYMBOL_NAME(sym
), 0, STRUCT_NAMESPACE
, 0, 0); /*demangled_name*/
990 /* This is the real sym that we want;
991 sym was a temp hack to make debugger happy */
992 /* ref_sym should already have space */
993 type
= SYMBOL_TYPE(ref_sym
);
996 /* Now read the baseclasses, if any, read the regular C struct or C++
997 class member fields, attach the fields to the type, read the C++
998 member functions, attach them to the type, and then read any tilde
999 field (baseclass specifier for the class holding the main vtable). */
1001 if (!read_cfront_baseclasses (&fi
, &p
, type
, objfile
)
1002 /* g++ does this next, but cfront already did this:
1003 || !read_struct_fields (&fi, &p, type, objfile) */
1004 || !copy_cfront_struct_fields (&fi
, type
, objfile
)
1005 || !read_cfront_member_functions (&fi
, &p
, type
, objfile
)
1006 || !read_cfront_static_fields(&fi
, &p
, type
, objfile
)
1007 || !attach_fields_to_type (&fi
, type
, objfile
)
1008 || !attach_fn_fields_to_type (&fi
, type
)
1009 /* g++ does this next, but cfront doesn't seem to have this:
1010 || !read_tilde_fields (&fi, &p, type, objfile) */
1013 type
= error_type (&p
, objfile
);
1016 do_cleanups (back_to
);
1018 /* End of code added to support parsing of ARM/Cfront stabs strings */
1023 define_symbol (valu
, string
, desc
, type
, objfile
)
1028 struct objfile
*objfile
;
1030 register struct symbol
*sym
;
1031 char *p
= (char *) strchr (string
, ':');
1036 /* We would like to eliminate nameless symbols, but keep their types.
1037 E.g. stab entry ":t10=*2" should produce a type 10, which is a pointer
1038 to type 2, but, should not create a symbol to address that type. Since
1039 the symbol will be nameless, there is no way any user can refer to it. */
1043 /* Ignore syms with empty names. */
1047 /* Ignore old-style symbols from cc -go */
1057 /* If a nameless stab entry, all we need is the type, not the symbol.
1058 e.g. ":t10=*2" or a nameless enum like " :T16=ered:0,green:1,blue:2,;" */
1059 nameless
= (p
== string
|| ((string
[0] == ' ') && (string
[1] == ':')));
1061 current_symbol
= sym
= (struct symbol
*)
1062 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
1063 memset (sym
, 0, sizeof (struct symbol
));
1065 switch (type
& N_TYPE
)
1068 SYMBOL_SECTION(sym
) = SECT_OFF_TEXT
;
1071 SYMBOL_SECTION(sym
) = SECT_OFF_DATA
;
1074 SYMBOL_SECTION(sym
) = SECT_OFF_BSS
;
1078 if (processing_gcc_compilation
)
1080 /* GCC 2.x puts the line number in desc. SunOS apparently puts in the
1081 number of bytes occupied by a type or object, which we ignore. */
1082 SYMBOL_LINE(sym
) = desc
;
1086 SYMBOL_LINE(sym
) = 0; /* unknown */
1089 if (is_cplus_marker (string
[0]))
1091 /* Special GNU C++ names. */
1095 SYMBOL_NAME (sym
) = obsavestring ("this", strlen ("this"),
1096 &objfile
-> symbol_obstack
);
1099 case 'v': /* $vtbl_ptr_type */
1100 /* Was: SYMBOL_NAME (sym) = "vptr"; */
1104 SYMBOL_NAME (sym
) = obsavestring ("eh_throw", strlen ("eh_throw"),
1105 &objfile
-> symbol_obstack
);
1109 /* This was an anonymous type that was never fixed up. */
1112 #ifdef STATIC_TRANSFORM_NAME
1114 /* SunPRO (3.0 at least) static variable encoding. */
1119 complain (&unrecognized_cplus_name_complaint
, string
);
1120 goto normal
; /* Do *something* with it */
1126 SYMBOL_LANGUAGE (sym
) = current_subfile
-> language
;
1127 SYMBOL_NAME (sym
) = (char *)
1128 obstack_alloc (&objfile
-> symbol_obstack
, ((p
- string
) + 1));
1129 /* Open-coded memcpy--saves function call time. */
1130 /* FIXME: Does it really? Try replacing with simple strcpy and
1131 try it on an executable with a large symbol table. */
1132 /* FIXME: considering that gcc can open code memcpy anyway, I
1133 doubt it. xoxorich. */
1135 register char *p1
= string
;
1136 register char *p2
= SYMBOL_NAME (sym
);
1144 /* If this symbol is from a C++ compilation, then attempt to cache the
1145 demangled form for future reference. This is a typical time versus
1146 space tradeoff, that was decided in favor of time because it sped up
1147 C++ symbol lookups by a factor of about 20. */
1149 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
1153 /* Determine the type of name being defined. */
1155 /* Getting GDB to correctly skip the symbol on an undefined symbol
1156 descriptor and not ever dump core is a very dodgy proposition if
1157 we do things this way. I say the acorn RISC machine can just
1158 fix their compiler. */
1159 /* The Acorn RISC machine's compiler can put out locals that don't
1160 start with "234=" or "(3,4)=", so assume anything other than the
1161 deftypes we know how to handle is a local. */
1162 if (!strchr ("cfFGpPrStTvVXCR", *p
))
1164 if (isdigit (*p
) || *p
== '(' || *p
== '-')
1173 /* c is a special case, not followed by a type-number.
1174 SYMBOL:c=iVALUE for an integer constant symbol.
1175 SYMBOL:c=rVALUE for a floating constant symbol.
1176 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
1177 e.g. "b:c=e6,0" for "const b = blob1"
1178 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
1181 SYMBOL_CLASS (sym
) = LOC_CONST
;
1182 SYMBOL_TYPE (sym
) = error_type (&p
, objfile
);
1183 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1184 add_symbol_to_list (sym
, &file_symbols
);
1192 double d
= atof (p
);
1195 /* FIXME-if-picky-about-floating-accuracy: Should be using
1196 target arithmetic to get the value. real.c in GCC
1197 probably has the necessary code. */
1199 /* FIXME: lookup_fundamental_type is a hack. We should be
1200 creating a type especially for the type of float constants.
1201 Problem is, what type should it be?
1203 Also, what should the name of this type be? Should we
1204 be using 'S' constants (see stabs.texinfo) instead? */
1206 SYMBOL_TYPE (sym
) = lookup_fundamental_type (objfile
,
1209 obstack_alloc (&objfile
-> symbol_obstack
,
1210 TYPE_LENGTH (SYMBOL_TYPE (sym
)));
1211 store_floating (dbl_valu
, TYPE_LENGTH (SYMBOL_TYPE (sym
)), d
);
1212 SYMBOL_VALUE_BYTES (sym
) = dbl_valu
;
1213 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
1218 /* Defining integer constants this way is kind of silly,
1219 since 'e' constants allows the compiler to give not
1220 only the value, but the type as well. C has at least
1221 int, long, unsigned int, and long long as constant
1222 types; other languages probably should have at least
1223 unsigned as well as signed constants. */
1225 /* We just need one int constant type for all objfiles.
1226 It doesn't depend on languages or anything (arguably its
1227 name should be a language-specific name for a type of
1228 that size, but I'm inclined to say that if the compiler
1229 wants a nice name for the type, it can use 'e'). */
1230 static struct type
*int_const_type
;
1232 /* Yes, this is as long as a *host* int. That is because we
1234 if (int_const_type
== NULL
)
1236 init_type (TYPE_CODE_INT
,
1237 sizeof (int) * HOST_CHAR_BIT
/ TARGET_CHAR_BIT
, 0,
1239 (struct objfile
*)NULL
);
1240 SYMBOL_TYPE (sym
) = int_const_type
;
1241 SYMBOL_VALUE (sym
) = atoi (p
);
1242 SYMBOL_CLASS (sym
) = LOC_CONST
;
1246 /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value
1247 can be represented as integral.
1248 e.g. "b:c=e6,0" for "const b = blob1"
1249 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
1251 SYMBOL_CLASS (sym
) = LOC_CONST
;
1252 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1256 SYMBOL_TYPE (sym
) = error_type (&p
, objfile
);
1261 /* If the value is too big to fit in an int (perhaps because
1262 it is unsigned), or something like that, we silently get
1263 a bogus value. The type and everything else about it is
1264 correct. Ideally, we should be using whatever we have
1265 available for parsing unsigned and long long values,
1267 SYMBOL_VALUE (sym
) = atoi (p
);
1272 SYMBOL_CLASS (sym
) = LOC_CONST
;
1273 SYMBOL_TYPE (sym
) = error_type (&p
, objfile
);
1276 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1277 add_symbol_to_list (sym
, &file_symbols
);
1281 /* The name of a caught exception. */
1282 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1283 SYMBOL_CLASS (sym
) = LOC_LABEL
;
1284 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1285 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1286 add_symbol_to_list (sym
, &local_symbols
);
1290 /* A static function definition. */
1291 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1292 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1293 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1294 add_symbol_to_list (sym
, &file_symbols
);
1295 /* fall into process_function_types. */
1297 process_function_types
:
1298 /* Function result types are described as the result type in stabs.
1299 We need to convert this to the function-returning-type-X type
1300 in GDB. E.g. "int" is converted to "function returning int". */
1301 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_FUNC
)
1302 SYMBOL_TYPE (sym
) = lookup_function_type (SYMBOL_TYPE (sym
));
1303 /* fall into process_prototype_types */
1305 process_prototype_types
:
1306 /* Sun acc puts declared types of arguments here. We don't care
1307 about their actual types (FIXME -- we should remember the whole
1308 function prototype), but the list may define some new types
1309 that we have to remember, so we must scan it now. */
1312 read_type (&p
, objfile
);
1317 /* A global function definition. */
1318 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1319 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1320 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1321 add_symbol_to_list (sym
, &global_symbols
);
1322 goto process_function_types
;
1325 /* For a class G (global) symbol, it appears that the
1326 value is not correct. It is necessary to search for the
1327 corresponding linker definition to find the value.
1328 These definitions appear at the end of the namelist. */
1329 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1330 i
= hashname (SYMBOL_NAME (sym
));
1331 SYMBOL_VALUE_CHAIN (sym
) = global_sym_chain
[i
];
1332 global_sym_chain
[i
] = sym
;
1333 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1334 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1335 add_symbol_to_list (sym
, &global_symbols
);
1338 /* This case is faked by a conditional above,
1339 when there is no code letter in the dbx data.
1340 Dbx data never actually contains 'l'. */
1343 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1344 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1345 SYMBOL_VALUE (sym
) = valu
;
1346 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1347 add_symbol_to_list (sym
, &local_symbols
);
1352 /* pF is a two-letter code that means a function parameter in Fortran.
1353 The type-number specifies the type of the return value.
1354 Translate it into a pointer-to-function type. */
1358 = lookup_pointer_type
1359 (lookup_function_type (read_type (&p
, objfile
)));
1362 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1364 /* Normally this is a parameter, a LOC_ARG. On the i960, it
1365 can also be a LOC_LOCAL_ARG depending on symbol type. */
1366 #ifndef DBX_PARM_SYMBOL_CLASS
1367 #define DBX_PARM_SYMBOL_CLASS(type) LOC_ARG
1370 SYMBOL_CLASS (sym
) = DBX_PARM_SYMBOL_CLASS (type
);
1371 SYMBOL_VALUE (sym
) = valu
;
1372 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1373 add_symbol_to_list (sym
, &local_symbols
);
1375 if (TARGET_BYTE_ORDER
!= BIG_ENDIAN
)
1377 /* On little-endian machines, this crud is never necessary,
1378 and, if the extra bytes contain garbage, is harmful. */
1382 /* If it's gcc-compiled, if it says `short', believe it. */
1383 if (processing_gcc_compilation
|| BELIEVE_PCC_PROMOTION
)
1386 #if !BELIEVE_PCC_PROMOTION
1388 /* This is the signed type which arguments get promoted to. */
1389 static struct type
*pcc_promotion_type
;
1390 /* This is the unsigned type which arguments get promoted to. */
1391 static struct type
*pcc_unsigned_promotion_type
;
1393 /* Call it "int" because this is mainly C lossage. */
1394 if (pcc_promotion_type
== NULL
)
1395 pcc_promotion_type
=
1396 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
1399 if (pcc_unsigned_promotion_type
== NULL
)
1400 pcc_unsigned_promotion_type
=
1401 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
1402 TYPE_FLAG_UNSIGNED
, "unsigned int", NULL
);
1404 #if defined(BELIEVE_PCC_PROMOTION_TYPE)
1405 /* This macro is defined on machines (e.g. sparc) where
1406 we should believe the type of a PCC 'short' argument,
1407 but shouldn't believe the address (the address is
1408 the address of the corresponding int).
1410 My guess is that this correction, as opposed to changing
1411 the parameter to an 'int' (as done below, for PCC
1412 on most machines), is the right thing to do
1413 on all machines, but I don't want to risk breaking
1414 something that already works. On most PCC machines,
1415 the sparc problem doesn't come up because the calling
1416 function has to zero the top bytes (not knowing whether
1417 the called function wants an int or a short), so there
1418 is little practical difference between an int and a short
1419 (except perhaps what happens when the GDB user types
1420 "print short_arg = 0x10000;").
1422 Hacked for SunOS 4.1 by gnu@cygnus.com. In 4.1, the compiler
1423 actually produces the correct address (we don't need to fix it
1424 up). I made this code adapt so that it will offset the symbol
1425 if it was pointing at an int-aligned location and not
1426 otherwise. This way you can use the same gdb for 4.0.x and
1429 If the parameter is shorter than an int, and is integral
1430 (e.g. char, short, or unsigned equivalent), and is claimed to
1431 be passed on an integer boundary, don't believe it! Offset the
1432 parameter's address to the tail-end of that integer. */
1434 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (pcc_promotion_type
)
1435 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
1436 && 0 == SYMBOL_VALUE (sym
) % TYPE_LENGTH (pcc_promotion_type
))
1438 SYMBOL_VALUE (sym
) += TYPE_LENGTH (pcc_promotion_type
)
1439 - TYPE_LENGTH (SYMBOL_TYPE (sym
));
1443 #else /* no BELIEVE_PCC_PROMOTION_TYPE. */
1445 /* If PCC says a parameter is a short or a char,
1446 it is really an int. */
1447 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (pcc_promotion_type
)
1448 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
)
1451 TYPE_UNSIGNED (SYMBOL_TYPE (sym
))
1452 ? pcc_unsigned_promotion_type
1453 : pcc_promotion_type
;
1457 #endif /* no BELIEVE_PCC_PROMOTION_TYPE. */
1459 #endif /* !BELIEVE_PCC_PROMOTION. */
1462 /* acc seems to use P to declare the prototypes of functions that
1463 are referenced by this file. gdb is not prepared to deal
1464 with this extra information. FIXME, it ought to. */
1467 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1468 goto process_prototype_types
;
1473 /* Parameter which is in a register. */
1474 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1475 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
1476 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
1477 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
1479 complain (®_value_complaint
, SYMBOL_VALUE (sym
), NUM_REGS
,
1480 SYMBOL_SOURCE_NAME (sym
));
1481 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
1483 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1484 add_symbol_to_list (sym
, &local_symbols
);
1488 /* Register variable (either global or local). */
1489 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1490 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
1491 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
1492 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
1494 complain (®_value_complaint
, SYMBOL_VALUE (sym
), NUM_REGS
,
1495 SYMBOL_SOURCE_NAME (sym
));
1496 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
1498 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1499 if (within_function
)
1501 /* Sun cc uses a pair of symbols, one 'p' and one 'r' with the same
1502 name to represent an argument passed in a register.
1503 GCC uses 'P' for the same case. So if we find such a symbol pair
1504 we combine it into one 'P' symbol. For Sun cc we need to do this
1505 regardless of REG_STRUCT_HAS_ADDR, because the compiler puts out
1506 the 'p' symbol even if it never saves the argument onto the stack.
1508 On most machines, we want to preserve both symbols, so that
1509 we can still get information about what is going on with the
1510 stack (VAX for computing args_printed, using stack slots instead
1511 of saved registers in backtraces, etc.).
1513 Note that this code illegally combines
1514 main(argc) struct foo argc; { register struct foo argc; }
1515 but this case is considered pathological and causes a warning
1516 from a decent compiler. */
1519 && local_symbols
->nsyms
> 0
1520 #ifndef USE_REGISTER_NOT_ARG
1521 && REG_STRUCT_HAS_ADDR (processing_gcc_compilation
,
1523 && (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
1524 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
1525 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_SET
1526 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_BITSTRING
)
1530 struct symbol
*prev_sym
;
1531 prev_sym
= local_symbols
->symbol
[local_symbols
->nsyms
- 1];
1532 if ((SYMBOL_CLASS (prev_sym
) == LOC_REF_ARG
1533 || SYMBOL_CLASS (prev_sym
) == LOC_ARG
)
1534 && STREQ (SYMBOL_NAME (prev_sym
), SYMBOL_NAME(sym
)))
1536 SYMBOL_CLASS (prev_sym
) = LOC_REGPARM
;
1537 /* Use the type from the LOC_REGISTER; that is the type
1538 that is actually in that register. */
1539 SYMBOL_TYPE (prev_sym
) = SYMBOL_TYPE (sym
);
1540 SYMBOL_VALUE (prev_sym
) = SYMBOL_VALUE (sym
);
1545 add_symbol_to_list (sym
, &local_symbols
);
1548 add_symbol_to_list (sym
, &file_symbols
);
1552 /* Static symbol at top level of file */
1553 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1554 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1555 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1556 #ifdef STATIC_TRANSFORM_NAME
1557 if (SYMBOL_NAME (sym
)[0] == '$')
1559 struct minimal_symbol
*msym
;
1560 msym
= lookup_minimal_symbol (SYMBOL_NAME (sym
), NULL
, objfile
);
1563 SYMBOL_NAME (sym
) = STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym
));
1564 SYMBOL_VALUE_ADDRESS (sym
) = SYMBOL_VALUE_ADDRESS (msym
);
1568 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1569 add_symbol_to_list (sym
, &file_symbols
);
1573 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1575 /* For a nameless type, we don't want a create a symbol, thus we
1576 did not use `sym'. Return without further processing. */
1577 if (nameless
) return NULL
;
1579 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1580 SYMBOL_VALUE (sym
) = valu
;
1581 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1582 /* C++ vagaries: we may have a type which is derived from
1583 a base type which did not have its name defined when the
1584 derived class was output. We fill in the derived class's
1585 base part member's name here in that case. */
1586 if (TYPE_NAME (SYMBOL_TYPE (sym
)) != NULL
)
1587 if ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
1588 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
)
1589 && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)))
1592 for (j
= TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)) - 1; j
>= 0; j
--)
1593 if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) == 0)
1594 TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) =
1595 type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym
), j
));
1598 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == NULL
)
1600 /* gcc-2.6 or later (when using -fvtable-thunks)
1601 emits a unique named type for a vtable entry.
1602 Some gdb code depends on that specific name. */
1603 extern const char vtbl_ptr_name
[];
1605 if ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_PTR
1606 && strcmp (SYMBOL_NAME (sym
), vtbl_ptr_name
))
1607 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_FUNC
)
1609 /* If we are giving a name to a type such as "pointer to
1610 foo" or "function returning foo", we better not set
1611 the TYPE_NAME. If the program contains "typedef char
1612 *caddr_t;", we don't want all variables of type char
1613 * to print as caddr_t. This is not just a
1614 consequence of GDB's type management; PCC and GCC (at
1615 least through version 2.4) both output variables of
1616 either type char * or caddr_t with the type number
1617 defined in the 't' symbol for caddr_t. If a future
1618 compiler cleans this up it GDB is not ready for it
1619 yet, but if it becomes ready we somehow need to
1620 disable this check (without breaking the PCC/GCC2.4
1625 Fortunately, this check seems not to be necessary
1626 for anything except pointers or functions. */
1629 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_NAME (sym
);
1632 add_symbol_to_list (sym
, &file_symbols
);
1636 /* Struct, union, or enum tag. For GNU C++, this can be be followed
1637 by 't' which means we are typedef'ing it as well. */
1638 synonym
= *p
== 't';
1642 /* The semantics of C++ state that "struct foo { ... }" also defines
1643 a typedef for "foo". Unfortunately, cfront never makes the typedef
1644 when translating C++ into C. We make the typedef here so that
1645 "ptype foo" works as expected for cfront translated code. */
1646 else if (current_subfile
->language
== language_cplus
)
1649 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1651 /* For a nameless type, we don't want a create a symbol, thus we
1652 did not use `sym'. Return without further processing. */
1653 if (nameless
) return NULL
;
1655 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1656 SYMBOL_VALUE (sym
) = valu
;
1657 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
1658 if (TYPE_TAG_NAME (SYMBOL_TYPE (sym
)) == 0)
1659 TYPE_TAG_NAME (SYMBOL_TYPE (sym
))
1660 = obconcat (&objfile
-> type_obstack
, "", "", SYMBOL_NAME (sym
));
1661 add_symbol_to_list (sym
, &file_symbols
);
1665 /* Clone the sym and then modify it. */
1666 register struct symbol
*typedef_sym
= (struct symbol
*)
1667 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
1668 *typedef_sym
= *sym
;
1669 SYMBOL_CLASS (typedef_sym
) = LOC_TYPEDEF
;
1670 SYMBOL_VALUE (typedef_sym
) = valu
;
1671 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
1672 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
1673 TYPE_NAME (SYMBOL_TYPE (sym
))
1674 = obconcat (&objfile
-> type_obstack
, "", "", SYMBOL_NAME (sym
));
1675 add_symbol_to_list (typedef_sym
, &file_symbols
);
1680 /* Static symbol of local scope */
1681 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1682 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1683 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1684 #ifdef STATIC_TRANSFORM_NAME
1685 if (SYMBOL_NAME (sym
)[0] == '$')
1687 struct minimal_symbol
*msym
;
1688 msym
= lookup_minimal_symbol (SYMBOL_NAME (sym
), NULL
, objfile
);
1691 SYMBOL_NAME (sym
) = STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym
));
1692 SYMBOL_VALUE_ADDRESS (sym
) = SYMBOL_VALUE_ADDRESS (msym
);
1696 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1698 add_symbol_to_list (sym
, &global_symbols
);
1700 add_symbol_to_list (sym
, &local_symbols
);
1704 /* Reference parameter */
1705 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1706 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
1707 SYMBOL_VALUE (sym
) = valu
;
1708 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1709 add_symbol_to_list (sym
, &local_symbols
);
1713 /* Reference parameter which is in a register. */
1714 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1715 SYMBOL_CLASS (sym
) = LOC_REGPARM_ADDR
;
1716 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
1717 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
1719 complain (®_value_complaint
, SYMBOL_VALUE (sym
), NUM_REGS
,
1720 SYMBOL_SOURCE_NAME (sym
));
1721 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
1723 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1724 add_symbol_to_list (sym
, &local_symbols
);
1728 /* This is used by Sun FORTRAN for "function result value".
1729 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
1730 that Pascal uses it too, but when I tried it Pascal used
1731 "x:3" (local symbol) instead. */
1732 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1733 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1734 SYMBOL_VALUE (sym
) = valu
;
1735 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1736 add_symbol_to_list (sym
, &local_symbols
);
1739 /* New code added to support cfront stabs strings */
1740 /* Note: case 'P' already handled above */
1742 /* Cfront type continuation coming up!
1743 find the original definition and add to it.
1744 We'll have to do this for the typedef too,
1745 since we clloned the symbol to define a type in read_type.
1746 Stabs info examples:
1748 foo__1CFv :ZtF (first def foo__1CFv:F(0,3);(0,24))
1749 C:ZsC;;__ct__1CFv func1__1CFv func2__1CFv ... ;;;
1750 where C is the name of the class. */
1751 /* can't lookup symbol yet 'cuz symbols not read yet
1752 so we save it for processing later */
1753 process_later(sym
,p
);
1754 SYMBOL_TYPE (sym
) = error_type (&p
, objfile
); /* FIXME! change later */
1755 SYMBOL_CLASS (sym
) = LOC_CONST
;
1756 SYMBOL_VALUE (sym
) = 0;
1757 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1758 /* don't add to list - we'll delete it later when
1759 we add the continuation to the real sym */
1761 /* End of new code added to support cfront stabs strings */
1764 SYMBOL_TYPE (sym
) = error_type (&p
, objfile
);
1765 SYMBOL_CLASS (sym
) = LOC_CONST
;
1766 SYMBOL_VALUE (sym
) = 0;
1767 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1768 add_symbol_to_list (sym
, &file_symbols
);
1772 /* When passing structures to a function, some systems sometimes pass
1773 the address in a register, not the structure itself. */
1775 if (REG_STRUCT_HAS_ADDR (processing_gcc_compilation
,
1777 && ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
)
1778 || (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
)
1779 || (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_BITSTRING
)
1780 || (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_SET
)))
1782 /* If REG_STRUCT_HAS_ADDR yields non-zero we have to
1783 convert LOC_REGPARM to LOC_REGPARM_ADDR for structures and unions. */
1784 if (SYMBOL_CLASS (sym
) == LOC_REGPARM
)
1785 SYMBOL_CLASS (sym
) = LOC_REGPARM_ADDR
;
1786 /* Likewise for converting LOC_ARG to LOC_REF_ARG (for the 7th and
1787 subsequent arguments on the sparc, for example). */
1788 else if (SYMBOL_CLASS (sym
) == LOC_ARG
)
1789 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
1796 /* Skip rest of this symbol and return an error type.
1798 General notes on error recovery: error_type always skips to the
1799 end of the symbol (modulo cretinous dbx symbol name continuation).
1800 Thus code like this:
1802 if (*(*pp)++ != ';')
1803 return error_type (pp, objfile);
1805 is wrong because if *pp starts out pointing at '\0' (typically as the
1806 result of an earlier error), it will be incremented to point to the
1807 start of the next symbol, which might produce strange results, at least
1808 if you run off the end of the string table. Instead use
1811 return error_type (pp, objfile);
1817 foo = error_type (pp, objfile);
1821 And in case it isn't obvious, the point of all this hair is so the compiler
1822 can define new types and new syntaxes, and old versions of the
1823 debugger will be able to read the new symbol tables. */
1825 static struct type
*
1826 error_type (pp
, objfile
)
1828 struct objfile
*objfile
;
1830 complain (&error_type_complaint
);
1833 /* Skip to end of symbol. */
1834 while (**pp
!= '\0')
1839 /* Check for and handle cretinous dbx symbol name continuation! */
1840 if ((*pp
)[-1] == '\\' || (*pp
)[-1] == '?')
1842 *pp
= next_symbol_text (objfile
);
1849 return (builtin_type_error
);
1853 /* Read type information or a type definition; return the type. Even
1854 though this routine accepts either type information or a type
1855 definition, the distinction is relevant--some parts of stabsread.c
1856 assume that type information starts with a digit, '-', or '(' in
1857 deciding whether to call read_type. */
1860 read_type (pp
, objfile
)
1862 struct objfile
*objfile
;
1864 register struct type
*type
= 0;
1868 char type_descriptor
;
1870 /* Size in bits of type if specified by a type attribute, or -1 if
1871 there is no size attribute. */
1874 /* Used to distinguish string and bitstring from char-array and set. */
1877 /* Read type number if present. The type number may be omitted.
1878 for instance in a two-dimensional array declared with type
1879 "ar1;1;10;ar1;1;10;4". */
1880 if ((**pp
>= '0' && **pp
<= '9')
1884 if (read_type_number (pp
, typenums
) != 0)
1885 return error_type (pp
, objfile
);
1887 /* Type is not being defined here. Either it already exists,
1888 or this is a forward reference to it. dbx_alloc_type handles
1891 return dbx_alloc_type (typenums
, objfile
);
1893 /* Type is being defined here. */
1895 Also skip the type descriptor - we get it below with (*pp)[-1]. */
1900 /* 'typenums=' not present, type is anonymous. Read and return
1901 the definition, but don't put it in the type vector. */
1902 typenums
[0] = typenums
[1] = -1;
1907 type_descriptor
= (*pp
)[-1];
1908 switch (type_descriptor
)
1912 enum type_code code
;
1914 /* Used to index through file_symbols. */
1915 struct pending
*ppt
;
1918 /* Name including "struct", etc. */
1922 char *from
, *to
, *p
, *q1
, *q2
;
1924 /* Set the type code according to the following letter. */
1928 code
= TYPE_CODE_STRUCT
;
1931 code
= TYPE_CODE_UNION
;
1934 code
= TYPE_CODE_ENUM
;
1938 /* Complain and keep going, so compilers can invent new
1939 cross-reference types. */
1940 static struct complaint msg
=
1941 {"Unrecognized cross-reference type `%c'", 0, 0};
1942 complain (&msg
, (*pp
)[0]);
1943 code
= TYPE_CODE_STRUCT
;
1948 q1
= strchr(*pp
, '<');
1949 p
= strchr(*pp
, ':');
1951 return error_type (pp
, objfile
);
1952 while (q1
&& p
> q1
&& p
[1] == ':')
1954 q2
= strchr(q1
, '>');
1960 return error_type (pp
, objfile
);
1963 (char *)obstack_alloc (&objfile
->type_obstack
, p
- *pp
+ 1);
1965 /* Copy the name. */
1971 /* Set the pointer ahead of the name which we just read, and
1976 /* Now check to see whether the type has already been
1977 declared. This was written for arrays of cross-referenced
1978 types before we had TYPE_CODE_TARGET_STUBBED, so I'm pretty
1979 sure it is not necessary anymore. But it might be a good
1980 idea, to save a little memory. */
1982 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
1983 for (i
= 0; i
< ppt
->nsyms
; i
++)
1985 struct symbol
*sym
= ppt
->symbol
[i
];
1987 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
1988 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
1989 && (TYPE_CODE (SYMBOL_TYPE (sym
)) == code
)
1990 && STREQ (SYMBOL_NAME (sym
), type_name
))
1992 obstack_free (&objfile
-> type_obstack
, type_name
);
1993 type
= SYMBOL_TYPE (sym
);
1998 /* Didn't find the type to which this refers, so we must
1999 be dealing with a forward reference. Allocate a type
2000 structure for it, and keep track of it so we can
2001 fill in the rest of the fields when we get the full
2003 type
= dbx_alloc_type (typenums
, objfile
);
2004 TYPE_CODE (type
) = code
;
2005 TYPE_TAG_NAME (type
) = type_name
;
2006 INIT_CPLUS_SPECIFIC(type
);
2007 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
2009 add_undefined_type (type
);
2013 case '-': /* RS/6000 built-in type */
2027 /* We deal with something like t(1,2)=(3,4)=... which
2028 the Lucid compiler and recent gcc versions (post 2.7.3) use. */
2030 /* Allocate and enter the typedef type first.
2031 This handles recursive types. */
2032 type
= dbx_alloc_type (typenums
, objfile
);
2033 TYPE_CODE (type
) = TYPE_CODE_TYPEDEF
;
2034 { struct type
*xtype
= read_type (pp
, objfile
);
2037 /* It's being defined as itself. That means it is "void". */
2038 TYPE_CODE (type
) = TYPE_CODE_VOID
;
2039 TYPE_LENGTH (type
) = 1;
2041 else if (type_size
>= 0 || is_string
)
2044 TYPE_NAME (type
) = NULL
;
2045 TYPE_TAG_NAME (type
) = NULL
;
2049 TYPE_FLAGS (type
) |= TYPE_FLAG_TARGET_STUB
;
2050 TYPE_TARGET_TYPE (type
) = xtype
;
2055 /* In the following types, we must be sure to overwrite any existing
2056 type that the typenums refer to, rather than allocating a new one
2057 and making the typenums point to the new one. This is because there
2058 may already be pointers to the existing type (if it had been
2059 forward-referenced), and we must change it to a pointer, function,
2060 reference, or whatever, *in-place*. */
2063 type1
= read_type (pp
, objfile
);
2064 type
= make_pointer_type (type1
, dbx_lookup_type (typenums
));
2067 case '&': /* Reference to another type */
2068 type1
= read_type (pp
, objfile
);
2069 type
= make_reference_type (type1
, dbx_lookup_type (typenums
));
2072 case 'f': /* Function returning another type */
2073 if (os9k_stabs
&& **pp
== '(')
2075 /* Function prototype; parse it.
2076 We must conditionalize this on os9k_stabs because otherwise
2077 it could be confused with a Sun-style (1,3) typenumber
2083 t
= read_type(pp
, objfile
);
2084 if (**pp
== ',') ++*pp
;
2087 type1
= read_type (pp
, objfile
);
2088 type
= make_function_type (type1
, dbx_lookup_type (typenums
));
2091 case 'k': /* Const qualifier on some type (Sun) */
2092 case 'c': /* Const qualifier on some type (OS9000) */
2093 /* Because 'c' means other things to AIX and 'k' is perfectly good,
2094 only accept 'c' in the os9k_stabs case. */
2095 if (type_descriptor
== 'c' && !os9k_stabs
)
2096 return error_type (pp
, objfile
);
2097 type
= read_type (pp
, objfile
);
2098 /* FIXME! For now, we ignore const and volatile qualifiers. */
2101 case 'B': /* Volatile qual on some type (Sun) */
2102 case 'i': /* Volatile qual on some type (OS9000) */
2103 /* Because 'i' means other things to AIX and 'B' is perfectly good,
2104 only accept 'i' in the os9k_stabs case. */
2105 if (type_descriptor
== 'i' && !os9k_stabs
)
2106 return error_type (pp
, objfile
);
2107 type
= read_type (pp
, objfile
);
2108 /* FIXME! For now, we ignore const and volatile qualifiers. */
2112 if (isdigit (**pp
) || **pp
== '(' || **pp
== '-')
2113 { /* Member (class & variable) type */
2114 /* FIXME -- we should be doing smash_to_XXX types here. */
2116 struct type
*domain
= read_type (pp
, objfile
);
2117 struct type
*memtype
;
2120 /* Invalid member type data format. */
2121 return error_type (pp
, objfile
);
2124 memtype
= read_type (pp
, objfile
);
2125 type
= dbx_alloc_type (typenums
, objfile
);
2126 smash_to_member_type (type
, domain
, memtype
);
2128 else /* type attribute */
2131 /* Skip to the semicolon. */
2132 while (**pp
!= ';' && **pp
!= '\0')
2135 return error_type (pp
, objfile
);
2137 ++*pp
; /* Skip the semicolon. */
2142 type_size
= atoi (attr
+ 1);
2152 /* Ignore unrecognized type attributes, so future compilers
2153 can invent new ones. */
2161 case '#': /* Method (class & fn) type */
2162 if ((*pp
)[0] == '#')
2164 /* We'll get the parameter types from the name. */
2165 struct type
*return_type
;
2168 return_type
= read_type (pp
, objfile
);
2169 if (*(*pp
)++ != ';')
2170 complain (&invalid_member_complaint
, symnum
);
2171 type
= allocate_stub_method (return_type
);
2172 if (typenums
[0] != -1)
2173 *dbx_lookup_type (typenums
) = type
;
2177 struct type
*domain
= read_type (pp
, objfile
);
2178 struct type
*return_type
;
2182 /* Invalid member type data format. */
2183 return error_type (pp
, objfile
);
2187 return_type
= read_type (pp
, objfile
);
2188 args
= read_args (pp
, ';', objfile
);
2189 type
= dbx_alloc_type (typenums
, objfile
);
2190 smash_to_method_type (type
, domain
, return_type
, args
);
2194 case 'r': /* Range type */
2195 type
= read_range_type (pp
, typenums
, objfile
);
2196 if (typenums
[0] != -1)
2197 *dbx_lookup_type (typenums
) = type
;
2202 /* Const and volatile qualified type. */
2203 type
= read_type (pp
, objfile
);
2206 /* Sun ACC builtin int type */
2207 type
= read_sun_builtin_type (pp
, typenums
, objfile
);
2208 if (typenums
[0] != -1)
2209 *dbx_lookup_type (typenums
) = type
;
2213 case 'R': /* Sun ACC builtin float type */
2214 type
= read_sun_floating_type (pp
, typenums
, objfile
);
2215 if (typenums
[0] != -1)
2216 *dbx_lookup_type (typenums
) = type
;
2219 case 'e': /* Enumeration type */
2220 type
= dbx_alloc_type (typenums
, objfile
);
2221 type
= read_enum_type (pp
, type
, objfile
);
2222 if (typenums
[0] != -1)
2223 *dbx_lookup_type (typenums
) = type
;
2226 case 's': /* Struct type */
2227 case 'u': /* Union type */
2228 type
= dbx_alloc_type (typenums
, objfile
);
2229 switch (type_descriptor
)
2232 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
2235 TYPE_CODE (type
) = TYPE_CODE_UNION
;
2238 type
= read_struct_type (pp
, type
, objfile
);
2241 case 'a': /* Array type */
2243 return error_type (pp
, objfile
);
2246 type
= dbx_alloc_type (typenums
, objfile
);
2247 type
= read_array_type (pp
, type
, objfile
);
2249 TYPE_CODE (type
) = TYPE_CODE_STRING
;
2253 type1
= read_type (pp
, objfile
);
2254 type
= create_set_type ((struct type
*) NULL
, type1
);
2256 TYPE_CODE (type
) = TYPE_CODE_BITSTRING
;
2257 if (typenums
[0] != -1)
2258 *dbx_lookup_type (typenums
) = type
;
2262 --*pp
; /* Go back to the symbol in error */
2263 /* Particularly important if it was \0! */
2264 return error_type (pp
, objfile
);
2269 warning ("GDB internal error, type is NULL in stabsread.c\n");
2270 return error_type (pp
, objfile
);
2273 /* Size specified in a type attribute overrides any other size. */
2274 if (type_size
!= -1)
2275 TYPE_LENGTH (type
) = (type_size
+ TARGET_CHAR_BIT
- 1) / TARGET_CHAR_BIT
;
2280 /* RS/6000 xlc/dbx combination uses a set of builtin types, starting from -1.
2281 Return the proper type node for a given builtin type number. */
2283 static struct type
*
2284 rs6000_builtin_type (typenum
)
2287 /* We recognize types numbered from -NUMBER_RECOGNIZED to -1. */
2288 #define NUMBER_RECOGNIZED 34
2289 /* This includes an empty slot for type number -0. */
2290 static struct type
*negative_types
[NUMBER_RECOGNIZED
+ 1];
2291 struct type
*rettype
= NULL
;
2293 if (typenum
>= 0 || typenum
< -NUMBER_RECOGNIZED
)
2295 complain (&rs6000_builtin_complaint
, typenum
);
2296 return builtin_type_error
;
2298 if (negative_types
[-typenum
] != NULL
)
2299 return negative_types
[-typenum
];
2301 #if TARGET_CHAR_BIT != 8
2302 #error This code wrong for TARGET_CHAR_BIT not 8
2303 /* These definitions all assume that TARGET_CHAR_BIT is 8. I think
2304 that if that ever becomes not true, the correct fix will be to
2305 make the size in the struct type to be in bits, not in units of
2312 /* The size of this and all the other types are fixed, defined
2313 by the debugging format. If there is a type called "int" which
2314 is other than 32 bits, then it should use a new negative type
2315 number (or avoid negative type numbers for that case).
2316 See stabs.texinfo. */
2317 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "int", NULL
);
2320 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "char", NULL
);
2323 rettype
= init_type (TYPE_CODE_INT
, 2, 0, "short", NULL
);
2326 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "long", NULL
);
2329 rettype
= init_type (TYPE_CODE_INT
, 1, TYPE_FLAG_UNSIGNED
,
2330 "unsigned char", NULL
);
2333 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "signed char", NULL
);
2336 rettype
= init_type (TYPE_CODE_INT
, 2, TYPE_FLAG_UNSIGNED
,
2337 "unsigned short", NULL
);
2340 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
2341 "unsigned int", NULL
);
2344 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
2347 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
2348 "unsigned long", NULL
);
2351 rettype
= init_type (TYPE_CODE_VOID
, 1, 0, "void", NULL
);
2354 /* IEEE single precision (32 bit). */
2355 rettype
= init_type (TYPE_CODE_FLT
, 4, 0, "float", NULL
);
2358 /* IEEE double precision (64 bit). */
2359 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "double", NULL
);
2362 /* This is an IEEE double on the RS/6000, and different machines with
2363 different sizes for "long double" should use different negative
2364 type numbers. See stabs.texinfo. */
2365 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "long double", NULL
);
2368 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "integer", NULL
);
2371 rettype
= init_type (TYPE_CODE_BOOL
, 4, TYPE_FLAG_UNSIGNED
,
2375 rettype
= init_type (TYPE_CODE_FLT
, 4, 0, "short real", NULL
);
2378 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "real", NULL
);
2381 rettype
= init_type (TYPE_CODE_ERROR
, 0, 0, "stringptr", NULL
);
2384 rettype
= init_type (TYPE_CODE_CHAR
, 1, TYPE_FLAG_UNSIGNED
,
2388 rettype
= init_type (TYPE_CODE_BOOL
, 1, TYPE_FLAG_UNSIGNED
,
2392 rettype
= init_type (TYPE_CODE_BOOL
, 2, TYPE_FLAG_UNSIGNED
,
2396 rettype
= init_type (TYPE_CODE_BOOL
, 4, TYPE_FLAG_UNSIGNED
,
2400 rettype
= init_type (TYPE_CODE_BOOL
, 4, TYPE_FLAG_UNSIGNED
,
2404 /* Complex type consisting of two IEEE single precision values. */
2405 rettype
= init_type (TYPE_CODE_ERROR
, 8, 0, "complex", NULL
);
2408 /* Complex type consisting of two IEEE double precision values. */
2409 rettype
= init_type (TYPE_CODE_ERROR
, 16, 0, "double complex", NULL
);
2412 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "integer*1", NULL
);
2415 rettype
= init_type (TYPE_CODE_INT
, 2, 0, "integer*2", NULL
);
2418 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "integer*4", NULL
);
2421 rettype
= init_type (TYPE_CODE_CHAR
, 2, 0, "wchar", NULL
);
2424 rettype
= init_type (TYPE_CODE_INT
, 8, 0, "long long", NULL
);
2427 rettype
= init_type (TYPE_CODE_INT
, 8, TYPE_FLAG_UNSIGNED
,
2428 "unsigned long long", NULL
);
2431 rettype
= init_type (TYPE_CODE_INT
, 8, TYPE_FLAG_UNSIGNED
,
2435 rettype
= init_type (TYPE_CODE_INT
, 8, 0, "integer*8", NULL
);
2438 negative_types
[-typenum
] = rettype
;
2442 /* This page contains subroutines of read_type. */
2444 /* Read member function stabs info for C++ classes. The form of each member
2447 NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
2449 An example with two member functions is:
2451 afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
2453 For the case of overloaded operators, the format is op$::*.funcs, where
2454 $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
2455 name (such as `+=') and `.' marks the end of the operator name.
2457 Returns 1 for success, 0 for failure. */
2460 read_member_functions (fip
, pp
, type
, objfile
)
2461 struct field_info
*fip
;
2464 struct objfile
*objfile
;
2468 /* Total number of member functions defined in this class. If the class
2469 defines two `f' functions, and one `g' function, then this will have
2471 int total_length
= 0;
2475 struct next_fnfield
*next
;
2476 struct fn_field fn_field
;
2478 struct type
*look_ahead_type
;
2479 struct next_fnfieldlist
*new_fnlist
;
2480 struct next_fnfield
*new_sublist
;
2484 /* Process each list until we find something that is not a member function
2485 or find the end of the functions. */
2489 /* We should be positioned at the start of the function name.
2490 Scan forward to find the first ':' and if it is not the
2491 first of a "::" delimiter, then this is not a member function. */
2503 look_ahead_type
= NULL
;
2506 new_fnlist
= (struct next_fnfieldlist
*)
2507 xmalloc (sizeof (struct next_fnfieldlist
));
2508 make_cleanup (free
, new_fnlist
);
2509 memset (new_fnlist
, 0, sizeof (struct next_fnfieldlist
));
2511 if ((*pp
)[0] == 'o' && (*pp
)[1] == 'p' && is_cplus_marker ((*pp
)[2]))
2513 /* This is a completely wierd case. In order to stuff in the
2514 names that might contain colons (the usual name delimiter),
2515 Mike Tiemann defined a different name format which is
2516 signalled if the identifier is "op$". In that case, the
2517 format is "op$::XXXX." where XXXX is the name. This is
2518 used for names like "+" or "=". YUUUUUUUK! FIXME! */
2519 /* This lets the user type "break operator+".
2520 We could just put in "+" as the name, but that wouldn't
2522 static char opname
[32] = {'o', 'p', CPLUS_MARKER
};
2523 char *o
= opname
+ 3;
2525 /* Skip past '::'. */
2528 STABS_CONTINUE (pp
, objfile
);
2534 main_fn_name
= savestring (opname
, o
- opname
);
2540 main_fn_name
= savestring (*pp
, p
- *pp
);
2541 /* Skip past '::'. */
2544 new_fnlist
-> fn_fieldlist
.name
= main_fn_name
;
2549 (struct next_fnfield
*) xmalloc (sizeof (struct next_fnfield
));
2550 make_cleanup (free
, new_sublist
);
2551 memset (new_sublist
, 0, sizeof (struct next_fnfield
));
2553 /* Check for and handle cretinous dbx symbol name continuation! */
2554 if (look_ahead_type
== NULL
)
2557 STABS_CONTINUE (pp
, objfile
);
2559 new_sublist
-> fn_field
.type
= read_type (pp
, objfile
);
2562 /* Invalid symtab info for member function. */
2568 /* g++ version 1 kludge */
2569 new_sublist
-> fn_field
.type
= look_ahead_type
;
2570 look_ahead_type
= NULL
;
2580 /* If this is just a stub, then we don't have the real name here. */
2582 if (TYPE_FLAGS (new_sublist
-> fn_field
.type
) & TYPE_FLAG_STUB
)
2584 if (!TYPE_DOMAIN_TYPE (new_sublist
-> fn_field
.type
))
2585 TYPE_DOMAIN_TYPE (new_sublist
-> fn_field
.type
) = type
;
2586 new_sublist
-> fn_field
.is_stub
= 1;
2588 new_sublist
-> fn_field
.physname
= savestring (*pp
, p
- *pp
);
2591 /* Set this member function's visibility fields. */
2594 case VISIBILITY_PRIVATE
:
2595 new_sublist
-> fn_field
.is_private
= 1;
2597 case VISIBILITY_PROTECTED
:
2598 new_sublist
-> fn_field
.is_protected
= 1;
2602 STABS_CONTINUE (pp
, objfile
);
2605 case 'A': /* Normal functions. */
2606 new_sublist
-> fn_field
.is_const
= 0;
2607 new_sublist
-> fn_field
.is_volatile
= 0;
2610 case 'B': /* `const' member functions. */
2611 new_sublist
-> fn_field
.is_const
= 1;
2612 new_sublist
-> fn_field
.is_volatile
= 0;
2615 case 'C': /* `volatile' member function. */
2616 new_sublist
-> fn_field
.is_const
= 0;
2617 new_sublist
-> fn_field
.is_volatile
= 1;
2620 case 'D': /* `const volatile' member function. */
2621 new_sublist
-> fn_field
.is_const
= 1;
2622 new_sublist
-> fn_field
.is_volatile
= 1;
2625 case '*': /* File compiled with g++ version 1 -- no info */
2630 complain (&const_vol_complaint
, **pp
);
2639 /* virtual member function, followed by index.
2640 The sign bit is set to distinguish pointers-to-methods
2641 from virtual function indicies. Since the array is
2642 in words, the quantity must be shifted left by 1
2643 on 16 bit machine, and by 2 on 32 bit machine, forcing
2644 the sign bit out, and usable as a valid index into
2645 the array. Remove the sign bit here. */
2646 new_sublist
-> fn_field
.voffset
=
2647 (0x7fffffff & read_huge_number (pp
, ';', &nbits
)) + 2;
2651 STABS_CONTINUE (pp
, objfile
);
2652 if (**pp
== ';' || **pp
== '\0')
2654 /* Must be g++ version 1. */
2655 new_sublist
-> fn_field
.fcontext
= 0;
2659 /* Figure out from whence this virtual function came.
2660 It may belong to virtual function table of
2661 one of its baseclasses. */
2662 look_ahead_type
= read_type (pp
, objfile
);
2665 /* g++ version 1 overloaded methods. */
2669 new_sublist
-> fn_field
.fcontext
= look_ahead_type
;
2678 look_ahead_type
= NULL
;
2684 /* static member function. */
2685 new_sublist
-> fn_field
.voffset
= VOFFSET_STATIC
;
2686 if (strncmp (new_sublist
-> fn_field
.physname
,
2687 main_fn_name
, strlen (main_fn_name
)))
2689 new_sublist
-> fn_field
.is_stub
= 1;
2695 complain (&member_fn_complaint
, (*pp
)[-1]);
2696 /* Fall through into normal member function. */
2699 /* normal member function. */
2700 new_sublist
-> fn_field
.voffset
= 0;
2701 new_sublist
-> fn_field
.fcontext
= 0;
2705 new_sublist
-> next
= sublist
;
2706 sublist
= new_sublist
;
2708 STABS_CONTINUE (pp
, objfile
);
2710 while (**pp
!= ';' && **pp
!= '\0');
2714 new_fnlist
-> fn_fieldlist
.fn_fields
= (struct fn_field
*)
2715 obstack_alloc (&objfile
-> type_obstack
,
2716 sizeof (struct fn_field
) * length
);
2717 memset (new_fnlist
-> fn_fieldlist
.fn_fields
, 0,
2718 sizeof (struct fn_field
) * length
);
2719 for (i
= length
; (i
--, sublist
); sublist
= sublist
-> next
)
2721 new_fnlist
-> fn_fieldlist
.fn_fields
[i
] = sublist
-> fn_field
;
2724 new_fnlist
-> fn_fieldlist
.length
= length
;
2725 new_fnlist
-> next
= fip
-> fnlist
;
2726 fip
-> fnlist
= new_fnlist
;
2728 total_length
+= length
;
2729 STABS_CONTINUE (pp
, objfile
);
2734 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2735 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2736 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * nfn_fields
);
2737 memset (TYPE_FN_FIELDLISTS (type
), 0,
2738 sizeof (struct fn_fieldlist
) * nfn_fields
);
2739 TYPE_NFN_FIELDS (type
) = nfn_fields
;
2740 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2746 /* Special GNU C++ name.
2748 Returns 1 for success, 0 for failure. "failure" means that we can't
2749 keep parsing and it's time for error_type(). */
2752 read_cpp_abbrev (fip
, pp
, type
, objfile
)
2753 struct field_info
*fip
;
2756 struct objfile
*objfile
;
2761 struct type
*context
;
2771 /* At this point, *pp points to something like "22:23=*22...",
2772 where the type number before the ':' is the "context" and
2773 everything after is a regular type definition. Lookup the
2774 type, find it's name, and construct the field name. */
2776 context
= read_type (pp
, objfile
);
2780 case 'f': /* $vf -- a virtual function table pointer */
2781 fip
->list
->field
.name
=
2782 obconcat (&objfile
->type_obstack
, vptr_name
, "", "");
2785 case 'b': /* $vb -- a virtual bsomethingorother */
2786 name
= type_name_no_tag (context
);
2789 complain (&invalid_cpp_type_complaint
, symnum
);
2792 fip
->list
->field
.name
=
2793 obconcat (&objfile
->type_obstack
, vb_name
, name
, "");
2797 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2798 fip
->list
->field
.name
=
2799 obconcat (&objfile
->type_obstack
,
2800 "INVALID_CPLUSPLUS_ABBREV", "", "");
2804 /* At this point, *pp points to the ':'. Skip it and read the
2810 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2813 fip
->list
->field
.type
= read_type (pp
, objfile
);
2815 (*pp
)++; /* Skip the comma. */
2821 fip
->list
->field
.bitpos
= read_huge_number (pp
, ';', &nbits
);
2825 /* This field is unpacked. */
2826 fip
->list
->field
.bitsize
= 0;
2827 fip
->list
->visibility
= VISIBILITY_PRIVATE
;
2831 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2832 /* We have no idea what syntax an unrecognized abbrev would have, so
2833 better return 0. If we returned 1, we would need to at least advance
2834 *pp to avoid an infinite loop. */
2841 read_one_struct_field (fip
, pp
, p
, type
, objfile
)
2842 struct field_info
*fip
;
2846 struct objfile
*objfile
;
2848 /* The following is code to work around cfront generated stabs.
2849 The stabs contains full mangled name for each field.
2850 We try to demangle the name and extract the field name out of it.
2852 if (ARM_DEMANGLING
&& current_subfile
->language
== language_cplus
)
2858 dem
= cplus_demangle (*pp
, DMGL_ANSI
| DMGL_PARAMS
);
2861 dem_p
= strrchr (dem
, ':');
2862 if (dem_p
!= 0 && *(dem_p
-1)==':')
2864 fip
->list
->field
.name
=
2865 obsavestring (dem_p
, strlen(dem_p
), &objfile
-> type_obstack
);
2869 fip
->list
->field
.name
=
2870 obsavestring (*pp
, p
- *pp
, &objfile
-> type_obstack
);
2874 /* end of code for cfront work around */
2877 fip
-> list
-> field
.name
=
2878 obsavestring (*pp
, p
- *pp
, &objfile
-> type_obstack
);
2881 /* This means we have a visibility for a field coming. */
2885 fip
-> list
-> visibility
= *(*pp
)++;
2889 /* normal dbx-style format, no explicit visibility */
2890 fip
-> list
-> visibility
= VISIBILITY_PUBLIC
;
2893 fip
-> list
-> field
.type
= read_type (pp
, objfile
);
2898 /* Possible future hook for nested types. */
2901 fip
-> list
-> field
.bitpos
= (long)-2; /* nested type */
2907 /* Static class member. */
2908 fip
-> list
-> field
.bitpos
= (long) -1;
2914 fip
-> list
-> field
.bitsize
= (long) savestring (*pp
, p
- *pp
);
2918 else if (**pp
!= ',')
2920 /* Bad structure-type format. */
2921 complain (&stabs_general_complaint
, "bad structure-type format");
2925 (*pp
)++; /* Skip the comma. */
2929 fip
-> list
-> field
.bitpos
= read_huge_number (pp
, ',', &nbits
);
2932 complain (&stabs_general_complaint
, "bad structure-type format");
2935 fip
-> list
-> field
.bitsize
= read_huge_number (pp
, ';', &nbits
);
2938 complain (&stabs_general_complaint
, "bad structure-type format");
2943 if (fip
-> list
-> field
.bitpos
== 0 && fip
-> list
-> field
.bitsize
== 0)
2945 /* This can happen in two cases: (1) at least for gcc 2.4.5 or so,
2946 it is a field which has been optimized out. The correct stab for
2947 this case is to use VISIBILITY_IGNORE, but that is a recent
2948 invention. (2) It is a 0-size array. For example
2949 union { int num; char str[0]; } foo. Printing "<no value>" for
2950 str in "p foo" is OK, since foo.str (and thus foo.str[3])
2951 will continue to work, and a 0-size array as a whole doesn't
2952 have any contents to print.
2954 I suspect this probably could also happen with gcc -gstabs (not
2955 -gstabs+) for static fields, and perhaps other C++ extensions.
2956 Hopefully few people use -gstabs with gdb, since it is intended
2957 for dbx compatibility. */
2959 /* Ignore this field. */
2960 fip
-> list
-> visibility
= VISIBILITY_IGNORE
;
2964 /* Detect an unpacked field and mark it as such.
2965 dbx gives a bit size for all fields.
2966 Note that forward refs cannot be packed,
2967 and treat enums as if they had the width of ints. */
2969 if (TYPE_CODE (fip
-> list
-> field
.type
) != TYPE_CODE_INT
2970 && TYPE_CODE (fip
-> list
-> field
.type
) != TYPE_CODE_BOOL
2971 && TYPE_CODE (fip
-> list
-> field
.type
) != TYPE_CODE_ENUM
)
2973 fip
-> list
-> field
.bitsize
= 0;
2975 if ((fip
-> list
-> field
.bitsize
2976 == TARGET_CHAR_BIT
* TYPE_LENGTH (fip
-> list
-> field
.type
)
2977 || (TYPE_CODE (fip
-> list
-> field
.type
) == TYPE_CODE_ENUM
2978 && (fip
-> list
-> field
.bitsize
2983 fip
-> list
-> field
.bitpos
% 8 == 0)
2985 fip
-> list
-> field
.bitsize
= 0;
2991 /* Read struct or class data fields. They have the form:
2993 NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
2995 At the end, we see a semicolon instead of a field.
2997 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
3000 The optional VISIBILITY is one of:
3002 '/0' (VISIBILITY_PRIVATE)
3003 '/1' (VISIBILITY_PROTECTED)
3004 '/2' (VISIBILITY_PUBLIC)
3005 '/9' (VISIBILITY_IGNORE)
3007 or nothing, for C style fields with public visibility.
3009 Returns 1 for success, 0 for failure. */
3012 read_struct_fields (fip
, pp
, type
, objfile
)
3013 struct field_info
*fip
;
3016 struct objfile
*objfile
;
3019 struct nextfield
*new;
3021 /* We better set p right now, in case there are no fields at all... */
3025 /* Read each data member type until we find the terminating ';' at the end of
3026 the data member list, or break for some other reason such as finding the
3027 start of the member function list. */
3031 if (os9k_stabs
&& **pp
== ',') break;
3032 STABS_CONTINUE (pp
, objfile
);
3033 /* Get space to record the next field's data. */
3034 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3035 make_cleanup (free
, new);
3036 memset (new, 0, sizeof (struct nextfield
));
3037 new -> next
= fip
-> list
;
3040 /* Get the field name. */
3043 /* If is starts with CPLUS_MARKER it is a special abbreviation,
3044 unless the CPLUS_MARKER is followed by an underscore, in
3045 which case it is just the name of an anonymous type, which we
3046 should handle like any other type name. */
3048 if (is_cplus_marker (p
[0]) && p
[1] != '_')
3050 if (!read_cpp_abbrev (fip
, pp
, type
, objfile
))
3055 /* Look for the ':' that separates the field name from the field
3056 values. Data members are delimited by a single ':', while member
3057 functions are delimited by a pair of ':'s. When we hit the member
3058 functions (if any), terminate scan loop and return. */
3060 while (*p
!= ':' && *p
!= '\0')
3067 /* Check to see if we have hit the member functions yet. */
3072 read_one_struct_field (fip
, pp
, p
, type
, objfile
);
3074 if (p
[0] == ':' && p
[1] == ':')
3076 /* chill the list of fields: the last entry (at the head) is a
3077 partially constructed entry which we now scrub. */
3078 fip
-> list
= fip
-> list
-> next
;
3083 /* The stabs for C++ derived classes contain baseclass information which
3084 is marked by a '!' character after the total size. This function is
3085 called when we encounter the baseclass marker, and slurps up all the
3086 baseclass information.
3088 Immediately following the '!' marker is the number of base classes that
3089 the class is derived from, followed by information for each base class.
3090 For each base class, there are two visibility specifiers, a bit offset
3091 to the base class information within the derived class, a reference to
3092 the type for the base class, and a terminating semicolon.
3094 A typical example, with two base classes, would be "!2,020,19;0264,21;".
3096 Baseclass information marker __________________|| | | | | | |
3097 Number of baseclasses __________________________| | | | | | |
3098 Visibility specifiers (2) ________________________| | | | | |
3099 Offset in bits from start of class _________________| | | | |
3100 Type number for base class ___________________________| | | |
3101 Visibility specifiers (2) _______________________________| | |
3102 Offset in bits from start of class ________________________| |
3103 Type number of base class ____________________________________|
3105 Return 1 for success, 0 for (error-type-inducing) failure. */
3108 read_baseclasses (fip
, pp
, type
, objfile
)
3109 struct field_info
*fip
;
3112 struct objfile
*objfile
;
3115 struct nextfield
*new;
3123 /* Skip the '!' baseclass information marker. */
3127 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3130 TYPE_N_BASECLASSES (type
) = read_huge_number (pp
, ',', &nbits
);
3136 /* Some stupid compilers have trouble with the following, so break
3137 it up into simpler expressions. */
3138 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*)
3139 TYPE_ALLOC (type
, B_BYTES (TYPE_N_BASECLASSES (type
)));
3142 int num_bytes
= B_BYTES (TYPE_N_BASECLASSES (type
));
3145 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
3146 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
3150 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), TYPE_N_BASECLASSES (type
));
3152 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
3154 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3155 make_cleanup (free
, new);
3156 memset (new, 0, sizeof (struct nextfield
));
3157 new -> next
= fip
-> list
;
3159 new -> field
.bitsize
= 0; /* this should be an unpacked field! */
3161 STABS_CONTINUE (pp
, objfile
);
3165 /* Nothing to do. */
3168 SET_TYPE_FIELD_VIRTUAL (type
, i
);
3171 /* Unknown character. Complain and treat it as non-virtual. */
3173 static struct complaint msg
= {
3174 "Unknown virtual character `%c' for baseclass", 0, 0};
3175 complain (&msg
, **pp
);
3180 new -> visibility
= *(*pp
)++;
3181 switch (new -> visibility
)
3183 case VISIBILITY_PRIVATE
:
3184 case VISIBILITY_PROTECTED
:
3185 case VISIBILITY_PUBLIC
:
3188 /* Bad visibility format. Complain and treat it as
3191 static struct complaint msg
= {
3192 "Unknown visibility `%c' for baseclass", 0, 0};
3193 complain (&msg
, new -> visibility
);
3194 new -> visibility
= VISIBILITY_PUBLIC
;
3201 /* The remaining value is the bit offset of the portion of the object
3202 corresponding to this baseclass. Always zero in the absence of
3203 multiple inheritance. */
3205 new -> field
.bitpos
= read_huge_number (pp
, ',', &nbits
);
3210 /* The last piece of baseclass information is the type of the
3211 base class. Read it, and remember it's type name as this
3214 new -> field
.type
= read_type (pp
, objfile
);
3215 new -> field
.name
= type_name_no_tag (new -> field
.type
);
3217 /* skip trailing ';' and bump count of number of fields seen */
3226 /* The tail end of stabs for C++ classes that contain a virtual function
3227 pointer contains a tilde, a %, and a type number.
3228 The type number refers to the base class (possibly this class itself) which
3229 contains the vtable pointer for the current class.
3231 This function is called when we have parsed all the method declarations,
3232 so we can look for the vptr base class info. */
3235 read_tilde_fields (fip
, pp
, type
, objfile
)
3236 struct field_info
*fip
;
3239 struct objfile
*objfile
;
3243 STABS_CONTINUE (pp
, objfile
);
3245 /* If we are positioned at a ';', then skip it. */
3255 if (**pp
== '=' || **pp
== '+' || **pp
== '-')
3257 /* Obsolete flags that used to indicate the presence
3258 of constructors and/or destructors. */
3262 /* Read either a '%' or the final ';'. */
3263 if (*(*pp
)++ == '%')
3265 /* The next number is the type number of the base class
3266 (possibly our own class) which supplies the vtable for
3267 this class. Parse it out, and search that class to find
3268 its vtable pointer, and install those into TYPE_VPTR_BASETYPE
3269 and TYPE_VPTR_FIELDNO. */
3274 t
= read_type (pp
, objfile
);
3276 while (*p
!= '\0' && *p
!= ';')
3282 /* Premature end of symbol. */
3286 TYPE_VPTR_BASETYPE (type
) = t
;
3287 if (type
== t
) /* Our own class provides vtbl ptr */
3289 for (i
= TYPE_NFIELDS (t
) - 1;
3290 i
>= TYPE_N_BASECLASSES (t
);
3293 if (! strncmp (TYPE_FIELD_NAME (t
, i
), vptr_name
,
3294 sizeof (vptr_name
) - 1))
3296 TYPE_VPTR_FIELDNO (type
) = i
;
3300 /* Virtual function table field not found. */
3301 complain (&vtbl_notfound_complaint
, TYPE_NAME (type
));
3306 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
3317 attach_fn_fields_to_type (fip
, type
)
3318 struct field_info
*fip
;
3319 register struct type
*type
;
3323 for (n
= TYPE_NFN_FIELDS (type
);
3324 fip
-> fnlist
!= NULL
;
3325 fip
-> fnlist
= fip
-> fnlist
-> next
)
3327 --n
; /* Circumvent Sun3 compiler bug */
3328 TYPE_FN_FIELDLISTS (type
)[n
] = fip
-> fnlist
-> fn_fieldlist
;
3333 /* read cfront class static data.
3334 pp points to string starting with the list of static data
3335 eg: A:ZcA;1@Bpub v2@Bvirpri;__ct__1AFv func__1AFv *sfunc__1AFv ;as__1A ;;
3338 A:ZcA;;foopri__1AFv foopro__1AFv __ct__1AFv __ct__1AFRC1A foopub__1AFv ;;;
3343 read_cfront_static_fields(fip
, pp
, type
, objfile
)
3344 struct field_info
*fip
;
3347 struct objfile
*objfile
;
3349 int nfields
= TYPE_NFIELDS(type
);
3351 struct nextfield
* new;
3354 struct symbol
* ref_static
=0;
3356 if (**pp
==';') /* no static data; return */
3362 /* Process each field in the list until we find the terminating ";" */
3364 /* eg: p = "as__1A ;;;" */
3365 STABS_CONTINUE (pp
, objfile
); /* handle \\ */
3366 while (**pp
!=';' && (sname
= get_substring(pp
,' '),sname
))
3368 ref_static
= lookup_symbol (sname
, 0, VAR_NAMESPACE
, 0, 0); /*demangled_name*/
3371 static struct complaint msg
= {"\
3372 Unable to find symbol for static data field %s\n",
3374 complain (&msg
, sname
);
3377 stype
= SYMBOL_TYPE(ref_static
);
3379 /* allocate a new fip */
3380 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3381 make_cleanup (free
, new);
3382 memset (new, 0, sizeof (struct nextfield
));
3383 new -> next
= fip
-> list
;
3386 /* set visibility */
3387 /* FIXME! no way to tell visibility from stabs??? */
3388 new -> visibility
= VISIBILITY_PUBLIC
;
3390 /* set field info into fip */
3391 fip
-> list
-> field
.type
= stype
;
3393 /* set bitpos & bitsize */
3394 fip
-> list
-> field
.bitpos
= (long) -1; /* -1 signifies a static member */
3395 /* YUK! what a hack! bitsize used for physname when field is static */
3396 fip
-> list
-> field
.bitsize
= (long) savestring (sname
, strlen(sname
));
3398 /* set name field */
3399 /* The following is code to work around cfront generated stabs.
3400 The stabs contains full mangled name for each field.
3401 We try to demangle the name and extract the field name out of it.
3406 dem
= cplus_demangle (sname
, DMGL_ANSI
| DMGL_PARAMS
);
3409 dem_p
= strrchr (dem
, ':');
3410 if (dem_p
!= 0 && *(dem_p
-1)==':')
3412 fip
->list
->field
.name
=
3413 obsavestring (dem_p
, strlen(dem_p
), &objfile
-> type_obstack
);
3417 fip
->list
->field
.name
=
3418 obsavestring (sname
, strlen(sname
), &objfile
-> type_obstack
);
3420 } /* end of code for cfront work around */
3421 } /* loop again for next static field */
3425 /* Copy structure fields to fip so attach_fields_to_type will work.
3426 type has already been created with the initial instance data fields.
3427 Now we want to be able to add the other members to the class,
3428 so we want to add them back to the fip and reattach them again
3429 once we have collected all the class members. */
3432 copy_cfront_struct_fields(fip
, type
, objfile
)
3433 struct field_info
*fip
;
3435 struct objfile
*objfile
;
3437 int nfields
= TYPE_NFIELDS(type
);
3439 struct nextfield
* new;
3441 /* Copy the fields into the list of fips and reset the types
3442 to remove the old fields */
3444 for (i
=0; i
<nfields
; i
++)
3446 /* allocate a new fip */
3447 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3448 make_cleanup (free
, new);
3449 memset (new, 0, sizeof (struct nextfield
));
3450 new -> next
= fip
-> list
;
3453 /* copy field info into fip */
3454 new -> field
= TYPE_FIELD (type
, i
);
3455 /* set visibility */
3456 if (TYPE_FIELD_PROTECTED (type
, i
))
3457 new -> visibility
= VISIBILITY_PROTECTED
;
3458 else if (TYPE_FIELD_PRIVATE (type
, i
))
3459 new -> visibility
= VISIBILITY_PRIVATE
;
3461 new -> visibility
= VISIBILITY_PUBLIC
;
3463 /* Now delete the fields from the type since we will be
3464 allocing new space once we get the rest of the fields
3465 in attach_fields_to_type.
3466 The pointer TYPE_FIELDS(type) is left dangling but should
3467 be freed later by objstack_free */
3468 TYPE_FIELDS (type
)=0;
3469 TYPE_NFIELDS (type
) = 0;
3474 /* Create the vector of fields, and record how big it is.
3475 We need this info to record proper virtual function table information
3476 for this class's virtual functions. */
3479 attach_fields_to_type (fip
, type
, objfile
)
3480 struct field_info
*fip
;
3481 register struct type
*type
;
3482 struct objfile
*objfile
;
3484 register int nfields
= 0;
3485 register int non_public_fields
= 0;
3486 register struct nextfield
*scan
;
3488 /* Count up the number of fields that we have, as well as taking note of
3489 whether or not there are any non-public fields, which requires us to
3490 allocate and build the private_field_bits and protected_field_bits
3493 for (scan
= fip
-> list
; scan
!= NULL
; scan
= scan
-> next
)
3496 if (scan
-> visibility
!= VISIBILITY_PUBLIC
)
3498 non_public_fields
++;
3502 /* Now we know how many fields there are, and whether or not there are any
3503 non-public fields. Record the field count, allocate space for the
3504 array of fields, and create blank visibility bitfields if necessary. */
3506 TYPE_NFIELDS (type
) = nfields
;
3507 TYPE_FIELDS (type
) = (struct field
*)
3508 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
3509 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
3511 if (non_public_fields
)
3513 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3515 TYPE_FIELD_PRIVATE_BITS (type
) =
3516 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3517 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
3519 TYPE_FIELD_PROTECTED_BITS (type
) =
3520 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3521 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
3523 TYPE_FIELD_IGNORE_BITS (type
) =
3524 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3525 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
3528 /* Copy the saved-up fields into the field vector. Start from the head
3529 of the list, adding to the tail of the field array, so that they end
3530 up in the same order in the array in which they were added to the list. */
3532 while (nfields
-- > 0)
3534 TYPE_FIELD (type
, nfields
) = fip
-> list
-> field
;
3535 switch (fip
-> list
-> visibility
)
3537 case VISIBILITY_PRIVATE
:
3538 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
3541 case VISIBILITY_PROTECTED
:
3542 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
3545 case VISIBILITY_IGNORE
:
3546 SET_TYPE_FIELD_IGNORE (type
, nfields
);
3549 case VISIBILITY_PUBLIC
:
3553 /* Unknown visibility. Complain and treat it as public. */
3555 static struct complaint msg
= {
3556 "Unknown visibility `%c' for field", 0, 0};
3557 complain (&msg
, fip
-> list
-> visibility
);
3561 fip
-> list
= fip
-> list
-> next
;
3566 /* Read the description of a structure (or union type) and return an object
3567 describing the type.
3569 PP points to a character pointer that points to the next unconsumed token
3570 in the the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
3571 *PP will point to "4a:1,0,32;;".
3573 TYPE points to an incomplete type that needs to be filled in.
3575 OBJFILE points to the current objfile from which the stabs information is
3576 being read. (Note that it is redundant in that TYPE also contains a pointer
3577 to this same objfile, so it might be a good idea to eliminate it. FIXME).
3580 static struct type
*
3581 read_struct_type (pp
, type
, objfile
)
3584 struct objfile
*objfile
;
3586 struct cleanup
*back_to
;
3587 struct field_info fi
;
3592 back_to
= make_cleanup (null_cleanup
, 0);
3594 INIT_CPLUS_SPECIFIC (type
);
3595 TYPE_FLAGS (type
) &= ~TYPE_FLAG_STUB
;
3597 /* First comes the total size in bytes. */
3601 TYPE_LENGTH (type
) = read_huge_number (pp
, 0, &nbits
);
3603 return error_type (pp
, objfile
);
3606 /* Now read the baseclasses, if any, read the regular C struct or C++
3607 class member fields, attach the fields to the type, read the C++
3608 member functions, attach them to the type, and then read any tilde
3609 field (baseclass specifier for the class holding the main vtable). */
3611 if (!read_baseclasses (&fi
, pp
, type
, objfile
)
3612 || !read_struct_fields (&fi
, pp
, type
, objfile
)
3613 || !attach_fields_to_type (&fi
, type
, objfile
)
3614 || !read_member_functions (&fi
, pp
, type
, objfile
)
3615 || !attach_fn_fields_to_type (&fi
, type
)
3616 || !read_tilde_fields (&fi
, pp
, type
, objfile
))
3618 type
= error_type (pp
, objfile
);
3621 do_cleanups (back_to
);
3625 /* Read a definition of an array type,
3626 and create and return a suitable type object.
3627 Also creates a range type which represents the bounds of that
3630 static struct type
*
3631 read_array_type (pp
, type
, objfile
)
3633 register struct type
*type
;
3634 struct objfile
*objfile
;
3636 struct type
*index_type
, *element_type
, *range_type
;
3641 /* Format of an array type:
3642 "ar<index type>;lower;upper;<array_contents_type>".
3643 OS9000: "arlower,upper;<array_contents_type>".
3645 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
3646 for these, produce a type like float[][]. */
3649 index_type
= builtin_type_int
;
3652 index_type
= read_type (pp
, objfile
);
3654 /* Improper format of array type decl. */
3655 return error_type (pp
, objfile
);
3659 if (!(**pp
>= '0' && **pp
<= '9') && **pp
!= '-')
3664 lower
= read_huge_number (pp
, os9k_stabs
? ',' : ';', &nbits
);
3666 return error_type (pp
, objfile
);
3668 if (!(**pp
>= '0' && **pp
<= '9') && **pp
!= '-')
3673 upper
= read_huge_number (pp
, ';', &nbits
);
3675 return error_type (pp
, objfile
);
3677 element_type
= read_type (pp
, objfile
);
3686 create_range_type ((struct type
*) NULL
, index_type
, lower
, upper
);
3687 type
= create_array_type (type
, element_type
, range_type
);
3693 /* Read a definition of an enumeration type,
3694 and create and return a suitable type object.
3695 Also defines the symbols that represent the values of the type. */
3697 static struct type
*
3698 read_enum_type (pp
, type
, objfile
)
3700 register struct type
*type
;
3701 struct objfile
*objfile
;
3706 register struct symbol
*sym
;
3708 struct pending
**symlist
;
3709 struct pending
*osyms
, *syms
;
3712 int unsigned_enum
= 1;
3715 /* FIXME! The stabs produced by Sun CC merrily define things that ought
3716 to be file-scope, between N_FN entries, using N_LSYM. What's a mother
3717 to do? For now, force all enum values to file scope. */
3718 if (within_function
)
3719 symlist
= &local_symbols
;
3722 symlist
= &file_symbols
;
3724 o_nsyms
= osyms
? osyms
->nsyms
: 0;
3728 /* Size. Perhaps this does not have to be conditionalized on
3729 os9k_stabs (assuming the name of an enum constant can't start
3731 read_huge_number (pp
, 0, &nbits
);
3733 return error_type (pp
, objfile
);
3736 /* The aix4 compiler emits an extra field before the enum members;
3737 my guess is it's a type of some sort. Just ignore it. */
3740 /* Skip over the type. */
3744 /* Skip over the colon. */
3748 /* Read the value-names and their values.
3749 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
3750 A semicolon or comma instead of a NAME means the end. */
3751 while (**pp
&& **pp
!= ';' && **pp
!= ',')
3753 STABS_CONTINUE (pp
, objfile
);
3755 while (*p
!= ':') p
++;
3756 name
= obsavestring (*pp
, p
- *pp
, &objfile
-> symbol_obstack
);
3758 n
= read_huge_number (pp
, ',', &nbits
);
3760 return error_type (pp
, objfile
);
3762 sym
= (struct symbol
*)
3763 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
3764 memset (sym
, 0, sizeof (struct symbol
));
3765 SYMBOL_NAME (sym
) = name
;
3766 SYMBOL_LANGUAGE (sym
) = current_subfile
-> language
;
3767 SYMBOL_CLASS (sym
) = LOC_CONST
;
3768 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
3769 SYMBOL_VALUE (sym
) = n
;
3772 add_symbol_to_list (sym
, symlist
);
3777 (*pp
)++; /* Skip the semicolon. */
3779 /* Now fill in the fields of the type-structure. */
3781 TYPE_LENGTH (type
) = TARGET_INT_BIT
/ HOST_CHAR_BIT
;
3782 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
3783 TYPE_FLAGS (type
) &= ~TYPE_FLAG_STUB
;
3785 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
3786 TYPE_NFIELDS (type
) = nsyms
;
3787 TYPE_FIELDS (type
) = (struct field
*)
3788 TYPE_ALLOC (type
, sizeof (struct field
) * nsyms
);
3789 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nsyms
);
3791 /* Find the symbols for the values and put them into the type.
3792 The symbols can be found in the symlist that we put them on
3793 to cause them to be defined. osyms contains the old value
3794 of that symlist; everything up to there was defined by us. */
3795 /* Note that we preserve the order of the enum constants, so
3796 that in something like "enum {FOO, LAST_THING=FOO}" we print
3797 FOO, not LAST_THING. */
3799 for (syms
= *symlist
, n
= nsyms
- 1; syms
; syms
= syms
->next
)
3801 int last
= syms
== osyms
? o_nsyms
: 0;
3802 int j
= syms
->nsyms
;
3803 for (; --j
>= last
; --n
)
3805 struct symbol
*xsym
= syms
->symbol
[j
];
3806 SYMBOL_TYPE (xsym
) = type
;
3807 TYPE_FIELD_NAME (type
, n
) = SYMBOL_NAME (xsym
);
3808 TYPE_FIELD_VALUE (type
, n
) = 0;
3809 TYPE_FIELD_BITPOS (type
, n
) = SYMBOL_VALUE (xsym
);
3810 TYPE_FIELD_BITSIZE (type
, n
) = 0;
3819 /* Sun's ACC uses a somewhat saner method for specifying the builtin
3820 typedefs in every file (for int, long, etc):
3822 type = b <signed> <width>; <offset>; <nbits>
3823 signed = u or s. Possible c in addition to u or s (for char?).
3824 offset = offset from high order bit to start bit of type.
3825 width is # bytes in object of this type, nbits is # bits in type.
3827 The width/offset stuff appears to be for small objects stored in
3828 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
3831 static struct type
*
3832 read_sun_builtin_type (pp
, typenums
, objfile
)
3835 struct objfile
*objfile
;
3850 return error_type (pp
, objfile
);
3854 /* For some odd reason, all forms of char put a c here. This is strange
3855 because no other type has this honor. We can safely ignore this because
3856 we actually determine 'char'acterness by the number of bits specified in
3862 /* The first number appears to be the number of bytes occupied
3863 by this type, except that unsigned short is 4 instead of 2.
3864 Since this information is redundant with the third number,
3865 we will ignore it. */
3866 read_huge_number (pp
, ';', &nbits
);
3868 return error_type (pp
, objfile
);
3870 /* The second number is always 0, so ignore it too. */
3871 read_huge_number (pp
, ';', &nbits
);
3873 return error_type (pp
, objfile
);
3875 /* The third number is the number of bits for this type. */
3876 type_bits
= read_huge_number (pp
, 0, &nbits
);
3878 return error_type (pp
, objfile
);
3879 /* The type *should* end with a semicolon. If it are embedded
3880 in a larger type the semicolon may be the only way to know where
3881 the type ends. If this type is at the end of the stabstring we
3882 can deal with the omitted semicolon (but we don't have to like
3883 it). Don't bother to complain(), Sun's compiler omits the semicolon
3889 return init_type (TYPE_CODE_VOID
, 1,
3890 signed_type
? 0 : TYPE_FLAG_UNSIGNED
, (char *)NULL
,
3893 return init_type (TYPE_CODE_INT
,
3894 type_bits
/ TARGET_CHAR_BIT
,
3895 signed_type
? 0 : TYPE_FLAG_UNSIGNED
, (char *)NULL
,
3899 static struct type
*
3900 read_sun_floating_type (pp
, typenums
, objfile
)
3903 struct objfile
*objfile
;
3909 /* The first number has more details about the type, for example
3911 details
= read_huge_number (pp
, ';', &nbits
);
3913 return error_type (pp
, objfile
);
3915 /* The second number is the number of bytes occupied by this type */
3916 nbytes
= read_huge_number (pp
, ';', &nbits
);
3918 return error_type (pp
, objfile
);
3920 if (details
== NF_COMPLEX
|| details
== NF_COMPLEX16
3921 || details
== NF_COMPLEX32
)
3922 /* This is a type we can't handle, but we do know the size.
3923 We also will be able to give it a name. */
3924 return init_type (TYPE_CODE_ERROR
, nbytes
, 0, NULL
, objfile
);
3926 return init_type (TYPE_CODE_FLT
, nbytes
, 0, NULL
, objfile
);
3929 /* Read a number from the string pointed to by *PP.
3930 The value of *PP is advanced over the number.
3931 If END is nonzero, the character that ends the
3932 number must match END, or an error happens;
3933 and that character is skipped if it does match.
3934 If END is zero, *PP is left pointing to that character.
3936 If the number fits in a long, set *BITS to 0 and return the value.
3937 If not, set *BITS to be the number of bits in the number and return 0.
3939 If encounter garbage, set *BITS to -1 and return 0. */
3942 read_huge_number (pp
, end
, bits
)
3962 /* Leading zero means octal. GCC uses this to output values larger
3963 than an int (because that would be hard in decimal). */
3971 upper_limit
= ULONG_MAX
/ radix
;
3973 upper_limit
= LONG_MAX
/ radix
;
3975 while ((c
= *p
++) >= '0' && c
< ('0' + radix
))
3977 if (n
<= upper_limit
)
3980 n
+= c
- '0'; /* FIXME this overflows anyway */
3985 /* This depends on large values being output in octal, which is
3992 /* Ignore leading zeroes. */
3996 else if (c
== '2' || c
== '3')
4022 /* Large decimal constants are an error (because it is hard to
4023 count how many bits are in them). */
4029 /* -0x7f is the same as 0x80. So deal with it by adding one to
4030 the number of bits. */
4042 /* It's *BITS which has the interesting information. */
4046 static struct type
*
4047 read_range_type (pp
, typenums
, objfile
)
4050 struct objfile
*objfile
;
4052 char *orig_pp
= *pp
;
4057 struct type
*result_type
;
4058 struct type
*index_type
= NULL
;
4060 /* First comes a type we are a subrange of.
4061 In C it is usually 0, 1 or the type being defined. */
4062 if (read_type_number (pp
, rangenums
) != 0)
4063 return error_type (pp
, objfile
);
4064 self_subrange
= (rangenums
[0] == typenums
[0] &&
4065 rangenums
[1] == typenums
[1]);
4070 index_type
= read_type (pp
, objfile
);
4073 /* A semicolon should now follow; skip it. */
4077 /* The remaining two operands are usually lower and upper bounds
4078 of the range. But in some special cases they mean something else. */
4079 n2
= read_huge_number (pp
, ';', &n2bits
);
4080 n3
= read_huge_number (pp
, ';', &n3bits
);
4082 if (n2bits
== -1 || n3bits
== -1)
4083 return error_type (pp
, objfile
);
4086 goto handle_true_range
;
4088 /* If limits are huge, must be large integral type. */
4089 if (n2bits
!= 0 || n3bits
!= 0)
4091 char got_signed
= 0;
4092 char got_unsigned
= 0;
4093 /* Number of bits in the type. */
4096 /* Range from 0 to <large number> is an unsigned large integral type. */
4097 if ((n2bits
== 0 && n2
== 0) && n3bits
!= 0)
4102 /* Range from <large number> to <large number>-1 is a large signed
4103 integral type. Take care of the case where <large number> doesn't
4104 fit in a long but <large number>-1 does. */
4105 else if ((n2bits
!= 0 && n3bits
!= 0 && n2bits
== n3bits
+ 1)
4106 || (n2bits
!= 0 && n3bits
== 0
4107 && (n2bits
== sizeof (long) * HOST_CHAR_BIT
)
4114 if (got_signed
|| got_unsigned
)
4116 return init_type (TYPE_CODE_INT
, nbits
/ TARGET_CHAR_BIT
,
4117 got_unsigned
? TYPE_FLAG_UNSIGNED
: 0, NULL
,
4121 return error_type (pp
, objfile
);
4124 /* A type defined as a subrange of itself, with bounds both 0, is void. */
4125 if (self_subrange
&& n2
== 0 && n3
== 0)
4126 return init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
4128 /* If n3 is zero and n2 is positive, we want a floating type,
4129 and n2 is the width in bytes.
4131 Fortran programs appear to use this for complex types also,
4132 and they give no way to distinguish between double and single-complex!
4134 GDB does not have complex types.
4136 Just return the complex as a float of that size. It won't work right
4137 for the complex values, but at least it makes the file loadable. */
4139 if (n3
== 0 && n2
> 0)
4141 return init_type (TYPE_CODE_FLT
, n2
, 0, NULL
, objfile
);
4144 /* If the upper bound is -1, it must really be an unsigned int. */
4146 else if (n2
== 0 && n3
== -1)
4148 /* It is unsigned int or unsigned long. */
4149 /* GCC 2.3.3 uses this for long long too, but that is just a GDB 3.5
4150 compatibility hack. */
4151 return init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
4152 TYPE_FLAG_UNSIGNED
, NULL
, objfile
);
4155 /* Special case: char is defined (Who knows why) as a subrange of
4156 itself with range 0-127. */
4157 else if (self_subrange
&& n2
== 0 && n3
== 127)
4158 return init_type (TYPE_CODE_INT
, 1, 0, NULL
, objfile
);
4160 else if (current_symbol
&& SYMBOL_LANGUAGE (current_symbol
) == language_chill
4162 goto handle_true_range
;
4164 /* We used to do this only for subrange of self or subrange of int. */
4168 /* n3 actually gives the size. */
4169 return init_type (TYPE_CODE_INT
, - n3
, TYPE_FLAG_UNSIGNED
,
4172 return init_type (TYPE_CODE_INT
, 1, TYPE_FLAG_UNSIGNED
, NULL
, objfile
);
4174 return init_type (TYPE_CODE_INT
, 2, TYPE_FLAG_UNSIGNED
, NULL
, objfile
);
4176 /* -1 is used for the upper bound of (4 byte) "unsigned int" and
4177 "unsigned long", and we already checked for that,
4178 so don't need to test for it here. */
4180 /* I think this is for Convex "long long". Since I don't know whether
4181 Convex sets self_subrange, I also accept that particular size regardless
4182 of self_subrange. */
4183 else if (n3
== 0 && n2
< 0
4185 || n2
== - TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
))
4186 return init_type (TYPE_CODE_INT
, - n2
, 0, NULL
, objfile
);
4187 else if (n2
== -n3
-1)
4190 return init_type (TYPE_CODE_INT
, 1, 0, NULL
, objfile
);
4192 return init_type (TYPE_CODE_INT
, 2, 0, NULL
, objfile
);
4193 if (n3
== 0x7fffffff)
4194 return init_type (TYPE_CODE_INT
, 4, 0, NULL
, objfile
);
4197 /* We have a real range type on our hands. Allocate space and
4198 return a real pointer. */
4202 index_type
= builtin_type_int
;
4204 index_type
= *dbx_lookup_type (rangenums
);
4205 if (index_type
== NULL
)
4207 /* Does this actually ever happen? Is that why we are worrying
4208 about dealing with it rather than just calling error_type? */
4210 static struct type
*range_type_index
;
4212 complain (&range_type_base_complaint
, rangenums
[1]);
4213 if (range_type_index
== NULL
)
4215 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
4216 0, "range type index type", NULL
);
4217 index_type
= range_type_index
;
4220 result_type
= create_range_type ((struct type
*) NULL
, index_type
, n2
, n3
);
4221 return (result_type
);
4224 /* Read in an argument list. This is a list of types, separated by commas
4225 and terminated with END. Return the list of types read in, or (struct type
4226 **)-1 if there is an error. */
4228 static struct type
**
4229 read_args (pp
, end
, objfile
)
4232 struct objfile
*objfile
;
4234 /* FIXME! Remove this arbitrary limit! */
4235 struct type
*types
[1024], **rval
; /* allow for fns of 1023 parameters */
4241 /* Invalid argument list: no ','. */
4242 return (struct type
**)-1;
4244 STABS_CONTINUE (pp
, objfile
);
4245 types
[n
++] = read_type (pp
, objfile
);
4247 (*pp
)++; /* get past `end' (the ':' character) */
4251 rval
= (struct type
**) xmalloc (2 * sizeof (struct type
*));
4253 else if (TYPE_CODE (types
[n
-1]) != TYPE_CODE_VOID
)
4255 rval
= (struct type
**) xmalloc ((n
+ 1) * sizeof (struct type
*));
4256 memset (rval
+ n
, 0, sizeof (struct type
*));
4260 rval
= (struct type
**) xmalloc (n
* sizeof (struct type
*));
4262 memcpy (rval
, types
, n
* sizeof (struct type
*));
4266 /* Common block handling. */
4268 /* List of symbols declared since the last BCOMM. This list is a tail
4269 of local_symbols. When ECOMM is seen, the symbols on the list
4270 are noted so their proper addresses can be filled in later,
4271 using the common block base address gotten from the assembler
4274 static struct pending
*common_block
;
4275 static int common_block_i
;
4277 /* Name of the current common block. We get it from the BCOMM instead of the
4278 ECOMM to match IBM documentation (even though IBM puts the name both places
4279 like everyone else). */
4280 static char *common_block_name
;
4282 /* Process a N_BCOMM symbol. The storage for NAME is not guaranteed
4283 to remain after this function returns. */
4286 common_block_start (name
, objfile
)
4288 struct objfile
*objfile
;
4290 if (common_block_name
!= NULL
)
4292 static struct complaint msg
= {
4293 "Invalid symbol data: common block within common block",
4297 common_block
= local_symbols
;
4298 common_block_i
= local_symbols
? local_symbols
->nsyms
: 0;
4299 common_block_name
= obsavestring (name
, strlen (name
),
4300 &objfile
-> symbol_obstack
);
4303 /* Process a N_ECOMM symbol. */
4306 common_block_end (objfile
)
4307 struct objfile
*objfile
;
4309 /* Symbols declared since the BCOMM are to have the common block
4310 start address added in when we know it. common_block and
4311 common_block_i point to the first symbol after the BCOMM in
4312 the local_symbols list; copy the list and hang it off the
4313 symbol for the common block name for later fixup. */
4316 struct pending
*new = 0;
4317 struct pending
*next
;
4320 if (common_block_name
== NULL
)
4322 static struct complaint msg
= {"ECOMM symbol unmatched by BCOMM", 0, 0};
4327 sym
= (struct symbol
*)
4328 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
4329 memset (sym
, 0, sizeof (struct symbol
));
4330 SYMBOL_NAME (sym
) = common_block_name
;
4331 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
4333 /* Now we copy all the symbols which have been defined since the BCOMM. */
4335 /* Copy all the struct pendings before common_block. */
4336 for (next
= local_symbols
;
4337 next
!= NULL
&& next
!= common_block
;
4340 for (j
= 0; j
< next
->nsyms
; j
++)
4341 add_symbol_to_list (next
->symbol
[j
], &new);
4344 /* Copy however much of COMMON_BLOCK we need. If COMMON_BLOCK is
4345 NULL, it means copy all the local symbols (which we already did
4348 if (common_block
!= NULL
)
4349 for (j
= common_block_i
; j
< common_block
->nsyms
; j
++)
4350 add_symbol_to_list (common_block
->symbol
[j
], &new);
4352 SYMBOL_TYPE (sym
) = (struct type
*) new;
4354 /* Should we be putting local_symbols back to what it was?
4357 i
= hashname (SYMBOL_NAME (sym
));
4358 SYMBOL_VALUE_CHAIN (sym
) = global_sym_chain
[i
];
4359 global_sym_chain
[i
] = sym
;
4360 common_block_name
= NULL
;
4363 /* Add a common block's start address to the offset of each symbol
4364 declared to be in it (by being between a BCOMM/ECOMM pair that uses
4365 the common block name). */
4368 fix_common_block (sym
, valu
)
4372 struct pending
*next
= (struct pending
*) SYMBOL_TYPE (sym
);
4373 for ( ; next
; next
= next
->next
)
4376 for (j
= next
->nsyms
- 1; j
>= 0; j
--)
4377 SYMBOL_VALUE_ADDRESS (next
->symbol
[j
]) += valu
;
4383 /* What about types defined as forward references inside of a small lexical
4385 /* Add a type to the list of undefined types to be checked through
4386 once this file has been read in. */
4389 add_undefined_type (type
)
4392 if (undef_types_length
== undef_types_allocated
)
4394 undef_types_allocated
*= 2;
4395 undef_types
= (struct type
**)
4396 xrealloc ((char *) undef_types
,
4397 undef_types_allocated
* sizeof (struct type
*));
4399 undef_types
[undef_types_length
++] = type
;
4402 /* Go through each undefined type, see if it's still undefined, and fix it
4403 up if possible. We have two kinds of undefined types:
4405 TYPE_CODE_ARRAY: Array whose target type wasn't defined yet.
4406 Fix: update array length using the element bounds
4407 and the target type's length.
4408 TYPE_CODE_STRUCT, TYPE_CODE_UNION: Structure whose fields were not
4409 yet defined at the time a pointer to it was made.
4410 Fix: Do a full lookup on the struct/union tag. */
4412 cleanup_undefined_types ()
4416 for (type
= undef_types
; type
< undef_types
+ undef_types_length
; type
++)
4418 switch (TYPE_CODE (*type
))
4421 case TYPE_CODE_STRUCT
:
4422 case TYPE_CODE_UNION
:
4423 case TYPE_CODE_ENUM
:
4425 /* Check if it has been defined since. Need to do this here
4426 as well as in check_typedef to deal with the (legitimate in
4427 C though not C++) case of several types with the same name
4428 in different source files. */
4429 if (TYPE_FLAGS (*type
) & TYPE_FLAG_STUB
)
4431 struct pending
*ppt
;
4433 /* Name of the type, without "struct" or "union" */
4434 char *typename
= TYPE_TAG_NAME (*type
);
4436 if (typename
== NULL
)
4438 static struct complaint msg
= {"need a type name", 0, 0};
4442 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
4444 for (i
= 0; i
< ppt
->nsyms
; i
++)
4446 struct symbol
*sym
= ppt
->symbol
[i
];
4448 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
4449 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
4450 && (TYPE_CODE (SYMBOL_TYPE (sym
)) ==
4452 && STREQ (SYMBOL_NAME (sym
), typename
))
4454 memcpy (*type
, SYMBOL_TYPE (sym
),
4455 sizeof (struct type
));
4465 static struct complaint msg
= {"\
4466 GDB internal error. cleanup_undefined_types with bad type %d.", 0, 0};
4467 complain (&msg
, TYPE_CODE (*type
));
4473 undef_types_length
= 0;
4476 /* Scan through all of the global symbols defined in the object file,
4477 assigning values to the debugging symbols that need to be assigned
4478 to. Get these symbols from the minimal symbol table. */
4481 scan_file_globals (objfile
)
4482 struct objfile
*objfile
;
4485 struct minimal_symbol
*msymbol
;
4486 struct symbol
*sym
, *prev
;
4488 /* Avoid expensive loop through all minimal symbols if there are
4489 no unresolved symbols. */
4490 for (hash
= 0; hash
< HASHSIZE
; hash
++)
4492 if (global_sym_chain
[hash
])
4495 if (hash
>= HASHSIZE
)
4498 for (msymbol
= objfile
-> msymbols
;
4499 msymbol
&& SYMBOL_NAME (msymbol
) != NULL
;
4504 /* Skip static symbols. */
4505 switch (MSYMBOL_TYPE (msymbol
))
4517 /* Get the hash index and check all the symbols
4518 under that hash index. */
4520 hash
= hashname (SYMBOL_NAME (msymbol
));
4522 for (sym
= global_sym_chain
[hash
]; sym
;)
4524 if (SYMBOL_NAME (msymbol
)[0] == SYMBOL_NAME (sym
)[0] &&
4525 STREQ(SYMBOL_NAME (msymbol
) + 1, SYMBOL_NAME (sym
) + 1))
4527 /* Splice this symbol out of the hash chain and
4528 assign the value we have to it. */
4531 SYMBOL_VALUE_CHAIN (prev
) = SYMBOL_VALUE_CHAIN (sym
);
4535 global_sym_chain
[hash
] = SYMBOL_VALUE_CHAIN (sym
);
4538 /* Check to see whether we need to fix up a common block. */
4539 /* Note: this code might be executed several times for
4540 the same symbol if there are multiple references. */
4542 if (SYMBOL_CLASS (sym
) == LOC_BLOCK
)
4544 fix_common_block (sym
, SYMBOL_VALUE_ADDRESS (msymbol
));
4548 SYMBOL_VALUE_ADDRESS (sym
) = SYMBOL_VALUE_ADDRESS (msymbol
);
4551 SYMBOL_SECTION (sym
) = SYMBOL_SECTION (msymbol
);
4555 sym
= SYMBOL_VALUE_CHAIN (prev
);
4559 sym
= global_sym_chain
[hash
];
4565 sym
= SYMBOL_VALUE_CHAIN (sym
);
4570 /* Change the storage class of any remaining unresolved globals to
4571 LOC_UNRESOLVED and remove them from the chain. */
4572 for (hash
= 0; hash
< HASHSIZE
; hash
++)
4574 sym
= global_sym_chain
[hash
];
4578 sym
= SYMBOL_VALUE_CHAIN (sym
);
4580 /* Change the symbol address from the misleading chain value
4582 SYMBOL_VALUE_ADDRESS (prev
) = 0;
4584 /* Complain about unresolved common block symbols. */
4585 if (SYMBOL_CLASS (prev
) == LOC_STATIC
)
4586 SYMBOL_CLASS (prev
) = LOC_UNRESOLVED
;
4588 complain (&unresolved_sym_chain_complaint
,
4589 objfile
->name
, SYMBOL_NAME (prev
));
4592 memset (global_sym_chain
, 0, sizeof (global_sym_chain
));
4595 /* Initialize anything that needs initializing when starting to read
4596 a fresh piece of a symbol file, e.g. reading in the stuff corresponding
4604 /* Initialize anything that needs initializing when a completely new
4605 symbol file is specified (not just adding some symbols from another
4606 file, e.g. a shared library). */
4609 stabsread_new_init ()
4611 /* Empty the hash table of global syms looking for values. */
4612 memset (global_sym_chain
, 0, sizeof (global_sym_chain
));
4615 /* Initialize anything that needs initializing at the same time as
4616 start_symtab() is called. */
4620 global_stabs
= NULL
; /* AIX COFF */
4621 /* Leave FILENUM of 0 free for builtin types and this file's types. */
4622 n_this_object_header_files
= 1;
4623 type_vector_length
= 0;
4624 type_vector
= (struct type
**) 0;
4626 /* FIXME: If common_block_name is not already NULL, we should complain(). */
4627 common_block_name
= NULL
;
4632 /* Call after end_symtab() */
4638 free ((char *) type_vector
);
4641 type_vector_length
= 0;
4642 previous_stab_code
= 0;
4646 finish_global_stabs (objfile
)
4647 struct objfile
*objfile
;
4651 patch_block_stabs (global_symbols
, global_stabs
, objfile
);
4652 free ((PTR
) global_stabs
);
4653 global_stabs
= NULL
;
4657 /* Initializer for this module */
4660 _initialize_stabsread ()
4662 undef_types_allocated
= 20;
4663 undef_types_length
= 0;
4664 undef_types
= (struct type
**)
4665 xmalloc (undef_types_allocated
* sizeof (struct type
*));