1 /* Support routines for decoding "stabs" debugging information format.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995
3 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21 /* Support routines for reading and decoding debugging information in
22 the "stabs" format. This format is used with many systems that use
23 the a.out object file format, as well as some systems that use
24 COFF or ELF where the stabs data is placed in a special section.
25 Avoid placing any object file format specific code in this file. */
28 #include "gdb_string.h"
33 #include "expression.h"
36 #include "aout/stab_gnu.h" /* We always use GNU stabs, not native */
38 #include "aout/aout64.h"
39 #include "gdb-stabs.h"
41 #include "complaints.h"
47 /* Ask stabsread.h to define the vars it normally declares `extern'. */
49 #include "stabsread.h" /* Our own declarations */
52 /* The routines that read and process a complete stabs for a C struct or
53 C++ class pass lists of data member fields and lists of member function
54 fields in an instance of a field_info structure, as defined below.
55 This is part of some reorganization of low level C++ support and is
56 expected to eventually go away... (FIXME) */
62 struct nextfield *next;
64 /* This is the raw visibility from the stab. It is not checked
65 for being one of the visibilities we recognize, so code which
66 examines this field better be able to deal. */
71 struct next_fnfieldlist
73 struct next_fnfieldlist *next;
74 struct fn_fieldlist fn_fieldlist;
79 dbx_alloc_type PARAMS ((int [2], struct objfile *));
81 static long read_huge_number PARAMS ((char **, int, int *));
83 static struct type *error_type PARAMS ((char **));
86 patch_block_stabs PARAMS ((struct pending *, struct pending_stabs *,
90 fix_common_block PARAMS ((struct symbol *, int));
93 read_type_number PARAMS ((char **, int *));
96 read_range_type PARAMS ((char **, int [2], struct objfile *));
99 read_sun_builtin_type PARAMS ((char **, int [2], struct objfile *));
102 read_sun_floating_type PARAMS ((char **, int [2], struct objfile *));
105 read_enum_type PARAMS ((char **, struct type *, struct objfile *));
108 rs6000_builtin_type PARAMS ((int));
111 read_member_functions PARAMS ((struct field_info *, char **, struct type *,
115 read_struct_fields PARAMS ((struct field_info *, char **, struct type *,
119 read_baseclasses PARAMS ((struct field_info *, char **, struct type *,
123 read_tilde_fields PARAMS ((struct field_info *, char **, struct type *,
127 attach_fn_fields_to_type PARAMS ((struct field_info *, struct type *));
130 attach_fields_to_type PARAMS ((struct field_info *, struct type *,
134 read_struct_type PARAMS ((char **, struct type *, struct objfile *));
137 read_array_type PARAMS ((char **, struct type *, struct objfile *));
139 static struct type **
140 read_args PARAMS ((char **, int, struct objfile *));
143 read_cpp_abbrev PARAMS ((struct field_info *, char **, struct type *,
146 static const char vptr_name[] = { '_','v','p','t','r',CPLUS_MARKER,'\0' };
147 static const char vb_name[] = { '_','v','b',CPLUS_MARKER,'\0' };
149 /* Define this as 1 if a pcc declaration of a char or short argument
150 gives the correct address. Otherwise assume pcc gives the
151 address of the corresponding int, which is not the same on a
152 big-endian machine. */
154 #ifndef BELIEVE_PCC_PROMOTION
155 #define BELIEVE_PCC_PROMOTION 0
158 struct complaint invalid_cpp_abbrev_complaint =
159 {"invalid C++ abbreviation `%s'", 0, 0};
161 struct complaint invalid_cpp_type_complaint =
162 {"C++ abbreviated type name unknown at symtab pos %d", 0, 0};
164 struct complaint member_fn_complaint =
165 {"member function type missing, got '%c'", 0, 0};
167 struct complaint const_vol_complaint =
168 {"const/volatile indicator missing, got '%c'", 0, 0};
170 struct complaint error_type_complaint =
171 {"debug info mismatch between compiler and debugger", 0, 0};
173 struct complaint invalid_member_complaint =
174 {"invalid (minimal) member type data format at symtab pos %d.", 0, 0};
176 struct complaint range_type_base_complaint =
177 {"base type %d of range type is not defined", 0, 0};
179 struct complaint reg_value_complaint =
180 {"register number too large in symbol %s", 0, 0};
182 struct complaint vtbl_notfound_complaint =
183 {"virtual function table pointer not found when defining class `%s'", 0, 0};
185 struct complaint unrecognized_cplus_name_complaint =
186 {"Unknown C++ symbol name `%s'", 0, 0};
188 struct complaint rs6000_builtin_complaint =
189 {"Unknown builtin type %d", 0, 0};
191 struct complaint unresolved_sym_chain_complaint =
192 {"%s: `%s' from global_sym_chain unresolved", 0, 0};
194 struct complaint stabs_general_complaint =
197 /* Make a list of forward references which haven't been defined. */
199 static struct type **undef_types;
200 static int undef_types_allocated;
201 static int undef_types_length;
203 /* Check for and handle cretinous stabs symbol name continuation! */
204 #define STABS_CONTINUE(pp) \
206 if (**(pp) == '\\' || (**(pp) == '?' && (*(pp))[1] == '\0')) \
207 *(pp) = next_symbol_text (); \
210 /* FIXME: These probably should be our own types (like rs6000_builtin_type
211 has its own types) rather than builtin_type_*. */
212 static struct type **os9k_type_vector[] = {
218 &builtin_type_unsigned_char,
219 &builtin_type_unsigned_short,
220 &builtin_type_unsigned_long,
221 &builtin_type_unsigned_int,
223 &builtin_type_double,
225 &builtin_type_long_double
228 static void os9k_init_type_vector PARAMS ((struct type **));
231 os9k_init_type_vector(tv)
235 for (i=0; i<sizeof(os9k_type_vector)/sizeof(struct type **); i++)
236 tv[i] = (os9k_type_vector[i] == 0 ? 0 : *(os9k_type_vector[i]));
239 /* Look up a dbx type-number pair. Return the address of the slot
240 where the type for that number-pair is stored.
241 The number-pair is in TYPENUMS.
243 This can be used for finding the type associated with that pair
244 or for associating a new type with the pair. */
247 dbx_lookup_type (typenums)
250 register int filenum = typenums[0];
251 register int index = typenums[1];
253 register int real_filenum;
254 register struct header_file *f;
257 if (filenum == -1) /* -1,-1 is for temporary types. */
260 if (filenum < 0 || filenum >= n_this_object_header_files)
262 static struct complaint msg = {"\
263 Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.",
265 complain (&msg, filenum, index, symnum);
273 /* Caller wants address of address of type. We think
274 that negative (rs6k builtin) types will never appear as
275 "lvalues", (nor should they), so we stuff the real type
276 pointer into a temp, and return its address. If referenced,
277 this will do the right thing. */
278 static struct type *temp_type;
280 temp_type = rs6000_builtin_type(index);
284 /* Type is defined outside of header files.
285 Find it in this object file's type vector. */
286 if (index >= type_vector_length)
288 old_len = type_vector_length;
291 type_vector_length = INITIAL_TYPE_VECTOR_LENGTH;
292 type_vector = (struct type **)
293 malloc (type_vector_length * sizeof (struct type *));
295 while (index >= type_vector_length)
297 type_vector_length *= 2;
299 type_vector = (struct type **)
300 xrealloc ((char *) type_vector,
301 (type_vector_length * sizeof (struct type *)));
302 memset (&type_vector[old_len], 0,
303 (type_vector_length - old_len) * sizeof (struct type *));
306 /* Deal with OS9000 fundamental types. */
307 os9k_init_type_vector (type_vector);
309 return (&type_vector[index]);
313 real_filenum = this_object_header_files[filenum];
315 if (real_filenum >= n_header_files)
317 struct type *temp_type;
318 struct type **temp_type_p;
320 warning ("GDB internal error: bad real_filenum");
323 temp_type = init_type (TYPE_CODE_ERROR, 0, 0, NULL, NULL);
324 temp_type_p = (struct type **) xmalloc (sizeof (struct type *));
325 *temp_type_p = temp_type;
329 f = &header_files[real_filenum];
331 f_orig_length = f->length;
332 if (index >= f_orig_length)
334 while (index >= f->length)
338 f->vector = (struct type **)
339 xrealloc ((char *) f->vector, f->length * sizeof (struct type *));
340 memset (&f->vector[f_orig_length], 0,
341 (f->length - f_orig_length) * sizeof (struct type *));
343 return (&f->vector[index]);
347 /* Make sure there is a type allocated for type numbers TYPENUMS
348 and return the type object.
349 This can create an empty (zeroed) type object.
350 TYPENUMS may be (-1, -1) to return a new type object that is not
351 put into the type vector, and so may not be referred to by number. */
354 dbx_alloc_type (typenums, objfile)
356 struct objfile *objfile;
358 register struct type **type_addr;
360 if (typenums[0] == -1)
362 return (alloc_type (objfile));
365 type_addr = dbx_lookup_type (typenums);
367 /* If we are referring to a type not known at all yet,
368 allocate an empty type for it.
369 We will fill it in later if we find out how. */
372 *type_addr = alloc_type (objfile);
378 /* for all the stabs in a given stab vector, build appropriate types
379 and fix their symbols in given symbol vector. */
382 patch_block_stabs (symbols, stabs, objfile)
383 struct pending *symbols;
384 struct pending_stabs *stabs;
385 struct objfile *objfile;
395 /* for all the stab entries, find their corresponding symbols and
396 patch their types! */
398 for (ii = 0; ii < stabs->count; ++ii)
400 name = stabs->stab[ii];
401 pp = (char*) strchr (name, ':');
405 pp = (char *)strchr(pp, ':');
407 sym = find_symbol_in_list (symbols, name, pp-name);
410 /* FIXME-maybe: it would be nice if we noticed whether
411 the variable was defined *anywhere*, not just whether
412 it is defined in this compilation unit. But neither
413 xlc or GCC seem to need such a definition, and until
414 we do psymtabs (so that the minimal symbols from all
415 compilation units are available now), I'm not sure
416 how to get the information. */
418 /* On xcoff, if a global is defined and never referenced,
419 ld will remove it from the executable. There is then
420 a N_GSYM stab for it, but no regular (C_EXT) symbol. */
421 sym = (struct symbol *)
422 obstack_alloc (&objfile->symbol_obstack,
423 sizeof (struct symbol));
425 memset (sym, 0, sizeof (struct symbol));
426 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
427 SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
429 obstack_copy0 (&objfile->symbol_obstack, name, pp - name);
431 if (*(pp-1) == 'F' || *(pp-1) == 'f')
433 /* I don't think the linker does this with functions,
434 so as far as I know this is never executed.
435 But it doesn't hurt to check. */
437 lookup_function_type (read_type (&pp, objfile));
441 SYMBOL_TYPE (sym) = read_type (&pp, objfile);
443 add_symbol_to_list (sym, &global_symbols);
448 if (*(pp-1) == 'F' || *(pp-1) == 'f')
451 lookup_function_type (read_type (&pp, objfile));
455 SYMBOL_TYPE (sym) = read_type (&pp, objfile);
463 /* Read a number by which a type is referred to in dbx data,
464 or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
465 Just a single number N is equivalent to (0,N).
466 Return the two numbers by storing them in the vector TYPENUMS.
467 TYPENUMS will then be used as an argument to dbx_lookup_type.
469 Returns 0 for success, -1 for error. */
472 read_type_number (pp, typenums)
474 register int *typenums;
480 typenums[0] = read_huge_number (pp, ',', &nbits);
481 if (nbits != 0) return -1;
482 typenums[1] = read_huge_number (pp, ')', &nbits);
483 if (nbits != 0) return -1;
488 typenums[1] = read_huge_number (pp, 0, &nbits);
489 if (nbits != 0) return -1;
495 /* To handle GNU C++ typename abbreviation, we need to be able to
496 fill in a type's name as soon as space for that type is allocated.
497 `type_synonym_name' is the name of the type being allocated.
498 It is cleared as soon as it is used (lest all allocated types
501 static char *type_synonym_name;
503 #if !defined (REG_STRUCT_HAS_ADDR)
504 #define REG_STRUCT_HAS_ADDR(gcc_p,type) 0
509 define_symbol (valu, string, desc, type, objfile)
514 struct objfile *objfile;
516 register struct symbol *sym;
517 char *p = (char *) strchr (string, ':');
522 /* We would like to eliminate nameless symbols, but keep their types.
523 E.g. stab entry ":t10=*2" should produce a type 10, which is a pointer
524 to type 2, but, should not create a symbol to address that type. Since
525 the symbol will be nameless, there is no way any user can refer to it. */
529 /* Ignore syms with empty names. */
533 /* Ignore old-style symbols from cc -go */
543 /* If a nameless stab entry, all we need is the type, not the symbol.
544 e.g. ":t10=*2" or a nameless enum like " :T16=ered:0,green:1,blue:2,;" */
545 nameless = (p == string || ((string[0] == ' ') && (string[1] == ':')));
547 sym = (struct symbol *)
548 obstack_alloc (&objfile -> symbol_obstack, sizeof (struct symbol));
549 memset (sym, 0, sizeof (struct symbol));
551 switch (type & N_TYPE)
554 SYMBOL_SECTION(sym) = SECT_OFF_TEXT;
557 SYMBOL_SECTION(sym) = SECT_OFF_DATA;
560 SYMBOL_SECTION(sym) = SECT_OFF_BSS;
564 if (processing_gcc_compilation)
566 /* GCC 2.x puts the line number in desc. SunOS apparently puts in the
567 number of bytes occupied by a type or object, which we ignore. */
568 SYMBOL_LINE(sym) = desc;
572 SYMBOL_LINE(sym) = 0; /* unknown */
575 if (string[0] == CPLUS_MARKER)
577 /* Special GNU C++ names. */
581 SYMBOL_NAME (sym) = obsavestring ("this", strlen ("this"),
582 &objfile -> symbol_obstack);
585 case 'v': /* $vtbl_ptr_type */
586 /* Was: SYMBOL_NAME (sym) = "vptr"; */
590 SYMBOL_NAME (sym) = obsavestring ("eh_throw", strlen ("eh_throw"),
591 &objfile -> symbol_obstack);
595 /* This was an anonymous type that was never fixed up. */
598 #ifdef STATIC_TRANSFORM_NAME
600 /* SunPRO (3.0 at least) static variable encoding. */
605 complain (&unrecognized_cplus_name_complaint, string);
606 goto normal; /* Do *something* with it */
612 SYMBOL_LANGUAGE (sym) = current_subfile -> language;
613 SYMBOL_NAME (sym) = (char *)
614 obstack_alloc (&objfile -> symbol_obstack, ((p - string) + 1));
615 /* Open-coded memcpy--saves function call time. */
616 /* FIXME: Does it really? Try replacing with simple strcpy and
617 try it on an executable with a large symbol table. */
618 /* FIXME: considering that gcc can open code memcpy anyway, I
619 doubt it. xoxorich. */
621 register char *p1 = string;
622 register char *p2 = SYMBOL_NAME (sym);
630 /* If this symbol is from a C++ compilation, then attempt to cache the
631 demangled form for future reference. This is a typical time versus
632 space tradeoff, that was decided in favor of time because it sped up
633 C++ symbol lookups by a factor of about 20. */
635 SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->symbol_obstack);
639 /* Determine the type of name being defined. */
641 /* Getting GDB to correctly skip the symbol on an undefined symbol
642 descriptor and not ever dump core is a very dodgy proposition if
643 we do things this way. I say the acorn RISC machine can just
644 fix their compiler. */
645 /* The Acorn RISC machine's compiler can put out locals that don't
646 start with "234=" or "(3,4)=", so assume anything other than the
647 deftypes we know how to handle is a local. */
648 if (!strchr ("cfFGpPrStTvVXCR", *p))
650 if (isdigit (*p) || *p == '(' || *p == '-')
659 /* c is a special case, not followed by a type-number.
660 SYMBOL:c=iVALUE for an integer constant symbol.
661 SYMBOL:c=rVALUE for a floating constant symbol.
662 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
663 e.g. "b:c=e6,0" for "const b = blob1"
664 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
667 SYMBOL_CLASS (sym) = LOC_CONST;
668 SYMBOL_TYPE (sym) = error_type (&p);
669 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
670 add_symbol_to_list (sym, &file_symbols);
681 /* FIXME-if-picky-about-floating-accuracy: Should be using
682 target arithmetic to get the value. real.c in GCC
683 probably has the necessary code. */
685 /* FIXME: lookup_fundamental_type is a hack. We should be
686 creating a type especially for the type of float constants.
687 Problem is, what type should it be?
689 Also, what should the name of this type be? Should we
690 be using 'S' constants (see stabs.texinfo) instead? */
692 SYMBOL_TYPE (sym) = lookup_fundamental_type (objfile,
695 obstack_alloc (&objfile -> symbol_obstack,
696 TYPE_LENGTH (SYMBOL_TYPE (sym)));
697 store_floating (dbl_valu, TYPE_LENGTH (SYMBOL_TYPE (sym)), d);
698 SYMBOL_VALUE_BYTES (sym) = dbl_valu;
699 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
704 /* Defining integer constants this way is kind of silly,
705 since 'e' constants allows the compiler to give not
706 only the value, but the type as well. C has at least
707 int, long, unsigned int, and long long as constant
708 types; other languages probably should have at least
709 unsigned as well as signed constants. */
711 /* We just need one int constant type for all objfiles.
712 It doesn't depend on languages or anything (arguably its
713 name should be a language-specific name for a type of
714 that size, but I'm inclined to say that if the compiler
715 wants a nice name for the type, it can use 'e'). */
716 static struct type *int_const_type;
718 /* Yes, this is as long as a *host* int. That is because we
720 if (int_const_type == NULL)
722 init_type (TYPE_CODE_INT,
723 sizeof (int) * HOST_CHAR_BIT / TARGET_CHAR_BIT, 0,
725 (struct objfile *)NULL);
726 SYMBOL_TYPE (sym) = int_const_type;
727 SYMBOL_VALUE (sym) = atoi (p);
728 SYMBOL_CLASS (sym) = LOC_CONST;
732 /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value
733 can be represented as integral.
734 e.g. "b:c=e6,0" for "const b = blob1"
735 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
737 SYMBOL_CLASS (sym) = LOC_CONST;
738 SYMBOL_TYPE (sym) = read_type (&p, objfile);
742 SYMBOL_TYPE (sym) = error_type (&p);
747 /* If the value is too big to fit in an int (perhaps because
748 it is unsigned), or something like that, we silently get
749 a bogus value. The type and everything else about it is
750 correct. Ideally, we should be using whatever we have
751 available for parsing unsigned and long long values,
753 SYMBOL_VALUE (sym) = atoi (p);
758 SYMBOL_CLASS (sym) = LOC_CONST;
759 SYMBOL_TYPE (sym) = error_type (&p);
762 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
763 add_symbol_to_list (sym, &file_symbols);
767 /* The name of a caught exception. */
768 SYMBOL_TYPE (sym) = read_type (&p, objfile);
769 SYMBOL_CLASS (sym) = LOC_LABEL;
770 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
771 SYMBOL_VALUE_ADDRESS (sym) = valu;
772 add_symbol_to_list (sym, &local_symbols);
776 /* A static function definition. */
777 SYMBOL_TYPE (sym) = read_type (&p, objfile);
778 SYMBOL_CLASS (sym) = LOC_BLOCK;
779 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
780 add_symbol_to_list (sym, &file_symbols);
781 /* fall into process_function_types. */
783 process_function_types:
784 /* Function result types are described as the result type in stabs.
785 We need to convert this to the function-returning-type-X type
786 in GDB. E.g. "int" is converted to "function returning int". */
787 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_FUNC)
788 SYMBOL_TYPE (sym) = lookup_function_type (SYMBOL_TYPE (sym));
789 /* fall into process_prototype_types */
791 process_prototype_types:
792 /* Sun acc puts declared types of arguments here. We don't care
793 about their actual types (FIXME -- we should remember the whole
794 function prototype), but the list may define some new types
795 that we have to remember, so we must scan it now. */
798 read_type (&p, objfile);
803 /* A global function definition. */
804 SYMBOL_TYPE (sym) = read_type (&p, objfile);
805 SYMBOL_CLASS (sym) = LOC_BLOCK;
806 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
807 add_symbol_to_list (sym, &global_symbols);
808 goto process_function_types;
811 /* For a class G (global) symbol, it appears that the
812 value is not correct. It is necessary to search for the
813 corresponding linker definition to find the value.
814 These definitions appear at the end of the namelist. */
815 SYMBOL_TYPE (sym) = read_type (&p, objfile);
816 i = hashname (SYMBOL_NAME (sym));
817 SYMBOL_VALUE_CHAIN (sym) = global_sym_chain[i];
818 global_sym_chain[i] = sym;
819 SYMBOL_CLASS (sym) = LOC_STATIC;
820 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
821 add_symbol_to_list (sym, &global_symbols);
824 /* This case is faked by a conditional above,
825 when there is no code letter in the dbx data.
826 Dbx data never actually contains 'l'. */
829 SYMBOL_TYPE (sym) = read_type (&p, objfile);
830 SYMBOL_CLASS (sym) = LOC_LOCAL;
831 SYMBOL_VALUE (sym) = valu;
832 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
833 add_symbol_to_list (sym, &local_symbols);
838 /* pF is a two-letter code that means a function parameter in Fortran.
839 The type-number specifies the type of the return value.
840 Translate it into a pointer-to-function type. */
844 = lookup_pointer_type
845 (lookup_function_type (read_type (&p, objfile)));
848 SYMBOL_TYPE (sym) = read_type (&p, objfile);
850 /* Normally this is a parameter, a LOC_ARG. On the i960, it
851 can also be a LOC_LOCAL_ARG depending on symbol type. */
852 #ifndef DBX_PARM_SYMBOL_CLASS
853 #define DBX_PARM_SYMBOL_CLASS(type) LOC_ARG
856 SYMBOL_CLASS (sym) = DBX_PARM_SYMBOL_CLASS (type);
857 SYMBOL_VALUE (sym) = valu;
858 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
859 add_symbol_to_list (sym, &local_symbols);
861 if (TARGET_BYTE_ORDER != BIG_ENDIAN)
863 /* On little-endian machines, this crud is never necessary,
864 and, if the extra bytes contain garbage, is harmful. */
868 /* If it's gcc-compiled, if it says `short', believe it. */
869 if (processing_gcc_compilation || BELIEVE_PCC_PROMOTION)
872 #if !BELIEVE_PCC_PROMOTION
874 /* This is the signed type which arguments get promoted to. */
875 static struct type *pcc_promotion_type;
876 /* This is the unsigned type which arguments get promoted to. */
877 static struct type *pcc_unsigned_promotion_type;
879 /* Call it "int" because this is mainly C lossage. */
880 if (pcc_promotion_type == NULL)
882 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
885 if (pcc_unsigned_promotion_type == NULL)
886 pcc_unsigned_promotion_type =
887 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
888 TYPE_FLAG_UNSIGNED, "unsigned int", NULL);
890 #if defined(BELIEVE_PCC_PROMOTION_TYPE)
891 /* This macro is defined on machines (e.g. sparc) where
892 we should believe the type of a PCC 'short' argument,
893 but shouldn't believe the address (the address is
894 the address of the corresponding int).
896 My guess is that this correction, as opposed to changing
897 the parameter to an 'int' (as done below, for PCC
898 on most machines), is the right thing to do
899 on all machines, but I don't want to risk breaking
900 something that already works. On most PCC machines,
901 the sparc problem doesn't come up because the calling
902 function has to zero the top bytes (not knowing whether
903 the called function wants an int or a short), so there
904 is little practical difference between an int and a short
905 (except perhaps what happens when the GDB user types
906 "print short_arg = 0x10000;").
909 actually produces the correct address (we don't need to fix it
910 up). I made this code adapt so that it will offset the symbol
911 if it was pointing at an int-aligned location and not
912 otherwise. This way you can use the same gdb for 4.0.x and
915 If the parameter is shorter than an int, and is integral
916 (e.g. char, short, or unsigned equivalent), and is claimed to
917 be passed on an integer boundary, don't believe it! Offset the
918 parameter's address to the tail-end of that integer. */
920 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) < TYPE_LENGTH (pcc_promotion_type)
921 && TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_INT
922 && 0 == SYMBOL_VALUE (sym) % TYPE_LENGTH (pcc_promotion_type))
924 SYMBOL_VALUE (sym) += TYPE_LENGTH (pcc_promotion_type)
925 - TYPE_LENGTH (SYMBOL_TYPE (sym));
929 #else /* no BELIEVE_PCC_PROMOTION_TYPE. */
931 /* If PCC says a parameter is a short or a char,
932 it is really an int. */
933 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) < TYPE_LENGTH (pcc_promotion_type)
934 && TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_INT)
937 TYPE_UNSIGNED (SYMBOL_TYPE (sym))
938 ? pcc_unsigned_promotion_type
939 : pcc_promotion_type;
943 #endif /* no BELIEVE_PCC_PROMOTION_TYPE. */
945 #endif /* !BELIEVE_PCC_PROMOTION. */
948 /* acc seems to use P to delare the prototypes of functions that
949 are referenced by this file. gdb is not prepared to deal
950 with this extra information. FIXME, it ought to. */
953 read_type (&p, objfile);
954 goto process_prototype_types;
959 /* Parameter which is in a register. */
960 SYMBOL_TYPE (sym) = read_type (&p, objfile);
961 SYMBOL_CLASS (sym) = LOC_REGPARM;
962 SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
963 if (SYMBOL_VALUE (sym) >= NUM_REGS)
965 complain (®_value_complaint, SYMBOL_SOURCE_NAME (sym));
966 SYMBOL_VALUE (sym) = SP_REGNUM; /* Known safe, though useless */
968 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
969 add_symbol_to_list (sym, &local_symbols);
973 /* Register variable (either global or local). */
974 SYMBOL_TYPE (sym) = read_type (&p, objfile);
975 SYMBOL_CLASS (sym) = LOC_REGISTER;
976 SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
977 if (SYMBOL_VALUE (sym) >= NUM_REGS)
979 complain (®_value_complaint, SYMBOL_SOURCE_NAME (sym));
980 SYMBOL_VALUE (sym) = SP_REGNUM; /* Known safe, though useless */
982 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
985 /* Sun cc uses a pair of symbols, one 'p' and one 'r' with the same
986 name to represent an argument passed in a register.
987 GCC uses 'P' for the same case. So if we find such a symbol pair
988 we combine it into one 'P' symbol. For Sun cc we need to do this
989 regardless of REG_STRUCT_HAS_ADDR, because the compiler puts out
990 the 'p' symbol even if it never saves the argument onto the stack.
992 On most machines, we want to preserve both symbols, so that
993 we can still get information about what is going on with the
994 stack (VAX for computing args_printed, using stack slots instead
995 of saved registers in backtraces, etc.).
997 Note that this code illegally combines
998 main(argc) struct foo argc; { register struct foo argc; }
999 but this case is considered pathological and causes a warning
1000 from a decent compiler. */
1003 && local_symbols->nsyms > 0
1004 #ifndef USE_REGISTER_NOT_ARG
1005 && REG_STRUCT_HAS_ADDR (processing_gcc_compilation,
1007 && (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
1008 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION)
1012 struct symbol *prev_sym;
1013 prev_sym = local_symbols->symbol[local_symbols->nsyms - 1];
1014 if ((SYMBOL_CLASS (prev_sym) == LOC_REF_ARG
1015 || SYMBOL_CLASS (prev_sym) == LOC_ARG)
1016 && STREQ (SYMBOL_NAME (prev_sym), SYMBOL_NAME(sym)))
1018 SYMBOL_CLASS (prev_sym) = LOC_REGPARM;
1019 /* Use the type from the LOC_REGISTER; that is the type
1020 that is actually in that register. */
1021 SYMBOL_TYPE (prev_sym) = SYMBOL_TYPE (sym);
1022 SYMBOL_VALUE (prev_sym) = SYMBOL_VALUE (sym);
1027 add_symbol_to_list (sym, &local_symbols);
1030 add_symbol_to_list (sym, &file_symbols);
1034 /* Static symbol at top level of file */
1035 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1036 SYMBOL_CLASS (sym) = LOC_STATIC;
1037 SYMBOL_VALUE_ADDRESS (sym) = valu;
1038 #ifdef STATIC_TRANSFORM_NAME
1039 if (SYMBOL_NAME (sym)[0] == '$')
1041 struct minimal_symbol *msym;
1042 msym = lookup_minimal_symbol (SYMBOL_NAME (sym), NULL, objfile);
1045 SYMBOL_NAME (sym) = STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym));
1046 SYMBOL_VALUE_ADDRESS (sym) = SYMBOL_VALUE_ADDRESS (msym);
1050 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1051 add_symbol_to_list (sym, &file_symbols);
1055 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1057 /* For a nameless type, we don't want a create a symbol, thus we
1058 did not use `sym'. Return without further processing. */
1059 if (nameless) return NULL;
1061 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1062 SYMBOL_VALUE (sym) = valu;
1063 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1064 /* C++ vagaries: we may have a type which is derived from
1065 a base type which did not have its name defined when the
1066 derived class was output. We fill in the derived class's
1067 base part member's name here in that case. */
1068 if (TYPE_NAME (SYMBOL_TYPE (sym)) != NULL)
1069 if ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
1070 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION)
1071 && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)))
1074 for (j = TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)) - 1; j >= 0; j--)
1075 if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) == 0)
1076 TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) =
1077 type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym), j));
1080 if (TYPE_NAME (SYMBOL_TYPE (sym)) == NULL)
1082 /* gcc-2.6 or later (when using -fvtable-thunks)
1083 emits a unique named type for a vtable entry.
1084 Some gdb code depends on that specific name. */
1085 extern const char vtbl_ptr_name[];
1087 if ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_PTR
1088 && strcmp (SYMBOL_NAME (sym), vtbl_ptr_name))
1089 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_FUNC)
1091 /* If we are giving a name to a type such as "pointer to
1092 foo" or "function returning foo", we better not set
1093 the TYPE_NAME. If the program contains "typedef char
1094 *caddr_t;", we don't want all variables of type char
1095 * to print as caddr_t. This is not just a
1096 consequence of GDB's type management; PCC and GCC (at
1097 least through version 2.4) both output variables of
1098 either type char * or caddr_t with the type number
1099 defined in the 't' symbol for caddr_t. If a future
1100 compiler cleans this up it GDB is not ready for it
1101 yet, but if it becomes ready we somehow need to
1102 disable this check (without breaking the PCC/GCC2.4
1107 Fortunately, this check seems not to be necessary
1108 for anything except pointers or functions. */
1111 TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_NAME (sym);
1114 add_symbol_to_list (sym, &file_symbols);
1118 /* Struct, union, or enum tag. For GNU C++, this can be be followed
1119 by 't' which means we are typedef'ing it as well. */
1120 synonym = *p == 't';
1125 type_synonym_name = obsavestring (SYMBOL_NAME (sym),
1126 strlen (SYMBOL_NAME (sym)),
1127 &objfile -> symbol_obstack);
1129 /* The semantics of C++ state that "struct foo { ... }" also defines
1130 a typedef for "foo". Unfortunately, cfront never makes the typedef
1131 when translating C++ into C. We make the typedef here so that
1132 "ptype foo" works as expected for cfront translated code. */
1133 else if (current_subfile->language == language_cplus)
1136 type_synonym_name = obsavestring (SYMBOL_NAME (sym),
1137 strlen (SYMBOL_NAME (sym)),
1138 &objfile -> symbol_obstack);
1141 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1143 /* For a nameless type, we don't want a create a symbol, thus we
1144 did not use `sym'. Return without further processing. */
1145 if (nameless) return NULL;
1147 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1148 SYMBOL_VALUE (sym) = valu;
1149 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
1150 if (TYPE_TAG_NAME (SYMBOL_TYPE (sym)) == 0)
1151 TYPE_TAG_NAME (SYMBOL_TYPE (sym))
1152 = obconcat (&objfile -> type_obstack, "", "", SYMBOL_NAME (sym));
1153 add_symbol_to_list (sym, &file_symbols);
1157 /* Clone the sym and then modify it. */
1158 register struct symbol *typedef_sym = (struct symbol *)
1159 obstack_alloc (&objfile -> symbol_obstack, sizeof (struct symbol));
1160 *typedef_sym = *sym;
1161 SYMBOL_CLASS (typedef_sym) = LOC_TYPEDEF;
1162 SYMBOL_VALUE (typedef_sym) = valu;
1163 SYMBOL_NAMESPACE (typedef_sym) = VAR_NAMESPACE;
1164 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
1165 TYPE_NAME (SYMBOL_TYPE (sym))
1166 = obconcat (&objfile -> type_obstack, "", "", SYMBOL_NAME (sym));
1167 add_symbol_to_list (typedef_sym, &file_symbols);
1172 /* Static symbol of local scope */
1173 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1174 SYMBOL_CLASS (sym) = LOC_STATIC;
1175 SYMBOL_VALUE_ADDRESS (sym) = valu;
1176 #ifdef STATIC_TRANSFORM_NAME
1177 if (SYMBOL_NAME (sym)[0] == '$')
1179 struct minimal_symbol *msym;
1180 msym = lookup_minimal_symbol (SYMBOL_NAME (sym), NULL, objfile);
1183 SYMBOL_NAME (sym) = STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym));
1184 SYMBOL_VALUE_ADDRESS (sym) = SYMBOL_VALUE_ADDRESS (msym);
1188 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1190 add_symbol_to_list (sym, &global_symbols);
1192 add_symbol_to_list (sym, &local_symbols);
1196 /* Reference parameter */
1197 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1198 SYMBOL_CLASS (sym) = LOC_REF_ARG;
1199 SYMBOL_VALUE (sym) = valu;
1200 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1201 add_symbol_to_list (sym, &local_symbols);
1205 /* Reference parameter which is in a register. */
1206 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1207 SYMBOL_CLASS (sym) = LOC_REGPARM_ADDR;
1208 SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
1209 if (SYMBOL_VALUE (sym) >= NUM_REGS)
1211 complain (®_value_complaint, SYMBOL_SOURCE_NAME (sym));
1212 SYMBOL_VALUE (sym) = SP_REGNUM; /* Known safe, though useless */
1214 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1215 add_symbol_to_list (sym, &local_symbols);
1219 /* This is used by Sun FORTRAN for "function result value".
1220 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
1221 that Pascal uses it too, but when I tried it Pascal used
1222 "x:3" (local symbol) instead. */
1223 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1224 SYMBOL_CLASS (sym) = LOC_LOCAL;
1225 SYMBOL_VALUE (sym) = valu;
1226 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1227 add_symbol_to_list (sym, &local_symbols);
1231 SYMBOL_TYPE (sym) = error_type (&p);
1232 SYMBOL_CLASS (sym) = LOC_CONST;
1233 SYMBOL_VALUE (sym) = 0;
1234 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1235 add_symbol_to_list (sym, &file_symbols);
1239 /* When passing structures to a function, some systems sometimes pass
1240 the address in a register, not the structure itself.
1242 If REG_STRUCT_HAS_ADDR yields non-zero we have to convert LOC_REGPARM
1243 to LOC_REGPARM_ADDR for structures and unions. */
1245 if (SYMBOL_CLASS (sym) == LOC_REGPARM
1246 && REG_STRUCT_HAS_ADDR (processing_gcc_compilation,
1248 && ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT)
1249 || (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION)))
1250 SYMBOL_CLASS (sym) = LOC_REGPARM_ADDR;
1252 /* Likewise for converting LOC_ARG to LOC_REF_ARG (for the 7th and
1253 subsequent arguments on the sparc, for example). */
1254 if (SYMBOL_CLASS (sym) == LOC_ARG
1255 && REG_STRUCT_HAS_ADDR (processing_gcc_compilation,
1257 && ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT)
1258 || (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION)))
1259 SYMBOL_CLASS (sym) = LOC_REF_ARG;
1265 /* Skip rest of this symbol and return an error type.
1267 General notes on error recovery: error_type always skips to the
1268 end of the symbol (modulo cretinous dbx symbol name continuation).
1269 Thus code like this:
1271 if (*(*pp)++ != ';')
1272 return error_type (pp);
1274 is wrong because if *pp starts out pointing at '\0' (typically as the
1275 result of an earlier error), it will be incremented to point to the
1276 start of the next symbol, which might produce strange results, at least
1277 if you run off the end of the string table. Instead use
1280 return error_type (pp);
1286 foo = error_type (pp);
1290 And in case it isn't obvious, the point of all this hair is so the compiler
1291 can define new types and new syntaxes, and old versions of the
1292 debugger will be able to read the new symbol tables. */
1294 static struct type *
1298 complain (&error_type_complaint);
1301 /* Skip to end of symbol. */
1302 while (**pp != '\0')
1307 /* Check for and handle cretinous dbx symbol name continuation! */
1308 if ((*pp)[-1] == '\\' || (*pp)[-1] == '?')
1310 *pp = next_symbol_text ();
1317 return (builtin_type_error);
1321 /* Read type information or a type definition; return the type. Even
1322 though this routine accepts either type information or a type
1323 definition, the distinction is relevant--some parts of stabsread.c
1324 assume that type information starts with a digit, '-', or '(' in
1325 deciding whether to call read_type. */
1328 read_type (pp, objfile)
1330 struct objfile *objfile;
1332 register struct type *type = 0;
1336 char type_descriptor;
1338 /* Size in bits of type if specified by a type attribute, or -1 if
1339 there is no size attribute. */
1342 /* Used to distinguish string and bitstring from char-array and set. */
1345 /* Read type number if present. The type number may be omitted.
1346 for instance in a two-dimensional array declared with type
1347 "ar1;1;10;ar1;1;10;4". */
1348 if ((**pp >= '0' && **pp <= '9')
1352 if (read_type_number (pp, typenums) != 0)
1353 return error_type (pp);
1355 /* Type is not being defined here. Either it already exists,
1356 or this is a forward reference to it. dbx_alloc_type handles
1359 return dbx_alloc_type (typenums, objfile);
1361 /* Type is being defined here. */
1368 /* It might be a type attribute or a member type. */
1369 if (isdigit (*p) || *p == '(' || *p == '-')
1374 /* Type attributes. */
1377 /* Skip to the semicolon. */
1378 while (*p != ';' && *p != '\0')
1382 return error_type (pp);
1384 /* Skip the semicolon. */
1390 type_size = atoi (attr + 1);
1400 /* Ignore unrecognized type attributes, so future compilers
1401 can invent new ones. */
1406 /* Skip the type descriptor, we get it below with (*pp)[-1]. */
1411 /* 'typenums=' not present, type is anonymous. Read and return
1412 the definition, but don't put it in the type vector. */
1413 typenums[0] = typenums[1] = -1;
1417 type_descriptor = (*pp)[-1];
1418 switch (type_descriptor)
1422 enum type_code code;
1424 /* Used to index through file_symbols. */
1425 struct pending *ppt;
1428 /* Name including "struct", etc. */
1432 char *from, *to, *p, *q1, *q2;
1434 /* Set the type code according to the following letter. */
1438 code = TYPE_CODE_STRUCT;
1441 code = TYPE_CODE_UNION;
1444 code = TYPE_CODE_ENUM;
1448 /* Complain and keep going, so compilers can invent new
1449 cross-reference types. */
1450 static struct complaint msg =
1451 {"Unrecognized cross-reference type `%c'", 0, 0};
1452 complain (&msg, (*pp)[0]);
1453 code = TYPE_CODE_STRUCT;
1458 q1 = strchr(*pp, '<');
1459 p = strchr(*pp, ':');
1461 return error_type (pp);
1462 while (q1 && p > q1 && p[1] == ':')
1464 q2 = strchr(q1, '>');
1470 return error_type (pp);
1473 (char *)obstack_alloc (&objfile->type_obstack, p - *pp + 1);
1475 /* Copy the name. */
1481 /* Set the pointer ahead of the name which we just read, and
1486 /* Now check to see whether the type has already been
1487 declared. This was written for arrays of cross-referenced
1488 types before we had TYPE_CODE_TARGET_STUBBED, so I'm pretty
1489 sure it is not necessary anymore. But it might be a good
1490 idea, to save a little memory. */
1492 for (ppt = file_symbols; ppt; ppt = ppt->next)
1493 for (i = 0; i < ppt->nsyms; i++)
1495 struct symbol *sym = ppt->symbol[i];
1497 if (SYMBOL_CLASS (sym) == LOC_TYPEDEF
1498 && SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE
1499 && (TYPE_CODE (SYMBOL_TYPE (sym)) == code)
1500 && STREQ (SYMBOL_NAME (sym), type_name))
1502 obstack_free (&objfile -> type_obstack, type_name);
1503 type = SYMBOL_TYPE (sym);
1508 /* Didn't find the type to which this refers, so we must
1509 be dealing with a forward reference. Allocate a type
1510 structure for it, and keep track of it so we can
1511 fill in the rest of the fields when we get the full
1513 type = dbx_alloc_type (typenums, objfile);
1514 TYPE_CODE (type) = code;
1515 TYPE_TAG_NAME (type) = type_name;
1516 INIT_CPLUS_SPECIFIC(type);
1517 TYPE_FLAGS (type) |= TYPE_FLAG_STUB;
1519 add_undefined_type (type);
1523 case '-': /* RS/6000 built-in type */
1542 /* Peek ahead at the number to detect void. */
1543 if (read_type_number (pp, xtypenums) != 0)
1544 return error_type (pp);
1546 if (typenums[0] == xtypenums[0] && typenums[1] == xtypenums[1])
1547 /* It's being defined as itself. That means it is "void". */
1548 type = init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile);
1553 /* Go back to the number and have read_type get it. This means
1554 that we can deal with something like t(1,2)=(3,4)=... which
1555 the Lucid compiler uses. */
1557 xtype = read_type (pp, objfile);
1559 /* The type is being defined to another type. So we copy the type.
1560 This loses if we copy a C++ class and so we lose track of how
1561 the names are mangled (but g++ doesn't output stabs like this
1564 type = alloc_type (objfile);
1565 memcpy (type, xtype, sizeof (struct type));
1567 /* The idea behind clearing the names is that the only purpose
1568 for defining a type to another type is so that the name of
1569 one can be different. So we probably don't need to worry much
1570 about the case where the compiler doesn't give a name to the
1572 TYPE_NAME (type) = NULL;
1573 TYPE_TAG_NAME (type) = NULL;
1575 if (typenums[0] != -1)
1576 *dbx_lookup_type (typenums) = type;
1580 /* In the following types, we must be sure to overwrite any existing
1581 type that the typenums refer to, rather than allocating a new one
1582 and making the typenums point to the new one. This is because there
1583 may already be pointers to the existing type (if it had been
1584 forward-referenced), and we must change it to a pointer, function,
1585 reference, or whatever, *in-place*. */
1588 type1 = read_type (pp, objfile);
1589 type = make_pointer_type (type1, dbx_lookup_type (typenums));
1592 case '&': /* Reference to another type */
1593 type1 = read_type (pp, objfile);
1594 type = make_reference_type (type1, dbx_lookup_type (typenums));
1597 case 'f': /* Function returning another type */
1598 if (os9k_stabs && **pp == '(')
1600 /* Function prototype; parse it.
1601 We must conditionalize this on os9k_stabs because otherwise
1602 it could be confused with a Sun-style (1,3) typenumber
1608 t = read_type(pp, objfile);
1609 if (**pp == ',') ++*pp;
1612 type1 = read_type (pp, objfile);
1613 type = make_function_type (type1, dbx_lookup_type (typenums));
1616 case 'k': /* Const qualifier on some type (Sun) */
1617 case 'c': /* Const qualifier on some type (OS9000) */
1618 /* Because 'c' means other things to AIX and 'k' is perfectly good,
1619 only accept 'c' in the os9k_stabs case. */
1620 if (type_descriptor == 'c' && !os9k_stabs)
1621 return error_type (pp);
1622 type = read_type (pp, objfile);
1623 /* FIXME! For now, we ignore const and volatile qualifiers. */
1626 case 'B': /* Volatile qual on some type (Sun) */
1627 case 'i': /* Volatile qual on some type (OS9000) */
1628 /* Because 'i' means other things to AIX and 'B' is perfectly good,
1629 only accept 'i' in the os9k_stabs case. */
1630 if (type_descriptor == 'i' && !os9k_stabs)
1631 return error_type (pp);
1632 type = read_type (pp, objfile);
1633 /* FIXME! For now, we ignore const and volatile qualifiers. */
1636 /* FIXME -- we should be doing smash_to_XXX types here. */
1637 case '@': /* Member (class & variable) type */
1639 struct type *domain = read_type (pp, objfile);
1640 struct type *memtype;
1643 /* Invalid member type data format. */
1644 return error_type (pp);
1647 memtype = read_type (pp, objfile);
1648 type = dbx_alloc_type (typenums, objfile);
1649 smash_to_member_type (type, domain, memtype);
1653 case '#': /* Method (class & fn) type */
1654 if ((*pp)[0] == '#')
1656 /* We'll get the parameter types from the name. */
1657 struct type *return_type;
1660 return_type = read_type (pp, objfile);
1661 if (*(*pp)++ != ';')
1662 complain (&invalid_member_complaint, symnum);
1663 type = allocate_stub_method (return_type);
1664 if (typenums[0] != -1)
1665 *dbx_lookup_type (typenums) = type;
1669 struct type *domain = read_type (pp, objfile);
1670 struct type *return_type;
1674 /* Invalid member type data format. */
1675 return error_type (pp);
1679 return_type = read_type (pp, objfile);
1680 args = read_args (pp, ';', objfile);
1681 type = dbx_alloc_type (typenums, objfile);
1682 smash_to_method_type (type, domain, return_type, args);
1686 case 'r': /* Range type */
1687 type = read_range_type (pp, typenums, objfile);
1688 if (typenums[0] != -1)
1689 *dbx_lookup_type (typenums) = type;
1694 /* Const and volatile qualified type. */
1695 type = read_type (pp, objfile);
1698 /* Sun ACC builtin int type */
1699 type = read_sun_builtin_type (pp, typenums, objfile);
1700 if (typenums[0] != -1)
1701 *dbx_lookup_type (typenums) = type;
1705 case 'R': /* Sun ACC builtin float type */
1706 type = read_sun_floating_type (pp, typenums, objfile);
1707 if (typenums[0] != -1)
1708 *dbx_lookup_type (typenums) = type;
1711 case 'e': /* Enumeration type */
1712 type = dbx_alloc_type (typenums, objfile);
1713 type = read_enum_type (pp, type, objfile);
1714 if (typenums[0] != -1)
1715 *dbx_lookup_type (typenums) = type;
1718 case 's': /* Struct type */
1719 case 'u': /* Union type */
1720 type = dbx_alloc_type (typenums, objfile);
1721 if (!TYPE_NAME (type))
1723 TYPE_NAME (type) = type_synonym_name;
1725 type_synonym_name = NULL;
1726 switch (type_descriptor)
1729 TYPE_CODE (type) = TYPE_CODE_STRUCT;
1732 TYPE_CODE (type) = TYPE_CODE_UNION;
1735 type = read_struct_type (pp, type, objfile);
1738 case 'a': /* Array type */
1740 return error_type (pp);
1743 type = dbx_alloc_type (typenums, objfile);
1744 type = read_array_type (pp, type, objfile);
1746 TYPE_CODE (type) = TYPE_CODE_STRING;
1750 type1 = read_type (pp, objfile);
1751 type = create_set_type ((struct type*) NULL, type1);
1753 TYPE_CODE (type) = TYPE_CODE_BITSTRING;
1754 if (typenums[0] != -1)
1755 *dbx_lookup_type (typenums) = type;
1759 --*pp; /* Go back to the symbol in error */
1760 /* Particularly important if it was \0! */
1761 return error_type (pp);
1766 warning ("GDB internal error, type is NULL in stabsread.c\n");
1767 return error_type (pp);
1770 /* Size specified in a type attribute overrides any other size. */
1771 if (type_size != -1)
1772 TYPE_LENGTH (type) = (type_size + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT;
1777 /* RS/6000 xlc/dbx combination uses a set of builtin types, starting from -1.
1778 Return the proper type node for a given builtin type number. */
1780 static struct type *
1781 rs6000_builtin_type (typenum)
1784 /* We recognize types numbered from -NUMBER_RECOGNIZED to -1. */
1785 #define NUMBER_RECOGNIZED 34
1786 /* This includes an empty slot for type number -0. */
1787 static struct type *negative_types[NUMBER_RECOGNIZED + 1];
1788 struct type *rettype = NULL;
1790 if (typenum >= 0 || typenum < -NUMBER_RECOGNIZED)
1792 complain (&rs6000_builtin_complaint, typenum);
1793 return builtin_type_error;
1795 if (negative_types[-typenum] != NULL)
1796 return negative_types[-typenum];
1798 #if TARGET_CHAR_BIT != 8
1799 #error This code wrong for TARGET_CHAR_BIT not 8
1800 /* These definitions all assume that TARGET_CHAR_BIT is 8. I think
1801 that if that ever becomes not true, the correct fix will be to
1802 make the size in the struct type to be in bits, not in units of
1809 /* The size of this and all the other types are fixed, defined
1810 by the debugging format. If there is a type called "int" which
1811 is other than 32 bits, then it should use a new negative type
1812 number (or avoid negative type numbers for that case).
1813 See stabs.texinfo. */
1814 rettype = init_type (TYPE_CODE_INT, 4, 0, "int", NULL);
1817 rettype = init_type (TYPE_CODE_INT, 1, 0, "char", NULL);
1820 rettype = init_type (TYPE_CODE_INT, 2, 0, "short", NULL);
1823 rettype = init_type (TYPE_CODE_INT, 4, 0, "long", NULL);
1826 rettype = init_type (TYPE_CODE_INT, 1, TYPE_FLAG_UNSIGNED,
1827 "unsigned char", NULL);
1830 rettype = init_type (TYPE_CODE_INT, 1, 0, "signed char", NULL);
1833 rettype = init_type (TYPE_CODE_INT, 2, TYPE_FLAG_UNSIGNED,
1834 "unsigned short", NULL);
1837 rettype = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED,
1838 "unsigned int", NULL);
1841 rettype = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED,
1844 rettype = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED,
1845 "unsigned long", NULL);
1848 rettype = init_type (TYPE_CODE_VOID, 1, 0, "void", NULL);
1851 /* IEEE single precision (32 bit). */
1852 rettype = init_type (TYPE_CODE_FLT, 4, 0, "float", NULL);
1855 /* IEEE double precision (64 bit). */
1856 rettype = init_type (TYPE_CODE_FLT, 8, 0, "double", NULL);
1859 /* This is an IEEE double on the RS/6000, and different machines with
1860 different sizes for "long double" should use different negative
1861 type numbers. See stabs.texinfo. */
1862 rettype = init_type (TYPE_CODE_FLT, 8, 0, "long double", NULL);
1865 rettype = init_type (TYPE_CODE_INT, 4, 0, "integer", NULL);
1868 rettype = init_type (TYPE_CODE_BOOL, 4, 0, "boolean", NULL);
1871 rettype = init_type (TYPE_CODE_FLT, 4, 0, "short real", NULL);
1874 rettype = init_type (TYPE_CODE_FLT, 8, 0, "real", NULL);
1877 rettype = init_type (TYPE_CODE_ERROR, 0, 0, "stringptr", NULL);
1880 rettype = init_type (TYPE_CODE_CHAR, 1, TYPE_FLAG_UNSIGNED,
1884 rettype = init_type (TYPE_CODE_BOOL, 1, TYPE_FLAG_UNSIGNED,
1888 rettype = init_type (TYPE_CODE_BOOL, 2, TYPE_FLAG_UNSIGNED,
1892 rettype = init_type (TYPE_CODE_BOOL, 4, TYPE_FLAG_UNSIGNED,
1896 rettype = init_type (TYPE_CODE_BOOL, 4, TYPE_FLAG_UNSIGNED,
1900 /* Complex type consisting of two IEEE single precision values. */
1901 rettype = init_type (TYPE_CODE_ERROR, 8, 0, "complex", NULL);
1904 /* Complex type consisting of two IEEE double precision values. */
1905 rettype = init_type (TYPE_CODE_ERROR, 16, 0, "double complex", NULL);
1908 rettype = init_type (TYPE_CODE_INT, 1, 0, "integer*1", NULL);
1911 rettype = init_type (TYPE_CODE_INT, 2, 0, "integer*2", NULL);
1914 rettype = init_type (TYPE_CODE_INT, 4, 0, "integer*4", NULL);
1917 rettype = init_type (TYPE_CODE_CHAR, 2, 0, "wchar", NULL);
1920 rettype = init_type (TYPE_CODE_INT, 8, 0, "long long", NULL);
1923 rettype = init_type (TYPE_CODE_INT, 8, TYPE_FLAG_UNSIGNED,
1924 "unsigned long long", NULL);
1927 rettype = init_type (TYPE_CODE_INT, 8, TYPE_FLAG_UNSIGNED,
1931 rettype = init_type (TYPE_CODE_INT, 8, 0, "integer*8", NULL);
1934 negative_types[-typenum] = rettype;
1938 /* This page contains subroutines of read_type. */
1940 #define VISIBILITY_PRIVATE '0' /* Stabs character for private field */
1941 #define VISIBILITY_PROTECTED '1' /* Stabs character for protected fld */
1942 #define VISIBILITY_PUBLIC '2' /* Stabs character for public field */
1943 #define VISIBILITY_IGNORE '9' /* Optimized out or zero length */
1945 /* Read member function stabs info for C++ classes. The form of each member
1948 NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
1950 An example with two member functions is:
1952 afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
1954 For the case of overloaded operators, the format is op$::*.funcs, where
1955 $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
1956 name (such as `+=') and `.' marks the end of the operator name.
1958 Returns 1 for success, 0 for failure. */
1961 read_member_functions (fip, pp, type, objfile)
1962 struct field_info *fip;
1965 struct objfile *objfile;
1969 /* Total number of member functions defined in this class. If the class
1970 defines two `f' functions, and one `g' function, then this will have
1972 int total_length = 0;
1976 struct next_fnfield *next;
1977 struct fn_field fn_field;
1979 struct type *look_ahead_type;
1980 struct next_fnfieldlist *new_fnlist;
1981 struct next_fnfield *new_sublist;
1985 /* Process each list until we find something that is not a member function
1986 or find the end of the functions. */
1990 /* We should be positioned at the start of the function name.
1991 Scan forward to find the first ':' and if it is not the
1992 first of a "::" delimiter, then this is not a member function. */
2004 look_ahead_type = NULL;
2007 new_fnlist = (struct next_fnfieldlist *)
2008 xmalloc (sizeof (struct next_fnfieldlist));
2009 make_cleanup (free, new_fnlist);
2010 memset (new_fnlist, 0, sizeof (struct next_fnfieldlist));
2012 if ((*pp)[0] == 'o' && (*pp)[1] == 'p' && (*pp)[2] == CPLUS_MARKER)
2014 /* This is a completely wierd case. In order to stuff in the
2015 names that might contain colons (the usual name delimiter),
2016 Mike Tiemann defined a different name format which is
2017 signalled if the identifier is "op$". In that case, the
2018 format is "op$::XXXX." where XXXX is the name. This is
2019 used for names like "+" or "=". YUUUUUUUK! FIXME! */
2020 /* This lets the user type "break operator+".
2021 We could just put in "+" as the name, but that wouldn't
2023 static char opname[32] = {'o', 'p', CPLUS_MARKER};
2024 char *o = opname + 3;
2026 /* Skip past '::'. */
2029 STABS_CONTINUE (pp);
2035 main_fn_name = savestring (opname, o - opname);
2041 main_fn_name = savestring (*pp, p - *pp);
2042 /* Skip past '::'. */
2045 new_fnlist -> fn_fieldlist.name = main_fn_name;
2050 (struct next_fnfield *) xmalloc (sizeof (struct next_fnfield));
2051 make_cleanup (free, new_sublist);
2052 memset (new_sublist, 0, sizeof (struct next_fnfield));
2054 /* Check for and handle cretinous dbx symbol name continuation! */
2055 if (look_ahead_type == NULL)
2058 STABS_CONTINUE (pp);
2060 new_sublist -> fn_field.type = read_type (pp, objfile);
2063 /* Invalid symtab info for member function. */
2069 /* g++ version 1 kludge */
2070 new_sublist -> fn_field.type = look_ahead_type;
2071 look_ahead_type = NULL;
2081 /* If this is just a stub, then we don't have the real name here. */
2083 if (TYPE_FLAGS (new_sublist -> fn_field.type) & TYPE_FLAG_STUB)
2085 if (!TYPE_DOMAIN_TYPE (new_sublist -> fn_field.type))
2086 TYPE_DOMAIN_TYPE (new_sublist -> fn_field.type) = type;
2087 new_sublist -> fn_field.is_stub = 1;
2089 new_sublist -> fn_field.physname = savestring (*pp, p - *pp);
2092 /* Set this member function's visibility fields. */
2095 case VISIBILITY_PRIVATE:
2096 new_sublist -> fn_field.is_private = 1;
2098 case VISIBILITY_PROTECTED:
2099 new_sublist -> fn_field.is_protected = 1;
2103 STABS_CONTINUE (pp);
2106 case 'A': /* Normal functions. */
2107 new_sublist -> fn_field.is_const = 0;
2108 new_sublist -> fn_field.is_volatile = 0;
2111 case 'B': /* `const' member functions. */
2112 new_sublist -> fn_field.is_const = 1;
2113 new_sublist -> fn_field.is_volatile = 0;
2116 case 'C': /* `volatile' member function. */
2117 new_sublist -> fn_field.is_const = 0;
2118 new_sublist -> fn_field.is_volatile = 1;
2121 case 'D': /* `const volatile' member function. */
2122 new_sublist -> fn_field.is_const = 1;
2123 new_sublist -> fn_field.is_volatile = 1;
2126 case '*': /* File compiled with g++ version 1 -- no info */
2131 complain (&const_vol_complaint, **pp);
2140 /* virtual member function, followed by index.
2141 The sign bit is set to distinguish pointers-to-methods
2142 from virtual function indicies. Since the array is
2143 in words, the quantity must be shifted left by 1
2144 on 16 bit machine, and by 2 on 32 bit machine, forcing
2145 the sign bit out, and usable as a valid index into
2146 the array. Remove the sign bit here. */
2147 new_sublist -> fn_field.voffset =
2148 (0x7fffffff & read_huge_number (pp, ';', &nbits)) + 2;
2152 STABS_CONTINUE (pp);
2153 if (**pp == ';' || **pp == '\0')
2155 /* Must be g++ version 1. */
2156 new_sublist -> fn_field.fcontext = 0;
2160 /* Figure out from whence this virtual function came.
2161 It may belong to virtual function table of
2162 one of its baseclasses. */
2163 look_ahead_type = read_type (pp, objfile);
2166 /* g++ version 1 overloaded methods. */
2170 new_sublist -> fn_field.fcontext = look_ahead_type;
2179 look_ahead_type = NULL;
2185 /* static member function. */
2186 new_sublist -> fn_field.voffset = VOFFSET_STATIC;
2187 if (strncmp (new_sublist -> fn_field.physname,
2188 main_fn_name, strlen (main_fn_name)))
2190 new_sublist -> fn_field.is_stub = 1;
2196 complain (&member_fn_complaint, (*pp)[-1]);
2197 /* Fall through into normal member function. */
2200 /* normal member function. */
2201 new_sublist -> fn_field.voffset = 0;
2202 new_sublist -> fn_field.fcontext = 0;
2206 new_sublist -> next = sublist;
2207 sublist = new_sublist;
2209 STABS_CONTINUE (pp);
2211 while (**pp != ';' && **pp != '\0');
2215 new_fnlist -> fn_fieldlist.fn_fields = (struct fn_field *)
2216 obstack_alloc (&objfile -> type_obstack,
2217 sizeof (struct fn_field) * length);
2218 memset (new_fnlist -> fn_fieldlist.fn_fields, 0,
2219 sizeof (struct fn_field) * length);
2220 for (i = length; (i--, sublist); sublist = sublist -> next)
2222 new_fnlist -> fn_fieldlist.fn_fields[i] = sublist -> fn_field;
2225 new_fnlist -> fn_fieldlist.length = length;
2226 new_fnlist -> next = fip -> fnlist;
2227 fip -> fnlist = new_fnlist;
2229 total_length += length;
2230 STABS_CONTINUE (pp);
2235 ALLOCATE_CPLUS_STRUCT_TYPE (type);
2236 TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
2237 TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * nfn_fields);
2238 memset (TYPE_FN_FIELDLISTS (type), 0,
2239 sizeof (struct fn_fieldlist) * nfn_fields);
2240 TYPE_NFN_FIELDS (type) = nfn_fields;
2241 TYPE_NFN_FIELDS_TOTAL (type) = total_length;
2247 /* Special GNU C++ name.
2249 Returns 1 for success, 0 for failure. "failure" means that we can't
2250 keep parsing and it's time for error_type(). */
2253 read_cpp_abbrev (fip, pp, type, objfile)
2254 struct field_info *fip;
2257 struct objfile *objfile;
2262 struct type *context;
2272 /* At this point, *pp points to something like "22:23=*22...",
2273 where the type number before the ':' is the "context" and
2274 everything after is a regular type definition. Lookup the
2275 type, find it's name, and construct the field name. */
2277 context = read_type (pp, objfile);
2281 case 'f': /* $vf -- a virtual function table pointer */
2282 fip->list->field.name =
2283 obconcat (&objfile->type_obstack, vptr_name, "", "");
2286 case 'b': /* $vb -- a virtual bsomethingorother */
2287 name = type_name_no_tag (context);
2290 complain (&invalid_cpp_type_complaint, symnum);
2293 fip->list->field.name =
2294 obconcat (&objfile->type_obstack, vb_name, name, "");
2298 complain (&invalid_cpp_abbrev_complaint, *pp);
2299 fip->list->field.name =
2300 obconcat (&objfile->type_obstack,
2301 "INVALID_CPLUSPLUS_ABBREV", "", "");
2305 /* At this point, *pp points to the ':'. Skip it and read the
2311 complain (&invalid_cpp_abbrev_complaint, *pp);
2314 fip->list->field.type = read_type (pp, objfile);
2316 (*pp)++; /* Skip the comma. */
2322 fip->list->field.bitpos = read_huge_number (pp, ';', &nbits);
2326 /* This field is unpacked. */
2327 fip->list->field.bitsize = 0;
2328 fip->list->visibility = VISIBILITY_PRIVATE;
2332 complain (&invalid_cpp_abbrev_complaint, *pp);
2333 /* We have no idea what syntax an unrecognized abbrev would have, so
2334 better return 0. If we returned 1, we would need to at least advance
2335 *pp to avoid an infinite loop. */
2342 read_one_struct_field (fip, pp, p, type, objfile)
2343 struct field_info *fip;
2347 struct objfile *objfile;
2349 /* The following is code to work around cfront generated stabs.
2350 The stabs contains full mangled name for each field.
2351 We try to demangle the name and extract the field name out of it.
2353 if (current_language->la_language == language_cplus)
2359 dem = cplus_demangle (*pp, DMGL_ANSI | DMGL_PARAMS);
2362 dem_p = strrchr (dem, ':');
2363 if (dem_p != 0 && *(dem_p-1)==':')
2365 fip->list->field.name =
2366 obsavestring (dem_p, strlen(dem_p), &objfile -> type_obstack);
2370 fip->list->field.name =
2371 obsavestring (*pp, p - *pp, &objfile -> type_obstack);
2375 /* end of code for cfront work around */
2378 fip -> list -> field.name =
2379 obsavestring (*pp, p - *pp, &objfile -> type_obstack);
2382 /* This means we have a visibility for a field coming. */
2386 fip -> list -> visibility = *(*pp)++;
2390 /* normal dbx-style format, no explicit visibility */
2391 fip -> list -> visibility = VISIBILITY_PUBLIC;
2394 fip -> list -> field.type = read_type (pp, objfile);
2399 /* Possible future hook for nested types. */
2402 fip -> list -> field.bitpos = (long)-2; /* nested type */
2408 /* Static class member. */
2409 fip -> list -> field.bitpos = (long) -1;
2415 fip -> list -> field.bitsize = (long) savestring (*pp, p - *pp);
2419 else if (**pp != ',')
2421 /* Bad structure-type format. */
2422 complain (&stabs_general_complaint, "bad structure-type format");
2426 (*pp)++; /* Skip the comma. */
2430 fip -> list -> field.bitpos = read_huge_number (pp, ',', &nbits);
2433 complain (&stabs_general_complaint, "bad structure-type format");
2436 fip -> list -> field.bitsize = read_huge_number (pp, ';', &nbits);
2439 complain (&stabs_general_complaint, "bad structure-type format");
2444 if (fip -> list -> field.bitpos == 0 && fip -> list -> field.bitsize == 0)
2446 /* This can happen in two cases: (1) at least for gcc 2.4.5 or so,
2447 it is a field which has been optimized out. The correct stab for
2448 this case is to use VISIBILITY_IGNORE, but that is a recent
2449 invention. (2) It is a 0-size array. For example
2450 union { int num; char str[0]; } foo. Printing "<no value>" for
2451 str in "p foo" is OK, since foo.str (and thus foo.str[3])
2452 will continue to work, and a 0-size array as a whole doesn't
2453 have any contents to print.
2455 I suspect this probably could also happen with gcc -gstabs (not
2456 -gstabs+) for static fields, and perhaps other C++ extensions.
2457 Hopefully few people use -gstabs with gdb, since it is intended
2458 for dbx compatibility. */
2460 /* Ignore this field. */
2461 fip -> list-> visibility = VISIBILITY_IGNORE;
2465 /* Detect an unpacked field and mark it as such.
2466 dbx gives a bit size for all fields.
2467 Note that forward refs cannot be packed,
2468 and treat enums as if they had the width of ints. */
2470 if (TYPE_CODE (fip -> list -> field.type) != TYPE_CODE_INT
2471 && TYPE_CODE (fip -> list -> field.type) != TYPE_CODE_ENUM)
2473 fip -> list -> field.bitsize = 0;
2475 if ((fip -> list -> field.bitsize
2476 == TARGET_CHAR_BIT * TYPE_LENGTH (fip -> list -> field.type)
2477 || (TYPE_CODE (fip -> list -> field.type) == TYPE_CODE_ENUM
2478 && (fip -> list -> field.bitsize
2483 fip -> list -> field.bitpos % 8 == 0)
2485 fip -> list -> field.bitsize = 0;
2491 /* Read struct or class data fields. They have the form:
2493 NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
2495 At the end, we see a semicolon instead of a field.
2497 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
2500 The optional VISIBILITY is one of:
2502 '/0' (VISIBILITY_PRIVATE)
2503 '/1' (VISIBILITY_PROTECTED)
2504 '/2' (VISIBILITY_PUBLIC)
2505 '/9' (VISIBILITY_IGNORE)
2507 or nothing, for C style fields with public visibility.
2509 Returns 1 for success, 0 for failure. */
2512 read_struct_fields (fip, pp, type, objfile)
2513 struct field_info *fip;
2516 struct objfile *objfile;
2519 struct nextfield *new;
2521 /* We better set p right now, in case there are no fields at all... */
2525 /* Read each data member type until we find the terminating ';' at the end of
2526 the data member list, or break for some other reason such as finding the
2527 start of the member function list. */
2531 if (os9k_stabs && **pp == ',') break;
2532 STABS_CONTINUE (pp);
2533 /* Get space to record the next field's data. */
2534 new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
2535 make_cleanup (free, new);
2536 memset (new, 0, sizeof (struct nextfield));
2537 new -> next = fip -> list;
2540 /* Get the field name. */
2543 /* If is starts with CPLUS_MARKER it is a special abbreviation,
2544 unless the CPLUS_MARKER is followed by an underscore, in
2545 which case it is just the name of an anonymous type, which we
2546 should handle like any other type name. We accept either '$'
2547 or '.', because a field name can never contain one of these
2548 characters except as a CPLUS_MARKER (we probably should be
2549 doing that in most parts of GDB). */
2551 if ((*p == '$' || *p == '.') && p[1] != '_')
2553 if (!read_cpp_abbrev (fip, pp, type, objfile))
2558 /* Look for the ':' that separates the field name from the field
2559 values. Data members are delimited by a single ':', while member
2560 functions are delimited by a pair of ':'s. When we hit the member
2561 functions (if any), terminate scan loop and return. */
2563 while (*p != ':' && *p != '\0')
2570 /* Check to see if we have hit the member functions yet. */
2575 read_one_struct_field (fip, pp, p, type, objfile);
2577 if (p[0] == ':' && p[1] == ':')
2579 /* chill the list of fields: the last entry (at the head) is a
2580 partially constructed entry which we now scrub. */
2581 fip -> list = fip -> list -> next;
2586 /* The stabs for C++ derived classes contain baseclass information which
2587 is marked by a '!' character after the total size. This function is
2588 called when we encounter the baseclass marker, and slurps up all the
2589 baseclass information.
2591 Immediately following the '!' marker is the number of base classes that
2592 the class is derived from, followed by information for each base class.
2593 For each base class, there are two visibility specifiers, a bit offset
2594 to the base class information within the derived class, a reference to
2595 the type for the base class, and a terminating semicolon.
2597 A typical example, with two base classes, would be "!2,020,19;0264,21;".
2599 Baseclass information marker __________________|| | | | | | |
2600 Number of baseclasses __________________________| | | | | | |
2601 Visibility specifiers (2) ________________________| | | | | |
2602 Offset in bits from start of class _________________| | | | |
2603 Type number for base class ___________________________| | | |
2604 Visibility specifiers (2) _______________________________| | |
2605 Offset in bits from start of class ________________________| |
2606 Type number of base class ____________________________________|
2608 Return 1 for success, 0 for (error-type-inducing) failure. */
2611 read_baseclasses (fip, pp, type, objfile)
2612 struct field_info *fip;
2615 struct objfile *objfile;
2618 struct nextfield *new;
2626 /* Skip the '!' baseclass information marker. */
2630 ALLOCATE_CPLUS_STRUCT_TYPE (type);
2633 TYPE_N_BASECLASSES (type) = read_huge_number (pp, ',', &nbits);
2639 /* Some stupid compilers have trouble with the following, so break
2640 it up into simpler expressions. */
2641 TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *)
2642 TYPE_ALLOC (type, B_BYTES (TYPE_N_BASECLASSES (type)));
2645 int num_bytes = B_BYTES (TYPE_N_BASECLASSES (type));
2648 pointer = (char *) TYPE_ALLOC (type, num_bytes);
2649 TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *) pointer;
2653 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), TYPE_N_BASECLASSES (type));
2655 for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
2657 new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
2658 make_cleanup (free, new);
2659 memset (new, 0, sizeof (struct nextfield));
2660 new -> next = fip -> list;
2662 new -> field.bitsize = 0; /* this should be an unpacked field! */
2664 STABS_CONTINUE (pp);
2668 /* Nothing to do. */
2671 SET_TYPE_FIELD_VIRTUAL (type, i);
2674 /* Unknown character. Complain and treat it as non-virtual. */
2676 static struct complaint msg = {
2677 "Unknown virtual character `%c' for baseclass", 0, 0};
2678 complain (&msg, **pp);
2683 new -> visibility = *(*pp)++;
2684 switch (new -> visibility)
2686 case VISIBILITY_PRIVATE:
2687 case VISIBILITY_PROTECTED:
2688 case VISIBILITY_PUBLIC:
2691 /* Bad visibility format. Complain and treat it as
2694 static struct complaint msg = {
2695 "Unknown visibility `%c' for baseclass", 0, 0};
2696 complain (&msg, new -> visibility);
2697 new -> visibility = VISIBILITY_PUBLIC;
2704 /* The remaining value is the bit offset of the portion of the object
2705 corresponding to this baseclass. Always zero in the absence of
2706 multiple inheritance. */
2708 new -> field.bitpos = read_huge_number (pp, ',', &nbits);
2713 /* The last piece of baseclass information is the type of the
2714 base class. Read it, and remember it's type name as this
2717 new -> field.type = read_type (pp, objfile);
2718 new -> field.name = type_name_no_tag (new -> field.type);
2720 /* skip trailing ';' and bump count of number of fields seen */
2729 /* The tail end of stabs for C++ classes that contain a virtual function
2730 pointer contains a tilde, a %, and a type number.
2731 The type number refers to the base class (possibly this class itself) which
2732 contains the vtable pointer for the current class.
2734 This function is called when we have parsed all the method declarations,
2735 so we can look for the vptr base class info. */
2738 read_tilde_fields (fip, pp, type, objfile)
2739 struct field_info *fip;
2742 struct objfile *objfile;
2746 STABS_CONTINUE (pp);
2748 /* If we are positioned at a ';', then skip it. */
2758 if (**pp == '=' || **pp == '+' || **pp == '-')
2760 /* Obsolete flags that used to indicate the presence
2761 of constructors and/or destructors. */
2765 /* Read either a '%' or the final ';'. */
2766 if (*(*pp)++ == '%')
2768 /* The next number is the type number of the base class
2769 (possibly our own class) which supplies the vtable for
2770 this class. Parse it out, and search that class to find
2771 its vtable pointer, and install those into TYPE_VPTR_BASETYPE
2772 and TYPE_VPTR_FIELDNO. */
2777 t = read_type (pp, objfile);
2779 while (*p != '\0' && *p != ';')
2785 /* Premature end of symbol. */
2789 TYPE_VPTR_BASETYPE (type) = t;
2790 if (type == t) /* Our own class provides vtbl ptr */
2792 for (i = TYPE_NFIELDS (t) - 1;
2793 i >= TYPE_N_BASECLASSES (t);
2796 if (! strncmp (TYPE_FIELD_NAME (t, i), vptr_name,
2797 sizeof (vptr_name) - 1))
2799 TYPE_VPTR_FIELDNO (type) = i;
2803 /* Virtual function table field not found. */
2804 complain (&vtbl_notfound_complaint, TYPE_NAME (type));
2809 TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t);
2820 attach_fn_fields_to_type (fip, type)
2821 struct field_info *fip;
2822 register struct type *type;
2826 for (n = TYPE_NFN_FIELDS (type);
2827 fip -> fnlist != NULL;
2828 fip -> fnlist = fip -> fnlist -> next)
2830 --n; /* Circumvent Sun3 compiler bug */
2831 TYPE_FN_FIELDLISTS (type)[n] = fip -> fnlist -> fn_fieldlist;
2836 /* Create the vector of fields, and record how big it is.
2837 We need this info to record proper virtual function table information
2838 for this class's virtual functions. */
2841 attach_fields_to_type (fip, type, objfile)
2842 struct field_info *fip;
2843 register struct type *type;
2844 struct objfile *objfile;
2846 register int nfields = 0;
2847 register int non_public_fields = 0;
2848 register struct nextfield *scan;
2850 /* Count up the number of fields that we have, as well as taking note of
2851 whether or not there are any non-public fields, which requires us to
2852 allocate and build the private_field_bits and protected_field_bits
2855 for (scan = fip -> list; scan != NULL; scan = scan -> next)
2858 if (scan -> visibility != VISIBILITY_PUBLIC)
2860 non_public_fields++;
2864 /* Now we know how many fields there are, and whether or not there are any
2865 non-public fields. Record the field count, allocate space for the
2866 array of fields, and create blank visibility bitfields if necessary. */
2868 TYPE_NFIELDS (type) = nfields;
2869 TYPE_FIELDS (type) = (struct field *)
2870 TYPE_ALLOC (type, sizeof (struct field) * nfields);
2871 memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields);
2873 if (non_public_fields)
2875 ALLOCATE_CPLUS_STRUCT_TYPE (type);
2877 TYPE_FIELD_PRIVATE_BITS (type) =
2878 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
2879 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
2881 TYPE_FIELD_PROTECTED_BITS (type) =
2882 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
2883 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
2885 TYPE_FIELD_IGNORE_BITS (type) =
2886 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
2887 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields);
2890 /* Copy the saved-up fields into the field vector. Start from the head
2891 of the list, adding to the tail of the field array, so that they end
2892 up in the same order in the array in which they were added to the list. */
2894 while (nfields-- > 0)
2896 TYPE_FIELD (type, nfields) = fip -> list -> field;
2897 switch (fip -> list -> visibility)
2899 case VISIBILITY_PRIVATE:
2900 SET_TYPE_FIELD_PRIVATE (type, nfields);
2903 case VISIBILITY_PROTECTED:
2904 SET_TYPE_FIELD_PROTECTED (type, nfields);
2907 case VISIBILITY_IGNORE:
2908 SET_TYPE_FIELD_IGNORE (type, nfields);
2911 case VISIBILITY_PUBLIC:
2915 /* Unknown visibility. Complain and treat it as public. */
2917 static struct complaint msg = {
2918 "Unknown visibility `%c' for field", 0, 0};
2919 complain (&msg, fip -> list -> visibility);
2923 fip -> list = fip -> list -> next;
2928 /* Read the description of a structure (or union type) and return an object
2929 describing the type.
2931 PP points to a character pointer that points to the next unconsumed token
2932 in the the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
2933 *PP will point to "4a:1,0,32;;".
2935 TYPE points to an incomplete type that needs to be filled in.
2937 OBJFILE points to the current objfile from which the stabs information is
2938 being read. (Note that it is redundant in that TYPE also contains a pointer
2939 to this same objfile, so it might be a good idea to eliminate it. FIXME).
2942 static struct type *
2943 read_struct_type (pp, type, objfile)
2946 struct objfile *objfile;
2948 struct cleanup *back_to;
2949 struct field_info fi;
2954 back_to = make_cleanup (null_cleanup, 0);
2956 INIT_CPLUS_SPECIFIC (type);
2957 TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
2959 /* First comes the total size in bytes. */
2963 TYPE_LENGTH (type) = read_huge_number (pp, 0, &nbits);
2965 return error_type (pp);
2968 /* Now read the baseclasses, if any, read the regular C struct or C++
2969 class member fields, attach the fields to the type, read the C++
2970 member functions, attach them to the type, and then read any tilde
2971 field (baseclass specifier for the class holding the main vtable). */
2973 if (!read_baseclasses (&fi, pp, type, objfile)
2974 || !read_struct_fields (&fi, pp, type, objfile)
2975 || !attach_fields_to_type (&fi, type, objfile)
2976 || !read_member_functions (&fi, pp, type, objfile)
2977 || !attach_fn_fields_to_type (&fi, type)
2978 || !read_tilde_fields (&fi, pp, type, objfile))
2980 do_cleanups (back_to);
2981 return (error_type (pp));
2984 do_cleanups (back_to);
2988 /* Read a definition of an array type,
2989 and create and return a suitable type object.
2990 Also creates a range type which represents the bounds of that
2993 static struct type *
2994 read_array_type (pp, type, objfile)
2996 register struct type *type;
2997 struct objfile *objfile;
2999 struct type *index_type, *element_type, *range_type;
3004 /* Format of an array type:
3005 "ar<index type>;lower;upper;<array_contents_type>".
3006 OS9000: "arlower,upper;<array_contents_type>".
3008 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
3009 for these, produce a type like float[][]. */
3012 index_type = builtin_type_int;
3015 index_type = read_type (pp, objfile);
3017 /* Improper format of array type decl. */
3018 return error_type (pp);
3022 if (!(**pp >= '0' && **pp <= '9') && **pp != '-')
3027 lower = read_huge_number (pp, os9k_stabs ? ',' : ';', &nbits);
3029 return error_type (pp);
3031 if (!(**pp >= '0' && **pp <= '9') && **pp != '-')
3036 upper = read_huge_number (pp, ';', &nbits);
3038 return error_type (pp);
3040 element_type = read_type (pp, objfile);
3049 create_range_type ((struct type *) NULL, index_type, lower, upper);
3050 type = create_array_type (type, element_type, range_type);
3052 /* If we have an array whose element type is not yet known, but whose
3053 bounds *are* known, record it to be adjusted at the end of the file. */
3055 if ((TYPE_FLAGS (element_type) & TYPE_FLAG_STUB) && !adjustable)
3057 TYPE_FLAGS (type) |= TYPE_FLAG_TARGET_STUB;
3058 add_undefined_type (type);
3065 /* Read a definition of an enumeration type,
3066 and create and return a suitable type object.
3067 Also defines the symbols that represent the values of the type. */
3069 static struct type *
3070 read_enum_type (pp, type, objfile)
3072 register struct type *type;
3073 struct objfile *objfile;
3078 register struct symbol *sym;
3080 struct pending **symlist;
3081 struct pending *osyms, *syms;
3084 int unsigned_enum = 1;
3087 /* FIXME! The stabs produced by Sun CC merrily define things that ought
3088 to be file-scope, between N_FN entries, using N_LSYM. What's a mother
3089 to do? For now, force all enum values to file scope. */
3090 if (within_function)
3091 symlist = &local_symbols;
3094 symlist = &file_symbols;
3096 o_nsyms = osyms ? osyms->nsyms : 0;
3100 /* Size. Perhaps this does not have to be conditionalized on
3101 os9k_stabs (assuming the name of an enum constant can't start
3103 read_huge_number (pp, 0, &nbits);
3105 return error_type (pp);
3108 /* The aix4 compiler emits an extra field before the enum members;
3109 my guess is it's a type of some sort. Just ignore it. */
3112 /* Skip over the type. */
3116 /* Skip over the colon. */
3120 /* Read the value-names and their values.
3121 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
3122 A semicolon or comma instead of a NAME means the end. */
3123 while (**pp && **pp != ';' && **pp != ',')
3125 STABS_CONTINUE (pp);
3127 while (*p != ':') p++;
3128 name = obsavestring (*pp, p - *pp, &objfile -> symbol_obstack);
3130 n = read_huge_number (pp, ',', &nbits);
3132 return error_type (pp);
3134 sym = (struct symbol *)
3135 obstack_alloc (&objfile -> symbol_obstack, sizeof (struct symbol));
3136 memset (sym, 0, sizeof (struct symbol));
3137 SYMBOL_NAME (sym) = name;
3138 SYMBOL_LANGUAGE (sym) = current_subfile -> language;
3139 SYMBOL_CLASS (sym) = LOC_CONST;
3140 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
3141 SYMBOL_VALUE (sym) = n;
3144 add_symbol_to_list (sym, symlist);
3149 (*pp)++; /* Skip the semicolon. */
3151 /* Now fill in the fields of the type-structure. */
3153 TYPE_LENGTH (type) = TARGET_INT_BIT / HOST_CHAR_BIT;
3154 TYPE_CODE (type) = TYPE_CODE_ENUM;
3155 TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
3157 TYPE_FLAGS (type) |= TYPE_FLAG_UNSIGNED;
3158 TYPE_NFIELDS (type) = nsyms;
3159 TYPE_FIELDS (type) = (struct field *)
3160 TYPE_ALLOC (type, sizeof (struct field) * nsyms);
3161 memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nsyms);
3163 /* Find the symbols for the values and put them into the type.
3164 The symbols can be found in the symlist that we put them on
3165 to cause them to be defined. osyms contains the old value
3166 of that symlist; everything up to there was defined by us. */
3167 /* Note that we preserve the order of the enum constants, so
3168 that in something like "enum {FOO, LAST_THING=FOO}" we print
3169 FOO, not LAST_THING. */
3171 for (syms = *symlist, n = nsyms - 1; syms; syms = syms->next)
3173 int last = syms == osyms ? o_nsyms : 0;
3174 int j = syms->nsyms;
3175 for (; --j >= last; --n)
3177 struct symbol *xsym = syms->symbol[j];
3178 SYMBOL_TYPE (xsym) = type;
3179 TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym);
3180 TYPE_FIELD_VALUE (type, n) = 0;
3181 TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (xsym);
3182 TYPE_FIELD_BITSIZE (type, n) = 0;
3191 /* Sun's ACC uses a somewhat saner method for specifying the builtin
3192 typedefs in every file (for int, long, etc):
3194 type = b <signed> <width>; <offset>; <nbits>
3195 signed = u or s. Possible c in addition to u or s (for char?).
3196 offset = offset from high order bit to start bit of type.
3197 width is # bytes in object of this type, nbits is # bits in type.
3199 The width/offset stuff appears to be for small objects stored in
3200 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
3203 static struct type *
3204 read_sun_builtin_type (pp, typenums, objfile)
3207 struct objfile *objfile;
3222 return error_type (pp);
3226 /* For some odd reason, all forms of char put a c here. This is strange
3227 because no other type has this honor. We can safely ignore this because
3228 we actually determine 'char'acterness by the number of bits specified in
3234 /* The first number appears to be the number of bytes occupied
3235 by this type, except that unsigned short is 4 instead of 2.
3236 Since this information is redundant with the third number,
3237 we will ignore it. */
3238 read_huge_number (pp, ';', &nbits);
3240 return error_type (pp);
3242 /* The second number is always 0, so ignore it too. */
3243 read_huge_number (pp, ';', &nbits);
3245 return error_type (pp);
3247 /* The third number is the number of bits for this type. */
3248 type_bits = read_huge_number (pp, 0, &nbits);
3250 return error_type (pp);
3251 /* The type *should* end with a semicolon. If it are embedded
3252 in a larger type the semicolon may be the only way to know where
3253 the type ends. If this type is at the end of the stabstring we
3254 can deal with the omitted semicolon (but we don't have to like
3255 it). Don't bother to complain(), Sun's compiler omits the semicolon
3261 return init_type (TYPE_CODE_VOID, 1,
3262 signed_type ? 0 : TYPE_FLAG_UNSIGNED, (char *)NULL,
3265 return init_type (TYPE_CODE_INT,
3266 type_bits / TARGET_CHAR_BIT,
3267 signed_type ? 0 : TYPE_FLAG_UNSIGNED, (char *)NULL,
3271 static struct type *
3272 read_sun_floating_type (pp, typenums, objfile)
3275 struct objfile *objfile;
3281 /* The first number has more details about the type, for example
3283 details = read_huge_number (pp, ';', &nbits);
3285 return error_type (pp);
3287 /* The second number is the number of bytes occupied by this type */
3288 nbytes = read_huge_number (pp, ';', &nbits);
3290 return error_type (pp);
3292 if (details == NF_COMPLEX || details == NF_COMPLEX16
3293 || details == NF_COMPLEX32)
3294 /* This is a type we can't handle, but we do know the size.
3295 We also will be able to give it a name. */
3296 return init_type (TYPE_CODE_ERROR, nbytes, 0, NULL, objfile);
3298 return init_type (TYPE_CODE_FLT, nbytes, 0, NULL, objfile);
3301 /* Read a number from the string pointed to by *PP.
3302 The value of *PP is advanced over the number.
3303 If END is nonzero, the character that ends the
3304 number must match END, or an error happens;
3305 and that character is skipped if it does match.
3306 If END is zero, *PP is left pointing to that character.
3308 If the number fits in a long, set *BITS to 0 and return the value.
3309 If not, set *BITS to be the number of bits in the number and return 0.
3311 If encounter garbage, set *BITS to -1 and return 0. */
3314 read_huge_number (pp, end, bits)
3334 /* Leading zero means octal. GCC uses this to output values larger
3335 than an int (because that would be hard in decimal). */
3343 upper_limit = ULONG_MAX / radix;
3345 upper_limit = LONG_MAX / radix;
3347 while ((c = *p++) >= '0' && c < ('0' + radix))
3349 if (n <= upper_limit)
3352 n += c - '0'; /* FIXME this overflows anyway */
3357 /* This depends on large values being output in octal, which is
3364 /* Ignore leading zeroes. */
3368 else if (c == '2' || c == '3')
3394 /* Large decimal constants are an error (because it is hard to
3395 count how many bits are in them). */
3401 /* -0x7f is the same as 0x80. So deal with it by adding one to
3402 the number of bits. */
3414 /* It's *BITS which has the interesting information. */
3418 static struct type *
3419 read_range_type (pp, typenums, objfile)
3422 struct objfile *objfile;
3424 char *orig_pp = *pp;
3429 struct type *result_type;
3430 struct type *index_type = NULL;
3432 /* First comes a type we are a subrange of.
3433 In C it is usually 0, 1 or the type being defined. */
3434 if (read_type_number (pp, rangenums) != 0)
3435 return error_type (pp);
3436 self_subrange = (rangenums[0] == typenums[0] &&
3437 rangenums[1] == typenums[1]);
3442 index_type = read_type (pp, objfile);
3445 /* A semicolon should now follow; skip it. */
3449 /* The remaining two operands are usually lower and upper bounds
3450 of the range. But in some special cases they mean something else. */
3451 n2 = read_huge_number (pp, ';', &n2bits);
3452 n3 = read_huge_number (pp, ';', &n3bits);
3454 if (n2bits == -1 || n3bits == -1)
3455 return error_type (pp);
3458 goto handle_true_range;
3460 /* If limits are huge, must be large integral type. */
3461 if (n2bits != 0 || n3bits != 0)
3463 char got_signed = 0;
3464 char got_unsigned = 0;
3465 /* Number of bits in the type. */
3468 /* Range from 0 to <large number> is an unsigned large integral type. */
3469 if ((n2bits == 0 && n2 == 0) && n3bits != 0)
3474 /* Range from <large number> to <large number>-1 is a large signed
3475 integral type. Take care of the case where <large number> doesn't
3476 fit in a long but <large number>-1 does. */
3477 else if ((n2bits != 0 && n3bits != 0 && n2bits == n3bits + 1)
3478 || (n2bits != 0 && n3bits == 0
3479 && (n2bits == sizeof (long) * HOST_CHAR_BIT)
3486 if (got_signed || got_unsigned)
3488 return init_type (TYPE_CODE_INT, nbits / TARGET_CHAR_BIT,
3489 got_unsigned ? TYPE_FLAG_UNSIGNED : 0, NULL,
3493 return error_type (pp);
3496 /* A type defined as a subrange of itself, with bounds both 0, is void. */
3497 if (self_subrange && n2 == 0 && n3 == 0)
3498 return init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile);
3500 /* If n3 is zero and n2 is not, we want a floating type,
3501 and n2 is the width in bytes.
3503 Fortran programs appear to use this for complex types also,
3504 and they give no way to distinguish between double and single-complex!
3506 GDB does not have complex types.
3508 Just return the complex as a float of that size. It won't work right
3509 for the complex values, but at least it makes the file loadable. */
3511 if (n3 == 0 && n2 > 0)
3513 return init_type (TYPE_CODE_FLT, n2, 0, NULL, objfile);
3516 /* If the upper bound is -1, it must really be an unsigned int. */
3518 else if (n2 == 0 && n3 == -1)
3520 /* It is unsigned int or unsigned long. */
3521 /* GCC 2.3.3 uses this for long long too, but that is just a GDB 3.5
3522 compatibility hack. */
3523 return init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
3524 TYPE_FLAG_UNSIGNED, NULL, objfile);
3527 /* Special case: char is defined (Who knows why) as a subrange of
3528 itself with range 0-127. */
3529 else if (self_subrange && n2 == 0 && n3 == 127)
3530 return init_type (TYPE_CODE_INT, 1, 0, NULL, objfile);
3532 /* We used to do this only for subrange of self or subrange of int. */
3536 /* n3 actually gives the size. */
3537 return init_type (TYPE_CODE_INT, - n3, TYPE_FLAG_UNSIGNED,
3540 return init_type (TYPE_CODE_INT, 1, TYPE_FLAG_UNSIGNED, NULL, objfile);
3542 return init_type (TYPE_CODE_INT, 2, TYPE_FLAG_UNSIGNED, NULL, objfile);
3544 /* -1 is used for the upper bound of (4 byte) "unsigned int" and
3545 "unsigned long", and we already checked for that,
3546 so don't need to test for it here. */
3548 /* I think this is for Convex "long long". Since I don't know whether
3549 Convex sets self_subrange, I also accept that particular size regardless
3550 of self_subrange. */
3551 else if (n3 == 0 && n2 < 0
3553 || n2 == - TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT))
3554 return init_type (TYPE_CODE_INT, - n2, 0, NULL, objfile);
3555 else if (n2 == -n3 -1)
3558 return init_type (TYPE_CODE_INT, 1, 0, NULL, objfile);
3560 return init_type (TYPE_CODE_INT, 2, 0, NULL, objfile);
3561 if (n3 == 0x7fffffff)
3562 return init_type (TYPE_CODE_INT, 4, 0, NULL, objfile);
3565 /* We have a real range type on our hands. Allocate space and
3566 return a real pointer. */
3569 /* At this point I don't have the faintest idea how to deal with
3570 a self_subrange type; I'm going to assume that this is used
3571 as an idiom, and that all of them are special cases. So . . . */
3573 return error_type (pp);
3575 index_type = *dbx_lookup_type (rangenums);
3576 if (index_type == NULL)
3578 /* Does this actually ever happen? Is that why we are worrying
3579 about dealing with it rather than just calling error_type? */
3581 static struct type *range_type_index;
3583 complain (&range_type_base_complaint, rangenums[1]);
3584 if (range_type_index == NULL)
3586 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
3587 0, "range type index type", NULL);
3588 index_type = range_type_index;
3591 result_type = create_range_type ((struct type *) NULL, index_type, n2, n3);
3592 return (result_type);
3595 /* Read in an argument list. This is a list of types, separated by commas
3596 and terminated with END. Return the list of types read in, or (struct type
3597 **)-1 if there is an error. */
3599 static struct type **
3600 read_args (pp, end, objfile)
3603 struct objfile *objfile;
3605 /* FIXME! Remove this arbitrary limit! */
3606 struct type *types[1024], **rval; /* allow for fns of 1023 parameters */
3612 /* Invalid argument list: no ','. */
3613 return (struct type **)-1;
3615 STABS_CONTINUE (pp);
3616 types[n++] = read_type (pp, objfile);
3618 (*pp)++; /* get past `end' (the ':' character) */
3622 rval = (struct type **) xmalloc (2 * sizeof (struct type *));
3624 else if (TYPE_CODE (types[n-1]) != TYPE_CODE_VOID)
3626 rval = (struct type **) xmalloc ((n + 1) * sizeof (struct type *));
3627 memset (rval + n, 0, sizeof (struct type *));
3631 rval = (struct type **) xmalloc (n * sizeof (struct type *));
3633 memcpy (rval, types, n * sizeof (struct type *));
3637 /* Common block handling. */
3639 /* List of symbols declared since the last BCOMM. This list is a tail
3640 of local_symbols. When ECOMM is seen, the symbols on the list
3641 are noted so their proper addresses can be filled in later,
3642 using the common block base address gotten from the assembler
3645 static struct pending *common_block;
3646 static int common_block_i;
3648 /* Name of the current common block. We get it from the BCOMM instead of the
3649 ECOMM to match IBM documentation (even though IBM puts the name both places
3650 like everyone else). */
3651 static char *common_block_name;
3653 /* Process a N_BCOMM symbol. The storage for NAME is not guaranteed
3654 to remain after this function returns. */
3657 common_block_start (name, objfile)
3659 struct objfile *objfile;
3661 if (common_block_name != NULL)
3663 static struct complaint msg = {
3664 "Invalid symbol data: common block within common block",
3668 common_block = local_symbols;
3669 common_block_i = local_symbols ? local_symbols->nsyms : 0;
3670 common_block_name = obsavestring (name, strlen (name),
3671 &objfile -> symbol_obstack);
3674 /* Process a N_ECOMM symbol. */
3677 common_block_end (objfile)
3678 struct objfile *objfile;
3680 /* Symbols declared since the BCOMM are to have the common block
3681 start address added in when we know it. common_block and
3682 common_block_i point to the first symbol after the BCOMM in
3683 the local_symbols list; copy the list and hang it off the
3684 symbol for the common block name for later fixup. */
3687 struct pending *new = 0;
3688 struct pending *next;
3691 if (common_block_name == NULL)
3693 static struct complaint msg = {"ECOMM symbol unmatched by BCOMM", 0, 0};
3698 sym = (struct symbol *)
3699 obstack_alloc (&objfile -> symbol_obstack, sizeof (struct symbol));
3700 memset (sym, 0, sizeof (struct symbol));
3701 SYMBOL_NAME (sym) = common_block_name;
3702 SYMBOL_CLASS (sym) = LOC_BLOCK;
3704 /* Now we copy all the symbols which have been defined since the BCOMM. */
3706 /* Copy all the struct pendings before common_block. */
3707 for (next = local_symbols;
3708 next != NULL && next != common_block;
3711 for (j = 0; j < next->nsyms; j++)
3712 add_symbol_to_list (next->symbol[j], &new);
3715 /* Copy however much of COMMON_BLOCK we need. If COMMON_BLOCK is
3716 NULL, it means copy all the local symbols (which we already did
3719 if (common_block != NULL)
3720 for (j = common_block_i; j < common_block->nsyms; j++)
3721 add_symbol_to_list (common_block->symbol[j], &new);
3723 SYMBOL_TYPE (sym) = (struct type *) new;
3725 /* Should we be putting local_symbols back to what it was?
3728 i = hashname (SYMBOL_NAME (sym));
3729 SYMBOL_VALUE_CHAIN (sym) = global_sym_chain[i];
3730 global_sym_chain[i] = sym;
3731 common_block_name = NULL;
3734 /* Add a common block's start address to the offset of each symbol
3735 declared to be in it (by being between a BCOMM/ECOMM pair that uses
3736 the common block name). */
3739 fix_common_block (sym, valu)
3743 struct pending *next = (struct pending *) SYMBOL_TYPE (sym);
3744 for ( ; next; next = next->next)
3747 for (j = next->nsyms - 1; j >= 0; j--)
3748 SYMBOL_VALUE_ADDRESS (next->symbol[j]) += valu;
3754 /* What about types defined as forward references inside of a small lexical
3756 /* Add a type to the list of undefined types to be checked through
3757 once this file has been read in. */
3760 add_undefined_type (type)
3763 if (undef_types_length == undef_types_allocated)
3765 undef_types_allocated *= 2;
3766 undef_types = (struct type **)
3767 xrealloc ((char *) undef_types,
3768 undef_types_allocated * sizeof (struct type *));
3770 undef_types[undef_types_length++] = type;
3773 /* Go through each undefined type, see if it's still undefined, and fix it
3774 up if possible. We have two kinds of undefined types:
3776 TYPE_CODE_ARRAY: Array whose target type wasn't defined yet.
3777 Fix: update array length using the element bounds
3778 and the target type's length.
3779 TYPE_CODE_STRUCT, TYPE_CODE_UNION: Structure whose fields were not
3780 yet defined at the time a pointer to it was made.
3781 Fix: Do a full lookup on the struct/union tag. */
3783 cleanup_undefined_types ()
3787 for (type = undef_types; type < undef_types + undef_types_length; type++)
3789 switch (TYPE_CODE (*type))
3792 case TYPE_CODE_STRUCT:
3793 case TYPE_CODE_UNION:
3794 case TYPE_CODE_ENUM:
3796 /* Check if it has been defined since. Need to do this here
3797 as well as in check_stub_type to deal with the (legitimate in
3798 C though not C++) case of several types with the same name
3799 in different source files. */
3800 if (TYPE_FLAGS (*type) & TYPE_FLAG_STUB)
3802 struct pending *ppt;
3804 /* Name of the type, without "struct" or "union" */
3805 char *typename = TYPE_TAG_NAME (*type);
3807 if (typename == NULL)
3809 static struct complaint msg = {"need a type name", 0, 0};
3813 for (ppt = file_symbols; ppt; ppt = ppt->next)
3815 for (i = 0; i < ppt->nsyms; i++)
3817 struct symbol *sym = ppt->symbol[i];
3819 if (SYMBOL_CLASS (sym) == LOC_TYPEDEF
3820 && SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE
3821 && (TYPE_CODE (SYMBOL_TYPE (sym)) ==
3823 && STREQ (SYMBOL_NAME (sym), typename))
3825 memcpy (*type, SYMBOL_TYPE (sym),
3826 sizeof (struct type));
3834 case TYPE_CODE_ARRAY:
3836 /* This is a kludge which is here for historical reasons
3837 because I suspect that check_stub_type does not get
3838 called everywhere it needs to be called for arrays. Even
3839 with this kludge, those places are broken for the case
3840 where the stub type is defined in another compilation
3841 unit, but this kludge at least deals with it for the case
3842 in which it is the same compilation unit.
3844 Don't try to do this by calling check_stub_type; it might
3845 cause symbols to be read in lookup_symbol, and the symbol
3846 reader is not reentrant. */
3848 struct type *range_type;
3851 if (TYPE_LENGTH (*type) != 0) /* Better be unknown */
3853 if (TYPE_NFIELDS (*type) != 1)
3855 range_type = TYPE_FIELD_TYPE (*type, 0);
3856 if (TYPE_CODE (range_type) != TYPE_CODE_RANGE)
3859 /* Now recompute the length of the array type, based on its
3860 number of elements and the target type's length. */
3861 lower = TYPE_FIELD_BITPOS (range_type, 0);
3862 upper = TYPE_FIELD_BITPOS (range_type, 1);
3863 TYPE_LENGTH (*type) = (upper - lower + 1)
3864 * TYPE_LENGTH (TYPE_TARGET_TYPE (*type));
3866 /* If the target type is not a stub, we could be clearing
3867 TYPE_FLAG_TARGET_STUB for *type. */
3874 static struct complaint msg = {"\
3875 GDB internal error. cleanup_undefined_types with bad type %d.", 0, 0};
3876 complain (&msg, TYPE_CODE (*type));
3882 undef_types_length = 0;
3885 /* Scan through all of the global symbols defined in the object file,
3886 assigning values to the debugging symbols that need to be assigned
3887 to. Get these symbols from the minimal symbol table.
3888 Return 1 if there might still be unresolved debugging symbols, else 0. */
3890 static int scan_file_globals_1 PARAMS ((struct objfile *));
3893 scan_file_globals_1 (objfile)
3894 struct objfile *objfile;
3897 struct minimal_symbol *msymbol;
3898 struct symbol *sym, *prev;
3900 /* Avoid expensive loop through all minimal symbols if there are
3901 no unresolved symbols. */
3902 for (hash = 0; hash < HASHSIZE; hash++)
3904 if (global_sym_chain[hash])
3907 if (hash >= HASHSIZE)
3910 if (objfile->msymbols == 0) /* Beware the null file. */
3913 for (msymbol = objfile -> msymbols; SYMBOL_NAME (msymbol) != NULL; msymbol++)
3917 /* Skip static symbols. */
3918 switch (MSYMBOL_TYPE (msymbol))
3930 /* Get the hash index and check all the symbols
3931 under that hash index. */
3933 hash = hashname (SYMBOL_NAME (msymbol));
3935 for (sym = global_sym_chain[hash]; sym;)
3937 if (SYMBOL_NAME (msymbol)[0] == SYMBOL_NAME (sym)[0] &&
3938 STREQ(SYMBOL_NAME (msymbol) + 1, SYMBOL_NAME (sym) + 1))
3940 /* Splice this symbol out of the hash chain and
3941 assign the value we have to it. */
3944 SYMBOL_VALUE_CHAIN (prev) = SYMBOL_VALUE_CHAIN (sym);
3948 global_sym_chain[hash] = SYMBOL_VALUE_CHAIN (sym);
3951 /* Check to see whether we need to fix up a common block. */
3952 /* Note: this code might be executed several times for
3953 the same symbol if there are multiple references. */
3955 if (SYMBOL_CLASS (sym) == LOC_BLOCK)
3957 fix_common_block (sym, SYMBOL_VALUE_ADDRESS (msymbol));
3961 SYMBOL_VALUE_ADDRESS (sym) = SYMBOL_VALUE_ADDRESS (msymbol);
3964 SYMBOL_SECTION (sym) = SYMBOL_SECTION (msymbol);
3968 sym = SYMBOL_VALUE_CHAIN (prev);
3972 sym = global_sym_chain[hash];
3978 sym = SYMBOL_VALUE_CHAIN (sym);
3985 /* Assign values to global debugging symbols.
3986 Search the passed objfile first, then try the runtime common symbols.
3987 Complain about any remaining unresolved symbols and remove them
3991 scan_file_globals (objfile)
3992 struct objfile *objfile;
3995 struct symbol *sym, *prev;
3997 if (scan_file_globals_1 (objfile) == 0)
3999 if (rt_common_objfile && scan_file_globals_1 (rt_common_objfile) == 0)
4002 for (hash = 0; hash < HASHSIZE; hash++)
4004 sym = global_sym_chain[hash];
4007 complain (&unresolved_sym_chain_complaint,
4008 objfile->name, SYMBOL_NAME (sym));
4010 /* Change the symbol address from the misleading chain value
4013 sym = SYMBOL_VALUE_CHAIN (sym);
4014 SYMBOL_VALUE_ADDRESS (prev) = 0;
4017 memset (global_sym_chain, 0, sizeof (global_sym_chain));
4020 /* Initialize anything that needs initializing when starting to read
4021 a fresh piece of a symbol file, e.g. reading in the stuff corresponding
4029 /* Initialize anything that needs initializing when a completely new
4030 symbol file is specified (not just adding some symbols from another
4031 file, e.g. a shared library). */
4034 stabsread_new_init ()
4036 /* Empty the hash table of global syms looking for values. */
4037 memset (global_sym_chain, 0, sizeof (global_sym_chain));
4040 /* Initialize anything that needs initializing at the same time as
4041 start_symtab() is called. */
4045 global_stabs = NULL; /* AIX COFF */
4046 /* Leave FILENUM of 0 free for builtin types and this file's types. */
4047 n_this_object_header_files = 1;
4048 type_vector_length = 0;
4049 type_vector = (struct type **) 0;
4051 /* FIXME: If common_block_name is not already NULL, we should complain(). */
4052 common_block_name = NULL;
4057 /* Call after end_symtab() */
4063 free ((char *) type_vector);
4066 type_vector_length = 0;
4067 previous_stab_code = 0;
4071 finish_global_stabs (objfile)
4072 struct objfile *objfile;
4076 patch_block_stabs (global_symbols, global_stabs, objfile);
4077 free ((PTR) global_stabs);
4078 global_stabs = NULL;
4082 /* Initializer for this module */
4085 _initialize_stabsread ()
4087 undef_types_allocated = 20;
4088 undef_types_length = 0;
4089 undef_types = (struct type **)
4090 xmalloc (undef_types_allocated * sizeof (struct type *));