1 /* stabs.c -- Parse stabs debugging information
2 Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001
3 Free Software Foundation, Inc.
4 Written by Ian Lance Taylor <ian@cygnus.com>.
6 This file is part of GNU Binutils.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23 /* This file contains code which parses stabs debugging information.
24 The organization of this code is based on the gdb stabs reading
25 code. The job it does is somewhat different, because it is not
26 trying to identify the correct address for anything. */
32 #include "libiberty.h"
33 #include "safe-ctype.h"
37 #include "filenames.h"
39 /* Meaningless definition needs by aout64.h. FIXME. */
40 #define BYTES_IN_WORD 4
42 #include "aout/aout64.h"
43 #include "aout/stab_gnu.h"
45 /* The number of predefined XCOFF types. */
47 #define XCOFF_TYPE_COUNT 34
49 /* This structure is used as a handle so that the stab parsing doesn't
50 need to use any static variables. */
56 /* True if this is stabs in sections. */
58 /* The symbol table. */
60 /* The number of symbols. */
62 /* The accumulated file name string. */
64 /* The value of the last N_SO symbol. */
66 /* The value of the start of the file, so that we can handle file
67 relative N_LBRAC and N_RBRAC symbols. */
68 bfd_vma file_start_offset
;
69 /* The offset of the start of the function, so that we can handle
70 function relative N_LBRAC and N_RBRAC symbols. */
71 bfd_vma function_start_offset
;
72 /* The version number of gcc which compiled the current compilation
73 unit, 0 if not compiled by gcc. */
75 /* Whether an N_OPT symbol was seen that was not generated by gcc,
76 so that we can detect the SunPRO compiler. */
78 /* The main file name. */
80 /* A stack of unfinished N_BINCL files. */
81 struct bincl_file
*bincl_stack
;
82 /* A list of finished N_BINCL files. */
83 struct bincl_file
*bincl_list
;
84 /* Whether we are inside a function or not. */
85 boolean within_function
;
86 /* The address of the end of the function, used if we have seen an
87 N_FUN symbol while in a function. This is -1 if we have not seen
88 an N_FUN (the normal case). */
90 /* The depth of block nesting. */
92 /* List of pending variable definitions. */
93 struct stab_pending_var
*pending
;
94 /* Number of files for which we have types. */
96 /* Lists of types per file. */
97 struct stab_types
**file_types
;
98 /* Predefined XCOFF types. */
99 debug_type xcoff_types
[XCOFF_TYPE_COUNT
];
100 /* Undefined tags. */
101 struct stab_tag
*tags
;
102 /* Set by parse_stab_type if it sees a structure defined as a cross
103 reference to itself. Reset by parse_stab_type otherwise. */
104 boolean self_crossref
;
107 /* A list of these structures is used to hold pending variable
108 definitions seen before the N_LBRAC of a block. */
110 struct stab_pending_var
112 /* Next pending variable definition. */
113 struct stab_pending_var
*next
;
119 enum debug_var_kind kind
;
124 /* A list of these structures is used to hold the types for a single
129 /* Next set of slots for this file. */
130 struct stab_types
*next
;
131 /* Types indexed by type number. */
132 #define STAB_TYPES_SLOTS (16)
133 debug_type types
[STAB_TYPES_SLOTS
];
136 /* We keep a list of undefined tags that we encounter, so that we can
137 fill them in if the tag is later defined. */
141 /* Next undefined tag. */
142 struct stab_tag
*next
;
146 enum debug_type_kind kind
;
147 /* Slot to hold real type when we discover it. If we don't, we fill
148 in an undefined tag type. */
150 /* Indirect type we have created to point at slot. */
154 static char *savestring
PARAMS ((const char *, int));
155 static bfd_vma parse_number
PARAMS ((const char **, boolean
*));
156 static void bad_stab
PARAMS ((const char *));
157 static void warn_stab
PARAMS ((const char *, const char *));
158 static boolean parse_stab_string
159 PARAMS ((PTR
, struct stab_handle
*, int, int, bfd_vma
, const char *));
160 static debug_type parse_stab_type
161 PARAMS ((PTR
, struct stab_handle
*, const char *, const char **,
163 static boolean parse_stab_type_number
164 PARAMS ((const char **, int *));
165 static debug_type parse_stab_range_type
166 PARAMS ((PTR
, struct stab_handle
*, const char *, const char **,
168 static debug_type parse_stab_sun_builtin_type
PARAMS ((PTR
, const char **));
169 static debug_type parse_stab_sun_floating_type
170 PARAMS ((PTR
, const char **));
171 static debug_type parse_stab_enum_type
PARAMS ((PTR
, const char **));
172 static debug_type parse_stab_struct_type
173 PARAMS ((PTR
, struct stab_handle
*, const char *, const char **, boolean
,
175 static boolean parse_stab_baseclasses
176 PARAMS ((PTR
, struct stab_handle
*, const char **, debug_baseclass
**));
177 static boolean parse_stab_struct_fields
178 PARAMS ((PTR
, struct stab_handle
*, const char **, debug_field
**,
180 static boolean parse_stab_cpp_abbrev
181 PARAMS ((PTR
, struct stab_handle
*, const char **, debug_field
*));
182 static boolean parse_stab_one_struct_field
183 PARAMS ((PTR
, struct stab_handle
*, const char **, const char *,
184 debug_field
*, boolean
*));
185 static boolean parse_stab_members
186 PARAMS ((PTR
, struct stab_handle
*, const char *, const char **,
187 const int *, debug_method
**));
188 static debug_type parse_stab_argtypes
189 PARAMS ((PTR
, struct stab_handle
*, debug_type
, const char *, const char *,
190 debug_type
, const char *, boolean
, boolean
, const char **));
191 static boolean parse_stab_tilde_field
192 PARAMS ((PTR
, struct stab_handle
*, const char **, const int *,
193 debug_type
*, boolean
*));
194 static debug_type parse_stab_array_type
195 PARAMS ((PTR
, struct stab_handle
*, const char **, boolean
));
196 static void push_bincl
PARAMS ((struct stab_handle
*, const char *, bfd_vma
));
197 static const char *pop_bincl
PARAMS ((struct stab_handle
*));
198 static boolean find_excl
199 PARAMS ((struct stab_handle
*, const char *, bfd_vma
));
200 static boolean stab_record_variable
201 PARAMS ((PTR
, struct stab_handle
*, const char *, debug_type
,
202 enum debug_var_kind
, bfd_vma
));
203 static boolean stab_emit_pending_vars
PARAMS ((PTR
, struct stab_handle
*));
204 static debug_type
*stab_find_slot
205 PARAMS ((struct stab_handle
*, const int *));
206 static debug_type stab_find_type
207 PARAMS ((PTR
, struct stab_handle
*, const int *));
208 static boolean stab_record_type
209 PARAMS ((PTR
, struct stab_handle
*, const int *, debug_type
));
210 static debug_type stab_xcoff_builtin_type
211 PARAMS ((PTR
, struct stab_handle
*, int));
212 static debug_type stab_find_tagged_type
213 PARAMS ((PTR
, struct stab_handle
*, const char *, int,
214 enum debug_type_kind
));
215 static debug_type
*stab_demangle_argtypes
216 PARAMS ((PTR
, struct stab_handle
*, const char *, boolean
*));
218 /* Save a string in memory. */
221 savestring (start
, len
)
227 ret
= (char *) xmalloc (len
+ 1);
228 memcpy (ret
, start
, len
);
233 /* Read a number from a string. */
236 parse_number (pp
, poverflow
)
243 if (poverflow
!= NULL
)
249 ul
= strtoul (*pp
, (char **) pp
, 0);
250 if (ul
+ 1 != 0 || errno
== 0)
252 /* If bfd_vma is larger than unsigned long, and the number is
253 meant to be negative, we have to make sure that we sign
256 return (bfd_vma
) (bfd_signed_vma
) (long) ul
;
260 /* Note that even though strtoul overflowed, it should have set *pp
261 to the end of the number, which is where we want it. */
263 if (sizeof (bfd_vma
) > sizeof (unsigned long))
268 bfd_vma over
, lastdig
;
272 /* Our own version of strtoul, for a bfd_vma. */
288 if (p
[1] == 'x' || p
[1] == 'X')
300 over
= ((bfd_vma
) (bfd_signed_vma
) -1) / (bfd_vma
) base
;
301 lastdig
= ((bfd_vma
) (bfd_signed_vma
) -1) % (bfd_vma
) base
;
312 else if (ISUPPER (d
))
314 else if (ISLOWER (d
))
322 if (v
> over
|| (v
== over
&& (bfd_vma
) d
> lastdig
))
337 /* If we get here, the number is too large to represent in a
340 if (poverflow
!= NULL
)
343 warn_stab (orig
, _("numeric overflow"));
348 /* Give an error for a bad stab string. */
354 fprintf (stderr
, _("Bad stab: %s\n"), p
);
357 /* Warn about something in a stab string. */
364 fprintf (stderr
, _("Warning: %s: %s\n"), err
, p
);
367 /* Create a handle to parse stabs symbols with. */
370 start_stab (dhandle
, abfd
, sections
, syms
, symcount
)
371 PTR dhandle ATTRIBUTE_UNUSED
;
377 struct stab_handle
*ret
;
379 ret
= (struct stab_handle
*) xmalloc (sizeof *ret
);
380 memset (ret
, 0, sizeof *ret
);
382 ret
->sections
= sections
;
384 ret
->symcount
= symcount
;
386 ret
->file_types
= (struct stab_types
**) xmalloc (sizeof *ret
->file_types
);
387 ret
->file_types
[0] = NULL
;
388 ret
->function_end
= (bfd_vma
) -1;
392 /* When we have processed all the stabs information, we need to go
393 through and fill in all the undefined tags. */
396 finish_stab (dhandle
, handle
)
400 struct stab_handle
*info
= (struct stab_handle
*) handle
;
403 if (info
->within_function
)
405 if (! stab_emit_pending_vars (dhandle
, info
)
406 || ! debug_end_function (dhandle
, info
->function_end
))
408 info
->within_function
= false;
409 info
->function_end
= (bfd_vma
) -1;
412 for (st
= info
->tags
; st
!= NULL
; st
= st
->next
)
414 enum debug_type_kind kind
;
417 if (kind
== DEBUG_KIND_ILLEGAL
)
418 kind
= DEBUG_KIND_STRUCT
;
419 st
->slot
= debug_make_undefined_tagged_type (dhandle
, st
->name
, kind
);
420 if (st
->slot
== DEBUG_TYPE_NULL
)
427 /* Handle a single stabs symbol. */
430 parse_stab (dhandle
, handle
, type
, desc
, value
, string
)
438 struct stab_handle
*info
= (struct stab_handle
*) handle
;
440 /* gcc will emit two N_SO strings per compilation unit, one for the
441 directory name and one for the file name. We just collect N_SO
442 strings as we see them, and start the new compilation unit when
443 we see a non N_SO symbol. */
444 if (info
->so_string
!= NULL
445 && (type
!= N_SO
|| *string
== '\0' || value
!= info
->so_value
))
447 if (! debug_set_filename (dhandle
, info
->so_string
))
449 info
->main_filename
= info
->so_string
;
451 info
->gcc_compiled
= 0;
452 info
->n_opt_found
= false;
454 /* Generally, for stabs in the symbol table, the N_LBRAC and
455 N_RBRAC symbols are relative to the N_SO symbol value. */
456 if (! info
->sections
)
457 info
->file_start_offset
= info
->so_value
;
459 /* We need to reset the mapping from type numbers to types. We
460 can't free the old mapping, because of the use of
461 debug_make_indirect_type. */
463 info
->file_types
= ((struct stab_types
**)
464 xmalloc (sizeof *info
->file_types
));
465 info
->file_types
[0] = NULL
;
467 info
->so_string
= NULL
;
469 /* Now process whatever type we just got. */
479 /* Ignore extra outermost context from SunPRO cc and acc. */
480 if (info
->n_opt_found
&& desc
== 1)
483 if (! info
->within_function
)
485 fprintf (stderr
, _("N_LBRAC not within function\n"));
489 /* Start an inner lexical block. */
490 if (! debug_start_block (dhandle
,
492 + info
->file_start_offset
493 + info
->function_start_offset
)))
496 /* Emit any pending variable definitions. */
497 if (! stab_emit_pending_vars (dhandle
, info
))
504 /* Ignore extra outermost context from SunPRO cc and acc. */
505 if (info
->n_opt_found
&& desc
== 1)
508 /* We shouldn't have any pending variable definitions here, but,
509 if we do, we probably need to emit them before closing the
511 if (! stab_emit_pending_vars (dhandle
, info
))
514 /* End an inner lexical block. */
515 if (! debug_end_block (dhandle
,
517 + info
->file_start_offset
518 + info
->function_start_offset
)))
522 if (info
->block_depth
< 0)
524 fprintf (stderr
, _("Too many N_RBRACs\n"));
530 /* This always ends a function. */
531 if (info
->within_function
)
537 && info
->function_end
!= (bfd_vma
) -1
538 && info
->function_end
< endval
)
539 endval
= info
->function_end
;
540 if (! stab_emit_pending_vars (dhandle
, info
)
541 || ! debug_end_function (dhandle
, endval
))
543 info
->within_function
= false;
544 info
->function_end
= (bfd_vma
) -1;
547 /* An empty string is emitted by gcc at the end of a compilation
552 /* Just accumulate strings until we see a non N_SO symbol. If
553 the string starts with a directory separator or some other
554 form of absolute path specification, we discard the previously
555 accumulated strings. */
556 if (info
->so_string
== NULL
)
557 info
->so_string
= xstrdup (string
);
564 if (IS_ABSOLUTE_PATH (string
))
565 info
->so_string
= xstrdup (string
);
567 info
->so_string
= concat (info
->so_string
, string
,
568 (const char *) NULL
);
572 info
->so_value
= value
;
577 /* Start an include file. */
578 if (! debug_start_source (dhandle
, string
))
583 /* Start an include file which may be replaced. */
584 push_bincl (info
, string
, value
);
585 if (! debug_start_source (dhandle
, string
))
590 /* End an N_BINCL include. */
591 if (! debug_start_source (dhandle
, pop_bincl (info
)))
596 /* This is a duplicate of a header file named by N_BINCL which
597 was eliminated by the linker. */
598 if (! find_excl (info
, string
, value
))
603 if (! debug_record_line (dhandle
, desc
,
604 value
+ info
->function_start_offset
))
609 if (! debug_start_common_block (dhandle
, string
))
614 if (! debug_end_common_block (dhandle
, string
))
621 if (info
->within_function
)
623 /* This always marks the end of a function; we don't
624 need to worry about info->function_end. */
626 value
+= info
->function_start_offset
;
627 if (! stab_emit_pending_vars (dhandle
, info
)
628 || ! debug_end_function (dhandle
, value
))
630 info
->within_function
= false;
631 info
->function_end
= (bfd_vma
) -1;
636 /* A const static symbol in the .text section will have an N_FUN
637 entry. We need to use these to mark the end of the function,
638 in case we are looking at gcc output before it was changed to
639 always emit an empty N_FUN. We can't call debug_end_function
640 here, because it might be a local static symbol. */
641 if (info
->within_function
642 && (info
->function_end
== (bfd_vma
) -1
643 || value
< info
->function_end
))
644 info
->function_end
= value
;
647 /* FIXME: gdb checks the string for N_STSYM, N_LCSYM or N_ROSYM
648 symbols, and if it does not start with :S, gdb relocates the
649 value to the start of the section. gcc always seems to use
650 :S, so we don't worry about this. */
656 colon
= strchr (string
, ':');
658 && (colon
[1] == 'f' || colon
[1] == 'F'))
660 if (info
->within_function
)
665 if (info
->function_end
!= (bfd_vma
) -1
666 && info
->function_end
< endval
)
667 endval
= info
->function_end
;
668 if (! stab_emit_pending_vars (dhandle
, info
)
669 || ! debug_end_function (dhandle
, endval
))
671 info
->function_end
= (bfd_vma
) -1;
673 /* For stabs in sections, line numbers and block addresses
674 are offsets from the start of the function. */
676 info
->function_start_offset
= value
;
677 info
->within_function
= true;
680 if (! parse_stab_string (dhandle
, info
, type
, desc
, value
, string
))
686 if (string
!= NULL
&& strcmp (string
, "gcc2_compiled.") == 0)
687 info
->gcc_compiled
= 2;
688 else if (string
!= NULL
&& strcmp (string
, "gcc_compiled.") == 0)
689 info
->gcc_compiled
= 1;
691 info
->n_opt_found
= true;
704 /* Parse the stabs string. */
707 parse_stab_string (dhandle
, info
, stabtype
, desc
, value
, string
)
709 struct stab_handle
*info
;
720 boolean self_crossref
;
724 p
= strchr (string
, ':');
739 /* GCC 2.x puts the line number in desc. SunOS apparently puts in
740 the number of bytes occupied by a type or object, which we
742 if (info
->gcc_compiled
>= 2)
747 /* FIXME: Sometimes the special C++ names start with '.'. */
749 if (string
[0] == '$')
757 /* Was: name = "vptr"; */
763 /* This was an anonymous type that was never fixed up. */
766 /* SunPRO (3.0 at least) static variable encoding. */
769 warn_stab (string
, _("unknown C++ encoded name"));
776 if (p
== string
|| (string
[0] == ' ' && p
== string
+ 1))
779 name
= savestring (string
, p
- string
);
783 if (ISDIGIT (*p
) || *p
== '(' || *p
== '-')
791 /* c is a special case, not followed by a type-number.
792 SYMBOL:c=iVALUE for an integer constant symbol.
793 SYMBOL:c=rVALUE for a floating constant symbol.
794 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
795 e.g. "b:c=e6,0" for "const b = blob1"
796 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
806 /* Floating point constant. */
807 if (! debug_record_float_const (dhandle
, name
, atof (p
)))
811 /* Integer constant. */
812 /* Defining integer constants this way is kind of silly,
813 since 'e' constants allows the compiler to give not only
814 the value, but the type as well. C has at least int,
815 long, unsigned int, and long long as constant types;
816 other languages probably should have at least unsigned as
817 well as signed constants. */
818 if (! debug_record_int_const (dhandle
, name
, atoi (p
)))
822 /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value
823 can be represented as integral.
824 e.g. "b:c=e6,0" for "const b = blob1"
825 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
826 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
,
827 &p
, (debug_type
**) NULL
);
828 if (dtype
== DEBUG_TYPE_NULL
)
835 if (! debug_record_typed_const (dhandle
, name
, dtype
, atoi (p
)))
846 /* The name of a caught exception. */
847 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
,
848 &p
, (debug_type
**) NULL
);
849 if (dtype
== DEBUG_TYPE_NULL
)
851 if (! debug_record_label (dhandle
, name
, dtype
, value
))
857 /* A function definition. */
858 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
859 (debug_type
**) NULL
);
860 if (dtype
== DEBUG_TYPE_NULL
)
862 if (! debug_record_function (dhandle
, name
, dtype
, type
== 'F', value
))
865 /* Sun acc puts declared types of arguments here. We don't care
866 about their actual types (FIXME -- we should remember the whole
867 function prototype), but the list may define some new types
868 that we have to remember, so we must scan it now. */
872 if (parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
873 (debug_type
**) NULL
)
886 /* A global symbol. The value must be extracted from the
888 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
889 (debug_type
**) NULL
);
890 if (dtype
== DEBUG_TYPE_NULL
)
892 leading
= bfd_get_symbol_leading_char (info
->abfd
);
893 for (c
= info
->symcount
, ps
= info
->syms
; c
> 0; --c
, ++ps
)
897 n
= bfd_asymbol_name (*ps
);
898 if (leading
!= '\0' && *n
== leading
)
900 if (*n
== *name
&& strcmp (n
, name
) == 0)
904 value
= bfd_asymbol_value (*ps
);
905 if (! stab_record_variable (dhandle
, info
, name
, dtype
, DEBUG_GLOBAL
,
911 /* This case is faked by a conditional above, when there is no
912 code letter in the dbx data. Dbx data never actually
916 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
917 (debug_type
**) NULL
);
918 if (dtype
== DEBUG_TYPE_NULL
)
920 if (! stab_record_variable (dhandle
, info
, name
, dtype
, DEBUG_LOCAL
,
926 /* A function parameter. */
928 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
929 (debug_type
**) NULL
);
932 /* pF is a two-letter code that means a function parameter in
933 Fortran. The type-number specifies the type of the return
934 value. Translate it into a pointer-to-function type. */
936 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
937 (debug_type
**) NULL
);
938 if (dtype
!= DEBUG_TYPE_NULL
)
942 ftype
= debug_make_function_type (dhandle
, dtype
,
943 (debug_type
*) NULL
, false);
944 dtype
= debug_make_pointer_type (dhandle
, ftype
);
947 if (dtype
== DEBUG_TYPE_NULL
)
949 if (! debug_record_parameter (dhandle
, name
, dtype
, DEBUG_PARM_STACK
,
953 /* FIXME: At this point gdb considers rearranging the parameter
954 address on a big endian machine if it is smaller than an int.
955 We have no way to do that, since we don't really know much
961 if (stabtype
== N_FUN
)
963 /* Prototype of a function referenced by this file. */
967 if (parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
968 (debug_type
**) NULL
)
976 /* Parameter which is in a register. */
977 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
978 (debug_type
**) NULL
);
979 if (dtype
== DEBUG_TYPE_NULL
)
981 if (! debug_record_parameter (dhandle
, name
, dtype
, DEBUG_PARM_REG
,
987 /* Register variable (either global or local). */
988 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
989 (debug_type
**) NULL
);
990 if (dtype
== DEBUG_TYPE_NULL
)
992 if (! stab_record_variable (dhandle
, info
, name
, dtype
, DEBUG_REGISTER
,
996 /* FIXME: At this point gdb checks to combine pairs of 'p' and
997 'r' stabs into a single 'P' stab. */
1002 /* Static symbol at top level of file */
1003 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
1004 (debug_type
**) NULL
);
1005 if (dtype
== DEBUG_TYPE_NULL
)
1007 if (! stab_record_variable (dhandle
, info
, name
, dtype
, DEBUG_STATIC
,
1014 dtype
= parse_stab_type (dhandle
, info
, name
, &p
, &slot
);
1015 if (dtype
== DEBUG_TYPE_NULL
)
1019 /* A nameless type. Nothing to do. */
1023 dtype
= debug_name_type (dhandle
, name
, dtype
);
1024 if (dtype
== DEBUG_TYPE_NULL
)
1033 /* Struct, union, or enum tag. For GNU C++, this can be be followed
1034 by 't' which means we are typedef'ing it as well. */
1038 /* FIXME: gdb sets synonym to true if the current language
1047 dtype
= parse_stab_type (dhandle
, info
, name
, &p
, &slot
);
1048 if (dtype
== DEBUG_TYPE_NULL
)
1053 /* INFO->SELF_CROSSREF is set by parse_stab_type if this type is
1054 a cross reference to itself. These are generated by some
1056 self_crossref
= info
->self_crossref
;
1058 dtype
= debug_tag_type (dhandle
, name
, dtype
);
1059 if (dtype
== DEBUG_TYPE_NULL
)
1064 /* See if we have a cross reference to this tag which we can now
1065 fill in. Avoid filling in a cross reference to ourselves,
1066 because that would lead to circular debugging information. */
1067 if (! self_crossref
)
1069 register struct stab_tag
**pst
;
1071 for (pst
= &info
->tags
; *pst
!= NULL
; pst
= &(*pst
)->next
)
1073 if ((*pst
)->name
[0] == name
[0]
1074 && strcmp ((*pst
)->name
, name
) == 0)
1076 (*pst
)->slot
= dtype
;
1077 *pst
= (*pst
)->next
;
1085 dtype
= debug_name_type (dhandle
, name
, dtype
);
1086 if (dtype
== DEBUG_TYPE_NULL
)
1096 /* Static symbol of local scope */
1097 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
1098 (debug_type
**) NULL
);
1099 if (dtype
== DEBUG_TYPE_NULL
)
1101 /* FIXME: gdb checks os9k_stabs here. */
1102 if (! stab_record_variable (dhandle
, info
, name
, dtype
,
1103 DEBUG_LOCAL_STATIC
, value
))
1108 /* Reference parameter. */
1109 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
1110 (debug_type
**) NULL
);
1111 if (dtype
== DEBUG_TYPE_NULL
)
1113 if (! debug_record_parameter (dhandle
, name
, dtype
, DEBUG_PARM_REFERENCE
,
1119 /* Reference parameter which is in a register. */
1120 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
1121 (debug_type
**) NULL
);
1122 if (dtype
== DEBUG_TYPE_NULL
)
1124 if (! debug_record_parameter (dhandle
, name
, dtype
, DEBUG_PARM_REF_REG
,
1130 /* This is used by Sun FORTRAN for "function result value".
1131 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
1132 that Pascal uses it too, but when I tried it Pascal used
1133 "x:3" (local symbol) instead. */
1134 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
1135 (debug_type
**) NULL
);
1136 if (dtype
== DEBUG_TYPE_NULL
)
1138 if (! stab_record_variable (dhandle
, info
, name
, dtype
, DEBUG_LOCAL
,
1148 /* FIXME: gdb converts structure values to structure pointers in a
1149 couple of cases, depending upon the target. */
1154 /* Parse a stabs type. The typename argument is non-NULL if this is a
1155 typedef or a tag definition. The pp argument points to the stab
1156 string, and is updated. The slotp argument points to a place to
1157 store the slot used if the type is being defined. */
1160 parse_stab_type (dhandle
, info
, typename
, pp
, slotp
)
1162 struct stab_handle
*info
;
1163 const char *typename
;
1182 info
->self_crossref
= false;
1184 /* Read type number if present. The type number may be omitted.
1185 for instance in a two-dimensional array declared with type
1186 "ar1;1;10;ar1;1;10;4". */
1187 if (! ISDIGIT (**pp
) && **pp
!= '(' && **pp
!= '-')
1189 /* 'typenums=' not present, type is anonymous. Read and return
1190 the definition, but don't put it in the type vector. */
1191 typenums
[0] = typenums
[1] = -1;
1195 if (! parse_stab_type_number (pp
, typenums
))
1196 return DEBUG_TYPE_NULL
;
1200 /* Type is not being defined here. Either it already
1201 exists, or this is a forward reference to it. */
1202 return stab_find_type (dhandle
, info
, typenums
);
1205 /* Only set the slot if the type is being defined. This means
1206 that the mapping from type numbers to types will only record
1207 the name of the typedef which defines a type. If we don't do
1208 this, then something like
1211 will record that i is of type foo. Unfortunately, stabs
1212 information is ambiguous about variable types. For this code,
1216 the stabs information records both i and j as having the same
1217 type. This could be fixed by patching the compiler. */
1218 if (slotp
!= NULL
&& typenums
[0] >= 0 && typenums
[1] >= 0)
1219 *slotp
= stab_find_slot (info
, typenums
);
1221 /* Type is being defined here. */
1227 const char *p
= *pp
+ 1;
1230 if (ISDIGIT (*p
) || *p
== '(' || *p
== '-')
1236 /* Type attributes. */
1239 for (; *p
!= ';'; ++p
)
1244 return DEBUG_TYPE_NULL
;
1252 size
= atoi (attr
+ 1);
1253 size
/= 8; /* Size is in bits. We store it in bytes. */
1263 /* Ignore unrecognized type attributes, so future
1264 compilers can invent new ones. */
1277 enum debug_type_kind code
;
1278 const char *q1
, *q2
, *p
;
1280 /* A cross reference to another type. */
1285 code
= DEBUG_KIND_STRUCT
;
1288 code
= DEBUG_KIND_UNION
;
1291 code
= DEBUG_KIND_ENUM
;
1294 /* Complain and keep going, so compilers can invent new
1295 cross-reference types. */
1296 warn_stab (orig
, _("unrecognized cross reference type"));
1297 code
= DEBUG_KIND_STRUCT
;
1302 q1
= strchr (*pp
, '<');
1303 p
= strchr (*pp
, ':');
1307 return DEBUG_TYPE_NULL
;
1309 if (q1
!= NULL
&& p
> q1
&& p
[1] == ':')
1313 for (q2
= q1
; *q2
!= '\0'; ++q2
)
1317 else if (*q2
== '>')
1319 else if (*q2
== ':' && nest
== 0)
1326 return DEBUG_TYPE_NULL
;
1330 /* Some versions of g++ can emit stabs like
1332 which define structures in terms of themselves. We need to
1333 tell the caller to avoid building a circular structure. */
1334 if (typename
!= NULL
1335 && strncmp (typename
, *pp
, p
- *pp
) == 0
1336 && typename
[p
- *pp
] == '\0')
1337 info
->self_crossref
= true;
1339 dtype
= stab_find_tagged_type (dhandle
, info
, *pp
, p
- *pp
, code
);
1361 /* This type is defined as another type. */
1366 /* Peek ahead at the number to detect void. */
1367 if (! parse_stab_type_number (pp
, xtypenums
))
1368 return DEBUG_TYPE_NULL
;
1370 if (typenums
[0] == xtypenums
[0] && typenums
[1] == xtypenums
[1])
1372 /* This type is being defined as itself, which means that
1374 dtype
= debug_make_void_type (dhandle
);
1380 /* Go back to the number and have parse_stab_type get it.
1381 This means that we can deal with something like
1382 t(1,2)=(3,4)=... which the Lucid compiler uses. */
1383 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
,
1384 pp
, (debug_type
**) NULL
);
1385 if (dtype
== DEBUG_TYPE_NULL
)
1386 return DEBUG_TYPE_NULL
;
1389 if (typenums
[0] != -1)
1391 if (! stab_record_type (dhandle
, info
, typenums
, dtype
))
1392 return DEBUG_TYPE_NULL
;
1399 dtype
= debug_make_pointer_type (dhandle
,
1400 parse_stab_type (dhandle
, info
,
1401 (const char *) NULL
,
1403 (debug_type
**) NULL
));
1407 /* Reference to another type. */
1408 dtype
= (debug_make_reference_type
1410 parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
1411 (debug_type
**) NULL
)));
1415 /* Function returning another type. */
1416 /* FIXME: gdb checks os9k_stabs here. */
1417 dtype
= (debug_make_function_type
1419 parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
1420 (debug_type
**) NULL
),
1421 (debug_type
*) NULL
, false));
1425 /* Const qualifier on some type (Sun). */
1426 /* FIXME: gdb accepts 'c' here if os9k_stabs. */
1427 dtype
= debug_make_const_type (dhandle
,
1428 parse_stab_type (dhandle
, info
,
1429 (const char *) NULL
,
1431 (debug_type
**) NULL
));
1435 /* Volatile qual on some type (Sun). */
1436 /* FIXME: gdb accepts 'i' here if os9k_stabs. */
1437 dtype
= (debug_make_volatile_type
1439 parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
1440 (debug_type
**) NULL
)));
1444 /* Offset (class & variable) type. This is used for a pointer
1445 relative to an object. */
1452 domain
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
1453 (debug_type
**) NULL
);
1454 if (domain
== DEBUG_TYPE_NULL
)
1455 return DEBUG_TYPE_NULL
;
1460 return DEBUG_TYPE_NULL
;
1464 memtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
1465 (debug_type
**) NULL
);
1466 if (memtype
== DEBUG_TYPE_NULL
)
1467 return DEBUG_TYPE_NULL
;
1469 dtype
= debug_make_offset_type (dhandle
, domain
, memtype
);
1474 /* Method (class & fn) type. */
1477 debug_type return_type
;
1480 return_type
= parse_stab_type (dhandle
, info
, (const char *) NULL
,
1481 pp
, (debug_type
**) NULL
);
1482 if (return_type
== DEBUG_TYPE_NULL
)
1483 return DEBUG_TYPE_NULL
;
1487 return DEBUG_TYPE_NULL
;
1490 dtype
= debug_make_method_type (dhandle
, return_type
,
1492 (debug_type
*) NULL
, false);
1497 debug_type return_type
;
1503 domain
= parse_stab_type (dhandle
, info
, (const char *) NULL
,
1504 pp
, (debug_type
**) NULL
);
1505 if (domain
== DEBUG_TYPE_NULL
)
1506 return DEBUG_TYPE_NULL
;
1511 return DEBUG_TYPE_NULL
;
1515 return_type
= parse_stab_type (dhandle
, info
, (const char *) NULL
,
1516 pp
, (debug_type
**) NULL
);
1517 if (return_type
== DEBUG_TYPE_NULL
)
1518 return DEBUG_TYPE_NULL
;
1521 args
= (debug_type
*) xmalloc (alloc
* sizeof *args
);
1528 return DEBUG_TYPE_NULL
;
1535 args
= ((debug_type
*)
1536 xrealloc ((PTR
) args
, alloc
* sizeof *args
));
1539 args
[n
] = parse_stab_type (dhandle
, info
, (const char *) NULL
,
1540 pp
, (debug_type
**) NULL
);
1541 if (args
[n
] == DEBUG_TYPE_NULL
)
1542 return DEBUG_TYPE_NULL
;
1547 /* If the last type is not void, then this function takes a
1548 variable number of arguments. Otherwise, we must strip
1551 || debug_get_type_kind (dhandle
, args
[n
- 1]) != DEBUG_KIND_VOID
)
1559 args
[n
] = DEBUG_TYPE_NULL
;
1561 dtype
= debug_make_method_type (dhandle
, return_type
, domain
, args
,
1568 dtype
= parse_stab_range_type (dhandle
, info
, typename
, pp
, typenums
);
1572 /* FIXME: gdb checks os9k_stabs here. */
1573 /* Sun ACC builtin int type. */
1574 dtype
= parse_stab_sun_builtin_type (dhandle
, pp
);
1578 /* Sun ACC builtin float type. */
1579 dtype
= parse_stab_sun_floating_type (dhandle
, pp
);
1583 /* Enumeration type. */
1584 dtype
= parse_stab_enum_type (dhandle
, pp
);
1589 /* Struct or union type. */
1590 dtype
= parse_stab_struct_type (dhandle
, info
, typename
, pp
,
1591 descriptor
== 's', typenums
);
1599 return DEBUG_TYPE_NULL
;
1603 dtype
= parse_stab_array_type (dhandle
, info
, pp
, stringp
);
1607 dtype
= debug_make_set_type (dhandle
,
1608 parse_stab_type (dhandle
, info
,
1609 (const char *) NULL
,
1611 (debug_type
**) NULL
),
1617 return DEBUG_TYPE_NULL
;
1620 if (dtype
== DEBUG_TYPE_NULL
)
1621 return DEBUG_TYPE_NULL
;
1623 if (typenums
[0] != -1)
1625 if (! stab_record_type (dhandle
, info
, typenums
, dtype
))
1626 return DEBUG_TYPE_NULL
;
1631 if (! debug_record_type_size (dhandle
, dtype
, (unsigned int) size
))
1632 return DEBUG_TYPE_NULL
;
1638 /* Read a number by which a type is referred to in dbx data, or
1639 perhaps read a pair (FILENUM, TYPENUM) in parentheses. Just a
1640 single number N is equivalent to (0,N). Return the two numbers by
1641 storing them in the vector TYPENUMS. */
1644 parse_stab_type_number (pp
, typenums
)
1655 typenums
[1] = (int) parse_number (pp
, (boolean
*) NULL
);
1660 typenums
[0] = (int) parse_number (pp
, (boolean
*) NULL
);
1667 typenums
[1] = (int) parse_number (pp
, (boolean
*) NULL
);
1679 /* Parse a range type. */
1682 parse_stab_range_type (dhandle
, info
, typename
, pp
, typenums
)
1684 struct stab_handle
*info
;
1685 const char *typename
;
1687 const int *typenums
;
1691 boolean self_subrange
;
1692 debug_type index_type
;
1693 const char *s2
, *s3
;
1694 bfd_signed_vma n2
, n3
;
1699 index_type
= DEBUG_TYPE_NULL
;
1701 /* First comes a type we are a subrange of.
1702 In C it is usually 0, 1 or the type being defined. */
1703 if (! parse_stab_type_number (pp
, rangenums
))
1704 return DEBUG_TYPE_NULL
;
1706 self_subrange
= (rangenums
[0] == typenums
[0]
1707 && rangenums
[1] == typenums
[1]);
1712 index_type
= parse_stab_type (dhandle
, info
, (const char *) NULL
,
1713 pp
, (debug_type
**) NULL
);
1714 if (index_type
== DEBUG_TYPE_NULL
)
1715 return DEBUG_TYPE_NULL
;
1721 /* The remaining two operands are usually lower and upper bounds of
1722 the range. But in some special cases they mean something else. */
1724 n2
= parse_number (pp
, &ov2
);
1728 return DEBUG_TYPE_NULL
;
1733 n3
= parse_number (pp
, &ov3
);
1737 return DEBUG_TYPE_NULL
;
1743 /* gcc will emit range stabs for long long types. Handle this
1744 as a special case. FIXME: This needs to be more general. */
1745 #define LLLOW "01000000000000000000000;"
1746 #define LLHIGH "0777777777777777777777;"
1747 #define ULLHIGH "01777777777777777777777;"
1748 if (index_type
== DEBUG_TYPE_NULL
)
1750 if (strncmp (s2
, LLLOW
, sizeof LLLOW
- 1) == 0
1751 && strncmp (s3
, LLHIGH
, sizeof LLHIGH
- 1) == 0)
1752 return debug_make_int_type (dhandle
, 8, false);
1755 && strncmp (s3
, ULLHIGH
, sizeof ULLHIGH
- 1) == 0)
1756 return debug_make_int_type (dhandle
, 8, true);
1759 warn_stab (orig
, _("numeric overflow"));
1762 if (index_type
== DEBUG_TYPE_NULL
)
1764 /* A type defined as a subrange of itself, with both bounds 0,
1766 if (self_subrange
&& n2
== 0 && n3
== 0)
1767 return debug_make_void_type (dhandle
);
1769 /* A type defined as a subrange of itself, with n2 positive and
1770 n3 zero, is a complex type, and n2 is the number of bytes. */
1771 if (self_subrange
&& n3
== 0 && n2
> 0)
1772 return debug_make_complex_type (dhandle
, n2
);
1774 /* If n3 is zero and n2 is positive, this is a floating point
1775 type, and n2 is the number of bytes. */
1776 if (n3
== 0 && n2
> 0)
1777 return debug_make_float_type (dhandle
, n2
);
1779 /* If the upper bound is -1, this is an unsigned int. */
1780 if (n2
== 0 && n3
== -1)
1782 /* When gcc is used with -gstabs, but not -gstabs+, it will emit
1783 long long int:t6=r1;0;-1;
1784 long long unsigned int:t7=r1;0;-1;
1785 We hack here to handle this reasonably. */
1786 if (typename
!= NULL
)
1788 if (strcmp (typename
, "long long int") == 0)
1789 return debug_make_int_type (dhandle
, 8, false);
1790 else if (strcmp (typename
, "long long unsigned int") == 0)
1791 return debug_make_int_type (dhandle
, 8, true);
1793 /* FIXME: The size here really depends upon the target. */
1794 return debug_make_int_type (dhandle
, 4, true);
1797 /* A range of 0 to 127 is char. */
1798 if (self_subrange
&& n2
== 0 && n3
== 127)
1799 return debug_make_int_type (dhandle
, 1, false);
1801 /* FIXME: gdb checks for the language CHILL here. */
1806 return debug_make_int_type (dhandle
, - n3
, true);
1807 else if (n3
== 0xff)
1808 return debug_make_int_type (dhandle
, 1, true);
1809 else if (n3
== 0xffff)
1810 return debug_make_int_type (dhandle
, 2, true);
1811 else if (n3
== (bfd_signed_vma
) 0xffffffff)
1812 return debug_make_int_type (dhandle
, 4, true);
1814 else if (n3
== ((((bfd_signed_vma
) 0xffffffff) << 32) | 0xffffffff))
1815 return debug_make_int_type (dhandle
, 8, true);
1820 && (self_subrange
|| n2
== -8))
1821 return debug_make_int_type (dhandle
, - n2
, true);
1822 else if (n2
== - n3
- 1 || n2
== n3
+ 1)
1825 return debug_make_int_type (dhandle
, 1, false);
1826 else if (n3
== 0x7fff)
1827 return debug_make_int_type (dhandle
, 2, false);
1828 else if (n3
== 0x7fffffff)
1829 return debug_make_int_type (dhandle
, 4, false);
1831 else if (n3
== ((((bfd_vma
) 0x7fffffff) << 32) | 0xffffffff))
1832 return debug_make_int_type (dhandle
, 8, false);
1837 /* At this point I don't have the faintest idea how to deal with a
1838 self_subrange type; I'm going to assume that this is used as an
1839 idiom, and that all of them are special cases. So . . . */
1843 return DEBUG_TYPE_NULL
;
1846 index_type
= stab_find_type (dhandle
, info
, rangenums
);
1847 if (index_type
== DEBUG_TYPE_NULL
)
1849 /* Does this actually ever happen? Is that why we are worrying
1850 about dealing with it rather than just calling error_type? */
1851 warn_stab (orig
, _("missing index type"));
1852 index_type
= debug_make_int_type (dhandle
, 4, false);
1855 return debug_make_range_type (dhandle
, index_type
, n2
, n3
);
1858 /* Sun's ACC uses a somewhat saner method for specifying the builtin
1859 typedefs in every file (for int, long, etc):
1861 type = b <signed> <width>; <offset>; <nbits>
1862 signed = u or s. Possible c in addition to u or s (for char?).
1863 offset = offset from high order bit to start bit of type.
1864 width is # bytes in object of this type, nbits is # bits in type.
1866 The width/offset stuff appears to be for small objects stored in
1867 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
1871 parse_stab_sun_builtin_type (dhandle
, pp
)
1891 return DEBUG_TYPE_NULL
;
1895 /* For some odd reason, all forms of char put a c here. This is strange
1896 because no other type has this honor. We can safely ignore this because
1897 we actually determine 'char'acterness by the number of bits specified in
1902 /* The first number appears to be the number of bytes occupied
1903 by this type, except that unsigned short is 4 instead of 2.
1904 Since this information is redundant with the third number,
1905 we will ignore it. */
1906 (void) parse_number (pp
, (boolean
*) NULL
);
1910 return DEBUG_TYPE_NULL
;
1914 /* The second number is always 0, so ignore it too. */
1915 (void) parse_number (pp
, (boolean
*) NULL
);
1919 return DEBUG_TYPE_NULL
;
1923 /* The third number is the number of bits for this type. */
1924 bits
= parse_number (pp
, (boolean
*) NULL
);
1926 /* The type *should* end with a semicolon. If it are embedded
1927 in a larger type the semicolon may be the only way to know where
1928 the type ends. If this type is at the end of the stabstring we
1929 can deal with the omitted semicolon (but we don't have to like
1930 it). Don't bother to complain(), Sun's compiler omits the semicolon
1936 return debug_make_void_type (dhandle
);
1938 return debug_make_int_type (dhandle
, bits
/ 8, unsignedp
);
1941 /* Parse a builtin floating type generated by the Sun compiler. */
1944 parse_stab_sun_floating_type (dhandle
, pp
)
1954 /* The first number has more details about the type, for example
1956 details
= parse_number (pp
, (boolean
*) NULL
);
1960 return DEBUG_TYPE_NULL
;
1963 /* The second number is the number of bytes occupied by this type */
1964 bytes
= parse_number (pp
, (boolean
*) NULL
);
1968 return DEBUG_TYPE_NULL
;
1971 if (details
== NF_COMPLEX
1972 || details
== NF_COMPLEX16
1973 || details
== NF_COMPLEX32
)
1974 return debug_make_complex_type (dhandle
, bytes
);
1976 return debug_make_float_type (dhandle
, bytes
);
1979 /* Handle an enum type. */
1982 parse_stab_enum_type (dhandle
, pp
)
1988 bfd_signed_vma
*values
;
1994 /* FIXME: gdb checks os9k_stabs here. */
1996 /* The aix4 compiler emits an extra field before the enum members;
1997 my guess is it's a type of some sort. Just ignore it. */
2005 /* Read the value-names and their values.
2006 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
2007 A semicolon or comma instead of a NAME means the end. */
2009 names
= (const char **) xmalloc (alloc
* sizeof *names
);
2010 values
= (bfd_signed_vma
*) xmalloc (alloc
* sizeof *values
);
2012 while (**pp
!= '\0' && **pp
!= ';' && **pp
!= ',')
2022 name
= savestring (*pp
, p
- *pp
);
2025 val
= (bfd_signed_vma
) parse_number (pp
, (boolean
*) NULL
);
2029 return DEBUG_TYPE_NULL
;
2036 names
= ((const char **)
2037 xrealloc ((PTR
) names
, alloc
* sizeof *names
));
2038 values
= ((bfd_signed_vma
*)
2039 xrealloc ((PTR
) values
, alloc
* sizeof *values
));
2053 return debug_make_enum_type (dhandle
, names
, values
);
2056 /* Read the description of a structure (or union type) and return an object
2057 describing the type.
2059 PP points to a character pointer that points to the next unconsumed token
2060 in the the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
2061 *PP will point to "4a:1,0,32;;". */
2064 parse_stab_struct_type (dhandle
, info
, tagname
, pp
, structp
, typenums
)
2066 struct stab_handle
*info
;
2067 const char *tagname
;
2070 const int *typenums
;
2074 debug_baseclass
*baseclasses
;
2075 debug_field
*fields
;
2077 debug_method
*methods
;
2078 debug_type vptrbase
;
2084 size
= parse_number (pp
, (boolean
*) NULL
);
2086 /* Get the other information. */
2087 if (! parse_stab_baseclasses (dhandle
, info
, pp
, &baseclasses
)
2088 || ! parse_stab_struct_fields (dhandle
, info
, pp
, &fields
, &statics
)
2089 || ! parse_stab_members (dhandle
, info
, tagname
, pp
, typenums
, &methods
)
2090 || ! parse_stab_tilde_field (dhandle
, info
, pp
, typenums
, &vptrbase
,
2092 return DEBUG_TYPE_NULL
;
2095 && baseclasses
== NULL
2097 && vptrbase
== DEBUG_TYPE_NULL
2099 return debug_make_struct_type (dhandle
, structp
, size
, fields
);
2101 return debug_make_object_type (dhandle
, structp
, size
, fields
, baseclasses
,
2102 methods
, vptrbase
, ownvptr
);
2105 /* The stabs for C++ derived classes contain baseclass information which
2106 is marked by a '!' character after the total size. This function is
2107 called when we encounter the baseclass marker, and slurps up all the
2108 baseclass information.
2110 Immediately following the '!' marker is the number of base classes that
2111 the class is derived from, followed by information for each base class.
2112 For each base class, there are two visibility specifiers, a bit offset
2113 to the base class information within the derived class, a reference to
2114 the type for the base class, and a terminating semicolon.
2116 A typical example, with two base classes, would be "!2,020,19;0264,21;".
2118 Baseclass information marker __________________|| | | | | | |
2119 Number of baseclasses __________________________| | | | | | |
2120 Visibility specifiers (2) ________________________| | | | | |
2121 Offset in bits from start of class _________________| | | | |
2122 Type number for base class ___________________________| | | |
2123 Visibility specifiers (2) _______________________________| | |
2124 Offset in bits from start of class ________________________| |
2125 Type number of base class ____________________________________|
2127 Return true for success, false for failure. */
2130 parse_stab_baseclasses (dhandle
, info
, pp
, retp
)
2132 struct stab_handle
*info
;
2134 debug_baseclass
**retp
;
2138 debug_baseclass
*classes
;
2146 /* No base classes. */
2151 c
= (unsigned int) parse_number (pp
, (boolean
*) NULL
);
2160 classes
= (debug_baseclass
*) xmalloc ((c
+ 1) * sizeof (**retp
));
2162 for (i
= 0; i
< c
; i
++)
2165 enum debug_visibility visibility
;
2178 warn_stab (orig
, _("unknown virtual character for baseclass"));
2187 visibility
= DEBUG_VISIBILITY_PRIVATE
;
2190 visibility
= DEBUG_VISIBILITY_PROTECTED
;
2193 visibility
= DEBUG_VISIBILITY_PUBLIC
;
2196 warn_stab (orig
, _("unknown visibility character for baseclass"));
2197 visibility
= DEBUG_VISIBILITY_PUBLIC
;
2202 /* The remaining value is the bit offset of the portion of the
2203 object corresponding to this baseclass. Always zero in the
2204 absence of multiple inheritance. */
2205 bitpos
= parse_number (pp
, (boolean
*) NULL
);
2213 type
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
2214 (debug_type
**) NULL
);
2215 if (type
== DEBUG_TYPE_NULL
)
2218 classes
[i
] = debug_make_baseclass (dhandle
, type
, bitpos
, virtual,
2220 if (classes
[i
] == DEBUG_BASECLASS_NULL
)
2228 classes
[i
] = DEBUG_BASECLASS_NULL
;
2235 /* Read struct or class data fields. They have the form:
2237 NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
2239 At the end, we see a semicolon instead of a field.
2241 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
2244 The optional VISIBILITY is one of:
2246 '/0' (VISIBILITY_PRIVATE)
2247 '/1' (VISIBILITY_PROTECTED)
2248 '/2' (VISIBILITY_PUBLIC)
2249 '/9' (VISIBILITY_IGNORE)
2251 or nothing, for C style fields with public visibility.
2253 Returns 1 for success, 0 for failure. */
2256 parse_stab_struct_fields (dhandle
, info
, pp
, retp
, staticsp
)
2258 struct stab_handle
*info
;
2265 debug_field
*fields
;
2276 fields
= (debug_field
*) xmalloc (alloc
* sizeof *fields
);
2279 /* FIXME: gdb checks os9k_stabs here. */
2283 /* Add 1 to c to leave room for NULL pointer at end. */
2287 fields
= ((debug_field
*)
2288 xrealloc ((PTR
) fields
, alloc
* sizeof *fields
));
2291 /* If it starts with CPLUS_MARKER it is a special abbreviation,
2292 unless the CPLUS_MARKER is followed by an underscore, in
2293 which case it is just the name of an anonymous type, which we
2294 should handle like any other type name. We accept either '$'
2295 or '.', because a field name can never contain one of these
2296 characters except as a CPLUS_MARKER. */
2298 if ((*p
== '$' || *p
== '.') && p
[1] != '_')
2301 if (! parse_stab_cpp_abbrev (dhandle
, info
, pp
, fields
+ c
))
2307 /* Look for the ':' that separates the field name from the field
2308 values. Data members are delimited by a single ':', while member
2309 functions are delimited by a pair of ':'s. When we hit the member
2310 functions (if any), terminate scan loop and return. */
2312 p
= strchr (p
, ':');
2322 if (! parse_stab_one_struct_field (dhandle
, info
, pp
, p
, fields
+ c
,
2329 fields
[c
] = DEBUG_FIELD_NULL
;
2336 /* Special GNU C++ name. */
2339 parse_stab_cpp_abbrev (dhandle
, info
, pp
, retp
)
2341 struct stab_handle
*info
;
2349 const char *typename
;
2353 *retp
= DEBUG_FIELD_NULL
;
2367 /* At this point, *pp points to something like "22:23=*22...", where
2368 the type number before the ':' is the "context" and everything
2369 after is a regular type definition. Lookup the type, find it's
2370 name, and construct the field name. */
2372 context
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
2373 (debug_type
**) NULL
);
2374 if (context
== DEBUG_TYPE_NULL
)
2380 /* $vf -- a virtual function table pointer. */
2384 /* $vb -- a virtual bsomethingorother */
2385 typename
= debug_get_type_name (dhandle
, context
);
2386 if (typename
== NULL
)
2388 warn_stab (orig
, _("unnamed $vb type"));
2391 name
= concat ("_vb$", typename
, (const char *) NULL
);
2394 warn_stab (orig
, _("unrecognized C++ abbreviation"));
2395 name
= "INVALID_CPLUSPLUS_ABBREV";
2406 type
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
2407 (debug_type
**) NULL
);
2415 bitpos
= parse_number (pp
, (boolean
*) NULL
);
2423 *retp
= debug_make_field (dhandle
, name
, type
, bitpos
, 0,
2424 DEBUG_VISIBILITY_PRIVATE
);
2425 if (*retp
== DEBUG_FIELD_NULL
)
2431 /* Parse a single field in a struct or union. */
2434 parse_stab_one_struct_field (dhandle
, info
, pp
, p
, retp
, staticsp
)
2436 struct stab_handle
*info
;
2444 enum debug_visibility visibility
;
2451 /* FIXME: gdb checks ARM_DEMANGLING here. */
2453 name
= savestring (*pp
, p
- *pp
);
2458 visibility
= DEBUG_VISIBILITY_PUBLIC
;
2465 visibility
= DEBUG_VISIBILITY_PRIVATE
;
2468 visibility
= DEBUG_VISIBILITY_PROTECTED
;
2471 visibility
= DEBUG_VISIBILITY_PUBLIC
;
2474 warn_stab (orig
, _("unknown visibility character for field"));
2475 visibility
= DEBUG_VISIBILITY_PUBLIC
;
2481 type
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
2482 (debug_type
**) NULL
);
2483 if (type
== DEBUG_TYPE_NULL
)
2490 /* This is a static class member. */
2492 p
= strchr (*pp
, ';');
2499 varname
= savestring (*pp
, p
- *pp
);
2503 *retp
= debug_make_static_member (dhandle
, name
, type
, varname
,
2517 bitpos
= parse_number (pp
, (boolean
*) NULL
);
2525 bitsize
= parse_number (pp
, (boolean
*) NULL
);
2533 if (bitpos
== 0 && bitsize
== 0)
2535 /* This can happen in two cases: (1) at least for gcc 2.4.5 or
2536 so, it is a field which has been optimized out. The correct
2537 stab for this case is to use VISIBILITY_IGNORE, but that is a
2538 recent invention. (2) It is a 0-size array. For example
2539 union { int num; char str[0]; } foo. Printing "<no value>"
2540 for str in "p foo" is OK, since foo.str (and thus foo.str[3])
2541 will continue to work, and a 0-size array as a whole doesn't
2542 have any contents to print.
2544 I suspect this probably could also happen with gcc -gstabs
2545 (not -gstabs+) for static fields, and perhaps other C++
2546 extensions. Hopefully few people use -gstabs with gdb, since
2547 it is intended for dbx compatibility. */
2548 visibility
= DEBUG_VISIBILITY_IGNORE
;
2551 /* FIXME: gdb does some stuff here to mark fields as unpacked. */
2553 *retp
= debug_make_field (dhandle
, name
, type
, bitpos
, bitsize
, visibility
);
2558 /* Read member function stabs info for C++ classes. The form of each member
2561 NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
2563 An example with two member functions is:
2565 afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
2567 For the case of overloaded operators, the format is op$::*.funcs, where
2568 $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
2569 name (such as `+=') and `.' marks the end of the operator name. */
2572 parse_stab_members (dhandle
, info
, tagname
, pp
, typenums
, retp
)
2574 struct stab_handle
*info
;
2575 const char *tagname
;
2577 const int *typenums
;
2578 debug_method
**retp
;
2581 debug_method
*methods
;
2597 debug_method_variant
*variants
;
2599 unsigned int allocvars
;
2600 debug_type look_ahead_type
;
2602 p
= strchr (*pp
, ':');
2603 if (p
== NULL
|| p
[1] != ':')
2606 /* FIXME: Some systems use something other than '$' here. */
2607 if ((*pp
)[0] != 'o' || (*pp
)[1] != 'p' || (*pp
)[2] != '$')
2609 name
= savestring (*pp
, p
- *pp
);
2614 /* This is a completely wierd case. In order to stuff in the
2615 names that might contain colons (the usual name delimiter),
2616 Mike Tiemann defined a different name format which is
2617 signalled if the identifier is "op$". In that case, the
2618 format is "op$::XXXX." where XXXX is the name. This is
2619 used for names like "+" or "=". YUUUUUUUK! FIXME! */
2621 for (p
= *pp
; *p
!= '.' && *p
!= '\0'; p
++)
2628 name
= savestring (*pp
, p
- *pp
);
2633 variants
= ((debug_method_variant
*)
2634 xmalloc (allocvars
* sizeof *variants
));
2637 look_ahead_type
= DEBUG_TYPE_NULL
;
2644 enum debug_visibility visibility
;
2645 boolean constp
, volatilep
, staticp
;
2648 const char *physname
;
2651 if (look_ahead_type
!= DEBUG_TYPE_NULL
)
2653 /* g++ version 1 kludge */
2654 type
= look_ahead_type
;
2655 look_ahead_type
= DEBUG_TYPE_NULL
;
2659 type
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
2660 (debug_type
**) NULL
);
2661 if (type
== DEBUG_TYPE_NULL
)
2671 p
= strchr (*pp
, ';');
2679 if (debug_get_type_kind (dhandle
, type
) == DEBUG_KIND_METHOD
2680 && debug_get_parameter_types (dhandle
, type
, &varargs
) == NULL
)
2683 argtypes
= savestring (*pp
, p
- *pp
);
2689 visibility
= DEBUG_VISIBILITY_PRIVATE
;
2692 visibility
= DEBUG_VISIBILITY_PROTECTED
;
2695 visibility
= DEBUG_VISIBILITY_PUBLIC
;
2705 /* Normal function. */
2709 /* const member function. */
2714 /* volatile member function. */
2719 /* const volatile member function. */
2727 /* File compiled with g++ version 1; no information. */
2730 warn_stab (orig
, _("const/volatile indicator missing"));
2738 /* virtual member function, followed by index. The sign
2739 bit is supposedly set to distinguish
2740 pointers-to-methods from virtual function indicies. */
2742 voffset
= parse_number (pp
, (boolean
*) NULL
);
2749 voffset
&= 0x7fffffff;
2751 if (**pp
== ';' || *pp
== '\0')
2753 /* Must be g++ version 1. */
2754 context
= DEBUG_TYPE_NULL
;
2758 /* Figure out from whence this virtual function
2759 came. It may belong to virtual function table of
2760 one of its baseclasses. */
2761 look_ahead_type
= parse_stab_type (dhandle
, info
,
2762 (const char *) NULL
,
2764 (debug_type
**) NULL
);
2767 /* g++ version 1 overloaded methods. */
2768 context
= DEBUG_TYPE_NULL
;
2772 context
= look_ahead_type
;
2773 look_ahead_type
= DEBUG_TYPE_NULL
;
2785 /* static member function. */
2789 context
= DEBUG_TYPE_NULL
;
2790 if (strncmp (argtypes
, name
, strlen (name
)) != 0)
2795 warn_stab (orig
, "member function type missing");
2797 context
= DEBUG_TYPE_NULL
;
2803 context
= DEBUG_TYPE_NULL
;
2807 /* If the type is not a stub, then the argtypes string is
2808 the physical name of the function. Otherwise the
2809 argtypes string is the mangled form of the argument
2810 types, and the full type and the physical name must be
2811 extracted from them. */
2813 physname
= argtypes
;
2816 debug_type class_type
, return_type
;
2818 class_type
= stab_find_type (dhandle
, info
, typenums
);
2819 if (class_type
== DEBUG_TYPE_NULL
)
2821 return_type
= debug_get_return_type (dhandle
, type
);
2822 if (return_type
== DEBUG_TYPE_NULL
)
2827 type
= parse_stab_argtypes (dhandle
, info
, class_type
, name
,
2828 tagname
, return_type
, argtypes
,
2829 constp
, volatilep
, &physname
);
2830 if (type
== DEBUG_TYPE_NULL
)
2834 if (cvars
+ 1 >= allocvars
)
2837 variants
= ((debug_method_variant
*)
2838 xrealloc ((PTR
) variants
,
2839 allocvars
* sizeof *variants
));
2843 variants
[cvars
] = debug_make_method_variant (dhandle
, physname
,
2848 variants
[cvars
] = debug_make_static_method_variant (dhandle
,
2854 if (variants
[cvars
] == DEBUG_METHOD_VARIANT_NULL
)
2859 while (**pp
!= ';' && **pp
!= '\0');
2861 variants
[cvars
] = DEBUG_METHOD_VARIANT_NULL
;
2869 methods
= ((debug_method
*)
2870 xrealloc ((PTR
) methods
, alloc
* sizeof *methods
));
2873 methods
[c
] = debug_make_method (dhandle
, name
, variants
);
2878 if (methods
!= NULL
)
2879 methods
[c
] = DEBUG_METHOD_NULL
;
2886 /* Parse a string representing argument types for a method. Stabs
2887 tries to save space by packing argument types into a mangled
2888 string. This string should give us enough information to extract
2889 both argument types and the physical name of the function, given
2893 parse_stab_argtypes (dhandle
, info
, class_type
, fieldname
, tagname
,
2894 return_type
, argtypes
, constp
, volatilep
, pphysname
)
2896 struct stab_handle
*info
;
2897 debug_type class_type
;
2898 const char *fieldname
;
2899 const char *tagname
;
2900 debug_type return_type
;
2901 const char *argtypes
;
2904 const char **pphysname
;
2906 boolean is_full_physname_constructor
;
2907 boolean is_constructor
;
2908 boolean is_destructor
;
2912 /* Constructors are sometimes handled specially. */
2913 is_full_physname_constructor
= ((argtypes
[0] == '_'
2914 && argtypes
[1] == '_'
2915 && (ISDIGIT (argtypes
[2])
2916 || argtypes
[2] == 'Q'
2917 || argtypes
[2] == 't'))
2918 || strncmp (argtypes
, "__ct", 4) == 0);
2920 is_constructor
= (is_full_physname_constructor
2922 && strcmp (fieldname
, tagname
) == 0));
2923 is_destructor
= ((argtypes
[0] == '_'
2924 && (argtypes
[1] == '$' || argtypes
[1] == '.')
2925 && argtypes
[2] == '_')
2926 || strncmp (argtypes
, "__dt", 4) == 0);
2928 if (is_destructor
|| is_full_physname_constructor
)
2929 *pphysname
= argtypes
;
2933 const char *const_prefix
;
2934 const char *volatile_prefix
;
2936 unsigned int mangled_name_len
;
2939 len
= tagname
== NULL
? 0 : strlen (tagname
);
2940 const_prefix
= constp
? "C" : "";
2941 volatile_prefix
= volatilep
? "V" : "";
2944 sprintf (buf
, "__%s%s", const_prefix
, volatile_prefix
);
2945 else if (tagname
!= NULL
&& strchr (tagname
, '<') != NULL
)
2947 /* Template methods are fully mangled. */
2948 sprintf (buf
, "__%s%s", const_prefix
, volatile_prefix
);
2953 sprintf (buf
, "__%s%s%d", const_prefix
, volatile_prefix
, len
);
2955 mangled_name_len
= ((is_constructor
? 0 : strlen (fieldname
))
2961 if (fieldname
[0] == 'o'
2962 && fieldname
[1] == 'p'
2963 && (fieldname
[2] == '$' || fieldname
[2] == '.'))
2967 opname
= cplus_mangle_opname (fieldname
+ 3, 0);
2970 fprintf (stderr
, _("No mangling for \"%s\"\n"), fieldname
);
2971 return DEBUG_TYPE_NULL
;
2973 mangled_name_len
+= strlen (opname
);
2974 physname
= (char *) xmalloc (mangled_name_len
);
2975 strncpy (physname
, fieldname
, 3);
2976 strcpy (physname
+ 3, opname
);
2980 physname
= (char *) xmalloc (mangled_name_len
);
2984 strcpy (physname
, fieldname
);
2987 strcat (physname
, buf
);
2988 if (tagname
!= NULL
)
2989 strcat (physname
, tagname
);
2990 strcat (physname
, argtypes
);
2992 *pphysname
= physname
;
2995 if (*argtypes
== '\0' || is_destructor
)
2997 args
= (debug_type
*) xmalloc (sizeof *args
);
2999 return debug_make_method_type (dhandle
, return_type
, class_type
, args
,
3003 args
= stab_demangle_argtypes (dhandle
, info
, *pphysname
, &varargs
);
3005 return DEBUG_TYPE_NULL
;
3007 return debug_make_method_type (dhandle
, return_type
, class_type
, args
,
3011 /* The tail end of stabs for C++ classes that contain a virtual function
3012 pointer contains a tilde, a %, and a type number.
3013 The type number refers to the base class (possibly this class itself) which
3014 contains the vtable pointer for the current class.
3016 This function is called when we have parsed all the method declarations,
3017 so we can look for the vptr base class info. */
3020 parse_stab_tilde_field (dhandle
, info
, pp
, typenums
, retvptrbase
, retownvptr
)
3022 struct stab_handle
*info
;
3024 const int *typenums
;
3025 debug_type
*retvptrbase
;
3026 boolean
*retownvptr
;
3032 *retvptrbase
= DEBUG_TYPE_NULL
;
3033 *retownvptr
= false;
3037 /* If we are positioned at a ';', then skip it. */
3046 if (**pp
== '=' || **pp
== '+' || **pp
== '-')
3048 /* Obsolete flags that used to indicate the presence of
3049 constructors and/or destructors. */
3060 /* The next number is the type number of the base class (possibly
3061 our own class) which supplies the vtable for this class. */
3062 if (! parse_stab_type_number (pp
, vtypenums
))
3065 if (vtypenums
[0] == typenums
[0]
3066 && vtypenums
[1] == typenums
[1])
3075 vtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
3076 (debug_type
**) NULL
);
3077 for (p
= *pp
; *p
!= ';' && *p
!= '\0'; p
++)
3085 *retvptrbase
= vtype
;
3093 /* Read a definition of an array type. */
3096 parse_stab_array_type (dhandle
, info
, pp
, stringp
)
3098 struct stab_handle
*info
;
3105 debug_type index_type
;
3107 bfd_signed_vma lower
, upper
;
3108 debug_type element_type
;
3110 /* Format of an array type:
3111 "ar<index type>;lower;upper;<array_contents_type>".
3112 OS9000: "arlower,upper;<array_contents_type>".
3114 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
3115 for these, produce a type like float[][]. */
3119 /* FIXME: gdb checks os9k_stabs here. */
3121 /* If the index type is type 0, we take it as int. */
3123 if (! parse_stab_type_number (&p
, typenums
))
3124 return DEBUG_TYPE_NULL
;
3125 if (typenums
[0] == 0 && typenums
[1] == 0 && **pp
!= '=')
3127 index_type
= debug_find_named_type (dhandle
, "int");
3128 if (index_type
== DEBUG_TYPE_NULL
)
3130 index_type
= debug_make_int_type (dhandle
, 4, false);
3131 if (index_type
== DEBUG_TYPE_NULL
)
3132 return DEBUG_TYPE_NULL
;
3138 index_type
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
3139 (debug_type
**) NULL
);
3145 return DEBUG_TYPE_NULL
;
3151 if (! ISDIGIT (**pp
) && **pp
!= '-')
3157 lower
= (bfd_signed_vma
) parse_number (pp
, (boolean
*) NULL
);
3161 return DEBUG_TYPE_NULL
;
3165 if (! ISDIGIT (**pp
) && **pp
!= '-')
3171 upper
= (bfd_signed_vma
) parse_number (pp
, (boolean
*) NULL
);
3175 return DEBUG_TYPE_NULL
;
3179 element_type
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
3180 (debug_type
**) NULL
);
3181 if (element_type
== DEBUG_TYPE_NULL
)
3182 return DEBUG_TYPE_NULL
;
3190 return debug_make_array_type (dhandle
, element_type
, index_type
, lower
,
3194 /* This struct holds information about files we have seen using
3199 /* The next N_BINCL file. */
3200 struct bincl_file
*next
;
3201 /* The next N_BINCL on the stack. */
3202 struct bincl_file
*next_stack
;
3203 /* The file name. */
3205 /* The hash value. */
3207 /* The file index. */
3209 /* The list of types defined in this file. */
3210 struct stab_types
*file_types
;
3213 /* Start a new N_BINCL file, pushing it onto the stack. */
3216 push_bincl (info
, name
, hash
)
3217 struct stab_handle
*info
;
3221 struct bincl_file
*n
;
3223 n
= (struct bincl_file
*) xmalloc (sizeof *n
);
3224 n
->next
= info
->bincl_list
;
3225 n
->next_stack
= info
->bincl_stack
;
3228 n
->file
= info
->files
;
3229 n
->file_types
= NULL
;
3230 info
->bincl_list
= n
;
3231 info
->bincl_stack
= n
;
3234 info
->file_types
= ((struct stab_types
**)
3235 xrealloc ((PTR
) info
->file_types
,
3237 * sizeof *info
->file_types
)));
3238 info
->file_types
[n
->file
] = NULL
;
3241 /* Finish an N_BINCL file, at an N_EINCL, popping the name off the
3246 struct stab_handle
*info
;
3248 struct bincl_file
*o
;
3250 o
= info
->bincl_stack
;
3252 return info
->main_filename
;
3253 info
->bincl_stack
= o
->next_stack
;
3255 o
->file_types
= info
->file_types
[o
->file
];
3257 if (info
->bincl_stack
== NULL
)
3258 return info
->main_filename
;
3259 return info
->bincl_stack
->name
;
3262 /* Handle an N_EXCL: get the types from the corresponding N_BINCL. */
3265 find_excl (info
, name
, hash
)
3266 struct stab_handle
*info
;
3270 struct bincl_file
*l
;
3273 info
->file_types
= ((struct stab_types
**)
3274 xrealloc ((PTR
) info
->file_types
,
3276 * sizeof *info
->file_types
)));
3278 for (l
= info
->bincl_list
; l
!= NULL
; l
= l
->next
)
3279 if (l
->hash
== hash
&& strcmp (l
->name
, name
) == 0)
3283 warn_stab (name
, _("Undefined N_EXCL"));
3284 info
->file_types
[info
->files
- 1] = NULL
;
3288 info
->file_types
[info
->files
- 1] = l
->file_types
;
3293 /* Handle a variable definition. gcc emits variable definitions for a
3294 block before the N_LBRAC, so we must hold onto them until we see
3295 it. The SunPRO compiler emits variable definitions after the
3296 N_LBRAC, so we can call debug_record_variable immediately. */
3299 stab_record_variable (dhandle
, info
, name
, type
, kind
, val
)
3301 struct stab_handle
*info
;
3304 enum debug_var_kind kind
;
3307 struct stab_pending_var
*v
;
3309 if ((kind
== DEBUG_GLOBAL
|| kind
== DEBUG_STATIC
)
3310 || ! info
->within_function
3311 || (info
->gcc_compiled
== 0 && info
->n_opt_found
))
3312 return debug_record_variable (dhandle
, name
, type
, kind
, val
);
3314 v
= (struct stab_pending_var
*) xmalloc (sizeof *v
);
3315 memset (v
, 0, sizeof *v
);
3317 v
->next
= info
->pending
;
3327 /* Emit pending variable definitions. This is called after we see the
3328 N_LBRAC that starts the block. */
3331 stab_emit_pending_vars (dhandle
, info
)
3333 struct stab_handle
*info
;
3335 struct stab_pending_var
*v
;
3340 struct stab_pending_var
*next
;
3342 if (! debug_record_variable (dhandle
, v
->name
, v
->type
, v
->kind
, v
->val
))
3350 info
->pending
= NULL
;
3355 /* Find the slot for a type in the database. */
3358 stab_find_slot (info
, typenums
)
3359 struct stab_handle
*info
;
3360 const int *typenums
;
3364 struct stab_types
**ps
;
3366 filenum
= typenums
[0];
3367 index
= typenums
[1];
3369 if (filenum
< 0 || (unsigned int) filenum
>= info
->files
)
3371 fprintf (stderr
, _("Type file number %d out of range\n"), filenum
);
3376 fprintf (stderr
, _("Type index number %d out of range\n"), index
);
3380 ps
= info
->file_types
+ filenum
;
3382 while (index
>= STAB_TYPES_SLOTS
)
3386 *ps
= (struct stab_types
*) xmalloc (sizeof **ps
);
3387 memset (*ps
, 0, sizeof **ps
);
3390 index
-= STAB_TYPES_SLOTS
;
3394 *ps
= (struct stab_types
*) xmalloc (sizeof **ps
);
3395 memset (*ps
, 0, sizeof **ps
);
3398 return (*ps
)->types
+ index
;
3401 /* Find a type given a type number. If the type has not been
3402 allocated yet, create an indirect type. */
3405 stab_find_type (dhandle
, info
, typenums
)
3407 struct stab_handle
*info
;
3408 const int *typenums
;
3412 if (typenums
[0] == 0 && typenums
[1] < 0)
3414 /* A negative type number indicates an XCOFF builtin type. */
3415 return stab_xcoff_builtin_type (dhandle
, info
, typenums
[1]);
3418 slot
= stab_find_slot (info
, typenums
);
3420 return DEBUG_TYPE_NULL
;
3422 if (*slot
== DEBUG_TYPE_NULL
)
3423 return debug_make_indirect_type (dhandle
, slot
, (const char *) NULL
);
3428 /* Record that a given type number refers to a given type. */
3431 stab_record_type (dhandle
, info
, typenums
, type
)
3432 PTR dhandle ATTRIBUTE_UNUSED
;
3433 struct stab_handle
*info
;
3434 const int *typenums
;
3439 slot
= stab_find_slot (info
, typenums
);
3443 /* gdb appears to ignore type redefinitions, so we do as well. */
3450 /* Return an XCOFF builtin type. */
3453 stab_xcoff_builtin_type (dhandle
, info
, typenum
)
3455 struct stab_handle
*info
;
3461 if (typenum
>= 0 || typenum
< -XCOFF_TYPE_COUNT
)
3463 fprintf (stderr
, _("Unrecognized XCOFF type %d\n"), typenum
);
3464 return DEBUG_TYPE_NULL
;
3466 if (info
->xcoff_types
[-typenum
] != NULL
)
3467 return info
->xcoff_types
[-typenum
];
3472 /* The size of this and all the other types are fixed, defined
3473 by the debugging format. */
3475 rettype
= debug_make_int_type (dhandle
, 4, false);
3479 rettype
= debug_make_int_type (dhandle
, 1, false);
3483 rettype
= debug_make_int_type (dhandle
, 2, false);
3487 rettype
= debug_make_int_type (dhandle
, 4, false);
3490 name
= "unsigned char";
3491 rettype
= debug_make_int_type (dhandle
, 1, true);
3494 name
= "signed char";
3495 rettype
= debug_make_int_type (dhandle
, 1, false);
3498 name
= "unsigned short";
3499 rettype
= debug_make_int_type (dhandle
, 2, true);
3502 name
= "unsigned int";
3503 rettype
= debug_make_int_type (dhandle
, 4, true);
3507 rettype
= debug_make_int_type (dhandle
, 4, true);
3509 name
= "unsigned long";
3510 rettype
= debug_make_int_type (dhandle
, 4, true);
3514 rettype
= debug_make_void_type (dhandle
);
3517 /* IEEE single precision (32 bit). */
3519 rettype
= debug_make_float_type (dhandle
, 4);
3522 /* IEEE double precision (64 bit). */
3524 rettype
= debug_make_float_type (dhandle
, 8);
3527 /* This is an IEEE double on the RS/6000, and different machines
3528 with different sizes for "long double" should use different
3529 negative type numbers. See stabs.texinfo. */
3530 name
= "long double";
3531 rettype
= debug_make_float_type (dhandle
, 8);
3535 rettype
= debug_make_int_type (dhandle
, 4, false);
3539 rettype
= debug_make_bool_type (dhandle
, 4);
3542 name
= "short real";
3543 rettype
= debug_make_float_type (dhandle
, 4);
3547 rettype
= debug_make_float_type (dhandle
, 8);
3557 rettype
= debug_make_int_type (dhandle
, 1, true);
3561 rettype
= debug_make_bool_type (dhandle
, 1);
3565 rettype
= debug_make_bool_type (dhandle
, 2);
3569 rettype
= debug_make_bool_type (dhandle
, 4);
3573 rettype
= debug_make_bool_type (dhandle
, 4);
3576 /* Complex type consisting of two IEEE single precision values. */
3578 rettype
= debug_make_complex_type (dhandle
, 8);
3581 /* Complex type consisting of two IEEE double precision values. */
3582 name
= "double complex";
3583 rettype
= debug_make_complex_type (dhandle
, 16);
3587 rettype
= debug_make_int_type (dhandle
, 1, false);
3591 rettype
= debug_make_int_type (dhandle
, 2, false);
3595 rettype
= debug_make_int_type (dhandle
, 4, false);
3600 rettype
= debug_make_int_type (dhandle
, 2, false);
3604 rettype
= debug_make_int_type (dhandle
, 8, false);
3607 name
= "unsigned long long";
3608 rettype
= debug_make_int_type (dhandle
, 8, true);
3612 rettype
= debug_make_bool_type (dhandle
, 8);
3616 rettype
= debug_make_int_type (dhandle
, 8, false);
3622 rettype
= debug_name_type (dhandle
, name
, rettype
);
3624 info
->xcoff_types
[-typenum
] = rettype
;
3629 /* Find or create a tagged type. */
3632 stab_find_tagged_type (dhandle
, info
, p
, len
, kind
)
3634 struct stab_handle
*info
;
3637 enum debug_type_kind kind
;
3641 struct stab_tag
*st
;
3643 name
= savestring (p
, len
);
3645 /* We pass DEBUG_KIND_ILLEGAL because we want all tags in the same
3646 namespace. This is right for C, and I don't know how to handle
3647 other languages. FIXME. */
3648 dtype
= debug_find_tagged_type (dhandle
, name
, DEBUG_KIND_ILLEGAL
);
3649 if (dtype
!= DEBUG_TYPE_NULL
)
3655 /* We need to allocate an entry on the undefined tag list. */
3656 for (st
= info
->tags
; st
!= NULL
; st
= st
->next
)
3658 if (st
->name
[0] == name
[0]
3659 && strcmp (st
->name
, name
) == 0)
3661 if (st
->kind
== DEBUG_KIND_ILLEGAL
)
3669 st
= (struct stab_tag
*) xmalloc (sizeof *st
);
3670 memset (st
, 0, sizeof *st
);
3672 st
->next
= info
->tags
;
3675 st
->slot
= DEBUG_TYPE_NULL
;
3676 st
->type
= debug_make_indirect_type (dhandle
, &st
->slot
, name
);
3683 /* In order to get the correct argument types for a stubbed method, we
3684 need to extract the argument types from a C++ mangled string.
3685 Since the argument types can refer back to the return type, this
3686 means that we must demangle the entire physical name. In gdb this
3687 is done by calling cplus_demangle and running the results back
3688 through the C++ expression parser. Since we have no expression
3689 parser, we must duplicate much of the work of cplus_demangle here.
3691 We assume that GNU style demangling is used, since this is only
3692 done for method stubs, and only g++ should output that form of
3693 debugging information. */
3695 /* This structure is used to hold a pointer to type information which
3696 demangling a string. */
3698 struct stab_demangle_typestring
3700 /* The start of the type. This is not null terminated. */
3701 const char *typestring
;
3702 /* The length of the type. */
3706 /* This structure is used to hold information while demangling a
3709 struct stab_demangle_info
3711 /* The debugging information handle. */
3713 /* The stab information handle. */
3714 struct stab_handle
*info
;
3715 /* The array of arguments we are building. */
3717 /* Whether the method takes a variable number of arguments. */
3719 /* The array of types we have remembered. */
3720 struct stab_demangle_typestring
*typestrings
;
3721 /* The number of typestrings. */
3722 unsigned int typestring_count
;
3723 /* The number of typestring slots we have allocated. */
3724 unsigned int typestring_alloc
;
3727 static void stab_bad_demangle
PARAMS ((const char *));
3728 static unsigned int stab_demangle_count
PARAMS ((const char **));
3729 static boolean stab_demangle_get_count
3730 PARAMS ((const char **, unsigned int *));
3731 static boolean stab_demangle_prefix
3732 PARAMS ((struct stab_demangle_info
*, const char **));
3733 static boolean stab_demangle_function_name
3734 PARAMS ((struct stab_demangle_info
*, const char **, const char *));
3735 static boolean stab_demangle_signature
3736 PARAMS ((struct stab_demangle_info
*, const char **));
3737 static boolean stab_demangle_qualified
3738 PARAMS ((struct stab_demangle_info
*, const char **, debug_type
*));
3739 static boolean stab_demangle_template
3740 PARAMS ((struct stab_demangle_info
*, const char **, char **));
3741 static boolean stab_demangle_class
3742 PARAMS ((struct stab_demangle_info
*, const char **, const char **));
3743 static boolean stab_demangle_args
3744 PARAMS ((struct stab_demangle_info
*, const char **, debug_type
**,
3746 static boolean stab_demangle_arg
3747 PARAMS ((struct stab_demangle_info
*, const char **, debug_type
**,
3748 unsigned int *, unsigned int *));
3749 static boolean stab_demangle_type
3750 PARAMS ((struct stab_demangle_info
*, const char **, debug_type
*));
3751 static boolean stab_demangle_fund_type
3752 PARAMS ((struct stab_demangle_info
*, const char **, debug_type
*));
3753 static boolean stab_demangle_remember_type
3754 PARAMS ((struct stab_demangle_info
*, const char *, int));
3756 /* Warn about a bad demangling. */
3759 stab_bad_demangle (s
)
3762 fprintf (stderr
, _("bad mangled name `%s'\n"), s
);
3765 /* Get a count from a stab string. */
3768 stab_demangle_count (pp
)
3774 while (ISDIGIT (**pp
))
3777 count
+= **pp
- '0';
3783 /* Require a count in a string. The count may be multiple digits, in
3784 which case it must end in an underscore. */
3787 stab_demangle_get_count (pp
, pi
)
3791 if (! ISDIGIT (**pp
))
3809 while (ISDIGIT (*p
));
3820 /* This function demangles a physical name, returning a NULL
3821 terminated array of argument types. */
3824 stab_demangle_argtypes (dhandle
, info
, physname
, pvarargs
)
3826 struct stab_handle
*info
;
3827 const char *physname
;
3830 struct stab_demangle_info minfo
;
3832 minfo
.dhandle
= dhandle
;
3835 minfo
.varargs
= false;
3836 minfo
.typestring_alloc
= 10;
3837 minfo
.typestrings
= ((struct stab_demangle_typestring
*)
3838 xmalloc (minfo
.typestring_alloc
3839 * sizeof *minfo
.typestrings
));
3840 minfo
.typestring_count
= 0;
3842 /* cplus_demangle checks for special GNU mangled forms, but we can't
3843 see any of them in mangled method argument types. */
3845 if (! stab_demangle_prefix (&minfo
, &physname
))
3848 if (*physname
!= '\0')
3850 if (! stab_demangle_signature (&minfo
, &physname
))
3854 free (minfo
.typestrings
);
3855 minfo
.typestrings
= NULL
;
3857 if (minfo
.args
== NULL
)
3858 fprintf (stderr
, _("no argument types in mangled string\n"));
3860 *pvarargs
= minfo
.varargs
;
3864 if (minfo
.typestrings
!= NULL
)
3865 free (minfo
.typestrings
);
3869 /* Demangle the prefix of the mangled name. */
3872 stab_demangle_prefix (minfo
, pp
)
3873 struct stab_demangle_info
*minfo
;
3879 /* cplus_demangle checks for global constructors and destructors,
3880 but we can't see them in mangled argument types. */
3882 /* Look for `__'. */
3886 scan
= strchr (scan
, '_');
3888 while (scan
!= NULL
&& *++scan
!= '_');
3892 stab_bad_demangle (*pp
);
3898 /* We found `__'; move ahead to the last contiguous `__' pair. */
3899 i
= strspn (scan
, "_");
3904 && (ISDIGIT (scan
[2])
3908 /* This is a GNU style constructor name. */
3912 else if (scan
== *pp
3913 && ! ISDIGIT (scan
[2])
3916 /* Look for the `__' that separates the prefix from the
3918 while (*scan
== '_')
3920 scan
= strstr (scan
, "__");
3921 if (scan
== NULL
|| scan
[2] == '\0')
3923 stab_bad_demangle (*pp
);
3927 return stab_demangle_function_name (minfo
, pp
, scan
);
3929 else if (scan
[2] != '\0')
3931 /* The name doesn't start with `__', but it does contain `__'. */
3932 return stab_demangle_function_name (minfo
, pp
, scan
);
3936 stab_bad_demangle (*pp
);
3942 /* Demangle a function name prefix. The scan argument points to the
3943 double underscore which separates the function name from the
3947 stab_demangle_function_name (minfo
, pp
, scan
)
3948 struct stab_demangle_info
*minfo
;
3954 /* The string from *pp to scan is the name of the function. We
3955 don't care about the name, since we just looking for argument
3956 types. However, for conversion operators, the name may include a
3957 type which we must remember in order to handle backreferences. */
3963 && strncmp (name
, "type", 4) == 0
3964 && (name
[4] == '$' || name
[4] == '.'))
3968 /* This is a type conversion operator. */
3970 if (! stab_demangle_type (minfo
, &tem
, (debug_type
*) NULL
))
3973 else if (name
[0] == '_'
3980 /* This is a type conversion operator. */
3982 if (! stab_demangle_type (minfo
, &tem
, (debug_type
*) NULL
))
3989 /* Demangle the signature. This is where the argument types are
3993 stab_demangle_signature (minfo
, pp
)
3994 struct stab_demangle_info
*minfo
;
3998 boolean expect_func
, func_done
;
4003 expect_func
= false;
4007 while (**pp
!= '\0')
4013 if (! stab_demangle_qualified (minfo
, pp
, (debug_type
*) NULL
)
4014 || ! stab_demangle_remember_type (minfo
, hold
, *pp
- hold
))
4021 /* Static member function. FIXME: Can this happen? */
4028 /* Const member function. */
4034 case '0': case '1': case '2': case '3': case '4':
4035 case '5': case '6': case '7': case '8': case '9':
4038 if (! stab_demangle_class (minfo
, pp
, (const char **) NULL
)
4039 || ! stab_demangle_remember_type (minfo
, hold
, *pp
- hold
))
4046 /* Function. I don't know if this actually happens with g++
4051 if (! stab_demangle_args (minfo
, pp
, &minfo
->args
, &minfo
->varargs
))
4059 if (! stab_demangle_template (minfo
, pp
, (char **) NULL
)
4060 || ! stab_demangle_remember_type (minfo
, hold
, *pp
- hold
))
4067 /* At the outermost level, we cannot have a return type
4068 specified, so if we run into another '_' at this point we
4069 are dealing with a mangled name that is either bogus, or
4070 has been mangled by some algorithm we don't know how to
4071 deal with. So just reject the entire demangling. */
4072 stab_bad_demangle (orig
);
4076 /* Assume we have stumbled onto the first outermost function
4077 argument token, and start processing args. */
4079 if (! stab_demangle_args (minfo
, pp
, &minfo
->args
, &minfo
->varargs
))
4087 if (! stab_demangle_args (minfo
, pp
, &minfo
->args
, &minfo
->varargs
))
4094 /* With GNU style demangling, bar__3foo is 'foo::bar(void)', and
4095 bar__3fooi is 'foo::bar(int)'. We get here when we find the
4096 first case, and need to ensure that the '(void)' gets added
4097 to the current declp. */
4098 if (! stab_demangle_args (minfo
, pp
, &minfo
->args
, &minfo
->varargs
))
4105 /* Demangle a qualified name, such as "Q25Outer5Inner" which is the
4106 mangled form of "Outer::Inner". */
4109 stab_demangle_qualified (minfo
, pp
, ptype
)
4110 struct stab_demangle_info
*minfo
;
4116 unsigned int qualifiers
;
4124 /* GNU mangled name with more than 9 classes. The count is
4125 preceded by an underscore (to distinguish it from the <= 9
4126 case) and followed by an underscore. */
4128 if (! ISDIGIT (*p
) || *p
== '0')
4130 stab_bad_demangle (orig
);
4133 qualifiers
= atoi (p
);
4134 while (ISDIGIT (*p
))
4138 stab_bad_demangle (orig
);
4144 case '1': case '2': case '3': case '4': case '5':
4145 case '6': case '7': case '8': case '9':
4146 qualifiers
= (*pp
)[1] - '0';
4147 /* Skip an optional underscore after the count. */
4148 if ((*pp
)[2] == '_')
4155 stab_bad_demangle (orig
);
4159 context
= DEBUG_TYPE_NULL
;
4161 /* Pick off the names. */
4162 while (qualifiers
-- > 0)
4170 if (! stab_demangle_template (minfo
, pp
,
4171 ptype
!= NULL
? &name
: NULL
))
4176 context
= stab_find_tagged_type (minfo
->dhandle
, minfo
->info
,
4177 name
, strlen (name
),
4180 if (context
== DEBUG_TYPE_NULL
)
4188 len
= stab_demangle_count (pp
);
4189 if (strlen (*pp
) < len
)
4191 stab_bad_demangle (orig
);
4197 const debug_field
*fields
;
4200 if (context
!= DEBUG_TYPE_NULL
)
4201 fields
= debug_get_fields (minfo
->dhandle
, context
);
4203 context
= DEBUG_TYPE_NULL
;
4209 /* Try to find the type by looking through the
4210 fields of context until we find a field with the
4211 same type. This ought to work for a class
4212 defined within a class, but it won't work for,
4213 e.g., an enum defined within a class. stabs does
4214 not give us enough information to figure out the
4217 name
= savestring (*pp
, len
);
4219 for (; *fields
!= DEBUG_FIELD_NULL
; fields
++)
4224 ft
= debug_get_field_type (minfo
->dhandle
, *fields
);
4227 dn
= debug_get_type_name (minfo
->dhandle
, ft
);
4228 if (dn
!= NULL
&& strcmp (dn
, name
) == 0)
4238 if (context
== DEBUG_TYPE_NULL
)
4240 /* We have to fall back on finding the type by name.
4241 If there are more types to come, then this must
4242 be a class. Otherwise, it could be anything. */
4244 if (qualifiers
== 0)
4248 name
= savestring (*pp
, len
);
4249 context
= debug_find_named_type (minfo
->dhandle
,
4254 if (context
== DEBUG_TYPE_NULL
)
4256 context
= stab_find_tagged_type (minfo
->dhandle
,
4260 ? DEBUG_KIND_ILLEGAL
4261 : DEBUG_KIND_CLASS
));
4262 if (context
== DEBUG_TYPE_NULL
)
4278 /* Demangle a template. If PNAME is not NULL, this sets *PNAME to a
4279 string representation of the template. */
4282 stab_demangle_template (minfo
, pp
, pname
)
4283 struct stab_demangle_info
*minfo
;
4294 /* Skip the template name. */
4295 r
= stab_demangle_count (pp
);
4296 if (r
== 0 || strlen (*pp
) < r
)
4298 stab_bad_demangle (orig
);
4303 /* Get the size of the parameter list. */
4304 if (stab_demangle_get_count (pp
, &r
) == 0)
4306 stab_bad_demangle (orig
);
4310 for (i
= 0; i
< r
; i
++)
4314 /* This is a type parameter. */
4316 if (! stab_demangle_type (minfo
, pp
, (debug_type
*) NULL
))
4322 boolean pointerp
, realp
, integralp
, charp
, boolp
;
4333 /* This is a value parameter. */
4335 if (! stab_demangle_type (minfo
, pp
, (debug_type
*) NULL
))
4338 while (*old_p
!= '\0' && ! done
)
4348 case 'C': /* Const. */
4349 case 'S': /* Signed. */
4350 case 'U': /* Unsigned. */
4351 case 'V': /* Volatile. */
4352 case 'F': /* Function. */
4353 case 'M': /* Member function. */
4357 case 'Q': /* Qualified name. */
4361 case 'T': /* Remembered type. */
4363 case 'v': /* Void. */
4365 case 'x': /* Long long. */
4366 case 'l': /* Long. */
4367 case 'i': /* Int. */
4368 case 's': /* Short. */
4369 case 'w': /* Wchar_t. */
4373 case 'b': /* Bool. */
4377 case 'c': /* Char. */
4381 case 'r': /* Long double. */
4382 case 'd': /* Double. */
4383 case 'f': /* Float. */
4388 /* Assume it's a user defined integral type. */
4399 while (ISDIGIT (**pp
))
4408 val
= stab_demangle_count (pp
);
4411 stab_bad_demangle (orig
);
4419 val
= stab_demangle_count (pp
);
4420 if (val
!= 0 && val
!= 1)
4422 stab_bad_demangle (orig
);
4430 while (ISDIGIT (**pp
))
4435 while (ISDIGIT (**pp
))
4441 while (ISDIGIT (**pp
))
4449 if (! stab_demangle_get_count (pp
, &len
))
4451 stab_bad_demangle (orig
);
4459 /* We can translate this to a string fairly easily by invoking the
4460 regular demangling routine. */
4463 char *s1
, *s2
, *s3
, *s4
= NULL
;
4466 s1
= savestring (orig
, *pp
- orig
);
4468 s2
= concat ("NoSuchStrinG__", s1
, (const char *) NULL
);
4472 s3
= cplus_demangle (s2
, DMGL_ANSI
);
4477 s4
= strstr (s3
, "::NoSuchStrinG");
4478 if (s3
== NULL
|| s4
== NULL
)
4480 stab_bad_demangle (orig
);
4486 /* Eliminating all spaces, except those between > characters,
4487 makes it more likely that the demangled name will match the
4488 name which g++ used as the structure name. */
4489 for (from
= to
= s3
; from
!= s4
; ++from
)
4491 || (from
[1] == '>' && from
> s3
&& from
[-1] == '>'))
4494 *pname
= savestring (s3
, to
- s3
);
4502 /* Demangle a class name. */
4505 stab_demangle_class (minfo
, pp
, pstart
)
4506 struct stab_demangle_info
*minfo ATTRIBUTE_UNUSED
;
4508 const char **pstart
;
4515 n
= stab_demangle_count (pp
);
4516 if (strlen (*pp
) < n
)
4518 stab_bad_demangle (orig
);
4530 /* Demangle function arguments. If the pargs argument is not NULL, it
4531 is set to a NULL terminated array holding the arguments. */
4534 stab_demangle_args (minfo
, pp
, pargs
, pvarargs
)
4535 struct stab_demangle_info
*minfo
;
4541 unsigned int alloc
, count
;
4548 *pargs
= (debug_type
*) xmalloc (alloc
* sizeof **pargs
);
4553 while (**pp
!= '_' && **pp
!= '\0' && **pp
!= 'e')
4555 if (**pp
== 'N' || **pp
== 'T')
4563 if (temptype
== 'T')
4567 if (! stab_demangle_get_count (pp
, &r
))
4569 stab_bad_demangle (orig
);
4574 if (! stab_demangle_get_count (pp
, &t
))
4576 stab_bad_demangle (orig
);
4580 if (t
>= minfo
->typestring_count
)
4582 stab_bad_demangle (orig
);
4589 tem
= minfo
->typestrings
[t
].typestring
;
4590 if (! stab_demangle_arg (minfo
, &tem
, pargs
, &count
, &alloc
))
4596 if (! stab_demangle_arg (minfo
, pp
, pargs
, &count
, &alloc
))
4602 (*pargs
)[count
] = DEBUG_TYPE_NULL
;
4614 /* Demangle a single argument. */
4617 stab_demangle_arg (minfo
, pp
, pargs
, pcount
, palloc
)
4618 struct stab_demangle_info
*minfo
;
4621 unsigned int *pcount
;
4622 unsigned int *palloc
;
4628 if (! stab_demangle_type (minfo
, pp
,
4629 pargs
== NULL
? (debug_type
*) NULL
: &type
)
4630 || ! stab_demangle_remember_type (minfo
, start
, *pp
- start
))
4635 if (type
== DEBUG_TYPE_NULL
)
4638 if (*pcount
+ 1 >= *palloc
)
4641 *pargs
= ((debug_type
*)
4642 xrealloc (*pargs
, *palloc
* sizeof **pargs
));
4644 (*pargs
)[*pcount
] = type
;
4651 /* Demangle a type. If the ptype argument is not NULL, *ptype is set
4652 to the newly allocated type. */
4655 stab_demangle_type (minfo
, pp
, ptype
)
4656 struct stab_demangle_info
*minfo
;
4668 /* A pointer type. */
4670 if (! stab_demangle_type (minfo
, pp
, ptype
))
4673 *ptype
= debug_make_pointer_type (minfo
->dhandle
, *ptype
);
4677 /* A reference type. */
4679 if (! stab_demangle_type (minfo
, pp
, ptype
))
4682 *ptype
= debug_make_reference_type (minfo
->dhandle
, *ptype
);
4692 while (**pp
!= '\0' && **pp
!= '_')
4694 if (! ISDIGIT (**pp
))
4696 stab_bad_demangle (orig
);
4705 stab_bad_demangle (orig
);
4710 if (! stab_demangle_type (minfo
, pp
, ptype
))
4714 debug_type int_type
;
4716 int_type
= debug_find_named_type (minfo
->dhandle
, "int");
4717 if (int_type
== NULL
)
4718 int_type
= debug_make_int_type (minfo
->dhandle
, 4, false);
4719 *ptype
= debug_make_array_type (minfo
->dhandle
, *ptype
, int_type
,
4726 /* A back reference to a remembered type. */
4732 if (! stab_demangle_get_count (pp
, &i
))
4734 stab_bad_demangle (orig
);
4737 if (i
>= minfo
->typestring_count
)
4739 stab_bad_demangle (orig
);
4742 p
= minfo
->typestrings
[i
].typestring
;
4743 if (! stab_demangle_type (minfo
, &p
, ptype
))
4755 if (! stab_demangle_args (minfo
, pp
,
4757 ? (debug_type
**) NULL
4765 /* cplus_demangle will accept a function without a return
4766 type, but I don't know when that will happen, or what
4767 to do if it does. */
4768 stab_bad_demangle (orig
);
4772 if (! stab_demangle_type (minfo
, pp
, ptype
))
4775 *ptype
= debug_make_function_type (minfo
->dhandle
, *ptype
, args
,
4784 boolean memberp
, constp
, volatilep
;
4785 debug_type class_type
= DEBUG_TYPE_NULL
;
4791 memberp
= **pp
== 'M';
4800 n
= stab_demangle_count (pp
);
4801 if (strlen (*pp
) < n
)
4803 stab_bad_demangle (orig
);
4811 class_type
= stab_find_tagged_type (minfo
->dhandle
,
4815 if (class_type
== DEBUG_TYPE_NULL
)
4819 else if (**pp
== 'Q')
4821 if (! stab_demangle_qualified (minfo
, pp
,
4823 ? (debug_type
*) NULL
4829 stab_bad_demangle (orig
);
4840 else if (**pp
== 'V')
4847 stab_bad_demangle (orig
);
4851 if (! stab_demangle_args (minfo
, pp
,
4853 ? (debug_type
**) NULL
4863 stab_bad_demangle (orig
);
4868 if (! stab_demangle_type (minfo
, pp
, ptype
))
4874 *ptype
= debug_make_offset_type (minfo
->dhandle
, class_type
,
4878 /* FIXME: We have no way to record constp or
4880 *ptype
= debug_make_method_type (minfo
->dhandle
, *ptype
,
4881 class_type
, args
, varargs
);
4889 if (! stab_demangle_type (minfo
, pp
, ptype
))
4895 if (! stab_demangle_type (minfo
, pp
, ptype
))
4898 *ptype
= debug_make_const_type (minfo
->dhandle
, *ptype
);
4906 if (! stab_demangle_qualified (minfo
, pp
, ptype
))
4912 if (! stab_demangle_fund_type (minfo
, pp
, ptype
))
4920 /* Demangle a fundamental type. If the ptype argument is not NULL,
4921 *ptype is set to the newly allocated type. */
4924 stab_demangle_fund_type (minfo
, pp
, ptype
)
4925 struct stab_demangle_info
*minfo
;
4930 boolean constp
, volatilep
, unsignedp
, signedp
;
4975 /* cplus_demangle permits this, but I don't know what it means. */
4976 stab_bad_demangle (orig
);
4979 case 'v': /* void */
4982 *ptype
= debug_find_named_type (minfo
->dhandle
, "void");
4983 if (*ptype
== DEBUG_TYPE_NULL
)
4984 *ptype
= debug_make_void_type (minfo
->dhandle
);
4989 case 'x': /* long long */
4992 *ptype
= debug_find_named_type (minfo
->dhandle
,
4994 ? "long long unsigned int"
4995 : "long long int"));
4996 if (*ptype
== DEBUG_TYPE_NULL
)
4997 *ptype
= debug_make_int_type (minfo
->dhandle
, 8, unsignedp
);
5002 case 'l': /* long */
5005 *ptype
= debug_find_named_type (minfo
->dhandle
,
5007 ? "long unsigned int"
5009 if (*ptype
== DEBUG_TYPE_NULL
)
5010 *ptype
= debug_make_int_type (minfo
->dhandle
, 4, unsignedp
);
5018 *ptype
= debug_find_named_type (minfo
->dhandle
,
5022 if (*ptype
== DEBUG_TYPE_NULL
)
5023 *ptype
= debug_make_int_type (minfo
->dhandle
, 4, unsignedp
);
5028 case 's': /* short */
5031 *ptype
= debug_find_named_type (minfo
->dhandle
,
5033 ? "short unsigned int"
5035 if (*ptype
== DEBUG_TYPE_NULL
)
5036 *ptype
= debug_make_int_type (minfo
->dhandle
, 2, unsignedp
);
5041 case 'b': /* bool */
5044 *ptype
= debug_find_named_type (minfo
->dhandle
, "bool");
5045 if (*ptype
== DEBUG_TYPE_NULL
)
5046 *ptype
= debug_make_bool_type (minfo
->dhandle
, 4);
5051 case 'c': /* char */
5054 *ptype
= debug_find_named_type (minfo
->dhandle
,
5060 if (*ptype
== DEBUG_TYPE_NULL
)
5061 *ptype
= debug_make_int_type (minfo
->dhandle
, 1, unsignedp
);
5066 case 'w': /* wchar_t */
5069 *ptype
= debug_find_named_type (minfo
->dhandle
, "__wchar_t");
5070 if (*ptype
== DEBUG_TYPE_NULL
)
5071 *ptype
= debug_make_int_type (minfo
->dhandle
, 2, true);
5076 case 'r': /* long double */
5079 *ptype
= debug_find_named_type (minfo
->dhandle
, "long double");
5080 if (*ptype
== DEBUG_TYPE_NULL
)
5081 *ptype
= debug_make_float_type (minfo
->dhandle
, 8);
5086 case 'd': /* double */
5089 *ptype
= debug_find_named_type (minfo
->dhandle
, "double");
5090 if (*ptype
== DEBUG_TYPE_NULL
)
5091 *ptype
= debug_make_float_type (minfo
->dhandle
, 8);
5096 case 'f': /* float */
5099 *ptype
= debug_find_named_type (minfo
->dhandle
, "float");
5100 if (*ptype
== DEBUG_TYPE_NULL
)
5101 *ptype
= debug_make_float_type (minfo
->dhandle
, 4);
5108 if (! ISDIGIT (**pp
))
5110 stab_bad_demangle (orig
);
5114 case '0': case '1': case '2': case '3': case '4':
5115 case '5': case '6': case '7': case '8': case '9':
5119 if (! stab_demangle_class (minfo
, pp
, &hold
))
5125 name
= savestring (hold
, *pp
- hold
);
5126 *ptype
= debug_find_named_type (minfo
->dhandle
, name
);
5128 if (*ptype
== DEBUG_TYPE_NULL
)
5130 /* FIXME: It is probably incorrect to assume that
5131 undefined types are tagged types. */
5132 *ptype
= stab_find_tagged_type (minfo
->dhandle
, minfo
->info
,
5134 DEBUG_KIND_ILLEGAL
);
5135 if (*ptype
== DEBUG_TYPE_NULL
)
5146 if (! stab_demangle_template (minfo
, pp
,
5147 ptype
!= NULL
? &name
: NULL
))
5151 *ptype
= stab_find_tagged_type (minfo
->dhandle
, minfo
->info
,
5152 name
, strlen (name
),
5155 if (*ptype
== DEBUG_TYPE_NULL
)
5162 stab_bad_demangle (orig
);
5169 *ptype
= debug_make_const_type (minfo
->dhandle
, *ptype
);
5171 *ptype
= debug_make_volatile_type (minfo
->dhandle
, *ptype
);
5177 /* Remember a type string in a demangled string. */
5180 stab_demangle_remember_type (minfo
, p
, len
)
5181 struct stab_demangle_info
*minfo
;
5185 if (minfo
->typestring_count
>= minfo
->typestring_alloc
)
5187 minfo
->typestring_alloc
+= 10;
5188 minfo
->typestrings
= ((struct stab_demangle_typestring
*)
5189 xrealloc (minfo
->typestrings
,
5190 (minfo
->typestring_alloc
5191 * sizeof *minfo
->typestrings
)));
5194 minfo
->typestrings
[minfo
->typestring_count
].typestring
= p
;
5195 minfo
->typestrings
[minfo
->typestring_count
].len
= (unsigned int) len
;
5196 ++minfo
->typestring_count
;