1 /* stabs.c -- Parse stabs debugging information
2 Copyright (C) 1995, 1996, 1997, 1998 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 2 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., 59 Temple Place - Suite 330, 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. */
32 #include "libiberty.h"
37 /* Meaningless definition needs by aout64.h. FIXME. */
38 #define BYTES_IN_WORD 4
40 #include "aout/aout64.h"
41 #include "aout/stab_gnu.h"
45 #define DIR_SEPARATOR '\\'
47 #define DIR_SEPARATOR '/'
51 /* The number of predefined XCOFF types. */
53 #define XCOFF_TYPE_COUNT 34
55 /* This structure is used as a handle so that the stab parsing doesn't
56 need to use any static variables. */
62 /* True if this is stabs in sections. */
64 /* The symbol table. */
66 /* The number of symbols. */
68 /* The accumulated file name string. */
70 /* The value of the last N_SO symbol. */
72 /* The value of the start of the file, so that we can handle file
73 relative N_LBRAC and N_RBRAC symbols. */
74 bfd_vma file_start_offset
;
75 /* The offset of the start of the function, so that we can handle
76 function relative N_LBRAC and N_RBRAC symbols. */
77 bfd_vma function_start_offset
;
78 /* The version number of gcc which compiled the current compilation
79 unit, 0 if not compiled by gcc. */
81 /* Whether an N_OPT symbol was seen that was not generated by gcc,
82 so that we can detect the SunPRO compiler. */
84 /* The main file name. */
86 /* A stack of unfinished N_BINCL files. */
87 struct bincl_file
*bincl_stack
;
88 /* A list of finished N_BINCL files. */
89 struct bincl_file
*bincl_list
;
90 /* Whether we are inside a function or not. */
91 boolean within_function
;
92 /* The address of the end of the function, used if we have seen an
93 N_FUN symbol while in a function. This is -1 if we have not seen
94 an N_FUN (the normal case). */
96 /* The depth of block nesting. */
98 /* List of pending variable definitions. */
99 struct stab_pending_var
*pending
;
100 /* Number of files for which we have types. */
102 /* Lists of types per file. */
103 struct stab_types
**file_types
;
104 /* Predefined XCOFF types. */
105 debug_type xcoff_types
[XCOFF_TYPE_COUNT
];
106 /* Undefined tags. */
107 struct stab_tag
*tags
;
108 /* Set by parse_stab_type if it sees a structure defined as a cross
109 reference to itself. Reset by parse_stab_type otherwise. */
110 boolean self_crossref
;
113 /* A list of these structures is used to hold pending variable
114 definitions seen before the N_LBRAC of a block. */
116 struct stab_pending_var
118 /* Next pending variable definition. */
119 struct stab_pending_var
*next
;
125 enum debug_var_kind kind
;
130 /* A list of these structures is used to hold the types for a single
135 /* Next set of slots for this file. */
136 struct stab_types
*next
;
137 /* Types indexed by type number. */
138 #define STAB_TYPES_SLOTS (16)
139 debug_type types
[STAB_TYPES_SLOTS
];
142 /* We keep a list of undefined tags that we encounter, so that we can
143 fill them in if the tag is later defined. */
147 /* Next undefined tag. */
148 struct stab_tag
*next
;
152 enum debug_type_kind kind
;
153 /* Slot to hold real type when we discover it. If we don't, we fill
154 in an undefined tag type. */
156 /* Indirect type we have created to point at slot. */
160 static char *savestring
PARAMS ((const char *, int));
161 static bfd_vma parse_number
PARAMS ((const char **, boolean
*));
162 static void bad_stab
PARAMS ((const char *));
163 static void warn_stab
PARAMS ((const char *, const char *));
164 static boolean parse_stab_string
165 PARAMS ((PTR
, struct stab_handle
*, int, int, bfd_vma
, const char *));
166 static debug_type parse_stab_type
167 PARAMS ((PTR
, struct stab_handle
*, const char *, const char **,
169 static boolean parse_stab_type_number
170 PARAMS ((const char **, int *));
171 static debug_type parse_stab_range_type
172 PARAMS ((PTR
, struct stab_handle
*, const char *, const char **,
174 static debug_type parse_stab_sun_builtin_type
PARAMS ((PTR
, const char **));
175 static debug_type parse_stab_sun_floating_type
176 PARAMS ((PTR
, const char **));
177 static debug_type parse_stab_enum_type
PARAMS ((PTR
, const char **));
178 static debug_type parse_stab_struct_type
179 PARAMS ((PTR
, struct stab_handle
*, const char *, const char **, boolean
,
181 static boolean parse_stab_baseclasses
182 PARAMS ((PTR
, struct stab_handle
*, const char **, debug_baseclass
**));
183 static boolean parse_stab_struct_fields
184 PARAMS ((PTR
, struct stab_handle
*, const char **, debug_field
**,
186 static boolean parse_stab_cpp_abbrev
187 PARAMS ((PTR
, struct stab_handle
*, const char **, debug_field
*));
188 static boolean parse_stab_one_struct_field
189 PARAMS ((PTR
, struct stab_handle
*, const char **, const char *,
190 debug_field
*, boolean
*));
191 static boolean parse_stab_members
192 PARAMS ((PTR
, struct stab_handle
*, const char *, const char **,
193 const int *, debug_method
**));
194 static debug_type parse_stab_argtypes
195 PARAMS ((PTR
, struct stab_handle
*, debug_type
, const char *, const char *,
196 debug_type
, const char *, boolean
, boolean
, const char **));
197 static boolean parse_stab_tilde_field
198 PARAMS ((PTR
, struct stab_handle
*, const char **, const int *,
199 debug_type
*, boolean
*));
200 static debug_type parse_stab_array_type
201 PARAMS ((PTR
, struct stab_handle
*, const char **, boolean
));
202 static void push_bincl
PARAMS ((struct stab_handle
*, const char *, bfd_vma
));
203 static const char *pop_bincl
PARAMS ((struct stab_handle
*));
204 static boolean find_excl
205 PARAMS ((struct stab_handle
*, const char *, bfd_vma
));
206 static boolean stab_record_variable
207 PARAMS ((PTR
, struct stab_handle
*, const char *, debug_type
,
208 enum debug_var_kind
, bfd_vma
));
209 static boolean stab_emit_pending_vars
PARAMS ((PTR
, struct stab_handle
*));
210 static debug_type
*stab_find_slot
211 PARAMS ((struct stab_handle
*, const int *));
212 static debug_type stab_find_type
213 PARAMS ((PTR
, struct stab_handle
*, const int *));
214 static boolean stab_record_type
215 PARAMS ((PTR
, struct stab_handle
*, const int *, debug_type
));
216 static debug_type stab_xcoff_builtin_type
217 PARAMS ((PTR
, struct stab_handle
*, int));
218 static debug_type stab_find_tagged_type
219 PARAMS ((PTR
, struct stab_handle
*, const char *, int,
220 enum debug_type_kind
));
221 static debug_type
*stab_demangle_argtypes
222 PARAMS ((PTR
, struct stab_handle
*, const char *, boolean
*));
224 /* Save a string in memory. */
227 savestring (start
, len
)
233 ret
= (char *) xmalloc (len
+ 1);
234 memcpy (ret
, start
, len
);
239 /* Read a number from a string. */
242 parse_number (pp
, poverflow
)
249 if (poverflow
!= NULL
)
255 ul
= strtoul (*pp
, (char **) pp
, 0);
256 if (ul
+ 1 != 0 || errno
== 0)
258 /* If bfd_vma is larger than unsigned long, and the number is
259 meant to be negative, we have to make sure that we sign
262 return (bfd_vma
) (bfd_signed_vma
) (long) ul
;
266 /* Note that even though strtoul overflowed, it should have set *pp
267 to the end of the number, which is where we want it. */
269 if (sizeof (bfd_vma
) > sizeof (unsigned long))
274 bfd_vma over
, lastdig
;
278 /* Our own version of strtoul, for a bfd_vma. */
294 if (p
[1] == 'x' || p
[1] == 'X')
306 over
= ((bfd_vma
) (bfd_signed_vma
) -1) / (bfd_vma
) base
;
307 lastdig
= ((bfd_vma
) (bfd_signed_vma
) -1) % (bfd_vma
) base
;
316 if (isdigit ((unsigned char) d
))
318 else if (isupper ((unsigned char) d
))
320 else if (islower ((unsigned char) d
))
328 if (v
> over
|| (v
== over
&& (bfd_vma
) d
> lastdig
))
343 /* If we get here, the number is too large to represent in a
346 if (poverflow
!= NULL
)
349 warn_stab (orig
, _("numeric overflow"));
354 /* Give an error for a bad stab string. */
360 fprintf (stderr
, _("Bad stab: %s\n"), p
);
363 /* Warn about something in a stab string. */
370 fprintf (stderr
, _("Warning: %s: %s\n"), err
, p
);
373 /* Create a handle to parse stabs symbols with. */
377 start_stab (dhandle
, abfd
, sections
, syms
, symcount
)
384 struct stab_handle
*ret
;
386 ret
= (struct stab_handle
*) xmalloc (sizeof *ret
);
387 memset (ret
, 0, sizeof *ret
);
389 ret
->sections
= sections
;
391 ret
->symcount
= symcount
;
393 ret
->file_types
= (struct stab_types
**) xmalloc (sizeof *ret
->file_types
);
394 ret
->file_types
[0] = NULL
;
395 ret
->function_end
= (bfd_vma
) -1;
399 /* When we have processed all the stabs information, we need to go
400 through and fill in all the undefined tags. */
403 finish_stab (dhandle
, handle
)
407 struct stab_handle
*info
= (struct stab_handle
*) handle
;
410 if (info
->within_function
)
412 if (! stab_emit_pending_vars (dhandle
, info
)
413 || ! debug_end_function (dhandle
, info
->function_end
))
415 info
->within_function
= false;
416 info
->function_end
= (bfd_vma
) -1;
419 for (st
= info
->tags
; st
!= NULL
; st
= st
->next
)
421 enum debug_type_kind kind
;
424 if (kind
== DEBUG_KIND_ILLEGAL
)
425 kind
= DEBUG_KIND_STRUCT
;
426 st
->slot
= debug_make_undefined_tagged_type (dhandle
, st
->name
, kind
);
427 if (st
->slot
== DEBUG_TYPE_NULL
)
434 /* Handle a single stabs symbol. */
437 parse_stab (dhandle
, handle
, type
, desc
, value
, string
)
445 struct stab_handle
*info
= (struct stab_handle
*) handle
;
447 /* gcc will emit two N_SO strings per compilation unit, one for the
448 directory name and one for the file name. We just collect N_SO
449 strings as we see them, and start the new compilation unit when
450 we see a non N_SO symbol. */
451 if (info
->so_string
!= NULL
452 && (type
!= N_SO
|| *string
== '\0' || value
!= info
->so_value
))
454 if (! debug_set_filename (dhandle
, info
->so_string
))
456 info
->main_filename
= info
->so_string
;
458 info
->gcc_compiled
= 0;
459 info
->n_opt_found
= false;
461 /* Generally, for stabs in the symbol table, the N_LBRAC and
462 N_RBRAC symbols are relative to the N_SO symbol value. */
463 if (! info
->sections
)
464 info
->file_start_offset
= info
->so_value
;
466 /* We need to reset the mapping from type numbers to types. We
467 can't free the old mapping, because of the use of
468 debug_make_indirect_type. */
470 info
->file_types
= ((struct stab_types
**)
471 xmalloc (sizeof *info
->file_types
));
472 info
->file_types
[0] = NULL
;
474 info
->so_string
= NULL
;
476 /* Now process whatever type we just got. */
486 /* Ignore extra outermost context from SunPRO cc and acc. */
487 if (info
->n_opt_found
&& desc
== 1)
490 if (! info
->within_function
)
492 fprintf (stderr
, _("N_LBRAC not within function\n"));
496 /* Start an inner lexical block. */
497 if (! debug_start_block (dhandle
,
499 + info
->file_start_offset
500 + info
->function_start_offset
)))
503 /* Emit any pending variable definitions. */
504 if (! stab_emit_pending_vars (dhandle
, info
))
511 /* Ignore extra outermost context from SunPRO cc and acc. */
512 if (info
->n_opt_found
&& desc
== 1)
515 /* We shouldn't have any pending variable definitions here, but,
516 if we do, we probably need to emit them before closing the
518 if (! stab_emit_pending_vars (dhandle
, info
))
521 /* End an inner lexical block. */
522 if (! debug_end_block (dhandle
,
524 + info
->file_start_offset
525 + info
->function_start_offset
)))
529 if (info
->block_depth
< 0)
531 fprintf (stderr
, _("Too many N_RBRACs\n"));
537 /* This always ends a function. */
538 if (info
->within_function
)
544 && info
->function_end
!= (bfd_vma
) -1
545 && info
->function_end
< endval
)
546 endval
= info
->function_end
;
547 if (! stab_emit_pending_vars (dhandle
, info
)
548 || ! debug_end_function (dhandle
, endval
))
550 info
->within_function
= false;
551 info
->function_end
= (bfd_vma
) -1;
554 /* An empty string is emitted by gcc at the end of a compilation
559 /* Just accumulate strings until we see a non N_SO symbol. If
560 the string starts with a directory separator or some other
561 form of absolute path specification, we discard the previously
562 accumulated strings. */
563 if (info
->so_string
== NULL
)
564 info
->so_string
= xstrdup (string
);
571 if ( (string
[0] == '/')
572 || (string
[0] == DIR_SEPARATOR
)
573 || ( (DIR_SEPARATOR
== '\\')
574 && (string
[1] == ':')
575 && ( (string
[2] == DIR_SEPARATOR
)
576 || (string
[2] == '/'))))
577 info
->so_string
= xstrdup (string
);
579 info
->so_string
= concat (info
->so_string
, string
,
580 (const char *) NULL
);
584 info
->so_value
= value
;
589 /* Start an include file. */
590 if (! debug_start_source (dhandle
, string
))
595 /* Start an include file which may be replaced. */
596 push_bincl (info
, string
, value
);
597 if (! debug_start_source (dhandle
, string
))
602 /* End an N_BINCL include. */
603 if (! debug_start_source (dhandle
, pop_bincl (info
)))
608 /* This is a duplicate of a header file named by N_BINCL which
609 was eliminated by the linker. */
610 if (! find_excl (info
, string
, value
))
615 if (! debug_record_line (dhandle
, desc
,
616 value
+ info
->function_start_offset
))
621 if (! debug_start_common_block (dhandle
, string
))
626 if (! debug_end_common_block (dhandle
, string
))
633 if (info
->within_function
)
635 /* This always marks the end of a function; we don't
636 need to worry about info->function_end. */
638 value
+= info
->function_start_offset
;
639 if (! stab_emit_pending_vars (dhandle
, info
)
640 || ! debug_end_function (dhandle
, value
))
642 info
->within_function
= false;
643 info
->function_end
= (bfd_vma
) -1;
648 /* A const static symbol in the .text section will have an N_FUN
649 entry. We need to use these to mark the end of the function,
650 in case we are looking at gcc output before it was changed to
651 always emit an empty N_FUN. We can't call debug_end_function
652 here, because it might be a local static symbol. */
653 if (info
->within_function
654 && (info
->function_end
== (bfd_vma
) -1
655 || value
< info
->function_end
))
656 info
->function_end
= value
;
659 /* FIXME: gdb checks the string for N_STSYM, N_LCSYM or N_ROSYM
660 symbols, and if it does not start with :S, gdb relocates the
661 value to the start of the section. gcc always seems to use
662 :S, so we don't worry about this. */
668 colon
= strchr (string
, ':');
670 && (colon
[1] == 'f' || colon
[1] == 'F'))
672 if (info
->within_function
)
677 if (info
->function_end
!= (bfd_vma
) -1
678 && info
->function_end
< endval
)
679 endval
= info
->function_end
;
680 if (! stab_emit_pending_vars (dhandle
, info
)
681 || ! debug_end_function (dhandle
, endval
))
683 info
->function_end
= (bfd_vma
) -1;
685 /* For stabs in sections, line numbers and block addresses
686 are offsets from the start of the function. */
688 info
->function_start_offset
= value
;
689 info
->within_function
= true;
692 if (! parse_stab_string (dhandle
, info
, type
, desc
, value
, string
))
698 if (string
!= NULL
&& strcmp (string
, "gcc2_compiled.") == 0)
699 info
->gcc_compiled
= 2;
700 else if (string
!= NULL
&& strcmp (string
, "gcc_compiled.") == 0)
701 info
->gcc_compiled
= 1;
703 info
->n_opt_found
= true;
715 /* Parse the stabs string. */
718 parse_stab_string (dhandle
, info
, stabtype
, desc
, value
, string
)
720 struct stab_handle
*info
;
731 boolean self_crossref
;
735 p
= strchr (string
, ':');
750 /* GCC 2.x puts the line number in desc. SunOS apparently puts in
751 the number of bytes occupied by a type or object, which we
753 if (info
->gcc_compiled
>= 2)
758 /* FIXME: Sometimes the special C++ names start with '.'. */
760 if (string
[0] == '$')
768 /* Was: name = "vptr"; */
774 /* This was an anonymous type that was never fixed up. */
777 /* SunPRO (3.0 at least) static variable encoding. */
780 warn_stab (string
, _("unknown C++ encoded name"));
787 if (p
== string
|| (string
[0] == ' ' && p
== string
+ 1))
790 name
= savestring (string
, p
- string
);
794 if (isdigit ((unsigned char) *p
) || *p
== '(' || *p
== '-')
802 /* c is a special case, not followed by a type-number.
803 SYMBOL:c=iVALUE for an integer constant symbol.
804 SYMBOL:c=rVALUE for a floating constant symbol.
805 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
806 e.g. "b:c=e6,0" for "const b = blob1"
807 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
817 /* Floating point constant. */
818 if (! debug_record_float_const (dhandle
, name
, atof (p
)))
822 /* Integer constant. */
823 /* Defining integer constants this way is kind of silly,
824 since 'e' constants allows the compiler to give not only
825 the value, but the type as well. C has at least int,
826 long, unsigned int, and long long as constant types;
827 other languages probably should have at least unsigned as
828 well as signed constants. */
829 if (! debug_record_int_const (dhandle
, name
, atoi (p
)))
833 /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value
834 can be represented as integral.
835 e.g. "b:c=e6,0" for "const b = blob1"
836 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
837 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
,
838 &p
, (debug_type
**) NULL
);
839 if (dtype
== DEBUG_TYPE_NULL
)
846 if (! debug_record_typed_const (dhandle
, name
, dtype
, atoi (p
)))
857 /* The name of a caught exception. */
858 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
,
859 &p
, (debug_type
**) NULL
);
860 if (dtype
== DEBUG_TYPE_NULL
)
862 if (! debug_record_label (dhandle
, name
, dtype
, value
))
868 /* A function definition. */
869 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
870 (debug_type
**) NULL
);
871 if (dtype
== DEBUG_TYPE_NULL
)
873 if (! debug_record_function (dhandle
, name
, dtype
, type
== 'F', value
))
876 /* Sun acc puts declared types of arguments here. We don't care
877 about their actual types (FIXME -- we should remember the whole
878 function prototype), but the list may define some new types
879 that we have to remember, so we must scan it now. */
883 if (parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
884 (debug_type
**) NULL
)
897 /* A global symbol. The value must be extracted from the
899 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
900 (debug_type
**) NULL
);
901 if (dtype
== DEBUG_TYPE_NULL
)
903 leading
= bfd_get_symbol_leading_char (info
->abfd
);
904 for (c
= info
->symcount
, ps
= info
->syms
; c
> 0; --c
, ++ps
)
908 n
= bfd_asymbol_name (*ps
);
909 if (leading
!= '\0' && *n
== leading
)
911 if (*n
== *name
&& strcmp (n
, name
) == 0)
915 value
= bfd_asymbol_value (*ps
);
916 if (! stab_record_variable (dhandle
, info
, name
, dtype
, DEBUG_GLOBAL
,
922 /* This case is faked by a conditional above, when there is no
923 code letter in the dbx data. Dbx data never actually
927 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
928 (debug_type
**) NULL
);
929 if (dtype
== DEBUG_TYPE_NULL
)
931 if (! stab_record_variable (dhandle
, info
, name
, dtype
, DEBUG_LOCAL
,
937 /* A function parameter. */
939 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
940 (debug_type
**) NULL
);
943 /* pF is a two-letter code that means a function parameter in
944 Fortran. The type-number specifies the type of the return
945 value. Translate it into a pointer-to-function type. */
947 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
948 (debug_type
**) NULL
);
949 if (dtype
!= DEBUG_TYPE_NULL
)
953 ftype
= debug_make_function_type (dhandle
, dtype
,
954 (debug_type
*) NULL
, false);
955 dtype
= debug_make_pointer_type (dhandle
, ftype
);
958 if (dtype
== DEBUG_TYPE_NULL
)
960 if (! debug_record_parameter (dhandle
, name
, dtype
, DEBUG_PARM_STACK
,
964 /* FIXME: At this point gdb considers rearranging the parameter
965 address on a big endian machine if it is smaller than an int.
966 We have no way to do that, since we don't really know much
972 if (stabtype
== N_FUN
)
974 /* Prototype of a function referenced by this file. */
978 if (parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
979 (debug_type
**) NULL
)
987 /* Parameter which is in a register. */
988 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
989 (debug_type
**) NULL
);
990 if (dtype
== DEBUG_TYPE_NULL
)
992 if (! debug_record_parameter (dhandle
, name
, dtype
, DEBUG_PARM_REG
,
998 /* Register variable (either global or local). */
999 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
1000 (debug_type
**) NULL
);
1001 if (dtype
== DEBUG_TYPE_NULL
)
1003 if (! stab_record_variable (dhandle
, info
, name
, dtype
, DEBUG_REGISTER
,
1007 /* FIXME: At this point gdb checks to combine pairs of 'p' and
1008 'r' stabs into a single 'P' stab. */
1013 /* Static symbol at top level of file */
1014 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
1015 (debug_type
**) NULL
);
1016 if (dtype
== DEBUG_TYPE_NULL
)
1018 if (! stab_record_variable (dhandle
, info
, name
, dtype
, DEBUG_STATIC
,
1025 dtype
= parse_stab_type (dhandle
, info
, name
, &p
, &slot
);
1026 if (dtype
== DEBUG_TYPE_NULL
)
1030 /* A nameless type. Nothing to do. */
1034 dtype
= debug_name_type (dhandle
, name
, dtype
);
1035 if (dtype
== DEBUG_TYPE_NULL
)
1044 /* Struct, union, or enum tag. For GNU C++, this can be be followed
1045 by 't' which means we are typedef'ing it as well. */
1049 /* FIXME: gdb sets synonym to true if the current language
1058 dtype
= parse_stab_type (dhandle
, info
, name
, &p
, &slot
);
1059 if (dtype
== DEBUG_TYPE_NULL
)
1064 /* INFO->SELF_CROSSREF is set by parse_stab_type if this type is
1065 a cross reference to itself. These are generated by some
1067 self_crossref
= info
->self_crossref
;
1069 dtype
= debug_tag_type (dhandle
, name
, dtype
);
1070 if (dtype
== DEBUG_TYPE_NULL
)
1075 /* See if we have a cross reference to this tag which we can now
1076 fill in. Avoid filling in a cross reference to ourselves,
1077 because that would lead to circular debugging information. */
1078 if (! self_crossref
)
1080 register struct stab_tag
**pst
;
1082 for (pst
= &info
->tags
; *pst
!= NULL
; pst
= &(*pst
)->next
)
1084 if ((*pst
)->name
[0] == name
[0]
1085 && strcmp ((*pst
)->name
, name
) == 0)
1087 (*pst
)->slot
= dtype
;
1088 *pst
= (*pst
)->next
;
1096 dtype
= debug_name_type (dhandle
, name
, dtype
);
1097 if (dtype
== DEBUG_TYPE_NULL
)
1107 /* Static symbol of local scope */
1108 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
1109 (debug_type
**) NULL
);
1110 if (dtype
== DEBUG_TYPE_NULL
)
1112 /* FIXME: gdb checks os9k_stabs here. */
1113 if (! stab_record_variable (dhandle
, info
, name
, dtype
,
1114 DEBUG_LOCAL_STATIC
, value
))
1119 /* Reference parameter. */
1120 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
1121 (debug_type
**) NULL
);
1122 if (dtype
== DEBUG_TYPE_NULL
)
1124 if (! debug_record_parameter (dhandle
, name
, dtype
, DEBUG_PARM_REFERENCE
,
1130 /* Reference parameter which is in a register. */
1131 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
1132 (debug_type
**) NULL
);
1133 if (dtype
== DEBUG_TYPE_NULL
)
1135 if (! debug_record_parameter (dhandle
, name
, dtype
, DEBUG_PARM_REF_REG
,
1141 /* This is used by Sun FORTRAN for "function result value".
1142 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
1143 that Pascal uses it too, but when I tried it Pascal used
1144 "x:3" (local symbol) instead. */
1145 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
1146 (debug_type
**) NULL
);
1147 if (dtype
== DEBUG_TYPE_NULL
)
1149 if (! stab_record_variable (dhandle
, info
, name
, dtype
, DEBUG_LOCAL
,
1159 /* FIXME: gdb converts structure values to structure pointers in a
1160 couple of cases, depending upon the target. */
1165 /* Parse a stabs type. The typename argument is non-NULL if this is a
1166 typedef or a tag definition. The pp argument points to the stab
1167 string, and is updated. The slotp argument points to a place to
1168 store the slot used if the type is being defined. */
1171 parse_stab_type (dhandle
, info
, typename
, pp
, slotp
)
1173 struct stab_handle
*info
;
1174 const char *typename
;
1193 info
->self_crossref
= false;
1195 /* Read type number if present. The type number may be omitted.
1196 for instance in a two-dimensional array declared with type
1197 "ar1;1;10;ar1;1;10;4". */
1198 if (! isdigit ((unsigned char) **pp
) && **pp
!= '(' && **pp
!= '-')
1200 /* 'typenums=' not present, type is anonymous. Read and return
1201 the definition, but don't put it in the type vector. */
1202 typenums
[0] = typenums
[1] = -1;
1206 if (! parse_stab_type_number (pp
, typenums
))
1207 return DEBUG_TYPE_NULL
;
1211 /* Type is not being defined here. Either it already
1212 exists, or this is a forward reference to it. */
1213 return stab_find_type (dhandle
, info
, typenums
);
1216 /* Only set the slot if the type is being defined. This means
1217 that the mapping from type numbers to types will only record
1218 the name of the typedef which defines a type. If we don't do
1219 this, then something like
1222 will record that i is of type foo. Unfortunately, stabs
1223 information is ambiguous about variable types. For this code,
1227 the stabs information records both i and j as having the same
1228 type. This could be fixed by patching the compiler. */
1229 if (slotp
!= NULL
&& typenums
[0] >= 0 && typenums
[1] >= 0)
1230 *slotp
= stab_find_slot (info
, typenums
);
1232 /* Type is being defined here. */
1238 const char *p
= *pp
+ 1;
1241 if (isdigit ((unsigned char) *p
) || *p
== '(' || *p
== '-')
1247 /* Type attributes. */
1250 for (; *p
!= ';'; ++p
)
1255 return DEBUG_TYPE_NULL
;
1263 size
= atoi (attr
+ 1);
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. */
1295 code
= DEBUG_KIND_STRUCT
;
1298 code
= DEBUG_KIND_UNION
;
1301 code
= DEBUG_KIND_ENUM
;
1304 /* Complain and keep going, so compilers can invent new
1305 cross-reference types. */
1306 warn_stab (orig
, _("unrecognized cross reference type"));
1307 code
= DEBUG_KIND_STRUCT
;
1312 q1
= strchr (*pp
, '<');
1313 p
= strchr (*pp
, ':');
1317 return DEBUG_TYPE_NULL
;
1319 while (q1
!= NULL
&& p
> q1
&& p
[1] == ':')
1321 q2
= strchr (q1
, '>');
1322 if (q2
== NULL
|| q2
< p
)
1325 p
= strchr (p
, ':');
1329 return DEBUG_TYPE_NULL
;
1333 /* Some versions of g++ can emit stabs like
1335 which define structures in terms of themselves. We need to
1336 tell the caller to avoid building a circular structure. */
1337 if (typename
!= NULL
1338 && strncmp (typename
, *pp
, p
- *pp
) == 0
1339 && typename
[p
- *pp
] == '\0')
1340 info
->self_crossref
= true;
1342 dtype
= stab_find_tagged_type (dhandle
, info
, *pp
, p
- *pp
, code
);
1364 /* This type is defined as another type. */
1369 /* Peek ahead at the number to detect void. */
1370 if (! parse_stab_type_number (pp
, xtypenums
))
1371 return DEBUG_TYPE_NULL
;
1373 if (typenums
[0] == xtypenums
[0] && typenums
[1] == xtypenums
[1])
1375 /* This type is being defined as itself, which means that
1377 dtype
= debug_make_void_type (dhandle
);
1383 /* Go back to the number and have parse_stab_type get it.
1384 This means that we can deal with something like
1385 t(1,2)=(3,4)=... which the Lucid compiler uses. */
1386 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
,
1387 pp
, (debug_type
**) NULL
);
1388 if (dtype
== DEBUG_TYPE_NULL
)
1389 return DEBUG_TYPE_NULL
;
1392 if (typenums
[0] != -1)
1394 if (! stab_record_type (dhandle
, info
, typenums
, dtype
))
1395 return DEBUG_TYPE_NULL
;
1402 dtype
= debug_make_pointer_type (dhandle
,
1403 parse_stab_type (dhandle
, info
,
1404 (const char *) NULL
,
1406 (debug_type
**) NULL
));
1410 /* Reference to another type. */
1411 dtype
= (debug_make_reference_type
1413 parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
1414 (debug_type
**) NULL
)));
1418 /* Function returning another type. */
1419 /* FIXME: gdb checks os9k_stabs here. */
1420 dtype
= (debug_make_function_type
1422 parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
1423 (debug_type
**) NULL
),
1424 (debug_type
*) NULL
, false));
1428 /* Const qualifier on some type (Sun). */
1429 /* FIXME: gdb accepts 'c' here if os9k_stabs. */
1430 dtype
= debug_make_const_type (dhandle
,
1431 parse_stab_type (dhandle
, info
,
1432 (const char *) NULL
,
1434 (debug_type
**) NULL
));
1438 /* Volatile qual on some type (Sun). */
1439 /* FIXME: gdb accepts 'i' here if os9k_stabs. */
1440 dtype
= (debug_make_volatile_type
1442 parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
1443 (debug_type
**) NULL
)));
1447 /* Offset (class & variable) type. This is used for a pointer
1448 relative to an object. */
1455 domain
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
1456 (debug_type
**) NULL
);
1457 if (domain
== DEBUG_TYPE_NULL
)
1458 return DEBUG_TYPE_NULL
;
1463 return DEBUG_TYPE_NULL
;
1467 memtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
1468 (debug_type
**) NULL
);
1469 if (memtype
== DEBUG_TYPE_NULL
)
1470 return DEBUG_TYPE_NULL
;
1472 dtype
= debug_make_offset_type (dhandle
, domain
, memtype
);
1477 /* Method (class & fn) type. */
1480 debug_type return_type
;
1483 return_type
= parse_stab_type (dhandle
, info
, (const char *) NULL
,
1484 pp
, (debug_type
**) NULL
);
1485 if (return_type
== DEBUG_TYPE_NULL
)
1486 return DEBUG_TYPE_NULL
;
1490 return DEBUG_TYPE_NULL
;
1493 dtype
= debug_make_method_type (dhandle
, return_type
,
1495 (debug_type
*) NULL
, false);
1500 debug_type return_type
;
1506 domain
= parse_stab_type (dhandle
, info
, (const char *) NULL
,
1507 pp
, (debug_type
**) NULL
);
1508 if (domain
== DEBUG_TYPE_NULL
)
1509 return DEBUG_TYPE_NULL
;
1514 return DEBUG_TYPE_NULL
;
1518 return_type
= parse_stab_type (dhandle
, info
, (const char *) NULL
,
1519 pp
, (debug_type
**) NULL
);
1520 if (return_type
== DEBUG_TYPE_NULL
)
1521 return DEBUG_TYPE_NULL
;
1524 args
= (debug_type
*) xmalloc (alloc
* sizeof *args
);
1531 return DEBUG_TYPE_NULL
;
1538 args
= ((debug_type
*)
1539 xrealloc ((PTR
) args
, alloc
* sizeof *args
));
1542 args
[n
] = parse_stab_type (dhandle
, info
, (const char *) NULL
,
1543 pp
, (debug_type
**) NULL
);
1544 if (args
[n
] == DEBUG_TYPE_NULL
)
1545 return DEBUG_TYPE_NULL
;
1550 /* If the last type is not void, then this function takes a
1551 variable number of arguments. Otherwise, we must strip
1554 || debug_get_type_kind (dhandle
, args
[n
- 1]) != DEBUG_KIND_VOID
)
1562 args
[n
] = DEBUG_TYPE_NULL
;
1564 dtype
= debug_make_method_type (dhandle
, return_type
, domain
, args
,
1571 dtype
= parse_stab_range_type (dhandle
, info
, typename
, pp
, typenums
);
1575 /* FIXME: gdb checks os9k_stabs here. */
1576 /* Sun ACC builtin int type. */
1577 dtype
= parse_stab_sun_builtin_type (dhandle
, pp
);
1581 /* Sun ACC builtin float type. */
1582 dtype
= parse_stab_sun_floating_type (dhandle
, pp
);
1586 /* Enumeration type. */
1587 dtype
= parse_stab_enum_type (dhandle
, pp
);
1592 /* Struct or union type. */
1593 dtype
= parse_stab_struct_type (dhandle
, info
, typename
, pp
,
1594 descriptor
== 's', typenums
);
1602 return DEBUG_TYPE_NULL
;
1606 dtype
= parse_stab_array_type (dhandle
, info
, pp
, stringp
);
1610 dtype
= debug_make_set_type (dhandle
,
1611 parse_stab_type (dhandle
, info
,
1612 (const char *) NULL
,
1614 (debug_type
**) NULL
),
1620 return DEBUG_TYPE_NULL
;
1623 if (dtype
== DEBUG_TYPE_NULL
)
1624 return DEBUG_TYPE_NULL
;
1626 if (typenums
[0] != -1)
1628 if (! stab_record_type (dhandle
, info
, typenums
, dtype
))
1629 return DEBUG_TYPE_NULL
;
1634 if (! debug_record_type_size (dhandle
, dtype
, (unsigned int) size
))
1641 /* Read a number by which a type is referred to in dbx data, or
1642 perhaps read a pair (FILENUM, TYPENUM) in parentheses. Just a
1643 single number N is equivalent to (0,N). Return the two numbers by
1644 storing them in the vector TYPENUMS. */
1647 parse_stab_type_number (pp
, typenums
)
1658 typenums
[1] = (int) parse_number (pp
, (boolean
*) NULL
);
1663 typenums
[0] = (int) parse_number (pp
, (boolean
*) NULL
);
1670 typenums
[1] = (int) parse_number (pp
, (boolean
*) NULL
);
1682 /* Parse a range type. */
1685 parse_stab_range_type (dhandle
, info
, typename
, pp
, typenums
)
1687 struct stab_handle
*info
;
1688 const char *typename
;
1690 const int *typenums
;
1694 boolean self_subrange
;
1695 debug_type index_type
;
1696 const char *s2
, *s3
;
1697 bfd_signed_vma n2
, n3
;
1702 index_type
= DEBUG_TYPE_NULL
;
1704 /* First comes a type we are a subrange of.
1705 In C it is usually 0, 1 or the type being defined. */
1706 if (! parse_stab_type_number (pp
, rangenums
))
1707 return DEBUG_TYPE_NULL
;
1709 self_subrange
= (rangenums
[0] == typenums
[0]
1710 && rangenums
[1] == typenums
[1]);
1715 index_type
= parse_stab_type (dhandle
, info
, (const char *) NULL
,
1716 pp
, (debug_type
**) NULL
);
1717 if (index_type
== DEBUG_TYPE_NULL
)
1718 return DEBUG_TYPE_NULL
;
1724 /* The remaining two operands are usually lower and upper bounds of
1725 the range. But in some special cases they mean something else. */
1727 n2
= parse_number (pp
, &ov2
);
1731 return DEBUG_TYPE_NULL
;
1736 n3
= parse_number (pp
, &ov3
);
1740 return DEBUG_TYPE_NULL
;
1746 /* gcc will emit range stabs for long long types. Handle this
1747 as a special case. FIXME: This needs to be more general. */
1748 #define LLLOW "01000000000000000000000;"
1749 #define LLHIGH "0777777777777777777777;"
1750 #define ULLHIGH "01777777777777777777777;"
1751 if (index_type
== DEBUG_TYPE_NULL
)
1753 if (strncmp (s2
, LLLOW
, sizeof LLLOW
- 1) == 0
1754 && strncmp (s3
, LLHIGH
, sizeof LLHIGH
- 1) == 0)
1755 return debug_make_int_type (dhandle
, 8, false);
1758 && strncmp (s3
, ULLHIGH
, sizeof ULLHIGH
- 1) == 0)
1759 return debug_make_int_type (dhandle
, 8, true);
1762 warn_stab (orig
, _("numeric overflow"));
1765 if (index_type
== DEBUG_TYPE_NULL
)
1767 /* A type defined as a subrange of itself, with both bounds 0,
1769 if (self_subrange
&& n2
== 0 && n3
== 0)
1770 return debug_make_void_type (dhandle
);
1772 /* A type defined as a subrange of itself, with n2 positive and
1773 n3 zero, is a complex type, and n2 is the number of bytes. */
1774 if (self_subrange
&& n3
== 0 && n2
> 0)
1775 return debug_make_complex_type (dhandle
, n2
);
1777 /* If n3 is zero and n2 is positive, this is a floating point
1778 type, and n2 is the number of bytes. */
1779 if (n3
== 0 && n2
> 0)
1780 return debug_make_float_type (dhandle
, n2
);
1782 /* If the upper bound is -1, this is an unsigned int. */
1783 if (n2
== 0 && n3
== -1)
1785 /* When gcc is used with -gstabs, but not -gstabs+, it will emit
1786 long long int:t6=r1;0;-1;
1787 long long unsigned int:t7=r1;0;-1;
1788 We hack here to handle this reasonably. */
1789 if (typename
!= NULL
)
1791 if (strcmp (typename
, "long long int") == 0)
1792 return debug_make_int_type (dhandle
, 8, false);
1793 else if (strcmp (typename
, "long long unsigned int") == 0)
1794 return debug_make_int_type (dhandle
, 8, true);
1796 /* FIXME: The size here really depends upon the target. */
1797 return debug_make_int_type (dhandle
, 4, true);
1800 /* A range of 0 to 127 is char. */
1801 if (self_subrange
&& n2
== 0 && n3
== 127)
1802 return debug_make_int_type (dhandle
, 1, false);
1804 /* FIXME: gdb checks for the language CHILL here. */
1809 return debug_make_int_type (dhandle
, - n3
, true);
1810 else if (n3
== 0xff)
1811 return debug_make_int_type (dhandle
, 1, true);
1812 else if (n3
== 0xffff)
1813 return debug_make_int_type (dhandle
, 2, true);
1814 else if (n3
== 0xffffffff)
1815 return debug_make_int_type (dhandle
, 4, true);
1817 else if (n3
== ((((bfd_vma
) 0xffffffff) << 32) | 0xffffffff))
1818 return debug_make_int_type (dhandle
, 8, true);
1823 && (self_subrange
|| n2
== -8))
1824 return debug_make_int_type (dhandle
, - n2
, true);
1825 else if (n2
== - n3
- 1 || n2
== n3
+ 1)
1828 return debug_make_int_type (dhandle
, 1, false);
1829 else if (n3
== 0x7fff)
1830 return debug_make_int_type (dhandle
, 2, false);
1831 else if (n3
== 0x7fffffff)
1832 return debug_make_int_type (dhandle
, 4, false);
1834 else if (n3
== ((((bfd_vma
) 0x7fffffff) << 32) | 0xffffffff))
1835 return debug_make_int_type (dhandle
, 8, false);
1840 /* At this point I don't have the faintest idea how to deal with a
1841 self_subrange type; I'm going to assume that this is used as an
1842 idiom, and that all of them are special cases. So . . . */
1846 return DEBUG_TYPE_NULL
;
1849 index_type
= stab_find_type (dhandle
, info
, rangenums
);
1850 if (index_type
== DEBUG_TYPE_NULL
)
1852 /* Does this actually ever happen? Is that why we are worrying
1853 about dealing with it rather than just calling error_type? */
1854 warn_stab (orig
, _("missing index type"));
1855 index_type
= debug_make_int_type (dhandle
, 4, false);
1858 return debug_make_range_type (dhandle
, index_type
, n2
, n3
);
1861 /* Sun's ACC uses a somewhat saner method for specifying the builtin
1862 typedefs in every file (for int, long, etc):
1864 type = b <signed> <width>; <offset>; <nbits>
1865 signed = u or s. Possible c in addition to u or s (for char?).
1866 offset = offset from high order bit to start bit of type.
1867 width is # bytes in object of this type, nbits is # bits in type.
1869 The width/offset stuff appears to be for small objects stored in
1870 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
1874 parse_stab_sun_builtin_type (dhandle
, pp
)
1894 return DEBUG_TYPE_NULL
;
1898 /* For some odd reason, all forms of char put a c here. This is strange
1899 because no other type has this honor. We can safely ignore this because
1900 we actually determine 'char'acterness by the number of bits specified in
1905 /* The first number appears to be the number of bytes occupied
1906 by this type, except that unsigned short is 4 instead of 2.
1907 Since this information is redundant with the third number,
1908 we will ignore it. */
1909 (void) parse_number (pp
, (boolean
*) NULL
);
1913 return DEBUG_TYPE_NULL
;
1917 /* The second number is always 0, so ignore it too. */
1918 (void) parse_number (pp
, (boolean
*) NULL
);
1922 return DEBUG_TYPE_NULL
;
1926 /* The third number is the number of bits for this type. */
1927 bits
= parse_number (pp
, (boolean
*) NULL
);
1929 /* The type *should* end with a semicolon. If it are embedded
1930 in a larger type the semicolon may be the only way to know where
1931 the type ends. If this type is at the end of the stabstring we
1932 can deal with the omitted semicolon (but we don't have to like
1933 it). Don't bother to complain(), Sun's compiler omits the semicolon
1939 return debug_make_void_type (dhandle
);
1941 return debug_make_int_type (dhandle
, bits
/ 8, unsignedp
);
1944 /* Parse a builtin floating type generated by the Sun compiler. */
1947 parse_stab_sun_floating_type (dhandle
, pp
)
1957 /* The first number has more details about the type, for example
1959 details
= parse_number (pp
, (boolean
*) NULL
);
1963 return DEBUG_TYPE_NULL
;
1966 /* The second number is the number of bytes occupied by this type */
1967 bytes
= parse_number (pp
, (boolean
*) NULL
);
1971 return DEBUG_TYPE_NULL
;
1974 if (details
== NF_COMPLEX
1975 || details
== NF_COMPLEX16
1976 || details
== NF_COMPLEX32
)
1977 return debug_make_complex_type (dhandle
, bytes
);
1979 return debug_make_float_type (dhandle
, bytes
);
1982 /* Handle an enum type. */
1985 parse_stab_enum_type (dhandle
, pp
)
1991 bfd_signed_vma
*values
;
1997 /* FIXME: gdb checks os9k_stabs here. */
1999 /* The aix4 compiler emits an extra field before the enum members;
2000 my guess is it's a type of some sort. Just ignore it. */
2008 /* Read the value-names and their values.
2009 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
2010 A semicolon or comma instead of a NAME means the end. */
2012 names
= (const char **) xmalloc (alloc
* sizeof *names
);
2013 values
= (bfd_signed_vma
*) xmalloc (alloc
* sizeof *values
);
2015 while (**pp
!= '\0' && **pp
!= ';' && **pp
!= ',')
2025 name
= savestring (*pp
, p
- *pp
);
2028 val
= (bfd_signed_vma
) parse_number (pp
, (boolean
*) NULL
);
2032 return DEBUG_TYPE_NULL
;
2039 names
= ((const char **)
2040 xrealloc ((PTR
) names
, alloc
* sizeof *names
));
2041 values
= ((bfd_signed_vma
*)
2042 xrealloc ((PTR
) values
, alloc
* sizeof *values
));
2056 return debug_make_enum_type (dhandle
, names
, values
);
2059 /* Read the description of a structure (or union type) and return an object
2060 describing the type.
2062 PP points to a character pointer that points to the next unconsumed token
2063 in the the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
2064 *PP will point to "4a:1,0,32;;". */
2067 parse_stab_struct_type (dhandle
, info
, tagname
, pp
, structp
, typenums
)
2069 struct stab_handle
*info
;
2070 const char *tagname
;
2073 const int *typenums
;
2077 debug_baseclass
*baseclasses
;
2078 debug_field
*fields
;
2080 debug_method
*methods
;
2081 debug_type vptrbase
;
2087 size
= parse_number (pp
, (boolean
*) NULL
);
2089 /* Get the other information. */
2090 if (! parse_stab_baseclasses (dhandle
, info
, pp
, &baseclasses
)
2091 || ! parse_stab_struct_fields (dhandle
, info
, pp
, &fields
, &statics
)
2092 || ! parse_stab_members (dhandle
, info
, tagname
, pp
, typenums
, &methods
)
2093 || ! parse_stab_tilde_field (dhandle
, info
, pp
, typenums
, &vptrbase
,
2095 return DEBUG_TYPE_NULL
;
2098 && baseclasses
== NULL
2100 && vptrbase
== DEBUG_TYPE_NULL
2102 return debug_make_struct_type (dhandle
, structp
, size
, fields
);
2104 return debug_make_object_type (dhandle
, structp
, size
, fields
, baseclasses
,
2105 methods
, vptrbase
, ownvptr
);
2108 /* The stabs for C++ derived classes contain baseclass information which
2109 is marked by a '!' character after the total size. This function is
2110 called when we encounter the baseclass marker, and slurps up all the
2111 baseclass information.
2113 Immediately following the '!' marker is the number of base classes that
2114 the class is derived from, followed by information for each base class.
2115 For each base class, there are two visibility specifiers, a bit offset
2116 to the base class information within the derived class, a reference to
2117 the type for the base class, and a terminating semicolon.
2119 A typical example, with two base classes, would be "!2,020,19;0264,21;".
2121 Baseclass information marker __________________|| | | | | | |
2122 Number of baseclasses __________________________| | | | | | |
2123 Visibility specifiers (2) ________________________| | | | | |
2124 Offset in bits from start of class _________________| | | | |
2125 Type number for base class ___________________________| | | |
2126 Visibility specifiers (2) _______________________________| | |
2127 Offset in bits from start of class ________________________| |
2128 Type number of base class ____________________________________|
2130 Return true for success, false for failure. */
2133 parse_stab_baseclasses (dhandle
, info
, pp
, retp
)
2135 struct stab_handle
*info
;
2137 debug_baseclass
**retp
;
2141 debug_baseclass
*classes
;
2149 /* No base classes. */
2154 c
= (unsigned int) parse_number (pp
, (boolean
*) NULL
);
2163 classes
= (debug_baseclass
*) xmalloc ((c
+ 1) * sizeof (**retp
));
2165 for (i
= 0; i
< c
; i
++)
2168 enum debug_visibility visibility
;
2181 warn_stab (orig
, _("unknown virtual character for baseclass"));
2190 visibility
= DEBUG_VISIBILITY_PRIVATE
;
2193 visibility
= DEBUG_VISIBILITY_PROTECTED
;
2196 visibility
= DEBUG_VISIBILITY_PUBLIC
;
2199 warn_stab (orig
, _("unknown visibility character for baseclass"));
2200 visibility
= DEBUG_VISIBILITY_PUBLIC
;
2205 /* The remaining value is the bit offset of the portion of the
2206 object corresponding to this baseclass. Always zero in the
2207 absence of multiple inheritance. */
2208 bitpos
= parse_number (pp
, (boolean
*) NULL
);
2216 type
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
2217 (debug_type
**) NULL
);
2218 if (type
== DEBUG_TYPE_NULL
)
2221 classes
[i
] = debug_make_baseclass (dhandle
, type
, bitpos
, virtual,
2223 if (classes
[i
] == DEBUG_BASECLASS_NULL
)
2231 classes
[i
] = DEBUG_BASECLASS_NULL
;
2238 /* Read struct or class data fields. They have the form:
2240 NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
2242 At the end, we see a semicolon instead of a field.
2244 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
2247 The optional VISIBILITY is one of:
2249 '/0' (VISIBILITY_PRIVATE)
2250 '/1' (VISIBILITY_PROTECTED)
2251 '/2' (VISIBILITY_PUBLIC)
2252 '/9' (VISIBILITY_IGNORE)
2254 or nothing, for C style fields with public visibility.
2256 Returns 1 for success, 0 for failure. */
2259 parse_stab_struct_fields (dhandle
, info
, pp
, retp
, staticsp
)
2261 struct stab_handle
*info
;
2268 debug_field
*fields
;
2279 fields
= (debug_field
*) xmalloc (alloc
* sizeof *fields
);
2282 /* FIXME: gdb checks os9k_stabs here. */
2286 /* Add 1 to c to leave room for NULL pointer at end. */
2290 fields
= ((debug_field
*)
2291 xrealloc ((PTR
) fields
, alloc
* sizeof *fields
));
2294 /* If it starts with CPLUS_MARKER it is a special abbreviation,
2295 unless the CPLUS_MARKER is followed by an underscore, in
2296 which case it is just the name of an anonymous type, which we
2297 should handle like any other type name. We accept either '$'
2298 or '.', because a field name can never contain one of these
2299 characters except as a CPLUS_MARKER. */
2301 if ((*p
== '$' || *p
== '.') && p
[1] != '_')
2304 if (! parse_stab_cpp_abbrev (dhandle
, info
, pp
, fields
+ c
))
2310 /* Look for the ':' that separates the field name from the field
2311 values. Data members are delimited by a single ':', while member
2312 functions are delimited by a pair of ':'s. When we hit the member
2313 functions (if any), terminate scan loop and return. */
2315 p
= strchr (p
, ':');
2325 if (! parse_stab_one_struct_field (dhandle
, info
, pp
, p
, fields
+ c
,
2332 fields
[c
] = DEBUG_FIELD_NULL
;
2339 /* Special GNU C++ name. */
2342 parse_stab_cpp_abbrev (dhandle
, info
, pp
, retp
)
2344 struct stab_handle
*info
;
2352 const char *typename
;
2356 *retp
= DEBUG_FIELD_NULL
;
2370 /* At this point, *pp points to something like "22:23=*22...", where
2371 the type number before the ':' is the "context" and everything
2372 after is a regular type definition. Lookup the type, find it's
2373 name, and construct the field name. */
2375 context
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
2376 (debug_type
**) NULL
);
2377 if (context
== DEBUG_TYPE_NULL
)
2383 /* $vf -- a virtual function table pointer. */
2387 /* $vb -- a virtual bsomethingorother */
2388 typename
= debug_get_type_name (dhandle
, context
);
2389 if (typename
== NULL
)
2391 warn_stab (orig
, _("unnamed $vb type"));
2394 name
= concat ("_vb$", typename
, (const char *) NULL
);
2397 warn_stab (orig
, _("unrecognized C++ abbreviation"));
2398 name
= "INVALID_CPLUSPLUS_ABBREV";
2409 type
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
2410 (debug_type
**) NULL
);
2418 bitpos
= parse_number (pp
, (boolean
*) NULL
);
2426 *retp
= debug_make_field (dhandle
, name
, type
, bitpos
, 0,
2427 DEBUG_VISIBILITY_PRIVATE
);
2428 if (*retp
== DEBUG_FIELD_NULL
)
2434 /* Parse a single field in a struct or union. */
2437 parse_stab_one_struct_field (dhandle
, info
, pp
, p
, retp
, staticsp
)
2439 struct stab_handle
*info
;
2447 enum debug_visibility visibility
;
2454 /* FIXME: gdb checks ARM_DEMANGLING here. */
2456 name
= savestring (*pp
, p
- *pp
);
2461 visibility
= DEBUG_VISIBILITY_PUBLIC
;
2468 visibility
= DEBUG_VISIBILITY_PRIVATE
;
2471 visibility
= DEBUG_VISIBILITY_PROTECTED
;
2474 visibility
= DEBUG_VISIBILITY_PUBLIC
;
2477 warn_stab (orig
, _("unknown visibility character for field"));
2478 visibility
= DEBUG_VISIBILITY_PUBLIC
;
2484 type
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
2485 (debug_type
**) NULL
);
2486 if (type
== DEBUG_TYPE_NULL
)
2493 /* This is a static class member. */
2495 p
= strchr (*pp
, ';');
2502 varname
= savestring (*pp
, p
- *pp
);
2506 *retp
= debug_make_static_member (dhandle
, name
, type
, varname
,
2520 bitpos
= parse_number (pp
, (boolean
*) NULL
);
2528 bitsize
= parse_number (pp
, (boolean
*) NULL
);
2536 if (bitpos
== 0 && bitsize
== 0)
2538 /* This can happen in two cases: (1) at least for gcc 2.4.5 or
2539 so, it is a field which has been optimized out. The correct
2540 stab for this case is to use VISIBILITY_IGNORE, but that is a
2541 recent invention. (2) It is a 0-size array. For example
2542 union { int num; char str[0]; } foo. Printing "<no value>"
2543 for str in "p foo" is OK, since foo.str (and thus foo.str[3])
2544 will continue to work, and a 0-size array as a whole doesn't
2545 have any contents to print.
2547 I suspect this probably could also happen with gcc -gstabs
2548 (not -gstabs+) for static fields, and perhaps other C++
2549 extensions. Hopefully few people use -gstabs with gdb, since
2550 it is intended for dbx compatibility. */
2551 visibility
= DEBUG_VISIBILITY_IGNORE
;
2554 /* FIXME: gdb does some stuff here to mark fields as unpacked. */
2556 *retp
= debug_make_field (dhandle
, name
, type
, bitpos
, bitsize
, visibility
);
2561 /* Read member function stabs info for C++ classes. The form of each member
2564 NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
2566 An example with two member functions is:
2568 afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
2570 For the case of overloaded operators, the format is op$::*.funcs, where
2571 $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
2572 name (such as `+=') and `.' marks the end of the operator name. */
2575 parse_stab_members (dhandle
, info
, tagname
, pp
, typenums
, retp
)
2577 struct stab_handle
*info
;
2578 const char *tagname
;
2580 const int *typenums
;
2581 debug_method
**retp
;
2584 debug_method
*methods
;
2600 debug_method_variant
*variants
;
2602 unsigned int allocvars
;
2603 debug_type look_ahead_type
;
2605 p
= strchr (*pp
, ':');
2606 if (p
== NULL
|| p
[1] != ':')
2609 /* FIXME: Some systems use something other than '$' here. */
2610 if ((*pp
)[0] != 'o' || (*pp
)[1] != 'p' || (*pp
)[2] != '$')
2612 name
= savestring (*pp
, p
- *pp
);
2617 /* This is a completely wierd case. In order to stuff in the
2618 names that might contain colons (the usual name delimiter),
2619 Mike Tiemann defined a different name format which is
2620 signalled if the identifier is "op$". In that case, the
2621 format is "op$::XXXX." where XXXX is the name. This is
2622 used for names like "+" or "=". YUUUUUUUK! FIXME! */
2624 for (p
= *pp
; *p
!= '.' && *p
!= '\0'; p
++)
2631 name
= savestring (*pp
, p
- *pp
);
2636 variants
= ((debug_method_variant
*)
2637 xmalloc (allocvars
* sizeof *variants
));
2640 look_ahead_type
= DEBUG_TYPE_NULL
;
2647 enum debug_visibility visibility
;
2648 boolean constp
, volatilep
, staticp
;
2651 const char *physname
;
2654 if (look_ahead_type
!= DEBUG_TYPE_NULL
)
2656 /* g++ version 1 kludge */
2657 type
= look_ahead_type
;
2658 look_ahead_type
= DEBUG_TYPE_NULL
;
2662 type
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
2663 (debug_type
**) NULL
);
2664 if (type
== DEBUG_TYPE_NULL
)
2674 p
= strchr (*pp
, ';');
2682 if (debug_get_type_kind (dhandle
, type
) == DEBUG_KIND_METHOD
2683 && debug_get_parameter_types (dhandle
, type
, &varargs
) == NULL
)
2686 argtypes
= savestring (*pp
, p
- *pp
);
2692 visibility
= DEBUG_VISIBILITY_PRIVATE
;
2695 visibility
= DEBUG_VISIBILITY_PROTECTED
;
2698 visibility
= DEBUG_VISIBILITY_PUBLIC
;
2708 /* Normal function. */
2712 /* const member function. */
2717 /* volatile member function. */
2722 /* const volatile member function. */
2730 /* File compiled with g++ version 1; no information. */
2733 warn_stab (orig
, _("const/volatile indicator missing"));
2741 /* virtual member function, followed by index. The sign
2742 bit is supposedly set to distinguish
2743 pointers-to-methods from virtual function indicies. */
2745 voffset
= parse_number (pp
, (boolean
*) NULL
);
2752 voffset
&= 0x7fffffff;
2754 if (**pp
== ';' || *pp
== '\0')
2756 /* Must be g++ version 1. */
2757 context
= DEBUG_TYPE_NULL
;
2761 /* Figure out from whence this virtual function
2762 came. It may belong to virtual function table of
2763 one of its baseclasses. */
2764 look_ahead_type
= parse_stab_type (dhandle
, info
,
2765 (const char *) NULL
,
2767 (debug_type
**) NULL
);
2770 /* g++ version 1 overloaded methods. */
2771 context
= DEBUG_TYPE_NULL
;
2775 context
= look_ahead_type
;
2776 look_ahead_type
= DEBUG_TYPE_NULL
;
2788 /* static member function. */
2792 context
= DEBUG_TYPE_NULL
;
2793 if (strncmp (argtypes
, name
, strlen (name
)) != 0)
2798 warn_stab (orig
, "member function type missing");
2800 context
= DEBUG_TYPE_NULL
;
2806 context
= DEBUG_TYPE_NULL
;
2810 /* If the type is not a stub, then the argtypes string is
2811 the physical name of the function. Otherwise the
2812 argtypes string is the mangled form of the argument
2813 types, and the full type and the physical name must be
2814 extracted from them. */
2816 physname
= argtypes
;
2819 debug_type class_type
, return_type
;
2821 class_type
= stab_find_type (dhandle
, info
, typenums
);
2822 if (class_type
== DEBUG_TYPE_NULL
)
2824 return_type
= debug_get_return_type (dhandle
, type
);
2825 if (return_type
== DEBUG_TYPE_NULL
)
2830 type
= parse_stab_argtypes (dhandle
, info
, class_type
, name
,
2831 tagname
, return_type
, argtypes
,
2832 constp
, volatilep
, &physname
);
2833 if (type
== DEBUG_TYPE_NULL
)
2837 if (cvars
+ 1 >= allocvars
)
2840 variants
= ((debug_method_variant
*)
2841 xrealloc ((PTR
) variants
,
2842 allocvars
* sizeof *variants
));
2846 variants
[cvars
] = debug_make_method_variant (dhandle
, physname
,
2851 variants
[cvars
] = debug_make_static_method_variant (dhandle
,
2857 if (variants
[cvars
] == DEBUG_METHOD_VARIANT_NULL
)
2862 while (**pp
!= ';' && **pp
!= '\0');
2864 variants
[cvars
] = DEBUG_METHOD_VARIANT_NULL
;
2872 methods
= ((debug_method
*)
2873 xrealloc ((PTR
) methods
, alloc
* sizeof *methods
));
2876 methods
[c
] = debug_make_method (dhandle
, name
, variants
);
2881 if (methods
!= NULL
)
2882 methods
[c
] = DEBUG_METHOD_NULL
;
2889 /* Parse a string representing argument types for a method. Stabs
2890 tries to save space by packing argument types into a mangled
2891 string. This string should give us enough information to extract
2892 both argument types and the physical name of the function, given
2896 parse_stab_argtypes (dhandle
, info
, class_type
, fieldname
, tagname
,
2897 return_type
, argtypes
, constp
, volatilep
, pphysname
)
2899 struct stab_handle
*info
;
2900 debug_type class_type
;
2901 const char *fieldname
;
2902 const char *tagname
;
2903 debug_type return_type
;
2904 const char *argtypes
;
2907 const char **pphysname
;
2909 boolean is_full_physname_constructor
;
2910 boolean is_constructor
;
2911 boolean is_destructor
;
2915 /* Constructors are sometimes handled specially. */
2916 is_full_physname_constructor
= ((argtypes
[0] == '_'
2917 && argtypes
[1] == '_'
2918 && (isdigit ((unsigned char) argtypes
[2])
2919 || argtypes
[2] == 'Q'
2920 || argtypes
[2] == 't'))
2921 || strncmp (argtypes
, "__ct", 4) == 0);
2923 is_constructor
= (is_full_physname_constructor
2925 && strcmp (fieldname
, tagname
) == 0));
2926 is_destructor
= ((argtypes
[0] == '_'
2927 && (argtypes
[1] == '$' || argtypes
[1] == '.')
2928 && argtypes
[2] == '_')
2929 || strncmp (argtypes
, "__dt", 4) == 0);
2931 if (is_destructor
|| is_full_physname_constructor
)
2932 *pphysname
= argtypes
;
2936 const char *const_prefix
;
2937 const char *volatile_prefix
;
2939 unsigned int mangled_name_len
;
2942 len
= tagname
== NULL
? 0 : strlen (tagname
);
2943 const_prefix
= constp
? "C" : "";
2944 volatile_prefix
= volatilep
? "V" : "";
2947 sprintf (buf
, "__%s%s", const_prefix
, volatile_prefix
);
2948 else if (tagname
!= NULL
&& strchr (tagname
, '<') != NULL
)
2950 /* Template methods are fully mangled. */
2951 sprintf (buf
, "__%s%s", const_prefix
, volatile_prefix
);
2956 sprintf (buf
, "__%s%s%d", const_prefix
, volatile_prefix
, len
);
2958 mangled_name_len
= ((is_constructor
? 0 : strlen (fieldname
))
2964 if (fieldname
[0] == 'o'
2965 && fieldname
[1] == 'p'
2966 && (fieldname
[2] == '$' || fieldname
[2] == '.'))
2970 opname
= cplus_mangle_opname (fieldname
+ 3, 0);
2973 fprintf (stderr
, _("No mangling for \"%s\"\n"), fieldname
);
2974 return DEBUG_TYPE_NULL
;
2976 mangled_name_len
+= strlen (opname
);
2977 physname
= (char *) xmalloc (mangled_name_len
);
2978 strncpy (physname
, fieldname
, 3);
2979 strcpy (physname
+ 3, opname
);
2983 physname
= (char *) xmalloc (mangled_name_len
);
2987 strcpy (physname
, fieldname
);
2990 strcat (physname
, buf
);
2991 if (tagname
!= NULL
)
2992 strcat (physname
, tagname
);
2993 strcat (physname
, argtypes
);
2995 *pphysname
= physname
;
2998 if (*argtypes
== '\0' || is_destructor
)
3000 args
= (debug_type
*) xmalloc (sizeof *args
);
3002 return debug_make_method_type (dhandle
, return_type
, class_type
, args
,
3006 args
= stab_demangle_argtypes (dhandle
, info
, *pphysname
, &varargs
);
3008 return DEBUG_TYPE_NULL
;
3010 return debug_make_method_type (dhandle
, return_type
, class_type
, args
,
3014 /* The tail end of stabs for C++ classes that contain a virtual function
3015 pointer contains a tilde, a %, and a type number.
3016 The type number refers to the base class (possibly this class itself) which
3017 contains the vtable pointer for the current class.
3019 This function is called when we have parsed all the method declarations,
3020 so we can look for the vptr base class info. */
3023 parse_stab_tilde_field (dhandle
, info
, pp
, typenums
, retvptrbase
, retownvptr
)
3025 struct stab_handle
*info
;
3027 const int *typenums
;
3028 debug_type
*retvptrbase
;
3029 boolean
*retownvptr
;
3035 *retvptrbase
= DEBUG_TYPE_NULL
;
3036 *retownvptr
= false;
3040 /* If we are positioned at a ';', then skip it. */
3049 if (**pp
== '=' || **pp
== '+' || **pp
== '-')
3051 /* Obsolete flags that used to indicate the presence of
3052 constructors and/or destructors. */
3063 /* The next number is the type number of the base class (possibly
3064 our own class) which supplies the vtable for this class. */
3065 if (! parse_stab_type_number (pp
, vtypenums
))
3068 if (vtypenums
[0] == typenums
[0]
3069 && vtypenums
[1] == typenums
[1])
3078 vtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
3079 (debug_type
**) NULL
);
3080 for (p
= *pp
; *p
!= ';' && *p
!= '\0'; p
++)
3088 *retvptrbase
= vtype
;
3096 /* Read a definition of an array type. */
3099 parse_stab_array_type (dhandle
, info
, pp
, stringp
)
3101 struct stab_handle
*info
;
3108 debug_type index_type
;
3110 bfd_signed_vma lower
, upper
;
3111 debug_type element_type
;
3113 /* Format of an array type:
3114 "ar<index type>;lower;upper;<array_contents_type>".
3115 OS9000: "arlower,upper;<array_contents_type>".
3117 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
3118 for these, produce a type like float[][]. */
3122 /* FIXME: gdb checks os9k_stabs here. */
3124 /* If the index type is type 0, we take it as int. */
3126 if (! parse_stab_type_number (&p
, typenums
))
3128 if (typenums
[0] == 0 && typenums
[1] == 0 && **pp
!= '=')
3130 index_type
= debug_find_named_type (dhandle
, "int");
3131 if (index_type
== DEBUG_TYPE_NULL
)
3133 index_type
= debug_make_int_type (dhandle
, 4, false);
3134 if (index_type
== DEBUG_TYPE_NULL
)
3141 index_type
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
3142 (debug_type
**) NULL
);
3148 return DEBUG_TYPE_NULL
;
3154 if (! isdigit ((unsigned char) **pp
) && **pp
!= '-')
3160 lower
= (bfd_signed_vma
) parse_number (pp
, (boolean
*) NULL
);
3168 if (! isdigit ((unsigned char) **pp
) && **pp
!= '-')
3174 upper
= (bfd_signed_vma
) parse_number (pp
, (boolean
*) NULL
);
3182 element_type
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
3183 (debug_type
**) NULL
);
3184 if (element_type
== DEBUG_TYPE_NULL
)
3193 return debug_make_array_type (dhandle
, element_type
, index_type
, lower
,
3197 /* This struct holds information about files we have seen using
3202 /* The next N_BINCL file. */
3203 struct bincl_file
*next
;
3204 /* The next N_BINCL on the stack. */
3205 struct bincl_file
*next_stack
;
3206 /* The file name. */
3208 /* The hash value. */
3210 /* The file index. */
3212 /* The list of types defined in this file. */
3213 struct stab_types
*file_types
;
3216 /* Start a new N_BINCL file, pushing it onto the stack. */
3219 push_bincl (info
, name
, hash
)
3220 struct stab_handle
*info
;
3224 struct bincl_file
*n
;
3226 n
= (struct bincl_file
*) xmalloc (sizeof *n
);
3227 n
->next
= info
->bincl_list
;
3228 n
->next_stack
= info
->bincl_stack
;
3231 n
->file
= info
->files
;
3232 n
->file_types
= NULL
;
3233 info
->bincl_list
= n
;
3234 info
->bincl_stack
= n
;
3237 info
->file_types
= ((struct stab_types
**)
3238 xrealloc ((PTR
) info
->file_types
,
3240 * sizeof *info
->file_types
)));
3241 info
->file_types
[n
->file
] = NULL
;
3244 /* Finish an N_BINCL file, at an N_EINCL, popping the name off the
3249 struct stab_handle
*info
;
3251 struct bincl_file
*o
;
3253 o
= info
->bincl_stack
;
3255 return info
->main_filename
;
3256 info
->bincl_stack
= o
->next_stack
;
3258 o
->file_types
= info
->file_types
[o
->file
];
3260 if (info
->bincl_stack
== NULL
)
3261 return info
->main_filename
;
3262 return info
->bincl_stack
->name
;
3265 /* Handle an N_EXCL: get the types from the corresponding N_BINCL. */
3268 find_excl (info
, name
, hash
)
3269 struct stab_handle
*info
;
3273 struct bincl_file
*l
;
3276 info
->file_types
= ((struct stab_types
**)
3277 xrealloc ((PTR
) info
->file_types
,
3279 * sizeof *info
->file_types
)));
3281 for (l
= info
->bincl_list
; l
!= NULL
; l
= l
->next
)
3282 if (l
->hash
== hash
&& strcmp (l
->name
, name
) == 0)
3286 warn_stab (name
, _("Undefined N_EXCL"));
3287 info
->file_types
[info
->files
- 1] = NULL
;
3291 info
->file_types
[info
->files
- 1] = l
->file_types
;
3296 /* Handle a variable definition. gcc emits variable definitions for a
3297 block before the N_LBRAC, so we must hold onto them until we see
3298 it. The SunPRO compiler emits variable definitions after the
3299 N_LBRAC, so we can call debug_record_variable immediately. */
3302 stab_record_variable (dhandle
, info
, name
, type
, kind
, val
)
3304 struct stab_handle
*info
;
3307 enum debug_var_kind kind
;
3310 struct stab_pending_var
*v
;
3312 if ((kind
== DEBUG_GLOBAL
|| kind
== DEBUG_STATIC
)
3313 || ! info
->within_function
3314 || (info
->gcc_compiled
== 0 && info
->n_opt_found
))
3315 return debug_record_variable (dhandle
, name
, type
, kind
, val
);
3317 v
= (struct stab_pending_var
*) xmalloc (sizeof *v
);
3318 memset (v
, 0, sizeof *v
);
3320 v
->next
= info
->pending
;
3330 /* Emit pending variable definitions. This is called after we see the
3331 N_LBRAC that starts the block. */
3334 stab_emit_pending_vars (dhandle
, info
)
3336 struct stab_handle
*info
;
3338 struct stab_pending_var
*v
;
3343 struct stab_pending_var
*next
;
3345 if (! debug_record_variable (dhandle
, v
->name
, v
->type
, v
->kind
, v
->val
))
3353 info
->pending
= NULL
;
3358 /* Find the slot for a type in the database. */
3361 stab_find_slot (info
, typenums
)
3362 struct stab_handle
*info
;
3363 const int *typenums
;
3367 struct stab_types
**ps
;
3369 filenum
= typenums
[0];
3370 index
= typenums
[1];
3372 if (filenum
< 0 || (unsigned int) filenum
>= info
->files
)
3374 fprintf (stderr
, _("Type file number %d out of range\n"), filenum
);
3379 fprintf (stderr
, _("Type index number %d out of range\n"), index
);
3383 ps
= info
->file_types
+ filenum
;
3385 while (index
>= STAB_TYPES_SLOTS
)
3389 *ps
= (struct stab_types
*) xmalloc (sizeof **ps
);
3390 memset (*ps
, 0, sizeof **ps
);
3393 index
-= STAB_TYPES_SLOTS
;
3397 *ps
= (struct stab_types
*) xmalloc (sizeof **ps
);
3398 memset (*ps
, 0, sizeof **ps
);
3401 return (*ps
)->types
+ index
;
3404 /* Find a type given a type number. If the type has not been
3405 allocated yet, create an indirect type. */
3408 stab_find_type (dhandle
, info
, typenums
)
3410 struct stab_handle
*info
;
3411 const int *typenums
;
3415 if (typenums
[0] == 0 && typenums
[1] < 0)
3417 /* A negative type number indicates an XCOFF builtin type. */
3418 return stab_xcoff_builtin_type (dhandle
, info
, typenums
[1]);
3421 slot
= stab_find_slot (info
, typenums
);
3423 return DEBUG_TYPE_NULL
;
3425 if (*slot
== DEBUG_TYPE_NULL
)
3426 return debug_make_indirect_type (dhandle
, slot
, (const char *) NULL
);
3431 /* Record that a given type number refers to a given type. */
3434 stab_record_type (dhandle
, info
, typenums
, type
)
3436 struct stab_handle
*info
;
3437 const int *typenums
;
3442 slot
= stab_find_slot (info
, typenums
);
3446 /* gdb appears to ignore type redefinitions, so we do as well. */
3453 /* Return an XCOFF builtin type. */
3456 stab_xcoff_builtin_type (dhandle
, info
, typenum
)
3458 struct stab_handle
*info
;
3464 if (typenum
>= 0 || typenum
< -XCOFF_TYPE_COUNT
)
3466 fprintf (stderr
, _("Unrecognized XCOFF type %d\n"), typenum
);
3467 return DEBUG_TYPE_NULL
;
3469 if (info
->xcoff_types
[-typenum
] != NULL
)
3470 return info
->xcoff_types
[-typenum
];
3475 /* The size of this and all the other types are fixed, defined
3476 by the debugging format. */
3478 rettype
= debug_make_int_type (dhandle
, 4, false);
3482 rettype
= debug_make_int_type (dhandle
, 1, false);
3486 rettype
= debug_make_int_type (dhandle
, 2, false);
3490 rettype
= debug_make_int_type (dhandle
, 4, false);
3493 name
= "unsigned char";
3494 rettype
= debug_make_int_type (dhandle
, 1, true);
3497 name
= "signed char";
3498 rettype
= debug_make_int_type (dhandle
, 1, false);
3501 name
= "unsigned short";
3502 rettype
= debug_make_int_type (dhandle
, 2, true);
3505 name
= "unsigned int";
3506 rettype
= debug_make_int_type (dhandle
, 4, true);
3510 rettype
= debug_make_int_type (dhandle
, 4, true);
3512 name
= "unsigned long";
3513 rettype
= debug_make_int_type (dhandle
, 4, true);
3517 rettype
= debug_make_void_type (dhandle
);
3520 /* IEEE single precision (32 bit). */
3522 rettype
= debug_make_float_type (dhandle
, 4);
3525 /* IEEE double precision (64 bit). */
3527 rettype
= debug_make_float_type (dhandle
, 8);
3530 /* This is an IEEE double on the RS/6000, and different machines
3531 with different sizes for "long double" should use different
3532 negative type numbers. See stabs.texinfo. */
3533 name
= "long double";
3534 rettype
= debug_make_float_type (dhandle
, 8);
3538 rettype
= debug_make_int_type (dhandle
, 4, false);
3542 rettype
= debug_make_bool_type (dhandle
, 4);
3545 name
= "short real";
3546 rettype
= debug_make_float_type (dhandle
, 4);
3550 rettype
= debug_make_float_type (dhandle
, 8);
3560 rettype
= debug_make_int_type (dhandle
, 1, true);
3564 rettype
= debug_make_bool_type (dhandle
, 1);
3568 rettype
= debug_make_bool_type (dhandle
, 2);
3572 rettype
= debug_make_bool_type (dhandle
, 4);
3576 rettype
= debug_make_bool_type (dhandle
, 4);
3579 /* Complex type consisting of two IEEE single precision values. */
3581 rettype
= debug_make_complex_type (dhandle
, 8);
3584 /* Complex type consisting of two IEEE double precision values. */
3585 name
= "double complex";
3586 rettype
= debug_make_complex_type (dhandle
, 16);
3590 rettype
= debug_make_int_type (dhandle
, 1, false);
3594 rettype
= debug_make_int_type (dhandle
, 2, false);
3598 rettype
= debug_make_int_type (dhandle
, 4, false);
3603 rettype
= debug_make_int_type (dhandle
, 2, false);
3607 rettype
= debug_make_int_type (dhandle
, 8, false);
3610 name
= "unsigned long long";
3611 rettype
= debug_make_int_type (dhandle
, 8, true);
3615 rettype
= debug_make_bool_type (dhandle
, 8);
3619 rettype
= debug_make_int_type (dhandle
, 8, false);
3625 rettype
= debug_name_type (dhandle
, name
, rettype
);
3627 info
->xcoff_types
[-typenum
] = rettype
;
3632 /* Find or create a tagged type. */
3635 stab_find_tagged_type (dhandle
, info
, p
, len
, kind
)
3637 struct stab_handle
*info
;
3640 enum debug_type_kind kind
;
3644 struct stab_tag
*st
;
3646 name
= savestring (p
, len
);
3648 /* We pass DEBUG_KIND_ILLEGAL because we want all tags in the same
3649 namespace. This is right for C, and I don't know how to handle
3650 other languages. FIXME. */
3651 dtype
= debug_find_tagged_type (dhandle
, name
, DEBUG_KIND_ILLEGAL
);
3652 if (dtype
!= DEBUG_TYPE_NULL
)
3658 /* We need to allocate an entry on the undefined tag list. */
3659 for (st
= info
->tags
; st
!= NULL
; st
= st
->next
)
3661 if (st
->name
[0] == name
[0]
3662 && strcmp (st
->name
, name
) == 0)
3664 if (st
->kind
== DEBUG_KIND_ILLEGAL
)
3672 st
= (struct stab_tag
*) xmalloc (sizeof *st
);
3673 memset (st
, 0, sizeof *st
);
3675 st
->next
= info
->tags
;
3678 st
->slot
= DEBUG_TYPE_NULL
;
3679 st
->type
= debug_make_indirect_type (dhandle
, &st
->slot
, name
);
3686 /* In order to get the correct argument types for a stubbed method, we
3687 need to extract the argument types from a C++ mangled string.
3688 Since the argument types can refer back to the return type, this
3689 means that we must demangle the entire physical name. In gdb this
3690 is done by calling cplus_demangle and running the results back
3691 through the C++ expression parser. Since we have no expression
3692 parser, we must duplicate much of the work of cplus_demangle here.
3694 We assume that GNU style demangling is used, since this is only
3695 done for method stubs, and only g++ should output that form of
3696 debugging information. */
3698 /* This structure is used to hold a pointer to type information which
3699 demangling a string. */
3701 struct stab_demangle_typestring
3703 /* The start of the type. This is not null terminated. */
3704 const char *typestring
;
3705 /* The length of the type. */
3709 /* This structure is used to hold information while demangling a
3712 struct stab_demangle_info
3714 /* The debugging information handle. */
3716 /* The stab information handle. */
3717 struct stab_handle
*info
;
3718 /* The array of arguments we are building. */
3720 /* Whether the method takes a variable number of arguments. */
3722 /* The array of types we have remembered. */
3723 struct stab_demangle_typestring
*typestrings
;
3724 /* The number of typestrings. */
3725 unsigned int typestring_count
;
3726 /* The number of typestring slots we have allocated. */
3727 unsigned int typestring_alloc
;
3730 static void stab_bad_demangle
PARAMS ((const char *));
3731 static unsigned int stab_demangle_count
PARAMS ((const char **));
3732 static boolean stab_demangle_get_count
3733 PARAMS ((const char **, unsigned int *));
3734 static boolean stab_demangle_prefix
3735 PARAMS ((struct stab_demangle_info
*, const char **));
3736 static boolean stab_demangle_function_name
3737 PARAMS ((struct stab_demangle_info
*, const char **, const char *));
3738 static boolean stab_demangle_signature
3739 PARAMS ((struct stab_demangle_info
*, const char **));
3740 static boolean stab_demangle_qualified
3741 PARAMS ((struct stab_demangle_info
*, const char **, debug_type
*));
3742 static boolean stab_demangle_template
3743 PARAMS ((struct stab_demangle_info
*, const char **, char **));
3744 static boolean stab_demangle_class
3745 PARAMS ((struct stab_demangle_info
*, const char **, const char **));
3746 static boolean stab_demangle_args
3747 PARAMS ((struct stab_demangle_info
*, const char **, debug_type
**,
3749 static boolean stab_demangle_arg
3750 PARAMS ((struct stab_demangle_info
*, const char **, debug_type
**,
3751 unsigned int *, unsigned int *));
3752 static boolean stab_demangle_type
3753 PARAMS ((struct stab_demangle_info
*, const char **, debug_type
*));
3754 static boolean stab_demangle_fund_type
3755 PARAMS ((struct stab_demangle_info
*, const char **, debug_type
*));
3756 static boolean stab_demangle_remember_type
3757 PARAMS ((struct stab_demangle_info
*, const char *, int));
3759 /* Warn about a bad demangling. */
3762 stab_bad_demangle (s
)
3765 fprintf (stderr
, _("bad mangled name `%s'\n"), s
);
3768 /* Get a count from a stab string. */
3771 stab_demangle_count (pp
)
3777 while (isdigit ((unsigned char) **pp
))
3780 count
+= **pp
- '0';
3786 /* Require a count in a string. The count may be multiple digits, in
3787 which case it must end in an underscore. */
3790 stab_demangle_get_count (pp
, pi
)
3794 if (! isdigit ((unsigned char) **pp
))
3799 if (isdigit ((unsigned char) **pp
))
3812 while (isdigit ((unsigned char) *p
));
3823 /* This function demangles a physical name, returning a NULL
3824 terminated array of argument types. */
3827 stab_demangle_argtypes (dhandle
, info
, physname
, pvarargs
)
3829 struct stab_handle
*info
;
3830 const char *physname
;
3833 struct stab_demangle_info minfo
;
3835 minfo
.dhandle
= dhandle
;
3838 minfo
.varargs
= false;
3839 minfo
.typestring_alloc
= 10;
3840 minfo
.typestrings
= ((struct stab_demangle_typestring
*)
3841 xmalloc (minfo
.typestring_alloc
3842 * sizeof *minfo
.typestrings
));
3843 minfo
.typestring_count
= 0;
3845 /* cplus_demangle checks for special GNU mangled forms, but we can't
3846 see any of them in mangled method argument types. */
3848 if (! stab_demangle_prefix (&minfo
, &physname
))
3851 if (*physname
!= '\0')
3853 if (! stab_demangle_signature (&minfo
, &physname
))
3857 free (minfo
.typestrings
);
3858 minfo
.typestrings
= NULL
;
3860 if (minfo
.args
== NULL
)
3861 fprintf (stderr
, _("no argument types in mangled string\n"));
3863 *pvarargs
= minfo
.varargs
;
3867 if (minfo
.typestrings
!= NULL
)
3868 free (minfo
.typestrings
);
3872 /* Demangle the prefix of the mangled name. */
3875 stab_demangle_prefix (minfo
, pp
)
3876 struct stab_demangle_info
*minfo
;
3882 /* cplus_demangle checks for global constructors and destructors,
3883 but we can't see them in mangled argument types. */
3885 /* Look for `__'. */
3889 scan
= strchr (scan
, '_');
3891 while (scan
!= NULL
&& *++scan
!= '_');
3895 stab_bad_demangle (*pp
);
3901 /* We found `__'; move ahead to the last contiguous `__' pair. */
3902 i
= strspn (scan
, "_");
3907 && (isdigit ((unsigned char) scan
[2])
3911 /* This is a GNU style constructor name. */
3915 else if (scan
== *pp
3916 && ! isdigit ((unsigned char) scan
[2])
3919 /* Look for the `__' that separates the prefix from the
3921 while (*scan
== '_')
3923 scan
= strstr (scan
, "__");
3924 if (scan
== NULL
|| scan
[2] == '\0')
3926 stab_bad_demangle (*pp
);
3930 return stab_demangle_function_name (minfo
, pp
, scan
);
3932 else if (scan
[2] != '\0')
3934 /* The name doesn't start with `__', but it does contain `__'. */
3935 return stab_demangle_function_name (minfo
, pp
, scan
);
3939 stab_bad_demangle (*pp
);
3945 /* Demangle a function name prefix. The scan argument points to the
3946 double underscore which separates the function name from the
3950 stab_demangle_function_name (minfo
, pp
, scan
)
3951 struct stab_demangle_info
*minfo
;
3957 /* The string from *pp to scan is the name of the function. We
3958 don't care about the name, since we just looking for argument
3959 types. However, for conversion operators, the name may include a
3960 type which we must remember in order to handle backreferences. */
3966 && strncmp (name
, "type", 4) == 0
3967 && (name
[4] == '$' || name
[4] == '.'))
3971 /* This is a type conversion operator. */
3973 if (! stab_demangle_type (minfo
, &tem
, (debug_type
*) NULL
))
3976 else if (name
[0] == '_'
3983 /* This is a type conversion operator. */
3985 if (! stab_demangle_type (minfo
, &tem
, (debug_type
*) NULL
))
3992 /* Demangle the signature. This is where the argument types are
3996 stab_demangle_signature (minfo
, pp
)
3997 struct stab_demangle_info
*minfo
;
4001 boolean expect_func
, func_done
;
4006 expect_func
= false;
4010 while (**pp
!= '\0')
4016 if (! stab_demangle_qualified (minfo
, pp
, (debug_type
*) NULL
)
4017 || ! stab_demangle_remember_type (minfo
, hold
, *pp
- hold
))
4024 /* Static member function. FIXME: Can this happen? */
4031 /* Const member function. */
4037 case '0': case '1': case '2': case '3': case '4':
4038 case '5': case '6': case '7': case '8': case '9':
4041 if (! stab_demangle_class (minfo
, pp
, (const char **) NULL
)
4042 || ! stab_demangle_remember_type (minfo
, hold
, *pp
- hold
))
4049 /* Function. I don't know if this actually happens with g++
4054 if (! stab_demangle_args (minfo
, pp
, &minfo
->args
, &minfo
->varargs
))
4062 if (! stab_demangle_template (minfo
, pp
, (char **) NULL
)
4063 || ! stab_demangle_remember_type (minfo
, hold
, *pp
- hold
))
4070 /* At the outermost level, we cannot have a return type
4071 specified, so if we run into another '_' at this point we
4072 are dealing with a mangled name that is either bogus, or
4073 has been mangled by some algorithm we don't know how to
4074 deal with. So just reject the entire demangling. */
4075 stab_bad_demangle (orig
);
4079 /* Assume we have stumbled onto the first outermost function
4080 argument token, and start processing args. */
4082 if (! stab_demangle_args (minfo
, pp
, &minfo
->args
, &minfo
->varargs
))
4090 if (! stab_demangle_args (minfo
, pp
, &minfo
->args
, &minfo
->varargs
))
4097 /* With GNU style demangling, bar__3foo is 'foo::bar(void)', and
4098 bar__3fooi is 'foo::bar(int)'. We get here when we find the
4099 first case, and need to ensure that the '(void)' gets added
4100 to the current declp. */
4101 if (! stab_demangle_args (minfo
, pp
, &minfo
->args
, &minfo
->varargs
))
4108 /* Demangle a qualified name, such as "Q25Outer5Inner" which is the
4109 mangled form of "Outer::Inner". */
4112 stab_demangle_qualified (minfo
, pp
, ptype
)
4113 struct stab_demangle_info
*minfo
;
4119 unsigned int qualifiers
;
4127 /* GNU mangled name with more than 9 classes. The count is
4128 preceded by an underscore (to distinguish it from the <= 9
4129 case) and followed by an underscore. */
4131 if (! isdigit ((unsigned char) *p
) || *p
== '0')
4133 stab_bad_demangle (orig
);
4136 qualifiers
= atoi (p
);
4137 while (isdigit ((unsigned char) *p
))
4141 stab_bad_demangle (orig
);
4147 case '1': case '2': case '3': case '4': case '5':
4148 case '6': case '7': case '8': case '9':
4149 qualifiers
= (*pp
)[1] - '0';
4150 /* Skip an optional underscore after the count. */
4151 if ((*pp
)[2] == '_')
4158 stab_bad_demangle (orig
);
4162 context
= DEBUG_TYPE_NULL
;
4164 /* Pick off the names. */
4165 while (qualifiers
-- > 0)
4173 if (! stab_demangle_template (minfo
, pp
,
4174 ptype
!= NULL
? &name
: NULL
))
4179 context
= stab_find_tagged_type (minfo
->dhandle
, minfo
->info
,
4180 name
, strlen (name
),
4183 if (context
== DEBUG_TYPE_NULL
)
4191 len
= stab_demangle_count (pp
);
4192 if (strlen (*pp
) < len
)
4194 stab_bad_demangle (orig
);
4200 const debug_field
*fields
;
4203 if (context
!= DEBUG_TYPE_NULL
)
4204 fields
= debug_get_fields (minfo
->dhandle
, context
);
4206 context
= DEBUG_TYPE_NULL
;
4212 /* Try to find the type by looking through the
4213 fields of context until we find a field with the
4214 same type. This ought to work for a class
4215 defined within a class, but it won't work for,
4216 e.g., an enum defined within a class. stabs does
4217 not give us enough information to figure out the
4220 name
= savestring (*pp
, len
);
4222 for (; *fields
!= DEBUG_FIELD_NULL
; fields
++)
4227 ft
= debug_get_field_type (minfo
->dhandle
, *fields
);
4230 dn
= debug_get_type_name (minfo
->dhandle
, ft
);
4231 if (dn
!= NULL
&& strcmp (dn
, name
) == 0)
4241 if (context
== DEBUG_TYPE_NULL
)
4243 /* We have to fall back on finding the type by name.
4244 If there are more types to come, then this must
4245 be a class. Otherwise, it could be anything. */
4247 if (qualifiers
== 0)
4251 name
= savestring (*pp
, len
);
4252 context
= debug_find_named_type (minfo
->dhandle
,
4257 if (context
== DEBUG_TYPE_NULL
)
4259 context
= stab_find_tagged_type (minfo
->dhandle
,
4263 ? DEBUG_KIND_ILLEGAL
4264 : DEBUG_KIND_CLASS
));
4265 if (context
== DEBUG_TYPE_NULL
)
4281 /* Demangle a template. If PNAME is not NULL, this sets *PNAME to a
4282 string representation of the template. */
4285 stab_demangle_template (minfo
, pp
, pname
)
4286 struct stab_demangle_info
*minfo
;
4297 /* Skip the template name. */
4298 r
= stab_demangle_count (pp
);
4299 if (r
== 0 || strlen (*pp
) < r
)
4301 stab_bad_demangle (orig
);
4306 /* Get the size of the parameter list. */
4307 if (stab_demangle_get_count (pp
, &r
) == 0)
4309 stab_bad_demangle (orig
);
4313 for (i
= 0; i
< r
; i
++)
4317 /* This is a type parameter. */
4319 if (! stab_demangle_type (minfo
, pp
, (debug_type
*) NULL
))
4325 boolean pointerp
, realp
, integralp
, charp
, boolp
;
4336 /* This is a value parameter. */
4338 if (! stab_demangle_type (minfo
, pp
, (debug_type
*) NULL
))
4341 while (*old_p
!= '\0' && ! done
)
4351 case 'C': /* Const. */
4352 case 'S': /* Signed. */
4353 case 'U': /* Unsigned. */
4354 case 'V': /* Volatile. */
4355 case 'F': /* Function. */
4356 case 'M': /* Member function. */
4360 case 'Q': /* Qualified name. */
4364 case 'T': /* Remembered type. */
4366 case 'v': /* Void. */
4368 case 'x': /* Long long. */
4369 case 'l': /* Long. */
4370 case 'i': /* Int. */
4371 case 's': /* Short. */
4372 case 'w': /* Wchar_t. */
4376 case 'b': /* Bool. */
4380 case 'c': /* Char. */
4384 case 'r': /* Long double. */
4385 case 'd': /* Double. */
4386 case 'f': /* Float. */
4391 /* Assume it's a user defined integral type. */
4402 while (isdigit ((unsigned char) **pp
))
4411 val
= stab_demangle_count (pp
);
4414 stab_bad_demangle (orig
);
4422 val
= stab_demangle_count (pp
);
4423 if (val
!= 0 && val
!= 1)
4425 stab_bad_demangle (orig
);
4433 while (isdigit ((unsigned char) **pp
))
4438 while (isdigit ((unsigned char) **pp
))
4444 while (isdigit ((unsigned char) **pp
))
4452 if (! stab_demangle_get_count (pp
, &len
))
4454 stab_bad_demangle (orig
);
4462 /* We can translate this to a string fairly easily by invoking the
4463 regular demangling routine. */
4466 char *s1
, *s2
, *s3
, *s4
;
4469 s1
= savestring (orig
, *pp
- orig
);
4471 s2
= concat ("NoSuchStrinG__", s1
, (const char *) NULL
);
4475 s3
= cplus_demangle (s2
, DMGL_ANSI
);
4480 s4
= strstr (s3
, "::NoSuchStrinG");
4481 if (s3
== NULL
|| s4
== NULL
)
4483 stab_bad_demangle (orig
);
4489 /* Eliminating all spaces, except those between > characters,
4490 makes it more likely that the demangled name will match the
4491 name which g++ used as the structure name. */
4492 for (from
= to
= s3
; from
!= s4
; ++from
)
4494 || (from
[1] == '>' && from
> s3
&& from
[-1] == '>'))
4497 *pname
= savestring (s3
, to
- s3
);
4505 /* Demangle a class name. */
4508 stab_demangle_class (minfo
, pp
, pstart
)
4509 struct stab_demangle_info
*minfo
;
4511 const char **pstart
;
4518 n
= stab_demangle_count (pp
);
4519 if (strlen (*pp
) < n
)
4521 stab_bad_demangle (orig
);
4533 /* Demangle function arguments. If the pargs argument is not NULL, it
4534 is set to a NULL terminated array holding the arguments. */
4537 stab_demangle_args (minfo
, pp
, pargs
, pvarargs
)
4538 struct stab_demangle_info
*minfo
;
4544 unsigned int alloc
, count
;
4551 *pargs
= (debug_type
*) xmalloc (alloc
* sizeof **pargs
);
4556 while (**pp
!= '_' && **pp
!= '\0' && **pp
!= 'e')
4558 if (**pp
== 'N' || **pp
== 'T')
4566 if (temptype
== 'T')
4570 if (! stab_demangle_get_count (pp
, &r
))
4572 stab_bad_demangle (orig
);
4577 if (! stab_demangle_get_count (pp
, &t
))
4579 stab_bad_demangle (orig
);
4583 if (t
>= minfo
->typestring_count
)
4585 stab_bad_demangle (orig
);
4592 tem
= minfo
->typestrings
[t
].typestring
;
4593 if (! stab_demangle_arg (minfo
, &tem
, pargs
, &count
, &alloc
))
4599 if (! stab_demangle_arg (minfo
, pp
, pargs
, &count
, &alloc
))
4605 (*pargs
)[count
] = DEBUG_TYPE_NULL
;
4617 /* Demangle a single argument. */
4620 stab_demangle_arg (minfo
, pp
, pargs
, pcount
, palloc
)
4621 struct stab_demangle_info
*minfo
;
4624 unsigned int *pcount
;
4625 unsigned int *palloc
;
4631 if (! stab_demangle_type (minfo
, pp
,
4632 pargs
== NULL
? (debug_type
*) NULL
: &type
)
4633 || ! stab_demangle_remember_type (minfo
, start
, *pp
- start
))
4638 if (type
== DEBUG_TYPE_NULL
)
4641 if (*pcount
+ 1 >= *palloc
)
4644 *pargs
= ((debug_type
*)
4645 xrealloc (*pargs
, *palloc
* sizeof **pargs
));
4647 (*pargs
)[*pcount
] = type
;
4654 /* Demangle a type. If the ptype argument is not NULL, *ptype is set
4655 to the newly allocated type. */
4658 stab_demangle_type (minfo
, pp
, ptype
)
4659 struct stab_demangle_info
*minfo
;
4671 /* A pointer type. */
4673 if (! stab_demangle_type (minfo
, pp
, ptype
))
4676 *ptype
= debug_make_pointer_type (minfo
->dhandle
, *ptype
);
4680 /* A reference type. */
4682 if (! stab_demangle_type (minfo
, pp
, ptype
))
4685 *ptype
= debug_make_reference_type (minfo
->dhandle
, *ptype
);
4695 while (**pp
!= '\0' && **pp
!= '_')
4697 if (! isdigit ((unsigned char) **pp
))
4699 stab_bad_demangle (orig
);
4708 stab_bad_demangle (orig
);
4713 if (! stab_demangle_type (minfo
, pp
, ptype
))
4717 debug_type int_type
;
4719 int_type
= debug_find_named_type (minfo
->dhandle
, "int");
4720 if (int_type
== NULL
)
4721 int_type
= debug_make_int_type (minfo
->dhandle
, 4, false);
4722 *ptype
= debug_make_array_type (minfo
->dhandle
, *ptype
, int_type
,
4729 /* A back reference to a remembered type. */
4735 if (! stab_demangle_get_count (pp
, &i
))
4737 stab_bad_demangle (orig
);
4740 if (i
>= minfo
->typestring_count
)
4742 stab_bad_demangle (orig
);
4745 p
= minfo
->typestrings
[i
].typestring
;
4746 if (! stab_demangle_type (minfo
, &p
, ptype
))
4758 if (! stab_demangle_args (minfo
, pp
,
4760 ? (debug_type
**) NULL
4768 /* cplus_demangle will accept a function without a return
4769 type, but I don't know when that will happen, or what
4770 to do if it does. */
4771 stab_bad_demangle (orig
);
4775 if (! stab_demangle_type (minfo
, pp
, ptype
))
4778 *ptype
= debug_make_function_type (minfo
->dhandle
, *ptype
, args
,
4787 boolean memberp
, constp
, volatilep
;
4793 memberp
= **pp
== 'M';
4800 if (! isdigit ((unsigned char) **pp
))
4802 stab_bad_demangle (orig
);
4805 n
= stab_demangle_count (pp
);
4806 if (strlen (*pp
) < n
)
4808 stab_bad_demangle (orig
);
4821 else if (**pp
== 'V')
4828 stab_bad_demangle (orig
);
4832 if (! stab_demangle_args (minfo
, pp
,
4834 ? (debug_type
**) NULL
4844 stab_bad_demangle (orig
);
4849 if (! stab_demangle_type (minfo
, pp
, ptype
))
4854 debug_type class_type
;
4856 class_type
= stab_find_tagged_type (minfo
->dhandle
, minfo
->info
,
4859 if (class_type
== DEBUG_TYPE_NULL
)
4863 *ptype
= debug_make_offset_type (minfo
->dhandle
, class_type
,
4867 /* FIXME: We have no way to record constp or
4869 *ptype
= debug_make_method_type (minfo
->dhandle
, *ptype
,
4870 class_type
, args
, varargs
);
4878 if (! stab_demangle_type (minfo
, pp
, ptype
))
4884 if (! stab_demangle_type (minfo
, pp
, ptype
))
4887 *ptype
= debug_make_const_type (minfo
->dhandle
, *ptype
);
4895 if (! stab_demangle_qualified (minfo
, pp
, ptype
))
4901 if (! stab_demangle_fund_type (minfo
, pp
, ptype
))
4909 /* Demangle a fundamental type. If the ptype argument is not NULL,
4910 *ptype is set to the newly allocated type. */
4913 stab_demangle_fund_type (minfo
, pp
, ptype
)
4914 struct stab_demangle_info
*minfo
;
4919 boolean constp
, volatilep
, unsignedp
, signedp
;
4964 /* cplus_demangle permits this, but I don't know what it means. */
4965 stab_bad_demangle (orig
);
4968 case 'v': /* void */
4971 *ptype
= debug_find_named_type (minfo
->dhandle
, "void");
4972 if (*ptype
== DEBUG_TYPE_NULL
)
4973 *ptype
= debug_make_void_type (minfo
->dhandle
);
4978 case 'x': /* long long */
4981 *ptype
= debug_find_named_type (minfo
->dhandle
,
4983 ? "long long unsigned int"
4984 : "long long int"));
4985 if (*ptype
== DEBUG_TYPE_NULL
)
4986 *ptype
= debug_make_int_type (minfo
->dhandle
, 8, unsignedp
);
4991 case 'l': /* long */
4994 *ptype
= debug_find_named_type (minfo
->dhandle
,
4996 ? "long unsigned int"
4998 if (*ptype
== DEBUG_TYPE_NULL
)
4999 *ptype
= debug_make_int_type (minfo
->dhandle
, 4, unsignedp
);
5007 *ptype
= debug_find_named_type (minfo
->dhandle
,
5011 if (*ptype
== DEBUG_TYPE_NULL
)
5012 *ptype
= debug_make_int_type (minfo
->dhandle
, 4, unsignedp
);
5017 case 's': /* short */
5020 *ptype
= debug_find_named_type (minfo
->dhandle
,
5022 ? "short unsigned int"
5024 if (*ptype
== DEBUG_TYPE_NULL
)
5025 *ptype
= debug_make_int_type (minfo
->dhandle
, 2, unsignedp
);
5030 case 'b': /* bool */
5033 *ptype
= debug_find_named_type (minfo
->dhandle
, "bool");
5034 if (*ptype
== DEBUG_TYPE_NULL
)
5035 *ptype
= debug_make_bool_type (minfo
->dhandle
, 4);
5040 case 'c': /* char */
5043 *ptype
= debug_find_named_type (minfo
->dhandle
,
5049 if (*ptype
== DEBUG_TYPE_NULL
)
5050 *ptype
= debug_make_int_type (minfo
->dhandle
, 1, unsignedp
);
5055 case 'w': /* wchar_t */
5058 *ptype
= debug_find_named_type (minfo
->dhandle
, "__wchar_t");
5059 if (*ptype
== DEBUG_TYPE_NULL
)
5060 *ptype
= debug_make_int_type (minfo
->dhandle
, 2, true);
5065 case 'r': /* long double */
5068 *ptype
= debug_find_named_type (minfo
->dhandle
, "long double");
5069 if (*ptype
== DEBUG_TYPE_NULL
)
5070 *ptype
= debug_make_float_type (minfo
->dhandle
, 8);
5075 case 'd': /* double */
5078 *ptype
= debug_find_named_type (minfo
->dhandle
, "double");
5079 if (*ptype
== DEBUG_TYPE_NULL
)
5080 *ptype
= debug_make_float_type (minfo
->dhandle
, 8);
5085 case 'f': /* float */
5088 *ptype
= debug_find_named_type (minfo
->dhandle
, "float");
5089 if (*ptype
== DEBUG_TYPE_NULL
)
5090 *ptype
= debug_make_float_type (minfo
->dhandle
, 4);
5097 if (! isdigit ((unsigned char) **pp
))
5099 stab_bad_demangle (orig
);
5103 case '0': case '1': case '2': case '3': case '4':
5104 case '5': case '6': case '7': case '8': case '9':
5108 if (! stab_demangle_class (minfo
, pp
, &hold
))
5114 name
= savestring (hold
, *pp
- hold
);
5115 *ptype
= debug_find_named_type (minfo
->dhandle
, name
);
5117 if (*ptype
== DEBUG_TYPE_NULL
)
5119 /* FIXME: It is probably incorrect to assume that
5120 undefined types are tagged types. */
5121 *ptype
= stab_find_tagged_type (minfo
->dhandle
, minfo
->info
,
5123 DEBUG_KIND_ILLEGAL
);
5124 if (*ptype
== DEBUG_TYPE_NULL
)
5135 if (! stab_demangle_template (minfo
, pp
,
5136 ptype
!= NULL
? &name
: NULL
))
5140 *ptype
= stab_find_tagged_type (minfo
->dhandle
, minfo
->info
,
5141 name
, strlen (name
),
5144 if (*ptype
== DEBUG_TYPE_NULL
)
5151 stab_bad_demangle (orig
);
5158 *ptype
= debug_make_const_type (minfo
->dhandle
, *ptype
);
5160 *ptype
= debug_make_volatile_type (minfo
->dhandle
, *ptype
);
5166 /* Remember a type string in a demangled string. */
5169 stab_demangle_remember_type (minfo
, p
, len
)
5170 struct stab_demangle_info
*minfo
;
5174 if (minfo
->typestring_count
>= minfo
->typestring_alloc
)
5176 minfo
->typestring_alloc
+= 10;
5177 minfo
->typestrings
= ((struct stab_demangle_typestring
*)
5178 xrealloc (minfo
->typestrings
,
5179 (minfo
->typestring_alloc
5180 * sizeof *minfo
->typestrings
)));
5183 minfo
->typestrings
[minfo
->typestring_count
].typestring
= p
;
5184 minfo
->typestrings
[minfo
->typestring_count
].len
= (unsigned int) len
;
5185 ++minfo
->typestring_count
;