1 /* stabs.c -- Parse stabs debugging information
2 Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
3 2005, 2006, 2007, 2008, 2009, 2010, 2011 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 3 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., 51 Franklin Street - Fifth Floor, 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. */
30 #include "libiberty.h"
31 #include "safe-ctype.h"
35 #include "filenames.h"
36 #include "aout/aout64.h"
37 #include "aout/stab_gnu.h"
39 /* The number of predefined XCOFF types. */
41 #define XCOFF_TYPE_COUNT 34
43 /* This structure is used as a handle so that the stab parsing doesn't
44 need to use any static variables. */
50 /* TRUE if this is stabs in sections. */
52 /* The symbol table. */
54 /* The number of symbols. */
56 /* The accumulated file name string. */
58 /* The value of the last N_SO symbol. */
60 /* The value of the start of the file, so that we can handle file
61 relative N_LBRAC and N_RBRAC symbols. */
62 bfd_vma file_start_offset
;
63 /* The offset of the start of the function, so that we can handle
64 function relative N_LBRAC and N_RBRAC symbols. */
65 bfd_vma function_start_offset
;
66 /* The version number of gcc which compiled the current compilation
67 unit, 0 if not compiled by gcc. */
69 /* Whether an N_OPT symbol was seen that was not generated by gcc,
70 so that we can detect the SunPRO compiler. */
71 bfd_boolean n_opt_found
;
72 /* The main file name. */
74 /* A stack of unfinished N_BINCL files. */
75 struct bincl_file
*bincl_stack
;
76 /* A list of finished N_BINCL files. */
77 struct bincl_file
*bincl_list
;
78 /* Whether we are inside a function or not. */
79 bfd_boolean within_function
;
80 /* The address of the end of the function, used if we have seen an
81 N_FUN symbol while in a function. This is -1 if we have not seen
82 an N_FUN (the normal case). */
84 /* The depth of block nesting. */
86 /* List of pending variable definitions. */
87 struct stab_pending_var
*pending
;
88 /* Number of files for which we have types. */
90 /* Lists of types per file. */
91 struct stab_types
**file_types
;
92 /* Predefined XCOFF types. */
93 debug_type xcoff_types
[XCOFF_TYPE_COUNT
];
95 struct stab_tag
*tags
;
96 /* Set by parse_stab_type if it sees a structure defined as a cross
97 reference to itself. Reset by parse_stab_type otherwise. */
98 bfd_boolean self_crossref
;
101 /* A list of these structures is used to hold pending variable
102 definitions seen before the N_LBRAC of a block. */
104 struct stab_pending_var
106 /* Next pending variable definition. */
107 struct stab_pending_var
*next
;
113 enum debug_var_kind kind
;
118 /* A list of these structures is used to hold the types for a single
123 /* Next set of slots for this file. */
124 struct stab_types
*next
;
125 /* Types indexed by type number. */
126 #define STAB_TYPES_SLOTS (16)
127 debug_type types
[STAB_TYPES_SLOTS
];
130 /* We keep a list of undefined tags that we encounter, so that we can
131 fill them in if the tag is later defined. */
135 /* Next undefined tag. */
136 struct stab_tag
*next
;
140 enum debug_type_kind kind
;
141 /* Slot to hold real type when we discover it. If we don't, we fill
142 in an undefined tag type. */
144 /* Indirect type we have created to point at slot. */
148 static char *savestring (const char *, int);
149 static bfd_vma
parse_number (const char **, bfd_boolean
*);
150 static void bad_stab (const char *);
151 static void warn_stab (const char *, const char *);
152 static bfd_boolean parse_stab_string
153 (void *, struct stab_handle
*, int, int, bfd_vma
, const char *);
154 static debug_type parse_stab_type
155 (void *, struct stab_handle
*, const char *, const char **, debug_type
**);
156 static bfd_boolean
parse_stab_type_number (const char **, int *);
157 static debug_type parse_stab_range_type
158 (void *, struct stab_handle
*, const char *, const char **, const int *);
159 static debug_type
parse_stab_sun_builtin_type (void *, const char **);
160 static debug_type
parse_stab_sun_floating_type (void *, const char **);
161 static debug_type
parse_stab_enum_type (void *, const char **);
162 static debug_type parse_stab_struct_type
163 (void *, struct stab_handle
*, const char *, const char **,
164 bfd_boolean
, const int *);
165 static bfd_boolean parse_stab_baseclasses
166 (void *, struct stab_handle
*, const char **, debug_baseclass
**);
167 static bfd_boolean parse_stab_struct_fields
168 (void *, struct stab_handle
*, const char **, debug_field
**, bfd_boolean
*);
169 static bfd_boolean parse_stab_cpp_abbrev
170 (void *, struct stab_handle
*, const char **, debug_field
*);
171 static bfd_boolean parse_stab_one_struct_field
172 (void *, struct stab_handle
*, const char **, const char *,
173 debug_field
*, bfd_boolean
*);
174 static bfd_boolean parse_stab_members
175 (void *, struct stab_handle
*, const char *, const char **, const int *,
177 static debug_type parse_stab_argtypes
178 (void *, struct stab_handle
*, debug_type
, const char *, const char *,
179 debug_type
, const char *, bfd_boolean
, bfd_boolean
, const char **);
180 static bfd_boolean parse_stab_tilde_field
181 (void *, struct stab_handle
*, const char **, const int *, debug_type
*,
183 static debug_type parse_stab_array_type
184 (void *, struct stab_handle
*, const char **, bfd_boolean
);
185 static void push_bincl (struct stab_handle
*, const char *, bfd_vma
);
186 static const char *pop_bincl (struct stab_handle
*);
187 static bfd_boolean
find_excl (struct stab_handle
*, const char *, bfd_vma
);
188 static bfd_boolean stab_record_variable
189 (void *, struct stab_handle
*, const char *, debug_type
,
190 enum debug_var_kind
, bfd_vma
);
191 static bfd_boolean
stab_emit_pending_vars (void *, struct stab_handle
*);
192 static debug_type
*stab_find_slot (struct stab_handle
*, const int *);
193 static debug_type
stab_find_type (void *, struct stab_handle
*, const int *);
194 static bfd_boolean stab_record_type
195 (void *, struct stab_handle
*, const int *, debug_type
);
196 static debug_type stab_xcoff_builtin_type
197 (void *, struct stab_handle
*, int);
198 static debug_type stab_find_tagged_type
199 (void *, struct stab_handle
*, const char *, int, enum debug_type_kind
);
200 static debug_type
*stab_demangle_argtypes
201 (void *, struct stab_handle
*, const char *, bfd_boolean
*, unsigned int);
202 static debug_type
*stab_demangle_v3_argtypes
203 (void *, struct stab_handle
*, const char *, bfd_boolean
*);
204 static debug_type
*stab_demangle_v3_arglist
205 (void *, struct stab_handle
*, struct demangle_component
*, bfd_boolean
*);
206 static debug_type stab_demangle_v3_arg
207 (void *, struct stab_handle
*, struct demangle_component
*, debug_type
,
210 /* Save a string in memory. */
213 savestring (const char *start
, int len
)
217 ret
= (char *) xmalloc (len
+ 1);
218 memcpy (ret
, start
, len
);
223 /* Read a number from a string. */
226 parse_number (const char **pp
, bfd_boolean
*poverflow
)
231 if (poverflow
!= NULL
)
237 ul
= strtoul (*pp
, (char **) pp
, 0);
238 if (ul
+ 1 != 0 || errno
== 0)
240 /* If bfd_vma is larger than unsigned long, and the number is
241 meant to be negative, we have to make sure that we sign
244 return (bfd_vma
) (bfd_signed_vma
) (long) ul
;
248 /* Note that even though strtoul overflowed, it should have set *pp
249 to the end of the number, which is where we want it. */
250 if (sizeof (bfd_vma
) > sizeof (unsigned long))
255 bfd_vma over
, lastdig
;
256 bfd_boolean overflow
;
259 /* Our own version of strtoul, for a bfd_vma. */
274 if (p
[1] == 'x' || p
[1] == 'X')
286 over
= ((bfd_vma
) (bfd_signed_vma
) -1) / (bfd_vma
) base
;
287 lastdig
= ((bfd_vma
) (bfd_signed_vma
) -1) % (bfd_vma
) base
;
298 else if (ISUPPER (d
))
300 else if (ISLOWER (d
))
308 if (v
> over
|| (v
== over
&& (bfd_vma
) d
> lastdig
))
323 /* If we get here, the number is too large to represent in a
325 if (poverflow
!= NULL
)
328 warn_stab (orig
, _("numeric overflow"));
333 /* Give an error for a bad stab string. */
336 bad_stab (const char *p
)
338 fprintf (stderr
, _("Bad stab: %s\n"), p
);
341 /* Warn about something in a stab string. */
344 warn_stab (const char *p
, const char *err
)
346 fprintf (stderr
, _("Warning: %s: %s\n"), err
, p
);
349 /* Create a handle to parse stabs symbols with. */
352 start_stab (void *dhandle ATTRIBUTE_UNUSED
, bfd
*abfd
, bfd_boolean sections
,
353 asymbol
**syms
, long symcount
)
355 struct stab_handle
*ret
;
357 ret
= (struct stab_handle
*) xmalloc (sizeof *ret
);
358 memset (ret
, 0, sizeof *ret
);
360 ret
->sections
= sections
;
362 ret
->symcount
= symcount
;
364 ret
->file_types
= (struct stab_types
**) xmalloc (sizeof *ret
->file_types
);
365 ret
->file_types
[0] = NULL
;
366 ret
->function_end
= (bfd_vma
) -1;
370 /* When we have processed all the stabs information, we need to go
371 through and fill in all the undefined tags. */
374 finish_stab (void *dhandle
, void *handle
)
376 struct stab_handle
*info
= (struct stab_handle
*) handle
;
379 if (info
->within_function
)
381 if (! stab_emit_pending_vars (dhandle
, info
)
382 || ! debug_end_function (dhandle
, info
->function_end
))
384 info
->within_function
= FALSE
;
385 info
->function_end
= (bfd_vma
) -1;
388 for (st
= info
->tags
; st
!= NULL
; st
= st
->next
)
390 enum debug_type_kind kind
;
393 if (kind
== DEBUG_KIND_ILLEGAL
)
394 kind
= DEBUG_KIND_STRUCT
;
395 st
->slot
= debug_make_undefined_tagged_type (dhandle
, st
->name
, kind
);
396 if (st
->slot
== DEBUG_TYPE_NULL
)
403 /* Handle a single stabs symbol. */
406 parse_stab (void *dhandle
, void *handle
, int type
, int desc
, bfd_vma value
,
409 struct stab_handle
*info
= (struct stab_handle
*) handle
;
411 /* gcc will emit two N_SO strings per compilation unit, one for the
412 directory name and one for the file name. We just collect N_SO
413 strings as we see them, and start the new compilation unit when
414 we see a non N_SO symbol. */
415 if (info
->so_string
!= NULL
416 && (type
!= N_SO
|| *string
== '\0' || value
!= info
->so_value
))
418 if (! debug_set_filename (dhandle
, info
->so_string
))
420 info
->main_filename
= info
->so_string
;
422 info
->gcc_compiled
= 0;
423 info
->n_opt_found
= FALSE
;
425 /* Generally, for stabs in the symbol table, the N_LBRAC and
426 N_RBRAC symbols are relative to the N_SO symbol value. */
427 if (! info
->sections
)
428 info
->file_start_offset
= info
->so_value
;
430 /* We need to reset the mapping from type numbers to types. We
431 can't free the old mapping, because of the use of
432 debug_make_indirect_type. */
434 info
->file_types
= ((struct stab_types
**)
435 xmalloc (sizeof *info
->file_types
));
436 info
->file_types
[0] = NULL
;
438 info
->so_string
= NULL
;
440 /* Now process whatever type we just got. */
450 /* Ignore extra outermost context from SunPRO cc and acc. */
451 if (info
->n_opt_found
&& desc
== 1)
454 if (! info
->within_function
)
456 fprintf (stderr
, _("N_LBRAC not within function\n"));
460 /* Start an inner lexical block. */
461 if (! debug_start_block (dhandle
,
463 + info
->file_start_offset
464 + info
->function_start_offset
)))
467 /* Emit any pending variable definitions. */
468 if (! stab_emit_pending_vars (dhandle
, info
))
475 /* Ignore extra outermost context from SunPRO cc and acc. */
476 if (info
->n_opt_found
&& desc
== 1)
479 /* We shouldn't have any pending variable definitions here, but,
480 if we do, we probably need to emit them before closing the
482 if (! stab_emit_pending_vars (dhandle
, info
))
485 /* End an inner lexical block. */
486 if (! debug_end_block (dhandle
,
488 + info
->file_start_offset
489 + info
->function_start_offset
)))
493 if (info
->block_depth
< 0)
495 fprintf (stderr
, _("Too many N_RBRACs\n"));
501 /* This always ends a function. */
502 if (info
->within_function
)
508 && info
->function_end
!= (bfd_vma
) -1
509 && info
->function_end
< endval
)
510 endval
= info
->function_end
;
511 if (! stab_emit_pending_vars (dhandle
, info
)
512 || ! debug_end_function (dhandle
, endval
))
514 info
->within_function
= FALSE
;
515 info
->function_end
= (bfd_vma
) -1;
518 /* An empty string is emitted by gcc at the end of a compilation
523 /* Just accumulate strings until we see a non N_SO symbol. If
524 the string starts with a directory separator or some other
525 form of absolute path specification, we discard the previously
526 accumulated strings. */
527 if (info
->so_string
== NULL
)
528 info
->so_string
= xstrdup (string
);
535 if (IS_ABSOLUTE_PATH (string
))
536 info
->so_string
= xstrdup (string
);
538 info
->so_string
= concat (info
->so_string
, string
,
539 (const char *) NULL
);
543 info
->so_value
= value
;
548 /* Start an include file. */
549 if (! debug_start_source (dhandle
, string
))
554 /* Start an include file which may be replaced. */
555 push_bincl (info
, string
, value
);
556 if (! debug_start_source (dhandle
, string
))
561 /* End an N_BINCL include. */
562 if (! debug_start_source (dhandle
, pop_bincl (info
)))
567 /* This is a duplicate of a header file named by N_BINCL which
568 was eliminated by the linker. */
569 if (! find_excl (info
, string
, value
))
574 if (! debug_record_line (dhandle
, desc
,
575 value
+ (info
->within_function
576 ? info
->function_start_offset
: 0)))
581 if (! debug_start_common_block (dhandle
, string
))
586 if (! debug_end_common_block (dhandle
, string
))
593 if (info
->within_function
)
595 /* This always marks the end of a function; we don't
596 need to worry about info->function_end. */
598 value
+= info
->function_start_offset
;
599 if (! stab_emit_pending_vars (dhandle
, info
)
600 || ! debug_end_function (dhandle
, value
))
602 info
->within_function
= FALSE
;
603 info
->function_end
= (bfd_vma
) -1;
608 /* A const static symbol in the .text section will have an N_FUN
609 entry. We need to use these to mark the end of the function,
610 in case we are looking at gcc output before it was changed to
611 always emit an empty N_FUN. We can't call debug_end_function
612 here, because it might be a local static symbol. */
613 if (info
->within_function
614 && (info
->function_end
== (bfd_vma
) -1
615 || value
< info
->function_end
))
616 info
->function_end
= value
;
619 /* FIXME: gdb checks the string for N_STSYM, N_LCSYM or N_ROSYM
620 symbols, and if it does not start with :S, gdb relocates the
621 value to the start of the section. gcc always seems to use
622 :S, so we don't worry about this. */
628 colon
= strchr (string
, ':');
630 && (colon
[1] == 'f' || colon
[1] == 'F'))
632 if (info
->within_function
)
637 if (info
->function_end
!= (bfd_vma
) -1
638 && info
->function_end
< endval
)
639 endval
= info
->function_end
;
640 if (! stab_emit_pending_vars (dhandle
, info
)
641 || ! debug_end_function (dhandle
, endval
))
643 info
->function_end
= (bfd_vma
) -1;
645 /* For stabs in sections, line numbers and block addresses
646 are offsets from the start of the function. */
648 info
->function_start_offset
= value
;
649 info
->within_function
= TRUE
;
652 if (! parse_stab_string (dhandle
, info
, type
, desc
, value
, string
))
658 if (string
!= NULL
&& strcmp (string
, "gcc2_compiled.") == 0)
659 info
->gcc_compiled
= 2;
660 else if (string
!= NULL
&& strcmp (string
, "gcc_compiled.") == 0)
661 info
->gcc_compiled
= 1;
663 info
->n_opt_found
= TRUE
;
676 /* Parse the stabs string. */
679 parse_stab_string (void *dhandle
, struct stab_handle
*info
, int stabtype
,
680 int desc ATTRIBUTE_UNUSED
, bfd_vma value
, const char *string
)
687 bfd_boolean self_crossref
;
690 p
= strchr (string
, ':');
705 /* FIXME: Sometimes the special C++ names start with '.'. */
707 if (string
[0] == '$')
715 /* Was: name = "vptr"; */
721 /* This was an anonymous type that was never fixed up. */
724 /* SunPRO (3.0 at least) static variable encoding. */
727 warn_stab (string
, _("unknown C++ encoded name"));
734 if (p
== string
|| (string
[0] == ' ' && p
== string
+ 1))
737 name
= savestring (string
, p
- string
);
741 if (ISDIGIT (*p
) || *p
== '(' || *p
== '-')
749 /* c is a special case, not followed by a type-number.
750 SYMBOL:c=iVALUE for an integer constant symbol.
751 SYMBOL:c=rVALUE for a floating constant symbol.
752 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
753 e.g. "b:c=e6,0" for "const b = blob1"
754 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
764 /* Floating point constant. */
765 if (! debug_record_float_const (dhandle
, name
, atof (p
)))
769 /* Integer constant. */
770 /* Defining integer constants this way is kind of silly,
771 since 'e' constants allows the compiler to give not only
772 the value, but the type as well. C has at least int,
773 long, unsigned int, and long long as constant types;
774 other languages probably should have at least unsigned as
775 well as signed constants. */
776 if (! debug_record_int_const (dhandle
, name
, atoi (p
)))
780 /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value
781 can be represented as integral.
782 e.g. "b:c=e6,0" for "const b = blob1"
783 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
784 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
,
785 &p
, (debug_type
**) NULL
);
786 if (dtype
== DEBUG_TYPE_NULL
)
793 if (! debug_record_typed_const (dhandle
, name
, dtype
, atoi (p
)))
804 /* The name of a caught exception. */
805 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
,
806 &p
, (debug_type
**) NULL
);
807 if (dtype
== DEBUG_TYPE_NULL
)
809 if (! debug_record_label (dhandle
, name
, dtype
, value
))
815 /* A function definition. */
816 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
817 (debug_type
**) NULL
);
818 if (dtype
== DEBUG_TYPE_NULL
)
820 if (! debug_record_function (dhandle
, name
, dtype
, type
== 'F', value
))
823 /* Sun acc puts declared types of arguments here. We don't care
824 about their actual types (FIXME -- we should remember the whole
825 function prototype), but the list may define some new types
826 that we have to remember, so we must scan it now. */
830 if (parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
831 (debug_type
**) NULL
)
844 /* A global symbol. The value must be extracted from the
846 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
847 (debug_type
**) NULL
);
848 if (dtype
== DEBUG_TYPE_NULL
)
850 leading
= bfd_get_symbol_leading_char (info
->abfd
);
851 for (c
= info
->symcount
, ps
= info
->syms
; c
> 0; --c
, ++ps
)
855 n
= bfd_asymbol_name (*ps
);
856 if (leading
!= '\0' && *n
== leading
)
858 if (*n
== *name
&& strcmp (n
, name
) == 0)
862 value
= bfd_asymbol_value (*ps
);
863 if (! stab_record_variable (dhandle
, info
, name
, dtype
, DEBUG_GLOBAL
,
869 /* This case is faked by a conditional above, when there is no
870 code letter in the dbx data. Dbx data never actually
874 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
875 (debug_type
**) NULL
);
876 if (dtype
== DEBUG_TYPE_NULL
)
878 if (! stab_record_variable (dhandle
, info
, name
, dtype
, DEBUG_LOCAL
,
884 /* A function parameter. */
886 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
887 (debug_type
**) NULL
);
890 /* pF is a two-letter code that means a function parameter in
891 Fortran. The type-number specifies the type of the return
892 value. Translate it into a pointer-to-function type. */
894 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
895 (debug_type
**) NULL
);
896 if (dtype
!= DEBUG_TYPE_NULL
)
900 ftype
= debug_make_function_type (dhandle
, dtype
,
901 (debug_type
*) NULL
, FALSE
);
902 dtype
= debug_make_pointer_type (dhandle
, ftype
);
905 if (dtype
== DEBUG_TYPE_NULL
)
907 if (! debug_record_parameter (dhandle
, name
, dtype
, DEBUG_PARM_STACK
,
911 /* FIXME: At this point gdb considers rearranging the parameter
912 address on a big endian machine if it is smaller than an int.
913 We have no way to do that, since we don't really know much
918 if (stabtype
== N_FUN
)
920 /* Prototype of a function referenced by this file. */
924 if (parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
925 (debug_type
**) NULL
)
933 /* Parameter which is in a register. */
934 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
935 (debug_type
**) NULL
);
936 if (dtype
== DEBUG_TYPE_NULL
)
938 if (! debug_record_parameter (dhandle
, name
, dtype
, DEBUG_PARM_REG
,
944 /* Register variable (either global or local). */
945 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
946 (debug_type
**) NULL
);
947 if (dtype
== DEBUG_TYPE_NULL
)
949 if (! stab_record_variable (dhandle
, info
, name
, dtype
, DEBUG_REGISTER
,
953 /* FIXME: At this point gdb checks to combine pairs of 'p' and
954 'r' stabs into a single 'P' stab. */
958 /* Static symbol at top level of file. */
959 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
960 (debug_type
**) NULL
);
961 if (dtype
== DEBUG_TYPE_NULL
)
963 if (! stab_record_variable (dhandle
, info
, name
, dtype
, DEBUG_STATIC
,
970 dtype
= parse_stab_type (dhandle
, info
, name
, &p
, &slot
);
971 if (dtype
== DEBUG_TYPE_NULL
)
975 /* A nameless type. Nothing to do. */
979 dtype
= debug_name_type (dhandle
, name
, dtype
);
980 if (dtype
== DEBUG_TYPE_NULL
)
989 /* Struct, union, or enum tag. For GNU C++, this can be be followed
990 by 't' which means we are typedef'ing it as well. */
994 /* FIXME: gdb sets synonym to TRUE if the current language
1003 dtype
= parse_stab_type (dhandle
, info
, name
, &p
, &slot
);
1004 if (dtype
== DEBUG_TYPE_NULL
)
1009 /* INFO->SELF_CROSSREF is set by parse_stab_type if this type is
1010 a cross reference to itself. These are generated by some
1012 self_crossref
= info
->self_crossref
;
1014 dtype
= debug_tag_type (dhandle
, name
, dtype
);
1015 if (dtype
== DEBUG_TYPE_NULL
)
1020 /* See if we have a cross reference to this tag which we can now
1021 fill in. Avoid filling in a cross reference to ourselves,
1022 because that would lead to circular debugging information. */
1023 if (! self_crossref
)
1025 register struct stab_tag
**pst
;
1027 for (pst
= &info
->tags
; *pst
!= NULL
; pst
= &(*pst
)->next
)
1029 if ((*pst
)->name
[0] == name
[0]
1030 && strcmp ((*pst
)->name
, name
) == 0)
1032 (*pst
)->slot
= dtype
;
1033 *pst
= (*pst
)->next
;
1041 dtype
= debug_name_type (dhandle
, name
, dtype
);
1042 if (dtype
== DEBUG_TYPE_NULL
)
1052 /* Static symbol of local scope */
1053 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
1054 (debug_type
**) NULL
);
1055 if (dtype
== DEBUG_TYPE_NULL
)
1057 /* FIXME: gdb checks os9k_stabs here. */
1058 if (! stab_record_variable (dhandle
, info
, name
, dtype
,
1059 DEBUG_LOCAL_STATIC
, value
))
1064 /* Reference parameter. */
1065 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
1066 (debug_type
**) NULL
);
1067 if (dtype
== DEBUG_TYPE_NULL
)
1069 if (! debug_record_parameter (dhandle
, name
, dtype
, DEBUG_PARM_REFERENCE
,
1075 /* Reference parameter which is in a register. */
1076 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
1077 (debug_type
**) NULL
);
1078 if (dtype
== DEBUG_TYPE_NULL
)
1080 if (! debug_record_parameter (dhandle
, name
, dtype
, DEBUG_PARM_REF_REG
,
1086 /* This is used by Sun FORTRAN for "function result value".
1087 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
1088 that Pascal uses it too, but when I tried it Pascal used
1089 "x:3" (local symbol) instead. */
1090 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
1091 (debug_type
**) NULL
);
1092 if (dtype
== DEBUG_TYPE_NULL
)
1094 if (! stab_record_variable (dhandle
, info
, name
, dtype
, DEBUG_LOCAL
,
1100 /* SUNPro C++ Namespace =Yn0. */
1101 /* Skip the namespace mapping, as it is not used now. */
1102 if (*(++p
) == 'n' && *(++p
) == '0')
1110 /* TODO SUNPro C++ support:
1111 Support default arguments after F,P parameters
1112 Ya = Anonymous unions
1113 YM,YD = Pointers to class members
1115 YR = Run-time type information (RTTI) */
1124 /* FIXME: gdb converts structure values to structure pointers in a
1125 couple of cases, depending upon the target. */
1130 /* Parse a stabs type. The typename argument is non-NULL if this is a
1131 typedef or a tag definition. The pp argument points to the stab
1132 string, and is updated. The slotp argument points to a place to
1133 store the slot used if the type is being defined. */
1136 parse_stab_type (void *dhandle
, struct stab_handle
*info
, const char *type_name
, const char **pp
, debug_type
**slotp
)
1141 bfd_boolean stringp
;
1153 info
->self_crossref
= FALSE
;
1155 /* Read type number if present. The type number may be omitted.
1156 for instance in a two-dimensional array declared with type
1157 "ar1;1;10;ar1;1;10;4". */
1158 if (! ISDIGIT (**pp
) && **pp
!= '(' && **pp
!= '-')
1160 /* 'typenums=' not present, type is anonymous. Read and return
1161 the definition, but don't put it in the type vector. */
1162 typenums
[0] = typenums
[1] = -1;
1166 if (! parse_stab_type_number (pp
, typenums
))
1167 return DEBUG_TYPE_NULL
;
1170 /* Type is not being defined here. Either it already
1171 exists, or this is a forward reference to it. */
1172 return stab_find_type (dhandle
, info
, typenums
);
1174 /* Only set the slot if the type is being defined. This means
1175 that the mapping from type numbers to types will only record
1176 the name of the typedef which defines a type. If we don't do
1177 this, then something like
1180 will record that i is of type foo. Unfortunately, stabs
1181 information is ambiguous about variable types. For this code,
1185 the stabs information records both i and j as having the same
1186 type. This could be fixed by patching the compiler. */
1187 if (slotp
!= NULL
&& typenums
[0] >= 0 && typenums
[1] >= 0)
1188 *slotp
= stab_find_slot (info
, typenums
);
1190 /* Type is being defined here. */
1196 const char *p
= *pp
+ 1;
1199 if (ISDIGIT (*p
) || *p
== '(' || *p
== '-')
1203 /* Type attributes. */
1206 for (; *p
!= ';'; ++p
)
1211 return DEBUG_TYPE_NULL
;
1219 size
= atoi (attr
+ 1);
1220 size
/= 8; /* Size is in bits. We store it in bytes. */
1230 /* Ignore unrecognized type attributes, so future
1231 compilers can invent new ones. */
1244 enum debug_type_kind code
;
1245 const char *q1
, *q2
, *p
;
1247 /* A cross reference to another type. */
1251 code
= DEBUG_KIND_STRUCT
;
1254 code
= DEBUG_KIND_UNION
;
1257 code
= DEBUG_KIND_ENUM
;
1260 /* Complain and keep going, so compilers can invent new
1261 cross-reference types. */
1262 warn_stab (orig
, _("unrecognized cross reference type"));
1263 code
= DEBUG_KIND_STRUCT
;
1268 q1
= strchr (*pp
, '<');
1269 p
= strchr (*pp
, ':');
1273 return DEBUG_TYPE_NULL
;
1275 if (q1
!= NULL
&& p
> q1
&& p
[1] == ':')
1279 for (q2
= q1
; *q2
!= '\0'; ++q2
)
1283 else if (*q2
== '>')
1285 else if (*q2
== ':' && nest
== 0)
1292 return DEBUG_TYPE_NULL
;
1296 /* Some versions of g++ can emit stabs like
1298 which define structures in terms of themselves. We need to
1299 tell the caller to avoid building a circular structure. */
1300 if (type_name
!= NULL
1301 && strncmp (type_name
, *pp
, p
- *pp
) == 0
1302 && type_name
[p
- *pp
] == '\0')
1303 info
->self_crossref
= TRUE
;
1305 dtype
= stab_find_tagged_type (dhandle
, info
, *pp
, p
- *pp
, code
);
1327 /* This type is defined as another type. */
1331 /* Peek ahead at the number to detect void. */
1332 if (! parse_stab_type_number (pp
, xtypenums
))
1333 return DEBUG_TYPE_NULL
;
1335 if (typenums
[0] == xtypenums
[0] && typenums
[1] == xtypenums
[1])
1337 /* This type is being defined as itself, which means that
1339 dtype
= debug_make_void_type (dhandle
);
1345 /* Go back to the number and have parse_stab_type get it.
1346 This means that we can deal with something like
1347 t(1,2)=(3,4)=... which the Lucid compiler uses. */
1348 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
,
1349 pp
, (debug_type
**) NULL
);
1350 if (dtype
== DEBUG_TYPE_NULL
)
1351 return DEBUG_TYPE_NULL
;
1354 if (typenums
[0] != -1)
1356 if (! stab_record_type (dhandle
, info
, typenums
, dtype
))
1357 return DEBUG_TYPE_NULL
;
1364 dtype
= debug_make_pointer_type (dhandle
,
1365 parse_stab_type (dhandle
, info
,
1366 (const char *) NULL
,
1368 (debug_type
**) NULL
));
1372 /* Reference to another type. */
1373 dtype
= (debug_make_reference_type
1375 parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
1376 (debug_type
**) NULL
)));
1380 /* Function returning another type. */
1381 /* FIXME: gdb checks os9k_stabs here. */
1382 dtype
= (debug_make_function_type
1384 parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
1385 (debug_type
**) NULL
),
1386 (debug_type
*) NULL
, FALSE
));
1390 /* Const qualifier on some type (Sun). */
1391 /* FIXME: gdb accepts 'c' here if os9k_stabs. */
1392 dtype
= debug_make_const_type (dhandle
,
1393 parse_stab_type (dhandle
, info
,
1394 (const char *) NULL
,
1396 (debug_type
**) NULL
));
1400 /* Volatile qual on some type (Sun). */
1401 /* FIXME: gdb accepts 'i' here if os9k_stabs. */
1402 dtype
= (debug_make_volatile_type
1404 parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
1405 (debug_type
**) NULL
)));
1409 /* Offset (class & variable) type. This is used for a pointer
1410 relative to an object. */
1417 domain
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
1418 (debug_type
**) NULL
);
1419 if (domain
== DEBUG_TYPE_NULL
)
1420 return DEBUG_TYPE_NULL
;
1425 return DEBUG_TYPE_NULL
;
1429 memtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
1430 (debug_type
**) NULL
);
1431 if (memtype
== DEBUG_TYPE_NULL
)
1432 return DEBUG_TYPE_NULL
;
1434 dtype
= debug_make_offset_type (dhandle
, domain
, memtype
);
1439 /* Method (class & fn) type. */
1442 debug_type return_type
;
1445 return_type
= parse_stab_type (dhandle
, info
, (const char *) NULL
,
1446 pp
, (debug_type
**) NULL
);
1447 if (return_type
== DEBUG_TYPE_NULL
)
1448 return DEBUG_TYPE_NULL
;
1452 return DEBUG_TYPE_NULL
;
1455 dtype
= debug_make_method_type (dhandle
, return_type
,
1457 (debug_type
*) NULL
, FALSE
);
1462 debug_type return_type
;
1466 bfd_boolean varargs
;
1468 domain
= parse_stab_type (dhandle
, info
, (const char *) NULL
,
1469 pp
, (debug_type
**) NULL
);
1470 if (domain
== DEBUG_TYPE_NULL
)
1471 return DEBUG_TYPE_NULL
;
1476 return DEBUG_TYPE_NULL
;
1480 return_type
= parse_stab_type (dhandle
, info
, (const char *) NULL
,
1481 pp
, (debug_type
**) NULL
);
1482 if (return_type
== DEBUG_TYPE_NULL
)
1483 return DEBUG_TYPE_NULL
;
1486 args
= (debug_type
*) xmalloc (alloc
* sizeof *args
);
1493 return DEBUG_TYPE_NULL
;
1500 args
= ((debug_type
*)
1501 xrealloc (args
, alloc
* sizeof *args
));
1504 args
[n
] = parse_stab_type (dhandle
, info
, (const char *) NULL
,
1505 pp
, (debug_type
**) NULL
);
1506 if (args
[n
] == DEBUG_TYPE_NULL
)
1507 return DEBUG_TYPE_NULL
;
1512 /* If the last type is not void, then this function takes a
1513 variable number of arguments. Otherwise, we must strip
1516 || debug_get_type_kind (dhandle
, args
[n
- 1]) != DEBUG_KIND_VOID
)
1524 args
[n
] = DEBUG_TYPE_NULL
;
1526 dtype
= debug_make_method_type (dhandle
, return_type
, domain
, args
,
1533 dtype
= parse_stab_range_type (dhandle
, info
, type_name
, pp
, typenums
);
1537 /* FIXME: gdb checks os9k_stabs here. */
1538 /* Sun ACC builtin int type. */
1539 dtype
= parse_stab_sun_builtin_type (dhandle
, pp
);
1543 /* Sun ACC builtin float type. */
1544 dtype
= parse_stab_sun_floating_type (dhandle
, pp
);
1548 /* Enumeration type. */
1549 dtype
= parse_stab_enum_type (dhandle
, pp
);
1554 /* Struct or union type. */
1555 dtype
= parse_stab_struct_type (dhandle
, info
, type_name
, pp
,
1556 descriptor
== 's', typenums
);
1564 return DEBUG_TYPE_NULL
;
1568 dtype
= parse_stab_array_type (dhandle
, info
, pp
, stringp
);
1572 dtype
= debug_make_set_type (dhandle
,
1573 parse_stab_type (dhandle
, info
,
1574 (const char *) NULL
,
1576 (debug_type
**) NULL
),
1582 return DEBUG_TYPE_NULL
;
1585 if (dtype
== DEBUG_TYPE_NULL
)
1586 return DEBUG_TYPE_NULL
;
1588 if (typenums
[0] != -1)
1590 if (! stab_record_type (dhandle
, info
, typenums
, dtype
))
1591 return DEBUG_TYPE_NULL
;
1596 if (! debug_record_type_size (dhandle
, dtype
, (unsigned int) size
))
1597 return DEBUG_TYPE_NULL
;
1603 /* Read a number by which a type is referred to in dbx data, or
1604 perhaps read a pair (FILENUM, TYPENUM) in parentheses. Just a
1605 single number N is equivalent to (0,N). Return the two numbers by
1606 storing them in the vector TYPENUMS. */
1609 parse_stab_type_number (const char **pp
, int *typenums
)
1618 typenums
[1] = (int) parse_number (pp
, (bfd_boolean
*) NULL
);
1623 typenums
[0] = (int) parse_number (pp
, (bfd_boolean
*) NULL
);
1630 typenums
[1] = (int) parse_number (pp
, (bfd_boolean
*) NULL
);
1642 /* Parse a range type. */
1645 parse_stab_range_type (void *dhandle
, struct stab_handle
*info
, const char *type_name
, const char **pp
, const int *typenums
)
1649 bfd_boolean self_subrange
;
1650 debug_type index_type
;
1651 const char *s2
, *s3
;
1652 bfd_signed_vma n2
, n3
;
1653 bfd_boolean ov2
, ov3
;
1657 index_type
= DEBUG_TYPE_NULL
;
1659 /* First comes a type we are a subrange of.
1660 In C it is usually 0, 1 or the type being defined. */
1661 if (! parse_stab_type_number (pp
, rangenums
))
1662 return DEBUG_TYPE_NULL
;
1664 self_subrange
= (rangenums
[0] == typenums
[0]
1665 && rangenums
[1] == typenums
[1]);
1670 index_type
= parse_stab_type (dhandle
, info
, (const char *) NULL
,
1671 pp
, (debug_type
**) NULL
);
1672 if (index_type
== DEBUG_TYPE_NULL
)
1673 return DEBUG_TYPE_NULL
;
1679 /* The remaining two operands are usually lower and upper bounds of
1680 the range. But in some special cases they mean something else. */
1682 n2
= parse_number (pp
, &ov2
);
1686 return DEBUG_TYPE_NULL
;
1691 n3
= parse_number (pp
, &ov3
);
1695 return DEBUG_TYPE_NULL
;
1701 /* gcc will emit range stabs for long long types. Handle this
1702 as a special case. FIXME: This needs to be more general. */
1703 #define LLLOW "01000000000000000000000;"
1704 #define LLHIGH "0777777777777777777777;"
1705 #define ULLHIGH "01777777777777777777777;"
1706 if (index_type
== DEBUG_TYPE_NULL
)
1708 if (CONST_STRNEQ (s2
, LLLOW
)
1709 && CONST_STRNEQ (s3
, LLHIGH
))
1710 return debug_make_int_type (dhandle
, 8, FALSE
);
1713 && CONST_STRNEQ (s3
, ULLHIGH
))
1714 return debug_make_int_type (dhandle
, 8, TRUE
);
1717 warn_stab (orig
, _("numeric overflow"));
1720 if (index_type
== DEBUG_TYPE_NULL
)
1722 /* A type defined as a subrange of itself, with both bounds 0,
1724 if (self_subrange
&& n2
== 0 && n3
== 0)
1725 return debug_make_void_type (dhandle
);
1727 /* A type defined as a subrange of itself, with n2 positive and
1728 n3 zero, is a complex type, and n2 is the number of bytes. */
1729 if (self_subrange
&& n3
== 0 && n2
> 0)
1730 return debug_make_complex_type (dhandle
, n2
);
1732 /* If n3 is zero and n2 is positive, this is a floating point
1733 type, and n2 is the number of bytes. */
1734 if (n3
== 0 && n2
> 0)
1735 return debug_make_float_type (dhandle
, n2
);
1737 /* If the upper bound is -1, this is an unsigned int. */
1738 if (n2
== 0 && n3
== -1)
1740 /* When gcc is used with -gstabs, but not -gstabs+, it will emit
1741 long long int:t6=r1;0;-1;
1742 long long unsigned int:t7=r1;0;-1;
1743 We hack here to handle this reasonably. */
1744 if (type_name
!= NULL
)
1746 if (strcmp (type_name
, "long long int") == 0)
1747 return debug_make_int_type (dhandle
, 8, FALSE
);
1748 else if (strcmp (type_name
, "long long unsigned int") == 0)
1749 return debug_make_int_type (dhandle
, 8, TRUE
);
1751 /* FIXME: The size here really depends upon the target. */
1752 return debug_make_int_type (dhandle
, 4, TRUE
);
1755 /* A range of 0 to 127 is char. */
1756 if (self_subrange
&& n2
== 0 && n3
== 127)
1757 return debug_make_int_type (dhandle
, 1, FALSE
);
1759 /* FIXME: gdb checks for the language CHILL here. */
1764 return debug_make_int_type (dhandle
, - n3
, TRUE
);
1765 else if (n3
== 0xff)
1766 return debug_make_int_type (dhandle
, 1, TRUE
);
1767 else if (n3
== 0xffff)
1768 return debug_make_int_type (dhandle
, 2, TRUE
);
1769 else if (n3
== (bfd_signed_vma
) 0xffffffff)
1770 return debug_make_int_type (dhandle
, 4, TRUE
);
1772 else if (n3
== ((((bfd_signed_vma
) 0xffffffff) << 32) | 0xffffffff))
1773 return debug_make_int_type (dhandle
, 8, TRUE
);
1778 && (self_subrange
|| n2
== -8))
1779 return debug_make_int_type (dhandle
, - n2
, TRUE
);
1780 else if (n2
== - n3
- 1 || n2
== n3
+ 1)
1783 return debug_make_int_type (dhandle
, 1, FALSE
);
1784 else if (n3
== 0x7fff)
1785 return debug_make_int_type (dhandle
, 2, FALSE
);
1786 else if (n3
== 0x7fffffff)
1787 return debug_make_int_type (dhandle
, 4, FALSE
);
1789 else if (n3
== ((((bfd_vma
) 0x7fffffff) << 32) | 0xffffffff))
1790 return debug_make_int_type (dhandle
, 8, FALSE
);
1795 /* At this point I don't have the faintest idea how to deal with a
1796 self_subrange type; I'm going to assume that this is used as an
1797 idiom, and that all of them are special cases. So . . . */
1801 return DEBUG_TYPE_NULL
;
1804 index_type
= stab_find_type (dhandle
, info
, rangenums
);
1805 if (index_type
== DEBUG_TYPE_NULL
)
1807 /* Does this actually ever happen? Is that why we are worrying
1808 about dealing with it rather than just calling error_type? */
1809 warn_stab (orig
, _("missing index type"));
1810 index_type
= debug_make_int_type (dhandle
, 4, FALSE
);
1813 return debug_make_range_type (dhandle
, index_type
, n2
, n3
);
1816 /* Sun's ACC uses a somewhat saner method for specifying the builtin
1817 typedefs in every file (for int, long, etc):
1819 type = b <signed> <width>; <offset>; <nbits>
1820 signed = u or s. Possible c in addition to u or s (for char?).
1821 offset = offset from high order bit to start bit of type.
1822 width is # bytes in object of this type, nbits is # bits in type.
1824 The width/offset stuff appears to be for small objects stored in
1825 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
1829 parse_stab_sun_builtin_type (void *dhandle
, const char **pp
)
1832 bfd_boolean unsignedp
;
1847 return DEBUG_TYPE_NULL
;
1851 /* OpenSolaris source code indicates that one of "cbv" characters
1852 can come next and specify the intrinsic 'iformat' encoding.
1853 'c' is character encoding, 'b' is boolean encoding, and 'v' is
1854 varargs encoding. This field can be safely ignored because
1855 the type of the field is determined from the bitwidth extracted
1857 if (**pp
== 'c' || **pp
== 'b' || **pp
== 'v')
1860 /* The first number appears to be the number of bytes occupied
1861 by this type, except that unsigned short is 4 instead of 2.
1862 Since this information is redundant with the third number,
1863 we will ignore it. */
1864 (void) parse_number (pp
, (bfd_boolean
*) NULL
);
1868 return DEBUG_TYPE_NULL
;
1872 /* The second number is always 0, so ignore it too. */
1873 (void) parse_number (pp
, (bfd_boolean
*) NULL
);
1877 return DEBUG_TYPE_NULL
;
1881 /* The third number is the number of bits for this type. */
1882 bits
= parse_number (pp
, (bfd_boolean
*) NULL
);
1884 /* The type *should* end with a semicolon. If it are embedded
1885 in a larger type the semicolon may be the only way to know where
1886 the type ends. If this type is at the end of the stabstring we
1887 can deal with the omitted semicolon (but we don't have to like
1888 it). Don't bother to complain(), Sun's compiler omits the semicolon
1894 return debug_make_void_type (dhandle
);
1896 return debug_make_int_type (dhandle
, bits
/ 8, unsignedp
);
1899 /* Parse a builtin floating type generated by the Sun compiler. */
1902 parse_stab_sun_floating_type (void *dhandle
, const char **pp
)
1910 /* The first number has more details about the type, for example
1912 details
= parse_number (pp
, (bfd_boolean
*) NULL
);
1916 return DEBUG_TYPE_NULL
;
1919 /* The second number is the number of bytes occupied by this type */
1920 bytes
= parse_number (pp
, (bfd_boolean
*) NULL
);
1924 return DEBUG_TYPE_NULL
;
1927 if (details
== NF_COMPLEX
1928 || details
== NF_COMPLEX16
1929 || details
== NF_COMPLEX32
)
1930 return debug_make_complex_type (dhandle
, bytes
);
1932 return debug_make_float_type (dhandle
, bytes
);
1935 /* Handle an enum type. */
1938 parse_stab_enum_type (void *dhandle
, const char **pp
)
1942 bfd_signed_vma
*values
;
1948 /* FIXME: gdb checks os9k_stabs here. */
1950 /* The aix4 compiler emits an extra field before the enum members;
1951 my guess is it's a type of some sort. Just ignore it. */
1959 /* Read the value-names and their values.
1960 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
1961 A semicolon or comma instead of a NAME means the end. */
1963 names
= (const char **) xmalloc (alloc
* sizeof *names
);
1964 values
= (bfd_signed_vma
*) xmalloc (alloc
* sizeof *values
);
1966 while (**pp
!= '\0' && **pp
!= ';' && **pp
!= ',')
1976 name
= savestring (*pp
, p
- *pp
);
1979 val
= (bfd_signed_vma
) parse_number (pp
, (bfd_boolean
*) NULL
);
1986 return DEBUG_TYPE_NULL
;
1993 names
= ((const char **)
1994 xrealloc (names
, alloc
* sizeof *names
));
1995 values
= ((bfd_signed_vma
*)
1996 xrealloc (values
, alloc
* sizeof *values
));
2010 return debug_make_enum_type (dhandle
, names
, values
);
2013 /* Read the description of a structure (or union type) and return an object
2014 describing the type.
2016 PP points to a character pointer that points to the next unconsumed token
2017 in the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
2018 *PP will point to "4a:1,0,32;;". */
2021 parse_stab_struct_type (void *dhandle
, struct stab_handle
*info
,
2022 const char *tagname
, const char **pp
,
2023 bfd_boolean structp
, const int *typenums
)
2026 debug_baseclass
*baseclasses
;
2027 debug_field
*fields
= NULL
;
2028 bfd_boolean statics
;
2029 debug_method
*methods
;
2030 debug_type vptrbase
;
2031 bfd_boolean ownvptr
;
2034 size
= parse_number (pp
, (bfd_boolean
*) NULL
);
2036 /* Get the other information. */
2037 if (! parse_stab_baseclasses (dhandle
, info
, pp
, &baseclasses
)
2038 || ! parse_stab_struct_fields (dhandle
, info
, pp
, &fields
, &statics
)
2039 || ! parse_stab_members (dhandle
, info
, tagname
, pp
, typenums
, &methods
)
2040 || ! parse_stab_tilde_field (dhandle
, info
, pp
, typenums
, &vptrbase
,
2045 return DEBUG_TYPE_NULL
;
2049 && baseclasses
== NULL
2051 && vptrbase
== DEBUG_TYPE_NULL
2053 return debug_make_struct_type (dhandle
, structp
, size
, fields
);
2055 return debug_make_object_type (dhandle
, structp
, size
, fields
, baseclasses
,
2056 methods
, vptrbase
, ownvptr
);
2059 /* The stabs for C++ derived classes contain baseclass information which
2060 is marked by a '!' character after the total size. This function is
2061 called when we encounter the baseclass marker, and slurps up all the
2062 baseclass information.
2064 Immediately following the '!' marker is the number of base classes that
2065 the class is derived from, followed by information for each base class.
2066 For each base class, there are two visibility specifiers, a bit offset
2067 to the base class information within the derived class, a reference to
2068 the type for the base class, and a terminating semicolon.
2070 A typical example, with two base classes, would be "!2,020,19;0264,21;".
2072 Baseclass information marker __________________|| | | | | | |
2073 Number of baseclasses __________________________| | | | | | |
2074 Visibility specifiers (2) ________________________| | | | | |
2075 Offset in bits from start of class _________________| | | | |
2076 Type number for base class ___________________________| | | |
2077 Visibility specifiers (2) _______________________________| | |
2078 Offset in bits from start of class ________________________| |
2079 Type number of base class ____________________________________|
2081 Return TRUE for success, FALSE for failure. */
2084 parse_stab_baseclasses (void *dhandle
, struct stab_handle
*info
,
2085 const char **pp
, debug_baseclass
**retp
)
2089 debug_baseclass
*classes
;
2097 /* No base classes. */
2102 c
= (unsigned int) parse_number (pp
, (bfd_boolean
*) NULL
);
2111 classes
= (debug_baseclass
*) xmalloc ((c
+ 1) * sizeof (**retp
));
2113 for (i
= 0; i
< c
; i
++)
2115 bfd_boolean is_virtual
;
2116 enum debug_visibility visibility
;
2129 warn_stab (orig
, _("unknown virtual character for baseclass"));
2138 visibility
= DEBUG_VISIBILITY_PRIVATE
;
2141 visibility
= DEBUG_VISIBILITY_PROTECTED
;
2144 visibility
= DEBUG_VISIBILITY_PUBLIC
;
2147 warn_stab (orig
, _("unknown visibility character for baseclass"));
2148 visibility
= DEBUG_VISIBILITY_PUBLIC
;
2153 /* The remaining value is the bit offset of the portion of the
2154 object corresponding to this baseclass. Always zero in the
2155 absence of multiple inheritance. */
2156 bitpos
= parse_number (pp
, (bfd_boolean
*) NULL
);
2164 type
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
2165 (debug_type
**) NULL
);
2166 if (type
== DEBUG_TYPE_NULL
)
2169 classes
[i
] = debug_make_baseclass (dhandle
, type
, bitpos
, is_virtual
,
2171 if (classes
[i
] == DEBUG_BASECLASS_NULL
)
2179 classes
[i
] = DEBUG_BASECLASS_NULL
;
2186 /* Read struct or class data fields. They have the form:
2188 NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
2190 At the end, we see a semicolon instead of a field.
2192 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
2195 The optional VISIBILITY is one of:
2197 '/0' (VISIBILITY_PRIVATE)
2198 '/1' (VISIBILITY_PROTECTED)
2199 '/2' (VISIBILITY_PUBLIC)
2200 '/9' (VISIBILITY_IGNORE)
2202 or nothing, for C style fields with public visibility.
2204 Returns 1 for success, 0 for failure. */
2207 parse_stab_struct_fields (void *dhandle
, struct stab_handle
*info
,
2208 const char **pp
, debug_field
**retp
,
2209 bfd_boolean
*staticsp
)
2213 debug_field
*fields
;
2224 fields
= (debug_field
*) xmalloc (alloc
* sizeof *fields
);
2227 /* FIXME: gdb checks os9k_stabs here. */
2231 /* Add 1 to c to leave room for NULL pointer at end. */
2235 fields
= ((debug_field
*)
2236 xrealloc (fields
, alloc
* sizeof *fields
));
2239 /* If it starts with CPLUS_MARKER it is a special abbreviation,
2240 unless the CPLUS_MARKER is followed by an underscore, in
2241 which case it is just the name of an anonymous type, which we
2242 should handle like any other type name. We accept either '$'
2243 or '.', because a field name can never contain one of these
2244 characters except as a CPLUS_MARKER. */
2246 if ((*p
== '$' || *p
== '.') && p
[1] != '_')
2249 if (! parse_stab_cpp_abbrev (dhandle
, info
, pp
, fields
+ c
))
2258 /* Look for the ':' that separates the field name from the field
2259 values. Data members are delimited by a single ':', while member
2260 functions are delimited by a pair of ':'s. When we hit the member
2261 functions (if any), terminate scan loop and return. */
2263 p
= strchr (p
, ':');
2274 if (! parse_stab_one_struct_field (dhandle
, info
, pp
, p
, fields
+ c
,
2281 fields
[c
] = DEBUG_FIELD_NULL
;
2288 /* Special GNU C++ name. */
2291 parse_stab_cpp_abbrev (void *dhandle
, struct stab_handle
*info
,
2292 const char **pp
, debug_field
*retp
)
2298 const char *type_name
;
2302 *retp
= DEBUG_FIELD_NULL
;
2316 /* At this point, *pp points to something like "22:23=*22...", where
2317 the type number before the ':' is the "context" and everything
2318 after is a regular type definition. Lookup the type, find it's
2319 name, and construct the field name. */
2321 context
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
2322 (debug_type
**) NULL
);
2323 if (context
== DEBUG_TYPE_NULL
)
2329 /* $vf -- a virtual function table pointer. */
2333 /* $vb -- a virtual bsomethingorother */
2334 type_name
= debug_get_type_name (dhandle
, context
);
2335 if (type_name
== NULL
)
2337 warn_stab (orig
, _("unnamed $vb type"));
2340 name
= concat ("_vb$", type_name
, (const char *) NULL
);
2343 warn_stab (orig
, _("unrecognized C++ abbreviation"));
2344 name
= "INVALID_CPLUSPLUS_ABBREV";
2355 type
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
2356 (debug_type
**) NULL
);
2364 bitpos
= parse_number (pp
, (bfd_boolean
*) NULL
);
2372 *retp
= debug_make_field (dhandle
, name
, type
, bitpos
, 0,
2373 DEBUG_VISIBILITY_PRIVATE
);
2374 if (*retp
== DEBUG_FIELD_NULL
)
2380 /* Parse a single field in a struct or union. */
2383 parse_stab_one_struct_field (void *dhandle
, struct stab_handle
*info
,
2384 const char **pp
, const char *p
,
2385 debug_field
*retp
, bfd_boolean
*staticsp
)
2389 enum debug_visibility visibility
;
2396 /* FIXME: gdb checks ARM_DEMANGLING here. */
2398 name
= savestring (*pp
, p
- *pp
);
2403 visibility
= DEBUG_VISIBILITY_PUBLIC
;
2410 visibility
= DEBUG_VISIBILITY_PRIVATE
;
2413 visibility
= DEBUG_VISIBILITY_PROTECTED
;
2416 visibility
= DEBUG_VISIBILITY_PUBLIC
;
2419 warn_stab (orig
, _("unknown visibility character for field"));
2420 visibility
= DEBUG_VISIBILITY_PUBLIC
;
2426 type
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
2427 (debug_type
**) NULL
);
2428 if (type
== DEBUG_TYPE_NULL
)
2438 /* This is a static class member. */
2440 p
= strchr (*pp
, ';');
2448 varname
= savestring (*pp
, p
- *pp
);
2452 *retp
= debug_make_static_member (dhandle
, name
, type
, varname
,
2467 bitpos
= parse_number (pp
, (bfd_boolean
*) NULL
);
2476 bitsize
= parse_number (pp
, (bfd_boolean
*) NULL
);
2485 if (bitpos
== 0 && bitsize
== 0)
2487 /* This can happen in two cases: (1) at least for gcc 2.4.5 or
2488 so, it is a field which has been optimized out. The correct
2489 stab for this case is to use VISIBILITY_IGNORE, but that is a
2490 recent invention. (2) It is a 0-size array. For example
2491 union { int num; char str[0]; } foo. Printing "<no value>"
2492 for str in "p foo" is OK, since foo.str (and thus foo.str[3])
2493 will continue to work, and a 0-size array as a whole doesn't
2494 have any contents to print.
2496 I suspect this probably could also happen with gcc -gstabs
2497 (not -gstabs+) for static fields, and perhaps other C++
2498 extensions. Hopefully few people use -gstabs with gdb, since
2499 it is intended for dbx compatibility. */
2500 visibility
= DEBUG_VISIBILITY_IGNORE
;
2503 /* FIXME: gdb does some stuff here to mark fields as unpacked. */
2505 *retp
= debug_make_field (dhandle
, name
, type
, bitpos
, bitsize
, visibility
);
2510 /* Read member function stabs info for C++ classes. The form of each member
2513 NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
2515 An example with two member functions is:
2517 afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
2519 For the case of overloaded operators, the format is op$::*.funcs, where
2520 $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
2521 name (such as `+=') and `.' marks the end of the operator name. */
2524 parse_stab_members (void *dhandle
, struct stab_handle
*info
,
2525 const char *tagname
, const char **pp
,
2526 const int *typenums
, debug_method
**retp
)
2529 debug_method
*methods
;
2533 debug_method_variant
*variants
= NULL
;
2534 char *argtypes
= NULL
;
2548 unsigned int allocvars
;
2549 debug_type look_ahead_type
;
2551 p
= strchr (*pp
, ':');
2552 if (p
== NULL
|| p
[1] != ':')
2555 /* FIXME: Some systems use something other than '$' here. */
2556 if ((*pp
)[0] != 'o' || (*pp
)[1] != 'p' || (*pp
)[2] != '$')
2558 name
= savestring (*pp
, p
- *pp
);
2563 /* This is a completely weird case. In order to stuff in the
2564 names that might contain colons (the usual name delimiter),
2565 Mike Tiemann defined a different name format which is
2566 signalled if the identifier is "op$". In that case, the
2567 format is "op$::XXXX." where XXXX is the name. This is
2568 used for names like "+" or "=". YUUUUUUUK! FIXME! */
2570 for (p
= *pp
; *p
!= '.' && *p
!= '\0'; p
++)
2577 name
= savestring (*pp
, p
- *pp
);
2582 variants
= ((debug_method_variant
*)
2583 xmalloc (allocvars
* sizeof *variants
));
2586 look_ahead_type
= DEBUG_TYPE_NULL
;
2592 enum debug_visibility visibility
;
2593 bfd_boolean constp
, volatilep
, staticp
;
2596 const char *physname
;
2597 bfd_boolean varargs
;
2599 if (look_ahead_type
!= DEBUG_TYPE_NULL
)
2601 /* g++ version 1 kludge */
2602 type
= look_ahead_type
;
2603 look_ahead_type
= DEBUG_TYPE_NULL
;
2607 type
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
2608 (debug_type
**) NULL
);
2609 if (type
== DEBUG_TYPE_NULL
)
2620 p
= strchr (*pp
, ';');
2628 if (debug_get_type_kind (dhandle
, type
) == DEBUG_KIND_METHOD
2629 && debug_get_parameter_types (dhandle
, type
, &varargs
) == NULL
)
2632 argtypes
= savestring (*pp
, p
- *pp
);
2638 visibility
= DEBUG_VISIBILITY_PRIVATE
;
2641 visibility
= DEBUG_VISIBILITY_PROTECTED
;
2644 visibility
= DEBUG_VISIBILITY_PUBLIC
;
2654 /* Normal function. */
2658 /* const member function. */
2663 /* volatile member function. */
2668 /* const volatile member function. */
2676 /* File compiled with g++ version 1; no information. */
2679 warn_stab (orig
, _("const/volatile indicator missing"));
2687 /* virtual member function, followed by index. The sign
2688 bit is supposedly set to distinguish
2689 pointers-to-methods from virtual function indicies. */
2691 voffset
= parse_number (pp
, (bfd_boolean
*) NULL
);
2698 voffset
&= 0x7fffffff;
2700 if (**pp
== ';' || *pp
== '\0')
2702 /* Must be g++ version 1. */
2703 context
= DEBUG_TYPE_NULL
;
2707 /* Figure out from whence this virtual function
2708 came. It may belong to virtual function table of
2709 one of its baseclasses. */
2710 look_ahead_type
= parse_stab_type (dhandle
, info
,
2711 (const char *) NULL
,
2713 (debug_type
**) NULL
);
2716 /* g++ version 1 overloaded methods. */
2717 context
= DEBUG_TYPE_NULL
;
2721 context
= look_ahead_type
;
2722 look_ahead_type
= DEBUG_TYPE_NULL
;
2734 /* static member function. */
2738 context
= DEBUG_TYPE_NULL
;
2739 if (strncmp (argtypes
, name
, strlen (name
)) != 0)
2744 warn_stab (orig
, "member function type missing");
2746 context
= DEBUG_TYPE_NULL
;
2752 context
= DEBUG_TYPE_NULL
;
2756 /* If the type is not a stub, then the argtypes string is
2757 the physical name of the function. Otherwise the
2758 argtypes string is the mangled form of the argument
2759 types, and the full type and the physical name must be
2760 extracted from them. */
2761 physname
= argtypes
;
2764 debug_type class_type
, return_type
;
2766 class_type
= stab_find_type (dhandle
, info
, typenums
);
2767 if (class_type
== DEBUG_TYPE_NULL
)
2769 return_type
= debug_get_return_type (dhandle
, type
);
2770 if (return_type
== DEBUG_TYPE_NULL
)
2775 type
= parse_stab_argtypes (dhandle
, info
, class_type
, name
,
2776 tagname
, return_type
, argtypes
,
2777 constp
, volatilep
, &physname
);
2778 if (type
== DEBUG_TYPE_NULL
)
2782 if (cvars
+ 1 >= allocvars
)
2785 variants
= ((debug_method_variant
*)
2787 allocvars
* sizeof *variants
));
2791 variants
[cvars
] = debug_make_method_variant (dhandle
, physname
,
2796 variants
[cvars
] = debug_make_static_method_variant (dhandle
,
2802 if (variants
[cvars
] == DEBUG_METHOD_VARIANT_NULL
)
2807 while (**pp
!= ';' && **pp
!= '\0');
2809 variants
[cvars
] = DEBUG_METHOD_VARIANT_NULL
;
2817 methods
= ((debug_method
*)
2818 xrealloc (methods
, alloc
* sizeof *methods
));
2821 methods
[c
] = debug_make_method (dhandle
, name
, variants
);
2826 if (methods
!= NULL
)
2827 methods
[c
] = DEBUG_METHOD_NULL
;
2836 if (variants
!= NULL
)
2838 if (argtypes
!= NULL
)
2843 /* Parse a string representing argument types for a method. Stabs
2844 tries to save space by packing argument types into a mangled
2845 string. This string should give us enough information to extract
2846 both argument types and the physical name of the function, given
2850 parse_stab_argtypes (void *dhandle
, struct stab_handle
*info
,
2851 debug_type class_type
, const char *fieldname
,
2852 const char *tagname
, debug_type return_type
,
2853 const char *argtypes
, bfd_boolean constp
,
2854 bfd_boolean volatilep
, const char **pphysname
)
2856 bfd_boolean is_full_physname_constructor
;
2857 bfd_boolean is_constructor
;
2858 bfd_boolean is_destructor
;
2861 bfd_boolean varargs
;
2862 unsigned int physname_len
= 0;
2864 /* Constructors are sometimes handled specially. */
2865 is_full_physname_constructor
= ((argtypes
[0] == '_'
2866 && argtypes
[1] == '_'
2867 && (ISDIGIT (argtypes
[2])
2868 || argtypes
[2] == 'Q'
2869 || argtypes
[2] == 't'))
2870 || CONST_STRNEQ (argtypes
, "__ct"));
2872 is_constructor
= (is_full_physname_constructor
2874 && strcmp (fieldname
, tagname
) == 0));
2875 is_destructor
= ((argtypes
[0] == '_'
2876 && (argtypes
[1] == '$' || argtypes
[1] == '.')
2877 && argtypes
[2] == '_')
2878 || CONST_STRNEQ (argtypes
, "__dt"));
2879 is_v3
= argtypes
[0] == '_' && argtypes
[1] == 'Z';
2881 if (!(is_destructor
|| is_full_physname_constructor
|| is_v3
))
2884 const char *const_prefix
;
2885 const char *volatile_prefix
;
2887 unsigned int mangled_name_len
;
2890 len
= tagname
== NULL
? 0 : strlen (tagname
);
2891 const_prefix
= constp
? "C" : "";
2892 volatile_prefix
= volatilep
? "V" : "";
2895 sprintf (buf
, "__%s%s", const_prefix
, volatile_prefix
);
2896 else if (tagname
!= NULL
&& strchr (tagname
, '<') != NULL
)
2898 /* Template methods are fully mangled. */
2899 sprintf (buf
, "__%s%s", const_prefix
, volatile_prefix
);
2904 sprintf (buf
, "__%s%s%d", const_prefix
, volatile_prefix
, len
);
2906 mangled_name_len
= ((is_constructor
? 0 : strlen (fieldname
))
2912 if (fieldname
[0] == 'o'
2913 && fieldname
[1] == 'p'
2914 && (fieldname
[2] == '$' || fieldname
[2] == '.'))
2918 opname
= cplus_mangle_opname (fieldname
+ 3, 0);
2921 fprintf (stderr
, _("No mangling for \"%s\"\n"), fieldname
);
2922 return DEBUG_TYPE_NULL
;
2924 mangled_name_len
+= strlen (opname
);
2925 physname
= (char *) xmalloc (mangled_name_len
);
2926 strncpy (physname
, fieldname
, 3);
2927 strcpy (physname
+ 3, opname
);
2931 physname
= (char *) xmalloc (mangled_name_len
);
2935 strcpy (physname
, fieldname
);
2938 physname_len
= strlen (physname
);
2939 strcat (physname
, buf
);
2940 if (tagname
!= NULL
)
2941 strcat (physname
, tagname
);
2942 strcat (physname
, argtypes
);
2944 *pphysname
= physname
;
2947 if (*argtypes
== '\0' || is_destructor
)
2949 args
= (debug_type
*) xmalloc (sizeof *args
);
2951 return debug_make_method_type (dhandle
, return_type
, class_type
, args
,
2955 args
= stab_demangle_argtypes (dhandle
, info
, *pphysname
, &varargs
, physname_len
);
2957 return DEBUG_TYPE_NULL
;
2959 return debug_make_method_type (dhandle
, return_type
, class_type
, args
,
2963 /* The tail end of stabs for C++ classes that contain a virtual function
2964 pointer contains a tilde, a %, and a type number.
2965 The type number refers to the base class (possibly this class itself) which
2966 contains the vtable pointer for the current class.
2968 This function is called when we have parsed all the method declarations,
2969 so we can look for the vptr base class info. */
2972 parse_stab_tilde_field (void *dhandle
, struct stab_handle
*info
,
2973 const char **pp
, const int *typenums
,
2974 debug_type
*retvptrbase
, bfd_boolean
*retownvptr
)
2980 *retvptrbase
= DEBUG_TYPE_NULL
;
2981 *retownvptr
= FALSE
;
2985 /* If we are positioned at a ';', then skip it. */
2994 if (**pp
== '=' || **pp
== '+' || **pp
== '-')
2996 /* Obsolete flags that used to indicate the presence of
2997 constructors and/or destructors. */
3008 /* The next number is the type number of the base class (possibly
3009 our own class) which supplies the vtable for this class. */
3010 if (! parse_stab_type_number (pp
, vtypenums
))
3013 if (vtypenums
[0] == typenums
[0]
3014 && vtypenums
[1] == typenums
[1])
3023 vtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
3024 (debug_type
**) NULL
);
3025 for (p
= *pp
; *p
!= ';' && *p
!= '\0'; p
++)
3033 *retvptrbase
= vtype
;
3041 /* Read a definition of an array type. */
3044 parse_stab_array_type (void *dhandle
, struct stab_handle
*info
,
3045 const char **pp
, bfd_boolean stringp
)
3050 debug_type index_type
;
3051 bfd_boolean adjustable
;
3052 bfd_signed_vma lower
, upper
;
3053 debug_type element_type
;
3055 /* Format of an array type:
3056 "ar<index type>;lower;upper;<array_contents_type>".
3057 OS9000: "arlower,upper;<array_contents_type>".
3059 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
3060 for these, produce a type like float[][]. */
3064 /* FIXME: gdb checks os9k_stabs here. */
3066 /* If the index type is type 0, we take it as int. */
3068 if (! parse_stab_type_number (&p
, typenums
))
3069 return DEBUG_TYPE_NULL
;
3070 if (typenums
[0] == 0 && typenums
[1] == 0 && **pp
!= '=')
3072 index_type
= debug_find_named_type (dhandle
, "int");
3073 if (index_type
== DEBUG_TYPE_NULL
)
3075 index_type
= debug_make_int_type (dhandle
, 4, FALSE
);
3076 if (index_type
== DEBUG_TYPE_NULL
)
3077 return DEBUG_TYPE_NULL
;
3083 index_type
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
3084 (debug_type
**) NULL
);
3090 return DEBUG_TYPE_NULL
;
3096 if (! ISDIGIT (**pp
) && **pp
!= '-')
3102 lower
= (bfd_signed_vma
) parse_number (pp
, (bfd_boolean
*) NULL
);
3106 return DEBUG_TYPE_NULL
;
3110 if (! ISDIGIT (**pp
) && **pp
!= '-')
3116 upper
= (bfd_signed_vma
) parse_number (pp
, (bfd_boolean
*) NULL
);
3120 return DEBUG_TYPE_NULL
;
3124 element_type
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
3125 (debug_type
**) NULL
);
3126 if (element_type
== DEBUG_TYPE_NULL
)
3127 return DEBUG_TYPE_NULL
;
3135 return debug_make_array_type (dhandle
, element_type
, index_type
, lower
,
3139 /* This struct holds information about files we have seen using
3144 /* The next N_BINCL file. */
3145 struct bincl_file
*next
;
3146 /* The next N_BINCL on the stack. */
3147 struct bincl_file
*next_stack
;
3148 /* The file name. */
3150 /* The hash value. */
3152 /* The file index. */
3154 /* The list of types defined in this file. */
3155 struct stab_types
*file_types
;
3158 /* Start a new N_BINCL file, pushing it onto the stack. */
3161 push_bincl (struct stab_handle
*info
, const char *name
, bfd_vma hash
)
3163 struct bincl_file
*n
;
3165 n
= (struct bincl_file
*) xmalloc (sizeof *n
);
3166 n
->next
= info
->bincl_list
;
3167 n
->next_stack
= info
->bincl_stack
;
3170 n
->file
= info
->files
;
3171 n
->file_types
= NULL
;
3172 info
->bincl_list
= n
;
3173 info
->bincl_stack
= n
;
3176 info
->file_types
= ((struct stab_types
**)
3177 xrealloc (info
->file_types
,
3179 * sizeof *info
->file_types
)));
3180 info
->file_types
[n
->file
] = NULL
;
3183 /* Finish an N_BINCL file, at an N_EINCL, popping the name off the
3187 pop_bincl (struct stab_handle
*info
)
3189 struct bincl_file
*o
;
3191 o
= info
->bincl_stack
;
3193 return info
->main_filename
;
3194 info
->bincl_stack
= o
->next_stack
;
3196 o
->file_types
= info
->file_types
[o
->file
];
3198 if (info
->bincl_stack
== NULL
)
3199 return info
->main_filename
;
3200 return info
->bincl_stack
->name
;
3203 /* Handle an N_EXCL: get the types from the corresponding N_BINCL. */
3206 find_excl (struct stab_handle
*info
, const char *name
, bfd_vma hash
)
3208 struct bincl_file
*l
;
3211 info
->file_types
= ((struct stab_types
**)
3212 xrealloc (info
->file_types
,
3214 * sizeof *info
->file_types
)));
3216 for (l
= info
->bincl_list
; l
!= NULL
; l
= l
->next
)
3217 if (l
->hash
== hash
&& strcmp (l
->name
, name
) == 0)
3221 warn_stab (name
, _("Undefined N_EXCL"));
3222 info
->file_types
[info
->files
- 1] = NULL
;
3226 info
->file_types
[info
->files
- 1] = l
->file_types
;
3231 /* Handle a variable definition. gcc emits variable definitions for a
3232 block before the N_LBRAC, so we must hold onto them until we see
3233 it. The SunPRO compiler emits variable definitions after the
3234 N_LBRAC, so we can call debug_record_variable immediately. */
3237 stab_record_variable (void *dhandle
, struct stab_handle
*info
,
3238 const char *name
, debug_type type
,
3239 enum debug_var_kind kind
, bfd_vma val
)
3241 struct stab_pending_var
*v
;
3243 if ((kind
== DEBUG_GLOBAL
|| kind
== DEBUG_STATIC
)
3244 || ! info
->within_function
3245 || (info
->gcc_compiled
== 0 && info
->n_opt_found
))
3246 return debug_record_variable (dhandle
, name
, type
, kind
, val
);
3248 v
= (struct stab_pending_var
*) xmalloc (sizeof *v
);
3249 memset (v
, 0, sizeof *v
);
3251 v
->next
= info
->pending
;
3261 /* Emit pending variable definitions. This is called after we see the
3262 N_LBRAC that starts the block. */
3265 stab_emit_pending_vars (void *dhandle
, struct stab_handle
*info
)
3267 struct stab_pending_var
*v
;
3272 struct stab_pending_var
*next
;
3274 if (! debug_record_variable (dhandle
, v
->name
, v
->type
, v
->kind
, v
->val
))
3282 info
->pending
= NULL
;
3287 /* Find the slot for a type in the database. */
3290 stab_find_slot (struct stab_handle
*info
, const int *typenums
)
3294 struct stab_types
**ps
;
3296 filenum
= typenums
[0];
3297 tindex
= typenums
[1];
3299 if (filenum
< 0 || (unsigned int) filenum
>= info
->files
)
3301 fprintf (stderr
, _("Type file number %d out of range\n"), filenum
);
3306 fprintf (stderr
, _("Type index number %d out of range\n"), tindex
);
3310 ps
= info
->file_types
+ filenum
;
3312 while (tindex
>= STAB_TYPES_SLOTS
)
3316 *ps
= (struct stab_types
*) xmalloc (sizeof **ps
);
3317 memset (*ps
, 0, sizeof **ps
);
3320 tindex
-= STAB_TYPES_SLOTS
;
3324 *ps
= (struct stab_types
*) xmalloc (sizeof **ps
);
3325 memset (*ps
, 0, sizeof **ps
);
3328 return (*ps
)->types
+ tindex
;
3331 /* Find a type given a type number. If the type has not been
3332 allocated yet, create an indirect type. */
3335 stab_find_type (void *dhandle
, struct stab_handle
*info
, const int *typenums
)
3339 if (typenums
[0] == 0 && typenums
[1] < 0)
3341 /* A negative type number indicates an XCOFF builtin type. */
3342 return stab_xcoff_builtin_type (dhandle
, info
, typenums
[1]);
3345 slot
= stab_find_slot (info
, typenums
);
3347 return DEBUG_TYPE_NULL
;
3349 if (*slot
== DEBUG_TYPE_NULL
)
3350 return debug_make_indirect_type (dhandle
, slot
, (const char *) NULL
);
3355 /* Record that a given type number refers to a given type. */
3358 stab_record_type (void *dhandle ATTRIBUTE_UNUSED
, struct stab_handle
*info
,
3359 const int *typenums
, debug_type type
)
3363 slot
= stab_find_slot (info
, typenums
);
3367 /* gdb appears to ignore type redefinitions, so we do as well. */
3374 /* Return an XCOFF builtin type. */
3377 stab_xcoff_builtin_type (void *dhandle
, struct stab_handle
*info
,
3383 if (typenum
>= 0 || typenum
< -XCOFF_TYPE_COUNT
)
3385 fprintf (stderr
, _("Unrecognized XCOFF type %d\n"), typenum
);
3386 return DEBUG_TYPE_NULL
;
3388 if (info
->xcoff_types
[-typenum
] != NULL
)
3389 return info
->xcoff_types
[-typenum
];
3394 /* The size of this and all the other types are fixed, defined
3395 by the debugging format. */
3397 rettype
= debug_make_int_type (dhandle
, 4, FALSE
);
3401 rettype
= debug_make_int_type (dhandle
, 1, FALSE
);
3405 rettype
= debug_make_int_type (dhandle
, 2, FALSE
);
3409 rettype
= debug_make_int_type (dhandle
, 4, FALSE
);
3412 name
= "unsigned char";
3413 rettype
= debug_make_int_type (dhandle
, 1, TRUE
);
3416 name
= "signed char";
3417 rettype
= debug_make_int_type (dhandle
, 1, FALSE
);
3420 name
= "unsigned short";
3421 rettype
= debug_make_int_type (dhandle
, 2, TRUE
);
3424 name
= "unsigned int";
3425 rettype
= debug_make_int_type (dhandle
, 4, TRUE
);
3429 rettype
= debug_make_int_type (dhandle
, 4, TRUE
);
3431 name
= "unsigned long";
3432 rettype
= debug_make_int_type (dhandle
, 4, TRUE
);
3436 rettype
= debug_make_void_type (dhandle
);
3439 /* IEEE single precision (32 bit). */
3441 rettype
= debug_make_float_type (dhandle
, 4);
3444 /* IEEE double precision (64 bit). */
3446 rettype
= debug_make_float_type (dhandle
, 8);
3449 /* This is an IEEE double on the RS/6000, and different machines
3450 with different sizes for "long double" should use different
3451 negative type numbers. See stabs.texinfo. */
3452 name
= "long double";
3453 rettype
= debug_make_float_type (dhandle
, 8);
3457 rettype
= debug_make_int_type (dhandle
, 4, FALSE
);
3461 rettype
= debug_make_bool_type (dhandle
, 4);
3464 name
= "short real";
3465 rettype
= debug_make_float_type (dhandle
, 4);
3469 rettype
= debug_make_float_type (dhandle
, 8);
3479 rettype
= debug_make_int_type (dhandle
, 1, TRUE
);
3483 rettype
= debug_make_bool_type (dhandle
, 1);
3487 rettype
= debug_make_bool_type (dhandle
, 2);
3491 rettype
= debug_make_bool_type (dhandle
, 4);
3495 rettype
= debug_make_bool_type (dhandle
, 4);
3498 /* Complex type consisting of two IEEE single precision values. */
3500 rettype
= debug_make_complex_type (dhandle
, 8);
3503 /* Complex type consisting of two IEEE double precision values. */
3504 name
= "double complex";
3505 rettype
= debug_make_complex_type (dhandle
, 16);
3509 rettype
= debug_make_int_type (dhandle
, 1, FALSE
);
3513 rettype
= debug_make_int_type (dhandle
, 2, FALSE
);
3517 rettype
= debug_make_int_type (dhandle
, 4, FALSE
);
3522 rettype
= debug_make_int_type (dhandle
, 2, FALSE
);
3526 rettype
= debug_make_int_type (dhandle
, 8, FALSE
);
3529 name
= "unsigned long long";
3530 rettype
= debug_make_int_type (dhandle
, 8, TRUE
);
3534 rettype
= debug_make_bool_type (dhandle
, 8);
3538 rettype
= debug_make_int_type (dhandle
, 8, FALSE
);
3544 rettype
= debug_name_type (dhandle
, name
, rettype
);
3546 info
->xcoff_types
[-typenum
] = rettype
;
3551 /* Find or create a tagged type. */
3554 stab_find_tagged_type (void *dhandle
, struct stab_handle
*info
,
3555 const char *p
, int len
, enum debug_type_kind kind
)
3559 struct stab_tag
*st
;
3561 name
= savestring (p
, len
);
3563 /* We pass DEBUG_KIND_ILLEGAL because we want all tags in the same
3564 namespace. This is right for C, and I don't know how to handle
3565 other languages. FIXME. */
3566 dtype
= debug_find_tagged_type (dhandle
, name
, DEBUG_KIND_ILLEGAL
);
3567 if (dtype
!= DEBUG_TYPE_NULL
)
3573 /* We need to allocate an entry on the undefined tag list. */
3574 for (st
= info
->tags
; st
!= NULL
; st
= st
->next
)
3576 if (st
->name
[0] == name
[0]
3577 && strcmp (st
->name
, name
) == 0)
3579 if (st
->kind
== DEBUG_KIND_ILLEGAL
)
3587 st
= (struct stab_tag
*) xmalloc (sizeof *st
);
3588 memset (st
, 0, sizeof *st
);
3590 st
->next
= info
->tags
;
3593 st
->slot
= DEBUG_TYPE_NULL
;
3594 st
->type
= debug_make_indirect_type (dhandle
, &st
->slot
, name
);
3601 /* In order to get the correct argument types for a stubbed method, we
3602 need to extract the argument types from a C++ mangled string.
3603 Since the argument types can refer back to the return type, this
3604 means that we must demangle the entire physical name. In gdb this
3605 is done by calling cplus_demangle and running the results back
3606 through the C++ expression parser. Since we have no expression
3607 parser, we must duplicate much of the work of cplus_demangle here.
3609 We assume that GNU style demangling is used, since this is only
3610 done for method stubs, and only g++ should output that form of
3611 debugging information. */
3613 /* This structure is used to hold a pointer to type information which
3614 demangling a string. */
3616 struct stab_demangle_typestring
3618 /* The start of the type. This is not null terminated. */
3619 const char *typestring
;
3620 /* The length of the type. */
3624 /* This structure is used to hold information while demangling a
3627 struct stab_demangle_info
3629 /* The debugging information handle. */
3631 /* The stab information handle. */
3632 struct stab_handle
*info
;
3633 /* The array of arguments we are building. */
3635 /* Whether the method takes a variable number of arguments. */
3636 bfd_boolean varargs
;
3637 /* The array of types we have remembered. */
3638 struct stab_demangle_typestring
*typestrings
;
3639 /* The number of typestrings. */
3640 unsigned int typestring_count
;
3641 /* The number of typestring slots we have allocated. */
3642 unsigned int typestring_alloc
;
3645 static void stab_bad_demangle (const char *);
3646 static unsigned int stab_demangle_count (const char **);
3647 static bfd_boolean
stab_demangle_get_count (const char **, unsigned int *);
3648 static bfd_boolean stab_demangle_prefix
3649 (struct stab_demangle_info
*, const char **, unsigned int);
3650 static bfd_boolean stab_demangle_function_name
3651 (struct stab_demangle_info
*, const char **, const char *);
3652 static bfd_boolean stab_demangle_signature
3653 (struct stab_demangle_info
*, const char **);
3654 static bfd_boolean stab_demangle_qualified
3655 (struct stab_demangle_info
*, const char **, debug_type
*);
3656 static bfd_boolean stab_demangle_template
3657 (struct stab_demangle_info
*, const char **, char **);
3658 static bfd_boolean stab_demangle_class
3659 (struct stab_demangle_info
*, const char **, const char **);
3660 static bfd_boolean stab_demangle_args
3661 (struct stab_demangle_info
*, const char **, debug_type
**, bfd_boolean
*);
3662 static bfd_boolean stab_demangle_arg
3663 (struct stab_demangle_info
*, const char **, debug_type
**,
3664 unsigned int *, unsigned int *);
3665 static bfd_boolean stab_demangle_type
3666 (struct stab_demangle_info
*, const char **, debug_type
*);
3667 static bfd_boolean stab_demangle_fund_type
3668 (struct stab_demangle_info
*, const char **, debug_type
*);
3669 static bfd_boolean stab_demangle_remember_type
3670 (struct stab_demangle_info
*, const char *, int);
3672 /* Warn about a bad demangling. */
3675 stab_bad_demangle (const char *s
)
3677 fprintf (stderr
, _("bad mangled name `%s'\n"), s
);
3680 /* Get a count from a stab string. */
3683 stab_demangle_count (const char **pp
)
3688 while (ISDIGIT (**pp
))
3691 count
+= **pp
- '0';
3697 /* Require a count in a string. The count may be multiple digits, in
3698 which case it must end in an underscore. */
3701 stab_demangle_get_count (const char **pp
, unsigned int *pi
)
3703 if (! ISDIGIT (**pp
))
3721 while (ISDIGIT (*p
));
3732 /* This function demangles a physical name, returning a NULL
3733 terminated array of argument types. */
3736 stab_demangle_argtypes (void *dhandle
, struct stab_handle
*info
,
3737 const char *physname
, bfd_boolean
*pvarargs
,
3738 unsigned int physname_len
)
3740 struct stab_demangle_info minfo
;
3742 /* Check for the g++ V3 ABI. */
3743 if (physname
[0] == '_' && physname
[1] == 'Z')
3744 return stab_demangle_v3_argtypes (dhandle
, info
, physname
, pvarargs
);
3746 minfo
.dhandle
= dhandle
;
3749 minfo
.varargs
= FALSE
;
3750 minfo
.typestring_alloc
= 10;
3751 minfo
.typestrings
= ((struct stab_demangle_typestring
*)
3752 xmalloc (minfo
.typestring_alloc
3753 * sizeof *minfo
.typestrings
));
3754 minfo
.typestring_count
= 0;
3756 /* cplus_demangle checks for special GNU mangled forms, but we can't
3757 see any of them in mangled method argument types. */
3759 if (! stab_demangle_prefix (&minfo
, &physname
, physname_len
))
3762 if (*physname
!= '\0')
3764 if (! stab_demangle_signature (&minfo
, &physname
))
3768 free (minfo
.typestrings
);
3769 minfo
.typestrings
= NULL
;
3771 if (minfo
.args
== NULL
)
3772 fprintf (stderr
, _("no argument types in mangled string\n"));
3774 *pvarargs
= minfo
.varargs
;
3778 if (minfo
.typestrings
!= NULL
)
3779 free (minfo
.typestrings
);
3783 /* Demangle the prefix of the mangled name. */
3786 stab_demangle_prefix (struct stab_demangle_info
*minfo
, const char **pp
,
3787 unsigned int physname_len
)
3792 /* cplus_demangle checks for global constructors and destructors,
3793 but we can't see them in mangled argument types. */
3796 scan
= *pp
+ physname_len
;
3799 /* Look for `__'. */
3802 scan
= strchr (scan
, '_');
3803 while (scan
!= NULL
&& *++scan
!= '_');
3807 stab_bad_demangle (*pp
);
3813 /* We found `__'; move ahead to the last contiguous `__' pair. */
3814 i
= strspn (scan
, "_");
3820 && (ISDIGIT (scan
[2])
3824 /* This is a GNU style constructor name. */
3828 else if (scan
== *pp
3829 && ! ISDIGIT (scan
[2])
3832 /* Look for the `__' that separates the prefix from the
3834 while (*scan
== '_')
3836 scan
= strstr (scan
, "__");
3837 if (scan
== NULL
|| scan
[2] == '\0')
3839 stab_bad_demangle (*pp
);
3843 return stab_demangle_function_name (minfo
, pp
, scan
);
3845 else if (scan
[2] != '\0')
3847 /* The name doesn't start with `__', but it does contain `__'. */
3848 return stab_demangle_function_name (minfo
, pp
, scan
);
3852 stab_bad_demangle (*pp
);
3858 /* Demangle a function name prefix. The scan argument points to the
3859 double underscore which separates the function name from the
3863 stab_demangle_function_name (struct stab_demangle_info
*minfo
,
3864 const char **pp
, const char *scan
)
3868 /* The string from *pp to scan is the name of the function. We
3869 don't care about the name, since we just looking for argument
3870 types. However, for conversion operators, the name may include a
3871 type which we must remember in order to handle backreferences. */
3877 && CONST_STRNEQ (name
, "type")
3878 && (name
[4] == '$' || name
[4] == '.'))
3882 /* This is a type conversion operator. */
3884 if (! stab_demangle_type (minfo
, &tem
, (debug_type
*) NULL
))
3887 else if (name
[0] == '_'
3894 /* This is a type conversion operator. */
3896 if (! stab_demangle_type (minfo
, &tem
, (debug_type
*) NULL
))
3903 /* Demangle the signature. This is where the argument types are
3907 stab_demangle_signature (struct stab_demangle_info
*minfo
, const char **pp
)
3910 bfd_boolean expect_func
, func_done
;
3915 expect_func
= FALSE
;
3919 while (**pp
!= '\0')
3925 if (! stab_demangle_qualified (minfo
, pp
, (debug_type
*) NULL
)
3926 || ! stab_demangle_remember_type (minfo
, hold
, *pp
- hold
))
3933 /* Static member function. FIXME: Can this happen? */
3940 /* Const member function. */
3946 case '0': case '1': case '2': case '3': case '4':
3947 case '5': case '6': case '7': case '8': case '9':
3950 if (! stab_demangle_class (minfo
, pp
, (const char **) NULL
)
3951 || ! stab_demangle_remember_type (minfo
, hold
, *pp
- hold
))
3958 /* Function. I don't know if this actually happens with g++
3963 if (! stab_demangle_args (minfo
, pp
, &minfo
->args
, &minfo
->varargs
))
3971 if (! stab_demangle_template (minfo
, pp
, (char **) NULL
)
3972 || ! stab_demangle_remember_type (minfo
, hold
, *pp
- hold
))
3979 /* At the outermost level, we cannot have a return type
3980 specified, so if we run into another '_' at this point we
3981 are dealing with a mangled name that is either bogus, or
3982 has been mangled by some algorithm we don't know how to
3983 deal with. So just reject the entire demangling. */
3984 stab_bad_demangle (orig
);
3988 /* Assume we have stumbled onto the first outermost function
3989 argument token, and start processing args. */
3991 if (! stab_demangle_args (minfo
, pp
, &minfo
->args
, &minfo
->varargs
))
3999 if (! stab_demangle_args (minfo
, pp
, &minfo
->args
, &minfo
->varargs
))
4006 /* With GNU style demangling, bar__3foo is 'foo::bar(void)', and
4007 bar__3fooi is 'foo::bar(int)'. We get here when we find the
4008 first case, and need to ensure that the '(void)' gets added
4009 to the current declp. */
4010 if (! stab_demangle_args (minfo
, pp
, &minfo
->args
, &minfo
->varargs
))
4017 /* Demangle a qualified name, such as "Q25Outer5Inner" which is the
4018 mangled form of "Outer::Inner". */
4021 stab_demangle_qualified (struct stab_demangle_info
*minfo
, const char **pp
,
4026 unsigned int qualifiers
;
4034 /* GNU mangled name with more than 9 classes. The count is
4035 preceded by an underscore (to distinguish it from the <= 9
4036 case) and followed by an underscore. */
4038 if (! ISDIGIT (*p
) || *p
== '0')
4040 stab_bad_demangle (orig
);
4043 qualifiers
= atoi (p
);
4044 while (ISDIGIT (*p
))
4048 stab_bad_demangle (orig
);
4054 case '1': case '2': case '3': case '4': case '5':
4055 case '6': case '7': case '8': case '9':
4056 qualifiers
= (*pp
)[1] - '0';
4057 /* Skip an optional underscore after the count. */
4058 if ((*pp
)[2] == '_')
4065 stab_bad_demangle (orig
);
4069 context
= DEBUG_TYPE_NULL
;
4071 /* Pick off the names. */
4072 while (qualifiers
-- > 0)
4080 if (! stab_demangle_template (minfo
, pp
,
4081 ptype
!= NULL
? &name
: NULL
))
4086 context
= stab_find_tagged_type (minfo
->dhandle
, minfo
->info
,
4087 name
, strlen (name
),
4090 if (context
== DEBUG_TYPE_NULL
)
4098 len
= stab_demangle_count (pp
);
4099 if (strlen (*pp
) < len
)
4101 stab_bad_demangle (orig
);
4107 const debug_field
*fields
;
4110 if (context
!= DEBUG_TYPE_NULL
)
4111 fields
= debug_get_fields (minfo
->dhandle
, context
);
4113 context
= DEBUG_TYPE_NULL
;
4119 /* Try to find the type by looking through the
4120 fields of context until we find a field with the
4121 same type. This ought to work for a class
4122 defined within a class, but it won't work for,
4123 e.g., an enum defined within a class. stabs does
4124 not give us enough information to figure out the
4127 name
= savestring (*pp
, len
);
4129 for (; *fields
!= DEBUG_FIELD_NULL
; fields
++)
4134 ft
= debug_get_field_type (minfo
->dhandle
, *fields
);
4140 dn
= debug_get_type_name (minfo
->dhandle
, ft
);
4141 if (dn
!= NULL
&& strcmp (dn
, name
) == 0)
4151 if (context
== DEBUG_TYPE_NULL
)
4153 /* We have to fall back on finding the type by name.
4154 If there are more types to come, then this must
4155 be a class. Otherwise, it could be anything. */
4157 if (qualifiers
== 0)
4161 name
= savestring (*pp
, len
);
4162 context
= debug_find_named_type (minfo
->dhandle
,
4167 if (context
== DEBUG_TYPE_NULL
)
4169 context
= stab_find_tagged_type (minfo
->dhandle
,
4173 ? DEBUG_KIND_ILLEGAL
4174 : DEBUG_KIND_CLASS
));
4175 if (context
== DEBUG_TYPE_NULL
)
4191 /* Demangle a template. If PNAME is not NULL, this sets *PNAME to a
4192 string representation of the template. */
4195 stab_demangle_template (struct stab_demangle_info
*minfo
, const char **pp
,
4205 /* Skip the template name. */
4206 r
= stab_demangle_count (pp
);
4207 if (r
== 0 || strlen (*pp
) < r
)
4209 stab_bad_demangle (orig
);
4214 /* Get the size of the parameter list. */
4215 if (stab_demangle_get_count (pp
, &r
) == 0)
4217 stab_bad_demangle (orig
);
4221 for (i
= 0; i
< r
; i
++)
4225 /* This is a type parameter. */
4227 if (! stab_demangle_type (minfo
, pp
, (debug_type
*) NULL
))
4233 bfd_boolean pointerp
, realp
, integralp
, charp
, boolp
;
4244 /* This is a value parameter. */
4246 if (! stab_demangle_type (minfo
, pp
, (debug_type
*) NULL
))
4249 while (*old_p
!= '\0' && ! done
)
4259 case 'C': /* Const. */
4260 case 'S': /* Signed. */
4261 case 'U': /* Unsigned. */
4262 case 'V': /* Volatile. */
4263 case 'F': /* Function. */
4264 case 'M': /* Member function. */
4268 case 'Q': /* Qualified name. */
4272 case 'T': /* Remembered type. */
4274 case 'v': /* Void. */
4276 case 'x': /* Long long. */
4277 case 'l': /* Long. */
4278 case 'i': /* Int. */
4279 case 's': /* Short. */
4280 case 'w': /* Wchar_t. */
4284 case 'b': /* Bool. */
4288 case 'c': /* Char. */
4292 case 'r': /* Long double. */
4293 case 'd': /* Double. */
4294 case 'f': /* Float. */
4299 /* Assume it's a user defined integral type. */
4310 while (ISDIGIT (**pp
))
4319 val
= stab_demangle_count (pp
);
4322 stab_bad_demangle (orig
);
4330 val
= stab_demangle_count (pp
);
4331 if (val
!= 0 && val
!= 1)
4333 stab_bad_demangle (orig
);
4341 while (ISDIGIT (**pp
))
4346 while (ISDIGIT (**pp
))
4352 while (ISDIGIT (**pp
))
4360 len
= stab_demangle_count (pp
);
4363 stab_bad_demangle (orig
);
4371 /* We can translate this to a string fairly easily by invoking the
4372 regular demangling routine. */
4375 char *s1
, *s2
, *s3
, *s4
= NULL
;
4378 s1
= savestring (orig
, *pp
- orig
);
4380 s2
= concat ("NoSuchStrinG__", s1
, (const char *) NULL
);
4384 s3
= cplus_demangle (s2
, DMGL_ANSI
);
4389 s4
= strstr (s3
, "::NoSuchStrinG");
4390 if (s3
== NULL
|| s4
== NULL
)
4392 stab_bad_demangle (orig
);
4398 /* Eliminating all spaces, except those between > characters,
4399 makes it more likely that the demangled name will match the
4400 name which g++ used as the structure name. */
4401 for (from
= to
= s3
; from
!= s4
; ++from
)
4403 || (from
[1] == '>' && from
> s3
&& from
[-1] == '>'))
4406 *pname
= savestring (s3
, to
- s3
);
4414 /* Demangle a class name. */
4417 stab_demangle_class (struct stab_demangle_info
*minfo ATTRIBUTE_UNUSED
,
4418 const char **pp
, const char **pstart
)
4425 n
= stab_demangle_count (pp
);
4426 if (strlen (*pp
) < n
)
4428 stab_bad_demangle (orig
);
4440 /* Demangle function arguments. If the pargs argument is not NULL, it
4441 is set to a NULL terminated array holding the arguments. */
4444 stab_demangle_args (struct stab_demangle_info
*minfo
, const char **pp
,
4445 debug_type
**pargs
, bfd_boolean
*pvarargs
)
4448 unsigned int alloc
, count
;
4455 *pargs
= (debug_type
*) xmalloc (alloc
* sizeof **pargs
);
4460 while (**pp
!= '_' && **pp
!= '\0' && **pp
!= 'e')
4462 if (**pp
== 'N' || **pp
== 'T')
4470 if (temptype
== 'T')
4474 if (! stab_demangle_get_count (pp
, &r
))
4476 stab_bad_demangle (orig
);
4481 if (! stab_demangle_get_count (pp
, &t
))
4483 stab_bad_demangle (orig
);
4487 if (t
>= minfo
->typestring_count
)
4489 stab_bad_demangle (orig
);
4496 tem
= minfo
->typestrings
[t
].typestring
;
4497 if (! stab_demangle_arg (minfo
, &tem
, pargs
, &count
, &alloc
))
4503 if (! stab_demangle_arg (minfo
, pp
, pargs
, &count
, &alloc
))
4509 (*pargs
)[count
] = DEBUG_TYPE_NULL
;
4521 /* Demangle a single argument. */
4524 stab_demangle_arg (struct stab_demangle_info
*minfo
, const char **pp
,
4525 debug_type
**pargs
, unsigned int *pcount
,
4526 unsigned int *palloc
)
4532 if (! stab_demangle_type (minfo
, pp
,
4533 pargs
== NULL
? (debug_type
*) NULL
: &type
)
4534 || ! stab_demangle_remember_type (minfo
, start
, *pp
- start
))
4539 if (type
== DEBUG_TYPE_NULL
)
4542 if (*pcount
+ 1 >= *palloc
)
4545 *pargs
= ((debug_type
*)
4546 xrealloc (*pargs
, *palloc
* sizeof **pargs
));
4548 (*pargs
)[*pcount
] = type
;
4555 /* Demangle a type. If the ptype argument is not NULL, *ptype is set
4556 to the newly allocated type. */
4559 stab_demangle_type (struct stab_demangle_info
*minfo
, const char **pp
,
4570 /* A pointer type. */
4572 if (! stab_demangle_type (minfo
, pp
, ptype
))
4575 *ptype
= debug_make_pointer_type (minfo
->dhandle
, *ptype
);
4579 /* A reference type. */
4581 if (! stab_demangle_type (minfo
, pp
, ptype
))
4584 *ptype
= debug_make_reference_type (minfo
->dhandle
, *ptype
);
4594 while (**pp
!= '\0' && **pp
!= '_')
4596 if (! ISDIGIT (**pp
))
4598 stab_bad_demangle (orig
);
4607 stab_bad_demangle (orig
);
4612 if (! stab_demangle_type (minfo
, pp
, ptype
))
4616 debug_type int_type
;
4618 int_type
= debug_find_named_type (minfo
->dhandle
, "int");
4619 if (int_type
== NULL
)
4620 int_type
= debug_make_int_type (minfo
->dhandle
, 4, FALSE
);
4621 *ptype
= debug_make_array_type (minfo
->dhandle
, *ptype
, int_type
,
4628 /* A back reference to a remembered type. */
4634 if (! stab_demangle_get_count (pp
, &i
))
4636 stab_bad_demangle (orig
);
4639 if (i
>= minfo
->typestring_count
)
4641 stab_bad_demangle (orig
);
4644 p
= minfo
->typestrings
[i
].typestring
;
4645 if (! stab_demangle_type (minfo
, &p
, ptype
))
4654 bfd_boolean varargs
;
4657 if (! stab_demangle_args (minfo
, pp
,
4659 ? (debug_type
**) NULL
4662 ? (bfd_boolean
*) NULL
4667 /* cplus_demangle will accept a function without a return
4668 type, but I don't know when that will happen, or what
4669 to do if it does. */
4670 stab_bad_demangle (orig
);
4674 if (! stab_demangle_type (minfo
, pp
, ptype
))
4677 *ptype
= debug_make_function_type (minfo
->dhandle
, *ptype
, args
,
4686 bfd_boolean memberp
;
4687 debug_type class_type
= DEBUG_TYPE_NULL
;
4689 bfd_boolean varargs
;
4693 memberp
= **pp
== 'M';
4700 n
= stab_demangle_count (pp
);
4701 if (strlen (*pp
) < n
)
4703 stab_bad_demangle (orig
);
4711 class_type
= stab_find_tagged_type (minfo
->dhandle
,
4715 if (class_type
== DEBUG_TYPE_NULL
)
4719 else if (**pp
== 'Q')
4721 if (! stab_demangle_qualified (minfo
, pp
,
4723 ? (debug_type
*) NULL
4729 stab_bad_demangle (orig
);
4739 else if (**pp
== 'V')
4745 stab_bad_demangle (orig
);
4749 if (! stab_demangle_args (minfo
, pp
,
4751 ? (debug_type
**) NULL
4754 ? (bfd_boolean
*) NULL
4761 stab_bad_demangle (orig
);
4766 if (! stab_demangle_type (minfo
, pp
, ptype
))
4772 *ptype
= debug_make_offset_type (minfo
->dhandle
, class_type
,
4776 /* FIXME: We have no way to record constp or
4778 *ptype
= debug_make_method_type (minfo
->dhandle
, *ptype
,
4779 class_type
, args
, varargs
);
4787 if (! stab_demangle_type (minfo
, pp
, ptype
))
4793 if (! stab_demangle_type (minfo
, pp
, ptype
))
4796 *ptype
= debug_make_const_type (minfo
->dhandle
, *ptype
);
4801 if (! stab_demangle_qualified (minfo
, pp
, ptype
))
4807 if (! stab_demangle_fund_type (minfo
, pp
, ptype
))
4815 /* Demangle a fundamental type. If the ptype argument is not NULL,
4816 *ptype is set to the newly allocated type. */
4819 stab_demangle_fund_type (struct stab_demangle_info
*minfo
, const char **pp
,
4823 bfd_boolean constp
, volatilep
, unsignedp
, signedp
;
4868 /* cplus_demangle permits this, but I don't know what it means. */
4869 stab_bad_demangle (orig
);
4872 case 'v': /* void */
4875 *ptype
= debug_find_named_type (minfo
->dhandle
, "void");
4876 if (*ptype
== DEBUG_TYPE_NULL
)
4877 *ptype
= debug_make_void_type (minfo
->dhandle
);
4882 case 'x': /* long long */
4885 *ptype
= debug_find_named_type (minfo
->dhandle
,
4887 ? "long long unsigned int"
4888 : "long long int"));
4889 if (*ptype
== DEBUG_TYPE_NULL
)
4890 *ptype
= debug_make_int_type (minfo
->dhandle
, 8, unsignedp
);
4895 case 'l': /* long */
4898 *ptype
= debug_find_named_type (minfo
->dhandle
,
4900 ? "long unsigned int"
4902 if (*ptype
== DEBUG_TYPE_NULL
)
4903 *ptype
= debug_make_int_type (minfo
->dhandle
, 4, unsignedp
);
4911 *ptype
= debug_find_named_type (minfo
->dhandle
,
4915 if (*ptype
== DEBUG_TYPE_NULL
)
4916 *ptype
= debug_make_int_type (minfo
->dhandle
, 4, unsignedp
);
4921 case 's': /* short */
4924 *ptype
= debug_find_named_type (minfo
->dhandle
,
4926 ? "short unsigned int"
4928 if (*ptype
== DEBUG_TYPE_NULL
)
4929 *ptype
= debug_make_int_type (minfo
->dhandle
, 2, unsignedp
);
4934 case 'b': /* bool */
4937 *ptype
= debug_find_named_type (minfo
->dhandle
, "bool");
4938 if (*ptype
== DEBUG_TYPE_NULL
)
4939 *ptype
= debug_make_bool_type (minfo
->dhandle
, 4);
4944 case 'c': /* char */
4947 *ptype
= debug_find_named_type (minfo
->dhandle
,
4953 if (*ptype
== DEBUG_TYPE_NULL
)
4954 *ptype
= debug_make_int_type (minfo
->dhandle
, 1, unsignedp
);
4959 case 'w': /* wchar_t */
4962 *ptype
= debug_find_named_type (minfo
->dhandle
, "__wchar_t");
4963 if (*ptype
== DEBUG_TYPE_NULL
)
4964 *ptype
= debug_make_int_type (minfo
->dhandle
, 2, TRUE
);
4969 case 'r': /* long double */
4972 *ptype
= debug_find_named_type (minfo
->dhandle
, "long double");
4973 if (*ptype
== DEBUG_TYPE_NULL
)
4974 *ptype
= debug_make_float_type (minfo
->dhandle
, 8);
4979 case 'd': /* double */
4982 *ptype
= debug_find_named_type (minfo
->dhandle
, "double");
4983 if (*ptype
== DEBUG_TYPE_NULL
)
4984 *ptype
= debug_make_float_type (minfo
->dhandle
, 8);
4989 case 'f': /* float */
4992 *ptype
= debug_find_named_type (minfo
->dhandle
, "float");
4993 if (*ptype
== DEBUG_TYPE_NULL
)
4994 *ptype
= debug_make_float_type (minfo
->dhandle
, 4);
5001 if (! ISDIGIT (**pp
))
5003 stab_bad_demangle (orig
);
5007 case '0': case '1': case '2': case '3': case '4':
5008 case '5': case '6': case '7': case '8': case '9':
5012 if (! stab_demangle_class (minfo
, pp
, &hold
))
5018 name
= savestring (hold
, *pp
- hold
);
5019 *ptype
= debug_find_named_type (minfo
->dhandle
, name
);
5021 if (*ptype
== DEBUG_TYPE_NULL
)
5023 /* FIXME: It is probably incorrect to assume that
5024 undefined types are tagged types. */
5025 *ptype
= stab_find_tagged_type (minfo
->dhandle
, minfo
->info
,
5027 DEBUG_KIND_ILLEGAL
);
5028 if (*ptype
== DEBUG_TYPE_NULL
)
5039 if (! stab_demangle_template (minfo
, pp
,
5040 ptype
!= NULL
? &name
: NULL
))
5044 *ptype
= stab_find_tagged_type (minfo
->dhandle
, minfo
->info
,
5045 name
, strlen (name
),
5048 if (*ptype
== DEBUG_TYPE_NULL
)
5055 stab_bad_demangle (orig
);
5062 *ptype
= debug_make_const_type (minfo
->dhandle
, *ptype
);
5064 *ptype
= debug_make_volatile_type (minfo
->dhandle
, *ptype
);
5070 /* Remember a type string in a demangled string. */
5073 stab_demangle_remember_type (struct stab_demangle_info
*minfo
,
5074 const char *p
, int len
)
5076 if (minfo
->typestring_count
>= minfo
->typestring_alloc
)
5078 minfo
->typestring_alloc
+= 10;
5079 minfo
->typestrings
= ((struct stab_demangle_typestring
*)
5080 xrealloc (minfo
->typestrings
,
5081 (minfo
->typestring_alloc
5082 * sizeof *minfo
->typestrings
)));
5085 minfo
->typestrings
[minfo
->typestring_count
].typestring
= p
;
5086 minfo
->typestrings
[minfo
->typestring_count
].len
= (unsigned int) len
;
5087 ++minfo
->typestring_count
;
5092 /* Demangle names encoded using the g++ V3 ABI. The newer versions of
5093 g++ which use this ABI do not encode ordinary method argument types
5094 in a mangled name; they simply output the argument types. However,
5095 for a static method, g++ simply outputs the return type and the
5096 physical name. So in that case we need to demangle the name here.
5097 Here PHYSNAME is the physical name of the function, and we set the
5098 variable pointed at by PVARARGS to indicate whether this function
5099 is varargs. This returns NULL, or a NULL terminated array of
5103 stab_demangle_v3_argtypes (void *dhandle
, struct stab_handle
*info
,
5104 const char *physname
, bfd_boolean
*pvarargs
)
5106 struct demangle_component
*dc
;
5110 dc
= cplus_demangle_v3_components (physname
, DMGL_PARAMS
| DMGL_ANSI
, &mem
);
5113 stab_bad_demangle (physname
);
5117 /* We expect to see TYPED_NAME, and the right subtree describes the
5119 if (dc
->type
!= DEMANGLE_COMPONENT_TYPED_NAME
5120 || dc
->u
.s_binary
.right
->type
!= DEMANGLE_COMPONENT_FUNCTION_TYPE
)
5122 fprintf (stderr
, _("Demangled name is not a function\n"));
5127 pargs
= stab_demangle_v3_arglist (dhandle
, info
,
5128 dc
->u
.s_binary
.right
->u
.s_binary
.right
,
5136 /* Demangle an argument list in a struct demangle_component tree.
5137 Returns a DEBUG_TYPE_NULL terminated array of argument types, and
5138 sets *PVARARGS to indicate whether this is a varargs function. */
5141 stab_demangle_v3_arglist (void *dhandle
, struct stab_handle
*info
,
5142 struct demangle_component
*arglist
,
5143 bfd_boolean
*pvarargs
)
5145 struct demangle_component
*dc
;
5146 unsigned int alloc
, count
;
5150 pargs
= (debug_type
*) xmalloc (alloc
* sizeof *pargs
);
5157 dc
= dc
->u
.s_binary
.right
)
5160 bfd_boolean varargs
;
5162 if (dc
->type
!= DEMANGLE_COMPONENT_ARGLIST
)
5164 fprintf (stderr
, _("Unexpected type in v3 arglist demangling\n"));
5169 /* PR 13925: Cope if the demangler returns an empty
5170 context for a function with no arguments. */
5171 if (dc
->u
.s_binary
.left
== NULL
)
5174 arg
= stab_demangle_v3_arg (dhandle
, info
, dc
->u
.s_binary
.left
,
5187 if (count
+ 1 >= alloc
)
5190 pargs
= (debug_type
*) xrealloc (pargs
, alloc
* sizeof *pargs
);
5197 pargs
[count
] = DEBUG_TYPE_NULL
;
5202 /* Convert a struct demangle_component tree describing an argument
5203 type into a debug_type. */
5206 stab_demangle_v3_arg (void *dhandle
, struct stab_handle
*info
,
5207 struct demangle_component
*dc
, debug_type context
,
5208 bfd_boolean
*pvarargs
)
5212 if (pvarargs
!= NULL
)
5217 /* FIXME: These are demangle component types which we probably
5218 need to handle one way or another. */
5219 case DEMANGLE_COMPONENT_LOCAL_NAME
:
5220 case DEMANGLE_COMPONENT_TYPED_NAME
:
5221 case DEMANGLE_COMPONENT_TEMPLATE_PARAM
:
5222 case DEMANGLE_COMPONENT_CTOR
:
5223 case DEMANGLE_COMPONENT_DTOR
:
5224 case DEMANGLE_COMPONENT_JAVA_CLASS
:
5225 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
5226 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
5227 case DEMANGLE_COMPONENT_CONST_THIS
:
5228 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
5229 case DEMANGLE_COMPONENT_COMPLEX
:
5230 case DEMANGLE_COMPONENT_IMAGINARY
:
5231 case DEMANGLE_COMPONENT_VENDOR_TYPE
:
5232 case DEMANGLE_COMPONENT_ARRAY_TYPE
:
5233 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
5234 case DEMANGLE_COMPONENT_ARGLIST
:
5236 fprintf (stderr
, _("Unrecognized demangle component %d\n"),
5240 case DEMANGLE_COMPONENT_NAME
:
5241 if (context
!= NULL
)
5243 const debug_field
*fields
;
5245 fields
= debug_get_fields (dhandle
, context
);
5248 /* Try to find this type by looking through the context
5250 for (; *fields
!= DEBUG_FIELD_NULL
; fields
++)
5255 ft
= debug_get_field_type (dhandle
, *fields
);
5258 dn
= debug_get_type_name (dhandle
, ft
);
5260 && (int) strlen (dn
) == dc
->u
.s_name
.len
5261 && strncmp (dn
, dc
->u
.s_name
.s
, dc
->u
.s_name
.len
) == 0)
5266 return stab_find_tagged_type (dhandle
, info
, dc
->u
.s_name
.s
,
5267 dc
->u
.s_name
.len
, DEBUG_KIND_ILLEGAL
);
5269 case DEMANGLE_COMPONENT_QUAL_NAME
:
5270 context
= stab_demangle_v3_arg (dhandle
, info
, dc
->u
.s_binary
.left
,
5272 if (context
== NULL
)
5274 return stab_demangle_v3_arg (dhandle
, info
, dc
->u
.s_binary
.right
,
5277 case DEMANGLE_COMPONENT_TEMPLATE
:
5282 /* We print this component to get a class name which we can
5283 use. FIXME: This probably won't work if the template uses
5284 template parameters which refer to an outer template. */
5285 p
= cplus_demangle_print (DMGL_PARAMS
| DMGL_ANSI
, dc
, 20, &alc
);
5288 fprintf (stderr
, _("Failed to print demangled template\n"));
5291 dt
= stab_find_tagged_type (dhandle
, info
, p
, strlen (p
),
5297 case DEMANGLE_COMPONENT_SUB_STD
:
5298 return stab_find_tagged_type (dhandle
, info
, dc
->u
.s_string
.string
,
5299 dc
->u
.s_string
.len
, DEBUG_KIND_ILLEGAL
);
5301 case DEMANGLE_COMPONENT_RESTRICT
:
5302 case DEMANGLE_COMPONENT_VOLATILE
:
5303 case DEMANGLE_COMPONENT_CONST
:
5304 case DEMANGLE_COMPONENT_POINTER
:
5305 case DEMANGLE_COMPONENT_REFERENCE
:
5306 dt
= stab_demangle_v3_arg (dhandle
, info
, dc
->u
.s_binary
.left
, NULL
,
5315 case DEMANGLE_COMPONENT_RESTRICT
:
5316 /* FIXME: We have no way to represent restrict. */
5318 case DEMANGLE_COMPONENT_VOLATILE
:
5319 return debug_make_volatile_type (dhandle
, dt
);
5320 case DEMANGLE_COMPONENT_CONST
:
5321 return debug_make_const_type (dhandle
, dt
);
5322 case DEMANGLE_COMPONENT_POINTER
:
5323 return debug_make_pointer_type (dhandle
, dt
);
5324 case DEMANGLE_COMPONENT_REFERENCE
:
5325 return debug_make_reference_type (dhandle
, dt
);
5328 case DEMANGLE_COMPONENT_FUNCTION_TYPE
:
5331 bfd_boolean varargs
;
5333 if (dc
->u
.s_binary
.left
== NULL
)
5335 /* In this case the return type is actually unknown.
5336 However, I'm not sure this will ever arise in practice;
5337 normally an unknown return type would only appear at
5338 the top level, which is handled above. */
5339 dt
= debug_make_void_type (dhandle
);
5342 dt
= stab_demangle_v3_arg (dhandle
, info
, dc
->u
.s_binary
.left
, NULL
,
5347 pargs
= stab_demangle_v3_arglist (dhandle
, info
,
5348 dc
->u
.s_binary
.right
,
5353 return debug_make_function_type (dhandle
, dt
, pargs
, varargs
);
5356 case DEMANGLE_COMPONENT_BUILTIN_TYPE
:
5362 /* We print this component in order to find out the type name.
5363 FIXME: Should we instead expose the
5364 demangle_builtin_type_info structure? */
5365 p
= cplus_demangle_print (DMGL_PARAMS
| DMGL_ANSI
, dc
, 20, &alc
);
5368 fprintf (stderr
, _("Couldn't get demangled builtin type\n"));
5372 /* The mangling is based on the type, but does not itself
5373 indicate what the sizes are. So we have to guess. */
5374 if (strcmp (p
, "signed char") == 0)
5375 ret
= debug_make_int_type (dhandle
, 1, FALSE
);
5376 else if (strcmp (p
, "bool") == 0)
5377 ret
= debug_make_bool_type (dhandle
, 1);
5378 else if (strcmp (p
, "char") == 0)
5379 ret
= debug_make_int_type (dhandle
, 1, FALSE
);
5380 else if (strcmp (p
, "double") == 0)
5381 ret
= debug_make_float_type (dhandle
, 8);
5382 else if (strcmp (p
, "long double") == 0)
5383 ret
= debug_make_float_type (dhandle
, 8);
5384 else if (strcmp (p
, "float") == 0)
5385 ret
= debug_make_float_type (dhandle
, 4);
5386 else if (strcmp (p
, "__float128") == 0)
5387 ret
= debug_make_float_type (dhandle
, 16);
5388 else if (strcmp (p
, "unsigned char") == 0)
5389 ret
= debug_make_int_type (dhandle
, 1, TRUE
);
5390 else if (strcmp (p
, "int") == 0)
5391 ret
= debug_make_int_type (dhandle
, 4, FALSE
);
5392 else if (strcmp (p
, "unsigned int") == 0)
5393 ret
= debug_make_int_type (dhandle
, 4, TRUE
);
5394 else if (strcmp (p
, "long") == 0)
5395 ret
= debug_make_int_type (dhandle
, 4, FALSE
);
5396 else if (strcmp (p
, "unsigned long") == 0)
5397 ret
= debug_make_int_type (dhandle
, 4, TRUE
);
5398 else if (strcmp (p
, "__int128") == 0)
5399 ret
= debug_make_int_type (dhandle
, 16, FALSE
);
5400 else if (strcmp (p
, "unsigned __int128") == 0)
5401 ret
= debug_make_int_type (dhandle
, 16, TRUE
);
5402 else if (strcmp (p
, "short") == 0)
5403 ret
= debug_make_int_type (dhandle
, 2, FALSE
);
5404 else if (strcmp (p
, "unsigned short") == 0)
5405 ret
= debug_make_int_type (dhandle
, 2, TRUE
);
5406 else if (strcmp (p
, "void") == 0)
5407 ret
= debug_make_void_type (dhandle
);
5408 else if (strcmp (p
, "wchar_t") == 0)
5409 ret
= debug_make_int_type (dhandle
, 4, TRUE
);
5410 else if (strcmp (p
, "long long") == 0)
5411 ret
= debug_make_int_type (dhandle
, 8, FALSE
);
5412 else if (strcmp (p
, "unsigned long long") == 0)
5413 ret
= debug_make_int_type (dhandle
, 8, TRUE
);
5414 else if (strcmp (p
, "...") == 0)
5416 if (pvarargs
== NULL
)
5417 fprintf (stderr
, _("Unexpected demangled varargs\n"));
5424 fprintf (stderr
, _("Unrecognized demangled builtin type\n"));