1 /* stabs.c -- Parse stabs debugging information
2 Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
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
*, unsigned int));
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
;
2911 unsigned int physname_len
= 0;
2913 /* Constructors are sometimes handled specially. */
2914 is_full_physname_constructor
= ((argtypes
[0] == '_'
2915 && argtypes
[1] == '_'
2916 && (ISDIGIT (argtypes
[2])
2917 || argtypes
[2] == 'Q'
2918 || argtypes
[2] == 't'))
2919 || strncmp (argtypes
, "__ct", 4) == 0);
2921 is_constructor
= (is_full_physname_constructor
2923 && strcmp (fieldname
, tagname
) == 0));
2924 is_destructor
= ((argtypes
[0] == '_'
2925 && (argtypes
[1] == '$' || argtypes
[1] == '.')
2926 && argtypes
[2] == '_')
2927 || strncmp (argtypes
, "__dt", 4) == 0);
2929 if (is_destructor
|| is_full_physname_constructor
)
2930 *pphysname
= argtypes
;
2934 const char *const_prefix
;
2935 const char *volatile_prefix
;
2937 unsigned int mangled_name_len
;
2940 len
= tagname
== NULL
? 0 : strlen (tagname
);
2941 const_prefix
= constp
? "C" : "";
2942 volatile_prefix
= volatilep
? "V" : "";
2945 sprintf (buf
, "__%s%s", const_prefix
, volatile_prefix
);
2946 else if (tagname
!= NULL
&& strchr (tagname
, '<') != NULL
)
2948 /* Template methods are fully mangled. */
2949 sprintf (buf
, "__%s%s", const_prefix
, volatile_prefix
);
2954 sprintf (buf
, "__%s%s%d", const_prefix
, volatile_prefix
, len
);
2956 mangled_name_len
= ((is_constructor
? 0 : strlen (fieldname
))
2962 if (fieldname
[0] == 'o'
2963 && fieldname
[1] == 'p'
2964 && (fieldname
[2] == '$' || fieldname
[2] == '.'))
2968 opname
= cplus_mangle_opname (fieldname
+ 3, 0);
2971 fprintf (stderr
, _("No mangling for \"%s\"\n"), fieldname
);
2972 return DEBUG_TYPE_NULL
;
2974 mangled_name_len
+= strlen (opname
);
2975 physname
= (char *) xmalloc (mangled_name_len
);
2976 strncpy (physname
, fieldname
, 3);
2977 strcpy (physname
+ 3, opname
);
2981 physname
= (char *) xmalloc (mangled_name_len
);
2985 strcpy (physname
, fieldname
);
2988 physname_len
= strlen (physname
);
2989 strcat (physname
, buf
);
2990 if (tagname
!= NULL
)
2991 strcat (physname
, tagname
);
2992 strcat (physname
, argtypes
);
2994 *pphysname
= physname
;
2997 if (*argtypes
== '\0' || is_destructor
)
2999 args
= (debug_type
*) xmalloc (sizeof *args
);
3001 return debug_make_method_type (dhandle
, return_type
, class_type
, args
,
3005 args
= stab_demangle_argtypes (dhandle
, info
, *pphysname
, &varargs
, physname_len
);
3007 return DEBUG_TYPE_NULL
;
3009 return debug_make_method_type (dhandle
, return_type
, class_type
, args
,
3013 /* The tail end of stabs for C++ classes that contain a virtual function
3014 pointer contains a tilde, a %, and a type number.
3015 The type number refers to the base class (possibly this class itself) which
3016 contains the vtable pointer for the current class.
3018 This function is called when we have parsed all the method declarations,
3019 so we can look for the vptr base class info. */
3022 parse_stab_tilde_field (dhandle
, info
, pp
, typenums
, retvptrbase
, retownvptr
)
3024 struct stab_handle
*info
;
3026 const int *typenums
;
3027 debug_type
*retvptrbase
;
3028 boolean
*retownvptr
;
3034 *retvptrbase
= DEBUG_TYPE_NULL
;
3035 *retownvptr
= false;
3039 /* If we are positioned at a ';', then skip it. */
3048 if (**pp
== '=' || **pp
== '+' || **pp
== '-')
3050 /* Obsolete flags that used to indicate the presence of
3051 constructors and/or destructors. */
3062 /* The next number is the type number of the base class (possibly
3063 our own class) which supplies the vtable for this class. */
3064 if (! parse_stab_type_number (pp
, vtypenums
))
3067 if (vtypenums
[0] == typenums
[0]
3068 && vtypenums
[1] == typenums
[1])
3077 vtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
3078 (debug_type
**) NULL
);
3079 for (p
= *pp
; *p
!= ';' && *p
!= '\0'; p
++)
3087 *retvptrbase
= vtype
;
3095 /* Read a definition of an array type. */
3098 parse_stab_array_type (dhandle
, info
, pp
, stringp
)
3100 struct stab_handle
*info
;
3107 debug_type index_type
;
3109 bfd_signed_vma lower
, upper
;
3110 debug_type element_type
;
3112 /* Format of an array type:
3113 "ar<index type>;lower;upper;<array_contents_type>".
3114 OS9000: "arlower,upper;<array_contents_type>".
3116 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
3117 for these, produce a type like float[][]. */
3121 /* FIXME: gdb checks os9k_stabs here. */
3123 /* If the index type is type 0, we take it as int. */
3125 if (! parse_stab_type_number (&p
, typenums
))
3126 return DEBUG_TYPE_NULL
;
3127 if (typenums
[0] == 0 && typenums
[1] == 0 && **pp
!= '=')
3129 index_type
= debug_find_named_type (dhandle
, "int");
3130 if (index_type
== DEBUG_TYPE_NULL
)
3132 index_type
= debug_make_int_type (dhandle
, 4, false);
3133 if (index_type
== DEBUG_TYPE_NULL
)
3134 return DEBUG_TYPE_NULL
;
3140 index_type
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
3141 (debug_type
**) NULL
);
3147 return DEBUG_TYPE_NULL
;
3153 if (! ISDIGIT (**pp
) && **pp
!= '-')
3159 lower
= (bfd_signed_vma
) parse_number (pp
, (boolean
*) NULL
);
3163 return DEBUG_TYPE_NULL
;
3167 if (! ISDIGIT (**pp
) && **pp
!= '-')
3173 upper
= (bfd_signed_vma
) parse_number (pp
, (boolean
*) NULL
);
3177 return DEBUG_TYPE_NULL
;
3181 element_type
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
3182 (debug_type
**) NULL
);
3183 if (element_type
== DEBUG_TYPE_NULL
)
3184 return DEBUG_TYPE_NULL
;
3192 return debug_make_array_type (dhandle
, element_type
, index_type
, lower
,
3196 /* This struct holds information about files we have seen using
3201 /* The next N_BINCL file. */
3202 struct bincl_file
*next
;
3203 /* The next N_BINCL on the stack. */
3204 struct bincl_file
*next_stack
;
3205 /* The file name. */
3207 /* The hash value. */
3209 /* The file index. */
3211 /* The list of types defined in this file. */
3212 struct stab_types
*file_types
;
3215 /* Start a new N_BINCL file, pushing it onto the stack. */
3218 push_bincl (info
, name
, hash
)
3219 struct stab_handle
*info
;
3223 struct bincl_file
*n
;
3225 n
= (struct bincl_file
*) xmalloc (sizeof *n
);
3226 n
->next
= info
->bincl_list
;
3227 n
->next_stack
= info
->bincl_stack
;
3230 n
->file
= info
->files
;
3231 n
->file_types
= NULL
;
3232 info
->bincl_list
= n
;
3233 info
->bincl_stack
= n
;
3236 info
->file_types
= ((struct stab_types
**)
3237 xrealloc ((PTR
) info
->file_types
,
3239 * sizeof *info
->file_types
)));
3240 info
->file_types
[n
->file
] = NULL
;
3243 /* Finish an N_BINCL file, at an N_EINCL, popping the name off the
3248 struct stab_handle
*info
;
3250 struct bincl_file
*o
;
3252 o
= info
->bincl_stack
;
3254 return info
->main_filename
;
3255 info
->bincl_stack
= o
->next_stack
;
3257 o
->file_types
= info
->file_types
[o
->file
];
3259 if (info
->bincl_stack
== NULL
)
3260 return info
->main_filename
;
3261 return info
->bincl_stack
->name
;
3264 /* Handle an N_EXCL: get the types from the corresponding N_BINCL. */
3267 find_excl (info
, name
, hash
)
3268 struct stab_handle
*info
;
3272 struct bincl_file
*l
;
3275 info
->file_types
= ((struct stab_types
**)
3276 xrealloc ((PTR
) info
->file_types
,
3278 * sizeof *info
->file_types
)));
3280 for (l
= info
->bincl_list
; l
!= NULL
; l
= l
->next
)
3281 if (l
->hash
== hash
&& strcmp (l
->name
, name
) == 0)
3285 warn_stab (name
, _("Undefined N_EXCL"));
3286 info
->file_types
[info
->files
- 1] = NULL
;
3290 info
->file_types
[info
->files
- 1] = l
->file_types
;
3295 /* Handle a variable definition. gcc emits variable definitions for a
3296 block before the N_LBRAC, so we must hold onto them until we see
3297 it. The SunPRO compiler emits variable definitions after the
3298 N_LBRAC, so we can call debug_record_variable immediately. */
3301 stab_record_variable (dhandle
, info
, name
, type
, kind
, val
)
3303 struct stab_handle
*info
;
3306 enum debug_var_kind kind
;
3309 struct stab_pending_var
*v
;
3311 if ((kind
== DEBUG_GLOBAL
|| kind
== DEBUG_STATIC
)
3312 || ! info
->within_function
3313 || (info
->gcc_compiled
== 0 && info
->n_opt_found
))
3314 return debug_record_variable (dhandle
, name
, type
, kind
, val
);
3316 v
= (struct stab_pending_var
*) xmalloc (sizeof *v
);
3317 memset (v
, 0, sizeof *v
);
3319 v
->next
= info
->pending
;
3329 /* Emit pending variable definitions. This is called after we see the
3330 N_LBRAC that starts the block. */
3333 stab_emit_pending_vars (dhandle
, info
)
3335 struct stab_handle
*info
;
3337 struct stab_pending_var
*v
;
3342 struct stab_pending_var
*next
;
3344 if (! debug_record_variable (dhandle
, v
->name
, v
->type
, v
->kind
, v
->val
))
3352 info
->pending
= NULL
;
3357 /* Find the slot for a type in the database. */
3360 stab_find_slot (info
, typenums
)
3361 struct stab_handle
*info
;
3362 const int *typenums
;
3366 struct stab_types
**ps
;
3368 filenum
= typenums
[0];
3369 index
= typenums
[1];
3371 if (filenum
< 0 || (unsigned int) filenum
>= info
->files
)
3373 fprintf (stderr
, _("Type file number %d out of range\n"), filenum
);
3378 fprintf (stderr
, _("Type index number %d out of range\n"), index
);
3382 ps
= info
->file_types
+ filenum
;
3384 while (index
>= STAB_TYPES_SLOTS
)
3388 *ps
= (struct stab_types
*) xmalloc (sizeof **ps
);
3389 memset (*ps
, 0, sizeof **ps
);
3392 index
-= STAB_TYPES_SLOTS
;
3396 *ps
= (struct stab_types
*) xmalloc (sizeof **ps
);
3397 memset (*ps
, 0, sizeof **ps
);
3400 return (*ps
)->types
+ index
;
3403 /* Find a type given a type number. If the type has not been
3404 allocated yet, create an indirect type. */
3407 stab_find_type (dhandle
, info
, typenums
)
3409 struct stab_handle
*info
;
3410 const int *typenums
;
3414 if (typenums
[0] == 0 && typenums
[1] < 0)
3416 /* A negative type number indicates an XCOFF builtin type. */
3417 return stab_xcoff_builtin_type (dhandle
, info
, typenums
[1]);
3420 slot
= stab_find_slot (info
, typenums
);
3422 return DEBUG_TYPE_NULL
;
3424 if (*slot
== DEBUG_TYPE_NULL
)
3425 return debug_make_indirect_type (dhandle
, slot
, (const char *) NULL
);
3430 /* Record that a given type number refers to a given type. */
3433 stab_record_type (dhandle
, info
, typenums
, type
)
3434 PTR dhandle ATTRIBUTE_UNUSED
;
3435 struct stab_handle
*info
;
3436 const int *typenums
;
3441 slot
= stab_find_slot (info
, typenums
);
3445 /* gdb appears to ignore type redefinitions, so we do as well. */
3452 /* Return an XCOFF builtin type. */
3455 stab_xcoff_builtin_type (dhandle
, info
, typenum
)
3457 struct stab_handle
*info
;
3463 if (typenum
>= 0 || typenum
< -XCOFF_TYPE_COUNT
)
3465 fprintf (stderr
, _("Unrecognized XCOFF type %d\n"), typenum
);
3466 return DEBUG_TYPE_NULL
;
3468 if (info
->xcoff_types
[-typenum
] != NULL
)
3469 return info
->xcoff_types
[-typenum
];
3474 /* The size of this and all the other types are fixed, defined
3475 by the debugging format. */
3477 rettype
= debug_make_int_type (dhandle
, 4, false);
3481 rettype
= debug_make_int_type (dhandle
, 1, false);
3485 rettype
= debug_make_int_type (dhandle
, 2, false);
3489 rettype
= debug_make_int_type (dhandle
, 4, false);
3492 name
= "unsigned char";
3493 rettype
= debug_make_int_type (dhandle
, 1, true);
3496 name
= "signed char";
3497 rettype
= debug_make_int_type (dhandle
, 1, false);
3500 name
= "unsigned short";
3501 rettype
= debug_make_int_type (dhandle
, 2, true);
3504 name
= "unsigned int";
3505 rettype
= debug_make_int_type (dhandle
, 4, true);
3509 rettype
= debug_make_int_type (dhandle
, 4, true);
3511 name
= "unsigned long";
3512 rettype
= debug_make_int_type (dhandle
, 4, true);
3516 rettype
= debug_make_void_type (dhandle
);
3519 /* IEEE single precision (32 bit). */
3521 rettype
= debug_make_float_type (dhandle
, 4);
3524 /* IEEE double precision (64 bit). */
3526 rettype
= debug_make_float_type (dhandle
, 8);
3529 /* This is an IEEE double on the RS/6000, and different machines
3530 with different sizes for "long double" should use different
3531 negative type numbers. See stabs.texinfo. */
3532 name
= "long double";
3533 rettype
= debug_make_float_type (dhandle
, 8);
3537 rettype
= debug_make_int_type (dhandle
, 4, false);
3541 rettype
= debug_make_bool_type (dhandle
, 4);
3544 name
= "short real";
3545 rettype
= debug_make_float_type (dhandle
, 4);
3549 rettype
= debug_make_float_type (dhandle
, 8);
3559 rettype
= debug_make_int_type (dhandle
, 1, true);
3563 rettype
= debug_make_bool_type (dhandle
, 1);
3567 rettype
= debug_make_bool_type (dhandle
, 2);
3571 rettype
= debug_make_bool_type (dhandle
, 4);
3575 rettype
= debug_make_bool_type (dhandle
, 4);
3578 /* Complex type consisting of two IEEE single precision values. */
3580 rettype
= debug_make_complex_type (dhandle
, 8);
3583 /* Complex type consisting of two IEEE double precision values. */
3584 name
= "double complex";
3585 rettype
= debug_make_complex_type (dhandle
, 16);
3589 rettype
= debug_make_int_type (dhandle
, 1, false);
3593 rettype
= debug_make_int_type (dhandle
, 2, false);
3597 rettype
= debug_make_int_type (dhandle
, 4, false);
3602 rettype
= debug_make_int_type (dhandle
, 2, false);
3606 rettype
= debug_make_int_type (dhandle
, 8, false);
3609 name
= "unsigned long long";
3610 rettype
= debug_make_int_type (dhandle
, 8, true);
3614 rettype
= debug_make_bool_type (dhandle
, 8);
3618 rettype
= debug_make_int_type (dhandle
, 8, false);
3624 rettype
= debug_name_type (dhandle
, name
, rettype
);
3626 info
->xcoff_types
[-typenum
] = rettype
;
3631 /* Find or create a tagged type. */
3634 stab_find_tagged_type (dhandle
, info
, p
, len
, kind
)
3636 struct stab_handle
*info
;
3639 enum debug_type_kind kind
;
3643 struct stab_tag
*st
;
3645 name
= savestring (p
, len
);
3647 /* We pass DEBUG_KIND_ILLEGAL because we want all tags in the same
3648 namespace. This is right for C, and I don't know how to handle
3649 other languages. FIXME. */
3650 dtype
= debug_find_tagged_type (dhandle
, name
, DEBUG_KIND_ILLEGAL
);
3651 if (dtype
!= DEBUG_TYPE_NULL
)
3657 /* We need to allocate an entry on the undefined tag list. */
3658 for (st
= info
->tags
; st
!= NULL
; st
= st
->next
)
3660 if (st
->name
[0] == name
[0]
3661 && strcmp (st
->name
, name
) == 0)
3663 if (st
->kind
== DEBUG_KIND_ILLEGAL
)
3671 st
= (struct stab_tag
*) xmalloc (sizeof *st
);
3672 memset (st
, 0, sizeof *st
);
3674 st
->next
= info
->tags
;
3677 st
->slot
= DEBUG_TYPE_NULL
;
3678 st
->type
= debug_make_indirect_type (dhandle
, &st
->slot
, name
);
3685 /* In order to get the correct argument types for a stubbed method, we
3686 need to extract the argument types from a C++ mangled string.
3687 Since the argument types can refer back to the return type, this
3688 means that we must demangle the entire physical name. In gdb this
3689 is done by calling cplus_demangle and running the results back
3690 through the C++ expression parser. Since we have no expression
3691 parser, we must duplicate much of the work of cplus_demangle here.
3693 We assume that GNU style demangling is used, since this is only
3694 done for method stubs, and only g++ should output that form of
3695 debugging information. */
3697 /* This structure is used to hold a pointer to type information which
3698 demangling a string. */
3700 struct stab_demangle_typestring
3702 /* The start of the type. This is not null terminated. */
3703 const char *typestring
;
3704 /* The length of the type. */
3708 /* This structure is used to hold information while demangling a
3711 struct stab_demangle_info
3713 /* The debugging information handle. */
3715 /* The stab information handle. */
3716 struct stab_handle
*info
;
3717 /* The array of arguments we are building. */
3719 /* Whether the method takes a variable number of arguments. */
3721 /* The array of types we have remembered. */
3722 struct stab_demangle_typestring
*typestrings
;
3723 /* The number of typestrings. */
3724 unsigned int typestring_count
;
3725 /* The number of typestring slots we have allocated. */
3726 unsigned int typestring_alloc
;
3729 static void stab_bad_demangle
PARAMS ((const char *));
3730 static unsigned int stab_demangle_count
PARAMS ((const char **));
3731 static boolean stab_demangle_get_count
3732 PARAMS ((const char **, unsigned int *));
3733 static boolean stab_demangle_prefix
3734 PARAMS ((struct stab_demangle_info
*, const char **, unsigned int));
3735 static boolean stab_demangle_function_name
3736 PARAMS ((struct stab_demangle_info
*, const char **, const char *));
3737 static boolean stab_demangle_signature
3738 PARAMS ((struct stab_demangle_info
*, const char **));
3739 static boolean stab_demangle_qualified
3740 PARAMS ((struct stab_demangle_info
*, const char **, debug_type
*));
3741 static boolean stab_demangle_template
3742 PARAMS ((struct stab_demangle_info
*, const char **, char **));
3743 static boolean stab_demangle_class
3744 PARAMS ((struct stab_demangle_info
*, const char **, const char **));
3745 static boolean stab_demangle_args
3746 PARAMS ((struct stab_demangle_info
*, const char **, debug_type
**,
3748 static boolean stab_demangle_arg
3749 PARAMS ((struct stab_demangle_info
*, const char **, debug_type
**,
3750 unsigned int *, unsigned int *));
3751 static boolean stab_demangle_type
3752 PARAMS ((struct stab_demangle_info
*, const char **, debug_type
*));
3753 static boolean stab_demangle_fund_type
3754 PARAMS ((struct stab_demangle_info
*, const char **, debug_type
*));
3755 static boolean stab_demangle_remember_type
3756 PARAMS ((struct stab_demangle_info
*, const char *, int));
3758 /* Warn about a bad demangling. */
3761 stab_bad_demangle (s
)
3764 fprintf (stderr
, _("bad mangled name `%s'\n"), s
);
3767 /* Get a count from a stab string. */
3770 stab_demangle_count (pp
)
3776 while (ISDIGIT (**pp
))
3779 count
+= **pp
- '0';
3785 /* Require a count in a string. The count may be multiple digits, in
3786 which case it must end in an underscore. */
3789 stab_demangle_get_count (pp
, pi
)
3793 if (! ISDIGIT (**pp
))
3811 while (ISDIGIT (*p
));
3822 /* This function demangles a physical name, returning a NULL
3823 terminated array of argument types. */
3826 stab_demangle_argtypes (dhandle
, info
, physname
, pvarargs
, physname_len
)
3828 struct stab_handle
*info
;
3829 const char *physname
;
3831 unsigned int physname_len
;
3833 struct stab_demangle_info minfo
;
3835 minfo
.dhandle
= dhandle
;
3838 minfo
.varargs
= false;
3839 minfo
.typestring_alloc
= 10;
3840 minfo
.typestrings
= ((struct stab_demangle_typestring
*)
3841 xmalloc (minfo
.typestring_alloc
3842 * sizeof *minfo
.typestrings
));
3843 minfo
.typestring_count
= 0;
3845 /* cplus_demangle checks for special GNU mangled forms, but we can't
3846 see any of them in mangled method argument types. */
3848 if (! stab_demangle_prefix (&minfo
, &physname
, physname_len
))
3851 if (*physname
!= '\0')
3853 if (! stab_demangle_signature (&minfo
, &physname
))
3857 free (minfo
.typestrings
);
3858 minfo
.typestrings
= NULL
;
3860 if (minfo
.args
== NULL
)
3861 fprintf (stderr
, _("no argument types in mangled string\n"));
3863 *pvarargs
= minfo
.varargs
;
3867 if (minfo
.typestrings
!= NULL
)
3868 free (minfo
.typestrings
);
3872 /* Demangle the prefix of the mangled name. */
3875 stab_demangle_prefix (minfo
, pp
, physname_len
)
3876 struct stab_demangle_info
*minfo
;
3878 unsigned int physname_len
;
3883 /* cplus_demangle checks for global constructors and destructors,
3884 but we can't see them in mangled argument types. */
3887 scan
= *pp
+ physname_len
;
3890 /* Look for `__'. */
3893 scan
= strchr (scan
, '_');
3894 while (scan
!= NULL
&& *++scan
!= '_');
3898 stab_bad_demangle (*pp
);
3904 /* We found `__'; move ahead to the last contiguous `__' pair. */
3905 i
= strspn (scan
, "_");
3911 && (ISDIGIT (scan
[2])
3915 /* This is a GNU style constructor name. */
3919 else if (scan
== *pp
3920 && ! ISDIGIT (scan
[2])
3923 /* Look for the `__' that separates the prefix from the
3925 while (*scan
== '_')
3927 scan
= strstr (scan
, "__");
3928 if (scan
== NULL
|| scan
[2] == '\0')
3930 stab_bad_demangle (*pp
);
3934 return stab_demangle_function_name (minfo
, pp
, scan
);
3936 else if (scan
[2] != '\0')
3938 /* The name doesn't start with `__', but it does contain `__'. */
3939 return stab_demangle_function_name (minfo
, pp
, scan
);
3943 stab_bad_demangle (*pp
);
3949 /* Demangle a function name prefix. The scan argument points to the
3950 double underscore which separates the function name from the
3954 stab_demangle_function_name (minfo
, pp
, scan
)
3955 struct stab_demangle_info
*minfo
;
3961 /* The string from *pp to scan is the name of the function. We
3962 don't care about the name, since we just looking for argument
3963 types. However, for conversion operators, the name may include a
3964 type which we must remember in order to handle backreferences. */
3970 && strncmp (name
, "type", 4) == 0
3971 && (name
[4] == '$' || name
[4] == '.'))
3975 /* This is a type conversion operator. */
3977 if (! stab_demangle_type (minfo
, &tem
, (debug_type
*) NULL
))
3980 else if (name
[0] == '_'
3987 /* This is a type conversion operator. */
3989 if (! stab_demangle_type (minfo
, &tem
, (debug_type
*) NULL
))
3996 /* Demangle the signature. This is where the argument types are
4000 stab_demangle_signature (minfo
, pp
)
4001 struct stab_demangle_info
*minfo
;
4005 boolean expect_func
, func_done
;
4010 expect_func
= false;
4014 while (**pp
!= '\0')
4020 if (! stab_demangle_qualified (minfo
, pp
, (debug_type
*) NULL
)
4021 || ! stab_demangle_remember_type (minfo
, hold
, *pp
- hold
))
4028 /* Static member function. FIXME: Can this happen? */
4035 /* Const member function. */
4041 case '0': case '1': case '2': case '3': case '4':
4042 case '5': case '6': case '7': case '8': case '9':
4045 if (! stab_demangle_class (minfo
, pp
, (const char **) NULL
)
4046 || ! stab_demangle_remember_type (minfo
, hold
, *pp
- hold
))
4053 /* Function. I don't know if this actually happens with g++
4058 if (! stab_demangle_args (minfo
, pp
, &minfo
->args
, &minfo
->varargs
))
4066 if (! stab_demangle_template (minfo
, pp
, (char **) NULL
)
4067 || ! stab_demangle_remember_type (minfo
, hold
, *pp
- hold
))
4074 /* At the outermost level, we cannot have a return type
4075 specified, so if we run into another '_' at this point we
4076 are dealing with a mangled name that is either bogus, or
4077 has been mangled by some algorithm we don't know how to
4078 deal with. So just reject the entire demangling. */
4079 stab_bad_demangle (orig
);
4083 /* Assume we have stumbled onto the first outermost function
4084 argument token, and start processing args. */
4086 if (! stab_demangle_args (minfo
, pp
, &minfo
->args
, &minfo
->varargs
))
4094 if (! stab_demangle_args (minfo
, pp
, &minfo
->args
, &minfo
->varargs
))
4101 /* With GNU style demangling, bar__3foo is 'foo::bar(void)', and
4102 bar__3fooi is 'foo::bar(int)'. We get here when we find the
4103 first case, and need to ensure that the '(void)' gets added
4104 to the current declp. */
4105 if (! stab_demangle_args (minfo
, pp
, &minfo
->args
, &minfo
->varargs
))
4112 /* Demangle a qualified name, such as "Q25Outer5Inner" which is the
4113 mangled form of "Outer::Inner". */
4116 stab_demangle_qualified (minfo
, pp
, ptype
)
4117 struct stab_demangle_info
*minfo
;
4123 unsigned int qualifiers
;
4131 /* GNU mangled name with more than 9 classes. The count is
4132 preceded by an underscore (to distinguish it from the <= 9
4133 case) and followed by an underscore. */
4135 if (! ISDIGIT (*p
) || *p
== '0')
4137 stab_bad_demangle (orig
);
4140 qualifiers
= atoi (p
);
4141 while (ISDIGIT (*p
))
4145 stab_bad_demangle (orig
);
4151 case '1': case '2': case '3': case '4': case '5':
4152 case '6': case '7': case '8': case '9':
4153 qualifiers
= (*pp
)[1] - '0';
4154 /* Skip an optional underscore after the count. */
4155 if ((*pp
)[2] == '_')
4162 stab_bad_demangle (orig
);
4166 context
= DEBUG_TYPE_NULL
;
4168 /* Pick off the names. */
4169 while (qualifiers
-- > 0)
4177 if (! stab_demangle_template (minfo
, pp
,
4178 ptype
!= NULL
? &name
: NULL
))
4183 context
= stab_find_tagged_type (minfo
->dhandle
, minfo
->info
,
4184 name
, strlen (name
),
4187 if (context
== DEBUG_TYPE_NULL
)
4195 len
= stab_demangle_count (pp
);
4196 if (strlen (*pp
) < len
)
4198 stab_bad_demangle (orig
);
4204 const debug_field
*fields
;
4207 if (context
!= DEBUG_TYPE_NULL
)
4208 fields
= debug_get_fields (minfo
->dhandle
, context
);
4210 context
= DEBUG_TYPE_NULL
;
4216 /* Try to find the type by looking through the
4217 fields of context until we find a field with the
4218 same type. This ought to work for a class
4219 defined within a class, but it won't work for,
4220 e.g., an enum defined within a class. stabs does
4221 not give us enough information to figure out the
4224 name
= savestring (*pp
, len
);
4226 for (; *fields
!= DEBUG_FIELD_NULL
; fields
++)
4231 ft
= debug_get_field_type (minfo
->dhandle
, *fields
);
4234 dn
= debug_get_type_name (minfo
->dhandle
, ft
);
4235 if (dn
!= NULL
&& strcmp (dn
, name
) == 0)
4245 if (context
== DEBUG_TYPE_NULL
)
4247 /* We have to fall back on finding the type by name.
4248 If there are more types to come, then this must
4249 be a class. Otherwise, it could be anything. */
4251 if (qualifiers
== 0)
4255 name
= savestring (*pp
, len
);
4256 context
= debug_find_named_type (minfo
->dhandle
,
4261 if (context
== DEBUG_TYPE_NULL
)
4263 context
= stab_find_tagged_type (minfo
->dhandle
,
4267 ? DEBUG_KIND_ILLEGAL
4268 : DEBUG_KIND_CLASS
));
4269 if (context
== DEBUG_TYPE_NULL
)
4285 /* Demangle a template. If PNAME is not NULL, this sets *PNAME to a
4286 string representation of the template. */
4289 stab_demangle_template (minfo
, pp
, pname
)
4290 struct stab_demangle_info
*minfo
;
4301 /* Skip the template name. */
4302 r
= stab_demangle_count (pp
);
4303 if (r
== 0 || strlen (*pp
) < r
)
4305 stab_bad_demangle (orig
);
4310 /* Get the size of the parameter list. */
4311 if (stab_demangle_get_count (pp
, &r
) == 0)
4313 stab_bad_demangle (orig
);
4317 for (i
= 0; i
< r
; i
++)
4321 /* This is a type parameter. */
4323 if (! stab_demangle_type (minfo
, pp
, (debug_type
*) NULL
))
4329 boolean pointerp
, realp
, integralp
, charp
, boolp
;
4340 /* This is a value parameter. */
4342 if (! stab_demangle_type (minfo
, pp
, (debug_type
*) NULL
))
4345 while (*old_p
!= '\0' && ! done
)
4355 case 'C': /* Const. */
4356 case 'S': /* Signed. */
4357 case 'U': /* Unsigned. */
4358 case 'V': /* Volatile. */
4359 case 'F': /* Function. */
4360 case 'M': /* Member function. */
4364 case 'Q': /* Qualified name. */
4368 case 'T': /* Remembered type. */
4370 case 'v': /* Void. */
4372 case 'x': /* Long long. */
4373 case 'l': /* Long. */
4374 case 'i': /* Int. */
4375 case 's': /* Short. */
4376 case 'w': /* Wchar_t. */
4380 case 'b': /* Bool. */
4384 case 'c': /* Char. */
4388 case 'r': /* Long double. */
4389 case 'd': /* Double. */
4390 case 'f': /* Float. */
4395 /* Assume it's a user defined integral type. */
4406 while (ISDIGIT (**pp
))
4415 val
= stab_demangle_count (pp
);
4418 stab_bad_demangle (orig
);
4426 val
= stab_demangle_count (pp
);
4427 if (val
!= 0 && val
!= 1)
4429 stab_bad_demangle (orig
);
4437 while (ISDIGIT (**pp
))
4442 while (ISDIGIT (**pp
))
4448 while (ISDIGIT (**pp
))
4456 if (! stab_demangle_get_count (pp
, &len
))
4458 stab_bad_demangle (orig
);
4466 /* We can translate this to a string fairly easily by invoking the
4467 regular demangling routine. */
4470 char *s1
, *s2
, *s3
, *s4
= NULL
;
4473 s1
= savestring (orig
, *pp
- orig
);
4475 s2
= concat ("NoSuchStrinG__", s1
, (const char *) NULL
);
4479 s3
= cplus_demangle (s2
, DMGL_ANSI
);
4484 s4
= strstr (s3
, "::NoSuchStrinG");
4485 if (s3
== NULL
|| s4
== NULL
)
4487 stab_bad_demangle (orig
);
4493 /* Eliminating all spaces, except those between > characters,
4494 makes it more likely that the demangled name will match the
4495 name which g++ used as the structure name. */
4496 for (from
= to
= s3
; from
!= s4
; ++from
)
4498 || (from
[1] == '>' && from
> s3
&& from
[-1] == '>'))
4501 *pname
= savestring (s3
, to
- s3
);
4509 /* Demangle a class name. */
4512 stab_demangle_class (minfo
, pp
, pstart
)
4513 struct stab_demangle_info
*minfo ATTRIBUTE_UNUSED
;
4515 const char **pstart
;
4522 n
= stab_demangle_count (pp
);
4523 if (strlen (*pp
) < n
)
4525 stab_bad_demangle (orig
);
4537 /* Demangle function arguments. If the pargs argument is not NULL, it
4538 is set to a NULL terminated array holding the arguments. */
4541 stab_demangle_args (minfo
, pp
, pargs
, pvarargs
)
4542 struct stab_demangle_info
*minfo
;
4548 unsigned int alloc
, count
;
4555 *pargs
= (debug_type
*) xmalloc (alloc
* sizeof **pargs
);
4560 while (**pp
!= '_' && **pp
!= '\0' && **pp
!= 'e')
4562 if (**pp
== 'N' || **pp
== 'T')
4570 if (temptype
== 'T')
4574 if (! stab_demangle_get_count (pp
, &r
))
4576 stab_bad_demangle (orig
);
4581 if (! stab_demangle_get_count (pp
, &t
))
4583 stab_bad_demangle (orig
);
4587 if (t
>= minfo
->typestring_count
)
4589 stab_bad_demangle (orig
);
4596 tem
= minfo
->typestrings
[t
].typestring
;
4597 if (! stab_demangle_arg (minfo
, &tem
, pargs
, &count
, &alloc
))
4603 if (! stab_demangle_arg (minfo
, pp
, pargs
, &count
, &alloc
))
4609 (*pargs
)[count
] = DEBUG_TYPE_NULL
;
4621 /* Demangle a single argument. */
4624 stab_demangle_arg (minfo
, pp
, pargs
, pcount
, palloc
)
4625 struct stab_demangle_info
*minfo
;
4628 unsigned int *pcount
;
4629 unsigned int *palloc
;
4635 if (! stab_demangle_type (minfo
, pp
,
4636 pargs
== NULL
? (debug_type
*) NULL
: &type
)
4637 || ! stab_demangle_remember_type (minfo
, start
, *pp
- start
))
4642 if (type
== DEBUG_TYPE_NULL
)
4645 if (*pcount
+ 1 >= *palloc
)
4648 *pargs
= ((debug_type
*)
4649 xrealloc (*pargs
, *palloc
* sizeof **pargs
));
4651 (*pargs
)[*pcount
] = type
;
4658 /* Demangle a type. If the ptype argument is not NULL, *ptype is set
4659 to the newly allocated type. */
4662 stab_demangle_type (minfo
, pp
, ptype
)
4663 struct stab_demangle_info
*minfo
;
4675 /* A pointer type. */
4677 if (! stab_demangle_type (minfo
, pp
, ptype
))
4680 *ptype
= debug_make_pointer_type (minfo
->dhandle
, *ptype
);
4684 /* A reference type. */
4686 if (! stab_demangle_type (minfo
, pp
, ptype
))
4689 *ptype
= debug_make_reference_type (minfo
->dhandle
, *ptype
);
4699 while (**pp
!= '\0' && **pp
!= '_')
4701 if (! ISDIGIT (**pp
))
4703 stab_bad_demangle (orig
);
4712 stab_bad_demangle (orig
);
4717 if (! stab_demangle_type (minfo
, pp
, ptype
))
4721 debug_type int_type
;
4723 int_type
= debug_find_named_type (minfo
->dhandle
, "int");
4724 if (int_type
== NULL
)
4725 int_type
= debug_make_int_type (minfo
->dhandle
, 4, false);
4726 *ptype
= debug_make_array_type (minfo
->dhandle
, *ptype
, int_type
,
4733 /* A back reference to a remembered type. */
4739 if (! stab_demangle_get_count (pp
, &i
))
4741 stab_bad_demangle (orig
);
4744 if (i
>= minfo
->typestring_count
)
4746 stab_bad_demangle (orig
);
4749 p
= minfo
->typestrings
[i
].typestring
;
4750 if (! stab_demangle_type (minfo
, &p
, ptype
))
4762 if (! stab_demangle_args (minfo
, pp
,
4764 ? (debug_type
**) NULL
4772 /* cplus_demangle will accept a function without a return
4773 type, but I don't know when that will happen, or what
4774 to do if it does. */
4775 stab_bad_demangle (orig
);
4779 if (! stab_demangle_type (minfo
, pp
, ptype
))
4782 *ptype
= debug_make_function_type (minfo
->dhandle
, *ptype
, args
,
4791 boolean memberp
, constp
, volatilep
;
4792 debug_type class_type
= DEBUG_TYPE_NULL
;
4798 memberp
= **pp
== 'M';
4807 n
= stab_demangle_count (pp
);
4808 if (strlen (*pp
) < n
)
4810 stab_bad_demangle (orig
);
4818 class_type
= stab_find_tagged_type (minfo
->dhandle
,
4822 if (class_type
== DEBUG_TYPE_NULL
)
4826 else if (**pp
== 'Q')
4828 if (! stab_demangle_qualified (minfo
, pp
,
4830 ? (debug_type
*) NULL
4836 stab_bad_demangle (orig
);
4847 else if (**pp
== 'V')
4854 stab_bad_demangle (orig
);
4858 if (! stab_demangle_args (minfo
, pp
,
4860 ? (debug_type
**) NULL
4870 stab_bad_demangle (orig
);
4875 if (! stab_demangle_type (minfo
, pp
, ptype
))
4881 *ptype
= debug_make_offset_type (minfo
->dhandle
, class_type
,
4885 /* FIXME: We have no way to record constp or
4887 *ptype
= debug_make_method_type (minfo
->dhandle
, *ptype
,
4888 class_type
, args
, varargs
);
4896 if (! stab_demangle_type (minfo
, pp
, ptype
))
4902 if (! stab_demangle_type (minfo
, pp
, ptype
))
4905 *ptype
= debug_make_const_type (minfo
->dhandle
, *ptype
);
4913 if (! stab_demangle_qualified (minfo
, pp
, ptype
))
4919 if (! stab_demangle_fund_type (minfo
, pp
, ptype
))
4927 /* Demangle a fundamental type. If the ptype argument is not NULL,
4928 *ptype is set to the newly allocated type. */
4931 stab_demangle_fund_type (minfo
, pp
, ptype
)
4932 struct stab_demangle_info
*minfo
;
4937 boolean constp
, volatilep
, unsignedp
, signedp
;
4982 /* cplus_demangle permits this, but I don't know what it means. */
4983 stab_bad_demangle (orig
);
4986 case 'v': /* void */
4989 *ptype
= debug_find_named_type (minfo
->dhandle
, "void");
4990 if (*ptype
== DEBUG_TYPE_NULL
)
4991 *ptype
= debug_make_void_type (minfo
->dhandle
);
4996 case 'x': /* long long */
4999 *ptype
= debug_find_named_type (minfo
->dhandle
,
5001 ? "long long unsigned int"
5002 : "long long int"));
5003 if (*ptype
== DEBUG_TYPE_NULL
)
5004 *ptype
= debug_make_int_type (minfo
->dhandle
, 8, unsignedp
);
5009 case 'l': /* long */
5012 *ptype
= debug_find_named_type (minfo
->dhandle
,
5014 ? "long unsigned int"
5016 if (*ptype
== DEBUG_TYPE_NULL
)
5017 *ptype
= debug_make_int_type (minfo
->dhandle
, 4, unsignedp
);
5025 *ptype
= debug_find_named_type (minfo
->dhandle
,
5029 if (*ptype
== DEBUG_TYPE_NULL
)
5030 *ptype
= debug_make_int_type (minfo
->dhandle
, 4, unsignedp
);
5035 case 's': /* short */
5038 *ptype
= debug_find_named_type (minfo
->dhandle
,
5040 ? "short unsigned int"
5042 if (*ptype
== DEBUG_TYPE_NULL
)
5043 *ptype
= debug_make_int_type (minfo
->dhandle
, 2, unsignedp
);
5048 case 'b': /* bool */
5051 *ptype
= debug_find_named_type (minfo
->dhandle
, "bool");
5052 if (*ptype
== DEBUG_TYPE_NULL
)
5053 *ptype
= debug_make_bool_type (minfo
->dhandle
, 4);
5058 case 'c': /* char */
5061 *ptype
= debug_find_named_type (minfo
->dhandle
,
5067 if (*ptype
== DEBUG_TYPE_NULL
)
5068 *ptype
= debug_make_int_type (minfo
->dhandle
, 1, unsignedp
);
5073 case 'w': /* wchar_t */
5076 *ptype
= debug_find_named_type (minfo
->dhandle
, "__wchar_t");
5077 if (*ptype
== DEBUG_TYPE_NULL
)
5078 *ptype
= debug_make_int_type (minfo
->dhandle
, 2, true);
5083 case 'r': /* long double */
5086 *ptype
= debug_find_named_type (minfo
->dhandle
, "long double");
5087 if (*ptype
== DEBUG_TYPE_NULL
)
5088 *ptype
= debug_make_float_type (minfo
->dhandle
, 8);
5093 case 'd': /* double */
5096 *ptype
= debug_find_named_type (minfo
->dhandle
, "double");
5097 if (*ptype
== DEBUG_TYPE_NULL
)
5098 *ptype
= debug_make_float_type (minfo
->dhandle
, 8);
5103 case 'f': /* float */
5106 *ptype
= debug_find_named_type (minfo
->dhandle
, "float");
5107 if (*ptype
== DEBUG_TYPE_NULL
)
5108 *ptype
= debug_make_float_type (minfo
->dhandle
, 4);
5115 if (! ISDIGIT (**pp
))
5117 stab_bad_demangle (orig
);
5121 case '0': case '1': case '2': case '3': case '4':
5122 case '5': case '6': case '7': case '8': case '9':
5126 if (! stab_demangle_class (minfo
, pp
, &hold
))
5132 name
= savestring (hold
, *pp
- hold
);
5133 *ptype
= debug_find_named_type (minfo
->dhandle
, name
);
5135 if (*ptype
== DEBUG_TYPE_NULL
)
5137 /* FIXME: It is probably incorrect to assume that
5138 undefined types are tagged types. */
5139 *ptype
= stab_find_tagged_type (minfo
->dhandle
, minfo
->info
,
5141 DEBUG_KIND_ILLEGAL
);
5142 if (*ptype
== DEBUG_TYPE_NULL
)
5153 if (! stab_demangle_template (minfo
, pp
,
5154 ptype
!= NULL
? &name
: NULL
))
5158 *ptype
= stab_find_tagged_type (minfo
->dhandle
, minfo
->info
,
5159 name
, strlen (name
),
5162 if (*ptype
== DEBUG_TYPE_NULL
)
5169 stab_bad_demangle (orig
);
5176 *ptype
= debug_make_const_type (minfo
->dhandle
, *ptype
);
5178 *ptype
= debug_make_volatile_type (minfo
->dhandle
, *ptype
);
5184 /* Remember a type string in a demangled string. */
5187 stab_demangle_remember_type (minfo
, p
, len
)
5188 struct stab_demangle_info
*minfo
;
5192 if (minfo
->typestring_count
>= minfo
->typestring_alloc
)
5194 minfo
->typestring_alloc
+= 10;
5195 minfo
->typestrings
= ((struct stab_demangle_typestring
*)
5196 xrealloc (minfo
->typestrings
,
5197 (minfo
->typestring_alloc
5198 * sizeof *minfo
->typestrings
)));
5201 minfo
->typestrings
[minfo
->typestring_count
].typestring
= p
;
5202 minfo
->typestrings
[minfo
->typestring_count
].len
= (unsigned int) len
;
5203 ++minfo
->typestring_count
;