1 /* ieee.c -- Write out IEEE-695 debugging information.
2 Copyright (C) 1996 Free Software Foundation, Inc.
5 This file is part of GNU Binutils.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22 /* This file reads and writes IEEE-695 debugging information. */
30 #include "libiberty.h"
34 /* This structure holds an entry on the block stack. */
38 /* The kind of block. */
40 /* The source file name, for a BB5 block. */
44 /* This structure is the block stack. */
46 #define BLOCKSTACK_SIZE (16)
48 struct ieee_blockstack
50 /* The stack pointer. */
51 struct ieee_block *bsp;
53 struct ieee_block stack[BLOCKSTACK_SIZE];
56 /* This structure holds information for a variable. */
68 /* This structure holds all the variables. */
72 /* Number of slots allocated. */
75 struct ieee_var *vars;
78 /* This structure holds information for a type. We need this because
79 we don't want to represent bitfields as real types. */
85 /* Slot if this is type is referenced before it is defined. */
87 /* If this is a bitfield, this is the size in bits. If this is not
88 a bitfield, this is zero. */
89 unsigned long bitsize;
90 /* If this is a function type ('x' or 'X') this is the return type. */
91 debug_type return_type;
94 /* This structure holds all the type information. */
98 /* Number of slots allocated. */
101 struct ieee_type *types;
103 #define BUILTIN_TYPE_COUNT (60)
104 debug_type builtins[BUILTIN_TYPE_COUNT];
107 /* Basic builtin types, not including the pointers. */
113 builtin_signed_char = 2,
114 builtin_unsigned_char = 3,
115 builtin_signed_short_int = 4,
116 builtin_unsigned_short_int = 5,
117 builtin_signed_long = 6,
118 builtin_unsigned_long = 7,
119 builtin_signed_long_long = 8,
120 builtin_unsigned_long_long = 9,
123 builtin_long_double = 12,
124 builtin_long_long_double = 13,
125 builtin_quoted_string = 14,
126 builtin_instruction_address = 15,
128 builtin_unsigned = 17,
129 builtin_unsigned_int = 18,
133 builtin_unsigned_short = 22,
134 builtin_short_int = 23,
135 builtin_signed_short = 24,
136 builtin_bcd_float = 25
139 static void ieee_error
140 PARAMS ((bfd *, const bfd_byte *, const bfd_byte *, const char *));
141 static void ieee_eof PARAMS ((bfd *));
142 static char *savestring PARAMS ((const char *, unsigned long));
143 static boolean ieee_read_number
144 PARAMS ((bfd *, const bfd_byte *, const bfd_byte **, const bfd_byte *,
146 static boolean ieee_read_optional_number
147 PARAMS ((bfd *, const bfd_byte *, const bfd_byte **, const bfd_byte *,
148 bfd_vma *, boolean *));
149 static boolean ieee_read_id
150 PARAMS ((bfd *, const bfd_byte *, const bfd_byte **, const bfd_byte *,
151 const char **, unsigned long *));
152 static boolean ieee_read_optional_id
153 PARAMS ((bfd *, const bfd_byte *, const bfd_byte **, const bfd_byte *,
154 const char **, unsigned long *, boolean *));
155 static boolean ieee_read_expression
156 PARAMS ((bfd *, const bfd_byte *, const bfd_byte **, const bfd_byte *,
158 static debug_type ieee_builtin_type
159 PARAMS ((PTR, bfd *, struct ieee_types *, const bfd_byte *,
160 const bfd_byte *, unsigned int));
161 static boolean ieee_alloc_type
162 PARAMS ((PTR, struct ieee_types *, unsigned int, boolean));
163 static boolean ieee_read_type_index
164 PARAMS ((PTR, bfd *, struct ieee_types *, const bfd_byte *,
165 const bfd_byte **, const bfd_byte *, debug_type *));
166 static int ieee_regno_to_genreg PARAMS ((bfd *, int));
167 static int ieee_genreg_to_regno PARAMS ((bfd *, int));
168 static boolean parse_ieee_bb
169 PARAMS ((PTR, bfd *, struct ieee_types *, struct ieee_blockstack *,
170 const bfd_byte *, const bfd_byte **, const bfd_byte *));
171 static boolean parse_ieee_be
172 PARAMS ((PTR, bfd *, struct ieee_blockstack *, const bfd_byte *,
173 const bfd_byte **, const bfd_byte *));
174 static boolean parse_ieee_nn
175 PARAMS ((PTR, bfd *, struct ieee_vars *, const bfd_byte *,
176 const bfd_byte **, const bfd_byte *));
177 static boolean parse_ieee_ty
178 PARAMS ((PTR, bfd *, struct ieee_types *, struct ieee_vars *,
179 const bfd_byte *, const bfd_byte **, const bfd_byte *));
180 static boolean parse_ieee_atn
181 PARAMS ((PTR, bfd *, struct ieee_types *, struct ieee_vars *, int,
182 const bfd_byte *, const bfd_byte **, const bfd_byte *));
183 static boolean ieee_require_asn
184 PARAMS ((bfd *, const bfd_byte *, const bfd_byte **, const bfd_byte *,
187 /* Report an error in the IEEE debugging information. */
190 ieee_error (abfd, bytes, p, s)
192 const bfd_byte *bytes;
197 fprintf (stderr, "%s: 0x%lx: %s (0x%x)\n", bfd_get_filename (abfd),
198 (unsigned long) (p - bytes), s, *p);
200 fprintf (stderr, "%s: %s\n", bfd_get_filename (abfd), s);
203 /* Report an unexpected EOF in the IEEE debugging information. */
209 ieee_error (abfd, (const bfd_byte *) NULL, (const bfd_byte *) NULL,
210 "unexpected end of debugging information");
213 /* Save a string in memory. */
216 savestring (start, len)
222 ret = (char *) xmalloc (len + 1);
223 memcpy (ret, start, len);
228 /* Read a number which must be present in an IEEE file. */
231 ieee_read_number (abfd, bytes, pp, pend, pv)
233 const bfd_byte *bytes;
235 const bfd_byte *pend;
238 return ieee_read_optional_number (abfd, bytes, pp, pend, pv,
242 /* Read a number in an IEEE file. If ppresent is not NULL, the number
243 need not be there. */
246 ieee_read_optional_number (abfd, bytes, pp, pend, pv, ppresent)
248 const bfd_byte *bytes;
250 const bfd_byte *pend;
254 ieee_record_enum_type b;
258 if (ppresent != NULL)
267 b = (ieee_record_enum_type) **pp;
270 if (b <= ieee_number_end_enum)
273 if (ppresent != NULL)
278 if (b >= ieee_number_repeat_start_enum && b <= ieee_number_repeat_end_enum)
282 i = (int) b - (int) ieee_number_repeat_start_enum;
283 if (*pp + i - 1 >= pend)
297 if (ppresent != NULL)
303 if (ppresent != NULL)
310 ieee_error (abfd, bytes, *pp - 1, "invalid number");
314 /* Read a required string from an IEEE file. */
317 ieee_read_id (abfd, bytes, pp, pend, pname, pnamlen)
319 const bfd_byte *bytes;
321 const bfd_byte *pend;
323 unsigned long *pnamlen;
325 return ieee_read_optional_id (abfd, bytes, pp, pend, pname, pnamlen,
329 /* Read a string from an IEEE file. If ppresent is not NULL, the
330 string is optional. */
333 ieee_read_optional_id (abfd, bytes, pp, pend, pname, pnamlen, ppresent)
335 const bfd_byte *bytes;
337 const bfd_byte *pend;
339 unsigned long *pnamlen;
356 else if ((ieee_record_enum_type) b == ieee_extension_length_1_enum)
361 else if ((ieee_record_enum_type) b == ieee_extension_length_2_enum)
363 len = (**pp << 8) + (*pp)[1];
368 if (ppresent != NULL)
374 ieee_error (abfd, bytes, *pp - 1, "invalid string length");
378 if ((unsigned long) (pend - *pp) < len)
384 *pname = (const char *) *pp;
388 if (ppresent != NULL)
394 /* Read an expression from an IEEE file. Since this code is only used
395 to parse debugging information, I haven't bothered to write a full
396 blown IEEE expression parser. I've only thrown in the things I've
397 seen in debugging information. This can be easily extended if
401 ieee_read_expression (abfd, bytes, pp, pend, pv)
403 const bfd_byte *bytes;
405 const bfd_byte *pend;
408 const bfd_byte *expr_start;
409 #define EXPR_STACK_SIZE (10)
410 bfd_vma expr_stack[EXPR_STACK_SIZE];
419 const bfd_byte *start;
422 ieee_record_enum_type c;
426 if (! ieee_read_optional_number (abfd, bytes, pp, pend, &val, &present))
431 if (esp - expr_stack >= EXPR_STACK_SIZE)
433 ieee_error (abfd, bytes, start, "expression stack overflow");
440 c = (ieee_record_enum_type) **pp;
442 if (c >= ieee_module_beginning_enum)
453 ieee_error (abfd, bytes, start,
454 "unsupported IEEE expression operator");
457 case ieee_variable_R_enum:
462 if (! ieee_read_number (abfd, bytes, pp, pend, &indx))
464 for (s = abfd->sections; s != NULL; s = s->next)
465 if ((bfd_vma) s->target_index == indx)
469 ieee_error (abfd, bytes, start, "unknown section");
473 if (esp - expr_stack >= EXPR_STACK_SIZE)
475 ieee_error (abfd, bytes, start, "expression stack overflow");
479 *esp++ = bfd_get_section_vma (abfd, s);
483 case ieee_function_plus_enum:
484 case ieee_function_minus_enum:
488 if (esp - expr_stack < 2)
490 ieee_error (abfd, bytes, start, "expression stack underflow");
502 if (esp - 1 != expr_stack)
504 ieee_error (abfd, bytes, expr_start, "expression stack mismatch");
513 /* Return an IEEE builtin type. */
516 ieee_builtin_type (dhandle, abfd, types, bytes, p, indx)
519 struct ieee_types *types;
520 const bfd_byte *bytes;
527 if (indx < BUILTIN_TYPE_COUNT
528 && types->builtins[indx] != DEBUG_TYPE_NULL)
529 return types->builtins[indx];
531 if (indx >= 32 && indx < 64)
533 type = debug_make_pointer_type (dhandle,
534 ieee_builtin_type (dhandle, abfd,
537 assert (indx < BUILTIN_TYPE_COUNT);
538 types->builtins[indx] = type;
542 switch ((enum builtin_types) indx)
545 ieee_error (abfd, bytes, p, "unknown builtin type");
548 case builtin_unknown:
549 type = debug_make_void_type (dhandle);
554 type = debug_make_void_type (dhandle);
558 case builtin_signed_char:
559 type = debug_make_int_type (dhandle, 1, false);
560 name = "signed char";
563 case builtin_unsigned_char:
564 type = debug_make_int_type (dhandle, 1, true);
565 name = "unsigned char";
568 case builtin_signed_short_int:
569 type = debug_make_int_type (dhandle, 2, false);
570 name = "signed short int";
573 case builtin_unsigned_short_int:
574 type = debug_make_int_type (dhandle, 2, true);
575 name = "unsigned short int";
578 case builtin_signed_long:
579 type = debug_make_int_type (dhandle, 4, false);
580 name = "signed long";
583 case builtin_unsigned_long:
584 type = debug_make_int_type (dhandle, 4, true);
585 name = "unsigned long";
588 case builtin_signed_long_long:
589 type = debug_make_int_type (dhandle, 8, false);
590 name = "signed long long";
593 case builtin_unsigned_long_long:
594 type = debug_make_int_type (dhandle, 8, true);
595 name = "unsigned long long";
599 type = debug_make_float_type (dhandle, 4);
604 type = debug_make_float_type (dhandle, 8);
608 case builtin_long_double:
609 /* FIXME: The size for this type should depend upon the
611 type = debug_make_float_type (dhandle, 12);
612 name = "long double";
615 case builtin_long_long_double:
616 type = debug_make_float_type (dhandle, 16);
617 name = "long long double";
620 case builtin_quoted_string:
621 type = debug_make_array_type (dhandle,
622 ieee_builtin_type (dhandle, abfd, types,
626 ieee_builtin_type (dhandle, abfd, types,
631 name = "QUOTED STRING";
634 case builtin_instruction_address:
635 /* FIXME: This should be a code address. */
636 type = debug_make_int_type (dhandle, 4, true);
637 name = "instruction address";
641 /* FIXME: The size for this type should depend upon the
643 type = debug_make_int_type (dhandle, 4, false);
647 case builtin_unsigned:
648 /* FIXME: The size for this type should depend upon the
650 type = debug_make_int_type (dhandle, 4, true);
654 case builtin_unsigned_int:
655 /* FIXME: The size for this type should depend upon the
657 type = debug_make_int_type (dhandle, 4, true);
658 name = "unsigned int";
662 type = debug_make_int_type (dhandle, 1, false);
667 type = debug_make_int_type (dhandle, 4, false);
672 type = debug_make_int_type (dhandle, 2, false);
676 case builtin_unsigned_short:
677 type = debug_make_int_type (dhandle, 2, true);
678 name = "unsigned short";
681 case builtin_short_int:
682 type = debug_make_int_type (dhandle, 2, false);
686 case builtin_signed_short:
687 type = debug_make_int_type (dhandle, 2, false);
688 name = "signed short";
691 case builtin_bcd_float:
692 ieee_error (abfd, bytes, p, "BCD float type not supported");
697 type = debug_name_type (dhandle, name, type);
699 assert (indx < BUILTIN_TYPE_COUNT);
701 types->builtins[indx] = type;
706 /* Allocate more space in the type table. If ref is true, this is a
707 reference to the type; if it is not already defined, we should set
708 up an indirect type. */
711 ieee_alloc_type (dhandle, types, indx, ref)
713 struct ieee_types *types;
718 register struct ieee_type *t;
719 struct ieee_type *tend;
721 if (indx >= types->alloc)
723 nalloc = types->alloc;
726 while (indx >= nalloc)
729 types->types = ((struct ieee_type *)
730 xrealloc (types->types, nalloc * sizeof *types->types));
732 memset (types->types + types->alloc, 0,
733 (nalloc - types->alloc) * sizeof *types->types);
735 tend = types->types + nalloc;
736 for (t = types->types + types->alloc; t < tend; t++)
738 t->type = DEBUG_TYPE_NULL;
739 t->return_type = DEBUG_TYPE_NULL;
742 types->alloc = nalloc;
747 t = types->types + indx;
750 t->pslot = (debug_type *) xmalloc (sizeof *t->pslot);
751 *t->pslot = DEBUG_TYPE_NULL;
752 t->type = debug_make_indirect_type (dhandle, t->pslot,
753 (const char *) NULL);
762 /* Read a type index and return the corresponding type. */
765 ieee_read_type_index (dhandle, abfd, types, bytes, pp, pend, ptype)
768 struct ieee_types *types;
769 const bfd_byte *bytes;
771 const bfd_byte *pend;
774 const bfd_byte *start;
779 if (! ieee_read_number (abfd, bytes, pp, pend, &indx))
784 *ptype = ieee_builtin_type (dhandle, abfd, types, bytes, start, indx);
791 if (! ieee_alloc_type (dhandle, types, indx, true))
794 *ptype = types->types[indx].type;
799 /* Parse IEEE debugging information for a file. This is passed the
800 bytes which compose the Debug Information Part of an IEEE file. */
803 parse_ieee (dhandle, abfd, bytes, len)
806 const bfd_byte *bytes;
809 struct ieee_blockstack blockstack;
810 struct ieee_vars vars;
811 struct ieee_types types;
813 const bfd_byte *p, *pend;
815 blockstack.bsp = blockstack.stack;
820 for (i = 0; i < BUILTIN_TYPE_COUNT; i++)
821 types.builtins[i] = DEBUG_TYPE_NULL;
827 const bfd_byte *record_start;
828 ieee_record_enum_type c;
832 c = (ieee_record_enum_type) *p++;
834 if (c == ieee_at_record_enum)
835 c = (ieee_record_enum_type) (((unsigned int) c << 8) | *p++);
837 if (c <= ieee_number_repeat_end_enum)
839 ieee_error (abfd, bytes, record_start, "unexpected number");
846 ieee_error (abfd, bytes, record_start, "unexpected record type");
849 case ieee_bb_record_enum:
850 if (! parse_ieee_bb (dhandle, abfd, &types, &blockstack, bytes,
855 case ieee_be_record_enum:
856 if (! parse_ieee_be (dhandle, abfd, &blockstack, bytes, &p, pend))
861 if (! parse_ieee_nn (dhandle, abfd, &vars, bytes, &p, pend))
865 case ieee_ty_record_enum:
866 if (! parse_ieee_ty (dhandle, abfd, &types, &vars, bytes, &p, pend))
870 case ieee_atn_record_enum:
871 if (! parse_ieee_atn (dhandle, abfd, &types, &vars,
872 (blockstack.bsp <= blockstack.stack
874 : blockstack.bsp[-1].kind),
881 if (blockstack.bsp != blockstack.stack)
883 ieee_error (abfd, (const bfd_byte *) NULL, (const bfd_byte *) NULL,
884 "blocks left on stack at end");
891 /* Handle an IEEE BB record. */
894 parse_ieee_bb (dhandle, abfd, types, blockstack, bytes, pp, pend)
897 struct ieee_types *types;
898 struct ieee_blockstack *blockstack;
899 const bfd_byte *bytes;
901 const bfd_byte *pend;
903 const bfd_byte *block_start;
907 unsigned long namlen;
915 if (! ieee_read_number (abfd, bytes, pp, pend, &size)
916 || ! ieee_read_id (abfd, bytes, pp, pend, &name, &namlen))
922 /* BB1: Type definitions local to a module. */
923 namcopy = savestring (name, namlen);
926 if (! debug_set_filename (dhandle, namcopy))
931 /* BB2: Global type definitions. The name is supposed to be
932 empty, but we don't check. */
933 if (! debug_set_filename (dhandle, "*global*"))
938 /* BB3: High level module block begin. We don't have to do
939 anything here. The name is supposed to be the same as for
940 the BB1, but we don't check. */
944 /* BB4: Global function. */
946 bfd_vma stackspace, typindx, offset;
947 debug_type return_type;
949 if (! ieee_read_number (abfd, bytes, pp, pend, &stackspace)
950 || ! ieee_read_number (abfd, bytes, pp, pend, &typindx)
951 || ! ieee_read_expression (abfd, bytes, pp, pend, &offset))
954 /* We have no way to record the stack space. FIXME. */
958 return_type = ieee_builtin_type (dhandle, abfd, types, bytes,
959 block_start, typindx);
960 if (return_type == NULL)
966 if (! ieee_alloc_type (dhandle, types, typindx, true))
968 return_type = types->types[typindx].return_type;
969 if (return_type == NULL)
970 return_type = types->types[typindx].type;
973 namcopy = savestring (name, namlen);
976 if (! debug_record_function (dhandle, namcopy, return_type,
983 /* BB5: File name for source line numbers. */
987 /* We ignore the date and time. FIXME. */
988 for (i = 0; i < 6; i++)
993 if (! ieee_read_optional_number (abfd, bytes, pp, pend, &ignore,
1000 namcopy = savestring (name, namlen);
1001 if (namcopy == NULL)
1003 if (! debug_start_source (dhandle, namcopy))
1009 /* BB6: Local function or block. */
1011 bfd_vma stackspace, typindx, offset;
1013 if (! ieee_read_number (abfd, bytes, pp, pend, &stackspace)
1014 || ! ieee_read_number (abfd, bytes, pp, pend, &typindx)
1015 || ! ieee_read_expression (abfd, bytes, pp, pend, &offset))
1018 /* We have no way to record the stack space. FIXME. */
1022 if (! debug_start_block (dhandle, offset))
1024 /* Change b to indicate that this is a block
1025 rather than a function. */
1030 debug_type return_type;
1034 return_type = ieee_builtin_type (dhandle, abfd, types, bytes,
1035 block_start, typindx);
1036 if (return_type == NULL)
1042 if (! ieee_alloc_type (dhandle, types, typindx, true))
1044 return_type = types->types[typindx].return_type;
1045 if (return_type == NULL)
1046 return_type = types->types[typindx].type;
1049 namcopy = savestring (name, namlen);
1050 if (namcopy == NULL)
1052 if (! debug_record_function (dhandle, namcopy, return_type,
1060 /* BB10: Assembler module scope. We completely ignore all this
1061 information. FIXME. */
1063 const char *inam, *vstr;
1064 unsigned long inamlen, vstrlen;
1069 if (! ieee_read_id (abfd, bytes, pp, pend, &inam, &inamlen)
1070 || ! ieee_read_number (abfd, bytes, pp, pend, &tool_type)
1071 || ! ieee_read_optional_id (abfd, bytes, pp, pend, &vstr, &vstrlen,
1074 for (i = 0; i < 6; i++)
1078 if (! ieee_read_optional_number (abfd, bytes, pp, pend, &ignore,
1088 /* BB11: Module section. We completely ignore all this
1089 information. FIXME. */
1091 bfd_vma sectype, secindx, offset, map;
1094 if (! ieee_read_number (abfd, bytes, pp, pend, §ype)
1095 || ! ieee_read_number (abfd, bytes, pp, pend, &secindx)
1096 || ! ieee_read_expression (abfd, bytes, pp, pend, &offset)
1097 || ! ieee_read_optional_number (abfd, bytes, pp, pend, &map,
1104 ieee_error (abfd, bytes, block_start, "unknown BB type");
1109 /* Push this block on the block stack. */
1111 if (blockstack->bsp >= blockstack->stack + BLOCKSTACK_SIZE)
1113 ieee_error (abfd, (const bfd_byte *) NULL, (const bfd_byte *) NULL,
1118 blockstack->bsp->kind = b;
1120 blockstack->bsp->filename = namcopy;
1126 /* Handle an IEEE BE record. */
1129 parse_ieee_be (dhandle, abfd, blockstack, bytes, pp, pend)
1132 struct ieee_blockstack *blockstack;
1133 const bfd_byte *bytes;
1134 const bfd_byte **pp;
1135 const bfd_byte *pend;
1139 if (blockstack->bsp <= blockstack->stack)
1141 ieee_error (abfd, bytes, *pp, "stack underflow");
1146 switch (blockstack->bsp->kind)
1150 if (! ieee_read_expression (abfd, bytes, pp, pend, &offset))
1152 if (! debug_end_function (dhandle, offset))
1157 /* This is BE6 when BB6 started a block rather than a local
1159 if (! ieee_read_expression (abfd, bytes, pp, pend, &offset))
1161 if (! debug_end_block (dhandle, offset))
1166 /* When we end a BB5, we look up the stack for the last BB5, if
1167 there is one, so that we can call debug_start_source. */
1168 if (blockstack->bsp > blockstack->stack)
1170 struct ieee_block *bl;
1172 bl = blockstack->bsp;
1178 if (! debug_start_source (dhandle, bl->filename))
1183 while (bl != blockstack->stack);
1188 if (! ieee_read_expression (abfd, bytes, pp, pend, &offset))
1190 /* We just ignore the module size. FIXME. */
1194 /* Other block types do not have any trailing information. */
1201 /* Parse an NN record. */
1204 parse_ieee_nn (dhandle, abfd, vars, bytes, pp, pend)
1207 struct ieee_vars *vars;
1208 const bfd_byte *bytes;
1209 const bfd_byte **pp;
1210 const bfd_byte *pend;
1212 const bfd_byte *nn_start;
1215 unsigned long namlen;
1219 if (! ieee_read_number (abfd, bytes, pp, pend, &varindx)
1220 || ! ieee_read_id (abfd, bytes, pp, pend, &name, &namlen))
1225 ieee_error (abfd, bytes, nn_start, "illegal variable index");
1230 if (varindx >= vars->alloc)
1234 alloc = vars->alloc;
1237 while (varindx >= alloc)
1239 vars->vars = ((struct ieee_var *)
1240 xrealloc (vars->vars, alloc * sizeof *vars->vars));
1241 memset (vars->vars + vars->alloc, 0,
1242 (alloc - vars->alloc) * sizeof *vars->vars);
1243 vars->alloc = alloc;
1246 vars->vars[varindx].name = name;
1247 vars->vars[varindx].namlen = namlen;
1252 /* Parse a TY record. */
1255 parse_ieee_ty (dhandle, abfd, types, vars, bytes, pp, pend)
1258 struct ieee_types *types;
1259 struct ieee_vars *vars;
1260 const bfd_byte *bytes;
1261 const bfd_byte **pp;
1262 const bfd_byte *pend;
1264 const bfd_byte *ty_start, *ty_var_start, *ty_code_start;
1265 bfd_vma typeindx, varindx, tc;
1267 boolean tag, typdef;
1268 unsigned long type_bitsize;
1269 debug_type return_type;
1273 if (! ieee_read_number (abfd, bytes, pp, pend, &typeindx))
1278 ieee_error (abfd, bytes, ty_start, "illegal type index");
1283 if (! ieee_alloc_type (dhandle, types, typeindx, false))
1288 ieee_error (abfd, bytes, *pp, "unknown TY code");
1295 if (! ieee_read_number (abfd, bytes, pp, pend, &varindx))
1300 ieee_error (abfd, bytes, ty_var_start, "illegal variable index");
1305 if (varindx >= vars->alloc || vars->vars[varindx].name == NULL)
1307 ieee_error (abfd, bytes, ty_var_start, "undefined variable in TY");
1311 ty_code_start = *pp;
1313 if (! ieee_read_number (abfd, bytes, pp, pend, &tc))
1319 return_type = DEBUG_TYPE_NULL;
1323 ieee_error (abfd, bytes, ty_code_start, "unknown TY code");
1327 /* Unknown type, with size. We treat it as int. FIXME. */
1331 if (! ieee_read_number (abfd, bytes, pp, pend, &size))
1333 type = debug_make_int_type (dhandle, size, false);
1337 case 'A': /* Array. */
1338 case 'a': /* FORTRAN array in column/row order. FIXME: Not
1339 distinguished from normal array. */
1341 debug_type ele_type;
1342 bfd_vma lower, upper;
1344 if (! ieee_read_type_index (dhandle, abfd, types, bytes, pp, pend,
1346 || ! ieee_read_number (abfd, bytes, pp, pend, &lower)
1347 || ! ieee_read_number (abfd, bytes, pp, pend, &upper))
1349 type = debug_make_array_type (dhandle, ele_type,
1350 ieee_builtin_type (dhandle, abfd, types,
1351 bytes, ty_code_start,
1354 (bfd_signed_vma) lower,
1355 (bfd_signed_vma) upper,
1361 /* Simple enumeration. */
1367 bfd_signed_vma *vals;
1370 if (! ieee_read_number (abfd, bytes, pp, pend, &size))
1372 /* FIXME: we ignore the enumeration size. */
1375 names = (const char **) xmalloc (alloc * sizeof *names);
1376 memset (names, 0, alloc * sizeof *names);
1381 unsigned long namlen;
1384 if (! ieee_read_optional_id (abfd, bytes, pp, pend, &name,
1393 names = ((const char **)
1394 xrealloc (names, alloc * sizeof *names));
1397 names[c] = savestring (name, namlen);
1398 if (names[c] == NULL)
1405 vals = (bfd_signed_vma *) xmalloc (c * sizeof *vals);
1406 for (i = 0; i < c; i++)
1409 type = debug_make_enum_type (dhandle, names, vals);
1415 /* Struct with bit fields. */
1419 debug_field *fields;
1422 if (! ieee_read_number (abfd, bytes, pp, pend, &size))
1426 fields = (debug_field *) xmalloc (alloc * sizeof *fields);
1431 unsigned long namlen;
1434 bfd_vma bitpos, bitsize;
1436 if (! ieee_read_optional_id (abfd, bytes, pp, pend, &name,
1441 if (! ieee_read_type_index (dhandle, abfd, types, bytes, pp, pend,
1443 || ! ieee_read_number (abfd, bytes, pp, pend, &bitpos)
1444 || ! ieee_read_number (abfd, bytes, pp, pend, &bitsize))
1450 fields = ((debug_field *)
1451 xrealloc (fields, alloc * sizeof *fields));
1454 fields[c] = debug_make_field (dhandle, savestring (name, namlen),
1455 ftype, bitpos, bitsize,
1456 DEBUG_VISIBILITY_PUBLIC);
1457 if (fields[c] == NULL)
1464 type = debug_make_struct_type (dhandle, true, size, fields);
1474 bfd_signed_vma *vals;
1478 names = (const char **) xmalloc (alloc * sizeof *names);
1479 vals = (bfd_signed_vma *) xmalloc (alloc * sizeof *names);
1484 unsigned long namlen;
1488 if (! ieee_read_optional_id (abfd, bytes, pp, pend, &name,
1493 if (! ieee_read_number (abfd, bytes, pp, pend, &val))
1496 /* If the length of the name is zero, then the value is
1497 actually the size of the enum. We ignore this
1498 information. FIXME. */
1505 names = ((const char **)
1506 xrealloc (names, alloc * sizeof *names));
1507 vals = ((bfd_signed_vma *)
1508 xrealloc (vals, alloc * sizeof *vals));
1511 names[c] = savestring (name, namlen);
1512 if (names[c] == NULL)
1514 vals[c] = (bfd_signed_vma) val;
1520 type = debug_make_enum_type (dhandle, names, vals);
1525 case 'O': /* Small pointer. We don't distinguish small and large
1527 case 'P': /* Large pointer. */
1531 if (! ieee_read_type_index (dhandle, abfd, types, bytes, pp, pend, &t))
1533 type = debug_make_pointer_type (dhandle, t);
1540 bfd_vma low, high, signedp, size;
1542 if (! ieee_read_number (abfd, bytes, pp, pend, &low)
1543 || ! ieee_read_number (abfd, bytes, pp, pend, &high)
1544 || ! ieee_read_number (abfd, bytes, pp, pend, &signedp)
1545 || ! ieee_read_number (abfd, bytes, pp, pend, &size))
1548 type = debug_make_range_type (dhandle,
1549 debug_make_int_type (dhandle, size,
1551 (bfd_signed_vma) low,
1552 (bfd_signed_vma) high);
1556 case 'S': /* Struct. */
1557 case 'U': /* Union. */
1561 debug_field *fields;
1564 if (! ieee_read_number (abfd, bytes, pp, pend, &size))
1568 fields = (debug_field *) xmalloc (alloc * sizeof *fields);
1573 unsigned long namlen;
1580 if (! ieee_read_optional_id (abfd, bytes, pp, pend, &name,
1585 if (! ieee_read_number (abfd, bytes, pp, pend, &tindx)
1586 || ! ieee_read_number (abfd, bytes, pp, pend, &offset))
1591 ftype = ieee_builtin_type (dhandle, abfd, types, bytes,
1592 ty_code_start, tindx);
1598 struct ieee_type *t;
1601 if (! ieee_alloc_type (dhandle, types, tindx, true))
1603 t = types->types + tindx;
1605 bitsize = t->bitsize;
1613 fields = ((debug_field *)
1614 xrealloc (fields, alloc * sizeof *fields));
1617 fields[c] = debug_make_field (dhandle, savestring (name, namlen),
1618 ftype, offset, bitsize,
1619 DEBUG_VISIBILITY_PUBLIC);
1620 if (fields[c] == NULL)
1627 type = debug_make_struct_type (dhandle, tc == 'S', size, fields);
1634 if (! ieee_read_type_index (dhandle, abfd, types, bytes, pp, pend,
1641 /* Procedure. FIXME: This is an extern declaration, which we
1642 have no way of representing. */
1649 /* FIXME: We ignore the attribute and the argument names. */
1651 if (! ieee_read_number (abfd, bytes, pp, pend, &attr)
1652 || ! ieee_read_type_index (dhandle, abfd, types, bytes, pp, pend,
1654 || ! ieee_read_number (abfd, bytes, pp, pend, &nargs))
1659 unsigned long namlen;
1661 if (! ieee_read_optional_id (abfd, bytes, pp, pend, &name,
1667 type = debug_make_function_type (dhandle, rtype);
1668 return_type = rtype;
1673 /* Array with 0 lower bound. */
1678 if (! ieee_read_type_index (dhandle, abfd, types, bytes, pp, pend,
1680 || ! ieee_read_number (abfd, bytes, pp, pend, &high))
1683 type = debug_make_array_type (dhandle, etype,
1684 ieee_builtin_type (dhandle, abfd, types,
1685 bytes, ty_code_start,
1688 0, (bfd_signed_vma) high, false);
1692 case 'c': /* Complex. */
1693 case 'd': /* Double complex. */
1696 unsigned long namlen;
1698 /* FIXME: I don't know what the name means. */
1700 if (! ieee_read_id (abfd, bytes, pp, pend, &name, &namlen))
1703 type = debug_make_complex_type (dhandle, tc == 'c' ? 4 : 8);
1708 /* Pascal file name. FIXME. */
1709 ieee_error (abfd, bytes, ty_code_start,
1710 "Pascal file name not supported");
1714 /* Bitfield type. */
1716 bfd_vma signedp, bitsize;
1718 if (! ieee_read_number (abfd, bytes, pp, pend, &signedp)
1719 || ! ieee_read_number (abfd, bytes, pp, pend, &bitsize)
1720 || ! ieee_read_type_index (dhandle, abfd, types, bytes, pp, pend,
1724 /* FIXME: This is just a guess. */
1726 type = debug_make_int_type (dhandle, 4, true);
1727 type_bitsize = bitsize;
1737 if (! ieee_read_number (abfd, bytes, pp, pend, &kind)
1738 || ! ieee_read_type_index (dhandle, abfd, types, bytes, pp, pend,
1745 ieee_error (abfd, bytes, ty_start, "unsupported qualifer");
1749 type = debug_make_const_type (dhandle, t);
1753 type = debug_make_volatile_type (dhandle, t);
1765 if (! ieee_read_number (abfd, bytes, pp, pend, &size)
1766 || ! ieee_read_type_index (dhandle, abfd, types, bytes, pp, pend,
1770 /* FIXME: We ignore the size. */
1772 type = debug_make_set_type (dhandle, etype, false);
1777 /* Procedure with compiler dependencies. FIXME: This is an
1778 extern declaration, which we have no way of representing. */
1780 bfd_vma attr, frame_type, push_mask, nargs, level, father;
1784 /* FIXME: We ignore almost all this information. */
1786 if (! ieee_read_number (abfd, bytes, pp, pend, &attr)
1787 || ! ieee_read_number (abfd, bytes, pp, pend, &frame_type)
1788 || ! ieee_read_number (abfd, bytes, pp, pend, &push_mask)
1789 || ! ieee_read_type_index (dhandle, abfd, types, bytes, pp, pend,
1791 || ! ieee_read_number (abfd, bytes, pp, pend, &nargs))
1793 if (nargs != (bfd_vma) -1)
1795 for (; nargs > 0; nargs--)
1799 if (! ieee_read_type_index (dhandle, abfd, types, bytes, pp,
1804 if (! ieee_read_number (abfd, bytes, pp, pend, &level)
1805 || ! ieee_read_optional_number (abfd, bytes, pp, pend, &father,
1809 type = debug_make_function_type (dhandle, rtype);
1810 return_type = rtype;
1815 /* Record the type in the table. If the corresponding NN record has
1816 a name, name it. FIXME: Is this always correct? */
1822 && vars->vars[varindx].namlen > 0)
1826 name = savestring (vars->vars[varindx].name,
1827 vars->vars[varindx].namlen);
1829 type = debug_tag_type (dhandle, name, type);
1831 type = debug_name_type (dhandle, name, type);
1836 types->types[typeindx].type = type;
1837 types->types[typeindx].bitsize = type_bitsize;
1838 types->types[typeindx].return_type = return_type;
1840 /* We may have already allocated type as an indirect type pointing
1841 to slot. It does no harm to replace the indirect type with the
1842 real type. Filling in slot as well handles the indirect types
1843 which are already hanging around. */
1844 if (types->types[typeindx].pslot != NULL)
1845 *types->types[typeindx].pslot = type;
1850 /* Parse an ATN record. */
1853 parse_ieee_atn (dhandle, abfd, types, vars, blocktype, bytes, pp, pend)
1856 struct ieee_types *types;
1857 struct ieee_vars *vars;
1859 const bfd_byte *bytes;
1860 const bfd_byte **pp;
1861 const bfd_byte *pend;
1863 const bfd_byte *atn_start, *atn_code_start;
1868 bfd_vma v, v2, v3, v4, v5;
1870 unsigned long namlen;
1876 if (! ieee_read_number (abfd, bytes, pp, pend, &varindx)
1877 || ! ieee_read_type_index (dhandle, abfd, types, bytes, pp, pend, &type))
1880 atn_code_start = *pp;
1882 if (! ieee_read_number (abfd, bytes, pp, pend, &atn_code))
1891 else if (varindx < 32)
1893 ieee_error (abfd, bytes, atn_start, "illegal variable index");
1900 if (varindx >= vars->alloc || vars->vars[varindx].name == NULL)
1902 ieee_error (abfd, bytes, atn_start, "undefined variable in ATN");
1906 vars->vars[varindx].type = type;
1908 name = vars->vars[varindx].name;
1909 namlen = vars->vars[varindx].namlen;
1915 ieee_error (abfd, bytes, atn_code_start, "unknown ATN type");
1919 /* Automatic variable. */
1920 if (! ieee_read_number (abfd, bytes, pp, pend, &v))
1922 namcopy = savestring (name, namlen);
1924 type = debug_make_void_type (dhandle);
1925 return debug_record_variable (dhandle, namcopy, type, DEBUG_LOCAL, v);
1928 /* Register variable. */
1929 if (! ieee_read_number (abfd, bytes, pp, pend, &v))
1931 namcopy = savestring (name, namlen);
1933 type = debug_make_void_type (dhandle);
1934 return debug_record_variable (dhandle, namcopy, type, DEBUG_REGISTER,
1935 ieee_regno_to_genreg (abfd, v));
1938 /* Static variable. */
1939 if (! ieee_require_asn (abfd, bytes, pp, pend, &v))
1941 namcopy = savestring (name, namlen);
1943 type = debug_make_void_type (dhandle);
1944 return debug_record_variable (dhandle, namcopy, type,
1945 (blocktype == 4 || blocktype == 6
1946 ? DEBUG_LOCAL_STATIC
1951 /* External function. We don't currently record these. FIXME. */
1955 /* External variable. We don't currently record these. FIXME. */
1959 if (! ieee_read_number (abfd, bytes, pp, pend, &v)
1960 || ! ieee_read_number (abfd, bytes, pp, pend, &v2)
1961 || ! ieee_read_optional_number (abfd, bytes, pp, pend, &v3,
1966 if (! ieee_read_optional_number (abfd, bytes, pp, pend, &v4,
1971 /* We just ignore the two optional fields in v3 and v4, since
1972 they are not defined. */
1974 if (! ieee_require_asn (abfd, bytes, pp, pend, &v3))
1977 /* We have no way to record the column number. FIXME. */
1979 return debug_record_line (dhandle, v, v3);
1982 /* Global variable. */
1983 if (! ieee_require_asn (abfd, bytes, pp, pend, &v))
1985 namcopy = savestring (name, namlen);
1987 type = debug_make_void_type (dhandle);
1988 return debug_record_variable (dhandle, namcopy, type, DEBUG_GLOBAL, v);
1991 /* Variable lifetime information. */
1992 if (! ieee_read_number (abfd, bytes, pp, pend, &v))
1995 /* We have no way to record this information. FIXME. */
1999 /* Locked register. */
2000 if (! ieee_read_number (abfd, bytes, pp, pend, &v)
2001 || ! ieee_read_number (abfd, bytes, pp, pend, &v2))
2004 /* I think this means a variable that is both in a register and
2005 a frame slot. We ignore the frame slot. FIXME. */
2007 namcopy = savestring (name, namlen);
2009 type = debug_make_void_type (dhandle);
2010 return debug_record_variable (dhandle, namcopy, type, DEBUG_REGISTER, v);
2013 /* Reserved for FORTRAN common. */
2014 ieee_error (abfd, bytes, atn_code_start, "unsupported ATN11");
2016 /* Return true to keep going. */
2020 /* Based variable. */
2024 if (! ieee_read_number (abfd, bytes, pp, pend, &v)
2025 || ! ieee_read_number (abfd, bytes, pp, pend, &v2)
2026 || ! ieee_read_optional_number (abfd, bytes, pp, pend, &v3,
2031 if (! ieee_read_optional_number (abfd, bytes, pp, pend, &v4,
2036 if (! ieee_read_optional_number (abfd, bytes, pp, pend, &v5,
2042 /* We have no way to record this information. FIXME. */
2044 ieee_error (abfd, bytes, atn_code_start, "unsupported ATN12");
2046 /* Return true to keep going. */
2050 /* Constant. The description of this that I have is ambiguous,
2051 so I'm not going to try to implement it. */
2052 ieee_error (abfd, bytes, atn_code_start, "unsupported ATN16");
2056 /* Static variable from assembler. */
2058 if (! ieee_read_number (abfd, bytes, pp, pend, &v)
2059 || ! ieee_read_optional_number (abfd, bytes, pp, pend, &v2,
2061 || ! ieee_require_asn (abfd, bytes, pp, pend, &v3))
2063 namcopy = savestring (name, namlen);
2064 /* We don't really handle this correctly. FIXME. */
2065 return debug_record_variable (dhandle, namcopy,
2066 debug_make_void_type (dhandle),
2067 v2 != 0 ? DEBUG_GLOBAL : DEBUG_STATIC,
2071 /* Procedure miscellaneous information. */
2073 /* Variable miscellaneous information. */
2075 /* Module miscellaneous information. */
2076 if (! ieee_read_number (abfd, bytes, pp, pend, &v)
2077 || ! ieee_read_number (abfd, bytes, pp, pend, &v2)
2078 || ! ieee_read_optional_id (abfd, bytes, pp, pend, &name, &namlen,
2082 /* We just ignore all of this stuff. FIXME. */
2084 for (; v2 > 0; --v2)
2086 ieee_record_enum_type c;
2089 unsigned long strlen;
2091 c = (ieee_record_enum_type) **pp;
2093 if (c != ieee_at_record_enum
2094 && c != ieee_e2_first_byte_enum)
2096 ieee_error (abfd, bytes, *pp - 1, "bad misc record");
2100 c = (ieee_record_enum_type) (((unsigned int) c << 8) | **pp);
2105 ieee_error (abfd, bytes, *pp - 2, "bad misc record");
2108 case ieee_atn_record_enum:
2109 if (! ieee_read_number (abfd, bytes, pp, pend, &vindx))
2111 if ((*pp)[0] != 0 || (*pp)[1] != 65)
2113 ieee_error (abfd, bytes, *pp, "bad atn in misc");
2117 if (! ieee_read_id (abfd, bytes, pp, pend, &str, &strlen))
2121 case ieee_asn_record_enum:
2122 if (! ieee_read_number (abfd, bytes, pp, pend, &vindx)
2123 || ! ieee_read_expression (abfd, bytes, pp, pend, &v3))
2135 /* Require an ASN record. */
2138 ieee_require_asn (abfd, bytes, pp, pend, pv)
2140 const bfd_byte *bytes;
2141 const bfd_byte **pp;
2142 const bfd_byte *pend;
2145 const bfd_byte *start;
2146 ieee_record_enum_type c;
2151 c = (ieee_record_enum_type) **pp;
2152 if (c != ieee_e2_first_byte_enum)
2154 ieee_error (abfd, bytes, start, "missing required ASN");
2159 c = (ieee_record_enum_type) (((unsigned int) c << 8) | **pp);
2160 if (c != ieee_asn_record_enum)
2162 ieee_error (abfd, bytes, start, "missing required ASN");
2167 /* Just ignore the variable index. */
2168 if (! ieee_read_number (abfd, bytes, pp, pend, &varindx))
2171 return ieee_read_expression (abfd, bytes, pp, pend, pv);
2174 /* Convert a register number in IEEE debugging information into a
2175 generic register number. */
2178 ieee_regno_to_genreg (abfd, r)
2185 /* Convert a generic register number to an IEEE specific one. */
2188 ieee_genreg_to_regno (abfd, r)
2195 /* These routines build IEEE debugging information out of the generic
2196 debugging information. */
2198 /* We build the IEEE debugging information byte by byte. Rather than
2199 waste time copying data around, we use a linked list of buffers to
2202 #define IEEE_BUFSIZE (490)
2207 struct ieee_buf *next;
2208 /* Number of data bytes in this buffer. */
2211 bfd_byte buf[IEEE_BUFSIZE];
2214 /* In order to generate the BB11 blocks required by the HP emulator,
2215 we keep track of ranges of addresses which correspond to a given
2216 compilation unit. */
2221 struct ieee_range *next;
2228 /* This is how we store types for the writing routines. Most types
2229 are simply represented by a type index. */
2231 struct ieee_write_type
2235 /* The size of the type, if known. */
2237 /* If this is a struct, this is where the struct definition is
2239 struct ieee_buf *strdef;
2240 /* Whether the type is unsigned. */
2241 unsigned int unsignedp : 1;
2242 /* Whether this is a reference type. */
2243 unsigned int referencep : 1;
2246 /* This is the type stack used by the debug writing routines. FIXME:
2247 We could generate more efficient output if we remembered when we
2248 have output a particular type before. */
2250 struct ieee_type_stack
2252 /* Next entry on stack. */
2253 struct ieee_type_stack *next;
2254 /* Type information. */
2255 struct ieee_write_type type;
2258 /* This is a list of associations between names and types. This could
2259 be more efficiently implemented as a hash table. */
2261 struct ieee_name_type
2263 /* Next name/type assocation. */
2264 struct ieee_name_type *next;
2268 struct ieee_write_type type;
2269 /* If this is a tag which has not yet been defined, this is the
2270 kind. If the tag has been defined, this is DEBUG_KIND_ILLEGAL. */
2271 enum debug_type_kind kind;
2274 /* This is a list of pending function parameter information. We don't
2275 output them until we see the first block. */
2277 struct ieee_pending_parm
2279 /* Next pending parameter. */
2280 struct ieee_pending_parm *next;
2286 enum debug_parm_kind kind;
2291 /* This is the handle passed down by debug_write. */
2295 /* BFD we are writing to. */
2297 /* Current data buffer. */
2298 struct ieee_buf *current;
2299 /* Filename of current compilation unit. */
2300 const char *filename;
2301 /* Module name of current compilation unit. */
2302 const char *modname;
2303 /* List of finished data buffers. */
2304 struct ieee_buf *data;
2305 /* List of buffers for typedefs in the current compilation unit. */
2306 struct ieee_buf *types;
2307 /* List of buffers for variables and functions in the current
2308 compilation unit. */
2309 struct ieee_buf *vars;
2310 /* List of buffers for line numbers in the current compilation unit. */
2311 struct ieee_buf *linenos;
2312 /* Ranges for the current compilation unit. */
2313 struct ieee_range *ranges;
2314 /* Nested pending ranges. */
2315 struct ieee_range *pending_ranges;
2317 struct ieee_type_stack *type_stack;
2318 /* Next unallocated type index. */
2319 unsigned int type_indx;
2320 /* Next unallocated name index. */
2321 unsigned int name_indx;
2323 struct ieee_name_type *typedefs;
2325 struct ieee_name_type *tags;
2326 /* The depth of block nesting. This is 0 outside a function, and 1
2327 just after start_function is called. */
2328 unsigned int block_depth;
2329 /* Pending function parameters. */
2330 struct ieee_pending_parm *pending_parms;
2331 /* Current line number filename. */
2332 const char *lineno_filename;
2333 /* Line number name index. */
2334 unsigned int lineno_name_indx;
2337 static boolean ieee_change_buffer
2338 PARAMS ((struct ieee_handle *, struct ieee_buf **));
2339 static boolean ieee_push_type
2340 PARAMS ((struct ieee_handle *, unsigned int, unsigned int, boolean));
2341 static unsigned int ieee_pop_type PARAMS ((struct ieee_handle *));
2342 static boolean ieee_add_range
2343 PARAMS ((struct ieee_handle *, bfd_vma, bfd_vma));
2344 static boolean ieee_start_range PARAMS ((struct ieee_handle *, bfd_vma));
2345 static boolean ieee_end_range PARAMS ((struct ieee_handle *, bfd_vma));
2346 static boolean ieee_real_write_byte PARAMS ((struct ieee_handle *, int));
2347 static boolean ieee_write_2bytes PARAMS ((struct ieee_handle *, int));
2348 static boolean ieee_write_number PARAMS ((struct ieee_handle *, bfd_vma));
2349 static boolean ieee_write_id PARAMS ((struct ieee_handle *, const char *));
2350 static boolean ieee_define_type
2351 PARAMS ((struct ieee_handle *, unsigned int, boolean));
2352 static boolean ieee_define_named_type
2353 PARAMS ((struct ieee_handle *, const char *, boolean, unsigned int, boolean,
2354 struct ieee_buf **));
2355 static boolean ieee_finish_compilation_unit PARAMS ((struct ieee_handle *));
2356 static boolean ieee_output_pending_parms PARAMS ((struct ieee_handle *));
2358 static boolean ieee_start_compilation_unit PARAMS ((PTR, const char *));
2359 static boolean ieee_start_source PARAMS ((PTR, const char *));
2360 static boolean ieee_ellipsis_type PARAMS ((PTR));
2361 static boolean ieee_empty_type PARAMS ((PTR));
2362 static boolean ieee_void_type PARAMS ((PTR));
2363 static boolean ieee_int_type PARAMS ((PTR, unsigned int, boolean));
2364 static boolean ieee_float_type PARAMS ((PTR, unsigned int));
2365 static boolean ieee_complex_type PARAMS ((PTR, unsigned int));
2366 static boolean ieee_bool_type PARAMS ((PTR, unsigned int));
2367 static boolean ieee_enum_type
2368 PARAMS ((PTR, const char *, const char **, bfd_signed_vma *));
2369 static boolean ieee_pointer_type PARAMS ((PTR));
2370 static boolean ieee_function_type PARAMS ((PTR));
2371 static boolean ieee_reference_type PARAMS ((PTR));
2372 static boolean ieee_range_type PARAMS ((PTR, bfd_signed_vma, bfd_signed_vma));
2373 static boolean ieee_array_type
2374 PARAMS ((PTR, bfd_signed_vma, bfd_signed_vma, boolean));
2375 static boolean ieee_set_type PARAMS ((PTR, boolean));
2376 static boolean ieee_offset_type PARAMS ((PTR));
2377 static boolean ieee_method_type PARAMS ((PTR, boolean, int));
2378 static boolean ieee_const_type PARAMS ((PTR));
2379 static boolean ieee_volatile_type PARAMS ((PTR));
2380 static boolean ieee_start_struct_type
2381 PARAMS ((PTR, const char *, unsigned int, boolean, unsigned int));
2382 static boolean ieee_struct_field
2383 PARAMS ((PTR, const char *, bfd_vma, bfd_vma, enum debug_visibility));
2384 static boolean ieee_end_struct_type PARAMS ((PTR));
2385 static boolean ieee_start_class_type
2386 PARAMS ((PTR, const char *, unsigned int, boolean, unsigned int, boolean,
2388 static boolean ieee_class_static_member
2389 PARAMS ((PTR, const char *, const char *, enum debug_visibility));
2390 static boolean ieee_class_baseclass
2391 PARAMS ((PTR, bfd_vma, boolean, enum debug_visibility));
2392 static boolean ieee_class_start_method PARAMS ((PTR, const char *));
2393 static boolean ieee_class_method_variant
2394 PARAMS ((PTR, const char *, enum debug_visibility, boolean, boolean,
2396 static boolean ieee_class_static_method_variant
2397 PARAMS ((PTR, const char *, enum debug_visibility, boolean, boolean));
2398 static boolean ieee_class_end_method PARAMS ((PTR));
2399 static boolean ieee_end_class_type PARAMS ((PTR));
2400 static boolean ieee_typedef_type PARAMS ((PTR, const char *));
2401 static boolean ieee_tag_type
2402 PARAMS ((PTR, const char *, unsigned int, enum debug_type_kind));
2403 static boolean ieee_typdef PARAMS ((PTR, const char *));
2404 static boolean ieee_tag PARAMS ((PTR, const char *));
2405 static boolean ieee_int_constant PARAMS ((PTR, const char *, bfd_vma));
2406 static boolean ieee_float_constant PARAMS ((PTR, const char *, double));
2407 static boolean ieee_typed_constant PARAMS ((PTR, const char *, bfd_vma));
2408 static boolean ieee_variable
2409 PARAMS ((PTR, const char *, enum debug_var_kind, bfd_vma));
2410 static boolean ieee_start_function PARAMS ((PTR, const char *, boolean));
2411 static boolean ieee_function_parameter
2412 PARAMS ((PTR, const char *, enum debug_parm_kind, bfd_vma));
2413 static boolean ieee_start_block PARAMS ((PTR, bfd_vma));
2414 static boolean ieee_end_block PARAMS ((PTR, bfd_vma));
2415 static boolean ieee_end_function PARAMS ((PTR));
2416 static boolean ieee_lineno
2417 PARAMS ((PTR, const char *, unsigned long, bfd_vma));
2419 static const struct debug_write_fns ieee_fns =
2421 ieee_start_compilation_unit,
2433 ieee_reference_type,
2441 ieee_start_struct_type,
2443 ieee_end_struct_type,
2444 ieee_start_class_type,
2445 ieee_class_static_member,
2446 ieee_class_baseclass,
2447 ieee_class_start_method,
2448 ieee_class_method_variant,
2449 ieee_class_static_method_variant,
2450 ieee_class_end_method,
2451 ieee_end_class_type,
2457 ieee_float_constant,
2458 ieee_typed_constant,
2460 ieee_start_function,
2461 ieee_function_parameter,
2468 /* Change the current buffer to a specified buffer chain. */
2471 ieee_change_buffer (info, ppbuf)
2472 struct ieee_handle *info;
2473 struct ieee_buf **ppbuf;
2475 struct ieee_buf *buf;
2479 for (buf = *ppbuf; buf->next != NULL; buf = buf->next)
2484 buf = (struct ieee_buf *) xmalloc (sizeof *buf);
2490 info->current = buf;
2494 /* Push a type index onto the type stack. */
2497 ieee_push_type (info, indx, size, unsignedp)
2498 struct ieee_handle *info;
2503 struct ieee_type_stack *ts;
2505 ts = (struct ieee_type_stack *) xmalloc (sizeof *ts);
2506 memset (ts, 0, sizeof *ts);
2508 ts->type.indx = indx;
2509 ts->type.size = size;
2510 ts->type.unsignedp = unsignedp;
2512 ts->next = info->type_stack;
2513 info->type_stack = ts;
2518 /* Pop a type index off the type stack. */
2521 ieee_pop_type (info)
2522 struct ieee_handle *info;
2524 struct ieee_type_stack *ts;
2527 ts = info->type_stack;
2528 assert (ts != NULL);
2529 ret = ts->type.indx;
2530 info->type_stack = ts->next;
2535 /* Add a range of bytes included in the current compilation unit. */
2538 ieee_add_range (info, low, high)
2539 struct ieee_handle *info;
2543 struct ieee_range *r, **pr;
2545 if (low == (bfd_vma) -1 || high == (bfd_vma) -1)
2548 for (r = info->ranges; r != NULL; r = r->next)
2550 if (high >= r->low && low <= r->high)
2552 /* The new range overlaps r. */
2558 while (*pr != NULL && (*pr)->low <= r->high)
2560 struct ieee_range *n;
2562 if ((*pr)->high > r->high)
2563 r->high = (*pr)->high;
2572 r = (struct ieee_range *) xmalloc (sizeof *r);
2573 memset (r, 0, sizeof *r);
2578 /* Store the ranges sorted by address. */
2579 for (pr = &info->ranges; *pr != NULL; pr = &(*pr)->next)
2580 if ((*pr)->next != NULL && (*pr)->next->low > high)
2588 /* Start a new range for which we only have the low address. */
2591 ieee_start_range (info, low)
2592 struct ieee_handle *info;
2595 struct ieee_range *r;
2597 r = (struct ieee_range *) xmalloc (sizeof *r);
2598 memset (r, 0, sizeof *r);
2600 r->next = info->pending_ranges;
2601 info->pending_ranges = r;
2605 /* Finish a range started by ieee_start_range. */
2608 ieee_end_range (info, high)
2609 struct ieee_handle *info;
2612 struct ieee_range *r;
2615 assert (info->pending_ranges != NULL);
2616 r = info->pending_ranges;
2618 info->pending_ranges = r->next;
2620 return ieee_add_range (info, low, high);
2623 /* Write a byte into the buffer. We use a macro for speed and a
2624 function for the complex cases. */
2626 #define ieee_write_byte(info, b) \
2627 ((info)->current->c < IEEE_BUFSIZE \
2628 ? ((info)->current->buf[(info)->current->c++] = (b), true) \
2629 : ieee_real_write_byte ((info), (b)))
2632 ieee_real_write_byte (info, b)
2633 struct ieee_handle *info;
2636 if (info->current->c >= IEEE_BUFSIZE)
2640 n = (struct ieee_buf *) xmalloc (sizeof *n);
2643 info->current->next = n;
2647 info->current->buf[info->current->c] = b;
2653 /* Write out two bytes. */
2656 ieee_write_2bytes (info, i)
2657 struct ieee_handle *info;
2660 return (ieee_write_byte (info, i >> 8)
2661 && ieee_write_byte (info, i & 0xff));
2664 /* Write out an integer. */
2667 ieee_write_number (info, v)
2668 struct ieee_handle *info;
2676 if (v <= (bfd_vma) ieee_number_end_enum)
2677 return ieee_write_byte (info, (int) v);
2688 if (c > (unsigned int) (ieee_number_repeat_end_enum
2689 - ieee_number_repeat_start_enum))
2691 fprintf (stderr, "IEEE numeric overflow: 0x");
2692 fprintf_vma (stderr, v);
2693 fprintf (stderr, "\n");
2697 if (! ieee_write_byte (info, (int) ieee_number_repeat_start_enum + c))
2699 for (; c > 0; --c, ++p)
2701 if (! ieee_write_byte (info, *p))
2708 /* Write out a string. */
2711 ieee_write_id (info, s)
2712 struct ieee_handle *info;
2720 if (! ieee_write_byte (info, len))
2723 else if (len <= 0xff)
2725 if (! ieee_write_byte (info, (int) ieee_extension_length_1_enum)
2726 || ! ieee_write_byte (info, len))
2729 else if (len <= 0xffff)
2731 if (! ieee_write_byte (info, (int) ieee_extension_length_2_enum)
2732 || ! ieee_write_2bytes (info, len))
2737 fprintf (stderr, "IEEE string length overflow: %u\n", len);
2741 for (; *s != '\0'; s++)
2742 if (! ieee_write_byte (info, *s))
2748 /* Start defining a type. */
2751 ieee_define_type (info, size, unsignedp)
2752 struct ieee_handle *info;
2756 return ieee_define_named_type (info, (const char *) NULL, false, size,
2757 unsignedp, (struct ieee_buf **) NULL);
2760 /* Start defining a named type. */
2763 ieee_define_named_type (info, name, tagp, size, unsignedp, ppbuf)
2764 struct ieee_handle *info;
2769 struct ieee_buf **ppbuf;
2771 unsigned int type_indx;
2772 unsigned int name_indx;
2774 if (! tagp || name == NULL || *name == '\0')
2776 type_indx = info->type_indx;
2781 struct ieee_name_type *nt;
2783 /* The name is a tag. If we have already defined the tag, we
2784 must use the existing type index. */
2785 for (nt = info->tags; nt != NULL; nt = nt->next)
2786 if (nt->name[0] == name[0]
2787 && strcmp (nt->name, name) == 0)
2792 nt = (struct ieee_name_type *) xmalloc (sizeof *nt);
2793 memset (nt, 0, sizeof *nt);
2795 nt->next = info->tags;
2797 nt->type.indx = info->type_indx;
2801 nt->type.size = size;
2802 nt->type.unsignedp = unsignedp;
2803 nt->kind = DEBUG_KIND_ILLEGAL;
2805 type_indx = nt->type.indx;
2808 name_indx = info->name_indx;
2814 /* If we were given a buffer, use it; otherwise, use the general
2815 type information, and make sure that the type block is started. */
2818 if (! ieee_change_buffer (info, ppbuf))
2821 else if (info->types != NULL)
2823 if (! ieee_change_buffer (info, &info->types))
2828 if (! ieee_change_buffer (info, &info->types)
2829 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
2830 || ! ieee_write_byte (info, 1)
2831 || ! ieee_write_number (info, 0)
2832 || ! ieee_write_id (info, info->modname))
2836 /* Push the new type on the type stack, write out an NN record, and
2837 write out the start of a TY record. The caller will then finish
2839 return (ieee_push_type (info, type_indx, size, unsignedp)
2840 && ieee_write_byte (info, (int) ieee_nn_record)
2841 && ieee_write_number (info, name_indx)
2842 && ieee_write_id (info, name)
2843 && ieee_write_byte (info, (int) ieee_ty_record_enum)
2844 && ieee_write_number (info, type_indx)
2845 && ieee_write_byte (info, 0xce)
2846 && ieee_write_number (info, name_indx));
2849 /* The general routine to write out IEEE debugging information. */
2852 write_ieee_debugging_info (abfd, dhandle)
2856 struct ieee_handle info;
2857 struct ieee_buf *tags;
2858 struct ieee_name_type *nt;
2863 memset (&info, 0, sizeof info);
2865 info.type_indx = 256;
2866 info.name_indx = 32;
2868 if (! debug_write (dhandle, &ieee_fns, (PTR) &info))
2871 if (info.filename != NULL)
2873 if (! ieee_finish_compilation_unit (&info))
2877 /* Put any undefined tags in the global typedef information. */
2879 for (nt = info.tags; nt != NULL; nt = nt->next)
2881 unsigned int name_indx;
2884 if (nt->kind == DEBUG_KIND_ILLEGAL)
2888 if (! ieee_change_buffer (&info, &tags)
2889 || ! ieee_write_byte (&info, (int) ieee_bb_record_enum)
2890 || ! ieee_write_byte (&info, 2)
2891 || ! ieee_write_number (&info, 0)
2892 || ! ieee_write_id (&info, ""))
2895 name_indx = info.name_indx;
2897 if (! ieee_write_byte (&info, (int) ieee_nn_record)
2898 || ! ieee_write_number (&info, name_indx)
2899 || ! ieee_write_id (&info, nt->name)
2900 || ! ieee_write_byte (&info, (int) ieee_ty_record_enum)
2901 || ! ieee_write_number (&info, nt->type.indx)
2902 || ! ieee_write_byte (&info, 0xce)
2903 || ! ieee_write_number (&info, name_indx))
2910 case DEBUG_KIND_STRUCT:
2911 case DEBUG_KIND_CLASS:
2914 case DEBUG_KIND_UNION:
2915 case DEBUG_KIND_UNION_CLASS:
2918 case DEBUG_KIND_ENUM:
2922 if (! ieee_write_number (&info, code)
2923 || ! ieee_write_number (&info, 0))
2928 struct ieee_buf **pb;
2930 if (! ieee_write_byte (&info, (int) ieee_be_record_enum))
2933 for (pb = &tags; *pb != NULL; pb = &(*pb)->next)
2939 /* Now all the data is in info.data. Write it out to the BFD. We
2940 normally would need to worry about whether all the other sections
2941 are set up yet, but the IEEE backend will handle this particular
2942 case correctly regardless. */
2943 if (info.data == NULL)
2945 /* There is no debugging information. */
2949 s = bfd_make_section (abfd, ".debug");
2951 err = "bfd_make_section";
2954 if (! bfd_set_section_flags (abfd, s, SEC_DEBUGGING | SEC_HAS_CONTENTS))
2955 err = "bfd_set_section_flags";
2962 for (b = info.data; b != NULL; b = b->next)
2964 if (! bfd_set_section_size (abfd, s, size))
2965 err = "bfd_set_section_size";
2972 for (b = info.data; b != NULL; b = b->next)
2974 if (! bfd_set_section_contents (abfd, s, b->buf, offset, b->c))
2976 err = "bfd_set_section_contents";
2985 fprintf (stderr, "%s: %s: %s\n", bfd_get_filename (abfd), err,
2986 bfd_errmsg (bfd_get_error ()));
2993 /* Start writing out information for a compilation unit. */
2996 ieee_start_compilation_unit (p, filename)
2998 const char *filename;
3000 struct ieee_handle *info = (struct ieee_handle *) p;
3001 const char *modname;
3004 if (info->filename != NULL)
3006 if (! ieee_finish_compilation_unit (info))
3010 info->filename = filename;
3011 modname = strrchr (filename, '/');
3012 if (modname != NULL)
3016 modname = strrchr (filename, '\\');
3017 if (modname != NULL)
3022 c = xstrdup (modname);
3023 s = strrchr (c, '.');
3030 info->linenos = NULL;
3031 info->ranges = NULL;
3036 /* Finish up a compilation unit. */
3039 ieee_finish_compilation_unit (info)
3040 struct ieee_handle *info;
3042 struct ieee_buf **pp;
3043 struct ieee_range *r;
3045 if (info->types != NULL)
3047 if (! ieee_change_buffer (info, &info->types)
3048 || ! ieee_write_byte (info, (int) ieee_be_record_enum))
3052 if (info->vars != NULL)
3054 if (! ieee_change_buffer (info, &info->vars)
3055 || ! ieee_write_byte (info, (int) ieee_be_record_enum))
3059 if (info->linenos != NULL)
3061 if (! ieee_change_buffer (info, &info->linenos)
3062 || ! ieee_write_byte (info, (int) ieee_be_record_enum))
3066 for (pp = &info->data; *pp != NULL; pp = &(*pp)->next)
3069 for (; *pp != NULL; pp = &(*pp)->next)
3072 for (; *pp != NULL; pp = &(*pp)->next)
3074 *pp = info->linenos;
3076 /* Build BB10/BB11 blocks based on the ranges we recorded. */
3077 if (! ieee_change_buffer (info, &info->data))
3080 if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
3081 || ! ieee_write_byte (info, 10)
3082 || ! ieee_write_number (info, 0)
3083 || ! ieee_write_id (info, info->modname)
3084 || ! ieee_write_id (info, "")
3085 || ! ieee_write_number (info, 0)
3086 || ! ieee_write_id (info, "GNU objcopy"))
3089 for (r = info->ranges; r != NULL; r = r->next)
3098 /* Find the section corresponding to this range. */
3099 for (s = info->abfd->sections; s != NULL; s = s->next)
3101 if (bfd_get_section_vma (info->abfd, s) <= low
3102 && high <= (bfd_get_section_vma (info->abfd, s)
3103 + bfd_section_size (info->abfd, s)))
3109 /* Just ignore this range. */
3113 /* Coalesce ranges if it seems reasonable. */
3114 while (r->next != NULL
3115 && high + 64 >= r->next->low
3117 <= (bfd_get_section_vma (info->abfd, s)
3118 + bfd_section_size (info->abfd, s))))
3121 high = r->next->high;
3124 if ((s->flags & SEC_CODE) != 0)
3126 else if ((s->flags & SEC_READONLY) != 0)
3131 if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
3132 || ! ieee_write_byte (info, 11)
3133 || ! ieee_write_number (info, 0)
3134 || ! ieee_write_id (info, "")
3135 || ! ieee_write_number (info, kind)
3136 || ! ieee_write_number (info, s->index)
3137 || ! ieee_write_number (info, low)
3138 || ! ieee_write_byte (info, (int) ieee_be_record_enum)
3139 || ! ieee_write_number (info, high - low))
3143 if (! ieee_write_byte (info, (int) ieee_be_record_enum))
3149 /* Start recording information from a particular source file. This is
3150 used to record which file defined which types, variables, etc. It
3151 is not used for line numbers, since the lineno entry point passes
3152 down the file name anyhow. IEEE debugging information doesn't seem
3153 to store this information anywhere. */
3157 ieee_start_source (p, filename)
3159 const char *filename;
3164 /* Make an ellipsis type. */
3167 ieee_ellipsis_type (p)
3173 /* Make an empty type. */
3179 struct ieee_handle *info = (struct ieee_handle *) p;
3181 return ieee_push_type (info, 0, 0, false);
3184 /* Make a void type. */
3190 struct ieee_handle *info = (struct ieee_handle *) p;
3192 return ieee_push_type (info, 1, 0, false);
3195 /* Make an integer type. */
3198 ieee_int_type (p, size, unsignedp)
3203 struct ieee_handle *info = (struct ieee_handle *) p;
3209 indx = (int) builtin_signed_char;
3212 indx = (int) builtin_signed_short_int;
3215 indx = (int) builtin_signed_long;
3218 indx = (int) builtin_signed_long_long;
3221 fprintf (stderr, "IEEE unsupported integer type size %u\n", size);
3228 return ieee_push_type (info, indx, size, unsignedp);
3231 /* Make a floating point type. */
3234 ieee_float_type (p, size)
3238 struct ieee_handle *info = (struct ieee_handle *) p;
3244 indx = (int) builtin_float;
3247 indx = (int) builtin_double;
3250 /* FIXME: This size really depends upon the processor. */
3251 indx = (int) builtin_long_double;
3254 indx = (int) builtin_long_long_double;
3257 fprintf (stderr, "IEEE unsupported float type size %u\n", size);
3261 return ieee_push_type (info, indx, size, false);
3264 /* Make a complex type. */
3267 ieee_complex_type (p, size)
3271 struct ieee_handle *info = (struct ieee_handle *) p;
3283 fprintf (stderr, "IEEE unsupported complex type size %u\n", size);
3287 /* FIXME: I don't know what the string is for. */
3288 return (ieee_define_type (info, size, false)
3289 && ieee_write_number (info, code)
3290 && ieee_write_id (info, ""));
3293 /* Make a boolean type. IEEE doesn't support these, so we just make
3294 an integer type instead. */
3297 ieee_bool_type (p, size)
3301 return ieee_int_type (p, size, true);
3304 /* Make an enumeration. */
3307 ieee_enum_type (p, tag, names, vals)
3311 bfd_signed_vma *vals;
3313 struct ieee_handle *info = (struct ieee_handle *) p;
3317 /* If this is a simple enumeration, in which the values start at 0
3318 and always increment by 1, we can use type E. Otherwise we must
3324 for (i = 0; names[i] != NULL; i++)
3334 if (! ieee_define_named_type (info, tag, true, 0, true,
3335 (struct ieee_buf **) NULL)
3336 || ! ieee_write_number (info, simple ? 'E' : 'N'))
3340 /* FIXME: This is supposed to be the enumeration size, but we
3341 don't store that. */
3342 if (! ieee_write_number (info, 4))
3347 for (i = 0; names[i] != NULL; i++)
3349 if (! ieee_write_id (info, names[i]))
3353 if (! ieee_write_number (info, vals[i]))
3362 /* Make a pointer type. */
3365 ieee_pointer_type (p)
3368 struct ieee_handle *info = (struct ieee_handle *) p;
3371 indx = ieee_pop_type (info);
3373 /* A pointer to a simple builtin type can be obtained by adding 32. */
3375 return ieee_push_type (info, indx + 32, 0, true);
3377 return (ieee_define_type (info, 0, true)
3378 && ieee_write_number (info, 'P')
3379 && ieee_write_number (info, indx));
3382 /* Make a function type. */
3385 ieee_function_type (p)
3388 struct ieee_handle *info = (struct ieee_handle *) p;
3391 indx = ieee_pop_type (info);
3393 /* FIXME: IEEE can represent the argument types for the function,
3394 but we didn't store them. */
3396 /* An attribute of 0x41 means that the frame and push mask are
3398 return (ieee_define_type (info, 0, true)
3399 && ieee_write_number (info, 'x')
3400 && ieee_write_number (info, 0x41)
3401 && ieee_write_number (info, 0)
3402 && ieee_write_number (info, 0)
3403 && ieee_write_number (info, indx)
3404 && ieee_write_number (info, (bfd_vma) -1)
3405 && ieee_write_number (info, 0));
3408 /* Make a reference type. */
3411 ieee_reference_type (p)
3414 struct ieee_handle *info = (struct ieee_handle *) p;
3416 /* IEEE appears to record a normal pointer type, and then use a
3417 pmisc record to indicate that it is really a reference. */
3419 if (! ieee_pointer_type (p))
3421 info->type_stack->type.referencep = true;
3425 /* Make a range type. */
3428 ieee_range_type (p, low, high)
3431 bfd_signed_vma high;
3433 struct ieee_handle *info = (struct ieee_handle *) p;
3437 size = info->type_stack->type.size;
3438 unsignedp = info->type_stack->type.unsignedp;
3439 (void) ieee_pop_type (info);
3440 return (ieee_define_type (info, size, unsignedp)
3441 && ieee_write_number (info, 'R')
3442 && ieee_write_number (info, (bfd_vma) low)
3443 && ieee_write_number (info, (bfd_vma) high)
3444 && ieee_write_number (info, unsignedp ? 0 : 1)
3445 && ieee_write_number (info, size));
3448 /* Make an array type. */
3452 ieee_array_type (p, low, high, stringp)
3455 bfd_signed_vma high;
3458 struct ieee_handle *info = (struct ieee_handle *) p;
3459 unsigned int eleindx;
3461 /* IEEE does not store the range, so we just ignore it. */
3462 (void) ieee_pop_type (info);
3463 eleindx = ieee_pop_type (info);
3465 if (! ieee_define_type (info, 0, false)
3466 || ! ieee_write_number (info, low == 0 ? 'Z' : 'C')
3467 || ! ieee_write_number (info, eleindx))
3471 if (! ieee_write_number (info, low))
3475 return ieee_write_number (info, high);
3478 /* Make a set type. */
3481 ieee_set_type (p, bitstringp)
3485 struct ieee_handle *info = (struct ieee_handle *) p;
3486 unsigned int eleindx;
3488 eleindx = ieee_pop_type (info);
3490 /* FIXME: We don't know the size, so we just use 4. */
3492 return (ieee_define_type (info, 0, true)
3493 && ieee_write_number (info, 's')
3494 && ieee_write_number (info, 4)
3495 && ieee_write_number (info, eleindx));
3498 /* Make an offset type. */
3501 ieee_offset_type (p)
3504 struct ieee_handle *info = (struct ieee_handle *) p;
3505 unsigned int targetindx, baseindx;
3507 targetindx = ieee_pop_type (info);
3508 baseindx = ieee_pop_type (info);
3510 /* FIXME: The MRI C++ compiler does not appear to generate any
3511 useful type information about an offset type. It just records a
3512 pointer to member as an integer. The MRI/HP IEEE spec does
3513 describe a pmisc record which can be used for a pointer to
3514 member. Unfortunately, it does not describe the target type,
3515 which seems pretty important. I'm going to punt this for now. */
3517 return ieee_int_type (p, 4, true);
3520 /* Make a method type. */
3523 ieee_method_type (p, domain, argcount)
3528 struct ieee_handle *info = (struct ieee_handle *) p;
3529 unsigned int *args = NULL;
3531 unsigned int retindx;
3533 /* FIXME: The MRI/HP IEEE spec defines a pmisc record to use for a
3534 method, but the definition is incomplete. We just output an 'x'
3538 (void) ieee_pop_type (info);
3542 args = (unsigned int *) xmalloc (argcount * sizeof *args);
3543 for (i = argcount - 1; i >= 0; i--)
3544 args[i] = ieee_pop_type (info);
3547 retindx = ieee_pop_type (info);
3549 if (! ieee_define_type (info, 0, true)
3550 || ! ieee_write_number (info, 'x')
3551 || ! ieee_write_number (info, 0x41)
3552 || ! ieee_write_number (info, 0)
3553 || ! ieee_write_number (info, 0)
3554 || ! ieee_write_number (info, retindx)
3555 || ! ieee_write_number (info, (bfd_vma) argcount))
3559 for (i = 0; i < argcount; i++)
3560 if (! ieee_write_number (info, args[i]))
3565 return ieee_write_number (info, 0);
3568 /* Make a const qualified type. */
3574 struct ieee_handle *info = (struct ieee_handle *) p;
3579 size = info->type_stack->type.size;
3580 unsignedp = info->type_stack->type.unsignedp;
3581 indx = ieee_pop_type (info);
3582 return (ieee_define_type (info, size, unsignedp)
3583 && ieee_write_number (info, 'n')
3584 && ieee_write_number (info, 1)
3585 && ieee_write_number (info, indx));
3588 /* Make a volatile qualified type. */
3591 ieee_volatile_type (p)
3594 struct ieee_handle *info = (struct ieee_handle *) p;
3599 size = info->type_stack->type.size;
3600 unsignedp = info->type_stack->type.unsignedp;
3601 indx = ieee_pop_type (info);
3602 return (ieee_define_type (info, size, unsignedp)
3603 && ieee_write_number (info, 'n')
3604 && ieee_write_number (info, 2)
3605 && ieee_write_number (info, indx));
3608 /* Start defining a struct type. We build it in the strdef field on
3609 the stack, to avoid confusing type definitions required by the
3610 fields with the struct type itself. */
3613 ieee_start_struct_type (p, tag, id, structp, size)
3620 struct ieee_handle *info = (struct ieee_handle *) p;
3621 struct ieee_buf *strdef;
3624 if (! ieee_define_named_type (info, tag, true, size, true, &strdef)
3625 || ! ieee_write_number (info, structp ? 'S' : 'U')
3626 || ! ieee_write_number (info, size))
3629 info->type_stack->type.strdef = strdef;
3634 /* Add a field to a struct. */
3637 ieee_struct_field (p, name, bitpos, bitsize, visibility)
3642 enum debug_visibility visibility;
3644 struct ieee_handle *info = (struct ieee_handle *) p;
3650 size = info->type_stack->type.size;
3651 unsignedp = info->type_stack->type.unsignedp;
3652 indx = ieee_pop_type (info);
3654 assert (info->type_stack != NULL && info->type_stack->type.strdef != NULL);
3656 /* If the bitsize doesn't match the expected size, we need to output
3658 if (size == 0 || bitsize == size * 8)
3659 offset = bitpos / 8;
3662 if (! ieee_define_type (info, 0, unsignedp)
3663 || ! ieee_write_number (info, 'g')
3664 || ! ieee_write_number (info, unsignedp ? 0 : 1)
3665 || ! ieee_write_number (info, indx))
3667 indx = ieee_pop_type (info);
3671 /* Switch to the struct we are building in order to output this
3672 field definition. */
3673 return (ieee_change_buffer (info, &info->type_stack->type.strdef)
3674 && ieee_write_id (info, name)
3675 && ieee_write_number (info, indx)
3676 && ieee_write_number (info, offset));
3679 /* Finish up a struct type. */
3682 ieee_end_struct_type (p)
3685 struct ieee_handle *info = (struct ieee_handle *) p;
3686 struct ieee_buf **pb;
3688 assert (info->type_stack != NULL && info->type_stack->type.strdef != NULL);
3690 /* Make sure we have started the types block. */
3691 if (info->types == NULL)
3693 if (! ieee_change_buffer (info, &info->types)
3694 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
3695 || ! ieee_write_byte (info, 1)
3696 || ! ieee_write_number (info, 0)
3697 || ! ieee_write_id (info, info->modname))
3701 /* Append the struct definition to the types. */
3702 for (pb = &info->types; *pb != NULL; pb = &(*pb)->next)
3704 *pb = info->type_stack->type.strdef;
3705 info->type_stack->type.strdef = NULL;
3707 /* Leave the struct on the type stack. */
3712 /* Start a class type. */
3715 ieee_start_class_type (p, tag, id, structp, size, vptr, ownvptr)
3724 struct ieee_handle *info = (struct ieee_handle *) p;
3727 if (vptr && ! ownvptr)
3728 (void) ieee_pop_type (info);
3729 return ieee_start_struct_type (p, tag, id, structp, size);
3732 /* Add a static member to a class. */
3735 ieee_class_static_member (p, name, physname, visibility)
3738 const char *physname;
3739 enum debug_visibility visibility;
3741 struct ieee_handle *info = (struct ieee_handle *) p;
3744 (void) ieee_pop_type (info);
3748 /* Add a base class to a class. */
3751 ieee_class_baseclass (p, bitpos, virtual, visibility)
3755 enum debug_visibility visibility;
3757 struct ieee_handle *info = (struct ieee_handle *) p;
3760 (void) ieee_pop_type (info);
3764 /* Start building a method for a class. */
3767 ieee_class_start_method (p, name)
3775 /* Define a new method variant. */
3778 ieee_class_method_variant (p, physname, visibility, constp, volatilep,
3781 const char *physname;
3782 enum debug_visibility visibility;
3788 struct ieee_handle *info = (struct ieee_handle *) p;
3791 (void) ieee_pop_type (info);
3793 (void) ieee_pop_type (info);
3797 /* Define a new static method variant. */
3800 ieee_class_static_method_variant (p, physname, visibility, constp, volatilep)
3802 const char *physname;
3803 enum debug_visibility visibility;
3807 struct ieee_handle *info = (struct ieee_handle *) p;
3810 (void) ieee_pop_type (info);
3814 /* Finish up a method. */
3817 ieee_class_end_method (p)
3824 /* Finish up a class. */
3827 ieee_end_class_type (p)
3830 return ieee_end_struct_type (p);
3833 /* Push a previously seen typedef onto the type stack. */
3836 ieee_typedef_type (p, name)
3840 struct ieee_handle *info = (struct ieee_handle *) p;
3841 register struct ieee_name_type *nt;
3843 for (nt = info->typedefs; nt != NULL; nt = nt->next)
3845 if (nt->name[0] == name[0]
3846 && strcmp (nt->name, name) == 0)
3848 if (! ieee_push_type (info, nt->type.indx, nt->type.size,
3849 nt->type.unsignedp))
3851 /* Copy over any other type information we may have. */
3852 info->type_stack->type = nt->type;
3860 /* Push a tagged type onto the type stack. */
3863 ieee_tag_type (p, name, id, kind)
3867 enum debug_type_kind kind;
3869 struct ieee_handle *info = (struct ieee_handle *) p;
3870 register struct ieee_name_type *nt;
3875 for (nt = info->tags; nt != NULL; nt = nt->next)
3877 if (nt->name[0] == name[0]
3878 && strcmp (nt->name, name) == 0)
3880 if (! ieee_push_type (info, nt->type.indx, nt->type.size,
3881 nt->type.unsignedp))
3883 /* Copy over any other type information we may have. */
3884 info->type_stack->type = nt->type;
3889 nt = (struct ieee_name_type *) xmalloc (sizeof *nt);
3890 memset (nt, 0, sizeof *nt);
3893 nt->type.indx = info->type_indx;
3897 nt->next = info->tags;
3900 return ieee_push_type (info, nt->type.indx, 0, false);
3903 /* Output a typedef. */
3906 ieee_typdef (p, name)
3910 struct ieee_handle *info = (struct ieee_handle *) p;
3911 struct ieee_name_type *nt;
3916 nt = (struct ieee_name_type *) xmalloc (sizeof *nt);
3917 memset (nt, 0, sizeof *nt);
3919 nt->type = info->type_stack->type;
3920 nt->kind = DEBUG_KIND_ILLEGAL;
3922 nt->next = info->typedefs;
3923 info->typedefs = nt;
3925 size = info->type_stack->type.size;
3926 unsignedp = info->type_stack->type.unsignedp;
3927 indx = ieee_pop_type (info);
3929 /* If this is a simple builtin type using a builtin name, we don't
3930 want to output the typedef itself. We also want to change the
3931 type index to correspond to the name being used. We recognize
3932 names used in stabs debugging output even if they don't exactly
3933 correspond to the names used for the IEEE builtin types. */
3934 if (indx <= (unsigned int) builtin_bcd_float)
3939 switch ((enum builtin_types) indx)
3945 if (strcmp (name, "void") == 0)
3949 case builtin_signed_char:
3951 if (strcmp (name, "signed char") == 0)
3953 indx = (unsigned int) builtin_signed_char;
3956 else if (strcmp (name, "char") == 0)
3958 indx = (unsigned int) builtin_char;
3963 case builtin_unsigned_char:
3964 if (strcmp (name, "unsigned char") == 0)
3968 case builtin_signed_short_int:
3970 case builtin_short_int:
3971 case builtin_signed_short:
3972 if (strcmp (name, "signed short int") == 0)
3974 indx = (unsigned int) builtin_signed_short_int;
3977 else if (strcmp (name, "short") == 0)
3979 indx = (unsigned int) builtin_short;
3982 else if (strcmp (name, "short int") == 0)
3984 indx = (unsigned int) builtin_short_int;
3987 else if (strcmp (name, "signed short") == 0)
3989 indx = (unsigned int) builtin_signed_short;
3994 case builtin_unsigned_short_int:
3995 case builtin_unsigned_short:
3996 if (strcmp (name, "unsigned short int") == 0
3997 || strcmp (name, "short unsigned int") == 0)
3999 indx = builtin_unsigned_short_int;
4002 else if (strcmp (name, "unsigned short") == 0)
4004 indx = builtin_unsigned_short;
4009 case builtin_signed_long:
4010 case builtin_int: /* FIXME: Size depends upon architecture. */
4012 if (strcmp (name, "signed long") == 0)
4014 indx = builtin_signed_long;
4017 else if (strcmp (name, "int") == 0)
4022 else if (strcmp (name, "long") == 0
4023 || strcmp (name, "long int") == 0)
4025 indx = builtin_long;
4030 case builtin_unsigned_long:
4031 case builtin_unsigned: /* FIXME: Size depends upon architecture. */
4032 case builtin_unsigned_int: /* FIXME: Like builtin_unsigned. */
4033 if (strcmp (name, "unsigned long") == 0
4034 || strcmp (name, "long unsigned int") == 0)
4036 indx = builtin_unsigned_long;
4039 else if (strcmp (name, "unsigned") == 0)
4041 indx = builtin_unsigned;
4044 else if (strcmp (name, "unsigned int") == 0)
4046 indx = builtin_unsigned_int;
4051 case builtin_signed_long_long:
4052 if (strcmp (name, "signed long long") == 0
4053 || strcmp (name, "long long int") == 0)
4057 case builtin_unsigned_long_long:
4058 if (strcmp (name, "unsigned long long") == 0
4059 || strcmp (name, "long long unsigned int") == 0)
4064 if (strcmp (name, "float") == 0)
4068 case builtin_double:
4069 if (strcmp (name, "double") == 0)
4073 case builtin_long_double:
4074 if (strcmp (name, "long double") == 0)
4078 case builtin_long_long_double:
4079 if (strcmp (name, "long long double") == 0)
4086 nt->type.indx = indx;
4091 if (! ieee_define_named_type (info, name, false, size, unsignedp,
4092 (struct ieee_buf **) NULL)
4093 || ! ieee_write_number (info, 'T')
4094 || ! ieee_write_number (info, indx))
4097 /* Remove the type we just added to the type stack. */
4098 (void) ieee_pop_type (info);
4103 /* Output a tag for a type. We don't have to do anything here. */
4110 struct ieee_handle *info = (struct ieee_handle *) p;
4112 (void) ieee_pop_type (info);
4116 /* Output an integer constant. */
4119 ieee_int_constant (p, name, val)
4128 /* Output a floating point constant. */
4131 ieee_float_constant (p, name, val)
4140 /* Output a typed constant. */
4143 ieee_typed_constant (p, name, val)
4148 struct ieee_handle *info = (struct ieee_handle *) p;
4151 (void) ieee_pop_type (info);
4155 /* Output a variable. */
4158 ieee_variable (p, name, kind, val)
4161 enum debug_var_kind kind;
4164 struct ieee_handle *info = (struct ieee_handle *) p;
4165 unsigned int name_indx;
4167 unsigned int type_indx;
4170 /* Make sure the variable section is started. */
4171 if (info->vars != NULL)
4173 if (! ieee_change_buffer (info, &info->vars))
4178 if (! ieee_change_buffer (info, &info->vars)
4179 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
4180 || ! ieee_write_byte (info, 3)
4181 || ! ieee_write_number (info, 0)
4182 || ! ieee_write_id (info, info->modname))
4186 name_indx = info->name_indx;
4189 size = info->type_stack->type.size;
4190 type_indx = ieee_pop_type (info);
4192 /* Write out an NN and an ATN record for this variable. */
4193 if (! ieee_write_byte (info, (int) ieee_nn_record)
4194 || ! ieee_write_number (info, name_indx)
4195 || ! ieee_write_id (info, name)
4196 || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
4197 || ! ieee_write_number (info, name_indx)
4198 || ! ieee_write_number (info, type_indx))
4206 if (! ieee_write_number (info, 8)
4207 || ! ieee_add_range (info, val, val + size))
4212 case DEBUG_LOCAL_STATIC:
4213 if (! ieee_write_number (info, 3)
4214 || ! ieee_add_range (info, val, val + size))
4219 if (! ieee_write_number (info, 1)
4220 || ! ieee_write_number (info, val))
4224 case DEBUG_REGISTER:
4225 if (! ieee_write_number (info, 2)
4226 || ! ieee_write_number (info,
4227 ieee_genreg_to_regno (info->abfd, val)))
4235 if (! ieee_write_2bytes (info, (int) ieee_asn_record_enum)
4236 || ! ieee_write_number (info, name_indx)
4237 || ! ieee_write_number (info, val))
4244 /* Start outputting information for a function. */
4247 ieee_start_function (p, name, global)
4252 struct ieee_handle *info = (struct ieee_handle *) p;
4255 /* Make sure the variable section is started. */
4256 if (info->vars != NULL)
4258 if (! ieee_change_buffer (info, &info->vars))
4263 if (! ieee_change_buffer (info, &info->vars)
4264 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
4265 || ! ieee_write_byte (info, 3)
4266 || ! ieee_write_number (info, 0)
4267 || ! ieee_write_id (info, info->modname))
4271 indx = ieee_pop_type (info);
4273 /* The address is written out as the first block. */
4275 ++info->block_depth;
4277 return (ieee_write_byte (info, (int) ieee_bb_record_enum)
4278 && ieee_write_byte (info, global ? 4 : 6)
4279 && ieee_write_number (info, 0)
4280 && ieee_write_id (info, name)
4281 && ieee_write_number (info, 0)
4282 && ieee_write_number (info, indx));
4285 /* Add a function parameter. This will normally be called before the
4286 first block, so we postpone them until we see the block. */
4289 ieee_function_parameter (p, name, kind, val)
4292 enum debug_parm_kind kind;
4295 struct ieee_handle *info = (struct ieee_handle *) p;
4296 struct ieee_pending_parm *m, **pm;
4298 assert (info->block_depth == 1);
4300 m = (struct ieee_pending_parm *) xmalloc (sizeof *m);
4301 memset (m, 0, sizeof *m);
4305 m->type = ieee_pop_type (info);
4309 for (pm = &info->pending_parms; *pm != NULL; pm = &(*pm)->next)
4316 /* Output pending function parameters. */
4319 ieee_output_pending_parms (info)
4320 struct ieee_handle *info;
4322 struct ieee_pending_parm *m;
4324 m = info->pending_parms;
4327 struct ieee_pending_parm *next;
4328 enum debug_var_kind vkind;
4335 case DEBUG_PARM_STACK:
4336 case DEBUG_PARM_REFERENCE:
4337 vkind = DEBUG_LOCAL;
4339 case DEBUG_PARM_REG:
4340 case DEBUG_PARM_REF_REG:
4341 vkind = DEBUG_REGISTER;
4345 if (! ieee_push_type (info, m->type, 0, false)
4346 || ! ieee_variable ((PTR) info, m->name, vkind, m->val))
4349 /* FIXME: We should output a pmisc note here for reference
4356 info->pending_parms = NULL;
4361 /* Start a block. If this is the first block, we output the address
4362 to finish the BB4 or BB6, and then output the function parameters. */
4365 ieee_start_block (p, addr)
4369 struct ieee_handle *info = (struct ieee_handle *) p;
4371 if (! ieee_change_buffer (info, &info->vars))
4374 if (info->block_depth == 1)
4376 if (! ieee_write_number (info, addr)
4377 || ! ieee_output_pending_parms (info))
4382 if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
4383 || ! ieee_write_byte (info, 6)
4384 || ! ieee_write_byte (info, 0)
4385 || ! ieee_write_id (info, "")
4386 || ! ieee_write_number (info, 0)
4387 || ! ieee_write_number (info, 0)
4388 || ! ieee_write_number (info, addr))
4392 if (! ieee_start_range (info, addr))
4395 ++info->block_depth;
4403 ieee_end_block (p, addr)
4407 struct ieee_handle *info = (struct ieee_handle *) p;
4409 if (! ieee_change_buffer (info, &info->vars)
4410 || ! ieee_write_byte (info, (int) ieee_be_record_enum)
4411 || ! ieee_write_number (info, addr))
4414 if (! ieee_end_range (info, addr))
4417 --info->block_depth;
4422 /* End a function. */
4425 ieee_end_function (p)
4428 struct ieee_handle *info = (struct ieee_handle *) p;
4430 assert (info->block_depth == 1);
4432 --info->block_depth;
4437 /* Record line number information. */
4440 ieee_lineno (p, filename, lineno, addr)
4442 const char *filename;
4443 unsigned long lineno;
4446 struct ieee_handle *info = (struct ieee_handle *) p;
4448 assert (info->filename != NULL);
4450 /* Make sure we have a line number block. */
4451 if (info->linenos != NULL)
4453 if (! ieee_change_buffer (info, &info->linenos))
4458 info->lineno_name_indx = info->name_indx;
4460 if (! ieee_change_buffer (info, &info->linenos)
4461 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
4462 || ! ieee_write_byte (info, 5)
4463 || ! ieee_write_number (info, 0)
4464 || ! ieee_write_id (info, info->filename)
4465 || ! ieee_write_byte (info, (int) ieee_nn_record)
4466 || ! ieee_write_number (info, info->lineno_name_indx)
4467 || ! ieee_write_id (info, ""))
4469 info->lineno_filename = info->filename;
4472 if (strcmp (filename, info->lineno_filename) != 0)
4474 if (strcmp (info->filename, info->lineno_filename) != 0)
4476 /* We were not in the main file. Close the block for the
4478 if (! ieee_write_byte (info, (int) ieee_be_record_enum))
4481 if (strcmp (info->filename, filename) != 0)
4483 /* We are not changing to the main file. Open a block for
4484 the new included file. */
4485 if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
4486 || ! ieee_write_byte (info, 5)
4487 || ! ieee_write_number (info, 0)
4488 || ! ieee_write_id (info, filename))
4491 info->lineno_filename = filename;
4494 return (ieee_write_2bytes (info, (int) ieee_atn_record_enum)
4495 && ieee_write_number (info, info->lineno_name_indx)
4496 && ieee_write_number (info, 0)
4497 && ieee_write_number (info, 7)
4498 && ieee_write_number (info, lineno)
4499 && ieee_write_number (info, 0)
4500 && ieee_write_2bytes (info, (int) ieee_asn_record_enum)
4501 && ieee_write_number (info, info->lineno_name_indx)
4502 && ieee_write_number (info, addr));