1 /* ieee.c -- Read and write IEEE-695 debugging information.
2 Copyright 1996, 1998, 1999, 2000, 2001, 2002, 2003, 2005, 2006, 2007,
3 2008, 2009, 2010, 2011 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 3 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., 51 Franklin Street - Fifth Floor, Boston, MA
23 /* This file reads and writes IEEE-695 debugging information. */
29 #include "libiberty.h"
32 #include "filenames.h"
34 /* This structure holds an entry on the block stack. */
38 /* The kind of block. */
40 /* The source file name, for a BB5 block. */
42 /* The index of the function type, for a BB4 or BB6 block. */
44 /* TRUE if this function is being skipped. */
48 /* This structure is the block stack. */
50 #define BLOCKSTACK_SIZE (16)
52 struct ieee_blockstack
54 /* The stack pointer. */
55 struct ieee_block *bsp;
57 struct ieee_block stack[BLOCKSTACK_SIZE];
60 /* This structure holds information for a variable. */
80 /* Slot if we make an indirect type. */
82 /* Kind of variable or function. */
83 enum ieee_var_kind kind;
86 /* This structure holds all the variables. */
90 /* Number of slots allocated. */
93 struct ieee_var *vars;
96 /* This structure holds information for a type. We need this because
97 we don't want to represent bitfields as real types. */
103 /* Slot if this is type is referenced before it is defined. */
105 /* Slots for arguments if we make indirect types for them. */
106 debug_type *arg_slots;
107 /* If this is a bitfield, this is the size in bits. If this is not
108 a bitfield, this is zero. */
109 unsigned long bitsize;
112 /* This structure holds all the type information. */
116 /* Number of slots allocated. */
119 struct ieee_type *types;
121 #define BUILTIN_TYPE_COUNT (60)
122 debug_type builtins[BUILTIN_TYPE_COUNT];
125 /* This structure holds a linked last of structs with their tag names,
126 so that we can convert them to C++ classes if necessary. */
131 struct ieee_tag *next;
134 /* The type of the tag. */
136 /* The tagged type is an indirect type pointing at this slot. */
138 /* This is an array of slots used when a field type is converted
139 into a indirect type, in case it needs to be later converted into
144 /* This structure holds the information we pass around to the parsing
149 /* The debugging handle. */
153 /* The start of the bytes to be parsed. */
154 const bfd_byte *bytes;
155 /* The end of the bytes to be parsed. */
156 const bfd_byte *pend;
157 /* The block stack. */
158 struct ieee_blockstack blockstack;
159 /* Whether we have seen a BB1 or BB2. */
160 bfd_boolean saw_filename;
162 struct ieee_vars vars;
163 /* The global variables, after a global typedef block. */
164 struct ieee_vars *global_vars;
166 struct ieee_types types;
167 /* The global types, after a global typedef block. */
168 struct ieee_types *global_types;
169 /* The list of tagged structs. */
170 struct ieee_tag *tags;
173 /* Basic builtin types, not including the pointers. */
179 builtin_signed_char = 2,
180 builtin_unsigned_char = 3,
181 builtin_signed_short_int = 4,
182 builtin_unsigned_short_int = 5,
183 builtin_signed_long = 6,
184 builtin_unsigned_long = 7,
185 builtin_signed_long_long = 8,
186 builtin_unsigned_long_long = 9,
189 builtin_long_double = 12,
190 builtin_long_long_double = 13,
191 builtin_quoted_string = 14,
192 builtin_instruction_address = 15,
194 builtin_unsigned = 17,
195 builtin_unsigned_int = 18,
199 builtin_unsigned_short = 22,
200 builtin_short_int = 23,
201 builtin_signed_short = 24,
202 builtin_bcd_float = 25
205 /* These are the values found in the derivation flags of a 'b'
206 component record of a 'T' type extension record in a C++ pmisc
207 record. These are bitmasks. */
209 /* Set for a private base class, clear for a public base class.
210 Protected base classes are not supported. */
211 #define BASEFLAGS_PRIVATE (0x1)
212 /* Set for a virtual base class. */
213 #define BASEFLAGS_VIRTUAL (0x2)
214 /* Set for a friend class, clear for a base class. */
215 #define BASEFLAGS_FRIEND (0x10)
217 /* These are the values found in the specs flags of a 'd', 'm', or 'v'
218 component record of a 'T' type extension record in a C++ pmisc
219 record. The same flags are used for a 'M' record in a C++ pmisc
222 /* The lower two bits hold visibility information. */
223 #define CXXFLAGS_VISIBILITY (0x3)
224 /* This value in the lower two bits indicates a public member. */
225 #define CXXFLAGS_VISIBILITY_PUBLIC (0x0)
226 /* This value in the lower two bits indicates a private member. */
227 #define CXXFLAGS_VISIBILITY_PRIVATE (0x1)
228 /* This value in the lower two bits indicates a protected member. */
229 #define CXXFLAGS_VISIBILITY_PROTECTED (0x2)
230 /* Set for a static member. */
231 #define CXXFLAGS_STATIC (0x4)
232 /* Set for a virtual override. */
233 #define CXXFLAGS_OVERRIDE (0x8)
234 /* Set for a friend function. */
235 #define CXXFLAGS_FRIEND (0x10)
236 /* Set for a const function. */
237 #define CXXFLAGS_CONST (0x20)
238 /* Set for a volatile function. */
239 #define CXXFLAGS_VOLATILE (0x40)
240 /* Set for an overloaded function. */
241 #define CXXFLAGS_OVERLOADED (0x80)
242 /* Set for an operator function. */
243 #define CXXFLAGS_OPERATOR (0x100)
244 /* Set for a constructor or destructor. */
245 #define CXXFLAGS_CTORDTOR (0x400)
246 /* Set for a constructor. */
247 #define CXXFLAGS_CTOR (0x200)
248 /* Set for an inline function. */
249 #define CXXFLAGS_INLINE (0x800)
251 /* Local functions. */
253 static void ieee_error (struct ieee_info *, const bfd_byte *, const char *);
254 static void ieee_eof (struct ieee_info *);
255 static char *savestring (const char *, unsigned long);
256 static bfd_boolean ieee_read_number
257 (struct ieee_info *, const bfd_byte **, bfd_vma *);
258 static bfd_boolean ieee_read_optional_number
259 (struct ieee_info *, const bfd_byte **, bfd_vma *, bfd_boolean *);
260 static bfd_boolean ieee_read_id
261 (struct ieee_info *, const bfd_byte **, const char **, unsigned long *);
262 static bfd_boolean ieee_read_optional_id
263 (struct ieee_info *, const bfd_byte **, const char **, unsigned long *,
265 static bfd_boolean ieee_read_expression
266 (struct ieee_info *, const bfd_byte **, bfd_vma *);
267 static debug_type ieee_builtin_type
268 (struct ieee_info *, const bfd_byte *, unsigned int);
269 static bfd_boolean ieee_alloc_type
270 (struct ieee_info *, unsigned int, bfd_boolean);
271 static bfd_boolean ieee_read_type_index
272 (struct ieee_info *, const bfd_byte **, debug_type *);
273 static int ieee_regno_to_genreg (bfd *, int);
274 static int ieee_genreg_to_regno (bfd *, int);
275 static bfd_boolean parse_ieee_bb (struct ieee_info *, const bfd_byte **);
276 static bfd_boolean parse_ieee_be (struct ieee_info *, const bfd_byte **);
277 static bfd_boolean parse_ieee_nn (struct ieee_info *, const bfd_byte **);
278 static bfd_boolean parse_ieee_ty (struct ieee_info *, const bfd_byte **);
279 static bfd_boolean parse_ieee_atn (struct ieee_info *, const bfd_byte **);
280 static bfd_boolean ieee_read_cxx_misc
281 (struct ieee_info *, const bfd_byte **, unsigned long);
282 static bfd_boolean ieee_read_cxx_class
283 (struct ieee_info *, const bfd_byte **, unsigned long);
284 static bfd_boolean ieee_read_cxx_defaults
285 (struct ieee_info *, const bfd_byte **, unsigned long);
286 static bfd_boolean ieee_read_reference
287 (struct ieee_info *, const bfd_byte **);
288 static bfd_boolean ieee_require_asn
289 (struct ieee_info *, const bfd_byte **, bfd_vma *);
290 static bfd_boolean ieee_require_atn65
291 (struct ieee_info *, const bfd_byte **, const char **, unsigned long *);
293 /* Report an error in the IEEE debugging information. */
296 ieee_error (struct ieee_info *info, const bfd_byte *p, const char *s)
299 fprintf (stderr, "%s: 0x%lx: %s (0x%x)\n", bfd_get_filename (info->abfd),
300 (unsigned long) (p - info->bytes), s, *p);
302 fprintf (stderr, "%s: %s\n", bfd_get_filename (info->abfd), s);
305 /* Report an unexpected EOF in the IEEE debugging information. */
308 ieee_eof (struct ieee_info *info)
310 ieee_error (info, (const bfd_byte *) NULL,
311 _("unexpected end of debugging information"));
314 /* Save a string in memory. */
317 savestring (const char *start, unsigned long len)
321 ret = (char *) xmalloc (len + 1);
322 memcpy (ret, start, len);
327 /* Read a number which must be present in an IEEE file. */
330 ieee_read_number (struct ieee_info *info, const bfd_byte **pp, bfd_vma *pv)
332 return ieee_read_optional_number (info, pp, pv, (bfd_boolean *) NULL);
335 /* Read a number in an IEEE file. If ppresent is not NULL, the number
336 need not be there. */
339 ieee_read_optional_number (struct ieee_info *info, const bfd_byte **pp,
340 bfd_vma *pv, bfd_boolean *ppresent)
342 ieee_record_enum_type b;
344 if (*pp >= info->pend)
346 if (ppresent != NULL)
355 b = (ieee_record_enum_type) **pp;
358 if (b <= ieee_number_end_enum)
361 if (ppresent != NULL)
366 if (b >= ieee_number_repeat_start_enum && b <= ieee_number_repeat_end_enum)
370 i = (int) b - (int) ieee_number_repeat_start_enum;
371 if (*pp + i - 1 >= info->pend)
385 if (ppresent != NULL)
391 if (ppresent != NULL)
398 ieee_error (info, *pp - 1, _("invalid number"));
402 /* Read a required string from an IEEE file. */
405 ieee_read_id (struct ieee_info *info, const bfd_byte **pp,
406 const char **pname, unsigned long *pnamlen)
408 return ieee_read_optional_id (info, pp, pname, pnamlen, (bfd_boolean *) NULL);
411 /* Read a string from an IEEE file. If ppresent is not NULL, the
412 string is optional. */
415 ieee_read_optional_id (struct ieee_info *info, const bfd_byte **pp,
416 const char **pname, unsigned long *pnamlen,
417 bfd_boolean *ppresent)
422 if (*pp >= info->pend)
433 else if ((ieee_record_enum_type) b == ieee_extension_length_1_enum)
438 else if ((ieee_record_enum_type) b == ieee_extension_length_2_enum)
440 len = (**pp << 8) + (*pp)[1];
445 if (ppresent != NULL)
451 ieee_error (info, *pp - 1, _("invalid string length"));
455 if ((unsigned long) (info->pend - *pp) < len)
461 *pname = (const char *) *pp;
465 if (ppresent != NULL)
471 /* Read an expression from an IEEE file. Since this code is only used
472 to parse debugging information, I haven't bothered to write a full
473 blown IEEE expression parser. I've only thrown in the things I've
474 seen in debugging information. This can be easily extended if
478 ieee_read_expression (struct ieee_info *info, const bfd_byte **pp,
481 const bfd_byte *expr_start;
482 #define EXPR_STACK_SIZE (10)
483 bfd_vma expr_stack[EXPR_STACK_SIZE];
492 const bfd_byte *start;
495 ieee_record_enum_type c;
499 if (! ieee_read_optional_number (info, pp, &val, &present))
504 if (esp - expr_stack >= EXPR_STACK_SIZE)
506 ieee_error (info, start, _("expression stack overflow"));
513 c = (ieee_record_enum_type) **pp;
515 if (c >= ieee_module_beginning_enum)
526 ieee_error (info, start, _("unsupported IEEE expression operator"));
529 case ieee_variable_R_enum:
534 if (! ieee_read_number (info, pp, &indx))
536 for (s = info->abfd->sections; s != NULL; s = s->next)
537 if ((bfd_vma) s->target_index == indx)
541 ieee_error (info, start, _("unknown section"));
545 if (esp - expr_stack >= EXPR_STACK_SIZE)
547 ieee_error (info, start, _("expression stack overflow"));
551 *esp++ = bfd_get_section_vma (info->abfd, s);
555 case ieee_function_plus_enum:
556 case ieee_function_minus_enum:
560 if (esp - expr_stack < 2)
562 ieee_error (info, start, _("expression stack underflow"));
574 if (esp - 1 != expr_stack)
576 ieee_error (info, expr_start, _("expression stack mismatch"));
585 /* Return an IEEE builtin type. */
588 ieee_builtin_type (struct ieee_info *info, const bfd_byte *p,
595 if (indx < BUILTIN_TYPE_COUNT
596 && info->types.builtins[indx] != DEBUG_TYPE_NULL)
597 return info->types.builtins[indx];
599 dhandle = info->dhandle;
601 if (indx >= 32 && indx < 64)
603 type = debug_make_pointer_type (dhandle,
604 ieee_builtin_type (info, p, indx - 32));
605 assert (indx < BUILTIN_TYPE_COUNT);
606 info->types.builtins[indx] = type;
610 switch ((enum builtin_types) indx)
613 ieee_error (info, p, _("unknown builtin type"));
616 case builtin_unknown:
617 type = debug_make_void_type (dhandle);
622 type = debug_make_void_type (dhandle);
626 case builtin_signed_char:
627 type = debug_make_int_type (dhandle, 1, FALSE);
628 name = "signed char";
631 case builtin_unsigned_char:
632 type = debug_make_int_type (dhandle, 1, TRUE);
633 name = "unsigned char";
636 case builtin_signed_short_int:
637 type = debug_make_int_type (dhandle, 2, FALSE);
638 name = "signed short int";
641 case builtin_unsigned_short_int:
642 type = debug_make_int_type (dhandle, 2, TRUE);
643 name = "unsigned short int";
646 case builtin_signed_long:
647 type = debug_make_int_type (dhandle, 4, FALSE);
648 name = "signed long";
651 case builtin_unsigned_long:
652 type = debug_make_int_type (dhandle, 4, TRUE);
653 name = "unsigned long";
656 case builtin_signed_long_long:
657 type = debug_make_int_type (dhandle, 8, FALSE);
658 name = "signed long long";
661 case builtin_unsigned_long_long:
662 type = debug_make_int_type (dhandle, 8, TRUE);
663 name = "unsigned long long";
667 type = debug_make_float_type (dhandle, 4);
672 type = debug_make_float_type (dhandle, 8);
676 case builtin_long_double:
677 /* FIXME: The size for this type should depend upon the
679 type = debug_make_float_type (dhandle, 12);
680 name = "long double";
683 case builtin_long_long_double:
684 type = debug_make_float_type (dhandle, 16);
685 name = "long long double";
688 case builtin_quoted_string:
689 type = debug_make_array_type (dhandle,
690 ieee_builtin_type (info, p,
693 ieee_builtin_type (info, p,
697 name = "QUOTED STRING";
700 case builtin_instruction_address:
701 /* FIXME: This should be a code address. */
702 type = debug_make_int_type (dhandle, 4, TRUE);
703 name = "instruction address";
707 /* FIXME: The size for this type should depend upon the
709 type = debug_make_int_type (dhandle, 4, FALSE);
713 case builtin_unsigned:
714 /* FIXME: The size for this type should depend upon the
716 type = debug_make_int_type (dhandle, 4, TRUE);
720 case builtin_unsigned_int:
721 /* FIXME: The size for this type should depend upon the
723 type = debug_make_int_type (dhandle, 4, TRUE);
724 name = "unsigned int";
728 type = debug_make_int_type (dhandle, 1, FALSE);
733 type = debug_make_int_type (dhandle, 4, FALSE);
738 type = debug_make_int_type (dhandle, 2, FALSE);
742 case builtin_unsigned_short:
743 type = debug_make_int_type (dhandle, 2, TRUE);
744 name = "unsigned short";
747 case builtin_short_int:
748 type = debug_make_int_type (dhandle, 2, FALSE);
752 case builtin_signed_short:
753 type = debug_make_int_type (dhandle, 2, FALSE);
754 name = "signed short";
757 case builtin_bcd_float:
758 ieee_error (info, p, _("BCD float type not supported"));
759 return DEBUG_TYPE_NULL;
763 type = debug_name_type (dhandle, name, type);
765 assert (indx < BUILTIN_TYPE_COUNT);
767 info->types.builtins[indx] = type;
772 /* Allocate more space in the type table. If ref is TRUE, this is a
773 reference to the type; if it is not already defined, we should set
774 up an indirect type. */
777 ieee_alloc_type (struct ieee_info *info, unsigned int indx, bfd_boolean ref)
780 register struct ieee_type *t;
781 struct ieee_type *tend;
783 if (indx >= info->types.alloc)
785 nalloc = info->types.alloc;
788 while (indx >= nalloc)
791 info->types.types = ((struct ieee_type *)
792 xrealloc (info->types.types,
793 nalloc * sizeof *info->types.types));
795 memset (info->types.types + info->types.alloc, 0,
796 (nalloc - info->types.alloc) * sizeof *info->types.types);
798 tend = info->types.types + nalloc;
799 for (t = info->types.types + info->types.alloc; t < tend; t++)
800 t->type = DEBUG_TYPE_NULL;
802 info->types.alloc = nalloc;
807 t = info->types.types + indx;
810 t->pslot = (debug_type *) xmalloc (sizeof *t->pslot);
811 *t->pslot = DEBUG_TYPE_NULL;
812 t->type = debug_make_indirect_type (info->dhandle, t->pslot,
813 (const char *) NULL);
822 /* Read a type index and return the corresponding type. */
825 ieee_read_type_index (struct ieee_info *info, const bfd_byte **pp,
828 const bfd_byte *start;
833 if (! ieee_read_number (info, pp, &indx))
838 *ptype = ieee_builtin_type (info, start, indx);
845 if (! ieee_alloc_type (info, indx, TRUE))
848 *ptype = info->types.types[indx].type;
853 /* Parse IEEE debugging information for a file. This is passed the
854 bytes which compose the Debug Information Part of an IEEE file. */
857 parse_ieee (void *dhandle, bfd *abfd, const bfd_byte *bytes, bfd_size_type len)
859 struct ieee_info info;
861 const bfd_byte *p, *pend;
863 info.dhandle = dhandle;
866 info.pend = bytes + len;
867 info.blockstack.bsp = info.blockstack.stack;
868 info.saw_filename = FALSE;
870 info.vars.vars = NULL;
871 info.global_vars = NULL;
872 info.types.alloc = 0;
873 info.types.types = NULL;
874 info.global_types = NULL;
876 for (i = 0; i < BUILTIN_TYPE_COUNT; i++)
877 info.types.builtins[i] = DEBUG_TYPE_NULL;
883 const bfd_byte *record_start;
884 ieee_record_enum_type c;
888 c = (ieee_record_enum_type) *p++;
890 if (c == ieee_at_record_enum)
891 c = (ieee_record_enum_type) (((unsigned int) c << 8) | *p++);
893 if (c <= ieee_number_repeat_end_enum)
895 ieee_error (&info, record_start, _("unexpected number"));
902 ieee_error (&info, record_start, _("unexpected record type"));
905 case ieee_bb_record_enum:
906 if (! parse_ieee_bb (&info, &p))
910 case ieee_be_record_enum:
911 if (! parse_ieee_be (&info, &p))
916 if (! parse_ieee_nn (&info, &p))
920 case ieee_ty_record_enum:
921 if (! parse_ieee_ty (&info, &p))
925 case ieee_atn_record_enum:
926 if (! parse_ieee_atn (&info, &p))
932 if (info.blockstack.bsp != info.blockstack.stack)
934 ieee_error (&info, (const bfd_byte *) NULL,
935 _("blocks left on stack at end"));
942 /* Handle an IEEE BB record. */
945 parse_ieee_bb (struct ieee_info *info, const bfd_byte **pp)
947 const bfd_byte *block_start;
951 unsigned long namlen;
952 char *namcopy = NULL;
961 if (! ieee_read_number (info, pp, &size)
962 || ! ieee_read_id (info, pp, &name, &namlen))
965 fnindx = (unsigned int) -1;
971 /* BB1: Type definitions local to a module. */
972 namcopy = savestring (name, namlen);
975 if (! debug_set_filename (info->dhandle, namcopy))
977 info->saw_filename = TRUE;
979 /* Discard any variables or types we may have seen before. */
980 if (info->vars.vars != NULL)
981 free (info->vars.vars);
982 info->vars.vars = NULL;
983 info->vars.alloc = 0;
984 if (info->types.types != NULL)
985 free (info->types.types);
986 info->types.types = NULL;
987 info->types.alloc = 0;
989 /* Initialize the types to the global types. */
990 if (info->global_types != NULL)
992 info->types.alloc = info->global_types->alloc;
993 info->types.types = ((struct ieee_type *)
994 xmalloc (info->types.alloc
995 * sizeof (*info->types.types)));
996 memcpy (info->types.types, info->global_types->types,
997 info->types.alloc * sizeof (*info->types.types));
1003 /* BB2: Global type definitions. The name is supposed to be
1004 empty, but we don't check. */
1005 if (! debug_set_filename (info->dhandle, "*global*"))
1007 info->saw_filename = TRUE;
1011 /* BB3: High level module block begin. We don't have to do
1012 anything here. The name is supposed to be the same as for
1013 the BB1, but we don't check. */
1017 /* BB4: Global function. */
1019 bfd_vma stackspace, typindx, offset;
1020 debug_type return_type;
1022 if (! ieee_read_number (info, pp, &stackspace)
1023 || ! ieee_read_number (info, pp, &typindx)
1024 || ! ieee_read_expression (info, pp, &offset))
1027 /* We have no way to record the stack space. FIXME. */
1031 return_type = ieee_builtin_type (info, block_start, typindx);
1032 if (return_type == DEBUG_TYPE_NULL)
1038 if (! ieee_alloc_type (info, typindx, TRUE))
1041 return_type = info->types.types[typindx].type;
1042 if (debug_get_type_kind (info->dhandle, return_type)
1043 == DEBUG_KIND_FUNCTION)
1044 return_type = debug_get_return_type (info->dhandle,
1048 namcopy = savestring (name, namlen);
1049 if (namcopy == NULL)
1051 if (! debug_record_function (info->dhandle, namcopy, return_type,
1058 /* BB5: File name for source line numbers. */
1062 /* We ignore the date and time. FIXME. */
1063 for (i = 0; i < 6; i++)
1066 bfd_boolean present;
1068 if (! ieee_read_optional_number (info, pp, &ignore, &present))
1074 if (! info->saw_filename)
1076 namcopy = savestring (name, namlen);
1077 if (namcopy == NULL)
1079 if (! debug_set_filename (info->dhandle, namcopy))
1081 info->saw_filename = TRUE;
1084 namcopy = savestring (name, namlen);
1085 if (namcopy == NULL)
1087 if (! debug_start_source (info->dhandle, namcopy))
1093 /* BB6: Local function or block. */
1095 bfd_vma stackspace, typindx, offset;
1097 if (! ieee_read_number (info, pp, &stackspace)
1098 || ! ieee_read_number (info, pp, &typindx)
1099 || ! ieee_read_expression (info, pp, &offset))
1102 /* We have no way to record the stack space. FIXME. */
1106 if (! debug_start_block (info->dhandle, offset))
1108 /* Change b to indicate that this is a block
1109 rather than a function. */
1114 /* The MRI C++ compiler will output a fake function named
1115 __XRYCPP to hold C++ debugging information. We skip
1116 that function. This is not crucial, but it makes
1117 converting from IEEE to other debug formats work
1119 if (strncmp (name, "__XRYCPP", namlen) == 0)
1123 debug_type return_type;
1127 return_type = ieee_builtin_type (info, block_start,
1129 if (return_type == NULL)
1135 if (! ieee_alloc_type (info, typindx, TRUE))
1138 return_type = info->types.types[typindx].type;
1139 if (debug_get_type_kind (info->dhandle, return_type)
1140 == DEBUG_KIND_FUNCTION)
1141 return_type = debug_get_return_type (info->dhandle,
1145 namcopy = savestring (name, namlen);
1146 if (namcopy == NULL)
1148 if (! debug_record_function (info->dhandle, namcopy,
1149 return_type, FALSE, offset))
1157 /* BB10: Assembler module scope. In the normal case, we
1158 completely ignore all this information. FIXME. */
1160 const char *inam, *vstr;
1161 unsigned long inamlen, vstrlen;
1163 bfd_boolean present;
1166 if (! info->saw_filename)
1168 namcopy = savestring (name, namlen);
1169 if (namcopy == NULL)
1171 if (! debug_set_filename (info->dhandle, namcopy))
1173 info->saw_filename = TRUE;
1176 if (! ieee_read_id (info, pp, &inam, &inamlen)
1177 || ! ieee_read_number (info, pp, &tool_type)
1178 || ! ieee_read_optional_id (info, pp, &vstr, &vstrlen, &present))
1180 for (i = 0; i < 6; i++)
1184 if (! ieee_read_optional_number (info, pp, &ignore, &present))
1193 /* BB11: Module section. We completely ignore all this
1194 information. FIXME. */
1196 bfd_vma sectype, secindx, offset, map;
1197 bfd_boolean present;
1199 if (! ieee_read_number (info, pp, §ype)
1200 || ! ieee_read_number (info, pp, &secindx)
1201 || ! ieee_read_expression (info, pp, &offset)
1202 || ! ieee_read_optional_number (info, pp, &map, &present))
1208 ieee_error (info, block_start, _("unknown BB type"));
1213 /* Push this block on the block stack. */
1215 if (info->blockstack.bsp >= info->blockstack.stack + BLOCKSTACK_SIZE)
1217 ieee_error (info, (const bfd_byte *) NULL, _("stack overflow"));
1221 info->blockstack.bsp->kind = b;
1223 info->blockstack.bsp->filename = namcopy;
1224 info->blockstack.bsp->fnindx = fnindx;
1225 info->blockstack.bsp->skip = skip;
1226 ++info->blockstack.bsp;
1231 /* Handle an IEEE BE record. */
1234 parse_ieee_be (struct ieee_info *info, const bfd_byte **pp)
1238 if (info->blockstack.bsp <= info->blockstack.stack)
1240 ieee_error (info, *pp, _("stack underflow"));
1243 --info->blockstack.bsp;
1245 switch (info->blockstack.bsp->kind)
1248 /* When we end the global typedefs block, we copy out the
1249 contents of info->vars. This is because the variable indices
1250 may be reused in the local blocks. However, we need to
1251 preserve them so that we can locate a function returning a
1252 reference variable whose type is named in the global typedef
1254 info->global_vars = ((struct ieee_vars *)
1255 xmalloc (sizeof *info->global_vars));
1256 info->global_vars->alloc = info->vars.alloc;
1257 info->global_vars->vars = ((struct ieee_var *)
1258 xmalloc (info->vars.alloc
1259 * sizeof (*info->vars.vars)));
1260 memcpy (info->global_vars->vars, info->vars.vars,
1261 info->vars.alloc * sizeof (*info->vars.vars));
1263 /* We also copy out the non builtin parts of info->types, since
1264 the types are discarded when we start a new block. */
1265 info->global_types = ((struct ieee_types *)
1266 xmalloc (sizeof *info->global_types));
1267 info->global_types->alloc = info->types.alloc;
1268 info->global_types->types = ((struct ieee_type *)
1269 xmalloc (info->types.alloc
1270 * sizeof (*info->types.types)));
1271 memcpy (info->global_types->types, info->types.types,
1272 info->types.alloc * sizeof (*info->types.types));
1273 memset (info->global_types->builtins, 0,
1274 sizeof (info->global_types->builtins));
1280 if (! ieee_read_expression (info, pp, &offset))
1282 if (! info->blockstack.bsp->skip)
1284 if (! debug_end_function (info->dhandle, offset + 1))
1290 /* This is BE6 when BB6 started a block rather than a local
1292 if (! ieee_read_expression (info, pp, &offset))
1294 if (! debug_end_block (info->dhandle, offset + 1))
1299 /* When we end a BB5, we look up the stack for the last BB5, if
1300 there is one, so that we can call debug_start_source. */
1301 if (info->blockstack.bsp > info->blockstack.stack)
1303 struct ieee_block *bl;
1305 bl = info->blockstack.bsp;
1311 if (! debug_start_source (info->dhandle, bl->filename))
1316 while (bl != info->blockstack.stack);
1321 if (! ieee_read_expression (info, pp, &offset))
1323 /* We just ignore the module size. FIXME. */
1327 /* Other block types do not have any trailing information. */
1334 /* Parse an NN record. */
1337 parse_ieee_nn (struct ieee_info *info, const bfd_byte **pp)
1339 const bfd_byte *nn_start;
1342 unsigned long namlen;
1346 if (! ieee_read_number (info, pp, &varindx)
1347 || ! ieee_read_id (info, pp, &name, &namlen))
1352 ieee_error (info, nn_start, _("illegal variable index"));
1357 if (varindx >= info->vars.alloc)
1361 alloc = info->vars.alloc;
1364 while (varindx >= alloc)
1366 info->vars.vars = ((struct ieee_var *)
1367 xrealloc (info->vars.vars,
1368 alloc * sizeof *info->vars.vars));
1369 memset (info->vars.vars + info->vars.alloc, 0,
1370 (alloc - info->vars.alloc) * sizeof *info->vars.vars);
1371 info->vars.alloc = alloc;
1374 info->vars.vars[varindx].name = name;
1375 info->vars.vars[varindx].namlen = namlen;
1380 /* Parse a TY record. */
1383 parse_ieee_ty (struct ieee_info *info, const bfd_byte **pp)
1385 const bfd_byte *ty_start, *ty_var_start, *ty_code_start;
1386 bfd_vma typeindx, varindx, tc;
1388 bfd_boolean tag, typdef;
1389 debug_type *arg_slots;
1390 unsigned long type_bitsize;
1395 if (! ieee_read_number (info, pp, &typeindx))
1400 ieee_error (info, ty_start, _("illegal type index"));
1405 if (! ieee_alloc_type (info, typeindx, FALSE))
1410 ieee_error (info, *pp, _("unknown TY code"));
1417 if (! ieee_read_number (info, pp, &varindx))
1422 ieee_error (info, ty_var_start, _("illegal variable index"));
1427 if (varindx >= info->vars.alloc || info->vars.vars[varindx].name == NULL)
1429 ieee_error (info, ty_var_start, _("undefined variable in TY"));
1433 ty_code_start = *pp;
1435 if (! ieee_read_number (info, pp, &tc))
1438 dhandle = info->dhandle;
1447 ieee_error (info, ty_code_start, _("unknown TY code"));
1451 /* Unknown type, with size. We treat it as int. FIXME. */
1455 if (! ieee_read_number (info, pp, &size))
1457 type = debug_make_int_type (dhandle, size, FALSE);
1461 case 'A': /* Array. */
1462 case 'a': /* FORTRAN array in column/row order. FIXME: Not
1463 distinguished from normal array. */
1465 debug_type ele_type;
1466 bfd_vma lower, upper;
1468 if (! ieee_read_type_index (info, pp, &ele_type)
1469 || ! ieee_read_number (info, pp, &lower)
1470 || ! ieee_read_number (info, pp, &upper))
1472 type = debug_make_array_type (dhandle, ele_type,
1473 ieee_builtin_type (info, ty_code_start,
1476 (bfd_signed_vma) lower,
1477 (bfd_signed_vma) upper,
1483 /* Simple enumeration. */
1489 bfd_signed_vma *vals;
1492 if (! ieee_read_number (info, pp, &size))
1494 /* FIXME: we ignore the enumeration size. */
1497 names = (const char **) xmalloc (alloc * sizeof *names);
1498 memset (names, 0, alloc * sizeof *names);
1503 unsigned long namlen;
1504 bfd_boolean present;
1506 if (! ieee_read_optional_id (info, pp, &name, &namlen, &present))
1514 names = ((const char **)
1515 xrealloc (names, alloc * sizeof *names));
1518 names[c] = savestring (name, namlen);
1519 if (names[c] == NULL)
1526 vals = (bfd_signed_vma *) xmalloc (c * sizeof *vals);
1527 for (i = 0; i < c; i++)
1530 type = debug_make_enum_type (dhandle, names, vals);
1536 /* Struct with bit fields. */
1540 debug_field *fields;
1543 if (! ieee_read_number (info, pp, &size))
1547 fields = (debug_field *) xmalloc (alloc * sizeof *fields);
1552 unsigned long namlen;
1553 bfd_boolean present;
1555 bfd_vma bitpos, bitsize;
1557 if (! ieee_read_optional_id (info, pp, &name, &namlen, &present))
1561 if (! ieee_read_type_index (info, pp, &ftype)
1562 || ! ieee_read_number (info, pp, &bitpos)
1563 || ! ieee_read_number (info, pp, &bitsize))
1569 fields = ((debug_field *)
1570 xrealloc (fields, alloc * sizeof *fields));
1573 fields[c] = debug_make_field (dhandle, savestring (name, namlen),
1574 ftype, bitpos, bitsize,
1575 DEBUG_VISIBILITY_PUBLIC);
1576 if (fields[c] == NULL)
1583 type = debug_make_struct_type (dhandle, TRUE, size, fields);
1593 bfd_signed_vma *vals;
1597 names = (const char **) xmalloc (alloc * sizeof *names);
1598 vals = (bfd_signed_vma *) xmalloc (alloc * sizeof *names);
1603 unsigned long namlen;
1604 bfd_boolean present;
1607 if (! ieee_read_optional_id (info, pp, &name, &namlen, &present))
1611 if (! ieee_read_number (info, pp, &val))
1614 /* If the length of the name is zero, then the value is
1615 actually the size of the enum. We ignore this
1616 information. FIXME. */
1623 names = ((const char **)
1624 xrealloc (names, alloc * sizeof *names));
1625 vals = ((bfd_signed_vma *)
1626 xrealloc (vals, alloc * sizeof *vals));
1629 names[c] = savestring (name, namlen);
1630 if (names[c] == NULL)
1632 vals[c] = (bfd_signed_vma) val;
1638 type = debug_make_enum_type (dhandle, names, vals);
1643 case 'O': /* Small pointer. We don't distinguish small and large
1645 case 'P': /* Large pointer. */
1649 if (! ieee_read_type_index (info, pp, &t))
1651 type = debug_make_pointer_type (dhandle, t);
1658 bfd_vma low, high, signedp, size;
1660 if (! ieee_read_number (info, pp, &low)
1661 || ! ieee_read_number (info, pp, &high)
1662 || ! ieee_read_number (info, pp, &signedp)
1663 || ! ieee_read_number (info, pp, &size))
1666 type = debug_make_range_type (dhandle,
1667 debug_make_int_type (dhandle, size,
1669 (bfd_signed_vma) low,
1670 (bfd_signed_vma) high);
1674 case 'S': /* Struct. */
1675 case 'U': /* Union. */
1679 debug_field *fields;
1682 if (! ieee_read_number (info, pp, &size))
1686 fields = (debug_field *) xmalloc (alloc * sizeof *fields);
1691 unsigned long namlen;
1692 bfd_boolean present;
1698 if (! ieee_read_optional_id (info, pp, &name, &namlen, &present))
1702 if (! ieee_read_number (info, pp, &tindx)
1703 || ! ieee_read_number (info, pp, &offset))
1708 ftype = ieee_builtin_type (info, ty_code_start, tindx);
1714 struct ieee_type *t;
1717 if (! ieee_alloc_type (info, tindx, TRUE))
1719 t = info->types.types + tindx;
1721 bitsize = t->bitsize;
1729 fields = ((debug_field *)
1730 xrealloc (fields, alloc * sizeof *fields));
1733 fields[c] = debug_make_field (dhandle, savestring (name, namlen),
1734 ftype, offset, bitsize,
1735 DEBUG_VISIBILITY_PUBLIC);
1736 if (fields[c] == NULL)
1743 type = debug_make_struct_type (dhandle, tc == 'S', size, fields);
1750 if (! ieee_read_type_index (info, pp, &type))
1756 /* Procedure. FIXME: This is an extern declaration, which we
1757 have no way of representing. */
1762 bfd_boolean present;
1763 struct ieee_var *pv;
1765 /* FIXME: We ignore the attribute and the argument names. */
1767 if (! ieee_read_number (info, pp, &attr)
1768 || ! ieee_read_type_index (info, pp, &rtype)
1769 || ! ieee_read_number (info, pp, &nargs))
1774 unsigned long namlen;
1776 if (! ieee_read_optional_id (info, pp, &name, &namlen, &present))
1781 pv = info->vars.vars + varindx;
1782 pv->kind = IEEE_EXTERNAL;
1784 && debug_get_type_kind (dhandle, rtype) == DEBUG_KIND_POINTER)
1786 /* Set up the return type as an indirect type pointing to
1787 the variable slot, so that we can change it to a
1788 reference later if appropriate. */
1789 pv->pslot = (debug_type *) xmalloc (sizeof *pv->pslot);
1791 rtype = debug_make_indirect_type (dhandle, pv->pslot,
1792 (const char *) NULL);
1795 type = debug_make_function_type (dhandle, rtype, (debug_type *) NULL,
1802 /* Void. This is not documented, but the MRI compiler emits it. */
1803 type = debug_make_void_type (dhandle);
1807 /* Array with 0 lower bound. */
1812 if (! ieee_read_type_index (info, pp, &etype)
1813 || ! ieee_read_number (info, pp, &high))
1816 type = debug_make_array_type (dhandle, etype,
1817 ieee_builtin_type (info, ty_code_start,
1820 0, (bfd_signed_vma) high, FALSE);
1824 case 'c': /* Complex. */
1825 case 'd': /* Double complex. */
1828 unsigned long namlen;
1830 /* FIXME: I don't know what the name means. */
1832 if (! ieee_read_id (info, pp, &name, &namlen))
1835 type = debug_make_complex_type (dhandle, tc == 'c' ? 4 : 8);
1840 /* Pascal file name. FIXME. */
1841 ieee_error (info, ty_code_start, _("Pascal file name not supported"));
1845 /* Bitfield type. */
1847 bfd_vma signedp, bitsize, dummy;
1848 const bfd_byte *hold;
1849 bfd_boolean present;
1851 if (! ieee_read_number (info, pp, &signedp)
1852 || ! ieee_read_number (info, pp, &bitsize))
1855 /* I think the documentation says that there is a type index,
1856 but some actual files do not have one. */
1858 if (! ieee_read_optional_number (info, pp, &dummy, &present))
1862 /* FIXME: This is just a guess. */
1863 type = debug_make_int_type (dhandle, 4,
1864 signedp ? FALSE : TRUE);
1869 if (! ieee_read_type_index (info, pp, &type))
1872 type_bitsize = bitsize;
1882 if (! ieee_read_number (info, pp, &kind)
1883 || ! ieee_read_type_index (info, pp, &t))
1889 ieee_error (info, ty_start, _("unsupported qualifier"));
1893 type = debug_make_const_type (dhandle, t);
1897 type = debug_make_volatile_type (dhandle, t);
1909 if (! ieee_read_number (info, pp, &size)
1910 || ! ieee_read_type_index (info, pp, &etype))
1913 /* FIXME: We ignore the size. */
1915 type = debug_make_set_type (dhandle, etype, FALSE);
1920 /* Procedure with compiler dependencies. */
1922 struct ieee_var *pv;
1923 bfd_vma attr, frame_type, push_mask, nargs, level, father;
1925 debug_type *arg_types;
1926 bfd_boolean varargs;
1927 bfd_boolean present;
1929 /* FIXME: We ignore some of this information. */
1931 pv = info->vars.vars + varindx;
1933 if (! ieee_read_number (info, pp, &attr)
1934 || ! ieee_read_number (info, pp, &frame_type)
1935 || ! ieee_read_number (info, pp, &push_mask)
1936 || ! ieee_read_type_index (info, pp, &rtype)
1937 || ! ieee_read_number (info, pp, &nargs))
1939 if (nargs == (bfd_vma) -1)
1948 arg_types = ((debug_type *)
1949 xmalloc ((nargs + 1) * sizeof *arg_types));
1950 for (i = 0; i < nargs; i++)
1951 if (! ieee_read_type_index (info, pp, arg_types + i))
1954 /* If the last type is pointer to void, this is really a
1955 varargs function. */
1961 last = arg_types[nargs - 1];
1962 if (debug_get_type_kind (dhandle, last) == DEBUG_KIND_POINTER
1963 && (debug_get_type_kind (dhandle,
1964 debug_get_target_type (dhandle,
1966 == DEBUG_KIND_VOID))
1973 /* If there are any pointer arguments, turn them into
1974 indirect types in case we later need to convert them to
1976 for (i = 0; i < nargs; i++)
1978 if (debug_get_type_kind (dhandle, arg_types[i])
1979 == DEBUG_KIND_POINTER)
1981 if (arg_slots == NULL)
1983 arg_slots = ((debug_type *)
1984 xmalloc (nargs * sizeof *arg_slots));
1985 memset (arg_slots, 0, nargs * sizeof *arg_slots);
1987 arg_slots[i] = arg_types[i];
1989 debug_make_indirect_type (dhandle,
1991 (const char *) NULL);
1995 arg_types[nargs] = DEBUG_TYPE_NULL;
1997 if (! ieee_read_number (info, pp, &level)
1998 || ! ieee_read_optional_number (info, pp, &father, &present))
2001 /* We can't distinguish between a global function and a static
2003 pv->kind = IEEE_FUNCTION;
2006 && debug_get_type_kind (dhandle, rtype) == DEBUG_KIND_POINTER)
2008 /* Set up the return type as an indirect type pointing to
2009 the variable slot, so that we can change it to a
2010 reference later if appropriate. */
2011 pv->pslot = (debug_type *) xmalloc (sizeof *pv->pslot);
2013 rtype = debug_make_indirect_type (dhandle, pv->pslot,
2014 (const char *) NULL);
2017 type = debug_make_function_type (dhandle, rtype, arg_types, varargs);
2022 /* Record the type in the table. */
2024 if (type == DEBUG_TYPE_NULL)
2027 info->vars.vars[varindx].type = type;
2030 && info->vars.vars[varindx].namlen > 0)
2034 name = savestring (info->vars.vars[varindx].name,
2035 info->vars.vars[varindx].namlen);
2037 type = debug_name_type (dhandle, name, type);
2038 else if (tc == 'E' || tc == 'N')
2039 type = debug_tag_type (dhandle, name, type);
2042 struct ieee_tag *it;
2044 /* We must allocate all struct tags as indirect types, so
2045 that if we later see a definition of the tag as a C++
2046 record we can update the indirect slot and automatically
2047 change all the existing references. */
2048 it = (struct ieee_tag *) xmalloc (sizeof *it);
2049 memset (it, 0, sizeof *it);
2050 it->next = info->tags;
2055 type = debug_make_indirect_type (dhandle, &it->slot, name);
2056 type = debug_tag_type (dhandle, name, type);
2064 info->types.types[typeindx].type = type;
2065 info->types.types[typeindx].arg_slots = arg_slots;
2066 info->types.types[typeindx].bitsize = type_bitsize;
2068 /* We may have already allocated type as an indirect type pointing
2069 to slot. It does no harm to replace the indirect type with the
2070 real type. Filling in slot as well handles the indirect types
2071 which are already hanging around. */
2072 if (info->types.types[typeindx].pslot != NULL)
2073 *info->types.types[typeindx].pslot = type;
2078 /* Parse an ATN record. */
2081 parse_ieee_atn (struct ieee_info *info, const bfd_byte **pp)
2083 const bfd_byte *atn_start, *atn_code_start;
2085 struct ieee_var *pvar;
2089 bfd_vma v, v2, v3, v4, v5;
2091 unsigned long namlen;
2093 bfd_boolean present;
2098 if (! ieee_read_number (info, pp, &varindx)
2099 || ! ieee_read_type_index (info, pp, &type))
2102 atn_code_start = *pp;
2104 if (! ieee_read_number (info, pp, &atn_code))
2113 else if (varindx < 32)
2115 /* The MRI compiler reportedly sometimes emits variable lifetime
2116 information for a register. We just ignore it. */
2118 return ieee_read_number (info, pp, &v);
2120 ieee_error (info, atn_start, _("illegal variable index"));
2126 if (varindx >= info->vars.alloc
2127 || info->vars.vars[varindx].name == NULL)
2129 /* The MRI compiler or linker sometimes omits the NN record
2130 for a pmisc record. */
2133 if (varindx >= info->vars.alloc)
2137 alloc = info->vars.alloc;
2140 while (varindx >= alloc)
2142 info->vars.vars = ((struct ieee_var *)
2143 xrealloc (info->vars.vars,
2145 * sizeof *info->vars.vars)));
2146 memset (info->vars.vars + info->vars.alloc, 0,
2147 ((alloc - info->vars.alloc)
2148 * sizeof *info->vars.vars));
2149 info->vars.alloc = alloc;
2152 pvar = info->vars.vars + varindx;
2158 ieee_error (info, atn_start, _("undefined variable in ATN"));
2163 pvar = info->vars.vars + varindx;
2168 namlen = pvar->namlen;
2171 dhandle = info->dhandle;
2173 /* If we are going to call debug_record_variable with a pointer
2174 type, change the type to an indirect type so that we can later
2175 change it to a reference type if we encounter a C++ pmisc 'R'
2178 && type != DEBUG_TYPE_NULL
2179 && debug_get_type_kind (dhandle, type) == DEBUG_KIND_POINTER)
2189 pvar->pslot = (debug_type *) xmalloc (sizeof *pvar->pslot);
2190 *pvar->pslot = type;
2191 type = debug_make_indirect_type (dhandle, pvar->pslot,
2192 (const char *) NULL);
2201 ieee_error (info, atn_code_start, _("unknown ATN type"));
2205 /* Automatic variable. */
2206 if (! ieee_read_number (info, pp, &v))
2208 namcopy = savestring (name, namlen);
2210 type = debug_make_void_type (dhandle);
2212 pvar->kind = IEEE_LOCAL;
2213 return debug_record_variable (dhandle, namcopy, type, DEBUG_LOCAL, v);
2216 /* Register variable. */
2217 if (! ieee_read_number (info, pp, &v))
2219 namcopy = savestring (name, namlen);
2221 type = debug_make_void_type (dhandle);
2223 pvar->kind = IEEE_LOCAL;
2224 return debug_record_variable (dhandle, namcopy, type, DEBUG_REGISTER,
2225 ieee_regno_to_genreg (info->abfd, v));
2228 /* Static variable. */
2229 if (! ieee_require_asn (info, pp, &v))
2231 namcopy = savestring (name, namlen);
2233 type = debug_make_void_type (dhandle);
2234 if (info->blockstack.bsp <= info->blockstack.stack)
2237 blocktype = info->blockstack.bsp[-1].kind;
2240 if (blocktype == 4 || blocktype == 6)
2241 pvar->kind = IEEE_LOCAL;
2243 pvar->kind = IEEE_STATIC;
2245 return debug_record_variable (dhandle, namcopy, type,
2246 (blocktype == 4 || blocktype == 6
2247 ? DEBUG_LOCAL_STATIC
2252 /* External function. We don't currently record these. FIXME. */
2254 pvar->kind = IEEE_EXTERNAL;
2258 /* External variable. We don't currently record these. FIXME. */
2260 pvar->kind = IEEE_EXTERNAL;
2264 if (! ieee_read_number (info, pp, &v)
2265 || ! ieee_read_number (info, pp, &v2)
2266 || ! ieee_read_optional_number (info, pp, &v3, &present))
2270 if (! ieee_read_optional_number (info, pp, &v4, &present))
2274 /* We just ignore the two optional fields in v3 and v4, since
2275 they are not defined. */
2277 if (! ieee_require_asn (info, pp, &v3))
2280 /* We have no way to record the column number. FIXME. */
2282 return debug_record_line (dhandle, v, v3);
2285 /* Global variable. */
2286 if (! ieee_require_asn (info, pp, &v))
2288 namcopy = savestring (name, namlen);
2290 type = debug_make_void_type (dhandle);
2292 pvar->kind = IEEE_GLOBAL;
2293 return debug_record_variable (dhandle, namcopy, type, DEBUG_GLOBAL, v);
2296 /* Variable lifetime information. */
2297 if (! ieee_read_number (info, pp, &v))
2300 /* We have no way to record this information. FIXME. */
2304 /* Locked register. The spec says that there are two required
2305 fields, but at least on occasion the MRI compiler only emits
2307 if (! ieee_read_number (info, pp, &v)
2308 || ! ieee_read_optional_number (info, pp, &v2, &present))
2311 /* I think this means a variable that is both in a register and
2312 a frame slot. We ignore the frame slot. FIXME. */
2314 namcopy = savestring (name, namlen);
2316 type = debug_make_void_type (dhandle);
2318 pvar->kind = IEEE_LOCAL;
2319 return debug_record_variable (dhandle, namcopy, type, DEBUG_REGISTER, v);
2322 /* Reserved for FORTRAN common. */
2323 ieee_error (info, atn_code_start, _("unsupported ATN11"));
2325 /* Return TRUE to keep going. */
2329 /* Based variable. */
2333 if (! ieee_read_number (info, pp, &v)
2334 || ! ieee_read_number (info, pp, &v2)
2335 || ! ieee_read_optional_number (info, pp, &v3, &present))
2339 if (! ieee_read_optional_number (info, pp, &v4, &present))
2343 if (! ieee_read_optional_number (info, pp, &v5, &present))
2348 /* We have no way to record this information. FIXME. */
2350 ieee_error (info, atn_code_start, _("unsupported ATN12"));
2352 /* Return TRUE to keep going. */
2356 /* Constant. The description of this that I have is ambiguous,
2357 so I'm not going to try to implement it. */
2358 if (! ieee_read_number (info, pp, &v)
2359 || ! ieee_read_optional_number (info, pp, &v2, &present))
2363 if (! ieee_read_optional_number (info, pp, &v2, &present))
2367 if (! ieee_read_optional_id (info, pp, &name, &namlen, &present))
2372 if ((ieee_record_enum_type) **pp == ieee_e2_first_byte_enum)
2374 if (! ieee_require_asn (info, pp, &v3))
2381 /* Static variable from assembler. */
2383 if (! ieee_read_number (info, pp, &v)
2384 || ! ieee_read_optional_number (info, pp, &v2, &present)
2385 || ! ieee_require_asn (info, pp, &v3))
2387 namcopy = savestring (name, namlen);
2388 /* We don't really handle this correctly. FIXME. */
2389 return debug_record_variable (dhandle, namcopy,
2390 debug_make_void_type (dhandle),
2391 v2 != 0 ? DEBUG_GLOBAL : DEBUG_STATIC,
2395 /* Procedure miscellaneous information. */
2397 /* Variable miscellaneous information. */
2399 /* Module miscellaneous information. */
2400 if (! ieee_read_number (info, pp, &v)
2401 || ! ieee_read_number (info, pp, &v2)
2402 || ! ieee_read_optional_id (info, pp, &name, &namlen, &present))
2405 if (atn_code == 62 && v == 80)
2409 ieee_error (info, atn_code_start,
2410 _("unexpected string in C++ misc"));
2413 return ieee_read_cxx_misc (info, pp, v2);
2416 /* We just ignore all of this stuff. FIXME. */
2418 for (; v2 > 0; --v2)
2420 switch ((ieee_record_enum_type) **pp)
2423 ieee_error (info, *pp, _("bad misc record"));
2426 case ieee_at_record_enum:
2427 if (! ieee_require_atn65 (info, pp, &name, &namlen))
2431 case ieee_e2_first_byte_enum:
2432 if (! ieee_require_asn (info, pp, &v3))
2444 /* Handle C++ debugging miscellaneous records. This is called for
2445 procedure miscellaneous records of type 80. */
2448 ieee_read_cxx_misc (struct ieee_info *info, const bfd_byte **pp,
2449 unsigned long count)
2451 const bfd_byte *start;
2456 /* Get the category of C++ misc record. */
2457 if (! ieee_require_asn (info, pp, &category))
2464 ieee_error (info, start, _("unrecognized C++ misc record"));
2468 if (! ieee_read_cxx_class (info, pp, count))
2476 unsigned long namlen;
2478 /* The IEEE spec indicates that the 'M' record only has a
2479 flags field. The MRI compiler also emits the name of the
2482 if (! ieee_require_asn (info, pp, &flags))
2484 if (*pp < info->pend
2485 && (ieee_record_enum_type) **pp == ieee_at_record_enum)
2487 if (! ieee_require_atn65 (info, pp, &name, &namlen))
2491 /* This is emitted for method functions, but I don't think we
2492 care very much. It might help if it told us useful
2493 information like the class with which this function is
2494 associated, but it doesn't, so it isn't helpful. */
2499 if (! ieee_read_cxx_defaults (info, pp, count))
2505 const char *name, *mangled, *cxx_class;
2506 unsigned long namlen, mangledlen, classlen;
2509 /* Pointer to member. */
2511 if (! ieee_require_atn65 (info, pp, &name, &namlen)
2512 || ! ieee_require_atn65 (info, pp, &mangled, &mangledlen)
2513 || ! ieee_require_atn65 (info, pp, &cxx_class, &classlen)
2514 || ! ieee_require_asn (info, pp, &control))
2517 /* FIXME: We should now track down name and change its type. */
2522 if (! ieee_read_reference (info, pp))
2530 /* Read a C++ class definition. This is a pmisc type 80 record of
2534 ieee_read_cxx_class (struct ieee_info *info, const bfd_byte **pp,
2535 unsigned long count)
2537 const bfd_byte *start;
2540 unsigned long taglen;
2541 struct ieee_tag *it;
2543 debug_field *fields;
2544 unsigned int field_count, field_alloc;
2545 debug_baseclass *baseclasses;
2546 unsigned int baseclasses_count, baseclasses_alloc;
2547 const debug_field *structfields;
2551 unsigned long namlen;
2552 debug_method_variant *variants;
2556 unsigned int methods_count, methods_alloc;
2557 debug_type vptrbase;
2558 bfd_boolean ownvptr;
2559 debug_method *dmethods;
2563 if (! ieee_require_asn (info, pp, &cxx_class))
2567 if (! ieee_require_atn65 (info, pp, &tag, &taglen))
2571 /* Find the C struct with this name. */
2572 for (it = info->tags; it != NULL; it = it->next)
2573 if (it->name[0] == tag[0]
2574 && strncmp (it->name, tag, taglen) == 0
2575 && strlen (it->name) == taglen)
2579 ieee_error (info, start, _("undefined C++ object"));
2583 dhandle = info->dhandle;
2589 baseclasses_count = 0;
2590 baseclasses_alloc = 0;
2594 vptrbase = DEBUG_TYPE_NULL;
2597 structfields = debug_get_fields (dhandle, it->type);
2602 const bfd_byte *spec_start;
2606 if (! ieee_require_asn (info, pp, &id))
2613 ieee_error (info, spec_start, _("unrecognized C++ object spec"));
2618 bfd_vma flags, cinline;
2619 const char *base, *fieldname;
2620 unsigned long baselen, fieldlen;
2622 debug_type basetype;
2624 bfd_boolean virtualp;
2625 enum debug_visibility visibility;
2626 debug_baseclass baseclass;
2628 /* This represents a base or friend class. */
2630 if (! ieee_require_asn (info, pp, &flags)
2631 || ! ieee_require_atn65 (info, pp, &base, &baselen)
2632 || ! ieee_require_asn (info, pp, &cinline)
2633 || ! ieee_require_atn65 (info, pp, &fieldname, &fieldlen))
2637 /* We have no way of recording friend information, so we
2639 if ((flags & BASEFLAGS_FRIEND) != 0)
2642 /* I assume that either all of the members of the
2643 baseclass are included in the object, starting at the
2644 beginning of the object, or that none of them are
2647 if ((fieldlen == 0) == (cinline == 0))
2649 ieee_error (info, start, _("unsupported C++ object type"));
2653 basecopy = savestring (base, baselen);
2654 basetype = debug_find_tagged_type (dhandle, basecopy,
2655 DEBUG_KIND_ILLEGAL);
2657 if (basetype == DEBUG_TYPE_NULL)
2659 ieee_error (info, start, _("C++ base class not defined"));
2667 const debug_field *pf;
2669 if (structfields == NULL)
2671 ieee_error (info, start, _("C++ object has no fields"));
2675 for (pf = structfields; *pf != DEBUG_FIELD_NULL; pf++)
2679 fname = debug_get_field_name (dhandle, *pf);
2682 if (fname[0] == fieldname[0]
2683 && strncmp (fname, fieldname, fieldlen) == 0
2684 && strlen (fname) == fieldlen)
2687 if (*pf == DEBUG_FIELD_NULL)
2689 ieee_error (info, start,
2690 _("C++ base class not found in container"));
2694 bitpos = debug_get_field_bitpos (dhandle, *pf);
2697 if ((flags & BASEFLAGS_VIRTUAL) != 0)
2701 if ((flags & BASEFLAGS_PRIVATE) != 0)
2702 visibility = DEBUG_VISIBILITY_PRIVATE;
2704 visibility = DEBUG_VISIBILITY_PUBLIC;
2706 baseclass = debug_make_baseclass (dhandle, basetype, bitpos,
2707 virtualp, visibility);
2708 if (baseclass == DEBUG_BASECLASS_NULL)
2711 if (baseclasses_count + 1 >= baseclasses_alloc)
2713 baseclasses_alloc += 10;
2714 baseclasses = ((debug_baseclass *)
2715 xrealloc (baseclasses,
2717 * sizeof *baseclasses)));
2720 baseclasses[baseclasses_count] = baseclass;
2721 ++baseclasses_count;
2722 baseclasses[baseclasses_count] = DEBUG_BASECLASS_NULL;
2729 const char *fieldname, *mangledname;
2730 unsigned long fieldlen, mangledlen;
2732 bfd_boolean staticp;
2734 const debug_field *pf = NULL;
2735 enum debug_visibility visibility;
2738 /* This represents a data member. */
2740 if (! ieee_require_asn (info, pp, &flags)
2741 || ! ieee_require_atn65 (info, pp, &fieldname, &fieldlen)
2742 || ! ieee_require_atn65 (info, pp, &mangledname, &mangledlen))
2746 fieldcopy = savestring (fieldname, fieldlen);
2748 staticp = (flags & CXXFLAGS_STATIC) != 0 ? TRUE : FALSE;
2752 struct ieee_var *pv, *pvend;
2754 /* See if we can find a definition for this variable. */
2755 pv = info->vars.vars;
2756 pvend = pv + info->vars.alloc;
2757 for (; pv < pvend; pv++)
2758 if (pv->namlen == mangledlen
2759 && strncmp (pv->name, mangledname, mangledlen) == 0)
2765 /* This can happen if the variable is never used. */
2766 ftype = ieee_builtin_type (info, start,
2767 (unsigned int) builtin_void);
2774 if (structfields == NULL)
2776 ieee_error (info, start, _("C++ object has no fields"));
2780 for (pf = structfields, findx = 0;
2781 *pf != DEBUG_FIELD_NULL;
2786 fname = debug_get_field_name (dhandle, *pf);
2789 if (fname[0] == mangledname[0]
2790 && strncmp (fname, mangledname, mangledlen) == 0
2791 && strlen (fname) == mangledlen)
2794 if (*pf == DEBUG_FIELD_NULL)
2796 ieee_error (info, start,
2797 _("C++ data member not found in container"));
2801 ftype = debug_get_field_type (dhandle, *pf);
2803 if (debug_get_type_kind (dhandle, ftype) == DEBUG_KIND_POINTER)
2805 /* We might need to convert this field into a
2806 reference type later on, so make it an indirect
2808 if (it->fslots == NULL)
2811 const debug_field *pfcnt;
2814 for (pfcnt = structfields;
2815 *pfcnt != DEBUG_FIELD_NULL;
2818 it->fslots = ((debug_type *)
2819 xmalloc (fcnt * sizeof *it->fslots));
2820 memset (it->fslots, 0,
2821 fcnt * sizeof *it->fslots);
2824 if (ftype == DEBUG_TYPE_NULL)
2826 it->fslots[findx] = ftype;
2827 ftype = debug_make_indirect_type (dhandle,
2829 (const char *) NULL);
2832 if (ftype == DEBUG_TYPE_NULL)
2835 switch (flags & CXXFLAGS_VISIBILITY)
2838 ieee_error (info, start, _("unknown C++ visibility"));
2841 case CXXFLAGS_VISIBILITY_PUBLIC:
2842 visibility = DEBUG_VISIBILITY_PUBLIC;
2845 case CXXFLAGS_VISIBILITY_PRIVATE:
2846 visibility = DEBUG_VISIBILITY_PRIVATE;
2849 case CXXFLAGS_VISIBILITY_PROTECTED:
2850 visibility = DEBUG_VISIBILITY_PROTECTED;
2858 mangledcopy = savestring (mangledname, mangledlen);
2860 field = debug_make_static_member (dhandle, fieldcopy,
2866 bfd_vma bitpos, bitsize;
2868 bitpos = debug_get_field_bitpos (dhandle, *pf);
2869 bitsize = debug_get_field_bitsize (dhandle, *pf);
2870 if (bitpos == (bfd_vma) -1 || bitsize == (bfd_vma) -1)
2872 ieee_error (info, start, _("bad C++ field bit pos or size"));
2875 field = debug_make_field (dhandle, fieldcopy, ftype, bitpos,
2876 bitsize, visibility);
2879 if (field == DEBUG_FIELD_NULL)
2882 if (field_count + 1 >= field_alloc)
2885 fields = ((debug_field *)
2886 xrealloc (fields, field_alloc * sizeof *fields));
2889 fields[field_count] = field;
2891 fields[field_count] = DEBUG_FIELD_NULL;
2898 bfd_vma flags, voffset, control;
2899 const char *name, *mangled;
2900 unsigned long namlen, mangledlen;
2901 struct ieee_var *pv, *pvend;
2903 enum debug_visibility visibility;
2904 bfd_boolean constp, volatilep;
2906 debug_method_variant mv;
2907 struct ieee_method *meth;
2910 if (! ieee_require_asn (info, pp, &flags)
2911 || ! ieee_require_atn65 (info, pp, &name, &namlen)
2912 || ! ieee_require_atn65 (info, pp, &mangled, &mangledlen))
2919 if (! ieee_require_asn (info, pp, &voffset))
2923 if (! ieee_require_asn (info, pp, &control))
2927 /* We just ignore the control information. */
2929 /* We have no way to represent friend information, so we
2931 if ((flags & CXXFLAGS_FRIEND) != 0)
2934 /* We should already have seen a type for the function. */
2935 pv = info->vars.vars;
2936 pvend = pv + info->vars.alloc;
2937 for (; pv < pvend; pv++)
2938 if (pv->namlen == mangledlen
2939 && strncmp (pv->name, mangled, mangledlen) == 0)
2944 /* We won't have type information for this function if
2945 it is not included in this file. We don't try to
2946 handle this case. FIXME. */
2947 type = (debug_make_function_type
2949 ieee_builtin_type (info, start,
2950 (unsigned int) builtin_void),
2951 (debug_type *) NULL,
2956 debug_type return_type;
2957 const debug_type *arg_types;
2958 bfd_boolean varargs;
2960 if (debug_get_type_kind (dhandle, pv->type)
2961 != DEBUG_KIND_FUNCTION)
2963 ieee_error (info, start,
2964 _("bad type for C++ method function"));
2968 return_type = debug_get_return_type (dhandle, pv->type);
2969 arg_types = debug_get_parameter_types (dhandle, pv->type,
2971 if (return_type == DEBUG_TYPE_NULL || arg_types == NULL)
2973 ieee_error (info, start,
2974 _("no type information for C++ method function"));
2978 type = debug_make_method_type (dhandle, return_type, it->type,
2979 (debug_type *) arg_types,
2982 if (type == DEBUG_TYPE_NULL)
2985 switch (flags & CXXFLAGS_VISIBILITY)
2988 ieee_error (info, start, _("unknown C++ visibility"));
2991 case CXXFLAGS_VISIBILITY_PUBLIC:
2992 visibility = DEBUG_VISIBILITY_PUBLIC;
2995 case CXXFLAGS_VISIBILITY_PRIVATE:
2996 visibility = DEBUG_VISIBILITY_PRIVATE;
2999 case CXXFLAGS_VISIBILITY_PROTECTED:
3000 visibility = DEBUG_VISIBILITY_PROTECTED;
3004 constp = (flags & CXXFLAGS_CONST) != 0 ? TRUE : FALSE;
3005 volatilep = (flags & CXXFLAGS_VOLATILE) != 0 ? TRUE : FALSE;
3007 mangledcopy = savestring (mangled, mangledlen);
3009 if ((flags & CXXFLAGS_STATIC) != 0)
3013 ieee_error (info, start, _("C++ static virtual method"));
3016 mv = debug_make_static_method_variant (dhandle, mangledcopy,
3022 debug_type vcontext;
3025 vcontext = DEBUG_TYPE_NULL;
3028 /* FIXME: How can we calculate this correctly? */
3029 vcontext = it->type;
3031 mv = debug_make_method_variant (dhandle, mangledcopy, type,
3036 if (mv == DEBUG_METHOD_VARIANT_NULL)
3039 for (meth = methods, im = 0; im < methods_count; meth++, im++)
3040 if (meth->namlen == namlen
3041 && strncmp (meth->name, name, namlen) == 0)
3043 if (im >= methods_count)
3045 if (methods_count >= methods_alloc)
3047 methods_alloc += 10;
3048 methods = ((struct ieee_method *)
3050 methods_alloc * sizeof *methods));
3052 methods[methods_count].name = name;
3053 methods[methods_count].namlen = namlen;
3054 methods[methods_count].variants = NULL;
3055 methods[methods_count].count = 0;
3056 methods[methods_count].alloc = 0;
3057 meth = methods + methods_count;
3061 if (meth->count + 1 >= meth->alloc)
3064 meth->variants = ((debug_method_variant *)
3065 xrealloc (meth->variants,
3067 * sizeof *meth->variants)));
3070 meth->variants[meth->count] = mv;
3072 meth->variants[meth->count] = DEBUG_METHOD_VARIANT_NULL;
3080 /* We have no way to store this information, so we just
3082 if (! ieee_require_asn (info, pp, &spec))
3085 if ((spec & 4) != 0)
3087 const char *filename;
3088 unsigned long filenamlen;
3091 if (! ieee_require_atn65 (info, pp, &filename, &filenamlen)
3092 || ! ieee_require_asn (info, pp, &lineno))
3096 else if ((spec & 8) != 0)
3098 const char *mangled;
3099 unsigned long mangledlen;
3101 if (! ieee_require_atn65 (info, pp, &mangled, &mangledlen))
3107 ieee_error (info, start,
3108 _("unrecognized C++ object overhead spec"));
3116 const char *vname, *base;
3117 unsigned long vnamelen, baselen;
3118 bfd_vma vsize, control;
3120 /* A virtual table pointer. */
3122 if (! ieee_require_atn65 (info, pp, &vname, &vnamelen)
3123 || ! ieee_require_asn (info, pp, &vsize)
3124 || ! ieee_require_atn65 (info, pp, &base, &baselen)
3125 || ! ieee_require_asn (info, pp, &control))
3129 /* We just ignore the control number. We don't care what
3130 the virtual table name is. We have no way to store the
3131 virtual table size, and I don't think we care anyhow. */
3133 /* FIXME: We can't handle multiple virtual table pointers. */
3141 basecopy = savestring (base, baselen);
3142 vptrbase = debug_find_tagged_type (dhandle, basecopy,
3143 DEBUG_KIND_ILLEGAL);
3145 if (vptrbase == DEBUG_TYPE_NULL)
3147 ieee_error (info, start, _("undefined C++ vtable"));
3156 /* Now that we have seen all the method variants, we can call
3157 debug_make_method for each one. */
3159 if (methods_count == 0)
3165 dmethods = ((debug_method *)
3166 xmalloc ((methods_count + 1) * sizeof *dmethods));
3167 for (i = 0; i < methods_count; i++)
3171 namcopy = savestring (methods[i].name, methods[i].namlen);
3172 dmethods[i] = debug_make_method (dhandle, namcopy,
3173 methods[i].variants);
3174 if (dmethods[i] == DEBUG_METHOD_NULL)
3177 dmethods[i] = DEBUG_METHOD_NULL;
3181 /* The struct type was created as an indirect type pointing at
3182 it->slot. We update it->slot to automatically update all
3183 references to this struct. */
3184 it->slot = debug_make_object_type (dhandle,
3186 debug_get_type_size (dhandle,
3188 fields, baseclasses, dmethods,
3190 if (it->slot == DEBUG_TYPE_NULL)
3196 /* Read C++ default argument value and reference type information. */
3199 ieee_read_cxx_defaults (struct ieee_info *info, const bfd_byte **pp,
3200 unsigned long count)
3202 const bfd_byte *start;
3204 unsigned long fnlen;
3209 /* Giving the function name before the argument count is an addendum
3210 to the spec. The function name is demangled, though, so this
3211 record must always refer to the current function. */
3213 if (info->blockstack.bsp <= info->blockstack.stack
3214 || info->blockstack.bsp[-1].fnindx == (unsigned int) -1)
3216 ieee_error (info, start, _("C++ default values not in a function"));
3220 if (! ieee_require_atn65 (info, pp, &fnname, &fnlen)
3221 || ! ieee_require_asn (info, pp, &defcount))
3225 while (defcount-- > 0)
3229 unsigned long strvallen;
3231 if (! ieee_require_asn (info, pp, &type))
3243 if (! ieee_require_asn (info, pp, &val))
3250 if (! ieee_require_atn65 (info, pp, &strval, &strvallen))
3256 ieee_error (info, start, _("unrecognized C++ default type"));
3260 /* We have no way to record the default argument values, so we
3261 just ignore them. FIXME. */
3264 /* Any remaining arguments are indices of parameters that are really
3269 debug_type *arg_slots;
3271 dhandle = info->dhandle;
3272 arg_slots = info->types.types[info->blockstack.bsp[-1].fnindx].arg_slots;
3278 if (! ieee_require_asn (info, pp, &indx))
3280 /* The index is 1 based. */
3282 if (arg_slots == NULL
3283 || arg_slots[indx] == DEBUG_TYPE_NULL
3284 || (debug_get_type_kind (dhandle, arg_slots[indx])
3285 != DEBUG_KIND_POINTER))
3287 ieee_error (info, start, _("reference parameter is not a pointer"));
3291 target = debug_get_target_type (dhandle, arg_slots[indx]);
3292 arg_slots[indx] = debug_make_reference_type (dhandle, target);
3293 if (arg_slots[indx] == DEBUG_TYPE_NULL)
3301 /* Read a C++ reference definition. */
3304 ieee_read_reference (struct ieee_info *info, const bfd_byte **pp)
3306 const bfd_byte *start;
3308 const char *cxx_class, *name;
3309 unsigned long classlen, namlen;
3315 if (! ieee_require_asn (info, pp, &flags))
3318 /* Giving the class name before the member name is in an addendum to
3322 if (! ieee_require_atn65 (info, pp, &cxx_class, &classlen))
3326 if (! ieee_require_atn65 (info, pp, &name, &namlen))
3334 /* We search from the last variable indices to the first in
3335 hopes of finding local variables correctly. We search the
3336 local variables on the first pass, and the global variables
3337 on the second. FIXME: This probably won't work in all cases.
3338 On the other hand, I don't know what will. */
3339 for (pass = 0; pass < 2; pass++)
3341 struct ieee_vars *vars;
3343 struct ieee_var *pv = NULL;
3349 vars = info->global_vars;
3354 for (i = (int) vars->alloc - 1; i >= 0; i--)
3358 pv = vars->vars + i;
3360 if (pv->pslot == NULL
3361 || pv->namlen != namlen
3362 || strncmp (pv->name, name, namlen) != 0)
3369 ieee_error (info, start,
3370 _("unrecognized C++ reference type"));
3374 /* Global variable or function. */
3375 if (pv->kind == IEEE_GLOBAL
3376 || pv->kind == IEEE_EXTERNAL
3377 || pv->kind == IEEE_FUNCTION)
3382 /* Global static variable or function. */
3383 if (pv->kind == IEEE_STATIC
3384 || pv->kind == IEEE_FUNCTION)
3389 /* Local variable. */
3390 if (pv->kind == IEEE_LOCAL)
3408 struct ieee_tag *it;
3410 for (it = info->tags; it != NULL; it = it->next)
3412 if (it->name[0] == cxx_class[0]
3413 && strncmp (it->name, cxx_class, classlen) == 0
3414 && strlen (it->name) == classlen)
3416 if (it->fslots != NULL)
3418 const debug_field *pf;
3421 pf = debug_get_fields (info->dhandle, it->type);
3424 ieee_error (info, start,
3425 "C++ reference in class with no fields");
3429 for (findx = 0; *pf != DEBUG_FIELD_NULL; pf++, findx++)
3433 fname = debug_get_field_name (info->dhandle, *pf);
3436 if (strncmp (fname, name, namlen) == 0
3437 && strlen (fname) == namlen)
3439 pslot = it->fslots + findx;
3452 ieee_error (info, start, _("C++ reference not found"));
3456 /* We allocated the type of the object as an indirect type pointing
3457 to *pslot, which we can now update to be a reference type. */
3458 if (debug_get_type_kind (info->dhandle, *pslot) != DEBUG_KIND_POINTER)
3460 ieee_error (info, start, _("C++ reference is not pointer"));
3464 target = debug_get_target_type (info->dhandle, *pslot);
3465 *pslot = debug_make_reference_type (info->dhandle, target);
3466 if (*pslot == DEBUG_TYPE_NULL)
3472 /* Require an ASN record. */
3475 ieee_require_asn (struct ieee_info *info, const bfd_byte **pp, bfd_vma *pv)
3477 const bfd_byte *start;
3478 ieee_record_enum_type c;
3483 c = (ieee_record_enum_type) **pp;
3484 if (c != ieee_e2_first_byte_enum)
3486 ieee_error (info, start, _("missing required ASN"));
3491 c = (ieee_record_enum_type) (((unsigned int) c << 8) | **pp);
3492 if (c != ieee_asn_record_enum)
3494 ieee_error (info, start, _("missing required ASN"));
3499 /* Just ignore the variable index. */
3500 if (! ieee_read_number (info, pp, &varindx))
3503 return ieee_read_expression (info, pp, pv);
3506 /* Require an ATN65 record. */
3509 ieee_require_atn65 (struct ieee_info *info, const bfd_byte **pp,
3510 const char **pname, unsigned long *pnamlen)
3512 const bfd_byte *start;
3513 ieee_record_enum_type c;
3514 bfd_vma name_indx, type_indx, atn_code;
3518 c = (ieee_record_enum_type) **pp;
3519 if (c != ieee_at_record_enum)
3521 ieee_error (info, start, _("missing required ATN65"));
3526 c = (ieee_record_enum_type) (((unsigned int) c << 8) | **pp);
3527 if (c != ieee_atn_record_enum)
3529 ieee_error (info, start, _("missing required ATN65"));
3534 if (! ieee_read_number (info, pp, &name_indx)
3535 || ! ieee_read_number (info, pp, &type_indx)
3536 || ! ieee_read_number (info, pp, &atn_code))
3539 /* Just ignore name_indx. */
3541 if (type_indx != 0 || atn_code != 65)
3543 ieee_error (info, start, _("bad ATN65 record"));
3547 return ieee_read_id (info, pp, pname, pnamlen);
3550 /* Convert a register number in IEEE debugging information into a
3551 generic register number. */
3554 ieee_regno_to_genreg (bfd *abfd, int r)
3556 switch (bfd_get_arch (abfd))
3559 /* For some reasons stabs adds 2 to the floating point register
3566 /* Stabs uses 0 to 15 for r0 to r15, 16 to 31 for g0 to g15, and
3567 32 to 35 for fp0 to fp3. */
3578 /* Convert a generic register number to an IEEE specific one. */
3581 ieee_genreg_to_regno (bfd *abfd, int r)
3583 switch (bfd_get_arch (abfd))
3586 /* For some reason stabs add 2 to the floating point register
3593 /* Stabs uses 0 to 15 for r0 to r15, 16 to 31 for g0 to g15, and
3594 32 to 35 for fp0 to fp3. */
3605 /* These routines build IEEE debugging information out of the generic
3606 debugging information. */
3608 /* We build the IEEE debugging information byte by byte. Rather than
3609 waste time copying data around, we use a linked list of buffers to
3612 #define IEEE_BUFSIZE (490)
3617 struct ieee_buf *next;
3618 /* Number of data bytes in this buffer. */
3621 bfd_byte buf[IEEE_BUFSIZE];
3624 /* A list of buffers. */
3629 struct ieee_buf *head;
3630 /* Tail--last buffer on list. */
3631 struct ieee_buf *tail;
3634 /* In order to generate the BB11 blocks required by the HP emulator,
3635 we keep track of ranges of addresses which correspond to a given
3636 compilation unit. */
3641 struct ieee_range *next;
3648 /* This structure holds information for a class on the type stack. */
3650 struct ieee_type_class
3652 /* The name index in the debugging information. */
3654 /* The pmisc records for the class. */
3655 struct ieee_buflist pmiscbuf;
3656 /* The number of pmisc records. */
3657 unsigned int pmisccount;
3658 /* The name of the class holding the virtual table, if not this
3661 /* Whether this class holds its own virtual table. */
3662 bfd_boolean ownvptr;
3663 /* The largest virtual table offset seen so far. */
3665 /* The current method. */
3667 /* Additional pmisc records used to record fields of reference type. */
3668 struct ieee_buflist refs;
3671 /* This is how we store types for the writing routines. Most types
3672 are simply represented by a type index. */
3674 struct ieee_write_type
3678 /* The size of the type, if known. */
3680 /* The name of the type, if any. */
3682 /* If this is a function or method type, we build the type here, and
3683 only add it to the output buffers if we need it. */
3684 struct ieee_buflist fndef;
3685 /* If this is a struct, this is where the struct definition is
3687 struct ieee_buflist strdef;
3688 /* If this is a class, this is where the class information is built. */
3689 struct ieee_type_class *classdef;
3690 /* Whether the type is unsigned. */
3691 unsigned int unsignedp : 1;
3692 /* Whether this is a reference type. */
3693 unsigned int referencep : 1;
3694 /* Whether this is in the local type block. */
3695 unsigned int localp : 1;
3696 /* Whether this is a duplicate struct definition which we are
3698 unsigned int ignorep : 1;
3701 /* This is the type stack used by the debug writing routines. FIXME:
3702 We could generate more efficient output if we remembered when we
3703 have output a particular type before. */
3705 struct ieee_type_stack
3707 /* Next entry on stack. */
3708 struct ieee_type_stack *next;
3709 /* Type information. */
3710 struct ieee_write_type type;
3713 /* This is a list of associations between a name and some types.
3714 These are used for typedefs and tags. */
3716 struct ieee_name_type
3718 /* Next type for this name. */
3719 struct ieee_name_type *next;
3720 /* ID number. For a typedef, this is the index of the type to which
3721 this name is typedefed. */
3724 struct ieee_write_type type;
3725 /* If this is a tag which has not yet been defined, this is the
3726 kind. If the tag has been defined, this is DEBUG_KIND_ILLEGAL. */
3727 enum debug_type_kind kind;
3730 /* We use a hash table to associate names and types. */
3732 struct ieee_name_type_hash_table
3734 struct bfd_hash_table root;
3737 struct ieee_name_type_hash_entry
3739 struct bfd_hash_entry root;
3740 /* Information for this name. */
3741 struct ieee_name_type *types;
3744 /* This is a list of enums. */
3746 struct ieee_defined_enum
3749 struct ieee_defined_enum *next;
3752 /* Whether this enum has been defined. */
3753 bfd_boolean defined;
3759 bfd_signed_vma *vals;
3762 /* We keep a list of modified versions of types, so that we don't
3763 output them more than once. */
3765 struct ieee_modified_type
3767 /* Pointer to this type. */
3768 unsigned int pointer;
3769 /* Function with unknown arguments returning this type. */
3770 unsigned int function;
3771 /* Const version of this type. */
3772 unsigned int const_qualified;
3773 /* Volatile version of this type. */
3774 unsigned int volatile_qualified;
3775 /* List of arrays of this type of various bounds. */
3776 struct ieee_modified_array_type *arrays;
3779 /* A list of arrays bounds. */
3781 struct ieee_modified_array_type
3783 /* Next array bounds. */
3784 struct ieee_modified_array_type *next;
3785 /* Type index with these bounds. */
3790 bfd_signed_vma high;
3793 /* This is a list of pending function parameter information. We don't
3794 output them until we see the first block. */
3796 struct ieee_pending_parm
3798 /* Next pending parameter. */
3799 struct ieee_pending_parm *next;
3804 /* Whether the type is a reference. */
3805 bfd_boolean referencep;
3807 enum debug_parm_kind kind;
3812 /* This is the handle passed down by debug_write. */
3816 /* BFD we are writing to. */
3818 /* Whether we got an error in a subroutine called via traverse or
3819 map_over_sections. */
3821 /* Current data buffer list. */
3822 struct ieee_buflist *current;
3823 /* Current data buffer. */
3824 struct ieee_buf *curbuf;
3825 /* Filename of current compilation unit. */
3826 const char *filename;
3827 /* Module name of current compilation unit. */
3828 const char *modname;
3829 /* List of buffer for global types. */
3830 struct ieee_buflist global_types;
3831 /* List of finished data buffers. */
3832 struct ieee_buflist data;
3833 /* List of buffers for typedefs in the current compilation unit. */
3834 struct ieee_buflist types;
3835 /* List of buffers for variables and functions in the current
3836 compilation unit. */
3837 struct ieee_buflist vars;
3838 /* List of buffers for C++ class definitions in the current
3839 compilation unit. */
3840 struct ieee_buflist cxx;
3841 /* List of buffers for line numbers in the current compilation unit. */
3842 struct ieee_buflist linenos;
3843 /* Ranges for the current compilation unit. */
3844 struct ieee_range *ranges;
3845 /* Ranges for all debugging information. */
3846 struct ieee_range *global_ranges;
3847 /* Nested pending ranges. */
3848 struct ieee_range *pending_ranges;
3850 struct ieee_type_stack *type_stack;
3851 /* Next unallocated type index. */
3852 unsigned int type_indx;
3853 /* Next unallocated name index. */
3854 unsigned int name_indx;
3856 struct ieee_name_type_hash_table typedefs;
3858 struct ieee_name_type_hash_table tags;
3860 struct ieee_defined_enum *enums;
3861 /* Modified versions of types. */
3862 struct ieee_modified_type *modified;
3863 /* Number of entries allocated in modified. */
3864 unsigned int modified_alloc;
3865 /* 4 byte complex type. */
3866 unsigned int complex_float_index;
3867 /* 8 byte complex type. */
3868 unsigned int complex_double_index;
3869 /* The depth of block nesting. This is 0 outside a function, and 1
3870 just after start_function is called. */
3871 unsigned int block_depth;
3872 /* The name of the current function. */
3874 /* List of buffers for the type of the function we are currently
3876 struct ieee_buflist fntype;
3877 /* List of buffers for the parameters of the function we are
3878 currently writing out. */
3879 struct ieee_buflist fnargs;
3880 /* Number of arguments written to fnargs. */
3881 unsigned int fnargcount;
3882 /* Pending function parameters. */
3883 struct ieee_pending_parm *pending_parms;
3884 /* Current line number filename. */
3885 const char *lineno_filename;
3886 /* Line number name index. */
3887 unsigned int lineno_name_indx;
3888 /* Filename of pending line number. */
3889 const char *pending_lineno_filename;
3890 /* Pending line number. */
3891 unsigned long pending_lineno;
3892 /* Address of pending line number. */
3893 bfd_vma pending_lineno_addr;
3894 /* Highest address seen at end of procedure. */
3898 static bfd_boolean ieee_init_buffer
3899 (struct ieee_handle *, struct ieee_buflist *);
3900 static bfd_boolean ieee_change_buffer
3901 (struct ieee_handle *, struct ieee_buflist *);
3902 static bfd_boolean ieee_append_buffer
3903 (struct ieee_handle *, struct ieee_buflist *, struct ieee_buflist *);
3904 static bfd_boolean ieee_real_write_byte (struct ieee_handle *, int);
3905 static bfd_boolean ieee_write_2bytes (struct ieee_handle *, int);
3906 static bfd_boolean ieee_write_number (struct ieee_handle *, bfd_vma);
3907 static bfd_boolean ieee_write_id (struct ieee_handle *, const char *);
3908 static bfd_boolean ieee_write_asn
3909 (struct ieee_handle *, unsigned int, bfd_vma);
3910 static bfd_boolean ieee_write_atn65
3911 (struct ieee_handle *, unsigned int, const char *);
3912 static bfd_boolean ieee_push_type
3913 (struct ieee_handle *, unsigned int, unsigned int, bfd_boolean,
3915 static unsigned int ieee_pop_type (struct ieee_handle *);
3916 static void ieee_pop_unused_type (struct ieee_handle *);
3917 static unsigned int ieee_pop_type_used (struct ieee_handle *, bfd_boolean);
3918 static bfd_boolean ieee_add_range
3919 (struct ieee_handle *, bfd_boolean, bfd_vma, bfd_vma);
3920 static bfd_boolean ieee_start_range (struct ieee_handle *, bfd_vma);
3921 static bfd_boolean ieee_end_range (struct ieee_handle *, bfd_vma);
3922 static bfd_boolean ieee_define_type
3923 (struct ieee_handle *, unsigned int, bfd_boolean, bfd_boolean);
3924 static bfd_boolean ieee_define_named_type
3925 (struct ieee_handle *, const char *, unsigned int, unsigned int,
3926 bfd_boolean, bfd_boolean, struct ieee_buflist *);
3927 static struct ieee_modified_type *ieee_get_modified_info
3928 (struct ieee_handle *, unsigned int);
3929 static struct bfd_hash_entry *ieee_name_type_newfunc
3930 (struct bfd_hash_entry *, struct bfd_hash_table *, const char *);
3931 static bfd_boolean ieee_write_undefined_tag
3932 (struct ieee_name_type_hash_entry *, void *);
3933 static bfd_boolean ieee_finish_compilation_unit (struct ieee_handle *);
3934 static void ieee_add_bb11_blocks (bfd *, asection *, void *);
3935 static bfd_boolean ieee_add_bb11
3936 (struct ieee_handle *, asection *, bfd_vma, bfd_vma);
3937 static bfd_boolean ieee_output_pending_parms (struct ieee_handle *);
3938 static unsigned int ieee_vis_to_flags (enum debug_visibility);
3939 static bfd_boolean ieee_class_method_var
3940 (struct ieee_handle *, const char *, enum debug_visibility, bfd_boolean,
3941 bfd_boolean, bfd_boolean, bfd_vma, bfd_boolean);
3943 static bfd_boolean ieee_start_compilation_unit (void *, const char *);
3944 static bfd_boolean ieee_start_source (void *, const char *);
3945 static bfd_boolean ieee_empty_type (void *);
3946 static bfd_boolean ieee_void_type (void *);
3947 static bfd_boolean ieee_int_type (void *, unsigned int, bfd_boolean);
3948 static bfd_boolean ieee_float_type (void *, unsigned int);
3949 static bfd_boolean ieee_complex_type (void *, unsigned int);
3950 static bfd_boolean ieee_bool_type (void *, unsigned int);
3951 static bfd_boolean ieee_enum_type
3952 (void *, const char *, const char **, bfd_signed_vma *);
3953 static bfd_boolean ieee_pointer_type (void *);
3954 static bfd_boolean ieee_function_type (void *, int, bfd_boolean);
3955 static bfd_boolean ieee_reference_type (void *);
3956 static bfd_boolean ieee_range_type (void *, bfd_signed_vma, bfd_signed_vma);
3957 static bfd_boolean ieee_array_type
3958 (void *, bfd_signed_vma, bfd_signed_vma, bfd_boolean);
3959 static bfd_boolean ieee_set_type (void *, bfd_boolean);
3960 static bfd_boolean ieee_offset_type (void *);
3961 static bfd_boolean ieee_method_type (void *, bfd_boolean, int, bfd_boolean);
3962 static bfd_boolean ieee_const_type (void *);
3963 static bfd_boolean ieee_volatile_type (void *);
3964 static bfd_boolean ieee_start_struct_type
3965 (void *, const char *, unsigned int, bfd_boolean, unsigned int);
3966 static bfd_boolean ieee_struct_field
3967 (void *, const char *, bfd_vma, bfd_vma, enum debug_visibility);
3968 static bfd_boolean ieee_end_struct_type (void *);
3969 static bfd_boolean ieee_start_class_type
3970 (void *, const char *, unsigned int, bfd_boolean, unsigned int, bfd_boolean,
3972 static bfd_boolean ieee_class_static_member
3973 (void *, const char *, const char *, enum debug_visibility);
3974 static bfd_boolean ieee_class_baseclass
3975 (void *, bfd_vma, bfd_boolean, enum debug_visibility);
3976 static bfd_boolean ieee_class_start_method (void *, const char *);
3977 static bfd_boolean ieee_class_method_variant
3978 (void *, const char *, enum debug_visibility, bfd_boolean, bfd_boolean,
3979 bfd_vma, bfd_boolean);
3980 static bfd_boolean ieee_class_static_method_variant
3981 (void *, const char *, enum debug_visibility, bfd_boolean, bfd_boolean);
3982 static bfd_boolean ieee_class_end_method (void *);
3983 static bfd_boolean ieee_end_class_type (void *);
3984 static bfd_boolean ieee_typedef_type (void *, const char *);
3985 static bfd_boolean ieee_tag_type
3986 (void *, const char *, unsigned int, enum debug_type_kind);
3987 static bfd_boolean ieee_typdef (void *, const char *);
3988 static bfd_boolean ieee_tag (void *, const char *);
3989 static bfd_boolean ieee_int_constant (void *, const char *, bfd_vma);
3990 static bfd_boolean ieee_float_constant (void *, const char *, double);
3991 static bfd_boolean ieee_typed_constant (void *, const char *, bfd_vma);
3992 static bfd_boolean ieee_variable
3993 (void *, const char *, enum debug_var_kind, bfd_vma);
3994 static bfd_boolean ieee_start_function (void *, const char *, bfd_boolean);
3995 static bfd_boolean ieee_function_parameter
3996 (void *, const char *, enum debug_parm_kind, bfd_vma);
3997 static bfd_boolean ieee_start_block (void *, bfd_vma);
3998 static bfd_boolean ieee_end_block (void *, bfd_vma);
3999 static bfd_boolean ieee_end_function (void *);
4000 static bfd_boolean ieee_lineno (void *, const char *, unsigned long, bfd_vma);
4002 static const struct debug_write_fns ieee_fns =
4004 ieee_start_compilation_unit,
4015 ieee_reference_type,
4023 ieee_start_struct_type,
4025 ieee_end_struct_type,
4026 ieee_start_class_type,
4027 ieee_class_static_member,
4028 ieee_class_baseclass,
4029 ieee_class_start_method,
4030 ieee_class_method_variant,
4031 ieee_class_static_method_variant,
4032 ieee_class_end_method,
4033 ieee_end_class_type,
4039 ieee_float_constant,
4040 ieee_typed_constant,
4042 ieee_start_function,
4043 ieee_function_parameter,
4050 /* Initialize a buffer to be empty. */
4053 ieee_init_buffer (struct ieee_handle *info ATTRIBUTE_UNUSED,
4054 struct ieee_buflist *buflist)
4056 buflist->head = NULL;
4057 buflist->tail = NULL;
4061 /* See whether a buffer list has any data. */
4063 #define ieee_buffer_emptyp(buflist) ((buflist)->head == NULL)
4065 /* Change the current buffer to a specified buffer chain. */
4068 ieee_change_buffer (struct ieee_handle *info, struct ieee_buflist *buflist)
4070 if (buflist->head == NULL)
4072 struct ieee_buf *buf;
4074 buf = (struct ieee_buf *) xmalloc (sizeof *buf);
4077 buflist->head = buf;
4078 buflist->tail = buf;
4081 info->current = buflist;
4082 info->curbuf = buflist->tail;
4087 /* Append a buffer chain. */
4090 ieee_append_buffer (struct ieee_handle *info ATTRIBUTE_UNUSED,
4091 struct ieee_buflist *mainbuf,
4092 struct ieee_buflist *newbuf)
4094 if (newbuf->head != NULL)
4096 if (mainbuf->head == NULL)
4097 mainbuf->head = newbuf->head;
4099 mainbuf->tail->next = newbuf->head;
4100 mainbuf->tail = newbuf->tail;
4105 /* Write a byte into the buffer. We use a macro for speed and a
4106 function for the complex cases. */
4108 #define ieee_write_byte(info, b) \
4109 ((info)->curbuf->c < IEEE_BUFSIZE \
4110 ? ((info)->curbuf->buf[(info)->curbuf->c++] = (b), TRUE) \
4111 : ieee_real_write_byte ((info), (b)))
4114 ieee_real_write_byte (struct ieee_handle *info, int b)
4116 if (info->curbuf->c >= IEEE_BUFSIZE)
4120 n = (struct ieee_buf *) xmalloc (sizeof *n);
4123 if (info->current->head == NULL)
4124 info->current->head = n;
4126 info->current->tail->next = n;
4127 info->current->tail = n;
4131 info->curbuf->buf[info->curbuf->c] = b;
4137 /* Write out two bytes. */
4140 ieee_write_2bytes (struct ieee_handle *info, int i)
4142 return (ieee_write_byte (info, i >> 8)
4143 && ieee_write_byte (info, i & 0xff));
4146 /* Write out an integer. */
4149 ieee_write_number (struct ieee_handle *info, bfd_vma v)
4156 if (v <= (bfd_vma) ieee_number_end_enum)
4157 return ieee_write_byte (info, (int) v);
4168 if (c > (unsigned int) (ieee_number_repeat_end_enum
4169 - ieee_number_repeat_start_enum))
4171 fprintf (stderr, _("IEEE numeric overflow: 0x"));
4172 fprintf_vma (stderr, v);
4173 fprintf (stderr, "\n");
4177 if (! ieee_write_byte (info, (int) ieee_number_repeat_start_enum + c))
4179 for (; c > 0; --c, ++p)
4181 if (! ieee_write_byte (info, *p))
4188 /* Write out a string. */
4191 ieee_write_id (struct ieee_handle *info, const char *s)
4198 if (! ieee_write_byte (info, len))
4201 else if (len <= 0xff)
4203 if (! ieee_write_byte (info, (int) ieee_extension_length_1_enum)
4204 || ! ieee_write_byte (info, len))
4207 else if (len <= 0xffff)
4209 if (! ieee_write_byte (info, (int) ieee_extension_length_2_enum)
4210 || ! ieee_write_2bytes (info, len))
4215 fprintf (stderr, _("IEEE string length overflow: %u\n"), len);
4219 for (; *s != '\0'; s++)
4220 if (! ieee_write_byte (info, *s))
4226 /* Write out an ASN record. */
4229 ieee_write_asn (struct ieee_handle *info, unsigned int indx, bfd_vma val)
4231 return (ieee_write_2bytes (info, (int) ieee_asn_record_enum)
4232 && ieee_write_number (info, indx)
4233 && ieee_write_number (info, val));
4236 /* Write out an ATN65 record. */
4239 ieee_write_atn65 (struct ieee_handle *info, unsigned int indx, const char *s)
4241 return (ieee_write_2bytes (info, (int) ieee_atn_record_enum)
4242 && ieee_write_number (info, indx)
4243 && ieee_write_number (info, 0)
4244 && ieee_write_number (info, 65)
4245 && ieee_write_id (info, s));
4248 /* Push a type index onto the type stack. */
4251 ieee_push_type (struct ieee_handle *info, unsigned int indx,
4252 unsigned int size, bfd_boolean unsignedp, bfd_boolean localp)
4254 struct ieee_type_stack *ts;
4256 ts = (struct ieee_type_stack *) xmalloc (sizeof *ts);
4257 memset (ts, 0, sizeof *ts);
4259 ts->type.indx = indx;
4260 ts->type.size = size;
4261 ts->type.unsignedp = unsignedp;
4262 ts->type.localp = localp;
4264 ts->next = info->type_stack;
4265 info->type_stack = ts;
4270 /* Pop a type index off the type stack. */
4273 ieee_pop_type (struct ieee_handle *info)
4275 return ieee_pop_type_used (info, TRUE);
4278 /* Pop an unused type index off the type stack. */
4281 ieee_pop_unused_type (struct ieee_handle *info)
4283 (void) ieee_pop_type_used (info, FALSE);
4286 /* Pop a used or unused type index off the type stack. */
4289 ieee_pop_type_used (struct ieee_handle *info, bfd_boolean used)
4291 struct ieee_type_stack *ts;
4294 ts = info->type_stack;
4295 assert (ts != NULL);
4297 /* If this is a function type, and we need it, we need to append the
4298 actual definition to the typedef block now. */
4299 if (used && ! ieee_buffer_emptyp (&ts->type.fndef))
4301 struct ieee_buflist *buflist;
4303 if (ts->type.localp)
4305 /* Make sure we have started the types block. */
4306 if (ieee_buffer_emptyp (&info->types))
4308 if (! ieee_change_buffer (info, &info->types)
4309 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
4310 || ! ieee_write_byte (info, 1)
4311 || ! ieee_write_number (info, 0)
4312 || ! ieee_write_id (info, info->modname))
4315 buflist = &info->types;
4319 /* Make sure we started the global type block. */
4320 if (ieee_buffer_emptyp (&info->global_types))
4322 if (! ieee_change_buffer (info, &info->global_types)
4323 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
4324 || ! ieee_write_byte (info, 2)
4325 || ! ieee_write_number (info, 0)
4326 || ! ieee_write_id (info, ""))
4329 buflist = &info->global_types;
4332 if (! ieee_append_buffer (info, buflist, &ts->type.fndef))
4336 ret = ts->type.indx;
4337 info->type_stack = ts->next;
4342 /* Add a range of bytes included in the current compilation unit. */
4345 ieee_add_range (struct ieee_handle *info, bfd_boolean global, bfd_vma low,
4348 struct ieee_range **plist, *r, **pr;
4350 if (low == (bfd_vma) -1 || high == (bfd_vma) -1 || low == high)
4354 plist = &info->global_ranges;
4356 plist = &info->ranges;
4358 for (r = *plist; r != NULL; r = r->next)
4360 if (high >= r->low && low <= r->high)
4362 /* The new range overlaps r. */
4368 while (*pr != NULL && (*pr)->low <= r->high)
4370 struct ieee_range *n;
4372 if ((*pr)->high > r->high)
4373 r->high = (*pr)->high;
4382 r = (struct ieee_range *) xmalloc (sizeof *r);
4383 memset (r, 0, sizeof *r);
4388 /* Store the ranges sorted by address. */
4389 for (pr = plist; *pr != NULL; pr = &(*pr)->next)
4390 if ((*pr)->low > high)
4398 /* Start a new range for which we only have the low address. */
4401 ieee_start_range (struct ieee_handle *info, bfd_vma low)
4403 struct ieee_range *r;
4405 r = (struct ieee_range *) xmalloc (sizeof *r);
4406 memset (r, 0, sizeof *r);
4408 r->next = info->pending_ranges;
4409 info->pending_ranges = r;
4413 /* Finish a range started by ieee_start_range. */
4416 ieee_end_range (struct ieee_handle *info, bfd_vma high)
4418 struct ieee_range *r;
4421 assert (info->pending_ranges != NULL);
4422 r = info->pending_ranges;
4424 info->pending_ranges = r->next;
4426 return ieee_add_range (info, FALSE, low, high);
4429 /* Start defining a type. */
4432 ieee_define_type (struct ieee_handle *info, unsigned int size,
4433 bfd_boolean unsignedp, bfd_boolean localp)
4435 return ieee_define_named_type (info, (const char *) NULL,
4436 (unsigned int) -1, size, unsignedp,
4437 localp, (struct ieee_buflist *) NULL);
4440 /* Start defining a named type. */
4443 ieee_define_named_type (struct ieee_handle *info, const char *name,
4444 unsigned int indx, unsigned int size,
4445 bfd_boolean unsignedp, bfd_boolean localp,
4446 struct ieee_buflist *buflist)
4448 unsigned int type_indx;
4449 unsigned int name_indx;
4451 if (indx != (unsigned int) -1)
4455 type_indx = info->type_indx;
4459 name_indx = info->name_indx;
4465 /* If we were given a buffer, use it; otherwise, use either the
4466 local or the global type information, and make sure that the type
4467 block is started. */
4468 if (buflist != NULL)
4470 if (! ieee_change_buffer (info, buflist))
4475 if (! ieee_buffer_emptyp (&info->types))
4477 if (! ieee_change_buffer (info, &info->types))
4482 if (! ieee_change_buffer (info, &info->types)
4483 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
4484 || ! ieee_write_byte (info, 1)
4485 || ! ieee_write_number (info, 0)
4486 || ! ieee_write_id (info, info->modname))
4492 if (! ieee_buffer_emptyp (&info->global_types))
4494 if (! ieee_change_buffer (info, &info->global_types))
4499 if (! ieee_change_buffer (info, &info->global_types)
4500 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
4501 || ! ieee_write_byte (info, 2)
4502 || ! ieee_write_number (info, 0)
4503 || ! ieee_write_id (info, ""))
4508 /* Push the new type on the type stack, write out an NN record, and
4509 write out the start of a TY record. The caller will then finish
4511 if (! ieee_push_type (info, type_indx, size, unsignedp, localp))
4514 return (ieee_write_byte (info, (int) ieee_nn_record)
4515 && ieee_write_number (info, name_indx)
4516 && ieee_write_id (info, name)
4517 && ieee_write_byte (info, (int) ieee_ty_record_enum)
4518 && ieee_write_number (info, type_indx)
4519 && ieee_write_byte (info, 0xce)
4520 && ieee_write_number (info, name_indx));
4523 /* Get an entry to the list of modified versions of a type. */
4525 static struct ieee_modified_type *
4526 ieee_get_modified_info (struct ieee_handle *info, unsigned int indx)
4528 if (indx >= info->modified_alloc)
4530 unsigned int nalloc;
4532 nalloc = info->modified_alloc;
4535 while (indx >= nalloc)
4537 info->modified = ((struct ieee_modified_type *)
4538 xrealloc (info->modified,
4539 nalloc * sizeof *info->modified));
4540 memset (info->modified + info->modified_alloc, 0,
4541 (nalloc - info->modified_alloc) * sizeof *info->modified);
4542 info->modified_alloc = nalloc;
4545 return info->modified + indx;
4548 /* Routines for the hash table mapping names to types. */
4550 /* Initialize an entry in the hash table. */
4552 static struct bfd_hash_entry *
4553 ieee_name_type_newfunc (struct bfd_hash_entry *entry,
4554 struct bfd_hash_table *table, const char *string)
4556 struct ieee_name_type_hash_entry *ret =
4557 (struct ieee_name_type_hash_entry *) entry;
4559 /* Allocate the structure if it has not already been allocated by a
4562 ret = ((struct ieee_name_type_hash_entry *)
4563 bfd_hash_allocate (table, sizeof *ret));
4567 /* Call the allocation method of the superclass. */
4568 ret = ((struct ieee_name_type_hash_entry *)
4569 bfd_hash_newfunc ((struct bfd_hash_entry *) ret, table, string));
4572 /* Set local fields. */
4576 return (struct bfd_hash_entry *) ret;
4579 /* Look up an entry in the hash table. */
4581 #define ieee_name_type_hash_lookup(table, string, create, copy) \
4582 ((struct ieee_name_type_hash_entry *) \
4583 bfd_hash_lookup (&(table)->root, (string), (create), (copy)))
4585 /* Traverse the hash table. */
4587 #define ieee_name_type_hash_traverse(table, func, info) \
4588 (bfd_hash_traverse \
4590 (bfd_boolean (*) (struct bfd_hash_entry *, void *)) (func), \
4593 /* The general routine to write out IEEE debugging information. */
4596 write_ieee_debugging_info (bfd *abfd, void *dhandle)
4598 struct ieee_handle info;
4603 memset (&info, 0, sizeof info);
4605 info.type_indx = 256;
4606 info.name_indx = 32;
4608 if (!bfd_hash_table_init (&info.typedefs.root, ieee_name_type_newfunc,
4609 sizeof (struct ieee_name_type_hash_entry))
4610 || !bfd_hash_table_init (&info.tags.root, ieee_name_type_newfunc,
4611 sizeof (struct ieee_name_type_hash_entry)))
4614 if (! ieee_init_buffer (&info, &info.global_types)
4615 || ! ieee_init_buffer (&info, &info.data)
4616 || ! ieee_init_buffer (&info, &info.types)
4617 || ! ieee_init_buffer (&info, &info.vars)
4618 || ! ieee_init_buffer (&info, &info.cxx)
4619 || ! ieee_init_buffer (&info, &info.linenos)
4620 || ! ieee_init_buffer (&info, &info.fntype)
4621 || ! ieee_init_buffer (&info, &info.fnargs))
4624 if (! debug_write (dhandle, &ieee_fns, (void *) &info))
4627 if (info.filename != NULL)
4629 if (! ieee_finish_compilation_unit (&info))
4633 /* Put any undefined tags in the global typedef information. */
4635 ieee_name_type_hash_traverse (&info.tags,
4636 ieee_write_undefined_tag,
4641 /* Prepend the global typedef information to the other data. */
4642 if (! ieee_buffer_emptyp (&info.global_types))
4644 /* The HP debugger seems to have a bug in which it ignores the
4645 last entry in the global types, so we add a dummy entry. */
4646 if (! ieee_change_buffer (&info, &info.global_types)
4647 || ! ieee_write_byte (&info, (int) ieee_nn_record)
4648 || ! ieee_write_number (&info, info.name_indx)
4649 || ! ieee_write_id (&info, "")
4650 || ! ieee_write_byte (&info, (int) ieee_ty_record_enum)
4651 || ! ieee_write_number (&info, info.type_indx)
4652 || ! ieee_write_byte (&info, 0xce)
4653 || ! ieee_write_number (&info, info.name_indx)
4654 || ! ieee_write_number (&info, 'P')
4655 || ! ieee_write_number (&info, (int) builtin_void + 32)
4656 || ! ieee_write_byte (&info, (int) ieee_be_record_enum))
4659 if (! ieee_append_buffer (&info, &info.global_types, &info.data))
4661 info.data = info.global_types;
4664 /* Make sure that we have declare BB11 blocks for each range in the
4665 file. They are added to info->vars. */
4667 if (! ieee_init_buffer (&info, &info.vars))
4669 bfd_map_over_sections (abfd, ieee_add_bb11_blocks, (void *) &info);
4672 if (! ieee_buffer_emptyp (&info.vars))
4674 if (! ieee_change_buffer (&info, &info.vars)
4675 || ! ieee_write_byte (&info, (int) ieee_be_record_enum))
4678 if (! ieee_append_buffer (&info, &info.data, &info.vars))
4682 /* Now all the data is in info.data. Write it out to the BFD. We
4683 normally would need to worry about whether all the other sections
4684 are set up yet, but the IEEE backend will handle this particular
4685 case correctly regardless. */
4686 if (ieee_buffer_emptyp (&info.data))
4688 /* There is no debugging information. */
4692 s = bfd_make_section_with_flags (abfd, ".debug",
4693 SEC_DEBUGGING | SEC_HAS_CONTENTS);
4695 err = "bfd_make_section";
4701 for (b = info.data.head; b != NULL; b = b->next)
4703 if (! bfd_set_section_size (abfd, s, size))
4704 err = "bfd_set_section_size";
4711 for (b = info.data.head; b != NULL; b = b->next)
4713 if (! bfd_set_section_contents (abfd, s, b->buf, offset, b->c))
4715 err = "bfd_set_section_contents";
4724 fprintf (stderr, "%s: %s: %s\n", bfd_get_filename (abfd), err,
4725 bfd_errmsg (bfd_get_error ()));
4729 bfd_hash_table_free (&info.typedefs.root);
4730 bfd_hash_table_free (&info.tags.root);
4735 /* Write out information for an undefined tag. This is called via
4736 ieee_name_type_hash_traverse. */
4739 ieee_write_undefined_tag (struct ieee_name_type_hash_entry *h, void *p)
4741 struct ieee_handle *info = (struct ieee_handle *) p;
4742 struct ieee_name_type *nt;
4744 for (nt = h->types; nt != NULL; nt = nt->next)
4746 unsigned int name_indx;
4749 if (nt->kind == DEBUG_KIND_ILLEGAL)
4752 if (ieee_buffer_emptyp (&info->global_types))
4754 if (! ieee_change_buffer (info, &info->global_types)
4755 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
4756 || ! ieee_write_byte (info, 2)
4757 || ! ieee_write_number (info, 0)
4758 || ! ieee_write_id (info, ""))
4766 if (! ieee_change_buffer (info, &info->global_types))
4773 name_indx = info->name_indx;
4775 if (! ieee_write_byte (info, (int) ieee_nn_record)
4776 || ! ieee_write_number (info, name_indx)
4777 || ! ieee_write_id (info, nt->type.name)
4778 || ! ieee_write_byte (info, (int) ieee_ty_record_enum)
4779 || ! ieee_write_number (info, nt->type.indx)
4780 || ! ieee_write_byte (info, 0xce)
4781 || ! ieee_write_number (info, name_indx))
4793 case DEBUG_KIND_STRUCT:
4794 case DEBUG_KIND_CLASS:
4797 case DEBUG_KIND_UNION:
4798 case DEBUG_KIND_UNION_CLASS:
4801 case DEBUG_KIND_ENUM:
4805 if (! ieee_write_number (info, code)
4806 || ! ieee_write_number (info, 0))
4816 /* Start writing out information for a compilation unit. */
4819 ieee_start_compilation_unit (void *p, const char *filename)
4821 struct ieee_handle *info = (struct ieee_handle *) p;
4822 const char *modname;
4823 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
4824 const char *backslash;
4828 if (info->filename != NULL)
4830 if (! ieee_finish_compilation_unit (info))
4834 info->filename = filename;
4835 modname = strrchr (filename, '/');
4836 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
4837 /* We could have a mixed forward/back slash case. */
4838 backslash = strrchr (filename, '\\');
4839 if (modname == NULL || (backslash != NULL && backslash > modname))
4840 modname = backslash;
4843 if (modname != NULL)
4845 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
4846 else if (filename[0] && filename[1] == ':')
4847 modname = filename + 2;
4852 c = xstrdup (modname);
4853 s = strrchr (c, '.');
4858 if (! ieee_init_buffer (info, &info->types)
4859 || ! ieee_init_buffer (info, &info->vars)
4860 || ! ieee_init_buffer (info, &info->cxx)
4861 || ! ieee_init_buffer (info, &info->linenos))
4863 info->ranges = NULL;
4865 /* Always include a BB1 and a BB3 block. That is what the output of
4866 the MRI linker seems to look like. */
4867 if (! ieee_change_buffer (info, &info->types)
4868 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
4869 || ! ieee_write_byte (info, 1)
4870 || ! ieee_write_number (info, 0)
4871 || ! ieee_write_id (info, info->modname))
4875 if (! ieee_change_buffer (info, &info->vars)
4876 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
4877 || ! ieee_write_byte (info, 3)
4878 || ! ieee_write_number (info, 0)
4879 || ! ieee_write_id (info, info->modname))
4885 /* Finish up a compilation unit. */
4888 ieee_finish_compilation_unit (struct ieee_handle *info)
4890 struct ieee_range *r;
4892 if (! ieee_buffer_emptyp (&info->types))
4894 if (! ieee_change_buffer (info, &info->types)
4895 || ! ieee_write_byte (info, (int) ieee_be_record_enum))
4899 if (! ieee_buffer_emptyp (&info->cxx))
4901 /* Append any C++ information to the global function and
4902 variable information. */
4903 assert (! ieee_buffer_emptyp (&info->vars));
4904 if (! ieee_change_buffer (info, &info->vars))
4907 /* We put the pmisc records in a dummy procedure, just as the
4908 MRI compiler does. */
4909 if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
4910 || ! ieee_write_byte (info, 6)
4911 || ! ieee_write_number (info, 0)
4912 || ! ieee_write_id (info, "__XRYCPP")
4913 || ! ieee_write_number (info, 0)
4914 || ! ieee_write_number (info, 0)
4915 || ! ieee_write_number (info, info->highaddr - 1)
4916 || ! ieee_append_buffer (info, &info->vars, &info->cxx)
4917 || ! ieee_change_buffer (info, &info->vars)
4918 || ! ieee_write_byte (info, (int) ieee_be_record_enum)
4919 || ! ieee_write_number (info, info->highaddr - 1))
4923 if (! ieee_buffer_emptyp (&info->vars))
4925 if (! ieee_change_buffer (info, &info->vars)
4926 || ! ieee_write_byte (info, (int) ieee_be_record_enum))
4930 if (info->pending_lineno_filename != NULL)
4932 /* Force out the pending line number. */
4933 if (! ieee_lineno ((void *) info, (const char *) NULL, 0, (bfd_vma) -1))
4936 if (! ieee_buffer_emptyp (&info->linenos))
4938 if (! ieee_change_buffer (info, &info->linenos)
4939 || ! ieee_write_byte (info, (int) ieee_be_record_enum))
4941 if (filename_cmp (info->filename, info->lineno_filename) != 0)
4943 /* We were not in the main file. We just closed the
4944 included line number block, and now we must close the
4945 main line number block. */
4946 if (! ieee_write_byte (info, (int) ieee_be_record_enum))
4951 if (! ieee_append_buffer (info, &info->data, &info->types)
4952 || ! ieee_append_buffer (info, &info->data, &info->vars)
4953 || ! ieee_append_buffer (info, &info->data, &info->linenos))
4956 /* Build BB10/BB11 blocks based on the ranges we recorded. */
4957 if (! ieee_change_buffer (info, &info->data))
4960 if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
4961 || ! ieee_write_byte (info, 10)
4962 || ! ieee_write_number (info, 0)
4963 || ! ieee_write_id (info, info->modname)
4964 || ! ieee_write_id (info, "")
4965 || ! ieee_write_number (info, 0)
4966 || ! ieee_write_id (info, "GNU objcopy"))
4969 for (r = info->ranges; r != NULL; r = r->next)
4978 /* Find the section corresponding to this range. */
4979 for (s = info->abfd->sections; s != NULL; s = s->next)
4981 if (bfd_get_section_vma (info->abfd, s) <= low
4982 && high <= (bfd_get_section_vma (info->abfd, s)
4983 + bfd_section_size (info->abfd, s)))
4989 /* Just ignore this range. */
4993 /* Coalesce ranges if it seems reasonable. */
4994 while (r->next != NULL
4995 && high + 0x1000 >= r->next->low
4997 <= (bfd_get_section_vma (info->abfd, s)
4998 + bfd_section_size (info->abfd, s))))
5004 if ((s->flags & SEC_CODE) != 0)
5006 else if ((s->flags & SEC_READONLY) != 0)
5011 if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
5012 || ! ieee_write_byte (info, 11)
5013 || ! ieee_write_number (info, 0)
5014 || ! ieee_write_id (info, "")
5015 || ! ieee_write_number (info, kind)
5016 || ! ieee_write_number (info, s->index + IEEE_SECTION_NUMBER_BASE)
5017 || ! ieee_write_number (info, low)
5018 || ! ieee_write_byte (info, (int) ieee_be_record_enum)
5019 || ! ieee_write_number (info, high - low))
5022 /* Add this range to the list of global ranges. */
5023 if (! ieee_add_range (info, TRUE, low, high))
5027 if (! ieee_write_byte (info, (int) ieee_be_record_enum))
5033 /* Add BB11 blocks describing each range that we have not already
5037 ieee_add_bb11_blocks (bfd *abfd ATTRIBUTE_UNUSED, asection *sec, void *data)
5039 struct ieee_handle *info = (struct ieee_handle *) data;
5041 struct ieee_range *r;
5043 low = bfd_get_section_vma (abfd, sec);
5044 high = low + bfd_section_size (abfd, sec);
5046 /* Find the first range at or after this section. The ranges are
5047 sorted by address. */
5048 for (r = info->global_ranges; r != NULL; r = r->next)
5054 if (r == NULL || r->low >= high)
5056 if (! ieee_add_bb11 (info, sec, low, high))
5062 && r->low - low > 0x100)
5064 if (! ieee_add_bb11 (info, sec, low, r->low))
5076 /* Add a single BB11 block for a range. We add it to info->vars. */
5079 ieee_add_bb11 (struct ieee_handle *info, asection *sec, bfd_vma low,
5084 if (! ieee_buffer_emptyp (&info->vars))
5086 if (! ieee_change_buffer (info, &info->vars))
5091 const char *filename, *modname;
5092 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
5093 const char *backslash;
5097 /* Start the enclosing BB10 block. */
5098 filename = bfd_get_filename (info->abfd);
5099 modname = strrchr (filename, '/');
5100 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
5101 backslash = strrchr (filename, '\\');
5102 if (modname == NULL || (backslash != NULL && backslash > modname))
5103 modname = backslash;
5106 if (modname != NULL)
5108 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
5109 else if (filename[0] && filename[1] == ':')
5110 modname = filename + 2;
5115 c = xstrdup (modname);
5116 s = strrchr (c, '.');
5120 if (! ieee_change_buffer (info, &info->vars)
5121 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
5122 || ! ieee_write_byte (info, 10)
5123 || ! ieee_write_number (info, 0)
5124 || ! ieee_write_id (info, c)
5125 || ! ieee_write_id (info, "")
5126 || ! ieee_write_number (info, 0)
5127 || ! ieee_write_id (info, "GNU objcopy"))
5136 if ((sec->flags & SEC_CODE) != 0)
5138 else if ((sec->flags & SEC_READONLY) != 0)
5143 if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
5144 || ! ieee_write_byte (info, 11)
5145 || ! ieee_write_number (info, 0)
5146 || ! ieee_write_id (info, "")
5147 || ! ieee_write_number (info, kind)
5148 || ! ieee_write_number (info, sec->index + IEEE_SECTION_NUMBER_BASE)
5149 || ! ieee_write_number (info, low)
5150 || ! ieee_write_byte (info, (int) ieee_be_record_enum)
5151 || ! ieee_write_number (info, high - low))
5157 /* Start recording information from a particular source file. This is
5158 used to record which file defined which types, variables, etc. It
5159 is not used for line numbers, since the lineno entry point passes
5160 down the file name anyhow. IEEE debugging information doesn't seem
5161 to store this information anywhere. */
5164 ieee_start_source (void *p ATTRIBUTE_UNUSED,
5165 const char *filename ATTRIBUTE_UNUSED)
5170 /* Make an empty type. */
5173 ieee_empty_type (void *p)
5175 struct ieee_handle *info = (struct ieee_handle *) p;
5177 return ieee_push_type (info, (int) builtin_unknown, 0, FALSE, FALSE);
5180 /* Make a void type. */
5183 ieee_void_type (void *p)
5185 struct ieee_handle *info = (struct ieee_handle *) p;
5187 return ieee_push_type (info, (int) builtin_void, 0, FALSE, FALSE);
5190 /* Make an integer type. */
5193 ieee_int_type (void *p, unsigned int size, bfd_boolean unsignedp)
5195 struct ieee_handle *info = (struct ieee_handle *) p;
5201 indx = (int) builtin_signed_char;
5204 indx = (int) builtin_signed_short_int;
5207 indx = (int) builtin_signed_long;
5210 indx = (int) builtin_signed_long_long;
5213 fprintf (stderr, _("IEEE unsupported integer type size %u\n"), size);
5220 return ieee_push_type (info, indx, size, unsignedp, FALSE);
5223 /* Make a floating point type. */
5226 ieee_float_type (void *p, unsigned int size)
5228 struct ieee_handle *info = (struct ieee_handle *) p;
5234 indx = (int) builtin_float;
5237 indx = (int) builtin_double;
5240 /* FIXME: This size really depends upon the processor. */
5241 indx = (int) builtin_long_double;
5244 indx = (int) builtin_long_long_double;
5247 fprintf (stderr, _("IEEE unsupported float type size %u\n"), size);
5251 return ieee_push_type (info, indx, size, FALSE, FALSE);
5254 /* Make a complex type. */
5257 ieee_complex_type (void *p, unsigned int size)
5259 struct ieee_handle *info = (struct ieee_handle *) p;
5265 if (info->complex_float_index != 0)
5266 return ieee_push_type (info, info->complex_float_index, size * 2,
5272 /* These cases can be output by gcc -gstabs. Outputting the
5273 wrong type is better than crashing. */
5275 if (info->complex_double_index != 0)
5276 return ieee_push_type (info, info->complex_double_index, size * 2,
5281 fprintf (stderr, _("IEEE unsupported complex type size %u\n"), size);
5285 /* FIXME: I don't know what the string is for. */
5286 if (! ieee_define_type (info, size * 2, FALSE, FALSE)
5287 || ! ieee_write_number (info, code)
5288 || ! ieee_write_id (info, ""))
5292 info->complex_float_index = info->type_stack->type.indx;
5294 info->complex_double_index = info->type_stack->type.indx;
5299 /* Make a boolean type. IEEE doesn't support these, so we just make
5300 an integer type instead. */
5303 ieee_bool_type (void *p, unsigned int size)
5305 return ieee_int_type (p, size, TRUE);
5308 /* Make an enumeration. */
5311 ieee_enum_type (void *p, const char *tag, const char **names,
5312 bfd_signed_vma *vals)
5314 struct ieee_handle *info = (struct ieee_handle *) p;
5315 struct ieee_defined_enum *e;
5316 bfd_boolean localp, simple;
5321 indx = (unsigned int) -1;
5322 for (e = info->enums; e != NULL; e = e->next)
5332 || tag[0] != e->tag[0]
5333 || strcmp (tag, e->tag) != 0)
5339 /* This enum tag has been seen but not defined. */
5344 if (names != NULL && e->names != NULL)
5346 for (i = 0; names[i] != NULL && e->names[i] != NULL; i++)
5348 if (names[i][0] != e->names[i][0]
5349 || vals[i] != e->vals[i]
5350 || strcmp (names[i], e->names[i]) != 0)
5355 if ((names == NULL && e->names == NULL)
5359 && e->names[i] == NULL))
5361 /* We've seen this enum before. */
5362 return ieee_push_type (info, e->indx, 0, TRUE, FALSE);
5367 /* We've already seen an enum of the same name, so we must make
5368 sure to output this one locally. */
5374 /* If this is a simple enumeration, in which the values start at 0
5375 and always increment by 1, we can use type E. Otherwise we must
5381 for (i = 0; names[i] != NULL; i++)
5391 if (! ieee_define_named_type (info, tag, indx, 0, TRUE, localp,
5392 (struct ieee_buflist *) NULL)
5393 || ! ieee_write_number (info, simple ? 'E' : 'N'))
5397 /* FIXME: This is supposed to be the enumeration size, but we
5398 don't store that. */
5399 if (! ieee_write_number (info, 4))
5404 for (i = 0; names[i] != NULL; i++)
5406 if (! ieee_write_id (info, names[i]))
5410 if (! ieee_write_number (info, vals[i]))
5418 if (indx == (unsigned int) -1)
5420 e = (struct ieee_defined_enum *) xmalloc (sizeof *e);
5421 memset (e, 0, sizeof *e);
5422 e->indx = info->type_stack->type.indx;
5425 e->next = info->enums;
5437 /* Make a pointer type. */
5440 ieee_pointer_type (void *p)
5442 struct ieee_handle *info = (struct ieee_handle *) p;
5445 struct ieee_modified_type *m = NULL;
5447 localp = info->type_stack->type.localp;
5448 indx = ieee_pop_type (info);
5450 /* A pointer to a simple builtin type can be obtained by adding 32.
5451 FIXME: Will this be a short pointer, and will that matter? */
5453 return ieee_push_type (info, indx + 32, 0, TRUE, FALSE);
5457 m = ieee_get_modified_info ((struct ieee_handle *) p, indx);
5461 /* FIXME: The size should depend upon the architecture. */
5463 return ieee_push_type (info, m->pointer, 4, TRUE, FALSE);
5466 if (! ieee_define_type (info, 4, TRUE, localp)
5467 || ! ieee_write_number (info, 'P')
5468 || ! ieee_write_number (info, indx))
5472 m->pointer = info->type_stack->type.indx;
5477 /* Make a function type. This will be called for a method, but we
5478 don't want to actually add it to the type table in that case. We
5479 handle this by defining the type in a private buffer, and only
5480 adding that buffer to the typedef block if we are going to use it. */
5483 ieee_function_type (void *p, int argcount, bfd_boolean varargs)
5485 struct ieee_handle *info = (struct ieee_handle *) p;
5487 unsigned int *args = NULL;
5489 unsigned int retindx;
5490 struct ieee_buflist fndef;
5491 struct ieee_modified_type *m;
5497 args = (unsigned int *) xmalloc (argcount * sizeof *args);
5498 for (i = argcount - 1; i >= 0; i--)
5500 if (info->type_stack->type.localp)
5502 args[i] = ieee_pop_type (info);
5505 else if (argcount < 0)
5508 if (info->type_stack->type.localp)
5510 retindx = ieee_pop_type (info);
5513 if (argcount < 0 && ! localp)
5515 m = ieee_get_modified_info ((struct ieee_handle *) p, retindx);
5519 if (m->function > 0)
5520 return ieee_push_type (info, m->function, 0, TRUE, FALSE);
5523 /* An attribute of 0x41 means that the frame and push mask are
5525 if (! ieee_init_buffer (info, &fndef)
5526 || ! ieee_define_named_type (info, (const char *) NULL,
5527 (unsigned int) -1, 0, TRUE, localp,
5529 || ! ieee_write_number (info, 'x')
5530 || ! ieee_write_number (info, 0x41)
5531 || ! ieee_write_number (info, 0)
5532 || ! ieee_write_number (info, 0)
5533 || ! ieee_write_number (info, retindx)
5534 || ! ieee_write_number (info, (bfd_vma) argcount + (varargs ? 1 : 0)))
5541 for (i = 0; i < argcount; i++)
5542 if (! ieee_write_number (info, args[i]))
5548 /* A varargs function is represented by writing out the last
5549 argument as type void *, although this makes little sense. */
5550 if (! ieee_write_number (info, (bfd_vma) builtin_void + 32))
5554 if (! ieee_write_number (info, 0))
5557 /* We wrote the information into fndef, in case we don't need it.
5558 It will be appended to info->types by ieee_pop_type. */
5559 info->type_stack->type.fndef = fndef;
5562 m->function = info->type_stack->type.indx;
5567 /* Make a reference type. */
5570 ieee_reference_type (void *p)
5572 struct ieee_handle *info = (struct ieee_handle *) p;
5574 /* IEEE appears to record a normal pointer type, and then use a
5575 pmisc record to indicate that it is really a reference. */
5577 if (! ieee_pointer_type (p))
5579 info->type_stack->type.referencep = TRUE;
5583 /* Make a range type. */
5586 ieee_range_type (void *p, bfd_signed_vma low, bfd_signed_vma high)
5588 struct ieee_handle *info = (struct ieee_handle *) p;
5590 bfd_boolean unsignedp, localp;
5592 size = info->type_stack->type.size;
5593 unsignedp = info->type_stack->type.unsignedp;
5594 localp = info->type_stack->type.localp;
5595 ieee_pop_unused_type (info);
5596 return (ieee_define_type (info, size, unsignedp, localp)
5597 && ieee_write_number (info, 'R')
5598 && ieee_write_number (info, (bfd_vma) low)
5599 && ieee_write_number (info, (bfd_vma) high)
5600 && ieee_write_number (info, unsignedp ? 0 : 1)
5601 && ieee_write_number (info, size));
5604 /* Make an array type. */
5607 ieee_array_type (void *p, bfd_signed_vma low, bfd_signed_vma high,
5608 bfd_boolean stringp ATTRIBUTE_UNUSED)
5610 struct ieee_handle *info = (struct ieee_handle *) p;
5611 unsigned int eleindx;
5614 struct ieee_modified_type *m = NULL;
5615 struct ieee_modified_array_type *a;
5617 /* IEEE does not store the range, so we just ignore it. */
5618 ieee_pop_unused_type (info);
5619 localp = info->type_stack->type.localp;
5620 size = info->type_stack->type.size;
5621 eleindx = ieee_pop_type (info);
5623 /* If we don't know the range, treat the size as exactly one
5626 size *= (high - low) + 1;
5630 m = ieee_get_modified_info (info, eleindx);
5634 for (a = m->arrays; a != NULL; a = a->next)
5636 if (a->low == low && a->high == high)
5637 return ieee_push_type (info, a->indx, size, FALSE, FALSE);
5641 if (! ieee_define_type (info, size, FALSE, localp)
5642 || ! ieee_write_number (info, low == 0 ? 'Z' : 'C')
5643 || ! ieee_write_number (info, eleindx))
5647 if (! ieee_write_number (info, low))
5651 if (! ieee_write_number (info, high + 1))
5656 a = (struct ieee_modified_array_type *) xmalloc (sizeof *a);
5657 memset (a, 0, sizeof *a);
5659 a->indx = info->type_stack->type.indx;
5663 a->next = m->arrays;
5670 /* Make a set type. */
5673 ieee_set_type (void *p, bfd_boolean bitstringp ATTRIBUTE_UNUSED)
5675 struct ieee_handle *info = (struct ieee_handle *) p;
5677 unsigned int eleindx;
5679 localp = info->type_stack->type.localp;
5680 eleindx = ieee_pop_type (info);
5682 /* FIXME: We don't know the size, so we just use 4. */
5684 return (ieee_define_type (info, 0, TRUE, localp)
5685 && ieee_write_number (info, 's')
5686 && ieee_write_number (info, 4)
5687 && ieee_write_number (info, eleindx));
5690 /* Make an offset type. */
5693 ieee_offset_type (void *p)
5695 /* FIXME: The MRI C++ compiler does not appear to generate any
5696 useful type information about an offset type. It just records a
5697 pointer to member as an integer. The MRI/HP IEEE spec does
5698 describe a pmisc record which can be used for a pointer to
5699 member. Unfortunately, it does not describe the target type,
5700 which seems pretty important. I'm going to punt this for now. */
5702 return ieee_int_type (p, 4, TRUE);
5705 /* Make a method type. */
5708 ieee_method_type (void *p, bfd_boolean domain, int argcount,
5709 bfd_boolean varargs)
5711 struct ieee_handle *info = (struct ieee_handle *) p;
5713 /* FIXME: The MRI/HP IEEE spec defines a pmisc record to use for a
5714 method, but the definition is incomplete. We just output an 'x'
5718 ieee_pop_unused_type (info);
5720 return ieee_function_type (p, argcount, varargs);
5723 /* Make a const qualified type. */
5726 ieee_const_type (void *p)
5728 struct ieee_handle *info = (struct ieee_handle *) p;
5730 bfd_boolean unsignedp, localp;
5732 struct ieee_modified_type *m = NULL;
5734 size = info->type_stack->type.size;
5735 unsignedp = info->type_stack->type.unsignedp;
5736 localp = info->type_stack->type.localp;
5737 indx = ieee_pop_type (info);
5741 m = ieee_get_modified_info (info, indx);
5745 if (m->const_qualified > 0)
5746 return ieee_push_type (info, m->const_qualified, size, unsignedp,
5750 if (! ieee_define_type (info, size, unsignedp, localp)
5751 || ! ieee_write_number (info, 'n')
5752 || ! ieee_write_number (info, 1)
5753 || ! ieee_write_number (info, indx))
5757 m->const_qualified = info->type_stack->type.indx;
5762 /* Make a volatile qualified type. */
5765 ieee_volatile_type (void *p)
5767 struct ieee_handle *info = (struct ieee_handle *) p;
5769 bfd_boolean unsignedp, localp;
5771 struct ieee_modified_type *m = NULL;
5773 size = info->type_stack->type.size;
5774 unsignedp = info->type_stack->type.unsignedp;
5775 localp = info->type_stack->type.localp;
5776 indx = ieee_pop_type (info);
5780 m = ieee_get_modified_info (info, indx);
5784 if (m->volatile_qualified > 0)
5785 return ieee_push_type (info, m->volatile_qualified, size, unsignedp,
5789 if (! ieee_define_type (info, size, unsignedp, localp)
5790 || ! ieee_write_number (info, 'n')
5791 || ! ieee_write_number (info, 2)
5792 || ! ieee_write_number (info, indx))
5796 m->volatile_qualified = info->type_stack->type.indx;
5801 /* Convert an enum debug_visibility into a CXXFLAGS value. */
5804 ieee_vis_to_flags (enum debug_visibility visibility)
5810 case DEBUG_VISIBILITY_PUBLIC:
5811 return CXXFLAGS_VISIBILITY_PUBLIC;
5812 case DEBUG_VISIBILITY_PRIVATE:
5813 return CXXFLAGS_VISIBILITY_PRIVATE;
5814 case DEBUG_VISIBILITY_PROTECTED:
5815 return CXXFLAGS_VISIBILITY_PROTECTED;
5820 /* Start defining a struct type. We build it in the strdef field on
5821 the stack, to avoid confusing type definitions required by the
5822 fields with the struct type itself. */
5825 ieee_start_struct_type (void *p, const char *tag, unsigned int id,
5826 bfd_boolean structp, unsigned int size)
5828 struct ieee_handle *info = (struct ieee_handle *) p;
5829 bfd_boolean localp, ignorep;
5833 struct ieee_name_type_hash_entry *h;
5834 struct ieee_name_type *nt, *ntlook;
5835 struct ieee_buflist strdef;
5840 /* We need to create a tag for internal use even if we don't want
5841 one for external use. This will let us refer to an anonymous
5850 sprintf (ab, "__anon%u", id);
5855 /* If we already have references to the tag, we must use the
5856 existing type index. */
5857 h = ieee_name_type_hash_lookup (&info->tags, look, TRUE, copy);
5862 for (ntlook = h->types; ntlook != NULL; ntlook = ntlook->next)
5864 if (ntlook->id == id)
5866 else if (! ntlook->type.localp)
5868 /* We are creating a duplicate definition of a globally
5869 defined tag. Force it to be local to avoid
5877 assert (localp == nt->type.localp);
5878 if (nt->kind == DEBUG_KIND_ILLEGAL && ! localp)
5880 /* We've already seen a global definition of the type.
5881 Ignore this new definition. */
5887 nt = (struct ieee_name_type *) xmalloc (sizeof *nt);
5888 memset (nt, 0, sizeof *nt);
5890 nt->type.name = h->root.string;
5891 nt->next = h->types;
5893 nt->type.indx = info->type_indx;
5897 nt->kind = DEBUG_KIND_ILLEGAL;
5899 if (! ieee_init_buffer (info, &strdef)
5900 || ! ieee_define_named_type (info, tag, nt->type.indx, size, TRUE,
5902 || ! ieee_write_number (info, structp ? 'S' : 'U')
5903 || ! ieee_write_number (info, size))
5910 /* We never want nt->type.name to be NULL. We want the rest of
5911 the type to be the object set up on the type stack; it will
5912 have a NULL name if tag is NULL. */
5913 hold = nt->type.name;
5914 nt->type = info->type_stack->type;
5915 nt->type.name = hold;
5918 info->type_stack->type.name = tag;
5919 info->type_stack->type.strdef = strdef;
5920 info->type_stack->type.ignorep = ignorep;
5925 /* Add a field to a struct. */
5928 ieee_struct_field (void *p, const char *name, bfd_vma bitpos, bfd_vma bitsize,
5929 enum debug_visibility visibility)
5931 struct ieee_handle *info = (struct ieee_handle *) p;
5933 bfd_boolean unsignedp;
5934 bfd_boolean referencep;
5939 assert (info->type_stack != NULL
5940 && info->type_stack->next != NULL
5941 && ! ieee_buffer_emptyp (&info->type_stack->next->type.strdef));
5943 /* If we are ignoring this struct definition, just pop and ignore
5945 if (info->type_stack->next->type.ignorep)
5947 ieee_pop_unused_type (info);
5951 size = info->type_stack->type.size;
5952 unsignedp = info->type_stack->type.unsignedp;
5953 referencep = info->type_stack->type.referencep;
5954 localp = info->type_stack->type.localp;
5955 indx = ieee_pop_type (info);
5958 info->type_stack->type.localp = TRUE;
5960 if (info->type_stack->type.classdef != NULL)
5965 /* This is a class. We must add a description of this field to
5966 the class records we are building. */
5968 flags = ieee_vis_to_flags (visibility);
5969 nindx = info->type_stack->type.classdef->indx;
5970 if (! ieee_change_buffer (info,
5971 &info->type_stack->type.classdef->pmiscbuf)
5972 || ! ieee_write_asn (info, nindx, 'd')
5973 || ! ieee_write_asn (info, nindx, flags)
5974 || ! ieee_write_atn65 (info, nindx, name)
5975 || ! ieee_write_atn65 (info, nindx, name))
5977 info->type_stack->type.classdef->pmisccount += 4;
5981 /* We need to output a record recording that this field is
5982 really of reference type. We put this on the refs field
5983 of classdef, so that it can be appended to the C++
5984 records after the class is defined. */
5986 nindx = info->name_indx;
5989 if (! ieee_change_buffer (info,
5990 &info->type_stack->type.classdef->refs)
5991 || ! ieee_write_byte (info, (int) ieee_nn_record)
5992 || ! ieee_write_number (info, nindx)
5993 || ! ieee_write_id (info, "")
5994 || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
5995 || ! ieee_write_number (info, nindx)
5996 || ! ieee_write_number (info, 0)
5997 || ! ieee_write_number (info, 62)
5998 || ! ieee_write_number (info, 80)
5999 || ! ieee_write_number (info, 4)
6000 || ! ieee_write_asn (info, nindx, 'R')
6001 || ! ieee_write_asn (info, nindx, 3)
6002 || ! ieee_write_atn65 (info, nindx, info->type_stack->type.name)
6003 || ! ieee_write_atn65 (info, nindx, name))
6008 /* If the bitsize doesn't match the expected size, we need to output
6010 if (size == 0 || bitsize == 0 || bitsize == size * 8)
6011 offset = bitpos / 8;
6014 if (! ieee_define_type (info, 0, unsignedp,
6015 info->type_stack->type.localp)
6016 || ! ieee_write_number (info, 'g')
6017 || ! ieee_write_number (info, unsignedp ? 0 : 1)
6018 || ! ieee_write_number (info, bitsize)
6019 || ! ieee_write_number (info, indx))
6021 indx = ieee_pop_type (info);
6025 /* Switch to the struct we are building in order to output this
6026 field definition. */
6027 return (ieee_change_buffer (info, &info->type_stack->type.strdef)
6028 && ieee_write_id (info, name)
6029 && ieee_write_number (info, indx)
6030 && ieee_write_number (info, offset));
6033 /* Finish up a struct type. */
6036 ieee_end_struct_type (void *p)
6038 struct ieee_handle *info = (struct ieee_handle *) p;
6039 struct ieee_buflist *pb;
6041 assert (info->type_stack != NULL
6042 && ! ieee_buffer_emptyp (&info->type_stack->type.strdef));
6044 /* If we were ignoring this struct definition because it was a
6045 duplicate definition, just through away whatever bytes we have
6046 accumulated. Leave the type on the stack. */
6047 if (info->type_stack->type.ignorep)
6050 /* If this is not a duplicate definition of this tag, then localp
6051 will be FALSE, and we can put it in the global type block.
6052 FIXME: We should avoid outputting duplicate definitions which are
6054 if (! info->type_stack->type.localp)
6056 /* Make sure we have started the global type block. */
6057 if (ieee_buffer_emptyp (&info->global_types))
6059 if (! ieee_change_buffer (info, &info->global_types)
6060 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
6061 || ! ieee_write_byte (info, 2)
6062 || ! ieee_write_number (info, 0)
6063 || ! ieee_write_id (info, ""))
6066 pb = &info->global_types;
6070 /* Make sure we have started the types block. */
6071 if (ieee_buffer_emptyp (&info->types))
6073 if (! ieee_change_buffer (info, &info->types)
6074 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
6075 || ! ieee_write_byte (info, 1)
6076 || ! ieee_write_number (info, 0)
6077 || ! ieee_write_id (info, info->modname))
6083 /* Append the struct definition to the types. */
6084 if (! ieee_append_buffer (info, pb, &info->type_stack->type.strdef)
6085 || ! ieee_init_buffer (info, &info->type_stack->type.strdef))
6088 /* Leave the struct on the type stack. */
6093 /* Start a class type. */
6096 ieee_start_class_type (void *p, const char *tag, unsigned int id,
6097 bfd_boolean structp, unsigned int size,
6098 bfd_boolean vptr, bfd_boolean ownvptr)
6100 struct ieee_handle *info = (struct ieee_handle *) p;
6102 struct ieee_buflist pmiscbuf;
6104 struct ieee_type_class *classdef;
6106 /* A C++ class is output as a C++ struct along with a set of pmisc
6107 records describing the class. */
6109 /* We need to have a name so that we can associate the struct and
6115 t = (char *) xmalloc (20);
6116 sprintf (t, "__anon%u", id);
6120 /* We can't write out the virtual table information until we have
6121 finished the class, because we don't know the virtual table size.
6122 We get the size from the largest voffset we see. */
6124 if (vptr && ! ownvptr)
6126 vclass = info->type_stack->type.name;
6127 assert (vclass != NULL);
6128 /* We don't call ieee_pop_unused_type, since the class should
6130 (void) ieee_pop_type (info);
6133 if (! ieee_start_struct_type (p, tag, id, structp, size))
6136 indx = info->name_indx;
6139 /* We write out pmisc records into the classdef field. We will
6140 write out the pmisc start after we know the number of records we
6142 if (! ieee_init_buffer (info, &pmiscbuf)
6143 || ! ieee_change_buffer (info, &pmiscbuf)
6144 || ! ieee_write_asn (info, indx, 'T')
6145 || ! ieee_write_asn (info, indx, structp ? 'o' : 'u')
6146 || ! ieee_write_atn65 (info, indx, tag))
6149 classdef = (struct ieee_type_class *) xmalloc (sizeof *classdef);
6150 memset (classdef, 0, sizeof *classdef);
6152 classdef->indx = indx;
6153 classdef->pmiscbuf = pmiscbuf;
6154 classdef->pmisccount = 3;
6155 classdef->vclass = vclass;
6156 classdef->ownvptr = ownvptr;
6158 info->type_stack->type.classdef = classdef;
6163 /* Add a static member to a class. */
6166 ieee_class_static_member (void *p, const char *name, const char *physname,
6167 enum debug_visibility visibility)
6169 struct ieee_handle *info = (struct ieee_handle *) p;
6173 /* We don't care about the type. Hopefully there will be a call to
6174 ieee_variable declaring the physical name and the type, since
6175 that is where an IEEE consumer must get the type. */
6176 ieee_pop_unused_type (info);
6178 assert (info->type_stack != NULL
6179 && info->type_stack->type.classdef != NULL);
6181 flags = ieee_vis_to_flags (visibility);
6182 flags |= CXXFLAGS_STATIC;
6184 nindx = info->type_stack->type.classdef->indx;
6186 if (! ieee_change_buffer (info, &info->type_stack->type.classdef->pmiscbuf)
6187 || ! ieee_write_asn (info, nindx, 'd')
6188 || ! ieee_write_asn (info, nindx, flags)
6189 || ! ieee_write_atn65 (info, nindx, name)
6190 || ! ieee_write_atn65 (info, nindx, physname))
6192 info->type_stack->type.classdef->pmisccount += 4;
6197 /* Add a base class to a class. */
6200 ieee_class_baseclass (void *p, bfd_vma bitpos, bfd_boolean is_virtual,
6201 enum debug_visibility visibility)
6203 struct ieee_handle *info = (struct ieee_handle *) p;
6211 assert (info->type_stack != NULL
6212 && info->type_stack->type.name != NULL
6213 && info->type_stack->next != NULL
6214 && info->type_stack->next->type.classdef != NULL
6215 && ! ieee_buffer_emptyp (&info->type_stack->next->type.strdef));
6217 bname = info->type_stack->type.name;
6218 localp = info->type_stack->type.localp;
6219 bindx = ieee_pop_type (info);
6221 /* We are currently defining both a struct and a class. We must
6222 write out a field definition in the struct which holds the base
6223 class. The stabs debugging reader will create a field named
6224 _vb$CLASS for a virtual base class, so we just use that. FIXME:
6225 we should not depend upon a detail of stabs debugging. */
6228 fname = (char *) xmalloc (strlen (bname) + sizeof "_vb$");
6229 sprintf (fname, "_vb$%s", bname);
6230 flags = BASEFLAGS_VIRTUAL;
6235 info->type_stack->type.localp = TRUE;
6237 fname = (char *) xmalloc (strlen (bname) + sizeof "_b$");
6238 sprintf (fname, "_b$%s", bname);
6240 if (! ieee_change_buffer (info, &info->type_stack->type.strdef)
6241 || ! ieee_write_id (info, fname)
6242 || ! ieee_write_number (info, bindx)
6243 || ! ieee_write_number (info, bitpos / 8))
6251 if (visibility == DEBUG_VISIBILITY_PRIVATE)
6252 flags |= BASEFLAGS_PRIVATE;
6254 nindx = info->type_stack->type.classdef->indx;
6256 if (! ieee_change_buffer (info, &info->type_stack->type.classdef->pmiscbuf)
6257 || ! ieee_write_asn (info, nindx, 'b')
6258 || ! ieee_write_asn (info, nindx, flags)
6259 || ! ieee_write_atn65 (info, nindx, bname)
6260 || ! ieee_write_asn (info, nindx, 0)
6261 || ! ieee_write_atn65 (info, nindx, fname))
6266 info->type_stack->type.classdef->pmisccount += 5;
6273 /* Start building a method for a class. */
6276 ieee_class_start_method (void *p, const char *name)
6278 struct ieee_handle *info = (struct ieee_handle *) p;
6280 assert (info->type_stack != NULL
6281 && info->type_stack->type.classdef != NULL
6282 && info->type_stack->type.classdef->method == NULL);
6284 info->type_stack->type.classdef->method = name;
6289 /* Define a new method variant, either static or not. */
6292 ieee_class_method_var (struct ieee_handle *info, const char *physname,
6293 enum debug_visibility visibility,
6294 bfd_boolean staticp, bfd_boolean constp,
6295 bfd_boolean volatilep, bfd_vma voffset,
6296 bfd_boolean context)
6300 bfd_boolean is_virtual;
6302 /* We don't need the type of the method. An IEEE consumer which
6303 wants the type must track down the function by the physical name
6304 and get the type from that. */
6305 ieee_pop_unused_type (info);
6307 /* We don't use the context. FIXME: We probably ought to use it to
6308 adjust the voffset somehow, but I don't really know how. */
6310 ieee_pop_unused_type (info);
6312 assert (info->type_stack != NULL
6313 && info->type_stack->type.classdef != NULL
6314 && info->type_stack->type.classdef->method != NULL);
6316 flags = ieee_vis_to_flags (visibility);
6318 /* FIXME: We never set CXXFLAGS_OVERRIDE, CXXFLAGS_OPERATOR,
6319 CXXFLAGS_CTORDTOR, CXXFLAGS_CTOR, or CXXFLAGS_INLINE. */
6322 flags |= CXXFLAGS_STATIC;
6324 flags |= CXXFLAGS_CONST;
6326 flags |= CXXFLAGS_VOLATILE;
6328 nindx = info->type_stack->type.classdef->indx;
6330 is_virtual = context || voffset > 0;
6332 if (! ieee_change_buffer (info,
6333 &info->type_stack->type.classdef->pmiscbuf)
6334 || ! ieee_write_asn (info, nindx, is_virtual ? 'v' : 'm')
6335 || ! ieee_write_asn (info, nindx, flags)
6336 || ! ieee_write_atn65 (info, nindx,
6337 info->type_stack->type.classdef->method)
6338 || ! ieee_write_atn65 (info, nindx, physname))
6343 if (voffset > info->type_stack->type.classdef->voffset)
6344 info->type_stack->type.classdef->voffset = voffset;
6345 if (! ieee_write_asn (info, nindx, voffset))
6347 ++info->type_stack->type.classdef->pmisccount;
6350 if (! ieee_write_asn (info, nindx, 0))
6353 info->type_stack->type.classdef->pmisccount += 5;
6358 /* Define a new method variant. */
6361 ieee_class_method_variant (void *p, const char *physname,
6362 enum debug_visibility visibility,
6363 bfd_boolean constp, bfd_boolean volatilep,
6364 bfd_vma voffset, bfd_boolean context)
6366 struct ieee_handle *info = (struct ieee_handle *) p;
6368 return ieee_class_method_var (info, physname, visibility, FALSE, constp,
6369 volatilep, voffset, context);
6372 /* Define a new static method variant. */
6375 ieee_class_static_method_variant (void *p, const char *physname,
6376 enum debug_visibility visibility,
6377 bfd_boolean constp, bfd_boolean volatilep)
6379 struct ieee_handle *info = (struct ieee_handle *) p;
6381 return ieee_class_method_var (info, physname, visibility, TRUE, constp,
6382 volatilep, 0, FALSE);
6385 /* Finish up a method. */
6388 ieee_class_end_method (void *p)
6390 struct ieee_handle *info = (struct ieee_handle *) p;
6392 assert (info->type_stack != NULL
6393 && info->type_stack->type.classdef != NULL
6394 && info->type_stack->type.classdef->method != NULL);
6396 info->type_stack->type.classdef->method = NULL;
6401 /* Finish up a class. */
6404 ieee_end_class_type (void *p)
6406 struct ieee_handle *info = (struct ieee_handle *) p;
6409 assert (info->type_stack != NULL
6410 && info->type_stack->type.classdef != NULL);
6412 /* If we were ignoring this class definition because it was a
6413 duplicate definition, just through away whatever bytes we have
6414 accumulated. Leave the type on the stack. */
6415 if (info->type_stack->type.ignorep)
6418 nindx = info->type_stack->type.classdef->indx;
6420 /* If we have a virtual table, we can write out the information now. */
6421 if (info->type_stack->type.classdef->vclass != NULL
6422 || info->type_stack->type.classdef->ownvptr)
6424 if (! ieee_change_buffer (info,
6425 &info->type_stack->type.classdef->pmiscbuf)
6426 || ! ieee_write_asn (info, nindx, 'z')
6427 || ! ieee_write_atn65 (info, nindx, "")
6428 || ! ieee_write_asn (info, nindx,
6429 info->type_stack->type.classdef->voffset))
6431 if (info->type_stack->type.classdef->ownvptr)
6433 if (! ieee_write_atn65 (info, nindx, ""))
6438 if (! ieee_write_atn65 (info, nindx,
6439 info->type_stack->type.classdef->vclass))
6442 if (! ieee_write_asn (info, nindx, 0))
6444 info->type_stack->type.classdef->pmisccount += 5;
6447 /* Now that we know the number of pmisc records, we can write out
6448 the atn62 which starts the pmisc records, and append them to the
6451 if (! ieee_change_buffer (info, &info->cxx)
6452 || ! ieee_write_byte (info, (int) ieee_nn_record)
6453 || ! ieee_write_number (info, nindx)
6454 || ! ieee_write_id (info, "")
6455 || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
6456 || ! ieee_write_number (info, nindx)
6457 || ! ieee_write_number (info, 0)
6458 || ! ieee_write_number (info, 62)
6459 || ! ieee_write_number (info, 80)
6460 || ! ieee_write_number (info,
6461 info->type_stack->type.classdef->pmisccount))
6464 if (! ieee_append_buffer (info, &info->cxx,
6465 &info->type_stack->type.classdef->pmiscbuf))
6467 if (! ieee_buffer_emptyp (&info->type_stack->type.classdef->refs))
6469 if (! ieee_append_buffer (info, &info->cxx,
6470 &info->type_stack->type.classdef->refs))
6474 return ieee_end_struct_type (p);
6477 /* Push a previously seen typedef onto the type stack. */
6480 ieee_typedef_type (void *p, const char *name)
6482 struct ieee_handle *info = (struct ieee_handle *) p;
6483 struct ieee_name_type_hash_entry *h;
6484 struct ieee_name_type *nt;
6486 h = ieee_name_type_hash_lookup (&info->typedefs, name, FALSE, FALSE);
6488 /* h should never be NULL, since that would imply that the generic
6489 debugging code has asked for a typedef which it has not yet
6493 /* We always use the most recently defined type for this name, which
6494 will be the first one on the list. */
6497 if (! ieee_push_type (info, nt->type.indx, nt->type.size,
6498 nt->type.unsignedp, nt->type.localp))
6501 /* Copy over any other type information we may have. */
6502 info->type_stack->type = nt->type;
6507 /* Push a tagged type onto the type stack. */
6510 ieee_tag_type (void *p, const char *name, unsigned int id,
6511 enum debug_type_kind kind)
6513 struct ieee_handle *info = (struct ieee_handle *) p;
6517 struct ieee_name_type_hash_entry *h;
6518 struct ieee_name_type *nt;
6520 if (kind == DEBUG_KIND_ENUM)
6522 struct ieee_defined_enum *e;
6526 for (e = info->enums; e != NULL; e = e->next)
6527 if (e->tag != NULL && strcmp (e->tag, name) == 0)
6528 return ieee_push_type (info, e->indx, 0, TRUE, FALSE);
6530 e = (struct ieee_defined_enum *) xmalloc (sizeof *e);
6531 memset (e, 0, sizeof *e);
6533 e->indx = info->type_indx;
6538 e->next = info->enums;
6541 return ieee_push_type (info, e->indx, 0, TRUE, FALSE);
6549 sprintf (ab, "__anon%u", id);
6554 h = ieee_name_type_hash_lookup (&info->tags, name, TRUE, copy);
6558 for (nt = h->types; nt != NULL; nt = nt->next)
6562 if (! ieee_push_type (info, nt->type.indx, nt->type.size,
6563 nt->type.unsignedp, nt->type.localp))
6565 /* Copy over any other type information we may have. */
6566 info->type_stack->type = nt->type;
6570 if (! nt->type.localp)
6572 /* This is a duplicate of a global type, so it must be
6578 nt = (struct ieee_name_type *) xmalloc (sizeof *nt);
6579 memset (nt, 0, sizeof *nt);
6582 nt->type.name = h->root.string;
6583 nt->type.indx = info->type_indx;
6584 nt->type.localp = localp;
6588 nt->next = h->types;
6591 if (! ieee_push_type (info, nt->type.indx, 0, FALSE, localp))
6594 info->type_stack->type.name = h->root.string;
6599 /* Output a typedef. */
6602 ieee_typdef (void *p, const char *name)
6604 struct ieee_handle *info = (struct ieee_handle *) p;
6605 struct ieee_write_type type;
6609 struct ieee_name_type_hash_entry *h;
6610 struct ieee_name_type *nt;
6612 type = info->type_stack->type;
6615 /* If this is a simple builtin type using a builtin name, we don't
6616 want to output the typedef itself. We also want to change the
6617 type index to correspond to the name being used. We recognize
6618 names used in stabs debugging output even if they don't exactly
6619 correspond to the names used for the IEEE builtin types. */
6621 if (indx <= (unsigned int) builtin_bcd_float)
6623 switch ((enum builtin_types) indx)
6629 if (strcmp (name, "void") == 0)
6633 case builtin_signed_char:
6635 if (strcmp (name, "signed char") == 0)
6637 indx = (unsigned int) builtin_signed_char;
6640 else if (strcmp (name, "char") == 0)
6642 indx = (unsigned int) builtin_char;
6647 case builtin_unsigned_char:
6648 if (strcmp (name, "unsigned char") == 0)
6652 case builtin_signed_short_int:
6654 case builtin_short_int:
6655 case builtin_signed_short:
6656 if (strcmp (name, "signed short int") == 0)
6658 indx = (unsigned int) builtin_signed_short_int;
6661 else if (strcmp (name, "short") == 0)
6663 indx = (unsigned int) builtin_short;
6666 else if (strcmp (name, "short int") == 0)
6668 indx = (unsigned int) builtin_short_int;
6671 else if (strcmp (name, "signed short") == 0)
6673 indx = (unsigned int) builtin_signed_short;
6678 case builtin_unsigned_short_int:
6679 case builtin_unsigned_short:
6680 if (strcmp (name, "unsigned short int") == 0
6681 || strcmp (name, "short unsigned int") == 0)
6683 indx = builtin_unsigned_short_int;
6686 else if (strcmp (name, "unsigned short") == 0)
6688 indx = builtin_unsigned_short;
6693 case builtin_signed_long:
6694 case builtin_int: /* FIXME: Size depends upon architecture. */
6696 if (strcmp (name, "signed long") == 0)
6698 indx = builtin_signed_long;
6701 else if (strcmp (name, "int") == 0)
6706 else if (strcmp (name, "long") == 0
6707 || strcmp (name, "long int") == 0)
6709 indx = builtin_long;
6714 case builtin_unsigned_long:
6715 case builtin_unsigned: /* FIXME: Size depends upon architecture. */
6716 case builtin_unsigned_int: /* FIXME: Like builtin_unsigned. */
6717 if (strcmp (name, "unsigned long") == 0
6718 || strcmp (name, "long unsigned int") == 0)
6720 indx = builtin_unsigned_long;
6723 else if (strcmp (name, "unsigned") == 0)
6725 indx = builtin_unsigned;
6728 else if (strcmp (name, "unsigned int") == 0)
6730 indx = builtin_unsigned_int;
6735 case builtin_signed_long_long:
6736 if (strcmp (name, "signed long long") == 0
6737 || strcmp (name, "long long int") == 0)
6741 case builtin_unsigned_long_long:
6742 if (strcmp (name, "unsigned long long") == 0
6743 || strcmp (name, "long long unsigned int") == 0)
6748 if (strcmp (name, "float") == 0)
6752 case builtin_double:
6753 if (strcmp (name, "double") == 0)
6757 case builtin_long_double:
6758 if (strcmp (name, "long double") == 0)
6762 case builtin_long_long_double:
6763 if (strcmp (name, "long long double") == 0)
6772 h = ieee_name_type_hash_lookup (&info->typedefs, name, TRUE, FALSE);
6776 /* See if we have already defined this type with this name. */
6777 localp = type.localp;
6778 for (nt = h->types; nt != NULL; nt = nt->next)
6782 /* If this is a global definition, then we don't need to
6783 do anything here. */
6784 if (! nt->type.localp)
6786 ieee_pop_unused_type (info);
6792 /* This is a duplicate definition, so make this one local. */
6797 /* We need to add a new typedef for this type. */
6799 nt = (struct ieee_name_type *) xmalloc (sizeof *nt);
6800 memset (nt, 0, sizeof *nt);
6803 nt->type.name = name;
6804 nt->type.localp = localp;
6805 nt->kind = DEBUG_KIND_ILLEGAL;
6807 nt->next = h->types;
6812 /* This is one of the builtin typedefs, so we don't need to
6813 actually define it. */
6814 ieee_pop_unused_type (info);
6818 indx = ieee_pop_type (info);
6820 if (! ieee_define_named_type (info, name, (unsigned int) -1, type.size,
6821 type.unsignedp, localp,
6822 (struct ieee_buflist *) NULL)
6823 || ! ieee_write_number (info, 'T')
6824 || ! ieee_write_number (info, indx))
6827 /* Remove the type we just added to the type stack. This should not
6828 be ieee_pop_unused_type, since the type is used, we just don't
6830 (void) ieee_pop_type (info);
6835 /* Output a tag for a type. We don't have to do anything here. */
6838 ieee_tag (void *p, const char *name ATTRIBUTE_UNUSED)
6840 struct ieee_handle *info = (struct ieee_handle *) p;
6842 /* This should not be ieee_pop_unused_type, since we want the type
6844 (void) ieee_pop_type (info);
6848 /* Output an integer constant. */
6851 ieee_int_constant (void *p ATTRIBUTE_UNUSED, const char *name ATTRIBUTE_UNUSED,
6852 bfd_vma val ATTRIBUTE_UNUSED)
6858 /* Output a floating point constant. */
6861 ieee_float_constant (void *p ATTRIBUTE_UNUSED,
6862 const char *name ATTRIBUTE_UNUSED,
6863 double val ATTRIBUTE_UNUSED)
6869 /* Output a typed constant. */
6872 ieee_typed_constant (void *p, const char *name ATTRIBUTE_UNUSED,
6873 bfd_vma val ATTRIBUTE_UNUSED)
6875 struct ieee_handle *info = (struct ieee_handle *) p;
6878 ieee_pop_unused_type (info);
6882 /* Output a variable. */
6885 ieee_variable (void *p, const char *name, enum debug_var_kind kind,
6888 struct ieee_handle *info = (struct ieee_handle *) p;
6889 unsigned int name_indx;
6891 bfd_boolean referencep;
6892 unsigned int type_indx;
6896 size = info->type_stack->type.size;
6897 referencep = info->type_stack->type.referencep;
6898 type_indx = ieee_pop_type (info);
6900 assert (! ieee_buffer_emptyp (&info->vars));
6901 if (! ieee_change_buffer (info, &info->vars))
6904 name_indx = info->name_indx;
6907 /* Write out an NN and an ATN record for this variable. */
6908 if (! ieee_write_byte (info, (int) ieee_nn_record)
6909 || ! ieee_write_number (info, name_indx)
6910 || ! ieee_write_id (info, name)
6911 || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
6912 || ! ieee_write_number (info, name_indx)
6913 || ! ieee_write_number (info, type_indx))
6921 if (! ieee_write_number (info, 8)
6922 || ! ieee_add_range (info, FALSE, val, val + size))
6928 if (! ieee_write_number (info, 3)
6929 || ! ieee_add_range (info, FALSE, val, val + size))
6934 case DEBUG_LOCAL_STATIC:
6935 if (! ieee_write_number (info, 3)
6936 || ! ieee_add_range (info, FALSE, val, val + size))
6942 if (! ieee_write_number (info, 1)
6943 || ! ieee_write_number (info, val))
6948 case DEBUG_REGISTER:
6949 if (! ieee_write_number (info, 2)
6950 || ! ieee_write_number (info,
6951 ieee_genreg_to_regno (info->abfd, val)))
6960 if (! ieee_write_asn (info, name_indx, val))
6964 /* If this is really a reference type, then we just output it with
6965 pointer type, and must now output a C++ record indicating that it
6966 is really reference type. */
6971 nindx = info->name_indx;
6974 /* If this is a global variable, we want to output the misc
6975 record in the C++ misc record block. Otherwise, we want to
6976 output it just after the variable definition, which is where
6977 the current buffer is. */
6980 if (! ieee_change_buffer (info, &info->cxx))
6984 if (! ieee_write_byte (info, (int) ieee_nn_record)
6985 || ! ieee_write_number (info, nindx)
6986 || ! ieee_write_id (info, "")
6987 || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
6988 || ! ieee_write_number (info, nindx)
6989 || ! ieee_write_number (info, 0)
6990 || ! ieee_write_number (info, 62)
6991 || ! ieee_write_number (info, 80)
6992 || ! ieee_write_number (info, 3)
6993 || ! ieee_write_asn (info, nindx, 'R')
6994 || ! ieee_write_asn (info, nindx, refflag)
6995 || ! ieee_write_atn65 (info, nindx, name))
7002 /* Start outputting information for a function. */
7005 ieee_start_function (void *p, const char *name, bfd_boolean global)
7007 struct ieee_handle *info = (struct ieee_handle *) p;
7008 bfd_boolean referencep;
7009 unsigned int retindx, typeindx;
7011 referencep = info->type_stack->type.referencep;
7012 retindx = ieee_pop_type (info);
7014 /* Besides recording a BB4 or BB6 block, we record the type of the
7015 function in the BB1 typedef block. We can't write out the full
7016 type until we have seen all the parameters, so we accumulate it
7017 in info->fntype and info->fnargs. */
7018 if (! ieee_buffer_emptyp (&info->fntype))
7020 /* FIXME: This might happen someday if we support nested
7025 info->fnname = name;
7027 /* An attribute of 0x40 means that the push mask is unknown. */
7028 if (! ieee_define_named_type (info, name, (unsigned int) -1, 0, FALSE, TRUE,
7030 || ! ieee_write_number (info, 'x')
7031 || ! ieee_write_number (info, 0x40)
7032 || ! ieee_write_number (info, 0)
7033 || ! ieee_write_number (info, 0)
7034 || ! ieee_write_number (info, retindx))
7037 typeindx = ieee_pop_type (info);
7039 if (! ieee_init_buffer (info, &info->fnargs))
7041 info->fnargcount = 0;
7043 /* If the function return value is actually a reference type, we
7044 must add a record indicating that. */
7049 nindx = info->name_indx;
7051 if (! ieee_change_buffer (info, &info->cxx)
7052 || ! ieee_write_byte (info, (int) ieee_nn_record)
7053 || ! ieee_write_number (info, nindx)
7054 || ! ieee_write_id (info, "")
7055 || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
7056 || ! ieee_write_number (info, nindx)
7057 || ! ieee_write_number (info, 0)
7058 || ! ieee_write_number (info, 62)
7059 || ! ieee_write_number (info, 80)
7060 || ! ieee_write_number (info, 3)
7061 || ! ieee_write_asn (info, nindx, 'R')
7062 || ! ieee_write_asn (info, nindx, global ? 0 : 1)
7063 || ! ieee_write_atn65 (info, nindx, name))
7067 assert (! ieee_buffer_emptyp (&info->vars));
7068 if (! ieee_change_buffer (info, &info->vars))
7071 /* The address is written out as the first block. */
7073 ++info->block_depth;
7075 return (ieee_write_byte (info, (int) ieee_bb_record_enum)
7076 && ieee_write_byte (info, global ? 4 : 6)
7077 && ieee_write_number (info, 0)
7078 && ieee_write_id (info, name)
7079 && ieee_write_number (info, 0)
7080 && ieee_write_number (info, typeindx));
7083 /* Add a function parameter. This will normally be called before the
7084 first block, so we postpone them until we see the block. */
7087 ieee_function_parameter (void *p, const char *name, enum debug_parm_kind kind,
7090 struct ieee_handle *info = (struct ieee_handle *) p;
7091 struct ieee_pending_parm *m, **pm;
7093 assert (info->block_depth == 1);
7095 m = (struct ieee_pending_parm *) xmalloc (sizeof *m);
7096 memset (m, 0, sizeof *m);
7100 m->referencep = info->type_stack->type.referencep;
7101 m->type = ieee_pop_type (info);
7105 for (pm = &info->pending_parms; *pm != NULL; pm = &(*pm)->next)
7109 /* Add the type to the fnargs list. */
7110 if (! ieee_change_buffer (info, &info->fnargs)
7111 || ! ieee_write_number (info, m->type))
7118 /* Output pending function parameters. */
7121 ieee_output_pending_parms (struct ieee_handle *info)
7123 struct ieee_pending_parm *m;
7124 unsigned int refcount;
7127 for (m = info->pending_parms; m != NULL; m = m->next)
7129 enum debug_var_kind vkind;
7136 case DEBUG_PARM_STACK:
7137 case DEBUG_PARM_REFERENCE:
7138 vkind = DEBUG_LOCAL;
7140 case DEBUG_PARM_REG:
7141 case DEBUG_PARM_REF_REG:
7142 vkind = DEBUG_REGISTER;
7146 if (! ieee_push_type (info, m->type, 0, FALSE, FALSE))
7148 info->type_stack->type.referencep = m->referencep;
7151 if (! ieee_variable ((void *) info, m->name, vkind, m->val))
7155 /* If there are any reference parameters, we need to output a
7156 miscellaneous record indicating them. */
7159 unsigned int nindx, varindx;
7161 /* FIXME: The MRI compiler outputs the demangled function name
7162 here, but we are outputting the mangled name. */
7163 nindx = info->name_indx;
7165 if (! ieee_change_buffer (info, &info->vars)
7166 || ! ieee_write_byte (info, (int) ieee_nn_record)
7167 || ! ieee_write_number (info, nindx)
7168 || ! ieee_write_id (info, "")
7169 || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
7170 || ! ieee_write_number (info, nindx)
7171 || ! ieee_write_number (info, 0)
7172 || ! ieee_write_number (info, 62)
7173 || ! ieee_write_number (info, 80)
7174 || ! ieee_write_number (info, refcount + 3)
7175 || ! ieee_write_asn (info, nindx, 'B')
7176 || ! ieee_write_atn65 (info, nindx, info->fnname)
7177 || ! ieee_write_asn (info, nindx, 0))
7179 for (m = info->pending_parms, varindx = 1;
7181 m = m->next, varindx++)
7185 if (! ieee_write_asn (info, nindx, varindx))
7191 m = info->pending_parms;
7194 struct ieee_pending_parm *next;
7201 info->pending_parms = NULL;
7206 /* Start a block. If this is the first block, we output the address
7207 to finish the BB4 or BB6, and then output the function parameters. */
7210 ieee_start_block (void *p, bfd_vma addr)
7212 struct ieee_handle *info = (struct ieee_handle *) p;
7214 if (! ieee_change_buffer (info, &info->vars))
7217 if (info->block_depth == 1)
7219 if (! ieee_write_number (info, addr)
7220 || ! ieee_output_pending_parms (info))
7225 if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
7226 || ! ieee_write_byte (info, 6)
7227 || ! ieee_write_number (info, 0)
7228 || ! ieee_write_id (info, "")
7229 || ! ieee_write_number (info, 0)
7230 || ! ieee_write_number (info, 0)
7231 || ! ieee_write_number (info, addr))
7235 if (! ieee_start_range (info, addr))
7238 ++info->block_depth;
7246 ieee_end_block (void *p, bfd_vma addr)
7248 struct ieee_handle *info = (struct ieee_handle *) p;
7250 /* The address we are given is the end of the block, but IEEE seems
7251 to want to the address of the last byte in the block, so we
7253 if (! ieee_change_buffer (info, &info->vars)
7254 || ! ieee_write_byte (info, (int) ieee_be_record_enum)
7255 || ! ieee_write_number (info, addr - 1))
7258 if (! ieee_end_range (info, addr))
7261 --info->block_depth;
7263 if (addr > info->highaddr)
7264 info->highaddr = addr;
7269 /* End a function. */
7272 ieee_end_function (void *p)
7274 struct ieee_handle *info = (struct ieee_handle *) p;
7276 assert (info->block_depth == 1);
7278 --info->block_depth;
7280 /* Now we can finish up fntype, and add it to the typdef section.
7281 At this point, fntype is the 'x' type up to the argument count,
7282 and fnargs is the argument types. We must add the argument
7283 count, and we must add the level. FIXME: We don't record varargs
7284 functions correctly. In fact, stabs debugging does not give us
7285 enough information to do so. */
7286 if (! ieee_change_buffer (info, &info->fntype)
7287 || ! ieee_write_number (info, info->fnargcount)
7288 || ! ieee_change_buffer (info, &info->fnargs)
7289 || ! ieee_write_number (info, 0))
7292 /* Make sure the typdef block has been started. */
7293 if (ieee_buffer_emptyp (&info->types))
7295 if (! ieee_change_buffer (info, &info->types)
7296 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
7297 || ! ieee_write_byte (info, 1)
7298 || ! ieee_write_number (info, 0)
7299 || ! ieee_write_id (info, info->modname))
7303 if (! ieee_append_buffer (info, &info->types, &info->fntype)
7304 || ! ieee_append_buffer (info, &info->types, &info->fnargs))
7307 info->fnname = NULL;
7308 if (! ieee_init_buffer (info, &info->fntype)
7309 || ! ieee_init_buffer (info, &info->fnargs))
7311 info->fnargcount = 0;
7316 /* Record line number information. */
7319 ieee_lineno (void *p, const char *filename, unsigned long lineno, bfd_vma addr)
7321 struct ieee_handle *info = (struct ieee_handle *) p;
7323 assert (info->filename != NULL);
7325 /* The HP simulator seems to get confused when more than one line is
7326 listed for the same address, at least if they are in different
7327 files. We handle this by always listing the last line for a
7328 given address, since that seems to be the one that gdb uses. */
7329 if (info->pending_lineno_filename != NULL
7330 && addr != info->pending_lineno_addr)
7332 /* Make sure we have a line number block. */
7333 if (! ieee_buffer_emptyp (&info->linenos))
7335 if (! ieee_change_buffer (info, &info->linenos))
7340 info->lineno_name_indx = info->name_indx;
7342 if (! ieee_change_buffer (info, &info->linenos)
7343 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
7344 || ! ieee_write_byte (info, 5)
7345 || ! ieee_write_number (info, 0)
7346 || ! ieee_write_id (info, info->filename)
7347 || ! ieee_write_byte (info, (int) ieee_nn_record)
7348 || ! ieee_write_number (info, info->lineno_name_indx)
7349 || ! ieee_write_id (info, ""))
7351 info->lineno_filename = info->filename;
7354 if (filename_cmp (info->pending_lineno_filename,
7355 info->lineno_filename) != 0)
7357 if (filename_cmp (info->filename, info->lineno_filename) != 0)
7359 /* We were not in the main file. Close the block for the
7361 if (! ieee_write_byte (info, (int) ieee_be_record_enum))
7363 if (filename_cmp (info->filename,
7364 info->pending_lineno_filename) == 0)
7366 /* We need a new NN record, and we aren't about to
7368 info->lineno_name_indx = info->name_indx;
7370 if (! ieee_write_byte (info, (int) ieee_nn_record)
7371 || ! ieee_write_number (info, info->lineno_name_indx)
7372 || ! ieee_write_id (info, ""))
7376 if (filename_cmp (info->filename,
7377 info->pending_lineno_filename) != 0)
7379 /* We are not changing to the main file. Open a block for
7380 the new included file. */
7381 info->lineno_name_indx = info->name_indx;
7383 if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
7384 || ! ieee_write_byte (info, 5)
7385 || ! ieee_write_number (info, 0)
7386 || ! ieee_write_id (info, info->pending_lineno_filename)
7387 || ! ieee_write_byte (info, (int) ieee_nn_record)
7388 || ! ieee_write_number (info, info->lineno_name_indx)
7389 || ! ieee_write_id (info, ""))
7392 info->lineno_filename = info->pending_lineno_filename;
7395 if (! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
7396 || ! ieee_write_number (info, info->lineno_name_indx)
7397 || ! ieee_write_number (info, 0)
7398 || ! ieee_write_number (info, 7)
7399 || ! ieee_write_number (info, info->pending_lineno)
7400 || ! ieee_write_number (info, 0)
7401 || ! ieee_write_asn (info, info->lineno_name_indx,
7402 info->pending_lineno_addr))
7406 info->pending_lineno_filename = filename;
7407 info->pending_lineno = lineno;
7408 info->pending_lineno_addr = addr;