1 /* ieee.c -- Read and write IEEE-695 debugging information.
2 Copyright (C) 1996 Free Software Foundation, Inc.
3 Written by Ian Lance Taylor <ian@cygnus.com>.
5 This file is part of GNU Binutils.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22 /* This file 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;
157 /* Whether we have seen a BB1 or BB2. */
158 boolean saw_filename;
160 struct ieee_vars vars;
161 /* The global variables, after a global typedef block. */
162 struct ieee_vars *global_vars;
164 struct ieee_types types;
165 /* The global types, after a global typedef block. */
166 struct ieee_types *global_types;
167 /* The list of tagged structs. */
168 struct ieee_tag *tags;
171 /* Basic builtin types, not including the pointers. */
177 builtin_signed_char = 2,
178 builtin_unsigned_char = 3,
179 builtin_signed_short_int = 4,
180 builtin_unsigned_short_int = 5,
181 builtin_signed_long = 6,
182 builtin_unsigned_long = 7,
183 builtin_signed_long_long = 8,
184 builtin_unsigned_long_long = 9,
187 builtin_long_double = 12,
188 builtin_long_long_double = 13,
189 builtin_quoted_string = 14,
190 builtin_instruction_address = 15,
192 builtin_unsigned = 17,
193 builtin_unsigned_int = 18,
197 builtin_unsigned_short = 22,
198 builtin_short_int = 23,
199 builtin_signed_short = 24,
200 builtin_bcd_float = 25
203 /* These are the values found in the derivation flags of a 'b'
204 component record of a 'T' type extension record in a C++ pmisc
205 record. These are bitmasks. */
207 /* Set for a private base class, clear for a public base class.
208 Protected base classes are not supported. */
209 #define BASEFLAGS_PRIVATE (0x1)
210 /* Set for a virtual base class. */
211 #define BASEFLAGS_VIRTUAL (0x2)
212 /* Set for a friend class, clear for a base class. */
213 #define BASEFLAGS_FRIEND (0x10)
215 /* These are the values found in the specs flags of a 'd', 'm', or 'v'
216 component record of a 'T' type extension record in a C++ pmisc
217 record. The same flags are used for a 'M' record in a C++ pmisc
220 /* The lower two bits hold visibility information. */
221 #define CXXFLAGS_VISIBILITY (0x3)
222 /* This value in the lower two bits indicates a public member. */
223 #define CXXFLAGS_VISIBILITY_PUBLIC (0x0)
224 /* This value in the lower two bits indicates a private member. */
225 #define CXXFLAGS_VISIBILITY_PRIVATE (0x1)
226 /* This value in the lower two bits indicates a protected member. */
227 #define CXXFLAGS_VISIBILITY_PROTECTED (0x2)
228 /* Set for a static member. */
229 #define CXXFLAGS_STATIC (0x4)
230 /* Set for a virtual override. */
231 #define CXXFLAGS_OVERRIDE (0x8)
232 /* Set for a friend function. */
233 #define CXXFLAGS_FRIEND (0x10)
234 /* Set for a const function. */
235 #define CXXFLAGS_CONST (0x20)
236 /* Set for a volatile function. */
237 #define CXXFLAGS_VOLATILE (0x40)
238 /* Set for an overloaded function. */
239 #define CXXFLAGS_OVERLOADED (0x80)
240 /* Set for an operator function. */
241 #define CXXFLAGS_OPERATOR (0x100)
242 /* Set for a constructor or destructor. */
243 #define CXXFLAGS_CTORDTOR (0x400)
244 /* Set for a constructor. */
245 #define CXXFLAGS_CTOR (0x200)
246 /* Set for an inline function. */
247 #define CXXFLAGS_INLINE (0x800)
249 /* Local functions. */
251 static void ieee_error
252 PARAMS ((struct ieee_info *, const bfd_byte *, const char *));
253 static void ieee_eof PARAMS ((struct ieee_info *));
254 static char *savestring PARAMS ((const char *, unsigned long));
255 static boolean ieee_read_number
256 PARAMS ((struct ieee_info *, const bfd_byte **, bfd_vma *));
257 static boolean ieee_read_optional_number
258 PARAMS ((struct ieee_info *, const bfd_byte **, bfd_vma *, boolean *));
259 static boolean ieee_read_id
260 PARAMS ((struct ieee_info *, const bfd_byte **, const char **,
262 static boolean ieee_read_optional_id
263 PARAMS ((struct ieee_info *, const bfd_byte **, const char **,
264 unsigned long *, boolean *));
265 static boolean ieee_read_expression
266 PARAMS ((struct ieee_info *, const bfd_byte **, bfd_vma *));
267 static debug_type ieee_builtin_type
268 PARAMS ((struct ieee_info *, const bfd_byte *, unsigned int));
269 static boolean ieee_alloc_type
270 PARAMS ((struct ieee_info *, unsigned int, boolean));
271 static boolean ieee_read_type_index
272 PARAMS ((struct ieee_info *, const bfd_byte **, debug_type *));
273 static int ieee_regno_to_genreg PARAMS ((bfd *, int));
274 static int ieee_genreg_to_regno PARAMS ((bfd *, int));
275 static boolean parse_ieee_bb PARAMS ((struct ieee_info *, const bfd_byte **));
276 static boolean parse_ieee_be PARAMS ((struct ieee_info *, const bfd_byte **));
277 static boolean parse_ieee_nn PARAMS ((struct ieee_info *, const bfd_byte **));
278 static boolean parse_ieee_ty PARAMS ((struct ieee_info *, const bfd_byte **));
279 static boolean parse_ieee_atn PARAMS ((struct ieee_info *, const bfd_byte **));
280 static boolean ieee_read_cxx_misc
281 PARAMS ((struct ieee_info *, const bfd_byte **, unsigned long));
282 static boolean ieee_read_cxx_class
283 PARAMS ((struct ieee_info *, const bfd_byte **, unsigned long));
284 static boolean ieee_read_cxx_defaults
285 PARAMS ((struct ieee_info *, const bfd_byte **, unsigned long));
286 static boolean ieee_read_reference
287 PARAMS ((struct ieee_info *, const bfd_byte **));
288 static boolean ieee_require_asn
289 PARAMS ((struct ieee_info *, const bfd_byte **, bfd_vma *));
290 static boolean ieee_require_atn65
291 PARAMS ((struct ieee_info *, const bfd_byte **, const char **,
294 /* Report an error in the IEEE debugging information. */
297 ieee_error (info, p, s)
298 struct ieee_info *info;
303 fprintf (stderr, "%s: 0x%lx: %s (0x%x)\n", bfd_get_filename (info->abfd),
304 (unsigned long) (p - info->bytes), s, *p);
306 fprintf (stderr, "%s: %s\n", bfd_get_filename (info->abfd), s);
309 /* Report an unexpected EOF in the IEEE debugging information. */
313 struct ieee_info *info;
315 ieee_error (info, (const bfd_byte *) NULL,
316 "unexpected end of debugging information");
319 /* Save a string in memory. */
322 savestring (start, len)
328 ret = (char *) xmalloc (len + 1);
329 memcpy (ret, start, len);
334 /* Read a number which must be present in an IEEE file. */
337 ieee_read_number (info, pp, pv)
338 struct ieee_info *info;
342 return ieee_read_optional_number (info, pp, pv, (boolean *) NULL);
345 /* Read a number in an IEEE file. If ppresent is not NULL, the number
346 need not be there. */
349 ieee_read_optional_number (info, pp, pv, ppresent)
350 struct ieee_info *info;
355 ieee_record_enum_type b;
357 if (*pp >= info->pend)
359 if (ppresent != NULL)
368 b = (ieee_record_enum_type) **pp;
371 if (b <= ieee_number_end_enum)
374 if (ppresent != NULL)
379 if (b >= ieee_number_repeat_start_enum && b <= ieee_number_repeat_end_enum)
383 i = (int) b - (int) ieee_number_repeat_start_enum;
384 if (*pp + i - 1 >= info->pend)
398 if (ppresent != NULL)
404 if (ppresent != NULL)
411 ieee_error (info, *pp - 1, "invalid number");
415 /* Read a required string from an IEEE file. */
418 ieee_read_id (info, pp, pname, pnamlen)
419 struct ieee_info *info;
422 unsigned long *pnamlen;
424 return ieee_read_optional_id (info, pp, pname, pnamlen, (boolean *) NULL);
427 /* Read a string from an IEEE file. If ppresent is not NULL, the
428 string is optional. */
431 ieee_read_optional_id (info, pp, pname, pnamlen, ppresent)
432 struct ieee_info *info;
435 unsigned long *pnamlen;
441 if (*pp >= info->pend)
452 else if ((ieee_record_enum_type) b == ieee_extension_length_1_enum)
457 else if ((ieee_record_enum_type) b == ieee_extension_length_2_enum)
459 len = (**pp << 8) + (*pp)[1];
464 if (ppresent != NULL)
470 ieee_error (info, *pp - 1, "invalid string length");
474 if ((unsigned long) (info->pend - *pp) < len)
480 *pname = (const char *) *pp;
484 if (ppresent != NULL)
490 /* Read an expression from an IEEE file. Since this code is only used
491 to parse debugging information, I haven't bothered to write a full
492 blown IEEE expression parser. I've only thrown in the things I've
493 seen in debugging information. This can be easily extended if
497 ieee_read_expression (info, pp, pv)
498 struct ieee_info *info;
502 const bfd_byte *expr_start;
503 #define EXPR_STACK_SIZE (10)
504 bfd_vma expr_stack[EXPR_STACK_SIZE];
513 const bfd_byte *start;
516 ieee_record_enum_type c;
520 if (! ieee_read_optional_number (info, pp, &val, &present))
525 if (esp - expr_stack >= EXPR_STACK_SIZE)
527 ieee_error (info, start, "expression stack overflow");
534 c = (ieee_record_enum_type) **pp;
536 if (c >= ieee_module_beginning_enum)
547 ieee_error (info, start, "unsupported IEEE expression operator");
550 case ieee_variable_R_enum:
555 if (! ieee_read_number (info, pp, &indx))
557 for (s = info->abfd->sections; s != NULL; s = s->next)
558 if ((bfd_vma) s->target_index == indx)
562 ieee_error (info, start, "unknown section");
566 if (esp - expr_stack >= EXPR_STACK_SIZE)
568 ieee_error (info, start, "expression stack overflow");
572 *esp++ = bfd_get_section_vma (info->abfd, s);
576 case ieee_function_plus_enum:
577 case ieee_function_minus_enum:
581 if (esp - expr_stack < 2)
583 ieee_error (info, start, "expression stack underflow");
595 if (esp - 1 != expr_stack)
597 ieee_error (info, expr_start, "expression stack mismatch");
606 /* Return an IEEE builtin type. */
609 ieee_builtin_type (info, p, indx)
610 struct ieee_info *info;
618 if (indx < BUILTIN_TYPE_COUNT
619 && info->types.builtins[indx] != DEBUG_TYPE_NULL)
620 return info->types.builtins[indx];
622 dhandle = info->dhandle;
624 if (indx >= 32 && indx < 64)
626 type = debug_make_pointer_type (dhandle,
627 ieee_builtin_type (info, p, indx - 32));
628 assert (indx < BUILTIN_TYPE_COUNT);
629 info->types.builtins[indx] = type;
633 switch ((enum builtin_types) indx)
636 ieee_error (info, p, "unknown builtin type");
639 case builtin_unknown:
640 type = debug_make_void_type (dhandle);
645 type = debug_make_void_type (dhandle);
649 case builtin_signed_char:
650 type = debug_make_int_type (dhandle, 1, false);
651 name = "signed char";
654 case builtin_unsigned_char:
655 type = debug_make_int_type (dhandle, 1, true);
656 name = "unsigned char";
659 case builtin_signed_short_int:
660 type = debug_make_int_type (dhandle, 2, false);
661 name = "signed short int";
664 case builtin_unsigned_short_int:
665 type = debug_make_int_type (dhandle, 2, true);
666 name = "unsigned short int";
669 case builtin_signed_long:
670 type = debug_make_int_type (dhandle, 4, false);
671 name = "signed long";
674 case builtin_unsigned_long:
675 type = debug_make_int_type (dhandle, 4, true);
676 name = "unsigned long";
679 case builtin_signed_long_long:
680 type = debug_make_int_type (dhandle, 8, false);
681 name = "signed long long";
684 case builtin_unsigned_long_long:
685 type = debug_make_int_type (dhandle, 8, true);
686 name = "unsigned long long";
690 type = debug_make_float_type (dhandle, 4);
695 type = debug_make_float_type (dhandle, 8);
699 case builtin_long_double:
700 /* FIXME: The size for this type should depend upon the
702 type = debug_make_float_type (dhandle, 12);
703 name = "long double";
706 case builtin_long_long_double:
707 type = debug_make_float_type (dhandle, 16);
708 name = "long long double";
711 case builtin_quoted_string:
712 type = debug_make_array_type (dhandle,
713 ieee_builtin_type (info, p,
716 ieee_builtin_type (info, p,
720 name = "QUOTED STRING";
723 case builtin_instruction_address:
724 /* FIXME: This should be a code address. */
725 type = debug_make_int_type (dhandle, 4, true);
726 name = "instruction address";
730 /* FIXME: The size for this type should depend upon the
732 type = debug_make_int_type (dhandle, 4, false);
736 case builtin_unsigned:
737 /* FIXME: The size for this type should depend upon the
739 type = debug_make_int_type (dhandle, 4, true);
743 case builtin_unsigned_int:
744 /* FIXME: The size for this type should depend upon the
746 type = debug_make_int_type (dhandle, 4, true);
747 name = "unsigned int";
751 type = debug_make_int_type (dhandle, 1, false);
756 type = debug_make_int_type (dhandle, 4, false);
761 type = debug_make_int_type (dhandle, 2, false);
765 case builtin_unsigned_short:
766 type = debug_make_int_type (dhandle, 2, true);
767 name = "unsigned short";
770 case builtin_short_int:
771 type = debug_make_int_type (dhandle, 2, false);
775 case builtin_signed_short:
776 type = debug_make_int_type (dhandle, 2, false);
777 name = "signed short";
780 case builtin_bcd_float:
781 ieee_error (info, p, "BCD float type not supported");
786 type = debug_name_type (dhandle, name, type);
788 assert (indx < BUILTIN_TYPE_COUNT);
790 info->types.builtins[indx] = type;
795 /* Allocate more space in the type table. If ref is true, this is a
796 reference to the type; if it is not already defined, we should set
797 up an indirect type. */
800 ieee_alloc_type (info, indx, ref)
801 struct ieee_info *info;
806 register struct ieee_type *t;
807 struct ieee_type *tend;
809 if (indx >= info->types.alloc)
811 nalloc = info->types.alloc;
814 while (indx >= nalloc)
817 info->types.types = ((struct ieee_type *)
818 xrealloc (info->types.types,
819 nalloc * sizeof *info->types.types));
821 memset (info->types.types + info->types.alloc, 0,
822 (nalloc - info->types.alloc) * sizeof *info->types.types);
824 tend = info->types.types + nalloc;
825 for (t = info->types.types + info->types.alloc; t < tend; t++)
826 t->type = DEBUG_TYPE_NULL;
828 info->types.alloc = nalloc;
833 t = info->types.types + indx;
836 t->pslot = (debug_type *) xmalloc (sizeof *t->pslot);
837 *t->pslot = DEBUG_TYPE_NULL;
838 t->type = debug_make_indirect_type (info->dhandle, t->pslot,
839 (const char *) NULL);
848 /* Read a type index and return the corresponding type. */
851 ieee_read_type_index (info, pp, ptype)
852 struct ieee_info *info;
856 const bfd_byte *start;
861 if (! ieee_read_number (info, pp, &indx))
866 *ptype = ieee_builtin_type (info, start, indx);
873 if (! ieee_alloc_type (info, indx, true))
876 *ptype = info->types.types[indx].type;
881 /* Parse IEEE debugging information for a file. This is passed the
882 bytes which compose the Debug Information Part of an IEEE file. */
885 parse_ieee (dhandle, abfd, bytes, len)
888 const bfd_byte *bytes;
891 struct ieee_info info;
893 const bfd_byte *p, *pend;
895 info.dhandle = dhandle;
898 info.pend = bytes + len;
899 info.blockstack.bsp = info.blockstack.stack;
900 info.saw_filename = false;
902 info.vars.vars = NULL;
903 info.types.alloc = 0;
904 info.types.types = NULL;
906 for (i = 0; i < BUILTIN_TYPE_COUNT; i++)
907 info.types.builtins[i] = DEBUG_TYPE_NULL;
913 const bfd_byte *record_start;
914 ieee_record_enum_type c;
918 c = (ieee_record_enum_type) *p++;
920 if (c == ieee_at_record_enum)
921 c = (ieee_record_enum_type) (((unsigned int) c << 8) | *p++);
923 if (c <= ieee_number_repeat_end_enum)
925 ieee_error (&info, record_start, "unexpected number");
932 ieee_error (&info, record_start, "unexpected record type");
935 case ieee_bb_record_enum:
936 if (! parse_ieee_bb (&info, &p))
940 case ieee_be_record_enum:
941 if (! parse_ieee_be (&info, &p))
946 if (! parse_ieee_nn (&info, &p))
950 case ieee_ty_record_enum:
951 if (! parse_ieee_ty (&info, &p))
955 case ieee_atn_record_enum:
956 if (! parse_ieee_atn (&info, &p))
962 if (info.blockstack.bsp != info.blockstack.stack)
964 ieee_error (&info, (const bfd_byte *) NULL,
965 "blocks left on stack at end");
972 /* Handle an IEEE BB record. */
975 parse_ieee_bb (info, pp)
976 struct ieee_info *info;
979 const bfd_byte *block_start;
983 unsigned long namlen;
993 if (! ieee_read_number (info, pp, &size)
994 || ! ieee_read_id (info, pp, &name, &namlen))
997 fnindx = (unsigned int) -1;
1003 /* BB1: Type definitions local to a module. */
1004 namcopy = savestring (name, namlen);
1005 if (namcopy == NULL)
1007 if (! debug_set_filename (info->dhandle, namcopy))
1009 info->saw_filename = true;
1011 /* Discard any variables or types we may have seen before. */
1012 if (info->vars.vars != NULL)
1013 free (info->vars.vars);
1014 info->vars.vars = NULL;
1015 info->vars.alloc = 0;
1016 if (info->types.types != NULL)
1017 free (info->types.types);
1018 info->types.types = NULL;
1019 info->types.alloc = 0;
1021 /* Initialize the types to the global types. */
1022 if (info->global_types != NULL)
1024 info->types.alloc = info->global_types->alloc;
1025 info->types.types = ((struct ieee_type *)
1026 xmalloc (info->types.alloc
1027 * sizeof (*info->types.types)));
1028 memcpy (info->types.types, info->global_types->types,
1029 info->types.alloc * sizeof (*info->types.types));
1035 /* BB2: Global type definitions. The name is supposed to be
1036 empty, but we don't check. */
1037 if (! debug_set_filename (info->dhandle, "*global*"))
1039 info->saw_filename = true;
1043 /* BB3: High level module block begin. We don't have to do
1044 anything here. The name is supposed to be the same as for
1045 the BB1, but we don't check. */
1049 /* BB4: Global function. */
1051 bfd_vma stackspace, typindx, offset;
1052 debug_type return_type;
1054 if (! ieee_read_number (info, pp, &stackspace)
1055 || ! ieee_read_number (info, pp, &typindx)
1056 || ! ieee_read_expression (info, pp, &offset))
1059 /* We have no way to record the stack space. FIXME. */
1063 return_type = ieee_builtin_type (info, block_start, typindx);
1064 if (return_type == DEBUG_TYPE_NULL)
1070 if (! ieee_alloc_type (info, typindx, true))
1073 return_type = info->types.types[typindx].type;
1074 if (debug_get_type_kind (info->dhandle, return_type)
1075 == DEBUG_KIND_FUNCTION)
1076 return_type = debug_get_return_type (info->dhandle,
1080 namcopy = savestring (name, namlen);
1081 if (namcopy == NULL)
1083 if (! debug_record_function (info->dhandle, namcopy, return_type,
1090 /* BB5: File name for source line numbers. */
1094 /* We ignore the date and time. FIXME. */
1095 for (i = 0; i < 6; i++)
1100 if (! ieee_read_optional_number (info, pp, &ignore, &present))
1106 namcopy = savestring (name, namlen);
1107 if (namcopy == NULL)
1109 if (! debug_start_source (info->dhandle, namcopy))
1115 /* BB6: Local function or block. */
1117 bfd_vma stackspace, typindx, offset;
1119 if (! ieee_read_number (info, pp, &stackspace)
1120 || ! ieee_read_number (info, pp, &typindx)
1121 || ! ieee_read_expression (info, pp, &offset))
1124 /* We have no way to record the stack space. FIXME. */
1128 if (! debug_start_block (info->dhandle, offset))
1130 /* Change b to indicate that this is a block
1131 rather than a function. */
1136 /* The MRI C++ compiler will output a fake function named
1137 __XRYCPP to hold C++ debugging information. We skip
1138 that function. This is not crucial, but it makes
1139 converting from IEEE to other debug formats work
1141 if (strncmp (name, "__XRYCPP", namlen) == 0)
1145 debug_type return_type;
1149 return_type = ieee_builtin_type (info, block_start,
1151 if (return_type == NULL)
1157 if (! ieee_alloc_type (info, typindx, true))
1160 return_type = info->types.types[typindx].type;
1161 if (debug_get_type_kind (info->dhandle, return_type)
1162 == DEBUG_KIND_FUNCTION)
1163 return_type = debug_get_return_type (info->dhandle,
1167 namcopy = savestring (name, namlen);
1168 if (namcopy == NULL)
1170 if (! debug_record_function (info->dhandle, namcopy,
1171 return_type, false, offset))
1179 /* BB10: Assembler module scope. In the normal case, we
1180 completely ignore all this information. FIXME. */
1182 const char *inam, *vstr;
1183 unsigned long inamlen, vstrlen;
1188 if (! info->saw_filename)
1190 namcopy = savestring (name, namlen);
1191 if (namcopy == NULL)
1193 if (! debug_set_filename (info->dhandle, namcopy))
1195 info->saw_filename = true;
1198 if (! ieee_read_id (info, pp, &inam, &inamlen)
1199 || ! ieee_read_number (info, pp, &tool_type)
1200 || ! ieee_read_optional_id (info, pp, &vstr, &vstrlen, &present))
1202 for (i = 0; i < 6; i++)
1206 if (! ieee_read_optional_number (info, pp, &ignore, &present))
1215 /* BB11: Module section. We completely ignore all this
1216 information. FIXME. */
1218 bfd_vma sectype, secindx, offset, map;
1221 if (! ieee_read_number (info, pp, §ype)
1222 || ! ieee_read_number (info, pp, &secindx)
1223 || ! ieee_read_expression (info, pp, &offset)
1224 || ! ieee_read_optional_number (info, pp, &map, &present))
1230 ieee_error (info, block_start, "unknown BB type");
1235 /* Push this block on the block stack. */
1237 if (info->blockstack.bsp >= info->blockstack.stack + BLOCKSTACK_SIZE)
1239 ieee_error (info, (const bfd_byte *) NULL, "stack overflow");
1243 info->blockstack.bsp->kind = b;
1245 info->blockstack.bsp->filename = namcopy;
1246 info->blockstack.bsp->fnindx = fnindx;
1247 info->blockstack.bsp->skip = skip;
1248 ++info->blockstack.bsp;
1253 /* Handle an IEEE BE record. */
1256 parse_ieee_be (info, pp)
1257 struct ieee_info *info;
1258 const bfd_byte **pp;
1262 if (info->blockstack.bsp <= info->blockstack.stack)
1264 ieee_error (info, *pp, "stack underflow");
1267 --info->blockstack.bsp;
1269 switch (info->blockstack.bsp->kind)
1272 /* When we end the global typedefs block, we copy out the the
1273 contents of info->vars. This is because the variable indices
1274 may be reused in the local blocks. However, we need to
1275 preserve them so that we can locate a function returning a
1276 reference variable whose type is named in the global typedef
1278 info->global_vars = ((struct ieee_vars *)
1279 xmalloc (sizeof *info->global_vars));
1280 info->global_vars->alloc = info->vars.alloc;
1281 info->global_vars->vars = ((struct ieee_var *)
1282 xmalloc (info->vars.alloc
1283 * sizeof (*info->vars.vars)));
1284 memcpy (info->global_vars->vars, info->vars.vars,
1285 info->vars.alloc * sizeof (*info->vars.vars));
1287 /* We also copy out the non builtin parts of info->types, since
1288 the types are discarded when we start a new block. */
1289 info->global_types = ((struct ieee_types *)
1290 xmalloc (sizeof *info->global_types));
1291 info->global_types->alloc = info->types.alloc;
1292 info->global_types->types = ((struct ieee_type *)
1293 xmalloc (info->types.alloc
1294 * sizeof (*info->types.types)));
1295 memcpy (info->global_types->types, info->types.types,
1296 info->types.alloc * sizeof (*info->types.types));
1297 memset (info->global_types->builtins, 0,
1298 sizeof (info->global_types->builtins));
1304 if (! ieee_read_expression (info, pp, &offset))
1306 if (! info->blockstack.bsp->skip)
1308 if (! debug_end_function (info->dhandle, offset + 1))
1314 /* This is BE6 when BB6 started a block rather than a local
1316 if (! ieee_read_expression (info, pp, &offset))
1318 if (! debug_end_block (info->dhandle, offset + 1))
1323 /* When we end a BB5, we look up the stack for the last BB5, if
1324 there is one, so that we can call debug_start_source. */
1325 if (info->blockstack.bsp > info->blockstack.stack)
1327 struct ieee_block *bl;
1329 bl = info->blockstack.bsp;
1335 if (! debug_start_source (info->dhandle, bl->filename))
1340 while (bl != info->blockstack.stack);
1345 if (! ieee_read_expression (info, pp, &offset))
1347 /* We just ignore the module size. FIXME. */
1351 /* Other block types do not have any trailing information. */
1358 /* Parse an NN record. */
1361 parse_ieee_nn (info, pp)
1362 struct ieee_info *info;
1363 const bfd_byte **pp;
1365 const bfd_byte *nn_start;
1368 unsigned long namlen;
1372 if (! ieee_read_number (info, pp, &varindx)
1373 || ! ieee_read_id (info, pp, &name, &namlen))
1378 ieee_error (info, nn_start, "illegal variable index");
1383 if (varindx >= info->vars.alloc)
1387 alloc = info->vars.alloc;
1390 while (varindx >= alloc)
1392 info->vars.vars = ((struct ieee_var *)
1393 xrealloc (info->vars.vars,
1394 alloc * sizeof *info->vars.vars));
1395 memset (info->vars.vars + info->vars.alloc, 0,
1396 (alloc - info->vars.alloc) * sizeof *info->vars.vars);
1397 info->vars.alloc = alloc;
1400 info->vars.vars[varindx].name = name;
1401 info->vars.vars[varindx].namlen = namlen;
1406 /* Parse a TY record. */
1409 parse_ieee_ty (info, pp)
1410 struct ieee_info *info;
1411 const bfd_byte **pp;
1413 const bfd_byte *ty_start, *ty_var_start, *ty_code_start;
1414 bfd_vma typeindx, varindx, tc;
1416 boolean tag, typdef;
1417 debug_type *arg_slots;
1418 unsigned long type_bitsize;
1423 if (! ieee_read_number (info, pp, &typeindx))
1428 ieee_error (info, ty_start, "illegal type index");
1433 if (! ieee_alloc_type (info, typeindx, false))
1438 ieee_error (info, *pp, "unknown TY code");
1445 if (! ieee_read_number (info, pp, &varindx))
1450 ieee_error (info, ty_var_start, "illegal variable index");
1455 if (varindx >= info->vars.alloc || info->vars.vars[varindx].name == NULL)
1457 ieee_error (info, ty_var_start, "undefined variable in TY");
1461 ty_code_start = *pp;
1463 if (! ieee_read_number (info, pp, &tc))
1466 dhandle = info->dhandle;
1475 ieee_error (info, ty_code_start, "unknown TY code");
1479 /* Unknown type, with size. We treat it as int. FIXME. */
1483 if (! ieee_read_number (info, pp, &size))
1485 type = debug_make_int_type (dhandle, size, false);
1489 case 'A': /* Array. */
1490 case 'a': /* FORTRAN array in column/row order. FIXME: Not
1491 distinguished from normal array. */
1493 debug_type ele_type;
1494 bfd_vma lower, upper;
1496 if (! ieee_read_type_index (info, pp, &ele_type)
1497 || ! ieee_read_number (info, pp, &lower)
1498 || ! ieee_read_number (info, pp, &upper))
1500 type = debug_make_array_type (dhandle, ele_type,
1501 ieee_builtin_type (info, ty_code_start,
1504 (bfd_signed_vma) lower,
1505 (bfd_signed_vma) upper,
1511 /* Simple enumeration. */
1517 bfd_signed_vma *vals;
1520 if (! ieee_read_number (info, pp, &size))
1522 /* FIXME: we ignore the enumeration size. */
1525 names = (const char **) xmalloc (alloc * sizeof *names);
1526 memset (names, 0, alloc * sizeof *names);
1531 unsigned long namlen;
1534 if (! ieee_read_optional_id (info, pp, &name, &namlen, &present))
1542 names = ((const char **)
1543 xrealloc (names, alloc * sizeof *names));
1546 names[c] = savestring (name, namlen);
1547 if (names[c] == NULL)
1554 vals = (bfd_signed_vma *) xmalloc (c * sizeof *vals);
1555 for (i = 0; i < c; i++)
1558 type = debug_make_enum_type (dhandle, names, vals);
1564 /* Struct with bit fields. */
1568 debug_field *fields;
1571 if (! ieee_read_number (info, pp, &size))
1575 fields = (debug_field *) xmalloc (alloc * sizeof *fields);
1580 unsigned long namlen;
1583 bfd_vma bitpos, bitsize;
1585 if (! ieee_read_optional_id (info, pp, &name, &namlen, &present))
1589 if (! ieee_read_type_index (info, pp, &ftype)
1590 || ! ieee_read_number (info, pp, &bitpos)
1591 || ! ieee_read_number (info, pp, &bitsize))
1597 fields = ((debug_field *)
1598 xrealloc (fields, alloc * sizeof *fields));
1601 fields[c] = debug_make_field (dhandle, savestring (name, namlen),
1602 ftype, bitpos, bitsize,
1603 DEBUG_VISIBILITY_PUBLIC);
1604 if (fields[c] == NULL)
1611 type = debug_make_struct_type (dhandle, true, size, fields);
1621 bfd_signed_vma *vals;
1625 names = (const char **) xmalloc (alloc * sizeof *names);
1626 vals = (bfd_signed_vma *) xmalloc (alloc * sizeof *names);
1631 unsigned long namlen;
1635 if (! ieee_read_optional_id (info, pp, &name, &namlen, &present))
1639 if (! ieee_read_number (info, pp, &val))
1642 /* If the length of the name is zero, then the value is
1643 actually the size of the enum. We ignore this
1644 information. FIXME. */
1651 names = ((const char **)
1652 xrealloc (names, alloc * sizeof *names));
1653 vals = ((bfd_signed_vma *)
1654 xrealloc (vals, alloc * sizeof *vals));
1657 names[c] = savestring (name, namlen);
1658 if (names[c] == NULL)
1660 vals[c] = (bfd_signed_vma) val;
1666 type = debug_make_enum_type (dhandle, names, vals);
1671 case 'O': /* Small pointer. We don't distinguish small and large
1673 case 'P': /* Large pointer. */
1677 if (! ieee_read_type_index (info, pp, &t))
1679 type = debug_make_pointer_type (dhandle, t);
1686 bfd_vma low, high, signedp, size;
1688 if (! ieee_read_number (info, pp, &low)
1689 || ! ieee_read_number (info, pp, &high)
1690 || ! ieee_read_number (info, pp, &signedp)
1691 || ! ieee_read_number (info, pp, &size))
1694 type = debug_make_range_type (dhandle,
1695 debug_make_int_type (dhandle, size,
1697 (bfd_signed_vma) low,
1698 (bfd_signed_vma) high);
1702 case 'S': /* Struct. */
1703 case 'U': /* Union. */
1707 debug_field *fields;
1710 if (! ieee_read_number (info, pp, &size))
1714 fields = (debug_field *) xmalloc (alloc * sizeof *fields);
1719 unsigned long namlen;
1726 if (! ieee_read_optional_id (info, pp, &name, &namlen, &present))
1730 if (! ieee_read_number (info, pp, &tindx)
1731 || ! ieee_read_number (info, pp, &offset))
1736 ftype = ieee_builtin_type (info, ty_code_start, tindx);
1742 struct ieee_type *t;
1745 if (! ieee_alloc_type (info, tindx, true))
1747 t = info->types.types + tindx;
1749 bitsize = t->bitsize;
1757 fields = ((debug_field *)
1758 xrealloc (fields, alloc * sizeof *fields));
1761 fields[c] = debug_make_field (dhandle, savestring (name, namlen),
1762 ftype, offset, bitsize,
1763 DEBUG_VISIBILITY_PUBLIC);
1764 if (fields[c] == NULL)
1771 type = debug_make_struct_type (dhandle, tc == 'S', size, fields);
1778 if (! ieee_read_type_index (info, pp, &type))
1784 /* Procedure. FIXME: This is an extern declaration, which we
1785 have no way of representing. */
1791 struct ieee_var *pv;
1793 /* FIXME: We ignore the attribute and the argument names. */
1795 if (! ieee_read_number (info, pp, &attr)
1796 || ! ieee_read_type_index (info, pp, &rtype)
1797 || ! ieee_read_number (info, pp, &nargs))
1802 unsigned long namlen;
1804 if (! ieee_read_optional_id (info, pp, &name, &namlen, &present))
1809 pv = info->vars.vars + varindx;
1810 pv->kind = IEEE_EXTERNAL;
1812 && debug_get_type_kind (dhandle, rtype) == DEBUG_KIND_POINTER)
1814 /* Set up the return type as an indirect type pointing to
1815 the variable slot, so that we can change it to a
1816 reference later if appropriate. */
1817 pv->pslot = (debug_type *) xmalloc (sizeof *pv->pslot);
1819 rtype = debug_make_indirect_type (dhandle, pv->pslot,
1820 (const char *) NULL);
1823 type = debug_make_function_type (dhandle, rtype, (debug_type *) NULL,
1829 /* Void. This is not documented, but the MRI compiler emits it. */
1830 type = debug_make_void_type (dhandle);
1834 /* Array with 0 lower bound. */
1839 if (! ieee_read_type_index (info, pp, &etype)
1840 || ! ieee_read_number (info, pp, &high))
1843 type = debug_make_array_type (dhandle, etype,
1844 ieee_builtin_type (info, ty_code_start,
1847 0, (bfd_signed_vma) high, false);
1851 case 'c': /* Complex. */
1852 case 'd': /* Double complex. */
1855 unsigned long namlen;
1857 /* FIXME: I don't know what the name means. */
1859 if (! ieee_read_id (info, pp, &name, &namlen))
1862 type = debug_make_complex_type (dhandle, tc == 'c' ? 4 : 8);
1867 /* Pascal file name. FIXME. */
1868 ieee_error (info, ty_code_start, "Pascal file name not supported");
1872 /* Bitfield type. */
1874 bfd_vma signedp, bitsize, dummy;
1875 const bfd_byte *hold;
1878 if (! ieee_read_number (info, pp, &signedp)
1879 || ! ieee_read_number (info, pp, &bitsize))
1882 /* I think the documentation says that there is a type index,
1883 but some actual files do not have one. */
1885 if (! ieee_read_optional_number (info, pp, &dummy, &present))
1889 /* FIXME: This is just a guess. */
1890 type = debug_make_int_type (dhandle, 4,
1891 signedp ? false : true);
1896 if (! ieee_read_type_index (info, pp, &type))
1899 type_bitsize = bitsize;
1909 if (! ieee_read_number (info, pp, &kind)
1910 || ! ieee_read_type_index (info, pp, &t))
1916 ieee_error (info, ty_start, "unsupported qualifer");
1920 type = debug_make_const_type (dhandle, t);
1924 type = debug_make_volatile_type (dhandle, t);
1936 if (! ieee_read_number (info, pp, &size)
1937 || ! ieee_read_type_index (info, pp, &etype))
1940 /* FIXME: We ignore the size. */
1942 type = debug_make_set_type (dhandle, etype, false);
1947 /* Procedure with compiler dependencies. */
1949 struct ieee_var *pv;
1950 bfd_vma attr, frame_type, push_mask, nargs, level, father;
1952 debug_type *arg_types;
1956 /* FIXME: We ignore some of this information. */
1958 pv = info->vars.vars + varindx;
1960 if (! ieee_read_number (info, pp, &attr)
1961 || ! ieee_read_number (info, pp, &frame_type)
1962 || ! ieee_read_number (info, pp, &push_mask)
1963 || ! ieee_read_type_index (info, pp, &rtype)
1964 || ! ieee_read_number (info, pp, &nargs))
1966 if (nargs == (bfd_vma) -1)
1975 arg_types = ((debug_type *)
1976 xmalloc ((nargs + 1) * sizeof *arg_types));
1977 for (i = 0; i < nargs; i++)
1978 if (! ieee_read_type_index (info, pp, arg_types + i))
1981 /* If the last type is pointer to void, this is really a
1982 varargs function. */
1988 last = arg_types[nargs - 1];
1989 if (debug_get_type_kind (dhandle, last) == DEBUG_KIND_POINTER
1990 && (debug_get_type_kind (dhandle,
1991 debug_get_target_type (dhandle,
1993 == DEBUG_KIND_VOID))
2000 /* If there are any pointer arguments, turn them into
2001 indirect types in case we later need to convert them to
2003 for (i = 0; i < nargs; i++)
2005 if (debug_get_type_kind (dhandle, arg_types[i])
2006 == DEBUG_KIND_POINTER)
2008 if (arg_slots == NULL)
2010 arg_slots = ((debug_type *)
2011 xmalloc (nargs * sizeof *arg_slots));
2012 memset (arg_slots, 0, nargs * sizeof *arg_slots);
2014 arg_slots[i] = arg_types[i];
2016 debug_make_indirect_type (dhandle,
2018 (const char *) NULL);
2022 arg_types[nargs] = DEBUG_TYPE_NULL;
2024 if (! ieee_read_number (info, pp, &level)
2025 || ! ieee_read_optional_number (info, pp, &father, &present))
2028 /* We can't distinguish between a global function and a static
2030 pv->kind = IEEE_FUNCTION;
2033 && debug_get_type_kind (dhandle, rtype) == DEBUG_KIND_POINTER)
2035 /* Set up the return type as an indirect type pointing to
2036 the variable slot, so that we can change it to a
2037 reference later if appropriate. */
2038 pv->pslot = (debug_type *) xmalloc (sizeof *pv->pslot);
2040 rtype = debug_make_indirect_type (dhandle, pv->pslot,
2041 (const char *) NULL);
2044 type = debug_make_function_type (dhandle, rtype, arg_types, varargs);
2049 /* Record the type in the table. */
2051 if (type == DEBUG_TYPE_NULL)
2054 info->vars.vars[varindx].type = type;
2057 && info->vars.vars[varindx].namlen > 0)
2061 name = savestring (info->vars.vars[varindx].name,
2062 info->vars.vars[varindx].namlen);
2064 type = debug_name_type (dhandle, name, type);
2065 else if (tc == 'E' || tc == 'N')
2066 type = debug_tag_type (dhandle, name, type);
2069 struct ieee_tag *it;
2071 /* We must allocate all struct tags as indirect types, so
2072 that if we later see a definition of the tag as a C++
2073 record we can update the indirect slot and automatically
2074 change all the existing references. */
2075 it = (struct ieee_tag *) xmalloc (sizeof *it);
2076 memset (it, 0, sizeof *it);
2077 it->next = info->tags;
2082 type = debug_make_indirect_type (dhandle, &it->slot, name);
2083 type = debug_tag_type (dhandle, name, type);
2091 info->types.types[typeindx].type = type;
2092 info->types.types[typeindx].arg_slots = arg_slots;
2093 info->types.types[typeindx].bitsize = type_bitsize;
2095 /* We may have already allocated type as an indirect type pointing
2096 to slot. It does no harm to replace the indirect type with the
2097 real type. Filling in slot as well handles the indirect types
2098 which are already hanging around. */
2099 if (info->types.types[typeindx].pslot != NULL)
2100 *info->types.types[typeindx].pslot = type;
2105 /* Parse an ATN record. */
2108 parse_ieee_atn (info, pp)
2109 struct ieee_info *info;
2110 const bfd_byte **pp;
2112 const bfd_byte *atn_start, *atn_code_start;
2114 struct ieee_var *pvar;
2118 bfd_vma v, v2, v3, v4, v5;
2120 unsigned long namlen;
2127 if (! ieee_read_number (info, pp, &varindx)
2128 || ! ieee_read_type_index (info, pp, &type))
2131 atn_code_start = *pp;
2133 if (! ieee_read_number (info, pp, &atn_code))
2142 else if (varindx < 32)
2144 ieee_error (info, atn_start, "illegal variable index");
2150 if (varindx >= info->vars.alloc
2151 || info->vars.vars[varindx].name == NULL)
2153 /* The MRI compiler or linker sometimes omits the NN record
2154 for a pmisc record. */
2157 if (varindx >= info->vars.alloc)
2161 alloc = info->vars.alloc;
2164 while (varindx >= alloc)
2166 info->vars.vars = ((struct ieee_var *)
2167 xrealloc (info->vars.vars,
2169 * sizeof *info->vars.vars)));
2170 memset (info->vars.vars + info->vars.alloc, 0,
2171 ((alloc - info->vars.alloc)
2172 * sizeof *info->vars.vars));
2173 info->vars.alloc = alloc;
2176 pvar = info->vars.vars + varindx;
2182 ieee_error (info, atn_start, "undefined variable in ATN");
2187 pvar = info->vars.vars + varindx;
2192 namlen = pvar->namlen;
2195 dhandle = info->dhandle;
2197 /* If we are going to call debug_record_variable with a pointer
2198 type, change the type to an indirect type so that we can later
2199 change it to a reference type if we encounter a C++ pmisc 'R'
2202 && type != DEBUG_TYPE_NULL
2203 && debug_get_type_kind (dhandle, type) == DEBUG_KIND_POINTER)
2213 pvar->pslot = (debug_type *) xmalloc (sizeof *pvar->pslot);
2214 *pvar->pslot = type;
2215 type = debug_make_indirect_type (dhandle, pvar->pslot,
2216 (const char *) NULL);
2225 ieee_error (info, atn_code_start, "unknown ATN type");
2229 /* Automatic variable. */
2230 if (! ieee_read_number (info, pp, &v))
2232 namcopy = savestring (name, namlen);
2234 type = debug_make_void_type (dhandle);
2236 pvar->kind = IEEE_LOCAL;
2237 return debug_record_variable (dhandle, namcopy, type, DEBUG_LOCAL, v);
2240 /* Register variable. */
2241 if (! ieee_read_number (info, pp, &v))
2243 namcopy = savestring (name, namlen);
2245 type = debug_make_void_type (dhandle);
2247 pvar->kind = IEEE_LOCAL;
2248 return debug_record_variable (dhandle, namcopy, type, DEBUG_REGISTER,
2249 ieee_regno_to_genreg (info->abfd, v));
2252 /* Static variable. */
2253 if (! ieee_require_asn (info, pp, &v))
2255 namcopy = savestring (name, namlen);
2257 type = debug_make_void_type (dhandle);
2258 if (info->blockstack.bsp <= info->blockstack.stack)
2261 blocktype = info->blockstack.bsp[-1].kind;
2264 if (blocktype == 4 || blocktype == 6)
2265 pvar->kind = IEEE_LOCAL;
2267 pvar->kind = IEEE_STATIC;
2269 return debug_record_variable (dhandle, namcopy, type,
2270 (blocktype == 4 || blocktype == 6
2271 ? DEBUG_LOCAL_STATIC
2276 /* External function. We don't currently record these. FIXME. */
2278 pvar->kind = IEEE_EXTERNAL;
2282 /* External variable. We don't currently record these. FIXME. */
2284 pvar->kind = IEEE_EXTERNAL;
2288 if (! ieee_read_number (info, pp, &v)
2289 || ! ieee_read_number (info, pp, &v2)
2290 || ! ieee_read_optional_number (info, pp, &v3, &present))
2294 if (! ieee_read_optional_number (info, pp, &v4, &present))
2298 /* We just ignore the two optional fields in v3 and v4, since
2299 they are not defined. */
2301 if (! ieee_require_asn (info, pp, &v3))
2304 /* We have no way to record the column number. FIXME. */
2306 return debug_record_line (dhandle, v, v3);
2309 /* Global variable. */
2310 if (! ieee_require_asn (info, pp, &v))
2312 namcopy = savestring (name, namlen);
2314 type = debug_make_void_type (dhandle);
2316 pvar->kind = IEEE_GLOBAL;
2317 return debug_record_variable (dhandle, namcopy, type, DEBUG_GLOBAL, v);
2320 /* Variable lifetime information. */
2321 if (! ieee_read_number (info, pp, &v))
2324 /* We have no way to record this information. FIXME. */
2328 /* Locked register. The spec says that there are two required
2329 fields, but at least on occasion the MRI compiler only emits
2331 if (! ieee_read_number (info, pp, &v)
2332 || ! ieee_read_optional_number (info, pp, &v2, &present))
2335 /* I think this means a variable that is both in a register and
2336 a frame slot. We ignore the frame slot. FIXME. */
2338 namcopy = savestring (name, namlen);
2340 type = debug_make_void_type (dhandle);
2342 pvar->kind = IEEE_LOCAL;
2343 return debug_record_variable (dhandle, namcopy, type, DEBUG_REGISTER, v);
2346 /* Reserved for FORTRAN common. */
2347 ieee_error (info, atn_code_start, "unsupported ATN11");
2349 /* Return true to keep going. */
2353 /* Based variable. */
2357 if (! ieee_read_number (info, pp, &v)
2358 || ! ieee_read_number (info, pp, &v2)
2359 || ! ieee_read_optional_number (info, pp, &v3, &present))
2363 if (! ieee_read_optional_number (info, pp, &v4, &present))
2367 if (! ieee_read_optional_number (info, pp, &v5, &present))
2372 /* We have no way to record this information. FIXME. */
2374 ieee_error (info, atn_code_start, "unsupported ATN12");
2376 /* Return true to keep going. */
2380 /* Constant. The description of this that I have is ambiguous,
2381 so I'm not going to try to implement it. */
2382 if (! ieee_read_number (info, pp, &v)
2383 || ! ieee_read_optional_number (info, pp, &v2, &present))
2387 if (! ieee_read_optional_number (info, pp, &v2, &present))
2391 if (! ieee_read_optional_id (info, pp, &name, &namlen, &present))
2396 if ((ieee_record_enum_type) **pp == ieee_e2_first_byte_enum)
2398 if (! ieee_require_asn (info, pp, &v3))
2405 /* Static variable from assembler. */
2407 if (! ieee_read_number (info, pp, &v)
2408 || ! ieee_read_optional_number (info, pp, &v2, &present)
2409 || ! ieee_require_asn (info, pp, &v3))
2411 namcopy = savestring (name, namlen);
2412 /* We don't really handle this correctly. FIXME. */
2413 return debug_record_variable (dhandle, namcopy,
2414 debug_make_void_type (dhandle),
2415 v2 != 0 ? DEBUG_GLOBAL : DEBUG_STATIC,
2419 /* Procedure miscellaneous information. */
2421 /* Variable miscellaneous information. */
2423 /* Module miscellaneous information. */
2424 if (! ieee_read_number (info, pp, &v)
2425 || ! ieee_read_number (info, pp, &v2)
2426 || ! ieee_read_optional_id (info, pp, &name, &namlen, &present))
2429 if (atn_code == 62 && v == 80)
2433 ieee_error (info, atn_code_start,
2434 "unexpected string in C++ misc");
2437 return ieee_read_cxx_misc (info, pp, v2);
2440 /* We just ignore all of this stuff. FIXME. */
2442 for (; v2 > 0; --v2)
2444 switch ((ieee_record_enum_type) **pp)
2447 ieee_error (info, *pp, "bad misc record");
2450 case ieee_at_record_enum:
2451 if (! ieee_require_atn65 (info, pp, &name, &namlen))
2455 case ieee_e2_first_byte_enum:
2456 if (! ieee_require_asn (info, pp, &v3))
2468 /* Handle C++ debugging miscellaneous records. This is called for
2469 procedure miscellaneous records of type 80. */
2472 ieee_read_cxx_misc (info, pp, count)
2473 struct ieee_info *info;
2474 const bfd_byte **pp;
2475 unsigned long count;
2477 const bfd_byte *start;
2482 /* Get the category of C++ misc record. */
2483 if (! ieee_require_asn (info, pp, &category))
2490 ieee_error (info, start, "unrecognized C++ misc record");
2494 if (! ieee_read_cxx_class (info, pp, count))
2502 unsigned long namlen;
2504 /* The IEEE spec indicates that the 'M' record only has a
2505 flags field. The MRI compiler also emits the name of the
2508 if (! ieee_require_asn (info, pp, &flags))
2510 if (*pp < info->pend
2511 && (ieee_record_enum_type) **pp == ieee_at_record_enum)
2513 if (! ieee_require_atn65 (info, pp, &name, &namlen))
2517 /* This is emitted for method functions, but I don't think we
2518 care very much. It might help if it told us useful
2519 information like the class with which this function is
2520 associated, but it doesn't, so it isn't helpful. */
2525 if (! ieee_read_cxx_defaults (info, pp, count))
2531 const char *name, *mangled, *class;
2532 unsigned long namlen, mangledlen, classlen;
2535 /* Pointer to member. */
2537 if (! ieee_require_atn65 (info, pp, &name, &namlen)
2538 || ! ieee_require_atn65 (info, pp, &mangled, &mangledlen)
2539 || ! ieee_require_atn65 (info, pp, &class, &classlen)
2540 || ! ieee_require_asn (info, pp, &control))
2543 /* FIXME: We should now track down name and change its type. */
2548 if (! ieee_read_reference (info, pp))
2556 /* Read a C++ class definition. This is a pmisc type 80 record of
2560 ieee_read_cxx_class (info, pp, count)
2561 struct ieee_info *info;
2562 const bfd_byte **pp;
2563 unsigned long count;
2565 const bfd_byte *start;
2568 unsigned long taglen;
2569 struct ieee_tag *it;
2571 debug_field *fields;
2572 unsigned int field_count, field_alloc;
2573 debug_baseclass *baseclasses;
2574 unsigned int baseclasses_count, baseclasses_alloc;
2575 const debug_field *structfields;
2579 unsigned long namlen;
2580 debug_method_variant *variants;
2584 unsigned int methods_count, methods_alloc;
2585 debug_type vptrbase;
2587 debug_method *dmethods;
2591 if (! ieee_require_asn (info, pp, &class))
2595 if (! ieee_require_atn65 (info, pp, &tag, &taglen))
2599 /* Find the C struct with this name. */
2600 for (it = info->tags; it != NULL; it = it->next)
2601 if (it->name[0] == tag[0]
2602 && strncmp (it->name, tag, taglen) == 0
2603 && strlen (it->name) == taglen)
2607 ieee_error (info, start, "undefined C++ object");
2611 dhandle = info->dhandle;
2617 baseclasses_count = 0;
2618 baseclasses_alloc = 0;
2622 vptrbase = DEBUG_TYPE_NULL;
2625 structfields = debug_get_fields (dhandle, it->type);
2630 const bfd_byte *spec_start;
2634 if (! ieee_require_asn (info, pp, &id))
2641 ieee_error (info, spec_start, "unrecognized C++ object spec");
2646 bfd_vma flags, cinline;
2647 const char *basename, *fieldname;
2648 unsigned long baselen, fieldlen;
2650 debug_type basetype;
2653 enum debug_visibility visibility;
2654 debug_baseclass baseclass;
2656 /* This represents a base or friend class. */
2658 if (! ieee_require_asn (info, pp, &flags)
2659 || ! ieee_require_atn65 (info, pp, &basename, &baselen)
2660 || ! ieee_require_asn (info, pp, &cinline)
2661 || ! ieee_require_atn65 (info, pp, &fieldname, &fieldlen))
2665 /* We have no way of recording friend information, so we
2667 if ((flags & BASEFLAGS_FRIEND) != 0)
2670 /* I assume that either all of the members of the
2671 baseclass are included in the object, starting at the
2672 beginning of the object, or that none of them are
2675 if ((fieldlen == 0) == (cinline == 0))
2677 ieee_error (info, start, "unsupported C++ object type");
2681 basecopy = savestring (basename, baselen);
2682 basetype = debug_find_tagged_type (dhandle, basecopy,
2683 DEBUG_KIND_ILLEGAL);
2685 if (basetype == DEBUG_TYPE_NULL)
2687 ieee_error (info, start, "C++ base class not defined");
2695 const debug_field *pf;
2697 if (structfields == NULL)
2699 ieee_error (info, start, "C++ object has no fields");
2703 for (pf = structfields; *pf != DEBUG_FIELD_NULL; pf++)
2707 fname = debug_get_field_name (dhandle, *pf);
2710 if (fname[0] == fieldname[0]
2711 && strncmp (fname, fieldname, fieldlen) == 0
2712 && strlen (fname) == fieldlen)
2715 if (*pf == DEBUG_FIELD_NULL)
2717 ieee_error (info, start,
2718 "C++ base class not found in container");
2722 bitpos = debug_get_field_bitpos (dhandle, *pf);
2725 if ((flags & BASEFLAGS_VIRTUAL) != 0)
2729 if ((flags & BASEFLAGS_PRIVATE) != 0)
2730 visibility = DEBUG_VISIBILITY_PRIVATE;
2732 visibility = DEBUG_VISIBILITY_PUBLIC;
2734 baseclass = debug_make_baseclass (dhandle, basetype, bitpos,
2735 virtualp, visibility);
2736 if (baseclass == DEBUG_BASECLASS_NULL)
2739 if (baseclasses_count + 1 >= baseclasses_alloc)
2741 baseclasses_alloc += 10;
2742 baseclasses = ((debug_baseclass *)
2743 xrealloc (baseclasses,
2745 * sizeof *baseclasses)));
2748 baseclasses[baseclasses_count] = baseclass;
2749 ++baseclasses_count;
2750 baseclasses[baseclasses_count] = DEBUG_BASECLASS_NULL;
2757 const char *fieldname, *mangledname;
2758 unsigned long fieldlen, mangledlen;
2762 const debug_field *pf;
2763 enum debug_visibility visibility;
2766 /* This represents a data member. */
2768 if (! ieee_require_asn (info, pp, &flags)
2769 || ! ieee_require_atn65 (info, pp, &fieldname, &fieldlen)
2770 || ! ieee_require_atn65 (info, pp, &mangledname, &mangledlen))
2774 fieldcopy = savestring (fieldname, fieldlen);
2776 staticp = (flags & CXXFLAGS_STATIC) != 0 ? true : false;
2780 struct ieee_var *pv, *pvend;
2782 /* See if we can find a definition for this variable. */
2783 pv = info->vars.vars;
2784 pvend = pv + info->vars.alloc;
2785 for (; pv < pvend; pv++)
2786 if (pv->namlen == mangledlen
2787 && strncmp (pv->name, mangledname, mangledlen) == 0)
2793 /* This can happen if the variable is never used. */
2794 ftype = ieee_builtin_type (info, start,
2795 (unsigned int) builtin_void);
2802 if (structfields == NULL)
2804 ieee_error (info, start, "C++ object has no fields");
2808 for (pf = structfields, findx = 0;
2809 *pf != DEBUG_FIELD_NULL;
2814 fname = debug_get_field_name (dhandle, *pf);
2817 if (fname[0] == mangledname[0]
2818 && strncmp (fname, mangledname, mangledlen) == 0
2819 && strlen (fname) == mangledlen)
2822 if (*pf == DEBUG_FIELD_NULL)
2824 ieee_error (info, start,
2825 "C++ data member not found in container");
2829 ftype = debug_get_field_type (dhandle, *pf);
2831 if (debug_get_type_kind (dhandle, ftype) == DEBUG_KIND_POINTER)
2833 /* We might need to convert this field into a
2834 reference type later on, so make it an indirect
2836 if (it->fslots == NULL)
2839 const debug_field *pfcnt;
2842 for (pfcnt = structfields;
2843 *pfcnt != DEBUG_FIELD_NULL;
2846 it->fslots = ((debug_type *)
2847 xmalloc (fcnt * sizeof *it->fslots));
2848 memset (it->fslots, 0,
2849 fcnt * sizeof *it->fslots);
2852 if (ftype == DEBUG_TYPE_NULL)
2854 it->fslots[findx] = ftype;
2855 ftype = debug_make_indirect_type (dhandle,
2857 (const char *) NULL);
2860 if (ftype == DEBUG_TYPE_NULL)
2863 switch (flags & CXXFLAGS_VISIBILITY)
2866 ieee_error (info, start, "unknown C++ visibility");
2869 case CXXFLAGS_VISIBILITY_PUBLIC:
2870 visibility = DEBUG_VISIBILITY_PUBLIC;
2873 case CXXFLAGS_VISIBILITY_PRIVATE:
2874 visibility = DEBUG_VISIBILITY_PRIVATE;
2877 case CXXFLAGS_VISIBILITY_PROTECTED:
2878 visibility = DEBUG_VISIBILITY_PROTECTED;
2886 mangledcopy = savestring (mangledname, mangledlen);
2888 field = debug_make_static_member (dhandle, fieldcopy,
2894 bfd_vma bitpos, bitsize;
2896 bitpos = debug_get_field_bitpos (dhandle, *pf);
2897 bitsize = debug_get_field_bitsize (dhandle, *pf);
2898 if (bitpos == (bfd_vma) -1 || bitsize == (bfd_vma) -1)
2900 ieee_error (info, start, "bad C++ field bit pos or size");
2903 field = debug_make_field (dhandle, fieldcopy, ftype, bitpos,
2904 bitsize, visibility);
2907 if (field == DEBUG_FIELD_NULL)
2910 if (field_count + 1 >= field_alloc)
2913 fields = ((debug_field *)
2914 xrealloc (fields, field_alloc * sizeof *fields));
2917 fields[field_count] = field;
2919 fields[field_count] = DEBUG_FIELD_NULL;
2926 bfd_vma flags, voffset, control;
2927 const char *name, *mangled;
2928 unsigned long namlen, mangledlen;
2929 struct ieee_var *pv, *pvend;
2931 enum debug_visibility visibility;
2932 boolean constp, volatilep;
2934 debug_method_variant mv;
2935 struct ieee_method *meth;
2938 if (! ieee_require_asn (info, pp, &flags)
2939 || ! ieee_require_atn65 (info, pp, &name, &namlen)
2940 || ! ieee_require_atn65 (info, pp, &mangled, &mangledlen))
2947 if (! ieee_require_asn (info, pp, &voffset))
2951 if (! ieee_require_asn (info, pp, &control))
2955 /* We just ignore the control information. */
2957 /* We have no way to represent friend information, so we
2959 if ((flags & CXXFLAGS_FRIEND) != 0)
2962 /* We should already have seen a type for the function. */
2963 pv = info->vars.vars;
2964 pvend = pv + info->vars.alloc;
2965 for (; pv < pvend; pv++)
2966 if (pv->namlen == mangledlen
2967 && strncmp (pv->name, mangled, mangledlen) == 0)
2972 /* We won't have type information for this function if
2973 it is not included in this file. We don't try to
2974 handle this case. FIXME. */
2975 type = (debug_make_function_type
2977 ieee_builtin_type (info, start,
2978 (unsigned int) builtin_void),
2979 (debug_type *) NULL,
2984 debug_type return_type;
2985 const debug_type *arg_types;
2988 if (debug_get_type_kind (dhandle, pv->type)
2989 != DEBUG_KIND_FUNCTION)
2991 ieee_error (info, start,
2992 "bad type for C++ method function");
2996 return_type = debug_get_return_type (dhandle, pv->type);
2997 arg_types = debug_get_parameter_types (dhandle, pv->type,
2999 if (return_type == DEBUG_TYPE_NULL || arg_types == NULL)
3001 ieee_error (info, start,
3002 "no type information for C++ method function");
3006 type = debug_make_method_type (dhandle, return_type, it->type,
3007 (debug_type *) arg_types,
3010 if (type == DEBUG_TYPE_NULL)
3013 switch (flags & CXXFLAGS_VISIBILITY)
3016 ieee_error (info, start, "unknown C++ visibility");
3019 case CXXFLAGS_VISIBILITY_PUBLIC:
3020 visibility = DEBUG_VISIBILITY_PUBLIC;
3023 case CXXFLAGS_VISIBILITY_PRIVATE:
3024 visibility = DEBUG_VISIBILITY_PRIVATE;
3027 case CXXFLAGS_VISIBILITY_PROTECTED:
3028 visibility = DEBUG_VISIBILITY_PROTECTED;
3032 constp = (flags & CXXFLAGS_CONST) != 0 ? true : false;
3033 volatilep = (flags & CXXFLAGS_VOLATILE) != 0 ? true : false;
3035 mangledcopy = savestring (mangled, mangledlen);
3037 if ((flags & CXXFLAGS_STATIC) != 0)
3041 ieee_error (info, start, "C++ static virtual method");
3044 mv = debug_make_static_method_variant (dhandle, mangledcopy,
3050 debug_type vcontext;
3053 vcontext = DEBUG_TYPE_NULL;
3056 /* FIXME: How can we calculate this correctly? */
3057 vcontext = it->type;
3059 mv = debug_make_method_variant (dhandle, mangledcopy, type,
3064 if (mv == DEBUG_METHOD_VARIANT_NULL)
3067 for (meth = methods, im = 0; im < methods_count; meth++, im++)
3068 if (meth->namlen == namlen
3069 && strncmp (meth->name, name, namlen) == 0)
3071 if (im >= methods_count)
3073 if (methods_count >= methods_alloc)
3075 methods_alloc += 10;
3076 methods = ((struct ieee_method *)
3078 methods_alloc * sizeof *methods));
3080 methods[methods_count].name = name;
3081 methods[methods_count].namlen = namlen;
3082 methods[methods_count].variants = NULL;
3083 methods[methods_count].count = 0;
3084 methods[methods_count].alloc = 0;
3085 meth = methods + methods_count;
3089 if (meth->count + 1 >= meth->alloc)
3092 meth->variants = ((debug_method_variant *)
3093 xrealloc (meth->variants,
3095 * sizeof *meth->variants)));
3098 meth->variants[meth->count] = mv;
3100 meth->variants[meth->count] = DEBUG_METHOD_VARIANT_NULL;
3108 /* We have no way to store this information, so we just
3110 if (! ieee_require_asn (info, pp, &spec))
3113 if ((spec & 4) != 0)
3115 const char *filename;
3116 unsigned long filenamlen;
3119 if (! ieee_require_atn65 (info, pp, &filename, &filenamlen)
3120 || ! ieee_require_asn (info, pp, &lineno))
3124 else if ((spec & 8) != 0)
3126 const char *mangled;
3127 unsigned long mangledlen;
3129 if (! ieee_require_atn65 (info, pp, &mangled, &mangledlen))
3135 ieee_error (info, start,
3136 "unrecognized C++ object overhead spec");
3144 const char *vname, *basename;
3145 unsigned long vnamelen, baselen;
3146 bfd_vma vsize, control;
3148 /* A virtual table pointer. */
3150 if (! ieee_require_atn65 (info, pp, &vname, &vnamelen)
3151 || ! ieee_require_asn (info, pp, &vsize)
3152 || ! ieee_require_atn65 (info, pp, &basename, &baselen)
3153 || ! ieee_require_asn (info, pp, &control))
3157 /* We just ignore the control number. We don't care what
3158 the virtual table name is. We have no way to store the
3159 virtual table size, and I don't think we care anyhow. */
3161 /* FIXME: We can't handle multiple virtual table pointers. */
3169 basecopy = savestring (basename, baselen);
3170 vptrbase = debug_find_tagged_type (dhandle, basecopy,
3171 DEBUG_KIND_ILLEGAL);
3173 if (vptrbase == DEBUG_TYPE_NULL)
3175 ieee_error (info, start, "undefined C++ vtable");
3184 /* Now that we have seen all the method variants, we can call
3185 debug_make_method for each one. */
3187 if (methods_count == 0)
3193 dmethods = ((debug_method *)
3194 xmalloc ((methods_count + 1) * sizeof *dmethods));
3195 for (i = 0; i < methods_count; i++)
3199 namcopy = savestring (methods[i].name, methods[i].namlen);
3200 dmethods[i] = debug_make_method (dhandle, namcopy,
3201 methods[i].variants);
3202 if (dmethods[i] == DEBUG_METHOD_NULL)
3205 dmethods[i] = DEBUG_METHOD_NULL;
3209 /* The struct type was created as an indirect type pointing at
3210 it->slot. We update it->slot to automatically update all
3211 references to this struct. */
3212 it->slot = debug_make_object_type (dhandle,
3214 debug_get_type_size (dhandle,
3216 fields, baseclasses, dmethods,
3218 if (it->slot == DEBUG_TYPE_NULL)
3224 /* Read C++ default argument value and reference type information. */
3227 ieee_read_cxx_defaults (info, pp, count)
3228 struct ieee_info *info;
3229 const bfd_byte **pp;
3230 unsigned long count;
3232 const bfd_byte *start;
3234 unsigned long fnlen;
3239 /* Giving the function name before the argument count is an addendum
3240 to the spec. The function name is demangled, though, so this
3241 record must always refer to the current function. */
3243 if (info->blockstack.bsp <= info->blockstack.stack
3244 || info->blockstack.bsp[-1].fnindx == (unsigned int) -1)
3246 ieee_error (info, start, "C++ default values not in a function");
3250 if (! ieee_require_atn65 (info, pp, &fnname, &fnlen)
3251 || ! ieee_require_asn (info, pp, &defcount))
3255 while (defcount-- > 0)
3259 unsigned long strvallen;
3261 if (! ieee_require_asn (info, pp, &type))
3273 if (! ieee_require_asn (info, pp, &val))
3280 if (! ieee_require_atn65 (info, pp, &strval, &strvallen))
3286 ieee_error (info, start, "unrecognized C++ default type");
3290 /* We have no way to record the default argument values, so we
3291 just ignore them. FIXME. */
3294 /* Any remaining arguments are indices of parameters that are really
3299 debug_type *arg_slots;
3301 dhandle = info->dhandle;
3302 arg_slots = info->types.types[info->blockstack.bsp[-1].fnindx].arg_slots;
3308 if (! ieee_require_asn (info, pp, &indx))
3310 /* The index is 1 based. */
3312 if (arg_slots == NULL
3313 || arg_slots[indx] == DEBUG_TYPE_NULL
3314 || (debug_get_type_kind (dhandle, arg_slots[indx])
3315 != DEBUG_KIND_POINTER))
3317 ieee_error (info, start, "reference parameter is not a pointer");
3321 target = debug_get_target_type (dhandle, arg_slots[indx]);
3322 arg_slots[indx] = debug_make_reference_type (dhandle, target);
3323 if (arg_slots[indx] == DEBUG_TYPE_NULL)
3331 /* Read a C++ reference definition. */
3334 ieee_read_reference (info, pp)
3335 struct ieee_info *info;
3336 const bfd_byte **pp;
3338 const bfd_byte *start;
3340 const char *class, *name;
3341 unsigned long classlen, namlen;
3347 if (! ieee_require_asn (info, pp, &flags))
3350 /* Giving the class name before the member name is in an addendum to
3354 if (! ieee_require_atn65 (info, pp, &class, &classlen))
3358 if (! ieee_require_atn65 (info, pp, &name, &namlen))
3366 /* We search from the last variable indices to the first in
3367 hopes of finding local variables correctly. We search the
3368 local variables on the first pass, and the global variables
3369 on the second. FIXME: This probably won't work in all cases.
3370 On the other hand, I don't know what will. */
3371 for (pass = 0; pass < 2; pass++)
3373 struct ieee_vars *vars;
3375 struct ieee_var *pv = NULL;
3381 vars = info->global_vars;
3386 for (i = (int) vars->alloc - 1; i >= 0; i--)
3390 pv = vars->vars + i;
3392 if (pv->pslot == NULL
3393 || pv->namlen != namlen
3394 || strncmp (pv->name, name, namlen) != 0)
3401 ieee_error (info, start,
3402 "unrecognized C++ reference type");
3406 /* Global variable or function. */
3407 if (pv->kind == IEEE_GLOBAL
3408 || pv->kind == IEEE_EXTERNAL
3409 || pv->kind == IEEE_FUNCTION)
3414 /* Global static variable or function. */
3415 if (pv->kind == IEEE_STATIC
3416 || pv->kind == IEEE_FUNCTION)
3421 /* Local variable. */
3422 if (pv->kind == IEEE_LOCAL)
3440 struct ieee_tag *it;
3442 for (it = info->tags; it != NULL; it = it->next)
3444 if (it->name[0] == class[0]
3445 && strncmp (it->name, class, classlen) == 0
3446 && strlen (it->name) == classlen)
3448 if (it->fslots != NULL)
3450 const debug_field *pf;
3453 pf = debug_get_fields (info->dhandle, it->type);
3456 ieee_error (info, start,
3457 "C++ reference in class with no fields");
3461 for (findx = 0; *pf != DEBUG_FIELD_NULL; pf++, findx++)
3465 fname = debug_get_field_name (info->dhandle, *pf);
3468 if (strncmp (fname, name, namlen) == 0
3469 && strlen (fname) == namlen)
3471 pslot = it->fslots + findx;
3484 ieee_error (info, start, "C++ reference not found");
3488 /* We allocated the type of the object as an indirect type pointing
3489 to *pslot, which we can now update to be a reference type. */
3490 if (debug_get_type_kind (info->dhandle, *pslot) != DEBUG_KIND_POINTER)
3492 ieee_error (info, start, "C++ reference is not pointer");
3496 target = debug_get_target_type (info->dhandle, *pslot);
3497 *pslot = debug_make_reference_type (info->dhandle, target);
3498 if (*pslot == DEBUG_TYPE_NULL)
3504 /* Require an ASN record. */
3507 ieee_require_asn (info, pp, pv)
3508 struct ieee_info *info;
3509 const bfd_byte **pp;
3512 const bfd_byte *start;
3513 ieee_record_enum_type c;
3518 c = (ieee_record_enum_type) **pp;
3519 if (c != ieee_e2_first_byte_enum)
3521 ieee_error (info, start, "missing required ASN");
3526 c = (ieee_record_enum_type) (((unsigned int) c << 8) | **pp);
3527 if (c != ieee_asn_record_enum)
3529 ieee_error (info, start, "missing required ASN");
3534 /* Just ignore the variable index. */
3535 if (! ieee_read_number (info, pp, &varindx))
3538 return ieee_read_expression (info, pp, pv);
3541 /* Require an ATN65 record. */
3544 ieee_require_atn65 (info, pp, pname, pnamlen)
3545 struct ieee_info *info;
3546 const bfd_byte **pp;
3548 unsigned long *pnamlen;
3550 const bfd_byte *start;
3551 ieee_record_enum_type c;
3552 bfd_vma name_indx, type_indx, atn_code;
3556 c = (ieee_record_enum_type) **pp;
3557 if (c != ieee_at_record_enum)
3559 ieee_error (info, start, "missing required ATN65");
3564 c = (ieee_record_enum_type) (((unsigned int) c << 8) | **pp);
3565 if (c != ieee_atn_record_enum)
3567 ieee_error (info, start, "missing required ATN65");
3572 if (! ieee_read_number (info, pp, &name_indx)
3573 || ! ieee_read_number (info, pp, &type_indx)
3574 || ! ieee_read_number (info, pp, &atn_code))
3577 /* Just ignore name_indx. */
3579 if (type_indx != 0 || atn_code != 65)
3581 ieee_error (info, start, "bad ATN65 record");
3585 return ieee_read_id (info, pp, pname, pnamlen);
3588 /* Convert a register number in IEEE debugging information into a
3589 generic register number. */
3592 ieee_regno_to_genreg (abfd, r)
3596 switch (bfd_get_arch (abfd))
3599 /* For some reasons stabs adds 2 to the floating point register
3606 /* Stabs uses 0 to 15 for r0 to r15, 16 to 31 for g0 to g15, and
3607 32 to 35 for fp0 to fp3. */
3618 /* Convert a generic register number to an IEEE specific one. */
3621 ieee_genreg_to_regno (abfd, r)
3625 switch (bfd_get_arch (abfd))
3628 /* For some reason stabs add 2 to the floating point register
3635 /* Stabs uses 0 to 15 for r0 to r15, 16 to 31 for g0 to g15, and
3636 32 to 35 for fp0 to fp3. */
3647 /* These routines build IEEE debugging information out of the generic
3648 debugging information. */
3650 /* We build the IEEE debugging information byte by byte. Rather than
3651 waste time copying data around, we use a linked list of buffers to
3654 #define IEEE_BUFSIZE (490)
3659 struct ieee_buf *next;
3660 /* Number of data bytes in this buffer. */
3663 bfd_byte buf[IEEE_BUFSIZE];
3666 /* A list of buffers. */
3671 struct ieee_buf *head;
3672 /* Tail--last buffer on list. */
3673 struct ieee_buf *tail;
3676 /* In order to generate the BB11 blocks required by the HP emulator,
3677 we keep track of ranges of addresses which correspond to a given
3678 compilation unit. */
3683 struct ieee_range *next;
3690 /* This structure holds information for a class on the type stack. */
3692 struct ieee_type_class
3694 /* The name index in the debugging information. */
3696 /* The pmisc records for the class. */
3697 struct ieee_buflist pmiscbuf;
3698 /* The number of pmisc records. */
3699 unsigned int pmisccount;
3700 /* The name of the class holding the virtual table, if not this
3703 /* Whether this class holds its own virtual table. */
3705 /* The largest virtual table offset seen so far. */
3707 /* The current method. */
3709 /* Additional pmisc records used to record fields of reference type. */
3710 struct ieee_buflist refs;
3713 /* This is how we store types for the writing routines. Most types
3714 are simply represented by a type index. */
3716 struct ieee_write_type
3720 /* The size of the type, if known. */
3722 /* The name of the type, if any. */
3724 /* If this is a function or method type, we build the type here, and
3725 only add it to the output buffers if we need it. */
3726 struct ieee_buflist fndef;
3727 /* If this is a struct, this is where the struct definition is
3729 struct ieee_buflist strdef;
3730 /* If this is a class, this is where the class information is built. */
3731 struct ieee_type_class *classdef;
3732 /* Whether the type is unsigned. */
3733 unsigned int unsignedp : 1;
3734 /* Whether this is a reference type. */
3735 unsigned int referencep : 1;
3736 /* Whether this is in the local type block. */
3737 unsigned int localp : 1;
3738 /* If this is not local, whether a reference to this type should be
3740 unsigned reflocalp : 1;
3741 /* Whether this is a duplicate struct definition which we are
3743 unsigned int ignorep : 1;
3746 /* This is the type stack used by the debug writing routines. FIXME:
3747 We could generate more efficient output if we remembered when we
3748 have output a particular type before. */
3750 struct ieee_type_stack
3752 /* Next entry on stack. */
3753 struct ieee_type_stack *next;
3754 /* Type information. */
3755 struct ieee_write_type type;
3758 /* This is a list of associations between a name and some types.
3759 These are used for typedefs and tags. */
3761 struct ieee_name_type
3763 /* Next type for this name. */
3764 struct ieee_name_type *next;
3765 /* ID number. For a typedef, this is the index of the type to which
3766 this name is typedefed. */
3769 struct ieee_write_type type;
3770 /* If this is a tag which has not yet been defined, this is the
3771 kind. If the tag has been defined, this is DEBUG_KIND_ILLEGAL. */
3772 enum debug_type_kind kind;
3775 /* We use a hash table to associate names and types. */
3777 struct ieee_name_type_hash_table
3779 struct bfd_hash_table root;
3782 struct ieee_name_type_hash_entry
3784 struct bfd_hash_entry root;
3785 /* Information for this name. */
3786 struct ieee_name_type *types;
3789 /* This is a list of enums. */
3791 struct ieee_defined_enum
3794 struct ieee_defined_enum *next;
3802 bfd_signed_vma *vals;
3805 /* We keep a list of modified versions of types, so that we don't
3806 output them more than once. */
3808 struct ieee_modified_type
3810 /* Pointer to this type. */
3811 unsigned int pointer;
3812 /* Function with unknown arguments returning this type. */
3813 unsigned int function;
3814 /* Const version of this type. */
3815 unsigned int const_qualified;
3816 /* Volatile version of this type. */
3817 unsigned int volatile_qualified;
3818 /* List of arrays of this type of various bounds. */
3819 struct ieee_modified_array_type *arrays;
3822 /* A list of arrays bounds. */
3824 struct ieee_modified_array_type
3826 /* Next array bounds. */
3827 struct ieee_modified_array_type *next;
3828 /* Type index with these bounds. */
3833 bfd_signed_vma high;
3836 /* This is a list of pending function parameter information. We don't
3837 output them until we see the first block. */
3839 struct ieee_pending_parm
3841 /* Next pending parameter. */
3842 struct ieee_pending_parm *next;
3847 /* Whether the type is a reference. */
3850 enum debug_parm_kind kind;
3855 /* This is the handle passed down by debug_write. */
3859 /* BFD we are writing to. */
3861 /* Whether we got an error in a subroutine called via traverse or
3862 map_over_sections. */
3864 /* Current data buffer list. */
3865 struct ieee_buflist *current;
3866 /* Current data buffer. */
3867 struct ieee_buf *curbuf;
3868 /* Filename of current compilation unit. */
3869 const char *filename;
3870 /* Module name of current compilation unit. */
3871 const char *modname;
3872 /* List of buffer for global types. */
3873 struct ieee_buflist global_types;
3874 /* List of finished data buffers. */
3875 struct ieee_buflist data;
3876 /* List of buffers for typedefs in the current compilation unit. */
3877 struct ieee_buflist types;
3878 /* List of buffers for variables and functions in the current
3879 compilation unit. */
3880 struct ieee_buflist vars;
3881 /* List of buffers for C++ class definitions in the current
3882 compilation unit. */
3883 struct ieee_buflist cxx;
3884 /* List of buffers for line numbers in the current compilation unit. */
3885 struct ieee_buflist linenos;
3886 /* Ranges for the current compilation unit. */
3887 struct ieee_range *ranges;
3888 /* Ranges for all debugging information. */
3889 struct ieee_range *global_ranges;
3890 /* Nested pending ranges. */
3891 struct ieee_range *pending_ranges;
3893 struct ieee_type_stack *type_stack;
3894 /* Next unallocated type index. */
3895 unsigned int type_indx;
3896 /* Next unallocated name index. */
3897 unsigned int name_indx;
3899 struct ieee_name_type_hash_table typedefs;
3901 struct ieee_name_type_hash_table tags;
3903 struct ieee_defined_enum *enums;
3904 /* Modified versions of types. */
3905 struct ieee_modified_type *modified;
3906 /* Number of entries allocated in modified. */
3907 unsigned int modified_alloc;
3908 /* 4 byte complex type. */
3909 unsigned int complex_float_index;
3910 /* 8 byte complex type. */
3911 unsigned int complex_double_index;
3912 /* The depth of block nesting. This is 0 outside a function, and 1
3913 just after start_function is called. */
3914 unsigned int block_depth;
3915 /* The name of the current function. */
3917 /* List of buffers for the type of the function we are currently
3919 struct ieee_buflist fntype;
3920 /* List of buffers for the parameters of the function we are
3921 currently writing out. */
3922 struct ieee_buflist fnargs;
3923 /* Number of arguments written to fnargs. */
3924 unsigned int fnargcount;
3925 /* Pending function parameters. */
3926 struct ieee_pending_parm *pending_parms;
3927 /* Current line number filename. */
3928 const char *lineno_filename;
3929 /* Line number name index. */
3930 unsigned int lineno_name_indx;
3931 /* Filename of pending line number. */
3932 const char *pending_lineno_filename;
3933 /* Pending line number. */
3934 unsigned long pending_lineno;
3935 /* Address of pending line number. */
3936 bfd_vma pending_lineno_addr;
3937 /* Highest address seen at end of procedure. */
3941 static boolean ieee_init_buffer
3942 PARAMS ((struct ieee_handle *, struct ieee_buflist *));
3943 static boolean ieee_change_buffer
3944 PARAMS ((struct ieee_handle *, struct ieee_buflist *));
3945 static boolean ieee_append_buffer
3946 PARAMS ((struct ieee_handle *, struct ieee_buflist *,
3947 struct ieee_buflist *));
3948 static boolean ieee_real_write_byte PARAMS ((struct ieee_handle *, int));
3949 static boolean ieee_write_2bytes PARAMS ((struct ieee_handle *, int));
3950 static boolean ieee_write_number PARAMS ((struct ieee_handle *, bfd_vma));
3951 static boolean ieee_write_id PARAMS ((struct ieee_handle *, const char *));
3952 static boolean ieee_write_asn
3953 PARAMS ((struct ieee_handle *, unsigned int, bfd_vma));
3954 static boolean ieee_write_atn65
3955 PARAMS ((struct ieee_handle *, unsigned int, const char *));
3956 static boolean ieee_push_type
3957 PARAMS ((struct ieee_handle *, unsigned int, unsigned int, boolean,
3959 static unsigned int ieee_pop_type PARAMS ((struct ieee_handle *));
3960 static void ieee_pop_unused_type PARAMS ((struct ieee_handle *));
3961 static unsigned int ieee_pop_type_used
3962 PARAMS ((struct ieee_handle *, boolean));
3963 static boolean ieee_add_range
3964 PARAMS ((struct ieee_handle *, boolean, bfd_vma, bfd_vma));
3965 static boolean ieee_start_range PARAMS ((struct ieee_handle *, bfd_vma));
3966 static boolean ieee_end_range PARAMS ((struct ieee_handle *, bfd_vma));
3967 static boolean ieee_define_type
3968 PARAMS ((struct ieee_handle *, unsigned int, boolean, boolean));
3969 static boolean ieee_define_named_type
3970 PARAMS ((struct ieee_handle *, const char *, unsigned int, unsigned int,
3971 boolean, boolean, struct ieee_buflist *));
3972 static struct ieee_modified_type *ieee_get_modified_info
3973 PARAMS ((struct ieee_handle *, unsigned int));
3974 static struct bfd_hash_entry *ieee_name_type_newfunc
3975 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
3976 static boolean ieee_write_undefined_tag
3977 PARAMS ((struct ieee_name_type_hash_entry *, PTR));
3978 static boolean ieee_finish_compilation_unit PARAMS ((struct ieee_handle *));
3979 static void ieee_add_bb11_blocks PARAMS ((bfd *, asection *, PTR));
3980 static boolean ieee_add_bb11
3981 PARAMS ((struct ieee_handle *, asection *, bfd_vma, bfd_vma));
3982 static boolean ieee_output_pending_parms PARAMS ((struct ieee_handle *));
3983 static unsigned int ieee_vis_to_flags PARAMS ((enum debug_visibility));
3984 static boolean ieee_class_method_var
3985 PARAMS ((struct ieee_handle *, const char *, enum debug_visibility, boolean,
3986 boolean, boolean, bfd_vma, boolean));
3988 static boolean ieee_start_compilation_unit PARAMS ((PTR, const char *));
3989 static boolean ieee_start_source PARAMS ((PTR, const char *));
3990 static boolean ieee_empty_type PARAMS ((PTR));
3991 static boolean ieee_void_type PARAMS ((PTR));
3992 static boolean ieee_int_type PARAMS ((PTR, unsigned int, boolean));
3993 static boolean ieee_float_type PARAMS ((PTR, unsigned int));
3994 static boolean ieee_complex_type PARAMS ((PTR, unsigned int));
3995 static boolean ieee_bool_type PARAMS ((PTR, unsigned int));
3996 static boolean ieee_enum_type
3997 PARAMS ((PTR, const char *, const char **, bfd_signed_vma *));
3998 static boolean ieee_pointer_type PARAMS ((PTR));
3999 static boolean ieee_function_type PARAMS ((PTR, int, boolean));
4000 static boolean ieee_reference_type PARAMS ((PTR));
4001 static boolean ieee_range_type PARAMS ((PTR, bfd_signed_vma, bfd_signed_vma));
4002 static boolean ieee_array_type
4003 PARAMS ((PTR, bfd_signed_vma, bfd_signed_vma, boolean));
4004 static boolean ieee_set_type PARAMS ((PTR, boolean));
4005 static boolean ieee_offset_type PARAMS ((PTR));
4006 static boolean ieee_method_type PARAMS ((PTR, boolean, int, boolean));
4007 static boolean ieee_const_type PARAMS ((PTR));
4008 static boolean ieee_volatile_type PARAMS ((PTR));
4009 static boolean ieee_start_struct_type
4010 PARAMS ((PTR, const char *, unsigned int, boolean, unsigned int));
4011 static boolean ieee_struct_field
4012 PARAMS ((PTR, const char *, bfd_vma, bfd_vma, enum debug_visibility));
4013 static boolean ieee_end_struct_type PARAMS ((PTR));
4014 static boolean ieee_start_class_type
4015 PARAMS ((PTR, const char *, unsigned int, boolean, unsigned int, boolean,
4017 static boolean ieee_class_static_member
4018 PARAMS ((PTR, const char *, const char *, enum debug_visibility));
4019 static boolean ieee_class_baseclass
4020 PARAMS ((PTR, bfd_vma, boolean, enum debug_visibility));
4021 static boolean ieee_class_start_method PARAMS ((PTR, const char *));
4022 static boolean ieee_class_method_variant
4023 PARAMS ((PTR, const char *, enum debug_visibility, boolean, boolean,
4025 static boolean ieee_class_static_method_variant
4026 PARAMS ((PTR, const char *, enum debug_visibility, boolean, boolean));
4027 static boolean ieee_class_end_method PARAMS ((PTR));
4028 static boolean ieee_end_class_type PARAMS ((PTR));
4029 static boolean ieee_typedef_type PARAMS ((PTR, const char *));
4030 static boolean ieee_tag_type
4031 PARAMS ((PTR, const char *, unsigned int, enum debug_type_kind));
4032 static boolean ieee_typdef PARAMS ((PTR, const char *));
4033 static boolean ieee_tag PARAMS ((PTR, const char *));
4034 static boolean ieee_int_constant PARAMS ((PTR, const char *, bfd_vma));
4035 static boolean ieee_float_constant PARAMS ((PTR, const char *, double));
4036 static boolean ieee_typed_constant PARAMS ((PTR, const char *, bfd_vma));
4037 static boolean ieee_variable
4038 PARAMS ((PTR, const char *, enum debug_var_kind, bfd_vma));
4039 static boolean ieee_start_function PARAMS ((PTR, const char *, boolean));
4040 static boolean ieee_function_parameter
4041 PARAMS ((PTR, const char *, enum debug_parm_kind, bfd_vma));
4042 static boolean ieee_start_block PARAMS ((PTR, bfd_vma));
4043 static boolean ieee_end_block PARAMS ((PTR, bfd_vma));
4044 static boolean ieee_end_function PARAMS ((PTR));
4045 static boolean ieee_lineno
4046 PARAMS ((PTR, const char *, unsigned long, bfd_vma));
4048 static const struct debug_write_fns ieee_fns =
4050 ieee_start_compilation_unit,
4061 ieee_reference_type,
4069 ieee_start_struct_type,
4071 ieee_end_struct_type,
4072 ieee_start_class_type,
4073 ieee_class_static_member,
4074 ieee_class_baseclass,
4075 ieee_class_start_method,
4076 ieee_class_method_variant,
4077 ieee_class_static_method_variant,
4078 ieee_class_end_method,
4079 ieee_end_class_type,
4085 ieee_float_constant,
4086 ieee_typed_constant,
4088 ieee_start_function,
4089 ieee_function_parameter,
4096 /* Initialize a buffer to be empty. */
4100 ieee_init_buffer (info, buflist)
4101 struct ieee_handle *info;
4102 struct ieee_buflist *buflist;
4104 buflist->head = NULL;
4105 buflist->tail = NULL;
4109 /* See whether a buffer list has any data. */
4111 #define ieee_buffer_emptyp(buflist) ((buflist)->head == NULL)
4113 /* Change the current buffer to a specified buffer chain. */
4116 ieee_change_buffer (info, buflist)
4117 struct ieee_handle *info;
4118 struct ieee_buflist *buflist;
4120 if (buflist->head == NULL)
4122 struct ieee_buf *buf;
4124 buf = (struct ieee_buf *) xmalloc (sizeof *buf);
4127 buflist->head = buf;
4128 buflist->tail = buf;
4131 info->current = buflist;
4132 info->curbuf = buflist->tail;
4137 /* Append a buffer chain. */
4141 ieee_append_buffer (info, mainbuf, newbuf)
4142 struct ieee_handle *info;
4143 struct ieee_buflist *mainbuf;
4144 struct ieee_buflist *newbuf;
4146 if (newbuf->head != NULL)
4148 if (mainbuf->head == NULL)
4149 mainbuf->head = newbuf->head;
4151 mainbuf->tail->next = newbuf->head;
4152 mainbuf->tail = newbuf->tail;
4157 /* Write a byte into the buffer. We use a macro for speed and a
4158 function for the complex cases. */
4160 #define ieee_write_byte(info, b) \
4161 ((info)->curbuf->c < IEEE_BUFSIZE \
4162 ? ((info)->curbuf->buf[(info)->curbuf->c++] = (b), true) \
4163 : ieee_real_write_byte ((info), (b)))
4166 ieee_real_write_byte (info, b)
4167 struct ieee_handle *info;
4170 if (info->curbuf->c >= IEEE_BUFSIZE)
4174 n = (struct ieee_buf *) xmalloc (sizeof *n);
4177 if (info->current->head == NULL)
4178 info->current->head = n;
4180 info->current->tail->next = n;
4181 info->current->tail = n;
4185 info->curbuf->buf[info->curbuf->c] = b;
4191 /* Write out two bytes. */
4194 ieee_write_2bytes (info, i)
4195 struct ieee_handle *info;
4198 return (ieee_write_byte (info, i >> 8)
4199 && ieee_write_byte (info, i & 0xff));
4202 /* Write out an integer. */
4205 ieee_write_number (info, v)
4206 struct ieee_handle *info;
4214 if (v <= (bfd_vma) ieee_number_end_enum)
4215 return ieee_write_byte (info, (int) v);
4226 if (c > (unsigned int) (ieee_number_repeat_end_enum
4227 - ieee_number_repeat_start_enum))
4229 fprintf (stderr, "IEEE numeric overflow: 0x");
4230 fprintf_vma (stderr, v);
4231 fprintf (stderr, "\n");
4235 if (! ieee_write_byte (info, (int) ieee_number_repeat_start_enum + c))
4237 for (; c > 0; --c, ++p)
4239 if (! ieee_write_byte (info, *p))
4246 /* Write out a string. */
4249 ieee_write_id (info, s)
4250 struct ieee_handle *info;
4258 if (! ieee_write_byte (info, len))
4261 else if (len <= 0xff)
4263 if (! ieee_write_byte (info, (int) ieee_extension_length_1_enum)
4264 || ! ieee_write_byte (info, len))
4267 else if (len <= 0xffff)
4269 if (! ieee_write_byte (info, (int) ieee_extension_length_2_enum)
4270 || ! ieee_write_2bytes (info, len))
4275 fprintf (stderr, "IEEE string length overflow: %u\n", len);
4279 for (; *s != '\0'; s++)
4280 if (! ieee_write_byte (info, *s))
4286 /* Write out an ASN record. */
4289 ieee_write_asn (info, indx, val)
4290 struct ieee_handle *info;
4294 return (ieee_write_2bytes (info, (int) ieee_asn_record_enum)
4295 && ieee_write_number (info, indx)
4296 && ieee_write_number (info, val));
4299 /* Write out an ATN65 record. */
4302 ieee_write_atn65 (info, indx, s)
4303 struct ieee_handle *info;
4307 return (ieee_write_2bytes (info, (int) ieee_atn_record_enum)
4308 && ieee_write_number (info, indx)
4309 && ieee_write_number (info, 0)
4310 && ieee_write_number (info, 65)
4311 && ieee_write_id (info, s));
4314 /* Push a type index onto the type stack. */
4317 ieee_push_type (info, indx, size, unsignedp, localp)
4318 struct ieee_handle *info;
4324 struct ieee_type_stack *ts;
4326 ts = (struct ieee_type_stack *) xmalloc (sizeof *ts);
4327 memset (ts, 0, sizeof *ts);
4329 ts->type.indx = indx;
4330 ts->type.size = size;
4331 ts->type.unsignedp = unsignedp;
4332 ts->type.localp = localp;
4334 ts->next = info->type_stack;
4335 info->type_stack = ts;
4340 /* Pop a type index off the type stack. */
4343 ieee_pop_type (info)
4344 struct ieee_handle *info;
4346 return ieee_pop_type_used (info, true);
4349 /* Pop an unused type index off the type stack. */
4352 ieee_pop_unused_type (info)
4353 struct ieee_handle *info;
4355 (void) ieee_pop_type_used (info, false);
4358 /* Pop a used or unused type index off the type stack. */
4361 ieee_pop_type_used (info, used)
4362 struct ieee_handle *info;
4365 struct ieee_type_stack *ts;
4368 ts = info->type_stack;
4369 assert (ts != NULL);
4371 /* If this is a function type, and we need it, we need to append the
4372 actual definition to the typedef block now. */
4373 if (used && ! ieee_buffer_emptyp (&ts->type.fndef))
4375 struct ieee_buflist *buflist;
4377 if (ts->type.localp)
4379 /* Make sure we have started the types block. */
4380 if (ieee_buffer_emptyp (&info->types))
4382 if (! ieee_change_buffer (info, &info->types)
4383 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
4384 || ! ieee_write_byte (info, 1)
4385 || ! ieee_write_number (info, 0)
4386 || ! ieee_write_id (info, info->modname))
4389 buflist = &info->types;
4393 /* Make sure we started the global type block. */
4394 if (ieee_buffer_emptyp (&info->global_types))
4396 if (! ieee_change_buffer (info, &info->global_types)
4397 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
4398 || ! ieee_write_byte (info, 2)
4399 || ! ieee_write_number (info, 0)
4400 || ! ieee_write_id (info, ""))
4403 buflist = &info->global_types;
4406 if (! ieee_append_buffer (info, buflist, &ts->type.fndef))
4410 ret = ts->type.indx;
4411 info->type_stack = ts->next;
4416 /* Add a range of bytes included in the current compilation unit. */
4419 ieee_add_range (info, global, low, high)
4420 struct ieee_handle *info;
4425 struct ieee_range **plist, *r, **pr;
4427 if (low == (bfd_vma) -1 || high == (bfd_vma) -1 || low == high)
4431 plist = &info->global_ranges;
4433 plist = &info->ranges;
4435 for (r = *plist; r != NULL; r = r->next)
4437 if (high >= r->low && low <= r->high)
4439 /* The new range overlaps r. */
4445 while (*pr != NULL && (*pr)->low <= r->high)
4447 struct ieee_range *n;
4449 if ((*pr)->high > r->high)
4450 r->high = (*pr)->high;
4459 r = (struct ieee_range *) xmalloc (sizeof *r);
4460 memset (r, 0, sizeof *r);
4465 /* Store the ranges sorted by address. */
4466 for (pr = plist; *pr != NULL; pr = &(*pr)->next)
4467 if ((*pr)->low > high)
4475 /* Start a new range for which we only have the low address. */
4478 ieee_start_range (info, low)
4479 struct ieee_handle *info;
4482 struct ieee_range *r;
4484 r = (struct ieee_range *) xmalloc (sizeof *r);
4485 memset (r, 0, sizeof *r);
4487 r->next = info->pending_ranges;
4488 info->pending_ranges = r;
4492 /* Finish a range started by ieee_start_range. */
4495 ieee_end_range (info, high)
4496 struct ieee_handle *info;
4499 struct ieee_range *r;
4502 assert (info->pending_ranges != NULL);
4503 r = info->pending_ranges;
4505 info->pending_ranges = r->next;
4507 return ieee_add_range (info, false, low, high);
4510 /* Start defining a type. */
4513 ieee_define_type (info, size, unsignedp, localp)
4514 struct ieee_handle *info;
4519 return ieee_define_named_type (info, (const char *) NULL,
4520 (unsigned int) -1, size, unsignedp,
4521 localp, (struct ieee_buflist *) NULL);
4524 /* Start defining a named type. */
4527 ieee_define_named_type (info, name, indx, size, unsignedp, localp, buflist)
4528 struct ieee_handle *info;
4534 struct ieee_buflist *buflist;
4536 unsigned int type_indx;
4537 unsigned int name_indx;
4539 if (indx != (unsigned int) -1)
4543 type_indx = info->type_indx;
4547 name_indx = info->name_indx;
4553 /* If we were given a buffer, use it; otherwise, use either the
4554 local or the global type information, and make sure that the type
4555 block is started. */
4556 if (buflist != NULL)
4558 if (! ieee_change_buffer (info, buflist))
4563 if (! ieee_buffer_emptyp (&info->types))
4565 if (! ieee_change_buffer (info, &info->types))
4570 if (! ieee_change_buffer (info, &info->types)
4571 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
4572 || ! ieee_write_byte (info, 1)
4573 || ! ieee_write_number (info, 0)
4574 || ! ieee_write_id (info, info->modname))
4580 if (! ieee_buffer_emptyp (&info->global_types))
4582 if (! ieee_change_buffer (info, &info->global_types))
4587 if (! ieee_change_buffer (info, &info->global_types)
4588 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
4589 || ! ieee_write_byte (info, 2)
4590 || ! ieee_write_number (info, 0)
4591 || ! ieee_write_id (info, ""))
4596 /* Push the new type on the type stack, write out an NN record, and
4597 write out the start of a TY record. The caller will then finish
4599 if (! ieee_push_type (info, type_indx, size, unsignedp, localp))
4602 return (ieee_write_byte (info, (int) ieee_nn_record)
4603 && ieee_write_number (info, name_indx)
4604 && ieee_write_id (info, name)
4605 && ieee_write_byte (info, (int) ieee_ty_record_enum)
4606 && ieee_write_number (info, type_indx)
4607 && ieee_write_byte (info, 0xce)
4608 && ieee_write_number (info, name_indx));
4611 /* Get an entry to the list of modified versions of a type. */
4613 static struct ieee_modified_type *
4614 ieee_get_modified_info (info, indx)
4615 struct ieee_handle *info;
4618 if (indx >= info->modified_alloc)
4620 unsigned int nalloc;
4622 nalloc = info->modified_alloc;
4625 while (indx >= nalloc)
4627 info->modified = ((struct ieee_modified_type *)
4628 xrealloc (info->modified,
4629 nalloc * sizeof *info->modified));
4630 memset (info->modified + info->modified_alloc, 0,
4631 (nalloc - info->modified_alloc) * sizeof *info->modified);
4632 info->modified_alloc = nalloc;
4635 return info->modified + indx;
4638 /* Routines for the hash table mapping names to types. */
4640 /* Initialize an entry in the hash table. */
4642 static struct bfd_hash_entry *
4643 ieee_name_type_newfunc (entry, table, string)
4644 struct bfd_hash_entry *entry;
4645 struct bfd_hash_table *table;
4648 struct ieee_name_type_hash_entry *ret =
4649 (struct ieee_name_type_hash_entry *) entry;
4651 /* Allocate the structure if it has not already been allocated by a
4654 ret = ((struct ieee_name_type_hash_entry *)
4655 bfd_hash_allocate (table, sizeof *ret));
4659 /* Call the allocation method of the superclass. */
4660 ret = ((struct ieee_name_type_hash_entry *)
4661 bfd_hash_newfunc ((struct bfd_hash_entry *) ret, table, string));
4664 /* Set local fields. */
4668 return (struct bfd_hash_entry *) ret;
4671 /* Look up an entry in the hash table. */
4673 #define ieee_name_type_hash_lookup(table, string, create, copy) \
4674 ((struct ieee_name_type_hash_entry *) \
4675 bfd_hash_lookup (&(table)->root, (string), (create), (copy)))
4677 /* Traverse the hash table. */
4679 #define ieee_name_type_hash_traverse(table, func, info) \
4680 (bfd_hash_traverse \
4682 (boolean (*) PARAMS ((struct bfd_hash_entry *, PTR))) (func), \
4685 /* The general routine to write out IEEE debugging information. */
4688 write_ieee_debugging_info (abfd, dhandle)
4692 struct ieee_handle info;
4697 memset (&info, 0, sizeof info);
4699 info.type_indx = 256;
4700 info.name_indx = 32;
4702 if (! bfd_hash_table_init (&info.typedefs.root, ieee_name_type_newfunc)
4703 || ! bfd_hash_table_init (&info.tags.root, ieee_name_type_newfunc))
4706 if (! ieee_init_buffer (&info, &info.global_types)
4707 || ! ieee_init_buffer (&info, &info.data)
4708 || ! ieee_init_buffer (&info, &info.types)
4709 || ! ieee_init_buffer (&info, &info.vars)
4710 || ! ieee_init_buffer (&info, &info.cxx)
4711 || ! ieee_init_buffer (&info, &info.linenos)
4712 || ! ieee_init_buffer (&info, &info.fntype)
4713 || ! ieee_init_buffer (&info, &info.fnargs))
4716 if (! debug_write (dhandle, &ieee_fns, (PTR) &info))
4719 if (info.filename != NULL)
4721 if (! ieee_finish_compilation_unit (&info))
4725 /* Put any undefined tags in the global typedef information. */
4727 ieee_name_type_hash_traverse (&info.tags,
4728 ieee_write_undefined_tag,
4733 /* Prepend the global typedef information to the other data. */
4734 if (! ieee_buffer_emptyp (&info.global_types))
4736 if (! ieee_change_buffer (&info, &info.global_types)
4737 || ! ieee_write_byte (&info, (int) ieee_be_record_enum))
4740 if (! ieee_append_buffer (&info, &info.global_types, &info.data))
4742 info.data = info.global_types;
4745 /* Make sure that we have declare BB11 blocks for each range in the
4746 file. They are added to info->vars. */
4748 if (! ieee_init_buffer (&info, &info.vars))
4750 bfd_map_over_sections (abfd, ieee_add_bb11_blocks, (PTR) &info);
4753 if (! ieee_buffer_emptyp (&info.vars))
4755 if (! ieee_change_buffer (&info, &info.vars)
4756 || ! ieee_write_byte (&info, (int) ieee_be_record_enum))
4759 if (! ieee_append_buffer (&info, &info.data, &info.vars))
4763 /* Now all the data is in info.data. Write it out to the BFD. We
4764 normally would need to worry about whether all the other sections
4765 are set up yet, but the IEEE backend will handle this particular
4766 case correctly regardless. */
4767 if (ieee_buffer_emptyp (&info.data))
4769 /* There is no debugging information. */
4773 s = bfd_make_section (abfd, ".debug");
4775 err = "bfd_make_section";
4778 if (! bfd_set_section_flags (abfd, s, SEC_DEBUGGING | SEC_HAS_CONTENTS))
4779 err = "bfd_set_section_flags";
4786 for (b = info.data.head; b != NULL; b = b->next)
4788 if (! bfd_set_section_size (abfd, s, size))
4789 err = "bfd_set_section_size";
4796 for (b = info.data.head; b != NULL; b = b->next)
4798 if (! bfd_set_section_contents (abfd, s, b->buf, offset, b->c))
4800 err = "bfd_set_section_contents";
4809 fprintf (stderr, "%s: %s: %s\n", bfd_get_filename (abfd), err,
4810 bfd_errmsg (bfd_get_error ()));
4814 bfd_hash_table_free (&info.typedefs.root);
4815 bfd_hash_table_free (&info.tags.root);
4820 /* Write out information for an undefined tag. This is called via
4821 ieee_name_type_hash_traverse. */
4824 ieee_write_undefined_tag (h, p)
4825 struct ieee_name_type_hash_entry *h;
4828 struct ieee_handle *info = (struct ieee_handle *) p;
4829 struct ieee_name_type *nt;
4831 for (nt = h->types; nt != NULL; nt = nt->next)
4833 unsigned int name_indx;
4836 if (nt->kind == DEBUG_KIND_ILLEGAL)
4839 if (ieee_buffer_emptyp (&info->global_types))
4841 if (! ieee_change_buffer (info, &info->global_types)
4842 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
4843 || ! ieee_write_byte (info, 2)
4844 || ! ieee_write_number (info, 0)
4845 || ! ieee_write_id (info, ""))
4853 if (! ieee_change_buffer (info, &info->global_types))
4860 name_indx = info->name_indx;
4862 if (! ieee_write_byte (info, (int) ieee_nn_record)
4863 || ! ieee_write_number (info, name_indx)
4864 || ! ieee_write_id (info, nt->type.name)
4865 || ! ieee_write_byte (info, (int) ieee_ty_record_enum)
4866 || ! ieee_write_number (info, nt->type.indx)
4867 || ! ieee_write_byte (info, 0xce)
4868 || ! ieee_write_number (info, name_indx))
4880 case DEBUG_KIND_STRUCT:
4881 case DEBUG_KIND_CLASS:
4884 case DEBUG_KIND_UNION:
4885 case DEBUG_KIND_UNION_CLASS:
4888 case DEBUG_KIND_ENUM:
4892 if (! ieee_write_number (info, code)
4893 || ! ieee_write_number (info, 0))
4903 /* Start writing out information for a compilation unit. */
4906 ieee_start_compilation_unit (p, filename)
4908 const char *filename;
4910 struct ieee_handle *info = (struct ieee_handle *) p;
4911 const char *modname;
4915 if (info->filename != NULL)
4917 if (! ieee_finish_compilation_unit (info))
4921 info->filename = filename;
4922 modname = strrchr (filename, '/');
4923 if (modname != NULL)
4927 modname = strrchr (filename, '\\');
4928 if (modname != NULL)
4933 c = xstrdup (modname);
4934 s = strrchr (c, '.');
4939 if (! ieee_init_buffer (info, &info->types)
4940 || ! ieee_init_buffer (info, &info->vars)
4941 || ! ieee_init_buffer (info, &info->cxx)
4942 || ! ieee_init_buffer (info, &info->linenos))
4944 info->ranges = NULL;
4946 /* Always include a BB1 and a BB3 block. That is what the output of
4947 the MRI linker seems to look like. */
4948 if (! ieee_change_buffer (info, &info->types)
4949 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
4950 || ! ieee_write_byte (info, 1)
4951 || ! ieee_write_number (info, 0)
4952 || ! ieee_write_id (info, info->modname))
4955 nindx = info->name_indx;
4957 if (! ieee_change_buffer (info, &info->vars)
4958 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
4959 || ! ieee_write_byte (info, 3)
4960 || ! ieee_write_number (info, 0)
4961 || ! ieee_write_id (info, info->modname))
4967 /* Finish up a compilation unit. */
4970 ieee_finish_compilation_unit (info)
4971 struct ieee_handle *info;
4973 struct ieee_range *r;
4975 if (! ieee_buffer_emptyp (&info->types))
4977 if (! ieee_change_buffer (info, &info->types)
4978 || ! ieee_write_byte (info, (int) ieee_be_record_enum))
4982 if (! ieee_buffer_emptyp (&info->cxx))
4984 /* Append any C++ information to the global function and
4985 variable information. */
4986 assert (! ieee_buffer_emptyp (&info->vars));
4987 if (! ieee_change_buffer (info, &info->vars))
4990 /* We put the pmisc records in a dummy procedure, just as the
4991 MRI compiler does. */
4992 if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
4993 || ! ieee_write_byte (info, 6)
4994 || ! ieee_write_number (info, 0)
4995 || ! ieee_write_id (info, "__XRYCPP")
4996 || ! ieee_write_number (info, 0)
4997 || ! ieee_write_number (info, 0)
4998 || ! ieee_write_number (info, info->highaddr - 1)
4999 || ! ieee_append_buffer (info, &info->vars, &info->cxx)
5000 || ! ieee_change_buffer (info, &info->vars)
5001 || ! ieee_write_byte (info, (int) ieee_be_record_enum)
5002 || ! ieee_write_number (info, info->highaddr - 1))
5006 if (! ieee_buffer_emptyp (&info->vars))
5008 if (! ieee_change_buffer (info, &info->vars)
5009 || ! ieee_write_byte (info, (int) ieee_be_record_enum))
5013 if (info->pending_lineno_filename != NULL)
5015 /* Force out the pending line number. */
5016 if (! ieee_lineno ((PTR) info, (const char *) NULL, 0, (bfd_vma) -1))
5019 if (! ieee_buffer_emptyp (&info->linenos))
5021 if (! ieee_change_buffer (info, &info->linenos)
5022 || ! ieee_write_byte (info, (int) ieee_be_record_enum))
5024 if (strcmp (info->filename, info->lineno_filename) != 0)
5026 /* We were not in the main file. We just closed the
5027 included line number block, and now we must close the
5028 main line number block. */
5029 if (! ieee_write_byte (info, (int) ieee_be_record_enum))
5034 if (! ieee_append_buffer (info, &info->data, &info->types)
5035 || ! ieee_append_buffer (info, &info->data, &info->vars)
5036 || ! ieee_append_buffer (info, &info->data, &info->linenos))
5039 /* Build BB10/BB11 blocks based on the ranges we recorded. */
5040 if (! ieee_change_buffer (info, &info->data))
5043 if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
5044 || ! ieee_write_byte (info, 10)
5045 || ! ieee_write_number (info, 0)
5046 || ! ieee_write_id (info, info->modname)
5047 || ! ieee_write_id (info, "")
5048 || ! ieee_write_number (info, 0)
5049 || ! ieee_write_id (info, "GNU objcopy"))
5052 for (r = info->ranges; r != NULL; r = r->next)
5061 /* Find the section corresponding to this range. */
5062 for (s = info->abfd->sections; s != NULL; s = s->next)
5064 if (bfd_get_section_vma (info->abfd, s) <= low
5065 && high <= (bfd_get_section_vma (info->abfd, s)
5066 + bfd_section_size (info->abfd, s)))
5072 /* Just ignore this range. */
5076 /* Coalesce ranges if it seems reasonable. */
5077 while (r->next != NULL
5078 && high + 64 >= r->next->low
5080 <= (bfd_get_section_vma (info->abfd, s)
5081 + bfd_section_size (info->abfd, s))))
5087 if ((s->flags & SEC_CODE) != 0)
5089 else if ((s->flags & SEC_READONLY) != 0)
5094 if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
5095 || ! ieee_write_byte (info, 11)
5096 || ! ieee_write_number (info, 0)
5097 || ! ieee_write_id (info, "")
5098 || ! ieee_write_number (info, kind)
5099 || ! ieee_write_number (info, s->index + IEEE_SECTION_NUMBER_BASE)
5100 || ! ieee_write_number (info, low)
5101 || ! ieee_write_byte (info, (int) ieee_be_record_enum)
5102 || ! ieee_write_number (info, high - low))
5105 /* Add this range to the list of global ranges. */
5106 if (! ieee_add_range (info, true, low, high))
5110 if (! ieee_write_byte (info, (int) ieee_be_record_enum))
5116 /* Add BB11 blocks describing each range that we have not already
5120 ieee_add_bb11_blocks (abfd, sec, data)
5125 struct ieee_handle *info = (struct ieee_handle *) data;
5127 struct ieee_range *r;
5129 low = bfd_get_section_vma (abfd, sec);
5130 high = low + bfd_section_size (abfd, sec);
5132 /* Find the first range at or after this section. The ranges are
5133 sorted by address. */
5134 for (r = info->global_ranges; r != NULL; r = r->next)
5140 if (r == NULL || r->low >= high)
5142 if (! ieee_add_bb11 (info, sec, low, high))
5149 if (! ieee_add_bb11 (info, sec, low, r->low))
5161 /* Add a single BB11 block for a range. We add it to info->vars. */
5164 ieee_add_bb11 (info, sec, low, high)
5165 struct ieee_handle *info;
5172 if (! ieee_buffer_emptyp (&info->vars))
5174 if (! ieee_change_buffer (info, &info->vars))
5179 const char *filename, *modname;
5182 /* Start the enclosing BB10 block. */
5183 filename = bfd_get_filename (info->abfd);
5184 modname = strrchr (filename, '/');
5185 if (modname != NULL)
5189 modname = strrchr (filename, '\\');
5190 if (modname != NULL)
5195 c = xstrdup (modname);
5196 s = strrchr (c, '.');
5200 if (! ieee_change_buffer (info, &info->vars)
5201 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
5202 || ! ieee_write_byte (info, 10)
5203 || ! ieee_write_number (info, 0)
5204 || ! ieee_write_id (info, c)
5205 || ! ieee_write_id (info, "")
5206 || ! ieee_write_number (info, 0)
5207 || ! ieee_write_id (info, "GNU objcopy"))
5213 if ((sec->flags & SEC_CODE) != 0)
5215 else if ((sec->flags & SEC_READONLY) != 0)
5220 if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
5221 || ! ieee_write_byte (info, 11)
5222 || ! ieee_write_number (info, 0)
5223 || ! ieee_write_id (info, "")
5224 || ! ieee_write_number (info, kind)
5225 || ! ieee_write_number (info, sec->index + IEEE_SECTION_NUMBER_BASE)
5226 || ! ieee_write_number (info, low)
5227 || ! ieee_write_byte (info, (int) ieee_be_record_enum)
5228 || ! ieee_write_number (info, high - low))
5234 /* Start recording information from a particular source file. This is
5235 used to record which file defined which types, variables, etc. It
5236 is not used for line numbers, since the lineno entry point passes
5237 down the file name anyhow. IEEE debugging information doesn't seem
5238 to store this information anywhere. */
5242 ieee_start_source (p, filename)
5244 const char *filename;
5249 /* Make an empty type. */
5255 struct ieee_handle *info = (struct ieee_handle *) p;
5257 return ieee_push_type (info, (int) builtin_unknown, 0, false, false);
5260 /* Make a void type. */
5266 struct ieee_handle *info = (struct ieee_handle *) p;
5268 return ieee_push_type (info, (int) builtin_void, 0, false, false);
5271 /* Make an integer type. */
5274 ieee_int_type (p, size, unsignedp)
5279 struct ieee_handle *info = (struct ieee_handle *) p;
5285 indx = (int) builtin_signed_char;
5288 indx = (int) builtin_signed_short_int;
5291 indx = (int) builtin_signed_long;
5294 indx = (int) builtin_signed_long_long;
5297 fprintf (stderr, "IEEE unsupported integer type size %u\n", size);
5304 return ieee_push_type (info, indx, size, unsignedp, false);
5307 /* Make a floating point type. */
5310 ieee_float_type (p, size)
5314 struct ieee_handle *info = (struct ieee_handle *) p;
5320 indx = (int) builtin_float;
5323 indx = (int) builtin_double;
5326 /* FIXME: This size really depends upon the processor. */
5327 indx = (int) builtin_long_double;
5330 indx = (int) builtin_long_long_double;
5333 fprintf (stderr, "IEEE unsupported float type size %u\n", size);
5337 return ieee_push_type (info, indx, size, false, false);
5340 /* Make a complex type. */
5343 ieee_complex_type (p, size)
5347 struct ieee_handle *info = (struct ieee_handle *) p;
5353 if (info->complex_float_index != 0)
5354 return ieee_push_type (info, info->complex_float_index, size * 2,
5360 /* These cases can be output by gcc -gstabs. Outputting the
5361 wrong type is better than crashing. */
5363 if (info->complex_double_index != 0)
5364 return ieee_push_type (info, info->complex_double_index, size * 2,
5369 fprintf (stderr, "IEEE unsupported complex type size %u\n", size);
5373 /* FIXME: I don't know what the string is for. */
5374 if (! ieee_define_type (info, size * 2, false, false)
5375 || ! ieee_write_number (info, code)
5376 || ! ieee_write_id (info, ""))
5380 info->complex_float_index = info->type_stack->type.indx;
5382 info->complex_double_index = info->type_stack->type.indx;
5387 /* Make a boolean type. IEEE doesn't support these, so we just make
5388 an integer type instead. */
5391 ieee_bool_type (p, size)
5395 return ieee_int_type (p, size, true);
5398 /* Make an enumeration. */
5401 ieee_enum_type (p, tag, names, vals)
5405 bfd_signed_vma *vals;
5407 struct ieee_handle *info = (struct ieee_handle *) p;
5408 struct ieee_defined_enum *e;
5409 boolean localp, simple;
5413 for (e = info->enums; e != NULL; e = e->next)
5423 || tag[0] != e->tag[0]
5424 || strcmp (tag, e->tag) != 0)
5428 if (names != NULL && e->names != NULL)
5430 for (i = 0; names[i] != NULL && e->names[i] != NULL; i++)
5432 if (names[i][0] != e->names[i][0]
5433 || vals[i] != e->vals[i]
5434 || strcmp (names[i], e->names[i]) != 0)
5439 if ((names == NULL && e->names == NULL)
5443 && e->names[i] == NULL))
5445 /* We've seen this enum before. */
5446 return ieee_push_type (info, e->indx, 0, true, false);
5451 /* We've already seen an enum of the same name, so we must make
5452 sure to output this one locally. */
5458 /* If this is a simple enumeration, in which the values start at 0
5459 and always increment by 1, we can use type E. Otherwise we must
5465 for (i = 0; names[i] != NULL; i++)
5475 if (! ieee_define_named_type (info, tag, (unsigned int) -1, 0,
5476 true, localp, (struct ieee_buflist *) NULL)
5477 || ! ieee_write_number (info, simple ? 'E' : 'N'))
5481 /* FIXME: This is supposed to be the enumeration size, but we
5482 don't store that. */
5483 if (! ieee_write_number (info, 4))
5488 for (i = 0; names[i] != NULL; i++)
5490 if (! ieee_write_id (info, names[i]))
5494 if (! ieee_write_number (info, vals[i]))
5502 e = (struct ieee_defined_enum *) xmalloc (sizeof *e);
5503 memset (e, 0, sizeof *e);
5505 e->indx = info->type_stack->type.indx;
5510 e->next = info->enums;
5517 /* Make a pointer type. The HP debugger seems to sometimes get
5518 confused by global pointers to global pointers. Therefore, we mark
5519 all pointers as reflocalp, so that references to global pointers are
5520 forced to be local. This is probably less efficient than possible. */
5523 ieee_pointer_type (p)
5526 struct ieee_handle *info = (struct ieee_handle *) p;
5529 struct ieee_modified_type *m = NULL;
5531 localp = info->type_stack->type.localp || info->type_stack->type.reflocalp;
5532 indx = ieee_pop_type (info);
5534 /* A pointer to a simple builtin type can be obtained by adding 32.
5535 FIXME: Will this be a short pointer, and will that matter? */
5538 if (! ieee_push_type (info, indx + 32, 0, true, false))
5540 /* I don't think we need to set reflocalp for this case. */
5546 m = ieee_get_modified_info (p, indx);
5550 /* FIXME: The size should depend upon the architecture. */
5553 if (! ieee_push_type (info, m->pointer, 4, true, false))
5555 info->type_stack->type.reflocalp = true;
5560 if (! ieee_define_type (info, 4, true, localp)
5561 || ! ieee_write_number (info, 'P')
5562 || ! ieee_write_number (info, indx))
5566 m->pointer = info->type_stack->type.indx;
5568 info->type_stack->type.reflocalp = true;
5573 /* Make a function type. This will be called for a method, but we
5574 don't want to actually add it to the type table in that case. We
5575 handle this by defining the type in a private buffer, and only
5576 adding that buffer to the typedef block if we are going to use it. */
5579 ieee_function_type (p, argcount, varargs)
5584 struct ieee_handle *info = (struct ieee_handle *) p;
5586 unsigned int *args = NULL;
5588 unsigned int retindx;
5589 struct ieee_buflist fndef;
5590 struct ieee_modified_type *m;
5596 args = (unsigned int *) xmalloc (argcount * sizeof *args);
5597 for (i = argcount - 1; i >= 0; i--)
5599 if (info->type_stack->type.localp
5600 || info->type_stack->type.reflocalp)
5602 args[i] = ieee_pop_type (info);
5605 else if (argcount < 0)
5608 if (info->type_stack->type.localp || info->type_stack->type.reflocalp)
5610 retindx = ieee_pop_type (info);
5613 if (argcount < 0 && ! localp)
5615 m = ieee_get_modified_info (p, retindx);
5619 if (m->function > 0)
5620 return ieee_push_type (info, m->function, 0, true, false);
5623 /* An attribute of 0x41 means that the frame and push mask are
5625 if (! ieee_init_buffer (info, &fndef)
5626 || ! ieee_define_named_type (info, (const char *) NULL,
5627 (unsigned int) -1, 0, true, localp,
5629 || ! ieee_write_number (info, 'x')
5630 || ! ieee_write_number (info, 0x41)
5631 || ! ieee_write_number (info, 0)
5632 || ! ieee_write_number (info, 0)
5633 || ! ieee_write_number (info, retindx)
5634 || ! ieee_write_number (info, (bfd_vma) argcount + (varargs ? 1 : 0)))
5638 for (i = 0; i < argcount; i++)
5639 if (! ieee_write_number (info, args[i]))
5645 /* A varargs function is represented by writing out the last
5646 argument as type void *, although this makes little sense. */
5647 if (! ieee_write_number (info, (bfd_vma) builtin_void + 32))
5651 if (! ieee_write_number (info, 0))
5654 /* We wrote the information into fndef, in case we don't need it.
5655 It will be appended to info->types by ieee_pop_type. */
5656 info->type_stack->type.fndef = fndef;
5659 m->function = info->type_stack->type.indx;
5664 /* Make a reference type. */
5667 ieee_reference_type (p)
5670 struct ieee_handle *info = (struct ieee_handle *) p;
5672 /* IEEE appears to record a normal pointer type, and then use a
5673 pmisc record to indicate that it is really a reference. */
5675 if (! ieee_pointer_type (p))
5677 info->type_stack->type.referencep = true;
5681 /* Make a range type. */
5684 ieee_range_type (p, low, high)
5687 bfd_signed_vma high;
5689 struct ieee_handle *info = (struct ieee_handle *) p;
5691 boolean unsignedp, localp;
5693 size = info->type_stack->type.size;
5694 unsignedp = info->type_stack->type.unsignedp;
5695 localp = info->type_stack->type.localp || info->type_stack->type.reflocalp;
5696 ieee_pop_unused_type (info);
5697 return (ieee_define_type (info, size, unsignedp, localp)
5698 && ieee_write_number (info, 'R')
5699 && ieee_write_number (info, (bfd_vma) low)
5700 && ieee_write_number (info, (bfd_vma) high)
5701 && ieee_write_number (info, unsignedp ? 0 : 1)
5702 && ieee_write_number (info, size));
5705 /* Make an array type. */
5709 ieee_array_type (p, low, high, stringp)
5712 bfd_signed_vma high;
5715 struct ieee_handle *info = (struct ieee_handle *) p;
5716 unsigned int eleindx;
5718 struct ieee_modified_type *m = NULL;
5719 struct ieee_modified_array_type *a;
5721 /* IEEE does not store the range, so we just ignore it. */
5722 ieee_pop_unused_type (info);
5723 localp = info->type_stack->type.localp || info->type_stack->type.reflocalp;
5724 eleindx = ieee_pop_type (info);
5728 m = ieee_get_modified_info (info, eleindx);
5732 for (a = m->arrays; a != NULL; a = a->next)
5734 if (a->low == low && a->high == high)
5735 return ieee_push_type (info, a->indx, 0, false, false);
5739 if (! ieee_define_type (info, 0, false, localp)
5740 || ! ieee_write_number (info, low == 0 ? 'Z' : 'C')
5741 || ! ieee_write_number (info, eleindx))
5745 if (! ieee_write_number (info, low))
5749 if (! ieee_write_number (info, high + 1))
5754 a = (struct ieee_modified_array_type *) xmalloc (sizeof *a);
5755 memset (a, 0, sizeof *a);
5757 a->indx = info->type_stack->type.indx;
5761 a->next = m->arrays;
5768 /* Make a set type. */
5771 ieee_set_type (p, bitstringp)
5775 struct ieee_handle *info = (struct ieee_handle *) p;
5777 unsigned int eleindx;
5779 localp = info->type_stack->type.localp || info->type_stack->type.reflocalp;
5780 eleindx = ieee_pop_type (info);
5782 /* FIXME: We don't know the size, so we just use 4. */
5784 return (ieee_define_type (info, 0, true, localp)
5785 && ieee_write_number (info, 's')
5786 && ieee_write_number (info, 4)
5787 && ieee_write_number (info, eleindx));
5790 /* Make an offset type. */
5793 ieee_offset_type (p)
5796 struct ieee_handle *info = (struct ieee_handle *) p;
5797 unsigned int targetindx, baseindx;
5799 targetindx = ieee_pop_type (info);
5800 baseindx = ieee_pop_type (info);
5802 /* FIXME: The MRI C++ compiler does not appear to generate any
5803 useful type information about an offset type. It just records a
5804 pointer to member as an integer. The MRI/HP IEEE spec does
5805 describe a pmisc record which can be used for a pointer to
5806 member. Unfortunately, it does not describe the target type,
5807 which seems pretty important. I'm going to punt this for now. */
5809 return ieee_int_type (p, 4, true);
5812 /* Make a method type. */
5815 ieee_method_type (p, domain, argcount, varargs)
5821 struct ieee_handle *info = (struct ieee_handle *) p;
5823 /* FIXME: The MRI/HP IEEE spec defines a pmisc record to use for a
5824 method, but the definition is incomplete. We just output an 'x'
5828 ieee_pop_unused_type (info);
5830 return ieee_function_type (p, argcount, varargs);
5833 /* Make a const qualified type. */
5839 struct ieee_handle *info = (struct ieee_handle *) p;
5841 boolean unsignedp, localp;
5843 struct ieee_modified_type *m = NULL;
5845 size = info->type_stack->type.size;
5846 unsignedp = info->type_stack->type.unsignedp;
5847 localp = info->type_stack->type.localp || info->type_stack->type.reflocalp;
5848 indx = ieee_pop_type (info);
5852 m = ieee_get_modified_info (info, indx);
5856 if (m->const_qualified > 0)
5857 return ieee_push_type (info, m->const_qualified, size, unsignedp,
5861 if (! ieee_define_type (info, size, unsignedp, localp)
5862 || ! ieee_write_number (info, 'n')
5863 || ! ieee_write_number (info, 1)
5864 || ! ieee_write_number (info, indx))
5868 m->const_qualified = info->type_stack->type.indx;
5873 /* Make a volatile qualified type. */
5876 ieee_volatile_type (p)
5879 struct ieee_handle *info = (struct ieee_handle *) p;
5881 boolean unsignedp, localp;
5883 struct ieee_modified_type *m = NULL;
5885 size = info->type_stack->type.size;
5886 unsignedp = info->type_stack->type.unsignedp;
5887 localp = info->type_stack->type.localp || info->type_stack->type.reflocalp;
5888 indx = ieee_pop_type (info);
5892 m = ieee_get_modified_info (info, indx);
5896 if (m->volatile_qualified > 0)
5897 return ieee_push_type (info, m->volatile_qualified, size, unsignedp,
5901 if (! ieee_define_type (info, size, unsignedp, localp)
5902 || ! ieee_write_number (info, 'n')
5903 || ! ieee_write_number (info, 2)
5904 || ! ieee_write_number (info, indx))
5908 m->volatile_qualified = info->type_stack->type.indx;
5913 /* Convert an enum debug_visibility into a CXXFLAGS value. */
5916 ieee_vis_to_flags (visibility)
5917 enum debug_visibility visibility;
5923 case DEBUG_VISIBILITY_PUBLIC:
5924 return CXXFLAGS_VISIBILITY_PUBLIC;
5925 case DEBUG_VISIBILITY_PRIVATE:
5926 return CXXFLAGS_VISIBILITY_PRIVATE;
5927 case DEBUG_VISIBILITY_PROTECTED:
5928 return CXXFLAGS_VISIBILITY_PROTECTED;
5933 /* Start defining a struct type. We build it in the strdef field on
5934 the stack, to avoid confusing type definitions required by the
5935 fields with the struct type itself. */
5938 ieee_start_struct_type (p, tag, id, structp, size)
5945 struct ieee_handle *info = (struct ieee_handle *) p;
5946 boolean localp, ignorep;
5950 struct ieee_name_type_hash_entry *h;
5951 struct ieee_name_type *nt, *ntlook;
5952 struct ieee_buflist strdef;
5957 /* We need to create a tag for internal use even if we don't want
5958 one for external use. This will let us refer to an anonymous
5967 sprintf (ab, "__anon%u", id);
5972 /* If we already have references to the tag, we must use the
5973 existing type index. */
5974 h = ieee_name_type_hash_lookup (&info->tags, look, true, copy);
5979 for (ntlook = h->types; ntlook != NULL; ntlook = ntlook->next)
5981 if (ntlook->id == id)
5983 else if (! ntlook->type.localp)
5985 /* We are creating a duplicate definition of a globally
5986 defined tag. Force it to be local to avoid
5994 assert (localp == nt->type.localp);
5995 if (nt->kind == DEBUG_KIND_ILLEGAL && ! localp)
5997 /* We've already seen a global definition of the type.
5998 Ignore this new definition. */
6004 nt = (struct ieee_name_type *) xmalloc (sizeof *nt);
6005 memset (nt, 0, sizeof *nt);
6007 nt->type.name = h->root.string;
6008 nt->next = h->types;
6010 nt->type.indx = info->type_indx;
6014 nt->kind = DEBUG_KIND_ILLEGAL;
6016 if (! ieee_init_buffer (info, &strdef)
6017 || ! ieee_define_named_type (info, tag, nt->type.indx, size, true,
6019 || ! ieee_write_number (info, structp ? 'S' : 'U')
6020 || ! ieee_write_number (info, size))
6027 /* We never want nt->type.name to be NULL. We want the rest of
6028 the type to be the object set up on the type stack; it will
6029 have a NULL name if tag is NULL. */
6030 hold = nt->type.name;
6031 nt->type = info->type_stack->type;
6032 nt->type.name = hold;
6035 info->type_stack->type.name = tag;
6036 info->type_stack->type.strdef = strdef;
6037 info->type_stack->type.ignorep = ignorep;
6042 /* Add a field to a struct. */
6045 ieee_struct_field (p, name, bitpos, bitsize, visibility)
6050 enum debug_visibility visibility;
6052 struct ieee_handle *info = (struct ieee_handle *) p;
6060 assert (info->type_stack != NULL
6061 && info->type_stack->next != NULL
6062 && ! ieee_buffer_emptyp (&info->type_stack->next->type.strdef));
6064 /* If we are ignoring this struct definition, just pop and ignore
6066 if (info->type_stack->next->type.ignorep)
6068 ieee_pop_unused_type (info);
6072 size = info->type_stack->type.size;
6073 unsignedp = info->type_stack->type.unsignedp;
6074 referencep = info->type_stack->type.referencep;
6075 localp = info->type_stack->type.localp || info->type_stack->type.reflocalp;
6076 indx = ieee_pop_type (info);
6079 info->type_stack->type.localp = true;
6081 if (info->type_stack->type.classdef != NULL)
6086 /* This is a class. We must add a description of this field to
6087 the class records we are building. */
6089 flags = ieee_vis_to_flags (visibility);
6090 nindx = info->type_stack->type.classdef->indx;
6091 if (! ieee_change_buffer (info,
6092 &info->type_stack->type.classdef->pmiscbuf)
6093 || ! ieee_write_asn (info, nindx, 'd')
6094 || ! ieee_write_asn (info, nindx, flags)
6095 || ! ieee_write_atn65 (info, nindx, name)
6096 || ! ieee_write_atn65 (info, nindx, name))
6098 info->type_stack->type.classdef->pmisccount += 4;
6104 /* We need to output a record recording that this field is
6105 really of reference type. We put this on the refs field
6106 of classdef, so that it can be appended to the C++
6107 records after the class is defined. */
6109 nindx = info->name_indx;
6112 if (! ieee_change_buffer (info,
6113 &info->type_stack->type.classdef->refs)
6114 || ! ieee_write_byte (info, (int) ieee_nn_record)
6115 || ! ieee_write_number (info, nindx)
6116 || ! ieee_write_id (info, "")
6117 || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
6118 || ! ieee_write_number (info, nindx)
6119 || ! ieee_write_number (info, 0)
6120 || ! ieee_write_number (info, 62)
6121 || ! ieee_write_number (info, 80)
6122 || ! ieee_write_number (info, 4)
6123 || ! ieee_write_asn (info, nindx, 'R')
6124 || ! ieee_write_asn (info, nindx, 3)
6125 || ! ieee_write_atn65 (info, nindx, info->type_stack->type.name)
6126 || ! ieee_write_atn65 (info, nindx, name))
6131 /* If the bitsize doesn't match the expected size, we need to output
6133 if (size == 0 || bitsize == 0 || bitsize == size * 8)
6134 offset = bitpos / 8;
6137 if (! ieee_define_type (info, 0, unsignedp,
6138 info->type_stack->type.localp)
6139 || ! ieee_write_number (info, 'g')
6140 || ! ieee_write_number (info, unsignedp ? 0 : 1)
6141 || ! ieee_write_number (info, bitsize)
6142 || ! ieee_write_number (info, indx))
6144 indx = ieee_pop_type (info);
6148 /* Switch to the struct we are building in order to output this
6149 field definition. */
6150 return (ieee_change_buffer (info, &info->type_stack->type.strdef)
6151 && ieee_write_id (info, name)
6152 && ieee_write_number (info, indx)
6153 && ieee_write_number (info, offset));
6156 /* Finish up a struct type. */
6159 ieee_end_struct_type (p)
6162 struct ieee_handle *info = (struct ieee_handle *) p;
6163 struct ieee_buflist *pb;
6165 assert (info->type_stack != NULL
6166 && ! ieee_buffer_emptyp (&info->type_stack->type.strdef));
6168 /* If we were ignoring this struct definition because it was a
6169 duplicate defintion, just through away whatever bytes we have
6170 accumulated. Leave the type on the stack. */
6171 if (info->type_stack->type.ignorep)
6174 /* If this is not a duplicate definition of this tag, then localp
6175 will be false, and we can put it in the global type block.
6176 FIXME: We should avoid outputting duplicate definitions which are
6178 if (! info->type_stack->type.localp)
6180 /* Make sure we have started the global type block. */
6181 if (ieee_buffer_emptyp (&info->global_types))
6183 if (! ieee_change_buffer (info, &info->global_types)
6184 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
6185 || ! ieee_write_byte (info, 2)
6186 || ! ieee_write_number (info, 0)
6187 || ! ieee_write_id (info, ""))
6190 pb = &info->global_types;
6194 /* Make sure we have started the types block. */
6195 if (ieee_buffer_emptyp (&info->types))
6197 if (! ieee_change_buffer (info, &info->types)
6198 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
6199 || ! ieee_write_byte (info, 1)
6200 || ! ieee_write_number (info, 0)
6201 || ! ieee_write_id (info, info->modname))
6207 /* Append the struct definition to the types. */
6208 if (! ieee_append_buffer (info, pb, &info->type_stack->type.strdef)
6209 || ! ieee_init_buffer (info, &info->type_stack->type.strdef))
6212 /* Leave the struct on the type stack. */
6217 /* Start a class type. */
6220 ieee_start_class_type (p, tag, id, structp, size, vptr, ownvptr)
6229 struct ieee_handle *info = (struct ieee_handle *) p;
6231 struct ieee_buflist pmiscbuf;
6233 struct ieee_type_class *classdef;
6235 /* A C++ class is output as a C++ struct along with a set of pmisc
6236 records describing the class. */
6238 /* We need to have a name so that we can associate the struct and
6244 t = (char *) xmalloc (20);
6245 sprintf (t, "__anon%u", id);
6249 /* We can't write out the virtual table information until we have
6250 finished the class, because we don't know the virtual table size.
6251 We get the size from the largest voffset we see. */
6253 if (vptr && ! ownvptr)
6255 vclass = info->type_stack->type.name;
6256 assert (vclass != NULL);
6257 /* We don't call ieee_pop_unused_type, since the class should
6259 (void) ieee_pop_type (info);
6262 if (! ieee_start_struct_type (p, tag, id, structp, size))
6265 indx = info->name_indx;
6268 /* We write out pmisc records into the classdef field. We will
6269 write out the pmisc start after we know the number of records we
6271 if (! ieee_init_buffer (info, &pmiscbuf)
6272 || ! ieee_change_buffer (info, &pmiscbuf)
6273 || ! ieee_write_asn (info, indx, 'T')
6274 || ! ieee_write_asn (info, indx, structp ? 'o' : 'u')
6275 || ! ieee_write_atn65 (info, indx, tag))
6278 classdef = (struct ieee_type_class *) xmalloc (sizeof *classdef);
6279 memset (classdef, 0, sizeof *classdef);
6281 classdef->indx = indx;
6282 classdef->pmiscbuf = pmiscbuf;
6283 classdef->pmisccount = 3;
6284 classdef->vclass = vclass;
6285 classdef->ownvptr = ownvptr;
6287 info->type_stack->type.classdef = classdef;
6292 /* Add a static member to a class. */
6295 ieee_class_static_member (p, name, physname, visibility)
6298 const char *physname;
6299 enum debug_visibility visibility;
6301 struct ieee_handle *info = (struct ieee_handle *) p;
6305 /* We don't care about the type. Hopefully there will be a call to
6306 ieee_variable declaring the physical name and the type, since
6307 that is where an IEEE consumer must get the type. */
6308 ieee_pop_unused_type (info);
6310 assert (info->type_stack != NULL
6311 && info->type_stack->type.classdef != NULL);
6313 flags = ieee_vis_to_flags (visibility);
6314 flags |= CXXFLAGS_STATIC;
6316 nindx = info->type_stack->type.classdef->indx;
6318 if (! ieee_change_buffer (info, &info->type_stack->type.classdef->pmiscbuf)
6319 || ! ieee_write_asn (info, nindx, 'd')
6320 || ! ieee_write_asn (info, nindx, flags)
6321 || ! ieee_write_atn65 (info, nindx, name)
6322 || ! ieee_write_atn65 (info, nindx, physname))
6324 info->type_stack->type.classdef->pmisccount += 4;
6329 /* Add a base class to a class. */
6332 ieee_class_baseclass (p, bitpos, virtual, visibility)
6336 enum debug_visibility visibility;
6338 struct ieee_handle *info = (struct ieee_handle *) p;
6346 assert (info->type_stack != NULL
6347 && info->type_stack->type.name != NULL
6348 && info->type_stack->next != NULL
6349 && info->type_stack->next->type.classdef != NULL
6350 && ! ieee_buffer_emptyp (&info->type_stack->next->type.strdef));
6352 bname = info->type_stack->type.name;
6353 localp = info->type_stack->type.localp || info->type_stack->type.reflocalp;
6354 bindx = ieee_pop_type (info);
6356 /* We are currently defining both a struct and a class. We must
6357 write out a field definition in the struct which holds the base
6358 class. The stabs debugging reader will create a field named
6359 _vb$CLASS for a virtual base class, so we just use that. FIXME:
6360 we should not depend upon a detail of stabs debugging. */
6363 fname = (char *) xmalloc (strlen (bname) + sizeof "_vb$");
6364 sprintf (fname, "_vb$%s", bname);
6365 flags = BASEFLAGS_VIRTUAL;
6370 info->type_stack->type.localp = true;
6372 fname = (char *) xmalloc (strlen (bname) + sizeof "_b$");
6373 sprintf (fname, "_b$%s", bname);
6375 if (! ieee_change_buffer (info, &info->type_stack->type.strdef)
6376 || ! ieee_write_id (info, fname)
6377 || ! ieee_write_number (info, bindx)
6378 || ! ieee_write_number (info, bitpos / 8))
6383 if (visibility == DEBUG_VISIBILITY_PRIVATE)
6384 flags |= BASEFLAGS_PRIVATE;
6386 nindx = info->type_stack->type.classdef->indx;
6388 if (! ieee_change_buffer (info, &info->type_stack->type.classdef->pmiscbuf)
6389 || ! ieee_write_asn (info, nindx, 'b')
6390 || ! ieee_write_asn (info, nindx, flags)
6391 || ! ieee_write_atn65 (info, nindx, bname)
6392 || ! ieee_write_asn (info, nindx, 0)
6393 || ! ieee_write_atn65 (info, nindx, fname))
6395 info->type_stack->type.classdef->pmisccount += 5;
6402 /* Start building a method for a class. */
6405 ieee_class_start_method (p, name)
6409 struct ieee_handle *info = (struct ieee_handle *) p;
6411 assert (info->type_stack != NULL
6412 && info->type_stack->type.classdef != NULL
6413 && info->type_stack->type.classdef->method == NULL);
6415 info->type_stack->type.classdef->method = name;
6420 /* Define a new method variant, either static or not. */
6423 ieee_class_method_var (info, physname, visibility, staticp, constp,
6424 volatilep, voffset, context)
6425 struct ieee_handle *info;
6426 const char *physname;
6427 enum debug_visibility visibility;
6438 /* We don't need the type of the method. An IEEE consumer which
6439 wants the type must track down the function by the physical name
6440 and get the type from that. */
6441 ieee_pop_unused_type (info);
6443 /* We don't use the context. FIXME: We probably ought to use it to
6444 adjust the voffset somehow, but I don't really know how. */
6446 ieee_pop_unused_type (info);
6448 assert (info->type_stack != NULL
6449 && info->type_stack->type.classdef != NULL
6450 && info->type_stack->type.classdef->method != NULL);
6452 flags = ieee_vis_to_flags (visibility);
6454 /* FIXME: We never set CXXFLAGS_OVERRIDE, CXXFLAGS_OPERATOR,
6455 CXXFLAGS_CTORDTOR, CXXFLAGS_CTOR, or CXXFLAGS_INLINE. */
6458 flags |= CXXFLAGS_STATIC;
6460 flags |= CXXFLAGS_CONST;
6462 flags |= CXXFLAGS_VOLATILE;
6464 nindx = info->type_stack->type.classdef->indx;
6466 virtual = context || voffset > 0;
6468 if (! ieee_change_buffer (info,
6469 &info->type_stack->type.classdef->pmiscbuf)
6470 || ! ieee_write_asn (info, nindx, virtual ? 'v' : 'm')
6471 || ! ieee_write_asn (info, nindx, flags)
6472 || ! ieee_write_atn65 (info, nindx,
6473 info->type_stack->type.classdef->method)
6474 || ! ieee_write_atn65 (info, nindx, physname))
6479 if (voffset > info->type_stack->type.classdef->voffset)
6480 info->type_stack->type.classdef->voffset = voffset;
6481 if (! ieee_write_asn (info, nindx, voffset))
6483 ++info->type_stack->type.classdef->pmisccount;
6486 if (! ieee_write_asn (info, nindx, 0))
6489 info->type_stack->type.classdef->pmisccount += 5;
6494 /* Define a new method variant. */
6497 ieee_class_method_variant (p, physname, visibility, constp, volatilep,
6500 const char *physname;
6501 enum debug_visibility visibility;
6507 struct ieee_handle *info = (struct ieee_handle *) p;
6509 return ieee_class_method_var (info, physname, visibility, false, constp,
6510 volatilep, voffset, context);
6513 /* Define a new static method variant. */
6516 ieee_class_static_method_variant (p, physname, visibility, constp, volatilep)
6518 const char *physname;
6519 enum debug_visibility visibility;
6523 struct ieee_handle *info = (struct ieee_handle *) p;
6525 return ieee_class_method_var (info, physname, visibility, true, constp,
6526 volatilep, 0, false);
6529 /* Finish up a method. */
6532 ieee_class_end_method (p)
6535 struct ieee_handle *info = (struct ieee_handle *) p;
6537 assert (info->type_stack != NULL
6538 && info->type_stack->type.classdef != NULL
6539 && info->type_stack->type.classdef->method != NULL);
6541 info->type_stack->type.classdef->method = NULL;
6546 /* Finish up a class. */
6549 ieee_end_class_type (p)
6552 struct ieee_handle *info = (struct ieee_handle *) p;
6555 assert (info->type_stack != NULL
6556 && info->type_stack->type.classdef != NULL);
6558 /* If we were ignoring this class definition because it was a
6559 duplicate definition, just through away whatever bytes we have
6560 accumulated. Leave the type on the stack. */
6561 if (info->type_stack->type.ignorep)
6564 nindx = info->type_stack->type.classdef->indx;
6566 /* If we have a virtual table, we can write out the information now. */
6567 if (info->type_stack->type.classdef->vclass != NULL
6568 || info->type_stack->type.classdef->ownvptr)
6570 if (! ieee_change_buffer (info,
6571 &info->type_stack->type.classdef->pmiscbuf)
6572 || ! ieee_write_asn (info, nindx, 'z')
6573 || ! ieee_write_atn65 (info, nindx, "")
6574 || ! ieee_write_asn (info, nindx,
6575 info->type_stack->type.classdef->voffset))
6577 if (info->type_stack->type.classdef->ownvptr)
6579 if (! ieee_write_atn65 (info, nindx, ""))
6584 if (! ieee_write_atn65 (info, nindx,
6585 info->type_stack->type.classdef->vclass))
6588 if (! ieee_write_asn (info, nindx, 0))
6590 info->type_stack->type.classdef->pmisccount += 5;
6593 /* Now that we know the number of pmisc records, we can write out
6594 the atn62 which starts the pmisc records, and append them to the
6597 if (! ieee_change_buffer (info, &info->cxx)
6598 || ! ieee_write_byte (info, (int) ieee_nn_record)
6599 || ! ieee_write_number (info, nindx)
6600 || ! ieee_write_id (info, "")
6601 || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
6602 || ! ieee_write_number (info, nindx)
6603 || ! ieee_write_number (info, 0)
6604 || ! ieee_write_number (info, 62)
6605 || ! ieee_write_number (info, 80)
6606 || ! ieee_write_number (info,
6607 info->type_stack->type.classdef->pmisccount))
6610 if (! ieee_append_buffer (info, &info->cxx,
6611 &info->type_stack->type.classdef->pmiscbuf))
6613 if (! ieee_buffer_emptyp (&info->type_stack->type.classdef->refs))
6615 if (! ieee_append_buffer (info, &info->cxx,
6616 &info->type_stack->type.classdef->refs))
6620 return ieee_end_struct_type (p);
6623 /* Push a previously seen typedef onto the type stack. */
6626 ieee_typedef_type (p, name)
6630 struct ieee_handle *info = (struct ieee_handle *) p;
6631 struct ieee_name_type_hash_entry *h;
6632 struct ieee_name_type *nt;
6634 h = ieee_name_type_hash_lookup (&info->typedefs, name, false, false);
6636 /* h should never be NULL, since that would imply that the generic
6637 debugging code has asked for a typedef which it has not yet
6641 /* We always use the most recently defined type for this name, which
6642 will be the first one on the list. */
6645 if (! ieee_push_type (info, nt->type.indx, nt->type.size,
6646 nt->type.unsignedp, nt->type.localp))
6649 /* Copy over any other type information we may have. */
6650 info->type_stack->type = nt->type;
6655 /* Push a tagged type onto the type stack. */
6658 ieee_tag_type (p, name, id, kind)
6662 enum debug_type_kind kind;
6664 struct ieee_handle *info = (struct ieee_handle *) p;
6668 struct ieee_name_type_hash_entry *h;
6669 struct ieee_name_type *nt;
6671 if (kind == DEBUG_KIND_ENUM)
6673 struct ieee_defined_enum *e;
6677 for (e = info->enums; e != NULL; e = e->next)
6678 if (e->tag != NULL && strcmp (e->tag, name) == 0)
6679 return ieee_push_type (info, e->indx, 0, true, false);
6688 sprintf (ab, "__anon%u", id);
6693 h = ieee_name_type_hash_lookup (&info->tags, name, true, copy);
6697 for (nt = h->types; nt != NULL; nt = nt->next)
6701 if (! ieee_push_type (info, nt->type.indx, nt->type.size,
6702 nt->type.unsignedp, nt->type.localp))
6704 /* Copy over any other type information we may have. */
6705 info->type_stack->type = nt->type;
6709 if (! nt->type.localp)
6711 /* This is a duplicate of a global type, so it must be
6717 nt = (struct ieee_name_type *) xmalloc (sizeof *nt);
6718 memset (nt, 0, sizeof *nt);
6721 nt->type.name = h->root.string;
6722 nt->type.indx = info->type_indx;
6723 nt->type.localp = localp;
6727 nt->next = h->types;
6730 if (! ieee_push_type (info, nt->type.indx, 0, false, localp))
6733 info->type_stack->type.name = h->root.string;
6738 /* Output a typedef. */
6741 ieee_typdef (p, name)
6745 struct ieee_handle *info = (struct ieee_handle *) p;
6746 struct ieee_write_type type;
6750 struct ieee_name_type_hash_entry *h;
6751 struct ieee_name_type *nt;
6753 type = info->type_stack->type;
6756 /* If this is a simple builtin type using a builtin name, we don't
6757 want to output the typedef itself. We also want to change the
6758 type index to correspond to the name being used. We recognize
6759 names used in stabs debugging output even if they don't exactly
6760 correspond to the names used for the IEEE builtin types. */
6762 if (indx <= (unsigned int) builtin_bcd_float)
6764 switch ((enum builtin_types) indx)
6770 if (strcmp (name, "void") == 0)
6774 case builtin_signed_char:
6776 if (strcmp (name, "signed char") == 0)
6778 indx = (unsigned int) builtin_signed_char;
6781 else if (strcmp (name, "char") == 0)
6783 indx = (unsigned int) builtin_char;
6788 case builtin_unsigned_char:
6789 if (strcmp (name, "unsigned char") == 0)
6793 case builtin_signed_short_int:
6795 case builtin_short_int:
6796 case builtin_signed_short:
6797 if (strcmp (name, "signed short int") == 0)
6799 indx = (unsigned int) builtin_signed_short_int;
6802 else if (strcmp (name, "short") == 0)
6804 indx = (unsigned int) builtin_short;
6807 else if (strcmp (name, "short int") == 0)
6809 indx = (unsigned int) builtin_short_int;
6812 else if (strcmp (name, "signed short") == 0)
6814 indx = (unsigned int) builtin_signed_short;
6819 case builtin_unsigned_short_int:
6820 case builtin_unsigned_short:
6821 if (strcmp (name, "unsigned short int") == 0
6822 || strcmp (name, "short unsigned int") == 0)
6824 indx = builtin_unsigned_short_int;
6827 else if (strcmp (name, "unsigned short") == 0)
6829 indx = builtin_unsigned_short;
6834 case builtin_signed_long:
6835 case builtin_int: /* FIXME: Size depends upon architecture. */
6837 if (strcmp (name, "signed long") == 0)
6839 indx = builtin_signed_long;
6842 else if (strcmp (name, "int") == 0)
6847 else if (strcmp (name, "long") == 0
6848 || strcmp (name, "long int") == 0)
6850 indx = builtin_long;
6855 case builtin_unsigned_long:
6856 case builtin_unsigned: /* FIXME: Size depends upon architecture. */
6857 case builtin_unsigned_int: /* FIXME: Like builtin_unsigned. */
6858 if (strcmp (name, "unsigned long") == 0
6859 || strcmp (name, "long unsigned int") == 0)
6861 indx = builtin_unsigned_long;
6864 else if (strcmp (name, "unsigned") == 0)
6866 indx = builtin_unsigned;
6869 else if (strcmp (name, "unsigned int") == 0)
6871 indx = builtin_unsigned_int;
6876 case builtin_signed_long_long:
6877 if (strcmp (name, "signed long long") == 0
6878 || strcmp (name, "long long int") == 0)
6882 case builtin_unsigned_long_long:
6883 if (strcmp (name, "unsigned long long") == 0
6884 || strcmp (name, "long long unsigned int") == 0)
6889 if (strcmp (name, "float") == 0)
6893 case builtin_double:
6894 if (strcmp (name, "double") == 0)
6898 case builtin_long_double:
6899 if (strcmp (name, "long double") == 0)
6903 case builtin_long_long_double:
6904 if (strcmp (name, "long long double") == 0)
6913 h = ieee_name_type_hash_lookup (&info->typedefs, name, true, false);
6917 /* See if we have already defined this type with this name. */
6918 localp = type.localp;
6919 for (nt = h->types; nt != NULL; nt = nt->next)
6923 /* If this is a global definition, then we don't need to
6924 do anything here. */
6925 if (! nt->type.localp)
6927 ieee_pop_unused_type (info);
6933 /* This is a duplicate definition, so make this one local. */
6938 /* We need to add a new typedef for this type. */
6940 nt = (struct ieee_name_type *) xmalloc (sizeof *nt);
6941 memset (nt, 0, sizeof *nt);
6944 nt->type.name = name;
6945 nt->type.localp = localp;
6946 nt->kind = DEBUG_KIND_ILLEGAL;
6948 nt->next = h->types;
6953 /* This is one of the builtin typedefs, so we don't need to
6954 actually define it. */
6955 ieee_pop_unused_type (info);
6959 indx = ieee_pop_type (info);
6961 if (! ieee_define_named_type (info, name, (unsigned int) -1, type.size,
6962 type.unsignedp, localp,
6963 (struct ieee_buflist *) NULL)
6964 || ! ieee_write_number (info, 'T')
6965 || ! ieee_write_number (info, indx))
6968 /* Remove the type we just added to the type stack. This should not
6969 be ieee_pop_unused_type, since the type is used, we just don't
6971 (void) ieee_pop_type (info);
6976 /* Output a tag for a type. We don't have to do anything here. */
6983 struct ieee_handle *info = (struct ieee_handle *) p;
6985 /* This should not be ieee_pop_unused_type, since we want the type
6987 (void) ieee_pop_type (info);
6991 /* Output an integer constant. */
6994 ieee_int_constant (p, name, val)
7003 /* Output a floating point constant. */
7006 ieee_float_constant (p, name, val)
7015 /* Output a typed constant. */
7018 ieee_typed_constant (p, name, val)
7023 struct ieee_handle *info = (struct ieee_handle *) p;
7026 ieee_pop_unused_type (info);
7030 /* Output a variable. */
7033 ieee_variable (p, name, kind, val)
7036 enum debug_var_kind kind;
7039 struct ieee_handle *info = (struct ieee_handle *) p;
7040 unsigned int name_indx;
7043 unsigned int type_indx;
7047 size = info->type_stack->type.size;
7048 referencep = info->type_stack->type.referencep;
7049 type_indx = ieee_pop_type (info);
7051 assert (! ieee_buffer_emptyp (&info->vars));
7052 if (! ieee_change_buffer (info, &info->vars))
7055 name_indx = info->name_indx;
7058 /* Write out an NN and an ATN record for this variable. */
7059 if (! ieee_write_byte (info, (int) ieee_nn_record)
7060 || ! ieee_write_number (info, name_indx)
7061 || ! ieee_write_id (info, name)
7062 || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
7063 || ! ieee_write_number (info, name_indx)
7064 || ! ieee_write_number (info, type_indx))
7072 if (! ieee_write_number (info, 8)
7073 || ! ieee_add_range (info, false, val, val + size))
7079 if (! ieee_write_number (info, 3)
7080 || ! ieee_add_range (info, false, val, val + size))
7085 case DEBUG_LOCAL_STATIC:
7086 if (! ieee_write_number (info, 3)
7087 || ! ieee_add_range (info, false, val, val + size))
7093 if (! ieee_write_number (info, 1)
7094 || ! ieee_write_number (info, val))
7099 case DEBUG_REGISTER:
7100 if (! ieee_write_number (info, 2)
7101 || ! ieee_write_number (info,
7102 ieee_genreg_to_regno (info->abfd, val)))
7111 if (! ieee_write_asn (info, name_indx, val))
7115 /* If this is really a reference type, then we just output it with
7116 pointer type, and must now output a C++ record indicating that it
7117 is really reference type. */
7122 nindx = info->name_indx;
7125 /* If this is a global variable, we want to output the misc
7126 record in the C++ misc record block. Otherwise, we want to
7127 output it just after the variable definition, which is where
7128 the current buffer is. */
7131 if (! ieee_change_buffer (info, &info->cxx))
7135 if (! ieee_write_byte (info, (int) ieee_nn_record)
7136 || ! ieee_write_number (info, nindx)
7137 || ! ieee_write_id (info, "")
7138 || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
7139 || ! ieee_write_number (info, nindx)
7140 || ! ieee_write_number (info, 0)
7141 || ! ieee_write_number (info, 62)
7142 || ! ieee_write_number (info, 80)
7143 || ! ieee_write_number (info, 3)
7144 || ! ieee_write_asn (info, nindx, 'R')
7145 || ! ieee_write_asn (info, nindx, refflag)
7146 || ! ieee_write_atn65 (info, nindx, name))
7153 /* Start outputting information for a function. */
7156 ieee_start_function (p, name, global)
7161 struct ieee_handle *info = (struct ieee_handle *) p;
7163 unsigned int retindx, typeindx;
7165 referencep = info->type_stack->type.referencep;
7166 retindx = ieee_pop_type (info);
7168 /* Besides recording a BB4 or BB6 block, we record the type of the
7169 function in the BB1 typedef block. We can't write out the full
7170 type until we have seen all the parameters, so we accumulate it
7171 in info->fntype and info->fnargs. */
7172 if (! ieee_buffer_emptyp (&info->fntype))
7174 /* FIXME: This might happen someday if we support nested
7179 info->fnname = name;
7181 /* An attribute of 0x40 means that the push mask is unknown. */
7182 if (! ieee_define_named_type (info, name, (unsigned int) -1, 0, false, true,
7184 || ! ieee_write_number (info, 'x')
7185 || ! ieee_write_number (info, 0x40)
7186 || ! ieee_write_number (info, 0)
7187 || ! ieee_write_number (info, 0)
7188 || ! ieee_write_number (info, retindx))
7191 typeindx = ieee_pop_type (info);
7193 if (! ieee_init_buffer (info, &info->fnargs))
7195 info->fnargcount = 0;
7197 /* If the function return value is actually a reference type, we
7198 must add a record indicating that. */
7203 nindx = info->name_indx;
7205 if (! ieee_change_buffer (info, &info->cxx)
7206 || ! ieee_write_byte (info, (int) ieee_nn_record)
7207 || ! ieee_write_number (info, nindx)
7208 || ! ieee_write_id (info, "")
7209 || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
7210 || ! ieee_write_number (info, nindx)
7211 || ! ieee_write_number (info, 0)
7212 || ! ieee_write_number (info, 62)
7213 || ! ieee_write_number (info, 80)
7214 || ! ieee_write_number (info, 3)
7215 || ! ieee_write_asn (info, nindx, 'R')
7216 || ! ieee_write_asn (info, nindx, global ? 0 : 1)
7217 || ! ieee_write_atn65 (info, nindx, name))
7221 assert (! ieee_buffer_emptyp (&info->vars));
7222 if (! ieee_change_buffer (info, &info->vars))
7225 /* The address is written out as the first block. */
7227 ++info->block_depth;
7229 return (ieee_write_byte (info, (int) ieee_bb_record_enum)
7230 && ieee_write_byte (info, global ? 4 : 6)
7231 && ieee_write_number (info, 0)
7232 && ieee_write_id (info, name)
7233 && ieee_write_number (info, 0)
7234 && ieee_write_number (info, typeindx));
7237 /* Add a function parameter. This will normally be called before the
7238 first block, so we postpone them until we see the block. */
7241 ieee_function_parameter (p, name, kind, val)
7244 enum debug_parm_kind kind;
7247 struct ieee_handle *info = (struct ieee_handle *) p;
7248 struct ieee_pending_parm *m, **pm;
7250 assert (info->block_depth == 1);
7252 m = (struct ieee_pending_parm *) xmalloc (sizeof *m);
7253 memset (m, 0, sizeof *m);
7257 m->referencep = info->type_stack->type.referencep;
7258 m->type = ieee_pop_type (info);
7262 for (pm = &info->pending_parms; *pm != NULL; pm = &(*pm)->next)
7266 /* Add the type to the fnargs list. */
7267 if (! ieee_change_buffer (info, &info->fnargs)
7268 || ! ieee_write_number (info, m->type))
7275 /* Output pending function parameters. */
7278 ieee_output_pending_parms (info)
7279 struct ieee_handle *info;
7281 struct ieee_pending_parm *m;
7282 unsigned int refcount;
7285 for (m = info->pending_parms; m != NULL; m = m->next)
7287 enum debug_var_kind vkind;
7294 case DEBUG_PARM_STACK:
7295 case DEBUG_PARM_REFERENCE:
7296 vkind = DEBUG_LOCAL;
7298 case DEBUG_PARM_REG:
7299 case DEBUG_PARM_REF_REG:
7300 vkind = DEBUG_REGISTER;
7304 if (! ieee_push_type (info, m->type, 0, false, false))
7306 info->type_stack->type.referencep = m->referencep;
7309 if (! ieee_variable ((PTR) info, m->name, vkind, m->val))
7313 /* If there are any reference parameters, we need to output a
7314 miscellaneous record indicating them. */
7317 unsigned int nindx, varindx;
7319 /* FIXME: The MRI compiler outputs the demangled function name
7320 here, but we are outputting the mangled name. */
7321 nindx = info->name_indx;
7323 if (! ieee_change_buffer (info, &info->vars)
7324 || ! ieee_write_byte (info, (int) ieee_nn_record)
7325 || ! ieee_write_number (info, nindx)
7326 || ! ieee_write_id (info, "")
7327 || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
7328 || ! ieee_write_number (info, nindx)
7329 || ! ieee_write_number (info, 0)
7330 || ! ieee_write_number (info, 62)
7331 || ! ieee_write_number (info, 80)
7332 || ! ieee_write_number (info, refcount + 3)
7333 || ! ieee_write_asn (info, nindx, 'B')
7334 || ! ieee_write_atn65 (info, nindx, info->fnname)
7335 || ! ieee_write_asn (info, nindx, 0))
7337 for (m = info->pending_parms, varindx = 1;
7339 m = m->next, varindx++)
7343 if (! ieee_write_asn (info, nindx, varindx))
7349 m = info->pending_parms;
7352 struct ieee_pending_parm *next;
7359 info->pending_parms = NULL;
7364 /* Start a block. If this is the first block, we output the address
7365 to finish the BB4 or BB6, and then output the function parameters. */
7368 ieee_start_block (p, addr)
7372 struct ieee_handle *info = (struct ieee_handle *) p;
7374 if (! ieee_change_buffer (info, &info->vars))
7377 if (info->block_depth == 1)
7379 if (! ieee_write_number (info, addr)
7380 || ! ieee_output_pending_parms (info))
7385 if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
7386 || ! ieee_write_byte (info, 6)
7387 || ! ieee_write_number (info, 0)
7388 || ! ieee_write_id (info, "")
7389 || ! ieee_write_number (info, 0)
7390 || ! ieee_write_number (info, 0)
7391 || ! ieee_write_number (info, addr))
7395 if (! ieee_start_range (info, addr))
7398 ++info->block_depth;
7406 ieee_end_block (p, addr)
7410 struct ieee_handle *info = (struct ieee_handle *) p;
7412 /* The address we are given is the end of the block, but IEEE seems
7413 to want to the address of the last byte in the block, so we
7415 if (! ieee_change_buffer (info, &info->vars)
7416 || ! ieee_write_byte (info, (int) ieee_be_record_enum)
7417 || ! ieee_write_number (info, addr - 1))
7420 if (! ieee_end_range (info, addr))
7423 --info->block_depth;
7425 if (addr > info->highaddr)
7426 info->highaddr = addr;
7431 /* End a function. */
7434 ieee_end_function (p)
7437 struct ieee_handle *info = (struct ieee_handle *) p;
7439 assert (info->block_depth == 1);
7441 --info->block_depth;
7443 /* Now we can finish up fntype, and add it to the typdef section.
7444 At this point, fntype is the 'x' type up to the argument count,
7445 and fnargs is the argument types. We must add the argument
7446 count, and we must add the level. FIXME: We don't record varargs
7447 functions correctly. In fact, stabs debugging does not give us
7448 enough information to do so. */
7449 if (! ieee_change_buffer (info, &info->fntype)
7450 || ! ieee_write_number (info, info->fnargcount)
7451 || ! ieee_change_buffer (info, &info->fnargs)
7452 || ! ieee_write_number (info, 0))
7455 /* Make sure the typdef block has been started. */
7456 if (ieee_buffer_emptyp (&info->types))
7458 if (! ieee_change_buffer (info, &info->types)
7459 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
7460 || ! ieee_write_byte (info, 1)
7461 || ! ieee_write_number (info, 0)
7462 || ! ieee_write_id (info, info->modname))
7466 if (! ieee_append_buffer (info, &info->types, &info->fntype)
7467 || ! ieee_append_buffer (info, &info->types, &info->fnargs))
7470 info->fnname = NULL;
7471 if (! ieee_init_buffer (info, &info->fntype)
7472 || ! ieee_init_buffer (info, &info->fnargs))
7474 info->fnargcount = 0;
7479 /* Record line number information. */
7482 ieee_lineno (p, filename, lineno, addr)
7484 const char *filename;
7485 unsigned long lineno;
7488 struct ieee_handle *info = (struct ieee_handle *) p;
7490 assert (info->filename != NULL);
7492 /* The HP simulator seems to get confused when more than one line is
7493 listed for the same address, at least if they are in different
7494 files. We handle this by always listing the last line for a
7495 given address, since that seems to be the one that gdb uses. */
7496 if (info->pending_lineno_filename != NULL
7497 && addr != info->pending_lineno_addr)
7499 /* Make sure we have a line number block. */
7500 if (! ieee_buffer_emptyp (&info->linenos))
7502 if (! ieee_change_buffer (info, &info->linenos))
7507 info->lineno_name_indx = info->name_indx;
7509 if (! ieee_change_buffer (info, &info->linenos)
7510 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
7511 || ! ieee_write_byte (info, 5)
7512 || ! ieee_write_number (info, 0)
7513 || ! ieee_write_id (info, info->filename)
7514 || ! ieee_write_byte (info, (int) ieee_nn_record)
7515 || ! ieee_write_number (info, info->lineno_name_indx)
7516 || ! ieee_write_id (info, ""))
7518 info->lineno_filename = info->filename;
7521 if (strcmp (info->pending_lineno_filename, info->lineno_filename) != 0)
7523 if (strcmp (info->filename, info->lineno_filename) != 0)
7525 /* We were not in the main file. Close the block for the
7527 if (! ieee_write_byte (info, (int) ieee_be_record_enum))
7529 if (strcmp (info->filename, info->pending_lineno_filename) == 0)
7531 /* We need a new NN record, and we aren't about to
7533 info->lineno_name_indx = info->name_indx;
7535 if (! ieee_write_byte (info, (int) ieee_nn_record)
7536 || ! ieee_write_number (info, info->lineno_name_indx)
7537 || ! ieee_write_id (info, ""))
7541 if (strcmp (info->filename, info->pending_lineno_filename) != 0)
7543 /* We are not changing to the main file. Open a block for
7544 the new included file. */
7545 info->lineno_name_indx = info->name_indx;
7547 if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
7548 || ! ieee_write_byte (info, 5)
7549 || ! ieee_write_number (info, 0)
7550 || ! ieee_write_id (info, info->pending_lineno_filename)
7551 || ! ieee_write_byte (info, (int) ieee_nn_record)
7552 || ! ieee_write_number (info, info->lineno_name_indx)
7553 || ! ieee_write_id (info, ""))
7556 info->lineno_filename = info->pending_lineno_filename;
7559 if (! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
7560 || ! ieee_write_number (info, info->lineno_name_indx)
7561 || ! ieee_write_number (info, 0)
7562 || ! ieee_write_number (info, 7)
7563 || ! ieee_write_number (info, info->pending_lineno)
7564 || ! ieee_write_number (info, 0)
7565 || ! ieee_write_asn (info, info->lineno_name_indx,
7566 info->pending_lineno_addr))
7570 info->pending_lineno_filename = filename;
7571 info->pending_lineno = lineno;
7572 info->pending_lineno_addr = addr;