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 (const char *, int);
151 static bfd_vma
parse_number (const char **, bfd_boolean
*);
152 static void bad_stab (const char *);
153 static void warn_stab (const char *, const char *);
154 static bfd_boolean parse_stab_string
155 (void *, struct stab_handle
*, int, int, bfd_vma
, const char *);
156 static debug_type parse_stab_type
157 (void *, struct stab_handle
*, const char *, const char **, debug_type
**);
158 static bfd_boolean
parse_stab_type_number (const char **, int *);
159 static debug_type parse_stab_range_type
160 (void *, struct stab_handle
*, const char *, const char **, const int *);
161 static debug_type
parse_stab_sun_builtin_type (void *, const char **);
162 static debug_type
parse_stab_sun_floating_type (void *, const char **);
163 static debug_type
parse_stab_enum_type (void *, const char **);
164 static debug_type parse_stab_struct_type
165 (void *, struct stab_handle
*, const char *, const char **,
166 bfd_boolean
, const int *);
167 static bfd_boolean parse_stab_baseclasses
168 (void *, struct stab_handle
*, const char **, debug_baseclass
**);
169 static bfd_boolean parse_stab_struct_fields
170 (void *, struct stab_handle
*, const char **, debug_field
**, bfd_boolean
*);
171 static bfd_boolean parse_stab_cpp_abbrev
172 (void *, struct stab_handle
*, const char **, debug_field
*);
173 static bfd_boolean parse_stab_one_struct_field
174 (void *, struct stab_handle
*, const char **, const char *,
175 debug_field
*, bfd_boolean
*);
176 static bfd_boolean parse_stab_members
177 (void *, struct stab_handle
*, const char *, const char **, const int *,
179 static debug_type parse_stab_argtypes
180 (void *, struct stab_handle
*, debug_type
, const char *, const char *,
181 debug_type
, const char *, bfd_boolean
, bfd_boolean
, const char **);
182 static bfd_boolean parse_stab_tilde_field
183 (void *, struct stab_handle
*, const char **, const int *, debug_type
*,
185 static debug_type parse_stab_array_type
186 (void *, struct stab_handle
*, const char **, bfd_boolean
);
187 static void push_bincl (struct stab_handle
*, const char *, bfd_vma
);
188 static const char *pop_bincl (struct stab_handle
*);
189 static bfd_boolean
find_excl (struct stab_handle
*, const char *, bfd_vma
);
190 static bfd_boolean stab_record_variable
191 (void *, struct stab_handle
*, const char *, debug_type
,
192 enum debug_var_kind
, bfd_vma
);
193 static bfd_boolean
stab_emit_pending_vars (void *, struct stab_handle
*);
194 static debug_type
*stab_find_slot (struct stab_handle
*, const int *);
195 static debug_type
stab_find_type (void *, struct stab_handle
*, const int *);
196 static bfd_boolean stab_record_type
197 (void *, struct stab_handle
*, const int *, debug_type
);
198 static debug_type stab_xcoff_builtin_type
199 (void *, struct stab_handle
*, int);
200 static debug_type stab_find_tagged_type
201 (void *, struct stab_handle
*, const char *, int, enum debug_type_kind
);
202 static debug_type
*stab_demangle_argtypes
203 (void *, struct stab_handle
*, const char *, bfd_boolean
*, unsigned int);
205 /* Save a string in memory. */
208 savestring (const char *start
, int len
)
212 ret
= (char *) xmalloc (len
+ 1);
213 memcpy (ret
, start
, len
);
218 /* Read a number from a string. */
221 parse_number (const char **pp
, bfd_boolean
*poverflow
)
226 if (poverflow
!= NULL
)
232 ul
= strtoul (*pp
, (char **) pp
, 0);
233 if (ul
+ 1 != 0 || errno
== 0)
235 /* If bfd_vma is larger than unsigned long, and the number is
236 meant to be negative, we have to make sure that we sign
239 return (bfd_vma
) (bfd_signed_vma
) (long) ul
;
243 /* Note that even though strtoul overflowed, it should have set *pp
244 to the end of the number, which is where we want it. */
245 if (sizeof (bfd_vma
) > sizeof (unsigned long))
250 bfd_vma over
, lastdig
;
251 bfd_boolean overflow
;
254 /* Our own version of strtoul, for a bfd_vma. */
269 if (p
[1] == 'x' || p
[1] == 'X')
281 over
= ((bfd_vma
) (bfd_signed_vma
) -1) / (bfd_vma
) base
;
282 lastdig
= ((bfd_vma
) (bfd_signed_vma
) -1) % (bfd_vma
) base
;
293 else if (ISUPPER (d
))
295 else if (ISLOWER (d
))
303 if (v
> over
|| (v
== over
&& (bfd_vma
) d
> lastdig
))
318 /* If we get here, the number is too large to represent in a
320 if (poverflow
!= NULL
)
323 warn_stab (orig
, _("numeric overflow"));
328 /* Give an error for a bad stab string. */
331 bad_stab (const char *p
)
333 fprintf (stderr
, _("Bad stab: %s\n"), p
);
336 /* Warn about something in a stab string. */
339 warn_stab (const char *p
, const char *err
)
341 fprintf (stderr
, _("Warning: %s: %s\n"), err
, p
);
344 /* Create a handle to parse stabs symbols with. */
347 start_stab (void *dhandle ATTRIBUTE_UNUSED
, bfd
*abfd
, bfd_boolean sections
,
348 asymbol
**syms
, long symcount
)
350 struct stab_handle
*ret
;
352 ret
= (struct stab_handle
*) xmalloc (sizeof *ret
);
353 memset (ret
, 0, sizeof *ret
);
355 ret
->sections
= sections
;
357 ret
->symcount
= symcount
;
359 ret
->file_types
= (struct stab_types
**) xmalloc (sizeof *ret
->file_types
);
360 ret
->file_types
[0] = NULL
;
361 ret
->function_end
= (bfd_vma
) -1;
365 /* When we have processed all the stabs information, we need to go
366 through and fill in all the undefined tags. */
369 finish_stab (void *dhandle
, void *handle
)
371 struct stab_handle
*info
= (struct stab_handle
*) handle
;
374 if (info
->within_function
)
376 if (! stab_emit_pending_vars (dhandle
, info
)
377 || ! debug_end_function (dhandle
, info
->function_end
))
379 info
->within_function
= FALSE
;
380 info
->function_end
= (bfd_vma
) -1;
383 for (st
= info
->tags
; st
!= NULL
; st
= st
->next
)
385 enum debug_type_kind kind
;
388 if (kind
== DEBUG_KIND_ILLEGAL
)
389 kind
= DEBUG_KIND_STRUCT
;
390 st
->slot
= debug_make_undefined_tagged_type (dhandle
, st
->name
, kind
);
391 if (st
->slot
== DEBUG_TYPE_NULL
)
398 /* Handle a single stabs symbol. */
401 parse_stab (void *dhandle
, void *handle
, int type
, int desc
, bfd_vma value
,
404 struct stab_handle
*info
= (struct stab_handle
*) handle
;
406 /* gcc will emit two N_SO strings per compilation unit, one for the
407 directory name and one for the file name. We just collect N_SO
408 strings as we see them, and start the new compilation unit when
409 we see a non N_SO symbol. */
410 if (info
->so_string
!= NULL
411 && (type
!= N_SO
|| *string
== '\0' || value
!= info
->so_value
))
413 if (! debug_set_filename (dhandle
, info
->so_string
))
415 info
->main_filename
= info
->so_string
;
417 info
->gcc_compiled
= 0;
418 info
->n_opt_found
= FALSE
;
420 /* Generally, for stabs in the symbol table, the N_LBRAC and
421 N_RBRAC symbols are relative to the N_SO symbol value. */
422 if (! info
->sections
)
423 info
->file_start_offset
= info
->so_value
;
425 /* We need to reset the mapping from type numbers to types. We
426 can't free the old mapping, because of the use of
427 debug_make_indirect_type. */
429 info
->file_types
= ((struct stab_types
**)
430 xmalloc (sizeof *info
->file_types
));
431 info
->file_types
[0] = NULL
;
433 info
->so_string
= NULL
;
435 /* Now process whatever type we just got. */
445 /* Ignore extra outermost context from SunPRO cc and acc. */
446 if (info
->n_opt_found
&& desc
== 1)
449 if (! info
->within_function
)
451 fprintf (stderr
, _("N_LBRAC not within function\n"));
455 /* Start an inner lexical block. */
456 if (! debug_start_block (dhandle
,
458 + info
->file_start_offset
459 + info
->function_start_offset
)))
462 /* Emit any pending variable definitions. */
463 if (! stab_emit_pending_vars (dhandle
, info
))
470 /* Ignore extra outermost context from SunPRO cc and acc. */
471 if (info
->n_opt_found
&& desc
== 1)
474 /* We shouldn't have any pending variable definitions here, but,
475 if we do, we probably need to emit them before closing the
477 if (! stab_emit_pending_vars (dhandle
, info
))
480 /* End an inner lexical block. */
481 if (! debug_end_block (dhandle
,
483 + info
->file_start_offset
484 + info
->function_start_offset
)))
488 if (info
->block_depth
< 0)
490 fprintf (stderr
, _("Too many N_RBRACs\n"));
496 /* This always ends a function. */
497 if (info
->within_function
)
503 && info
->function_end
!= (bfd_vma
) -1
504 && info
->function_end
< endval
)
505 endval
= info
->function_end
;
506 if (! stab_emit_pending_vars (dhandle
, info
)
507 || ! debug_end_function (dhandle
, endval
))
509 info
->within_function
= FALSE
;
510 info
->function_end
= (bfd_vma
) -1;
513 /* An empty string is emitted by gcc at the end of a compilation
518 /* Just accumulate strings until we see a non N_SO symbol. If
519 the string starts with a directory separator or some other
520 form of absolute path specification, we discard the previously
521 accumulated strings. */
522 if (info
->so_string
== NULL
)
523 info
->so_string
= xstrdup (string
);
530 if (IS_ABSOLUTE_PATH (string
))
531 info
->so_string
= xstrdup (string
);
533 info
->so_string
= concat (info
->so_string
, string
,
534 (const char *) NULL
);
538 info
->so_value
= value
;
543 /* Start an include file. */
544 if (! debug_start_source (dhandle
, string
))
549 /* Start an include file which may be replaced. */
550 push_bincl (info
, string
, value
);
551 if (! debug_start_source (dhandle
, string
))
556 /* End an N_BINCL include. */
557 if (! debug_start_source (dhandle
, pop_bincl (info
)))
562 /* This is a duplicate of a header file named by N_BINCL which
563 was eliminated by the linker. */
564 if (! find_excl (info
, string
, value
))
569 if (! debug_record_line (dhandle
, desc
,
570 value
+ (info
->within_function
571 ? info
->function_start_offset
: 0)))
576 if (! debug_start_common_block (dhandle
, string
))
581 if (! debug_end_common_block (dhandle
, string
))
588 if (info
->within_function
)
590 /* This always marks the end of a function; we don't
591 need to worry about info->function_end. */
593 value
+= info
->function_start_offset
;
594 if (! stab_emit_pending_vars (dhandle
, info
)
595 || ! debug_end_function (dhandle
, value
))
597 info
->within_function
= FALSE
;
598 info
->function_end
= (bfd_vma
) -1;
603 /* A const static symbol in the .text section will have an N_FUN
604 entry. We need to use these to mark the end of the function,
605 in case we are looking at gcc output before it was changed to
606 always emit an empty N_FUN. We can't call debug_end_function
607 here, because it might be a local static symbol. */
608 if (info
->within_function
609 && (info
->function_end
== (bfd_vma
) -1
610 || value
< info
->function_end
))
611 info
->function_end
= value
;
614 /* FIXME: gdb checks the string for N_STSYM, N_LCSYM or N_ROSYM
615 symbols, and if it does not start with :S, gdb relocates the
616 value to the start of the section. gcc always seems to use
617 :S, so we don't worry about this. */
623 colon
= strchr (string
, ':');
625 && (colon
[1] == 'f' || colon
[1] == 'F'))
627 if (info
->within_function
)
632 if (info
->function_end
!= (bfd_vma
) -1
633 && info
->function_end
< endval
)
634 endval
= info
->function_end
;
635 if (! stab_emit_pending_vars (dhandle
, info
)
636 || ! debug_end_function (dhandle
, endval
))
638 info
->function_end
= (bfd_vma
) -1;
640 /* For stabs in sections, line numbers and block addresses
641 are offsets from the start of the function. */
643 info
->function_start_offset
= value
;
644 info
->within_function
= TRUE
;
647 if (! parse_stab_string (dhandle
, info
, type
, desc
, value
, string
))
653 if (string
!= NULL
&& strcmp (string
, "gcc2_compiled.") == 0)
654 info
->gcc_compiled
= 2;
655 else if (string
!= NULL
&& strcmp (string
, "gcc_compiled.") == 0)
656 info
->gcc_compiled
= 1;
658 info
->n_opt_found
= TRUE
;
671 /* Parse the stabs string. */
674 parse_stab_string (void *dhandle
, struct stab_handle
*info
, int stabtype
,
675 int desc
, bfd_vma value
, const char *string
)
682 bfd_boolean self_crossref
;
686 p
= strchr (string
, ':');
701 /* GCC 2.x puts the line number in desc. SunOS apparently puts in
702 the number of bytes occupied by a type or object, which we
704 if (info
->gcc_compiled
>= 2)
709 /* FIXME: Sometimes the special C++ names start with '.'. */
711 if (string
[0] == '$')
719 /* Was: name = "vptr"; */
725 /* This was an anonymous type that was never fixed up. */
728 /* SunPRO (3.0 at least) static variable encoding. */
731 warn_stab (string
, _("unknown C++ encoded name"));
738 if (p
== string
|| (string
[0] == ' ' && p
== string
+ 1))
741 name
= savestring (string
, p
- string
);
745 if (ISDIGIT (*p
) || *p
== '(' || *p
== '-')
753 /* c is a special case, not followed by a type-number.
754 SYMBOL:c=iVALUE for an integer constant symbol.
755 SYMBOL:c=rVALUE for a floating constant symbol.
756 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
757 e.g. "b:c=e6,0" for "const b = blob1"
758 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
768 /* Floating point constant. */
769 if (! debug_record_float_const (dhandle
, name
, atof (p
)))
773 /* Integer constant. */
774 /* Defining integer constants this way is kind of silly,
775 since 'e' constants allows the compiler to give not only
776 the value, but the type as well. C has at least int,
777 long, unsigned int, and long long as constant types;
778 other languages probably should have at least unsigned as
779 well as signed constants. */
780 if (! debug_record_int_const (dhandle
, name
, atoi (p
)))
784 /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value
785 can be represented as integral.
786 e.g. "b:c=e6,0" for "const b = blob1"
787 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
788 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
,
789 &p
, (debug_type
**) NULL
);
790 if (dtype
== DEBUG_TYPE_NULL
)
797 if (! debug_record_typed_const (dhandle
, name
, dtype
, atoi (p
)))
808 /* The name of a caught exception. */
809 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
,
810 &p
, (debug_type
**) NULL
);
811 if (dtype
== DEBUG_TYPE_NULL
)
813 if (! debug_record_label (dhandle
, name
, dtype
, value
))
819 /* A function definition. */
820 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
821 (debug_type
**) NULL
);
822 if (dtype
== DEBUG_TYPE_NULL
)
824 if (! debug_record_function (dhandle
, name
, dtype
, type
== 'F', value
))
827 /* Sun acc puts declared types of arguments here. We don't care
828 about their actual types (FIXME -- we should remember the whole
829 function prototype), but the list may define some new types
830 that we have to remember, so we must scan it now. */
834 if (parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
835 (debug_type
**) NULL
)
848 /* A global symbol. The value must be extracted from the
850 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
851 (debug_type
**) NULL
);
852 if (dtype
== DEBUG_TYPE_NULL
)
854 leading
= bfd_get_symbol_leading_char (info
->abfd
);
855 for (c
= info
->symcount
, ps
= info
->syms
; c
> 0; --c
, ++ps
)
859 n
= bfd_asymbol_name (*ps
);
860 if (leading
!= '\0' && *n
== leading
)
862 if (*n
== *name
&& strcmp (n
, name
) == 0)
866 value
= bfd_asymbol_value (*ps
);
867 if (! stab_record_variable (dhandle
, info
, name
, dtype
, DEBUG_GLOBAL
,
873 /* This case is faked by a conditional above, when there is no
874 code letter in the dbx data. Dbx data never actually
878 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
879 (debug_type
**) NULL
);
880 if (dtype
== DEBUG_TYPE_NULL
)
882 if (! stab_record_variable (dhandle
, info
, name
, dtype
, DEBUG_LOCAL
,
888 /* A function parameter. */
890 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
891 (debug_type
**) NULL
);
894 /* pF is a two-letter code that means a function parameter in
895 Fortran. The type-number specifies the type of the return
896 value. Translate it into a pointer-to-function type. */
898 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
899 (debug_type
**) NULL
);
900 if (dtype
!= DEBUG_TYPE_NULL
)
904 ftype
= debug_make_function_type (dhandle
, dtype
,
905 (debug_type
*) NULL
, FALSE
);
906 dtype
= debug_make_pointer_type (dhandle
, ftype
);
909 if (dtype
== DEBUG_TYPE_NULL
)
911 if (! debug_record_parameter (dhandle
, name
, dtype
, DEBUG_PARM_STACK
,
915 /* FIXME: At this point gdb considers rearranging the parameter
916 address on a big endian machine if it is smaller than an int.
917 We have no way to do that, since we don't really know much
922 if (stabtype
== N_FUN
)
924 /* Prototype of a function referenced by this file. */
928 if (parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
929 (debug_type
**) NULL
)
937 /* Parameter which is in a register. */
938 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
939 (debug_type
**) NULL
);
940 if (dtype
== DEBUG_TYPE_NULL
)
942 if (! debug_record_parameter (dhandle
, name
, dtype
, DEBUG_PARM_REG
,
948 /* Register variable (either global or local). */
949 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
950 (debug_type
**) NULL
);
951 if (dtype
== DEBUG_TYPE_NULL
)
953 if (! stab_record_variable (dhandle
, info
, name
, dtype
, DEBUG_REGISTER
,
957 /* FIXME: At this point gdb checks to combine pairs of 'p' and
958 'r' stabs into a single 'P' stab. */
962 /* Static symbol at top level of file. */
963 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
964 (debug_type
**) NULL
);
965 if (dtype
== DEBUG_TYPE_NULL
)
967 if (! stab_record_variable (dhandle
, info
, name
, dtype
, DEBUG_STATIC
,
974 dtype
= parse_stab_type (dhandle
, info
, name
, &p
, &slot
);
975 if (dtype
== DEBUG_TYPE_NULL
)
979 /* A nameless type. Nothing to do. */
983 dtype
= debug_name_type (dhandle
, name
, dtype
);
984 if (dtype
== DEBUG_TYPE_NULL
)
993 /* Struct, union, or enum tag. For GNU C++, this can be be followed
994 by 't' which means we are typedef'ing it as well. */
998 /* FIXME: gdb sets synonym to TRUE if the current language
1007 dtype
= parse_stab_type (dhandle
, info
, name
, &p
, &slot
);
1008 if (dtype
== DEBUG_TYPE_NULL
)
1013 /* INFO->SELF_CROSSREF is set by parse_stab_type if this type is
1014 a cross reference to itself. These are generated by some
1016 self_crossref
= info
->self_crossref
;
1018 dtype
= debug_tag_type (dhandle
, name
, dtype
);
1019 if (dtype
== DEBUG_TYPE_NULL
)
1024 /* See if we have a cross reference to this tag which we can now
1025 fill in. Avoid filling in a cross reference to ourselves,
1026 because that would lead to circular debugging information. */
1027 if (! self_crossref
)
1029 register struct stab_tag
**pst
;
1031 for (pst
= &info
->tags
; *pst
!= NULL
; pst
= &(*pst
)->next
)
1033 if ((*pst
)->name
[0] == name
[0]
1034 && strcmp ((*pst
)->name
, name
) == 0)
1036 (*pst
)->slot
= dtype
;
1037 *pst
= (*pst
)->next
;
1045 dtype
= debug_name_type (dhandle
, name
, dtype
);
1046 if (dtype
== DEBUG_TYPE_NULL
)
1056 /* Static symbol of local scope */
1057 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
1058 (debug_type
**) NULL
);
1059 if (dtype
== DEBUG_TYPE_NULL
)
1061 /* FIXME: gdb checks os9k_stabs here. */
1062 if (! stab_record_variable (dhandle
, info
, name
, dtype
,
1063 DEBUG_LOCAL_STATIC
, value
))
1068 /* Reference parameter. */
1069 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
1070 (debug_type
**) NULL
);
1071 if (dtype
== DEBUG_TYPE_NULL
)
1073 if (! debug_record_parameter (dhandle
, name
, dtype
, DEBUG_PARM_REFERENCE
,
1079 /* Reference parameter which is in a register. */
1080 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
1081 (debug_type
**) NULL
);
1082 if (dtype
== DEBUG_TYPE_NULL
)
1084 if (! debug_record_parameter (dhandle
, name
, dtype
, DEBUG_PARM_REF_REG
,
1090 /* This is used by Sun FORTRAN for "function result value".
1091 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
1092 that Pascal uses it too, but when I tried it Pascal used
1093 "x:3" (local symbol) instead. */
1094 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
1095 (debug_type
**) NULL
);
1096 if (dtype
== DEBUG_TYPE_NULL
)
1098 if (! stab_record_variable (dhandle
, info
, name
, dtype
, DEBUG_LOCAL
,
1108 /* FIXME: gdb converts structure values to structure pointers in a
1109 couple of cases, depending upon the target. */
1114 /* Parse a stabs type. The typename argument is non-NULL if this is a
1115 typedef or a tag definition. The pp argument points to the stab
1116 string, and is updated. The slotp argument points to a place to
1117 store the slot used if the type is being defined. */
1120 parse_stab_type (void *dhandle
, struct stab_handle
*info
, const char *typename
, const char **pp
, debug_type
**slotp
)
1125 bfd_boolean stringp
;
1137 info
->self_crossref
= FALSE
;
1139 /* Read type number if present. The type number may be omitted.
1140 for instance in a two-dimensional array declared with type
1141 "ar1;1;10;ar1;1;10;4". */
1142 if (! ISDIGIT (**pp
) && **pp
!= '(' && **pp
!= '-')
1144 /* 'typenums=' not present, type is anonymous. Read and return
1145 the definition, but don't put it in the type vector. */
1146 typenums
[0] = typenums
[1] = -1;
1150 if (! parse_stab_type_number (pp
, typenums
))
1151 return DEBUG_TYPE_NULL
;
1154 /* Type is not being defined here. Either it already
1155 exists, or this is a forward reference to it. */
1156 return stab_find_type (dhandle
, info
, typenums
);
1158 /* Only set the slot if the type is being defined. This means
1159 that the mapping from type numbers to types will only record
1160 the name of the typedef which defines a type. If we don't do
1161 this, then something like
1164 will record that i is of type foo. Unfortunately, stabs
1165 information is ambiguous about variable types. For this code,
1169 the stabs information records both i and j as having the same
1170 type. This could be fixed by patching the compiler. */
1171 if (slotp
!= NULL
&& typenums
[0] >= 0 && typenums
[1] >= 0)
1172 *slotp
= stab_find_slot (info
, typenums
);
1174 /* Type is being defined here. */
1180 const char *p
= *pp
+ 1;
1183 if (ISDIGIT (*p
) || *p
== '(' || *p
== '-')
1187 /* Type attributes. */
1190 for (; *p
!= ';'; ++p
)
1195 return DEBUG_TYPE_NULL
;
1203 size
= atoi (attr
+ 1);
1204 size
/= 8; /* Size is in bits. We store it in bytes. */
1214 /* Ignore unrecognized type attributes, so future
1215 compilers can invent new ones. */
1228 enum debug_type_kind code
;
1229 const char *q1
, *q2
, *p
;
1231 /* A cross reference to another type. */
1235 code
= DEBUG_KIND_STRUCT
;
1238 code
= DEBUG_KIND_UNION
;
1241 code
= DEBUG_KIND_ENUM
;
1244 /* Complain and keep going, so compilers can invent new
1245 cross-reference types. */
1246 warn_stab (orig
, _("unrecognized cross reference type"));
1247 code
= DEBUG_KIND_STRUCT
;
1252 q1
= strchr (*pp
, '<');
1253 p
= strchr (*pp
, ':');
1257 return DEBUG_TYPE_NULL
;
1259 if (q1
!= NULL
&& p
> q1
&& p
[1] == ':')
1263 for (q2
= q1
; *q2
!= '\0'; ++q2
)
1267 else if (*q2
== '>')
1269 else if (*q2
== ':' && nest
== 0)
1276 return DEBUG_TYPE_NULL
;
1280 /* Some versions of g++ can emit stabs like
1282 which define structures in terms of themselves. We need to
1283 tell the caller to avoid building a circular structure. */
1284 if (typename
!= NULL
1285 && strncmp (typename
, *pp
, p
- *pp
) == 0
1286 && typename
[p
- *pp
] == '\0')
1287 info
->self_crossref
= TRUE
;
1289 dtype
= stab_find_tagged_type (dhandle
, info
, *pp
, p
- *pp
, code
);
1311 /* This type is defined as another type. */
1315 /* Peek ahead at the number to detect void. */
1316 if (! parse_stab_type_number (pp
, xtypenums
))
1317 return DEBUG_TYPE_NULL
;
1319 if (typenums
[0] == xtypenums
[0] && typenums
[1] == xtypenums
[1])
1321 /* This type is being defined as itself, which means that
1323 dtype
= debug_make_void_type (dhandle
);
1329 /* Go back to the number and have parse_stab_type get it.
1330 This means that we can deal with something like
1331 t(1,2)=(3,4)=... which the Lucid compiler uses. */
1332 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
,
1333 pp
, (debug_type
**) NULL
);
1334 if (dtype
== DEBUG_TYPE_NULL
)
1335 return DEBUG_TYPE_NULL
;
1338 if (typenums
[0] != -1)
1340 if (! stab_record_type (dhandle
, info
, typenums
, dtype
))
1341 return DEBUG_TYPE_NULL
;
1348 dtype
= debug_make_pointer_type (dhandle
,
1349 parse_stab_type (dhandle
, info
,
1350 (const char *) NULL
,
1352 (debug_type
**) NULL
));
1356 /* Reference to another type. */
1357 dtype
= (debug_make_reference_type
1359 parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
1360 (debug_type
**) NULL
)));
1364 /* Function returning another type. */
1365 /* FIXME: gdb checks os9k_stabs here. */
1366 dtype
= (debug_make_function_type
1368 parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
1369 (debug_type
**) NULL
),
1370 (debug_type
*) NULL
, FALSE
));
1374 /* Const qualifier on some type (Sun). */
1375 /* FIXME: gdb accepts 'c' here if os9k_stabs. */
1376 dtype
= debug_make_const_type (dhandle
,
1377 parse_stab_type (dhandle
, info
,
1378 (const char *) NULL
,
1380 (debug_type
**) NULL
));
1384 /* Volatile qual on some type (Sun). */
1385 /* FIXME: gdb accepts 'i' here if os9k_stabs. */
1386 dtype
= (debug_make_volatile_type
1388 parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
1389 (debug_type
**) NULL
)));
1393 /* Offset (class & variable) type. This is used for a pointer
1394 relative to an object. */
1401 domain
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
1402 (debug_type
**) NULL
);
1403 if (domain
== DEBUG_TYPE_NULL
)
1404 return DEBUG_TYPE_NULL
;
1409 return DEBUG_TYPE_NULL
;
1413 memtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
1414 (debug_type
**) NULL
);
1415 if (memtype
== DEBUG_TYPE_NULL
)
1416 return DEBUG_TYPE_NULL
;
1418 dtype
= debug_make_offset_type (dhandle
, domain
, memtype
);
1423 /* Method (class & fn) type. */
1426 debug_type return_type
;
1429 return_type
= parse_stab_type (dhandle
, info
, (const char *) NULL
,
1430 pp
, (debug_type
**) NULL
);
1431 if (return_type
== DEBUG_TYPE_NULL
)
1432 return DEBUG_TYPE_NULL
;
1436 return DEBUG_TYPE_NULL
;
1439 dtype
= debug_make_method_type (dhandle
, return_type
,
1441 (debug_type
*) NULL
, FALSE
);
1446 debug_type return_type
;
1450 bfd_boolean varargs
;
1452 domain
= parse_stab_type (dhandle
, info
, (const char *) NULL
,
1453 pp
, (debug_type
**) NULL
);
1454 if (domain
== DEBUG_TYPE_NULL
)
1455 return DEBUG_TYPE_NULL
;
1460 return DEBUG_TYPE_NULL
;
1464 return_type
= parse_stab_type (dhandle
, info
, (const char *) NULL
,
1465 pp
, (debug_type
**) NULL
);
1466 if (return_type
== DEBUG_TYPE_NULL
)
1467 return DEBUG_TYPE_NULL
;
1470 args
= (debug_type
*) xmalloc (alloc
* sizeof *args
);
1477 return DEBUG_TYPE_NULL
;
1484 args
= ((debug_type
*)
1485 xrealloc (args
, alloc
* sizeof *args
));
1488 args
[n
] = parse_stab_type (dhandle
, info
, (const char *) NULL
,
1489 pp
, (debug_type
**) NULL
);
1490 if (args
[n
] == DEBUG_TYPE_NULL
)
1491 return DEBUG_TYPE_NULL
;
1496 /* If the last type is not void, then this function takes a
1497 variable number of arguments. Otherwise, we must strip
1500 || debug_get_type_kind (dhandle
, args
[n
- 1]) != DEBUG_KIND_VOID
)
1508 args
[n
] = DEBUG_TYPE_NULL
;
1510 dtype
= debug_make_method_type (dhandle
, return_type
, domain
, args
,
1517 dtype
= parse_stab_range_type (dhandle
, info
, typename
, pp
, typenums
);
1521 /* FIXME: gdb checks os9k_stabs here. */
1522 /* Sun ACC builtin int type. */
1523 dtype
= parse_stab_sun_builtin_type (dhandle
, pp
);
1527 /* Sun ACC builtin float type. */
1528 dtype
= parse_stab_sun_floating_type (dhandle
, pp
);
1532 /* Enumeration type. */
1533 dtype
= parse_stab_enum_type (dhandle
, pp
);
1538 /* Struct or union type. */
1539 dtype
= parse_stab_struct_type (dhandle
, info
, typename
, pp
,
1540 descriptor
== 's', typenums
);
1548 return DEBUG_TYPE_NULL
;
1552 dtype
= parse_stab_array_type (dhandle
, info
, pp
, stringp
);
1556 dtype
= debug_make_set_type (dhandle
,
1557 parse_stab_type (dhandle
, info
,
1558 (const char *) NULL
,
1560 (debug_type
**) NULL
),
1566 return DEBUG_TYPE_NULL
;
1569 if (dtype
== DEBUG_TYPE_NULL
)
1570 return DEBUG_TYPE_NULL
;
1572 if (typenums
[0] != -1)
1574 if (! stab_record_type (dhandle
, info
, typenums
, dtype
))
1575 return DEBUG_TYPE_NULL
;
1580 if (! debug_record_type_size (dhandle
, dtype
, (unsigned int) size
))
1581 return DEBUG_TYPE_NULL
;
1587 /* Read a number by which a type is referred to in dbx data, or
1588 perhaps read a pair (FILENUM, TYPENUM) in parentheses. Just a
1589 single number N is equivalent to (0,N). Return the two numbers by
1590 storing them in the vector TYPENUMS. */
1593 parse_stab_type_number (const char **pp
, int *typenums
)
1602 typenums
[1] = (int) parse_number (pp
, (bfd_boolean
*) NULL
);
1607 typenums
[0] = (int) parse_number (pp
, (bfd_boolean
*) NULL
);
1614 typenums
[1] = (int) parse_number (pp
, (bfd_boolean
*) NULL
);
1626 /* Parse a range type. */
1629 parse_stab_range_type (void *dhandle
, struct stab_handle
*info
, const char *typename
, const char **pp
, const int *typenums
)
1633 bfd_boolean self_subrange
;
1634 debug_type index_type
;
1635 const char *s2
, *s3
;
1636 bfd_signed_vma n2
, n3
;
1637 bfd_boolean ov2
, ov3
;
1641 index_type
= DEBUG_TYPE_NULL
;
1643 /* First comes a type we are a subrange of.
1644 In C it is usually 0, 1 or the type being defined. */
1645 if (! parse_stab_type_number (pp
, rangenums
))
1646 return DEBUG_TYPE_NULL
;
1648 self_subrange
= (rangenums
[0] == typenums
[0]
1649 && rangenums
[1] == typenums
[1]);
1654 index_type
= parse_stab_type (dhandle
, info
, (const char *) NULL
,
1655 pp
, (debug_type
**) NULL
);
1656 if (index_type
== DEBUG_TYPE_NULL
)
1657 return DEBUG_TYPE_NULL
;
1663 /* The remaining two operands are usually lower and upper bounds of
1664 the range. But in some special cases they mean something else. */
1666 n2
= parse_number (pp
, &ov2
);
1670 return DEBUG_TYPE_NULL
;
1675 n3
= parse_number (pp
, &ov3
);
1679 return DEBUG_TYPE_NULL
;
1685 /* gcc will emit range stabs for long long types. Handle this
1686 as a special case. FIXME: This needs to be more general. */
1687 #define LLLOW "01000000000000000000000;"
1688 #define LLHIGH "0777777777777777777777;"
1689 #define ULLHIGH "01777777777777777777777;"
1690 if (index_type
== DEBUG_TYPE_NULL
)
1692 if (strncmp (s2
, LLLOW
, sizeof LLLOW
- 1) == 0
1693 && strncmp (s3
, LLHIGH
, sizeof LLHIGH
- 1) == 0)
1694 return debug_make_int_type (dhandle
, 8, FALSE
);
1697 && strncmp (s3
, ULLHIGH
, sizeof ULLHIGH
- 1) == 0)
1698 return debug_make_int_type (dhandle
, 8, TRUE
);
1701 warn_stab (orig
, _("numeric overflow"));
1704 if (index_type
== DEBUG_TYPE_NULL
)
1706 /* A type defined as a subrange of itself, with both bounds 0,
1708 if (self_subrange
&& n2
== 0 && n3
== 0)
1709 return debug_make_void_type (dhandle
);
1711 /* A type defined as a subrange of itself, with n2 positive and
1712 n3 zero, is a complex type, and n2 is the number of bytes. */
1713 if (self_subrange
&& n3
== 0 && n2
> 0)
1714 return debug_make_complex_type (dhandle
, n2
);
1716 /* If n3 is zero and n2 is positive, this is a floating point
1717 type, and n2 is the number of bytes. */
1718 if (n3
== 0 && n2
> 0)
1719 return debug_make_float_type (dhandle
, n2
);
1721 /* If the upper bound is -1, this is an unsigned int. */
1722 if (n2
== 0 && n3
== -1)
1724 /* When gcc is used with -gstabs, but not -gstabs+, it will emit
1725 long long int:t6=r1;0;-1;
1726 long long unsigned int:t7=r1;0;-1;
1727 We hack here to handle this reasonably. */
1728 if (typename
!= NULL
)
1730 if (strcmp (typename
, "long long int") == 0)
1731 return debug_make_int_type (dhandle
, 8, FALSE
);
1732 else if (strcmp (typename
, "long long unsigned int") == 0)
1733 return debug_make_int_type (dhandle
, 8, TRUE
);
1735 /* FIXME: The size here really depends upon the target. */
1736 return debug_make_int_type (dhandle
, 4, TRUE
);
1739 /* A range of 0 to 127 is char. */
1740 if (self_subrange
&& n2
== 0 && n3
== 127)
1741 return debug_make_int_type (dhandle
, 1, FALSE
);
1743 /* FIXME: gdb checks for the language CHILL here. */
1748 return debug_make_int_type (dhandle
, - n3
, TRUE
);
1749 else if (n3
== 0xff)
1750 return debug_make_int_type (dhandle
, 1, TRUE
);
1751 else if (n3
== 0xffff)
1752 return debug_make_int_type (dhandle
, 2, TRUE
);
1753 else if (n3
== (bfd_signed_vma
) 0xffffffff)
1754 return debug_make_int_type (dhandle
, 4, TRUE
);
1756 else if (n3
== ((((bfd_signed_vma
) 0xffffffff) << 32) | 0xffffffff))
1757 return debug_make_int_type (dhandle
, 8, TRUE
);
1762 && (self_subrange
|| n2
== -8))
1763 return debug_make_int_type (dhandle
, - n2
, TRUE
);
1764 else if (n2
== - n3
- 1 || n2
== n3
+ 1)
1767 return debug_make_int_type (dhandle
, 1, FALSE
);
1768 else if (n3
== 0x7fff)
1769 return debug_make_int_type (dhandle
, 2, FALSE
);
1770 else if (n3
== 0x7fffffff)
1771 return debug_make_int_type (dhandle
, 4, FALSE
);
1773 else if (n3
== ((((bfd_vma
) 0x7fffffff) << 32) | 0xffffffff))
1774 return debug_make_int_type (dhandle
, 8, FALSE
);
1779 /* At this point I don't have the faintest idea how to deal with a
1780 self_subrange type; I'm going to assume that this is used as an
1781 idiom, and that all of them are special cases. So . . . */
1785 return DEBUG_TYPE_NULL
;
1788 index_type
= stab_find_type (dhandle
, info
, rangenums
);
1789 if (index_type
== DEBUG_TYPE_NULL
)
1791 /* Does this actually ever happen? Is that why we are worrying
1792 about dealing with it rather than just calling error_type? */
1793 warn_stab (orig
, _("missing index type"));
1794 index_type
= debug_make_int_type (dhandle
, 4, FALSE
);
1797 return debug_make_range_type (dhandle
, index_type
, n2
, n3
);
1800 /* Sun's ACC uses a somewhat saner method for specifying the builtin
1801 typedefs in every file (for int, long, etc):
1803 type = b <signed> <width>; <offset>; <nbits>
1804 signed = u or s. Possible c in addition to u or s (for char?).
1805 offset = offset from high order bit to start bit of type.
1806 width is # bytes in object of this type, nbits is # bits in type.
1808 The width/offset stuff appears to be for small objects stored in
1809 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
1813 parse_stab_sun_builtin_type (void *dhandle
, const char **pp
)
1816 bfd_boolean unsignedp
;
1831 return DEBUG_TYPE_NULL
;
1835 /* For some odd reason, all forms of char put a c here. This is strange
1836 because no other type has this honor. We can safely ignore this because
1837 we actually determine 'char'acterness by the number of bits specified in
1842 /* The first number appears to be the number of bytes occupied
1843 by this type, except that unsigned short is 4 instead of 2.
1844 Since this information is redundant with the third number,
1845 we will ignore it. */
1846 (void) parse_number (pp
, (bfd_boolean
*) NULL
);
1850 return DEBUG_TYPE_NULL
;
1854 /* The second number is always 0, so ignore it too. */
1855 (void) parse_number (pp
, (bfd_boolean
*) NULL
);
1859 return DEBUG_TYPE_NULL
;
1863 /* The third number is the number of bits for this type. */
1864 bits
= parse_number (pp
, (bfd_boolean
*) NULL
);
1866 /* The type *should* end with a semicolon. If it are embedded
1867 in a larger type the semicolon may be the only way to know where
1868 the type ends. If this type is at the end of the stabstring we
1869 can deal with the omitted semicolon (but we don't have to like
1870 it). Don't bother to complain(), Sun's compiler omits the semicolon
1876 return debug_make_void_type (dhandle
);
1878 return debug_make_int_type (dhandle
, bits
/ 8, unsignedp
);
1881 /* Parse a builtin floating type generated by the Sun compiler. */
1884 parse_stab_sun_floating_type (void *dhandle
, const char **pp
)
1892 /* The first number has more details about the type, for example
1894 details
= parse_number (pp
, (bfd_boolean
*) NULL
);
1898 return DEBUG_TYPE_NULL
;
1901 /* The second number is the number of bytes occupied by this type */
1902 bytes
= parse_number (pp
, (bfd_boolean
*) NULL
);
1906 return DEBUG_TYPE_NULL
;
1909 if (details
== NF_COMPLEX
1910 || details
== NF_COMPLEX16
1911 || details
== NF_COMPLEX32
)
1912 return debug_make_complex_type (dhandle
, bytes
);
1914 return debug_make_float_type (dhandle
, bytes
);
1917 /* Handle an enum type. */
1920 parse_stab_enum_type (void *dhandle
, const char **pp
)
1924 bfd_signed_vma
*values
;
1930 /* FIXME: gdb checks os9k_stabs here. */
1932 /* The aix4 compiler emits an extra field before the enum members;
1933 my guess is it's a type of some sort. Just ignore it. */
1941 /* Read the value-names and their values.
1942 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
1943 A semicolon or comma instead of a NAME means the end. */
1945 names
= (const char **) xmalloc (alloc
* sizeof *names
);
1946 values
= (bfd_signed_vma
*) xmalloc (alloc
* sizeof *values
);
1948 while (**pp
!= '\0' && **pp
!= ';' && **pp
!= ',')
1958 name
= savestring (*pp
, p
- *pp
);
1961 val
= (bfd_signed_vma
) parse_number (pp
, (bfd_boolean
*) NULL
);
1965 return DEBUG_TYPE_NULL
;
1972 names
= ((const char **)
1973 xrealloc (names
, alloc
* sizeof *names
));
1974 values
= ((bfd_signed_vma
*)
1975 xrealloc (values
, alloc
* sizeof *values
));
1989 return debug_make_enum_type (dhandle
, names
, values
);
1992 /* Read the description of a structure (or union type) and return an object
1993 describing the type.
1995 PP points to a character pointer that points to the next unconsumed token
1996 in the the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
1997 *PP will point to "4a:1,0,32;;". */
2000 parse_stab_struct_type (void *dhandle
, struct stab_handle
*info
,
2001 const char *tagname
, const char **pp
,
2002 bfd_boolean structp
, const int *typenums
)
2006 debug_baseclass
*baseclasses
;
2007 debug_field
*fields
;
2008 bfd_boolean statics
;
2009 debug_method
*methods
;
2010 debug_type vptrbase
;
2011 bfd_boolean ownvptr
;
2016 size
= parse_number (pp
, (bfd_boolean
*) NULL
);
2018 /* Get the other information. */
2019 if (! parse_stab_baseclasses (dhandle
, info
, pp
, &baseclasses
)
2020 || ! parse_stab_struct_fields (dhandle
, info
, pp
, &fields
, &statics
)
2021 || ! parse_stab_members (dhandle
, info
, tagname
, pp
, typenums
, &methods
)
2022 || ! parse_stab_tilde_field (dhandle
, info
, pp
, typenums
, &vptrbase
,
2024 return DEBUG_TYPE_NULL
;
2027 && baseclasses
== NULL
2029 && vptrbase
== DEBUG_TYPE_NULL
2031 return debug_make_struct_type (dhandle
, structp
, size
, fields
);
2033 return debug_make_object_type (dhandle
, structp
, size
, fields
, baseclasses
,
2034 methods
, vptrbase
, ownvptr
);
2037 /* The stabs for C++ derived classes contain baseclass information which
2038 is marked by a '!' character after the total size. This function is
2039 called when we encounter the baseclass marker, and slurps up all the
2040 baseclass information.
2042 Immediately following the '!' marker is the number of base classes that
2043 the class is derived from, followed by information for each base class.
2044 For each base class, there are two visibility specifiers, a bit offset
2045 to the base class information within the derived class, a reference to
2046 the type for the base class, and a terminating semicolon.
2048 A typical example, with two base classes, would be "!2,020,19;0264,21;".
2050 Baseclass information marker __________________|| | | | | | |
2051 Number of baseclasses __________________________| | | | | | |
2052 Visibility specifiers (2) ________________________| | | | | |
2053 Offset in bits from start of class _________________| | | | |
2054 Type number for base class ___________________________| | | |
2055 Visibility specifiers (2) _______________________________| | |
2056 Offset in bits from start of class ________________________| |
2057 Type number of base class ____________________________________|
2059 Return TRUE for success, FALSE for failure. */
2062 parse_stab_baseclasses (void *dhandle
, struct stab_handle
*info
,
2063 const char **pp
, debug_baseclass
**retp
)
2067 debug_baseclass
*classes
;
2075 /* No base classes. */
2080 c
= (unsigned int) parse_number (pp
, (bfd_boolean
*) NULL
);
2089 classes
= (debug_baseclass
*) xmalloc ((c
+ 1) * sizeof (**retp
));
2091 for (i
= 0; i
< c
; i
++)
2093 bfd_boolean
virtual;
2094 enum debug_visibility visibility
;
2107 warn_stab (orig
, _("unknown virtual character for baseclass"));
2116 visibility
= DEBUG_VISIBILITY_PRIVATE
;
2119 visibility
= DEBUG_VISIBILITY_PROTECTED
;
2122 visibility
= DEBUG_VISIBILITY_PUBLIC
;
2125 warn_stab (orig
, _("unknown visibility character for baseclass"));
2126 visibility
= DEBUG_VISIBILITY_PUBLIC
;
2131 /* The remaining value is the bit offset of the portion of the
2132 object corresponding to this baseclass. Always zero in the
2133 absence of multiple inheritance. */
2134 bitpos
= parse_number (pp
, (bfd_boolean
*) NULL
);
2142 type
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
2143 (debug_type
**) NULL
);
2144 if (type
== DEBUG_TYPE_NULL
)
2147 classes
[i
] = debug_make_baseclass (dhandle
, type
, bitpos
, virtual,
2149 if (classes
[i
] == DEBUG_BASECLASS_NULL
)
2157 classes
[i
] = DEBUG_BASECLASS_NULL
;
2164 /* Read struct or class data fields. They have the form:
2166 NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
2168 At the end, we see a semicolon instead of a field.
2170 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
2173 The optional VISIBILITY is one of:
2175 '/0' (VISIBILITY_PRIVATE)
2176 '/1' (VISIBILITY_PROTECTED)
2177 '/2' (VISIBILITY_PUBLIC)
2178 '/9' (VISIBILITY_IGNORE)
2180 or nothing, for C style fields with public visibility.
2182 Returns 1 for success, 0 for failure. */
2185 parse_stab_struct_fields (void *dhandle
, struct stab_handle
*info
,
2186 const char **pp
, debug_field
**retp
,
2187 bfd_boolean
*staticsp
)
2191 debug_field
*fields
;
2202 fields
= (debug_field
*) xmalloc (alloc
* sizeof *fields
);
2205 /* FIXME: gdb checks os9k_stabs here. */
2209 /* Add 1 to c to leave room for NULL pointer at end. */
2213 fields
= ((debug_field
*)
2214 xrealloc (fields
, alloc
* sizeof *fields
));
2217 /* If it starts with CPLUS_MARKER it is a special abbreviation,
2218 unless the CPLUS_MARKER is followed by an underscore, in
2219 which case it is just the name of an anonymous type, which we
2220 should handle like any other type name. We accept either '$'
2221 or '.', because a field name can never contain one of these
2222 characters except as a CPLUS_MARKER. */
2224 if ((*p
== '$' || *p
== '.') && p
[1] != '_')
2227 if (! parse_stab_cpp_abbrev (dhandle
, info
, pp
, fields
+ c
))
2233 /* Look for the ':' that separates the field name from the field
2234 values. Data members are delimited by a single ':', while member
2235 functions are delimited by a pair of ':'s. When we hit the member
2236 functions (if any), terminate scan loop and return. */
2238 p
= strchr (p
, ':');
2248 if (! parse_stab_one_struct_field (dhandle
, info
, pp
, p
, fields
+ c
,
2255 fields
[c
] = DEBUG_FIELD_NULL
;
2262 /* Special GNU C++ name. */
2265 parse_stab_cpp_abbrev (void *dhandle
, struct stab_handle
*info
,
2266 const char **pp
, debug_field
*retp
)
2272 const char *typename
;
2276 *retp
= DEBUG_FIELD_NULL
;
2290 /* At this point, *pp points to something like "22:23=*22...", where
2291 the type number before the ':' is the "context" and everything
2292 after is a regular type definition. Lookup the type, find it's
2293 name, and construct the field name. */
2295 context
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
2296 (debug_type
**) NULL
);
2297 if (context
== DEBUG_TYPE_NULL
)
2303 /* $vf -- a virtual function table pointer. */
2307 /* $vb -- a virtual bsomethingorother */
2308 typename
= debug_get_type_name (dhandle
, context
);
2309 if (typename
== NULL
)
2311 warn_stab (orig
, _("unnamed $vb type"));
2314 name
= concat ("_vb$", typename
, (const char *) NULL
);
2317 warn_stab (orig
, _("unrecognized C++ abbreviation"));
2318 name
= "INVALID_CPLUSPLUS_ABBREV";
2329 type
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
2330 (debug_type
**) NULL
);
2338 bitpos
= parse_number (pp
, (bfd_boolean
*) NULL
);
2346 *retp
= debug_make_field (dhandle
, name
, type
, bitpos
, 0,
2347 DEBUG_VISIBILITY_PRIVATE
);
2348 if (*retp
== DEBUG_FIELD_NULL
)
2354 /* Parse a single field in a struct or union. */
2357 parse_stab_one_struct_field (void *dhandle
, struct stab_handle
*info
,
2358 const char **pp
, const char *p
,
2359 debug_field
*retp
, bfd_boolean
*staticsp
)
2363 enum debug_visibility visibility
;
2370 /* FIXME: gdb checks ARM_DEMANGLING here. */
2372 name
= savestring (*pp
, p
- *pp
);
2377 visibility
= DEBUG_VISIBILITY_PUBLIC
;
2384 visibility
= DEBUG_VISIBILITY_PRIVATE
;
2387 visibility
= DEBUG_VISIBILITY_PROTECTED
;
2390 visibility
= DEBUG_VISIBILITY_PUBLIC
;
2393 warn_stab (orig
, _("unknown visibility character for field"));
2394 visibility
= DEBUG_VISIBILITY_PUBLIC
;
2400 type
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
2401 (debug_type
**) NULL
);
2402 if (type
== DEBUG_TYPE_NULL
)
2409 /* This is a static class member. */
2411 p
= strchr (*pp
, ';');
2418 varname
= savestring (*pp
, p
- *pp
);
2422 *retp
= debug_make_static_member (dhandle
, name
, type
, varname
,
2436 bitpos
= parse_number (pp
, (bfd_boolean
*) NULL
);
2444 bitsize
= parse_number (pp
, (bfd_boolean
*) NULL
);
2452 if (bitpos
== 0 && bitsize
== 0)
2454 /* This can happen in two cases: (1) at least for gcc 2.4.5 or
2455 so, it is a field which has been optimized out. The correct
2456 stab for this case is to use VISIBILITY_IGNORE, but that is a
2457 recent invention. (2) It is a 0-size array. For example
2458 union { int num; char str[0]; } foo. Printing "<no value>"
2459 for str in "p foo" is OK, since foo.str (and thus foo.str[3])
2460 will continue to work, and a 0-size array as a whole doesn't
2461 have any contents to print.
2463 I suspect this probably could also happen with gcc -gstabs
2464 (not -gstabs+) for static fields, and perhaps other C++
2465 extensions. Hopefully few people use -gstabs with gdb, since
2466 it is intended for dbx compatibility. */
2467 visibility
= DEBUG_VISIBILITY_IGNORE
;
2470 /* FIXME: gdb does some stuff here to mark fields as unpacked. */
2472 *retp
= debug_make_field (dhandle
, name
, type
, bitpos
, bitsize
, visibility
);
2477 /* Read member function stabs info for C++ classes. The form of each member
2480 NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
2482 An example with two member functions is:
2484 afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
2486 For the case of overloaded operators, the format is op$::*.funcs, where
2487 $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
2488 name (such as `+=') and `.' marks the end of the operator name. */
2491 parse_stab_members (void *dhandle
, struct stab_handle
*info
,
2492 const char *tagname
, const char **pp
,
2493 const int *typenums
, debug_method
**retp
)
2496 debug_method
*methods
;
2512 debug_method_variant
*variants
;
2514 unsigned int allocvars
;
2515 debug_type look_ahead_type
;
2517 p
= strchr (*pp
, ':');
2518 if (p
== NULL
|| p
[1] != ':')
2521 /* FIXME: Some systems use something other than '$' here. */
2522 if ((*pp
)[0] != 'o' || (*pp
)[1] != 'p' || (*pp
)[2] != '$')
2524 name
= savestring (*pp
, p
- *pp
);
2529 /* This is a completely wierd case. In order to stuff in the
2530 names that might contain colons (the usual name delimiter),
2531 Mike Tiemann defined a different name format which is
2532 signalled if the identifier is "op$". In that case, the
2533 format is "op$::XXXX." where XXXX is the name. This is
2534 used for names like "+" or "=". YUUUUUUUK! FIXME! */
2536 for (p
= *pp
; *p
!= '.' && *p
!= '\0'; p
++)
2543 name
= savestring (*pp
, p
- *pp
);
2548 variants
= ((debug_method_variant
*)
2549 xmalloc (allocvars
* sizeof *variants
));
2552 look_ahead_type
= DEBUG_TYPE_NULL
;
2559 enum debug_visibility visibility
;
2560 bfd_boolean constp
, volatilep
, staticp
;
2563 const char *physname
;
2564 bfd_boolean varargs
;
2566 if (look_ahead_type
!= DEBUG_TYPE_NULL
)
2568 /* g++ version 1 kludge */
2569 type
= look_ahead_type
;
2570 look_ahead_type
= DEBUG_TYPE_NULL
;
2574 type
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
2575 (debug_type
**) NULL
);
2576 if (type
== DEBUG_TYPE_NULL
)
2586 p
= strchr (*pp
, ';');
2594 if (debug_get_type_kind (dhandle
, type
) == DEBUG_KIND_METHOD
2595 && debug_get_parameter_types (dhandle
, type
, &varargs
) == NULL
)
2598 argtypes
= savestring (*pp
, p
- *pp
);
2604 visibility
= DEBUG_VISIBILITY_PRIVATE
;
2607 visibility
= DEBUG_VISIBILITY_PROTECTED
;
2610 visibility
= DEBUG_VISIBILITY_PUBLIC
;
2620 /* Normal function. */
2624 /* const member function. */
2629 /* volatile member function. */
2634 /* const volatile member function. */
2642 /* File compiled with g++ version 1; no information. */
2645 warn_stab (orig
, _("const/volatile indicator missing"));
2653 /* virtual member function, followed by index. The sign
2654 bit is supposedly set to distinguish
2655 pointers-to-methods from virtual function indicies. */
2657 voffset
= parse_number (pp
, (bfd_boolean
*) NULL
);
2664 voffset
&= 0x7fffffff;
2666 if (**pp
== ';' || *pp
== '\0')
2668 /* Must be g++ version 1. */
2669 context
= DEBUG_TYPE_NULL
;
2673 /* Figure out from whence this virtual function
2674 came. It may belong to virtual function table of
2675 one of its baseclasses. */
2676 look_ahead_type
= parse_stab_type (dhandle
, info
,
2677 (const char *) NULL
,
2679 (debug_type
**) NULL
);
2682 /* g++ version 1 overloaded methods. */
2683 context
= DEBUG_TYPE_NULL
;
2687 context
= look_ahead_type
;
2688 look_ahead_type
= DEBUG_TYPE_NULL
;
2700 /* static member function. */
2704 context
= DEBUG_TYPE_NULL
;
2705 if (strncmp (argtypes
, name
, strlen (name
)) != 0)
2710 warn_stab (orig
, "member function type missing");
2712 context
= DEBUG_TYPE_NULL
;
2718 context
= DEBUG_TYPE_NULL
;
2722 /* If the type is not a stub, then the argtypes string is
2723 the physical name of the function. Otherwise the
2724 argtypes string is the mangled form of the argument
2725 types, and the full type and the physical name must be
2726 extracted from them. */
2728 physname
= argtypes
;
2731 debug_type class_type
, return_type
;
2733 class_type
= stab_find_type (dhandle
, info
, typenums
);
2734 if (class_type
== DEBUG_TYPE_NULL
)
2736 return_type
= debug_get_return_type (dhandle
, type
);
2737 if (return_type
== DEBUG_TYPE_NULL
)
2742 type
= parse_stab_argtypes (dhandle
, info
, class_type
, name
,
2743 tagname
, return_type
, argtypes
,
2744 constp
, volatilep
, &physname
);
2745 if (type
== DEBUG_TYPE_NULL
)
2749 if (cvars
+ 1 >= allocvars
)
2752 variants
= ((debug_method_variant
*)
2754 allocvars
* sizeof *variants
));
2758 variants
[cvars
] = debug_make_method_variant (dhandle
, physname
,
2763 variants
[cvars
] = debug_make_static_method_variant (dhandle
,
2769 if (variants
[cvars
] == DEBUG_METHOD_VARIANT_NULL
)
2774 while (**pp
!= ';' && **pp
!= '\0');
2776 variants
[cvars
] = DEBUG_METHOD_VARIANT_NULL
;
2784 methods
= ((debug_method
*)
2785 xrealloc (methods
, alloc
* sizeof *methods
));
2788 methods
[c
] = debug_make_method (dhandle
, name
, variants
);
2793 if (methods
!= NULL
)
2794 methods
[c
] = DEBUG_METHOD_NULL
;
2801 /* Parse a string representing argument types for a method. Stabs
2802 tries to save space by packing argument types into a mangled
2803 string. This string should give us enough information to extract
2804 both argument types and the physical name of the function, given
2808 parse_stab_argtypes (void *dhandle
, struct stab_handle
*info
,
2809 debug_type class_type
, const char *fieldname
,
2810 const char *tagname
, debug_type return_type
,
2811 const char *argtypes
, bfd_boolean constp
,
2812 bfd_boolean volatilep
, const char **pphysname
)
2814 bfd_boolean is_full_physname_constructor
;
2815 bfd_boolean is_constructor
;
2816 bfd_boolean is_destructor
;
2818 bfd_boolean varargs
;
2819 unsigned int physname_len
= 0;
2821 /* Constructors are sometimes handled specially. */
2822 is_full_physname_constructor
= ((argtypes
[0] == '_'
2823 && argtypes
[1] == '_'
2824 && (ISDIGIT (argtypes
[2])
2825 || argtypes
[2] == 'Q'
2826 || argtypes
[2] == 't'))
2827 || strncmp (argtypes
, "__ct", 4) == 0);
2829 is_constructor
= (is_full_physname_constructor
2831 && strcmp (fieldname
, tagname
) == 0));
2832 is_destructor
= ((argtypes
[0] == '_'
2833 && (argtypes
[1] == '$' || argtypes
[1] == '.')
2834 && argtypes
[2] == '_')
2835 || strncmp (argtypes
, "__dt", 4) == 0);
2837 if (is_destructor
|| is_full_physname_constructor
)
2838 *pphysname
= argtypes
;
2842 const char *const_prefix
;
2843 const char *volatile_prefix
;
2845 unsigned int mangled_name_len
;
2848 len
= tagname
== NULL
? 0 : strlen (tagname
);
2849 const_prefix
= constp
? "C" : "";
2850 volatile_prefix
= volatilep
? "V" : "";
2853 sprintf (buf
, "__%s%s", const_prefix
, volatile_prefix
);
2854 else if (tagname
!= NULL
&& strchr (tagname
, '<') != NULL
)
2856 /* Template methods are fully mangled. */
2857 sprintf (buf
, "__%s%s", const_prefix
, volatile_prefix
);
2862 sprintf (buf
, "__%s%s%d", const_prefix
, volatile_prefix
, len
);
2864 mangled_name_len
= ((is_constructor
? 0 : strlen (fieldname
))
2870 if (fieldname
[0] == 'o'
2871 && fieldname
[1] == 'p'
2872 && (fieldname
[2] == '$' || fieldname
[2] == '.'))
2876 opname
= cplus_mangle_opname (fieldname
+ 3, 0);
2879 fprintf (stderr
, _("No mangling for \"%s\"\n"), fieldname
);
2880 return DEBUG_TYPE_NULL
;
2882 mangled_name_len
+= strlen (opname
);
2883 physname
= (char *) xmalloc (mangled_name_len
);
2884 strncpy (physname
, fieldname
, 3);
2885 strcpy (physname
+ 3, opname
);
2889 physname
= (char *) xmalloc (mangled_name_len
);
2893 strcpy (physname
, fieldname
);
2896 physname_len
= strlen (physname
);
2897 strcat (physname
, buf
);
2898 if (tagname
!= NULL
)
2899 strcat (physname
, tagname
);
2900 strcat (physname
, argtypes
);
2902 *pphysname
= physname
;
2905 if (*argtypes
== '\0' || is_destructor
)
2907 args
= (debug_type
*) xmalloc (sizeof *args
);
2909 return debug_make_method_type (dhandle
, return_type
, class_type
, args
,
2913 args
= stab_demangle_argtypes (dhandle
, info
, *pphysname
, &varargs
, physname_len
);
2915 return DEBUG_TYPE_NULL
;
2917 return debug_make_method_type (dhandle
, return_type
, class_type
, args
,
2921 /* The tail end of stabs for C++ classes that contain a virtual function
2922 pointer contains a tilde, a %, and a type number.
2923 The type number refers to the base class (possibly this class itself) which
2924 contains the vtable pointer for the current class.
2926 This function is called when we have parsed all the method declarations,
2927 so we can look for the vptr base class info. */
2930 parse_stab_tilde_field (void *dhandle
, struct stab_handle
*info
,
2931 const char **pp
, const int *typenums
,
2932 debug_type
*retvptrbase
, bfd_boolean
*retownvptr
)
2938 *retvptrbase
= DEBUG_TYPE_NULL
;
2939 *retownvptr
= FALSE
;
2943 /* If we are positioned at a ';', then skip it. */
2952 if (**pp
== '=' || **pp
== '+' || **pp
== '-')
2954 /* Obsolete flags that used to indicate the presence of
2955 constructors and/or destructors. */
2966 /* The next number is the type number of the base class (possibly
2967 our own class) which supplies the vtable for this class. */
2968 if (! parse_stab_type_number (pp
, vtypenums
))
2971 if (vtypenums
[0] == typenums
[0]
2972 && vtypenums
[1] == typenums
[1])
2981 vtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
2982 (debug_type
**) NULL
);
2983 for (p
= *pp
; *p
!= ';' && *p
!= '\0'; p
++)
2991 *retvptrbase
= vtype
;
2999 /* Read a definition of an array type. */
3002 parse_stab_array_type (void *dhandle
, struct stab_handle
*info
,
3003 const char **pp
, bfd_boolean stringp
)
3008 debug_type index_type
;
3009 bfd_boolean adjustable
;
3010 bfd_signed_vma lower
, upper
;
3011 debug_type element_type
;
3013 /* Format of an array type:
3014 "ar<index type>;lower;upper;<array_contents_type>".
3015 OS9000: "arlower,upper;<array_contents_type>".
3017 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
3018 for these, produce a type like float[][]. */
3022 /* FIXME: gdb checks os9k_stabs here. */
3024 /* If the index type is type 0, we take it as int. */
3026 if (! parse_stab_type_number (&p
, typenums
))
3027 return DEBUG_TYPE_NULL
;
3028 if (typenums
[0] == 0 && typenums
[1] == 0 && **pp
!= '=')
3030 index_type
= debug_find_named_type (dhandle
, "int");
3031 if (index_type
== DEBUG_TYPE_NULL
)
3033 index_type
= debug_make_int_type (dhandle
, 4, FALSE
);
3034 if (index_type
== DEBUG_TYPE_NULL
)
3035 return DEBUG_TYPE_NULL
;
3041 index_type
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
3042 (debug_type
**) NULL
);
3048 return DEBUG_TYPE_NULL
;
3054 if (! ISDIGIT (**pp
) && **pp
!= '-')
3060 lower
= (bfd_signed_vma
) parse_number (pp
, (bfd_boolean
*) NULL
);
3064 return DEBUG_TYPE_NULL
;
3068 if (! ISDIGIT (**pp
) && **pp
!= '-')
3074 upper
= (bfd_signed_vma
) parse_number (pp
, (bfd_boolean
*) NULL
);
3078 return DEBUG_TYPE_NULL
;
3082 element_type
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
3083 (debug_type
**) NULL
);
3084 if (element_type
== DEBUG_TYPE_NULL
)
3085 return DEBUG_TYPE_NULL
;
3093 return debug_make_array_type (dhandle
, element_type
, index_type
, lower
,
3097 /* This struct holds information about files we have seen using
3102 /* The next N_BINCL file. */
3103 struct bincl_file
*next
;
3104 /* The next N_BINCL on the stack. */
3105 struct bincl_file
*next_stack
;
3106 /* The file name. */
3108 /* The hash value. */
3110 /* The file index. */
3112 /* The list of types defined in this file. */
3113 struct stab_types
*file_types
;
3116 /* Start a new N_BINCL file, pushing it onto the stack. */
3119 push_bincl (struct stab_handle
*info
, const char *name
, bfd_vma hash
)
3121 struct bincl_file
*n
;
3123 n
= (struct bincl_file
*) xmalloc (sizeof *n
);
3124 n
->next
= info
->bincl_list
;
3125 n
->next_stack
= info
->bincl_stack
;
3128 n
->file
= info
->files
;
3129 n
->file_types
= NULL
;
3130 info
->bincl_list
= n
;
3131 info
->bincl_stack
= n
;
3134 info
->file_types
= ((struct stab_types
**)
3135 xrealloc (info
->file_types
,
3137 * sizeof *info
->file_types
)));
3138 info
->file_types
[n
->file
] = NULL
;
3141 /* Finish an N_BINCL file, at an N_EINCL, popping the name off the
3145 pop_bincl (struct stab_handle
*info
)
3147 struct bincl_file
*o
;
3149 o
= info
->bincl_stack
;
3151 return info
->main_filename
;
3152 info
->bincl_stack
= o
->next_stack
;
3154 o
->file_types
= info
->file_types
[o
->file
];
3156 if (info
->bincl_stack
== NULL
)
3157 return info
->main_filename
;
3158 return info
->bincl_stack
->name
;
3161 /* Handle an N_EXCL: get the types from the corresponding N_BINCL. */
3164 find_excl (struct stab_handle
*info
, const char *name
, bfd_vma hash
)
3166 struct bincl_file
*l
;
3169 info
->file_types
= ((struct stab_types
**)
3170 xrealloc (info
->file_types
,
3172 * sizeof *info
->file_types
)));
3174 for (l
= info
->bincl_list
; l
!= NULL
; l
= l
->next
)
3175 if (l
->hash
== hash
&& strcmp (l
->name
, name
) == 0)
3179 warn_stab (name
, _("Undefined N_EXCL"));
3180 info
->file_types
[info
->files
- 1] = NULL
;
3184 info
->file_types
[info
->files
- 1] = l
->file_types
;
3189 /* Handle a variable definition. gcc emits variable definitions for a
3190 block before the N_LBRAC, so we must hold onto them until we see
3191 it. The SunPRO compiler emits variable definitions after the
3192 N_LBRAC, so we can call debug_record_variable immediately. */
3195 stab_record_variable (void *dhandle
, struct stab_handle
*info
,
3196 const char *name
, debug_type type
,
3197 enum debug_var_kind kind
, bfd_vma val
)
3199 struct stab_pending_var
*v
;
3201 if ((kind
== DEBUG_GLOBAL
|| kind
== DEBUG_STATIC
)
3202 || ! info
->within_function
3203 || (info
->gcc_compiled
== 0 && info
->n_opt_found
))
3204 return debug_record_variable (dhandle
, name
, type
, kind
, val
);
3206 v
= (struct stab_pending_var
*) xmalloc (sizeof *v
);
3207 memset (v
, 0, sizeof *v
);
3209 v
->next
= info
->pending
;
3219 /* Emit pending variable definitions. This is called after we see the
3220 N_LBRAC that starts the block. */
3223 stab_emit_pending_vars (void *dhandle
, struct stab_handle
*info
)
3225 struct stab_pending_var
*v
;
3230 struct stab_pending_var
*next
;
3232 if (! debug_record_variable (dhandle
, v
->name
, v
->type
, v
->kind
, v
->val
))
3240 info
->pending
= NULL
;
3245 /* Find the slot for a type in the database. */
3248 stab_find_slot (struct stab_handle
*info
, const int *typenums
)
3252 struct stab_types
**ps
;
3254 filenum
= typenums
[0];
3255 index
= typenums
[1];
3257 if (filenum
< 0 || (unsigned int) filenum
>= info
->files
)
3259 fprintf (stderr
, _("Type file number %d out of range\n"), filenum
);
3264 fprintf (stderr
, _("Type index number %d out of range\n"), index
);
3268 ps
= info
->file_types
+ filenum
;
3270 while (index
>= STAB_TYPES_SLOTS
)
3274 *ps
= (struct stab_types
*) xmalloc (sizeof **ps
);
3275 memset (*ps
, 0, sizeof **ps
);
3278 index
-= STAB_TYPES_SLOTS
;
3282 *ps
= (struct stab_types
*) xmalloc (sizeof **ps
);
3283 memset (*ps
, 0, sizeof **ps
);
3286 return (*ps
)->types
+ index
;
3289 /* Find a type given a type number. If the type has not been
3290 allocated yet, create an indirect type. */
3293 stab_find_type (void *dhandle
, struct stab_handle
*info
, const int *typenums
)
3297 if (typenums
[0] == 0 && typenums
[1] < 0)
3299 /* A negative type number indicates an XCOFF builtin type. */
3300 return stab_xcoff_builtin_type (dhandle
, info
, typenums
[1]);
3303 slot
= stab_find_slot (info
, typenums
);
3305 return DEBUG_TYPE_NULL
;
3307 if (*slot
== DEBUG_TYPE_NULL
)
3308 return debug_make_indirect_type (dhandle
, slot
, (const char *) NULL
);
3313 /* Record that a given type number refers to a given type. */
3316 stab_record_type (void *dhandle ATTRIBUTE_UNUSED
, struct stab_handle
*info
,
3317 const int *typenums
, debug_type type
)
3321 slot
= stab_find_slot (info
, typenums
);
3325 /* gdb appears to ignore type redefinitions, so we do as well. */
3332 /* Return an XCOFF builtin type. */
3335 stab_xcoff_builtin_type (void *dhandle
, struct stab_handle
*info
,
3341 if (typenum
>= 0 || typenum
< -XCOFF_TYPE_COUNT
)
3343 fprintf (stderr
, _("Unrecognized XCOFF type %d\n"), typenum
);
3344 return DEBUG_TYPE_NULL
;
3346 if (info
->xcoff_types
[-typenum
] != NULL
)
3347 return info
->xcoff_types
[-typenum
];
3352 /* The size of this and all the other types are fixed, defined
3353 by the debugging format. */
3355 rettype
= debug_make_int_type (dhandle
, 4, FALSE
);
3359 rettype
= debug_make_int_type (dhandle
, 1, FALSE
);
3363 rettype
= debug_make_int_type (dhandle
, 2, FALSE
);
3367 rettype
= debug_make_int_type (dhandle
, 4, FALSE
);
3370 name
= "unsigned char";
3371 rettype
= debug_make_int_type (dhandle
, 1, TRUE
);
3374 name
= "signed char";
3375 rettype
= debug_make_int_type (dhandle
, 1, FALSE
);
3378 name
= "unsigned short";
3379 rettype
= debug_make_int_type (dhandle
, 2, TRUE
);
3382 name
= "unsigned int";
3383 rettype
= debug_make_int_type (dhandle
, 4, TRUE
);
3387 rettype
= debug_make_int_type (dhandle
, 4, TRUE
);
3389 name
= "unsigned long";
3390 rettype
= debug_make_int_type (dhandle
, 4, TRUE
);
3394 rettype
= debug_make_void_type (dhandle
);
3397 /* IEEE single precision (32 bit). */
3399 rettype
= debug_make_float_type (dhandle
, 4);
3402 /* IEEE double precision (64 bit). */
3404 rettype
= debug_make_float_type (dhandle
, 8);
3407 /* This is an IEEE double on the RS/6000, and different machines
3408 with different sizes for "long double" should use different
3409 negative type numbers. See stabs.texinfo. */
3410 name
= "long double";
3411 rettype
= debug_make_float_type (dhandle
, 8);
3415 rettype
= debug_make_int_type (dhandle
, 4, FALSE
);
3419 rettype
= debug_make_bool_type (dhandle
, 4);
3422 name
= "short real";
3423 rettype
= debug_make_float_type (dhandle
, 4);
3427 rettype
= debug_make_float_type (dhandle
, 8);
3437 rettype
= debug_make_int_type (dhandle
, 1, TRUE
);
3441 rettype
= debug_make_bool_type (dhandle
, 1);
3445 rettype
= debug_make_bool_type (dhandle
, 2);
3449 rettype
= debug_make_bool_type (dhandle
, 4);
3453 rettype
= debug_make_bool_type (dhandle
, 4);
3456 /* Complex type consisting of two IEEE single precision values. */
3458 rettype
= debug_make_complex_type (dhandle
, 8);
3461 /* Complex type consisting of two IEEE double precision values. */
3462 name
= "double complex";
3463 rettype
= debug_make_complex_type (dhandle
, 16);
3467 rettype
= debug_make_int_type (dhandle
, 1, FALSE
);
3471 rettype
= debug_make_int_type (dhandle
, 2, FALSE
);
3475 rettype
= debug_make_int_type (dhandle
, 4, FALSE
);
3480 rettype
= debug_make_int_type (dhandle
, 2, FALSE
);
3484 rettype
= debug_make_int_type (dhandle
, 8, FALSE
);
3487 name
= "unsigned long long";
3488 rettype
= debug_make_int_type (dhandle
, 8, TRUE
);
3492 rettype
= debug_make_bool_type (dhandle
, 8);
3496 rettype
= debug_make_int_type (dhandle
, 8, FALSE
);
3502 rettype
= debug_name_type (dhandle
, name
, rettype
);
3504 info
->xcoff_types
[-typenum
] = rettype
;
3509 /* Find or create a tagged type. */
3512 stab_find_tagged_type (void *dhandle
, struct stab_handle
*info
,
3513 const char *p
, int len
, enum debug_type_kind kind
)
3517 struct stab_tag
*st
;
3519 name
= savestring (p
, len
);
3521 /* We pass DEBUG_KIND_ILLEGAL because we want all tags in the same
3522 namespace. This is right for C, and I don't know how to handle
3523 other languages. FIXME. */
3524 dtype
= debug_find_tagged_type (dhandle
, name
, DEBUG_KIND_ILLEGAL
);
3525 if (dtype
!= DEBUG_TYPE_NULL
)
3531 /* We need to allocate an entry on the undefined tag list. */
3532 for (st
= info
->tags
; st
!= NULL
; st
= st
->next
)
3534 if (st
->name
[0] == name
[0]
3535 && strcmp (st
->name
, name
) == 0)
3537 if (st
->kind
== DEBUG_KIND_ILLEGAL
)
3545 st
= (struct stab_tag
*) xmalloc (sizeof *st
);
3546 memset (st
, 0, sizeof *st
);
3548 st
->next
= info
->tags
;
3551 st
->slot
= DEBUG_TYPE_NULL
;
3552 st
->type
= debug_make_indirect_type (dhandle
, &st
->slot
, name
);
3559 /* In order to get the correct argument types for a stubbed method, we
3560 need to extract the argument types from a C++ mangled string.
3561 Since the argument types can refer back to the return type, this
3562 means that we must demangle the entire physical name. In gdb this
3563 is done by calling cplus_demangle and running the results back
3564 through the C++ expression parser. Since we have no expression
3565 parser, we must duplicate much of the work of cplus_demangle here.
3567 We assume that GNU style demangling is used, since this is only
3568 done for method stubs, and only g++ should output that form of
3569 debugging information. */
3571 /* This structure is used to hold a pointer to type information which
3572 demangling a string. */
3574 struct stab_demangle_typestring
3576 /* The start of the type. This is not null terminated. */
3577 const char *typestring
;
3578 /* The length of the type. */
3582 /* This structure is used to hold information while demangling a
3585 struct stab_demangle_info
3587 /* The debugging information handle. */
3589 /* The stab information handle. */
3590 struct stab_handle
*info
;
3591 /* The array of arguments we are building. */
3593 /* Whether the method takes a variable number of arguments. */
3594 bfd_boolean varargs
;
3595 /* The array of types we have remembered. */
3596 struct stab_demangle_typestring
*typestrings
;
3597 /* The number of typestrings. */
3598 unsigned int typestring_count
;
3599 /* The number of typestring slots we have allocated. */
3600 unsigned int typestring_alloc
;
3603 static void stab_bad_demangle (const char *);
3604 static unsigned int stab_demangle_count (const char **);
3605 static bfd_boolean
stab_demangle_get_count (const char **, unsigned int *);
3606 static bfd_boolean stab_demangle_prefix
3607 (struct stab_demangle_info
*, const char **, unsigned int);
3608 static bfd_boolean stab_demangle_function_name
3609 (struct stab_demangle_info
*, const char **, const char *);
3610 static bfd_boolean stab_demangle_signature
3611 (struct stab_demangle_info
*, const char **);
3612 static bfd_boolean stab_demangle_qualified
3613 (struct stab_demangle_info
*, const char **, debug_type
*);
3614 static bfd_boolean stab_demangle_template
3615 (struct stab_demangle_info
*, const char **, char **);
3616 static bfd_boolean stab_demangle_class
3617 (struct stab_demangle_info
*, const char **, const char **);
3618 static bfd_boolean stab_demangle_args
3619 (struct stab_demangle_info
*, const char **, debug_type
**, bfd_boolean
*);
3620 static bfd_boolean stab_demangle_arg
3621 (struct stab_demangle_info
*, const char **, debug_type
**,
3622 unsigned int *, unsigned int *);
3623 static bfd_boolean stab_demangle_type
3624 (struct stab_demangle_info
*, const char **, debug_type
*);
3625 static bfd_boolean stab_demangle_fund_type
3626 (struct stab_demangle_info
*, const char **, debug_type
*);
3627 static bfd_boolean stab_demangle_remember_type
3628 (struct stab_demangle_info
*, const char *, int);
3630 /* Warn about a bad demangling. */
3633 stab_bad_demangle (const char *s
)
3635 fprintf (stderr
, _("bad mangled name `%s'\n"), s
);
3638 /* Get a count from a stab string. */
3641 stab_demangle_count (const char **pp
)
3646 while (ISDIGIT (**pp
))
3649 count
+= **pp
- '0';
3655 /* Require a count in a string. The count may be multiple digits, in
3656 which case it must end in an underscore. */
3659 stab_demangle_get_count (const char **pp
, unsigned int *pi
)
3661 if (! ISDIGIT (**pp
))
3679 while (ISDIGIT (*p
));
3690 /* This function demangles a physical name, returning a NULL
3691 terminated array of argument types. */
3694 stab_demangle_argtypes (void *dhandle
, struct stab_handle
*info
,
3695 const char *physname
, bfd_boolean
*pvarargs
,
3696 unsigned int physname_len
)
3698 struct stab_demangle_info minfo
;
3700 minfo
.dhandle
= dhandle
;
3703 minfo
.varargs
= FALSE
;
3704 minfo
.typestring_alloc
= 10;
3705 minfo
.typestrings
= ((struct stab_demangle_typestring
*)
3706 xmalloc (minfo
.typestring_alloc
3707 * sizeof *minfo
.typestrings
));
3708 minfo
.typestring_count
= 0;
3710 /* cplus_demangle checks for special GNU mangled forms, but we can't
3711 see any of them in mangled method argument types. */
3713 if (! stab_demangle_prefix (&minfo
, &physname
, physname_len
))
3716 if (*physname
!= '\0')
3718 if (! stab_demangle_signature (&minfo
, &physname
))
3722 free (minfo
.typestrings
);
3723 minfo
.typestrings
= NULL
;
3725 if (minfo
.args
== NULL
)
3726 fprintf (stderr
, _("no argument types in mangled string\n"));
3728 *pvarargs
= minfo
.varargs
;
3732 if (minfo
.typestrings
!= NULL
)
3733 free (minfo
.typestrings
);
3737 /* Demangle the prefix of the mangled name. */
3740 stab_demangle_prefix (struct stab_demangle_info
*minfo
, const char **pp
,
3741 unsigned int physname_len
)
3746 /* cplus_demangle checks for global constructors and destructors,
3747 but we can't see them in mangled argument types. */
3750 scan
= *pp
+ physname_len
;
3753 /* Look for `__'. */
3756 scan
= strchr (scan
, '_');
3757 while (scan
!= NULL
&& *++scan
!= '_');
3761 stab_bad_demangle (*pp
);
3767 /* We found `__'; move ahead to the last contiguous `__' pair. */
3768 i
= strspn (scan
, "_");
3774 && (ISDIGIT (scan
[2])
3778 /* This is a GNU style constructor name. */
3782 else if (scan
== *pp
3783 && ! ISDIGIT (scan
[2])
3786 /* Look for the `__' that separates the prefix from the
3788 while (*scan
== '_')
3790 scan
= strstr (scan
, "__");
3791 if (scan
== NULL
|| scan
[2] == '\0')
3793 stab_bad_demangle (*pp
);
3797 return stab_demangle_function_name (minfo
, pp
, scan
);
3799 else if (scan
[2] != '\0')
3801 /* The name doesn't start with `__', but it does contain `__'. */
3802 return stab_demangle_function_name (minfo
, pp
, scan
);
3806 stab_bad_demangle (*pp
);
3812 /* Demangle a function name prefix. The scan argument points to the
3813 double underscore which separates the function name from the
3817 stab_demangle_function_name (struct stab_demangle_info
*minfo
,
3818 const char **pp
, const char *scan
)
3822 /* The string from *pp to scan is the name of the function. We
3823 don't care about the name, since we just looking for argument
3824 types. However, for conversion operators, the name may include a
3825 type which we must remember in order to handle backreferences. */
3831 && strncmp (name
, "type", 4) == 0
3832 && (name
[4] == '$' || name
[4] == '.'))
3836 /* This is a type conversion operator. */
3838 if (! stab_demangle_type (minfo
, &tem
, (debug_type
*) NULL
))
3841 else if (name
[0] == '_'
3848 /* This is a type conversion operator. */
3850 if (! stab_demangle_type (minfo
, &tem
, (debug_type
*) NULL
))
3857 /* Demangle the signature. This is where the argument types are
3861 stab_demangle_signature (struct stab_demangle_info
*minfo
, const char **pp
)
3864 bfd_boolean expect_func
, func_done
;
3869 expect_func
= FALSE
;
3873 while (**pp
!= '\0')
3879 if (! stab_demangle_qualified (minfo
, pp
, (debug_type
*) NULL
)
3880 || ! stab_demangle_remember_type (minfo
, hold
, *pp
- hold
))
3887 /* Static member function. FIXME: Can this happen? */
3894 /* Const member function. */
3900 case '0': case '1': case '2': case '3': case '4':
3901 case '5': case '6': case '7': case '8': case '9':
3904 if (! stab_demangle_class (minfo
, pp
, (const char **) NULL
)
3905 || ! stab_demangle_remember_type (minfo
, hold
, *pp
- hold
))
3912 /* Function. I don't know if this actually happens with g++
3917 if (! stab_demangle_args (minfo
, pp
, &minfo
->args
, &minfo
->varargs
))
3925 if (! stab_demangle_template (minfo
, pp
, (char **) NULL
)
3926 || ! stab_demangle_remember_type (minfo
, hold
, *pp
- hold
))
3933 /* At the outermost level, we cannot have a return type
3934 specified, so if we run into another '_' at this point we
3935 are dealing with a mangled name that is either bogus, or
3936 has been mangled by some algorithm we don't know how to
3937 deal with. So just reject the entire demangling. */
3938 stab_bad_demangle (orig
);
3942 /* Assume we have stumbled onto the first outermost function
3943 argument token, and start processing args. */
3945 if (! stab_demangle_args (minfo
, pp
, &minfo
->args
, &minfo
->varargs
))
3953 if (! stab_demangle_args (minfo
, pp
, &minfo
->args
, &minfo
->varargs
))
3960 /* With GNU style demangling, bar__3foo is 'foo::bar(void)', and
3961 bar__3fooi is 'foo::bar(int)'. We get here when we find the
3962 first case, and need to ensure that the '(void)' gets added
3963 to the current declp. */
3964 if (! stab_demangle_args (minfo
, pp
, &minfo
->args
, &minfo
->varargs
))
3971 /* Demangle a qualified name, such as "Q25Outer5Inner" which is the
3972 mangled form of "Outer::Inner". */
3975 stab_demangle_qualified (struct stab_demangle_info
*minfo
, const char **pp
,
3980 unsigned int qualifiers
;
3988 /* GNU mangled name with more than 9 classes. The count is
3989 preceded by an underscore (to distinguish it from the <= 9
3990 case) and followed by an underscore. */
3992 if (! ISDIGIT (*p
) || *p
== '0')
3994 stab_bad_demangle (orig
);
3997 qualifiers
= atoi (p
);
3998 while (ISDIGIT (*p
))
4002 stab_bad_demangle (orig
);
4008 case '1': case '2': case '3': case '4': case '5':
4009 case '6': case '7': case '8': case '9':
4010 qualifiers
= (*pp
)[1] - '0';
4011 /* Skip an optional underscore after the count. */
4012 if ((*pp
)[2] == '_')
4019 stab_bad_demangle (orig
);
4023 context
= DEBUG_TYPE_NULL
;
4025 /* Pick off the names. */
4026 while (qualifiers
-- > 0)
4034 if (! stab_demangle_template (minfo
, pp
,
4035 ptype
!= NULL
? &name
: NULL
))
4040 context
= stab_find_tagged_type (minfo
->dhandle
, minfo
->info
,
4041 name
, strlen (name
),
4044 if (context
== DEBUG_TYPE_NULL
)
4052 len
= stab_demangle_count (pp
);
4053 if (strlen (*pp
) < len
)
4055 stab_bad_demangle (orig
);
4061 const debug_field
*fields
;
4064 if (context
!= DEBUG_TYPE_NULL
)
4065 fields
= debug_get_fields (minfo
->dhandle
, context
);
4067 context
= DEBUG_TYPE_NULL
;
4073 /* Try to find the type by looking through the
4074 fields of context until we find a field with the
4075 same type. This ought to work for a class
4076 defined within a class, but it won't work for,
4077 e.g., an enum defined within a class. stabs does
4078 not give us enough information to figure out the
4081 name
= savestring (*pp
, len
);
4083 for (; *fields
!= DEBUG_FIELD_NULL
; fields
++)
4088 ft
= debug_get_field_type (minfo
->dhandle
, *fields
);
4091 dn
= debug_get_type_name (minfo
->dhandle
, ft
);
4092 if (dn
!= NULL
&& strcmp (dn
, name
) == 0)
4102 if (context
== DEBUG_TYPE_NULL
)
4104 /* We have to fall back on finding the type by name.
4105 If there are more types to come, then this must
4106 be a class. Otherwise, it could be anything. */
4108 if (qualifiers
== 0)
4112 name
= savestring (*pp
, len
);
4113 context
= debug_find_named_type (minfo
->dhandle
,
4118 if (context
== DEBUG_TYPE_NULL
)
4120 context
= stab_find_tagged_type (minfo
->dhandle
,
4124 ? DEBUG_KIND_ILLEGAL
4125 : DEBUG_KIND_CLASS
));
4126 if (context
== DEBUG_TYPE_NULL
)
4142 /* Demangle a template. If PNAME is not NULL, this sets *PNAME to a
4143 string representation of the template. */
4146 stab_demangle_template (struct stab_demangle_info
*minfo
, const char **pp
,
4156 /* Skip the template name. */
4157 r
= stab_demangle_count (pp
);
4158 if (r
== 0 || strlen (*pp
) < r
)
4160 stab_bad_demangle (orig
);
4165 /* Get the size of the parameter list. */
4166 if (stab_demangle_get_count (pp
, &r
) == 0)
4168 stab_bad_demangle (orig
);
4172 for (i
= 0; i
< r
; i
++)
4176 /* This is a type parameter. */
4178 if (! stab_demangle_type (minfo
, pp
, (debug_type
*) NULL
))
4184 bfd_boolean pointerp
, realp
, integralp
, charp
, boolp
;
4195 /* This is a value parameter. */
4197 if (! stab_demangle_type (minfo
, pp
, (debug_type
*) NULL
))
4200 while (*old_p
!= '\0' && ! done
)
4210 case 'C': /* Const. */
4211 case 'S': /* Signed. */
4212 case 'U': /* Unsigned. */
4213 case 'V': /* Volatile. */
4214 case 'F': /* Function. */
4215 case 'M': /* Member function. */
4219 case 'Q': /* Qualified name. */
4223 case 'T': /* Remembered type. */
4225 case 'v': /* Void. */
4227 case 'x': /* Long long. */
4228 case 'l': /* Long. */
4229 case 'i': /* Int. */
4230 case 's': /* Short. */
4231 case 'w': /* Wchar_t. */
4235 case 'b': /* Bool. */
4239 case 'c': /* Char. */
4243 case 'r': /* Long double. */
4244 case 'd': /* Double. */
4245 case 'f': /* Float. */
4250 /* Assume it's a user defined integral type. */
4261 while (ISDIGIT (**pp
))
4270 val
= stab_demangle_count (pp
);
4273 stab_bad_demangle (orig
);
4281 val
= stab_demangle_count (pp
);
4282 if (val
!= 0 && val
!= 1)
4284 stab_bad_demangle (orig
);
4292 while (ISDIGIT (**pp
))
4297 while (ISDIGIT (**pp
))
4303 while (ISDIGIT (**pp
))
4311 if (! stab_demangle_get_count (pp
, &len
))
4313 stab_bad_demangle (orig
);
4321 /* We can translate this to a string fairly easily by invoking the
4322 regular demangling routine. */
4325 char *s1
, *s2
, *s3
, *s4
= NULL
;
4328 s1
= savestring (orig
, *pp
- orig
);
4330 s2
= concat ("NoSuchStrinG__", s1
, (const char *) NULL
);
4334 s3
= cplus_demangle (s2
, DMGL_ANSI
);
4339 s4
= strstr (s3
, "::NoSuchStrinG");
4340 if (s3
== NULL
|| s4
== NULL
)
4342 stab_bad_demangle (orig
);
4348 /* Eliminating all spaces, except those between > characters,
4349 makes it more likely that the demangled name will match the
4350 name which g++ used as the structure name. */
4351 for (from
= to
= s3
; from
!= s4
; ++from
)
4353 || (from
[1] == '>' && from
> s3
&& from
[-1] == '>'))
4356 *pname
= savestring (s3
, to
- s3
);
4364 /* Demangle a class name. */
4367 stab_demangle_class (struct stab_demangle_info
*minfo ATTRIBUTE_UNUSED
,
4368 const char **pp
, const char **pstart
)
4375 n
= stab_demangle_count (pp
);
4376 if (strlen (*pp
) < n
)
4378 stab_bad_demangle (orig
);
4390 /* Demangle function arguments. If the pargs argument is not NULL, it
4391 is set to a NULL terminated array holding the arguments. */
4394 stab_demangle_args (struct stab_demangle_info
*minfo
, const char **pp
,
4395 debug_type
**pargs
, bfd_boolean
*pvarargs
)
4398 unsigned int alloc
, count
;
4405 *pargs
= (debug_type
*) xmalloc (alloc
* sizeof **pargs
);
4410 while (**pp
!= '_' && **pp
!= '\0' && **pp
!= 'e')
4412 if (**pp
== 'N' || **pp
== 'T')
4420 if (temptype
== 'T')
4424 if (! stab_demangle_get_count (pp
, &r
))
4426 stab_bad_demangle (orig
);
4431 if (! stab_demangle_get_count (pp
, &t
))
4433 stab_bad_demangle (orig
);
4437 if (t
>= minfo
->typestring_count
)
4439 stab_bad_demangle (orig
);
4446 tem
= minfo
->typestrings
[t
].typestring
;
4447 if (! stab_demangle_arg (minfo
, &tem
, pargs
, &count
, &alloc
))
4453 if (! stab_demangle_arg (minfo
, pp
, pargs
, &count
, &alloc
))
4459 (*pargs
)[count
] = DEBUG_TYPE_NULL
;
4471 /* Demangle a single argument. */
4474 stab_demangle_arg (struct stab_demangle_info
*minfo
, const char **pp
,
4475 debug_type
**pargs
, unsigned int *pcount
,
4476 unsigned int *palloc
)
4482 if (! stab_demangle_type (minfo
, pp
,
4483 pargs
== NULL
? (debug_type
*) NULL
: &type
)
4484 || ! stab_demangle_remember_type (minfo
, start
, *pp
- start
))
4489 if (type
== DEBUG_TYPE_NULL
)
4492 if (*pcount
+ 1 >= *palloc
)
4495 *pargs
= ((debug_type
*)
4496 xrealloc (*pargs
, *palloc
* sizeof **pargs
));
4498 (*pargs
)[*pcount
] = type
;
4505 /* Demangle a type. If the ptype argument is not NULL, *ptype is set
4506 to the newly allocated type. */
4509 stab_demangle_type (struct stab_demangle_info
*minfo
, const char **pp
,
4520 /* A pointer type. */
4522 if (! stab_demangle_type (minfo
, pp
, ptype
))
4525 *ptype
= debug_make_pointer_type (minfo
->dhandle
, *ptype
);
4529 /* A reference type. */
4531 if (! stab_demangle_type (minfo
, pp
, ptype
))
4534 *ptype
= debug_make_reference_type (minfo
->dhandle
, *ptype
);
4544 while (**pp
!= '\0' && **pp
!= '_')
4546 if (! ISDIGIT (**pp
))
4548 stab_bad_demangle (orig
);
4557 stab_bad_demangle (orig
);
4562 if (! stab_demangle_type (minfo
, pp
, ptype
))
4566 debug_type int_type
;
4568 int_type
= debug_find_named_type (minfo
->dhandle
, "int");
4569 if (int_type
== NULL
)
4570 int_type
= debug_make_int_type (minfo
->dhandle
, 4, FALSE
);
4571 *ptype
= debug_make_array_type (minfo
->dhandle
, *ptype
, int_type
,
4578 /* A back reference to a remembered type. */
4584 if (! stab_demangle_get_count (pp
, &i
))
4586 stab_bad_demangle (orig
);
4589 if (i
>= minfo
->typestring_count
)
4591 stab_bad_demangle (orig
);
4594 p
= minfo
->typestrings
[i
].typestring
;
4595 if (! stab_demangle_type (minfo
, &p
, ptype
))
4604 bfd_boolean varargs
;
4607 if (! stab_demangle_args (minfo
, pp
,
4609 ? (debug_type
**) NULL
4612 ? (bfd_boolean
*) NULL
4617 /* cplus_demangle will accept a function without a return
4618 type, but I don't know when that will happen, or what
4619 to do if it does. */
4620 stab_bad_demangle (orig
);
4624 if (! stab_demangle_type (minfo
, pp
, ptype
))
4627 *ptype
= debug_make_function_type (minfo
->dhandle
, *ptype
, args
,
4636 bfd_boolean memberp
, constp
, volatilep
;
4637 debug_type class_type
= DEBUG_TYPE_NULL
;
4639 bfd_boolean varargs
;
4643 memberp
= **pp
== 'M';
4652 n
= stab_demangle_count (pp
);
4653 if (strlen (*pp
) < n
)
4655 stab_bad_demangle (orig
);
4663 class_type
= stab_find_tagged_type (minfo
->dhandle
,
4667 if (class_type
== DEBUG_TYPE_NULL
)
4671 else if (**pp
== 'Q')
4673 if (! stab_demangle_qualified (minfo
, pp
,
4675 ? (debug_type
*) NULL
4681 stab_bad_demangle (orig
);
4692 else if (**pp
== 'V')
4699 stab_bad_demangle (orig
);
4703 if (! stab_demangle_args (minfo
, pp
,
4705 ? (debug_type
**) NULL
4708 ? (bfd_boolean
*) NULL
4715 stab_bad_demangle (orig
);
4720 if (! stab_demangle_type (minfo
, pp
, ptype
))
4726 *ptype
= debug_make_offset_type (minfo
->dhandle
, class_type
,
4730 /* FIXME: We have no way to record constp or
4732 *ptype
= debug_make_method_type (minfo
->dhandle
, *ptype
,
4733 class_type
, args
, varargs
);
4741 if (! stab_demangle_type (minfo
, pp
, ptype
))
4747 if (! stab_demangle_type (minfo
, pp
, ptype
))
4750 *ptype
= debug_make_const_type (minfo
->dhandle
, *ptype
);
4758 if (! stab_demangle_qualified (minfo
, pp
, ptype
))
4764 if (! stab_demangle_fund_type (minfo
, pp
, ptype
))
4772 /* Demangle a fundamental type. If the ptype argument is not NULL,
4773 *ptype is set to the newly allocated type. */
4776 stab_demangle_fund_type (struct stab_demangle_info
*minfo
, const char **pp
,
4780 bfd_boolean constp
, volatilep
, unsignedp
, signedp
;
4825 /* cplus_demangle permits this, but I don't know what it means. */
4826 stab_bad_demangle (orig
);
4829 case 'v': /* void */
4832 *ptype
= debug_find_named_type (minfo
->dhandle
, "void");
4833 if (*ptype
== DEBUG_TYPE_NULL
)
4834 *ptype
= debug_make_void_type (minfo
->dhandle
);
4839 case 'x': /* long long */
4842 *ptype
= debug_find_named_type (minfo
->dhandle
,
4844 ? "long long unsigned int"
4845 : "long long int"));
4846 if (*ptype
== DEBUG_TYPE_NULL
)
4847 *ptype
= debug_make_int_type (minfo
->dhandle
, 8, unsignedp
);
4852 case 'l': /* long */
4855 *ptype
= debug_find_named_type (minfo
->dhandle
,
4857 ? "long unsigned int"
4859 if (*ptype
== DEBUG_TYPE_NULL
)
4860 *ptype
= debug_make_int_type (minfo
->dhandle
, 4, unsignedp
);
4868 *ptype
= debug_find_named_type (minfo
->dhandle
,
4872 if (*ptype
== DEBUG_TYPE_NULL
)
4873 *ptype
= debug_make_int_type (minfo
->dhandle
, 4, unsignedp
);
4878 case 's': /* short */
4881 *ptype
= debug_find_named_type (minfo
->dhandle
,
4883 ? "short unsigned int"
4885 if (*ptype
== DEBUG_TYPE_NULL
)
4886 *ptype
= debug_make_int_type (minfo
->dhandle
, 2, unsignedp
);
4891 case 'b': /* bool */
4894 *ptype
= debug_find_named_type (minfo
->dhandle
, "bool");
4895 if (*ptype
== DEBUG_TYPE_NULL
)
4896 *ptype
= debug_make_bool_type (minfo
->dhandle
, 4);
4901 case 'c': /* char */
4904 *ptype
= debug_find_named_type (minfo
->dhandle
,
4910 if (*ptype
== DEBUG_TYPE_NULL
)
4911 *ptype
= debug_make_int_type (minfo
->dhandle
, 1, unsignedp
);
4916 case 'w': /* wchar_t */
4919 *ptype
= debug_find_named_type (minfo
->dhandle
, "__wchar_t");
4920 if (*ptype
== DEBUG_TYPE_NULL
)
4921 *ptype
= debug_make_int_type (minfo
->dhandle
, 2, TRUE
);
4926 case 'r': /* long double */
4929 *ptype
= debug_find_named_type (minfo
->dhandle
, "long double");
4930 if (*ptype
== DEBUG_TYPE_NULL
)
4931 *ptype
= debug_make_float_type (minfo
->dhandle
, 8);
4936 case 'd': /* double */
4939 *ptype
= debug_find_named_type (minfo
->dhandle
, "double");
4940 if (*ptype
== DEBUG_TYPE_NULL
)
4941 *ptype
= debug_make_float_type (minfo
->dhandle
, 8);
4946 case 'f': /* float */
4949 *ptype
= debug_find_named_type (minfo
->dhandle
, "float");
4950 if (*ptype
== DEBUG_TYPE_NULL
)
4951 *ptype
= debug_make_float_type (minfo
->dhandle
, 4);
4958 if (! ISDIGIT (**pp
))
4960 stab_bad_demangle (orig
);
4964 case '0': case '1': case '2': case '3': case '4':
4965 case '5': case '6': case '7': case '8': case '9':
4969 if (! stab_demangle_class (minfo
, pp
, &hold
))
4975 name
= savestring (hold
, *pp
- hold
);
4976 *ptype
= debug_find_named_type (minfo
->dhandle
, name
);
4978 if (*ptype
== DEBUG_TYPE_NULL
)
4980 /* FIXME: It is probably incorrect to assume that
4981 undefined types are tagged types. */
4982 *ptype
= stab_find_tagged_type (minfo
->dhandle
, minfo
->info
,
4984 DEBUG_KIND_ILLEGAL
);
4985 if (*ptype
== DEBUG_TYPE_NULL
)
4996 if (! stab_demangle_template (minfo
, pp
,
4997 ptype
!= NULL
? &name
: NULL
))
5001 *ptype
= stab_find_tagged_type (minfo
->dhandle
, minfo
->info
,
5002 name
, strlen (name
),
5005 if (*ptype
== DEBUG_TYPE_NULL
)
5012 stab_bad_demangle (orig
);
5019 *ptype
= debug_make_const_type (minfo
->dhandle
, *ptype
);
5021 *ptype
= debug_make_volatile_type (minfo
->dhandle
, *ptype
);
5027 /* Remember a type string in a demangled string. */
5030 stab_demangle_remember_type (struct stab_demangle_info
*minfo
,
5031 const char *p
, int len
)
5033 if (minfo
->typestring_count
>= minfo
->typestring_alloc
)
5035 minfo
->typestring_alloc
+= 10;
5036 minfo
->typestrings
= ((struct stab_demangle_typestring
*)
5037 xrealloc (minfo
->typestrings
,
5038 (minfo
->typestring_alloc
5039 * sizeof *minfo
->typestrings
)));
5042 minfo
->typestrings
[minfo
->typestring_count
].typestring
= p
;
5043 minfo
->typestrings
[minfo
->typestring_count
].len
= (unsigned int) len
;
5044 ++minfo
->typestring_count
;