1 /* stabs.c -- Parse stabs debugging information
2 Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
3 Written by Ian Lance Taylor <ian@cygnus.com>.
5 This file is part of GNU Binutils.
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
22 /* This file contains code which parses stabs debugging information.
23 The organization of this code is based on the gdb stabs reading
24 code. The job it does is somewhat different, because it is not
25 trying to identify the correct address for anything. */
32 #include "libiberty.h"
37 /* Meaningless definition needs by aout64.h. FIXME. */
38 #define BYTES_IN_WORD 4
40 #include "aout/aout64.h"
41 #include "aout/stab_gnu.h"
44 #define DIR_SEPARATOR '/'
47 /* The number of predefined XCOFF types. */
49 #define XCOFF_TYPE_COUNT 34
51 /* This structure is used as a handle so that the stab parsing doesn't
52 need to use any static variables. */
58 /* True if this is stabs in sections. */
60 /* The symbol table. */
62 /* The number of symbols. */
64 /* The accumulated file name string. */
66 /* The value of the last N_SO symbol. */
68 /* The value of the start of the file, so that we can handle file
69 relative N_LBRAC and N_RBRAC symbols. */
70 bfd_vma file_start_offset
;
71 /* The offset of the start of the function, so that we can handle
72 function relative N_LBRAC and N_RBRAC symbols. */
73 bfd_vma function_start_offset
;
74 /* The version number of gcc which compiled the current compilation
75 unit, 0 if not compiled by gcc. */
77 /* Whether an N_OPT symbol was seen that was not generated by gcc,
78 so that we can detect the SunPRO compiler. */
80 /* The main file name. */
82 /* A stack of unfinished N_BINCL files. */
83 struct bincl_file
*bincl_stack
;
84 /* A list of finished N_BINCL files. */
85 struct bincl_file
*bincl_list
;
86 /* Whether we are inside a function or not. */
87 boolean within_function
;
88 /* The address of the end of the function, used if we have seen an
89 N_FUN symbol while in a function. This is -1 if we have not seen
90 an N_FUN (the normal case). */
92 /* The depth of block nesting. */
94 /* List of pending variable definitions. */
95 struct stab_pending_var
*pending
;
96 /* Number of files for which we have types. */
98 /* Lists of types per file. */
99 struct stab_types
**file_types
;
100 /* Predefined XCOFF types. */
101 debug_type xcoff_types
[XCOFF_TYPE_COUNT
];
102 /* Undefined tags. */
103 struct stab_tag
*tags
;
104 /* Set by parse_stab_type if it sees a structure defined as a cross
105 reference to itself. Reset by parse_stab_type otherwise. */
106 boolean self_crossref
;
109 /* A list of these structures is used to hold pending variable
110 definitions seen before the N_LBRAC of a block. */
112 struct stab_pending_var
114 /* Next pending variable definition. */
115 struct stab_pending_var
*next
;
121 enum debug_var_kind kind
;
126 /* A list of these structures is used to hold the types for a single
131 /* Next set of slots for this file. */
132 struct stab_types
*next
;
133 /* Types indexed by type number. */
134 #define STAB_TYPES_SLOTS (16)
135 debug_type types
[STAB_TYPES_SLOTS
];
138 /* We keep a list of undefined tags that we encounter, so that we can
139 fill them in if the tag is later defined. */
143 /* Next undefined tag. */
144 struct stab_tag
*next
;
148 enum debug_type_kind kind
;
149 /* Slot to hold real type when we discover it. If we don't, we fill
150 in an undefined tag type. */
152 /* Indirect type we have created to point at slot. */
156 static char *savestring
PARAMS ((const char *, int));
157 static bfd_vma parse_number
PARAMS ((const char **, boolean
*));
158 static void bad_stab
PARAMS ((const char *));
159 static void warn_stab
PARAMS ((const char *, const char *));
160 static boolean parse_stab_string
161 PARAMS ((PTR
, struct stab_handle
*, int, int, bfd_vma
, const char *));
162 static debug_type parse_stab_type
163 PARAMS ((PTR
, struct stab_handle
*, const char *, const char **,
165 static boolean parse_stab_type_number
166 PARAMS ((const char **, int *));
167 static debug_type parse_stab_range_type
168 PARAMS ((PTR
, struct stab_handle
*, const char *, const char **,
170 static debug_type parse_stab_sun_builtin_type
PARAMS ((PTR
, const char **));
171 static debug_type parse_stab_sun_floating_type
172 PARAMS ((PTR
, const char **));
173 static debug_type parse_stab_enum_type
PARAMS ((PTR
, const char **));
174 static debug_type parse_stab_struct_type
175 PARAMS ((PTR
, struct stab_handle
*, const char *, const char **, boolean
,
177 static boolean parse_stab_baseclasses
178 PARAMS ((PTR
, struct stab_handle
*, const char **, debug_baseclass
**));
179 static boolean parse_stab_struct_fields
180 PARAMS ((PTR
, struct stab_handle
*, const char **, debug_field
**,
182 static boolean parse_stab_cpp_abbrev
183 PARAMS ((PTR
, struct stab_handle
*, const char **, debug_field
*));
184 static boolean parse_stab_one_struct_field
185 PARAMS ((PTR
, struct stab_handle
*, const char **, const char *,
186 debug_field
*, boolean
*));
187 static boolean parse_stab_members
188 PARAMS ((PTR
, struct stab_handle
*, const char *, const char **,
189 const int *, debug_method
**));
190 static debug_type parse_stab_argtypes
191 PARAMS ((PTR
, struct stab_handle
*, debug_type
, const char *, const char *,
192 debug_type
, const char *, boolean
, boolean
, const char **));
193 static boolean parse_stab_tilde_field
194 PARAMS ((PTR
, struct stab_handle
*, const char **, const int *,
195 debug_type
*, boolean
*));
196 static debug_type parse_stab_array_type
197 PARAMS ((PTR
, struct stab_handle
*, const char **, boolean
));
198 static void push_bincl
PARAMS ((struct stab_handle
*, const char *, bfd_vma
));
199 static const char *pop_bincl
PARAMS ((struct stab_handle
*));
200 static boolean find_excl
201 PARAMS ((struct stab_handle
*, const char *, bfd_vma
));
202 static boolean stab_record_variable
203 PARAMS ((PTR
, struct stab_handle
*, const char *, debug_type
,
204 enum debug_var_kind
, bfd_vma
));
205 static boolean stab_emit_pending_vars
PARAMS ((PTR
, struct stab_handle
*));
206 static debug_type
*stab_find_slot
207 PARAMS ((struct stab_handle
*, const int *));
208 static debug_type stab_find_type
209 PARAMS ((PTR
, struct stab_handle
*, const int *));
210 static boolean stab_record_type
211 PARAMS ((PTR
, struct stab_handle
*, const int *, debug_type
));
212 static debug_type stab_xcoff_builtin_type
213 PARAMS ((PTR
, struct stab_handle
*, int));
214 static debug_type stab_find_tagged_type
215 PARAMS ((PTR
, struct stab_handle
*, const char *, int,
216 enum debug_type_kind
));
217 static debug_type
*stab_demangle_argtypes
218 PARAMS ((PTR
, struct stab_handle
*, const char *, boolean
*));
220 /* Save a string in memory. */
223 savestring (start
, len
)
229 ret
= (char *) xmalloc (len
+ 1);
230 memcpy (ret
, start
, len
);
235 /* Read a number from a string. */
238 parse_number (pp
, poverflow
)
245 if (poverflow
!= NULL
)
251 ul
= strtoul (*pp
, (char **) pp
, 0);
252 if (ul
+ 1 != 0 || errno
== 0)
254 /* If bfd_vma is larger than unsigned long, and the number is
255 meant to be negative, we have to make sure that we sign
258 return (bfd_vma
) (bfd_signed_vma
) (long) ul
;
262 /* Note that even though strtoul overflowed, it should have set *pp
263 to the end of the number, which is where we want it. */
265 if (sizeof (bfd_vma
) > sizeof (unsigned long))
270 bfd_vma over
, lastdig
;
274 /* Our own version of strtoul, for a bfd_vma. */
290 if (p
[1] == 'x' || p
[1] == 'X')
302 over
= ((bfd_vma
) (bfd_signed_vma
) -1) / (bfd_vma
) base
;
303 lastdig
= ((bfd_vma
) (bfd_signed_vma
) -1) % (bfd_vma
) base
;
312 if (isdigit ((unsigned char) d
))
314 else if (isupper ((unsigned char) d
))
316 else if (islower ((unsigned char) d
))
324 if (v
> over
|| (v
== over
&& (bfd_vma
) d
> lastdig
))
339 /* If we get here, the number is too large to represent in a
342 if (poverflow
!= NULL
)
345 warn_stab (orig
, _("numeric overflow"));
350 /* Give an error for a bad stab string. */
356 fprintf (stderr
, _("Bad stab: %s\n"), p
);
359 /* Warn about something in a stab string. */
366 fprintf (stderr
, _("Warning: %s: %s\n"), err
, p
);
369 /* Create a handle to parse stabs symbols with. */
373 start_stab (dhandle
, abfd
, sections
, syms
, symcount
)
380 struct stab_handle
*ret
;
382 ret
= (struct stab_handle
*) xmalloc (sizeof *ret
);
383 memset (ret
, 0, sizeof *ret
);
385 ret
->sections
= sections
;
387 ret
->symcount
= symcount
;
389 ret
->file_types
= (struct stab_types
**) xmalloc (sizeof *ret
->file_types
);
390 ret
->file_types
[0] = NULL
;
391 ret
->function_end
= (bfd_vma
) -1;
395 /* When we have processed all the stabs information, we need to go
396 through and fill in all the undefined tags. */
399 finish_stab (dhandle
, handle
)
403 struct stab_handle
*info
= (struct stab_handle
*) handle
;
406 if (info
->within_function
)
408 if (! stab_emit_pending_vars (dhandle
, info
)
409 || ! debug_end_function (dhandle
, info
->function_end
))
411 info
->within_function
= false;
412 info
->function_end
= (bfd_vma
) -1;
415 for (st
= info
->tags
; st
!= NULL
; st
= st
->next
)
417 enum debug_type_kind kind
;
420 if (kind
== DEBUG_KIND_ILLEGAL
)
421 kind
= DEBUG_KIND_STRUCT
;
422 st
->slot
= debug_make_undefined_tagged_type (dhandle
, st
->name
, kind
);
423 if (st
->slot
== DEBUG_TYPE_NULL
)
430 /* Handle a single stabs symbol. */
433 parse_stab (dhandle
, handle
, type
, desc
, value
, string
)
441 struct stab_handle
*info
= (struct stab_handle
*) handle
;
443 /* gcc will emit two N_SO strings per compilation unit, one for the
444 directory name and one for the file name. We just collect N_SO
445 strings as we see them, and start the new compilation unit when
446 we see a non N_SO symbol. */
447 if (info
->so_string
!= NULL
448 && (type
!= N_SO
|| *string
== '\0' || value
!= info
->so_value
))
450 if (! debug_set_filename (dhandle
, info
->so_string
))
452 info
->main_filename
= info
->so_string
;
454 info
->gcc_compiled
= 0;
455 info
->n_opt_found
= false;
457 /* Generally, for stabs in the symbol table, the N_LBRAC and
458 N_RBRAC symbols are relative to the N_SO symbol value. */
459 if (! info
->sections
)
460 info
->file_start_offset
= info
->so_value
;
462 /* We need to reset the mapping from type numbers to types. We
463 can't free the old mapping, because of the use of
464 debug_make_indirect_type. */
466 info
->file_types
= ((struct stab_types
**)
467 xmalloc (sizeof *info
->file_types
));
468 info
->file_types
[0] = NULL
;
470 info
->so_string
= NULL
;
472 /* Now process whatever type we just got. */
482 /* Ignore extra outermost context from SunPRO cc and acc. */
483 if (info
->n_opt_found
&& desc
== 1)
486 if (! info
->within_function
)
488 fprintf (stderr
, _("N_LBRAC not within function\n"));
492 /* Start an inner lexical block. */
493 if (! debug_start_block (dhandle
,
495 + info
->file_start_offset
496 + info
->function_start_offset
)))
499 /* Emit any pending variable definitions. */
500 if (! stab_emit_pending_vars (dhandle
, info
))
507 /* Ignore extra outermost context from SunPRO cc and acc. */
508 if (info
->n_opt_found
&& desc
== 1)
511 /* We shouldn't have any pending variable definitions here, but,
512 if we do, we probably need to emit them before closing the
514 if (! stab_emit_pending_vars (dhandle
, info
))
517 /* End an inner lexical block. */
518 if (! debug_end_block (dhandle
,
520 + info
->file_start_offset
521 + info
->function_start_offset
)))
525 if (info
->block_depth
< 0)
527 fprintf (stderr
, _("Too many N_RBRACs\n"));
533 /* This always ends a function. */
534 if (info
->within_function
)
540 && info
->function_end
!= (bfd_vma
) -1
541 && info
->function_end
< endval
)
542 endval
= info
->function_end
;
543 if (! stab_emit_pending_vars (dhandle
, info
)
544 || ! debug_end_function (dhandle
, endval
))
546 info
->within_function
= false;
547 info
->function_end
= (bfd_vma
) -1;
550 /* An empty string is emitted by gcc at the end of a compilation
555 /* Just accumulate strings until we see a non N_SO symbol. If
556 the string starts with a directory separator or some other
557 form of absolute path specification, we discard the previously
558 accumulated strings. */
559 if (info
->so_string
== NULL
)
560 info
->so_string
= xstrdup (string
);
567 if ( (string
[0] == '/')
568 || (string
[0] == DIR_SEPARATOR
)
569 || ( (DIR_SEPARATOR
== '\\')
570 && (string
[1] == ':')
571 && ( (string
[2] == DIR_SEPARATOR
)
572 || (string
[2] == '/'))))
573 info
->so_string
= xstrdup (string
);
575 info
->so_string
= concat (info
->so_string
, string
,
576 (const char *) NULL
);
580 info
->so_value
= value
;
585 /* Start an include file. */
586 if (! debug_start_source (dhandle
, string
))
591 /* Start an include file which may be replaced. */
592 push_bincl (info
, string
, value
);
593 if (! debug_start_source (dhandle
, string
))
598 /* End an N_BINCL include. */
599 if (! debug_start_source (dhandle
, pop_bincl (info
)))
604 /* This is a duplicate of a header file named by N_BINCL which
605 was eliminated by the linker. */
606 if (! find_excl (info
, string
, value
))
611 if (! debug_record_line (dhandle
, desc
,
612 value
+ info
->function_start_offset
))
617 if (! debug_start_common_block (dhandle
, string
))
622 if (! debug_end_common_block (dhandle
, string
))
629 if (info
->within_function
)
631 /* This always marks the end of a function; we don't
632 need to worry about info->function_end. */
634 value
+= info
->function_start_offset
;
635 if (! stab_emit_pending_vars (dhandle
, info
)
636 || ! debug_end_function (dhandle
, value
))
638 info
->within_function
= false;
639 info
->function_end
= (bfd_vma
) -1;
644 /* A const static symbol in the .text section will have an N_FUN
645 entry. We need to use these to mark the end of the function,
646 in case we are looking at gcc output before it was changed to
647 always emit an empty N_FUN. We can't call debug_end_function
648 here, because it might be a local static symbol. */
649 if (info
->within_function
650 && (info
->function_end
== (bfd_vma
) -1
651 || value
< info
->function_end
))
652 info
->function_end
= value
;
655 /* FIXME: gdb checks the string for N_STSYM, N_LCSYM or N_ROSYM
656 symbols, and if it does not start with :S, gdb relocates the
657 value to the start of the section. gcc always seems to use
658 :S, so we don't worry about this. */
664 colon
= strchr (string
, ':');
666 && (colon
[1] == 'f' || colon
[1] == 'F'))
668 if (info
->within_function
)
673 if (info
->function_end
!= (bfd_vma
) -1
674 && info
->function_end
< endval
)
675 endval
= info
->function_end
;
676 if (! stab_emit_pending_vars (dhandle
, info
)
677 || ! debug_end_function (dhandle
, endval
))
679 info
->function_end
= (bfd_vma
) -1;
681 /* For stabs in sections, line numbers and block addresses
682 are offsets from the start of the function. */
684 info
->function_start_offset
= value
;
685 info
->within_function
= true;
688 if (! parse_stab_string (dhandle
, info
, type
, desc
, value
, string
))
694 if (string
!= NULL
&& strcmp (string
, "gcc2_compiled.") == 0)
695 info
->gcc_compiled
= 2;
696 else if (string
!= NULL
&& strcmp (string
, "gcc_compiled.") == 0)
697 info
->gcc_compiled
= 1;
699 info
->n_opt_found
= true;
711 /* Parse the stabs string. */
714 parse_stab_string (dhandle
, info
, stabtype
, desc
, value
, string
)
716 struct stab_handle
*info
;
727 boolean self_crossref
;
731 p
= strchr (string
, ':');
746 /* GCC 2.x puts the line number in desc. SunOS apparently puts in
747 the number of bytes occupied by a type or object, which we
749 if (info
->gcc_compiled
>= 2)
754 /* FIXME: Sometimes the special C++ names start with '.'. */
756 if (string
[0] == '$')
764 /* Was: name = "vptr"; */
770 /* This was an anonymous type that was never fixed up. */
773 /* SunPRO (3.0 at least) static variable encoding. */
776 warn_stab (string
, _("unknown C++ encoded name"));
783 if (p
== string
|| (string
[0] == ' ' && p
== string
+ 1))
786 name
= savestring (string
, p
- string
);
790 if (isdigit ((unsigned char) *p
) || *p
== '(' || *p
== '-')
798 /* c is a special case, not followed by a type-number.
799 SYMBOL:c=iVALUE for an integer constant symbol.
800 SYMBOL:c=rVALUE for a floating constant symbol.
801 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
802 e.g. "b:c=e6,0" for "const b = blob1"
803 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
813 /* Floating point constant. */
814 if (! debug_record_float_const (dhandle
, name
, atof (p
)))
818 /* Integer constant. */
819 /* Defining integer constants this way is kind of silly,
820 since 'e' constants allows the compiler to give not only
821 the value, but the type as well. C has at least int,
822 long, unsigned int, and long long as constant types;
823 other languages probably should have at least unsigned as
824 well as signed constants. */
825 if (! debug_record_int_const (dhandle
, name
, atoi (p
)))
829 /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value
830 can be represented as integral.
831 e.g. "b:c=e6,0" for "const b = blob1"
832 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
833 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
,
834 &p
, (debug_type
**) NULL
);
835 if (dtype
== DEBUG_TYPE_NULL
)
842 if (! debug_record_typed_const (dhandle
, name
, dtype
, atoi (p
)))
853 /* The name of a caught exception. */
854 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
,
855 &p
, (debug_type
**) NULL
);
856 if (dtype
== DEBUG_TYPE_NULL
)
858 if (! debug_record_label (dhandle
, name
, dtype
, value
))
864 /* A function definition. */
865 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
866 (debug_type
**) NULL
);
867 if (dtype
== DEBUG_TYPE_NULL
)
869 if (! debug_record_function (dhandle
, name
, dtype
, type
== 'F', value
))
872 /* Sun acc puts declared types of arguments here. We don't care
873 about their actual types (FIXME -- we should remember the whole
874 function prototype), but the list may define some new types
875 that we have to remember, so we must scan it now. */
879 if (parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
880 (debug_type
**) NULL
)
893 /* A global symbol. The value must be extracted from the
895 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
896 (debug_type
**) NULL
);
897 if (dtype
== DEBUG_TYPE_NULL
)
899 leading
= bfd_get_symbol_leading_char (info
->abfd
);
900 for (c
= info
->symcount
, ps
= info
->syms
; c
> 0; --c
, ++ps
)
904 n
= bfd_asymbol_name (*ps
);
905 if (leading
!= '\0' && *n
== leading
)
907 if (*n
== *name
&& strcmp (n
, name
) == 0)
911 value
= bfd_asymbol_value (*ps
);
912 if (! stab_record_variable (dhandle
, info
, name
, dtype
, DEBUG_GLOBAL
,
918 /* This case is faked by a conditional above, when there is no
919 code letter in the dbx data. Dbx data never actually
923 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
924 (debug_type
**) NULL
);
925 if (dtype
== DEBUG_TYPE_NULL
)
927 if (! stab_record_variable (dhandle
, info
, name
, dtype
, DEBUG_LOCAL
,
933 /* A function parameter. */
935 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
936 (debug_type
**) NULL
);
939 /* pF is a two-letter code that means a function parameter in
940 Fortran. The type-number specifies the type of the return
941 value. Translate it into a pointer-to-function type. */
943 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
944 (debug_type
**) NULL
);
945 if (dtype
!= DEBUG_TYPE_NULL
)
949 ftype
= debug_make_function_type (dhandle
, dtype
,
950 (debug_type
*) NULL
, false);
951 dtype
= debug_make_pointer_type (dhandle
, ftype
);
954 if (dtype
== DEBUG_TYPE_NULL
)
956 if (! debug_record_parameter (dhandle
, name
, dtype
, DEBUG_PARM_STACK
,
960 /* FIXME: At this point gdb considers rearranging the parameter
961 address on a big endian machine if it is smaller than an int.
962 We have no way to do that, since we don't really know much
968 if (stabtype
== N_FUN
)
970 /* Prototype of a function referenced by this file. */
974 if (parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
975 (debug_type
**) NULL
)
983 /* Parameter which is in a register. */
984 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
985 (debug_type
**) NULL
);
986 if (dtype
== DEBUG_TYPE_NULL
)
988 if (! debug_record_parameter (dhandle
, name
, dtype
, DEBUG_PARM_REG
,
994 /* Register variable (either global or local). */
995 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
996 (debug_type
**) NULL
);
997 if (dtype
== DEBUG_TYPE_NULL
)
999 if (! stab_record_variable (dhandle
, info
, name
, dtype
, DEBUG_REGISTER
,
1003 /* FIXME: At this point gdb checks to combine pairs of 'p' and
1004 'r' stabs into a single 'P' stab. */
1009 /* Static symbol at top level of file */
1010 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
1011 (debug_type
**) NULL
);
1012 if (dtype
== DEBUG_TYPE_NULL
)
1014 if (! stab_record_variable (dhandle
, info
, name
, dtype
, DEBUG_STATIC
,
1021 dtype
= parse_stab_type (dhandle
, info
, name
, &p
, &slot
);
1022 if (dtype
== DEBUG_TYPE_NULL
)
1026 /* A nameless type. Nothing to do. */
1030 dtype
= debug_name_type (dhandle
, name
, dtype
);
1031 if (dtype
== DEBUG_TYPE_NULL
)
1040 /* Struct, union, or enum tag. For GNU C++, this can be be followed
1041 by 't' which means we are typedef'ing it as well. */
1045 /* FIXME: gdb sets synonym to true if the current language
1054 dtype
= parse_stab_type (dhandle
, info
, name
, &p
, &slot
);
1055 if (dtype
== DEBUG_TYPE_NULL
)
1060 /* INFO->SELF_CROSSREF is set by parse_stab_type if this type is
1061 a cross reference to itself. These are generated by some
1063 self_crossref
= info
->self_crossref
;
1065 dtype
= debug_tag_type (dhandle
, name
, dtype
);
1066 if (dtype
== DEBUG_TYPE_NULL
)
1071 /* See if we have a cross reference to this tag which we can now
1072 fill in. Avoid filling in a cross reference to ourselves,
1073 because that would lead to circular debugging information. */
1074 if (! self_crossref
)
1076 register struct stab_tag
**pst
;
1078 for (pst
= &info
->tags
; *pst
!= NULL
; pst
= &(*pst
)->next
)
1080 if ((*pst
)->name
[0] == name
[0]
1081 && strcmp ((*pst
)->name
, name
) == 0)
1083 (*pst
)->slot
= dtype
;
1084 *pst
= (*pst
)->next
;
1092 dtype
= debug_name_type (dhandle
, name
, dtype
);
1093 if (dtype
== DEBUG_TYPE_NULL
)
1103 /* Static symbol of local scope */
1104 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
1105 (debug_type
**) NULL
);
1106 if (dtype
== DEBUG_TYPE_NULL
)
1108 /* FIXME: gdb checks os9k_stabs here. */
1109 if (! stab_record_variable (dhandle
, info
, name
, dtype
,
1110 DEBUG_LOCAL_STATIC
, value
))
1115 /* Reference parameter. */
1116 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
1117 (debug_type
**) NULL
);
1118 if (dtype
== DEBUG_TYPE_NULL
)
1120 if (! debug_record_parameter (dhandle
, name
, dtype
, DEBUG_PARM_REFERENCE
,
1126 /* Reference parameter which is in a register. */
1127 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
1128 (debug_type
**) NULL
);
1129 if (dtype
== DEBUG_TYPE_NULL
)
1131 if (! debug_record_parameter (dhandle
, name
, dtype
, DEBUG_PARM_REF_REG
,
1137 /* This is used by Sun FORTRAN for "function result value".
1138 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
1139 that Pascal uses it too, but when I tried it Pascal used
1140 "x:3" (local symbol) instead. */
1141 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
1142 (debug_type
**) NULL
);
1143 if (dtype
== DEBUG_TYPE_NULL
)
1145 if (! stab_record_variable (dhandle
, info
, name
, dtype
, DEBUG_LOCAL
,
1155 /* FIXME: gdb converts structure values to structure pointers in a
1156 couple of cases, depending upon the target. */
1161 /* Parse a stabs type. The typename argument is non-NULL if this is a
1162 typedef or a tag definition. The pp argument points to the stab
1163 string, and is updated. The slotp argument points to a place to
1164 store the slot used if the type is being defined. */
1167 parse_stab_type (dhandle
, info
, typename
, pp
, slotp
)
1169 struct stab_handle
*info
;
1170 const char *typename
;
1189 info
->self_crossref
= false;
1191 /* Read type number if present. The type number may be omitted.
1192 for instance in a two-dimensional array declared with type
1193 "ar1;1;10;ar1;1;10;4". */
1194 if (! isdigit ((unsigned char) **pp
) && **pp
!= '(' && **pp
!= '-')
1196 /* 'typenums=' not present, type is anonymous. Read and return
1197 the definition, but don't put it in the type vector. */
1198 typenums
[0] = typenums
[1] = -1;
1202 if (! parse_stab_type_number (pp
, typenums
))
1203 return DEBUG_TYPE_NULL
;
1207 /* Type is not being defined here. Either it already
1208 exists, or this is a forward reference to it. */
1209 return stab_find_type (dhandle
, info
, typenums
);
1212 /* Only set the slot if the type is being defined. This means
1213 that the mapping from type numbers to types will only record
1214 the name of the typedef which defines a type. If we don't do
1215 this, then something like
1218 will record that i is of type foo. Unfortunately, stabs
1219 information is ambiguous about variable types. For this code,
1223 the stabs information records both i and j as having the same
1224 type. This could be fixed by patching the compiler. */
1225 if (slotp
!= NULL
&& typenums
[0] >= 0 && typenums
[1] >= 0)
1226 *slotp
= stab_find_slot (info
, typenums
);
1228 /* Type is being defined here. */
1234 const char *p
= *pp
+ 1;
1237 if (isdigit ((unsigned char) *p
) || *p
== '(' || *p
== '-')
1243 /* Type attributes. */
1246 for (; *p
!= ';'; ++p
)
1251 return DEBUG_TYPE_NULL
;
1259 size
= atoi (attr
+ 1);
1269 /* Ignore unrecognized type attributes, so future
1270 compilers can invent new ones. */
1283 enum debug_type_kind code
;
1284 const char *q1
, *q2
, *p
;
1286 /* A cross reference to another type. */
1291 code
= DEBUG_KIND_STRUCT
;
1294 code
= DEBUG_KIND_UNION
;
1297 code
= DEBUG_KIND_ENUM
;
1300 /* Complain and keep going, so compilers can invent new
1301 cross-reference types. */
1302 warn_stab (orig
, _("unrecognized cross reference type"));
1303 code
= DEBUG_KIND_STRUCT
;
1308 q1
= strchr (*pp
, '<');
1309 p
= strchr (*pp
, ':');
1313 return DEBUG_TYPE_NULL
;
1315 while (q1
!= NULL
&& p
> q1
&& p
[1] == ':')
1317 q2
= strchr (q1
, '>');
1318 if (q2
== NULL
|| q2
< p
)
1321 p
= strchr (p
, ':');
1325 return DEBUG_TYPE_NULL
;
1329 /* Some versions of g++ can emit stabs like
1331 which define structures in terms of themselves. We need to
1332 tell the caller to avoid building a circular structure. */
1333 if (typename
!= NULL
1334 && strncmp (typename
, *pp
, p
- *pp
) == 0
1335 && typename
[p
- *pp
] == '\0')
1336 info
->self_crossref
= true;
1338 dtype
= stab_find_tagged_type (dhandle
, info
, *pp
, p
- *pp
, code
);
1360 /* This type is defined as another type. */
1365 /* Peek ahead at the number to detect void. */
1366 if (! parse_stab_type_number (pp
, xtypenums
))
1367 return DEBUG_TYPE_NULL
;
1369 if (typenums
[0] == xtypenums
[0] && typenums
[1] == xtypenums
[1])
1371 /* This type is being defined as itself, which means that
1373 dtype
= debug_make_void_type (dhandle
);
1379 /* Go back to the number and have parse_stab_type get it.
1380 This means that we can deal with something like
1381 t(1,2)=(3,4)=... which the Lucid compiler uses. */
1382 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
,
1383 pp
, (debug_type
**) NULL
);
1384 if (dtype
== DEBUG_TYPE_NULL
)
1385 return DEBUG_TYPE_NULL
;
1388 if (typenums
[0] != -1)
1390 if (! stab_record_type (dhandle
, info
, typenums
, dtype
))
1391 return DEBUG_TYPE_NULL
;
1398 dtype
= debug_make_pointer_type (dhandle
,
1399 parse_stab_type (dhandle
, info
,
1400 (const char *) NULL
,
1402 (debug_type
**) NULL
));
1406 /* Reference to another type. */
1407 dtype
= (debug_make_reference_type
1409 parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
1410 (debug_type
**) NULL
)));
1414 /* Function returning another type. */
1415 /* FIXME: gdb checks os9k_stabs here. */
1416 dtype
= (debug_make_function_type
1418 parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
1419 (debug_type
**) NULL
),
1420 (debug_type
*) NULL
, false));
1424 /* Const qualifier on some type (Sun). */
1425 /* FIXME: gdb accepts 'c' here if os9k_stabs. */
1426 dtype
= debug_make_const_type (dhandle
,
1427 parse_stab_type (dhandle
, info
,
1428 (const char *) NULL
,
1430 (debug_type
**) NULL
));
1434 /* Volatile qual on some type (Sun). */
1435 /* FIXME: gdb accepts 'i' here if os9k_stabs. */
1436 dtype
= (debug_make_volatile_type
1438 parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
1439 (debug_type
**) NULL
)));
1443 /* Offset (class & variable) type. This is used for a pointer
1444 relative to an object. */
1451 domain
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
1452 (debug_type
**) NULL
);
1453 if (domain
== DEBUG_TYPE_NULL
)
1454 return DEBUG_TYPE_NULL
;
1459 return DEBUG_TYPE_NULL
;
1463 memtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
1464 (debug_type
**) NULL
);
1465 if (memtype
== DEBUG_TYPE_NULL
)
1466 return DEBUG_TYPE_NULL
;
1468 dtype
= debug_make_offset_type (dhandle
, domain
, memtype
);
1473 /* Method (class & fn) type. */
1476 debug_type return_type
;
1479 return_type
= parse_stab_type (dhandle
, info
, (const char *) NULL
,
1480 pp
, (debug_type
**) NULL
);
1481 if (return_type
== DEBUG_TYPE_NULL
)
1482 return DEBUG_TYPE_NULL
;
1486 return DEBUG_TYPE_NULL
;
1489 dtype
= debug_make_method_type (dhandle
, return_type
,
1491 (debug_type
*) NULL
, false);
1496 debug_type return_type
;
1502 domain
= parse_stab_type (dhandle
, info
, (const char *) NULL
,
1503 pp
, (debug_type
**) NULL
);
1504 if (domain
== DEBUG_TYPE_NULL
)
1505 return DEBUG_TYPE_NULL
;
1510 return DEBUG_TYPE_NULL
;
1514 return_type
= parse_stab_type (dhandle
, info
, (const char *) NULL
,
1515 pp
, (debug_type
**) NULL
);
1516 if (return_type
== DEBUG_TYPE_NULL
)
1517 return DEBUG_TYPE_NULL
;
1520 args
= (debug_type
*) xmalloc (alloc
* sizeof *args
);
1527 return DEBUG_TYPE_NULL
;
1534 args
= ((debug_type
*)
1535 xrealloc ((PTR
) args
, alloc
* sizeof *args
));
1538 args
[n
] = parse_stab_type (dhandle
, info
, (const char *) NULL
,
1539 pp
, (debug_type
**) NULL
);
1540 if (args
[n
] == DEBUG_TYPE_NULL
)
1541 return DEBUG_TYPE_NULL
;
1546 /* If the last type is not void, then this function takes a
1547 variable number of arguments. Otherwise, we must strip
1550 || debug_get_type_kind (dhandle
, args
[n
- 1]) != DEBUG_KIND_VOID
)
1558 args
[n
] = DEBUG_TYPE_NULL
;
1560 dtype
= debug_make_method_type (dhandle
, return_type
, domain
, args
,
1567 dtype
= parse_stab_range_type (dhandle
, info
, typename
, pp
, typenums
);
1571 /* FIXME: gdb checks os9k_stabs here. */
1572 /* Sun ACC builtin int type. */
1573 dtype
= parse_stab_sun_builtin_type (dhandle
, pp
);
1577 /* Sun ACC builtin float type. */
1578 dtype
= parse_stab_sun_floating_type (dhandle
, pp
);
1582 /* Enumeration type. */
1583 dtype
= parse_stab_enum_type (dhandle
, pp
);
1588 /* Struct or union type. */
1589 dtype
= parse_stab_struct_type (dhandle
, info
, typename
, pp
,
1590 descriptor
== 's', typenums
);
1598 return DEBUG_TYPE_NULL
;
1602 dtype
= parse_stab_array_type (dhandle
, info
, pp
, stringp
);
1606 dtype
= debug_make_set_type (dhandle
,
1607 parse_stab_type (dhandle
, info
,
1608 (const char *) NULL
,
1610 (debug_type
**) NULL
),
1616 return DEBUG_TYPE_NULL
;
1619 if (dtype
== DEBUG_TYPE_NULL
)
1620 return DEBUG_TYPE_NULL
;
1622 if (typenums
[0] != -1)
1624 if (! stab_record_type (dhandle
, info
, typenums
, dtype
))
1625 return DEBUG_TYPE_NULL
;
1630 if (! debug_record_type_size (dhandle
, dtype
, (unsigned int) size
))
1637 /* Read a number by which a type is referred to in dbx data, or
1638 perhaps read a pair (FILENUM, TYPENUM) in parentheses. Just a
1639 single number N is equivalent to (0,N). Return the two numbers by
1640 storing them in the vector TYPENUMS. */
1643 parse_stab_type_number (pp
, typenums
)
1654 typenums
[1] = (int) parse_number (pp
, (boolean
*) NULL
);
1659 typenums
[0] = (int) parse_number (pp
, (boolean
*) NULL
);
1666 typenums
[1] = (int) parse_number (pp
, (boolean
*) NULL
);
1678 /* Parse a range type. */
1681 parse_stab_range_type (dhandle
, info
, typename
, pp
, typenums
)
1683 struct stab_handle
*info
;
1684 const char *typename
;
1686 const int *typenums
;
1690 boolean self_subrange
;
1691 debug_type index_type
;
1692 const char *s2
, *s3
;
1693 bfd_signed_vma n2
, n3
;
1698 index_type
= DEBUG_TYPE_NULL
;
1700 /* First comes a type we are a subrange of.
1701 In C it is usually 0, 1 or the type being defined. */
1702 if (! parse_stab_type_number (pp
, rangenums
))
1703 return DEBUG_TYPE_NULL
;
1705 self_subrange
= (rangenums
[0] == typenums
[0]
1706 && rangenums
[1] == typenums
[1]);
1711 index_type
= parse_stab_type (dhandle
, info
, (const char *) NULL
,
1712 pp
, (debug_type
**) NULL
);
1713 if (index_type
== DEBUG_TYPE_NULL
)
1714 return DEBUG_TYPE_NULL
;
1720 /* The remaining two operands are usually lower and upper bounds of
1721 the range. But in some special cases they mean something else. */
1723 n2
= parse_number (pp
, &ov2
);
1727 return DEBUG_TYPE_NULL
;
1732 n3
= parse_number (pp
, &ov3
);
1736 return DEBUG_TYPE_NULL
;
1742 /* gcc will emit range stabs for long long types. Handle this
1743 as a special case. FIXME: This needs to be more general. */
1744 #define LLLOW "01000000000000000000000;"
1745 #define LLHIGH "0777777777777777777777;"
1746 #define ULLHIGH "01777777777777777777777;"
1747 if (index_type
== DEBUG_TYPE_NULL
)
1749 if (strncmp (s2
, LLLOW
, sizeof LLLOW
- 1) == 0
1750 && strncmp (s3
, LLHIGH
, sizeof LLHIGH
- 1) == 0)
1751 return debug_make_int_type (dhandle
, 8, false);
1754 && strncmp (s3
, ULLHIGH
, sizeof ULLHIGH
- 1) == 0)
1755 return debug_make_int_type (dhandle
, 8, true);
1758 warn_stab (orig
, _("numeric overflow"));
1761 if (index_type
== DEBUG_TYPE_NULL
)
1763 /* A type defined as a subrange of itself, with both bounds 0,
1765 if (self_subrange
&& n2
== 0 && n3
== 0)
1766 return debug_make_void_type (dhandle
);
1768 /* A type defined as a subrange of itself, with n2 positive and
1769 n3 zero, is a complex type, and n2 is the number of bytes. */
1770 if (self_subrange
&& n3
== 0 && n2
> 0)
1771 return debug_make_complex_type (dhandle
, n2
);
1773 /* If n3 is zero and n2 is positive, this is a floating point
1774 type, and n2 is the number of bytes. */
1775 if (n3
== 0 && n2
> 0)
1776 return debug_make_float_type (dhandle
, n2
);
1778 /* If the upper bound is -1, this is an unsigned int. */
1779 if (n2
== 0 && n3
== -1)
1781 /* When gcc is used with -gstabs, but not -gstabs+, it will emit
1782 long long int:t6=r1;0;-1;
1783 long long unsigned int:t7=r1;0;-1;
1784 We hack here to handle this reasonably. */
1785 if (typename
!= NULL
)
1787 if (strcmp (typename
, "long long int") == 0)
1788 return debug_make_int_type (dhandle
, 8, false);
1789 else if (strcmp (typename
, "long long unsigned int") == 0)
1790 return debug_make_int_type (dhandle
, 8, true);
1792 /* FIXME: The size here really depends upon the target. */
1793 return debug_make_int_type (dhandle
, 4, true);
1796 /* A range of 0 to 127 is char. */
1797 if (self_subrange
&& n2
== 0 && n3
== 127)
1798 return debug_make_int_type (dhandle
, 1, false);
1800 /* FIXME: gdb checks for the language CHILL here. */
1805 return debug_make_int_type (dhandle
, - n3
, true);
1806 else if (n3
== 0xff)
1807 return debug_make_int_type (dhandle
, 1, true);
1808 else if (n3
== 0xffff)
1809 return debug_make_int_type (dhandle
, 2, true);
1810 else if (n3
== 0xffffffff)
1811 return debug_make_int_type (dhandle
, 4, true);
1813 else if (n3
== (((bfd_vma
) 0xffffffff) << 32) | 0xffffffff)
1814 return debug_make_int_type (dhandle
, 8, true);
1819 && (self_subrange
|| n2
== -8))
1820 return debug_make_int_type (dhandle
, - n2
, true);
1821 else if (n2
== - n3
- 1 || n2
== n3
+ 1)
1824 return debug_make_int_type (dhandle
, 1, false);
1825 else if (n3
== 0x7fff)
1826 return debug_make_int_type (dhandle
, 2, false);
1827 else if (n3
== 0x7fffffff)
1828 return debug_make_int_type (dhandle
, 4, false);
1830 else if (n3
== (((bfd_vma
) 0x7fffffff) << 32) | 0xffffffff)
1831 return debug_make_int_type (dhandle
, 8, false);
1836 /* At this point I don't have the faintest idea how to deal with a
1837 self_subrange type; I'm going to assume that this is used as an
1838 idiom, and that all of them are special cases. So . . . */
1842 return DEBUG_TYPE_NULL
;
1845 index_type
= stab_find_type (dhandle
, info
, rangenums
);
1846 if (index_type
== DEBUG_TYPE_NULL
)
1848 /* Does this actually ever happen? Is that why we are worrying
1849 about dealing with it rather than just calling error_type? */
1850 warn_stab (orig
, _("missing index type"));
1851 index_type
= debug_make_int_type (dhandle
, 4, false);
1854 return debug_make_range_type (dhandle
, index_type
, n2
, n3
);
1857 /* Sun's ACC uses a somewhat saner method for specifying the builtin
1858 typedefs in every file (for int, long, etc):
1860 type = b <signed> <width>; <offset>; <nbits>
1861 signed = u or s. Possible c in addition to u or s (for char?).
1862 offset = offset from high order bit to start bit of type.
1863 width is # bytes in object of this type, nbits is # bits in type.
1865 The width/offset stuff appears to be for small objects stored in
1866 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
1870 parse_stab_sun_builtin_type (dhandle
, pp
)
1890 return DEBUG_TYPE_NULL
;
1894 /* For some odd reason, all forms of char put a c here. This is strange
1895 because no other type has this honor. We can safely ignore this because
1896 we actually determine 'char'acterness by the number of bits specified in
1901 /* The first number appears to be the number of bytes occupied
1902 by this type, except that unsigned short is 4 instead of 2.
1903 Since this information is redundant with the third number,
1904 we will ignore it. */
1905 (void) parse_number (pp
, (boolean
*) NULL
);
1909 return DEBUG_TYPE_NULL
;
1913 /* The second number is always 0, so ignore it too. */
1914 (void) parse_number (pp
, (boolean
*) NULL
);
1918 return DEBUG_TYPE_NULL
;
1922 /* The third number is the number of bits for this type. */
1923 bits
= parse_number (pp
, (boolean
*) NULL
);
1925 /* The type *should* end with a semicolon. If it are embedded
1926 in a larger type the semicolon may be the only way to know where
1927 the type ends. If this type is at the end of the stabstring we
1928 can deal with the omitted semicolon (but we don't have to like
1929 it). Don't bother to complain(), Sun's compiler omits the semicolon
1935 return debug_make_void_type (dhandle
);
1937 return debug_make_int_type (dhandle
, bits
/ 8, unsignedp
);
1940 /* Parse a builtin floating type generated by the Sun compiler. */
1943 parse_stab_sun_floating_type (dhandle
, pp
)
1953 /* The first number has more details about the type, for example
1955 details
= parse_number (pp
, (boolean
*) NULL
);
1959 return DEBUG_TYPE_NULL
;
1962 /* The second number is the number of bytes occupied by this type */
1963 bytes
= parse_number (pp
, (boolean
*) NULL
);
1967 return DEBUG_TYPE_NULL
;
1970 if (details
== NF_COMPLEX
1971 || details
== NF_COMPLEX16
1972 || details
== NF_COMPLEX32
)
1973 return debug_make_complex_type (dhandle
, bytes
);
1975 return debug_make_float_type (dhandle
, bytes
);
1978 /* Handle an enum type. */
1981 parse_stab_enum_type (dhandle
, pp
)
1987 bfd_signed_vma
*values
;
1993 /* FIXME: gdb checks os9k_stabs here. */
1995 /* The aix4 compiler emits an extra field before the enum members;
1996 my guess is it's a type of some sort. Just ignore it. */
2004 /* Read the value-names and their values.
2005 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
2006 A semicolon or comma instead of a NAME means the end. */
2008 names
= (const char **) xmalloc (alloc
* sizeof *names
);
2009 values
= (bfd_signed_vma
*) xmalloc (alloc
* sizeof *values
);
2011 while (**pp
!= '\0' && **pp
!= ';' && **pp
!= ',')
2021 name
= savestring (*pp
, p
- *pp
);
2024 val
= (bfd_signed_vma
) parse_number (pp
, (boolean
*) NULL
);
2028 return DEBUG_TYPE_NULL
;
2035 names
= ((const char **)
2036 xrealloc ((PTR
) names
, alloc
* sizeof *names
));
2037 values
= ((bfd_signed_vma
*)
2038 xrealloc ((PTR
) values
, alloc
* sizeof *values
));
2052 return debug_make_enum_type (dhandle
, names
, values
);
2055 /* Read the description of a structure (or union type) and return an object
2056 describing the type.
2058 PP points to a character pointer that points to the next unconsumed token
2059 in the the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
2060 *PP will point to "4a:1,0,32;;". */
2063 parse_stab_struct_type (dhandle
, info
, tagname
, pp
, structp
, typenums
)
2065 struct stab_handle
*info
;
2066 const char *tagname
;
2069 const int *typenums
;
2073 debug_baseclass
*baseclasses
;
2074 debug_field
*fields
;
2076 debug_method
*methods
;
2077 debug_type vptrbase
;
2083 size
= parse_number (pp
, (boolean
*) NULL
);
2085 /* Get the other information. */
2086 if (! parse_stab_baseclasses (dhandle
, info
, pp
, &baseclasses
)
2087 || ! parse_stab_struct_fields (dhandle
, info
, pp
, &fields
, &statics
)
2088 || ! parse_stab_members (dhandle
, info
, tagname
, pp
, typenums
, &methods
)
2089 || ! parse_stab_tilde_field (dhandle
, info
, pp
, typenums
, &vptrbase
,
2091 return DEBUG_TYPE_NULL
;
2094 && baseclasses
== NULL
2096 && vptrbase
== DEBUG_TYPE_NULL
2098 return debug_make_struct_type (dhandle
, structp
, size
, fields
);
2100 return debug_make_object_type (dhandle
, structp
, size
, fields
, baseclasses
,
2101 methods
, vptrbase
, ownvptr
);
2104 /* The stabs for C++ derived classes contain baseclass information which
2105 is marked by a '!' character after the total size. This function is
2106 called when we encounter the baseclass marker, and slurps up all the
2107 baseclass information.
2109 Immediately following the '!' marker is the number of base classes that
2110 the class is derived from, followed by information for each base class.
2111 For each base class, there are two visibility specifiers, a bit offset
2112 to the base class information within the derived class, a reference to
2113 the type for the base class, and a terminating semicolon.
2115 A typical example, with two base classes, would be "!2,020,19;0264,21;".
2117 Baseclass information marker __________________|| | | | | | |
2118 Number of baseclasses __________________________| | | | | | |
2119 Visibility specifiers (2) ________________________| | | | | |
2120 Offset in bits from start of class _________________| | | | |
2121 Type number for base class ___________________________| | | |
2122 Visibility specifiers (2) _______________________________| | |
2123 Offset in bits from start of class ________________________| |
2124 Type number of base class ____________________________________|
2126 Return true for success, false for failure. */
2129 parse_stab_baseclasses (dhandle
, info
, pp
, retp
)
2131 struct stab_handle
*info
;
2133 debug_baseclass
**retp
;
2137 debug_baseclass
*classes
;
2145 /* No base classes. */
2150 c
= (unsigned int) parse_number (pp
, (boolean
*) NULL
);
2159 classes
= (debug_baseclass
*) xmalloc ((c
+ 1) * sizeof (**retp
));
2161 for (i
= 0; i
< c
; i
++)
2164 enum debug_visibility visibility
;
2177 warn_stab (orig
, _("unknown virtual character for baseclass"));
2186 visibility
= DEBUG_VISIBILITY_PRIVATE
;
2189 visibility
= DEBUG_VISIBILITY_PROTECTED
;
2192 visibility
= DEBUG_VISIBILITY_PUBLIC
;
2195 warn_stab (orig
, _("unknown visibility character for baseclass"));
2196 visibility
= DEBUG_VISIBILITY_PUBLIC
;
2201 /* The remaining value is the bit offset of the portion of the
2202 object corresponding to this baseclass. Always zero in the
2203 absence of multiple inheritance. */
2204 bitpos
= parse_number (pp
, (boolean
*) NULL
);
2212 type
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
2213 (debug_type
**) NULL
);
2214 if (type
== DEBUG_TYPE_NULL
)
2217 classes
[i
] = debug_make_baseclass (dhandle
, type
, bitpos
, virtual,
2219 if (classes
[i
] == DEBUG_BASECLASS_NULL
)
2227 classes
[i
] = DEBUG_BASECLASS_NULL
;
2234 /* Read struct or class data fields. They have the form:
2236 NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
2238 At the end, we see a semicolon instead of a field.
2240 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
2243 The optional VISIBILITY is one of:
2245 '/0' (VISIBILITY_PRIVATE)
2246 '/1' (VISIBILITY_PROTECTED)
2247 '/2' (VISIBILITY_PUBLIC)
2248 '/9' (VISIBILITY_IGNORE)
2250 or nothing, for C style fields with public visibility.
2252 Returns 1 for success, 0 for failure. */
2255 parse_stab_struct_fields (dhandle
, info
, pp
, retp
, staticsp
)
2257 struct stab_handle
*info
;
2264 debug_field
*fields
;
2275 fields
= (debug_field
*) xmalloc (alloc
* sizeof *fields
);
2278 /* FIXME: gdb checks os9k_stabs here. */
2282 /* Add 1 to c to leave room for NULL pointer at end. */
2286 fields
= ((debug_field
*)
2287 xrealloc ((PTR
) fields
, alloc
* sizeof *fields
));
2290 /* If it starts with CPLUS_MARKER it is a special abbreviation,
2291 unless the CPLUS_MARKER is followed by an underscore, in
2292 which case it is just the name of an anonymous type, which we
2293 should handle like any other type name. We accept either '$'
2294 or '.', because a field name can never contain one of these
2295 characters except as a CPLUS_MARKER. */
2297 if ((*p
== '$' || *p
== '.') && p
[1] != '_')
2300 if (! parse_stab_cpp_abbrev (dhandle
, info
, pp
, fields
+ c
))
2306 /* Look for the ':' that separates the field name from the field
2307 values. Data members are delimited by a single ':', while member
2308 functions are delimited by a pair of ':'s. When we hit the member
2309 functions (if any), terminate scan loop and return. */
2311 p
= strchr (p
, ':');
2321 if (! parse_stab_one_struct_field (dhandle
, info
, pp
, p
, fields
+ c
,
2328 fields
[c
] = DEBUG_FIELD_NULL
;
2335 /* Special GNU C++ name. */
2338 parse_stab_cpp_abbrev (dhandle
, info
, pp
, retp
)
2340 struct stab_handle
*info
;
2348 const char *typename
;
2352 *retp
= DEBUG_FIELD_NULL
;
2366 /* At this point, *pp points to something like "22:23=*22...", where
2367 the type number before the ':' is the "context" and everything
2368 after is a regular type definition. Lookup the type, find it's
2369 name, and construct the field name. */
2371 context
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
2372 (debug_type
**) NULL
);
2373 if (context
== DEBUG_TYPE_NULL
)
2379 /* $vf -- a virtual function table pointer. */
2383 /* $vb -- a virtual bsomethingorother */
2384 typename
= debug_get_type_name (dhandle
, context
);
2385 if (typename
== NULL
)
2387 warn_stab (orig
, _("unnamed $vb type"));
2390 name
= concat ("_vb$", typename
, (const char *) NULL
);
2393 warn_stab (orig
, _("unrecognized C++ abbreviation"));
2394 name
= "INVALID_CPLUSPLUS_ABBREV";
2405 type
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
2406 (debug_type
**) NULL
);
2414 bitpos
= parse_number (pp
, (boolean
*) NULL
);
2422 *retp
= debug_make_field (dhandle
, name
, type
, bitpos
, 0,
2423 DEBUG_VISIBILITY_PRIVATE
);
2424 if (*retp
== DEBUG_FIELD_NULL
)
2430 /* Parse a single field in a struct or union. */
2433 parse_stab_one_struct_field (dhandle
, info
, pp
, p
, retp
, staticsp
)
2435 struct stab_handle
*info
;
2443 enum debug_visibility visibility
;
2450 /* FIXME: gdb checks ARM_DEMANGLING here. */
2452 name
= savestring (*pp
, p
- *pp
);
2457 visibility
= DEBUG_VISIBILITY_PUBLIC
;
2464 visibility
= DEBUG_VISIBILITY_PRIVATE
;
2467 visibility
= DEBUG_VISIBILITY_PROTECTED
;
2470 visibility
= DEBUG_VISIBILITY_PUBLIC
;
2473 warn_stab (orig
, _("unknown visibility character for field"));
2474 visibility
= DEBUG_VISIBILITY_PUBLIC
;
2480 type
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
2481 (debug_type
**) NULL
);
2482 if (type
== DEBUG_TYPE_NULL
)
2489 /* This is a static class member. */
2491 p
= strchr (*pp
, ';');
2498 varname
= savestring (*pp
, p
- *pp
);
2502 *retp
= debug_make_static_member (dhandle
, name
, type
, varname
,
2516 bitpos
= parse_number (pp
, (boolean
*) NULL
);
2524 bitsize
= parse_number (pp
, (boolean
*) NULL
);
2532 if (bitpos
== 0 && bitsize
== 0)
2534 /* This can happen in two cases: (1) at least for gcc 2.4.5 or
2535 so, it is a field which has been optimized out. The correct
2536 stab for this case is to use VISIBILITY_IGNORE, but that is a
2537 recent invention. (2) It is a 0-size array. For example
2538 union { int num; char str[0]; } foo. Printing "<no value>"
2539 for str in "p foo" is OK, since foo.str (and thus foo.str[3])
2540 will continue to work, and a 0-size array as a whole doesn't
2541 have any contents to print.
2543 I suspect this probably could also happen with gcc -gstabs
2544 (not -gstabs+) for static fields, and perhaps other C++
2545 extensions. Hopefully few people use -gstabs with gdb, since
2546 it is intended for dbx compatibility. */
2547 visibility
= DEBUG_VISIBILITY_IGNORE
;
2550 /* FIXME: gdb does some stuff here to mark fields as unpacked. */
2552 *retp
= debug_make_field (dhandle
, name
, type
, bitpos
, bitsize
, visibility
);
2557 /* Read member function stabs info for C++ classes. The form of each member
2560 NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
2562 An example with two member functions is:
2564 afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
2566 For the case of overloaded operators, the format is op$::*.funcs, where
2567 $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
2568 name (such as `+=') and `.' marks the end of the operator name. */
2571 parse_stab_members (dhandle
, info
, tagname
, pp
, typenums
, retp
)
2573 struct stab_handle
*info
;
2574 const char *tagname
;
2576 const int *typenums
;
2577 debug_method
**retp
;
2580 debug_method
*methods
;
2596 debug_method_variant
*variants
;
2598 unsigned int allocvars
;
2599 debug_type look_ahead_type
;
2601 p
= strchr (*pp
, ':');
2602 if (p
== NULL
|| p
[1] != ':')
2605 /* FIXME: Some systems use something other than '$' here. */
2606 if ((*pp
)[0] != 'o' || (*pp
)[1] != 'p' || (*pp
)[2] != '$')
2608 name
= savestring (*pp
, p
- *pp
);
2613 /* This is a completely wierd case. In order to stuff in the
2614 names that might contain colons (the usual name delimiter),
2615 Mike Tiemann defined a different name format which is
2616 signalled if the identifier is "op$". In that case, the
2617 format is "op$::XXXX." where XXXX is the name. This is
2618 used for names like "+" or "=". YUUUUUUUK! FIXME! */
2620 for (p
= *pp
; *p
!= '.' && *p
!= '\0'; p
++)
2627 name
= savestring (*pp
, p
- *pp
);
2632 variants
= ((debug_method_variant
*)
2633 xmalloc (allocvars
* sizeof *variants
));
2636 look_ahead_type
= DEBUG_TYPE_NULL
;
2643 enum debug_visibility visibility
;
2644 boolean constp
, volatilep
, staticp
;
2647 const char *physname
;
2650 if (look_ahead_type
!= DEBUG_TYPE_NULL
)
2652 /* g++ version 1 kludge */
2653 type
= look_ahead_type
;
2654 look_ahead_type
= DEBUG_TYPE_NULL
;
2658 type
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
2659 (debug_type
**) NULL
);
2660 if (type
== DEBUG_TYPE_NULL
)
2670 p
= strchr (*pp
, ';');
2678 if (debug_get_type_kind (dhandle
, type
) == DEBUG_KIND_METHOD
2679 && debug_get_parameter_types (dhandle
, type
, &varargs
) == NULL
)
2682 argtypes
= savestring (*pp
, p
- *pp
);
2688 visibility
= DEBUG_VISIBILITY_PRIVATE
;
2691 visibility
= DEBUG_VISIBILITY_PROTECTED
;
2694 visibility
= DEBUG_VISIBILITY_PUBLIC
;
2704 /* Normal function. */
2708 /* const member function. */
2713 /* volatile member function. */
2718 /* const volatile member function. */
2726 /* File compiled with g++ version 1; no information. */
2729 warn_stab (orig
, _("const/volatile indicator missing"));
2737 /* virtual member function, followed by index. The sign
2738 bit is supposedly set to distinguish
2739 pointers-to-methods from virtual function indicies. */
2741 voffset
= parse_number (pp
, (boolean
*) NULL
);
2748 voffset
&= 0x7fffffff;
2750 if (**pp
== ';' || *pp
== '\0')
2752 /* Must be g++ version 1. */
2753 context
= DEBUG_TYPE_NULL
;
2757 /* Figure out from whence this virtual function
2758 came. It may belong to virtual function table of
2759 one of its baseclasses. */
2760 look_ahead_type
= parse_stab_type (dhandle
, info
,
2761 (const char *) NULL
,
2763 (debug_type
**) NULL
);
2766 /* g++ version 1 overloaded methods. */
2767 context
= DEBUG_TYPE_NULL
;
2771 context
= look_ahead_type
;
2772 look_ahead_type
= DEBUG_TYPE_NULL
;
2784 /* static member function. */
2788 context
= DEBUG_TYPE_NULL
;
2789 if (strncmp (argtypes
, name
, strlen (name
)) != 0)
2794 warn_stab (orig
, "member function type missing");
2796 context
= DEBUG_TYPE_NULL
;
2802 context
= DEBUG_TYPE_NULL
;
2806 /* If the type is not a stub, then the argtypes string is
2807 the physical name of the function. Otherwise the
2808 argtypes string is the mangled form of the argument
2809 types, and the full type and the physical name must be
2810 extracted from them. */
2812 physname
= argtypes
;
2815 debug_type class_type
, return_type
;
2817 class_type
= stab_find_type (dhandle
, info
, typenums
);
2818 if (class_type
== DEBUG_TYPE_NULL
)
2820 return_type
= debug_get_return_type (dhandle
, type
);
2821 if (return_type
== DEBUG_TYPE_NULL
)
2826 type
= parse_stab_argtypes (dhandle
, info
, class_type
, name
,
2827 tagname
, return_type
, argtypes
,
2828 constp
, volatilep
, &physname
);
2829 if (type
== DEBUG_TYPE_NULL
)
2833 if (cvars
+ 1 >= allocvars
)
2836 variants
= ((debug_method_variant
*)
2837 xrealloc ((PTR
) variants
,
2838 allocvars
* sizeof *variants
));
2842 variants
[cvars
] = debug_make_method_variant (dhandle
, physname
,
2847 variants
[cvars
] = debug_make_static_method_variant (dhandle
,
2853 if (variants
[cvars
] == DEBUG_METHOD_VARIANT_NULL
)
2858 while (**pp
!= ';' && **pp
!= '\0');
2860 variants
[cvars
] = DEBUG_METHOD_VARIANT_NULL
;
2868 methods
= ((debug_method
*)
2869 xrealloc ((PTR
) methods
, alloc
* sizeof *methods
));
2872 methods
[c
] = debug_make_method (dhandle
, name
, variants
);
2877 if (methods
!= NULL
)
2878 methods
[c
] = DEBUG_METHOD_NULL
;
2885 /* Parse a string representing argument types for a method. Stabs
2886 tries to save space by packing argument types into a mangled
2887 string. This string should give us enough information to extract
2888 both argument types and the physical name of the function, given
2892 parse_stab_argtypes (dhandle
, info
, class_type
, fieldname
, tagname
,
2893 return_type
, argtypes
, constp
, volatilep
, pphysname
)
2895 struct stab_handle
*info
;
2896 debug_type class_type
;
2897 const char *fieldname
;
2898 const char *tagname
;
2899 debug_type return_type
;
2900 const char *argtypes
;
2903 const char **pphysname
;
2905 boolean is_full_physname_constructor
;
2906 boolean is_constructor
;
2907 boolean is_destructor
;
2911 /* Constructors are sometimes handled specially. */
2912 is_full_physname_constructor
= ((argtypes
[0] == '_'
2913 && argtypes
[1] == '_'
2914 && (isdigit ((unsigned char) argtypes
[2])
2915 || argtypes
[2] == 'Q'
2916 || argtypes
[2] == 't'))
2917 || strncmp (argtypes
, "__ct", 4) == 0);
2919 is_constructor
= (is_full_physname_constructor
2921 && strcmp (fieldname
, tagname
) == 0));
2922 is_destructor
= ((argtypes
[0] == '_'
2923 && (argtypes
[1] == '$' || argtypes
[1] == '.')
2924 && argtypes
[2] == '_')
2925 || strncmp (argtypes
, "__dt", 4) == 0);
2927 if (is_destructor
|| is_full_physname_constructor
)
2928 *pphysname
= argtypes
;
2932 const char *const_prefix
;
2933 const char *volatile_prefix
;
2935 unsigned int mangled_name_len
;
2938 len
= tagname
== NULL
? 0 : strlen (tagname
);
2939 const_prefix
= constp
? "C" : "";
2940 volatile_prefix
= volatilep
? "V" : "";
2943 sprintf (buf
, "__%s%s", const_prefix
, volatile_prefix
);
2944 else if (tagname
!= NULL
&& strchr (tagname
, '<') != NULL
)
2946 /* Template methods are fully mangled. */
2947 sprintf (buf
, "__%s%s", const_prefix
, volatile_prefix
);
2952 sprintf (buf
, "__%s%s%d", const_prefix
, volatile_prefix
, len
);
2954 mangled_name_len
= ((is_constructor
? 0 : strlen (fieldname
))
2960 if (fieldname
[0] == 'o'
2961 && fieldname
[1] == 'p'
2962 && (fieldname
[2] == '$' || fieldname
[2] == '.'))
2966 opname
= cplus_mangle_opname (fieldname
+ 3, 0);
2969 fprintf (stderr
, _("No mangling for \"%s\"\n"), fieldname
);
2970 return DEBUG_TYPE_NULL
;
2972 mangled_name_len
+= strlen (opname
);
2973 physname
= (char *) xmalloc (mangled_name_len
);
2974 strncpy (physname
, fieldname
, 3);
2975 strcpy (physname
+ 3, opname
);
2979 physname
= (char *) xmalloc (mangled_name_len
);
2983 strcpy (physname
, fieldname
);
2986 strcat (physname
, buf
);
2987 if (tagname
!= NULL
)
2988 strcat (physname
, tagname
);
2989 strcat (physname
, argtypes
);
2991 *pphysname
= physname
;
2994 if (*argtypes
== '\0' || is_destructor
)
2996 args
= (debug_type
*) xmalloc (sizeof *args
);
2998 return debug_make_method_type (dhandle
, return_type
, class_type
, args
,
3002 args
= stab_demangle_argtypes (dhandle
, info
, *pphysname
, &varargs
);
3004 return DEBUG_TYPE_NULL
;
3006 return debug_make_method_type (dhandle
, return_type
, class_type
, args
,
3010 /* The tail end of stabs for C++ classes that contain a virtual function
3011 pointer contains a tilde, a %, and a type number.
3012 The type number refers to the base class (possibly this class itself) which
3013 contains the vtable pointer for the current class.
3015 This function is called when we have parsed all the method declarations,
3016 so we can look for the vptr base class info. */
3019 parse_stab_tilde_field (dhandle
, info
, pp
, typenums
, retvptrbase
, retownvptr
)
3021 struct stab_handle
*info
;
3023 const int *typenums
;
3024 debug_type
*retvptrbase
;
3025 boolean
*retownvptr
;
3031 *retvptrbase
= DEBUG_TYPE_NULL
;
3032 *retownvptr
= false;
3036 /* If we are positioned at a ';', then skip it. */
3045 if (**pp
== '=' || **pp
== '+' || **pp
== '-')
3047 /* Obsolete flags that used to indicate the presence of
3048 constructors and/or destructors. */
3059 /* The next number is the type number of the base class (possibly
3060 our own class) which supplies the vtable for this class. */
3061 if (! parse_stab_type_number (pp
, vtypenums
))
3064 if (vtypenums
[0] == typenums
[0]
3065 && vtypenums
[1] == typenums
[1])
3074 vtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
3075 (debug_type
**) NULL
);
3076 for (p
= *pp
; *p
!= ';' && *p
!= '\0'; p
++)
3084 *retvptrbase
= vtype
;
3092 /* Read a definition of an array type. */
3095 parse_stab_array_type (dhandle
, info
, pp
, stringp
)
3097 struct stab_handle
*info
;
3104 debug_type index_type
;
3106 bfd_signed_vma lower
, upper
;
3107 debug_type element_type
;
3109 /* Format of an array type:
3110 "ar<index type>;lower;upper;<array_contents_type>".
3111 OS9000: "arlower,upper;<array_contents_type>".
3113 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
3114 for these, produce a type like float[][]. */
3118 /* FIXME: gdb checks os9k_stabs here. */
3120 /* If the index type is type 0, we take it as int. */
3122 if (! parse_stab_type_number (&p
, typenums
))
3124 if (typenums
[0] == 0 && typenums
[1] == 0 && **pp
!= '=')
3126 index_type
= debug_find_named_type (dhandle
, "int");
3127 if (index_type
== DEBUG_TYPE_NULL
)
3129 index_type
= debug_make_int_type (dhandle
, 4, false);
3130 if (index_type
== DEBUG_TYPE_NULL
)
3137 index_type
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
3138 (debug_type
**) NULL
);
3144 return DEBUG_TYPE_NULL
;
3150 if (! isdigit ((unsigned char) **pp
) && **pp
!= '-')
3156 lower
= (bfd_signed_vma
) parse_number (pp
, (boolean
*) NULL
);
3164 if (! isdigit ((unsigned char) **pp
) && **pp
!= '-')
3170 upper
= (bfd_signed_vma
) parse_number (pp
, (boolean
*) NULL
);
3178 element_type
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
3179 (debug_type
**) NULL
);
3180 if (element_type
== DEBUG_TYPE_NULL
)
3189 return debug_make_array_type (dhandle
, element_type
, index_type
, lower
,
3193 /* This struct holds information about files we have seen using
3198 /* The next N_BINCL file. */
3199 struct bincl_file
*next
;
3200 /* The next N_BINCL on the stack. */
3201 struct bincl_file
*next_stack
;
3202 /* The file name. */
3204 /* The hash value. */
3206 /* The file index. */
3208 /* The list of types defined in this file. */
3209 struct stab_types
*file_types
;
3212 /* Start a new N_BINCL file, pushing it onto the stack. */
3215 push_bincl (info
, name
, hash
)
3216 struct stab_handle
*info
;
3220 struct bincl_file
*n
;
3222 n
= (struct bincl_file
*) xmalloc (sizeof *n
);
3223 n
->next
= info
->bincl_list
;
3224 n
->next_stack
= info
->bincl_stack
;
3227 n
->file
= info
->files
;
3228 n
->file_types
= NULL
;
3229 info
->bincl_list
= n
;
3230 info
->bincl_stack
= n
;
3233 info
->file_types
= ((struct stab_types
**)
3234 xrealloc ((PTR
) info
->file_types
,
3236 * sizeof *info
->file_types
)));
3237 info
->file_types
[n
->file
] = NULL
;
3240 /* Finish an N_BINCL file, at an N_EINCL, popping the name off the
3245 struct stab_handle
*info
;
3247 struct bincl_file
*o
;
3249 o
= info
->bincl_stack
;
3251 return info
->main_filename
;
3252 info
->bincl_stack
= o
->next_stack
;
3254 o
->file_types
= info
->file_types
[o
->file
];
3256 if (info
->bincl_stack
== NULL
)
3257 return info
->main_filename
;
3258 return info
->bincl_stack
->name
;
3261 /* Handle an N_EXCL: get the types from the corresponding N_BINCL. */
3264 find_excl (info
, name
, hash
)
3265 struct stab_handle
*info
;
3269 struct bincl_file
*l
;
3272 info
->file_types
= ((struct stab_types
**)
3273 xrealloc ((PTR
) info
->file_types
,
3275 * sizeof *info
->file_types
)));
3277 for (l
= info
->bincl_list
; l
!= NULL
; l
= l
->next
)
3278 if (l
->hash
== hash
&& strcmp (l
->name
, name
) == 0)
3282 warn_stab (name
, _("Undefined N_EXCL"));
3283 info
->file_types
[info
->files
- 1] = NULL
;
3287 info
->file_types
[info
->files
- 1] = l
->file_types
;
3292 /* Handle a variable definition. gcc emits variable definitions for a
3293 block before the N_LBRAC, so we must hold onto them until we see
3294 it. The SunPRO compiler emits variable definitions after the
3295 N_LBRAC, so we can call debug_record_variable immediately. */
3298 stab_record_variable (dhandle
, info
, name
, type
, kind
, val
)
3300 struct stab_handle
*info
;
3303 enum debug_var_kind kind
;
3306 struct stab_pending_var
*v
;
3308 if ((kind
== DEBUG_GLOBAL
|| kind
== DEBUG_STATIC
)
3309 || ! info
->within_function
3310 || (info
->gcc_compiled
== 0 && info
->n_opt_found
))
3311 return debug_record_variable (dhandle
, name
, type
, kind
, val
);
3313 v
= (struct stab_pending_var
*) xmalloc (sizeof *v
);
3314 memset (v
, 0, sizeof *v
);
3316 v
->next
= info
->pending
;
3326 /* Emit pending variable definitions. This is called after we see the
3327 N_LBRAC that starts the block. */
3330 stab_emit_pending_vars (dhandle
, info
)
3332 struct stab_handle
*info
;
3334 struct stab_pending_var
*v
;
3339 struct stab_pending_var
*next
;
3341 if (! debug_record_variable (dhandle
, v
->name
, v
->type
, v
->kind
, v
->val
))
3349 info
->pending
= NULL
;
3354 /* Find the slot for a type in the database. */
3357 stab_find_slot (info
, typenums
)
3358 struct stab_handle
*info
;
3359 const int *typenums
;
3363 struct stab_types
**ps
;
3365 filenum
= typenums
[0];
3366 index
= typenums
[1];
3368 if (filenum
< 0 || (unsigned int) filenum
>= info
->files
)
3370 fprintf (stderr
, _("Type file number %d out of range\n"), filenum
);
3375 fprintf (stderr
, _("Type index number %d out of range\n"), index
);
3379 ps
= info
->file_types
+ filenum
;
3381 while (index
>= STAB_TYPES_SLOTS
)
3385 *ps
= (struct stab_types
*) xmalloc (sizeof **ps
);
3386 memset (*ps
, 0, sizeof **ps
);
3389 index
-= STAB_TYPES_SLOTS
;
3393 *ps
= (struct stab_types
*) xmalloc (sizeof **ps
);
3394 memset (*ps
, 0, sizeof **ps
);
3397 return (*ps
)->types
+ index
;
3400 /* Find a type given a type number. If the type has not been
3401 allocated yet, create an indirect type. */
3404 stab_find_type (dhandle
, info
, typenums
)
3406 struct stab_handle
*info
;
3407 const int *typenums
;
3411 if (typenums
[0] == 0 && typenums
[1] < 0)
3413 /* A negative type number indicates an XCOFF builtin type. */
3414 return stab_xcoff_builtin_type (dhandle
, info
, typenums
[1]);
3417 slot
= stab_find_slot (info
, typenums
);
3419 return DEBUG_TYPE_NULL
;
3421 if (*slot
== DEBUG_TYPE_NULL
)
3422 return debug_make_indirect_type (dhandle
, slot
, (const char *) NULL
);
3427 /* Record that a given type number refers to a given type. */
3430 stab_record_type (dhandle
, info
, typenums
, type
)
3432 struct stab_handle
*info
;
3433 const int *typenums
;
3438 slot
= stab_find_slot (info
, typenums
);
3442 /* gdb appears to ignore type redefinitions, so we do as well. */
3449 /* Return an XCOFF builtin type. */
3452 stab_xcoff_builtin_type (dhandle
, info
, typenum
)
3454 struct stab_handle
*info
;
3460 if (typenum
>= 0 || typenum
< -XCOFF_TYPE_COUNT
)
3462 fprintf (stderr
, _("Unrecognized XCOFF type %d\n"), typenum
);
3463 return DEBUG_TYPE_NULL
;
3465 if (info
->xcoff_types
[-typenum
] != NULL
)
3466 return info
->xcoff_types
[-typenum
];
3471 /* The size of this and all the other types are fixed, defined
3472 by the debugging format. */
3474 rettype
= debug_make_int_type (dhandle
, 4, false);
3478 rettype
= debug_make_int_type (dhandle
, 1, false);
3482 rettype
= debug_make_int_type (dhandle
, 2, false);
3486 rettype
= debug_make_int_type (dhandle
, 4, false);
3489 name
= "unsigned char";
3490 rettype
= debug_make_int_type (dhandle
, 1, true);
3493 name
= "signed char";
3494 rettype
= debug_make_int_type (dhandle
, 1, false);
3497 name
= "unsigned short";
3498 rettype
= debug_make_int_type (dhandle
, 2, true);
3501 name
= "unsigned int";
3502 rettype
= debug_make_int_type (dhandle
, 4, true);
3506 rettype
= debug_make_int_type (dhandle
, 4, true);
3508 name
= "unsigned long";
3509 rettype
= debug_make_int_type (dhandle
, 4, true);
3513 rettype
= debug_make_void_type (dhandle
);
3516 /* IEEE single precision (32 bit). */
3518 rettype
= debug_make_float_type (dhandle
, 4);
3521 /* IEEE double precision (64 bit). */
3523 rettype
= debug_make_float_type (dhandle
, 8);
3526 /* This is an IEEE double on the RS/6000, and different machines
3527 with different sizes for "long double" should use different
3528 negative type numbers. See stabs.texinfo. */
3529 name
= "long double";
3530 rettype
= debug_make_float_type (dhandle
, 8);
3534 rettype
= debug_make_int_type (dhandle
, 4, false);
3538 rettype
= debug_make_bool_type (dhandle
, 4);
3541 name
= "short real";
3542 rettype
= debug_make_float_type (dhandle
, 4);
3546 rettype
= debug_make_float_type (dhandle
, 8);
3556 rettype
= debug_make_int_type (dhandle
, 1, true);
3560 rettype
= debug_make_bool_type (dhandle
, 1);
3564 rettype
= debug_make_bool_type (dhandle
, 2);
3568 rettype
= debug_make_bool_type (dhandle
, 4);
3572 rettype
= debug_make_bool_type (dhandle
, 4);
3575 /* Complex type consisting of two IEEE single precision values. */
3577 rettype
= debug_make_complex_type (dhandle
, 8);
3580 /* Complex type consisting of two IEEE double precision values. */
3581 name
= "double complex";
3582 rettype
= debug_make_complex_type (dhandle
, 16);
3586 rettype
= debug_make_int_type (dhandle
, 1, false);
3590 rettype
= debug_make_int_type (dhandle
, 2, false);
3594 rettype
= debug_make_int_type (dhandle
, 4, false);
3599 rettype
= debug_make_int_type (dhandle
, 2, false);
3603 rettype
= debug_make_int_type (dhandle
, 8, false);
3606 name
= "unsigned long long";
3607 rettype
= debug_make_int_type (dhandle
, 8, true);
3611 rettype
= debug_make_bool_type (dhandle
, 8);
3615 rettype
= debug_make_int_type (dhandle
, 8, false);
3621 rettype
= debug_name_type (dhandle
, name
, rettype
);
3623 info
->xcoff_types
[-typenum
] = rettype
;
3628 /* Find or create a tagged type. */
3631 stab_find_tagged_type (dhandle
, info
, p
, len
, kind
)
3633 struct stab_handle
*info
;
3636 enum debug_type_kind kind
;
3640 struct stab_tag
*st
;
3642 name
= savestring (p
, len
);
3644 /* We pass DEBUG_KIND_ILLEGAL because we want all tags in the same
3645 namespace. This is right for C, and I don't know how to handle
3646 other languages. FIXME. */
3647 dtype
= debug_find_tagged_type (dhandle
, name
, DEBUG_KIND_ILLEGAL
);
3648 if (dtype
!= DEBUG_TYPE_NULL
)
3654 /* We need to allocate an entry on the undefined tag list. */
3655 for (st
= info
->tags
; st
!= NULL
; st
= st
->next
)
3657 if (st
->name
[0] == name
[0]
3658 && strcmp (st
->name
, name
) == 0)
3660 if (st
->kind
== DEBUG_KIND_ILLEGAL
)
3668 st
= (struct stab_tag
*) xmalloc (sizeof *st
);
3669 memset (st
, 0, sizeof *st
);
3671 st
->next
= info
->tags
;
3674 st
->slot
= DEBUG_TYPE_NULL
;
3675 st
->type
= debug_make_indirect_type (dhandle
, &st
->slot
, name
);
3682 /* In order to get the correct argument types for a stubbed method, we
3683 need to extract the argument types from a C++ mangled string.
3684 Since the argument types can refer back to the return type, this
3685 means that we must demangle the entire physical name. In gdb this
3686 is done by calling cplus_demangle and running the results back
3687 through the C++ expression parser. Since we have no expression
3688 parser, we must duplicate much of the work of cplus_demangle here.
3690 We assume that GNU style demangling is used, since this is only
3691 done for method stubs, and only g++ should output that form of
3692 debugging information. */
3694 /* This structure is used to hold a pointer to type information which
3695 demangling a string. */
3697 struct stab_demangle_typestring
3699 /* The start of the type. This is not null terminated. */
3700 const char *typestring
;
3701 /* The length of the type. */
3705 /* This structure is used to hold information while demangling a
3708 struct stab_demangle_info
3710 /* The debugging information handle. */
3712 /* The stab information handle. */
3713 struct stab_handle
*info
;
3714 /* The array of arguments we are building. */
3716 /* Whether the method takes a variable number of arguments. */
3718 /* The array of types we have remembered. */
3719 struct stab_demangle_typestring
*typestrings
;
3720 /* The number of typestrings. */
3721 unsigned int typestring_count
;
3722 /* The number of typestring slots we have allocated. */
3723 unsigned int typestring_alloc
;
3726 static void stab_bad_demangle
PARAMS ((const char *));
3727 static unsigned int stab_demangle_count
PARAMS ((const char **));
3728 static boolean stab_demangle_get_count
3729 PARAMS ((const char **, unsigned int *));
3730 static boolean stab_demangle_prefix
3731 PARAMS ((struct stab_demangle_info
*, const char **));
3732 static boolean stab_demangle_function_name
3733 PARAMS ((struct stab_demangle_info
*, const char **, const char *));
3734 static boolean stab_demangle_signature
3735 PARAMS ((struct stab_demangle_info
*, const char **));
3736 static boolean stab_demangle_qualified
3737 PARAMS ((struct stab_demangle_info
*, const char **, debug_type
*));
3738 static boolean stab_demangle_template
3739 PARAMS ((struct stab_demangle_info
*, const char **, char **));
3740 static boolean stab_demangle_class
3741 PARAMS ((struct stab_demangle_info
*, const char **, const char **));
3742 static boolean stab_demangle_args
3743 PARAMS ((struct stab_demangle_info
*, const char **, debug_type
**,
3745 static boolean stab_demangle_arg
3746 PARAMS ((struct stab_demangle_info
*, const char **, debug_type
**,
3747 unsigned int *, unsigned int *));
3748 static boolean stab_demangle_type
3749 PARAMS ((struct stab_demangle_info
*, const char **, debug_type
*));
3750 static boolean stab_demangle_fund_type
3751 PARAMS ((struct stab_demangle_info
*, const char **, debug_type
*));
3752 static boolean stab_demangle_remember_type
3753 PARAMS ((struct stab_demangle_info
*, const char *, int));
3755 /* Warn about a bad demangling. */
3758 stab_bad_demangle (s
)
3761 fprintf (stderr
, _("bad mangled name `%s'\n"), s
);
3764 /* Get a count from a stab string. */
3767 stab_demangle_count (pp
)
3773 while (isdigit ((unsigned char) **pp
))
3776 count
+= **pp
- '0';
3782 /* Require a count in a string. The count may be multiple digits, in
3783 which case it must end in an underscore. */
3786 stab_demangle_get_count (pp
, pi
)
3790 if (! isdigit ((unsigned char) **pp
))
3795 if (isdigit ((unsigned char) **pp
))
3808 while (isdigit ((unsigned char) *p
));
3819 /* This function demangles a physical name, returning a NULL
3820 terminated array of argument types. */
3823 stab_demangle_argtypes (dhandle
, info
, physname
, pvarargs
)
3825 struct stab_handle
*info
;
3826 const char *physname
;
3829 struct stab_demangle_info minfo
;
3831 minfo
.dhandle
= dhandle
;
3834 minfo
.varargs
= false;
3835 minfo
.typestring_alloc
= 10;
3836 minfo
.typestrings
= ((struct stab_demangle_typestring
*)
3837 xmalloc (minfo
.typestring_alloc
3838 * sizeof *minfo
.typestrings
));
3839 minfo
.typestring_count
= 0;
3841 /* cplus_demangle checks for special GNU mangled forms, but we can't
3842 see any of them in mangled method argument types. */
3844 if (! stab_demangle_prefix (&minfo
, &physname
))
3847 if (*physname
!= '\0')
3849 if (! stab_demangle_signature (&minfo
, &physname
))
3853 free (minfo
.typestrings
);
3854 minfo
.typestrings
= NULL
;
3856 if (minfo
.args
== NULL
)
3857 fprintf (stderr
, _("no argument types in mangled string\n"));
3859 *pvarargs
= minfo
.varargs
;
3863 if (minfo
.typestrings
!= NULL
)
3864 free (minfo
.typestrings
);
3868 /* Demangle the prefix of the mangled name. */
3871 stab_demangle_prefix (minfo
, pp
)
3872 struct stab_demangle_info
*minfo
;
3878 /* cplus_demangle checks for global constructors and destructors,
3879 but we can't see them in mangled argument types. */
3881 /* Look for `__'. */
3885 scan
= strchr (scan
, '_');
3887 while (scan
!= NULL
&& *++scan
!= '_');
3891 stab_bad_demangle (*pp
);
3897 /* We found `__'; move ahead to the last contiguous `__' pair. */
3898 i
= strspn (scan
, "_");
3903 && (isdigit ((unsigned char) scan
[2])
3907 /* This is a GNU style constructor name. */
3911 else if (scan
== *pp
3912 && ! isdigit ((unsigned char) scan
[2])
3915 /* Look for the `__' that separates the prefix from the
3917 while (*scan
== '_')
3919 scan
= strstr (scan
, "__");
3920 if (scan
== NULL
|| scan
[2] == '\0')
3922 stab_bad_demangle (*pp
);
3926 return stab_demangle_function_name (minfo
, pp
, scan
);
3928 else if (scan
[2] != '\0')
3930 /* The name doesn't start with `__', but it does contain `__'. */
3931 return stab_demangle_function_name (minfo
, pp
, scan
);
3935 stab_bad_demangle (*pp
);
3941 /* Demangle a function name prefix. The scan argument points to the
3942 double underscore which separates the function name from the
3946 stab_demangle_function_name (minfo
, pp
, scan
)
3947 struct stab_demangle_info
*minfo
;
3953 /* The string from *pp to scan is the name of the function. We
3954 don't care about the name, since we just looking for argument
3955 types. However, for conversion operators, the name may include a
3956 type which we must remember in order to handle backreferences. */
3962 && strncmp (name
, "type", 4) == 0
3963 && (name
[4] == '$' || name
[4] == '.'))
3967 /* This is a type conversion operator. */
3969 if (! stab_demangle_type (minfo
, &tem
, (debug_type
*) NULL
))
3972 else if (name
[0] == '_'
3979 /* This is a type conversion operator. */
3981 if (! stab_demangle_type (minfo
, &tem
, (debug_type
*) NULL
))
3988 /* Demangle the signature. This is where the argument types are
3992 stab_demangle_signature (minfo
, pp
)
3993 struct stab_demangle_info
*minfo
;
3997 boolean expect_func
, func_done
;
4002 expect_func
= false;
4006 while (**pp
!= '\0')
4012 if (! stab_demangle_qualified (minfo
, pp
, (debug_type
*) NULL
)
4013 || ! stab_demangle_remember_type (minfo
, hold
, *pp
- hold
))
4020 /* Static member function. FIXME: Can this happen? */
4027 /* Const member function. */
4033 case '0': case '1': case '2': case '3': case '4':
4034 case '5': case '6': case '7': case '8': case '9':
4037 if (! stab_demangle_class (minfo
, pp
, (const char **) NULL
)
4038 || ! stab_demangle_remember_type (minfo
, hold
, *pp
- hold
))
4045 /* Function. I don't know if this actually happens with g++
4050 if (! stab_demangle_args (minfo
, pp
, &minfo
->args
, &minfo
->varargs
))
4058 if (! stab_demangle_template (minfo
, pp
, (char **) NULL
)
4059 || ! stab_demangle_remember_type (minfo
, hold
, *pp
- hold
))
4066 /* At the outermost level, we cannot have a return type
4067 specified, so if we run into another '_' at this point we
4068 are dealing with a mangled name that is either bogus, or
4069 has been mangled by some algorithm we don't know how to
4070 deal with. So just reject the entire demangling. */
4071 stab_bad_demangle (orig
);
4075 /* Assume we have stumbled onto the first outermost function
4076 argument token, and start processing args. */
4078 if (! stab_demangle_args (minfo
, pp
, &minfo
->args
, &minfo
->varargs
))
4086 if (! stab_demangle_args (minfo
, pp
, &minfo
->args
, &minfo
->varargs
))
4093 /* With GNU style demangling, bar__3foo is 'foo::bar(void)', and
4094 bar__3fooi is 'foo::bar(int)'. We get here when we find the
4095 first case, and need to ensure that the '(void)' gets added
4096 to the current declp. */
4097 if (! stab_demangle_args (minfo
, pp
, &minfo
->args
, &minfo
->varargs
))
4104 /* Demangle a qualified name, such as "Q25Outer5Inner" which is the
4105 mangled form of "Outer::Inner". */
4108 stab_demangle_qualified (minfo
, pp
, ptype
)
4109 struct stab_demangle_info
*minfo
;
4115 unsigned int qualifiers
;
4123 /* GNU mangled name with more than 9 classes. The count is
4124 preceded by an underscore (to distinguish it from the <= 9
4125 case) and followed by an underscore. */
4127 if (! isdigit ((unsigned char) *p
) || *p
== '0')
4129 stab_bad_demangle (orig
);
4132 qualifiers
= atoi (p
);
4133 while (isdigit ((unsigned char) *p
))
4137 stab_bad_demangle (orig
);
4143 case '1': case '2': case '3': case '4': case '5':
4144 case '6': case '7': case '8': case '9':
4145 qualifiers
= (*pp
)[1] - '0';
4146 /* Skip an optional underscore after the count. */
4147 if ((*pp
)[2] == '_')
4154 stab_bad_demangle (orig
);
4158 context
= DEBUG_TYPE_NULL
;
4160 /* Pick off the names. */
4161 while (qualifiers
-- > 0)
4169 if (! stab_demangle_template (minfo
, pp
,
4170 ptype
!= NULL
? &name
: NULL
))
4175 context
= stab_find_tagged_type (minfo
->dhandle
, minfo
->info
,
4176 name
, strlen (name
),
4179 if (context
== DEBUG_TYPE_NULL
)
4187 len
= stab_demangle_count (pp
);
4188 if (strlen (*pp
) < len
)
4190 stab_bad_demangle (orig
);
4196 const debug_field
*fields
;
4199 if (context
!= DEBUG_TYPE_NULL
)
4200 fields
= debug_get_fields (minfo
->dhandle
, context
);
4202 context
= DEBUG_TYPE_NULL
;
4208 /* Try to find the type by looking through the
4209 fields of context until we find a field with the
4210 same type. This ought to work for a class
4211 defined within a class, but it won't work for,
4212 e.g., an enum defined within a class. stabs does
4213 not give us enough information to figure out the
4216 name
= savestring (*pp
, len
);
4218 for (; *fields
!= DEBUG_FIELD_NULL
; fields
++)
4223 ft
= debug_get_field_type (minfo
->dhandle
, *fields
);
4226 dn
= debug_get_type_name (minfo
->dhandle
, ft
);
4227 if (dn
!= NULL
&& strcmp (dn
, name
) == 0)
4237 if (context
== DEBUG_TYPE_NULL
)
4239 /* We have to fall back on finding the type by name.
4240 If there are more types to come, then this must
4241 be a class. Otherwise, it could be anything. */
4243 if (qualifiers
== 0)
4247 name
= savestring (*pp
, len
);
4248 context
= debug_find_named_type (minfo
->dhandle
,
4253 if (context
== DEBUG_TYPE_NULL
)
4255 context
= stab_find_tagged_type (minfo
->dhandle
,
4259 ? DEBUG_KIND_ILLEGAL
4260 : DEBUG_KIND_CLASS
));
4261 if (context
== DEBUG_TYPE_NULL
)
4277 /* Demangle a template. If PNAME is not NULL, this sets *PNAME to a
4278 string representation of the template. */
4281 stab_demangle_template (minfo
, pp
, pname
)
4282 struct stab_demangle_info
*minfo
;
4293 /* Skip the template name. */
4294 r
= stab_demangle_count (pp
);
4295 if (r
== 0 || strlen (*pp
) < r
)
4297 stab_bad_demangle (orig
);
4302 /* Get the size of the parameter list. */
4303 if (stab_demangle_get_count (pp
, &r
) == 0)
4305 stab_bad_demangle (orig
);
4309 for (i
= 0; i
< r
; i
++)
4313 /* This is a type parameter. */
4315 if (! stab_demangle_type (minfo
, pp
, (debug_type
*) NULL
))
4321 boolean pointerp
, realp
, integralp
, charp
, boolp
;
4332 /* This is a value parameter. */
4334 if (! stab_demangle_type (minfo
, pp
, (debug_type
*) NULL
))
4337 while (*old_p
!= '\0' && ! done
)
4347 case 'C': /* Const. */
4348 case 'S': /* Signed. */
4349 case 'U': /* Unsigned. */
4350 case 'V': /* Volatile. */
4351 case 'F': /* Function. */
4352 case 'M': /* Member function. */
4356 case 'Q': /* Qualified name. */
4360 case 'T': /* Remembered type. */
4362 case 'v': /* Void. */
4364 case 'x': /* Long long. */
4365 case 'l': /* Long. */
4366 case 'i': /* Int. */
4367 case 's': /* Short. */
4368 case 'w': /* Wchar_t. */
4372 case 'b': /* Bool. */
4376 case 'c': /* Char. */
4380 case 'r': /* Long double. */
4381 case 'd': /* Double. */
4382 case 'f': /* Float. */
4387 /* Assume it's a user defined integral type. */
4398 while (isdigit ((unsigned char) **pp
))
4407 val
= stab_demangle_count (pp
);
4410 stab_bad_demangle (orig
);
4418 val
= stab_demangle_count (pp
);
4419 if (val
!= 0 && val
!= 1)
4421 stab_bad_demangle (orig
);
4429 while (isdigit ((unsigned char) **pp
))
4434 while (isdigit ((unsigned char) **pp
))
4440 while (isdigit ((unsigned char) **pp
))
4448 if (! stab_demangle_get_count (pp
, &len
))
4450 stab_bad_demangle (orig
);
4458 /* We can translate this to a string fairly easily by invoking the
4459 regular demangling routine. */
4462 char *s1
, *s2
, *s3
, *s4
;
4464 s1
= savestring (orig
, *pp
- orig
);
4466 s2
= concat ("NoSuchStrinG__", s1
, (const char *) NULL
);
4470 s3
= cplus_demangle (s2
, DMGL_ANSI
);
4475 s4
= strstr (s3
, "::NoSuchStrinG");
4476 if (s3
== NULL
|| s4
== NULL
)
4478 stab_bad_demangle (orig
);
4484 *pname
= savestring (s3
, s4
- s3
);
4492 /* Demangle a class name. */
4495 stab_demangle_class (minfo
, pp
, pstart
)
4496 struct stab_demangle_info
*minfo
;
4498 const char **pstart
;
4505 n
= stab_demangle_count (pp
);
4506 if (strlen (*pp
) < n
)
4508 stab_bad_demangle (orig
);
4520 /* Demangle function arguments. If the pargs argument is not NULL, it
4521 is set to a NULL terminated array holding the arguments. */
4524 stab_demangle_args (minfo
, pp
, pargs
, pvarargs
)
4525 struct stab_demangle_info
*minfo
;
4531 unsigned int alloc
, count
;
4538 *pargs
= (debug_type
*) xmalloc (alloc
* sizeof **pargs
);
4543 while (**pp
!= '_' && **pp
!= '\0' && **pp
!= 'e')
4545 if (**pp
== 'N' || **pp
== 'T')
4553 if (temptype
== 'T')
4557 if (! stab_demangle_get_count (pp
, &r
))
4559 stab_bad_demangle (orig
);
4564 if (! stab_demangle_get_count (pp
, &t
))
4566 stab_bad_demangle (orig
);
4570 if (t
>= minfo
->typestring_count
)
4572 stab_bad_demangle (orig
);
4579 tem
= minfo
->typestrings
[t
].typestring
;
4580 if (! stab_demangle_arg (minfo
, &tem
, pargs
, &count
, &alloc
))
4586 if (! stab_demangle_arg (minfo
, pp
, pargs
, &count
, &alloc
))
4592 (*pargs
)[count
] = DEBUG_TYPE_NULL
;
4604 /* Demangle a single argument. */
4607 stab_demangle_arg (minfo
, pp
, pargs
, pcount
, palloc
)
4608 struct stab_demangle_info
*minfo
;
4611 unsigned int *pcount
;
4612 unsigned int *palloc
;
4618 if (! stab_demangle_type (minfo
, pp
,
4619 pargs
== NULL
? (debug_type
*) NULL
: &type
)
4620 || ! stab_demangle_remember_type (minfo
, start
, *pp
- start
))
4625 if (type
== DEBUG_TYPE_NULL
)
4628 if (*pcount
+ 1 >= *palloc
)
4631 *pargs
= ((debug_type
*)
4632 xrealloc (*pargs
, *palloc
* sizeof **pargs
));
4634 (*pargs
)[*pcount
] = type
;
4641 /* Demangle a type. If the ptype argument is not NULL, *ptype is set
4642 to the newly allocated type. */
4645 stab_demangle_type (minfo
, pp
, ptype
)
4646 struct stab_demangle_info
*minfo
;
4658 /* A pointer type. */
4660 if (! stab_demangle_type (minfo
, pp
, ptype
))
4663 *ptype
= debug_make_pointer_type (minfo
->dhandle
, *ptype
);
4667 /* A reference type. */
4669 if (! stab_demangle_type (minfo
, pp
, ptype
))
4672 *ptype
= debug_make_reference_type (minfo
->dhandle
, *ptype
);
4682 while (**pp
!= '\0' && **pp
!= '_')
4684 if (! isdigit ((unsigned char) **pp
))
4686 stab_bad_demangle (orig
);
4695 stab_bad_demangle (orig
);
4700 if (! stab_demangle_type (minfo
, pp
, ptype
))
4704 debug_type int_type
;
4706 int_type
= debug_find_named_type (minfo
->dhandle
, "int");
4707 if (int_type
== NULL
)
4708 int_type
= debug_make_int_type (minfo
->dhandle
, 4, false);
4709 *ptype
= debug_make_array_type (minfo
->dhandle
, *ptype
, int_type
,
4716 /* A back reference to a remembered type. */
4722 if (! stab_demangle_get_count (pp
, &i
))
4724 stab_bad_demangle (orig
);
4727 if (i
>= minfo
->typestring_count
)
4729 stab_bad_demangle (orig
);
4732 p
= minfo
->typestrings
[i
].typestring
;
4733 if (! stab_demangle_type (minfo
, &p
, ptype
))
4745 if (! stab_demangle_args (minfo
, pp
,
4747 ? (debug_type
**) NULL
4755 /* cplus_demangle will accept a function without a return
4756 type, but I don't know when that will happen, or what
4757 to do if it does. */
4758 stab_bad_demangle (orig
);
4762 if (! stab_demangle_type (minfo
, pp
, ptype
))
4765 *ptype
= debug_make_function_type (minfo
->dhandle
, *ptype
, args
,
4774 boolean memberp
, constp
, volatilep
;
4780 memberp
= **pp
== 'M';
4787 if (! isdigit ((unsigned char) **pp
))
4789 stab_bad_demangle (orig
);
4792 n
= stab_demangle_count (pp
);
4793 if (strlen (*pp
) < n
)
4795 stab_bad_demangle (orig
);
4808 else if (**pp
== 'V')
4815 stab_bad_demangle (orig
);
4819 if (! stab_demangle_args (minfo
, pp
,
4821 ? (debug_type
**) NULL
4831 stab_bad_demangle (orig
);
4836 if (! stab_demangle_type (minfo
, pp
, ptype
))
4841 debug_type class_type
;
4843 class_type
= stab_find_tagged_type (minfo
->dhandle
, minfo
->info
,
4846 if (class_type
== DEBUG_TYPE_NULL
)
4850 *ptype
= debug_make_offset_type (minfo
->dhandle
, class_type
,
4854 /* FIXME: We have no way to record constp or
4856 *ptype
= debug_make_method_type (minfo
->dhandle
, *ptype
,
4857 class_type
, args
, varargs
);
4865 if (! stab_demangle_type (minfo
, pp
, ptype
))
4871 if (! stab_demangle_type (minfo
, pp
, ptype
))
4874 *ptype
= debug_make_const_type (minfo
->dhandle
, *ptype
);
4882 if (! stab_demangle_qualified (minfo
, pp
, ptype
))
4888 if (! stab_demangle_fund_type (minfo
, pp
, ptype
))
4896 /* Demangle a fundamental type. If the ptype argument is not NULL,
4897 *ptype is set to the newly allocated type. */
4900 stab_demangle_fund_type (minfo
, pp
, ptype
)
4901 struct stab_demangle_info
*minfo
;
4906 boolean constp
, volatilep
, unsignedp
, signedp
;
4951 /* cplus_demangle permits this, but I don't know what it means. */
4952 stab_bad_demangle (orig
);
4955 case 'v': /* void */
4958 *ptype
= debug_find_named_type (minfo
->dhandle
, "void");
4959 if (*ptype
== DEBUG_TYPE_NULL
)
4960 *ptype
= debug_make_void_type (minfo
->dhandle
);
4965 case 'x': /* long long */
4968 *ptype
= debug_find_named_type (minfo
->dhandle
,
4970 ? "long long unsigned int"
4971 : "long long int"));
4972 if (*ptype
== DEBUG_TYPE_NULL
)
4973 *ptype
= debug_make_int_type (minfo
->dhandle
, 8, unsignedp
);
4978 case 'l': /* long */
4981 *ptype
= debug_find_named_type (minfo
->dhandle
,
4983 ? "long unsigned int"
4985 if (*ptype
== DEBUG_TYPE_NULL
)
4986 *ptype
= debug_make_int_type (minfo
->dhandle
, 4, unsignedp
);
4994 *ptype
= debug_find_named_type (minfo
->dhandle
,
4998 if (*ptype
== DEBUG_TYPE_NULL
)
4999 *ptype
= debug_make_int_type (minfo
->dhandle
, 4, unsignedp
);
5004 case 's': /* short */
5007 *ptype
= debug_find_named_type (minfo
->dhandle
,
5009 ? "short unsigned int"
5011 if (*ptype
== DEBUG_TYPE_NULL
)
5012 *ptype
= debug_make_int_type (minfo
->dhandle
, 2, unsignedp
);
5017 case 'b': /* bool */
5020 *ptype
= debug_find_named_type (minfo
->dhandle
, "bool");
5021 if (*ptype
== DEBUG_TYPE_NULL
)
5022 *ptype
= debug_make_bool_type (minfo
->dhandle
, 4);
5027 case 'c': /* char */
5030 *ptype
= debug_find_named_type (minfo
->dhandle
,
5036 if (*ptype
== DEBUG_TYPE_NULL
)
5037 *ptype
= debug_make_int_type (minfo
->dhandle
, 1, unsignedp
);
5042 case 'w': /* wchar_t */
5045 *ptype
= debug_find_named_type (minfo
->dhandle
, "__wchar_t");
5046 if (*ptype
== DEBUG_TYPE_NULL
)
5047 *ptype
= debug_make_int_type (minfo
->dhandle
, 2, true);
5052 case 'r': /* long double */
5055 *ptype
= debug_find_named_type (minfo
->dhandle
, "long double");
5056 if (*ptype
== DEBUG_TYPE_NULL
)
5057 *ptype
= debug_make_float_type (minfo
->dhandle
, 8);
5062 case 'd': /* double */
5065 *ptype
= debug_find_named_type (minfo
->dhandle
, "double");
5066 if (*ptype
== DEBUG_TYPE_NULL
)
5067 *ptype
= debug_make_float_type (minfo
->dhandle
, 8);
5072 case 'f': /* float */
5075 *ptype
= debug_find_named_type (minfo
->dhandle
, "float");
5076 if (*ptype
== DEBUG_TYPE_NULL
)
5077 *ptype
= debug_make_float_type (minfo
->dhandle
, 4);
5084 if (! isdigit ((unsigned char) **pp
))
5086 stab_bad_demangle (orig
);
5090 case '0': case '1': case '2': case '3': case '4':
5091 case '5': case '6': case '7': case '8': case '9':
5095 if (! stab_demangle_class (minfo
, pp
, &hold
))
5101 name
= savestring (hold
, *pp
- hold
);
5102 *ptype
= debug_find_named_type (minfo
->dhandle
, name
);
5104 if (*ptype
== DEBUG_TYPE_NULL
)
5106 /* FIXME: It is probably incorrect to assume that
5107 undefined types are tagged types. */
5108 *ptype
= stab_find_tagged_type (minfo
->dhandle
, minfo
->info
,
5110 DEBUG_KIND_ILLEGAL
);
5111 if (*ptype
== DEBUG_TYPE_NULL
)
5122 if (! stab_demangle_template (minfo
, pp
,
5123 ptype
!= NULL
? &name
: NULL
))
5127 *ptype
= stab_find_tagged_type (minfo
->dhandle
, minfo
->info
,
5128 name
, strlen (name
),
5131 if (*ptype
== DEBUG_TYPE_NULL
)
5138 stab_bad_demangle (orig
);
5145 *ptype
= debug_make_const_type (minfo
->dhandle
, *ptype
);
5147 *ptype
= debug_make_volatile_type (minfo
->dhandle
, *ptype
);
5153 /* Remember a type string in a demangled string. */
5156 stab_demangle_remember_type (minfo
, p
, len
)
5157 struct stab_demangle_info
*minfo
;
5161 if (minfo
->typestring_count
>= minfo
->typestring_alloc
)
5163 minfo
->typestring_alloc
+= 10;
5164 minfo
->typestrings
= ((struct stab_demangle_typestring
*)
5165 xrealloc (minfo
->typestrings
,
5166 (minfo
->typestring_alloc
5167 * sizeof *minfo
->typestrings
)));
5170 minfo
->typestrings
[minfo
->typestring_count
].typestring
= p
;
5171 minfo
->typestrings
[minfo
->typestring_count
].len
= (unsigned int) len
;
5172 ++minfo
->typestring_count
;