1 /* ieee.c -- Read and write IEEE-695 debugging information.
2 Copyright (C) 1996 Free Software Foundation, Inc.
5 This file is part of GNU Binutils.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22 /* This file reads and writes IEEE-695 debugging information. */
30 #include "libiberty.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. */
70 /* Slot if we make an indirect type. */
72 /* Kind of variable or function. */
84 /* This structure holds all the variables. */
88 /* Number of slots allocated. */
91 struct ieee_var *vars;
94 /* This structure holds information for a type. We need this because
95 we don't want to represent bitfields as real types. */
101 /* Slot if this is type is referenced before it is defined. */
103 /* Slots for arguments if we make indirect types for them. */
104 debug_type *arg_slots;
105 /* If this is a bitfield, this is the size in bits. If this is not
106 a bitfield, this is zero. */
107 unsigned long bitsize;
110 /* This structure holds all the type information. */
114 /* Number of slots allocated. */
117 struct ieee_type *types;
119 #define BUILTIN_TYPE_COUNT (60)
120 debug_type builtins[BUILTIN_TYPE_COUNT];
123 /* This structure holds a linked last of structs with their tag names,
124 so that we can convert them to C++ classes if necessary. */
129 struct ieee_tag *next;
132 /* The type of the tag. */
134 /* The tagged type is an indirect type pointing at this slot. */
136 /* This is an array of slots used when a field type is converted
137 into a indirect type, in case it needs to be later converted into
142 /* This structure holds the information we pass around to the parsing
147 /* The debugging handle. */
151 /* The start of the bytes to be parsed. */
152 const bfd_byte *bytes;
153 /* The end of the bytes to be parsed. */
154 const bfd_byte *pend;
155 /* The block stack. */
156 struct ieee_blockstack blockstack;
158 struct ieee_vars vars;
160 struct ieee_types types;
161 /* The list of tagged structs. */
162 struct ieee_tag *tags;
165 /* Basic builtin types, not including the pointers. */
171 builtin_signed_char = 2,
172 builtin_unsigned_char = 3,
173 builtin_signed_short_int = 4,
174 builtin_unsigned_short_int = 5,
175 builtin_signed_long = 6,
176 builtin_unsigned_long = 7,
177 builtin_signed_long_long = 8,
178 builtin_unsigned_long_long = 9,
181 builtin_long_double = 12,
182 builtin_long_long_double = 13,
183 builtin_quoted_string = 14,
184 builtin_instruction_address = 15,
186 builtin_unsigned = 17,
187 builtin_unsigned_int = 18,
191 builtin_unsigned_short = 22,
192 builtin_short_int = 23,
193 builtin_signed_short = 24,
194 builtin_bcd_float = 25
197 /* These are the values found in the derivation flags of a 'b'
198 component record of a 'T' type extension record in a C++ pmisc
199 record. These are bitmasks. */
201 /* Set for a private base class, clear for a public base class.
202 Protected base classes are not supported. */
203 #define BASEFLAGS_PRIVATE (0x1)
204 /* Set for a virtual base class. */
205 #define BASEFLAGS_VIRTUAL (0x2)
206 /* Set for a friend class, clear for a base class. */
207 #define BASEFLAGS_FRIEND (0x10)
209 /* These are the values found in the specs flags of a 'd', 'm', or 'v'
210 component record of a 'T' type extension record in a C++ pmisc
211 record. The same flags are used for a 'M' record in a C++ pmisc
214 /* The lower two bits hold visibility information. */
215 #define CXXFLAGS_VISIBILITY (0x3)
216 /* This value in the lower two bits indicates a public member. */
217 #define CXXFLAGS_VISIBILITY_PUBLIC (0x0)
218 /* This value in the lower two bits indicates a private member. */
219 #define CXXFLAGS_VISIBILITY_PRIVATE (0x1)
220 /* This value in the lower two bits indicates a protected member. */
221 #define CXXFLAGS_VISIBILITY_PROTECTED (0x2)
222 /* Set for a static member. */
223 #define CXXFLAGS_STATIC (0x4)
224 /* Set for a virtual override. */
225 #define CXXFLAGS_OVERRIDE (0x8)
226 /* Set for a friend function. */
227 #define CXXFLAGS_FRIEND (0x10)
228 /* Set for a const function. */
229 #define CXXFLAGS_CONST (0x20)
230 /* Set for a volatile function. */
231 #define CXXFLAGS_VOLATILE (0x40)
232 /* Set for an overloaded function. */
233 #define CXXFLAGS_OVERLOADED (0x80)
234 /* Set for an operator function. */
235 #define CXXFLAGS_OPERATOR (0x100)
236 /* Set for a constructor or destructor. */
237 #define CXXFLAGS_CTORDTOR (0x400)
238 /* Set for a constructor. */
239 #define CXXFLAGS_CTOR (0x200)
240 /* Set for an inline function. */
241 #define CXXFLAGS_INLINE (0x800)
243 /* Local functions. */
245 static void ieee_error
246 PARAMS ((struct ieee_info *, const bfd_byte *, const char *));
247 static void ieee_eof PARAMS ((struct ieee_info *));
248 static char *savestring PARAMS ((const char *, unsigned long));
249 static boolean ieee_read_number
250 PARAMS ((struct ieee_info *, const bfd_byte **, bfd_vma *));
251 static boolean ieee_read_optional_number
252 PARAMS ((struct ieee_info *, const bfd_byte **, bfd_vma *, boolean *));
253 static boolean ieee_read_id
254 PARAMS ((struct ieee_info *, const bfd_byte **, const char **,
256 static boolean ieee_read_optional_id
257 PARAMS ((struct ieee_info *, const bfd_byte **, const char **,
258 unsigned long *, boolean *));
259 static boolean ieee_read_expression
260 PARAMS ((struct ieee_info *, const bfd_byte **, bfd_vma *));
261 static debug_type ieee_builtin_type
262 PARAMS ((struct ieee_info *, const bfd_byte *, unsigned int));
263 static boolean ieee_alloc_type
264 PARAMS ((struct ieee_info *, unsigned int, boolean));
265 static boolean ieee_read_type_index
266 PARAMS ((struct ieee_info *, const bfd_byte **, debug_type *));
267 static int ieee_regno_to_genreg PARAMS ((bfd *, int));
268 static int ieee_genreg_to_regno PARAMS ((bfd *, int));
269 static boolean parse_ieee_bb PARAMS ((struct ieee_info *, const bfd_byte **));
270 static boolean parse_ieee_be PARAMS ((struct ieee_info *, const bfd_byte **));
271 static boolean parse_ieee_nn PARAMS ((struct ieee_info *, const bfd_byte **));
272 static boolean parse_ieee_ty PARAMS ((struct ieee_info *, const bfd_byte **));
273 static boolean parse_ieee_atn PARAMS ((struct ieee_info *, const bfd_byte **));
274 static boolean ieee_read_cxx_misc
275 PARAMS ((struct ieee_info *, const bfd_byte **, unsigned long));
276 static boolean ieee_read_cxx_class
277 PARAMS ((struct ieee_info *, const bfd_byte **, unsigned long));
278 static boolean ieee_read_cxx_defaults
279 PARAMS ((struct ieee_info *, const bfd_byte **, unsigned long));
280 static boolean ieee_read_reference
281 PARAMS ((struct ieee_info *, const bfd_byte **));
282 static boolean ieee_require_asn
283 PARAMS ((struct ieee_info *, const bfd_byte **, bfd_vma *));
284 static boolean ieee_require_atn65
285 PARAMS ((struct ieee_info *, const bfd_byte **, const char **,
288 /* Report an error in the IEEE debugging information. */
291 ieee_error (info, p, s)
292 struct ieee_info *info;
297 fprintf (stderr, "%s: 0x%lx: %s (0x%x)\n", bfd_get_filename (info->abfd),
298 (unsigned long) (p - info->bytes), s, *p);
300 fprintf (stderr, "%s: %s\n", bfd_get_filename (info->abfd), s);
303 /* Report an unexpected EOF in the IEEE debugging information. */
307 struct ieee_info *info;
309 ieee_error (info, (const bfd_byte *) NULL,
310 "unexpected end of debugging information");
313 /* Save a string in memory. */
316 savestring (start, len)
322 ret = (char *) xmalloc (len + 1);
323 memcpy (ret, start, len);
328 /* Read a number which must be present in an IEEE file. */
331 ieee_read_number (info, pp, pv)
332 struct ieee_info *info;
336 return ieee_read_optional_number (info, pp, pv, (boolean *) NULL);
339 /* Read a number in an IEEE file. If ppresent is not NULL, the number
340 need not be there. */
343 ieee_read_optional_number (info, pp, pv, ppresent)
344 struct ieee_info *info;
349 ieee_record_enum_type b;
351 if (*pp >= info->pend)
353 if (ppresent != NULL)
362 b = (ieee_record_enum_type) **pp;
365 if (b <= ieee_number_end_enum)
368 if (ppresent != NULL)
373 if (b >= ieee_number_repeat_start_enum && b <= ieee_number_repeat_end_enum)
377 i = (int) b - (int) ieee_number_repeat_start_enum;
378 if (*pp + i - 1 >= info->pend)
392 if (ppresent != NULL)
398 if (ppresent != NULL)
405 ieee_error (info, *pp - 1, "invalid number");
409 /* Read a required string from an IEEE file. */
412 ieee_read_id (info, pp, pname, pnamlen)
413 struct ieee_info *info;
416 unsigned long *pnamlen;
418 return ieee_read_optional_id (info, pp, pname, pnamlen, (boolean *) NULL);
421 /* Read a string from an IEEE file. If ppresent is not NULL, the
422 string is optional. */
425 ieee_read_optional_id (info, pp, pname, pnamlen, ppresent)
426 struct ieee_info *info;
429 unsigned long *pnamlen;
435 if (*pp >= info->pend)
446 else if ((ieee_record_enum_type) b == ieee_extension_length_1_enum)
451 else if ((ieee_record_enum_type) b == ieee_extension_length_2_enum)
453 len = (**pp << 8) + (*pp)[1];
458 if (ppresent != NULL)
464 ieee_error (info, *pp - 1, "invalid string length");
468 if ((unsigned long) (info->pend - *pp) < len)
474 *pname = (const char *) *pp;
478 if (ppresent != NULL)
484 /* Read an expression from an IEEE file. Since this code is only used
485 to parse debugging information, I haven't bothered to write a full
486 blown IEEE expression parser. I've only thrown in the things I've
487 seen in debugging information. This can be easily extended if
491 ieee_read_expression (info, pp, pv)
492 struct ieee_info *info;
496 const bfd_byte *expr_start;
497 #define EXPR_STACK_SIZE (10)
498 bfd_vma expr_stack[EXPR_STACK_SIZE];
507 const bfd_byte *start;
510 ieee_record_enum_type c;
514 if (! ieee_read_optional_number (info, pp, &val, &present))
519 if (esp - expr_stack >= EXPR_STACK_SIZE)
521 ieee_error (info, start, "expression stack overflow");
528 c = (ieee_record_enum_type) **pp;
530 if (c >= ieee_module_beginning_enum)
541 ieee_error (info, start, "unsupported IEEE expression operator");
544 case ieee_variable_R_enum:
549 if (! ieee_read_number (info, pp, &indx))
551 for (s = info->abfd->sections; s != NULL; s = s->next)
552 if ((bfd_vma) s->target_index == indx)
556 ieee_error (info, start, "unknown section");
560 if (esp - expr_stack >= EXPR_STACK_SIZE)
562 ieee_error (info, start, "expression stack overflow");
566 *esp++ = bfd_get_section_vma (info->abfd, s);
570 case ieee_function_plus_enum:
571 case ieee_function_minus_enum:
575 if (esp - expr_stack < 2)
577 ieee_error (info, start, "expression stack underflow");
589 if (esp - 1 != expr_stack)
591 ieee_error (info, expr_start, "expression stack mismatch");
600 /* Return an IEEE builtin type. */
603 ieee_builtin_type (info, p, indx)
604 struct ieee_info *info;
612 if (indx < BUILTIN_TYPE_COUNT
613 && info->types.builtins[indx] != DEBUG_TYPE_NULL)
614 return info->types.builtins[indx];
616 dhandle = info->dhandle;
618 if (indx >= 32 && indx < 64)
620 type = debug_make_pointer_type (dhandle,
621 ieee_builtin_type (info, p, indx - 32));
622 assert (indx < BUILTIN_TYPE_COUNT);
623 info->types.builtins[indx] = type;
627 switch ((enum builtin_types) indx)
630 ieee_error (info, p, "unknown builtin type");
633 case builtin_unknown:
634 type = debug_make_void_type (dhandle);
639 type = debug_make_void_type (dhandle);
643 case builtin_signed_char:
644 type = debug_make_int_type (dhandle, 1, false);
645 name = "signed char";
648 case builtin_unsigned_char:
649 type = debug_make_int_type (dhandle, 1, true);
650 name = "unsigned char";
653 case builtin_signed_short_int:
654 type = debug_make_int_type (dhandle, 2, false);
655 name = "signed short int";
658 case builtin_unsigned_short_int:
659 type = debug_make_int_type (dhandle, 2, true);
660 name = "unsigned short int";
663 case builtin_signed_long:
664 type = debug_make_int_type (dhandle, 4, false);
665 name = "signed long";
668 case builtin_unsigned_long:
669 type = debug_make_int_type (dhandle, 4, true);
670 name = "unsigned long";
673 case builtin_signed_long_long:
674 type = debug_make_int_type (dhandle, 8, false);
675 name = "signed long long";
678 case builtin_unsigned_long_long:
679 type = debug_make_int_type (dhandle, 8, true);
680 name = "unsigned long long";
684 type = debug_make_float_type (dhandle, 4);
689 type = debug_make_float_type (dhandle, 8);
693 case builtin_long_double:
694 /* FIXME: The size for this type should depend upon the
696 type = debug_make_float_type (dhandle, 12);
697 name = "long double";
700 case builtin_long_long_double:
701 type = debug_make_float_type (dhandle, 16);
702 name = "long long double";
705 case builtin_quoted_string:
706 type = debug_make_array_type (dhandle,
707 ieee_builtin_type (info, p,
710 ieee_builtin_type (info, p,
714 name = "QUOTED STRING";
717 case builtin_instruction_address:
718 /* FIXME: This should be a code address. */
719 type = debug_make_int_type (dhandle, 4, true);
720 name = "instruction address";
724 /* FIXME: The size for this type should depend upon the
726 type = debug_make_int_type (dhandle, 4, false);
730 case builtin_unsigned:
731 /* FIXME: The size for this type should depend upon the
733 type = debug_make_int_type (dhandle, 4, true);
737 case builtin_unsigned_int:
738 /* FIXME: The size for this type should depend upon the
740 type = debug_make_int_type (dhandle, 4, true);
741 name = "unsigned int";
745 type = debug_make_int_type (dhandle, 1, false);
750 type = debug_make_int_type (dhandle, 4, false);
755 type = debug_make_int_type (dhandle, 2, false);
759 case builtin_unsigned_short:
760 type = debug_make_int_type (dhandle, 2, true);
761 name = "unsigned short";
764 case builtin_short_int:
765 type = debug_make_int_type (dhandle, 2, false);
769 case builtin_signed_short:
770 type = debug_make_int_type (dhandle, 2, false);
771 name = "signed short";
774 case builtin_bcd_float:
775 ieee_error (info, p, "BCD float type not supported");
780 type = debug_name_type (dhandle, name, type);
782 assert (indx < BUILTIN_TYPE_COUNT);
784 info->types.builtins[indx] = type;
789 /* Allocate more space in the type table. If ref is true, this is a
790 reference to the type; if it is not already defined, we should set
791 up an indirect type. */
794 ieee_alloc_type (info, indx, ref)
795 struct ieee_info *info;
800 register struct ieee_type *t;
801 struct ieee_type *tend;
803 if (indx >= info->types.alloc)
805 nalloc = info->types.alloc;
808 while (indx >= nalloc)
811 info->types.types = ((struct ieee_type *)
812 xrealloc (info->types.types,
813 nalloc * sizeof *info->types.types));
815 memset (info->types.types + info->types.alloc, 0,
816 (nalloc - info->types.alloc) * sizeof *info->types.types);
818 tend = info->types.types + nalloc;
819 for (t = info->types.types + info->types.alloc; t < tend; t++)
820 t->type = DEBUG_TYPE_NULL;
822 info->types.alloc = nalloc;
827 t = info->types.types + indx;
830 t->pslot = (debug_type *) xmalloc (sizeof *t->pslot);
831 *t->pslot = DEBUG_TYPE_NULL;
832 t->type = debug_make_indirect_type (info->dhandle, t->pslot,
833 (const char *) NULL);
842 /* Read a type index and return the corresponding type. */
845 ieee_read_type_index (info, pp, ptype)
846 struct ieee_info *info;
850 const bfd_byte *start;
855 if (! ieee_read_number (info, pp, &indx))
860 *ptype = ieee_builtin_type (info, start, indx);
867 if (! ieee_alloc_type (info, indx, true))
870 *ptype = info->types.types[indx].type;
875 /* Parse IEEE debugging information for a file. This is passed the
876 bytes which compose the Debug Information Part of an IEEE file. */
879 parse_ieee (dhandle, abfd, bytes, len)
882 const bfd_byte *bytes;
885 struct ieee_info info;
887 const bfd_byte *p, *pend;
889 info.dhandle = dhandle;
892 info.pend = bytes + len;
893 info.blockstack.bsp = info.blockstack.stack;
895 info.vars.vars = NULL;
896 info.types.alloc = 0;
897 info.types.types = NULL;
899 for (i = 0; i < BUILTIN_TYPE_COUNT; i++)
900 info.types.builtins[i] = DEBUG_TYPE_NULL;
906 const bfd_byte *record_start;
907 ieee_record_enum_type c;
911 c = (ieee_record_enum_type) *p++;
913 if (c == ieee_at_record_enum)
914 c = (ieee_record_enum_type) (((unsigned int) c << 8) | *p++);
916 if (c <= ieee_number_repeat_end_enum)
918 ieee_error (&info, record_start, "unexpected number");
925 ieee_error (&info, record_start, "unexpected record type");
928 case ieee_bb_record_enum:
929 if (! parse_ieee_bb (&info, &p))
933 case ieee_be_record_enum:
934 if (! parse_ieee_be (&info, &p))
939 if (! parse_ieee_nn (&info, &p))
943 case ieee_ty_record_enum:
944 if (! parse_ieee_ty (&info, &p))
948 case ieee_atn_record_enum:
949 if (! parse_ieee_atn (&info, &p))
955 if (info.blockstack.bsp != info.blockstack.stack)
957 ieee_error (&info, (const bfd_byte *) NULL,
958 "blocks left on stack at end");
965 /* Handle an IEEE BB record. */
968 parse_ieee_bb (info, pp)
969 struct ieee_info *info;
972 const bfd_byte *block_start;
976 unsigned long namlen;
986 if (! ieee_read_number (info, pp, &size)
987 || ! ieee_read_id (info, pp, &name, &namlen))
990 fnindx = (unsigned int) -1;
996 /* BB1: Type definitions local to a module. */
997 namcopy = savestring (name, namlen);
1000 if (! debug_set_filename (info->dhandle, namcopy))
1005 /* BB2: Global type definitions. The name is supposed to be
1006 empty, but we don't check. */
1007 if (! debug_set_filename (info->dhandle, "*global*"))
1012 /* BB3: High level module block begin. We don't have to do
1013 anything here. The name is supposed to be the same as for
1014 the BB1, but we don't check. */
1018 /* BB4: Global function. */
1020 bfd_vma stackspace, typindx, offset;
1021 debug_type return_type;
1023 if (! ieee_read_number (info, pp, &stackspace)
1024 || ! ieee_read_number (info, pp, &typindx)
1025 || ! ieee_read_expression (info, pp, &offset))
1028 /* We have no way to record the stack space. FIXME. */
1032 return_type = ieee_builtin_type (info, block_start, typindx);
1033 if (return_type == DEBUG_TYPE_NULL)
1039 if (! ieee_alloc_type (info, typindx, true))
1042 return_type = info->types.types[typindx].type;
1043 if (debug_get_type_kind (info->dhandle, return_type)
1044 == DEBUG_KIND_FUNCTION)
1045 return_type = debug_get_return_type (info->dhandle,
1049 namcopy = savestring (name, namlen);
1050 if (namcopy == NULL)
1052 if (! debug_record_function (info->dhandle, namcopy, return_type,
1059 /* BB5: File name for source line numbers. */
1063 /* We ignore the date and time. FIXME. */
1064 for (i = 0; i < 6; i++)
1069 if (! ieee_read_optional_number (info, pp, &ignore, &present))
1075 namcopy = savestring (name, namlen);
1076 if (namcopy == NULL)
1078 if (! debug_start_source (info->dhandle, namcopy))
1084 /* BB6: Local function or block. */
1086 bfd_vma stackspace, typindx, offset;
1088 if (! ieee_read_number (info, pp, &stackspace)
1089 || ! ieee_read_number (info, pp, &typindx)
1090 || ! ieee_read_expression (info, pp, &offset))
1093 /* We have no way to record the stack space. FIXME. */
1097 if (! debug_start_block (info->dhandle, offset))
1099 /* Change b to indicate that this is a block
1100 rather than a function. */
1105 /* The MRI C++ compiler will output a fake function named
1106 __XRYCPP to hold C++ debugging information. We skip
1107 that function. This is not crucial, but it makes
1108 converting from IEEE to other debug formats work
1110 if (strncmp (name, "__XRYCPP", namlen) == 0)
1114 debug_type return_type;
1118 return_type = ieee_builtin_type (info, block_start,
1120 if (return_type == NULL)
1126 if (! ieee_alloc_type (info, typindx, true))
1129 return_type = info->types.types[typindx].type;
1130 if (debug_get_type_kind (info->dhandle, return_type)
1131 == DEBUG_KIND_FUNCTION)
1132 return_type = debug_get_return_type (info->dhandle,
1136 namcopy = savestring (name, namlen);
1137 if (namcopy == NULL)
1139 if (! debug_record_function (info->dhandle, namcopy,
1140 return_type, false, offset))
1148 /* BB10: Assembler module scope. We completely ignore all this
1149 information. FIXME. */
1151 const char *inam, *vstr;
1152 unsigned long inamlen, vstrlen;
1157 if (! ieee_read_id (info, pp, &inam, &inamlen)
1158 || ! ieee_read_number (info, pp, &tool_type)
1159 || ! ieee_read_optional_id (info, pp, &vstr, &vstrlen, &present))
1161 for (i = 0; i < 6; i++)
1165 if (! ieee_read_optional_number (info, pp, &ignore, &present))
1174 /* BB11: Module section. We completely ignore all this
1175 information. FIXME. */
1177 bfd_vma sectype, secindx, offset, map;
1180 if (! ieee_read_number (info, pp, §ype)
1181 || ! ieee_read_number (info, pp, &secindx)
1182 || ! ieee_read_expression (info, pp, &offset)
1183 || ! ieee_read_optional_number (info, pp, &map, &present))
1189 ieee_error (info, block_start, "unknown BB type");
1194 /* Push this block on the block stack. */
1196 if (info->blockstack.bsp >= info->blockstack.stack + BLOCKSTACK_SIZE)
1198 ieee_error (info, (const bfd_byte *) NULL, "stack overflow");
1202 info->blockstack.bsp->kind = b;
1204 info->blockstack.bsp->filename = namcopy;
1205 info->blockstack.bsp->fnindx = fnindx;
1206 info->blockstack.bsp->skip = skip;
1207 ++info->blockstack.bsp;
1212 /* Handle an IEEE BE record. */
1215 parse_ieee_be (info, pp)
1216 struct ieee_info *info;
1217 const bfd_byte **pp;
1221 if (info->blockstack.bsp <= info->blockstack.stack)
1223 ieee_error (info, *pp, "stack underflow");
1226 --info->blockstack.bsp;
1228 switch (info->blockstack.bsp->kind)
1232 if (! ieee_read_expression (info, pp, &offset))
1234 if (! info->blockstack.bsp->skip)
1236 if (! debug_end_function (info->dhandle, offset + 1))
1242 /* This is BE6 when BB6 started a block rather than a local
1244 if (! ieee_read_expression (info, pp, &offset))
1246 if (! debug_end_block (info->dhandle, offset + 1))
1251 /* When we end a BB5, we look up the stack for the last BB5, if
1252 there is one, so that we can call debug_start_source. */
1253 if (info->blockstack.bsp > info->blockstack.stack)
1255 struct ieee_block *bl;
1257 bl = info->blockstack.bsp;
1263 if (! debug_start_source (info->dhandle, bl->filename))
1268 while (bl != info->blockstack.stack);
1273 if (! ieee_read_expression (info, pp, &offset))
1275 /* We just ignore the module size. FIXME. */
1279 /* Other block types do not have any trailing information. */
1286 /* Parse an NN record. */
1289 parse_ieee_nn (info, pp)
1290 struct ieee_info *info;
1291 const bfd_byte **pp;
1293 const bfd_byte *nn_start;
1296 unsigned long namlen;
1300 if (! ieee_read_number (info, pp, &varindx)
1301 || ! ieee_read_id (info, pp, &name, &namlen))
1306 ieee_error (info, nn_start, "illegal variable index");
1311 if (varindx >= info->vars.alloc)
1315 alloc = info->vars.alloc;
1318 while (varindx >= alloc)
1320 info->vars.vars = ((struct ieee_var *)
1321 xrealloc (info->vars.vars,
1322 alloc * sizeof *info->vars.vars));
1323 memset (info->vars.vars + info->vars.alloc, 0,
1324 (alloc - info->vars.alloc) * sizeof *info->vars.vars);
1325 info->vars.alloc = alloc;
1328 info->vars.vars[varindx].name = name;
1329 info->vars.vars[varindx].namlen = namlen;
1334 /* Parse a TY record. */
1337 parse_ieee_ty (info, pp)
1338 struct ieee_info *info;
1339 const bfd_byte **pp;
1341 const bfd_byte *ty_start, *ty_var_start, *ty_code_start;
1342 bfd_vma typeindx, varindx, tc;
1344 boolean tag, typdef;
1345 debug_type *arg_slots;
1346 unsigned long type_bitsize;
1351 if (! ieee_read_number (info, pp, &typeindx))
1356 ieee_error (info, ty_start, "illegal type index");
1361 if (! ieee_alloc_type (info, typeindx, false))
1366 ieee_error (info, *pp, "unknown TY code");
1373 if (! ieee_read_number (info, pp, &varindx))
1378 ieee_error (info, ty_var_start, "illegal variable index");
1383 if (varindx >= info->vars.alloc || info->vars.vars[varindx].name == NULL)
1385 ieee_error (info, ty_var_start, "undefined variable in TY");
1389 ty_code_start = *pp;
1391 if (! ieee_read_number (info, pp, &tc))
1394 dhandle = info->dhandle;
1403 ieee_error (info, ty_code_start, "unknown TY code");
1407 /* Unknown type, with size. We treat it as int. FIXME. */
1411 if (! ieee_read_number (info, pp, &size))
1413 type = debug_make_int_type (dhandle, size, false);
1417 case 'A': /* Array. */
1418 case 'a': /* FORTRAN array in column/row order. FIXME: Not
1419 distinguished from normal array. */
1421 debug_type ele_type;
1422 bfd_vma lower, upper;
1424 if (! ieee_read_type_index (info, pp, &ele_type)
1425 || ! ieee_read_number (info, pp, &lower)
1426 || ! ieee_read_number (info, pp, &upper))
1428 type = debug_make_array_type (dhandle, ele_type,
1429 ieee_builtin_type (info, ty_code_start,
1432 (bfd_signed_vma) lower,
1433 (bfd_signed_vma) upper,
1439 /* Simple enumeration. */
1445 bfd_signed_vma *vals;
1448 if (! ieee_read_number (info, pp, &size))
1450 /* FIXME: we ignore the enumeration size. */
1453 names = (const char **) xmalloc (alloc * sizeof *names);
1454 memset (names, 0, alloc * sizeof *names);
1459 unsigned long namlen;
1462 if (! ieee_read_optional_id (info, pp, &name, &namlen, &present))
1470 names = ((const char **)
1471 xrealloc (names, alloc * sizeof *names));
1474 names[c] = savestring (name, namlen);
1475 if (names[c] == NULL)
1482 vals = (bfd_signed_vma *) xmalloc (c * sizeof *vals);
1483 for (i = 0; i < c; i++)
1486 type = debug_make_enum_type (dhandle, names, vals);
1492 /* Struct with bit fields. */
1496 debug_field *fields;
1499 if (! ieee_read_number (info, pp, &size))
1503 fields = (debug_field *) xmalloc (alloc * sizeof *fields);
1508 unsigned long namlen;
1511 bfd_vma bitpos, bitsize;
1513 if (! ieee_read_optional_id (info, pp, &name, &namlen, &present))
1517 if (! ieee_read_type_index (info, pp, &ftype)
1518 || ! ieee_read_number (info, pp, &bitpos)
1519 || ! ieee_read_number (info, pp, &bitsize))
1525 fields = ((debug_field *)
1526 xrealloc (fields, alloc * sizeof *fields));
1529 fields[c] = debug_make_field (dhandle, savestring (name, namlen),
1530 ftype, bitpos, bitsize,
1531 DEBUG_VISIBILITY_PUBLIC);
1532 if (fields[c] == NULL)
1539 type = debug_make_struct_type (dhandle, true, size, fields);
1549 bfd_signed_vma *vals;
1553 names = (const char **) xmalloc (alloc * sizeof *names);
1554 vals = (bfd_signed_vma *) xmalloc (alloc * sizeof *names);
1559 unsigned long namlen;
1563 if (! ieee_read_optional_id (info, pp, &name, &namlen, &present))
1567 if (! ieee_read_number (info, pp, &val))
1570 /* If the length of the name is zero, then the value is
1571 actually the size of the enum. We ignore this
1572 information. FIXME. */
1579 names = ((const char **)
1580 xrealloc (names, alloc * sizeof *names));
1581 vals = ((bfd_signed_vma *)
1582 xrealloc (vals, alloc * sizeof *vals));
1585 names[c] = savestring (name, namlen);
1586 if (names[c] == NULL)
1588 vals[c] = (bfd_signed_vma) val;
1594 type = debug_make_enum_type (dhandle, names, vals);
1599 case 'O': /* Small pointer. We don't distinguish small and large
1601 case 'P': /* Large pointer. */
1605 if (! ieee_read_type_index (info, pp, &t))
1607 type = debug_make_pointer_type (dhandle, t);
1614 bfd_vma low, high, signedp, size;
1616 if (! ieee_read_number (info, pp, &low)
1617 || ! ieee_read_number (info, pp, &high)
1618 || ! ieee_read_number (info, pp, &signedp)
1619 || ! ieee_read_number (info, pp, &size))
1622 type = debug_make_range_type (dhandle,
1623 debug_make_int_type (dhandle, size,
1625 (bfd_signed_vma) low,
1626 (bfd_signed_vma) high);
1630 case 'S': /* Struct. */
1631 case 'U': /* Union. */
1635 debug_field *fields;
1638 if (! ieee_read_number (info, pp, &size))
1642 fields = (debug_field *) xmalloc (alloc * sizeof *fields);
1647 unsigned long namlen;
1654 if (! ieee_read_optional_id (info, pp, &name, &namlen, &present))
1658 if (! ieee_read_number (info, pp, &tindx)
1659 || ! ieee_read_number (info, pp, &offset))
1664 ftype = ieee_builtin_type (info, ty_code_start, tindx);
1670 struct ieee_type *t;
1673 if (! ieee_alloc_type (info, tindx, true))
1675 t = info->types.types + tindx;
1677 bitsize = t->bitsize;
1685 fields = ((debug_field *)
1686 xrealloc (fields, alloc * sizeof *fields));
1689 fields[c] = debug_make_field (dhandle, savestring (name, namlen),
1690 ftype, offset, bitsize,
1691 DEBUG_VISIBILITY_PUBLIC);
1692 if (fields[c] == NULL)
1699 type = debug_make_struct_type (dhandle, tc == 'S', size, fields);
1706 if (! ieee_read_type_index (info, pp, &type))
1712 /* Procedure. FIXME: This is an extern declaration, which we
1713 have no way of representing. */
1719 struct ieee_var *pv;
1721 /* FIXME: We ignore the attribute and the argument names. */
1723 if (! ieee_read_number (info, pp, &attr)
1724 || ! ieee_read_type_index (info, pp, &rtype)
1725 || ! ieee_read_number (info, pp, &nargs))
1730 unsigned long namlen;
1732 if (! ieee_read_optional_id (info, pp, &name, &namlen, &present))
1737 pv = info->vars.vars + varindx;
1738 pv->kind = IEEE_EXTERNAL;
1740 && debug_get_type_kind (dhandle, rtype) == DEBUG_KIND_POINTER)
1742 /* Set up the return type as an indirect type pointing to
1743 the variable slot, so that we can change it to a
1744 reference later if appropriate. */
1745 pv->pslot = (debug_type *) xmalloc (sizeof *pv->pslot);
1747 rtype = debug_make_indirect_type (dhandle, pv->pslot,
1748 (const char *) NULL);
1751 type = debug_make_function_type (dhandle, rtype, (debug_type *) NULL,
1757 /* Void. This is not documented, but the MRI compiler emits it. */
1758 type = debug_make_void_type (dhandle);
1762 /* Array with 0 lower bound. */
1767 if (! ieee_read_type_index (info, pp, &etype)
1768 || ! ieee_read_number (info, pp, &high))
1771 type = debug_make_array_type (dhandle, etype,
1772 ieee_builtin_type (info, ty_code_start,
1775 0, (bfd_signed_vma) high, false);
1779 case 'c': /* Complex. */
1780 case 'd': /* Double complex. */
1783 unsigned long namlen;
1785 /* FIXME: I don't know what the name means. */
1787 if (! ieee_read_id (info, pp, &name, &namlen))
1790 type = debug_make_complex_type (dhandle, tc == 'c' ? 4 : 8);
1795 /* Pascal file name. FIXME. */
1796 ieee_error (info, ty_code_start, "Pascal file name not supported");
1800 /* Bitfield type. */
1802 bfd_vma signedp, bitsize;
1804 if (! ieee_read_number (info, pp, &signedp)
1805 || ! ieee_read_number (info, pp, &bitsize)
1806 || ! ieee_read_type_index (info, pp, &type))
1809 /* FIXME: This is just a guess. */
1811 type = debug_make_int_type (dhandle, 4, true);
1812 type_bitsize = bitsize;
1822 if (! ieee_read_number (info, pp, &kind)
1823 || ! ieee_read_type_index (info, pp, &t))
1829 ieee_error (info, ty_start, "unsupported qualifer");
1833 type = debug_make_const_type (dhandle, t);
1837 type = debug_make_volatile_type (dhandle, t);
1849 if (! ieee_read_number (info, pp, &size)
1850 || ! ieee_read_type_index (info, pp, &etype))
1853 /* FIXME: We ignore the size. */
1855 type = debug_make_set_type (dhandle, etype, false);
1860 /* Procedure with compiler dependencies. */
1862 struct ieee_var *pv;
1863 bfd_vma attr, frame_type, push_mask, nargs, level, father;
1865 debug_type *arg_types;
1869 /* FIXME: We ignore some of this information. */
1871 pv = info->vars.vars + varindx;
1873 if (! ieee_read_number (info, pp, &attr)
1874 || ! ieee_read_number (info, pp, &frame_type)
1875 || ! ieee_read_number (info, pp, &push_mask)
1876 || ! ieee_read_type_index (info, pp, &rtype)
1877 || ! ieee_read_number (info, pp, &nargs))
1879 if (nargs == (bfd_vma) -1)
1888 arg_types = ((debug_type *)
1889 xmalloc ((nargs + 1) * sizeof *arg_types));
1890 for (i = 0; i < nargs; i++)
1891 if (! ieee_read_type_index (info, pp, arg_types + i))
1894 /* If the last type is pointer to void, this is really a
1895 varargs function. */
1901 last = arg_types[nargs - 1];
1902 if (debug_get_type_kind (dhandle, last) == DEBUG_KIND_POINTER
1903 && (debug_get_type_kind (dhandle,
1904 debug_get_target_type (dhandle,
1906 == DEBUG_KIND_VOID))
1913 /* If there are any pointer arguments, turn them into
1914 indirect types in case we later need to convert them to
1916 for (i = 0; i < nargs; i++)
1918 if (debug_get_type_kind (dhandle, arg_types[i])
1919 == DEBUG_KIND_POINTER)
1921 if (arg_slots == NULL)
1923 arg_slots = ((debug_type *)
1924 xmalloc (nargs * sizeof *arg_slots));
1925 memset (arg_slots, 0, nargs * sizeof *arg_slots);
1927 arg_slots[i] = arg_types[i];
1929 debug_make_indirect_type (dhandle,
1931 (const char *) NULL);
1935 arg_types[nargs] = DEBUG_TYPE_NULL;
1937 if (! ieee_read_number (info, pp, &level)
1938 || ! ieee_read_optional_number (info, pp, &father, &present))
1941 /* We can't distinguish between a global function and a static
1943 pv->kind = IEEE_FUNCTION;
1946 && debug_get_type_kind (dhandle, rtype) == DEBUG_KIND_POINTER)
1948 /* Set up the return type as an indirect type pointing to
1949 the variable slot, so that we can change it to a
1950 reference later if appropriate. */
1951 pv->pslot = (debug_type *) xmalloc (sizeof *pv->pslot);
1953 rtype = debug_make_indirect_type (dhandle, pv->pslot,
1954 (const char *) NULL);
1957 type = debug_make_function_type (dhandle, rtype, arg_types, varargs);
1962 /* Record the type in the table. If the corresponding NN record has
1963 a name, name it. FIXME: Is this always correct? */
1965 if (type == DEBUG_TYPE_NULL)
1968 info->vars.vars[varindx].type = type;
1971 && info->vars.vars[varindx].namlen > 0)
1975 name = savestring (info->vars.vars[varindx].name,
1976 info->vars.vars[varindx].namlen);
1978 type = debug_name_type (dhandle, name, type);
1979 else if (tc == 'E' || tc == 'N')
1980 type = debug_tag_type (dhandle, name, type);
1983 struct ieee_tag *it;
1985 /* We must allocate all struct tags as indirect types, so
1986 that if we later see a definition of the tag as a C++
1987 record we can update the indirect slot and automatically
1988 change all the existing references. */
1989 it = (struct ieee_tag *) xmalloc (sizeof *it);
1990 memset (it, 0, sizeof *it);
1991 it->next = info->tags;
1996 type = debug_make_indirect_type (dhandle, &it->slot, name);
1997 type = debug_tag_type (dhandle, name, type);
2005 info->types.types[typeindx].type = type;
2006 info->types.types[typeindx].arg_slots = arg_slots;
2007 info->types.types[typeindx].bitsize = type_bitsize;
2009 /* We may have already allocated type as an indirect type pointing
2010 to slot. It does no harm to replace the indirect type with the
2011 real type. Filling in slot as well handles the indirect types
2012 which are already hanging around. */
2013 if (info->types.types[typeindx].pslot != NULL)
2014 *info->types.types[typeindx].pslot = type;
2019 /* Parse an ATN record. */
2022 parse_ieee_atn (info, pp)
2023 struct ieee_info *info;
2024 const bfd_byte **pp;
2026 const bfd_byte *atn_start, *atn_code_start;
2028 struct ieee_var *pvar;
2032 bfd_vma v, v2, v3, v4, v5;
2034 unsigned long namlen;
2041 if (! ieee_read_number (info, pp, &varindx)
2042 || ! ieee_read_type_index (info, pp, &type))
2045 atn_code_start = *pp;
2047 if (! ieee_read_number (info, pp, &atn_code))
2056 else if (varindx < 32)
2058 ieee_error (info, atn_start, "illegal variable index");
2064 if (varindx >= info->vars.alloc
2065 || info->vars.vars[varindx].name == NULL)
2067 ieee_error (info, atn_start, "undefined variable in ATN");
2071 pvar = info->vars.vars + varindx;
2076 namlen = pvar->namlen;
2079 dhandle = info->dhandle;
2081 /* If we are going to call debug_record_variable with a pointer
2082 type, change the type to an indirect type so that we can later
2083 change it to a reference type if we encounter a C++ pmisc 'R'
2086 && type != DEBUG_TYPE_NULL
2087 && debug_get_type_kind (dhandle, type) == DEBUG_KIND_POINTER)
2097 pvar->pslot = (debug_type *) xmalloc (sizeof *pvar->pslot);
2098 *pvar->pslot = type;
2099 type = debug_make_indirect_type (dhandle, pvar->pslot,
2100 (const char *) NULL);
2109 ieee_error (info, atn_code_start, "unknown ATN type");
2113 /* Automatic variable. */
2114 if (! ieee_read_number (info, pp, &v))
2116 namcopy = savestring (name, namlen);
2118 type = debug_make_void_type (dhandle);
2120 pvar->kind = IEEE_LOCAL;
2121 return debug_record_variable (dhandle, namcopy, type, DEBUG_LOCAL, v);
2124 /* Register variable. */
2125 if (! ieee_read_number (info, pp, &v))
2127 namcopy = savestring (name, namlen);
2129 type = debug_make_void_type (dhandle);
2131 pvar->kind = IEEE_LOCAL;
2132 return debug_record_variable (dhandle, namcopy, type, DEBUG_REGISTER,
2133 ieee_regno_to_genreg (info->abfd, v));
2136 /* Static variable. */
2137 if (! ieee_require_asn (info, pp, &v))
2139 namcopy = savestring (name, namlen);
2141 type = debug_make_void_type (dhandle);
2142 if (info->blockstack.bsp <= info->blockstack.stack)
2145 blocktype = info->blockstack.bsp[-1].kind;
2148 if (blocktype == 4 || blocktype == 6)
2149 pvar->kind = IEEE_LOCAL;
2151 pvar->kind = IEEE_STATIC;
2153 return debug_record_variable (dhandle, namcopy, type,
2154 (blocktype == 4 || blocktype == 6
2155 ? DEBUG_LOCAL_STATIC
2160 /* External function. We don't currently record these. FIXME. */
2162 pvar->kind = IEEE_EXTERNAL;
2166 /* External variable. We don't currently record these. FIXME. */
2168 pvar->kind = IEEE_EXTERNAL;
2172 if (! ieee_read_number (info, pp, &v)
2173 || ! ieee_read_number (info, pp, &v2)
2174 || ! ieee_read_optional_number (info, pp, &v3, &present))
2178 if (! ieee_read_optional_number (info, pp, &v4, &present))
2182 /* We just ignore the two optional fields in v3 and v4, since
2183 they are not defined. */
2185 if (! ieee_require_asn (info, pp, &v3))
2188 /* We have no way to record the column number. FIXME. */
2190 return debug_record_line (dhandle, v, v3);
2193 /* Global variable. */
2194 if (! ieee_require_asn (info, pp, &v))
2196 namcopy = savestring (name, namlen);
2198 type = debug_make_void_type (dhandle);
2200 pvar->kind = IEEE_GLOBAL;
2201 return debug_record_variable (dhandle, namcopy, type, DEBUG_GLOBAL, v);
2204 /* Variable lifetime information. */
2205 if (! ieee_read_number (info, pp, &v))
2208 /* We have no way to record this information. FIXME. */
2212 /* Locked register. The spec says that there are two required
2213 fields, but at least on occasion the MRI compiler only emits
2215 if (! ieee_read_number (info, pp, &v)
2216 || ! ieee_read_optional_number (info, pp, &v2, &present))
2219 /* I think this means a variable that is both in a register and
2220 a frame slot. We ignore the frame slot. FIXME. */
2222 namcopy = savestring (name, namlen);
2224 type = debug_make_void_type (dhandle);
2226 pvar->kind = IEEE_LOCAL;
2227 return debug_record_variable (dhandle, namcopy, type, DEBUG_REGISTER, v);
2230 /* Reserved for FORTRAN common. */
2231 ieee_error (info, atn_code_start, "unsupported ATN11");
2233 /* Return true to keep going. */
2237 /* Based variable. */
2241 if (! ieee_read_number (info, pp, &v)
2242 || ! ieee_read_number (info, pp, &v2)
2243 || ! ieee_read_optional_number (info, pp, &v3, &present))
2247 if (! ieee_read_optional_number (info, pp, &v4, &present))
2251 if (! ieee_read_optional_number (info, pp, &v5, &present))
2256 /* We have no way to record this information. FIXME. */
2258 ieee_error (info, atn_code_start, "unsupported ATN12");
2260 /* Return true to keep going. */
2264 /* Constant. The description of this that I have is ambiguous,
2265 so I'm not going to try to implement it. */
2266 if (! ieee_read_number (info, pp, &v)
2267 || ! ieee_read_optional_number (info, pp, &v2, &present))
2271 if (! ieee_read_optional_number (info, pp, &v2, &present))
2275 if (! ieee_read_optional_id (info, pp, &name, &namlen, &present))
2280 if ((ieee_record_enum_type) **pp == ieee_e2_first_byte_enum)
2282 if (! ieee_require_asn (info, pp, &v3))
2289 /* Static variable from assembler. */
2291 if (! ieee_read_number (info, pp, &v)
2292 || ! ieee_read_optional_number (info, pp, &v2, &present)
2293 || ! ieee_require_asn (info, pp, &v3))
2295 namcopy = savestring (name, namlen);
2296 /* We don't really handle this correctly. FIXME. */
2297 return debug_record_variable (dhandle, namcopy,
2298 debug_make_void_type (dhandle),
2299 v2 != 0 ? DEBUG_GLOBAL : DEBUG_STATIC,
2303 /* Procedure miscellaneous information. */
2305 /* Variable miscellaneous information. */
2307 /* Module miscellaneous information. */
2308 if (! ieee_read_number (info, pp, &v)
2309 || ! ieee_read_number (info, pp, &v2)
2310 || ! ieee_read_optional_id (info, pp, &name, &namlen, &present))
2313 if (atn_code == 62 && v == 80)
2317 ieee_error (info, atn_code_start,
2318 "unexpected string in C++ misc");
2321 return ieee_read_cxx_misc (info, pp, v2);
2324 /* We just ignore all of this stuff. FIXME. */
2326 for (; v2 > 0; --v2)
2328 switch ((ieee_record_enum_type) **pp)
2331 ieee_error (info, *pp, "bad misc record");
2334 case ieee_at_record_enum:
2335 if (! ieee_require_atn65 (info, pp, &name, &namlen))
2339 case ieee_e2_first_byte_enum:
2340 if (! ieee_require_asn (info, pp, &v3))
2352 /* Handle C++ debugging miscellaneous records. This is called for
2353 procedure miscellaneous records of type 80. */
2356 ieee_read_cxx_misc (info, pp, count)
2357 struct ieee_info *info;
2358 const bfd_byte **pp;
2359 unsigned long count;
2361 const bfd_byte *start;
2366 /* Get the category of C++ misc record. */
2367 if (! ieee_require_asn (info, pp, &category))
2374 ieee_error (info, start, "unrecognized C++ misc record");
2378 if (! ieee_read_cxx_class (info, pp, count))
2386 unsigned long namlen;
2388 /* The IEEE spec indicates that the 'M' record only has a
2389 flags field. The MRI compiler also emits the name of the
2392 if (! ieee_require_asn (info, pp, &flags))
2394 if (*pp < info->pend
2395 && (ieee_record_enum_type) **pp == ieee_at_record_enum)
2397 if (! ieee_require_atn65 (info, pp, &name, &namlen))
2401 /* This is emitted for method functions, but I don't think we
2402 care very much. It might help if it told us useful
2403 information like the class with which this function is
2404 associated, but it doesn't, so it isn't helpful. */
2409 if (! ieee_read_cxx_defaults (info, pp, count))
2415 const char *name, *mangled, *class;
2416 unsigned long namlen, mangledlen, classlen;
2419 /* Pointer to member. */
2421 if (! ieee_require_atn65 (info, pp, &name, &namlen)
2422 || ! ieee_require_atn65 (info, pp, &mangled, &mangledlen)
2423 || ! ieee_require_atn65 (info, pp, &class, &classlen)
2424 || ! ieee_require_asn (info, pp, &control))
2427 /* FIXME: We should now track down name and change its type. */
2432 if (! ieee_read_reference (info, pp))
2440 /* Read a C++ class definition. This is a pmisc type 80 record of
2444 ieee_read_cxx_class (info, pp, count)
2445 struct ieee_info *info;
2446 const bfd_byte **pp;
2447 unsigned long count;
2449 const bfd_byte *start;
2452 unsigned long taglen;
2453 struct ieee_tag *it;
2455 debug_field *fields;
2456 unsigned int field_count, field_alloc;
2457 debug_baseclass *baseclasses;
2458 unsigned int baseclasses_count, baseclasses_alloc;
2459 const debug_field *structfields;
2463 unsigned long namlen;
2464 debug_method_variant *variants;
2468 unsigned int methods_count, methods_alloc;
2469 debug_type vptrbase;
2471 debug_method *dmethods;
2475 if (! ieee_require_asn (info, pp, &class))
2479 if (! ieee_require_atn65 (info, pp, &tag, &taglen))
2483 /* Find the C struct with this name. */
2484 for (it = info->tags; it != NULL; it = it->next)
2485 if (it->name[0] == tag[0]
2486 && strncmp (it->name, tag, taglen) == 0
2487 && strlen (it->name) == taglen)
2491 ieee_error (info, start, "undefined C++ object");
2495 dhandle = info->dhandle;
2501 baseclasses_count = 0;
2502 baseclasses_alloc = 0;
2506 vptrbase = DEBUG_TYPE_NULL;
2509 structfields = debug_get_fields (dhandle, it->type);
2514 const bfd_byte *spec_start;
2518 if (! ieee_require_asn (info, pp, &id))
2525 ieee_error (info, spec_start, "unrecognized C++ object spec");
2530 bfd_vma flags, cinline;
2531 const char *basename, *fieldname;
2532 unsigned long baselen, fieldlen;
2534 debug_type basetype;
2537 enum debug_visibility visibility;
2538 debug_baseclass baseclass;
2540 /* This represents a base or friend class. */
2542 if (! ieee_require_asn (info, pp, &flags)
2543 || ! ieee_require_atn65 (info, pp, &basename, &baselen)
2544 || ! ieee_require_asn (info, pp, &cinline)
2545 || ! ieee_require_atn65 (info, pp, &fieldname, &fieldlen))
2549 /* We have no way of recording friend information, so we
2551 if ((flags & BASEFLAGS_FRIEND) != 0)
2554 /* I assume that either all of the members of the
2555 baseclass are included in the object, starting at the
2556 beginning of the object, or that none of them are
2559 if ((fieldlen == 0) == (cinline == 0))
2561 ieee_error (info, start, "unsupported C++ object type");
2565 basecopy = savestring (basename, baselen);
2566 basetype = debug_find_tagged_type (dhandle, basecopy,
2567 DEBUG_KIND_ILLEGAL);
2569 if (basetype == DEBUG_TYPE_NULL)
2571 ieee_error (info, start, "C++ base class not defined");
2579 const debug_field *pf;
2581 if (structfields == NULL)
2583 ieee_error (info, start, "C++ object has no fields");
2587 for (pf = structfields; *pf != DEBUG_FIELD_NULL; pf++)
2591 fname = debug_get_field_name (dhandle, *pf);
2594 if (fname[0] == fieldname[0]
2595 && strncmp (fname, fieldname, fieldlen) == 0
2596 && strlen (fname) == fieldlen)
2599 if (*pf == DEBUG_FIELD_NULL)
2601 ieee_error (info, start,
2602 "C++ base class not found in container");
2606 bitpos = debug_get_field_bitpos (dhandle, *pf);
2609 if ((flags & BASEFLAGS_VIRTUAL) != 0)
2613 if ((flags & BASEFLAGS_PRIVATE) != 0)
2614 visibility = DEBUG_VISIBILITY_PRIVATE;
2616 visibility = DEBUG_VISIBILITY_PUBLIC;
2618 baseclass = debug_make_baseclass (dhandle, basetype, bitpos,
2619 virtualp, visibility);
2620 if (baseclass == DEBUG_BASECLASS_NULL)
2623 if (baseclasses_count + 1 >= baseclasses_alloc)
2625 baseclasses_alloc += 10;
2626 baseclasses = ((debug_baseclass *)
2627 xrealloc (baseclasses,
2629 * sizeof *baseclasses)));
2632 baseclasses[baseclasses_count] = baseclass;
2633 ++baseclasses_count;
2634 baseclasses[baseclasses_count] = DEBUG_BASECLASS_NULL;
2641 const char *fieldname, *mangledname;
2642 unsigned long fieldlen, mangledlen;
2646 const debug_field *pf;
2647 enum debug_visibility visibility;
2650 /* This represents a data member. */
2652 if (! ieee_require_asn (info, pp, &flags)
2653 || ! ieee_require_atn65 (info, pp, &fieldname, &fieldlen)
2654 || ! ieee_require_atn65 (info, pp, &mangledname, &mangledlen))
2658 fieldcopy = savestring (fieldname, fieldlen);
2660 staticp = (flags & CXXFLAGS_STATIC) != 0 ? true : false;
2664 struct ieee_var *pv, *pvend;
2666 /* See if we can find a definition for this variable. */
2667 pv = info->vars.vars;
2668 pvend = pv + info->vars.alloc;
2669 for (; pv < pvend; pv++)
2670 if (pv->namlen == mangledlen
2671 && strncmp (pv->name, mangledname, mangledlen) == 0)
2677 /* This can happen if the variable is never used. */
2678 ftype = ieee_builtin_type (info, start,
2679 (unsigned int) builtin_void);
2686 if (structfields == NULL)
2688 ieee_error (info, start, "C++ object has no fields");
2692 for (pf = structfields, findx = 0;
2693 *pf != DEBUG_FIELD_NULL;
2698 fname = debug_get_field_name (dhandle, *pf);
2701 if (fname[0] == mangledname[0]
2702 && strncmp (fname, mangledname, mangledlen) == 0
2703 && strlen (fname) == mangledlen)
2706 if (*pf == DEBUG_FIELD_NULL)
2708 ieee_error (info, start,
2709 "C++ data member not found in container");
2713 ftype = debug_get_field_type (dhandle, *pf);
2715 if (debug_get_type_kind (dhandle, ftype) == DEBUG_KIND_POINTER)
2717 /* We might need to convert this field into a
2718 reference type later on, so make it an indirect
2720 if (it->fslots == NULL)
2723 const debug_field *pfcnt;
2726 for (pfcnt = structfields;
2727 *pfcnt != DEBUG_FIELD_NULL;
2730 it->fslots = ((debug_type *)
2731 xmalloc (fcnt * sizeof *it->fslots));
2732 memset (it->fslots, 0,
2733 fcnt * sizeof *it->fslots);
2736 if (ftype == DEBUG_TYPE_NULL)
2738 it->fslots[findx] = ftype;
2739 ftype = debug_make_indirect_type (dhandle,
2741 (const char *) NULL);
2744 if (ftype == DEBUG_TYPE_NULL)
2747 switch (flags & CXXFLAGS_VISIBILITY)
2750 ieee_error (info, start, "unknown C++ visibility");
2753 case CXXFLAGS_VISIBILITY_PUBLIC:
2754 visibility = DEBUG_VISIBILITY_PUBLIC;
2757 case CXXFLAGS_VISIBILITY_PRIVATE:
2758 visibility = DEBUG_VISIBILITY_PRIVATE;
2761 case CXXFLAGS_VISIBILITY_PROTECTED:
2762 visibility = DEBUG_VISIBILITY_PROTECTED;
2770 mangledcopy = savestring (mangledname, mangledlen);
2772 field = debug_make_static_member (dhandle, fieldcopy,
2778 bfd_vma bitpos, bitsize;
2780 bitpos = debug_get_field_bitpos (dhandle, *pf);
2781 bitsize = debug_get_field_bitsize (dhandle, *pf);
2782 if (bitpos == (bfd_vma) -1 || bitsize == (bfd_vma) -1)
2784 ieee_error (info, start, "bad C++ field bit pos or size");
2787 field = debug_make_field (dhandle, fieldcopy, ftype, bitpos,
2788 bitsize, visibility);
2791 if (field == DEBUG_FIELD_NULL)
2794 if (field_count + 1 >= field_alloc)
2797 fields = ((debug_field *)
2798 xrealloc (fields, field_alloc * sizeof *fields));
2801 fields[field_count] = field;
2803 fields[field_count] = DEBUG_FIELD_NULL;
2810 bfd_vma flags, voffset, control;
2811 const char *name, *mangled;
2812 unsigned long namlen, mangledlen;
2813 struct ieee_var *pv, *pvend;
2815 enum debug_visibility visibility;
2816 boolean constp, volatilep;
2818 debug_method_variant mv;
2819 struct ieee_method *meth;
2822 if (! ieee_require_asn (info, pp, &flags)
2823 || ! ieee_require_atn65 (info, pp, &name, &namlen)
2824 || ! ieee_require_atn65 (info, pp, &mangled, &mangledlen))
2831 if (! ieee_require_asn (info, pp, &voffset))
2835 if (! ieee_require_asn (info, pp, &control))
2839 /* We just ignore the control information. */
2841 /* We have no way to represent friend information, so we
2843 if ((flags & CXXFLAGS_FRIEND) != 0)
2846 /* We should already have seen a type for the function. */
2847 pv = info->vars.vars;
2848 pvend = pv + info->vars.alloc;
2849 for (; pv < pvend; pv++)
2850 if (pv->namlen == mangledlen
2851 && strncmp (pv->name, mangled, mangledlen) == 0)
2856 /* We won't have type information for this function if
2857 it is not included in this file. We don't try to
2858 handle this case. FIXME. */
2859 type = (debug_make_function_type
2861 ieee_builtin_type (info, start,
2862 (unsigned int) builtin_void),
2863 (debug_type *) NULL,
2868 debug_type return_type;
2869 const debug_type *arg_types;
2872 if (debug_get_type_kind (dhandle, pv->type)
2873 != DEBUG_KIND_FUNCTION)
2875 ieee_error (info, start,
2876 "bad type for C++ method function");
2880 return_type = debug_get_return_type (dhandle, pv->type);
2881 arg_types = debug_get_parameter_types (dhandle, pv->type,
2883 if (return_type == DEBUG_TYPE_NULL || arg_types == NULL)
2885 ieee_error (info, start,
2886 "no type information for C++ method function");
2890 type = debug_make_method_type (dhandle, return_type, it->type,
2891 (debug_type *) arg_types,
2894 if (type == DEBUG_TYPE_NULL)
2897 switch (flags & CXXFLAGS_VISIBILITY)
2900 ieee_error (info, start, "unknown C++ visibility");
2903 case CXXFLAGS_VISIBILITY_PUBLIC:
2904 visibility = DEBUG_VISIBILITY_PUBLIC;
2907 case CXXFLAGS_VISIBILITY_PRIVATE:
2908 visibility = DEBUG_VISIBILITY_PRIVATE;
2911 case CXXFLAGS_VISIBILITY_PROTECTED:
2912 visibility = DEBUG_VISIBILITY_PROTECTED;
2916 constp = (flags & CXXFLAGS_CONST) != 0 ? true : false;
2917 volatilep = (flags & CXXFLAGS_VOLATILE) != 0 ? true : false;
2919 mangledcopy = savestring (mangled, mangledlen);
2921 if ((flags & CXXFLAGS_STATIC) != 0)
2925 ieee_error (info, start, "C++ static virtual method");
2928 mv = debug_make_static_method_variant (dhandle, mangledcopy,
2934 debug_type vcontext;
2937 vcontext = DEBUG_TYPE_NULL;
2940 /* FIXME: How can we calculate this correctly? */
2941 vcontext = it->type;
2943 mv = debug_make_method_variant (dhandle, mangledcopy, type,
2948 if (mv == DEBUG_METHOD_VARIANT_NULL)
2951 for (meth = methods, im = 0; im < methods_count; meth++, im++)
2952 if (meth->namlen == namlen
2953 && strncmp (meth->name, name, namlen) == 0)
2955 if (im >= methods_count)
2957 if (methods_count >= methods_alloc)
2959 methods_alloc += 10;
2960 methods = ((struct ieee_method *)
2962 methods_alloc * sizeof *methods));
2964 methods[methods_count].name = name;
2965 methods[methods_count].namlen = namlen;
2966 methods[methods_count].variants = NULL;
2967 methods[methods_count].count = 0;
2968 methods[methods_count].alloc = 0;
2969 meth = methods + methods_count;
2973 if (meth->count + 1 >= meth->alloc)
2976 meth->variants = ((debug_method_variant *)
2977 xrealloc (meth->variants,
2979 * sizeof *meth->variants)));
2982 meth->variants[meth->count] = mv;
2984 meth->variants[meth->count] = DEBUG_METHOD_VARIANT_NULL;
2992 /* We have no way to store this information, so we just
2994 if (! ieee_require_asn (info, pp, &spec))
2997 if ((spec & 4) != 0)
2999 const char *filename;
3000 unsigned long filenamlen;
3003 if (! ieee_require_atn65 (info, pp, &filename, &filenamlen)
3004 || ! ieee_require_asn (info, pp, &lineno))
3008 else if ((spec & 8) != 0)
3010 const char *mangled;
3011 unsigned long mangledlen;
3013 if (! ieee_require_atn65 (info, pp, &mangled, &mangledlen))
3019 ieee_error (info, start,
3020 "unrecognized C++ object overhead spec");
3028 const char *vname, *basename;
3029 unsigned long vnamelen, baselen;
3030 bfd_vma vsize, control;
3032 /* A virtual table pointer. */
3034 if (! ieee_require_atn65 (info, pp, &vname, &vnamelen)
3035 || ! ieee_require_asn (info, pp, &vsize)
3036 || ! ieee_require_atn65 (info, pp, &basename, &baselen)
3037 || ! ieee_require_asn (info, pp, &control))
3041 /* We just ignore the control number. We don't care what
3042 the virtual table name is. We have no way to store the
3043 virtual table size, and I don't think we care anyhow. */
3045 /* FIXME: We can't handle multiple virtual table pointers. */
3053 basecopy = savestring (basename, baselen);
3054 vptrbase = debug_find_tagged_type (dhandle, basecopy,
3055 DEBUG_KIND_ILLEGAL);
3057 if (vptrbase == DEBUG_TYPE_NULL)
3059 ieee_error (info, start, "undefined C++ vtable");
3068 /* Now that we have seen all the method variants, we can call
3069 debug_make_method for each one. */
3071 if (methods_count == 0)
3077 dmethods = ((debug_method *)
3078 xmalloc ((methods_count + 1) * sizeof *dmethods));
3079 for (i = 0; i < methods_count; i++)
3083 namcopy = savestring (methods[i].name, methods[i].namlen);
3084 dmethods[i] = debug_make_method (dhandle, namcopy,
3085 methods[i].variants);
3086 if (dmethods[i] == DEBUG_METHOD_NULL)
3089 dmethods[i] = DEBUG_METHOD_NULL;
3093 /* The struct type was created as an indirect type pointing at
3094 it->slot. We update it->slot to automatically update all
3095 references to this struct. */
3096 it->slot = debug_make_object_type (dhandle,
3098 debug_get_type_size (dhandle,
3100 fields, baseclasses, dmethods,
3102 if (it->slot == DEBUG_TYPE_NULL)
3108 /* Read C++ default argument value and reference type information. */
3111 ieee_read_cxx_defaults (info, pp, count)
3112 struct ieee_info *info;
3113 const bfd_byte **pp;
3114 unsigned long count;
3116 const bfd_byte *start;
3118 unsigned long fnlen;
3123 /* Giving the function name before the argument count is an addendum
3124 to the spec. The function name is demangled, though, so this
3125 record must always refer to the current function. */
3127 if (info->blockstack.bsp <= info->blockstack.stack
3128 || info->blockstack.bsp[-1].fnindx == (unsigned int) -1)
3130 ieee_error (info, start, "C++ default values not in a function");
3134 if (! ieee_require_atn65 (info, pp, &fnname, &fnlen)
3135 || ! ieee_require_asn (info, pp, &defcount))
3139 while (defcount-- > 0)
3143 unsigned long strvallen;
3145 if (! ieee_require_asn (info, pp, &type))
3157 if (! ieee_require_asn (info, pp, &val))
3164 if (! ieee_require_atn65 (info, pp, &strval, &strvallen))
3170 ieee_error (info, start, "unrecognized C++ default type");
3174 /* We have no way to record the default argument values, so we
3175 just ignore them. FIXME. */
3178 /* Any remaining arguments are indices of parameters that are really
3183 debug_type *arg_slots;
3185 dhandle = info->dhandle;
3186 arg_slots = info->types.types[info->blockstack.bsp[-1].fnindx].arg_slots;
3192 if (! ieee_require_asn (info, pp, &indx))
3194 /* The index is 1 based. */
3196 if (arg_slots == NULL
3197 || arg_slots[indx] == DEBUG_TYPE_NULL
3198 || (debug_get_type_kind (dhandle, arg_slots[indx])
3199 != DEBUG_KIND_POINTER))
3201 ieee_error (info, start, "reference parameter is not a pointer");
3205 target = debug_get_target_type (dhandle, arg_slots[indx]);
3206 arg_slots[indx] = debug_make_reference_type (dhandle, target);
3207 if (arg_slots[indx] == DEBUG_TYPE_NULL)
3215 /* Read a C++ reference definition. */
3218 ieee_read_reference (info, pp)
3219 struct ieee_info *info;
3220 const bfd_byte **pp;
3222 const bfd_byte *start;
3224 const char *class, *name;
3225 unsigned long classlen, namlen;
3231 if (! ieee_require_asn (info, pp, &flags))
3234 /* Giving the class name before the member name is in an addendum to
3238 if (! ieee_require_atn65 (info, pp, &class, &classlen))
3242 if (! ieee_require_atn65 (info, pp, &name, &namlen))
3249 struct ieee_var *pv = NULL;
3251 /* We search from the last variable indices to the first in
3252 hopes of finding local variables correctly. FIXME: This
3253 probably won't work in all cases. On the other hand, I don't
3255 for (i = (int) info->vars.alloc - 1; i >= 0; i--)
3259 pv = info->vars.vars + i;
3261 if (pv->pslot == NULL
3262 || pv->namlen != namlen
3263 || strncmp (pv->name, name, namlen) != 0)
3270 ieee_error (info, start,
3271 "unrecognized C++ reference type");
3275 /* Global variable or function. */
3276 if (pv->kind == IEEE_GLOBAL
3277 || pv->kind == IEEE_EXTERNAL
3278 || pv->kind == IEEE_FUNCTION)
3283 /* Global static variable or function. */
3284 if (pv->kind == IEEE_STATIC
3285 || pv->kind == IEEE_FUNCTION)
3290 /* Local variable. */
3291 if (pv->kind == IEEE_LOCAL)
3305 struct ieee_tag *it;
3307 for (it = info->tags; it != NULL; it = it->next)
3309 if (it->name[0] == class[0]
3310 && strncmp (it->name, class, classlen) == 0
3311 && strlen (it->name) == classlen)
3313 if (it->fslots != NULL)
3315 const debug_field *pf;
3318 pf = debug_get_fields (info->dhandle, it->type);
3321 ieee_error (info, start,
3322 "C++ reference in class with no fields");
3326 for (findx = 0; *pf != DEBUG_FIELD_NULL; pf++, findx++)
3330 fname = debug_get_field_name (info->dhandle, *pf);
3333 if (strncmp (fname, name, namlen) == 0
3334 && strlen (fname) == namlen)
3336 pslot = it->fslots + findx;
3349 ieee_error (info, start, "C++ reference not found");
3353 /* We allocated the type of the object as an indirect type pointing
3354 to *pslot, which we can now update to be a reference type. */
3355 if (debug_get_type_kind (info->dhandle, *pslot) != DEBUG_KIND_POINTER)
3357 ieee_error (info, start, "C++ reference is not pointer");
3361 target = debug_get_target_type (info->dhandle, *pslot);
3362 *pslot = debug_make_reference_type (info->dhandle, target);
3363 if (*pslot == DEBUG_TYPE_NULL)
3369 /* Require an ASN record. */
3372 ieee_require_asn (info, pp, pv)
3373 struct ieee_info *info;
3374 const bfd_byte **pp;
3377 const bfd_byte *start;
3378 ieee_record_enum_type c;
3383 c = (ieee_record_enum_type) **pp;
3384 if (c != ieee_e2_first_byte_enum)
3386 ieee_error (info, start, "missing required ASN");
3391 c = (ieee_record_enum_type) (((unsigned int) c << 8) | **pp);
3392 if (c != ieee_asn_record_enum)
3394 ieee_error (info, start, "missing required ASN");
3399 /* Just ignore the variable index. */
3400 if (! ieee_read_number (info, pp, &varindx))
3403 return ieee_read_expression (info, pp, pv);
3406 /* Require an ATN65 record. */
3409 ieee_require_atn65 (info, pp, pname, pnamlen)
3410 struct ieee_info *info;
3411 const bfd_byte **pp;
3413 unsigned long *pnamlen;
3415 const bfd_byte *start;
3416 ieee_record_enum_type c;
3417 bfd_vma name_indx, type_indx, atn_code;
3421 c = (ieee_record_enum_type) **pp;
3422 if (c != ieee_at_record_enum)
3424 ieee_error (info, start, "missing required ATN65");
3429 c = (ieee_record_enum_type) (((unsigned int) c << 8) | **pp);
3430 if (c != ieee_atn_record_enum)
3432 ieee_error (info, start, "missing required ATN65");
3437 if (! ieee_read_number (info, pp, &name_indx)
3438 || ! ieee_read_number (info, pp, &type_indx)
3439 || ! ieee_read_number (info, pp, &atn_code))
3442 /* Just ignore name_indx. */
3444 if (type_indx != 0 || atn_code != 65)
3446 ieee_error (info, start, "bad ATN65 record");
3450 return ieee_read_id (info, pp, pname, pnamlen);
3453 /* Convert a register number in IEEE debugging information into a
3454 generic register number. */
3457 ieee_regno_to_genreg (abfd, r)
3461 switch (bfd_get_arch (abfd))
3464 /* For some reasons stabs adds 2 to the floating point register
3471 /* Stabs uses 0 to 15 for r0 to r15, 16 to 31 for g0 to g15, and
3472 32 to 35 for fp0 to fp3. */
3483 /* Convert a generic register number to an IEEE specific one. */
3486 ieee_genreg_to_regno (abfd, r)
3490 switch (bfd_get_arch (abfd))
3493 /* For some reason stabs add 2 to the floating point register
3500 /* Stabs uses 0 to 15 for r0 to r15, 16 to 31 for g0 to g15, and
3501 32 to 35 for fp0 to fp3. */
3512 /* These routines build IEEE debugging information out of the generic
3513 debugging information. */
3515 /* We build the IEEE debugging information byte by byte. Rather than
3516 waste time copying data around, we use a linked list of buffers to
3519 #define IEEE_BUFSIZE (490)
3524 struct ieee_buf *next;
3525 /* Number of data bytes in this buffer. */
3528 bfd_byte buf[IEEE_BUFSIZE];
3531 /* A list of buffers. */
3536 struct ieee_buf *head;
3537 /* Tail--last buffer on list. */
3538 struct ieee_buf *tail;
3541 /* In order to generate the BB11 blocks required by the HP emulator,
3542 we keep track of ranges of addresses which correspond to a given
3543 compilation unit. */
3548 struct ieee_range *next;
3555 /* This structure holds information for a class on the type stack. */
3557 struct ieee_type_class
3559 /* The name index in the debugging information. */
3561 /* The pmisc records for the class. */
3562 struct ieee_buflist pmiscbuf;
3563 /* The number of pmisc records. */
3564 unsigned int pmisccount;
3565 /* The name of the class holding the virtual table, if not this
3568 /* Whether this class holds its own virtual table. */
3570 /* The largest virtual table offset seen so far. */
3572 /* The current method. */
3574 /* Additional pmisc records used to record fields of reference type. */
3575 struct ieee_buflist refs;
3578 /* This is how we store types for the writing routines. Most types
3579 are simply represented by a type index. */
3581 struct ieee_write_type
3585 /* The size of the type, if known. */
3587 /* The name of the type, if any. */
3589 /* If this is a function or method type, we build the type here, and
3590 only add it to the output buffers if we need it. */
3591 struct ieee_buflist fndef;
3592 /* If this is a struct, this is where the struct definition is
3594 struct ieee_buflist strdef;
3595 /* If this is a class, this is where the class information is built. */
3596 struct ieee_type_class *classdef;
3597 /* Whether the type is unsigned. */
3598 unsigned int unsignedp : 1;
3599 /* Whether this is a reference type. */
3600 unsigned int referencep : 1;
3601 /* Whether this is in the local type block. */
3602 unsigned int localp : 1;
3603 /* Whether this is a duplicate struct definition which we are
3605 unsigned int ignorep : 1;
3608 /* This is the type stack used by the debug writing routines. FIXME:
3609 We could generate more efficient output if we remembered when we
3610 have output a particular type before. */
3612 struct ieee_type_stack
3614 /* Next entry on stack. */
3615 struct ieee_type_stack *next;
3616 /* Type information. */
3617 struct ieee_write_type type;
3620 /* This is a list of associations between a name and some types.
3621 These are used for typedefs and tags. */
3623 struct ieee_name_type
3625 /* Next type for this name. */
3626 struct ieee_name_type *next;
3627 /* ID number. For a typedef, this is the index of the type to which
3628 this name is typedefed. */
3631 struct ieee_write_type type;
3632 /* If this is a tag which has not yet been defined, this is the
3633 kind. If the tag has been defined, this is DEBUG_KIND_ILLEGAL. */
3634 enum debug_type_kind kind;
3637 /* We use a hash table to associate names and types. */
3639 struct ieee_name_type_hash_table
3641 struct bfd_hash_table root;
3644 struct ieee_name_type_hash_entry
3646 struct bfd_hash_entry root;
3647 /* Information for this name. */
3648 struct ieee_name_type *types;
3651 /* This is a list of enums. */
3653 struct ieee_defined_enum
3656 struct ieee_defined_enum *next;
3664 bfd_signed_vma *vals;
3667 /* We keep a list of modified versions of types, so that we don't
3668 output them more than once. */
3670 struct ieee_modified_type
3672 /* Pointer to this type. */
3673 unsigned int pointer;
3674 /* Function with unknown arguments returning this type. */
3675 unsigned int function;
3676 /* Const version of this type. */
3677 unsigned int const_qualified;
3678 /* Volatile version of this type. */
3679 unsigned int volatile_qualified;
3680 /* List of arrays of this type of various bounds. */
3681 struct ieee_modified_array_type *arrays;
3684 /* A list of arrays bounds. */
3686 struct ieee_modified_array_type
3688 /* Next array bounds. */
3689 struct ieee_modified_array_type *next;
3690 /* Type index with these bounds. */
3695 bfd_signed_vma high;
3698 /* This is a list of pending function parameter information. We don't
3699 output them until we see the first block. */
3701 struct ieee_pending_parm
3703 /* Next pending parameter. */
3704 struct ieee_pending_parm *next;
3709 /* Whether the type is a reference. */
3712 enum debug_parm_kind kind;
3717 /* This is the handle passed down by debug_write. */
3721 /* BFD we are writing to. */
3723 /* Whether we got an error in a subroutine called via traverse or
3724 map_over_sections. */
3726 /* Current data buffer list. */
3727 struct ieee_buflist *current;
3728 /* Current data buffer. */
3729 struct ieee_buf *curbuf;
3730 /* Filename of current compilation unit. */
3731 const char *filename;
3732 /* Module name of current compilation unit. */
3733 const char *modname;
3734 /* List of buffer for global types. */
3735 struct ieee_buflist global_types;
3736 /* List of finished data buffers. */
3737 struct ieee_buflist data;
3738 /* List of buffers for typedefs in the current compilation unit. */
3739 struct ieee_buflist types;
3740 /* List of buffers for variables and functions in the current
3741 compilation unit. */
3742 struct ieee_buflist vars;
3743 /* List of buffers for C++ class definitions in the current
3744 compilation unit. */
3745 struct ieee_buflist cxx;
3746 /* List of buffers for line numbers in the current compilation unit. */
3747 struct ieee_buflist linenos;
3748 /* Ranges for the current compilation unit. */
3749 struct ieee_range *ranges;
3750 /* Ranges for all debugging information. */
3751 struct ieee_range *global_ranges;
3752 /* Nested pending ranges. */
3753 struct ieee_range *pending_ranges;
3755 struct ieee_type_stack *type_stack;
3756 /* Next unallocated type index. */
3757 unsigned int type_indx;
3758 /* Next unallocated name index. */
3759 unsigned int name_indx;
3761 struct ieee_name_type_hash_table typedefs;
3763 struct ieee_name_type_hash_table tags;
3765 struct ieee_defined_enum *enums;
3766 /* Modified versions of types. */
3767 struct ieee_modified_type *modified;
3768 /* Number of entries allocated in modified. */
3769 unsigned int modified_alloc;
3770 /* 4 byte complex type. */
3771 unsigned int complex_float_index;
3772 /* 8 byte complex type. */
3773 unsigned int complex_double_index;
3774 /* The depth of block nesting. This is 0 outside a function, and 1
3775 just after start_function is called. */
3776 unsigned int block_depth;
3777 /* The name of the current function. */
3779 /* List of buffers for the type of the function we are currently
3781 struct ieee_buflist fntype;
3782 /* List of buffers for the parameters of the function we are
3783 currently writing out. */
3784 struct ieee_buflist fnargs;
3785 /* Number of arguments written to fnargs. */
3786 unsigned int fnargcount;
3787 /* Pending function parameters. */
3788 struct ieee_pending_parm *pending_parms;
3789 /* Current line number filename. */
3790 const char *lineno_filename;
3791 /* Line number name index. */
3792 unsigned int lineno_name_indx;
3793 /* Filename of pending line number. */
3794 const char *pending_lineno_filename;
3795 /* Pending line number. */
3796 unsigned long pending_lineno;
3797 /* Address of pending line number. */
3798 bfd_vma pending_lineno_addr;
3799 /* Highest address seen at end of procedure. */
3803 static boolean ieee_init_buffer
3804 PARAMS ((struct ieee_handle *, struct ieee_buflist *));
3805 static boolean ieee_change_buffer
3806 PARAMS ((struct ieee_handle *, struct ieee_buflist *));
3807 static boolean ieee_append_buffer
3808 PARAMS ((struct ieee_handle *, struct ieee_buflist *,
3809 struct ieee_buflist *));
3810 static boolean ieee_real_write_byte PARAMS ((struct ieee_handle *, int));
3811 static boolean ieee_write_2bytes PARAMS ((struct ieee_handle *, int));
3812 static boolean ieee_write_number PARAMS ((struct ieee_handle *, bfd_vma));
3813 static boolean ieee_write_id PARAMS ((struct ieee_handle *, const char *));
3814 static boolean ieee_write_asn
3815 PARAMS ((struct ieee_handle *, unsigned int, bfd_vma));
3816 static boolean ieee_write_atn65
3817 PARAMS ((struct ieee_handle *, unsigned int, const char *));
3818 static boolean ieee_push_type
3819 PARAMS ((struct ieee_handle *, unsigned int, unsigned int, boolean,
3821 static unsigned int ieee_pop_type PARAMS ((struct ieee_handle *));
3822 static void ieee_pop_unused_type PARAMS ((struct ieee_handle *));
3823 static unsigned int ieee_pop_type_used
3824 PARAMS ((struct ieee_handle *, boolean));
3825 static boolean ieee_add_range
3826 PARAMS ((struct ieee_handle *, boolean, bfd_vma, bfd_vma));
3827 static boolean ieee_start_range PARAMS ((struct ieee_handle *, bfd_vma));
3828 static boolean ieee_end_range PARAMS ((struct ieee_handle *, bfd_vma));
3829 static boolean ieee_define_type
3830 PARAMS ((struct ieee_handle *, unsigned int, boolean, boolean));
3831 static boolean ieee_define_named_type
3832 PARAMS ((struct ieee_handle *, const char *, unsigned int, unsigned int,
3833 boolean, boolean, struct ieee_buflist *));
3834 static struct ieee_modified_type *ieee_get_modified_info
3835 PARAMS ((struct ieee_handle *, unsigned int));
3836 static struct bfd_hash_entry *ieee_name_type_newfunc
3837 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
3838 static boolean ieee_write_undefined_tag
3839 PARAMS ((struct ieee_name_type_hash_entry *, PTR));
3840 static boolean ieee_finish_compilation_unit PARAMS ((struct ieee_handle *));
3841 static void ieee_add_bb11_blocks PARAMS ((bfd *, asection *, PTR));
3842 static boolean ieee_add_bb11
3843 PARAMS ((struct ieee_handle *, asection *, bfd_vma, bfd_vma));
3844 static boolean ieee_output_pending_parms PARAMS ((struct ieee_handle *));
3845 static unsigned int ieee_vis_to_flags PARAMS ((enum debug_visibility));
3846 static boolean ieee_class_method_var
3847 PARAMS ((struct ieee_handle *, const char *, enum debug_visibility, boolean,
3848 boolean, boolean, bfd_vma, boolean));
3850 static boolean ieee_start_compilation_unit PARAMS ((PTR, const char *));
3851 static boolean ieee_start_source PARAMS ((PTR, const char *));
3852 static boolean ieee_empty_type PARAMS ((PTR));
3853 static boolean ieee_void_type PARAMS ((PTR));
3854 static boolean ieee_int_type PARAMS ((PTR, unsigned int, boolean));
3855 static boolean ieee_float_type PARAMS ((PTR, unsigned int));
3856 static boolean ieee_complex_type PARAMS ((PTR, unsigned int));
3857 static boolean ieee_bool_type PARAMS ((PTR, unsigned int));
3858 static boolean ieee_enum_type
3859 PARAMS ((PTR, const char *, const char **, bfd_signed_vma *));
3860 static boolean ieee_pointer_type PARAMS ((PTR));
3861 static boolean ieee_function_type PARAMS ((PTR, int, boolean));
3862 static boolean ieee_reference_type PARAMS ((PTR));
3863 static boolean ieee_range_type PARAMS ((PTR, bfd_signed_vma, bfd_signed_vma));
3864 static boolean ieee_array_type
3865 PARAMS ((PTR, bfd_signed_vma, bfd_signed_vma, boolean));
3866 static boolean ieee_set_type PARAMS ((PTR, boolean));
3867 static boolean ieee_offset_type PARAMS ((PTR));
3868 static boolean ieee_method_type PARAMS ((PTR, boolean, int, boolean));
3869 static boolean ieee_const_type PARAMS ((PTR));
3870 static boolean ieee_volatile_type PARAMS ((PTR));
3871 static boolean ieee_start_struct_type
3872 PARAMS ((PTR, const char *, unsigned int, boolean, unsigned int));
3873 static boolean ieee_struct_field
3874 PARAMS ((PTR, const char *, bfd_vma, bfd_vma, enum debug_visibility));
3875 static boolean ieee_end_struct_type PARAMS ((PTR));
3876 static boolean ieee_start_class_type
3877 PARAMS ((PTR, const char *, unsigned int, boolean, unsigned int, boolean,
3879 static boolean ieee_class_static_member
3880 PARAMS ((PTR, const char *, const char *, enum debug_visibility));
3881 static boolean ieee_class_baseclass
3882 PARAMS ((PTR, bfd_vma, boolean, enum debug_visibility));
3883 static boolean ieee_class_start_method PARAMS ((PTR, const char *));
3884 static boolean ieee_class_method_variant
3885 PARAMS ((PTR, const char *, enum debug_visibility, boolean, boolean,
3887 static boolean ieee_class_static_method_variant
3888 PARAMS ((PTR, const char *, enum debug_visibility, boolean, boolean));
3889 static boolean ieee_class_end_method PARAMS ((PTR));
3890 static boolean ieee_end_class_type PARAMS ((PTR));
3891 static boolean ieee_typedef_type PARAMS ((PTR, const char *));
3892 static boolean ieee_tag_type
3893 PARAMS ((PTR, const char *, unsigned int, enum debug_type_kind));
3894 static boolean ieee_typdef PARAMS ((PTR, const char *));
3895 static boolean ieee_tag PARAMS ((PTR, const char *));
3896 static boolean ieee_int_constant PARAMS ((PTR, const char *, bfd_vma));
3897 static boolean ieee_float_constant PARAMS ((PTR, const char *, double));
3898 static boolean ieee_typed_constant PARAMS ((PTR, const char *, bfd_vma));
3899 static boolean ieee_variable
3900 PARAMS ((PTR, const char *, enum debug_var_kind, bfd_vma));
3901 static boolean ieee_start_function PARAMS ((PTR, const char *, boolean));
3902 static boolean ieee_function_parameter
3903 PARAMS ((PTR, const char *, enum debug_parm_kind, bfd_vma));
3904 static boolean ieee_start_block PARAMS ((PTR, bfd_vma));
3905 static boolean ieee_end_block PARAMS ((PTR, bfd_vma));
3906 static boolean ieee_end_function PARAMS ((PTR));
3907 static boolean ieee_lineno
3908 PARAMS ((PTR, const char *, unsigned long, bfd_vma));
3910 static const struct debug_write_fns ieee_fns =
3912 ieee_start_compilation_unit,
3923 ieee_reference_type,
3931 ieee_start_struct_type,
3933 ieee_end_struct_type,
3934 ieee_start_class_type,
3935 ieee_class_static_member,
3936 ieee_class_baseclass,
3937 ieee_class_start_method,
3938 ieee_class_method_variant,
3939 ieee_class_static_method_variant,
3940 ieee_class_end_method,
3941 ieee_end_class_type,
3947 ieee_float_constant,
3948 ieee_typed_constant,
3950 ieee_start_function,
3951 ieee_function_parameter,
3958 /* Initialize a buffer to be empty. */
3962 ieee_init_buffer (info, buflist)
3963 struct ieee_handle *info;
3964 struct ieee_buflist *buflist;
3966 buflist->head = NULL;
3967 buflist->tail = NULL;
3971 /* See whether a buffer list has any data. */
3973 #define ieee_buffer_emptyp(buflist) ((buflist)->head == NULL)
3975 /* Change the current buffer to a specified buffer chain. */
3978 ieee_change_buffer (info, buflist)
3979 struct ieee_handle *info;
3980 struct ieee_buflist *buflist;
3982 if (buflist->head == NULL)
3984 struct ieee_buf *buf;
3986 buf = (struct ieee_buf *) xmalloc (sizeof *buf);
3989 buflist->head = buf;
3990 buflist->tail = buf;
3993 info->current = buflist;
3994 info->curbuf = buflist->tail;
3999 /* Append a buffer chain. */
4003 ieee_append_buffer (info, mainbuf, newbuf)
4004 struct ieee_handle *info;
4005 struct ieee_buflist *mainbuf;
4006 struct ieee_buflist *newbuf;
4008 if (newbuf->head != NULL)
4010 if (mainbuf->head == NULL)
4011 mainbuf->head = newbuf->head;
4013 mainbuf->tail->next = newbuf->head;
4014 mainbuf->tail = newbuf->tail;
4019 /* Write a byte into the buffer. We use a macro for speed and a
4020 function for the complex cases. */
4022 #define ieee_write_byte(info, b) \
4023 ((info)->curbuf->c < IEEE_BUFSIZE \
4024 ? ((info)->curbuf->buf[(info)->curbuf->c++] = (b), true) \
4025 : ieee_real_write_byte ((info), (b)))
4028 ieee_real_write_byte (info, b)
4029 struct ieee_handle *info;
4032 if (info->curbuf->c >= IEEE_BUFSIZE)
4036 n = (struct ieee_buf *) xmalloc (sizeof *n);
4039 if (info->current->head == NULL)
4040 info->current->head = n;
4042 info->current->tail->next = n;
4043 info->current->tail = n;
4047 info->curbuf->buf[info->curbuf->c] = b;
4053 /* Write out two bytes. */
4056 ieee_write_2bytes (info, i)
4057 struct ieee_handle *info;
4060 return (ieee_write_byte (info, i >> 8)
4061 && ieee_write_byte (info, i & 0xff));
4064 /* Write out an integer. */
4067 ieee_write_number (info, v)
4068 struct ieee_handle *info;
4076 if (v <= (bfd_vma) ieee_number_end_enum)
4077 return ieee_write_byte (info, (int) v);
4088 if (c > (unsigned int) (ieee_number_repeat_end_enum
4089 - ieee_number_repeat_start_enum))
4091 fprintf (stderr, "IEEE numeric overflow: 0x");
4092 fprintf_vma (stderr, v);
4093 fprintf (stderr, "\n");
4097 if (! ieee_write_byte (info, (int) ieee_number_repeat_start_enum + c))
4099 for (; c > 0; --c, ++p)
4101 if (! ieee_write_byte (info, *p))
4108 /* Write out a string. */
4111 ieee_write_id (info, s)
4112 struct ieee_handle *info;
4120 if (! ieee_write_byte (info, len))
4123 else if (len <= 0xff)
4125 if (! ieee_write_byte (info, (int) ieee_extension_length_1_enum)
4126 || ! ieee_write_byte (info, len))
4129 else if (len <= 0xffff)
4131 if (! ieee_write_byte (info, (int) ieee_extension_length_2_enum)
4132 || ! ieee_write_2bytes (info, len))
4137 fprintf (stderr, "IEEE string length overflow: %u\n", len);
4141 for (; *s != '\0'; s++)
4142 if (! ieee_write_byte (info, *s))
4148 /* Write out an ASN record. */
4151 ieee_write_asn (info, indx, val)
4152 struct ieee_handle *info;
4156 return (ieee_write_2bytes (info, (int) ieee_asn_record_enum)
4157 && ieee_write_number (info, indx)
4158 && ieee_write_number (info, val));
4161 /* Write out an ATN65 record. */
4164 ieee_write_atn65 (info, indx, s)
4165 struct ieee_handle *info;
4169 return (ieee_write_2bytes (info, (int) ieee_atn_record_enum)
4170 && ieee_write_number (info, indx)
4171 && ieee_write_number (info, 0)
4172 && ieee_write_number (info, 65)
4173 && ieee_write_id (info, s));
4176 /* Push a type index onto the type stack. */
4179 ieee_push_type (info, indx, size, unsignedp, localp)
4180 struct ieee_handle *info;
4186 struct ieee_type_stack *ts;
4188 ts = (struct ieee_type_stack *) xmalloc (sizeof *ts);
4189 memset (ts, 0, sizeof *ts);
4191 ts->type.indx = indx;
4192 ts->type.size = size;
4193 ts->type.unsignedp = unsignedp;
4194 ts->type.localp = localp;
4196 ts->next = info->type_stack;
4197 info->type_stack = ts;
4202 /* Pop a type index off the type stack. */
4205 ieee_pop_type (info)
4206 struct ieee_handle *info;
4208 return ieee_pop_type_used (info, true);
4211 /* Pop an unused type index off the type stack. */
4214 ieee_pop_unused_type (info)
4215 struct ieee_handle *info;
4217 (void) ieee_pop_type_used (info, false);
4220 /* Pop a used or unused type index off the type stack. */
4223 ieee_pop_type_used (info, used)
4224 struct ieee_handle *info;
4227 struct ieee_type_stack *ts;
4230 ts = info->type_stack;
4231 assert (ts != NULL);
4233 /* If this is a function type, and we need it, we need to append the
4234 actual definition to the typedef block now. */
4235 if (used && ! ieee_buffer_emptyp (&ts->type.fndef))
4237 struct ieee_buflist *buflist;
4239 if (ts->type.localp)
4241 /* Make sure we have started the types block. */
4242 if (ieee_buffer_emptyp (&info->types))
4244 if (! ieee_change_buffer (info, &info->types)
4245 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
4246 || ! ieee_write_byte (info, 1)
4247 || ! ieee_write_number (info, 0)
4248 || ! ieee_write_id (info, info->modname))
4251 buflist = &info->types;
4255 /* Make sure we started the global type block. */
4256 if (ieee_buffer_emptyp (&info->global_types))
4258 if (! ieee_change_buffer (info, &info->global_types)
4259 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
4260 || ! ieee_write_byte (info, 2)
4261 || ! ieee_write_number (info, 0)
4262 || ! ieee_write_id (info, ""))
4265 buflist = &info->global_types;
4268 if (! ieee_append_buffer (info, buflist, &ts->type.fndef))
4272 ret = ts->type.indx;
4273 info->type_stack = ts->next;
4278 /* Add a range of bytes included in the current compilation unit. */
4281 ieee_add_range (info, global, low, high)
4282 struct ieee_handle *info;
4287 struct ieee_range **plist, *r, **pr;
4289 if (low == (bfd_vma) -1 || high == (bfd_vma) -1 || low == high)
4293 plist = &info->global_ranges;
4295 plist = &info->ranges;
4297 for (r = *plist; r != NULL; r = r->next)
4299 if (high >= r->low && low <= r->high)
4301 /* The new range overlaps r. */
4307 while (*pr != NULL && (*pr)->low <= r->high)
4309 struct ieee_range *n;
4311 if ((*pr)->high > r->high)
4312 r->high = (*pr)->high;
4321 r = (struct ieee_range *) xmalloc (sizeof *r);
4322 memset (r, 0, sizeof *r);
4327 /* Store the ranges sorted by address. */
4328 for (pr = plist; *pr != NULL; pr = &(*pr)->next)
4329 if ((*pr)->low > high)
4337 /* Start a new range for which we only have the low address. */
4340 ieee_start_range (info, low)
4341 struct ieee_handle *info;
4344 struct ieee_range *r;
4346 r = (struct ieee_range *) xmalloc (sizeof *r);
4347 memset (r, 0, sizeof *r);
4349 r->next = info->pending_ranges;
4350 info->pending_ranges = r;
4354 /* Finish a range started by ieee_start_range. */
4357 ieee_end_range (info, high)
4358 struct ieee_handle *info;
4361 struct ieee_range *r;
4364 assert (info->pending_ranges != NULL);
4365 r = info->pending_ranges;
4367 info->pending_ranges = r->next;
4369 return ieee_add_range (info, false, low, high);
4372 /* Start defining a type. */
4375 ieee_define_type (info, size, unsignedp, localp)
4376 struct ieee_handle *info;
4381 return ieee_define_named_type (info, (const char *) NULL,
4382 (unsigned int) -1, size, unsignedp,
4383 localp, (struct ieee_buflist *) NULL);
4386 /* Start defining a named type. */
4389 ieee_define_named_type (info, name, indx, size, unsignedp, localp, buflist)
4390 struct ieee_handle *info;
4396 struct ieee_buflist *buflist;
4398 unsigned int type_indx;
4399 unsigned int name_indx;
4401 if (indx != (unsigned int) -1)
4405 type_indx = info->type_indx;
4409 name_indx = info->name_indx;
4415 /* If we were given a buffer, use it; otherwise, use either the
4416 local or the global type information, and make sure that the type
4417 block is started. */
4418 if (buflist != NULL)
4420 if (! ieee_change_buffer (info, buflist))
4425 if (! ieee_buffer_emptyp (&info->types))
4427 if (! ieee_change_buffer (info, &info->types))
4432 if (! ieee_change_buffer (info, &info->types)
4433 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
4434 || ! ieee_write_byte (info, 1)
4435 || ! ieee_write_number (info, 0)
4436 || ! ieee_write_id (info, info->modname))
4442 if (! ieee_buffer_emptyp (&info->global_types))
4444 if (! ieee_change_buffer (info, &info->global_types))
4449 if (! ieee_change_buffer (info, &info->global_types)
4450 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
4451 || ! ieee_write_byte (info, 2)
4452 || ! ieee_write_number (info, 0)
4453 || ! ieee_write_id (info, ""))
4458 /* Push the new type on the type stack, write out an NN record, and
4459 write out the start of a TY record. The caller will then finish
4461 if (! ieee_push_type (info, type_indx, size, unsignedp, localp))
4464 return (ieee_write_byte (info, (int) ieee_nn_record)
4465 && ieee_write_number (info, name_indx)
4466 && ieee_write_id (info, name)
4467 && ieee_write_byte (info, (int) ieee_ty_record_enum)
4468 && ieee_write_number (info, type_indx)
4469 && ieee_write_byte (info, 0xce)
4470 && ieee_write_number (info, name_indx));
4473 /* Get an entry to the list of modified versions of a type. */
4475 static struct ieee_modified_type *
4476 ieee_get_modified_info (info, indx)
4477 struct ieee_handle *info;
4480 if (indx >= info->modified_alloc)
4482 unsigned int nalloc;
4484 nalloc = info->modified_alloc;
4487 while (indx >= nalloc)
4489 info->modified = ((struct ieee_modified_type *)
4490 xrealloc (info->modified,
4491 nalloc * sizeof *info->modified));
4492 memset (info->modified + info->modified_alloc, 0,
4493 (nalloc - info->modified_alloc) * sizeof *info->modified);
4494 info->modified_alloc = nalloc;
4497 return info->modified + indx;
4500 /* Routines for the hash table mapping names to types. */
4502 /* Initialize an entry in the hash table. */
4504 static struct bfd_hash_entry *
4505 ieee_name_type_newfunc (entry, table, string)
4506 struct bfd_hash_entry *entry;
4507 struct bfd_hash_table *table;
4510 struct ieee_name_type_hash_entry *ret =
4511 (struct ieee_name_type_hash_entry *) entry;
4513 /* Allocate the structure if it has not already been allocated by a
4516 ret = ((struct ieee_name_type_hash_entry *)
4517 bfd_hash_allocate (table, sizeof *ret));
4521 /* Call the allocation method of the superclass. */
4522 ret = ((struct ieee_name_type_hash_entry *)
4523 bfd_hash_newfunc ((struct bfd_hash_entry *) ret, table, string));
4526 /* Set local fields. */
4530 return (struct bfd_hash_entry *) ret;
4533 /* Look up an entry in the hash table. */
4535 #define ieee_name_type_hash_lookup(table, string, create, copy) \
4536 ((struct ieee_name_type_hash_entry *) \
4537 bfd_hash_lookup (&(table)->root, (string), (create), (copy)))
4539 /* Traverse the hash table. */
4541 #define ieee_name_type_hash_traverse(table, func, info) \
4542 (bfd_hash_traverse \
4544 (boolean (*) PARAMS ((struct bfd_hash_entry *, PTR))) (func), \
4547 /* The general routine to write out IEEE debugging information. */
4550 write_ieee_debugging_info (abfd, dhandle)
4554 struct ieee_handle info;
4559 memset (&info, 0, sizeof info);
4561 info.type_indx = 256;
4562 info.name_indx = 32;
4564 if (! bfd_hash_table_init (&info.typedefs.root, ieee_name_type_newfunc)
4565 || ! bfd_hash_table_init (&info.tags.root, ieee_name_type_newfunc))
4568 if (! ieee_init_buffer (&info, &info.global_types)
4569 || ! ieee_init_buffer (&info, &info.data)
4570 || ! ieee_init_buffer (&info, &info.types)
4571 || ! ieee_init_buffer (&info, &info.vars)
4572 || ! ieee_init_buffer (&info, &info.cxx)
4573 || ! ieee_init_buffer (&info, &info.linenos)
4574 || ! ieee_init_buffer (&info, &info.fntype)
4575 || ! ieee_init_buffer (&info, &info.fnargs))
4578 if (! debug_write (dhandle, &ieee_fns, (PTR) &info))
4581 if (info.filename != NULL)
4583 if (! ieee_finish_compilation_unit (&info))
4587 /* Put any undefined tags in the global typedef information. */
4589 ieee_name_type_hash_traverse (&info.tags,
4590 ieee_write_undefined_tag,
4595 /* Prepend the global typedef information to the other data. */
4596 if (! ieee_buffer_emptyp (&info.global_types))
4598 if (! ieee_change_buffer (&info, &info.global_types)
4599 || ! ieee_write_byte (&info, (int) ieee_be_record_enum))
4602 if (! ieee_append_buffer (&info, &info.global_types, &info.data))
4604 info.data = info.global_types;
4607 /* Make sure that we have declare BB11 blocks for each range in the
4608 file. They are added to info->vars. */
4610 if (! ieee_init_buffer (&info, &info.vars))
4612 bfd_map_over_sections (abfd, ieee_add_bb11_blocks, (PTR) &info);
4615 if (! ieee_buffer_emptyp (&info.vars))
4617 if (! ieee_change_buffer (&info, &info.vars)
4618 || ! ieee_write_byte (&info, (int) ieee_be_record_enum))
4621 if (! ieee_append_buffer (&info, &info.data, &info.vars))
4625 /* Now all the data is in info.data. Write it out to the BFD. We
4626 normally would need to worry about whether all the other sections
4627 are set up yet, but the IEEE backend will handle this particular
4628 case correctly regardless. */
4629 if (ieee_buffer_emptyp (&info.data))
4631 /* There is no debugging information. */
4635 s = bfd_make_section (abfd, ".debug");
4637 err = "bfd_make_section";
4640 if (! bfd_set_section_flags (abfd, s, SEC_DEBUGGING | SEC_HAS_CONTENTS))
4641 err = "bfd_set_section_flags";
4648 for (b = info.data.head; b != NULL; b = b->next)
4650 if (! bfd_set_section_size (abfd, s, size))
4651 err = "bfd_set_section_size";
4658 for (b = info.data.head; b != NULL; b = b->next)
4660 if (! bfd_set_section_contents (abfd, s, b->buf, offset, b->c))
4662 err = "bfd_set_section_contents";
4671 fprintf (stderr, "%s: %s: %s\n", bfd_get_filename (abfd), err,
4672 bfd_errmsg (bfd_get_error ()));
4676 bfd_hash_table_free (&info.typedefs.root);
4677 bfd_hash_table_free (&info.tags.root);
4682 /* Write out information for an undefined tag. This is called via
4683 ieee_name_type_hash_traverse. */
4686 ieee_write_undefined_tag (h, p)
4687 struct ieee_name_type_hash_entry *h;
4690 struct ieee_handle *info = (struct ieee_handle *) p;
4691 struct ieee_name_type *nt;
4693 for (nt = h->types; nt != NULL; nt = nt->next)
4695 unsigned int name_indx;
4698 if (nt->kind == DEBUG_KIND_ILLEGAL)
4701 if (ieee_buffer_emptyp (&info->global_types))
4703 if (! ieee_change_buffer (info, &info->global_types)
4704 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
4705 || ! ieee_write_byte (info, 2)
4706 || ! ieee_write_number (info, 0)
4707 || ! ieee_write_id (info, ""))
4715 if (! ieee_change_buffer (info, &info->global_types))
4722 name_indx = info->name_indx;
4724 if (! ieee_write_byte (info, (int) ieee_nn_record)
4725 || ! ieee_write_number (info, name_indx)
4726 || ! ieee_write_id (info, nt->type.name)
4727 || ! ieee_write_byte (info, (int) ieee_ty_record_enum)
4728 || ! ieee_write_number (info, nt->type.indx)
4729 || ! ieee_write_byte (info, 0xce)
4730 || ! ieee_write_number (info, name_indx))
4742 case DEBUG_KIND_STRUCT:
4743 case DEBUG_KIND_CLASS:
4746 case DEBUG_KIND_UNION:
4747 case DEBUG_KIND_UNION_CLASS:
4750 case DEBUG_KIND_ENUM:
4754 if (! ieee_write_number (info, code)
4755 || ! ieee_write_number (info, 0))
4765 /* Start writing out information for a compilation unit. */
4768 ieee_start_compilation_unit (p, filename)
4770 const char *filename;
4772 struct ieee_handle *info = (struct ieee_handle *) p;
4773 const char *modname;
4777 if (info->filename != NULL)
4779 if (! ieee_finish_compilation_unit (info))
4783 info->filename = filename;
4784 modname = strrchr (filename, '/');
4785 if (modname != NULL)
4789 modname = strrchr (filename, '\\');
4790 if (modname != NULL)
4795 c = xstrdup (modname);
4796 s = strrchr (c, '.');
4801 if (! ieee_init_buffer (info, &info->types)
4802 || ! ieee_init_buffer (info, &info->vars)
4803 || ! ieee_init_buffer (info, &info->cxx)
4804 || ! ieee_init_buffer (info, &info->linenos))
4806 info->ranges = NULL;
4808 /* Always include a BB1 and a BB3 block. That is what the output of
4809 the MRI linker seems to look like. */
4810 if (! ieee_change_buffer (info, &info->types)
4811 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
4812 || ! ieee_write_byte (info, 1)
4813 || ! ieee_write_number (info, 0)
4814 || ! ieee_write_id (info, info->modname))
4817 nindx = info->name_indx;
4819 if (! ieee_change_buffer (info, &info->vars)
4820 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
4821 || ! ieee_write_byte (info, 3)
4822 || ! ieee_write_number (info, 0)
4823 || ! ieee_write_id (info, info->modname))
4829 /* Finish up a compilation unit. */
4832 ieee_finish_compilation_unit (info)
4833 struct ieee_handle *info;
4835 struct ieee_range *r;
4837 if (! ieee_buffer_emptyp (&info->types))
4839 if (! ieee_change_buffer (info, &info->types)
4840 || ! ieee_write_byte (info, (int) ieee_be_record_enum))
4844 if (! ieee_buffer_emptyp (&info->cxx))
4846 /* Append any C++ information to the global function and
4847 variable information. */
4848 assert (! ieee_buffer_emptyp (&info->vars));
4849 if (! ieee_change_buffer (info, &info->vars))
4852 /* We put the pmisc records in a dummy procedure, just as the
4853 MRI compiler does. */
4854 if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
4855 || ! ieee_write_byte (info, 6)
4856 || ! ieee_write_number (info, 0)
4857 || ! ieee_write_id (info, "__XRYCPP")
4858 || ! ieee_write_number (info, 0)
4859 || ! ieee_write_number (info, 0)
4860 || ! ieee_write_number (info, info->highaddr - 1)
4861 || ! ieee_append_buffer (info, &info->vars, &info->cxx)
4862 || ! ieee_change_buffer (info, &info->vars)
4863 || ! ieee_write_byte (info, (int) ieee_be_record_enum)
4864 || ! ieee_write_number (info, info->highaddr - 1))
4868 if (! ieee_buffer_emptyp (&info->vars))
4870 if (! ieee_change_buffer (info, &info->vars)
4871 || ! ieee_write_byte (info, (int) ieee_be_record_enum))
4875 if (info->pending_lineno_filename != NULL)
4877 /* Force out the pending line number. */
4878 if (! ieee_lineno ((PTR) info, (const char *) NULL, 0, (bfd_vma) -1))
4881 if (! ieee_buffer_emptyp (&info->linenos))
4883 if (! ieee_change_buffer (info, &info->linenos)
4884 || ! ieee_write_byte (info, (int) ieee_be_record_enum))
4886 if (strcmp (info->filename, info->lineno_filename) != 0)
4888 /* We were not in the main file. We just closed the
4889 included line number block, and now we must close the
4890 main line number block. */
4891 if (! ieee_write_byte (info, (int) ieee_be_record_enum))
4896 if (! ieee_append_buffer (info, &info->data, &info->types)
4897 || ! ieee_append_buffer (info, &info->data, &info->vars)
4898 || ! ieee_append_buffer (info, &info->data, &info->linenos))
4901 /* Build BB10/BB11 blocks based on the ranges we recorded. */
4902 if (! ieee_change_buffer (info, &info->data))
4905 if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
4906 || ! ieee_write_byte (info, 10)
4907 || ! ieee_write_number (info, 0)
4908 || ! ieee_write_id (info, info->modname)
4909 || ! ieee_write_id (info, "")
4910 || ! ieee_write_number (info, 0)
4911 || ! ieee_write_id (info, "GNU objcopy"))
4914 for (r = info->ranges; r != NULL; r = r->next)
4923 /* Find the section corresponding to this range. */
4924 for (s = info->abfd->sections; s != NULL; s = s->next)
4926 if (bfd_get_section_vma (info->abfd, s) <= low
4927 && high <= (bfd_get_section_vma (info->abfd, s)
4928 + bfd_section_size (info->abfd, s)))
4934 /* Just ignore this range. */
4938 /* Coalesce ranges if it seems reasonable. */
4939 while (r->next != NULL
4940 && high + 64 >= r->next->low
4942 <= (bfd_get_section_vma (info->abfd, s)
4943 + bfd_section_size (info->abfd, s))))
4949 if ((s->flags & SEC_CODE) != 0)
4951 else if ((s->flags & SEC_READONLY) != 0)
4956 if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
4957 || ! ieee_write_byte (info, 11)
4958 || ! ieee_write_number (info, 0)
4959 || ! ieee_write_id (info, "")
4960 || ! ieee_write_number (info, kind)
4961 || ! ieee_write_number (info, s->index + IEEE_SECTION_NUMBER_BASE)
4962 || ! ieee_write_number (info, low)
4963 || ! ieee_write_byte (info, (int) ieee_be_record_enum)
4964 || ! ieee_write_number (info, high - low))
4967 /* Add this range to the list of global ranges. */
4968 if (! ieee_add_range (info, true, low, high))
4972 if (! ieee_write_byte (info, (int) ieee_be_record_enum))
4978 /* Add BB11 blocks describing each range that we have not already
4982 ieee_add_bb11_blocks (abfd, sec, data)
4987 struct ieee_handle *info = (struct ieee_handle *) data;
4989 struct ieee_range *r;
4991 low = bfd_get_section_vma (abfd, sec);
4992 high = low + bfd_section_size (abfd, sec);
4994 /* Find the first range at or after this section. The ranges are
4995 sorted by address. */
4996 for (r = info->global_ranges; r != NULL; r = r->next)
5002 if (r == NULL || r->low >= high)
5004 if (! ieee_add_bb11 (info, sec, low, high))
5011 if (! ieee_add_bb11 (info, sec, low, r->low))
5023 /* Add a single BB11 block for a range. We add it to info->vars. */
5026 ieee_add_bb11 (info, sec, low, high)
5027 struct ieee_handle *info;
5034 if (! ieee_buffer_emptyp (&info->vars))
5036 if (! ieee_change_buffer (info, &info->vars))
5041 const char *filename, *modname;
5044 /* Start the enclosing BB10 block. */
5045 filename = bfd_get_filename (info->abfd);
5046 modname = strrchr (filename, '/');
5047 if (modname != NULL)
5051 modname = strrchr (filename, '\\');
5052 if (modname != NULL)
5057 c = xstrdup (modname);
5058 s = strrchr (c, '.');
5062 if (! ieee_change_buffer (info, &info->vars)
5063 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
5064 || ! ieee_write_byte (info, 10)
5065 || ! ieee_write_number (info, 0)
5066 || ! ieee_write_id (info, c)
5067 || ! ieee_write_id (info, "")
5068 || ! ieee_write_number (info, 0)
5069 || ! ieee_write_id (info, "GNU objcopy"))
5075 if ((sec->flags & SEC_CODE) != 0)
5077 else if ((sec->flags & SEC_READONLY) != 0)
5082 if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
5083 || ! ieee_write_byte (info, 11)
5084 || ! ieee_write_number (info, 0)
5085 || ! ieee_write_id (info, "")
5086 || ! ieee_write_number (info, kind)
5087 || ! ieee_write_number (info, sec->index + IEEE_SECTION_NUMBER_BASE)
5088 || ! ieee_write_number (info, low)
5089 || ! ieee_write_byte (info, (int) ieee_be_record_enum)
5090 || ! ieee_write_number (info, high - low))
5096 /* Start recording information from a particular source file. This is
5097 used to record which file defined which types, variables, etc. It
5098 is not used for line numbers, since the lineno entry point passes
5099 down the file name anyhow. IEEE debugging information doesn't seem
5100 to store this information anywhere. */
5104 ieee_start_source (p, filename)
5106 const char *filename;
5111 /* Make an empty type. */
5117 struct ieee_handle *info = (struct ieee_handle *) p;
5119 return ieee_push_type (info, (int) builtin_unknown, 0, false, false);
5122 /* Make a void type. */
5128 struct ieee_handle *info = (struct ieee_handle *) p;
5130 return ieee_push_type (info, (int) builtin_void, 0, false, false);
5133 /* Make an integer type. */
5136 ieee_int_type (p, size, unsignedp)
5141 struct ieee_handle *info = (struct ieee_handle *) p;
5147 indx = (int) builtin_signed_char;
5150 indx = (int) builtin_signed_short_int;
5153 indx = (int) builtin_signed_long;
5156 indx = (int) builtin_signed_long_long;
5159 fprintf (stderr, "IEEE unsupported integer type size %u\n", size);
5166 return ieee_push_type (info, indx, size, unsignedp, false);
5169 /* Make a floating point type. */
5172 ieee_float_type (p, size)
5176 struct ieee_handle *info = (struct ieee_handle *) p;
5182 indx = (int) builtin_float;
5185 indx = (int) builtin_double;
5188 /* FIXME: This size really depends upon the processor. */
5189 indx = (int) builtin_long_double;
5192 indx = (int) builtin_long_long_double;
5195 fprintf (stderr, "IEEE unsupported float type size %u\n", size);
5199 return ieee_push_type (info, indx, size, false, false);
5202 /* Make a complex type. */
5205 ieee_complex_type (p, size)
5209 struct ieee_handle *info = (struct ieee_handle *) p;
5215 if (info->complex_float_index != 0)
5216 return ieee_push_type (info, info->complex_float_index, size * 2,
5222 /* These cases can be output by gcc -gstabs. Outputting the
5223 wrong type is better than crashing. */
5225 if (info->complex_double_index != 0)
5226 return ieee_push_type (info, info->complex_double_index, size * 2,
5231 fprintf (stderr, "IEEE unsupported complex type size %u\n", size);
5235 /* FIXME: I don't know what the string is for. */
5236 if (! ieee_define_type (info, size * 2, false, false)
5237 || ! ieee_write_number (info, code)
5238 || ! ieee_write_id (info, ""))
5242 info->complex_float_index = info->type_stack->type.indx;
5244 info->complex_double_index = info->type_stack->type.indx;
5249 /* Make a boolean type. IEEE doesn't support these, so we just make
5250 an integer type instead. */
5253 ieee_bool_type (p, size)
5257 return ieee_int_type (p, size, true);
5260 /* Make an enumeration. */
5263 ieee_enum_type (p, tag, names, vals)
5267 bfd_signed_vma *vals;
5269 struct ieee_handle *info = (struct ieee_handle *) p;
5270 struct ieee_defined_enum *e;
5271 boolean localp, simple;
5275 for (e = info->enums; e != NULL; e = e->next)
5285 || tag[0] != e->tag[0]
5286 || strcmp (tag, e->tag) != 0)
5290 if (names != NULL && e->names != NULL)
5292 for (i = 0; names[i] != NULL && e->names[i] != NULL; i++)
5294 if (names[i][0] != e->names[i][0]
5295 || vals[i] != e->vals[i]
5296 || strcmp (names[i], e->names[i]) != 0)
5301 if ((names == NULL && e->names == NULL)
5302 || (names[i] == NULL && e->names[i] == NULL))
5304 /* We've seen this enum before. */
5305 return ieee_push_type (info, e->indx, 0, true, false);
5310 /* We've already seen an enum of the same name, so we must make
5311 sure to output this one locally. */
5317 /* If this is a simple enumeration, in which the values start at 0
5318 and always increment by 1, we can use type E. Otherwise we must
5324 for (i = 0; names[i] != NULL; i++)
5334 if (! ieee_define_named_type (info, tag, (unsigned int) -1, 0,
5335 true, localp, (struct ieee_buflist *) NULL)
5336 || ! ieee_write_number (info, simple ? 'E' : 'N'))
5340 /* FIXME: This is supposed to be the enumeration size, but we
5341 don't store that. */
5342 if (! ieee_write_number (info, 4))
5347 for (i = 0; names[i] != NULL; i++)
5349 if (! ieee_write_id (info, names[i]))
5353 if (! ieee_write_number (info, vals[i]))
5361 e = (struct ieee_defined_enum *) xmalloc (sizeof *e);
5362 memset (e, 0, sizeof *e);
5364 e->indx = info->type_stack->type.indx;
5369 e->next = info->enums;
5376 /* Make a pointer type. */
5379 ieee_pointer_type (p)
5382 struct ieee_handle *info = (struct ieee_handle *) p;
5385 struct ieee_modified_type *m = NULL;
5387 localp = info->type_stack->type.localp;
5388 indx = ieee_pop_type (info);
5390 /* A pointer to a simple builtin type can be obtained by adding 32.
5391 FIXME: Will this be a short pointer, and will that matter? */
5393 return ieee_push_type (info, indx + 32, 0, true, false);
5397 m = ieee_get_modified_info (p, indx);
5401 /* FIXME: The size should depend upon the architecture. */
5403 return ieee_push_type (info, m->pointer, 4, true, false);
5406 if (! ieee_define_type (info, 4, true, localp)
5407 || ! ieee_write_number (info, 'P')
5408 || ! ieee_write_number (info, indx))
5412 m->pointer = info->type_stack->type.indx;
5417 /* Make a function type. This will be called for a method, but we
5418 don't want to actually add it to the type table in that case. We
5419 handle this by defining the type in a private buffer, and only
5420 adding that buffer to the typedef block if we are going to use it. */
5423 ieee_function_type (p, argcount, varargs)
5428 struct ieee_handle *info = (struct ieee_handle *) p;
5430 unsigned int *args = NULL;
5432 unsigned int retindx;
5433 struct ieee_buflist fndef;
5434 struct ieee_modified_type *m;
5440 args = (unsigned int *) xmalloc (argcount * sizeof *args);
5441 for (i = argcount - 1; i >= 0; i--)
5443 if (info->type_stack->type.localp)
5445 args[i] = ieee_pop_type (info);
5448 else if (argcount < 0)
5451 if (info->type_stack->type.localp)
5453 retindx = ieee_pop_type (info);
5456 if (argcount < 0 && ! localp)
5458 m = ieee_get_modified_info (p, retindx);
5462 if (m->function > 0)
5463 return ieee_push_type (info, m->function, 0, true, false);
5466 /* An attribute of 0x41 means that the frame and push mask are
5468 if (! ieee_init_buffer (info, &fndef)
5469 || ! ieee_define_named_type (info, (const char *) NULL,
5470 (unsigned int) -1, 0, true, localp,
5472 || ! ieee_write_number (info, 'x')
5473 || ! ieee_write_number (info, 0x41)
5474 || ! ieee_write_number (info, 0)
5475 || ! ieee_write_number (info, 0)
5476 || ! ieee_write_number (info, retindx)
5477 || ! ieee_write_number (info, (bfd_vma) argcount + (varargs ? 1 : 0)))
5481 for (i = 0; i < argcount; i++)
5482 if (! ieee_write_number (info, args[i]))
5488 /* A varargs function is represented by writing out the last
5489 argument as type void *, although this makes little sense. */
5490 if (! ieee_write_number (info, (bfd_vma) builtin_void + 32))
5494 if (! ieee_write_number (info, 0))
5497 /* We wrote the information into fndef, in case we don't need it.
5498 It will be appended to info->types by ieee_pop_type. */
5499 info->type_stack->type.fndef = fndef;
5502 m->function = info->type_stack->type.indx;
5507 /* Make a reference type. */
5510 ieee_reference_type (p)
5513 struct ieee_handle *info = (struct ieee_handle *) p;
5515 /* IEEE appears to record a normal pointer type, and then use a
5516 pmisc record to indicate that it is really a reference. */
5518 if (! ieee_pointer_type (p))
5520 info->type_stack->type.referencep = true;
5524 /* Make a range type. */
5527 ieee_range_type (p, low, high)
5530 bfd_signed_vma high;
5532 struct ieee_handle *info = (struct ieee_handle *) p;
5534 boolean unsignedp, localp;
5536 size = info->type_stack->type.size;
5537 unsignedp = info->type_stack->type.unsignedp;
5538 localp = info->type_stack->type.localp;
5539 ieee_pop_unused_type (info);
5540 return (ieee_define_type (info, size, unsignedp, localp)
5541 && ieee_write_number (info, 'R')
5542 && ieee_write_number (info, (bfd_vma) low)
5543 && ieee_write_number (info, (bfd_vma) high)
5544 && ieee_write_number (info, unsignedp ? 0 : 1)
5545 && ieee_write_number (info, size));
5548 /* Make an array type. */
5552 ieee_array_type (p, low, high, stringp)
5555 bfd_signed_vma high;
5558 struct ieee_handle *info = (struct ieee_handle *) p;
5559 unsigned int eleindx;
5561 struct ieee_modified_type *m = NULL;
5562 struct ieee_modified_array_type *a;
5564 /* IEEE does not store the range, so we just ignore it. */
5565 ieee_pop_unused_type (info);
5566 localp = info->type_stack->type.localp;
5567 eleindx = ieee_pop_type (info);
5571 m = ieee_get_modified_info (info, eleindx);
5575 for (a = m->arrays; a != NULL; a = a->next)
5577 if (a->low == low && a->high == high)
5578 return ieee_push_type (info, a->indx, 0, false, false);
5582 if (! ieee_define_type (info, 0, false, localp)
5583 || ! ieee_write_number (info, low == 0 ? 'Z' : 'C')
5584 || ! ieee_write_number (info, eleindx))
5588 if (! ieee_write_number (info, low))
5592 if (! ieee_write_number (info, high + 1))
5597 a = (struct ieee_modified_array_type *) xmalloc (sizeof *a);
5598 memset (a, 0, sizeof *a);
5600 a->indx = info->type_stack->type.indx;
5604 a->next = m->arrays;
5611 /* Make a set type. */
5614 ieee_set_type (p, bitstringp)
5618 struct ieee_handle *info = (struct ieee_handle *) p;
5620 unsigned int eleindx;
5622 localp = info->type_stack->type.localp;
5623 eleindx = ieee_pop_type (info);
5625 /* FIXME: We don't know the size, so we just use 4. */
5627 return (ieee_define_type (info, 0, true, localp)
5628 && ieee_write_number (info, 's')
5629 && ieee_write_number (info, 4)
5630 && ieee_write_number (info, eleindx));
5633 /* Make an offset type. */
5636 ieee_offset_type (p)
5639 struct ieee_handle *info = (struct ieee_handle *) p;
5640 unsigned int targetindx, baseindx;
5642 targetindx = ieee_pop_type (info);
5643 baseindx = ieee_pop_type (info);
5645 /* FIXME: The MRI C++ compiler does not appear to generate any
5646 useful type information about an offset type. It just records a
5647 pointer to member as an integer. The MRI/HP IEEE spec does
5648 describe a pmisc record which can be used for a pointer to
5649 member. Unfortunately, it does not describe the target type,
5650 which seems pretty important. I'm going to punt this for now. */
5652 return ieee_int_type (p, 4, true);
5655 /* Make a method type. */
5658 ieee_method_type (p, domain, argcount, varargs)
5664 struct ieee_handle *info = (struct ieee_handle *) p;
5666 /* FIXME: The MRI/HP IEEE spec defines a pmisc record to use for a
5667 method, but the definition is incomplete. We just output an 'x'
5671 ieee_pop_unused_type (info);
5673 return ieee_function_type (p, argcount, varargs);
5676 /* Make a const qualified type. */
5682 struct ieee_handle *info = (struct ieee_handle *) p;
5684 boolean unsignedp, localp;
5686 struct ieee_modified_type *m = NULL;
5688 size = info->type_stack->type.size;
5689 unsignedp = info->type_stack->type.unsignedp;
5690 localp = info->type_stack->type.localp;
5691 indx = ieee_pop_type (info);
5695 m = ieee_get_modified_info (info, indx);
5699 if (m->const_qualified > 0)
5700 return ieee_push_type (info, m->const_qualified, size, unsignedp,
5704 if (! ieee_define_type (info, size, unsignedp, localp)
5705 || ! ieee_write_number (info, 'n')
5706 || ! ieee_write_number (info, 1)
5707 || ! ieee_write_number (info, indx))
5711 m->const_qualified = info->type_stack->type.indx;
5716 /* Make a volatile qualified type. */
5719 ieee_volatile_type (p)
5722 struct ieee_handle *info = (struct ieee_handle *) p;
5724 boolean unsignedp, localp;
5726 struct ieee_modified_type *m = NULL;
5728 size = info->type_stack->type.size;
5729 unsignedp = info->type_stack->type.unsignedp;
5730 localp = info->type_stack->type.localp;
5731 indx = ieee_pop_type (info);
5735 m = ieee_get_modified_info (info, indx);
5739 if (m->volatile_qualified > 0)
5740 return ieee_push_type (info, m->volatile_qualified, size, unsignedp,
5744 if (! ieee_define_type (info, size, unsignedp, localp)
5745 || ! ieee_write_number (info, 'n')
5746 || ! ieee_write_number (info, 2)
5747 || ! ieee_write_number (info, indx))
5751 m->volatile_qualified = info->type_stack->type.indx;
5756 /* Convert an enum debug_visibility into a CXXFLAGS value. */
5759 ieee_vis_to_flags (visibility)
5760 enum debug_visibility visibility;
5766 case DEBUG_VISIBILITY_PUBLIC:
5767 return CXXFLAGS_VISIBILITY_PUBLIC;
5768 case DEBUG_VISIBILITY_PRIVATE:
5769 return CXXFLAGS_VISIBILITY_PRIVATE;
5770 case DEBUG_VISIBILITY_PROTECTED:
5771 return CXXFLAGS_VISIBILITY_PROTECTED;
5776 /* Start defining a struct type. We build it in the strdef field on
5777 the stack, to avoid confusing type definitions required by the
5778 fields with the struct type itself. */
5781 ieee_start_struct_type (p, tag, id, structp, size)
5788 struct ieee_handle *info = (struct ieee_handle *) p;
5789 boolean localp, ignorep;
5793 struct ieee_name_type_hash_entry *h;
5794 struct ieee_name_type *nt, *ntlook;
5795 struct ieee_buflist strdef;
5800 /* We need to create a tag for internal use even if we don't want
5801 one for external use. This will let us refer to an anonymous
5810 sprintf (ab, "__anon%u", id);
5815 /* If we already have references to the tag, we must use the
5816 existing type index. */
5817 h = ieee_name_type_hash_lookup (&info->tags, look, true, copy);
5822 for (ntlook = h->types; ntlook != NULL; ntlook = ntlook->next)
5824 if (ntlook->id == id)
5826 else if (! ntlook->type.localp)
5828 /* We are creating a duplicate definition of a globally
5829 defined tag. Force it to be local to avoid
5837 assert (localp == nt->type.localp);
5838 if (nt->kind == DEBUG_KIND_ILLEGAL && ! localp)
5840 /* We've already seen a global definition of the type.
5841 Ignore this new definition. */
5847 nt = (struct ieee_name_type *) xmalloc (sizeof *nt);
5848 memset (nt, 0, sizeof *nt);
5850 nt->type.name = h->root.string;
5851 nt->next = h->types;
5853 nt->type.indx = info->type_indx;
5857 nt->kind = DEBUG_KIND_ILLEGAL;
5859 if (! ieee_init_buffer (info, &strdef)
5860 || ! ieee_define_named_type (info, tag, nt->type.indx, size, true,
5862 || ! ieee_write_number (info, structp ? 'S' : 'U')
5863 || ! ieee_write_number (info, size))
5870 /* We never want nt->type.name to be NULL. We want the rest of
5871 the type to be the object set up on the type stack; it will
5872 have a NULL name if tag is NULL. */
5873 hold = nt->type.name;
5874 nt->type = info->type_stack->type;
5875 nt->type.name = hold;
5878 info->type_stack->type.name = tag;
5879 info->type_stack->type.strdef = strdef;
5880 info->type_stack->type.ignorep = ignorep;
5885 /* Add a field to a struct. */
5888 ieee_struct_field (p, name, bitpos, bitsize, visibility)
5893 enum debug_visibility visibility;
5895 struct ieee_handle *info = (struct ieee_handle *) p;
5903 assert (info->type_stack != NULL
5904 && info->type_stack->next != NULL
5905 && ! ieee_buffer_emptyp (&info->type_stack->next->type.strdef));
5907 /* If we are ignoring this struct definition, just pop and ignore
5909 if (info->type_stack->next->type.ignorep)
5911 ieee_pop_unused_type (info);
5915 size = info->type_stack->type.size;
5916 unsignedp = info->type_stack->type.unsignedp;
5917 referencep = info->type_stack->type.referencep;
5918 localp = info->type_stack->type.localp;
5919 indx = ieee_pop_type (info);
5922 info->type_stack->type.localp = true;
5924 if (info->type_stack->type.classdef != NULL)
5929 /* This is a class. We must add a description of this field to
5930 the class records we are building. */
5932 flags = ieee_vis_to_flags (visibility);
5933 nindx = info->type_stack->type.classdef->indx;
5934 if (! ieee_change_buffer (info,
5935 &info->type_stack->type.classdef->pmiscbuf)
5936 || ! ieee_write_asn (info, nindx, 'd')
5937 || ! ieee_write_asn (info, nindx, flags)
5938 || ! ieee_write_atn65 (info, nindx, name)
5939 || ! ieee_write_atn65 (info, nindx, name))
5941 info->type_stack->type.classdef->pmisccount += 4;
5947 /* We need to output a record recording that this field is
5948 really of reference type. We put this on the refs field
5949 of classdef, so that it can be appended to the C++
5950 records after the class is defined. */
5952 nindx = info->name_indx;
5955 if (! ieee_change_buffer (info,
5956 &info->type_stack->type.classdef->refs)
5957 || ! ieee_write_byte (info, (int) ieee_nn_record)
5958 || ! ieee_write_number (info, nindx)
5959 || ! ieee_write_id (info, "")
5960 || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
5961 || ! ieee_write_number (info, nindx)
5962 || ! ieee_write_number (info, 0)
5963 || ! ieee_write_number (info, 62)
5964 || ! ieee_write_number (info, 80)
5965 || ! ieee_write_number (info, 4)
5966 || ! ieee_write_asn (info, nindx, 'R')
5967 || ! ieee_write_asn (info, nindx, 3)
5968 || ! ieee_write_atn65 (info, nindx, info->type_stack->type.name)
5969 || ! ieee_write_atn65 (info, nindx, name))
5974 /* If the bitsize doesn't match the expected size, we need to output
5976 if (size == 0 || bitsize == 0 || bitsize == size * 8)
5977 offset = bitpos / 8;
5980 if (! ieee_define_type (info, 0, unsignedp,
5981 info->type_stack->type.localp)
5982 || ! ieee_write_number (info, 'g')
5983 || ! ieee_write_number (info, unsignedp ? 0 : 1)
5984 || ! ieee_write_number (info, bitsize)
5985 || ! ieee_write_number (info, indx))
5987 indx = ieee_pop_type (info);
5991 /* Switch to the struct we are building in order to output this
5992 field definition. */
5993 return (ieee_change_buffer (info, &info->type_stack->type.strdef)
5994 && ieee_write_id (info, name)
5995 && ieee_write_number (info, indx)
5996 && ieee_write_number (info, offset));
5999 /* Finish up a struct type. */
6002 ieee_end_struct_type (p)
6005 struct ieee_handle *info = (struct ieee_handle *) p;
6006 struct ieee_buflist *pb;
6008 assert (info->type_stack != NULL
6009 && ! ieee_buffer_emptyp (&info->type_stack->type.strdef));
6011 /* If we were ignoring this struct definition because it was a
6012 duplicate defintion, just through away whatever bytes we have
6013 accumulated. Leave the type on the stack. */
6014 if (info->type_stack->type.ignorep)
6017 /* If this is not a duplicate definition of this tag, then localp
6018 will be false, and we can put it in the global type block.
6019 FIXME: We should avoid outputting duplicate definitions which are
6021 if (! info->type_stack->type.localp)
6023 /* Make sure we have started the global type block. */
6024 if (ieee_buffer_emptyp (&info->global_types))
6026 if (! ieee_change_buffer (info, &info->global_types)
6027 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
6028 || ! ieee_write_byte (info, 2)
6029 || ! ieee_write_number (info, 0)
6030 || ! ieee_write_id (info, ""))
6033 pb = &info->global_types;
6037 /* Make sure we have started the types block. */
6038 if (ieee_buffer_emptyp (&info->types))
6040 if (! ieee_change_buffer (info, &info->types)
6041 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
6042 || ! ieee_write_byte (info, 1)
6043 || ! ieee_write_number (info, 0)
6044 || ! ieee_write_id (info, info->modname))
6050 /* Append the struct definition to the types. */
6051 if (! ieee_append_buffer (info, pb, &info->type_stack->type.strdef)
6052 || ! ieee_init_buffer (info, &info->type_stack->type.strdef))
6055 /* Leave the struct on the type stack. */
6060 /* Start a class type. */
6063 ieee_start_class_type (p, tag, id, structp, size, vptr, ownvptr)
6072 struct ieee_handle *info = (struct ieee_handle *) p;
6074 struct ieee_buflist pmiscbuf;
6076 struct ieee_type_class *classdef;
6078 /* A C++ class is output as a C++ struct along with a set of pmisc
6079 records describing the class. */
6081 /* We need to have a name so that we can associate the struct and
6087 t = (char *) xmalloc (20);
6088 sprintf (t, "__anon%u", id);
6092 /* We can't write out the virtual table information until we have
6093 finished the class, because we don't know the virtual table size.
6094 We get the size from the largest voffset we see. */
6096 if (vptr && ! ownvptr)
6098 vclass = info->type_stack->type.name;
6099 assert (vclass != NULL);
6100 /* We don't call ieee_pop_unused_type, since the class should
6102 (void) ieee_pop_type (info);
6105 if (! ieee_start_struct_type (p, tag, id, structp, size))
6108 indx = info->name_indx;
6111 /* We write out pmisc records into the classdef field. We will
6112 write out the pmisc start after we know the number of records we
6114 if (! ieee_init_buffer (info, &pmiscbuf)
6115 || ! ieee_change_buffer (info, &pmiscbuf)
6116 || ! ieee_write_asn (info, indx, 'T')
6117 || ! ieee_write_asn (info, indx, structp ? 'o' : 'u')
6118 || ! ieee_write_atn65 (info, indx, tag))
6121 classdef = (struct ieee_type_class *) xmalloc (sizeof *classdef);
6122 memset (classdef, 0, sizeof *classdef);
6124 classdef->indx = indx;
6125 classdef->pmiscbuf = pmiscbuf;
6126 classdef->pmisccount = 3;
6127 classdef->vclass = vclass;
6128 classdef->ownvptr = ownvptr;
6130 info->type_stack->type.classdef = classdef;
6135 /* Add a static member to a class. */
6138 ieee_class_static_member (p, name, physname, visibility)
6141 const char *physname;
6142 enum debug_visibility visibility;
6144 struct ieee_handle *info = (struct ieee_handle *) p;
6148 /* We don't care about the type. Hopefully there will be a call to
6149 ieee_variable declaring the physical name and the type, since
6150 that is where an IEEE consumer must get the type. */
6151 ieee_pop_unused_type (info);
6153 assert (info->type_stack != NULL
6154 && info->type_stack->type.classdef != NULL);
6156 flags = ieee_vis_to_flags (visibility);
6157 flags |= CXXFLAGS_STATIC;
6159 nindx = info->type_stack->type.classdef->indx;
6161 if (! ieee_change_buffer (info, &info->type_stack->type.classdef->pmiscbuf)
6162 || ! ieee_write_asn (info, nindx, 'd')
6163 || ! ieee_write_asn (info, nindx, flags)
6164 || ! ieee_write_atn65 (info, nindx, name)
6165 || ! ieee_write_atn65 (info, nindx, physname))
6167 info->type_stack->type.classdef->pmisccount += 4;
6172 /* Add a base class to a class. */
6175 ieee_class_baseclass (p, bitpos, virtual, visibility)
6179 enum debug_visibility visibility;
6181 struct ieee_handle *info = (struct ieee_handle *) p;
6189 assert (info->type_stack != NULL
6190 && info->type_stack->type.name != NULL
6191 && info->type_stack->next != NULL
6192 && info->type_stack->next->type.classdef != NULL
6193 && ! ieee_buffer_emptyp (&info->type_stack->next->type.strdef));
6195 bname = info->type_stack->type.name;
6196 localp = info->type_stack->type.localp;
6197 bindx = ieee_pop_type (info);
6199 /* We are currently defining both a struct and a class. We must
6200 write out a field definition in the struct which holds the base
6201 class. The stabs debugging reader will create a field named
6202 _vb$CLASS for a virtual base class, so we just use that. FIXME:
6203 we should not depend upon a detail of stabs debugging. */
6206 fname = (char *) xmalloc (strlen (bname) + sizeof "_vb$");
6207 sprintf (fname, "_vb$%s", bname);
6208 flags = BASEFLAGS_VIRTUAL;
6213 info->type_stack->type.localp = true;
6215 fname = (char *) xmalloc (strlen (bname) + sizeof "_b$");
6216 sprintf (fname, "_b$%s", bname);
6218 if (! ieee_change_buffer (info, &info->type_stack->type.strdef)
6219 || ! ieee_write_id (info, fname)
6220 || ! ieee_write_number (info, bindx)
6221 || ! ieee_write_number (info, bitpos / 8))
6226 if (visibility == DEBUG_VISIBILITY_PRIVATE)
6227 flags |= BASEFLAGS_PRIVATE;
6229 nindx = info->type_stack->type.classdef->indx;
6231 if (! ieee_change_buffer (info, &info->type_stack->type.classdef->pmiscbuf)
6232 || ! ieee_write_asn (info, nindx, 'b')
6233 || ! ieee_write_asn (info, nindx, flags)
6234 || ! ieee_write_atn65 (info, nindx, bname)
6235 || ! ieee_write_asn (info, nindx, 0)
6236 || ! ieee_write_atn65 (info, nindx, fname))
6238 info->type_stack->type.classdef->pmisccount += 5;
6245 /* Start building a method for a class. */
6248 ieee_class_start_method (p, name)
6252 struct ieee_handle *info = (struct ieee_handle *) p;
6254 assert (info->type_stack != NULL
6255 && info->type_stack->type.classdef != NULL
6256 && info->type_stack->type.classdef->method == NULL);
6258 info->type_stack->type.classdef->method = name;
6263 /* Define a new method variant, either static or not. */
6266 ieee_class_method_var (info, physname, visibility, staticp, constp,
6267 volatilep, voffset, context)
6268 struct ieee_handle *info;
6269 const char *physname;
6270 enum debug_visibility visibility;
6281 /* We don't need the type of the method. An IEEE consumer which
6282 wants the type must track down the function by the physical name
6283 and get the type from that. */
6284 ieee_pop_unused_type (info);
6286 /* We don't use the context. FIXME: We probably ought to use it to
6287 adjust the voffset somehow, but I don't really know how. */
6289 ieee_pop_unused_type (info);
6291 assert (info->type_stack != NULL
6292 && info->type_stack->type.classdef != NULL
6293 && info->type_stack->type.classdef->method != NULL);
6295 flags = ieee_vis_to_flags (visibility);
6297 /* FIXME: We never set CXXFLAGS_OVERRIDE, CXXFLAGS_OPERATOR,
6298 CXXFLAGS_CTORDTOR, CXXFLAGS_CTOR, or CXXFLAGS_INLINE. */
6301 flags |= CXXFLAGS_STATIC;
6303 flags |= CXXFLAGS_CONST;
6305 flags |= CXXFLAGS_VOLATILE;
6307 nindx = info->type_stack->type.classdef->indx;
6309 virtual = context || voffset > 0;
6311 if (! ieee_change_buffer (info,
6312 &info->type_stack->type.classdef->pmiscbuf)
6313 || ! ieee_write_asn (info, nindx, virtual ? 'v' : 'm')
6314 || ! ieee_write_asn (info, nindx, flags)
6315 || ! ieee_write_atn65 (info, nindx,
6316 info->type_stack->type.classdef->method)
6317 || ! ieee_write_atn65 (info, nindx, physname))
6322 if (voffset > info->type_stack->type.classdef->voffset)
6323 info->type_stack->type.classdef->voffset = voffset;
6324 if (! ieee_write_asn (info, nindx, voffset))
6326 ++info->type_stack->type.classdef->pmisccount;
6329 if (! ieee_write_asn (info, nindx, 0))
6332 info->type_stack->type.classdef->pmisccount += 5;
6337 /* Define a new method variant. */
6340 ieee_class_method_variant (p, physname, visibility, constp, volatilep,
6343 const char *physname;
6344 enum debug_visibility visibility;
6350 struct ieee_handle *info = (struct ieee_handle *) p;
6352 return ieee_class_method_var (info, physname, visibility, false, constp,
6353 volatilep, voffset, context);
6356 /* Define a new static method variant. */
6359 ieee_class_static_method_variant (p, physname, visibility, constp, volatilep)
6361 const char *physname;
6362 enum debug_visibility visibility;
6366 struct ieee_handle *info = (struct ieee_handle *) p;
6368 return ieee_class_method_var (info, physname, visibility, true, constp,
6369 volatilep, 0, false);
6372 /* Finish up a method. */
6375 ieee_class_end_method (p)
6378 struct ieee_handle *info = (struct ieee_handle *) p;
6380 assert (info->type_stack != NULL
6381 && info->type_stack->type.classdef != NULL
6382 && info->type_stack->type.classdef->method != NULL);
6384 info->type_stack->type.classdef->method = NULL;
6389 /* Finish up a class. */
6392 ieee_end_class_type (p)
6395 struct ieee_handle *info = (struct ieee_handle *) p;
6398 assert (info->type_stack != NULL
6399 && info->type_stack->type.classdef != NULL);
6401 /* If we were ignoring this class definition because it was a
6402 duplicate definition, just through away whatever bytes we have
6403 accumulated. Leave the type on the stack. */
6404 if (info->type_stack->type.ignorep)
6407 nindx = info->type_stack->type.classdef->indx;
6409 /* If we have a virtual table, we can write out the information now. */
6410 if (info->type_stack->type.classdef->vclass != NULL
6411 || info->type_stack->type.classdef->ownvptr)
6413 if (! ieee_change_buffer (info,
6414 &info->type_stack->type.classdef->pmiscbuf)
6415 || ! ieee_write_asn (info, nindx, 'z')
6416 || ! ieee_write_atn65 (info, nindx, "")
6417 || ! ieee_write_asn (info, nindx,
6418 info->type_stack->type.classdef->voffset))
6420 if (info->type_stack->type.classdef->ownvptr)
6422 if (! ieee_write_atn65 (info, nindx, ""))
6427 if (! ieee_write_atn65 (info, nindx,
6428 info->type_stack->type.classdef->vclass))
6431 if (! ieee_write_asn (info, nindx, 0))
6433 info->type_stack->type.classdef->pmisccount += 5;
6436 /* Now that we know the number of pmisc records, we can write out
6437 the atn62 which starts the pmisc records, and append them to the
6440 if (! ieee_change_buffer (info, &info->cxx)
6441 || ! ieee_write_byte (info, (int) ieee_nn_record)
6442 || ! ieee_write_number (info, nindx)
6443 || ! ieee_write_id (info, "")
6444 || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
6445 || ! ieee_write_number (info, nindx)
6446 || ! ieee_write_number (info, 0)
6447 || ! ieee_write_number (info, 62)
6448 || ! ieee_write_number (info, 80)
6449 || ! ieee_write_number (info,
6450 info->type_stack->type.classdef->pmisccount))
6453 if (! ieee_append_buffer (info, &info->cxx,
6454 &info->type_stack->type.classdef->pmiscbuf))
6456 if (! ieee_buffer_emptyp (&info->type_stack->type.classdef->refs))
6458 if (! ieee_append_buffer (info, &info->cxx,
6459 &info->type_stack->type.classdef->refs))
6463 return ieee_end_struct_type (p);
6466 /* Push a previously seen typedef onto the type stack. */
6469 ieee_typedef_type (p, name)
6473 struct ieee_handle *info = (struct ieee_handle *) p;
6474 struct ieee_name_type_hash_entry *h;
6475 struct ieee_name_type *nt;
6477 h = ieee_name_type_hash_lookup (&info->typedefs, name, false, false);
6479 /* h should never be NULL, since that would imply that the generic
6480 debugging code has asked for a typedef which it has not yet
6484 /* We always use the most recently defined type for this name, which
6485 will be the first one on the list. */
6488 if (! ieee_push_type (info, nt->type.indx, nt->type.size,
6489 nt->type.unsignedp, nt->type.localp))
6492 /* Copy over any other type information we may have. */
6493 info->type_stack->type = nt->type;
6498 /* Push a tagged type onto the type stack. */
6501 ieee_tag_type (p, name, id, kind)
6505 enum debug_type_kind kind;
6507 struct ieee_handle *info = (struct ieee_handle *) p;
6511 struct ieee_name_type_hash_entry *h;
6512 struct ieee_name_type *nt;
6514 if (kind == DEBUG_KIND_ENUM)
6516 struct ieee_defined_enum *e;
6520 for (e = info->enums; e != NULL; e = e->next)
6521 if (e->tag != NULL && strcmp (e->tag, name) == 0)
6522 return ieee_push_type (info, e->indx, 0, true, false);
6531 sprintf (ab, "__anon%u", id);
6536 h = ieee_name_type_hash_lookup (&info->tags, name, true, copy);
6540 for (nt = h->types; nt != NULL; nt = nt->next)
6544 if (! ieee_push_type (info, nt->type.indx, nt->type.size,
6545 nt->type.unsignedp, nt->type.localp))
6547 /* Copy over any other type information we may have. */
6548 info->type_stack->type = nt->type;
6552 if (! nt->type.localp)
6554 /* This is a duplicate of a global type, so it must be
6560 nt = (struct ieee_name_type *) xmalloc (sizeof *nt);
6561 memset (nt, 0, sizeof *nt);
6564 nt->type.name = h->root.string;
6565 nt->type.indx = info->type_indx;
6566 nt->type.localp = localp;
6570 nt->next = h->types;
6573 if (! ieee_push_type (info, nt->type.indx, 0, false, localp))
6576 info->type_stack->type.name = h->root.string;
6581 /* Output a typedef. */
6584 ieee_typdef (p, name)
6588 struct ieee_handle *info = (struct ieee_handle *) p;
6589 struct ieee_write_type type;
6593 struct ieee_name_type_hash_entry *h;
6594 struct ieee_name_type *nt;
6596 type = info->type_stack->type;
6599 /* If this is a simple builtin type using a builtin name, we don't
6600 want to output the typedef itself. We also want to change the
6601 type index to correspond to the name being used. We recognize
6602 names used in stabs debugging output even if they don't exactly
6603 correspond to the names used for the IEEE builtin types. */
6605 if (indx <= (unsigned int) builtin_bcd_float)
6607 switch ((enum builtin_types) indx)
6613 if (strcmp (name, "void") == 0)
6617 case builtin_signed_char:
6619 if (strcmp (name, "signed char") == 0)
6621 indx = (unsigned int) builtin_signed_char;
6624 else if (strcmp (name, "char") == 0)
6626 indx = (unsigned int) builtin_char;
6631 case builtin_unsigned_char:
6632 if (strcmp (name, "unsigned char") == 0)
6636 case builtin_signed_short_int:
6638 case builtin_short_int:
6639 case builtin_signed_short:
6640 if (strcmp (name, "signed short int") == 0)
6642 indx = (unsigned int) builtin_signed_short_int;
6645 else if (strcmp (name, "short") == 0)
6647 indx = (unsigned int) builtin_short;
6650 else if (strcmp (name, "short int") == 0)
6652 indx = (unsigned int) builtin_short_int;
6655 else if (strcmp (name, "signed short") == 0)
6657 indx = (unsigned int) builtin_signed_short;
6662 case builtin_unsigned_short_int:
6663 case builtin_unsigned_short:
6664 if (strcmp (name, "unsigned short int") == 0
6665 || strcmp (name, "short unsigned int") == 0)
6667 indx = builtin_unsigned_short_int;
6670 else if (strcmp (name, "unsigned short") == 0)
6672 indx = builtin_unsigned_short;
6677 case builtin_signed_long:
6678 case builtin_int: /* FIXME: Size depends upon architecture. */
6680 if (strcmp (name, "signed long") == 0)
6682 indx = builtin_signed_long;
6685 else if (strcmp (name, "int") == 0)
6690 else if (strcmp (name, "long") == 0
6691 || strcmp (name, "long int") == 0)
6693 indx = builtin_long;
6698 case builtin_unsigned_long:
6699 case builtin_unsigned: /* FIXME: Size depends upon architecture. */
6700 case builtin_unsigned_int: /* FIXME: Like builtin_unsigned. */
6701 if (strcmp (name, "unsigned long") == 0
6702 || strcmp (name, "long unsigned int") == 0)
6704 indx = builtin_unsigned_long;
6707 else if (strcmp (name, "unsigned") == 0)
6709 indx = builtin_unsigned;
6712 else if (strcmp (name, "unsigned int") == 0)
6714 indx = builtin_unsigned_int;
6719 case builtin_signed_long_long:
6720 if (strcmp (name, "signed long long") == 0
6721 || strcmp (name, "long long int") == 0)
6725 case builtin_unsigned_long_long:
6726 if (strcmp (name, "unsigned long long") == 0
6727 || strcmp (name, "long long unsigned int") == 0)
6732 if (strcmp (name, "float") == 0)
6736 case builtin_double:
6737 if (strcmp (name, "double") == 0)
6741 case builtin_long_double:
6742 if (strcmp (name, "long double") == 0)
6746 case builtin_long_long_double:
6747 if (strcmp (name, "long long double") == 0)
6756 h = ieee_name_type_hash_lookup (&info->typedefs, name, true, false);
6760 /* See if we have already defined this type with this name. */
6761 localp = type.localp;
6762 for (nt = h->types; nt != NULL; nt = nt->next)
6766 /* If this is a global definition, then we don't need to
6767 do anything here. */
6768 if (! nt->type.localp)
6770 ieee_pop_unused_type (info);
6776 /* This is a duplicate definition, so make this one local. */
6781 /* We need to add a new typedef for this type. */
6783 nt = (struct ieee_name_type *) xmalloc (sizeof *nt);
6784 memset (nt, 0, sizeof *nt);
6787 nt->type.name = name;
6788 nt->type.localp = localp;
6789 nt->kind = DEBUG_KIND_ILLEGAL;
6791 nt->next = h->types;
6796 /* This is one of the builtin typedefs, so we don't need to
6797 actually define it. */
6798 ieee_pop_unused_type (info);
6802 indx = ieee_pop_type (info);
6804 if (! ieee_define_named_type (info, name, (unsigned int) -1, type.size,
6805 type.unsignedp, localp,
6806 (struct ieee_buflist *) NULL)
6807 || ! ieee_write_number (info, 'T')
6808 || ! ieee_write_number (info, indx))
6811 /* Remove the type we just added to the type stack. This should not
6812 be ieee_pop_unused_type, since the type is used, we just don't
6814 (void) ieee_pop_type (info);
6819 /* Output a tag for a type. We don't have to do anything here. */
6826 struct ieee_handle *info = (struct ieee_handle *) p;
6828 /* This should not be ieee_pop_unused_type, since we want the type
6830 (void) ieee_pop_type (info);
6834 /* Output an integer constant. */
6837 ieee_int_constant (p, name, val)
6846 /* Output a floating point constant. */
6849 ieee_float_constant (p, name, val)
6858 /* Output a typed constant. */
6861 ieee_typed_constant (p, name, val)
6866 struct ieee_handle *info = (struct ieee_handle *) p;
6869 ieee_pop_unused_type (info);
6873 /* Output a variable. */
6876 ieee_variable (p, name, kind, val)
6879 enum debug_var_kind kind;
6882 struct ieee_handle *info = (struct ieee_handle *) p;
6883 unsigned int name_indx;
6886 unsigned int type_indx;
6890 size = info->type_stack->type.size;
6891 referencep = info->type_stack->type.referencep;
6892 type_indx = ieee_pop_type (info);
6894 assert (! ieee_buffer_emptyp (&info->vars));
6895 if (! ieee_change_buffer (info, &info->vars))
6898 name_indx = info->name_indx;
6901 /* Write out an NN and an ATN record for this variable. */
6902 if (! ieee_write_byte (info, (int) ieee_nn_record)
6903 || ! ieee_write_number (info, name_indx)
6904 || ! ieee_write_id (info, name)
6905 || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
6906 || ! ieee_write_number (info, name_indx)
6907 || ! ieee_write_number (info, type_indx))
6915 if (! ieee_write_number (info, 8)
6916 || ! ieee_add_range (info, false, val, val + size))
6922 if (! ieee_write_number (info, 3)
6923 || ! ieee_add_range (info, false, val, val + size))
6928 case DEBUG_LOCAL_STATIC:
6929 if (! ieee_write_number (info, 3)
6930 || ! ieee_add_range (info, false, val, val + size))
6936 if (! ieee_write_number (info, 1)
6937 || ! ieee_write_number (info, val))
6942 case DEBUG_REGISTER:
6943 if (! ieee_write_number (info, 2)
6944 || ! ieee_write_number (info,
6945 ieee_genreg_to_regno (info->abfd, val)))
6954 if (! ieee_write_asn (info, name_indx, val))
6958 /* If this is really a reference type, then we just output it with
6959 pointer type, and must now output a C++ record indicating that it
6960 is really reference type. */
6965 nindx = info->name_indx;
6968 /* If this is a global variable, we want to output the misc
6969 record in the C++ misc record block. Otherwise, we want to
6970 output it just after the variable definition, which is where
6971 the current buffer is. */
6974 if (! ieee_change_buffer (info, &info->cxx))
6978 if (! ieee_write_byte (info, (int) ieee_nn_record)
6979 || ! ieee_write_number (info, nindx)
6980 || ! ieee_write_id (info, "")
6981 || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
6982 || ! ieee_write_number (info, nindx)
6983 || ! ieee_write_number (info, 0)
6984 || ! ieee_write_number (info, 62)
6985 || ! ieee_write_number (info, 80)
6986 || ! ieee_write_number (info, 3)
6987 || ! ieee_write_asn (info, nindx, 'R')
6988 || ! ieee_write_asn (info, nindx, refflag)
6989 || ! ieee_write_atn65 (info, nindx, name))
6996 /* Start outputting information for a function. */
6999 ieee_start_function (p, name, global)
7004 struct ieee_handle *info = (struct ieee_handle *) p;
7006 unsigned int retindx, typeindx;
7008 referencep = info->type_stack->type.referencep;
7009 retindx = ieee_pop_type (info);
7011 /* Besides recording a BB4 or BB6 block, we record the type of the
7012 function in the BB1 typedef block. We can't write out the full
7013 type until we have seen all the parameters, so we accumulate it
7014 in info->fntype and info->fnargs. */
7015 if (! ieee_buffer_emptyp (&info->fntype))
7017 /* FIXME: This might happen someday if we support nested
7022 info->fnname = name;
7024 /* An attribute of 0x40 means that the push mask is unknown. */
7025 if (! ieee_define_named_type (info, name, (unsigned int) -1, 0, false, true,
7027 || ! ieee_write_number (info, 'x')
7028 || ! ieee_write_number (info, 0x40)
7029 || ! ieee_write_number (info, 0)
7030 || ! ieee_write_number (info, 0)
7031 || ! ieee_write_number (info, retindx))
7034 typeindx = ieee_pop_type (info);
7036 if (! ieee_init_buffer (info, &info->fnargs))
7038 info->fnargcount = 0;
7040 /* If the function return value is actually a reference type, we
7041 must add a record indicating that. */
7046 nindx = info->name_indx;
7048 if (! ieee_change_buffer (info, &info->cxx)
7049 || ! ieee_write_byte (info, (int) ieee_nn_record)
7050 || ! ieee_write_number (info, nindx)
7051 || ! ieee_write_id (info, "")
7052 || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
7053 || ! ieee_write_number (info, nindx)
7054 || ! ieee_write_number (info, 0)
7055 || ! ieee_write_number (info, 62)
7056 || ! ieee_write_number (info, 80)
7057 || ! ieee_write_number (info, 3)
7058 || ! ieee_write_asn (info, nindx, 'R')
7059 || ! ieee_write_asn (info, nindx, global ? 0 : 1)
7060 || ! ieee_write_atn65 (info, nindx, name))
7064 assert (! ieee_buffer_emptyp (&info->vars));
7065 if (! ieee_change_buffer (info, &info->vars))
7068 /* The address is written out as the first block. */
7070 ++info->block_depth;
7072 return (ieee_write_byte (info, (int) ieee_bb_record_enum)
7073 && ieee_write_byte (info, global ? 4 : 6)
7074 && ieee_write_number (info, 0)
7075 && ieee_write_id (info, name)
7076 && ieee_write_number (info, 0)
7077 && ieee_write_number (info, typeindx));
7080 /* Add a function parameter. This will normally be called before the
7081 first block, so we postpone them until we see the block. */
7084 ieee_function_parameter (p, name, kind, val)
7087 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 (info)
7122 struct ieee_handle *info;
7124 struct ieee_pending_parm *m;
7125 unsigned int refcount;
7128 for (m = info->pending_parms; m != NULL; m = m->next)
7130 enum debug_var_kind vkind;
7137 case DEBUG_PARM_STACK:
7138 case DEBUG_PARM_REFERENCE:
7139 vkind = DEBUG_LOCAL;
7141 case DEBUG_PARM_REG:
7142 case DEBUG_PARM_REF_REG:
7143 vkind = DEBUG_REGISTER;
7147 if (! ieee_push_type (info, m->type, 0, false, false))
7149 info->type_stack->type.referencep = m->referencep;
7152 if (! ieee_variable ((PTR) info, m->name, vkind, m->val))
7156 /* If there are any reference parameters, we need to output a
7157 miscellaneous record indicating them. */
7160 unsigned int nindx, varindx;
7162 /* FIXME: The MRI compiler outputs the demangled function name
7163 here, but we are outputting the mangled name. */
7164 nindx = info->name_indx;
7166 if (! ieee_change_buffer (info, &info->vars)
7167 || ! ieee_write_byte (info, (int) ieee_nn_record)
7168 || ! ieee_write_number (info, nindx)
7169 || ! ieee_write_id (info, "")
7170 || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
7171 || ! ieee_write_number (info, nindx)
7172 || ! ieee_write_number (info, 0)
7173 || ! ieee_write_number (info, 62)
7174 || ! ieee_write_number (info, 80)
7175 || ! ieee_write_number (info, refcount + 3)
7176 || ! ieee_write_asn (info, nindx, 'B')
7177 || ! ieee_write_atn65 (info, nindx, info->fnname)
7178 || ! ieee_write_asn (info, nindx, 0))
7180 for (m = info->pending_parms, varindx = 1;
7182 m = m->next, varindx++)
7186 if (! ieee_write_asn (info, nindx, varindx))
7192 m = info->pending_parms;
7195 struct ieee_pending_parm *next;
7202 info->pending_parms = NULL;
7207 /* Start a block. If this is the first block, we output the address
7208 to finish the BB4 or BB6, and then output the function parameters. */
7211 ieee_start_block (p, addr)
7215 struct ieee_handle *info = (struct ieee_handle *) p;
7217 if (! ieee_change_buffer (info, &info->vars))
7220 if (info->block_depth == 1)
7222 if (! ieee_write_number (info, addr)
7223 || ! ieee_output_pending_parms (info))
7228 if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
7229 || ! ieee_write_byte (info, 6)
7230 || ! ieee_write_number (info, 0)
7231 || ! ieee_write_id (info, "")
7232 || ! ieee_write_number (info, 0)
7233 || ! ieee_write_number (info, 0)
7234 || ! ieee_write_number (info, addr))
7238 if (! ieee_start_range (info, addr))
7241 ++info->block_depth;
7249 ieee_end_block (p, addr)
7253 struct ieee_handle *info = (struct ieee_handle *) p;
7255 /* The address we are given is the end of the block, but IEEE seems
7256 to want to the address of the last byte in the block, so we
7258 if (! ieee_change_buffer (info, &info->vars)
7259 || ! ieee_write_byte (info, (int) ieee_be_record_enum)
7260 || ! ieee_write_number (info, addr - 1))
7263 if (! ieee_end_range (info, addr))
7266 --info->block_depth;
7268 if (addr > info->highaddr)
7269 info->highaddr = addr;
7274 /* End a function. */
7277 ieee_end_function (p)
7280 struct ieee_handle *info = (struct ieee_handle *) p;
7282 assert (info->block_depth == 1);
7284 --info->block_depth;
7286 /* Now we can finish up fntype, and add it to the typdef section.
7287 At this point, fntype is the 'x' type up to the argument count,
7288 and fnargs is the argument types. We must add the argument
7289 count, and we must add the level. FIXME: We don't record varargs
7290 functions correctly. In fact, stabs debugging does not give us
7291 enough information to do so. */
7292 if (! ieee_change_buffer (info, &info->fntype)
7293 || ! ieee_write_number (info, info->fnargcount)
7294 || ! ieee_change_buffer (info, &info->fnargs)
7295 || ! ieee_write_number (info, 0))
7298 /* Make sure the typdef block has been started. */
7299 if (ieee_buffer_emptyp (&info->types))
7301 if (! ieee_change_buffer (info, &info->types)
7302 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
7303 || ! ieee_write_byte (info, 1)
7304 || ! ieee_write_number (info, 0)
7305 || ! ieee_write_id (info, info->modname))
7309 if (! ieee_append_buffer (info, &info->types, &info->fntype)
7310 || ! ieee_append_buffer (info, &info->types, &info->fnargs))
7313 info->fnname = NULL;
7314 if (! ieee_init_buffer (info, &info->fntype)
7315 || ! ieee_init_buffer (info, &info->fnargs))
7317 info->fnargcount = 0;
7322 /* Record line number information. */
7325 ieee_lineno (p, filename, lineno, addr)
7327 const char *filename;
7328 unsigned long lineno;
7331 struct ieee_handle *info = (struct ieee_handle *) p;
7333 assert (info->filename != NULL);
7335 /* The HP simulator seems to get confused when more than one line is
7336 listed for the same address, at least if they are in different
7337 files. We handle this by always listing the last line for a
7338 given address, since that seems to be the one that gdb uses. */
7339 if (info->pending_lineno_filename != NULL
7340 && addr != info->pending_lineno_addr)
7342 /* Make sure we have a line number block. */
7343 if (! ieee_buffer_emptyp (&info->linenos))
7345 if (! ieee_change_buffer (info, &info->linenos))
7350 info->lineno_name_indx = info->name_indx;
7352 if (! ieee_change_buffer (info, &info->linenos)
7353 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
7354 || ! ieee_write_byte (info, 5)
7355 || ! ieee_write_number (info, 0)
7356 || ! ieee_write_id (info, info->filename)
7357 || ! ieee_write_byte (info, (int) ieee_nn_record)
7358 || ! ieee_write_number (info, info->lineno_name_indx)
7359 || ! ieee_write_id (info, ""))
7361 info->lineno_filename = info->filename;
7364 if (strcmp (info->pending_lineno_filename, info->lineno_filename) != 0)
7366 if (strcmp (info->filename, info->lineno_filename) != 0)
7368 /* We were not in the main file. Close the block for the
7370 if (! ieee_write_byte (info, (int) ieee_be_record_enum))
7372 if (strcmp (info->filename, info->pending_lineno_filename) == 0)
7374 /* We need a new NN record, and we aren't about to
7376 info->lineno_name_indx = info->name_indx;
7378 if (! ieee_write_byte (info, (int) ieee_nn_record)
7379 || ! ieee_write_number (info, info->lineno_name_indx)
7380 || ! ieee_write_id (info, ""))
7384 if (strcmp (info->filename, info->pending_lineno_filename) != 0)
7386 /* We are not changing to the main file. Open a block for
7387 the new included file. */
7388 info->lineno_name_indx = info->name_indx;
7390 if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
7391 || ! ieee_write_byte (info, 5)
7392 || ! ieee_write_number (info, 0)
7393 || ! ieee_write_id (info, info->pending_lineno_filename)
7394 || ! ieee_write_byte (info, (int) ieee_nn_record)
7395 || ! ieee_write_number (info, info->lineno_name_indx)
7396 || ! ieee_write_id (info, ""))
7399 info->lineno_filename = info->pending_lineno_filename;
7402 if (! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
7403 || ! ieee_write_number (info, info->lineno_name_indx)
7404 || ! ieee_write_number (info, 0)
7405 || ! ieee_write_number (info, 7)
7406 || ! ieee_write_number (info, info->pending_lineno)
7407 || ! ieee_write_number (info, 0)
7408 || ! ieee_write_asn (info, info->lineno_name_indx,
7409 info->pending_lineno_addr))
7413 info->pending_lineno_filename = filename;
7414 info->pending_lineno = lineno;
7415 info->pending_lineno_addr = addr;