1 /* Support routines for decoding "stabs" debugging information format.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992
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., 675 Mass Ave, Cambridge, MA 02139, 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. */
32 #include "symfile.h" /* Needed for "struct complaint" */
34 #include "aout/stab_gnu.h" /* We always use GNU stabs, not native */
37 /* Ask stabsread.h to define the vars it normally declares `extern'. */
39 #include "stabsread.h" /* Our own declarations */
43 dbx_alloc_type
PARAMS ((int [2], struct objfile
*));
46 read_huge_number
PARAMS ((char **, int, long *, int *));
49 patch_block_stabs
PARAMS ((struct pending
*, struct pending_stabs
*,
53 fix_common_block
PARAMS ((struct symbol
*, int));
56 read_range_type
PARAMS ((char **, int [2], struct objfile
*));
59 read_sun_builtin_type
PARAMS ((char **, int [2], struct objfile
*));
62 read_sun_floating_type
PARAMS ((char **, int [2], struct objfile
*));
65 read_enum_type
PARAMS ((char **, struct type
*, struct objfile
*));
68 read_struct_type
PARAMS ((char **, struct type
*, struct objfile
*));
71 read_array_type
PARAMS ((char **, struct type
*, struct objfile
*));
74 read_args
PARAMS ((char **, int, struct objfile
*));
76 static const char vptr_name
[] = { '_','v','p','t','r',CPLUS_MARKER
,'\0' };
77 static const char vb_name
[] = { '_','v','b',CPLUS_MARKER
,'\0' };
79 /* Define this as 1 if a pcc declaration of a char or short argument
80 gives the correct address. Otherwise assume pcc gives the
81 address of the corresponding int, which is not the same on a
82 big-endian machine. */
84 #ifndef BELIEVE_PCC_PROMOTION
85 #define BELIEVE_PCC_PROMOTION 0
88 /* During some calls to read_type (and thus to read_range_type), this
89 contains the name of the type being defined. Range types are only
90 used in C as basic types. We use the name to distinguish the otherwise
91 identical basic types "int" and "long" and their unsigned versions.
92 FIXME, this should disappear with better type management. */
94 static char *long_kludge_name
;
97 struct complaint dbx_class_complaint
=
99 "encountered DBX-style class variable debugging information.\n\
100 You seem to have compiled your program with \
101 \"g++ -g0\" instead of \"g++ -g\".\n\
102 Therefore GDB will not know about your class variables", 0, 0
106 struct complaint invalid_cpp_abbrev_complaint
=
107 {"invalid C++ abbreviation `%s'", 0, 0};
109 struct complaint invalid_cpp_type_complaint
=
110 {"C++ abbreviated type name unknown at symtab pos %d", 0, 0};
112 struct complaint member_fn_complaint
=
113 {"member function type missing, got '%c'", 0, 0};
115 struct complaint const_vol_complaint
=
116 {"const/volatile indicator missing, got '%c'", 0, 0};
118 struct complaint error_type_complaint
=
119 {"debug info mismatch between compiler and debugger", 0, 0};
121 struct complaint invalid_member_complaint
=
122 {"invalid (minimal) member type data format at symtab pos %d.", 0, 0};
124 struct complaint range_type_base_complaint
=
125 {"base type %d of range type is not defined", 0, 0};
127 struct complaint reg_value_complaint
=
128 {"register number too large in symbol %s", 0, 0};
130 /* Make a list of forward references which haven't been defined. */
132 static struct type
**undef_types
;
133 static int undef_types_allocated
;
134 static int undef_types_length
;
141 register char *p
= name
;
142 register int total
= p
[0];
157 /* Ensure result is positive. */
160 total
+= (1000 << 6);
162 return (total
% HASHSIZE
);
166 /* Look up a dbx type-number pair. Return the address of the slot
167 where the type for that number-pair is stored.
168 The number-pair is in TYPENUMS.
170 This can be used for finding the type associated with that pair
171 or for associating a new type with the pair. */
174 dbx_lookup_type (typenums
)
177 register int filenum
= typenums
[0];
178 register int index
= typenums
[1];
180 register int real_filenum
;
181 register struct header_file
*f
;
184 if (filenum
== -1) /* -1,-1 is for temporary types. */
187 if (filenum
< 0 || filenum
>= n_this_object_header_files
)
188 error ("Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.",
189 filenum
, index
, symnum
);
193 /* Type is defined outside of header files.
194 Find it in this object file's type vector. */
195 if (index
>= type_vector_length
)
197 old_len
= type_vector_length
;
200 type_vector_length
= INITIAL_TYPE_VECTOR_LENGTH
;
201 type_vector
= (struct type
**)
202 malloc (type_vector_length
* sizeof (struct type
*));
204 while (index
>= type_vector_length
)
206 type_vector_length
*= 2;
208 type_vector
= (struct type
**)
209 xrealloc ((char *) type_vector
,
210 (type_vector_length
* sizeof (struct type
*)));
211 memset (&type_vector
[old_len
], 0,
212 (type_vector_length
- old_len
) * sizeof (struct type
*));
214 return (&type_vector
[index
]);
218 real_filenum
= this_object_header_files
[filenum
];
220 if (real_filenum
>= n_header_files
)
225 f
= &header_files
[real_filenum
];
227 f_orig_length
= f
->length
;
228 if (index
>= f_orig_length
)
230 while (index
>= f
->length
)
234 f
->vector
= (struct type
**)
235 xrealloc ((char *) f
->vector
, f
->length
* sizeof (struct type
*));
236 memset (&f
->vector
[f_orig_length
], 0,
237 (f
->length
- f_orig_length
) * sizeof (struct type
*));
239 return (&f
->vector
[index
]);
243 /* Make sure there is a type allocated for type numbers TYPENUMS
244 and return the type object.
245 This can create an empty (zeroed) type object.
246 TYPENUMS may be (-1, -1) to return a new type object that is not
247 put into the type vector, and so may not be referred to by number. */
250 dbx_alloc_type (typenums
, objfile
)
252 struct objfile
*objfile
;
254 register struct type
**type_addr
;
256 if (typenums
[0] == -1)
258 return (alloc_type (objfile
));
261 type_addr
= dbx_lookup_type (typenums
);
263 /* If we are referring to a type not known at all yet,
264 allocate an empty type for it.
265 We will fill it in later if we find out how. */
268 *type_addr
= alloc_type (objfile
);
274 /* for all the stabs in a given stab vector, build appropriate types
275 and fix their symbols in given symbol vector. */
278 patch_block_stabs (symbols
, stabs
, objfile
)
279 struct pending
*symbols
;
280 struct pending_stabs
*stabs
;
281 struct objfile
*objfile
;
291 /* for all the stab entries, find their corresponding symbols and
292 patch their types! */
294 for (ii
= 0; ii
< stabs
->count
; ++ii
)
296 name
= stabs
->stab
[ii
];
297 pp
= (char*) strchr (name
, ':');
298 sym
= find_symbol_in_list (symbols
, name
, pp
-name
);
301 #ifndef IBM6000_TARGET
302 printf ("ERROR! stab symbol not found!\n"); /* FIXME */
308 if (*(pp
-1) == 'F' || *(pp
-1) == 'f')
311 lookup_function_type (read_type (&pp
, objfile
));
315 SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
323 /* Read a number by which a type is referred to in dbx data,
324 or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
325 Just a single number N is equivalent to (0,N).
326 Return the two numbers by storing them in the vector TYPENUMS.
327 TYPENUMS will then be used as an argument to dbx_lookup_type. */
330 read_type_number (pp
, typenums
)
332 register int *typenums
;
337 typenums
[0] = read_number (pp
, ',');
338 typenums
[1] = read_number (pp
, ')');
343 typenums
[1] = read_number (pp
, 0);
348 /* To handle GNU C++ typename abbreviation, we need to be able to
349 fill in a type's name as soon as space for that type is allocated.
350 `type_synonym_name' is the name of the type being allocated.
351 It is cleared as soon as it is used (lest all allocated types
354 static char *type_synonym_name
;
358 define_symbol (valu
, string
, desc
, type
, objfile
)
363 struct objfile
*objfile
;
365 register struct symbol
*sym
;
366 char *p
= (char *) strchr (string
, ':');
370 struct type
*temptype
;
372 /* We would like to eliminate nameless symbols, but keep their types.
373 E.g. stab entry ":t10=*2" should produce a type 10, which is a pointer
374 to type 2, but, should not creat a symbol to address that type. Since
375 the symbol will be nameless, there is no way any user can refer to it. */
379 /* Ignore syms with empty names. */
383 /* Ignore old-style symbols from cc -go */
387 /* If a nameless stab entry, all we need is the type, not the symbol.
389 nameless
= (p
== string
);
391 sym
= (struct symbol
*)
392 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
394 if (processing_gcc_compilation
)
396 /* GCC 2.x puts the line number in desc. SunOS apparently puts in the
397 number of bytes occupied by a type or object, which we ignore. */
398 SYMBOL_LINE(sym
) = desc
;
402 SYMBOL_LINE(sym
) = 0; /* unknown */
405 if (string
[0] == CPLUS_MARKER
)
407 /* Special GNU C++ names. */
411 SYMBOL_NAME (sym
) = obsavestring ("this", strlen ("this"),
412 &objfile
-> symbol_obstack
);
415 case 'v': /* $vtbl_ptr_type */
416 /* Was: SYMBOL_NAME (sym) = "vptr"; */
420 SYMBOL_NAME (sym
) = obsavestring ("eh_throw", strlen ("eh_throw"),
421 &objfile
-> symbol_obstack
);
425 /* This was an anonymous type that was never fixed up. */
435 SYMBOL_NAME (sym
) = (char *)
436 obstack_alloc (&objfile
-> symbol_obstack
, ((p
- string
) + 1));
437 /* Open-coded bcopy--saves function call time. */
439 register char *p1
= string
;
440 register char *p2
= SYMBOL_NAME (sym
);
449 /* Determine the type of name being defined. */
450 /* The Acorn RISC machine's compiler can put out locals that don't
451 start with "234=" or "(3,4)=", so assume anything other than the
452 deftypes we know how to handle is a local. */
453 /* (Peter Watkins @ Computervision)
454 Handle Sun-style local fortran array types 'ar...' .
455 (gnu@cygnus.com) -- this strchr() handles them properly?
456 (tiemann@cygnus.com) -- 'C' is for catch. */
458 #ifdef IBM6000_TARGET
460 /* 'R' is for register parameters. */
462 if (!strchr ("cfFGpPrStTvVXCR", *p
))
466 if (!strchr ("cfFGpPrStTvVXC", *p
))
473 /* c is a special case, not followed by a type-number.
474 SYMBOL:c=iVALUE for an integer constant symbol.
475 SYMBOL:c=rVALUE for a floating constant symbol.
476 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
477 e.g. "b:c=e6,0" for "const b = blob1"
478 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
482 error ("Invalid symbol data at symtab pos %d.", symnum
);
490 SYMBOL_TYPE (sym
) = lookup_fundamental_type (objfile
,
493 obstack_alloc (&objfile
-> type_obstack
,
495 memcpy (dbl_valu
, &d
, sizeof (double));
496 SWAP_TARGET_AND_HOST (dbl_valu
, sizeof (double));
497 SYMBOL_VALUE_BYTES (sym
) = dbl_valu
;
498 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
503 SYMBOL_TYPE (sym
) = lookup_fundamental_type (objfile
,
505 SYMBOL_VALUE (sym
) = atoi (p
);
506 SYMBOL_CLASS (sym
) = LOC_CONST
;
510 /* SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
511 e.g. "b:c=e6,0" for "const b = blob1"
512 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
516 read_type_number (&p
, typenums
);
518 error ("Invalid symbol data: no comma in enum const symbol");
520 SYMBOL_TYPE (sym
) = *dbx_lookup_type (typenums
);
521 SYMBOL_VALUE (sym
) = atoi (p
);
522 SYMBOL_CLASS (sym
) = LOC_CONST
;
526 error ("Invalid symbol data at symtab pos %d.", symnum
);
528 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
529 add_symbol_to_list (sym
, &file_symbols
);
533 /* Now usually comes a number that says which data type,
534 and possibly more stuff to define the type
535 (all of which is handled by read_type) */
537 if (deftype
== 'p' && *p
== 'F')
538 /* pF is a two-letter code that means a function parameter in Fortran.
539 The type-number specifies the type of the return value.
540 Translate it into a pointer-to-function type. */
544 = lookup_pointer_type (lookup_function_type (read_type (&p
, objfile
)));
547 #ifdef IBM6000_TARGET
548 else if (deftype
== 'R')
549 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
554 /* The symbol class letter is followed by a type (typically the
555 type of the symbol, or its return-type, or etc). Read it. */
562 type_synonym_name
= obsavestring (SYMBOL_NAME (sym
),
563 strlen (SYMBOL_NAME (sym
)),
564 &objfile
-> symbol_obstack
);
567 /* Here we save the name of the symbol for read_range_type, which
568 ends up reading in the basic types. In stabs, unfortunately there
569 is no distinction between "int" and "long" types except their
570 names. Until we work out a saner type policy (eliminating most
571 builtin types and using the names specified in the files), we
572 save away the name so that far away from here in read_range_type,
573 we can examine it to decide between "int" and "long". FIXME. */
574 long_kludge_name
= SYMBOL_NAME (sym
);
576 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
582 /* The name of a caught exception. */
583 SYMBOL_CLASS (sym
) = LOC_LABEL
;
584 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
585 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
586 add_symbol_to_list (sym
, &local_symbols
);
590 /* A static function definition. */
591 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
592 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
593 add_symbol_to_list (sym
, &file_symbols
);
594 /* fall into process_function_types. */
596 process_function_types
:
597 /* Function result types are described as the result type in stabs.
598 We need to convert this to the function-returning-type-X type
599 in GDB. E.g. "int" is converted to "function returning int". */
600 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_FUNC
)
603 /* This code doesn't work -- it needs to realloc and can't. */
604 /* Attempt to set up to record a function prototype... */
605 struct type
*new = (struct type
*)
606 obstack_alloc (&objfile
-> type_obstack
,
607 sizeof (struct type
));
609 /* Generate a template for the type of this function. The
610 types of the arguments will be added as we read the symbol
612 *new = *lookup_function_type (SYMBOL_TYPE(sym
));
613 SYMBOL_TYPE(sym
) = new;
614 TYPE_OBJFILE (new) = objfile
;
615 in_function_type
= new;
617 SYMBOL_TYPE (sym
) = lookup_function_type (SYMBOL_TYPE (sym
));
620 /* fall into process_prototype_types */
622 process_prototype_types
:
623 /* Sun acc puts declared types of arguments here. We don't care
624 about their actual types (FIXME -- we should remember the whole
625 function prototype), but the list may define some new types
626 that we have to remember, so we must scan it now. */
629 read_type (&p
, objfile
);
634 /* A global function definition. */
635 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
636 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
637 add_symbol_to_list (sym
, &global_symbols
);
638 goto process_function_types
;
641 /* For a class G (global) symbol, it appears that the
642 value is not correct. It is necessary to search for the
643 corresponding linker definition to find the value.
644 These definitions appear at the end of the namelist. */
645 i
= hashname (SYMBOL_NAME (sym
));
646 SYMBOL_VALUE_CHAIN (sym
) = global_sym_chain
[i
];
647 global_sym_chain
[i
] = sym
;
648 SYMBOL_CLASS (sym
) = LOC_STATIC
;
649 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
650 add_symbol_to_list (sym
, &global_symbols
);
653 /* This case is faked by a conditional above,
654 when there is no code letter in the dbx data.
655 Dbx data never actually contains 'l'. */
657 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
658 SYMBOL_VALUE (sym
) = valu
;
659 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
660 add_symbol_to_list (sym
, &local_symbols
);
664 /* Normally this is a parameter, a LOC_ARG. On the i960, it
665 can also be a LOC_LOCAL_ARG depending on symbol type. */
666 #ifndef DBX_PARM_SYMBOL_CLASS
667 #define DBX_PARM_SYMBOL_CLASS(type) LOC_ARG
669 SYMBOL_CLASS (sym
) = DBX_PARM_SYMBOL_CLASS (type
);
670 SYMBOL_VALUE (sym
) = valu
;
671 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
673 /* This doesn't work yet. */
674 add_param_to_type (&in_function_type
, sym
);
676 add_symbol_to_list (sym
, &local_symbols
);
678 /* If it's gcc-compiled, if it says `short', believe it. */
679 if (processing_gcc_compilation
|| BELIEVE_PCC_PROMOTION
)
682 #if defined(BELIEVE_PCC_PROMOTION_TYPE)
683 /* This macro is defined on machines (e.g. sparc) where
684 we should believe the type of a PCC 'short' argument,
685 but shouldn't believe the address (the address is
686 the address of the corresponding int). Note that
687 this is only different from the BELIEVE_PCC_PROMOTION
688 case on big-endian machines.
690 My guess is that this correction, as opposed to changing
691 the parameter to an 'int' (as done below, for PCC
692 on most machines), is the right thing to do
693 on all machines, but I don't want to risk breaking
694 something that already works. On most PCC machines,
695 the sparc problem doesn't come up because the calling
696 function has to zero the top bytes (not knowing whether
697 the called function wants an int or a short), so there
698 is no practical difference between an int and a short
699 (except perhaps what happens when the GDB user types
700 "print short_arg = 0x10000;").
702 Hacked for SunOS 4.1 by gnu@cygnus.com. In 4.1, the compiler
703 actually produces the correct address (we don't need to fix it
704 up). I made this code adapt so that it will offset the symbol
705 if it was pointing at an int-aligned location and not
706 otherwise. This way you can use the same gdb for 4.0.x and
709 If the parameter is shorter than an int, and is integral
710 (e.g. char, short, or unsigned equivalent), and is claimed to
711 be passed on an integer boundary, don't believe it! Offset the
712 parameter's address to the tail-end of that integer. */
714 temptype
= lookup_fundamental_type (objfile
, FT_INTEGER
);
715 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (temptype
)
716 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
717 && 0 == SYMBOL_VALUE (sym
) % TYPE_LENGTH (temptype
))
719 SYMBOL_VALUE (sym
) += TYPE_LENGTH (temptype
)
720 - TYPE_LENGTH (SYMBOL_TYPE (sym
));
724 #else /* no BELIEVE_PCC_PROMOTION_TYPE. */
726 /* If PCC says a parameter is a short or a char,
727 it is really an int. */
728 temptype
= lookup_fundamental_type (objfile
, FT_INTEGER
);
729 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (temptype
)
730 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
)
732 SYMBOL_TYPE (sym
) = TYPE_UNSIGNED (SYMBOL_TYPE (sym
))
733 ? lookup_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
)
738 #endif /* no BELIEVE_PCC_PROMOTION_TYPE. */
741 /* acc seems to use P to delare the prototypes of functions that
742 are referenced by this file. gdb is not prepared to deal
743 with this extra information. FIXME, it ought to. */
745 goto process_prototype_types
;
747 /* Parameter which is in a register. */
748 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
749 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
750 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
752 complain (®_value_complaint
, SYMBOL_NAME (sym
));
753 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
755 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
756 add_symbol_to_list (sym
, &local_symbols
);
759 #ifdef IBM6000_TARGET
763 /* Register variable (either global or local). */
764 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
765 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
766 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
768 complain (®_value_complaint
, SYMBOL_NAME (sym
));
769 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
771 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
773 add_symbol_to_list (sym
, &local_symbols
);
775 add_symbol_to_list (sym
, &file_symbols
);
779 /* Static symbol at top level of file */
780 SYMBOL_CLASS (sym
) = LOC_STATIC
;
781 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
782 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
783 add_symbol_to_list (sym
, &file_symbols
);
787 /* For a nameless type, we don't want a create a symbol, thus we
788 did not use `sym'. Return without further processing. */
789 if (nameless
) return NULL
;
791 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
792 SYMBOL_VALUE (sym
) = valu
;
793 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
794 /* C++ vagaries: we may have a type which is derived from
795 a base type which did not have its name defined when the
796 derived class was output. We fill in the derived class's
797 base part member's name here in that case. */
798 if (TYPE_NAME (SYMBOL_TYPE (sym
)) != NULL
)
799 if ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
800 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
)
801 && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)))
804 for (j
= TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)) - 1; j
>= 0; j
--)
805 if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) == 0)
806 TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) =
807 type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym
), j
));
810 add_symbol_to_list (sym
, &file_symbols
);
814 /* For a nameless type, we don't want a create a symbol, thus we
815 did not use `sym'. Return without further processing. */
816 if (nameless
) return NULL
;
818 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
819 SYMBOL_VALUE (sym
) = valu
;
820 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
821 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
822 TYPE_NAME (SYMBOL_TYPE (sym
))
823 = obconcat (&objfile
-> type_obstack
, "",
824 (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_ENUM
826 : (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
827 ? "struct " : "union ")),
829 add_symbol_to_list (sym
, &file_symbols
);
833 register struct symbol
*typedef_sym
= (struct symbol
*)
834 obstack_alloc (&objfile
-> type_obstack
,
835 sizeof (struct symbol
));
836 SYMBOL_NAME (typedef_sym
) = SYMBOL_NAME (sym
);
837 SYMBOL_TYPE (typedef_sym
) = SYMBOL_TYPE (sym
);
839 SYMBOL_CLASS (typedef_sym
) = LOC_TYPEDEF
;
840 SYMBOL_VALUE (typedef_sym
) = valu
;
841 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
842 add_symbol_to_list (typedef_sym
, &file_symbols
);
847 /* Static symbol of local scope */
848 SYMBOL_CLASS (sym
) = LOC_STATIC
;
849 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
850 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
851 add_symbol_to_list (sym
, &local_symbols
);
855 /* Reference parameter */
856 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
857 SYMBOL_VALUE (sym
) = valu
;
858 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
859 add_symbol_to_list (sym
, &local_symbols
);
863 /* This is used by Sun FORTRAN for "function result value".
864 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
865 that Pascal uses it too, but when I tried it Pascal used
866 "x:3" (local symbol) instead. */
867 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
868 SYMBOL_VALUE (sym
) = valu
;
869 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
870 add_symbol_to_list (sym
, &local_symbols
);
874 error ("Invalid symbol data: unknown symbol-type code `%c' at symtab pos %d.", deftype
, symnum
);
880 /* Skip rest of this symbol and return an error type.
882 General notes on error recovery: error_type always skips to the
883 end of the symbol (modulo cretinous dbx symbol name continuation).
887 return error_type (pp);
889 is wrong because if *pp starts out pointing at '\0' (typically as the
890 result of an earlier error), it will be incremented to point to the
891 start of the next symbol, which might produce strange results, at least
892 if you run off the end of the string table. Instead use
895 return error_type (pp);
901 foo = error_type (pp);
905 And in case it isn't obvious, the point of all this hair is so the compiler
906 can define new types and new syntaxes, and old versions of the
907 debugger will be able to read the new symbol tables. */
913 complain (&error_type_complaint
, 0);
916 /* Skip to end of symbol. */
920 /* Check for and handle cretinous dbx symbol name continuation! */
921 if ((*pp
)[-1] == '\\')
922 *pp
= next_symbol_text ();
926 return builtin_type_error
;
930 /* Read a dbx type reference or definition;
931 return the type that is meant.
932 This can be just a number, in which case it references
933 a type already defined and placed in type_vector.
934 Or the number can be followed by an =, in which case
935 it means to define a new type according to the text that
939 read_type (pp
, objfile
)
941 struct objfile
*objfile
;
943 register struct type
*type
= 0;
948 /* Read type number if present. The type number may be omitted.
949 for instance in a two-dimensional array declared with type
950 "ar1;1;10;ar1;1;10;4". */
951 if ((**pp
>= '0' && **pp
<= '9')
954 read_type_number (pp
, typenums
);
956 /* Type is not being defined here. Either it already exists,
957 or this is a forward reference to it. dbx_alloc_type handles
960 return dbx_alloc_type (typenums
, objfile
);
962 /* Type is being defined here. */
963 #if 0 /* Callers aren't prepared for a NULL result! FIXME -- metin! */
967 /* if such a type already exists, this is an unnecessary duplication
968 of the stab string, which is common in (RS/6000) xlc generated
969 objects. In that case, simply return NULL and let the caller take
972 tt
= *dbx_lookup_type (typenums
);
973 if (tt
&& tt
->length
&& tt
->code
)
982 /* 'typenums=' not present, type is anonymous. Read and return
983 the definition, but don't put it in the type vector. */
984 typenums
[0] = typenums
[1] = -1;
994 /* Used to index through file_symbols. */
998 /* Name including "struct", etc. */
1001 /* Name without "struct", etc. */
1002 char *type_name_only
;
1008 /* Set the type code according to the following letter. */
1012 code
= TYPE_CODE_STRUCT
;
1016 code
= TYPE_CODE_UNION
;
1020 code
= TYPE_CODE_ENUM
;
1024 return error_type (pp
);
1027 to
= type_name
= (char *)
1028 obstack_alloc (&objfile
-> type_obstack
,
1030 ((char *) strchr (*pp
, ':') - (*pp
)) + 1));
1032 /* Copy the prefix. */
1034 while (*to
++ = *from
++)
1038 type_name_only
= to
;
1040 /* Copy the name. */
1042 while ((*to
++ = *from
++) != ':')
1046 /* Set the pointer ahead of the name which we just read. */
1050 /* The following hack is clearly wrong, because it doesn't
1051 check whether we are in a baseclass. I tried to reproduce
1052 the case that it is trying to fix, but I couldn't get
1053 g++ to put out a cross reference to a basetype. Perhaps
1054 it doesn't do it anymore. */
1055 /* Note: for C++, the cross reference may be to a base type which
1056 has not yet been seen. In this case, we skip to the comma,
1057 which will mark the end of the base class name. (The ':'
1058 at the end of the base class name will be skipped as well.)
1059 But sometimes (ie. when the cross ref is the last thing on
1060 the line) there will be no ','. */
1061 from
= (char *) strchr (*pp
, ',');
1067 /* Now check to see whether the type has already been declared. */
1068 /* This is necessary at least in the case where the
1069 program says something like
1071 The compiler puts out a cross-reference; we better find
1072 set the length of the structure correctly so we can
1073 set the length of the array. */
1074 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
1075 for (i
= 0; i
< ppt
->nsyms
; i
++)
1077 struct symbol
*sym
= ppt
->symbol
[i
];
1079 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
1080 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
1081 && (TYPE_CODE (SYMBOL_TYPE (sym
)) == code
)
1082 && !strcmp (SYMBOL_NAME (sym
), type_name_only
))
1084 obstack_free (&objfile
-> type_obstack
, type_name
);
1085 type
= SYMBOL_TYPE (sym
);
1090 /* Didn't find the type to which this refers, so we must
1091 be dealing with a forward reference. Allocate a type
1092 structure for it, and keep track of it so we can
1093 fill in the rest of the fields when we get the full
1095 type
= dbx_alloc_type (typenums
, objfile
);
1096 TYPE_CODE (type
) = code
;
1097 TYPE_NAME (type
) = type_name
;
1098 INIT_CPLUS_SPECIFIC(type
);
1099 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
1101 add_undefined_type (type
);
1105 case '-': /* RS/6000 built-in type */
1107 type
= builtin_type (pp
); /* (in xcoffread.c) */
1122 read_type_number (pp
, xtypenums
);
1123 type
= *dbx_lookup_type (xtypenums
);
1128 type
= lookup_fundamental_type (objfile
, FT_VOID
);
1129 if (typenums
[0] != -1)
1130 *dbx_lookup_type (typenums
) = type
;
1133 /* In the following types, we must be sure to overwrite any existing
1134 type that the typenums refer to, rather than allocating a new one
1135 and making the typenums point to the new one. This is because there
1136 may already be pointers to the existing type (if it had been
1137 forward-referenced), and we must change it to a pointer, function,
1138 reference, or whatever, *in-place*. */
1141 type1
= read_type (pp
, objfile
);
1142 type
= make_pointer_type (type1
, dbx_lookup_type (typenums
));
1145 case '&': /* Reference to another type */
1146 type1
= read_type (pp
, objfile
);
1147 type
= make_reference_type (type1
, dbx_lookup_type (typenums
));
1150 case 'f': /* Function returning another type */
1151 type1
= read_type (pp
, objfile
);
1152 type
= make_function_type (type1
, dbx_lookup_type (typenums
));
1155 case 'k': /* Const qualifier on some type (Sun) */
1156 type
= read_type (pp
, objfile
);
1157 /* FIXME! For now, we ignore const and volatile qualifiers. */
1160 case 'B': /* Volatile qual on some type (Sun) */
1161 type
= read_type (pp
, objfile
);
1162 /* FIXME! For now, we ignore const and volatile qualifiers. */
1165 /* FIXME -- we should be doing smash_to_XXX types here. */
1166 case '@': /* Member (class & variable) type */
1168 struct type
*domain
= read_type (pp
, objfile
);
1169 struct type
*memtype
;
1172 /* Invalid member type data format. */
1173 return error_type (pp
);
1176 memtype
= read_type (pp
, objfile
);
1177 type
= dbx_alloc_type (typenums
, objfile
);
1178 smash_to_member_type (type
, domain
, memtype
);
1182 case '#': /* Method (class & fn) type */
1183 if ((*pp
)[0] == '#')
1185 /* We'll get the parameter types from the name. */
1186 struct type
*return_type
;
1189 return_type
= read_type (pp
, objfile
);
1190 if (*(*pp
)++ != ';')
1191 complain (&invalid_member_complaint
, (char *) symnum
);
1192 type
= allocate_stub_method (return_type
);
1193 if (typenums
[0] != -1)
1194 *dbx_lookup_type (typenums
) = type
;
1198 struct type
*domain
= read_type (pp
, objfile
);
1199 struct type
*return_type
;
1202 if (*(*pp
)++ != ',')
1203 error ("invalid member type data format, at symtab pos %d.",
1206 return_type
= read_type (pp
, objfile
);
1207 args
= read_args (pp
, ';', objfile
);
1208 type
= dbx_alloc_type (typenums
, objfile
);
1209 smash_to_method_type (type
, domain
, return_type
, args
);
1213 case 'r': /* Range type */
1214 type
= read_range_type (pp
, typenums
, objfile
);
1215 if (typenums
[0] != -1)
1216 *dbx_lookup_type (typenums
) = type
;
1219 case 'b': /* Sun ACC builtin int type */
1220 type
= read_sun_builtin_type (pp
, typenums
, objfile
);
1221 if (typenums
[0] != -1)
1222 *dbx_lookup_type (typenums
) = type
;
1225 case 'R': /* Sun ACC builtin float type */
1226 type
= read_sun_floating_type (pp
, typenums
, objfile
);
1227 if (typenums
[0] != -1)
1228 *dbx_lookup_type (typenums
) = type
;
1231 case 'e': /* Enumeration type */
1232 type
= dbx_alloc_type (typenums
, objfile
);
1233 type
= read_enum_type (pp
, type
, objfile
);
1234 *dbx_lookup_type (typenums
) = type
;
1237 case 's': /* Struct type */
1238 type
= dbx_alloc_type (typenums
, objfile
);
1239 if (!TYPE_NAME (type
))
1240 TYPE_NAME (type
) = type_synonym_name
;
1241 type_synonym_name
= 0;
1242 type
= read_struct_type (pp
, type
, objfile
);
1245 case 'u': /* Union type */
1246 type
= dbx_alloc_type (typenums
, objfile
);
1247 if (!TYPE_NAME (type
))
1248 TYPE_NAME (type
) = type_synonym_name
;
1249 type_synonym_name
= 0;
1250 type
= read_struct_type (pp
, type
, objfile
);
1251 TYPE_CODE (type
) = TYPE_CODE_UNION
;
1254 case 'a': /* Array type */
1256 return error_type (pp
);
1259 type
= dbx_alloc_type (typenums
, objfile
);
1260 type
= read_array_type (pp
, type
, objfile
);
1264 --*pp
; /* Go back to the symbol in error */
1265 /* Particularly important if it was \0! */
1266 return error_type (pp
);
1275 /* This page contains subroutines of read_type. */
1277 /* Read the description of a structure (or union type)
1278 and return an object describing the type. */
1280 static struct type
*
1281 read_struct_type (pp
, type
, objfile
)
1283 register struct type
*type
;
1284 struct objfile
*objfile
;
1286 /* Total number of methods defined in this class.
1287 If the class defines two `f' methods, and one `g' method,
1288 then this will have the value 3. */
1289 int total_length
= 0;
1293 struct nextfield
*next
;
1294 int visibility
; /* 0=public, 1=protected, 2=public */
1300 struct next_fnfield
*next
;
1301 struct fn_field fn_field
;
1304 struct next_fnfieldlist
1306 struct next_fnfieldlist
*next
;
1307 struct fn_fieldlist fn_fieldlist
;
1310 register struct nextfield
*list
= 0;
1311 struct nextfield
*new;
1314 int non_public_fields
= 0;
1317 register struct next_fnfieldlist
*mainlist
= 0;
1320 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
1321 INIT_CPLUS_SPECIFIC(type
);
1322 TYPE_FLAGS (type
) &= ~TYPE_FLAG_STUB
;
1324 /* First comes the total size in bytes. */
1326 TYPE_LENGTH (type
) = read_number (pp
, 0);
1328 /* C++: Now, if the class is a derived class, then the next character
1329 will be a '!', followed by the number of base classes derived from.
1330 Each element in the list contains visibility information,
1331 the offset of this base class in the derived structure,
1332 and then the base type. */
1335 int i
, n_baseclasses
, offset
;
1336 struct type
*baseclass
;
1339 /* Nonzero if it is a virtual baseclass, i.e.,
1343 struct C : public B, public virtual A {};
1345 B is a baseclass of C; A is a virtual baseclass for C. This is a C++
1346 2.0 language feature. */
1351 ALLOCATE_CPLUS_STRUCT_TYPE(type
);
1353 n_baseclasses
= read_number (pp
, ',');
1354 TYPE_FIELD_VIRTUAL_BITS (type
) =
1355 (B_TYPE
*) obstack_alloc (&objfile
-> type_obstack
,
1356 B_BYTES (n_baseclasses
));
1357 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), n_baseclasses
);
1359 for (i
= 0; i
< n_baseclasses
; i
++)
1362 *pp
= next_symbol_text ();
1373 /* Bad visibility format. */
1374 return error_type (pp
);
1382 non_public_fields
++;
1388 /* Bad visibility format. */
1389 return error_type (pp
);
1392 SET_TYPE_FIELD_VIRTUAL (type
, i
);
1395 /* Offset of the portion of the object corresponding to
1396 this baseclass. Always zero in the absence of
1397 multiple inheritance. */
1398 offset
= read_number (pp
, ',');
1399 baseclass
= read_type (pp
, objfile
);
1400 *pp
+= 1; /* skip trailing ';' */
1402 /* Make this baseclass visible for structure-printing purposes. */
1403 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
1404 memset (new, 0, sizeof (struct nextfield
));
1407 list
->visibility
= via_public
;
1408 list
->field
.type
= baseclass
;
1409 list
->field
.name
= type_name_no_tag (baseclass
);
1410 list
->field
.bitpos
= offset
;
1411 list
->field
.bitsize
= 0; /* this should be an unpacked field! */
1414 TYPE_N_BASECLASSES (type
) = n_baseclasses
;
1417 /* Now come the fields, as NAME:?TYPENUM,BITPOS,BITSIZE; for each one.
1418 At the end, we see a semicolon instead of a field.
1420 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
1423 The `?' is a placeholder for one of '/2' (public visibility),
1424 '/1' (protected visibility), '/0' (private visibility), or nothing
1425 (C style symbol table, public visibility). */
1427 /* We better set p right now, in case there are no fields at all... */
1432 /* Check for and handle cretinous dbx symbol name continuation! */
1433 if (**pp
== '\\') *pp
= next_symbol_text ();
1435 /* Get space to record the next field's data. */
1436 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
1437 memset (new, 0, sizeof (struct nextfield
));
1441 /* Get the field name. */
1443 if (*p
== CPLUS_MARKER
)
1445 /* Special GNU C++ name. */
1450 struct type
*context
;
1461 complain (&invalid_cpp_abbrev_complaint
, *pp
);
1462 prefix
= "INVALID_C++_ABBREV";
1466 context
= read_type (pp
, objfile
);
1467 name
= type_name_no_tag (context
);
1470 complain (&invalid_cpp_type_complaint
, (char *) symnum
);
1473 list
->field
.name
= obconcat (&objfile
-> type_obstack
,
1477 complain (&invalid_cpp_abbrev_complaint
, *pp
);
1478 list
->field
.type
= read_type (pp
, objfile
);
1479 (*pp
)++; /* Skip the comma. */
1480 list
->field
.bitpos
= read_number (pp
, ';');
1481 /* This field is unpacked. */
1482 list
->field
.bitsize
= 0;
1483 list
->visibility
= 0; /* private */
1484 non_public_fields
++;
1486 /* GNU C++ anonymous type. */
1490 complain (&invalid_cpp_abbrev_complaint
, *pp
);
1496 while (*p
!= ':') p
++;
1497 list
->field
.name
= obsavestring (*pp
, p
- *pp
,
1498 &objfile
-> type_obstack
);
1500 /* C++: Check to see if we have hit the methods yet. */
1506 /* This means we have a visibility for a field coming. */
1512 list
->visibility
= 0; /* private */
1513 non_public_fields
++;
1518 list
->visibility
= 1; /* protected */
1519 non_public_fields
++;
1524 list
->visibility
= 2; /* public */
1529 else /* normal dbx-style format. */
1530 list
->visibility
= 2; /* public */
1532 list
->field
.type
= read_type (pp
, objfile
);
1537 /* Possible future hook for nested types. */
1540 list
->field
.bitpos
= (long)-2; /* nested type */
1545 { /* Static class member. */
1546 list
->field
.bitpos
= (long)-1;
1548 while (*p
!= ';') p
++;
1549 list
->field
.bitsize
= (long) savestring (*pp
, p
- *pp
);
1554 else if (**pp
!= ',')
1555 /* Bad structure-type format. */
1556 return error_type (pp
);
1558 (*pp
)++; /* Skip the comma. */
1559 list
->field
.bitpos
= read_number (pp
, ',');
1560 list
->field
.bitsize
= read_number (pp
, ';');
1563 /* FIXME-tiemann: Can't the compiler put out something which
1564 lets us distinguish these? (or maybe just not put out anything
1565 for the field). What is the story here? What does the compiler
1566 really do? Also, patch gdb.texinfo for this case; I document
1567 it as a possible problem there. Search for "DBX-style". */
1569 /* This is wrong because this is identical to the symbols
1570 produced for GCC 0-size arrays. For example:
1575 The code which dumped core in such circumstances should be
1576 fixed not to dump core. */
1578 /* g++ -g0 can put out bitpos & bitsize zero for a static
1579 field. This does not give us any way of getting its
1580 class, so we can't know its name. But we can just
1581 ignore the field so we don't dump core and other nasty
1583 if (list
->field
.bitpos
== 0
1584 && list
->field
.bitsize
== 0)
1586 complain (&dbx_class_complaint
, 0);
1587 /* Ignore this field. */
1593 /* Detect an unpacked field and mark it as such.
1594 dbx gives a bit size for all fields.
1595 Note that forward refs cannot be packed,
1596 and treat enums as if they had the width of ints. */
1597 if (TYPE_CODE (list
->field
.type
) != TYPE_CODE_INT
1598 && TYPE_CODE (list
->field
.type
) != TYPE_CODE_ENUM
)
1599 list
->field
.bitsize
= 0;
1600 if ((list
->field
.bitsize
== 8 * TYPE_LENGTH (list
->field
.type
)
1601 || (TYPE_CODE (list
->field
.type
) == TYPE_CODE_ENUM
1602 && (list
->field
.bitsize
1603 == 8 * TYPE_LENGTH (lookup_fundamental_type (objfile
, FT_INTEGER
)))
1607 list
->field
.bitpos
% 8 == 0)
1608 list
->field
.bitsize
= 0;
1614 /* chill the list of fields: the last entry (at the head)
1615 is a partially constructed entry which we now scrub. */
1618 /* Now create the vector of fields, and record how big it is.
1619 We need this info to record proper virtual function table information
1620 for this class's virtual functions. */
1622 TYPE_NFIELDS (type
) = nfields
;
1623 TYPE_FIELDS (type
) = (struct field
*)
1624 obstack_alloc (&objfile
-> type_obstack
, sizeof (struct field
) * nfields
);
1626 if (non_public_fields
)
1628 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1630 TYPE_FIELD_PRIVATE_BITS (type
) =
1631 (B_TYPE
*) obstack_alloc (&objfile
-> type_obstack
,
1633 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
1635 TYPE_FIELD_PROTECTED_BITS (type
) =
1636 (B_TYPE
*) obstack_alloc (&objfile
-> type_obstack
,
1638 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
1641 /* Copy the saved-up fields into the field vector. */
1643 for (n
= nfields
; list
; list
= list
->next
)
1646 TYPE_FIELD (type
, n
) = list
->field
;
1647 if (list
->visibility
== 0)
1648 SET_TYPE_FIELD_PRIVATE (type
, n
);
1649 else if (list
->visibility
== 1)
1650 SET_TYPE_FIELD_PROTECTED (type
, n
);
1653 /* Now come the method fields, as NAME::methods
1654 where each method is of the form TYPENUM,ARGS,...:PHYSNAME;
1655 At the end, we see a semicolon instead of a field.
1657 For the case of overloaded operators, the format is
1658 op$::*.methods, where $ is the CPLUS_MARKER (usually '$'),
1659 `*' holds the place for an operator name (such as `+=')
1660 and `.' marks the end of the operator name. */
1663 /* Now, read in the methods. To simplify matters, we
1664 "unread" the name that has been read, so that we can
1665 start from the top. */
1667 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1668 /* For each list of method lists... */
1672 struct next_fnfield
*sublist
= 0;
1673 struct type
*look_ahead_type
= NULL
;
1675 struct next_fnfieldlist
*new_mainlist
;
1678 new_mainlist
= (struct next_fnfieldlist
*)
1679 alloca (sizeof (struct next_fnfieldlist
));
1680 memset (new_mainlist
, 0, sizeof (struct next_fnfieldlist
));
1684 /* read in the name. */
1685 while (*p
!= ':') p
++;
1686 if ((*pp
)[0] == 'o' && (*pp
)[1] == 'p' && (*pp
)[2] == CPLUS_MARKER
)
1688 /* This is a completely wierd case. In order to stuff in the
1689 names that might contain colons (the usual name delimiter),
1690 Mike Tiemann defined a different name format which is
1691 signalled if the identifier is "op$". In that case, the
1692 format is "op$::XXXX." where XXXX is the name. This is
1693 used for names like "+" or "=". YUUUUUUUK! FIXME! */
1694 /* This lets the user type "break operator+".
1695 We could just put in "+" as the name, but that wouldn't
1697 static char opname
[32] = {'o', 'p', CPLUS_MARKER
};
1698 char *o
= opname
+ 3;
1700 /* Skip past '::'. */
1702 if (**pp
== '\\') *pp
= next_symbol_text ();
1706 main_fn_name
= savestring (opname
, o
- opname
);
1712 main_fn_name
= savestring (*pp
, p
- *pp
);
1713 /* Skip past '::'. */
1716 new_mainlist
->fn_fieldlist
.name
= main_fn_name
;
1720 struct next_fnfield
*new_sublist
=
1721 (struct next_fnfield
*) alloca (sizeof (struct next_fnfield
));
1722 memset (new_sublist
, 0, sizeof (struct next_fnfield
));
1724 /* Check for and handle cretinous dbx symbol name continuation! */
1725 if (look_ahead_type
== NULL
) /* Normal case. */
1727 if (**pp
== '\\') *pp
= next_symbol_text ();
1729 new_sublist
->fn_field
.type
= read_type (pp
, objfile
);
1731 /* Invalid symtab info for method. */
1732 return error_type (pp
);
1735 { /* g++ version 1 kludge */
1736 new_sublist
->fn_field
.type
= look_ahead_type
;
1737 look_ahead_type
= NULL
;
1742 while (*p
!= ';') p
++;
1744 /* If this is just a stub, then we don't have the
1746 if (TYPE_FLAGS (new_sublist
->fn_field
.type
) & TYPE_FLAG_STUB
)
1747 new_sublist
->fn_field
.is_stub
= 1;
1748 new_sublist
->fn_field
.physname
= savestring (*pp
, p
- *pp
);
1751 /* Set this method's visibility fields. */
1752 switch (*(*pp
)++ - '0')
1755 new_sublist
->fn_field
.is_private
= 1;
1758 new_sublist
->fn_field
.is_protected
= 1;
1762 if (**pp
== '\\') *pp
= next_symbol_text ();
1765 case 'A': /* Normal functions. */
1766 new_sublist
->fn_field
.is_const
= 0;
1767 new_sublist
->fn_field
.is_volatile
= 0;
1770 case 'B': /* `const' member functions. */
1771 new_sublist
->fn_field
.is_const
= 1;
1772 new_sublist
->fn_field
.is_volatile
= 0;
1775 case 'C': /* `volatile' member function. */
1776 new_sublist
->fn_field
.is_const
= 0;
1777 new_sublist
->fn_field
.is_volatile
= 1;
1780 case 'D': /* `const volatile' member function. */
1781 new_sublist
->fn_field
.is_const
= 1;
1782 new_sublist
->fn_field
.is_volatile
= 1;
1785 case '*': /* File compiled with g++ version 1 -- no info */
1790 complain (&const_vol_complaint
, (char *) (long) **pp
);
1797 /* virtual member function, followed by index. */
1798 /* The sign bit is set to distinguish pointers-to-methods
1799 from virtual function indicies. Since the array is
1800 in words, the quantity must be shifted left by 1
1801 on 16 bit machine, and by 2 on 32 bit machine, forcing
1802 the sign bit out, and usable as a valid index into
1803 the array. Remove the sign bit here. */
1804 new_sublist
->fn_field
.voffset
=
1805 (0x7fffffff & read_number (pp
, ';')) + 2;
1807 if (**pp
== '\\') *pp
= next_symbol_text ();
1809 if (**pp
== ';' || **pp
== '\0')
1810 /* Must be g++ version 1. */
1811 new_sublist
->fn_field
.fcontext
= 0;
1814 /* Figure out from whence this virtual function came.
1815 It may belong to virtual function table of
1816 one of its baseclasses. */
1817 look_ahead_type
= read_type (pp
, objfile
);
1819 { /* g++ version 1 overloaded methods. */ }
1822 new_sublist
->fn_field
.fcontext
= look_ahead_type
;
1824 return error_type (pp
);
1827 look_ahead_type
= NULL
;
1833 /* static member function. */
1834 new_sublist
->fn_field
.voffset
= VOFFSET_STATIC
;
1835 if (strncmp (new_sublist
->fn_field
.physname
,
1836 main_fn_name
, strlen (main_fn_name
)))
1837 new_sublist
->fn_field
.is_stub
= 1;
1842 complain (&member_fn_complaint
, (char *) (long) (*pp
)[-1]);
1843 /* Fall through into normal member function. */
1846 /* normal member function. */
1847 new_sublist
->fn_field
.voffset
= 0;
1848 new_sublist
->fn_field
.fcontext
= 0;
1852 new_sublist
->next
= sublist
;
1853 sublist
= new_sublist
;
1855 if (**pp
== '\\') *pp
= next_symbol_text ();
1857 while (**pp
!= ';' && **pp
!= '\0');
1861 new_mainlist
->fn_fieldlist
.fn_fields
=
1862 (struct fn_field
*) obstack_alloc (&objfile
-> type_obstack
,
1863 sizeof (struct fn_field
) * length
);
1864 for (i
= length
; (i
--, sublist
); sublist
= sublist
->next
)
1865 new_mainlist
->fn_fieldlist
.fn_fields
[i
] = sublist
->fn_field
;
1867 new_mainlist
->fn_fieldlist
.length
= length
;
1868 new_mainlist
->next
= mainlist
;
1869 mainlist
= new_mainlist
;
1871 total_length
+= length
;
1872 if (**pp
== '\\') *pp
= next_symbol_text ();
1874 while (**pp
!= ';');
1882 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
1883 obstack_alloc (&objfile
-> type_obstack
,
1884 sizeof (struct fn_fieldlist
) * nfn_fields
);
1885 TYPE_NFN_FIELDS (type
) = nfn_fields
;
1886 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
1891 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); ++i
)
1893 if (TYPE_CODE (TYPE_BASECLASS (type
, i
)) == TYPE_CODE_UNDEF
)
1894 /* @@ Memory leak on objfile->type_obstack? */
1895 return error_type (pp
);
1896 TYPE_NFN_FIELDS_TOTAL (type
) +=
1897 TYPE_NFN_FIELDS_TOTAL (TYPE_BASECLASS (type
, i
));
1901 for (n
= nfn_fields
; mainlist
; mainlist
= mainlist
->next
) {
1902 --n
; /* Circumvent Sun3 compiler bug */
1903 TYPE_FN_FIELDLISTS (type
)[n
] = mainlist
->fn_fieldlist
;
1910 if (**pp
== '=' || **pp
== '+' || **pp
== '-')
1912 /* Obsolete flags that used to indicate the presence
1913 of constructors and/or destructors. */
1917 /* Read either a '%' or the final ';'. */
1918 if (*(*pp
)++ == '%')
1920 /* We'd like to be able to derive the vtable pointer field
1921 from the type information, but when it's inherited, that's
1922 hard. A reason it's hard is because we may read in the
1923 info about a derived class before we read in info about
1924 the base class that provides the vtable pointer field.
1925 Once the base info has been read, we could fill in the info
1926 for the derived classes, but for the fact that by then,
1927 we don't remember who needs what. */
1930 int predicted_fieldno
= -1;
1933 /* Now we must record the virtual function table pointer's
1934 field information. */
1942 /* In version 2, we derive the vfield ourselves. */
1943 for (n
= 0; n
< nfields
; n
++)
1945 if (! strncmp (TYPE_FIELD_NAME (type
, n
), vptr_name
,
1946 sizeof (vptr_name
) -1))
1948 predicted_fieldno
= n
;
1952 if (predicted_fieldno
< 0)
1953 for (n
= 0; n
< TYPE_N_BASECLASSES (type
); n
++)
1954 if (! TYPE_FIELD_VIRTUAL (type
, n
)
1955 && TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type
, n
)) >= 0)
1957 predicted_fieldno
= TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type
, n
));
1963 t
= read_type (pp
, objfile
);
1965 while (*p
!= '\0' && *p
!= ';')
1968 /* Premature end of symbol. */
1969 return error_type (pp
);
1971 TYPE_VPTR_BASETYPE (type
) = t
;
1974 if (TYPE_FIELD_NAME (t
, TYPE_N_BASECLASSES (t
)) == 0)
1976 /* FIXME-tiemann: what's this? */
1978 TYPE_VPTR_FIELDNO (type
) = i
= TYPE_N_BASECLASSES (t
);
1983 else for (i
= TYPE_NFIELDS (t
) - 1; i
>= TYPE_N_BASECLASSES (t
); --i
)
1984 if (! strncmp (TYPE_FIELD_NAME (t
, i
), vptr_name
,
1985 sizeof (vptr_name
) - 1))
1987 TYPE_VPTR_FIELDNO (type
) = i
;
1991 /* Virtual function table field not found. */
1992 return error_type (pp
);
1995 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
1998 if (TYPE_VPTR_FIELDNO (type
) != predicted_fieldno
)
1999 error ("TYPE_VPTR_FIELDNO miscalculated");
2009 /* Read a definition of an array type,
2010 and create and return a suitable type object.
2011 Also creates a range type which represents the bounds of that
2014 static struct type
*
2015 read_array_type (pp
, type
, objfile
)
2017 register struct type
*type
;
2018 struct objfile
*objfile
;
2020 struct type
*index_type
, *element_type
, *range_type
;
2024 /* Format of an array type:
2025 "ar<index type>;lower;upper;<array_contents_type>". Put code in
2028 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
2029 for these, produce a type like float[][]. */
2031 index_type
= read_type (pp
, objfile
);
2033 /* Improper format of array type decl. */
2034 return error_type (pp
);
2037 if (!(**pp
>= '0' && **pp
<= '9'))
2042 lower
= read_number (pp
, ';');
2044 if (!(**pp
>= '0' && **pp
<= '9'))
2049 upper
= read_number (pp
, ';');
2051 element_type
= read_type (pp
, objfile
);
2060 /* Create range type. */
2061 range_type
= (struct type
*)
2062 obstack_alloc (&objfile
-> type_obstack
, sizeof (struct type
));
2063 memset (range_type
, 0, sizeof (struct type
));
2064 TYPE_OBJFILE (range_type
) = objfile
;
2065 TYPE_CODE (range_type
) = TYPE_CODE_RANGE
;
2066 TYPE_TARGET_TYPE (range_type
) = index_type
;
2068 /* This should never be needed. */
2069 TYPE_LENGTH (range_type
) = sizeof (int);
2071 TYPE_NFIELDS (range_type
) = 2;
2072 TYPE_FIELDS (range_type
) =
2073 (struct field
*) obstack_alloc (&objfile
-> type_obstack
,
2074 2 * sizeof (struct field
));
2075 TYPE_FIELD_BITPOS (range_type
, 0) = lower
;
2076 TYPE_FIELD_BITPOS (range_type
, 1) = upper
;
2079 TYPE_CODE (type
) = TYPE_CODE_ARRAY
;
2080 TYPE_TARGET_TYPE (type
) = element_type
;
2081 TYPE_LENGTH (type
) = (upper
- lower
+ 1) * TYPE_LENGTH (element_type
);
2082 TYPE_NFIELDS (type
) = 1;
2083 TYPE_FIELDS (type
) =
2084 (struct field
*) obstack_alloc (&objfile
-> type_obstack
,
2085 sizeof (struct field
));
2086 TYPE_FIELD_TYPE (type
, 0) = range_type
;
2088 /* If we have an array whose element type is not yet known, but whose
2089 bounds *are* known, record it to be adjusted at the end of the file. */
2090 if (TYPE_LENGTH (element_type
) == 0 && !adjustable
)
2091 add_undefined_type (type
);
2097 /* Read a definition of an enumeration type,
2098 and create and return a suitable type object.
2099 Also defines the symbols that represent the values of the type. */
2101 static struct type
*
2102 read_enum_type (pp
, type
, objfile
)
2104 register struct type
*type
;
2105 struct objfile
*objfile
;
2110 register struct symbol
*sym
;
2112 struct pending
**symlist
;
2113 struct pending
*osyms
, *syms
;
2117 /* FIXME! The stabs produced by Sun CC merrily define things that ought
2118 to be file-scope, between N_FN entries, using N_LSYM. What's a mother
2119 to do? For now, force all enum values to file scope. */
2120 if (within_function
)
2121 symlist
= &local_symbols
;
2124 symlist
= &file_symbols
;
2126 o_nsyms
= osyms
? osyms
->nsyms
: 0;
2128 /* Read the value-names and their values.
2129 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
2130 A semicolon or comma instead of a NAME means the end. */
2131 while (**pp
&& **pp
!= ';' && **pp
!= ',')
2133 /* Check for and handle cretinous dbx symbol name continuation! */
2134 if (**pp
== '\\') *pp
= next_symbol_text ();
2137 while (*p
!= ':') p
++;
2138 name
= obsavestring (*pp
, p
- *pp
, &objfile
-> symbol_obstack
);
2140 n
= read_number (pp
, ',');
2142 sym
= (struct symbol
*) obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
2143 memset (sym
, 0, sizeof (struct symbol
));
2144 SYMBOL_NAME (sym
) = name
;
2145 SYMBOL_CLASS (sym
) = LOC_CONST
;
2146 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2147 SYMBOL_VALUE (sym
) = n
;
2148 add_symbol_to_list (sym
, symlist
);
2153 (*pp
)++; /* Skip the semicolon. */
2155 /* Now fill in the fields of the type-structure. */
2157 TYPE_LENGTH (type
) = sizeof (int);
2158 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2159 TYPE_FLAGS (type
) &= ~TYPE_FLAG_STUB
;
2160 TYPE_NFIELDS (type
) = nsyms
;
2161 TYPE_FIELDS (type
) = (struct field
*)
2162 obstack_alloc (&objfile
-> type_obstack
,
2163 sizeof (struct field
) * nsyms
);
2165 /* Find the symbols for the values and put them into the type.
2166 The symbols can be found in the symlist that we put them on
2167 to cause them to be defined. osyms contains the old value
2168 of that symlist; everything up to there was defined by us. */
2169 /* Note that we preserve the order of the enum constants, so
2170 that in something like "enum {FOO, LAST_THING=FOO}" we print
2171 FOO, not LAST_THING. */
2173 for (syms
= *symlist
, n
= 0; syms
; syms
= syms
->next
)
2178 for (; j
< syms
->nsyms
; j
++,n
++)
2180 struct symbol
*xsym
= syms
->symbol
[j
];
2181 SYMBOL_TYPE (xsym
) = type
;
2182 TYPE_FIELD_NAME (type
, n
) = SYMBOL_NAME (xsym
);
2183 TYPE_FIELD_VALUE (type
, n
) = 0;
2184 TYPE_FIELD_BITPOS (type
, n
) = SYMBOL_VALUE (xsym
);
2185 TYPE_FIELD_BITSIZE (type
, n
) = 0;
2192 /* This screws up perfectly good C programs with enums. FIXME. */
2193 /* Is this Modula-2's BOOLEAN type? Flag it as such if so. */
2194 if(TYPE_NFIELDS(type
) == 2 &&
2195 ((!strcmp(TYPE_FIELD_NAME(type
,0),"TRUE") &&
2196 !strcmp(TYPE_FIELD_NAME(type
,1),"FALSE")) ||
2197 (!strcmp(TYPE_FIELD_NAME(type
,1),"TRUE") &&
2198 !strcmp(TYPE_FIELD_NAME(type
,0),"FALSE"))))
2199 TYPE_CODE(type
) = TYPE_CODE_BOOL
;
2205 /* Sun's ACC uses a somewhat saner method for specifying the builtin
2206 typedefs in every file (for int, long, etc):
2208 type = b <signed> <width>; <offset>; <nbits>
2209 signed = u or s. Possible c in addition to u or s (for char?).
2210 offset = offset from high order bit to start bit of type.
2211 width is # bytes in object of this type, nbits is # bits in type.
2213 The width/offset stuff appears to be for small objects stored in
2214 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
2217 static struct type
*
2218 read_sun_builtin_type (pp
, typenums
, objfile
)
2221 struct objfile
*objfile
;
2235 return error_type (pp
);
2239 /* For some odd reason, all forms of char put a c here. This is strange
2240 because no other type has this honor. We can safely ignore this because
2241 we actually determine 'char'acterness by the number of bits specified in
2247 /* The first number appears to be the number of bytes occupied
2248 by this type, except that unsigned short is 4 instead of 2.
2249 Since this information is redundant with the third number,
2250 we will ignore it. */
2251 read_number (pp
, ';');
2253 /* The second number is always 0, so ignore it too. */
2254 read_number (pp
, ';');
2256 /* The third number is the number of bits for this type. */
2257 nbits
= read_number (pp
, 0);
2259 /* FIXME. Here we should just be able to make a type of the right
2260 number of bits and signedness. FIXME. */
2262 if (nbits
== TARGET_LONG_LONG_BIT
)
2263 return (lookup_fundamental_type (objfile
,
2264 signed_type
? FT_LONG_LONG
: FT_UNSIGNED_LONG_LONG
));
2266 if (nbits
== TARGET_INT_BIT
)
2268 /* FIXME -- the only way to distinguish `int' from `long'
2269 is to look at its name! */
2272 if (long_kludge_name
&& long_kludge_name
[0] == 'l' /* long */)
2273 return lookup_fundamental_type (objfile
, FT_LONG
);
2275 return lookup_fundamental_type (objfile
, FT_INTEGER
);
2279 if (long_kludge_name
2280 && ((long_kludge_name
[0] == 'u' /* unsigned */ &&
2281 long_kludge_name
[9] == 'l' /* long */)
2282 || (long_kludge_name
[0] == 'l' /* long unsigned */)))
2283 return lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG
);
2285 return lookup_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
);
2289 if (nbits
== TARGET_SHORT_BIT
)
2290 return (lookup_fundamental_type (objfile
,
2291 signed_type
? FT_SHORT
: FT_UNSIGNED_SHORT
));
2293 if (nbits
== TARGET_CHAR_BIT
)
2294 return (lookup_fundamental_type (objfile
,
2295 signed_type
? FT_CHAR
: FT_UNSIGNED_CHAR
));
2298 return lookup_fundamental_type (objfile
, FT_VOID
);
2300 return error_type (pp
);
2303 static struct type
*
2304 read_sun_floating_type (pp
, typenums
, objfile
)
2307 struct objfile
*objfile
;
2311 /* The first number has more details about the type, for example
2312 FN_COMPLEX. See the sun stab.h. */
2313 read_number (pp
, ';');
2315 /* The second number is the number of bytes occupied by this type */
2316 nbytes
= read_number (pp
, ';');
2319 return error_type (pp
);
2321 if (nbytes
== TARGET_FLOAT_BIT
/ TARGET_CHAR_BIT
)
2322 return lookup_fundamental_type (objfile
, FT_FLOAT
);
2324 if (nbytes
== TARGET_DOUBLE_BIT
/ TARGET_CHAR_BIT
)
2325 return lookup_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
2327 if (nbytes
== TARGET_LONG_DOUBLE_BIT
/ TARGET_CHAR_BIT
)
2328 return lookup_fundamental_type (objfile
, FT_EXT_PREC_FLOAT
);
2330 return error_type (pp
);
2333 /* Read a number from the string pointed to by *PP.
2334 The value of *PP is advanced over the number.
2335 If END is nonzero, the character that ends the
2336 number must match END, or an error happens;
2337 and that character is skipped if it does match.
2338 If END is zero, *PP is left pointing to that character.
2340 If the number fits in a long, set *VALUE and set *BITS to 0.
2341 If not, set *BITS to be the number of bits in the number.
2343 If encounter garbage, set *BITS to -1. */
2346 read_huge_number (pp
, end
, valu
, bits
)
2367 /* Leading zero means octal. GCC uses this to output values larger
2368 than an int (because that would be hard in decimal). */
2375 upper_limit
= LONG_MAX
/ radix
;
2376 while ((c
= *p
++) >= '0' && c
<= ('0' + radix
))
2378 if (n
<= upper_limit
)
2381 n
+= c
- '0'; /* FIXME this overflows anyway */
2386 /* This depends on large values being output in octal, which is
2393 /* Ignore leading zeroes. */
2397 else if (c
== '2' || c
== '3')
2423 /* Large decimal constants are an error (because it is hard to
2424 count how many bits are in them). */
2430 /* -0x7f is the same as 0x80. So deal with it by adding one to
2431 the number of bits. */
2446 static struct type
*
2447 read_range_type (pp
, typenums
, objfile
)
2450 struct objfile
*objfile
;
2456 struct type
*result_type
;
2458 /* First comes a type we are a subrange of.
2459 In C it is usually 0, 1 or the type being defined. */
2460 read_type_number (pp
, rangenums
);
2461 self_subrange
= (rangenums
[0] == typenums
[0] &&
2462 rangenums
[1] == typenums
[1]);
2464 /* A semicolon should now follow; skip it. */
2468 /* The remaining two operands are usually lower and upper bounds
2469 of the range. But in some special cases they mean something else. */
2470 read_huge_number (pp
, ';', &n2
, &n2bits
);
2471 read_huge_number (pp
, ';', &n3
, &n3bits
);
2473 if (n2bits
== -1 || n3bits
== -1)
2474 return error_type (pp
);
2476 /* If limits are huge, must be large integral type. */
2477 if (n2bits
!= 0 || n3bits
!= 0)
2479 char got_signed
= 0;
2480 char got_unsigned
= 0;
2481 /* Number of bits in the type. */
2484 /* Range from 0 to <large number> is an unsigned large integral type. */
2485 if ((n2bits
== 0 && n2
== 0) && n3bits
!= 0)
2490 /* Range from <large number> to <large number>-1 is a large signed
2492 else if (n2bits
!= 0 && n3bits
!= 0 && n2bits
== n3bits
+ 1)
2498 /* Check for "long long". */
2499 if (got_signed
&& nbits
== TARGET_LONG_LONG_BIT
)
2500 return (lookup_fundamental_type (objfile
, FT_LONG_LONG
));
2501 if (got_unsigned
&& nbits
== TARGET_LONG_LONG_BIT
)
2502 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG_LONG
));
2504 if (got_signed
|| got_unsigned
)
2506 result_type
= (struct type
*)
2507 obstack_alloc (&objfile
-> type_obstack
,
2508 sizeof (struct type
));
2509 memset (result_type
, 0, sizeof (struct type
));
2510 TYPE_OBJFILE (result_type
) = objfile
;
2511 TYPE_LENGTH (result_type
) = nbits
/ TARGET_CHAR_BIT
;
2512 TYPE_CODE (result_type
) = TYPE_CODE_INT
;
2514 TYPE_FLAGS (result_type
) |= TYPE_FLAG_UNSIGNED
;
2518 return error_type (pp
);
2521 /* A type defined as a subrange of itself, with bounds both 0, is void. */
2522 if (self_subrange
&& n2
== 0 && n3
== 0)
2523 return (lookup_fundamental_type (objfile
, FT_VOID
));
2525 /* If n3 is zero and n2 is not, we want a floating type,
2526 and n2 is the width in bytes.
2528 Fortran programs appear to use this for complex types also,
2529 and they give no way to distinguish between double and single-complex!
2530 We don't have complex types, so we would lose on all fortran files!
2531 So return type `double' for all of those. It won't work right
2532 for the complex values, but at least it makes the file loadable.
2534 FIXME, we may be able to distinguish these by their names. FIXME. */
2536 if (n3
== 0 && n2
> 0)
2538 if (n2
== sizeof (float))
2539 return (lookup_fundamental_type (objfile
, FT_FLOAT
));
2540 return (lookup_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
));
2543 /* If the upper bound is -1, it must really be an unsigned int. */
2545 else if (n2
== 0 && n3
== -1)
2547 /* FIXME -- the only way to distinguish `unsigned int' from `unsigned
2548 long' is to look at its name! */
2550 long_kludge_name
&& ((long_kludge_name
[0] == 'u' /* unsigned */ &&
2551 long_kludge_name
[9] == 'l' /* long */)
2552 || (long_kludge_name
[0] == 'l' /* long unsigned */)))
2553 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG
));
2555 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
));
2558 /* Special case: char is defined (Who knows why) as a subrange of
2559 itself with range 0-127. */
2560 else if (self_subrange
&& n2
== 0 && n3
== 127)
2561 return (lookup_fundamental_type (objfile
, FT_CHAR
));
2563 /* Assumptions made here: Subrange of self is equivalent to subrange
2564 of int. FIXME: Host and target type-sizes assumed the same. */
2565 /* FIXME: This is the *only* place in GDB that depends on comparing
2566 some type to a builtin type with ==. Fix it! */
2568 && (self_subrange
||
2569 *dbx_lookup_type (rangenums
) == lookup_fundamental_type (objfile
, FT_INTEGER
)))
2571 /* an unsigned type */
2573 if (n3
== - sizeof (long long))
2574 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG_LONG
));
2576 /* FIXME -- the only way to distinguish `unsigned int' from `unsigned
2577 long' is to look at its name! */
2578 if (n3
== (unsigned long)~0L &&
2579 long_kludge_name
&& ((long_kludge_name
[0] == 'u' /* unsigned */ &&
2580 long_kludge_name
[9] == 'l' /* long */)
2581 || (long_kludge_name
[0] == 'l' /* long unsigned */)))
2582 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG
));
2583 if (n3
== (unsigned int)~0L)
2584 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
));
2585 if (n3
== (unsigned short)~0L)
2586 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_SHORT
));
2587 if (n3
== (unsigned char)~0L)
2588 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_CHAR
));
2591 else if (n3
== 0 && n2
== -sizeof (long long))
2592 return (lookup_fundamental_type (objfile
, FT_LONG_LONG
));
2594 else if (n2
== -n3
-1)
2597 /* FIXME -- the only way to distinguish `int' from `long' is to look
2599 if ((n3
==(long)(((unsigned long)1 << (8 * sizeof (long) - 1)) - 1)) &&
2600 long_kludge_name
&& long_kludge_name
[0] == 'l' /* long */)
2601 return (lookup_fundamental_type (objfile
, FT_LONG
));
2602 if (n3
== (long)(((unsigned long)1 << (8 * sizeof (int) - 1)) - 1))
2603 return (lookup_fundamental_type (objfile
, FT_INTEGER
));
2604 if (n3
== ( 1 << (8 * sizeof (short) - 1)) - 1)
2605 return (lookup_fundamental_type (objfile
, FT_SHORT
));
2606 if (n3
== ( 1 << (8 * sizeof (char) - 1)) - 1)
2607 return (lookup_fundamental_type (objfile
, FT_SIGNED_CHAR
));
2610 /* We have a real range type on our hands. Allocate space and
2611 return a real pointer. */
2613 /* At this point I don't have the faintest idea how to deal with
2614 a self_subrange type; I'm going to assume that this is used
2615 as an idiom, and that all of them are special cases. So . . . */
2617 return error_type (pp
);
2619 result_type
= (struct type
*)
2620 obstack_alloc (&objfile
-> type_obstack
, sizeof (struct type
));
2621 memset (result_type
, 0, sizeof (struct type
));
2622 TYPE_OBJFILE (result_type
) = objfile
;
2624 TYPE_CODE (result_type
) = TYPE_CODE_RANGE
;
2626 TYPE_TARGET_TYPE (result_type
) = *dbx_lookup_type(rangenums
);
2627 if (TYPE_TARGET_TYPE (result_type
) == 0) {
2628 complain (&range_type_base_complaint
, (char *) rangenums
[1]);
2629 TYPE_TARGET_TYPE (result_type
) = lookup_fundamental_type (objfile
, FT_INTEGER
);
2632 TYPE_NFIELDS (result_type
) = 2;
2633 TYPE_FIELDS (result_type
) =
2634 (struct field
*) obstack_alloc (&objfile
-> type_obstack
,
2635 2 * sizeof (struct field
));
2636 memset (TYPE_FIELDS (result_type
), 0, 2 * sizeof (struct field
));
2637 TYPE_FIELD_BITPOS (result_type
, 0) = n2
;
2638 TYPE_FIELD_BITPOS (result_type
, 1) = n3
;
2640 TYPE_LENGTH (result_type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (result_type
));
2645 /* Read a number from the string pointed to by *PP.
2646 The value of *PP is advanced over the number.
2647 If END is nonzero, the character that ends the
2648 number must match END, or an error happens;
2649 and that character is skipped if it does match.
2650 If END is zero, *PP is left pointing to that character. */
2653 read_number (pp
, end
)
2657 register char *p
= *pp
;
2658 register long n
= 0;
2662 /* Handle an optional leading minus sign. */
2670 /* Read the digits, as far as they go. */
2672 while ((c
= *p
++) >= '0' && c
<= '9')
2680 error ("Invalid symbol data: invalid character \\%03o at symbol pos %d.", c
, symnum
);
2689 /* Read in an argument list. This is a list of types, separated by commas
2690 and terminated with END. Return the list of types read in, or (struct type
2691 **)-1 if there is an error. */
2693 static struct type
**
2694 read_args (pp
, end
, objfile
)
2697 struct objfile
*objfile
;
2699 /* FIXME! Remove this arbitrary limit! */
2700 struct type
*types
[1024], **rval
; /* allow for fns of 1023 parameters */
2706 /* Invalid argument list: no ','. */
2707 return (struct type
**)-1;
2710 /* Check for and handle cretinous dbx symbol name continuation! */
2712 *pp
= next_symbol_text ();
2714 types
[n
++] = read_type (pp
, objfile
);
2716 *pp
+= 1; /* get past `end' (the ':' character) */
2720 rval
= (struct type
**) xmalloc (2 * sizeof (struct type
*));
2722 else if (TYPE_CODE (types
[n
-1]) != TYPE_CODE_VOID
)
2724 rval
= (struct type
**) xmalloc ((n
+ 1) * sizeof (struct type
*));
2725 memset (rval
+ n
, 0, sizeof (struct type
*));
2729 rval
= (struct type
**) xmalloc (n
* sizeof (struct type
*));
2731 memcpy (rval
, types
, n
* sizeof (struct type
*));
2735 /* Add a common block's start address to the offset of each symbol
2736 declared to be in it (by being between a BCOMM/ECOMM pair that uses
2737 the common block name). */
2740 fix_common_block (sym
, valu
)
2744 struct pending
*next
= (struct pending
*) SYMBOL_NAMESPACE (sym
);
2745 for ( ; next
; next
= next
->next
)
2748 for (j
= next
->nsyms
- 1; j
>= 0; j
--)
2749 SYMBOL_VALUE_ADDRESS (next
->symbol
[j
]) += valu
;
2755 /* What about types defined as forward references inside of a small lexical
2757 /* Add a type to the list of undefined types to be checked through
2758 once this file has been read in. */
2761 add_undefined_type (type
)
2764 if (undef_types_length
== undef_types_allocated
)
2766 undef_types_allocated
*= 2;
2767 undef_types
= (struct type
**)
2768 xrealloc ((char *) undef_types
,
2769 undef_types_allocated
* sizeof (struct type
*));
2771 undef_types
[undef_types_length
++] = type
;
2774 /* Go through each undefined type, see if it's still undefined, and fix it
2775 up if possible. We have two kinds of undefined types:
2777 TYPE_CODE_ARRAY: Array whose target type wasn't defined yet.
2778 Fix: update array length using the element bounds
2779 and the target type's length.
2780 TYPE_CODE_STRUCT, TYPE_CODE_UNION: Structure whose fields were not
2781 yet defined at the time a pointer to it was made.
2782 Fix: Do a full lookup on the struct/union tag. */
2784 cleanup_undefined_types ()
2788 for (type
= undef_types
; type
< undef_types
+ undef_types_length
; type
++)
2790 switch (TYPE_CODE (*type
))
2793 case TYPE_CODE_STRUCT
:
2794 case TYPE_CODE_UNION
:
2795 case TYPE_CODE_ENUM
:
2797 /* Check if it has been defined since. */
2798 if (TYPE_FLAGS (*type
) & TYPE_FLAG_STUB
)
2800 struct pending
*ppt
;
2802 /* Name of the type, without "struct" or "union" */
2803 char *typename
= TYPE_NAME (*type
);
2805 if (!strncmp (typename
, "struct ", 7))
2807 if (!strncmp (typename
, "union ", 6))
2809 if (!strncmp (typename
, "enum ", 5))
2812 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
2814 for (i
= 0; i
< ppt
->nsyms
; i
++)
2816 struct symbol
*sym
= ppt
->symbol
[i
];
2818 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
2819 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
2820 && (TYPE_CODE (SYMBOL_TYPE (sym
)) ==
2822 && !strcmp (SYMBOL_NAME (sym
), typename
))
2824 memcpy (*type
, SYMBOL_TYPE (sym
),
2825 sizeof (struct type
));
2833 case TYPE_CODE_ARRAY
:
2835 struct type
*range_type
;
2838 if (TYPE_LENGTH (*type
) != 0) /* Better be unknown */
2840 if (TYPE_NFIELDS (*type
) != 1)
2842 range_type
= TYPE_FIELD_TYPE (*type
, 0);
2843 if (TYPE_CODE (range_type
) != TYPE_CODE_RANGE
)
2846 /* Now recompute the length of the array type, based on its
2847 number of elements and the target type's length. */
2848 lower
= TYPE_FIELD_BITPOS (range_type
, 0);
2849 upper
= TYPE_FIELD_BITPOS (range_type
, 1);
2850 TYPE_LENGTH (*type
) = (upper
- lower
+ 1)
2851 * TYPE_LENGTH (TYPE_TARGET_TYPE (*type
));
2857 error ("GDB internal error. cleanup_undefined_types with bad type %d.", TYPE_CODE (*type
));
2861 undef_types_length
= 0;
2864 /* Scan through all of the global symbols defined in the object file,
2865 assigning values to the debugging symbols that need to be assigned
2866 to. Get these symbols from the minimal symbol table. */
2869 scan_file_globals (objfile
)
2870 struct objfile
*objfile
;
2873 struct minimal_symbol
*msymbol
;
2874 struct symbol
*sym
, *prev
;
2876 if (objfile
->msymbols
== 0) /* Beware the null file. */
2879 for (msymbol
= objfile
-> msymbols
; msymbol
-> name
!= NULL
; msymbol
++)
2885 /* Get the hash index and check all the symbols
2886 under that hash index. */
2888 hash
= hashname (msymbol
-> name
);
2890 for (sym
= global_sym_chain
[hash
]; sym
;)
2892 if (*(msymbol
-> name
) == SYMBOL_NAME (sym
)[0]
2893 && !strcmp(msymbol
-> name
+ 1, SYMBOL_NAME (sym
) + 1))
2895 /* Splice this symbol out of the hash chain and
2896 assign the value we have to it. */
2899 SYMBOL_VALUE_CHAIN (prev
) = SYMBOL_VALUE_CHAIN (sym
);
2903 global_sym_chain
[hash
] = SYMBOL_VALUE_CHAIN (sym
);
2906 /* Check to see whether we need to fix up a common block. */
2907 /* Note: this code might be executed several times for
2908 the same symbol if there are multiple references. */
2910 if (SYMBOL_CLASS (sym
) == LOC_BLOCK
)
2912 fix_common_block (sym
, msymbol
-> address
);
2916 SYMBOL_VALUE_ADDRESS (sym
) = msymbol
-> address
;
2921 sym
= SYMBOL_VALUE_CHAIN (prev
);
2925 sym
= global_sym_chain
[hash
];
2931 sym
= SYMBOL_VALUE_CHAIN (sym
);
2937 /* Initialize anything that needs initializing when starting to read
2938 a fresh piece of a symbol file, e.g. reading in the stuff corresponding
2946 /* Initialize anything that needs initializing when a completely new
2947 symbol file is specified (not just adding some symbols from another
2948 file, e.g. a shared library). */
2951 stabsread_new_init ()
2953 /* Empty the hash table of global syms looking for values. */
2954 memset (global_sym_chain
, 0, sizeof (global_sym_chain
));
2957 /* Initialize anything that needs initializing at the same time as
2958 start_symtab() is called. */
2962 global_stabs
= NULL
; /* AIX COFF */
2963 /* Leave FILENUM of 0 free for builtin types and this file's types. */
2964 n_this_object_header_files
= 1;
2965 type_vector_length
= 0;
2966 type_vector
= (struct type
**) 0;
2969 /* Call after end_symtab() */
2975 free ((char *) type_vector
);
2978 type_vector_length
= 0;
2979 previous_stab_code
= 0;
2983 finish_global_stabs (objfile
)
2985 struct objfile
*objfile
;
2989 patch_block_stabs (global_symbols
, global_stabs
, objfile
);
2990 free ((PTR
) global_stabs
);
2991 global_stabs
= NULL
;
2995 /* Initializer for this module */
2998 _initialize_stabsread ()
3000 undef_types_allocated
= 20;
3001 undef_types_length
= 0;
3002 undef_types
= (struct type
**)
3003 xmalloc (undef_types_allocated
* sizeof (struct type
*));