1 /* Support routines for decoding "stabs" debugging information format.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
3 1996, 1997, 1998, 1999, 2000, 2001, 2002
4 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
23 /* Support routines for reading and decoding debugging information in
24 the "stabs" format. This format is used with many systems that use
25 the a.out object file format, as well as some systems that use
26 COFF or ELF where the stabs data is placed in a special section.
27 Avoid placing any object file format specific code in this file. */
30 #include "gdb_string.h"
35 #include "expression.h"
38 #include "aout/stab_gnu.h" /* We always use GNU stabs, not native */
40 #include "aout/aout64.h"
41 #include "gdb-stabs.h"
43 #include "complaints.h"
50 /* Ask stabsread.h to define the vars it normally declares `extern'. */
53 #include "stabsread.h" /* Our own declarations */
56 extern void _initialize_stabsread (void);
58 /* The routines that read and process a complete stabs for a C struct or
59 C++ class pass lists of data member fields and lists of member function
60 fields in an instance of a field_info structure, as defined below.
61 This is part of some reorganization of low level C++ support and is
62 expected to eventually go away... (FIXME) */
68 struct nextfield
*next
;
70 /* This is the raw visibility from the stab. It is not checked
71 for being one of the visibilities we recognize, so code which
72 examines this field better be able to deal. */
78 struct next_fnfieldlist
80 struct next_fnfieldlist
*next
;
81 struct fn_fieldlist fn_fieldlist
;
87 read_one_struct_field (struct field_info
*, char **, char *,
88 struct type
*, struct objfile
*);
90 static char *get_substring (char **, int);
92 static struct type
*dbx_alloc_type (int[2], struct objfile
*);
94 static long read_huge_number (char **, int, int *);
96 static struct type
*error_type (char **, struct objfile
*);
99 patch_block_stabs (struct pending
*, struct pending_stabs
*,
102 static void fix_common_block (struct symbol
*, int);
104 static int read_type_number (char **, int *);
106 static struct type
*read_range_type (char **, int[2], struct objfile
*);
108 static struct type
*read_sun_builtin_type (char **, int[2], struct objfile
*);
110 static struct type
*read_sun_floating_type (char **, int[2],
113 static struct type
*read_enum_type (char **, struct type
*, struct objfile
*);
115 static struct type
*rs6000_builtin_type (int);
118 read_member_functions (struct field_info
*, char **, struct type
*,
122 read_struct_fields (struct field_info
*, char **, struct type
*,
126 read_baseclasses (struct field_info
*, char **, struct type
*,
130 read_tilde_fields (struct field_info
*, char **, struct type
*,
133 static int attach_fn_fields_to_type (struct field_info
*, struct type
*);
136 attach_fields_to_type (struct field_info
*, struct type
*, struct objfile
*);
138 static struct type
*read_struct_type (char **, struct type
*,
141 static struct type
*read_array_type (char **, struct type
*,
144 static struct type
**read_args (char **, int, struct objfile
*);
147 read_cpp_abbrev (struct field_info
*, char **, struct type
*,
150 /* new functions added for cfront support */
153 copy_cfront_struct_fields (struct field_info
*, struct type
*,
156 static char *get_cfront_method_physname (char *);
159 read_cfront_baseclasses (struct field_info
*, char **,
160 struct type
*, struct objfile
*);
163 read_cfront_static_fields (struct field_info
*, char **,
164 struct type
*, struct objfile
*);
166 read_cfront_member_functions (struct field_info
*, char **,
167 struct type
*, struct objfile
*);
169 /* end new functions added for cfront support */
172 add_live_range (struct objfile
*, struct symbol
*, CORE_ADDR
, CORE_ADDR
);
174 static int resolve_live_range (struct objfile
*, struct symbol
*, char *);
176 static int process_reference (char **string
);
178 static CORE_ADDR
ref_search_value (int refnum
);
181 resolve_symbol_reference (struct objfile
*, struct symbol
*, char *);
183 void stabsread_clear_cache (void);
185 static const char vptr_name
[] =
186 {'_', 'v', 'p', 't', 'r', CPLUS_MARKER
, '\0'};
187 static const char vb_name
[] =
188 {'_', 'v', 'b', CPLUS_MARKER
, '\0'};
190 /* Define this as 1 if a pcc declaration of a char or short argument
191 gives the correct address. Otherwise assume pcc gives the
192 address of the corresponding int, which is not the same on a
193 big-endian machine. */
195 #if !defined (BELIEVE_PCC_PROMOTION)
196 #define BELIEVE_PCC_PROMOTION 0
198 #if !defined (BELIEVE_PCC_PROMOTION_TYPE)
199 #define BELIEVE_PCC_PROMOTION_TYPE 0
202 static struct complaint invalid_cpp_abbrev_complaint
=
203 {"invalid C++ abbreviation `%s'", 0, 0};
205 static struct complaint invalid_cpp_type_complaint
=
206 {"C++ abbreviated type name unknown at symtab pos %d", 0, 0};
208 static struct complaint member_fn_complaint
=
209 {"member function type missing, got '%c'", 0, 0};
211 static struct complaint const_vol_complaint
=
212 {"const/volatile indicator missing, got '%c'", 0, 0};
214 static struct complaint error_type_complaint
=
215 {"debug info mismatch between compiler and debugger", 0, 0};
217 static struct complaint invalid_member_complaint
=
218 {"invalid (minimal) member type data format at symtab pos %d.", 0, 0};
220 static struct complaint range_type_base_complaint
=
221 {"base type %d of range type is not defined", 0, 0};
223 static struct complaint reg_value_complaint
=
224 {"register number %d too large (max %d) in symbol %s", 0, 0};
226 static struct complaint vtbl_notfound_complaint
=
227 {"virtual function table pointer not found when defining class `%s'", 0, 0};
229 static struct complaint unrecognized_cplus_name_complaint
=
230 {"Unknown C++ symbol name `%s'", 0, 0};
232 static struct complaint rs6000_builtin_complaint
=
233 {"Unknown builtin type %d", 0, 0};
235 static struct complaint unresolved_sym_chain_complaint
=
236 {"%s: common block `%s' from global_sym_chain unresolved", 0, 0};
238 static struct complaint stabs_general_complaint
=
241 static struct complaint lrs_general_complaint
=
244 /* Make a list of forward references which haven't been defined. */
246 static struct type
**undef_types
;
247 static int undef_types_allocated
;
248 static int undef_types_length
;
249 static struct symbol
*current_symbol
= NULL
;
251 /* Check for and handle cretinous stabs symbol name continuation! */
252 #define STABS_CONTINUE(pp,objfile) \
254 if (**(pp) == '\\' || (**(pp) == '?' && (*(pp))[1] == '\0')) \
255 *(pp) = next_symbol_text (objfile); \
258 /* FIXME: These probably should be our own types (like rs6000_builtin_type
259 has its own types) rather than builtin_type_*. */
260 static struct type
**os9k_type_vector
[] =
267 &builtin_type_unsigned_char
,
268 &builtin_type_unsigned_short
,
269 &builtin_type_unsigned_long
,
270 &builtin_type_unsigned_int
,
272 &builtin_type_double
,
274 &builtin_type_long_double
277 static void os9k_init_type_vector (struct type
**);
280 os9k_init_type_vector (struct type
**tv
)
283 for (i
= 0; i
< sizeof (os9k_type_vector
) / sizeof (struct type
**); i
++)
284 tv
[i
] = (os9k_type_vector
[i
] == 0 ? 0 : *(os9k_type_vector
[i
]));
287 /* Look up a dbx type-number pair. Return the address of the slot
288 where the type for that number-pair is stored.
289 The number-pair is in TYPENUMS.
291 This can be used for finding the type associated with that pair
292 or for associating a new type with the pair. */
295 dbx_lookup_type (int typenums
[2])
297 register int filenum
= typenums
[0];
298 register int index
= typenums
[1];
300 register int real_filenum
;
301 register struct header_file
*f
;
304 if (filenum
== -1) /* -1,-1 is for temporary types. */
307 if (filenum
< 0 || filenum
>= n_this_object_header_files
)
309 static struct complaint msg
=
311 Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.",
313 complain (&msg
, filenum
, index
, symnum
);
321 /* Caller wants address of address of type. We think
322 that negative (rs6k builtin) types will never appear as
323 "lvalues", (nor should they), so we stuff the real type
324 pointer into a temp, and return its address. If referenced,
325 this will do the right thing. */
326 static struct type
*temp_type
;
328 temp_type
= rs6000_builtin_type (index
);
332 /* Type is defined outside of header files.
333 Find it in this object file's type vector. */
334 if (index
>= type_vector_length
)
336 old_len
= type_vector_length
;
339 type_vector_length
= INITIAL_TYPE_VECTOR_LENGTH
;
340 type_vector
= (struct type
**)
341 xmalloc (type_vector_length
* sizeof (struct type
*));
343 while (index
>= type_vector_length
)
345 type_vector_length
*= 2;
347 type_vector
= (struct type
**)
348 xrealloc ((char *) type_vector
,
349 (type_vector_length
* sizeof (struct type
*)));
350 memset (&type_vector
[old_len
], 0,
351 (type_vector_length
- old_len
) * sizeof (struct type
*));
354 /* Deal with OS9000 fundamental types. */
355 os9k_init_type_vector (type_vector
);
357 return (&type_vector
[index
]);
361 real_filenum
= this_object_header_files
[filenum
];
363 if (real_filenum
>= N_HEADER_FILES (current_objfile
))
365 struct type
*temp_type
;
366 struct type
**temp_type_p
;
368 warning ("GDB internal error: bad real_filenum");
371 temp_type
= init_type (TYPE_CODE_ERROR
, 0, 0, NULL
, NULL
);
372 temp_type_p
= (struct type
**) xmalloc (sizeof (struct type
*));
373 *temp_type_p
= temp_type
;
377 f
= HEADER_FILES (current_objfile
) + real_filenum
;
379 f_orig_length
= f
->length
;
380 if (index
>= f_orig_length
)
382 while (index
>= f
->length
)
386 f
->vector
= (struct type
**)
387 xrealloc ((char *) f
->vector
, f
->length
* sizeof (struct type
*));
388 memset (&f
->vector
[f_orig_length
], 0,
389 (f
->length
- f_orig_length
) * sizeof (struct type
*));
391 return (&f
->vector
[index
]);
395 /* Make sure there is a type allocated for type numbers TYPENUMS
396 and return the type object.
397 This can create an empty (zeroed) type object.
398 TYPENUMS may be (-1, -1) to return a new type object that is not
399 put into the type vector, and so may not be referred to by number. */
402 dbx_alloc_type (int typenums
[2], struct objfile
*objfile
)
404 register struct type
**type_addr
;
406 if (typenums
[0] == -1)
408 return (alloc_type (objfile
));
411 type_addr
= dbx_lookup_type (typenums
);
413 /* If we are referring to a type not known at all yet,
414 allocate an empty type for it.
415 We will fill it in later if we find out how. */
418 *type_addr
= alloc_type (objfile
);
424 /* for all the stabs in a given stab vector, build appropriate types
425 and fix their symbols in given symbol vector. */
428 patch_block_stabs (struct pending
*symbols
, struct pending_stabs
*stabs
,
429 struct objfile
*objfile
)
439 /* for all the stab entries, find their corresponding symbols and
440 patch their types! */
442 for (ii
= 0; ii
< stabs
->count
; ++ii
)
444 name
= stabs
->stab
[ii
];
445 pp
= (char *) strchr (name
, ':');
449 pp
= (char *) strchr (pp
, ':');
451 sym
= find_symbol_in_list (symbols
, name
, pp
- name
);
454 /* FIXME-maybe: it would be nice if we noticed whether
455 the variable was defined *anywhere*, not just whether
456 it is defined in this compilation unit. But neither
457 xlc or GCC seem to need such a definition, and until
458 we do psymtabs (so that the minimal symbols from all
459 compilation units are available now), I'm not sure
460 how to get the information. */
462 /* On xcoff, if a global is defined and never referenced,
463 ld will remove it from the executable. There is then
464 a N_GSYM stab for it, but no regular (C_EXT) symbol. */
465 sym
= (struct symbol
*)
466 obstack_alloc (&objfile
->symbol_obstack
,
467 sizeof (struct symbol
));
469 memset (sym
, 0, sizeof (struct symbol
));
470 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
471 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
473 obsavestring (name
, pp
- name
, &objfile
->symbol_obstack
);
475 if (*(pp
- 1) == 'F' || *(pp
- 1) == 'f')
477 /* I don't think the linker does this with functions,
478 so as far as I know this is never executed.
479 But it doesn't hurt to check. */
481 lookup_function_type (read_type (&pp
, objfile
));
485 SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
487 add_symbol_to_list (sym
, &global_symbols
);
492 if (*(pp
- 1) == 'F' || *(pp
- 1) == 'f')
495 lookup_function_type (read_type (&pp
, objfile
));
499 SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
507 /* Read a number by which a type is referred to in dbx data,
508 or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
509 Just a single number N is equivalent to (0,N).
510 Return the two numbers by storing them in the vector TYPENUMS.
511 TYPENUMS will then be used as an argument to dbx_lookup_type.
513 Returns 0 for success, -1 for error. */
516 read_type_number (register char **pp
, register int *typenums
)
522 typenums
[0] = read_huge_number (pp
, ',', &nbits
);
525 typenums
[1] = read_huge_number (pp
, ')', &nbits
);
532 typenums
[1] = read_huge_number (pp
, 0, &nbits
);
540 #define VISIBILITY_PRIVATE '0' /* Stabs character for private field */
541 #define VISIBILITY_PROTECTED '1' /* Stabs character for protected fld */
542 #define VISIBILITY_PUBLIC '2' /* Stabs character for public field */
543 #define VISIBILITY_IGNORE '9' /* Optimized out or zero length */
545 #define CFRONT_VISIBILITY_PRIVATE '2' /* Stabs character for private field */
546 #define CFRONT_VISIBILITY_PUBLIC '1' /* Stabs character for public field */
548 /* This code added to support parsing of ARM/Cfront stabs strings */
550 /* Get substring from string up to char c, advance string pointer past
554 get_substring (char **p
, int c
)
569 /* Physname gets strcat'd onto sname in order to recreate the mangled
570 name (see funtion gdb_mangle_name in gdbtypes.c). For cfront, make
571 the physname look like that of g++ - take out the initial mangling
572 eg: for sname="a" and fname="foo__1aFPFs_i" return "FPFs_i" */
575 get_cfront_method_physname (char *fname
)
578 /* FIXME would like to make this generic for g++ too, but
579 that is already handled in read_member_funcctions */
582 /* search ahead to find the start of the mangled suffix */
583 if (*p
== '_' && *(p
+ 1) == '_') /* compiler generated; probably a ctor/dtor */
585 while (p
&& (unsigned) ((p
+ 1) - fname
) < strlen (fname
) && *(p
+ 1) != '_')
587 if (!(p
&& *p
== '_' && *(p
+ 1) == '_'))
588 error ("Invalid mangled function name %s", fname
);
589 p
+= 2; /* advance past '__' */
591 /* struct name length and name of type should come next; advance past it */
594 len
= len
* 10 + (*p
- '0');
602 /* Read base classes within cfront class definition.
603 eg: A:ZcA;1@Bpub v2@Bvirpri;__ct__1AFv func__1AFv *sfunc__1AFv ;as__1A ;;
606 A:ZcA;;foopri__1AFv foopro__1AFv __ct__1AFv __ct__1AFRC1A foopub__1AFv ;;;
611 read_cfront_baseclasses (struct field_info
*fip
, char **pp
, struct type
*type
,
612 struct objfile
*objfile
)
614 static struct complaint msg_unknown
=
616 Unsupported token in stabs string %s.\n",
618 static struct complaint msg_notfound
=
620 Unable to find base type for %s.\n",
625 struct nextfield
*new;
627 if (**pp
== ';') /* no base classes; return */
633 /* first count base classes so we can allocate space before parsing */
634 for (p
= *pp
; p
&& *p
&& *p
!= ';'; p
++)
639 bnum
++; /* add one more for last one */
641 /* now parse the base classes until we get to the start of the methods
642 (code extracted and munged from read_baseclasses) */
643 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
644 TYPE_N_BASECLASSES (type
) = bnum
;
648 int num_bytes
= B_BYTES (TYPE_N_BASECLASSES (type
));
651 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
652 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
654 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), TYPE_N_BASECLASSES (type
));
656 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
658 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
659 make_cleanup (xfree
, new);
660 memset (new, 0, sizeof (struct nextfield
));
661 new->next
= fip
->list
;
663 FIELD_BITSIZE (new->field
) = 0; /* this should be an unpacked field! */
665 STABS_CONTINUE (pp
, objfile
);
667 /* virtual? eg: v2@Bvir */
670 SET_TYPE_FIELD_VIRTUAL (type
, i
);
674 /* access? eg: 2@Bvir */
675 /* Note: protected inheritance not supported in cfront */
678 case CFRONT_VISIBILITY_PRIVATE
:
679 new->visibility
= VISIBILITY_PRIVATE
;
681 case CFRONT_VISIBILITY_PUBLIC
:
682 new->visibility
= VISIBILITY_PUBLIC
;
685 /* Bad visibility format. Complain and treat it as
688 static struct complaint msg
=
690 "Unknown visibility `%c' for baseclass", 0, 0};
691 complain (&msg
, new->visibility
);
692 new->visibility
= VISIBILITY_PUBLIC
;
696 /* "@" comes next - eg: @Bvir */
699 complain (&msg_unknown
, *pp
);
705 /* Set the bit offset of the portion of the object corresponding
706 to this baseclass. Always zero in the absence of
707 multiple inheritance. */
708 /* Unable to read bit position from stabs;
709 Assuming no multiple inheritance for now FIXME! */
710 /* We may have read this in the structure definition;
711 now we should fixup the members to be the actual base classes */
712 FIELD_BITPOS (new->field
) = 0;
714 /* Get the base class name and type */
716 char *bname
; /* base class name */
717 struct symbol
*bsym
; /* base class */
719 p1
= strchr (*pp
, ' ');
720 p2
= strchr (*pp
, ';');
722 bname
= get_substring (pp
, ' ');
724 bname
= get_substring (pp
, ';');
725 if (!bname
|| !*bname
)
727 complain (&msg_unknown
, *pp
);
730 /* FIXME! attach base info to type */
731 bsym
= lookup_symbol (bname
, 0, STRUCT_NAMESPACE
, 0, 0); /*demangled_name */
734 new->field
.type
= SYMBOL_TYPE (bsym
);
735 new->field
.name
= type_name_no_tag (new->field
.type
);
739 complain (&msg_notfound
, *pp
);
744 /* If more base classes to parse, loop again.
745 We ate the last ' ' or ';' in get_substring,
746 so on exit we will have skipped the trailing ';' */
747 /* if invalid, return 0; add code to detect - FIXME! */
752 /* read cfront member functions.
753 pp points to string starting with list of functions
754 eg: A:ZcA;1@Bpub v2@Bvirpri;__ct__1AFv func__1AFv *sfunc__1AFv ;as__1A ;;
755 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
756 A:ZcA;;foopri__1AFv foopro__1AFv __ct__1AFv __ct__1AFRC1A foopub__1AFv ;;;
757 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
761 read_cfront_member_functions (struct field_info
*fip
, char **pp
,
762 struct type
*type
, struct objfile
*objfile
)
764 /* This code extracted from read_member_functions
765 so as to do the similar thing for our funcs */
769 /* Total number of member functions defined in this class. If the class
770 defines two `f' functions, and one `g' function, then this will have
772 int total_length
= 0;
776 struct next_fnfield
*next
;
777 struct fn_field fn_field
;
780 struct type
*look_ahead_type
;
781 struct next_fnfieldlist
*new_fnlist
;
782 struct next_fnfield
*new_sublist
;
785 struct symbol
*ref_func
= 0;
787 /* Process each list until we find the end of the member functions.
788 eg: p = "__ct__1AFv foo__1AFv ;;;" */
790 STABS_CONTINUE (pp
, objfile
); /* handle \\ */
792 while (**pp
!= ';' && (fname
= get_substring (pp
, ' '), fname
))
795 int sublist_count
= 0;
797 if (fname
[0] == '*') /* static member */
803 ref_func
= lookup_symbol (fname
, 0, VAR_NAMESPACE
, 0, 0); /* demangled name */
806 static struct complaint msg
=
808 Unable to find function symbol for %s\n",
810 complain (&msg
, fname
);
814 look_ahead_type
= NULL
;
817 new_fnlist
= (struct next_fnfieldlist
*)
818 xmalloc (sizeof (struct next_fnfieldlist
));
819 make_cleanup (xfree
, new_fnlist
);
820 memset (new_fnlist
, 0, sizeof (struct next_fnfieldlist
));
822 /* The following is code to work around cfront generated stabs.
823 The stabs contains full mangled name for each field.
824 We try to demangle the name and extract the field name out of it. */
826 char *dem
, *dem_p
, *dem_args
;
828 dem
= cplus_demangle (fname
, DMGL_ANSI
| DMGL_PARAMS
);
831 dem_p
= strrchr (dem
, ':');
832 if (dem_p
!= 0 && *(dem_p
- 1) == ':')
834 /* get rid of args */
835 dem_args
= strchr (dem_p
, '(');
836 if (dem_args
== NULL
)
837 dem_len
= strlen (dem_p
);
839 dem_len
= dem_args
- dem_p
;
841 obsavestring (dem_p
, dem_len
, &objfile
->type_obstack
);
846 obsavestring (fname
, strlen (fname
), &objfile
->type_obstack
);
848 } /* end of code for cfront work around */
850 new_fnlist
->fn_fieldlist
.name
= main_fn_name
;
852 /*-------------------------------------------------*/
853 /* Set up the sublists
854 Sublists are stuff like args, static, visibility, etc.
855 so in ARM, we have to set that info some other way.
856 Multiple sublists happen if overloading
857 eg: foo::26=##1;:;2A.;
858 In g++, we'd loop here thru all the sublists... */
861 (struct next_fnfield
*) xmalloc (sizeof (struct next_fnfield
));
862 make_cleanup (xfree
, new_sublist
);
863 memset (new_sublist
, 0, sizeof (struct next_fnfield
));
865 /* eat 1; from :;2A.; */
866 new_sublist
->fn_field
.type
= SYMBOL_TYPE (ref_func
); /* normally takes a read_type */
867 /* Make this type look like a method stub for gdb */
868 TYPE_FLAGS (new_sublist
->fn_field
.type
) |= TYPE_FLAG_STUB
;
869 TYPE_CODE (new_sublist
->fn_field
.type
) = TYPE_CODE_METHOD
;
871 /* If this is just a stub, then we don't have the real name here. */
872 if (TYPE_STUB (new_sublist
->fn_field
.type
))
874 if (!TYPE_DOMAIN_TYPE (new_sublist
->fn_field
.type
))
875 TYPE_DOMAIN_TYPE (new_sublist
->fn_field
.type
) = type
;
876 new_sublist
->fn_field
.is_stub
= 1;
879 /* physname used later in mangling; eg PFs_i,5 for foo__1aFPFs_i
880 physname gets strcat'd in order to recreate the onto mangled name */
881 pname
= get_cfront_method_physname (fname
);
882 new_sublist
->fn_field
.physname
= savestring (pname
, strlen (pname
));
885 /* Set this member function's visibility fields.
886 Unable to distinguish access from stabs definition!
887 Assuming public for now. FIXME!
888 (for private, set new_sublist->fn_field.is_private = 1,
889 for public, set new_sublist->fn_field.is_protected = 1) */
891 /* Unable to distinguish const/volatile from stabs definition!
892 Assuming normal for now. FIXME! */
894 new_sublist
->fn_field
.is_const
= 0;
895 new_sublist
->fn_field
.is_volatile
= 0; /* volatile not implemented in cfront */
897 /* Set virtual/static function info
898 How to get vtable offsets ?
899 Assuming normal for now FIXME!!
900 For vtables, figure out from whence this virtual function came.
901 It may belong to virtual function table of
902 one of its baseclasses.
904 new_sublist -> fn_field.voffset = vtable offset,
905 new_sublist -> fn_field.fcontext = look_ahead_type;
906 where look_ahead_type is type of baseclass */
908 new_sublist
->fn_field
.voffset
= VOFFSET_STATIC
;
909 else /* normal member function. */
910 new_sublist
->fn_field
.voffset
= 0;
911 new_sublist
->fn_field
.fcontext
= 0;
914 /* Prepare new sublist */
915 new_sublist
->next
= sublist
;
916 sublist
= new_sublist
;
919 /* In g++, we loop thu sublists - now we set from functions. */
920 new_fnlist
->fn_fieldlist
.fn_fields
= (struct fn_field
*)
921 obstack_alloc (&objfile
->type_obstack
,
922 sizeof (struct fn_field
) * length
);
923 memset (new_fnlist
->fn_fieldlist
.fn_fields
, 0,
924 sizeof (struct fn_field
) * length
);
925 for (i
= length
; (i
--, sublist
); sublist
= sublist
->next
)
927 new_fnlist
->fn_fieldlist
.fn_fields
[i
] = sublist
->fn_field
;
930 new_fnlist
->fn_fieldlist
.length
= length
;
931 new_fnlist
->next
= fip
->fnlist
;
932 fip
->fnlist
= new_fnlist
;
934 total_length
+= length
;
935 STABS_CONTINUE (pp
, objfile
); /* handle \\ */
940 /* type should already have space */
941 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
942 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * nfn_fields
);
943 memset (TYPE_FN_FIELDLISTS (type
), 0,
944 sizeof (struct fn_fieldlist
) * nfn_fields
);
945 TYPE_NFN_FIELDS (type
) = nfn_fields
;
946 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
949 /* end of scope for reading member func */
953 /* Skip trailing ';' and bump count of number of fields seen */
961 /* This routine fixes up partial cfront types that were created
962 while parsing the stabs. The main need for this function is
963 to add information such as methods to classes.
964 Examples of "p": "sA;;__ct__1AFv foo__1AFv ;;;" */
966 resolve_cfront_continuation (struct objfile
*objfile
, struct symbol
*sym
,
969 struct symbol
*ref_sym
= 0;
971 /* snarfed from read_struct_type */
972 struct field_info fi
;
974 struct cleanup
*back_to
;
976 /* Need to make sure that fi isn't gunna conflict with struct
977 in case struct already had some fnfs */
980 back_to
= make_cleanup (null_cleanup
, 0);
982 /* We only accept structs, classes and unions at the moment.
983 Other continuation types include t (typedef), r (long dbl), ...
984 We may want to add support for them as well;
985 right now they are handled by duplicating the symbol information
986 into the type information (see define_symbol) */
987 if (*p
!= 's' /* structs */
988 && *p
!= 'c' /* class */
989 && *p
!= 'u') /* union */
990 return 0; /* only handle C++ types */
993 /* Get symbol typs name and validate
994 eg: p = "A;;__ct__1AFv foo__1AFv ;;;" */
995 sname
= get_substring (&p
, ';');
996 if (!sname
|| strcmp (sname
, SYMBOL_NAME (sym
)))
997 error ("Internal error: base symbol type name does not match\n");
999 /* Find symbol's internal gdb reference using demangled_name.
1000 This is the real sym that we want;
1001 sym was a temp hack to make debugger happy */
1002 ref_sym
= lookup_symbol (SYMBOL_NAME (sym
), 0, STRUCT_NAMESPACE
, 0, 0);
1003 type
= SYMBOL_TYPE (ref_sym
);
1006 /* Now read the baseclasses, if any, read the regular C struct or C++
1007 class member fields, attach the fields to the type, read the C++
1008 member functions, attach them to the type, and then read any tilde
1009 field (baseclass specifier for the class holding the main vtable). */
1011 if (!read_cfront_baseclasses (&fi
, &p
, type
, objfile
)
1012 /* g++ does this next, but cfront already did this:
1013 || !read_struct_fields (&fi, &p, type, objfile) */
1014 || !copy_cfront_struct_fields (&fi
, type
, objfile
)
1015 || !read_cfront_member_functions (&fi
, &p
, type
, objfile
)
1016 || !read_cfront_static_fields (&fi
, &p
, type
, objfile
)
1017 || !attach_fields_to_type (&fi
, type
, objfile
)
1018 || !attach_fn_fields_to_type (&fi
, type
)
1019 /* g++ does this next, but cfront doesn't seem to have this:
1020 || !read_tilde_fields (&fi, &p, type, objfile) */
1023 type
= error_type (&p
, objfile
);
1026 do_cleanups (back_to
);
1029 /* End of code added to support parsing of ARM/Cfront stabs strings */
1032 /* This routine fixes up symbol references/aliases to point to the original
1033 symbol definition. Returns 0 on failure, non-zero on success. */
1036 resolve_symbol_reference (struct objfile
*objfile
, struct symbol
*sym
, char *p
)
1039 struct symbol
*ref_sym
= 0;
1040 struct alias_list
*alias
;
1042 /* If this is not a symbol reference return now. */
1046 /* Use "#<num>" as the name; we'll fix the name later.
1047 We stored the original symbol name as "#<id>=<name>"
1048 so we can now search for "#<id>" to resolving the reference.
1049 We'll fix the names later by removing the "#<id>" or "#<id>=" */
1051 /*---------------------------------------------------------*/
1052 /* Get the reference id number, and
1053 advance p past the names so we can parse the rest.
1054 eg: id=2 for p : "2=", "2=z:r(0,1)" "2:r(0,1);l(#5,#6),l(#7,#4)" */
1055 /*---------------------------------------------------------*/
1057 /* This gets reference name from string. sym may not have a name. */
1059 /* Get the reference number associated with the reference id in the
1060 gdb stab string. From that reference number, get the main/primary
1061 symbol for this alias. */
1062 refnum
= process_reference (&p
);
1063 ref_sym
= ref_search (refnum
);
1066 complain (&lrs_general_complaint
, "symbol for reference not found");
1070 /* Parse the stab of the referencing symbol
1071 now that we have the referenced symbol.
1072 Add it as a new symbol and a link back to the referenced symbol.
1073 eg: p : "=", "=z:r(0,1)" ":r(0,1);l(#5,#6),l(#7,#4)" */
1076 /* If the stab symbol table and string contain:
1077 RSYM 0 5 00000000 868 #15=z:r(0,1)
1078 LBRAC 0 0 00000000 899 #5=
1079 SLINE 0 16 00000003 923 #6=
1080 Then the same symbols can be later referenced by:
1081 RSYM 0 5 00000000 927 #15:r(0,1);l(#5,#6)
1082 This is used in live range splitting to:
1083 1) specify that a symbol (#15) is actually just a new storage
1084 class for a symbol (#15=z) which was previously defined.
1085 2) specify that the beginning and ending ranges for a symbol
1086 (#15) are the values of the beginning (#5) and ending (#6)
1089 /* Read number as reference id.
1090 eg: p : "=", "=z:r(0,1)" ":r(0,1);l(#5,#6),l(#7,#4)" */
1091 /* FIXME! Might I want to use SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
1092 in case of "l(0,0)"? */
1094 /*--------------------------------------------------*/
1095 /* Add this symbol to the reference list. */
1096 /*--------------------------------------------------*/
1098 alias
= (struct alias_list
*) obstack_alloc (&objfile
->type_obstack
,
1099 sizeof (struct alias_list
));
1102 complain (&lrs_general_complaint
, "Unable to allocate alias list memory");
1109 if (!SYMBOL_ALIASES (ref_sym
))
1111 SYMBOL_ALIASES (ref_sym
) = alias
;
1115 struct alias_list
*temp
;
1117 /* Get to the end of the list. */
1118 for (temp
= SYMBOL_ALIASES (ref_sym
);
1125 /* Want to fix up name so that other functions (eg. valops)
1126 will correctly print the name.
1127 Don't add_symbol_to_list so that lookup_symbol won't find it.
1128 nope... needed for fixups. */
1129 SYMBOL_NAME (sym
) = SYMBOL_NAME (ref_sym
);
1135 /* Structure for storing pointers to reference definitions for fast lookup
1136 during "process_later". */
1145 #define MAX_CHUNK_REFS 100
1146 #define REF_CHUNK_SIZE (MAX_CHUNK_REFS * sizeof (struct ref_map))
1147 #define REF_MAP_SIZE(ref_chunk) ((ref_chunk) * REF_CHUNK_SIZE)
1149 static struct ref_map
*ref_map
;
1151 /* Ptr to free cell in chunk's linked list. */
1152 static int ref_count
= 0;
1154 /* Number of chunks malloced. */
1155 static int ref_chunk
= 0;
1157 /* This file maintains a cache of stabs aliases found in the symbol
1158 table. If the symbol table changes, this cache must be cleared
1159 or we are left holding onto data in invalid obstacks. */
1161 stabsread_clear_cache (void)
1167 /* Create array of pointers mapping refids to symbols and stab strings.
1168 Add pointers to reference definition symbols and/or their values as we
1169 find them, using their reference numbers as our index.
1170 These will be used later when we resolve references. */
1172 ref_add (int refnum
, struct symbol
*sym
, char *stabs
, CORE_ADDR value
)
1176 if (refnum
>= ref_count
)
1177 ref_count
= refnum
+ 1;
1178 if (ref_count
> ref_chunk
* MAX_CHUNK_REFS
)
1180 int new_slots
= ref_count
- ref_chunk
* MAX_CHUNK_REFS
;
1181 int new_chunks
= new_slots
/ MAX_CHUNK_REFS
+ 1;
1182 ref_map
= (struct ref_map
*)
1183 xrealloc (ref_map
, REF_MAP_SIZE (ref_chunk
+ new_chunks
));
1184 memset (ref_map
+ ref_chunk
* MAX_CHUNK_REFS
, 0, new_chunks
* REF_CHUNK_SIZE
);
1185 ref_chunk
+= new_chunks
;
1187 ref_map
[refnum
].stabs
= stabs
;
1188 ref_map
[refnum
].sym
= sym
;
1189 ref_map
[refnum
].value
= value
;
1192 /* Return defined sym for the reference REFNUM. */
1194 ref_search (int refnum
)
1196 if (refnum
< 0 || refnum
> ref_count
)
1198 return ref_map
[refnum
].sym
;
1201 /* Return value for the reference REFNUM. */
1204 ref_search_value (int refnum
)
1206 if (refnum
< 0 || refnum
> ref_count
)
1208 return ref_map
[refnum
].value
;
1211 /* Parse a reference id in STRING and return the resulting
1212 reference number. Move STRING beyond the reference id. */
1215 process_reference (char **string
)
1220 if (**string
!= '#')
1223 /* Advance beyond the initial '#'. */
1226 /* Read number as reference id. */
1227 while (*p
&& isdigit (*p
))
1229 refnum
= refnum
* 10 + *p
- '0';
1236 /* If STRING defines a reference, store away a pointer to the reference
1237 definition for later use. Return the reference number. */
1240 symbol_reference_defined (char **string
)
1245 refnum
= process_reference (&p
);
1247 /* Defining symbols end in '=' */
1250 /* Symbol is being defined here. */
1256 /* Must be a reference. Either the symbol has already been defined,
1257 or this is a forward reference to it. */
1265 define_symbol (CORE_ADDR valu
, char *string
, int desc
, int type
,
1266 struct objfile
*objfile
)
1268 register struct symbol
*sym
;
1269 char *p
= (char *) strchr (string
, ':');
1274 /* We would like to eliminate nameless symbols, but keep their types.
1275 E.g. stab entry ":t10=*2" should produce a type 10, which is a pointer
1276 to type 2, but, should not create a symbol to address that type. Since
1277 the symbol will be nameless, there is no way any user can refer to it. */
1281 /* Ignore syms with empty names. */
1285 /* Ignore old-style symbols from cc -go */
1292 p
= strchr (p
, ':');
1295 /* If a nameless stab entry, all we need is the type, not the symbol.
1296 e.g. ":t10=*2" or a nameless enum like " :T16=ered:0,green:1,blue:2,;" */
1297 nameless
= (p
== string
|| ((string
[0] == ' ') && (string
[1] == ':')));
1299 current_symbol
= sym
= (struct symbol
*)
1300 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct symbol
));
1301 memset (sym
, 0, sizeof (struct symbol
));
1303 switch (type
& N_TYPE
)
1306 SYMBOL_SECTION (sym
) = SECT_OFF_TEXT (objfile
);
1309 SYMBOL_SECTION (sym
) = SECT_OFF_DATA (objfile
);
1312 SYMBOL_SECTION (sym
) = SECT_OFF_BSS (objfile
);
1316 if (processing_gcc_compilation
)
1318 /* GCC 2.x puts the line number in desc. SunOS apparently puts in the
1319 number of bytes occupied by a type or object, which we ignore. */
1320 SYMBOL_LINE (sym
) = desc
;
1324 SYMBOL_LINE (sym
) = 0; /* unknown */
1327 if (is_cplus_marker (string
[0]))
1329 /* Special GNU C++ names. */
1333 SYMBOL_NAME (sym
) = obsavestring ("this", strlen ("this"),
1334 &objfile
->symbol_obstack
);
1337 case 'v': /* $vtbl_ptr_type */
1338 /* Was: SYMBOL_NAME (sym) = "vptr"; */
1342 SYMBOL_NAME (sym
) = obsavestring ("eh_throw", strlen ("eh_throw"),
1343 &objfile
->symbol_obstack
);
1347 /* This was an anonymous type that was never fixed up. */
1350 #ifdef STATIC_TRANSFORM_NAME
1352 /* SunPRO (3.0 at least) static variable encoding. */
1357 complain (&unrecognized_cplus_name_complaint
, string
);
1358 goto normal
; /* Do *something* with it */
1361 else if (string
[0] == '#')
1363 /* Special GNU C extension for referencing symbols. */
1367 /* If STRING defines a new reference id, then add it to the
1368 reference map. Else it must be referring to a previously
1369 defined symbol, so add it to the alias list of the previously
1372 refnum
= symbol_reference_defined (&s
);
1374 ref_add (refnum
, sym
, string
, SYMBOL_VALUE (sym
));
1375 else if (!resolve_symbol_reference (objfile
, sym
, string
))
1378 /* S..P contains the name of the symbol. We need to store
1379 the correct name into SYMBOL_NAME. */
1385 SYMBOL_NAME (sym
) = (char *)
1386 obstack_alloc (&objfile
->symbol_obstack
, nlen
);
1387 strncpy (SYMBOL_NAME (sym
), s
, nlen
);
1388 SYMBOL_NAME (sym
)[nlen
] = '\0';
1389 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
1392 /* FIXME! Want SYMBOL_NAME (sym) = 0;
1393 Get error if leave name 0. So give it something. */
1396 SYMBOL_NAME (sym
) = (char *)
1397 obstack_alloc (&objfile
->symbol_obstack
, nlen
);
1398 strncpy (SYMBOL_NAME (sym
), string
, nlen
);
1399 SYMBOL_NAME (sym
)[nlen
] = '\0';
1400 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
1403 /* Advance STRING beyond the reference id. */
1409 SYMBOL_LANGUAGE (sym
) = current_subfile
->language
;
1410 SYMBOL_NAME (sym
) = (char *)
1411 obstack_alloc (&objfile
->symbol_obstack
, ((p
- string
) + 1));
1412 /* Open-coded memcpy--saves function call time. */
1413 /* FIXME: Does it really? Try replacing with simple strcpy and
1414 try it on an executable with a large symbol table. */
1415 /* FIXME: considering that gcc can open code memcpy anyway, I
1416 doubt it. xoxorich. */
1418 register char *p1
= string
;
1419 register char *p2
= SYMBOL_NAME (sym
);
1427 /* If this symbol is from a C++ compilation, then attempt to cache the
1428 demangled form for future reference. This is a typical time versus
1429 space tradeoff, that was decided in favor of time because it sped up
1430 C++ symbol lookups by a factor of about 20. */
1432 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
1436 /* Determine the type of name being defined. */
1438 /* Getting GDB to correctly skip the symbol on an undefined symbol
1439 descriptor and not ever dump core is a very dodgy proposition if
1440 we do things this way. I say the acorn RISC machine can just
1441 fix their compiler. */
1442 /* The Acorn RISC machine's compiler can put out locals that don't
1443 start with "234=" or "(3,4)=", so assume anything other than the
1444 deftypes we know how to handle is a local. */
1445 if (!strchr ("cfFGpPrStTvVXCR", *p
))
1447 if (isdigit (*p
) || *p
== '(' || *p
== '-')
1456 /* c is a special case, not followed by a type-number.
1457 SYMBOL:c=iVALUE for an integer constant symbol.
1458 SYMBOL:c=rVALUE for a floating constant symbol.
1459 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
1460 e.g. "b:c=e6,0" for "const b = blob1"
1461 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
1464 SYMBOL_CLASS (sym
) = LOC_CONST
;
1465 SYMBOL_TYPE (sym
) = error_type (&p
, objfile
);
1466 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1467 add_symbol_to_list (sym
, &file_symbols
);
1475 double d
= atof (p
);
1478 /* FIXME-if-picky-about-floating-accuracy: Should be using
1479 target arithmetic to get the value. real.c in GCC
1480 probably has the necessary code. */
1482 /* FIXME: lookup_fundamental_type is a hack. We should be
1483 creating a type especially for the type of float constants.
1484 Problem is, what type should it be?
1486 Also, what should the name of this type be? Should we
1487 be using 'S' constants (see stabs.texinfo) instead? */
1489 SYMBOL_TYPE (sym
) = lookup_fundamental_type (objfile
,
1492 obstack_alloc (&objfile
->symbol_obstack
,
1493 TYPE_LENGTH (SYMBOL_TYPE (sym
)));
1494 store_typed_floating (dbl_valu
, SYMBOL_TYPE (sym
), d
);
1495 SYMBOL_VALUE_BYTES (sym
) = dbl_valu
;
1496 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
1501 /* Defining integer constants this way is kind of silly,
1502 since 'e' constants allows the compiler to give not
1503 only the value, but the type as well. C has at least
1504 int, long, unsigned int, and long long as constant
1505 types; other languages probably should have at least
1506 unsigned as well as signed constants. */
1508 /* We just need one int constant type for all objfiles.
1509 It doesn't depend on languages or anything (arguably its
1510 name should be a language-specific name for a type of
1511 that size, but I'm inclined to say that if the compiler
1512 wants a nice name for the type, it can use 'e'). */
1513 static struct type
*int_const_type
;
1515 /* Yes, this is as long as a *host* int. That is because we
1517 if (int_const_type
== NULL
)
1519 init_type (TYPE_CODE_INT
,
1520 sizeof (int) * HOST_CHAR_BIT
/ TARGET_CHAR_BIT
, 0,
1522 (struct objfile
*) NULL
);
1523 SYMBOL_TYPE (sym
) = int_const_type
;
1524 SYMBOL_VALUE (sym
) = atoi (p
);
1525 SYMBOL_CLASS (sym
) = LOC_CONST
;
1529 /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value
1530 can be represented as integral.
1531 e.g. "b:c=e6,0" for "const b = blob1"
1532 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
1534 SYMBOL_CLASS (sym
) = LOC_CONST
;
1535 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1539 SYMBOL_TYPE (sym
) = error_type (&p
, objfile
);
1544 /* If the value is too big to fit in an int (perhaps because
1545 it is unsigned), or something like that, we silently get
1546 a bogus value. The type and everything else about it is
1547 correct. Ideally, we should be using whatever we have
1548 available for parsing unsigned and long long values,
1550 SYMBOL_VALUE (sym
) = atoi (p
);
1555 SYMBOL_CLASS (sym
) = LOC_CONST
;
1556 SYMBOL_TYPE (sym
) = error_type (&p
, objfile
);
1559 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1560 add_symbol_to_list (sym
, &file_symbols
);
1564 /* The name of a caught exception. */
1565 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1566 SYMBOL_CLASS (sym
) = LOC_LABEL
;
1567 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1568 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1569 add_symbol_to_list (sym
, &local_symbols
);
1573 /* A static function definition. */
1574 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1575 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1576 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1577 add_symbol_to_list (sym
, &file_symbols
);
1578 /* fall into process_function_types. */
1580 process_function_types
:
1581 /* Function result types are described as the result type in stabs.
1582 We need to convert this to the function-returning-type-X type
1583 in GDB. E.g. "int" is converted to "function returning int". */
1584 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_FUNC
)
1585 SYMBOL_TYPE (sym
) = lookup_function_type (SYMBOL_TYPE (sym
));
1587 /* All functions in C++ have prototypes. */
1588 if (SYMBOL_LANGUAGE (sym
) == language_cplus
)
1589 TYPE_FLAGS (SYMBOL_TYPE (sym
)) |= TYPE_FLAG_PROTOTYPED
;
1591 /* fall into process_prototype_types */
1593 process_prototype_types
:
1594 /* Sun acc puts declared types of arguments here. */
1597 struct type
*ftype
= SYMBOL_TYPE (sym
);
1602 /* Obtain a worst case guess for the number of arguments
1603 by counting the semicolons. */
1610 /* Allocate parameter information fields and fill them in. */
1611 TYPE_FIELDS (ftype
) = (struct field
*)
1612 TYPE_ALLOC (ftype
, nsemi
* sizeof (struct field
));
1617 /* A type number of zero indicates the start of varargs.
1618 FIXME: GDB currently ignores vararg functions. */
1619 if (p
[0] == '0' && p
[1] == '\0')
1621 ptype
= read_type (&p
, objfile
);
1623 /* The Sun compilers mark integer arguments, which should
1624 be promoted to the width of the calling conventions, with
1625 a type which references itself. This type is turned into
1626 a TYPE_CODE_VOID type by read_type, and we have to turn
1627 it back into builtin_type_int here.
1628 FIXME: Do we need a new builtin_type_promoted_int_arg ? */
1629 if (TYPE_CODE (ptype
) == TYPE_CODE_VOID
)
1630 ptype
= builtin_type_int
;
1631 TYPE_FIELD_TYPE (ftype
, nparams
++) = ptype
;
1633 TYPE_NFIELDS (ftype
) = nparams
;
1634 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
1639 /* A global function definition. */
1640 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1641 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1642 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1643 add_symbol_to_list (sym
, &global_symbols
);
1644 goto process_function_types
;
1647 /* For a class G (global) symbol, it appears that the
1648 value is not correct. It is necessary to search for the
1649 corresponding linker definition to find the value.
1650 These definitions appear at the end of the namelist. */
1651 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1652 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1653 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1654 /* Don't add symbol references to global_sym_chain.
1655 Symbol references don't have valid names and wont't match up with
1656 minimal symbols when the global_sym_chain is relocated.
1657 We'll fixup symbol references when we fixup the defining symbol. */
1658 if (SYMBOL_NAME (sym
) && SYMBOL_NAME (sym
)[0] != '#')
1660 i
= hashname (SYMBOL_NAME (sym
));
1661 SYMBOL_VALUE_CHAIN (sym
) = global_sym_chain
[i
];
1662 global_sym_chain
[i
] = sym
;
1664 add_symbol_to_list (sym
, &global_symbols
);
1667 /* This case is faked by a conditional above,
1668 when there is no code letter in the dbx data.
1669 Dbx data never actually contains 'l'. */
1672 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1673 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1674 SYMBOL_VALUE (sym
) = valu
;
1675 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1676 add_symbol_to_list (sym
, &local_symbols
);
1681 /* pF is a two-letter code that means a function parameter in Fortran.
1682 The type-number specifies the type of the return value.
1683 Translate it into a pointer-to-function type. */
1687 = lookup_pointer_type
1688 (lookup_function_type (read_type (&p
, objfile
)));
1691 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1693 /* Normally this is a parameter, a LOC_ARG. On the i960, it
1694 can also be a LOC_LOCAL_ARG depending on symbol type. */
1695 #ifndef DBX_PARM_SYMBOL_CLASS
1696 #define DBX_PARM_SYMBOL_CLASS(type) LOC_ARG
1699 SYMBOL_CLASS (sym
) = DBX_PARM_SYMBOL_CLASS (type
);
1700 SYMBOL_VALUE (sym
) = valu
;
1701 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1702 add_symbol_to_list (sym
, &local_symbols
);
1704 if (TARGET_BYTE_ORDER
!= BFD_ENDIAN_BIG
)
1706 /* On little-endian machines, this crud is never necessary,
1707 and, if the extra bytes contain garbage, is harmful. */
1711 /* If it's gcc-compiled, if it says `short', believe it. */
1712 if (processing_gcc_compilation
|| BELIEVE_PCC_PROMOTION
)
1715 if (!BELIEVE_PCC_PROMOTION
)
1717 /* This is the signed type which arguments get promoted to. */
1718 static struct type
*pcc_promotion_type
;
1719 /* This is the unsigned type which arguments get promoted to. */
1720 static struct type
*pcc_unsigned_promotion_type
;
1722 /* Call it "int" because this is mainly C lossage. */
1723 if (pcc_promotion_type
== NULL
)
1724 pcc_promotion_type
=
1725 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
1728 if (pcc_unsigned_promotion_type
== NULL
)
1729 pcc_unsigned_promotion_type
=
1730 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
1731 TYPE_FLAG_UNSIGNED
, "unsigned int", NULL
);
1733 if (BELIEVE_PCC_PROMOTION_TYPE
)
1735 /* This is defined on machines (e.g. sparc) where we
1736 should believe the type of a PCC 'short' argument,
1737 but shouldn't believe the address (the address is the
1738 address of the corresponding int).
1740 My guess is that this correction, as opposed to
1741 changing the parameter to an 'int' (as done below,
1742 for PCC on most machines), is the right thing to do
1743 on all machines, but I don't want to risk breaking
1744 something that already works. On most PCC machines,
1745 the sparc problem doesn't come up because the calling
1746 function has to zero the top bytes (not knowing
1747 whether the called function wants an int or a short),
1748 so there is little practical difference between an
1749 int and a short (except perhaps what happens when the
1750 GDB user types "print short_arg = 0x10000;").
1752 Hacked for SunOS 4.1 by gnu@cygnus.com. In 4.1, the
1753 compiler actually produces the correct address (we
1754 don't need to fix it up). I made this code adapt so
1755 that it will offset the symbol if it was pointing at
1756 an int-aligned location and not otherwise. This way
1757 you can use the same gdb for 4.0.x and 4.1 systems.
1759 If the parameter is shorter than an int, and is
1760 integral (e.g. char, short, or unsigned equivalent),
1761 and is claimed to be passed on an integer boundary,
1762 don't believe it! Offset the parameter's address to
1763 the tail-end of that integer. */
1765 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (pcc_promotion_type
)
1766 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
1767 && 0 == SYMBOL_VALUE (sym
) % TYPE_LENGTH (pcc_promotion_type
))
1769 SYMBOL_VALUE (sym
) += TYPE_LENGTH (pcc_promotion_type
)
1770 - TYPE_LENGTH (SYMBOL_TYPE (sym
));
1776 /* If PCC says a parameter is a short or a char,
1777 it is really an int. */
1778 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (pcc_promotion_type
)
1779 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
)
1782 TYPE_UNSIGNED (SYMBOL_TYPE (sym
))
1783 ? pcc_unsigned_promotion_type
1784 : pcc_promotion_type
;
1791 /* acc seems to use P to declare the prototypes of functions that
1792 are referenced by this file. gdb is not prepared to deal
1793 with this extra information. FIXME, it ought to. */
1796 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1797 goto process_prototype_types
;
1802 /* Parameter which is in a register. */
1803 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1804 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
1805 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
1806 if (SYMBOL_VALUE (sym
) >= NUM_REGS
+ NUM_PSEUDO_REGS
)
1808 complain (®_value_complaint
, SYMBOL_VALUE (sym
),
1809 NUM_REGS
+ NUM_PSEUDO_REGS
,
1810 SYMBOL_SOURCE_NAME (sym
));
1811 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
1813 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1814 add_symbol_to_list (sym
, &local_symbols
);
1818 /* Register variable (either global or local). */
1819 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1820 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
1821 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
1822 if (SYMBOL_VALUE (sym
) >= NUM_REGS
+ NUM_PSEUDO_REGS
)
1824 complain (®_value_complaint
, SYMBOL_VALUE (sym
),
1825 NUM_REGS
+ NUM_PSEUDO_REGS
,
1826 SYMBOL_SOURCE_NAME (sym
));
1827 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
1829 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1830 if (within_function
)
1832 /* Sun cc uses a pair of symbols, one 'p' and one 'r' with the same
1833 name to represent an argument passed in a register.
1834 GCC uses 'P' for the same case. So if we find such a symbol pair
1835 we combine it into one 'P' symbol. For Sun cc we need to do this
1836 regardless of REG_STRUCT_HAS_ADDR, because the compiler puts out
1837 the 'p' symbol even if it never saves the argument onto the stack.
1839 On most machines, we want to preserve both symbols, so that
1840 we can still get information about what is going on with the
1841 stack (VAX for computing args_printed, using stack slots instead
1842 of saved registers in backtraces, etc.).
1844 Note that this code illegally combines
1845 main(argc) struct foo argc; { register struct foo argc; }
1846 but this case is considered pathological and causes a warning
1847 from a decent compiler. */
1850 && local_symbols
->nsyms
> 0
1851 #ifndef USE_REGISTER_NOT_ARG
1852 && REG_STRUCT_HAS_ADDR_P ()
1853 && REG_STRUCT_HAS_ADDR (processing_gcc_compilation
,
1855 && (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
1856 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
1857 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_SET
1858 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_BITSTRING
)
1862 struct symbol
*prev_sym
;
1863 prev_sym
= local_symbols
->symbol
[local_symbols
->nsyms
- 1];
1864 if ((SYMBOL_CLASS (prev_sym
) == LOC_REF_ARG
1865 || SYMBOL_CLASS (prev_sym
) == LOC_ARG
)
1866 && STREQ (SYMBOL_NAME (prev_sym
), SYMBOL_NAME (sym
)))
1868 SYMBOL_CLASS (prev_sym
) = LOC_REGPARM
;
1869 /* Use the type from the LOC_REGISTER; that is the type
1870 that is actually in that register. */
1871 SYMBOL_TYPE (prev_sym
) = SYMBOL_TYPE (sym
);
1872 SYMBOL_VALUE (prev_sym
) = SYMBOL_VALUE (sym
);
1877 add_symbol_to_list (sym
, &local_symbols
);
1880 add_symbol_to_list (sym
, &file_symbols
);
1884 /* Static symbol at top level of file */
1885 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1886 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1887 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1888 #ifdef STATIC_TRANSFORM_NAME
1889 if (IS_STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym
)))
1891 struct minimal_symbol
*msym
;
1892 msym
= lookup_minimal_symbol (SYMBOL_NAME (sym
), NULL
, objfile
);
1895 SYMBOL_NAME (sym
) = STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym
));
1896 SYMBOL_VALUE_ADDRESS (sym
) = SYMBOL_VALUE_ADDRESS (msym
);
1900 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1901 add_symbol_to_list (sym
, &file_symbols
);
1905 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1907 /* For a nameless type, we don't want a create a symbol, thus we
1908 did not use `sym'. Return without further processing. */
1912 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1913 SYMBOL_VALUE (sym
) = valu
;
1914 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1915 /* C++ vagaries: we may have a type which is derived from
1916 a base type which did not have its name defined when the
1917 derived class was output. We fill in the derived class's
1918 base part member's name here in that case. */
1919 if (TYPE_NAME (SYMBOL_TYPE (sym
)) != NULL
)
1920 if ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
1921 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
)
1922 && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)))
1925 for (j
= TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)) - 1; j
>= 0; j
--)
1926 if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) == 0)
1927 TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) =
1928 type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym
), j
));
1931 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == NULL
)
1933 /* gcc-2.6 or later (when using -fvtable-thunks)
1934 emits a unique named type for a vtable entry.
1935 Some gdb code depends on that specific name. */
1936 extern const char vtbl_ptr_name
[];
1938 if ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_PTR
1939 && strcmp (SYMBOL_NAME (sym
), vtbl_ptr_name
))
1940 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_FUNC
)
1942 /* If we are giving a name to a type such as "pointer to
1943 foo" or "function returning foo", we better not set
1944 the TYPE_NAME. If the program contains "typedef char
1945 *caddr_t;", we don't want all variables of type char
1946 * to print as caddr_t. This is not just a
1947 consequence of GDB's type management; PCC and GCC (at
1948 least through version 2.4) both output variables of
1949 either type char * or caddr_t with the type number
1950 defined in the 't' symbol for caddr_t. If a future
1951 compiler cleans this up it GDB is not ready for it
1952 yet, but if it becomes ready we somehow need to
1953 disable this check (without breaking the PCC/GCC2.4
1958 Fortunately, this check seems not to be necessary
1959 for anything except pointers or functions. */
1960 /* ezannoni: 2000-10-26. This seems to apply for
1961 versions of gcc older than 2.8. This was the original
1962 problem: with the following code gdb would tell that
1963 the type for name1 is caddr_t, and func is char()
1964 typedef char *caddr_t;
1976 /* Pascal accepts names for pointer types. */
1977 if (current_subfile
->language
== language_pascal
)
1979 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_NAME (sym
);
1983 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_NAME (sym
);
1986 add_symbol_to_list (sym
, &file_symbols
);
1990 /* Struct, union, or enum tag. For GNU C++, this can be be followed
1991 by 't' which means we are typedef'ing it as well. */
1992 synonym
= *p
== 't';
1996 /* The semantics of C++ state that "struct foo { ... }" also defines
1997 a typedef for "foo". Unfortunately, cfront never makes the typedef
1998 when translating C++ into C. We make the typedef here so that
1999 "ptype foo" works as expected for cfront translated code. */
2000 else if (current_subfile
->language
== language_cplus
)
2003 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
2005 /* For a nameless type, we don't want a create a symbol, thus we
2006 did not use `sym'. Return without further processing. */
2010 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
2011 SYMBOL_VALUE (sym
) = valu
;
2012 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
2013 if (TYPE_TAG_NAME (SYMBOL_TYPE (sym
)) == 0)
2014 TYPE_TAG_NAME (SYMBOL_TYPE (sym
))
2015 = obconcat (&objfile
->type_obstack
, "", "", SYMBOL_NAME (sym
));
2016 add_symbol_to_list (sym
, &file_symbols
);
2020 /* Clone the sym and then modify it. */
2021 register struct symbol
*typedef_sym
= (struct symbol
*)
2022 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct symbol
));
2023 *typedef_sym
= *sym
;
2024 SYMBOL_CLASS (typedef_sym
) = LOC_TYPEDEF
;
2025 SYMBOL_VALUE (typedef_sym
) = valu
;
2026 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
2027 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
2028 TYPE_NAME (SYMBOL_TYPE (sym
))
2029 = obconcat (&objfile
->type_obstack
, "", "", SYMBOL_NAME (sym
));
2030 add_symbol_to_list (typedef_sym
, &file_symbols
);
2035 /* Static symbol of local scope */
2036 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
2037 SYMBOL_CLASS (sym
) = LOC_STATIC
;
2038 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
2039 #ifdef STATIC_TRANSFORM_NAME
2040 if (IS_STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym
)))
2042 struct minimal_symbol
*msym
;
2043 msym
= lookup_minimal_symbol (SYMBOL_NAME (sym
), NULL
, objfile
);
2046 SYMBOL_NAME (sym
) = STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym
));
2047 SYMBOL_VALUE_ADDRESS (sym
) = SYMBOL_VALUE_ADDRESS (msym
);
2051 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2053 add_symbol_to_list (sym
, &global_symbols
);
2055 add_symbol_to_list (sym
, &local_symbols
);
2059 /* Reference parameter */
2060 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
2061 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
2062 SYMBOL_VALUE (sym
) = valu
;
2063 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2064 add_symbol_to_list (sym
, &local_symbols
);
2068 /* Reference parameter which is in a register. */
2069 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
2070 SYMBOL_CLASS (sym
) = LOC_REGPARM_ADDR
;
2071 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
2072 if (SYMBOL_VALUE (sym
) >= NUM_REGS
+ NUM_PSEUDO_REGS
)
2074 complain (®_value_complaint
, SYMBOL_VALUE (sym
),
2075 NUM_REGS
+ NUM_PSEUDO_REGS
,
2076 SYMBOL_SOURCE_NAME (sym
));
2077 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
2079 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2080 add_symbol_to_list (sym
, &local_symbols
);
2084 /* This is used by Sun FORTRAN for "function result value".
2085 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
2086 that Pascal uses it too, but when I tried it Pascal used
2087 "x:3" (local symbol) instead. */
2088 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
2089 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
2090 SYMBOL_VALUE (sym
) = valu
;
2091 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2092 add_symbol_to_list (sym
, &local_symbols
);
2095 /* New code added to support cfront stabs strings.
2096 Note: case 'P' already handled above */
2098 /* Cfront type continuation coming up!
2099 Find the original definition and add to it.
2100 We'll have to do this for the typedef too,
2101 since we cloned the symbol to define a type in read_type.
2102 Stabs info examples:
2104 foo__1CFv :ZtF (first def foo__1CFv:F(0,3);(0,24))
2105 C:ZsC;;__ct__1CFv func1__1CFv func2__1CFv ... ;;;
2106 where C is the name of the class.
2107 Unfortunately, we can't lookup the original symbol yet 'cuz
2108 we haven't finished reading all the symbols.
2109 Instead, we save it for processing later */
2110 process_later (sym
, p
, resolve_cfront_continuation
);
2111 SYMBOL_TYPE (sym
) = error_type (&p
, objfile
); /* FIXME! change later */
2112 SYMBOL_CLASS (sym
) = LOC_CONST
;
2113 SYMBOL_VALUE (sym
) = 0;
2114 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2115 /* Don't add to list - we'll delete it later when
2116 we add the continuation to the real sym */
2118 /* End of new code added to support cfront stabs strings */
2121 SYMBOL_TYPE (sym
) = error_type (&p
, objfile
);
2122 SYMBOL_CLASS (sym
) = LOC_CONST
;
2123 SYMBOL_VALUE (sym
) = 0;
2124 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2125 add_symbol_to_list (sym
, &file_symbols
);
2129 /* When passing structures to a function, some systems sometimes pass
2130 the address in a register, not the structure itself. */
2132 if (REG_STRUCT_HAS_ADDR_P ()
2133 && REG_STRUCT_HAS_ADDR (processing_gcc_compilation
, SYMBOL_TYPE (sym
))
2134 && (SYMBOL_CLASS (sym
) == LOC_REGPARM
|| SYMBOL_CLASS (sym
) == LOC_ARG
))
2136 struct type
*symbol_type
= check_typedef (SYMBOL_TYPE (sym
));
2138 if ((TYPE_CODE (symbol_type
) == TYPE_CODE_STRUCT
)
2139 || (TYPE_CODE (symbol_type
) == TYPE_CODE_UNION
)
2140 || (TYPE_CODE (symbol_type
) == TYPE_CODE_BITSTRING
)
2141 || (TYPE_CODE (symbol_type
) == TYPE_CODE_SET
))
2143 /* If REG_STRUCT_HAS_ADDR yields non-zero we have to convert
2144 LOC_REGPARM to LOC_REGPARM_ADDR for structures and unions. */
2145 if (SYMBOL_CLASS (sym
) == LOC_REGPARM
)
2146 SYMBOL_CLASS (sym
) = LOC_REGPARM_ADDR
;
2147 /* Likewise for converting LOC_ARG to LOC_REF_ARG (for the 7th
2148 and subsequent arguments on the sparc, for example). */
2149 else if (SYMBOL_CLASS (sym
) == LOC_ARG
)
2150 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
2154 /* Is there more to parse? For example LRS/alias information? */
2155 while (*p
&& *p
== ';')
2158 if (*p
&& p
[0] == 'l' && p
[1] == '(')
2160 /* GNU extensions for live range splitting may be appended to
2161 the end of the stab string. eg. "l(#1,#2);l(#3,#5)" */
2163 /* Resolve the live range and add it to SYM's live range list. */
2164 if (!resolve_live_range (objfile
, sym
, p
))
2167 /* Find end of live range info. */
2168 p
= strchr (p
, ')');
2169 if (!*p
|| *p
!= ')')
2171 complain (&lrs_general_complaint
, "live range format not recognized");
2180 /* Add the live range found in P to the symbol SYM in objfile OBJFILE. Returns
2181 non-zero on success, zero otherwise. */
2184 resolve_live_range (struct objfile
*objfile
, struct symbol
*sym
, char *p
)
2187 CORE_ADDR start
, end
;
2189 /* Sanity check the beginning of the stabs string. */
2190 if (!*p
|| *p
!= 'l')
2192 complain (&lrs_general_complaint
, "live range string 1");
2197 if (!*p
|| *p
!= '(')
2199 complain (&lrs_general_complaint
, "live range string 2");
2204 /* Get starting value of range and advance P past the reference id.
2206 ?!? In theory, the process_reference should never fail, but we should
2207 catch that case just in case the compiler scrogged the stabs. */
2208 refnum
= process_reference (&p
);
2209 start
= ref_search_value (refnum
);
2212 complain (&lrs_general_complaint
, "Live range symbol not found 1");
2216 if (!*p
|| *p
!= ',')
2218 complain (&lrs_general_complaint
, "live range string 3");
2223 /* Get ending value of range and advance P past the reference id.
2225 ?!? In theory, the process_reference should never fail, but we should
2226 catch that case just in case the compiler scrogged the stabs. */
2227 refnum
= process_reference (&p
);
2228 end
= ref_search_value (refnum
);
2231 complain (&lrs_general_complaint
, "Live range symbol not found 2");
2235 if (!*p
|| *p
!= ')')
2237 complain (&lrs_general_complaint
, "live range string 4");
2241 /* Now that we know the bounds of the range, add it to the
2243 add_live_range (objfile
, sym
, start
, end
);
2248 /* Add a new live range defined by START and END to the symbol SYM
2249 in objfile OBJFILE. */
2252 add_live_range (struct objfile
*objfile
, struct symbol
*sym
, CORE_ADDR start
,
2255 struct range_list
*r
, *rs
;
2259 complain (&lrs_general_complaint
, "end of live range follows start");
2263 /* Alloc new live range structure. */
2264 r
= (struct range_list
*)
2265 obstack_alloc (&objfile
->type_obstack
,
2266 sizeof (struct range_list
));
2271 /* Append this range to the symbol's range list. */
2272 if (!SYMBOL_RANGES (sym
))
2273 SYMBOL_RANGES (sym
) = r
;
2276 /* Get the last range for the symbol. */
2277 for (rs
= SYMBOL_RANGES (sym
); rs
->next
; rs
= rs
->next
)
2284 /* Skip rest of this symbol and return an error type.
2286 General notes on error recovery: error_type always skips to the
2287 end of the symbol (modulo cretinous dbx symbol name continuation).
2288 Thus code like this:
2290 if (*(*pp)++ != ';')
2291 return error_type (pp, objfile);
2293 is wrong because if *pp starts out pointing at '\0' (typically as the
2294 result of an earlier error), it will be incremented to point to the
2295 start of the next symbol, which might produce strange results, at least
2296 if you run off the end of the string table. Instead use
2299 return error_type (pp, objfile);
2305 foo = error_type (pp, objfile);
2309 And in case it isn't obvious, the point of all this hair is so the compiler
2310 can define new types and new syntaxes, and old versions of the
2311 debugger will be able to read the new symbol tables. */
2313 static struct type
*
2314 error_type (char **pp
, struct objfile
*objfile
)
2316 complain (&error_type_complaint
);
2319 /* Skip to end of symbol. */
2320 while (**pp
!= '\0')
2325 /* Check for and handle cretinous dbx symbol name continuation! */
2326 if ((*pp
)[-1] == '\\' || (*pp
)[-1] == '?')
2328 *pp
= next_symbol_text (objfile
);
2335 return (builtin_type_error
);
2339 /* Read type information or a type definition; return the type. Even
2340 though this routine accepts either type information or a type
2341 definition, the distinction is relevant--some parts of stabsread.c
2342 assume that type information starts with a digit, '-', or '(' in
2343 deciding whether to call read_type. */
2346 read_type (register char **pp
, struct objfile
*objfile
)
2348 register struct type
*type
= 0;
2351 char type_descriptor
;
2353 /* Size in bits of type if specified by a type attribute, or -1 if
2354 there is no size attribute. */
2357 /* Used to distinguish string and bitstring from char-array and set. */
2360 /* Read type number if present. The type number may be omitted.
2361 for instance in a two-dimensional array declared with type
2362 "ar1;1;10;ar1;1;10;4". */
2363 if ((**pp
>= '0' && **pp
<= '9')
2367 if (read_type_number (pp
, typenums
) != 0)
2368 return error_type (pp
, objfile
);
2370 /* Type is not being defined here. Either it already exists,
2371 or this is a forward reference to it. dbx_alloc_type handles
2374 return dbx_alloc_type (typenums
, objfile
);
2376 /* Type is being defined here. */
2378 Also skip the type descriptor - we get it below with (*pp)[-1]. */
2383 /* 'typenums=' not present, type is anonymous. Read and return
2384 the definition, but don't put it in the type vector. */
2385 typenums
[0] = typenums
[1] = -1;
2390 type_descriptor
= (*pp
)[-1];
2391 switch (type_descriptor
)
2395 enum type_code code
;
2397 /* Used to index through file_symbols. */
2398 struct pending
*ppt
;
2401 /* Name including "struct", etc. */
2405 char *from
, *to
, *p
, *q1
, *q2
;
2407 /* Set the type code according to the following letter. */
2411 code
= TYPE_CODE_STRUCT
;
2414 code
= TYPE_CODE_UNION
;
2417 code
= TYPE_CODE_ENUM
;
2421 /* Complain and keep going, so compilers can invent new
2422 cross-reference types. */
2423 static struct complaint msg
=
2424 {"Unrecognized cross-reference type `%c'", 0, 0};
2425 complain (&msg
, (*pp
)[0]);
2426 code
= TYPE_CODE_STRUCT
;
2431 q1
= strchr (*pp
, '<');
2432 p
= strchr (*pp
, ':');
2434 return error_type (pp
, objfile
);
2435 if (q1
&& p
> q1
&& p
[1] == ':')
2437 int nesting_level
= 0;
2438 for (q2
= q1
; *q2
; q2
++)
2442 else if (*q2
== '>')
2444 else if (*q2
== ':' && nesting_level
== 0)
2449 return error_type (pp
, objfile
);
2452 (char *) obstack_alloc (&objfile
->type_obstack
, p
- *pp
+ 1);
2454 /* Copy the name. */
2460 /* Set the pointer ahead of the name which we just read, and
2465 /* Now check to see whether the type has already been
2466 declared. This was written for arrays of cross-referenced
2467 types before we had TYPE_CODE_TARGET_STUBBED, so I'm pretty
2468 sure it is not necessary anymore. But it might be a good
2469 idea, to save a little memory. */
2471 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
2472 for (i
= 0; i
< ppt
->nsyms
; i
++)
2474 struct symbol
*sym
= ppt
->symbol
[i
];
2476 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
2477 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
2478 && (TYPE_CODE (SYMBOL_TYPE (sym
)) == code
)
2479 && STREQ (SYMBOL_NAME (sym
), type_name
))
2481 obstack_free (&objfile
->type_obstack
, type_name
);
2482 type
= SYMBOL_TYPE (sym
);
2487 /* Didn't find the type to which this refers, so we must
2488 be dealing with a forward reference. Allocate a type
2489 structure for it, and keep track of it so we can
2490 fill in the rest of the fields when we get the full
2492 type
= dbx_alloc_type (typenums
, objfile
);
2493 TYPE_CODE (type
) = code
;
2494 TYPE_TAG_NAME (type
) = type_name
;
2495 INIT_CPLUS_SPECIFIC (type
);
2496 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
2498 add_undefined_type (type
);
2502 case '-': /* RS/6000 built-in type */
2516 /* We deal with something like t(1,2)=(3,4)=... which
2517 the Lucid compiler and recent gcc versions (post 2.7.3) use. */
2519 /* Allocate and enter the typedef type first.
2520 This handles recursive types. */
2521 type
= dbx_alloc_type (typenums
, objfile
);
2522 TYPE_CODE (type
) = TYPE_CODE_TYPEDEF
;
2524 struct type
*xtype
= read_type (pp
, objfile
);
2527 /* It's being defined as itself. That means it is "void". */
2528 TYPE_CODE (type
) = TYPE_CODE_VOID
;
2529 TYPE_LENGTH (type
) = 1;
2531 else if (type_size
>= 0 || is_string
)
2534 TYPE_NAME (type
) = NULL
;
2535 TYPE_TAG_NAME (type
) = NULL
;
2539 TYPE_FLAGS (type
) |= TYPE_FLAG_TARGET_STUB
;
2540 TYPE_TARGET_TYPE (type
) = xtype
;
2545 /* In the following types, we must be sure to overwrite any existing
2546 type that the typenums refer to, rather than allocating a new one
2547 and making the typenums point to the new one. This is because there
2548 may already be pointers to the existing type (if it had been
2549 forward-referenced), and we must change it to a pointer, function,
2550 reference, or whatever, *in-place*. */
2553 type1
= read_type (pp
, objfile
);
2554 type
= make_pointer_type (type1
, dbx_lookup_type (typenums
));
2557 case '&': /* Reference to another type */
2558 type1
= read_type (pp
, objfile
);
2559 type
= make_reference_type (type1
, dbx_lookup_type (typenums
));
2562 case 'f': /* Function returning another type */
2563 if (os9k_stabs
&& **pp
== '(')
2565 /* Function prototype; parse it.
2566 We must conditionalize this on os9k_stabs because otherwise
2567 it could be confused with a Sun-style (1,3) typenumber
2573 t
= read_type (pp
, objfile
);
2578 type1
= read_type (pp
, objfile
);
2579 type
= make_function_type (type1
, dbx_lookup_type (typenums
));
2582 case 'k': /* Const qualifier on some type (Sun) */
2583 case 'c': /* Const qualifier on some type (OS9000) */
2584 /* Because 'c' means other things to AIX and 'k' is perfectly good,
2585 only accept 'c' in the os9k_stabs case. */
2586 if (type_descriptor
== 'c' && !os9k_stabs
)
2587 return error_type (pp
, objfile
);
2588 type
= read_type (pp
, objfile
);
2589 type
= make_cv_type (1, TYPE_VOLATILE (type
), type
,
2590 dbx_lookup_type (typenums
));
2593 case 'B': /* Volatile qual on some type (Sun) */
2594 case 'i': /* Volatile qual on some type (OS9000) */
2595 /* Because 'i' means other things to AIX and 'B' is perfectly good,
2596 only accept 'i' in the os9k_stabs case. */
2597 if (type_descriptor
== 'i' && !os9k_stabs
)
2598 return error_type (pp
, objfile
);
2599 type
= read_type (pp
, objfile
);
2600 type
= make_cv_type (TYPE_CONST (type
), 1, type
,
2601 dbx_lookup_type (typenums
));
2605 if (isdigit (**pp
) || **pp
== '(' || **pp
== '-')
2606 { /* Member (class & variable) type */
2607 /* FIXME -- we should be doing smash_to_XXX types here. */
2609 struct type
*domain
= read_type (pp
, objfile
);
2610 struct type
*memtype
;
2613 /* Invalid member type data format. */
2614 return error_type (pp
, objfile
);
2617 memtype
= read_type (pp
, objfile
);
2618 type
= dbx_alloc_type (typenums
, objfile
);
2619 smash_to_member_type (type
, domain
, memtype
);
2622 /* type attribute */
2625 /* Skip to the semicolon. */
2626 while (**pp
!= ';' && **pp
!= '\0')
2629 return error_type (pp
, objfile
);
2631 ++ * pp
; /* Skip the semicolon. */
2636 type_size
= atoi (attr
+ 1);
2646 /* Ignore unrecognized type attributes, so future compilers
2647 can invent new ones. */
2655 case '#': /* Method (class & fn) type */
2656 if ((*pp
)[0] == '#')
2658 /* We'll get the parameter types from the name. */
2659 struct type
*return_type
;
2662 return_type
= read_type (pp
, objfile
);
2663 if (*(*pp
)++ != ';')
2664 complain (&invalid_member_complaint
, symnum
);
2665 type
= allocate_stub_method (return_type
);
2666 if (typenums
[0] != -1)
2667 *dbx_lookup_type (typenums
) = type
;
2671 struct type
*domain
= read_type (pp
, objfile
);
2672 struct type
*return_type
;
2676 /* Invalid member type data format. */
2677 return error_type (pp
, objfile
);
2681 return_type
= read_type (pp
, objfile
);
2682 args
= read_args (pp
, ';', objfile
);
2683 type
= dbx_alloc_type (typenums
, objfile
);
2684 smash_to_method_type (type
, domain
, return_type
, args
);
2688 case 'r': /* Range type */
2689 type
= read_range_type (pp
, typenums
, objfile
);
2690 if (typenums
[0] != -1)
2691 *dbx_lookup_type (typenums
) = type
;
2696 /* Const and volatile qualified type. */
2697 type
= read_type (pp
, objfile
);
2700 /* Sun ACC builtin int type */
2701 type
= read_sun_builtin_type (pp
, typenums
, objfile
);
2702 if (typenums
[0] != -1)
2703 *dbx_lookup_type (typenums
) = type
;
2707 case 'R': /* Sun ACC builtin float type */
2708 type
= read_sun_floating_type (pp
, typenums
, objfile
);
2709 if (typenums
[0] != -1)
2710 *dbx_lookup_type (typenums
) = type
;
2713 case 'e': /* Enumeration type */
2714 type
= dbx_alloc_type (typenums
, objfile
);
2715 type
= read_enum_type (pp
, type
, objfile
);
2716 if (typenums
[0] != -1)
2717 *dbx_lookup_type (typenums
) = type
;
2720 case 's': /* Struct type */
2721 case 'u': /* Union type */
2722 type
= dbx_alloc_type (typenums
, objfile
);
2723 switch (type_descriptor
)
2726 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
2729 TYPE_CODE (type
) = TYPE_CODE_UNION
;
2732 type
= read_struct_type (pp
, type
, objfile
);
2735 case 'a': /* Array type */
2737 return error_type (pp
, objfile
);
2740 type
= dbx_alloc_type (typenums
, objfile
);
2741 type
= read_array_type (pp
, type
, objfile
);
2743 TYPE_CODE (type
) = TYPE_CODE_STRING
;
2747 type1
= read_type (pp
, objfile
);
2748 type
= create_set_type ((struct type
*) NULL
, type1
);
2750 TYPE_CODE (type
) = TYPE_CODE_BITSTRING
;
2751 if (typenums
[0] != -1)
2752 *dbx_lookup_type (typenums
) = type
;
2756 --*pp
; /* Go back to the symbol in error */
2757 /* Particularly important if it was \0! */
2758 return error_type (pp
, objfile
);
2763 warning ("GDB internal error, type is NULL in stabsread.c\n");
2764 return error_type (pp
, objfile
);
2767 /* Size specified in a type attribute overrides any other size. */
2768 if (type_size
!= -1)
2769 TYPE_LENGTH (type
) = (type_size
+ TARGET_CHAR_BIT
- 1) / TARGET_CHAR_BIT
;
2774 /* RS/6000 xlc/dbx combination uses a set of builtin types, starting from -1.
2775 Return the proper type node for a given builtin type number. */
2777 static struct type
*
2778 rs6000_builtin_type (int typenum
)
2780 /* We recognize types numbered from -NUMBER_RECOGNIZED to -1. */
2781 #define NUMBER_RECOGNIZED 34
2782 /* This includes an empty slot for type number -0. */
2783 static struct type
*negative_types
[NUMBER_RECOGNIZED
+ 1];
2784 struct type
*rettype
= NULL
;
2786 if (typenum
>= 0 || typenum
< -NUMBER_RECOGNIZED
)
2788 complain (&rs6000_builtin_complaint
, typenum
);
2789 return builtin_type_error
;
2791 if (negative_types
[-typenum
] != NULL
)
2792 return negative_types
[-typenum
];
2794 #if TARGET_CHAR_BIT != 8
2795 #error This code wrong for TARGET_CHAR_BIT not 8
2796 /* These definitions all assume that TARGET_CHAR_BIT is 8. I think
2797 that if that ever becomes not true, the correct fix will be to
2798 make the size in the struct type to be in bits, not in units of
2805 /* The size of this and all the other types are fixed, defined
2806 by the debugging format. If there is a type called "int" which
2807 is other than 32 bits, then it should use a new negative type
2808 number (or avoid negative type numbers for that case).
2809 See stabs.texinfo. */
2810 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "int", NULL
);
2813 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "char", NULL
);
2816 rettype
= init_type (TYPE_CODE_INT
, 2, 0, "short", NULL
);
2819 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "long", NULL
);
2822 rettype
= init_type (TYPE_CODE_INT
, 1, TYPE_FLAG_UNSIGNED
,
2823 "unsigned char", NULL
);
2826 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "signed char", NULL
);
2829 rettype
= init_type (TYPE_CODE_INT
, 2, TYPE_FLAG_UNSIGNED
,
2830 "unsigned short", NULL
);
2833 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
2834 "unsigned int", NULL
);
2837 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
2840 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
2841 "unsigned long", NULL
);
2844 rettype
= init_type (TYPE_CODE_VOID
, 1, 0, "void", NULL
);
2847 /* IEEE single precision (32 bit). */
2848 rettype
= init_type (TYPE_CODE_FLT
, 4, 0, "float", NULL
);
2851 /* IEEE double precision (64 bit). */
2852 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "double", NULL
);
2855 /* This is an IEEE double on the RS/6000, and different machines with
2856 different sizes for "long double" should use different negative
2857 type numbers. See stabs.texinfo. */
2858 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "long double", NULL
);
2861 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "integer", NULL
);
2864 rettype
= init_type (TYPE_CODE_BOOL
, 4, TYPE_FLAG_UNSIGNED
,
2868 rettype
= init_type (TYPE_CODE_FLT
, 4, 0, "short real", NULL
);
2871 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "real", NULL
);
2874 rettype
= init_type (TYPE_CODE_ERROR
, 0, 0, "stringptr", NULL
);
2877 rettype
= init_type (TYPE_CODE_CHAR
, 1, TYPE_FLAG_UNSIGNED
,
2881 rettype
= init_type (TYPE_CODE_BOOL
, 1, TYPE_FLAG_UNSIGNED
,
2885 rettype
= init_type (TYPE_CODE_BOOL
, 2, TYPE_FLAG_UNSIGNED
,
2889 rettype
= init_type (TYPE_CODE_BOOL
, 4, TYPE_FLAG_UNSIGNED
,
2893 rettype
= init_type (TYPE_CODE_BOOL
, 4, TYPE_FLAG_UNSIGNED
,
2897 /* Complex type consisting of two IEEE single precision values. */
2898 rettype
= init_type (TYPE_CODE_COMPLEX
, 8, 0, "complex", NULL
);
2901 /* Complex type consisting of two IEEE double precision values. */
2902 rettype
= init_type (TYPE_CODE_COMPLEX
, 16, 0, "double complex", NULL
);
2905 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "integer*1", NULL
);
2908 rettype
= init_type (TYPE_CODE_INT
, 2, 0, "integer*2", NULL
);
2911 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "integer*4", NULL
);
2914 rettype
= init_type (TYPE_CODE_CHAR
, 2, 0, "wchar", NULL
);
2917 rettype
= init_type (TYPE_CODE_INT
, 8, 0, "long long", NULL
);
2920 rettype
= init_type (TYPE_CODE_INT
, 8, TYPE_FLAG_UNSIGNED
,
2921 "unsigned long long", NULL
);
2924 rettype
= init_type (TYPE_CODE_INT
, 8, TYPE_FLAG_UNSIGNED
,
2928 rettype
= init_type (TYPE_CODE_INT
, 8, 0, "integer*8", NULL
);
2931 negative_types
[-typenum
] = rettype
;
2935 /* This page contains subroutines of read_type. */
2937 /* Read member function stabs info for C++ classes. The form of each member
2940 NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
2942 An example with two member functions is:
2944 afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
2946 For the case of overloaded operators, the format is op$::*.funcs, where
2947 $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
2948 name (such as `+=') and `.' marks the end of the operator name.
2950 Returns 1 for success, 0 for failure. */
2953 read_member_functions (struct field_info
*fip
, char **pp
, struct type
*type
,
2954 struct objfile
*objfile
)
2959 /* Total number of member functions defined in this class. If the class
2960 defines two `f' functions, and one `g' function, then this will have
2962 int total_length
= 0;
2966 struct next_fnfield
*next
;
2967 struct fn_field fn_field
;
2970 struct type
*look_ahead_type
;
2971 struct next_fnfieldlist
*new_fnlist
;
2972 struct next_fnfield
*new_sublist
;
2976 /* Process each list until we find something that is not a member function
2977 or find the end of the functions. */
2981 /* We should be positioned at the start of the function name.
2982 Scan forward to find the first ':' and if it is not the
2983 first of a "::" delimiter, then this is not a member function. */
2995 look_ahead_type
= NULL
;
2999 if (p
- *pp
== strlen ("__base_ctor")
3000 && strncmp (*pp
, "__base_ctor", strlen ("__base_ctor")) == 0)
3002 else if (p
- *pp
== strlen ("__base_dtor")
3003 && strncmp (*pp
, "__base_dtor", strlen ("__base_dtor")) == 0)
3005 else if (p
- *pp
== strlen ("__deleting_dtor")
3006 && strncmp (*pp
, "__deleting_dtor",
3007 strlen ("__deleting_dtor")) == 0)
3012 /* Skip past '::'. */
3014 /* Read the type. */
3015 read_type (pp
, objfile
);
3016 /* Skip past the colon, mangled name, semicolon, flags, and final
3028 new_fnlist
= (struct next_fnfieldlist
*)
3029 xmalloc (sizeof (struct next_fnfieldlist
));
3030 make_cleanup (xfree
, new_fnlist
);
3031 memset (new_fnlist
, 0, sizeof (struct next_fnfieldlist
));
3033 if ((*pp
)[0] == 'o' && (*pp
)[1] == 'p' && is_cplus_marker ((*pp
)[2]))
3035 /* This is a completely wierd case. In order to stuff in the
3036 names that might contain colons (the usual name delimiter),
3037 Mike Tiemann defined a different name format which is
3038 signalled if the identifier is "op$". In that case, the
3039 format is "op$::XXXX." where XXXX is the name. This is
3040 used for names like "+" or "=". YUUUUUUUK! FIXME! */
3041 /* This lets the user type "break operator+".
3042 We could just put in "+" as the name, but that wouldn't
3044 static char opname
[32] =
3045 {'o', 'p', CPLUS_MARKER
};
3046 char *o
= opname
+ 3;
3048 /* Skip past '::'. */
3051 STABS_CONTINUE (pp
, objfile
);
3057 main_fn_name
= savestring (opname
, o
- opname
);
3063 main_fn_name
= savestring (*pp
, p
- *pp
);
3064 /* Skip past '::'. */
3067 new_fnlist
->fn_fieldlist
.name
= main_fn_name
;
3072 (struct next_fnfield
*) xmalloc (sizeof (struct next_fnfield
));
3073 make_cleanup (xfree
, new_sublist
);
3074 memset (new_sublist
, 0, sizeof (struct next_fnfield
));
3076 /* Check for and handle cretinous dbx symbol name continuation! */
3077 if (look_ahead_type
== NULL
)
3080 STABS_CONTINUE (pp
, objfile
);
3082 new_sublist
->fn_field
.type
= read_type (pp
, objfile
);
3085 /* Invalid symtab info for member function. */
3091 /* g++ version 1 kludge */
3092 new_sublist
->fn_field
.type
= look_ahead_type
;
3093 look_ahead_type
= NULL
;
3103 /* If this is just a stub, then we don't have the real name here. */
3105 if (TYPE_STUB (new_sublist
->fn_field
.type
))
3107 if (!TYPE_DOMAIN_TYPE (new_sublist
->fn_field
.type
))
3108 TYPE_DOMAIN_TYPE (new_sublist
->fn_field
.type
) = type
;
3109 new_sublist
->fn_field
.is_stub
= 1;
3111 new_sublist
->fn_field
.physname
= savestring (*pp
, p
- *pp
);
3114 /* Set this member function's visibility fields. */
3117 case VISIBILITY_PRIVATE
:
3118 new_sublist
->fn_field
.is_private
= 1;
3120 case VISIBILITY_PROTECTED
:
3121 new_sublist
->fn_field
.is_protected
= 1;
3125 STABS_CONTINUE (pp
, objfile
);
3128 case 'A': /* Normal functions. */
3129 new_sublist
->fn_field
.is_const
= 0;
3130 new_sublist
->fn_field
.is_volatile
= 0;
3133 case 'B': /* `const' member functions. */
3134 new_sublist
->fn_field
.is_const
= 1;
3135 new_sublist
->fn_field
.is_volatile
= 0;
3138 case 'C': /* `volatile' member function. */
3139 new_sublist
->fn_field
.is_const
= 0;
3140 new_sublist
->fn_field
.is_volatile
= 1;
3143 case 'D': /* `const volatile' member function. */
3144 new_sublist
->fn_field
.is_const
= 1;
3145 new_sublist
->fn_field
.is_volatile
= 1;
3148 case '*': /* File compiled with g++ version 1 -- no info */
3153 complain (&const_vol_complaint
, **pp
);
3162 /* virtual member function, followed by index.
3163 The sign bit is set to distinguish pointers-to-methods
3164 from virtual function indicies. Since the array is
3165 in words, the quantity must be shifted left by 1
3166 on 16 bit machine, and by 2 on 32 bit machine, forcing
3167 the sign bit out, and usable as a valid index into
3168 the array. Remove the sign bit here. */
3169 new_sublist
->fn_field
.voffset
=
3170 (0x7fffffff & read_huge_number (pp
, ';', &nbits
)) + 2;
3174 STABS_CONTINUE (pp
, objfile
);
3175 if (**pp
== ';' || **pp
== '\0')
3177 /* Must be g++ version 1. */
3178 new_sublist
->fn_field
.fcontext
= 0;
3182 /* Figure out from whence this virtual function came.
3183 It may belong to virtual function table of
3184 one of its baseclasses. */
3185 look_ahead_type
= read_type (pp
, objfile
);
3188 /* g++ version 1 overloaded methods. */
3192 new_sublist
->fn_field
.fcontext
= look_ahead_type
;
3201 look_ahead_type
= NULL
;
3207 /* static member function. */
3208 new_sublist
->fn_field
.voffset
= VOFFSET_STATIC
;
3209 if (strncmp (new_sublist
->fn_field
.physname
,
3210 main_fn_name
, strlen (main_fn_name
)))
3212 new_sublist
->fn_field
.is_stub
= 1;
3218 complain (&member_fn_complaint
, (*pp
)[-1]);
3219 /* Fall through into normal member function. */
3222 /* normal member function. */
3223 new_sublist
->fn_field
.voffset
= 0;
3224 new_sublist
->fn_field
.fcontext
= 0;
3228 new_sublist
->next
= sublist
;
3229 sublist
= new_sublist
;
3231 STABS_CONTINUE (pp
, objfile
);
3233 while (**pp
!= ';' && **pp
!= '\0');
3237 new_fnlist
->fn_fieldlist
.fn_fields
= (struct fn_field
*)
3238 obstack_alloc (&objfile
->type_obstack
,
3239 sizeof (struct fn_field
) * length
);
3240 memset (new_fnlist
->fn_fieldlist
.fn_fields
, 0,
3241 sizeof (struct fn_field
) * length
);
3242 for (i
= length
; (i
--, sublist
); sublist
= sublist
->next
)
3244 new_fnlist
->fn_fieldlist
.fn_fields
[i
] = sublist
->fn_field
;
3247 new_fnlist
->fn_fieldlist
.length
= length
;
3248 new_fnlist
->next
= fip
->fnlist
;
3249 fip
->fnlist
= new_fnlist
;
3251 total_length
+= length
;
3252 STABS_CONTINUE (pp
, objfile
);
3257 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3258 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
3259 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * nfn_fields
);
3260 memset (TYPE_FN_FIELDLISTS (type
), 0,
3261 sizeof (struct fn_fieldlist
) * nfn_fields
);
3262 TYPE_NFN_FIELDS (type
) = nfn_fields
;
3263 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
3269 /* Special GNU C++ name.
3271 Returns 1 for success, 0 for failure. "failure" means that we can't
3272 keep parsing and it's time for error_type(). */
3275 read_cpp_abbrev (struct field_info
*fip
, char **pp
, struct type
*type
,
3276 struct objfile
*objfile
)
3281 struct type
*context
;
3291 /* At this point, *pp points to something like "22:23=*22...",
3292 where the type number before the ':' is the "context" and
3293 everything after is a regular type definition. Lookup the
3294 type, find it's name, and construct the field name. */
3296 context
= read_type (pp
, objfile
);
3300 case 'f': /* $vf -- a virtual function table pointer */
3301 name
= type_name_no_tag (context
);
3306 fip
->list
->field
.name
=
3307 obconcat (&objfile
->type_obstack
, vptr_name
, name
, "");
3310 case 'b': /* $vb -- a virtual bsomethingorother */
3311 name
= type_name_no_tag (context
);
3314 complain (&invalid_cpp_type_complaint
, symnum
);
3317 fip
->list
->field
.name
=
3318 obconcat (&objfile
->type_obstack
, vb_name
, name
, "");
3322 complain (&invalid_cpp_abbrev_complaint
, *pp
);
3323 fip
->list
->field
.name
=
3324 obconcat (&objfile
->type_obstack
,
3325 "INVALID_CPLUSPLUS_ABBREV", "", "");
3329 /* At this point, *pp points to the ':'. Skip it and read the
3335 complain (&invalid_cpp_abbrev_complaint
, *pp
);
3338 fip
->list
->field
.type
= read_type (pp
, objfile
);
3340 (*pp
)++; /* Skip the comma. */
3346 FIELD_BITPOS (fip
->list
->field
) = read_huge_number (pp
, ';', &nbits
);
3350 /* This field is unpacked. */
3351 FIELD_BITSIZE (fip
->list
->field
) = 0;
3352 fip
->list
->visibility
= VISIBILITY_PRIVATE
;
3356 complain (&invalid_cpp_abbrev_complaint
, *pp
);
3357 /* We have no idea what syntax an unrecognized abbrev would have, so
3358 better return 0. If we returned 1, we would need to at least advance
3359 *pp to avoid an infinite loop. */
3366 read_one_struct_field (struct field_info
*fip
, char **pp
, char *p
,
3367 struct type
*type
, struct objfile
*objfile
)
3369 /* The following is code to work around cfront generated stabs.
3370 The stabs contains full mangled name for each field.
3371 We try to demangle the name and extract the field name out of it.
3373 if (ARM_DEMANGLING
&& current_subfile
->language
== language_cplus
)
3379 dem
= cplus_demangle (*pp
, DMGL_ANSI
| DMGL_PARAMS
);
3382 dem_p
= strrchr (dem
, ':');
3383 if (dem_p
!= 0 && *(dem_p
- 1) == ':')
3385 FIELD_NAME (fip
->list
->field
) =
3386 obsavestring (dem_p
, strlen (dem_p
), &objfile
->type_obstack
);
3390 FIELD_NAME (fip
->list
->field
) =
3391 obsavestring (*pp
, p
- *pp
, &objfile
->type_obstack
);
3395 /* end of code for cfront work around */
3398 fip
->list
->field
.name
=
3399 obsavestring (*pp
, p
- *pp
, &objfile
->type_obstack
);
3402 /* This means we have a visibility for a field coming. */
3406 fip
->list
->visibility
= *(*pp
)++;
3410 /* normal dbx-style format, no explicit visibility */
3411 fip
->list
->visibility
= VISIBILITY_PUBLIC
;
3414 fip
->list
->field
.type
= read_type (pp
, objfile
);
3419 /* Possible future hook for nested types. */
3422 fip
->list
->field
.bitpos
= (long) -2; /* nested type */
3432 /* Static class member. */
3433 SET_FIELD_PHYSNAME (fip
->list
->field
, savestring (*pp
, p
- *pp
));
3437 else if (**pp
!= ',')
3439 /* Bad structure-type format. */
3440 complain (&stabs_general_complaint
, "bad structure-type format");
3444 (*pp
)++; /* Skip the comma. */
3448 FIELD_BITPOS (fip
->list
->field
) = read_huge_number (pp
, ',', &nbits
);
3451 complain (&stabs_general_complaint
, "bad structure-type format");
3454 FIELD_BITSIZE (fip
->list
->field
) = read_huge_number (pp
, ';', &nbits
);
3457 complain (&stabs_general_complaint
, "bad structure-type format");
3462 if (FIELD_BITPOS (fip
->list
->field
) == 0
3463 && FIELD_BITSIZE (fip
->list
->field
) == 0)
3465 /* This can happen in two cases: (1) at least for gcc 2.4.5 or so,
3466 it is a field which has been optimized out. The correct stab for
3467 this case is to use VISIBILITY_IGNORE, but that is a recent
3468 invention. (2) It is a 0-size array. For example
3469 union { int num; char str[0]; } foo. Printing "<no value>" for
3470 str in "p foo" is OK, since foo.str (and thus foo.str[3])
3471 will continue to work, and a 0-size array as a whole doesn't
3472 have any contents to print.
3474 I suspect this probably could also happen with gcc -gstabs (not
3475 -gstabs+) for static fields, and perhaps other C++ extensions.
3476 Hopefully few people use -gstabs with gdb, since it is intended
3477 for dbx compatibility. */
3479 /* Ignore this field. */
3480 fip
->list
->visibility
= VISIBILITY_IGNORE
;
3484 /* Detect an unpacked field and mark it as such.
3485 dbx gives a bit size for all fields.
3486 Note that forward refs cannot be packed,
3487 and treat enums as if they had the width of ints. */
3489 struct type
*field_type
= check_typedef (FIELD_TYPE (fip
->list
->field
));
3491 if (TYPE_CODE (field_type
) != TYPE_CODE_INT
3492 && TYPE_CODE (field_type
) != TYPE_CODE_RANGE
3493 && TYPE_CODE (field_type
) != TYPE_CODE_BOOL
3494 && TYPE_CODE (field_type
) != TYPE_CODE_ENUM
)
3496 FIELD_BITSIZE (fip
->list
->field
) = 0;
3498 if ((FIELD_BITSIZE (fip
->list
->field
)
3499 == TARGET_CHAR_BIT
* TYPE_LENGTH (field_type
)
3500 || (TYPE_CODE (field_type
) == TYPE_CODE_ENUM
3501 && FIELD_BITSIZE (fip
->list
->field
) == TARGET_INT_BIT
)
3504 FIELD_BITPOS (fip
->list
->field
) % 8 == 0)
3506 FIELD_BITSIZE (fip
->list
->field
) = 0;
3512 /* Read struct or class data fields. They have the form:
3514 NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
3516 At the end, we see a semicolon instead of a field.
3518 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
3521 The optional VISIBILITY is one of:
3523 '/0' (VISIBILITY_PRIVATE)
3524 '/1' (VISIBILITY_PROTECTED)
3525 '/2' (VISIBILITY_PUBLIC)
3526 '/9' (VISIBILITY_IGNORE)
3528 or nothing, for C style fields with public visibility.
3530 Returns 1 for success, 0 for failure. */
3533 read_struct_fields (struct field_info
*fip
, char **pp
, struct type
*type
,
3534 struct objfile
*objfile
)
3537 struct nextfield
*new;
3539 /* We better set p right now, in case there are no fields at all... */
3543 /* Read each data member type until we find the terminating ';' at the end of
3544 the data member list, or break for some other reason such as finding the
3545 start of the member function list. */
3546 /* Stab string for structure/union does not end with two ';' in
3547 SUN C compiler 5.3 i.e. F6U2, hence check for end of string. */
3549 while (**pp
!= ';' && **pp
!= '\0')
3551 if (os9k_stabs
&& **pp
== ',')
3553 STABS_CONTINUE (pp
, objfile
);
3554 /* Get space to record the next field's data. */
3555 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3556 make_cleanup (xfree
, new);
3557 memset (new, 0, sizeof (struct nextfield
));
3558 new->next
= fip
->list
;
3561 /* Get the field name. */
3564 /* If is starts with CPLUS_MARKER it is a special abbreviation,
3565 unless the CPLUS_MARKER is followed by an underscore, in
3566 which case it is just the name of an anonymous type, which we
3567 should handle like any other type name. */
3569 if (is_cplus_marker (p
[0]) && p
[1] != '_')
3571 if (!read_cpp_abbrev (fip
, pp
, type
, objfile
))
3576 /* Look for the ':' that separates the field name from the field
3577 values. Data members are delimited by a single ':', while member
3578 functions are delimited by a pair of ':'s. When we hit the member
3579 functions (if any), terminate scan loop and return. */
3581 while (*p
!= ':' && *p
!= '\0')
3588 /* Check to see if we have hit the member functions yet. */
3593 read_one_struct_field (fip
, pp
, p
, type
, objfile
);
3595 if (p
[0] == ':' && p
[1] == ':')
3597 /* chill the list of fields: the last entry (at the head) is a
3598 partially constructed entry which we now scrub. */
3599 fip
->list
= fip
->list
->next
;
3604 /* The stabs for C++ derived classes contain baseclass information which
3605 is marked by a '!' character after the total size. This function is
3606 called when we encounter the baseclass marker, and slurps up all the
3607 baseclass information.
3609 Immediately following the '!' marker is the number of base classes that
3610 the class is derived from, followed by information for each base class.
3611 For each base class, there are two visibility specifiers, a bit offset
3612 to the base class information within the derived class, a reference to
3613 the type for the base class, and a terminating semicolon.
3615 A typical example, with two base classes, would be "!2,020,19;0264,21;".
3617 Baseclass information marker __________________|| | | | | | |
3618 Number of baseclasses __________________________| | | | | | |
3619 Visibility specifiers (2) ________________________| | | | | |
3620 Offset in bits from start of class _________________| | | | |
3621 Type number for base class ___________________________| | | |
3622 Visibility specifiers (2) _______________________________| | |
3623 Offset in bits from start of class ________________________| |
3624 Type number of base class ____________________________________|
3626 Return 1 for success, 0 for (error-type-inducing) failure. */
3632 read_baseclasses (struct field_info
*fip
, char **pp
, struct type
*type
,
3633 struct objfile
*objfile
)
3636 struct nextfield
*new;
3644 /* Skip the '!' baseclass information marker. */
3648 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3651 TYPE_N_BASECLASSES (type
) = read_huge_number (pp
, ',', &nbits
);
3657 /* Some stupid compilers have trouble with the following, so break
3658 it up into simpler expressions. */
3659 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*)
3660 TYPE_ALLOC (type
, B_BYTES (TYPE_N_BASECLASSES (type
)));
3663 int num_bytes
= B_BYTES (TYPE_N_BASECLASSES (type
));
3666 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
3667 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
3671 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), TYPE_N_BASECLASSES (type
));
3673 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
3675 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3676 make_cleanup (xfree
, new);
3677 memset (new, 0, sizeof (struct nextfield
));
3678 new->next
= fip
->list
;
3680 FIELD_BITSIZE (new->field
) = 0; /* this should be an unpacked field! */
3682 STABS_CONTINUE (pp
, objfile
);
3686 /* Nothing to do. */
3689 SET_TYPE_FIELD_VIRTUAL (type
, i
);
3692 /* Unknown character. Complain and treat it as non-virtual. */
3694 static struct complaint msg
=
3696 "Unknown virtual character `%c' for baseclass", 0, 0};
3697 complain (&msg
, **pp
);
3702 new->visibility
= *(*pp
)++;
3703 switch (new->visibility
)
3705 case VISIBILITY_PRIVATE
:
3706 case VISIBILITY_PROTECTED
:
3707 case VISIBILITY_PUBLIC
:
3710 /* Bad visibility format. Complain and treat it as
3713 static struct complaint msg
=
3715 "Unknown visibility `%c' for baseclass", 0, 0
3717 complain (&msg
, new->visibility
);
3718 new->visibility
= VISIBILITY_PUBLIC
;
3725 /* The remaining value is the bit offset of the portion of the object
3726 corresponding to this baseclass. Always zero in the absence of
3727 multiple inheritance. */
3729 FIELD_BITPOS (new->field
) = read_huge_number (pp
, ',', &nbits
);
3734 /* The last piece of baseclass information is the type of the
3735 base class. Read it, and remember it's type name as this
3738 new->field
.type
= read_type (pp
, objfile
);
3739 new->field
.name
= type_name_no_tag (new->field
.type
);
3741 /* skip trailing ';' and bump count of number of fields seen */
3750 /* The tail end of stabs for C++ classes that contain a virtual function
3751 pointer contains a tilde, a %, and a type number.
3752 The type number refers to the base class (possibly this class itself) which
3753 contains the vtable pointer for the current class.
3755 This function is called when we have parsed all the method declarations,
3756 so we can look for the vptr base class info. */
3759 read_tilde_fields (struct field_info
*fip
, char **pp
, struct type
*type
,
3760 struct objfile
*objfile
)
3764 STABS_CONTINUE (pp
, objfile
);
3766 /* If we are positioned at a ';', then skip it. */
3776 if (**pp
== '=' || **pp
== '+' || **pp
== '-')
3778 /* Obsolete flags that used to indicate the presence
3779 of constructors and/or destructors. */
3783 /* Read either a '%' or the final ';'. */
3784 if (*(*pp
)++ == '%')
3786 /* The next number is the type number of the base class
3787 (possibly our own class) which supplies the vtable for
3788 this class. Parse it out, and search that class to find
3789 its vtable pointer, and install those into TYPE_VPTR_BASETYPE
3790 and TYPE_VPTR_FIELDNO. */
3795 t
= read_type (pp
, objfile
);
3797 while (*p
!= '\0' && *p
!= ';')
3803 /* Premature end of symbol. */
3807 TYPE_VPTR_BASETYPE (type
) = t
;
3808 if (type
== t
) /* Our own class provides vtbl ptr */
3810 for (i
= TYPE_NFIELDS (t
) - 1;
3811 i
>= TYPE_N_BASECLASSES (t
);
3814 if (!strncmp (TYPE_FIELD_NAME (t
, i
), vptr_name
,
3815 sizeof (vptr_name
) - 1))
3817 TYPE_VPTR_FIELDNO (type
) = i
;
3821 /* Virtual function table field not found. */
3822 complain (&vtbl_notfound_complaint
, TYPE_NAME (type
));
3827 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
3838 attach_fn_fields_to_type (struct field_info
*fip
, register struct type
*type
)
3842 for (n
= TYPE_NFN_FIELDS (type
);
3843 fip
->fnlist
!= NULL
;
3844 fip
->fnlist
= fip
->fnlist
->next
)
3846 --n
; /* Circumvent Sun3 compiler bug */
3847 TYPE_FN_FIELDLISTS (type
)[n
] = fip
->fnlist
->fn_fieldlist
;
3852 /* read cfront class static data.
3853 pp points to string starting with the list of static data
3854 eg: A:ZcA;1@Bpub v2@Bvirpri;__ct__1AFv func__1AFv *sfunc__1AFv ;as__1A ;;
3857 A:ZcA;;foopri__1AFv foopro__1AFv __ct__1AFv __ct__1AFRC1A foopub__1AFv ;;;
3862 read_cfront_static_fields (struct field_info
*fip
, char **pp
, struct type
*type
,
3863 struct objfile
*objfile
)
3865 struct nextfield
*new;
3868 struct symbol
*ref_static
= 0;
3870 if (**pp
== ';') /* no static data; return */
3876 /* Process each field in the list until we find the terminating ";" */
3878 /* eg: p = "as__1A ;;;" */
3879 STABS_CONTINUE (pp
, objfile
); /* handle \\ */
3880 while (**pp
!= ';' && (sname
= get_substring (pp
, ' '), sname
))
3882 ref_static
= lookup_symbol (sname
, 0, VAR_NAMESPACE
, 0, 0); /*demangled_name */
3885 static struct complaint msg
=
3887 Unable to find symbol for static data field %s\n",
3889 complain (&msg
, sname
);
3892 stype
= SYMBOL_TYPE (ref_static
);
3894 /* allocate a new fip */
3895 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3896 make_cleanup (xfree
, new);
3897 memset (new, 0, sizeof (struct nextfield
));
3898 new->next
= fip
->list
;
3901 /* set visibility */
3902 /* FIXME! no way to tell visibility from stabs??? */
3903 new->visibility
= VISIBILITY_PUBLIC
;
3905 /* set field info into fip */
3906 fip
->list
->field
.type
= stype
;
3908 /* set bitpos & bitsize */
3909 SET_FIELD_PHYSNAME (fip
->list
->field
, savestring (sname
, strlen (sname
)));
3911 /* set name field */
3912 /* The following is code to work around cfront generated stabs.
3913 The stabs contains full mangled name for each field.
3914 We try to demangle the name and extract the field name out of it.
3919 dem
= cplus_demangle (sname
, DMGL_ANSI
| DMGL_PARAMS
);
3922 dem_p
= strrchr (dem
, ':');
3923 if (dem_p
!= 0 && *(dem_p
- 1) == ':')
3925 fip
->list
->field
.name
=
3926 obsavestring (dem_p
, strlen (dem_p
), &objfile
->type_obstack
);
3930 fip
->list
->field
.name
=
3931 obsavestring (sname
, strlen (sname
), &objfile
->type_obstack
);
3933 } /* end of code for cfront work around */
3934 } /* loop again for next static field */
3938 /* Copy structure fields to fip so attach_fields_to_type will work.
3939 type has already been created with the initial instance data fields.
3940 Now we want to be able to add the other members to the class,
3941 so we want to add them back to the fip and reattach them again
3942 once we have collected all the class members. */
3945 copy_cfront_struct_fields (struct field_info
*fip
, struct type
*type
,
3946 struct objfile
*objfile
)
3948 int nfields
= TYPE_NFIELDS (type
);
3950 struct nextfield
*new;
3952 /* Copy the fields into the list of fips and reset the types
3953 to remove the old fields */
3955 for (i
= 0; i
< nfields
; i
++)
3957 /* allocate a new fip */
3958 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3959 make_cleanup (xfree
, new);
3960 memset (new, 0, sizeof (struct nextfield
));
3961 new->next
= fip
->list
;
3964 /* copy field info into fip */
3965 new->field
= TYPE_FIELD (type
, i
);
3966 /* set visibility */
3967 if (TYPE_FIELD_PROTECTED (type
, i
))
3968 new->visibility
= VISIBILITY_PROTECTED
;
3969 else if (TYPE_FIELD_PRIVATE (type
, i
))
3970 new->visibility
= VISIBILITY_PRIVATE
;
3972 new->visibility
= VISIBILITY_PUBLIC
;
3974 /* Now delete the fields from the type since we will be
3975 allocing new space once we get the rest of the fields
3976 in attach_fields_to_type.
3977 The pointer TYPE_FIELDS(type) is left dangling but should
3978 be freed later by objstack_free */
3979 TYPE_FIELDS (type
) = 0;
3980 TYPE_NFIELDS (type
) = 0;
3985 /* Create the vector of fields, and record how big it is.
3986 We need this info to record proper virtual function table information
3987 for this class's virtual functions. */
3990 attach_fields_to_type (struct field_info
*fip
, register struct type
*type
,
3991 struct objfile
*objfile
)
3993 register int nfields
= 0;
3994 register int non_public_fields
= 0;
3995 register struct nextfield
*scan
;
3997 /* Count up the number of fields that we have, as well as taking note of
3998 whether or not there are any non-public fields, which requires us to
3999 allocate and build the private_field_bits and protected_field_bits
4002 for (scan
= fip
->list
; scan
!= NULL
; scan
= scan
->next
)
4005 if (scan
->visibility
!= VISIBILITY_PUBLIC
)
4007 non_public_fields
++;
4011 /* Now we know how many fields there are, and whether or not there are any
4012 non-public fields. Record the field count, allocate space for the
4013 array of fields, and create blank visibility bitfields if necessary. */
4015 TYPE_NFIELDS (type
) = nfields
;
4016 TYPE_FIELDS (type
) = (struct field
*)
4017 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
4018 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
4020 if (non_public_fields
)
4022 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
4024 TYPE_FIELD_PRIVATE_BITS (type
) =
4025 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
4026 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
4028 TYPE_FIELD_PROTECTED_BITS (type
) =
4029 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
4030 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
4032 TYPE_FIELD_IGNORE_BITS (type
) =
4033 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
4034 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
4037 /* Copy the saved-up fields into the field vector. Start from the head
4038 of the list, adding to the tail of the field array, so that they end
4039 up in the same order in the array in which they were added to the list. */
4041 while (nfields
-- > 0)
4043 TYPE_FIELD (type
, nfields
) = fip
->list
->field
;
4044 switch (fip
->list
->visibility
)
4046 case VISIBILITY_PRIVATE
:
4047 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
4050 case VISIBILITY_PROTECTED
:
4051 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
4054 case VISIBILITY_IGNORE
:
4055 SET_TYPE_FIELD_IGNORE (type
, nfields
);
4058 case VISIBILITY_PUBLIC
:
4062 /* Unknown visibility. Complain and treat it as public. */
4064 static struct complaint msg
=
4066 "Unknown visibility `%c' for field", 0, 0};
4067 complain (&msg
, fip
->list
->visibility
);
4071 fip
->list
= fip
->list
->next
;
4076 /* Read the description of a structure (or union type) and return an object
4077 describing the type.
4079 PP points to a character pointer that points to the next unconsumed token
4080 in the the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
4081 *PP will point to "4a:1,0,32;;".
4083 TYPE points to an incomplete type that needs to be filled in.
4085 OBJFILE points to the current objfile from which the stabs information is
4086 being read. (Note that it is redundant in that TYPE also contains a pointer
4087 to this same objfile, so it might be a good idea to eliminate it. FIXME).
4090 static struct type
*
4091 read_struct_type (char **pp
, struct type
*type
, struct objfile
*objfile
)
4093 struct cleanup
*back_to
;
4094 struct field_info fi
;
4099 back_to
= make_cleanup (null_cleanup
, 0);
4101 INIT_CPLUS_SPECIFIC (type
);
4102 TYPE_FLAGS (type
) &= ~TYPE_FLAG_STUB
;
4104 /* First comes the total size in bytes. */
4108 TYPE_LENGTH (type
) = read_huge_number (pp
, 0, &nbits
);
4110 return error_type (pp
, objfile
);
4113 /* Now read the baseclasses, if any, read the regular C struct or C++
4114 class member fields, attach the fields to the type, read the C++
4115 member functions, attach them to the type, and then read any tilde
4116 field (baseclass specifier for the class holding the main vtable). */
4118 if (!read_baseclasses (&fi
, pp
, type
, objfile
)
4119 || !read_struct_fields (&fi
, pp
, type
, objfile
)
4120 || !attach_fields_to_type (&fi
, type
, objfile
)
4121 || !read_member_functions (&fi
, pp
, type
, objfile
)
4122 || !attach_fn_fields_to_type (&fi
, type
)
4123 || !read_tilde_fields (&fi
, pp
, type
, objfile
))
4125 type
= error_type (pp
, objfile
);
4128 /* Fix up any cv-qualified versions of this type. */
4129 finish_cv_type (type
);
4130 do_cleanups (back_to
);
4134 /* Read a definition of an array type,
4135 and create and return a suitable type object.
4136 Also creates a range type which represents the bounds of that
4139 static struct type
*
4140 read_array_type (register char **pp
, register struct type
*type
,
4141 struct objfile
*objfile
)
4143 struct type
*index_type
, *element_type
, *range_type
;
4148 /* Format of an array type:
4149 "ar<index type>;lower;upper;<array_contents_type>".
4150 OS9000: "arlower,upper;<array_contents_type>".
4152 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
4153 for these, produce a type like float[][]. */
4156 index_type
= builtin_type_int
;
4159 index_type
= read_type (pp
, objfile
);
4161 /* Improper format of array type decl. */
4162 return error_type (pp
, objfile
);
4166 if (!(**pp
>= '0' && **pp
<= '9') && **pp
!= '-')
4171 lower
= read_huge_number (pp
, os9k_stabs
? ',' : ';', &nbits
);
4173 return error_type (pp
, objfile
);
4175 if (!(**pp
>= '0' && **pp
<= '9') && **pp
!= '-')
4180 upper
= read_huge_number (pp
, ';', &nbits
);
4182 return error_type (pp
, objfile
);
4184 element_type
= read_type (pp
, objfile
);
4193 create_range_type ((struct type
*) NULL
, index_type
, lower
, upper
);
4194 type
= create_array_type (type
, element_type
, range_type
);
4200 /* Read a definition of an enumeration type,
4201 and create and return a suitable type object.
4202 Also defines the symbols that represent the values of the type. */
4204 static struct type
*
4205 read_enum_type (register char **pp
, register struct type
*type
,
4206 struct objfile
*objfile
)
4211 register struct symbol
*sym
;
4213 struct pending
**symlist
;
4214 struct pending
*osyms
, *syms
;
4217 int unsigned_enum
= 1;
4220 /* FIXME! The stabs produced by Sun CC merrily define things that ought
4221 to be file-scope, between N_FN entries, using N_LSYM. What's a mother
4222 to do? For now, force all enum values to file scope. */
4223 if (within_function
)
4224 symlist
= &local_symbols
;
4227 symlist
= &file_symbols
;
4229 o_nsyms
= osyms
? osyms
->nsyms
: 0;
4233 /* Size. Perhaps this does not have to be conditionalized on
4234 os9k_stabs (assuming the name of an enum constant can't start
4236 read_huge_number (pp
, 0, &nbits
);
4238 return error_type (pp
, objfile
);
4241 /* The aix4 compiler emits an extra field before the enum members;
4242 my guess is it's a type of some sort. Just ignore it. */
4245 /* Skip over the type. */
4249 /* Skip over the colon. */
4253 /* Read the value-names and their values.
4254 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
4255 A semicolon or comma instead of a NAME means the end. */
4256 while (**pp
&& **pp
!= ';' && **pp
!= ',')
4258 STABS_CONTINUE (pp
, objfile
);
4262 name
= obsavestring (*pp
, p
- *pp
, &objfile
->symbol_obstack
);
4264 n
= read_huge_number (pp
, ',', &nbits
);
4266 return error_type (pp
, objfile
);
4268 sym
= (struct symbol
*)
4269 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct symbol
));
4270 memset (sym
, 0, sizeof (struct symbol
));
4271 SYMBOL_NAME (sym
) = name
;
4272 SYMBOL_LANGUAGE (sym
) = current_subfile
->language
;
4273 SYMBOL_CLASS (sym
) = LOC_CONST
;
4274 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4275 SYMBOL_VALUE (sym
) = n
;
4278 add_symbol_to_list (sym
, symlist
);
4283 (*pp
)++; /* Skip the semicolon. */
4285 /* Now fill in the fields of the type-structure. */
4287 TYPE_LENGTH (type
) = TARGET_INT_BIT
/ HOST_CHAR_BIT
;
4288 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
4289 TYPE_FLAGS (type
) &= ~TYPE_FLAG_STUB
;
4291 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
4292 TYPE_NFIELDS (type
) = nsyms
;
4293 TYPE_FIELDS (type
) = (struct field
*)
4294 TYPE_ALLOC (type
, sizeof (struct field
) * nsyms
);
4295 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nsyms
);
4297 /* Find the symbols for the values and put them into the type.
4298 The symbols can be found in the symlist that we put them on
4299 to cause them to be defined. osyms contains the old value
4300 of that symlist; everything up to there was defined by us. */
4301 /* Note that we preserve the order of the enum constants, so
4302 that in something like "enum {FOO, LAST_THING=FOO}" we print
4303 FOO, not LAST_THING. */
4305 for (syms
= *symlist
, n
= nsyms
- 1; syms
; syms
= syms
->next
)
4307 int last
= syms
== osyms
? o_nsyms
: 0;
4308 int j
= syms
->nsyms
;
4309 for (; --j
>= last
; --n
)
4311 struct symbol
*xsym
= syms
->symbol
[j
];
4312 SYMBOL_TYPE (xsym
) = type
;
4313 TYPE_FIELD_NAME (type
, n
) = SYMBOL_NAME (xsym
);
4314 TYPE_FIELD_BITPOS (type
, n
) = SYMBOL_VALUE (xsym
);
4315 TYPE_FIELD_BITSIZE (type
, n
) = 0;
4324 /* Sun's ACC uses a somewhat saner method for specifying the builtin
4325 typedefs in every file (for int, long, etc):
4327 type = b <signed> <width> <format type>; <offset>; <nbits>
4329 optional format type = c or b for char or boolean.
4330 offset = offset from high order bit to start bit of type.
4331 width is # bytes in object of this type, nbits is # bits in type.
4333 The width/offset stuff appears to be for small objects stored in
4334 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
4337 static struct type
*
4338 read_sun_builtin_type (char **pp
, int typenums
[2], struct objfile
*objfile
)
4343 enum type_code code
= TYPE_CODE_INT
;
4354 return error_type (pp
, objfile
);
4358 /* For some odd reason, all forms of char put a c here. This is strange
4359 because no other type has this honor. We can safely ignore this because
4360 we actually determine 'char'acterness by the number of bits specified in
4362 Boolean forms, e.g Fortran logical*X, put a b here. */
4366 else if (**pp
== 'b')
4368 code
= TYPE_CODE_BOOL
;
4372 /* The first number appears to be the number of bytes occupied
4373 by this type, except that unsigned short is 4 instead of 2.
4374 Since this information is redundant with the third number,
4375 we will ignore it. */
4376 read_huge_number (pp
, ';', &nbits
);
4378 return error_type (pp
, objfile
);
4380 /* The second number is always 0, so ignore it too. */
4381 read_huge_number (pp
, ';', &nbits
);
4383 return error_type (pp
, objfile
);
4385 /* The third number is the number of bits for this type. */
4386 type_bits
= read_huge_number (pp
, 0, &nbits
);
4388 return error_type (pp
, objfile
);
4389 /* The type *should* end with a semicolon. If it are embedded
4390 in a larger type the semicolon may be the only way to know where
4391 the type ends. If this type is at the end of the stabstring we
4392 can deal with the omitted semicolon (but we don't have to like
4393 it). Don't bother to complain(), Sun's compiler omits the semicolon
4399 return init_type (TYPE_CODE_VOID
, 1,
4400 signed_type
? 0 : TYPE_FLAG_UNSIGNED
, (char *) NULL
,
4403 return init_type (code
,
4404 type_bits
/ TARGET_CHAR_BIT
,
4405 signed_type
? 0 : TYPE_FLAG_UNSIGNED
, (char *) NULL
,
4409 static struct type
*
4410 read_sun_floating_type (char **pp
, int typenums
[2], struct objfile
*objfile
)
4416 /* The first number has more details about the type, for example
4418 details
= read_huge_number (pp
, ';', &nbits
);
4420 return error_type (pp
, objfile
);
4422 /* The second number is the number of bytes occupied by this type */
4423 nbytes
= read_huge_number (pp
, ';', &nbits
);
4425 return error_type (pp
, objfile
);
4427 if (details
== NF_COMPLEX
|| details
== NF_COMPLEX16
4428 || details
== NF_COMPLEX32
)
4429 /* This is a type we can't handle, but we do know the size.
4430 We also will be able to give it a name. */
4431 return init_type (TYPE_CODE_COMPLEX
, nbytes
, 0, NULL
, objfile
);
4433 return init_type (TYPE_CODE_FLT
, nbytes
, 0, NULL
, objfile
);
4436 /* Read a number from the string pointed to by *PP.
4437 The value of *PP is advanced over the number.
4438 If END is nonzero, the character that ends the
4439 number must match END, or an error happens;
4440 and that character is skipped if it does match.
4441 If END is zero, *PP is left pointing to that character.
4443 If the number fits in a long, set *BITS to 0 and return the value.
4444 If not, set *BITS to be the number of bits in the number and return 0.
4446 If encounter garbage, set *BITS to -1 and return 0. */
4449 read_huge_number (char **pp
, int end
, int *bits
)
4466 /* Leading zero means octal. GCC uses this to output values larger
4467 than an int (because that would be hard in decimal). */
4475 upper_limit
= ULONG_MAX
/ radix
;
4477 upper_limit
= LONG_MAX
/ radix
;
4479 while ((c
= *p
++) >= '0' && c
< ('0' + radix
))
4481 if (n
<= upper_limit
)
4484 n
+= c
- '0'; /* FIXME this overflows anyway */
4489 /* This depends on large values being output in octal, which is
4496 /* Ignore leading zeroes. */
4500 else if (c
== '2' || c
== '3')
4526 /* Large decimal constants are an error (because it is hard to
4527 count how many bits are in them). */
4533 /* -0x7f is the same as 0x80. So deal with it by adding one to
4534 the number of bits. */
4546 /* It's *BITS which has the interesting information. */
4550 static struct type
*
4551 read_range_type (char **pp
, int typenums
[2], struct objfile
*objfile
)
4553 char *orig_pp
= *pp
;
4558 struct type
*result_type
;
4559 struct type
*index_type
= NULL
;
4561 /* First comes a type we are a subrange of.
4562 In C it is usually 0, 1 or the type being defined. */
4563 if (read_type_number (pp
, rangenums
) != 0)
4564 return error_type (pp
, objfile
);
4565 self_subrange
= (rangenums
[0] == typenums
[0] &&
4566 rangenums
[1] == typenums
[1]);
4571 index_type
= read_type (pp
, objfile
);
4574 /* A semicolon should now follow; skip it. */
4578 /* The remaining two operands are usually lower and upper bounds
4579 of the range. But in some special cases they mean something else. */
4580 n2
= read_huge_number (pp
, ';', &n2bits
);
4581 n3
= read_huge_number (pp
, ';', &n3bits
);
4583 if (n2bits
== -1 || n3bits
== -1)
4584 return error_type (pp
, objfile
);
4587 goto handle_true_range
;
4589 /* If limits are huge, must be large integral type. */
4590 if (n2bits
!= 0 || n3bits
!= 0)
4592 char got_signed
= 0;
4593 char got_unsigned
= 0;
4594 /* Number of bits in the type. */
4597 /* Range from 0 to <large number> is an unsigned large integral type. */
4598 if ((n2bits
== 0 && n2
== 0) && n3bits
!= 0)
4603 /* Range from <large number> to <large number>-1 is a large signed
4604 integral type. Take care of the case where <large number> doesn't
4605 fit in a long but <large number>-1 does. */
4606 else if ((n2bits
!= 0 && n3bits
!= 0 && n2bits
== n3bits
+ 1)
4607 || (n2bits
!= 0 && n3bits
== 0
4608 && (n2bits
== sizeof (long) * HOST_CHAR_BIT
)
4615 if (got_signed
|| got_unsigned
)
4617 return init_type (TYPE_CODE_INT
, nbits
/ TARGET_CHAR_BIT
,
4618 got_unsigned
? TYPE_FLAG_UNSIGNED
: 0, NULL
,
4622 return error_type (pp
, objfile
);
4625 /* A type defined as a subrange of itself, with bounds both 0, is void. */
4626 if (self_subrange
&& n2
== 0 && n3
== 0)
4627 return init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
4629 /* If n3 is zero and n2 is positive, we want a floating type, and n2
4630 is the width in bytes.
4632 Fortran programs appear to use this for complex types also. To
4633 distinguish between floats and complex, g77 (and others?) seem
4634 to use self-subranges for the complexes, and subranges of int for
4637 Also note that for complexes, g77 sets n2 to the size of one of
4638 the member floats, not the whole complex beast. My guess is that
4639 this was to work well with pre-COMPLEX versions of gdb. */
4641 if (n3
== 0 && n2
> 0)
4643 struct type
*float_type
4644 = init_type (TYPE_CODE_FLT
, n2
, 0, NULL
, objfile
);
4648 struct type
*complex_type
=
4649 init_type (TYPE_CODE_COMPLEX
, 2 * n2
, 0, NULL
, objfile
);
4650 TYPE_TARGET_TYPE (complex_type
) = float_type
;
4651 return complex_type
;
4657 /* If the upper bound is -1, it must really be an unsigned int. */
4659 else if (n2
== 0 && n3
== -1)
4661 /* It is unsigned int or unsigned long. */
4662 /* GCC 2.3.3 uses this for long long too, but that is just a GDB 3.5
4663 compatibility hack. */
4664 return init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
4665 TYPE_FLAG_UNSIGNED
, NULL
, objfile
);
4668 /* Special case: char is defined (Who knows why) as a subrange of
4669 itself with range 0-127. */
4670 else if (self_subrange
&& n2
== 0 && n3
== 127)
4671 return init_type (TYPE_CODE_INT
, 1, 0, NULL
, objfile
);
4673 else if (current_symbol
&& SYMBOL_LANGUAGE (current_symbol
) == language_chill
4675 goto handle_true_range
;
4677 /* We used to do this only for subrange of self or subrange of int. */
4680 /* -1 is used for the upper bound of (4 byte) "unsigned int" and
4681 "unsigned long", and we already checked for that,
4682 so don't need to test for it here. */
4685 /* n3 actually gives the size. */
4686 return init_type (TYPE_CODE_INT
, -n3
, TYPE_FLAG_UNSIGNED
,
4689 /* Is n3 == 2**(8n)-1 for some integer n? Then it's an
4690 unsigned n-byte integer. But do require n to be a power of
4691 two; we don't want 3- and 5-byte integers flying around. */
4697 for (bytes
= 0; (bits
& 0xff) == 0xff; bytes
++)
4700 && ((bytes
- 1) & bytes
) == 0) /* "bytes is a power of two" */
4701 return init_type (TYPE_CODE_INT
, bytes
, TYPE_FLAG_UNSIGNED
, NULL
,
4705 /* I think this is for Convex "long long". Since I don't know whether
4706 Convex sets self_subrange, I also accept that particular size regardless
4707 of self_subrange. */
4708 else if (n3
== 0 && n2
< 0
4710 || n2
== -TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
))
4711 return init_type (TYPE_CODE_INT
, -n2
, 0, NULL
, objfile
);
4712 else if (n2
== -n3
- 1)
4715 return init_type (TYPE_CODE_INT
, 1, 0, NULL
, objfile
);
4717 return init_type (TYPE_CODE_INT
, 2, 0, NULL
, objfile
);
4718 if (n3
== 0x7fffffff)
4719 return init_type (TYPE_CODE_INT
, 4, 0, NULL
, objfile
);
4722 /* We have a real range type on our hands. Allocate space and
4723 return a real pointer. */
4727 index_type
= builtin_type_int
;
4729 index_type
= *dbx_lookup_type (rangenums
);
4730 if (index_type
== NULL
)
4732 /* Does this actually ever happen? Is that why we are worrying
4733 about dealing with it rather than just calling error_type? */
4735 static struct type
*range_type_index
;
4737 complain (&range_type_base_complaint
, rangenums
[1]);
4738 if (range_type_index
== NULL
)
4740 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
4741 0, "range type index type", NULL
);
4742 index_type
= range_type_index
;
4745 result_type
= create_range_type ((struct type
*) NULL
, index_type
, n2
, n3
);
4746 return (result_type
);
4749 /* Read in an argument list. This is a list of types, separated by commas
4750 and terminated with END. Return the list of types read in, or (struct type
4751 **)-1 if there is an error. */
4753 static struct type
**
4754 read_args (char **pp
, int end
, struct objfile
*objfile
)
4756 /* FIXME! Remove this arbitrary limit! */
4757 struct type
*types
[1024], **rval
; /* allow for fns of 1023 parameters */
4763 /* Invalid argument list: no ','. */
4764 return (struct type
**) -1;
4766 STABS_CONTINUE (pp
, objfile
);
4767 types
[n
++] = read_type (pp
, objfile
);
4769 (*pp
)++; /* get past `end' (the ':' character) */
4773 rval
= (struct type
**) xmalloc (2 * sizeof (struct type
*));
4775 else if (TYPE_CODE (types
[n
- 1]) != TYPE_CODE_VOID
)
4777 rval
= (struct type
**) xmalloc ((n
+ 1) * sizeof (struct type
*));
4778 memset (rval
+ n
, 0, sizeof (struct type
*));
4782 rval
= (struct type
**) xmalloc (n
* sizeof (struct type
*));
4784 memcpy (rval
, types
, n
* sizeof (struct type
*));
4788 /* Common block handling. */
4790 /* List of symbols declared since the last BCOMM. This list is a tail
4791 of local_symbols. When ECOMM is seen, the symbols on the list
4792 are noted so their proper addresses can be filled in later,
4793 using the common block base address gotten from the assembler
4796 static struct pending
*common_block
;
4797 static int common_block_i
;
4799 /* Name of the current common block. We get it from the BCOMM instead of the
4800 ECOMM to match IBM documentation (even though IBM puts the name both places
4801 like everyone else). */
4802 static char *common_block_name
;
4804 /* Process a N_BCOMM symbol. The storage for NAME is not guaranteed
4805 to remain after this function returns. */
4808 common_block_start (char *name
, struct objfile
*objfile
)
4810 if (common_block_name
!= NULL
)
4812 static struct complaint msg
=
4814 "Invalid symbol data: common block within common block",
4818 common_block
= local_symbols
;
4819 common_block_i
= local_symbols
? local_symbols
->nsyms
: 0;
4820 common_block_name
= obsavestring (name
, strlen (name
),
4821 &objfile
->symbol_obstack
);
4824 /* Process a N_ECOMM symbol. */
4827 common_block_end (struct objfile
*objfile
)
4829 /* Symbols declared since the BCOMM are to have the common block
4830 start address added in when we know it. common_block and
4831 common_block_i point to the first symbol after the BCOMM in
4832 the local_symbols list; copy the list and hang it off the
4833 symbol for the common block name for later fixup. */
4836 struct pending
*new = 0;
4837 struct pending
*next
;
4840 if (common_block_name
== NULL
)
4842 static struct complaint msg
=
4843 {"ECOMM symbol unmatched by BCOMM", 0, 0};
4848 sym
= (struct symbol
*)
4849 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct symbol
));
4850 memset (sym
, 0, sizeof (struct symbol
));
4851 /* Note: common_block_name already saved on symbol_obstack */
4852 SYMBOL_NAME (sym
) = common_block_name
;
4853 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
4855 /* Now we copy all the symbols which have been defined since the BCOMM. */
4857 /* Copy all the struct pendings before common_block. */
4858 for (next
= local_symbols
;
4859 next
!= NULL
&& next
!= common_block
;
4862 for (j
= 0; j
< next
->nsyms
; j
++)
4863 add_symbol_to_list (next
->symbol
[j
], &new);
4866 /* Copy however much of COMMON_BLOCK we need. If COMMON_BLOCK is
4867 NULL, it means copy all the local symbols (which we already did
4870 if (common_block
!= NULL
)
4871 for (j
= common_block_i
; j
< common_block
->nsyms
; j
++)
4872 add_symbol_to_list (common_block
->symbol
[j
], &new);
4874 SYMBOL_TYPE (sym
) = (struct type
*) new;
4876 /* Should we be putting local_symbols back to what it was?
4879 i
= hashname (SYMBOL_NAME (sym
));
4880 SYMBOL_VALUE_CHAIN (sym
) = global_sym_chain
[i
];
4881 global_sym_chain
[i
] = sym
;
4882 common_block_name
= NULL
;
4885 /* Add a common block's start address to the offset of each symbol
4886 declared to be in it (by being between a BCOMM/ECOMM pair that uses
4887 the common block name). */
4890 fix_common_block (struct symbol
*sym
, int valu
)
4892 struct pending
*next
= (struct pending
*) SYMBOL_TYPE (sym
);
4893 for (; next
; next
= next
->next
)
4896 for (j
= next
->nsyms
- 1; j
>= 0; j
--)
4897 SYMBOL_VALUE_ADDRESS (next
->symbol
[j
]) += valu
;
4903 /* What about types defined as forward references inside of a small lexical
4905 /* Add a type to the list of undefined types to be checked through
4906 once this file has been read in. */
4909 add_undefined_type (struct type
*type
)
4911 if (undef_types_length
== undef_types_allocated
)
4913 undef_types_allocated
*= 2;
4914 undef_types
= (struct type
**)
4915 xrealloc ((char *) undef_types
,
4916 undef_types_allocated
* sizeof (struct type
*));
4918 undef_types
[undef_types_length
++] = type
;
4921 /* Go through each undefined type, see if it's still undefined, and fix it
4922 up if possible. We have two kinds of undefined types:
4924 TYPE_CODE_ARRAY: Array whose target type wasn't defined yet.
4925 Fix: update array length using the element bounds
4926 and the target type's length.
4927 TYPE_CODE_STRUCT, TYPE_CODE_UNION: Structure whose fields were not
4928 yet defined at the time a pointer to it was made.
4929 Fix: Do a full lookup on the struct/union tag. */
4931 cleanup_undefined_types (void)
4935 for (type
= undef_types
; type
< undef_types
+ undef_types_length
; type
++)
4937 switch (TYPE_CODE (*type
))
4940 case TYPE_CODE_STRUCT
:
4941 case TYPE_CODE_UNION
:
4942 case TYPE_CODE_ENUM
:
4944 /* Check if it has been defined since. Need to do this here
4945 as well as in check_typedef to deal with the (legitimate in
4946 C though not C++) case of several types with the same name
4947 in different source files. */
4948 if (TYPE_STUB (*type
))
4950 struct pending
*ppt
;
4952 /* Name of the type, without "struct" or "union" */
4953 char *typename
= TYPE_TAG_NAME (*type
);
4955 if (typename
== NULL
)
4957 static struct complaint msg
=
4958 {"need a type name", 0, 0};
4962 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
4964 for (i
= 0; i
< ppt
->nsyms
; i
++)
4966 struct symbol
*sym
= ppt
->symbol
[i
];
4968 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
4969 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
4970 && (TYPE_CODE (SYMBOL_TYPE (sym
)) ==
4972 && STREQ (SYMBOL_NAME (sym
), typename
))
4974 memcpy (*type
, SYMBOL_TYPE (sym
),
4975 sizeof (struct type
));
4985 static struct complaint msg
=
4987 GDB internal error. cleanup_undefined_types with bad type %d.", 0, 0};
4988 complain (&msg
, TYPE_CODE (*type
));
4994 undef_types_length
= 0;
4997 /* Scan through all of the global symbols defined in the object file,
4998 assigning values to the debugging symbols that need to be assigned
4999 to. Get these symbols from the minimal symbol table. */
5002 scan_file_globals (struct objfile
*objfile
)
5005 struct minimal_symbol
*msymbol
;
5006 struct symbol
*sym
, *prev
, *rsym
;
5007 struct objfile
*resolve_objfile
;
5009 /* SVR4 based linkers copy referenced global symbols from shared
5010 libraries to the main executable.
5011 If we are scanning the symbols for a shared library, try to resolve
5012 them from the minimal symbols of the main executable first. */
5014 if (symfile_objfile
&& objfile
!= symfile_objfile
)
5015 resolve_objfile
= symfile_objfile
;
5017 resolve_objfile
= objfile
;
5021 /* Avoid expensive loop through all minimal symbols if there are
5022 no unresolved symbols. */
5023 for (hash
= 0; hash
< HASHSIZE
; hash
++)
5025 if (global_sym_chain
[hash
])
5028 if (hash
>= HASHSIZE
)
5031 for (msymbol
= resolve_objfile
->msymbols
;
5032 msymbol
&& SYMBOL_NAME (msymbol
) != NULL
;
5037 /* Skip static symbols. */
5038 switch (MSYMBOL_TYPE (msymbol
))
5050 /* Get the hash index and check all the symbols
5051 under that hash index. */
5053 hash
= hashname (SYMBOL_NAME (msymbol
));
5055 for (sym
= global_sym_chain
[hash
]; sym
;)
5057 if (SYMBOL_NAME (msymbol
)[0] == SYMBOL_NAME (sym
)[0] &&
5058 STREQ (SYMBOL_NAME (msymbol
) + 1, SYMBOL_NAME (sym
) + 1))
5061 struct alias_list
*aliases
;
5063 /* Splice this symbol out of the hash chain and
5064 assign the value we have to it. */
5067 SYMBOL_VALUE_CHAIN (prev
) = SYMBOL_VALUE_CHAIN (sym
);
5071 global_sym_chain
[hash
] = SYMBOL_VALUE_CHAIN (sym
);
5074 /* Check to see whether we need to fix up a common block. */
5075 /* Note: this code might be executed several times for
5076 the same symbol if there are multiple references. */
5078 /* If symbol has aliases, do minimal symbol fixups for each.
5079 These live aliases/references weren't added to
5080 global_sym_chain hash but may also need to be fixed up. */
5081 /* FIXME: Maybe should have added aliases to the global chain, resolved symbol name, then treated aliases as normal
5082 symbols? Still, we wouldn't want to add_to_list. */
5083 /* Now do the same for each alias of this symbol */
5085 aliases
= SYMBOL_ALIASES (sym
);
5088 if (SYMBOL_CLASS (rsym
) == LOC_BLOCK
)
5090 fix_common_block (rsym
,
5091 SYMBOL_VALUE_ADDRESS (msymbol
));
5095 SYMBOL_VALUE_ADDRESS (rsym
)
5096 = SYMBOL_VALUE_ADDRESS (msymbol
);
5098 SYMBOL_SECTION (rsym
) = SYMBOL_SECTION (msymbol
);
5101 rsym
= aliases
->sym
;
5102 aliases
= aliases
->next
;
5111 sym
= SYMBOL_VALUE_CHAIN (prev
);
5115 sym
= global_sym_chain
[hash
];
5121 sym
= SYMBOL_VALUE_CHAIN (sym
);
5125 if (resolve_objfile
== objfile
)
5127 resolve_objfile
= objfile
;
5130 /* Change the storage class of any remaining unresolved globals to
5131 LOC_UNRESOLVED and remove them from the chain. */
5132 for (hash
= 0; hash
< HASHSIZE
; hash
++)
5134 sym
= global_sym_chain
[hash
];
5138 sym
= SYMBOL_VALUE_CHAIN (sym
);
5140 /* Change the symbol address from the misleading chain value
5142 SYMBOL_VALUE_ADDRESS (prev
) = 0;
5144 /* Complain about unresolved common block symbols. */
5145 if (SYMBOL_CLASS (prev
) == LOC_STATIC
)
5146 SYMBOL_CLASS (prev
) = LOC_UNRESOLVED
;
5148 complain (&unresolved_sym_chain_complaint
,
5149 objfile
->name
, SYMBOL_NAME (prev
));
5152 memset (global_sym_chain
, 0, sizeof (global_sym_chain
));
5155 /* Initialize anything that needs initializing when starting to read
5156 a fresh piece of a symbol file, e.g. reading in the stuff corresponding
5160 stabsread_init (void)
5164 /* Initialize anything that needs initializing when a completely new
5165 symbol file is specified (not just adding some symbols from another
5166 file, e.g. a shared library). */
5169 stabsread_new_init (void)
5171 /* Empty the hash table of global syms looking for values. */
5172 memset (global_sym_chain
, 0, sizeof (global_sym_chain
));
5175 /* Initialize anything that needs initializing at the same time as
5176 start_symtab() is called. */
5181 global_stabs
= NULL
; /* AIX COFF */
5182 /* Leave FILENUM of 0 free for builtin types and this file's types. */
5183 n_this_object_header_files
= 1;
5184 type_vector_length
= 0;
5185 type_vector
= (struct type
**) 0;
5187 /* FIXME: If common_block_name is not already NULL, we should complain(). */
5188 common_block_name
= NULL
;
5193 /* Call after end_symtab() */
5200 xfree (type_vector
);
5203 type_vector_length
= 0;
5204 previous_stab_code
= 0;
5208 finish_global_stabs (struct objfile
*objfile
)
5212 patch_block_stabs (global_symbols
, global_stabs
, objfile
);
5213 xfree (global_stabs
);
5214 global_stabs
= NULL
;
5218 /* Initializer for this module */
5221 _initialize_stabsread (void)
5223 undef_types_allocated
= 20;
5224 undef_types_length
= 0;
5225 undef_types
= (struct type
**)
5226 xmalloc (undef_types_allocated
* sizeof (struct type
*));