1 /* stabs.c -- Parse stabs debugging information
2 Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
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"
38 #include "aout/aout64.h"
39 #include "aout/stab_gnu.h"
41 /* The number of predefined XCOFF types. */
43 #define XCOFF_TYPE_COUNT 34
45 /* This structure is used as a handle so that the stab parsing doesn't
46 need to use any static variables. */
52 /* TRUE if this is stabs in sections. */
54 /* The symbol table. */
56 /* The number of symbols. */
58 /* The accumulated file name string. */
60 /* The value of the last N_SO symbol. */
62 /* The value of the start of the file, so that we can handle file
63 relative N_LBRAC and N_RBRAC symbols. */
64 bfd_vma file_start_offset
;
65 /* The offset of the start of the function, so that we can handle
66 function relative N_LBRAC and N_RBRAC symbols. */
67 bfd_vma function_start_offset
;
68 /* The version number of gcc which compiled the current compilation
69 unit, 0 if not compiled by gcc. */
71 /* Whether an N_OPT symbol was seen that was not generated by gcc,
72 so that we can detect the SunPRO compiler. */
73 bfd_boolean n_opt_found
;
74 /* The main file name. */
76 /* A stack of unfinished N_BINCL files. */
77 struct bincl_file
*bincl_stack
;
78 /* A list of finished N_BINCL files. */
79 struct bincl_file
*bincl_list
;
80 /* Whether we are inside a function or not. */
81 bfd_boolean within_function
;
82 /* The address of the end of the function, used if we have seen an
83 N_FUN symbol while in a function. This is -1 if we have not seen
84 an N_FUN (the normal case). */
86 /* The depth of block nesting. */
88 /* List of pending variable definitions. */
89 struct stab_pending_var
*pending
;
90 /* Number of files for which we have types. */
92 /* Lists of types per file. */
93 struct stab_types
**file_types
;
94 /* Predefined XCOFF types. */
95 debug_type xcoff_types
[XCOFF_TYPE_COUNT
];
97 struct stab_tag
*tags
;
98 /* Set by parse_stab_type if it sees a structure defined as a cross
99 reference to itself. Reset by parse_stab_type otherwise. */
100 bfd_boolean self_crossref
;
103 /* A list of these structures is used to hold pending variable
104 definitions seen before the N_LBRAC of a block. */
106 struct stab_pending_var
108 /* Next pending variable definition. */
109 struct stab_pending_var
*next
;
115 enum debug_var_kind kind
;
120 /* A list of these structures is used to hold the types for a single
125 /* Next set of slots for this file. */
126 struct stab_types
*next
;
127 /* Types indexed by type number. */
128 #define STAB_TYPES_SLOTS (16)
129 debug_type types
[STAB_TYPES_SLOTS
];
132 /* We keep a list of undefined tags that we encounter, so that we can
133 fill them in if the tag is later defined. */
137 /* Next undefined tag. */
138 struct stab_tag
*next
;
142 enum debug_type_kind kind
;
143 /* Slot to hold real type when we discover it. If we don't, we fill
144 in an undefined tag type. */
146 /* Indirect type we have created to point at slot. */
150 static char *savestring
151 PARAMS ((const char *, int));
152 static bfd_vma parse_number
153 PARAMS ((const char **, bfd_boolean
*));
155 PARAMS ((const char *));
156 static void warn_stab
157 PARAMS ((const char *, const char *));
158 static bfd_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 bfd_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
169 PARAMS ((PTR
, const char **));
170 static debug_type parse_stab_sun_floating_type
171 PARAMS ((PTR
, const char **));
172 static debug_type parse_stab_enum_type
173 PARAMS ((PTR
, const char **));
174 static debug_type parse_stab_struct_type
175 PARAMS ((PTR
, struct stab_handle
*, const char *, const char **,
176 bfd_boolean
, const int *));
177 static bfd_boolean parse_stab_baseclasses
178 PARAMS ((PTR
, struct stab_handle
*, const char **, debug_baseclass
**));
179 static bfd_boolean parse_stab_struct_fields
180 PARAMS ((PTR
, struct stab_handle
*, const char **, debug_field
**,
182 static bfd_boolean parse_stab_cpp_abbrev
183 PARAMS ((PTR
, struct stab_handle
*, const char **, debug_field
*));
184 static bfd_boolean parse_stab_one_struct_field
185 PARAMS ((PTR
, struct stab_handle
*, const char **, const char *,
186 debug_field
*, bfd_boolean
*));
187 static bfd_boolean parse_stab_members
188 PARAMS ((PTR
, struct stab_handle
*, const char *, const char **,
189 const int *, debug_method
**));
190 static debug_type parse_stab_argtypes
191 PARAMS ((PTR
, struct stab_handle
*, debug_type
, const char *, const char *,
192 debug_type
, const char *, bfd_boolean
, bfd_boolean
, const char **));
193 static bfd_boolean parse_stab_tilde_field
194 PARAMS ((PTR
, struct stab_handle
*, const char **, const int *,
195 debug_type
*, bfd_boolean
*));
196 static debug_type parse_stab_array_type
197 PARAMS ((PTR
, struct stab_handle
*, const char **, bfd_boolean
));
198 static void push_bincl
199 PARAMS ((struct stab_handle
*, const char *, bfd_vma
));
200 static const char *pop_bincl
201 PARAMS ((struct stab_handle
*));
202 static bfd_boolean find_excl
203 PARAMS ((struct stab_handle
*, const char *, bfd_vma
));
204 static bfd_boolean stab_record_variable
205 PARAMS ((PTR
, struct stab_handle
*, const char *, debug_type
,
206 enum debug_var_kind
, bfd_vma
));
207 static bfd_boolean stab_emit_pending_vars
208 PARAMS ((PTR
, struct stab_handle
*));
209 static debug_type
*stab_find_slot
210 PARAMS ((struct stab_handle
*, const int *));
211 static debug_type stab_find_type
212 PARAMS ((PTR
, struct stab_handle
*, const int *));
213 static bfd_boolean stab_record_type
214 PARAMS ((PTR
, struct stab_handle
*, const int *, debug_type
));
215 static debug_type stab_xcoff_builtin_type
216 PARAMS ((PTR
, struct stab_handle
*, int));
217 static debug_type stab_find_tagged_type
218 PARAMS ((PTR
, struct stab_handle
*, const char *, int,
219 enum debug_type_kind
));
220 static debug_type
*stab_demangle_argtypes
221 PARAMS ((PTR
, struct stab_handle
*, const char *, bfd_boolean
*,
224 /* Save a string in memory. */
227 savestring (start
, len
)
233 ret
= (char *) xmalloc (len
+ 1);
234 memcpy (ret
, start
, len
);
239 /* Read a number from a string. */
242 parse_number (pp
, poverflow
)
244 bfd_boolean
*poverflow
;
249 if (poverflow
!= NULL
)
255 ul
= strtoul (*pp
, (char **) pp
, 0);
256 if (ul
+ 1 != 0 || errno
== 0)
258 /* If bfd_vma is larger than unsigned long, and the number is
259 meant to be negative, we have to make sure that we sign
262 return (bfd_vma
) (bfd_signed_vma
) (long) ul
;
266 /* Note that even though strtoul overflowed, it should have set *pp
267 to the end of the number, which is where we want it. */
268 if (sizeof (bfd_vma
) > sizeof (unsigned long))
273 bfd_vma over
, lastdig
;
274 bfd_boolean overflow
;
277 /* Our own version of strtoul, for a bfd_vma. */
292 if (p
[1] == 'x' || p
[1] == 'X')
304 over
= ((bfd_vma
) (bfd_signed_vma
) -1) / (bfd_vma
) base
;
305 lastdig
= ((bfd_vma
) (bfd_signed_vma
) -1) % (bfd_vma
) base
;
316 else if (ISUPPER (d
))
318 else if (ISLOWER (d
))
326 if (v
> over
|| (v
== over
&& (bfd_vma
) d
> lastdig
))
341 /* If we get here, the number is too large to represent in a
343 if (poverflow
!= NULL
)
346 warn_stab (orig
, _("numeric overflow"));
351 /* Give an error for a bad stab string. */
357 fprintf (stderr
, _("Bad stab: %s\n"), p
);
360 /* Warn about something in a stab string. */
367 fprintf (stderr
, _("Warning: %s: %s\n"), err
, p
);
370 /* Create a handle to parse stabs symbols with. */
373 start_stab (dhandle
, abfd
, sections
, syms
, symcount
)
374 PTR dhandle ATTRIBUTE_UNUSED
;
376 bfd_boolean sections
;
380 struct stab_handle
*ret
;
382 ret
= (struct stab_handle
*) xmalloc (sizeof *ret
);
383 memset (ret
, 0, sizeof *ret
);
385 ret
->sections
= sections
;
387 ret
->symcount
= symcount
;
389 ret
->file_types
= (struct stab_types
**) xmalloc (sizeof *ret
->file_types
);
390 ret
->file_types
[0] = NULL
;
391 ret
->function_end
= (bfd_vma
) -1;
395 /* When we have processed all the stabs information, we need to go
396 through and fill in all the undefined tags. */
399 finish_stab (dhandle
, handle
)
403 struct stab_handle
*info
= (struct stab_handle
*) handle
;
406 if (info
->within_function
)
408 if (! stab_emit_pending_vars (dhandle
, info
)
409 || ! debug_end_function (dhandle
, info
->function_end
))
411 info
->within_function
= FALSE
;
412 info
->function_end
= (bfd_vma
) -1;
415 for (st
= info
->tags
; st
!= NULL
; st
= st
->next
)
417 enum debug_type_kind kind
;
420 if (kind
== DEBUG_KIND_ILLEGAL
)
421 kind
= DEBUG_KIND_STRUCT
;
422 st
->slot
= debug_make_undefined_tagged_type (dhandle
, st
->name
, kind
);
423 if (st
->slot
== DEBUG_TYPE_NULL
)
430 /* Handle a single stabs symbol. */
433 parse_stab (dhandle
, handle
, type
, desc
, value
, string
)
441 struct stab_handle
*info
= (struct stab_handle
*) handle
;
443 /* gcc will emit two N_SO strings per compilation unit, one for the
444 directory name and one for the file name. We just collect N_SO
445 strings as we see them, and start the new compilation unit when
446 we see a non N_SO symbol. */
447 if (info
->so_string
!= NULL
448 && (type
!= N_SO
|| *string
== '\0' || value
!= info
->so_value
))
450 if (! debug_set_filename (dhandle
, info
->so_string
))
452 info
->main_filename
= info
->so_string
;
454 info
->gcc_compiled
= 0;
455 info
->n_opt_found
= FALSE
;
457 /* Generally, for stabs in the symbol table, the N_LBRAC and
458 N_RBRAC symbols are relative to the N_SO symbol value. */
459 if (! info
->sections
)
460 info
->file_start_offset
= info
->so_value
;
462 /* We need to reset the mapping from type numbers to types. We
463 can't free the old mapping, because of the use of
464 debug_make_indirect_type. */
466 info
->file_types
= ((struct stab_types
**)
467 xmalloc (sizeof *info
->file_types
));
468 info
->file_types
[0] = NULL
;
470 info
->so_string
= NULL
;
472 /* Now process whatever type we just got. */
482 /* Ignore extra outermost context from SunPRO cc and acc. */
483 if (info
->n_opt_found
&& desc
== 1)
486 if (! info
->within_function
)
488 fprintf (stderr
, _("N_LBRAC not within function\n"));
492 /* Start an inner lexical block. */
493 if (! debug_start_block (dhandle
,
495 + info
->file_start_offset
496 + info
->function_start_offset
)))
499 /* Emit any pending variable definitions. */
500 if (! stab_emit_pending_vars (dhandle
, info
))
507 /* Ignore extra outermost context from SunPRO cc and acc. */
508 if (info
->n_opt_found
&& desc
== 1)
511 /* We shouldn't have any pending variable definitions here, but,
512 if we do, we probably need to emit them before closing the
514 if (! stab_emit_pending_vars (dhandle
, info
))
517 /* End an inner lexical block. */
518 if (! debug_end_block (dhandle
,
520 + info
->file_start_offset
521 + info
->function_start_offset
)))
525 if (info
->block_depth
< 0)
527 fprintf (stderr
, _("Too many N_RBRACs\n"));
533 /* This always ends a function. */
534 if (info
->within_function
)
540 && info
->function_end
!= (bfd_vma
) -1
541 && info
->function_end
< endval
)
542 endval
= info
->function_end
;
543 if (! stab_emit_pending_vars (dhandle
, info
)
544 || ! debug_end_function (dhandle
, endval
))
546 info
->within_function
= FALSE
;
547 info
->function_end
= (bfd_vma
) -1;
550 /* An empty string is emitted by gcc at the end of a compilation
555 /* Just accumulate strings until we see a non N_SO symbol. If
556 the string starts with a directory separator or some other
557 form of absolute path specification, we discard the previously
558 accumulated strings. */
559 if (info
->so_string
== NULL
)
560 info
->so_string
= xstrdup (string
);
567 if (IS_ABSOLUTE_PATH (string
))
568 info
->so_string
= xstrdup (string
);
570 info
->so_string
= concat (info
->so_string
, string
,
571 (const char *) NULL
);
575 info
->so_value
= value
;
580 /* Start an include file. */
581 if (! debug_start_source (dhandle
, string
))
586 /* Start an include file which may be replaced. */
587 push_bincl (info
, string
, value
);
588 if (! debug_start_source (dhandle
, string
))
593 /* End an N_BINCL include. */
594 if (! debug_start_source (dhandle
, pop_bincl (info
)))
599 /* This is a duplicate of a header file named by N_BINCL which
600 was eliminated by the linker. */
601 if (! find_excl (info
, string
, value
))
606 if (! debug_record_line (dhandle
, desc
,
607 value
+ (info
->within_function
608 ? info
->function_start_offset
: 0)))
613 if (! debug_start_common_block (dhandle
, string
))
618 if (! debug_end_common_block (dhandle
, string
))
625 if (info
->within_function
)
627 /* This always marks the end of a function; we don't
628 need to worry about info->function_end. */
630 value
+= info
->function_start_offset
;
631 if (! stab_emit_pending_vars (dhandle
, info
)
632 || ! debug_end_function (dhandle
, value
))
634 info
->within_function
= FALSE
;
635 info
->function_end
= (bfd_vma
) -1;
640 /* A const static symbol in the .text section will have an N_FUN
641 entry. We need to use these to mark the end of the function,
642 in case we are looking at gcc output before it was changed to
643 always emit an empty N_FUN. We can't call debug_end_function
644 here, because it might be a local static symbol. */
645 if (info
->within_function
646 && (info
->function_end
== (bfd_vma
) -1
647 || value
< info
->function_end
))
648 info
->function_end
= value
;
651 /* FIXME: gdb checks the string for N_STSYM, N_LCSYM or N_ROSYM
652 symbols, and if it does not start with :S, gdb relocates the
653 value to the start of the section. gcc always seems to use
654 :S, so we don't worry about this. */
660 colon
= strchr (string
, ':');
662 && (colon
[1] == 'f' || colon
[1] == 'F'))
664 if (info
->within_function
)
669 if (info
->function_end
!= (bfd_vma
) -1
670 && info
->function_end
< endval
)
671 endval
= info
->function_end
;
672 if (! stab_emit_pending_vars (dhandle
, info
)
673 || ! debug_end_function (dhandle
, endval
))
675 info
->function_end
= (bfd_vma
) -1;
677 /* For stabs in sections, line numbers and block addresses
678 are offsets from the start of the function. */
680 info
->function_start_offset
= value
;
681 info
->within_function
= TRUE
;
684 if (! parse_stab_string (dhandle
, info
, type
, desc
, value
, string
))
690 if (string
!= NULL
&& strcmp (string
, "gcc2_compiled.") == 0)
691 info
->gcc_compiled
= 2;
692 else if (string
!= NULL
&& strcmp (string
, "gcc_compiled.") == 0)
693 info
->gcc_compiled
= 1;
695 info
->n_opt_found
= TRUE
;
708 /* Parse the stabs string. */
711 parse_stab_string (dhandle
, info
, stabtype
, desc
, value
, string
)
713 struct stab_handle
*info
;
724 bfd_boolean self_crossref
;
728 p
= strchr (string
, ':');
743 /* GCC 2.x puts the line number in desc. SunOS apparently puts in
744 the number of bytes occupied by a type or object, which we
746 if (info
->gcc_compiled
>= 2)
751 /* FIXME: Sometimes the special C++ names start with '.'. */
753 if (string
[0] == '$')
761 /* Was: name = "vptr"; */
767 /* This was an anonymous type that was never fixed up. */
770 /* SunPRO (3.0 at least) static variable encoding. */
773 warn_stab (string
, _("unknown C++ encoded name"));
780 if (p
== string
|| (string
[0] == ' ' && p
== string
+ 1))
783 name
= savestring (string
, p
- string
);
787 if (ISDIGIT (*p
) || *p
== '(' || *p
== '-')
795 /* c is a special case, not followed by a type-number.
796 SYMBOL:c=iVALUE for an integer constant symbol.
797 SYMBOL:c=rVALUE for a floating constant symbol.
798 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
799 e.g. "b:c=e6,0" for "const b = blob1"
800 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
810 /* Floating point constant. */
811 if (! debug_record_float_const (dhandle
, name
, atof (p
)))
815 /* Integer constant. */
816 /* Defining integer constants this way is kind of silly,
817 since 'e' constants allows the compiler to give not only
818 the value, but the type as well. C has at least int,
819 long, unsigned int, and long long as constant types;
820 other languages probably should have at least unsigned as
821 well as signed constants. */
822 if (! debug_record_int_const (dhandle
, name
, atoi (p
)))
826 /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value
827 can be represented as integral.
828 e.g. "b:c=e6,0" for "const b = blob1"
829 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
830 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
,
831 &p
, (debug_type
**) NULL
);
832 if (dtype
== DEBUG_TYPE_NULL
)
839 if (! debug_record_typed_const (dhandle
, name
, dtype
, atoi (p
)))
850 /* The name of a caught exception. */
851 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
,
852 &p
, (debug_type
**) NULL
);
853 if (dtype
== DEBUG_TYPE_NULL
)
855 if (! debug_record_label (dhandle
, name
, dtype
, value
))
861 /* A function definition. */
862 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
863 (debug_type
**) NULL
);
864 if (dtype
== DEBUG_TYPE_NULL
)
866 if (! debug_record_function (dhandle
, name
, dtype
, type
== 'F', value
))
869 /* Sun acc puts declared types of arguments here. We don't care
870 about their actual types (FIXME -- we should remember the whole
871 function prototype), but the list may define some new types
872 that we have to remember, so we must scan it now. */
876 if (parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
877 (debug_type
**) NULL
)
890 /* A global symbol. The value must be extracted from the
892 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
893 (debug_type
**) NULL
);
894 if (dtype
== DEBUG_TYPE_NULL
)
896 leading
= bfd_get_symbol_leading_char (info
->abfd
);
897 for (c
= info
->symcount
, ps
= info
->syms
; c
> 0; --c
, ++ps
)
901 n
= bfd_asymbol_name (*ps
);
902 if (leading
!= '\0' && *n
== leading
)
904 if (*n
== *name
&& strcmp (n
, name
) == 0)
908 value
= bfd_asymbol_value (*ps
);
909 if (! stab_record_variable (dhandle
, info
, name
, dtype
, DEBUG_GLOBAL
,
915 /* This case is faked by a conditional above, when there is no
916 code letter in the dbx data. Dbx data never actually
920 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
921 (debug_type
**) NULL
);
922 if (dtype
== DEBUG_TYPE_NULL
)
924 if (! stab_record_variable (dhandle
, info
, name
, dtype
, DEBUG_LOCAL
,
930 /* A function parameter. */
932 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
933 (debug_type
**) NULL
);
936 /* pF is a two-letter code that means a function parameter in
937 Fortran. The type-number specifies the type of the return
938 value. Translate it into a pointer-to-function type. */
940 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
941 (debug_type
**) NULL
);
942 if (dtype
!= DEBUG_TYPE_NULL
)
946 ftype
= debug_make_function_type (dhandle
, dtype
,
947 (debug_type
*) NULL
, FALSE
);
948 dtype
= debug_make_pointer_type (dhandle
, ftype
);
951 if (dtype
== DEBUG_TYPE_NULL
)
953 if (! debug_record_parameter (dhandle
, name
, dtype
, DEBUG_PARM_STACK
,
957 /* FIXME: At this point gdb considers rearranging the parameter
958 address on a big endian machine if it is smaller than an int.
959 We have no way to do that, since we don't really know much
964 if (stabtype
== N_FUN
)
966 /* Prototype of a function referenced by this file. */
970 if (parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
971 (debug_type
**) NULL
)
979 /* Parameter which is in a register. */
980 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
981 (debug_type
**) NULL
);
982 if (dtype
== DEBUG_TYPE_NULL
)
984 if (! debug_record_parameter (dhandle
, name
, dtype
, DEBUG_PARM_REG
,
990 /* Register variable (either global or local). */
991 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
992 (debug_type
**) NULL
);
993 if (dtype
== DEBUG_TYPE_NULL
)
995 if (! stab_record_variable (dhandle
, info
, name
, dtype
, DEBUG_REGISTER
,
999 /* FIXME: At this point gdb checks to combine pairs of 'p' and
1000 'r' stabs into a single 'P' stab. */
1004 /* Static symbol at top level of file. */
1005 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
1006 (debug_type
**) NULL
);
1007 if (dtype
== DEBUG_TYPE_NULL
)
1009 if (! stab_record_variable (dhandle
, info
, name
, dtype
, DEBUG_STATIC
,
1016 dtype
= parse_stab_type (dhandle
, info
, name
, &p
, &slot
);
1017 if (dtype
== DEBUG_TYPE_NULL
)
1021 /* A nameless type. Nothing to do. */
1025 dtype
= debug_name_type (dhandle
, name
, dtype
);
1026 if (dtype
== DEBUG_TYPE_NULL
)
1035 /* Struct, union, or enum tag. For GNU C++, this can be be followed
1036 by 't' which means we are typedef'ing it as well. */
1040 /* FIXME: gdb sets synonym to TRUE if the current language
1049 dtype
= parse_stab_type (dhandle
, info
, name
, &p
, &slot
);
1050 if (dtype
== DEBUG_TYPE_NULL
)
1055 /* INFO->SELF_CROSSREF is set by parse_stab_type if this type is
1056 a cross reference to itself. These are generated by some
1058 self_crossref
= info
->self_crossref
;
1060 dtype
= debug_tag_type (dhandle
, name
, dtype
);
1061 if (dtype
== DEBUG_TYPE_NULL
)
1066 /* See if we have a cross reference to this tag which we can now
1067 fill in. Avoid filling in a cross reference to ourselves,
1068 because that would lead to circular debugging information. */
1069 if (! self_crossref
)
1071 register struct stab_tag
**pst
;
1073 for (pst
= &info
->tags
; *pst
!= NULL
; pst
= &(*pst
)->next
)
1075 if ((*pst
)->name
[0] == name
[0]
1076 && strcmp ((*pst
)->name
, name
) == 0)
1078 (*pst
)->slot
= dtype
;
1079 *pst
= (*pst
)->next
;
1087 dtype
= debug_name_type (dhandle
, name
, dtype
);
1088 if (dtype
== DEBUG_TYPE_NULL
)
1098 /* Static symbol of local scope */
1099 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
1100 (debug_type
**) NULL
);
1101 if (dtype
== DEBUG_TYPE_NULL
)
1103 /* FIXME: gdb checks os9k_stabs here. */
1104 if (! stab_record_variable (dhandle
, info
, name
, dtype
,
1105 DEBUG_LOCAL_STATIC
, value
))
1110 /* Reference parameter. */
1111 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
1112 (debug_type
**) NULL
);
1113 if (dtype
== DEBUG_TYPE_NULL
)
1115 if (! debug_record_parameter (dhandle
, name
, dtype
, DEBUG_PARM_REFERENCE
,
1121 /* Reference parameter which is in a register. */
1122 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
1123 (debug_type
**) NULL
);
1124 if (dtype
== DEBUG_TYPE_NULL
)
1126 if (! debug_record_parameter (dhandle
, name
, dtype
, DEBUG_PARM_REF_REG
,
1132 /* This is used by Sun FORTRAN for "function result value".
1133 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
1134 that Pascal uses it too, but when I tried it Pascal used
1135 "x:3" (local symbol) instead. */
1136 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
1137 (debug_type
**) NULL
);
1138 if (dtype
== DEBUG_TYPE_NULL
)
1140 if (! stab_record_variable (dhandle
, info
, name
, dtype
, DEBUG_LOCAL
,
1150 /* FIXME: gdb converts structure values to structure pointers in a
1151 couple of cases, depending upon the target. */
1156 /* Parse a stabs type. The typename argument is non-NULL if this is a
1157 typedef or a tag definition. The pp argument points to the stab
1158 string, and is updated. The slotp argument points to a place to
1159 store the slot used if the type is being defined. */
1162 parse_stab_type (dhandle
, info
, typename
, pp
, slotp
)
1164 struct stab_handle
*info
;
1165 const char *typename
;
1172 bfd_boolean stringp
;
1184 info
->self_crossref
= FALSE
;
1186 /* Read type number if present. The type number may be omitted.
1187 for instance in a two-dimensional array declared with type
1188 "ar1;1;10;ar1;1;10;4". */
1189 if (! ISDIGIT (**pp
) && **pp
!= '(' && **pp
!= '-')
1191 /* 'typenums=' not present, type is anonymous. Read and return
1192 the definition, but don't put it in the type vector. */
1193 typenums
[0] = typenums
[1] = -1;
1197 if (! parse_stab_type_number (pp
, typenums
))
1198 return DEBUG_TYPE_NULL
;
1201 /* Type is not being defined here. Either it already
1202 exists, or this is a forward reference to it. */
1203 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
== '-')
1234 /* Type attributes. */
1237 for (; *p
!= ';'; ++p
)
1242 return DEBUG_TYPE_NULL
;
1250 size
= atoi (attr
+ 1);
1251 size
/= 8; /* Size is in bits. We store it in bytes. */
1261 /* Ignore unrecognized type attributes, so future
1262 compilers can invent new ones. */
1275 enum debug_type_kind code
;
1276 const char *q1
, *q2
, *p
;
1278 /* A cross reference to another type. */
1282 code
= DEBUG_KIND_STRUCT
;
1285 code
= DEBUG_KIND_UNION
;
1288 code
= DEBUG_KIND_ENUM
;
1291 /* Complain and keep going, so compilers can invent new
1292 cross-reference types. */
1293 warn_stab (orig
, _("unrecognized cross reference type"));
1294 code
= DEBUG_KIND_STRUCT
;
1299 q1
= strchr (*pp
, '<');
1300 p
= strchr (*pp
, ':');
1304 return DEBUG_TYPE_NULL
;
1306 if (q1
!= NULL
&& p
> q1
&& p
[1] == ':')
1310 for (q2
= q1
; *q2
!= '\0'; ++q2
)
1314 else if (*q2
== '>')
1316 else if (*q2
== ':' && nest
== 0)
1323 return DEBUG_TYPE_NULL
;
1327 /* Some versions of g++ can emit stabs like
1329 which define structures in terms of themselves. We need to
1330 tell the caller to avoid building a circular structure. */
1331 if (typename
!= NULL
1332 && strncmp (typename
, *pp
, p
- *pp
) == 0
1333 && typename
[p
- *pp
] == '\0')
1334 info
->self_crossref
= TRUE
;
1336 dtype
= stab_find_tagged_type (dhandle
, info
, *pp
, p
- *pp
, code
);
1358 /* This type is defined as another type. */
1362 /* Peek ahead at the number to detect void. */
1363 if (! parse_stab_type_number (pp
, xtypenums
))
1364 return DEBUG_TYPE_NULL
;
1366 if (typenums
[0] == xtypenums
[0] && typenums
[1] == xtypenums
[1])
1368 /* This type is being defined as itself, which means that
1370 dtype
= debug_make_void_type (dhandle
);
1376 /* Go back to the number and have parse_stab_type get it.
1377 This means that we can deal with something like
1378 t(1,2)=(3,4)=... which the Lucid compiler uses. */
1379 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
,
1380 pp
, (debug_type
**) NULL
);
1381 if (dtype
== DEBUG_TYPE_NULL
)
1382 return DEBUG_TYPE_NULL
;
1385 if (typenums
[0] != -1)
1387 if (! stab_record_type (dhandle
, info
, typenums
, dtype
))
1388 return DEBUG_TYPE_NULL
;
1395 dtype
= debug_make_pointer_type (dhandle
,
1396 parse_stab_type (dhandle
, info
,
1397 (const char *) NULL
,
1399 (debug_type
**) NULL
));
1403 /* Reference to another type. */
1404 dtype
= (debug_make_reference_type
1406 parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
1407 (debug_type
**) NULL
)));
1411 /* Function returning another type. */
1412 /* FIXME: gdb checks os9k_stabs here. */
1413 dtype
= (debug_make_function_type
1415 parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
1416 (debug_type
**) NULL
),
1417 (debug_type
*) NULL
, FALSE
));
1421 /* Const qualifier on some type (Sun). */
1422 /* FIXME: gdb accepts 'c' here if os9k_stabs. */
1423 dtype
= debug_make_const_type (dhandle
,
1424 parse_stab_type (dhandle
, info
,
1425 (const char *) NULL
,
1427 (debug_type
**) NULL
));
1431 /* Volatile qual on some type (Sun). */
1432 /* FIXME: gdb accepts 'i' here if os9k_stabs. */
1433 dtype
= (debug_make_volatile_type
1435 parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
1436 (debug_type
**) NULL
)));
1440 /* Offset (class & variable) type. This is used for a pointer
1441 relative to an object. */
1448 domain
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
1449 (debug_type
**) NULL
);
1450 if (domain
== DEBUG_TYPE_NULL
)
1451 return DEBUG_TYPE_NULL
;
1456 return DEBUG_TYPE_NULL
;
1460 memtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
1461 (debug_type
**) NULL
);
1462 if (memtype
== DEBUG_TYPE_NULL
)
1463 return DEBUG_TYPE_NULL
;
1465 dtype
= debug_make_offset_type (dhandle
, domain
, memtype
);
1470 /* Method (class & fn) type. */
1473 debug_type return_type
;
1476 return_type
= parse_stab_type (dhandle
, info
, (const char *) NULL
,
1477 pp
, (debug_type
**) NULL
);
1478 if (return_type
== DEBUG_TYPE_NULL
)
1479 return DEBUG_TYPE_NULL
;
1483 return DEBUG_TYPE_NULL
;
1486 dtype
= debug_make_method_type (dhandle
, return_type
,
1488 (debug_type
*) NULL
, FALSE
);
1493 debug_type return_type
;
1497 bfd_boolean varargs
;
1499 domain
= parse_stab_type (dhandle
, info
, (const char *) NULL
,
1500 pp
, (debug_type
**) NULL
);
1501 if (domain
== DEBUG_TYPE_NULL
)
1502 return DEBUG_TYPE_NULL
;
1507 return DEBUG_TYPE_NULL
;
1511 return_type
= parse_stab_type (dhandle
, info
, (const char *) NULL
,
1512 pp
, (debug_type
**) NULL
);
1513 if (return_type
== DEBUG_TYPE_NULL
)
1514 return DEBUG_TYPE_NULL
;
1517 args
= (debug_type
*) xmalloc (alloc
* sizeof *args
);
1524 return DEBUG_TYPE_NULL
;
1531 args
= ((debug_type
*)
1532 xrealloc ((PTR
) args
, alloc
* sizeof *args
));
1535 args
[n
] = parse_stab_type (dhandle
, info
, (const char *) NULL
,
1536 pp
, (debug_type
**) NULL
);
1537 if (args
[n
] == DEBUG_TYPE_NULL
)
1538 return DEBUG_TYPE_NULL
;
1543 /* If the last type is not void, then this function takes a
1544 variable number of arguments. Otherwise, we must strip
1547 || debug_get_type_kind (dhandle
, args
[n
- 1]) != DEBUG_KIND_VOID
)
1555 args
[n
] = DEBUG_TYPE_NULL
;
1557 dtype
= debug_make_method_type (dhandle
, return_type
, domain
, args
,
1564 dtype
= parse_stab_range_type (dhandle
, info
, typename
, pp
, typenums
);
1568 /* FIXME: gdb checks os9k_stabs here. */
1569 /* Sun ACC builtin int type. */
1570 dtype
= parse_stab_sun_builtin_type (dhandle
, pp
);
1574 /* Sun ACC builtin float type. */
1575 dtype
= parse_stab_sun_floating_type (dhandle
, pp
);
1579 /* Enumeration type. */
1580 dtype
= parse_stab_enum_type (dhandle
, pp
);
1585 /* Struct or union type. */
1586 dtype
= parse_stab_struct_type (dhandle
, info
, typename
, pp
,
1587 descriptor
== 's', typenums
);
1595 return DEBUG_TYPE_NULL
;
1599 dtype
= parse_stab_array_type (dhandle
, info
, pp
, stringp
);
1603 dtype
= debug_make_set_type (dhandle
,
1604 parse_stab_type (dhandle
, info
,
1605 (const char *) NULL
,
1607 (debug_type
**) NULL
),
1613 return DEBUG_TYPE_NULL
;
1616 if (dtype
== DEBUG_TYPE_NULL
)
1617 return DEBUG_TYPE_NULL
;
1619 if (typenums
[0] != -1)
1621 if (! stab_record_type (dhandle
, info
, typenums
, dtype
))
1622 return DEBUG_TYPE_NULL
;
1627 if (! debug_record_type_size (dhandle
, dtype
, (unsigned int) size
))
1628 return DEBUG_TYPE_NULL
;
1634 /* Read a number by which a type is referred to in dbx data, or
1635 perhaps read a pair (FILENUM, TYPENUM) in parentheses. Just a
1636 single number N is equivalent to (0,N). Return the two numbers by
1637 storing them in the vector TYPENUMS. */
1640 parse_stab_type_number (pp
, typenums
)
1651 typenums
[1] = (int) parse_number (pp
, (bfd_boolean
*) NULL
);
1656 typenums
[0] = (int) parse_number (pp
, (bfd_boolean
*) NULL
);
1663 typenums
[1] = (int) parse_number (pp
, (bfd_boolean
*) NULL
);
1675 /* Parse a range type. */
1678 parse_stab_range_type (dhandle
, info
, typename
, pp
, typenums
)
1680 struct stab_handle
*info
;
1681 const char *typename
;
1683 const int *typenums
;
1687 bfd_boolean self_subrange
;
1688 debug_type index_type
;
1689 const char *s2
, *s3
;
1690 bfd_signed_vma n2
, n3
;
1691 bfd_boolean ov2
, ov3
;
1695 index_type
= DEBUG_TYPE_NULL
;
1697 /* First comes a type we are a subrange of.
1698 In C it is usually 0, 1 or the type being defined. */
1699 if (! parse_stab_type_number (pp
, rangenums
))
1700 return DEBUG_TYPE_NULL
;
1702 self_subrange
= (rangenums
[0] == typenums
[0]
1703 && rangenums
[1] == typenums
[1]);
1708 index_type
= parse_stab_type (dhandle
, info
, (const char *) NULL
,
1709 pp
, (debug_type
**) NULL
);
1710 if (index_type
== DEBUG_TYPE_NULL
)
1711 return DEBUG_TYPE_NULL
;
1717 /* The remaining two operands are usually lower and upper bounds of
1718 the range. But in some special cases they mean something else. */
1720 n2
= parse_number (pp
, &ov2
);
1724 return DEBUG_TYPE_NULL
;
1729 n3
= parse_number (pp
, &ov3
);
1733 return DEBUG_TYPE_NULL
;
1739 /* gcc will emit range stabs for long long types. Handle this
1740 as a special case. FIXME: This needs to be more general. */
1741 #define LLLOW "01000000000000000000000;"
1742 #define LLHIGH "0777777777777777777777;"
1743 #define ULLHIGH "01777777777777777777777;"
1744 if (index_type
== DEBUG_TYPE_NULL
)
1746 if (strncmp (s2
, LLLOW
, sizeof LLLOW
- 1) == 0
1747 && strncmp (s3
, LLHIGH
, sizeof LLHIGH
- 1) == 0)
1748 return debug_make_int_type (dhandle
, 8, FALSE
);
1751 && strncmp (s3
, ULLHIGH
, sizeof ULLHIGH
- 1) == 0)
1752 return debug_make_int_type (dhandle
, 8, TRUE
);
1755 warn_stab (orig
, _("numeric overflow"));
1758 if (index_type
== DEBUG_TYPE_NULL
)
1760 /* A type defined as a subrange of itself, with both bounds 0,
1762 if (self_subrange
&& n2
== 0 && n3
== 0)
1763 return debug_make_void_type (dhandle
);
1765 /* A type defined as a subrange of itself, with n2 positive and
1766 n3 zero, is a complex type, and n2 is the number of bytes. */
1767 if (self_subrange
&& n3
== 0 && n2
> 0)
1768 return debug_make_complex_type (dhandle
, n2
);
1770 /* If n3 is zero and n2 is positive, this is a floating point
1771 type, and n2 is the number of bytes. */
1772 if (n3
== 0 && n2
> 0)
1773 return debug_make_float_type (dhandle
, n2
);
1775 /* If the upper bound is -1, this is an unsigned int. */
1776 if (n2
== 0 && n3
== -1)
1778 /* When gcc is used with -gstabs, but not -gstabs+, it will emit
1779 long long int:t6=r1;0;-1;
1780 long long unsigned int:t7=r1;0;-1;
1781 We hack here to handle this reasonably. */
1782 if (typename
!= NULL
)
1784 if (strcmp (typename
, "long long int") == 0)
1785 return debug_make_int_type (dhandle
, 8, FALSE
);
1786 else if (strcmp (typename
, "long long unsigned int") == 0)
1787 return debug_make_int_type (dhandle
, 8, TRUE
);
1789 /* FIXME: The size here really depends upon the target. */
1790 return debug_make_int_type (dhandle
, 4, TRUE
);
1793 /* A range of 0 to 127 is char. */
1794 if (self_subrange
&& n2
== 0 && n3
== 127)
1795 return debug_make_int_type (dhandle
, 1, FALSE
);
1797 /* FIXME: gdb checks for the language CHILL here. */
1802 return debug_make_int_type (dhandle
, - n3
, TRUE
);
1803 else if (n3
== 0xff)
1804 return debug_make_int_type (dhandle
, 1, TRUE
);
1805 else if (n3
== 0xffff)
1806 return debug_make_int_type (dhandle
, 2, TRUE
);
1807 else if (n3
== (bfd_signed_vma
) 0xffffffff)
1808 return debug_make_int_type (dhandle
, 4, TRUE
);
1810 else if (n3
== ((((bfd_signed_vma
) 0xffffffff) << 32) | 0xffffffff))
1811 return debug_make_int_type (dhandle
, 8, TRUE
);
1816 && (self_subrange
|| n2
== -8))
1817 return debug_make_int_type (dhandle
, - n2
, TRUE
);
1818 else if (n2
== - n3
- 1 || n2
== n3
+ 1)
1821 return debug_make_int_type (dhandle
, 1, FALSE
);
1822 else if (n3
== 0x7fff)
1823 return debug_make_int_type (dhandle
, 2, FALSE
);
1824 else if (n3
== 0x7fffffff)
1825 return debug_make_int_type (dhandle
, 4, FALSE
);
1827 else if (n3
== ((((bfd_vma
) 0x7fffffff) << 32) | 0xffffffff))
1828 return debug_make_int_type (dhandle
, 8, FALSE
);
1833 /* At this point I don't have the faintest idea how to deal with a
1834 self_subrange type; I'm going to assume that this is used as an
1835 idiom, and that all of them are special cases. So . . . */
1839 return DEBUG_TYPE_NULL
;
1842 index_type
= stab_find_type (dhandle
, info
, rangenums
);
1843 if (index_type
== DEBUG_TYPE_NULL
)
1845 /* Does this actually ever happen? Is that why we are worrying
1846 about dealing with it rather than just calling error_type? */
1847 warn_stab (orig
, _("missing index type"));
1848 index_type
= debug_make_int_type (dhandle
, 4, FALSE
);
1851 return debug_make_range_type (dhandle
, index_type
, n2
, n3
);
1854 /* Sun's ACC uses a somewhat saner method for specifying the builtin
1855 typedefs in every file (for int, long, etc):
1857 type = b <signed> <width>; <offset>; <nbits>
1858 signed = u or s. Possible c in addition to u or s (for char?).
1859 offset = offset from high order bit to start bit of type.
1860 width is # bytes in object of this type, nbits is # bits in type.
1862 The width/offset stuff appears to be for small objects stored in
1863 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
1867 parse_stab_sun_builtin_type (dhandle
, pp
)
1872 bfd_boolean unsignedp
;
1887 return DEBUG_TYPE_NULL
;
1891 /* For some odd reason, all forms of char put a c here. This is strange
1892 because no other type has this honor. We can safely ignore this because
1893 we actually determine 'char'acterness by the number of bits specified in
1898 /* The first number appears to be the number of bytes occupied
1899 by this type, except that unsigned short is 4 instead of 2.
1900 Since this information is redundant with the third number,
1901 we will ignore it. */
1902 (void) parse_number (pp
, (bfd_boolean
*) NULL
);
1906 return DEBUG_TYPE_NULL
;
1910 /* The second number is always 0, so ignore it too. */
1911 (void) parse_number (pp
, (bfd_boolean
*) NULL
);
1915 return DEBUG_TYPE_NULL
;
1919 /* The third number is the number of bits for this type. */
1920 bits
= parse_number (pp
, (bfd_boolean
*) NULL
);
1922 /* The type *should* end with a semicolon. If it are embedded
1923 in a larger type the semicolon may be the only way to know where
1924 the type ends. If this type is at the end of the stabstring we
1925 can deal with the omitted semicolon (but we don't have to like
1926 it). Don't bother to complain(), Sun's compiler omits the semicolon
1932 return debug_make_void_type (dhandle
);
1934 return debug_make_int_type (dhandle
, bits
/ 8, unsignedp
);
1937 /* Parse a builtin floating type generated by the Sun compiler. */
1940 parse_stab_sun_floating_type (dhandle
, pp
)
1950 /* The first number has more details about the type, for example
1952 details
= parse_number (pp
, (bfd_boolean
*) NULL
);
1956 return DEBUG_TYPE_NULL
;
1959 /* The second number is the number of bytes occupied by this type */
1960 bytes
= parse_number (pp
, (bfd_boolean
*) NULL
);
1964 return DEBUG_TYPE_NULL
;
1967 if (details
== NF_COMPLEX
1968 || details
== NF_COMPLEX16
1969 || details
== NF_COMPLEX32
)
1970 return debug_make_complex_type (dhandle
, bytes
);
1972 return debug_make_float_type (dhandle
, bytes
);
1975 /* Handle an enum type. */
1978 parse_stab_enum_type (dhandle
, pp
)
1984 bfd_signed_vma
*values
;
1990 /* FIXME: gdb checks os9k_stabs here. */
1992 /* The aix4 compiler emits an extra field before the enum members;
1993 my guess is it's a type of some sort. Just ignore it. */
2001 /* Read the value-names and their values.
2002 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
2003 A semicolon or comma instead of a NAME means the end. */
2005 names
= (const char **) xmalloc (alloc
* sizeof *names
);
2006 values
= (bfd_signed_vma
*) xmalloc (alloc
* sizeof *values
);
2008 while (**pp
!= '\0' && **pp
!= ';' && **pp
!= ',')
2018 name
= savestring (*pp
, p
- *pp
);
2021 val
= (bfd_signed_vma
) parse_number (pp
, (bfd_boolean
*) NULL
);
2025 return DEBUG_TYPE_NULL
;
2032 names
= ((const char **)
2033 xrealloc ((PTR
) names
, alloc
* sizeof *names
));
2034 values
= ((bfd_signed_vma
*)
2035 xrealloc ((PTR
) values
, alloc
* sizeof *values
));
2049 return debug_make_enum_type (dhandle
, names
, values
);
2052 /* Read the description of a structure (or union type) and return an object
2053 describing the type.
2055 PP points to a character pointer that points to the next unconsumed token
2056 in the the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
2057 *PP will point to "4a:1,0,32;;". */
2060 parse_stab_struct_type (dhandle
, info
, tagname
, pp
, structp
, typenums
)
2062 struct stab_handle
*info
;
2063 const char *tagname
;
2065 bfd_boolean structp
;
2066 const int *typenums
;
2070 debug_baseclass
*baseclasses
;
2071 debug_field
*fields
;
2072 bfd_boolean statics
;
2073 debug_method
*methods
;
2074 debug_type vptrbase
;
2075 bfd_boolean ownvptr
;
2080 size
= parse_number (pp
, (bfd_boolean
*) NULL
);
2082 /* Get the other information. */
2083 if (! parse_stab_baseclasses (dhandle
, info
, pp
, &baseclasses
)
2084 || ! parse_stab_struct_fields (dhandle
, info
, pp
, &fields
, &statics
)
2085 || ! parse_stab_members (dhandle
, info
, tagname
, pp
, typenums
, &methods
)
2086 || ! parse_stab_tilde_field (dhandle
, info
, pp
, typenums
, &vptrbase
,
2088 return DEBUG_TYPE_NULL
;
2091 && baseclasses
== NULL
2093 && vptrbase
== DEBUG_TYPE_NULL
2095 return debug_make_struct_type (dhandle
, structp
, size
, fields
);
2097 return debug_make_object_type (dhandle
, structp
, size
, fields
, baseclasses
,
2098 methods
, vptrbase
, ownvptr
);
2101 /* The stabs for C++ derived classes contain baseclass information which
2102 is marked by a '!' character after the total size. This function is
2103 called when we encounter the baseclass marker, and slurps up all the
2104 baseclass information.
2106 Immediately following the '!' marker is the number of base classes that
2107 the class is derived from, followed by information for each base class.
2108 For each base class, there are two visibility specifiers, a bit offset
2109 to the base class information within the derived class, a reference to
2110 the type for the base class, and a terminating semicolon.
2112 A typical example, with two base classes, would be "!2,020,19;0264,21;".
2114 Baseclass information marker __________________|| | | | | | |
2115 Number of baseclasses __________________________| | | | | | |
2116 Visibility specifiers (2) ________________________| | | | | |
2117 Offset in bits from start of class _________________| | | | |
2118 Type number for base class ___________________________| | | |
2119 Visibility specifiers (2) _______________________________| | |
2120 Offset in bits from start of class ________________________| |
2121 Type number of base class ____________________________________|
2123 Return TRUE for success, FALSE for failure. */
2126 parse_stab_baseclasses (dhandle
, info
, pp
, retp
)
2128 struct stab_handle
*info
;
2130 debug_baseclass
**retp
;
2134 debug_baseclass
*classes
;
2142 /* No base classes. */
2147 c
= (unsigned int) parse_number (pp
, (bfd_boolean
*) NULL
);
2156 classes
= (debug_baseclass
*) xmalloc ((c
+ 1) * sizeof (**retp
));
2158 for (i
= 0; i
< c
; i
++)
2160 bfd_boolean
virtual;
2161 enum debug_visibility visibility
;
2174 warn_stab (orig
, _("unknown virtual character for baseclass"));
2183 visibility
= DEBUG_VISIBILITY_PRIVATE
;
2186 visibility
= DEBUG_VISIBILITY_PROTECTED
;
2189 visibility
= DEBUG_VISIBILITY_PUBLIC
;
2192 warn_stab (orig
, _("unknown visibility character for baseclass"));
2193 visibility
= DEBUG_VISIBILITY_PUBLIC
;
2198 /* The remaining value is the bit offset of the portion of the
2199 object corresponding to this baseclass. Always zero in the
2200 absence of multiple inheritance. */
2201 bitpos
= parse_number (pp
, (bfd_boolean
*) NULL
);
2209 type
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
2210 (debug_type
**) NULL
);
2211 if (type
== DEBUG_TYPE_NULL
)
2214 classes
[i
] = debug_make_baseclass (dhandle
, type
, bitpos
, virtual,
2216 if (classes
[i
] == DEBUG_BASECLASS_NULL
)
2224 classes
[i
] = DEBUG_BASECLASS_NULL
;
2231 /* Read struct or class data fields. They have the form:
2233 NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
2235 At the end, we see a semicolon instead of a field.
2237 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
2240 The optional VISIBILITY is one of:
2242 '/0' (VISIBILITY_PRIVATE)
2243 '/1' (VISIBILITY_PROTECTED)
2244 '/2' (VISIBILITY_PUBLIC)
2245 '/9' (VISIBILITY_IGNORE)
2247 or nothing, for C style fields with public visibility.
2249 Returns 1 for success, 0 for failure. */
2252 parse_stab_struct_fields (dhandle
, info
, pp
, retp
, staticsp
)
2254 struct stab_handle
*info
;
2257 bfd_boolean
*staticsp
;
2261 debug_field
*fields
;
2272 fields
= (debug_field
*) xmalloc (alloc
* sizeof *fields
);
2275 /* FIXME: gdb checks os9k_stabs here. */
2279 /* Add 1 to c to leave room for NULL pointer at end. */
2283 fields
= ((debug_field
*)
2284 xrealloc ((PTR
) fields
, alloc
* sizeof *fields
));
2287 /* If it starts with CPLUS_MARKER it is a special abbreviation,
2288 unless the CPLUS_MARKER is followed by an underscore, in
2289 which case it is just the name of an anonymous type, which we
2290 should handle like any other type name. We accept either '$'
2291 or '.', because a field name can never contain one of these
2292 characters except as a CPLUS_MARKER. */
2294 if ((*p
== '$' || *p
== '.') && p
[1] != '_')
2297 if (! parse_stab_cpp_abbrev (dhandle
, info
, pp
, fields
+ c
))
2303 /* Look for the ':' that separates the field name from the field
2304 values. Data members are delimited by a single ':', while member
2305 functions are delimited by a pair of ':'s. When we hit the member
2306 functions (if any), terminate scan loop and return. */
2308 p
= strchr (p
, ':');
2318 if (! parse_stab_one_struct_field (dhandle
, info
, pp
, p
, fields
+ c
,
2325 fields
[c
] = DEBUG_FIELD_NULL
;
2332 /* Special GNU C++ name. */
2335 parse_stab_cpp_abbrev (dhandle
, info
, pp
, retp
)
2337 struct stab_handle
*info
;
2345 const char *typename
;
2349 *retp
= DEBUG_FIELD_NULL
;
2363 /* At this point, *pp points to something like "22:23=*22...", where
2364 the type number before the ':' is the "context" and everything
2365 after is a regular type definition. Lookup the type, find it's
2366 name, and construct the field name. */
2368 context
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
2369 (debug_type
**) NULL
);
2370 if (context
== DEBUG_TYPE_NULL
)
2376 /* $vf -- a virtual function table pointer. */
2380 /* $vb -- a virtual bsomethingorother */
2381 typename
= debug_get_type_name (dhandle
, context
);
2382 if (typename
== NULL
)
2384 warn_stab (orig
, _("unnamed $vb type"));
2387 name
= concat ("_vb$", typename
, (const char *) NULL
);
2390 warn_stab (orig
, _("unrecognized C++ abbreviation"));
2391 name
= "INVALID_CPLUSPLUS_ABBREV";
2402 type
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
2403 (debug_type
**) NULL
);
2411 bitpos
= parse_number (pp
, (bfd_boolean
*) NULL
);
2419 *retp
= debug_make_field (dhandle
, name
, type
, bitpos
, 0,
2420 DEBUG_VISIBILITY_PRIVATE
);
2421 if (*retp
== DEBUG_FIELD_NULL
)
2427 /* Parse a single field in a struct or union. */
2430 parse_stab_one_struct_field (dhandle
, info
, pp
, p
, retp
, staticsp
)
2432 struct stab_handle
*info
;
2436 bfd_boolean
*staticsp
;
2440 enum debug_visibility visibility
;
2447 /* FIXME: gdb checks ARM_DEMANGLING here. */
2449 name
= savestring (*pp
, p
- *pp
);
2454 visibility
= DEBUG_VISIBILITY_PUBLIC
;
2461 visibility
= DEBUG_VISIBILITY_PRIVATE
;
2464 visibility
= DEBUG_VISIBILITY_PROTECTED
;
2467 visibility
= DEBUG_VISIBILITY_PUBLIC
;
2470 warn_stab (orig
, _("unknown visibility character for field"));
2471 visibility
= DEBUG_VISIBILITY_PUBLIC
;
2477 type
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
2478 (debug_type
**) NULL
);
2479 if (type
== DEBUG_TYPE_NULL
)
2486 /* This is a static class member. */
2488 p
= strchr (*pp
, ';');
2495 varname
= savestring (*pp
, p
- *pp
);
2499 *retp
= debug_make_static_member (dhandle
, name
, type
, varname
,
2513 bitpos
= parse_number (pp
, (bfd_boolean
*) NULL
);
2521 bitsize
= parse_number (pp
, (bfd_boolean
*) NULL
);
2529 if (bitpos
== 0 && bitsize
== 0)
2531 /* This can happen in two cases: (1) at least for gcc 2.4.5 or
2532 so, it is a field which has been optimized out. The correct
2533 stab for this case is to use VISIBILITY_IGNORE, but that is a
2534 recent invention. (2) It is a 0-size array. For example
2535 union { int num; char str[0]; } foo. Printing "<no value>"
2536 for str in "p foo" is OK, since foo.str (and thus foo.str[3])
2537 will continue to work, and a 0-size array as a whole doesn't
2538 have any contents to print.
2540 I suspect this probably could also happen with gcc -gstabs
2541 (not -gstabs+) for static fields, and perhaps other C++
2542 extensions. Hopefully few people use -gstabs with gdb, since
2543 it is intended for dbx compatibility. */
2544 visibility
= DEBUG_VISIBILITY_IGNORE
;
2547 /* FIXME: gdb does some stuff here to mark fields as unpacked. */
2549 *retp
= debug_make_field (dhandle
, name
, type
, bitpos
, bitsize
, visibility
);
2554 /* Read member function stabs info for C++ classes. The form of each member
2557 NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
2559 An example with two member functions is:
2561 afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
2563 For the case of overloaded operators, the format is op$::*.funcs, where
2564 $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
2565 name (such as `+=') and `.' marks the end of the operator name. */
2568 parse_stab_members (dhandle
, info
, tagname
, pp
, typenums
, retp
)
2570 struct stab_handle
*info
;
2571 const char *tagname
;
2573 const int *typenums
;
2574 debug_method
**retp
;
2577 debug_method
*methods
;
2593 debug_method_variant
*variants
;
2595 unsigned int allocvars
;
2596 debug_type look_ahead_type
;
2598 p
= strchr (*pp
, ':');
2599 if (p
== NULL
|| p
[1] != ':')
2602 /* FIXME: Some systems use something other than '$' here. */
2603 if ((*pp
)[0] != 'o' || (*pp
)[1] != 'p' || (*pp
)[2] != '$')
2605 name
= savestring (*pp
, p
- *pp
);
2610 /* This is a completely wierd case. In order to stuff in the
2611 names that might contain colons (the usual name delimiter),
2612 Mike Tiemann defined a different name format which is
2613 signalled if the identifier is "op$". In that case, the
2614 format is "op$::XXXX." where XXXX is the name. This is
2615 used for names like "+" or "=". YUUUUUUUK! FIXME! */
2617 for (p
= *pp
; *p
!= '.' && *p
!= '\0'; p
++)
2624 name
= savestring (*pp
, p
- *pp
);
2629 variants
= ((debug_method_variant
*)
2630 xmalloc (allocvars
* sizeof *variants
));
2633 look_ahead_type
= DEBUG_TYPE_NULL
;
2640 enum debug_visibility visibility
;
2641 bfd_boolean constp
, volatilep
, staticp
;
2644 const char *physname
;
2645 bfd_boolean varargs
;
2647 if (look_ahead_type
!= DEBUG_TYPE_NULL
)
2649 /* g++ version 1 kludge */
2650 type
= look_ahead_type
;
2651 look_ahead_type
= DEBUG_TYPE_NULL
;
2655 type
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
2656 (debug_type
**) NULL
);
2657 if (type
== DEBUG_TYPE_NULL
)
2667 p
= strchr (*pp
, ';');
2675 if (debug_get_type_kind (dhandle
, type
) == DEBUG_KIND_METHOD
2676 && debug_get_parameter_types (dhandle
, type
, &varargs
) == NULL
)
2679 argtypes
= savestring (*pp
, p
- *pp
);
2685 visibility
= DEBUG_VISIBILITY_PRIVATE
;
2688 visibility
= DEBUG_VISIBILITY_PROTECTED
;
2691 visibility
= DEBUG_VISIBILITY_PUBLIC
;
2701 /* Normal function. */
2705 /* const member function. */
2710 /* volatile member function. */
2715 /* const volatile member function. */
2723 /* File compiled with g++ version 1; no information. */
2726 warn_stab (orig
, _("const/volatile indicator missing"));
2734 /* virtual member function, followed by index. The sign
2735 bit is supposedly set to distinguish
2736 pointers-to-methods from virtual function indicies. */
2738 voffset
= parse_number (pp
, (bfd_boolean
*) NULL
);
2745 voffset
&= 0x7fffffff;
2747 if (**pp
== ';' || *pp
== '\0')
2749 /* Must be g++ version 1. */
2750 context
= DEBUG_TYPE_NULL
;
2754 /* Figure out from whence this virtual function
2755 came. It may belong to virtual function table of
2756 one of its baseclasses. */
2757 look_ahead_type
= parse_stab_type (dhandle
, info
,
2758 (const char *) NULL
,
2760 (debug_type
**) NULL
);
2763 /* g++ version 1 overloaded methods. */
2764 context
= DEBUG_TYPE_NULL
;
2768 context
= look_ahead_type
;
2769 look_ahead_type
= DEBUG_TYPE_NULL
;
2781 /* static member function. */
2785 context
= DEBUG_TYPE_NULL
;
2786 if (strncmp (argtypes
, name
, strlen (name
)) != 0)
2791 warn_stab (orig
, "member function type missing");
2793 context
= DEBUG_TYPE_NULL
;
2799 context
= DEBUG_TYPE_NULL
;
2803 /* If the type is not a stub, then the argtypes string is
2804 the physical name of the function. Otherwise the
2805 argtypes string is the mangled form of the argument
2806 types, and the full type and the physical name must be
2807 extracted from them. */
2809 physname
= argtypes
;
2812 debug_type class_type
, return_type
;
2814 class_type
= stab_find_type (dhandle
, info
, typenums
);
2815 if (class_type
== DEBUG_TYPE_NULL
)
2817 return_type
= debug_get_return_type (dhandle
, type
);
2818 if (return_type
== DEBUG_TYPE_NULL
)
2823 type
= parse_stab_argtypes (dhandle
, info
, class_type
, name
,
2824 tagname
, return_type
, argtypes
,
2825 constp
, volatilep
, &physname
);
2826 if (type
== DEBUG_TYPE_NULL
)
2830 if (cvars
+ 1 >= allocvars
)
2833 variants
= ((debug_method_variant
*)
2834 xrealloc ((PTR
) variants
,
2835 allocvars
* sizeof *variants
));
2839 variants
[cvars
] = debug_make_method_variant (dhandle
, physname
,
2844 variants
[cvars
] = debug_make_static_method_variant (dhandle
,
2850 if (variants
[cvars
] == DEBUG_METHOD_VARIANT_NULL
)
2855 while (**pp
!= ';' && **pp
!= '\0');
2857 variants
[cvars
] = DEBUG_METHOD_VARIANT_NULL
;
2865 methods
= ((debug_method
*)
2866 xrealloc ((PTR
) methods
, alloc
* sizeof *methods
));
2869 methods
[c
] = debug_make_method (dhandle
, name
, variants
);
2874 if (methods
!= NULL
)
2875 methods
[c
] = DEBUG_METHOD_NULL
;
2882 /* Parse a string representing argument types for a method. Stabs
2883 tries to save space by packing argument types into a mangled
2884 string. This string should give us enough information to extract
2885 both argument types and the physical name of the function, given
2889 parse_stab_argtypes (dhandle
, info
, class_type
, fieldname
, tagname
,
2890 return_type
, argtypes
, constp
, volatilep
, pphysname
)
2892 struct stab_handle
*info
;
2893 debug_type class_type
;
2894 const char *fieldname
;
2895 const char *tagname
;
2896 debug_type return_type
;
2897 const char *argtypes
;
2899 bfd_boolean volatilep
;
2900 const char **pphysname
;
2902 bfd_boolean is_full_physname_constructor
;
2903 bfd_boolean is_constructor
;
2904 bfd_boolean is_destructor
;
2906 bfd_boolean varargs
;
2907 unsigned int physname_len
= 0;
2909 /* Constructors are sometimes handled specially. */
2910 is_full_physname_constructor
= ((argtypes
[0] == '_'
2911 && argtypes
[1] == '_'
2912 && (ISDIGIT (argtypes
[2])
2913 || argtypes
[2] == 'Q'
2914 || argtypes
[2] == 't'))
2915 || strncmp (argtypes
, "__ct", 4) == 0);
2917 is_constructor
= (is_full_physname_constructor
2919 && strcmp (fieldname
, tagname
) == 0));
2920 is_destructor
= ((argtypes
[0] == '_'
2921 && (argtypes
[1] == '$' || argtypes
[1] == '.')
2922 && argtypes
[2] == '_')
2923 || strncmp (argtypes
, "__dt", 4) == 0);
2925 if (is_destructor
|| is_full_physname_constructor
)
2926 *pphysname
= argtypes
;
2930 const char *const_prefix
;
2931 const char *volatile_prefix
;
2933 unsigned int mangled_name_len
;
2936 len
= tagname
== NULL
? 0 : strlen (tagname
);
2937 const_prefix
= constp
? "C" : "";
2938 volatile_prefix
= volatilep
? "V" : "";
2941 sprintf (buf
, "__%s%s", const_prefix
, volatile_prefix
);
2942 else if (tagname
!= NULL
&& strchr (tagname
, '<') != NULL
)
2944 /* Template methods are fully mangled. */
2945 sprintf (buf
, "__%s%s", const_prefix
, volatile_prefix
);
2950 sprintf (buf
, "__%s%s%d", const_prefix
, volatile_prefix
, len
);
2952 mangled_name_len
= ((is_constructor
? 0 : strlen (fieldname
))
2958 if (fieldname
[0] == 'o'
2959 && fieldname
[1] == 'p'
2960 && (fieldname
[2] == '$' || fieldname
[2] == '.'))
2964 opname
= cplus_mangle_opname (fieldname
+ 3, 0);
2967 fprintf (stderr
, _("No mangling for \"%s\"\n"), fieldname
);
2968 return DEBUG_TYPE_NULL
;
2970 mangled_name_len
+= strlen (opname
);
2971 physname
= (char *) xmalloc (mangled_name_len
);
2972 strncpy (physname
, fieldname
, 3);
2973 strcpy (physname
+ 3, opname
);
2977 physname
= (char *) xmalloc (mangled_name_len
);
2981 strcpy (physname
, fieldname
);
2984 physname_len
= strlen (physname
);
2985 strcat (physname
, buf
);
2986 if (tagname
!= NULL
)
2987 strcat (physname
, tagname
);
2988 strcat (physname
, argtypes
);
2990 *pphysname
= physname
;
2993 if (*argtypes
== '\0' || is_destructor
)
2995 args
= (debug_type
*) xmalloc (sizeof *args
);
2997 return debug_make_method_type (dhandle
, return_type
, class_type
, args
,
3001 args
= stab_demangle_argtypes (dhandle
, info
, *pphysname
, &varargs
, physname_len
);
3003 return DEBUG_TYPE_NULL
;
3005 return debug_make_method_type (dhandle
, return_type
, class_type
, args
,
3009 /* The tail end of stabs for C++ classes that contain a virtual function
3010 pointer contains a tilde, a %, and a type number.
3011 The type number refers to the base class (possibly this class itself) which
3012 contains the vtable pointer for the current class.
3014 This function is called when we have parsed all the method declarations,
3015 so we can look for the vptr base class info. */
3018 parse_stab_tilde_field (dhandle
, info
, pp
, typenums
, retvptrbase
, retownvptr
)
3020 struct stab_handle
*info
;
3022 const int *typenums
;
3023 debug_type
*retvptrbase
;
3024 bfd_boolean
*retownvptr
;
3030 *retvptrbase
= DEBUG_TYPE_NULL
;
3031 *retownvptr
= FALSE
;
3035 /* If we are positioned at a ';', then skip it. */
3044 if (**pp
== '=' || **pp
== '+' || **pp
== '-')
3046 /* Obsolete flags that used to indicate the presence of
3047 constructors and/or destructors. */
3058 /* The next number is the type number of the base class (possibly
3059 our own class) which supplies the vtable for this class. */
3060 if (! parse_stab_type_number (pp
, vtypenums
))
3063 if (vtypenums
[0] == typenums
[0]
3064 && vtypenums
[1] == typenums
[1])
3073 vtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
3074 (debug_type
**) NULL
);
3075 for (p
= *pp
; *p
!= ';' && *p
!= '\0'; p
++)
3083 *retvptrbase
= vtype
;
3091 /* Read a definition of an array type. */
3094 parse_stab_array_type (dhandle
, info
, pp
, stringp
)
3096 struct stab_handle
*info
;
3098 bfd_boolean stringp
;
3103 debug_type index_type
;
3104 bfd_boolean adjustable
;
3105 bfd_signed_vma lower
, upper
;
3106 debug_type element_type
;
3108 /* Format of an array type:
3109 "ar<index type>;lower;upper;<array_contents_type>".
3110 OS9000: "arlower,upper;<array_contents_type>".
3112 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
3113 for these, produce a type like float[][]. */
3117 /* FIXME: gdb checks os9k_stabs here. */
3119 /* If the index type is type 0, we take it as int. */
3121 if (! parse_stab_type_number (&p
, typenums
))
3122 return DEBUG_TYPE_NULL
;
3123 if (typenums
[0] == 0 && typenums
[1] == 0 && **pp
!= '=')
3125 index_type
= debug_find_named_type (dhandle
, "int");
3126 if (index_type
== DEBUG_TYPE_NULL
)
3128 index_type
= debug_make_int_type (dhandle
, 4, FALSE
);
3129 if (index_type
== DEBUG_TYPE_NULL
)
3130 return DEBUG_TYPE_NULL
;
3136 index_type
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
3137 (debug_type
**) NULL
);
3143 return DEBUG_TYPE_NULL
;
3149 if (! ISDIGIT (**pp
) && **pp
!= '-')
3155 lower
= (bfd_signed_vma
) parse_number (pp
, (bfd_boolean
*) NULL
);
3159 return DEBUG_TYPE_NULL
;
3163 if (! ISDIGIT (**pp
) && **pp
!= '-')
3169 upper
= (bfd_signed_vma
) parse_number (pp
, (bfd_boolean
*) NULL
);
3173 return DEBUG_TYPE_NULL
;
3177 element_type
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
3178 (debug_type
**) NULL
);
3179 if (element_type
== DEBUG_TYPE_NULL
)
3180 return DEBUG_TYPE_NULL
;
3188 return debug_make_array_type (dhandle
, element_type
, index_type
, lower
,
3192 /* This struct holds information about files we have seen using
3197 /* The next N_BINCL file. */
3198 struct bincl_file
*next
;
3199 /* The next N_BINCL on the stack. */
3200 struct bincl_file
*next_stack
;
3201 /* The file name. */
3203 /* The hash value. */
3205 /* The file index. */
3207 /* The list of types defined in this file. */
3208 struct stab_types
*file_types
;
3211 /* Start a new N_BINCL file, pushing it onto the stack. */
3214 push_bincl (info
, name
, hash
)
3215 struct stab_handle
*info
;
3219 struct bincl_file
*n
;
3221 n
= (struct bincl_file
*) xmalloc (sizeof *n
);
3222 n
->next
= info
->bincl_list
;
3223 n
->next_stack
= info
->bincl_stack
;
3226 n
->file
= info
->files
;
3227 n
->file_types
= NULL
;
3228 info
->bincl_list
= n
;
3229 info
->bincl_stack
= n
;
3232 info
->file_types
= ((struct stab_types
**)
3233 xrealloc ((PTR
) info
->file_types
,
3235 * sizeof *info
->file_types
)));
3236 info
->file_types
[n
->file
] = NULL
;
3239 /* Finish an N_BINCL file, at an N_EINCL, popping the name off the
3244 struct stab_handle
*info
;
3246 struct bincl_file
*o
;
3248 o
= info
->bincl_stack
;
3250 return info
->main_filename
;
3251 info
->bincl_stack
= o
->next_stack
;
3253 o
->file_types
= info
->file_types
[o
->file
];
3255 if (info
->bincl_stack
== NULL
)
3256 return info
->main_filename
;
3257 return info
->bincl_stack
->name
;
3260 /* Handle an N_EXCL: get the types from the corresponding N_BINCL. */
3263 find_excl (info
, name
, hash
)
3264 struct stab_handle
*info
;
3268 struct bincl_file
*l
;
3271 info
->file_types
= ((struct stab_types
**)
3272 xrealloc ((PTR
) info
->file_types
,
3274 * sizeof *info
->file_types
)));
3276 for (l
= info
->bincl_list
; l
!= NULL
; l
= l
->next
)
3277 if (l
->hash
== hash
&& strcmp (l
->name
, name
) == 0)
3281 warn_stab (name
, _("Undefined N_EXCL"));
3282 info
->file_types
[info
->files
- 1] = NULL
;
3286 info
->file_types
[info
->files
- 1] = l
->file_types
;
3291 /* Handle a variable definition. gcc emits variable definitions for a
3292 block before the N_LBRAC, so we must hold onto them until we see
3293 it. The SunPRO compiler emits variable definitions after the
3294 N_LBRAC, so we can call debug_record_variable immediately. */
3297 stab_record_variable (dhandle
, info
, name
, type
, kind
, val
)
3299 struct stab_handle
*info
;
3302 enum debug_var_kind kind
;
3305 struct stab_pending_var
*v
;
3307 if ((kind
== DEBUG_GLOBAL
|| kind
== DEBUG_STATIC
)
3308 || ! info
->within_function
3309 || (info
->gcc_compiled
== 0 && info
->n_opt_found
))
3310 return debug_record_variable (dhandle
, name
, type
, kind
, val
);
3312 v
= (struct stab_pending_var
*) xmalloc (sizeof *v
);
3313 memset (v
, 0, sizeof *v
);
3315 v
->next
= info
->pending
;
3325 /* Emit pending variable definitions. This is called after we see the
3326 N_LBRAC that starts the block. */
3329 stab_emit_pending_vars (dhandle
, info
)
3331 struct stab_handle
*info
;
3333 struct stab_pending_var
*v
;
3338 struct stab_pending_var
*next
;
3340 if (! debug_record_variable (dhandle
, v
->name
, v
->type
, v
->kind
, v
->val
))
3348 info
->pending
= NULL
;
3353 /* Find the slot for a type in the database. */
3356 stab_find_slot (info
, typenums
)
3357 struct stab_handle
*info
;
3358 const int *typenums
;
3362 struct stab_types
**ps
;
3364 filenum
= typenums
[0];
3365 index
= typenums
[1];
3367 if (filenum
< 0 || (unsigned int) filenum
>= info
->files
)
3369 fprintf (stderr
, _("Type file number %d out of range\n"), filenum
);
3374 fprintf (stderr
, _("Type index number %d out of range\n"), index
);
3378 ps
= info
->file_types
+ filenum
;
3380 while (index
>= STAB_TYPES_SLOTS
)
3384 *ps
= (struct stab_types
*) xmalloc (sizeof **ps
);
3385 memset (*ps
, 0, sizeof **ps
);
3388 index
-= STAB_TYPES_SLOTS
;
3392 *ps
= (struct stab_types
*) xmalloc (sizeof **ps
);
3393 memset (*ps
, 0, sizeof **ps
);
3396 return (*ps
)->types
+ index
;
3399 /* Find a type given a type number. If the type has not been
3400 allocated yet, create an indirect type. */
3403 stab_find_type (dhandle
, info
, typenums
)
3405 struct stab_handle
*info
;
3406 const int *typenums
;
3410 if (typenums
[0] == 0 && typenums
[1] < 0)
3412 /* A negative type number indicates an XCOFF builtin type. */
3413 return stab_xcoff_builtin_type (dhandle
, info
, typenums
[1]);
3416 slot
= stab_find_slot (info
, typenums
);
3418 return DEBUG_TYPE_NULL
;
3420 if (*slot
== DEBUG_TYPE_NULL
)
3421 return debug_make_indirect_type (dhandle
, slot
, (const char *) NULL
);
3426 /* Record that a given type number refers to a given type. */
3429 stab_record_type (dhandle
, info
, typenums
, type
)
3430 PTR dhandle ATTRIBUTE_UNUSED
;
3431 struct stab_handle
*info
;
3432 const int *typenums
;
3437 slot
= stab_find_slot (info
, typenums
);
3441 /* gdb appears to ignore type redefinitions, so we do as well. */
3448 /* Return an XCOFF builtin type. */
3451 stab_xcoff_builtin_type (dhandle
, info
, typenum
)
3453 struct stab_handle
*info
;
3459 if (typenum
>= 0 || typenum
< -XCOFF_TYPE_COUNT
)
3461 fprintf (stderr
, _("Unrecognized XCOFF type %d\n"), typenum
);
3462 return DEBUG_TYPE_NULL
;
3464 if (info
->xcoff_types
[-typenum
] != NULL
)
3465 return info
->xcoff_types
[-typenum
];
3470 /* The size of this and all the other types are fixed, defined
3471 by the debugging format. */
3473 rettype
= debug_make_int_type (dhandle
, 4, FALSE
);
3477 rettype
= debug_make_int_type (dhandle
, 1, FALSE
);
3481 rettype
= debug_make_int_type (dhandle
, 2, FALSE
);
3485 rettype
= debug_make_int_type (dhandle
, 4, FALSE
);
3488 name
= "unsigned char";
3489 rettype
= debug_make_int_type (dhandle
, 1, TRUE
);
3492 name
= "signed char";
3493 rettype
= debug_make_int_type (dhandle
, 1, FALSE
);
3496 name
= "unsigned short";
3497 rettype
= debug_make_int_type (dhandle
, 2, TRUE
);
3500 name
= "unsigned int";
3501 rettype
= debug_make_int_type (dhandle
, 4, TRUE
);
3505 rettype
= debug_make_int_type (dhandle
, 4, TRUE
);
3507 name
= "unsigned long";
3508 rettype
= debug_make_int_type (dhandle
, 4, TRUE
);
3512 rettype
= debug_make_void_type (dhandle
);
3515 /* IEEE single precision (32 bit). */
3517 rettype
= debug_make_float_type (dhandle
, 4);
3520 /* IEEE double precision (64 bit). */
3522 rettype
= debug_make_float_type (dhandle
, 8);
3525 /* This is an IEEE double on the RS/6000, and different machines
3526 with different sizes for "long double" should use different
3527 negative type numbers. See stabs.texinfo. */
3528 name
= "long double";
3529 rettype
= debug_make_float_type (dhandle
, 8);
3533 rettype
= debug_make_int_type (dhandle
, 4, FALSE
);
3537 rettype
= debug_make_bool_type (dhandle
, 4);
3540 name
= "short real";
3541 rettype
= debug_make_float_type (dhandle
, 4);
3545 rettype
= debug_make_float_type (dhandle
, 8);
3555 rettype
= debug_make_int_type (dhandle
, 1, TRUE
);
3559 rettype
= debug_make_bool_type (dhandle
, 1);
3563 rettype
= debug_make_bool_type (dhandle
, 2);
3567 rettype
= debug_make_bool_type (dhandle
, 4);
3571 rettype
= debug_make_bool_type (dhandle
, 4);
3574 /* Complex type consisting of two IEEE single precision values. */
3576 rettype
= debug_make_complex_type (dhandle
, 8);
3579 /* Complex type consisting of two IEEE double precision values. */
3580 name
= "double complex";
3581 rettype
= debug_make_complex_type (dhandle
, 16);
3585 rettype
= debug_make_int_type (dhandle
, 1, FALSE
);
3589 rettype
= debug_make_int_type (dhandle
, 2, FALSE
);
3593 rettype
= debug_make_int_type (dhandle
, 4, FALSE
);
3598 rettype
= debug_make_int_type (dhandle
, 2, FALSE
);
3602 rettype
= debug_make_int_type (dhandle
, 8, FALSE
);
3605 name
= "unsigned long long";
3606 rettype
= debug_make_int_type (dhandle
, 8, TRUE
);
3610 rettype
= debug_make_bool_type (dhandle
, 8);
3614 rettype
= debug_make_int_type (dhandle
, 8, FALSE
);
3620 rettype
= debug_name_type (dhandle
, name
, rettype
);
3622 info
->xcoff_types
[-typenum
] = rettype
;
3627 /* Find or create a tagged type. */
3630 stab_find_tagged_type (dhandle
, info
, p
, len
, kind
)
3632 struct stab_handle
*info
;
3635 enum debug_type_kind kind
;
3639 struct stab_tag
*st
;
3641 name
= savestring (p
, len
);
3643 /* We pass DEBUG_KIND_ILLEGAL because we want all tags in the same
3644 namespace. This is right for C, and I don't know how to handle
3645 other languages. FIXME. */
3646 dtype
= debug_find_tagged_type (dhandle
, name
, DEBUG_KIND_ILLEGAL
);
3647 if (dtype
!= DEBUG_TYPE_NULL
)
3653 /* We need to allocate an entry on the undefined tag list. */
3654 for (st
= info
->tags
; st
!= NULL
; st
= st
->next
)
3656 if (st
->name
[0] == name
[0]
3657 && strcmp (st
->name
, name
) == 0)
3659 if (st
->kind
== DEBUG_KIND_ILLEGAL
)
3667 st
= (struct stab_tag
*) xmalloc (sizeof *st
);
3668 memset (st
, 0, sizeof *st
);
3670 st
->next
= info
->tags
;
3673 st
->slot
= DEBUG_TYPE_NULL
;
3674 st
->type
= debug_make_indirect_type (dhandle
, &st
->slot
, name
);
3681 /* In order to get the correct argument types for a stubbed method, we
3682 need to extract the argument types from a C++ mangled string.
3683 Since the argument types can refer back to the return type, this
3684 means that we must demangle the entire physical name. In gdb this
3685 is done by calling cplus_demangle and running the results back
3686 through the C++ expression parser. Since we have no expression
3687 parser, we must duplicate much of the work of cplus_demangle here.
3689 We assume that GNU style demangling is used, since this is only
3690 done for method stubs, and only g++ should output that form of
3691 debugging information. */
3693 /* This structure is used to hold a pointer to type information which
3694 demangling a string. */
3696 struct stab_demangle_typestring
3698 /* The start of the type. This is not null terminated. */
3699 const char *typestring
;
3700 /* The length of the type. */
3704 /* This structure is used to hold information while demangling a
3707 struct stab_demangle_info
3709 /* The debugging information handle. */
3711 /* The stab information handle. */
3712 struct stab_handle
*info
;
3713 /* The array of arguments we are building. */
3715 /* Whether the method takes a variable number of arguments. */
3716 bfd_boolean varargs
;
3717 /* The array of types we have remembered. */
3718 struct stab_demangle_typestring
*typestrings
;
3719 /* The number of typestrings. */
3720 unsigned int typestring_count
;
3721 /* The number of typestring slots we have allocated. */
3722 unsigned int typestring_alloc
;
3725 static void stab_bad_demangle
3726 PARAMS ((const char *));
3727 static unsigned int stab_demangle_count
3728 PARAMS ((const char **));
3729 static bfd_boolean stab_demangle_get_count
3730 PARAMS ((const char **, unsigned int *));
3731 static bfd_boolean stab_demangle_prefix
3732 PARAMS ((struct stab_demangle_info
*, const char **, unsigned int));
3733 static bfd_boolean stab_demangle_function_name
3734 PARAMS ((struct stab_demangle_info
*, const char **, const char *));
3735 static bfd_boolean stab_demangle_signature
3736 PARAMS ((struct stab_demangle_info
*, const char **));
3737 static bfd_boolean stab_demangle_qualified
3738 PARAMS ((struct stab_demangle_info
*, const char **, debug_type
*));
3739 static bfd_boolean stab_demangle_template
3740 PARAMS ((struct stab_demangle_info
*, const char **, char **));
3741 static bfd_boolean stab_demangle_class
3742 PARAMS ((struct stab_demangle_info
*, const char **, const char **));
3743 static bfd_boolean stab_demangle_args
3744 PARAMS ((struct stab_demangle_info
*, const char **, debug_type
**,
3746 static bfd_boolean stab_demangle_arg
3747 PARAMS ((struct stab_demangle_info
*, const char **, debug_type
**,
3748 unsigned int *, unsigned int *));
3749 static bfd_boolean stab_demangle_type
3750 PARAMS ((struct stab_demangle_info
*, const char **, debug_type
*));
3751 static bfd_boolean stab_demangle_fund_type
3752 PARAMS ((struct stab_demangle_info
*, const char **, debug_type
*));
3753 static bfd_boolean stab_demangle_remember_type
3754 PARAMS ((struct stab_demangle_info
*, const char *, int));
3756 /* Warn about a bad demangling. */
3759 stab_bad_demangle (s
)
3762 fprintf (stderr
, _("bad mangled name `%s'\n"), s
);
3765 /* Get a count from a stab string. */
3768 stab_demangle_count (pp
)
3774 while (ISDIGIT (**pp
))
3777 count
+= **pp
- '0';
3783 /* Require a count in a string. The count may be multiple digits, in
3784 which case it must end in an underscore. */
3787 stab_demangle_get_count (pp
, pi
)
3791 if (! ISDIGIT (**pp
))
3809 while (ISDIGIT (*p
));
3820 /* This function demangles a physical name, returning a NULL
3821 terminated array of argument types. */
3824 stab_demangle_argtypes (dhandle
, info
, physname
, pvarargs
, physname_len
)
3826 struct stab_handle
*info
;
3827 const char *physname
;
3828 bfd_boolean
*pvarargs
;
3829 unsigned int physname_len
;
3831 struct stab_demangle_info minfo
;
3833 minfo
.dhandle
= dhandle
;
3836 minfo
.varargs
= FALSE
;
3837 minfo
.typestring_alloc
= 10;
3838 minfo
.typestrings
= ((struct stab_demangle_typestring
*)
3839 xmalloc (minfo
.typestring_alloc
3840 * sizeof *minfo
.typestrings
));
3841 minfo
.typestring_count
= 0;
3843 /* cplus_demangle checks for special GNU mangled forms, but we can't
3844 see any of them in mangled method argument types. */
3846 if (! stab_demangle_prefix (&minfo
, &physname
, physname_len
))
3849 if (*physname
!= '\0')
3851 if (! stab_demangle_signature (&minfo
, &physname
))
3855 free (minfo
.typestrings
);
3856 minfo
.typestrings
= NULL
;
3858 if (minfo
.args
== NULL
)
3859 fprintf (stderr
, _("no argument types in mangled string\n"));
3861 *pvarargs
= minfo
.varargs
;
3865 if (minfo
.typestrings
!= NULL
)
3866 free (minfo
.typestrings
);
3870 /* Demangle the prefix of the mangled name. */
3873 stab_demangle_prefix (minfo
, pp
, physname_len
)
3874 struct stab_demangle_info
*minfo
;
3876 unsigned int physname_len
;
3881 /* cplus_demangle checks for global constructors and destructors,
3882 but we can't see them in mangled argument types. */
3885 scan
= *pp
+ physname_len
;
3888 /* Look for `__'. */
3891 scan
= strchr (scan
, '_');
3892 while (scan
!= NULL
&& *++scan
!= '_');
3896 stab_bad_demangle (*pp
);
3902 /* We found `__'; move ahead to the last contiguous `__' pair. */
3903 i
= strspn (scan
, "_");
3909 && (ISDIGIT (scan
[2])
3913 /* This is a GNU style constructor name. */
3917 else if (scan
== *pp
3918 && ! ISDIGIT (scan
[2])
3921 /* Look for the `__' that separates the prefix from the
3923 while (*scan
== '_')
3925 scan
= strstr (scan
, "__");
3926 if (scan
== NULL
|| scan
[2] == '\0')
3928 stab_bad_demangle (*pp
);
3932 return stab_demangle_function_name (minfo
, pp
, scan
);
3934 else if (scan
[2] != '\0')
3936 /* The name doesn't start with `__', but it does contain `__'. */
3937 return stab_demangle_function_name (minfo
, pp
, scan
);
3941 stab_bad_demangle (*pp
);
3947 /* Demangle a function name prefix. The scan argument points to the
3948 double underscore which separates the function name from the
3952 stab_demangle_function_name (minfo
, pp
, scan
)
3953 struct stab_demangle_info
*minfo
;
3959 /* The string from *pp to scan is the name of the function. We
3960 don't care about the name, since we just looking for argument
3961 types. However, for conversion operators, the name may include a
3962 type which we must remember in order to handle backreferences. */
3968 && strncmp (name
, "type", 4) == 0
3969 && (name
[4] == '$' || name
[4] == '.'))
3973 /* This is a type conversion operator. */
3975 if (! stab_demangle_type (minfo
, &tem
, (debug_type
*) NULL
))
3978 else if (name
[0] == '_'
3985 /* This is a type conversion operator. */
3987 if (! stab_demangle_type (minfo
, &tem
, (debug_type
*) NULL
))
3994 /* Demangle the signature. This is where the argument types are
3998 stab_demangle_signature (minfo
, pp
)
3999 struct stab_demangle_info
*minfo
;
4003 bfd_boolean expect_func
, func_done
;
4008 expect_func
= FALSE
;
4012 while (**pp
!= '\0')
4018 if (! stab_demangle_qualified (minfo
, pp
, (debug_type
*) NULL
)
4019 || ! stab_demangle_remember_type (minfo
, hold
, *pp
- hold
))
4026 /* Static member function. FIXME: Can this happen? */
4033 /* Const member function. */
4039 case '0': case '1': case '2': case '3': case '4':
4040 case '5': case '6': case '7': case '8': case '9':
4043 if (! stab_demangle_class (minfo
, pp
, (const char **) NULL
)
4044 || ! stab_demangle_remember_type (minfo
, hold
, *pp
- hold
))
4051 /* Function. I don't know if this actually happens with g++
4056 if (! stab_demangle_args (minfo
, pp
, &minfo
->args
, &minfo
->varargs
))
4064 if (! stab_demangle_template (minfo
, pp
, (char **) NULL
)
4065 || ! stab_demangle_remember_type (minfo
, hold
, *pp
- hold
))
4072 /* At the outermost level, we cannot have a return type
4073 specified, so if we run into another '_' at this point we
4074 are dealing with a mangled name that is either bogus, or
4075 has been mangled by some algorithm we don't know how to
4076 deal with. So just reject the entire demangling. */
4077 stab_bad_demangle (orig
);
4081 /* Assume we have stumbled onto the first outermost function
4082 argument token, and start processing args. */
4084 if (! stab_demangle_args (minfo
, pp
, &minfo
->args
, &minfo
->varargs
))
4092 if (! stab_demangle_args (minfo
, pp
, &minfo
->args
, &minfo
->varargs
))
4099 /* With GNU style demangling, bar__3foo is 'foo::bar(void)', and
4100 bar__3fooi is 'foo::bar(int)'. We get here when we find the
4101 first case, and need to ensure that the '(void)' gets added
4102 to the current declp. */
4103 if (! stab_demangle_args (minfo
, pp
, &minfo
->args
, &minfo
->varargs
))
4110 /* Demangle a qualified name, such as "Q25Outer5Inner" which is the
4111 mangled form of "Outer::Inner". */
4114 stab_demangle_qualified (minfo
, pp
, ptype
)
4115 struct stab_demangle_info
*minfo
;
4121 unsigned int qualifiers
;
4129 /* GNU mangled name with more than 9 classes. The count is
4130 preceded by an underscore (to distinguish it from the <= 9
4131 case) and followed by an underscore. */
4133 if (! ISDIGIT (*p
) || *p
== '0')
4135 stab_bad_demangle (orig
);
4138 qualifiers
= atoi (p
);
4139 while (ISDIGIT (*p
))
4143 stab_bad_demangle (orig
);
4149 case '1': case '2': case '3': case '4': case '5':
4150 case '6': case '7': case '8': case '9':
4151 qualifiers
= (*pp
)[1] - '0';
4152 /* Skip an optional underscore after the count. */
4153 if ((*pp
)[2] == '_')
4160 stab_bad_demangle (orig
);
4164 context
= DEBUG_TYPE_NULL
;
4166 /* Pick off the names. */
4167 while (qualifiers
-- > 0)
4175 if (! stab_demangle_template (minfo
, pp
,
4176 ptype
!= NULL
? &name
: NULL
))
4181 context
= stab_find_tagged_type (minfo
->dhandle
, minfo
->info
,
4182 name
, strlen (name
),
4185 if (context
== DEBUG_TYPE_NULL
)
4193 len
= stab_demangle_count (pp
);
4194 if (strlen (*pp
) < len
)
4196 stab_bad_demangle (orig
);
4202 const debug_field
*fields
;
4205 if (context
!= DEBUG_TYPE_NULL
)
4206 fields
= debug_get_fields (minfo
->dhandle
, context
);
4208 context
= DEBUG_TYPE_NULL
;
4214 /* Try to find the type by looking through the
4215 fields of context until we find a field with the
4216 same type. This ought to work for a class
4217 defined within a class, but it won't work for,
4218 e.g., an enum defined within a class. stabs does
4219 not give us enough information to figure out the
4222 name
= savestring (*pp
, len
);
4224 for (; *fields
!= DEBUG_FIELD_NULL
; fields
++)
4229 ft
= debug_get_field_type (minfo
->dhandle
, *fields
);
4232 dn
= debug_get_type_name (minfo
->dhandle
, ft
);
4233 if (dn
!= NULL
&& strcmp (dn
, name
) == 0)
4243 if (context
== DEBUG_TYPE_NULL
)
4245 /* We have to fall back on finding the type by name.
4246 If there are more types to come, then this must
4247 be a class. Otherwise, it could be anything. */
4249 if (qualifiers
== 0)
4253 name
= savestring (*pp
, len
);
4254 context
= debug_find_named_type (minfo
->dhandle
,
4259 if (context
== DEBUG_TYPE_NULL
)
4261 context
= stab_find_tagged_type (minfo
->dhandle
,
4265 ? DEBUG_KIND_ILLEGAL
4266 : DEBUG_KIND_CLASS
));
4267 if (context
== DEBUG_TYPE_NULL
)
4283 /* Demangle a template. If PNAME is not NULL, this sets *PNAME to a
4284 string representation of the template. */
4287 stab_demangle_template (minfo
, pp
, pname
)
4288 struct stab_demangle_info
*minfo
;
4299 /* Skip the template name. */
4300 r
= stab_demangle_count (pp
);
4301 if (r
== 0 || strlen (*pp
) < r
)
4303 stab_bad_demangle (orig
);
4308 /* Get the size of the parameter list. */
4309 if (stab_demangle_get_count (pp
, &r
) == 0)
4311 stab_bad_demangle (orig
);
4315 for (i
= 0; i
< r
; i
++)
4319 /* This is a type parameter. */
4321 if (! stab_demangle_type (minfo
, pp
, (debug_type
*) NULL
))
4327 bfd_boolean pointerp
, realp
, integralp
, charp
, boolp
;
4338 /* This is a value parameter. */
4340 if (! stab_demangle_type (minfo
, pp
, (debug_type
*) NULL
))
4343 while (*old_p
!= '\0' && ! done
)
4353 case 'C': /* Const. */
4354 case 'S': /* Signed. */
4355 case 'U': /* Unsigned. */
4356 case 'V': /* Volatile. */
4357 case 'F': /* Function. */
4358 case 'M': /* Member function. */
4362 case 'Q': /* Qualified name. */
4366 case 'T': /* Remembered type. */
4368 case 'v': /* Void. */
4370 case 'x': /* Long long. */
4371 case 'l': /* Long. */
4372 case 'i': /* Int. */
4373 case 's': /* Short. */
4374 case 'w': /* Wchar_t. */
4378 case 'b': /* Bool. */
4382 case 'c': /* Char. */
4386 case 'r': /* Long double. */
4387 case 'd': /* Double. */
4388 case 'f': /* Float. */
4393 /* Assume it's a user defined integral type. */
4404 while (ISDIGIT (**pp
))
4413 val
= stab_demangle_count (pp
);
4416 stab_bad_demangle (orig
);
4424 val
= stab_demangle_count (pp
);
4425 if (val
!= 0 && val
!= 1)
4427 stab_bad_demangle (orig
);
4435 while (ISDIGIT (**pp
))
4440 while (ISDIGIT (**pp
))
4446 while (ISDIGIT (**pp
))
4454 if (! stab_demangle_get_count (pp
, &len
))
4456 stab_bad_demangle (orig
);
4464 /* We can translate this to a string fairly easily by invoking the
4465 regular demangling routine. */
4468 char *s1
, *s2
, *s3
, *s4
= NULL
;
4471 s1
= savestring (orig
, *pp
- orig
);
4473 s2
= concat ("NoSuchStrinG__", s1
, (const char *) NULL
);
4477 s3
= cplus_demangle (s2
, DMGL_ANSI
);
4482 s4
= strstr (s3
, "::NoSuchStrinG");
4483 if (s3
== NULL
|| s4
== NULL
)
4485 stab_bad_demangle (orig
);
4491 /* Eliminating all spaces, except those between > characters,
4492 makes it more likely that the demangled name will match the
4493 name which g++ used as the structure name. */
4494 for (from
= to
= s3
; from
!= s4
; ++from
)
4496 || (from
[1] == '>' && from
> s3
&& from
[-1] == '>'))
4499 *pname
= savestring (s3
, to
- s3
);
4507 /* Demangle a class name. */
4510 stab_demangle_class (minfo
, pp
, pstart
)
4511 struct stab_demangle_info
*minfo ATTRIBUTE_UNUSED
;
4513 const char **pstart
;
4520 n
= stab_demangle_count (pp
);
4521 if (strlen (*pp
) < n
)
4523 stab_bad_demangle (orig
);
4535 /* Demangle function arguments. If the pargs argument is not NULL, it
4536 is set to a NULL terminated array holding the arguments. */
4539 stab_demangle_args (minfo
, pp
, pargs
, pvarargs
)
4540 struct stab_demangle_info
*minfo
;
4543 bfd_boolean
*pvarargs
;
4546 unsigned int alloc
, count
;
4553 *pargs
= (debug_type
*) xmalloc (alloc
* sizeof **pargs
);
4558 while (**pp
!= '_' && **pp
!= '\0' && **pp
!= 'e')
4560 if (**pp
== 'N' || **pp
== 'T')
4568 if (temptype
== 'T')
4572 if (! stab_demangle_get_count (pp
, &r
))
4574 stab_bad_demangle (orig
);
4579 if (! stab_demangle_get_count (pp
, &t
))
4581 stab_bad_demangle (orig
);
4585 if (t
>= minfo
->typestring_count
)
4587 stab_bad_demangle (orig
);
4594 tem
= minfo
->typestrings
[t
].typestring
;
4595 if (! stab_demangle_arg (minfo
, &tem
, pargs
, &count
, &alloc
))
4601 if (! stab_demangle_arg (minfo
, pp
, pargs
, &count
, &alloc
))
4607 (*pargs
)[count
] = DEBUG_TYPE_NULL
;
4619 /* Demangle a single argument. */
4622 stab_demangle_arg (minfo
, pp
, pargs
, pcount
, palloc
)
4623 struct stab_demangle_info
*minfo
;
4626 unsigned int *pcount
;
4627 unsigned int *palloc
;
4633 if (! stab_demangle_type (minfo
, pp
,
4634 pargs
== NULL
? (debug_type
*) NULL
: &type
)
4635 || ! stab_demangle_remember_type (minfo
, start
, *pp
- start
))
4640 if (type
== DEBUG_TYPE_NULL
)
4643 if (*pcount
+ 1 >= *palloc
)
4646 *pargs
= ((debug_type
*)
4647 xrealloc (*pargs
, *palloc
* sizeof **pargs
));
4649 (*pargs
)[*pcount
] = type
;
4656 /* Demangle a type. If the ptype argument is not NULL, *ptype is set
4657 to the newly allocated type. */
4660 stab_demangle_type (minfo
, pp
, ptype
)
4661 struct stab_demangle_info
*minfo
;
4673 /* A pointer type. */
4675 if (! stab_demangle_type (minfo
, pp
, ptype
))
4678 *ptype
= debug_make_pointer_type (minfo
->dhandle
, *ptype
);
4682 /* A reference type. */
4684 if (! stab_demangle_type (minfo
, pp
, ptype
))
4687 *ptype
= debug_make_reference_type (minfo
->dhandle
, *ptype
);
4697 while (**pp
!= '\0' && **pp
!= '_')
4699 if (! ISDIGIT (**pp
))
4701 stab_bad_demangle (orig
);
4710 stab_bad_demangle (orig
);
4715 if (! stab_demangle_type (minfo
, pp
, ptype
))
4719 debug_type int_type
;
4721 int_type
= debug_find_named_type (minfo
->dhandle
, "int");
4722 if (int_type
== NULL
)
4723 int_type
= debug_make_int_type (minfo
->dhandle
, 4, FALSE
);
4724 *ptype
= debug_make_array_type (minfo
->dhandle
, *ptype
, int_type
,
4731 /* A back reference to a remembered type. */
4737 if (! stab_demangle_get_count (pp
, &i
))
4739 stab_bad_demangle (orig
);
4742 if (i
>= minfo
->typestring_count
)
4744 stab_bad_demangle (orig
);
4747 p
= minfo
->typestrings
[i
].typestring
;
4748 if (! stab_demangle_type (minfo
, &p
, ptype
))
4757 bfd_boolean varargs
;
4760 if (! stab_demangle_args (minfo
, pp
,
4762 ? (debug_type
**) NULL
4765 ? (bfd_boolean
*) NULL
4770 /* cplus_demangle will accept a function without a return
4771 type, but I don't know when that will happen, or what
4772 to do if it does. */
4773 stab_bad_demangle (orig
);
4777 if (! stab_demangle_type (minfo
, pp
, ptype
))
4780 *ptype
= debug_make_function_type (minfo
->dhandle
, *ptype
, args
,
4789 bfd_boolean memberp
, constp
, volatilep
;
4790 debug_type class_type
= DEBUG_TYPE_NULL
;
4792 bfd_boolean varargs
;
4796 memberp
= **pp
== 'M';
4805 n
= stab_demangle_count (pp
);
4806 if (strlen (*pp
) < n
)
4808 stab_bad_demangle (orig
);
4816 class_type
= stab_find_tagged_type (minfo
->dhandle
,
4820 if (class_type
== DEBUG_TYPE_NULL
)
4824 else if (**pp
== 'Q')
4826 if (! stab_demangle_qualified (minfo
, pp
,
4828 ? (debug_type
*) NULL
4834 stab_bad_demangle (orig
);
4845 else if (**pp
== 'V')
4852 stab_bad_demangle (orig
);
4856 if (! stab_demangle_args (minfo
, pp
,
4858 ? (debug_type
**) NULL
4861 ? (bfd_boolean
*) NULL
4868 stab_bad_demangle (orig
);
4873 if (! stab_demangle_type (minfo
, pp
, ptype
))
4879 *ptype
= debug_make_offset_type (minfo
->dhandle
, class_type
,
4883 /* FIXME: We have no way to record constp or
4885 *ptype
= debug_make_method_type (minfo
->dhandle
, *ptype
,
4886 class_type
, args
, varargs
);
4894 if (! stab_demangle_type (minfo
, pp
, ptype
))
4900 if (! stab_demangle_type (minfo
, pp
, ptype
))
4903 *ptype
= debug_make_const_type (minfo
->dhandle
, *ptype
);
4911 if (! stab_demangle_qualified (minfo
, pp
, ptype
))
4917 if (! stab_demangle_fund_type (minfo
, pp
, ptype
))
4925 /* Demangle a fundamental type. If the ptype argument is not NULL,
4926 *ptype is set to the newly allocated type. */
4929 stab_demangle_fund_type (minfo
, pp
, ptype
)
4930 struct stab_demangle_info
*minfo
;
4935 bfd_boolean constp
, volatilep
, unsignedp
, signedp
;
4980 /* cplus_demangle permits this, but I don't know what it means. */
4981 stab_bad_demangle (orig
);
4984 case 'v': /* void */
4987 *ptype
= debug_find_named_type (minfo
->dhandle
, "void");
4988 if (*ptype
== DEBUG_TYPE_NULL
)
4989 *ptype
= debug_make_void_type (minfo
->dhandle
);
4994 case 'x': /* long long */
4997 *ptype
= debug_find_named_type (minfo
->dhandle
,
4999 ? "long long unsigned int"
5000 : "long long int"));
5001 if (*ptype
== DEBUG_TYPE_NULL
)
5002 *ptype
= debug_make_int_type (minfo
->dhandle
, 8, unsignedp
);
5007 case 'l': /* long */
5010 *ptype
= debug_find_named_type (minfo
->dhandle
,
5012 ? "long unsigned int"
5014 if (*ptype
== DEBUG_TYPE_NULL
)
5015 *ptype
= debug_make_int_type (minfo
->dhandle
, 4, unsignedp
);
5023 *ptype
= debug_find_named_type (minfo
->dhandle
,
5027 if (*ptype
== DEBUG_TYPE_NULL
)
5028 *ptype
= debug_make_int_type (minfo
->dhandle
, 4, unsignedp
);
5033 case 's': /* short */
5036 *ptype
= debug_find_named_type (minfo
->dhandle
,
5038 ? "short unsigned int"
5040 if (*ptype
== DEBUG_TYPE_NULL
)
5041 *ptype
= debug_make_int_type (minfo
->dhandle
, 2, unsignedp
);
5046 case 'b': /* bool */
5049 *ptype
= debug_find_named_type (minfo
->dhandle
, "bool");
5050 if (*ptype
== DEBUG_TYPE_NULL
)
5051 *ptype
= debug_make_bool_type (minfo
->dhandle
, 4);
5056 case 'c': /* char */
5059 *ptype
= debug_find_named_type (minfo
->dhandle
,
5065 if (*ptype
== DEBUG_TYPE_NULL
)
5066 *ptype
= debug_make_int_type (minfo
->dhandle
, 1, unsignedp
);
5071 case 'w': /* wchar_t */
5074 *ptype
= debug_find_named_type (minfo
->dhandle
, "__wchar_t");
5075 if (*ptype
== DEBUG_TYPE_NULL
)
5076 *ptype
= debug_make_int_type (minfo
->dhandle
, 2, TRUE
);
5081 case 'r': /* long double */
5084 *ptype
= debug_find_named_type (minfo
->dhandle
, "long double");
5085 if (*ptype
== DEBUG_TYPE_NULL
)
5086 *ptype
= debug_make_float_type (minfo
->dhandle
, 8);
5091 case 'd': /* double */
5094 *ptype
= debug_find_named_type (minfo
->dhandle
, "double");
5095 if (*ptype
== DEBUG_TYPE_NULL
)
5096 *ptype
= debug_make_float_type (minfo
->dhandle
, 8);
5101 case 'f': /* float */
5104 *ptype
= debug_find_named_type (minfo
->dhandle
, "float");
5105 if (*ptype
== DEBUG_TYPE_NULL
)
5106 *ptype
= debug_make_float_type (minfo
->dhandle
, 4);
5113 if (! ISDIGIT (**pp
))
5115 stab_bad_demangle (orig
);
5119 case '0': case '1': case '2': case '3': case '4':
5120 case '5': case '6': case '7': case '8': case '9':
5124 if (! stab_demangle_class (minfo
, pp
, &hold
))
5130 name
= savestring (hold
, *pp
- hold
);
5131 *ptype
= debug_find_named_type (minfo
->dhandle
, name
);
5133 if (*ptype
== DEBUG_TYPE_NULL
)
5135 /* FIXME: It is probably incorrect to assume that
5136 undefined types are tagged types. */
5137 *ptype
= stab_find_tagged_type (minfo
->dhandle
, minfo
->info
,
5139 DEBUG_KIND_ILLEGAL
);
5140 if (*ptype
== DEBUG_TYPE_NULL
)
5151 if (! stab_demangle_template (minfo
, pp
,
5152 ptype
!= NULL
? &name
: NULL
))
5156 *ptype
= stab_find_tagged_type (minfo
->dhandle
, minfo
->info
,
5157 name
, strlen (name
),
5160 if (*ptype
== DEBUG_TYPE_NULL
)
5167 stab_bad_demangle (orig
);
5174 *ptype
= debug_make_const_type (minfo
->dhandle
, *ptype
);
5176 *ptype
= debug_make_volatile_type (minfo
->dhandle
, *ptype
);
5182 /* Remember a type string in a demangled string. */
5185 stab_demangle_remember_type (minfo
, p
, len
)
5186 struct stab_demangle_info
*minfo
;
5190 if (minfo
->typestring_count
>= minfo
->typestring_alloc
)
5192 minfo
->typestring_alloc
+= 10;
5193 minfo
->typestrings
= ((struct stab_demangle_typestring
*)
5194 xrealloc (minfo
->typestrings
,
5195 (minfo
->typestring_alloc
5196 * sizeof *minfo
->typestrings
)));
5199 minfo
->typestrings
[minfo
->typestring_count
].typestring
= p
;
5200 minfo
->typestrings
[minfo
->typestring_count
].len
= (unsigned int) len
;
5201 ++minfo
->typestring_count
;