1 /* stabs.c -- Parse stabs debugging information
2 Copyright (C) 1995-2023 Free Software Foundation, Inc.
3 Written by Ian Lance Taylor <ian@cygnus.com>.
5 This file is part of GNU Binutils.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
22 /* This file contains code which parses stabs debugging information.
23 The organization of this code is based on the gdb stabs reading
24 code. The job it does is somewhat different, because it is not
25 trying to identify the correct address for anything. */
29 #include "libiberty.h"
30 #include "safe-ctype.h"
34 #include "filenames.h"
35 #include "aout/aout64.h"
36 #include "aout/stab_gnu.h"
38 /* The number of predefined XCOFF types. */
40 #define XCOFF_TYPE_COUNT 34
42 /* This structure is used as a handle so that the stab parsing doesn't
43 need to use any static variables. */
49 /* TRUE if this is stabs in sections. */
51 /* The symbol table. */
53 /* The number of symbols. */
55 /* The accumulated file name string. */
57 /* The value of the last N_SO symbol. */
59 /* The value of the start of the file, so that we can handle file
60 relative N_LBRAC and N_RBRAC symbols. */
61 bfd_vma file_start_offset
;
62 /* The offset of the start of the function, so that we can handle
63 function relative N_LBRAC and N_RBRAC symbols. */
64 bfd_vma function_start_offset
;
65 /* The version number of gcc which compiled the current compilation
66 unit, 0 if not compiled by gcc. */
68 /* Whether an N_OPT symbol was seen that was not generated by gcc,
69 so that we can detect the SunPRO compiler. */
71 /* The main file name. */
73 /* A stack of unfinished N_BINCL files. */
74 struct bincl_file
*bincl_stack
;
75 /* A list of finished N_BINCL files. */
76 struct bincl_file
*bincl_list
;
77 /* Whether we are inside a function or not. */
79 /* The address of the end of the function, used if we have seen an
80 N_FUN symbol while in a function. This is -1 if we have not seen
81 an N_FUN (the normal case). */
83 /* The depth of block nesting. */
85 /* List of pending variable definitions. */
86 struct stab_pending_var
*pending
;
87 /* Number of files for which we have types. */
89 /* Lists of types per file. */
90 struct stab_types
**file_types
;
91 /* Predefined XCOFF types. */
92 debug_type xcoff_types
[XCOFF_TYPE_COUNT
];
94 struct stab_tag
*tags
;
95 /* Set by parse_stab_type if it sees a structure defined as a cross
96 reference to itself. Reset by parse_stab_type otherwise. */
100 /* A list of these structures is used to hold pending variable
101 definitions seen before the N_LBRAC of a block. */
103 struct stab_pending_var
105 /* Next pending variable definition. */
106 struct stab_pending_var
*next
;
112 enum debug_var_kind kind
;
117 /* A list of these structures is used to hold the types for a single
122 /* Next set of slots for this file. */
123 struct stab_types
*next
;
124 /* Where the TYPES array starts. */
125 unsigned int base_index
;
126 /* Types indexed by type number. */
127 #define STAB_TYPES_SLOTS (16)
128 debug_type types
[STAB_TYPES_SLOTS
];
131 /* We keep a list of undefined tags that we encounter, so that we can
132 fill them in if the tag is later defined. */
136 /* Next undefined tag. */
137 struct stab_tag
*next
;
141 enum debug_type_kind kind
;
142 /* Slot to hold real type when we discover it. If we don't, we fill
143 in an undefined tag type. */
145 /* Indirect type we have created to point at slot. */
149 static char *savestring (const char *, int);
151 static void bad_stab (const char *);
152 static void warn_stab (const char *, const char *);
153 static bool parse_stab_string
154 (void *, struct stab_handle
*, int, int, bfd_vma
,
155 const char *, const char *);
156 static debug_type parse_stab_type
157 (void *, struct stab_handle
*, const char *, const char **,
158 debug_type
**, const char *);
159 static bool parse_stab_type_number
160 (const char **, int *, const char *);
161 static debug_type parse_stab_range_type
162 (void *, struct stab_handle
*, const char *, const char **,
163 const int *, const char *);
164 static debug_type parse_stab_sun_builtin_type
165 (void *, const char **, const char *);
166 static debug_type parse_stab_sun_floating_type
167 (void *, const char **, const char *);
168 static debug_type parse_stab_enum_type
169 (void *, const char **, const char *);
170 static debug_type parse_stab_struct_type
171 (void *, struct stab_handle
*, const char *, const char **,
172 bool, const int *, const char *);
173 static bool parse_stab_baseclasses
174 (void *, struct stab_handle
*, const char **, debug_baseclass
**,
176 static bool parse_stab_struct_fields
177 (void *, struct stab_handle
*, const char **, debug_field
**,
178 bool *, const char *);
179 static bool parse_stab_cpp_abbrev
180 (void *, struct stab_handle
*, const char **, debug_field
*, const char *);
181 static bool parse_stab_one_struct_field
182 (void *, struct stab_handle
*, const char **, const char *,
183 debug_field
*, bool *, const char *);
184 static bool parse_stab_members
185 (void *, struct stab_handle
*, const char *, const char **, const int *,
186 debug_method
**, const char *);
187 static debug_type parse_stab_argtypes
188 (void *, struct stab_handle
*, debug_type
, const char *, const char *,
189 debug_type
, const char *, bool, bool, const char **);
190 static bool parse_stab_tilde_field
191 (void *, struct stab_handle
*, const char **, const int *, debug_type
*,
192 bool *, const char *);
193 static debug_type parse_stab_array_type
194 (void *, struct stab_handle
*, const char **, bool, const char *);
195 static void push_bincl (struct stab_handle
*, const char *, bfd_vma
);
196 static const char *pop_bincl (struct stab_handle
*);
197 static bool find_excl (struct stab_handle
*, const char *, bfd_vma
);
198 static bool stab_record_variable
199 (void *, struct stab_handle
*, const char *, debug_type
,
200 enum debug_var_kind
, bfd_vma
);
201 static bool stab_emit_pending_vars (void *, struct stab_handle
*);
202 static debug_type
*stab_find_slot (struct stab_handle
*, const int *);
203 static debug_type
stab_find_type (void *, struct stab_handle
*, const int *);
204 static bool stab_record_type
205 (void *, struct stab_handle
*, const int *, debug_type
);
206 static debug_type stab_xcoff_builtin_type
207 (void *, struct stab_handle
*, unsigned int);
208 static debug_type stab_find_tagged_type
209 (void *, struct stab_handle
*, const char *, int, enum debug_type_kind
);
210 static debug_type
*stab_demangle_argtypes
211 (void *, struct stab_handle
*, const char *, bool *, unsigned int);
212 static debug_type
*stab_demangle_v3_argtypes
213 (void *, struct stab_handle
*, const char *, bool *);
214 static debug_type
*stab_demangle_v3_arglist
215 (void *, struct stab_handle
*, struct demangle_component
*, bool *);
216 static debug_type stab_demangle_v3_arg
217 (void *, struct stab_handle
*, struct demangle_component
*, debug_type
,
220 static int demangle_flags
= DMGL_ANSI
;
222 /* Save a string in memory. */
225 savestring (const char *start
, int len
)
229 ret
= (char *) xmalloc (len
+ 1);
230 memcpy (ret
, start
, len
);
235 /* Read a number from a string. */
238 parse_number (const char **pp
, bool *poverflow
, const char *p_end
)
243 if (poverflow
!= NULL
)
250 /* Stop early if we are passed an empty string. */
255 ul
= strtoul (*pp
, (char **) pp
, 0);
256 if (ul
+ 1 != 0 || errno
== 0)
258 /* If bfd_vma is larger than unsigned long, and the number is
259 meant to be negative, we have to make sure that we sign
262 return (bfd_vma
) (bfd_signed_vma
) (long) ul
;
266 /* Note that even though strtoul overflowed, it should have set *pp
267 to the end of the number, which is where we want it. */
268 if (sizeof (bfd_vma
) > sizeof (unsigned long))
273 bfd_vma over
, lastdig
;
277 /* Our own version of strtoul, for a bfd_vma. */
292 if (p
[1] == 'x' || p
[1] == 'X')
304 over
= ((bfd_vma
) (bfd_signed_vma
) -1) / (bfd_vma
) base
;
305 lastdig
= ((bfd_vma
) (bfd_signed_vma
) -1) % (bfd_vma
) base
;
316 else if (ISUPPER (d
))
318 else if (ISLOWER (d
))
326 if (v
> over
|| (v
== over
&& (bfd_vma
) d
> lastdig
))
341 /* If we get here, the number is too large to represent in a
343 if (poverflow
!= NULL
)
346 warn_stab (orig
, _("numeric overflow"));
351 /* Give an error for a bad stab string. */
354 bad_stab (const char *p
)
356 fprintf (stderr
, _("Bad stab: %s\n"), p
);
359 /* Warn about something in a stab string. */
362 warn_stab (const char *p
, const char *err
)
364 fprintf (stderr
, _("Warning: %s: %s\n"), err
, p
);
367 /* Create a handle to parse stabs symbols with. */
370 start_stab (void *dhandle ATTRIBUTE_UNUSED
, bfd
*abfd
, bool sections
,
371 asymbol
**syms
, long symcount
)
373 struct stab_handle
*ret
;
375 ret
= (struct stab_handle
*) xmalloc (sizeof *ret
);
376 memset (ret
, 0, sizeof *ret
);
378 ret
->sections
= sections
;
380 ret
->symcount
= symcount
;
382 ret
->file_types
= (struct stab_types
**) xmalloc (sizeof *ret
->file_types
);
383 ret
->file_types
[0] = NULL
;
384 ret
->function_end
= (bfd_vma
) -1;
388 /* When we have processed all the stabs information, we need to go
389 through and fill in all the undefined tags. */
392 finish_stab (void *dhandle
, void *handle
)
394 struct stab_handle
*info
= (struct stab_handle
*) handle
;
397 if (info
->within_function
)
399 if (! stab_emit_pending_vars (dhandle
, info
)
400 || ! debug_end_function (dhandle
, info
->function_end
))
402 info
->within_function
= false;
403 info
->function_end
= (bfd_vma
) -1;
406 for (st
= info
->tags
; st
!= NULL
; st
= st
->next
)
408 enum debug_type_kind kind
;
411 if (kind
== DEBUG_KIND_ILLEGAL
)
412 kind
= DEBUG_KIND_STRUCT
;
413 st
->slot
= debug_make_undefined_tagged_type (dhandle
, st
->name
, kind
);
414 if (st
->slot
== DEBUG_TYPE_NULL
)
421 /* Handle a single stabs symbol. */
424 parse_stab (void *dhandle
, void *handle
, int type
, int desc
, bfd_vma value
,
427 const char * string_end
;
428 struct stab_handle
*info
= (struct stab_handle
*) handle
;
430 /* gcc will emit two N_SO strings per compilation unit, one for the
431 directory name and one for the file name. We just collect N_SO
432 strings as we see them, and start the new compilation unit when
433 we see a non N_SO symbol. */
434 if (info
->so_string
!= NULL
435 && (type
!= N_SO
|| *string
== '\0' || value
!= info
->so_value
))
437 if (! debug_set_filename (dhandle
, info
->so_string
))
439 info
->main_filename
= info
->so_string
;
441 info
->gcc_compiled
= 0;
442 info
->n_opt_found
= false;
444 /* Generally, for stabs in the symbol table, the N_LBRAC and
445 N_RBRAC symbols are relative to the N_SO symbol value. */
446 if (! info
->sections
)
447 info
->file_start_offset
= info
->so_value
;
449 /* We need to reset the mapping from type numbers to types. We
450 can't free the old mapping, because of the use of
451 debug_make_indirect_type. */
453 info
->file_types
= ((struct stab_types
**)
454 xmalloc (sizeof *info
->file_types
));
455 info
->file_types
[0] = NULL
;
456 info
->so_string
= NULL
;
458 /* Now process whatever type we just got. */
461 string_end
= string
+ strlen (string
);
470 /* Ignore extra outermost context from SunPRO cc and acc. */
471 if (info
->n_opt_found
&& desc
== 1)
474 if (! info
->within_function
)
476 fprintf (stderr
, _("N_LBRAC not within function\n"));
480 /* Start an inner lexical block. */
481 if (! debug_start_block (dhandle
,
483 + info
->file_start_offset
484 + info
->function_start_offset
)))
487 /* Emit any pending variable definitions. */
488 if (! stab_emit_pending_vars (dhandle
, info
))
495 /* Ignore extra outermost context from SunPRO cc and acc. */
496 if (info
->n_opt_found
&& desc
== 1)
499 /* We shouldn't have any pending variable definitions here, but,
500 if we do, we probably need to emit them before closing the
502 if (! stab_emit_pending_vars (dhandle
, info
))
505 /* End an inner lexical block. */
506 if (! debug_end_block (dhandle
,
508 + info
->file_start_offset
509 + info
->function_start_offset
)))
513 if (info
->block_depth
< 0)
515 fprintf (stderr
, _("Too many N_RBRACs\n"));
521 /* This always ends a function. */
522 if (info
->within_function
)
528 && info
->function_end
!= (bfd_vma
) -1
529 && info
->function_end
< endval
)
530 endval
= info
->function_end
;
531 if (! stab_emit_pending_vars (dhandle
, info
)
532 || ! debug_end_function (dhandle
, endval
))
534 info
->within_function
= false;
535 info
->function_end
= (bfd_vma
) -1;
538 /* An empty string is emitted by gcc at the end of a compilation
543 /* Just accumulate strings until we see a non N_SO symbol. If
544 the string starts with a directory separator or some other
545 form of absolute path specification, we discard the previously
546 accumulated strings. */
547 if (info
->so_string
== NULL
)
548 info
->so_string
= xstrdup (string
);
555 if (IS_ABSOLUTE_PATH (string
))
556 info
->so_string
= xstrdup (string
);
558 info
->so_string
= concat (info
->so_string
, string
,
559 (const char *) NULL
);
563 info
->so_value
= value
;
568 /* Start an include file. */
569 if (! debug_start_source (dhandle
, string
))
574 /* Start an include file which may be replaced. */
575 push_bincl (info
, string
, value
);
576 if (! debug_start_source (dhandle
, string
))
581 /* End an N_BINCL include. */
582 if (! debug_start_source (dhandle
, pop_bincl (info
)))
587 /* This is a duplicate of a header file named by N_BINCL which
588 was eliminated by the linker. */
589 if (! find_excl (info
, string
, value
))
594 if (! debug_record_line (dhandle
, desc
,
595 value
+ (info
->within_function
596 ? info
->function_start_offset
: 0)))
601 if (! debug_start_common_block (dhandle
, string
))
606 if (! debug_end_common_block (dhandle
, string
))
613 if (info
->within_function
)
615 /* This always marks the end of a function; we don't
616 need to worry about info->function_end. */
618 value
+= info
->function_start_offset
;
619 if (! stab_emit_pending_vars (dhandle
, info
)
620 || ! debug_end_function (dhandle
, value
))
622 info
->within_function
= false;
623 info
->function_end
= (bfd_vma
) -1;
628 /* A const static symbol in the .text section will have an N_FUN
629 entry. We need to use these to mark the end of the function,
630 in case we are looking at gcc output before it was changed to
631 always emit an empty N_FUN. We can't call debug_end_function
632 here, because it might be a local static symbol. */
633 if (info
->within_function
634 && (info
->function_end
== (bfd_vma
) -1
635 || value
< info
->function_end
))
636 info
->function_end
= value
;
639 /* FIXME: gdb checks the string for N_STSYM, N_LCSYM or N_ROSYM
640 symbols, and if it does not start with :S, gdb relocates the
641 value to the start of the section. gcc always seems to use
642 :S, so we don't worry about this. */
648 colon
= strchr (string
, ':');
650 && (colon
[1] == 'f' || colon
[1] == 'F'))
652 if (info
->within_function
)
657 if (info
->function_end
!= (bfd_vma
) -1
658 && info
->function_end
< endval
)
659 endval
= info
->function_end
;
660 if (! stab_emit_pending_vars (dhandle
, info
)
661 || ! debug_end_function (dhandle
, endval
))
663 info
->function_end
= (bfd_vma
) -1;
665 /* For stabs in sections, line numbers and block addresses
666 are offsets from the start of the function. */
668 info
->function_start_offset
= value
;
669 info
->within_function
= true;
672 if (! parse_stab_string (dhandle
, info
, type
, desc
, value
, string
, string_end
))
678 if (string
!= NULL
&& strcmp (string
, "gcc2_compiled.") == 0)
679 info
->gcc_compiled
= 2;
680 else if (string
!= NULL
&& strcmp (string
, "gcc_compiled.") == 0)
681 info
->gcc_compiled
= 1;
683 info
->n_opt_found
= true;
696 /* Parse the stabs string. */
699 parse_stab_string (void *dhandle
, struct stab_handle
*info
, int stabtype
,
700 int desc ATTRIBUTE_UNUSED
, bfd_vma value
,
701 const char *string
, const char * string_end
)
711 p
= strchr (string
, ':');
726 /* FIXME: Sometimes the special C++ names start with '.'. */
728 if (string
[0] == '$')
736 /* Was: name = "vptr"; */
742 /* This was an anonymous type that was never fixed up. */
745 /* SunPRO (3.0 at least) static variable encoding. */
748 warn_stab (string
, _("unknown C++ encoded name"));
755 if (p
== string
|| (string
[0] == ' ' && p
== string
+ 1))
758 name
= savestring (string
, p
- string
);
762 if (ISDIGIT (*p
) || *p
== '(' || *p
== '-')
775 /* c is a special case, not followed by a type-number.
776 SYMBOL:c=iVALUE for an integer constant symbol.
777 SYMBOL:c=rVALUE for a floating constant symbol.
778 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
779 e.g. "b:c=e6,0" for "const b = blob1"
780 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
790 /* Floating point constant. */
791 if (! debug_record_float_const (dhandle
, name
, atof (p
)))
795 /* Integer constant. */
796 /* Defining integer constants this way is kind of silly,
797 since 'e' constants allows the compiler to give not only
798 the value, but the type as well. C has at least int,
799 long, unsigned int, and long long as constant types;
800 other languages probably should have at least unsigned as
801 well as signed constants. */
802 if (! debug_record_int_const (dhandle
, name
, atoi (p
)))
806 /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value
807 can be represented as integral.
808 e.g. "b:c=e6,0" for "const b = blob1"
809 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
810 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
,
811 &p
, (debug_type
**) NULL
, string_end
);
812 if (dtype
== DEBUG_TYPE_NULL
)
819 if (! debug_record_typed_const (dhandle
, name
, dtype
, atoi (p
)))
830 /* The name of a caught exception. */
831 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
,
832 &p
, (debug_type
**) NULL
, string_end
);
833 if (dtype
== DEBUG_TYPE_NULL
)
835 if (! debug_record_label (dhandle
, name
, dtype
, value
))
841 /* A function definition. */
842 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
843 (debug_type
**) NULL
, string_end
);
844 if (dtype
== DEBUG_TYPE_NULL
)
846 if (! debug_record_function (dhandle
, name
, dtype
, type
== 'F', value
))
849 /* Sun acc puts declared types of arguments here. We don't care
850 about their actual types (FIXME -- we should remember the whole
851 function prototype), but the list may define some new types
852 that we have to remember, so we must scan it now. */
856 if (parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
857 (debug_type
**) NULL
, string_end
)
868 /* A global symbol. The value must be extracted from the
870 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
871 (debug_type
**) NULL
, string_end
);
872 if (dtype
== DEBUG_TYPE_NULL
)
879 leading
= bfd_get_symbol_leading_char (info
->abfd
);
880 for (c
= info
->symcount
, ps
= info
->syms
; c
> 0; --c
, ++ps
)
884 n
= bfd_asymbol_name (*ps
);
885 if (leading
!= '\0' && *n
== leading
)
887 if (*n
== *name
&& strcmp (n
, name
) == 0)
892 value
= bfd_asymbol_value (*ps
);
895 if (! stab_record_variable (dhandle
, info
, name
, dtype
, DEBUG_GLOBAL
,
901 /* This case is faked by a conditional above, when there is no
902 code letter in the dbx data. Dbx data never actually
906 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
907 (debug_type
**) NULL
, string_end
);
908 if (dtype
== DEBUG_TYPE_NULL
)
910 if (! stab_record_variable (dhandle
, info
, name
, dtype
, DEBUG_LOCAL
,
916 /* A function parameter. */
918 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
919 (debug_type
**) NULL
, string_end
);
922 /* pF is a two-letter code that means a function parameter in
923 Fortran. The type-number specifies the type of the return
924 value. Translate it into a pointer-to-function type. */
926 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
927 (debug_type
**) NULL
, string_end
);
928 if (dtype
!= DEBUG_TYPE_NULL
)
932 ftype
= debug_make_function_type (dhandle
, dtype
,
933 (debug_type
*) NULL
, false);
934 dtype
= debug_make_pointer_type (dhandle
, ftype
);
937 if (dtype
== DEBUG_TYPE_NULL
)
939 if (! debug_record_parameter (dhandle
, name
, dtype
, DEBUG_PARM_STACK
,
943 /* FIXME: At this point gdb considers rearranging the parameter
944 address on a big endian machine if it is smaller than an int.
945 We have no way to do that, since we don't really know much
950 if (stabtype
== N_FUN
)
952 /* Prototype of a function referenced by this file. */
956 if (parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
957 (debug_type
**) NULL
, string_end
)
965 /* Parameter which is in a register. */
966 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
967 (debug_type
**) NULL
, string_end
);
968 if (dtype
== DEBUG_TYPE_NULL
)
970 if (! debug_record_parameter (dhandle
, name
, dtype
, DEBUG_PARM_REG
,
976 /* Register variable (either global or local). */
977 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
978 (debug_type
**) NULL
, string_end
);
979 if (dtype
== DEBUG_TYPE_NULL
)
981 if (! stab_record_variable (dhandle
, info
, name
, dtype
, DEBUG_REGISTER
,
985 /* FIXME: At this point gdb checks to combine pairs of 'p' and
986 'r' stabs into a single 'P' stab. */
990 /* Static symbol at top level of file. */
991 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
992 (debug_type
**) NULL
, string_end
);
993 if (dtype
== DEBUG_TYPE_NULL
)
995 if (! stab_record_variable (dhandle
, info
, name
, dtype
, DEBUG_STATIC
,
1002 dtype
= parse_stab_type (dhandle
, info
, name
, &p
, &slot
, string_end
);
1003 if (dtype
== DEBUG_TYPE_NULL
)
1007 /* A nameless type. Nothing to do. */
1011 dtype
= debug_name_type (dhandle
, name
, dtype
);
1012 if (dtype
== DEBUG_TYPE_NULL
)
1021 /* Struct, union, or enum tag. For GNU C++, this can be followed
1022 by 't' which means we are typedef'ing it as well. */
1026 /* FIXME: gdb sets synonym to TRUE if the current language
1035 dtype
= parse_stab_type (dhandle
, info
, name
, &p
, &slot
, string_end
);
1036 if (dtype
== DEBUG_TYPE_NULL
)
1041 /* INFO->SELF_CROSSREF is set by parse_stab_type if this type is
1042 a cross reference to itself. These are generated by some
1044 self_crossref
= info
->self_crossref
;
1046 dtype
= debug_tag_type (dhandle
, name
, dtype
);
1047 if (dtype
== DEBUG_TYPE_NULL
)
1052 /* See if we have a cross reference to this tag which we can now
1053 fill in. Avoid filling in a cross reference to ourselves,
1054 because that would lead to circular debugging information. */
1055 if (! self_crossref
)
1057 register struct stab_tag
**pst
;
1059 for (pst
= &info
->tags
; *pst
!= NULL
; pst
= &(*pst
)->next
)
1061 if ((*pst
)->name
[0] == name
[0]
1062 && strcmp ((*pst
)->name
, name
) == 0)
1064 (*pst
)->slot
= dtype
;
1065 *pst
= (*pst
)->next
;
1073 dtype
= debug_name_type (dhandle
, name
, dtype
);
1074 if (dtype
== DEBUG_TYPE_NULL
)
1084 /* Static symbol of local scope */
1085 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
1086 (debug_type
**) NULL
, string_end
);
1087 if (dtype
== DEBUG_TYPE_NULL
)
1089 /* FIXME: gdb checks os9k_stabs here. */
1090 if (! stab_record_variable (dhandle
, info
, name
, dtype
,
1091 DEBUG_LOCAL_STATIC
, value
))
1096 /* Reference parameter. */
1097 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
1098 (debug_type
**) NULL
, string_end
);
1099 if (dtype
== DEBUG_TYPE_NULL
)
1101 if (! debug_record_parameter (dhandle
, name
, dtype
, DEBUG_PARM_REFERENCE
,
1107 /* Reference parameter which is in a register. */
1108 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
1109 (debug_type
**) NULL
, string_end
);
1110 if (dtype
== DEBUG_TYPE_NULL
)
1112 if (! debug_record_parameter (dhandle
, name
, dtype
, DEBUG_PARM_REF_REG
,
1118 /* This is used by Sun FORTRAN for "function result value".
1119 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
1120 that Pascal uses it too, but when I tried it Pascal used
1121 "x:3" (local symbol) instead. */
1122 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
1123 (debug_type
**) NULL
, string_end
);
1124 if (dtype
== DEBUG_TYPE_NULL
)
1126 if (! stab_record_variable (dhandle
, info
, name
, dtype
, DEBUG_LOCAL
,
1132 /* SUNPro C++ Namespace =Yn0. */
1133 /* Skip the namespace mapping, as it is not used now. */
1134 if (*p
++ != 0 && *p
++ == 'n' && *p
++ == '0')
1137 while (*p
&& *p
!= ';')
1142 /* TODO SUNPro C++ support:
1143 Support default arguments after F,P parameters
1144 Ya = Anonymous unions
1145 YM,YD = Pointers to class members
1147 YR = Run-time type information (RTTI) */
1156 /* FIXME: gdb converts structure values to structure pointers in a
1157 couple of cases, depending upon the target. */
1162 /* Parse a stabs type. The typename argument is non-NULL if this is a
1163 typedef or a tag definition. The pp argument points to the stab
1164 string, and is updated. The slotp argument points to a place to
1165 store the slot used if the type is being defined. */
1168 parse_stab_type (void * dhandle
,
1169 struct stab_handle
* info
,
1170 const char * type_name
,
1172 debug_type
** slotp
,
1187 return DEBUG_TYPE_NULL
;
1192 info
->self_crossref
= false;
1194 /* Read type number if present. The type number may be omitted.
1195 for instance in a two-dimensional array declared with type
1196 "ar1;1;10;ar1;1;10;4". */
1197 if (! ISDIGIT (**pp
) && **pp
!= '(' && **pp
!= '-')
1199 /* 'typenums=' not present, type is anonymous. Read and return
1200 the definition, but don't put it in the type vector. */
1201 typenums
[0] = typenums
[1] = -1;
1205 if (! parse_stab_type_number (pp
, typenums
, p_end
))
1206 return DEBUG_TYPE_NULL
;
1209 /* Type is not being defined here. Either it already
1210 exists, or this is a forward reference to it. */
1211 return stab_find_type (dhandle
, info
, typenums
);
1213 /* Only set the slot if the type is being defined. This means
1214 that the mapping from type numbers to types will only record
1215 the name of the typedef which defines a type. If we don't do
1216 this, then something like
1219 will record that i is of type foo. Unfortunately, stabs
1220 information is ambiguous about variable types. For this code,
1224 the stabs information records both i and j as having the same
1225 type. This could be fixed by patching the compiler. */
1226 if (slotp
!= NULL
&& typenums
[0] >= 0 && typenums
[1] >= 0)
1227 *slotp
= stab_find_slot (info
, typenums
);
1229 /* Type is being defined here. */
1235 const char *p
= *pp
+ 1;
1238 if (ISDIGIT (*p
) || *p
== '(' || *p
== '-')
1242 /* Type attributes. */
1245 for (; *p
!= ';'; ++p
)
1250 return DEBUG_TYPE_NULL
;
1258 size
= atoi (attr
+ 1);
1259 size
/= 8; /* Size is in bits. We store it in bytes. */
1270 return DEBUG_TYPE_NULL
;
1273 /* Ignore unrecognized type attributes, so future
1274 compilers can invent new ones. */
1287 enum debug_type_kind code
;
1288 const char *q1
, *q2
, *p
;
1290 /* A cross reference to another type. */
1294 code
= DEBUG_KIND_STRUCT
;
1297 code
= DEBUG_KIND_UNION
;
1300 code
= DEBUG_KIND_ENUM
;
1304 return DEBUG_TYPE_NULL
;
1307 /* Complain and keep going, so compilers can invent new
1308 cross-reference types. */
1309 warn_stab (orig
, _("unrecognized cross reference type"));
1310 code
= DEBUG_KIND_STRUCT
;
1315 q1
= strchr (*pp
, '<');
1316 p
= strchr (*pp
, ':');
1320 return DEBUG_TYPE_NULL
;
1322 if (q1
!= NULL
&& p
> q1
&& p
[1] == ':')
1326 for (q2
= q1
; *q2
!= '\0'; ++q2
)
1330 else if (*q2
== '>')
1332 else if (*q2
== ':' && nest
== 0)
1339 return DEBUG_TYPE_NULL
;
1343 /* Some versions of g++ can emit stabs like
1345 which define structures in terms of themselves. We need to
1346 tell the caller to avoid building a circular structure. */
1347 if (type_name
!= NULL
1348 && strncmp (type_name
, *pp
, p
- *pp
) == 0
1349 && type_name
[p
- *pp
] == '\0')
1350 info
->self_crossref
= true;
1352 dtype
= stab_find_tagged_type (dhandle
, info
, *pp
, p
- *pp
, code
);
1374 /* This type is defined as another type. */
1378 /* Peek ahead at the number to detect void. */
1379 if (! parse_stab_type_number (pp
, xtypenums
, p_end
))
1380 return DEBUG_TYPE_NULL
;
1382 if (typenums
[0] == xtypenums
[0] && typenums
[1] == xtypenums
[1])
1384 /* This type is being defined as itself, which means that
1386 dtype
= debug_make_void_type (dhandle
);
1392 /* Go back to the number and have parse_stab_type get it.
1393 This means that we can deal with something like
1394 t(1,2)=(3,4)=... which the Lucid compiler uses. */
1395 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
,
1396 pp
, (debug_type
**) NULL
, p_end
);
1397 if (dtype
== DEBUG_TYPE_NULL
)
1398 return DEBUG_TYPE_NULL
;
1401 if (typenums
[0] != -1)
1403 if (! stab_record_type (dhandle
, info
, typenums
, dtype
))
1404 return DEBUG_TYPE_NULL
;
1411 dtype
= debug_make_pointer_type (dhandle
,
1412 parse_stab_type (dhandle
, info
,
1413 (const char *) NULL
,
1415 (debug_type
**) NULL
,
1420 /* Reference to another type. */
1421 dtype
= (debug_make_reference_type
1423 parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
1424 (debug_type
**) NULL
, p_end
)));
1428 /* Function returning another type. */
1429 /* FIXME: gdb checks os9k_stabs here. */
1430 dtype
= (debug_make_function_type
1432 parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
1433 (debug_type
**) NULL
, p_end
),
1434 (debug_type
*) NULL
, false));
1438 /* Const qualifier on some type (Sun). */
1439 /* FIXME: gdb accepts 'c' here if os9k_stabs. */
1440 dtype
= debug_make_const_type (dhandle
,
1441 parse_stab_type (dhandle
, info
,
1442 (const char *) NULL
,
1444 (debug_type
**) NULL
,
1449 /* Volatile qual on some type (Sun). */
1450 /* FIXME: gdb accepts 'i' here if os9k_stabs. */
1451 dtype
= (debug_make_volatile_type
1453 parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
1454 (debug_type
**) NULL
, p_end
)));
1458 /* Offset (class & variable) type. This is used for a pointer
1459 relative to an object. */
1466 domain
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
1467 (debug_type
**) NULL
, p_end
);
1468 if (domain
== DEBUG_TYPE_NULL
)
1469 return DEBUG_TYPE_NULL
;
1474 return DEBUG_TYPE_NULL
;
1478 memtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
1479 (debug_type
**) NULL
, p_end
);
1480 if (memtype
== DEBUG_TYPE_NULL
)
1481 return DEBUG_TYPE_NULL
;
1483 dtype
= debug_make_offset_type (dhandle
, domain
, memtype
);
1488 /* Method (class & fn) type. */
1491 debug_type return_type
;
1494 return_type
= parse_stab_type (dhandle
, info
, (const char *) NULL
,
1495 pp
, (debug_type
**) NULL
, p_end
);
1496 if (return_type
== DEBUG_TYPE_NULL
)
1497 return DEBUG_TYPE_NULL
;
1501 return DEBUG_TYPE_NULL
;
1504 dtype
= debug_make_method_type (dhandle
, return_type
,
1506 (debug_type
*) NULL
, false);
1511 debug_type return_type
;
1517 domain
= parse_stab_type (dhandle
, info
, (const char *) NULL
,
1518 pp
, (debug_type
**) NULL
, p_end
);
1519 if (domain
== DEBUG_TYPE_NULL
)
1520 return DEBUG_TYPE_NULL
;
1525 return DEBUG_TYPE_NULL
;
1529 return_type
= parse_stab_type (dhandle
, info
, (const char *) NULL
,
1530 pp
, (debug_type
**) NULL
, p_end
);
1531 if (return_type
== DEBUG_TYPE_NULL
)
1532 return DEBUG_TYPE_NULL
;
1535 args
= (debug_type
*) xmalloc (alloc
* sizeof *args
);
1542 return DEBUG_TYPE_NULL
;
1549 args
= ((debug_type
*)
1550 xrealloc (args
, alloc
* sizeof *args
));
1553 args
[n
] = parse_stab_type (dhandle
, info
, (const char *) NULL
,
1554 pp
, (debug_type
**) NULL
, p_end
);
1555 if (args
[n
] == DEBUG_TYPE_NULL
)
1556 return DEBUG_TYPE_NULL
;
1561 /* If the last type is not void, then this function takes a
1562 variable number of arguments. Otherwise, we must strip
1565 || debug_get_type_kind (dhandle
, args
[n
- 1]) != DEBUG_KIND_VOID
)
1573 args
[n
] = DEBUG_TYPE_NULL
;
1575 dtype
= debug_make_method_type (dhandle
, return_type
, domain
, args
,
1582 dtype
= parse_stab_range_type (dhandle
, info
, type_name
, pp
, typenums
, p_end
);
1586 /* FIXME: gdb checks os9k_stabs here. */
1587 /* Sun ACC builtin int type. */
1588 dtype
= parse_stab_sun_builtin_type (dhandle
, pp
, p_end
);
1592 /* Sun ACC builtin float type. */
1593 dtype
= parse_stab_sun_floating_type (dhandle
, pp
, p_end
);
1597 /* Enumeration type. */
1598 dtype
= parse_stab_enum_type (dhandle
, pp
, p_end
);
1603 /* Struct or union type. */
1604 dtype
= parse_stab_struct_type (dhandle
, info
, type_name
, pp
,
1605 descriptor
== 's', typenums
, p_end
);
1613 return DEBUG_TYPE_NULL
;
1617 dtype
= parse_stab_array_type (dhandle
, info
, pp
, stringp
, p_end
);
1621 dtype
= debug_make_set_type (dhandle
,
1622 parse_stab_type (dhandle
, info
,
1623 (const char *) NULL
,
1625 (debug_type
**) NULL
,
1632 return DEBUG_TYPE_NULL
;
1635 if (dtype
== DEBUG_TYPE_NULL
)
1636 return DEBUG_TYPE_NULL
;
1638 if (typenums
[0] != -1)
1640 if (! stab_record_type (dhandle
, info
, typenums
, dtype
))
1641 return DEBUG_TYPE_NULL
;
1646 if (! debug_record_type_size (dhandle
, dtype
, (unsigned int) size
))
1647 return DEBUG_TYPE_NULL
;
1653 /* Read a number by which a type is referred to in dbx data, or
1654 perhaps read a pair (FILENUM, TYPENUM) in parentheses. Just a
1655 single number N is equivalent to (0,N). Return the two numbers by
1656 storing them in the vector TYPENUMS. */
1659 parse_stab_type_number (const char **pp
, int *typenums
, const char *p_end
)
1668 typenums
[1] = (int) parse_number (pp
, (bool *) NULL
, p_end
);
1673 typenums
[0] = (int) parse_number (pp
, (bool *) NULL
, p_end
);
1681 typenums
[1] = (int) parse_number (pp
, (bool *) NULL
, p_end
);
1692 /* Parse a range type. */
1695 parse_stab_range_type (void * dhandle
,
1696 struct stab_handle
* info
,
1697 const char * type_name
,
1699 const int * typenums
,
1705 debug_type index_type
;
1706 const char *s2
, *s3
;
1707 bfd_signed_vma n2
, n3
;
1712 return DEBUG_TYPE_NULL
;
1714 index_type
= DEBUG_TYPE_NULL
;
1716 /* First comes a type we are a subrange of.
1717 In C it is usually 0, 1 or the type being defined. */
1718 if (! parse_stab_type_number (pp
, rangenums
, p_end
))
1719 return DEBUG_TYPE_NULL
;
1721 self_subrange
= (rangenums
[0] == typenums
[0]
1722 && rangenums
[1] == typenums
[1]);
1727 index_type
= parse_stab_type (dhandle
, info
, (const char *) NULL
,
1728 pp
, (debug_type
**) NULL
, p_end
);
1729 if (index_type
== DEBUG_TYPE_NULL
)
1730 return DEBUG_TYPE_NULL
;
1736 /* The remaining two operands are usually lower and upper bounds of
1737 the range. But in some special cases they mean something else. */
1739 n2
= parse_number (pp
, &ov2
, p_end
);
1743 return DEBUG_TYPE_NULL
;
1748 n3
= parse_number (pp
, &ov3
, p_end
);
1752 return DEBUG_TYPE_NULL
;
1758 /* gcc will emit range stabs for long long types. Handle this
1759 as a special case. FIXME: This needs to be more general. */
1760 #define LLLOW "01000000000000000000000;"
1761 #define LLHIGH "0777777777777777777777;"
1762 #define ULLHIGH "01777777777777777777777;"
1763 if (index_type
== DEBUG_TYPE_NULL
)
1765 if (startswith (s2
, LLLOW
)
1766 && startswith (s3
, LLHIGH
))
1767 return debug_make_int_type (dhandle
, 8, false);
1770 && startswith (s3
, ULLHIGH
))
1771 return debug_make_int_type (dhandle
, 8, true);
1774 warn_stab (orig
, _("numeric overflow"));
1777 if (index_type
== DEBUG_TYPE_NULL
)
1779 /* A type defined as a subrange of itself, with both bounds 0,
1781 if (self_subrange
&& n2
== 0 && n3
== 0)
1782 return debug_make_void_type (dhandle
);
1784 /* A type defined as a subrange of itself, with n2 positive and
1785 n3 zero, is a complex type, and n2 is the number of bytes. */
1786 if (self_subrange
&& n3
== 0 && n2
> 0)
1787 return debug_make_complex_type (dhandle
, n2
);
1789 /* If n3 is zero and n2 is positive, this is a floating point
1790 type, and n2 is the number of bytes. */
1791 if (n3
== 0 && n2
> 0)
1792 return debug_make_float_type (dhandle
, n2
);
1794 /* If the upper bound is -1, this is an unsigned int. */
1795 if (n2
== 0 && n3
== -1)
1797 /* When gcc is used with -gstabs, but not -gstabs+, it will emit
1798 long long int:t6=r1;0;-1;
1799 long long unsigned int:t7=r1;0;-1;
1800 We hack here to handle this reasonably. */
1801 if (type_name
!= NULL
)
1803 if (strcmp (type_name
, "long long int") == 0)
1804 return debug_make_int_type (dhandle
, 8, false);
1805 else if (strcmp (type_name
, "long long unsigned int") == 0)
1806 return debug_make_int_type (dhandle
, 8, true);
1808 /* FIXME: The size here really depends upon the target. */
1809 return debug_make_int_type (dhandle
, 4, true);
1812 /* A range of 0 to 127 is char. */
1813 if (self_subrange
&& n2
== 0 && n3
== 127)
1814 return debug_make_int_type (dhandle
, 1, false);
1816 /* FIXME: gdb checks for the language CHILL here. */
1821 return debug_make_int_type (dhandle
, - n3
, true);
1822 else if (n3
== 0xff)
1823 return debug_make_int_type (dhandle
, 1, true);
1824 else if (n3
== 0xffff)
1825 return debug_make_int_type (dhandle
, 2, true);
1826 else if (n3
== (bfd_signed_vma
) 0xffffffff)
1827 return debug_make_int_type (dhandle
, 4, true);
1829 else if (n3
== (bfd_signed_vma
) 0xffffffffffffffffLL
)
1830 return debug_make_int_type (dhandle
, 8, true);
1835 && (self_subrange
|| n2
== -8))
1836 return debug_make_int_type (dhandle
, - n2
, true);
1837 else if (n2
== - n3
- 1 || n2
== n3
+ 1)
1840 return debug_make_int_type (dhandle
, 1, false);
1841 else if (n3
== 0x7fff)
1842 return debug_make_int_type (dhandle
, 2, false);
1843 else if (n3
== 0x7fffffff)
1844 return debug_make_int_type (dhandle
, 4, false);
1846 else if (n3
== ((((bfd_vma
) 0x7fffffff) << 32) | 0xffffffff))
1847 return debug_make_int_type (dhandle
, 8, false);
1852 /* At this point I don't have the faintest idea how to deal with a
1853 self_subrange type; I'm going to assume that this is used as an
1854 idiom, and that all of them are special cases. So . . . */
1858 return DEBUG_TYPE_NULL
;
1861 index_type
= stab_find_type (dhandle
, info
, rangenums
);
1862 if (index_type
== DEBUG_TYPE_NULL
)
1864 /* Does this actually ever happen? Is that why we are worrying
1865 about dealing with it rather than just calling error_type? */
1866 warn_stab (orig
, _("missing index type"));
1867 index_type
= debug_make_int_type (dhandle
, 4, false);
1870 return debug_make_range_type (dhandle
, index_type
, n2
, n3
);
1873 /* Sun's ACC uses a somewhat saner method for specifying the builtin
1874 typedefs in every file (for int, long, etc):
1876 type = b <signed> <width>; <offset>; <nbits>
1877 signed = u or s. Possible c in addition to u or s (for char?).
1878 offset = offset from high order bit to start bit of type.
1879 width is # bytes in object of this type, nbits is # bits in type.
1881 The width/offset stuff appears to be for small objects stored in
1882 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
1886 parse_stab_sun_builtin_type (void *dhandle
, const char **pp
, const char * p_end
)
1894 return DEBUG_TYPE_NULL
;
1906 return DEBUG_TYPE_NULL
;
1910 /* OpenSolaris source code indicates that one of "cbv" characters
1911 can come next and specify the intrinsic 'iformat' encoding.
1912 'c' is character encoding, 'b' is boolean encoding, and 'v' is
1913 varargs encoding. This field can be safely ignored because
1914 the type of the field is determined from the bitwidth extracted
1916 if (**pp
== 'c' || **pp
== 'b' || **pp
== 'v')
1919 /* The first number appears to be the number of bytes occupied
1920 by this type, except that unsigned short is 4 instead of 2.
1921 Since this information is redundant with the third number,
1922 we will ignore it. */
1923 (void) parse_number (pp
, (bool *) NULL
, p_end
);
1927 return DEBUG_TYPE_NULL
;
1931 /* The second number is always 0, so ignore it too. */
1932 (void) parse_number (pp
, (bool *) NULL
, p_end
);
1936 return DEBUG_TYPE_NULL
;
1940 /* The third number is the number of bits for this type. */
1941 bits
= parse_number (pp
, (bool *) NULL
, p_end
);
1943 /* The type *should* end with a semicolon. If it are embedded
1944 in a larger type the semicolon may be the only way to know where
1945 the type ends. If this type is at the end of the stabstring we
1946 can deal with the omitted semicolon (but we don't have to like
1947 it). Don't bother to complain(), Sun's compiler omits the semicolon
1953 return debug_make_void_type (dhandle
);
1955 return debug_make_int_type (dhandle
, bits
/ 8, unsignedp
);
1958 /* Parse a builtin floating type generated by the Sun compiler. */
1961 parse_stab_sun_floating_type (void *dhandle
, const char **pp
, const char *p_end
)
1969 return DEBUG_TYPE_NULL
;
1971 /* The first number has more details about the type, for example
1973 details
= parse_number (pp
, (bool *) NULL
, p_end
);
1977 return DEBUG_TYPE_NULL
;
1980 /* The second number is the number of bytes occupied by this type */
1981 bytes
= parse_number (pp
, (bool *) NULL
, p_end
);
1985 return DEBUG_TYPE_NULL
;
1988 if (details
== NF_COMPLEX
1989 || details
== NF_COMPLEX16
1990 || details
== NF_COMPLEX32
)
1991 return debug_make_complex_type (dhandle
, bytes
);
1993 return debug_make_float_type (dhandle
, bytes
);
1996 /* Handle an enum type. */
1999 parse_stab_enum_type (void *dhandle
, const char **pp
, const char * p_end
)
2003 bfd_signed_vma
*values
;
2009 return DEBUG_TYPE_NULL
;
2011 /* FIXME: gdb checks os9k_stabs here. */
2013 /* The aix4 compiler emits an extra field before the enum members;
2014 my guess is it's a type of some sort. Just ignore it. */
2017 while (**pp
!= ':' && **pp
!= 0)
2023 return DEBUG_TYPE_NULL
;
2028 /* Read the value-names and their values.
2029 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
2030 A semicolon or comma instead of a NAME means the end. */
2032 names
= (const char **) xmalloc (alloc
* sizeof *names
);
2033 values
= (bfd_signed_vma
*) xmalloc (alloc
* sizeof *values
);
2035 while (**pp
!= '\0' && **pp
!= ';' && **pp
!= ',')
2042 while (*p
!= ':' && *p
!= 0)
2050 return DEBUG_TYPE_NULL
;
2053 name
= savestring (*pp
, p
- *pp
);
2056 val
= (bfd_signed_vma
) parse_number (pp
, (bool *) NULL
, p_end
);
2063 return DEBUG_TYPE_NULL
;
2070 names
= ((const char **)
2071 xrealloc (names
, alloc
* sizeof *names
));
2072 values
= ((bfd_signed_vma
*)
2073 xrealloc (values
, alloc
* sizeof *values
));
2087 return debug_make_enum_type (dhandle
, names
, values
);
2090 /* Read the description of a structure (or union type) and return an object
2091 describing the type.
2093 PP points to a character pointer that points to the next unconsumed token
2094 in the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
2095 *PP will point to "4a:1,0,32;;". */
2098 parse_stab_struct_type (void *dhandle
,
2099 struct stab_handle
*info
,
2100 const char *tagname
,
2103 const int *typenums
,
2107 debug_baseclass
*baseclasses
;
2108 debug_field
*fields
= NULL
;
2110 debug_method
*methods
;
2111 debug_type vptrbase
;
2115 size
= parse_number (pp
, (bool *) NULL
, p_end
);
2117 /* Get the other information. */
2118 if (! parse_stab_baseclasses (dhandle
, info
, pp
, &baseclasses
, p_end
)
2119 || ! parse_stab_struct_fields (dhandle
, info
, pp
, &fields
, &statics
, p_end
)
2120 || ! parse_stab_members (dhandle
, info
, tagname
, pp
, typenums
, &methods
, p_end
)
2121 || ! parse_stab_tilde_field (dhandle
, info
, pp
, typenums
, &vptrbase
,
2125 return DEBUG_TYPE_NULL
;
2129 && baseclasses
== NULL
2131 && vptrbase
== DEBUG_TYPE_NULL
2133 return debug_make_struct_type (dhandle
, structp
, size
, fields
);
2135 return debug_make_object_type (dhandle
, structp
, size
, fields
, baseclasses
,
2136 methods
, vptrbase
, ownvptr
);
2139 /* The stabs for C++ derived classes contain baseclass information which
2140 is marked by a '!' character after the total size. This function is
2141 called when we encounter the baseclass marker, and slurps up all the
2142 baseclass information.
2144 Immediately following the '!' marker is the number of base classes that
2145 the class is derived from, followed by information for each base class.
2146 For each base class, there are two visibility specifiers, a bit offset
2147 to the base class information within the derived class, a reference to
2148 the type for the base class, and a terminating semicolon.
2150 A typical example, with two base classes, would be "!2,020,19;0264,21;".
2152 Baseclass information marker __________________|| | | | | | |
2153 Number of baseclasses __________________________| | | | | | |
2154 Visibility specifiers (2) ________________________| | | | | |
2155 Offset in bits from start of class _________________| | | | |
2156 Type number for base class ___________________________| | | |
2157 Visibility specifiers (2) _______________________________| | |
2158 Offset in bits from start of class ________________________| |
2159 Type number of base class ____________________________________|
2161 Return TRUE for success, FALSE for failure. */
2164 parse_stab_baseclasses (void * dhandle
,
2165 struct stab_handle
* info
,
2167 debug_baseclass
** retp
,
2172 debug_baseclass
*classes
;
2182 /* No base classes. */
2187 c
= (unsigned int) parse_number (pp
, (bool *) NULL
, p_end
);
2196 classes
= (debug_baseclass
*) xmalloc ((c
+ 1) * sizeof (**retp
));
2198 for (i
= 0; i
< c
; i
++)
2201 enum debug_visibility visibility
;
2217 warn_stab (orig
, _("unknown virtual character for baseclass"));
2226 visibility
= DEBUG_VISIBILITY_PRIVATE
;
2229 visibility
= DEBUG_VISIBILITY_PROTECTED
;
2232 visibility
= DEBUG_VISIBILITY_PUBLIC
;
2238 warn_stab (orig
, _("unknown visibility character for baseclass"));
2239 visibility
= DEBUG_VISIBILITY_PUBLIC
;
2244 /* The remaining value is the bit offset of the portion of the
2245 object corresponding to this baseclass. Always zero in the
2246 absence of multiple inheritance. */
2247 bitpos
= parse_number (pp
, (bool *) NULL
, p_end
);
2255 type
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
2256 (debug_type
**) NULL
, p_end
);
2257 if (type
== DEBUG_TYPE_NULL
)
2260 classes
[i
] = debug_make_baseclass (dhandle
, type
, bitpos
, is_virtual
,
2262 if (classes
[i
] == DEBUG_BASECLASS_NULL
)
2270 classes
[i
] = DEBUG_BASECLASS_NULL
;
2277 /* Read struct or class data fields. They have the form:
2279 NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
2281 At the end, we see a semicolon instead of a field.
2283 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
2286 The optional VISIBILITY is one of:
2288 '/0' (VISIBILITY_PRIVATE)
2289 '/1' (VISIBILITY_PROTECTED)
2290 '/2' (VISIBILITY_PUBLIC)
2291 '/9' (VISIBILITY_IGNORE)
2293 or nothing, for C style fields with public visibility.
2295 Returns 1 for success, 0 for failure. */
2298 parse_stab_struct_fields (void *dhandle
,
2299 struct stab_handle
*info
,
2307 debug_field
*fields
;
2320 fields
= (debug_field
*) xmalloc (alloc
* sizeof *fields
);
2323 /* FIXME: gdb checks os9k_stabs here. */
2327 /* Add 1 to c to leave room for NULL pointer at end. */
2331 fields
= ((debug_field
*)
2332 xrealloc (fields
, alloc
* sizeof *fields
));
2335 /* If it starts with CPLUS_MARKER it is a special abbreviation,
2336 unless the CPLUS_MARKER is followed by an underscore, in
2337 which case it is just the name of an anonymous type, which we
2338 should handle like any other type name. We accept either '$'
2339 or '.', because a field name can never contain one of these
2340 characters except as a CPLUS_MARKER. */
2342 if ((*p
== '$' || *p
== '.') && p
[1] != '_')
2345 if (! parse_stab_cpp_abbrev (dhandle
, info
, pp
, fields
+ c
, p_end
))
2354 /* Look for the ':' that separates the field name from the field
2355 values. Data members are delimited by a single ':', while member
2356 functions are delimited by a pair of ':'s. When we hit the member
2357 functions (if any), terminate scan loop and return. */
2359 p
= strchr (p
, ':');
2370 if (! parse_stab_one_struct_field (dhandle
, info
, pp
, p
, fields
+ c
,
2380 fields
[c
] = DEBUG_FIELD_NULL
;
2387 /* Special GNU C++ name. */
2390 parse_stab_cpp_abbrev (void * dhandle
,
2391 struct stab_handle
* info
,
2400 const char *type_name
;
2404 *retp
= DEBUG_FIELD_NULL
;
2418 if (cpp_abbrev
== 0)
2425 /* At this point, *pp points to something like "22:23=*22...", where
2426 the type number before the ':' is the "context" and everything
2427 after is a regular type definition. Lookup the type, find it's
2428 name, and construct the field name. */
2430 context
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
2431 (debug_type
**) NULL
, p_end
);
2432 if (context
== DEBUG_TYPE_NULL
)
2438 /* $vf -- a virtual function table pointer. */
2442 /* $vb -- a virtual bsomethingorother */
2443 type_name
= debug_get_type_name (dhandle
, context
);
2444 if (type_name
== NULL
)
2446 warn_stab (orig
, _("unnamed $vb type"));
2449 name
= concat ("_vb$", type_name
, (const char *) NULL
);
2452 warn_stab (orig
, _("unrecognized C++ abbreviation"));
2453 name
= "INVALID_CPLUSPLUS_ABBREV";
2464 type
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
2465 (debug_type
**) NULL
, p_end
);
2473 bitpos
= parse_number (pp
, (bool *) NULL
, p_end
);
2481 *retp
= debug_make_field (dhandle
, name
, type
, bitpos
, 0,
2482 DEBUG_VISIBILITY_PRIVATE
);
2483 if (*retp
== DEBUG_FIELD_NULL
)
2489 /* Parse a single field in a struct or union. */
2492 parse_stab_one_struct_field (void *dhandle
,
2493 struct stab_handle
*info
,
2502 enum debug_visibility visibility
;
2511 /* FIXME: gdb checks ARM_DEMANGLING here. */
2513 name
= savestring (*pp
, p
- *pp
);
2518 visibility
= DEBUG_VISIBILITY_PUBLIC
;
2525 visibility
= DEBUG_VISIBILITY_PRIVATE
;
2528 visibility
= DEBUG_VISIBILITY_PROTECTED
;
2531 visibility
= DEBUG_VISIBILITY_PUBLIC
;
2537 warn_stab (orig
, _("unknown visibility character for field"));
2538 visibility
= DEBUG_VISIBILITY_PUBLIC
;
2544 type
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
2545 (debug_type
**) NULL
, p_end
);
2546 if (type
== DEBUG_TYPE_NULL
)
2556 /* This is a static class member. */
2558 p
= strchr (*pp
, ';');
2566 varname
= savestring (*pp
, p
- *pp
);
2570 *retp
= debug_make_static_member (dhandle
, name
, type
, varname
,
2585 bitpos
= parse_number (pp
, (bool *) NULL
, p_end
);
2594 bitsize
= parse_number (pp
, (bool *) NULL
, p_end
);
2603 if (bitpos
== 0 && bitsize
== 0)
2605 /* This can happen in two cases: (1) at least for gcc 2.4.5 or
2606 so, it is a field which has been optimized out. The correct
2607 stab for this case is to use VISIBILITY_IGNORE, but that is a
2608 recent invention. (2) It is a 0-size array. For example
2609 union { int num; char str[0]; } foo. Printing "<no value>"
2610 for str in "p foo" is OK, since foo.str (and thus foo.str[3])
2611 will continue to work, and a 0-size array as a whole doesn't
2612 have any contents to print.
2614 I suspect this probably could also happen with gcc -gstabs
2615 (not -gstabs+) for static fields, and perhaps other C++
2616 extensions. Hopefully few people use -gstabs with gdb, since
2617 it is intended for dbx compatibility. */
2618 visibility
= DEBUG_VISIBILITY_IGNORE
;
2621 /* FIXME: gdb does some stuff here to mark fields as unpacked. */
2623 *retp
= debug_make_field (dhandle
, name
, type
, bitpos
, bitsize
, visibility
);
2628 /* Read member function stabs info for C++ classes. The form of each member
2631 NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
2633 An example with two member functions is:
2635 afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
2637 For the case of overloaded operators, the format is op$::*.funcs, where
2638 $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
2639 name (such as `+=') and `.' marks the end of the operator name. */
2642 parse_stab_members (void * dhandle
,
2643 struct stab_handle
* info
,
2644 const char * tagname
,
2646 const int * typenums
,
2647 debug_method
** retp
,
2651 debug_method
*methods
;
2655 debug_method_variant
*variants
= NULL
;
2656 char *argtypes
= NULL
;
2672 unsigned int allocvars
;
2673 debug_type look_ahead_type
;
2675 p
= strchr (*pp
, ':');
2676 if (p
== NULL
|| p
[1] != ':')
2679 /* FIXME: Some systems use something other than '$' here. */
2680 if ((*pp
)[0] != 'o' || (*pp
)[1] != 'p' || (*pp
)[2] != '$')
2682 name
= savestring (*pp
, p
- *pp
);
2687 /* This is a completely weird case. In order to stuff in the
2688 names that might contain colons (the usual name delimiter),
2689 Mike Tiemann defined a different name format which is
2690 signalled if the identifier is "op$". In that case, the
2691 format is "op$::XXXX." where XXXX is the name. This is
2692 used for names like "+" or "=". YUUUUUUUK! FIXME! */
2694 for (p
= *pp
; *p
!= '.' && *p
!= '\0'; p
++)
2701 name
= savestring (*pp
, p
- *pp
);
2706 variants
= ((debug_method_variant
*)
2707 xmalloc (allocvars
* sizeof *variants
));
2710 look_ahead_type
= DEBUG_TYPE_NULL
;
2716 enum debug_visibility visibility
;
2717 bool constp
, volatilep
, staticp
;
2720 const char *physname
;
2723 if (look_ahead_type
!= DEBUG_TYPE_NULL
)
2725 /* g++ version 1 kludge */
2726 type
= look_ahead_type
;
2727 look_ahead_type
= DEBUG_TYPE_NULL
;
2731 type
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
2732 (debug_type
**) NULL
, p_end
);
2733 if (type
== DEBUG_TYPE_NULL
)
2744 p
= strchr (*pp
, ';');
2752 if (debug_get_type_kind (dhandle
, type
) == DEBUG_KIND_METHOD
2753 && debug_get_parameter_types (dhandle
, type
, &varargs
) == NULL
)
2756 argtypes
= savestring (*pp
, p
- *pp
);
2762 visibility
= DEBUG_VISIBILITY_PRIVATE
;
2765 visibility
= DEBUG_VISIBILITY_PROTECTED
;
2771 visibility
= DEBUG_VISIBILITY_PUBLIC
;
2781 /* Normal function. */
2785 /* const member function. */
2790 /* volatile member function. */
2795 /* const volatile member function. */
2803 /* File compiled with g++ version 1; no information. */
2806 warn_stab (orig
, _("const/volatile indicator missing"));
2814 /* virtual member function, followed by index. The sign
2815 bit is supposedly set to distinguish
2816 pointers-to-methods from virtual function indices. */
2818 voffset
= parse_number (pp
, (bool *) NULL
, p_end
);
2825 voffset
&= 0x7fffffff;
2827 if (**pp
== ';' || **pp
== '\0')
2829 /* Must be g++ version 1. */
2830 context
= DEBUG_TYPE_NULL
;
2834 /* Figure out from whence this virtual function
2835 came. It may belong to virtual function table of
2836 one of its baseclasses. */
2837 look_ahead_type
= parse_stab_type (dhandle
, info
,
2838 (const char *) NULL
,
2840 (debug_type
**) NULL
,
2844 /* g++ version 1 overloaded methods. */
2845 context
= DEBUG_TYPE_NULL
;
2849 context
= look_ahead_type
;
2850 look_ahead_type
= DEBUG_TYPE_NULL
;
2862 /* static member function. */
2866 context
= DEBUG_TYPE_NULL
;
2867 if (strncmp (argtypes
, name
, strlen (name
)) != 0)
2872 warn_stab (orig
, "member function type missing");
2874 context
= DEBUG_TYPE_NULL
;
2880 context
= DEBUG_TYPE_NULL
;
2884 /* If the type is not a stub, then the argtypes string is
2885 the physical name of the function. Otherwise the
2886 argtypes string is the mangled form of the argument
2887 types, and the full type and the physical name must be
2888 extracted from them. */
2889 physname
= argtypes
;
2892 debug_type class_type
, return_type
;
2894 class_type
= stab_find_type (dhandle
, info
, typenums
);
2895 if (class_type
== DEBUG_TYPE_NULL
)
2897 return_type
= debug_get_return_type (dhandle
, type
);
2898 if (return_type
== DEBUG_TYPE_NULL
)
2903 type
= parse_stab_argtypes (dhandle
, info
, class_type
, name
,
2904 tagname
, return_type
, argtypes
,
2905 constp
, volatilep
, &physname
);
2906 if (type
== DEBUG_TYPE_NULL
)
2910 if (cvars
+ 1 >= allocvars
)
2913 variants
= ((debug_method_variant
*)
2915 allocvars
* sizeof *variants
));
2919 variants
[cvars
] = debug_make_method_variant (dhandle
, physname
,
2924 variants
[cvars
] = debug_make_static_method_variant (dhandle
,
2930 if (variants
[cvars
] == DEBUG_METHOD_VARIANT_NULL
)
2935 while (**pp
!= ';' && **pp
!= '\0');
2937 variants
[cvars
] = DEBUG_METHOD_VARIANT_NULL
;
2945 methods
= ((debug_method
*)
2946 xrealloc (methods
, alloc
* sizeof *methods
));
2949 methods
[c
] = debug_make_method (dhandle
, name
, variants
);
2954 if (methods
!= NULL
)
2955 methods
[c
] = DEBUG_METHOD_NULL
;
2968 /* Parse a string representing argument types for a method. Stabs
2969 tries to save space by packing argument types into a mangled
2970 string. This string should give us enough information to extract
2971 both argument types and the physical name of the function, given
2975 parse_stab_argtypes (void *dhandle
, struct stab_handle
*info
,
2976 debug_type class_type
, const char *fieldname
,
2977 const char *tagname
, debug_type return_type
,
2978 const char *argtypes
, bool constp
,
2979 bool volatilep
, const char **pphysname
)
2981 bool is_full_physname_constructor
;
2982 bool is_constructor
;
2987 unsigned int physname_len
= 0;
2989 /* Constructors are sometimes handled specially. */
2990 is_full_physname_constructor
= ((argtypes
[0] == '_'
2991 && argtypes
[1] == '_'
2992 && (ISDIGIT (argtypes
[2])
2993 || argtypes
[2] == 'Q'
2994 || argtypes
[2] == 't'))
2995 || startswith (argtypes
, "__ct"));
2997 is_constructor
= (is_full_physname_constructor
2999 && strcmp (fieldname
, tagname
) == 0));
3000 is_destructor
= ((argtypes
[0] == '_'
3001 && (argtypes
[1] == '$' || argtypes
[1] == '.')
3002 && argtypes
[2] == '_')
3003 || startswith (argtypes
, "__dt"));
3004 is_v3
= argtypes
[0] == '_' && argtypes
[1] == 'Z';
3006 if (!(is_destructor
|| is_full_physname_constructor
|| is_v3
))
3009 const char *const_prefix
;
3010 const char *volatile_prefix
;
3012 unsigned int mangled_name_len
;
3015 len
= tagname
== NULL
? 0 : strlen (tagname
);
3016 const_prefix
= constp
? "C" : "";
3017 volatile_prefix
= volatilep
? "V" : "";
3020 sprintf (buf
, "__%s%s", const_prefix
, volatile_prefix
);
3021 else if (tagname
!= NULL
&& strchr (tagname
, '<') != NULL
)
3023 /* Template methods are fully mangled. */
3024 sprintf (buf
, "__%s%s", const_prefix
, volatile_prefix
);
3029 sprintf (buf
, "__%s%s%d", const_prefix
, volatile_prefix
, len
);
3031 mangled_name_len
= ((is_constructor
? 0 : strlen (fieldname
))
3037 if (fieldname
[0] == 'o'
3038 && fieldname
[1] == 'p'
3039 && (fieldname
[2] == '$' || fieldname
[2] == '.'))
3041 /* Opname selection is no longer supported by libiberty's demangler. */
3042 return DEBUG_TYPE_NULL
;
3045 physname
= (char *) xmalloc (mangled_name_len
);
3049 strcpy (physname
, fieldname
);
3051 physname_len
= strlen (physname
);
3052 strcat (physname
, buf
);
3053 if (tagname
!= NULL
)
3054 strcat (physname
, tagname
);
3055 strcat (physname
, argtypes
);
3057 *pphysname
= physname
;
3060 if (*argtypes
== '\0' || is_destructor
)
3062 args
= (debug_type
*) xmalloc (sizeof *args
);
3064 return debug_make_method_type (dhandle
, return_type
, class_type
, args
,
3068 args
= stab_demangle_argtypes (dhandle
, info
, *pphysname
, &varargs
, physname_len
);
3070 return DEBUG_TYPE_NULL
;
3072 return debug_make_method_type (dhandle
, return_type
, class_type
, args
,
3076 /* The tail end of stabs for C++ classes that contain a virtual function
3077 pointer contains a tilde, a %, and a type number.
3078 The type number refers to the base class (possibly this class itself) which
3079 contains the vtable pointer for the current class.
3081 This function is called when we have parsed all the method declarations,
3082 so we can look for the vptr base class info. */
3085 parse_stab_tilde_field (void *dhandle
,
3086 struct stab_handle
*info
,
3088 const int *typenums
,
3089 debug_type
*retvptrbase
,
3097 *retvptrbase
= DEBUG_TYPE_NULL
;
3098 *retownvptr
= false;
3104 /* If we are positioned at a ';', then skip it. */
3112 if (**pp
== '=' || **pp
== '+' || **pp
== '-')
3114 /* Obsolete flags that used to indicate the presence of
3115 constructors and/or destructors. */
3125 /* The next number is the type number of the base class (possibly
3126 our own class) which supplies the vtable for this class. */
3127 if (! parse_stab_type_number (pp
, vtypenums
, p_end
))
3130 if (vtypenums
[0] == typenums
[0]
3131 && vtypenums
[1] == typenums
[1])
3140 vtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
3141 (debug_type
**) NULL
, p_end
);
3142 for (p
= *pp
; *p
!= ';' && *p
!= '\0'; p
++)
3150 *retvptrbase
= vtype
;
3158 /* Read a definition of an array type. */
3161 parse_stab_array_type (void *dhandle
,
3162 struct stab_handle
*info
,
3170 debug_type index_type
;
3172 bfd_signed_vma lower
, upper
;
3173 debug_type element_type
;
3175 /* Format of an array type:
3176 "ar<index type>;lower;upper;<array_contents_type>".
3177 OS9000: "arlower,upper;<array_contents_type>".
3179 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
3180 for these, produce a type like float[][]. */
3184 return DEBUG_TYPE_NULL
;
3186 /* FIXME: gdb checks os9k_stabs here. */
3188 /* If the index type is type 0, we take it as int. */
3190 if (! parse_stab_type_number (&p
, typenums
, p_end
))
3191 return DEBUG_TYPE_NULL
;
3193 if (typenums
[0] == 0 && typenums
[1] == 0 && **pp
!= '=')
3195 index_type
= debug_find_named_type (dhandle
, "int");
3196 if (index_type
== DEBUG_TYPE_NULL
)
3198 index_type
= debug_make_int_type (dhandle
, 4, false);
3199 if (index_type
== DEBUG_TYPE_NULL
)
3200 return DEBUG_TYPE_NULL
;
3206 index_type
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
3207 (debug_type
**) NULL
, p_end
);
3213 return DEBUG_TYPE_NULL
;
3219 if (! ISDIGIT (**pp
) && **pp
!= '-' && **pp
!= 0)
3225 lower
= (bfd_signed_vma
) parse_number (pp
, (bool *) NULL
, p_end
);
3229 return DEBUG_TYPE_NULL
;
3233 if (! ISDIGIT (**pp
) && **pp
!= '-' && **pp
!= 0)
3239 upper
= (bfd_signed_vma
) parse_number (pp
, (bool *) NULL
, p_end
);
3243 return DEBUG_TYPE_NULL
;
3247 element_type
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
3248 (debug_type
**) NULL
, p_end
);
3249 if (element_type
== DEBUG_TYPE_NULL
)
3250 return DEBUG_TYPE_NULL
;
3258 return debug_make_array_type (dhandle
, element_type
, index_type
, lower
,
3262 /* This struct holds information about files we have seen using
3267 /* The next N_BINCL file. */
3268 struct bincl_file
*next
;
3269 /* The next N_BINCL on the stack. */
3270 struct bincl_file
*next_stack
;
3271 /* The file name. */
3273 /* The hash value. */
3275 /* The file index. */
3277 /* The list of types defined in this file. */
3278 struct stab_types
*file_types
;
3281 /* Start a new N_BINCL file, pushing it onto the stack. */
3284 push_bincl (struct stab_handle
*info
, const char *name
, bfd_vma hash
)
3286 struct bincl_file
*n
;
3288 n
= (struct bincl_file
*) xmalloc (sizeof *n
);
3289 n
->next
= info
->bincl_list
;
3290 n
->next_stack
= info
->bincl_stack
;
3293 n
->file
= info
->files
;
3294 n
->file_types
= NULL
;
3295 info
->bincl_list
= n
;
3296 info
->bincl_stack
= n
;
3299 info
->file_types
= ((struct stab_types
**)
3300 xrealloc (info
->file_types
,
3302 * sizeof *info
->file_types
)));
3303 info
->file_types
[n
->file
] = NULL
;
3306 /* Finish an N_BINCL file, at an N_EINCL, popping the name off the
3310 pop_bincl (struct stab_handle
*info
)
3312 struct bincl_file
*o
;
3314 o
= info
->bincl_stack
;
3316 return info
->main_filename
;
3317 info
->bincl_stack
= o
->next_stack
;
3319 if (o
->file
>= info
->files
)
3320 return info
->main_filename
;
3322 o
->file_types
= info
->file_types
[o
->file
];
3324 if (info
->bincl_stack
== NULL
)
3325 return info
->main_filename
;
3326 return info
->bincl_stack
->name
;
3329 /* Handle an N_EXCL: get the types from the corresponding N_BINCL. */
3332 find_excl (struct stab_handle
*info
, const char *name
, bfd_vma hash
)
3334 struct bincl_file
*l
;
3337 info
->file_types
= ((struct stab_types
**)
3338 xrealloc (info
->file_types
,
3340 * sizeof *info
->file_types
)));
3342 for (l
= info
->bincl_list
; l
!= NULL
; l
= l
->next
)
3343 if (l
->hash
== hash
&& strcmp (l
->name
, name
) == 0)
3347 warn_stab (name
, _("Undefined N_EXCL"));
3348 info
->file_types
[info
->files
- 1] = NULL
;
3352 info
->file_types
[info
->files
- 1] = l
->file_types
;
3357 /* Handle a variable definition. gcc emits variable definitions for a
3358 block before the N_LBRAC, so we must hold onto them until we see
3359 it. The SunPRO compiler emits variable definitions after the
3360 N_LBRAC, so we can call debug_record_variable immediately. */
3363 stab_record_variable (void *dhandle
, struct stab_handle
*info
,
3364 const char *name
, debug_type type
,
3365 enum debug_var_kind kind
, bfd_vma val
)
3367 struct stab_pending_var
*v
;
3369 if ((kind
== DEBUG_GLOBAL
|| kind
== DEBUG_STATIC
)
3370 || ! info
->within_function
3371 || (info
->gcc_compiled
== 0 && info
->n_opt_found
))
3372 return debug_record_variable (dhandle
, name
, type
, kind
, val
);
3374 v
= (struct stab_pending_var
*) xmalloc (sizeof *v
);
3375 memset (v
, 0, sizeof *v
);
3377 v
->next
= info
->pending
;
3387 /* Emit pending variable definitions. This is called after we see the
3388 N_LBRAC that starts the block. */
3391 stab_emit_pending_vars (void *dhandle
, struct stab_handle
*info
)
3393 struct stab_pending_var
*v
;
3398 struct stab_pending_var
*next
;
3400 if (! debug_record_variable (dhandle
, v
->name
, v
->type
, v
->kind
, v
->val
))
3408 info
->pending
= NULL
;
3413 /* Find the slot for a type in the database. */
3416 stab_find_slot (struct stab_handle
*info
, const int *typenums
)
3418 unsigned int filenum
;
3419 unsigned int tindex
;
3420 unsigned int base_index
;
3421 struct stab_types
**ps
;
3423 filenum
= typenums
[0];
3424 tindex
= typenums
[1];
3426 if (filenum
>= info
->files
)
3428 fprintf (stderr
, _("Type file number %d out of range\n"), filenum
);
3432 ps
= info
->file_types
+ filenum
;
3433 base_index
= tindex
/ STAB_TYPES_SLOTS
* STAB_TYPES_SLOTS
;
3434 tindex
-= base_index
;
3435 while (*ps
&& (*ps
)->base_index
< base_index
)
3438 if (*ps
== NULL
|| (*ps
)->base_index
!= base_index
)
3440 struct stab_types
*n
= xcalloc (1, sizeof (*n
));
3442 n
->base_index
= base_index
;
3446 return (*ps
)->types
+ tindex
;
3449 /* Find a type given a type number. If the type has not been
3450 allocated yet, create an indirect type. */
3453 stab_find_type (void *dhandle
, struct stab_handle
*info
, const int *typenums
)
3457 if (typenums
[0] == 0 && typenums
[1] < 0)
3459 /* A negative type number indicates an XCOFF builtin type. */
3460 return stab_xcoff_builtin_type (dhandle
, info
, typenums
[1]);
3463 slot
= stab_find_slot (info
, typenums
);
3465 return DEBUG_TYPE_NULL
;
3467 if (*slot
== DEBUG_TYPE_NULL
)
3468 return debug_make_indirect_type (dhandle
, slot
, (const char *) NULL
);
3473 /* Record that a given type number refers to a given type. */
3476 stab_record_type (void *dhandle ATTRIBUTE_UNUSED
, struct stab_handle
*info
,
3477 const int *typenums
, debug_type type
)
3481 slot
= stab_find_slot (info
, typenums
);
3485 /* gdb appears to ignore type redefinitions, so we do as well. */
3492 /* Return an XCOFF builtin type. */
3495 stab_xcoff_builtin_type (void *dhandle
, struct stab_handle
*info
,
3496 unsigned int typenum
)
3501 typenum
= -typenum
- 1;
3502 if (typenum
>= XCOFF_TYPE_COUNT
)
3504 fprintf (stderr
, _("Unrecognized XCOFF type %d\n"), -typenum
- 1);
3505 return DEBUG_TYPE_NULL
;
3507 if (info
->xcoff_types
[typenum
] != NULL
)
3508 return info
->xcoff_types
[typenum
];
3513 /* The size of this and all the other types are fixed, defined
3514 by the debugging format. */
3516 rettype
= debug_make_int_type (dhandle
, 4, false);
3520 rettype
= debug_make_int_type (dhandle
, 1, false);
3524 rettype
= debug_make_int_type (dhandle
, 2, false);
3528 rettype
= debug_make_int_type (dhandle
, 4, false);
3531 name
= "unsigned char";
3532 rettype
= debug_make_int_type (dhandle
, 1, true);
3535 name
= "signed char";
3536 rettype
= debug_make_int_type (dhandle
, 1, false);
3539 name
= "unsigned short";
3540 rettype
= debug_make_int_type (dhandle
, 2, true);
3543 name
= "unsigned int";
3544 rettype
= debug_make_int_type (dhandle
, 4, true);
3548 rettype
= debug_make_int_type (dhandle
, 4, true);
3551 name
= "unsigned long";
3552 rettype
= debug_make_int_type (dhandle
, 4, true);
3556 rettype
= debug_make_void_type (dhandle
);
3559 /* IEEE single precision (32 bit). */
3561 rettype
= debug_make_float_type (dhandle
, 4);
3564 /* IEEE double precision (64 bit). */
3566 rettype
= debug_make_float_type (dhandle
, 8);
3569 /* This is an IEEE double on the RS/6000, and different machines
3570 with different sizes for "long double" should use different
3571 negative type numbers. See stabs.texinfo. */
3572 name
= "long double";
3573 rettype
= debug_make_float_type (dhandle
, 8);
3577 rettype
= debug_make_int_type (dhandle
, 4, false);
3581 rettype
= debug_make_bool_type (dhandle
, 4);
3584 name
= "short real";
3585 rettype
= debug_make_float_type (dhandle
, 4);
3589 rettype
= debug_make_float_type (dhandle
, 8);
3599 rettype
= debug_make_int_type (dhandle
, 1, true);
3603 rettype
= debug_make_bool_type (dhandle
, 1);
3607 rettype
= debug_make_bool_type (dhandle
, 2);
3611 rettype
= debug_make_bool_type (dhandle
, 4);
3615 rettype
= debug_make_bool_type (dhandle
, 4);
3618 /* Complex type consisting of two IEEE single precision values. */
3620 rettype
= debug_make_complex_type (dhandle
, 8);
3623 /* Complex type consisting of two IEEE double precision values. */
3624 name
= "double complex";
3625 rettype
= debug_make_complex_type (dhandle
, 16);
3629 rettype
= debug_make_int_type (dhandle
, 1, false);
3633 rettype
= debug_make_int_type (dhandle
, 2, false);
3637 rettype
= debug_make_int_type (dhandle
, 4, false);
3642 rettype
= debug_make_int_type (dhandle
, 2, false);
3646 rettype
= debug_make_int_type (dhandle
, 8, false);
3649 name
= "unsigned long long";
3650 rettype
= debug_make_int_type (dhandle
, 8, true);
3654 rettype
= debug_make_bool_type (dhandle
, 8);
3658 rettype
= debug_make_int_type (dhandle
, 8, false);
3664 rettype
= debug_name_type (dhandle
, name
, rettype
);
3665 info
->xcoff_types
[typenum
] = rettype
;
3669 /* Find or create a tagged type. */
3672 stab_find_tagged_type (void *dhandle
, struct stab_handle
*info
,
3673 const char *p
, int len
, enum debug_type_kind kind
)
3677 struct stab_tag
*st
;
3679 name
= savestring (p
, len
);
3681 /* We pass DEBUG_KIND_ILLEGAL because we want all tags in the same
3682 namespace. This is right for C, and I don't know how to handle
3683 other languages. FIXME. */
3684 dtype
= debug_find_tagged_type (dhandle
, name
, DEBUG_KIND_ILLEGAL
);
3685 if (dtype
!= DEBUG_TYPE_NULL
)
3691 /* We need to allocate an entry on the undefined tag list. */
3692 for (st
= info
->tags
; st
!= NULL
; st
= st
->next
)
3694 if (st
->name
[0] == name
[0]
3695 && strcmp (st
->name
, name
) == 0)
3697 if (st
->kind
== DEBUG_KIND_ILLEGAL
)
3705 st
= (struct stab_tag
*) xmalloc (sizeof *st
);
3706 memset (st
, 0, sizeof *st
);
3708 st
->next
= info
->tags
;
3711 st
->slot
= DEBUG_TYPE_NULL
;
3712 st
->type
= debug_make_indirect_type (dhandle
, &st
->slot
, name
);
3719 /* In order to get the correct argument types for a stubbed method, we
3720 need to extract the argument types from a C++ mangled string.
3721 Since the argument types can refer back to the return type, this
3722 means that we must demangle the entire physical name. In gdb this
3723 is done by calling cplus_demangle and running the results back
3724 through the C++ expression parser. Since we have no expression
3725 parser, we must duplicate much of the work of cplus_demangle here.
3727 We assume that GNU style demangling is used, since this is only
3728 done for method stubs, and only g++ should output that form of
3729 debugging information. */
3731 /* This structure is used to hold a pointer to type information which
3732 demangling a string. */
3734 struct stab_demangle_typestring
3736 /* The start of the type. This is not null terminated. */
3737 const char *typestring
;
3738 /* The length of the type. */
3742 /* This structure is used to hold information while demangling a
3745 struct stab_demangle_info
3747 /* The debugging information handle. */
3749 /* The stab information handle. */
3750 struct stab_handle
*info
;
3751 /* The array of arguments we are building. */
3753 /* Whether the method takes a variable number of arguments. */
3755 /* The array of types we have remembered. */
3756 struct stab_demangle_typestring
*typestrings
;
3757 /* The number of typestrings. */
3758 unsigned int typestring_count
;
3759 /* The number of typestring slots we have allocated. */
3760 unsigned int typestring_alloc
;
3763 static void stab_bad_demangle (const char *);
3764 static unsigned int stab_demangle_count (const char **);
3765 static bool stab_demangle_get_count (const char **, unsigned int *);
3766 static bool stab_demangle_prefix
3767 (struct stab_demangle_info
*, const char **, unsigned int);
3768 static bool stab_demangle_function_name
3769 (struct stab_demangle_info
*, const char **, const char *);
3770 static bool stab_demangle_signature
3771 (struct stab_demangle_info
*, const char **);
3772 static bool stab_demangle_qualified
3773 (struct stab_demangle_info
*, const char **, debug_type
*);
3774 static bool stab_demangle_template
3775 (struct stab_demangle_info
*, const char **, char **);
3776 static bool stab_demangle_class
3777 (struct stab_demangle_info
*, const char **, const char **);
3778 static bool stab_demangle_args
3779 (struct stab_demangle_info
*, const char **, debug_type
**, bool *);
3780 static bool stab_demangle_arg
3781 (struct stab_demangle_info
*, const char **, debug_type
**,
3782 unsigned int *, unsigned int *);
3783 static bool stab_demangle_type
3784 (struct stab_demangle_info
*, const char **, debug_type
*);
3785 static bool stab_demangle_fund_type
3786 (struct stab_demangle_info
*, const char **, debug_type
*);
3787 static bool stab_demangle_remember_type
3788 (struct stab_demangle_info
*, const char *, int);
3790 /* Warn about a bad demangling. */
3793 stab_bad_demangle (const char *s
)
3795 fprintf (stderr
, _("bad mangled name `%s'\n"), s
);
3798 /* Get a count from a stab string. */
3801 stab_demangle_count (const char **pp
)
3806 while (ISDIGIT (**pp
))
3809 count
+= **pp
- '0';
3815 /* Require a count in a string. The count may be multiple digits, in
3816 which case it must end in an underscore. */
3819 stab_demangle_get_count (const char **pp
, unsigned int *pi
)
3821 if (! ISDIGIT (**pp
))
3839 while (ISDIGIT (*p
));
3850 /* This function demangles a physical name, returning a NULL
3851 terminated array of argument types. */
3854 stab_demangle_argtypes (void *dhandle
, struct stab_handle
*info
,
3855 const char *physname
, bool *pvarargs
,
3856 unsigned int physname_len
)
3858 struct stab_demangle_info minfo
;
3860 /* Check for the g++ V3 ABI. */
3861 if (physname
[0] == '_' && physname
[1] == 'Z')
3862 return stab_demangle_v3_argtypes (dhandle
, info
, physname
, pvarargs
);
3864 minfo
.dhandle
= dhandle
;
3867 minfo
.varargs
= false;
3868 minfo
.typestring_alloc
= 10;
3869 minfo
.typestrings
= ((struct stab_demangle_typestring
*)
3870 xmalloc (minfo
.typestring_alloc
3871 * sizeof *minfo
.typestrings
));
3872 minfo
.typestring_count
= 0;
3874 /* cplus_demangle checks for special GNU mangled forms, but we can't
3875 see any of them in mangled method argument types. */
3877 if (! stab_demangle_prefix (&minfo
, &physname
, physname_len
))
3880 if (*physname
!= '\0')
3882 if (! stab_demangle_signature (&minfo
, &physname
))
3886 free (minfo
.typestrings
);
3887 minfo
.typestrings
= NULL
;
3889 if (minfo
.args
== NULL
)
3890 fprintf (stderr
, _("no argument types in mangled string\n"));
3892 *pvarargs
= minfo
.varargs
;
3896 free (minfo
.typestrings
);
3900 /* Demangle the prefix of the mangled name. */
3903 stab_demangle_prefix (struct stab_demangle_info
*minfo
, const char **pp
,
3904 unsigned int physname_len
)
3909 /* cplus_demangle checks for global constructors and destructors,
3910 but we can't see them in mangled argument types. */
3913 scan
= *pp
+ physname_len
;
3916 /* Look for `__'. */
3919 scan
= strchr (scan
, '_');
3920 while (scan
!= NULL
&& *++scan
!= '_');
3924 stab_bad_demangle (*pp
);
3930 /* We found `__'; move ahead to the last contiguous `__' pair. */
3931 i
= strspn (scan
, "_");
3937 && (ISDIGIT (scan
[2])
3941 /* This is a GNU style constructor name. */
3945 else if (scan
== *pp
3946 && ! ISDIGIT (scan
[2])
3949 /* Look for the `__' that separates the prefix from the
3951 while (*scan
== '_')
3953 scan
= strstr (scan
, "__");
3954 if (scan
== NULL
|| scan
[2] == '\0')
3956 stab_bad_demangle (*pp
);
3960 return stab_demangle_function_name (minfo
, pp
, scan
);
3962 else if (scan
[2] != '\0')
3964 /* The name doesn't start with `__', but it does contain `__'. */
3965 return stab_demangle_function_name (minfo
, pp
, scan
);
3969 stab_bad_demangle (*pp
);
3975 /* Demangle a function name prefix. The scan argument points to the
3976 double underscore which separates the function name from the
3980 stab_demangle_function_name (struct stab_demangle_info
*minfo
,
3981 const char **pp
, const char *scan
)
3985 /* The string from *pp to scan is the name of the function. We
3986 don't care about the name, since we just looking for argument
3987 types. However, for conversion operators, the name may include a
3988 type which we must remember in order to handle backreferences. */
3994 && startswith (name
, "type")
3995 && (name
[4] == '$' || name
[4] == '.'))
3999 /* This is a type conversion operator. */
4001 if (! stab_demangle_type (minfo
, &tem
, (debug_type
*) NULL
))
4004 else if (name
[0] == '_'
4011 /* This is a type conversion operator. */
4013 if (! stab_demangle_type (minfo
, &tem
, (debug_type
*) NULL
))
4020 /* Demangle the signature. This is where the argument types are
4024 stab_demangle_signature (struct stab_demangle_info
*minfo
, const char **pp
)
4027 bool expect_func
, func_done
;
4032 expect_func
= false;
4036 while (**pp
!= '\0')
4042 if (! stab_demangle_qualified (minfo
, pp
, (debug_type
*) NULL
)
4043 || ! stab_demangle_remember_type (minfo
, hold
, *pp
- hold
))
4050 /* Static member function. FIXME: Can this happen? */
4057 /* Const member function. */
4063 case '0': case '1': case '2': case '3': case '4':
4064 case '5': case '6': case '7': case '8': case '9':
4067 if (! stab_demangle_class (minfo
, pp
, (const char **) NULL
)
4068 || ! stab_demangle_remember_type (minfo
, hold
, *pp
- hold
))
4075 /* Function. I don't know if this actually happens with g++
4080 if (! stab_demangle_args (minfo
, pp
, &minfo
->args
, &minfo
->varargs
))
4088 if (! stab_demangle_template (minfo
, pp
, (char **) NULL
)
4089 || ! stab_demangle_remember_type (minfo
, hold
, *pp
- hold
))
4096 /* At the outermost level, we cannot have a return type
4097 specified, so if we run into another '_' at this point we
4098 are dealing with a mangled name that is either bogus, or
4099 has been mangled by some algorithm we don't know how to
4100 deal with. So just reject the entire demangling. */
4101 stab_bad_demangle (orig
);
4105 /* Assume we have stumbled onto the first outermost function
4106 argument token, and start processing args. */
4108 if (! stab_demangle_args (minfo
, pp
, &minfo
->args
, &minfo
->varargs
))
4116 if (! stab_demangle_args (minfo
, pp
, &minfo
->args
, &minfo
->varargs
))
4123 /* With GNU style demangling, bar__3foo is 'foo::bar(void)', and
4124 bar__3fooi is 'foo::bar(int)'. We get here when we find the
4125 first case, and need to ensure that the '(void)' gets added
4126 to the current declp. */
4127 if (! stab_demangle_args (minfo
, pp
, &minfo
->args
, &minfo
->varargs
))
4134 /* Demangle a qualified name, such as "Q25Outer5Inner" which is the
4135 mangled form of "Outer::Inner". */
4138 stab_demangle_qualified (struct stab_demangle_info
*minfo
, const char **pp
,
4143 unsigned int qualifiers
;
4151 /* GNU mangled name with more than 9 classes. The count is
4152 preceded by an underscore (to distinguish it from the <= 9
4153 case) and followed by an underscore. */
4155 if (! ISDIGIT (*p
) || *p
== '0')
4157 stab_bad_demangle (orig
);
4160 qualifiers
= atoi (p
);
4161 while (ISDIGIT (*p
))
4165 stab_bad_demangle (orig
);
4171 case '1': case '2': case '3': case '4': case '5':
4172 case '6': case '7': case '8': case '9':
4173 qualifiers
= (*pp
)[1] - '0';
4174 /* Skip an optional underscore after the count. */
4175 if ((*pp
)[2] == '_')
4182 stab_bad_demangle (orig
);
4186 context
= DEBUG_TYPE_NULL
;
4188 /* Pick off the names. */
4189 while (qualifiers
-- > 0)
4197 if (! stab_demangle_template (minfo
, pp
,
4198 ptype
!= NULL
? &name
: NULL
))
4203 context
= stab_find_tagged_type (minfo
->dhandle
, minfo
->info
,
4204 name
, strlen (name
),
4207 if (context
== DEBUG_TYPE_NULL
)
4215 len
= stab_demangle_count (pp
);
4216 if (strlen (*pp
) < len
)
4218 stab_bad_demangle (orig
);
4224 const debug_field
*fields
;
4227 if (context
!= DEBUG_TYPE_NULL
)
4228 fields
= debug_get_fields (minfo
->dhandle
, context
);
4230 context
= DEBUG_TYPE_NULL
;
4236 /* Try to find the type by looking through the
4237 fields of context until we find a field with the
4238 same type. This ought to work for a class
4239 defined within a class, but it won't work for,
4240 e.g., an enum defined within a class. stabs does
4241 not give us enough information to figure out the
4244 name
= savestring (*pp
, len
);
4246 for (; *fields
!= DEBUG_FIELD_NULL
; fields
++)
4251 ft
= debug_get_field_type (minfo
->dhandle
, *fields
);
4257 dn
= debug_get_type_name (minfo
->dhandle
, ft
);
4258 if (dn
!= NULL
&& strcmp (dn
, name
) == 0)
4268 if (context
== DEBUG_TYPE_NULL
)
4270 /* We have to fall back on finding the type by name.
4271 If there are more types to come, then this must
4272 be a class. Otherwise, it could be anything. */
4274 if (qualifiers
== 0)
4278 name
= savestring (*pp
, len
);
4279 context
= debug_find_named_type (minfo
->dhandle
,
4284 if (context
== DEBUG_TYPE_NULL
)
4286 context
= stab_find_tagged_type (minfo
->dhandle
,
4290 ? DEBUG_KIND_ILLEGAL
4291 : DEBUG_KIND_CLASS
));
4292 if (context
== DEBUG_TYPE_NULL
)
4308 /* Demangle a template. If PNAME is not NULL, this sets *PNAME to a
4309 string representation of the template. */
4312 stab_demangle_template (struct stab_demangle_info
*minfo
, const char **pp
,
4322 /* Skip the template name. */
4323 r
= stab_demangle_count (pp
);
4324 if (r
== 0 || strlen (*pp
) < r
)
4326 stab_bad_demangle (orig
);
4331 /* Get the size of the parameter list. */
4332 if (stab_demangle_get_count (pp
, &r
) == 0)
4334 stab_bad_demangle (orig
);
4338 for (i
= 0; i
< r
; i
++)
4342 /* This is a type parameter. */
4344 if (! stab_demangle_type (minfo
, pp
, (debug_type
*) NULL
))
4350 bool pointerp
, realp
, integralp
, charp
, boolp
;
4361 /* This is a value parameter. */
4363 if (! stab_demangle_type (minfo
, pp
, (debug_type
*) NULL
))
4366 while (*old_p
!= '\0' && ! done
)
4376 case 'C': /* Const. */
4377 case 'S': /* Signed. */
4378 case 'U': /* Unsigned. */
4379 case 'V': /* Volatile. */
4380 case 'F': /* Function. */
4381 case 'M': /* Member function. */
4385 case 'Q': /* Qualified name. */
4389 case 'T': /* Remembered type. */
4391 case 'v': /* Void. */
4393 case 'x': /* Long long. */
4394 case 'l': /* Long. */
4395 case 'i': /* Int. */
4396 case 's': /* Short. */
4397 case 'w': /* Wchar_t. */
4401 case 'b': /* Bool. */
4405 case 'c': /* Char. */
4409 case 'r': /* Long double. */
4410 case 'd': /* Double. */
4411 case 'f': /* Float. */
4416 /* Assume it's a user defined integral type. */
4427 while (ISDIGIT (**pp
))
4436 val
= stab_demangle_count (pp
);
4439 stab_bad_demangle (orig
);
4447 val
= stab_demangle_count (pp
);
4448 if (val
!= 0 && val
!= 1)
4450 stab_bad_demangle (orig
);
4458 while (ISDIGIT (**pp
))
4463 while (ISDIGIT (**pp
))
4469 while (ISDIGIT (**pp
))
4477 len
= stab_demangle_count (pp
);
4480 stab_bad_demangle (orig
);
4488 /* We can translate this to a string fairly easily by invoking the
4489 regular demangling routine. */
4492 char *s1
, *s2
, *s3
, *s4
= NULL
;
4495 s1
= savestring (orig
, *pp
- orig
);
4497 s2
= concat ("NoSuchStrinG__", s1
, (const char *) NULL
);
4501 s3
= cplus_demangle (s2
, demangle_flags
);
4506 s4
= strstr (s3
, "::NoSuchStrinG");
4507 if (s3
== NULL
|| s4
== NULL
)
4509 stab_bad_demangle (orig
);
4514 /* Eliminating all spaces, except those between > characters,
4515 makes it more likely that the demangled name will match the
4516 name which g++ used as the structure name. */
4517 for (from
= to
= s3
; from
!= s4
; ++from
)
4519 || (from
[1] == '>' && from
> s3
&& from
[-1] == '>'))
4522 *pname
= savestring (s3
, to
- s3
);
4530 /* Demangle a class name. */
4533 stab_demangle_class (struct stab_demangle_info
*minfo ATTRIBUTE_UNUSED
,
4534 const char **pp
, const char **pstart
)
4541 n
= stab_demangle_count (pp
);
4542 if (strlen (*pp
) < n
)
4544 stab_bad_demangle (orig
);
4556 /* Demangle function arguments. If the pargs argument is not NULL, it
4557 is set to a NULL terminated array holding the arguments. */
4560 stab_demangle_args (struct stab_demangle_info
*minfo
, const char **pp
,
4561 debug_type
**pargs
, bool *pvarargs
)
4564 unsigned int alloc
, count
;
4571 *pargs
= (debug_type
*) xmalloc (alloc
* sizeof **pargs
);
4576 while (**pp
!= '_' && **pp
!= '\0' && **pp
!= 'e')
4578 if (**pp
== 'N' || **pp
== 'T')
4586 if (temptype
== 'T')
4590 if (! stab_demangle_get_count (pp
, &r
))
4592 stab_bad_demangle (orig
);
4597 if (! stab_demangle_get_count (pp
, &t
))
4599 stab_bad_demangle (orig
);
4603 if (t
>= minfo
->typestring_count
)
4605 stab_bad_demangle (orig
);
4612 tem
= minfo
->typestrings
[t
].typestring
;
4613 if (! stab_demangle_arg (minfo
, &tem
, pargs
, &count
, &alloc
))
4619 if (! stab_demangle_arg (minfo
, pp
, pargs
, &count
, &alloc
))
4625 (*pargs
)[count
] = DEBUG_TYPE_NULL
;
4637 /* Demangle a single argument. */
4640 stab_demangle_arg (struct stab_demangle_info
*minfo
, const char **pp
,
4641 debug_type
**pargs
, unsigned int *pcount
,
4642 unsigned int *palloc
)
4648 if (! stab_demangle_type (minfo
, pp
,
4649 pargs
== NULL
? (debug_type
*) NULL
: &type
)
4650 || ! stab_demangle_remember_type (minfo
, start
, *pp
- start
))
4655 if (type
== DEBUG_TYPE_NULL
)
4658 if (*pcount
+ 1 >= *palloc
)
4661 *pargs
= ((debug_type
*)
4662 xrealloc (*pargs
, *palloc
* sizeof **pargs
));
4664 (*pargs
)[*pcount
] = type
;
4671 /* Demangle a type. If the ptype argument is not NULL, *ptype is set
4672 to the newly allocated type. */
4675 stab_demangle_type (struct stab_demangle_info
*minfo
, const char **pp
,
4686 /* A pointer type. */
4688 if (! stab_demangle_type (minfo
, pp
, ptype
))
4691 *ptype
= debug_make_pointer_type (minfo
->dhandle
, *ptype
);
4695 /* A reference type. */
4697 if (! stab_demangle_type (minfo
, pp
, ptype
))
4700 *ptype
= debug_make_reference_type (minfo
->dhandle
, *ptype
);
4710 while (**pp
!= '\0' && **pp
!= '_')
4712 if (! ISDIGIT (**pp
))
4714 stab_bad_demangle (orig
);
4723 stab_bad_demangle (orig
);
4728 if (! stab_demangle_type (minfo
, pp
, ptype
))
4732 debug_type int_type
;
4734 int_type
= debug_find_named_type (minfo
->dhandle
, "int");
4735 if (int_type
== NULL
)
4736 int_type
= debug_make_int_type (minfo
->dhandle
, 4, false);
4737 *ptype
= debug_make_array_type (minfo
->dhandle
, *ptype
, int_type
,
4744 /* A back reference to a remembered type. */
4750 if (! stab_demangle_get_count (pp
, &i
))
4752 stab_bad_demangle (orig
);
4755 if (i
>= minfo
->typestring_count
)
4757 stab_bad_demangle (orig
);
4760 p
= minfo
->typestrings
[i
].typestring
;
4761 if (! stab_demangle_type (minfo
, &p
, ptype
))
4773 if (! stab_demangle_args (minfo
, pp
,
4775 ? (debug_type
**) NULL
4783 /* cplus_demangle will accept a function without a return
4784 type, but I don't know when that will happen, or what
4785 to do if it does. */
4786 stab_bad_demangle (orig
);
4790 if (! stab_demangle_type (minfo
, pp
, ptype
))
4793 *ptype
= debug_make_function_type (minfo
->dhandle
, *ptype
, args
,
4803 debug_type class_type
= DEBUG_TYPE_NULL
;
4809 memberp
= **pp
== 'M';
4816 n
= stab_demangle_count (pp
);
4817 if (strlen (*pp
) < n
)
4819 stab_bad_demangle (orig
);
4827 class_type
= stab_find_tagged_type (minfo
->dhandle
,
4831 if (class_type
== DEBUG_TYPE_NULL
)
4835 else if (**pp
== 'Q')
4837 if (! stab_demangle_qualified (minfo
, pp
,
4839 ? (debug_type
*) NULL
4845 stab_bad_demangle (orig
);
4855 else if (**pp
== 'V')
4861 stab_bad_demangle (orig
);
4865 if (! stab_demangle_args (minfo
, pp
,
4867 ? (debug_type
**) NULL
4877 stab_bad_demangle (orig
);
4882 if (! stab_demangle_type (minfo
, pp
, ptype
))
4888 *ptype
= debug_make_offset_type (minfo
->dhandle
, class_type
,
4892 /* FIXME: We have no way to record constp or
4894 *ptype
= debug_make_method_type (minfo
->dhandle
, *ptype
,
4895 class_type
, args
, varargs
);
4903 if (! stab_demangle_type (minfo
, pp
, ptype
))
4909 if (! stab_demangle_type (minfo
, pp
, ptype
))
4912 *ptype
= debug_make_const_type (minfo
->dhandle
, *ptype
);
4917 if (! stab_demangle_qualified (minfo
, pp
, ptype
))
4923 if (! stab_demangle_fund_type (minfo
, pp
, ptype
))
4931 /* Demangle a fundamental type. If the ptype argument is not NULL,
4932 *ptype is set to the newly allocated type. */
4935 stab_demangle_fund_type (struct stab_demangle_info
*minfo
, const char **pp
,
4939 bool constp
, volatilep
, unsignedp
, signedp
;
4984 /* cplus_demangle permits this, but I don't know what it means. */
4985 stab_bad_demangle (orig
);
4988 case 'v': /* void */
4991 *ptype
= debug_find_named_type (minfo
->dhandle
, "void");
4992 if (*ptype
== DEBUG_TYPE_NULL
)
4993 *ptype
= debug_make_void_type (minfo
->dhandle
);
4998 case 'x': /* long long */
5001 *ptype
= debug_find_named_type (minfo
->dhandle
,
5003 ? "long long unsigned int"
5004 : "long long int"));
5005 if (*ptype
== DEBUG_TYPE_NULL
)
5006 *ptype
= debug_make_int_type (minfo
->dhandle
, 8, unsignedp
);
5011 case 'l': /* long */
5014 *ptype
= debug_find_named_type (minfo
->dhandle
,
5016 ? "long unsigned int"
5018 if (*ptype
== DEBUG_TYPE_NULL
)
5019 *ptype
= debug_make_int_type (minfo
->dhandle
, 4, unsignedp
);
5027 *ptype
= debug_find_named_type (minfo
->dhandle
,
5031 if (*ptype
== DEBUG_TYPE_NULL
)
5032 *ptype
= debug_make_int_type (minfo
->dhandle
, 4, unsignedp
);
5037 case 's': /* short */
5040 *ptype
= debug_find_named_type (minfo
->dhandle
,
5042 ? "short unsigned int"
5044 if (*ptype
== DEBUG_TYPE_NULL
)
5045 *ptype
= debug_make_int_type (minfo
->dhandle
, 2, unsignedp
);
5050 case 'b': /* bool */
5053 *ptype
= debug_find_named_type (minfo
->dhandle
, "bool");
5054 if (*ptype
== DEBUG_TYPE_NULL
)
5055 *ptype
= debug_make_bool_type (minfo
->dhandle
, 4);
5060 case 'c': /* char */
5063 *ptype
= debug_find_named_type (minfo
->dhandle
,
5069 if (*ptype
== DEBUG_TYPE_NULL
)
5070 *ptype
= debug_make_int_type (minfo
->dhandle
, 1, unsignedp
);
5075 case 'w': /* wchar_t */
5078 *ptype
= debug_find_named_type (minfo
->dhandle
, "__wchar_t");
5079 if (*ptype
== DEBUG_TYPE_NULL
)
5080 *ptype
= debug_make_int_type (minfo
->dhandle
, 2, true);
5085 case 'r': /* long double */
5088 *ptype
= debug_find_named_type (minfo
->dhandle
, "long double");
5089 if (*ptype
== DEBUG_TYPE_NULL
)
5090 *ptype
= debug_make_float_type (minfo
->dhandle
, 8);
5095 case 'd': /* double */
5098 *ptype
= debug_find_named_type (minfo
->dhandle
, "double");
5099 if (*ptype
== DEBUG_TYPE_NULL
)
5100 *ptype
= debug_make_float_type (minfo
->dhandle
, 8);
5105 case 'f': /* float */
5108 *ptype
= debug_find_named_type (minfo
->dhandle
, "float");
5109 if (*ptype
== DEBUG_TYPE_NULL
)
5110 *ptype
= debug_make_float_type (minfo
->dhandle
, 4);
5117 if (! ISDIGIT (**pp
))
5119 stab_bad_demangle (orig
);
5123 case '0': case '1': case '2': case '3': case '4':
5124 case '5': case '6': case '7': case '8': case '9':
5128 if (! stab_demangle_class (minfo
, pp
, &hold
))
5134 name
= savestring (hold
, *pp
- hold
);
5135 *ptype
= debug_find_named_type (minfo
->dhandle
, name
);
5137 if (*ptype
== DEBUG_TYPE_NULL
)
5139 /* FIXME: It is probably incorrect to assume that
5140 undefined types are tagged types. */
5141 *ptype
= stab_find_tagged_type (minfo
->dhandle
, minfo
->info
,
5143 DEBUG_KIND_ILLEGAL
);
5144 if (*ptype
== DEBUG_TYPE_NULL
)
5155 if (! stab_demangle_template (minfo
, pp
,
5156 ptype
!= NULL
? &name
: NULL
))
5160 *ptype
= stab_find_tagged_type (minfo
->dhandle
, minfo
->info
,
5161 name
, strlen (name
),
5164 if (*ptype
== DEBUG_TYPE_NULL
)
5171 stab_bad_demangle (orig
);
5178 *ptype
= debug_make_const_type (minfo
->dhandle
, *ptype
);
5180 *ptype
= debug_make_volatile_type (minfo
->dhandle
, *ptype
);
5186 /* Remember a type string in a demangled string. */
5189 stab_demangle_remember_type (struct stab_demangle_info
*minfo
,
5190 const char *p
, int len
)
5192 if (minfo
->typestring_count
>= minfo
->typestring_alloc
)
5194 minfo
->typestring_alloc
+= 10;
5195 minfo
->typestrings
= ((struct stab_demangle_typestring
*)
5196 xrealloc (minfo
->typestrings
,
5197 (minfo
->typestring_alloc
5198 * sizeof *minfo
->typestrings
)));
5201 minfo
->typestrings
[minfo
->typestring_count
].typestring
= p
;
5202 minfo
->typestrings
[minfo
->typestring_count
].len
= (unsigned int) len
;
5203 ++minfo
->typestring_count
;
5208 /* Demangle names encoded using the g++ V3 ABI. The newer versions of
5209 g++ which use this ABI do not encode ordinary method argument types
5210 in a mangled name; they simply output the argument types. However,
5211 for a static method, g++ simply outputs the return type and the
5212 physical name. So in that case we need to demangle the name here.
5213 Here PHYSNAME is the physical name of the function, and we set the
5214 variable pointed at by PVARARGS to indicate whether this function
5215 is varargs. This returns NULL, or a NULL terminated array of
5219 stab_demangle_v3_argtypes (void *dhandle
, struct stab_handle
*info
,
5220 const char *physname
, bool *pvarargs
)
5222 struct demangle_component
*dc
;
5226 dc
= cplus_demangle_v3_components (physname
, DMGL_PARAMS
| demangle_flags
, &mem
);
5229 stab_bad_demangle (physname
);
5233 /* We expect to see TYPED_NAME, and the right subtree describes the
5235 if (dc
->type
!= DEMANGLE_COMPONENT_TYPED_NAME
5236 || dc
->u
.s_binary
.right
->type
!= DEMANGLE_COMPONENT_FUNCTION_TYPE
)
5238 fprintf (stderr
, _("Demangled name is not a function\n"));
5243 pargs
= stab_demangle_v3_arglist (dhandle
, info
,
5244 dc
->u
.s_binary
.right
->u
.s_binary
.right
,
5252 /* Demangle an argument list in a struct demangle_component tree.
5253 Returns a DEBUG_TYPE_NULL terminated array of argument types, and
5254 sets *PVARARGS to indicate whether this is a varargs function. */
5257 stab_demangle_v3_arglist (void *dhandle
, struct stab_handle
*info
,
5258 struct demangle_component
*arglist
,
5261 struct demangle_component
*dc
;
5262 unsigned int alloc
, count
;
5266 pargs
= (debug_type
*) xmalloc (alloc
* sizeof *pargs
);
5273 dc
= dc
->u
.s_binary
.right
)
5278 if (dc
->type
!= DEMANGLE_COMPONENT_ARGLIST
)
5280 fprintf (stderr
, _("Unexpected type in v3 arglist demangling\n"));
5285 /* PR 13925: Cope if the demangler returns an empty
5286 context for a function with no arguments. */
5287 if (dc
->u
.s_binary
.left
== NULL
)
5290 arg
= stab_demangle_v3_arg (dhandle
, info
, dc
->u
.s_binary
.left
,
5303 if (count
+ 1 >= alloc
)
5306 pargs
= (debug_type
*) xrealloc (pargs
, alloc
* sizeof *pargs
);
5313 pargs
[count
] = DEBUG_TYPE_NULL
;
5318 /* Convert a struct demangle_component tree describing an argument
5319 type into a debug_type. */
5322 stab_demangle_v3_arg (void *dhandle
, struct stab_handle
*info
,
5323 struct demangle_component
*dc
, debug_type context
,
5328 if (pvarargs
!= NULL
)
5333 /* FIXME: These are demangle component types which we probably
5334 need to handle one way or another. */
5335 case DEMANGLE_COMPONENT_LOCAL_NAME
:
5336 case DEMANGLE_COMPONENT_TYPED_NAME
:
5337 case DEMANGLE_COMPONENT_TEMPLATE_PARAM
:
5338 case DEMANGLE_COMPONENT_CTOR
:
5339 case DEMANGLE_COMPONENT_DTOR
:
5340 case DEMANGLE_COMPONENT_JAVA_CLASS
:
5341 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
5342 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
5343 case DEMANGLE_COMPONENT_CONST_THIS
:
5344 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
5345 case DEMANGLE_COMPONENT_COMPLEX
:
5346 case DEMANGLE_COMPONENT_IMAGINARY
:
5347 case DEMANGLE_COMPONENT_VENDOR_TYPE
:
5348 case DEMANGLE_COMPONENT_ARRAY_TYPE
:
5349 case DEMANGLE_COMPONENT_PTRMEM_TYPE
:
5350 case DEMANGLE_COMPONENT_ARGLIST
:
5352 fprintf (stderr
, _("Unrecognized demangle component %d\n"),
5356 case DEMANGLE_COMPONENT_NAME
:
5357 if (context
!= NULL
)
5359 const debug_field
*fields
;
5361 fields
= debug_get_fields (dhandle
, context
);
5364 /* Try to find this type by looking through the context
5366 for (; *fields
!= DEBUG_FIELD_NULL
; fields
++)
5371 ft
= debug_get_field_type (dhandle
, *fields
);
5374 dn
= debug_get_type_name (dhandle
, ft
);
5376 && (int) strlen (dn
) == dc
->u
.s_name
.len
5377 && strncmp (dn
, dc
->u
.s_name
.s
, dc
->u
.s_name
.len
) == 0)
5382 return stab_find_tagged_type (dhandle
, info
, dc
->u
.s_name
.s
,
5383 dc
->u
.s_name
.len
, DEBUG_KIND_ILLEGAL
);
5385 case DEMANGLE_COMPONENT_QUAL_NAME
:
5386 context
= stab_demangle_v3_arg (dhandle
, info
, dc
->u
.s_binary
.left
,
5388 if (context
== NULL
)
5390 return stab_demangle_v3_arg (dhandle
, info
, dc
->u
.s_binary
.right
,
5393 case DEMANGLE_COMPONENT_TEMPLATE
:
5398 /* We print this component to get a class name which we can
5399 use. FIXME: This probably won't work if the template uses
5400 template parameters which refer to an outer template. */
5401 p
= cplus_demangle_print (DMGL_PARAMS
| demangle_flags
, dc
, 20, &alc
);
5404 fprintf (stderr
, _("Failed to print demangled template\n"));
5407 dt
= stab_find_tagged_type (dhandle
, info
, p
, strlen (p
),
5413 case DEMANGLE_COMPONENT_SUB_STD
:
5414 return stab_find_tagged_type (dhandle
, info
, dc
->u
.s_string
.string
,
5415 dc
->u
.s_string
.len
, DEBUG_KIND_ILLEGAL
);
5417 case DEMANGLE_COMPONENT_RESTRICT
:
5418 case DEMANGLE_COMPONENT_VOLATILE
:
5419 case DEMANGLE_COMPONENT_CONST
:
5420 case DEMANGLE_COMPONENT_POINTER
:
5421 case DEMANGLE_COMPONENT_REFERENCE
:
5422 dt
= stab_demangle_v3_arg (dhandle
, info
, dc
->u
.s_binary
.left
, NULL
,
5431 case DEMANGLE_COMPONENT_RESTRICT
:
5432 /* FIXME: We have no way to represent restrict. */
5434 case DEMANGLE_COMPONENT_VOLATILE
:
5435 return debug_make_volatile_type (dhandle
, dt
);
5436 case DEMANGLE_COMPONENT_CONST
:
5437 return debug_make_const_type (dhandle
, dt
);
5438 case DEMANGLE_COMPONENT_POINTER
:
5439 return debug_make_pointer_type (dhandle
, dt
);
5440 case DEMANGLE_COMPONENT_REFERENCE
:
5441 return debug_make_reference_type (dhandle
, dt
);
5444 case DEMANGLE_COMPONENT_FUNCTION_TYPE
:
5449 if (dc
->u
.s_binary
.left
== NULL
)
5451 /* In this case the return type is actually unknown.
5452 However, I'm not sure this will ever arise in practice;
5453 normally an unknown return type would only appear at
5454 the top level, which is handled above. */
5455 dt
= debug_make_void_type (dhandle
);
5458 dt
= stab_demangle_v3_arg (dhandle
, info
, dc
->u
.s_binary
.left
, NULL
,
5463 pargs
= stab_demangle_v3_arglist (dhandle
, info
,
5464 dc
->u
.s_binary
.right
,
5472 return debug_make_function_type (dhandle
, dt
, pargs
, varargs
);
5475 case DEMANGLE_COMPONENT_BUILTIN_TYPE
:
5481 /* We print this component in order to find out the type name.
5482 FIXME: Should we instead expose the
5483 demangle_builtin_type_info structure? */
5484 p
= cplus_demangle_print (DMGL_PARAMS
| demangle_flags
, dc
, 20, &alc
);
5487 fprintf (stderr
, _("Couldn't get demangled builtin type\n"));
5491 /* The mangling is based on the type, but does not itself
5492 indicate what the sizes are. So we have to guess. */
5493 if (strcmp (p
, "signed char") == 0)
5494 ret
= debug_make_int_type (dhandle
, 1, false);
5495 else if (strcmp (p
, "bool") == 0)
5496 ret
= debug_make_bool_type (dhandle
, 1);
5497 else if (strcmp (p
, "char") == 0)
5498 ret
= debug_make_int_type (dhandle
, 1, false);
5499 else if (strcmp (p
, "double") == 0)
5500 ret
= debug_make_float_type (dhandle
, 8);
5501 else if (strcmp (p
, "long double") == 0)
5502 ret
= debug_make_float_type (dhandle
, 8);
5503 else if (strcmp (p
, "float") == 0)
5504 ret
= debug_make_float_type (dhandle
, 4);
5505 else if (strcmp (p
, "__float128") == 0)
5506 ret
= debug_make_float_type (dhandle
, 16);
5507 else if (strcmp (p
, "unsigned char") == 0)
5508 ret
= debug_make_int_type (dhandle
, 1, true);
5509 else if (strcmp (p
, "int") == 0)
5510 ret
= debug_make_int_type (dhandle
, 4, false);
5511 else if (strcmp (p
, "unsigned int") == 0)
5512 ret
= debug_make_int_type (dhandle
, 4, true);
5513 else if (strcmp (p
, "long") == 0)
5514 ret
= debug_make_int_type (dhandle
, 4, false);
5515 else if (strcmp (p
, "unsigned long") == 0)
5516 ret
= debug_make_int_type (dhandle
, 4, true);
5517 else if (strcmp (p
, "__int128") == 0)
5518 ret
= debug_make_int_type (dhandle
, 16, false);
5519 else if (strcmp (p
, "unsigned __int128") == 0)
5520 ret
= debug_make_int_type (dhandle
, 16, true);
5521 else if (strcmp (p
, "short") == 0)
5522 ret
= debug_make_int_type (dhandle
, 2, false);
5523 else if (strcmp (p
, "unsigned short") == 0)
5524 ret
= debug_make_int_type (dhandle
, 2, true);
5525 else if (strcmp (p
, "void") == 0)
5526 ret
= debug_make_void_type (dhandle
);
5527 else if (strcmp (p
, "wchar_t") == 0)
5528 ret
= debug_make_int_type (dhandle
, 4, true);
5529 else if (strcmp (p
, "long long") == 0)
5530 ret
= debug_make_int_type (dhandle
, 8, false);
5531 else if (strcmp (p
, "unsigned long long") == 0)
5532 ret
= debug_make_int_type (dhandle
, 8, true);
5533 else if (strcmp (p
, "...") == 0)
5535 if (pvarargs
== NULL
)
5536 fprintf (stderr
, _("Unexpected demangled varargs\n"));
5543 fprintf (stderr
, _("Unrecognized demangled builtin type\n"));