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. */
1838 struct ieee_var *pv;
1839 bfd_vma attr, frame_type, push_mask, nargs, level, father;
1841 debug_type *arg_types;
1845 /* FIXME: We ignore some of this information. */
1847 pv = info->vars.vars + varindx;
1849 if (! ieee_read_number (info, pp, &attr)
1850 || ! ieee_read_number (info, pp, &frame_type)
1851 || ! ieee_read_number (info, pp, &push_mask)
1852 || ! ieee_read_type_index (info, pp, &rtype)
1853 || ! ieee_read_number (info, pp, &nargs))
1855 if (nargs == (bfd_vma) -1)
1864 arg_types = ((debug_type *)
1865 xmalloc ((nargs + 1) * sizeof *arg_types));
1866 for (i = 0; i < nargs; i++)
1867 if (! ieee_read_type_index (info, pp, arg_types + i))
1870 /* If the last type is pointer to void, this is really a
1871 varargs function. */
1877 last = arg_types[nargs - 1];
1878 if (debug_get_type_kind (dhandle, last) == DEBUG_KIND_POINTER
1879 && (debug_get_type_kind (dhandle,
1880 debug_get_target_type (dhandle,
1882 == DEBUG_KIND_VOID))
1889 /* If there are any pointer arguments, turn them into
1890 indirect types in case we later need to convert them to
1892 for (i = 0; i < nargs; i++)
1894 if (debug_get_type_kind (dhandle, arg_types[i])
1895 == DEBUG_KIND_POINTER)
1897 if (arg_slots == NULL)
1899 arg_slots = ((debug_type *)
1900 xmalloc (nargs * sizeof *arg_slots));
1901 memset (arg_slots, 0, nargs * sizeof *arg_slots);
1903 arg_slots[i] = arg_types[i];
1905 debug_make_indirect_type (dhandle,
1907 (const char *) NULL);
1911 arg_types[nargs] = DEBUG_TYPE_NULL;
1913 if (! ieee_read_number (info, pp, &level)
1914 || ! ieee_read_optional_number (info, pp, &father, &present))
1917 /* We can't distinguish between a global function and a static
1919 pv->kind = IEEE_FUNCTION;
1922 && debug_get_type_kind (dhandle, rtype) == DEBUG_KIND_POINTER)
1924 /* Set up the return type as an indirect type pointing to
1925 the variable slot, so that we can change it to a
1926 reference later if appropriate. */
1927 pv->pslot = (debug_type *) xmalloc (sizeof *pv->pslot);
1929 rtype = debug_make_indirect_type (dhandle, pv->pslot,
1930 (const char *) NULL);
1933 type = debug_make_function_type (dhandle, rtype, arg_types, varargs);
1938 /* Record the type in the table. If the corresponding NN record has
1939 a name, name it. FIXME: Is this always correct? */
1941 if (type == DEBUG_TYPE_NULL)
1944 info->vars.vars[varindx].type = type;
1947 && info->vars.vars[varindx].namlen > 0)
1951 name = savestring (info->vars.vars[varindx].name,
1952 info->vars.vars[varindx].namlen);
1954 type = debug_name_type (dhandle, name, type);
1955 else if (tc == 'E' || tc == 'N')
1956 type = debug_tag_type (dhandle, name, type);
1959 struct ieee_tag *it;
1961 /* We must allocate all struct tags as indirect types, so
1962 that if we later see a definition of the tag as a C++
1963 record we can update the indirect slot and automatically
1964 change all the existing references. */
1965 it = (struct ieee_tag *) xmalloc (sizeof *it);
1966 memset (it, 0, sizeof *it);
1967 it->next = info->tags;
1972 type = debug_make_indirect_type (dhandle, &it->slot, name);
1973 type = debug_tag_type (dhandle, name, type);
1981 info->types.types[typeindx].type = type;
1982 info->types.types[typeindx].arg_slots = arg_slots;
1983 info->types.types[typeindx].bitsize = type_bitsize;
1985 /* We may have already allocated type as an indirect type pointing
1986 to slot. It does no harm to replace the indirect type with the
1987 real type. Filling in slot as well handles the indirect types
1988 which are already hanging around. */
1989 if (info->types.types[typeindx].pslot != NULL)
1990 *info->types.types[typeindx].pslot = type;
1995 /* Parse an ATN record. */
1998 parse_ieee_atn (info, pp)
1999 struct ieee_info *info;
2000 const bfd_byte **pp;
2002 const bfd_byte *atn_start, *atn_code_start;
2004 struct ieee_var *pvar;
2008 bfd_vma v, v2, v3, v4, v5;
2010 unsigned long namlen;
2017 if (! ieee_read_number (info, pp, &varindx)
2018 || ! ieee_read_type_index (info, pp, &type))
2021 atn_code_start = *pp;
2023 if (! ieee_read_number (info, pp, &atn_code))
2032 else if (varindx < 32)
2034 ieee_error (info, atn_start, "illegal variable index");
2040 if (varindx >= info->vars.alloc
2041 || info->vars.vars[varindx].name == NULL)
2043 ieee_error (info, atn_start, "undefined variable in ATN");
2047 pvar = info->vars.vars + varindx;
2052 namlen = pvar->namlen;
2055 dhandle = info->dhandle;
2057 /* If we are going to call debug_record_variable with a pointer
2058 type, change the type to an indirect type so that we can later
2059 change it to a reference type if we encounter a C++ pmisc 'R'
2062 && type != DEBUG_TYPE_NULL
2063 && debug_get_type_kind (dhandle, type) == DEBUG_KIND_POINTER)
2073 pvar->pslot = (debug_type *) xmalloc (sizeof *pvar->pslot);
2074 *pvar->pslot = type;
2075 type = debug_make_indirect_type (dhandle, pvar->pslot,
2076 (const char *) NULL);
2085 ieee_error (info, atn_code_start, "unknown ATN type");
2089 /* Automatic variable. */
2090 if (! ieee_read_number (info, pp, &v))
2092 namcopy = savestring (name, namlen);
2094 type = debug_make_void_type (dhandle);
2096 pvar->kind = IEEE_LOCAL;
2097 return debug_record_variable (dhandle, namcopy, type, DEBUG_LOCAL, v);
2100 /* Register variable. */
2101 if (! ieee_read_number (info, pp, &v))
2103 namcopy = savestring (name, namlen);
2105 type = debug_make_void_type (dhandle);
2107 pvar->kind = IEEE_LOCAL;
2108 return debug_record_variable (dhandle, namcopy, type, DEBUG_REGISTER,
2109 ieee_regno_to_genreg (info->abfd, v));
2112 /* Static variable. */
2113 if (! ieee_require_asn (info, pp, &v))
2115 namcopy = savestring (name, namlen);
2117 type = debug_make_void_type (dhandle);
2118 if (info->blockstack.bsp <= info->blockstack.stack)
2121 blocktype = info->blockstack.bsp[-1].kind;
2124 if (blocktype == 4 || blocktype == 6)
2125 pvar->kind = IEEE_LOCAL;
2127 pvar->kind = IEEE_STATIC;
2129 return debug_record_variable (dhandle, namcopy, type,
2130 (blocktype == 4 || blocktype == 6
2131 ? DEBUG_LOCAL_STATIC
2136 /* External function. We don't currently record these. FIXME. */
2138 pvar->kind = IEEE_EXTERNAL;
2142 /* External variable. We don't currently record these. FIXME. */
2144 pvar->kind = IEEE_EXTERNAL;
2148 if (! ieee_read_number (info, pp, &v)
2149 || ! ieee_read_number (info, pp, &v2)
2150 || ! ieee_read_optional_number (info, pp, &v3, &present))
2154 if (! ieee_read_optional_number (info, pp, &v4, &present))
2158 /* We just ignore the two optional fields in v3 and v4, since
2159 they are not defined. */
2161 if (! ieee_require_asn (info, pp, &v3))
2164 /* We have no way to record the column number. FIXME. */
2166 return debug_record_line (dhandle, v, v3);
2169 /* Global variable. */
2170 if (! ieee_require_asn (info, pp, &v))
2172 namcopy = savestring (name, namlen);
2174 type = debug_make_void_type (dhandle);
2176 pvar->kind = IEEE_GLOBAL;
2177 return debug_record_variable (dhandle, namcopy, type, DEBUG_GLOBAL, v);
2180 /* Variable lifetime information. */
2181 if (! ieee_read_number (info, pp, &v))
2184 /* We have no way to record this information. FIXME. */
2188 /* Locked register. */
2189 if (! ieee_read_number (info, pp, &v)
2190 || ! ieee_read_number (info, pp, &v2))
2193 /* I think this means a variable that is both in a register and
2194 a frame slot. We ignore the frame slot. FIXME. */
2196 namcopy = savestring (name, namlen);
2198 type = debug_make_void_type (dhandle);
2200 pvar->kind = IEEE_LOCAL;
2201 return debug_record_variable (dhandle, namcopy, type, DEBUG_REGISTER, v);
2204 /* Reserved for FORTRAN common. */
2205 ieee_error (info, atn_code_start, "unsupported ATN11");
2207 /* Return true to keep going. */
2211 /* Based variable. */
2215 if (! ieee_read_number (info, pp, &v)
2216 || ! ieee_read_number (info, pp, &v2)
2217 || ! ieee_read_optional_number (info, pp, &v3, &present))
2221 if (! ieee_read_optional_number (info, pp, &v4, &present))
2225 if (! ieee_read_optional_number (info, pp, &v5, &present))
2230 /* We have no way to record this information. FIXME. */
2232 ieee_error (info, atn_code_start, "unsupported ATN12");
2234 /* Return true to keep going. */
2238 /* Constant. The description of this that I have is ambiguous,
2239 so I'm not going to try to implement it. */
2240 if (! ieee_read_number (info, pp, &v)
2241 || ! ieee_read_optional_number (info, pp, &v2, &present))
2245 if (! ieee_read_optional_number (info, pp, &v2, &present))
2249 if (! ieee_read_optional_id (info, pp, &name, &namlen, &present))
2254 if ((ieee_record_enum_type) **pp == ieee_e2_first_byte_enum)
2256 if (! ieee_require_asn (info, pp, &v3))
2263 /* Static variable from assembler. */
2265 if (! ieee_read_number (info, pp, &v)
2266 || ! ieee_read_optional_number (info, pp, &v2, &present)
2267 || ! ieee_require_asn (info, pp, &v3))
2269 namcopy = savestring (name, namlen);
2270 /* We don't really handle this correctly. FIXME. */
2271 return debug_record_variable (dhandle, namcopy,
2272 debug_make_void_type (dhandle),
2273 v2 != 0 ? DEBUG_GLOBAL : DEBUG_STATIC,
2277 /* Procedure miscellaneous information. */
2279 /* Variable miscellaneous information. */
2281 /* Module miscellaneous information. */
2282 if (! ieee_read_number (info, pp, &v)
2283 || ! ieee_read_number (info, pp, &v2)
2284 || ! ieee_read_optional_id (info, pp, &name, &namlen, &present))
2287 if (atn_code == 62 && v == 80)
2291 ieee_error (info, atn_code_start,
2292 "unexpected string in C++ misc");
2295 return ieee_read_cxx_misc (info, pp, v2);
2298 /* We just ignore all of this stuff. FIXME. */
2300 for (; v2 > 0; --v2)
2302 switch ((ieee_record_enum_type) **pp)
2305 ieee_error (info, *pp, "bad misc record");
2308 case ieee_at_record_enum:
2309 if (! ieee_require_atn65 (info, pp, &name, &namlen))
2313 case ieee_e2_first_byte_enum:
2314 if (! ieee_require_asn (info, pp, &v3))
2326 /* Handle C++ debugging miscellaneous records. This is called for
2327 procedure miscellaneous records of type 80. */
2330 ieee_read_cxx_misc (info, pp, count)
2331 struct ieee_info *info;
2332 const bfd_byte **pp;
2333 unsigned long count;
2335 const bfd_byte *start;
2340 /* Get the category of C++ misc record. */
2341 if (! ieee_require_asn (info, pp, &category))
2348 ieee_error (info, start, "unrecognized C++ misc record");
2352 if (! ieee_read_cxx_class (info, pp, count))
2360 unsigned long namlen;
2362 /* The IEEE spec indicates that the 'M' record only has a
2363 flags field. The MRI compiler also emits the name of the
2366 if (! ieee_require_asn (info, pp, &flags))
2368 if (*pp < info->pend
2369 && (ieee_record_enum_type) **pp == ieee_at_record_enum)
2371 if (! ieee_require_atn65 (info, pp, &name, &namlen))
2375 /* This is emitted for method functions, but I don't think we
2376 care very much. It might help if it told us useful
2377 information like the class with which this function is
2378 associated, but it doesn't, so it isn't helpful. */
2383 if (! ieee_read_cxx_defaults (info, pp, count))
2389 const char *name, *mangled, *class;
2390 unsigned long namlen, mangledlen, classlen;
2393 /* Pointer to member. */
2395 if (! ieee_require_atn65 (info, pp, &name, &namlen)
2396 || ! ieee_require_atn65 (info, pp, &mangled, &mangledlen)
2397 || ! ieee_require_atn65 (info, pp, &class, &classlen)
2398 || ! ieee_require_asn (info, pp, &control))
2401 /* FIXME: We should now track down name and change its type. */
2406 if (! ieee_read_reference (info, pp))
2414 /* Read a C++ class definition. This is a pmisc type 80 record of
2418 ieee_read_cxx_class (info, pp, count)
2419 struct ieee_info *info;
2420 const bfd_byte **pp;
2421 unsigned long count;
2423 const bfd_byte *start;
2426 unsigned long taglen;
2427 struct ieee_tag *it;
2429 debug_field *fields;
2430 unsigned int field_count, field_alloc;
2431 debug_baseclass *baseclasses;
2432 unsigned int baseclasses_count, baseclasses_alloc;
2433 const debug_field *structfields;
2437 unsigned long namlen;
2438 debug_method_variant *variants;
2442 unsigned int methods_count, methods_alloc;
2443 debug_type vptrbase;
2445 debug_method *dmethods;
2449 if (! ieee_require_asn (info, pp, &class))
2453 if (! ieee_require_atn65 (info, pp, &tag, &taglen))
2457 /* Find the C struct with this name. */
2458 for (it = info->tags; it != NULL; it = it->next)
2459 if (it->name[0] == tag[0]
2460 && strncmp (it->name, tag, taglen) == 0
2461 && strlen (it->name) == taglen)
2465 ieee_error (info, start, "undefined C++ object");
2469 dhandle = info->dhandle;
2475 baseclasses_count = 0;
2476 baseclasses_alloc = 0;
2480 vptrbase = DEBUG_TYPE_NULL;
2483 structfields = debug_get_fields (dhandle, it->type);
2488 const bfd_byte *spec_start;
2492 if (! ieee_require_asn (info, pp, &id))
2499 ieee_error (info, spec_start, "unrecognized C++ object spec");
2504 bfd_vma flags, cinline;
2505 const char *basename, *fieldname;
2506 unsigned long baselen, fieldlen;
2508 debug_type basetype;
2511 enum debug_visibility visibility;
2512 debug_baseclass baseclass;
2514 /* This represents a base or friend class. */
2516 if (! ieee_require_asn (info, pp, &flags)
2517 || ! ieee_require_atn65 (info, pp, &basename, &baselen)
2518 || ! ieee_require_asn (info, pp, &cinline)
2519 || ! ieee_require_atn65 (info, pp, &fieldname, &fieldlen))
2523 /* We have no way of recording friend information, so we
2525 if ((flags & BASEFLAGS_FRIEND) != 0)
2528 /* I assume that either all of the members of the
2529 baseclass are included in the object, starting at the
2530 beginning of the object, or that none of them are
2533 if ((fieldlen == 0) == (cinline == 0))
2535 ieee_error (info, start, "unsupported C++ object type");
2539 basecopy = savestring (basename, baselen);
2540 basetype = debug_find_tagged_type (dhandle, basecopy,
2541 DEBUG_KIND_ILLEGAL);
2543 if (basetype == DEBUG_TYPE_NULL)
2545 ieee_error (info, start, "C++ base class not defined");
2553 const debug_field *pf;
2555 if (structfields == NULL)
2557 ieee_error (info, start, "C++ object has no fields");
2561 for (pf = structfields; *pf != DEBUG_FIELD_NULL; pf++)
2565 fname = debug_get_field_name (dhandle, *pf);
2568 if (fname[0] == fieldname[0]
2569 && strncmp (fname, fieldname, fieldlen) == 0
2570 && strlen (fname) == fieldlen)
2573 if (*pf == DEBUG_FIELD_NULL)
2575 ieee_error (info, start,
2576 "C++ base class not found in container");
2580 bitpos = debug_get_field_bitpos (dhandle, *pf);
2583 if ((flags & BASEFLAGS_VIRTUAL) != 0)
2587 if ((flags & BASEFLAGS_PRIVATE) != 0)
2588 visibility = DEBUG_VISIBILITY_PRIVATE;
2590 visibility = DEBUG_VISIBILITY_PUBLIC;
2592 baseclass = debug_make_baseclass (dhandle, basetype, bitpos,
2593 virtualp, visibility);
2594 if (baseclass == DEBUG_BASECLASS_NULL)
2597 if (baseclasses_count + 1 >= baseclasses_alloc)
2599 baseclasses_alloc += 10;
2600 baseclasses = ((debug_baseclass *)
2601 xrealloc (baseclasses,
2603 * sizeof *baseclasses)));
2606 baseclasses[baseclasses_count] = baseclass;
2607 ++baseclasses_count;
2608 baseclasses[baseclasses_count] = DEBUG_BASECLASS_NULL;
2615 const char *fieldname, *mangledname;
2616 unsigned long fieldlen, mangledlen;
2620 const debug_field *pf;
2621 enum debug_visibility visibility;
2624 /* This represents a data member. */
2626 if (! ieee_require_asn (info, pp, &flags)
2627 || ! ieee_require_atn65 (info, pp, &fieldname, &fieldlen)
2628 || ! ieee_require_atn65 (info, pp, &mangledname, &mangledlen))
2632 fieldcopy = savestring (fieldname, fieldlen);
2634 staticp = (flags & CXXFLAGS_STATIC) != 0 ? true : false;
2638 struct ieee_var *pv, *pvend;
2640 /* See if we can find a definition for this variable. */
2641 pv = info->vars.vars;
2642 pvend = pv + info->vars.alloc;
2643 for (; pv < pvend; pv++)
2644 if (pv->namlen == mangledlen
2645 && strncmp (pv->name, mangledname, mangledlen) == 0)
2651 /* This can happen if the variable is never used. */
2652 ftype = ieee_builtin_type (info, start,
2653 (unsigned int) builtin_void);
2660 if (structfields == NULL)
2662 ieee_error (info, start, "C++ object has no fields");
2666 for (pf = structfields, findx = 0;
2667 *pf != DEBUG_FIELD_NULL;
2672 fname = debug_get_field_name (dhandle, *pf);
2675 if (fname[0] == mangledname[0]
2676 && strncmp (fname, mangledname, mangledlen) == 0
2677 && strlen (fname) == mangledlen)
2680 if (*pf == DEBUG_FIELD_NULL)
2682 ieee_error (info, start,
2683 "C++ data member not found in container");
2687 ftype = debug_get_field_type (dhandle, *pf);
2689 if (debug_get_type_kind (dhandle, ftype) == DEBUG_KIND_POINTER)
2691 /* We might need to convert this field into a
2692 reference type later on, so make it an indirect
2694 if (it->fslots == NULL)
2697 const debug_field *pfcnt;
2700 for (pfcnt = structfields;
2701 *pfcnt != DEBUG_FIELD_NULL;
2704 it->fslots = ((debug_type *)
2705 xmalloc (fcnt * sizeof *it->fslots));
2706 memset (it->fslots, 0,
2707 fcnt * sizeof *it->fslots);
2710 if (ftype == DEBUG_TYPE_NULL)
2712 it->fslots[findx] = ftype;
2713 ftype = debug_make_indirect_type (dhandle,
2715 (const char *) NULL);
2718 if (ftype == DEBUG_TYPE_NULL)
2721 switch (flags & CXXFLAGS_VISIBILITY)
2724 ieee_error (info, start, "unknown C++ visibility");
2727 case CXXFLAGS_VISIBILITY_PUBLIC:
2728 visibility = DEBUG_VISIBILITY_PUBLIC;
2731 case CXXFLAGS_VISIBILITY_PRIVATE:
2732 visibility = DEBUG_VISIBILITY_PRIVATE;
2735 case CXXFLAGS_VISIBILITY_PROTECTED:
2736 visibility = DEBUG_VISIBILITY_PROTECTED;
2744 mangledcopy = savestring (mangledname, mangledlen);
2746 field = debug_make_static_member (dhandle, fieldcopy,
2752 bfd_vma bitpos, bitsize;
2754 bitpos = debug_get_field_bitpos (dhandle, *pf);
2755 bitsize = debug_get_field_bitsize (dhandle, *pf);
2756 if (bitpos == (bfd_vma) -1 || bitsize == (bfd_vma) -1)
2758 ieee_error (info, start, "bad C++ field bit pos or size");
2761 field = debug_make_field (dhandle, fieldcopy, ftype, bitpos,
2762 bitsize, visibility);
2765 if (field == DEBUG_FIELD_NULL)
2768 if (field_count + 1 >= field_alloc)
2771 fields = ((debug_field *)
2772 xrealloc (fields, field_alloc * sizeof *fields));
2775 fields[field_count] = field;
2777 fields[field_count] = DEBUG_FIELD_NULL;
2784 bfd_vma flags, voffset, control;
2785 const char *name, *mangled;
2786 unsigned long namlen, mangledlen;
2787 struct ieee_var *pv, *pvend;
2789 enum debug_visibility visibility;
2790 boolean constp, volatilep;
2792 debug_method_variant mv;
2793 struct ieee_method *meth;
2796 if (! ieee_require_asn (info, pp, &flags)
2797 || ! ieee_require_atn65 (info, pp, &name, &namlen)
2798 || ! ieee_require_atn65 (info, pp, &mangled, &mangledlen))
2805 if (! ieee_require_asn (info, pp, &voffset))
2809 if (! ieee_require_asn (info, pp, &control))
2813 /* We just ignore the control information. */
2815 /* We have no way to represent friend information, so we
2817 if ((flags & CXXFLAGS_FRIEND) != 0)
2820 /* We should already have seen a type for the function. */
2821 pv = info->vars.vars;
2822 pvend = pv + info->vars.alloc;
2823 for (; pv < pvend; pv++)
2824 if (pv->namlen == mangledlen
2825 && strncmp (pv->name, mangled, mangledlen) == 0)
2830 /* We won't have type information for this function if
2831 it is not included in this file. We don't try to
2832 handle this case. FIXME. */
2833 type = (debug_make_function_type
2835 ieee_builtin_type (info, start,
2836 (unsigned int) builtin_void),
2837 (debug_type *) NULL,
2842 debug_type return_type;
2843 const debug_type *arg_types;
2846 if (debug_get_type_kind (dhandle, pv->type)
2847 != DEBUG_KIND_FUNCTION)
2849 ieee_error (info, start,
2850 "bad type for C++ method function");
2854 return_type = debug_get_return_type (dhandle, pv->type);
2855 arg_types = debug_get_parameter_types (dhandle, pv->type,
2857 if (return_type == DEBUG_TYPE_NULL || arg_types == NULL)
2859 ieee_error (info, start,
2860 "no type information for C++ method function");
2864 type = debug_make_method_type (dhandle, return_type, it->type,
2865 (debug_type *) arg_types,
2868 if (type == DEBUG_TYPE_NULL)
2871 switch (flags & CXXFLAGS_VISIBILITY)
2874 ieee_error (info, start, "unknown C++ visibility");
2877 case CXXFLAGS_VISIBILITY_PUBLIC:
2878 visibility = DEBUG_VISIBILITY_PUBLIC;
2881 case CXXFLAGS_VISIBILITY_PRIVATE:
2882 visibility = DEBUG_VISIBILITY_PRIVATE;
2885 case CXXFLAGS_VISIBILITY_PROTECTED:
2886 visibility = DEBUG_VISIBILITY_PROTECTED;
2890 constp = (flags & CXXFLAGS_CONST) != 0 ? true : false;
2891 volatilep = (flags & CXXFLAGS_VOLATILE) != 0 ? true : false;
2893 mangledcopy = savestring (mangled, mangledlen);
2895 if ((flags & CXXFLAGS_STATIC) != 0)
2899 ieee_error (info, start, "C++ static virtual method");
2902 mv = debug_make_static_method_variant (dhandle, mangledcopy,
2908 debug_type vcontext;
2911 vcontext = DEBUG_TYPE_NULL;
2914 /* FIXME: How can we calculate this correctly? */
2915 vcontext = it->type;
2917 mv = debug_make_method_variant (dhandle, mangledcopy, type,
2922 if (mv == DEBUG_METHOD_VARIANT_NULL)
2925 for (meth = methods, im = 0; im < methods_count; meth++, im++)
2926 if (meth->namlen == namlen
2927 && strncmp (meth->name, name, namlen) == 0)
2929 if (im >= methods_count)
2931 if (methods_count >= methods_alloc)
2933 methods_alloc += 10;
2934 methods = ((struct ieee_method *)
2936 methods_alloc * sizeof *methods));
2938 methods[methods_count].name = name;
2939 methods[methods_count].namlen = namlen;
2940 methods[methods_count].variants = NULL;
2941 methods[methods_count].count = 0;
2942 methods[methods_count].alloc = 0;
2943 meth = methods + methods_count;
2947 if (meth->count + 1 >= meth->alloc)
2950 meth->variants = ((debug_method_variant *)
2951 xrealloc (meth->variants,
2953 * sizeof *meth->variants)));
2956 meth->variants[meth->count] = mv;
2958 meth->variants[meth->count] = DEBUG_METHOD_VARIANT_NULL;
2966 /* We have no way to store this information, so we just
2968 if (! ieee_require_asn (info, pp, &spec))
2971 if ((spec & 4) != 0)
2973 const char *filename;
2974 unsigned long filenamlen;
2977 if (! ieee_require_atn65 (info, pp, &filename, &filenamlen)
2978 || ! ieee_require_asn (info, pp, &lineno))
2982 else if ((spec & 8) != 0)
2984 const char *mangled;
2985 unsigned long mangledlen;
2987 if (! ieee_require_atn65 (info, pp, &mangled, &mangledlen))
2993 ieee_error (info, start,
2994 "unrecognized C++ object overhead spec");
3002 const char *vname, *basename;
3003 unsigned long vnamelen, baselen;
3004 bfd_vma vsize, control;
3006 /* A virtual table pointer. */
3008 if (! ieee_require_atn65 (info, pp, &vname, &vnamelen)
3009 || ! ieee_require_asn (info, pp, &vsize)
3010 || ! ieee_require_atn65 (info, pp, &basename, &baselen)
3011 || ! ieee_require_asn (info, pp, &control))
3015 /* We just ignore the control number. We don't care what
3016 the virtual table name is. We have no way to store the
3017 virtual table size, and I don't think we care anyhow. */
3019 /* FIXME: We can't handle multiple virtual table pointers. */
3027 basecopy = savestring (basename, baselen);
3028 vptrbase = debug_find_tagged_type (dhandle, basecopy,
3029 DEBUG_KIND_ILLEGAL);
3031 if (vptrbase == DEBUG_TYPE_NULL)
3033 ieee_error (info, start, "undefined C++ vtable");
3042 /* Now that we have seen all the method variants, we can call
3043 debug_make_method for each one. */
3045 if (methods_count == 0)
3051 dmethods = ((debug_method *)
3052 xmalloc ((methods_count + 1) * sizeof *dmethods));
3053 for (i = 0; i < methods_count; i++)
3057 namcopy = savestring (methods[i].name, methods[i].namlen);
3058 dmethods[i] = debug_make_method (dhandle, namcopy,
3059 methods[i].variants);
3060 if (dmethods[i] == DEBUG_METHOD_NULL)
3063 dmethods[i] = DEBUG_METHOD_NULL;
3067 /* The struct type was created as an indirect type pointing at
3068 it->slot. We update it->slot to automatically update all
3069 references to this struct. */
3070 it->slot = debug_make_object_type (dhandle,
3072 debug_get_type_size (dhandle,
3074 fields, baseclasses, dmethods,
3076 if (it->slot == DEBUG_TYPE_NULL)
3082 /* Read C++ default argument value and reference type information. */
3085 ieee_read_cxx_defaults (info, pp, count)
3086 struct ieee_info *info;
3087 const bfd_byte **pp;
3088 unsigned long count;
3090 const bfd_byte *start;
3092 unsigned long fnlen;
3097 /* Giving the function name before the argument count is an addendum
3098 to the spec. The function name is demangled, though, so this
3099 record must always refer to the current function. */
3101 if (info->blockstack.bsp <= info->blockstack.stack
3102 || info->blockstack.bsp[-1].fnindx == (unsigned int) -1)
3104 ieee_error (info, start, "C++ default values not in a function");
3108 if (! ieee_require_atn65 (info, pp, &fnname, &fnlen)
3109 || ! ieee_require_asn (info, pp, &defcount))
3113 while (defcount-- > 0)
3117 unsigned long strvallen;
3119 if (! ieee_require_asn (info, pp, &type))
3131 if (! ieee_require_asn (info, pp, &val))
3138 if (! ieee_require_atn65 (info, pp, &strval, &strvallen))
3144 ieee_error (info, start, "unrecognized C++ default type");
3148 /* We have no way to record the default argument values, so we
3149 just ignore them. FIXME. */
3152 /* Any remaining arguments are indices of parameters that are really
3157 debug_type *arg_slots;
3159 dhandle = info->dhandle;
3160 arg_slots = info->types.types[info->blockstack.bsp[-1].fnindx].arg_slots;
3166 if (! ieee_require_asn (info, pp, &indx))
3168 /* The index is 1 based. */
3170 if (arg_slots == NULL
3171 || arg_slots[indx] == DEBUG_TYPE_NULL
3172 || (debug_get_type_kind (dhandle, arg_slots[indx])
3173 != DEBUG_KIND_POINTER))
3175 ieee_error (info, start, "reference parameter is not a pointer");
3179 target = debug_get_target_type (dhandle, arg_slots[indx]);
3180 arg_slots[indx] = debug_make_reference_type (dhandle, target);
3181 if (arg_slots[indx] == DEBUG_TYPE_NULL)
3189 /* Read a C++ reference definition. */
3192 ieee_read_reference (info, pp)
3193 struct ieee_info *info;
3194 const bfd_byte **pp;
3196 const bfd_byte *start;
3198 const char *class, *name;
3199 unsigned long classlen, namlen;
3205 if (! ieee_require_asn (info, pp, &flags))
3208 /* Giving the class name before the member name is in an addendum to
3212 if (! ieee_require_atn65 (info, pp, &class, &classlen))
3216 if (! ieee_require_atn65 (info, pp, &name, &namlen))
3223 struct ieee_var *pv = NULL;
3225 /* We search from the last variable indices to the first in
3226 hopes of finding local variables correctly. FIXME: This
3227 probably won't work in all cases. On the other hand, I don't
3229 for (i = (int) info->vars.alloc - 1; i >= 0; i--)
3233 pv = info->vars.vars + i;
3235 if (pv->pslot == NULL
3236 || pv->namlen != namlen
3237 || strncmp (pv->name, name, namlen) != 0)
3244 ieee_error (info, start,
3245 "unrecognized C++ reference type");
3249 /* Global variable or function. */
3250 if (pv->kind == IEEE_GLOBAL
3251 || pv->kind == IEEE_EXTERNAL
3252 || pv->kind == IEEE_FUNCTION)
3257 /* Global static variable or function. */
3258 if (pv->kind == IEEE_STATIC
3259 || pv->kind == IEEE_FUNCTION)
3264 /* Local variable. */
3265 if (pv->kind == IEEE_LOCAL)
3279 struct ieee_tag *it;
3281 for (it = info->tags; it != NULL; it = it->next)
3283 if (it->name[0] == class[0]
3284 && strncmp (it->name, class, classlen) == 0
3285 && strlen (it->name) == classlen)
3287 if (it->fslots != NULL)
3289 const debug_field *pf;
3292 pf = debug_get_fields (info->dhandle, it->type);
3295 ieee_error (info, start,
3296 "C++ reference in class with no fields");
3300 for (findx = 0; *pf != DEBUG_FIELD_NULL; pf++, findx++)
3304 fname = debug_get_field_name (info->dhandle, *pf);
3307 if (strncmp (fname, name, namlen) == 0
3308 && strlen (fname) == namlen)
3310 pslot = it->fslots + findx;
3323 ieee_error (info, start, "C++ reference not found");
3327 /* We allocated the type of the object as an indirect type pointing
3328 to *pslot, which we can now update to be a reference type. */
3329 if (debug_get_type_kind (info->dhandle, *pslot) != DEBUG_KIND_POINTER)
3331 ieee_error (info, start, "C++ reference is not pointer");
3335 target = debug_get_target_type (info->dhandle, *pslot);
3336 *pslot = debug_make_reference_type (info->dhandle, target);
3337 if (*pslot == DEBUG_TYPE_NULL)
3343 /* Require an ASN record. */
3346 ieee_require_asn (info, pp, pv)
3347 struct ieee_info *info;
3348 const bfd_byte **pp;
3351 const bfd_byte *start;
3352 ieee_record_enum_type c;
3357 c = (ieee_record_enum_type) **pp;
3358 if (c != ieee_e2_first_byte_enum)
3360 ieee_error (info, start, "missing required ASN");
3365 c = (ieee_record_enum_type) (((unsigned int) c << 8) | **pp);
3366 if (c != ieee_asn_record_enum)
3368 ieee_error (info, start, "missing required ASN");
3373 /* Just ignore the variable index. */
3374 if (! ieee_read_number (info, pp, &varindx))
3377 return ieee_read_expression (info, pp, pv);
3380 /* Require an ATN65 record. */
3383 ieee_require_atn65 (info, pp, pname, pnamlen)
3384 struct ieee_info *info;
3385 const bfd_byte **pp;
3387 unsigned long *pnamlen;
3389 const bfd_byte *start;
3390 ieee_record_enum_type c;
3391 bfd_vma name_indx, type_indx, atn_code;
3395 c = (ieee_record_enum_type) **pp;
3396 if (c != ieee_at_record_enum)
3398 ieee_error (info, start, "missing required ATN65");
3403 c = (ieee_record_enum_type) (((unsigned int) c << 8) | **pp);
3404 if (c != ieee_atn_record_enum)
3406 ieee_error (info, start, "missing required ATN65");
3411 if (! ieee_read_number (info, pp, &name_indx)
3412 || ! ieee_read_number (info, pp, &type_indx)
3413 || ! ieee_read_number (info, pp, &atn_code))
3416 /* Just ignore name_indx. */
3418 if (type_indx != 0 || atn_code != 65)
3420 ieee_error (info, start, "bad ATN65 record");
3424 return ieee_read_id (info, pp, pname, pnamlen);
3427 /* Convert a register number in IEEE debugging information into a
3428 generic register number. */
3431 ieee_regno_to_genreg (abfd, r)
3435 switch (bfd_get_arch (abfd))
3438 /* For some reasons stabs adds 2 to the floating point register
3445 /* Stabs uses 0 to 15 for r0 to r15, 16 to 31 for g0 to g15, and
3446 32 to 35 for fp0 to fp3. */
3457 /* Convert a generic register number to an IEEE specific one. */
3460 ieee_genreg_to_regno (abfd, r)
3464 switch (bfd_get_arch (abfd))
3467 /* For some reason stabs add 2 to the floating point register
3474 /* Stabs uses 0 to 15 for r0 to r15, 16 to 31 for g0 to g15, and
3475 32 to 35 for fp0 to fp3. */
3486 /* These routines build IEEE debugging information out of the generic
3487 debugging information. */
3489 /* We build the IEEE debugging information byte by byte. Rather than
3490 waste time copying data around, we use a linked list of buffers to
3493 #define IEEE_BUFSIZE (490)
3498 struct ieee_buf *next;
3499 /* Number of data bytes in this buffer. */
3502 bfd_byte buf[IEEE_BUFSIZE];
3505 /* A list of buffers. */
3510 struct ieee_buf *head;
3511 /* Tail--last buffer on list. */
3512 struct ieee_buf *tail;
3515 /* In order to generate the BB11 blocks required by the HP emulator,
3516 we keep track of ranges of addresses which correspond to a given
3517 compilation unit. */
3522 struct ieee_range *next;
3529 /* This structure holds information for a class on the type stack. */
3531 struct ieee_type_class
3533 /* The name index in the debugging information. */
3535 /* The pmisc records for the class. */
3536 struct ieee_buflist pmiscbuf;
3537 /* The number of pmisc records. */
3538 unsigned int pmisccount;
3539 /* The name of the class holding the virtual table, if not this
3542 /* Whether this class holds its own virtual table. */
3544 /* The largest virtual table offset seen so far. */
3546 /* The current method. */
3548 /* Additional pmisc records used to record fields of reference type. */
3549 struct ieee_buflist refs;
3552 /* This is how we store types for the writing routines. Most types
3553 are simply represented by a type index. */
3555 struct ieee_write_type
3559 /* The size of the type, if known. */
3561 /* The name of the type, if any. */
3563 /* If this is a function or method type, we build the type here, and
3564 only add it to the output buffers if we need it. */
3565 struct ieee_buflist fndef;
3566 /* If this is a struct, this is where the struct definition is
3568 struct ieee_buflist strdef;
3569 /* If this is a class, this is where the class information is built. */
3570 struct ieee_type_class *classdef;
3571 /* Whether the type is unsigned. */
3572 unsigned int unsignedp : 1;
3573 /* Whether this is a reference type. */
3574 unsigned int referencep : 1;
3575 /* Whether this is in the local type block. */
3576 unsigned int localp : 1;
3577 /* Whether this is a duplicate struct definition which we are
3579 unsigned int ignorep : 1;
3582 /* This is the type stack used by the debug writing routines. FIXME:
3583 We could generate more efficient output if we remembered when we
3584 have output a particular type before. */
3586 struct ieee_type_stack
3588 /* Next entry on stack. */
3589 struct ieee_type_stack *next;
3590 /* Type information. */
3591 struct ieee_write_type type;
3594 /* This is a list of associations between a name and some types.
3595 These are used for typedefs and tags. */
3597 struct ieee_name_type
3599 /* Next type for this name. */
3600 struct ieee_name_type *next;
3601 /* ID number. For a typedef, this is the index of the type to which
3602 this name is typedefed. */
3605 struct ieee_write_type type;
3606 /* If this is a tag which has not yet been defined, this is the
3607 kind. If the tag has been defined, this is DEBUG_KIND_ILLEGAL. */
3608 enum debug_type_kind kind;
3611 /* We use a hash table to associate names and types. */
3613 struct ieee_name_type_hash_table
3615 struct bfd_hash_table root;
3618 struct ieee_name_type_hash_entry
3620 struct bfd_hash_entry root;
3621 /* Information for this name. */
3622 struct ieee_name_type *types;
3625 /* This is a list of enums. */
3627 struct ieee_defined_enum
3630 struct ieee_defined_enum *next;
3638 bfd_signed_vma *vals;
3641 /* We keep a list of modified versions of types, so that we don't
3642 output them more than once. */
3644 struct ieee_modified_type
3646 /* Pointer to this type. */
3647 unsigned int pointer;
3648 /* Function with unknown arguments returning this type. */
3649 unsigned int function;
3650 /* Const version of this type. */
3651 unsigned int const_qualified;
3652 /* Volatile version of this type. */
3653 unsigned int volatile_qualified;
3654 /* List of arrays of this type of various bounds. */
3655 struct ieee_modified_array_type *arrays;
3658 /* A list of arrays bounds. */
3660 struct ieee_modified_array_type
3662 /* Next array bounds. */
3663 struct ieee_modified_array_type *next;
3664 /* Type index with these bounds. */
3669 bfd_signed_vma high;
3672 /* This is a list of pending function parameter information. We don't
3673 output them until we see the first block. */
3675 struct ieee_pending_parm
3677 /* Next pending parameter. */
3678 struct ieee_pending_parm *next;
3683 /* Whether the type is a reference. */
3686 enum debug_parm_kind kind;
3691 /* This is the handle passed down by debug_write. */
3695 /* BFD we are writing to. */
3697 /* Whether we got an error in a subroutine called via traverse or
3698 map_over_sections. */
3700 /* Current data buffer list. */
3701 struct ieee_buflist *current;
3702 /* Current data buffer. */
3703 struct ieee_buf *curbuf;
3704 /* Filename of current compilation unit. */
3705 const char *filename;
3706 /* Module name of current compilation unit. */
3707 const char *modname;
3708 /* List of buffer for global types. */
3709 struct ieee_buflist global_types;
3710 /* List of finished data buffers. */
3711 struct ieee_buflist data;
3712 /* List of buffers for typedefs in the current compilation unit. */
3713 struct ieee_buflist types;
3714 /* List of buffers for variables and functions in the current
3715 compilation unit. */
3716 struct ieee_buflist vars;
3717 /* List of buffers for C++ class definitions in the current
3718 compilation unit. */
3719 struct ieee_buflist cxx;
3720 /* List of buffers for line numbers in the current compilation unit. */
3721 struct ieee_buflist linenos;
3722 /* Ranges for the current compilation unit. */
3723 struct ieee_range *ranges;
3724 /* Ranges for all debugging information. */
3725 struct ieee_range *global_ranges;
3726 /* Nested pending ranges. */
3727 struct ieee_range *pending_ranges;
3729 struct ieee_type_stack *type_stack;
3730 /* Next unallocated type index. */
3731 unsigned int type_indx;
3732 /* Next unallocated name index. */
3733 unsigned int name_indx;
3735 struct ieee_name_type_hash_table typedefs;
3737 struct ieee_name_type_hash_table tags;
3739 struct ieee_defined_enum *enums;
3740 /* Modified versions of types. */
3741 struct ieee_modified_type *modified;
3742 /* Number of entries allocated in modified. */
3743 unsigned int modified_alloc;
3744 /* The depth of block nesting. This is 0 outside a function, and 1
3745 just after start_function is called. */
3746 unsigned int block_depth;
3747 /* The name of the current function. */
3749 /* List of buffers for the type of the function we are currently
3751 struct ieee_buflist fntype;
3752 /* List of buffers for the parameters of the function we are
3753 currently writing out. */
3754 struct ieee_buflist fnargs;
3755 /* Number of arguments written to fnargs. */
3756 unsigned int fnargcount;
3757 /* Pending function parameters. */
3758 struct ieee_pending_parm *pending_parms;
3759 /* Current line number filename. */
3760 const char *lineno_filename;
3761 /* Line number name index. */
3762 unsigned int lineno_name_indx;
3763 /* Filename of pending line number. */
3764 const char *pending_lineno_filename;
3765 /* Pending line number. */
3766 unsigned long pending_lineno;
3767 /* Address of pending line number. */
3768 bfd_vma pending_lineno_addr;
3769 /* Highest address seen at end of procedure. */
3773 static boolean ieee_init_buffer
3774 PARAMS ((struct ieee_handle *, struct ieee_buflist *));
3775 static boolean ieee_change_buffer
3776 PARAMS ((struct ieee_handle *, struct ieee_buflist *));
3777 static boolean ieee_append_buffer
3778 PARAMS ((struct ieee_handle *, struct ieee_buflist *,
3779 struct ieee_buflist *));
3780 static boolean ieee_real_write_byte PARAMS ((struct ieee_handle *, int));
3781 static boolean ieee_write_2bytes PARAMS ((struct ieee_handle *, int));
3782 static boolean ieee_write_number PARAMS ((struct ieee_handle *, bfd_vma));
3783 static boolean ieee_write_id PARAMS ((struct ieee_handle *, const char *));
3784 static boolean ieee_write_asn
3785 PARAMS ((struct ieee_handle *, unsigned int, bfd_vma));
3786 static boolean ieee_write_atn65
3787 PARAMS ((struct ieee_handle *, unsigned int, const char *));
3788 static boolean ieee_push_type
3789 PARAMS ((struct ieee_handle *, unsigned int, unsigned int, boolean,
3791 static unsigned int ieee_pop_type PARAMS ((struct ieee_handle *));
3792 static void ieee_pop_unused_type PARAMS ((struct ieee_handle *));
3793 static unsigned int ieee_pop_type_used
3794 PARAMS ((struct ieee_handle *, boolean));
3795 static boolean ieee_add_range
3796 PARAMS ((struct ieee_handle *, boolean, bfd_vma, bfd_vma));
3797 static boolean ieee_start_range PARAMS ((struct ieee_handle *, bfd_vma));
3798 static boolean ieee_end_range PARAMS ((struct ieee_handle *, bfd_vma));
3799 static boolean ieee_define_type
3800 PARAMS ((struct ieee_handle *, unsigned int, boolean, boolean));
3801 static boolean ieee_define_named_type
3802 PARAMS ((struct ieee_handle *, const char *, unsigned int, unsigned int,
3803 boolean, boolean, struct ieee_buflist *));
3804 static struct ieee_modified_type *ieee_get_modified_info
3805 PARAMS ((struct ieee_handle *, unsigned int));
3806 static struct bfd_hash_entry *ieee_name_type_newfunc
3807 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
3808 static boolean ieee_write_undefined_tag
3809 PARAMS ((struct ieee_name_type_hash_entry *, PTR));
3810 static boolean ieee_finish_compilation_unit PARAMS ((struct ieee_handle *));
3811 static void ieee_add_bb11_blocks PARAMS ((bfd *, asection *, PTR));
3812 static boolean ieee_add_bb11
3813 PARAMS ((struct ieee_handle *, asection *, bfd_vma, bfd_vma));
3814 static boolean ieee_output_pending_parms PARAMS ((struct ieee_handle *));
3815 static unsigned int ieee_vis_to_flags PARAMS ((enum debug_visibility));
3816 static boolean ieee_class_method_var
3817 PARAMS ((struct ieee_handle *, const char *, enum debug_visibility, boolean,
3818 boolean, boolean, bfd_vma, boolean));
3820 static boolean ieee_start_compilation_unit PARAMS ((PTR, const char *));
3821 static boolean ieee_start_source PARAMS ((PTR, const char *));
3822 static boolean ieee_empty_type PARAMS ((PTR));
3823 static boolean ieee_void_type PARAMS ((PTR));
3824 static boolean ieee_int_type PARAMS ((PTR, unsigned int, boolean));
3825 static boolean ieee_float_type PARAMS ((PTR, unsigned int));
3826 static boolean ieee_complex_type PARAMS ((PTR, unsigned int));
3827 static boolean ieee_bool_type PARAMS ((PTR, unsigned int));
3828 static boolean ieee_enum_type
3829 PARAMS ((PTR, const char *, const char **, bfd_signed_vma *));
3830 static boolean ieee_pointer_type PARAMS ((PTR));
3831 static boolean ieee_function_type PARAMS ((PTR, int, boolean));
3832 static boolean ieee_reference_type PARAMS ((PTR));
3833 static boolean ieee_range_type PARAMS ((PTR, bfd_signed_vma, bfd_signed_vma));
3834 static boolean ieee_array_type
3835 PARAMS ((PTR, bfd_signed_vma, bfd_signed_vma, boolean));
3836 static boolean ieee_set_type PARAMS ((PTR, boolean));
3837 static boolean ieee_offset_type PARAMS ((PTR));
3838 static boolean ieee_method_type PARAMS ((PTR, boolean, int, boolean));
3839 static boolean ieee_const_type PARAMS ((PTR));
3840 static boolean ieee_volatile_type PARAMS ((PTR));
3841 static boolean ieee_start_struct_type
3842 PARAMS ((PTR, const char *, unsigned int, boolean, unsigned int));
3843 static boolean ieee_struct_field
3844 PARAMS ((PTR, const char *, bfd_vma, bfd_vma, enum debug_visibility));
3845 static boolean ieee_end_struct_type PARAMS ((PTR));
3846 static boolean ieee_start_class_type
3847 PARAMS ((PTR, const char *, unsigned int, boolean, unsigned int, boolean,
3849 static boolean ieee_class_static_member
3850 PARAMS ((PTR, const char *, const char *, enum debug_visibility));
3851 static boolean ieee_class_baseclass
3852 PARAMS ((PTR, bfd_vma, boolean, enum debug_visibility));
3853 static boolean ieee_class_start_method PARAMS ((PTR, const char *));
3854 static boolean ieee_class_method_variant
3855 PARAMS ((PTR, const char *, enum debug_visibility, boolean, boolean,
3857 static boolean ieee_class_static_method_variant
3858 PARAMS ((PTR, const char *, enum debug_visibility, boolean, boolean));
3859 static boolean ieee_class_end_method PARAMS ((PTR));
3860 static boolean ieee_end_class_type PARAMS ((PTR));
3861 static boolean ieee_typedef_type PARAMS ((PTR, const char *));
3862 static boolean ieee_tag_type
3863 PARAMS ((PTR, const char *, unsigned int, enum debug_type_kind));
3864 static boolean ieee_typdef PARAMS ((PTR, const char *));
3865 static boolean ieee_tag PARAMS ((PTR, const char *));
3866 static boolean ieee_int_constant PARAMS ((PTR, const char *, bfd_vma));
3867 static boolean ieee_float_constant PARAMS ((PTR, const char *, double));
3868 static boolean ieee_typed_constant PARAMS ((PTR, const char *, bfd_vma));
3869 static boolean ieee_variable
3870 PARAMS ((PTR, const char *, enum debug_var_kind, bfd_vma));
3871 static boolean ieee_start_function PARAMS ((PTR, const char *, boolean));
3872 static boolean ieee_function_parameter
3873 PARAMS ((PTR, const char *, enum debug_parm_kind, bfd_vma));
3874 static boolean ieee_start_block PARAMS ((PTR, bfd_vma));
3875 static boolean ieee_end_block PARAMS ((PTR, bfd_vma));
3876 static boolean ieee_end_function PARAMS ((PTR));
3877 static boolean ieee_lineno
3878 PARAMS ((PTR, const char *, unsigned long, bfd_vma));
3880 static const struct debug_write_fns ieee_fns =
3882 ieee_start_compilation_unit,
3893 ieee_reference_type,
3901 ieee_start_struct_type,
3903 ieee_end_struct_type,
3904 ieee_start_class_type,
3905 ieee_class_static_member,
3906 ieee_class_baseclass,
3907 ieee_class_start_method,
3908 ieee_class_method_variant,
3909 ieee_class_static_method_variant,
3910 ieee_class_end_method,
3911 ieee_end_class_type,
3917 ieee_float_constant,
3918 ieee_typed_constant,
3920 ieee_start_function,
3921 ieee_function_parameter,
3928 /* Initialize a buffer to be empty. */
3932 ieee_init_buffer (info, buflist)
3933 struct ieee_handle *info;
3934 struct ieee_buflist *buflist;
3936 buflist->head = NULL;
3937 buflist->tail = NULL;
3941 /* See whether a buffer list has any data. */
3943 #define ieee_buffer_emptyp(buflist) ((buflist)->head == NULL)
3945 /* Change the current buffer to a specified buffer chain. */
3948 ieee_change_buffer (info, buflist)
3949 struct ieee_handle *info;
3950 struct ieee_buflist *buflist;
3952 if (buflist->head == NULL)
3954 struct ieee_buf *buf;
3956 buf = (struct ieee_buf *) xmalloc (sizeof *buf);
3959 buflist->head = buf;
3960 buflist->tail = buf;
3963 info->current = buflist;
3964 info->curbuf = buflist->tail;
3969 /* Append a buffer chain. */
3973 ieee_append_buffer (info, mainbuf, newbuf)
3974 struct ieee_handle *info;
3975 struct ieee_buflist *mainbuf;
3976 struct ieee_buflist *newbuf;
3978 if (newbuf->head != NULL)
3980 if (mainbuf->head == NULL)
3981 mainbuf->head = newbuf->head;
3983 mainbuf->tail->next = newbuf->head;
3984 mainbuf->tail = newbuf->tail;
3989 /* Write a byte into the buffer. We use a macro for speed and a
3990 function for the complex cases. */
3992 #define ieee_write_byte(info, b) \
3993 ((info)->curbuf->c < IEEE_BUFSIZE \
3994 ? ((info)->curbuf->buf[(info)->curbuf->c++] = (b), true) \
3995 : ieee_real_write_byte ((info), (b)))
3998 ieee_real_write_byte (info, b)
3999 struct ieee_handle *info;
4002 if (info->curbuf->c >= IEEE_BUFSIZE)
4006 n = (struct ieee_buf *) xmalloc (sizeof *n);
4009 if (info->current->head == NULL)
4010 info->current->head = n;
4012 info->current->tail->next = n;
4013 info->current->tail = n;
4017 info->curbuf->buf[info->curbuf->c] = b;
4023 /* Write out two bytes. */
4026 ieee_write_2bytes (info, i)
4027 struct ieee_handle *info;
4030 return (ieee_write_byte (info, i >> 8)
4031 && ieee_write_byte (info, i & 0xff));
4034 /* Write out an integer. */
4037 ieee_write_number (info, v)
4038 struct ieee_handle *info;
4046 if (v <= (bfd_vma) ieee_number_end_enum)
4047 return ieee_write_byte (info, (int) v);
4058 if (c > (unsigned int) (ieee_number_repeat_end_enum
4059 - ieee_number_repeat_start_enum))
4061 fprintf (stderr, "IEEE numeric overflow: 0x");
4062 fprintf_vma (stderr, v);
4063 fprintf (stderr, "\n");
4067 if (! ieee_write_byte (info, (int) ieee_number_repeat_start_enum + c))
4069 for (; c > 0; --c, ++p)
4071 if (! ieee_write_byte (info, *p))
4078 /* Write out a string. */
4081 ieee_write_id (info, s)
4082 struct ieee_handle *info;
4090 if (! ieee_write_byte (info, len))
4093 else if (len <= 0xff)
4095 if (! ieee_write_byte (info, (int) ieee_extension_length_1_enum)
4096 || ! ieee_write_byte (info, len))
4099 else if (len <= 0xffff)
4101 if (! ieee_write_byte (info, (int) ieee_extension_length_2_enum)
4102 || ! ieee_write_2bytes (info, len))
4107 fprintf (stderr, "IEEE string length overflow: %u\n", len);
4111 for (; *s != '\0'; s++)
4112 if (! ieee_write_byte (info, *s))
4118 /* Write out an ASN record. */
4121 ieee_write_asn (info, indx, val)
4122 struct ieee_handle *info;
4126 return (ieee_write_2bytes (info, (int) ieee_asn_record_enum)
4127 && ieee_write_number (info, indx)
4128 && ieee_write_number (info, val));
4131 /* Write out an ATN65 record. */
4134 ieee_write_atn65 (info, indx, s)
4135 struct ieee_handle *info;
4139 return (ieee_write_2bytes (info, (int) ieee_atn_record_enum)
4140 && ieee_write_number (info, indx)
4141 && ieee_write_number (info, 0)
4142 && ieee_write_number (info, 65)
4143 && ieee_write_id (info, s));
4146 /* Push a type index onto the type stack. */
4149 ieee_push_type (info, indx, size, unsignedp, localp)
4150 struct ieee_handle *info;
4156 struct ieee_type_stack *ts;
4158 ts = (struct ieee_type_stack *) xmalloc (sizeof *ts);
4159 memset (ts, 0, sizeof *ts);
4161 ts->type.indx = indx;
4162 ts->type.size = size;
4163 ts->type.unsignedp = unsignedp;
4164 ts->type.localp = localp;
4166 ts->next = info->type_stack;
4167 info->type_stack = ts;
4172 /* Pop a type index off the type stack. */
4175 ieee_pop_type (info)
4176 struct ieee_handle *info;
4178 return ieee_pop_type_used (info, true);
4181 /* Pop an unused type index off the type stack. */
4184 ieee_pop_unused_type (info)
4185 struct ieee_handle *info;
4187 (void) ieee_pop_type_used (info, false);
4190 /* Pop a used or unused type index off the type stack. */
4193 ieee_pop_type_used (info, used)
4194 struct ieee_handle *info;
4197 struct ieee_type_stack *ts;
4200 ts = info->type_stack;
4201 assert (ts != NULL);
4203 /* If this is a function type, and we need it, we need to append the
4204 actual definition to the typedef block now. */
4205 if (used && ! ieee_buffer_emptyp (&ts->type.fndef))
4207 struct ieee_buflist *buflist;
4209 if (ts->type.localp)
4211 /* Make sure we have started the types block. */
4212 if (ieee_buffer_emptyp (&info->types))
4214 if (! ieee_change_buffer (info, &info->types)
4215 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
4216 || ! ieee_write_byte (info, 1)
4217 || ! ieee_write_number (info, 0)
4218 || ! ieee_write_id (info, info->modname))
4221 buflist = &info->types;
4225 /* Make sure we started the global type block. */
4226 if (ieee_buffer_emptyp (&info->global_types))
4228 if (! ieee_change_buffer (info, &info->global_types)
4229 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
4230 || ! ieee_write_byte (info, 2)
4231 || ! ieee_write_number (info, 0)
4232 || ! ieee_write_id (info, ""))
4235 buflist = &info->global_types;
4238 if (! ieee_append_buffer (info, buflist, &ts->type.fndef))
4242 ret = ts->type.indx;
4243 info->type_stack = ts->next;
4248 /* Add a range of bytes included in the current compilation unit. */
4251 ieee_add_range (info, global, low, high)
4252 struct ieee_handle *info;
4257 struct ieee_range **plist, *r, **pr;
4259 if (low == (bfd_vma) -1 || high == (bfd_vma) -1 || low == high)
4263 plist = &info->global_ranges;
4265 plist = &info->ranges;
4267 for (r = *plist; r != NULL; r = r->next)
4269 if (high >= r->low && low <= r->high)
4271 /* The new range overlaps r. */
4277 while (*pr != NULL && (*pr)->low <= r->high)
4279 struct ieee_range *n;
4281 if ((*pr)->high > r->high)
4282 r->high = (*pr)->high;
4291 r = (struct ieee_range *) xmalloc (sizeof *r);
4292 memset (r, 0, sizeof *r);
4297 /* Store the ranges sorted by address. */
4298 for (pr = plist; *pr != NULL; pr = &(*pr)->next)
4299 if ((*pr)->low > high)
4307 /* Start a new range for which we only have the low address. */
4310 ieee_start_range (info, low)
4311 struct ieee_handle *info;
4314 struct ieee_range *r;
4316 r = (struct ieee_range *) xmalloc (sizeof *r);
4317 memset (r, 0, sizeof *r);
4319 r->next = info->pending_ranges;
4320 info->pending_ranges = r;
4324 /* Finish a range started by ieee_start_range. */
4327 ieee_end_range (info, high)
4328 struct ieee_handle *info;
4331 struct ieee_range *r;
4334 assert (info->pending_ranges != NULL);
4335 r = info->pending_ranges;
4337 info->pending_ranges = r->next;
4339 return ieee_add_range (info, false, low, high);
4342 /* Start defining a type. */
4345 ieee_define_type (info, size, unsignedp, localp)
4346 struct ieee_handle *info;
4351 return ieee_define_named_type (info, (const char *) NULL,
4352 (unsigned int) -1, size, unsignedp,
4353 localp, (struct ieee_buflist *) NULL);
4356 /* Start defining a named type. */
4359 ieee_define_named_type (info, name, indx, size, unsignedp, localp, buflist)
4360 struct ieee_handle *info;
4366 struct ieee_buflist *buflist;
4368 unsigned int type_indx;
4369 unsigned int name_indx;
4371 if (indx != (unsigned int) -1)
4375 type_indx = info->type_indx;
4379 name_indx = info->name_indx;
4385 /* If we were given a buffer, use it; otherwise, use either the
4386 local or the global type information, and make sure that the type
4387 block is started. */
4388 if (buflist != NULL)
4390 if (! ieee_change_buffer (info, buflist))
4395 if (! ieee_buffer_emptyp (&info->types))
4397 if (! ieee_change_buffer (info, &info->types))
4402 if (! ieee_change_buffer (info, &info->types)
4403 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
4404 || ! ieee_write_byte (info, 1)
4405 || ! ieee_write_number (info, 0)
4406 || ! ieee_write_id (info, info->modname))
4412 if (! ieee_buffer_emptyp (&info->global_types))
4414 if (! ieee_change_buffer (info, &info->global_types))
4419 if (! ieee_change_buffer (info, &info->global_types)
4420 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
4421 || ! ieee_write_byte (info, 2)
4422 || ! ieee_write_number (info, 0)
4423 || ! ieee_write_id (info, ""))
4428 /* Push the new type on the type stack, write out an NN record, and
4429 write out the start of a TY record. The caller will then finish
4431 if (! ieee_push_type (info, type_indx, size, unsignedp, localp))
4434 return (ieee_write_byte (info, (int) ieee_nn_record)
4435 && ieee_write_number (info, name_indx)
4436 && ieee_write_id (info, name)
4437 && ieee_write_byte (info, (int) ieee_ty_record_enum)
4438 && ieee_write_number (info, type_indx)
4439 && ieee_write_byte (info, 0xce)
4440 && ieee_write_number (info, name_indx));
4443 /* Get an entry to the list of modified versions of a type. */
4445 static struct ieee_modified_type *
4446 ieee_get_modified_info (info, indx)
4447 struct ieee_handle *info;
4450 if (indx >= info->modified_alloc)
4452 unsigned int nalloc;
4454 nalloc = info->modified_alloc;
4457 while (indx >= nalloc)
4459 info->modified = ((struct ieee_modified_type *)
4460 xrealloc (info->modified,
4461 nalloc * sizeof *info->modified));
4462 memset (info->modified + info->modified_alloc, 0,
4463 (nalloc - info->modified_alloc) * sizeof *info->modified);
4464 info->modified_alloc = nalloc;
4467 return info->modified + indx;
4470 /* Routines for the hash table mapping names to types. */
4472 /* Initialize an entry in the hash table. */
4474 static struct bfd_hash_entry *
4475 ieee_name_type_newfunc (entry, table, string)
4476 struct bfd_hash_entry *entry;
4477 struct bfd_hash_table *table;
4480 struct ieee_name_type_hash_entry *ret =
4481 (struct ieee_name_type_hash_entry *) entry;
4483 /* Allocate the structure if it has not already been allocated by a
4486 ret = ((struct ieee_name_type_hash_entry *)
4487 bfd_hash_allocate (table, sizeof *ret));
4491 /* Call the allocation method of the superclass. */
4492 ret = ((struct ieee_name_type_hash_entry *)
4493 bfd_hash_newfunc ((struct bfd_hash_entry *) ret, table, string));
4496 /* Set local fields. */
4500 return (struct bfd_hash_entry *) ret;
4503 /* Look up an entry in the hash table. */
4505 #define ieee_name_type_hash_lookup(table, string, create, copy) \
4506 ((struct ieee_name_type_hash_entry *) \
4507 bfd_hash_lookup (&(table)->root, (string), (create), (copy)))
4509 /* Traverse the hash table. */
4511 #define ieee_name_type_hash_traverse(table, func, info) \
4512 (bfd_hash_traverse \
4514 (boolean (*) PARAMS ((struct bfd_hash_entry *, PTR))) (func), \
4517 /* The general routine to write out IEEE debugging information. */
4520 write_ieee_debugging_info (abfd, dhandle)
4524 struct ieee_handle info;
4529 memset (&info, 0, sizeof info);
4531 info.type_indx = 256;
4532 info.name_indx = 32;
4534 if (! bfd_hash_table_init (&info.typedefs.root, ieee_name_type_newfunc)
4535 || ! bfd_hash_table_init (&info.tags.root, ieee_name_type_newfunc))
4538 if (! ieee_init_buffer (&info, &info.global_types)
4539 || ! ieee_init_buffer (&info, &info.data)
4540 || ! ieee_init_buffer (&info, &info.types)
4541 || ! ieee_init_buffer (&info, &info.vars)
4542 || ! ieee_init_buffer (&info, &info.cxx)
4543 || ! ieee_init_buffer (&info, &info.linenos)
4544 || ! ieee_init_buffer (&info, &info.fntype)
4545 || ! ieee_init_buffer (&info, &info.fnargs))
4548 if (! debug_write (dhandle, &ieee_fns, (PTR) &info))
4551 if (info.filename != NULL)
4553 if (! ieee_finish_compilation_unit (&info))
4557 /* Put any undefined tags in the global typedef information. */
4559 ieee_name_type_hash_traverse (&info.tags,
4560 ieee_write_undefined_tag,
4565 /* Prepend the global typedef information to the other data. */
4566 if (! ieee_buffer_emptyp (&info.global_types))
4568 if (! ieee_change_buffer (&info, &info.global_types)
4569 || ! ieee_write_byte (&info, (int) ieee_be_record_enum))
4572 if (! ieee_append_buffer (&info, &info.global_types, &info.data))
4574 info.data = info.global_types;
4577 /* Make sure that we have declare BB11 blocks for each range in the
4578 file. They are added to info->vars. */
4580 if (! ieee_init_buffer (&info, &info.vars))
4582 bfd_map_over_sections (abfd, ieee_add_bb11_blocks, (PTR) &info);
4585 if (! ieee_buffer_emptyp (&info.vars))
4587 if (! ieee_change_buffer (&info, &info.vars)
4588 || ! ieee_write_byte (&info, (int) ieee_be_record_enum))
4591 if (! ieee_append_buffer (&info, &info.data, &info.vars))
4595 /* Now all the data is in info.data. Write it out to the BFD. We
4596 normally would need to worry about whether all the other sections
4597 are set up yet, but the IEEE backend will handle this particular
4598 case correctly regardless. */
4599 if (ieee_buffer_emptyp (&info.data))
4601 /* There is no debugging information. */
4605 s = bfd_make_section (abfd, ".debug");
4607 err = "bfd_make_section";
4610 if (! bfd_set_section_flags (abfd, s, SEC_DEBUGGING | SEC_HAS_CONTENTS))
4611 err = "bfd_set_section_flags";
4618 for (b = info.data.head; b != NULL; b = b->next)
4620 if (! bfd_set_section_size (abfd, s, size))
4621 err = "bfd_set_section_size";
4628 for (b = info.data.head; b != NULL; b = b->next)
4630 if (! bfd_set_section_contents (abfd, s, b->buf, offset, b->c))
4632 err = "bfd_set_section_contents";
4641 fprintf (stderr, "%s: %s: %s\n", bfd_get_filename (abfd), err,
4642 bfd_errmsg (bfd_get_error ()));
4646 bfd_hash_table_free (&info.typedefs.root);
4647 bfd_hash_table_free (&info.tags.root);
4652 /* Write out information for an undefined tag. This is called via
4653 ieee_name_type_hash_traverse. */
4656 ieee_write_undefined_tag (h, p)
4657 struct ieee_name_type_hash_entry *h;
4660 struct ieee_handle *info = (struct ieee_handle *) p;
4661 struct ieee_name_type *nt;
4663 for (nt = h->types; nt != NULL; nt = nt->next)
4665 unsigned int name_indx;
4668 if (nt->kind == DEBUG_KIND_ILLEGAL)
4671 if (ieee_buffer_emptyp (&info->global_types))
4673 if (! ieee_change_buffer (info, &info->global_types)
4674 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
4675 || ! ieee_write_byte (info, 2)
4676 || ! ieee_write_number (info, 0)
4677 || ! ieee_write_id (info, ""))
4685 if (! ieee_change_buffer (info, &info->global_types))
4692 name_indx = info->name_indx;
4694 if (! ieee_write_byte (info, (int) ieee_nn_record)
4695 || ! ieee_write_number (info, name_indx)
4696 || ! ieee_write_id (info, nt->type.name)
4697 || ! ieee_write_byte (info, (int) ieee_ty_record_enum)
4698 || ! ieee_write_number (info, nt->type.indx)
4699 || ! ieee_write_byte (info, 0xce)
4700 || ! ieee_write_number (info, name_indx))
4712 case DEBUG_KIND_STRUCT:
4713 case DEBUG_KIND_CLASS:
4716 case DEBUG_KIND_UNION:
4717 case DEBUG_KIND_UNION_CLASS:
4720 case DEBUG_KIND_ENUM:
4724 if (! ieee_write_number (info, code)
4725 || ! ieee_write_number (info, 0))
4735 /* Start writing out information for a compilation unit. */
4738 ieee_start_compilation_unit (p, filename)
4740 const char *filename;
4742 struct ieee_handle *info = (struct ieee_handle *) p;
4743 const char *modname;
4747 if (info->filename != NULL)
4749 if (! ieee_finish_compilation_unit (info))
4753 info->filename = filename;
4754 modname = strrchr (filename, '/');
4755 if (modname != NULL)
4759 modname = strrchr (filename, '\\');
4760 if (modname != NULL)
4765 c = xstrdup (modname);
4766 s = strrchr (c, '.');
4771 if (! ieee_init_buffer (info, &info->types)
4772 || ! ieee_init_buffer (info, &info->vars)
4773 || ! ieee_init_buffer (info, &info->cxx)
4774 || ! ieee_init_buffer (info, &info->linenos))
4776 info->ranges = NULL;
4778 /* Always include a BB1 and a BB3 block. That is what the output of
4779 the MRI linker seems to look like. */
4780 if (! ieee_change_buffer (info, &info->types)
4781 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
4782 || ! ieee_write_byte (info, 1)
4783 || ! ieee_write_number (info, 0)
4784 || ! ieee_write_id (info, info->modname))
4787 nindx = info->name_indx;
4789 if (! ieee_change_buffer (info, &info->vars)
4790 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
4791 || ! ieee_write_byte (info, 3)
4792 || ! ieee_write_number (info, 0)
4793 || ! ieee_write_id (info, info->modname))
4799 /* Finish up a compilation unit. */
4802 ieee_finish_compilation_unit (info)
4803 struct ieee_handle *info;
4805 struct ieee_range *r;
4807 if (! ieee_buffer_emptyp (&info->types))
4809 if (! ieee_change_buffer (info, &info->types)
4810 || ! ieee_write_byte (info, (int) ieee_be_record_enum))
4814 if (! ieee_buffer_emptyp (&info->cxx))
4816 /* Append any C++ information to the global function and
4817 variable information. */
4818 assert (! ieee_buffer_emptyp (&info->vars));
4819 if (! ieee_change_buffer (info, &info->vars))
4822 /* We put the pmisc records in a dummy procedure, just as the
4823 MRI compiler does. */
4824 if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
4825 || ! ieee_write_byte (info, 6)
4826 || ! ieee_write_number (info, 0)
4827 || ! ieee_write_id (info, "__XRYCPP")
4828 || ! ieee_write_number (info, 0)
4829 || ! ieee_write_number (info, 0)
4830 || ! ieee_write_number (info, info->highaddr - 1)
4831 || ! ieee_append_buffer (info, &info->vars, &info->cxx)
4832 || ! ieee_change_buffer (info, &info->vars)
4833 || ! ieee_write_byte (info, (int) ieee_be_record_enum)
4834 || ! ieee_write_number (info, info->highaddr - 1))
4838 if (! ieee_buffer_emptyp (&info->vars))
4840 if (! ieee_change_buffer (info, &info->vars)
4841 || ! ieee_write_byte (info, (int) ieee_be_record_enum))
4845 if (info->pending_lineno_filename != NULL)
4847 /* Force out the pending line number. */
4848 if (! ieee_lineno ((PTR) info, (const char *) NULL, 0, (bfd_vma) -1))
4851 if (! ieee_buffer_emptyp (&info->linenos))
4853 if (! ieee_change_buffer (info, &info->linenos)
4854 || ! ieee_write_byte (info, (int) ieee_be_record_enum))
4856 if (strcmp (info->filename, info->lineno_filename) != 0)
4858 /* We were not in the main file. We just closed the
4859 included line number block, and now we must close the
4860 main line number block. */
4861 if (! ieee_write_byte (info, (int) ieee_be_record_enum))
4866 if (! ieee_append_buffer (info, &info->data, &info->types)
4867 || ! ieee_append_buffer (info, &info->data, &info->vars)
4868 || ! ieee_append_buffer (info, &info->data, &info->linenos))
4871 /* Build BB10/BB11 blocks based on the ranges we recorded. */
4872 if (! ieee_change_buffer (info, &info->data))
4875 if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
4876 || ! ieee_write_byte (info, 10)
4877 || ! ieee_write_number (info, 0)
4878 || ! ieee_write_id (info, info->modname)
4879 || ! ieee_write_id (info, "")
4880 || ! ieee_write_number (info, 0)
4881 || ! ieee_write_id (info, "GNU objcopy"))
4884 for (r = info->ranges; r != NULL; r = r->next)
4893 /* Find the section corresponding to this range. */
4894 for (s = info->abfd->sections; s != NULL; s = s->next)
4896 if (bfd_get_section_vma (info->abfd, s) <= low
4897 && high <= (bfd_get_section_vma (info->abfd, s)
4898 + bfd_section_size (info->abfd, s)))
4904 /* Just ignore this range. */
4908 /* Coalesce ranges if it seems reasonable. */
4909 while (r->next != NULL
4910 && high + 64 >= r->next->low
4912 <= (bfd_get_section_vma (info->abfd, s)
4913 + bfd_section_size (info->abfd, s))))
4919 if ((s->flags & SEC_CODE) != 0)
4921 else if ((s->flags & SEC_READONLY) != 0)
4926 if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
4927 || ! ieee_write_byte (info, 11)
4928 || ! ieee_write_number (info, 0)
4929 || ! ieee_write_id (info, "")
4930 || ! ieee_write_number (info, kind)
4931 || ! ieee_write_number (info, s->index + IEEE_SECTION_NUMBER_BASE)
4932 || ! ieee_write_number (info, low)
4933 || ! ieee_write_byte (info, (int) ieee_be_record_enum)
4934 || ! ieee_write_number (info, high - low))
4937 /* Add this range to the list of global ranges. */
4938 if (! ieee_add_range (info, true, low, high))
4942 if (! ieee_write_byte (info, (int) ieee_be_record_enum))
4948 /* Add BB11 blocks describing each range that we have not already
4952 ieee_add_bb11_blocks (abfd, sec, data)
4957 struct ieee_handle *info = (struct ieee_handle *) data;
4959 struct ieee_range *r;
4961 low = bfd_get_section_vma (abfd, sec);
4962 high = low + bfd_section_size (abfd, sec);
4964 /* Find the first range at or after this section. The ranges are
4965 sorted by address. */
4966 for (r = info->global_ranges; r != NULL; r = r->next)
4972 if (r == NULL || r->low >= high)
4974 if (! ieee_add_bb11 (info, sec, low, high))
4981 if (! ieee_add_bb11 (info, sec, low, r->low))
4993 /* Add a single BB11 block for a range. We add it to info->vars. */
4996 ieee_add_bb11 (info, sec, low, high)
4997 struct ieee_handle *info;
5004 if (! ieee_buffer_emptyp (&info->vars))
5006 if (! ieee_change_buffer (info, &info->vars))
5011 const char *filename, *modname;
5014 /* Start the enclosing BB10 block. */
5015 filename = bfd_get_filename (info->abfd);
5016 modname = strrchr (filename, '/');
5017 if (modname != NULL)
5021 modname = strrchr (filename, '\\');
5022 if (modname != NULL)
5027 c = xstrdup (modname);
5028 s = strrchr (c, '.');
5032 if (! ieee_change_buffer (info, &info->vars)
5033 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
5034 || ! ieee_write_byte (info, 10)
5035 || ! ieee_write_number (info, 0)
5036 || ! ieee_write_id (info, c)
5037 || ! ieee_write_id (info, "")
5038 || ! ieee_write_number (info, 0)
5039 || ! ieee_write_id (info, "GNU objcopy"))
5045 if ((sec->flags & SEC_CODE) != 0)
5047 else if ((sec->flags & SEC_READONLY) != 0)
5052 if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
5053 || ! ieee_write_byte (info, 11)
5054 || ! ieee_write_number (info, 0)
5055 || ! ieee_write_id (info, "")
5056 || ! ieee_write_number (info, kind)
5057 || ! ieee_write_number (info, sec->index + IEEE_SECTION_NUMBER_BASE)
5058 || ! ieee_write_number (info, low)
5059 || ! ieee_write_byte (info, (int) ieee_be_record_enum)
5060 || ! ieee_write_number (info, high - low))
5066 /* Start recording information from a particular source file. This is
5067 used to record which file defined which types, variables, etc. It
5068 is not used for line numbers, since the lineno entry point passes
5069 down the file name anyhow. IEEE debugging information doesn't seem
5070 to store this information anywhere. */
5074 ieee_start_source (p, filename)
5076 const char *filename;
5081 /* Make an empty type. */
5087 struct ieee_handle *info = (struct ieee_handle *) p;
5089 return ieee_push_type (info, 0, 0, false, false);
5092 /* Make a void type. */
5098 struct ieee_handle *info = (struct ieee_handle *) p;
5100 return ieee_push_type (info, 1, 0, false, false);
5103 /* Make an integer type. */
5106 ieee_int_type (p, size, unsignedp)
5111 struct ieee_handle *info = (struct ieee_handle *) p;
5117 indx = (int) builtin_signed_char;
5120 indx = (int) builtin_signed_short_int;
5123 indx = (int) builtin_signed_long;
5126 indx = (int) builtin_signed_long_long;
5129 fprintf (stderr, "IEEE unsupported integer type size %u\n", size);
5136 return ieee_push_type (info, indx, size, unsignedp, false);
5139 /* Make a floating point type. */
5142 ieee_float_type (p, size)
5146 struct ieee_handle *info = (struct ieee_handle *) p;
5152 indx = (int) builtin_float;
5155 indx = (int) builtin_double;
5158 /* FIXME: This size really depends upon the processor. */
5159 indx = (int) builtin_long_double;
5162 indx = (int) builtin_long_long_double;
5165 fprintf (stderr, "IEEE unsupported float type size %u\n", size);
5169 return ieee_push_type (info, indx, size, false, false);
5172 /* Make a complex type. */
5175 ieee_complex_type (p, size)
5179 struct ieee_handle *info = (struct ieee_handle *) p;
5189 /* These cases can be output by gcc -gstabs. Outputting the
5190 wrong type is better than crashing. */
5195 fprintf (stderr, "IEEE unsupported complex type size %u\n", size);
5199 /* FIXME: I don't know what the string is for. */
5200 return (ieee_define_type (info, size, false, false)
5201 && ieee_write_number (info, code)
5202 && ieee_write_id (info, ""));
5205 /* Make a boolean type. IEEE doesn't support these, so we just make
5206 an integer type instead. */
5209 ieee_bool_type (p, size)
5213 return ieee_int_type (p, size, true);
5216 /* Make an enumeration. */
5219 ieee_enum_type (p, tag, names, vals)
5223 bfd_signed_vma *vals;
5225 struct ieee_handle *info = (struct ieee_handle *) p;
5226 struct ieee_defined_enum *e;
5227 boolean localp, simple;
5231 for (e = info->enums; e != NULL; e = e->next)
5241 || tag[0] != e->tag[0]
5242 || strcmp (tag, e->tag) != 0)
5246 if (names != NULL && e->names != NULL)
5248 for (i = 0; names[i] != NULL && e->names[i] != NULL; i++)
5250 if (names[i][0] != e->names[i][0]
5251 || vals[i] != e->vals[i]
5252 || strcmp (names[i], e->names[i]) != 0)
5257 if ((names == NULL && e->names == NULL)
5258 || (names[i] == NULL && e->names[i] == NULL))
5260 /* We've seen this enum before. */
5261 return ieee_push_type (info, e->indx, 0, true, false);
5266 /* We've already seen an enum of the same name, so we must make
5267 sure to output this one locally. */
5273 /* If this is a simple enumeration, in which the values start at 0
5274 and always increment by 1, we can use type E. Otherwise we must
5280 for (i = 0; names[i] != NULL; i++)
5290 if (! ieee_define_named_type (info, tag, (unsigned int) -1, 0,
5291 true, localp, (struct ieee_buflist *) NULL)
5292 || ! ieee_write_number (info, simple ? 'E' : 'N'))
5296 /* FIXME: This is supposed to be the enumeration size, but we
5297 don't store that. */
5298 if (! ieee_write_number (info, 4))
5303 for (i = 0; names[i] != NULL; i++)
5305 if (! ieee_write_id (info, names[i]))
5309 if (! ieee_write_number (info, vals[i]))
5317 e = (struct ieee_defined_enum *) xmalloc (sizeof *e);
5318 memset (e, 0, sizeof *e);
5320 e->indx = info->type_stack->type.indx;
5325 e->next = info->enums;
5332 /* Make a pointer type. */
5335 ieee_pointer_type (p)
5338 struct ieee_handle *info = (struct ieee_handle *) p;
5341 struct ieee_modified_type *m = NULL;
5343 localp = info->type_stack->type.localp;
5344 indx = ieee_pop_type (info);
5346 /* A pointer to a simple builtin type can be obtained by adding 32.
5347 FIXME: Will this be a short pointer, and will that matter? */
5349 return ieee_push_type (info, indx + 32, 0, true, false);
5353 m = ieee_get_modified_info (p, indx);
5357 /* FIXME: The size should depend upon the architecture. */
5359 return ieee_push_type (info, m->pointer, 4, true, false);
5362 if (! ieee_define_type (info, 4, true, localp)
5363 || ! ieee_write_number (info, 'P')
5364 || ! ieee_write_number (info, indx))
5368 m->pointer = info->type_stack->type.indx;
5373 /* Make a function type. This will be called for a method, but we
5374 don't want to actually add it to the type table in that case. We
5375 handle this by defining the type in a private buffer, and only
5376 adding that buffer to the typedef block if we are going to use it. */
5379 ieee_function_type (p, argcount, varargs)
5384 struct ieee_handle *info = (struct ieee_handle *) p;
5386 unsigned int *args = NULL;
5388 unsigned int retindx;
5389 struct ieee_buflist fndef;
5390 struct ieee_modified_type *m;
5396 args = (unsigned int *) xmalloc (argcount * sizeof *args);
5397 for (i = argcount - 1; i >= 0; i--)
5399 if (info->type_stack->type.localp)
5401 args[i] = ieee_pop_type (info);
5404 else if (argcount < 0)
5407 if (info->type_stack->type.localp)
5409 retindx = ieee_pop_type (info);
5412 if (argcount < 0 && ! localp)
5414 m = ieee_get_modified_info (p, retindx);
5418 if (m->function > 0)
5419 return ieee_push_type (info, m->function, 0, true, false);
5422 /* An attribute of 0x41 means that the frame and push mask are
5424 if (! ieee_init_buffer (info, &fndef)
5425 || ! ieee_define_named_type (info, (const char *) NULL,
5426 (unsigned int) -1, 0, true, localp,
5428 || ! ieee_write_number (info, 'x')
5429 || ! ieee_write_number (info, 0x41)
5430 || ! ieee_write_number (info, 0)
5431 || ! ieee_write_number (info, 0)
5432 || ! ieee_write_number (info, retindx)
5433 || ! ieee_write_number (info, (bfd_vma) argcount + (varargs ? 1 : 0)))
5437 for (i = 0; i < argcount; i++)
5438 if (! ieee_write_number (info, args[i]))
5444 /* A varargs function is represented by writing out the last
5445 argument as type void *, although this makes little sense. */
5446 if (! ieee_write_number (info, (bfd_vma) builtin_void + 32))
5450 if (! ieee_write_number (info, 0))
5453 /* We wrote the information into fndef, in case we don't need it.
5454 It will be appended to info->types by ieee_pop_type. */
5455 info->type_stack->type.fndef = fndef;
5458 m->function = info->type_stack->type.indx;
5463 /* Make a reference type. */
5466 ieee_reference_type (p)
5469 struct ieee_handle *info = (struct ieee_handle *) p;
5471 /* IEEE appears to record a normal pointer type, and then use a
5472 pmisc record to indicate that it is really a reference. */
5474 if (! ieee_pointer_type (p))
5476 info->type_stack->type.referencep = true;
5480 /* Make a range type. */
5483 ieee_range_type (p, low, high)
5486 bfd_signed_vma high;
5488 struct ieee_handle *info = (struct ieee_handle *) p;
5490 boolean unsignedp, localp;
5492 size = info->type_stack->type.size;
5493 unsignedp = info->type_stack->type.unsignedp;
5494 localp = info->type_stack->type.localp;
5495 ieee_pop_unused_type (info);
5496 return (ieee_define_type (info, size, unsignedp, localp)
5497 && ieee_write_number (info, 'R')
5498 && ieee_write_number (info, (bfd_vma) low)
5499 && ieee_write_number (info, (bfd_vma) high)
5500 && ieee_write_number (info, unsignedp ? 0 : 1)
5501 && ieee_write_number (info, size));
5504 /* Make an array type. */
5508 ieee_array_type (p, low, high, stringp)
5511 bfd_signed_vma high;
5514 struct ieee_handle *info = (struct ieee_handle *) p;
5515 unsigned int eleindx;
5517 struct ieee_modified_type *m = NULL;
5518 struct ieee_modified_array_type *a;
5520 /* IEEE does not store the range, so we just ignore it. */
5521 ieee_pop_unused_type (info);
5522 localp = info->type_stack->type.localp;
5523 eleindx = ieee_pop_type (info);
5527 m = ieee_get_modified_info (info, eleindx);
5531 for (a = m->arrays; a != NULL; a = a->next)
5533 if (a->low == low && a->high == high)
5534 return ieee_push_type (info, a->indx, 0, false, false);
5538 if (! ieee_define_type (info, 0, false, localp)
5539 || ! ieee_write_number (info, low == 0 ? 'Z' : 'C')
5540 || ! ieee_write_number (info, eleindx))
5544 if (! ieee_write_number (info, low))
5548 if (! ieee_write_number (info, high + 1))
5553 a = (struct ieee_modified_array_type *) xmalloc (sizeof *a);
5554 memset (a, 0, sizeof *a);
5556 a->indx = info->type_stack->type.indx;
5560 a->next = m->arrays;
5567 /* Make a set type. */
5570 ieee_set_type (p, bitstringp)
5574 struct ieee_handle *info = (struct ieee_handle *) p;
5576 unsigned int eleindx;
5578 localp = info->type_stack->type.localp;
5579 eleindx = ieee_pop_type (info);
5581 /* FIXME: We don't know the size, so we just use 4. */
5583 return (ieee_define_type (info, 0, true, localp)
5584 && ieee_write_number (info, 's')
5585 && ieee_write_number (info, 4)
5586 && ieee_write_number (info, eleindx));
5589 /* Make an offset type. */
5592 ieee_offset_type (p)
5595 struct ieee_handle *info = (struct ieee_handle *) p;
5596 unsigned int targetindx, baseindx;
5598 targetindx = ieee_pop_type (info);
5599 baseindx = ieee_pop_type (info);
5601 /* FIXME: The MRI C++ compiler does not appear to generate any
5602 useful type information about an offset type. It just records a
5603 pointer to member as an integer. The MRI/HP IEEE spec does
5604 describe a pmisc record which can be used for a pointer to
5605 member. Unfortunately, it does not describe the target type,
5606 which seems pretty important. I'm going to punt this for now. */
5608 return ieee_int_type (p, 4, true);
5611 /* Make a method type. */
5614 ieee_method_type (p, domain, argcount, varargs)
5620 struct ieee_handle *info = (struct ieee_handle *) p;
5622 /* FIXME: The MRI/HP IEEE spec defines a pmisc record to use for a
5623 method, but the definition is incomplete. We just output an 'x'
5627 ieee_pop_unused_type (info);
5629 return ieee_function_type (p, argcount, varargs);
5632 /* Make a const qualified type. */
5638 struct ieee_handle *info = (struct ieee_handle *) p;
5640 boolean unsignedp, localp;
5642 struct ieee_modified_type *m = NULL;
5644 size = info->type_stack->type.size;
5645 unsignedp = info->type_stack->type.unsignedp;
5646 localp = info->type_stack->type.localp;
5647 indx = ieee_pop_type (info);
5651 m = ieee_get_modified_info (info, indx);
5655 if (m->const_qualified > 0)
5656 return ieee_push_type (info, m->const_qualified, size, unsignedp,
5660 if (! ieee_define_type (info, size, unsignedp, localp)
5661 || ! ieee_write_number (info, 'n')
5662 || ! ieee_write_number (info, 1)
5663 || ! ieee_write_number (info, indx))
5667 m->const_qualified = info->type_stack->type.indx;
5672 /* Make a volatile qualified type. */
5675 ieee_volatile_type (p)
5678 struct ieee_handle *info = (struct ieee_handle *) p;
5680 boolean unsignedp, localp;
5682 struct ieee_modified_type *m = NULL;
5684 size = info->type_stack->type.size;
5685 unsignedp = info->type_stack->type.unsignedp;
5686 localp = info->type_stack->type.localp;
5687 indx = ieee_pop_type (info);
5691 m = ieee_get_modified_info (info, indx);
5695 if (m->volatile_qualified > 0)
5696 return ieee_push_type (info, m->volatile_qualified, size, unsignedp,
5700 if (! ieee_define_type (info, size, unsignedp, localp)
5701 || ! ieee_write_number (info, 'n')
5702 || ! ieee_write_number (info, 2)
5703 || ! ieee_write_number (info, indx))
5707 m->volatile_qualified = info->type_stack->type.indx;
5712 /* Convert an enum debug_visibility into a CXXFLAGS value. */
5715 ieee_vis_to_flags (visibility)
5716 enum debug_visibility visibility;
5722 case DEBUG_VISIBILITY_PUBLIC:
5723 return CXXFLAGS_VISIBILITY_PUBLIC;
5724 case DEBUG_VISIBILITY_PRIVATE:
5725 return CXXFLAGS_VISIBILITY_PRIVATE;
5726 case DEBUG_VISIBILITY_PROTECTED:
5727 return CXXFLAGS_VISIBILITY_PROTECTED;
5732 /* Start defining a struct type. We build it in the strdef field on
5733 the stack, to avoid confusing type definitions required by the
5734 fields with the struct type itself. */
5737 ieee_start_struct_type (p, tag, id, structp, size)
5744 struct ieee_handle *info = (struct ieee_handle *) p;
5745 boolean localp, ignorep;
5749 struct ieee_name_type_hash_entry *h;
5750 struct ieee_name_type *nt, *ntlook;
5751 struct ieee_buflist strdef;
5756 /* We need to create a tag for internal use even if we don't want
5757 one for external use. This will let us refer to an anonymous
5766 sprintf (ab, "__anon%u", id);
5771 /* If we already have references to the tag, we must use the
5772 existing type index. */
5773 h = ieee_name_type_hash_lookup (&info->tags, look, true, copy);
5778 for (ntlook = h->types; ntlook != NULL; ntlook = ntlook->next)
5780 if (ntlook->id == id)
5782 else if (! ntlook->type.localp)
5784 /* We are creating a duplicate definition of a globally
5785 defined tag. Force it to be local to avoid
5793 assert (localp == nt->type.localp);
5794 if (nt->kind == DEBUG_KIND_ILLEGAL && ! localp)
5796 /* We've already seen a global definition of the type.
5797 Ignore this new definition. */
5803 nt = (struct ieee_name_type *) xmalloc (sizeof *nt);
5804 memset (nt, 0, sizeof *nt);
5806 nt->type.name = h->root.string;
5807 nt->next = h->types;
5809 nt->type.indx = info->type_indx;
5813 nt->kind = DEBUG_KIND_ILLEGAL;
5815 if (! ieee_init_buffer (info, &strdef)
5816 || ! ieee_define_named_type (info, tag, nt->type.indx, size, true,
5818 || ! ieee_write_number (info, structp ? 'S' : 'U')
5819 || ! ieee_write_number (info, size))
5826 /* We never want nt->type.name to be NULL. We want the rest of
5827 the type to be the object set up on the type stack; it will
5828 have a NULL name if tag is NULL. */
5829 hold = nt->type.name;
5830 nt->type = info->type_stack->type;
5831 nt->type.name = hold;
5834 info->type_stack->type.name = tag;
5835 info->type_stack->type.strdef = strdef;
5836 info->type_stack->type.ignorep = ignorep;
5841 /* Add a field to a struct. */
5844 ieee_struct_field (p, name, bitpos, bitsize, visibility)
5849 enum debug_visibility visibility;
5851 struct ieee_handle *info = (struct ieee_handle *) p;
5859 assert (info->type_stack != NULL
5860 && info->type_stack->next != NULL
5861 && ! ieee_buffer_emptyp (&info->type_stack->next->type.strdef));
5863 /* If we are ignoring this struct definition, just pop and ignore
5865 if (info->type_stack->next->type.ignorep)
5867 ieee_pop_unused_type (info);
5871 size = info->type_stack->type.size;
5872 unsignedp = info->type_stack->type.unsignedp;
5873 referencep = info->type_stack->type.referencep;
5874 localp = info->type_stack->type.localp;
5875 indx = ieee_pop_type (info);
5878 info->type_stack->type.localp = true;
5880 if (info->type_stack->type.classdef != NULL)
5885 /* This is a class. We must add a description of this field to
5886 the class records we are building. */
5888 flags = ieee_vis_to_flags (visibility);
5889 nindx = info->type_stack->type.classdef->indx;
5890 if (! ieee_change_buffer (info,
5891 &info->type_stack->type.classdef->pmiscbuf)
5892 || ! ieee_write_asn (info, nindx, 'd')
5893 || ! ieee_write_asn (info, nindx, flags)
5894 || ! ieee_write_atn65 (info, nindx, name)
5895 || ! ieee_write_atn65 (info, nindx, name))
5897 info->type_stack->type.classdef->pmisccount += 4;
5903 /* We need to output a record recording that this field is
5904 really of reference type. We put this on the refs field
5905 of classdef, so that it can be appended to the C++
5906 records after the class is defined. */
5908 nindx = info->name_indx;
5911 if (! ieee_change_buffer (info,
5912 &info->type_stack->type.classdef->refs)
5913 || ! ieee_write_byte (info, (int) ieee_nn_record)
5914 || ! ieee_write_number (info, nindx)
5915 || ! ieee_write_id (info, "")
5916 || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
5917 || ! ieee_write_number (info, nindx)
5918 || ! ieee_write_number (info, 0)
5919 || ! ieee_write_number (info, 62)
5920 || ! ieee_write_number (info, 80)
5921 || ! ieee_write_number (info, 4)
5922 || ! ieee_write_asn (info, nindx, 'R')
5923 || ! ieee_write_asn (info, nindx, 3)
5924 || ! ieee_write_atn65 (info, nindx, info->type_stack->type.name)
5925 || ! ieee_write_atn65 (info, nindx, name))
5930 /* If the bitsize doesn't match the expected size, we need to output
5932 if (size == 0 || bitsize == 0 || bitsize == size * 8)
5933 offset = bitpos / 8;
5936 if (! ieee_define_type (info, 0, unsignedp,
5937 info->type_stack->type.localp)
5938 || ! ieee_write_number (info, 'g')
5939 || ! ieee_write_number (info, unsignedp ? 0 : 1)
5940 || ! ieee_write_number (info, bitsize)
5941 || ! ieee_write_number (info, indx))
5943 indx = ieee_pop_type (info);
5947 /* Switch to the struct we are building in order to output this
5948 field definition. */
5949 return (ieee_change_buffer (info, &info->type_stack->type.strdef)
5950 && ieee_write_id (info, name)
5951 && ieee_write_number (info, indx)
5952 && ieee_write_number (info, offset));
5955 /* Finish up a struct type. */
5958 ieee_end_struct_type (p)
5961 struct ieee_handle *info = (struct ieee_handle *) p;
5962 struct ieee_buflist *pb;
5964 assert (info->type_stack != NULL
5965 && ! ieee_buffer_emptyp (&info->type_stack->type.strdef));
5967 /* If we were ignoring this struct definition because it was a
5968 duplicate defintion, just through away whatever bytes we have
5969 accumulated. Leave the type on the stack. */
5970 if (info->type_stack->type.ignorep)
5973 /* If this is not a duplicate definition of this tag, then localp
5974 will be false, and we can put it in the global type block.
5975 FIXME: We should avoid outputting duplicate definitions which are
5977 if (! info->type_stack->type.localp)
5979 /* Make sure we have started the global type block. */
5980 if (ieee_buffer_emptyp (&info->global_types))
5982 if (! ieee_change_buffer (info, &info->global_types)
5983 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
5984 || ! ieee_write_byte (info, 2)
5985 || ! ieee_write_number (info, 0)
5986 || ! ieee_write_id (info, ""))
5989 pb = &info->global_types;
5993 /* Make sure we have started the types block. */
5994 if (ieee_buffer_emptyp (&info->types))
5996 if (! ieee_change_buffer (info, &info->types)
5997 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
5998 || ! ieee_write_byte (info, 1)
5999 || ! ieee_write_number (info, 0)
6000 || ! ieee_write_id (info, info->modname))
6006 /* Append the struct definition to the types. */
6007 if (! ieee_append_buffer (info, pb, &info->type_stack->type.strdef)
6008 || ! ieee_init_buffer (info, &info->type_stack->type.strdef))
6011 /* Leave the struct on the type stack. */
6016 /* Start a class type. */
6019 ieee_start_class_type (p, tag, id, structp, size, vptr, ownvptr)
6028 struct ieee_handle *info = (struct ieee_handle *) p;
6030 struct ieee_buflist pmiscbuf;
6032 struct ieee_type_class *classdef;
6034 /* A C++ class is output as a C++ struct along with a set of pmisc
6035 records describing the class. */
6037 /* We need to have a name so that we can associate the struct and
6043 t = (char *) xmalloc (20);
6044 sprintf (t, "__anon%u", id);
6048 /* We can't write out the virtual table information until we have
6049 finished the class, because we don't know the virtual table size.
6050 We get the size from the largest voffset we see. */
6052 if (vptr && ! ownvptr)
6054 vclass = info->type_stack->type.name;
6055 assert (vclass != NULL);
6056 /* We don't call ieee_pop_unused_type, since the class should
6058 (void) ieee_pop_type (info);
6061 if (! ieee_start_struct_type (p, tag, id, structp, size))
6064 indx = info->name_indx;
6067 /* We write out pmisc records into the classdef field. We will
6068 write out the pmisc start after we know the number of records we
6070 if (! ieee_init_buffer (info, &pmiscbuf)
6071 || ! ieee_change_buffer (info, &pmiscbuf)
6072 || ! ieee_write_asn (info, indx, 'T')
6073 || ! ieee_write_asn (info, indx, structp ? 'o' : 'u')
6074 || ! ieee_write_atn65 (info, indx, tag))
6077 classdef = (struct ieee_type_class *) xmalloc (sizeof *classdef);
6078 memset (classdef, 0, sizeof *classdef);
6080 classdef->indx = indx;
6081 classdef->pmiscbuf = pmiscbuf;
6082 classdef->pmisccount = 3;
6083 classdef->vclass = vclass;
6084 classdef->ownvptr = ownvptr;
6086 info->type_stack->type.classdef = classdef;
6091 /* Add a static member to a class. */
6094 ieee_class_static_member (p, name, physname, visibility)
6097 const char *physname;
6098 enum debug_visibility visibility;
6100 struct ieee_handle *info = (struct ieee_handle *) p;
6104 /* We don't care about the type. Hopefully there will be a call to
6105 ieee_variable declaring the physical name and the type, since
6106 that is where an IEEE consumer must get the type. */
6107 ieee_pop_unused_type (info);
6109 assert (info->type_stack != NULL
6110 && info->type_stack->type.classdef != NULL);
6112 flags = ieee_vis_to_flags (visibility);
6113 flags |= CXXFLAGS_STATIC;
6115 nindx = info->type_stack->type.classdef->indx;
6117 if (! ieee_change_buffer (info, &info->type_stack->type.classdef->pmiscbuf)
6118 || ! ieee_write_asn (info, nindx, 'd')
6119 || ! ieee_write_asn (info, nindx, flags)
6120 || ! ieee_write_atn65 (info, nindx, name)
6121 || ! ieee_write_atn65 (info, nindx, physname))
6123 info->type_stack->type.classdef->pmisccount += 4;
6128 /* Add a base class to a class. */
6131 ieee_class_baseclass (p, bitpos, virtual, visibility)
6135 enum debug_visibility visibility;
6137 struct ieee_handle *info = (struct ieee_handle *) p;
6145 assert (info->type_stack != NULL
6146 && info->type_stack->type.name != NULL
6147 && info->type_stack->next != NULL
6148 && info->type_stack->next->type.classdef != NULL
6149 && ! ieee_buffer_emptyp (&info->type_stack->next->type.strdef));
6151 bname = info->type_stack->type.name;
6152 localp = info->type_stack->type.localp;
6153 bindx = ieee_pop_type (info);
6155 /* We are currently defining both a struct and a class. We must
6156 write out a field definition in the struct which holds the base
6157 class. The stabs debugging reader will create a field named
6158 _vb$CLASS for a virtual base class, so we just use that. FIXME:
6159 we should not depend upon a detail of stabs debugging. */
6162 fname = (char *) xmalloc (strlen (bname) + sizeof "_vb$");
6163 sprintf (fname, "_vb$%s", bname);
6164 flags = BASEFLAGS_VIRTUAL;
6169 info->type_stack->type.localp = true;
6171 fname = (char *) xmalloc (strlen (bname) + sizeof "_b$");
6172 sprintf (fname, "_b$%s", bname);
6174 if (! ieee_change_buffer (info, &info->type_stack->type.strdef)
6175 || ! ieee_write_id (info, fname)
6176 || ! ieee_write_number (info, bindx)
6177 || ! ieee_write_number (info, bitpos / 8))
6182 if (visibility == DEBUG_VISIBILITY_PRIVATE)
6183 flags |= BASEFLAGS_PRIVATE;
6185 nindx = info->type_stack->type.classdef->indx;
6187 if (! ieee_change_buffer (info, &info->type_stack->type.classdef->pmiscbuf)
6188 || ! ieee_write_asn (info, nindx, 'b')
6189 || ! ieee_write_asn (info, nindx, flags)
6190 || ! ieee_write_atn65 (info, nindx, bname)
6191 || ! ieee_write_asn (info, nindx, 0)
6192 || ! ieee_write_atn65 (info, nindx, fname))
6194 info->type_stack->type.classdef->pmisccount += 5;
6201 /* Start building a method for a class. */
6204 ieee_class_start_method (p, name)
6208 struct ieee_handle *info = (struct ieee_handle *) p;
6210 assert (info->type_stack != NULL
6211 && info->type_stack->type.classdef != NULL
6212 && info->type_stack->type.classdef->method == NULL);
6214 info->type_stack->type.classdef->method = name;
6219 /* Define a new method variant, either static or not. */
6222 ieee_class_method_var (info, physname, visibility, staticp, constp,
6223 volatilep, voffset, context)
6224 struct ieee_handle *info;
6225 const char *physname;
6226 enum debug_visibility visibility;
6237 /* We don't need the type of the method. An IEEE consumer which
6238 wants the type must track down the function by the physical name
6239 and get the type from that. */
6240 ieee_pop_unused_type (info);
6242 /* We don't use the context. FIXME: We probably ought to use it to
6243 adjust the voffset somehow, but I don't really know how. */
6245 ieee_pop_unused_type (info);
6247 assert (info->type_stack != NULL
6248 && info->type_stack->type.classdef != NULL
6249 && info->type_stack->type.classdef->method != NULL);
6251 flags = ieee_vis_to_flags (visibility);
6253 /* FIXME: We never set CXXFLAGS_OVERRIDE, CXXFLAGS_OPERATOR,
6254 CXXFLAGS_CTORDTOR, CXXFLAGS_CTOR, or CXXFLAGS_INLINE. */
6257 flags |= CXXFLAGS_STATIC;
6259 flags |= CXXFLAGS_CONST;
6261 flags |= CXXFLAGS_VOLATILE;
6263 nindx = info->type_stack->type.classdef->indx;
6265 virtual = context || voffset > 0;
6267 if (! ieee_change_buffer (info,
6268 &info->type_stack->type.classdef->pmiscbuf)
6269 || ! ieee_write_asn (info, nindx, virtual ? 'v' : 'm')
6270 || ! ieee_write_asn (info, nindx, flags)
6271 || ! ieee_write_atn65 (info, nindx,
6272 info->type_stack->type.classdef->method)
6273 || ! ieee_write_atn65 (info, nindx, physname))
6278 if (voffset > info->type_stack->type.classdef->voffset)
6279 info->type_stack->type.classdef->voffset = voffset;
6280 if (! ieee_write_asn (info, nindx, voffset))
6282 ++info->type_stack->type.classdef->pmisccount;
6285 if (! ieee_write_asn (info, nindx, 0))
6288 info->type_stack->type.classdef->pmisccount += 5;
6293 /* Define a new method variant. */
6296 ieee_class_method_variant (p, physname, visibility, constp, volatilep,
6299 const char *physname;
6300 enum debug_visibility visibility;
6306 struct ieee_handle *info = (struct ieee_handle *) p;
6308 return ieee_class_method_var (info, physname, visibility, false, constp,
6309 volatilep, voffset, context);
6312 /* Define a new static method variant. */
6315 ieee_class_static_method_variant (p, physname, visibility, constp, volatilep)
6317 const char *physname;
6318 enum debug_visibility visibility;
6322 struct ieee_handle *info = (struct ieee_handle *) p;
6324 return ieee_class_method_var (info, physname, visibility, true, constp,
6325 volatilep, 0, false);
6328 /* Finish up a method. */
6331 ieee_class_end_method (p)
6334 struct ieee_handle *info = (struct ieee_handle *) p;
6336 assert (info->type_stack != NULL
6337 && info->type_stack->type.classdef != NULL
6338 && info->type_stack->type.classdef->method != NULL);
6340 info->type_stack->type.classdef->method = NULL;
6345 /* Finish up a class. */
6348 ieee_end_class_type (p)
6351 struct ieee_handle *info = (struct ieee_handle *) p;
6354 assert (info->type_stack != NULL
6355 && info->type_stack->type.classdef != NULL);
6357 /* If we were ignoring this class definition because it was a
6358 duplicate definition, just through away whatever bytes we have
6359 accumulated. Leave the type on the stack. */
6360 if (info->type_stack->type.ignorep)
6363 nindx = info->type_stack->type.classdef->indx;
6365 /* If we have a virtual table, we can write out the information now. */
6366 if (info->type_stack->type.classdef->vclass != NULL
6367 || info->type_stack->type.classdef->ownvptr)
6369 if (! ieee_change_buffer (info,
6370 &info->type_stack->type.classdef->pmiscbuf)
6371 || ! ieee_write_asn (info, nindx, 'z')
6372 || ! ieee_write_atn65 (info, nindx, "")
6373 || ! ieee_write_asn (info, nindx,
6374 info->type_stack->type.classdef->voffset))
6376 if (info->type_stack->type.classdef->ownvptr)
6378 if (! ieee_write_atn65 (info, nindx, ""))
6383 if (! ieee_write_atn65 (info, nindx,
6384 info->type_stack->type.classdef->vclass))
6387 if (! ieee_write_asn (info, nindx, 0))
6389 info->type_stack->type.classdef->pmisccount += 5;
6392 /* Now that we know the number of pmisc records, we can write out
6393 the atn62 which starts the pmisc records, and append them to the
6396 if (! ieee_change_buffer (info, &info->cxx)
6397 || ! ieee_write_byte (info, (int) ieee_nn_record)
6398 || ! ieee_write_number (info, nindx)
6399 || ! ieee_write_id (info, "")
6400 || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
6401 || ! ieee_write_number (info, nindx)
6402 || ! ieee_write_number (info, 0)
6403 || ! ieee_write_number (info, 62)
6404 || ! ieee_write_number (info, 80)
6405 || ! ieee_write_number (info,
6406 info->type_stack->type.classdef->pmisccount))
6409 if (! ieee_append_buffer (info, &info->cxx,
6410 &info->type_stack->type.classdef->pmiscbuf))
6412 if (! ieee_buffer_emptyp (&info->type_stack->type.classdef->refs))
6414 if (! ieee_append_buffer (info, &info->cxx,
6415 &info->type_stack->type.classdef->refs))
6419 return ieee_end_struct_type (p);
6422 /* Push a previously seen typedef onto the type stack. */
6425 ieee_typedef_type (p, name)
6429 struct ieee_handle *info = (struct ieee_handle *) p;
6430 struct ieee_name_type_hash_entry *h;
6431 struct ieee_name_type *nt;
6433 h = ieee_name_type_hash_lookup (&info->typedefs, name, false, false);
6435 /* h should never be NULL, since that would imply that the generic
6436 debugging code has asked for a typedef which it has not yet
6440 /* We always use the most recently defined type for this name, which
6441 will be the first one on the list. */
6444 if (! ieee_push_type (info, nt->type.indx, nt->type.size,
6445 nt->type.unsignedp, nt->type.localp))
6448 /* Copy over any other type information we may have. */
6449 info->type_stack->type = nt->type;
6454 /* Push a tagged type onto the type stack. */
6457 ieee_tag_type (p, name, id, kind)
6461 enum debug_type_kind kind;
6463 struct ieee_handle *info = (struct ieee_handle *) p;
6467 struct ieee_name_type_hash_entry *h;
6468 struct ieee_name_type *nt;
6470 if (kind == DEBUG_KIND_ENUM)
6472 struct ieee_defined_enum *e;
6476 for (e = info->enums; e != NULL; e = e->next)
6477 if (e->tag != NULL && strcmp (e->tag, name) == 0)
6478 return ieee_push_type (info, e->indx, 0, true, false);
6487 sprintf (ab, "__anon%u", id);
6492 h = ieee_name_type_hash_lookup (&info->tags, name, true, copy);
6496 for (nt = h->types; nt != NULL; nt = nt->next)
6500 if (! ieee_push_type (info, nt->type.indx, nt->type.size,
6501 nt->type.unsignedp, nt->type.localp))
6503 /* Copy over any other type information we may have. */
6504 info->type_stack->type = nt->type;
6508 if (! nt->type.localp)
6510 /* This is a duplicate of a global type, so it must be
6516 nt = (struct ieee_name_type *) xmalloc (sizeof *nt);
6517 memset (nt, 0, sizeof *nt);
6520 nt->type.name = h->root.string;
6521 nt->type.indx = info->type_indx;
6522 nt->type.localp = localp;
6526 nt->next = h->types;
6529 if (! ieee_push_type (info, nt->type.indx, 0, false, localp))
6532 info->type_stack->type.name = h->root.string;
6537 /* Output a typedef. */
6540 ieee_typdef (p, name)
6544 struct ieee_handle *info = (struct ieee_handle *) p;
6545 struct ieee_write_type type;
6549 struct ieee_name_type_hash_entry *h;
6550 struct ieee_name_type *nt;
6552 type = info->type_stack->type;
6555 /* If this is a simple builtin type using a builtin name, we don't
6556 want to output the typedef itself. We also want to change the
6557 type index to correspond to the name being used. We recognize
6558 names used in stabs debugging output even if they don't exactly
6559 correspond to the names used for the IEEE builtin types. */
6561 if (indx <= (unsigned int) builtin_bcd_float)
6563 switch ((enum builtin_types) indx)
6569 if (strcmp (name, "void") == 0)
6573 case builtin_signed_char:
6575 if (strcmp (name, "signed char") == 0)
6577 indx = (unsigned int) builtin_signed_char;
6580 else if (strcmp (name, "char") == 0)
6582 indx = (unsigned int) builtin_char;
6587 case builtin_unsigned_char:
6588 if (strcmp (name, "unsigned char") == 0)
6592 case builtin_signed_short_int:
6594 case builtin_short_int:
6595 case builtin_signed_short:
6596 if (strcmp (name, "signed short int") == 0)
6598 indx = (unsigned int) builtin_signed_short_int;
6601 else if (strcmp (name, "short") == 0)
6603 indx = (unsigned int) builtin_short;
6606 else if (strcmp (name, "short int") == 0)
6608 indx = (unsigned int) builtin_short_int;
6611 else if (strcmp (name, "signed short") == 0)
6613 indx = (unsigned int) builtin_signed_short;
6618 case builtin_unsigned_short_int:
6619 case builtin_unsigned_short:
6620 if (strcmp (name, "unsigned short int") == 0
6621 || strcmp (name, "short unsigned int") == 0)
6623 indx = builtin_unsigned_short_int;
6626 else if (strcmp (name, "unsigned short") == 0)
6628 indx = builtin_unsigned_short;
6633 case builtin_signed_long:
6634 case builtin_int: /* FIXME: Size depends upon architecture. */
6636 if (strcmp (name, "signed long") == 0)
6638 indx = builtin_signed_long;
6641 else if (strcmp (name, "int") == 0)
6646 else if (strcmp (name, "long") == 0
6647 || strcmp (name, "long int") == 0)
6649 indx = builtin_long;
6654 case builtin_unsigned_long:
6655 case builtin_unsigned: /* FIXME: Size depends upon architecture. */
6656 case builtin_unsigned_int: /* FIXME: Like builtin_unsigned. */
6657 if (strcmp (name, "unsigned long") == 0
6658 || strcmp (name, "long unsigned int") == 0)
6660 indx = builtin_unsigned_long;
6663 else if (strcmp (name, "unsigned") == 0)
6665 indx = builtin_unsigned;
6668 else if (strcmp (name, "unsigned int") == 0)
6670 indx = builtin_unsigned_int;
6675 case builtin_signed_long_long:
6676 if (strcmp (name, "signed long long") == 0
6677 || strcmp (name, "long long int") == 0)
6681 case builtin_unsigned_long_long:
6682 if (strcmp (name, "unsigned long long") == 0
6683 || strcmp (name, "long long unsigned int") == 0)
6688 if (strcmp (name, "float") == 0)
6692 case builtin_double:
6693 if (strcmp (name, "double") == 0)
6697 case builtin_long_double:
6698 if (strcmp (name, "long double") == 0)
6702 case builtin_long_long_double:
6703 if (strcmp (name, "long long double") == 0)
6712 h = ieee_name_type_hash_lookup (&info->typedefs, name, true, false);
6716 /* See if we have already defined this type with this name. */
6717 localp = type.localp;
6718 for (nt = h->types; nt != NULL; nt = nt->next)
6722 /* If this is a global definition, then we don't need to
6723 do anything here. */
6724 if (! nt->type.localp)
6726 ieee_pop_unused_type (info);
6732 /* This is a duplicate definition, so make this one local. */
6737 /* We need to add a new typedef for this type. */
6739 nt = (struct ieee_name_type *) xmalloc (sizeof *nt);
6740 memset (nt, 0, sizeof *nt);
6743 nt->type.name = name;
6744 nt->type.localp = localp;
6745 nt->kind = DEBUG_KIND_ILLEGAL;
6747 nt->next = h->types;
6752 /* This is one of the builtin typedefs, so we don't need to
6753 actually define it. */
6754 ieee_pop_unused_type (info);
6758 indx = ieee_pop_type (info);
6760 if (! ieee_define_named_type (info, name, (unsigned int) -1, type.size,
6761 type.unsignedp, localp,
6762 (struct ieee_buflist *) NULL)
6763 || ! ieee_write_number (info, 'T')
6764 || ! ieee_write_number (info, indx))
6767 /* Remove the type we just added to the type stack. This should not
6768 be ieee_pop_unused_type, since the type is used, we just don't
6770 (void) ieee_pop_type (info);
6775 /* Output a tag for a type. We don't have to do anything here. */
6782 struct ieee_handle *info = (struct ieee_handle *) p;
6784 /* This should not be ieee_pop_unused_type, since we want the type
6786 (void) ieee_pop_type (info);
6790 /* Output an integer constant. */
6793 ieee_int_constant (p, name, val)
6802 /* Output a floating point constant. */
6805 ieee_float_constant (p, name, val)
6814 /* Output a typed constant. */
6817 ieee_typed_constant (p, name, val)
6822 struct ieee_handle *info = (struct ieee_handle *) p;
6825 ieee_pop_unused_type (info);
6829 /* Output a variable. */
6832 ieee_variable (p, name, kind, val)
6835 enum debug_var_kind kind;
6838 struct ieee_handle *info = (struct ieee_handle *) p;
6839 unsigned int name_indx;
6842 unsigned int type_indx;
6846 size = info->type_stack->type.size;
6847 referencep = info->type_stack->type.referencep;
6848 type_indx = ieee_pop_type (info);
6850 assert (! ieee_buffer_emptyp (&info->vars));
6851 if (! ieee_change_buffer (info, &info->vars))
6854 name_indx = info->name_indx;
6857 /* Write out an NN and an ATN record for this variable. */
6858 if (! ieee_write_byte (info, (int) ieee_nn_record)
6859 || ! ieee_write_number (info, name_indx)
6860 || ! ieee_write_id (info, name)
6861 || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
6862 || ! ieee_write_number (info, name_indx)
6863 || ! ieee_write_number (info, type_indx))
6871 if (! ieee_write_number (info, 8)
6872 || ! ieee_add_range (info, false, val, val + size))
6878 if (! ieee_write_number (info, 3)
6879 || ! ieee_add_range (info, false, val, val + size))
6884 case DEBUG_LOCAL_STATIC:
6885 if (! ieee_write_number (info, 3)
6886 || ! ieee_add_range (info, false, val, val + size))
6892 if (! ieee_write_number (info, 1)
6893 || ! ieee_write_number (info, val))
6898 case DEBUG_REGISTER:
6899 if (! ieee_write_number (info, 2)
6900 || ! ieee_write_number (info,
6901 ieee_genreg_to_regno (info->abfd, val)))
6910 if (! ieee_write_asn (info, name_indx, val))
6914 /* If this is really a reference type, then we just output it with
6915 pointer type, and must now output a C++ record indicating that it
6916 is really reference type. */
6921 nindx = info->name_indx;
6924 /* If this is a global variable, we want to output the misc
6925 record in the C++ misc record block. Otherwise, we want to
6926 output it just after the variable definition, which is where
6927 the current buffer is. */
6930 if (! ieee_change_buffer (info, &info->cxx))
6934 if (! ieee_write_byte (info, (int) ieee_nn_record)
6935 || ! ieee_write_number (info, nindx)
6936 || ! ieee_write_id (info, "")
6937 || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
6938 || ! ieee_write_number (info, nindx)
6939 || ! ieee_write_number (info, 0)
6940 || ! ieee_write_number (info, 62)
6941 || ! ieee_write_number (info, 80)
6942 || ! ieee_write_number (info, 3)
6943 || ! ieee_write_asn (info, nindx, 'R')
6944 || ! ieee_write_asn (info, nindx, refflag)
6945 || ! ieee_write_atn65 (info, nindx, name))
6952 /* Start outputting information for a function. */
6955 ieee_start_function (p, name, global)
6960 struct ieee_handle *info = (struct ieee_handle *) p;
6962 unsigned int retindx, typeindx;
6964 referencep = info->type_stack->type.referencep;
6965 retindx = ieee_pop_type (info);
6967 /* Besides recording a BB4 or BB6 block, we record the type of the
6968 function in the BB1 typedef block. We can't write out the full
6969 type until we have seen all the parameters, so we accumulate it
6970 in info->fntype and info->fnargs. */
6971 if (! ieee_buffer_emptyp (&info->fntype))
6973 /* FIXME: This might happen someday if we support nested
6978 info->fnname = name;
6980 /* An attribute of 0x40 means that the push mask is unknown. */
6981 if (! ieee_define_named_type (info, name, (unsigned int) -1, 0, false, true,
6983 || ! ieee_write_number (info, 'x')
6984 || ! ieee_write_number (info, 0x40)
6985 || ! ieee_write_number (info, 0)
6986 || ! ieee_write_number (info, 0)
6987 || ! ieee_write_number (info, retindx))
6990 typeindx = ieee_pop_type (info);
6992 if (! ieee_init_buffer (info, &info->fnargs))
6994 info->fnargcount = 0;
6996 /* If the function return value is actually a reference type, we
6997 must add a record indicating that. */
7002 nindx = info->name_indx;
7004 if (! ieee_change_buffer (info, &info->cxx)
7005 || ! ieee_write_byte (info, (int) ieee_nn_record)
7006 || ! ieee_write_number (info, nindx)
7007 || ! ieee_write_id (info, "")
7008 || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
7009 || ! ieee_write_number (info, nindx)
7010 || ! ieee_write_number (info, 0)
7011 || ! ieee_write_number (info, 62)
7012 || ! ieee_write_number (info, 80)
7013 || ! ieee_write_number (info, 3)
7014 || ! ieee_write_asn (info, nindx, 'R')
7015 || ! ieee_write_asn (info, nindx, global ? 0 : 1)
7016 || ! ieee_write_atn65 (info, nindx, name))
7020 assert (! ieee_buffer_emptyp (&info->vars));
7021 if (! ieee_change_buffer (info, &info->vars))
7024 /* The address is written out as the first block. */
7026 ++info->block_depth;
7028 return (ieee_write_byte (info, (int) ieee_bb_record_enum)
7029 && ieee_write_byte (info, global ? 4 : 6)
7030 && ieee_write_number (info, 0)
7031 && ieee_write_id (info, name)
7032 && ieee_write_number (info, 0)
7033 && ieee_write_number (info, typeindx));
7036 /* Add a function parameter. This will normally be called before the
7037 first block, so we postpone them until we see the block. */
7040 ieee_function_parameter (p, name, kind, val)
7043 enum debug_parm_kind kind;
7046 struct ieee_handle *info = (struct ieee_handle *) p;
7047 struct ieee_pending_parm *m, **pm;
7049 assert (info->block_depth == 1);
7051 m = (struct ieee_pending_parm *) xmalloc (sizeof *m);
7052 memset (m, 0, sizeof *m);
7056 m->referencep = info->type_stack->type.referencep;
7057 m->type = ieee_pop_type (info);
7061 for (pm = &info->pending_parms; *pm != NULL; pm = &(*pm)->next)
7065 /* Add the type to the fnargs list. */
7066 if (! ieee_change_buffer (info, &info->fnargs)
7067 || ! ieee_write_number (info, m->type))
7074 /* Output pending function parameters. */
7077 ieee_output_pending_parms (info)
7078 struct ieee_handle *info;
7080 struct ieee_pending_parm *m;
7081 unsigned int refcount;
7084 for (m = info->pending_parms; m != NULL; m = m->next)
7086 enum debug_var_kind vkind;
7093 case DEBUG_PARM_STACK:
7094 case DEBUG_PARM_REFERENCE:
7095 vkind = DEBUG_LOCAL;
7097 case DEBUG_PARM_REG:
7098 case DEBUG_PARM_REF_REG:
7099 vkind = DEBUG_REGISTER;
7103 if (! ieee_push_type (info, m->type, 0, false, false))
7105 info->type_stack->type.referencep = m->referencep;
7108 if (! ieee_variable ((PTR) info, m->name, vkind, m->val))
7112 /* If there are any reference parameters, we need to output a
7113 miscellaneous record indicating them. */
7116 unsigned int nindx, varindx;
7118 /* FIXME: The MRI compiler outputs the demangled function name
7119 here, but we are outputting the mangled name. */
7120 nindx = info->name_indx;
7122 if (! ieee_change_buffer (info, &info->vars)
7123 || ! ieee_write_byte (info, (int) ieee_nn_record)
7124 || ! ieee_write_number (info, nindx)
7125 || ! ieee_write_id (info, "")
7126 || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
7127 || ! ieee_write_number (info, nindx)
7128 || ! ieee_write_number (info, 0)
7129 || ! ieee_write_number (info, 62)
7130 || ! ieee_write_number (info, 80)
7131 || ! ieee_write_number (info, refcount + 3)
7132 || ! ieee_write_asn (info, nindx, 'B')
7133 || ! ieee_write_atn65 (info, nindx, info->fnname)
7134 || ! ieee_write_asn (info, nindx, 0))
7136 for (m = info->pending_parms, varindx = 1;
7138 m = m->next, varindx++)
7142 if (! ieee_write_asn (info, nindx, varindx))
7148 m = info->pending_parms;
7151 struct ieee_pending_parm *next;
7158 info->pending_parms = NULL;
7163 /* Start a block. If this is the first block, we output the address
7164 to finish the BB4 or BB6, and then output the function parameters. */
7167 ieee_start_block (p, addr)
7171 struct ieee_handle *info = (struct ieee_handle *) p;
7173 if (! ieee_change_buffer (info, &info->vars))
7176 if (info->block_depth == 1)
7178 if (! ieee_write_number (info, addr)
7179 || ! ieee_output_pending_parms (info))
7184 if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
7185 || ! ieee_write_byte (info, 6)
7186 || ! ieee_write_number (info, 0)
7187 || ! ieee_write_id (info, "")
7188 || ! ieee_write_number (info, 0)
7189 || ! ieee_write_number (info, 0)
7190 || ! ieee_write_number (info, addr))
7194 if (! ieee_start_range (info, addr))
7197 ++info->block_depth;
7205 ieee_end_block (p, addr)
7209 struct ieee_handle *info = (struct ieee_handle *) p;
7211 /* The address we are given is the end of the block, but IEEE seems
7212 to want to the address of the last byte in the block, so we
7214 if (! ieee_change_buffer (info, &info->vars)
7215 || ! ieee_write_byte (info, (int) ieee_be_record_enum)
7216 || ! ieee_write_number (info, addr - 1))
7219 if (! ieee_end_range (info, addr))
7222 --info->block_depth;
7224 if (addr > info->highaddr)
7225 info->highaddr = addr;
7230 /* End a function. */
7233 ieee_end_function (p)
7236 struct ieee_handle *info = (struct ieee_handle *) p;
7238 assert (info->block_depth == 1);
7240 --info->block_depth;
7242 /* Now we can finish up fntype, and add it to the typdef section.
7243 At this point, fntype is the 'x' type up to the argument count,
7244 and fnargs is the argument types. We must add the argument
7245 count, and we must add the level. FIXME: We don't record varargs
7246 functions correctly. In fact, stabs debugging does not give us
7247 enough information to do so. */
7248 if (! ieee_change_buffer (info, &info->fntype)
7249 || ! ieee_write_number (info, info->fnargcount)
7250 || ! ieee_change_buffer (info, &info->fnargs)
7251 || ! ieee_write_number (info, 0))
7254 /* Make sure the typdef block has been started. */
7255 if (ieee_buffer_emptyp (&info->types))
7257 if (! ieee_change_buffer (info, &info->types)
7258 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
7259 || ! ieee_write_byte (info, 1)
7260 || ! ieee_write_number (info, 0)
7261 || ! ieee_write_id (info, info->modname))
7265 if (! ieee_append_buffer (info, &info->types, &info->fntype)
7266 || ! ieee_append_buffer (info, &info->types, &info->fnargs))
7269 info->fnname = NULL;
7270 if (! ieee_init_buffer (info, &info->fntype)
7271 || ! ieee_init_buffer (info, &info->fnargs))
7273 info->fnargcount = 0;
7278 /* Record line number information. */
7281 ieee_lineno (p, filename, lineno, addr)
7283 const char *filename;
7284 unsigned long lineno;
7287 struct ieee_handle *info = (struct ieee_handle *) p;
7289 assert (info->filename != NULL);
7291 /* The HP simulator seems to get confused when more than one line is
7292 listed for the same address, at least if they are in different
7293 files. We handle this by always listing the last line for a
7294 given address, since that seems to be the one that gdb uses. */
7295 if (info->pending_lineno_filename != NULL
7296 && addr != info->pending_lineno_addr)
7298 /* Make sure we have a line number block. */
7299 if (! ieee_buffer_emptyp (&info->linenos))
7301 if (! ieee_change_buffer (info, &info->linenos))
7306 info->lineno_name_indx = info->name_indx;
7308 if (! ieee_change_buffer (info, &info->linenos)
7309 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
7310 || ! ieee_write_byte (info, 5)
7311 || ! ieee_write_number (info, 0)
7312 || ! ieee_write_id (info, info->filename)
7313 || ! ieee_write_byte (info, (int) ieee_nn_record)
7314 || ! ieee_write_number (info, info->lineno_name_indx)
7315 || ! ieee_write_id (info, ""))
7317 info->lineno_filename = info->filename;
7320 if (strcmp (info->pending_lineno_filename, info->lineno_filename) != 0)
7322 if (strcmp (info->filename, info->lineno_filename) != 0)
7324 /* We were not in the main file. Close the block for the
7326 if (! ieee_write_byte (info, (int) ieee_be_record_enum))
7328 if (strcmp (info->filename, info->pending_lineno_filename) == 0)
7330 /* We need a new NN record, and we aren't output to
7332 info->lineno_name_indx = info->name_indx;
7334 if (! ieee_write_byte (info, (int) ieee_nn_record)
7335 || ! ieee_write_number (info, info->lineno_name_indx)
7336 || ! ieee_write_id (info, ""))
7340 if (strcmp (info->filename, info->pending_lineno_filename) != 0)
7342 /* We are not changing to the main file. Open a block for
7343 the new included file. */
7344 info->lineno_name_indx = info->name_indx;
7346 if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
7347 || ! ieee_write_byte (info, 5)
7348 || ! ieee_write_number (info, 0)
7349 || ! ieee_write_id (info, info->pending_lineno_filename)
7350 || ! ieee_write_byte (info, (int) ieee_nn_record)
7351 || ! ieee_write_number (info, info->lineno_name_indx)
7352 || ! ieee_write_id (info, ""))
7355 info->lineno_filename = info->pending_lineno_filename;
7358 if (! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
7359 || ! ieee_write_number (info, info->lineno_name_indx)
7360 || ! ieee_write_number (info, 0)
7361 || ! ieee_write_number (info, 7)
7362 || ! ieee_write_number (info, info->pending_lineno)
7363 || ! ieee_write_number (info, 0)
7364 || ! ieee_write_asn (info, info->lineno_name_indx,
7365 info->pending_lineno_addr))
7369 info->pending_lineno_filename = filename;
7370 info->pending_lineno = lineno;
7371 info->pending_lineno_addr = addr;