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. */
46 /* This structure is the block stack. */
48 #define BLOCKSTACK_SIZE (16)
50 struct ieee_blockstack
52 /* The stack pointer. */
53 struct ieee_block *bsp;
55 struct ieee_block stack[BLOCKSTACK_SIZE];
58 /* This structure holds information for a variable. */
68 /* Slot if we make an indirect type. */
70 /* Kind of variable or function. */
82 /* This structure holds all the variables. */
86 /* Number of slots allocated. */
89 struct ieee_var *vars;
92 /* This structure holds information for a type. We need this because
93 we don't want to represent bitfields as real types. */
99 /* Slot if this is type is referenced before it is defined. */
101 /* Slots for arguments if we make indirect types for them. */
102 debug_type *arg_slots;
103 /* If this is a bitfield, this is the size in bits. If this is not
104 a bitfield, this is zero. */
105 unsigned long bitsize;
108 /* This structure holds all the type information. */
112 /* Number of slots allocated. */
115 struct ieee_type *types;
117 #define BUILTIN_TYPE_COUNT (60)
118 debug_type builtins[BUILTIN_TYPE_COUNT];
121 /* This structure holds a linked last of structs with their tag names,
122 so that we can convert them to C++ classes if necessary. */
127 struct ieee_tag *next;
130 /* The type of the tag. */
132 /* The tagged type is an indirect type pointing at this slot. */
134 /* This is an array of slots used when a field type is converted
135 into a indirect type, in case it needs to be later converted into
140 /* This structure holds the information we pass around to the parsing
145 /* The debugging handle. */
149 /* The start of the bytes to be parsed. */
150 const bfd_byte *bytes;
151 /* The end of the bytes to be parsed. */
152 const bfd_byte *pend;
153 /* The block stack. */
154 struct ieee_blockstack blockstack;
156 struct ieee_vars vars;
158 struct ieee_types types;
159 /* The list of tagged structs. */
160 struct ieee_tag *tags;
163 /* Basic builtin types, not including the pointers. */
169 builtin_signed_char = 2,
170 builtin_unsigned_char = 3,
171 builtin_signed_short_int = 4,
172 builtin_unsigned_short_int = 5,
173 builtin_signed_long = 6,
174 builtin_unsigned_long = 7,
175 builtin_signed_long_long = 8,
176 builtin_unsigned_long_long = 9,
179 builtin_long_double = 12,
180 builtin_long_long_double = 13,
181 builtin_quoted_string = 14,
182 builtin_instruction_address = 15,
184 builtin_unsigned = 17,
185 builtin_unsigned_int = 18,
189 builtin_unsigned_short = 22,
190 builtin_short_int = 23,
191 builtin_signed_short = 24,
192 builtin_bcd_float = 25
195 /* These are the values found in the derivation flags of a 'b'
196 component record of a 'T' type extension record in a C++ pmisc
197 record. These are bitmasks. */
199 /* Set for a private base class, clear for a public base class.
200 Protected base classes are not supported. */
201 #define BASEFLAGS_PRIVATE (0x1)
202 /* Set for a virtual base class. */
203 #define BASEFLAGS_VIRTUAL (0x2)
204 /* Set for a friend class, clear for a base class. */
205 #define BASEFLAGS_FRIEND (0x10)
207 /* These are the values found in the specs flags of a 'd', 'm', or 'v'
208 component record of a 'T' type extension record in a C++ pmisc
209 record. The same flags are used for a 'M' record in a C++ pmisc
212 /* The lower two bits hold visibility information. */
213 #define CXXFLAGS_VISIBILITY (0x3)
214 /* This value in the lower two bits indicates a public member. */
215 #define CXXFLAGS_VISIBILITY_PUBLIC (0x0)
216 /* This value in the lower two bits indicates a private member. */
217 #define CXXFLAGS_VISIBILITY_PRIVATE (0x1)
218 /* This value in the lower two bits indicates a protected member. */
219 #define CXXFLAGS_VISIBILITY_PROTECTED (0x2)
220 /* Set for a static member. */
221 #define CXXFLAGS_STATIC (0x4)
222 /* Set for a virtual override. */
223 #define CXXFLAGS_OVERRIDE (0x8)
224 /* Set for a friend function. */
225 #define CXXFLAGS_FRIEND (0x10)
226 /* Set for a const function. */
227 #define CXXFLAGS_CONST (0x20)
228 /* Set for a volatile function. */
229 #define CXXFLAGS_VOLATILE (0x40)
230 /* Set for an overloaded function. */
231 #define CXXFLAGS_OVERLOADED (0x80)
232 /* Set for an operator function. */
233 #define CXXFLAGS_OPERATOR (0x100)
234 /* Set for a constructor or destructor. */
235 #define CXXFLAGS_CTORDTOR (0x400)
236 /* Set for a constructor. */
237 #define CXXFLAGS_CTOR (0x200)
238 /* Set for an inline function. */
239 #define CXXFLAGS_INLINE (0x800)
241 /* Local functions. */
243 static void ieee_error
244 PARAMS ((struct ieee_info *, const bfd_byte *, const char *));
245 static void ieee_eof PARAMS ((struct ieee_info *));
246 static char *savestring PARAMS ((const char *, unsigned long));
247 static boolean ieee_read_number
248 PARAMS ((struct ieee_info *, const bfd_byte **, bfd_vma *));
249 static boolean ieee_read_optional_number
250 PARAMS ((struct ieee_info *, const bfd_byte **, bfd_vma *, boolean *));
251 static boolean ieee_read_id
252 PARAMS ((struct ieee_info *, const bfd_byte **, const char **,
254 static boolean ieee_read_optional_id
255 PARAMS ((struct ieee_info *, const bfd_byte **, const char **,
256 unsigned long *, boolean *));
257 static boolean ieee_read_expression
258 PARAMS ((struct ieee_info *, const bfd_byte **, bfd_vma *));
259 static debug_type ieee_builtin_type
260 PARAMS ((struct ieee_info *, const bfd_byte *, unsigned int));
261 static boolean ieee_alloc_type
262 PARAMS ((struct ieee_info *, unsigned int, boolean));
263 static boolean ieee_read_type_index
264 PARAMS ((struct ieee_info *, const bfd_byte **, debug_type *));
265 static int ieee_regno_to_genreg PARAMS ((bfd *, int));
266 static int ieee_genreg_to_regno PARAMS ((bfd *, int));
267 static boolean parse_ieee_bb PARAMS ((struct ieee_info *, const bfd_byte **));
268 static boolean parse_ieee_be PARAMS ((struct ieee_info *, const bfd_byte **));
269 static boolean parse_ieee_nn PARAMS ((struct ieee_info *, const bfd_byte **));
270 static boolean parse_ieee_ty PARAMS ((struct ieee_info *, const bfd_byte **));
271 static boolean parse_ieee_atn PARAMS ((struct ieee_info *, const bfd_byte **));
272 static boolean ieee_read_cxx_misc
273 PARAMS ((struct ieee_info *, const bfd_byte **, unsigned long));
274 static boolean ieee_read_cxx_class
275 PARAMS ((struct ieee_info *, const bfd_byte **, unsigned long));
276 static boolean ieee_read_cxx_defaults
277 PARAMS ((struct ieee_info *, const bfd_byte **, unsigned long));
278 static boolean ieee_read_reference
279 PARAMS ((struct ieee_info *, const bfd_byte **));
280 static boolean ieee_require_asn
281 PARAMS ((struct ieee_info *, const bfd_byte **, bfd_vma *));
282 static boolean ieee_require_atn65
283 PARAMS ((struct ieee_info *, const bfd_byte **, const char **,
286 /* Report an error in the IEEE debugging information. */
289 ieee_error (info, p, s)
290 struct ieee_info *info;
295 fprintf (stderr, "%s: 0x%lx: %s (0x%x)\n", bfd_get_filename (info->abfd),
296 (unsigned long) (p - info->bytes), s, *p);
298 fprintf (stderr, "%s: %s\n", bfd_get_filename (info->abfd), s);
301 /* Report an unexpected EOF in the IEEE debugging information. */
305 struct ieee_info *info;
307 ieee_error (info, (const bfd_byte *) NULL,
308 "unexpected end of debugging information");
311 /* Save a string in memory. */
314 savestring (start, len)
320 ret = (char *) xmalloc (len + 1);
321 memcpy (ret, start, len);
326 /* Read a number which must be present in an IEEE file. */
329 ieee_read_number (info, pp, pv)
330 struct ieee_info *info;
334 return ieee_read_optional_number (info, pp, pv, (boolean *) NULL);
337 /* Read a number in an IEEE file. If ppresent is not NULL, the number
338 need not be there. */
341 ieee_read_optional_number (info, pp, pv, ppresent)
342 struct ieee_info *info;
347 ieee_record_enum_type b;
349 if (*pp >= info->pend)
351 if (ppresent != NULL)
360 b = (ieee_record_enum_type) **pp;
363 if (b <= ieee_number_end_enum)
366 if (ppresent != NULL)
371 if (b >= ieee_number_repeat_start_enum && b <= ieee_number_repeat_end_enum)
375 i = (int) b - (int) ieee_number_repeat_start_enum;
376 if (*pp + i - 1 >= info->pend)
390 if (ppresent != NULL)
396 if (ppresent != NULL)
403 ieee_error (info, *pp - 1, "invalid number");
407 /* Read a required string from an IEEE file. */
410 ieee_read_id (info, pp, pname, pnamlen)
411 struct ieee_info *info;
414 unsigned long *pnamlen;
416 return ieee_read_optional_id (info, pp, pname, pnamlen, (boolean *) NULL);
419 /* Read a string from an IEEE file. If ppresent is not NULL, the
420 string is optional. */
423 ieee_read_optional_id (info, pp, pname, pnamlen, ppresent)
424 struct ieee_info *info;
427 unsigned long *pnamlen;
433 if (*pp >= info->pend)
444 else if ((ieee_record_enum_type) b == ieee_extension_length_1_enum)
449 else if ((ieee_record_enum_type) b == ieee_extension_length_2_enum)
451 len = (**pp << 8) + (*pp)[1];
456 if (ppresent != NULL)
462 ieee_error (info, *pp - 1, "invalid string length");
466 if ((unsigned long) (info->pend - *pp) < len)
472 *pname = (const char *) *pp;
476 if (ppresent != NULL)
482 /* Read an expression from an IEEE file. Since this code is only used
483 to parse debugging information, I haven't bothered to write a full
484 blown IEEE expression parser. I've only thrown in the things I've
485 seen in debugging information. This can be easily extended if
489 ieee_read_expression (info, pp, pv)
490 struct ieee_info *info;
494 const bfd_byte *expr_start;
495 #define EXPR_STACK_SIZE (10)
496 bfd_vma expr_stack[EXPR_STACK_SIZE];
505 const bfd_byte *start;
508 ieee_record_enum_type c;
512 if (! ieee_read_optional_number (info, pp, &val, &present))
517 if (esp - expr_stack >= EXPR_STACK_SIZE)
519 ieee_error (info, start, "expression stack overflow");
526 c = (ieee_record_enum_type) **pp;
528 if (c >= ieee_module_beginning_enum)
539 ieee_error (info, start, "unsupported IEEE expression operator");
542 case ieee_variable_R_enum:
547 if (! ieee_read_number (info, pp, &indx))
549 for (s = info->abfd->sections; s != NULL; s = s->next)
550 if ((bfd_vma) s->target_index == indx)
554 ieee_error (info, start, "unknown section");
558 if (esp - expr_stack >= EXPR_STACK_SIZE)
560 ieee_error (info, start, "expression stack overflow");
564 *esp++ = bfd_get_section_vma (info->abfd, s);
568 case ieee_function_plus_enum:
569 case ieee_function_minus_enum:
573 if (esp - expr_stack < 2)
575 ieee_error (info, start, "expression stack underflow");
587 if (esp - 1 != expr_stack)
589 ieee_error (info, expr_start, "expression stack mismatch");
598 /* Return an IEEE builtin type. */
601 ieee_builtin_type (info, p, indx)
602 struct ieee_info *info;
610 if (indx < BUILTIN_TYPE_COUNT
611 && info->types.builtins[indx] != DEBUG_TYPE_NULL)
612 return info->types.builtins[indx];
614 dhandle = info->dhandle;
616 if (indx >= 32 && indx < 64)
618 type = debug_make_pointer_type (dhandle,
619 ieee_builtin_type (info, p, indx - 32));
620 assert (indx < BUILTIN_TYPE_COUNT);
621 info->types.builtins[indx] = type;
625 switch ((enum builtin_types) indx)
628 ieee_error (info, p, "unknown builtin type");
631 case builtin_unknown:
632 type = debug_make_void_type (dhandle);
637 type = debug_make_void_type (dhandle);
641 case builtin_signed_char:
642 type = debug_make_int_type (dhandle, 1, false);
643 name = "signed char";
646 case builtin_unsigned_char:
647 type = debug_make_int_type (dhandle, 1, true);
648 name = "unsigned char";
651 case builtin_signed_short_int:
652 type = debug_make_int_type (dhandle, 2, false);
653 name = "signed short int";
656 case builtin_unsigned_short_int:
657 type = debug_make_int_type (dhandle, 2, true);
658 name = "unsigned short int";
661 case builtin_signed_long:
662 type = debug_make_int_type (dhandle, 4, false);
663 name = "signed long";
666 case builtin_unsigned_long:
667 type = debug_make_int_type (dhandle, 4, true);
668 name = "unsigned long";
671 case builtin_signed_long_long:
672 type = debug_make_int_type (dhandle, 8, false);
673 name = "signed long long";
676 case builtin_unsigned_long_long:
677 type = debug_make_int_type (dhandle, 8, true);
678 name = "unsigned long long";
682 type = debug_make_float_type (dhandle, 4);
687 type = debug_make_float_type (dhandle, 8);
691 case builtin_long_double:
692 /* FIXME: The size for this type should depend upon the
694 type = debug_make_float_type (dhandle, 12);
695 name = "long double";
698 case builtin_long_long_double:
699 type = debug_make_float_type (dhandle, 16);
700 name = "long long double";
703 case builtin_quoted_string:
704 type = debug_make_array_type (dhandle,
705 ieee_builtin_type (info, p,
708 ieee_builtin_type (info, p,
712 name = "QUOTED STRING";
715 case builtin_instruction_address:
716 /* FIXME: This should be a code address. */
717 type = debug_make_int_type (dhandle, 4, true);
718 name = "instruction address";
722 /* FIXME: The size for this type should depend upon the
724 type = debug_make_int_type (dhandle, 4, false);
728 case builtin_unsigned:
729 /* FIXME: The size for this type should depend upon the
731 type = debug_make_int_type (dhandle, 4, true);
735 case builtin_unsigned_int:
736 /* FIXME: The size for this type should depend upon the
738 type = debug_make_int_type (dhandle, 4, true);
739 name = "unsigned int";
743 type = debug_make_int_type (dhandle, 1, false);
748 type = debug_make_int_type (dhandle, 4, false);
753 type = debug_make_int_type (dhandle, 2, false);
757 case builtin_unsigned_short:
758 type = debug_make_int_type (dhandle, 2, true);
759 name = "unsigned short";
762 case builtin_short_int:
763 type = debug_make_int_type (dhandle, 2, false);
767 case builtin_signed_short:
768 type = debug_make_int_type (dhandle, 2, false);
769 name = "signed short";
772 case builtin_bcd_float:
773 ieee_error (info, p, "BCD float type not supported");
778 type = debug_name_type (dhandle, name, type);
780 assert (indx < BUILTIN_TYPE_COUNT);
782 info->types.builtins[indx] = type;
787 /* Allocate more space in the type table. If ref is true, this is a
788 reference to the type; if it is not already defined, we should set
789 up an indirect type. */
792 ieee_alloc_type (info, indx, ref)
793 struct ieee_info *info;
798 register struct ieee_type *t;
799 struct ieee_type *tend;
801 if (indx >= info->types.alloc)
803 nalloc = info->types.alloc;
806 while (indx >= nalloc)
809 info->types.types = ((struct ieee_type *)
810 xrealloc (info->types.types,
811 nalloc * sizeof *info->types.types));
813 memset (info->types.types + info->types.alloc, 0,
814 (nalloc - info->types.alloc) * sizeof *info->types.types);
816 tend = info->types.types + nalloc;
817 for (t = info->types.types + info->types.alloc; t < tend; t++)
818 t->type = DEBUG_TYPE_NULL;
820 info->types.alloc = nalloc;
825 t = info->types.types + indx;
828 t->pslot = (debug_type *) xmalloc (sizeof *t->pslot);
829 *t->pslot = DEBUG_TYPE_NULL;
830 t->type = debug_make_indirect_type (info->dhandle, t->pslot,
831 (const char *) NULL);
840 /* Read a type index and return the corresponding type. */
843 ieee_read_type_index (info, pp, ptype)
844 struct ieee_info *info;
848 const bfd_byte *start;
853 if (! ieee_read_number (info, pp, &indx))
858 *ptype = ieee_builtin_type (info, start, indx);
865 if (! ieee_alloc_type (info, indx, true))
868 *ptype = info->types.types[indx].type;
873 /* Parse IEEE debugging information for a file. This is passed the
874 bytes which compose the Debug Information Part of an IEEE file. */
877 parse_ieee (dhandle, abfd, bytes, len)
880 const bfd_byte *bytes;
883 struct ieee_info info;
885 const bfd_byte *p, *pend;
887 info.dhandle = dhandle;
890 info.pend = bytes + len;
891 info.blockstack.bsp = info.blockstack.stack;
893 info.vars.vars = NULL;
894 info.types.alloc = 0;
895 info.types.types = NULL;
897 for (i = 0; i < BUILTIN_TYPE_COUNT; i++)
898 info.types.builtins[i] = DEBUG_TYPE_NULL;
904 const bfd_byte *record_start;
905 ieee_record_enum_type c;
909 c = (ieee_record_enum_type) *p++;
911 if (c == ieee_at_record_enum)
912 c = (ieee_record_enum_type) (((unsigned int) c << 8) | *p++);
914 if (c <= ieee_number_repeat_end_enum)
916 ieee_error (&info, record_start, "unexpected number");
923 ieee_error (&info, record_start, "unexpected record type");
926 case ieee_bb_record_enum:
927 if (! parse_ieee_bb (&info, &p))
931 case ieee_be_record_enum:
932 if (! parse_ieee_be (&info, &p))
937 if (! parse_ieee_nn (&info, &p))
941 case ieee_ty_record_enum:
942 if (! parse_ieee_ty (&info, &p))
946 case ieee_atn_record_enum:
947 if (! parse_ieee_atn (&info, &p))
953 if (info.blockstack.bsp != info.blockstack.stack)
955 ieee_error (&info, (const bfd_byte *) NULL,
956 "blocks left on stack at end");
963 /* Handle an IEEE BB record. */
966 parse_ieee_bb (info, pp)
967 struct ieee_info *info;
970 const bfd_byte *block_start;
974 unsigned long namlen;
983 if (! ieee_read_number (info, pp, &size)
984 || ! ieee_read_id (info, pp, &name, &namlen))
987 fnindx = (unsigned int) -1;
992 /* BB1: Type definitions local to a module. */
993 namcopy = savestring (name, namlen);
996 if (! debug_set_filename (info->dhandle, namcopy))
1001 /* BB2: Global type definitions. The name is supposed to be
1002 empty, but we don't check. */
1003 if (! debug_set_filename (info->dhandle, "*global*"))
1008 /* BB3: High level module block begin. We don't have to do
1009 anything here. The name is supposed to be the same as for
1010 the BB1, but we don't check. */
1014 /* BB4: Global function. */
1016 bfd_vma stackspace, typindx, offset;
1017 debug_type return_type;
1019 if (! ieee_read_number (info, pp, &stackspace)
1020 || ! ieee_read_number (info, pp, &typindx)
1021 || ! ieee_read_expression (info, pp, &offset))
1024 /* We have no way to record the stack space. FIXME. */
1028 return_type = ieee_builtin_type (info, block_start, typindx);
1029 if (return_type == DEBUG_TYPE_NULL)
1035 if (! ieee_alloc_type (info, typindx, true))
1038 return_type = info->types.types[typindx].type;
1039 if (debug_get_type_kind (info->dhandle, return_type)
1040 == DEBUG_KIND_FUNCTION)
1041 return_type = debug_get_return_type (info->dhandle,
1045 namcopy = savestring (name, namlen);
1046 if (namcopy == NULL)
1048 if (! debug_record_function (info->dhandle, namcopy, return_type,
1055 /* BB5: File name for source line numbers. */
1059 /* We ignore the date and time. FIXME. */
1060 for (i = 0; i < 6; i++)
1065 if (! ieee_read_optional_number (info, pp, &ignore, &present))
1071 namcopy = savestring (name, namlen);
1072 if (namcopy == NULL)
1074 if (! debug_start_source (info->dhandle, namcopy))
1080 /* BB6: Local function or block. */
1082 bfd_vma stackspace, typindx, offset;
1084 if (! ieee_read_number (info, pp, &stackspace)
1085 || ! ieee_read_number (info, pp, &typindx)
1086 || ! ieee_read_expression (info, pp, &offset))
1089 /* We have no way to record the stack space. FIXME. */
1093 if (! debug_start_block (info->dhandle, offset))
1095 /* Change b to indicate that this is a block
1096 rather than a function. */
1101 debug_type return_type;
1105 return_type = ieee_builtin_type (info, block_start, typindx);
1106 if (return_type == NULL)
1112 if (! ieee_alloc_type (info, typindx, true))
1115 return_type = info->types.types[typindx].type;
1116 if (debug_get_type_kind (info->dhandle, return_type)
1117 == DEBUG_KIND_FUNCTION)
1118 return_type = debug_get_return_type (info->dhandle,
1122 namcopy = savestring (name, namlen);
1123 if (namcopy == NULL)
1125 if (! debug_record_function (info->dhandle, namcopy, return_type,
1133 /* BB10: Assembler module scope. We completely ignore all this
1134 information. FIXME. */
1136 const char *inam, *vstr;
1137 unsigned long inamlen, vstrlen;
1142 if (! ieee_read_id (info, pp, &inam, &inamlen)
1143 || ! ieee_read_number (info, pp, &tool_type)
1144 || ! ieee_read_optional_id (info, pp, &vstr, &vstrlen, &present))
1146 for (i = 0; i < 6; i++)
1150 if (! ieee_read_optional_number (info, pp, &ignore, &present))
1159 /* BB11: Module section. We completely ignore all this
1160 information. FIXME. */
1162 bfd_vma sectype, secindx, offset, map;
1165 if (! ieee_read_number (info, pp, §ype)
1166 || ! ieee_read_number (info, pp, &secindx)
1167 || ! ieee_read_expression (info, pp, &offset)
1168 || ! ieee_read_optional_number (info, pp, &map, &present))
1174 ieee_error (info, block_start, "unknown BB type");
1179 /* Push this block on the block stack. */
1181 if (info->blockstack.bsp >= info->blockstack.stack + BLOCKSTACK_SIZE)
1183 ieee_error (info, (const bfd_byte *) NULL, "stack overflow");
1187 info->blockstack.bsp->kind = b;
1189 info->blockstack.bsp->filename = namcopy;
1190 info->blockstack.bsp->fnindx = fnindx;
1191 ++info->blockstack.bsp;
1196 /* Handle an IEEE BE record. */
1199 parse_ieee_be (info, pp)
1200 struct ieee_info *info;
1201 const bfd_byte **pp;
1205 if (info->blockstack.bsp <= info->blockstack.stack)
1207 ieee_error (info, *pp, "stack underflow");
1210 --info->blockstack.bsp;
1212 switch (info->blockstack.bsp->kind)
1216 if (! ieee_read_expression (info, pp, &offset))
1218 if (! debug_end_function (info->dhandle, offset))
1223 /* This is BE6 when BB6 started a block rather than a local
1225 if (! ieee_read_expression (info, pp, &offset))
1227 if (! debug_end_block (info->dhandle, offset))
1232 /* When we end a BB5, we look up the stack for the last BB5, if
1233 there is one, so that we can call debug_start_source. */
1234 if (info->blockstack.bsp > info->blockstack.stack)
1236 struct ieee_block *bl;
1238 bl = info->blockstack.bsp;
1244 if (! debug_start_source (info->dhandle, bl->filename))
1249 while (bl != info->blockstack.stack);
1254 if (! ieee_read_expression (info, pp, &offset))
1256 /* We just ignore the module size. FIXME. */
1260 /* Other block types do not have any trailing information. */
1267 /* Parse an NN record. */
1270 parse_ieee_nn (info, pp)
1271 struct ieee_info *info;
1272 const bfd_byte **pp;
1274 const bfd_byte *nn_start;
1277 unsigned long namlen;
1281 if (! ieee_read_number (info, pp, &varindx)
1282 || ! ieee_read_id (info, pp, &name, &namlen))
1287 ieee_error (info, nn_start, "illegal variable index");
1292 if (varindx >= info->vars.alloc)
1296 alloc = info->vars.alloc;
1299 while (varindx >= alloc)
1301 info->vars.vars = ((struct ieee_var *)
1302 xrealloc (info->vars.vars,
1303 alloc * sizeof *info->vars.vars));
1304 memset (info->vars.vars + info->vars.alloc, 0,
1305 (alloc - info->vars.alloc) * sizeof *info->vars.vars);
1306 info->vars.alloc = alloc;
1309 info->vars.vars[varindx].name = name;
1310 info->vars.vars[varindx].namlen = namlen;
1315 /* Parse a TY record. */
1318 parse_ieee_ty (info, pp)
1319 struct ieee_info *info;
1320 const bfd_byte **pp;
1322 const bfd_byte *ty_start, *ty_var_start, *ty_code_start;
1323 bfd_vma typeindx, varindx, tc;
1325 boolean tag, typdef;
1326 debug_type *arg_slots;
1327 unsigned long type_bitsize;
1332 if (! ieee_read_number (info, pp, &typeindx))
1337 ieee_error (info, ty_start, "illegal type index");
1342 if (! ieee_alloc_type (info, typeindx, false))
1347 ieee_error (info, *pp, "unknown TY code");
1354 if (! ieee_read_number (info, pp, &varindx))
1359 ieee_error (info, ty_var_start, "illegal variable index");
1364 if (varindx >= info->vars.alloc || info->vars.vars[varindx].name == NULL)
1366 ieee_error (info, ty_var_start, "undefined variable in TY");
1370 ty_code_start = *pp;
1372 if (! ieee_read_number (info, pp, &tc))
1375 dhandle = info->dhandle;
1384 ieee_error (info, ty_code_start, "unknown TY code");
1388 /* Unknown type, with size. We treat it as int. FIXME. */
1392 if (! ieee_read_number (info, pp, &size))
1394 type = debug_make_int_type (dhandle, size, false);
1398 case 'A': /* Array. */
1399 case 'a': /* FORTRAN array in column/row order. FIXME: Not
1400 distinguished from normal array. */
1402 debug_type ele_type;
1403 bfd_vma lower, upper;
1405 if (! ieee_read_type_index (info, pp, &ele_type)
1406 || ! ieee_read_number (info, pp, &lower)
1407 || ! ieee_read_number (info, pp, &upper))
1409 type = debug_make_array_type (dhandle, ele_type,
1410 ieee_builtin_type (info, ty_code_start,
1413 (bfd_signed_vma) lower,
1414 (bfd_signed_vma) upper,
1420 /* Simple enumeration. */
1426 bfd_signed_vma *vals;
1429 if (! ieee_read_number (info, pp, &size))
1431 /* FIXME: we ignore the enumeration size. */
1434 names = (const char **) xmalloc (alloc * sizeof *names);
1435 memset (names, 0, alloc * sizeof *names);
1440 unsigned long namlen;
1443 if (! ieee_read_optional_id (info, pp, &name, &namlen, &present))
1451 names = ((const char **)
1452 xrealloc (names, alloc * sizeof *names));
1455 names[c] = savestring (name, namlen);
1456 if (names[c] == NULL)
1463 vals = (bfd_signed_vma *) xmalloc (c * sizeof *vals);
1464 for (i = 0; i < c; i++)
1467 type = debug_make_enum_type (dhandle, names, vals);
1473 /* Struct with bit fields. */
1477 debug_field *fields;
1480 if (! ieee_read_number (info, pp, &size))
1484 fields = (debug_field *) xmalloc (alloc * sizeof *fields);
1489 unsigned long namlen;
1492 bfd_vma bitpos, bitsize;
1494 if (! ieee_read_optional_id (info, pp, &name, &namlen, &present))
1498 if (! ieee_read_type_index (info, pp, &ftype)
1499 || ! ieee_read_number (info, pp, &bitpos)
1500 || ! ieee_read_number (info, pp, &bitsize))
1506 fields = ((debug_field *)
1507 xrealloc (fields, alloc * sizeof *fields));
1510 fields[c] = debug_make_field (dhandle, savestring (name, namlen),
1511 ftype, bitpos, bitsize,
1512 DEBUG_VISIBILITY_PUBLIC);
1513 if (fields[c] == NULL)
1520 type = debug_make_struct_type (dhandle, true, size, fields);
1530 bfd_signed_vma *vals;
1534 names = (const char **) xmalloc (alloc * sizeof *names);
1535 vals = (bfd_signed_vma *) xmalloc (alloc * sizeof *names);
1540 unsigned long namlen;
1544 if (! ieee_read_optional_id (info, pp, &name, &namlen, &present))
1548 if (! ieee_read_number (info, pp, &val))
1551 /* If the length of the name is zero, then the value is
1552 actually the size of the enum. We ignore this
1553 information. FIXME. */
1560 names = ((const char **)
1561 xrealloc (names, alloc * sizeof *names));
1562 vals = ((bfd_signed_vma *)
1563 xrealloc (vals, alloc * sizeof *vals));
1566 names[c] = savestring (name, namlen);
1567 if (names[c] == NULL)
1569 vals[c] = (bfd_signed_vma) val;
1575 type = debug_make_enum_type (dhandle, names, vals);
1580 case 'O': /* Small pointer. We don't distinguish small and large
1582 case 'P': /* Large pointer. */
1586 if (! ieee_read_type_index (info, pp, &t))
1588 type = debug_make_pointer_type (dhandle, t);
1595 bfd_vma low, high, signedp, size;
1597 if (! ieee_read_number (info, pp, &low)
1598 || ! ieee_read_number (info, pp, &high)
1599 || ! ieee_read_number (info, pp, &signedp)
1600 || ! ieee_read_number (info, pp, &size))
1603 type = debug_make_range_type (dhandle,
1604 debug_make_int_type (dhandle, size,
1606 (bfd_signed_vma) low,
1607 (bfd_signed_vma) high);
1611 case 'S': /* Struct. */
1612 case 'U': /* Union. */
1616 debug_field *fields;
1619 if (! ieee_read_number (info, pp, &size))
1623 fields = (debug_field *) xmalloc (alloc * sizeof *fields);
1628 unsigned long namlen;
1635 if (! ieee_read_optional_id (info, pp, &name, &namlen, &present))
1639 if (! ieee_read_number (info, pp, &tindx)
1640 || ! ieee_read_number (info, pp, &offset))
1645 ftype = ieee_builtin_type (info, ty_code_start, tindx);
1651 struct ieee_type *t;
1654 if (! ieee_alloc_type (info, tindx, true))
1656 t = info->types.types + tindx;
1658 bitsize = t->bitsize;
1666 fields = ((debug_field *)
1667 xrealloc (fields, alloc * sizeof *fields));
1670 fields[c] = debug_make_field (dhandle, savestring (name, namlen),
1671 ftype, offset, bitsize,
1672 DEBUG_VISIBILITY_PUBLIC);
1673 if (fields[c] == NULL)
1680 type = debug_make_struct_type (dhandle, tc == 'S', size, fields);
1687 if (! ieee_read_type_index (info, pp, &type))
1693 /* Procedure. FIXME: This is an extern declaration, which we
1694 have no way of representing. */
1700 struct ieee_var *pv;
1702 /* FIXME: We ignore the attribute and the argument names. */
1704 if (! ieee_read_number (info, pp, &attr)
1705 || ! ieee_read_type_index (info, pp, &rtype)
1706 || ! ieee_read_number (info, pp, &nargs))
1711 unsigned long namlen;
1713 if (! ieee_read_optional_id (info, pp, &name, &namlen, &present))
1718 pv = info->vars.vars + varindx;
1719 pv->kind = IEEE_EXTERNAL;
1721 && debug_get_type_kind (dhandle, rtype) == DEBUG_KIND_POINTER)
1723 /* Set up the return type as an indirect type pointing to
1724 the variable slot, so that we can change it to a
1725 reference later if appropriate. */
1726 pv->pslot = (debug_type *) xmalloc (sizeof *pv->pslot);
1728 rtype = debug_make_indirect_type (dhandle, pv->pslot,
1729 (const char *) NULL);
1732 type = debug_make_function_type (dhandle, rtype, (debug_type *) NULL,
1738 /* Array with 0 lower bound. */
1743 if (! ieee_read_type_index (info, pp, &etype)
1744 || ! ieee_read_number (info, pp, &high))
1747 type = debug_make_array_type (dhandle, etype,
1748 ieee_builtin_type (info, ty_code_start,
1751 0, (bfd_signed_vma) high, false);
1755 case 'c': /* Complex. */
1756 case 'd': /* Double complex. */
1759 unsigned long namlen;
1761 /* FIXME: I don't know what the name means. */
1763 if (! ieee_read_id (info, pp, &name, &namlen))
1766 type = debug_make_complex_type (dhandle, tc == 'c' ? 4 : 8);
1771 /* Pascal file name. FIXME. */
1772 ieee_error (info, ty_code_start, "Pascal file name not supported");
1776 /* Bitfield type. */
1778 bfd_vma signedp, bitsize;
1780 if (! ieee_read_number (info, pp, &signedp)
1781 || ! ieee_read_number (info, pp, &bitsize)
1782 || ! ieee_read_type_index (info, pp, &type))
1785 /* FIXME: This is just a guess. */
1787 type = debug_make_int_type (dhandle, 4, true);
1788 type_bitsize = bitsize;
1798 if (! ieee_read_number (info, pp, &kind)
1799 || ! ieee_read_type_index (info, pp, &t))
1805 ieee_error (info, ty_start, "unsupported qualifer");
1809 type = debug_make_const_type (dhandle, t);
1813 type = debug_make_volatile_type (dhandle, t);
1825 if (! ieee_read_number (info, pp, &size)
1826 || ! ieee_read_type_index (info, pp, &etype))
1829 /* FIXME: We ignore the size. */
1831 type = debug_make_set_type (dhandle, etype, false);
1836 /* Procedure with compiler dependencies. FIXME: This is an
1837 extern declaration, which we have no way of representing. */
1839 struct ieee_var *pv;
1840 bfd_vma attr, frame_type, push_mask, nargs, level, father;
1842 debug_type *arg_types;
1846 /* FIXME: We ignore almost all this information. */
1848 pv = info->vars.vars + varindx;
1850 if (! ieee_read_number (info, pp, &attr)
1851 || ! ieee_read_number (info, pp, &frame_type)
1852 || ! ieee_read_number (info, pp, &push_mask)
1853 || ! ieee_read_type_index (info, pp, &rtype)
1854 || ! ieee_read_number (info, pp, &nargs))
1856 if (nargs == (bfd_vma) -1)
1865 arg_types = ((debug_type *)
1866 xmalloc ((nargs + 1) * sizeof *arg_types));
1867 for (i = 0; i < nargs; i++)
1868 if (! ieee_read_type_index (info, pp, arg_types + i))
1871 /* If the last type is pointer to void, this is really a
1872 varargs function. */
1878 last = arg_types[nargs - 1];
1879 if (debug_get_type_kind (dhandle, last) == DEBUG_KIND_POINTER
1880 && (debug_get_type_kind (dhandle,
1881 debug_get_target_type (dhandle,
1883 == DEBUG_KIND_VOID))
1890 /* If there are any pointer arguments, turn them into
1891 indirect types in case we later need to convert them to
1893 for (i = 0; i < nargs; i++)
1895 if (debug_get_type_kind (dhandle, arg_types[i])
1896 == DEBUG_KIND_POINTER)
1898 if (arg_slots == NULL)
1900 arg_slots = ((debug_type *)
1901 xmalloc (nargs * sizeof *arg_slots));
1902 memset (arg_slots, 0, nargs * sizeof *arg_slots);
1904 arg_slots[i] = arg_types[i];
1906 debug_make_indirect_type (dhandle,
1908 (const char *) NULL);
1912 arg_types[nargs] = DEBUG_TYPE_NULL;
1914 if (! ieee_read_number (info, pp, &level)
1915 || ! ieee_read_optional_number (info, pp, &father, &present))
1918 /* We can't distinguish between a global function and a static
1920 pv->kind = IEEE_FUNCTION;
1923 && debug_get_type_kind (dhandle, rtype) == DEBUG_KIND_POINTER)
1925 /* Set up the return type as an indirect type pointing to
1926 the variable slot, so that we can change it to a
1927 reference later if appropriate. */
1928 pv->pslot = (debug_type *) xmalloc (sizeof *pv->pslot);
1930 rtype = debug_make_indirect_type (dhandle, pv->pslot,
1931 (const char *) NULL);
1934 type = debug_make_function_type (dhandle, rtype, arg_types, varargs);
1939 /* Record the type in the table. If the corresponding NN record has
1940 a name, name it. FIXME: Is this always correct? */
1942 if (type == DEBUG_TYPE_NULL)
1945 info->vars.vars[varindx].type = type;
1948 && info->vars.vars[varindx].namlen > 0)
1952 name = savestring (info->vars.vars[varindx].name,
1953 info->vars.vars[varindx].namlen);
1955 type = debug_name_type (dhandle, name, type);
1956 else if (tc == 'E' || tc == 'N')
1957 type = debug_tag_type (dhandle, name, type);
1960 struct ieee_tag *it;
1962 /* We must allocate all struct tags as indirect types, so
1963 that if we later see a definition of the tag as a C++
1964 record we can update the indirect slot and automatically
1965 change all the existing references. */
1966 it = (struct ieee_tag *) xmalloc (sizeof *it);
1967 memset (it, 0, sizeof *it);
1968 it->next = info->tags;
1973 type = debug_make_indirect_type (dhandle, &it->slot, name);
1974 type = debug_tag_type (dhandle, name, type);
1982 info->types.types[typeindx].type = type;
1983 info->types.types[typeindx].arg_slots = arg_slots;
1984 info->types.types[typeindx].bitsize = type_bitsize;
1986 /* We may have already allocated type as an indirect type pointing
1987 to slot. It does no harm to replace the indirect type with the
1988 real type. Filling in slot as well handles the indirect types
1989 which are already hanging around. */
1990 if (info->types.types[typeindx].pslot != NULL)
1991 *info->types.types[typeindx].pslot = type;
1996 /* Parse an ATN record. */
1999 parse_ieee_atn (info, pp)
2000 struct ieee_info *info;
2001 const bfd_byte **pp;
2003 const bfd_byte *atn_start, *atn_code_start;
2005 struct ieee_var *pvar;
2009 bfd_vma v, v2, v3, v4, v5;
2011 unsigned long namlen;
2018 if (! ieee_read_number (info, pp, &varindx)
2019 || ! ieee_read_type_index (info, pp, &type))
2022 atn_code_start = *pp;
2024 if (! ieee_read_number (info, pp, &atn_code))
2033 else if (varindx < 32)
2035 ieee_error (info, atn_start, "illegal variable index");
2041 if (varindx >= info->vars.alloc
2042 || info->vars.vars[varindx].name == NULL)
2044 ieee_error (info, atn_start, "undefined variable in ATN");
2048 pvar = info->vars.vars + varindx;
2053 namlen = pvar->namlen;
2056 dhandle = info->dhandle;
2058 /* If we are going to call debug_record_variable with a pointer
2059 type, change the type to an indirect type so that we can later
2060 change it to a reference type if we encounter a C++ pmisc 'R'
2063 && type != DEBUG_TYPE_NULL
2064 && debug_get_type_kind (dhandle, type) == DEBUG_KIND_POINTER)
2074 pvar->pslot = (debug_type *) xmalloc (sizeof *pvar->pslot);
2075 *pvar->pslot = type;
2076 type = debug_make_indirect_type (dhandle, pvar->pslot,
2077 (const char *) NULL);
2086 ieee_error (info, atn_code_start, "unknown ATN type");
2090 /* Automatic variable. */
2091 if (! ieee_read_number (info, pp, &v))
2093 namcopy = savestring (name, namlen);
2095 type = debug_make_void_type (dhandle);
2097 pvar->kind = IEEE_LOCAL;
2098 return debug_record_variable (dhandle, namcopy, type, DEBUG_LOCAL, v);
2101 /* Register variable. */
2102 if (! ieee_read_number (info, pp, &v))
2104 namcopy = savestring (name, namlen);
2106 type = debug_make_void_type (dhandle);
2108 pvar->kind = IEEE_LOCAL;
2109 return debug_record_variable (dhandle, namcopy, type, DEBUG_REGISTER,
2110 ieee_regno_to_genreg (info->abfd, v));
2113 /* Static variable. */
2114 if (! ieee_require_asn (info, pp, &v))
2116 namcopy = savestring (name, namlen);
2118 type = debug_make_void_type (dhandle);
2119 if (info->blockstack.bsp <= info->blockstack.stack)
2122 blocktype = info->blockstack.bsp[-1].kind;
2125 if (blocktype == 4 || blocktype == 6)
2126 pvar->kind = IEEE_LOCAL;
2128 pvar->kind = IEEE_STATIC;
2130 return debug_record_variable (dhandle, namcopy, type,
2131 (blocktype == 4 || blocktype == 6
2132 ? DEBUG_LOCAL_STATIC
2137 /* External function. We don't currently record these. FIXME. */
2139 pvar->kind = IEEE_EXTERNAL;
2143 /* External variable. We don't currently record these. FIXME. */
2145 pvar->kind = IEEE_EXTERNAL;
2149 if (! ieee_read_number (info, pp, &v)
2150 || ! ieee_read_number (info, pp, &v2)
2151 || ! ieee_read_optional_number (info, pp, &v3, &present))
2155 if (! ieee_read_optional_number (info, pp, &v4, &present))
2159 /* We just ignore the two optional fields in v3 and v4, since
2160 they are not defined. */
2162 if (! ieee_require_asn (info, pp, &v3))
2165 /* We have no way to record the column number. FIXME. */
2167 return debug_record_line (dhandle, v, v3);
2170 /* Global variable. */
2171 if (! ieee_require_asn (info, pp, &v))
2173 namcopy = savestring (name, namlen);
2175 type = debug_make_void_type (dhandle);
2177 pvar->kind = IEEE_GLOBAL;
2178 return debug_record_variable (dhandle, namcopy, type, DEBUG_GLOBAL, v);
2181 /* Variable lifetime information. */
2182 if (! ieee_read_number (info, pp, &v))
2185 /* We have no way to record this information. FIXME. */
2189 /* Locked register. */
2190 if (! ieee_read_number (info, pp, &v)
2191 || ! ieee_read_number (info, pp, &v2))
2194 /* I think this means a variable that is both in a register and
2195 a frame slot. We ignore the frame slot. FIXME. */
2197 namcopy = savestring (name, namlen);
2199 type = debug_make_void_type (dhandle);
2201 pvar->kind = IEEE_LOCAL;
2202 return debug_record_variable (dhandle, namcopy, type, DEBUG_REGISTER, v);
2205 /* Reserved for FORTRAN common. */
2206 ieee_error (info, atn_code_start, "unsupported ATN11");
2208 /* Return true to keep going. */
2212 /* Based variable. */
2216 if (! ieee_read_number (info, pp, &v)
2217 || ! ieee_read_number (info, pp, &v2)
2218 || ! ieee_read_optional_number (info, pp, &v3, &present))
2222 if (! ieee_read_optional_number (info, pp, &v4, &present))
2226 if (! ieee_read_optional_number (info, pp, &v5, &present))
2231 /* We have no way to record this information. FIXME. */
2233 ieee_error (info, atn_code_start, "unsupported ATN12");
2235 /* Return true to keep going. */
2239 /* Constant. The description of this that I have is ambiguous,
2240 so I'm not going to try to implement it. */
2241 if (! ieee_read_number (info, pp, &v)
2242 || ! ieee_read_optional_number (info, pp, &v2, &present))
2246 if (! ieee_read_optional_number (info, pp, &v2, &present))
2250 if (! ieee_read_optional_id (info, pp, &name, &namlen, &present))
2255 if ((ieee_record_enum_type) **pp == ieee_e2_first_byte_enum)
2257 if (! ieee_require_asn (info, pp, &v3))
2264 /* Static variable from assembler. */
2266 if (! ieee_read_number (info, pp, &v)
2267 || ! ieee_read_optional_number (info, pp, &v2, &present)
2268 || ! ieee_require_asn (info, pp, &v3))
2270 namcopy = savestring (name, namlen);
2271 /* We don't really handle this correctly. FIXME. */
2272 return debug_record_variable (dhandle, namcopy,
2273 debug_make_void_type (dhandle),
2274 v2 != 0 ? DEBUG_GLOBAL : DEBUG_STATIC,
2278 /* Procedure miscellaneous information. */
2280 /* Variable miscellaneous information. */
2282 /* Module miscellaneous information. */
2283 if (! ieee_read_number (info, pp, &v)
2284 || ! ieee_read_number (info, pp, &v2)
2285 || ! ieee_read_optional_id (info, pp, &name, &namlen, &present))
2288 if (atn_code == 62 && v == 80)
2292 ieee_error (info, atn_code_start,
2293 "unexpected string in C++ misc");
2296 return ieee_read_cxx_misc (info, pp, v2);
2299 /* We just ignore all of this stuff. FIXME. */
2301 for (; v2 > 0; --v2)
2303 switch ((ieee_record_enum_type) **pp)
2306 ieee_error (info, *pp, "bad misc record");
2309 case ieee_at_record_enum:
2310 if (! ieee_require_atn65 (info, pp, &name, &namlen))
2314 case ieee_e2_first_byte_enum:
2315 if (! ieee_require_asn (info, pp, &v3))
2327 /* Handle C++ debugging miscellaneous records. This is called for
2328 procedure miscellaneous records of type 80. */
2331 ieee_read_cxx_misc (info, pp, count)
2332 struct ieee_info *info;
2333 const bfd_byte **pp;
2334 unsigned long count;
2336 const bfd_byte *start;
2341 /* Get the category of C++ misc record. */
2342 if (! ieee_require_asn (info, pp, &category))
2349 ieee_error (info, start, "unrecognized C++ misc record");
2353 if (! ieee_read_cxx_class (info, pp, count))
2361 unsigned long namlen;
2363 /* The IEEE spec indicates that the 'M' record only has a
2364 flags field. The MRI compiler also emits the name of the
2367 if (! ieee_require_asn (info, pp, &flags))
2369 if (*pp < info->pend
2370 && (ieee_record_enum_type) **pp == ieee_at_record_enum)
2372 if (! ieee_require_atn65 (info, pp, &name, &namlen))
2376 /* This is emitted for method functions, but I don't think we
2377 care very much. It might help if it told us useful
2378 information like the class with which this function is
2379 associated, but it doesn't, so it isn't helpful. */
2384 if (! ieee_read_cxx_defaults (info, pp, count))
2390 const char *name, *mangled, *class;
2391 unsigned long namlen, mangledlen, classlen;
2394 /* Pointer to member. */
2396 if (! ieee_require_atn65 (info, pp, &name, &namlen)
2397 || ! ieee_require_atn65 (info, pp, &mangled, &mangledlen)
2398 || ! ieee_require_atn65 (info, pp, &class, &classlen)
2399 || ! ieee_require_asn (info, pp, &control))
2402 /* FIXME: We should now track down name and change its type. */
2407 if (! ieee_read_reference (info, pp))
2415 /* Read a C++ class definition. This is a pmisc type 80 record of
2419 ieee_read_cxx_class (info, pp, count)
2420 struct ieee_info *info;
2421 const bfd_byte **pp;
2422 unsigned long count;
2424 const bfd_byte *start;
2427 unsigned long taglen;
2428 struct ieee_tag *it;
2430 debug_field *fields;
2431 unsigned int field_count, field_alloc;
2432 debug_baseclass *baseclasses;
2433 unsigned int baseclasses_count, baseclasses_alloc;
2434 const debug_field *structfields;
2438 unsigned long namlen;
2439 debug_method_variant *variants;
2443 unsigned int methods_count, methods_alloc;
2444 debug_type vptrbase;
2446 debug_method *dmethods;
2450 if (! ieee_require_asn (info, pp, &class))
2454 if (! ieee_require_atn65 (info, pp, &tag, &taglen))
2458 /* Find the C struct with this name. */
2459 for (it = info->tags; it != NULL; it = it->next)
2460 if (it->name[0] == tag[0]
2461 && strncmp (it->name, tag, taglen) == 0
2462 && strlen (it->name) == taglen)
2466 ieee_error (info, start, "undefined C++ object");
2470 dhandle = info->dhandle;
2476 baseclasses_count = 0;
2477 baseclasses_alloc = 0;
2481 vptrbase = DEBUG_TYPE_NULL;
2484 structfields = debug_get_fields (dhandle, it->type);
2489 const bfd_byte *spec_start;
2493 if (! ieee_require_asn (info, pp, &id))
2500 ieee_error (info, spec_start, "unrecognized C++ object spec");
2505 bfd_vma flags, cinline;
2506 const char *basename, *fieldname;
2507 unsigned long baselen, fieldlen;
2509 debug_type basetype;
2512 enum debug_visibility visibility;
2513 debug_baseclass baseclass;
2515 /* This represents a base or friend class. */
2517 if (! ieee_require_asn (info, pp, &flags)
2518 || ! ieee_require_atn65 (info, pp, &basename, &baselen)
2519 || ! ieee_require_asn (info, pp, &cinline)
2520 || ! ieee_require_atn65 (info, pp, &fieldname, &fieldlen))
2524 /* We have no way of recording friend information, so we
2526 if ((flags & BASEFLAGS_FRIEND) != 0)
2529 /* I assume that either all of the members of the
2530 baseclass are included in the object, starting at the
2531 beginning of the object, or that none of them are
2534 if ((fieldlen == 0) == (cinline == 0))
2536 ieee_error (info, start, "unsupported C++ object type");
2540 basecopy = savestring (basename, baselen);
2541 basetype = debug_find_tagged_type (dhandle, basecopy,
2542 DEBUG_KIND_ILLEGAL);
2544 if (basetype == DEBUG_TYPE_NULL)
2546 ieee_error (info, start, "C++ base class not defined");
2554 const debug_field *pf;
2556 if (structfields == NULL)
2558 ieee_error (info, start, "C++ object has no fields");
2562 for (pf = structfields; *pf != DEBUG_FIELD_NULL; pf++)
2566 fname = debug_get_field_name (dhandle, *pf);
2569 if (fname[0] == fieldname[0]
2570 && strncmp (fname, fieldname, fieldlen) == 0
2571 && strlen (fname) == fieldlen)
2574 if (*pf == DEBUG_FIELD_NULL)
2576 ieee_error (info, start,
2577 "C++ base class not found in container");
2581 bitpos = debug_get_field_bitpos (dhandle, *pf);
2584 if ((flags & BASEFLAGS_VIRTUAL) != 0)
2588 if ((flags & BASEFLAGS_PRIVATE) != 0)
2589 visibility = DEBUG_VISIBILITY_PRIVATE;
2591 visibility = DEBUG_VISIBILITY_PUBLIC;
2593 baseclass = debug_make_baseclass (dhandle, basetype, bitpos,
2594 virtualp, visibility);
2595 if (baseclass == DEBUG_BASECLASS_NULL)
2598 if (baseclasses_count + 1 >= baseclasses_alloc)
2600 baseclasses_alloc += 10;
2601 baseclasses = ((debug_baseclass *)
2602 xrealloc (baseclasses,
2604 * sizeof *baseclasses)));
2607 baseclasses[baseclasses_count] = baseclass;
2608 ++baseclasses_count;
2609 baseclasses[baseclasses_count] = DEBUG_BASECLASS_NULL;
2616 const char *fieldname, *mangledname;
2617 unsigned long fieldlen, mangledlen;
2621 const debug_field *pf;
2622 enum debug_visibility visibility;
2625 /* This represents a data member. */
2627 if (! ieee_require_asn (info, pp, &flags)
2628 || ! ieee_require_atn65 (info, pp, &fieldname, &fieldlen)
2629 || ! ieee_require_atn65 (info, pp, &mangledname, &mangledlen))
2633 fieldcopy = savestring (fieldname, fieldlen);
2635 staticp = (flags & CXXFLAGS_STATIC) != 0 ? true : false;
2639 struct ieee_var *pv, *pvend;
2641 /* See if we can find a definition for this variable. */
2642 pv = info->vars.vars;
2643 pvend = pv + info->vars.alloc;
2644 for (; pv < pvend; pv++)
2645 if (pv->namlen == mangledlen
2646 && strncmp (pv->name, mangledname, mangledlen) == 0)
2652 /* This can happen if the variable is never used. */
2653 ftype = ieee_builtin_type (info, start,
2654 (unsigned int) builtin_void);
2661 if (structfields == NULL)
2663 ieee_error (info, start, "C++ object has no fields");
2667 for (pf = structfields, findx = 0;
2668 *pf != DEBUG_FIELD_NULL;
2673 fname = debug_get_field_name (dhandle, *pf);
2676 if (fname[0] == mangledname[0]
2677 && strncmp (fname, mangledname, mangledlen) == 0
2678 && strlen (fname) == mangledlen)
2681 if (*pf == DEBUG_FIELD_NULL)
2683 ieee_error (info, start,
2684 "C++ data member not found in container");
2688 ftype = debug_get_field_type (dhandle, *pf);
2690 if (debug_get_type_kind (dhandle, ftype) == DEBUG_KIND_POINTER)
2692 /* We might need to convert this field into a
2693 reference type later on, so make it an indirect
2695 if (it->fslots == NULL)
2698 const debug_field *pfcnt;
2701 for (pfcnt = structfields;
2702 *pfcnt != DEBUG_FIELD_NULL;
2705 it->fslots = ((debug_type *)
2706 xmalloc (fcnt * sizeof *it->fslots));
2707 memset (it->fslots, 0,
2708 fcnt * sizeof *it->fslots);
2711 if (ftype == DEBUG_TYPE_NULL)
2713 it->fslots[findx] = ftype;
2714 ftype = debug_make_indirect_type (dhandle,
2716 (const char *) NULL);
2719 if (ftype == DEBUG_TYPE_NULL)
2722 switch (flags & CXXFLAGS_VISIBILITY)
2725 ieee_error (info, start, "unknown C++ visibility");
2728 case CXXFLAGS_VISIBILITY_PUBLIC:
2729 visibility = DEBUG_VISIBILITY_PUBLIC;
2732 case CXXFLAGS_VISIBILITY_PRIVATE:
2733 visibility = DEBUG_VISIBILITY_PRIVATE;
2736 case CXXFLAGS_VISIBILITY_PROTECTED:
2737 visibility = DEBUG_VISIBILITY_PROTECTED;
2745 mangledcopy = savestring (mangledname, mangledlen);
2747 field = debug_make_static_member (dhandle, fieldcopy,
2753 bfd_vma bitpos, bitsize;
2755 bitpos = debug_get_field_bitpos (dhandle, *pf);
2756 bitsize = debug_get_field_bitsize (dhandle, *pf);
2757 if (bitpos == (bfd_vma) -1 || bitsize == (bfd_vma) -1)
2759 ieee_error (info, start, "bad C++ field bit pos or size");
2762 field = debug_make_field (dhandle, fieldcopy, ftype, bitpos,
2763 bitsize, visibility);
2766 if (field == DEBUG_FIELD_NULL)
2769 if (field_count + 1 >= field_alloc)
2772 fields = ((debug_field *)
2773 xrealloc (fields, field_alloc * sizeof *fields));
2776 fields[field_count] = field;
2778 fields[field_count] = DEBUG_FIELD_NULL;
2785 bfd_vma flags, virtindex, control;
2786 const char *name, *mangled;
2787 unsigned long namlen, mangledlen;
2788 struct ieee_var *pv, *pvend;
2790 enum debug_visibility visibility;
2791 boolean constp, volatilep;
2793 debug_method_variant mv;
2794 struct ieee_method *meth;
2797 if (! ieee_require_asn (info, pp, &flags)
2798 || ! ieee_require_atn65 (info, pp, &name, &namlen)
2799 || ! ieee_require_atn65 (info, pp, &mangled, &mangledlen))
2804 if (! ieee_require_asn (info, pp, &virtindex))
2808 if (! ieee_require_asn (info, pp, &control))
2812 /* We just ignore the control information. */
2814 /* We have no way to represent friend information, so we
2816 if ((flags & CXXFLAGS_FRIEND) != 0)
2819 /* We should already have seen a type for the function. */
2820 pv = info->vars.vars;
2821 pvend = pv + info->vars.alloc;
2822 for (; pv < pvend; pv++)
2823 if (pv->namlen == mangledlen
2824 && strncmp (pv->name, mangled, mangledlen) == 0)
2829 /* We won't have type information for this function if
2830 it is not included in this file. We don't try to
2831 handle this case. FIXME. */
2832 type = (debug_make_function_type
2834 ieee_builtin_type (info, start,
2835 (unsigned int) builtin_void),
2836 (debug_type *) NULL,
2841 debug_type return_type;
2842 const debug_type *arg_types;
2845 if (debug_get_type_kind (dhandle, pv->type)
2846 != DEBUG_KIND_FUNCTION)
2848 ieee_error (info, start,
2849 "bad type for C++ method function");
2853 return_type = debug_get_return_type (dhandle, pv->type);
2854 arg_types = debug_get_parameter_types (dhandle, pv->type,
2856 if (return_type == DEBUG_TYPE_NULL || arg_types == NULL)
2858 ieee_error (info, start,
2859 "no type information for C++ method function");
2863 type = debug_make_method_type (dhandle, return_type, it->type,
2864 (debug_type *) arg_types,
2867 if (type == DEBUG_TYPE_NULL)
2870 switch (flags & CXXFLAGS_VISIBILITY)
2873 ieee_error (info, start, "unknown C++ visibility");
2876 case CXXFLAGS_VISIBILITY_PUBLIC:
2877 visibility = DEBUG_VISIBILITY_PUBLIC;
2880 case CXXFLAGS_VISIBILITY_PRIVATE:
2881 visibility = DEBUG_VISIBILITY_PRIVATE;
2884 case CXXFLAGS_VISIBILITY_PROTECTED:
2885 visibility = DEBUG_VISIBILITY_PROTECTED;
2889 constp = (flags & CXXFLAGS_CONST) != 0 ? true : false;
2890 volatilep = (flags & CXXFLAGS_VOLATILE) != 0 ? true : false;
2892 mangledcopy = savestring (mangled, mangledlen);
2894 if ((flags & CXXFLAGS_STATIC) != 0)
2898 ieee_error (info, start, "C++ static virtual method");
2901 mv = debug_make_static_method_variant (dhandle, mangledcopy,
2908 debug_type vcontext;
2913 vcontext = DEBUG_TYPE_NULL;
2917 /* FIXME: This should depend upon the pointer
2919 voffset = virtindex * 4;
2920 /* FIXME: How can we calculate this correctly? */
2921 vcontext = it->type;
2923 mv = debug_make_method_variant (dhandle, mangledcopy, type,
2928 if (mv == DEBUG_METHOD_VARIANT_NULL)
2931 for (meth = methods, im = 0; im < methods_count; meth++, im++)
2932 if (meth->namlen == namlen
2933 && strncmp (meth->name, name, namlen) == 0)
2935 if (im >= methods_count)
2937 if (methods_count >= methods_alloc)
2939 methods_alloc += 10;
2940 methods = ((struct ieee_method *)
2942 methods_alloc * sizeof *methods));
2944 methods[methods_count].name = name;
2945 methods[methods_count].namlen = namlen;
2946 methods[methods_count].variants = NULL;
2947 methods[methods_count].count = 0;
2948 methods[methods_count].alloc = 0;
2949 meth = methods + methods_count;
2953 if (meth->count + 1 >= meth->alloc)
2956 meth->variants = ((debug_method_variant *)
2957 xrealloc (meth->variants,
2959 * sizeof *meth->variants)));
2962 meth->variants[meth->count] = mv;
2964 meth->variants[meth->count] = DEBUG_METHOD_VARIANT_NULL;
2972 /* We have no way to store this information, so we just
2974 if (! ieee_require_asn (info, pp, &spec))
2977 if ((spec & 4) != 0)
2979 const char *filename;
2980 unsigned long filenamlen;
2983 if (! ieee_require_atn65 (info, pp, &filename, &filenamlen)
2984 || ! ieee_require_asn (info, pp, &lineno))
2988 else if ((spec & 8) != 0)
2990 const char *mangled;
2991 unsigned long mangledlen;
2993 if (! ieee_require_atn65 (info, pp, &mangled, &mangledlen))
2999 ieee_error (info, start,
3000 "unrecognized C++ object overhead spec");
3008 const char *vname, *basename;
3009 unsigned long vnamelen, baselen;
3010 bfd_vma vsize, control;
3012 /* A virtual table pointer. */
3014 if (! ieee_require_atn65 (info, pp, &vname, &vnamelen)
3015 || ! ieee_require_asn (info, pp, &vsize)
3016 || ! ieee_require_atn65 (info, pp, &basename, &baselen)
3017 || ! ieee_require_asn (info, pp, &control))
3021 /* We just ignore the control number. We don't care what
3022 the virtual table name is. We have no way to store the
3023 virtual table size, and I don't think we care anyhow. */
3025 /* FIXME: We can't handle multiple virtual table pointers. */
3033 basecopy = savestring (basename, baselen);
3034 vptrbase = debug_find_tagged_type (dhandle, basecopy,
3035 DEBUG_KIND_ILLEGAL);
3037 if (vptrbase == DEBUG_TYPE_NULL)
3039 ieee_error (info, start, "undefined C++ vtable");
3048 /* Now that we have seen all the method variants, we can call
3049 debug_make_method for each one. */
3051 if (methods_count == 0)
3057 dmethods = ((debug_method *)
3058 xmalloc ((methods_count + 1) * sizeof *dmethods));
3059 for (i = 0; i < methods_count; i++)
3063 namcopy = savestring (methods[i].name, methods[i].namlen);
3064 dmethods[i] = debug_make_method (dhandle, namcopy,
3065 methods[i].variants);
3066 if (dmethods[i] == DEBUG_METHOD_NULL)
3069 dmethods[i] = DEBUG_METHOD_NULL;
3073 /* The struct type was created as an indirect type pointing at
3074 it->slot. We update it->slot to automatically update all
3075 references to this struct. */
3076 it->slot = debug_make_object_type (dhandle,
3078 debug_get_type_size (dhandle,
3080 fields, baseclasses, dmethods,
3082 if (it->slot == DEBUG_TYPE_NULL)
3088 /* Read C++ default argument value and reference type information. */
3091 ieee_read_cxx_defaults (info, pp, count)
3092 struct ieee_info *info;
3093 const bfd_byte **pp;
3094 unsigned long count;
3096 const bfd_byte *start;
3098 unsigned long fnlen;
3103 /* Giving the function name before the argument count is an addendum
3104 to the spec. The function name is demangled, though, so this
3105 record must always refer to the current function. */
3107 if (info->blockstack.bsp <= info->blockstack.stack
3108 || info->blockstack.bsp[-1].fnindx == (unsigned int) -1)
3110 ieee_error (info, start, "C++ default values not in a function");
3114 if (! ieee_require_atn65 (info, pp, &fnname, &fnlen)
3115 || ! ieee_require_asn (info, pp, &defcount))
3119 while (defcount-- > 0)
3123 unsigned long strvallen;
3125 if (! ieee_require_asn (info, pp, &type))
3137 if (! ieee_require_asn (info, pp, &val))
3144 if (! ieee_require_atn65 (info, pp, &strval, &strvallen))
3150 ieee_error (info, start, "unrecognized C++ default type");
3154 /* We have no way to record the default argument values, so we
3155 just ignore them. FIXME. */
3158 /* Any remaining arguments are indices of parameters that are really
3163 debug_type *arg_slots;
3165 dhandle = info->dhandle;
3166 arg_slots = info->types.types[info->blockstack.bsp[-1].fnindx].arg_slots;
3172 if (! ieee_require_asn (info, pp, &indx))
3174 /* The index is 1 based. */
3176 if (arg_slots == NULL
3177 || arg_slots[indx] == DEBUG_TYPE_NULL
3178 || (debug_get_type_kind (dhandle, arg_slots[indx])
3179 != DEBUG_KIND_POINTER))
3181 ieee_error (info, start, "reference parameter is not a pointer");
3185 target = debug_get_target_type (dhandle, arg_slots[indx]);
3186 arg_slots[indx] = debug_make_reference_type (dhandle, target);
3187 if (arg_slots[indx] == DEBUG_TYPE_NULL)
3195 /* Read a C++ reference definition. */
3198 ieee_read_reference (info, pp)
3199 struct ieee_info *info;
3200 const bfd_byte **pp;
3202 const bfd_byte *start;
3204 const char *class, *name;
3205 unsigned long classlen, namlen;
3211 if (! ieee_require_asn (info, pp, &flags))
3214 /* Giving the class name before the member name is in an addendum to
3218 if (! ieee_require_atn65 (info, pp, &class, &classlen))
3222 if (! ieee_require_atn65 (info, pp, &name, &namlen))
3229 struct ieee_var *pv = NULL;
3231 /* We search from the last variable indices to the first in
3232 hopes of finding local variables correctly. FIXME: This
3233 probably won't work in all cases. On the other hand, I don't
3235 for (i = (int) info->vars.alloc - 1; i >= 0; i--)
3239 pv = info->vars.vars + i;
3241 if (pv->pslot == NULL
3242 || pv->namlen != namlen
3243 || strncmp (pv->name, name, namlen) != 0)
3250 ieee_error (info, start,
3251 "unrecognized C++ reference type");
3255 /* Global variable or function. */
3256 if (pv->kind == IEEE_GLOBAL
3257 || pv->kind == IEEE_EXTERNAL
3258 || pv->kind == IEEE_FUNCTION)
3263 /* Global static variable or function. */
3264 if (pv->kind == IEEE_STATIC
3265 || pv->kind == IEEE_FUNCTION)
3270 /* Local variable. */
3271 if (pv->kind == IEEE_LOCAL)
3285 struct ieee_tag *it;
3287 for (it = info->tags; it != NULL; it = it->next)
3289 if (it->name[0] == class[0]
3290 && strncmp (it->name, class, classlen) == 0
3291 && strlen (it->name) == classlen)
3293 if (it->fslots != NULL)
3295 const debug_field *pf;
3298 pf = debug_get_fields (info->dhandle, it->type);
3301 ieee_error (info, start,
3302 "C++ reference in class with no fields");
3306 for (findx = 0; *pf != DEBUG_FIELD_NULL; pf++, findx++)
3310 fname = debug_get_field_name (info->dhandle, *pf);
3313 if (strncmp (fname, name, namlen) == 0
3314 && strlen (fname) == namlen)
3316 pslot = it->fslots + findx;
3329 ieee_error (info, start, "C++ reference not found");
3333 /* We allocated the type of the object as an indirect type pointing
3334 to *pslot, which we can now update to be a reference type. */
3335 if (debug_get_type_kind (info->dhandle, *pslot) != DEBUG_KIND_POINTER)
3337 ieee_error (info, start, "C++ reference is not pointer");
3341 target = debug_get_target_type (info->dhandle, *pslot);
3342 *pslot = debug_make_reference_type (info->dhandle, target);
3343 if (*pslot == DEBUG_TYPE_NULL)
3349 /* Require an ASN record. */
3352 ieee_require_asn (info, pp, pv)
3353 struct ieee_info *info;
3354 const bfd_byte **pp;
3357 const bfd_byte *start;
3358 ieee_record_enum_type c;
3363 c = (ieee_record_enum_type) **pp;
3364 if (c != ieee_e2_first_byte_enum)
3366 ieee_error (info, start, "missing required ASN");
3371 c = (ieee_record_enum_type) (((unsigned int) c << 8) | **pp);
3372 if (c != ieee_asn_record_enum)
3374 ieee_error (info, start, "missing required ASN");
3379 /* Just ignore the variable index. */
3380 if (! ieee_read_number (info, pp, &varindx))
3383 return ieee_read_expression (info, pp, pv);
3386 /* Require an ATN65 record. */
3389 ieee_require_atn65 (info, pp, pname, pnamlen)
3390 struct ieee_info *info;
3391 const bfd_byte **pp;
3393 unsigned long *pnamlen;
3395 const bfd_byte *start;
3396 ieee_record_enum_type c;
3397 bfd_vma name_indx, type_indx, atn_code;
3401 c = (ieee_record_enum_type) **pp;
3402 if (c != ieee_at_record_enum)
3404 ieee_error (info, start, "missing required ATN65");
3409 c = (ieee_record_enum_type) (((unsigned int) c << 8) | **pp);
3410 if (c != ieee_atn_record_enum)
3412 ieee_error (info, start, "missing required ATN65");
3417 if (! ieee_read_number (info, pp, &name_indx)
3418 || ! ieee_read_number (info, pp, &type_indx)
3419 || ! ieee_read_number (info, pp, &atn_code))
3422 /* Just ignore name_indx. */
3424 if (type_indx != 0 || atn_code != 65)
3426 ieee_error (info, start, "bad ATN65 record");
3430 return ieee_read_id (info, pp, pname, pnamlen);
3433 /* Convert a register number in IEEE debugging information into a
3434 generic register number. */
3437 ieee_regno_to_genreg (abfd, r)
3444 /* Convert a generic register number to an IEEE specific one. */
3447 ieee_genreg_to_regno (abfd, r)
3454 /* These routines build IEEE debugging information out of the generic
3455 debugging information. */
3457 /* We build the IEEE debugging information byte by byte. Rather than
3458 waste time copying data around, we use a linked list of buffers to
3461 #define IEEE_BUFSIZE (490)
3466 struct ieee_buf *next;
3467 /* Number of data bytes in this buffer. */
3470 bfd_byte buf[IEEE_BUFSIZE];
3473 /* In order to generate the BB11 blocks required by the HP emulator,
3474 we keep track of ranges of addresses which correspond to a given
3475 compilation unit. */
3480 struct ieee_range *next;
3487 /* This structure holds information for a class on the type stack. */
3489 struct ieee_type_class
3491 /* The name of the class. */
3493 /* The name index in the debugging information. */
3495 /* The pmisc records for the class. */
3496 struct ieee_buf *pmiscbuf;
3497 /* The number of pmisc records. */
3498 unsigned int pmisccount;
3499 /* The name of the class holding the virtual table, if not this
3502 /* Whether this class holds its own virtual table. */
3504 /* The largest virtual table offset seen so far. */
3506 /* The current method. */
3508 /* Additional pmisc records used to record fields of reference type. */
3509 struct ieee_buf *refs;
3512 /* This is how we store types for the writing routines. Most types
3513 are simply represented by a type index. */
3515 struct ieee_write_type
3519 /* The size of the type, if known. */
3521 /* If this is a function or method type, we build the type here, and
3522 only add it to the output buffers if we need it. */
3523 struct ieee_buf *fndef;
3524 /* If this is a struct, this is where the struct definition is
3526 struct ieee_buf *strdef;
3527 /* If this is a class, this is where the class information is built. */
3528 struct ieee_type_class *classdef;
3529 /* Whether the type is unsigned. */
3530 unsigned int unsignedp : 1;
3531 /* Whether this is a reference type. */
3532 unsigned int referencep : 1;
3535 /* This is the type stack used by the debug writing routines. FIXME:
3536 We could generate more efficient output if we remembered when we
3537 have output a particular type before. */
3539 struct ieee_type_stack
3541 /* Next entry on stack. */
3542 struct ieee_type_stack *next;
3543 /* Type information. */
3544 struct ieee_write_type type;
3547 /* This is a list of associations between names and types. This could
3548 be more efficiently implemented as a hash table. */
3550 struct ieee_name_type
3552 /* Next name/type assocation. */
3553 struct ieee_name_type *next;
3557 struct ieee_write_type type;
3558 /* If this is a tag which has not yet been defined, this is the
3559 kind. If the tag has been defined, this is DEBUG_KIND_ILLEGAL. */
3560 enum debug_type_kind kind;
3563 /* This is a list of pending function parameter information. We don't
3564 output them until we see the first block. */
3566 struct ieee_pending_parm
3568 /* Next pending parameter. */
3569 struct ieee_pending_parm *next;
3574 /* Whether the type is a reference. */
3577 enum debug_parm_kind kind;
3582 /* This is the handle passed down by debug_write. */
3586 /* BFD we are writing to. */
3588 /* Current data buffer. */
3589 struct ieee_buf *current;
3590 /* Filename of current compilation unit. */
3591 const char *filename;
3592 /* Module name of current compilation unit. */
3593 const char *modname;
3594 /* List of finished data buffers. */
3595 struct ieee_buf *data;
3596 /* List of buffers for typedefs in the current compilation unit. */
3597 struct ieee_buf *types;
3598 /* List of buffers for variables and functions in the current
3599 compilation unit. */
3600 struct ieee_buf *vars;
3601 /* List of buffers for C++ class definitions in the current
3602 compilation unit. */
3603 struct ieee_buf *cxx;
3604 /* List of buffers for line numbers in the current compilation unit. */
3605 struct ieee_buf *linenos;
3606 /* Ranges for the current compilation unit. */
3607 struct ieee_range *ranges;
3608 /* Nested pending ranges. */
3609 struct ieee_range *pending_ranges;
3611 struct ieee_type_stack *type_stack;
3612 /* Next unallocated type index. */
3613 unsigned int type_indx;
3614 /* Next unallocated name index. */
3615 unsigned int name_indx;
3617 struct ieee_name_type *typedefs;
3619 struct ieee_name_type *tags;
3620 /* The depth of block nesting. This is 0 outside a function, and 1
3621 just after start_function is called. */
3622 unsigned int block_depth;
3623 /* The name of the current function. */
3625 /* List of buffers for the type of the function we are currently
3627 struct ieee_buf *fntype;
3628 /* List of buffers for the parameters of the function we are
3629 currently writing out. */
3630 struct ieee_buf *fnargs;
3631 /* Number of arguments written to fnargs. */
3632 unsigned int fnargcount;
3633 /* Pending function parameters. */
3634 struct ieee_pending_parm *pending_parms;
3635 /* Current line number filename. */
3636 const char *lineno_filename;
3637 /* Line number name index. */
3638 unsigned int lineno_name_indx;
3639 /* Highest address seen at end of procedure. */
3643 static boolean ieee_change_buffer
3644 PARAMS ((struct ieee_handle *, struct ieee_buf **));
3645 static boolean ieee_real_write_byte PARAMS ((struct ieee_handle *, int));
3646 static boolean ieee_write_2bytes PARAMS ((struct ieee_handle *, int));
3647 static boolean ieee_write_number PARAMS ((struct ieee_handle *, bfd_vma));
3648 static boolean ieee_write_id PARAMS ((struct ieee_handle *, const char *));
3649 static boolean ieee_write_asn
3650 PARAMS ((struct ieee_handle *, unsigned int, bfd_vma));
3651 static boolean ieee_write_atn65
3652 PARAMS ((struct ieee_handle *, unsigned int, const char *));
3653 static boolean ieee_push_type
3654 PARAMS ((struct ieee_handle *, unsigned int, unsigned int, boolean));
3655 static unsigned int ieee_pop_type PARAMS ((struct ieee_handle *));
3656 static void ieee_pop_unused_type PARAMS ((struct ieee_handle *));
3657 static unsigned int ieee_pop_type_used
3658 PARAMS ((struct ieee_handle *, boolean));
3659 static boolean ieee_add_range
3660 PARAMS ((struct ieee_handle *, bfd_vma, bfd_vma));
3661 static boolean ieee_start_range PARAMS ((struct ieee_handle *, bfd_vma));
3662 static boolean ieee_end_range PARAMS ((struct ieee_handle *, bfd_vma));
3663 static boolean ieee_define_type
3664 PARAMS ((struct ieee_handle *, unsigned int, boolean));
3665 static boolean ieee_define_named_type
3666 PARAMS ((struct ieee_handle *, const char *, boolean, unsigned int,
3667 unsigned int, boolean, struct ieee_buf **));
3668 static boolean ieee_finish_compilation_unit PARAMS ((struct ieee_handle *));
3669 static boolean ieee_output_pending_parms PARAMS ((struct ieee_handle *));
3670 static unsigned int ieee_vis_to_flags PARAMS ((enum debug_visibility));
3671 static boolean ieee_class_method_var
3672 PARAMS ((struct ieee_handle *, const char *, enum debug_visibility, boolean,
3673 boolean, boolean, bfd_vma, boolean));
3675 static boolean ieee_start_compilation_unit PARAMS ((PTR, const char *));
3676 static boolean ieee_start_source PARAMS ((PTR, const char *));
3677 static boolean ieee_empty_type PARAMS ((PTR));
3678 static boolean ieee_void_type PARAMS ((PTR));
3679 static boolean ieee_int_type PARAMS ((PTR, unsigned int, boolean));
3680 static boolean ieee_float_type PARAMS ((PTR, unsigned int));
3681 static boolean ieee_complex_type PARAMS ((PTR, unsigned int));
3682 static boolean ieee_bool_type PARAMS ((PTR, unsigned int));
3683 static boolean ieee_enum_type
3684 PARAMS ((PTR, const char *, const char **, bfd_signed_vma *));
3685 static boolean ieee_pointer_type PARAMS ((PTR));
3686 static boolean ieee_function_type PARAMS ((PTR, int, boolean));
3687 static boolean ieee_reference_type PARAMS ((PTR));
3688 static boolean ieee_range_type PARAMS ((PTR, bfd_signed_vma, bfd_signed_vma));
3689 static boolean ieee_array_type
3690 PARAMS ((PTR, bfd_signed_vma, bfd_signed_vma, boolean));
3691 static boolean ieee_set_type PARAMS ((PTR, boolean));
3692 static boolean ieee_offset_type PARAMS ((PTR));
3693 static boolean ieee_method_type PARAMS ((PTR, boolean, int, boolean));
3694 static boolean ieee_const_type PARAMS ((PTR));
3695 static boolean ieee_volatile_type PARAMS ((PTR));
3696 static boolean ieee_start_struct_type
3697 PARAMS ((PTR, const char *, unsigned int, boolean, unsigned int));
3698 static boolean ieee_struct_field
3699 PARAMS ((PTR, const char *, bfd_vma, bfd_vma, enum debug_visibility));
3700 static boolean ieee_end_struct_type PARAMS ((PTR));
3701 static boolean ieee_start_class_type
3702 PARAMS ((PTR, const char *, unsigned int, boolean, unsigned int, boolean,
3704 static boolean ieee_class_static_member
3705 PARAMS ((PTR, const char *, const char *, enum debug_visibility));
3706 static boolean ieee_class_baseclass
3707 PARAMS ((PTR, bfd_vma, boolean, enum debug_visibility));
3708 static boolean ieee_class_start_method PARAMS ((PTR, const char *));
3709 static boolean ieee_class_method_variant
3710 PARAMS ((PTR, const char *, enum debug_visibility, boolean, boolean,
3712 static boolean ieee_class_static_method_variant
3713 PARAMS ((PTR, const char *, enum debug_visibility, boolean, boolean));
3714 static boolean ieee_class_end_method PARAMS ((PTR));
3715 static boolean ieee_end_class_type PARAMS ((PTR));
3716 static boolean ieee_typedef_type PARAMS ((PTR, const char *));
3717 static boolean ieee_tag_type
3718 PARAMS ((PTR, const char *, unsigned int, enum debug_type_kind));
3719 static boolean ieee_typdef PARAMS ((PTR, const char *));
3720 static boolean ieee_tag PARAMS ((PTR, const char *));
3721 static boolean ieee_int_constant PARAMS ((PTR, const char *, bfd_vma));
3722 static boolean ieee_float_constant PARAMS ((PTR, const char *, double));
3723 static boolean ieee_typed_constant PARAMS ((PTR, const char *, bfd_vma));
3724 static boolean ieee_variable
3725 PARAMS ((PTR, const char *, enum debug_var_kind, bfd_vma));
3726 static boolean ieee_start_function PARAMS ((PTR, const char *, boolean));
3727 static boolean ieee_function_parameter
3728 PARAMS ((PTR, const char *, enum debug_parm_kind, bfd_vma));
3729 static boolean ieee_start_block PARAMS ((PTR, bfd_vma));
3730 static boolean ieee_end_block PARAMS ((PTR, bfd_vma));
3731 static boolean ieee_end_function PARAMS ((PTR));
3732 static boolean ieee_lineno
3733 PARAMS ((PTR, const char *, unsigned long, bfd_vma));
3735 static const struct debug_write_fns ieee_fns =
3737 ieee_start_compilation_unit,
3748 ieee_reference_type,
3756 ieee_start_struct_type,
3758 ieee_end_struct_type,
3759 ieee_start_class_type,
3760 ieee_class_static_member,
3761 ieee_class_baseclass,
3762 ieee_class_start_method,
3763 ieee_class_method_variant,
3764 ieee_class_static_method_variant,
3765 ieee_class_end_method,
3766 ieee_end_class_type,
3772 ieee_float_constant,
3773 ieee_typed_constant,
3775 ieee_start_function,
3776 ieee_function_parameter,
3783 /* Change the current buffer to a specified buffer chain. */
3786 ieee_change_buffer (info, ppbuf)
3787 struct ieee_handle *info;
3788 struct ieee_buf **ppbuf;
3790 struct ieee_buf *buf;
3794 for (buf = *ppbuf; buf->next != NULL; buf = buf->next)
3799 buf = (struct ieee_buf *) xmalloc (sizeof *buf);
3805 info->current = buf;
3809 /* Write a byte into the buffer. We use a macro for speed and a
3810 function for the complex cases. */
3812 #define ieee_write_byte(info, b) \
3813 ((info)->current->c < IEEE_BUFSIZE \
3814 ? ((info)->current->buf[(info)->current->c++] = (b), true) \
3815 : ieee_real_write_byte ((info), (b)))
3818 ieee_real_write_byte (info, b)
3819 struct ieee_handle *info;
3822 if (info->current->c >= IEEE_BUFSIZE)
3826 n = (struct ieee_buf *) xmalloc (sizeof *n);
3829 info->current->next = n;
3833 info->current->buf[info->current->c] = b;
3839 /* Write out two bytes. */
3842 ieee_write_2bytes (info, i)
3843 struct ieee_handle *info;
3846 return (ieee_write_byte (info, i >> 8)
3847 && ieee_write_byte (info, i & 0xff));
3850 /* Write out an integer. */
3853 ieee_write_number (info, v)
3854 struct ieee_handle *info;
3862 if (v <= (bfd_vma) ieee_number_end_enum)
3863 return ieee_write_byte (info, (int) v);
3874 if (c > (unsigned int) (ieee_number_repeat_end_enum
3875 - ieee_number_repeat_start_enum))
3877 fprintf (stderr, "IEEE numeric overflow: 0x");
3878 fprintf_vma (stderr, v);
3879 fprintf (stderr, "\n");
3883 if (! ieee_write_byte (info, (int) ieee_number_repeat_start_enum + c))
3885 for (; c > 0; --c, ++p)
3887 if (! ieee_write_byte (info, *p))
3894 /* Write out a string. */
3897 ieee_write_id (info, s)
3898 struct ieee_handle *info;
3906 if (! ieee_write_byte (info, len))
3909 else if (len <= 0xff)
3911 if (! ieee_write_byte (info, (int) ieee_extension_length_1_enum)
3912 || ! ieee_write_byte (info, len))
3915 else if (len <= 0xffff)
3917 if (! ieee_write_byte (info, (int) ieee_extension_length_2_enum)
3918 || ! ieee_write_2bytes (info, len))
3923 fprintf (stderr, "IEEE string length overflow: %u\n", len);
3927 for (; *s != '\0'; s++)
3928 if (! ieee_write_byte (info, *s))
3934 /* Write out an ASN record. */
3937 ieee_write_asn (info, indx, val)
3938 struct ieee_handle *info;
3942 return (ieee_write_2bytes (info, (int) ieee_asn_record_enum)
3943 && ieee_write_number (info, indx)
3944 && ieee_write_number (info, val));
3947 /* Write out an ATN65 record. */
3950 ieee_write_atn65 (info, indx, s)
3951 struct ieee_handle *info;
3955 return (ieee_write_2bytes (info, (int) ieee_atn_record_enum)
3956 && ieee_write_number (info, indx)
3957 && ieee_write_number (info, 0)
3958 && ieee_write_number (info, 65)
3959 && ieee_write_id (info, s));
3962 /* Push a type index onto the type stack. */
3965 ieee_push_type (info, indx, size, unsignedp)
3966 struct ieee_handle *info;
3971 struct ieee_type_stack *ts;
3973 ts = (struct ieee_type_stack *) xmalloc (sizeof *ts);
3974 memset (ts, 0, sizeof *ts);
3976 ts->type.indx = indx;
3977 ts->type.size = size;
3978 ts->type.unsignedp = unsignedp;
3980 ts->next = info->type_stack;
3981 info->type_stack = ts;
3986 /* Pop a type index off the type stack. */
3989 ieee_pop_type (info)
3990 struct ieee_handle *info;
3992 return ieee_pop_type_used (info, true);
3995 /* Pop an unused type index off the type stack. */
3998 ieee_pop_unused_type (info)
3999 struct ieee_handle *info;
4001 (void) ieee_pop_type_used (info, false);
4004 /* Pop a used or unused type index off the type stack. */
4007 ieee_pop_type_used (info, used)
4008 struct ieee_handle *info;
4011 struct ieee_type_stack *ts;
4014 ts = info->type_stack;
4015 assert (ts != NULL);
4017 /* If this is a function type, and we need it, we need to append the
4018 actual definition to the typedef block now. */
4019 if (ts->type.fndef != NULL && used)
4021 struct ieee_buf **pb;
4023 /* Make sure we have started the types block. */
4024 if (info->types == NULL)
4026 if (! ieee_change_buffer (info, &info->types)
4027 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
4028 || ! ieee_write_byte (info, 1)
4029 || ! ieee_write_number (info, 0)
4030 || ! ieee_write_id (info, info->modname))
4034 for (pb = &info->types; *pb != NULL; pb = &(*pb)->next)
4036 *pb = ts->type.fndef;
4039 ret = ts->type.indx;
4040 info->type_stack = ts->next;
4045 /* Add a range of bytes included in the current compilation unit. */
4048 ieee_add_range (info, low, high)
4049 struct ieee_handle *info;
4053 struct ieee_range *r, **pr;
4055 if (low == (bfd_vma) -1 || high == (bfd_vma) -1)
4058 for (r = info->ranges; r != NULL; r = r->next)
4060 if (high >= r->low && low <= r->high)
4062 /* The new range overlaps r. */
4068 while (*pr != NULL && (*pr)->low <= r->high)
4070 struct ieee_range *n;
4072 if ((*pr)->high > r->high)
4073 r->high = (*pr)->high;
4082 r = (struct ieee_range *) xmalloc (sizeof *r);
4083 memset (r, 0, sizeof *r);
4088 /* Store the ranges sorted by address. */
4089 for (pr = &info->ranges; *pr != NULL; pr = &(*pr)->next)
4090 if ((*pr)->next != NULL && (*pr)->next->low > high)
4098 /* Start a new range for which we only have the low address. */
4101 ieee_start_range (info, low)
4102 struct ieee_handle *info;
4105 struct ieee_range *r;
4107 r = (struct ieee_range *) xmalloc (sizeof *r);
4108 memset (r, 0, sizeof *r);
4110 r->next = info->pending_ranges;
4111 info->pending_ranges = r;
4115 /* Finish a range started by ieee_start_range. */
4118 ieee_end_range (info, high)
4119 struct ieee_handle *info;
4122 struct ieee_range *r;
4125 assert (info->pending_ranges != NULL);
4126 r = info->pending_ranges;
4128 info->pending_ranges = r->next;
4130 return ieee_add_range (info, low, high);
4133 /* Start defining a type. */
4136 ieee_define_type (info, size, unsignedp)
4137 struct ieee_handle *info;
4141 return ieee_define_named_type (info, (const char *) NULL, false, 0, size,
4142 unsignedp, (struct ieee_buf **) NULL);
4145 /* Start defining a named type. */
4148 ieee_define_named_type (info, name, tagp, id, size, unsignedp, ppbuf)
4149 struct ieee_handle *info;
4155 struct ieee_buf **ppbuf;
4157 unsigned int type_indx;
4158 unsigned int name_indx;
4160 if (! tagp || id == (unsigned int) -1)
4162 type_indx = info->type_indx;
4167 struct ieee_name_type *nt;
4171 /* We need to create a tag for internal use even if we don't
4172 want one for external use. This will let us refer to an
4173 anonymous struct. */
4178 sprintf (ab, "__anon%u", id);
4182 /* The name is a tag. If we have already defined the tag, we
4183 must use the existing type index. */
4184 for (nt = info->tags; nt != NULL; nt = nt->next)
4185 if (nt->name[0] == tag[0]
4186 && strcmp (nt->name, tag) == 0)
4191 nt = (struct ieee_name_type *) xmalloc (sizeof *nt);
4192 memset (nt, 0, sizeof *nt);
4194 nt->next = info->tags;
4196 nt->type.indx = info->type_indx;
4200 nt->type.size = size;
4201 nt->type.unsignedp = unsignedp;
4202 nt->kind = DEBUG_KIND_ILLEGAL;
4204 type_indx = nt->type.indx;
4207 name_indx = info->name_indx;
4213 /* If we were given a buffer, use it; otherwise, use the general
4214 type information, and make sure that the type block is started. */
4217 if (! ieee_change_buffer (info, ppbuf))
4220 else if (info->types != NULL)
4222 if (! ieee_change_buffer (info, &info->types))
4227 if (! ieee_change_buffer (info, &info->types)
4228 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
4229 || ! ieee_write_byte (info, 1)
4230 || ! ieee_write_number (info, 0)
4231 || ! ieee_write_id (info, info->modname))
4235 /* Push the new type on the type stack, write out an NN record, and
4236 write out the start of a TY record. The caller will then finish
4238 return (ieee_push_type (info, type_indx, size, unsignedp)
4239 && ieee_write_byte (info, (int) ieee_nn_record)
4240 && ieee_write_number (info, name_indx)
4241 && ieee_write_id (info, name)
4242 && ieee_write_byte (info, (int) ieee_ty_record_enum)
4243 && ieee_write_number (info, type_indx)
4244 && ieee_write_byte (info, 0xce)
4245 && ieee_write_number (info, name_indx));
4248 /* The general routine to write out IEEE debugging information. */
4251 write_ieee_debugging_info (abfd, dhandle)
4255 struct ieee_handle info;
4256 struct ieee_buf *tags;
4257 struct ieee_name_type *nt;
4262 memset (&info, 0, sizeof info);
4264 info.type_indx = 256;
4265 info.name_indx = 32;
4267 if (! debug_write (dhandle, &ieee_fns, (PTR) &info))
4270 if (info.filename != NULL)
4272 if (! ieee_finish_compilation_unit (&info))
4276 /* Put any undefined tags in the global typedef information. */
4278 for (nt = info.tags; nt != NULL; nt = nt->next)
4280 unsigned int name_indx;
4283 if (nt->kind == DEBUG_KIND_ILLEGAL)
4287 if (! ieee_change_buffer (&info, &tags)
4288 || ! ieee_write_byte (&info, (int) ieee_bb_record_enum)
4289 || ! ieee_write_byte (&info, 2)
4290 || ! ieee_write_number (&info, 0)
4291 || ! ieee_write_id (&info, ""))
4294 name_indx = info.name_indx;
4296 if (! ieee_write_byte (&info, (int) ieee_nn_record)
4297 || ! ieee_write_number (&info, name_indx)
4298 || ! ieee_write_id (&info, nt->name)
4299 || ! ieee_write_byte (&info, (int) ieee_ty_record_enum)
4300 || ! ieee_write_number (&info, nt->type.indx)
4301 || ! ieee_write_byte (&info, 0xce)
4302 || ! ieee_write_number (&info, name_indx))
4309 case DEBUG_KIND_STRUCT:
4310 case DEBUG_KIND_CLASS:
4313 case DEBUG_KIND_UNION:
4314 case DEBUG_KIND_UNION_CLASS:
4317 case DEBUG_KIND_ENUM:
4321 if (! ieee_write_number (&info, code)
4322 || ! ieee_write_number (&info, 0))
4327 struct ieee_buf **pb;
4329 if (! ieee_write_byte (&info, (int) ieee_be_record_enum))
4332 for (pb = &tags; *pb != NULL; pb = &(*pb)->next)
4338 /* Now all the data is in info.data. Write it out to the BFD. We
4339 normally would need to worry about whether all the other sections
4340 are set up yet, but the IEEE backend will handle this particular
4341 case correctly regardless. */
4342 if (info.data == NULL)
4344 /* There is no debugging information. */
4348 s = bfd_make_section (abfd, ".debug");
4350 err = "bfd_make_section";
4353 if (! bfd_set_section_flags (abfd, s, SEC_DEBUGGING | SEC_HAS_CONTENTS))
4354 err = "bfd_set_section_flags";
4361 for (b = info.data; b != NULL; b = b->next)
4363 if (! bfd_set_section_size (abfd, s, size))
4364 err = "bfd_set_section_size";
4371 for (b = info.data; b != NULL; b = b->next)
4373 if (! bfd_set_section_contents (abfd, s, b->buf, offset, b->c))
4375 err = "bfd_set_section_contents";
4384 fprintf (stderr, "%s: %s: %s\n", bfd_get_filename (abfd), err,
4385 bfd_errmsg (bfd_get_error ()));
4392 /* Start writing out information for a compilation unit. */
4395 ieee_start_compilation_unit (p, filename)
4397 const char *filename;
4399 struct ieee_handle *info = (struct ieee_handle *) p;
4400 const char *modname;
4403 if (info->filename != NULL)
4405 if (! ieee_finish_compilation_unit (info))
4409 info->filename = filename;
4410 modname = strrchr (filename, '/');
4411 if (modname != NULL)
4415 modname = strrchr (filename, '\\');
4416 if (modname != NULL)
4421 c = xstrdup (modname);
4422 s = strrchr (c, '.');
4430 info->linenos = NULL;
4431 info->ranges = NULL;
4436 /* Finish up a compilation unit. */
4439 ieee_finish_compilation_unit (info)
4440 struct ieee_handle *info;
4442 struct ieee_buf **pp;
4443 struct ieee_range *r;
4445 if (info->types != NULL)
4447 if (! ieee_change_buffer (info, &info->types)
4448 || ! ieee_write_byte (info, (int) ieee_be_record_enum))
4452 if (info->cxx != NULL)
4454 /* Append any C++ information to the global function and
4455 variable information. */
4456 if (info->vars != NULL)
4458 if (! ieee_change_buffer (info, &info->vars))
4463 if (! ieee_change_buffer (info, &info->vars)
4464 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
4465 || ! ieee_write_byte (info, 3)
4466 || ! ieee_write_number (info, 0)
4467 || ! ieee_write_id (info, info->modname))
4471 /* We put the pmisc records in a dummy procedure, just as the
4472 MRI compiler does. */
4473 if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
4474 || ! ieee_write_byte (info, 6)
4475 || ! ieee_write_number (info, 0)
4476 || ! ieee_write_id (info, "__XRYCPP")
4477 || ! ieee_write_number (info, 0)
4478 || ! ieee_write_number (info, 0)
4479 || ! ieee_write_number (info, info->highaddr))
4482 for (pp = &info->vars; *pp != NULL; pp = &(*pp)->next)
4486 if (! ieee_change_buffer (info, &info->vars)
4487 || ! ieee_write_byte (info, (int) ieee_be_record_enum)
4488 || ! ieee_write_number (info, info->highaddr))
4492 if (info->vars != NULL)
4494 if (! ieee_change_buffer (info, &info->vars)
4495 || ! ieee_write_byte (info, (int) ieee_be_record_enum))
4499 if (info->linenos != NULL)
4501 if (! ieee_change_buffer (info, &info->linenos)
4502 || ! ieee_write_byte (info, (int) ieee_be_record_enum))
4506 for (pp = &info->data; *pp != NULL; pp = &(*pp)->next)
4509 for (; *pp != NULL; pp = &(*pp)->next)
4512 for (; *pp != NULL; pp = &(*pp)->next)
4514 *pp = info->linenos;
4516 /* Build BB10/BB11 blocks based on the ranges we recorded. */
4517 if (! ieee_change_buffer (info, &info->data))
4520 if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
4521 || ! ieee_write_byte (info, 10)
4522 || ! ieee_write_number (info, 0)
4523 || ! ieee_write_id (info, info->modname)
4524 || ! ieee_write_id (info, "")
4525 || ! ieee_write_number (info, 0)
4526 || ! ieee_write_id (info, "GNU objcopy"))
4529 for (r = info->ranges; r != NULL; r = r->next)
4538 /* Find the section corresponding to this range. */
4539 for (s = info->abfd->sections; s != NULL; s = s->next)
4541 if (bfd_get_section_vma (info->abfd, s) <= low
4542 && high <= (bfd_get_section_vma (info->abfd, s)
4543 + bfd_section_size (info->abfd, s)))
4549 /* Just ignore this range. */
4553 /* Coalesce ranges if it seems reasonable. */
4554 while (r->next != NULL
4555 && high + 64 >= r->next->low
4557 <= (bfd_get_section_vma (info->abfd, s)
4558 + bfd_section_size (info->abfd, s))))
4561 high = r->next->high;
4564 if ((s->flags & SEC_CODE) != 0)
4566 else if ((s->flags & SEC_READONLY) != 0)
4571 if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
4572 || ! ieee_write_byte (info, 11)
4573 || ! ieee_write_number (info, 0)
4574 || ! ieee_write_id (info, "")
4575 || ! ieee_write_number (info, kind)
4576 || ! ieee_write_number (info, s->index)
4577 || ! ieee_write_number (info, low)
4578 || ! ieee_write_byte (info, (int) ieee_be_record_enum)
4579 || ! ieee_write_number (info, high - low))
4583 if (! ieee_write_byte (info, (int) ieee_be_record_enum))
4589 /* Start recording information from a particular source file. This is
4590 used to record which file defined which types, variables, etc. It
4591 is not used for line numbers, since the lineno entry point passes
4592 down the file name anyhow. IEEE debugging information doesn't seem
4593 to store this information anywhere. */
4597 ieee_start_source (p, filename)
4599 const char *filename;
4604 /* Make an empty type. */
4610 struct ieee_handle *info = (struct ieee_handle *) p;
4612 return ieee_push_type (info, 0, 0, false);
4615 /* Make a void type. */
4621 struct ieee_handle *info = (struct ieee_handle *) p;
4623 return ieee_push_type (info, 1, 0, false);
4626 /* Make an integer type. */
4629 ieee_int_type (p, size, unsignedp)
4634 struct ieee_handle *info = (struct ieee_handle *) p;
4640 indx = (int) builtin_signed_char;
4643 indx = (int) builtin_signed_short_int;
4646 indx = (int) builtin_signed_long;
4649 indx = (int) builtin_signed_long_long;
4652 fprintf (stderr, "IEEE unsupported integer type size %u\n", size);
4659 return ieee_push_type (info, indx, size, unsignedp);
4662 /* Make a floating point type. */
4665 ieee_float_type (p, size)
4669 struct ieee_handle *info = (struct ieee_handle *) p;
4675 indx = (int) builtin_float;
4678 indx = (int) builtin_double;
4681 /* FIXME: This size really depends upon the processor. */
4682 indx = (int) builtin_long_double;
4685 indx = (int) builtin_long_long_double;
4688 fprintf (stderr, "IEEE unsupported float type size %u\n", size);
4692 return ieee_push_type (info, indx, size, false);
4695 /* Make a complex type. */
4698 ieee_complex_type (p, size)
4702 struct ieee_handle *info = (struct ieee_handle *) p;
4714 fprintf (stderr, "IEEE unsupported complex type size %u\n", size);
4718 /* FIXME: I don't know what the string is for. */
4719 return (ieee_define_type (info, size, false)
4720 && ieee_write_number (info, code)
4721 && ieee_write_id (info, ""));
4724 /* Make a boolean type. IEEE doesn't support these, so we just make
4725 an integer type instead. */
4728 ieee_bool_type (p, size)
4732 return ieee_int_type (p, size, true);
4735 /* Make an enumeration. */
4738 ieee_enum_type (p, tag, names, vals)
4742 bfd_signed_vma *vals;
4744 struct ieee_handle *info = (struct ieee_handle *) p;
4748 /* If this is a simple enumeration, in which the values start at 0
4749 and always increment by 1, we can use type E. Otherwise we must
4755 for (i = 0; names[i] != NULL; i++)
4765 if (! ieee_define_named_type (info, tag, true, (unsigned int) -1, 0,
4766 true, (struct ieee_buf **) NULL)
4767 || ! ieee_write_number (info, simple ? 'E' : 'N'))
4771 /* FIXME: This is supposed to be the enumeration size, but we
4772 don't store that. */
4773 if (! ieee_write_number (info, 4))
4778 for (i = 0; names[i] != NULL; i++)
4780 if (! ieee_write_id (info, names[i]))
4784 if (! ieee_write_number (info, vals[i]))
4793 /* Make a pointer type. */
4796 ieee_pointer_type (p)
4799 struct ieee_handle *info = (struct ieee_handle *) p;
4802 indx = ieee_pop_type (info);
4804 /* A pointer to a simple builtin type can be obtained by adding 32. */
4806 return ieee_push_type (info, indx + 32, 0, true);
4808 return (ieee_define_type (info, 0, true)
4809 && ieee_write_number (info, 'P')
4810 && ieee_write_number (info, indx));
4813 /* Make a function type. This will be called for a method, but we
4814 don't want to actually add it to the type table in that case. We
4815 handle this by defining the type in a private buffer, and only
4816 adding that buffer to the typedef block if we are going to use it. */
4819 ieee_function_type (p, argcount, varargs)
4824 struct ieee_handle *info = (struct ieee_handle *) p;
4825 unsigned int *args = NULL;
4827 unsigned int retindx;
4828 struct ieee_buf *fndef;
4832 args = (unsigned int *) xmalloc (argcount * sizeof *args);
4833 for (i = argcount - 1; i >= 0; i--)
4834 args[i] = ieee_pop_type (info);
4836 else if (argcount < 0)
4839 retindx = ieee_pop_type (info);
4841 /* An attribute of 0x41 means that the frame and push mask are
4844 if (! ieee_define_named_type (info, (const char *) NULL, false, 0, 0,
4846 || ! ieee_write_number (info, 'x')
4847 || ! ieee_write_number (info, 0x41)
4848 || ! ieee_write_number (info, 0)
4849 || ! ieee_write_number (info, 0)
4850 || ! ieee_write_number (info, retindx)
4851 || ! ieee_write_number (info, (bfd_vma) argcount + (varargs ? 1 : 0)))
4855 for (i = 0; i < argcount; i++)
4856 if (! ieee_write_number (info, args[i]))
4862 /* A varargs function is represented by writing out the last
4863 argument as type void *, although this makes little sense. */
4864 if (! ieee_write_number (info, (bfd_vma) builtin_void + 32))
4868 if (! ieee_write_number (info, 0))
4871 /* We wrote the information into fndef, in case we don't need it.
4872 It will be appended to info->types by ieee_pop_type. */
4873 info->type_stack->type.fndef = fndef;
4878 /* Make a reference type. */
4881 ieee_reference_type (p)
4884 struct ieee_handle *info = (struct ieee_handle *) p;
4886 /* IEEE appears to record a normal pointer type, and then use a
4887 pmisc record to indicate that it is really a reference. */
4889 if (! ieee_pointer_type (p))
4891 info->type_stack->type.referencep = true;
4895 /* Make a range type. */
4898 ieee_range_type (p, low, high)
4901 bfd_signed_vma high;
4903 struct ieee_handle *info = (struct ieee_handle *) p;
4907 size = info->type_stack->type.size;
4908 unsignedp = info->type_stack->type.unsignedp;
4909 ieee_pop_unused_type (info);
4910 return (ieee_define_type (info, size, unsignedp)
4911 && ieee_write_number (info, 'R')
4912 && ieee_write_number (info, (bfd_vma) low)
4913 && ieee_write_number (info, (bfd_vma) high)
4914 && ieee_write_number (info, unsignedp ? 0 : 1)
4915 && ieee_write_number (info, size));
4918 /* Make an array type. */
4922 ieee_array_type (p, low, high, stringp)
4925 bfd_signed_vma high;
4928 struct ieee_handle *info = (struct ieee_handle *) p;
4929 unsigned int eleindx;
4931 /* IEEE does not store the range, so we just ignore it. */
4932 ieee_pop_unused_type (info);
4933 eleindx = ieee_pop_type (info);
4935 if (! ieee_define_type (info, 0, false)
4936 || ! ieee_write_number (info, low == 0 ? 'Z' : 'C')
4937 || ! ieee_write_number (info, eleindx))
4941 if (! ieee_write_number (info, low))
4945 return ieee_write_number (info, high);
4948 /* Make a set type. */
4951 ieee_set_type (p, bitstringp)
4955 struct ieee_handle *info = (struct ieee_handle *) p;
4956 unsigned int eleindx;
4958 eleindx = ieee_pop_type (info);
4960 /* FIXME: We don't know the size, so we just use 4. */
4962 return (ieee_define_type (info, 0, true)
4963 && ieee_write_number (info, 's')
4964 && ieee_write_number (info, 4)
4965 && ieee_write_number (info, eleindx));
4968 /* Make an offset type. */
4971 ieee_offset_type (p)
4974 struct ieee_handle *info = (struct ieee_handle *) p;
4975 unsigned int targetindx, baseindx;
4977 targetindx = ieee_pop_type (info);
4978 baseindx = ieee_pop_type (info);
4980 /* FIXME: The MRI C++ compiler does not appear to generate any
4981 useful type information about an offset type. It just records a
4982 pointer to member as an integer. The MRI/HP IEEE spec does
4983 describe a pmisc record which can be used for a pointer to
4984 member. Unfortunately, it does not describe the target type,
4985 which seems pretty important. I'm going to punt this for now. */
4987 return ieee_int_type (p, 4, true);
4990 /* Make a method type. */
4993 ieee_method_type (p, domain, argcount, varargs)
4999 struct ieee_handle *info = (struct ieee_handle *) p;
5001 /* FIXME: The MRI/HP IEEE spec defines a pmisc record to use for a
5002 method, but the definition is incomplete. We just output an 'x'
5006 ieee_pop_unused_type (info);
5008 return ieee_function_type (p, argcount, varargs);
5011 /* Make a const qualified type. */
5017 struct ieee_handle *info = (struct ieee_handle *) p;
5022 size = info->type_stack->type.size;
5023 unsignedp = info->type_stack->type.unsignedp;
5024 indx = ieee_pop_type (info);
5025 return (ieee_define_type (info, size, unsignedp)
5026 && ieee_write_number (info, 'n')
5027 && ieee_write_number (info, 1)
5028 && ieee_write_number (info, indx));
5031 /* Make a volatile qualified type. */
5034 ieee_volatile_type (p)
5037 struct ieee_handle *info = (struct ieee_handle *) p;
5042 size = info->type_stack->type.size;
5043 unsignedp = info->type_stack->type.unsignedp;
5044 indx = ieee_pop_type (info);
5045 return (ieee_define_type (info, size, unsignedp)
5046 && ieee_write_number (info, 'n')
5047 && ieee_write_number (info, 2)
5048 && ieee_write_number (info, indx));
5051 /* Convert an enum debug_visibility into a CXXFLAGS value. */
5054 ieee_vis_to_flags (visibility)
5055 enum debug_visibility visibility;
5061 case DEBUG_VISIBILITY_PUBLIC:
5062 return CXXFLAGS_VISIBILITY_PUBLIC;
5063 case DEBUG_VISIBILITY_PRIVATE:
5064 return CXXFLAGS_VISIBILITY_PRIVATE;
5065 case DEBUG_VISIBILITY_PROTECTED:
5066 return CXXFLAGS_VISIBILITY_PROTECTED;
5071 /* Start defining a struct type. We build it in the strdef field on
5072 the stack, to avoid confusing type definitions required by the
5073 fields with the struct type itself. */
5076 ieee_start_struct_type (p, tag, id, structp, size)
5083 struct ieee_handle *info = (struct ieee_handle *) p;
5084 struct ieee_buf *strdef;
5087 if (! ieee_define_named_type (info, tag, true, id, size, true, &strdef)
5088 || ! ieee_write_number (info, structp ? 'S' : 'U')
5089 || ! ieee_write_number (info, size))
5092 info->type_stack->type.strdef = strdef;
5097 /* Add a field to a struct. */
5100 ieee_struct_field (p, name, bitpos, bitsize, visibility)
5105 enum debug_visibility visibility;
5107 struct ieee_handle *info = (struct ieee_handle *) p;
5114 size = info->type_stack->type.size;
5115 unsignedp = info->type_stack->type.unsignedp;
5116 referencep = info->type_stack->type.referencep;
5117 indx = ieee_pop_type (info);
5119 assert (info->type_stack != NULL && info->type_stack->type.strdef != NULL);
5121 if (info->type_stack->type.classdef != NULL)
5126 /* This is a class. We must add a description of this field to
5127 the class records we are building. */
5129 flags = ieee_vis_to_flags (visibility);
5130 nindx = info->type_stack->type.classdef->indx;
5131 if (! ieee_change_buffer (info,
5132 &info->type_stack->type.classdef->pmiscbuf)
5133 || ! ieee_write_asn (info, nindx, 'd')
5134 || ! ieee_write_asn (info, nindx, flags)
5135 || ! ieee_write_atn65 (info, nindx, name)
5136 || ! ieee_write_atn65 (info, nindx, name))
5138 info->type_stack->type.classdef->pmisccount += 4;
5144 /* We need to output a record recording that this field is
5145 really of reference type. We put this on the refs field
5146 of classdef, so that it can be appended to the C++
5147 records after the class is defined. */
5149 nindx = info->name_indx;
5152 if (! ieee_change_buffer (info,
5153 &info->type_stack->type.classdef->refs)
5154 || ! ieee_write_byte (info, (int) ieee_nn_record)
5155 || ! ieee_write_number (info, nindx)
5156 || ! ieee_write_id (info, "")
5157 || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
5158 || ! ieee_write_number (info, nindx)
5159 || ! ieee_write_number (info, 0)
5160 || ! ieee_write_number (info, 62)
5161 || ! ieee_write_number (info, 80)
5162 || ! ieee_write_number (info, 4)
5163 || ! ieee_write_asn (info, nindx, 'R')
5164 || ! ieee_write_asn (info, nindx, 3)
5165 || ! ieee_write_atn65 (info, nindx,
5166 info->type_stack->type.classdef->name)
5167 || ! ieee_write_atn65 (info, nindx, name))
5172 /* If the bitsize doesn't match the expected size, we need to output
5174 if (size == 0 || bitsize == size * 8)
5175 offset = bitpos / 8;
5178 if (! ieee_define_type (info, 0, unsignedp)
5179 || ! ieee_write_number (info, 'g')
5180 || ! ieee_write_number (info, unsignedp ? 0 : 1)
5181 || ! ieee_write_number (info, indx))
5183 indx = ieee_pop_type (info);
5187 /* Switch to the struct we are building in order to output this
5188 field definition. */
5189 return (ieee_change_buffer (info, &info->type_stack->type.strdef)
5190 && ieee_write_id (info, name)
5191 && ieee_write_number (info, indx)
5192 && ieee_write_number (info, offset));
5195 /* Finish up a struct type. */
5198 ieee_end_struct_type (p)
5201 struct ieee_handle *info = (struct ieee_handle *) p;
5202 struct ieee_buf **pb;
5204 assert (info->type_stack != NULL && info->type_stack->type.strdef != NULL);
5206 /* Make sure we have started the types block. */
5207 if (info->types == NULL)
5209 if (! ieee_change_buffer (info, &info->types)
5210 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
5211 || ! ieee_write_byte (info, 1)
5212 || ! ieee_write_number (info, 0)
5213 || ! ieee_write_id (info, info->modname))
5217 /* Append the struct definition to the types. */
5218 for (pb = &info->types; *pb != NULL; pb = &(*pb)->next)
5220 *pb = info->type_stack->type.strdef;
5221 info->type_stack->type.strdef = NULL;
5223 /* Leave the struct on the type stack. */
5228 /* Start a class type. */
5231 ieee_start_class_type (p, tag, id, structp, size, vptr, ownvptr)
5240 struct ieee_handle *info = (struct ieee_handle *) p;
5242 struct ieee_buf *pmiscbuf;
5244 struct ieee_type_class *classdef;
5245 struct ieee_name_type *nt;
5247 /* A C++ class is output as a C++ struct along with a set of pmisc
5248 records describing the class. */
5250 /* We need to have a name so that we can associate the struct and
5256 t = (char *) xmalloc (20);
5257 sprintf (t, "__anon%u", id);
5261 /* We can't write out the virtual table information until we have
5262 finished the class, because we don't know the virtual table size.
5263 We get the size from the largest voffset we see. */
5265 if (vptr && ! ownvptr)
5267 assert (info->type_stack->type.classdef != NULL);
5268 vclass = info->type_stack->type.classdef->name;
5269 /* We don't call ieee_pop_unused_type, since the class should
5271 (void) ieee_pop_type (info);
5274 if (! ieee_start_struct_type (p, tag, id, structp, size))
5277 indx = info->name_indx;
5280 /* We write out pmisc records into the classdef field. We will
5281 write out the pmisc start after we know the number of records we
5284 if (! ieee_change_buffer (info, &pmiscbuf)
5285 || ! ieee_write_asn (info, indx, 'T')
5286 || ! ieee_write_asn (info, indx, structp ? 'o' : 'u')
5287 || ! ieee_write_atn65 (info, indx, tag))
5290 classdef = (struct ieee_type_class *) xmalloc (sizeof *classdef);
5291 memset (classdef, 0, sizeof *classdef);
5293 classdef->name = tag;
5294 classdef->indx = indx;
5295 classdef->pmiscbuf = pmiscbuf;
5296 classdef->pmisccount = 3;
5297 classdef->vclass = vclass;
5298 classdef->ownvptr = ownvptr;
5300 info->type_stack->type.classdef = classdef;
5302 /* We need to fill in the classdef in the tag as well, so that it
5303 will be set when ieee_tag_type is called. */
5304 for (nt = info->tags; nt != NULL; nt = nt->next)
5305 if (nt->name[0] == tag[0]
5306 && strcmp (nt->name, tag) == 0)
5308 assert (nt != NULL);
5309 nt->type.classdef = classdef;
5314 /* Add a static member to a class. */
5317 ieee_class_static_member (p, name, physname, visibility)
5320 const char *physname;
5321 enum debug_visibility visibility;
5323 struct ieee_handle *info = (struct ieee_handle *) p;
5327 /* We don't care about the type. Hopefully there will be a call to
5328 ieee_variable declaring the physical name and the type, since
5329 that is where an IEEE consumer must get the type. */
5330 ieee_pop_unused_type (info);
5332 assert (info->type_stack != NULL
5333 && info->type_stack->type.classdef != NULL);
5335 flags = ieee_vis_to_flags (visibility);
5336 flags |= CXXFLAGS_STATIC;
5338 nindx = info->type_stack->type.classdef->indx;
5340 if (! ieee_change_buffer (info, &info->type_stack->type.classdef->pmiscbuf)
5341 || ! ieee_write_asn (info, nindx, 'd')
5342 || ! ieee_write_asn (info, nindx, flags)
5343 || ! ieee_write_atn65 (info, nindx, name)
5344 || ! ieee_write_atn65 (info, nindx, physname))
5346 info->type_stack->type.classdef->pmisccount += 4;
5351 /* Add a base class to a class. */
5354 ieee_class_baseclass (p, bitpos, virtual, visibility)
5358 enum debug_visibility visibility;
5360 struct ieee_handle *info = (struct ieee_handle *) p;
5367 assert (info->type_stack != NULL
5368 && info->type_stack->type.classdef != NULL
5369 && info->type_stack->next != NULL
5370 && info->type_stack->next->type.classdef != NULL
5371 && info->type_stack->next->type.strdef != NULL);
5373 bname = info->type_stack->type.classdef->name;
5374 bindx = ieee_pop_type (info);
5376 /* We are currently defining both a struct and a class. We must
5377 write out a field definition in the struct which holds the base
5378 class. The stabs debugging reader will create a field named
5379 _vb$CLASS for a virtual base class, so we just use that. FIXME:
5380 we should not depend upon a detail of stabs debugging. */
5383 fname = (char *) xmalloc (strlen (bname) + sizeof "_vb$");
5384 sprintf (fname, "_vb$%s", bname);
5385 flags = BASEFLAGS_VIRTUAL;
5389 fname = (char *) xmalloc (strlen (bname) + sizeof "_b$");
5390 sprintf (fname, "_b$%s", bname);
5392 if (! ieee_change_buffer (info, &info->type_stack->type.strdef)
5393 || ! ieee_write_id (info, fname)
5394 || ! ieee_write_number (info, bindx)
5395 || ! ieee_write_number (info, bitpos / 8))
5400 if (visibility == DEBUG_VISIBILITY_PRIVATE)
5401 flags |= BASEFLAGS_PRIVATE;
5403 nindx = info->type_stack->type.classdef->indx;
5405 if (! ieee_change_buffer (info, &info->type_stack->type.classdef->pmiscbuf)
5406 || ! ieee_write_asn (info, nindx, 'b')
5407 || ! ieee_write_asn (info, nindx, flags)
5408 || ! ieee_write_atn65 (info, nindx, bname)
5409 || ! ieee_write_asn (info, nindx, 0)
5410 || ! ieee_write_atn65 (info, nindx, fname))
5412 info->type_stack->type.classdef->pmisccount += 5;
5419 /* Start building a method for a class. */
5422 ieee_class_start_method (p, name)
5426 struct ieee_handle *info = (struct ieee_handle *) p;
5428 assert (info->type_stack != NULL
5429 && info->type_stack->type.classdef != NULL
5430 && info->type_stack->type.classdef->method == NULL);
5432 info->type_stack->type.classdef->method = name;
5437 /* Define a new method variant, either static or not. */
5440 ieee_class_method_var (info, physname, visibility, staticp, constp,
5441 volatilep, voffset, context)
5442 struct ieee_handle *info;
5443 const char *physname;
5444 enum debug_visibility visibility;
5455 /* We don't need the type of the method. An IEEE consumer which
5456 wants the type must track down the function by the physical name
5457 and get the type from that. */
5458 ieee_pop_unused_type (info);
5460 /* We don't use the context. FIXME: We probably ought to use it to
5461 adjust the voffset somehow, but I don't really know how. */
5463 ieee_pop_unused_type (info);
5465 assert (info->type_stack != NULL
5466 && info->type_stack->type.classdef != NULL
5467 && info->type_stack->type.classdef->method != NULL);
5469 flags = ieee_vis_to_flags (visibility);
5471 /* FIXME: We never set CXXFLAGS_OVERRIDE, CXXFLAGS_OPERATOR,
5472 CXXFLAGS_CTORDTOR, CXXFLAGS_CTOR, or CXXFLAGS_INLINE. */
5475 flags |= CXXFLAGS_STATIC;
5477 flags |= CXXFLAGS_CONST;
5479 flags |= CXXFLAGS_VOLATILE;
5481 nindx = info->type_stack->type.classdef->indx;
5483 virtual = context || voffset > 0;
5485 if (! ieee_change_buffer (info,
5486 &info->type_stack->type.classdef->pmiscbuf)
5487 || ! ieee_write_asn (info, nindx, virtual ? 'v' : 'm')
5488 || ! ieee_write_asn (info, nindx, flags)
5489 || ! ieee_write_atn65 (info, nindx,
5490 info->type_stack->type.classdef->method)
5491 || ! ieee_write_atn65 (info, nindx, physname))
5496 if (voffset > info->type_stack->type.classdef->voffset)
5497 info->type_stack->type.classdef->voffset = voffset;
5498 /* FIXME: The size of a vtable entry depends upon the
5500 if (! ieee_write_asn (info, nindx, (voffset / 4) + 1))
5502 ++info->type_stack->type.classdef->pmisccount;
5505 if (! ieee_write_asn (info, nindx, 0))
5508 info->type_stack->type.classdef->pmisccount += 5;
5513 /* Define a new method variant. */
5516 ieee_class_method_variant (p, physname, visibility, constp, volatilep,
5519 const char *physname;
5520 enum debug_visibility visibility;
5526 struct ieee_handle *info = (struct ieee_handle *) p;
5528 return ieee_class_method_var (info, physname, visibility, false, constp,
5529 volatilep, voffset, context);
5532 /* Define a new static method variant. */
5535 ieee_class_static_method_variant (p, physname, visibility, constp, volatilep)
5537 const char *physname;
5538 enum debug_visibility visibility;
5542 struct ieee_handle *info = (struct ieee_handle *) p;
5544 return ieee_class_method_var (info, physname, visibility, true, constp,
5545 volatilep, 0, false);
5548 /* Finish up a method. */
5551 ieee_class_end_method (p)
5554 struct ieee_handle *info = (struct ieee_handle *) p;
5556 assert (info->type_stack != NULL
5557 && info->type_stack->type.classdef != NULL
5558 && info->type_stack->type.classdef->method != NULL);
5560 info->type_stack->type.classdef->method = NULL;
5565 /* Finish up a class. */
5568 ieee_end_class_type (p)
5571 struct ieee_handle *info = (struct ieee_handle *) p;
5573 struct ieee_buf **pb;
5575 assert (info->type_stack != NULL
5576 && info->type_stack->type.classdef != NULL);
5578 nindx = info->type_stack->type.classdef->indx;
5580 /* If we have a virtual table, we can write out the information now. */
5581 if (info->type_stack->type.classdef->vclass != NULL
5582 || info->type_stack->type.classdef->ownvptr)
5586 /* FIXME: This calculation is architecture dependent. */
5587 vsize = (info->type_stack->type.classdef->voffset + 4) / 4;
5589 if (! ieee_change_buffer (info,
5590 &info->type_stack->type.classdef->pmiscbuf)
5591 || ! ieee_write_asn (info, nindx, 'z')
5592 || ! ieee_write_atn65 (info, nindx, "")
5593 || ! ieee_write_asn (info, nindx, vsize))
5595 if (info->type_stack->type.classdef->ownvptr)
5597 if (! ieee_write_atn65 (info, nindx, ""))
5602 if (! ieee_write_atn65 (info, nindx,
5603 info->type_stack->type.classdef->vclass))
5606 if (! ieee_write_asn (info, nindx, 0))
5608 info->type_stack->type.classdef->pmisccount += 5;
5611 /* Now that we know the number of pmisc records, we can write out
5612 the atn62 which starts the pmisc records, and append them to the
5615 if (! ieee_change_buffer (info, &info->cxx)
5616 || ! ieee_write_byte (info, (int) ieee_nn_record)
5617 || ! ieee_write_number (info, nindx)
5618 || ! ieee_write_id (info, "")
5619 || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
5620 || ! ieee_write_number (info, nindx)
5621 || ! ieee_write_number (info, 0)
5622 || ! ieee_write_number (info, 62)
5623 || ! ieee_write_number (info, 80)
5624 || ! ieee_write_number (info,
5625 info->type_stack->type.classdef->pmisccount))
5628 for (pb = &info->cxx; *pb != NULL; pb = &(*pb)->next)
5630 *pb = info->type_stack->type.classdef->pmiscbuf;
5631 if (info->type_stack->type.classdef->refs != NULL)
5633 for (; *pb != NULL; pb = &(*pb)->next)
5635 *pb = info->type_stack->type.classdef->refs;
5638 return ieee_end_struct_type (p);
5641 /* Push a previously seen typedef onto the type stack. */
5644 ieee_typedef_type (p, name)
5648 struct ieee_handle *info = (struct ieee_handle *) p;
5649 register struct ieee_name_type *nt;
5651 for (nt = info->typedefs; nt != NULL; nt = nt->next)
5653 if (nt->name[0] == name[0]
5654 && strcmp (nt->name, name) == 0)
5656 if (! ieee_push_type (info, nt->type.indx, nt->type.size,
5657 nt->type.unsignedp))
5659 /* Copy over any other type information we may have. */
5660 info->type_stack->type = nt->type;
5668 /* Push a tagged type onto the type stack. */
5671 ieee_tag_type (p, name, id, kind)
5675 enum debug_type_kind kind;
5677 struct ieee_handle *info = (struct ieee_handle *) p;
5678 register struct ieee_name_type *nt;
5683 sprintf (ab, "__anon%u", id);
5687 for (nt = info->tags; nt != NULL; nt = nt->next)
5689 if (nt->name[0] == name[0]
5690 && strcmp (nt->name, name) == 0)
5692 if (! ieee_push_type (info, nt->type.indx, nt->type.size,
5693 nt->type.unsignedp))
5695 /* Copy over any other type information we may have. */
5696 info->type_stack->type = nt->type;
5701 nt = (struct ieee_name_type *) xmalloc (sizeof *nt);
5702 memset (nt, 0, sizeof *nt);
5705 nt->type.indx = info->type_indx;
5709 nt->next = info->tags;
5712 return ieee_push_type (info, nt->type.indx, 0, false);
5715 /* Output a typedef. */
5718 ieee_typdef (p, name)
5722 struct ieee_handle *info = (struct ieee_handle *) p;
5723 struct ieee_name_type *nt;
5728 nt = (struct ieee_name_type *) xmalloc (sizeof *nt);
5729 memset (nt, 0, sizeof *nt);
5731 nt->type = info->type_stack->type;
5732 nt->kind = DEBUG_KIND_ILLEGAL;
5734 nt->next = info->typedefs;
5735 info->typedefs = nt;
5737 size = info->type_stack->type.size;
5738 unsignedp = info->type_stack->type.unsignedp;
5739 indx = ieee_pop_type (info);
5741 /* If this is a simple builtin type using a builtin name, we don't
5742 want to output the typedef itself. We also want to change the
5743 type index to correspond to the name being used. We recognize
5744 names used in stabs debugging output even if they don't exactly
5745 correspond to the names used for the IEEE builtin types. */
5746 if (indx <= (unsigned int) builtin_bcd_float)
5751 switch ((enum builtin_types) indx)
5757 if (strcmp (name, "void") == 0)
5761 case builtin_signed_char:
5763 if (strcmp (name, "signed char") == 0)
5765 indx = (unsigned int) builtin_signed_char;
5768 else if (strcmp (name, "char") == 0)
5770 indx = (unsigned int) builtin_char;
5775 case builtin_unsigned_char:
5776 if (strcmp (name, "unsigned char") == 0)
5780 case builtin_signed_short_int:
5782 case builtin_short_int:
5783 case builtin_signed_short:
5784 if (strcmp (name, "signed short int") == 0)
5786 indx = (unsigned int) builtin_signed_short_int;
5789 else if (strcmp (name, "short") == 0)
5791 indx = (unsigned int) builtin_short;
5794 else if (strcmp (name, "short int") == 0)
5796 indx = (unsigned int) builtin_short_int;
5799 else if (strcmp (name, "signed short") == 0)
5801 indx = (unsigned int) builtin_signed_short;
5806 case builtin_unsigned_short_int:
5807 case builtin_unsigned_short:
5808 if (strcmp (name, "unsigned short int") == 0
5809 || strcmp (name, "short unsigned int") == 0)
5811 indx = builtin_unsigned_short_int;
5814 else if (strcmp (name, "unsigned short") == 0)
5816 indx = builtin_unsigned_short;
5821 case builtin_signed_long:
5822 case builtin_int: /* FIXME: Size depends upon architecture. */
5824 if (strcmp (name, "signed long") == 0)
5826 indx = builtin_signed_long;
5829 else if (strcmp (name, "int") == 0)
5834 else if (strcmp (name, "long") == 0
5835 || strcmp (name, "long int") == 0)
5837 indx = builtin_long;
5842 case builtin_unsigned_long:
5843 case builtin_unsigned: /* FIXME: Size depends upon architecture. */
5844 case builtin_unsigned_int: /* FIXME: Like builtin_unsigned. */
5845 if (strcmp (name, "unsigned long") == 0
5846 || strcmp (name, "long unsigned int") == 0)
5848 indx = builtin_unsigned_long;
5851 else if (strcmp (name, "unsigned") == 0)
5853 indx = builtin_unsigned;
5856 else if (strcmp (name, "unsigned int") == 0)
5858 indx = builtin_unsigned_int;
5863 case builtin_signed_long_long:
5864 if (strcmp (name, "signed long long") == 0
5865 || strcmp (name, "long long int") == 0)
5869 case builtin_unsigned_long_long:
5870 if (strcmp (name, "unsigned long long") == 0
5871 || strcmp (name, "long long unsigned int") == 0)
5876 if (strcmp (name, "float") == 0)
5880 case builtin_double:
5881 if (strcmp (name, "double") == 0)
5885 case builtin_long_double:
5886 if (strcmp (name, "long double") == 0)
5890 case builtin_long_long_double:
5891 if (strcmp (name, "long long double") == 0)
5898 nt->type.indx = indx;
5903 if (! ieee_define_named_type (info, name, false, 0, size, unsignedp,
5904 (struct ieee_buf **) NULL)
5905 || ! ieee_write_number (info, 'T')
5906 || ! ieee_write_number (info, indx))
5909 /* Remove the type we just added to the type stack. This should not
5910 be ieee_pop_unused_type, since the type is used, we just don't
5912 (void) ieee_pop_type (info);
5917 /* Output a tag for a type. We don't have to do anything here. */
5924 struct ieee_handle *info = (struct ieee_handle *) p;
5926 /* This should not be ieee_pop_unused_type, since we want the type
5928 (void) ieee_pop_type (info);
5932 /* Output an integer constant. */
5935 ieee_int_constant (p, name, val)
5944 /* Output a floating point constant. */
5947 ieee_float_constant (p, name, val)
5956 /* Output a typed constant. */
5959 ieee_typed_constant (p, name, val)
5964 struct ieee_handle *info = (struct ieee_handle *) p;
5967 ieee_pop_unused_type (info);
5971 /* Output a variable. */
5974 ieee_variable (p, name, kind, val)
5977 enum debug_var_kind kind;
5980 struct ieee_handle *info = (struct ieee_handle *) p;
5981 unsigned int name_indx;
5984 unsigned int type_indx;
5988 size = info->type_stack->type.size;
5989 referencep = info->type_stack->type.referencep;
5990 type_indx = ieee_pop_type (info);
5992 /* Make sure the variable section is started. */
5993 if (info->vars != NULL)
5995 if (! ieee_change_buffer (info, &info->vars))
6000 if (! ieee_change_buffer (info, &info->vars)
6001 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
6002 || ! ieee_write_byte (info, 3)
6003 || ! ieee_write_number (info, 0)
6004 || ! ieee_write_id (info, info->modname))
6008 name_indx = info->name_indx;
6011 /* Write out an NN and an ATN record for this variable. */
6012 if (! ieee_write_byte (info, (int) ieee_nn_record)
6013 || ! ieee_write_number (info, name_indx)
6014 || ! ieee_write_id (info, name)
6015 || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
6016 || ! ieee_write_number (info, name_indx)
6017 || ! ieee_write_number (info, type_indx))
6025 if (! ieee_write_number (info, 8)
6026 || ! ieee_add_range (info, val, val + size))
6032 if (! ieee_write_number (info, 3)
6033 || ! ieee_add_range (info, val, val + size))
6038 case DEBUG_LOCAL_STATIC:
6039 if (! ieee_write_number (info, 3)
6040 || ! ieee_add_range (info, val, val + size))
6046 if (! ieee_write_number (info, 1)
6047 || ! ieee_write_number (info, val))
6052 case DEBUG_REGISTER:
6053 if (! ieee_write_number (info, 2)
6054 || ! ieee_write_number (info,
6055 ieee_genreg_to_regno (info->abfd, val)))
6064 if (! ieee_write_asn (info, name_indx, val))
6068 /* If this is really a reference type, then we just output it with
6069 pointer type, and must now output a C++ record indicating that it
6070 is really reference type. */
6075 nindx = info->name_indx;
6078 /* If this is a global variable, we want to output the misc
6079 record in the C++ misc record block. Otherwise, we want to
6080 output it just after the variable definition, which is where
6081 the current buffer is. */
6084 if (! ieee_change_buffer (info, &info->cxx))
6088 if (! ieee_write_byte (info, (int) ieee_nn_record)
6089 || ! ieee_write_number (info, nindx)
6090 || ! ieee_write_id (info, "")
6091 || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
6092 || ! ieee_write_number (info, nindx)
6093 || ! ieee_write_number (info, 0)
6094 || ! ieee_write_number (info, 62)
6095 || ! ieee_write_number (info, 80)
6096 || ! ieee_write_number (info, 3)
6097 || ! ieee_write_asn (info, nindx, 'R')
6098 || ! ieee_write_asn (info, nindx, refflag)
6099 || ! ieee_write_atn65 (info, nindx, name))
6106 /* Start outputting information for a function. */
6109 ieee_start_function (p, name, global)
6114 struct ieee_handle *info = (struct ieee_handle *) p;
6116 unsigned int retindx, typeindx;
6118 referencep = info->type_stack->type.referencep;
6119 retindx = ieee_pop_type (info);
6121 /* Besides recording a BB4 or BB6 block, we record the type of the
6122 function in the BB1 typedef block. We can't write out the full
6123 type until we have seen all the parameters, so we accumulate it
6124 in info->fntype and info->fnargs. */
6125 if (info->fntype != NULL)
6127 /* FIXME: This might happen someday if we support nested
6132 info->fnname = name;
6134 /* An attribute of 0x41 means that the frame and push mask are
6136 if (! ieee_define_named_type (info, name, false, 0, 0, false, &info->fntype)
6137 || ! ieee_write_number (info, 'x')
6138 || ! ieee_write_number (info, 0x41)
6139 || ! ieee_write_number (info, 0)
6140 || ! ieee_write_number (info, 0)
6141 || ! ieee_write_number (info, retindx))
6144 typeindx = ieee_pop_type (info);
6146 info->fnargs = NULL;
6147 info->fnargcount = 0;
6149 /* If the function return value is actually a reference type, we
6150 must add a record indicating that. */
6155 nindx = info->name_indx;
6157 if (! ieee_change_buffer (info, &info->cxx)
6158 || ! ieee_write_byte (info, (int) ieee_nn_record)
6159 || ! ieee_write_number (info, nindx)
6160 || ! ieee_write_id (info, "")
6161 || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
6162 || ! ieee_write_number (info, nindx)
6163 || ! ieee_write_number (info, 0)
6164 || ! ieee_write_number (info, 62)
6165 || ! ieee_write_number (info, 80)
6166 || ! ieee_write_number (info, 3)
6167 || ! ieee_write_asn (info, nindx, 'R')
6168 || ! ieee_write_asn (info, nindx, global ? 0 : 1)
6169 || ! ieee_write_atn65 (info, nindx, name))
6173 /* Make sure the variable section is started. */
6174 if (info->vars != NULL)
6176 if (! ieee_change_buffer (info, &info->vars))
6181 if (! ieee_change_buffer (info, &info->vars)
6182 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
6183 || ! ieee_write_byte (info, 3)
6184 || ! ieee_write_number (info, 0)
6185 || ! ieee_write_id (info, info->modname))
6189 /* The address is written out as the first block. */
6191 ++info->block_depth;
6193 return (ieee_write_byte (info, (int) ieee_bb_record_enum)
6194 && ieee_write_byte (info, global ? 4 : 6)
6195 && ieee_write_number (info, 0)
6196 && ieee_write_id (info, name)
6197 && ieee_write_number (info, 0)
6198 && ieee_write_number (info, typeindx));
6201 /* Add a function parameter. This will normally be called before the
6202 first block, so we postpone them until we see the block. */
6205 ieee_function_parameter (p, name, kind, val)
6208 enum debug_parm_kind kind;
6211 struct ieee_handle *info = (struct ieee_handle *) p;
6212 struct ieee_pending_parm *m, **pm;
6214 assert (info->block_depth == 1);
6216 m = (struct ieee_pending_parm *) xmalloc (sizeof *m);
6217 memset (m, 0, sizeof *m);
6221 m->referencep = info->type_stack->type.referencep;
6222 m->type = ieee_pop_type (info);
6226 for (pm = &info->pending_parms; *pm != NULL; pm = &(*pm)->next)
6230 /* Add the type to the fnargs list. */
6231 if (! ieee_change_buffer (info, &info->fnargs)
6232 || ! ieee_write_number (info, m->type))
6239 /* Output pending function parameters. */
6242 ieee_output_pending_parms (info)
6243 struct ieee_handle *info;
6245 struct ieee_pending_parm *m;
6246 unsigned int refcount;
6249 for (m = info->pending_parms; m != NULL; m = m->next)
6251 enum debug_var_kind vkind;
6258 case DEBUG_PARM_STACK:
6259 case DEBUG_PARM_REFERENCE:
6260 vkind = DEBUG_LOCAL;
6262 case DEBUG_PARM_REG:
6263 case DEBUG_PARM_REF_REG:
6264 vkind = DEBUG_REGISTER;
6268 if (! ieee_push_type (info, m->type, 0, false))
6270 info->type_stack->type.referencep = m->referencep;
6273 if (! ieee_variable ((PTR) info, m->name, vkind, m->val))
6277 /* If there are any reference parameters, we need to output a
6278 miscellaneous record indicating them. */
6281 unsigned int nindx, varindx;
6283 /* FIXME: The MRI compiler outputs the demangled function name
6284 here, but we are outputting the mangled name. */
6285 nindx = info->name_indx;
6287 if (! ieee_change_buffer (info, &info->vars)
6288 || ! ieee_write_byte (info, (int) ieee_nn_record)
6289 || ! ieee_write_number (info, nindx)
6290 || ! ieee_write_id (info, "")
6291 || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
6292 || ! ieee_write_number (info, nindx)
6293 || ! ieee_write_number (info, 0)
6294 || ! ieee_write_number (info, 62)
6295 || ! ieee_write_number (info, 80)
6296 || ! ieee_write_number (info, refcount + 3)
6297 || ! ieee_write_asn (info, nindx, 'B')
6298 || ! ieee_write_atn65 (info, nindx, info->fnname)
6299 || ! ieee_write_asn (info, nindx, 0))
6301 for (m = info->pending_parms, varindx = 1;
6303 m = m->next, varindx++)
6307 if (! ieee_write_asn (info, nindx, varindx))
6313 m = info->pending_parms;
6316 struct ieee_pending_parm *next;
6323 info->pending_parms = NULL;
6328 /* Start a block. If this is the first block, we output the address
6329 to finish the BB4 or BB6, and then output the function parameters. */
6332 ieee_start_block (p, addr)
6336 struct ieee_handle *info = (struct ieee_handle *) p;
6338 if (! ieee_change_buffer (info, &info->vars))
6341 if (info->block_depth == 1)
6343 if (! ieee_write_number (info, addr)
6344 || ! ieee_output_pending_parms (info))
6349 if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
6350 || ! ieee_write_byte (info, 6)
6351 || ! ieee_write_number (info, 0)
6352 || ! ieee_write_id (info, "")
6353 || ! ieee_write_number (info, 0)
6354 || ! ieee_write_number (info, 0)
6355 || ! ieee_write_number (info, addr))
6359 if (! ieee_start_range (info, addr))
6362 ++info->block_depth;
6370 ieee_end_block (p, addr)
6374 struct ieee_handle *info = (struct ieee_handle *) p;
6376 if (! ieee_change_buffer (info, &info->vars)
6377 || ! ieee_write_byte (info, (int) ieee_be_record_enum)
6378 || ! ieee_write_number (info, addr))
6381 if (! ieee_end_range (info, addr))
6384 --info->block_depth;
6386 if (addr > info->highaddr)
6387 info->highaddr = addr;
6392 /* End a function. */
6395 ieee_end_function (p)
6398 struct ieee_handle *info = (struct ieee_handle *) p;
6399 struct ieee_buf **pb;
6401 assert (info->block_depth == 1);
6403 --info->block_depth;
6405 /* Now we can finish up fntype, and add it to the typdef section.
6406 At this point, fntype is the 'x' type up to the argument count,
6407 and fnargs is the argument types. We must add the argument
6408 count, and we must add the level. FIXME: We don't record varargs
6409 functions correctly. In fact, stabs debugging does not give us
6410 enough information to do so. */
6411 if (! ieee_change_buffer (info, &info->fntype)
6412 || ! ieee_write_number (info, info->fnargcount)
6413 || ! ieee_change_buffer (info, &info->fnargs)
6414 || ! ieee_write_number (info, 0))
6417 /* Make sure the typdef block has been started. */
6418 if (info->types == NULL)
6420 if (! ieee_change_buffer (info, &info->types)
6421 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
6422 || ! ieee_write_byte (info, 1)
6423 || ! ieee_write_number (info, 0)
6424 || ! ieee_write_id (info, info->modname))
6428 for (pb = &info->types; *pb != NULL; pb = &(*pb)->next)
6431 for (; *pb != NULL; pb = &(*pb)->next)
6435 info->fnname = NULL;
6436 info->fntype = NULL;
6437 info->fnargs = NULL;
6438 info->fnargcount = 0;
6443 /* Record line number information. */
6446 ieee_lineno (p, filename, lineno, addr)
6448 const char *filename;
6449 unsigned long lineno;
6452 struct ieee_handle *info = (struct ieee_handle *) p;
6454 assert (info->filename != NULL);
6456 /* Make sure we have a line number block. */
6457 if (info->linenos != NULL)
6459 if (! ieee_change_buffer (info, &info->linenos))
6464 info->lineno_name_indx = info->name_indx;
6466 if (! ieee_change_buffer (info, &info->linenos)
6467 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
6468 || ! ieee_write_byte (info, 5)
6469 || ! ieee_write_number (info, 0)
6470 || ! ieee_write_id (info, info->filename)
6471 || ! ieee_write_byte (info, (int) ieee_nn_record)
6472 || ! ieee_write_number (info, info->lineno_name_indx)
6473 || ! ieee_write_id (info, ""))
6475 info->lineno_filename = info->filename;
6478 if (strcmp (filename, info->lineno_filename) != 0)
6480 if (strcmp (info->filename, info->lineno_filename) != 0)
6482 /* We were not in the main file. Close the block for the
6484 if (! ieee_write_byte (info, (int) ieee_be_record_enum))
6487 if (strcmp (info->filename, filename) != 0)
6489 /* We are not changing to the main file. Open a block for
6490 the new included file. */
6491 if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
6492 || ! ieee_write_byte (info, 5)
6493 || ! ieee_write_number (info, 0)
6494 || ! ieee_write_id (info, filename))
6497 info->lineno_filename = filename;
6500 return (ieee_write_2bytes (info, (int) ieee_atn_record_enum)
6501 && ieee_write_number (info, info->lineno_name_indx)
6502 && ieee_write_number (info, 0)
6503 && ieee_write_number (info, 7)
6504 && ieee_write_number (info, lineno)
6505 && ieee_write_number (info, 0)
6506 && ieee_write_asn (info, info->lineno_name_indx, addr));