1 /* stabs.c -- Parse stabs debugging information
2 Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001
3 Free Software Foundation, Inc.
4 Written by Ian Lance Taylor <ian@cygnus.com>.
6 This file is part of GNU Binutils.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23 /* This file contains code which parses stabs debugging information.
24 The organization of this code is based on the gdb stabs reading
25 code. The job it does is somewhat different, because it is not
26 trying to identify the correct address for anything. */
32 #include "libiberty.h"
33 #include "safe-ctype.h"
37 #include "filenames.h"
39 /* Meaningless definition needs by aout64.h. FIXME. */
40 #define BYTES_IN_WORD 4
42 #include "aout/aout64.h"
43 #include "aout/stab_gnu.h"
45 /* The number of predefined XCOFF types. */
47 #define XCOFF_TYPE_COUNT 34
49 /* This structure is used as a handle so that the stab parsing doesn't
50 need to use any static variables. */
56 /* True if this is stabs in sections. */
58 /* The symbol table. */
60 /* The number of symbols. */
62 /* The accumulated file name string. */
64 /* The value of the last N_SO symbol. */
66 /* The value of the start of the file, so that we can handle file
67 relative N_LBRAC and N_RBRAC symbols. */
68 bfd_vma file_start_offset
;
69 /* The offset of the start of the function, so that we can handle
70 function relative N_LBRAC and N_RBRAC symbols. */
71 bfd_vma function_start_offset
;
72 /* The version number of gcc which compiled the current compilation
73 unit, 0 if not compiled by gcc. */
75 /* Whether an N_OPT symbol was seen that was not generated by gcc,
76 so that we can detect the SunPRO compiler. */
78 /* The main file name. */
80 /* A stack of unfinished N_BINCL files. */
81 struct bincl_file
*bincl_stack
;
82 /* A list of finished N_BINCL files. */
83 struct bincl_file
*bincl_list
;
84 /* Whether we are inside a function or not. */
85 boolean within_function
;
86 /* The address of the end of the function, used if we have seen an
87 N_FUN symbol while in a function. This is -1 if we have not seen
88 an N_FUN (the normal case). */
90 /* The depth of block nesting. */
92 /* List of pending variable definitions. */
93 struct stab_pending_var
*pending
;
94 /* Number of files for which we have types. */
96 /* Lists of types per file. */
97 struct stab_types
**file_types
;
98 /* Predefined XCOFF types. */
99 debug_type xcoff_types
[XCOFF_TYPE_COUNT
];
100 /* Undefined tags. */
101 struct stab_tag
*tags
;
102 /* Set by parse_stab_type if it sees a structure defined as a cross
103 reference to itself. Reset by parse_stab_type otherwise. */
104 boolean self_crossref
;
107 /* A list of these structures is used to hold pending variable
108 definitions seen before the N_LBRAC of a block. */
110 struct stab_pending_var
112 /* Next pending variable definition. */
113 struct stab_pending_var
*next
;
119 enum debug_var_kind kind
;
124 /* A list of these structures is used to hold the types for a single
129 /* Next set of slots for this file. */
130 struct stab_types
*next
;
131 /* Types indexed by type number. */
132 #define STAB_TYPES_SLOTS (16)
133 debug_type types
[STAB_TYPES_SLOTS
];
136 /* We keep a list of undefined tags that we encounter, so that we can
137 fill them in if the tag is later defined. */
141 /* Next undefined tag. */
142 struct stab_tag
*next
;
146 enum debug_type_kind kind
;
147 /* Slot to hold real type when we discover it. If we don't, we fill
148 in an undefined tag type. */
150 /* Indirect type we have created to point at slot. */
154 static char *savestring
PARAMS ((const char *, int));
155 static bfd_vma parse_number
PARAMS ((const char **, boolean
*));
156 static void bad_stab
PARAMS ((const char *));
157 static void warn_stab
PARAMS ((const char *, const char *));
158 static boolean parse_stab_string
159 PARAMS ((PTR
, struct stab_handle
*, int, int, bfd_vma
, const char *));
160 static debug_type parse_stab_type
161 PARAMS ((PTR
, struct stab_handle
*, const char *, const char **,
163 static boolean parse_stab_type_number
164 PARAMS ((const char **, int *));
165 static debug_type parse_stab_range_type
166 PARAMS ((PTR
, struct stab_handle
*, const char *, const char **,
168 static debug_type parse_stab_sun_builtin_type
PARAMS ((PTR
, const char **));
169 static debug_type parse_stab_sun_floating_type
170 PARAMS ((PTR
, const char **));
171 static debug_type parse_stab_enum_type
PARAMS ((PTR
, const char **));
172 static debug_type parse_stab_struct_type
173 PARAMS ((PTR
, struct stab_handle
*, const char *, const char **, boolean
,
175 static boolean parse_stab_baseclasses
176 PARAMS ((PTR
, struct stab_handle
*, const char **, debug_baseclass
**));
177 static boolean parse_stab_struct_fields
178 PARAMS ((PTR
, struct stab_handle
*, const char **, debug_field
**,
180 static boolean parse_stab_cpp_abbrev
181 PARAMS ((PTR
, struct stab_handle
*, const char **, debug_field
*));
182 static boolean parse_stab_one_struct_field
183 PARAMS ((PTR
, struct stab_handle
*, const char **, const char *,
184 debug_field
*, boolean
*));
185 static boolean parse_stab_members
186 PARAMS ((PTR
, struct stab_handle
*, const char *, const char **,
187 const int *, debug_method
**));
188 static debug_type parse_stab_argtypes
189 PARAMS ((PTR
, struct stab_handle
*, debug_type
, const char *, const char *,
190 debug_type
, const char *, boolean
, boolean
, const char **));
191 static boolean parse_stab_tilde_field
192 PARAMS ((PTR
, struct stab_handle
*, const char **, const int *,
193 debug_type
*, boolean
*));
194 static debug_type parse_stab_array_type
195 PARAMS ((PTR
, struct stab_handle
*, const char **, boolean
));
196 static void push_bincl
PARAMS ((struct stab_handle
*, const char *, bfd_vma
));
197 static const char *pop_bincl
PARAMS ((struct stab_handle
*));
198 static boolean find_excl
199 PARAMS ((struct stab_handle
*, const char *, bfd_vma
));
200 static boolean stab_record_variable
201 PARAMS ((PTR
, struct stab_handle
*, const char *, debug_type
,
202 enum debug_var_kind
, bfd_vma
));
203 static boolean stab_emit_pending_vars
PARAMS ((PTR
, struct stab_handle
*));
204 static debug_type
*stab_find_slot
205 PARAMS ((struct stab_handle
*, const int *));
206 static debug_type stab_find_type
207 PARAMS ((PTR
, struct stab_handle
*, const int *));
208 static boolean stab_record_type
209 PARAMS ((PTR
, struct stab_handle
*, const int *, debug_type
));
210 static debug_type stab_xcoff_builtin_type
211 PARAMS ((PTR
, struct stab_handle
*, int));
212 static debug_type stab_find_tagged_type
213 PARAMS ((PTR
, struct stab_handle
*, const char *, int,
214 enum debug_type_kind
));
215 static debug_type
*stab_demangle_argtypes
216 PARAMS ((PTR
, struct stab_handle
*, const char *, boolean
*));
218 /* Save a string in memory. */
221 savestring (start
, len
)
227 ret
= (char *) xmalloc (len
+ 1);
228 memcpy (ret
, start
, len
);
233 /* Read a number from a string. */
236 parse_number (pp
, poverflow
)
243 if (poverflow
!= NULL
)
249 ul
= strtoul (*pp
, (char **) pp
, 0);
250 if (ul
+ 1 != 0 || errno
== 0)
252 /* If bfd_vma is larger than unsigned long, and the number is
253 meant to be negative, we have to make sure that we sign
256 return (bfd_vma
) (bfd_signed_vma
) (long) ul
;
260 /* Note that even though strtoul overflowed, it should have set *pp
261 to the end of the number, which is where we want it. */
263 if (sizeof (bfd_vma
) > sizeof (unsigned long))
268 bfd_vma over
, lastdig
;
272 /* Our own version of strtoul, for a bfd_vma. */
288 if (p
[1] == 'x' || p
[1] == 'X')
300 over
= ((bfd_vma
) (bfd_signed_vma
) -1) / (bfd_vma
) base
;
301 lastdig
= ((bfd_vma
) (bfd_signed_vma
) -1) % (bfd_vma
) base
;
312 else if (ISUPPER (d
))
314 else if (ISLOWER (d
))
322 if (v
> over
|| (v
== over
&& (bfd_vma
) d
> lastdig
))
337 /* If we get here, the number is too large to represent in a
340 if (poverflow
!= NULL
)
343 warn_stab (orig
, _("numeric overflow"));
348 /* Give an error for a bad stab string. */
354 fprintf (stderr
, _("Bad stab: %s\n"), p
);
357 /* Warn about something in a stab string. */
364 fprintf (stderr
, _("Warning: %s: %s\n"), err
, p
);
367 /* Create a handle to parse stabs symbols with. */
371 start_stab (dhandle
, abfd
, sections
, syms
, symcount
)
372 PTR dhandle ATTRIBUTE_UNUSED
;
378 struct stab_handle
*ret
;
380 ret
= (struct stab_handle
*) xmalloc (sizeof *ret
);
381 memset (ret
, 0, sizeof *ret
);
383 ret
->sections
= sections
;
385 ret
->symcount
= symcount
;
387 ret
->file_types
= (struct stab_types
**) xmalloc (sizeof *ret
->file_types
);
388 ret
->file_types
[0] = NULL
;
389 ret
->function_end
= (bfd_vma
) -1;
393 /* When we have processed all the stabs information, we need to go
394 through and fill in all the undefined tags. */
397 finish_stab (dhandle
, handle
)
401 struct stab_handle
*info
= (struct stab_handle
*) handle
;
404 if (info
->within_function
)
406 if (! stab_emit_pending_vars (dhandle
, info
)
407 || ! debug_end_function (dhandle
, info
->function_end
))
409 info
->within_function
= false;
410 info
->function_end
= (bfd_vma
) -1;
413 for (st
= info
->tags
; st
!= NULL
; st
= st
->next
)
415 enum debug_type_kind kind
;
418 if (kind
== DEBUG_KIND_ILLEGAL
)
419 kind
= DEBUG_KIND_STRUCT
;
420 st
->slot
= debug_make_undefined_tagged_type (dhandle
, st
->name
, kind
);
421 if (st
->slot
== DEBUG_TYPE_NULL
)
428 /* Handle a single stabs symbol. */
431 parse_stab (dhandle
, handle
, type
, desc
, value
, string
)
439 struct stab_handle
*info
= (struct stab_handle
*) handle
;
441 /* gcc will emit two N_SO strings per compilation unit, one for the
442 directory name and one for the file name. We just collect N_SO
443 strings as we see them, and start the new compilation unit when
444 we see a non N_SO symbol. */
445 if (info
->so_string
!= NULL
446 && (type
!= N_SO
|| *string
== '\0' || value
!= info
->so_value
))
448 if (! debug_set_filename (dhandle
, info
->so_string
))
450 info
->main_filename
= info
->so_string
;
452 info
->gcc_compiled
= 0;
453 info
->n_opt_found
= false;
455 /* Generally, for stabs in the symbol table, the N_LBRAC and
456 N_RBRAC symbols are relative to the N_SO symbol value. */
457 if (! info
->sections
)
458 info
->file_start_offset
= info
->so_value
;
460 /* We need to reset the mapping from type numbers to types. We
461 can't free the old mapping, because of the use of
462 debug_make_indirect_type. */
464 info
->file_types
= ((struct stab_types
**)
465 xmalloc (sizeof *info
->file_types
));
466 info
->file_types
[0] = NULL
;
468 info
->so_string
= NULL
;
470 /* Now process whatever type we just got. */
480 /* Ignore extra outermost context from SunPRO cc and acc. */
481 if (info
->n_opt_found
&& desc
== 1)
484 if (! info
->within_function
)
486 fprintf (stderr
, _("N_LBRAC not within function\n"));
490 /* Start an inner lexical block. */
491 if (! debug_start_block (dhandle
,
493 + info
->file_start_offset
494 + info
->function_start_offset
)))
497 /* Emit any pending variable definitions. */
498 if (! stab_emit_pending_vars (dhandle
, info
))
505 /* Ignore extra outermost context from SunPRO cc and acc. */
506 if (info
->n_opt_found
&& desc
== 1)
509 /* We shouldn't have any pending variable definitions here, but,
510 if we do, we probably need to emit them before closing the
512 if (! stab_emit_pending_vars (dhandle
, info
))
515 /* End an inner lexical block. */
516 if (! debug_end_block (dhandle
,
518 + info
->file_start_offset
519 + info
->function_start_offset
)))
523 if (info
->block_depth
< 0)
525 fprintf (stderr
, _("Too many N_RBRACs\n"));
531 /* This always ends a function. */
532 if (info
->within_function
)
538 && info
->function_end
!= (bfd_vma
) -1
539 && info
->function_end
< endval
)
540 endval
= info
->function_end
;
541 if (! stab_emit_pending_vars (dhandle
, info
)
542 || ! debug_end_function (dhandle
, endval
))
544 info
->within_function
= false;
545 info
->function_end
= (bfd_vma
) -1;
548 /* An empty string is emitted by gcc at the end of a compilation
553 /* Just accumulate strings until we see a non N_SO symbol. If
554 the string starts with a directory separator or some other
555 form of absolute path specification, we discard the previously
556 accumulated strings. */
557 if (info
->so_string
== NULL
)
558 info
->so_string
= xstrdup (string
);
565 if (IS_ABSOLUTE_PATH (string
))
566 info
->so_string
= xstrdup (string
);
568 info
->so_string
= concat (info
->so_string
, string
,
569 (const char *) NULL
);
573 info
->so_value
= value
;
578 /* Start an include file. */
579 if (! debug_start_source (dhandle
, string
))
584 /* Start an include file which may be replaced. */
585 push_bincl (info
, string
, value
);
586 if (! debug_start_source (dhandle
, string
))
591 /* End an N_BINCL include. */
592 if (! debug_start_source (dhandle
, pop_bincl (info
)))
597 /* This is a duplicate of a header file named by N_BINCL which
598 was eliminated by the linker. */
599 if (! find_excl (info
, string
, value
))
604 if (! debug_record_line (dhandle
, desc
,
605 value
+ info
->function_start_offset
))
610 if (! debug_start_common_block (dhandle
, string
))
615 if (! debug_end_common_block (dhandle
, string
))
622 if (info
->within_function
)
624 /* This always marks the end of a function; we don't
625 need to worry about info->function_end. */
627 value
+= info
->function_start_offset
;
628 if (! stab_emit_pending_vars (dhandle
, info
)
629 || ! debug_end_function (dhandle
, value
))
631 info
->within_function
= false;
632 info
->function_end
= (bfd_vma
) -1;
637 /* A const static symbol in the .text section will have an N_FUN
638 entry. We need to use these to mark the end of the function,
639 in case we are looking at gcc output before it was changed to
640 always emit an empty N_FUN. We can't call debug_end_function
641 here, because it might be a local static symbol. */
642 if (info
->within_function
643 && (info
->function_end
== (bfd_vma
) -1
644 || value
< info
->function_end
))
645 info
->function_end
= value
;
648 /* FIXME: gdb checks the string for N_STSYM, N_LCSYM or N_ROSYM
649 symbols, and if it does not start with :S, gdb relocates the
650 value to the start of the section. gcc always seems to use
651 :S, so we don't worry about this. */
657 colon
= strchr (string
, ':');
659 && (colon
[1] == 'f' || colon
[1] == 'F'))
661 if (info
->within_function
)
666 if (info
->function_end
!= (bfd_vma
) -1
667 && info
->function_end
< endval
)
668 endval
= info
->function_end
;
669 if (! stab_emit_pending_vars (dhandle
, info
)
670 || ! debug_end_function (dhandle
, endval
))
672 info
->function_end
= (bfd_vma
) -1;
674 /* For stabs in sections, line numbers and block addresses
675 are offsets from the start of the function. */
677 info
->function_start_offset
= value
;
678 info
->within_function
= true;
681 if (! parse_stab_string (dhandle
, info
, type
, desc
, value
, string
))
687 if (string
!= NULL
&& strcmp (string
, "gcc2_compiled.") == 0)
688 info
->gcc_compiled
= 2;
689 else if (string
!= NULL
&& strcmp (string
, "gcc_compiled.") == 0)
690 info
->gcc_compiled
= 1;
692 info
->n_opt_found
= true;
705 /* Parse the stabs string. */
708 parse_stab_string (dhandle
, info
, stabtype
, desc
, value
, string
)
710 struct stab_handle
*info
;
721 boolean self_crossref
;
725 p
= strchr (string
, ':');
740 /* GCC 2.x puts the line number in desc. SunOS apparently puts in
741 the number of bytes occupied by a type or object, which we
743 if (info
->gcc_compiled
>= 2)
748 /* FIXME: Sometimes the special C++ names start with '.'. */
750 if (string
[0] == '$')
758 /* Was: name = "vptr"; */
764 /* This was an anonymous type that was never fixed up. */
767 /* SunPRO (3.0 at least) static variable encoding. */
770 warn_stab (string
, _("unknown C++ encoded name"));
777 if (p
== string
|| (string
[0] == ' ' && p
== string
+ 1))
780 name
= savestring (string
, p
- string
);
784 if (ISDIGIT (*p
) || *p
== '(' || *p
== '-')
792 /* c is a special case, not followed by a type-number.
793 SYMBOL:c=iVALUE for an integer constant symbol.
794 SYMBOL:c=rVALUE for a floating constant symbol.
795 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
796 e.g. "b:c=e6,0" for "const b = blob1"
797 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
807 /* Floating point constant. */
808 if (! debug_record_float_const (dhandle
, name
, atof (p
)))
812 /* Integer constant. */
813 /* Defining integer constants this way is kind of silly,
814 since 'e' constants allows the compiler to give not only
815 the value, but the type as well. C has at least int,
816 long, unsigned int, and long long as constant types;
817 other languages probably should have at least unsigned as
818 well as signed constants. */
819 if (! debug_record_int_const (dhandle
, name
, atoi (p
)))
823 /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value
824 can be represented as integral.
825 e.g. "b:c=e6,0" for "const b = blob1"
826 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
827 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
,
828 &p
, (debug_type
**) NULL
);
829 if (dtype
== DEBUG_TYPE_NULL
)
836 if (! debug_record_typed_const (dhandle
, name
, dtype
, atoi (p
)))
847 /* The name of a caught exception. */
848 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
,
849 &p
, (debug_type
**) NULL
);
850 if (dtype
== DEBUG_TYPE_NULL
)
852 if (! debug_record_label (dhandle
, name
, dtype
, value
))
858 /* A function definition. */
859 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
860 (debug_type
**) NULL
);
861 if (dtype
== DEBUG_TYPE_NULL
)
863 if (! debug_record_function (dhandle
, name
, dtype
, type
== 'F', value
))
866 /* Sun acc puts declared types of arguments here. We don't care
867 about their actual types (FIXME -- we should remember the whole
868 function prototype), but the list may define some new types
869 that we have to remember, so we must scan it now. */
873 if (parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
874 (debug_type
**) NULL
)
887 /* A global symbol. The value must be extracted from the
889 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
890 (debug_type
**) NULL
);
891 if (dtype
== DEBUG_TYPE_NULL
)
893 leading
= bfd_get_symbol_leading_char (info
->abfd
);
894 for (c
= info
->symcount
, ps
= info
->syms
; c
> 0; --c
, ++ps
)
898 n
= bfd_asymbol_name (*ps
);
899 if (leading
!= '\0' && *n
== leading
)
901 if (*n
== *name
&& strcmp (n
, name
) == 0)
905 value
= bfd_asymbol_value (*ps
);
906 if (! stab_record_variable (dhandle
, info
, name
, dtype
, DEBUG_GLOBAL
,
912 /* This case is faked by a conditional above, when there is no
913 code letter in the dbx data. Dbx data never actually
917 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
918 (debug_type
**) NULL
);
919 if (dtype
== DEBUG_TYPE_NULL
)
921 if (! stab_record_variable (dhandle
, info
, name
, dtype
, DEBUG_LOCAL
,
927 /* A function parameter. */
929 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
930 (debug_type
**) NULL
);
933 /* pF is a two-letter code that means a function parameter in
934 Fortran. The type-number specifies the type of the return
935 value. Translate it into a pointer-to-function type. */
937 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
938 (debug_type
**) NULL
);
939 if (dtype
!= DEBUG_TYPE_NULL
)
943 ftype
= debug_make_function_type (dhandle
, dtype
,
944 (debug_type
*) NULL
, false);
945 dtype
= debug_make_pointer_type (dhandle
, ftype
);
948 if (dtype
== DEBUG_TYPE_NULL
)
950 if (! debug_record_parameter (dhandle
, name
, dtype
, DEBUG_PARM_STACK
,
954 /* FIXME: At this point gdb considers rearranging the parameter
955 address on a big endian machine if it is smaller than an int.
956 We have no way to do that, since we don't really know much
962 if (stabtype
== N_FUN
)
964 /* Prototype of a function referenced by this file. */
968 if (parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
969 (debug_type
**) NULL
)
977 /* Parameter which is in a register. */
978 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
979 (debug_type
**) NULL
);
980 if (dtype
== DEBUG_TYPE_NULL
)
982 if (! debug_record_parameter (dhandle
, name
, dtype
, DEBUG_PARM_REG
,
988 /* Register variable (either global or local). */
989 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
990 (debug_type
**) NULL
);
991 if (dtype
== DEBUG_TYPE_NULL
)
993 if (! stab_record_variable (dhandle
, info
, name
, dtype
, DEBUG_REGISTER
,
997 /* FIXME: At this point gdb checks to combine pairs of 'p' and
998 'r' stabs into a single 'P' stab. */
1003 /* Static symbol at top level of file */
1004 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
1005 (debug_type
**) NULL
);
1006 if (dtype
== DEBUG_TYPE_NULL
)
1008 if (! stab_record_variable (dhandle
, info
, name
, dtype
, DEBUG_STATIC
,
1015 dtype
= parse_stab_type (dhandle
, info
, name
, &p
, &slot
);
1016 if (dtype
== DEBUG_TYPE_NULL
)
1020 /* A nameless type. Nothing to do. */
1024 dtype
= debug_name_type (dhandle
, name
, dtype
);
1025 if (dtype
== DEBUG_TYPE_NULL
)
1034 /* Struct, union, or enum tag. For GNU C++, this can be be followed
1035 by 't' which means we are typedef'ing it as well. */
1039 /* FIXME: gdb sets synonym to true if the current language
1048 dtype
= parse_stab_type (dhandle
, info
, name
, &p
, &slot
);
1049 if (dtype
== DEBUG_TYPE_NULL
)
1054 /* INFO->SELF_CROSSREF is set by parse_stab_type if this type is
1055 a cross reference to itself. These are generated by some
1057 self_crossref
= info
->self_crossref
;
1059 dtype
= debug_tag_type (dhandle
, name
, dtype
);
1060 if (dtype
== DEBUG_TYPE_NULL
)
1065 /* See if we have a cross reference to this tag which we can now
1066 fill in. Avoid filling in a cross reference to ourselves,
1067 because that would lead to circular debugging information. */
1068 if (! self_crossref
)
1070 register struct stab_tag
**pst
;
1072 for (pst
= &info
->tags
; *pst
!= NULL
; pst
= &(*pst
)->next
)
1074 if ((*pst
)->name
[0] == name
[0]
1075 && strcmp ((*pst
)->name
, name
) == 0)
1077 (*pst
)->slot
= dtype
;
1078 *pst
= (*pst
)->next
;
1086 dtype
= debug_name_type (dhandle
, name
, dtype
);
1087 if (dtype
== DEBUG_TYPE_NULL
)
1097 /* Static symbol of local scope */
1098 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
1099 (debug_type
**) NULL
);
1100 if (dtype
== DEBUG_TYPE_NULL
)
1102 /* FIXME: gdb checks os9k_stabs here. */
1103 if (! stab_record_variable (dhandle
, info
, name
, dtype
,
1104 DEBUG_LOCAL_STATIC
, value
))
1109 /* Reference parameter. */
1110 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
1111 (debug_type
**) NULL
);
1112 if (dtype
== DEBUG_TYPE_NULL
)
1114 if (! debug_record_parameter (dhandle
, name
, dtype
, DEBUG_PARM_REFERENCE
,
1120 /* Reference parameter which is in a register. */
1121 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
1122 (debug_type
**) NULL
);
1123 if (dtype
== DEBUG_TYPE_NULL
)
1125 if (! debug_record_parameter (dhandle
, name
, dtype
, DEBUG_PARM_REF_REG
,
1131 /* This is used by Sun FORTRAN for "function result value".
1132 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
1133 that Pascal uses it too, but when I tried it Pascal used
1134 "x:3" (local symbol) instead. */
1135 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
1136 (debug_type
**) NULL
);
1137 if (dtype
== DEBUG_TYPE_NULL
)
1139 if (! stab_record_variable (dhandle
, info
, name
, dtype
, DEBUG_LOCAL
,
1149 /* FIXME: gdb converts structure values to structure pointers in a
1150 couple of cases, depending upon the target. */
1155 /* Parse a stabs type. The typename argument is non-NULL if this is a
1156 typedef or a tag definition. The pp argument points to the stab
1157 string, and is updated. The slotp argument points to a place to
1158 store the slot used if the type is being defined. */
1161 parse_stab_type (dhandle
, info
, typename
, pp
, slotp
)
1163 struct stab_handle
*info
;
1164 const char *typename
;
1183 info
->self_crossref
= false;
1185 /* Read type number if present. The type number may be omitted.
1186 for instance in a two-dimensional array declared with type
1187 "ar1;1;10;ar1;1;10;4". */
1188 if (! ISDIGIT (**pp
) && **pp
!= '(' && **pp
!= '-')
1190 /* 'typenums=' not present, type is anonymous. Read and return
1191 the definition, but don't put it in the type vector. */
1192 typenums
[0] = typenums
[1] = -1;
1196 if (! parse_stab_type_number (pp
, typenums
))
1197 return DEBUG_TYPE_NULL
;
1201 /* Type is not being defined here. Either it already
1202 exists, or this is a forward reference to it. */
1203 return stab_find_type (dhandle
, info
, typenums
);
1206 /* Only set the slot if the type is being defined. This means
1207 that the mapping from type numbers to types will only record
1208 the name of the typedef which defines a type. If we don't do
1209 this, then something like
1212 will record that i is of type foo. Unfortunately, stabs
1213 information is ambiguous about variable types. For this code,
1217 the stabs information records both i and j as having the same
1218 type. This could be fixed by patching the compiler. */
1219 if (slotp
!= NULL
&& typenums
[0] >= 0 && typenums
[1] >= 0)
1220 *slotp
= stab_find_slot (info
, typenums
);
1222 /* Type is being defined here. */
1228 const char *p
= *pp
+ 1;
1231 if (ISDIGIT (*p
) || *p
== '(' || *p
== '-')
1237 /* Type attributes. */
1240 for (; *p
!= ';'; ++p
)
1245 return DEBUG_TYPE_NULL
;
1253 size
= atoi (attr
+ 1);
1254 size
/= 8; /* Size is in bits. We store it in bytes. */
1264 /* Ignore unrecognized type attributes, so future
1265 compilers can invent new ones. */
1278 enum debug_type_kind code
;
1279 const char *q1
, *q2
, *p
;
1281 /* A cross reference to another type. */
1286 code
= DEBUG_KIND_STRUCT
;
1289 code
= DEBUG_KIND_UNION
;
1292 code
= DEBUG_KIND_ENUM
;
1295 /* Complain and keep going, so compilers can invent new
1296 cross-reference types. */
1297 warn_stab (orig
, _("unrecognized cross reference type"));
1298 code
= DEBUG_KIND_STRUCT
;
1303 q1
= strchr (*pp
, '<');
1304 p
= strchr (*pp
, ':');
1308 return DEBUG_TYPE_NULL
;
1310 if (q1
!= NULL
&& p
> q1
&& p
[1] == ':')
1314 for (q2
= q1
; *q2
!= '\0'; ++q2
)
1318 else if (*q2
== '>')
1320 else if (*q2
== ':' && nest
== 0)
1327 return DEBUG_TYPE_NULL
;
1331 /* Some versions of g++ can emit stabs like
1333 which define structures in terms of themselves. We need to
1334 tell the caller to avoid building a circular structure. */
1335 if (typename
!= NULL
1336 && strncmp (typename
, *pp
, p
- *pp
) == 0
1337 && typename
[p
- *pp
] == '\0')
1338 info
->self_crossref
= true;
1340 dtype
= stab_find_tagged_type (dhandle
, info
, *pp
, p
- *pp
, code
);
1362 /* This type is defined as another type. */
1367 /* Peek ahead at the number to detect void. */
1368 if (! parse_stab_type_number (pp
, xtypenums
))
1369 return DEBUG_TYPE_NULL
;
1371 if (typenums
[0] == xtypenums
[0] && typenums
[1] == xtypenums
[1])
1373 /* This type is being defined as itself, which means that
1375 dtype
= debug_make_void_type (dhandle
);
1381 /* Go back to the number and have parse_stab_type get it.
1382 This means that we can deal with something like
1383 t(1,2)=(3,4)=... which the Lucid compiler uses. */
1384 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
,
1385 pp
, (debug_type
**) NULL
);
1386 if (dtype
== DEBUG_TYPE_NULL
)
1387 return DEBUG_TYPE_NULL
;
1390 if (typenums
[0] != -1)
1392 if (! stab_record_type (dhandle
, info
, typenums
, dtype
))
1393 return DEBUG_TYPE_NULL
;
1400 dtype
= debug_make_pointer_type (dhandle
,
1401 parse_stab_type (dhandle
, info
,
1402 (const char *) NULL
,
1404 (debug_type
**) NULL
));
1408 /* Reference to another type. */
1409 dtype
= (debug_make_reference_type
1411 parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
1412 (debug_type
**) NULL
)));
1416 /* Function returning another type. */
1417 /* FIXME: gdb checks os9k_stabs here. */
1418 dtype
= (debug_make_function_type
1420 parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
1421 (debug_type
**) NULL
),
1422 (debug_type
*) NULL
, false));
1426 /* Const qualifier on some type (Sun). */
1427 /* FIXME: gdb accepts 'c' here if os9k_stabs. */
1428 dtype
= debug_make_const_type (dhandle
,
1429 parse_stab_type (dhandle
, info
,
1430 (const char *) NULL
,
1432 (debug_type
**) NULL
));
1436 /* Volatile qual on some type (Sun). */
1437 /* FIXME: gdb accepts 'i' here if os9k_stabs. */
1438 dtype
= (debug_make_volatile_type
1440 parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
1441 (debug_type
**) NULL
)));
1445 /* Offset (class & variable) type. This is used for a pointer
1446 relative to an object. */
1453 domain
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
1454 (debug_type
**) NULL
);
1455 if (domain
== DEBUG_TYPE_NULL
)
1456 return DEBUG_TYPE_NULL
;
1461 return DEBUG_TYPE_NULL
;
1465 memtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
1466 (debug_type
**) NULL
);
1467 if (memtype
== DEBUG_TYPE_NULL
)
1468 return DEBUG_TYPE_NULL
;
1470 dtype
= debug_make_offset_type (dhandle
, domain
, memtype
);
1475 /* Method (class & fn) type. */
1478 debug_type return_type
;
1481 return_type
= parse_stab_type (dhandle
, info
, (const char *) NULL
,
1482 pp
, (debug_type
**) NULL
);
1483 if (return_type
== DEBUG_TYPE_NULL
)
1484 return DEBUG_TYPE_NULL
;
1488 return DEBUG_TYPE_NULL
;
1491 dtype
= debug_make_method_type (dhandle
, return_type
,
1493 (debug_type
*) NULL
, false);
1498 debug_type return_type
;
1504 domain
= parse_stab_type (dhandle
, info
, (const char *) NULL
,
1505 pp
, (debug_type
**) NULL
);
1506 if (domain
== DEBUG_TYPE_NULL
)
1507 return DEBUG_TYPE_NULL
;
1512 return DEBUG_TYPE_NULL
;
1516 return_type
= parse_stab_type (dhandle
, info
, (const char *) NULL
,
1517 pp
, (debug_type
**) NULL
);
1518 if (return_type
== DEBUG_TYPE_NULL
)
1519 return DEBUG_TYPE_NULL
;
1522 args
= (debug_type
*) xmalloc (alloc
* sizeof *args
);
1529 return DEBUG_TYPE_NULL
;
1536 args
= ((debug_type
*)
1537 xrealloc ((PTR
) args
, alloc
* sizeof *args
));
1540 args
[n
] = parse_stab_type (dhandle
, info
, (const char *) NULL
,
1541 pp
, (debug_type
**) NULL
);
1542 if (args
[n
] == DEBUG_TYPE_NULL
)
1543 return DEBUG_TYPE_NULL
;
1548 /* If the last type is not void, then this function takes a
1549 variable number of arguments. Otherwise, we must strip
1552 || debug_get_type_kind (dhandle
, args
[n
- 1]) != DEBUG_KIND_VOID
)
1560 args
[n
] = DEBUG_TYPE_NULL
;
1562 dtype
= debug_make_method_type (dhandle
, return_type
, domain
, args
,
1569 dtype
= parse_stab_range_type (dhandle
, info
, typename
, pp
, typenums
);
1573 /* FIXME: gdb checks os9k_stabs here. */
1574 /* Sun ACC builtin int type. */
1575 dtype
= parse_stab_sun_builtin_type (dhandle
, pp
);
1579 /* Sun ACC builtin float type. */
1580 dtype
= parse_stab_sun_floating_type (dhandle
, pp
);
1584 /* Enumeration type. */
1585 dtype
= parse_stab_enum_type (dhandle
, pp
);
1590 /* Struct or union type. */
1591 dtype
= parse_stab_struct_type (dhandle
, info
, typename
, pp
,
1592 descriptor
== 's', typenums
);
1600 return DEBUG_TYPE_NULL
;
1604 dtype
= parse_stab_array_type (dhandle
, info
, pp
, stringp
);
1608 dtype
= debug_make_set_type (dhandle
,
1609 parse_stab_type (dhandle
, info
,
1610 (const char *) NULL
,
1612 (debug_type
**) NULL
),
1618 return DEBUG_TYPE_NULL
;
1621 if (dtype
== DEBUG_TYPE_NULL
)
1622 return DEBUG_TYPE_NULL
;
1624 if (typenums
[0] != -1)
1626 if (! stab_record_type (dhandle
, info
, typenums
, dtype
))
1627 return DEBUG_TYPE_NULL
;
1632 if (! debug_record_type_size (dhandle
, dtype
, (unsigned int) size
))
1633 return DEBUG_TYPE_NULL
;
1639 /* Read a number by which a type is referred to in dbx data, or
1640 perhaps read a pair (FILENUM, TYPENUM) in parentheses. Just a
1641 single number N is equivalent to (0,N). Return the two numbers by
1642 storing them in the vector TYPENUMS. */
1645 parse_stab_type_number (pp
, typenums
)
1656 typenums
[1] = (int) parse_number (pp
, (boolean
*) NULL
);
1661 typenums
[0] = (int) parse_number (pp
, (boolean
*) NULL
);
1668 typenums
[1] = (int) parse_number (pp
, (boolean
*) NULL
);
1680 /* Parse a range type. */
1683 parse_stab_range_type (dhandle
, info
, typename
, pp
, typenums
)
1685 struct stab_handle
*info
;
1686 const char *typename
;
1688 const int *typenums
;
1692 boolean self_subrange
;
1693 debug_type index_type
;
1694 const char *s2
, *s3
;
1695 bfd_signed_vma n2
, n3
;
1700 index_type
= DEBUG_TYPE_NULL
;
1702 /* First comes a type we are a subrange of.
1703 In C it is usually 0, 1 or the type being defined. */
1704 if (! parse_stab_type_number (pp
, rangenums
))
1705 return DEBUG_TYPE_NULL
;
1707 self_subrange
= (rangenums
[0] == typenums
[0]
1708 && rangenums
[1] == typenums
[1]);
1713 index_type
= parse_stab_type (dhandle
, info
, (const char *) NULL
,
1714 pp
, (debug_type
**) NULL
);
1715 if (index_type
== DEBUG_TYPE_NULL
)
1716 return DEBUG_TYPE_NULL
;
1722 /* The remaining two operands are usually lower and upper bounds of
1723 the range. But in some special cases they mean something else. */
1725 n2
= parse_number (pp
, &ov2
);
1729 return DEBUG_TYPE_NULL
;
1734 n3
= parse_number (pp
, &ov3
);
1738 return DEBUG_TYPE_NULL
;
1744 /* gcc will emit range stabs for long long types. Handle this
1745 as a special case. FIXME: This needs to be more general. */
1746 #define LLLOW "01000000000000000000000;"
1747 #define LLHIGH "0777777777777777777777;"
1748 #define ULLHIGH "01777777777777777777777;"
1749 if (index_type
== DEBUG_TYPE_NULL
)
1751 if (strncmp (s2
, LLLOW
, sizeof LLLOW
- 1) == 0
1752 && strncmp (s3
, LLHIGH
, sizeof LLHIGH
- 1) == 0)
1753 return debug_make_int_type (dhandle
, 8, false);
1756 && strncmp (s3
, ULLHIGH
, sizeof ULLHIGH
- 1) == 0)
1757 return debug_make_int_type (dhandle
, 8, true);
1760 warn_stab (orig
, _("numeric overflow"));
1763 if (index_type
== DEBUG_TYPE_NULL
)
1765 /* A type defined as a subrange of itself, with both bounds 0,
1767 if (self_subrange
&& n2
== 0 && n3
== 0)
1768 return debug_make_void_type (dhandle
);
1770 /* A type defined as a subrange of itself, with n2 positive and
1771 n3 zero, is a complex type, and n2 is the number of bytes. */
1772 if (self_subrange
&& n3
== 0 && n2
> 0)
1773 return debug_make_complex_type (dhandle
, n2
);
1775 /* If n3 is zero and n2 is positive, this is a floating point
1776 type, and n2 is the number of bytes. */
1777 if (n3
== 0 && n2
> 0)
1778 return debug_make_float_type (dhandle
, n2
);
1780 /* If the upper bound is -1, this is an unsigned int. */
1781 if (n2
== 0 && n3
== -1)
1783 /* When gcc is used with -gstabs, but not -gstabs+, it will emit
1784 long long int:t6=r1;0;-1;
1785 long long unsigned int:t7=r1;0;-1;
1786 We hack here to handle this reasonably. */
1787 if (typename
!= NULL
)
1789 if (strcmp (typename
, "long long int") == 0)
1790 return debug_make_int_type (dhandle
, 8, false);
1791 else if (strcmp (typename
, "long long unsigned int") == 0)
1792 return debug_make_int_type (dhandle
, 8, true);
1794 /* FIXME: The size here really depends upon the target. */
1795 return debug_make_int_type (dhandle
, 4, true);
1798 /* A range of 0 to 127 is char. */
1799 if (self_subrange
&& n2
== 0 && n3
== 127)
1800 return debug_make_int_type (dhandle
, 1, false);
1802 /* FIXME: gdb checks for the language CHILL here. */
1807 return debug_make_int_type (dhandle
, - n3
, true);
1808 else if (n3
== 0xff)
1809 return debug_make_int_type (dhandle
, 1, true);
1810 else if (n3
== 0xffff)
1811 return debug_make_int_type (dhandle
, 2, true);
1812 else if (n3
== (bfd_signed_vma
) 0xffffffff)
1813 return debug_make_int_type (dhandle
, 4, true);
1815 else if (n3
== ((((bfd_signed_vma
) 0xffffffff) << 32) | 0xffffffff))
1816 return debug_make_int_type (dhandle
, 8, true);
1821 && (self_subrange
|| n2
== -8))
1822 return debug_make_int_type (dhandle
, - n2
, true);
1823 else if (n2
== - n3
- 1 || n2
== n3
+ 1)
1826 return debug_make_int_type (dhandle
, 1, false);
1827 else if (n3
== 0x7fff)
1828 return debug_make_int_type (dhandle
, 2, false);
1829 else if (n3
== 0x7fffffff)
1830 return debug_make_int_type (dhandle
, 4, false);
1832 else if (n3
== ((((bfd_vma
) 0x7fffffff) << 32) | 0xffffffff))
1833 return debug_make_int_type (dhandle
, 8, false);
1838 /* At this point I don't have the faintest idea how to deal with a
1839 self_subrange type; I'm going to assume that this is used as an
1840 idiom, and that all of them are special cases. So . . . */
1844 return DEBUG_TYPE_NULL
;
1847 index_type
= stab_find_type (dhandle
, info
, rangenums
);
1848 if (index_type
== DEBUG_TYPE_NULL
)
1850 /* Does this actually ever happen? Is that why we are worrying
1851 about dealing with it rather than just calling error_type? */
1852 warn_stab (orig
, _("missing index type"));
1853 index_type
= debug_make_int_type (dhandle
, 4, false);
1856 return debug_make_range_type (dhandle
, index_type
, n2
, n3
);
1859 /* Sun's ACC uses a somewhat saner method for specifying the builtin
1860 typedefs in every file (for int, long, etc):
1862 type = b <signed> <width>; <offset>; <nbits>
1863 signed = u or s. Possible c in addition to u or s (for char?).
1864 offset = offset from high order bit to start bit of type.
1865 width is # bytes in object of this type, nbits is # bits in type.
1867 The width/offset stuff appears to be for small objects stored in
1868 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
1872 parse_stab_sun_builtin_type (dhandle
, pp
)
1892 return DEBUG_TYPE_NULL
;
1896 /* For some odd reason, all forms of char put a c here. This is strange
1897 because no other type has this honor. We can safely ignore this because
1898 we actually determine 'char'acterness by the number of bits specified in
1903 /* The first number appears to be the number of bytes occupied
1904 by this type, except that unsigned short is 4 instead of 2.
1905 Since this information is redundant with the third number,
1906 we will ignore it. */
1907 (void) parse_number (pp
, (boolean
*) NULL
);
1911 return DEBUG_TYPE_NULL
;
1915 /* The second number is always 0, so ignore it too. */
1916 (void) parse_number (pp
, (boolean
*) NULL
);
1920 return DEBUG_TYPE_NULL
;
1924 /* The third number is the number of bits for this type. */
1925 bits
= parse_number (pp
, (boolean
*) NULL
);
1927 /* The type *should* end with a semicolon. If it are embedded
1928 in a larger type the semicolon may be the only way to know where
1929 the type ends. If this type is at the end of the stabstring we
1930 can deal with the omitted semicolon (but we don't have to like
1931 it). Don't bother to complain(), Sun's compiler omits the semicolon
1937 return debug_make_void_type (dhandle
);
1939 return debug_make_int_type (dhandle
, bits
/ 8, unsignedp
);
1942 /* Parse a builtin floating type generated by the Sun compiler. */
1945 parse_stab_sun_floating_type (dhandle
, pp
)
1955 /* The first number has more details about the type, for example
1957 details
= parse_number (pp
, (boolean
*) NULL
);
1961 return DEBUG_TYPE_NULL
;
1964 /* The second number is the number of bytes occupied by this type */
1965 bytes
= parse_number (pp
, (boolean
*) NULL
);
1969 return DEBUG_TYPE_NULL
;
1972 if (details
== NF_COMPLEX
1973 || details
== NF_COMPLEX16
1974 || details
== NF_COMPLEX32
)
1975 return debug_make_complex_type (dhandle
, bytes
);
1977 return debug_make_float_type (dhandle
, bytes
);
1980 /* Handle an enum type. */
1983 parse_stab_enum_type (dhandle
, pp
)
1989 bfd_signed_vma
*values
;
1995 /* FIXME: gdb checks os9k_stabs here. */
1997 /* The aix4 compiler emits an extra field before the enum members;
1998 my guess is it's a type of some sort. Just ignore it. */
2006 /* Read the value-names and their values.
2007 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
2008 A semicolon or comma instead of a NAME means the end. */
2010 names
= (const char **) xmalloc (alloc
* sizeof *names
);
2011 values
= (bfd_signed_vma
*) xmalloc (alloc
* sizeof *values
);
2013 while (**pp
!= '\0' && **pp
!= ';' && **pp
!= ',')
2023 name
= savestring (*pp
, p
- *pp
);
2026 val
= (bfd_signed_vma
) parse_number (pp
, (boolean
*) NULL
);
2030 return DEBUG_TYPE_NULL
;
2037 names
= ((const char **)
2038 xrealloc ((PTR
) names
, alloc
* sizeof *names
));
2039 values
= ((bfd_signed_vma
*)
2040 xrealloc ((PTR
) values
, alloc
* sizeof *values
));
2054 return debug_make_enum_type (dhandle
, names
, values
);
2057 /* Read the description of a structure (or union type) and return an object
2058 describing the type.
2060 PP points to a character pointer that points to the next unconsumed token
2061 in the the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
2062 *PP will point to "4a:1,0,32;;". */
2065 parse_stab_struct_type (dhandle
, info
, tagname
, pp
, structp
, typenums
)
2067 struct stab_handle
*info
;
2068 const char *tagname
;
2071 const int *typenums
;
2075 debug_baseclass
*baseclasses
;
2076 debug_field
*fields
;
2078 debug_method
*methods
;
2079 debug_type vptrbase
;
2085 size
= parse_number (pp
, (boolean
*) NULL
);
2087 /* Get the other information. */
2088 if (! parse_stab_baseclasses (dhandle
, info
, pp
, &baseclasses
)
2089 || ! parse_stab_struct_fields (dhandle
, info
, pp
, &fields
, &statics
)
2090 || ! parse_stab_members (dhandle
, info
, tagname
, pp
, typenums
, &methods
)
2091 || ! parse_stab_tilde_field (dhandle
, info
, pp
, typenums
, &vptrbase
,
2093 return DEBUG_TYPE_NULL
;
2096 && baseclasses
== NULL
2098 && vptrbase
== DEBUG_TYPE_NULL
2100 return debug_make_struct_type (dhandle
, structp
, size
, fields
);
2102 return debug_make_object_type (dhandle
, structp
, size
, fields
, baseclasses
,
2103 methods
, vptrbase
, ownvptr
);
2106 /* The stabs for C++ derived classes contain baseclass information which
2107 is marked by a '!' character after the total size. This function is
2108 called when we encounter the baseclass marker, and slurps up all the
2109 baseclass information.
2111 Immediately following the '!' marker is the number of base classes that
2112 the class is derived from, followed by information for each base class.
2113 For each base class, there are two visibility specifiers, a bit offset
2114 to the base class information within the derived class, a reference to
2115 the type for the base class, and a terminating semicolon.
2117 A typical example, with two base classes, would be "!2,020,19;0264,21;".
2119 Baseclass information marker __________________|| | | | | | |
2120 Number of baseclasses __________________________| | | | | | |
2121 Visibility specifiers (2) ________________________| | | | | |
2122 Offset in bits from start of class _________________| | | | |
2123 Type number for base class ___________________________| | | |
2124 Visibility specifiers (2) _______________________________| | |
2125 Offset in bits from start of class ________________________| |
2126 Type number of base class ____________________________________|
2128 Return true for success, false for failure. */
2131 parse_stab_baseclasses (dhandle
, info
, pp
, retp
)
2133 struct stab_handle
*info
;
2135 debug_baseclass
**retp
;
2139 debug_baseclass
*classes
;
2147 /* No base classes. */
2152 c
= (unsigned int) parse_number (pp
, (boolean
*) NULL
);
2161 classes
= (debug_baseclass
*) xmalloc ((c
+ 1) * sizeof (**retp
));
2163 for (i
= 0; i
< c
; i
++)
2166 enum debug_visibility visibility
;
2179 warn_stab (orig
, _("unknown virtual character for baseclass"));
2188 visibility
= DEBUG_VISIBILITY_PRIVATE
;
2191 visibility
= DEBUG_VISIBILITY_PROTECTED
;
2194 visibility
= DEBUG_VISIBILITY_PUBLIC
;
2197 warn_stab (orig
, _("unknown visibility character for baseclass"));
2198 visibility
= DEBUG_VISIBILITY_PUBLIC
;
2203 /* The remaining value is the bit offset of the portion of the
2204 object corresponding to this baseclass. Always zero in the
2205 absence of multiple inheritance. */
2206 bitpos
= parse_number (pp
, (boolean
*) NULL
);
2214 type
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
2215 (debug_type
**) NULL
);
2216 if (type
== DEBUG_TYPE_NULL
)
2219 classes
[i
] = debug_make_baseclass (dhandle
, type
, bitpos
, virtual,
2221 if (classes
[i
] == DEBUG_BASECLASS_NULL
)
2229 classes
[i
] = DEBUG_BASECLASS_NULL
;
2236 /* Read struct or class data fields. They have the form:
2238 NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
2240 At the end, we see a semicolon instead of a field.
2242 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
2245 The optional VISIBILITY is one of:
2247 '/0' (VISIBILITY_PRIVATE)
2248 '/1' (VISIBILITY_PROTECTED)
2249 '/2' (VISIBILITY_PUBLIC)
2250 '/9' (VISIBILITY_IGNORE)
2252 or nothing, for C style fields with public visibility.
2254 Returns 1 for success, 0 for failure. */
2257 parse_stab_struct_fields (dhandle
, info
, pp
, retp
, staticsp
)
2259 struct stab_handle
*info
;
2266 debug_field
*fields
;
2277 fields
= (debug_field
*) xmalloc (alloc
* sizeof *fields
);
2280 /* FIXME: gdb checks os9k_stabs here. */
2284 /* Add 1 to c to leave room for NULL pointer at end. */
2288 fields
= ((debug_field
*)
2289 xrealloc ((PTR
) fields
, alloc
* sizeof *fields
));
2292 /* If it starts with CPLUS_MARKER it is a special abbreviation,
2293 unless the CPLUS_MARKER is followed by an underscore, in
2294 which case it is just the name of an anonymous type, which we
2295 should handle like any other type name. We accept either '$'
2296 or '.', because a field name can never contain one of these
2297 characters except as a CPLUS_MARKER. */
2299 if ((*p
== '$' || *p
== '.') && p
[1] != '_')
2302 if (! parse_stab_cpp_abbrev (dhandle
, info
, pp
, fields
+ c
))
2308 /* Look for the ':' that separates the field name from the field
2309 values. Data members are delimited by a single ':', while member
2310 functions are delimited by a pair of ':'s. When we hit the member
2311 functions (if any), terminate scan loop and return. */
2313 p
= strchr (p
, ':');
2323 if (! parse_stab_one_struct_field (dhandle
, info
, pp
, p
, fields
+ c
,
2330 fields
[c
] = DEBUG_FIELD_NULL
;
2337 /* Special GNU C++ name. */
2340 parse_stab_cpp_abbrev (dhandle
, info
, pp
, retp
)
2342 struct stab_handle
*info
;
2350 const char *typename
;
2354 *retp
= DEBUG_FIELD_NULL
;
2368 /* At this point, *pp points to something like "22:23=*22...", where
2369 the type number before the ':' is the "context" and everything
2370 after is a regular type definition. Lookup the type, find it's
2371 name, and construct the field name. */
2373 context
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
2374 (debug_type
**) NULL
);
2375 if (context
== DEBUG_TYPE_NULL
)
2381 /* $vf -- a virtual function table pointer. */
2385 /* $vb -- a virtual bsomethingorother */
2386 typename
= debug_get_type_name (dhandle
, context
);
2387 if (typename
== NULL
)
2389 warn_stab (orig
, _("unnamed $vb type"));
2392 name
= concat ("_vb$", typename
, (const char *) NULL
);
2395 warn_stab (orig
, _("unrecognized C++ abbreviation"));
2396 name
= "INVALID_CPLUSPLUS_ABBREV";
2407 type
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
2408 (debug_type
**) NULL
);
2416 bitpos
= parse_number (pp
, (boolean
*) NULL
);
2424 *retp
= debug_make_field (dhandle
, name
, type
, bitpos
, 0,
2425 DEBUG_VISIBILITY_PRIVATE
);
2426 if (*retp
== DEBUG_FIELD_NULL
)
2432 /* Parse a single field in a struct or union. */
2435 parse_stab_one_struct_field (dhandle
, info
, pp
, p
, retp
, staticsp
)
2437 struct stab_handle
*info
;
2445 enum debug_visibility visibility
;
2452 /* FIXME: gdb checks ARM_DEMANGLING here. */
2454 name
= savestring (*pp
, p
- *pp
);
2459 visibility
= DEBUG_VISIBILITY_PUBLIC
;
2466 visibility
= DEBUG_VISIBILITY_PRIVATE
;
2469 visibility
= DEBUG_VISIBILITY_PROTECTED
;
2472 visibility
= DEBUG_VISIBILITY_PUBLIC
;
2475 warn_stab (orig
, _("unknown visibility character for field"));
2476 visibility
= DEBUG_VISIBILITY_PUBLIC
;
2482 type
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
2483 (debug_type
**) NULL
);
2484 if (type
== DEBUG_TYPE_NULL
)
2491 /* This is a static class member. */
2493 p
= strchr (*pp
, ';');
2500 varname
= savestring (*pp
, p
- *pp
);
2504 *retp
= debug_make_static_member (dhandle
, name
, type
, varname
,
2518 bitpos
= parse_number (pp
, (boolean
*) NULL
);
2526 bitsize
= parse_number (pp
, (boolean
*) NULL
);
2534 if (bitpos
== 0 && bitsize
== 0)
2536 /* This can happen in two cases: (1) at least for gcc 2.4.5 or
2537 so, it is a field which has been optimized out. The correct
2538 stab for this case is to use VISIBILITY_IGNORE, but that is a
2539 recent invention. (2) It is a 0-size array. For example
2540 union { int num; char str[0]; } foo. Printing "<no value>"
2541 for str in "p foo" is OK, since foo.str (and thus foo.str[3])
2542 will continue to work, and a 0-size array as a whole doesn't
2543 have any contents to print.
2545 I suspect this probably could also happen with gcc -gstabs
2546 (not -gstabs+) for static fields, and perhaps other C++
2547 extensions. Hopefully few people use -gstabs with gdb, since
2548 it is intended for dbx compatibility. */
2549 visibility
= DEBUG_VISIBILITY_IGNORE
;
2552 /* FIXME: gdb does some stuff here to mark fields as unpacked. */
2554 *retp
= debug_make_field (dhandle
, name
, type
, bitpos
, bitsize
, visibility
);
2559 /* Read member function stabs info for C++ classes. The form of each member
2562 NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
2564 An example with two member functions is:
2566 afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
2568 For the case of overloaded operators, the format is op$::*.funcs, where
2569 $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
2570 name (such as `+=') and `.' marks the end of the operator name. */
2573 parse_stab_members (dhandle
, info
, tagname
, pp
, typenums
, retp
)
2575 struct stab_handle
*info
;
2576 const char *tagname
;
2578 const int *typenums
;
2579 debug_method
**retp
;
2582 debug_method
*methods
;
2598 debug_method_variant
*variants
;
2600 unsigned int allocvars
;
2601 debug_type look_ahead_type
;
2603 p
= strchr (*pp
, ':');
2604 if (p
== NULL
|| p
[1] != ':')
2607 /* FIXME: Some systems use something other than '$' here. */
2608 if ((*pp
)[0] != 'o' || (*pp
)[1] != 'p' || (*pp
)[2] != '$')
2610 name
= savestring (*pp
, p
- *pp
);
2615 /* This is a completely wierd case. In order to stuff in the
2616 names that might contain colons (the usual name delimiter),
2617 Mike Tiemann defined a different name format which is
2618 signalled if the identifier is "op$". In that case, the
2619 format is "op$::XXXX." where XXXX is the name. This is
2620 used for names like "+" or "=". YUUUUUUUK! FIXME! */
2622 for (p
= *pp
; *p
!= '.' && *p
!= '\0'; p
++)
2629 name
= savestring (*pp
, p
- *pp
);
2634 variants
= ((debug_method_variant
*)
2635 xmalloc (allocvars
* sizeof *variants
));
2638 look_ahead_type
= DEBUG_TYPE_NULL
;
2645 enum debug_visibility visibility
;
2646 boolean constp
, volatilep
, staticp
;
2649 const char *physname
;
2652 if (look_ahead_type
!= DEBUG_TYPE_NULL
)
2654 /* g++ version 1 kludge */
2655 type
= look_ahead_type
;
2656 look_ahead_type
= DEBUG_TYPE_NULL
;
2660 type
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
2661 (debug_type
**) NULL
);
2662 if (type
== DEBUG_TYPE_NULL
)
2672 p
= strchr (*pp
, ';');
2680 if (debug_get_type_kind (dhandle
, type
) == DEBUG_KIND_METHOD
2681 && debug_get_parameter_types (dhandle
, type
, &varargs
) == NULL
)
2684 argtypes
= savestring (*pp
, p
- *pp
);
2690 visibility
= DEBUG_VISIBILITY_PRIVATE
;
2693 visibility
= DEBUG_VISIBILITY_PROTECTED
;
2696 visibility
= DEBUG_VISIBILITY_PUBLIC
;
2706 /* Normal function. */
2710 /* const member function. */
2715 /* volatile member function. */
2720 /* const volatile member function. */
2728 /* File compiled with g++ version 1; no information. */
2731 warn_stab (orig
, _("const/volatile indicator missing"));
2739 /* virtual member function, followed by index. The sign
2740 bit is supposedly set to distinguish
2741 pointers-to-methods from virtual function indicies. */
2743 voffset
= parse_number (pp
, (boolean
*) NULL
);
2750 voffset
&= 0x7fffffff;
2752 if (**pp
== ';' || *pp
== '\0')
2754 /* Must be g++ version 1. */
2755 context
= DEBUG_TYPE_NULL
;
2759 /* Figure out from whence this virtual function
2760 came. It may belong to virtual function table of
2761 one of its baseclasses. */
2762 look_ahead_type
= parse_stab_type (dhandle
, info
,
2763 (const char *) NULL
,
2765 (debug_type
**) NULL
);
2768 /* g++ version 1 overloaded methods. */
2769 context
= DEBUG_TYPE_NULL
;
2773 context
= look_ahead_type
;
2774 look_ahead_type
= DEBUG_TYPE_NULL
;
2786 /* static member function. */
2790 context
= DEBUG_TYPE_NULL
;
2791 if (strncmp (argtypes
, name
, strlen (name
)) != 0)
2796 warn_stab (orig
, "member function type missing");
2798 context
= DEBUG_TYPE_NULL
;
2804 context
= DEBUG_TYPE_NULL
;
2808 /* If the type is not a stub, then the argtypes string is
2809 the physical name of the function. Otherwise the
2810 argtypes string is the mangled form of the argument
2811 types, and the full type and the physical name must be
2812 extracted from them. */
2814 physname
= argtypes
;
2817 debug_type class_type
, return_type
;
2819 class_type
= stab_find_type (dhandle
, info
, typenums
);
2820 if (class_type
== DEBUG_TYPE_NULL
)
2822 return_type
= debug_get_return_type (dhandle
, type
);
2823 if (return_type
== DEBUG_TYPE_NULL
)
2828 type
= parse_stab_argtypes (dhandle
, info
, class_type
, name
,
2829 tagname
, return_type
, argtypes
,
2830 constp
, volatilep
, &physname
);
2831 if (type
== DEBUG_TYPE_NULL
)
2835 if (cvars
+ 1 >= allocvars
)
2838 variants
= ((debug_method_variant
*)
2839 xrealloc ((PTR
) variants
,
2840 allocvars
* sizeof *variants
));
2844 variants
[cvars
] = debug_make_method_variant (dhandle
, physname
,
2849 variants
[cvars
] = debug_make_static_method_variant (dhandle
,
2855 if (variants
[cvars
] == DEBUG_METHOD_VARIANT_NULL
)
2860 while (**pp
!= ';' && **pp
!= '\0');
2862 variants
[cvars
] = DEBUG_METHOD_VARIANT_NULL
;
2870 methods
= ((debug_method
*)
2871 xrealloc ((PTR
) methods
, alloc
* sizeof *methods
));
2874 methods
[c
] = debug_make_method (dhandle
, name
, variants
);
2879 if (methods
!= NULL
)
2880 methods
[c
] = DEBUG_METHOD_NULL
;
2887 /* Parse a string representing argument types for a method. Stabs
2888 tries to save space by packing argument types into a mangled
2889 string. This string should give us enough information to extract
2890 both argument types and the physical name of the function, given
2894 parse_stab_argtypes (dhandle
, info
, class_type
, fieldname
, tagname
,
2895 return_type
, argtypes
, constp
, volatilep
, pphysname
)
2897 struct stab_handle
*info
;
2898 debug_type class_type
;
2899 const char *fieldname
;
2900 const char *tagname
;
2901 debug_type return_type
;
2902 const char *argtypes
;
2905 const char **pphysname
;
2907 boolean is_full_physname_constructor
;
2908 boolean is_constructor
;
2909 boolean is_destructor
;
2913 /* Constructors are sometimes handled specially. */
2914 is_full_physname_constructor
= ((argtypes
[0] == '_'
2915 && argtypes
[1] == '_'
2916 && (ISDIGIT (argtypes
[2])
2917 || argtypes
[2] == 'Q'
2918 || argtypes
[2] == 't'))
2919 || strncmp (argtypes
, "__ct", 4) == 0);
2921 is_constructor
= (is_full_physname_constructor
2923 && strcmp (fieldname
, tagname
) == 0));
2924 is_destructor
= ((argtypes
[0] == '_'
2925 && (argtypes
[1] == '$' || argtypes
[1] == '.')
2926 && argtypes
[2] == '_')
2927 || strncmp (argtypes
, "__dt", 4) == 0);
2929 if (is_destructor
|| is_full_physname_constructor
)
2930 *pphysname
= argtypes
;
2934 const char *const_prefix
;
2935 const char *volatile_prefix
;
2937 unsigned int mangled_name_len
;
2940 len
= tagname
== NULL
? 0 : strlen (tagname
);
2941 const_prefix
= constp
? "C" : "";
2942 volatile_prefix
= volatilep
? "V" : "";
2945 sprintf (buf
, "__%s%s", const_prefix
, volatile_prefix
);
2946 else if (tagname
!= NULL
&& strchr (tagname
, '<') != NULL
)
2948 /* Template methods are fully mangled. */
2949 sprintf (buf
, "__%s%s", const_prefix
, volatile_prefix
);
2954 sprintf (buf
, "__%s%s%d", const_prefix
, volatile_prefix
, len
);
2956 mangled_name_len
= ((is_constructor
? 0 : strlen (fieldname
))
2962 if (fieldname
[0] == 'o'
2963 && fieldname
[1] == 'p'
2964 && (fieldname
[2] == '$' || fieldname
[2] == '.'))
2968 opname
= cplus_mangle_opname (fieldname
+ 3, 0);
2971 fprintf (stderr
, _("No mangling for \"%s\"\n"), fieldname
);
2972 return DEBUG_TYPE_NULL
;
2974 mangled_name_len
+= strlen (opname
);
2975 physname
= (char *) xmalloc (mangled_name_len
);
2976 strncpy (physname
, fieldname
, 3);
2977 strcpy (physname
+ 3, opname
);
2981 physname
= (char *) xmalloc (mangled_name_len
);
2985 strcpy (physname
, fieldname
);
2988 strcat (physname
, buf
);
2989 if (tagname
!= NULL
)
2990 strcat (physname
, tagname
);
2991 strcat (physname
, argtypes
);
2993 *pphysname
= physname
;
2996 if (*argtypes
== '\0' || is_destructor
)
2998 args
= (debug_type
*) xmalloc (sizeof *args
);
3000 return debug_make_method_type (dhandle
, return_type
, class_type
, args
,
3004 args
= stab_demangle_argtypes (dhandle
, info
, *pphysname
, &varargs
);
3006 return DEBUG_TYPE_NULL
;
3008 return debug_make_method_type (dhandle
, return_type
, class_type
, args
,
3012 /* The tail end of stabs for C++ classes that contain a virtual function
3013 pointer contains a tilde, a %, and a type number.
3014 The type number refers to the base class (possibly this class itself) which
3015 contains the vtable pointer for the current class.
3017 This function is called when we have parsed all the method declarations,
3018 so we can look for the vptr base class info. */
3021 parse_stab_tilde_field (dhandle
, info
, pp
, typenums
, retvptrbase
, retownvptr
)
3023 struct stab_handle
*info
;
3025 const int *typenums
;
3026 debug_type
*retvptrbase
;
3027 boolean
*retownvptr
;
3033 *retvptrbase
= DEBUG_TYPE_NULL
;
3034 *retownvptr
= false;
3038 /* If we are positioned at a ';', then skip it. */
3047 if (**pp
== '=' || **pp
== '+' || **pp
== '-')
3049 /* Obsolete flags that used to indicate the presence of
3050 constructors and/or destructors. */
3061 /* The next number is the type number of the base class (possibly
3062 our own class) which supplies the vtable for this class. */
3063 if (! parse_stab_type_number (pp
, vtypenums
))
3066 if (vtypenums
[0] == typenums
[0]
3067 && vtypenums
[1] == typenums
[1])
3076 vtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
3077 (debug_type
**) NULL
);
3078 for (p
= *pp
; *p
!= ';' && *p
!= '\0'; p
++)
3086 *retvptrbase
= vtype
;
3094 /* Read a definition of an array type. */
3097 parse_stab_array_type (dhandle
, info
, pp
, stringp
)
3099 struct stab_handle
*info
;
3106 debug_type index_type
;
3108 bfd_signed_vma lower
, upper
;
3109 debug_type element_type
;
3111 /* Format of an array type:
3112 "ar<index type>;lower;upper;<array_contents_type>".
3113 OS9000: "arlower,upper;<array_contents_type>".
3115 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
3116 for these, produce a type like float[][]. */
3120 /* FIXME: gdb checks os9k_stabs here. */
3122 /* If the index type is type 0, we take it as int. */
3124 if (! parse_stab_type_number (&p
, typenums
))
3125 return DEBUG_TYPE_NULL
;
3126 if (typenums
[0] == 0 && typenums
[1] == 0 && **pp
!= '=')
3128 index_type
= debug_find_named_type (dhandle
, "int");
3129 if (index_type
== DEBUG_TYPE_NULL
)
3131 index_type
= debug_make_int_type (dhandle
, 4, false);
3132 if (index_type
== DEBUG_TYPE_NULL
)
3133 return DEBUG_TYPE_NULL
;
3139 index_type
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
3140 (debug_type
**) NULL
);
3146 return DEBUG_TYPE_NULL
;
3152 if (! ISDIGIT (**pp
) && **pp
!= '-')
3158 lower
= (bfd_signed_vma
) parse_number (pp
, (boolean
*) NULL
);
3162 return DEBUG_TYPE_NULL
;
3166 if (! ISDIGIT (**pp
) && **pp
!= '-')
3172 upper
= (bfd_signed_vma
) parse_number (pp
, (boolean
*) NULL
);
3176 return DEBUG_TYPE_NULL
;
3180 element_type
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
3181 (debug_type
**) NULL
);
3182 if (element_type
== DEBUG_TYPE_NULL
)
3183 return DEBUG_TYPE_NULL
;
3191 return debug_make_array_type (dhandle
, element_type
, index_type
, lower
,
3195 /* This struct holds information about files we have seen using
3200 /* The next N_BINCL file. */
3201 struct bincl_file
*next
;
3202 /* The next N_BINCL on the stack. */
3203 struct bincl_file
*next_stack
;
3204 /* The file name. */
3206 /* The hash value. */
3208 /* The file index. */
3210 /* The list of types defined in this file. */
3211 struct stab_types
*file_types
;
3214 /* Start a new N_BINCL file, pushing it onto the stack. */
3217 push_bincl (info
, name
, hash
)
3218 struct stab_handle
*info
;
3222 struct bincl_file
*n
;
3224 n
= (struct bincl_file
*) xmalloc (sizeof *n
);
3225 n
->next
= info
->bincl_list
;
3226 n
->next_stack
= info
->bincl_stack
;
3229 n
->file
= info
->files
;
3230 n
->file_types
= NULL
;
3231 info
->bincl_list
= n
;
3232 info
->bincl_stack
= n
;
3235 info
->file_types
= ((struct stab_types
**)
3236 xrealloc ((PTR
) info
->file_types
,
3238 * sizeof *info
->file_types
)));
3239 info
->file_types
[n
->file
] = NULL
;
3242 /* Finish an N_BINCL file, at an N_EINCL, popping the name off the
3247 struct stab_handle
*info
;
3249 struct bincl_file
*o
;
3251 o
= info
->bincl_stack
;
3253 return info
->main_filename
;
3254 info
->bincl_stack
= o
->next_stack
;
3256 o
->file_types
= info
->file_types
[o
->file
];
3258 if (info
->bincl_stack
== NULL
)
3259 return info
->main_filename
;
3260 return info
->bincl_stack
->name
;
3263 /* Handle an N_EXCL: get the types from the corresponding N_BINCL. */
3266 find_excl (info
, name
, hash
)
3267 struct stab_handle
*info
;
3271 struct bincl_file
*l
;
3274 info
->file_types
= ((struct stab_types
**)
3275 xrealloc ((PTR
) info
->file_types
,
3277 * sizeof *info
->file_types
)));
3279 for (l
= info
->bincl_list
; l
!= NULL
; l
= l
->next
)
3280 if (l
->hash
== hash
&& strcmp (l
->name
, name
) == 0)
3284 warn_stab (name
, _("Undefined N_EXCL"));
3285 info
->file_types
[info
->files
- 1] = NULL
;
3289 info
->file_types
[info
->files
- 1] = l
->file_types
;
3294 /* Handle a variable definition. gcc emits variable definitions for a
3295 block before the N_LBRAC, so we must hold onto them until we see
3296 it. The SunPRO compiler emits variable definitions after the
3297 N_LBRAC, so we can call debug_record_variable immediately. */
3300 stab_record_variable (dhandle
, info
, name
, type
, kind
, val
)
3302 struct stab_handle
*info
;
3305 enum debug_var_kind kind
;
3308 struct stab_pending_var
*v
;
3310 if ((kind
== DEBUG_GLOBAL
|| kind
== DEBUG_STATIC
)
3311 || ! info
->within_function
3312 || (info
->gcc_compiled
== 0 && info
->n_opt_found
))
3313 return debug_record_variable (dhandle
, name
, type
, kind
, val
);
3315 v
= (struct stab_pending_var
*) xmalloc (sizeof *v
);
3316 memset (v
, 0, sizeof *v
);
3318 v
->next
= info
->pending
;
3328 /* Emit pending variable definitions. This is called after we see the
3329 N_LBRAC that starts the block. */
3332 stab_emit_pending_vars (dhandle
, info
)
3334 struct stab_handle
*info
;
3336 struct stab_pending_var
*v
;
3341 struct stab_pending_var
*next
;
3343 if (! debug_record_variable (dhandle
, v
->name
, v
->type
, v
->kind
, v
->val
))
3351 info
->pending
= NULL
;
3356 /* Find the slot for a type in the database. */
3359 stab_find_slot (info
, typenums
)
3360 struct stab_handle
*info
;
3361 const int *typenums
;
3365 struct stab_types
**ps
;
3367 filenum
= typenums
[0];
3368 index
= typenums
[1];
3370 if (filenum
< 0 || (unsigned int) filenum
>= info
->files
)
3372 fprintf (stderr
, _("Type file number %d out of range\n"), filenum
);
3377 fprintf (stderr
, _("Type index number %d out of range\n"), index
);
3381 ps
= info
->file_types
+ filenum
;
3383 while (index
>= STAB_TYPES_SLOTS
)
3387 *ps
= (struct stab_types
*) xmalloc (sizeof **ps
);
3388 memset (*ps
, 0, sizeof **ps
);
3391 index
-= STAB_TYPES_SLOTS
;
3395 *ps
= (struct stab_types
*) xmalloc (sizeof **ps
);
3396 memset (*ps
, 0, sizeof **ps
);
3399 return (*ps
)->types
+ index
;
3402 /* Find a type given a type number. If the type has not been
3403 allocated yet, create an indirect type. */
3406 stab_find_type (dhandle
, info
, typenums
)
3408 struct stab_handle
*info
;
3409 const int *typenums
;
3413 if (typenums
[0] == 0 && typenums
[1] < 0)
3415 /* A negative type number indicates an XCOFF builtin type. */
3416 return stab_xcoff_builtin_type (dhandle
, info
, typenums
[1]);
3419 slot
= stab_find_slot (info
, typenums
);
3421 return DEBUG_TYPE_NULL
;
3423 if (*slot
== DEBUG_TYPE_NULL
)
3424 return debug_make_indirect_type (dhandle
, slot
, (const char *) NULL
);
3429 /* Record that a given type number refers to a given type. */
3432 stab_record_type (dhandle
, info
, typenums
, type
)
3433 PTR dhandle ATTRIBUTE_UNUSED
;
3434 struct stab_handle
*info
;
3435 const int *typenums
;
3440 slot
= stab_find_slot (info
, typenums
);
3444 /* gdb appears to ignore type redefinitions, so we do as well. */
3451 /* Return an XCOFF builtin type. */
3454 stab_xcoff_builtin_type (dhandle
, info
, typenum
)
3456 struct stab_handle
*info
;
3462 if (typenum
>= 0 || typenum
< -XCOFF_TYPE_COUNT
)
3464 fprintf (stderr
, _("Unrecognized XCOFF type %d\n"), typenum
);
3465 return DEBUG_TYPE_NULL
;
3467 if (info
->xcoff_types
[-typenum
] != NULL
)
3468 return info
->xcoff_types
[-typenum
];
3473 /* The size of this and all the other types are fixed, defined
3474 by the debugging format. */
3476 rettype
= debug_make_int_type (dhandle
, 4, false);
3480 rettype
= debug_make_int_type (dhandle
, 1, false);
3484 rettype
= debug_make_int_type (dhandle
, 2, false);
3488 rettype
= debug_make_int_type (dhandle
, 4, false);
3491 name
= "unsigned char";
3492 rettype
= debug_make_int_type (dhandle
, 1, true);
3495 name
= "signed char";
3496 rettype
= debug_make_int_type (dhandle
, 1, false);
3499 name
= "unsigned short";
3500 rettype
= debug_make_int_type (dhandle
, 2, true);
3503 name
= "unsigned int";
3504 rettype
= debug_make_int_type (dhandle
, 4, true);
3508 rettype
= debug_make_int_type (dhandle
, 4, true);
3510 name
= "unsigned long";
3511 rettype
= debug_make_int_type (dhandle
, 4, true);
3515 rettype
= debug_make_void_type (dhandle
);
3518 /* IEEE single precision (32 bit). */
3520 rettype
= debug_make_float_type (dhandle
, 4);
3523 /* IEEE double precision (64 bit). */
3525 rettype
= debug_make_float_type (dhandle
, 8);
3528 /* This is an IEEE double on the RS/6000, and different machines
3529 with different sizes for "long double" should use different
3530 negative type numbers. See stabs.texinfo. */
3531 name
= "long double";
3532 rettype
= debug_make_float_type (dhandle
, 8);
3536 rettype
= debug_make_int_type (dhandle
, 4, false);
3540 rettype
= debug_make_bool_type (dhandle
, 4);
3543 name
= "short real";
3544 rettype
= debug_make_float_type (dhandle
, 4);
3548 rettype
= debug_make_float_type (dhandle
, 8);
3558 rettype
= debug_make_int_type (dhandle
, 1, true);
3562 rettype
= debug_make_bool_type (dhandle
, 1);
3566 rettype
= debug_make_bool_type (dhandle
, 2);
3570 rettype
= debug_make_bool_type (dhandle
, 4);
3574 rettype
= debug_make_bool_type (dhandle
, 4);
3577 /* Complex type consisting of two IEEE single precision values. */
3579 rettype
= debug_make_complex_type (dhandle
, 8);
3582 /* Complex type consisting of two IEEE double precision values. */
3583 name
= "double complex";
3584 rettype
= debug_make_complex_type (dhandle
, 16);
3588 rettype
= debug_make_int_type (dhandle
, 1, false);
3592 rettype
= debug_make_int_type (dhandle
, 2, false);
3596 rettype
= debug_make_int_type (dhandle
, 4, false);
3601 rettype
= debug_make_int_type (dhandle
, 2, false);
3605 rettype
= debug_make_int_type (dhandle
, 8, false);
3608 name
= "unsigned long long";
3609 rettype
= debug_make_int_type (dhandle
, 8, true);
3613 rettype
= debug_make_bool_type (dhandle
, 8);
3617 rettype
= debug_make_int_type (dhandle
, 8, false);
3623 rettype
= debug_name_type (dhandle
, name
, rettype
);
3625 info
->xcoff_types
[-typenum
] = rettype
;
3630 /* Find or create a tagged type. */
3633 stab_find_tagged_type (dhandle
, info
, p
, len
, kind
)
3635 struct stab_handle
*info
;
3638 enum debug_type_kind kind
;
3642 struct stab_tag
*st
;
3644 name
= savestring (p
, len
);
3646 /* We pass DEBUG_KIND_ILLEGAL because we want all tags in the same
3647 namespace. This is right for C, and I don't know how to handle
3648 other languages. FIXME. */
3649 dtype
= debug_find_tagged_type (dhandle
, name
, DEBUG_KIND_ILLEGAL
);
3650 if (dtype
!= DEBUG_TYPE_NULL
)
3656 /* We need to allocate an entry on the undefined tag list. */
3657 for (st
= info
->tags
; st
!= NULL
; st
= st
->next
)
3659 if (st
->name
[0] == name
[0]
3660 && strcmp (st
->name
, name
) == 0)
3662 if (st
->kind
== DEBUG_KIND_ILLEGAL
)
3670 st
= (struct stab_tag
*) xmalloc (sizeof *st
);
3671 memset (st
, 0, sizeof *st
);
3673 st
->next
= info
->tags
;
3676 st
->slot
= DEBUG_TYPE_NULL
;
3677 st
->type
= debug_make_indirect_type (dhandle
, &st
->slot
, name
);
3684 /* In order to get the correct argument types for a stubbed method, we
3685 need to extract the argument types from a C++ mangled string.
3686 Since the argument types can refer back to the return type, this
3687 means that we must demangle the entire physical name. In gdb this
3688 is done by calling cplus_demangle and running the results back
3689 through the C++ expression parser. Since we have no expression
3690 parser, we must duplicate much of the work of cplus_demangle here.
3692 We assume that GNU style demangling is used, since this is only
3693 done for method stubs, and only g++ should output that form of
3694 debugging information. */
3696 /* This structure is used to hold a pointer to type information which
3697 demangling a string. */
3699 struct stab_demangle_typestring
3701 /* The start of the type. This is not null terminated. */
3702 const char *typestring
;
3703 /* The length of the type. */
3707 /* This structure is used to hold information while demangling a
3710 struct stab_demangle_info
3712 /* The debugging information handle. */
3714 /* The stab information handle. */
3715 struct stab_handle
*info
;
3716 /* The array of arguments we are building. */
3718 /* Whether the method takes a variable number of arguments. */
3720 /* The array of types we have remembered. */
3721 struct stab_demangle_typestring
*typestrings
;
3722 /* The number of typestrings. */
3723 unsigned int typestring_count
;
3724 /* The number of typestring slots we have allocated. */
3725 unsigned int typestring_alloc
;
3728 static void stab_bad_demangle
PARAMS ((const char *));
3729 static unsigned int stab_demangle_count
PARAMS ((const char **));
3730 static boolean stab_demangle_get_count
3731 PARAMS ((const char **, unsigned int *));
3732 static boolean stab_demangle_prefix
3733 PARAMS ((struct stab_demangle_info
*, const char **));
3734 static boolean stab_demangle_function_name
3735 PARAMS ((struct stab_demangle_info
*, const char **, const char *));
3736 static boolean stab_demangle_signature
3737 PARAMS ((struct stab_demangle_info
*, const char **));
3738 static boolean stab_demangle_qualified
3739 PARAMS ((struct stab_demangle_info
*, const char **, debug_type
*));
3740 static boolean stab_demangle_template
3741 PARAMS ((struct stab_demangle_info
*, const char **, char **));
3742 static boolean stab_demangle_class
3743 PARAMS ((struct stab_demangle_info
*, const char **, const char **));
3744 static boolean stab_demangle_args
3745 PARAMS ((struct stab_demangle_info
*, const char **, debug_type
**,
3747 static boolean stab_demangle_arg
3748 PARAMS ((struct stab_demangle_info
*, const char **, debug_type
**,
3749 unsigned int *, unsigned int *));
3750 static boolean stab_demangle_type
3751 PARAMS ((struct stab_demangle_info
*, const char **, debug_type
*));
3752 static boolean stab_demangle_fund_type
3753 PARAMS ((struct stab_demangle_info
*, const char **, debug_type
*));
3754 static boolean stab_demangle_remember_type
3755 PARAMS ((struct stab_demangle_info
*, const char *, int));
3757 /* Warn about a bad demangling. */
3760 stab_bad_demangle (s
)
3763 fprintf (stderr
, _("bad mangled name `%s'\n"), s
);
3766 /* Get a count from a stab string. */
3769 stab_demangle_count (pp
)
3775 while (ISDIGIT (**pp
))
3778 count
+= **pp
- '0';
3784 /* Require a count in a string. The count may be multiple digits, in
3785 which case it must end in an underscore. */
3788 stab_demangle_get_count (pp
, pi
)
3792 if (! ISDIGIT (**pp
))
3810 while (ISDIGIT (*p
));
3821 /* This function demangles a physical name, returning a NULL
3822 terminated array of argument types. */
3825 stab_demangle_argtypes (dhandle
, info
, physname
, pvarargs
)
3827 struct stab_handle
*info
;
3828 const char *physname
;
3831 struct stab_demangle_info minfo
;
3833 minfo
.dhandle
= dhandle
;
3836 minfo
.varargs
= false;
3837 minfo
.typestring_alloc
= 10;
3838 minfo
.typestrings
= ((struct stab_demangle_typestring
*)
3839 xmalloc (minfo
.typestring_alloc
3840 * sizeof *minfo
.typestrings
));
3841 minfo
.typestring_count
= 0;
3843 /* cplus_demangle checks for special GNU mangled forms, but we can't
3844 see any of them in mangled method argument types. */
3846 if (! stab_demangle_prefix (&minfo
, &physname
))
3849 if (*physname
!= '\0')
3851 if (! stab_demangle_signature (&minfo
, &physname
))
3855 free (minfo
.typestrings
);
3856 minfo
.typestrings
= NULL
;
3858 if (minfo
.args
== NULL
)
3859 fprintf (stderr
, _("no argument types in mangled string\n"));
3861 *pvarargs
= minfo
.varargs
;
3865 if (minfo
.typestrings
!= NULL
)
3866 free (minfo
.typestrings
);
3870 /* Demangle the prefix of the mangled name. */
3873 stab_demangle_prefix (minfo
, pp
)
3874 struct stab_demangle_info
*minfo
;
3880 /* cplus_demangle checks for global constructors and destructors,
3881 but we can't see them in mangled argument types. */
3883 /* Look for `__'. */
3887 scan
= strchr (scan
, '_');
3889 while (scan
!= NULL
&& *++scan
!= '_');
3893 stab_bad_demangle (*pp
);
3899 /* We found `__'; move ahead to the last contiguous `__' pair. */
3900 i
= strspn (scan
, "_");
3905 && (ISDIGIT (scan
[2])
3909 /* This is a GNU style constructor name. */
3913 else if (scan
== *pp
3914 && ! ISDIGIT (scan
[2])
3917 /* Look for the `__' that separates the prefix from the
3919 while (*scan
== '_')
3921 scan
= strstr (scan
, "__");
3922 if (scan
== NULL
|| scan
[2] == '\0')
3924 stab_bad_demangle (*pp
);
3928 return stab_demangle_function_name (minfo
, pp
, scan
);
3930 else if (scan
[2] != '\0')
3932 /* The name doesn't start with `__', but it does contain `__'. */
3933 return stab_demangle_function_name (minfo
, pp
, scan
);
3937 stab_bad_demangle (*pp
);
3943 /* Demangle a function name prefix. The scan argument points to the
3944 double underscore which separates the function name from the
3948 stab_demangle_function_name (minfo
, pp
, scan
)
3949 struct stab_demangle_info
*minfo
;
3955 /* The string from *pp to scan is the name of the function. We
3956 don't care about the name, since we just looking for argument
3957 types. However, for conversion operators, the name may include a
3958 type which we must remember in order to handle backreferences. */
3964 && strncmp (name
, "type", 4) == 0
3965 && (name
[4] == '$' || name
[4] == '.'))
3969 /* This is a type conversion operator. */
3971 if (! stab_demangle_type (minfo
, &tem
, (debug_type
*) NULL
))
3974 else if (name
[0] == '_'
3981 /* This is a type conversion operator. */
3983 if (! stab_demangle_type (minfo
, &tem
, (debug_type
*) NULL
))
3990 /* Demangle the signature. This is where the argument types are
3994 stab_demangle_signature (minfo
, pp
)
3995 struct stab_demangle_info
*minfo
;
3999 boolean expect_func
, func_done
;
4004 expect_func
= false;
4008 while (**pp
!= '\0')
4014 if (! stab_demangle_qualified (minfo
, pp
, (debug_type
*) NULL
)
4015 || ! stab_demangle_remember_type (minfo
, hold
, *pp
- hold
))
4022 /* Static member function. FIXME: Can this happen? */
4029 /* Const member function. */
4035 case '0': case '1': case '2': case '3': case '4':
4036 case '5': case '6': case '7': case '8': case '9':
4039 if (! stab_demangle_class (minfo
, pp
, (const char **) NULL
)
4040 || ! stab_demangle_remember_type (minfo
, hold
, *pp
- hold
))
4047 /* Function. I don't know if this actually happens with g++
4052 if (! stab_demangle_args (minfo
, pp
, &minfo
->args
, &minfo
->varargs
))
4060 if (! stab_demangle_template (minfo
, pp
, (char **) NULL
)
4061 || ! stab_demangle_remember_type (minfo
, hold
, *pp
- hold
))
4068 /* At the outermost level, we cannot have a return type
4069 specified, so if we run into another '_' at this point we
4070 are dealing with a mangled name that is either bogus, or
4071 has been mangled by some algorithm we don't know how to
4072 deal with. So just reject the entire demangling. */
4073 stab_bad_demangle (orig
);
4077 /* Assume we have stumbled onto the first outermost function
4078 argument token, and start processing args. */
4080 if (! stab_demangle_args (minfo
, pp
, &minfo
->args
, &minfo
->varargs
))
4088 if (! stab_demangle_args (minfo
, pp
, &minfo
->args
, &minfo
->varargs
))
4095 /* With GNU style demangling, bar__3foo is 'foo::bar(void)', and
4096 bar__3fooi is 'foo::bar(int)'. We get here when we find the
4097 first case, and need to ensure that the '(void)' gets added
4098 to the current declp. */
4099 if (! stab_demangle_args (minfo
, pp
, &minfo
->args
, &minfo
->varargs
))
4106 /* Demangle a qualified name, such as "Q25Outer5Inner" which is the
4107 mangled form of "Outer::Inner". */
4110 stab_demangle_qualified (minfo
, pp
, ptype
)
4111 struct stab_demangle_info
*minfo
;
4117 unsigned int qualifiers
;
4125 /* GNU mangled name with more than 9 classes. The count is
4126 preceded by an underscore (to distinguish it from the <= 9
4127 case) and followed by an underscore. */
4129 if (! ISDIGIT (*p
) || *p
== '0')
4131 stab_bad_demangle (orig
);
4134 qualifiers
= atoi (p
);
4135 while (ISDIGIT (*p
))
4139 stab_bad_demangle (orig
);
4145 case '1': case '2': case '3': case '4': case '5':
4146 case '6': case '7': case '8': case '9':
4147 qualifiers
= (*pp
)[1] - '0';
4148 /* Skip an optional underscore after the count. */
4149 if ((*pp
)[2] == '_')
4156 stab_bad_demangle (orig
);
4160 context
= DEBUG_TYPE_NULL
;
4162 /* Pick off the names. */
4163 while (qualifiers
-- > 0)
4171 if (! stab_demangle_template (minfo
, pp
,
4172 ptype
!= NULL
? &name
: NULL
))
4177 context
= stab_find_tagged_type (minfo
->dhandle
, minfo
->info
,
4178 name
, strlen (name
),
4181 if (context
== DEBUG_TYPE_NULL
)
4189 len
= stab_demangle_count (pp
);
4190 if (strlen (*pp
) < len
)
4192 stab_bad_demangle (orig
);
4198 const debug_field
*fields
;
4201 if (context
!= DEBUG_TYPE_NULL
)
4202 fields
= debug_get_fields (minfo
->dhandle
, context
);
4204 context
= DEBUG_TYPE_NULL
;
4210 /* Try to find the type by looking through the
4211 fields of context until we find a field with the
4212 same type. This ought to work for a class
4213 defined within a class, but it won't work for,
4214 e.g., an enum defined within a class. stabs does
4215 not give us enough information to figure out the
4218 name
= savestring (*pp
, len
);
4220 for (; *fields
!= DEBUG_FIELD_NULL
; fields
++)
4225 ft
= debug_get_field_type (minfo
->dhandle
, *fields
);
4228 dn
= debug_get_type_name (minfo
->dhandle
, ft
);
4229 if (dn
!= NULL
&& strcmp (dn
, name
) == 0)
4239 if (context
== DEBUG_TYPE_NULL
)
4241 /* We have to fall back on finding the type by name.
4242 If there are more types to come, then this must
4243 be a class. Otherwise, it could be anything. */
4245 if (qualifiers
== 0)
4249 name
= savestring (*pp
, len
);
4250 context
= debug_find_named_type (minfo
->dhandle
,
4255 if (context
== DEBUG_TYPE_NULL
)
4257 context
= stab_find_tagged_type (minfo
->dhandle
,
4261 ? DEBUG_KIND_ILLEGAL
4262 : DEBUG_KIND_CLASS
));
4263 if (context
== DEBUG_TYPE_NULL
)
4279 /* Demangle a template. If PNAME is not NULL, this sets *PNAME to a
4280 string representation of the template. */
4283 stab_demangle_template (minfo
, pp
, pname
)
4284 struct stab_demangle_info
*minfo
;
4295 /* Skip the template name. */
4296 r
= stab_demangle_count (pp
);
4297 if (r
== 0 || strlen (*pp
) < r
)
4299 stab_bad_demangle (orig
);
4304 /* Get the size of the parameter list. */
4305 if (stab_demangle_get_count (pp
, &r
) == 0)
4307 stab_bad_demangle (orig
);
4311 for (i
= 0; i
< r
; i
++)
4315 /* This is a type parameter. */
4317 if (! stab_demangle_type (minfo
, pp
, (debug_type
*) NULL
))
4323 boolean pointerp
, realp
, integralp
, charp
, boolp
;
4334 /* This is a value parameter. */
4336 if (! stab_demangle_type (minfo
, pp
, (debug_type
*) NULL
))
4339 while (*old_p
!= '\0' && ! done
)
4349 case 'C': /* Const. */
4350 case 'S': /* Signed. */
4351 case 'U': /* Unsigned. */
4352 case 'V': /* Volatile. */
4353 case 'F': /* Function. */
4354 case 'M': /* Member function. */
4358 case 'Q': /* Qualified name. */
4362 case 'T': /* Remembered type. */
4364 case 'v': /* Void. */
4366 case 'x': /* Long long. */
4367 case 'l': /* Long. */
4368 case 'i': /* Int. */
4369 case 's': /* Short. */
4370 case 'w': /* Wchar_t. */
4374 case 'b': /* Bool. */
4378 case 'c': /* Char. */
4382 case 'r': /* Long double. */
4383 case 'd': /* Double. */
4384 case 'f': /* Float. */
4389 /* Assume it's a user defined integral type. */
4400 while (ISDIGIT (**pp
))
4409 val
= stab_demangle_count (pp
);
4412 stab_bad_demangle (orig
);
4420 val
= stab_demangle_count (pp
);
4421 if (val
!= 0 && val
!= 1)
4423 stab_bad_demangle (orig
);
4431 while (ISDIGIT (**pp
))
4436 while (ISDIGIT (**pp
))
4442 while (ISDIGIT (**pp
))
4450 if (! stab_demangle_get_count (pp
, &len
))
4452 stab_bad_demangle (orig
);
4460 /* We can translate this to a string fairly easily by invoking the
4461 regular demangling routine. */
4464 char *s1
, *s2
, *s3
, *s4
= NULL
;
4467 s1
= savestring (orig
, *pp
- orig
);
4469 s2
= concat ("NoSuchStrinG__", s1
, (const char *) NULL
);
4473 s3
= cplus_demangle (s2
, DMGL_ANSI
);
4478 s4
= strstr (s3
, "::NoSuchStrinG");
4479 if (s3
== NULL
|| s4
== NULL
)
4481 stab_bad_demangle (orig
);
4487 /* Eliminating all spaces, except those between > characters,
4488 makes it more likely that the demangled name will match the
4489 name which g++ used as the structure name. */
4490 for (from
= to
= s3
; from
!= s4
; ++from
)
4492 || (from
[1] == '>' && from
> s3
&& from
[-1] == '>'))
4495 *pname
= savestring (s3
, to
- s3
);
4503 /* Demangle a class name. */
4506 stab_demangle_class (minfo
, pp
, pstart
)
4507 struct stab_demangle_info
*minfo ATTRIBUTE_UNUSED
;
4509 const char **pstart
;
4516 n
= stab_demangle_count (pp
);
4517 if (strlen (*pp
) < n
)
4519 stab_bad_demangle (orig
);
4531 /* Demangle function arguments. If the pargs argument is not NULL, it
4532 is set to a NULL terminated array holding the arguments. */
4535 stab_demangle_args (minfo
, pp
, pargs
, pvarargs
)
4536 struct stab_demangle_info
*minfo
;
4542 unsigned int alloc
, count
;
4549 *pargs
= (debug_type
*) xmalloc (alloc
* sizeof **pargs
);
4554 while (**pp
!= '_' && **pp
!= '\0' && **pp
!= 'e')
4556 if (**pp
== 'N' || **pp
== 'T')
4564 if (temptype
== 'T')
4568 if (! stab_demangle_get_count (pp
, &r
))
4570 stab_bad_demangle (orig
);
4575 if (! stab_demangle_get_count (pp
, &t
))
4577 stab_bad_demangle (orig
);
4581 if (t
>= minfo
->typestring_count
)
4583 stab_bad_demangle (orig
);
4590 tem
= minfo
->typestrings
[t
].typestring
;
4591 if (! stab_demangle_arg (minfo
, &tem
, pargs
, &count
, &alloc
))
4597 if (! stab_demangle_arg (minfo
, pp
, pargs
, &count
, &alloc
))
4603 (*pargs
)[count
] = DEBUG_TYPE_NULL
;
4615 /* Demangle a single argument. */
4618 stab_demangle_arg (minfo
, pp
, pargs
, pcount
, palloc
)
4619 struct stab_demangle_info
*minfo
;
4622 unsigned int *pcount
;
4623 unsigned int *palloc
;
4629 if (! stab_demangle_type (minfo
, pp
,
4630 pargs
== NULL
? (debug_type
*) NULL
: &type
)
4631 || ! stab_demangle_remember_type (minfo
, start
, *pp
- start
))
4636 if (type
== DEBUG_TYPE_NULL
)
4639 if (*pcount
+ 1 >= *palloc
)
4642 *pargs
= ((debug_type
*)
4643 xrealloc (*pargs
, *palloc
* sizeof **pargs
));
4645 (*pargs
)[*pcount
] = type
;
4652 /* Demangle a type. If the ptype argument is not NULL, *ptype is set
4653 to the newly allocated type. */
4656 stab_demangle_type (minfo
, pp
, ptype
)
4657 struct stab_demangle_info
*minfo
;
4669 /* A pointer type. */
4671 if (! stab_demangle_type (minfo
, pp
, ptype
))
4674 *ptype
= debug_make_pointer_type (minfo
->dhandle
, *ptype
);
4678 /* A reference type. */
4680 if (! stab_demangle_type (minfo
, pp
, ptype
))
4683 *ptype
= debug_make_reference_type (minfo
->dhandle
, *ptype
);
4693 while (**pp
!= '\0' && **pp
!= '_')
4695 if (! ISDIGIT (**pp
))
4697 stab_bad_demangle (orig
);
4706 stab_bad_demangle (orig
);
4711 if (! stab_demangle_type (minfo
, pp
, ptype
))
4715 debug_type int_type
;
4717 int_type
= debug_find_named_type (minfo
->dhandle
, "int");
4718 if (int_type
== NULL
)
4719 int_type
= debug_make_int_type (minfo
->dhandle
, 4, false);
4720 *ptype
= debug_make_array_type (minfo
->dhandle
, *ptype
, int_type
,
4727 /* A back reference to a remembered type. */
4733 if (! stab_demangle_get_count (pp
, &i
))
4735 stab_bad_demangle (orig
);
4738 if (i
>= minfo
->typestring_count
)
4740 stab_bad_demangle (orig
);
4743 p
= minfo
->typestrings
[i
].typestring
;
4744 if (! stab_demangle_type (minfo
, &p
, ptype
))
4756 if (! stab_demangle_args (minfo
, pp
,
4758 ? (debug_type
**) NULL
4766 /* cplus_demangle will accept a function without a return
4767 type, but I don't know when that will happen, or what
4768 to do if it does. */
4769 stab_bad_demangle (orig
);
4773 if (! stab_demangle_type (minfo
, pp
, ptype
))
4776 *ptype
= debug_make_function_type (minfo
->dhandle
, *ptype
, args
,
4785 boolean memberp
, constp
, volatilep
;
4786 debug_type class_type
= DEBUG_TYPE_NULL
;
4792 memberp
= **pp
== 'M';
4801 n
= stab_demangle_count (pp
);
4802 if (strlen (*pp
) < n
)
4804 stab_bad_demangle (orig
);
4812 class_type
= stab_find_tagged_type (minfo
->dhandle
,
4816 if (class_type
== DEBUG_TYPE_NULL
)
4820 else if (**pp
== 'Q')
4822 if (! stab_demangle_qualified (minfo
, pp
,
4824 ? (debug_type
*) NULL
4830 stab_bad_demangle (orig
);
4841 else if (**pp
== 'V')
4848 stab_bad_demangle (orig
);
4852 if (! stab_demangle_args (minfo
, pp
,
4854 ? (debug_type
**) NULL
4864 stab_bad_demangle (orig
);
4869 if (! stab_demangle_type (minfo
, pp
, ptype
))
4875 *ptype
= debug_make_offset_type (minfo
->dhandle
, class_type
,
4879 /* FIXME: We have no way to record constp or
4881 *ptype
= debug_make_method_type (minfo
->dhandle
, *ptype
,
4882 class_type
, args
, varargs
);
4890 if (! stab_demangle_type (minfo
, pp
, ptype
))
4896 if (! stab_demangle_type (minfo
, pp
, ptype
))
4899 *ptype
= debug_make_const_type (minfo
->dhandle
, *ptype
);
4907 if (! stab_demangle_qualified (minfo
, pp
, ptype
))
4913 if (! stab_demangle_fund_type (minfo
, pp
, ptype
))
4921 /* Demangle a fundamental type. If the ptype argument is not NULL,
4922 *ptype is set to the newly allocated type. */
4925 stab_demangle_fund_type (minfo
, pp
, ptype
)
4926 struct stab_demangle_info
*minfo
;
4931 boolean constp
, volatilep
, unsignedp
, signedp
;
4976 /* cplus_demangle permits this, but I don't know what it means. */
4977 stab_bad_demangle (orig
);
4980 case 'v': /* void */
4983 *ptype
= debug_find_named_type (minfo
->dhandle
, "void");
4984 if (*ptype
== DEBUG_TYPE_NULL
)
4985 *ptype
= debug_make_void_type (minfo
->dhandle
);
4990 case 'x': /* long long */
4993 *ptype
= debug_find_named_type (minfo
->dhandle
,
4995 ? "long long unsigned int"
4996 : "long long int"));
4997 if (*ptype
== DEBUG_TYPE_NULL
)
4998 *ptype
= debug_make_int_type (minfo
->dhandle
, 8, unsignedp
);
5003 case 'l': /* long */
5006 *ptype
= debug_find_named_type (minfo
->dhandle
,
5008 ? "long unsigned int"
5010 if (*ptype
== DEBUG_TYPE_NULL
)
5011 *ptype
= debug_make_int_type (minfo
->dhandle
, 4, unsignedp
);
5019 *ptype
= debug_find_named_type (minfo
->dhandle
,
5023 if (*ptype
== DEBUG_TYPE_NULL
)
5024 *ptype
= debug_make_int_type (minfo
->dhandle
, 4, unsignedp
);
5029 case 's': /* short */
5032 *ptype
= debug_find_named_type (minfo
->dhandle
,
5034 ? "short unsigned int"
5036 if (*ptype
== DEBUG_TYPE_NULL
)
5037 *ptype
= debug_make_int_type (minfo
->dhandle
, 2, unsignedp
);
5042 case 'b': /* bool */
5045 *ptype
= debug_find_named_type (minfo
->dhandle
, "bool");
5046 if (*ptype
== DEBUG_TYPE_NULL
)
5047 *ptype
= debug_make_bool_type (minfo
->dhandle
, 4);
5052 case 'c': /* char */
5055 *ptype
= debug_find_named_type (minfo
->dhandle
,
5061 if (*ptype
== DEBUG_TYPE_NULL
)
5062 *ptype
= debug_make_int_type (minfo
->dhandle
, 1, unsignedp
);
5067 case 'w': /* wchar_t */
5070 *ptype
= debug_find_named_type (minfo
->dhandle
, "__wchar_t");
5071 if (*ptype
== DEBUG_TYPE_NULL
)
5072 *ptype
= debug_make_int_type (minfo
->dhandle
, 2, true);
5077 case 'r': /* long double */
5080 *ptype
= debug_find_named_type (minfo
->dhandle
, "long double");
5081 if (*ptype
== DEBUG_TYPE_NULL
)
5082 *ptype
= debug_make_float_type (minfo
->dhandle
, 8);
5087 case 'd': /* double */
5090 *ptype
= debug_find_named_type (minfo
->dhandle
, "double");
5091 if (*ptype
== DEBUG_TYPE_NULL
)
5092 *ptype
= debug_make_float_type (minfo
->dhandle
, 8);
5097 case 'f': /* float */
5100 *ptype
= debug_find_named_type (minfo
->dhandle
, "float");
5101 if (*ptype
== DEBUG_TYPE_NULL
)
5102 *ptype
= debug_make_float_type (minfo
->dhandle
, 4);
5109 if (! ISDIGIT (**pp
))
5111 stab_bad_demangle (orig
);
5115 case '0': case '1': case '2': case '3': case '4':
5116 case '5': case '6': case '7': case '8': case '9':
5120 if (! stab_demangle_class (minfo
, pp
, &hold
))
5126 name
= savestring (hold
, *pp
- hold
);
5127 *ptype
= debug_find_named_type (minfo
->dhandle
, name
);
5129 if (*ptype
== DEBUG_TYPE_NULL
)
5131 /* FIXME: It is probably incorrect to assume that
5132 undefined types are tagged types. */
5133 *ptype
= stab_find_tagged_type (minfo
->dhandle
, minfo
->info
,
5135 DEBUG_KIND_ILLEGAL
);
5136 if (*ptype
== DEBUG_TYPE_NULL
)
5147 if (! stab_demangle_template (minfo
, pp
,
5148 ptype
!= NULL
? &name
: NULL
))
5152 *ptype
= stab_find_tagged_type (minfo
->dhandle
, minfo
->info
,
5153 name
, strlen (name
),
5156 if (*ptype
== DEBUG_TYPE_NULL
)
5163 stab_bad_demangle (orig
);
5170 *ptype
= debug_make_const_type (minfo
->dhandle
, *ptype
);
5172 *ptype
= debug_make_volatile_type (minfo
->dhandle
, *ptype
);
5178 /* Remember a type string in a demangled string. */
5181 stab_demangle_remember_type (minfo
, p
, len
)
5182 struct stab_demangle_info
*minfo
;
5186 if (minfo
->typestring_count
>= minfo
->typestring_alloc
)
5188 minfo
->typestring_alloc
+= 10;
5189 minfo
->typestrings
= ((struct stab_demangle_typestring
*)
5190 xrealloc (minfo
->typestrings
,
5191 (minfo
->typestring_alloc
5192 * sizeof *minfo
->typestrings
)));
5195 minfo
->typestrings
[minfo
->typestring_count
].typestring
= p
;
5196 minfo
->typestrings
[minfo
->typestring_count
].len
= (unsigned int) len
;
5197 ++minfo
->typestring_count
;