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 static const char vptr_name
[] = { '_','v','p','t','r',CPLUS_MARKER
,'\0' };
147 static const char vb_name
[] = { '_','v','b',CPLUS_MARKER
,'\0' };
149 /* Define this as 1 if a pcc declaration of a char or short argument
150 gives the correct address. Otherwise assume pcc gives the
151 address of the corresponding int, which is not the same on a
152 big-endian machine. */
154 #ifndef BELIEVE_PCC_PROMOTION
155 #define BELIEVE_PCC_PROMOTION 0
158 struct complaint invalid_cpp_abbrev_complaint
=
159 {"invalid C++ abbreviation `%s'", 0, 0};
161 struct complaint invalid_cpp_type_complaint
=
162 {"C++ abbreviated type name unknown at symtab pos %d", 0, 0};
164 struct complaint member_fn_complaint
=
165 {"member function type missing, got '%c'", 0, 0};
167 struct complaint const_vol_complaint
=
168 {"const/volatile indicator missing, got '%c'", 0, 0};
170 struct complaint error_type_complaint
=
171 {"debug info mismatch between compiler and debugger", 0, 0};
173 struct complaint invalid_member_complaint
=
174 {"invalid (minimal) member type data format at symtab pos %d.", 0, 0};
176 struct complaint range_type_base_complaint
=
177 {"base type %d of range type is not defined", 0, 0};
179 struct complaint reg_value_complaint
=
180 {"register number %d too large (max %d) in symbol %s", 0, 0};
182 struct complaint vtbl_notfound_complaint
=
183 {"virtual function table pointer not found when defining class `%s'", 0, 0};
185 struct complaint unrecognized_cplus_name_complaint
=
186 {"Unknown C++ symbol name `%s'", 0, 0};
188 struct complaint rs6000_builtin_complaint
=
189 {"Unknown builtin type %d", 0, 0};
191 struct complaint unresolved_sym_chain_complaint
=
192 {"%s: common block `%s' from global_sym_chain unresolved", 0, 0};
194 struct complaint stabs_general_complaint
=
197 /* Make a list of forward references which haven't been defined. */
199 static struct type
**undef_types
;
200 static int undef_types_allocated
;
201 static int undef_types_length
;
202 static struct symbol
*current_symbol
= NULL
;
204 /* Check for and handle cretinous stabs symbol name continuation! */
205 #define STABS_CONTINUE(pp,objfile) \
207 if (**(pp) == '\\' || (**(pp) == '?' && (*(pp))[1] == '\0')) \
208 *(pp) = next_symbol_text (objfile); \
211 /* FIXME: These probably should be our own types (like rs6000_builtin_type
212 has its own types) rather than builtin_type_*. */
213 static struct type
**os9k_type_vector
[] = {
219 &builtin_type_unsigned_char
,
220 &builtin_type_unsigned_short
,
221 &builtin_type_unsigned_long
,
222 &builtin_type_unsigned_int
,
224 &builtin_type_double
,
226 &builtin_type_long_double
229 static void os9k_init_type_vector
PARAMS ((struct type
**));
232 os9k_init_type_vector(tv
)
236 for (i
=0; i
<sizeof(os9k_type_vector
)/sizeof(struct type
**); i
++)
237 tv
[i
] = (os9k_type_vector
[i
] == 0 ? 0 : *(os9k_type_vector
[i
]));
240 /* Look up a dbx type-number pair. Return the address of the slot
241 where the type for that number-pair is stored.
242 The number-pair is in TYPENUMS.
244 This can be used for finding the type associated with that pair
245 or for associating a new type with the pair. */
248 dbx_lookup_type (typenums
)
251 register int filenum
= typenums
[0];
252 register int index
= typenums
[1];
254 register int real_filenum
;
255 register struct header_file
*f
;
258 if (filenum
== -1) /* -1,-1 is for temporary types. */
261 if (filenum
< 0 || filenum
>= n_this_object_header_files
)
263 static struct complaint msg
= {"\
264 Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.",
266 complain (&msg
, filenum
, index
, symnum
);
274 /* Caller wants address of address of type. We think
275 that negative (rs6k builtin) types will never appear as
276 "lvalues", (nor should they), so we stuff the real type
277 pointer into a temp, and return its address. If referenced,
278 this will do the right thing. */
279 static struct type
*temp_type
;
281 temp_type
= rs6000_builtin_type(index
);
285 /* Type is defined outside of header files.
286 Find it in this object file's type vector. */
287 if (index
>= type_vector_length
)
289 old_len
= type_vector_length
;
292 type_vector_length
= INITIAL_TYPE_VECTOR_LENGTH
;
293 type_vector
= (struct type
**)
294 xmalloc (type_vector_length
* sizeof (struct type
*));
296 while (index
>= type_vector_length
)
298 type_vector_length
*= 2;
300 type_vector
= (struct type
**)
301 xrealloc ((char *) type_vector
,
302 (type_vector_length
* sizeof (struct type
*)));
303 memset (&type_vector
[old_len
], 0,
304 (type_vector_length
- old_len
) * sizeof (struct type
*));
307 /* Deal with OS9000 fundamental types. */
308 os9k_init_type_vector (type_vector
);
310 return (&type_vector
[index
]);
314 real_filenum
= this_object_header_files
[filenum
];
316 if (real_filenum
>= n_header_files
)
318 struct type
*temp_type
;
319 struct type
**temp_type_p
;
321 warning ("GDB internal error: bad real_filenum");
324 temp_type
= init_type (TYPE_CODE_ERROR
, 0, 0, NULL
, NULL
);
325 temp_type_p
= (struct type
**) xmalloc (sizeof (struct type
*));
326 *temp_type_p
= temp_type
;
330 f
= &header_files
[real_filenum
];
332 f_orig_length
= f
->length
;
333 if (index
>= f_orig_length
)
335 while (index
>= f
->length
)
339 f
->vector
= (struct type
**)
340 xrealloc ((char *) f
->vector
, f
->length
* sizeof (struct type
*));
341 memset (&f
->vector
[f_orig_length
], 0,
342 (f
->length
- f_orig_length
) * sizeof (struct type
*));
344 return (&f
->vector
[index
]);
348 /* Make sure there is a type allocated for type numbers TYPENUMS
349 and return the type object.
350 This can create an empty (zeroed) type object.
351 TYPENUMS may be (-1, -1) to return a new type object that is not
352 put into the type vector, and so may not be referred to by number. */
355 dbx_alloc_type (typenums
, objfile
)
357 struct objfile
*objfile
;
359 register struct type
**type_addr
;
361 if (typenums
[0] == -1)
363 return (alloc_type (objfile
));
366 type_addr
= dbx_lookup_type (typenums
);
368 /* If we are referring to a type not known at all yet,
369 allocate an empty type for it.
370 We will fill it in later if we find out how. */
373 *type_addr
= alloc_type (objfile
);
379 /* for all the stabs in a given stab vector, build appropriate types
380 and fix their symbols in given symbol vector. */
383 patch_block_stabs (symbols
, stabs
, objfile
)
384 struct pending
*symbols
;
385 struct pending_stabs
*stabs
;
386 struct objfile
*objfile
;
396 /* for all the stab entries, find their corresponding symbols and
397 patch their types! */
399 for (ii
= 0; ii
< stabs
->count
; ++ii
)
401 name
= stabs
->stab
[ii
];
402 pp
= (char*) strchr (name
, ':');
406 pp
= (char *)strchr(pp
, ':');
408 sym
= find_symbol_in_list (symbols
, name
, pp
-name
);
411 /* FIXME-maybe: it would be nice if we noticed whether
412 the variable was defined *anywhere*, not just whether
413 it is defined in this compilation unit. But neither
414 xlc or GCC seem to need such a definition, and until
415 we do psymtabs (so that the minimal symbols from all
416 compilation units are available now), I'm not sure
417 how to get the information. */
419 /* On xcoff, if a global is defined and never referenced,
420 ld will remove it from the executable. There is then
421 a N_GSYM stab for it, but no regular (C_EXT) symbol. */
422 sym
= (struct symbol
*)
423 obstack_alloc (&objfile
->symbol_obstack
,
424 sizeof (struct symbol
));
426 memset (sym
, 0, sizeof (struct symbol
));
427 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
428 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
430 obstack_copy0 (&objfile
->symbol_obstack
, name
, pp
- name
);
432 if (*(pp
-1) == 'F' || *(pp
-1) == 'f')
434 /* I don't think the linker does this with functions,
435 so as far as I know this is never executed.
436 But it doesn't hurt to check. */
438 lookup_function_type (read_type (&pp
, objfile
));
442 SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
444 add_symbol_to_list (sym
, &global_symbols
);
449 if (*(pp
-1) == 'F' || *(pp
-1) == 'f')
452 lookup_function_type (read_type (&pp
, objfile
));
456 SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
464 /* Read a number by which a type is referred to in dbx data,
465 or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
466 Just a single number N is equivalent to (0,N).
467 Return the two numbers by storing them in the vector TYPENUMS.
468 TYPENUMS will then be used as an argument to dbx_lookup_type.
470 Returns 0 for success, -1 for error. */
473 read_type_number (pp
, typenums
)
475 register int *typenums
;
481 typenums
[0] = read_huge_number (pp
, ',', &nbits
);
482 if (nbits
!= 0) return -1;
483 typenums
[1] = read_huge_number (pp
, ')', &nbits
);
484 if (nbits
!= 0) return -1;
489 typenums
[1] = read_huge_number (pp
, 0, &nbits
);
490 if (nbits
!= 0) return -1;
496 #if !defined (REG_STRUCT_HAS_ADDR)
497 #define REG_STRUCT_HAS_ADDR(gcc_p,type) 0
500 #define VISIBILITY_PRIVATE '0' /* Stabs character for private field */
501 #define VISIBILITY_PROTECTED '1' /* Stabs character for protected fld */
502 #define VISIBILITY_PUBLIC '2' /* Stabs character for public field */
503 #define VISIBILITY_IGNORE '9' /* Optimized out or zero length */
505 #define CFRONT_VISIBILITY_PRIVATE '2' /* Stabs character for private field */
506 #define CFRONT_VISIBILITY_PUBLIC '1' /* Stabs character for public field */
508 /* This code added to support parsing of ARM/Cfront stabs strings */
510 /* get substring from string up to char c
511 advance string pointer past suibstring */
530 /* Physname gets strcat'd onto sname in order to recreate the mangled name
531 (see funtion gdb_mangle_name in gdbtypes.c). For cfront, make the physname
532 look like that of g++ - take out the initial mangling
533 eg: for sname="a" and fname="foo__1aFPFs_i" return "FPFs_i" */
535 get_cfront_method_physname(fname
)
539 /* FIXME would like to make this generic for g++ too, but
540 that is already handled in read_member_funcctions */
543 /* search ahead to find the start of the mangled suffix */
544 if (*p
== '_' && *(p
+1)=='_') /* compiler generated; probably a ctor/dtor */
546 while (p
&& ((p
+1) - fname
) < strlen(fname
) && *(p
+1)!='_')
548 if (!(p
&& *p
=='_' && *(p
+1)=='_'))
549 error("Invalid mangled function name %s",fname
);
550 p
+=2; /* advance past '__' */
552 /* struct name length and name of type should come next; advance past it */
555 len
= len
*10 + (*p
- '0');
563 /* Read base classes within cfront class definition.
564 eg: class A : Bpri, public Bpub, virtual Bvir
565 A:T(0,27)=s20b__4Bpri:(0,3),0,32;OBpub:(0,25),32,8;a__1A:(0,3),64,32;PBvir:(0,28)=*(0,26),96,32;OBvir:(0,26),128,8;;
566 A:ZcA;2@Bpri 1@Bpub v2@Bvir;foopri__1AFv foopro__1AFv __ct__1AFv __ct__1AFRC1A foopub__1AFv ;;;
567 ^^^^^^^^^^^^^^^^^^^^^
570 read_cfront_baseclasses(fip
, pp
, type
, objfile
)
571 struct field_info
*fip
;
572 struct objfile
* objfile
;
576 static struct complaint msg_noterm
= {"\
577 Base classes not terminated while reading stabs string %s.\n",
579 static struct complaint msg_unknown
= {"\
580 Unsupported token in stabs string %s.\n",
582 static struct complaint msg_notfound
= {"\
583 Unable to find base type for %s.\n",
588 struct nextfield
*new;
590 if (**pp
==';') /* no base classes; return */
596 /* first count base classes so we can allocate space before parsing */
597 for (p
= *pp
; p
&& *p
&& *p
!=';'; p
++)
601 bnum
++; /* add one more for last one */
603 /* now parse the base classes until we get to the start of the methods
604 (code extracted from read_baseclasses) */
605 TYPE_N_BASECLASSES(type
) = bnum
;
609 int num_bytes
= B_BYTES (TYPE_N_BASECLASSES (type
));
611 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
612 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
614 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), TYPE_N_BASECLASSES (type
));
617 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
619 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
620 make_cleanup (free
, new);
621 memset (new, 0, sizeof (struct nextfield
));
622 new -> next
= fip
-> list
;
624 new -> field
.bitsize
= 0; /* this should be an unpacked field! */
626 STABS_CONTINUE (pp
, objfile
);
628 /* virtual? eg: v2@Bvir */
631 SET_TYPE_FIELD_VIRTUAL (type
, i
);
635 /* access? eg: 2@Bvir */
636 /* Note: protected inheritance not supported in cfront */
639 case CFRONT_VISIBILITY_PRIVATE
:
640 new -> visibility
= VISIBILITY_PRIVATE
;
642 case CFRONT_VISIBILITY_PUBLIC
:
643 new -> visibility
= VISIBILITY_PUBLIC
;
646 /* Bad visibility format. Complain and treat it as
649 static struct complaint msg
= {
650 "Unknown visibility `%c' for baseclass", 0, 0};
651 complain (&msg
, new -> visibility
);
652 new -> visibility
= VISIBILITY_PUBLIC
;
656 /* "@" comes next - eg: @Bvir */
659 complain (&msg_unknown
, *pp
);
665 /* Set the bit offset of the portion of the object corresponding
666 to this baseclass. Always zero in the absence of
667 multiple inheritance. */
668 /* Unable to read bit position from stabs;
669 Assuming no multiple inheritance for now FIXME! */
670 /* We may have read this in the structure definition;
671 now we should fixup the members to be the actual base classes */
672 new -> field
.bitpos
= 0;
674 /* Get the base class name and type */
676 char * bname
; /* base class name */
677 struct symbol
* bsym
; /* base class */
679 p1
= strchr(*pp
,' ');
680 p2
= strchr(*pp
,';');
682 bname
= get_substring(pp
,' ');
684 bname
= get_substring(pp
,';');
685 if (!bname
|| !*bname
)
687 complain (&msg_unknown
, *pp
);
690 /* FIXME! attach base info to type */
691 bsym
= lookup_symbol (bname
, 0, STRUCT_NAMESPACE
, 0, 0); /*demangled_name*/
694 struct type
* btype
= SYMBOL_TYPE(bsym
);
695 new -> field
.type
= btype
;
696 new -> field
.name
= type_name_no_tag (new -> field
.type
);
700 complain (&msg_notfound
, *pp
);
705 /* If more base classes to parse, loop again.
706 We ate the last ' ' or ';' in get_substring,
707 so on exit we will have skipped the trailing ';' */
708 /* if invalid, return 0; add code to detect - FIXME! */
714 read_cfront_member_functions(fip
, pp
, type
, objfile
)
715 struct field_info
*fip
;
718 struct objfile
*objfile
;
720 /* This code extracted from read_member_functions
721 so as to do the similar thing for our funcs */
725 /* Total number of member functions defined in this class. If the class
726 defines two `f' functions, and one `g' function, then this will have
728 int total_length
= 0;
732 struct next_fnfield
*next
;
733 struct fn_field fn_field
;
735 struct type
*look_ahead_type
;
736 struct next_fnfieldlist
*new_fnlist
;
737 struct next_fnfield
*new_sublist
;
740 struct symbol
* ref_func
=0;
742 /* Process each list until we find something that is not a member function
743 or find the end of the functions. */
745 /* eg: p = "__ct__1AFv foo__1AFv ;;;" */
746 STABS_CONTINUE (pp
, objfile
); /* handle \\ */
747 while (**pp
!=';' && (fname
= get_substring(pp
,' '),fname
))
752 if (fname
[0]=='*') /* static member */
758 ref_func
= lookup_symbol (fname
, 0, VAR_NAMESPACE
, 0, 0); /*demangled_name*/
761 static struct complaint msg
= {"\
762 Unable to find function symbol for %s\n",
764 complain (&msg
, fname
);
768 look_ahead_type
= NULL
;
771 new_fnlist
= (struct next_fnfieldlist
*)
772 xmalloc (sizeof (struct next_fnfieldlist
));
773 make_cleanup (free
, new_fnlist
);
774 memset (new_fnlist
, 0, sizeof (struct next_fnfieldlist
));
776 /* The following is code to work around cfront generated stabs.
777 The stabs contains full mangled name for each field.
778 We try to demangle the name and extract the field name out of it. */
780 char *dem
, *dem_p
, *dem_args
;
782 dem
= cplus_demangle (fname
, DMGL_ANSI
| DMGL_PARAMS
);
785 dem_p
= strrchr (dem
, ':');
786 if (dem_p
!= 0 && *(dem_p
-1)==':')
788 /* get rid of args */
789 dem_args
= strchr (dem_p
, '(');
790 if (dem_args
== NULL
)
791 dem_len
= strlen(dem_p
);
793 dem_len
= dem_args
- dem_p
;
795 obsavestring (dem_p
, dem_len
, &objfile
-> type_obstack
);
800 obsavestring (fname
, strlen(fname
), &objfile
-> type_obstack
);
802 } /* end of code for cfront work around */
804 new_fnlist
-> fn_fieldlist
.name
= main_fn_name
;
806 /*-------------------------------------------------*/
807 /* Set up the sublists
808 Sublists are stuff like args, static, visibility, etc.
809 so in ARM, we have to set that info some other way.
810 Multiple sublists happen if overloading
811 eg: foo::26=##1;:;2A.;
812 In g++, we'd loop here thru all the sublists... */
814 (struct next_fnfield
*) xmalloc (sizeof (struct next_fnfield
));
815 make_cleanup (free
, new_sublist
);
816 memset (new_sublist
, 0, sizeof (struct next_fnfield
));
818 /* eat 1; from :;2A.; */
819 new_sublist
-> fn_field
.type
= SYMBOL_TYPE(ref_func
); /* normally takes a read_type */
820 /* make this type look like a method stub for gdb */
821 TYPE_FLAGS (new_sublist
-> fn_field
.type
) |= TYPE_FLAG_STUB
;
822 TYPE_CODE (new_sublist
-> fn_field
.type
) = TYPE_CODE_METHOD
;
824 /* If this is just a stub, then we don't have the real name here. */
825 if (TYPE_FLAGS (new_sublist
-> fn_field
.type
) & TYPE_FLAG_STUB
)
827 if (!TYPE_DOMAIN_TYPE (new_sublist
-> fn_field
.type
))
828 TYPE_DOMAIN_TYPE (new_sublist
-> fn_field
.type
) = type
;
829 new_sublist
-> fn_field
.is_stub
= 1;
831 /* physname used later in mangling; eg PFs_i,5 for foo__1aFPFs_i
832 physname gets strcat'd in order to recreate the onto mangled name */
833 pname
= get_cfront_method_physname(fname
);
834 new_sublist
-> fn_field
.physname
= savestring (pname
, strlen(pname
));
837 /* Set this member function's visibility fields.
838 Unable to distinguish access from stabs definition!
839 Assuming public for now. FIXME!
840 (for private, set new_sublist->fn_field.is_private = 1,
841 for public, set new_sublist->fn_field.is_protected = 1) */
843 /* Unable to distinguish const/volatile from stabs definition!
844 Assuming normal for now. FIXME!
845 new_sublist -> fn_field.is_const = 0;
846 new_sublist -> fn_field.is_volatile = 0; /* volatile not implemented in cfront */
848 /* set virtual/static function info
849 How to get vtable offsets ?
850 Assuming normal for now FIXME!!
851 For vtables, figure out from whence this virtual function came.
852 It may belong to virtual function table of
853 one of its baseclasses.
855 new_sublist -> fn_field.voffset = vtable offset,
856 new_sublist -> fn_field.fcontext = look_ahead_type;
857 where look_ahead_type is type of baseclass */
859 new_sublist
-> fn_field
.voffset
= VOFFSET_STATIC
;
860 else /* normal member function. */
861 new_sublist
-> fn_field
.voffset
= 0;
862 new_sublist
-> fn_field
.fcontext
= 0;
865 /* prepare new sublist */
866 new_sublist
-> next
= sublist
;
867 sublist
= new_sublist
;
869 /* In g++, we loop thu sublists - now we set from function */
871 new_fnlist
-> fn_fieldlist
.fn_fields
= (struct fn_field
*)
872 obstack_alloc (&objfile
-> type_obstack
,
873 sizeof (struct fn_field
) * length
);
874 memset (new_fnlist
-> fn_fieldlist
.fn_fields
, 0,
875 sizeof (struct fn_field
) * length
);
876 for (i
= length
; (i
--, sublist
); sublist
= sublist
-> next
)
878 new_fnlist
-> fn_fieldlist
.fn_fields
[i
] = sublist
-> fn_field
;
881 new_fnlist
-> fn_fieldlist
.length
= length
;
882 new_fnlist
-> next
= fip
-> fnlist
;
883 fip
-> fnlist
= new_fnlist
;
885 total_length
+= length
;
886 STABS_CONTINUE (pp
, objfile
); /* handle \\ */
891 /* type should already have space */
892 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
893 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * nfn_fields
);
894 memset (TYPE_FN_FIELDLISTS (type
), 0,
895 sizeof (struct fn_fieldlist
) * nfn_fields
);
896 TYPE_NFN_FIELDS (type
) = nfn_fields
;
897 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
900 /* end of scope for reading member func */
903 /* skip trailing ';' and bump count of number of fields seen */
911 /* This routine fixes up partial cfront types that were created
912 while parsing the stabs. The main need for this function is
913 to add information such as methods to classes.
914 Examples of "p": "sA;;__ct__1AFv foo__1AFv ;;;" */
916 resolve_cont(objfile
, sym
, p
)
917 struct objfile
* objfile
;
921 struct symbol
* ref_sym
=0;
923 /* snarfed from read_struct_type */
924 struct field_info fi
;
925 struct field_info
* fip
= &fi
;
927 struct cleanup
*back_to
;
929 /* need to make sure that fi isn't gunna conflict with struct
930 in case struct already had some fnfs */
933 back_to
= make_cleanup (null_cleanup
, 0);
935 /* we only accept structs, classes and unions at the moment.
936 Other continuation types include t (typedef), r (long dbl), ...
937 We may want to add support for them as well;
938 right now they are handled by duplicating the symbol information
939 into the type information (see define_symbol) */
940 if (*p
!= 's' /* structs */
941 && *p
!= 'c' /* class */
942 && *p
!= 'u') /* union */
943 return; /* only handle C++ types */
946 /* get symbol typs name and validate
947 eg: p = "A;;__ct__1AFv foo__1AFv ;;;" */
948 sname
= get_substring(&p
,';');
949 if (!sname
|| strcmp(sname
,SYMBOL_NAME(sym
)))
950 error("Internal error: base symbol type name does not match\n");
952 /* find symbol's internal gdb reference */
953 ref_sym
= lookup_symbol (SYMBOL_NAME(sym
), 0, STRUCT_NAMESPACE
, 0, 0); /*demangled_name*/
954 /* This is the real sym that we want;
955 sym was a temp hack to make debugger happy */
956 /* ref_sym should already have space */
957 type
= SYMBOL_TYPE(ref_sym
);
960 /* Now read the baseclasses, if any, read the regular C struct or C++
961 class member fields, attach the fields to the type, read the C++
962 member functions, attach them to the type, and then read any tilde
963 field (baseclass specifier for the class holding the main vtable). */
965 if (!read_cfront_baseclasses (&fi
, &p
, type
, objfile
)
966 /* g++ does this next, but cfront already did this:
967 || !read_struct_fields (&fi, &p, type, objfile) */
968 || !attach_fields_to_type (&fi
, type
, objfile
)
969 || !read_cfront_member_functions (&fi
, &p
, type
, objfile
)
970 || !attach_fn_fields_to_type (&fi
, type
)
971 /* g++ does this next, but cfront doesn't seem to have this:
972 || !read_tilde_fields (&fi, &p, type, objfile) */
975 type
= error_type (&p
, objfile
);
978 do_cleanups (back_to
);
980 /* End of code added to support parsing of ARM/Cfront stabs strings */
985 define_symbol (valu
, string
, desc
, type
, objfile
)
990 struct objfile
*objfile
;
992 register struct symbol
*sym
;
993 char *p
= (char *) strchr (string
, ':');
998 /* We would like to eliminate nameless symbols, but keep their types.
999 E.g. stab entry ":t10=*2" should produce a type 10, which is a pointer
1000 to type 2, but, should not create a symbol to address that type. Since
1001 the symbol will be nameless, there is no way any user can refer to it. */
1005 /* Ignore syms with empty names. */
1009 /* Ignore old-style symbols from cc -go */
1019 /* If a nameless stab entry, all we need is the type, not the symbol.
1020 e.g. ":t10=*2" or a nameless enum like " :T16=ered:0,green:1,blue:2,;" */
1021 nameless
= (p
== string
|| ((string
[0] == ' ') && (string
[1] == ':')));
1023 current_symbol
= sym
= (struct symbol
*)
1024 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
1025 memset (sym
, 0, sizeof (struct symbol
));
1027 switch (type
& N_TYPE
)
1030 SYMBOL_SECTION(sym
) = SECT_OFF_TEXT
;
1033 SYMBOL_SECTION(sym
) = SECT_OFF_DATA
;
1036 SYMBOL_SECTION(sym
) = SECT_OFF_BSS
;
1040 if (processing_gcc_compilation
)
1042 /* GCC 2.x puts the line number in desc. SunOS apparently puts in the
1043 number of bytes occupied by a type or object, which we ignore. */
1044 SYMBOL_LINE(sym
) = desc
;
1048 SYMBOL_LINE(sym
) = 0; /* unknown */
1051 if (is_cplus_marker (string
[0]))
1053 /* Special GNU C++ names. */
1057 SYMBOL_NAME (sym
) = obsavestring ("this", strlen ("this"),
1058 &objfile
-> symbol_obstack
);
1061 case 'v': /* $vtbl_ptr_type */
1062 /* Was: SYMBOL_NAME (sym) = "vptr"; */
1066 SYMBOL_NAME (sym
) = obsavestring ("eh_throw", strlen ("eh_throw"),
1067 &objfile
-> symbol_obstack
);
1071 /* This was an anonymous type that was never fixed up. */
1074 #ifdef STATIC_TRANSFORM_NAME
1076 /* SunPRO (3.0 at least) static variable encoding. */
1081 complain (&unrecognized_cplus_name_complaint
, string
);
1082 goto normal
; /* Do *something* with it */
1088 SYMBOL_LANGUAGE (sym
) = current_subfile
-> language
;
1089 SYMBOL_NAME (sym
) = (char *)
1090 obstack_alloc (&objfile
-> symbol_obstack
, ((p
- string
) + 1));
1091 /* Open-coded memcpy--saves function call time. */
1092 /* FIXME: Does it really? Try replacing with simple strcpy and
1093 try it on an executable with a large symbol table. */
1094 /* FIXME: considering that gcc can open code memcpy anyway, I
1095 doubt it. xoxorich. */
1097 register char *p1
= string
;
1098 register char *p2
= SYMBOL_NAME (sym
);
1106 /* If this symbol is from a C++ compilation, then attempt to cache the
1107 demangled form for future reference. This is a typical time versus
1108 space tradeoff, that was decided in favor of time because it sped up
1109 C++ symbol lookups by a factor of about 20. */
1111 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
1115 /* Determine the type of name being defined. */
1117 /* Getting GDB to correctly skip the symbol on an undefined symbol
1118 descriptor and not ever dump core is a very dodgy proposition if
1119 we do things this way. I say the acorn RISC machine can just
1120 fix their compiler. */
1121 /* The Acorn RISC machine's compiler can put out locals that don't
1122 start with "234=" or "(3,4)=", so assume anything other than the
1123 deftypes we know how to handle is a local. */
1124 if (!strchr ("cfFGpPrStTvVXCR", *p
))
1126 if (isdigit (*p
) || *p
== '(' || *p
== '-')
1135 /* c is a special case, not followed by a type-number.
1136 SYMBOL:c=iVALUE for an integer constant symbol.
1137 SYMBOL:c=rVALUE for a floating constant symbol.
1138 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
1139 e.g. "b:c=e6,0" for "const b = blob1"
1140 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
1143 SYMBOL_CLASS (sym
) = LOC_CONST
;
1144 SYMBOL_TYPE (sym
) = error_type (&p
, objfile
);
1145 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1146 add_symbol_to_list (sym
, &file_symbols
);
1154 double d
= atof (p
);
1157 /* FIXME-if-picky-about-floating-accuracy: Should be using
1158 target arithmetic to get the value. real.c in GCC
1159 probably has the necessary code. */
1161 /* FIXME: lookup_fundamental_type is a hack. We should be
1162 creating a type especially for the type of float constants.
1163 Problem is, what type should it be?
1165 Also, what should the name of this type be? Should we
1166 be using 'S' constants (see stabs.texinfo) instead? */
1168 SYMBOL_TYPE (sym
) = lookup_fundamental_type (objfile
,
1171 obstack_alloc (&objfile
-> symbol_obstack
,
1172 TYPE_LENGTH (SYMBOL_TYPE (sym
)));
1173 store_floating (dbl_valu
, TYPE_LENGTH (SYMBOL_TYPE (sym
)), d
);
1174 SYMBOL_VALUE_BYTES (sym
) = dbl_valu
;
1175 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
1180 /* Defining integer constants this way is kind of silly,
1181 since 'e' constants allows the compiler to give not
1182 only the value, but the type as well. C has at least
1183 int, long, unsigned int, and long long as constant
1184 types; other languages probably should have at least
1185 unsigned as well as signed constants. */
1187 /* We just need one int constant type for all objfiles.
1188 It doesn't depend on languages or anything (arguably its
1189 name should be a language-specific name for a type of
1190 that size, but I'm inclined to say that if the compiler
1191 wants a nice name for the type, it can use 'e'). */
1192 static struct type
*int_const_type
;
1194 /* Yes, this is as long as a *host* int. That is because we
1196 if (int_const_type
== NULL
)
1198 init_type (TYPE_CODE_INT
,
1199 sizeof (int) * HOST_CHAR_BIT
/ TARGET_CHAR_BIT
, 0,
1201 (struct objfile
*)NULL
);
1202 SYMBOL_TYPE (sym
) = int_const_type
;
1203 SYMBOL_VALUE (sym
) = atoi (p
);
1204 SYMBOL_CLASS (sym
) = LOC_CONST
;
1208 /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value
1209 can be represented as integral.
1210 e.g. "b:c=e6,0" for "const b = blob1"
1211 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
1213 SYMBOL_CLASS (sym
) = LOC_CONST
;
1214 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1218 SYMBOL_TYPE (sym
) = error_type (&p
, objfile
);
1223 /* If the value is too big to fit in an int (perhaps because
1224 it is unsigned), or something like that, we silently get
1225 a bogus value. The type and everything else about it is
1226 correct. Ideally, we should be using whatever we have
1227 available for parsing unsigned and long long values,
1229 SYMBOL_VALUE (sym
) = atoi (p
);
1234 SYMBOL_CLASS (sym
) = LOC_CONST
;
1235 SYMBOL_TYPE (sym
) = error_type (&p
, objfile
);
1238 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1239 add_symbol_to_list (sym
, &file_symbols
);
1243 /* The name of a caught exception. */
1244 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1245 SYMBOL_CLASS (sym
) = LOC_LABEL
;
1246 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1247 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1248 add_symbol_to_list (sym
, &local_symbols
);
1252 /* A static function definition. */
1253 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1254 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1255 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1256 add_symbol_to_list (sym
, &file_symbols
);
1257 /* fall into process_function_types. */
1259 process_function_types
:
1260 /* Function result types are described as the result type in stabs.
1261 We need to convert this to the function-returning-type-X type
1262 in GDB. E.g. "int" is converted to "function returning int". */
1263 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_FUNC
)
1264 SYMBOL_TYPE (sym
) = lookup_function_type (SYMBOL_TYPE (sym
));
1265 /* fall into process_prototype_types */
1267 process_prototype_types
:
1268 /* Sun acc puts declared types of arguments here. We don't care
1269 about their actual types (FIXME -- we should remember the whole
1270 function prototype), but the list may define some new types
1271 that we have to remember, so we must scan it now. */
1274 read_type (&p
, objfile
);
1279 /* A global function definition. */
1280 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1281 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1282 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1283 add_symbol_to_list (sym
, &global_symbols
);
1284 goto process_function_types
;
1287 /* For a class G (global) symbol, it appears that the
1288 value is not correct. It is necessary to search for the
1289 corresponding linker definition to find the value.
1290 These definitions appear at the end of the namelist. */
1291 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1292 i
= hashname (SYMBOL_NAME (sym
));
1293 SYMBOL_VALUE_CHAIN (sym
) = global_sym_chain
[i
];
1294 global_sym_chain
[i
] = sym
;
1295 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1296 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1297 add_symbol_to_list (sym
, &global_symbols
);
1300 /* This case is faked by a conditional above,
1301 when there is no code letter in the dbx data.
1302 Dbx data never actually contains 'l'. */
1305 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1306 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1307 SYMBOL_VALUE (sym
) = valu
;
1308 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1309 add_symbol_to_list (sym
, &local_symbols
);
1314 /* pF is a two-letter code that means a function parameter in Fortran.
1315 The type-number specifies the type of the return value.
1316 Translate it into a pointer-to-function type. */
1320 = lookup_pointer_type
1321 (lookup_function_type (read_type (&p
, objfile
)));
1324 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1326 /* Normally this is a parameter, a LOC_ARG. On the i960, it
1327 can also be a LOC_LOCAL_ARG depending on symbol type. */
1328 #ifndef DBX_PARM_SYMBOL_CLASS
1329 #define DBX_PARM_SYMBOL_CLASS(type) LOC_ARG
1332 SYMBOL_CLASS (sym
) = DBX_PARM_SYMBOL_CLASS (type
);
1333 SYMBOL_VALUE (sym
) = valu
;
1334 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1335 add_symbol_to_list (sym
, &local_symbols
);
1337 if (TARGET_BYTE_ORDER
!= BIG_ENDIAN
)
1339 /* On little-endian machines, this crud is never necessary,
1340 and, if the extra bytes contain garbage, is harmful. */
1344 /* If it's gcc-compiled, if it says `short', believe it. */
1345 if (processing_gcc_compilation
|| BELIEVE_PCC_PROMOTION
)
1348 #if !BELIEVE_PCC_PROMOTION
1350 /* This is the signed type which arguments get promoted to. */
1351 static struct type
*pcc_promotion_type
;
1352 /* This is the unsigned type which arguments get promoted to. */
1353 static struct type
*pcc_unsigned_promotion_type
;
1355 /* Call it "int" because this is mainly C lossage. */
1356 if (pcc_promotion_type
== NULL
)
1357 pcc_promotion_type
=
1358 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
1361 if (pcc_unsigned_promotion_type
== NULL
)
1362 pcc_unsigned_promotion_type
=
1363 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
1364 TYPE_FLAG_UNSIGNED
, "unsigned int", NULL
);
1366 #if defined(BELIEVE_PCC_PROMOTION_TYPE)
1367 /* This macro is defined on machines (e.g. sparc) where
1368 we should believe the type of a PCC 'short' argument,
1369 but shouldn't believe the address (the address is
1370 the address of the corresponding int).
1372 My guess is that this correction, as opposed to changing
1373 the parameter to an 'int' (as done below, for PCC
1374 on most machines), is the right thing to do
1375 on all machines, but I don't want to risk breaking
1376 something that already works. On most PCC machines,
1377 the sparc problem doesn't come up because the calling
1378 function has to zero the top bytes (not knowing whether
1379 the called function wants an int or a short), so there
1380 is little practical difference between an int and a short
1381 (except perhaps what happens when the GDB user types
1382 "print short_arg = 0x10000;").
1384 Hacked for SunOS 4.1 by gnu@cygnus.com. In 4.1, the compiler
1385 actually produces the correct address (we don't need to fix it
1386 up). I made this code adapt so that it will offset the symbol
1387 if it was pointing at an int-aligned location and not
1388 otherwise. This way you can use the same gdb for 4.0.x and
1391 If the parameter is shorter than an int, and is integral
1392 (e.g. char, short, or unsigned equivalent), and is claimed to
1393 be passed on an integer boundary, don't believe it! Offset the
1394 parameter's address to the tail-end of that integer. */
1396 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (pcc_promotion_type
)
1397 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
1398 && 0 == SYMBOL_VALUE (sym
) % TYPE_LENGTH (pcc_promotion_type
))
1400 SYMBOL_VALUE (sym
) += TYPE_LENGTH (pcc_promotion_type
)
1401 - TYPE_LENGTH (SYMBOL_TYPE (sym
));
1405 #else /* no BELIEVE_PCC_PROMOTION_TYPE. */
1407 /* If PCC says a parameter is a short or a char,
1408 it is really an int. */
1409 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (pcc_promotion_type
)
1410 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
)
1413 TYPE_UNSIGNED (SYMBOL_TYPE (sym
))
1414 ? pcc_unsigned_promotion_type
1415 : pcc_promotion_type
;
1419 #endif /* no BELIEVE_PCC_PROMOTION_TYPE. */
1421 #endif /* !BELIEVE_PCC_PROMOTION. */
1424 /* acc seems to use P to declare the prototypes of functions that
1425 are referenced by this file. gdb is not prepared to deal
1426 with this extra information. FIXME, it ought to. */
1429 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1430 goto process_prototype_types
;
1435 /* Parameter which is in a register. */
1436 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1437 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
1438 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
1439 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
1441 complain (®_value_complaint
, SYMBOL_VALUE (sym
), NUM_REGS
,
1442 SYMBOL_SOURCE_NAME (sym
));
1443 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
1445 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1446 add_symbol_to_list (sym
, &local_symbols
);
1450 /* Register variable (either global or local). */
1451 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1452 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
1453 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
1454 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
1456 complain (®_value_complaint
, SYMBOL_VALUE (sym
), NUM_REGS
,
1457 SYMBOL_SOURCE_NAME (sym
));
1458 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
1460 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1461 if (within_function
)
1463 /* Sun cc uses a pair of symbols, one 'p' and one 'r' with the same
1464 name to represent an argument passed in a register.
1465 GCC uses 'P' for the same case. So if we find such a symbol pair
1466 we combine it into one 'P' symbol. For Sun cc we need to do this
1467 regardless of REG_STRUCT_HAS_ADDR, because the compiler puts out
1468 the 'p' symbol even if it never saves the argument onto the stack.
1470 On most machines, we want to preserve both symbols, so that
1471 we can still get information about what is going on with the
1472 stack (VAX for computing args_printed, using stack slots instead
1473 of saved registers in backtraces, etc.).
1475 Note that this code illegally combines
1476 main(argc) struct foo argc; { register struct foo argc; }
1477 but this case is considered pathological and causes a warning
1478 from a decent compiler. */
1481 && local_symbols
->nsyms
> 0
1482 #ifndef USE_REGISTER_NOT_ARG
1483 && REG_STRUCT_HAS_ADDR (processing_gcc_compilation
,
1485 && (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
1486 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
1487 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_SET
1488 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_BITSTRING
)
1492 struct symbol
*prev_sym
;
1493 prev_sym
= local_symbols
->symbol
[local_symbols
->nsyms
- 1];
1494 if ((SYMBOL_CLASS (prev_sym
) == LOC_REF_ARG
1495 || SYMBOL_CLASS (prev_sym
) == LOC_ARG
)
1496 && STREQ (SYMBOL_NAME (prev_sym
), SYMBOL_NAME(sym
)))
1498 SYMBOL_CLASS (prev_sym
) = LOC_REGPARM
;
1499 /* Use the type from the LOC_REGISTER; that is the type
1500 that is actually in that register. */
1501 SYMBOL_TYPE (prev_sym
) = SYMBOL_TYPE (sym
);
1502 SYMBOL_VALUE (prev_sym
) = SYMBOL_VALUE (sym
);
1507 add_symbol_to_list (sym
, &local_symbols
);
1510 add_symbol_to_list (sym
, &file_symbols
);
1514 /* Static symbol at top level of file */
1515 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1516 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1517 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1518 #ifdef STATIC_TRANSFORM_NAME
1519 if (SYMBOL_NAME (sym
)[0] == '$')
1521 struct minimal_symbol
*msym
;
1522 msym
= lookup_minimal_symbol (SYMBOL_NAME (sym
), NULL
, objfile
);
1525 SYMBOL_NAME (sym
) = STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym
));
1526 SYMBOL_VALUE_ADDRESS (sym
) = SYMBOL_VALUE_ADDRESS (msym
);
1530 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1531 add_symbol_to_list (sym
, &file_symbols
);
1535 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1537 /* For a nameless type, we don't want a create a symbol, thus we
1538 did not use `sym'. Return without further processing. */
1539 if (nameless
) return NULL
;
1541 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1542 SYMBOL_VALUE (sym
) = valu
;
1543 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1544 /* C++ vagaries: we may have a type which is derived from
1545 a base type which did not have its name defined when the
1546 derived class was output. We fill in the derived class's
1547 base part member's name here in that case. */
1548 if (TYPE_NAME (SYMBOL_TYPE (sym
)) != NULL
)
1549 if ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
1550 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
)
1551 && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)))
1554 for (j
= TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)) - 1; j
>= 0; j
--)
1555 if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) == 0)
1556 TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) =
1557 type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym
), j
));
1560 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == NULL
)
1562 /* gcc-2.6 or later (when using -fvtable-thunks)
1563 emits a unique named type for a vtable entry.
1564 Some gdb code depends on that specific name. */
1565 extern const char vtbl_ptr_name
[];
1567 if ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_PTR
1568 && strcmp (SYMBOL_NAME (sym
), vtbl_ptr_name
))
1569 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_FUNC
)
1571 /* If we are giving a name to a type such as "pointer to
1572 foo" or "function returning foo", we better not set
1573 the TYPE_NAME. If the program contains "typedef char
1574 *caddr_t;", we don't want all variables of type char
1575 * to print as caddr_t. This is not just a
1576 consequence of GDB's type management; PCC and GCC (at
1577 least through version 2.4) both output variables of
1578 either type char * or caddr_t with the type number
1579 defined in the 't' symbol for caddr_t. If a future
1580 compiler cleans this up it GDB is not ready for it
1581 yet, but if it becomes ready we somehow need to
1582 disable this check (without breaking the PCC/GCC2.4
1587 Fortunately, this check seems not to be necessary
1588 for anything except pointers or functions. */
1591 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_NAME (sym
);
1594 add_symbol_to_list (sym
, &file_symbols
);
1598 /* Struct, union, or enum tag. For GNU C++, this can be be followed
1599 by 't' which means we are typedef'ing it as well. */
1600 synonym
= *p
== 't';
1604 /* The semantics of C++ state that "struct foo { ... }" also defines
1605 a typedef for "foo". Unfortunately, cfront never makes the typedef
1606 when translating C++ into C. We make the typedef here so that
1607 "ptype foo" works as expected for cfront translated code. */
1608 else if (current_subfile
->language
== language_cplus
)
1611 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1613 /* For a nameless type, we don't want a create a symbol, thus we
1614 did not use `sym'. Return without further processing. */
1615 if (nameless
) return NULL
;
1617 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1618 SYMBOL_VALUE (sym
) = valu
;
1619 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
1620 if (TYPE_TAG_NAME (SYMBOL_TYPE (sym
)) == 0)
1621 TYPE_TAG_NAME (SYMBOL_TYPE (sym
))
1622 = obconcat (&objfile
-> type_obstack
, "", "", SYMBOL_NAME (sym
));
1623 add_symbol_to_list (sym
, &file_symbols
);
1627 /* Clone the sym and then modify it. */
1628 register struct symbol
*typedef_sym
= (struct symbol
*)
1629 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
1630 *typedef_sym
= *sym
;
1631 SYMBOL_CLASS (typedef_sym
) = LOC_TYPEDEF
;
1632 SYMBOL_VALUE (typedef_sym
) = valu
;
1633 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
1634 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
1635 TYPE_NAME (SYMBOL_TYPE (sym
))
1636 = obconcat (&objfile
-> type_obstack
, "", "", SYMBOL_NAME (sym
));
1637 add_symbol_to_list (typedef_sym
, &file_symbols
);
1642 /* Static symbol of local scope */
1643 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1644 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1645 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1646 #ifdef STATIC_TRANSFORM_NAME
1647 if (SYMBOL_NAME (sym
)[0] == '$')
1649 struct minimal_symbol
*msym
;
1650 msym
= lookup_minimal_symbol (SYMBOL_NAME (sym
), NULL
, objfile
);
1653 SYMBOL_NAME (sym
) = STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym
));
1654 SYMBOL_VALUE_ADDRESS (sym
) = SYMBOL_VALUE_ADDRESS (msym
);
1658 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1660 add_symbol_to_list (sym
, &global_symbols
);
1662 add_symbol_to_list (sym
, &local_symbols
);
1666 /* Reference parameter */
1667 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1668 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
1669 SYMBOL_VALUE (sym
) = valu
;
1670 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1671 add_symbol_to_list (sym
, &local_symbols
);
1675 /* Reference parameter which is in a register. */
1676 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1677 SYMBOL_CLASS (sym
) = LOC_REGPARM_ADDR
;
1678 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
1679 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
1681 complain (®_value_complaint
, SYMBOL_VALUE (sym
), NUM_REGS
,
1682 SYMBOL_SOURCE_NAME (sym
));
1683 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
1685 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1686 add_symbol_to_list (sym
, &local_symbols
);
1690 /* This is used by Sun FORTRAN for "function result value".
1691 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
1692 that Pascal uses it too, but when I tried it Pascal used
1693 "x:3" (local symbol) instead. */
1694 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1695 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1696 SYMBOL_VALUE (sym
) = valu
;
1697 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1698 add_symbol_to_list (sym
, &local_symbols
);
1701 /* New code added to support cfront stabs strings */
1702 /* Note: case 'P' already handled above */
1704 /* Cfront type continuation coming up!
1705 find the original definition and add to it.
1706 We'll have to do this for the typedef too,
1707 since we clloned the symbol to define a type in read_type.
1708 Stabs info examples:
1710 foo__1CFv :ZtF (first def foo__1CFv:F(0,3);(0,24))
1711 C:ZsC;;__ct__1CFv func1__1CFv func2__1CFv ... ;;;
1712 where C is the name of the class. */
1713 /* can't lookup symbol yet 'cuz symbols not read yet
1714 so we save it for processing later */
1715 process_later(sym
,p
);
1716 SYMBOL_TYPE (sym
) = error_type (&p
, objfile
); /* FIXME! change later */
1717 SYMBOL_CLASS (sym
) = LOC_CONST
;
1718 SYMBOL_VALUE (sym
) = 0;
1719 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1720 /* don't add to list - we'll delete it later when
1721 we add the continuation to the real sym */
1723 /* End of new code added to support cfront stabs strings */
1726 SYMBOL_TYPE (sym
) = error_type (&p
, objfile
);
1727 SYMBOL_CLASS (sym
) = LOC_CONST
;
1728 SYMBOL_VALUE (sym
) = 0;
1729 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1730 add_symbol_to_list (sym
, &file_symbols
);
1734 /* When passing structures to a function, some systems sometimes pass
1735 the address in a register, not the structure itself. */
1737 if (REG_STRUCT_HAS_ADDR (processing_gcc_compilation
,
1739 && ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
)
1740 || (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
)
1741 || (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_BITSTRING
)
1742 || (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_SET
)))
1744 /* If REG_STRUCT_HAS_ADDR yields non-zero we have to
1745 convert LOC_REGPARM to LOC_REGPARM_ADDR for structures and unions. */
1746 if (SYMBOL_CLASS (sym
) == LOC_REGPARM
)
1747 SYMBOL_CLASS (sym
) = LOC_REGPARM_ADDR
;
1748 /* Likewise for converting LOC_ARG to LOC_REF_ARG (for the 7th and
1749 subsequent arguments on the sparc, for example). */
1750 else if (SYMBOL_CLASS (sym
) == LOC_ARG
)
1751 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
1758 /* Skip rest of this symbol and return an error type.
1760 General notes on error recovery: error_type always skips to the
1761 end of the symbol (modulo cretinous dbx symbol name continuation).
1762 Thus code like this:
1764 if (*(*pp)++ != ';')
1765 return error_type (pp, objfile);
1767 is wrong because if *pp starts out pointing at '\0' (typically as the
1768 result of an earlier error), it will be incremented to point to the
1769 start of the next symbol, which might produce strange results, at least
1770 if you run off the end of the string table. Instead use
1773 return error_type (pp, objfile);
1779 foo = error_type (pp, objfile);
1783 And in case it isn't obvious, the point of all this hair is so the compiler
1784 can define new types and new syntaxes, and old versions of the
1785 debugger will be able to read the new symbol tables. */
1787 static struct type
*
1788 error_type (pp
, objfile
)
1790 struct objfile
*objfile
;
1792 complain (&error_type_complaint
);
1795 /* Skip to end of symbol. */
1796 while (**pp
!= '\0')
1801 /* Check for and handle cretinous dbx symbol name continuation! */
1802 if ((*pp
)[-1] == '\\' || (*pp
)[-1] == '?')
1804 *pp
= next_symbol_text (objfile
);
1811 return (builtin_type_error
);
1815 /* Read type information or a type definition; return the type. Even
1816 though this routine accepts either type information or a type
1817 definition, the distinction is relevant--some parts of stabsread.c
1818 assume that type information starts with a digit, '-', or '(' in
1819 deciding whether to call read_type. */
1822 read_type (pp
, objfile
)
1824 struct objfile
*objfile
;
1826 register struct type
*type
= 0;
1830 char type_descriptor
;
1832 /* Size in bits of type if specified by a type attribute, or -1 if
1833 there is no size attribute. */
1836 /* Used to distinguish string and bitstring from char-array and set. */
1839 /* Read type number if present. The type number may be omitted.
1840 for instance in a two-dimensional array declared with type
1841 "ar1;1;10;ar1;1;10;4". */
1842 if ((**pp
>= '0' && **pp
<= '9')
1846 if (read_type_number (pp
, typenums
) != 0)
1847 return error_type (pp
, objfile
);
1849 /* Type is not being defined here. Either it already exists,
1850 or this is a forward reference to it. dbx_alloc_type handles
1853 return dbx_alloc_type (typenums
, objfile
);
1855 /* Type is being defined here. */
1857 Also skip the type descriptor - we get it below with (*pp)[-1]. */
1862 /* 'typenums=' not present, type is anonymous. Read and return
1863 the definition, but don't put it in the type vector. */
1864 typenums
[0] = typenums
[1] = -1;
1869 type_descriptor
= (*pp
)[-1];
1870 switch (type_descriptor
)
1874 enum type_code code
;
1876 /* Used to index through file_symbols. */
1877 struct pending
*ppt
;
1880 /* Name including "struct", etc. */
1884 char *from
, *to
, *p
, *q1
, *q2
;
1886 /* Set the type code according to the following letter. */
1890 code
= TYPE_CODE_STRUCT
;
1893 code
= TYPE_CODE_UNION
;
1896 code
= TYPE_CODE_ENUM
;
1900 /* Complain and keep going, so compilers can invent new
1901 cross-reference types. */
1902 static struct complaint msg
=
1903 {"Unrecognized cross-reference type `%c'", 0, 0};
1904 complain (&msg
, (*pp
)[0]);
1905 code
= TYPE_CODE_STRUCT
;
1910 q1
= strchr(*pp
, '<');
1911 p
= strchr(*pp
, ':');
1913 return error_type (pp
, objfile
);
1914 while (q1
&& p
> q1
&& p
[1] == ':')
1916 q2
= strchr(q1
, '>');
1922 return error_type (pp
, objfile
);
1925 (char *)obstack_alloc (&objfile
->type_obstack
, p
- *pp
+ 1);
1927 /* Copy the name. */
1933 /* Set the pointer ahead of the name which we just read, and
1938 /* Now check to see whether the type has already been
1939 declared. This was written for arrays of cross-referenced
1940 types before we had TYPE_CODE_TARGET_STUBBED, so I'm pretty
1941 sure it is not necessary anymore. But it might be a good
1942 idea, to save a little memory. */
1944 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
1945 for (i
= 0; i
< ppt
->nsyms
; i
++)
1947 struct symbol
*sym
= ppt
->symbol
[i
];
1949 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
1950 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
1951 && (TYPE_CODE (SYMBOL_TYPE (sym
)) == code
)
1952 && STREQ (SYMBOL_NAME (sym
), type_name
))
1954 obstack_free (&objfile
-> type_obstack
, type_name
);
1955 type
= SYMBOL_TYPE (sym
);
1960 /* Didn't find the type to which this refers, so we must
1961 be dealing with a forward reference. Allocate a type
1962 structure for it, and keep track of it so we can
1963 fill in the rest of the fields when we get the full
1965 type
= dbx_alloc_type (typenums
, objfile
);
1966 TYPE_CODE (type
) = code
;
1967 TYPE_TAG_NAME (type
) = type_name
;
1968 INIT_CPLUS_SPECIFIC(type
);
1969 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
1971 add_undefined_type (type
);
1975 case '-': /* RS/6000 built-in type */
1989 /* We deal with something like t(1,2)=(3,4)=... which
1990 the Lucid compiler and recent gcc versions (post 2.7.3) use. */
1992 /* Allocate and enter the typedef type first.
1993 This handles recursive types. */
1994 type
= dbx_alloc_type (typenums
, objfile
);
1995 TYPE_CODE (type
) = TYPE_CODE_TYPEDEF
;
1996 { struct type
*xtype
= read_type (pp
, objfile
);
1999 /* It's being defined as itself. That means it is "void". */
2000 TYPE_CODE (type
) = TYPE_CODE_VOID
;
2001 TYPE_LENGTH (type
) = 1;
2003 else if (type_size
>= 0 || is_string
)
2006 TYPE_NAME (type
) = NULL
;
2007 TYPE_TAG_NAME (type
) = NULL
;
2011 TYPE_FLAGS (type
) |= TYPE_FLAG_TARGET_STUB
;
2012 TYPE_TARGET_TYPE (type
) = xtype
;
2017 /* In the following types, we must be sure to overwrite any existing
2018 type that the typenums refer to, rather than allocating a new one
2019 and making the typenums point to the new one. This is because there
2020 may already be pointers to the existing type (if it had been
2021 forward-referenced), and we must change it to a pointer, function,
2022 reference, or whatever, *in-place*. */
2025 type1
= read_type (pp
, objfile
);
2026 type
= make_pointer_type (type1
, dbx_lookup_type (typenums
));
2029 case '&': /* Reference to another type */
2030 type1
= read_type (pp
, objfile
);
2031 type
= make_reference_type (type1
, dbx_lookup_type (typenums
));
2034 case 'f': /* Function returning another type */
2035 if (os9k_stabs
&& **pp
== '(')
2037 /* Function prototype; parse it.
2038 We must conditionalize this on os9k_stabs because otherwise
2039 it could be confused with a Sun-style (1,3) typenumber
2045 t
= read_type(pp
, objfile
);
2046 if (**pp
== ',') ++*pp
;
2049 type1
= read_type (pp
, objfile
);
2050 type
= make_function_type (type1
, dbx_lookup_type (typenums
));
2053 case 'k': /* Const qualifier on some type (Sun) */
2054 case 'c': /* Const qualifier on some type (OS9000) */
2055 /* Because 'c' means other things to AIX and 'k' is perfectly good,
2056 only accept 'c' in the os9k_stabs case. */
2057 if (type_descriptor
== 'c' && !os9k_stabs
)
2058 return error_type (pp
, objfile
);
2059 type
= read_type (pp
, objfile
);
2060 /* FIXME! For now, we ignore const and volatile qualifiers. */
2063 case 'B': /* Volatile qual on some type (Sun) */
2064 case 'i': /* Volatile qual on some type (OS9000) */
2065 /* Because 'i' means other things to AIX and 'B' is perfectly good,
2066 only accept 'i' in the os9k_stabs case. */
2067 if (type_descriptor
== 'i' && !os9k_stabs
)
2068 return error_type (pp
, objfile
);
2069 type
= read_type (pp
, objfile
);
2070 /* FIXME! For now, we ignore const and volatile qualifiers. */
2074 if (isdigit (**pp
) || **pp
== '(' || **pp
== '-')
2075 { /* Member (class & variable) type */
2076 /* FIXME -- we should be doing smash_to_XXX types here. */
2078 struct type
*domain
= read_type (pp
, objfile
);
2079 struct type
*memtype
;
2082 /* Invalid member type data format. */
2083 return error_type (pp
, objfile
);
2086 memtype
= read_type (pp
, objfile
);
2087 type
= dbx_alloc_type (typenums
, objfile
);
2088 smash_to_member_type (type
, domain
, memtype
);
2090 else /* type attribute */
2093 /* Skip to the semicolon. */
2094 while (**pp
!= ';' && **pp
!= '\0')
2097 return error_type (pp
, objfile
);
2099 ++*pp
; /* Skip the semicolon. */
2104 type_size
= atoi (attr
+ 1);
2114 /* Ignore unrecognized type attributes, so future compilers
2115 can invent new ones. */
2123 case '#': /* Method (class & fn) type */
2124 if ((*pp
)[0] == '#')
2126 /* We'll get the parameter types from the name. */
2127 struct type
*return_type
;
2130 return_type
= read_type (pp
, objfile
);
2131 if (*(*pp
)++ != ';')
2132 complain (&invalid_member_complaint
, symnum
);
2133 type
= allocate_stub_method (return_type
);
2134 if (typenums
[0] != -1)
2135 *dbx_lookup_type (typenums
) = type
;
2139 struct type
*domain
= read_type (pp
, objfile
);
2140 struct type
*return_type
;
2144 /* Invalid member type data format. */
2145 return error_type (pp
, objfile
);
2149 return_type
= read_type (pp
, objfile
);
2150 args
= read_args (pp
, ';', objfile
);
2151 type
= dbx_alloc_type (typenums
, objfile
);
2152 smash_to_method_type (type
, domain
, return_type
, args
);
2156 case 'r': /* Range type */
2157 type
= read_range_type (pp
, typenums
, objfile
);
2158 if (typenums
[0] != -1)
2159 *dbx_lookup_type (typenums
) = type
;
2164 /* Const and volatile qualified type. */
2165 type
= read_type (pp
, objfile
);
2168 /* Sun ACC builtin int type */
2169 type
= read_sun_builtin_type (pp
, typenums
, objfile
);
2170 if (typenums
[0] != -1)
2171 *dbx_lookup_type (typenums
) = type
;
2175 case 'R': /* Sun ACC builtin float type */
2176 type
= read_sun_floating_type (pp
, typenums
, objfile
);
2177 if (typenums
[0] != -1)
2178 *dbx_lookup_type (typenums
) = type
;
2181 case 'e': /* Enumeration type */
2182 type
= dbx_alloc_type (typenums
, objfile
);
2183 type
= read_enum_type (pp
, type
, objfile
);
2184 if (typenums
[0] != -1)
2185 *dbx_lookup_type (typenums
) = type
;
2188 case 's': /* Struct type */
2189 case 'u': /* Union type */
2190 type
= dbx_alloc_type (typenums
, objfile
);
2191 switch (type_descriptor
)
2194 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
2197 TYPE_CODE (type
) = TYPE_CODE_UNION
;
2200 type
= read_struct_type (pp
, type
, objfile
);
2203 case 'a': /* Array type */
2205 return error_type (pp
, objfile
);
2208 type
= dbx_alloc_type (typenums
, objfile
);
2209 type
= read_array_type (pp
, type
, objfile
);
2211 TYPE_CODE (type
) = TYPE_CODE_STRING
;
2215 type1
= read_type (pp
, objfile
);
2216 type
= create_set_type ((struct type
*) NULL
, type1
);
2218 TYPE_CODE (type
) = TYPE_CODE_BITSTRING
;
2219 if (typenums
[0] != -1)
2220 *dbx_lookup_type (typenums
) = type
;
2224 --*pp
; /* Go back to the symbol in error */
2225 /* Particularly important if it was \0! */
2226 return error_type (pp
, objfile
);
2231 warning ("GDB internal error, type is NULL in stabsread.c\n");
2232 return error_type (pp
, objfile
);
2235 /* Size specified in a type attribute overrides any other size. */
2236 if (type_size
!= -1)
2237 TYPE_LENGTH (type
) = (type_size
+ TARGET_CHAR_BIT
- 1) / TARGET_CHAR_BIT
;
2242 /* RS/6000 xlc/dbx combination uses a set of builtin types, starting from -1.
2243 Return the proper type node for a given builtin type number. */
2245 static struct type
*
2246 rs6000_builtin_type (typenum
)
2249 /* We recognize types numbered from -NUMBER_RECOGNIZED to -1. */
2250 #define NUMBER_RECOGNIZED 34
2251 /* This includes an empty slot for type number -0. */
2252 static struct type
*negative_types
[NUMBER_RECOGNIZED
+ 1];
2253 struct type
*rettype
= NULL
;
2255 if (typenum
>= 0 || typenum
< -NUMBER_RECOGNIZED
)
2257 complain (&rs6000_builtin_complaint
, typenum
);
2258 return builtin_type_error
;
2260 if (negative_types
[-typenum
] != NULL
)
2261 return negative_types
[-typenum
];
2263 #if TARGET_CHAR_BIT != 8
2264 #error This code wrong for TARGET_CHAR_BIT not 8
2265 /* These definitions all assume that TARGET_CHAR_BIT is 8. I think
2266 that if that ever becomes not true, the correct fix will be to
2267 make the size in the struct type to be in bits, not in units of
2274 /* The size of this and all the other types are fixed, defined
2275 by the debugging format. If there is a type called "int" which
2276 is other than 32 bits, then it should use a new negative type
2277 number (or avoid negative type numbers for that case).
2278 See stabs.texinfo. */
2279 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "int", NULL
);
2282 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "char", NULL
);
2285 rettype
= init_type (TYPE_CODE_INT
, 2, 0, "short", NULL
);
2288 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "long", NULL
);
2291 rettype
= init_type (TYPE_CODE_INT
, 1, TYPE_FLAG_UNSIGNED
,
2292 "unsigned char", NULL
);
2295 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "signed char", NULL
);
2298 rettype
= init_type (TYPE_CODE_INT
, 2, TYPE_FLAG_UNSIGNED
,
2299 "unsigned short", NULL
);
2302 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
2303 "unsigned int", NULL
);
2306 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
2309 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
2310 "unsigned long", NULL
);
2313 rettype
= init_type (TYPE_CODE_VOID
, 1, 0, "void", NULL
);
2316 /* IEEE single precision (32 bit). */
2317 rettype
= init_type (TYPE_CODE_FLT
, 4, 0, "float", NULL
);
2320 /* IEEE double precision (64 bit). */
2321 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "double", NULL
);
2324 /* This is an IEEE double on the RS/6000, and different machines with
2325 different sizes for "long double" should use different negative
2326 type numbers. See stabs.texinfo. */
2327 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "long double", NULL
);
2330 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "integer", NULL
);
2333 rettype
= init_type (TYPE_CODE_BOOL
, 4, TYPE_FLAG_UNSIGNED
,
2337 rettype
= init_type (TYPE_CODE_FLT
, 4, 0, "short real", NULL
);
2340 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "real", NULL
);
2343 rettype
= init_type (TYPE_CODE_ERROR
, 0, 0, "stringptr", NULL
);
2346 rettype
= init_type (TYPE_CODE_CHAR
, 1, TYPE_FLAG_UNSIGNED
,
2350 rettype
= init_type (TYPE_CODE_BOOL
, 1, TYPE_FLAG_UNSIGNED
,
2354 rettype
= init_type (TYPE_CODE_BOOL
, 2, TYPE_FLAG_UNSIGNED
,
2358 rettype
= init_type (TYPE_CODE_BOOL
, 4, TYPE_FLAG_UNSIGNED
,
2362 rettype
= init_type (TYPE_CODE_BOOL
, 4, TYPE_FLAG_UNSIGNED
,
2366 /* Complex type consisting of two IEEE single precision values. */
2367 rettype
= init_type (TYPE_CODE_ERROR
, 8, 0, "complex", NULL
);
2370 /* Complex type consisting of two IEEE double precision values. */
2371 rettype
= init_type (TYPE_CODE_ERROR
, 16, 0, "double complex", NULL
);
2374 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "integer*1", NULL
);
2377 rettype
= init_type (TYPE_CODE_INT
, 2, 0, "integer*2", NULL
);
2380 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "integer*4", NULL
);
2383 rettype
= init_type (TYPE_CODE_CHAR
, 2, 0, "wchar", NULL
);
2386 rettype
= init_type (TYPE_CODE_INT
, 8, 0, "long long", NULL
);
2389 rettype
= init_type (TYPE_CODE_INT
, 8, TYPE_FLAG_UNSIGNED
,
2390 "unsigned long long", NULL
);
2393 rettype
= init_type (TYPE_CODE_INT
, 8, TYPE_FLAG_UNSIGNED
,
2397 rettype
= init_type (TYPE_CODE_INT
, 8, 0, "integer*8", NULL
);
2400 negative_types
[-typenum
] = rettype
;
2404 /* This page contains subroutines of read_type. */
2406 /* Read member function stabs info for C++ classes. The form of each member
2409 NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
2411 An example with two member functions is:
2413 afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
2415 For the case of overloaded operators, the format is op$::*.funcs, where
2416 $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
2417 name (such as `+=') and `.' marks the end of the operator name.
2419 Returns 1 for success, 0 for failure. */
2422 read_member_functions (fip
, pp
, type
, objfile
)
2423 struct field_info
*fip
;
2426 struct objfile
*objfile
;
2430 /* Total number of member functions defined in this class. If the class
2431 defines two `f' functions, and one `g' function, then this will have
2433 int total_length
= 0;
2437 struct next_fnfield
*next
;
2438 struct fn_field fn_field
;
2440 struct type
*look_ahead_type
;
2441 struct next_fnfieldlist
*new_fnlist
;
2442 struct next_fnfield
*new_sublist
;
2446 /* Process each list until we find something that is not a member function
2447 or find the end of the functions. */
2451 /* We should be positioned at the start of the function name.
2452 Scan forward to find the first ':' and if it is not the
2453 first of a "::" delimiter, then this is not a member function. */
2465 look_ahead_type
= NULL
;
2468 new_fnlist
= (struct next_fnfieldlist
*)
2469 xmalloc (sizeof (struct next_fnfieldlist
));
2470 make_cleanup (free
, new_fnlist
);
2471 memset (new_fnlist
, 0, sizeof (struct next_fnfieldlist
));
2473 if ((*pp
)[0] == 'o' && (*pp
)[1] == 'p' && is_cplus_marker ((*pp
)[2]))
2475 /* This is a completely wierd case. In order to stuff in the
2476 names that might contain colons (the usual name delimiter),
2477 Mike Tiemann defined a different name format which is
2478 signalled if the identifier is "op$". In that case, the
2479 format is "op$::XXXX." where XXXX is the name. This is
2480 used for names like "+" or "=". YUUUUUUUK! FIXME! */
2481 /* This lets the user type "break operator+".
2482 We could just put in "+" as the name, but that wouldn't
2484 static char opname
[32] = {'o', 'p', CPLUS_MARKER
};
2485 char *o
= opname
+ 3;
2487 /* Skip past '::'. */
2490 STABS_CONTINUE (pp
, objfile
);
2496 main_fn_name
= savestring (opname
, o
- opname
);
2502 main_fn_name
= savestring (*pp
, p
- *pp
);
2503 /* Skip past '::'. */
2506 new_fnlist
-> fn_fieldlist
.name
= main_fn_name
;
2511 (struct next_fnfield
*) xmalloc (sizeof (struct next_fnfield
));
2512 make_cleanup (free
, new_sublist
);
2513 memset (new_sublist
, 0, sizeof (struct next_fnfield
));
2515 /* Check for and handle cretinous dbx symbol name continuation! */
2516 if (look_ahead_type
== NULL
)
2519 STABS_CONTINUE (pp
, objfile
);
2521 new_sublist
-> fn_field
.type
= read_type (pp
, objfile
);
2524 /* Invalid symtab info for member function. */
2530 /* g++ version 1 kludge */
2531 new_sublist
-> fn_field
.type
= look_ahead_type
;
2532 look_ahead_type
= NULL
;
2542 /* If this is just a stub, then we don't have the real name here. */
2544 if (TYPE_FLAGS (new_sublist
-> fn_field
.type
) & TYPE_FLAG_STUB
)
2546 if (!TYPE_DOMAIN_TYPE (new_sublist
-> fn_field
.type
))
2547 TYPE_DOMAIN_TYPE (new_sublist
-> fn_field
.type
) = type
;
2548 new_sublist
-> fn_field
.is_stub
= 1;
2550 new_sublist
-> fn_field
.physname
= savestring (*pp
, p
- *pp
);
2553 /* Set this member function's visibility fields. */
2556 case VISIBILITY_PRIVATE
:
2557 new_sublist
-> fn_field
.is_private
= 1;
2559 case VISIBILITY_PROTECTED
:
2560 new_sublist
-> fn_field
.is_protected
= 1;
2564 STABS_CONTINUE (pp
, objfile
);
2567 case 'A': /* Normal functions. */
2568 new_sublist
-> fn_field
.is_const
= 0;
2569 new_sublist
-> fn_field
.is_volatile
= 0;
2572 case 'B': /* `const' member functions. */
2573 new_sublist
-> fn_field
.is_const
= 1;
2574 new_sublist
-> fn_field
.is_volatile
= 0;
2577 case 'C': /* `volatile' member function. */
2578 new_sublist
-> fn_field
.is_const
= 0;
2579 new_sublist
-> fn_field
.is_volatile
= 1;
2582 case 'D': /* `const volatile' member function. */
2583 new_sublist
-> fn_field
.is_const
= 1;
2584 new_sublist
-> fn_field
.is_volatile
= 1;
2587 case '*': /* File compiled with g++ version 1 -- no info */
2592 complain (&const_vol_complaint
, **pp
);
2601 /* virtual member function, followed by index.
2602 The sign bit is set to distinguish pointers-to-methods
2603 from virtual function indicies. Since the array is
2604 in words, the quantity must be shifted left by 1
2605 on 16 bit machine, and by 2 on 32 bit machine, forcing
2606 the sign bit out, and usable as a valid index into
2607 the array. Remove the sign bit here. */
2608 new_sublist
-> fn_field
.voffset
=
2609 (0x7fffffff & read_huge_number (pp
, ';', &nbits
)) + 2;
2613 STABS_CONTINUE (pp
, objfile
);
2614 if (**pp
== ';' || **pp
== '\0')
2616 /* Must be g++ version 1. */
2617 new_sublist
-> fn_field
.fcontext
= 0;
2621 /* Figure out from whence this virtual function came.
2622 It may belong to virtual function table of
2623 one of its baseclasses. */
2624 look_ahead_type
= read_type (pp
, objfile
);
2627 /* g++ version 1 overloaded methods. */
2631 new_sublist
-> fn_field
.fcontext
= look_ahead_type
;
2640 look_ahead_type
= NULL
;
2646 /* static member function. */
2647 new_sublist
-> fn_field
.voffset
= VOFFSET_STATIC
;
2648 if (strncmp (new_sublist
-> fn_field
.physname
,
2649 main_fn_name
, strlen (main_fn_name
)))
2651 new_sublist
-> fn_field
.is_stub
= 1;
2657 complain (&member_fn_complaint
, (*pp
)[-1]);
2658 /* Fall through into normal member function. */
2661 /* normal member function. */
2662 new_sublist
-> fn_field
.voffset
= 0;
2663 new_sublist
-> fn_field
.fcontext
= 0;
2667 new_sublist
-> next
= sublist
;
2668 sublist
= new_sublist
;
2670 STABS_CONTINUE (pp
, objfile
);
2672 while (**pp
!= ';' && **pp
!= '\0');
2676 new_fnlist
-> fn_fieldlist
.fn_fields
= (struct fn_field
*)
2677 obstack_alloc (&objfile
-> type_obstack
,
2678 sizeof (struct fn_field
) * length
);
2679 memset (new_fnlist
-> fn_fieldlist
.fn_fields
, 0,
2680 sizeof (struct fn_field
) * length
);
2681 for (i
= length
; (i
--, sublist
); sublist
= sublist
-> next
)
2683 new_fnlist
-> fn_fieldlist
.fn_fields
[i
] = sublist
-> fn_field
;
2686 new_fnlist
-> fn_fieldlist
.length
= length
;
2687 new_fnlist
-> next
= fip
-> fnlist
;
2688 fip
-> fnlist
= new_fnlist
;
2690 total_length
+= length
;
2691 STABS_CONTINUE (pp
, objfile
);
2696 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2697 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2698 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * nfn_fields
);
2699 memset (TYPE_FN_FIELDLISTS (type
), 0,
2700 sizeof (struct fn_fieldlist
) * nfn_fields
);
2701 TYPE_NFN_FIELDS (type
) = nfn_fields
;
2702 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2708 /* Special GNU C++ name.
2710 Returns 1 for success, 0 for failure. "failure" means that we can't
2711 keep parsing and it's time for error_type(). */
2714 read_cpp_abbrev (fip
, pp
, type
, objfile
)
2715 struct field_info
*fip
;
2718 struct objfile
*objfile
;
2723 struct type
*context
;
2733 /* At this point, *pp points to something like "22:23=*22...",
2734 where the type number before the ':' is the "context" and
2735 everything after is a regular type definition. Lookup the
2736 type, find it's name, and construct the field name. */
2738 context
= read_type (pp
, objfile
);
2742 case 'f': /* $vf -- a virtual function table pointer */
2743 fip
->list
->field
.name
=
2744 obconcat (&objfile
->type_obstack
, vptr_name
, "", "");
2747 case 'b': /* $vb -- a virtual bsomethingorother */
2748 name
= type_name_no_tag (context
);
2751 complain (&invalid_cpp_type_complaint
, symnum
);
2754 fip
->list
->field
.name
=
2755 obconcat (&objfile
->type_obstack
, vb_name
, name
, "");
2759 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2760 fip
->list
->field
.name
=
2761 obconcat (&objfile
->type_obstack
,
2762 "INVALID_CPLUSPLUS_ABBREV", "", "");
2766 /* At this point, *pp points to the ':'. Skip it and read the
2772 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2775 fip
->list
->field
.type
= read_type (pp
, objfile
);
2777 (*pp
)++; /* Skip the comma. */
2783 fip
->list
->field
.bitpos
= read_huge_number (pp
, ';', &nbits
);
2787 /* This field is unpacked. */
2788 fip
->list
->field
.bitsize
= 0;
2789 fip
->list
->visibility
= VISIBILITY_PRIVATE
;
2793 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2794 /* We have no idea what syntax an unrecognized abbrev would have, so
2795 better return 0. If we returned 1, we would need to at least advance
2796 *pp to avoid an infinite loop. */
2803 read_one_struct_field (fip
, pp
, p
, type
, objfile
)
2804 struct field_info
*fip
;
2808 struct objfile
*objfile
;
2810 /* The following is code to work around cfront generated stabs.
2811 The stabs contains full mangled name for each field.
2812 We try to demangle the name and extract the field name out of it.
2814 if (ARM_DEMANGLING
&& current_subfile
->language
== language_cplus
)
2820 dem
= cplus_demangle (*pp
, DMGL_ANSI
| DMGL_PARAMS
);
2823 dem_p
= strrchr (dem
, ':');
2824 if (dem_p
!= 0 && *(dem_p
-1)==':')
2826 fip
->list
->field
.name
=
2827 obsavestring (dem_p
, strlen(dem_p
), &objfile
-> type_obstack
);
2831 fip
->list
->field
.name
=
2832 obsavestring (*pp
, p
- *pp
, &objfile
-> type_obstack
);
2836 /* end of code for cfront work around */
2839 fip
-> list
-> field
.name
=
2840 obsavestring (*pp
, p
- *pp
, &objfile
-> type_obstack
);
2843 /* This means we have a visibility for a field coming. */
2847 fip
-> list
-> visibility
= *(*pp
)++;
2851 /* normal dbx-style format, no explicit visibility */
2852 fip
-> list
-> visibility
= VISIBILITY_PUBLIC
;
2855 fip
-> list
-> field
.type
= read_type (pp
, objfile
);
2860 /* Possible future hook for nested types. */
2863 fip
-> list
-> field
.bitpos
= (long)-2; /* nested type */
2869 /* Static class member. */
2870 fip
-> list
-> field
.bitpos
= (long) -1;
2876 fip
-> list
-> field
.bitsize
= (long) savestring (*pp
, p
- *pp
);
2880 else if (**pp
!= ',')
2882 /* Bad structure-type format. */
2883 complain (&stabs_general_complaint
, "bad structure-type format");
2887 (*pp
)++; /* Skip the comma. */
2891 fip
-> list
-> field
.bitpos
= read_huge_number (pp
, ',', &nbits
);
2894 complain (&stabs_general_complaint
, "bad structure-type format");
2897 fip
-> list
-> field
.bitsize
= read_huge_number (pp
, ';', &nbits
);
2900 complain (&stabs_general_complaint
, "bad structure-type format");
2905 if (fip
-> list
-> field
.bitpos
== 0 && fip
-> list
-> field
.bitsize
== 0)
2907 /* This can happen in two cases: (1) at least for gcc 2.4.5 or so,
2908 it is a field which has been optimized out. The correct stab for
2909 this case is to use VISIBILITY_IGNORE, but that is a recent
2910 invention. (2) It is a 0-size array. For example
2911 union { int num; char str[0]; } foo. Printing "<no value>" for
2912 str in "p foo" is OK, since foo.str (and thus foo.str[3])
2913 will continue to work, and a 0-size array as a whole doesn't
2914 have any contents to print.
2916 I suspect this probably could also happen with gcc -gstabs (not
2917 -gstabs+) for static fields, and perhaps other C++ extensions.
2918 Hopefully few people use -gstabs with gdb, since it is intended
2919 for dbx compatibility. */
2921 /* Ignore this field. */
2922 fip
-> list
-> visibility
= VISIBILITY_IGNORE
;
2926 /* Detect an unpacked field and mark it as such.
2927 dbx gives a bit size for all fields.
2928 Note that forward refs cannot be packed,
2929 and treat enums as if they had the width of ints. */
2931 if (TYPE_CODE (fip
-> list
-> field
.type
) != TYPE_CODE_INT
2932 && TYPE_CODE (fip
-> list
-> field
.type
) != TYPE_CODE_BOOL
2933 && TYPE_CODE (fip
-> list
-> field
.type
) != TYPE_CODE_ENUM
)
2935 fip
-> list
-> field
.bitsize
= 0;
2937 if ((fip
-> list
-> field
.bitsize
2938 == TARGET_CHAR_BIT
* TYPE_LENGTH (fip
-> list
-> field
.type
)
2939 || (TYPE_CODE (fip
-> list
-> field
.type
) == TYPE_CODE_ENUM
2940 && (fip
-> list
-> field
.bitsize
2945 fip
-> list
-> field
.bitpos
% 8 == 0)
2947 fip
-> list
-> field
.bitsize
= 0;
2953 /* Read struct or class data fields. They have the form:
2955 NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
2957 At the end, we see a semicolon instead of a field.
2959 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
2962 The optional VISIBILITY is one of:
2964 '/0' (VISIBILITY_PRIVATE)
2965 '/1' (VISIBILITY_PROTECTED)
2966 '/2' (VISIBILITY_PUBLIC)
2967 '/9' (VISIBILITY_IGNORE)
2969 or nothing, for C style fields with public visibility.
2971 Returns 1 for success, 0 for failure. */
2974 read_struct_fields (fip
, pp
, type
, objfile
)
2975 struct field_info
*fip
;
2978 struct objfile
*objfile
;
2981 struct nextfield
*new;
2983 /* We better set p right now, in case there are no fields at all... */
2987 /* Read each data member type until we find the terminating ';' at the end of
2988 the data member list, or break for some other reason such as finding the
2989 start of the member function list. */
2993 if (os9k_stabs
&& **pp
== ',') break;
2994 STABS_CONTINUE (pp
, objfile
);
2995 /* Get space to record the next field's data. */
2996 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
2997 make_cleanup (free
, new);
2998 memset (new, 0, sizeof (struct nextfield
));
2999 new -> next
= fip
-> list
;
3002 /* Get the field name. */
3005 /* If is starts with CPLUS_MARKER it is a special abbreviation,
3006 unless the CPLUS_MARKER is followed by an underscore, in
3007 which case it is just the name of an anonymous type, which we
3008 should handle like any other type name. */
3010 if (is_cplus_marker (p
[0]) && p
[1] != '_')
3012 if (!read_cpp_abbrev (fip
, pp
, type
, objfile
))
3017 /* Look for the ':' that separates the field name from the field
3018 values. Data members are delimited by a single ':', while member
3019 functions are delimited by a pair of ':'s. When we hit the member
3020 functions (if any), terminate scan loop and return. */
3022 while (*p
!= ':' && *p
!= '\0')
3029 /* Check to see if we have hit the member functions yet. */
3034 read_one_struct_field (fip
, pp
, p
, type
, objfile
);
3036 if (p
[0] == ':' && p
[1] == ':')
3038 /* chill the list of fields: the last entry (at the head) is a
3039 partially constructed entry which we now scrub. */
3040 fip
-> list
= fip
-> list
-> next
;
3045 /* The stabs for C++ derived classes contain baseclass information which
3046 is marked by a '!' character after the total size. This function is
3047 called when we encounter the baseclass marker, and slurps up all the
3048 baseclass information.
3050 Immediately following the '!' marker is the number of base classes that
3051 the class is derived from, followed by information for each base class.
3052 For each base class, there are two visibility specifiers, a bit offset
3053 to the base class information within the derived class, a reference to
3054 the type for the base class, and a terminating semicolon.
3056 A typical example, with two base classes, would be "!2,020,19;0264,21;".
3058 Baseclass information marker __________________|| | | | | | |
3059 Number of baseclasses __________________________| | | | | | |
3060 Visibility specifiers (2) ________________________| | | | | |
3061 Offset in bits from start of class _________________| | | | |
3062 Type number for base class ___________________________| | | |
3063 Visibility specifiers (2) _______________________________| | |
3064 Offset in bits from start of class ________________________| |
3065 Type number of base class ____________________________________|
3067 Return 1 for success, 0 for (error-type-inducing) failure. */
3070 read_baseclasses (fip
, pp
, type
, objfile
)
3071 struct field_info
*fip
;
3074 struct objfile
*objfile
;
3077 struct nextfield
*new;
3085 /* Skip the '!' baseclass information marker. */
3089 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3092 TYPE_N_BASECLASSES (type
) = read_huge_number (pp
, ',', &nbits
);
3098 /* Some stupid compilers have trouble with the following, so break
3099 it up into simpler expressions. */
3100 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*)
3101 TYPE_ALLOC (type
, B_BYTES (TYPE_N_BASECLASSES (type
)));
3104 int num_bytes
= B_BYTES (TYPE_N_BASECLASSES (type
));
3107 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
3108 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
3112 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), TYPE_N_BASECLASSES (type
));
3114 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
3116 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3117 make_cleanup (free
, new);
3118 memset (new, 0, sizeof (struct nextfield
));
3119 new -> next
= fip
-> list
;
3121 new -> field
.bitsize
= 0; /* this should be an unpacked field! */
3123 STABS_CONTINUE (pp
, objfile
);
3127 /* Nothing to do. */
3130 SET_TYPE_FIELD_VIRTUAL (type
, i
);
3133 /* Unknown character. Complain and treat it as non-virtual. */
3135 static struct complaint msg
= {
3136 "Unknown virtual character `%c' for baseclass", 0, 0};
3137 complain (&msg
, **pp
);
3142 new -> visibility
= *(*pp
)++;
3143 switch (new -> visibility
)
3145 case VISIBILITY_PRIVATE
:
3146 case VISIBILITY_PROTECTED
:
3147 case VISIBILITY_PUBLIC
:
3150 /* Bad visibility format. Complain and treat it as
3153 static struct complaint msg
= {
3154 "Unknown visibility `%c' for baseclass", 0, 0};
3155 complain (&msg
, new -> visibility
);
3156 new -> visibility
= VISIBILITY_PUBLIC
;
3163 /* The remaining value is the bit offset of the portion of the object
3164 corresponding to this baseclass. Always zero in the absence of
3165 multiple inheritance. */
3167 new -> field
.bitpos
= read_huge_number (pp
, ',', &nbits
);
3172 /* The last piece of baseclass information is the type of the
3173 base class. Read it, and remember it's type name as this
3176 new -> field
.type
= read_type (pp
, objfile
);
3177 new -> field
.name
= type_name_no_tag (new -> field
.type
);
3179 /* skip trailing ';' and bump count of number of fields seen */
3188 /* The tail end of stabs for C++ classes that contain a virtual function
3189 pointer contains a tilde, a %, and a type number.
3190 The type number refers to the base class (possibly this class itself) which
3191 contains the vtable pointer for the current class.
3193 This function is called when we have parsed all the method declarations,
3194 so we can look for the vptr base class info. */
3197 read_tilde_fields (fip
, pp
, type
, objfile
)
3198 struct field_info
*fip
;
3201 struct objfile
*objfile
;
3205 STABS_CONTINUE (pp
, objfile
);
3207 /* If we are positioned at a ';', then skip it. */
3217 if (**pp
== '=' || **pp
== '+' || **pp
== '-')
3219 /* Obsolete flags that used to indicate the presence
3220 of constructors and/or destructors. */
3224 /* Read either a '%' or the final ';'. */
3225 if (*(*pp
)++ == '%')
3227 /* The next number is the type number of the base class
3228 (possibly our own class) which supplies the vtable for
3229 this class. Parse it out, and search that class to find
3230 its vtable pointer, and install those into TYPE_VPTR_BASETYPE
3231 and TYPE_VPTR_FIELDNO. */
3236 t
= read_type (pp
, objfile
);
3238 while (*p
!= '\0' && *p
!= ';')
3244 /* Premature end of symbol. */
3248 TYPE_VPTR_BASETYPE (type
) = t
;
3249 if (type
== t
) /* Our own class provides vtbl ptr */
3251 for (i
= TYPE_NFIELDS (t
) - 1;
3252 i
>= TYPE_N_BASECLASSES (t
);
3255 if (! strncmp (TYPE_FIELD_NAME (t
, i
), vptr_name
,
3256 sizeof (vptr_name
) - 1))
3258 TYPE_VPTR_FIELDNO (type
) = i
;
3262 /* Virtual function table field not found. */
3263 complain (&vtbl_notfound_complaint
, TYPE_NAME (type
));
3268 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
3279 attach_fn_fields_to_type (fip
, type
)
3280 struct field_info
*fip
;
3281 register struct type
*type
;
3285 for (n
= TYPE_NFN_FIELDS (type
);
3286 fip
-> fnlist
!= NULL
;
3287 fip
-> fnlist
= fip
-> fnlist
-> next
)
3289 --n
; /* Circumvent Sun3 compiler bug */
3290 TYPE_FN_FIELDLISTS (type
)[n
] = fip
-> fnlist
-> fn_fieldlist
;
3295 /* Create the vector of fields, and record how big it is.
3296 We need this info to record proper virtual function table information
3297 for this class's virtual functions. */
3300 attach_fields_to_type (fip
, type
, objfile
)
3301 struct field_info
*fip
;
3302 register struct type
*type
;
3303 struct objfile
*objfile
;
3305 register int nfields
= 0;
3306 register int non_public_fields
= 0;
3307 register struct nextfield
*scan
;
3309 /* Count up the number of fields that we have, as well as taking note of
3310 whether or not there are any non-public fields, which requires us to
3311 allocate and build the private_field_bits and protected_field_bits
3314 for (scan
= fip
-> list
; scan
!= NULL
; scan
= scan
-> next
)
3317 if (scan
-> visibility
!= VISIBILITY_PUBLIC
)
3319 non_public_fields
++;
3323 /* Now we know how many fields there are, and whether or not there are any
3324 non-public fields. Record the field count, allocate space for the
3325 array of fields, and create blank visibility bitfields if necessary. */
3327 TYPE_NFIELDS (type
) = nfields
;
3328 TYPE_FIELDS (type
) = (struct field
*)
3329 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
3330 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
3332 if (non_public_fields
)
3334 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3336 TYPE_FIELD_PRIVATE_BITS (type
) =
3337 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3338 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
3340 TYPE_FIELD_PROTECTED_BITS (type
) =
3341 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3342 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
3344 TYPE_FIELD_IGNORE_BITS (type
) =
3345 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3346 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
3349 /* Copy the saved-up fields into the field vector. Start from the head
3350 of the list, adding to the tail of the field array, so that they end
3351 up in the same order in the array in which they were added to the list. */
3353 while (nfields
-- > 0)
3355 TYPE_FIELD (type
, nfields
) = fip
-> list
-> field
;
3356 switch (fip
-> list
-> visibility
)
3358 case VISIBILITY_PRIVATE
:
3359 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
3362 case VISIBILITY_PROTECTED
:
3363 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
3366 case VISIBILITY_IGNORE
:
3367 SET_TYPE_FIELD_IGNORE (type
, nfields
);
3370 case VISIBILITY_PUBLIC
:
3374 /* Unknown visibility. Complain and treat it as public. */
3376 static struct complaint msg
= {
3377 "Unknown visibility `%c' for field", 0, 0};
3378 complain (&msg
, fip
-> list
-> visibility
);
3382 fip
-> list
= fip
-> list
-> next
;
3387 /* Read the description of a structure (or union type) and return an object
3388 describing the type.
3390 PP points to a character pointer that points to the next unconsumed token
3391 in the the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
3392 *PP will point to "4a:1,0,32;;".
3394 TYPE points to an incomplete type that needs to be filled in.
3396 OBJFILE points to the current objfile from which the stabs information is
3397 being read. (Note that it is redundant in that TYPE also contains a pointer
3398 to this same objfile, so it might be a good idea to eliminate it. FIXME).
3401 static struct type
*
3402 read_struct_type (pp
, type
, objfile
)
3405 struct objfile
*objfile
;
3407 struct cleanup
*back_to
;
3408 struct field_info fi
;
3413 back_to
= make_cleanup (null_cleanup
, 0);
3415 INIT_CPLUS_SPECIFIC (type
);
3416 TYPE_FLAGS (type
) &= ~TYPE_FLAG_STUB
;
3418 /* First comes the total size in bytes. */
3422 TYPE_LENGTH (type
) = read_huge_number (pp
, 0, &nbits
);
3424 return error_type (pp
, objfile
);
3427 /* Now read the baseclasses, if any, read the regular C struct or C++
3428 class member fields, attach the fields to the type, read the C++
3429 member functions, attach them to the type, and then read any tilde
3430 field (baseclass specifier for the class holding the main vtable). */
3432 if (!read_baseclasses (&fi
, pp
, type
, objfile
)
3433 || !read_struct_fields (&fi
, pp
, type
, objfile
)
3434 || !attach_fields_to_type (&fi
, type
, objfile
)
3435 || !read_member_functions (&fi
, pp
, type
, objfile
)
3436 || !attach_fn_fields_to_type (&fi
, type
)
3437 || !read_tilde_fields (&fi
, pp
, type
, objfile
))
3439 type
= error_type (pp
, objfile
);
3442 do_cleanups (back_to
);
3446 /* Read a definition of an array type,
3447 and create and return a suitable type object.
3448 Also creates a range type which represents the bounds of that
3451 static struct type
*
3452 read_array_type (pp
, type
, objfile
)
3454 register struct type
*type
;
3455 struct objfile
*objfile
;
3457 struct type
*index_type
, *element_type
, *range_type
;
3462 /* Format of an array type:
3463 "ar<index type>;lower;upper;<array_contents_type>".
3464 OS9000: "arlower,upper;<array_contents_type>".
3466 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
3467 for these, produce a type like float[][]. */
3470 index_type
= builtin_type_int
;
3473 index_type
= read_type (pp
, objfile
);
3475 /* Improper format of array type decl. */
3476 return error_type (pp
, objfile
);
3480 if (!(**pp
>= '0' && **pp
<= '9') && **pp
!= '-')
3485 lower
= read_huge_number (pp
, os9k_stabs
? ',' : ';', &nbits
);
3487 return error_type (pp
, objfile
);
3489 if (!(**pp
>= '0' && **pp
<= '9') && **pp
!= '-')
3494 upper
= read_huge_number (pp
, ';', &nbits
);
3496 return error_type (pp
, objfile
);
3498 element_type
= read_type (pp
, objfile
);
3507 create_range_type ((struct type
*) NULL
, index_type
, lower
, upper
);
3508 type
= create_array_type (type
, element_type
, range_type
);
3514 /* Read a definition of an enumeration type,
3515 and create and return a suitable type object.
3516 Also defines the symbols that represent the values of the type. */
3518 static struct type
*
3519 read_enum_type (pp
, type
, objfile
)
3521 register struct type
*type
;
3522 struct objfile
*objfile
;
3527 register struct symbol
*sym
;
3529 struct pending
**symlist
;
3530 struct pending
*osyms
, *syms
;
3533 int unsigned_enum
= 1;
3536 /* FIXME! The stabs produced by Sun CC merrily define things that ought
3537 to be file-scope, between N_FN entries, using N_LSYM. What's a mother
3538 to do? For now, force all enum values to file scope. */
3539 if (within_function
)
3540 symlist
= &local_symbols
;
3543 symlist
= &file_symbols
;
3545 o_nsyms
= osyms
? osyms
->nsyms
: 0;
3549 /* Size. Perhaps this does not have to be conditionalized on
3550 os9k_stabs (assuming the name of an enum constant can't start
3552 read_huge_number (pp
, 0, &nbits
);
3554 return error_type (pp
, objfile
);
3557 /* The aix4 compiler emits an extra field before the enum members;
3558 my guess is it's a type of some sort. Just ignore it. */
3561 /* Skip over the type. */
3565 /* Skip over the colon. */
3569 /* Read the value-names and their values.
3570 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
3571 A semicolon or comma instead of a NAME means the end. */
3572 while (**pp
&& **pp
!= ';' && **pp
!= ',')
3574 STABS_CONTINUE (pp
, objfile
);
3576 while (*p
!= ':') p
++;
3577 name
= obsavestring (*pp
, p
- *pp
, &objfile
-> symbol_obstack
);
3579 n
= read_huge_number (pp
, ',', &nbits
);
3581 return error_type (pp
, objfile
);
3583 sym
= (struct symbol
*)
3584 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
3585 memset (sym
, 0, sizeof (struct symbol
));
3586 SYMBOL_NAME (sym
) = name
;
3587 SYMBOL_LANGUAGE (sym
) = current_subfile
-> language
;
3588 SYMBOL_CLASS (sym
) = LOC_CONST
;
3589 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
3590 SYMBOL_VALUE (sym
) = n
;
3593 add_symbol_to_list (sym
, symlist
);
3598 (*pp
)++; /* Skip the semicolon. */
3600 /* Now fill in the fields of the type-structure. */
3602 TYPE_LENGTH (type
) = TARGET_INT_BIT
/ HOST_CHAR_BIT
;
3603 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
3604 TYPE_FLAGS (type
) &= ~TYPE_FLAG_STUB
;
3606 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
3607 TYPE_NFIELDS (type
) = nsyms
;
3608 TYPE_FIELDS (type
) = (struct field
*)
3609 TYPE_ALLOC (type
, sizeof (struct field
) * nsyms
);
3610 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nsyms
);
3612 /* Find the symbols for the values and put them into the type.
3613 The symbols can be found in the symlist that we put them on
3614 to cause them to be defined. osyms contains the old value
3615 of that symlist; everything up to there was defined by us. */
3616 /* Note that we preserve the order of the enum constants, so
3617 that in something like "enum {FOO, LAST_THING=FOO}" we print
3618 FOO, not LAST_THING. */
3620 for (syms
= *symlist
, n
= nsyms
- 1; syms
; syms
= syms
->next
)
3622 int last
= syms
== osyms
? o_nsyms
: 0;
3623 int j
= syms
->nsyms
;
3624 for (; --j
>= last
; --n
)
3626 struct symbol
*xsym
= syms
->symbol
[j
];
3627 SYMBOL_TYPE (xsym
) = type
;
3628 TYPE_FIELD_NAME (type
, n
) = SYMBOL_NAME (xsym
);
3629 TYPE_FIELD_VALUE (type
, n
) = 0;
3630 TYPE_FIELD_BITPOS (type
, n
) = SYMBOL_VALUE (xsym
);
3631 TYPE_FIELD_BITSIZE (type
, n
) = 0;
3640 /* Sun's ACC uses a somewhat saner method for specifying the builtin
3641 typedefs in every file (for int, long, etc):
3643 type = b <signed> <width>; <offset>; <nbits>
3644 signed = u or s. Possible c in addition to u or s (for char?).
3645 offset = offset from high order bit to start bit of type.
3646 width is # bytes in object of this type, nbits is # bits in type.
3648 The width/offset stuff appears to be for small objects stored in
3649 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
3652 static struct type
*
3653 read_sun_builtin_type (pp
, typenums
, objfile
)
3656 struct objfile
*objfile
;
3671 return error_type (pp
, objfile
);
3675 /* For some odd reason, all forms of char put a c here. This is strange
3676 because no other type has this honor. We can safely ignore this because
3677 we actually determine 'char'acterness by the number of bits specified in
3683 /* The first number appears to be the number of bytes occupied
3684 by this type, except that unsigned short is 4 instead of 2.
3685 Since this information is redundant with the third number,
3686 we will ignore it. */
3687 read_huge_number (pp
, ';', &nbits
);
3689 return error_type (pp
, objfile
);
3691 /* The second number is always 0, so ignore it too. */
3692 read_huge_number (pp
, ';', &nbits
);
3694 return error_type (pp
, objfile
);
3696 /* The third number is the number of bits for this type. */
3697 type_bits
= read_huge_number (pp
, 0, &nbits
);
3699 return error_type (pp
, objfile
);
3700 /* The type *should* end with a semicolon. If it are embedded
3701 in a larger type the semicolon may be the only way to know where
3702 the type ends. If this type is at the end of the stabstring we
3703 can deal with the omitted semicolon (but we don't have to like
3704 it). Don't bother to complain(), Sun's compiler omits the semicolon
3710 return init_type (TYPE_CODE_VOID
, 1,
3711 signed_type
? 0 : TYPE_FLAG_UNSIGNED
, (char *)NULL
,
3714 return init_type (TYPE_CODE_INT
,
3715 type_bits
/ TARGET_CHAR_BIT
,
3716 signed_type
? 0 : TYPE_FLAG_UNSIGNED
, (char *)NULL
,
3720 static struct type
*
3721 read_sun_floating_type (pp
, typenums
, objfile
)
3724 struct objfile
*objfile
;
3730 /* The first number has more details about the type, for example
3732 details
= read_huge_number (pp
, ';', &nbits
);
3734 return error_type (pp
, objfile
);
3736 /* The second number is the number of bytes occupied by this type */
3737 nbytes
= read_huge_number (pp
, ';', &nbits
);
3739 return error_type (pp
, objfile
);
3741 if (details
== NF_COMPLEX
|| details
== NF_COMPLEX16
3742 || details
== NF_COMPLEX32
)
3743 /* This is a type we can't handle, but we do know the size.
3744 We also will be able to give it a name. */
3745 return init_type (TYPE_CODE_ERROR
, nbytes
, 0, NULL
, objfile
);
3747 return init_type (TYPE_CODE_FLT
, nbytes
, 0, NULL
, objfile
);
3750 /* Read a number from the string pointed to by *PP.
3751 The value of *PP is advanced over the number.
3752 If END is nonzero, the character that ends the
3753 number must match END, or an error happens;
3754 and that character is skipped if it does match.
3755 If END is zero, *PP is left pointing to that character.
3757 If the number fits in a long, set *BITS to 0 and return the value.
3758 If not, set *BITS to be the number of bits in the number and return 0.
3760 If encounter garbage, set *BITS to -1 and return 0. */
3763 read_huge_number (pp
, end
, bits
)
3783 /* Leading zero means octal. GCC uses this to output values larger
3784 than an int (because that would be hard in decimal). */
3792 upper_limit
= ULONG_MAX
/ radix
;
3794 upper_limit
= LONG_MAX
/ radix
;
3796 while ((c
= *p
++) >= '0' && c
< ('0' + radix
))
3798 if (n
<= upper_limit
)
3801 n
+= c
- '0'; /* FIXME this overflows anyway */
3806 /* This depends on large values being output in octal, which is
3813 /* Ignore leading zeroes. */
3817 else if (c
== '2' || c
== '3')
3843 /* Large decimal constants are an error (because it is hard to
3844 count how many bits are in them). */
3850 /* -0x7f is the same as 0x80. So deal with it by adding one to
3851 the number of bits. */
3863 /* It's *BITS which has the interesting information. */
3867 static struct type
*
3868 read_range_type (pp
, typenums
, objfile
)
3871 struct objfile
*objfile
;
3873 char *orig_pp
= *pp
;
3878 struct type
*result_type
;
3879 struct type
*index_type
= NULL
;
3881 /* First comes a type we are a subrange of.
3882 In C it is usually 0, 1 or the type being defined. */
3883 if (read_type_number (pp
, rangenums
) != 0)
3884 return error_type (pp
, objfile
);
3885 self_subrange
= (rangenums
[0] == typenums
[0] &&
3886 rangenums
[1] == typenums
[1]);
3891 index_type
= read_type (pp
, objfile
);
3894 /* A semicolon should now follow; skip it. */
3898 /* The remaining two operands are usually lower and upper bounds
3899 of the range. But in some special cases they mean something else. */
3900 n2
= read_huge_number (pp
, ';', &n2bits
);
3901 n3
= read_huge_number (pp
, ';', &n3bits
);
3903 if (n2bits
== -1 || n3bits
== -1)
3904 return error_type (pp
, objfile
);
3907 goto handle_true_range
;
3909 /* If limits are huge, must be large integral type. */
3910 if (n2bits
!= 0 || n3bits
!= 0)
3912 char got_signed
= 0;
3913 char got_unsigned
= 0;
3914 /* Number of bits in the type. */
3917 /* Range from 0 to <large number> is an unsigned large integral type. */
3918 if ((n2bits
== 0 && n2
== 0) && n3bits
!= 0)
3923 /* Range from <large number> to <large number>-1 is a large signed
3924 integral type. Take care of the case where <large number> doesn't
3925 fit in a long but <large number>-1 does. */
3926 else if ((n2bits
!= 0 && n3bits
!= 0 && n2bits
== n3bits
+ 1)
3927 || (n2bits
!= 0 && n3bits
== 0
3928 && (n2bits
== sizeof (long) * HOST_CHAR_BIT
)
3935 if (got_signed
|| got_unsigned
)
3937 return init_type (TYPE_CODE_INT
, nbits
/ TARGET_CHAR_BIT
,
3938 got_unsigned
? TYPE_FLAG_UNSIGNED
: 0, NULL
,
3942 return error_type (pp
, objfile
);
3945 /* A type defined as a subrange of itself, with bounds both 0, is void. */
3946 if (self_subrange
&& n2
== 0 && n3
== 0)
3947 return init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
3949 /* If n3 is zero and n2 is positive, we want a floating type,
3950 and n2 is the width in bytes.
3952 Fortran programs appear to use this for complex types also,
3953 and they give no way to distinguish between double and single-complex!
3955 GDB does not have complex types.
3957 Just return the complex as a float of that size. It won't work right
3958 for the complex values, but at least it makes the file loadable. */
3960 if (n3
== 0 && n2
> 0)
3962 return init_type (TYPE_CODE_FLT
, n2
, 0, NULL
, objfile
);
3965 /* If the upper bound is -1, it must really be an unsigned int. */
3967 else if (n2
== 0 && n3
== -1)
3969 /* It is unsigned int or unsigned long. */
3970 /* GCC 2.3.3 uses this for long long too, but that is just a GDB 3.5
3971 compatibility hack. */
3972 return init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
3973 TYPE_FLAG_UNSIGNED
, NULL
, objfile
);
3976 /* Special case: char is defined (Who knows why) as a subrange of
3977 itself with range 0-127. */
3978 else if (self_subrange
&& n2
== 0 && n3
== 127)
3979 return init_type (TYPE_CODE_INT
, 1, 0, NULL
, objfile
);
3981 else if (current_symbol
&& SYMBOL_LANGUAGE (current_symbol
) == language_chill
3983 goto handle_true_range
;
3985 /* We used to do this only for subrange of self or subrange of int. */
3989 /* n3 actually gives the size. */
3990 return init_type (TYPE_CODE_INT
, - n3
, TYPE_FLAG_UNSIGNED
,
3993 return init_type (TYPE_CODE_INT
, 1, TYPE_FLAG_UNSIGNED
, NULL
, objfile
);
3995 return init_type (TYPE_CODE_INT
, 2, TYPE_FLAG_UNSIGNED
, NULL
, objfile
);
3997 /* -1 is used for the upper bound of (4 byte) "unsigned int" and
3998 "unsigned long", and we already checked for that,
3999 so don't need to test for it here. */
4001 /* I think this is for Convex "long long". Since I don't know whether
4002 Convex sets self_subrange, I also accept that particular size regardless
4003 of self_subrange. */
4004 else if (n3
== 0 && n2
< 0
4006 || n2
== - TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
))
4007 return init_type (TYPE_CODE_INT
, - n2
, 0, NULL
, objfile
);
4008 else if (n2
== -n3
-1)
4011 return init_type (TYPE_CODE_INT
, 1, 0, NULL
, objfile
);
4013 return init_type (TYPE_CODE_INT
, 2, 0, NULL
, objfile
);
4014 if (n3
== 0x7fffffff)
4015 return init_type (TYPE_CODE_INT
, 4, 0, NULL
, objfile
);
4018 /* We have a real range type on our hands. Allocate space and
4019 return a real pointer. */
4023 index_type
= builtin_type_int
;
4025 index_type
= *dbx_lookup_type (rangenums
);
4026 if (index_type
== NULL
)
4028 /* Does this actually ever happen? Is that why we are worrying
4029 about dealing with it rather than just calling error_type? */
4031 static struct type
*range_type_index
;
4033 complain (&range_type_base_complaint
, rangenums
[1]);
4034 if (range_type_index
== NULL
)
4036 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
4037 0, "range type index type", NULL
);
4038 index_type
= range_type_index
;
4041 result_type
= create_range_type ((struct type
*) NULL
, index_type
, n2
, n3
);
4042 return (result_type
);
4045 /* Read in an argument list. This is a list of types, separated by commas
4046 and terminated with END. Return the list of types read in, or (struct type
4047 **)-1 if there is an error. */
4049 static struct type
**
4050 read_args (pp
, end
, objfile
)
4053 struct objfile
*objfile
;
4055 /* FIXME! Remove this arbitrary limit! */
4056 struct type
*types
[1024], **rval
; /* allow for fns of 1023 parameters */
4062 /* Invalid argument list: no ','. */
4063 return (struct type
**)-1;
4065 STABS_CONTINUE (pp
, objfile
);
4066 types
[n
++] = read_type (pp
, objfile
);
4068 (*pp
)++; /* get past `end' (the ':' character) */
4072 rval
= (struct type
**) xmalloc (2 * sizeof (struct type
*));
4074 else if (TYPE_CODE (types
[n
-1]) != TYPE_CODE_VOID
)
4076 rval
= (struct type
**) xmalloc ((n
+ 1) * sizeof (struct type
*));
4077 memset (rval
+ n
, 0, sizeof (struct type
*));
4081 rval
= (struct type
**) xmalloc (n
* sizeof (struct type
*));
4083 memcpy (rval
, types
, n
* sizeof (struct type
*));
4087 /* Common block handling. */
4089 /* List of symbols declared since the last BCOMM. This list is a tail
4090 of local_symbols. When ECOMM is seen, the symbols on the list
4091 are noted so their proper addresses can be filled in later,
4092 using the common block base address gotten from the assembler
4095 static struct pending
*common_block
;
4096 static int common_block_i
;
4098 /* Name of the current common block. We get it from the BCOMM instead of the
4099 ECOMM to match IBM documentation (even though IBM puts the name both places
4100 like everyone else). */
4101 static char *common_block_name
;
4103 /* Process a N_BCOMM symbol. The storage for NAME is not guaranteed
4104 to remain after this function returns. */
4107 common_block_start (name
, objfile
)
4109 struct objfile
*objfile
;
4111 if (common_block_name
!= NULL
)
4113 static struct complaint msg
= {
4114 "Invalid symbol data: common block within common block",
4118 common_block
= local_symbols
;
4119 common_block_i
= local_symbols
? local_symbols
->nsyms
: 0;
4120 common_block_name
= obsavestring (name
, strlen (name
),
4121 &objfile
-> symbol_obstack
);
4124 /* Process a N_ECOMM symbol. */
4127 common_block_end (objfile
)
4128 struct objfile
*objfile
;
4130 /* Symbols declared since the BCOMM are to have the common block
4131 start address added in when we know it. common_block and
4132 common_block_i point to the first symbol after the BCOMM in
4133 the local_symbols list; copy the list and hang it off the
4134 symbol for the common block name for later fixup. */
4137 struct pending
*new = 0;
4138 struct pending
*next
;
4141 if (common_block_name
== NULL
)
4143 static struct complaint msg
= {"ECOMM symbol unmatched by BCOMM", 0, 0};
4148 sym
= (struct symbol
*)
4149 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
4150 memset (sym
, 0, sizeof (struct symbol
));
4151 SYMBOL_NAME (sym
) = common_block_name
;
4152 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
4154 /* Now we copy all the symbols which have been defined since the BCOMM. */
4156 /* Copy all the struct pendings before common_block. */
4157 for (next
= local_symbols
;
4158 next
!= NULL
&& next
!= common_block
;
4161 for (j
= 0; j
< next
->nsyms
; j
++)
4162 add_symbol_to_list (next
->symbol
[j
], &new);
4165 /* Copy however much of COMMON_BLOCK we need. If COMMON_BLOCK is
4166 NULL, it means copy all the local symbols (which we already did
4169 if (common_block
!= NULL
)
4170 for (j
= common_block_i
; j
< common_block
->nsyms
; j
++)
4171 add_symbol_to_list (common_block
->symbol
[j
], &new);
4173 SYMBOL_TYPE (sym
) = (struct type
*) new;
4175 /* Should we be putting local_symbols back to what it was?
4178 i
= hashname (SYMBOL_NAME (sym
));
4179 SYMBOL_VALUE_CHAIN (sym
) = global_sym_chain
[i
];
4180 global_sym_chain
[i
] = sym
;
4181 common_block_name
= NULL
;
4184 /* Add a common block's start address to the offset of each symbol
4185 declared to be in it (by being between a BCOMM/ECOMM pair that uses
4186 the common block name). */
4189 fix_common_block (sym
, valu
)
4193 struct pending
*next
= (struct pending
*) SYMBOL_TYPE (sym
);
4194 for ( ; next
; next
= next
->next
)
4197 for (j
= next
->nsyms
- 1; j
>= 0; j
--)
4198 SYMBOL_VALUE_ADDRESS (next
->symbol
[j
]) += valu
;
4204 /* What about types defined as forward references inside of a small lexical
4206 /* Add a type to the list of undefined types to be checked through
4207 once this file has been read in. */
4210 add_undefined_type (type
)
4213 if (undef_types_length
== undef_types_allocated
)
4215 undef_types_allocated
*= 2;
4216 undef_types
= (struct type
**)
4217 xrealloc ((char *) undef_types
,
4218 undef_types_allocated
* sizeof (struct type
*));
4220 undef_types
[undef_types_length
++] = type
;
4223 /* Go through each undefined type, see if it's still undefined, and fix it
4224 up if possible. We have two kinds of undefined types:
4226 TYPE_CODE_ARRAY: Array whose target type wasn't defined yet.
4227 Fix: update array length using the element bounds
4228 and the target type's length.
4229 TYPE_CODE_STRUCT, TYPE_CODE_UNION: Structure whose fields were not
4230 yet defined at the time a pointer to it was made.
4231 Fix: Do a full lookup on the struct/union tag. */
4233 cleanup_undefined_types ()
4237 for (type
= undef_types
; type
< undef_types
+ undef_types_length
; type
++)
4239 switch (TYPE_CODE (*type
))
4242 case TYPE_CODE_STRUCT
:
4243 case TYPE_CODE_UNION
:
4244 case TYPE_CODE_ENUM
:
4246 /* Check if it has been defined since. Need to do this here
4247 as well as in check_typedef to deal with the (legitimate in
4248 C though not C++) case of several types with the same name
4249 in different source files. */
4250 if (TYPE_FLAGS (*type
) & TYPE_FLAG_STUB
)
4252 struct pending
*ppt
;
4254 /* Name of the type, without "struct" or "union" */
4255 char *typename
= TYPE_TAG_NAME (*type
);
4257 if (typename
== NULL
)
4259 static struct complaint msg
= {"need a type name", 0, 0};
4263 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
4265 for (i
= 0; i
< ppt
->nsyms
; i
++)
4267 struct symbol
*sym
= ppt
->symbol
[i
];
4269 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
4270 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
4271 && (TYPE_CODE (SYMBOL_TYPE (sym
)) ==
4273 && STREQ (SYMBOL_NAME (sym
), typename
))
4275 memcpy (*type
, SYMBOL_TYPE (sym
),
4276 sizeof (struct type
));
4286 static struct complaint msg
= {"\
4287 GDB internal error. cleanup_undefined_types with bad type %d.", 0, 0};
4288 complain (&msg
, TYPE_CODE (*type
));
4294 undef_types_length
= 0;
4297 /* Scan through all of the global symbols defined in the object file,
4298 assigning values to the debugging symbols that need to be assigned
4299 to. Get these symbols from the minimal symbol table. */
4302 scan_file_globals (objfile
)
4303 struct objfile
*objfile
;
4306 struct minimal_symbol
*msymbol
;
4307 struct symbol
*sym
, *prev
;
4309 /* Avoid expensive loop through all minimal symbols if there are
4310 no unresolved symbols. */
4311 for (hash
= 0; hash
< HASHSIZE
; hash
++)
4313 if (global_sym_chain
[hash
])
4316 if (hash
>= HASHSIZE
)
4319 for (msymbol
= objfile
-> msymbols
;
4320 msymbol
&& SYMBOL_NAME (msymbol
) != NULL
;
4325 /* Skip static symbols. */
4326 switch (MSYMBOL_TYPE (msymbol
))
4338 /* Get the hash index and check all the symbols
4339 under that hash index. */
4341 hash
= hashname (SYMBOL_NAME (msymbol
));
4343 for (sym
= global_sym_chain
[hash
]; sym
;)
4345 if (SYMBOL_NAME (msymbol
)[0] == SYMBOL_NAME (sym
)[0] &&
4346 STREQ(SYMBOL_NAME (msymbol
) + 1, SYMBOL_NAME (sym
) + 1))
4348 /* Splice this symbol out of the hash chain and
4349 assign the value we have to it. */
4352 SYMBOL_VALUE_CHAIN (prev
) = SYMBOL_VALUE_CHAIN (sym
);
4356 global_sym_chain
[hash
] = SYMBOL_VALUE_CHAIN (sym
);
4359 /* Check to see whether we need to fix up a common block. */
4360 /* Note: this code might be executed several times for
4361 the same symbol if there are multiple references. */
4363 if (SYMBOL_CLASS (sym
) == LOC_BLOCK
)
4365 fix_common_block (sym
, SYMBOL_VALUE_ADDRESS (msymbol
));
4369 SYMBOL_VALUE_ADDRESS (sym
) = SYMBOL_VALUE_ADDRESS (msymbol
);
4372 SYMBOL_SECTION (sym
) = SYMBOL_SECTION (msymbol
);
4376 sym
= SYMBOL_VALUE_CHAIN (prev
);
4380 sym
= global_sym_chain
[hash
];
4386 sym
= SYMBOL_VALUE_CHAIN (sym
);
4391 /* Change the storage class of any remaining unresolved globals to
4392 LOC_UNRESOLVED and remove them from the chain. */
4393 for (hash
= 0; hash
< HASHSIZE
; hash
++)
4395 sym
= global_sym_chain
[hash
];
4399 sym
= SYMBOL_VALUE_CHAIN (sym
);
4401 /* Change the symbol address from the misleading chain value
4403 SYMBOL_VALUE_ADDRESS (prev
) = 0;
4405 /* Complain about unresolved common block symbols. */
4406 if (SYMBOL_CLASS (prev
) == LOC_STATIC
)
4407 SYMBOL_CLASS (prev
) = LOC_UNRESOLVED
;
4409 complain (&unresolved_sym_chain_complaint
,
4410 objfile
->name
, SYMBOL_NAME (prev
));
4413 memset (global_sym_chain
, 0, sizeof (global_sym_chain
));
4416 /* Initialize anything that needs initializing when starting to read
4417 a fresh piece of a symbol file, e.g. reading in the stuff corresponding
4425 /* Initialize anything that needs initializing when a completely new
4426 symbol file is specified (not just adding some symbols from another
4427 file, e.g. a shared library). */
4430 stabsread_new_init ()
4432 /* Empty the hash table of global syms looking for values. */
4433 memset (global_sym_chain
, 0, sizeof (global_sym_chain
));
4436 /* Initialize anything that needs initializing at the same time as
4437 start_symtab() is called. */
4441 global_stabs
= NULL
; /* AIX COFF */
4442 /* Leave FILENUM of 0 free for builtin types and this file's types. */
4443 n_this_object_header_files
= 1;
4444 type_vector_length
= 0;
4445 type_vector
= (struct type
**) 0;
4447 /* FIXME: If common_block_name is not already NULL, we should complain(). */
4448 common_block_name
= NULL
;
4453 /* Call after end_symtab() */
4459 free ((char *) type_vector
);
4462 type_vector_length
= 0;
4463 previous_stab_code
= 0;
4467 finish_global_stabs (objfile
)
4468 struct objfile
*objfile
;
4472 patch_block_stabs (global_symbols
, global_stabs
, objfile
);
4473 free ((PTR
) global_stabs
);
4474 global_stabs
= NULL
;
4478 /* Initializer for this module */
4481 _initialize_stabsread ()
4483 undef_types_allocated
= 20;
4484 undef_types_length
= 0;
4485 undef_types
= (struct type
**)
4486 xmalloc (undef_types_allocated
* sizeof (struct type
*));