1 /* stabs.c -- Parse stabs debugging information
2 Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
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. */
77 bfd_boolean n_opt_found
;
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 bfd_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 bfd_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
155 PARAMS ((const char *, int));
156 static bfd_vma parse_number
157 PARAMS ((const char **, bfd_boolean
*));
159 PARAMS ((const char *));
160 static void warn_stab
161 PARAMS ((const char *, const char *));
162 static bfd_boolean parse_stab_string
163 PARAMS ((PTR
, struct stab_handle
*, int, int, bfd_vma
, const char *));
164 static debug_type parse_stab_type
165 PARAMS ((PTR
, struct stab_handle
*, const char *, const char **,
167 static bfd_boolean parse_stab_type_number
168 PARAMS ((const char **, int *));
169 static debug_type parse_stab_range_type
170 PARAMS ((PTR
, struct stab_handle
*, const char *, const char **,
172 static debug_type parse_stab_sun_builtin_type
173 PARAMS ((PTR
, const char **));
174 static debug_type parse_stab_sun_floating_type
175 PARAMS ((PTR
, const char **));
176 static debug_type parse_stab_enum_type
177 PARAMS ((PTR
, const char **));
178 static debug_type parse_stab_struct_type
179 PARAMS ((PTR
, struct stab_handle
*, const char *, const char **, bfd_boolean
,
181 static bfd_boolean parse_stab_baseclasses
182 PARAMS ((PTR
, struct stab_handle
*, const char **, debug_baseclass
**));
183 static bfd_boolean parse_stab_struct_fields
184 PARAMS ((PTR
, struct stab_handle
*, const char **, debug_field
**,
186 static bfd_boolean parse_stab_cpp_abbrev
187 PARAMS ((PTR
, struct stab_handle
*, const char **, debug_field
*));
188 static bfd_boolean parse_stab_one_struct_field
189 PARAMS ((PTR
, struct stab_handle
*, const char **, const char *,
190 debug_field
*, bfd_boolean
*));
191 static bfd_boolean parse_stab_members
192 PARAMS ((PTR
, struct stab_handle
*, const char *, const char **,
193 const int *, debug_method
**));
194 static debug_type parse_stab_argtypes
195 PARAMS ((PTR
, struct stab_handle
*, debug_type
, const char *, const char *,
196 debug_type
, const char *, bfd_boolean
, bfd_boolean
, const char **));
197 static bfd_boolean parse_stab_tilde_field
198 PARAMS ((PTR
, struct stab_handle
*, const char **, const int *,
199 debug_type
*, bfd_boolean
*));
200 static debug_type parse_stab_array_type
201 PARAMS ((PTR
, struct stab_handle
*, const char **, bfd_boolean
));
202 static void push_bincl
203 PARAMS ((struct stab_handle
*, const char *, bfd_vma
));
204 static const char *pop_bincl
205 PARAMS ((struct stab_handle
*));
206 static bfd_boolean find_excl
207 PARAMS ((struct stab_handle
*, const char *, bfd_vma
));
208 static bfd_boolean stab_record_variable
209 PARAMS ((PTR
, struct stab_handle
*, const char *, debug_type
,
210 enum debug_var_kind
, bfd_vma
));
211 static bfd_boolean stab_emit_pending_vars
212 PARAMS ((PTR
, struct stab_handle
*));
213 static debug_type
*stab_find_slot
214 PARAMS ((struct stab_handle
*, const int *));
215 static debug_type stab_find_type
216 PARAMS ((PTR
, struct stab_handle
*, const int *));
217 static bfd_boolean stab_record_type
218 PARAMS ((PTR
, struct stab_handle
*, const int *, debug_type
));
219 static debug_type stab_xcoff_builtin_type
220 PARAMS ((PTR
, struct stab_handle
*, int));
221 static debug_type stab_find_tagged_type
222 PARAMS ((PTR
, struct stab_handle
*, const char *, int,
223 enum debug_type_kind
));
224 static debug_type
*stab_demangle_argtypes
225 PARAMS ((PTR
, struct stab_handle
*, const char *, bfd_boolean
*, unsigned int));
227 /* Save a string in memory. */
230 savestring (start
, len
)
236 ret
= (char *) xmalloc (len
+ 1);
237 memcpy (ret
, start
, len
);
242 /* Read a number from a string. */
245 parse_number (pp
, poverflow
)
247 bfd_boolean
*poverflow
;
252 if (poverflow
!= NULL
)
258 ul
= strtoul (*pp
, (char **) pp
, 0);
259 if (ul
+ 1 != 0 || errno
== 0)
261 /* If bfd_vma is larger than unsigned long, and the number is
262 meant to be negative, we have to make sure that we sign
265 return (bfd_vma
) (bfd_signed_vma
) (long) ul
;
269 /* Note that even though strtoul overflowed, it should have set *pp
270 to the end of the number, which is where we want it. */
272 if (sizeof (bfd_vma
) > sizeof (unsigned long))
277 bfd_vma over
, lastdig
;
278 bfd_boolean overflow
;
281 /* Our own version of strtoul, for a bfd_vma. */
297 if (p
[1] == 'x' || p
[1] == 'X')
309 over
= ((bfd_vma
) (bfd_signed_vma
) -1) / (bfd_vma
) base
;
310 lastdig
= ((bfd_vma
) (bfd_signed_vma
) -1) % (bfd_vma
) base
;
321 else if (ISUPPER (d
))
323 else if (ISLOWER (d
))
331 if (v
> over
|| (v
== over
&& (bfd_vma
) d
> lastdig
))
346 /* If we get here, the number is too large to represent in a
349 if (poverflow
!= NULL
)
352 warn_stab (orig
, _("numeric overflow"));
357 /* Give an error for a bad stab string. */
363 fprintf (stderr
, _("Bad stab: %s\n"), p
);
366 /* Warn about something in a stab string. */
373 fprintf (stderr
, _("Warning: %s: %s\n"), err
, p
);
376 /* Create a handle to parse stabs symbols with. */
379 start_stab (dhandle
, abfd
, sections
, syms
, symcount
)
380 PTR dhandle ATTRIBUTE_UNUSED
;
382 bfd_boolean sections
;
386 struct stab_handle
*ret
;
388 ret
= (struct stab_handle
*) xmalloc (sizeof *ret
);
389 memset (ret
, 0, sizeof *ret
);
391 ret
->sections
= sections
;
393 ret
->symcount
= symcount
;
395 ret
->file_types
= (struct stab_types
**) xmalloc (sizeof *ret
->file_types
);
396 ret
->file_types
[0] = NULL
;
397 ret
->function_end
= (bfd_vma
) -1;
401 /* When we have processed all the stabs information, we need to go
402 through and fill in all the undefined tags. */
405 finish_stab (dhandle
, handle
)
409 struct stab_handle
*info
= (struct stab_handle
*) handle
;
412 if (info
->within_function
)
414 if (! stab_emit_pending_vars (dhandle
, info
)
415 || ! debug_end_function (dhandle
, info
->function_end
))
417 info
->within_function
= FALSE
;
418 info
->function_end
= (bfd_vma
) -1;
421 for (st
= info
->tags
; st
!= NULL
; st
= st
->next
)
423 enum debug_type_kind kind
;
426 if (kind
== DEBUG_KIND_ILLEGAL
)
427 kind
= DEBUG_KIND_STRUCT
;
428 st
->slot
= debug_make_undefined_tagged_type (dhandle
, st
->name
, kind
);
429 if (st
->slot
== DEBUG_TYPE_NULL
)
436 /* Handle a single stabs symbol. */
439 parse_stab (dhandle
, handle
, type
, desc
, value
, string
)
447 struct stab_handle
*info
= (struct stab_handle
*) handle
;
449 /* gcc will emit two N_SO strings per compilation unit, one for the
450 directory name and one for the file name. We just collect N_SO
451 strings as we see them, and start the new compilation unit when
452 we see a non N_SO symbol. */
453 if (info
->so_string
!= NULL
454 && (type
!= N_SO
|| *string
== '\0' || value
!= info
->so_value
))
456 if (! debug_set_filename (dhandle
, info
->so_string
))
458 info
->main_filename
= info
->so_string
;
460 info
->gcc_compiled
= 0;
461 info
->n_opt_found
= FALSE
;
463 /* Generally, for stabs in the symbol table, the N_LBRAC and
464 N_RBRAC symbols are relative to the N_SO symbol value. */
465 if (! info
->sections
)
466 info
->file_start_offset
= info
->so_value
;
468 /* We need to reset the mapping from type numbers to types. We
469 can't free the old mapping, because of the use of
470 debug_make_indirect_type. */
472 info
->file_types
= ((struct stab_types
**)
473 xmalloc (sizeof *info
->file_types
));
474 info
->file_types
[0] = NULL
;
476 info
->so_string
= NULL
;
478 /* Now process whatever type we just got. */
488 /* Ignore extra outermost context from SunPRO cc and acc. */
489 if (info
->n_opt_found
&& desc
== 1)
492 if (! info
->within_function
)
494 fprintf (stderr
, _("N_LBRAC not within function\n"));
498 /* Start an inner lexical block. */
499 if (! debug_start_block (dhandle
,
501 + info
->file_start_offset
502 + info
->function_start_offset
)))
505 /* Emit any pending variable definitions. */
506 if (! stab_emit_pending_vars (dhandle
, info
))
513 /* Ignore extra outermost context from SunPRO cc and acc. */
514 if (info
->n_opt_found
&& desc
== 1)
517 /* We shouldn't have any pending variable definitions here, but,
518 if we do, we probably need to emit them before closing the
520 if (! stab_emit_pending_vars (dhandle
, info
))
523 /* End an inner lexical block. */
524 if (! debug_end_block (dhandle
,
526 + info
->file_start_offset
527 + info
->function_start_offset
)))
531 if (info
->block_depth
< 0)
533 fprintf (stderr
, _("Too many N_RBRACs\n"));
539 /* This always ends a function. */
540 if (info
->within_function
)
546 && info
->function_end
!= (bfd_vma
) -1
547 && info
->function_end
< endval
)
548 endval
= info
->function_end
;
549 if (! stab_emit_pending_vars (dhandle
, info
)
550 || ! debug_end_function (dhandle
, endval
))
552 info
->within_function
= FALSE
;
553 info
->function_end
= (bfd_vma
) -1;
556 /* An empty string is emitted by gcc at the end of a compilation
561 /* Just accumulate strings until we see a non N_SO symbol. If
562 the string starts with a directory separator or some other
563 form of absolute path specification, we discard the previously
564 accumulated strings. */
565 if (info
->so_string
== NULL
)
566 info
->so_string
= xstrdup (string
);
573 if (IS_ABSOLUTE_PATH (string
))
574 info
->so_string
= xstrdup (string
);
576 info
->so_string
= concat (info
->so_string
, string
,
577 (const char *) NULL
);
581 info
->so_value
= value
;
586 /* Start an include file. */
587 if (! debug_start_source (dhandle
, string
))
592 /* Start an include file which may be replaced. */
593 push_bincl (info
, string
, value
);
594 if (! debug_start_source (dhandle
, string
))
599 /* End an N_BINCL include. */
600 if (! debug_start_source (dhandle
, pop_bincl (info
)))
605 /* This is a duplicate of a header file named by N_BINCL which
606 was eliminated by the linker. */
607 if (! find_excl (info
, string
, value
))
612 if (! debug_record_line (dhandle
, desc
,
613 value
+ info
->function_start_offset
))
618 if (! debug_start_common_block (dhandle
, string
))
623 if (! debug_end_common_block (dhandle
, string
))
630 if (info
->within_function
)
632 /* This always marks the end of a function; we don't
633 need to worry about info->function_end. */
635 value
+= info
->function_start_offset
;
636 if (! stab_emit_pending_vars (dhandle
, info
)
637 || ! debug_end_function (dhandle
, value
))
639 info
->within_function
= FALSE
;
640 info
->function_end
= (bfd_vma
) -1;
645 /* A const static symbol in the .text section will have an N_FUN
646 entry. We need to use these to mark the end of the function,
647 in case we are looking at gcc output before it was changed to
648 always emit an empty N_FUN. We can't call debug_end_function
649 here, because it might be a local static symbol. */
650 if (info
->within_function
651 && (info
->function_end
== (bfd_vma
) -1
652 || value
< info
->function_end
))
653 info
->function_end
= value
;
656 /* FIXME: gdb checks the string for N_STSYM, N_LCSYM or N_ROSYM
657 symbols, and if it does not start with :S, gdb relocates the
658 value to the start of the section. gcc always seems to use
659 :S, so we don't worry about this. */
665 colon
= strchr (string
, ':');
667 && (colon
[1] == 'f' || colon
[1] == 'F'))
669 if (info
->within_function
)
674 if (info
->function_end
!= (bfd_vma
) -1
675 && info
->function_end
< endval
)
676 endval
= info
->function_end
;
677 if (! stab_emit_pending_vars (dhandle
, info
)
678 || ! debug_end_function (dhandle
, endval
))
680 info
->function_end
= (bfd_vma
) -1;
682 /* For stabs in sections, line numbers and block addresses
683 are offsets from the start of the function. */
685 info
->function_start_offset
= value
;
686 info
->within_function
= TRUE
;
689 if (! parse_stab_string (dhandle
, info
, type
, desc
, value
, string
))
695 if (string
!= NULL
&& strcmp (string
, "gcc2_compiled.") == 0)
696 info
->gcc_compiled
= 2;
697 else if (string
!= NULL
&& strcmp (string
, "gcc_compiled.") == 0)
698 info
->gcc_compiled
= 1;
700 info
->n_opt_found
= TRUE
;
713 /* Parse the stabs string. */
716 parse_stab_string (dhandle
, info
, stabtype
, desc
, value
, string
)
718 struct stab_handle
*info
;
729 bfd_boolean self_crossref
;
733 p
= strchr (string
, ':');
748 /* GCC 2.x puts the line number in desc. SunOS apparently puts in
749 the number of bytes occupied by a type or object, which we
751 if (info
->gcc_compiled
>= 2)
756 /* FIXME: Sometimes the special C++ names start with '.'. */
758 if (string
[0] == '$')
766 /* Was: name = "vptr"; */
772 /* This was an anonymous type that was never fixed up. */
775 /* SunPRO (3.0 at least) static variable encoding. */
778 warn_stab (string
, _("unknown C++ encoded name"));
785 if (p
== string
|| (string
[0] == ' ' && p
== string
+ 1))
788 name
= savestring (string
, p
- string
);
792 if (ISDIGIT (*p
) || *p
== '(' || *p
== '-')
800 /* c is a special case, not followed by a type-number.
801 SYMBOL:c=iVALUE for an integer constant symbol.
802 SYMBOL:c=rVALUE for a floating constant symbol.
803 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
804 e.g. "b:c=e6,0" for "const b = blob1"
805 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
815 /* Floating point constant. */
816 if (! debug_record_float_const (dhandle
, name
, atof (p
)))
820 /* Integer constant. */
821 /* Defining integer constants this way is kind of silly,
822 since 'e' constants allows the compiler to give not only
823 the value, but the type as well. C has at least int,
824 long, unsigned int, and long long as constant types;
825 other languages probably should have at least unsigned as
826 well as signed constants. */
827 if (! debug_record_int_const (dhandle
, name
, atoi (p
)))
831 /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value
832 can be represented as integral.
833 e.g. "b:c=e6,0" for "const b = blob1"
834 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
835 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
,
836 &p
, (debug_type
**) NULL
);
837 if (dtype
== DEBUG_TYPE_NULL
)
844 if (! debug_record_typed_const (dhandle
, name
, dtype
, atoi (p
)))
855 /* The name of a caught exception. */
856 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
,
857 &p
, (debug_type
**) NULL
);
858 if (dtype
== DEBUG_TYPE_NULL
)
860 if (! debug_record_label (dhandle
, name
, dtype
, value
))
866 /* A function definition. */
867 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
868 (debug_type
**) NULL
);
869 if (dtype
== DEBUG_TYPE_NULL
)
871 if (! debug_record_function (dhandle
, name
, dtype
, type
== 'F', value
))
874 /* Sun acc puts declared types of arguments here. We don't care
875 about their actual types (FIXME -- we should remember the whole
876 function prototype), but the list may define some new types
877 that we have to remember, so we must scan it now. */
881 if (parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
882 (debug_type
**) NULL
)
895 /* A global symbol. The value must be extracted from the
897 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
898 (debug_type
**) NULL
);
899 if (dtype
== DEBUG_TYPE_NULL
)
901 leading
= bfd_get_symbol_leading_char (info
->abfd
);
902 for (c
= info
->symcount
, ps
= info
->syms
; c
> 0; --c
, ++ps
)
906 n
= bfd_asymbol_name (*ps
);
907 if (leading
!= '\0' && *n
== leading
)
909 if (*n
== *name
&& strcmp (n
, name
) == 0)
913 value
= bfd_asymbol_value (*ps
);
914 if (! stab_record_variable (dhandle
, info
, name
, dtype
, DEBUG_GLOBAL
,
920 /* This case is faked by a conditional above, when there is no
921 code letter in the dbx data. Dbx data never actually
925 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
926 (debug_type
**) NULL
);
927 if (dtype
== DEBUG_TYPE_NULL
)
929 if (! stab_record_variable (dhandle
, info
, name
, dtype
, DEBUG_LOCAL
,
935 /* A function parameter. */
937 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
938 (debug_type
**) NULL
);
941 /* pF is a two-letter code that means a function parameter in
942 Fortran. The type-number specifies the type of the return
943 value. Translate it into a pointer-to-function type. */
945 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
946 (debug_type
**) NULL
);
947 if (dtype
!= DEBUG_TYPE_NULL
)
951 ftype
= debug_make_function_type (dhandle
, dtype
,
952 (debug_type
*) NULL
, FALSE
);
953 dtype
= debug_make_pointer_type (dhandle
, ftype
);
956 if (dtype
== DEBUG_TYPE_NULL
)
958 if (! debug_record_parameter (dhandle
, name
, dtype
, DEBUG_PARM_STACK
,
962 /* FIXME: At this point gdb considers rearranging the parameter
963 address on a big endian machine if it is smaller than an int.
964 We have no way to do that, since we don't really know much
970 if (stabtype
== N_FUN
)
972 /* Prototype of a function referenced by this file. */
976 if (parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
977 (debug_type
**) NULL
)
985 /* Parameter which is in a register. */
986 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
987 (debug_type
**) NULL
);
988 if (dtype
== DEBUG_TYPE_NULL
)
990 if (! debug_record_parameter (dhandle
, name
, dtype
, DEBUG_PARM_REG
,
996 /* Register variable (either global or local). */
997 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
998 (debug_type
**) NULL
);
999 if (dtype
== DEBUG_TYPE_NULL
)
1001 if (! stab_record_variable (dhandle
, info
, name
, dtype
, DEBUG_REGISTER
,
1005 /* FIXME: At this point gdb checks to combine pairs of 'p' and
1006 'r' stabs into a single 'P' stab. */
1011 /* Static symbol at top level of file */
1012 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
1013 (debug_type
**) NULL
);
1014 if (dtype
== DEBUG_TYPE_NULL
)
1016 if (! stab_record_variable (dhandle
, info
, name
, dtype
, DEBUG_STATIC
,
1023 dtype
= parse_stab_type (dhandle
, info
, name
, &p
, &slot
);
1024 if (dtype
== DEBUG_TYPE_NULL
)
1028 /* A nameless type. Nothing to do. */
1032 dtype
= debug_name_type (dhandle
, name
, dtype
);
1033 if (dtype
== DEBUG_TYPE_NULL
)
1042 /* Struct, union, or enum tag. For GNU C++, this can be be followed
1043 by 't' which means we are typedef'ing it as well. */
1047 /* FIXME: gdb sets synonym to TRUE if the current language
1056 dtype
= parse_stab_type (dhandle
, info
, name
, &p
, &slot
);
1057 if (dtype
== DEBUG_TYPE_NULL
)
1062 /* INFO->SELF_CROSSREF is set by parse_stab_type if this type is
1063 a cross reference to itself. These are generated by some
1065 self_crossref
= info
->self_crossref
;
1067 dtype
= debug_tag_type (dhandle
, name
, dtype
);
1068 if (dtype
== DEBUG_TYPE_NULL
)
1073 /* See if we have a cross reference to this tag which we can now
1074 fill in. Avoid filling in a cross reference to ourselves,
1075 because that would lead to circular debugging information. */
1076 if (! self_crossref
)
1078 register struct stab_tag
**pst
;
1080 for (pst
= &info
->tags
; *pst
!= NULL
; pst
= &(*pst
)->next
)
1082 if ((*pst
)->name
[0] == name
[0]
1083 && strcmp ((*pst
)->name
, name
) == 0)
1085 (*pst
)->slot
= dtype
;
1086 *pst
= (*pst
)->next
;
1094 dtype
= debug_name_type (dhandle
, name
, dtype
);
1095 if (dtype
== DEBUG_TYPE_NULL
)
1105 /* Static symbol of local scope */
1106 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
1107 (debug_type
**) NULL
);
1108 if (dtype
== DEBUG_TYPE_NULL
)
1110 /* FIXME: gdb checks os9k_stabs here. */
1111 if (! stab_record_variable (dhandle
, info
, name
, dtype
,
1112 DEBUG_LOCAL_STATIC
, value
))
1117 /* Reference parameter. */
1118 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
1119 (debug_type
**) NULL
);
1120 if (dtype
== DEBUG_TYPE_NULL
)
1122 if (! debug_record_parameter (dhandle
, name
, dtype
, DEBUG_PARM_REFERENCE
,
1128 /* Reference parameter which is in a register. */
1129 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
1130 (debug_type
**) NULL
);
1131 if (dtype
== DEBUG_TYPE_NULL
)
1133 if (! debug_record_parameter (dhandle
, name
, dtype
, DEBUG_PARM_REF_REG
,
1139 /* This is used by Sun FORTRAN for "function result value".
1140 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
1141 that Pascal uses it too, but when I tried it Pascal used
1142 "x:3" (local symbol) instead. */
1143 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, &p
,
1144 (debug_type
**) NULL
);
1145 if (dtype
== DEBUG_TYPE_NULL
)
1147 if (! stab_record_variable (dhandle
, info
, name
, dtype
, DEBUG_LOCAL
,
1157 /* FIXME: gdb converts structure values to structure pointers in a
1158 couple of cases, depending upon the target. */
1163 /* Parse a stabs type. The typename argument is non-NULL if this is a
1164 typedef or a tag definition. The pp argument points to the stab
1165 string, and is updated. The slotp argument points to a place to
1166 store the slot used if the type is being defined. */
1169 parse_stab_type (dhandle
, info
, typename
, pp
, slotp
)
1171 struct stab_handle
*info
;
1172 const char *typename
;
1179 bfd_boolean stringp
;
1191 info
->self_crossref
= FALSE
;
1193 /* Read type number if present. The type number may be omitted.
1194 for instance in a two-dimensional array declared with type
1195 "ar1;1;10;ar1;1;10;4". */
1196 if (! ISDIGIT (**pp
) && **pp
!= '(' && **pp
!= '-')
1198 /* 'typenums=' not present, type is anonymous. Read and return
1199 the definition, but don't put it in the type vector. */
1200 typenums
[0] = typenums
[1] = -1;
1204 if (! parse_stab_type_number (pp
, typenums
))
1205 return DEBUG_TYPE_NULL
;
1209 /* Type is not being defined here. Either it already
1210 exists, or this is a forward reference to it. */
1211 return stab_find_type (dhandle
, info
, typenums
);
1214 /* Only set the slot if the type is being defined. This means
1215 that the mapping from type numbers to types will only record
1216 the name of the typedef which defines a type. If we don't do
1217 this, then something like
1220 will record that i is of type foo. Unfortunately, stabs
1221 information is ambiguous about variable types. For this code,
1225 the stabs information records both i and j as having the same
1226 type. This could be fixed by patching the compiler. */
1227 if (slotp
!= NULL
&& typenums
[0] >= 0 && typenums
[1] >= 0)
1228 *slotp
= stab_find_slot (info
, typenums
);
1230 /* Type is being defined here. */
1236 const char *p
= *pp
+ 1;
1239 if (ISDIGIT (*p
) || *p
== '(' || *p
== '-')
1245 /* Type attributes. */
1248 for (; *p
!= ';'; ++p
)
1253 return DEBUG_TYPE_NULL
;
1261 size
= atoi (attr
+ 1);
1262 size
/= 8; /* Size is in bits. We store it in bytes. */
1272 /* Ignore unrecognized type attributes, so future
1273 compilers can invent new ones. */
1286 enum debug_type_kind code
;
1287 const char *q1
, *q2
, *p
;
1289 /* A cross reference to another type. */
1294 code
= DEBUG_KIND_STRUCT
;
1297 code
= DEBUG_KIND_UNION
;
1300 code
= DEBUG_KIND_ENUM
;
1303 /* Complain and keep going, so compilers can invent new
1304 cross-reference types. */
1305 warn_stab (orig
, _("unrecognized cross reference type"));
1306 code
= DEBUG_KIND_STRUCT
;
1311 q1
= strchr (*pp
, '<');
1312 p
= strchr (*pp
, ':');
1316 return DEBUG_TYPE_NULL
;
1318 if (q1
!= NULL
&& p
> q1
&& p
[1] == ':')
1322 for (q2
= q1
; *q2
!= '\0'; ++q2
)
1326 else if (*q2
== '>')
1328 else if (*q2
== ':' && nest
== 0)
1335 return DEBUG_TYPE_NULL
;
1339 /* Some versions of g++ can emit stabs like
1341 which define structures in terms of themselves. We need to
1342 tell the caller to avoid building a circular structure. */
1343 if (typename
!= NULL
1344 && strncmp (typename
, *pp
, p
- *pp
) == 0
1345 && typename
[p
- *pp
] == '\0')
1346 info
->self_crossref
= TRUE
;
1348 dtype
= stab_find_tagged_type (dhandle
, info
, *pp
, p
- *pp
, code
);
1370 /* This type is defined as another type. */
1375 /* Peek ahead at the number to detect void. */
1376 if (! parse_stab_type_number (pp
, xtypenums
))
1377 return DEBUG_TYPE_NULL
;
1379 if (typenums
[0] == xtypenums
[0] && typenums
[1] == xtypenums
[1])
1381 /* This type is being defined as itself, which means that
1383 dtype
= debug_make_void_type (dhandle
);
1389 /* Go back to the number and have parse_stab_type get it.
1390 This means that we can deal with something like
1391 t(1,2)=(3,4)=... which the Lucid compiler uses. */
1392 dtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
,
1393 pp
, (debug_type
**) NULL
);
1394 if (dtype
== DEBUG_TYPE_NULL
)
1395 return DEBUG_TYPE_NULL
;
1398 if (typenums
[0] != -1)
1400 if (! stab_record_type (dhandle
, info
, typenums
, dtype
))
1401 return DEBUG_TYPE_NULL
;
1408 dtype
= debug_make_pointer_type (dhandle
,
1409 parse_stab_type (dhandle
, info
,
1410 (const char *) NULL
,
1412 (debug_type
**) NULL
));
1416 /* Reference to another type. */
1417 dtype
= (debug_make_reference_type
1419 parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
1420 (debug_type
**) NULL
)));
1424 /* Function returning another type. */
1425 /* FIXME: gdb checks os9k_stabs here. */
1426 dtype
= (debug_make_function_type
1428 parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
1429 (debug_type
**) NULL
),
1430 (debug_type
*) NULL
, FALSE
));
1434 /* Const qualifier on some type (Sun). */
1435 /* FIXME: gdb accepts 'c' here if os9k_stabs. */
1436 dtype
= debug_make_const_type (dhandle
,
1437 parse_stab_type (dhandle
, info
,
1438 (const char *) NULL
,
1440 (debug_type
**) NULL
));
1444 /* Volatile qual on some type (Sun). */
1445 /* FIXME: gdb accepts 'i' here if os9k_stabs. */
1446 dtype
= (debug_make_volatile_type
1448 parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
1449 (debug_type
**) NULL
)));
1453 /* Offset (class & variable) type. This is used for a pointer
1454 relative to an object. */
1461 domain
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
1462 (debug_type
**) NULL
);
1463 if (domain
== DEBUG_TYPE_NULL
)
1464 return DEBUG_TYPE_NULL
;
1469 return DEBUG_TYPE_NULL
;
1473 memtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
1474 (debug_type
**) NULL
);
1475 if (memtype
== DEBUG_TYPE_NULL
)
1476 return DEBUG_TYPE_NULL
;
1478 dtype
= debug_make_offset_type (dhandle
, domain
, memtype
);
1483 /* Method (class & fn) type. */
1486 debug_type return_type
;
1489 return_type
= parse_stab_type (dhandle
, info
, (const char *) NULL
,
1490 pp
, (debug_type
**) NULL
);
1491 if (return_type
== DEBUG_TYPE_NULL
)
1492 return DEBUG_TYPE_NULL
;
1496 return DEBUG_TYPE_NULL
;
1499 dtype
= debug_make_method_type (dhandle
, return_type
,
1501 (debug_type
*) NULL
, FALSE
);
1506 debug_type return_type
;
1510 bfd_boolean varargs
;
1512 domain
= parse_stab_type (dhandle
, info
, (const char *) NULL
,
1513 pp
, (debug_type
**) NULL
);
1514 if (domain
== DEBUG_TYPE_NULL
)
1515 return DEBUG_TYPE_NULL
;
1520 return DEBUG_TYPE_NULL
;
1524 return_type
= parse_stab_type (dhandle
, info
, (const char *) NULL
,
1525 pp
, (debug_type
**) NULL
);
1526 if (return_type
== DEBUG_TYPE_NULL
)
1527 return DEBUG_TYPE_NULL
;
1530 args
= (debug_type
*) xmalloc (alloc
* sizeof *args
);
1537 return DEBUG_TYPE_NULL
;
1544 args
= ((debug_type
*)
1545 xrealloc ((PTR
) args
, alloc
* sizeof *args
));
1548 args
[n
] = parse_stab_type (dhandle
, info
, (const char *) NULL
,
1549 pp
, (debug_type
**) NULL
);
1550 if (args
[n
] == DEBUG_TYPE_NULL
)
1551 return DEBUG_TYPE_NULL
;
1556 /* If the last type is not void, then this function takes a
1557 variable number of arguments. Otherwise, we must strip
1560 || debug_get_type_kind (dhandle
, args
[n
- 1]) != DEBUG_KIND_VOID
)
1568 args
[n
] = DEBUG_TYPE_NULL
;
1570 dtype
= debug_make_method_type (dhandle
, return_type
, domain
, args
,
1577 dtype
= parse_stab_range_type (dhandle
, info
, typename
, pp
, typenums
);
1581 /* FIXME: gdb checks os9k_stabs here. */
1582 /* Sun ACC builtin int type. */
1583 dtype
= parse_stab_sun_builtin_type (dhandle
, pp
);
1587 /* Sun ACC builtin float type. */
1588 dtype
= parse_stab_sun_floating_type (dhandle
, pp
);
1592 /* Enumeration type. */
1593 dtype
= parse_stab_enum_type (dhandle
, pp
);
1598 /* Struct or union type. */
1599 dtype
= parse_stab_struct_type (dhandle
, info
, typename
, pp
,
1600 descriptor
== 's', typenums
);
1608 return DEBUG_TYPE_NULL
;
1612 dtype
= parse_stab_array_type (dhandle
, info
, pp
, stringp
);
1616 dtype
= debug_make_set_type (dhandle
,
1617 parse_stab_type (dhandle
, info
,
1618 (const char *) NULL
,
1620 (debug_type
**) NULL
),
1626 return DEBUG_TYPE_NULL
;
1629 if (dtype
== DEBUG_TYPE_NULL
)
1630 return DEBUG_TYPE_NULL
;
1632 if (typenums
[0] != -1)
1634 if (! stab_record_type (dhandle
, info
, typenums
, dtype
))
1635 return DEBUG_TYPE_NULL
;
1640 if (! debug_record_type_size (dhandle
, dtype
, (unsigned int) size
))
1641 return DEBUG_TYPE_NULL
;
1647 /* Read a number by which a type is referred to in dbx data, or
1648 perhaps read a pair (FILENUM, TYPENUM) in parentheses. Just a
1649 single number N is equivalent to (0,N). Return the two numbers by
1650 storing them in the vector TYPENUMS. */
1653 parse_stab_type_number (pp
, typenums
)
1664 typenums
[1] = (int) parse_number (pp
, (bfd_boolean
*) NULL
);
1669 typenums
[0] = (int) parse_number (pp
, (bfd_boolean
*) NULL
);
1676 typenums
[1] = (int) parse_number (pp
, (bfd_boolean
*) NULL
);
1688 /* Parse a range type. */
1691 parse_stab_range_type (dhandle
, info
, typename
, pp
, typenums
)
1693 struct stab_handle
*info
;
1694 const char *typename
;
1696 const int *typenums
;
1700 bfd_boolean self_subrange
;
1701 debug_type index_type
;
1702 const char *s2
, *s3
;
1703 bfd_signed_vma n2
, n3
;
1704 bfd_boolean ov2
, ov3
;
1708 index_type
= DEBUG_TYPE_NULL
;
1710 /* First comes a type we are a subrange of.
1711 In C it is usually 0, 1 or the type being defined. */
1712 if (! parse_stab_type_number (pp
, rangenums
))
1713 return DEBUG_TYPE_NULL
;
1715 self_subrange
= (rangenums
[0] == typenums
[0]
1716 && rangenums
[1] == typenums
[1]);
1721 index_type
= parse_stab_type (dhandle
, info
, (const char *) NULL
,
1722 pp
, (debug_type
**) NULL
);
1723 if (index_type
== DEBUG_TYPE_NULL
)
1724 return DEBUG_TYPE_NULL
;
1730 /* The remaining two operands are usually lower and upper bounds of
1731 the range. But in some special cases they mean something else. */
1733 n2
= parse_number (pp
, &ov2
);
1737 return DEBUG_TYPE_NULL
;
1742 n3
= parse_number (pp
, &ov3
);
1746 return DEBUG_TYPE_NULL
;
1752 /* gcc will emit range stabs for long long types. Handle this
1753 as a special case. FIXME: This needs to be more general. */
1754 #define LLLOW "01000000000000000000000;"
1755 #define LLHIGH "0777777777777777777777;"
1756 #define ULLHIGH "01777777777777777777777;"
1757 if (index_type
== DEBUG_TYPE_NULL
)
1759 if (strncmp (s2
, LLLOW
, sizeof LLLOW
- 1) == 0
1760 && strncmp (s3
, LLHIGH
, sizeof LLHIGH
- 1) == 0)
1761 return debug_make_int_type (dhandle
, 8, FALSE
);
1764 && strncmp (s3
, ULLHIGH
, sizeof ULLHIGH
- 1) == 0)
1765 return debug_make_int_type (dhandle
, 8, TRUE
);
1768 warn_stab (orig
, _("numeric overflow"));
1771 if (index_type
== DEBUG_TYPE_NULL
)
1773 /* A type defined as a subrange of itself, with both bounds 0,
1775 if (self_subrange
&& n2
== 0 && n3
== 0)
1776 return debug_make_void_type (dhandle
);
1778 /* A type defined as a subrange of itself, with n2 positive and
1779 n3 zero, is a complex type, and n2 is the number of bytes. */
1780 if (self_subrange
&& n3
== 0 && n2
> 0)
1781 return debug_make_complex_type (dhandle
, n2
);
1783 /* If n3 is zero and n2 is positive, this is a floating point
1784 type, and n2 is the number of bytes. */
1785 if (n3
== 0 && n2
> 0)
1786 return debug_make_float_type (dhandle
, n2
);
1788 /* If the upper bound is -1, this is an unsigned int. */
1789 if (n2
== 0 && n3
== -1)
1791 /* When gcc is used with -gstabs, but not -gstabs+, it will emit
1792 long long int:t6=r1;0;-1;
1793 long long unsigned int:t7=r1;0;-1;
1794 We hack here to handle this reasonably. */
1795 if (typename
!= NULL
)
1797 if (strcmp (typename
, "long long int") == 0)
1798 return debug_make_int_type (dhandle
, 8, FALSE
);
1799 else if (strcmp (typename
, "long long unsigned int") == 0)
1800 return debug_make_int_type (dhandle
, 8, TRUE
);
1802 /* FIXME: The size here really depends upon the target. */
1803 return debug_make_int_type (dhandle
, 4, TRUE
);
1806 /* A range of 0 to 127 is char. */
1807 if (self_subrange
&& n2
== 0 && n3
== 127)
1808 return debug_make_int_type (dhandle
, 1, FALSE
);
1810 /* FIXME: gdb checks for the language CHILL here. */
1815 return debug_make_int_type (dhandle
, - n3
, TRUE
);
1816 else if (n3
== 0xff)
1817 return debug_make_int_type (dhandle
, 1, TRUE
);
1818 else if (n3
== 0xffff)
1819 return debug_make_int_type (dhandle
, 2, TRUE
);
1820 else if (n3
== (bfd_signed_vma
) 0xffffffff)
1821 return debug_make_int_type (dhandle
, 4, TRUE
);
1823 else if (n3
== ((((bfd_signed_vma
) 0xffffffff) << 32) | 0xffffffff))
1824 return debug_make_int_type (dhandle
, 8, TRUE
);
1829 && (self_subrange
|| n2
== -8))
1830 return debug_make_int_type (dhandle
, - n2
, TRUE
);
1831 else if (n2
== - n3
- 1 || n2
== n3
+ 1)
1834 return debug_make_int_type (dhandle
, 1, FALSE
);
1835 else if (n3
== 0x7fff)
1836 return debug_make_int_type (dhandle
, 2, FALSE
);
1837 else if (n3
== 0x7fffffff)
1838 return debug_make_int_type (dhandle
, 4, FALSE
);
1840 else if (n3
== ((((bfd_vma
) 0x7fffffff) << 32) | 0xffffffff))
1841 return debug_make_int_type (dhandle
, 8, FALSE
);
1846 /* At this point I don't have the faintest idea how to deal with a
1847 self_subrange type; I'm going to assume that this is used as an
1848 idiom, and that all of them are special cases. So . . . */
1852 return DEBUG_TYPE_NULL
;
1855 index_type
= stab_find_type (dhandle
, info
, rangenums
);
1856 if (index_type
== DEBUG_TYPE_NULL
)
1858 /* Does this actually ever happen? Is that why we are worrying
1859 about dealing with it rather than just calling error_type? */
1860 warn_stab (orig
, _("missing index type"));
1861 index_type
= debug_make_int_type (dhandle
, 4, FALSE
);
1864 return debug_make_range_type (dhandle
, index_type
, n2
, n3
);
1867 /* Sun's ACC uses a somewhat saner method for specifying the builtin
1868 typedefs in every file (for int, long, etc):
1870 type = b <signed> <width>; <offset>; <nbits>
1871 signed = u or s. Possible c in addition to u or s (for char?).
1872 offset = offset from high order bit to start bit of type.
1873 width is # bytes in object of this type, nbits is # bits in type.
1875 The width/offset stuff appears to be for small objects stored in
1876 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
1880 parse_stab_sun_builtin_type (dhandle
, pp
)
1885 bfd_boolean unsignedp
;
1900 return DEBUG_TYPE_NULL
;
1904 /* For some odd reason, all forms of char put a c here. This is strange
1905 because no other type has this honor. We can safely ignore this because
1906 we actually determine 'char'acterness by the number of bits specified in
1911 /* The first number appears to be the number of bytes occupied
1912 by this type, except that unsigned short is 4 instead of 2.
1913 Since this information is redundant with the third number,
1914 we will ignore it. */
1915 (void) parse_number (pp
, (bfd_boolean
*) NULL
);
1919 return DEBUG_TYPE_NULL
;
1923 /* The second number is always 0, so ignore it too. */
1924 (void) parse_number (pp
, (bfd_boolean
*) NULL
);
1928 return DEBUG_TYPE_NULL
;
1932 /* The third number is the number of bits for this type. */
1933 bits
= parse_number (pp
, (bfd_boolean
*) NULL
);
1935 /* The type *should* end with a semicolon. If it are embedded
1936 in a larger type the semicolon may be the only way to know where
1937 the type ends. If this type is at the end of the stabstring we
1938 can deal with the omitted semicolon (but we don't have to like
1939 it). Don't bother to complain(), Sun's compiler omits the semicolon
1945 return debug_make_void_type (dhandle
);
1947 return debug_make_int_type (dhandle
, bits
/ 8, unsignedp
);
1950 /* Parse a builtin floating type generated by the Sun compiler. */
1953 parse_stab_sun_floating_type (dhandle
, pp
)
1963 /* The first number has more details about the type, for example
1965 details
= parse_number (pp
, (bfd_boolean
*) NULL
);
1969 return DEBUG_TYPE_NULL
;
1972 /* The second number is the number of bytes occupied by this type */
1973 bytes
= parse_number (pp
, (bfd_boolean
*) NULL
);
1977 return DEBUG_TYPE_NULL
;
1980 if (details
== NF_COMPLEX
1981 || details
== NF_COMPLEX16
1982 || details
== NF_COMPLEX32
)
1983 return debug_make_complex_type (dhandle
, bytes
);
1985 return debug_make_float_type (dhandle
, bytes
);
1988 /* Handle an enum type. */
1991 parse_stab_enum_type (dhandle
, pp
)
1997 bfd_signed_vma
*values
;
2003 /* FIXME: gdb checks os9k_stabs here. */
2005 /* The aix4 compiler emits an extra field before the enum members;
2006 my guess is it's a type of some sort. Just ignore it. */
2014 /* Read the value-names and their values.
2015 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
2016 A semicolon or comma instead of a NAME means the end. */
2018 names
= (const char **) xmalloc (alloc
* sizeof *names
);
2019 values
= (bfd_signed_vma
*) xmalloc (alloc
* sizeof *values
);
2021 while (**pp
!= '\0' && **pp
!= ';' && **pp
!= ',')
2031 name
= savestring (*pp
, p
- *pp
);
2034 val
= (bfd_signed_vma
) parse_number (pp
, (bfd_boolean
*) NULL
);
2038 return DEBUG_TYPE_NULL
;
2045 names
= ((const char **)
2046 xrealloc ((PTR
) names
, alloc
* sizeof *names
));
2047 values
= ((bfd_signed_vma
*)
2048 xrealloc ((PTR
) values
, alloc
* sizeof *values
));
2062 return debug_make_enum_type (dhandle
, names
, values
);
2065 /* Read the description of a structure (or union type) and return an object
2066 describing the type.
2068 PP points to a character pointer that points to the next unconsumed token
2069 in the the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
2070 *PP will point to "4a:1,0,32;;". */
2073 parse_stab_struct_type (dhandle
, info
, tagname
, pp
, structp
, typenums
)
2075 struct stab_handle
*info
;
2076 const char *tagname
;
2078 bfd_boolean structp
;
2079 const int *typenums
;
2083 debug_baseclass
*baseclasses
;
2084 debug_field
*fields
;
2085 bfd_boolean statics
;
2086 debug_method
*methods
;
2087 debug_type vptrbase
;
2088 bfd_boolean ownvptr
;
2093 size
= parse_number (pp
, (bfd_boolean
*) NULL
);
2095 /* Get the other information. */
2096 if (! parse_stab_baseclasses (dhandle
, info
, pp
, &baseclasses
)
2097 || ! parse_stab_struct_fields (dhandle
, info
, pp
, &fields
, &statics
)
2098 || ! parse_stab_members (dhandle
, info
, tagname
, pp
, typenums
, &methods
)
2099 || ! parse_stab_tilde_field (dhandle
, info
, pp
, typenums
, &vptrbase
,
2101 return DEBUG_TYPE_NULL
;
2104 && baseclasses
== NULL
2106 && vptrbase
== DEBUG_TYPE_NULL
2108 return debug_make_struct_type (dhandle
, structp
, size
, fields
);
2110 return debug_make_object_type (dhandle
, structp
, size
, fields
, baseclasses
,
2111 methods
, vptrbase
, ownvptr
);
2114 /* The stabs for C++ derived classes contain baseclass information which
2115 is marked by a '!' character after the total size. This function is
2116 called when we encounter the baseclass marker, and slurps up all the
2117 baseclass information.
2119 Immediately following the '!' marker is the number of base classes that
2120 the class is derived from, followed by information for each base class.
2121 For each base class, there are two visibility specifiers, a bit offset
2122 to the base class information within the derived class, a reference to
2123 the type for the base class, and a terminating semicolon.
2125 A typical example, with two base classes, would be "!2,020,19;0264,21;".
2127 Baseclass information marker __________________|| | | | | | |
2128 Number of baseclasses __________________________| | | | | | |
2129 Visibility specifiers (2) ________________________| | | | | |
2130 Offset in bits from start of class _________________| | | | |
2131 Type number for base class ___________________________| | | |
2132 Visibility specifiers (2) _______________________________| | |
2133 Offset in bits from start of class ________________________| |
2134 Type number of base class ____________________________________|
2136 Return TRUE for success, FALSE for failure. */
2139 parse_stab_baseclasses (dhandle
, info
, pp
, retp
)
2141 struct stab_handle
*info
;
2143 debug_baseclass
**retp
;
2147 debug_baseclass
*classes
;
2155 /* No base classes. */
2160 c
= (unsigned int) parse_number (pp
, (bfd_boolean
*) NULL
);
2169 classes
= (debug_baseclass
*) xmalloc ((c
+ 1) * sizeof (**retp
));
2171 for (i
= 0; i
< c
; i
++)
2173 bfd_boolean
virtual;
2174 enum debug_visibility visibility
;
2187 warn_stab (orig
, _("unknown virtual character for baseclass"));
2196 visibility
= DEBUG_VISIBILITY_PRIVATE
;
2199 visibility
= DEBUG_VISIBILITY_PROTECTED
;
2202 visibility
= DEBUG_VISIBILITY_PUBLIC
;
2205 warn_stab (orig
, _("unknown visibility character for baseclass"));
2206 visibility
= DEBUG_VISIBILITY_PUBLIC
;
2211 /* The remaining value is the bit offset of the portion of the
2212 object corresponding to this baseclass. Always zero in the
2213 absence of multiple inheritance. */
2214 bitpos
= parse_number (pp
, (bfd_boolean
*) NULL
);
2222 type
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
2223 (debug_type
**) NULL
);
2224 if (type
== DEBUG_TYPE_NULL
)
2227 classes
[i
] = debug_make_baseclass (dhandle
, type
, bitpos
, virtual,
2229 if (classes
[i
] == DEBUG_BASECLASS_NULL
)
2237 classes
[i
] = DEBUG_BASECLASS_NULL
;
2244 /* Read struct or class data fields. They have the form:
2246 NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
2248 At the end, we see a semicolon instead of a field.
2250 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
2253 The optional VISIBILITY is one of:
2255 '/0' (VISIBILITY_PRIVATE)
2256 '/1' (VISIBILITY_PROTECTED)
2257 '/2' (VISIBILITY_PUBLIC)
2258 '/9' (VISIBILITY_IGNORE)
2260 or nothing, for C style fields with public visibility.
2262 Returns 1 for success, 0 for failure. */
2265 parse_stab_struct_fields (dhandle
, info
, pp
, retp
, staticsp
)
2267 struct stab_handle
*info
;
2270 bfd_boolean
*staticsp
;
2274 debug_field
*fields
;
2285 fields
= (debug_field
*) xmalloc (alloc
* sizeof *fields
);
2288 /* FIXME: gdb checks os9k_stabs here. */
2292 /* Add 1 to c to leave room for NULL pointer at end. */
2296 fields
= ((debug_field
*)
2297 xrealloc ((PTR
) fields
, alloc
* sizeof *fields
));
2300 /* If it starts with CPLUS_MARKER it is a special abbreviation,
2301 unless the CPLUS_MARKER is followed by an underscore, in
2302 which case it is just the name of an anonymous type, which we
2303 should handle like any other type name. We accept either '$'
2304 or '.', because a field name can never contain one of these
2305 characters except as a CPLUS_MARKER. */
2307 if ((*p
== '$' || *p
== '.') && p
[1] != '_')
2310 if (! parse_stab_cpp_abbrev (dhandle
, info
, pp
, fields
+ c
))
2316 /* Look for the ':' that separates the field name from the field
2317 values. Data members are delimited by a single ':', while member
2318 functions are delimited by a pair of ':'s. When we hit the member
2319 functions (if any), terminate scan loop and return. */
2321 p
= strchr (p
, ':');
2331 if (! parse_stab_one_struct_field (dhandle
, info
, pp
, p
, fields
+ c
,
2338 fields
[c
] = DEBUG_FIELD_NULL
;
2345 /* Special GNU C++ name. */
2348 parse_stab_cpp_abbrev (dhandle
, info
, pp
, retp
)
2350 struct stab_handle
*info
;
2358 const char *typename
;
2362 *retp
= DEBUG_FIELD_NULL
;
2376 /* At this point, *pp points to something like "22:23=*22...", where
2377 the type number before the ':' is the "context" and everything
2378 after is a regular type definition. Lookup the type, find it's
2379 name, and construct the field name. */
2381 context
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
2382 (debug_type
**) NULL
);
2383 if (context
== DEBUG_TYPE_NULL
)
2389 /* $vf -- a virtual function table pointer. */
2393 /* $vb -- a virtual bsomethingorother */
2394 typename
= debug_get_type_name (dhandle
, context
);
2395 if (typename
== NULL
)
2397 warn_stab (orig
, _("unnamed $vb type"));
2400 name
= concat ("_vb$", typename
, (const char *) NULL
);
2403 warn_stab (orig
, _("unrecognized C++ abbreviation"));
2404 name
= "INVALID_CPLUSPLUS_ABBREV";
2415 type
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
2416 (debug_type
**) NULL
);
2424 bitpos
= parse_number (pp
, (bfd_boolean
*) NULL
);
2432 *retp
= debug_make_field (dhandle
, name
, type
, bitpos
, 0,
2433 DEBUG_VISIBILITY_PRIVATE
);
2434 if (*retp
== DEBUG_FIELD_NULL
)
2440 /* Parse a single field in a struct or union. */
2443 parse_stab_one_struct_field (dhandle
, info
, pp
, p
, retp
, staticsp
)
2445 struct stab_handle
*info
;
2449 bfd_boolean
*staticsp
;
2453 enum debug_visibility visibility
;
2460 /* FIXME: gdb checks ARM_DEMANGLING here. */
2462 name
= savestring (*pp
, p
- *pp
);
2467 visibility
= DEBUG_VISIBILITY_PUBLIC
;
2474 visibility
= DEBUG_VISIBILITY_PRIVATE
;
2477 visibility
= DEBUG_VISIBILITY_PROTECTED
;
2480 visibility
= DEBUG_VISIBILITY_PUBLIC
;
2483 warn_stab (orig
, _("unknown visibility character for field"));
2484 visibility
= DEBUG_VISIBILITY_PUBLIC
;
2490 type
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
2491 (debug_type
**) NULL
);
2492 if (type
== DEBUG_TYPE_NULL
)
2499 /* This is a static class member. */
2501 p
= strchr (*pp
, ';');
2508 varname
= savestring (*pp
, p
- *pp
);
2512 *retp
= debug_make_static_member (dhandle
, name
, type
, varname
,
2526 bitpos
= parse_number (pp
, (bfd_boolean
*) NULL
);
2534 bitsize
= parse_number (pp
, (bfd_boolean
*) NULL
);
2542 if (bitpos
== 0 && bitsize
== 0)
2544 /* This can happen in two cases: (1) at least for gcc 2.4.5 or
2545 so, it is a field which has been optimized out. The correct
2546 stab for this case is to use VISIBILITY_IGNORE, but that is a
2547 recent invention. (2) It is a 0-size array. For example
2548 union { int num; char str[0]; } foo. Printing "<no value>"
2549 for str in "p foo" is OK, since foo.str (and thus foo.str[3])
2550 will continue to work, and a 0-size array as a whole doesn't
2551 have any contents to print.
2553 I suspect this probably could also happen with gcc -gstabs
2554 (not -gstabs+) for static fields, and perhaps other C++
2555 extensions. Hopefully few people use -gstabs with gdb, since
2556 it is intended for dbx compatibility. */
2557 visibility
= DEBUG_VISIBILITY_IGNORE
;
2560 /* FIXME: gdb does some stuff here to mark fields as unpacked. */
2562 *retp
= debug_make_field (dhandle
, name
, type
, bitpos
, bitsize
, visibility
);
2567 /* Read member function stabs info for C++ classes. The form of each member
2570 NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
2572 An example with two member functions is:
2574 afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
2576 For the case of overloaded operators, the format is op$::*.funcs, where
2577 $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
2578 name (such as `+=') and `.' marks the end of the operator name. */
2581 parse_stab_members (dhandle
, info
, tagname
, pp
, typenums
, retp
)
2583 struct stab_handle
*info
;
2584 const char *tagname
;
2586 const int *typenums
;
2587 debug_method
**retp
;
2590 debug_method
*methods
;
2606 debug_method_variant
*variants
;
2608 unsigned int allocvars
;
2609 debug_type look_ahead_type
;
2611 p
= strchr (*pp
, ':');
2612 if (p
== NULL
|| p
[1] != ':')
2615 /* FIXME: Some systems use something other than '$' here. */
2616 if ((*pp
)[0] != 'o' || (*pp
)[1] != 'p' || (*pp
)[2] != '$')
2618 name
= savestring (*pp
, p
- *pp
);
2623 /* This is a completely wierd case. In order to stuff in the
2624 names that might contain colons (the usual name delimiter),
2625 Mike Tiemann defined a different name format which is
2626 signalled if the identifier is "op$". In that case, the
2627 format is "op$::XXXX." where XXXX is the name. This is
2628 used for names like "+" or "=". YUUUUUUUK! FIXME! */
2630 for (p
= *pp
; *p
!= '.' && *p
!= '\0'; p
++)
2637 name
= savestring (*pp
, p
- *pp
);
2642 variants
= ((debug_method_variant
*)
2643 xmalloc (allocvars
* sizeof *variants
));
2646 look_ahead_type
= DEBUG_TYPE_NULL
;
2653 enum debug_visibility visibility
;
2654 bfd_boolean constp
, volatilep
, staticp
;
2657 const char *physname
;
2658 bfd_boolean varargs
;
2660 if (look_ahead_type
!= DEBUG_TYPE_NULL
)
2662 /* g++ version 1 kludge */
2663 type
= look_ahead_type
;
2664 look_ahead_type
= DEBUG_TYPE_NULL
;
2668 type
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
2669 (debug_type
**) NULL
);
2670 if (type
== DEBUG_TYPE_NULL
)
2680 p
= strchr (*pp
, ';');
2688 if (debug_get_type_kind (dhandle
, type
) == DEBUG_KIND_METHOD
2689 && debug_get_parameter_types (dhandle
, type
, &varargs
) == NULL
)
2692 argtypes
= savestring (*pp
, p
- *pp
);
2698 visibility
= DEBUG_VISIBILITY_PRIVATE
;
2701 visibility
= DEBUG_VISIBILITY_PROTECTED
;
2704 visibility
= DEBUG_VISIBILITY_PUBLIC
;
2714 /* Normal function. */
2718 /* const member function. */
2723 /* volatile member function. */
2728 /* const volatile member function. */
2736 /* File compiled with g++ version 1; no information. */
2739 warn_stab (orig
, _("const/volatile indicator missing"));
2747 /* virtual member function, followed by index. The sign
2748 bit is supposedly set to distinguish
2749 pointers-to-methods from virtual function indicies. */
2751 voffset
= parse_number (pp
, (bfd_boolean
*) NULL
);
2758 voffset
&= 0x7fffffff;
2760 if (**pp
== ';' || *pp
== '\0')
2762 /* Must be g++ version 1. */
2763 context
= DEBUG_TYPE_NULL
;
2767 /* Figure out from whence this virtual function
2768 came. It may belong to virtual function table of
2769 one of its baseclasses. */
2770 look_ahead_type
= parse_stab_type (dhandle
, info
,
2771 (const char *) NULL
,
2773 (debug_type
**) NULL
);
2776 /* g++ version 1 overloaded methods. */
2777 context
= DEBUG_TYPE_NULL
;
2781 context
= look_ahead_type
;
2782 look_ahead_type
= DEBUG_TYPE_NULL
;
2794 /* static member function. */
2798 context
= DEBUG_TYPE_NULL
;
2799 if (strncmp (argtypes
, name
, strlen (name
)) != 0)
2804 warn_stab (orig
, "member function type missing");
2806 context
= DEBUG_TYPE_NULL
;
2812 context
= DEBUG_TYPE_NULL
;
2816 /* If the type is not a stub, then the argtypes string is
2817 the physical name of the function. Otherwise the
2818 argtypes string is the mangled form of the argument
2819 types, and the full type and the physical name must be
2820 extracted from them. */
2822 physname
= argtypes
;
2825 debug_type class_type
, return_type
;
2827 class_type
= stab_find_type (dhandle
, info
, typenums
);
2828 if (class_type
== DEBUG_TYPE_NULL
)
2830 return_type
= debug_get_return_type (dhandle
, type
);
2831 if (return_type
== DEBUG_TYPE_NULL
)
2836 type
= parse_stab_argtypes (dhandle
, info
, class_type
, name
,
2837 tagname
, return_type
, argtypes
,
2838 constp
, volatilep
, &physname
);
2839 if (type
== DEBUG_TYPE_NULL
)
2843 if (cvars
+ 1 >= allocvars
)
2846 variants
= ((debug_method_variant
*)
2847 xrealloc ((PTR
) variants
,
2848 allocvars
* sizeof *variants
));
2852 variants
[cvars
] = debug_make_method_variant (dhandle
, physname
,
2857 variants
[cvars
] = debug_make_static_method_variant (dhandle
,
2863 if (variants
[cvars
] == DEBUG_METHOD_VARIANT_NULL
)
2868 while (**pp
!= ';' && **pp
!= '\0');
2870 variants
[cvars
] = DEBUG_METHOD_VARIANT_NULL
;
2878 methods
= ((debug_method
*)
2879 xrealloc ((PTR
) methods
, alloc
* sizeof *methods
));
2882 methods
[c
] = debug_make_method (dhandle
, name
, variants
);
2887 if (methods
!= NULL
)
2888 methods
[c
] = DEBUG_METHOD_NULL
;
2895 /* Parse a string representing argument types for a method. Stabs
2896 tries to save space by packing argument types into a mangled
2897 string. This string should give us enough information to extract
2898 both argument types and the physical name of the function, given
2902 parse_stab_argtypes (dhandle
, info
, class_type
, fieldname
, tagname
,
2903 return_type
, argtypes
, constp
, volatilep
, pphysname
)
2905 struct stab_handle
*info
;
2906 debug_type class_type
;
2907 const char *fieldname
;
2908 const char *tagname
;
2909 debug_type return_type
;
2910 const char *argtypes
;
2912 bfd_boolean volatilep
;
2913 const char **pphysname
;
2915 bfd_boolean is_full_physname_constructor
;
2916 bfd_boolean is_constructor
;
2917 bfd_boolean is_destructor
;
2919 bfd_boolean varargs
;
2920 unsigned int physname_len
= 0;
2922 /* Constructors are sometimes handled specially. */
2923 is_full_physname_constructor
= ((argtypes
[0] == '_'
2924 && argtypes
[1] == '_'
2925 && (ISDIGIT (argtypes
[2])
2926 || argtypes
[2] == 'Q'
2927 || argtypes
[2] == 't'))
2928 || strncmp (argtypes
, "__ct", 4) == 0);
2930 is_constructor
= (is_full_physname_constructor
2932 && strcmp (fieldname
, tagname
) == 0));
2933 is_destructor
= ((argtypes
[0] == '_'
2934 && (argtypes
[1] == '$' || argtypes
[1] == '.')
2935 && argtypes
[2] == '_')
2936 || strncmp (argtypes
, "__dt", 4) == 0);
2938 if (is_destructor
|| is_full_physname_constructor
)
2939 *pphysname
= argtypes
;
2943 const char *const_prefix
;
2944 const char *volatile_prefix
;
2946 unsigned int mangled_name_len
;
2949 len
= tagname
== NULL
? 0 : strlen (tagname
);
2950 const_prefix
= constp
? "C" : "";
2951 volatile_prefix
= volatilep
? "V" : "";
2954 sprintf (buf
, "__%s%s", const_prefix
, volatile_prefix
);
2955 else if (tagname
!= NULL
&& strchr (tagname
, '<') != NULL
)
2957 /* Template methods are fully mangled. */
2958 sprintf (buf
, "__%s%s", const_prefix
, volatile_prefix
);
2963 sprintf (buf
, "__%s%s%d", const_prefix
, volatile_prefix
, len
);
2965 mangled_name_len
= ((is_constructor
? 0 : strlen (fieldname
))
2971 if (fieldname
[0] == 'o'
2972 && fieldname
[1] == 'p'
2973 && (fieldname
[2] == '$' || fieldname
[2] == '.'))
2977 opname
= cplus_mangle_opname (fieldname
+ 3, 0);
2980 fprintf (stderr
, _("No mangling for \"%s\"\n"), fieldname
);
2981 return DEBUG_TYPE_NULL
;
2983 mangled_name_len
+= strlen (opname
);
2984 physname
= (char *) xmalloc (mangled_name_len
);
2985 strncpy (physname
, fieldname
, 3);
2986 strcpy (physname
+ 3, opname
);
2990 physname
= (char *) xmalloc (mangled_name_len
);
2994 strcpy (physname
, fieldname
);
2997 physname_len
= strlen (physname
);
2998 strcat (physname
, buf
);
2999 if (tagname
!= NULL
)
3000 strcat (physname
, tagname
);
3001 strcat (physname
, argtypes
);
3003 *pphysname
= physname
;
3006 if (*argtypes
== '\0' || is_destructor
)
3008 args
= (debug_type
*) xmalloc (sizeof *args
);
3010 return debug_make_method_type (dhandle
, return_type
, class_type
, args
,
3014 args
= stab_demangle_argtypes (dhandle
, info
, *pphysname
, &varargs
, physname_len
);
3016 return DEBUG_TYPE_NULL
;
3018 return debug_make_method_type (dhandle
, return_type
, class_type
, args
,
3022 /* The tail end of stabs for C++ classes that contain a virtual function
3023 pointer contains a tilde, a %, and a type number.
3024 The type number refers to the base class (possibly this class itself) which
3025 contains the vtable pointer for the current class.
3027 This function is called when we have parsed all the method declarations,
3028 so we can look for the vptr base class info. */
3031 parse_stab_tilde_field (dhandle
, info
, pp
, typenums
, retvptrbase
, retownvptr
)
3033 struct stab_handle
*info
;
3035 const int *typenums
;
3036 debug_type
*retvptrbase
;
3037 bfd_boolean
*retownvptr
;
3043 *retvptrbase
= DEBUG_TYPE_NULL
;
3044 *retownvptr
= FALSE
;
3048 /* If we are positioned at a ';', then skip it. */
3057 if (**pp
== '=' || **pp
== '+' || **pp
== '-')
3059 /* Obsolete flags that used to indicate the presence of
3060 constructors and/or destructors. */
3071 /* The next number is the type number of the base class (possibly
3072 our own class) which supplies the vtable for this class. */
3073 if (! parse_stab_type_number (pp
, vtypenums
))
3076 if (vtypenums
[0] == typenums
[0]
3077 && vtypenums
[1] == typenums
[1])
3086 vtype
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
3087 (debug_type
**) NULL
);
3088 for (p
= *pp
; *p
!= ';' && *p
!= '\0'; p
++)
3096 *retvptrbase
= vtype
;
3104 /* Read a definition of an array type. */
3107 parse_stab_array_type (dhandle
, info
, pp
, stringp
)
3109 struct stab_handle
*info
;
3111 bfd_boolean stringp
;
3116 debug_type index_type
;
3117 bfd_boolean adjustable
;
3118 bfd_signed_vma lower
, upper
;
3119 debug_type element_type
;
3121 /* Format of an array type:
3122 "ar<index type>;lower;upper;<array_contents_type>".
3123 OS9000: "arlower,upper;<array_contents_type>".
3125 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
3126 for these, produce a type like float[][]. */
3130 /* FIXME: gdb checks os9k_stabs here. */
3132 /* If the index type is type 0, we take it as int. */
3134 if (! parse_stab_type_number (&p
, typenums
))
3135 return DEBUG_TYPE_NULL
;
3136 if (typenums
[0] == 0 && typenums
[1] == 0 && **pp
!= '=')
3138 index_type
= debug_find_named_type (dhandle
, "int");
3139 if (index_type
== DEBUG_TYPE_NULL
)
3141 index_type
= debug_make_int_type (dhandle
, 4, FALSE
);
3142 if (index_type
== DEBUG_TYPE_NULL
)
3143 return DEBUG_TYPE_NULL
;
3149 index_type
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
3150 (debug_type
**) NULL
);
3156 return DEBUG_TYPE_NULL
;
3162 if (! ISDIGIT (**pp
) && **pp
!= '-')
3168 lower
= (bfd_signed_vma
) parse_number (pp
, (bfd_boolean
*) NULL
);
3172 return DEBUG_TYPE_NULL
;
3176 if (! ISDIGIT (**pp
) && **pp
!= '-')
3182 upper
= (bfd_signed_vma
) parse_number (pp
, (bfd_boolean
*) NULL
);
3186 return DEBUG_TYPE_NULL
;
3190 element_type
= parse_stab_type (dhandle
, info
, (const char *) NULL
, pp
,
3191 (debug_type
**) NULL
);
3192 if (element_type
== DEBUG_TYPE_NULL
)
3193 return DEBUG_TYPE_NULL
;
3201 return debug_make_array_type (dhandle
, element_type
, index_type
, lower
,
3205 /* This struct holds information about files we have seen using
3210 /* The next N_BINCL file. */
3211 struct bincl_file
*next
;
3212 /* The next N_BINCL on the stack. */
3213 struct bincl_file
*next_stack
;
3214 /* The file name. */
3216 /* The hash value. */
3218 /* The file index. */
3220 /* The list of types defined in this file. */
3221 struct stab_types
*file_types
;
3224 /* Start a new N_BINCL file, pushing it onto the stack. */
3227 push_bincl (info
, name
, hash
)
3228 struct stab_handle
*info
;
3232 struct bincl_file
*n
;
3234 n
= (struct bincl_file
*) xmalloc (sizeof *n
);
3235 n
->next
= info
->bincl_list
;
3236 n
->next_stack
= info
->bincl_stack
;
3239 n
->file
= info
->files
;
3240 n
->file_types
= NULL
;
3241 info
->bincl_list
= n
;
3242 info
->bincl_stack
= n
;
3245 info
->file_types
= ((struct stab_types
**)
3246 xrealloc ((PTR
) info
->file_types
,
3248 * sizeof *info
->file_types
)));
3249 info
->file_types
[n
->file
] = NULL
;
3252 /* Finish an N_BINCL file, at an N_EINCL, popping the name off the
3257 struct stab_handle
*info
;
3259 struct bincl_file
*o
;
3261 o
= info
->bincl_stack
;
3263 return info
->main_filename
;
3264 info
->bincl_stack
= o
->next_stack
;
3266 o
->file_types
= info
->file_types
[o
->file
];
3268 if (info
->bincl_stack
== NULL
)
3269 return info
->main_filename
;
3270 return info
->bincl_stack
->name
;
3273 /* Handle an N_EXCL: get the types from the corresponding N_BINCL. */
3276 find_excl (info
, name
, hash
)
3277 struct stab_handle
*info
;
3281 struct bincl_file
*l
;
3284 info
->file_types
= ((struct stab_types
**)
3285 xrealloc ((PTR
) info
->file_types
,
3287 * sizeof *info
->file_types
)));
3289 for (l
= info
->bincl_list
; l
!= NULL
; l
= l
->next
)
3290 if (l
->hash
== hash
&& strcmp (l
->name
, name
) == 0)
3294 warn_stab (name
, _("Undefined N_EXCL"));
3295 info
->file_types
[info
->files
- 1] = NULL
;
3299 info
->file_types
[info
->files
- 1] = l
->file_types
;
3304 /* Handle a variable definition. gcc emits variable definitions for a
3305 block before the N_LBRAC, so we must hold onto them until we see
3306 it. The SunPRO compiler emits variable definitions after the
3307 N_LBRAC, so we can call debug_record_variable immediately. */
3310 stab_record_variable (dhandle
, info
, name
, type
, kind
, val
)
3312 struct stab_handle
*info
;
3315 enum debug_var_kind kind
;
3318 struct stab_pending_var
*v
;
3320 if ((kind
== DEBUG_GLOBAL
|| kind
== DEBUG_STATIC
)
3321 || ! info
->within_function
3322 || (info
->gcc_compiled
== 0 && info
->n_opt_found
))
3323 return debug_record_variable (dhandle
, name
, type
, kind
, val
);
3325 v
= (struct stab_pending_var
*) xmalloc (sizeof *v
);
3326 memset (v
, 0, sizeof *v
);
3328 v
->next
= info
->pending
;
3338 /* Emit pending variable definitions. This is called after we see the
3339 N_LBRAC that starts the block. */
3342 stab_emit_pending_vars (dhandle
, info
)
3344 struct stab_handle
*info
;
3346 struct stab_pending_var
*v
;
3351 struct stab_pending_var
*next
;
3353 if (! debug_record_variable (dhandle
, v
->name
, v
->type
, v
->kind
, v
->val
))
3361 info
->pending
= NULL
;
3366 /* Find the slot for a type in the database. */
3369 stab_find_slot (info
, typenums
)
3370 struct stab_handle
*info
;
3371 const int *typenums
;
3375 struct stab_types
**ps
;
3377 filenum
= typenums
[0];
3378 index
= typenums
[1];
3380 if (filenum
< 0 || (unsigned int) filenum
>= info
->files
)
3382 fprintf (stderr
, _("Type file number %d out of range\n"), filenum
);
3387 fprintf (stderr
, _("Type index number %d out of range\n"), index
);
3391 ps
= info
->file_types
+ filenum
;
3393 while (index
>= STAB_TYPES_SLOTS
)
3397 *ps
= (struct stab_types
*) xmalloc (sizeof **ps
);
3398 memset (*ps
, 0, sizeof **ps
);
3401 index
-= STAB_TYPES_SLOTS
;
3405 *ps
= (struct stab_types
*) xmalloc (sizeof **ps
);
3406 memset (*ps
, 0, sizeof **ps
);
3409 return (*ps
)->types
+ index
;
3412 /* Find a type given a type number. If the type has not been
3413 allocated yet, create an indirect type. */
3416 stab_find_type (dhandle
, info
, typenums
)
3418 struct stab_handle
*info
;
3419 const int *typenums
;
3423 if (typenums
[0] == 0 && typenums
[1] < 0)
3425 /* A negative type number indicates an XCOFF builtin type. */
3426 return stab_xcoff_builtin_type (dhandle
, info
, typenums
[1]);
3429 slot
= stab_find_slot (info
, typenums
);
3431 return DEBUG_TYPE_NULL
;
3433 if (*slot
== DEBUG_TYPE_NULL
)
3434 return debug_make_indirect_type (dhandle
, slot
, (const char *) NULL
);
3439 /* Record that a given type number refers to a given type. */
3442 stab_record_type (dhandle
, info
, typenums
, type
)
3443 PTR dhandle ATTRIBUTE_UNUSED
;
3444 struct stab_handle
*info
;
3445 const int *typenums
;
3450 slot
= stab_find_slot (info
, typenums
);
3454 /* gdb appears to ignore type redefinitions, so we do as well. */
3461 /* Return an XCOFF builtin type. */
3464 stab_xcoff_builtin_type (dhandle
, info
, typenum
)
3466 struct stab_handle
*info
;
3472 if (typenum
>= 0 || typenum
< -XCOFF_TYPE_COUNT
)
3474 fprintf (stderr
, _("Unrecognized XCOFF type %d\n"), typenum
);
3475 return DEBUG_TYPE_NULL
;
3477 if (info
->xcoff_types
[-typenum
] != NULL
)
3478 return info
->xcoff_types
[-typenum
];
3483 /* The size of this and all the other types are fixed, defined
3484 by the debugging format. */
3486 rettype
= debug_make_int_type (dhandle
, 4, FALSE
);
3490 rettype
= debug_make_int_type (dhandle
, 1, FALSE
);
3494 rettype
= debug_make_int_type (dhandle
, 2, FALSE
);
3498 rettype
= debug_make_int_type (dhandle
, 4, FALSE
);
3501 name
= "unsigned char";
3502 rettype
= debug_make_int_type (dhandle
, 1, TRUE
);
3505 name
= "signed char";
3506 rettype
= debug_make_int_type (dhandle
, 1, FALSE
);
3509 name
= "unsigned short";
3510 rettype
= debug_make_int_type (dhandle
, 2, TRUE
);
3513 name
= "unsigned int";
3514 rettype
= debug_make_int_type (dhandle
, 4, TRUE
);
3518 rettype
= debug_make_int_type (dhandle
, 4, TRUE
);
3520 name
= "unsigned long";
3521 rettype
= debug_make_int_type (dhandle
, 4, TRUE
);
3525 rettype
= debug_make_void_type (dhandle
);
3528 /* IEEE single precision (32 bit). */
3530 rettype
= debug_make_float_type (dhandle
, 4);
3533 /* IEEE double precision (64 bit). */
3535 rettype
= debug_make_float_type (dhandle
, 8);
3538 /* This is an IEEE double on the RS/6000, and different machines
3539 with different sizes for "long double" should use different
3540 negative type numbers. See stabs.texinfo. */
3541 name
= "long double";
3542 rettype
= debug_make_float_type (dhandle
, 8);
3546 rettype
= debug_make_int_type (dhandle
, 4, FALSE
);
3550 rettype
= debug_make_bool_type (dhandle
, 4);
3553 name
= "short real";
3554 rettype
= debug_make_float_type (dhandle
, 4);
3558 rettype
= debug_make_float_type (dhandle
, 8);
3568 rettype
= debug_make_int_type (dhandle
, 1, TRUE
);
3572 rettype
= debug_make_bool_type (dhandle
, 1);
3576 rettype
= debug_make_bool_type (dhandle
, 2);
3580 rettype
= debug_make_bool_type (dhandle
, 4);
3584 rettype
= debug_make_bool_type (dhandle
, 4);
3587 /* Complex type consisting of two IEEE single precision values. */
3589 rettype
= debug_make_complex_type (dhandle
, 8);
3592 /* Complex type consisting of two IEEE double precision values. */
3593 name
= "double complex";
3594 rettype
= debug_make_complex_type (dhandle
, 16);
3598 rettype
= debug_make_int_type (dhandle
, 1, FALSE
);
3602 rettype
= debug_make_int_type (dhandle
, 2, FALSE
);
3606 rettype
= debug_make_int_type (dhandle
, 4, FALSE
);
3611 rettype
= debug_make_int_type (dhandle
, 2, FALSE
);
3615 rettype
= debug_make_int_type (dhandle
, 8, FALSE
);
3618 name
= "unsigned long long";
3619 rettype
= debug_make_int_type (dhandle
, 8, TRUE
);
3623 rettype
= debug_make_bool_type (dhandle
, 8);
3627 rettype
= debug_make_int_type (dhandle
, 8, FALSE
);
3633 rettype
= debug_name_type (dhandle
, name
, rettype
);
3635 info
->xcoff_types
[-typenum
] = rettype
;
3640 /* Find or create a tagged type. */
3643 stab_find_tagged_type (dhandle
, info
, p
, len
, kind
)
3645 struct stab_handle
*info
;
3648 enum debug_type_kind kind
;
3652 struct stab_tag
*st
;
3654 name
= savestring (p
, len
);
3656 /* We pass DEBUG_KIND_ILLEGAL because we want all tags in the same
3657 namespace. This is right for C, and I don't know how to handle
3658 other languages. FIXME. */
3659 dtype
= debug_find_tagged_type (dhandle
, name
, DEBUG_KIND_ILLEGAL
);
3660 if (dtype
!= DEBUG_TYPE_NULL
)
3666 /* We need to allocate an entry on the undefined tag list. */
3667 for (st
= info
->tags
; st
!= NULL
; st
= st
->next
)
3669 if (st
->name
[0] == name
[0]
3670 && strcmp (st
->name
, name
) == 0)
3672 if (st
->kind
== DEBUG_KIND_ILLEGAL
)
3680 st
= (struct stab_tag
*) xmalloc (sizeof *st
);
3681 memset (st
, 0, sizeof *st
);
3683 st
->next
= info
->tags
;
3686 st
->slot
= DEBUG_TYPE_NULL
;
3687 st
->type
= debug_make_indirect_type (dhandle
, &st
->slot
, name
);
3694 /* In order to get the correct argument types for a stubbed method, we
3695 need to extract the argument types from a C++ mangled string.
3696 Since the argument types can refer back to the return type, this
3697 means that we must demangle the entire physical name. In gdb this
3698 is done by calling cplus_demangle and running the results back
3699 through the C++ expression parser. Since we have no expression
3700 parser, we must duplicate much of the work of cplus_demangle here.
3702 We assume that GNU style demangling is used, since this is only
3703 done for method stubs, and only g++ should output that form of
3704 debugging information. */
3706 /* This structure is used to hold a pointer to type information which
3707 demangling a string. */
3709 struct stab_demangle_typestring
3711 /* The start of the type. This is not null terminated. */
3712 const char *typestring
;
3713 /* The length of the type. */
3717 /* This structure is used to hold information while demangling a
3720 struct stab_demangle_info
3722 /* The debugging information handle. */
3724 /* The stab information handle. */
3725 struct stab_handle
*info
;
3726 /* The array of arguments we are building. */
3728 /* Whether the method takes a variable number of arguments. */
3729 bfd_boolean varargs
;
3730 /* The array of types we have remembered. */
3731 struct stab_demangle_typestring
*typestrings
;
3732 /* The number of typestrings. */
3733 unsigned int typestring_count
;
3734 /* The number of typestring slots we have allocated. */
3735 unsigned int typestring_alloc
;
3738 static void stab_bad_demangle
3739 PARAMS ((const char *));
3740 static unsigned int stab_demangle_count
3741 PARAMS ((const char **));
3742 static bfd_boolean stab_demangle_get_count
3743 PARAMS ((const char **, unsigned int *));
3744 static bfd_boolean stab_demangle_prefix
3745 PARAMS ((struct stab_demangle_info
*, const char **, unsigned int));
3746 static bfd_boolean stab_demangle_function_name
3747 PARAMS ((struct stab_demangle_info
*, const char **, const char *));
3748 static bfd_boolean stab_demangle_signature
3749 PARAMS ((struct stab_demangle_info
*, const char **));
3750 static bfd_boolean stab_demangle_qualified
3751 PARAMS ((struct stab_demangle_info
*, const char **, debug_type
*));
3752 static bfd_boolean stab_demangle_template
3753 PARAMS ((struct stab_demangle_info
*, const char **, char **));
3754 static bfd_boolean stab_demangle_class
3755 PARAMS ((struct stab_demangle_info
*, const char **, const char **));
3756 static bfd_boolean stab_demangle_args
3757 PARAMS ((struct stab_demangle_info
*, const char **, debug_type
**,
3759 static bfd_boolean stab_demangle_arg
3760 PARAMS ((struct stab_demangle_info
*, const char **, debug_type
**,
3761 unsigned int *, unsigned int *));
3762 static bfd_boolean stab_demangle_type
3763 PARAMS ((struct stab_demangle_info
*, const char **, debug_type
*));
3764 static bfd_boolean stab_demangle_fund_type
3765 PARAMS ((struct stab_demangle_info
*, const char **, debug_type
*));
3766 static bfd_boolean stab_demangle_remember_type
3767 PARAMS ((struct stab_demangle_info
*, const char *, int));
3769 /* Warn about a bad demangling. */
3772 stab_bad_demangle (s
)
3775 fprintf (stderr
, _("bad mangled name `%s'\n"), s
);
3778 /* Get a count from a stab string. */
3781 stab_demangle_count (pp
)
3787 while (ISDIGIT (**pp
))
3790 count
+= **pp
- '0';
3796 /* Require a count in a string. The count may be multiple digits, in
3797 which case it must end in an underscore. */
3800 stab_demangle_get_count (pp
, pi
)
3804 if (! ISDIGIT (**pp
))
3822 while (ISDIGIT (*p
));
3833 /* This function demangles a physical name, returning a NULL
3834 terminated array of argument types. */
3837 stab_demangle_argtypes (dhandle
, info
, physname
, pvarargs
, physname_len
)
3839 struct stab_handle
*info
;
3840 const char *physname
;
3841 bfd_boolean
*pvarargs
;
3842 unsigned int physname_len
;
3844 struct stab_demangle_info minfo
;
3846 minfo
.dhandle
= dhandle
;
3849 minfo
.varargs
= FALSE
;
3850 minfo
.typestring_alloc
= 10;
3851 minfo
.typestrings
= ((struct stab_demangle_typestring
*)
3852 xmalloc (minfo
.typestring_alloc
3853 * sizeof *minfo
.typestrings
));
3854 minfo
.typestring_count
= 0;
3856 /* cplus_demangle checks for special GNU mangled forms, but we can't
3857 see any of them in mangled method argument types. */
3859 if (! stab_demangle_prefix (&minfo
, &physname
, physname_len
))
3862 if (*physname
!= '\0')
3864 if (! stab_demangle_signature (&minfo
, &physname
))
3868 free (minfo
.typestrings
);
3869 minfo
.typestrings
= NULL
;
3871 if (minfo
.args
== NULL
)
3872 fprintf (stderr
, _("no argument types in mangled string\n"));
3874 *pvarargs
= minfo
.varargs
;
3878 if (minfo
.typestrings
!= NULL
)
3879 free (minfo
.typestrings
);
3883 /* Demangle the prefix of the mangled name. */
3886 stab_demangle_prefix (minfo
, pp
, physname_len
)
3887 struct stab_demangle_info
*minfo
;
3889 unsigned int physname_len
;
3894 /* cplus_demangle checks for global constructors and destructors,
3895 but we can't see them in mangled argument types. */
3898 scan
= *pp
+ physname_len
;
3901 /* Look for `__'. */
3904 scan
= strchr (scan
, '_');
3905 while (scan
!= NULL
&& *++scan
!= '_');
3909 stab_bad_demangle (*pp
);
3915 /* We found `__'; move ahead to the last contiguous `__' pair. */
3916 i
= strspn (scan
, "_");
3922 && (ISDIGIT (scan
[2])
3926 /* This is a GNU style constructor name. */
3930 else if (scan
== *pp
3931 && ! ISDIGIT (scan
[2])
3934 /* Look for the `__' that separates the prefix from the
3936 while (*scan
== '_')
3938 scan
= strstr (scan
, "__");
3939 if (scan
== NULL
|| scan
[2] == '\0')
3941 stab_bad_demangle (*pp
);
3945 return stab_demangle_function_name (minfo
, pp
, scan
);
3947 else if (scan
[2] != '\0')
3949 /* The name doesn't start with `__', but it does contain `__'. */
3950 return stab_demangle_function_name (minfo
, pp
, scan
);
3954 stab_bad_demangle (*pp
);
3960 /* Demangle a function name prefix. The scan argument points to the
3961 double underscore which separates the function name from the
3965 stab_demangle_function_name (minfo
, pp
, scan
)
3966 struct stab_demangle_info
*minfo
;
3972 /* The string from *pp to scan is the name of the function. We
3973 don't care about the name, since we just looking for argument
3974 types. However, for conversion operators, the name may include a
3975 type which we must remember in order to handle backreferences. */
3981 && strncmp (name
, "type", 4) == 0
3982 && (name
[4] == '$' || name
[4] == '.'))
3986 /* This is a type conversion operator. */
3988 if (! stab_demangle_type (minfo
, &tem
, (debug_type
*) NULL
))
3991 else if (name
[0] == '_'
3998 /* This is a type conversion operator. */
4000 if (! stab_demangle_type (minfo
, &tem
, (debug_type
*) NULL
))
4007 /* Demangle the signature. This is where the argument types are
4011 stab_demangle_signature (minfo
, pp
)
4012 struct stab_demangle_info
*minfo
;
4016 bfd_boolean expect_func
, func_done
;
4021 expect_func
= FALSE
;
4025 while (**pp
!= '\0')
4031 if (! stab_demangle_qualified (minfo
, pp
, (debug_type
*) NULL
)
4032 || ! stab_demangle_remember_type (minfo
, hold
, *pp
- hold
))
4039 /* Static member function. FIXME: Can this happen? */
4046 /* Const member function. */
4052 case '0': case '1': case '2': case '3': case '4':
4053 case '5': case '6': case '7': case '8': case '9':
4056 if (! stab_demangle_class (minfo
, pp
, (const char **) NULL
)
4057 || ! stab_demangle_remember_type (minfo
, hold
, *pp
- hold
))
4064 /* Function. I don't know if this actually happens with g++
4069 if (! stab_demangle_args (minfo
, pp
, &minfo
->args
, &minfo
->varargs
))
4077 if (! stab_demangle_template (minfo
, pp
, (char **) NULL
)
4078 || ! stab_demangle_remember_type (minfo
, hold
, *pp
- hold
))
4085 /* At the outermost level, we cannot have a return type
4086 specified, so if we run into another '_' at this point we
4087 are dealing with a mangled name that is either bogus, or
4088 has been mangled by some algorithm we don't know how to
4089 deal with. So just reject the entire demangling. */
4090 stab_bad_demangle (orig
);
4094 /* Assume we have stumbled onto the first outermost function
4095 argument token, and start processing args. */
4097 if (! stab_demangle_args (minfo
, pp
, &minfo
->args
, &minfo
->varargs
))
4105 if (! stab_demangle_args (minfo
, pp
, &minfo
->args
, &minfo
->varargs
))
4112 /* With GNU style demangling, bar__3foo is 'foo::bar(void)', and
4113 bar__3fooi is 'foo::bar(int)'. We get here when we find the
4114 first case, and need to ensure that the '(void)' gets added
4115 to the current declp. */
4116 if (! stab_demangle_args (minfo
, pp
, &minfo
->args
, &minfo
->varargs
))
4123 /* Demangle a qualified name, such as "Q25Outer5Inner" which is the
4124 mangled form of "Outer::Inner". */
4127 stab_demangle_qualified (minfo
, pp
, ptype
)
4128 struct stab_demangle_info
*minfo
;
4134 unsigned int qualifiers
;
4142 /* GNU mangled name with more than 9 classes. The count is
4143 preceded by an underscore (to distinguish it from the <= 9
4144 case) and followed by an underscore. */
4146 if (! ISDIGIT (*p
) || *p
== '0')
4148 stab_bad_demangle (orig
);
4151 qualifiers
= atoi (p
);
4152 while (ISDIGIT (*p
))
4156 stab_bad_demangle (orig
);
4162 case '1': case '2': case '3': case '4': case '5':
4163 case '6': case '7': case '8': case '9':
4164 qualifiers
= (*pp
)[1] - '0';
4165 /* Skip an optional underscore after the count. */
4166 if ((*pp
)[2] == '_')
4173 stab_bad_demangle (orig
);
4177 context
= DEBUG_TYPE_NULL
;
4179 /* Pick off the names. */
4180 while (qualifiers
-- > 0)
4188 if (! stab_demangle_template (minfo
, pp
,
4189 ptype
!= NULL
? &name
: NULL
))
4194 context
= stab_find_tagged_type (minfo
->dhandle
, minfo
->info
,
4195 name
, strlen (name
),
4198 if (context
== DEBUG_TYPE_NULL
)
4206 len
= stab_demangle_count (pp
);
4207 if (strlen (*pp
) < len
)
4209 stab_bad_demangle (orig
);
4215 const debug_field
*fields
;
4218 if (context
!= DEBUG_TYPE_NULL
)
4219 fields
= debug_get_fields (minfo
->dhandle
, context
);
4221 context
= DEBUG_TYPE_NULL
;
4227 /* Try to find the type by looking through the
4228 fields of context until we find a field with the
4229 same type. This ought to work for a class
4230 defined within a class, but it won't work for,
4231 e.g., an enum defined within a class. stabs does
4232 not give us enough information to figure out the
4235 name
= savestring (*pp
, len
);
4237 for (; *fields
!= DEBUG_FIELD_NULL
; fields
++)
4242 ft
= debug_get_field_type (minfo
->dhandle
, *fields
);
4245 dn
= debug_get_type_name (minfo
->dhandle
, ft
);
4246 if (dn
!= NULL
&& strcmp (dn
, name
) == 0)
4256 if (context
== DEBUG_TYPE_NULL
)
4258 /* We have to fall back on finding the type by name.
4259 If there are more types to come, then this must
4260 be a class. Otherwise, it could be anything. */
4262 if (qualifiers
== 0)
4266 name
= savestring (*pp
, len
);
4267 context
= debug_find_named_type (minfo
->dhandle
,
4272 if (context
== DEBUG_TYPE_NULL
)
4274 context
= stab_find_tagged_type (minfo
->dhandle
,
4278 ? DEBUG_KIND_ILLEGAL
4279 : DEBUG_KIND_CLASS
));
4280 if (context
== DEBUG_TYPE_NULL
)
4296 /* Demangle a template. If PNAME is not NULL, this sets *PNAME to a
4297 string representation of the template. */
4300 stab_demangle_template (minfo
, pp
, pname
)
4301 struct stab_demangle_info
*minfo
;
4312 /* Skip the template name. */
4313 r
= stab_demangle_count (pp
);
4314 if (r
== 0 || strlen (*pp
) < r
)
4316 stab_bad_demangle (orig
);
4321 /* Get the size of the parameter list. */
4322 if (stab_demangle_get_count (pp
, &r
) == 0)
4324 stab_bad_demangle (orig
);
4328 for (i
= 0; i
< r
; i
++)
4332 /* This is a type parameter. */
4334 if (! stab_demangle_type (minfo
, pp
, (debug_type
*) NULL
))
4340 bfd_boolean pointerp
, realp
, integralp
, charp
, boolp
;
4351 /* This is a value parameter. */
4353 if (! stab_demangle_type (minfo
, pp
, (debug_type
*) NULL
))
4356 while (*old_p
!= '\0' && ! done
)
4366 case 'C': /* Const. */
4367 case 'S': /* Signed. */
4368 case 'U': /* Unsigned. */
4369 case 'V': /* Volatile. */
4370 case 'F': /* Function. */
4371 case 'M': /* Member function. */
4375 case 'Q': /* Qualified name. */
4379 case 'T': /* Remembered type. */
4381 case 'v': /* Void. */
4383 case 'x': /* Long long. */
4384 case 'l': /* Long. */
4385 case 'i': /* Int. */
4386 case 's': /* Short. */
4387 case 'w': /* Wchar_t. */
4391 case 'b': /* Bool. */
4395 case 'c': /* Char. */
4399 case 'r': /* Long double. */
4400 case 'd': /* Double. */
4401 case 'f': /* Float. */
4406 /* Assume it's a user defined integral type. */
4417 while (ISDIGIT (**pp
))
4426 val
= stab_demangle_count (pp
);
4429 stab_bad_demangle (orig
);
4437 val
= stab_demangle_count (pp
);
4438 if (val
!= 0 && val
!= 1)
4440 stab_bad_demangle (orig
);
4448 while (ISDIGIT (**pp
))
4453 while (ISDIGIT (**pp
))
4459 while (ISDIGIT (**pp
))
4467 if (! stab_demangle_get_count (pp
, &len
))
4469 stab_bad_demangle (orig
);
4477 /* We can translate this to a string fairly easily by invoking the
4478 regular demangling routine. */
4481 char *s1
, *s2
, *s3
, *s4
= NULL
;
4484 s1
= savestring (orig
, *pp
- orig
);
4486 s2
= concat ("NoSuchStrinG__", s1
, (const char *) NULL
);
4490 s3
= cplus_demangle (s2
, DMGL_ANSI
);
4495 s4
= strstr (s3
, "::NoSuchStrinG");
4496 if (s3
== NULL
|| s4
== NULL
)
4498 stab_bad_demangle (orig
);
4504 /* Eliminating all spaces, except those between > characters,
4505 makes it more likely that the demangled name will match the
4506 name which g++ used as the structure name. */
4507 for (from
= to
= s3
; from
!= s4
; ++from
)
4509 || (from
[1] == '>' && from
> s3
&& from
[-1] == '>'))
4512 *pname
= savestring (s3
, to
- s3
);
4520 /* Demangle a class name. */
4523 stab_demangle_class (minfo
, pp
, pstart
)
4524 struct stab_demangle_info
*minfo ATTRIBUTE_UNUSED
;
4526 const char **pstart
;
4533 n
= stab_demangle_count (pp
);
4534 if (strlen (*pp
) < n
)
4536 stab_bad_demangle (orig
);
4548 /* Demangle function arguments. If the pargs argument is not NULL, it
4549 is set to a NULL terminated array holding the arguments. */
4552 stab_demangle_args (minfo
, pp
, pargs
, pvarargs
)
4553 struct stab_demangle_info
*minfo
;
4556 bfd_boolean
*pvarargs
;
4559 unsigned int alloc
, count
;
4566 *pargs
= (debug_type
*) xmalloc (alloc
* sizeof **pargs
);
4571 while (**pp
!= '_' && **pp
!= '\0' && **pp
!= 'e')
4573 if (**pp
== 'N' || **pp
== 'T')
4581 if (temptype
== 'T')
4585 if (! stab_demangle_get_count (pp
, &r
))
4587 stab_bad_demangle (orig
);
4592 if (! stab_demangle_get_count (pp
, &t
))
4594 stab_bad_demangle (orig
);
4598 if (t
>= minfo
->typestring_count
)
4600 stab_bad_demangle (orig
);
4607 tem
= minfo
->typestrings
[t
].typestring
;
4608 if (! stab_demangle_arg (minfo
, &tem
, pargs
, &count
, &alloc
))
4614 if (! stab_demangle_arg (minfo
, pp
, pargs
, &count
, &alloc
))
4620 (*pargs
)[count
] = DEBUG_TYPE_NULL
;
4632 /* Demangle a single argument. */
4635 stab_demangle_arg (minfo
, pp
, pargs
, pcount
, palloc
)
4636 struct stab_demangle_info
*minfo
;
4639 unsigned int *pcount
;
4640 unsigned int *palloc
;
4646 if (! stab_demangle_type (minfo
, pp
,
4647 pargs
== NULL
? (debug_type
*) NULL
: &type
)
4648 || ! stab_demangle_remember_type (minfo
, start
, *pp
- start
))
4653 if (type
== DEBUG_TYPE_NULL
)
4656 if (*pcount
+ 1 >= *palloc
)
4659 *pargs
= ((debug_type
*)
4660 xrealloc (*pargs
, *palloc
* sizeof **pargs
));
4662 (*pargs
)[*pcount
] = type
;
4669 /* Demangle a type. If the ptype argument is not NULL, *ptype is set
4670 to the newly allocated type. */
4673 stab_demangle_type (minfo
, pp
, ptype
)
4674 struct stab_demangle_info
*minfo
;
4686 /* A pointer type. */
4688 if (! stab_demangle_type (minfo
, pp
, ptype
))
4691 *ptype
= debug_make_pointer_type (minfo
->dhandle
, *ptype
);
4695 /* A reference type. */
4697 if (! stab_demangle_type (minfo
, pp
, ptype
))
4700 *ptype
= debug_make_reference_type (minfo
->dhandle
, *ptype
);
4710 while (**pp
!= '\0' && **pp
!= '_')
4712 if (! ISDIGIT (**pp
))
4714 stab_bad_demangle (orig
);
4723 stab_bad_demangle (orig
);
4728 if (! stab_demangle_type (minfo
, pp
, ptype
))
4732 debug_type int_type
;
4734 int_type
= debug_find_named_type (minfo
->dhandle
, "int");
4735 if (int_type
== NULL
)
4736 int_type
= debug_make_int_type (minfo
->dhandle
, 4, FALSE
);
4737 *ptype
= debug_make_array_type (minfo
->dhandle
, *ptype
, int_type
,
4744 /* A back reference to a remembered type. */
4750 if (! stab_demangle_get_count (pp
, &i
))
4752 stab_bad_demangle (orig
);
4755 if (i
>= minfo
->typestring_count
)
4757 stab_bad_demangle (orig
);
4760 p
= minfo
->typestrings
[i
].typestring
;
4761 if (! stab_demangle_type (minfo
, &p
, ptype
))
4770 bfd_boolean varargs
;
4773 if (! stab_demangle_args (minfo
, pp
,
4775 ? (debug_type
**) NULL
4778 ? (bfd_boolean
*) NULL
4783 /* cplus_demangle will accept a function without a return
4784 type, but I don't know when that will happen, or what
4785 to do if it does. */
4786 stab_bad_demangle (orig
);
4790 if (! stab_demangle_type (minfo
, pp
, ptype
))
4793 *ptype
= debug_make_function_type (minfo
->dhandle
, *ptype
, args
,
4802 bfd_boolean memberp
, constp
, volatilep
;
4803 debug_type class_type
= DEBUG_TYPE_NULL
;
4805 bfd_boolean varargs
;
4809 memberp
= **pp
== 'M';
4818 n
= stab_demangle_count (pp
);
4819 if (strlen (*pp
) < n
)
4821 stab_bad_demangle (orig
);
4829 class_type
= stab_find_tagged_type (minfo
->dhandle
,
4833 if (class_type
== DEBUG_TYPE_NULL
)
4837 else if (**pp
== 'Q')
4839 if (! stab_demangle_qualified (minfo
, pp
,
4841 ? (debug_type
*) NULL
4847 stab_bad_demangle (orig
);
4858 else if (**pp
== 'V')
4865 stab_bad_demangle (orig
);
4869 if (! stab_demangle_args (minfo
, pp
,
4871 ? (debug_type
**) NULL
4874 ? (bfd_boolean
*) NULL
4881 stab_bad_demangle (orig
);
4886 if (! stab_demangle_type (minfo
, pp
, ptype
))
4892 *ptype
= debug_make_offset_type (minfo
->dhandle
, class_type
,
4896 /* FIXME: We have no way to record constp or
4898 *ptype
= debug_make_method_type (minfo
->dhandle
, *ptype
,
4899 class_type
, args
, varargs
);
4907 if (! stab_demangle_type (minfo
, pp
, ptype
))
4913 if (! stab_demangle_type (minfo
, pp
, ptype
))
4916 *ptype
= debug_make_const_type (minfo
->dhandle
, *ptype
);
4924 if (! stab_demangle_qualified (minfo
, pp
, ptype
))
4930 if (! stab_demangle_fund_type (minfo
, pp
, ptype
))
4938 /* Demangle a fundamental type. If the ptype argument is not NULL,
4939 *ptype is set to the newly allocated type. */
4942 stab_demangle_fund_type (minfo
, pp
, ptype
)
4943 struct stab_demangle_info
*minfo
;
4948 bfd_boolean constp
, volatilep
, unsignedp
, signedp
;
4993 /* cplus_demangle permits this, but I don't know what it means. */
4994 stab_bad_demangle (orig
);
4997 case 'v': /* void */
5000 *ptype
= debug_find_named_type (minfo
->dhandle
, "void");
5001 if (*ptype
== DEBUG_TYPE_NULL
)
5002 *ptype
= debug_make_void_type (minfo
->dhandle
);
5007 case 'x': /* long long */
5010 *ptype
= debug_find_named_type (minfo
->dhandle
,
5012 ? "long long unsigned int"
5013 : "long long int"));
5014 if (*ptype
== DEBUG_TYPE_NULL
)
5015 *ptype
= debug_make_int_type (minfo
->dhandle
, 8, unsignedp
);
5020 case 'l': /* long */
5023 *ptype
= debug_find_named_type (minfo
->dhandle
,
5025 ? "long unsigned int"
5027 if (*ptype
== DEBUG_TYPE_NULL
)
5028 *ptype
= debug_make_int_type (minfo
->dhandle
, 4, unsignedp
);
5036 *ptype
= debug_find_named_type (minfo
->dhandle
,
5040 if (*ptype
== DEBUG_TYPE_NULL
)
5041 *ptype
= debug_make_int_type (minfo
->dhandle
, 4, unsignedp
);
5046 case 's': /* short */
5049 *ptype
= debug_find_named_type (minfo
->dhandle
,
5051 ? "short unsigned int"
5053 if (*ptype
== DEBUG_TYPE_NULL
)
5054 *ptype
= debug_make_int_type (minfo
->dhandle
, 2, unsignedp
);
5059 case 'b': /* bool */
5062 *ptype
= debug_find_named_type (minfo
->dhandle
, "bool");
5063 if (*ptype
== DEBUG_TYPE_NULL
)
5064 *ptype
= debug_make_bool_type (minfo
->dhandle
, 4);
5069 case 'c': /* char */
5072 *ptype
= debug_find_named_type (minfo
->dhandle
,
5078 if (*ptype
== DEBUG_TYPE_NULL
)
5079 *ptype
= debug_make_int_type (minfo
->dhandle
, 1, unsignedp
);
5084 case 'w': /* wchar_t */
5087 *ptype
= debug_find_named_type (minfo
->dhandle
, "__wchar_t");
5088 if (*ptype
== DEBUG_TYPE_NULL
)
5089 *ptype
= debug_make_int_type (minfo
->dhandle
, 2, TRUE
);
5094 case 'r': /* long double */
5097 *ptype
= debug_find_named_type (minfo
->dhandle
, "long double");
5098 if (*ptype
== DEBUG_TYPE_NULL
)
5099 *ptype
= debug_make_float_type (minfo
->dhandle
, 8);
5104 case 'd': /* double */
5107 *ptype
= debug_find_named_type (minfo
->dhandle
, "double");
5108 if (*ptype
== DEBUG_TYPE_NULL
)
5109 *ptype
= debug_make_float_type (minfo
->dhandle
, 8);
5114 case 'f': /* float */
5117 *ptype
= debug_find_named_type (minfo
->dhandle
, "float");
5118 if (*ptype
== DEBUG_TYPE_NULL
)
5119 *ptype
= debug_make_float_type (minfo
->dhandle
, 4);
5126 if (! ISDIGIT (**pp
))
5128 stab_bad_demangle (orig
);
5132 case '0': case '1': case '2': case '3': case '4':
5133 case '5': case '6': case '7': case '8': case '9':
5137 if (! stab_demangle_class (minfo
, pp
, &hold
))
5143 name
= savestring (hold
, *pp
- hold
);
5144 *ptype
= debug_find_named_type (minfo
->dhandle
, name
);
5146 if (*ptype
== DEBUG_TYPE_NULL
)
5148 /* FIXME: It is probably incorrect to assume that
5149 undefined types are tagged types. */
5150 *ptype
= stab_find_tagged_type (minfo
->dhandle
, minfo
->info
,
5152 DEBUG_KIND_ILLEGAL
);
5153 if (*ptype
== DEBUG_TYPE_NULL
)
5164 if (! stab_demangle_template (minfo
, pp
,
5165 ptype
!= NULL
? &name
: NULL
))
5169 *ptype
= stab_find_tagged_type (minfo
->dhandle
, minfo
->info
,
5170 name
, strlen (name
),
5173 if (*ptype
== DEBUG_TYPE_NULL
)
5180 stab_bad_demangle (orig
);
5187 *ptype
= debug_make_const_type (minfo
->dhandle
, *ptype
);
5189 *ptype
= debug_make_volatile_type (minfo
->dhandle
, *ptype
);
5195 /* Remember a type string in a demangled string. */
5198 stab_demangle_remember_type (minfo
, p
, len
)
5199 struct stab_demangle_info
*minfo
;
5203 if (minfo
->typestring_count
>= minfo
->typestring_alloc
)
5205 minfo
->typestring_alloc
+= 10;
5206 minfo
->typestrings
= ((struct stab_demangle_typestring
*)
5207 xrealloc (minfo
->typestrings
,
5208 (minfo
->typestring_alloc
5209 * sizeof *minfo
->typestrings
)));
5212 minfo
->typestrings
[minfo
->typestring_count
].typestring
= p
;
5213 minfo
->typestrings
[minfo
->typestring_count
].len
= (unsigned int) len
;
5214 ++minfo
->typestring_count
;