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
PARAMS ((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
PARAMS ((struct field_info
*, char **, char *,
86 struct type
*, struct objfile
*));
89 get_substring
PARAMS ((char **, int));
92 dbx_alloc_type
PARAMS ((int[2], struct objfile
*));
94 static long read_huge_number
PARAMS ((char **, int, int *));
96 static struct type
*error_type
PARAMS ((char **, struct objfile
*));
99 patch_block_stabs
PARAMS ((struct pending
*, struct pending_stabs
*,
103 fix_common_block
PARAMS ((struct symbol
*, int));
106 read_type_number
PARAMS ((char **, int *));
109 read_range_type
PARAMS ((char **, int[2], struct objfile
*));
112 read_sun_builtin_type
PARAMS ((char **, int[2], struct objfile
*));
115 read_sun_floating_type
PARAMS ((char **, int[2], struct objfile
*));
118 read_enum_type
PARAMS ((char **, struct type
*, struct objfile
*));
121 rs6000_builtin_type
PARAMS ((int));
124 read_member_functions
PARAMS ((struct field_info
*, char **, struct type
*,
128 read_struct_fields
PARAMS ((struct field_info
*, char **, struct type
*,
132 read_baseclasses
PARAMS ((struct field_info
*, char **, struct type
*,
136 read_tilde_fields
PARAMS ((struct field_info
*, char **, struct type
*,
140 attach_fn_fields_to_type
PARAMS ((struct field_info
*, struct type
*));
143 attach_fields_to_type
PARAMS ((struct field_info
*, struct type
*,
147 read_struct_type
PARAMS ((char **, struct type
*, struct objfile
*));
150 read_array_type
PARAMS ((char **, struct type
*, struct objfile
*));
152 static struct type
**
153 read_args
PARAMS ((char **, int, struct objfile
*));
156 read_cpp_abbrev
PARAMS ((struct field_info
*, char **, struct type
*,
159 /* new functions added for cfront support */
162 copy_cfront_struct_fields
PARAMS ((struct field_info
*, struct type
*,
166 get_cfront_method_physname
PARAMS ((char *));
169 read_cfront_baseclasses
PARAMS ((struct field_info
*, char **,
170 struct type
*, struct objfile
*));
173 read_cfront_static_fields
PARAMS ((struct field_info
*, char **,
174 struct type
*, struct objfile
*));
176 read_cfront_member_functions
PARAMS ((struct field_info
*, char **,
177 struct type
*, struct objfile
*));
179 /* end new functions added for cfront support */
182 add_live_range
PARAMS ((struct objfile
*, struct symbol
*,
183 CORE_ADDR
, CORE_ADDR
));
186 resolve_live_range
PARAMS ((struct objfile
*, struct symbol
*, char *));
189 process_reference
PARAMS ((char **string
));
192 ref_search_value
PARAMS ((int refnum
));
195 resolve_symbol_reference
PARAMS ((struct objfile
*, struct symbol
*, char *));
197 void stabsread_clear_cache
PARAMS ((void));
199 static const char vptr_name
[] =
200 {'_', 'v', 'p', 't', 'r', CPLUS_MARKER
, '\0'};
201 static const char vb_name
[] =
202 {'_', 'v', 'b', CPLUS_MARKER
, '\0'};
204 /* Define this as 1 if a pcc declaration of a char or short argument
205 gives the correct address. Otherwise assume pcc gives the
206 address of the corresponding int, which is not the same on a
207 big-endian machine. */
209 #if !defined (BELIEVE_PCC_PROMOTION)
210 #define BELIEVE_PCC_PROMOTION 0
212 #if !defined (BELIEVE_PCC_PROMOTION_TYPE)
213 #define BELIEVE_PCC_PROMOTION_TYPE 0
216 static struct complaint invalid_cpp_abbrev_complaint
=
217 {"invalid C++ abbreviation `%s'", 0, 0};
219 static struct complaint invalid_cpp_type_complaint
=
220 {"C++ abbreviated type name unknown at symtab pos %d", 0, 0};
222 static struct complaint member_fn_complaint
=
223 {"member function type missing, got '%c'", 0, 0};
225 static struct complaint const_vol_complaint
=
226 {"const/volatile indicator missing, got '%c'", 0, 0};
228 static struct complaint error_type_complaint
=
229 {"debug info mismatch between compiler and debugger", 0, 0};
231 static struct complaint invalid_member_complaint
=
232 {"invalid (minimal) member type data format at symtab pos %d.", 0, 0};
234 static struct complaint range_type_base_complaint
=
235 {"base type %d of range type is not defined", 0, 0};
237 static struct complaint reg_value_complaint
=
238 {"register number %d too large (max %d) in symbol %s", 0, 0};
240 static struct complaint vtbl_notfound_complaint
=
241 {"virtual function table pointer not found when defining class `%s'", 0, 0};
243 static struct complaint unrecognized_cplus_name_complaint
=
244 {"Unknown C++ symbol name `%s'", 0, 0};
246 static struct complaint rs6000_builtin_complaint
=
247 {"Unknown builtin type %d", 0, 0};
249 static struct complaint unresolved_sym_chain_complaint
=
250 {"%s: common block `%s' from global_sym_chain unresolved", 0, 0};
252 static struct complaint stabs_general_complaint
=
255 static struct complaint lrs_general_complaint
=
258 /* Make a list of forward references which haven't been defined. */
260 static struct type
**undef_types
;
261 static int undef_types_allocated
;
262 static int undef_types_length
;
263 static struct symbol
*current_symbol
= NULL
;
265 /* Check for and handle cretinous stabs symbol name continuation! */
266 #define STABS_CONTINUE(pp,objfile) \
268 if (**(pp) == '\\' || (**(pp) == '?' && (*(pp))[1] == '\0')) \
269 *(pp) = next_symbol_text (objfile); \
272 /* FIXME: These probably should be our own types (like rs6000_builtin_type
273 has its own types) rather than builtin_type_*. */
274 static struct type
**os9k_type_vector
[] =
281 &builtin_type_unsigned_char
,
282 &builtin_type_unsigned_short
,
283 &builtin_type_unsigned_long
,
284 &builtin_type_unsigned_int
,
286 &builtin_type_double
,
288 &builtin_type_long_double
291 static void os9k_init_type_vector
PARAMS ((struct type
**));
294 os9k_init_type_vector (tv
)
298 for (i
= 0; i
< sizeof (os9k_type_vector
) / sizeof (struct type
**); i
++)
299 tv
[i
] = (os9k_type_vector
[i
] == 0 ? 0 : *(os9k_type_vector
[i
]));
302 /* Look up a dbx type-number pair. Return the address of the slot
303 where the type for that number-pair is stored.
304 The number-pair is in TYPENUMS.
306 This can be used for finding the type associated with that pair
307 or for associating a new type with the pair. */
310 dbx_lookup_type (typenums
)
313 register int filenum
= typenums
[0];
314 register int index
= typenums
[1];
316 register int real_filenum
;
317 register struct header_file
*f
;
320 if (filenum
== -1) /* -1,-1 is for temporary types. */
323 if (filenum
< 0 || filenum
>= n_this_object_header_files
)
325 static struct complaint msg
=
327 Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.",
329 complain (&msg
, filenum
, index
, symnum
);
337 /* Caller wants address of address of type. We think
338 that negative (rs6k builtin) types will never appear as
339 "lvalues", (nor should they), so we stuff the real type
340 pointer into a temp, and return its address. If referenced,
341 this will do the right thing. */
342 static struct type
*temp_type
;
344 temp_type
= rs6000_builtin_type (index
);
348 /* Type is defined outside of header files.
349 Find it in this object file's type vector. */
350 if (index
>= type_vector_length
)
352 old_len
= type_vector_length
;
355 type_vector_length
= INITIAL_TYPE_VECTOR_LENGTH
;
356 type_vector
= (struct type
**)
357 xmalloc (type_vector_length
* sizeof (struct type
*));
359 while (index
>= type_vector_length
)
361 type_vector_length
*= 2;
363 type_vector
= (struct type
**)
364 xrealloc ((char *) type_vector
,
365 (type_vector_length
* sizeof (struct type
*)));
366 memset (&type_vector
[old_len
], 0,
367 (type_vector_length
- old_len
) * sizeof (struct type
*));
370 /* Deal with OS9000 fundamental types. */
371 os9k_init_type_vector (type_vector
);
373 return (&type_vector
[index
]);
377 real_filenum
= this_object_header_files
[filenum
];
379 if (real_filenum
>= N_HEADER_FILES (current_objfile
))
381 struct type
*temp_type
;
382 struct type
**temp_type_p
;
384 warning ("GDB internal error: bad real_filenum");
387 temp_type
= init_type (TYPE_CODE_ERROR
, 0, 0, NULL
, NULL
);
388 temp_type_p
= (struct type
**) xmalloc (sizeof (struct type
*));
389 *temp_type_p
= temp_type
;
393 f
= HEADER_FILES (current_objfile
) + real_filenum
;
395 f_orig_length
= f
->length
;
396 if (index
>= f_orig_length
)
398 while (index
>= f
->length
)
402 f
->vector
= (struct type
**)
403 xrealloc ((char *) f
->vector
, f
->length
* sizeof (struct type
*));
404 memset (&f
->vector
[f_orig_length
], 0,
405 (f
->length
- f_orig_length
) * sizeof (struct type
*));
407 return (&f
->vector
[index
]);
411 /* Make sure there is a type allocated for type numbers TYPENUMS
412 and return the type object.
413 This can create an empty (zeroed) type object.
414 TYPENUMS may be (-1, -1) to return a new type object that is not
415 put into the type vector, and so may not be referred to by number. */
418 dbx_alloc_type (typenums
, objfile
)
420 struct objfile
*objfile
;
422 register struct type
**type_addr
;
424 if (typenums
[0] == -1)
426 return (alloc_type (objfile
));
429 type_addr
= dbx_lookup_type (typenums
);
431 /* If we are referring to a type not known at all yet,
432 allocate an empty type for it.
433 We will fill it in later if we find out how. */
436 *type_addr
= alloc_type (objfile
);
442 /* for all the stabs in a given stab vector, build appropriate types
443 and fix their symbols in given symbol vector. */
446 patch_block_stabs (symbols
, stabs
, objfile
)
447 struct pending
*symbols
;
448 struct pending_stabs
*stabs
;
449 struct objfile
*objfile
;
459 /* for all the stab entries, find their corresponding symbols and
460 patch their types! */
462 for (ii
= 0; ii
< stabs
->count
; ++ii
)
464 name
= stabs
->stab
[ii
];
465 pp
= (char *) strchr (name
, ':');
469 pp
= (char *) strchr (pp
, ':');
471 sym
= find_symbol_in_list (symbols
, name
, pp
- name
);
474 /* FIXME-maybe: it would be nice if we noticed whether
475 the variable was defined *anywhere*, not just whether
476 it is defined in this compilation unit. But neither
477 xlc or GCC seem to need such a definition, and until
478 we do psymtabs (so that the minimal symbols from all
479 compilation units are available now), I'm not sure
480 how to get the information. */
482 /* On xcoff, if a global is defined and never referenced,
483 ld will remove it from the executable. There is then
484 a N_GSYM stab for it, but no regular (C_EXT) symbol. */
485 sym
= (struct symbol
*)
486 obstack_alloc (&objfile
->symbol_obstack
,
487 sizeof (struct symbol
));
489 memset (sym
, 0, sizeof (struct symbol
));
490 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
491 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
493 obsavestring (name
, pp
- name
, &objfile
->symbol_obstack
);
495 if (*(pp
- 1) == 'F' || *(pp
- 1) == 'f')
497 /* I don't think the linker does this with functions,
498 so as far as I know this is never executed.
499 But it doesn't hurt to check. */
501 lookup_function_type (read_type (&pp
, objfile
));
505 SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
507 add_symbol_to_list (sym
, &global_symbols
);
512 if (*(pp
- 1) == 'F' || *(pp
- 1) == 'f')
515 lookup_function_type (read_type (&pp
, objfile
));
519 SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
527 /* Read a number by which a type is referred to in dbx data,
528 or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
529 Just a single number N is equivalent to (0,N).
530 Return the two numbers by storing them in the vector TYPENUMS.
531 TYPENUMS will then be used as an argument to dbx_lookup_type.
533 Returns 0 for success, -1 for error. */
536 read_type_number (pp
, typenums
)
538 register int *typenums
;
544 typenums
[0] = read_huge_number (pp
, ',', &nbits
);
547 typenums
[1] = read_huge_number (pp
, ')', &nbits
);
554 typenums
[1] = read_huge_number (pp
, 0, &nbits
);
562 #define VISIBILITY_PRIVATE '0' /* Stabs character for private field */
563 #define VISIBILITY_PROTECTED '1' /* Stabs character for protected fld */
564 #define VISIBILITY_PUBLIC '2' /* Stabs character for public field */
565 #define VISIBILITY_IGNORE '9' /* Optimized out or zero length */
567 #define CFRONT_VISIBILITY_PRIVATE '2' /* Stabs character for private field */
568 #define CFRONT_VISIBILITY_PUBLIC '1' /* Stabs character for public field */
570 /* This code added to support parsing of ARM/Cfront stabs strings */
572 /* Get substring from string up to char c, advance string pointer past
593 /* Physname gets strcat'd onto sname in order to recreate the mangled
594 name (see funtion gdb_mangle_name in gdbtypes.c). For cfront, make
595 the physname look like that of g++ - take out the initial mangling
596 eg: for sname="a" and fname="foo__1aFPFs_i" return "FPFs_i" */
599 get_cfront_method_physname (fname
)
603 /* FIXME would like to make this generic for g++ too, but
604 that is already handled in read_member_funcctions */
607 /* search ahead to find the start of the mangled suffix */
608 if (*p
== '_' && *(p
+ 1) == '_') /* compiler generated; probably a ctor/dtor */
610 while (p
&& (unsigned) ((p
+ 1) - fname
) < strlen (fname
) && *(p
+ 1) != '_')
612 if (!(p
&& *p
== '_' && *(p
+ 1) == '_'))
613 error ("Invalid mangled function name %s", fname
);
614 p
+= 2; /* advance past '__' */
616 /* struct name length and name of type should come next; advance past it */
619 len
= len
* 10 + (*p
- '0');
627 /* Read base classes within cfront class definition.
628 eg: A:ZcA;1@Bpub v2@Bvirpri;__ct__1AFv func__1AFv *sfunc__1AFv ;as__1A ;;
631 A:ZcA;;foopri__1AFv foopro__1AFv __ct__1AFv __ct__1AFRC1A foopub__1AFv ;;;
636 read_cfront_baseclasses (fip
, pp
, type
, objfile
)
637 struct field_info
*fip
;
638 struct objfile
*objfile
;
642 static struct complaint msg_unknown
=
644 Unsupported token in stabs string %s.\n",
646 static struct complaint msg_notfound
=
648 Unable to find base type for %s.\n",
653 struct nextfield
*new;
655 if (**pp
== ';') /* no base classes; return */
661 /* first count base classes so we can allocate space before parsing */
662 for (p
= *pp
; p
&& *p
&& *p
!= ';'; p
++)
667 bnum
++; /* add one more for last one */
669 /* now parse the base classes until we get to the start of the methods
670 (code extracted and munged from read_baseclasses) */
671 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
672 TYPE_N_BASECLASSES (type
) = bnum
;
676 int num_bytes
= B_BYTES (TYPE_N_BASECLASSES (type
));
679 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
680 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
682 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), TYPE_N_BASECLASSES (type
));
684 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
686 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
687 make_cleanup (free
, new);
688 memset (new, 0, sizeof (struct nextfield
));
689 new->next
= fip
->list
;
691 FIELD_BITSIZE (new->field
) = 0; /* this should be an unpacked field! */
693 STABS_CONTINUE (pp
, objfile
);
695 /* virtual? eg: v2@Bvir */
698 SET_TYPE_FIELD_VIRTUAL (type
, i
);
702 /* access? eg: 2@Bvir */
703 /* Note: protected inheritance not supported in cfront */
706 case CFRONT_VISIBILITY_PRIVATE
:
707 new->visibility
= VISIBILITY_PRIVATE
;
709 case CFRONT_VISIBILITY_PUBLIC
:
710 new->visibility
= VISIBILITY_PUBLIC
;
713 /* Bad visibility format. Complain and treat it as
716 static struct complaint msg
=
718 "Unknown visibility `%c' for baseclass", 0, 0};
719 complain (&msg
, new->visibility
);
720 new->visibility
= VISIBILITY_PUBLIC
;
724 /* "@" comes next - eg: @Bvir */
727 complain (&msg_unknown
, *pp
);
733 /* Set the bit offset of the portion of the object corresponding
734 to this baseclass. Always zero in the absence of
735 multiple inheritance. */
736 /* Unable to read bit position from stabs;
737 Assuming no multiple inheritance for now FIXME! */
738 /* We may have read this in the structure definition;
739 now we should fixup the members to be the actual base classes */
740 FIELD_BITPOS (new->field
) = 0;
742 /* Get the base class name and type */
744 char *bname
; /* base class name */
745 struct symbol
*bsym
; /* base class */
747 p1
= strchr (*pp
, ' ');
748 p2
= strchr (*pp
, ';');
750 bname
= get_substring (pp
, ' ');
752 bname
= get_substring (pp
, ';');
753 if (!bname
|| !*bname
)
755 complain (&msg_unknown
, *pp
);
758 /* FIXME! attach base info to type */
759 bsym
= lookup_symbol (bname
, 0, STRUCT_NAMESPACE
, 0, 0); /*demangled_name */
762 new->field
.type
= SYMBOL_TYPE (bsym
);
763 new->field
.name
= type_name_no_tag (new->field
.type
);
767 complain (&msg_notfound
, *pp
);
772 /* If more base classes to parse, loop again.
773 We ate the last ' ' or ';' in get_substring,
774 so on exit we will have skipped the trailing ';' */
775 /* if invalid, return 0; add code to detect - FIXME! */
780 /* read cfront member functions.
781 pp points to string starting with list of functions
782 eg: A:ZcA;1@Bpub v2@Bvirpri;__ct__1AFv func__1AFv *sfunc__1AFv ;as__1A ;;
783 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
784 A:ZcA;;foopri__1AFv foopro__1AFv __ct__1AFv __ct__1AFRC1A foopub__1AFv ;;;
785 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
789 read_cfront_member_functions (fip
, pp
, type
, objfile
)
790 struct field_info
*fip
;
793 struct objfile
*objfile
;
795 /* This code extracted from read_member_functions
796 so as to do the similar thing for our funcs */
800 /* Total number of member functions defined in this class. If the class
801 defines two `f' functions, and one `g' function, then this will have
803 int total_length
= 0;
807 struct next_fnfield
*next
;
808 struct fn_field fn_field
;
811 struct type
*look_ahead_type
;
812 struct next_fnfieldlist
*new_fnlist
;
813 struct next_fnfield
*new_sublist
;
816 struct symbol
*ref_func
= 0;
818 /* Process each list until we find the end of the member functions.
819 eg: p = "__ct__1AFv foo__1AFv ;;;" */
821 STABS_CONTINUE (pp
, objfile
); /* handle \\ */
823 while (**pp
!= ';' && (fname
= get_substring (pp
, ' '), fname
))
826 int sublist_count
= 0;
828 if (fname
[0] == '*') /* static member */
834 ref_func
= lookup_symbol (fname
, 0, VAR_NAMESPACE
, 0, 0); /* demangled name */
837 static struct complaint msg
=
839 Unable to find function symbol for %s\n",
841 complain (&msg
, fname
);
845 look_ahead_type
= NULL
;
848 new_fnlist
= (struct next_fnfieldlist
*)
849 xmalloc (sizeof (struct next_fnfieldlist
));
850 make_cleanup (free
, new_fnlist
);
851 memset (new_fnlist
, 0, sizeof (struct next_fnfieldlist
));
853 /* The following is code to work around cfront generated stabs.
854 The stabs contains full mangled name for each field.
855 We try to demangle the name and extract the field name out of it. */
857 char *dem
, *dem_p
, *dem_args
;
859 dem
= cplus_demangle (fname
, DMGL_ANSI
| DMGL_PARAMS
);
862 dem_p
= strrchr (dem
, ':');
863 if (dem_p
!= 0 && *(dem_p
- 1) == ':')
865 /* get rid of args */
866 dem_args
= strchr (dem_p
, '(');
867 if (dem_args
== NULL
)
868 dem_len
= strlen (dem_p
);
870 dem_len
= dem_args
- dem_p
;
872 obsavestring (dem_p
, dem_len
, &objfile
->type_obstack
);
877 obsavestring (fname
, strlen (fname
), &objfile
->type_obstack
);
879 } /* end of code for cfront work around */
881 new_fnlist
->fn_fieldlist
.name
= main_fn_name
;
883 /*-------------------------------------------------*/
884 /* Set up the sublists
885 Sublists are stuff like args, static, visibility, etc.
886 so in ARM, we have to set that info some other way.
887 Multiple sublists happen if overloading
888 eg: foo::26=##1;:;2A.;
889 In g++, we'd loop here thru all the sublists... */
892 (struct next_fnfield
*) xmalloc (sizeof (struct next_fnfield
));
893 make_cleanup (free
, new_sublist
);
894 memset (new_sublist
, 0, sizeof (struct next_fnfield
));
896 /* eat 1; from :;2A.; */
897 new_sublist
->fn_field
.type
= SYMBOL_TYPE (ref_func
); /* normally takes a read_type */
898 /* Make this type look like a method stub for gdb */
899 TYPE_FLAGS (new_sublist
->fn_field
.type
) |= TYPE_FLAG_STUB
;
900 TYPE_CODE (new_sublist
->fn_field
.type
) = TYPE_CODE_METHOD
;
902 /* If this is just a stub, then we don't have the real name here. */
903 if (TYPE_FLAGS (new_sublist
->fn_field
.type
) & TYPE_FLAG_STUB
)
905 if (!TYPE_DOMAIN_TYPE (new_sublist
->fn_field
.type
))
906 TYPE_DOMAIN_TYPE (new_sublist
->fn_field
.type
) = type
;
907 new_sublist
->fn_field
.is_stub
= 1;
910 /* physname used later in mangling; eg PFs_i,5 for foo__1aFPFs_i
911 physname gets strcat'd in order to recreate the onto mangled name */
912 pname
= get_cfront_method_physname (fname
);
913 new_sublist
->fn_field
.physname
= savestring (pname
, strlen (pname
));
916 /* Set this member function's visibility fields.
917 Unable to distinguish access from stabs definition!
918 Assuming public for now. FIXME!
919 (for private, set new_sublist->fn_field.is_private = 1,
920 for public, set new_sublist->fn_field.is_protected = 1) */
922 /* Unable to distinguish const/volatile from stabs definition!
923 Assuming normal for now. FIXME! */
925 new_sublist
->fn_field
.is_const
= 0;
926 new_sublist
->fn_field
.is_volatile
= 0; /* volatile not implemented in cfront */
928 /* Set virtual/static function info
929 How to get vtable offsets ?
930 Assuming normal for now FIXME!!
931 For vtables, figure out from whence this virtual function came.
932 It may belong to virtual function table of
933 one of its baseclasses.
935 new_sublist -> fn_field.voffset = vtable offset,
936 new_sublist -> fn_field.fcontext = look_ahead_type;
937 where look_ahead_type is type of baseclass */
939 new_sublist
->fn_field
.voffset
= VOFFSET_STATIC
;
940 else /* normal member function. */
941 new_sublist
->fn_field
.voffset
= 0;
942 new_sublist
->fn_field
.fcontext
= 0;
945 /* Prepare new sublist */
946 new_sublist
->next
= sublist
;
947 sublist
= new_sublist
;
950 /* In g++, we loop thu sublists - now we set from functions. */
951 new_fnlist
->fn_fieldlist
.fn_fields
= (struct fn_field
*)
952 obstack_alloc (&objfile
->type_obstack
,
953 sizeof (struct fn_field
) * length
);
954 memset (new_fnlist
->fn_fieldlist
.fn_fields
, 0,
955 sizeof (struct fn_field
) * length
);
956 for (i
= length
; (i
--, sublist
); sublist
= sublist
->next
)
958 new_fnlist
->fn_fieldlist
.fn_fields
[i
] = sublist
->fn_field
;
961 new_fnlist
->fn_fieldlist
.length
= length
;
962 new_fnlist
->next
= fip
->fnlist
;
963 fip
->fnlist
= new_fnlist
;
965 total_length
+= length
;
966 STABS_CONTINUE (pp
, objfile
); /* handle \\ */
971 /* type should already have space */
972 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
973 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * nfn_fields
);
974 memset (TYPE_FN_FIELDLISTS (type
), 0,
975 sizeof (struct fn_fieldlist
) * nfn_fields
);
976 TYPE_NFN_FIELDS (type
) = nfn_fields
;
977 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
980 /* end of scope for reading member func */
984 /* Skip trailing ';' and bump count of number of fields seen */
992 /* This routine fixes up partial cfront types that were created
993 while parsing the stabs. The main need for this function is
994 to add information such as methods to classes.
995 Examples of "p": "sA;;__ct__1AFv foo__1AFv ;;;" */
997 resolve_cfront_continuation (objfile
, sym
, p
)
998 struct objfile
*objfile
;
1002 struct symbol
*ref_sym
= 0;
1004 /* snarfed from read_struct_type */
1005 struct field_info fi
;
1007 struct cleanup
*back_to
;
1009 /* Need to make sure that fi isn't gunna conflict with struct
1010 in case struct already had some fnfs */
1013 back_to
= make_cleanup (null_cleanup
, 0);
1015 /* We only accept structs, classes and unions at the moment.
1016 Other continuation types include t (typedef), r (long dbl), ...
1017 We may want to add support for them as well;
1018 right now they are handled by duplicating the symbol information
1019 into the type information (see define_symbol) */
1020 if (*p
!= 's' /* structs */
1021 && *p
!= 'c' /* class */
1022 && *p
!= 'u') /* union */
1023 return 0; /* only handle C++ types */
1026 /* Get symbol typs name and validate
1027 eg: p = "A;;__ct__1AFv foo__1AFv ;;;" */
1028 sname
= get_substring (&p
, ';');
1029 if (!sname
|| strcmp (sname
, SYMBOL_NAME (sym
)))
1030 error ("Internal error: base symbol type name does not match\n");
1032 /* Find symbol's internal gdb reference using demangled_name.
1033 This is the real sym that we want;
1034 sym was a temp hack to make debugger happy */
1035 ref_sym
= lookup_symbol (SYMBOL_NAME (sym
), 0, STRUCT_NAMESPACE
, 0, 0);
1036 type
= SYMBOL_TYPE (ref_sym
);
1039 /* Now read the baseclasses, if any, read the regular C struct or C++
1040 class member fields, attach the fields to the type, read the C++
1041 member functions, attach them to the type, and then read any tilde
1042 field (baseclass specifier for the class holding the main vtable). */
1044 if (!read_cfront_baseclasses (&fi
, &p
, type
, objfile
)
1045 /* g++ does this next, but cfront already did this:
1046 || !read_struct_fields (&fi, &p, type, objfile) */
1047 || !copy_cfront_struct_fields (&fi
, type
, objfile
)
1048 || !read_cfront_member_functions (&fi
, &p
, type
, objfile
)
1049 || !read_cfront_static_fields (&fi
, &p
, type
, objfile
)
1050 || !attach_fields_to_type (&fi
, type
, objfile
)
1051 || !attach_fn_fields_to_type (&fi
, type
)
1052 /* g++ does this next, but cfront doesn't seem to have this:
1053 || !read_tilde_fields (&fi, &p, type, objfile) */
1056 type
= error_type (&p
, objfile
);
1059 do_cleanups (back_to
);
1062 /* End of code added to support parsing of ARM/Cfront stabs strings */
1065 /* This routine fixes up symbol references/aliases to point to the original
1066 symbol definition. Returns 0 on failure, non-zero on success. */
1069 resolve_symbol_reference (objfile
, sym
, p
)
1070 struct objfile
*objfile
;
1075 struct symbol
*ref_sym
= 0;
1076 struct alias_list
*alias
;
1078 /* If this is not a symbol reference return now. */
1082 /* Use "#<num>" as the name; we'll fix the name later.
1083 We stored the original symbol name as "#<id>=<name>"
1084 so we can now search for "#<id>" to resolving the reference.
1085 We'll fix the names later by removing the "#<id>" or "#<id>=" */
1087 /*---------------------------------------------------------*/
1088 /* Get the reference id number, and
1089 advance p past the names so we can parse the rest.
1090 eg: id=2 for p : "2=", "2=z:r(0,1)" "2:r(0,1);l(#5,#6),l(#7,#4)" */
1091 /*---------------------------------------------------------*/
1093 /* This gets reference name from string. sym may not have a name. */
1095 /* Get the reference number associated with the reference id in the
1096 gdb stab string. From that reference number, get the main/primary
1097 symbol for this alias. */
1098 refnum
= process_reference (&p
);
1099 ref_sym
= ref_search (refnum
);
1102 complain (&lrs_general_complaint
, "symbol for reference not found");
1106 /* Parse the stab of the referencing symbol
1107 now that we have the referenced symbol.
1108 Add it as a new symbol and a link back to the referenced symbol.
1109 eg: p : "=", "=z:r(0,1)" ":r(0,1);l(#5,#6),l(#7,#4)" */
1112 /* If the stab symbol table and string contain:
1113 RSYM 0 5 00000000 868 #15=z:r(0,1)
1114 LBRAC 0 0 00000000 899 #5=
1115 SLINE 0 16 00000003 923 #6=
1116 Then the same symbols can be later referenced by:
1117 RSYM 0 5 00000000 927 #15:r(0,1);l(#5,#6)
1118 This is used in live range splitting to:
1119 1) specify that a symbol (#15) is actually just a new storage
1120 class for a symbol (#15=z) which was previously defined.
1121 2) specify that the beginning and ending ranges for a symbol
1122 (#15) are the values of the beginning (#5) and ending (#6)
1125 /* Read number as reference id.
1126 eg: p : "=", "=z:r(0,1)" ":r(0,1);l(#5,#6),l(#7,#4)" */
1127 /* FIXME! Might I want to use SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
1128 in case of "l(0,0)"? */
1130 /*--------------------------------------------------*/
1131 /* Add this symbol to the reference list. */
1132 /*--------------------------------------------------*/
1134 alias
= (struct alias_list
*) obstack_alloc (&objfile
->type_obstack
,
1135 sizeof (struct alias_list
));
1138 complain (&lrs_general_complaint
, "Unable to allocate alias list memory");
1145 if (!SYMBOL_ALIASES (ref_sym
))
1147 SYMBOL_ALIASES (ref_sym
) = alias
;
1151 struct alias_list
*temp
;
1153 /* Get to the end of the list. */
1154 for (temp
= SYMBOL_ALIASES (ref_sym
);
1161 /* Want to fix up name so that other functions (eg. valops)
1162 will correctly print the name.
1163 Don't add_symbol_to_list so that lookup_symbol won't find it.
1164 nope... needed for fixups. */
1165 SYMBOL_NAME (sym
) = SYMBOL_NAME (ref_sym
);
1171 /* Structure for storing pointers to reference definitions for fast lookup
1172 during "process_later". */
1181 #define MAX_CHUNK_REFS 100
1182 #define REF_CHUNK_SIZE (MAX_CHUNK_REFS * sizeof (struct ref_map))
1183 #define REF_MAP_SIZE(ref_chunk) ((ref_chunk) * REF_CHUNK_SIZE)
1185 static struct ref_map
*ref_map
;
1187 /* Ptr to free cell in chunk's linked list. */
1188 static int ref_count
= 0;
1190 /* Number of chunks malloced. */
1191 static int ref_chunk
= 0;
1193 /* This file maintains a cache of stabs aliases found in the symbol
1194 table. If the symbol table changes, this cache must be cleared
1195 or we are left holding onto data in invalid obstacks. */
1197 stabsread_clear_cache ()
1203 /* Create array of pointers mapping refids to symbols and stab strings.
1204 Add pointers to reference definition symbols and/or their values as we
1205 find them, using their reference numbers as our index.
1206 These will be used later when we resolve references. */
1208 ref_add (refnum
, sym
, stabs
, value
)
1216 if (refnum
>= ref_count
)
1217 ref_count
= refnum
+ 1;
1218 if (ref_count
> ref_chunk
* MAX_CHUNK_REFS
)
1220 int new_slots
= ref_count
- ref_chunk
* MAX_CHUNK_REFS
;
1221 int new_chunks
= new_slots
/ MAX_CHUNK_REFS
+ 1;
1222 ref_map
= (struct ref_map
*)
1223 xrealloc (ref_map
, REF_MAP_SIZE (ref_chunk
+ new_chunks
));
1224 memset (ref_map
+ ref_chunk
* MAX_CHUNK_REFS
, 0, new_chunks
* REF_CHUNK_SIZE
);
1225 ref_chunk
+= new_chunks
;
1227 ref_map
[refnum
].stabs
= stabs
;
1228 ref_map
[refnum
].sym
= sym
;
1229 ref_map
[refnum
].value
= value
;
1232 /* Return defined sym for the reference REFNUM. */
1237 if (refnum
< 0 || refnum
> ref_count
)
1239 return ref_map
[refnum
].sym
;
1242 /* Return value for the reference REFNUM. */
1245 ref_search_value (refnum
)
1248 if (refnum
< 0 || refnum
> ref_count
)
1250 return ref_map
[refnum
].value
;
1253 /* Parse a reference id in STRING and return the resulting
1254 reference number. Move STRING beyond the reference id. */
1257 process_reference (string
)
1263 if (**string
!= '#')
1266 /* Advance beyond the initial '#'. */
1269 /* Read number as reference id. */
1270 while (*p
&& isdigit (*p
))
1272 refnum
= refnum
* 10 + *p
- '0';
1279 /* If STRING defines a reference, store away a pointer to the reference
1280 definition for later use. Return the reference number. */
1283 symbol_reference_defined (string
)
1289 refnum
= process_reference (&p
);
1291 /* Defining symbols end in '=' */
1294 /* Symbol is being defined here. */
1300 /* Must be a reference. Either the symbol has already been defined,
1301 or this is a forward reference to it. */
1309 define_symbol (valu
, string
, desc
, type
, objfile
)
1314 struct objfile
*objfile
;
1316 register struct symbol
*sym
;
1317 char *p
= (char *) strchr (string
, ':');
1322 /* We would like to eliminate nameless symbols, but keep their types.
1323 E.g. stab entry ":t10=*2" should produce a type 10, which is a pointer
1324 to type 2, but, should not create a symbol to address that type. Since
1325 the symbol will be nameless, there is no way any user can refer to it. */
1329 /* Ignore syms with empty names. */
1333 /* Ignore old-style symbols from cc -go */
1340 p
= strchr (p
, ':');
1343 /* If a nameless stab entry, all we need is the type, not the symbol.
1344 e.g. ":t10=*2" or a nameless enum like " :T16=ered:0,green:1,blue:2,;" */
1345 nameless
= (p
== string
|| ((string
[0] == ' ') && (string
[1] == ':')));
1347 current_symbol
= sym
= (struct symbol
*)
1348 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct symbol
));
1349 memset (sym
, 0, sizeof (struct symbol
));
1351 switch (type
& N_TYPE
)
1354 SYMBOL_SECTION (sym
) = SECT_OFF_TEXT (objfile
);
1357 SYMBOL_SECTION (sym
) = SECT_OFF_DATA (objfile
);
1360 SYMBOL_SECTION (sym
) = SECT_OFF_BSS (objfile
);
1364 if (processing_gcc_compilation
)
1366 /* GCC 2.x puts the line number in desc. SunOS apparently puts in the
1367 number of bytes occupied by a type or object, which we ignore. */
1368 SYMBOL_LINE (sym
) = desc
;
1372 SYMBOL_LINE (sym
) = 0; /* unknown */
1375 if (is_cplus_marker (string
[0]))
1377 /* Special GNU C++ names. */
1381 SYMBOL_NAME (sym
) = obsavestring ("this", strlen ("this"),
1382 &objfile
->symbol_obstack
);
1385 case 'v': /* $vtbl_ptr_type */
1386 /* Was: SYMBOL_NAME (sym) = "vptr"; */
1390 SYMBOL_NAME (sym
) = obsavestring ("eh_throw", strlen ("eh_throw"),
1391 &objfile
->symbol_obstack
);
1395 /* This was an anonymous type that was never fixed up. */
1398 #ifdef STATIC_TRANSFORM_NAME
1400 /* SunPRO (3.0 at least) static variable encoding. */
1405 complain (&unrecognized_cplus_name_complaint
, string
);
1406 goto normal
; /* Do *something* with it */
1409 else if (string
[0] == '#')
1411 /* Special GNU C extension for referencing symbols. */
1415 /* If STRING defines a new reference id, then add it to the
1416 reference map. Else it must be referring to a previously
1417 defined symbol, so add it to the alias list of the previously
1420 refnum
= symbol_reference_defined (&s
);
1422 ref_add (refnum
, sym
, string
, SYMBOL_VALUE (sym
));
1423 else if (!resolve_symbol_reference (objfile
, sym
, string
))
1426 /* S..P contains the name of the symbol. We need to store
1427 the correct name into SYMBOL_NAME. */
1433 SYMBOL_NAME (sym
) = (char *)
1434 obstack_alloc (&objfile
->symbol_obstack
, nlen
);
1435 strncpy (SYMBOL_NAME (sym
), s
, nlen
);
1436 SYMBOL_NAME (sym
)[nlen
] = '\0';
1437 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
1440 /* FIXME! Want SYMBOL_NAME (sym) = 0;
1441 Get error if leave name 0. So give it something. */
1444 SYMBOL_NAME (sym
) = (char *)
1445 obstack_alloc (&objfile
->symbol_obstack
, nlen
);
1446 strncpy (SYMBOL_NAME (sym
), string
, nlen
);
1447 SYMBOL_NAME (sym
)[nlen
] = '\0';
1448 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
1451 /* Advance STRING beyond the reference id. */
1457 SYMBOL_LANGUAGE (sym
) = current_subfile
->language
;
1458 SYMBOL_NAME (sym
) = (char *)
1459 obstack_alloc (&objfile
->symbol_obstack
, ((p
- string
) + 1));
1460 /* Open-coded memcpy--saves function call time. */
1461 /* FIXME: Does it really? Try replacing with simple strcpy and
1462 try it on an executable with a large symbol table. */
1463 /* FIXME: considering that gcc can open code memcpy anyway, I
1464 doubt it. xoxorich. */
1466 register char *p1
= string
;
1467 register char *p2
= SYMBOL_NAME (sym
);
1475 /* If this symbol is from a C++ compilation, then attempt to cache the
1476 demangled form for future reference. This is a typical time versus
1477 space tradeoff, that was decided in favor of time because it sped up
1478 C++ symbol lookups by a factor of about 20. */
1480 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
1484 /* Determine the type of name being defined. */
1486 /* Getting GDB to correctly skip the symbol on an undefined symbol
1487 descriptor and not ever dump core is a very dodgy proposition if
1488 we do things this way. I say the acorn RISC machine can just
1489 fix their compiler. */
1490 /* The Acorn RISC machine's compiler can put out locals that don't
1491 start with "234=" or "(3,4)=", so assume anything other than the
1492 deftypes we know how to handle is a local. */
1493 if (!strchr ("cfFGpPrStTvVXCR", *p
))
1495 if (isdigit (*p
) || *p
== '(' || *p
== '-')
1504 /* c is a special case, not followed by a type-number.
1505 SYMBOL:c=iVALUE for an integer constant symbol.
1506 SYMBOL:c=rVALUE for a floating constant symbol.
1507 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
1508 e.g. "b:c=e6,0" for "const b = blob1"
1509 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
1512 SYMBOL_CLASS (sym
) = LOC_CONST
;
1513 SYMBOL_TYPE (sym
) = error_type (&p
, objfile
);
1514 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1515 add_symbol_to_list (sym
, &file_symbols
);
1523 double d
= atof (p
);
1526 /* FIXME-if-picky-about-floating-accuracy: Should be using
1527 target arithmetic to get the value. real.c in GCC
1528 probably has the necessary code. */
1530 /* FIXME: lookup_fundamental_type is a hack. We should be
1531 creating a type especially for the type of float constants.
1532 Problem is, what type should it be?
1534 Also, what should the name of this type be? Should we
1535 be using 'S' constants (see stabs.texinfo) instead? */
1537 SYMBOL_TYPE (sym
) = lookup_fundamental_type (objfile
,
1540 obstack_alloc (&objfile
->symbol_obstack
,
1541 TYPE_LENGTH (SYMBOL_TYPE (sym
)));
1542 store_floating (dbl_valu
, TYPE_LENGTH (SYMBOL_TYPE (sym
)), d
);
1543 SYMBOL_VALUE_BYTES (sym
) = dbl_valu
;
1544 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
1549 /* Defining integer constants this way is kind of silly,
1550 since 'e' constants allows the compiler to give not
1551 only the value, but the type as well. C has at least
1552 int, long, unsigned int, and long long as constant
1553 types; other languages probably should have at least
1554 unsigned as well as signed constants. */
1556 /* We just need one int constant type for all objfiles.
1557 It doesn't depend on languages or anything (arguably its
1558 name should be a language-specific name for a type of
1559 that size, but I'm inclined to say that if the compiler
1560 wants a nice name for the type, it can use 'e'). */
1561 static struct type
*int_const_type
;
1563 /* Yes, this is as long as a *host* int. That is because we
1565 if (int_const_type
== NULL
)
1567 init_type (TYPE_CODE_INT
,
1568 sizeof (int) * HOST_CHAR_BIT
/ TARGET_CHAR_BIT
, 0,
1570 (struct objfile
*) NULL
);
1571 SYMBOL_TYPE (sym
) = int_const_type
;
1572 SYMBOL_VALUE (sym
) = atoi (p
);
1573 SYMBOL_CLASS (sym
) = LOC_CONST
;
1577 /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value
1578 can be represented as integral.
1579 e.g. "b:c=e6,0" for "const b = blob1"
1580 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
1582 SYMBOL_CLASS (sym
) = LOC_CONST
;
1583 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1587 SYMBOL_TYPE (sym
) = error_type (&p
, objfile
);
1592 /* If the value is too big to fit in an int (perhaps because
1593 it is unsigned), or something like that, we silently get
1594 a bogus value. The type and everything else about it is
1595 correct. Ideally, we should be using whatever we have
1596 available for parsing unsigned and long long values,
1598 SYMBOL_VALUE (sym
) = atoi (p
);
1603 SYMBOL_CLASS (sym
) = LOC_CONST
;
1604 SYMBOL_TYPE (sym
) = error_type (&p
, objfile
);
1607 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1608 add_symbol_to_list (sym
, &file_symbols
);
1612 /* The name of a caught exception. */
1613 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1614 SYMBOL_CLASS (sym
) = LOC_LABEL
;
1615 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1616 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1617 add_symbol_to_list (sym
, &local_symbols
);
1621 /* A static function definition. */
1622 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1623 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1624 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1625 add_symbol_to_list (sym
, &file_symbols
);
1626 /* fall into process_function_types. */
1628 process_function_types
:
1629 /* Function result types are described as the result type in stabs.
1630 We need to convert this to the function-returning-type-X type
1631 in GDB. E.g. "int" is converted to "function returning int". */
1632 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_FUNC
)
1633 SYMBOL_TYPE (sym
) = lookup_function_type (SYMBOL_TYPE (sym
));
1635 /* All functions in C++ have prototypes. */
1636 if (SYMBOL_LANGUAGE (sym
) == language_cplus
)
1637 TYPE_FLAGS (SYMBOL_TYPE (sym
)) |= TYPE_FLAG_PROTOTYPED
;
1639 /* fall into process_prototype_types */
1641 process_prototype_types
:
1642 /* Sun acc puts declared types of arguments here. */
1645 struct type
*ftype
= SYMBOL_TYPE (sym
);
1650 /* Obtain a worst case guess for the number of arguments
1651 by counting the semicolons. */
1658 /* Allocate parameter information fields and fill them in. */
1659 TYPE_FIELDS (ftype
) = (struct field
*)
1660 TYPE_ALLOC (ftype
, nsemi
* sizeof (struct field
));
1665 /* A type number of zero indicates the start of varargs.
1666 FIXME: GDB currently ignores vararg functions. */
1667 if (p
[0] == '0' && p
[1] == '\0')
1669 ptype
= read_type (&p
, objfile
);
1671 /* The Sun compilers mark integer arguments, which should
1672 be promoted to the width of the calling conventions, with
1673 a type which references itself. This type is turned into
1674 a TYPE_CODE_VOID type by read_type, and we have to turn
1675 it back into builtin_type_int here.
1676 FIXME: Do we need a new builtin_type_promoted_int_arg ? */
1677 if (TYPE_CODE (ptype
) == TYPE_CODE_VOID
)
1678 ptype
= builtin_type_int
;
1679 TYPE_FIELD_TYPE (ftype
, nparams
++) = ptype
;
1681 TYPE_NFIELDS (ftype
) = nparams
;
1682 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
1687 /* A global function definition. */
1688 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1689 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1690 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1691 add_symbol_to_list (sym
, &global_symbols
);
1692 goto process_function_types
;
1695 /* For a class G (global) symbol, it appears that the
1696 value is not correct. It is necessary to search for the
1697 corresponding linker definition to find the value.
1698 These definitions appear at the end of the namelist. */
1699 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1700 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1701 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1702 /* Don't add symbol references to global_sym_chain.
1703 Symbol references don't have valid names and wont't match up with
1704 minimal symbols when the global_sym_chain is relocated.
1705 We'll fixup symbol references when we fixup the defining symbol. */
1706 if (SYMBOL_NAME (sym
) && SYMBOL_NAME (sym
)[0] != '#')
1708 i
= hashname (SYMBOL_NAME (sym
));
1709 SYMBOL_VALUE_CHAIN (sym
) = global_sym_chain
[i
];
1710 global_sym_chain
[i
] = sym
;
1712 add_symbol_to_list (sym
, &global_symbols
);
1715 /* This case is faked by a conditional above,
1716 when there is no code letter in the dbx data.
1717 Dbx data never actually contains 'l'. */
1720 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1721 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1722 SYMBOL_VALUE (sym
) = valu
;
1723 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1724 add_symbol_to_list (sym
, &local_symbols
);
1729 /* pF is a two-letter code that means a function parameter in Fortran.
1730 The type-number specifies the type of the return value.
1731 Translate it into a pointer-to-function type. */
1735 = lookup_pointer_type
1736 (lookup_function_type (read_type (&p
, objfile
)));
1739 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1741 /* Normally this is a parameter, a LOC_ARG. On the i960, it
1742 can also be a LOC_LOCAL_ARG depending on symbol type. */
1743 #ifndef DBX_PARM_SYMBOL_CLASS
1744 #define DBX_PARM_SYMBOL_CLASS(type) LOC_ARG
1747 SYMBOL_CLASS (sym
) = DBX_PARM_SYMBOL_CLASS (type
);
1748 SYMBOL_VALUE (sym
) = valu
;
1749 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1750 add_symbol_to_list (sym
, &local_symbols
);
1752 if (TARGET_BYTE_ORDER
!= BIG_ENDIAN
)
1754 /* On little-endian machines, this crud is never necessary,
1755 and, if the extra bytes contain garbage, is harmful. */
1759 /* If it's gcc-compiled, if it says `short', believe it. */
1760 if (processing_gcc_compilation
|| BELIEVE_PCC_PROMOTION
)
1763 if (!BELIEVE_PCC_PROMOTION
)
1765 /* This is the signed type which arguments get promoted to. */
1766 static struct type
*pcc_promotion_type
;
1767 /* This is the unsigned type which arguments get promoted to. */
1768 static struct type
*pcc_unsigned_promotion_type
;
1770 /* Call it "int" because this is mainly C lossage. */
1771 if (pcc_promotion_type
== NULL
)
1772 pcc_promotion_type
=
1773 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
1776 if (pcc_unsigned_promotion_type
== NULL
)
1777 pcc_unsigned_promotion_type
=
1778 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
1779 TYPE_FLAG_UNSIGNED
, "unsigned int", NULL
);
1781 if (BELIEVE_PCC_PROMOTION_TYPE
)
1783 /* This is defined on machines (e.g. sparc) where we
1784 should believe the type of a PCC 'short' argument,
1785 but shouldn't believe the address (the address is the
1786 address of the corresponding int).
1788 My guess is that this correction, as opposed to
1789 changing the parameter to an 'int' (as done below,
1790 for PCC on most machines), is the right thing to do
1791 on all machines, but I don't want to risk breaking
1792 something that already works. On most PCC machines,
1793 the sparc problem doesn't come up because the calling
1794 function has to zero the top bytes (not knowing
1795 whether the called function wants an int or a short),
1796 so there is little practical difference between an
1797 int and a short (except perhaps what happens when the
1798 GDB user types "print short_arg = 0x10000;").
1800 Hacked for SunOS 4.1 by gnu@cygnus.com. In 4.1, the
1801 compiler actually produces the correct address (we
1802 don't need to fix it up). I made this code adapt so
1803 that it will offset the symbol if it was pointing at
1804 an int-aligned location and not otherwise. This way
1805 you can use the same gdb for 4.0.x and 4.1 systems.
1807 If the parameter is shorter than an int, and is
1808 integral (e.g. char, short, or unsigned equivalent),
1809 and is claimed to be passed on an integer boundary,
1810 don't believe it! Offset the parameter's address to
1811 the tail-end of that integer. */
1813 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (pcc_promotion_type
)
1814 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
1815 && 0 == SYMBOL_VALUE (sym
) % TYPE_LENGTH (pcc_promotion_type
))
1817 SYMBOL_VALUE (sym
) += TYPE_LENGTH (pcc_promotion_type
)
1818 - TYPE_LENGTH (SYMBOL_TYPE (sym
));
1824 /* If PCC says a parameter is a short or a char,
1825 it is really an int. */
1826 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (pcc_promotion_type
)
1827 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
)
1830 TYPE_UNSIGNED (SYMBOL_TYPE (sym
))
1831 ? pcc_unsigned_promotion_type
1832 : pcc_promotion_type
;
1839 /* acc seems to use P to declare the prototypes of functions that
1840 are referenced by this file. gdb is not prepared to deal
1841 with this extra information. FIXME, it ought to. */
1844 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1845 goto process_prototype_types
;
1850 /* Parameter which is in a register. */
1851 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1852 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
1853 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
1854 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
1856 complain (®_value_complaint
, SYMBOL_VALUE (sym
), NUM_REGS
,
1857 SYMBOL_SOURCE_NAME (sym
));
1858 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
1860 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1861 add_symbol_to_list (sym
, &local_symbols
);
1865 /* Register variable (either global or local). */
1866 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1867 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
1868 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
1869 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
1871 complain (®_value_complaint
, SYMBOL_VALUE (sym
), NUM_REGS
,
1872 SYMBOL_SOURCE_NAME (sym
));
1873 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
1875 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1876 if (within_function
)
1878 /* Sun cc uses a pair of symbols, one 'p' and one 'r' with the same
1879 name to represent an argument passed in a register.
1880 GCC uses 'P' for the same case. So if we find such a symbol pair
1881 we combine it into one 'P' symbol. For Sun cc we need to do this
1882 regardless of REG_STRUCT_HAS_ADDR, because the compiler puts out
1883 the 'p' symbol even if it never saves the argument onto the stack.
1885 On most machines, we want to preserve both symbols, so that
1886 we can still get information about what is going on with the
1887 stack (VAX for computing args_printed, using stack slots instead
1888 of saved registers in backtraces, etc.).
1890 Note that this code illegally combines
1891 main(argc) struct foo argc; { register struct foo argc; }
1892 but this case is considered pathological and causes a warning
1893 from a decent compiler. */
1896 && local_symbols
->nsyms
> 0
1897 #ifndef USE_REGISTER_NOT_ARG
1898 && REG_STRUCT_HAS_ADDR_P ()
1899 && REG_STRUCT_HAS_ADDR (processing_gcc_compilation
,
1901 && (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
1902 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
1903 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_SET
1904 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_BITSTRING
)
1908 struct symbol
*prev_sym
;
1909 prev_sym
= local_symbols
->symbol
[local_symbols
->nsyms
- 1];
1910 if ((SYMBOL_CLASS (prev_sym
) == LOC_REF_ARG
1911 || SYMBOL_CLASS (prev_sym
) == LOC_ARG
)
1912 && STREQ (SYMBOL_NAME (prev_sym
), SYMBOL_NAME (sym
)))
1914 SYMBOL_CLASS (prev_sym
) = LOC_REGPARM
;
1915 /* Use the type from the LOC_REGISTER; that is the type
1916 that is actually in that register. */
1917 SYMBOL_TYPE (prev_sym
) = SYMBOL_TYPE (sym
);
1918 SYMBOL_VALUE (prev_sym
) = SYMBOL_VALUE (sym
);
1923 add_symbol_to_list (sym
, &local_symbols
);
1926 add_symbol_to_list (sym
, &file_symbols
);
1930 /* Static symbol at top level of file */
1931 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1932 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1933 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1934 #ifdef STATIC_TRANSFORM_NAME
1935 if (IS_STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym
)))
1937 struct minimal_symbol
*msym
;
1938 msym
= lookup_minimal_symbol (SYMBOL_NAME (sym
), NULL
, objfile
);
1941 SYMBOL_NAME (sym
) = STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym
));
1942 SYMBOL_VALUE_ADDRESS (sym
) = SYMBOL_VALUE_ADDRESS (msym
);
1946 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1947 add_symbol_to_list (sym
, &file_symbols
);
1951 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1953 /* For a nameless type, we don't want a create a symbol, thus we
1954 did not use `sym'. Return without further processing. */
1958 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1959 SYMBOL_VALUE (sym
) = valu
;
1960 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1961 /* C++ vagaries: we may have a type which is derived from
1962 a base type which did not have its name defined when the
1963 derived class was output. We fill in the derived class's
1964 base part member's name here in that case. */
1965 if (TYPE_NAME (SYMBOL_TYPE (sym
)) != NULL
)
1966 if ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
1967 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
)
1968 && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)))
1971 for (j
= TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)) - 1; j
>= 0; j
--)
1972 if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) == 0)
1973 TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) =
1974 type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym
), j
));
1977 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == NULL
)
1979 /* gcc-2.6 or later (when using -fvtable-thunks)
1980 emits a unique named type for a vtable entry.
1981 Some gdb code depends on that specific name. */
1982 extern const char vtbl_ptr_name
[];
1984 if ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_PTR
1985 && strcmp (SYMBOL_NAME (sym
), vtbl_ptr_name
))
1986 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_FUNC
)
1988 /* If we are giving a name to a type such as "pointer to
1989 foo" or "function returning foo", we better not set
1990 the TYPE_NAME. If the program contains "typedef char
1991 *caddr_t;", we don't want all variables of type char
1992 * to print as caddr_t. This is not just a
1993 consequence of GDB's type management; PCC and GCC (at
1994 least through version 2.4) both output variables of
1995 either type char * or caddr_t with the type number
1996 defined in the 't' symbol for caddr_t. If a future
1997 compiler cleans this up it GDB is not ready for it
1998 yet, but if it becomes ready we somehow need to
1999 disable this check (without breaking the PCC/GCC2.4
2004 Fortunately, this check seems not to be necessary
2005 for anything except pointers or functions. */
2008 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_NAME (sym
);
2011 add_symbol_to_list (sym
, &file_symbols
);
2015 /* Struct, union, or enum tag. For GNU C++, this can be be followed
2016 by 't' which means we are typedef'ing it as well. */
2017 synonym
= *p
== 't';
2021 /* The semantics of C++ state that "struct foo { ... }" also defines
2022 a typedef for "foo". Unfortunately, cfront never makes the typedef
2023 when translating C++ into C. We make the typedef here so that
2024 "ptype foo" works as expected for cfront translated code. */
2025 else if (current_subfile
->language
== language_cplus
)
2028 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
2030 /* For a nameless type, we don't want a create a symbol, thus we
2031 did not use `sym'. Return without further processing. */
2035 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
2036 SYMBOL_VALUE (sym
) = valu
;
2037 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
2038 if (TYPE_TAG_NAME (SYMBOL_TYPE (sym
)) == 0)
2039 TYPE_TAG_NAME (SYMBOL_TYPE (sym
))
2040 = obconcat (&objfile
->type_obstack
, "", "", SYMBOL_NAME (sym
));
2041 add_symbol_to_list (sym
, &file_symbols
);
2045 /* Clone the sym and then modify it. */
2046 register struct symbol
*typedef_sym
= (struct symbol
*)
2047 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct symbol
));
2048 *typedef_sym
= *sym
;
2049 SYMBOL_CLASS (typedef_sym
) = LOC_TYPEDEF
;
2050 SYMBOL_VALUE (typedef_sym
) = valu
;
2051 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
2052 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
2053 TYPE_NAME (SYMBOL_TYPE (sym
))
2054 = obconcat (&objfile
->type_obstack
, "", "", SYMBOL_NAME (sym
));
2055 add_symbol_to_list (typedef_sym
, &file_symbols
);
2060 /* Static symbol of local scope */
2061 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
2062 SYMBOL_CLASS (sym
) = LOC_STATIC
;
2063 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
2064 #ifdef STATIC_TRANSFORM_NAME
2065 if (IS_STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym
)))
2067 struct minimal_symbol
*msym
;
2068 msym
= lookup_minimal_symbol (SYMBOL_NAME (sym
), NULL
, objfile
);
2071 SYMBOL_NAME (sym
) = STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym
));
2072 SYMBOL_VALUE_ADDRESS (sym
) = SYMBOL_VALUE_ADDRESS (msym
);
2076 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2078 add_symbol_to_list (sym
, &global_symbols
);
2080 add_symbol_to_list (sym
, &local_symbols
);
2084 /* Reference parameter */
2085 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
2086 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
2087 SYMBOL_VALUE (sym
) = valu
;
2088 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2089 add_symbol_to_list (sym
, &local_symbols
);
2093 /* Reference parameter which is in a register. */
2094 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
2095 SYMBOL_CLASS (sym
) = LOC_REGPARM_ADDR
;
2096 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
2097 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
2099 complain (®_value_complaint
, SYMBOL_VALUE (sym
), NUM_REGS
,
2100 SYMBOL_SOURCE_NAME (sym
));
2101 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
2103 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2104 add_symbol_to_list (sym
, &local_symbols
);
2108 /* This is used by Sun FORTRAN for "function result value".
2109 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
2110 that Pascal uses it too, but when I tried it Pascal used
2111 "x:3" (local symbol) instead. */
2112 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
2113 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
2114 SYMBOL_VALUE (sym
) = valu
;
2115 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2116 add_symbol_to_list (sym
, &local_symbols
);
2119 /* New code added to support cfront stabs strings.
2120 Note: case 'P' already handled above */
2122 /* Cfront type continuation coming up!
2123 Find the original definition and add to it.
2124 We'll have to do this for the typedef too,
2125 since we cloned the symbol to define a type in read_type.
2126 Stabs info examples:
2128 foo__1CFv :ZtF (first def foo__1CFv:F(0,3);(0,24))
2129 C:ZsC;;__ct__1CFv func1__1CFv func2__1CFv ... ;;;
2130 where C is the name of the class.
2131 Unfortunately, we can't lookup the original symbol yet 'cuz
2132 we haven't finished reading all the symbols.
2133 Instead, we save it for processing later */
2134 process_later (sym
, p
, resolve_cfront_continuation
);
2135 SYMBOL_TYPE (sym
) = error_type (&p
, objfile
); /* FIXME! change later */
2136 SYMBOL_CLASS (sym
) = LOC_CONST
;
2137 SYMBOL_VALUE (sym
) = 0;
2138 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2139 /* Don't add to list - we'll delete it later when
2140 we add the continuation to the real sym */
2142 /* End of new code added to support cfront stabs strings */
2145 SYMBOL_TYPE (sym
) = error_type (&p
, objfile
);
2146 SYMBOL_CLASS (sym
) = LOC_CONST
;
2147 SYMBOL_VALUE (sym
) = 0;
2148 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2149 add_symbol_to_list (sym
, &file_symbols
);
2153 /* When passing structures to a function, some systems sometimes pass
2154 the address in a register, not the structure itself. */
2156 if (REG_STRUCT_HAS_ADDR_P ()
2157 && REG_STRUCT_HAS_ADDR (processing_gcc_compilation
, SYMBOL_TYPE (sym
))
2158 && (SYMBOL_CLASS (sym
) == LOC_REGPARM
|| SYMBOL_CLASS (sym
) == LOC_ARG
))
2160 struct type
*symbol_type
= check_typedef (SYMBOL_TYPE (sym
));
2162 if ((TYPE_CODE (symbol_type
) == TYPE_CODE_STRUCT
)
2163 || (TYPE_CODE (symbol_type
) == TYPE_CODE_UNION
)
2164 || (TYPE_CODE (symbol_type
) == TYPE_CODE_BITSTRING
)
2165 || (TYPE_CODE (symbol_type
) == TYPE_CODE_SET
))
2167 /* If REG_STRUCT_HAS_ADDR yields non-zero we have to convert
2168 LOC_REGPARM to LOC_REGPARM_ADDR for structures and unions. */
2169 if (SYMBOL_CLASS (sym
) == LOC_REGPARM
)
2170 SYMBOL_CLASS (sym
) = LOC_REGPARM_ADDR
;
2171 /* Likewise for converting LOC_ARG to LOC_REF_ARG (for the 7th
2172 and subsequent arguments on the sparc, for example). */
2173 else if (SYMBOL_CLASS (sym
) == LOC_ARG
)
2174 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
2178 /* Is there more to parse? For example LRS/alias information? */
2179 while (*p
&& *p
== ';')
2182 if (*p
&& p
[0] == 'l' && p
[1] == '(')
2184 /* GNU extensions for live range splitting may be appended to
2185 the end of the stab string. eg. "l(#1,#2);l(#3,#5)" */
2187 /* Resolve the live range and add it to SYM's live range list. */
2188 if (!resolve_live_range (objfile
, sym
, p
))
2191 /* Find end of live range info. */
2192 p
= strchr (p
, ')');
2193 if (!*p
|| *p
!= ')')
2195 complain (&lrs_general_complaint
, "live range format not recognized");
2204 /* Add the live range found in P to the symbol SYM in objfile OBJFILE. Returns
2205 non-zero on success, zero otherwise. */
2208 resolve_live_range (objfile
, sym
, p
)
2209 struct objfile
*objfile
;
2214 CORE_ADDR start
, end
;
2216 /* Sanity check the beginning of the stabs string. */
2217 if (!*p
|| *p
!= 'l')
2219 complain (&lrs_general_complaint
, "live range string 1");
2224 if (!*p
|| *p
!= '(')
2226 complain (&lrs_general_complaint
, "live range string 2");
2231 /* Get starting value of range and advance P past the reference id.
2233 ?!? In theory, the process_reference should never fail, but we should
2234 catch that case just in case the compiler scrogged the stabs. */
2235 refnum
= process_reference (&p
);
2236 start
= ref_search_value (refnum
);
2239 complain (&lrs_general_complaint
, "Live range symbol not found 1");
2243 if (!*p
|| *p
!= ',')
2245 complain (&lrs_general_complaint
, "live range string 3");
2250 /* Get ending value of range and advance P past the reference id.
2252 ?!? In theory, the process_reference should never fail, but we should
2253 catch that case just in case the compiler scrogged the stabs. */
2254 refnum
= process_reference (&p
);
2255 end
= ref_search_value (refnum
);
2258 complain (&lrs_general_complaint
, "Live range symbol not found 2");
2262 if (!*p
|| *p
!= ')')
2264 complain (&lrs_general_complaint
, "live range string 4");
2268 /* Now that we know the bounds of the range, add it to the
2270 add_live_range (objfile
, sym
, start
, end
);
2275 /* Add a new live range defined by START and END to the symbol SYM
2276 in objfile OBJFILE. */
2279 add_live_range (objfile
, sym
, start
, end
)
2280 struct objfile
*objfile
;
2282 CORE_ADDR start
, end
;
2284 struct range_list
*r
, *rs
;
2288 complain (&lrs_general_complaint
, "end of live range follows start");
2292 /* Alloc new live range structure. */
2293 r
= (struct range_list
*)
2294 obstack_alloc (&objfile
->type_obstack
,
2295 sizeof (struct range_list
));
2300 /* Append this range to the symbol's range list. */
2301 if (!SYMBOL_RANGES (sym
))
2302 SYMBOL_RANGES (sym
) = r
;
2305 /* Get the last range for the symbol. */
2306 for (rs
= SYMBOL_RANGES (sym
); rs
->next
; rs
= rs
->next
)
2313 /* Skip rest of this symbol and return an error type.
2315 General notes on error recovery: error_type always skips to the
2316 end of the symbol (modulo cretinous dbx symbol name continuation).
2317 Thus code like this:
2319 if (*(*pp)++ != ';')
2320 return error_type (pp, objfile);
2322 is wrong because if *pp starts out pointing at '\0' (typically as the
2323 result of an earlier error), it will be incremented to point to the
2324 start of the next symbol, which might produce strange results, at least
2325 if you run off the end of the string table. Instead use
2328 return error_type (pp, objfile);
2334 foo = error_type (pp, objfile);
2338 And in case it isn't obvious, the point of all this hair is so the compiler
2339 can define new types and new syntaxes, and old versions of the
2340 debugger will be able to read the new symbol tables. */
2342 static struct type
*
2343 error_type (pp
, objfile
)
2345 struct objfile
*objfile
;
2347 complain (&error_type_complaint
);
2350 /* Skip to end of symbol. */
2351 while (**pp
!= '\0')
2356 /* Check for and handle cretinous dbx symbol name continuation! */
2357 if ((*pp
)[-1] == '\\' || (*pp
)[-1] == '?')
2359 *pp
= next_symbol_text (objfile
);
2366 return (builtin_type_error
);
2370 /* Read type information or a type definition; return the type. Even
2371 though this routine accepts either type information or a type
2372 definition, the distinction is relevant--some parts of stabsread.c
2373 assume that type information starts with a digit, '-', or '(' in
2374 deciding whether to call read_type. */
2377 read_type (pp
, objfile
)
2379 struct objfile
*objfile
;
2381 register struct type
*type
= 0;
2384 char type_descriptor
;
2386 /* Size in bits of type if specified by a type attribute, or -1 if
2387 there is no size attribute. */
2390 /* Used to distinguish string and bitstring from char-array and set. */
2393 /* Read type number if present. The type number may be omitted.
2394 for instance in a two-dimensional array declared with type
2395 "ar1;1;10;ar1;1;10;4". */
2396 if ((**pp
>= '0' && **pp
<= '9')
2400 if (read_type_number (pp
, typenums
) != 0)
2401 return error_type (pp
, objfile
);
2403 /* Type is not being defined here. Either it already exists,
2404 or this is a forward reference to it. dbx_alloc_type handles
2407 return dbx_alloc_type (typenums
, objfile
);
2409 /* Type is being defined here. */
2411 Also skip the type descriptor - we get it below with (*pp)[-1]. */
2416 /* 'typenums=' not present, type is anonymous. Read and return
2417 the definition, but don't put it in the type vector. */
2418 typenums
[0] = typenums
[1] = -1;
2423 type_descriptor
= (*pp
)[-1];
2424 switch (type_descriptor
)
2428 enum type_code code
;
2430 /* Used to index through file_symbols. */
2431 struct pending
*ppt
;
2434 /* Name including "struct", etc. */
2438 char *from
, *to
, *p
, *q1
, *q2
;
2440 /* Set the type code according to the following letter. */
2444 code
= TYPE_CODE_STRUCT
;
2447 code
= TYPE_CODE_UNION
;
2450 code
= TYPE_CODE_ENUM
;
2454 /* Complain and keep going, so compilers can invent new
2455 cross-reference types. */
2456 static struct complaint msg
=
2457 {"Unrecognized cross-reference type `%c'", 0, 0};
2458 complain (&msg
, (*pp
)[0]);
2459 code
= TYPE_CODE_STRUCT
;
2464 q1
= strchr (*pp
, '<');
2465 p
= strchr (*pp
, ':');
2467 return error_type (pp
, objfile
);
2468 if (q1
&& p
> q1
&& p
[1] == ':')
2470 int nesting_level
= 0;
2471 for (q2
= q1
; *q2
; q2
++)
2475 else if (*q2
== '>')
2477 else if (*q2
== ':' && nesting_level
== 0)
2482 return error_type (pp
, objfile
);
2485 (char *) obstack_alloc (&objfile
->type_obstack
, p
- *pp
+ 1);
2487 /* Copy the name. */
2493 /* Set the pointer ahead of the name which we just read, and
2498 /* Now check to see whether the type has already been
2499 declared. This was written for arrays of cross-referenced
2500 types before we had TYPE_CODE_TARGET_STUBBED, so I'm pretty
2501 sure it is not necessary anymore. But it might be a good
2502 idea, to save a little memory. */
2504 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
2505 for (i
= 0; i
< ppt
->nsyms
; i
++)
2507 struct symbol
*sym
= ppt
->symbol
[i
];
2509 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
2510 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
2511 && (TYPE_CODE (SYMBOL_TYPE (sym
)) == code
)
2512 && STREQ (SYMBOL_NAME (sym
), type_name
))
2514 obstack_free (&objfile
->type_obstack
, type_name
);
2515 type
= SYMBOL_TYPE (sym
);
2520 /* Didn't find the type to which this refers, so we must
2521 be dealing with a forward reference. Allocate a type
2522 structure for it, and keep track of it so we can
2523 fill in the rest of the fields when we get the full
2525 type
= dbx_alloc_type (typenums
, objfile
);
2526 TYPE_CODE (type
) = code
;
2527 TYPE_TAG_NAME (type
) = type_name
;
2528 INIT_CPLUS_SPECIFIC (type
);
2529 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
2531 add_undefined_type (type
);
2535 case '-': /* RS/6000 built-in type */
2549 /* We deal with something like t(1,2)=(3,4)=... which
2550 the Lucid compiler and recent gcc versions (post 2.7.3) use. */
2552 /* Allocate and enter the typedef type first.
2553 This handles recursive types. */
2554 type
= dbx_alloc_type (typenums
, objfile
);
2555 TYPE_CODE (type
) = TYPE_CODE_TYPEDEF
;
2557 struct type
*xtype
= read_type (pp
, objfile
);
2560 /* It's being defined as itself. That means it is "void". */
2561 TYPE_CODE (type
) = TYPE_CODE_VOID
;
2562 TYPE_LENGTH (type
) = 1;
2564 else if (type_size
>= 0 || is_string
)
2567 TYPE_NAME (type
) = NULL
;
2568 TYPE_TAG_NAME (type
) = NULL
;
2572 TYPE_FLAGS (type
) |= TYPE_FLAG_TARGET_STUB
;
2573 TYPE_TARGET_TYPE (type
) = xtype
;
2578 /* In the following types, we must be sure to overwrite any existing
2579 type that the typenums refer to, rather than allocating a new one
2580 and making the typenums point to the new one. This is because there
2581 may already be pointers to the existing type (if it had been
2582 forward-referenced), and we must change it to a pointer, function,
2583 reference, or whatever, *in-place*. */
2586 type1
= read_type (pp
, objfile
);
2587 type
= make_pointer_type (type1
, dbx_lookup_type (typenums
));
2590 case '&': /* Reference to another type */
2591 type1
= read_type (pp
, objfile
);
2592 type
= make_reference_type (type1
, dbx_lookup_type (typenums
));
2595 case 'f': /* Function returning another type */
2596 if (os9k_stabs
&& **pp
== '(')
2598 /* Function prototype; parse it.
2599 We must conditionalize this on os9k_stabs because otherwise
2600 it could be confused with a Sun-style (1,3) typenumber
2606 t
= read_type (pp
, objfile
);
2611 type1
= read_type (pp
, objfile
);
2612 type
= make_function_type (type1
, dbx_lookup_type (typenums
));
2615 case 'k': /* Const qualifier on some type (Sun) */
2616 case 'c': /* Const qualifier on some type (OS9000) */
2617 /* Because 'c' means other things to AIX and 'k' is perfectly good,
2618 only accept 'c' in the os9k_stabs case. */
2619 if (type_descriptor
== 'c' && !os9k_stabs
)
2620 return error_type (pp
, objfile
);
2621 type
= read_type (pp
, objfile
);
2622 /* FIXME! For now, we ignore const and volatile qualifiers. */
2625 case 'B': /* Volatile qual on some type (Sun) */
2626 case 'i': /* Volatile qual on some type (OS9000) */
2627 /* Because 'i' means other things to AIX and 'B' is perfectly good,
2628 only accept 'i' in the os9k_stabs case. */
2629 if (type_descriptor
== 'i' && !os9k_stabs
)
2630 return error_type (pp
, objfile
);
2631 type
= read_type (pp
, objfile
);
2632 /* FIXME! For now, we ignore const and volatile qualifiers. */
2636 if (isdigit (**pp
) || **pp
== '(' || **pp
== '-')
2637 { /* Member (class & variable) type */
2638 /* FIXME -- we should be doing smash_to_XXX types here. */
2640 struct type
*domain
= read_type (pp
, objfile
);
2641 struct type
*memtype
;
2644 /* Invalid member type data format. */
2645 return error_type (pp
, objfile
);
2648 memtype
= read_type (pp
, objfile
);
2649 type
= dbx_alloc_type (typenums
, objfile
);
2650 smash_to_member_type (type
, domain
, memtype
);
2653 /* type attribute */
2656 /* Skip to the semicolon. */
2657 while (**pp
!= ';' && **pp
!= '\0')
2660 return error_type (pp
, objfile
);
2662 ++ * pp
; /* Skip the semicolon. */
2667 type_size
= atoi (attr
+ 1);
2677 /* Ignore unrecognized type attributes, so future compilers
2678 can invent new ones. */
2686 case '#': /* Method (class & fn) type */
2687 if ((*pp
)[0] == '#')
2689 /* We'll get the parameter types from the name. */
2690 struct type
*return_type
;
2693 return_type
= read_type (pp
, objfile
);
2694 if (*(*pp
)++ != ';')
2695 complain (&invalid_member_complaint
, symnum
);
2696 type
= allocate_stub_method (return_type
);
2697 if (typenums
[0] != -1)
2698 *dbx_lookup_type (typenums
) = type
;
2702 struct type
*domain
= read_type (pp
, objfile
);
2703 struct type
*return_type
;
2707 /* Invalid member type data format. */
2708 return error_type (pp
, objfile
);
2712 return_type
= read_type (pp
, objfile
);
2713 args
= read_args (pp
, ';', objfile
);
2714 type
= dbx_alloc_type (typenums
, objfile
);
2715 smash_to_method_type (type
, domain
, return_type
, args
);
2719 case 'r': /* Range type */
2720 type
= read_range_type (pp
, typenums
, objfile
);
2721 if (typenums
[0] != -1)
2722 *dbx_lookup_type (typenums
) = type
;
2727 /* Const and volatile qualified type. */
2728 type
= read_type (pp
, objfile
);
2731 /* Sun ACC builtin int type */
2732 type
= read_sun_builtin_type (pp
, typenums
, objfile
);
2733 if (typenums
[0] != -1)
2734 *dbx_lookup_type (typenums
) = type
;
2738 case 'R': /* Sun ACC builtin float type */
2739 type
= read_sun_floating_type (pp
, typenums
, objfile
);
2740 if (typenums
[0] != -1)
2741 *dbx_lookup_type (typenums
) = type
;
2744 case 'e': /* Enumeration type */
2745 type
= dbx_alloc_type (typenums
, objfile
);
2746 type
= read_enum_type (pp
, type
, objfile
);
2747 if (typenums
[0] != -1)
2748 *dbx_lookup_type (typenums
) = type
;
2751 case 's': /* Struct type */
2752 case 'u': /* Union type */
2753 type
= dbx_alloc_type (typenums
, objfile
);
2754 switch (type_descriptor
)
2757 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
2760 TYPE_CODE (type
) = TYPE_CODE_UNION
;
2763 type
= read_struct_type (pp
, type
, objfile
);
2766 case 'a': /* Array type */
2768 return error_type (pp
, objfile
);
2771 type
= dbx_alloc_type (typenums
, objfile
);
2772 type
= read_array_type (pp
, type
, objfile
);
2774 TYPE_CODE (type
) = TYPE_CODE_STRING
;
2778 type1
= read_type (pp
, objfile
);
2779 type
= create_set_type ((struct type
*) NULL
, type1
);
2781 TYPE_CODE (type
) = TYPE_CODE_BITSTRING
;
2782 if (typenums
[0] != -1)
2783 *dbx_lookup_type (typenums
) = type
;
2787 --*pp
; /* Go back to the symbol in error */
2788 /* Particularly important if it was \0! */
2789 return error_type (pp
, objfile
);
2794 warning ("GDB internal error, type is NULL in stabsread.c\n");
2795 return error_type (pp
, objfile
);
2798 /* Size specified in a type attribute overrides any other size. */
2799 if (type_size
!= -1)
2800 TYPE_LENGTH (type
) = (type_size
+ TARGET_CHAR_BIT
- 1) / TARGET_CHAR_BIT
;
2805 /* RS/6000 xlc/dbx combination uses a set of builtin types, starting from -1.
2806 Return the proper type node for a given builtin type number. */
2808 static struct type
*
2809 rs6000_builtin_type (typenum
)
2812 /* We recognize types numbered from -NUMBER_RECOGNIZED to -1. */
2813 #define NUMBER_RECOGNIZED 34
2814 /* This includes an empty slot for type number -0. */
2815 static struct type
*negative_types
[NUMBER_RECOGNIZED
+ 1];
2816 struct type
*rettype
= NULL
;
2818 if (typenum
>= 0 || typenum
< -NUMBER_RECOGNIZED
)
2820 complain (&rs6000_builtin_complaint
, typenum
);
2821 return builtin_type_error
;
2823 if (negative_types
[-typenum
] != NULL
)
2824 return negative_types
[-typenum
];
2826 #if TARGET_CHAR_BIT != 8
2827 #error This code wrong for TARGET_CHAR_BIT not 8
2828 /* These definitions all assume that TARGET_CHAR_BIT is 8. I think
2829 that if that ever becomes not true, the correct fix will be to
2830 make the size in the struct type to be in bits, not in units of
2837 /* The size of this and all the other types are fixed, defined
2838 by the debugging format. If there is a type called "int" which
2839 is other than 32 bits, then it should use a new negative type
2840 number (or avoid negative type numbers for that case).
2841 See stabs.texinfo. */
2842 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "int", NULL
);
2845 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "char", NULL
);
2848 rettype
= init_type (TYPE_CODE_INT
, 2, 0, "short", NULL
);
2851 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "long", NULL
);
2854 rettype
= init_type (TYPE_CODE_INT
, 1, TYPE_FLAG_UNSIGNED
,
2855 "unsigned char", NULL
);
2858 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "signed char", NULL
);
2861 rettype
= init_type (TYPE_CODE_INT
, 2, TYPE_FLAG_UNSIGNED
,
2862 "unsigned short", NULL
);
2865 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
2866 "unsigned int", NULL
);
2869 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
2872 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
2873 "unsigned long", NULL
);
2876 rettype
= init_type (TYPE_CODE_VOID
, 1, 0, "void", NULL
);
2879 /* IEEE single precision (32 bit). */
2880 rettype
= init_type (TYPE_CODE_FLT
, 4, 0, "float", NULL
);
2883 /* IEEE double precision (64 bit). */
2884 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "double", NULL
);
2887 /* This is an IEEE double on the RS/6000, and different machines with
2888 different sizes for "long double" should use different negative
2889 type numbers. See stabs.texinfo. */
2890 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "long double", NULL
);
2893 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "integer", NULL
);
2896 rettype
= init_type (TYPE_CODE_BOOL
, 4, TYPE_FLAG_UNSIGNED
,
2900 rettype
= init_type (TYPE_CODE_FLT
, 4, 0, "short real", NULL
);
2903 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "real", NULL
);
2906 rettype
= init_type (TYPE_CODE_ERROR
, 0, 0, "stringptr", NULL
);
2909 rettype
= init_type (TYPE_CODE_CHAR
, 1, TYPE_FLAG_UNSIGNED
,
2913 rettype
= init_type (TYPE_CODE_BOOL
, 1, TYPE_FLAG_UNSIGNED
,
2917 rettype
= init_type (TYPE_CODE_BOOL
, 2, TYPE_FLAG_UNSIGNED
,
2921 rettype
= init_type (TYPE_CODE_BOOL
, 4, TYPE_FLAG_UNSIGNED
,
2925 rettype
= init_type (TYPE_CODE_BOOL
, 4, TYPE_FLAG_UNSIGNED
,
2929 /* Complex type consisting of two IEEE single precision values. */
2930 rettype
= init_type (TYPE_CODE_COMPLEX
, 8, 0, "complex", NULL
);
2933 /* Complex type consisting of two IEEE double precision values. */
2934 rettype
= init_type (TYPE_CODE_COMPLEX
, 16, 0, "double complex", NULL
);
2937 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "integer*1", NULL
);
2940 rettype
= init_type (TYPE_CODE_INT
, 2, 0, "integer*2", NULL
);
2943 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "integer*4", NULL
);
2946 rettype
= init_type (TYPE_CODE_CHAR
, 2, 0, "wchar", NULL
);
2949 rettype
= init_type (TYPE_CODE_INT
, 8, 0, "long long", NULL
);
2952 rettype
= init_type (TYPE_CODE_INT
, 8, TYPE_FLAG_UNSIGNED
,
2953 "unsigned long long", NULL
);
2956 rettype
= init_type (TYPE_CODE_INT
, 8, TYPE_FLAG_UNSIGNED
,
2960 rettype
= init_type (TYPE_CODE_INT
, 8, 0, "integer*8", NULL
);
2963 negative_types
[-typenum
] = rettype
;
2967 /* This page contains subroutines of read_type. */
2969 /* Read member function stabs info for C++ classes. The form of each member
2972 NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
2974 An example with two member functions is:
2976 afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
2978 For the case of overloaded operators, the format is op$::*.funcs, where
2979 $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
2980 name (such as `+=') and `.' marks the end of the operator name.
2982 Returns 1 for success, 0 for failure. */
2985 read_member_functions (fip
, pp
, type
, objfile
)
2986 struct field_info
*fip
;
2989 struct objfile
*objfile
;
2993 /* Total number of member functions defined in this class. If the class
2994 defines two `f' functions, and one `g' function, then this will have
2996 int total_length
= 0;
3000 struct next_fnfield
*next
;
3001 struct fn_field fn_field
;
3004 struct type
*look_ahead_type
;
3005 struct next_fnfieldlist
*new_fnlist
;
3006 struct next_fnfield
*new_sublist
;
3010 /* Process each list until we find something that is not a member function
3011 or find the end of the functions. */
3015 /* We should be positioned at the start of the function name.
3016 Scan forward to find the first ':' and if it is not the
3017 first of a "::" delimiter, then this is not a member function. */
3029 look_ahead_type
= NULL
;
3032 new_fnlist
= (struct next_fnfieldlist
*)
3033 xmalloc (sizeof (struct next_fnfieldlist
));
3034 make_cleanup (free
, new_fnlist
);
3035 memset (new_fnlist
, 0, sizeof (struct next_fnfieldlist
));
3037 if ((*pp
)[0] == 'o' && (*pp
)[1] == 'p' && is_cplus_marker ((*pp
)[2]))
3039 /* This is a completely wierd case. In order to stuff in the
3040 names that might contain colons (the usual name delimiter),
3041 Mike Tiemann defined a different name format which is
3042 signalled if the identifier is "op$". In that case, the
3043 format is "op$::XXXX." where XXXX is the name. This is
3044 used for names like "+" or "=". YUUUUUUUK! FIXME! */
3045 /* This lets the user type "break operator+".
3046 We could just put in "+" as the name, but that wouldn't
3048 static char opname
[32] =
3049 {'o', 'p', CPLUS_MARKER
};
3050 char *o
= opname
+ 3;
3052 /* Skip past '::'. */
3055 STABS_CONTINUE (pp
, objfile
);
3061 main_fn_name
= savestring (opname
, o
- opname
);
3067 main_fn_name
= savestring (*pp
, p
- *pp
);
3068 /* Skip past '::'. */
3071 new_fnlist
->fn_fieldlist
.name
= main_fn_name
;
3076 (struct next_fnfield
*) xmalloc (sizeof (struct next_fnfield
));
3077 make_cleanup (free
, new_sublist
);
3078 memset (new_sublist
, 0, sizeof (struct next_fnfield
));
3080 /* Check for and handle cretinous dbx symbol name continuation! */
3081 if (look_ahead_type
== NULL
)
3084 STABS_CONTINUE (pp
, objfile
);
3086 new_sublist
->fn_field
.type
= read_type (pp
, objfile
);
3089 /* Invalid symtab info for member function. */
3095 /* g++ version 1 kludge */
3096 new_sublist
->fn_field
.type
= look_ahead_type
;
3097 look_ahead_type
= NULL
;
3107 /* If this is just a stub, then we don't have the real name here. */
3109 if (TYPE_FLAGS (new_sublist
->fn_field
.type
) & TYPE_FLAG_STUB
)
3111 if (!TYPE_DOMAIN_TYPE (new_sublist
->fn_field
.type
))
3112 TYPE_DOMAIN_TYPE (new_sublist
->fn_field
.type
) = type
;
3113 new_sublist
->fn_field
.is_stub
= 1;
3115 new_sublist
->fn_field
.physname
= savestring (*pp
, p
- *pp
);
3118 /* Set this member function's visibility fields. */
3121 case VISIBILITY_PRIVATE
:
3122 new_sublist
->fn_field
.is_private
= 1;
3124 case VISIBILITY_PROTECTED
:
3125 new_sublist
->fn_field
.is_protected
= 1;
3129 STABS_CONTINUE (pp
, objfile
);
3132 case 'A': /* Normal functions. */
3133 new_sublist
->fn_field
.is_const
= 0;
3134 new_sublist
->fn_field
.is_volatile
= 0;
3137 case 'B': /* `const' member functions. */
3138 new_sublist
->fn_field
.is_const
= 1;
3139 new_sublist
->fn_field
.is_volatile
= 0;
3142 case 'C': /* `volatile' member function. */
3143 new_sublist
->fn_field
.is_const
= 0;
3144 new_sublist
->fn_field
.is_volatile
= 1;
3147 case 'D': /* `const volatile' member function. */
3148 new_sublist
->fn_field
.is_const
= 1;
3149 new_sublist
->fn_field
.is_volatile
= 1;
3152 case '*': /* File compiled with g++ version 1 -- no info */
3157 complain (&const_vol_complaint
, **pp
);
3166 /* virtual member function, followed by index.
3167 The sign bit is set to distinguish pointers-to-methods
3168 from virtual function indicies. Since the array is
3169 in words, the quantity must be shifted left by 1
3170 on 16 bit machine, and by 2 on 32 bit machine, forcing
3171 the sign bit out, and usable as a valid index into
3172 the array. Remove the sign bit here. */
3173 new_sublist
->fn_field
.voffset
=
3174 (0x7fffffff & read_huge_number (pp
, ';', &nbits
)) + 2;
3178 STABS_CONTINUE (pp
, objfile
);
3179 if (**pp
== ';' || **pp
== '\0')
3181 /* Must be g++ version 1. */
3182 new_sublist
->fn_field
.fcontext
= 0;
3186 /* Figure out from whence this virtual function came.
3187 It may belong to virtual function table of
3188 one of its baseclasses. */
3189 look_ahead_type
= read_type (pp
, objfile
);
3192 /* g++ version 1 overloaded methods. */
3196 new_sublist
->fn_field
.fcontext
= look_ahead_type
;
3205 look_ahead_type
= NULL
;
3211 /* static member function. */
3212 new_sublist
->fn_field
.voffset
= VOFFSET_STATIC
;
3213 if (strncmp (new_sublist
->fn_field
.physname
,
3214 main_fn_name
, strlen (main_fn_name
)))
3216 new_sublist
->fn_field
.is_stub
= 1;
3222 complain (&member_fn_complaint
, (*pp
)[-1]);
3223 /* Fall through into normal member function. */
3226 /* normal member function. */
3227 new_sublist
->fn_field
.voffset
= 0;
3228 new_sublist
->fn_field
.fcontext
= 0;
3232 new_sublist
->next
= sublist
;
3233 sublist
= new_sublist
;
3235 STABS_CONTINUE (pp
, objfile
);
3237 while (**pp
!= ';' && **pp
!= '\0');
3241 new_fnlist
->fn_fieldlist
.fn_fields
= (struct fn_field
*)
3242 obstack_alloc (&objfile
->type_obstack
,
3243 sizeof (struct fn_field
) * length
);
3244 memset (new_fnlist
->fn_fieldlist
.fn_fields
, 0,
3245 sizeof (struct fn_field
) * length
);
3246 for (i
= length
; (i
--, sublist
); sublist
= sublist
->next
)
3248 new_fnlist
->fn_fieldlist
.fn_fields
[i
] = sublist
->fn_field
;
3251 new_fnlist
->fn_fieldlist
.length
= length
;
3252 new_fnlist
->next
= fip
->fnlist
;
3253 fip
->fnlist
= new_fnlist
;
3255 total_length
+= length
;
3256 STABS_CONTINUE (pp
, objfile
);
3261 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3262 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
3263 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * nfn_fields
);
3264 memset (TYPE_FN_FIELDLISTS (type
), 0,
3265 sizeof (struct fn_fieldlist
) * nfn_fields
);
3266 TYPE_NFN_FIELDS (type
) = nfn_fields
;
3267 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
3273 /* Special GNU C++ name.
3275 Returns 1 for success, 0 for failure. "failure" means that we can't
3276 keep parsing and it's time for error_type(). */
3279 read_cpp_abbrev (fip
, pp
, type
, objfile
)
3280 struct field_info
*fip
;
3283 struct objfile
*objfile
;
3288 struct type
*context
;
3298 /* At this point, *pp points to something like "22:23=*22...",
3299 where the type number before the ':' is the "context" and
3300 everything after is a regular type definition. Lookup the
3301 type, find it's name, and construct the field name. */
3303 context
= read_type (pp
, objfile
);
3307 case 'f': /* $vf -- a virtual function table pointer */
3308 fip
->list
->field
.name
=
3309 obconcat (&objfile
->type_obstack
, vptr_name
, "", "");
3312 case 'b': /* $vb -- a virtual bsomethingorother */
3313 name
= type_name_no_tag (context
);
3316 complain (&invalid_cpp_type_complaint
, symnum
);
3319 fip
->list
->field
.name
=
3320 obconcat (&objfile
->type_obstack
, vb_name
, name
, "");
3324 complain (&invalid_cpp_abbrev_complaint
, *pp
);
3325 fip
->list
->field
.name
=
3326 obconcat (&objfile
->type_obstack
,
3327 "INVALID_CPLUSPLUS_ABBREV", "", "");
3331 /* At this point, *pp points to the ':'. Skip it and read the
3337 complain (&invalid_cpp_abbrev_complaint
, *pp
);
3340 fip
->list
->field
.type
= read_type (pp
, objfile
);
3342 (*pp
)++; /* Skip the comma. */
3348 FIELD_BITPOS (fip
->list
->field
) = read_huge_number (pp
, ';', &nbits
);
3352 /* This field is unpacked. */
3353 FIELD_BITSIZE (fip
->list
->field
) = 0;
3354 fip
->list
->visibility
= VISIBILITY_PRIVATE
;
3358 complain (&invalid_cpp_abbrev_complaint
, *pp
);
3359 /* We have no idea what syntax an unrecognized abbrev would have, so
3360 better return 0. If we returned 1, we would need to at least advance
3361 *pp to avoid an infinite loop. */
3368 read_one_struct_field (fip
, pp
, p
, type
, objfile
)
3369 struct field_info
*fip
;
3373 struct objfile
*objfile
;
3375 /* The following is code to work around cfront generated stabs.
3376 The stabs contains full mangled name for each field.
3377 We try to demangle the name and extract the field name out of it.
3379 if (ARM_DEMANGLING
&& current_subfile
->language
== language_cplus
)
3385 dem
= cplus_demangle (*pp
, DMGL_ANSI
| DMGL_PARAMS
);
3388 dem_p
= strrchr (dem
, ':');
3389 if (dem_p
!= 0 && *(dem_p
- 1) == ':')
3391 FIELD_NAME (fip
->list
->field
) =
3392 obsavestring (dem_p
, strlen (dem_p
), &objfile
->type_obstack
);
3396 FIELD_NAME (fip
->list
->field
) =
3397 obsavestring (*pp
, p
- *pp
, &objfile
->type_obstack
);
3401 /* end of code for cfront work around */
3404 fip
->list
->field
.name
=
3405 obsavestring (*pp
, p
- *pp
, &objfile
->type_obstack
);
3408 /* This means we have a visibility for a field coming. */
3412 fip
->list
->visibility
= *(*pp
)++;
3416 /* normal dbx-style format, no explicit visibility */
3417 fip
->list
->visibility
= VISIBILITY_PUBLIC
;
3420 fip
->list
->field
.type
= read_type (pp
, objfile
);
3425 /* Possible future hook for nested types. */
3428 fip
->list
->field
.bitpos
= (long) -2; /* nested type */
3438 /* Static class member. */
3439 SET_FIELD_PHYSNAME (fip
->list
->field
, savestring (*pp
, p
- *pp
));
3443 else if (**pp
!= ',')
3445 /* Bad structure-type format. */
3446 complain (&stabs_general_complaint
, "bad structure-type format");
3450 (*pp
)++; /* Skip the comma. */
3454 FIELD_BITPOS (fip
->list
->field
) = read_huge_number (pp
, ',', &nbits
);
3457 complain (&stabs_general_complaint
, "bad structure-type format");
3460 FIELD_BITSIZE (fip
->list
->field
) = read_huge_number (pp
, ';', &nbits
);
3463 complain (&stabs_general_complaint
, "bad structure-type format");
3468 if (FIELD_BITPOS (fip
->list
->field
) == 0
3469 && FIELD_BITSIZE (fip
->list
->field
) == 0)
3471 /* This can happen in two cases: (1) at least for gcc 2.4.5 or so,
3472 it is a field which has been optimized out. The correct stab for
3473 this case is to use VISIBILITY_IGNORE, but that is a recent
3474 invention. (2) It is a 0-size array. For example
3475 union { int num; char str[0]; } foo. Printing "<no value>" for
3476 str in "p foo" is OK, since foo.str (and thus foo.str[3])
3477 will continue to work, and a 0-size array as a whole doesn't
3478 have any contents to print.
3480 I suspect this probably could also happen with gcc -gstabs (not
3481 -gstabs+) for static fields, and perhaps other C++ extensions.
3482 Hopefully few people use -gstabs with gdb, since it is intended
3483 for dbx compatibility. */
3485 /* Ignore this field. */
3486 fip
->list
->visibility
= VISIBILITY_IGNORE
;
3490 /* Detect an unpacked field and mark it as such.
3491 dbx gives a bit size for all fields.
3492 Note that forward refs cannot be packed,
3493 and treat enums as if they had the width of ints. */
3495 struct type
*field_type
= check_typedef (FIELD_TYPE (fip
->list
->field
));
3497 if (TYPE_CODE (field_type
) != TYPE_CODE_INT
3498 && TYPE_CODE (field_type
) != TYPE_CODE_RANGE
3499 && TYPE_CODE (field_type
) != TYPE_CODE_BOOL
3500 && TYPE_CODE (field_type
) != TYPE_CODE_ENUM
)
3502 FIELD_BITSIZE (fip
->list
->field
) = 0;
3504 if ((FIELD_BITSIZE (fip
->list
->field
)
3505 == TARGET_CHAR_BIT
* TYPE_LENGTH (field_type
)
3506 || (TYPE_CODE (field_type
) == TYPE_CODE_ENUM
3507 && FIELD_BITSIZE (fip
->list
->field
) == TARGET_INT_BIT
)
3510 FIELD_BITPOS (fip
->list
->field
) % 8 == 0)
3512 FIELD_BITSIZE (fip
->list
->field
) = 0;
3518 /* Read struct or class data fields. They have the form:
3520 NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
3522 At the end, we see a semicolon instead of a field.
3524 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
3527 The optional VISIBILITY is one of:
3529 '/0' (VISIBILITY_PRIVATE)
3530 '/1' (VISIBILITY_PROTECTED)
3531 '/2' (VISIBILITY_PUBLIC)
3532 '/9' (VISIBILITY_IGNORE)
3534 or nothing, for C style fields with public visibility.
3536 Returns 1 for success, 0 for failure. */
3539 read_struct_fields (fip
, pp
, type
, objfile
)
3540 struct field_info
*fip
;
3543 struct objfile
*objfile
;
3546 struct nextfield
*new;
3548 /* We better set p right now, in case there are no fields at all... */
3552 /* Read each data member type until we find the terminating ';' at the end of
3553 the data member list, or break for some other reason such as finding the
3554 start of the member function list. */
3558 if (os9k_stabs
&& **pp
== ',')
3560 STABS_CONTINUE (pp
, objfile
);
3561 /* Get space to record the next field's data. */
3562 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3563 make_cleanup (free
, new);
3564 memset (new, 0, sizeof (struct nextfield
));
3565 new->next
= fip
->list
;
3568 /* Get the field name. */
3571 /* If is starts with CPLUS_MARKER it is a special abbreviation,
3572 unless the CPLUS_MARKER is followed by an underscore, in
3573 which case it is just the name of an anonymous type, which we
3574 should handle like any other type name. */
3576 if (is_cplus_marker (p
[0]) && p
[1] != '_')
3578 if (!read_cpp_abbrev (fip
, pp
, type
, objfile
))
3583 /* Look for the ':' that separates the field name from the field
3584 values. Data members are delimited by a single ':', while member
3585 functions are delimited by a pair of ':'s. When we hit the member
3586 functions (if any), terminate scan loop and return. */
3588 while (*p
!= ':' && *p
!= '\0')
3595 /* Check to see if we have hit the member functions yet. */
3600 read_one_struct_field (fip
, pp
, p
, type
, objfile
);
3602 if (p
[0] == ':' && p
[1] == ':')
3604 /* chill the list of fields: the last entry (at the head) is a
3605 partially constructed entry which we now scrub. */
3606 fip
->list
= fip
->list
->next
;
3611 /* The stabs for C++ derived classes contain baseclass information which
3612 is marked by a '!' character after the total size. This function is
3613 called when we encounter the baseclass marker, and slurps up all the
3614 baseclass information.
3616 Immediately following the '!' marker is the number of base classes that
3617 the class is derived from, followed by information for each base class.
3618 For each base class, there are two visibility specifiers, a bit offset
3619 to the base class information within the derived class, a reference to
3620 the type for the base class, and a terminating semicolon.
3622 A typical example, with two base classes, would be "!2,020,19;0264,21;".
3624 Baseclass information marker __________________|| | | | | | |
3625 Number of baseclasses __________________________| | | | | | |
3626 Visibility specifiers (2) ________________________| | | | | |
3627 Offset in bits from start of class _________________| | | | |
3628 Type number for base class ___________________________| | | |
3629 Visibility specifiers (2) _______________________________| | |
3630 Offset in bits from start of class ________________________| |
3631 Type number of base class ____________________________________|
3633 Return 1 for success, 0 for (error-type-inducing) failure. */
3639 read_baseclasses (fip
, pp
, type
, objfile
)
3640 struct field_info
*fip
;
3643 struct objfile
*objfile
;
3646 struct nextfield
*new;
3654 /* Skip the '!' baseclass information marker. */
3658 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3661 TYPE_N_BASECLASSES (type
) = read_huge_number (pp
, ',', &nbits
);
3667 /* Some stupid compilers have trouble with the following, so break
3668 it up into simpler expressions. */
3669 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*)
3670 TYPE_ALLOC (type
, B_BYTES (TYPE_N_BASECLASSES (type
)));
3673 int num_bytes
= B_BYTES (TYPE_N_BASECLASSES (type
));
3676 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
3677 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
3681 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), TYPE_N_BASECLASSES (type
));
3683 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
3685 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3686 make_cleanup (free
, new);
3687 memset (new, 0, sizeof (struct nextfield
));
3688 new->next
= fip
->list
;
3690 FIELD_BITSIZE (new->field
) = 0; /* this should be an unpacked field! */
3692 STABS_CONTINUE (pp
, objfile
);
3696 /* Nothing to do. */
3699 SET_TYPE_FIELD_VIRTUAL (type
, i
);
3702 /* Unknown character. Complain and treat it as non-virtual. */
3704 static struct complaint msg
=
3706 "Unknown virtual character `%c' for baseclass", 0, 0};
3707 complain (&msg
, **pp
);
3712 new->visibility
= *(*pp
)++;
3713 switch (new->visibility
)
3715 case VISIBILITY_PRIVATE
:
3716 case VISIBILITY_PROTECTED
:
3717 case VISIBILITY_PUBLIC
:
3720 /* Bad visibility format. Complain and treat it as
3723 static struct complaint msg
=
3725 "Unknown visibility `%c' for baseclass", 0, 0
3727 complain (&msg
, new->visibility
);
3728 new->visibility
= VISIBILITY_PUBLIC
;
3735 /* The remaining value is the bit offset of the portion of the object
3736 corresponding to this baseclass. Always zero in the absence of
3737 multiple inheritance. */
3739 FIELD_BITPOS (new->field
) = read_huge_number (pp
, ',', &nbits
);
3744 /* The last piece of baseclass information is the type of the
3745 base class. Read it, and remember it's type name as this
3748 new->field
.type
= read_type (pp
, objfile
);
3749 new->field
.name
= type_name_no_tag (new->field
.type
);
3751 /* skip trailing ';' and bump count of number of fields seen */
3760 /* The tail end of stabs for C++ classes that contain a virtual function
3761 pointer contains a tilde, a %, and a type number.
3762 The type number refers to the base class (possibly this class itself) which
3763 contains the vtable pointer for the current class.
3765 This function is called when we have parsed all the method declarations,
3766 so we can look for the vptr base class info. */
3769 read_tilde_fields (fip
, pp
, type
, objfile
)
3770 struct field_info
*fip
;
3773 struct objfile
*objfile
;
3777 STABS_CONTINUE (pp
, objfile
);
3779 /* If we are positioned at a ';', then skip it. */
3789 if (**pp
== '=' || **pp
== '+' || **pp
== '-')
3791 /* Obsolete flags that used to indicate the presence
3792 of constructors and/or destructors. */
3796 /* Read either a '%' or the final ';'. */
3797 if (*(*pp
)++ == '%')
3799 /* The next number is the type number of the base class
3800 (possibly our own class) which supplies the vtable for
3801 this class. Parse it out, and search that class to find
3802 its vtable pointer, and install those into TYPE_VPTR_BASETYPE
3803 and TYPE_VPTR_FIELDNO. */
3808 t
= read_type (pp
, objfile
);
3810 while (*p
!= '\0' && *p
!= ';')
3816 /* Premature end of symbol. */
3820 TYPE_VPTR_BASETYPE (type
) = t
;
3821 if (type
== t
) /* Our own class provides vtbl ptr */
3823 for (i
= TYPE_NFIELDS (t
) - 1;
3824 i
>= TYPE_N_BASECLASSES (t
);
3827 if (!strncmp (TYPE_FIELD_NAME (t
, i
), vptr_name
,
3828 sizeof (vptr_name
) - 1))
3830 TYPE_VPTR_FIELDNO (type
) = i
;
3834 /* Virtual function table field not found. */
3835 complain (&vtbl_notfound_complaint
, TYPE_NAME (type
));
3840 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
3851 attach_fn_fields_to_type (fip
, type
)
3852 struct field_info
*fip
;
3853 register struct type
*type
;
3857 for (n
= TYPE_NFN_FIELDS (type
);
3858 fip
->fnlist
!= NULL
;
3859 fip
->fnlist
= fip
->fnlist
->next
)
3861 --n
; /* Circumvent Sun3 compiler bug */
3862 TYPE_FN_FIELDLISTS (type
)[n
] = fip
->fnlist
->fn_fieldlist
;
3867 /* read cfront class static data.
3868 pp points to string starting with the list of static data
3869 eg: A:ZcA;1@Bpub v2@Bvirpri;__ct__1AFv func__1AFv *sfunc__1AFv ;as__1A ;;
3872 A:ZcA;;foopri__1AFv foopro__1AFv __ct__1AFv __ct__1AFRC1A foopub__1AFv ;;;
3877 read_cfront_static_fields (fip
, pp
, type
, objfile
)
3878 struct field_info
*fip
;
3881 struct objfile
*objfile
;
3883 struct nextfield
*new;
3886 struct symbol
*ref_static
= 0;
3888 if (**pp
== ';') /* no static data; return */
3894 /* Process each field in the list until we find the terminating ";" */
3896 /* eg: p = "as__1A ;;;" */
3897 STABS_CONTINUE (pp
, objfile
); /* handle \\ */
3898 while (**pp
!= ';' && (sname
= get_substring (pp
, ' '), sname
))
3900 ref_static
= lookup_symbol (sname
, 0, VAR_NAMESPACE
, 0, 0); /*demangled_name */
3903 static struct complaint msg
=
3905 Unable to find symbol for static data field %s\n",
3907 complain (&msg
, sname
);
3910 stype
= SYMBOL_TYPE (ref_static
);
3912 /* allocate a new fip */
3913 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3914 make_cleanup (free
, new);
3915 memset (new, 0, sizeof (struct nextfield
));
3916 new->next
= fip
->list
;
3919 /* set visibility */
3920 /* FIXME! no way to tell visibility from stabs??? */
3921 new->visibility
= VISIBILITY_PUBLIC
;
3923 /* set field info into fip */
3924 fip
->list
->field
.type
= stype
;
3926 /* set bitpos & bitsize */
3927 SET_FIELD_PHYSNAME (fip
->list
->field
, savestring (sname
, strlen (sname
)));
3929 /* set name field */
3930 /* The following is code to work around cfront generated stabs.
3931 The stabs contains full mangled name for each field.
3932 We try to demangle the name and extract the field name out of it.
3937 dem
= cplus_demangle (sname
, DMGL_ANSI
| DMGL_PARAMS
);
3940 dem_p
= strrchr (dem
, ':');
3941 if (dem_p
!= 0 && *(dem_p
- 1) == ':')
3943 fip
->list
->field
.name
=
3944 obsavestring (dem_p
, strlen (dem_p
), &objfile
->type_obstack
);
3948 fip
->list
->field
.name
=
3949 obsavestring (sname
, strlen (sname
), &objfile
->type_obstack
);
3951 } /* end of code for cfront work around */
3952 } /* loop again for next static field */
3956 /* Copy structure fields to fip so attach_fields_to_type will work.
3957 type has already been created with the initial instance data fields.
3958 Now we want to be able to add the other members to the class,
3959 so we want to add them back to the fip and reattach them again
3960 once we have collected all the class members. */
3963 copy_cfront_struct_fields (fip
, type
, objfile
)
3964 struct field_info
*fip
;
3966 struct objfile
*objfile
;
3968 int nfields
= TYPE_NFIELDS (type
);
3970 struct nextfield
*new;
3972 /* Copy the fields into the list of fips and reset the types
3973 to remove the old fields */
3975 for (i
= 0; i
< nfields
; i
++)
3977 /* allocate a new fip */
3978 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3979 make_cleanup (free
, new);
3980 memset (new, 0, sizeof (struct nextfield
));
3981 new->next
= fip
->list
;
3984 /* copy field info into fip */
3985 new->field
= TYPE_FIELD (type
, i
);
3986 /* set visibility */
3987 if (TYPE_FIELD_PROTECTED (type
, i
))
3988 new->visibility
= VISIBILITY_PROTECTED
;
3989 else if (TYPE_FIELD_PRIVATE (type
, i
))
3990 new->visibility
= VISIBILITY_PRIVATE
;
3992 new->visibility
= VISIBILITY_PUBLIC
;
3994 /* Now delete the fields from the type since we will be
3995 allocing new space once we get the rest of the fields
3996 in attach_fields_to_type.
3997 The pointer TYPE_FIELDS(type) is left dangling but should
3998 be freed later by objstack_free */
3999 TYPE_FIELDS (type
) = 0;
4000 TYPE_NFIELDS (type
) = 0;
4005 /* Create the vector of fields, and record how big it is.
4006 We need this info to record proper virtual function table information
4007 for this class's virtual functions. */
4010 attach_fields_to_type (fip
, type
, objfile
)
4011 struct field_info
*fip
;
4012 register struct type
*type
;
4013 struct objfile
*objfile
;
4015 register int nfields
= 0;
4016 register int non_public_fields
= 0;
4017 register struct nextfield
*scan
;
4019 /* Count up the number of fields that we have, as well as taking note of
4020 whether or not there are any non-public fields, which requires us to
4021 allocate and build the private_field_bits and protected_field_bits
4024 for (scan
= fip
->list
; scan
!= NULL
; scan
= scan
->next
)
4027 if (scan
->visibility
!= VISIBILITY_PUBLIC
)
4029 non_public_fields
++;
4033 /* Now we know how many fields there are, and whether or not there are any
4034 non-public fields. Record the field count, allocate space for the
4035 array of fields, and create blank visibility bitfields if necessary. */
4037 TYPE_NFIELDS (type
) = nfields
;
4038 TYPE_FIELDS (type
) = (struct field
*)
4039 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
4040 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
4042 if (non_public_fields
)
4044 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
4046 TYPE_FIELD_PRIVATE_BITS (type
) =
4047 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
4048 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
4050 TYPE_FIELD_PROTECTED_BITS (type
) =
4051 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
4052 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
4054 TYPE_FIELD_IGNORE_BITS (type
) =
4055 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
4056 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
4059 /* Copy the saved-up fields into the field vector. Start from the head
4060 of the list, adding to the tail of the field array, so that they end
4061 up in the same order in the array in which they were added to the list. */
4063 while (nfields
-- > 0)
4065 TYPE_FIELD (type
, nfields
) = fip
->list
->field
;
4066 switch (fip
->list
->visibility
)
4068 case VISIBILITY_PRIVATE
:
4069 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
4072 case VISIBILITY_PROTECTED
:
4073 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
4076 case VISIBILITY_IGNORE
:
4077 SET_TYPE_FIELD_IGNORE (type
, nfields
);
4080 case VISIBILITY_PUBLIC
:
4084 /* Unknown visibility. Complain and treat it as public. */
4086 static struct complaint msg
=
4088 "Unknown visibility `%c' for field", 0, 0};
4089 complain (&msg
, fip
->list
->visibility
);
4093 fip
->list
= fip
->list
->next
;
4098 /* Read the description of a structure (or union type) and return an object
4099 describing the type.
4101 PP points to a character pointer that points to the next unconsumed token
4102 in the the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
4103 *PP will point to "4a:1,0,32;;".
4105 TYPE points to an incomplete type that needs to be filled in.
4107 OBJFILE points to the current objfile from which the stabs information is
4108 being read. (Note that it is redundant in that TYPE also contains a pointer
4109 to this same objfile, so it might be a good idea to eliminate it. FIXME).
4112 static struct type
*
4113 read_struct_type (pp
, type
, objfile
)
4116 struct objfile
*objfile
;
4118 struct cleanup
*back_to
;
4119 struct field_info fi
;
4124 back_to
= make_cleanup (null_cleanup
, 0);
4126 INIT_CPLUS_SPECIFIC (type
);
4127 TYPE_FLAGS (type
) &= ~TYPE_FLAG_STUB
;
4129 /* First comes the total size in bytes. */
4133 TYPE_LENGTH (type
) = read_huge_number (pp
, 0, &nbits
);
4135 return error_type (pp
, objfile
);
4138 /* Now read the baseclasses, if any, read the regular C struct or C++
4139 class member fields, attach the fields to the type, read the C++
4140 member functions, attach them to the type, and then read any tilde
4141 field (baseclass specifier for the class holding the main vtable). */
4143 if (!read_baseclasses (&fi
, pp
, type
, objfile
)
4144 || !read_struct_fields (&fi
, pp
, type
, objfile
)
4145 || !attach_fields_to_type (&fi
, type
, objfile
)
4146 || !read_member_functions (&fi
, pp
, type
, objfile
)
4147 || !attach_fn_fields_to_type (&fi
, type
)
4148 || !read_tilde_fields (&fi
, pp
, type
, objfile
))
4150 type
= error_type (pp
, objfile
);
4153 do_cleanups (back_to
);
4157 /* Read a definition of an array type,
4158 and create and return a suitable type object.
4159 Also creates a range type which represents the bounds of that
4162 static struct type
*
4163 read_array_type (pp
, type
, objfile
)
4165 register struct type
*type
;
4166 struct objfile
*objfile
;
4168 struct type
*index_type
, *element_type
, *range_type
;
4173 /* Format of an array type:
4174 "ar<index type>;lower;upper;<array_contents_type>".
4175 OS9000: "arlower,upper;<array_contents_type>".
4177 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
4178 for these, produce a type like float[][]. */
4181 index_type
= builtin_type_int
;
4184 index_type
= read_type (pp
, objfile
);
4186 /* Improper format of array type decl. */
4187 return error_type (pp
, objfile
);
4191 if (!(**pp
>= '0' && **pp
<= '9') && **pp
!= '-')
4196 lower
= read_huge_number (pp
, os9k_stabs
? ',' : ';', &nbits
);
4198 return error_type (pp
, objfile
);
4200 if (!(**pp
>= '0' && **pp
<= '9') && **pp
!= '-')
4205 upper
= read_huge_number (pp
, ';', &nbits
);
4207 return error_type (pp
, objfile
);
4209 element_type
= read_type (pp
, objfile
);
4218 create_range_type ((struct type
*) NULL
, index_type
, lower
, upper
);
4219 type
= create_array_type (type
, element_type
, range_type
);
4225 /* Read a definition of an enumeration type,
4226 and create and return a suitable type object.
4227 Also defines the symbols that represent the values of the type. */
4229 static struct type
*
4230 read_enum_type (pp
, type
, objfile
)
4232 register struct type
*type
;
4233 struct objfile
*objfile
;
4238 register struct symbol
*sym
;
4240 struct pending
**symlist
;
4241 struct pending
*osyms
, *syms
;
4244 int unsigned_enum
= 1;
4247 /* FIXME! The stabs produced by Sun CC merrily define things that ought
4248 to be file-scope, between N_FN entries, using N_LSYM. What's a mother
4249 to do? For now, force all enum values to file scope. */
4250 if (within_function
)
4251 symlist
= &local_symbols
;
4254 symlist
= &file_symbols
;
4256 o_nsyms
= osyms
? osyms
->nsyms
: 0;
4260 /* Size. Perhaps this does not have to be conditionalized on
4261 os9k_stabs (assuming the name of an enum constant can't start
4263 read_huge_number (pp
, 0, &nbits
);
4265 return error_type (pp
, objfile
);
4268 /* The aix4 compiler emits an extra field before the enum members;
4269 my guess is it's a type of some sort. Just ignore it. */
4272 /* Skip over the type. */
4276 /* Skip over the colon. */
4280 /* Read the value-names and their values.
4281 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
4282 A semicolon or comma instead of a NAME means the end. */
4283 while (**pp
&& **pp
!= ';' && **pp
!= ',')
4285 STABS_CONTINUE (pp
, objfile
);
4289 name
= obsavestring (*pp
, p
- *pp
, &objfile
->symbol_obstack
);
4291 n
= read_huge_number (pp
, ',', &nbits
);
4293 return error_type (pp
, objfile
);
4295 sym
= (struct symbol
*)
4296 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct symbol
));
4297 memset (sym
, 0, sizeof (struct symbol
));
4298 SYMBOL_NAME (sym
) = name
;
4299 SYMBOL_LANGUAGE (sym
) = current_subfile
->language
;
4300 SYMBOL_CLASS (sym
) = LOC_CONST
;
4301 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4302 SYMBOL_VALUE (sym
) = n
;
4305 add_symbol_to_list (sym
, symlist
);
4310 (*pp
)++; /* Skip the semicolon. */
4312 /* Now fill in the fields of the type-structure. */
4314 TYPE_LENGTH (type
) = TARGET_INT_BIT
/ HOST_CHAR_BIT
;
4315 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
4316 TYPE_FLAGS (type
) &= ~TYPE_FLAG_STUB
;
4318 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
4319 TYPE_NFIELDS (type
) = nsyms
;
4320 TYPE_FIELDS (type
) = (struct field
*)
4321 TYPE_ALLOC (type
, sizeof (struct field
) * nsyms
);
4322 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nsyms
);
4324 /* Find the symbols for the values and put them into the type.
4325 The symbols can be found in the symlist that we put them on
4326 to cause them to be defined. osyms contains the old value
4327 of that symlist; everything up to there was defined by us. */
4328 /* Note that we preserve the order of the enum constants, so
4329 that in something like "enum {FOO, LAST_THING=FOO}" we print
4330 FOO, not LAST_THING. */
4332 for (syms
= *symlist
, n
= nsyms
- 1; syms
; syms
= syms
->next
)
4334 int last
= syms
== osyms
? o_nsyms
: 0;
4335 int j
= syms
->nsyms
;
4336 for (; --j
>= last
; --n
)
4338 struct symbol
*xsym
= syms
->symbol
[j
];
4339 SYMBOL_TYPE (xsym
) = type
;
4340 TYPE_FIELD_NAME (type
, n
) = SYMBOL_NAME (xsym
);
4341 TYPE_FIELD_BITPOS (type
, n
) = SYMBOL_VALUE (xsym
);
4342 TYPE_FIELD_BITSIZE (type
, n
) = 0;
4351 /* Sun's ACC uses a somewhat saner method for specifying the builtin
4352 typedefs in every file (for int, long, etc):
4354 type = b <signed> <width> <format type>; <offset>; <nbits>
4356 optional format type = c or b for char or boolean.
4357 offset = offset from high order bit to start bit of type.
4358 width is # bytes in object of this type, nbits is # bits in type.
4360 The width/offset stuff appears to be for small objects stored in
4361 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
4364 static struct type
*
4365 read_sun_builtin_type (pp
, typenums
, objfile
)
4368 struct objfile
*objfile
;
4373 enum type_code code
= TYPE_CODE_INT
;
4384 return error_type (pp
, objfile
);
4388 /* For some odd reason, all forms of char put a c here. This is strange
4389 because no other type has this honor. We can safely ignore this because
4390 we actually determine 'char'acterness by the number of bits specified in
4392 Boolean forms, e.g Fortran logical*X, put a b here. */
4396 else if (**pp
== 'b')
4398 code
= TYPE_CODE_BOOL
;
4402 /* The first number appears to be the number of bytes occupied
4403 by this type, except that unsigned short is 4 instead of 2.
4404 Since this information is redundant with the third number,
4405 we will ignore it. */
4406 read_huge_number (pp
, ';', &nbits
);
4408 return error_type (pp
, objfile
);
4410 /* The second number is always 0, so ignore it too. */
4411 read_huge_number (pp
, ';', &nbits
);
4413 return error_type (pp
, objfile
);
4415 /* The third number is the number of bits for this type. */
4416 type_bits
= read_huge_number (pp
, 0, &nbits
);
4418 return error_type (pp
, objfile
);
4419 /* The type *should* end with a semicolon. If it are embedded
4420 in a larger type the semicolon may be the only way to know where
4421 the type ends. If this type is at the end of the stabstring we
4422 can deal with the omitted semicolon (but we don't have to like
4423 it). Don't bother to complain(), Sun's compiler omits the semicolon
4429 return init_type (TYPE_CODE_VOID
, 1,
4430 signed_type
? 0 : TYPE_FLAG_UNSIGNED
, (char *) NULL
,
4433 return init_type (code
,
4434 type_bits
/ TARGET_CHAR_BIT
,
4435 signed_type
? 0 : TYPE_FLAG_UNSIGNED
, (char *) NULL
,
4439 static struct type
*
4440 read_sun_floating_type (pp
, typenums
, objfile
)
4443 struct objfile
*objfile
;
4449 /* The first number has more details about the type, for example
4451 details
= read_huge_number (pp
, ';', &nbits
);
4453 return error_type (pp
, objfile
);
4455 /* The second number is the number of bytes occupied by this type */
4456 nbytes
= read_huge_number (pp
, ';', &nbits
);
4458 return error_type (pp
, objfile
);
4460 if (details
== NF_COMPLEX
|| details
== NF_COMPLEX16
4461 || details
== NF_COMPLEX32
)
4462 /* This is a type we can't handle, but we do know the size.
4463 We also will be able to give it a name. */
4464 return init_type (TYPE_CODE_COMPLEX
, nbytes
, 0, NULL
, objfile
);
4466 return init_type (TYPE_CODE_FLT
, nbytes
, 0, NULL
, objfile
);
4469 /* Read a number from the string pointed to by *PP.
4470 The value of *PP is advanced over the number.
4471 If END is nonzero, the character that ends the
4472 number must match END, or an error happens;
4473 and that character is skipped if it does match.
4474 If END is zero, *PP is left pointing to that character.
4476 If the number fits in a long, set *BITS to 0 and return the value.
4477 If not, set *BITS to be the number of bits in the number and return 0.
4479 If encounter garbage, set *BITS to -1 and return 0. */
4482 read_huge_number (pp
, end
, bits
)
4502 /* Leading zero means octal. GCC uses this to output values larger
4503 than an int (because that would be hard in decimal). */
4511 upper_limit
= ULONG_MAX
/ radix
;
4513 upper_limit
= LONG_MAX
/ radix
;
4515 while ((c
= *p
++) >= '0' && c
< ('0' + radix
))
4517 if (n
<= upper_limit
)
4520 n
+= c
- '0'; /* FIXME this overflows anyway */
4525 /* This depends on large values being output in octal, which is
4532 /* Ignore leading zeroes. */
4536 else if (c
== '2' || c
== '3')
4562 /* Large decimal constants are an error (because it is hard to
4563 count how many bits are in them). */
4569 /* -0x7f is the same as 0x80. So deal with it by adding one to
4570 the number of bits. */
4582 /* It's *BITS which has the interesting information. */
4586 static struct type
*
4587 read_range_type (pp
, typenums
, objfile
)
4590 struct objfile
*objfile
;
4592 char *orig_pp
= *pp
;
4597 struct type
*result_type
;
4598 struct type
*index_type
= NULL
;
4600 /* First comes a type we are a subrange of.
4601 In C it is usually 0, 1 or the type being defined. */
4602 if (read_type_number (pp
, rangenums
) != 0)
4603 return error_type (pp
, objfile
);
4604 self_subrange
= (rangenums
[0] == typenums
[0] &&
4605 rangenums
[1] == typenums
[1]);
4610 index_type
= read_type (pp
, objfile
);
4613 /* A semicolon should now follow; skip it. */
4617 /* The remaining two operands are usually lower and upper bounds
4618 of the range. But in some special cases they mean something else. */
4619 n2
= read_huge_number (pp
, ';', &n2bits
);
4620 n3
= read_huge_number (pp
, ';', &n3bits
);
4622 if (n2bits
== -1 || n3bits
== -1)
4623 return error_type (pp
, objfile
);
4626 goto handle_true_range
;
4628 /* If limits are huge, must be large integral type. */
4629 if (n2bits
!= 0 || n3bits
!= 0)
4631 char got_signed
= 0;
4632 char got_unsigned
= 0;
4633 /* Number of bits in the type. */
4636 /* Range from 0 to <large number> is an unsigned large integral type. */
4637 if ((n2bits
== 0 && n2
== 0) && n3bits
!= 0)
4642 /* Range from <large number> to <large number>-1 is a large signed
4643 integral type. Take care of the case where <large number> doesn't
4644 fit in a long but <large number>-1 does. */
4645 else if ((n2bits
!= 0 && n3bits
!= 0 && n2bits
== n3bits
+ 1)
4646 || (n2bits
!= 0 && n3bits
== 0
4647 && (n2bits
== sizeof (long) * HOST_CHAR_BIT
)
4654 if (got_signed
|| got_unsigned
)
4656 return init_type (TYPE_CODE_INT
, nbits
/ TARGET_CHAR_BIT
,
4657 got_unsigned
? TYPE_FLAG_UNSIGNED
: 0, NULL
,
4661 return error_type (pp
, objfile
);
4664 /* A type defined as a subrange of itself, with bounds both 0, is void. */
4665 if (self_subrange
&& n2
== 0 && n3
== 0)
4666 return init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
4668 /* If n3 is zero and n2 is positive, we want a floating type, and n2
4669 is the width in bytes.
4671 Fortran programs appear to use this for complex types also. To
4672 distinguish between floats and complex, g77 (and others?) seem
4673 to use self-subranges for the complexes, and subranges of int for
4676 Also note that for complexes, g77 sets n2 to the size of one of
4677 the member floats, not the whole complex beast. My guess is that
4678 this was to work well with pre-COMPLEX versions of gdb. */
4680 if (n3
== 0 && n2
> 0)
4684 return init_type (TYPE_CODE_COMPLEX
, 2 * n2
, 0, NULL
, objfile
);
4688 return init_type (TYPE_CODE_FLT
, n2
, 0, NULL
, objfile
);
4692 /* If the upper bound is -1, it must really be an unsigned int. */
4694 else if (n2
== 0 && n3
== -1)
4696 /* It is unsigned int or unsigned long. */
4697 /* GCC 2.3.3 uses this for long long too, but that is just a GDB 3.5
4698 compatibility hack. */
4699 return init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
4700 TYPE_FLAG_UNSIGNED
, NULL
, objfile
);
4703 /* Special case: char is defined (Who knows why) as a subrange of
4704 itself with range 0-127. */
4705 else if (self_subrange
&& n2
== 0 && n3
== 127)
4706 return init_type (TYPE_CODE_INT
, 1, 0, NULL
, objfile
);
4708 else if (current_symbol
&& SYMBOL_LANGUAGE (current_symbol
) == language_chill
4710 goto handle_true_range
;
4712 /* We used to do this only for subrange of self or subrange of int. */
4715 /* -1 is used for the upper bound of (4 byte) "unsigned int" and
4716 "unsigned long", and we already checked for that,
4717 so don't need to test for it here. */
4720 /* n3 actually gives the size. */
4721 return init_type (TYPE_CODE_INT
, -n3
, TYPE_FLAG_UNSIGNED
,
4724 /* Is n3 == 2**(8n)-1 for some integer n? Then it's an
4725 unsigned n-byte integer. But do require n to be a power of
4726 two; we don't want 3- and 5-byte integers flying around. */
4732 for (bytes
= 0; (bits
& 0xff) == 0xff; bytes
++)
4735 && ((bytes
- 1) & bytes
) == 0) /* "bytes is a power of two" */
4736 return init_type (TYPE_CODE_INT
, bytes
, TYPE_FLAG_UNSIGNED
, NULL
,
4740 /* I think this is for Convex "long long". Since I don't know whether
4741 Convex sets self_subrange, I also accept that particular size regardless
4742 of self_subrange. */
4743 else if (n3
== 0 && n2
< 0
4745 || n2
== -TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
))
4746 return init_type (TYPE_CODE_INT
, -n2
, 0, NULL
, objfile
);
4747 else if (n2
== -n3
- 1)
4750 return init_type (TYPE_CODE_INT
, 1, 0, NULL
, objfile
);
4752 return init_type (TYPE_CODE_INT
, 2, 0, NULL
, objfile
);
4753 if (n3
== 0x7fffffff)
4754 return init_type (TYPE_CODE_INT
, 4, 0, NULL
, objfile
);
4757 /* We have a real range type on our hands. Allocate space and
4758 return a real pointer. */
4762 index_type
= builtin_type_int
;
4764 index_type
= *dbx_lookup_type (rangenums
);
4765 if (index_type
== NULL
)
4767 /* Does this actually ever happen? Is that why we are worrying
4768 about dealing with it rather than just calling error_type? */
4770 static struct type
*range_type_index
;
4772 complain (&range_type_base_complaint
, rangenums
[1]);
4773 if (range_type_index
== NULL
)
4775 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
4776 0, "range type index type", NULL
);
4777 index_type
= range_type_index
;
4780 result_type
= create_range_type ((struct type
*) NULL
, index_type
, n2
, n3
);
4781 return (result_type
);
4784 /* Read in an argument list. This is a list of types, separated by commas
4785 and terminated with END. Return the list of types read in, or (struct type
4786 **)-1 if there is an error. */
4788 static struct type
**
4789 read_args (pp
, end
, objfile
)
4792 struct objfile
*objfile
;
4794 /* FIXME! Remove this arbitrary limit! */
4795 struct type
*types
[1024], **rval
; /* allow for fns of 1023 parameters */
4801 /* Invalid argument list: no ','. */
4802 return (struct type
**) -1;
4804 STABS_CONTINUE (pp
, objfile
);
4805 types
[n
++] = read_type (pp
, objfile
);
4807 (*pp
)++; /* get past `end' (the ':' character) */
4811 rval
= (struct type
**) xmalloc (2 * sizeof (struct type
*));
4813 else if (TYPE_CODE (types
[n
- 1]) != TYPE_CODE_VOID
)
4815 rval
= (struct type
**) xmalloc ((n
+ 1) * sizeof (struct type
*));
4816 memset (rval
+ n
, 0, sizeof (struct type
*));
4820 rval
= (struct type
**) xmalloc (n
* sizeof (struct type
*));
4822 memcpy (rval
, types
, n
* sizeof (struct type
*));
4826 /* Common block handling. */
4828 /* List of symbols declared since the last BCOMM. This list is a tail
4829 of local_symbols. When ECOMM is seen, the symbols on the list
4830 are noted so their proper addresses can be filled in later,
4831 using the common block base address gotten from the assembler
4834 static struct pending
*common_block
;
4835 static int common_block_i
;
4837 /* Name of the current common block. We get it from the BCOMM instead of the
4838 ECOMM to match IBM documentation (even though IBM puts the name both places
4839 like everyone else). */
4840 static char *common_block_name
;
4842 /* Process a N_BCOMM symbol. The storage for NAME is not guaranteed
4843 to remain after this function returns. */
4846 common_block_start (name
, objfile
)
4848 struct objfile
*objfile
;
4850 if (common_block_name
!= NULL
)
4852 static struct complaint msg
=
4854 "Invalid symbol data: common block within common block",
4858 common_block
= local_symbols
;
4859 common_block_i
= local_symbols
? local_symbols
->nsyms
: 0;
4860 common_block_name
= obsavestring (name
, strlen (name
),
4861 &objfile
->symbol_obstack
);
4864 /* Process a N_ECOMM symbol. */
4867 common_block_end (objfile
)
4868 struct objfile
*objfile
;
4870 /* Symbols declared since the BCOMM are to have the common block
4871 start address added in when we know it. common_block and
4872 common_block_i point to the first symbol after the BCOMM in
4873 the local_symbols list; copy the list and hang it off the
4874 symbol for the common block name for later fixup. */
4877 struct pending
*new = 0;
4878 struct pending
*next
;
4881 if (common_block_name
== NULL
)
4883 static struct complaint msg
=
4884 {"ECOMM symbol unmatched by BCOMM", 0, 0};
4889 sym
= (struct symbol
*)
4890 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct symbol
));
4891 memset (sym
, 0, sizeof (struct symbol
));
4892 /* Note: common_block_name already saved on symbol_obstack */
4893 SYMBOL_NAME (sym
) = common_block_name
;
4894 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
4896 /* Now we copy all the symbols which have been defined since the BCOMM. */
4898 /* Copy all the struct pendings before common_block. */
4899 for (next
= local_symbols
;
4900 next
!= NULL
&& next
!= common_block
;
4903 for (j
= 0; j
< next
->nsyms
; j
++)
4904 add_symbol_to_list (next
->symbol
[j
], &new);
4907 /* Copy however much of COMMON_BLOCK we need. If COMMON_BLOCK is
4908 NULL, it means copy all the local symbols (which we already did
4911 if (common_block
!= NULL
)
4912 for (j
= common_block_i
; j
< common_block
->nsyms
; j
++)
4913 add_symbol_to_list (common_block
->symbol
[j
], &new);
4915 SYMBOL_TYPE (sym
) = (struct type
*) new;
4917 /* Should we be putting local_symbols back to what it was?
4920 i
= hashname (SYMBOL_NAME (sym
));
4921 SYMBOL_VALUE_CHAIN (sym
) = global_sym_chain
[i
];
4922 global_sym_chain
[i
] = sym
;
4923 common_block_name
= NULL
;
4926 /* Add a common block's start address to the offset of each symbol
4927 declared to be in it (by being between a BCOMM/ECOMM pair that uses
4928 the common block name). */
4931 fix_common_block (sym
, valu
)
4935 struct pending
*next
= (struct pending
*) SYMBOL_TYPE (sym
);
4936 for (; next
; next
= next
->next
)
4939 for (j
= next
->nsyms
- 1; j
>= 0; j
--)
4940 SYMBOL_VALUE_ADDRESS (next
->symbol
[j
]) += valu
;
4946 /* What about types defined as forward references inside of a small lexical
4948 /* Add a type to the list of undefined types to be checked through
4949 once this file has been read in. */
4952 add_undefined_type (type
)
4955 if (undef_types_length
== undef_types_allocated
)
4957 undef_types_allocated
*= 2;
4958 undef_types
= (struct type
**)
4959 xrealloc ((char *) undef_types
,
4960 undef_types_allocated
* sizeof (struct type
*));
4962 undef_types
[undef_types_length
++] = type
;
4965 /* Go through each undefined type, see if it's still undefined, and fix it
4966 up if possible. We have two kinds of undefined types:
4968 TYPE_CODE_ARRAY: Array whose target type wasn't defined yet.
4969 Fix: update array length using the element bounds
4970 and the target type's length.
4971 TYPE_CODE_STRUCT, TYPE_CODE_UNION: Structure whose fields were not
4972 yet defined at the time a pointer to it was made.
4973 Fix: Do a full lookup on the struct/union tag. */
4975 cleanup_undefined_types ()
4979 for (type
= undef_types
; type
< undef_types
+ undef_types_length
; type
++)
4981 switch (TYPE_CODE (*type
))
4984 case TYPE_CODE_STRUCT
:
4985 case TYPE_CODE_UNION
:
4986 case TYPE_CODE_ENUM
:
4988 /* Check if it has been defined since. Need to do this here
4989 as well as in check_typedef to deal with the (legitimate in
4990 C though not C++) case of several types with the same name
4991 in different source files. */
4992 if (TYPE_FLAGS (*type
) & TYPE_FLAG_STUB
)
4994 struct pending
*ppt
;
4996 /* Name of the type, without "struct" or "union" */
4997 char *typename
= TYPE_TAG_NAME (*type
);
4999 if (typename
== NULL
)
5001 static struct complaint msg
=
5002 {"need a type name", 0, 0};
5006 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
5008 for (i
= 0; i
< ppt
->nsyms
; i
++)
5010 struct symbol
*sym
= ppt
->symbol
[i
];
5012 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
5013 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
5014 && (TYPE_CODE (SYMBOL_TYPE (sym
)) ==
5016 && STREQ (SYMBOL_NAME (sym
), typename
))
5018 memcpy (*type
, SYMBOL_TYPE (sym
),
5019 sizeof (struct type
));
5029 static struct complaint msg
=
5031 GDB internal error. cleanup_undefined_types with bad type %d.", 0, 0};
5032 complain (&msg
, TYPE_CODE (*type
));
5038 undef_types_length
= 0;
5041 /* Scan through all of the global symbols defined in the object file,
5042 assigning values to the debugging symbols that need to be assigned
5043 to. Get these symbols from the minimal symbol table. */
5046 scan_file_globals (objfile
)
5047 struct objfile
*objfile
;
5050 struct minimal_symbol
*msymbol
;
5051 struct symbol
*sym
, *prev
, *rsym
;
5052 struct objfile
*resolve_objfile
;
5054 /* SVR4 based linkers copy referenced global symbols from shared
5055 libraries to the main executable.
5056 If we are scanning the symbols for a shared library, try to resolve
5057 them from the minimal symbols of the main executable first. */
5059 if (symfile_objfile
&& objfile
!= symfile_objfile
)
5060 resolve_objfile
= symfile_objfile
;
5062 resolve_objfile
= objfile
;
5066 /* Avoid expensive loop through all minimal symbols if there are
5067 no unresolved symbols. */
5068 for (hash
= 0; hash
< HASHSIZE
; hash
++)
5070 if (global_sym_chain
[hash
])
5073 if (hash
>= HASHSIZE
)
5076 for (msymbol
= resolve_objfile
->msymbols
;
5077 msymbol
&& SYMBOL_NAME (msymbol
) != NULL
;
5082 /* Skip static symbols. */
5083 switch (MSYMBOL_TYPE (msymbol
))
5095 /* Get the hash index and check all the symbols
5096 under that hash index. */
5098 hash
= hashname (SYMBOL_NAME (msymbol
));
5100 for (sym
= global_sym_chain
[hash
]; sym
;)
5102 if (SYMBOL_NAME (msymbol
)[0] == SYMBOL_NAME (sym
)[0] &&
5103 STREQ (SYMBOL_NAME (msymbol
) + 1, SYMBOL_NAME (sym
) + 1))
5106 struct alias_list
*aliases
;
5108 /* Splice this symbol out of the hash chain and
5109 assign the value we have to it. */
5112 SYMBOL_VALUE_CHAIN (prev
) = SYMBOL_VALUE_CHAIN (sym
);
5116 global_sym_chain
[hash
] = SYMBOL_VALUE_CHAIN (sym
);
5119 /* Check to see whether we need to fix up a common block. */
5120 /* Note: this code might be executed several times for
5121 the same symbol if there are multiple references. */
5123 /* If symbol has aliases, do minimal symbol fixups for each.
5124 These live aliases/references weren't added to
5125 global_sym_chain hash but may also need to be fixed up. */
5126 /* FIXME: Maybe should have added aliases to the global chain, resolved symbol name, then treated aliases as normal
5127 symbols? Still, we wouldn't want to add_to_list. */
5128 /* Now do the same for each alias of this symbol */
5130 aliases
= SYMBOL_ALIASES (sym
);
5133 if (SYMBOL_CLASS (rsym
) == LOC_BLOCK
)
5135 fix_common_block (rsym
,
5136 SYMBOL_VALUE_ADDRESS (msymbol
));
5140 SYMBOL_VALUE_ADDRESS (rsym
)
5141 = SYMBOL_VALUE_ADDRESS (msymbol
);
5143 SYMBOL_SECTION (rsym
) = SYMBOL_SECTION (msymbol
);
5146 rsym
= aliases
->sym
;
5147 aliases
= aliases
->next
;
5156 sym
= SYMBOL_VALUE_CHAIN (prev
);
5160 sym
= global_sym_chain
[hash
];
5166 sym
= SYMBOL_VALUE_CHAIN (sym
);
5170 if (resolve_objfile
== objfile
)
5172 resolve_objfile
= objfile
;
5175 /* Change the storage class of any remaining unresolved globals to
5176 LOC_UNRESOLVED and remove them from the chain. */
5177 for (hash
= 0; hash
< HASHSIZE
; hash
++)
5179 sym
= global_sym_chain
[hash
];
5183 sym
= SYMBOL_VALUE_CHAIN (sym
);
5185 /* Change the symbol address from the misleading chain value
5187 SYMBOL_VALUE_ADDRESS (prev
) = 0;
5189 /* Complain about unresolved common block symbols. */
5190 if (SYMBOL_CLASS (prev
) == LOC_STATIC
)
5191 SYMBOL_CLASS (prev
) = LOC_UNRESOLVED
;
5193 complain (&unresolved_sym_chain_complaint
,
5194 objfile
->name
, SYMBOL_NAME (prev
));
5197 memset (global_sym_chain
, 0, sizeof (global_sym_chain
));
5200 /* Initialize anything that needs initializing when starting to read
5201 a fresh piece of a symbol file, e.g. reading in the stuff corresponding
5209 /* Initialize anything that needs initializing when a completely new
5210 symbol file is specified (not just adding some symbols from another
5211 file, e.g. a shared library). */
5214 stabsread_new_init ()
5216 /* Empty the hash table of global syms looking for values. */
5217 memset (global_sym_chain
, 0, sizeof (global_sym_chain
));
5220 /* Initialize anything that needs initializing at the same time as
5221 start_symtab() is called. */
5226 global_stabs
= NULL
; /* AIX COFF */
5227 /* Leave FILENUM of 0 free for builtin types and this file's types. */
5228 n_this_object_header_files
= 1;
5229 type_vector_length
= 0;
5230 type_vector
= (struct type
**) 0;
5232 /* FIXME: If common_block_name is not already NULL, we should complain(). */
5233 common_block_name
= NULL
;
5238 /* Call after end_symtab() */
5245 free ((char *) type_vector
);
5248 type_vector_length
= 0;
5249 previous_stab_code
= 0;
5253 finish_global_stabs (objfile
)
5254 struct objfile
*objfile
;
5258 patch_block_stabs (global_symbols
, global_stabs
, objfile
);
5259 free ((PTR
) global_stabs
);
5260 global_stabs
= NULL
;
5264 /* Initializer for this module */
5267 _initialize_stabsread ()
5269 undef_types_allocated
= 20;
5270 undef_types_length
= 0;
5271 undef_types
= (struct type
**)
5272 xmalloc (undef_types_allocated
* sizeof (struct type
*));