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 #if !defined (REG_STRUCT_HAS_ADDR)
563 #define REG_STRUCT_HAS_ADDR(gcc_p,type) 0
566 #define VISIBILITY_PRIVATE '0' /* Stabs character for private field */
567 #define VISIBILITY_PROTECTED '1' /* Stabs character for protected fld */
568 #define VISIBILITY_PUBLIC '2' /* Stabs character for public field */
569 #define VISIBILITY_IGNORE '9' /* Optimized out or zero length */
571 #define CFRONT_VISIBILITY_PRIVATE '2' /* Stabs character for private field */
572 #define CFRONT_VISIBILITY_PUBLIC '1' /* Stabs character for public field */
574 /* This code added to support parsing of ARM/Cfront stabs strings */
576 /* Get substring from string up to char c, advance string pointer past
597 /* Physname gets strcat'd onto sname in order to recreate the mangled
598 name (see funtion gdb_mangle_name in gdbtypes.c). For cfront, make
599 the physname look like that of g++ - take out the initial mangling
600 eg: for sname="a" and fname="foo__1aFPFs_i" return "FPFs_i" */
603 get_cfront_method_physname (fname
)
607 /* FIXME would like to make this generic for g++ too, but
608 that is already handled in read_member_funcctions */
611 /* search ahead to find the start of the mangled suffix */
612 if (*p
== '_' && *(p
+ 1) == '_') /* compiler generated; probably a ctor/dtor */
614 while (p
&& (unsigned) ((p
+ 1) - fname
) < strlen (fname
) && *(p
+ 1) != '_')
616 if (!(p
&& *p
== '_' && *(p
+ 1) == '_'))
617 error ("Invalid mangled function name %s", fname
);
618 p
+= 2; /* advance past '__' */
620 /* struct name length and name of type should come next; advance past it */
623 len
= len
* 10 + (*p
- '0');
631 /* Read base classes within cfront class definition.
632 eg: A:ZcA;1@Bpub v2@Bvirpri;__ct__1AFv func__1AFv *sfunc__1AFv ;as__1A ;;
635 A:ZcA;;foopri__1AFv foopro__1AFv __ct__1AFv __ct__1AFRC1A foopub__1AFv ;;;
640 read_cfront_baseclasses (fip
, pp
, type
, objfile
)
641 struct field_info
*fip
;
642 struct objfile
*objfile
;
646 static struct complaint msg_unknown
=
648 Unsupported token in stabs string %s.\n",
650 static struct complaint msg_notfound
=
652 Unable to find base type for %s.\n",
657 struct nextfield
*new;
659 if (**pp
== ';') /* no base classes; return */
665 /* first count base classes so we can allocate space before parsing */
666 for (p
= *pp
; p
&& *p
&& *p
!= ';'; p
++)
671 bnum
++; /* add one more for last one */
673 /* now parse the base classes until we get to the start of the methods
674 (code extracted and munged from read_baseclasses) */
675 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
676 TYPE_N_BASECLASSES (type
) = bnum
;
680 int num_bytes
= B_BYTES (TYPE_N_BASECLASSES (type
));
683 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
684 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
686 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), TYPE_N_BASECLASSES (type
));
688 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
690 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
691 make_cleanup (free
, new);
692 memset (new, 0, sizeof (struct nextfield
));
693 new->next
= fip
->list
;
695 FIELD_BITSIZE (new->field
) = 0; /* this should be an unpacked field! */
697 STABS_CONTINUE (pp
, objfile
);
699 /* virtual? eg: v2@Bvir */
702 SET_TYPE_FIELD_VIRTUAL (type
, i
);
706 /* access? eg: 2@Bvir */
707 /* Note: protected inheritance not supported in cfront */
710 case CFRONT_VISIBILITY_PRIVATE
:
711 new->visibility
= VISIBILITY_PRIVATE
;
713 case CFRONT_VISIBILITY_PUBLIC
:
714 new->visibility
= VISIBILITY_PUBLIC
;
717 /* Bad visibility format. Complain and treat it as
720 static struct complaint msg
=
722 "Unknown visibility `%c' for baseclass", 0, 0};
723 complain (&msg
, new->visibility
);
724 new->visibility
= VISIBILITY_PUBLIC
;
728 /* "@" comes next - eg: @Bvir */
731 complain (&msg_unknown
, *pp
);
737 /* Set the bit offset of the portion of the object corresponding
738 to this baseclass. Always zero in the absence of
739 multiple inheritance. */
740 /* Unable to read bit position from stabs;
741 Assuming no multiple inheritance for now FIXME! */
742 /* We may have read this in the structure definition;
743 now we should fixup the members to be the actual base classes */
744 FIELD_BITPOS (new->field
) = 0;
746 /* Get the base class name and type */
748 char *bname
; /* base class name */
749 struct symbol
*bsym
; /* base class */
751 p1
= strchr (*pp
, ' ');
752 p2
= strchr (*pp
, ';');
754 bname
= get_substring (pp
, ' ');
756 bname
= get_substring (pp
, ';');
757 if (!bname
|| !*bname
)
759 complain (&msg_unknown
, *pp
);
762 /* FIXME! attach base info to type */
763 bsym
= lookup_symbol (bname
, 0, STRUCT_NAMESPACE
, 0, 0); /*demangled_name */
766 new->field
.type
= SYMBOL_TYPE (bsym
);
767 new->field
.name
= type_name_no_tag (new->field
.type
);
771 complain (&msg_notfound
, *pp
);
776 /* If more base classes to parse, loop again.
777 We ate the last ' ' or ';' in get_substring,
778 so on exit we will have skipped the trailing ';' */
779 /* if invalid, return 0; add code to detect - FIXME! */
784 /* read cfront member functions.
785 pp points to string starting with list of functions
786 eg: A:ZcA;1@Bpub v2@Bvirpri;__ct__1AFv func__1AFv *sfunc__1AFv ;as__1A ;;
787 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
788 A:ZcA;;foopri__1AFv foopro__1AFv __ct__1AFv __ct__1AFRC1A foopub__1AFv ;;;
789 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
793 read_cfront_member_functions (fip
, pp
, type
, objfile
)
794 struct field_info
*fip
;
797 struct objfile
*objfile
;
799 /* This code extracted from read_member_functions
800 so as to do the similar thing for our funcs */
804 /* Total number of member functions defined in this class. If the class
805 defines two `f' functions, and one `g' function, then this will have
807 int total_length
= 0;
811 struct next_fnfield
*next
;
812 struct fn_field fn_field
;
815 struct type
*look_ahead_type
;
816 struct next_fnfieldlist
*new_fnlist
;
817 struct next_fnfield
*new_sublist
;
820 struct symbol
*ref_func
= 0;
822 /* Process each list until we find the end of the member functions.
823 eg: p = "__ct__1AFv foo__1AFv ;;;" */
825 STABS_CONTINUE (pp
, objfile
); /* handle \\ */
827 while (**pp
!= ';' && (fname
= get_substring (pp
, ' '), fname
))
830 int sublist_count
= 0;
832 if (fname
[0] == '*') /* static member */
838 ref_func
= lookup_symbol (fname
, 0, VAR_NAMESPACE
, 0, 0); /* demangled name */
841 static struct complaint msg
=
843 Unable to find function symbol for %s\n",
845 complain (&msg
, fname
);
849 look_ahead_type
= NULL
;
852 new_fnlist
= (struct next_fnfieldlist
*)
853 xmalloc (sizeof (struct next_fnfieldlist
));
854 make_cleanup (free
, new_fnlist
);
855 memset (new_fnlist
, 0, sizeof (struct next_fnfieldlist
));
857 /* The following is code to work around cfront generated stabs.
858 The stabs contains full mangled name for each field.
859 We try to demangle the name and extract the field name out of it. */
861 char *dem
, *dem_p
, *dem_args
;
863 dem
= cplus_demangle (fname
, DMGL_ANSI
| DMGL_PARAMS
);
866 dem_p
= strrchr (dem
, ':');
867 if (dem_p
!= 0 && *(dem_p
- 1) == ':')
869 /* get rid of args */
870 dem_args
= strchr (dem_p
, '(');
871 if (dem_args
== NULL
)
872 dem_len
= strlen (dem_p
);
874 dem_len
= dem_args
- dem_p
;
876 obsavestring (dem_p
, dem_len
, &objfile
->type_obstack
);
881 obsavestring (fname
, strlen (fname
), &objfile
->type_obstack
);
883 } /* end of code for cfront work around */
885 new_fnlist
->fn_fieldlist
.name
= main_fn_name
;
887 /*-------------------------------------------------*/
888 /* Set up the sublists
889 Sublists are stuff like args, static, visibility, etc.
890 so in ARM, we have to set that info some other way.
891 Multiple sublists happen if overloading
892 eg: foo::26=##1;:;2A.;
893 In g++, we'd loop here thru all the sublists... */
896 (struct next_fnfield
*) xmalloc (sizeof (struct next_fnfield
));
897 make_cleanup (free
, new_sublist
);
898 memset (new_sublist
, 0, sizeof (struct next_fnfield
));
900 /* eat 1; from :;2A.; */
901 new_sublist
->fn_field
.type
= SYMBOL_TYPE (ref_func
); /* normally takes a read_type */
902 /* Make this type look like a method stub for gdb */
903 TYPE_FLAGS (new_sublist
->fn_field
.type
) |= TYPE_FLAG_STUB
;
904 TYPE_CODE (new_sublist
->fn_field
.type
) = TYPE_CODE_METHOD
;
906 /* If this is just a stub, then we don't have the real name here. */
907 if (TYPE_FLAGS (new_sublist
->fn_field
.type
) & TYPE_FLAG_STUB
)
909 if (!TYPE_DOMAIN_TYPE (new_sublist
->fn_field
.type
))
910 TYPE_DOMAIN_TYPE (new_sublist
->fn_field
.type
) = type
;
911 new_sublist
->fn_field
.is_stub
= 1;
914 /* physname used later in mangling; eg PFs_i,5 for foo__1aFPFs_i
915 physname gets strcat'd in order to recreate the onto mangled name */
916 pname
= get_cfront_method_physname (fname
);
917 new_sublist
->fn_field
.physname
= savestring (pname
, strlen (pname
));
920 /* Set this member function's visibility fields.
921 Unable to distinguish access from stabs definition!
922 Assuming public for now. FIXME!
923 (for private, set new_sublist->fn_field.is_private = 1,
924 for public, set new_sublist->fn_field.is_protected = 1) */
926 /* Unable to distinguish const/volatile from stabs definition!
927 Assuming normal for now. FIXME! */
929 new_sublist
->fn_field
.is_const
= 0;
930 new_sublist
->fn_field
.is_volatile
= 0; /* volatile not implemented in cfront */
932 /* Set virtual/static function info
933 How to get vtable offsets ?
934 Assuming normal for now FIXME!!
935 For vtables, figure out from whence this virtual function came.
936 It may belong to virtual function table of
937 one of its baseclasses.
939 new_sublist -> fn_field.voffset = vtable offset,
940 new_sublist -> fn_field.fcontext = look_ahead_type;
941 where look_ahead_type is type of baseclass */
943 new_sublist
->fn_field
.voffset
= VOFFSET_STATIC
;
944 else /* normal member function. */
945 new_sublist
->fn_field
.voffset
= 0;
946 new_sublist
->fn_field
.fcontext
= 0;
949 /* Prepare new sublist */
950 new_sublist
->next
= sublist
;
951 sublist
= new_sublist
;
954 /* In g++, we loop thu sublists - now we set from functions. */
955 new_fnlist
->fn_fieldlist
.fn_fields
= (struct fn_field
*)
956 obstack_alloc (&objfile
->type_obstack
,
957 sizeof (struct fn_field
) * length
);
958 memset (new_fnlist
->fn_fieldlist
.fn_fields
, 0,
959 sizeof (struct fn_field
) * length
);
960 for (i
= length
; (i
--, sublist
); sublist
= sublist
->next
)
962 new_fnlist
->fn_fieldlist
.fn_fields
[i
] = sublist
->fn_field
;
965 new_fnlist
->fn_fieldlist
.length
= length
;
966 new_fnlist
->next
= fip
->fnlist
;
967 fip
->fnlist
= new_fnlist
;
969 total_length
+= length
;
970 STABS_CONTINUE (pp
, objfile
); /* handle \\ */
975 /* type should already have space */
976 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
977 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * nfn_fields
);
978 memset (TYPE_FN_FIELDLISTS (type
), 0,
979 sizeof (struct fn_fieldlist
) * nfn_fields
);
980 TYPE_NFN_FIELDS (type
) = nfn_fields
;
981 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
984 /* end of scope for reading member func */
988 /* Skip trailing ';' and bump count of number of fields seen */
996 /* This routine fixes up partial cfront types that were created
997 while parsing the stabs. The main need for this function is
998 to add information such as methods to classes.
999 Examples of "p": "sA;;__ct__1AFv foo__1AFv ;;;" */
1001 resolve_cfront_continuation (objfile
, sym
, p
)
1002 struct objfile
*objfile
;
1006 struct symbol
*ref_sym
= 0;
1008 /* snarfed from read_struct_type */
1009 struct field_info fi
;
1011 struct cleanup
*back_to
;
1013 /* Need to make sure that fi isn't gunna conflict with struct
1014 in case struct already had some fnfs */
1017 back_to
= make_cleanup (null_cleanup
, 0);
1019 /* We only accept structs, classes and unions at the moment.
1020 Other continuation types include t (typedef), r (long dbl), ...
1021 We may want to add support for them as well;
1022 right now they are handled by duplicating the symbol information
1023 into the type information (see define_symbol) */
1024 if (*p
!= 's' /* structs */
1025 && *p
!= 'c' /* class */
1026 && *p
!= 'u') /* union */
1027 return 0; /* only handle C++ types */
1030 /* Get symbol typs name and validate
1031 eg: p = "A;;__ct__1AFv foo__1AFv ;;;" */
1032 sname
= get_substring (&p
, ';');
1033 if (!sname
|| strcmp (sname
, SYMBOL_NAME (sym
)))
1034 error ("Internal error: base symbol type name does not match\n");
1036 /* Find symbol's internal gdb reference using demangled_name.
1037 This is the real sym that we want;
1038 sym was a temp hack to make debugger happy */
1039 ref_sym
= lookup_symbol (SYMBOL_NAME (sym
), 0, STRUCT_NAMESPACE
, 0, 0);
1040 type
= SYMBOL_TYPE (ref_sym
);
1043 /* Now read the baseclasses, if any, read the regular C struct or C++
1044 class member fields, attach the fields to the type, read the C++
1045 member functions, attach them to the type, and then read any tilde
1046 field (baseclass specifier for the class holding the main vtable). */
1048 if (!read_cfront_baseclasses (&fi
, &p
, type
, objfile
)
1049 /* g++ does this next, but cfront already did this:
1050 || !read_struct_fields (&fi, &p, type, objfile) */
1051 || !copy_cfront_struct_fields (&fi
, type
, objfile
)
1052 || !read_cfront_member_functions (&fi
, &p
, type
, objfile
)
1053 || !read_cfront_static_fields (&fi
, &p
, type
, objfile
)
1054 || !attach_fields_to_type (&fi
, type
, objfile
)
1055 || !attach_fn_fields_to_type (&fi
, type
)
1056 /* g++ does this next, but cfront doesn't seem to have this:
1057 || !read_tilde_fields (&fi, &p, type, objfile) */
1060 type
= error_type (&p
, objfile
);
1063 do_cleanups (back_to
);
1066 /* End of code added to support parsing of ARM/Cfront stabs strings */
1069 /* This routine fixes up symbol references/aliases to point to the original
1070 symbol definition. Returns 0 on failure, non-zero on success. */
1073 resolve_symbol_reference (objfile
, sym
, p
)
1074 struct objfile
*objfile
;
1079 struct symbol
*ref_sym
= 0;
1080 struct alias_list
*alias
;
1082 /* If this is not a symbol reference return now. */
1086 /* Use "#<num>" as the name; we'll fix the name later.
1087 We stored the original symbol name as "#<id>=<name>"
1088 so we can now search for "#<id>" to resolving the reference.
1089 We'll fix the names later by removing the "#<id>" or "#<id>=" */
1091 /*---------------------------------------------------------*/
1092 /* Get the reference id number, and
1093 advance p past the names so we can parse the rest.
1094 eg: id=2 for p : "2=", "2=z:r(0,1)" "2:r(0,1);l(#5,#6),l(#7,#4)" */
1095 /*---------------------------------------------------------*/
1097 /* This gets reference name from string. sym may not have a name. */
1099 /* Get the reference number associated with the reference id in the
1100 gdb stab string. From that reference number, get the main/primary
1101 symbol for this alias. */
1102 refnum
= process_reference (&p
);
1103 ref_sym
= ref_search (refnum
);
1106 complain (&lrs_general_complaint
, "symbol for reference not found");
1110 /* Parse the stab of the referencing symbol
1111 now that we have the referenced symbol.
1112 Add it as a new symbol and a link back to the referenced symbol.
1113 eg: p : "=", "=z:r(0,1)" ":r(0,1);l(#5,#6),l(#7,#4)" */
1116 /* If the stab symbol table and string contain:
1117 RSYM 0 5 00000000 868 #15=z:r(0,1)
1118 LBRAC 0 0 00000000 899 #5=
1119 SLINE 0 16 00000003 923 #6=
1120 Then the same symbols can be later referenced by:
1121 RSYM 0 5 00000000 927 #15:r(0,1);l(#5,#6)
1122 This is used in live range splitting to:
1123 1) specify that a symbol (#15) is actually just a new storage
1124 class for a symbol (#15=z) which was previously defined.
1125 2) specify that the beginning and ending ranges for a symbol
1126 (#15) are the values of the beginning (#5) and ending (#6)
1129 /* Read number as reference id.
1130 eg: p : "=", "=z:r(0,1)" ":r(0,1);l(#5,#6),l(#7,#4)" */
1131 /* FIXME! Might I want to use SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
1132 in case of "l(0,0)"? */
1134 /*--------------------------------------------------*/
1135 /* Add this symbol to the reference list. */
1136 /*--------------------------------------------------*/
1138 alias
= (struct alias_list
*) obstack_alloc (&objfile
->type_obstack
,
1139 sizeof (struct alias_list
));
1142 complain (&lrs_general_complaint
, "Unable to allocate alias list memory");
1149 if (!SYMBOL_ALIASES (ref_sym
))
1151 SYMBOL_ALIASES (ref_sym
) = alias
;
1155 struct alias_list
*temp
;
1157 /* Get to the end of the list. */
1158 for (temp
= SYMBOL_ALIASES (ref_sym
);
1165 /* Want to fix up name so that other functions (eg. valops)
1166 will correctly print the name.
1167 Don't add_symbol_to_list so that lookup_symbol won't find it.
1168 nope... needed for fixups. */
1169 SYMBOL_NAME (sym
) = SYMBOL_NAME (ref_sym
);
1175 /* Structure for storing pointers to reference definitions for fast lookup
1176 during "process_later". */
1185 #define MAX_CHUNK_REFS 100
1186 #define REF_CHUNK_SIZE (MAX_CHUNK_REFS * sizeof (struct ref_map))
1187 #define REF_MAP_SIZE(ref_chunk) ((ref_chunk) * REF_CHUNK_SIZE)
1189 static struct ref_map
*ref_map
;
1191 /* Ptr to free cell in chunk's linked list. */
1192 static int ref_count
= 0;
1194 /* Number of chunks malloced. */
1195 static int ref_chunk
= 0;
1197 /* This file maintains a cache of stabs aliases found in the symbol
1198 table. If the symbol table changes, this cache must be cleared
1199 or we are left holding onto data in invalid obstacks. */
1201 stabsread_clear_cache ()
1207 /* Create array of pointers mapping refids to symbols and stab strings.
1208 Add pointers to reference definition symbols and/or their values as we
1209 find them, using their reference numbers as our index.
1210 These will be used later when we resolve references. */
1212 ref_add (refnum
, sym
, stabs
, value
)
1220 if (refnum
>= ref_count
)
1221 ref_count
= refnum
+ 1;
1222 if (ref_count
> ref_chunk
* MAX_CHUNK_REFS
)
1224 int new_slots
= ref_count
- ref_chunk
* MAX_CHUNK_REFS
;
1225 int new_chunks
= new_slots
/ MAX_CHUNK_REFS
+ 1;
1226 ref_map
= (struct ref_map
*)
1227 xrealloc (ref_map
, REF_MAP_SIZE (ref_chunk
+ new_chunks
));
1228 memset (ref_map
+ ref_chunk
* MAX_CHUNK_REFS
, 0, new_chunks
* REF_CHUNK_SIZE
);
1229 ref_chunk
+= new_chunks
;
1231 ref_map
[refnum
].stabs
= stabs
;
1232 ref_map
[refnum
].sym
= sym
;
1233 ref_map
[refnum
].value
= value
;
1236 /* Return defined sym for the reference REFNUM. */
1241 if (refnum
< 0 || refnum
> ref_count
)
1243 return ref_map
[refnum
].sym
;
1246 /* Return value for the reference REFNUM. */
1249 ref_search_value (refnum
)
1252 if (refnum
< 0 || refnum
> ref_count
)
1254 return ref_map
[refnum
].value
;
1257 /* Parse a reference id in STRING and return the resulting
1258 reference number. Move STRING beyond the reference id. */
1261 process_reference (string
)
1267 if (**string
!= '#')
1270 /* Advance beyond the initial '#'. */
1273 /* Read number as reference id. */
1274 while (*p
&& isdigit (*p
))
1276 refnum
= refnum
* 10 + *p
- '0';
1283 /* If STRING defines a reference, store away a pointer to the reference
1284 definition for later use. Return the reference number. */
1287 symbol_reference_defined (string
)
1293 refnum
= process_reference (&p
);
1295 /* Defining symbols end in '=' */
1298 /* Symbol is being defined here. */
1304 /* Must be a reference. Either the symbol has already been defined,
1305 or this is a forward reference to it. */
1313 define_symbol (valu
, string
, desc
, type
, objfile
)
1318 struct objfile
*objfile
;
1320 register struct symbol
*sym
;
1321 char *p
= (char *) strchr (string
, ':');
1326 /* We would like to eliminate nameless symbols, but keep their types.
1327 E.g. stab entry ":t10=*2" should produce a type 10, which is a pointer
1328 to type 2, but, should not create a symbol to address that type. Since
1329 the symbol will be nameless, there is no way any user can refer to it. */
1333 /* Ignore syms with empty names. */
1337 /* Ignore old-style symbols from cc -go */
1344 p
= strchr (p
, ':');
1347 /* If a nameless stab entry, all we need is the type, not the symbol.
1348 e.g. ":t10=*2" or a nameless enum like " :T16=ered:0,green:1,blue:2,;" */
1349 nameless
= (p
== string
|| ((string
[0] == ' ') && (string
[1] == ':')));
1351 current_symbol
= sym
= (struct symbol
*)
1352 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct symbol
));
1353 memset (sym
, 0, sizeof (struct symbol
));
1355 switch (type
& N_TYPE
)
1358 SYMBOL_SECTION (sym
) = SECT_OFF_TEXT
;
1361 SYMBOL_SECTION (sym
) = SECT_OFF_DATA
;
1364 SYMBOL_SECTION (sym
) = SECT_OFF_BSS
;
1368 if (processing_gcc_compilation
)
1370 /* GCC 2.x puts the line number in desc. SunOS apparently puts in the
1371 number of bytes occupied by a type or object, which we ignore. */
1372 SYMBOL_LINE (sym
) = desc
;
1376 SYMBOL_LINE (sym
) = 0; /* unknown */
1379 if (is_cplus_marker (string
[0]))
1381 /* Special GNU C++ names. */
1385 SYMBOL_NAME (sym
) = obsavestring ("this", strlen ("this"),
1386 &objfile
->symbol_obstack
);
1389 case 'v': /* $vtbl_ptr_type */
1390 /* Was: SYMBOL_NAME (sym) = "vptr"; */
1394 SYMBOL_NAME (sym
) = obsavestring ("eh_throw", strlen ("eh_throw"),
1395 &objfile
->symbol_obstack
);
1399 /* This was an anonymous type that was never fixed up. */
1402 #ifdef STATIC_TRANSFORM_NAME
1404 /* SunPRO (3.0 at least) static variable encoding. */
1409 complain (&unrecognized_cplus_name_complaint
, string
);
1410 goto normal
; /* Do *something* with it */
1413 else if (string
[0] == '#')
1415 /* Special GNU C extension for referencing symbols. */
1419 /* If STRING defines a new reference id, then add it to the
1420 reference map. Else it must be referring to a previously
1421 defined symbol, so add it to the alias list of the previously
1424 refnum
= symbol_reference_defined (&s
);
1426 ref_add (refnum
, sym
, string
, SYMBOL_VALUE (sym
));
1427 else if (!resolve_symbol_reference (objfile
, sym
, string
))
1430 /* S..P contains the name of the symbol. We need to store
1431 the correct name into SYMBOL_NAME. */
1437 SYMBOL_NAME (sym
) = (char *)
1438 obstack_alloc (&objfile
->symbol_obstack
, nlen
);
1439 strncpy (SYMBOL_NAME (sym
), s
, nlen
);
1440 SYMBOL_NAME (sym
)[nlen
] = '\0';
1441 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
1444 /* FIXME! Want SYMBOL_NAME (sym) = 0;
1445 Get error if leave name 0. So give it something. */
1448 SYMBOL_NAME (sym
) = (char *)
1449 obstack_alloc (&objfile
->symbol_obstack
, nlen
);
1450 strncpy (SYMBOL_NAME (sym
), string
, nlen
);
1451 SYMBOL_NAME (sym
)[nlen
] = '\0';
1452 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
1455 /* Advance STRING beyond the reference id. */
1461 SYMBOL_LANGUAGE (sym
) = current_subfile
->language
;
1462 SYMBOL_NAME (sym
) = (char *)
1463 obstack_alloc (&objfile
->symbol_obstack
, ((p
- string
) + 1));
1464 /* Open-coded memcpy--saves function call time. */
1465 /* FIXME: Does it really? Try replacing with simple strcpy and
1466 try it on an executable with a large symbol table. */
1467 /* FIXME: considering that gcc can open code memcpy anyway, I
1468 doubt it. xoxorich. */
1470 register char *p1
= string
;
1471 register char *p2
= SYMBOL_NAME (sym
);
1479 /* If this symbol is from a C++ compilation, then attempt to cache the
1480 demangled form for future reference. This is a typical time versus
1481 space tradeoff, that was decided in favor of time because it sped up
1482 C++ symbol lookups by a factor of about 20. */
1484 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
1488 /* Determine the type of name being defined. */
1490 /* Getting GDB to correctly skip the symbol on an undefined symbol
1491 descriptor and not ever dump core is a very dodgy proposition if
1492 we do things this way. I say the acorn RISC machine can just
1493 fix their compiler. */
1494 /* The Acorn RISC machine's compiler can put out locals that don't
1495 start with "234=" or "(3,4)=", so assume anything other than the
1496 deftypes we know how to handle is a local. */
1497 if (!strchr ("cfFGpPrStTvVXCR", *p
))
1499 if (isdigit (*p
) || *p
== '(' || *p
== '-')
1508 /* c is a special case, not followed by a type-number.
1509 SYMBOL:c=iVALUE for an integer constant symbol.
1510 SYMBOL:c=rVALUE for a floating constant symbol.
1511 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
1512 e.g. "b:c=e6,0" for "const b = blob1"
1513 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
1516 SYMBOL_CLASS (sym
) = LOC_CONST
;
1517 SYMBOL_TYPE (sym
) = error_type (&p
, objfile
);
1518 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1519 add_symbol_to_list (sym
, &file_symbols
);
1527 double d
= atof (p
);
1530 /* FIXME-if-picky-about-floating-accuracy: Should be using
1531 target arithmetic to get the value. real.c in GCC
1532 probably has the necessary code. */
1534 /* FIXME: lookup_fundamental_type is a hack. We should be
1535 creating a type especially for the type of float constants.
1536 Problem is, what type should it be?
1538 Also, what should the name of this type be? Should we
1539 be using 'S' constants (see stabs.texinfo) instead? */
1541 SYMBOL_TYPE (sym
) = lookup_fundamental_type (objfile
,
1544 obstack_alloc (&objfile
->symbol_obstack
,
1545 TYPE_LENGTH (SYMBOL_TYPE (sym
)));
1546 store_floating (dbl_valu
, TYPE_LENGTH (SYMBOL_TYPE (sym
)), d
);
1547 SYMBOL_VALUE_BYTES (sym
) = dbl_valu
;
1548 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
1553 /* Defining integer constants this way is kind of silly,
1554 since 'e' constants allows the compiler to give not
1555 only the value, but the type as well. C has at least
1556 int, long, unsigned int, and long long as constant
1557 types; other languages probably should have at least
1558 unsigned as well as signed constants. */
1560 /* We just need one int constant type for all objfiles.
1561 It doesn't depend on languages or anything (arguably its
1562 name should be a language-specific name for a type of
1563 that size, but I'm inclined to say that if the compiler
1564 wants a nice name for the type, it can use 'e'). */
1565 static struct type
*int_const_type
;
1567 /* Yes, this is as long as a *host* int. That is because we
1569 if (int_const_type
== NULL
)
1571 init_type (TYPE_CODE_INT
,
1572 sizeof (int) * HOST_CHAR_BIT
/ TARGET_CHAR_BIT
, 0,
1574 (struct objfile
*) NULL
);
1575 SYMBOL_TYPE (sym
) = int_const_type
;
1576 SYMBOL_VALUE (sym
) = atoi (p
);
1577 SYMBOL_CLASS (sym
) = LOC_CONST
;
1581 /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value
1582 can be represented as integral.
1583 e.g. "b:c=e6,0" for "const b = blob1"
1584 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
1586 SYMBOL_CLASS (sym
) = LOC_CONST
;
1587 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1591 SYMBOL_TYPE (sym
) = error_type (&p
, objfile
);
1596 /* If the value is too big to fit in an int (perhaps because
1597 it is unsigned), or something like that, we silently get
1598 a bogus value. The type and everything else about it is
1599 correct. Ideally, we should be using whatever we have
1600 available for parsing unsigned and long long values,
1602 SYMBOL_VALUE (sym
) = atoi (p
);
1607 SYMBOL_CLASS (sym
) = LOC_CONST
;
1608 SYMBOL_TYPE (sym
) = error_type (&p
, objfile
);
1611 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1612 add_symbol_to_list (sym
, &file_symbols
);
1616 /* The name of a caught exception. */
1617 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1618 SYMBOL_CLASS (sym
) = LOC_LABEL
;
1619 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1620 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1621 add_symbol_to_list (sym
, &local_symbols
);
1625 /* A static function definition. */
1626 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1627 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1628 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1629 add_symbol_to_list (sym
, &file_symbols
);
1630 /* fall into process_function_types. */
1632 process_function_types
:
1633 /* Function result types are described as the result type in stabs.
1634 We need to convert this to the function-returning-type-X type
1635 in GDB. E.g. "int" is converted to "function returning int". */
1636 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_FUNC
)
1637 SYMBOL_TYPE (sym
) = lookup_function_type (SYMBOL_TYPE (sym
));
1639 /* All functions in C++ have prototypes. */
1640 if (SYMBOL_LANGUAGE (sym
) == language_cplus
)
1641 TYPE_FLAGS (SYMBOL_TYPE (sym
)) |= TYPE_FLAG_PROTOTYPED
;
1643 /* fall into process_prototype_types */
1645 process_prototype_types
:
1646 /* Sun acc puts declared types of arguments here. */
1649 struct type
*ftype
= SYMBOL_TYPE (sym
);
1654 /* Obtain a worst case guess for the number of arguments
1655 by counting the semicolons. */
1662 /* Allocate parameter information fields and fill them in. */
1663 TYPE_FIELDS (ftype
) = (struct field
*)
1664 TYPE_ALLOC (ftype
, nsemi
* sizeof (struct field
));
1669 /* A type number of zero indicates the start of varargs.
1670 FIXME: GDB currently ignores vararg functions. */
1671 if (p
[0] == '0' && p
[1] == '\0')
1673 ptype
= read_type (&p
, objfile
);
1675 /* The Sun compilers mark integer arguments, which should
1676 be promoted to the width of the calling conventions, with
1677 a type which references itself. This type is turned into
1678 a TYPE_CODE_VOID type by read_type, and we have to turn
1679 it back into builtin_type_int here.
1680 FIXME: Do we need a new builtin_type_promoted_int_arg ? */
1681 if (TYPE_CODE (ptype
) == TYPE_CODE_VOID
)
1682 ptype
= builtin_type_int
;
1683 TYPE_FIELD_TYPE (ftype
, nparams
++) = ptype
;
1685 TYPE_NFIELDS (ftype
) = nparams
;
1686 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
1691 /* A global function definition. */
1692 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1693 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1694 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1695 add_symbol_to_list (sym
, &global_symbols
);
1696 goto process_function_types
;
1699 /* For a class G (global) symbol, it appears that the
1700 value is not correct. It is necessary to search for the
1701 corresponding linker definition to find the value.
1702 These definitions appear at the end of the namelist. */
1703 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1704 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1705 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1706 /* Don't add symbol references to global_sym_chain.
1707 Symbol references don't have valid names and wont't match up with
1708 minimal symbols when the global_sym_chain is relocated.
1709 We'll fixup symbol references when we fixup the defining symbol. */
1710 if (SYMBOL_NAME (sym
) && SYMBOL_NAME (sym
)[0] != '#')
1712 i
= hashname (SYMBOL_NAME (sym
));
1713 SYMBOL_VALUE_CHAIN (sym
) = global_sym_chain
[i
];
1714 global_sym_chain
[i
] = sym
;
1716 add_symbol_to_list (sym
, &global_symbols
);
1719 /* This case is faked by a conditional above,
1720 when there is no code letter in the dbx data.
1721 Dbx data never actually contains 'l'. */
1724 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1725 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1726 SYMBOL_VALUE (sym
) = valu
;
1727 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1728 add_symbol_to_list (sym
, &local_symbols
);
1733 /* pF is a two-letter code that means a function parameter in Fortran.
1734 The type-number specifies the type of the return value.
1735 Translate it into a pointer-to-function type. */
1739 = lookup_pointer_type
1740 (lookup_function_type (read_type (&p
, objfile
)));
1743 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1745 /* Normally this is a parameter, a LOC_ARG. On the i960, it
1746 can also be a LOC_LOCAL_ARG depending on symbol type. */
1747 #ifndef DBX_PARM_SYMBOL_CLASS
1748 #define DBX_PARM_SYMBOL_CLASS(type) LOC_ARG
1751 SYMBOL_CLASS (sym
) = DBX_PARM_SYMBOL_CLASS (type
);
1752 SYMBOL_VALUE (sym
) = valu
;
1753 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1754 add_symbol_to_list (sym
, &local_symbols
);
1756 if (TARGET_BYTE_ORDER
!= BIG_ENDIAN
)
1758 /* On little-endian machines, this crud is never necessary,
1759 and, if the extra bytes contain garbage, is harmful. */
1763 /* If it's gcc-compiled, if it says `short', believe it. */
1764 if (processing_gcc_compilation
|| BELIEVE_PCC_PROMOTION
)
1767 if (!BELIEVE_PCC_PROMOTION
)
1769 /* This is the signed type which arguments get promoted to. */
1770 static struct type
*pcc_promotion_type
;
1771 /* This is the unsigned type which arguments get promoted to. */
1772 static struct type
*pcc_unsigned_promotion_type
;
1774 /* Call it "int" because this is mainly C lossage. */
1775 if (pcc_promotion_type
== NULL
)
1776 pcc_promotion_type
=
1777 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
1780 if (pcc_unsigned_promotion_type
== NULL
)
1781 pcc_unsigned_promotion_type
=
1782 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
1783 TYPE_FLAG_UNSIGNED
, "unsigned int", NULL
);
1785 if (BELIEVE_PCC_PROMOTION_TYPE
)
1787 /* This is defined on machines (e.g. sparc) where we
1788 should believe the type of a PCC 'short' argument,
1789 but shouldn't believe the address (the address is the
1790 address of the corresponding int).
1792 My guess is that this correction, as opposed to
1793 changing the parameter to an 'int' (as done below,
1794 for PCC on most machines), is the right thing to do
1795 on all machines, but I don't want to risk breaking
1796 something that already works. On most PCC machines,
1797 the sparc problem doesn't come up because the calling
1798 function has to zero the top bytes (not knowing
1799 whether the called function wants an int or a short),
1800 so there is little practical difference between an
1801 int and a short (except perhaps what happens when the
1802 GDB user types "print short_arg = 0x10000;").
1804 Hacked for SunOS 4.1 by gnu@cygnus.com. In 4.1, the
1805 compiler actually produces the correct address (we
1806 don't need to fix it up). I made this code adapt so
1807 that it will offset the symbol if it was pointing at
1808 an int-aligned location and not otherwise. This way
1809 you can use the same gdb for 4.0.x and 4.1 systems.
1811 If the parameter is shorter than an int, and is
1812 integral (e.g. char, short, or unsigned equivalent),
1813 and is claimed to be passed on an integer boundary,
1814 don't believe it! Offset the parameter's address to
1815 the tail-end of that integer. */
1817 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (pcc_promotion_type
)
1818 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
1819 && 0 == SYMBOL_VALUE (sym
) % TYPE_LENGTH (pcc_promotion_type
))
1821 SYMBOL_VALUE (sym
) += TYPE_LENGTH (pcc_promotion_type
)
1822 - TYPE_LENGTH (SYMBOL_TYPE (sym
));
1828 /* If PCC says a parameter is a short or a char,
1829 it is really an int. */
1830 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (pcc_promotion_type
)
1831 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
)
1834 TYPE_UNSIGNED (SYMBOL_TYPE (sym
))
1835 ? pcc_unsigned_promotion_type
1836 : pcc_promotion_type
;
1843 /* acc seems to use P to declare the prototypes of functions that
1844 are referenced by this file. gdb is not prepared to deal
1845 with this extra information. FIXME, it ought to. */
1848 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1849 goto process_prototype_types
;
1854 /* Parameter which is in a register. */
1855 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1856 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
1857 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
1858 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
1860 complain (®_value_complaint
, SYMBOL_VALUE (sym
), NUM_REGS
,
1861 SYMBOL_SOURCE_NAME (sym
));
1862 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
1864 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1865 add_symbol_to_list (sym
, &local_symbols
);
1869 /* Register variable (either global or local). */
1870 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1871 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
1872 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
1873 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
1875 complain (®_value_complaint
, SYMBOL_VALUE (sym
), NUM_REGS
,
1876 SYMBOL_SOURCE_NAME (sym
));
1877 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
1879 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1880 if (within_function
)
1882 /* Sun cc uses a pair of symbols, one 'p' and one 'r' with the same
1883 name to represent an argument passed in a register.
1884 GCC uses 'P' for the same case. So if we find such a symbol pair
1885 we combine it into one 'P' symbol. For Sun cc we need to do this
1886 regardless of REG_STRUCT_HAS_ADDR, because the compiler puts out
1887 the 'p' symbol even if it never saves the argument onto the stack.
1889 On most machines, we want to preserve both symbols, so that
1890 we can still get information about what is going on with the
1891 stack (VAX for computing args_printed, using stack slots instead
1892 of saved registers in backtraces, etc.).
1894 Note that this code illegally combines
1895 main(argc) struct foo argc; { register struct foo argc; }
1896 but this case is considered pathological and causes a warning
1897 from a decent compiler. */
1900 && local_symbols
->nsyms
> 0
1901 #ifndef USE_REGISTER_NOT_ARG
1902 && REG_STRUCT_HAS_ADDR (processing_gcc_compilation
,
1904 && (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
1905 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
1906 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_SET
1907 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_BITSTRING
)
1911 struct symbol
*prev_sym
;
1912 prev_sym
= local_symbols
->symbol
[local_symbols
->nsyms
- 1];
1913 if ((SYMBOL_CLASS (prev_sym
) == LOC_REF_ARG
1914 || SYMBOL_CLASS (prev_sym
) == LOC_ARG
)
1915 && STREQ (SYMBOL_NAME (prev_sym
), SYMBOL_NAME (sym
)))
1917 SYMBOL_CLASS (prev_sym
) = LOC_REGPARM
;
1918 /* Use the type from the LOC_REGISTER; that is the type
1919 that is actually in that register. */
1920 SYMBOL_TYPE (prev_sym
) = SYMBOL_TYPE (sym
);
1921 SYMBOL_VALUE (prev_sym
) = SYMBOL_VALUE (sym
);
1926 add_symbol_to_list (sym
, &local_symbols
);
1929 add_symbol_to_list (sym
, &file_symbols
);
1933 /* Static symbol at top level of file */
1934 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1935 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1936 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1937 #ifdef STATIC_TRANSFORM_NAME
1938 if (IS_STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym
)))
1940 struct minimal_symbol
*msym
;
1941 msym
= lookup_minimal_symbol (SYMBOL_NAME (sym
), NULL
, objfile
);
1944 SYMBOL_NAME (sym
) = STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym
));
1945 SYMBOL_VALUE_ADDRESS (sym
) = SYMBOL_VALUE_ADDRESS (msym
);
1949 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1950 add_symbol_to_list (sym
, &file_symbols
);
1954 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1956 /* For a nameless type, we don't want a create a symbol, thus we
1957 did not use `sym'. Return without further processing. */
1961 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1962 SYMBOL_VALUE (sym
) = valu
;
1963 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1964 /* C++ vagaries: we may have a type which is derived from
1965 a base type which did not have its name defined when the
1966 derived class was output. We fill in the derived class's
1967 base part member's name here in that case. */
1968 if (TYPE_NAME (SYMBOL_TYPE (sym
)) != NULL
)
1969 if ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
1970 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
)
1971 && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)))
1974 for (j
= TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)) - 1; j
>= 0; j
--)
1975 if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) == 0)
1976 TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) =
1977 type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym
), j
));
1980 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == NULL
)
1982 /* gcc-2.6 or later (when using -fvtable-thunks)
1983 emits a unique named type for a vtable entry.
1984 Some gdb code depends on that specific name. */
1985 extern const char vtbl_ptr_name
[];
1987 if ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_PTR
1988 && strcmp (SYMBOL_NAME (sym
), vtbl_ptr_name
))
1989 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_FUNC
)
1991 /* If we are giving a name to a type such as "pointer to
1992 foo" or "function returning foo", we better not set
1993 the TYPE_NAME. If the program contains "typedef char
1994 *caddr_t;", we don't want all variables of type char
1995 * to print as caddr_t. This is not just a
1996 consequence of GDB's type management; PCC and GCC (at
1997 least through version 2.4) both output variables of
1998 either type char * or caddr_t with the type number
1999 defined in the 't' symbol for caddr_t. If a future
2000 compiler cleans this up it GDB is not ready for it
2001 yet, but if it becomes ready we somehow need to
2002 disable this check (without breaking the PCC/GCC2.4
2007 Fortunately, this check seems not to be necessary
2008 for anything except pointers or functions. */
2011 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_NAME (sym
);
2014 add_symbol_to_list (sym
, &file_symbols
);
2018 /* Struct, union, or enum tag. For GNU C++, this can be be followed
2019 by 't' which means we are typedef'ing it as well. */
2020 synonym
= *p
== 't';
2024 /* The semantics of C++ state that "struct foo { ... }" also defines
2025 a typedef for "foo". Unfortunately, cfront never makes the typedef
2026 when translating C++ into C. We make the typedef here so that
2027 "ptype foo" works as expected for cfront translated code. */
2028 else if (current_subfile
->language
== language_cplus
)
2031 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
2033 /* For a nameless type, we don't want a create a symbol, thus we
2034 did not use `sym'. Return without further processing. */
2038 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
2039 SYMBOL_VALUE (sym
) = valu
;
2040 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
2041 if (TYPE_TAG_NAME (SYMBOL_TYPE (sym
)) == 0)
2042 TYPE_TAG_NAME (SYMBOL_TYPE (sym
))
2043 = obconcat (&objfile
->type_obstack
, "", "", SYMBOL_NAME (sym
));
2044 add_symbol_to_list (sym
, &file_symbols
);
2048 /* Clone the sym and then modify it. */
2049 register struct symbol
*typedef_sym
= (struct symbol
*)
2050 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct symbol
));
2051 *typedef_sym
= *sym
;
2052 SYMBOL_CLASS (typedef_sym
) = LOC_TYPEDEF
;
2053 SYMBOL_VALUE (typedef_sym
) = valu
;
2054 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
2055 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
2056 TYPE_NAME (SYMBOL_TYPE (sym
))
2057 = obconcat (&objfile
->type_obstack
, "", "", SYMBOL_NAME (sym
));
2058 add_symbol_to_list (typedef_sym
, &file_symbols
);
2063 /* Static symbol of local scope */
2064 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
2065 SYMBOL_CLASS (sym
) = LOC_STATIC
;
2066 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
2067 #ifdef STATIC_TRANSFORM_NAME
2068 if (IS_STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym
)))
2070 struct minimal_symbol
*msym
;
2071 msym
= lookup_minimal_symbol (SYMBOL_NAME (sym
), NULL
, objfile
);
2074 SYMBOL_NAME (sym
) = STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym
));
2075 SYMBOL_VALUE_ADDRESS (sym
) = SYMBOL_VALUE_ADDRESS (msym
);
2079 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2081 add_symbol_to_list (sym
, &global_symbols
);
2083 add_symbol_to_list (sym
, &local_symbols
);
2087 /* Reference parameter */
2088 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
2089 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
2090 SYMBOL_VALUE (sym
) = valu
;
2091 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2092 add_symbol_to_list (sym
, &local_symbols
);
2096 /* Reference parameter which is in a register. */
2097 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
2098 SYMBOL_CLASS (sym
) = LOC_REGPARM_ADDR
;
2099 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
2100 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
2102 complain (®_value_complaint
, SYMBOL_VALUE (sym
), NUM_REGS
,
2103 SYMBOL_SOURCE_NAME (sym
));
2104 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
2106 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2107 add_symbol_to_list (sym
, &local_symbols
);
2111 /* This is used by Sun FORTRAN for "function result value".
2112 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
2113 that Pascal uses it too, but when I tried it Pascal used
2114 "x:3" (local symbol) instead. */
2115 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
2116 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
2117 SYMBOL_VALUE (sym
) = valu
;
2118 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2119 add_symbol_to_list (sym
, &local_symbols
);
2122 /* New code added to support cfront stabs strings.
2123 Note: case 'P' already handled above */
2125 /* Cfront type continuation coming up!
2126 Find the original definition and add to it.
2127 We'll have to do this for the typedef too,
2128 since we cloned the symbol to define a type in read_type.
2129 Stabs info examples:
2131 foo__1CFv :ZtF (first def foo__1CFv:F(0,3);(0,24))
2132 C:ZsC;;__ct__1CFv func1__1CFv func2__1CFv ... ;;;
2133 where C is the name of the class.
2134 Unfortunately, we can't lookup the original symbol yet 'cuz
2135 we haven't finished reading all the symbols.
2136 Instead, we save it for processing later */
2137 process_later (sym
, p
, resolve_cfront_continuation
);
2138 SYMBOL_TYPE (sym
) = error_type (&p
, objfile
); /* FIXME! change later */
2139 SYMBOL_CLASS (sym
) = LOC_CONST
;
2140 SYMBOL_VALUE (sym
) = 0;
2141 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2142 /* Don't add to list - we'll delete it later when
2143 we add the continuation to the real sym */
2145 /* End of new code added to support cfront stabs strings */
2148 SYMBOL_TYPE (sym
) = error_type (&p
, objfile
);
2149 SYMBOL_CLASS (sym
) = LOC_CONST
;
2150 SYMBOL_VALUE (sym
) = 0;
2151 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2152 add_symbol_to_list (sym
, &file_symbols
);
2156 /* When passing structures to a function, some systems sometimes pass
2157 the address in a register, not the structure itself. */
2159 if (REG_STRUCT_HAS_ADDR (processing_gcc_compilation
, SYMBOL_TYPE (sym
))
2160 && (SYMBOL_CLASS (sym
) == LOC_REGPARM
|| SYMBOL_CLASS (sym
) == LOC_ARG
))
2162 struct type
*symbol_type
= check_typedef (SYMBOL_TYPE (sym
));
2164 if ((TYPE_CODE (symbol_type
) == TYPE_CODE_STRUCT
)
2165 || (TYPE_CODE (symbol_type
) == TYPE_CODE_UNION
)
2166 || (TYPE_CODE (symbol_type
) == TYPE_CODE_BITSTRING
)
2167 || (TYPE_CODE (symbol_type
) == TYPE_CODE_SET
))
2169 /* If REG_STRUCT_HAS_ADDR yields non-zero we have to convert
2170 LOC_REGPARM to LOC_REGPARM_ADDR for structures and unions. */
2171 if (SYMBOL_CLASS (sym
) == LOC_REGPARM
)
2172 SYMBOL_CLASS (sym
) = LOC_REGPARM_ADDR
;
2173 /* Likewise for converting LOC_ARG to LOC_REF_ARG (for the 7th
2174 and subsequent arguments on the sparc, for example). */
2175 else if (SYMBOL_CLASS (sym
) == LOC_ARG
)
2176 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
2180 /* Is there more to parse? For example LRS/alias information? */
2181 while (*p
&& *p
== ';')
2184 if (*p
&& p
[0] == 'l' && p
[1] == '(')
2186 /* GNU extensions for live range splitting may be appended to
2187 the end of the stab string. eg. "l(#1,#2);l(#3,#5)" */
2189 /* Resolve the live range and add it to SYM's live range list. */
2190 if (!resolve_live_range (objfile
, sym
, p
))
2193 /* Find end of live range info. */
2194 p
= strchr (p
, ')');
2195 if (!*p
|| *p
!= ')')
2197 complain (&lrs_general_complaint
, "live range format not recognized");
2206 /* Add the live range found in P to the symbol SYM in objfile OBJFILE. Returns
2207 non-zero on success, zero otherwise. */
2210 resolve_live_range (objfile
, sym
, p
)
2211 struct objfile
*objfile
;
2216 CORE_ADDR start
, end
;
2218 /* Sanity check the beginning of the stabs string. */
2219 if (!*p
|| *p
!= 'l')
2221 complain (&lrs_general_complaint
, "live range string 1");
2226 if (!*p
|| *p
!= '(')
2228 complain (&lrs_general_complaint
, "live range string 2");
2233 /* Get starting value of range and advance P past the reference id.
2235 ?!? In theory, the process_reference should never fail, but we should
2236 catch that case just in case the compiler scrogged the stabs. */
2237 refnum
= process_reference (&p
);
2238 start
= ref_search_value (refnum
);
2241 complain (&lrs_general_complaint
, "Live range symbol not found 1");
2245 if (!*p
|| *p
!= ',')
2247 complain (&lrs_general_complaint
, "live range string 3");
2252 /* Get ending value of range and advance P past the reference id.
2254 ?!? In theory, the process_reference should never fail, but we should
2255 catch that case just in case the compiler scrogged the stabs. */
2256 refnum
= process_reference (&p
);
2257 end
= ref_search_value (refnum
);
2260 complain (&lrs_general_complaint
, "Live range symbol not found 2");
2264 if (!*p
|| *p
!= ')')
2266 complain (&lrs_general_complaint
, "live range string 4");
2270 /* Now that we know the bounds of the range, add it to the
2272 add_live_range (objfile
, sym
, start
, end
);
2277 /* Add a new live range defined by START and END to the symbol SYM
2278 in objfile OBJFILE. */
2281 add_live_range (objfile
, sym
, start
, end
)
2282 struct objfile
*objfile
;
2284 CORE_ADDR start
, end
;
2286 struct range_list
*r
, *rs
;
2290 complain (&lrs_general_complaint
, "end of live range follows start");
2294 /* Alloc new live range structure. */
2295 r
= (struct range_list
*)
2296 obstack_alloc (&objfile
->type_obstack
,
2297 sizeof (struct range_list
));
2302 /* Append this range to the symbol's range list. */
2303 if (!SYMBOL_RANGES (sym
))
2304 SYMBOL_RANGES (sym
) = r
;
2307 /* Get the last range for the symbol. */
2308 for (rs
= SYMBOL_RANGES (sym
); rs
->next
; rs
= rs
->next
)
2315 /* Skip rest of this symbol and return an error type.
2317 General notes on error recovery: error_type always skips to the
2318 end of the symbol (modulo cretinous dbx symbol name continuation).
2319 Thus code like this:
2321 if (*(*pp)++ != ';')
2322 return error_type (pp, objfile);
2324 is wrong because if *pp starts out pointing at '\0' (typically as the
2325 result of an earlier error), it will be incremented to point to the
2326 start of the next symbol, which might produce strange results, at least
2327 if you run off the end of the string table. Instead use
2330 return error_type (pp, objfile);
2336 foo = error_type (pp, objfile);
2340 And in case it isn't obvious, the point of all this hair is so the compiler
2341 can define new types and new syntaxes, and old versions of the
2342 debugger will be able to read the new symbol tables. */
2344 static struct type
*
2345 error_type (pp
, objfile
)
2347 struct objfile
*objfile
;
2349 complain (&error_type_complaint
);
2352 /* Skip to end of symbol. */
2353 while (**pp
!= '\0')
2358 /* Check for and handle cretinous dbx symbol name continuation! */
2359 if ((*pp
)[-1] == '\\' || (*pp
)[-1] == '?')
2361 *pp
= next_symbol_text (objfile
);
2368 return (builtin_type_error
);
2372 /* Read type information or a type definition; return the type. Even
2373 though this routine accepts either type information or a type
2374 definition, the distinction is relevant--some parts of stabsread.c
2375 assume that type information starts with a digit, '-', or '(' in
2376 deciding whether to call read_type. */
2379 read_type (pp
, objfile
)
2381 struct objfile
*objfile
;
2383 register struct type
*type
= 0;
2386 char type_descriptor
;
2388 /* Size in bits of type if specified by a type attribute, or -1 if
2389 there is no size attribute. */
2392 /* Used to distinguish string and bitstring from char-array and set. */
2395 /* Read type number if present. The type number may be omitted.
2396 for instance in a two-dimensional array declared with type
2397 "ar1;1;10;ar1;1;10;4". */
2398 if ((**pp
>= '0' && **pp
<= '9')
2402 if (read_type_number (pp
, typenums
) != 0)
2403 return error_type (pp
, objfile
);
2405 /* Type is not being defined here. Either it already exists,
2406 or this is a forward reference to it. dbx_alloc_type handles
2409 return dbx_alloc_type (typenums
, objfile
);
2411 /* Type is being defined here. */
2413 Also skip the type descriptor - we get it below with (*pp)[-1]. */
2418 /* 'typenums=' not present, type is anonymous. Read and return
2419 the definition, but don't put it in the type vector. */
2420 typenums
[0] = typenums
[1] = -1;
2425 type_descriptor
= (*pp
)[-1];
2426 switch (type_descriptor
)
2430 enum type_code code
;
2432 /* Used to index through file_symbols. */
2433 struct pending
*ppt
;
2436 /* Name including "struct", etc. */
2440 char *from
, *to
, *p
, *q1
, *q2
;
2442 /* Set the type code according to the following letter. */
2446 code
= TYPE_CODE_STRUCT
;
2449 code
= TYPE_CODE_UNION
;
2452 code
= TYPE_CODE_ENUM
;
2456 /* Complain and keep going, so compilers can invent new
2457 cross-reference types. */
2458 static struct complaint msg
=
2459 {"Unrecognized cross-reference type `%c'", 0, 0};
2460 complain (&msg
, (*pp
)[0]);
2461 code
= TYPE_CODE_STRUCT
;
2466 q1
= strchr (*pp
, '<');
2467 p
= strchr (*pp
, ':');
2469 return error_type (pp
, objfile
);
2470 if (q1
&& p
> q1
&& p
[1] == ':')
2472 int nesting_level
= 0;
2473 for (q2
= q1
; *q2
; q2
++)
2477 else if (*q2
== '>')
2479 else if (*q2
== ':' && nesting_level
== 0)
2484 return error_type (pp
, objfile
);
2487 (char *) obstack_alloc (&objfile
->type_obstack
, p
- *pp
+ 1);
2489 /* Copy the name. */
2495 /* Set the pointer ahead of the name which we just read, and
2500 /* Now check to see whether the type has already been
2501 declared. This was written for arrays of cross-referenced
2502 types before we had TYPE_CODE_TARGET_STUBBED, so I'm pretty
2503 sure it is not necessary anymore. But it might be a good
2504 idea, to save a little memory. */
2506 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
2507 for (i
= 0; i
< ppt
->nsyms
; i
++)
2509 struct symbol
*sym
= ppt
->symbol
[i
];
2511 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
2512 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
2513 && (TYPE_CODE (SYMBOL_TYPE (sym
)) == code
)
2514 && STREQ (SYMBOL_NAME (sym
), type_name
))
2516 obstack_free (&objfile
->type_obstack
, type_name
);
2517 type
= SYMBOL_TYPE (sym
);
2522 /* Didn't find the type to which this refers, so we must
2523 be dealing with a forward reference. Allocate a type
2524 structure for it, and keep track of it so we can
2525 fill in the rest of the fields when we get the full
2527 type
= dbx_alloc_type (typenums
, objfile
);
2528 TYPE_CODE (type
) = code
;
2529 TYPE_TAG_NAME (type
) = type_name
;
2530 INIT_CPLUS_SPECIFIC (type
);
2531 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
2533 add_undefined_type (type
);
2537 case '-': /* RS/6000 built-in type */
2551 /* We deal with something like t(1,2)=(3,4)=... which
2552 the Lucid compiler and recent gcc versions (post 2.7.3) use. */
2554 /* Allocate and enter the typedef type first.
2555 This handles recursive types. */
2556 type
= dbx_alloc_type (typenums
, objfile
);
2557 TYPE_CODE (type
) = TYPE_CODE_TYPEDEF
;
2559 struct type
*xtype
= read_type (pp
, objfile
);
2562 /* It's being defined as itself. That means it is "void". */
2563 TYPE_CODE (type
) = TYPE_CODE_VOID
;
2564 TYPE_LENGTH (type
) = 1;
2566 else if (type_size
>= 0 || is_string
)
2569 TYPE_NAME (type
) = NULL
;
2570 TYPE_TAG_NAME (type
) = NULL
;
2574 TYPE_FLAGS (type
) |= TYPE_FLAG_TARGET_STUB
;
2575 TYPE_TARGET_TYPE (type
) = xtype
;
2580 /* In the following types, we must be sure to overwrite any existing
2581 type that the typenums refer to, rather than allocating a new one
2582 and making the typenums point to the new one. This is because there
2583 may already be pointers to the existing type (if it had been
2584 forward-referenced), and we must change it to a pointer, function,
2585 reference, or whatever, *in-place*. */
2588 type1
= read_type (pp
, objfile
);
2589 type
= make_pointer_type (type1
, dbx_lookup_type (typenums
));
2592 case '&': /* Reference to another type */
2593 type1
= read_type (pp
, objfile
);
2594 type
= make_reference_type (type1
, dbx_lookup_type (typenums
));
2597 case 'f': /* Function returning another type */
2598 if (os9k_stabs
&& **pp
== '(')
2600 /* Function prototype; parse it.
2601 We must conditionalize this on os9k_stabs because otherwise
2602 it could be confused with a Sun-style (1,3) typenumber
2608 t
= read_type (pp
, objfile
);
2613 type1
= read_type (pp
, objfile
);
2614 type
= make_function_type (type1
, dbx_lookup_type (typenums
));
2617 case 'k': /* Const qualifier on some type (Sun) */
2618 case 'c': /* Const qualifier on some type (OS9000) */
2619 /* Because 'c' means other things to AIX and 'k' is perfectly good,
2620 only accept 'c' in the os9k_stabs case. */
2621 if (type_descriptor
== 'c' && !os9k_stabs
)
2622 return error_type (pp
, objfile
);
2623 type
= read_type (pp
, objfile
);
2624 /* FIXME! For now, we ignore const and volatile qualifiers. */
2627 case 'B': /* Volatile qual on some type (Sun) */
2628 case 'i': /* Volatile qual on some type (OS9000) */
2629 /* Because 'i' means other things to AIX and 'B' is perfectly good,
2630 only accept 'i' in the os9k_stabs case. */
2631 if (type_descriptor
== 'i' && !os9k_stabs
)
2632 return error_type (pp
, objfile
);
2633 type
= read_type (pp
, objfile
);
2634 /* FIXME! For now, we ignore const and volatile qualifiers. */
2638 if (isdigit (**pp
) || **pp
== '(' || **pp
== '-')
2639 { /* Member (class & variable) type */
2640 /* FIXME -- we should be doing smash_to_XXX types here. */
2642 struct type
*domain
= read_type (pp
, objfile
);
2643 struct type
*memtype
;
2646 /* Invalid member type data format. */
2647 return error_type (pp
, objfile
);
2650 memtype
= read_type (pp
, objfile
);
2651 type
= dbx_alloc_type (typenums
, objfile
);
2652 smash_to_member_type (type
, domain
, memtype
);
2655 /* type attribute */
2658 /* Skip to the semicolon. */
2659 while (**pp
!= ';' && **pp
!= '\0')
2662 return error_type (pp
, objfile
);
2664 ++ * pp
; /* Skip the semicolon. */
2669 type_size
= atoi (attr
+ 1);
2679 /* Ignore unrecognized type attributes, so future compilers
2680 can invent new ones. */
2688 case '#': /* Method (class & fn) type */
2689 if ((*pp
)[0] == '#')
2691 /* We'll get the parameter types from the name. */
2692 struct type
*return_type
;
2695 return_type
= read_type (pp
, objfile
);
2696 if (*(*pp
)++ != ';')
2697 complain (&invalid_member_complaint
, symnum
);
2698 type
= allocate_stub_method (return_type
);
2699 if (typenums
[0] != -1)
2700 *dbx_lookup_type (typenums
) = type
;
2704 struct type
*domain
= read_type (pp
, objfile
);
2705 struct type
*return_type
;
2709 /* Invalid member type data format. */
2710 return error_type (pp
, objfile
);
2714 return_type
= read_type (pp
, objfile
);
2715 args
= read_args (pp
, ';', objfile
);
2716 type
= dbx_alloc_type (typenums
, objfile
);
2717 smash_to_method_type (type
, domain
, return_type
, args
);
2721 case 'r': /* Range type */
2722 type
= read_range_type (pp
, typenums
, objfile
);
2723 if (typenums
[0] != -1)
2724 *dbx_lookup_type (typenums
) = type
;
2729 /* Const and volatile qualified type. */
2730 type
= read_type (pp
, objfile
);
2733 /* Sun ACC builtin int type */
2734 type
= read_sun_builtin_type (pp
, typenums
, objfile
);
2735 if (typenums
[0] != -1)
2736 *dbx_lookup_type (typenums
) = type
;
2740 case 'R': /* Sun ACC builtin float type */
2741 type
= read_sun_floating_type (pp
, typenums
, objfile
);
2742 if (typenums
[0] != -1)
2743 *dbx_lookup_type (typenums
) = type
;
2746 case 'e': /* Enumeration type */
2747 type
= dbx_alloc_type (typenums
, objfile
);
2748 type
= read_enum_type (pp
, type
, objfile
);
2749 if (typenums
[0] != -1)
2750 *dbx_lookup_type (typenums
) = type
;
2753 case 's': /* Struct type */
2754 case 'u': /* Union type */
2755 type
= dbx_alloc_type (typenums
, objfile
);
2756 switch (type_descriptor
)
2759 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
2762 TYPE_CODE (type
) = TYPE_CODE_UNION
;
2765 type
= read_struct_type (pp
, type
, objfile
);
2768 case 'a': /* Array type */
2770 return error_type (pp
, objfile
);
2773 type
= dbx_alloc_type (typenums
, objfile
);
2774 type
= read_array_type (pp
, type
, objfile
);
2776 TYPE_CODE (type
) = TYPE_CODE_STRING
;
2780 type1
= read_type (pp
, objfile
);
2781 type
= create_set_type ((struct type
*) NULL
, type1
);
2783 TYPE_CODE (type
) = TYPE_CODE_BITSTRING
;
2784 if (typenums
[0] != -1)
2785 *dbx_lookup_type (typenums
) = type
;
2789 --*pp
; /* Go back to the symbol in error */
2790 /* Particularly important if it was \0! */
2791 return error_type (pp
, objfile
);
2796 warning ("GDB internal error, type is NULL in stabsread.c\n");
2797 return error_type (pp
, objfile
);
2800 /* Size specified in a type attribute overrides any other size. */
2801 if (type_size
!= -1)
2802 TYPE_LENGTH (type
) = (type_size
+ TARGET_CHAR_BIT
- 1) / TARGET_CHAR_BIT
;
2807 /* RS/6000 xlc/dbx combination uses a set of builtin types, starting from -1.
2808 Return the proper type node for a given builtin type number. */
2810 static struct type
*
2811 rs6000_builtin_type (typenum
)
2814 /* We recognize types numbered from -NUMBER_RECOGNIZED to -1. */
2815 #define NUMBER_RECOGNIZED 34
2816 /* This includes an empty slot for type number -0. */
2817 static struct type
*negative_types
[NUMBER_RECOGNIZED
+ 1];
2818 struct type
*rettype
= NULL
;
2820 if (typenum
>= 0 || typenum
< -NUMBER_RECOGNIZED
)
2822 complain (&rs6000_builtin_complaint
, typenum
);
2823 return builtin_type_error
;
2825 if (negative_types
[-typenum
] != NULL
)
2826 return negative_types
[-typenum
];
2828 #if TARGET_CHAR_BIT != 8
2829 #error This code wrong for TARGET_CHAR_BIT not 8
2830 /* These definitions all assume that TARGET_CHAR_BIT is 8. I think
2831 that if that ever becomes not true, the correct fix will be to
2832 make the size in the struct type to be in bits, not in units of
2839 /* The size of this and all the other types are fixed, defined
2840 by the debugging format. If there is a type called "int" which
2841 is other than 32 bits, then it should use a new negative type
2842 number (or avoid negative type numbers for that case).
2843 See stabs.texinfo. */
2844 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "int", NULL
);
2847 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "char", NULL
);
2850 rettype
= init_type (TYPE_CODE_INT
, 2, 0, "short", NULL
);
2853 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "long", NULL
);
2856 rettype
= init_type (TYPE_CODE_INT
, 1, TYPE_FLAG_UNSIGNED
,
2857 "unsigned char", NULL
);
2860 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "signed char", NULL
);
2863 rettype
= init_type (TYPE_CODE_INT
, 2, TYPE_FLAG_UNSIGNED
,
2864 "unsigned short", NULL
);
2867 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
2868 "unsigned int", NULL
);
2871 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
2874 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
2875 "unsigned long", NULL
);
2878 rettype
= init_type (TYPE_CODE_VOID
, 1, 0, "void", NULL
);
2881 /* IEEE single precision (32 bit). */
2882 rettype
= init_type (TYPE_CODE_FLT
, 4, 0, "float", NULL
);
2885 /* IEEE double precision (64 bit). */
2886 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "double", NULL
);
2889 /* This is an IEEE double on the RS/6000, and different machines with
2890 different sizes for "long double" should use different negative
2891 type numbers. See stabs.texinfo. */
2892 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "long double", NULL
);
2895 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "integer", NULL
);
2898 rettype
= init_type (TYPE_CODE_BOOL
, 4, TYPE_FLAG_UNSIGNED
,
2902 rettype
= init_type (TYPE_CODE_FLT
, 4, 0, "short real", NULL
);
2905 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "real", NULL
);
2908 rettype
= init_type (TYPE_CODE_ERROR
, 0, 0, "stringptr", NULL
);
2911 rettype
= init_type (TYPE_CODE_CHAR
, 1, TYPE_FLAG_UNSIGNED
,
2915 rettype
= init_type (TYPE_CODE_BOOL
, 1, TYPE_FLAG_UNSIGNED
,
2919 rettype
= init_type (TYPE_CODE_BOOL
, 2, TYPE_FLAG_UNSIGNED
,
2923 rettype
= init_type (TYPE_CODE_BOOL
, 4, TYPE_FLAG_UNSIGNED
,
2927 rettype
= init_type (TYPE_CODE_BOOL
, 4, TYPE_FLAG_UNSIGNED
,
2931 /* Complex type consisting of two IEEE single precision values. */
2932 rettype
= init_type (TYPE_CODE_COMPLEX
, 8, 0, "complex", NULL
);
2935 /* Complex type consisting of two IEEE double precision values. */
2936 rettype
= init_type (TYPE_CODE_COMPLEX
, 16, 0, "double complex", NULL
);
2939 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "integer*1", NULL
);
2942 rettype
= init_type (TYPE_CODE_INT
, 2, 0, "integer*2", NULL
);
2945 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "integer*4", NULL
);
2948 rettype
= init_type (TYPE_CODE_CHAR
, 2, 0, "wchar", NULL
);
2951 rettype
= init_type (TYPE_CODE_INT
, 8, 0, "long long", NULL
);
2954 rettype
= init_type (TYPE_CODE_INT
, 8, TYPE_FLAG_UNSIGNED
,
2955 "unsigned long long", NULL
);
2958 rettype
= init_type (TYPE_CODE_INT
, 8, TYPE_FLAG_UNSIGNED
,
2962 rettype
= init_type (TYPE_CODE_INT
, 8, 0, "integer*8", NULL
);
2965 negative_types
[-typenum
] = rettype
;
2969 /* This page contains subroutines of read_type. */
2971 /* Read member function stabs info for C++ classes. The form of each member
2974 NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
2976 An example with two member functions is:
2978 afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
2980 For the case of overloaded operators, the format is op$::*.funcs, where
2981 $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
2982 name (such as `+=') and `.' marks the end of the operator name.
2984 Returns 1 for success, 0 for failure. */
2987 read_member_functions (fip
, pp
, type
, objfile
)
2988 struct field_info
*fip
;
2991 struct objfile
*objfile
;
2995 /* Total number of member functions defined in this class. If the class
2996 defines two `f' functions, and one `g' function, then this will have
2998 int total_length
= 0;
3002 struct next_fnfield
*next
;
3003 struct fn_field fn_field
;
3006 struct type
*look_ahead_type
;
3007 struct next_fnfieldlist
*new_fnlist
;
3008 struct next_fnfield
*new_sublist
;
3012 /* Process each list until we find something that is not a member function
3013 or find the end of the functions. */
3017 /* We should be positioned at the start of the function name.
3018 Scan forward to find the first ':' and if it is not the
3019 first of a "::" delimiter, then this is not a member function. */
3031 look_ahead_type
= NULL
;
3034 new_fnlist
= (struct next_fnfieldlist
*)
3035 xmalloc (sizeof (struct next_fnfieldlist
));
3036 make_cleanup (free
, new_fnlist
);
3037 memset (new_fnlist
, 0, sizeof (struct next_fnfieldlist
));
3039 if ((*pp
)[0] == 'o' && (*pp
)[1] == 'p' && is_cplus_marker ((*pp
)[2]))
3041 /* This is a completely wierd case. In order to stuff in the
3042 names that might contain colons (the usual name delimiter),
3043 Mike Tiemann defined a different name format which is
3044 signalled if the identifier is "op$". In that case, the
3045 format is "op$::XXXX." where XXXX is the name. This is
3046 used for names like "+" or "=". YUUUUUUUK! FIXME! */
3047 /* This lets the user type "break operator+".
3048 We could just put in "+" as the name, but that wouldn't
3050 static char opname
[32] =
3051 {'o', 'p', CPLUS_MARKER
};
3052 char *o
= opname
+ 3;
3054 /* Skip past '::'. */
3057 STABS_CONTINUE (pp
, objfile
);
3063 main_fn_name
= savestring (opname
, o
- opname
);
3069 main_fn_name
= savestring (*pp
, p
- *pp
);
3070 /* Skip past '::'. */
3073 new_fnlist
->fn_fieldlist
.name
= main_fn_name
;
3078 (struct next_fnfield
*) xmalloc (sizeof (struct next_fnfield
));
3079 make_cleanup (free
, new_sublist
);
3080 memset (new_sublist
, 0, sizeof (struct next_fnfield
));
3082 /* Check for and handle cretinous dbx symbol name continuation! */
3083 if (look_ahead_type
== NULL
)
3086 STABS_CONTINUE (pp
, objfile
);
3088 new_sublist
->fn_field
.type
= read_type (pp
, objfile
);
3091 /* Invalid symtab info for member function. */
3097 /* g++ version 1 kludge */
3098 new_sublist
->fn_field
.type
= look_ahead_type
;
3099 look_ahead_type
= NULL
;
3109 /* If this is just a stub, then we don't have the real name here. */
3111 if (TYPE_FLAGS (new_sublist
->fn_field
.type
) & TYPE_FLAG_STUB
)
3113 if (!TYPE_DOMAIN_TYPE (new_sublist
->fn_field
.type
))
3114 TYPE_DOMAIN_TYPE (new_sublist
->fn_field
.type
) = type
;
3115 new_sublist
->fn_field
.is_stub
= 1;
3117 new_sublist
->fn_field
.physname
= savestring (*pp
, p
- *pp
);
3120 /* Set this member function's visibility fields. */
3123 case VISIBILITY_PRIVATE
:
3124 new_sublist
->fn_field
.is_private
= 1;
3126 case VISIBILITY_PROTECTED
:
3127 new_sublist
->fn_field
.is_protected
= 1;
3131 STABS_CONTINUE (pp
, objfile
);
3134 case 'A': /* Normal functions. */
3135 new_sublist
->fn_field
.is_const
= 0;
3136 new_sublist
->fn_field
.is_volatile
= 0;
3139 case 'B': /* `const' member functions. */
3140 new_sublist
->fn_field
.is_const
= 1;
3141 new_sublist
->fn_field
.is_volatile
= 0;
3144 case 'C': /* `volatile' member function. */
3145 new_sublist
->fn_field
.is_const
= 0;
3146 new_sublist
->fn_field
.is_volatile
= 1;
3149 case 'D': /* `const volatile' member function. */
3150 new_sublist
->fn_field
.is_const
= 1;
3151 new_sublist
->fn_field
.is_volatile
= 1;
3154 case '*': /* File compiled with g++ version 1 -- no info */
3159 complain (&const_vol_complaint
, **pp
);
3168 /* virtual member function, followed by index.
3169 The sign bit is set to distinguish pointers-to-methods
3170 from virtual function indicies. Since the array is
3171 in words, the quantity must be shifted left by 1
3172 on 16 bit machine, and by 2 on 32 bit machine, forcing
3173 the sign bit out, and usable as a valid index into
3174 the array. Remove the sign bit here. */
3175 new_sublist
->fn_field
.voffset
=
3176 (0x7fffffff & read_huge_number (pp
, ';', &nbits
)) + 2;
3180 STABS_CONTINUE (pp
, objfile
);
3181 if (**pp
== ';' || **pp
== '\0')
3183 /* Must be g++ version 1. */
3184 new_sublist
->fn_field
.fcontext
= 0;
3188 /* Figure out from whence this virtual function came.
3189 It may belong to virtual function table of
3190 one of its baseclasses. */
3191 look_ahead_type
= read_type (pp
, objfile
);
3194 /* g++ version 1 overloaded methods. */
3198 new_sublist
->fn_field
.fcontext
= look_ahead_type
;
3207 look_ahead_type
= NULL
;
3213 /* static member function. */
3214 new_sublist
->fn_field
.voffset
= VOFFSET_STATIC
;
3215 if (strncmp (new_sublist
->fn_field
.physname
,
3216 main_fn_name
, strlen (main_fn_name
)))
3218 new_sublist
->fn_field
.is_stub
= 1;
3224 complain (&member_fn_complaint
, (*pp
)[-1]);
3225 /* Fall through into normal member function. */
3228 /* normal member function. */
3229 new_sublist
->fn_field
.voffset
= 0;
3230 new_sublist
->fn_field
.fcontext
= 0;
3234 new_sublist
->next
= sublist
;
3235 sublist
= new_sublist
;
3237 STABS_CONTINUE (pp
, objfile
);
3239 while (**pp
!= ';' && **pp
!= '\0');
3243 new_fnlist
->fn_fieldlist
.fn_fields
= (struct fn_field
*)
3244 obstack_alloc (&objfile
->type_obstack
,
3245 sizeof (struct fn_field
) * length
);
3246 memset (new_fnlist
->fn_fieldlist
.fn_fields
, 0,
3247 sizeof (struct fn_field
) * length
);
3248 for (i
= length
; (i
--, sublist
); sublist
= sublist
->next
)
3250 new_fnlist
->fn_fieldlist
.fn_fields
[i
] = sublist
->fn_field
;
3253 new_fnlist
->fn_fieldlist
.length
= length
;
3254 new_fnlist
->next
= fip
->fnlist
;
3255 fip
->fnlist
= new_fnlist
;
3257 total_length
+= length
;
3258 STABS_CONTINUE (pp
, objfile
);
3263 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3264 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
3265 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * nfn_fields
);
3266 memset (TYPE_FN_FIELDLISTS (type
), 0,
3267 sizeof (struct fn_fieldlist
) * nfn_fields
);
3268 TYPE_NFN_FIELDS (type
) = nfn_fields
;
3269 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
3275 /* Special GNU C++ name.
3277 Returns 1 for success, 0 for failure. "failure" means that we can't
3278 keep parsing and it's time for error_type(). */
3281 read_cpp_abbrev (fip
, pp
, type
, objfile
)
3282 struct field_info
*fip
;
3285 struct objfile
*objfile
;
3290 struct type
*context
;
3300 /* At this point, *pp points to something like "22:23=*22...",
3301 where the type number before the ':' is the "context" and
3302 everything after is a regular type definition. Lookup the
3303 type, find it's name, and construct the field name. */
3305 context
= read_type (pp
, objfile
);
3309 case 'f': /* $vf -- a virtual function table pointer */
3310 fip
->list
->field
.name
=
3311 obconcat (&objfile
->type_obstack
, vptr_name
, "", "");
3314 case 'b': /* $vb -- a virtual bsomethingorother */
3315 name
= type_name_no_tag (context
);
3318 complain (&invalid_cpp_type_complaint
, symnum
);
3321 fip
->list
->field
.name
=
3322 obconcat (&objfile
->type_obstack
, vb_name
, name
, "");
3326 complain (&invalid_cpp_abbrev_complaint
, *pp
);
3327 fip
->list
->field
.name
=
3328 obconcat (&objfile
->type_obstack
,
3329 "INVALID_CPLUSPLUS_ABBREV", "", "");
3333 /* At this point, *pp points to the ':'. Skip it and read the
3339 complain (&invalid_cpp_abbrev_complaint
, *pp
);
3342 fip
->list
->field
.type
= read_type (pp
, objfile
);
3344 (*pp
)++; /* Skip the comma. */
3350 FIELD_BITPOS (fip
->list
->field
) = read_huge_number (pp
, ';', &nbits
);
3354 /* This field is unpacked. */
3355 FIELD_BITSIZE (fip
->list
->field
) = 0;
3356 fip
->list
->visibility
= VISIBILITY_PRIVATE
;
3360 complain (&invalid_cpp_abbrev_complaint
, *pp
);
3361 /* We have no idea what syntax an unrecognized abbrev would have, so
3362 better return 0. If we returned 1, we would need to at least advance
3363 *pp to avoid an infinite loop. */
3370 read_one_struct_field (fip
, pp
, p
, type
, objfile
)
3371 struct field_info
*fip
;
3375 struct objfile
*objfile
;
3377 /* The following is code to work around cfront generated stabs.
3378 The stabs contains full mangled name for each field.
3379 We try to demangle the name and extract the field name out of it.
3381 if (ARM_DEMANGLING
&& current_subfile
->language
== language_cplus
)
3387 dem
= cplus_demangle (*pp
, DMGL_ANSI
| DMGL_PARAMS
);
3390 dem_p
= strrchr (dem
, ':');
3391 if (dem_p
!= 0 && *(dem_p
- 1) == ':')
3393 FIELD_NAME (fip
->list
->field
) =
3394 obsavestring (dem_p
, strlen (dem_p
), &objfile
->type_obstack
);
3398 FIELD_NAME (fip
->list
->field
) =
3399 obsavestring (*pp
, p
- *pp
, &objfile
->type_obstack
);
3403 /* end of code for cfront work around */
3406 fip
->list
->field
.name
=
3407 obsavestring (*pp
, p
- *pp
, &objfile
->type_obstack
);
3410 /* This means we have a visibility for a field coming. */
3414 fip
->list
->visibility
= *(*pp
)++;
3418 /* normal dbx-style format, no explicit visibility */
3419 fip
->list
->visibility
= VISIBILITY_PUBLIC
;
3422 fip
->list
->field
.type
= read_type (pp
, objfile
);
3427 /* Possible future hook for nested types. */
3430 fip
->list
->field
.bitpos
= (long) -2; /* nested type */
3440 /* Static class member. */
3441 SET_FIELD_PHYSNAME (fip
->list
->field
, savestring (*pp
, p
- *pp
));
3445 else if (**pp
!= ',')
3447 /* Bad structure-type format. */
3448 complain (&stabs_general_complaint
, "bad structure-type format");
3452 (*pp
)++; /* Skip the comma. */
3456 FIELD_BITPOS (fip
->list
->field
) = read_huge_number (pp
, ',', &nbits
);
3459 complain (&stabs_general_complaint
, "bad structure-type format");
3462 FIELD_BITSIZE (fip
->list
->field
) = read_huge_number (pp
, ';', &nbits
);
3465 complain (&stabs_general_complaint
, "bad structure-type format");
3470 if (FIELD_BITPOS (fip
->list
->field
) == 0
3471 && FIELD_BITSIZE (fip
->list
->field
) == 0)
3473 /* This can happen in two cases: (1) at least for gcc 2.4.5 or so,
3474 it is a field which has been optimized out. The correct stab for
3475 this case is to use VISIBILITY_IGNORE, but that is a recent
3476 invention. (2) It is a 0-size array. For example
3477 union { int num; char str[0]; } foo. Printing "<no value>" for
3478 str in "p foo" is OK, since foo.str (and thus foo.str[3])
3479 will continue to work, and a 0-size array as a whole doesn't
3480 have any contents to print.
3482 I suspect this probably could also happen with gcc -gstabs (not
3483 -gstabs+) for static fields, and perhaps other C++ extensions.
3484 Hopefully few people use -gstabs with gdb, since it is intended
3485 for dbx compatibility. */
3487 /* Ignore this field. */
3488 fip
->list
->visibility
= VISIBILITY_IGNORE
;
3492 /* Detect an unpacked field and mark it as such.
3493 dbx gives a bit size for all fields.
3494 Note that forward refs cannot be packed,
3495 and treat enums as if they had the width of ints. */
3497 struct type
*field_type
= check_typedef (FIELD_TYPE (fip
->list
->field
));
3499 if (TYPE_CODE (field_type
) != TYPE_CODE_INT
3500 && TYPE_CODE (field_type
) != TYPE_CODE_RANGE
3501 && TYPE_CODE (field_type
) != TYPE_CODE_BOOL
3502 && TYPE_CODE (field_type
) != TYPE_CODE_ENUM
)
3504 FIELD_BITSIZE (fip
->list
->field
) = 0;
3506 if ((FIELD_BITSIZE (fip
->list
->field
)
3507 == TARGET_CHAR_BIT
* TYPE_LENGTH (field_type
)
3508 || (TYPE_CODE (field_type
) == TYPE_CODE_ENUM
3509 && FIELD_BITSIZE (fip
->list
->field
) == TARGET_INT_BIT
)
3512 FIELD_BITPOS (fip
->list
->field
) % 8 == 0)
3514 FIELD_BITSIZE (fip
->list
->field
) = 0;
3520 /* Read struct or class data fields. They have the form:
3522 NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
3524 At the end, we see a semicolon instead of a field.
3526 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
3529 The optional VISIBILITY is one of:
3531 '/0' (VISIBILITY_PRIVATE)
3532 '/1' (VISIBILITY_PROTECTED)
3533 '/2' (VISIBILITY_PUBLIC)
3534 '/9' (VISIBILITY_IGNORE)
3536 or nothing, for C style fields with public visibility.
3538 Returns 1 for success, 0 for failure. */
3541 read_struct_fields (fip
, pp
, type
, objfile
)
3542 struct field_info
*fip
;
3545 struct objfile
*objfile
;
3548 struct nextfield
*new;
3550 /* We better set p right now, in case there are no fields at all... */
3554 /* Read each data member type until we find the terminating ';' at the end of
3555 the data member list, or break for some other reason such as finding the
3556 start of the member function list. */
3560 if (os9k_stabs
&& **pp
== ',')
3562 STABS_CONTINUE (pp
, objfile
);
3563 /* Get space to record the next field's data. */
3564 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3565 make_cleanup (free
, new);
3566 memset (new, 0, sizeof (struct nextfield
));
3567 new->next
= fip
->list
;
3570 /* Get the field name. */
3573 /* If is starts with CPLUS_MARKER it is a special abbreviation,
3574 unless the CPLUS_MARKER is followed by an underscore, in
3575 which case it is just the name of an anonymous type, which we
3576 should handle like any other type name. */
3578 if (is_cplus_marker (p
[0]) && p
[1] != '_')
3580 if (!read_cpp_abbrev (fip
, pp
, type
, objfile
))
3585 /* Look for the ':' that separates the field name from the field
3586 values. Data members are delimited by a single ':', while member
3587 functions are delimited by a pair of ':'s. When we hit the member
3588 functions (if any), terminate scan loop and return. */
3590 while (*p
!= ':' && *p
!= '\0')
3597 /* Check to see if we have hit the member functions yet. */
3602 read_one_struct_field (fip
, pp
, p
, type
, objfile
);
3604 if (p
[0] == ':' && p
[1] == ':')
3606 /* chill the list of fields: the last entry (at the head) is a
3607 partially constructed entry which we now scrub. */
3608 fip
->list
= fip
->list
->next
;
3613 /* The stabs for C++ derived classes contain baseclass information which
3614 is marked by a '!' character after the total size. This function is
3615 called when we encounter the baseclass marker, and slurps up all the
3616 baseclass information.
3618 Immediately following the '!' marker is the number of base classes that
3619 the class is derived from, followed by information for each base class.
3620 For each base class, there are two visibility specifiers, a bit offset
3621 to the base class information within the derived class, a reference to
3622 the type for the base class, and a terminating semicolon.
3624 A typical example, with two base classes, would be "!2,020,19;0264,21;".
3626 Baseclass information marker __________________|| | | | | | |
3627 Number of baseclasses __________________________| | | | | | |
3628 Visibility specifiers (2) ________________________| | | | | |
3629 Offset in bits from start of class _________________| | | | |
3630 Type number for base class ___________________________| | | |
3631 Visibility specifiers (2) _______________________________| | |
3632 Offset in bits from start of class ________________________| |
3633 Type number of base class ____________________________________|
3635 Return 1 for success, 0 for (error-type-inducing) failure. */
3641 read_baseclasses (fip
, pp
, type
, objfile
)
3642 struct field_info
*fip
;
3645 struct objfile
*objfile
;
3648 struct nextfield
*new;
3656 /* Skip the '!' baseclass information marker. */
3660 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3663 TYPE_N_BASECLASSES (type
) = read_huge_number (pp
, ',', &nbits
);
3669 /* Some stupid compilers have trouble with the following, so break
3670 it up into simpler expressions. */
3671 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*)
3672 TYPE_ALLOC (type
, B_BYTES (TYPE_N_BASECLASSES (type
)));
3675 int num_bytes
= B_BYTES (TYPE_N_BASECLASSES (type
));
3678 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
3679 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
3683 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), TYPE_N_BASECLASSES (type
));
3685 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
3687 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3688 make_cleanup (free
, new);
3689 memset (new, 0, sizeof (struct nextfield
));
3690 new->next
= fip
->list
;
3692 FIELD_BITSIZE (new->field
) = 0; /* this should be an unpacked field! */
3694 STABS_CONTINUE (pp
, objfile
);
3698 /* Nothing to do. */
3701 SET_TYPE_FIELD_VIRTUAL (type
, i
);
3704 /* Unknown character. Complain and treat it as non-virtual. */
3706 static struct complaint msg
=
3708 "Unknown virtual character `%c' for baseclass", 0, 0};
3709 complain (&msg
, **pp
);
3714 new->visibility
= *(*pp
)++;
3715 switch (new->visibility
)
3717 case VISIBILITY_PRIVATE
:
3718 case VISIBILITY_PROTECTED
:
3719 case VISIBILITY_PUBLIC
:
3722 /* Bad visibility format. Complain and treat it as
3725 static struct complaint msg
=
3727 "Unknown visibility `%c' for baseclass", 0, 0
3729 complain (&msg
, new->visibility
);
3730 new->visibility
= VISIBILITY_PUBLIC
;
3737 /* The remaining value is the bit offset of the portion of the object
3738 corresponding to this baseclass. Always zero in the absence of
3739 multiple inheritance. */
3741 FIELD_BITPOS (new->field
) = read_huge_number (pp
, ',', &nbits
);
3746 /* The last piece of baseclass information is the type of the
3747 base class. Read it, and remember it's type name as this
3750 new->field
.type
= read_type (pp
, objfile
);
3751 new->field
.name
= type_name_no_tag (new->field
.type
);
3753 /* skip trailing ';' and bump count of number of fields seen */
3762 /* The tail end of stabs for C++ classes that contain a virtual function
3763 pointer contains a tilde, a %, and a type number.
3764 The type number refers to the base class (possibly this class itself) which
3765 contains the vtable pointer for the current class.
3767 This function is called when we have parsed all the method declarations,
3768 so we can look for the vptr base class info. */
3771 read_tilde_fields (fip
, pp
, type
, objfile
)
3772 struct field_info
*fip
;
3775 struct objfile
*objfile
;
3779 STABS_CONTINUE (pp
, objfile
);
3781 /* If we are positioned at a ';', then skip it. */
3791 if (**pp
== '=' || **pp
== '+' || **pp
== '-')
3793 /* Obsolete flags that used to indicate the presence
3794 of constructors and/or destructors. */
3798 /* Read either a '%' or the final ';'. */
3799 if (*(*pp
)++ == '%')
3801 /* The next number is the type number of the base class
3802 (possibly our own class) which supplies the vtable for
3803 this class. Parse it out, and search that class to find
3804 its vtable pointer, and install those into TYPE_VPTR_BASETYPE
3805 and TYPE_VPTR_FIELDNO. */
3810 t
= read_type (pp
, objfile
);
3812 while (*p
!= '\0' && *p
!= ';')
3818 /* Premature end of symbol. */
3822 TYPE_VPTR_BASETYPE (type
) = t
;
3823 if (type
== t
) /* Our own class provides vtbl ptr */
3825 for (i
= TYPE_NFIELDS (t
) - 1;
3826 i
>= TYPE_N_BASECLASSES (t
);
3829 if (!strncmp (TYPE_FIELD_NAME (t
, i
), vptr_name
,
3830 sizeof (vptr_name
) - 1))
3832 TYPE_VPTR_FIELDNO (type
) = i
;
3836 /* Virtual function table field not found. */
3837 complain (&vtbl_notfound_complaint
, TYPE_NAME (type
));
3842 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
3853 attach_fn_fields_to_type (fip
, type
)
3854 struct field_info
*fip
;
3855 register struct type
*type
;
3859 for (n
= TYPE_NFN_FIELDS (type
);
3860 fip
->fnlist
!= NULL
;
3861 fip
->fnlist
= fip
->fnlist
->next
)
3863 --n
; /* Circumvent Sun3 compiler bug */
3864 TYPE_FN_FIELDLISTS (type
)[n
] = fip
->fnlist
->fn_fieldlist
;
3869 /* read cfront class static data.
3870 pp points to string starting with the list of static data
3871 eg: A:ZcA;1@Bpub v2@Bvirpri;__ct__1AFv func__1AFv *sfunc__1AFv ;as__1A ;;
3874 A:ZcA;;foopri__1AFv foopro__1AFv __ct__1AFv __ct__1AFRC1A foopub__1AFv ;;;
3879 read_cfront_static_fields (fip
, pp
, type
, objfile
)
3880 struct field_info
*fip
;
3883 struct objfile
*objfile
;
3885 struct nextfield
*new;
3888 struct symbol
*ref_static
= 0;
3890 if (**pp
== ';') /* no static data; return */
3896 /* Process each field in the list until we find the terminating ";" */
3898 /* eg: p = "as__1A ;;;" */
3899 STABS_CONTINUE (pp
, objfile
); /* handle \\ */
3900 while (**pp
!= ';' && (sname
= get_substring (pp
, ' '), sname
))
3902 ref_static
= lookup_symbol (sname
, 0, VAR_NAMESPACE
, 0, 0); /*demangled_name */
3905 static struct complaint msg
=
3907 Unable to find symbol for static data field %s\n",
3909 complain (&msg
, sname
);
3912 stype
= SYMBOL_TYPE (ref_static
);
3914 /* allocate a new fip */
3915 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3916 make_cleanup (free
, new);
3917 memset (new, 0, sizeof (struct nextfield
));
3918 new->next
= fip
->list
;
3921 /* set visibility */
3922 /* FIXME! no way to tell visibility from stabs??? */
3923 new->visibility
= VISIBILITY_PUBLIC
;
3925 /* set field info into fip */
3926 fip
->list
->field
.type
= stype
;
3928 /* set bitpos & bitsize */
3929 SET_FIELD_PHYSNAME (fip
->list
->field
, savestring (sname
, strlen (sname
)));
3931 /* set name field */
3932 /* The following is code to work around cfront generated stabs.
3933 The stabs contains full mangled name for each field.
3934 We try to demangle the name and extract the field name out of it.
3939 dem
= cplus_demangle (sname
, DMGL_ANSI
| DMGL_PARAMS
);
3942 dem_p
= strrchr (dem
, ':');
3943 if (dem_p
!= 0 && *(dem_p
- 1) == ':')
3945 fip
->list
->field
.name
=
3946 obsavestring (dem_p
, strlen (dem_p
), &objfile
->type_obstack
);
3950 fip
->list
->field
.name
=
3951 obsavestring (sname
, strlen (sname
), &objfile
->type_obstack
);
3953 } /* end of code for cfront work around */
3954 } /* loop again for next static field */
3958 /* Copy structure fields to fip so attach_fields_to_type will work.
3959 type has already been created with the initial instance data fields.
3960 Now we want to be able to add the other members to the class,
3961 so we want to add them back to the fip and reattach them again
3962 once we have collected all the class members. */
3965 copy_cfront_struct_fields (fip
, type
, objfile
)
3966 struct field_info
*fip
;
3968 struct objfile
*objfile
;
3970 int nfields
= TYPE_NFIELDS (type
);
3972 struct nextfield
*new;
3974 /* Copy the fields into the list of fips and reset the types
3975 to remove the old fields */
3977 for (i
= 0; i
< nfields
; i
++)
3979 /* allocate a new fip */
3980 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3981 make_cleanup (free
, new);
3982 memset (new, 0, sizeof (struct nextfield
));
3983 new->next
= fip
->list
;
3986 /* copy field info into fip */
3987 new->field
= TYPE_FIELD (type
, i
);
3988 /* set visibility */
3989 if (TYPE_FIELD_PROTECTED (type
, i
))
3990 new->visibility
= VISIBILITY_PROTECTED
;
3991 else if (TYPE_FIELD_PRIVATE (type
, i
))
3992 new->visibility
= VISIBILITY_PRIVATE
;
3994 new->visibility
= VISIBILITY_PUBLIC
;
3996 /* Now delete the fields from the type since we will be
3997 allocing new space once we get the rest of the fields
3998 in attach_fields_to_type.
3999 The pointer TYPE_FIELDS(type) is left dangling but should
4000 be freed later by objstack_free */
4001 TYPE_FIELDS (type
) = 0;
4002 TYPE_NFIELDS (type
) = 0;
4007 /* Create the vector of fields, and record how big it is.
4008 We need this info to record proper virtual function table information
4009 for this class's virtual functions. */
4012 attach_fields_to_type (fip
, type
, objfile
)
4013 struct field_info
*fip
;
4014 register struct type
*type
;
4015 struct objfile
*objfile
;
4017 register int nfields
= 0;
4018 register int non_public_fields
= 0;
4019 register struct nextfield
*scan
;
4021 /* Count up the number of fields that we have, as well as taking note of
4022 whether or not there are any non-public fields, which requires us to
4023 allocate and build the private_field_bits and protected_field_bits
4026 for (scan
= fip
->list
; scan
!= NULL
; scan
= scan
->next
)
4029 if (scan
->visibility
!= VISIBILITY_PUBLIC
)
4031 non_public_fields
++;
4035 /* Now we know how many fields there are, and whether or not there are any
4036 non-public fields. Record the field count, allocate space for the
4037 array of fields, and create blank visibility bitfields if necessary. */
4039 TYPE_NFIELDS (type
) = nfields
;
4040 TYPE_FIELDS (type
) = (struct field
*)
4041 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
4042 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
4044 if (non_public_fields
)
4046 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
4048 TYPE_FIELD_PRIVATE_BITS (type
) =
4049 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
4050 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
4052 TYPE_FIELD_PROTECTED_BITS (type
) =
4053 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
4054 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
4056 TYPE_FIELD_IGNORE_BITS (type
) =
4057 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
4058 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
4061 /* Copy the saved-up fields into the field vector. Start from the head
4062 of the list, adding to the tail of the field array, so that they end
4063 up in the same order in the array in which they were added to the list. */
4065 while (nfields
-- > 0)
4067 TYPE_FIELD (type
, nfields
) = fip
->list
->field
;
4068 switch (fip
->list
->visibility
)
4070 case VISIBILITY_PRIVATE
:
4071 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
4074 case VISIBILITY_PROTECTED
:
4075 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
4078 case VISIBILITY_IGNORE
:
4079 SET_TYPE_FIELD_IGNORE (type
, nfields
);
4082 case VISIBILITY_PUBLIC
:
4086 /* Unknown visibility. Complain and treat it as public. */
4088 static struct complaint msg
=
4090 "Unknown visibility `%c' for field", 0, 0};
4091 complain (&msg
, fip
->list
->visibility
);
4095 fip
->list
= fip
->list
->next
;
4100 /* Read the description of a structure (or union type) and return an object
4101 describing the type.
4103 PP points to a character pointer that points to the next unconsumed token
4104 in the the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
4105 *PP will point to "4a:1,0,32;;".
4107 TYPE points to an incomplete type that needs to be filled in.
4109 OBJFILE points to the current objfile from which the stabs information is
4110 being read. (Note that it is redundant in that TYPE also contains a pointer
4111 to this same objfile, so it might be a good idea to eliminate it. FIXME).
4114 static struct type
*
4115 read_struct_type (pp
, type
, objfile
)
4118 struct objfile
*objfile
;
4120 struct cleanup
*back_to
;
4121 struct field_info fi
;
4126 back_to
= make_cleanup (null_cleanup
, 0);
4128 INIT_CPLUS_SPECIFIC (type
);
4129 TYPE_FLAGS (type
) &= ~TYPE_FLAG_STUB
;
4131 /* First comes the total size in bytes. */
4135 TYPE_LENGTH (type
) = read_huge_number (pp
, 0, &nbits
);
4137 return error_type (pp
, objfile
);
4140 /* Now read the baseclasses, if any, read the regular C struct or C++
4141 class member fields, attach the fields to the type, read the C++
4142 member functions, attach them to the type, and then read any tilde
4143 field (baseclass specifier for the class holding the main vtable). */
4145 if (!read_baseclasses (&fi
, pp
, type
, objfile
)
4146 || !read_struct_fields (&fi
, pp
, type
, objfile
)
4147 || !attach_fields_to_type (&fi
, type
, objfile
)
4148 || !read_member_functions (&fi
, pp
, type
, objfile
)
4149 || !attach_fn_fields_to_type (&fi
, type
)
4150 || !read_tilde_fields (&fi
, pp
, type
, objfile
))
4152 type
= error_type (pp
, objfile
);
4155 do_cleanups (back_to
);
4159 /* Read a definition of an array type,
4160 and create and return a suitable type object.
4161 Also creates a range type which represents the bounds of that
4164 static struct type
*
4165 read_array_type (pp
, type
, objfile
)
4167 register struct type
*type
;
4168 struct objfile
*objfile
;
4170 struct type
*index_type
, *element_type
, *range_type
;
4175 /* Format of an array type:
4176 "ar<index type>;lower;upper;<array_contents_type>".
4177 OS9000: "arlower,upper;<array_contents_type>".
4179 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
4180 for these, produce a type like float[][]. */
4183 index_type
= builtin_type_int
;
4186 index_type
= read_type (pp
, objfile
);
4188 /* Improper format of array type decl. */
4189 return error_type (pp
, objfile
);
4193 if (!(**pp
>= '0' && **pp
<= '9') && **pp
!= '-')
4198 lower
= read_huge_number (pp
, os9k_stabs
? ',' : ';', &nbits
);
4200 return error_type (pp
, objfile
);
4202 if (!(**pp
>= '0' && **pp
<= '9') && **pp
!= '-')
4207 upper
= read_huge_number (pp
, ';', &nbits
);
4209 return error_type (pp
, objfile
);
4211 element_type
= read_type (pp
, objfile
);
4220 create_range_type ((struct type
*) NULL
, index_type
, lower
, upper
);
4221 type
= create_array_type (type
, element_type
, range_type
);
4227 /* Read a definition of an enumeration type,
4228 and create and return a suitable type object.
4229 Also defines the symbols that represent the values of the type. */
4231 static struct type
*
4232 read_enum_type (pp
, type
, objfile
)
4234 register struct type
*type
;
4235 struct objfile
*objfile
;
4240 register struct symbol
*sym
;
4242 struct pending
**symlist
;
4243 struct pending
*osyms
, *syms
;
4246 int unsigned_enum
= 1;
4249 /* FIXME! The stabs produced by Sun CC merrily define things that ought
4250 to be file-scope, between N_FN entries, using N_LSYM. What's a mother
4251 to do? For now, force all enum values to file scope. */
4252 if (within_function
)
4253 symlist
= &local_symbols
;
4256 symlist
= &file_symbols
;
4258 o_nsyms
= osyms
? osyms
->nsyms
: 0;
4262 /* Size. Perhaps this does not have to be conditionalized on
4263 os9k_stabs (assuming the name of an enum constant can't start
4265 read_huge_number (pp
, 0, &nbits
);
4267 return error_type (pp
, objfile
);
4270 /* The aix4 compiler emits an extra field before the enum members;
4271 my guess is it's a type of some sort. Just ignore it. */
4274 /* Skip over the type. */
4278 /* Skip over the colon. */
4282 /* Read the value-names and their values.
4283 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
4284 A semicolon or comma instead of a NAME means the end. */
4285 while (**pp
&& **pp
!= ';' && **pp
!= ',')
4287 STABS_CONTINUE (pp
, objfile
);
4291 name
= obsavestring (*pp
, p
- *pp
, &objfile
->symbol_obstack
);
4293 n
= read_huge_number (pp
, ',', &nbits
);
4295 return error_type (pp
, objfile
);
4297 sym
= (struct symbol
*)
4298 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct symbol
));
4299 memset (sym
, 0, sizeof (struct symbol
));
4300 SYMBOL_NAME (sym
) = name
;
4301 SYMBOL_LANGUAGE (sym
) = current_subfile
->language
;
4302 SYMBOL_CLASS (sym
) = LOC_CONST
;
4303 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4304 SYMBOL_VALUE (sym
) = n
;
4307 add_symbol_to_list (sym
, symlist
);
4312 (*pp
)++; /* Skip the semicolon. */
4314 /* Now fill in the fields of the type-structure. */
4316 TYPE_LENGTH (type
) = TARGET_INT_BIT
/ HOST_CHAR_BIT
;
4317 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
4318 TYPE_FLAGS (type
) &= ~TYPE_FLAG_STUB
;
4320 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
4321 TYPE_NFIELDS (type
) = nsyms
;
4322 TYPE_FIELDS (type
) = (struct field
*)
4323 TYPE_ALLOC (type
, sizeof (struct field
) * nsyms
);
4324 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nsyms
);
4326 /* Find the symbols for the values and put them into the type.
4327 The symbols can be found in the symlist that we put them on
4328 to cause them to be defined. osyms contains the old value
4329 of that symlist; everything up to there was defined by us. */
4330 /* Note that we preserve the order of the enum constants, so
4331 that in something like "enum {FOO, LAST_THING=FOO}" we print
4332 FOO, not LAST_THING. */
4334 for (syms
= *symlist
, n
= nsyms
- 1; syms
; syms
= syms
->next
)
4336 int last
= syms
== osyms
? o_nsyms
: 0;
4337 int j
= syms
->nsyms
;
4338 for (; --j
>= last
; --n
)
4340 struct symbol
*xsym
= syms
->symbol
[j
];
4341 SYMBOL_TYPE (xsym
) = type
;
4342 TYPE_FIELD_NAME (type
, n
) = SYMBOL_NAME (xsym
);
4343 TYPE_FIELD_BITPOS (type
, n
) = SYMBOL_VALUE (xsym
);
4344 TYPE_FIELD_BITSIZE (type
, n
) = 0;
4353 /* Sun's ACC uses a somewhat saner method for specifying the builtin
4354 typedefs in every file (for int, long, etc):
4356 type = b <signed> <width> <format type>; <offset>; <nbits>
4358 optional format type = c or b for char or boolean.
4359 offset = offset from high order bit to start bit of type.
4360 width is # bytes in object of this type, nbits is # bits in type.
4362 The width/offset stuff appears to be for small objects stored in
4363 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
4366 static struct type
*
4367 read_sun_builtin_type (pp
, typenums
, objfile
)
4370 struct objfile
*objfile
;
4375 enum type_code code
= TYPE_CODE_INT
;
4386 return error_type (pp
, objfile
);
4390 /* For some odd reason, all forms of char put a c here. This is strange
4391 because no other type has this honor. We can safely ignore this because
4392 we actually determine 'char'acterness by the number of bits specified in
4394 Boolean forms, e.g Fortran logical*X, put a b here. */
4398 else if (**pp
== 'b')
4400 code
= TYPE_CODE_BOOL
;
4404 /* The first number appears to be the number of bytes occupied
4405 by this type, except that unsigned short is 4 instead of 2.
4406 Since this information is redundant with the third number,
4407 we will ignore it. */
4408 read_huge_number (pp
, ';', &nbits
);
4410 return error_type (pp
, objfile
);
4412 /* The second number is always 0, so ignore it too. */
4413 read_huge_number (pp
, ';', &nbits
);
4415 return error_type (pp
, objfile
);
4417 /* The third number is the number of bits for this type. */
4418 type_bits
= read_huge_number (pp
, 0, &nbits
);
4420 return error_type (pp
, objfile
);
4421 /* The type *should* end with a semicolon. If it are embedded
4422 in a larger type the semicolon may be the only way to know where
4423 the type ends. If this type is at the end of the stabstring we
4424 can deal with the omitted semicolon (but we don't have to like
4425 it). Don't bother to complain(), Sun's compiler omits the semicolon
4431 return init_type (TYPE_CODE_VOID
, 1,
4432 signed_type
? 0 : TYPE_FLAG_UNSIGNED
, (char *) NULL
,
4435 return init_type (code
,
4436 type_bits
/ TARGET_CHAR_BIT
,
4437 signed_type
? 0 : TYPE_FLAG_UNSIGNED
, (char *) NULL
,
4441 static struct type
*
4442 read_sun_floating_type (pp
, typenums
, objfile
)
4445 struct objfile
*objfile
;
4451 /* The first number has more details about the type, for example
4453 details
= read_huge_number (pp
, ';', &nbits
);
4455 return error_type (pp
, objfile
);
4457 /* The second number is the number of bytes occupied by this type */
4458 nbytes
= read_huge_number (pp
, ';', &nbits
);
4460 return error_type (pp
, objfile
);
4462 if (details
== NF_COMPLEX
|| details
== NF_COMPLEX16
4463 || details
== NF_COMPLEX32
)
4464 /* This is a type we can't handle, but we do know the size.
4465 We also will be able to give it a name. */
4466 return init_type (TYPE_CODE_COMPLEX
, nbytes
, 0, NULL
, objfile
);
4468 return init_type (TYPE_CODE_FLT
, nbytes
, 0, NULL
, objfile
);
4471 /* Read a number from the string pointed to by *PP.
4472 The value of *PP is advanced over the number.
4473 If END is nonzero, the character that ends the
4474 number must match END, or an error happens;
4475 and that character is skipped if it does match.
4476 If END is zero, *PP is left pointing to that character.
4478 If the number fits in a long, set *BITS to 0 and return the value.
4479 If not, set *BITS to be the number of bits in the number and return 0.
4481 If encounter garbage, set *BITS to -1 and return 0. */
4484 read_huge_number (pp
, end
, bits
)
4504 /* Leading zero means octal. GCC uses this to output values larger
4505 than an int (because that would be hard in decimal). */
4513 upper_limit
= ULONG_MAX
/ radix
;
4515 upper_limit
= LONG_MAX
/ radix
;
4517 while ((c
= *p
++) >= '0' && c
< ('0' + radix
))
4519 if (n
<= upper_limit
)
4522 n
+= c
- '0'; /* FIXME this overflows anyway */
4527 /* This depends on large values being output in octal, which is
4534 /* Ignore leading zeroes. */
4538 else if (c
== '2' || c
== '3')
4564 /* Large decimal constants are an error (because it is hard to
4565 count how many bits are in them). */
4571 /* -0x7f is the same as 0x80. So deal with it by adding one to
4572 the number of bits. */
4584 /* It's *BITS which has the interesting information. */
4588 static struct type
*
4589 read_range_type (pp
, typenums
, objfile
)
4592 struct objfile
*objfile
;
4594 char *orig_pp
= *pp
;
4599 struct type
*result_type
;
4600 struct type
*index_type
= NULL
;
4602 /* First comes a type we are a subrange of.
4603 In C it is usually 0, 1 or the type being defined. */
4604 if (read_type_number (pp
, rangenums
) != 0)
4605 return error_type (pp
, objfile
);
4606 self_subrange
= (rangenums
[0] == typenums
[0] &&
4607 rangenums
[1] == typenums
[1]);
4612 index_type
= read_type (pp
, objfile
);
4615 /* A semicolon should now follow; skip it. */
4619 /* The remaining two operands are usually lower and upper bounds
4620 of the range. But in some special cases they mean something else. */
4621 n2
= read_huge_number (pp
, ';', &n2bits
);
4622 n3
= read_huge_number (pp
, ';', &n3bits
);
4624 if (n2bits
== -1 || n3bits
== -1)
4625 return error_type (pp
, objfile
);
4628 goto handle_true_range
;
4630 /* If limits are huge, must be large integral type. */
4631 if (n2bits
!= 0 || n3bits
!= 0)
4633 char got_signed
= 0;
4634 char got_unsigned
= 0;
4635 /* Number of bits in the type. */
4638 /* Range from 0 to <large number> is an unsigned large integral type. */
4639 if ((n2bits
== 0 && n2
== 0) && n3bits
!= 0)
4644 /* Range from <large number> to <large number>-1 is a large signed
4645 integral type. Take care of the case where <large number> doesn't
4646 fit in a long but <large number>-1 does. */
4647 else if ((n2bits
!= 0 && n3bits
!= 0 && n2bits
== n3bits
+ 1)
4648 || (n2bits
!= 0 && n3bits
== 0
4649 && (n2bits
== sizeof (long) * HOST_CHAR_BIT
)
4656 if (got_signed
|| got_unsigned
)
4658 return init_type (TYPE_CODE_INT
, nbits
/ TARGET_CHAR_BIT
,
4659 got_unsigned
? TYPE_FLAG_UNSIGNED
: 0, NULL
,
4663 return error_type (pp
, objfile
);
4666 /* A type defined as a subrange of itself, with bounds both 0, is void. */
4667 if (self_subrange
&& n2
== 0 && n3
== 0)
4668 return init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
4670 /* If n3 is zero and n2 is positive, we want a floating type, and n2
4671 is the width in bytes.
4673 Fortran programs appear to use this for complex types also. To
4674 distinguish between floats and complex, g77 (and others?) seem
4675 to use self-subranges for the complexes, and subranges of int for
4678 Also note that for complexes, g77 sets n2 to the size of one of
4679 the member floats, not the whole complex beast. My guess is that
4680 this was to work well with pre-COMPLEX versions of gdb. */
4682 if (n3
== 0 && n2
> 0)
4686 return init_type (TYPE_CODE_COMPLEX
, 2 * n2
, 0, NULL
, objfile
);
4690 return init_type (TYPE_CODE_FLT
, n2
, 0, NULL
, objfile
);
4694 /* If the upper bound is -1, it must really be an unsigned int. */
4696 else if (n2
== 0 && n3
== -1)
4698 /* It is unsigned int or unsigned long. */
4699 /* GCC 2.3.3 uses this for long long too, but that is just a GDB 3.5
4700 compatibility hack. */
4701 return init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
4702 TYPE_FLAG_UNSIGNED
, NULL
, objfile
);
4705 /* Special case: char is defined (Who knows why) as a subrange of
4706 itself with range 0-127. */
4707 else if (self_subrange
&& n2
== 0 && n3
== 127)
4708 return init_type (TYPE_CODE_INT
, 1, 0, NULL
, objfile
);
4710 else if (current_symbol
&& SYMBOL_LANGUAGE (current_symbol
) == language_chill
4712 goto handle_true_range
;
4714 /* We used to do this only for subrange of self or subrange of int. */
4717 /* -1 is used for the upper bound of (4 byte) "unsigned int" and
4718 "unsigned long", and we already checked for that,
4719 so don't need to test for it here. */
4722 /* n3 actually gives the size. */
4723 return init_type (TYPE_CODE_INT
, -n3
, TYPE_FLAG_UNSIGNED
,
4726 /* Is n3 == 2**(8n)-1 for some integer n? Then it's an
4727 unsigned n-byte integer. But do require n to be a power of
4728 two; we don't want 3- and 5-byte integers flying around. */
4734 for (bytes
= 0; (bits
& 0xff) == 0xff; bytes
++)
4737 && ((bytes
- 1) & bytes
) == 0) /* "bytes is a power of two" */
4738 return init_type (TYPE_CODE_INT
, bytes
, TYPE_FLAG_UNSIGNED
, NULL
,
4742 /* I think this is for Convex "long long". Since I don't know whether
4743 Convex sets self_subrange, I also accept that particular size regardless
4744 of self_subrange. */
4745 else if (n3
== 0 && n2
< 0
4747 || n2
== -TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
))
4748 return init_type (TYPE_CODE_INT
, -n2
, 0, NULL
, objfile
);
4749 else if (n2
== -n3
- 1)
4752 return init_type (TYPE_CODE_INT
, 1, 0, NULL
, objfile
);
4754 return init_type (TYPE_CODE_INT
, 2, 0, NULL
, objfile
);
4755 if (n3
== 0x7fffffff)
4756 return init_type (TYPE_CODE_INT
, 4, 0, NULL
, objfile
);
4759 /* We have a real range type on our hands. Allocate space and
4760 return a real pointer. */
4764 index_type
= builtin_type_int
;
4766 index_type
= *dbx_lookup_type (rangenums
);
4767 if (index_type
== NULL
)
4769 /* Does this actually ever happen? Is that why we are worrying
4770 about dealing with it rather than just calling error_type? */
4772 static struct type
*range_type_index
;
4774 complain (&range_type_base_complaint
, rangenums
[1]);
4775 if (range_type_index
== NULL
)
4777 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
4778 0, "range type index type", NULL
);
4779 index_type
= range_type_index
;
4782 result_type
= create_range_type ((struct type
*) NULL
, index_type
, n2
, n3
);
4783 return (result_type
);
4786 /* Read in an argument list. This is a list of types, separated by commas
4787 and terminated with END. Return the list of types read in, or (struct type
4788 **)-1 if there is an error. */
4790 static struct type
**
4791 read_args (pp
, end
, objfile
)
4794 struct objfile
*objfile
;
4796 /* FIXME! Remove this arbitrary limit! */
4797 struct type
*types
[1024], **rval
; /* allow for fns of 1023 parameters */
4803 /* Invalid argument list: no ','. */
4804 return (struct type
**) -1;
4806 STABS_CONTINUE (pp
, objfile
);
4807 types
[n
++] = read_type (pp
, objfile
);
4809 (*pp
)++; /* get past `end' (the ':' character) */
4813 rval
= (struct type
**) xmalloc (2 * sizeof (struct type
*));
4815 else if (TYPE_CODE (types
[n
- 1]) != TYPE_CODE_VOID
)
4817 rval
= (struct type
**) xmalloc ((n
+ 1) * sizeof (struct type
*));
4818 memset (rval
+ n
, 0, sizeof (struct type
*));
4822 rval
= (struct type
**) xmalloc (n
* sizeof (struct type
*));
4824 memcpy (rval
, types
, n
* sizeof (struct type
*));
4828 /* Common block handling. */
4830 /* List of symbols declared since the last BCOMM. This list is a tail
4831 of local_symbols. When ECOMM is seen, the symbols on the list
4832 are noted so their proper addresses can be filled in later,
4833 using the common block base address gotten from the assembler
4836 static struct pending
*common_block
;
4837 static int common_block_i
;
4839 /* Name of the current common block. We get it from the BCOMM instead of the
4840 ECOMM to match IBM documentation (even though IBM puts the name both places
4841 like everyone else). */
4842 static char *common_block_name
;
4844 /* Process a N_BCOMM symbol. The storage for NAME is not guaranteed
4845 to remain after this function returns. */
4848 common_block_start (name
, objfile
)
4850 struct objfile
*objfile
;
4852 if (common_block_name
!= NULL
)
4854 static struct complaint msg
=
4856 "Invalid symbol data: common block within common block",
4860 common_block
= local_symbols
;
4861 common_block_i
= local_symbols
? local_symbols
->nsyms
: 0;
4862 common_block_name
= obsavestring (name
, strlen (name
),
4863 &objfile
->symbol_obstack
);
4866 /* Process a N_ECOMM symbol. */
4869 common_block_end (objfile
)
4870 struct objfile
*objfile
;
4872 /* Symbols declared since the BCOMM are to have the common block
4873 start address added in when we know it. common_block and
4874 common_block_i point to the first symbol after the BCOMM in
4875 the local_symbols list; copy the list and hang it off the
4876 symbol for the common block name for later fixup. */
4879 struct pending
*new = 0;
4880 struct pending
*next
;
4883 if (common_block_name
== NULL
)
4885 static struct complaint msg
=
4886 {"ECOMM symbol unmatched by BCOMM", 0, 0};
4891 sym
= (struct symbol
*)
4892 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct symbol
));
4893 memset (sym
, 0, sizeof (struct symbol
));
4894 /* Note: common_block_name already saved on symbol_obstack */
4895 SYMBOL_NAME (sym
) = common_block_name
;
4896 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
4898 /* Now we copy all the symbols which have been defined since the BCOMM. */
4900 /* Copy all the struct pendings before common_block. */
4901 for (next
= local_symbols
;
4902 next
!= NULL
&& next
!= common_block
;
4905 for (j
= 0; j
< next
->nsyms
; j
++)
4906 add_symbol_to_list (next
->symbol
[j
], &new);
4909 /* Copy however much of COMMON_BLOCK we need. If COMMON_BLOCK is
4910 NULL, it means copy all the local symbols (which we already did
4913 if (common_block
!= NULL
)
4914 for (j
= common_block_i
; j
< common_block
->nsyms
; j
++)
4915 add_symbol_to_list (common_block
->symbol
[j
], &new);
4917 SYMBOL_TYPE (sym
) = (struct type
*) new;
4919 /* Should we be putting local_symbols back to what it was?
4922 i
= hashname (SYMBOL_NAME (sym
));
4923 SYMBOL_VALUE_CHAIN (sym
) = global_sym_chain
[i
];
4924 global_sym_chain
[i
] = sym
;
4925 common_block_name
= NULL
;
4928 /* Add a common block's start address to the offset of each symbol
4929 declared to be in it (by being between a BCOMM/ECOMM pair that uses
4930 the common block name). */
4933 fix_common_block (sym
, valu
)
4937 struct pending
*next
= (struct pending
*) SYMBOL_TYPE (sym
);
4938 for (; next
; next
= next
->next
)
4941 for (j
= next
->nsyms
- 1; j
>= 0; j
--)
4942 SYMBOL_VALUE_ADDRESS (next
->symbol
[j
]) += valu
;
4948 /* What about types defined as forward references inside of a small lexical
4950 /* Add a type to the list of undefined types to be checked through
4951 once this file has been read in. */
4954 add_undefined_type (type
)
4957 if (undef_types_length
== undef_types_allocated
)
4959 undef_types_allocated
*= 2;
4960 undef_types
= (struct type
**)
4961 xrealloc ((char *) undef_types
,
4962 undef_types_allocated
* sizeof (struct type
*));
4964 undef_types
[undef_types_length
++] = type
;
4967 /* Go through each undefined type, see if it's still undefined, and fix it
4968 up if possible. We have two kinds of undefined types:
4970 TYPE_CODE_ARRAY: Array whose target type wasn't defined yet.
4971 Fix: update array length using the element bounds
4972 and the target type's length.
4973 TYPE_CODE_STRUCT, TYPE_CODE_UNION: Structure whose fields were not
4974 yet defined at the time a pointer to it was made.
4975 Fix: Do a full lookup on the struct/union tag. */
4977 cleanup_undefined_types ()
4981 for (type
= undef_types
; type
< undef_types
+ undef_types_length
; type
++)
4983 switch (TYPE_CODE (*type
))
4986 case TYPE_CODE_STRUCT
:
4987 case TYPE_CODE_UNION
:
4988 case TYPE_CODE_ENUM
:
4990 /* Check if it has been defined since. Need to do this here
4991 as well as in check_typedef to deal with the (legitimate in
4992 C though not C++) case of several types with the same name
4993 in different source files. */
4994 if (TYPE_FLAGS (*type
) & TYPE_FLAG_STUB
)
4996 struct pending
*ppt
;
4998 /* Name of the type, without "struct" or "union" */
4999 char *typename
= TYPE_TAG_NAME (*type
);
5001 if (typename
== NULL
)
5003 static struct complaint msg
=
5004 {"need a type name", 0, 0};
5008 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
5010 for (i
= 0; i
< ppt
->nsyms
; i
++)
5012 struct symbol
*sym
= ppt
->symbol
[i
];
5014 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
5015 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
5016 && (TYPE_CODE (SYMBOL_TYPE (sym
)) ==
5018 && STREQ (SYMBOL_NAME (sym
), typename
))
5020 memcpy (*type
, SYMBOL_TYPE (sym
),
5021 sizeof (struct type
));
5031 static struct complaint msg
=
5033 GDB internal error. cleanup_undefined_types with bad type %d.", 0, 0};
5034 complain (&msg
, TYPE_CODE (*type
));
5040 undef_types_length
= 0;
5043 /* Scan through all of the global symbols defined in the object file,
5044 assigning values to the debugging symbols that need to be assigned
5045 to. Get these symbols from the minimal symbol table. */
5048 scan_file_globals (objfile
)
5049 struct objfile
*objfile
;
5052 struct minimal_symbol
*msymbol
;
5053 struct symbol
*sym
, *prev
, *rsym
;
5054 struct objfile
*resolve_objfile
;
5056 /* SVR4 based linkers copy referenced global symbols from shared
5057 libraries to the main executable.
5058 If we are scanning the symbols for a shared library, try to resolve
5059 them from the minimal symbols of the main executable first. */
5061 if (symfile_objfile
&& objfile
!= symfile_objfile
)
5062 resolve_objfile
= symfile_objfile
;
5064 resolve_objfile
= objfile
;
5068 /* Avoid expensive loop through all minimal symbols if there are
5069 no unresolved symbols. */
5070 for (hash
= 0; hash
< HASHSIZE
; hash
++)
5072 if (global_sym_chain
[hash
])
5075 if (hash
>= HASHSIZE
)
5078 for (msymbol
= resolve_objfile
->msymbols
;
5079 msymbol
&& SYMBOL_NAME (msymbol
) != NULL
;
5084 /* Skip static symbols. */
5085 switch (MSYMBOL_TYPE (msymbol
))
5097 /* Get the hash index and check all the symbols
5098 under that hash index. */
5100 hash
= hashname (SYMBOL_NAME (msymbol
));
5102 for (sym
= global_sym_chain
[hash
]; sym
;)
5104 if (SYMBOL_NAME (msymbol
)[0] == SYMBOL_NAME (sym
)[0] &&
5105 STREQ (SYMBOL_NAME (msymbol
) + 1, SYMBOL_NAME (sym
) + 1))
5108 struct alias_list
*aliases
;
5110 /* Splice this symbol out of the hash chain and
5111 assign the value we have to it. */
5114 SYMBOL_VALUE_CHAIN (prev
) = SYMBOL_VALUE_CHAIN (sym
);
5118 global_sym_chain
[hash
] = SYMBOL_VALUE_CHAIN (sym
);
5121 /* Check to see whether we need to fix up a common block. */
5122 /* Note: this code might be executed several times for
5123 the same symbol if there are multiple references. */
5125 /* If symbol has aliases, do minimal symbol fixups for each.
5126 These live aliases/references weren't added to
5127 global_sym_chain hash but may also need to be fixed up. */
5128 /* FIXME: Maybe should have added aliases to the global chain, resolved symbol name, then treated aliases as normal
5129 symbols? Still, we wouldn't want to add_to_list. */
5130 /* Now do the same for each alias of this symbol */
5132 aliases
= SYMBOL_ALIASES (sym
);
5135 if (SYMBOL_CLASS (rsym
) == LOC_BLOCK
)
5137 fix_common_block (rsym
,
5138 SYMBOL_VALUE_ADDRESS (msymbol
));
5142 SYMBOL_VALUE_ADDRESS (rsym
)
5143 = SYMBOL_VALUE_ADDRESS (msymbol
);
5145 SYMBOL_SECTION (rsym
) = SYMBOL_SECTION (msymbol
);
5148 rsym
= aliases
->sym
;
5149 aliases
= aliases
->next
;
5158 sym
= SYMBOL_VALUE_CHAIN (prev
);
5162 sym
= global_sym_chain
[hash
];
5168 sym
= SYMBOL_VALUE_CHAIN (sym
);
5172 if (resolve_objfile
== objfile
)
5174 resolve_objfile
= objfile
;
5177 /* Change the storage class of any remaining unresolved globals to
5178 LOC_UNRESOLVED and remove them from the chain. */
5179 for (hash
= 0; hash
< HASHSIZE
; hash
++)
5181 sym
= global_sym_chain
[hash
];
5185 sym
= SYMBOL_VALUE_CHAIN (sym
);
5187 /* Change the symbol address from the misleading chain value
5189 SYMBOL_VALUE_ADDRESS (prev
) = 0;
5191 /* Complain about unresolved common block symbols. */
5192 if (SYMBOL_CLASS (prev
) == LOC_STATIC
)
5193 SYMBOL_CLASS (prev
) = LOC_UNRESOLVED
;
5195 complain (&unresolved_sym_chain_complaint
,
5196 objfile
->name
, SYMBOL_NAME (prev
));
5199 memset (global_sym_chain
, 0, sizeof (global_sym_chain
));
5202 /* Initialize anything that needs initializing when starting to read
5203 a fresh piece of a symbol file, e.g. reading in the stuff corresponding
5211 /* Initialize anything that needs initializing when a completely new
5212 symbol file is specified (not just adding some symbols from another
5213 file, e.g. a shared library). */
5216 stabsread_new_init ()
5218 /* Empty the hash table of global syms looking for values. */
5219 memset (global_sym_chain
, 0, sizeof (global_sym_chain
));
5222 /* Initialize anything that needs initializing at the same time as
5223 start_symtab() is called. */
5228 global_stabs
= NULL
; /* AIX COFF */
5229 /* Leave FILENUM of 0 free for builtin types and this file's types. */
5230 n_this_object_header_files
= 1;
5231 type_vector_length
= 0;
5232 type_vector
= (struct type
**) 0;
5234 /* FIXME: If common_block_name is not already NULL, we should complain(). */
5235 common_block_name
= NULL
;
5240 /* Call after end_symtab() */
5247 free ((char *) type_vector
);
5250 type_vector_length
= 0;
5251 previous_stab_code
= 0;
5255 finish_global_stabs (objfile
)
5256 struct objfile
*objfile
;
5260 patch_block_stabs (global_symbols
, global_stabs
, objfile
);
5261 free ((PTR
) global_stabs
);
5262 global_stabs
= NULL
;
5266 /* Initializer for this module */
5269 _initialize_stabsread ()
5271 undef_types_allocated
= 20;
5272 undef_types_length
= 0;
5273 undef_types
= (struct type
**)
5274 xmalloc (undef_types_allocated
* sizeof (struct type
*));