1 /* stabs.c -- Parse stabs debugging information
2 Copyright (C) 1995 Free Software Foundation, Inc.
3 Written by Ian Lance Taylor <ian@cygnus.com>.
5 This file is part of GNU Binutils.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22 /* This file contains code which parses stabs debugging information.
23 The organization of this code is based on the gdb stabs reading
24 code. The job it does is somewhat different, because it is not
25 trying to identify the correct address for anything. */
32 #include "libiberty.h"
36 /* Meaningless definition needs by aout64.h. FIXME. */
37 #define BYTES_IN_WORD 4
39 #include "aout/aout64.h"
40 #include "aout/stab_gnu.h"
42 /* The number of predefined XCOFF types. */
44 #define XCOFF_TYPE_COUNT 34
46 /* This structure is used as a handle so that the stab parsing doesn't
47 need to use any static variables. */
51 /* The type of the last stab symbol, so that we can detect N_SO
54 /* The offset of the start of the function, so that we can handle
55 function relative N_RBRAC symbols. */
56 bfd_vma function_start_offset
;
57 /* The version number of gcc which compiled the current compilation
58 unit, 0 if not compiled by gcc. */
60 /* Whether an N_OPT symbol was seen that was not generated by gcc,
61 so that we can detect the SunPRO compiler. */
63 /* The main file name. */
65 /* A stack of N_BINCL files. */
66 struct bincl_file
*bincl_stack
;
67 /* Whether we are inside a function or not. */
68 boolean within_function
;
69 /* The depth of block nesting. */
71 /* List of pending variable definitions. */
72 struct stab_pending_var
*pending
;
73 /* Number of files for which we have types. */
75 /* Lists of types per file. */
76 struct stab_types
**file_types
;
77 /* Predefined XCOFF types. */
78 debug_type xcoff_types
[XCOFF_TYPE_COUNT
];
80 struct stab_tag
*tags
;
83 /* A list of these structures is used to hold pending variable
84 definitions seen before the N_LBRAC of a block. */
86 struct stab_pending_var
88 /* Next pending variable definition. */
89 struct stab_pending_var
*next
;
95 enum debug_var_kind kind
;
100 /* A list of these structures is used to hold the types for a single
105 /* Next set of slots for this file. */
106 struct stab_types
*next
;
107 /* Types indexed by type number. */
108 #define STAB_TYPES_SLOTS (16)
109 debug_type types
[STAB_TYPES_SLOTS
];
112 /* We keep a list of undefined tags that we encounter, so that we can
113 fill them in if the tag is later defined. */
117 /* Next undefined tag. */
118 struct stab_tag
*next
;
122 enum debug_type_kind kind
;
123 /* Slot to hold real type when we discover it. If we don't, we fill
124 in an undefined tag type. */
126 /* Indirect type we have created to point at slot. */
130 static char *savestring
PARAMS ((const char *, int));
131 static bfd_vma parse_number
PARAMS ((const char **, boolean
*));
132 static void bad_stab
PARAMS ((const char *));
133 static void warn_stab
PARAMS ((const char *, const char *));
134 static boolean parse_stab_string
135 PARAMS ((PTR
, struct stab_handle
*, int, int, bfd_vma
, const char *));
136 static debug_type parse_stab_type
137 PARAMS ((PTR
, struct stab_handle
*, const char **, debug_type
**));
138 static boolean parse_stab_type_number
139 PARAMS ((const char **, int *));
140 static debug_type parse_stab_range_type
141 PARAMS ((PTR
, struct stab_handle
*, const char **, const int *));
142 static debug_type parse_stab_sun_builtin_type
PARAMS ((PTR
, const char **));
143 static debug_type parse_stab_sun_floating_type
144 PARAMS ((PTR
, const char **));
145 static debug_type parse_stab_enum_type
PARAMS ((PTR
, const char **));
146 static debug_type parse_stab_struct_type
147 PARAMS ((PTR
, struct stab_handle
*, const char **, boolean
, const int *));
148 static boolean parse_stab_baseclasses
149 PARAMS ((PTR
, struct stab_handle
*, const char **, debug_baseclass
**));
150 static boolean parse_stab_struct_fields
151 PARAMS ((PTR
, struct stab_handle
*, const char **, debug_field
**,
153 static boolean parse_stab_cpp_abbrev
154 PARAMS ((PTR
, struct stab_handle
*, const char **, debug_field
*));
155 static boolean parse_stab_one_struct_field
156 PARAMS ((PTR
, struct stab_handle
*, const char **, const char *,
157 debug_field
*, boolean
*));
158 static boolean parse_stab_members
159 PARAMS ((PTR
, struct stab_handle
*, const char **, debug_method
**));
160 static boolean parse_stab_tilde_field
161 PARAMS ((PTR
, struct stab_handle
*, const char **, const int *,
162 debug_type
*, boolean
*));
163 static debug_type parse_stab_array_type
164 PARAMS ((PTR
, struct stab_handle
*, const char **, boolean
));
165 static void push_bincl
PARAMS ((struct stab_handle
*, const char *));
166 static const char *pop_bincl
PARAMS ((struct stab_handle
*));
167 static boolean stab_record_variable
168 PARAMS ((PTR
, struct stab_handle
*, const char *, debug_type
,
169 enum debug_var_kind
, bfd_vma
));
170 static boolean stab_emit_pending_vars
PARAMS ((PTR
, struct stab_handle
*));
171 static debug_type
*stab_find_slot
172 PARAMS ((struct stab_handle
*, const int *));
173 static debug_type stab_find_type
174 PARAMS ((PTR
, struct stab_handle
*, const int *));
175 static boolean stab_record_type
176 PARAMS ((PTR
, struct stab_handle
*, const int *, debug_type
));
177 static debug_type stab_xcoff_builtin_type
178 PARAMS ((PTR
, struct stab_handle
*, int));
180 /* Save a string in memory. */
183 savestring (start
, len
)
189 ret
= (char *) xmalloc (len
+ 1);
190 memcpy (ret
, start
, len
);
195 /* Read a number from a string. */
198 parse_number (pp
, poverflow
)
205 if (poverflow
!= NULL
)
211 ul
= strtoul (*pp
, (char **) pp
, 0);
212 if (ul
+ 1 != 0 || errno
== 0)
215 /* Note that even though strtoul overflowed, it should have set *pp
216 to the end of the number, which is where we want it. */
218 if (sizeof (bfd_vma
) > sizeof (unsigned long))
223 bfd_vma over
, lastdig
;
227 /* Our own version of strtoul, for a bfd_vma. */
243 if (p
[1] == 'x' || p
[1] == 'X')
255 over
= ((bfd_vma
) (bfd_signed_vma
) -1) / (bfd_vma
) base
;
256 lastdig
= ((bfd_vma
) (bfd_signed_vma
) -1) % (bfd_vma
) base
;
265 if (isdigit ((unsigned char) d
))
267 else if (isupper ((unsigned char) d
))
269 else if (islower ((unsigned char) d
))
277 if (v
> over
|| (v
== over
&& (bfd_vma
) d
> lastdig
))
292 /* If we get here, the number is too large to represent in a
295 if (poverflow
!= NULL
)
298 warn_stab (orig
, "numeric overflow");
303 /* Give an error for a bad stab string. */
309 fprintf (stderr
, "Bad stab: %s\n", p
);
312 /* Warn about something in a stab string. */
319 fprintf (stderr
, "Warning: %s: %s\n", err
, p
);
322 /* Create a handle to parse stabs symbols with. */
329 struct stab_handle
*ret
;
331 ret
= (struct stab_handle
*) xmalloc (sizeof *ret
);
332 memset (ret
, 0, sizeof *ret
);
334 ret
->file_types
= (struct stab_types
**) xmalloc (sizeof *ret
->file_types
);
335 ret
->file_types
[0] = NULL
;
339 /* When we have processed all the stabs information, we need to go
340 through and fill in all the undefined tags. */
343 finish_stab (dhandle
, handle
)
347 struct stab_handle
*info
= (struct stab_handle
*) handle
;
350 if (info
->within_function
)
352 if (! debug_end_function (dhandle
, (bfd_vma
) -1))
354 info
->within_function
= false;
357 for (st
= info
->tags
; st
!= NULL
; st
= st
->next
)
359 st
->slot
= debug_make_undefined_tagged_type (dhandle
, st
->name
,
361 if (st
->slot
== DEBUG_TYPE_NULL
)
368 /* Handle a single stabs symbol. */
371 parse_stab (dhandle
, handle
, type
, desc
, value
, string
)
379 struct stab_handle
*info
= (struct stab_handle
*) handle
;
388 /* Ignore extra outermost context from SunPRO cc and acc. */
389 if (info
->n_opt_found
&& desc
== 1)
392 if (! info
->within_function
)
394 fprintf (stderr
, "N_LBRAC not within function\n");
398 /* Start an inner lexical block. */
399 if (! debug_start_block (dhandle
, value
+ info
->function_start_offset
))
402 /* Emit any pending variable definitions. */
403 if (! stab_emit_pending_vars (dhandle
, info
))
410 /* Ignore extra outermost context from SunPRO cc and acc. */
411 if (info
->n_opt_found
&& desc
== 1)
414 /* We shouldn't have any pending variable definitions here, but,
415 if we do, we probably need to emit them before closing the
417 if (! stab_emit_pending_vars (dhandle
, info
))
420 /* End an inner lexical block. */
421 if (! debug_end_block (dhandle
, value
+ info
->function_start_offset
))
425 if (info
->block_depth
== 0)
427 info
->within_function
= false;
428 if (! debug_end_function (dhandle
,
429 value
+ info
->function_start_offset
))
435 /* Start a file. If we get two in a row, the first is the
436 directory name. An empty string is emitted by gcc at the end
437 of a compilation unit. */
440 if (info
->within_function
)
442 if (! debug_end_function (dhandle
, (bfd_vma
) -1))
444 info
->within_function
= false;
448 info
->gcc_compiled
= 0;
449 info
->n_opt_found
= false;
450 if (info
->last_type
== N_SO
)
454 if (! debug_append_filename (dhandle
, string
))
456 o
= info
->main_filename
;
457 info
->main_filename
= concat (o
, string
, (const char *) NULL
);
462 if (! debug_set_filename (dhandle
, string
))
464 if (info
->main_filename
!= NULL
)
465 free (info
->main_filename
);
466 info
->main_filename
= xstrdup (string
);
468 /* We need to reset the mapping from type numbers to types.
469 We 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
;
479 /* Start an include file. */
480 if (! debug_start_source (dhandle
, string
))
485 /* Start an include file which may be replaced. */
486 push_bincl (info
, string
);
487 if (! debug_start_source (dhandle
, string
))
492 /* End an N_BINCL include. */
493 if (! debug_start_source (dhandle
, pop_bincl (info
)))
498 /* This is a duplicate of a header file named by N_BINCL which
499 was eliminated by the linker. */
501 info
->file_types
= ((struct stab_types
**)
502 xrealloc ((PTR
) info
->file_types
,
504 * sizeof *info
->file_types
)));
505 info
->file_types
[info
->files
- 1] = NULL
;
509 if (! debug_record_line (dhandle
, desc
,
510 value
+ info
->function_start_offset
))
515 if (! debug_start_common_block (dhandle
, string
))
520 if (! debug_end_common_block (dhandle
, string
))
524 /* FIXME: gdb checks the string for N_STSYM, N_LCSYM or N_ROSYM
525 symbols, and if it does not start with :S, gdb relocates the
526 value to the start of the section. gcc always seems to use
527 :S, so we don't worry about this. */
532 colon
= strchr (string
, ':');
534 && (colon
[1] == 'f' || colon
[1] == 'F'))
536 if (info
->within_function
)
538 if (! debug_end_function (dhandle
, (bfd_vma
) -1))
541 info
->function_start_offset
= value
;
542 info
->within_function
= true;
545 if (! parse_stab_string (dhandle
, info
, type
, desc
, value
, string
))
551 if (string
!= NULL
&& strcmp (string
, "gcc2_compiled.") == 0)
552 info
->gcc_compiled
= 2;
553 else if (string
!= NULL
&& strcmp (string
, "gcc_compiled.") == 0)
554 info
->gcc_compiled
= 1;
556 info
->n_opt_found
= true;
565 info
->last_type
= type
;
570 /* Parse the stabs string. */
573 parse_stab_string (dhandle
, info
, stabtype
, desc
, value
, string
)
575 struct stab_handle
*info
;
589 p
= strchr (string
, ':');
604 /* GCC 2.x puts the line number in desc. SunOS apparently puts in
605 the number of bytes occupied by a type or object, which we
607 if (info
->gcc_compiled
>= 2)
612 /* FIXME: Sometimes the special C++ names start with '.'. */
614 if (string
[0] == '$')
622 /* Was: name = "vptr"; */
628 /* This was an anonymous type that was never fixed up. */
631 /* SunPRO (3.0 at least) static variable encoding. */
634 warn_stab (string
, "unknown C++ encoded name");
641 if (p
== string
|| (string
[0] == ' ' && p
== string
+ 1))
644 name
= savestring (string
, p
- string
);
648 if (isdigit ((unsigned char) *p
) || *p
== '(' || *p
== '-')
656 /* c is a special case, not followed by a type-number.
657 SYMBOL:c=iVALUE for an integer constant symbol.
658 SYMBOL:c=rVALUE for a floating constant symbol.
659 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
660 e.g. "b:c=e6,0" for "const b = blob1"
661 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
671 /* Floating point constant. */
672 if (! debug_record_float_const (dhandle
, name
, atof (p
)))
676 /* Integer constant. */
677 /* Defining integer constants this way is kind of silly,
678 since 'e' constants allows the compiler to give not only
679 the value, but the type as well. C has at least int,
680 long, unsigned int, and long long as constant types;
681 other languages probably should have at least unsigned as
682 well as signed constants. */
683 if (! debug_record_int_const (dhandle
, name
, atoi (p
)))
687 /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value
688 can be represented as integral.
689 e.g. "b:c=e6,0" for "const b = blob1"
690 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
691 dtype
= parse_stab_type (dhandle
, info
, &p
, (debug_type
**) NULL
);
692 if (dtype
== DEBUG_TYPE_NULL
)
699 if (! debug_record_typed_const (dhandle
, name
, dtype
, atoi (p
)))
710 /* The name of a caught exception. */
711 dtype
= parse_stab_type (dhandle
, info
, &p
, (debug_type
**) NULL
);
712 if (dtype
== DEBUG_TYPE_NULL
)
714 if (! debug_record_label (dhandle
, name
, dtype
, value
))
720 /* A function definition. */
721 dtype
= parse_stab_type (dhandle
, info
, &p
, (debug_type
**) NULL
);
722 if (dtype
== DEBUG_TYPE_NULL
)
724 if (! debug_record_function (dhandle
, name
, dtype
, type
== 'F', value
))
727 /* Sun acc puts declared types of arguments here. We don't care
728 about their actual types (FIXME -- we should remember the whole
729 function prototype), but the list may define some new types
730 that we have to remember, so we must scan it now. */
734 if (parse_stab_type (dhandle
, info
, &p
, (debug_type
**) NULL
)
742 /* A global symbol. The value must be extracted from the symbol
744 dtype
= parse_stab_type (dhandle
, info
, &p
, (debug_type
**) NULL
);
745 if (dtype
== DEBUG_TYPE_NULL
)
747 if (! stab_record_variable (dhandle
, info
, name
, dtype
, DEBUG_GLOBAL
,
752 /* This case is faked by a conditional above, when there is no
753 code letter in the dbx data. Dbx data never actually
757 dtype
= parse_stab_type (dhandle
, info
, &p
, (debug_type
**) NULL
);
758 if (dtype
== DEBUG_TYPE_NULL
)
760 if (! stab_record_variable (dhandle
, info
, name
, dtype
, DEBUG_LOCAL
,
766 /* A function parameter. */
768 dtype
= parse_stab_type (dhandle
, info
, &p
, (debug_type
**) NULL
);
771 /* pF is a two-letter code that means a function parameter in
772 Fortran. The type-number specifies the type of the return
773 value. Translate it into a pointer-to-function type. */
775 dtype
= parse_stab_type (dhandle
, info
, &p
, (debug_type
**) NULL
);
776 if (dtype
!= DEBUG_TYPE_NULL
)
777 dtype
= debug_make_pointer_type (dhandle
,
778 debug_make_function_type (dhandle
,
781 if (dtype
== DEBUG_TYPE_NULL
)
783 if (! debug_record_parameter (dhandle
, name
, dtype
, DEBUG_PARM_STACK
,
787 /* FIXME: At this point gdb considers rearranging the parameter
788 address on a big endian machine if it is smaller than an int.
789 We have no way to do that, since we don't really know much
795 if (stabtype
== N_FUN
)
797 /* Prototype of a function referenced by this file. */
801 if (parse_stab_type (dhandle
, info
, &p
, (debug_type
**) NULL
)
809 /* Parameter which is in a register. */
810 dtype
= parse_stab_type (dhandle
, info
, &p
, (debug_type
**) NULL
);
811 if (dtype
== DEBUG_TYPE_NULL
)
813 if (! debug_record_parameter (dhandle
, name
, dtype
, DEBUG_PARM_REG
,
819 /* Register variable (either global or local). */
820 dtype
= parse_stab_type (dhandle
, info
, &p
, (debug_type
**) NULL
);
821 if (dtype
== DEBUG_TYPE_NULL
)
823 if (! stab_record_variable (dhandle
, info
, name
, dtype
, DEBUG_REGISTER
,
827 /* FIXME: At this point gdb checks to combine pairs of 'p' and
828 'r' stabs into a single 'P' stab. */
833 /* Static symbol at top level of file */
834 dtype
= parse_stab_type (dhandle
, info
, &p
, (debug_type
**) NULL
);
835 if (dtype
== DEBUG_TYPE_NULL
)
837 if (! stab_record_variable (dhandle
, info
, name
, dtype
, DEBUG_STATIC
,
844 dtype
= parse_stab_type (dhandle
, info
, &p
, &slot
);
845 if (dtype
== DEBUG_TYPE_NULL
)
849 /* A nameless type. Nothing to do. */
853 dtype
= debug_name_type (dhandle
, name
, dtype
);
854 if (dtype
== DEBUG_TYPE_NULL
)
863 /* Struct, union, or enum tag. For GNU C++, this can be be followed
864 by 't' which means we are typedef'ing it as well. */
868 /* FIXME: gdb sets synonym to true if the current language
877 dtype
= parse_stab_type (dhandle
, info
, &p
, &slot
);
878 if (dtype
== DEBUG_TYPE_NULL
)
883 dtype
= debug_tag_type (dhandle
, name
, dtype
);
884 if (dtype
== DEBUG_TYPE_NULL
)
889 /* See if we have a cross reference to this tag which we can now
892 register struct stab_tag
**pst
;
894 for (pst
= &info
->tags
; *pst
!= NULL
; pst
= &(*pst
)->next
)
896 if ((*pst
)->name
[0] == name
[0]
897 && strcmp ((*pst
)->name
, name
) == 0)
899 (*pst
)->slot
= dtype
;
908 dtype
= debug_name_type (dhandle
, name
, dtype
);
909 if (dtype
== DEBUG_TYPE_NULL
)
919 /* Static symbol of local scope */
920 dtype
= parse_stab_type (dhandle
, info
, &p
, (debug_type
**) NULL
);
921 if (dtype
== DEBUG_TYPE_NULL
)
923 /* FIXME: gdb checks os9k_stabs here. */
924 if (! stab_record_variable (dhandle
, info
, name
, dtype
,
925 DEBUG_LOCAL_STATIC
, value
))
930 /* Reference parameter. */
931 dtype
= parse_stab_type (dhandle
, info
, &p
, (debug_type
**) NULL
);
932 if (dtype
== DEBUG_TYPE_NULL
)
934 if (! debug_record_parameter (dhandle
, name
, dtype
, DEBUG_PARM_REFERENCE
,
940 /* Reference parameter which is in a register. */
941 dtype
= parse_stab_type (dhandle
, info
, &p
, (debug_type
**) NULL
);
942 if (dtype
== DEBUG_TYPE_NULL
)
944 if (! debug_record_parameter (dhandle
, name
, dtype
, DEBUG_PARM_REF_REG
,
950 /* This is used by Sun FORTRAN for "function result value".
951 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
952 that Pascal uses it too, but when I tried it Pascal used
953 "x:3" (local symbol) instead. */
954 dtype
= parse_stab_type (dhandle
, info
, &p
, (debug_type
**) NULL
);
955 if (dtype
== DEBUG_TYPE_NULL
)
957 if (! stab_record_variable (dhandle
, info
, name
, dtype
, DEBUG_LOCAL
,
967 /* FIXME: gdb converts structure values to structure pointers in a
968 couple of cases, depending upon the target. */
973 /* Parse a stabs type. */
976 parse_stab_type (dhandle
, info
, pp
, slotp
)
978 struct stab_handle
*info
;
997 /* Read type number if present. The type number may be omitted.
998 for instance in a two-dimensional array declared with type
999 "ar1;1;10;ar1;1;10;4". */
1000 if (! isdigit ((unsigned char) **pp
) && **pp
!= '(' && **pp
!= '-')
1002 /* 'typenums=' not present, type is anonymous. Read and return
1003 the definition, but don't put it in the type vector. */
1004 typenums
[0] = typenums
[1] = -1;
1008 if (! parse_stab_type_number (pp
, typenums
))
1009 return DEBUG_TYPE_NULL
;
1013 /* Type is not being defined here. Either it already
1014 exists, or this is a forward reference to it. */
1015 return stab_find_type (dhandle
, info
, typenums
);
1018 /* Only set the slot if the type is being defined. This means
1019 that the mapping from type numbers to types will only record
1020 the name of the typedef which defines a type. If we don't do
1021 this, then something like
1024 will record that i is of type foo. Unfortunately, stabs
1025 information is ambiguous about variable types. For this code,
1029 the stabs information records both i and j as having the same
1030 type. This could be fixed by patching the compiler. */
1031 if (slotp
!= NULL
&& typenums
[0] >= 0 && typenums
[1] >= 0)
1032 *slotp
= stab_find_slot (info
, typenums
);
1034 /* Type is being defined here. */
1040 const char *p
= *pp
+ 1;
1043 if (isdigit ((unsigned char) *p
) || *p
== '(' || *p
== '-')
1049 /* Type attributes. */
1052 for (; *p
!= ';'; ++p
)
1057 return DEBUG_TYPE_NULL
;
1065 size
= atoi (attr
+ 1);
1075 /* Ignore unrecognized type attributes, so future
1076 compilers can invent new ones. */
1089 enum debug_type_kind code
;
1090 const char *q1
, *q2
, *p
;
1092 struct stab_tag
*st
;
1094 /* A cross reference to another type. */
1099 code
= DEBUG_KIND_STRUCT
;
1102 code
= DEBUG_KIND_UNION
;
1105 code
= DEBUG_KIND_ENUM
;
1108 /* Complain and keep going, so compilers can invent new
1109 cross-reference types. */
1110 warn_stab (orig
, "unrecognized cross reference type");
1111 code
= DEBUG_KIND_STRUCT
;
1116 q1
= strchr (*pp
, '<');
1117 p
= strchr (*pp
, ':');
1121 return DEBUG_TYPE_NULL
;
1123 while (q1
!= NULL
&& p
> q1
&& p
[1] == ':')
1125 q2
= strchr (q1
, '>');
1126 if (q2
== NULL
|| q2
< p
)
1129 p
= strchr (p
, ':');
1133 return DEBUG_TYPE_NULL
;
1137 name
= savestring (*pp
, p
- *pp
);
1141 /* We pass DEBUG_KIND_VOID because we want all tags in the
1142 same namespace. This is right for C, and I don't know how
1143 to handle other languages. FIXME. */
1144 dtype
= debug_find_tagged_type (dhandle
, name
, DEBUG_KIND_VOID
);
1145 if (dtype
!= DEBUG_TYPE_NULL
)
1148 if (typenums
[0] != -1)
1150 if (! stab_record_type (dhandle
, info
, typenums
, dtype
))
1151 return DEBUG_TYPE_NULL
;
1156 /* We need to allocate an entry on the undefined tag list. */
1157 for (st
= info
->tags
; st
!= NULL
; st
= st
->next
)
1159 if (st
->name
[0] == name
[0]
1160 && strcmp (st
->name
, name
) == 0)
1165 st
= (struct stab_tag
*) xmalloc (sizeof *st
);
1166 memset (st
, 0, sizeof *st
);
1168 st
->next
= info
->tags
;
1171 st
->slot
= DEBUG_TYPE_NULL
;
1172 st
->type
= debug_make_indirect_type (dhandle
, &st
->slot
, name
);
1177 if (typenums
[0] != -1)
1179 if (! stab_record_type (dhandle
, info
, typenums
, dtype
))
1180 return DEBUG_TYPE_NULL
;
1202 /* This type is defined as another type. */
1207 /* Peek ahead at the number to detect void. */
1208 if (! parse_stab_type_number (pp
, xtypenums
))
1209 return DEBUG_TYPE_NULL
;
1211 if (typenums
[0] == xtypenums
[0] && typenums
[1] == xtypenums
[1])
1213 /* This type is being defined as itself, which means that
1215 dtype
= debug_make_void_type (dhandle
);
1221 /* Go back to the number and have parse_stab_type get it.
1222 This means that we can deal with something like
1223 t(1,2)=(3,4)=... which the Lucid compiler uses. */
1224 dtype
= parse_stab_type (dhandle
, info
, pp
, (debug_type
**) NULL
);
1225 if (dtype
== DEBUG_TYPE_NULL
)
1226 return DEBUG_TYPE_NULL
;
1229 if (typenums
[0] != -1)
1231 if (! stab_record_type (dhandle
, info
, typenums
, dtype
))
1232 return DEBUG_TYPE_NULL
;
1239 dtype
= debug_make_pointer_type (dhandle
,
1240 parse_stab_type (dhandle
, info
, pp
,
1241 (debug_type
**) NULL
));
1245 /* Reference to another type. */
1246 dtype
= (debug_make_reference_type
1248 parse_stab_type (dhandle
, info
, pp
, (debug_type
**) NULL
)));
1252 /* Function returning another type. */
1253 /* FIXME: gdb checks os9k_stabs here. */
1254 dtype
= (debug_make_function_type
1256 parse_stab_type (dhandle
, info
, pp
, (debug_type
**) NULL
)));
1260 /* Const qualifier on some type (Sun). */
1261 /* FIXME: gdb accepts 'c' here if os9k_stabs. */
1262 dtype
= debug_make_const_type (dhandle
,
1263 parse_stab_type (dhandle
, info
, pp
,
1264 (debug_type
**) NULL
));
1268 /* Volatile qual on some type (Sun). */
1269 /* FIXME: gdb accepts 'i' here if os9k_stabs. */
1270 dtype
= (debug_make_volatile_type
1272 parse_stab_type (dhandle
, info
, pp
, (debug_type
**) NULL
)));
1276 /* Offset (class & variable) type. This is used for a pointer
1277 relative to an object. */
1284 domain
= parse_stab_type (dhandle
, info
, pp
, (debug_type
**) NULL
);
1285 if (domain
== DEBUG_TYPE_NULL
)
1286 return DEBUG_TYPE_NULL
;
1291 return DEBUG_TYPE_NULL
;
1295 memtype
= parse_stab_type (dhandle
, info
, pp
, (debug_type
**) NULL
);
1296 if (memtype
== DEBUG_TYPE_NULL
)
1297 return DEBUG_TYPE_NULL
;
1299 dtype
= debug_make_offset_type (dhandle
, domain
, memtype
);
1304 /* Method (class & fn) type. */
1307 debug_type return_type
;
1310 return_type
= parse_stab_type (dhandle
, info
, pp
,
1311 (debug_type
**) NULL
);
1312 if (return_type
== DEBUG_TYPE_NULL
)
1313 return DEBUG_TYPE_NULL
;
1317 return DEBUG_TYPE_NULL
;
1320 dtype
= debug_make_method_type (dhandle
, return_type
,
1321 DEBUG_TYPE_NULL
, NULL
);
1326 debug_type return_type
;
1331 domain
= parse_stab_type (dhandle
, info
, pp
, (debug_type
**) NULL
);
1332 if (domain
== DEBUG_TYPE_NULL
)
1333 return DEBUG_TYPE_NULL
;
1338 return DEBUG_TYPE_NULL
;
1342 return_type
= parse_stab_type (dhandle
, info
, pp
,
1343 (debug_type
**) NULL
);
1344 if (return_type
== DEBUG_TYPE_NULL
)
1345 return DEBUG_TYPE_NULL
;
1348 args
= (debug_type
*) xmalloc (alloc
* sizeof *args
);
1355 return DEBUG_TYPE_NULL
;
1362 args
= ((debug_type
*)
1363 xrealloc ((PTR
) args
, alloc
* sizeof *args
));
1366 args
[n
] = parse_stab_type (dhandle
, info
, pp
,
1367 (debug_type
**) NULL
);
1368 if (args
[n
] == DEBUG_TYPE_NULL
)
1369 return DEBUG_TYPE_NULL
;
1374 args
[n
] = DEBUG_TYPE_NULL
;
1376 dtype
= debug_make_method_type (dhandle
, return_type
, domain
, args
);
1382 dtype
= parse_stab_range_type (dhandle
, info
, pp
, typenums
);
1386 /* FIXME: gdb checks os9k_stabs here. */
1387 /* Sun ACC builtin int type. */
1388 dtype
= parse_stab_sun_builtin_type (dhandle
, pp
);
1392 /* Sun ACC builtin float type. */
1393 dtype
= parse_stab_sun_floating_type (dhandle
, pp
);
1397 /* Enumeration type. */
1398 dtype
= parse_stab_enum_type (dhandle
, pp
);
1403 /* Struct or union type. */
1404 dtype
= parse_stab_struct_type (dhandle
, info
, pp
,
1405 descriptor
== 's', typenums
);
1413 return DEBUG_TYPE_NULL
;
1417 dtype
= parse_stab_array_type (dhandle
, info
, pp
, stringp
);
1421 dtype
= debug_make_set_type (dhandle
,
1422 parse_stab_type (dhandle
, info
, pp
,
1423 (debug_type
**) NULL
),
1429 return DEBUG_TYPE_NULL
;
1432 if (dtype
== DEBUG_TYPE_NULL
)
1433 return DEBUG_TYPE_NULL
;
1435 if (typenums
[0] != -1)
1437 if (! stab_record_type (dhandle
, info
, typenums
, dtype
))
1438 return DEBUG_TYPE_NULL
;
1443 if (! debug_record_type_size (dhandle
, dtype
, (unsigned int) size
))
1450 /* Read a number by which a type is referred to in dbx data, or
1451 perhaps read a pair (FILENUM, TYPENUM) in parentheses. Just a
1452 single number N is equivalent to (0,N). Return the two numbers by
1453 storing them in the vector TYPENUMS. */
1456 parse_stab_type_number (pp
, typenums
)
1467 typenums
[1] = (int) parse_number (pp
, (boolean
*) NULL
);
1472 typenums
[0] = (int) parse_number (pp
, (boolean
*) NULL
);
1479 typenums
[1] = (int) parse_number (pp
, (boolean
*) NULL
);
1491 /* Parse a range type. */
1494 parse_stab_range_type (dhandle
, info
, pp
, typenums
)
1496 struct stab_handle
*info
;
1498 const int *typenums
;
1502 boolean self_subrange
;
1503 debug_type index_type
;
1504 const char *s2
, *s3
;
1505 bfd_signed_vma n2
, n3
;
1510 index_type
= DEBUG_TYPE_NULL
;
1512 /* First comes a type we are a subrange of.
1513 In C it is usually 0, 1 or the type being defined. */
1514 if (! parse_stab_type_number (pp
, rangenums
))
1515 return DEBUG_TYPE_NULL
;
1517 self_subrange
= (rangenums
[0] == typenums
[0]
1518 && rangenums
[1] == typenums
[1]);
1523 index_type
= parse_stab_type (dhandle
, info
, pp
, (debug_type
**) NULL
);
1524 if (index_type
== DEBUG_TYPE_NULL
)
1525 return DEBUG_TYPE_NULL
;
1531 /* The remaining two operands are usually lower and upper bounds of
1532 the range. But in some special cases they mean something else. */
1534 n2
= parse_number (pp
, &ov2
);
1538 return DEBUG_TYPE_NULL
;
1543 n3
= parse_number (pp
, &ov3
);
1547 return DEBUG_TYPE_NULL
;
1553 /* gcc will emit range stabs for long long types. Handle this
1554 as a special case. FIXME: This needs to be more general. */
1555 #define LLLOW "01000000000000000000000;"
1556 #define LLHIGH "0777777777777777777777;"
1557 #define ULLHIGH "01777777777777777777777;"
1558 if (index_type
== DEBUG_TYPE_NULL
)
1560 if (strncmp (s2
, LLLOW
, sizeof LLLOW
- 1) == 0
1561 && strncmp (s3
, LLHIGH
, sizeof LLHIGH
- 1) == 0)
1562 return debug_make_int_type (dhandle
, 8, false);
1565 && strncmp (s3
, ULLHIGH
, sizeof ULLHIGH
- 1) == 0)
1566 return debug_make_int_type (dhandle
, 8, true);
1569 warn_stab (orig
, "numeric overflow");
1572 if (index_type
== DEBUG_TYPE_NULL
)
1574 /* A type defined as a subrange of itself, with both bounds 0,
1576 if (self_subrange
&& n2
== 0 && n3
== 0)
1577 return debug_make_void_type (dhandle
);
1579 /* If n3 is zero and n2 is positive, this is a floating point
1580 type, and n2 is the number of bytes. */
1581 if (n3
== 0 && n2
> 0)
1582 return debug_make_float_type (dhandle
, n2
);
1584 /* If the upper bound is -1, this is an unsigned int. */
1585 if (n2
== 0 && n3
== -1)
1587 /* FIXME: The size here really depends upon the target. */
1588 return debug_make_int_type (dhandle
, 4, true);
1591 /* A range of 0 to 127 is char. */
1592 if (self_subrange
&& n2
== 0 && n3
== 127)
1593 return debug_make_int_type (dhandle
, 1, false);
1595 /* FIXME: gdb checks for the language CHILL here. */
1600 return debug_make_int_type (dhandle
, - n3
, true);
1601 else if (n3
== 0xff)
1602 return debug_make_int_type (dhandle
, 1, true);
1603 else if (n3
== 0xffff)
1604 return debug_make_int_type (dhandle
, 2, true);
1605 /* -1 is used for the upper bound of (4 byte) "unsigned int"
1606 and "unsigned long", and we already checked for that, so
1607 don't need to test for it here. */
1611 && (self_subrange
|| n2
== -8))
1612 return debug_make_int_type (dhandle
, - n2
, true);
1613 else if (n2
== - n3
- 1)
1616 return debug_make_int_type (dhandle
, 1, false);
1617 else if (n3
== 0x7fff)
1618 return debug_make_int_type (dhandle
, 2, false);
1619 else if (n3
== 0x7fffffff)
1620 return debug_make_int_type (dhandle
, 4, false);
1624 /* At this point I don't have the faintest idea how to deal with a
1625 self_subrange type; I'm going to assume that this is used as an
1626 idiom, and that all of them are special cases. So . . . */
1630 return DEBUG_TYPE_NULL
;
1633 index_type
= stab_find_type (dhandle
, info
, rangenums
);
1634 if (index_type
== DEBUG_TYPE_NULL
)
1636 /* Does this actually ever happen? Is that why we are worrying
1637 about dealing with it rather than just calling error_type? */
1638 warn_stab (orig
, "missing index type");
1639 index_type
= debug_make_int_type (dhandle
, 4, false);
1642 return debug_make_range_type (dhandle
, index_type
, n2
, n3
);
1645 /* Sun's ACC uses a somewhat saner method for specifying the builtin
1646 typedefs in every file (for int, long, etc):
1648 type = b <signed> <width>; <offset>; <nbits>
1649 signed = u or s. Possible c in addition to u or s (for char?).
1650 offset = offset from high order bit to start bit of type.
1651 width is # bytes in object of this type, nbits is # bits in type.
1653 The width/offset stuff appears to be for small objects stored in
1654 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
1658 parse_stab_sun_builtin_type (dhandle
, pp
)
1678 return DEBUG_TYPE_NULL
;
1682 /* For some odd reason, all forms of char put a c here. This is strange
1683 because no other type has this honor. We can safely ignore this because
1684 we actually determine 'char'acterness by the number of bits specified in
1689 /* The first number appears to be the number of bytes occupied
1690 by this type, except that unsigned short is 4 instead of 2.
1691 Since this information is redundant with the third number,
1692 we will ignore it. */
1693 (void) parse_number (pp
, (boolean
*) NULL
);
1697 return DEBUG_TYPE_NULL
;
1701 /* The second number is always 0, so ignore it too. */
1702 (void) parse_number (pp
, (boolean
*) NULL
);
1706 return DEBUG_TYPE_NULL
;
1710 /* The third number is the number of bits for this type. */
1711 bits
= parse_number (pp
, (boolean
*) NULL
);
1713 /* The type *should* end with a semicolon. If it are embedded
1714 in a larger type the semicolon may be the only way to know where
1715 the type ends. If this type is at the end of the stabstring we
1716 can deal with the omitted semicolon (but we don't have to like
1717 it). Don't bother to complain(), Sun's compiler omits the semicolon
1723 return debug_make_void_type (dhandle
);
1725 return debug_make_int_type (dhandle
, bits
/ 8, unsignedp
);
1728 /* Parse a builtin floating type generated by the Sun compiler. */
1731 parse_stab_sun_floating_type (dhandle
, pp
)
1741 /* The first number has more details about the type, for example
1743 details
= parse_number (pp
, (boolean
*) NULL
);
1747 return DEBUG_TYPE_NULL
;
1750 /* The second number is the number of bytes occupied by this type */
1751 bytes
= parse_number (pp
, (boolean
*) NULL
);
1755 return DEBUG_TYPE_NULL
;
1758 if (details
== NF_COMPLEX
1759 || details
== NF_COMPLEX16
1760 || details
== NF_COMPLEX32
)
1761 return debug_make_complex_type (dhandle
, bytes
);
1763 return debug_make_float_type (dhandle
, bytes
);
1766 /* Handle an enum type. */
1769 parse_stab_enum_type (dhandle
, pp
)
1775 bfd_signed_vma
*values
;
1781 /* FIXME: gdb checks os9k_stabs here. */
1783 /* The aix4 compiler emits an extra field before the enum members;
1784 my guess is it's a type of some sort. Just ignore it. */
1792 /* Read the value-names and their values.
1793 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
1794 A semicolon or comma instead of a NAME means the end. */
1796 names
= (const char **) xmalloc (alloc
* sizeof *names
);
1797 values
= (bfd_signed_vma
*) xmalloc (alloc
* sizeof *values
);
1799 while (**pp
!= '\0' && **pp
!= ';' && **pp
!= ',')
1809 name
= savestring (*pp
, p
- *pp
);
1812 val
= (bfd_signed_vma
) parse_number (pp
, (boolean
*) NULL
);
1816 return DEBUG_TYPE_NULL
;
1823 names
= ((const char **)
1824 xrealloc ((PTR
) names
, alloc
* sizeof *names
));
1825 values
= ((bfd_signed_vma
*)
1826 xrealloc ((PTR
) values
, alloc
* sizeof *values
));
1840 return debug_make_enum_type (dhandle
, names
, values
);
1843 /* Read the description of a structure (or union type) and return an object
1844 describing the type.
1846 PP points to a character pointer that points to the next unconsumed token
1847 in the the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
1848 *PP will point to "4a:1,0,32;;". */
1851 parse_stab_struct_type (dhandle
, info
, pp
, structp
, typenums
)
1853 struct stab_handle
*info
;
1856 const int *typenums
;
1860 debug_baseclass
*baseclasses
;
1861 debug_field
*fields
;
1863 debug_method
*methods
;
1864 debug_type vptrbase
;
1870 size
= parse_number (pp
, (boolean
*) NULL
);
1872 /* Get the other information. */
1873 if (! parse_stab_baseclasses (dhandle
, info
, pp
, &baseclasses
)
1874 || ! parse_stab_struct_fields (dhandle
, info
, pp
, &fields
, &statics
)
1875 || ! parse_stab_members (dhandle
, info
, pp
, &methods
)
1876 || ! parse_stab_tilde_field (dhandle
, info
, pp
, typenums
, &vptrbase
,
1878 return DEBUG_TYPE_NULL
;
1881 && baseclasses
== NULL
1883 && vptrbase
== DEBUG_TYPE_NULL
1885 return debug_make_struct_type (dhandle
, structp
, size
, fields
);
1887 return debug_make_object_type (dhandle
, structp
, size
, fields
, baseclasses
,
1888 methods
, vptrbase
, ownvptr
);
1891 /* The stabs for C++ derived classes contain baseclass information which
1892 is marked by a '!' character after the total size. This function is
1893 called when we encounter the baseclass marker, and slurps up all the
1894 baseclass information.
1896 Immediately following the '!' marker is the number of base classes that
1897 the class is derived from, followed by information for each base class.
1898 For each base class, there are two visibility specifiers, a bit offset
1899 to the base class information within the derived class, a reference to
1900 the type for the base class, and a terminating semicolon.
1902 A typical example, with two base classes, would be "!2,020,19;0264,21;".
1904 Baseclass information marker __________________|| | | | | | |
1905 Number of baseclasses __________________________| | | | | | |
1906 Visibility specifiers (2) ________________________| | | | | |
1907 Offset in bits from start of class _________________| | | | |
1908 Type number for base class ___________________________| | | |
1909 Visibility specifiers (2) _______________________________| | |
1910 Offset in bits from start of class ________________________| |
1911 Type number of base class ____________________________________|
1913 Return true for success, false for failure. */
1916 parse_stab_baseclasses (dhandle
, info
, pp
, retp
)
1918 struct stab_handle
*info
;
1920 debug_baseclass
**retp
;
1924 debug_baseclass
*classes
;
1932 /* No base classes. */
1937 c
= (unsigned int) parse_number (pp
, (boolean
*) NULL
);
1946 classes
= (debug_baseclass
*) xmalloc ((c
+ 1) * sizeof (**retp
));
1948 for (i
= 0; i
< c
; i
++)
1951 enum debug_visibility visibility
;
1964 warn_stab (orig
, "unknown virtual character for baseclass");
1973 visibility
= DEBUG_VISIBILITY_PRIVATE
;
1976 visibility
= DEBUG_VISIBILITY_PROTECTED
;
1979 visibility
= DEBUG_VISIBILITY_PUBLIC
;
1982 warn_stab (orig
, "unknown visibility character for baseclass");
1983 visibility
= DEBUG_VISIBILITY_PUBLIC
;
1988 /* The remaining value is the bit offset of the portion of the
1989 object corresponding to this baseclass. Always zero in the
1990 absence of multiple inheritance. */
1991 bitpos
= parse_number (pp
, (boolean
*) NULL
);
1999 type
= parse_stab_type (dhandle
, info
, pp
, (debug_type
**) NULL
);
2000 if (type
== DEBUG_TYPE_NULL
)
2003 classes
[i
] = debug_make_baseclass (dhandle
, type
, bitpos
, virtual,
2005 if (classes
[i
] == DEBUG_BASECLASS_NULL
)
2013 classes
[i
] = DEBUG_BASECLASS_NULL
;
2020 /* Read struct or class data fields. They have the form:
2022 NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
2024 At the end, we see a semicolon instead of a field.
2026 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
2029 The optional VISIBILITY is one of:
2031 '/0' (VISIBILITY_PRIVATE)
2032 '/1' (VISIBILITY_PROTECTED)
2033 '/2' (VISIBILITY_PUBLIC)
2034 '/9' (VISIBILITY_IGNORE)
2036 or nothing, for C style fields with public visibility.
2038 Returns 1 for success, 0 for failure. */
2041 parse_stab_struct_fields (dhandle
, info
, pp
, retp
, staticsp
)
2043 struct stab_handle
*info
;
2050 debug_field
*fields
;
2061 fields
= (debug_field
*) xmalloc (alloc
* sizeof *fields
);
2064 /* FIXME: gdb checks os9k_stabs here. */
2068 /* Add 1 to c to leave room for NULL pointer at end. */
2072 fields
= ((debug_field
*)
2073 xrealloc ((PTR
) fields
, alloc
* sizeof *fields
));
2076 /* If it starts with CPLUS_MARKER it is a special abbreviation,
2077 unless the CPLUS_MARKER is followed by an underscore, in
2078 which case it is just the name of an anonymous type, which we
2079 should handle like any other type name. We accept either '$'
2080 or '.', because a field name can never contain one of these
2081 characters except as a CPLUS_MARKER. */
2083 if ((*p
== '$' || *p
== '.') && p
[1] != '_')
2086 if (! parse_stab_cpp_abbrev (dhandle
, info
, pp
, fields
+ c
))
2092 /* Look for the ':' that separates the field name from the field
2093 values. Data members are delimited by a single ':', while member
2094 functions are delimited by a pair of ':'s. When we hit the member
2095 functions (if any), terminate scan loop and return. */
2097 p
= strchr (p
, ':');
2107 if (! parse_stab_one_struct_field (dhandle
, info
, pp
, p
, fields
+ c
,
2114 fields
[c
] = DEBUG_FIELD_NULL
;
2121 /* Special GNU C++ name. */
2124 parse_stab_cpp_abbrev (dhandle
, info
, pp
, retp
)
2126 struct stab_handle
*info
;
2134 const char *typename
;
2138 *retp
= DEBUG_FIELD_NULL
;
2152 /* At this point, *pp points to something like "22:23=*22...", where
2153 the type number before the ':' is the "context" and everything
2154 after is a regular type definition. Lookup the type, find it's
2155 name, and construct the field name. */
2157 context
= parse_stab_type (dhandle
, info
, pp
, (debug_type
**) NULL
);
2158 if (context
== DEBUG_TYPE_NULL
)
2164 /* $vf -- a virtual function table pointer. */
2168 /* $vb -- a virtual bsomethingorother */
2169 typename
= debug_get_type_name (dhandle
, context
);
2170 if (typename
== NULL
)
2172 warn_stab (orig
, "unnamed $vb type");
2175 name
= concat ("_vb$", typename
, (const char *) NULL
);
2178 warn_stab (orig
, "unrecognized C++ abbreviation");
2179 name
= "INVALID_CPLUSPLUS_ABBREV";
2190 type
= parse_stab_type (dhandle
, info
, pp
, (debug_type
**) NULL
);
2198 bitpos
= parse_number (pp
, (boolean
*) NULL
);
2206 *retp
= debug_make_field (dhandle
, name
, type
, bitpos
, 0,
2207 DEBUG_VISIBILITY_PRIVATE
);
2208 if (*retp
== DEBUG_FIELD_NULL
)
2214 /* Parse a single field in a struct or union. */
2217 parse_stab_one_struct_field (dhandle
, info
, pp
, p
, retp
, staticsp
)
2219 struct stab_handle
*info
;
2227 enum debug_visibility visibility
;
2234 /* FIXME: gdb checks ARM_DEMANGLING here. */
2236 name
= savestring (*pp
, p
- *pp
);
2241 visibility
= DEBUG_VISIBILITY_PUBLIC
;
2248 visibility
= DEBUG_VISIBILITY_PRIVATE
;
2251 visibility
= DEBUG_VISIBILITY_PROTECTED
;
2254 visibility
= DEBUG_VISIBILITY_PUBLIC
;
2257 warn_stab (orig
, "unknown visibility character for field");
2258 visibility
= DEBUG_VISIBILITY_PUBLIC
;
2264 type
= parse_stab_type (dhandle
, info
, pp
, (debug_type
**) NULL
);
2265 if (type
== DEBUG_TYPE_NULL
)
2272 /* This is a static class member. */
2274 p
= strchr (*pp
, ';');
2281 varname
= savestring (*pp
, p
- *pp
);
2285 *retp
= debug_make_static_member (dhandle
, name
, type
, varname
,
2299 bitpos
= parse_number (pp
, (boolean
*) NULL
);
2307 bitsize
= parse_number (pp
, (boolean
*) NULL
);
2315 if (bitpos
== 0 && bitsize
== 0)
2317 /* This can happen in two cases: (1) at least for gcc 2.4.5 or
2318 so, it is a field which has been optimized out. The correct
2319 stab for this case is to use VISIBILITY_IGNORE, but that is a
2320 recent invention. (2) It is a 0-size array. For example
2321 union { int num; char str[0]; } foo. Printing "<no value>"
2322 for str in "p foo" is OK, since foo.str (and thus foo.str[3])
2323 will continue to work, and a 0-size array as a whole doesn't
2324 have any contents to print.
2326 I suspect this probably could also happen with gcc -gstabs
2327 (not -gstabs+) for static fields, and perhaps other C++
2328 extensions. Hopefully few people use -gstabs with gdb, since
2329 it is intended for dbx compatibility. */
2330 visibility
= DEBUG_VISIBILITY_IGNORE
;
2333 /* FIXME: gdb does some stuff here to mark fields as unpacked. */
2335 *retp
= debug_make_field (dhandle
, name
, type
, bitpos
, bitsize
, visibility
);
2340 /* Read member function stabs info for C++ classes. The form of each member
2343 NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
2345 An example with two member functions is:
2347 afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
2349 For the case of overloaded operators, the format is op$::*.funcs, where
2350 $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
2351 name (such as `+=') and `.' marks the end of the operator name. */
2354 parse_stab_members (dhandle
, info
, pp
, retp
)
2356 struct stab_handle
*info
;
2358 debug_method
**retp
;
2361 debug_method
*methods
;
2377 debug_method_variant
*variants
;
2379 unsigned int allocvars
;
2380 debug_type look_ahead_type
;
2382 p
= strchr (*pp
, ':');
2383 if (p
== NULL
|| p
[1] != ':')
2386 /* FIXME: Some systems use something other than '$' here. */
2387 if ((*pp
)[0] != 'o' || (*pp
)[1] != 'p' || (*pp
)[2] != '$')
2389 name
= savestring (*pp
, p
- *pp
);
2394 /* This is a completely wierd case. In order to stuff in the
2395 names that might contain colons (the usual name delimiter),
2396 Mike Tiemann defined a different name format which is
2397 signalled if the identifier is "op$". In that case, the
2398 format is "op$::XXXX." where XXXX is the name. This is
2399 used for names like "+" or "=". YUUUUUUUK! FIXME! */
2401 for (p
= *pp
; *p
!= '.' && *p
!= '\0'; p
++)
2408 name
= savestring (*pp
, p
- *pp
);
2413 variants
= ((debug_method_variant
*)
2414 xmalloc (allocvars
* sizeof *variants
));
2417 look_ahead_type
= DEBUG_TYPE_NULL
;
2423 enum debug_visibility visibility
;
2424 boolean constp
, volatilep
, staticp
;
2428 if (look_ahead_type
!= DEBUG_TYPE_NULL
)
2430 /* g++ version 1 kludge */
2431 type
= look_ahead_type
;
2432 look_ahead_type
= DEBUG_TYPE_NULL
;
2436 type
= parse_stab_type (dhandle
, info
, pp
, (debug_type
**) NULL
);
2437 if (type
== DEBUG_TYPE_NULL
)
2447 p
= strchr (*pp
, ';');
2454 /* FIXME: gdb sets is_stub here. */
2456 argtypes
= savestring (*pp
, p
- *pp
);
2462 visibility
= DEBUG_VISIBILITY_PRIVATE
;
2465 visibility
= DEBUG_VISIBILITY_PROTECTED
;
2468 visibility
= DEBUG_VISIBILITY_PUBLIC
;
2478 /* Normal function. */
2482 /* const member function. */
2487 /* volatile member function. */
2492 /* const volatile member function. */
2500 /* File compiled with g++ version 1; no information. */
2503 warn_stab (orig
, "const/volatile indicator missing");
2511 /* virtual member function, followed by index. The sign
2512 bit is set to distinguish pointers-to-methods from
2513 virtual function indicies. Since the array is in
2514 words, the quantity must be shifted left by 1 on 16
2515 bit machine, and by 2 on 32 bit machine, forcing the
2516 sign bit out, and usable as a valid index into the
2517 array. Remove the sign bit here. */
2519 voffset
= parse_number (pp
, (boolean
*) NULL
);
2526 voffset
&= 0x7fffffff;
2529 if (**pp
== ';' || *pp
== '\0')
2531 /* Must be g++ version 1. */
2532 context
= DEBUG_TYPE_NULL
;
2536 /* Figure out from whence this virtual function
2537 came. It may belong to virtual function table of
2538 one of its baseclasses. */
2539 look_ahead_type
= parse_stab_type (dhandle
, info
, pp
,
2540 (debug_type
**) NULL
);
2543 /* g++ version 1 overloaded methods. */
2547 context
= look_ahead_type
;
2548 look_ahead_type
= DEBUG_TYPE_NULL
;
2560 /* static member function. */
2564 /* FIXME: gdb sets is_stub here. */
2565 context
= DEBUG_TYPE_NULL
;
2569 warn_stab (orig
, "member function type missing");
2571 context
= DEBUG_TYPE_NULL
;
2577 context
= DEBUG_TYPE_NULL
;
2581 if (cvars
+ 1 >= allocvars
)
2584 variants
= ((debug_method_variant
*)
2585 xrealloc ((PTR
) variants
,
2586 allocvars
* sizeof *variants
));
2590 variants
[cvars
] = debug_make_method_variant (dhandle
, argtypes
,
2595 variants
[cvars
] = debug_make_static_method_variant (dhandle
,
2601 if (variants
[cvars
] == DEBUG_METHOD_VARIANT_NULL
)
2606 while (**pp
!= ';' && **pp
!= '\0');
2608 variants
[cvars
] = DEBUG_METHOD_VARIANT_NULL
;
2616 methods
= ((debug_method
*)
2617 xrealloc ((PTR
) methods
, alloc
* sizeof *methods
));
2620 methods
[c
] = debug_make_method (dhandle
, name
, variants
);
2625 if (methods
!= NULL
)
2626 methods
[c
] = DEBUG_METHOD_NULL
;
2633 /* The tail end of stabs for C++ classes that contain a virtual function
2634 pointer contains a tilde, a %, and a type number.
2635 The type number refers to the base class (possibly this class itself) which
2636 contains the vtable pointer for the current class.
2638 This function is called when we have parsed all the method declarations,
2639 so we can look for the vptr base class info. */
2642 parse_stab_tilde_field (dhandle
, info
, pp
, typenums
, retvptrbase
, retownvptr
)
2644 struct stab_handle
*info
;
2646 const int *typenums
;
2647 debug_type
*retvptrbase
;
2648 boolean
*retownvptr
;
2654 *retvptrbase
= DEBUG_TYPE_NULL
;
2655 *retownvptr
= false;
2659 /* If we are positioned at a ';', then skip it. */
2668 if (**pp
== '=' || **pp
== '+' || **pp
== '-')
2670 /* Obsolete flags that used to indicate the presence of
2671 constructors and/or destructors. */
2682 /* The next number is the type number of the base class (possibly
2683 our own class) which supplies the vtable for this class. */
2684 if (! parse_stab_type_number (pp
, vtypenums
))
2687 if (vtypenums
[0] == typenums
[0]
2688 && vtypenums
[1] == typenums
[1])
2697 vtype
= parse_stab_type (dhandle
, info
, pp
, (debug_type
**) NULL
);
2698 for (p
= *pp
; *p
!= ';' && *p
!= '\0'; p
++)
2706 *retvptrbase
= vtype
;
2714 /* Read a definition of an array type. */
2717 parse_stab_array_type (dhandle
, info
, pp
, stringp
)
2719 struct stab_handle
*info
;
2724 debug_type index_type
;
2726 bfd_signed_vma lower
, upper
;
2727 debug_type element_type
;
2729 /* Format of an array type:
2730 "ar<index type>;lower;upper;<array_contents_type>".
2731 OS9000: "arlower,upper;<array_contents_type>".
2733 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
2734 for these, produce a type like float[][]. */
2738 /* FIXME: gdb checks os9k_stabs here. */
2740 index_type
= parse_stab_type (dhandle
, info
, pp
, (debug_type
**) NULL
);
2744 return DEBUG_TYPE_NULL
;
2750 if (! isdigit ((unsigned char) **pp
) && **pp
!= '-')
2756 lower
= (bfd_signed_vma
) parse_number (pp
, (boolean
*) NULL
);
2764 if (! isdigit ((unsigned char) **pp
) && **pp
!= '-')
2770 upper
= (bfd_signed_vma
) parse_number (pp
, (boolean
*) NULL
);
2778 element_type
= parse_stab_type (dhandle
, info
, pp
, (debug_type
**) NULL
);
2779 if (element_type
== DEBUG_TYPE_NULL
)
2788 return debug_make_array_type (dhandle
, element_type
, index_type
, lower
,
2792 /* Keep a stack of N_BINCL include files. */
2796 struct bincl_file
*next
;
2800 /* Start a new N_BINCL file, pushing it onto the stack. */
2803 push_bincl (info
, name
)
2804 struct stab_handle
*info
;
2807 struct bincl_file
*n
;
2809 n
= (struct bincl_file
*) xmalloc (sizeof *n
);
2810 n
->next
= info
->bincl_stack
;
2812 info
->bincl_stack
= n
;
2815 info
->file_types
= ((struct stab_types
**)
2816 xrealloc ((PTR
) info
->file_types
,
2818 * sizeof *info
->file_types
)));
2819 info
->file_types
[info
->files
- 1] = NULL
;
2822 /* Finish an N_BINCL file, at an N_EINCL, popping the name off the
2827 struct stab_handle
*info
;
2829 struct bincl_file
*o
;
2831 o
= info
->bincl_stack
;
2833 return info
->main_filename
;
2834 info
->bincl_stack
= o
->next
;
2836 if (info
->bincl_stack
== NULL
)
2837 return info
->main_filename
;
2838 return info
->bincl_stack
->name
;
2841 /* Handle a variable definition. gcc emits variable definitions for a
2842 block before the N_LBRAC, so we must hold onto them until we see
2843 it. The SunPRO compiler emits variable definitions after the
2844 N_LBRAC, so we can call debug_record_variable immediately. */
2847 stab_record_variable (dhandle
, info
, name
, type
, kind
, val
)
2849 struct stab_handle
*info
;
2852 enum debug_var_kind kind
;
2855 struct stab_pending_var
*v
;
2857 if (! info
->within_function
2858 || (info
->gcc_compiled
== 0 && info
->n_opt_found
))
2859 return debug_record_variable (dhandle
, name
, type
, kind
, val
);
2861 v
= (struct stab_pending_var
*) xmalloc (sizeof *v
);
2862 memset (v
, 0, sizeof *v
);
2864 v
->next
= info
->pending
;
2874 /* Emit pending variable definitions. This is called after we see the
2875 N_LBRAC that starts the block. */
2878 stab_emit_pending_vars (dhandle
, info
)
2880 struct stab_handle
*info
;
2882 struct stab_pending_var
*v
;
2887 struct stab_pending_var
*next
;
2889 if (! debug_record_variable (dhandle
, v
->name
, v
->type
, v
->kind
, v
->val
))
2897 info
->pending
= NULL
;
2902 /* Find the slot for a type in the database. */
2905 stab_find_slot (info
, typenums
)
2906 struct stab_handle
*info
;
2907 const int *typenums
;
2911 struct stab_types
**ps
;
2913 filenum
= typenums
[0];
2914 index
= typenums
[1];
2916 if (filenum
< 0 || (unsigned int) filenum
>= info
->files
)
2918 fprintf (stderr
, "Type file number %d out of range\n", filenum
);
2923 fprintf (stderr
, "Type index number %d out of range\n", index
);
2927 ps
= info
->file_types
+ filenum
;
2929 while (index
>= STAB_TYPES_SLOTS
)
2933 *ps
= (struct stab_types
*) xmalloc (sizeof **ps
);
2934 memset (*ps
, 0, sizeof **ps
);
2937 index
-= STAB_TYPES_SLOTS
;
2941 *ps
= (struct stab_types
*) xmalloc (sizeof **ps
);
2942 memset (*ps
, 0, sizeof **ps
);
2945 return (*ps
)->types
+ index
;
2948 /* Find a type given a type number. If the type has not been
2949 allocated yet, create an indirect type. */
2952 stab_find_type (dhandle
, info
, typenums
)
2954 struct stab_handle
*info
;
2955 const int *typenums
;
2959 if (typenums
[0] == 0 && typenums
[1] < 0)
2961 /* A negative type number indicates an XCOFF builtin type. */
2962 return stab_xcoff_builtin_type (dhandle
, info
, typenums
[1]);
2965 slot
= stab_find_slot (info
, typenums
);
2967 return DEBUG_TYPE_NULL
;
2969 if (*slot
== DEBUG_TYPE_NULL
)
2970 return debug_make_indirect_type (dhandle
, slot
, (const char *) NULL
);
2975 /* Record that a given type number refers to a given type. */
2978 stab_record_type (dhandle
, info
, typenums
, type
)
2980 struct stab_handle
*info
;
2981 const int *typenums
;
2986 slot
= stab_find_slot (info
, typenums
);
2990 /* gdb appears to ignore type redefinitions, so we do as well. */
2997 /* Return an XCOFF builtin type. */
3000 stab_xcoff_builtin_type (dhandle
, info
, typenum
)
3002 struct stab_handle
*info
;
3008 if (typenum
>= 0 || typenum
< -XCOFF_TYPE_COUNT
)
3010 fprintf (stderr
, "Unrecognized XCOFF type %d\n", typenum
);
3011 return DEBUG_TYPE_NULL
;
3013 if (info
->xcoff_types
[-typenum
] != NULL
)
3014 return info
->xcoff_types
[-typenum
];
3019 /* The size of this and all the other types are fixed, defined
3020 by the debugging format. */
3022 rettype
= debug_make_int_type (dhandle
, 4, false);
3026 rettype
= debug_make_int_type (dhandle
, 1, false);
3030 rettype
= debug_make_int_type (dhandle
, 2, false);
3034 rettype
= debug_make_int_type (dhandle
, 4, false);
3037 name
= "unsigned char";
3038 rettype
= debug_make_int_type (dhandle
, 1, true);
3041 name
= "signed char";
3042 rettype
= debug_make_int_type (dhandle
, 1, false);
3045 name
= "unsigned short";
3046 rettype
= debug_make_int_type (dhandle
, 2, true);
3049 name
= "unsigned int";
3050 rettype
= debug_make_int_type (dhandle
, 4, true);
3054 rettype
= debug_make_int_type (dhandle
, 4, true);
3056 name
= "unsigned long";
3057 rettype
= debug_make_int_type (dhandle
, 4, true);
3061 rettype
= debug_make_void_type (dhandle
);
3064 /* IEEE single precision (32 bit). */
3066 rettype
= debug_make_float_type (dhandle
, 4);
3069 /* IEEE double precision (64 bit). */
3071 rettype
= debug_make_float_type (dhandle
, 8);
3074 /* This is an IEEE double on the RS/6000, and different machines
3075 with different sizes for "long double" should use different
3076 negative type numbers. See stabs.texinfo. */
3077 name
= "long double";
3078 rettype
= debug_make_float_type (dhandle
, 8);
3082 rettype
= debug_make_int_type (dhandle
, 4, false);
3086 rettype
= debug_make_bool_type (dhandle
, 4);
3089 name
= "short real";
3090 rettype
= debug_make_float_type (dhandle
, 4);
3094 rettype
= debug_make_float_type (dhandle
, 8);
3104 rettype
= debug_make_int_type (dhandle
, 1, true);
3108 rettype
= debug_make_bool_type (dhandle
, 1);
3112 rettype
= debug_make_bool_type (dhandle
, 2);
3116 rettype
= debug_make_bool_type (dhandle
, 4);
3120 rettype
= debug_make_bool_type (dhandle
, 4);
3123 /* Complex type consisting of two IEEE single precision values. */
3125 rettype
= debug_make_complex_type (dhandle
, 8);
3128 /* Complex type consisting of two IEEE double precision values. */
3129 name
= "double complex";
3130 rettype
= debug_make_complex_type (dhandle
, 16);
3134 rettype
= debug_make_int_type (dhandle
, 1, false);
3138 rettype
= debug_make_int_type (dhandle
, 2, false);
3142 rettype
= debug_make_int_type (dhandle
, 4, false);
3147 rettype
= debug_make_int_type (dhandle
, 2, false);
3151 rettype
= debug_make_int_type (dhandle
, 8, false);
3154 name
= "unsigned long long";
3155 rettype
= debug_make_int_type (dhandle
, 8, true);
3159 rettype
= debug_make_bool_type (dhandle
, 8);
3163 rettype
= debug_make_int_type (dhandle
, 8, false);
3169 rettype
= debug_name_type (dhandle
, name
, rettype
);
3171 info
->xcoff_types
[-typenum
] = rettype
;