1 /* Support routines for decoding "stabs" debugging information format.
2 Copyright 1986, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 1998
3 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* Support routines for reading and decoding debugging information in
23 the "stabs" format. This format is used with many systems that use
24 the a.out object file format, as well as some systems that use
25 COFF or ELF where the stabs data is placed in a special section.
26 Avoid placing any object file format specific code in this file. */
29 #include "gdb_string.h"
34 #include "expression.h"
37 #include "aout/stab_gnu.h" /* We always use GNU stabs, not native */
39 #include "aout/aout64.h"
40 #include "gdb-stabs.h"
42 #include "complaints.h"
48 /* Ask stabsread.h to define the vars it normally declares `extern'. */
51 #include "stabsread.h" /* Our own declarations */
54 extern void _initialize_stabsread (void);
56 /* The routines that read and process a complete stabs for a C struct or
57 C++ class pass lists of data member fields and lists of member function
58 fields in an instance of a field_info structure, as defined below.
59 This is part of some reorganization of low level C++ support and is
60 expected to eventually go away... (FIXME) */
66 struct nextfield
*next
;
68 /* This is the raw visibility from the stab. It is not checked
69 for being one of the visibilities we recognize, so code which
70 examines this field better be able to deal. */
76 struct next_fnfieldlist
78 struct next_fnfieldlist
*next
;
79 struct fn_fieldlist fn_fieldlist
;
85 read_one_struct_field (struct field_info
*, char **, char *,
86 struct type
*, struct objfile
*);
88 static char *get_substring (char **, int);
90 static struct type
*dbx_alloc_type (int[2], struct objfile
*);
92 static long read_huge_number (char **, int, int *);
94 static struct type
*error_type (char **, struct objfile
*);
97 patch_block_stabs (struct pending
*, struct pending_stabs
*,
100 static void fix_common_block (struct symbol
*, int);
102 static int read_type_number (char **, int *);
104 static struct type
*read_range_type (char **, int[2], struct objfile
*);
106 static struct type
*read_sun_builtin_type (char **, int[2], struct objfile
*);
108 static struct type
*read_sun_floating_type (char **, int[2],
111 static struct type
*read_enum_type (char **, struct type
*, struct objfile
*);
113 static struct type
*rs6000_builtin_type (int);
116 read_member_functions (struct field_info
*, char **, struct type
*,
120 read_struct_fields (struct field_info
*, char **, struct type
*,
124 read_baseclasses (struct field_info
*, char **, struct type
*,
128 read_tilde_fields (struct field_info
*, char **, struct type
*,
131 static int attach_fn_fields_to_type (struct field_info
*, struct type
*);
134 attach_fields_to_type (struct field_info
*, struct type
*, struct objfile
*);
136 static struct type
*read_struct_type (char **, struct type
*,
139 static struct type
*read_array_type (char **, struct type
*,
142 static struct type
**read_args (char **, int, struct objfile
*);
145 read_cpp_abbrev (struct field_info
*, char **, struct type
*,
148 /* new functions added for cfront support */
151 copy_cfront_struct_fields (struct field_info
*, struct type
*,
154 static char *get_cfront_method_physname (char *);
157 read_cfront_baseclasses (struct field_info
*, char **,
158 struct type
*, struct objfile
*);
161 read_cfront_static_fields (struct field_info
*, char **,
162 struct type
*, struct objfile
*);
164 read_cfront_member_functions (struct field_info
*, char **,
165 struct type
*, struct objfile
*);
167 /* end new functions added for cfront support */
170 add_live_range (struct objfile
*, struct symbol
*, CORE_ADDR
, CORE_ADDR
);
172 static int resolve_live_range (struct objfile
*, struct symbol
*, char *);
174 static int process_reference (char **string
);
176 static CORE_ADDR
ref_search_value (int refnum
);
179 resolve_symbol_reference (struct objfile
*, struct symbol
*, char *);
181 void stabsread_clear_cache (void);
183 static const char vptr_name
[] =
184 {'_', 'v', 'p', 't', 'r', CPLUS_MARKER
, '\0'};
185 static const char vb_name
[] =
186 {'_', 'v', 'b', CPLUS_MARKER
, '\0'};
188 /* Define this as 1 if a pcc declaration of a char or short argument
189 gives the correct address. Otherwise assume pcc gives the
190 address of the corresponding int, which is not the same on a
191 big-endian machine. */
193 #if !defined (BELIEVE_PCC_PROMOTION)
194 #define BELIEVE_PCC_PROMOTION 0
196 #if !defined (BELIEVE_PCC_PROMOTION_TYPE)
197 #define BELIEVE_PCC_PROMOTION_TYPE 0
200 static struct complaint invalid_cpp_abbrev_complaint
=
201 {"invalid C++ abbreviation `%s'", 0, 0};
203 static struct complaint invalid_cpp_type_complaint
=
204 {"C++ abbreviated type name unknown at symtab pos %d", 0, 0};
206 static struct complaint member_fn_complaint
=
207 {"member function type missing, got '%c'", 0, 0};
209 static struct complaint const_vol_complaint
=
210 {"const/volatile indicator missing, got '%c'", 0, 0};
212 static struct complaint error_type_complaint
=
213 {"debug info mismatch between compiler and debugger", 0, 0};
215 static struct complaint invalid_member_complaint
=
216 {"invalid (minimal) member type data format at symtab pos %d.", 0, 0};
218 static struct complaint range_type_base_complaint
=
219 {"base type %d of range type is not defined", 0, 0};
221 static struct complaint reg_value_complaint
=
222 {"register number %d too large (max %d) in symbol %s", 0, 0};
224 static struct complaint vtbl_notfound_complaint
=
225 {"virtual function table pointer not found when defining class `%s'", 0, 0};
227 static struct complaint unrecognized_cplus_name_complaint
=
228 {"Unknown C++ symbol name `%s'", 0, 0};
230 static struct complaint rs6000_builtin_complaint
=
231 {"Unknown builtin type %d", 0, 0};
233 static struct complaint unresolved_sym_chain_complaint
=
234 {"%s: common block `%s' from global_sym_chain unresolved", 0, 0};
236 static struct complaint stabs_general_complaint
=
239 static struct complaint lrs_general_complaint
=
242 /* Make a list of forward references which haven't been defined. */
244 static struct type
**undef_types
;
245 static int undef_types_allocated
;
246 static int undef_types_length
;
247 static struct symbol
*current_symbol
= NULL
;
249 /* Check for and handle cretinous stabs symbol name continuation! */
250 #define STABS_CONTINUE(pp,objfile) \
252 if (**(pp) == '\\' || (**(pp) == '?' && (*(pp))[1] == '\0')) \
253 *(pp) = next_symbol_text (objfile); \
256 /* FIXME: These probably should be our own types (like rs6000_builtin_type
257 has its own types) rather than builtin_type_*. */
258 static struct type
**os9k_type_vector
[] =
265 &builtin_type_unsigned_char
,
266 &builtin_type_unsigned_short
,
267 &builtin_type_unsigned_long
,
268 &builtin_type_unsigned_int
,
270 &builtin_type_double
,
272 &builtin_type_long_double
275 static void os9k_init_type_vector (struct type
**);
278 os9k_init_type_vector (struct type
**tv
)
281 for (i
= 0; i
< sizeof (os9k_type_vector
) / sizeof (struct type
**); i
++)
282 tv
[i
] = (os9k_type_vector
[i
] == 0 ? 0 : *(os9k_type_vector
[i
]));
285 /* Look up a dbx type-number pair. Return the address of the slot
286 where the type for that number-pair is stored.
287 The number-pair is in TYPENUMS.
289 This can be used for finding the type associated with that pair
290 or for associating a new type with the pair. */
293 dbx_lookup_type (int typenums
[2])
295 register int filenum
= typenums
[0];
296 register int index
= typenums
[1];
298 register int real_filenum
;
299 register struct header_file
*f
;
302 if (filenum
== -1) /* -1,-1 is for temporary types. */
305 if (filenum
< 0 || filenum
>= n_this_object_header_files
)
307 static struct complaint msg
=
309 Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.",
311 complain (&msg
, filenum
, index
, symnum
);
319 /* Caller wants address of address of type. We think
320 that negative (rs6k builtin) types will never appear as
321 "lvalues", (nor should they), so we stuff the real type
322 pointer into a temp, and return its address. If referenced,
323 this will do the right thing. */
324 static struct type
*temp_type
;
326 temp_type
= rs6000_builtin_type (index
);
330 /* Type is defined outside of header files.
331 Find it in this object file's type vector. */
332 if (index
>= type_vector_length
)
334 old_len
= type_vector_length
;
337 type_vector_length
= INITIAL_TYPE_VECTOR_LENGTH
;
338 type_vector
= (struct type
**)
339 xmalloc (type_vector_length
* sizeof (struct type
*));
341 while (index
>= type_vector_length
)
343 type_vector_length
*= 2;
345 type_vector
= (struct type
**)
346 xrealloc ((char *) type_vector
,
347 (type_vector_length
* sizeof (struct type
*)));
348 memset (&type_vector
[old_len
], 0,
349 (type_vector_length
- old_len
) * sizeof (struct type
*));
352 /* Deal with OS9000 fundamental types. */
353 os9k_init_type_vector (type_vector
);
355 return (&type_vector
[index
]);
359 real_filenum
= this_object_header_files
[filenum
];
361 if (real_filenum
>= N_HEADER_FILES (current_objfile
))
363 struct type
*temp_type
;
364 struct type
**temp_type_p
;
366 warning ("GDB internal error: bad real_filenum");
369 temp_type
= init_type (TYPE_CODE_ERROR
, 0, 0, NULL
, NULL
);
370 temp_type_p
= (struct type
**) xmalloc (sizeof (struct type
*));
371 *temp_type_p
= temp_type
;
375 f
= HEADER_FILES (current_objfile
) + real_filenum
;
377 f_orig_length
= f
->length
;
378 if (index
>= f_orig_length
)
380 while (index
>= f
->length
)
384 f
->vector
= (struct type
**)
385 xrealloc ((char *) f
->vector
, f
->length
* sizeof (struct type
*));
386 memset (&f
->vector
[f_orig_length
], 0,
387 (f
->length
- f_orig_length
) * sizeof (struct type
*));
389 return (&f
->vector
[index
]);
393 /* Make sure there is a type allocated for type numbers TYPENUMS
394 and return the type object.
395 This can create an empty (zeroed) type object.
396 TYPENUMS may be (-1, -1) to return a new type object that is not
397 put into the type vector, and so may not be referred to by number. */
400 dbx_alloc_type (int typenums
[2], struct objfile
*objfile
)
402 register struct type
**type_addr
;
404 if (typenums
[0] == -1)
406 return (alloc_type (objfile
));
409 type_addr
= dbx_lookup_type (typenums
);
411 /* If we are referring to a type not known at all yet,
412 allocate an empty type for it.
413 We will fill it in later if we find out how. */
416 *type_addr
= alloc_type (objfile
);
422 /* for all the stabs in a given stab vector, build appropriate types
423 and fix their symbols in given symbol vector. */
426 patch_block_stabs (struct pending
*symbols
, struct pending_stabs
*stabs
,
427 struct objfile
*objfile
)
437 /* for all the stab entries, find their corresponding symbols and
438 patch their types! */
440 for (ii
= 0; ii
< stabs
->count
; ++ii
)
442 name
= stabs
->stab
[ii
];
443 pp
= (char *) strchr (name
, ':');
447 pp
= (char *) strchr (pp
, ':');
449 sym
= find_symbol_in_list (symbols
, name
, pp
- name
);
452 /* FIXME-maybe: it would be nice if we noticed whether
453 the variable was defined *anywhere*, not just whether
454 it is defined in this compilation unit. But neither
455 xlc or GCC seem to need such a definition, and until
456 we do psymtabs (so that the minimal symbols from all
457 compilation units are available now), I'm not sure
458 how to get the information. */
460 /* On xcoff, if a global is defined and never referenced,
461 ld will remove it from the executable. There is then
462 a N_GSYM stab for it, but no regular (C_EXT) symbol. */
463 sym
= (struct symbol
*)
464 obstack_alloc (&objfile
->symbol_obstack
,
465 sizeof (struct symbol
));
467 memset (sym
, 0, sizeof (struct symbol
));
468 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
469 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
471 obsavestring (name
, pp
- name
, &objfile
->symbol_obstack
);
473 if (*(pp
- 1) == 'F' || *(pp
- 1) == 'f')
475 /* I don't think the linker does this with functions,
476 so as far as I know this is never executed.
477 But it doesn't hurt to check. */
479 lookup_function_type (read_type (&pp
, objfile
));
483 SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
485 add_symbol_to_list (sym
, &global_symbols
);
490 if (*(pp
- 1) == 'F' || *(pp
- 1) == 'f')
493 lookup_function_type (read_type (&pp
, objfile
));
497 SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
505 /* Read a number by which a type is referred to in dbx data,
506 or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
507 Just a single number N is equivalent to (0,N).
508 Return the two numbers by storing them in the vector TYPENUMS.
509 TYPENUMS will then be used as an argument to dbx_lookup_type.
511 Returns 0 for success, -1 for error. */
514 read_type_number (register char **pp
, register int *typenums
)
520 typenums
[0] = read_huge_number (pp
, ',', &nbits
);
523 typenums
[1] = read_huge_number (pp
, ')', &nbits
);
530 typenums
[1] = read_huge_number (pp
, 0, &nbits
);
538 #define VISIBILITY_PRIVATE '0' /* Stabs character for private field */
539 #define VISIBILITY_PROTECTED '1' /* Stabs character for protected fld */
540 #define VISIBILITY_PUBLIC '2' /* Stabs character for public field */
541 #define VISIBILITY_IGNORE '9' /* Optimized out or zero length */
543 #define CFRONT_VISIBILITY_PRIVATE '2' /* Stabs character for private field */
544 #define CFRONT_VISIBILITY_PUBLIC '1' /* Stabs character for public field */
546 /* This code added to support parsing of ARM/Cfront stabs strings */
548 /* Get substring from string up to char c, advance string pointer past
552 get_substring (char **p
, int c
)
567 /* Physname gets strcat'd onto sname in order to recreate the mangled
568 name (see funtion gdb_mangle_name in gdbtypes.c). For cfront, make
569 the physname look like that of g++ - take out the initial mangling
570 eg: for sname="a" and fname="foo__1aFPFs_i" return "FPFs_i" */
573 get_cfront_method_physname (char *fname
)
576 /* FIXME would like to make this generic for g++ too, but
577 that is already handled in read_member_funcctions */
580 /* search ahead to find the start of the mangled suffix */
581 if (*p
== '_' && *(p
+ 1) == '_') /* compiler generated; probably a ctor/dtor */
583 while (p
&& (unsigned) ((p
+ 1) - fname
) < strlen (fname
) && *(p
+ 1) != '_')
585 if (!(p
&& *p
== '_' && *(p
+ 1) == '_'))
586 error ("Invalid mangled function name %s", fname
);
587 p
+= 2; /* advance past '__' */
589 /* struct name length and name of type should come next; advance past it */
592 len
= len
* 10 + (*p
- '0');
600 /* Read base classes within cfront class definition.
601 eg: A:ZcA;1@Bpub v2@Bvirpri;__ct__1AFv func__1AFv *sfunc__1AFv ;as__1A ;;
604 A:ZcA;;foopri__1AFv foopro__1AFv __ct__1AFv __ct__1AFRC1A foopub__1AFv ;;;
609 read_cfront_baseclasses (struct field_info
*fip
, char **pp
, struct type
*type
,
610 struct objfile
*objfile
)
612 static struct complaint msg_unknown
=
614 Unsupported token in stabs string %s.\n",
616 static struct complaint msg_notfound
=
618 Unable to find base type for %s.\n",
623 struct nextfield
*new;
625 if (**pp
== ';') /* no base classes; return */
631 /* first count base classes so we can allocate space before parsing */
632 for (p
= *pp
; p
&& *p
&& *p
!= ';'; p
++)
637 bnum
++; /* add one more for last one */
639 /* now parse the base classes until we get to the start of the methods
640 (code extracted and munged from read_baseclasses) */
641 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
642 TYPE_N_BASECLASSES (type
) = bnum
;
646 int num_bytes
= B_BYTES (TYPE_N_BASECLASSES (type
));
649 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
650 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
652 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), TYPE_N_BASECLASSES (type
));
654 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
656 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
657 make_cleanup (xfree
, new);
658 memset (new, 0, sizeof (struct nextfield
));
659 new->next
= fip
->list
;
661 FIELD_BITSIZE (new->field
) = 0; /* this should be an unpacked field! */
663 STABS_CONTINUE (pp
, objfile
);
665 /* virtual? eg: v2@Bvir */
668 SET_TYPE_FIELD_VIRTUAL (type
, i
);
672 /* access? eg: 2@Bvir */
673 /* Note: protected inheritance not supported in cfront */
676 case CFRONT_VISIBILITY_PRIVATE
:
677 new->visibility
= VISIBILITY_PRIVATE
;
679 case CFRONT_VISIBILITY_PUBLIC
:
680 new->visibility
= VISIBILITY_PUBLIC
;
683 /* Bad visibility format. Complain and treat it as
686 static struct complaint msg
=
688 "Unknown visibility `%c' for baseclass", 0, 0};
689 complain (&msg
, new->visibility
);
690 new->visibility
= VISIBILITY_PUBLIC
;
694 /* "@" comes next - eg: @Bvir */
697 complain (&msg_unknown
, *pp
);
703 /* Set the bit offset of the portion of the object corresponding
704 to this baseclass. Always zero in the absence of
705 multiple inheritance. */
706 /* Unable to read bit position from stabs;
707 Assuming no multiple inheritance for now FIXME! */
708 /* We may have read this in the structure definition;
709 now we should fixup the members to be the actual base classes */
710 FIELD_BITPOS (new->field
) = 0;
712 /* Get the base class name and type */
714 char *bname
; /* base class name */
715 struct symbol
*bsym
; /* base class */
717 p1
= strchr (*pp
, ' ');
718 p2
= strchr (*pp
, ';');
720 bname
= get_substring (pp
, ' ');
722 bname
= get_substring (pp
, ';');
723 if (!bname
|| !*bname
)
725 complain (&msg_unknown
, *pp
);
728 /* FIXME! attach base info to type */
729 bsym
= lookup_symbol (bname
, 0, STRUCT_NAMESPACE
, 0, 0); /*demangled_name */
732 new->field
.type
= SYMBOL_TYPE (bsym
);
733 new->field
.name
= type_name_no_tag (new->field
.type
);
737 complain (&msg_notfound
, *pp
);
742 /* If more base classes to parse, loop again.
743 We ate the last ' ' or ';' in get_substring,
744 so on exit we will have skipped the trailing ';' */
745 /* if invalid, return 0; add code to detect - FIXME! */
750 /* read cfront member functions.
751 pp points to string starting with list of functions
752 eg: A:ZcA;1@Bpub v2@Bvirpri;__ct__1AFv func__1AFv *sfunc__1AFv ;as__1A ;;
753 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
754 A:ZcA;;foopri__1AFv foopro__1AFv __ct__1AFv __ct__1AFRC1A foopub__1AFv ;;;
755 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
759 read_cfront_member_functions (struct field_info
*fip
, char **pp
,
760 struct type
*type
, struct objfile
*objfile
)
762 /* This code extracted from read_member_functions
763 so as to do the similar thing for our funcs */
767 /* Total number of member functions defined in this class. If the class
768 defines two `f' functions, and one `g' function, then this will have
770 int total_length
= 0;
774 struct next_fnfield
*next
;
775 struct fn_field fn_field
;
778 struct type
*look_ahead_type
;
779 struct next_fnfieldlist
*new_fnlist
;
780 struct next_fnfield
*new_sublist
;
783 struct symbol
*ref_func
= 0;
785 /* Process each list until we find the end of the member functions.
786 eg: p = "__ct__1AFv foo__1AFv ;;;" */
788 STABS_CONTINUE (pp
, objfile
); /* handle \\ */
790 while (**pp
!= ';' && (fname
= get_substring (pp
, ' '), fname
))
793 int sublist_count
= 0;
795 if (fname
[0] == '*') /* static member */
801 ref_func
= lookup_symbol (fname
, 0, VAR_NAMESPACE
, 0, 0); /* demangled name */
804 static struct complaint msg
=
806 Unable to find function symbol for %s\n",
808 complain (&msg
, fname
);
812 look_ahead_type
= NULL
;
815 new_fnlist
= (struct next_fnfieldlist
*)
816 xmalloc (sizeof (struct next_fnfieldlist
));
817 make_cleanup (xfree
, new_fnlist
);
818 memset (new_fnlist
, 0, sizeof (struct next_fnfieldlist
));
820 /* The following is code to work around cfront generated stabs.
821 The stabs contains full mangled name for each field.
822 We try to demangle the name and extract the field name out of it. */
824 char *dem
, *dem_p
, *dem_args
;
826 dem
= cplus_demangle (fname
, DMGL_ANSI
| DMGL_PARAMS
);
829 dem_p
= strrchr (dem
, ':');
830 if (dem_p
!= 0 && *(dem_p
- 1) == ':')
832 /* get rid of args */
833 dem_args
= strchr (dem_p
, '(');
834 if (dem_args
== NULL
)
835 dem_len
= strlen (dem_p
);
837 dem_len
= dem_args
- dem_p
;
839 obsavestring (dem_p
, dem_len
, &objfile
->type_obstack
);
844 obsavestring (fname
, strlen (fname
), &objfile
->type_obstack
);
846 } /* end of code for cfront work around */
848 new_fnlist
->fn_fieldlist
.name
= main_fn_name
;
850 /*-------------------------------------------------*/
851 /* Set up the sublists
852 Sublists are stuff like args, static, visibility, etc.
853 so in ARM, we have to set that info some other way.
854 Multiple sublists happen if overloading
855 eg: foo::26=##1;:;2A.;
856 In g++, we'd loop here thru all the sublists... */
859 (struct next_fnfield
*) xmalloc (sizeof (struct next_fnfield
));
860 make_cleanup (xfree
, new_sublist
);
861 memset (new_sublist
, 0, sizeof (struct next_fnfield
));
863 /* eat 1; from :;2A.; */
864 new_sublist
->fn_field
.type
= SYMBOL_TYPE (ref_func
); /* normally takes a read_type */
865 /* Make this type look like a method stub for gdb */
866 TYPE_FLAGS (new_sublist
->fn_field
.type
) |= TYPE_FLAG_STUB
;
867 TYPE_CODE (new_sublist
->fn_field
.type
) = TYPE_CODE_METHOD
;
869 /* If this is just a stub, then we don't have the real name here. */
870 if (TYPE_FLAGS (new_sublist
->fn_field
.type
) & TYPE_FLAG_STUB
)
872 if (!TYPE_DOMAIN_TYPE (new_sublist
->fn_field
.type
))
873 TYPE_DOMAIN_TYPE (new_sublist
->fn_field
.type
) = type
;
874 new_sublist
->fn_field
.is_stub
= 1;
877 /* physname used later in mangling; eg PFs_i,5 for foo__1aFPFs_i
878 physname gets strcat'd in order to recreate the onto mangled name */
879 pname
= get_cfront_method_physname (fname
);
880 new_sublist
->fn_field
.physname
= savestring (pname
, strlen (pname
));
883 /* Set this member function's visibility fields.
884 Unable to distinguish access from stabs definition!
885 Assuming public for now. FIXME!
886 (for private, set new_sublist->fn_field.is_private = 1,
887 for public, set new_sublist->fn_field.is_protected = 1) */
889 /* Unable to distinguish const/volatile from stabs definition!
890 Assuming normal for now. FIXME! */
892 new_sublist
->fn_field
.is_const
= 0;
893 new_sublist
->fn_field
.is_volatile
= 0; /* volatile not implemented in cfront */
895 /* Set virtual/static function info
896 How to get vtable offsets ?
897 Assuming normal for now FIXME!!
898 For vtables, figure out from whence this virtual function came.
899 It may belong to virtual function table of
900 one of its baseclasses.
902 new_sublist -> fn_field.voffset = vtable offset,
903 new_sublist -> fn_field.fcontext = look_ahead_type;
904 where look_ahead_type is type of baseclass */
906 new_sublist
->fn_field
.voffset
= VOFFSET_STATIC
;
907 else /* normal member function. */
908 new_sublist
->fn_field
.voffset
= 0;
909 new_sublist
->fn_field
.fcontext
= 0;
912 /* Prepare new sublist */
913 new_sublist
->next
= sublist
;
914 sublist
= new_sublist
;
917 /* In g++, we loop thu sublists - now we set from functions. */
918 new_fnlist
->fn_fieldlist
.fn_fields
= (struct fn_field
*)
919 obstack_alloc (&objfile
->type_obstack
,
920 sizeof (struct fn_field
) * length
);
921 memset (new_fnlist
->fn_fieldlist
.fn_fields
, 0,
922 sizeof (struct fn_field
) * length
);
923 for (i
= length
; (i
--, sublist
); sublist
= sublist
->next
)
925 new_fnlist
->fn_fieldlist
.fn_fields
[i
] = sublist
->fn_field
;
928 new_fnlist
->fn_fieldlist
.length
= length
;
929 new_fnlist
->next
= fip
->fnlist
;
930 fip
->fnlist
= new_fnlist
;
932 total_length
+= length
;
933 STABS_CONTINUE (pp
, objfile
); /* handle \\ */
938 /* type should already have space */
939 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
940 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * nfn_fields
);
941 memset (TYPE_FN_FIELDLISTS (type
), 0,
942 sizeof (struct fn_fieldlist
) * nfn_fields
);
943 TYPE_NFN_FIELDS (type
) = nfn_fields
;
944 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
947 /* end of scope for reading member func */
951 /* Skip trailing ';' and bump count of number of fields seen */
959 /* This routine fixes up partial cfront types that were created
960 while parsing the stabs. The main need for this function is
961 to add information such as methods to classes.
962 Examples of "p": "sA;;__ct__1AFv foo__1AFv ;;;" */
964 resolve_cfront_continuation (struct objfile
*objfile
, struct symbol
*sym
,
967 struct symbol
*ref_sym
= 0;
969 /* snarfed from read_struct_type */
970 struct field_info fi
;
972 struct cleanup
*back_to
;
974 /* Need to make sure that fi isn't gunna conflict with struct
975 in case struct already had some fnfs */
978 back_to
= make_cleanup (null_cleanup
, 0);
980 /* We only accept structs, classes and unions at the moment.
981 Other continuation types include t (typedef), r (long dbl), ...
982 We may want to add support for them as well;
983 right now they are handled by duplicating the symbol information
984 into the type information (see define_symbol) */
985 if (*p
!= 's' /* structs */
986 && *p
!= 'c' /* class */
987 && *p
!= 'u') /* union */
988 return 0; /* only handle C++ types */
991 /* Get symbol typs name and validate
992 eg: p = "A;;__ct__1AFv foo__1AFv ;;;" */
993 sname
= get_substring (&p
, ';');
994 if (!sname
|| strcmp (sname
, SYMBOL_NAME (sym
)))
995 error ("Internal error: base symbol type name does not match\n");
997 /* Find symbol's internal gdb reference using demangled_name.
998 This is the real sym that we want;
999 sym was a temp hack to make debugger happy */
1000 ref_sym
= lookup_symbol (SYMBOL_NAME (sym
), 0, STRUCT_NAMESPACE
, 0, 0);
1001 type
= SYMBOL_TYPE (ref_sym
);
1004 /* Now read the baseclasses, if any, read the regular C struct or C++
1005 class member fields, attach the fields to the type, read the C++
1006 member functions, attach them to the type, and then read any tilde
1007 field (baseclass specifier for the class holding the main vtable). */
1009 if (!read_cfront_baseclasses (&fi
, &p
, type
, objfile
)
1010 /* g++ does this next, but cfront already did this:
1011 || !read_struct_fields (&fi, &p, type, objfile) */
1012 || !copy_cfront_struct_fields (&fi
, type
, objfile
)
1013 || !read_cfront_member_functions (&fi
, &p
, type
, objfile
)
1014 || !read_cfront_static_fields (&fi
, &p
, type
, objfile
)
1015 || !attach_fields_to_type (&fi
, type
, objfile
)
1016 || !attach_fn_fields_to_type (&fi
, type
)
1017 /* g++ does this next, but cfront doesn't seem to have this:
1018 || !read_tilde_fields (&fi, &p, type, objfile) */
1021 type
= error_type (&p
, objfile
);
1024 do_cleanups (back_to
);
1027 /* End of code added to support parsing of ARM/Cfront stabs strings */
1030 /* This routine fixes up symbol references/aliases to point to the original
1031 symbol definition. Returns 0 on failure, non-zero on success. */
1034 resolve_symbol_reference (struct objfile
*objfile
, struct symbol
*sym
, char *p
)
1037 struct symbol
*ref_sym
= 0;
1038 struct alias_list
*alias
;
1040 /* If this is not a symbol reference return now. */
1044 /* Use "#<num>" as the name; we'll fix the name later.
1045 We stored the original symbol name as "#<id>=<name>"
1046 so we can now search for "#<id>" to resolving the reference.
1047 We'll fix the names later by removing the "#<id>" or "#<id>=" */
1049 /*---------------------------------------------------------*/
1050 /* Get the reference id number, and
1051 advance p past the names so we can parse the rest.
1052 eg: id=2 for p : "2=", "2=z:r(0,1)" "2:r(0,1);l(#5,#6),l(#7,#4)" */
1053 /*---------------------------------------------------------*/
1055 /* This gets reference name from string. sym may not have a name. */
1057 /* Get the reference number associated with the reference id in the
1058 gdb stab string. From that reference number, get the main/primary
1059 symbol for this alias. */
1060 refnum
= process_reference (&p
);
1061 ref_sym
= ref_search (refnum
);
1064 complain (&lrs_general_complaint
, "symbol for reference not found");
1068 /* Parse the stab of the referencing symbol
1069 now that we have the referenced symbol.
1070 Add it as a new symbol and a link back to the referenced symbol.
1071 eg: p : "=", "=z:r(0,1)" ":r(0,1);l(#5,#6),l(#7,#4)" */
1074 /* If the stab symbol table and string contain:
1075 RSYM 0 5 00000000 868 #15=z:r(0,1)
1076 LBRAC 0 0 00000000 899 #5=
1077 SLINE 0 16 00000003 923 #6=
1078 Then the same symbols can be later referenced by:
1079 RSYM 0 5 00000000 927 #15:r(0,1);l(#5,#6)
1080 This is used in live range splitting to:
1081 1) specify that a symbol (#15) is actually just a new storage
1082 class for a symbol (#15=z) which was previously defined.
1083 2) specify that the beginning and ending ranges for a symbol
1084 (#15) are the values of the beginning (#5) and ending (#6)
1087 /* Read number as reference id.
1088 eg: p : "=", "=z:r(0,1)" ":r(0,1);l(#5,#6),l(#7,#4)" */
1089 /* FIXME! Might I want to use SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
1090 in case of "l(0,0)"? */
1092 /*--------------------------------------------------*/
1093 /* Add this symbol to the reference list. */
1094 /*--------------------------------------------------*/
1096 alias
= (struct alias_list
*) obstack_alloc (&objfile
->type_obstack
,
1097 sizeof (struct alias_list
));
1100 complain (&lrs_general_complaint
, "Unable to allocate alias list memory");
1107 if (!SYMBOL_ALIASES (ref_sym
))
1109 SYMBOL_ALIASES (ref_sym
) = alias
;
1113 struct alias_list
*temp
;
1115 /* Get to the end of the list. */
1116 for (temp
= SYMBOL_ALIASES (ref_sym
);
1123 /* Want to fix up name so that other functions (eg. valops)
1124 will correctly print the name.
1125 Don't add_symbol_to_list so that lookup_symbol won't find it.
1126 nope... needed for fixups. */
1127 SYMBOL_NAME (sym
) = SYMBOL_NAME (ref_sym
);
1133 /* Structure for storing pointers to reference definitions for fast lookup
1134 during "process_later". */
1143 #define MAX_CHUNK_REFS 100
1144 #define REF_CHUNK_SIZE (MAX_CHUNK_REFS * sizeof (struct ref_map))
1145 #define REF_MAP_SIZE(ref_chunk) ((ref_chunk) * REF_CHUNK_SIZE)
1147 static struct ref_map
*ref_map
;
1149 /* Ptr to free cell in chunk's linked list. */
1150 static int ref_count
= 0;
1152 /* Number of chunks malloced. */
1153 static int ref_chunk
= 0;
1155 /* This file maintains a cache of stabs aliases found in the symbol
1156 table. If the symbol table changes, this cache must be cleared
1157 or we are left holding onto data in invalid obstacks. */
1159 stabsread_clear_cache (void)
1165 /* Create array of pointers mapping refids to symbols and stab strings.
1166 Add pointers to reference definition symbols and/or their values as we
1167 find them, using their reference numbers as our index.
1168 These will be used later when we resolve references. */
1170 ref_add (int refnum
, struct symbol
*sym
, char *stabs
, CORE_ADDR value
)
1174 if (refnum
>= ref_count
)
1175 ref_count
= refnum
+ 1;
1176 if (ref_count
> ref_chunk
* MAX_CHUNK_REFS
)
1178 int new_slots
= ref_count
- ref_chunk
* MAX_CHUNK_REFS
;
1179 int new_chunks
= new_slots
/ MAX_CHUNK_REFS
+ 1;
1180 ref_map
= (struct ref_map
*)
1181 xrealloc (ref_map
, REF_MAP_SIZE (ref_chunk
+ new_chunks
));
1182 memset (ref_map
+ ref_chunk
* MAX_CHUNK_REFS
, 0, new_chunks
* REF_CHUNK_SIZE
);
1183 ref_chunk
+= new_chunks
;
1185 ref_map
[refnum
].stabs
= stabs
;
1186 ref_map
[refnum
].sym
= sym
;
1187 ref_map
[refnum
].value
= value
;
1190 /* Return defined sym for the reference REFNUM. */
1192 ref_search (int refnum
)
1194 if (refnum
< 0 || refnum
> ref_count
)
1196 return ref_map
[refnum
].sym
;
1199 /* Return value for the reference REFNUM. */
1202 ref_search_value (int refnum
)
1204 if (refnum
< 0 || refnum
> ref_count
)
1206 return ref_map
[refnum
].value
;
1209 /* Parse a reference id in STRING and return the resulting
1210 reference number. Move STRING beyond the reference id. */
1213 process_reference (char **string
)
1218 if (**string
!= '#')
1221 /* Advance beyond the initial '#'. */
1224 /* Read number as reference id. */
1225 while (*p
&& isdigit (*p
))
1227 refnum
= refnum
* 10 + *p
- '0';
1234 /* If STRING defines a reference, store away a pointer to the reference
1235 definition for later use. Return the reference number. */
1238 symbol_reference_defined (char **string
)
1243 refnum
= process_reference (&p
);
1245 /* Defining symbols end in '=' */
1248 /* Symbol is being defined here. */
1254 /* Must be a reference. Either the symbol has already been defined,
1255 or this is a forward reference to it. */
1263 define_symbol (CORE_ADDR valu
, char *string
, int desc
, int type
,
1264 struct objfile
*objfile
)
1266 register struct symbol
*sym
;
1267 char *p
= (char *) strchr (string
, ':');
1272 /* We would like to eliminate nameless symbols, but keep their types.
1273 E.g. stab entry ":t10=*2" should produce a type 10, which is a pointer
1274 to type 2, but, should not create a symbol to address that type. Since
1275 the symbol will be nameless, there is no way any user can refer to it. */
1279 /* Ignore syms with empty names. */
1283 /* Ignore old-style symbols from cc -go */
1290 p
= strchr (p
, ':');
1293 /* If a nameless stab entry, all we need is the type, not the symbol.
1294 e.g. ":t10=*2" or a nameless enum like " :T16=ered:0,green:1,blue:2,;" */
1295 nameless
= (p
== string
|| ((string
[0] == ' ') && (string
[1] == ':')));
1297 current_symbol
= sym
= (struct symbol
*)
1298 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct symbol
));
1299 memset (sym
, 0, sizeof (struct symbol
));
1301 switch (type
& N_TYPE
)
1304 SYMBOL_SECTION (sym
) = SECT_OFF_TEXT (objfile
);
1307 SYMBOL_SECTION (sym
) = SECT_OFF_DATA (objfile
);
1310 SYMBOL_SECTION (sym
) = SECT_OFF_BSS (objfile
);
1314 if (processing_gcc_compilation
)
1316 /* GCC 2.x puts the line number in desc. SunOS apparently puts in the
1317 number of bytes occupied by a type or object, which we ignore. */
1318 SYMBOL_LINE (sym
) = desc
;
1322 SYMBOL_LINE (sym
) = 0; /* unknown */
1325 if (is_cplus_marker (string
[0]))
1327 /* Special GNU C++ names. */
1331 SYMBOL_NAME (sym
) = obsavestring ("this", strlen ("this"),
1332 &objfile
->symbol_obstack
);
1335 case 'v': /* $vtbl_ptr_type */
1336 /* Was: SYMBOL_NAME (sym) = "vptr"; */
1340 SYMBOL_NAME (sym
) = obsavestring ("eh_throw", strlen ("eh_throw"),
1341 &objfile
->symbol_obstack
);
1345 /* This was an anonymous type that was never fixed up. */
1348 #ifdef STATIC_TRANSFORM_NAME
1350 /* SunPRO (3.0 at least) static variable encoding. */
1355 complain (&unrecognized_cplus_name_complaint
, string
);
1356 goto normal
; /* Do *something* with it */
1359 else if (string
[0] == '#')
1361 /* Special GNU C extension for referencing symbols. */
1365 /* If STRING defines a new reference id, then add it to the
1366 reference map. Else it must be referring to a previously
1367 defined symbol, so add it to the alias list of the previously
1370 refnum
= symbol_reference_defined (&s
);
1372 ref_add (refnum
, sym
, string
, SYMBOL_VALUE (sym
));
1373 else if (!resolve_symbol_reference (objfile
, sym
, string
))
1376 /* S..P contains the name of the symbol. We need to store
1377 the correct name into SYMBOL_NAME. */
1383 SYMBOL_NAME (sym
) = (char *)
1384 obstack_alloc (&objfile
->symbol_obstack
, nlen
);
1385 strncpy (SYMBOL_NAME (sym
), s
, nlen
);
1386 SYMBOL_NAME (sym
)[nlen
] = '\0';
1387 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
1390 /* FIXME! Want SYMBOL_NAME (sym) = 0;
1391 Get error if leave name 0. So give it something. */
1394 SYMBOL_NAME (sym
) = (char *)
1395 obstack_alloc (&objfile
->symbol_obstack
, nlen
);
1396 strncpy (SYMBOL_NAME (sym
), string
, nlen
);
1397 SYMBOL_NAME (sym
)[nlen
] = '\0';
1398 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
1401 /* Advance STRING beyond the reference id. */
1407 SYMBOL_LANGUAGE (sym
) = current_subfile
->language
;
1408 SYMBOL_NAME (sym
) = (char *)
1409 obstack_alloc (&objfile
->symbol_obstack
, ((p
- string
) + 1));
1410 /* Open-coded memcpy--saves function call time. */
1411 /* FIXME: Does it really? Try replacing with simple strcpy and
1412 try it on an executable with a large symbol table. */
1413 /* FIXME: considering that gcc can open code memcpy anyway, I
1414 doubt it. xoxorich. */
1416 register char *p1
= string
;
1417 register char *p2
= SYMBOL_NAME (sym
);
1425 /* If this symbol is from a C++ compilation, then attempt to cache the
1426 demangled form for future reference. This is a typical time versus
1427 space tradeoff, that was decided in favor of time because it sped up
1428 C++ symbol lookups by a factor of about 20. */
1430 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
1434 /* Determine the type of name being defined. */
1436 /* Getting GDB to correctly skip the symbol on an undefined symbol
1437 descriptor and not ever dump core is a very dodgy proposition if
1438 we do things this way. I say the acorn RISC machine can just
1439 fix their compiler. */
1440 /* The Acorn RISC machine's compiler can put out locals that don't
1441 start with "234=" or "(3,4)=", so assume anything other than the
1442 deftypes we know how to handle is a local. */
1443 if (!strchr ("cfFGpPrStTvVXCR", *p
))
1445 if (isdigit (*p
) || *p
== '(' || *p
== '-')
1454 /* c is a special case, not followed by a type-number.
1455 SYMBOL:c=iVALUE for an integer constant symbol.
1456 SYMBOL:c=rVALUE for a floating constant symbol.
1457 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
1458 e.g. "b:c=e6,0" for "const b = blob1"
1459 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
1462 SYMBOL_CLASS (sym
) = LOC_CONST
;
1463 SYMBOL_TYPE (sym
) = error_type (&p
, objfile
);
1464 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1465 add_symbol_to_list (sym
, &file_symbols
);
1473 double d
= atof (p
);
1476 /* FIXME-if-picky-about-floating-accuracy: Should be using
1477 target arithmetic to get the value. real.c in GCC
1478 probably has the necessary code. */
1480 /* FIXME: lookup_fundamental_type is a hack. We should be
1481 creating a type especially for the type of float constants.
1482 Problem is, what type should it be?
1484 Also, what should the name of this type be? Should we
1485 be using 'S' constants (see stabs.texinfo) instead? */
1487 SYMBOL_TYPE (sym
) = lookup_fundamental_type (objfile
,
1490 obstack_alloc (&objfile
->symbol_obstack
,
1491 TYPE_LENGTH (SYMBOL_TYPE (sym
)));
1492 store_floating (dbl_valu
, TYPE_LENGTH (SYMBOL_TYPE (sym
)), d
);
1493 SYMBOL_VALUE_BYTES (sym
) = dbl_valu
;
1494 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
1499 /* Defining integer constants this way is kind of silly,
1500 since 'e' constants allows the compiler to give not
1501 only the value, but the type as well. C has at least
1502 int, long, unsigned int, and long long as constant
1503 types; other languages probably should have at least
1504 unsigned as well as signed constants. */
1506 /* We just need one int constant type for all objfiles.
1507 It doesn't depend on languages or anything (arguably its
1508 name should be a language-specific name for a type of
1509 that size, but I'm inclined to say that if the compiler
1510 wants a nice name for the type, it can use 'e'). */
1511 static struct type
*int_const_type
;
1513 /* Yes, this is as long as a *host* int. That is because we
1515 if (int_const_type
== NULL
)
1517 init_type (TYPE_CODE_INT
,
1518 sizeof (int) * HOST_CHAR_BIT
/ TARGET_CHAR_BIT
, 0,
1520 (struct objfile
*) NULL
);
1521 SYMBOL_TYPE (sym
) = int_const_type
;
1522 SYMBOL_VALUE (sym
) = atoi (p
);
1523 SYMBOL_CLASS (sym
) = LOC_CONST
;
1527 /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value
1528 can be represented as integral.
1529 e.g. "b:c=e6,0" for "const b = blob1"
1530 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
1532 SYMBOL_CLASS (sym
) = LOC_CONST
;
1533 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1537 SYMBOL_TYPE (sym
) = error_type (&p
, objfile
);
1542 /* If the value is too big to fit in an int (perhaps because
1543 it is unsigned), or something like that, we silently get
1544 a bogus value. The type and everything else about it is
1545 correct. Ideally, we should be using whatever we have
1546 available for parsing unsigned and long long values,
1548 SYMBOL_VALUE (sym
) = atoi (p
);
1553 SYMBOL_CLASS (sym
) = LOC_CONST
;
1554 SYMBOL_TYPE (sym
) = error_type (&p
, objfile
);
1557 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1558 add_symbol_to_list (sym
, &file_symbols
);
1562 /* The name of a caught exception. */
1563 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1564 SYMBOL_CLASS (sym
) = LOC_LABEL
;
1565 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1566 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1567 add_symbol_to_list (sym
, &local_symbols
);
1571 /* A static function definition. */
1572 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1573 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1574 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1575 add_symbol_to_list (sym
, &file_symbols
);
1576 /* fall into process_function_types. */
1578 process_function_types
:
1579 /* Function result types are described as the result type in stabs.
1580 We need to convert this to the function-returning-type-X type
1581 in GDB. E.g. "int" is converted to "function returning int". */
1582 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_FUNC
)
1583 SYMBOL_TYPE (sym
) = lookup_function_type (SYMBOL_TYPE (sym
));
1585 /* All functions in C++ have prototypes. */
1586 if (SYMBOL_LANGUAGE (sym
) == language_cplus
)
1587 TYPE_FLAGS (SYMBOL_TYPE (sym
)) |= TYPE_FLAG_PROTOTYPED
;
1589 /* fall into process_prototype_types */
1591 process_prototype_types
:
1592 /* Sun acc puts declared types of arguments here. */
1595 struct type
*ftype
= SYMBOL_TYPE (sym
);
1600 /* Obtain a worst case guess for the number of arguments
1601 by counting the semicolons. */
1608 /* Allocate parameter information fields and fill them in. */
1609 TYPE_FIELDS (ftype
) = (struct field
*)
1610 TYPE_ALLOC (ftype
, nsemi
* sizeof (struct field
));
1615 /* A type number of zero indicates the start of varargs.
1616 FIXME: GDB currently ignores vararg functions. */
1617 if (p
[0] == '0' && p
[1] == '\0')
1619 ptype
= read_type (&p
, objfile
);
1621 /* The Sun compilers mark integer arguments, which should
1622 be promoted to the width of the calling conventions, with
1623 a type which references itself. This type is turned into
1624 a TYPE_CODE_VOID type by read_type, and we have to turn
1625 it back into builtin_type_int here.
1626 FIXME: Do we need a new builtin_type_promoted_int_arg ? */
1627 if (TYPE_CODE (ptype
) == TYPE_CODE_VOID
)
1628 ptype
= builtin_type_int
;
1629 TYPE_FIELD_TYPE (ftype
, nparams
++) = ptype
;
1631 TYPE_NFIELDS (ftype
) = nparams
;
1632 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
1637 /* A global function definition. */
1638 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1639 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1640 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1641 add_symbol_to_list (sym
, &global_symbols
);
1642 goto process_function_types
;
1645 /* For a class G (global) symbol, it appears that the
1646 value is not correct. It is necessary to search for the
1647 corresponding linker definition to find the value.
1648 These definitions appear at the end of the namelist. */
1649 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1650 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1651 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1652 /* Don't add symbol references to global_sym_chain.
1653 Symbol references don't have valid names and wont't match up with
1654 minimal symbols when the global_sym_chain is relocated.
1655 We'll fixup symbol references when we fixup the defining symbol. */
1656 if (SYMBOL_NAME (sym
) && SYMBOL_NAME (sym
)[0] != '#')
1658 i
= hashname (SYMBOL_NAME (sym
));
1659 SYMBOL_VALUE_CHAIN (sym
) = global_sym_chain
[i
];
1660 global_sym_chain
[i
] = sym
;
1662 add_symbol_to_list (sym
, &global_symbols
);
1665 /* This case is faked by a conditional above,
1666 when there is no code letter in the dbx data.
1667 Dbx data never actually contains 'l'. */
1670 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1671 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1672 SYMBOL_VALUE (sym
) = valu
;
1673 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1674 add_symbol_to_list (sym
, &local_symbols
);
1679 /* pF is a two-letter code that means a function parameter in Fortran.
1680 The type-number specifies the type of the return value.
1681 Translate it into a pointer-to-function type. */
1685 = lookup_pointer_type
1686 (lookup_function_type (read_type (&p
, objfile
)));
1689 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1691 /* Normally this is a parameter, a LOC_ARG. On the i960, it
1692 can also be a LOC_LOCAL_ARG depending on symbol type. */
1693 #ifndef DBX_PARM_SYMBOL_CLASS
1694 #define DBX_PARM_SYMBOL_CLASS(type) LOC_ARG
1697 SYMBOL_CLASS (sym
) = DBX_PARM_SYMBOL_CLASS (type
);
1698 SYMBOL_VALUE (sym
) = valu
;
1699 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1700 add_symbol_to_list (sym
, &local_symbols
);
1702 if (TARGET_BYTE_ORDER
!= BIG_ENDIAN
)
1704 /* On little-endian machines, this crud is never necessary,
1705 and, if the extra bytes contain garbage, is harmful. */
1709 /* If it's gcc-compiled, if it says `short', believe it. */
1710 if (processing_gcc_compilation
|| BELIEVE_PCC_PROMOTION
)
1713 if (!BELIEVE_PCC_PROMOTION
)
1715 /* This is the signed type which arguments get promoted to. */
1716 static struct type
*pcc_promotion_type
;
1717 /* This is the unsigned type which arguments get promoted to. */
1718 static struct type
*pcc_unsigned_promotion_type
;
1720 /* Call it "int" because this is mainly C lossage. */
1721 if (pcc_promotion_type
== NULL
)
1722 pcc_promotion_type
=
1723 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
1726 if (pcc_unsigned_promotion_type
== NULL
)
1727 pcc_unsigned_promotion_type
=
1728 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
1729 TYPE_FLAG_UNSIGNED
, "unsigned int", NULL
);
1731 if (BELIEVE_PCC_PROMOTION_TYPE
)
1733 /* This is defined on machines (e.g. sparc) where we
1734 should believe the type of a PCC 'short' argument,
1735 but shouldn't believe the address (the address is the
1736 address of the corresponding int).
1738 My guess is that this correction, as opposed to
1739 changing the parameter to an 'int' (as done below,
1740 for PCC on most machines), is the right thing to do
1741 on all machines, but I don't want to risk breaking
1742 something that already works. On most PCC machines,
1743 the sparc problem doesn't come up because the calling
1744 function has to zero the top bytes (not knowing
1745 whether the called function wants an int or a short),
1746 so there is little practical difference between an
1747 int and a short (except perhaps what happens when the
1748 GDB user types "print short_arg = 0x10000;").
1750 Hacked for SunOS 4.1 by gnu@cygnus.com. In 4.1, the
1751 compiler actually produces the correct address (we
1752 don't need to fix it up). I made this code adapt so
1753 that it will offset the symbol if it was pointing at
1754 an int-aligned location and not otherwise. This way
1755 you can use the same gdb for 4.0.x and 4.1 systems.
1757 If the parameter is shorter than an int, and is
1758 integral (e.g. char, short, or unsigned equivalent),
1759 and is claimed to be passed on an integer boundary,
1760 don't believe it! Offset the parameter's address to
1761 the tail-end of that integer. */
1763 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (pcc_promotion_type
)
1764 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
1765 && 0 == SYMBOL_VALUE (sym
) % TYPE_LENGTH (pcc_promotion_type
))
1767 SYMBOL_VALUE (sym
) += TYPE_LENGTH (pcc_promotion_type
)
1768 - TYPE_LENGTH (SYMBOL_TYPE (sym
));
1774 /* If PCC says a parameter is a short or a char,
1775 it is really an int. */
1776 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (pcc_promotion_type
)
1777 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
)
1780 TYPE_UNSIGNED (SYMBOL_TYPE (sym
))
1781 ? pcc_unsigned_promotion_type
1782 : pcc_promotion_type
;
1789 /* acc seems to use P to declare the prototypes of functions that
1790 are referenced by this file. gdb is not prepared to deal
1791 with this extra information. FIXME, it ought to. */
1794 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1795 goto process_prototype_types
;
1800 /* Parameter which is in a register. */
1801 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1802 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
1803 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
1804 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
1806 complain (®_value_complaint
, SYMBOL_VALUE (sym
), NUM_REGS
,
1807 SYMBOL_SOURCE_NAME (sym
));
1808 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
1810 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1811 add_symbol_to_list (sym
, &local_symbols
);
1815 /* Register variable (either global or local). */
1816 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1817 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
1818 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
1819 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
1821 complain (®_value_complaint
, SYMBOL_VALUE (sym
), NUM_REGS
,
1822 SYMBOL_SOURCE_NAME (sym
));
1823 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
1825 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1826 if (within_function
)
1828 /* Sun cc uses a pair of symbols, one 'p' and one 'r' with the same
1829 name to represent an argument passed in a register.
1830 GCC uses 'P' for the same case. So if we find such a symbol pair
1831 we combine it into one 'P' symbol. For Sun cc we need to do this
1832 regardless of REG_STRUCT_HAS_ADDR, because the compiler puts out
1833 the 'p' symbol even if it never saves the argument onto the stack.
1835 On most machines, we want to preserve both symbols, so that
1836 we can still get information about what is going on with the
1837 stack (VAX for computing args_printed, using stack slots instead
1838 of saved registers in backtraces, etc.).
1840 Note that this code illegally combines
1841 main(argc) struct foo argc; { register struct foo argc; }
1842 but this case is considered pathological and causes a warning
1843 from a decent compiler. */
1846 && local_symbols
->nsyms
> 0
1847 #ifndef USE_REGISTER_NOT_ARG
1848 && REG_STRUCT_HAS_ADDR_P ()
1849 && REG_STRUCT_HAS_ADDR (processing_gcc_compilation
,
1851 && (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
1852 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
1853 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_SET
1854 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_BITSTRING
)
1858 struct symbol
*prev_sym
;
1859 prev_sym
= local_symbols
->symbol
[local_symbols
->nsyms
- 1];
1860 if ((SYMBOL_CLASS (prev_sym
) == LOC_REF_ARG
1861 || SYMBOL_CLASS (prev_sym
) == LOC_ARG
)
1862 && STREQ (SYMBOL_NAME (prev_sym
), SYMBOL_NAME (sym
)))
1864 SYMBOL_CLASS (prev_sym
) = LOC_REGPARM
;
1865 /* Use the type from the LOC_REGISTER; that is the type
1866 that is actually in that register. */
1867 SYMBOL_TYPE (prev_sym
) = SYMBOL_TYPE (sym
);
1868 SYMBOL_VALUE (prev_sym
) = SYMBOL_VALUE (sym
);
1873 add_symbol_to_list (sym
, &local_symbols
);
1876 add_symbol_to_list (sym
, &file_symbols
);
1880 /* Static symbol at top level of file */
1881 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1882 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1883 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1884 #ifdef STATIC_TRANSFORM_NAME
1885 if (IS_STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym
)))
1887 struct minimal_symbol
*msym
;
1888 msym
= lookup_minimal_symbol (SYMBOL_NAME (sym
), NULL
, objfile
);
1891 SYMBOL_NAME (sym
) = STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym
));
1892 SYMBOL_VALUE_ADDRESS (sym
) = SYMBOL_VALUE_ADDRESS (msym
);
1896 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1897 add_symbol_to_list (sym
, &file_symbols
);
1901 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1903 /* For a nameless type, we don't want a create a symbol, thus we
1904 did not use `sym'. Return without further processing. */
1908 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1909 SYMBOL_VALUE (sym
) = valu
;
1910 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1911 /* C++ vagaries: we may have a type which is derived from
1912 a base type which did not have its name defined when the
1913 derived class was output. We fill in the derived class's
1914 base part member's name here in that case. */
1915 if (TYPE_NAME (SYMBOL_TYPE (sym
)) != NULL
)
1916 if ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
1917 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
)
1918 && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)))
1921 for (j
= TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)) - 1; j
>= 0; j
--)
1922 if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) == 0)
1923 TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) =
1924 type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym
), j
));
1927 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == NULL
)
1929 /* gcc-2.6 or later (when using -fvtable-thunks)
1930 emits a unique named type for a vtable entry.
1931 Some gdb code depends on that specific name. */
1932 extern const char vtbl_ptr_name
[];
1934 if ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_PTR
1935 && strcmp (SYMBOL_NAME (sym
), vtbl_ptr_name
))
1936 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_FUNC
)
1938 /* If we are giving a name to a type such as "pointer to
1939 foo" or "function returning foo", we better not set
1940 the TYPE_NAME. If the program contains "typedef char
1941 *caddr_t;", we don't want all variables of type char
1942 * to print as caddr_t. This is not just a
1943 consequence of GDB's type management; PCC and GCC (at
1944 least through version 2.4) both output variables of
1945 either type char * or caddr_t with the type number
1946 defined in the 't' symbol for caddr_t. If a future
1947 compiler cleans this up it GDB is not ready for it
1948 yet, but if it becomes ready we somehow need to
1949 disable this check (without breaking the PCC/GCC2.4
1954 Fortunately, this check seems not to be necessary
1955 for anything except pointers or functions. */
1956 /* ezannoni: 2000-10-26. This seems to apply for
1957 versions of gcc older than 2.8. This was the original
1958 problem: with the following code gdb would tell that
1959 the type for name1 is caddr_t, and func is char()
1960 typedef char *caddr_t;
1972 /* Pascal accepts names for pointer types. */
1973 if (current_subfile
->language
== language_pascal
)
1975 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_NAME (sym
);
1979 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_NAME (sym
);
1982 add_symbol_to_list (sym
, &file_symbols
);
1986 /* Struct, union, or enum tag. For GNU C++, this can be be followed
1987 by 't' which means we are typedef'ing it as well. */
1988 synonym
= *p
== 't';
1992 /* The semantics of C++ state that "struct foo { ... }" also defines
1993 a typedef for "foo". Unfortunately, cfront never makes the typedef
1994 when translating C++ into C. We make the typedef here so that
1995 "ptype foo" works as expected for cfront translated code. */
1996 else if (current_subfile
->language
== language_cplus
)
1999 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
2001 /* For a nameless type, we don't want a create a symbol, thus we
2002 did not use `sym'. Return without further processing. */
2006 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
2007 SYMBOL_VALUE (sym
) = valu
;
2008 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
2009 if (TYPE_TAG_NAME (SYMBOL_TYPE (sym
)) == 0)
2010 TYPE_TAG_NAME (SYMBOL_TYPE (sym
))
2011 = obconcat (&objfile
->type_obstack
, "", "", SYMBOL_NAME (sym
));
2012 add_symbol_to_list (sym
, &file_symbols
);
2016 /* Clone the sym and then modify it. */
2017 register struct symbol
*typedef_sym
= (struct symbol
*)
2018 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct symbol
));
2019 *typedef_sym
= *sym
;
2020 SYMBOL_CLASS (typedef_sym
) = LOC_TYPEDEF
;
2021 SYMBOL_VALUE (typedef_sym
) = valu
;
2022 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
2023 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
2024 TYPE_NAME (SYMBOL_TYPE (sym
))
2025 = obconcat (&objfile
->type_obstack
, "", "", SYMBOL_NAME (sym
));
2026 add_symbol_to_list (typedef_sym
, &file_symbols
);
2031 /* Static symbol of local scope */
2032 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
2033 SYMBOL_CLASS (sym
) = LOC_STATIC
;
2034 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
2035 #ifdef STATIC_TRANSFORM_NAME
2036 if (IS_STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym
)))
2038 struct minimal_symbol
*msym
;
2039 msym
= lookup_minimal_symbol (SYMBOL_NAME (sym
), NULL
, objfile
);
2042 SYMBOL_NAME (sym
) = STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym
));
2043 SYMBOL_VALUE_ADDRESS (sym
) = SYMBOL_VALUE_ADDRESS (msym
);
2047 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2049 add_symbol_to_list (sym
, &global_symbols
);
2051 add_symbol_to_list (sym
, &local_symbols
);
2055 /* Reference parameter */
2056 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
2057 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
2058 SYMBOL_VALUE (sym
) = valu
;
2059 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2060 add_symbol_to_list (sym
, &local_symbols
);
2064 /* Reference parameter which is in a register. */
2065 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
2066 SYMBOL_CLASS (sym
) = LOC_REGPARM_ADDR
;
2067 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
2068 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
2070 complain (®_value_complaint
, SYMBOL_VALUE (sym
), NUM_REGS
,
2071 SYMBOL_SOURCE_NAME (sym
));
2072 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
2074 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2075 add_symbol_to_list (sym
, &local_symbols
);
2079 /* This is used by Sun FORTRAN for "function result value".
2080 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
2081 that Pascal uses it too, but when I tried it Pascal used
2082 "x:3" (local symbol) instead. */
2083 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
2084 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
2085 SYMBOL_VALUE (sym
) = valu
;
2086 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2087 add_symbol_to_list (sym
, &local_symbols
);
2090 /* New code added to support cfront stabs strings.
2091 Note: case 'P' already handled above */
2093 /* Cfront type continuation coming up!
2094 Find the original definition and add to it.
2095 We'll have to do this for the typedef too,
2096 since we cloned the symbol to define a type in read_type.
2097 Stabs info examples:
2099 foo__1CFv :ZtF (first def foo__1CFv:F(0,3);(0,24))
2100 C:ZsC;;__ct__1CFv func1__1CFv func2__1CFv ... ;;;
2101 where C is the name of the class.
2102 Unfortunately, we can't lookup the original symbol yet 'cuz
2103 we haven't finished reading all the symbols.
2104 Instead, we save it for processing later */
2105 process_later (sym
, p
, resolve_cfront_continuation
);
2106 SYMBOL_TYPE (sym
) = error_type (&p
, objfile
); /* FIXME! change later */
2107 SYMBOL_CLASS (sym
) = LOC_CONST
;
2108 SYMBOL_VALUE (sym
) = 0;
2109 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2110 /* Don't add to list - we'll delete it later when
2111 we add the continuation to the real sym */
2113 /* End of new code added to support cfront stabs strings */
2116 SYMBOL_TYPE (sym
) = error_type (&p
, objfile
);
2117 SYMBOL_CLASS (sym
) = LOC_CONST
;
2118 SYMBOL_VALUE (sym
) = 0;
2119 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2120 add_symbol_to_list (sym
, &file_symbols
);
2124 /* When passing structures to a function, some systems sometimes pass
2125 the address in a register, not the structure itself. */
2127 if (REG_STRUCT_HAS_ADDR_P ()
2128 && REG_STRUCT_HAS_ADDR (processing_gcc_compilation
, SYMBOL_TYPE (sym
))
2129 && (SYMBOL_CLASS (sym
) == LOC_REGPARM
|| SYMBOL_CLASS (sym
) == LOC_ARG
))
2131 struct type
*symbol_type
= check_typedef (SYMBOL_TYPE (sym
));
2133 if ((TYPE_CODE (symbol_type
) == TYPE_CODE_STRUCT
)
2134 || (TYPE_CODE (symbol_type
) == TYPE_CODE_UNION
)
2135 || (TYPE_CODE (symbol_type
) == TYPE_CODE_BITSTRING
)
2136 || (TYPE_CODE (symbol_type
) == TYPE_CODE_SET
))
2138 /* If REG_STRUCT_HAS_ADDR yields non-zero we have to convert
2139 LOC_REGPARM to LOC_REGPARM_ADDR for structures and unions. */
2140 if (SYMBOL_CLASS (sym
) == LOC_REGPARM
)
2141 SYMBOL_CLASS (sym
) = LOC_REGPARM_ADDR
;
2142 /* Likewise for converting LOC_ARG to LOC_REF_ARG (for the 7th
2143 and subsequent arguments on the sparc, for example). */
2144 else if (SYMBOL_CLASS (sym
) == LOC_ARG
)
2145 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
2149 /* Is there more to parse? For example LRS/alias information? */
2150 while (*p
&& *p
== ';')
2153 if (*p
&& p
[0] == 'l' && p
[1] == '(')
2155 /* GNU extensions for live range splitting may be appended to
2156 the end of the stab string. eg. "l(#1,#2);l(#3,#5)" */
2158 /* Resolve the live range and add it to SYM's live range list. */
2159 if (!resolve_live_range (objfile
, sym
, p
))
2162 /* Find end of live range info. */
2163 p
= strchr (p
, ')');
2164 if (!*p
|| *p
!= ')')
2166 complain (&lrs_general_complaint
, "live range format not recognized");
2175 /* Add the live range found in P to the symbol SYM in objfile OBJFILE. Returns
2176 non-zero on success, zero otherwise. */
2179 resolve_live_range (struct objfile
*objfile
, struct symbol
*sym
, char *p
)
2182 CORE_ADDR start
, end
;
2184 /* Sanity check the beginning of the stabs string. */
2185 if (!*p
|| *p
!= 'l')
2187 complain (&lrs_general_complaint
, "live range string 1");
2192 if (!*p
|| *p
!= '(')
2194 complain (&lrs_general_complaint
, "live range string 2");
2199 /* Get starting value of range and advance P past the reference id.
2201 ?!? In theory, the process_reference should never fail, but we should
2202 catch that case just in case the compiler scrogged the stabs. */
2203 refnum
= process_reference (&p
);
2204 start
= ref_search_value (refnum
);
2207 complain (&lrs_general_complaint
, "Live range symbol not found 1");
2211 if (!*p
|| *p
!= ',')
2213 complain (&lrs_general_complaint
, "live range string 3");
2218 /* Get ending value of range and advance P past the reference id.
2220 ?!? In theory, the process_reference should never fail, but we should
2221 catch that case just in case the compiler scrogged the stabs. */
2222 refnum
= process_reference (&p
);
2223 end
= ref_search_value (refnum
);
2226 complain (&lrs_general_complaint
, "Live range symbol not found 2");
2230 if (!*p
|| *p
!= ')')
2232 complain (&lrs_general_complaint
, "live range string 4");
2236 /* Now that we know the bounds of the range, add it to the
2238 add_live_range (objfile
, sym
, start
, end
);
2243 /* Add a new live range defined by START and END to the symbol SYM
2244 in objfile OBJFILE. */
2247 add_live_range (struct objfile
*objfile
, struct symbol
*sym
, CORE_ADDR start
,
2250 struct range_list
*r
, *rs
;
2254 complain (&lrs_general_complaint
, "end of live range follows start");
2258 /* Alloc new live range structure. */
2259 r
= (struct range_list
*)
2260 obstack_alloc (&objfile
->type_obstack
,
2261 sizeof (struct range_list
));
2266 /* Append this range to the symbol's range list. */
2267 if (!SYMBOL_RANGES (sym
))
2268 SYMBOL_RANGES (sym
) = r
;
2271 /* Get the last range for the symbol. */
2272 for (rs
= SYMBOL_RANGES (sym
); rs
->next
; rs
= rs
->next
)
2279 /* Skip rest of this symbol and return an error type.
2281 General notes on error recovery: error_type always skips to the
2282 end of the symbol (modulo cretinous dbx symbol name continuation).
2283 Thus code like this:
2285 if (*(*pp)++ != ';')
2286 return error_type (pp, objfile);
2288 is wrong because if *pp starts out pointing at '\0' (typically as the
2289 result of an earlier error), it will be incremented to point to the
2290 start of the next symbol, which might produce strange results, at least
2291 if you run off the end of the string table. Instead use
2294 return error_type (pp, objfile);
2300 foo = error_type (pp, objfile);
2304 And in case it isn't obvious, the point of all this hair is so the compiler
2305 can define new types and new syntaxes, and old versions of the
2306 debugger will be able to read the new symbol tables. */
2308 static struct type
*
2309 error_type (char **pp
, struct objfile
*objfile
)
2311 complain (&error_type_complaint
);
2314 /* Skip to end of symbol. */
2315 while (**pp
!= '\0')
2320 /* Check for and handle cretinous dbx symbol name continuation! */
2321 if ((*pp
)[-1] == '\\' || (*pp
)[-1] == '?')
2323 *pp
= next_symbol_text (objfile
);
2330 return (builtin_type_error
);
2334 /* Read type information or a type definition; return the type. Even
2335 though this routine accepts either type information or a type
2336 definition, the distinction is relevant--some parts of stabsread.c
2337 assume that type information starts with a digit, '-', or '(' in
2338 deciding whether to call read_type. */
2341 read_type (register char **pp
, struct objfile
*objfile
)
2343 register struct type
*type
= 0;
2346 char type_descriptor
;
2348 /* Size in bits of type if specified by a type attribute, or -1 if
2349 there is no size attribute. */
2352 /* Used to distinguish string and bitstring from char-array and set. */
2355 /* Read type number if present. The type number may be omitted.
2356 for instance in a two-dimensional array declared with type
2357 "ar1;1;10;ar1;1;10;4". */
2358 if ((**pp
>= '0' && **pp
<= '9')
2362 if (read_type_number (pp
, typenums
) != 0)
2363 return error_type (pp
, objfile
);
2365 /* Type is not being defined here. Either it already exists,
2366 or this is a forward reference to it. dbx_alloc_type handles
2369 return dbx_alloc_type (typenums
, objfile
);
2371 /* Type is being defined here. */
2373 Also skip the type descriptor - we get it below with (*pp)[-1]. */
2378 /* 'typenums=' not present, type is anonymous. Read and return
2379 the definition, but don't put it in the type vector. */
2380 typenums
[0] = typenums
[1] = -1;
2385 type_descriptor
= (*pp
)[-1];
2386 switch (type_descriptor
)
2390 enum type_code code
;
2392 /* Used to index through file_symbols. */
2393 struct pending
*ppt
;
2396 /* Name including "struct", etc. */
2400 char *from
, *to
, *p
, *q1
, *q2
;
2402 /* Set the type code according to the following letter. */
2406 code
= TYPE_CODE_STRUCT
;
2409 code
= TYPE_CODE_UNION
;
2412 code
= TYPE_CODE_ENUM
;
2416 /* Complain and keep going, so compilers can invent new
2417 cross-reference types. */
2418 static struct complaint msg
=
2419 {"Unrecognized cross-reference type `%c'", 0, 0};
2420 complain (&msg
, (*pp
)[0]);
2421 code
= TYPE_CODE_STRUCT
;
2426 q1
= strchr (*pp
, '<');
2427 p
= strchr (*pp
, ':');
2429 return error_type (pp
, objfile
);
2430 if (q1
&& p
> q1
&& p
[1] == ':')
2432 int nesting_level
= 0;
2433 for (q2
= q1
; *q2
; q2
++)
2437 else if (*q2
== '>')
2439 else if (*q2
== ':' && nesting_level
== 0)
2444 return error_type (pp
, objfile
);
2447 (char *) obstack_alloc (&objfile
->type_obstack
, p
- *pp
+ 1);
2449 /* Copy the name. */
2455 /* Set the pointer ahead of the name which we just read, and
2460 /* Now check to see whether the type has already been
2461 declared. This was written for arrays of cross-referenced
2462 types before we had TYPE_CODE_TARGET_STUBBED, so I'm pretty
2463 sure it is not necessary anymore. But it might be a good
2464 idea, to save a little memory. */
2466 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
2467 for (i
= 0; i
< ppt
->nsyms
; i
++)
2469 struct symbol
*sym
= ppt
->symbol
[i
];
2471 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
2472 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
2473 && (TYPE_CODE (SYMBOL_TYPE (sym
)) == code
)
2474 && STREQ (SYMBOL_NAME (sym
), type_name
))
2476 obstack_free (&objfile
->type_obstack
, type_name
);
2477 type
= SYMBOL_TYPE (sym
);
2482 /* Didn't find the type to which this refers, so we must
2483 be dealing with a forward reference. Allocate a type
2484 structure for it, and keep track of it so we can
2485 fill in the rest of the fields when we get the full
2487 type
= dbx_alloc_type (typenums
, objfile
);
2488 TYPE_CODE (type
) = code
;
2489 TYPE_TAG_NAME (type
) = type_name
;
2490 INIT_CPLUS_SPECIFIC (type
);
2491 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
2493 add_undefined_type (type
);
2497 case '-': /* RS/6000 built-in type */
2511 /* We deal with something like t(1,2)=(3,4)=... which
2512 the Lucid compiler and recent gcc versions (post 2.7.3) use. */
2514 /* Allocate and enter the typedef type first.
2515 This handles recursive types. */
2516 type
= dbx_alloc_type (typenums
, objfile
);
2517 TYPE_CODE (type
) = TYPE_CODE_TYPEDEF
;
2519 struct type
*xtype
= read_type (pp
, objfile
);
2522 /* It's being defined as itself. That means it is "void". */
2523 TYPE_CODE (type
) = TYPE_CODE_VOID
;
2524 TYPE_LENGTH (type
) = 1;
2526 else if (type_size
>= 0 || is_string
)
2529 TYPE_NAME (type
) = NULL
;
2530 TYPE_TAG_NAME (type
) = NULL
;
2534 TYPE_FLAGS (type
) |= TYPE_FLAG_TARGET_STUB
;
2535 TYPE_TARGET_TYPE (type
) = xtype
;
2540 /* In the following types, we must be sure to overwrite any existing
2541 type that the typenums refer to, rather than allocating a new one
2542 and making the typenums point to the new one. This is because there
2543 may already be pointers to the existing type (if it had been
2544 forward-referenced), and we must change it to a pointer, function,
2545 reference, or whatever, *in-place*. */
2548 type1
= read_type (pp
, objfile
);
2549 type
= make_pointer_type (type1
, dbx_lookup_type (typenums
));
2552 case '&': /* Reference to another type */
2553 type1
= read_type (pp
, objfile
);
2554 type
= make_reference_type (type1
, dbx_lookup_type (typenums
));
2557 case 'f': /* Function returning another type */
2558 if (os9k_stabs
&& **pp
== '(')
2560 /* Function prototype; parse it.
2561 We must conditionalize this on os9k_stabs because otherwise
2562 it could be confused with a Sun-style (1,3) typenumber
2568 t
= read_type (pp
, objfile
);
2573 type1
= read_type (pp
, objfile
);
2574 type
= make_function_type (type1
, dbx_lookup_type (typenums
));
2577 case 'k': /* Const qualifier on some type (Sun) */
2578 case 'c': /* Const qualifier on some type (OS9000) */
2579 /* Because 'c' means other things to AIX and 'k' is perfectly good,
2580 only accept 'c' in the os9k_stabs case. */
2581 if (type_descriptor
== 'c' && !os9k_stabs
)
2582 return error_type (pp
, objfile
);
2583 type
= read_type (pp
, objfile
);
2584 /* FIXME! For now, we ignore const and volatile qualifiers. */
2587 case 'B': /* Volatile qual on some type (Sun) */
2588 case 'i': /* Volatile qual on some type (OS9000) */
2589 /* Because 'i' means other things to AIX and 'B' is perfectly good,
2590 only accept 'i' in the os9k_stabs case. */
2591 if (type_descriptor
== 'i' && !os9k_stabs
)
2592 return error_type (pp
, objfile
);
2593 type
= read_type (pp
, objfile
);
2594 /* FIXME! For now, we ignore const and volatile qualifiers. */
2598 if (isdigit (**pp
) || **pp
== '(' || **pp
== '-')
2599 { /* Member (class & variable) type */
2600 /* FIXME -- we should be doing smash_to_XXX types here. */
2602 struct type
*domain
= read_type (pp
, objfile
);
2603 struct type
*memtype
;
2606 /* Invalid member type data format. */
2607 return error_type (pp
, objfile
);
2610 memtype
= read_type (pp
, objfile
);
2611 type
= dbx_alloc_type (typenums
, objfile
);
2612 smash_to_member_type (type
, domain
, memtype
);
2615 /* type attribute */
2618 /* Skip to the semicolon. */
2619 while (**pp
!= ';' && **pp
!= '\0')
2622 return error_type (pp
, objfile
);
2624 ++ * pp
; /* Skip the semicolon. */
2629 type_size
= atoi (attr
+ 1);
2639 /* Ignore unrecognized type attributes, so future compilers
2640 can invent new ones. */
2648 case '#': /* Method (class & fn) type */
2649 if ((*pp
)[0] == '#')
2651 /* We'll get the parameter types from the name. */
2652 struct type
*return_type
;
2655 return_type
= read_type (pp
, objfile
);
2656 if (*(*pp
)++ != ';')
2657 complain (&invalid_member_complaint
, symnum
);
2658 type
= allocate_stub_method (return_type
);
2659 if (typenums
[0] != -1)
2660 *dbx_lookup_type (typenums
) = type
;
2664 struct type
*domain
= read_type (pp
, objfile
);
2665 struct type
*return_type
;
2669 /* Invalid member type data format. */
2670 return error_type (pp
, objfile
);
2674 return_type
= read_type (pp
, objfile
);
2675 args
= read_args (pp
, ';', objfile
);
2676 type
= dbx_alloc_type (typenums
, objfile
);
2677 smash_to_method_type (type
, domain
, return_type
, args
);
2681 case 'r': /* Range type */
2682 type
= read_range_type (pp
, typenums
, objfile
);
2683 if (typenums
[0] != -1)
2684 *dbx_lookup_type (typenums
) = type
;
2689 /* Const and volatile qualified type. */
2690 type
= read_type (pp
, objfile
);
2693 /* Sun ACC builtin int type */
2694 type
= read_sun_builtin_type (pp
, typenums
, objfile
);
2695 if (typenums
[0] != -1)
2696 *dbx_lookup_type (typenums
) = type
;
2700 case 'R': /* Sun ACC builtin float type */
2701 type
= read_sun_floating_type (pp
, typenums
, objfile
);
2702 if (typenums
[0] != -1)
2703 *dbx_lookup_type (typenums
) = type
;
2706 case 'e': /* Enumeration type */
2707 type
= dbx_alloc_type (typenums
, objfile
);
2708 type
= read_enum_type (pp
, type
, objfile
);
2709 if (typenums
[0] != -1)
2710 *dbx_lookup_type (typenums
) = type
;
2713 case 's': /* Struct type */
2714 case 'u': /* Union type */
2715 type
= dbx_alloc_type (typenums
, objfile
);
2716 switch (type_descriptor
)
2719 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
2722 TYPE_CODE (type
) = TYPE_CODE_UNION
;
2725 type
= read_struct_type (pp
, type
, objfile
);
2728 case 'a': /* Array type */
2730 return error_type (pp
, objfile
);
2733 type
= dbx_alloc_type (typenums
, objfile
);
2734 type
= read_array_type (pp
, type
, objfile
);
2736 TYPE_CODE (type
) = TYPE_CODE_STRING
;
2740 type1
= read_type (pp
, objfile
);
2741 type
= create_set_type ((struct type
*) NULL
, type1
);
2743 TYPE_CODE (type
) = TYPE_CODE_BITSTRING
;
2744 if (typenums
[0] != -1)
2745 *dbx_lookup_type (typenums
) = type
;
2749 --*pp
; /* Go back to the symbol in error */
2750 /* Particularly important if it was \0! */
2751 return error_type (pp
, objfile
);
2756 warning ("GDB internal error, type is NULL in stabsread.c\n");
2757 return error_type (pp
, objfile
);
2760 /* Size specified in a type attribute overrides any other size. */
2761 if (type_size
!= -1)
2762 TYPE_LENGTH (type
) = (type_size
+ TARGET_CHAR_BIT
- 1) / TARGET_CHAR_BIT
;
2767 /* RS/6000 xlc/dbx combination uses a set of builtin types, starting from -1.
2768 Return the proper type node for a given builtin type number. */
2770 static struct type
*
2771 rs6000_builtin_type (int typenum
)
2773 /* We recognize types numbered from -NUMBER_RECOGNIZED to -1. */
2774 #define NUMBER_RECOGNIZED 34
2775 /* This includes an empty slot for type number -0. */
2776 static struct type
*negative_types
[NUMBER_RECOGNIZED
+ 1];
2777 struct type
*rettype
= NULL
;
2779 if (typenum
>= 0 || typenum
< -NUMBER_RECOGNIZED
)
2781 complain (&rs6000_builtin_complaint
, typenum
);
2782 return builtin_type_error
;
2784 if (negative_types
[-typenum
] != NULL
)
2785 return negative_types
[-typenum
];
2787 #if TARGET_CHAR_BIT != 8
2788 #error This code wrong for TARGET_CHAR_BIT not 8
2789 /* These definitions all assume that TARGET_CHAR_BIT is 8. I think
2790 that if that ever becomes not true, the correct fix will be to
2791 make the size in the struct type to be in bits, not in units of
2798 /* The size of this and all the other types are fixed, defined
2799 by the debugging format. If there is a type called "int" which
2800 is other than 32 bits, then it should use a new negative type
2801 number (or avoid negative type numbers for that case).
2802 See stabs.texinfo. */
2803 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "int", NULL
);
2806 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "char", NULL
);
2809 rettype
= init_type (TYPE_CODE_INT
, 2, 0, "short", NULL
);
2812 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "long", NULL
);
2815 rettype
= init_type (TYPE_CODE_INT
, 1, TYPE_FLAG_UNSIGNED
,
2816 "unsigned char", NULL
);
2819 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "signed char", NULL
);
2822 rettype
= init_type (TYPE_CODE_INT
, 2, TYPE_FLAG_UNSIGNED
,
2823 "unsigned short", NULL
);
2826 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
2827 "unsigned int", NULL
);
2830 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
2833 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
2834 "unsigned long", NULL
);
2837 rettype
= init_type (TYPE_CODE_VOID
, 1, 0, "void", NULL
);
2840 /* IEEE single precision (32 bit). */
2841 rettype
= init_type (TYPE_CODE_FLT
, 4, 0, "float", NULL
);
2844 /* IEEE double precision (64 bit). */
2845 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "double", NULL
);
2848 /* This is an IEEE double on the RS/6000, and different machines with
2849 different sizes for "long double" should use different negative
2850 type numbers. See stabs.texinfo. */
2851 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "long double", NULL
);
2854 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "integer", NULL
);
2857 rettype
= init_type (TYPE_CODE_BOOL
, 4, TYPE_FLAG_UNSIGNED
,
2861 rettype
= init_type (TYPE_CODE_FLT
, 4, 0, "short real", NULL
);
2864 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "real", NULL
);
2867 rettype
= init_type (TYPE_CODE_ERROR
, 0, 0, "stringptr", NULL
);
2870 rettype
= init_type (TYPE_CODE_CHAR
, 1, TYPE_FLAG_UNSIGNED
,
2874 rettype
= init_type (TYPE_CODE_BOOL
, 1, TYPE_FLAG_UNSIGNED
,
2878 rettype
= init_type (TYPE_CODE_BOOL
, 2, TYPE_FLAG_UNSIGNED
,
2882 rettype
= init_type (TYPE_CODE_BOOL
, 4, TYPE_FLAG_UNSIGNED
,
2886 rettype
= init_type (TYPE_CODE_BOOL
, 4, TYPE_FLAG_UNSIGNED
,
2890 /* Complex type consisting of two IEEE single precision values. */
2891 rettype
= init_type (TYPE_CODE_COMPLEX
, 8, 0, "complex", NULL
);
2894 /* Complex type consisting of two IEEE double precision values. */
2895 rettype
= init_type (TYPE_CODE_COMPLEX
, 16, 0, "double complex", NULL
);
2898 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "integer*1", NULL
);
2901 rettype
= init_type (TYPE_CODE_INT
, 2, 0, "integer*2", NULL
);
2904 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "integer*4", NULL
);
2907 rettype
= init_type (TYPE_CODE_CHAR
, 2, 0, "wchar", NULL
);
2910 rettype
= init_type (TYPE_CODE_INT
, 8, 0, "long long", NULL
);
2913 rettype
= init_type (TYPE_CODE_INT
, 8, TYPE_FLAG_UNSIGNED
,
2914 "unsigned long long", NULL
);
2917 rettype
= init_type (TYPE_CODE_INT
, 8, TYPE_FLAG_UNSIGNED
,
2921 rettype
= init_type (TYPE_CODE_INT
, 8, 0, "integer*8", NULL
);
2924 negative_types
[-typenum
] = rettype
;
2928 /* This page contains subroutines of read_type. */
2930 /* Read member function stabs info for C++ classes. The form of each member
2933 NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
2935 An example with two member functions is:
2937 afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
2939 For the case of overloaded operators, the format is op$::*.funcs, where
2940 $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
2941 name (such as `+=') and `.' marks the end of the operator name.
2943 Returns 1 for success, 0 for failure. */
2946 read_member_functions (struct field_info
*fip
, char **pp
, struct type
*type
,
2947 struct objfile
*objfile
)
2951 /* Total number of member functions defined in this class. If the class
2952 defines two `f' functions, and one `g' function, then this will have
2954 int total_length
= 0;
2958 struct next_fnfield
*next
;
2959 struct fn_field fn_field
;
2962 struct type
*look_ahead_type
;
2963 struct next_fnfieldlist
*new_fnlist
;
2964 struct next_fnfield
*new_sublist
;
2968 /* Process each list until we find something that is not a member function
2969 or find the end of the functions. */
2973 /* We should be positioned at the start of the function name.
2974 Scan forward to find the first ':' and if it is not the
2975 first of a "::" delimiter, then this is not a member function. */
2987 look_ahead_type
= NULL
;
2990 new_fnlist
= (struct next_fnfieldlist
*)
2991 xmalloc (sizeof (struct next_fnfieldlist
));
2992 make_cleanup (xfree
, new_fnlist
);
2993 memset (new_fnlist
, 0, sizeof (struct next_fnfieldlist
));
2995 if ((*pp
)[0] == 'o' && (*pp
)[1] == 'p' && is_cplus_marker ((*pp
)[2]))
2997 /* This is a completely wierd case. In order to stuff in the
2998 names that might contain colons (the usual name delimiter),
2999 Mike Tiemann defined a different name format which is
3000 signalled if the identifier is "op$". In that case, the
3001 format is "op$::XXXX." where XXXX is the name. This is
3002 used for names like "+" or "=". YUUUUUUUK! FIXME! */
3003 /* This lets the user type "break operator+".
3004 We could just put in "+" as the name, but that wouldn't
3006 static char opname
[32] =
3007 {'o', 'p', CPLUS_MARKER
};
3008 char *o
= opname
+ 3;
3010 /* Skip past '::'. */
3013 STABS_CONTINUE (pp
, objfile
);
3019 main_fn_name
= savestring (opname
, o
- opname
);
3025 main_fn_name
= savestring (*pp
, p
- *pp
);
3026 /* Skip past '::'. */
3029 new_fnlist
->fn_fieldlist
.name
= main_fn_name
;
3034 (struct next_fnfield
*) xmalloc (sizeof (struct next_fnfield
));
3035 make_cleanup (xfree
, new_sublist
);
3036 memset (new_sublist
, 0, sizeof (struct next_fnfield
));
3038 /* Check for and handle cretinous dbx symbol name continuation! */
3039 if (look_ahead_type
== NULL
)
3042 STABS_CONTINUE (pp
, objfile
);
3044 new_sublist
->fn_field
.type
= read_type (pp
, objfile
);
3047 /* Invalid symtab info for member function. */
3053 /* g++ version 1 kludge */
3054 new_sublist
->fn_field
.type
= look_ahead_type
;
3055 look_ahead_type
= NULL
;
3065 /* If this is just a stub, then we don't have the real name here. */
3067 if (TYPE_FLAGS (new_sublist
->fn_field
.type
) & TYPE_FLAG_STUB
)
3069 if (!TYPE_DOMAIN_TYPE (new_sublist
->fn_field
.type
))
3070 TYPE_DOMAIN_TYPE (new_sublist
->fn_field
.type
) = type
;
3071 new_sublist
->fn_field
.is_stub
= 1;
3073 new_sublist
->fn_field
.physname
= savestring (*pp
, p
- *pp
);
3076 /* Set this member function's visibility fields. */
3079 case VISIBILITY_PRIVATE
:
3080 new_sublist
->fn_field
.is_private
= 1;
3082 case VISIBILITY_PROTECTED
:
3083 new_sublist
->fn_field
.is_protected
= 1;
3087 STABS_CONTINUE (pp
, objfile
);
3090 case 'A': /* Normal functions. */
3091 new_sublist
->fn_field
.is_const
= 0;
3092 new_sublist
->fn_field
.is_volatile
= 0;
3095 case 'B': /* `const' member functions. */
3096 new_sublist
->fn_field
.is_const
= 1;
3097 new_sublist
->fn_field
.is_volatile
= 0;
3100 case 'C': /* `volatile' member function. */
3101 new_sublist
->fn_field
.is_const
= 0;
3102 new_sublist
->fn_field
.is_volatile
= 1;
3105 case 'D': /* `const volatile' member function. */
3106 new_sublist
->fn_field
.is_const
= 1;
3107 new_sublist
->fn_field
.is_volatile
= 1;
3110 case '*': /* File compiled with g++ version 1 -- no info */
3115 complain (&const_vol_complaint
, **pp
);
3124 /* virtual member function, followed by index.
3125 The sign bit is set to distinguish pointers-to-methods
3126 from virtual function indicies. Since the array is
3127 in words, the quantity must be shifted left by 1
3128 on 16 bit machine, and by 2 on 32 bit machine, forcing
3129 the sign bit out, and usable as a valid index into
3130 the array. Remove the sign bit here. */
3131 new_sublist
->fn_field
.voffset
=
3132 (0x7fffffff & read_huge_number (pp
, ';', &nbits
)) + 2;
3136 STABS_CONTINUE (pp
, objfile
);
3137 if (**pp
== ';' || **pp
== '\0')
3139 /* Must be g++ version 1. */
3140 new_sublist
->fn_field
.fcontext
= 0;
3144 /* Figure out from whence this virtual function came.
3145 It may belong to virtual function table of
3146 one of its baseclasses. */
3147 look_ahead_type
= read_type (pp
, objfile
);
3150 /* g++ version 1 overloaded methods. */
3154 new_sublist
->fn_field
.fcontext
= look_ahead_type
;
3163 look_ahead_type
= NULL
;
3169 /* static member function. */
3170 new_sublist
->fn_field
.voffset
= VOFFSET_STATIC
;
3171 if (strncmp (new_sublist
->fn_field
.physname
,
3172 main_fn_name
, strlen (main_fn_name
)))
3174 new_sublist
->fn_field
.is_stub
= 1;
3180 complain (&member_fn_complaint
, (*pp
)[-1]);
3181 /* Fall through into normal member function. */
3184 /* normal member function. */
3185 new_sublist
->fn_field
.voffset
= 0;
3186 new_sublist
->fn_field
.fcontext
= 0;
3190 new_sublist
->next
= sublist
;
3191 sublist
= new_sublist
;
3193 STABS_CONTINUE (pp
, objfile
);
3195 while (**pp
!= ';' && **pp
!= '\0');
3199 new_fnlist
->fn_fieldlist
.fn_fields
= (struct fn_field
*)
3200 obstack_alloc (&objfile
->type_obstack
,
3201 sizeof (struct fn_field
) * length
);
3202 memset (new_fnlist
->fn_fieldlist
.fn_fields
, 0,
3203 sizeof (struct fn_field
) * length
);
3204 for (i
= length
; (i
--, sublist
); sublist
= sublist
->next
)
3206 new_fnlist
->fn_fieldlist
.fn_fields
[i
] = sublist
->fn_field
;
3209 new_fnlist
->fn_fieldlist
.length
= length
;
3210 new_fnlist
->next
= fip
->fnlist
;
3211 fip
->fnlist
= new_fnlist
;
3213 total_length
+= length
;
3214 STABS_CONTINUE (pp
, objfile
);
3219 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3220 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
3221 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * nfn_fields
);
3222 memset (TYPE_FN_FIELDLISTS (type
), 0,
3223 sizeof (struct fn_fieldlist
) * nfn_fields
);
3224 TYPE_NFN_FIELDS (type
) = nfn_fields
;
3225 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
3231 /* Special GNU C++ name.
3233 Returns 1 for success, 0 for failure. "failure" means that we can't
3234 keep parsing and it's time for error_type(). */
3237 read_cpp_abbrev (struct field_info
*fip
, char **pp
, struct type
*type
,
3238 struct objfile
*objfile
)
3243 struct type
*context
;
3253 /* At this point, *pp points to something like "22:23=*22...",
3254 where the type number before the ':' is the "context" and
3255 everything after is a regular type definition. Lookup the
3256 type, find it's name, and construct the field name. */
3258 context
= read_type (pp
, objfile
);
3262 case 'f': /* $vf -- a virtual function table pointer */
3263 fip
->list
->field
.name
=
3264 obconcat (&objfile
->type_obstack
, vptr_name
, "", "");
3267 case 'b': /* $vb -- a virtual bsomethingorother */
3268 name
= type_name_no_tag (context
);
3271 complain (&invalid_cpp_type_complaint
, symnum
);
3274 fip
->list
->field
.name
=
3275 obconcat (&objfile
->type_obstack
, vb_name
, name
, "");
3279 complain (&invalid_cpp_abbrev_complaint
, *pp
);
3280 fip
->list
->field
.name
=
3281 obconcat (&objfile
->type_obstack
,
3282 "INVALID_CPLUSPLUS_ABBREV", "", "");
3286 /* At this point, *pp points to the ':'. Skip it and read the
3292 complain (&invalid_cpp_abbrev_complaint
, *pp
);
3295 fip
->list
->field
.type
= read_type (pp
, objfile
);
3297 (*pp
)++; /* Skip the comma. */
3303 FIELD_BITPOS (fip
->list
->field
) = read_huge_number (pp
, ';', &nbits
);
3307 /* This field is unpacked. */
3308 FIELD_BITSIZE (fip
->list
->field
) = 0;
3309 fip
->list
->visibility
= VISIBILITY_PRIVATE
;
3313 complain (&invalid_cpp_abbrev_complaint
, *pp
);
3314 /* We have no idea what syntax an unrecognized abbrev would have, so
3315 better return 0. If we returned 1, we would need to at least advance
3316 *pp to avoid an infinite loop. */
3323 read_one_struct_field (struct field_info
*fip
, char **pp
, char *p
,
3324 struct type
*type
, struct objfile
*objfile
)
3326 /* The following is code to work around cfront generated stabs.
3327 The stabs contains full mangled name for each field.
3328 We try to demangle the name and extract the field name out of it.
3330 if (ARM_DEMANGLING
&& current_subfile
->language
== language_cplus
)
3336 dem
= cplus_demangle (*pp
, DMGL_ANSI
| DMGL_PARAMS
);
3339 dem_p
= strrchr (dem
, ':');
3340 if (dem_p
!= 0 && *(dem_p
- 1) == ':')
3342 FIELD_NAME (fip
->list
->field
) =
3343 obsavestring (dem_p
, strlen (dem_p
), &objfile
->type_obstack
);
3347 FIELD_NAME (fip
->list
->field
) =
3348 obsavestring (*pp
, p
- *pp
, &objfile
->type_obstack
);
3352 /* end of code for cfront work around */
3355 fip
->list
->field
.name
=
3356 obsavestring (*pp
, p
- *pp
, &objfile
->type_obstack
);
3359 /* This means we have a visibility for a field coming. */
3363 fip
->list
->visibility
= *(*pp
)++;
3367 /* normal dbx-style format, no explicit visibility */
3368 fip
->list
->visibility
= VISIBILITY_PUBLIC
;
3371 fip
->list
->field
.type
= read_type (pp
, objfile
);
3376 /* Possible future hook for nested types. */
3379 fip
->list
->field
.bitpos
= (long) -2; /* nested type */
3389 /* Static class member. */
3390 SET_FIELD_PHYSNAME (fip
->list
->field
, savestring (*pp
, p
- *pp
));
3394 else if (**pp
!= ',')
3396 /* Bad structure-type format. */
3397 complain (&stabs_general_complaint
, "bad structure-type format");
3401 (*pp
)++; /* Skip the comma. */
3405 FIELD_BITPOS (fip
->list
->field
) = read_huge_number (pp
, ',', &nbits
);
3408 complain (&stabs_general_complaint
, "bad structure-type format");
3411 FIELD_BITSIZE (fip
->list
->field
) = read_huge_number (pp
, ';', &nbits
);
3414 complain (&stabs_general_complaint
, "bad structure-type format");
3419 if (FIELD_BITPOS (fip
->list
->field
) == 0
3420 && FIELD_BITSIZE (fip
->list
->field
) == 0)
3422 /* This can happen in two cases: (1) at least for gcc 2.4.5 or so,
3423 it is a field which has been optimized out. The correct stab for
3424 this case is to use VISIBILITY_IGNORE, but that is a recent
3425 invention. (2) It is a 0-size array. For example
3426 union { int num; char str[0]; } foo. Printing "<no value>" for
3427 str in "p foo" is OK, since foo.str (and thus foo.str[3])
3428 will continue to work, and a 0-size array as a whole doesn't
3429 have any contents to print.
3431 I suspect this probably could also happen with gcc -gstabs (not
3432 -gstabs+) for static fields, and perhaps other C++ extensions.
3433 Hopefully few people use -gstabs with gdb, since it is intended
3434 for dbx compatibility. */
3436 /* Ignore this field. */
3437 fip
->list
->visibility
= VISIBILITY_IGNORE
;
3441 /* Detect an unpacked field and mark it as such.
3442 dbx gives a bit size for all fields.
3443 Note that forward refs cannot be packed,
3444 and treat enums as if they had the width of ints. */
3446 struct type
*field_type
= check_typedef (FIELD_TYPE (fip
->list
->field
));
3448 if (TYPE_CODE (field_type
) != TYPE_CODE_INT
3449 && TYPE_CODE (field_type
) != TYPE_CODE_RANGE
3450 && TYPE_CODE (field_type
) != TYPE_CODE_BOOL
3451 && TYPE_CODE (field_type
) != TYPE_CODE_ENUM
)
3453 FIELD_BITSIZE (fip
->list
->field
) = 0;
3455 if ((FIELD_BITSIZE (fip
->list
->field
)
3456 == TARGET_CHAR_BIT
* TYPE_LENGTH (field_type
)
3457 || (TYPE_CODE (field_type
) == TYPE_CODE_ENUM
3458 && FIELD_BITSIZE (fip
->list
->field
) == TARGET_INT_BIT
)
3461 FIELD_BITPOS (fip
->list
->field
) % 8 == 0)
3463 FIELD_BITSIZE (fip
->list
->field
) = 0;
3469 /* Read struct or class data fields. They have the form:
3471 NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
3473 At the end, we see a semicolon instead of a field.
3475 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
3478 The optional VISIBILITY is one of:
3480 '/0' (VISIBILITY_PRIVATE)
3481 '/1' (VISIBILITY_PROTECTED)
3482 '/2' (VISIBILITY_PUBLIC)
3483 '/9' (VISIBILITY_IGNORE)
3485 or nothing, for C style fields with public visibility.
3487 Returns 1 for success, 0 for failure. */
3490 read_struct_fields (struct field_info
*fip
, char **pp
, struct type
*type
,
3491 struct objfile
*objfile
)
3494 struct nextfield
*new;
3496 /* We better set p right now, in case there are no fields at all... */
3500 /* Read each data member type until we find the terminating ';' at the end of
3501 the data member list, or break for some other reason such as finding the
3502 start of the member function list. */
3506 if (os9k_stabs
&& **pp
== ',')
3508 STABS_CONTINUE (pp
, objfile
);
3509 /* Get space to record the next field's data. */
3510 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3511 make_cleanup (xfree
, new);
3512 memset (new, 0, sizeof (struct nextfield
));
3513 new->next
= fip
->list
;
3516 /* Get the field name. */
3519 /* If is starts with CPLUS_MARKER it is a special abbreviation,
3520 unless the CPLUS_MARKER is followed by an underscore, in
3521 which case it is just the name of an anonymous type, which we
3522 should handle like any other type name. */
3524 if (is_cplus_marker (p
[0]) && p
[1] != '_')
3526 if (!read_cpp_abbrev (fip
, pp
, type
, objfile
))
3531 /* Look for the ':' that separates the field name from the field
3532 values. Data members are delimited by a single ':', while member
3533 functions are delimited by a pair of ':'s. When we hit the member
3534 functions (if any), terminate scan loop and return. */
3536 while (*p
!= ':' && *p
!= '\0')
3543 /* Check to see if we have hit the member functions yet. */
3548 read_one_struct_field (fip
, pp
, p
, type
, objfile
);
3550 if (p
[0] == ':' && p
[1] == ':')
3552 /* chill the list of fields: the last entry (at the head) is a
3553 partially constructed entry which we now scrub. */
3554 fip
->list
= fip
->list
->next
;
3559 /* The stabs for C++ derived classes contain baseclass information which
3560 is marked by a '!' character after the total size. This function is
3561 called when we encounter the baseclass marker, and slurps up all the
3562 baseclass information.
3564 Immediately following the '!' marker is the number of base classes that
3565 the class is derived from, followed by information for each base class.
3566 For each base class, there are two visibility specifiers, a bit offset
3567 to the base class information within the derived class, a reference to
3568 the type for the base class, and a terminating semicolon.
3570 A typical example, with two base classes, would be "!2,020,19;0264,21;".
3572 Baseclass information marker __________________|| | | | | | |
3573 Number of baseclasses __________________________| | | | | | |
3574 Visibility specifiers (2) ________________________| | | | | |
3575 Offset in bits from start of class _________________| | | | |
3576 Type number for base class ___________________________| | | |
3577 Visibility specifiers (2) _______________________________| | |
3578 Offset in bits from start of class ________________________| |
3579 Type number of base class ____________________________________|
3581 Return 1 for success, 0 for (error-type-inducing) failure. */
3587 read_baseclasses (struct field_info
*fip
, char **pp
, struct type
*type
,
3588 struct objfile
*objfile
)
3591 struct nextfield
*new;
3599 /* Skip the '!' baseclass information marker. */
3603 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3606 TYPE_N_BASECLASSES (type
) = read_huge_number (pp
, ',', &nbits
);
3612 /* Some stupid compilers have trouble with the following, so break
3613 it up into simpler expressions. */
3614 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*)
3615 TYPE_ALLOC (type
, B_BYTES (TYPE_N_BASECLASSES (type
)));
3618 int num_bytes
= B_BYTES (TYPE_N_BASECLASSES (type
));
3621 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
3622 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
3626 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), TYPE_N_BASECLASSES (type
));
3628 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
3630 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3631 make_cleanup (xfree
, new);
3632 memset (new, 0, sizeof (struct nextfield
));
3633 new->next
= fip
->list
;
3635 FIELD_BITSIZE (new->field
) = 0; /* this should be an unpacked field! */
3637 STABS_CONTINUE (pp
, objfile
);
3641 /* Nothing to do. */
3644 SET_TYPE_FIELD_VIRTUAL (type
, i
);
3647 /* Unknown character. Complain and treat it as non-virtual. */
3649 static struct complaint msg
=
3651 "Unknown virtual character `%c' for baseclass", 0, 0};
3652 complain (&msg
, **pp
);
3657 new->visibility
= *(*pp
)++;
3658 switch (new->visibility
)
3660 case VISIBILITY_PRIVATE
:
3661 case VISIBILITY_PROTECTED
:
3662 case VISIBILITY_PUBLIC
:
3665 /* Bad visibility format. Complain and treat it as
3668 static struct complaint msg
=
3670 "Unknown visibility `%c' for baseclass", 0, 0
3672 complain (&msg
, new->visibility
);
3673 new->visibility
= VISIBILITY_PUBLIC
;
3680 /* The remaining value is the bit offset of the portion of the object
3681 corresponding to this baseclass. Always zero in the absence of
3682 multiple inheritance. */
3684 FIELD_BITPOS (new->field
) = read_huge_number (pp
, ',', &nbits
);
3689 /* The last piece of baseclass information is the type of the
3690 base class. Read it, and remember it's type name as this
3693 new->field
.type
= read_type (pp
, objfile
);
3694 new->field
.name
= type_name_no_tag (new->field
.type
);
3696 /* skip trailing ';' and bump count of number of fields seen */
3705 /* The tail end of stabs for C++ classes that contain a virtual function
3706 pointer contains a tilde, a %, and a type number.
3707 The type number refers to the base class (possibly this class itself) which
3708 contains the vtable pointer for the current class.
3710 This function is called when we have parsed all the method declarations,
3711 so we can look for the vptr base class info. */
3714 read_tilde_fields (struct field_info
*fip
, char **pp
, struct type
*type
,
3715 struct objfile
*objfile
)
3719 STABS_CONTINUE (pp
, objfile
);
3721 /* If we are positioned at a ';', then skip it. */
3731 if (**pp
== '=' || **pp
== '+' || **pp
== '-')
3733 /* Obsolete flags that used to indicate the presence
3734 of constructors and/or destructors. */
3738 /* Read either a '%' or the final ';'. */
3739 if (*(*pp
)++ == '%')
3741 /* The next number is the type number of the base class
3742 (possibly our own class) which supplies the vtable for
3743 this class. Parse it out, and search that class to find
3744 its vtable pointer, and install those into TYPE_VPTR_BASETYPE
3745 and TYPE_VPTR_FIELDNO. */
3750 t
= read_type (pp
, objfile
);
3752 while (*p
!= '\0' && *p
!= ';')
3758 /* Premature end of symbol. */
3762 TYPE_VPTR_BASETYPE (type
) = t
;
3763 if (type
== t
) /* Our own class provides vtbl ptr */
3765 for (i
= TYPE_NFIELDS (t
) - 1;
3766 i
>= TYPE_N_BASECLASSES (t
);
3769 if (!strncmp (TYPE_FIELD_NAME (t
, i
), vptr_name
,
3770 sizeof (vptr_name
) - 1))
3772 TYPE_VPTR_FIELDNO (type
) = i
;
3776 /* Virtual function table field not found. */
3777 complain (&vtbl_notfound_complaint
, TYPE_NAME (type
));
3782 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
3793 attach_fn_fields_to_type (struct field_info
*fip
, register struct type
*type
)
3797 for (n
= TYPE_NFN_FIELDS (type
);
3798 fip
->fnlist
!= NULL
;
3799 fip
->fnlist
= fip
->fnlist
->next
)
3801 --n
; /* Circumvent Sun3 compiler bug */
3802 TYPE_FN_FIELDLISTS (type
)[n
] = fip
->fnlist
->fn_fieldlist
;
3807 /* read cfront class static data.
3808 pp points to string starting with the list of static data
3809 eg: A:ZcA;1@Bpub v2@Bvirpri;__ct__1AFv func__1AFv *sfunc__1AFv ;as__1A ;;
3812 A:ZcA;;foopri__1AFv foopro__1AFv __ct__1AFv __ct__1AFRC1A foopub__1AFv ;;;
3817 read_cfront_static_fields (struct field_info
*fip
, char **pp
, struct type
*type
,
3818 struct objfile
*objfile
)
3820 struct nextfield
*new;
3823 struct symbol
*ref_static
= 0;
3825 if (**pp
== ';') /* no static data; return */
3831 /* Process each field in the list until we find the terminating ";" */
3833 /* eg: p = "as__1A ;;;" */
3834 STABS_CONTINUE (pp
, objfile
); /* handle \\ */
3835 while (**pp
!= ';' && (sname
= get_substring (pp
, ' '), sname
))
3837 ref_static
= lookup_symbol (sname
, 0, VAR_NAMESPACE
, 0, 0); /*demangled_name */
3840 static struct complaint msg
=
3842 Unable to find symbol for static data field %s\n",
3844 complain (&msg
, sname
);
3847 stype
= SYMBOL_TYPE (ref_static
);
3849 /* allocate a new fip */
3850 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3851 make_cleanup (xfree
, new);
3852 memset (new, 0, sizeof (struct nextfield
));
3853 new->next
= fip
->list
;
3856 /* set visibility */
3857 /* FIXME! no way to tell visibility from stabs??? */
3858 new->visibility
= VISIBILITY_PUBLIC
;
3860 /* set field info into fip */
3861 fip
->list
->field
.type
= stype
;
3863 /* set bitpos & bitsize */
3864 SET_FIELD_PHYSNAME (fip
->list
->field
, savestring (sname
, strlen (sname
)));
3866 /* set name field */
3867 /* The following is code to work around cfront generated stabs.
3868 The stabs contains full mangled name for each field.
3869 We try to demangle the name and extract the field name out of it.
3874 dem
= cplus_demangle (sname
, DMGL_ANSI
| DMGL_PARAMS
);
3877 dem_p
= strrchr (dem
, ':');
3878 if (dem_p
!= 0 && *(dem_p
- 1) == ':')
3880 fip
->list
->field
.name
=
3881 obsavestring (dem_p
, strlen (dem_p
), &objfile
->type_obstack
);
3885 fip
->list
->field
.name
=
3886 obsavestring (sname
, strlen (sname
), &objfile
->type_obstack
);
3888 } /* end of code for cfront work around */
3889 } /* loop again for next static field */
3893 /* Copy structure fields to fip so attach_fields_to_type will work.
3894 type has already been created with the initial instance data fields.
3895 Now we want to be able to add the other members to the class,
3896 so we want to add them back to the fip and reattach them again
3897 once we have collected all the class members. */
3900 copy_cfront_struct_fields (struct field_info
*fip
, struct type
*type
,
3901 struct objfile
*objfile
)
3903 int nfields
= TYPE_NFIELDS (type
);
3905 struct nextfield
*new;
3907 /* Copy the fields into the list of fips and reset the types
3908 to remove the old fields */
3910 for (i
= 0; i
< nfields
; i
++)
3912 /* allocate a new fip */
3913 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3914 make_cleanup (xfree
, new);
3915 memset (new, 0, sizeof (struct nextfield
));
3916 new->next
= fip
->list
;
3919 /* copy field info into fip */
3920 new->field
= TYPE_FIELD (type
, i
);
3921 /* set visibility */
3922 if (TYPE_FIELD_PROTECTED (type
, i
))
3923 new->visibility
= VISIBILITY_PROTECTED
;
3924 else if (TYPE_FIELD_PRIVATE (type
, i
))
3925 new->visibility
= VISIBILITY_PRIVATE
;
3927 new->visibility
= VISIBILITY_PUBLIC
;
3929 /* Now delete the fields from the type since we will be
3930 allocing new space once we get the rest of the fields
3931 in attach_fields_to_type.
3932 The pointer TYPE_FIELDS(type) is left dangling but should
3933 be freed later by objstack_free */
3934 TYPE_FIELDS (type
) = 0;
3935 TYPE_NFIELDS (type
) = 0;
3940 /* Create the vector of fields, and record how big it is.
3941 We need this info to record proper virtual function table information
3942 for this class's virtual functions. */
3945 attach_fields_to_type (struct field_info
*fip
, register struct type
*type
,
3946 struct objfile
*objfile
)
3948 register int nfields
= 0;
3949 register int non_public_fields
= 0;
3950 register struct nextfield
*scan
;
3952 /* Count up the number of fields that we have, as well as taking note of
3953 whether or not there are any non-public fields, which requires us to
3954 allocate and build the private_field_bits and protected_field_bits
3957 for (scan
= fip
->list
; scan
!= NULL
; scan
= scan
->next
)
3960 if (scan
->visibility
!= VISIBILITY_PUBLIC
)
3962 non_public_fields
++;
3966 /* Now we know how many fields there are, and whether or not there are any
3967 non-public fields. Record the field count, allocate space for the
3968 array of fields, and create blank visibility bitfields if necessary. */
3970 TYPE_NFIELDS (type
) = nfields
;
3971 TYPE_FIELDS (type
) = (struct field
*)
3972 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
3973 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
3975 if (non_public_fields
)
3977 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3979 TYPE_FIELD_PRIVATE_BITS (type
) =
3980 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3981 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
3983 TYPE_FIELD_PROTECTED_BITS (type
) =
3984 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3985 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
3987 TYPE_FIELD_IGNORE_BITS (type
) =
3988 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3989 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
3992 /* Copy the saved-up fields into the field vector. Start from the head
3993 of the list, adding to the tail of the field array, so that they end
3994 up in the same order in the array in which they were added to the list. */
3996 while (nfields
-- > 0)
3998 TYPE_FIELD (type
, nfields
) = fip
->list
->field
;
3999 switch (fip
->list
->visibility
)
4001 case VISIBILITY_PRIVATE
:
4002 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
4005 case VISIBILITY_PROTECTED
:
4006 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
4009 case VISIBILITY_IGNORE
:
4010 SET_TYPE_FIELD_IGNORE (type
, nfields
);
4013 case VISIBILITY_PUBLIC
:
4017 /* Unknown visibility. Complain and treat it as public. */
4019 static struct complaint msg
=
4021 "Unknown visibility `%c' for field", 0, 0};
4022 complain (&msg
, fip
->list
->visibility
);
4026 fip
->list
= fip
->list
->next
;
4031 /* Read the description of a structure (or union type) and return an object
4032 describing the type.
4034 PP points to a character pointer that points to the next unconsumed token
4035 in the the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
4036 *PP will point to "4a:1,0,32;;".
4038 TYPE points to an incomplete type that needs to be filled in.
4040 OBJFILE points to the current objfile from which the stabs information is
4041 being read. (Note that it is redundant in that TYPE also contains a pointer
4042 to this same objfile, so it might be a good idea to eliminate it. FIXME).
4045 static struct type
*
4046 read_struct_type (char **pp
, struct type
*type
, struct objfile
*objfile
)
4048 struct cleanup
*back_to
;
4049 struct field_info fi
;
4054 back_to
= make_cleanup (null_cleanup
, 0);
4056 INIT_CPLUS_SPECIFIC (type
);
4057 TYPE_FLAGS (type
) &= ~TYPE_FLAG_STUB
;
4059 /* First comes the total size in bytes. */
4063 TYPE_LENGTH (type
) = read_huge_number (pp
, 0, &nbits
);
4065 return error_type (pp
, objfile
);
4068 /* Now read the baseclasses, if any, read the regular C struct or C++
4069 class member fields, attach the fields to the type, read the C++
4070 member functions, attach them to the type, and then read any tilde
4071 field (baseclass specifier for the class holding the main vtable). */
4073 if (!read_baseclasses (&fi
, pp
, type
, objfile
)
4074 || !read_struct_fields (&fi
, pp
, type
, objfile
)
4075 || !attach_fields_to_type (&fi
, type
, objfile
)
4076 || !read_member_functions (&fi
, pp
, type
, objfile
)
4077 || !attach_fn_fields_to_type (&fi
, type
)
4078 || !read_tilde_fields (&fi
, pp
, type
, objfile
))
4080 type
= error_type (pp
, objfile
);
4083 do_cleanups (back_to
);
4087 /* Read a definition of an array type,
4088 and create and return a suitable type object.
4089 Also creates a range type which represents the bounds of that
4092 static struct type
*
4093 read_array_type (register char **pp
, register struct type
*type
,
4094 struct objfile
*objfile
)
4096 struct type
*index_type
, *element_type
, *range_type
;
4101 /* Format of an array type:
4102 "ar<index type>;lower;upper;<array_contents_type>".
4103 OS9000: "arlower,upper;<array_contents_type>".
4105 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
4106 for these, produce a type like float[][]. */
4109 index_type
= builtin_type_int
;
4112 index_type
= read_type (pp
, objfile
);
4114 /* Improper format of array type decl. */
4115 return error_type (pp
, objfile
);
4119 if (!(**pp
>= '0' && **pp
<= '9') && **pp
!= '-')
4124 lower
= read_huge_number (pp
, os9k_stabs
? ',' : ';', &nbits
);
4126 return error_type (pp
, objfile
);
4128 if (!(**pp
>= '0' && **pp
<= '9') && **pp
!= '-')
4133 upper
= read_huge_number (pp
, ';', &nbits
);
4135 return error_type (pp
, objfile
);
4137 element_type
= read_type (pp
, objfile
);
4146 create_range_type ((struct type
*) NULL
, index_type
, lower
, upper
);
4147 type
= create_array_type (type
, element_type
, range_type
);
4153 /* Read a definition of an enumeration type,
4154 and create and return a suitable type object.
4155 Also defines the symbols that represent the values of the type. */
4157 static struct type
*
4158 read_enum_type (register char **pp
, register struct type
*type
,
4159 struct objfile
*objfile
)
4164 register struct symbol
*sym
;
4166 struct pending
**symlist
;
4167 struct pending
*osyms
, *syms
;
4170 int unsigned_enum
= 1;
4173 /* FIXME! The stabs produced by Sun CC merrily define things that ought
4174 to be file-scope, between N_FN entries, using N_LSYM. What's a mother
4175 to do? For now, force all enum values to file scope. */
4176 if (within_function
)
4177 symlist
= &local_symbols
;
4180 symlist
= &file_symbols
;
4182 o_nsyms
= osyms
? osyms
->nsyms
: 0;
4186 /* Size. Perhaps this does not have to be conditionalized on
4187 os9k_stabs (assuming the name of an enum constant can't start
4189 read_huge_number (pp
, 0, &nbits
);
4191 return error_type (pp
, objfile
);
4194 /* The aix4 compiler emits an extra field before the enum members;
4195 my guess is it's a type of some sort. Just ignore it. */
4198 /* Skip over the type. */
4202 /* Skip over the colon. */
4206 /* Read the value-names and their values.
4207 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
4208 A semicolon or comma instead of a NAME means the end. */
4209 while (**pp
&& **pp
!= ';' && **pp
!= ',')
4211 STABS_CONTINUE (pp
, objfile
);
4215 name
= obsavestring (*pp
, p
- *pp
, &objfile
->symbol_obstack
);
4217 n
= read_huge_number (pp
, ',', &nbits
);
4219 return error_type (pp
, objfile
);
4221 sym
= (struct symbol
*)
4222 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct symbol
));
4223 memset (sym
, 0, sizeof (struct symbol
));
4224 SYMBOL_NAME (sym
) = name
;
4225 SYMBOL_LANGUAGE (sym
) = current_subfile
->language
;
4226 SYMBOL_CLASS (sym
) = LOC_CONST
;
4227 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4228 SYMBOL_VALUE (sym
) = n
;
4231 add_symbol_to_list (sym
, symlist
);
4236 (*pp
)++; /* Skip the semicolon. */
4238 /* Now fill in the fields of the type-structure. */
4240 TYPE_LENGTH (type
) = TARGET_INT_BIT
/ HOST_CHAR_BIT
;
4241 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
4242 TYPE_FLAGS (type
) &= ~TYPE_FLAG_STUB
;
4244 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
4245 TYPE_NFIELDS (type
) = nsyms
;
4246 TYPE_FIELDS (type
) = (struct field
*)
4247 TYPE_ALLOC (type
, sizeof (struct field
) * nsyms
);
4248 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nsyms
);
4250 /* Find the symbols for the values and put them into the type.
4251 The symbols can be found in the symlist that we put them on
4252 to cause them to be defined. osyms contains the old value
4253 of that symlist; everything up to there was defined by us. */
4254 /* Note that we preserve the order of the enum constants, so
4255 that in something like "enum {FOO, LAST_THING=FOO}" we print
4256 FOO, not LAST_THING. */
4258 for (syms
= *symlist
, n
= nsyms
- 1; syms
; syms
= syms
->next
)
4260 int last
= syms
== osyms
? o_nsyms
: 0;
4261 int j
= syms
->nsyms
;
4262 for (; --j
>= last
; --n
)
4264 struct symbol
*xsym
= syms
->symbol
[j
];
4265 SYMBOL_TYPE (xsym
) = type
;
4266 TYPE_FIELD_NAME (type
, n
) = SYMBOL_NAME (xsym
);
4267 TYPE_FIELD_BITPOS (type
, n
) = SYMBOL_VALUE (xsym
);
4268 TYPE_FIELD_BITSIZE (type
, n
) = 0;
4277 /* Sun's ACC uses a somewhat saner method for specifying the builtin
4278 typedefs in every file (for int, long, etc):
4280 type = b <signed> <width> <format type>; <offset>; <nbits>
4282 optional format type = c or b for char or boolean.
4283 offset = offset from high order bit to start bit of type.
4284 width is # bytes in object of this type, nbits is # bits in type.
4286 The width/offset stuff appears to be for small objects stored in
4287 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
4290 static struct type
*
4291 read_sun_builtin_type (char **pp
, int typenums
[2], struct objfile
*objfile
)
4296 enum type_code code
= TYPE_CODE_INT
;
4307 return error_type (pp
, objfile
);
4311 /* For some odd reason, all forms of char put a c here. This is strange
4312 because no other type has this honor. We can safely ignore this because
4313 we actually determine 'char'acterness by the number of bits specified in
4315 Boolean forms, e.g Fortran logical*X, put a b here. */
4319 else if (**pp
== 'b')
4321 code
= TYPE_CODE_BOOL
;
4325 /* The first number appears to be the number of bytes occupied
4326 by this type, except that unsigned short is 4 instead of 2.
4327 Since this information is redundant with the third number,
4328 we will ignore it. */
4329 read_huge_number (pp
, ';', &nbits
);
4331 return error_type (pp
, objfile
);
4333 /* The second number is always 0, so ignore it too. */
4334 read_huge_number (pp
, ';', &nbits
);
4336 return error_type (pp
, objfile
);
4338 /* The third number is the number of bits for this type. */
4339 type_bits
= read_huge_number (pp
, 0, &nbits
);
4341 return error_type (pp
, objfile
);
4342 /* The type *should* end with a semicolon. If it are embedded
4343 in a larger type the semicolon may be the only way to know where
4344 the type ends. If this type is at the end of the stabstring we
4345 can deal with the omitted semicolon (but we don't have to like
4346 it). Don't bother to complain(), Sun's compiler omits the semicolon
4352 return init_type (TYPE_CODE_VOID
, 1,
4353 signed_type
? 0 : TYPE_FLAG_UNSIGNED
, (char *) NULL
,
4356 return init_type (code
,
4357 type_bits
/ TARGET_CHAR_BIT
,
4358 signed_type
? 0 : TYPE_FLAG_UNSIGNED
, (char *) NULL
,
4362 static struct type
*
4363 read_sun_floating_type (char **pp
, int typenums
[2], struct objfile
*objfile
)
4369 /* The first number has more details about the type, for example
4371 details
= read_huge_number (pp
, ';', &nbits
);
4373 return error_type (pp
, objfile
);
4375 /* The second number is the number of bytes occupied by this type */
4376 nbytes
= read_huge_number (pp
, ';', &nbits
);
4378 return error_type (pp
, objfile
);
4380 if (details
== NF_COMPLEX
|| details
== NF_COMPLEX16
4381 || details
== NF_COMPLEX32
)
4382 /* This is a type we can't handle, but we do know the size.
4383 We also will be able to give it a name. */
4384 return init_type (TYPE_CODE_COMPLEX
, nbytes
, 0, NULL
, objfile
);
4386 return init_type (TYPE_CODE_FLT
, nbytes
, 0, NULL
, objfile
);
4389 /* Read a number from the string pointed to by *PP.
4390 The value of *PP is advanced over the number.
4391 If END is nonzero, the character that ends the
4392 number must match END, or an error happens;
4393 and that character is skipped if it does match.
4394 If END is zero, *PP is left pointing to that character.
4396 If the number fits in a long, set *BITS to 0 and return the value.
4397 If not, set *BITS to be the number of bits in the number and return 0.
4399 If encounter garbage, set *BITS to -1 and return 0. */
4402 read_huge_number (char **pp
, int end
, int *bits
)
4419 /* Leading zero means octal. GCC uses this to output values larger
4420 than an int (because that would be hard in decimal). */
4428 upper_limit
= ULONG_MAX
/ radix
;
4430 upper_limit
= LONG_MAX
/ radix
;
4432 while ((c
= *p
++) >= '0' && c
< ('0' + radix
))
4434 if (n
<= upper_limit
)
4437 n
+= c
- '0'; /* FIXME this overflows anyway */
4442 /* This depends on large values being output in octal, which is
4449 /* Ignore leading zeroes. */
4453 else if (c
== '2' || c
== '3')
4479 /* Large decimal constants are an error (because it is hard to
4480 count how many bits are in them). */
4486 /* -0x7f is the same as 0x80. So deal with it by adding one to
4487 the number of bits. */
4499 /* It's *BITS which has the interesting information. */
4503 static struct type
*
4504 read_range_type (char **pp
, int typenums
[2], struct objfile
*objfile
)
4506 char *orig_pp
= *pp
;
4511 struct type
*result_type
;
4512 struct type
*index_type
= NULL
;
4514 /* First comes a type we are a subrange of.
4515 In C it is usually 0, 1 or the type being defined. */
4516 if (read_type_number (pp
, rangenums
) != 0)
4517 return error_type (pp
, objfile
);
4518 self_subrange
= (rangenums
[0] == typenums
[0] &&
4519 rangenums
[1] == typenums
[1]);
4524 index_type
= read_type (pp
, objfile
);
4527 /* A semicolon should now follow; skip it. */
4531 /* The remaining two operands are usually lower and upper bounds
4532 of the range. But in some special cases they mean something else. */
4533 n2
= read_huge_number (pp
, ';', &n2bits
);
4534 n3
= read_huge_number (pp
, ';', &n3bits
);
4536 if (n2bits
== -1 || n3bits
== -1)
4537 return error_type (pp
, objfile
);
4540 goto handle_true_range
;
4542 /* If limits are huge, must be large integral type. */
4543 if (n2bits
!= 0 || n3bits
!= 0)
4545 char got_signed
= 0;
4546 char got_unsigned
= 0;
4547 /* Number of bits in the type. */
4550 /* Range from 0 to <large number> is an unsigned large integral type. */
4551 if ((n2bits
== 0 && n2
== 0) && n3bits
!= 0)
4556 /* Range from <large number> to <large number>-1 is a large signed
4557 integral type. Take care of the case where <large number> doesn't
4558 fit in a long but <large number>-1 does. */
4559 else if ((n2bits
!= 0 && n3bits
!= 0 && n2bits
== n3bits
+ 1)
4560 || (n2bits
!= 0 && n3bits
== 0
4561 && (n2bits
== sizeof (long) * HOST_CHAR_BIT
)
4568 if (got_signed
|| got_unsigned
)
4570 return init_type (TYPE_CODE_INT
, nbits
/ TARGET_CHAR_BIT
,
4571 got_unsigned
? TYPE_FLAG_UNSIGNED
: 0, NULL
,
4575 return error_type (pp
, objfile
);
4578 /* A type defined as a subrange of itself, with bounds both 0, is void. */
4579 if (self_subrange
&& n2
== 0 && n3
== 0)
4580 return init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
4582 /* If n3 is zero and n2 is positive, we want a floating type, and n2
4583 is the width in bytes.
4585 Fortran programs appear to use this for complex types also. To
4586 distinguish between floats and complex, g77 (and others?) seem
4587 to use self-subranges for the complexes, and subranges of int for
4590 Also note that for complexes, g77 sets n2 to the size of one of
4591 the member floats, not the whole complex beast. My guess is that
4592 this was to work well with pre-COMPLEX versions of gdb. */
4594 if (n3
== 0 && n2
> 0)
4596 struct type
*float_type
4597 = init_type (TYPE_CODE_FLT
, n2
, 0, NULL
, objfile
);
4601 struct type
*complex_type
=
4602 init_type (TYPE_CODE_COMPLEX
, 2 * n2
, 0, NULL
, objfile
);
4603 TYPE_TARGET_TYPE (complex_type
) = float_type
;
4604 return complex_type
;
4610 /* If the upper bound is -1, it must really be an unsigned int. */
4612 else if (n2
== 0 && n3
== -1)
4614 /* It is unsigned int or unsigned long. */
4615 /* GCC 2.3.3 uses this for long long too, but that is just a GDB 3.5
4616 compatibility hack. */
4617 return init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
4618 TYPE_FLAG_UNSIGNED
, NULL
, objfile
);
4621 /* Special case: char is defined (Who knows why) as a subrange of
4622 itself with range 0-127. */
4623 else if (self_subrange
&& n2
== 0 && n3
== 127)
4624 return init_type (TYPE_CODE_INT
, 1, 0, NULL
, objfile
);
4626 else if (current_symbol
&& SYMBOL_LANGUAGE (current_symbol
) == language_chill
4628 goto handle_true_range
;
4630 /* We used to do this only for subrange of self or subrange of int. */
4633 /* -1 is used for the upper bound of (4 byte) "unsigned int" and
4634 "unsigned long", and we already checked for that,
4635 so don't need to test for it here. */
4638 /* n3 actually gives the size. */
4639 return init_type (TYPE_CODE_INT
, -n3
, TYPE_FLAG_UNSIGNED
,
4642 /* Is n3 == 2**(8n)-1 for some integer n? Then it's an
4643 unsigned n-byte integer. But do require n to be a power of
4644 two; we don't want 3- and 5-byte integers flying around. */
4650 for (bytes
= 0; (bits
& 0xff) == 0xff; bytes
++)
4653 && ((bytes
- 1) & bytes
) == 0) /* "bytes is a power of two" */
4654 return init_type (TYPE_CODE_INT
, bytes
, TYPE_FLAG_UNSIGNED
, NULL
,
4658 /* I think this is for Convex "long long". Since I don't know whether
4659 Convex sets self_subrange, I also accept that particular size regardless
4660 of self_subrange. */
4661 else if (n3
== 0 && n2
< 0
4663 || n2
== -TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
))
4664 return init_type (TYPE_CODE_INT
, -n2
, 0, NULL
, objfile
);
4665 else if (n2
== -n3
- 1)
4668 return init_type (TYPE_CODE_INT
, 1, 0, NULL
, objfile
);
4670 return init_type (TYPE_CODE_INT
, 2, 0, NULL
, objfile
);
4671 if (n3
== 0x7fffffff)
4672 return init_type (TYPE_CODE_INT
, 4, 0, NULL
, objfile
);
4675 /* We have a real range type on our hands. Allocate space and
4676 return a real pointer. */
4680 index_type
= builtin_type_int
;
4682 index_type
= *dbx_lookup_type (rangenums
);
4683 if (index_type
== NULL
)
4685 /* Does this actually ever happen? Is that why we are worrying
4686 about dealing with it rather than just calling error_type? */
4688 static struct type
*range_type_index
;
4690 complain (&range_type_base_complaint
, rangenums
[1]);
4691 if (range_type_index
== NULL
)
4693 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
4694 0, "range type index type", NULL
);
4695 index_type
= range_type_index
;
4698 result_type
= create_range_type ((struct type
*) NULL
, index_type
, n2
, n3
);
4699 return (result_type
);
4702 /* Read in an argument list. This is a list of types, separated by commas
4703 and terminated with END. Return the list of types read in, or (struct type
4704 **)-1 if there is an error. */
4706 static struct type
**
4707 read_args (char **pp
, int end
, struct objfile
*objfile
)
4709 /* FIXME! Remove this arbitrary limit! */
4710 struct type
*types
[1024], **rval
; /* allow for fns of 1023 parameters */
4716 /* Invalid argument list: no ','. */
4717 return (struct type
**) -1;
4719 STABS_CONTINUE (pp
, objfile
);
4720 types
[n
++] = read_type (pp
, objfile
);
4722 (*pp
)++; /* get past `end' (the ':' character) */
4726 rval
= (struct type
**) xmalloc (2 * sizeof (struct type
*));
4728 else if (TYPE_CODE (types
[n
- 1]) != TYPE_CODE_VOID
)
4730 rval
= (struct type
**) xmalloc ((n
+ 1) * sizeof (struct type
*));
4731 memset (rval
+ n
, 0, sizeof (struct type
*));
4735 rval
= (struct type
**) xmalloc (n
* sizeof (struct type
*));
4737 memcpy (rval
, types
, n
* sizeof (struct type
*));
4741 /* Common block handling. */
4743 /* List of symbols declared since the last BCOMM. This list is a tail
4744 of local_symbols. When ECOMM is seen, the symbols on the list
4745 are noted so their proper addresses can be filled in later,
4746 using the common block base address gotten from the assembler
4749 static struct pending
*common_block
;
4750 static int common_block_i
;
4752 /* Name of the current common block. We get it from the BCOMM instead of the
4753 ECOMM to match IBM documentation (even though IBM puts the name both places
4754 like everyone else). */
4755 static char *common_block_name
;
4757 /* Process a N_BCOMM symbol. The storage for NAME is not guaranteed
4758 to remain after this function returns. */
4761 common_block_start (char *name
, struct objfile
*objfile
)
4763 if (common_block_name
!= NULL
)
4765 static struct complaint msg
=
4767 "Invalid symbol data: common block within common block",
4771 common_block
= local_symbols
;
4772 common_block_i
= local_symbols
? local_symbols
->nsyms
: 0;
4773 common_block_name
= obsavestring (name
, strlen (name
),
4774 &objfile
->symbol_obstack
);
4777 /* Process a N_ECOMM symbol. */
4780 common_block_end (struct objfile
*objfile
)
4782 /* Symbols declared since the BCOMM are to have the common block
4783 start address added in when we know it. common_block and
4784 common_block_i point to the first symbol after the BCOMM in
4785 the local_symbols list; copy the list and hang it off the
4786 symbol for the common block name for later fixup. */
4789 struct pending
*new = 0;
4790 struct pending
*next
;
4793 if (common_block_name
== NULL
)
4795 static struct complaint msg
=
4796 {"ECOMM symbol unmatched by BCOMM", 0, 0};
4801 sym
= (struct symbol
*)
4802 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct symbol
));
4803 memset (sym
, 0, sizeof (struct symbol
));
4804 /* Note: common_block_name already saved on symbol_obstack */
4805 SYMBOL_NAME (sym
) = common_block_name
;
4806 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
4808 /* Now we copy all the symbols which have been defined since the BCOMM. */
4810 /* Copy all the struct pendings before common_block. */
4811 for (next
= local_symbols
;
4812 next
!= NULL
&& next
!= common_block
;
4815 for (j
= 0; j
< next
->nsyms
; j
++)
4816 add_symbol_to_list (next
->symbol
[j
], &new);
4819 /* Copy however much of COMMON_BLOCK we need. If COMMON_BLOCK is
4820 NULL, it means copy all the local symbols (which we already did
4823 if (common_block
!= NULL
)
4824 for (j
= common_block_i
; j
< common_block
->nsyms
; j
++)
4825 add_symbol_to_list (common_block
->symbol
[j
], &new);
4827 SYMBOL_TYPE (sym
) = (struct type
*) new;
4829 /* Should we be putting local_symbols back to what it was?
4832 i
= hashname (SYMBOL_NAME (sym
));
4833 SYMBOL_VALUE_CHAIN (sym
) = global_sym_chain
[i
];
4834 global_sym_chain
[i
] = sym
;
4835 common_block_name
= NULL
;
4838 /* Add a common block's start address to the offset of each symbol
4839 declared to be in it (by being between a BCOMM/ECOMM pair that uses
4840 the common block name). */
4843 fix_common_block (struct symbol
*sym
, int valu
)
4845 struct pending
*next
= (struct pending
*) SYMBOL_TYPE (sym
);
4846 for (; next
; next
= next
->next
)
4849 for (j
= next
->nsyms
- 1; j
>= 0; j
--)
4850 SYMBOL_VALUE_ADDRESS (next
->symbol
[j
]) += valu
;
4856 /* What about types defined as forward references inside of a small lexical
4858 /* Add a type to the list of undefined types to be checked through
4859 once this file has been read in. */
4862 add_undefined_type (struct type
*type
)
4864 if (undef_types_length
== undef_types_allocated
)
4866 undef_types_allocated
*= 2;
4867 undef_types
= (struct type
**)
4868 xrealloc ((char *) undef_types
,
4869 undef_types_allocated
* sizeof (struct type
*));
4871 undef_types
[undef_types_length
++] = type
;
4874 /* Go through each undefined type, see if it's still undefined, and fix it
4875 up if possible. We have two kinds of undefined types:
4877 TYPE_CODE_ARRAY: Array whose target type wasn't defined yet.
4878 Fix: update array length using the element bounds
4879 and the target type's length.
4880 TYPE_CODE_STRUCT, TYPE_CODE_UNION: Structure whose fields were not
4881 yet defined at the time a pointer to it was made.
4882 Fix: Do a full lookup on the struct/union tag. */
4884 cleanup_undefined_types (void)
4888 for (type
= undef_types
; type
< undef_types
+ undef_types_length
; type
++)
4890 switch (TYPE_CODE (*type
))
4893 case TYPE_CODE_STRUCT
:
4894 case TYPE_CODE_UNION
:
4895 case TYPE_CODE_ENUM
:
4897 /* Check if it has been defined since. Need to do this here
4898 as well as in check_typedef to deal with the (legitimate in
4899 C though not C++) case of several types with the same name
4900 in different source files. */
4901 if (TYPE_FLAGS (*type
) & TYPE_FLAG_STUB
)
4903 struct pending
*ppt
;
4905 /* Name of the type, without "struct" or "union" */
4906 char *typename
= TYPE_TAG_NAME (*type
);
4908 if (typename
== NULL
)
4910 static struct complaint msg
=
4911 {"need a type name", 0, 0};
4915 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
4917 for (i
= 0; i
< ppt
->nsyms
; i
++)
4919 struct symbol
*sym
= ppt
->symbol
[i
];
4921 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
4922 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
4923 && (TYPE_CODE (SYMBOL_TYPE (sym
)) ==
4925 && STREQ (SYMBOL_NAME (sym
), typename
))
4927 memcpy (*type
, SYMBOL_TYPE (sym
),
4928 sizeof (struct type
));
4938 static struct complaint msg
=
4940 GDB internal error. cleanup_undefined_types with bad type %d.", 0, 0};
4941 complain (&msg
, TYPE_CODE (*type
));
4947 undef_types_length
= 0;
4950 /* Scan through all of the global symbols defined in the object file,
4951 assigning values to the debugging symbols that need to be assigned
4952 to. Get these symbols from the minimal symbol table. */
4955 scan_file_globals (struct objfile
*objfile
)
4958 struct minimal_symbol
*msymbol
;
4959 struct symbol
*sym
, *prev
, *rsym
;
4960 struct objfile
*resolve_objfile
;
4962 /* SVR4 based linkers copy referenced global symbols from shared
4963 libraries to the main executable.
4964 If we are scanning the symbols for a shared library, try to resolve
4965 them from the minimal symbols of the main executable first. */
4967 if (symfile_objfile
&& objfile
!= symfile_objfile
)
4968 resolve_objfile
= symfile_objfile
;
4970 resolve_objfile
= objfile
;
4974 /* Avoid expensive loop through all minimal symbols if there are
4975 no unresolved symbols. */
4976 for (hash
= 0; hash
< HASHSIZE
; hash
++)
4978 if (global_sym_chain
[hash
])
4981 if (hash
>= HASHSIZE
)
4984 for (msymbol
= resolve_objfile
->msymbols
;
4985 msymbol
&& SYMBOL_NAME (msymbol
) != NULL
;
4990 /* Skip static symbols. */
4991 switch (MSYMBOL_TYPE (msymbol
))
5003 /* Get the hash index and check all the symbols
5004 under that hash index. */
5006 hash
= hashname (SYMBOL_NAME (msymbol
));
5008 for (sym
= global_sym_chain
[hash
]; sym
;)
5010 if (SYMBOL_NAME (msymbol
)[0] == SYMBOL_NAME (sym
)[0] &&
5011 STREQ (SYMBOL_NAME (msymbol
) + 1, SYMBOL_NAME (sym
) + 1))
5014 struct alias_list
*aliases
;
5016 /* Splice this symbol out of the hash chain and
5017 assign the value we have to it. */
5020 SYMBOL_VALUE_CHAIN (prev
) = SYMBOL_VALUE_CHAIN (sym
);
5024 global_sym_chain
[hash
] = SYMBOL_VALUE_CHAIN (sym
);
5027 /* Check to see whether we need to fix up a common block. */
5028 /* Note: this code might be executed several times for
5029 the same symbol if there are multiple references. */
5031 /* If symbol has aliases, do minimal symbol fixups for each.
5032 These live aliases/references weren't added to
5033 global_sym_chain hash but may also need to be fixed up. */
5034 /* FIXME: Maybe should have added aliases to the global chain, resolved symbol name, then treated aliases as normal
5035 symbols? Still, we wouldn't want to add_to_list. */
5036 /* Now do the same for each alias of this symbol */
5038 aliases
= SYMBOL_ALIASES (sym
);
5041 if (SYMBOL_CLASS (rsym
) == LOC_BLOCK
)
5043 fix_common_block (rsym
,
5044 SYMBOL_VALUE_ADDRESS (msymbol
));
5048 SYMBOL_VALUE_ADDRESS (rsym
)
5049 = SYMBOL_VALUE_ADDRESS (msymbol
);
5051 SYMBOL_SECTION (rsym
) = SYMBOL_SECTION (msymbol
);
5054 rsym
= aliases
->sym
;
5055 aliases
= aliases
->next
;
5064 sym
= SYMBOL_VALUE_CHAIN (prev
);
5068 sym
= global_sym_chain
[hash
];
5074 sym
= SYMBOL_VALUE_CHAIN (sym
);
5078 if (resolve_objfile
== objfile
)
5080 resolve_objfile
= objfile
;
5083 /* Change the storage class of any remaining unresolved globals to
5084 LOC_UNRESOLVED and remove them from the chain. */
5085 for (hash
= 0; hash
< HASHSIZE
; hash
++)
5087 sym
= global_sym_chain
[hash
];
5091 sym
= SYMBOL_VALUE_CHAIN (sym
);
5093 /* Change the symbol address from the misleading chain value
5095 SYMBOL_VALUE_ADDRESS (prev
) = 0;
5097 /* Complain about unresolved common block symbols. */
5098 if (SYMBOL_CLASS (prev
) == LOC_STATIC
)
5099 SYMBOL_CLASS (prev
) = LOC_UNRESOLVED
;
5101 complain (&unresolved_sym_chain_complaint
,
5102 objfile
->name
, SYMBOL_NAME (prev
));
5105 memset (global_sym_chain
, 0, sizeof (global_sym_chain
));
5108 /* Initialize anything that needs initializing when starting to read
5109 a fresh piece of a symbol file, e.g. reading in the stuff corresponding
5113 stabsread_init (void)
5117 /* Initialize anything that needs initializing when a completely new
5118 symbol file is specified (not just adding some symbols from another
5119 file, e.g. a shared library). */
5122 stabsread_new_init (void)
5124 /* Empty the hash table of global syms looking for values. */
5125 memset (global_sym_chain
, 0, sizeof (global_sym_chain
));
5128 /* Initialize anything that needs initializing at the same time as
5129 start_symtab() is called. */
5134 global_stabs
= NULL
; /* AIX COFF */
5135 /* Leave FILENUM of 0 free for builtin types and this file's types. */
5136 n_this_object_header_files
= 1;
5137 type_vector_length
= 0;
5138 type_vector
= (struct type
**) 0;
5140 /* FIXME: If common_block_name is not already NULL, we should complain(). */
5141 common_block_name
= NULL
;
5146 /* Call after end_symtab() */
5153 xfree (type_vector
);
5156 type_vector_length
= 0;
5157 previous_stab_code
= 0;
5161 finish_global_stabs (struct objfile
*objfile
)
5165 patch_block_stabs (global_symbols
, global_stabs
, objfile
);
5166 xfree (global_stabs
);
5167 global_stabs
= NULL
;
5171 /* Initializer for this module */
5174 _initialize_stabsread (void)
5176 undef_types_allocated
= 20;
5177 undef_types_length
= 0;
5178 undef_types
= (struct type
**)
5179 xmalloc (undef_types_allocated
* sizeof (struct type
*));