1 /* ieee.c -- Write out 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. */
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 /* If this is a bitfield, this is the size in bits. If this is not
86 a bitfield, this is zero. */
87 unsigned long bitsize;
88 /* If this is a function type ('x' or 'X') this is the return type. */
89 debug_type return_type;
92 /* This structure holds all the type information. */
96 /* Number of slots allocated. */
99 struct ieee_type *types;
101 #define BUILTIN_TYPE_COUNT (60)
102 debug_type builtins[BUILTIN_TYPE_COUNT];
105 static void ieee_error
106 PARAMS ((bfd *, const bfd_byte *, const bfd_byte *, const char *));
107 static void ieee_eof PARAMS ((bfd *));
108 static char *savestring PARAMS ((const char *, unsigned long));
109 static boolean ieee_read_number
110 PARAMS ((bfd *, const bfd_byte *, const bfd_byte **, const bfd_byte *,
112 static boolean ieee_read_optional_number
113 PARAMS ((bfd *, const bfd_byte *, const bfd_byte **, const bfd_byte *,
114 bfd_vma *, boolean *));
115 static boolean ieee_read_id
116 PARAMS ((bfd *, const bfd_byte *, const bfd_byte **, const bfd_byte *,
117 const char **, unsigned long *));
118 static boolean ieee_read_optional_id
119 PARAMS ((bfd *, const bfd_byte *, const bfd_byte **, const bfd_byte *,
120 const char **, unsigned long *, boolean *));
121 static boolean ieee_read_expression
122 PARAMS ((bfd *, const bfd_byte *, const bfd_byte **, const bfd_byte *,
124 static debug_type ieee_builtin_type
125 PARAMS ((PTR, bfd *, struct ieee_types *, const bfd_byte *,
126 const bfd_byte *, unsigned int));
127 static boolean ieee_read_type_index
128 PARAMS ((PTR, bfd *, struct ieee_types *, const bfd_byte *,
129 const bfd_byte **, const bfd_byte *, debug_type *));
130 static int ieee_regno_to_gen PARAMS ((bfd *, int));
131 static boolean parse_ieee_bb
132 PARAMS ((PTR, bfd *, struct ieee_types *, struct ieee_blockstack *,
133 const bfd_byte *, const bfd_byte **, const bfd_byte *));
134 static boolean parse_ieee_be
135 PARAMS ((PTR, bfd *, struct ieee_blockstack *, const bfd_byte *,
136 const bfd_byte **, const bfd_byte *));
137 static boolean parse_ieee_nn
138 PARAMS ((PTR, bfd *, struct ieee_vars *, const bfd_byte *,
139 const bfd_byte **, const bfd_byte *));
140 static boolean parse_ieee_ty
141 PARAMS ((PTR, bfd *, struct ieee_types *, struct ieee_vars *,
142 const bfd_byte *, const bfd_byte **, const bfd_byte *));
143 static boolean parse_ieee_atn
144 PARAMS ((PTR, bfd *, struct ieee_types *, struct ieee_vars *, int,
145 const bfd_byte *, const bfd_byte **, const bfd_byte *));
146 static boolean ieee_require_asn
147 PARAMS ((bfd *, const bfd_byte *, const bfd_byte **, const bfd_byte *,
150 /* Report an error in the IEEE debugging information. */
153 ieee_error (abfd, bytes, p, s)
155 const bfd_byte *bytes;
160 fprintf (stderr, "%s: 0x%lx: %s (0x%x)\n", bfd_get_filename (abfd),
161 (unsigned long) (p - bytes), s, *p);
163 fprintf (stderr, "%s: %s\n", bfd_get_filename (abfd), s);
166 /* Report an unexpected EOF in the IEEE debugging information. */
172 ieee_error (abfd, (const bfd_byte *) NULL, (const bfd_byte *) NULL,
173 "unexpected end of debugging information");
176 /* Save a string in memory. */
179 savestring (start, len)
185 ret = (char *) xmalloc (len + 1);
186 memcpy (ret, start, len);
191 /* Read a number which must be present in an IEEE file. */
194 ieee_read_number (abfd, bytes, pp, pend, pv)
196 const bfd_byte *bytes;
198 const bfd_byte *pend;
201 return ieee_read_optional_number (abfd, bytes, pp, pend, pv,
205 /* Read a number in an IEEE file. If ppresent is not NULL, the number
206 need not be there. */
209 ieee_read_optional_number (abfd, bytes, pp, pend, pv, ppresent)
211 const bfd_byte *bytes;
213 const bfd_byte *pend;
217 ieee_record_enum_type b;
221 if (ppresent != NULL)
230 b = (ieee_record_enum_type) **pp;
233 if (b <= ieee_number_end_enum)
236 if (ppresent != NULL)
241 if (b >= ieee_number_repeat_start_enum && b <= ieee_number_repeat_end_enum)
245 i = (int) b - (int) ieee_number_repeat_start_enum;
246 if (*pp + i - 1 >= pend)
260 if (ppresent != NULL)
266 if (ppresent != NULL)
273 ieee_error (abfd, bytes, *pp - 1, "invalid number");
277 /* Read a required string from an IEEE file. */
280 ieee_read_id (abfd, bytes, pp, pend, pname, pnamlen)
282 const bfd_byte *bytes;
284 const bfd_byte *pend;
286 unsigned long *pnamlen;
288 return ieee_read_optional_id (abfd, bytes, pp, pend, pname, pnamlen,
292 /* Read a string from an IEEE file. If ppresent is not NULL, the
293 string is optional. */
296 ieee_read_optional_id (abfd, bytes, pp, pend, pname, pnamlen, ppresent)
298 const bfd_byte *bytes;
300 const bfd_byte *pend;
302 unsigned long *pnamlen;
319 else if ((ieee_record_enum_type) b == ieee_extension_length_1_enum)
324 else if ((ieee_record_enum_type) b == ieee_extension_length_2_enum)
326 len = (**pp << 8) + (*pp)[1];
331 if (ppresent != NULL)
337 ieee_error (abfd, bytes, *pp - 1, "invalid string length");
341 if ((unsigned long) (pend - *pp) < len)
347 *pname = (const char *) *pp;
351 if (ppresent != NULL)
357 /* Read an expression from an IEEE file. Since this code is only used
358 to parse debugging information, I haven't bothered to write a full
359 blown IEEE expression parser. I've only thrown in the things I've
360 seen in debugging information. This can be easily extended if
364 ieee_read_expression (abfd, bytes, pp, pend, pv)
366 const bfd_byte *bytes;
368 const bfd_byte *pend;
371 const bfd_byte *expr_start;
372 #define EXPR_STACK_SIZE (10)
373 bfd_vma expr_stack[EXPR_STACK_SIZE];
382 const bfd_byte *start;
385 ieee_record_enum_type c;
389 if (! ieee_read_optional_number (abfd, bytes, pp, pend, &val, &present))
394 if (esp - expr_stack >= EXPR_STACK_SIZE)
396 ieee_error (abfd, bytes, start, "expression stack overflow");
403 c = (ieee_record_enum_type) **pp;
405 if (c >= ieee_module_beginning_enum)
416 ieee_error (abfd, bytes, start,
417 "unsupported IEEE expression operator");
420 case ieee_variable_R_enum:
425 if (! ieee_read_number (abfd, bytes, pp, pend, &indx))
427 for (s = abfd->sections; s != NULL; s = s->next)
428 if ((bfd_vma) s->target_index == indx)
432 ieee_error (abfd, bytes, start, "unknown section");
436 if (esp - expr_stack >= EXPR_STACK_SIZE)
438 ieee_error (abfd, bytes, start, "expression stack overflow");
442 *esp++ = bfd_get_section_vma (abfd, s);
446 case ieee_function_plus_enum:
447 case ieee_function_minus_enum:
451 if (esp - expr_stack < 2)
453 ieee_error (abfd, bytes, start, "expression stack underflow");
465 if (esp - 1 != expr_stack)
467 ieee_error (abfd, bytes, expr_start, "expression stack mismatch");
476 /* Return an IEEE builtin type. */
479 ieee_builtin_type (dhandle, abfd, types, bytes, p, indx)
482 struct ieee_types *types;
483 const bfd_byte *bytes;
491 if (indx < BUILTIN_TYPE_COUNT
492 && types->builtins[indx] != DEBUG_TYPE_NULL)
493 return types->builtins[indx];
499 ieee_error (abfd, bytes, p, "unknown builtin type");
506 type = debug_make_void_type (dhandle);
514 type = debug_make_void_type (dhandle);
522 type = debug_make_int_type (dhandle, 1, false);
523 name = "signed char";
530 type = debug_make_int_type (dhandle, 1, true);
531 name = "unsigned char";
538 type = debug_make_int_type (dhandle, 2, false);
539 name = "signed short int";
546 type = debug_make_int_type (dhandle, 2, true);
547 name = "unsigned short int";
554 type = debug_make_int_type (dhandle, 4, false);
555 name = "signed long";
562 type = debug_make_int_type (dhandle, 4, true);
563 name = "unsigned long";
570 type = debug_make_int_type (dhandle, 8, false);
571 name = "signed long long";
578 type = debug_make_int_type (dhandle, 8, true);
579 name = "unsigned long long";
586 type = debug_make_float_type (dhandle, 4);
594 type = debug_make_float_type (dhandle, 8);
602 /* FIXME: The size for this type should depend upon the
604 type = debug_make_float_type (dhandle, 12);
605 name = "long double";
612 type = debug_make_float_type (dhandle, 16);
613 name = "long long double";
620 type = debug_make_array_type (dhandle,
621 ieee_builtin_type (dhandle, abfd, types,
623 ieee_builtin_type (dhandle, abfd, types,
626 name = "QUOTED STRING";
633 /* FIXME: This should be a code address. */
634 type = debug_make_int_type (dhandle, 4, true);
635 name = "instruction address";
642 /* FIXME: The size for this type should depend upon the
644 type = debug_make_int_type (dhandle, 4, false);
652 /* FIXME: The size for this type should depend upon the
654 type = debug_make_int_type (dhandle, 4, true);
662 /* FIXME: The size for this type should depend upon the
664 type = debug_make_int_type (dhandle, 4, true);
665 name = "unsigned int";
672 type = debug_make_int_type (dhandle, 1, false);
680 type = debug_make_int_type (dhandle, 4, false);
688 type = debug_make_int_type (dhandle, 2, false);
696 type = debug_make_int_type (dhandle, 2, true);
697 name = "unsigned short";
704 type = debug_make_int_type (dhandle, 2, false);
712 type = debug_make_int_type (dhandle, 2, false);
713 name = "signed short";
720 ieee_error (abfd, bytes, p, "BCD float type not supported");
725 type = debug_make_pointer_type (dhandle, type);
726 else if (name != NULL)
727 type = debug_name_type (dhandle, name, type);
729 assert (indx < BUILTIN_TYPE_COUNT);
731 types->builtins[indx] = type;
736 /* Read a type index and return the corresponding type. */
739 ieee_read_type_index (dhandle, abfd, types, bytes, pp, pend, ptype)
742 struct ieee_types *types;
743 const bfd_byte *bytes;
745 const bfd_byte *pend;
748 const bfd_byte *start;
753 if (! ieee_read_number (abfd, bytes, pp, pend, &indx))
758 *ptype = ieee_builtin_type (dhandle, abfd, types, bytes, start, indx);
765 if (indx >= types->alloc
766 || types->types[indx].type == DEBUG_TYPE_NULL)
768 ieee_error (abfd, bytes, start, "undefined type");
772 *ptype = types->types[indx].type;
777 /* Convert a register number in IEEE debugging information into a
778 generic register number. */
781 ieee_regno_to_gen (abfd, r)
788 /* Parse IEEE debugging information for a file. This is passed the
789 bytes which compose the Debug Information Part of an IEEE file. */
792 parse_ieee (dhandle, abfd, bytes, len)
795 const bfd_byte *bytes;
798 struct ieee_blockstack blockstack;
799 struct ieee_vars vars;
800 struct ieee_types types;
802 const bfd_byte *p, *pend;
804 blockstack.bsp = blockstack.stack;
809 for (i = 0; i < BUILTIN_TYPE_COUNT; i++)
810 types.builtins[i] = DEBUG_TYPE_NULL;
816 const bfd_byte *record_start;
817 ieee_record_enum_type c;
821 c = (ieee_record_enum_type) *p++;
823 if (c == ieee_at_record_enum)
824 c = (ieee_record_enum_type) (((unsigned int) c << 8) | *p++);
826 if (c <= ieee_number_repeat_end_enum)
828 ieee_error (abfd, bytes, record_start, "unexpected number");
835 ieee_error (abfd, bytes, record_start, "unexpected record type");
838 case ieee_bb_record_enum:
839 if (! parse_ieee_bb (dhandle, abfd, &types, &blockstack, bytes,
844 case ieee_be_record_enum:
845 if (! parse_ieee_be (dhandle, abfd, &blockstack, bytes, &p, pend))
850 if (! parse_ieee_nn (dhandle, abfd, &vars, bytes, &p, pend))
854 case ieee_ty_record_enum:
855 if (! parse_ieee_ty (dhandle, abfd, &types, &vars, bytes, &p, pend))
859 case ieee_atn_record_enum:
860 if (! parse_ieee_atn (dhandle, abfd, &types, &vars,
861 (blockstack.bsp <= blockstack.stack
863 : blockstack.bsp[-1].kind),
870 if (blockstack.bsp != blockstack.stack)
872 ieee_error (abfd, (const bfd_byte *) NULL, (const bfd_byte *) NULL,
873 "blocks left on stack at end");
880 /* Handle an IEEE BB record. */
883 parse_ieee_bb (dhandle, abfd, types, blockstack, bytes, pp, pend)
886 struct ieee_types *types;
887 struct ieee_blockstack *blockstack;
888 const bfd_byte *bytes;
890 const bfd_byte *pend;
892 const bfd_byte *block_start;
896 unsigned long namlen;
904 if (! ieee_read_number (abfd, bytes, pp, pend, &size)
905 || ! ieee_read_id (abfd, bytes, pp, pend, &name, &namlen))
911 /* BB1: Type definitions local to a module. */
912 namcopy = savestring (name, namlen);
915 if (! debug_set_filename (dhandle, namcopy))
920 /* BB2: Global type definitions. The name is supposed to be
921 empty, but we don't check. */
922 if (! debug_set_filename (dhandle, "*global*"))
927 /* BB3: High level module block begin. We don't have to do
928 anything here. The name is supposed to be the same as for
929 the BB1, but we don't check. */
933 /* BB4: Global function. */
935 bfd_vma stackspace, typindx, offset;
936 debug_type return_type;
938 if (! ieee_read_number (abfd, bytes, pp, pend, &stackspace)
939 || ! ieee_read_number (abfd, bytes, pp, pend, &typindx)
940 || ! ieee_read_expression (abfd, bytes, pp, pend, &offset))
943 /* We have no way to record the stack space. FIXME. */
947 return_type = ieee_builtin_type (dhandle, abfd, types, bytes,
948 block_start, typindx);
949 if (return_type == NULL)
955 if (typindx >= types->alloc
956 || types->types[typindx].type == DEBUG_TYPE_NULL)
958 ieee_error (abfd, bytes, block_start, "undefined type index");
961 return_type = types->types[typindx].return_type;
962 if (return_type == NULL)
963 return_type = types->types[typindx].type;
966 namcopy = savestring (name, namlen);
969 if (! debug_record_function (dhandle, namcopy, return_type,
976 /* BB5: File name for source line numbers. */
980 /* We ignore the date and time. FIXME. */
981 for (i = 0; i < 6; i++)
986 if (! ieee_read_optional_number (abfd, bytes, pp, pend, &ignore,
993 namcopy = savestring (name, namlen);
996 if (! debug_start_source (dhandle, namcopy))
1002 /* BB6: Local function or block. */
1004 bfd_vma stackspace, typindx, offset;
1006 if (! ieee_read_number (abfd, bytes, pp, pend, &stackspace)
1007 || ! ieee_read_number (abfd, bytes, pp, pend, &typindx)
1008 || ! ieee_read_expression (abfd, bytes, pp, pend, &offset))
1011 /* We have no way to record the stack space. FIXME. */
1015 if (! debug_start_block (dhandle, offset))
1017 /* Change b to indicate that this is a block
1018 rather than a function. */
1023 debug_type return_type;
1027 return_type = ieee_builtin_type (dhandle, abfd, types, bytes,
1028 block_start, typindx);
1029 if (return_type == NULL)
1035 if (typindx >= types->alloc
1036 || types->types[typindx].type == DEBUG_TYPE_NULL)
1038 ieee_error (abfd, bytes, block_start,
1039 "undefined type index");
1042 return_type = types->types[typindx].return_type;
1043 if (return_type == NULL)
1044 return_type = types->types[typindx].type;
1047 namcopy = savestring (name, namlen);
1048 if (namcopy == NULL)
1050 if (! debug_record_function (dhandle, namcopy, return_type,
1058 /* BB10: Assembler module scope. We completely ignore all this
1059 information. FIXME. */
1061 const char *inam, *vstr;
1062 unsigned long inamlen, vstrlen;
1067 if (! ieee_read_id (abfd, bytes, pp, pend, &inam, &inamlen)
1068 || ! ieee_read_number (abfd, bytes, pp, pend, &tool_type)
1069 || ! ieee_read_optional_id (abfd, bytes, pp, pend, &vstr, &vstrlen,
1072 for (i = 0; i < 6; i++)
1076 if (! ieee_read_optional_number (abfd, bytes, pp, pend, &ignore,
1086 /* BB11: Module section. We completely ignore all this
1087 information. FIXME. */
1089 bfd_vma sectype, secindx, offset, map;
1092 if (! ieee_read_number (abfd, bytes, pp, pend, §ype)
1093 || ! ieee_read_number (abfd, bytes, pp, pend, &secindx)
1094 || ! ieee_read_expression (abfd, bytes, pp, pend, &offset)
1095 || ! ieee_read_optional_number (abfd, bytes, pp, pend, &map,
1102 ieee_error (abfd, bytes, block_start, "unknown BB type");
1107 /* Push this block on the block stack. */
1109 if (blockstack->bsp >= blockstack->stack + BLOCKSTACK_SIZE)
1111 ieee_error (abfd, (const bfd_byte *) NULL, (const bfd_byte *) NULL,
1116 blockstack->bsp->kind = b;
1118 blockstack->bsp->filename = namcopy;
1124 /* Handle an IEEE BE record. */
1127 parse_ieee_be (dhandle, abfd, blockstack, bytes, pp, pend)
1130 struct ieee_blockstack *blockstack;
1131 const bfd_byte *bytes;
1132 const bfd_byte **pp;
1133 const bfd_byte *pend;
1137 if (blockstack->bsp <= blockstack->stack)
1139 ieee_error (abfd, bytes, *pp, "stack underflow");
1144 switch (blockstack->bsp->kind)
1148 if (! ieee_read_expression (abfd, bytes, pp, pend, &offset))
1150 if (! debug_end_function (dhandle, offset))
1155 /* This is BE6 when BB6 started a block rather than a local
1157 if (! ieee_read_expression (abfd, bytes, pp, pend, &offset))
1159 if (! debug_end_block (dhandle, offset))
1164 /* When we end a BB5, we look up the stack for the last BB5, if
1165 there is one, so that we can call debug_start_source. */
1166 if (blockstack->bsp > blockstack->stack)
1168 struct ieee_block *bl;
1170 bl = blockstack->bsp;
1176 if (! debug_start_source (dhandle, bl->filename))
1181 while (bl != blockstack->stack);
1186 if (! ieee_read_expression (abfd, bytes, pp, pend, &offset))
1188 /* We just ignore the module size. FIXME. */
1192 /* Other block types do not have any trailing information. */
1199 /* Parse an NN record. */
1202 parse_ieee_nn (dhandle, abfd, vars, bytes, pp, pend)
1205 struct ieee_vars *vars;
1206 const bfd_byte *bytes;
1207 const bfd_byte **pp;
1208 const bfd_byte *pend;
1210 const bfd_byte *nn_start;
1213 unsigned long namlen;
1217 if (! ieee_read_number (abfd, bytes, pp, pend, &varindx)
1218 || ! ieee_read_id (abfd, bytes, pp, pend, &name, &namlen))
1223 ieee_error (abfd, bytes, nn_start, "illegal variable index");
1228 if (varindx >= vars->alloc)
1232 alloc = vars->alloc;
1235 while (varindx >= alloc)
1237 vars->vars = ((struct ieee_var *)
1238 xrealloc (vars->vars, alloc * sizeof *vars->vars));
1239 memset (vars->vars + vars->alloc, 0,
1240 (alloc - vars->alloc) * sizeof *vars->vars);
1241 vars->alloc = alloc;
1244 vars->vars[varindx].name = name;
1245 vars->vars[varindx].namlen = namlen;
1250 /* Parse a TY record. */
1253 parse_ieee_ty (dhandle, abfd, types, vars, bytes, pp, pend)
1256 struct ieee_types *types;
1257 struct ieee_vars *vars;
1258 const bfd_byte *bytes;
1259 const bfd_byte **pp;
1260 const bfd_byte *pend;
1262 const bfd_byte *ty_start, *ty_var_start, *ty_code_start;
1263 bfd_vma typeindx, varindx, tc;
1265 boolean tag, typdef;
1266 unsigned long type_bitsize;
1267 debug_type return_type;
1271 if (! ieee_read_number (abfd, bytes, pp, pend, &typeindx))
1276 ieee_error (abfd, bytes, ty_start, "illegal type index");
1281 if (typeindx >= types->alloc)
1283 unsigned int nalloc;
1284 struct ieee_type *t, *tend;
1286 nalloc = types->alloc;
1289 while (typeindx >= nalloc)
1291 types->types = ((struct ieee_type *)
1292 xrealloc (types->types, nalloc * sizeof *types->types));
1293 tend = types->types + nalloc;
1294 for (t = types->types + types->alloc; t < tend; t++)
1297 t->type = DEBUG_TYPE_NULL;
1299 types->alloc = nalloc;
1304 ieee_error (abfd, bytes, *pp, "unknown TY code");
1311 if (! ieee_read_number (abfd, bytes, pp, pend, &varindx))
1316 ieee_error (abfd, bytes, ty_var_start, "illegal variable index");
1321 if (varindx >= vars->alloc || vars->vars[varindx].name == NULL)
1323 ieee_error (abfd, bytes, ty_var_start, "undefined variable in TY");
1327 ty_code_start = *pp;
1329 if (! ieee_read_number (abfd, bytes, pp, pend, &tc))
1335 return_type = DEBUG_TYPE_NULL;
1339 ieee_error (abfd, bytes, ty_code_start, "unknown TY code");
1343 /* Unknown type, with size. We treat it as int. FIXME. */
1347 if (! ieee_read_number (abfd, bytes, pp, pend, &size))
1349 type = debug_make_int_type (dhandle, size, false);
1353 case 'A': /* Array. */
1354 case 'a': /* FORTRAN array in column/row order. FIXME: Not
1355 distinguished from normal array. */
1357 debug_type ele_type;
1358 bfd_vma lower, upper;
1360 if (! ieee_read_type_index (dhandle, abfd, types, bytes, pp, pend,
1362 || ! ieee_read_number (abfd, bytes, pp, pend, &lower)
1363 || ! ieee_read_number (abfd, bytes, pp, pend, &upper))
1365 type = debug_make_array_type (dhandle, ele_type,
1366 debug_make_int_type (dhandle, 4, false),
1367 (bfd_signed_vma) lower,
1368 (bfd_signed_vma) upper,
1374 /* Simple enumeration. */
1380 bfd_signed_vma *vals;
1383 if (! ieee_read_number (abfd, bytes, pp, pend, &size))
1385 /* FIXME: we ignore the enumeration size. */
1388 names = (const char **) xmalloc (alloc * sizeof *names);
1389 memset (names, 0, alloc * sizeof *names);
1394 unsigned long namlen;
1397 if (! ieee_read_optional_id (abfd, bytes, pp, pend, &name,
1406 names = ((const char **)
1407 xrealloc (names, alloc * sizeof *names));
1410 names[c] = savestring (name, namlen);
1411 if (names[c] == NULL)
1418 vals = (bfd_signed_vma *) xmalloc (c * sizeof *vals);
1419 for (i = 0; i < c; i++)
1422 type = debug_make_enum_type (dhandle, names, vals);
1428 /* Struct with bit fields. */
1432 debug_field *fields;
1435 if (! ieee_read_number (abfd, bytes, pp, pend, &size))
1439 fields = (debug_field *) xmalloc (alloc * sizeof *fields);
1444 unsigned long namlen;
1447 bfd_vma bitpos, bitsize;
1449 if (! ieee_read_optional_id (abfd, bytes, pp, pend, &name,
1454 if (! ieee_read_type_index (dhandle, abfd, types, bytes, pp, pend,
1456 || ! ieee_read_number (abfd, bytes, pp, pend, &bitpos)
1457 || ! ieee_read_number (abfd, bytes, pp, pend, &bitsize))
1463 fields = ((debug_field *)
1464 xrealloc (fields, alloc * sizeof *fields));
1467 fields[c] = debug_make_field (dhandle, savestring (name, namlen),
1468 ftype, bitpos, bitsize,
1469 DEBUG_VISIBILITY_PUBLIC);
1470 if (fields[c] == NULL)
1477 type = debug_make_struct_type (dhandle, true, size, fields);
1487 bfd_signed_vma *vals;
1491 names = (const char **) xmalloc (alloc * sizeof *names);
1492 vals = (bfd_signed_vma *) xmalloc (alloc * sizeof *names);
1497 unsigned long namlen;
1501 if (! ieee_read_optional_id (abfd, bytes, pp, pend, &name,
1506 if (! ieee_read_number (abfd, bytes, pp, pend, &val))
1509 /* If the length of the name is zero, then the value is
1510 actually the size of the enum. We ignore this
1511 information. FIXME. */
1518 names = ((const char **)
1519 xrealloc (names, alloc * sizeof *names));
1520 vals = ((bfd_signed_vma *)
1521 xrealloc (vals, alloc * sizeof *vals));
1524 names[c] = savestring (name, namlen);
1525 if (names[c] == NULL)
1527 vals[c] = (bfd_signed_vma) val;
1533 type = debug_make_enum_type (dhandle, names, vals);
1538 case 'O': /* Small pointer. We don't distinguish small and large
1540 case 'P': /* Large pointer. */
1544 if (! ieee_read_type_index (dhandle, abfd, types, bytes, pp, pend, &t))
1546 type = debug_make_pointer_type (dhandle, t);
1553 bfd_vma low, high, signedp, size;
1555 if (! ieee_read_number (abfd, bytes, pp, pend, &low)
1556 || ! ieee_read_number (abfd, bytes, pp, pend, &high)
1557 || ! ieee_read_number (abfd, bytes, pp, pend, &signedp)
1558 || ! ieee_read_number (abfd, bytes, pp, pend, &size))
1561 type = debug_make_range_type (dhandle,
1562 debug_make_int_type (dhandle, size,
1564 (bfd_signed_vma) low,
1565 (bfd_signed_vma) high);
1569 case 'S': /* Struct. */
1570 case 'U': /* Union. */
1574 debug_field *fields;
1577 if (! ieee_read_number (abfd, bytes, pp, pend, &size))
1581 fields = (debug_field *) xmalloc (alloc * sizeof *fields);
1586 unsigned long namlen;
1593 if (! ieee_read_optional_id (abfd, bytes, pp, pend, &name,
1598 if (! ieee_read_number (abfd, bytes, pp, pend, &tindx)
1599 || ! ieee_read_number (abfd, bytes, pp, pend, &offset))
1604 ftype = ieee_builtin_type (dhandle, abfd, types, bytes,
1605 ty_code_start, tindx);
1611 struct ieee_type *t;
1614 if (tindx >= types->alloc
1615 || types->types[tindx].type == DEBUG_TYPE_NULL)
1617 ieee_error (abfd, bytes, ty_start, "undefined type index");
1620 t = &types->types[tindx];
1622 bitsize = t->bitsize;
1630 fields = ((debug_field *)
1631 xrealloc (fields, alloc * sizeof *fields));
1634 fields[c] = debug_make_field (dhandle, savestring (name, namlen),
1635 ftype, offset, bitsize,
1636 DEBUG_VISIBILITY_PUBLIC);
1637 if (fields[c] == NULL)
1644 type = debug_make_struct_type (dhandle, tc == 'S', size, fields);
1651 if (! ieee_read_type_index (dhandle, abfd, types, bytes, pp, pend,
1658 /* Procedure. FIXME: This is an extern declaration, which we
1659 have no way of representing. */
1666 /* FIXME: We ignore the attribute and the argument names. */
1668 if (! ieee_read_number (abfd, bytes, pp, pend, &attr)
1669 || ! ieee_read_type_index (dhandle, abfd, types, bytes, pp, pend,
1671 || ! ieee_read_number (abfd, bytes, pp, pend, &nargs))
1676 unsigned long namlen;
1678 if (! ieee_read_optional_id (abfd, bytes, pp, pend, &name,
1684 type = debug_make_function_type (dhandle, rtype);
1685 return_type = rtype;
1690 /* Array with 0 lower bound. */
1695 if (! ieee_read_type_index (dhandle, abfd, types, bytes, pp, pend,
1697 || ! ieee_read_number (abfd, bytes, pp, pend, &high))
1700 type = debug_make_array_type (dhandle, etype,
1701 debug_make_int_type (dhandle, 4, false),
1702 0, (bfd_signed_vma) high, false);
1706 case 'c': /* Complex. */
1707 case 'd': /* Double complex. */
1710 unsigned long namlen;
1712 /* FIXME: I don't know what the name means. */
1714 if (! ieee_read_id (abfd, bytes, pp, pend, &name, &namlen))
1717 type = debug_make_complex_type (dhandle, tc == 'c' ? 4 : 8);
1722 /* Pascal file name. FIXME. */
1723 ieee_error (abfd, bytes, ty_code_start,
1724 "Pascal file name not supported");
1728 /* Bitfield type. */
1730 bfd_vma signedp, bitsize;
1732 if (! ieee_read_number (abfd, bytes, pp, pend, &signedp)
1733 || ! ieee_read_number (abfd, bytes, pp, pend, &bitsize)
1734 || ! ieee_read_type_index (dhandle, abfd, types, bytes, pp, pend,
1738 /* FIXME: This is just a guess. */
1740 type = debug_make_int_type (dhandle, 4, true);
1741 type_bitsize = bitsize;
1751 if (! ieee_read_number (abfd, bytes, pp, pend, &kind)
1752 || ! ieee_read_type_index (dhandle, abfd, types, bytes, pp, pend,
1759 ieee_error (abfd, bytes, ty_start, "unsupported qualifer");
1763 type = debug_make_const_type (dhandle, t);
1767 type = debug_make_volatile_type (dhandle, t);
1779 if (! ieee_read_number (abfd, bytes, pp, pend, &size)
1780 || ! ieee_read_type_index (dhandle, abfd, types, bytes, pp, pend,
1784 /* FIXME: We ignore the size. */
1786 type = debug_make_set_type (dhandle, etype, false);
1791 /* Procedure with compiler dependencies. FIXME: This is an
1792 extern declaration, which we have no way of representing. */
1794 bfd_vma attr, frame_type, push_mask, nargs, level, father;
1798 /* FIXME: We ignore almost all this information. */
1800 if (! ieee_read_number (abfd, bytes, pp, pend, &attr)
1801 || ! ieee_read_number (abfd, bytes, pp, pend, &frame_type)
1802 || ! ieee_read_number (abfd, bytes, pp, pend, &push_mask)
1803 || ! ieee_read_type_index (dhandle, abfd, types, bytes, pp, pend,
1805 || ! ieee_read_number (abfd, bytes, pp, pend, &nargs))
1807 if (nargs != (bfd_vma) -1)
1809 for (; nargs > 0; nargs--)
1813 if (! ieee_read_type_index (dhandle, abfd, types, bytes, pp,
1818 if (! ieee_read_number (abfd, bytes, pp, pend, &level)
1819 || ! ieee_read_optional_number (abfd, bytes, pp, pend, &father,
1823 type = debug_make_function_type (dhandle, rtype);
1824 return_type = rtype;
1829 /* Record the type in the table. If the corresponding NN record has
1830 a name, name it. FIXME: Is this always correct? */
1836 && vars->vars[varindx].namlen > 0)
1840 name = savestring (vars->vars[varindx].name,
1841 vars->vars[varindx].namlen);
1843 type = debug_tag_type (dhandle, name, type);
1845 type = debug_name_type (dhandle, name, type);
1850 types->types[typeindx].type = type;
1851 types->types[typeindx].bitsize = type_bitsize;
1852 types->types[typeindx].return_type = return_type;
1857 /* Parse an ATN record. */
1860 parse_ieee_atn (dhandle, abfd, types, vars, blocktype, bytes, pp, pend)
1863 struct ieee_types *types;
1864 struct ieee_vars *vars;
1866 const bfd_byte *bytes;
1867 const bfd_byte **pp;
1868 const bfd_byte *pend;
1870 const bfd_byte *atn_start, *atn_code_start;
1875 bfd_vma v, v2, v3, v4, v5;
1877 unsigned long namlen;
1883 if (! ieee_read_number (abfd, bytes, pp, pend, &varindx)
1884 || ! ieee_read_type_index (dhandle, abfd, types, bytes, pp, pend, &type))
1887 atn_code_start = *pp;
1889 if (! ieee_read_number (abfd, bytes, pp, pend, &atn_code))
1898 else if (varindx < 32)
1900 ieee_error (abfd, bytes, atn_start, "illegal variable index");
1907 if (varindx >= vars->alloc || vars->vars[varindx].name == NULL)
1909 ieee_error (abfd, bytes, atn_start, "undefined variable in ATN");
1913 vars->vars[varindx].type = type;
1915 name = vars->vars[varindx].name;
1916 namlen = vars->vars[varindx].namlen;
1922 ieee_error (abfd, bytes, atn_code_start, "unknown ATN type");
1926 /* Automatic variable. */
1927 if (! ieee_read_number (abfd, bytes, pp, pend, &v))
1929 namcopy = savestring (name, namlen);
1931 type = debug_make_void_type (dhandle);
1932 return debug_record_variable (dhandle, namcopy, type, DEBUG_LOCAL, v);
1935 /* Register variable. */
1936 if (! ieee_read_number (abfd, bytes, pp, pend, &v))
1938 namcopy = savestring (name, namlen);
1940 type = debug_make_void_type (dhandle);
1941 return debug_record_variable (dhandle, namcopy, type, DEBUG_REGISTER,
1942 ieee_regno_to_gen (abfd, v));
1945 /* Static variable. */
1946 if (! ieee_require_asn (abfd, bytes, pp, pend, &v))
1948 namcopy = savestring (name, namlen);
1950 type = debug_make_void_type (dhandle);
1951 return debug_record_variable (dhandle, namcopy, type,
1952 (blocktype == 4 || blocktype == 6
1953 ? DEBUG_LOCAL_STATIC
1958 /* External function. We don't currently record these. FIXME. */
1962 /* External variable. We don't currently record these. FIXME. */
1966 if (! ieee_read_number (abfd, bytes, pp, pend, &v)
1967 || ! ieee_read_number (abfd, bytes, pp, pend, &v2)
1968 || ! ieee_read_optional_number (abfd, bytes, pp, pend, &v3,
1973 if (! ieee_read_optional_number (abfd, bytes, pp, pend, &v4,
1978 /* We just ignore the two optional fields in v3 and v4, since
1979 they are not defined. */
1981 if (! ieee_require_asn (abfd, bytes, pp, pend, &v3))
1984 /* We have no way to record the column number. FIXME. */
1986 return debug_record_line (dhandle, v, v3);
1989 /* Global variable. */
1990 if (! ieee_require_asn (abfd, bytes, pp, pend, &v))
1992 namcopy = savestring (name, namlen);
1994 type = debug_make_void_type (dhandle);
1995 return debug_record_variable (dhandle, namcopy, type, DEBUG_GLOBAL, v);
1998 /* Variable lifetime information. */
1999 if (! ieee_read_number (abfd, bytes, pp, pend, &v))
2002 /* We have no way to record this information. FIXME. */
2006 /* Locked register. */
2007 if (! ieee_read_number (abfd, bytes, pp, pend, &v)
2008 || ! ieee_read_number (abfd, bytes, pp, pend, &v2))
2011 /* I don't know what this means. FIXME. */
2013 ieee_error (abfd, bytes, atn_code_start, "unsupported ATN10");
2015 /* Return true to keep going. */
2019 /* Reserved for FORTRAN common. */
2020 ieee_error (abfd, bytes, atn_code_start, "unsupported ATN11");
2022 /* Return true to keep going. */
2026 /* Based variable. */
2030 if (! ieee_read_number (abfd, bytes, pp, pend, &v)
2031 || ! ieee_read_number (abfd, bytes, pp, pend, &v2)
2032 || ! ieee_read_optional_number (abfd, bytes, pp, pend, &v3,
2037 if (! ieee_read_optional_number (abfd, bytes, pp, pend, &v4,
2042 if (! ieee_read_optional_number (abfd, bytes, pp, pend, &v5,
2048 /* We have no way to record this information. FIXME. */
2050 ieee_error (abfd, bytes, atn_code_start, "unsupported ATN12");
2052 /* Return true to keep going. */
2056 /* Constant. The description of this that I have is ambiguous,
2057 so I'm not going to try to implement it. */
2058 ieee_error (abfd, bytes, atn_code_start, "unsupported ATN16");
2062 /* Static variable from assembler. */
2064 if (! ieee_read_number (abfd, bytes, pp, pend, &v)
2065 || ! ieee_read_optional_number (abfd, bytes, pp, pend, &v2,
2067 || ! ieee_require_asn (abfd, bytes, pp, pend, &v3))
2069 namcopy = savestring (name, namlen);
2070 /* We don't really handle this correctly. FIXME. */
2071 return debug_record_variable (dhandle, namcopy,
2072 debug_make_void_type (dhandle),
2073 v2 != 0 ? DEBUG_GLOBAL : DEBUG_STATIC,
2077 /* Procedure miscellaneous information. */
2079 /* Variable miscellaneous information. */
2081 /* Module miscellaneous information. */
2082 if (! ieee_read_number (abfd, bytes, pp, pend, &v)
2083 || ! ieee_read_number (abfd, bytes, pp, pend, &v2)
2084 || ! ieee_read_optional_id (abfd, bytes, pp, pend, &name, &namlen,
2088 /* We just ignore all of this stuff. FIXME. */
2090 for (; v2 > 0; --v2)
2092 ieee_record_enum_type c;
2095 unsigned long strlen;
2097 c = (ieee_record_enum_type) **pp;
2099 if (c != ieee_at_record_enum
2100 && c != ieee_e2_first_byte_enum)
2102 ieee_error (abfd, bytes, *pp - 1, "bad misc record");
2106 c = (ieee_record_enum_type) (((unsigned int) c << 8) | **pp);
2111 ieee_error (abfd, bytes, *pp - 2, "bad misc record");
2114 case ieee_atn_record_enum:
2115 if (! ieee_read_number (abfd, bytes, pp, pend, &vindx))
2117 if ((*pp)[0] != 0 || (*pp)[1] != 65)
2119 ieee_error (abfd, bytes, *pp, "bad atn in misc");
2123 if (! ieee_read_id (abfd, bytes, pp, pend, &str, &strlen))
2127 case ieee_asn_record_enum:
2128 if (! ieee_read_number (abfd, bytes, pp, pend, &vindx)
2129 || ! ieee_read_expression (abfd, bytes, pp, pend, &v3))
2141 /* Require an ASN record. */
2144 ieee_require_asn (abfd, bytes, pp, pend, pv)
2146 const bfd_byte *bytes;
2147 const bfd_byte **pp;
2148 const bfd_byte *pend;
2151 const bfd_byte *start;
2152 ieee_record_enum_type c;
2157 c = (ieee_record_enum_type) **pp;
2158 if (c != ieee_e2_first_byte_enum)
2160 ieee_error (abfd, bytes, start, "missing required ASN");
2165 c = (ieee_record_enum_type) (((unsigned int) c << 8) | **pp);
2166 if (c != ieee_asn_record_enum)
2168 ieee_error (abfd, bytes, start, "missing required ASN");
2173 /* Just ignore the variable index. */
2174 if (! ieee_read_number (abfd, bytes, pp, pend, &varindx))
2177 return ieee_read_expression (abfd, bytes, pp, pend, pv);