1 /* ieee.c -- Read and write IEEE-695 debugging information.
2 Copyright (C) 1996 Free Software Foundation, Inc.
3 Written by Ian Lance Taylor <ian@cygnus.com>.
5 This file is part of GNU Binutils.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22 /* This file reads and writes IEEE-695 debugging information. */
30 #include "libiberty.h"
34 /* This structure holds an entry on the block stack. */
38 /* The kind of block. */
40 /* The source file name, for a BB5 block. */
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;
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 /* This structure holds a linked last of structs with their tag names,
106 so that we can convert them to C++ classes if necessary. */
111 struct ieee_tag *next;
114 /* The type of the tag. */
116 /* The tagged type is an indirect type pointing at this slot. */
120 /* This structure holds a linked list of functions with their argument
121 types, so that we can convert them to C++ methods if necessary. */
126 struct ieee_function *next;
127 /* This function name. */
129 /* The function type. */
133 /* This structure holds the information we pass around to the parsing
138 /* The debugging handle. */
142 /* The start of the bytes to be parsed. */
143 const bfd_byte *bytes;
144 /* The end of the bytes to be parsed. */
145 const bfd_byte *pend;
146 /* The block stack. */
147 struct ieee_blockstack blockstack;
149 struct ieee_vars vars;
151 struct ieee_types types;
152 /* The list of tagged structs. */
153 struct ieee_tag *tags;
154 /* The list of functions. */
155 struct ieee_function *functions;
158 /* Basic builtin types, not including the pointers. */
164 builtin_signed_char = 2,
165 builtin_unsigned_char = 3,
166 builtin_signed_short_int = 4,
167 builtin_unsigned_short_int = 5,
168 builtin_signed_long = 6,
169 builtin_unsigned_long = 7,
170 builtin_signed_long_long = 8,
171 builtin_unsigned_long_long = 9,
174 builtin_long_double = 12,
175 builtin_long_long_double = 13,
176 builtin_quoted_string = 14,
177 builtin_instruction_address = 15,
179 builtin_unsigned = 17,
180 builtin_unsigned_int = 18,
184 builtin_unsigned_short = 22,
185 builtin_short_int = 23,
186 builtin_signed_short = 24,
187 builtin_bcd_float = 25
190 /* These are the values found in the derivation flags of a 'b'
191 component record of a 'T' type extension record in a C++ pmisc
192 record. These are bitmasks. */
194 /* Set for a private base class, clear for a public base class.
195 Protected base classes are not supported. */
196 #define BASEFLAGS_PRIVATE (0x1)
197 /* Set for a virtual base class. */
198 #define BASEFLAGS_VIRTUAL (0x2)
199 /* Set for a friend class, clear for a base class. */
200 #define BASEFLAGS_FRIEND (0x10)
202 /* These are the values found in the specs flags of a 'd', 'm', or 'v'
203 component record of a 'T' type extension record in a C++ pmisc
204 record. The same flags are used for a 'M' record in a C++ pmisc
207 /* The lower two bits hold visibility information. */
208 #define CXXFLAGS_VISIBILITY (0x3)
209 /* This value in the lower two bits indicates a public member. */
210 #define CXXFLAGS_VISIBILITY_PUBLIC (0x0)
211 /* This value in the lower two bits indicates a private member. */
212 #define CXXFLAGS_VISIBILITY_PRIVATE (0x1)
213 /* This value in the lower two bits indicates a protected member. */
214 #define CXXFLAGS_VISIBILITY_PROTECTED (0x2)
215 /* Set for a static member. */
216 #define CXXFLAGS_STATIC (0x4)
217 /* Set for a virtual override. */
218 #define CXXFLAGS_OVERRIDE (0x8)
219 /* Set for a friend function. */
220 #define CXXFLAGS_FRIEND (0x10)
221 /* Set for a const function. */
222 #define CXXFLAGS_CONST (0x20)
223 /* Set for a volatile function. */
224 #define CXXFLAGS_VOLATILE (0x40)
225 /* Set for an overloaded function. */
226 #define CXXFLAGS_OVERLOADED (0x80)
227 /* Set for an operator function. */
228 #define CXXFLAGS_OPERATOR (0x100)
229 /* Set for a constructor or destructor. */
230 #define CXXFLAGS_CTORDTOR (0x400)
231 /* Set for a constructor. */
232 #define CXXFLAGS_CTOR (0x200)
233 /* Set for an inline function. */
234 #define CXXFLAGS_INLINE (0x800)
236 /* Local functions. */
238 static void ieee_error
239 PARAMS ((struct ieee_info *, const bfd_byte *, const char *));
240 static void ieee_eof PARAMS ((struct ieee_info *));
241 static char *savestring PARAMS ((const char *, unsigned long));
242 static boolean ieee_read_number
243 PARAMS ((struct ieee_info *, const bfd_byte **, bfd_vma *));
244 static boolean ieee_read_optional_number
245 PARAMS ((struct ieee_info *, const bfd_byte **, bfd_vma *, boolean *));
246 static boolean ieee_read_id
247 PARAMS ((struct ieee_info *, const bfd_byte **, const char **,
249 static boolean ieee_read_optional_id
250 PARAMS ((struct ieee_info *, const bfd_byte **, const char **,
251 unsigned long *, boolean *));
252 static boolean ieee_read_expression
253 PARAMS ((struct ieee_info *, const bfd_byte **, bfd_vma *));
254 static debug_type ieee_builtin_type
255 PARAMS ((struct ieee_info *, const bfd_byte *, unsigned int));
256 static boolean ieee_alloc_type
257 PARAMS ((struct ieee_info *, unsigned int, boolean));
258 static boolean ieee_read_type_index
259 PARAMS ((struct ieee_info *, const bfd_byte **, debug_type *));
260 static int ieee_regno_to_genreg PARAMS ((bfd *, int));
261 static int ieee_genreg_to_regno PARAMS ((bfd *, int));
262 static boolean parse_ieee_bb PARAMS ((struct ieee_info *, const bfd_byte **));
263 static boolean parse_ieee_be PARAMS ((struct ieee_info *, const bfd_byte **));
264 static boolean parse_ieee_nn PARAMS ((struct ieee_info *, const bfd_byte **));
265 static boolean parse_ieee_ty PARAMS ((struct ieee_info *, const bfd_byte **));
266 static boolean parse_ieee_atn PARAMS ((struct ieee_info *, const bfd_byte **));
267 static boolean ieee_read_cxx_misc
268 PARAMS ((struct ieee_info *, const bfd_byte **, unsigned long));
269 static boolean ieee_read_cxx_class
270 PARAMS ((struct ieee_info *, const bfd_byte **, unsigned long));
271 static boolean ieee_require_asn
272 PARAMS ((struct ieee_info *, const bfd_byte **, bfd_vma *));
273 static boolean ieee_require_atn65
274 PARAMS ((struct ieee_info *, const bfd_byte **, const char **,
277 /* Report an error in the IEEE debugging information. */
280 ieee_error (info, p, s)
281 struct ieee_info *info;
286 fprintf (stderr, "%s: 0x%lx: %s (0x%x)\n", bfd_get_filename (info->abfd),
287 (unsigned long) (p - info->bytes), s, *p);
289 fprintf (stderr, "%s: %s\n", bfd_get_filename (info->abfd), s);
292 /* Report an unexpected EOF in the IEEE debugging information. */
296 struct ieee_info *info;
298 ieee_error (info, (const bfd_byte *) NULL,
299 "unexpected end of debugging information");
302 /* Save a string in memory. */
305 savestring (start, len)
311 ret = (char *) xmalloc (len + 1);
312 memcpy (ret, start, len);
317 /* Read a number which must be present in an IEEE file. */
320 ieee_read_number (info, pp, pv)
321 struct ieee_info *info;
325 return ieee_read_optional_number (info, pp, pv, (boolean *) NULL);
328 /* Read a number in an IEEE file. If ppresent is not NULL, the number
329 need not be there. */
332 ieee_read_optional_number (info, pp, pv, ppresent)
333 struct ieee_info *info;
338 ieee_record_enum_type b;
340 if (*pp >= info->pend)
342 if (ppresent != NULL)
351 b = (ieee_record_enum_type) **pp;
354 if (b <= ieee_number_end_enum)
357 if (ppresent != NULL)
362 if (b >= ieee_number_repeat_start_enum && b <= ieee_number_repeat_end_enum)
366 i = (int) b - (int) ieee_number_repeat_start_enum;
367 if (*pp + i - 1 >= info->pend)
381 if (ppresent != NULL)
387 if (ppresent != NULL)
394 ieee_error (info, *pp - 1, "invalid number");
398 /* Read a required string from an IEEE file. */
401 ieee_read_id (info, pp, pname, pnamlen)
402 struct ieee_info *info;
405 unsigned long *pnamlen;
407 return ieee_read_optional_id (info, pp, pname, pnamlen, (boolean *) NULL);
410 /* Read a string from an IEEE file. If ppresent is not NULL, the
411 string is optional. */
414 ieee_read_optional_id (info, pp, pname, pnamlen, ppresent)
415 struct ieee_info *info;
418 unsigned long *pnamlen;
424 if (*pp >= info->pend)
435 else if ((ieee_record_enum_type) b == ieee_extension_length_1_enum)
440 else if ((ieee_record_enum_type) b == ieee_extension_length_2_enum)
442 len = (**pp << 8) + (*pp)[1];
447 if (ppresent != NULL)
453 ieee_error (info, *pp - 1, "invalid string length");
457 if ((unsigned long) (info->pend - *pp) < len)
463 *pname = (const char *) *pp;
467 if (ppresent != NULL)
473 /* Read an expression from an IEEE file. Since this code is only used
474 to parse debugging information, I haven't bothered to write a full
475 blown IEEE expression parser. I've only thrown in the things I've
476 seen in debugging information. This can be easily extended if
480 ieee_read_expression (info, pp, pv)
481 struct ieee_info *info;
485 const bfd_byte *expr_start;
486 #define EXPR_STACK_SIZE (10)
487 bfd_vma expr_stack[EXPR_STACK_SIZE];
496 const bfd_byte *start;
499 ieee_record_enum_type c;
503 if (! ieee_read_optional_number (info, pp, &val, &present))
508 if (esp - expr_stack >= EXPR_STACK_SIZE)
510 ieee_error (info, start, "expression stack overflow");
517 c = (ieee_record_enum_type) **pp;
519 if (c >= ieee_module_beginning_enum)
530 ieee_error (info, start, "unsupported IEEE expression operator");
533 case ieee_variable_R_enum:
538 if (! ieee_read_number (info, pp, &indx))
540 for (s = info->abfd->sections; s != NULL; s = s->next)
541 if ((bfd_vma) s->target_index == indx)
545 ieee_error (info, start, "unknown section");
549 if (esp - expr_stack >= EXPR_STACK_SIZE)
551 ieee_error (info, start, "expression stack overflow");
555 *esp++ = bfd_get_section_vma (info->abfd, s);
559 case ieee_function_plus_enum:
560 case ieee_function_minus_enum:
564 if (esp - expr_stack < 2)
566 ieee_error (info, start, "expression stack underflow");
578 if (esp - 1 != expr_stack)
580 ieee_error (info, expr_start, "expression stack mismatch");
589 /* Return an IEEE builtin type. */
592 ieee_builtin_type (info, p, indx)
593 struct ieee_info *info;
601 if (indx < BUILTIN_TYPE_COUNT
602 && info->types.builtins[indx] != DEBUG_TYPE_NULL)
603 return info->types.builtins[indx];
605 dhandle = info->dhandle;
607 if (indx >= 32 && indx < 64)
609 type = debug_make_pointer_type (dhandle,
610 ieee_builtin_type (info, p, indx - 32));
611 assert (indx < BUILTIN_TYPE_COUNT);
612 info->types.builtins[indx] = type;
616 switch ((enum builtin_types) indx)
619 ieee_error (info, p, "unknown builtin type");
622 case builtin_unknown:
623 type = debug_make_void_type (dhandle);
628 type = debug_make_void_type (dhandle);
632 case builtin_signed_char:
633 type = debug_make_int_type (dhandle, 1, false);
634 name = "signed char";
637 case builtin_unsigned_char:
638 type = debug_make_int_type (dhandle, 1, true);
639 name = "unsigned char";
642 case builtin_signed_short_int:
643 type = debug_make_int_type (dhandle, 2, false);
644 name = "signed short int";
647 case builtin_unsigned_short_int:
648 type = debug_make_int_type (dhandle, 2, true);
649 name = "unsigned short int";
652 case builtin_signed_long:
653 type = debug_make_int_type (dhandle, 4, false);
654 name = "signed long";
657 case builtin_unsigned_long:
658 type = debug_make_int_type (dhandle, 4, true);
659 name = "unsigned long";
662 case builtin_signed_long_long:
663 type = debug_make_int_type (dhandle, 8, false);
664 name = "signed long long";
667 case builtin_unsigned_long_long:
668 type = debug_make_int_type (dhandle, 8, true);
669 name = "unsigned long long";
673 type = debug_make_float_type (dhandle, 4);
678 type = debug_make_float_type (dhandle, 8);
682 case builtin_long_double:
683 /* FIXME: The size for this type should depend upon the
685 type = debug_make_float_type (dhandle, 12);
686 name = "long double";
689 case builtin_long_long_double:
690 type = debug_make_float_type (dhandle, 16);
691 name = "long long double";
694 case builtin_quoted_string:
695 type = debug_make_array_type (dhandle,
696 ieee_builtin_type (info, p,
699 ieee_builtin_type (info, p,
703 name = "QUOTED STRING";
706 case builtin_instruction_address:
707 /* FIXME: This should be a code address. */
708 type = debug_make_int_type (dhandle, 4, true);
709 name = "instruction address";
713 /* FIXME: The size for this type should depend upon the
715 type = debug_make_int_type (dhandle, 4, false);
719 case builtin_unsigned:
720 /* FIXME: The size for this type should depend upon the
722 type = debug_make_int_type (dhandle, 4, true);
726 case builtin_unsigned_int:
727 /* FIXME: The size for this type should depend upon the
729 type = debug_make_int_type (dhandle, 4, true);
730 name = "unsigned int";
734 type = debug_make_int_type (dhandle, 1, false);
739 type = debug_make_int_type (dhandle, 4, false);
744 type = debug_make_int_type (dhandle, 2, false);
748 case builtin_unsigned_short:
749 type = debug_make_int_type (dhandle, 2, true);
750 name = "unsigned short";
753 case builtin_short_int:
754 type = debug_make_int_type (dhandle, 2, false);
758 case builtin_signed_short:
759 type = debug_make_int_type (dhandle, 2, false);
760 name = "signed short";
763 case builtin_bcd_float:
764 ieee_error (info, p, "BCD float type not supported");
769 type = debug_name_type (dhandle, name, type);
771 assert (indx < BUILTIN_TYPE_COUNT);
773 info->types.builtins[indx] = type;
778 /* Allocate more space in the type table. If ref is true, this is a
779 reference to the type; if it is not already defined, we should set
780 up an indirect type. */
783 ieee_alloc_type (info, indx, ref)
784 struct ieee_info *info;
789 register struct ieee_type *t;
790 struct ieee_type *tend;
792 if (indx >= info->types.alloc)
794 nalloc = info->types.alloc;
797 while (indx >= nalloc)
800 info->types.types = ((struct ieee_type *)
801 xrealloc (info->types.types,
802 nalloc * sizeof *info->types.types));
804 memset (info->types.types + info->types.alloc, 0,
805 (nalloc - info->types.alloc) * sizeof *info->types.types);
807 tend = info->types.types + nalloc;
808 for (t = info->types.types + info->types.alloc; t < tend; t++)
809 t->type = DEBUG_TYPE_NULL;
811 info->types.alloc = nalloc;
816 t = info->types.types + indx;
819 t->pslot = (debug_type *) xmalloc (sizeof *t->pslot);
820 *t->pslot = DEBUG_TYPE_NULL;
821 t->type = debug_make_indirect_type (info->dhandle, t->pslot,
822 (const char *) NULL);
831 /* Read a type index and return the corresponding type. */
834 ieee_read_type_index (info, pp, ptype)
835 struct ieee_info *info;
839 const bfd_byte *start;
844 if (! ieee_read_number (info, pp, &indx))
849 *ptype = ieee_builtin_type (info, start, indx);
856 if (! ieee_alloc_type (info, indx, true))
859 *ptype = info->types.types[indx].type;
864 /* Parse IEEE debugging information for a file. This is passed the
865 bytes which compose the Debug Information Part of an IEEE file. */
868 parse_ieee (dhandle, abfd, bytes, len)
871 const bfd_byte *bytes;
874 struct ieee_info info;
876 const bfd_byte *p, *pend;
878 info.dhandle = dhandle;
881 info.pend = bytes + len;
882 info.blockstack.bsp = info.blockstack.stack;
884 info.vars.vars = NULL;
885 info.types.alloc = 0;
886 info.types.types = NULL;
888 info.functions = NULL;
889 for (i = 0; i < BUILTIN_TYPE_COUNT; i++)
890 info.types.builtins[i] = DEBUG_TYPE_NULL;
896 const bfd_byte *record_start;
897 ieee_record_enum_type c;
901 c = (ieee_record_enum_type) *p++;
903 if (c == ieee_at_record_enum)
904 c = (ieee_record_enum_type) (((unsigned int) c << 8) | *p++);
906 if (c <= ieee_number_repeat_end_enum)
908 ieee_error (&info, record_start, "unexpected number");
915 ieee_error (&info, record_start, "unexpected record type");
918 case ieee_bb_record_enum:
919 if (! parse_ieee_bb (&info, &p))
923 case ieee_be_record_enum:
924 if (! parse_ieee_be (&info, &p))
929 if (! parse_ieee_nn (&info, &p))
933 case ieee_ty_record_enum:
934 if (! parse_ieee_ty (&info, &p))
938 case ieee_atn_record_enum:
939 if (! parse_ieee_atn (&info, &p))
945 if (info.blockstack.bsp != info.blockstack.stack)
947 ieee_error (&info, (const bfd_byte *) NULL,
948 "blocks left on stack at end");
955 /* Handle an IEEE BB record. */
958 parse_ieee_bb (info, pp)
959 struct ieee_info *info;
962 const bfd_byte *block_start;
966 unsigned long namlen;
974 if (! ieee_read_number (info, pp, &size)
975 || ! ieee_read_id (info, pp, &name, &namlen))
981 /* BB1: Type definitions local to a module. */
982 namcopy = savestring (name, namlen);
985 if (! debug_set_filename (info->dhandle, namcopy))
990 /* BB2: Global type definitions. The name is supposed to be
991 empty, but we don't check. */
992 if (! debug_set_filename (info->dhandle, "*global*"))
997 /* BB3: High level module block begin. We don't have to do
998 anything here. The name is supposed to be the same as for
999 the BB1, but we don't check. */
1003 /* BB4: Global function. */
1005 bfd_vma stackspace, typindx, offset;
1006 debug_type type, return_type;
1007 struct ieee_function *func;
1009 if (! ieee_read_number (info, pp, &stackspace)
1010 || ! ieee_read_number (info, pp, &typindx)
1011 || ! ieee_read_expression (info, pp, &offset))
1014 /* We have no way to record the stack space. FIXME. */
1018 type = ieee_builtin_type (info, block_start, typindx);
1026 if (! ieee_alloc_type (info, typindx, true))
1028 type = info->types.types[typindx].type;
1029 if (debug_get_type_kind (info->dhandle, type)
1030 != DEBUG_KIND_FUNCTION)
1033 return_type = debug_get_return_type (info->dhandle, type);
1036 namcopy = savestring (name, namlen);
1037 if (namcopy == NULL)
1039 if (! debug_record_function (info->dhandle, namcopy, return_type,
1043 func = (struct ieee_function *) xmalloc (sizeof *func);
1044 memset (func, 0, sizeof *func);
1045 func->next = info->functions;
1046 info->functions = func;
1047 func->name = namcopy;
1053 /* BB5: File name for source line numbers. */
1057 /* We ignore the date and time. FIXME. */
1058 for (i = 0; i < 6; i++)
1063 if (! ieee_read_optional_number (info, pp, &ignore, &present))
1069 namcopy = savestring (name, namlen);
1070 if (namcopy == NULL)
1072 if (! debug_start_source (info->dhandle, namcopy))
1078 /* BB6: Local function or block. */
1080 bfd_vma stackspace, typindx, offset;
1082 if (! ieee_read_number (info, pp, &stackspace)
1083 || ! ieee_read_number (info, pp, &typindx)
1084 || ! ieee_read_expression (info, pp, &offset))
1087 /* We have no way to record the stack space. FIXME. */
1091 if (! debug_start_block (info->dhandle, offset))
1093 /* Change b to indicate that this is a block
1094 rather than a function. */
1099 debug_type return_type;
1103 return_type = ieee_builtin_type (info, block_start, typindx);
1104 if (return_type == NULL)
1110 if (! ieee_alloc_type (info, typindx, true))
1112 return_type = info->types.types[typindx].type;
1113 if (debug_get_type_kind (info->dhandle, return_type)
1114 == DEBUG_KIND_FUNCTION)
1115 return_type = debug_get_return_type (info->dhandle,
1119 namcopy = savestring (name, namlen);
1120 if (namcopy == NULL)
1122 if (! debug_record_function (info->dhandle, namcopy, return_type,
1130 /* BB10: Assembler module scope. We completely ignore all this
1131 information. FIXME. */
1133 const char *inam, *vstr;
1134 unsigned long inamlen, vstrlen;
1139 if (! ieee_read_id (info, pp, &inam, &inamlen)
1140 || ! ieee_read_number (info, pp, &tool_type)
1141 || ! ieee_read_optional_id (info, pp, &vstr, &vstrlen, &present))
1143 for (i = 0; i < 6; i++)
1147 if (! ieee_read_optional_number (info, pp, &ignore, &present))
1156 /* BB11: Module section. We completely ignore all this
1157 information. FIXME. */
1159 bfd_vma sectype, secindx, offset, map;
1162 if (! ieee_read_number (info, pp, §ype)
1163 || ! ieee_read_number (info, pp, &secindx)
1164 || ! ieee_read_expression (info, pp, &offset)
1165 || ! ieee_read_optional_number (info, pp, &map, &present))
1171 ieee_error (info, block_start, "unknown BB type");
1176 /* Push this block on the block stack. */
1178 if (info->blockstack.bsp >= info->blockstack.stack + BLOCKSTACK_SIZE)
1180 ieee_error (info, (const bfd_byte *) NULL, "stack overflow");
1184 info->blockstack.bsp->kind = b;
1186 info->blockstack.bsp->filename = namcopy;
1187 ++info->blockstack.bsp;
1192 /* Handle an IEEE BE record. */
1195 parse_ieee_be (info, pp)
1196 struct ieee_info *info;
1197 const bfd_byte **pp;
1201 if (info->blockstack.bsp <= info->blockstack.stack)
1203 ieee_error (info, *pp, "stack underflow");
1206 --info->blockstack.bsp;
1208 switch (info->blockstack.bsp->kind)
1212 if (! ieee_read_expression (info, pp, &offset))
1214 if (! debug_end_function (info->dhandle, offset))
1219 /* This is BE6 when BB6 started a block rather than a local
1221 if (! ieee_read_expression (info, pp, &offset))
1223 if (! debug_end_block (info->dhandle, offset))
1228 /* When we end a BB5, we look up the stack for the last BB5, if
1229 there is one, so that we can call debug_start_source. */
1230 if (info->blockstack.bsp > info->blockstack.stack)
1232 struct ieee_block *bl;
1234 bl = info->blockstack.bsp;
1240 if (! debug_start_source (info->dhandle, bl->filename))
1245 while (bl != info->blockstack.stack);
1250 if (! ieee_read_expression (info, pp, &offset))
1252 /* We just ignore the module size. FIXME. */
1256 /* Other block types do not have any trailing information. */
1263 /* Parse an NN record. */
1266 parse_ieee_nn (info, pp)
1267 struct ieee_info *info;
1268 const bfd_byte **pp;
1270 const bfd_byte *nn_start;
1273 unsigned long namlen;
1277 if (! ieee_read_number (info, pp, &varindx)
1278 || ! ieee_read_id (info, pp, &name, &namlen))
1283 ieee_error (info, nn_start, "illegal variable index");
1288 if (varindx >= info->vars.alloc)
1292 alloc = info->vars.alloc;
1295 while (varindx >= alloc)
1297 info->vars.vars = ((struct ieee_var *)
1298 xrealloc (info->vars.vars,
1299 alloc * sizeof *info->vars.vars));
1300 memset (info->vars.vars + info->vars.alloc, 0,
1301 (alloc - info->vars.alloc) * sizeof *info->vars.vars);
1302 info->vars.alloc = alloc;
1305 info->vars.vars[varindx].name = name;
1306 info->vars.vars[varindx].namlen = namlen;
1311 /* Parse a TY record. */
1314 parse_ieee_ty (info, pp)
1315 struct ieee_info *info;
1316 const bfd_byte **pp;
1318 const bfd_byte *ty_start, *ty_var_start, *ty_code_start;
1319 bfd_vma typeindx, varindx, tc;
1321 boolean tag, typdef;
1322 unsigned long type_bitsize;
1327 if (! ieee_read_number (info, pp, &typeindx))
1332 ieee_error (info, ty_start, "illegal type index");
1337 if (! ieee_alloc_type (info, typeindx, false))
1342 ieee_error (info, *pp, "unknown TY code");
1349 if (! ieee_read_number (info, pp, &varindx))
1354 ieee_error (info, ty_var_start, "illegal variable index");
1359 if (varindx >= info->vars.alloc || info->vars.vars[varindx].name == NULL)
1361 ieee_error (info, ty_var_start, "undefined variable in TY");
1365 ty_code_start = *pp;
1367 if (! ieee_read_number (info, pp, &tc))
1370 dhandle = info->dhandle;
1378 ieee_error (info, ty_code_start, "unknown TY code");
1382 /* Unknown type, with size. We treat it as int. FIXME. */
1386 if (! ieee_read_number (info, pp, &size))
1388 type = debug_make_int_type (dhandle, size, false);
1392 case 'A': /* Array. */
1393 case 'a': /* FORTRAN array in column/row order. FIXME: Not
1394 distinguished from normal array. */
1396 debug_type ele_type;
1397 bfd_vma lower, upper;
1399 if (! ieee_read_type_index (info, pp, &ele_type)
1400 || ! ieee_read_number (info, pp, &lower)
1401 || ! ieee_read_number (info, pp, &upper))
1403 type = debug_make_array_type (dhandle, ele_type,
1404 ieee_builtin_type (info, ty_code_start,
1407 (bfd_signed_vma) lower,
1408 (bfd_signed_vma) upper,
1414 /* Simple enumeration. */
1420 bfd_signed_vma *vals;
1423 if (! ieee_read_number (info, pp, &size))
1425 /* FIXME: we ignore the enumeration size. */
1428 names = (const char **) xmalloc (alloc * sizeof *names);
1429 memset (names, 0, alloc * sizeof *names);
1434 unsigned long namlen;
1437 if (! ieee_read_optional_id (info, pp, &name, &namlen, &present))
1445 names = ((const char **)
1446 xrealloc (names, alloc * sizeof *names));
1449 names[c] = savestring (name, namlen);
1450 if (names[c] == NULL)
1457 vals = (bfd_signed_vma *) xmalloc (c * sizeof *vals);
1458 for (i = 0; i < c; i++)
1461 type = debug_make_enum_type (dhandle, names, vals);
1467 /* Struct with bit fields. */
1471 debug_field *fields;
1474 if (! ieee_read_number (info, pp, &size))
1478 fields = (debug_field *) xmalloc (alloc * sizeof *fields);
1483 unsigned long namlen;
1486 bfd_vma bitpos, bitsize;
1488 if (! ieee_read_optional_id (info, pp, &name, &namlen, &present))
1492 if (! ieee_read_type_index (info, pp, &ftype)
1493 || ! ieee_read_number (info, pp, &bitpos)
1494 || ! ieee_read_number (info, pp, &bitsize))
1500 fields = ((debug_field *)
1501 xrealloc (fields, alloc * sizeof *fields));
1504 fields[c] = debug_make_field (dhandle, savestring (name, namlen),
1505 ftype, bitpos, bitsize,
1506 DEBUG_VISIBILITY_PUBLIC);
1507 if (fields[c] == NULL)
1514 type = debug_make_struct_type (dhandle, true, size, fields);
1524 bfd_signed_vma *vals;
1528 names = (const char **) xmalloc (alloc * sizeof *names);
1529 vals = (bfd_signed_vma *) xmalloc (alloc * sizeof *names);
1534 unsigned long namlen;
1538 if (! ieee_read_optional_id (info, pp, &name, &namlen, &present))
1542 if (! ieee_read_number (info, pp, &val))
1545 /* If the length of the name is zero, then the value is
1546 actually the size of the enum. We ignore this
1547 information. FIXME. */
1554 names = ((const char **)
1555 xrealloc (names, alloc * sizeof *names));
1556 vals = ((bfd_signed_vma *)
1557 xrealloc (vals, alloc * sizeof *vals));
1560 names[c] = savestring (name, namlen);
1561 if (names[c] == NULL)
1563 vals[c] = (bfd_signed_vma) val;
1569 type = debug_make_enum_type (dhandle, names, vals);
1574 case 'O': /* Small pointer. We don't distinguish small and large
1576 case 'P': /* Large pointer. */
1580 if (! ieee_read_type_index (info, pp, &t))
1582 type = debug_make_pointer_type (dhandle, t);
1589 bfd_vma low, high, signedp, size;
1591 if (! ieee_read_number (info, pp, &low)
1592 || ! ieee_read_number (info, pp, &high)
1593 || ! ieee_read_number (info, pp, &signedp)
1594 || ! ieee_read_number (info, pp, &size))
1597 type = debug_make_range_type (dhandle,
1598 debug_make_int_type (dhandle, size,
1600 (bfd_signed_vma) low,
1601 (bfd_signed_vma) high);
1605 case 'S': /* Struct. */
1606 case 'U': /* Union. */
1610 debug_field *fields;
1613 if (! ieee_read_number (info, pp, &size))
1617 fields = (debug_field *) xmalloc (alloc * sizeof *fields);
1622 unsigned long namlen;
1629 if (! ieee_read_optional_id (info, pp, &name, &namlen, &present))
1633 if (! ieee_read_number (info, pp, &tindx)
1634 || ! ieee_read_number (info, pp, &offset))
1639 ftype = ieee_builtin_type (info, ty_code_start, tindx);
1645 struct ieee_type *t;
1648 if (! ieee_alloc_type (info, tindx, true))
1650 t = info->types.types + tindx;
1652 bitsize = t->bitsize;
1660 fields = ((debug_field *)
1661 xrealloc (fields, alloc * sizeof *fields));
1664 fields[c] = debug_make_field (dhandle, savestring (name, namlen),
1665 ftype, offset, bitsize,
1666 DEBUG_VISIBILITY_PUBLIC);
1667 if (fields[c] == NULL)
1674 type = debug_make_struct_type (dhandle, tc == 'S', size, fields);
1681 if (! ieee_read_type_index (info, pp, &type))
1687 /* Procedure. FIXME: This is an extern declaration, which we
1688 have no way of representing. */
1695 /* FIXME: We ignore the attribute and the argument names. */
1697 if (! ieee_read_number (info, pp, &attr)
1698 || ! ieee_read_type_index (info, pp, &rtype)
1699 || ! ieee_read_number (info, pp, &nargs))
1704 unsigned long namlen;
1706 if (! ieee_read_optional_id (info, pp, &name, &namlen, &present))
1711 type = debug_make_function_type (dhandle, rtype, (debug_type *) NULL,
1717 /* Array with 0 lower bound. */
1722 if (! ieee_read_type_index (info, pp, &etype)
1723 || ! ieee_read_number (info, pp, &high))
1726 type = debug_make_array_type (dhandle, etype,
1727 ieee_builtin_type (info, ty_code_start,
1730 0, (bfd_signed_vma) high, false);
1734 case 'c': /* Complex. */
1735 case 'd': /* Double complex. */
1738 unsigned long namlen;
1740 /* FIXME: I don't know what the name means. */
1742 if (! ieee_read_id (info, pp, &name, &namlen))
1745 type = debug_make_complex_type (dhandle, tc == 'c' ? 4 : 8);
1750 /* Pascal file name. FIXME. */
1751 ieee_error (info, ty_code_start, "Pascal file name not supported");
1755 /* Bitfield type. */
1757 bfd_vma signedp, bitsize;
1759 if (! ieee_read_number (info, pp, &signedp)
1760 || ! ieee_read_number (info, pp, &bitsize)
1761 || ! ieee_read_type_index (info, pp, &type))
1764 /* FIXME: This is just a guess. */
1766 type = debug_make_int_type (dhandle, 4, true);
1767 type_bitsize = bitsize;
1777 if (! ieee_read_number (info, pp, &kind)
1778 || ! ieee_read_type_index (info, pp, &t))
1784 ieee_error (info, ty_start, "unsupported qualifer");
1788 type = debug_make_const_type (dhandle, t);
1792 type = debug_make_volatile_type (dhandle, t);
1804 if (! ieee_read_number (info, pp, &size)
1805 || ! ieee_read_type_index (info, pp, &etype))
1808 /* FIXME: We ignore the size. */
1810 type = debug_make_set_type (dhandle, etype, false);
1815 /* Procedure with compiler dependencies. FIXME: This is an
1816 extern declaration, which we have no way of representing. */
1818 bfd_vma attr, frame_type, push_mask, nargs, level, father;
1820 debug_type *arg_types;
1824 /* FIXME: We ignore almost all this information. */
1826 if (! ieee_read_number (info, pp, &attr)
1827 || ! ieee_read_number (info, pp, &frame_type)
1828 || ! ieee_read_number (info, pp, &push_mask)
1829 || ! ieee_read_type_index (info, pp, &rtype)
1830 || ! ieee_read_number (info, pp, &nargs))
1832 if (nargs == (bfd_vma) -1)
1841 arg_types = ((debug_type *)
1842 xmalloc ((nargs + 1) * sizeof *arg_types));
1843 for (i = 0; i < nargs; i++)
1844 if (! ieee_read_type_index (info, pp, arg_types + i))
1847 /* If the last type is pointer to void, this is really a
1848 varargs function. */
1854 last = arg_types[nargs - 1];
1855 if (debug_get_type_kind (dhandle, last) == DEBUG_KIND_POINTER
1856 && (debug_get_type_kind (dhandle,
1857 debug_get_target_type (dhandle,
1859 == DEBUG_KIND_VOID))
1866 arg_types[nargs] = DEBUG_TYPE_NULL;
1868 if (! ieee_read_number (info, pp, &level)
1869 || ! ieee_read_optional_number (info, pp, &father, &present))
1872 type = debug_make_function_type (dhandle, rtype, arg_types, varargs);
1877 /* Record the type in the table. If the corresponding NN record has
1878 a name, name it. FIXME: Is this always correct? */
1884 && info->vars.vars[varindx].namlen > 0)
1888 name = savestring (info->vars.vars[varindx].name,
1889 info->vars.vars[varindx].namlen);
1891 type = debug_name_type (dhandle, name, type);
1892 else if (tc == 'E' || tc == 'N')
1893 type = debug_tag_type (dhandle, name, type);
1896 struct ieee_tag *it;
1898 /* We must allocate all struct tags as indirect types, so
1899 that if we later see a definition of the tag as a C++
1900 record we can update the indirect slot and automatically
1901 change all the existing references. */
1902 it = (struct ieee_tag *) xmalloc (sizeof *it);
1903 memset (it, 0, sizeof *it);
1904 it->next = info->tags;
1909 type = debug_make_indirect_type (dhandle, &it->slot, name);
1910 type = debug_tag_type (dhandle, name, type);
1918 info->types.types[typeindx].type = type;
1919 info->types.types[typeindx].bitsize = type_bitsize;
1921 /* We may have already allocated type as an indirect type pointing
1922 to slot. It does no harm to replace the indirect type with the
1923 real type. Filling in slot as well handles the indirect types
1924 which are already hanging around. */
1925 if (info->types.types[typeindx].pslot != NULL)
1926 *info->types.types[typeindx].pslot = type;
1931 /* Parse an ATN record. */
1934 parse_ieee_atn (info, pp)
1935 struct ieee_info *info;
1936 const bfd_byte **pp;
1938 const bfd_byte *atn_start, *atn_code_start;
1944 bfd_vma v, v2, v3, v4, v5;
1946 unsigned long namlen;
1953 if (! ieee_read_number (info, pp, &varindx)
1954 || ! ieee_read_type_index (info, pp, &type))
1957 atn_code_start = *pp;
1959 if (! ieee_read_number (info, pp, &atn_code))
1968 else if (varindx < 32)
1970 ieee_error (info, atn_start, "illegal variable index");
1977 if (varindx >= info->vars.alloc
1978 || info->vars.vars[varindx].name == NULL)
1980 ieee_error (info, atn_start, "undefined variable in ATN");
1984 info->vars.vars[varindx].type = type;
1986 name = info->vars.vars[varindx].name;
1987 namlen = info->vars.vars[varindx].namlen;
1990 dhandle = info->dhandle;
1995 ieee_error (info, atn_code_start, "unknown ATN type");
1999 /* Automatic variable. */
2000 if (! ieee_read_number (info, pp, &v))
2002 namcopy = savestring (name, namlen);
2004 type = debug_make_void_type (dhandle);
2005 return debug_record_variable (dhandle, namcopy, type, DEBUG_LOCAL, v);
2008 /* Register variable. */
2009 if (! ieee_read_number (info, pp, &v))
2011 namcopy = savestring (name, namlen);
2013 type = debug_make_void_type (dhandle);
2014 return debug_record_variable (dhandle, namcopy, type, DEBUG_REGISTER,
2015 ieee_regno_to_genreg (info->abfd, v));
2018 /* Static variable. */
2019 if (! ieee_require_asn (info, pp, &v))
2021 namcopy = savestring (name, namlen);
2023 type = debug_make_void_type (dhandle);
2024 if (info->blockstack.bsp <= info->blockstack.stack)
2027 blocktype = info->blockstack.bsp[-1].kind;
2028 return debug_record_variable (dhandle, namcopy, type,
2029 (blocktype == 4 || blocktype == 6
2030 ? DEBUG_LOCAL_STATIC
2035 /* External function. We don't currently record these. FIXME. */
2039 /* External variable. We don't currently record these. FIXME. */
2043 if (! ieee_read_number (info, pp, &v)
2044 || ! ieee_read_number (info, pp, &v2)
2045 || ! ieee_read_optional_number (info, pp, &v3, &present))
2049 if (! ieee_read_optional_number (info, pp, &v4, &present))
2053 /* We just ignore the two optional fields in v3 and v4, since
2054 they are not defined. */
2056 if (! ieee_require_asn (info, pp, &v3))
2059 /* We have no way to record the column number. FIXME. */
2061 return debug_record_line (dhandle, v, v3);
2064 /* Global variable. */
2065 if (! ieee_require_asn (info, pp, &v))
2067 namcopy = savestring (name, namlen);
2069 type = debug_make_void_type (dhandle);
2070 return debug_record_variable (dhandle, namcopy, type, DEBUG_GLOBAL, v);
2073 /* Variable lifetime information. */
2074 if (! ieee_read_number (info, pp, &v))
2077 /* We have no way to record this information. FIXME. */
2081 /* Locked register. */
2082 if (! ieee_read_number (info, pp, &v)
2083 || ! ieee_read_number (info, pp, &v2))
2086 /* I think this means a variable that is both in a register and
2087 a frame slot. We ignore the frame slot. FIXME. */
2089 namcopy = savestring (name, namlen);
2091 type = debug_make_void_type (dhandle);
2092 return debug_record_variable (dhandle, namcopy, type, DEBUG_REGISTER, v);
2095 /* Reserved for FORTRAN common. */
2096 ieee_error (info, atn_code_start, "unsupported ATN11");
2098 /* Return true to keep going. */
2102 /* Based variable. */
2106 if (! ieee_read_number (info, pp, &v)
2107 || ! ieee_read_number (info, pp, &v2)
2108 || ! ieee_read_optional_number (info, pp, &v3, &present))
2112 if (! ieee_read_optional_number (info, pp, &v4, &present))
2116 if (! ieee_read_optional_number (info, pp, &v5, &present))
2121 /* We have no way to record this information. FIXME. */
2123 ieee_error (info, atn_code_start, "unsupported ATN12");
2125 /* Return true to keep going. */
2129 /* Constant. The description of this that I have is ambiguous,
2130 so I'm not going to try to implement it. */
2131 if (! ieee_read_number (info, pp, &v)
2132 || ! ieee_read_optional_number (info, pp, &v2, &present))
2136 if (! ieee_read_optional_number (info, pp, &v2, &present))
2140 if (! ieee_read_optional_id (info, pp, &name, &namlen, &present))
2145 if ((ieee_record_enum_type) **pp == ieee_e2_first_byte_enum)
2147 if (! ieee_require_asn (info, pp, &v3))
2154 /* Static variable from assembler. */
2156 if (! ieee_read_number (info, pp, &v)
2157 || ! ieee_read_optional_number (info, pp, &v2, &present)
2158 || ! ieee_require_asn (info, pp, &v3))
2160 namcopy = savestring (name, namlen);
2161 /* We don't really handle this correctly. FIXME. */
2162 return debug_record_variable (dhandle, namcopy,
2163 debug_make_void_type (dhandle),
2164 v2 != 0 ? DEBUG_GLOBAL : DEBUG_STATIC,
2168 /* Procedure miscellaneous information. */
2170 /* Variable miscellaneous information. */
2172 /* Module miscellaneous information. */
2173 if (! ieee_read_number (info, pp, &v)
2174 || ! ieee_read_number (info, pp, &v2)
2175 || ! ieee_read_optional_id (info, pp, &name, &namlen, &present))
2178 if (atn_code == 62 && v == 80)
2182 ieee_error (info, atn_code_start,
2183 "unexpected string in C++ misc");
2186 return ieee_read_cxx_misc (info, pp, v2);
2189 /* We just ignore all of this stuff. FIXME. */
2191 for (; v2 > 0; --v2)
2193 switch ((ieee_record_enum_type) **pp)
2196 ieee_error (info, *pp, "bad misc record");
2199 case ieee_at_record_enum:
2200 if (! ieee_require_atn65 (info, pp, &name, &namlen))
2204 case ieee_e2_first_byte_enum:
2205 if (! ieee_require_asn (info, pp, &v3))
2217 /* Handle C++ debugging miscellaneous records. This is called for
2218 procedure miscellaneous records of type 80. */
2221 ieee_read_cxx_misc (info, pp, count)
2222 struct ieee_info *info;
2223 const bfd_byte **pp;
2224 unsigned long count;
2226 const bfd_byte *start;
2231 /* Get the category of C++ misc record. */
2232 if (! ieee_require_asn (info, pp, &category))
2239 ieee_error (info, start, "unrecognized C++ misc record");
2243 if (! ieee_read_cxx_class (info, pp, count))
2251 unsigned long namlen;
2253 /* The IEEE spec indicates that the 'M' record only has a
2254 flags field. The MRI compiler also emits the name of the
2257 if (! ieee_require_asn (info, pp, &flags))
2259 if (*pp < info->pend
2260 && (ieee_record_enum_type) **pp == ieee_at_record_enum)
2262 if (! ieee_require_atn65 (info, pp, &name, &namlen))
2266 /* This is emitted for method functions, but I don't think we
2267 care very much. It might help if it told us useful
2268 information like the class with which this function is
2269 associated, but it doesn't, so it isn't helpful. */
2275 const char *fnname, *strval;
2276 unsigned long fnlen, strvallen;
2277 bfd_vma count, type, val;
2279 /* Specify default argument values. We have no way to store
2280 these, so we just ignore them. FIXME. */
2282 /* Giving the function name before the argument count is an
2283 addendum to the spec. */
2284 if (! ieee_require_atn65 (info, pp, &fnname, &fnlen)
2285 || ! ieee_require_asn (info, pp, &count)
2286 || ! ieee_require_asn (info, pp, &type))
2297 if (! ieee_require_asn (info, pp, &val))
2303 if (! ieee_require_atn65 (info, pp, &strval, &strvallen))
2308 ieee_error (info, start, "unrecognized C++ B type");
2316 if (! ieee_require_asn (info, pp, &pos))
2324 const char *name, *mangled, *class;
2325 unsigned long namlen, mangledlen, classlen;
2328 /* Pointer to member. */
2330 if (! ieee_require_atn65 (info, pp, &name, &namlen)
2331 || ! ieee_require_atn65 (info, pp, &mangled, &mangledlen)
2332 || ! ieee_require_atn65 (info, pp, &class, &classlen)
2333 || ! ieee_require_asn (info, pp, &control))
2336 /* FIXME: We should now track down name and change its type. */
2343 const char *class, *name;
2344 unsigned long classlen, namlen;
2346 /* Indicates that an object actually has reference type. */
2348 if (! ieee_require_asn (info, pp, &flags))
2351 /* Giving the class name before the member name is in an
2352 addendum to the spec. */
2355 if (! ieee_require_atn65 (info, pp, &class, &classlen))
2359 if (! ieee_require_atn65 (info, pp, &name, &namlen))
2362 /* FIXME: Now we are supposed to track down the variable or
2363 function or class member and convert the type into a
2372 /* Read a C++ class definition. This is a pmisc type 80 record of
2376 ieee_read_cxx_class (info, pp, count)
2377 struct ieee_info *info;
2378 const bfd_byte **pp;
2379 unsigned long count;
2381 const bfd_byte *start;
2384 unsigned long taglen;
2385 struct ieee_tag *it;
2387 debug_field *fields;
2388 unsigned int field_count, field_alloc;
2389 debug_baseclass *baseclasses;
2390 unsigned int baseclasses_count, baseclasses_alloc;
2391 const debug_field *structfields;
2395 unsigned long namlen;
2396 debug_method_variant *variants;
2400 unsigned int methods_count, methods_alloc;
2401 debug_type vptrbase;
2403 debug_method *dmethods;
2407 if (! ieee_require_asn (info, pp, &class))
2411 if (! ieee_require_atn65 (info, pp, &tag, &taglen))
2415 /* Find the C struct with this name. */
2416 for (it = info->tags; it != NULL; it = it->next)
2417 if (it->name[0] == tag[0]
2418 && strncmp (it->name, tag, taglen) == 0
2419 && strlen (it->name) == taglen)
2423 ieee_error (info, start, "undefined C++ object");
2427 dhandle = info->dhandle;
2433 baseclasses_count = 0;
2434 baseclasses_alloc = 0;
2438 vptrbase = DEBUG_TYPE_NULL;
2441 structfields = debug_get_fields (dhandle, it->type);
2446 const bfd_byte *spec_start;
2450 if (! ieee_require_asn (info, pp, &id))
2457 ieee_error (info, spec_start, "unrecognized C++ object spec");
2462 bfd_vma flags, cinline;
2463 const char *basename, *fieldname;
2464 unsigned long baselen, fieldlen;
2466 debug_type basetype;
2469 enum debug_visibility visibility;
2470 debug_baseclass baseclass;
2472 /* This represents a base or friend class. */
2474 if (! ieee_require_asn (info, pp, &flags)
2475 || ! ieee_require_atn65 (info, pp, &basename, &baselen)
2476 || ! ieee_require_asn (info, pp, &cinline)
2477 || ! ieee_require_atn65 (info, pp, &fieldname, &fieldlen))
2481 /* We have no way of recording friend information, so we
2483 if ((flags & BASEFLAGS_FRIEND) != 0)
2486 /* I assume that either all of the members of the
2487 baseclass are included in the object, starting at the
2488 beginning of the object, or that none of them are
2491 if ((fieldlen == 0) == (cinline == 0))
2493 ieee_error (info, start, "unsupported C++ object type");
2497 basecopy = savestring (basename, baselen);
2498 basetype = debug_find_tagged_type (dhandle, basecopy,
2499 DEBUG_KIND_ILLEGAL);
2501 if (basetype == DEBUG_TYPE_NULL)
2503 ieee_error (info, start, "C++ base class not defined");
2511 const debug_field *pf;
2513 if (structfields == NULL)
2515 ieee_error (info, start, "C++ object has no fields");
2519 for (pf = structfields; *pf != DEBUG_FIELD_NULL; pf++)
2523 fname = debug_get_field_name (dhandle, *pf);
2526 if (fname[0] == fieldname[0]
2527 && strncmp (fname, fieldname, fieldlen) == 0
2528 && strlen (fname) == fieldlen)
2531 if (*pf == DEBUG_FIELD_NULL)
2533 ieee_error (info, start,
2534 "C++ base class not found in container");
2538 bitpos = debug_get_field_bitpos (dhandle, *pf);
2541 if ((flags & BASEFLAGS_VIRTUAL) != 0)
2545 if ((flags & BASEFLAGS_PRIVATE) != 0)
2546 visibility = DEBUG_VISIBILITY_PRIVATE;
2548 visibility = DEBUG_VISIBILITY_PUBLIC;
2550 baseclass = debug_make_baseclass (dhandle, basetype, bitpos,
2551 virtualp, visibility);
2552 if (baseclass == DEBUG_BASECLASS_NULL)
2555 if (baseclasses_count + 1 >= baseclasses_alloc)
2557 baseclasses_alloc += 10;
2558 baseclasses = ((debug_baseclass *)
2559 xrealloc (baseclasses,
2561 * sizeof *baseclasses)));
2564 baseclasses[baseclasses_count] = baseclass;
2565 ++baseclasses_count;
2566 baseclasses[baseclasses_count] = DEBUG_BASECLASS_NULL;
2573 const char *fieldname, *mangledname;
2574 unsigned long fieldlen, mangledlen;
2578 const debug_field *pf;
2579 enum debug_visibility visibility;
2582 /* This represents a data member. */
2584 if (! ieee_require_asn (info, pp, &flags)
2585 || ! ieee_require_atn65 (info, pp, &fieldname, &fieldlen)
2586 || ! ieee_require_atn65 (info, pp, &mangledname, &mangledlen))
2590 fieldcopy = savestring (fieldname, fieldlen);
2592 staticp = (flags & CXXFLAGS_STATIC) != 0 ? true : false;
2596 /* We can only figure out the type here if mangledname
2597 happens to have already been defined, but that is
2598 not necessarily the case. In fact, it may never be
2599 defined. For now, we don't even try. FIXME. */
2601 ftype = ieee_builtin_type (info, start,
2602 (unsigned int) builtin_void);
2606 if (structfields == NULL)
2608 ieee_error (info, start, "C++ object has no fields");
2612 for (pf = structfields; *pf != DEBUG_FIELD_NULL; pf++)
2616 fname = debug_get_field_name (dhandle, *pf);
2619 if (fname[0] == mangledname[0]
2620 && strncmp (fname, mangledname, mangledlen) == 0
2621 && strlen (fname) == mangledlen)
2624 if (*pf == DEBUG_FIELD_NULL)
2626 ieee_error (info, start,
2627 "C++ data member not found in container");
2631 ftype = debug_get_field_type (dhandle, *pf);
2633 if (ftype == DEBUG_TYPE_NULL)
2636 switch (flags & CXXFLAGS_VISIBILITY)
2639 ieee_error (info, start, "unknown C++ visibility");
2642 case CXXFLAGS_VISIBILITY_PUBLIC:
2643 visibility = DEBUG_VISIBILITY_PUBLIC;
2646 case CXXFLAGS_VISIBILITY_PRIVATE:
2647 visibility = DEBUG_VISIBILITY_PRIVATE;
2650 case CXXFLAGS_VISIBILITY_PROTECTED:
2651 visibility = DEBUG_VISIBILITY_PROTECTED;
2655 if ((flags & CXXFLAGS_STATIC) != 0)
2659 mangledcopy = savestring (mangledname, mangledlen);
2661 field = debug_make_static_member (dhandle, fieldcopy,
2667 bfd_vma bitpos, bitsize;
2669 bitpos = debug_get_field_bitpos (dhandle, *pf);
2670 bitsize = debug_get_field_bitsize (dhandle, *pf);
2671 if (bitpos == (bfd_vma) -1 || bitsize == (bfd_vma) -1)
2673 ieee_error (info, start, "bad C++ field bit pos or size");
2676 field = debug_make_field (dhandle, fieldcopy, ftype, bitpos,
2677 bitsize, visibility);
2680 if (field == DEBUG_FIELD_NULL)
2683 if (field_count + 1 >= field_alloc)
2686 fields = ((debug_field *)
2687 xrealloc (fields, field_alloc * sizeof *fields));
2690 fields[field_count] = field;
2692 fields[field_count] = DEBUG_FIELD_NULL;
2699 bfd_vma flags, virtindex, control;
2700 const char *name, *mangled;
2701 unsigned long namlen, mangledlen;
2702 struct ieee_function *func;
2704 enum debug_visibility visibility;
2705 boolean constp, volatilep;
2707 debug_method_variant mv;
2708 struct ieee_method *meth;
2711 if (! ieee_require_asn (info, pp, &flags)
2712 || ! ieee_require_atn65 (info, pp, &name, &namlen)
2713 || ! ieee_require_atn65 (info, pp, &mangled, &mangledlen))
2718 if (! ieee_require_asn (info, pp, &virtindex))
2722 if (! ieee_require_asn (info, pp, &control))
2726 /* We just ignore the control information. */
2728 /* We have no way to represent friend information, so we
2730 if ((flags & CXXFLAGS_FRIEND) != 0)
2733 /* We should already have seen debugging information for
2734 the function itself, which will include type
2736 for (func = info->functions; func != NULL; func = func->next)
2737 if (func->name[0] == mangled[0]
2738 && strncmp (func->name, mangled, mangledlen)
2739 && strlen (func->name) == mangledlen)
2743 /* We won't have type information for this function if
2744 it is not included in this file. We don't try to
2745 handle this case. FIXME. */
2746 type = (debug_make_function_type
2748 ieee_builtin_type (info, start,
2749 (unsigned int) builtin_void),
2750 (debug_type *) NULL,
2755 debug_type return_type;
2756 const debug_type *arg_types;
2759 if (debug_get_type_kind (dhandle, func->type)
2760 != DEBUG_KIND_FUNCTION)
2762 ieee_error (info, start,
2763 "bad type for C++ method function");
2767 return_type = debug_get_return_type (dhandle, func->type);
2768 arg_types = debug_get_parameter_types (dhandle, func->type,
2770 if (return_type == DEBUG_TYPE_NULL || arg_types == NULL)
2772 ieee_error (info, start,
2773 "no type information for C++ method function");
2777 type = debug_make_method_type (dhandle, return_type, it->type,
2778 (debug_type *) arg_types,
2781 if (type == DEBUG_TYPE_NULL)
2784 switch (flags & CXXFLAGS_VISIBILITY)
2787 ieee_error (info, start, "unknown C++ visibility");
2790 case CXXFLAGS_VISIBILITY_PUBLIC:
2791 visibility = DEBUG_VISIBILITY_PUBLIC;
2794 case CXXFLAGS_VISIBILITY_PRIVATE:
2795 visibility = DEBUG_VISIBILITY_PRIVATE;
2798 case CXXFLAGS_VISIBILITY_PROTECTED:
2799 visibility = DEBUG_VISIBILITY_PROTECTED;
2803 constp = (flags & CXXFLAGS_CONST) != 0 ? true : false;
2804 volatilep = (flags & CXXFLAGS_VOLATILE) != 0 ? true : false;
2806 mangledcopy = savestring (mangled, mangledlen);
2808 if ((flags & CXXFLAGS_STATIC) != 0)
2812 ieee_error (info, start, "C++ static virtual method");
2815 mv = debug_make_static_method_variant (dhandle, mangledcopy,
2822 debug_type vcontext;
2827 vcontext = DEBUG_TYPE_NULL;
2831 /* FIXME: This should depend upon the pointer
2833 voffset = virtindex * 4;
2834 /* FIXME: How can we calculate this correctly? */
2835 vcontext = it->type;
2837 mv = debug_make_method_variant (dhandle, mangledcopy, type,
2842 if (mv == DEBUG_METHOD_VARIANT_NULL)
2845 for (meth = methods, im = 0; im < methods_count; meth++, im++)
2846 if (meth->namlen == namlen
2847 && strncmp (meth->name, name, namlen) == 0)
2849 if (im >= methods_count)
2851 if (methods_count >= methods_alloc)
2853 methods_alloc += 10;
2854 methods = ((struct ieee_method *)
2856 methods_alloc * sizeof *methods));
2858 methods[methods_count].name = name;
2859 methods[methods_count].namlen = namlen;
2860 methods[methods_count].variants = NULL;
2861 methods[methods_count].count = 0;
2862 methods[methods_count].alloc = 0;
2863 meth = methods + methods_count;
2867 if (meth->count + 1 >= meth->alloc)
2870 meth->variants = ((debug_method_variant *)
2871 xrealloc (meth->variants,
2873 * sizeof *meth->variants)));
2876 meth->variants[meth->count] = mv;
2878 meth->variants[meth->count] = DEBUG_METHOD_VARIANT_NULL;
2886 /* We have no way to store this information, so we just
2888 if (! ieee_require_asn (info, pp, &spec))
2891 if ((spec & 4) != 0)
2893 const char *filename;
2894 unsigned long filenamlen;
2897 if (! ieee_require_atn65 (info, pp, &filename, &filenamlen)
2898 || ! ieee_require_asn (info, pp, &lineno))
2902 else if ((spec & 8) != 0)
2904 const char *mangled;
2905 unsigned long mangledlen;
2907 if (! ieee_require_atn65 (info, pp, &mangled, &mangledlen))
2913 ieee_error (info, start,
2914 "unrecognized C++ object overhead spec");
2922 const char *vname, *basename;
2923 unsigned long vnamelen, baselen;
2924 bfd_vma vsize, control;
2926 /* A virtual table pointer. */
2928 if (! ieee_require_atn65 (info, pp, &vname, &vnamelen)
2929 || ! ieee_require_asn (info, pp, &vsize)
2930 || ! ieee_require_atn65 (info, pp, &basename, &baselen)
2931 || ! ieee_require_asn (info, pp, &control))
2935 /* We just ignore the control number. We don't care what
2936 the virtual table name is. We have no way to store the
2937 virtual table size, and I don't think we care anyhow. */
2939 /* FIXME: We can't handle multiple virtual table pointers. */
2947 basecopy = savestring (basename, baselen);
2948 vptrbase = debug_find_tagged_type (dhandle, basecopy,
2949 DEBUG_KIND_ILLEGAL);
2951 if (vptrbase == DEBUG_TYPE_NULL)
2953 ieee_error (info, start, "undefined C++ vtable");
2962 /* Now that we have seen all the method variants, we can call
2963 debug_make_method for each one. */
2965 if (methods_count == 0)
2971 dmethods = ((debug_method *)
2972 xmalloc ((methods_count + 1) * sizeof *dmethods));
2973 for (i = 0; i < methods_count; i++)
2977 namcopy = savestring (methods[i].name, methods[i].namlen);
2978 dmethods[i] = debug_make_method (dhandle, namcopy,
2979 methods[i].variants);
2980 if (dmethods[i] == DEBUG_METHOD_NULL)
2986 /* The struct type was created as an indirect type pointing at
2987 it->slot. We update it->slot to automatically update all
2988 references to this struct. */
2989 it->slot = debug_make_object_type (dhandle,
2991 debug_get_type_size (dhandle,
2993 fields, baseclasses, dmethods,
2995 if (it->slot == DEBUG_TYPE_NULL)
3001 /* Require an ASN record. */
3004 ieee_require_asn (info, pp, pv)
3005 struct ieee_info *info;
3006 const bfd_byte **pp;
3009 const bfd_byte *start;
3010 ieee_record_enum_type c;
3015 c = (ieee_record_enum_type) **pp;
3016 if (c != ieee_e2_first_byte_enum)
3018 ieee_error (info, start, "missing required ASN");
3023 c = (ieee_record_enum_type) (((unsigned int) c << 8) | **pp);
3024 if (c != ieee_asn_record_enum)
3026 ieee_error (info, start, "missing required ASN");
3031 /* Just ignore the variable index. */
3032 if (! ieee_read_number (info, pp, &varindx))
3035 return ieee_read_expression (info, pp, pv);
3038 /* Require an ATN65 record. */
3041 ieee_require_atn65 (info, pp, pname, pnamlen)
3042 struct ieee_info *info;
3043 const bfd_byte **pp;
3045 unsigned long *pnamlen;
3047 const bfd_byte *start;
3048 ieee_record_enum_type c;
3049 bfd_vma name_indx, type_indx, atn_code;
3053 c = (ieee_record_enum_type) **pp;
3054 if (c != ieee_at_record_enum)
3056 ieee_error (info, start, "missing required ATN65");
3061 c = (ieee_record_enum_type) (((unsigned int) c << 8) | **pp);
3062 if (c != ieee_atn_record_enum)
3064 ieee_error (info, start, "missing required ATN65");
3069 if (! ieee_read_number (info, pp, &name_indx)
3070 || ! ieee_read_number (info, pp, &type_indx)
3071 || ! ieee_read_number (info, pp, &atn_code))
3074 /* Just ignore name_indx. */
3076 if (type_indx != 0 || atn_code != 65)
3078 ieee_error (info, start, "bad ATN65 record");
3082 return ieee_read_id (info, pp, pname, pnamlen);
3085 /* Convert a register number in IEEE debugging information into a
3086 generic register number. */
3089 ieee_regno_to_genreg (abfd, r)
3096 /* Convert a generic register number to an IEEE specific one. */
3099 ieee_genreg_to_regno (abfd, r)
3106 /* These routines build IEEE debugging information out of the generic
3107 debugging information. */
3109 /* We build the IEEE debugging information byte by byte. Rather than
3110 waste time copying data around, we use a linked list of buffers to
3113 #define IEEE_BUFSIZE (490)
3118 struct ieee_buf *next;
3119 /* Number of data bytes in this buffer. */
3122 bfd_byte buf[IEEE_BUFSIZE];
3125 /* In order to generate the BB11 blocks required by the HP emulator,
3126 we keep track of ranges of addresses which correspond to a given
3127 compilation unit. */
3132 struct ieee_range *next;
3139 /* This structure holds information for a class on the type stack. */
3141 struct ieee_type_class
3143 /* The name of the class. */
3145 /* The name index in the debugging information. */
3147 /* The pmisc records for the class. */
3148 struct ieee_buf *pmiscbuf;
3149 /* The number of pmisc records. */
3150 unsigned int pmisccount;
3151 /* The name of the class holding the virtual table, if not this
3154 /* Whether this class holds its own virtual table. */
3156 /* The largest virtual table offset seen so far. */
3158 /* The current method. */
3162 /* This is how we store types for the writing routines. Most types
3163 are simply represented by a type index. */
3165 struct ieee_write_type
3169 /* The size of the type, if known. */
3171 /* If this is a struct, this is where the struct definition is
3173 struct ieee_buf *strdef;
3174 /* If this is a class, this is where the class information is built. */
3175 struct ieee_type_class *classdef;
3176 /* Whether the type is unsigned. */
3177 unsigned int unsignedp : 1;
3178 /* Whether this is a reference type. */
3179 unsigned int referencep : 1;
3182 /* This is the type stack used by the debug writing routines. FIXME:
3183 We could generate more efficient output if we remembered when we
3184 have output a particular type before. */
3186 struct ieee_type_stack
3188 /* Next entry on stack. */
3189 struct ieee_type_stack *next;
3190 /* Type information. */
3191 struct ieee_write_type type;
3194 /* This is a list of associations between names and types. This could
3195 be more efficiently implemented as a hash table. */
3197 struct ieee_name_type
3199 /* Next name/type assocation. */
3200 struct ieee_name_type *next;
3204 struct ieee_write_type type;
3205 /* If this is a tag which has not yet been defined, this is the
3206 kind. If the tag has been defined, this is DEBUG_KIND_ILLEGAL. */
3207 enum debug_type_kind kind;
3210 /* This is a list of pending function parameter information. We don't
3211 output them until we see the first block. */
3213 struct ieee_pending_parm
3215 /* Next pending parameter. */
3216 struct ieee_pending_parm *next;
3222 enum debug_parm_kind kind;
3227 /* This is the handle passed down by debug_write. */
3231 /* BFD we are writing to. */
3233 /* Current data buffer. */
3234 struct ieee_buf *current;
3235 /* Filename of current compilation unit. */
3236 const char *filename;
3237 /* Module name of current compilation unit. */
3238 const char *modname;
3239 /* List of finished data buffers. */
3240 struct ieee_buf *data;
3241 /* List of buffers for typedefs in the current compilation unit. */
3242 struct ieee_buf *types;
3243 /* List of buffers for variables and functions in the current
3244 compilation unit. */
3245 struct ieee_buf *vars;
3246 /* List of buffers for C++ class definitions in the current
3247 compilation unit. */
3248 struct ieee_buf *cxx;
3249 /* List of buffers for line numbers in the current compilation unit. */
3250 struct ieee_buf *linenos;
3251 /* Ranges for the current compilation unit. */
3252 struct ieee_range *ranges;
3253 /* Nested pending ranges. */
3254 struct ieee_range *pending_ranges;
3256 struct ieee_type_stack *type_stack;
3257 /* Next unallocated type index. */
3258 unsigned int type_indx;
3259 /* Next unallocated name index. */
3260 unsigned int name_indx;
3262 struct ieee_name_type *typedefs;
3264 struct ieee_name_type *tags;
3265 /* The depth of block nesting. This is 0 outside a function, and 1
3266 just after start_function is called. */
3267 unsigned int block_depth;
3268 /* Pending function parameters. */
3269 struct ieee_pending_parm *pending_parms;
3270 /* Current line number filename. */
3271 const char *lineno_filename;
3272 /* Line number name index. */
3273 unsigned int lineno_name_indx;
3274 /* Highest address seen at end of procedure. */
3278 static boolean ieee_change_buffer
3279 PARAMS ((struct ieee_handle *, struct ieee_buf **));
3280 static boolean ieee_push_type
3281 PARAMS ((struct ieee_handle *, unsigned int, unsigned int, boolean));
3282 static unsigned int ieee_pop_type PARAMS ((struct ieee_handle *));
3283 static boolean ieee_add_range
3284 PARAMS ((struct ieee_handle *, bfd_vma, bfd_vma));
3285 static boolean ieee_start_range PARAMS ((struct ieee_handle *, bfd_vma));
3286 static boolean ieee_end_range PARAMS ((struct ieee_handle *, bfd_vma));
3287 static boolean ieee_real_write_byte PARAMS ((struct ieee_handle *, int));
3288 static boolean ieee_write_2bytes PARAMS ((struct ieee_handle *, int));
3289 static boolean ieee_write_number PARAMS ((struct ieee_handle *, bfd_vma));
3290 static boolean ieee_write_id PARAMS ((struct ieee_handle *, const char *));
3291 static boolean ieee_write_asn
3292 PARAMS ((struct ieee_handle *, unsigned int, bfd_vma));
3293 static boolean ieee_write_atn65
3294 PARAMS ((struct ieee_handle *, unsigned int, const char *));
3295 static boolean ieee_define_type
3296 PARAMS ((struct ieee_handle *, unsigned int, boolean));
3297 static boolean ieee_define_named_type
3298 PARAMS ((struct ieee_handle *, const char *, boolean, unsigned int,
3299 unsigned int, boolean, struct ieee_buf **));
3300 static boolean ieee_finish_compilation_unit PARAMS ((struct ieee_handle *));
3301 static boolean ieee_output_pending_parms PARAMS ((struct ieee_handle *));
3302 static unsigned int ieee_vis_to_flags PARAMS ((enum debug_visibility));
3303 static boolean ieee_class_method_var
3304 PARAMS ((struct ieee_handle *, const char *, enum debug_visibility, boolean,
3305 boolean, boolean, bfd_vma, boolean));
3307 static boolean ieee_start_compilation_unit PARAMS ((PTR, const char *));
3308 static boolean ieee_start_source PARAMS ((PTR, const char *));
3309 static boolean ieee_empty_type PARAMS ((PTR));
3310 static boolean ieee_void_type PARAMS ((PTR));
3311 static boolean ieee_int_type PARAMS ((PTR, unsigned int, boolean));
3312 static boolean ieee_float_type PARAMS ((PTR, unsigned int));
3313 static boolean ieee_complex_type PARAMS ((PTR, unsigned int));
3314 static boolean ieee_bool_type PARAMS ((PTR, unsigned int));
3315 static boolean ieee_enum_type
3316 PARAMS ((PTR, const char *, const char **, bfd_signed_vma *));
3317 static boolean ieee_pointer_type PARAMS ((PTR));
3318 static boolean ieee_function_type PARAMS ((PTR, int, boolean));
3319 static boolean ieee_reference_type PARAMS ((PTR));
3320 static boolean ieee_range_type PARAMS ((PTR, bfd_signed_vma, bfd_signed_vma));
3321 static boolean ieee_array_type
3322 PARAMS ((PTR, bfd_signed_vma, bfd_signed_vma, boolean));
3323 static boolean ieee_set_type PARAMS ((PTR, boolean));
3324 static boolean ieee_offset_type PARAMS ((PTR));
3325 static boolean ieee_method_type PARAMS ((PTR, boolean, int, boolean));
3326 static boolean ieee_const_type PARAMS ((PTR));
3327 static boolean ieee_volatile_type PARAMS ((PTR));
3328 static boolean ieee_start_struct_type
3329 PARAMS ((PTR, const char *, unsigned int, boolean, unsigned int));
3330 static boolean ieee_struct_field
3331 PARAMS ((PTR, const char *, bfd_vma, bfd_vma, enum debug_visibility));
3332 static boolean ieee_end_struct_type PARAMS ((PTR));
3333 static boolean ieee_start_class_type
3334 PARAMS ((PTR, const char *, unsigned int, boolean, unsigned int, boolean,
3336 static boolean ieee_class_static_member
3337 PARAMS ((PTR, const char *, const char *, enum debug_visibility));
3338 static boolean ieee_class_baseclass
3339 PARAMS ((PTR, bfd_vma, boolean, enum debug_visibility));
3340 static boolean ieee_class_start_method PARAMS ((PTR, const char *));
3341 static boolean ieee_class_method_variant
3342 PARAMS ((PTR, const char *, enum debug_visibility, boolean, boolean,
3344 static boolean ieee_class_static_method_variant
3345 PARAMS ((PTR, const char *, enum debug_visibility, boolean, boolean));
3346 static boolean ieee_class_end_method PARAMS ((PTR));
3347 static boolean ieee_end_class_type PARAMS ((PTR));
3348 static boolean ieee_typedef_type PARAMS ((PTR, const char *));
3349 static boolean ieee_tag_type
3350 PARAMS ((PTR, const char *, unsigned int, enum debug_type_kind));
3351 static boolean ieee_typdef PARAMS ((PTR, const char *));
3352 static boolean ieee_tag PARAMS ((PTR, const char *));
3353 static boolean ieee_int_constant PARAMS ((PTR, const char *, bfd_vma));
3354 static boolean ieee_float_constant PARAMS ((PTR, const char *, double));
3355 static boolean ieee_typed_constant PARAMS ((PTR, const char *, bfd_vma));
3356 static boolean ieee_variable
3357 PARAMS ((PTR, const char *, enum debug_var_kind, bfd_vma));
3358 static boolean ieee_start_function PARAMS ((PTR, const char *, boolean));
3359 static boolean ieee_function_parameter
3360 PARAMS ((PTR, const char *, enum debug_parm_kind, bfd_vma));
3361 static boolean ieee_start_block PARAMS ((PTR, bfd_vma));
3362 static boolean ieee_end_block PARAMS ((PTR, bfd_vma));
3363 static boolean ieee_end_function PARAMS ((PTR));
3364 static boolean ieee_lineno
3365 PARAMS ((PTR, const char *, unsigned long, bfd_vma));
3367 static const struct debug_write_fns ieee_fns =
3369 ieee_start_compilation_unit,
3380 ieee_reference_type,
3388 ieee_start_struct_type,
3390 ieee_end_struct_type,
3391 ieee_start_class_type,
3392 ieee_class_static_member,
3393 ieee_class_baseclass,
3394 ieee_class_start_method,
3395 ieee_class_method_variant,
3396 ieee_class_static_method_variant,
3397 ieee_class_end_method,
3398 ieee_end_class_type,
3404 ieee_float_constant,
3405 ieee_typed_constant,
3407 ieee_start_function,
3408 ieee_function_parameter,
3415 /* Change the current buffer to a specified buffer chain. */
3418 ieee_change_buffer (info, ppbuf)
3419 struct ieee_handle *info;
3420 struct ieee_buf **ppbuf;
3422 struct ieee_buf *buf;
3426 for (buf = *ppbuf; buf->next != NULL; buf = buf->next)
3431 buf = (struct ieee_buf *) xmalloc (sizeof *buf);
3437 info->current = buf;
3441 /* Push a type index onto the type stack. */
3444 ieee_push_type (info, indx, size, unsignedp)
3445 struct ieee_handle *info;
3450 struct ieee_type_stack *ts;
3452 ts = (struct ieee_type_stack *) xmalloc (sizeof *ts);
3453 memset (ts, 0, sizeof *ts);
3455 ts->type.indx = indx;
3456 ts->type.size = size;
3457 ts->type.unsignedp = unsignedp;
3459 ts->next = info->type_stack;
3460 info->type_stack = ts;
3465 /* Pop a type index off the type stack. */
3468 ieee_pop_type (info)
3469 struct ieee_handle *info;
3471 struct ieee_type_stack *ts;
3474 ts = info->type_stack;
3475 assert (ts != NULL);
3476 ret = ts->type.indx;
3477 info->type_stack = ts->next;
3482 /* Add a range of bytes included in the current compilation unit. */
3485 ieee_add_range (info, low, high)
3486 struct ieee_handle *info;
3490 struct ieee_range *r, **pr;
3492 if (low == (bfd_vma) -1 || high == (bfd_vma) -1)
3495 for (r = info->ranges; r != NULL; r = r->next)
3497 if (high >= r->low && low <= r->high)
3499 /* The new range overlaps r. */
3505 while (*pr != NULL && (*pr)->low <= r->high)
3507 struct ieee_range *n;
3509 if ((*pr)->high > r->high)
3510 r->high = (*pr)->high;
3519 r = (struct ieee_range *) xmalloc (sizeof *r);
3520 memset (r, 0, sizeof *r);
3525 /* Store the ranges sorted by address. */
3526 for (pr = &info->ranges; *pr != NULL; pr = &(*pr)->next)
3527 if ((*pr)->next != NULL && (*pr)->next->low > high)
3535 /* Start a new range for which we only have the low address. */
3538 ieee_start_range (info, low)
3539 struct ieee_handle *info;
3542 struct ieee_range *r;
3544 r = (struct ieee_range *) xmalloc (sizeof *r);
3545 memset (r, 0, sizeof *r);
3547 r->next = info->pending_ranges;
3548 info->pending_ranges = r;
3552 /* Finish a range started by ieee_start_range. */
3555 ieee_end_range (info, high)
3556 struct ieee_handle *info;
3559 struct ieee_range *r;
3562 assert (info->pending_ranges != NULL);
3563 r = info->pending_ranges;
3565 info->pending_ranges = r->next;
3567 return ieee_add_range (info, low, high);
3570 /* Write a byte into the buffer. We use a macro for speed and a
3571 function for the complex cases. */
3573 #define ieee_write_byte(info, b) \
3574 ((info)->current->c < IEEE_BUFSIZE \
3575 ? ((info)->current->buf[(info)->current->c++] = (b), true) \
3576 : ieee_real_write_byte ((info), (b)))
3579 ieee_real_write_byte (info, b)
3580 struct ieee_handle *info;
3583 if (info->current->c >= IEEE_BUFSIZE)
3587 n = (struct ieee_buf *) xmalloc (sizeof *n);
3590 info->current->next = n;
3594 info->current->buf[info->current->c] = b;
3600 /* Write out two bytes. */
3603 ieee_write_2bytes (info, i)
3604 struct ieee_handle *info;
3607 return (ieee_write_byte (info, i >> 8)
3608 && ieee_write_byte (info, i & 0xff));
3611 /* Write out an integer. */
3614 ieee_write_number (info, v)
3615 struct ieee_handle *info;
3623 if (v <= (bfd_vma) ieee_number_end_enum)
3624 return ieee_write_byte (info, (int) v);
3635 if (c > (unsigned int) (ieee_number_repeat_end_enum
3636 - ieee_number_repeat_start_enum))
3638 fprintf (stderr, "IEEE numeric overflow: 0x");
3639 fprintf_vma (stderr, v);
3640 fprintf (stderr, "\n");
3644 if (! ieee_write_byte (info, (int) ieee_number_repeat_start_enum + c))
3646 for (; c > 0; --c, ++p)
3648 if (! ieee_write_byte (info, *p))
3655 /* Write out a string. */
3658 ieee_write_id (info, s)
3659 struct ieee_handle *info;
3667 if (! ieee_write_byte (info, len))
3670 else if (len <= 0xff)
3672 if (! ieee_write_byte (info, (int) ieee_extension_length_1_enum)
3673 || ! ieee_write_byte (info, len))
3676 else if (len <= 0xffff)
3678 if (! ieee_write_byte (info, (int) ieee_extension_length_2_enum)
3679 || ! ieee_write_2bytes (info, len))
3684 fprintf (stderr, "IEEE string length overflow: %u\n", len);
3688 for (; *s != '\0'; s++)
3689 if (! ieee_write_byte (info, *s))
3695 /* Write out an ASN record. */
3698 ieee_write_asn (info, indx, val)
3699 struct ieee_handle *info;
3703 return (ieee_write_2bytes (info, (int) ieee_asn_record_enum)
3704 && ieee_write_number (info, indx)
3705 && ieee_write_number (info, val));
3708 /* Write out an ATN65 record. */
3711 ieee_write_atn65 (info, indx, s)
3712 struct ieee_handle *info;
3716 return (ieee_write_2bytes (info, (int) ieee_atn_record_enum)
3717 && ieee_write_number (info, indx)
3718 && ieee_write_number (info, 0)
3719 && ieee_write_number (info, 65)
3720 && ieee_write_id (info, s));
3723 /* Start defining a type. */
3726 ieee_define_type (info, size, unsignedp)
3727 struct ieee_handle *info;
3731 return ieee_define_named_type (info, (const char *) NULL, false, 0, size,
3732 unsignedp, (struct ieee_buf **) NULL);
3735 /* Start defining a named type. */
3738 ieee_define_named_type (info, name, tagp, id, size, unsignedp, ppbuf)
3739 struct ieee_handle *info;
3745 struct ieee_buf **ppbuf;
3747 unsigned int type_indx;
3748 unsigned int name_indx;
3750 if (! tagp || id == (unsigned int) -1)
3752 type_indx = info->type_indx;
3757 struct ieee_name_type *nt;
3761 /* We need to create a tag for internal use even if we don't
3762 want one for external use. This will let us refer to an
3763 anonymous struct. */
3768 sprintf (ab, "__anon%u", id);
3772 /* The name is a tag. If we have already defined the tag, we
3773 must use the existing type index. */
3774 for (nt = info->tags; nt != NULL; nt = nt->next)
3775 if (nt->name[0] == tag[0]
3776 && strcmp (nt->name, tag) == 0)
3781 nt = (struct ieee_name_type *) xmalloc (sizeof *nt);
3782 memset (nt, 0, sizeof *nt);
3784 nt->next = info->tags;
3786 nt->type.indx = info->type_indx;
3790 nt->type.size = size;
3791 nt->type.unsignedp = unsignedp;
3792 nt->kind = DEBUG_KIND_ILLEGAL;
3794 type_indx = nt->type.indx;
3797 name_indx = info->name_indx;
3803 /* If we were given a buffer, use it; otherwise, use the general
3804 type information, and make sure that the type block is started. */
3807 if (! ieee_change_buffer (info, ppbuf))
3810 else if (info->types != NULL)
3812 if (! ieee_change_buffer (info, &info->types))
3817 if (! ieee_change_buffer (info, &info->types)
3818 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
3819 || ! ieee_write_byte (info, 1)
3820 || ! ieee_write_number (info, 0)
3821 || ! ieee_write_id (info, info->modname))
3825 /* Push the new type on the type stack, write out an NN record, and
3826 write out the start of a TY record. The caller will then finish
3828 return (ieee_push_type (info, type_indx, size, unsignedp)
3829 && ieee_write_byte (info, (int) ieee_nn_record)
3830 && ieee_write_number (info, name_indx)
3831 && ieee_write_id (info, name)
3832 && ieee_write_byte (info, (int) ieee_ty_record_enum)
3833 && ieee_write_number (info, type_indx)
3834 && ieee_write_byte (info, 0xce)
3835 && ieee_write_number (info, name_indx));
3838 /* The general routine to write out IEEE debugging information. */
3841 write_ieee_debugging_info (abfd, dhandle)
3845 struct ieee_handle info;
3846 struct ieee_buf *tags;
3847 struct ieee_name_type *nt;
3852 memset (&info, 0, sizeof info);
3854 info.type_indx = 256;
3855 info.name_indx = 32;
3857 if (! debug_write (dhandle, &ieee_fns, (PTR) &info))
3860 if (info.filename != NULL)
3862 if (! ieee_finish_compilation_unit (&info))
3866 /* Put any undefined tags in the global typedef information. */
3868 for (nt = info.tags; nt != NULL; nt = nt->next)
3870 unsigned int name_indx;
3873 if (nt->kind == DEBUG_KIND_ILLEGAL)
3877 if (! ieee_change_buffer (&info, &tags)
3878 || ! ieee_write_byte (&info, (int) ieee_bb_record_enum)
3879 || ! ieee_write_byte (&info, 2)
3880 || ! ieee_write_number (&info, 0)
3881 || ! ieee_write_id (&info, ""))
3884 name_indx = info.name_indx;
3886 if (! ieee_write_byte (&info, (int) ieee_nn_record)
3887 || ! ieee_write_number (&info, name_indx)
3888 || ! ieee_write_id (&info, nt->name)
3889 || ! ieee_write_byte (&info, (int) ieee_ty_record_enum)
3890 || ! ieee_write_number (&info, nt->type.indx)
3891 || ! ieee_write_byte (&info, 0xce)
3892 || ! ieee_write_number (&info, name_indx))
3899 case DEBUG_KIND_STRUCT:
3900 case DEBUG_KIND_CLASS:
3903 case DEBUG_KIND_UNION:
3904 case DEBUG_KIND_UNION_CLASS:
3907 case DEBUG_KIND_ENUM:
3911 if (! ieee_write_number (&info, code)
3912 || ! ieee_write_number (&info, 0))
3917 struct ieee_buf **pb;
3919 if (! ieee_write_byte (&info, (int) ieee_be_record_enum))
3922 for (pb = &tags; *pb != NULL; pb = &(*pb)->next)
3928 /* Now all the data is in info.data. Write it out to the BFD. We
3929 normally would need to worry about whether all the other sections
3930 are set up yet, but the IEEE backend will handle this particular
3931 case correctly regardless. */
3932 if (info.data == NULL)
3934 /* There is no debugging information. */
3938 s = bfd_make_section (abfd, ".debug");
3940 err = "bfd_make_section";
3943 if (! bfd_set_section_flags (abfd, s, SEC_DEBUGGING | SEC_HAS_CONTENTS))
3944 err = "bfd_set_section_flags";
3951 for (b = info.data; b != NULL; b = b->next)
3953 if (! bfd_set_section_size (abfd, s, size))
3954 err = "bfd_set_section_size";
3961 for (b = info.data; b != NULL; b = b->next)
3963 if (! bfd_set_section_contents (abfd, s, b->buf, offset, b->c))
3965 err = "bfd_set_section_contents";
3974 fprintf (stderr, "%s: %s: %s\n", bfd_get_filename (abfd), err,
3975 bfd_errmsg (bfd_get_error ()));
3982 /* Start writing out information for a compilation unit. */
3985 ieee_start_compilation_unit (p, filename)
3987 const char *filename;
3989 struct ieee_handle *info = (struct ieee_handle *) p;
3990 const char *modname;
3993 if (info->filename != NULL)
3995 if (! ieee_finish_compilation_unit (info))
3999 info->filename = filename;
4000 modname = strrchr (filename, '/');
4001 if (modname != NULL)
4005 modname = strrchr (filename, '\\');
4006 if (modname != NULL)
4011 c = xstrdup (modname);
4012 s = strrchr (c, '.');
4020 info->linenos = NULL;
4021 info->ranges = NULL;
4026 /* Finish up a compilation unit. */
4029 ieee_finish_compilation_unit (info)
4030 struct ieee_handle *info;
4032 struct ieee_buf **pp;
4033 struct ieee_range *r;
4035 if (info->types != NULL)
4037 if (! ieee_change_buffer (info, &info->types)
4038 || ! ieee_write_byte (info, (int) ieee_be_record_enum))
4042 if (info->cxx != NULL)
4044 /* Append any C++ information to the global function and
4045 variable information. */
4046 if (info->vars != NULL)
4048 if (! ieee_change_buffer (info, &info->vars))
4053 if (! ieee_change_buffer (info, &info->vars)
4054 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
4055 || ! ieee_write_byte (info, 3)
4056 || ! ieee_write_number (info, 0)
4057 || ! ieee_write_id (info, info->modname))
4061 /* We put the pmisc records in a dummy procedure, just as the
4062 MRI compiler does. */
4063 if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
4064 || ! ieee_write_byte (info, 6)
4065 || ! ieee_write_number (info, 0)
4066 || ! ieee_write_id (info, "__XRYCPP")
4067 || ! ieee_write_number (info, 0)
4068 || ! ieee_write_number (info, 0)
4069 || ! ieee_write_number (info, info->highaddr))
4072 for (pp = &info->vars; *pp != NULL; pp = &(*pp)->next)
4076 if (! ieee_change_buffer (info, &info->vars)
4077 || ! ieee_write_byte (info, (int) ieee_be_record_enum)
4078 || ! ieee_write_number (info, info->highaddr))
4082 if (info->vars != NULL)
4084 if (! ieee_change_buffer (info, &info->vars)
4085 || ! ieee_write_byte (info, (int) ieee_be_record_enum))
4089 if (info->linenos != NULL)
4091 if (! ieee_change_buffer (info, &info->linenos)
4092 || ! ieee_write_byte (info, (int) ieee_be_record_enum))
4096 for (pp = &info->data; *pp != NULL; pp = &(*pp)->next)
4099 for (; *pp != NULL; pp = &(*pp)->next)
4102 for (; *pp != NULL; pp = &(*pp)->next)
4104 *pp = info->linenos;
4106 /* Build BB10/BB11 blocks based on the ranges we recorded. */
4107 if (! ieee_change_buffer (info, &info->data))
4110 if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
4111 || ! ieee_write_byte (info, 10)
4112 || ! ieee_write_number (info, 0)
4113 || ! ieee_write_id (info, info->modname)
4114 || ! ieee_write_id (info, "")
4115 || ! ieee_write_number (info, 0)
4116 || ! ieee_write_id (info, "GNU objcopy"))
4119 for (r = info->ranges; r != NULL; r = r->next)
4128 /* Find the section corresponding to this range. */
4129 for (s = info->abfd->sections; s != NULL; s = s->next)
4131 if (bfd_get_section_vma (info->abfd, s) <= low
4132 && high <= (bfd_get_section_vma (info->abfd, s)
4133 + bfd_section_size (info->abfd, s)))
4139 /* Just ignore this range. */
4143 /* Coalesce ranges if it seems reasonable. */
4144 while (r->next != NULL
4145 && high + 64 >= r->next->low
4147 <= (bfd_get_section_vma (info->abfd, s)
4148 + bfd_section_size (info->abfd, s))))
4151 high = r->next->high;
4154 if ((s->flags & SEC_CODE) != 0)
4156 else if ((s->flags & SEC_READONLY) != 0)
4161 if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
4162 || ! ieee_write_byte (info, 11)
4163 || ! ieee_write_number (info, 0)
4164 || ! ieee_write_id (info, "")
4165 || ! ieee_write_number (info, kind)
4166 || ! ieee_write_number (info, s->index)
4167 || ! ieee_write_number (info, low)
4168 || ! ieee_write_byte (info, (int) ieee_be_record_enum)
4169 || ! ieee_write_number (info, high - low))
4173 if (! ieee_write_byte (info, (int) ieee_be_record_enum))
4179 /* Start recording information from a particular source file. This is
4180 used to record which file defined which types, variables, etc. It
4181 is not used for line numbers, since the lineno entry point passes
4182 down the file name anyhow. IEEE debugging information doesn't seem
4183 to store this information anywhere. */
4187 ieee_start_source (p, filename)
4189 const char *filename;
4194 /* Make an empty type. */
4200 struct ieee_handle *info = (struct ieee_handle *) p;
4202 return ieee_push_type (info, 0, 0, false);
4205 /* Make a void type. */
4211 struct ieee_handle *info = (struct ieee_handle *) p;
4213 return ieee_push_type (info, 1, 0, false);
4216 /* Make an integer type. */
4219 ieee_int_type (p, size, unsignedp)
4224 struct ieee_handle *info = (struct ieee_handle *) p;
4230 indx = (int) builtin_signed_char;
4233 indx = (int) builtin_signed_short_int;
4236 indx = (int) builtin_signed_long;
4239 indx = (int) builtin_signed_long_long;
4242 fprintf (stderr, "IEEE unsupported integer type size %u\n", size);
4249 return ieee_push_type (info, indx, size, unsignedp);
4252 /* Make a floating point type. */
4255 ieee_float_type (p, size)
4259 struct ieee_handle *info = (struct ieee_handle *) p;
4265 indx = (int) builtin_float;
4268 indx = (int) builtin_double;
4271 /* FIXME: This size really depends upon the processor. */
4272 indx = (int) builtin_long_double;
4275 indx = (int) builtin_long_long_double;
4278 fprintf (stderr, "IEEE unsupported float type size %u\n", size);
4282 return ieee_push_type (info, indx, size, false);
4285 /* Make a complex type. */
4288 ieee_complex_type (p, size)
4292 struct ieee_handle *info = (struct ieee_handle *) p;
4304 fprintf (stderr, "IEEE unsupported complex type size %u\n", size);
4308 /* FIXME: I don't know what the string is for. */
4309 return (ieee_define_type (info, size, false)
4310 && ieee_write_number (info, code)
4311 && ieee_write_id (info, ""));
4314 /* Make a boolean type. IEEE doesn't support these, so we just make
4315 an integer type instead. */
4318 ieee_bool_type (p, size)
4322 return ieee_int_type (p, size, true);
4325 /* Make an enumeration. */
4328 ieee_enum_type (p, tag, names, vals)
4332 bfd_signed_vma *vals;
4334 struct ieee_handle *info = (struct ieee_handle *) p;
4338 /* If this is a simple enumeration, in which the values start at 0
4339 and always increment by 1, we can use type E. Otherwise we must
4345 for (i = 0; names[i] != NULL; i++)
4355 if (! ieee_define_named_type (info, tag, true, (unsigned int) -1, 0,
4356 true, (struct ieee_buf **) NULL)
4357 || ! ieee_write_number (info, simple ? 'E' : 'N'))
4361 /* FIXME: This is supposed to be the enumeration size, but we
4362 don't store that. */
4363 if (! ieee_write_number (info, 4))
4368 for (i = 0; names[i] != NULL; i++)
4370 if (! ieee_write_id (info, names[i]))
4374 if (! ieee_write_number (info, vals[i]))
4383 /* Make a pointer type. */
4386 ieee_pointer_type (p)
4389 struct ieee_handle *info = (struct ieee_handle *) p;
4392 indx = ieee_pop_type (info);
4394 /* A pointer to a simple builtin type can be obtained by adding 32. */
4396 return ieee_push_type (info, indx + 32, 0, true);
4398 return (ieee_define_type (info, 0, true)
4399 && ieee_write_number (info, 'P')
4400 && ieee_write_number (info, indx));
4403 /* Make a function type. */
4406 ieee_function_type (p, argcount, varargs)
4411 struct ieee_handle *info = (struct ieee_handle *) p;
4412 unsigned int *args = NULL;
4414 unsigned int retindx;
4418 args = (unsigned int *) xmalloc (argcount * sizeof *args);
4419 for (i = argcount - 1; i >= 0; i--)
4420 args[i] = ieee_pop_type (info);
4422 else if (argcount < 0)
4425 retindx = ieee_pop_type (info);
4427 /* An attribute of 0x41 means that the frame and push mask are
4429 if (! ieee_define_type (info, 0, true)
4430 || ! ieee_write_number (info, 'x')
4431 || ! ieee_write_number (info, 0x41)
4432 || ! ieee_write_number (info, 0)
4433 || ! ieee_write_number (info, 0)
4434 || ! ieee_write_number (info, retindx)
4435 || ! ieee_write_number (info, (bfd_vma) argcount + (varargs ? 1 : 0)))
4439 for (i = 0; i < argcount; i++)
4440 if (! ieee_write_number (info, args[i]))
4446 /* A varargs function is represented by writing out the last
4447 argument as type void *, although this makes little sense. */
4448 if (! ieee_write_number (info, (bfd_vma) builtin_void + 32))
4452 return ieee_write_number (info, 0);
4455 /* Make a reference type. */
4458 ieee_reference_type (p)
4461 struct ieee_handle *info = (struct ieee_handle *) p;
4463 /* IEEE appears to record a normal pointer type, and then use a
4464 pmisc record to indicate that it is really a reference. */
4466 if (! ieee_pointer_type (p))
4468 info->type_stack->type.referencep = true;
4472 /* Make a range type. */
4475 ieee_range_type (p, low, high)
4478 bfd_signed_vma high;
4480 struct ieee_handle *info = (struct ieee_handle *) p;
4484 size = info->type_stack->type.size;
4485 unsignedp = info->type_stack->type.unsignedp;
4486 (void) ieee_pop_type (info);
4487 return (ieee_define_type (info, size, unsignedp)
4488 && ieee_write_number (info, 'R')
4489 && ieee_write_number (info, (bfd_vma) low)
4490 && ieee_write_number (info, (bfd_vma) high)
4491 && ieee_write_number (info, unsignedp ? 0 : 1)
4492 && ieee_write_number (info, size));
4495 /* Make an array type. */
4499 ieee_array_type (p, low, high, stringp)
4502 bfd_signed_vma high;
4505 struct ieee_handle *info = (struct ieee_handle *) p;
4506 unsigned int eleindx;
4508 /* IEEE does not store the range, so we just ignore it. */
4509 (void) ieee_pop_type (info);
4510 eleindx = ieee_pop_type (info);
4512 if (! ieee_define_type (info, 0, false)
4513 || ! ieee_write_number (info, low == 0 ? 'Z' : 'C')
4514 || ! ieee_write_number (info, eleindx))
4518 if (! ieee_write_number (info, low))
4522 return ieee_write_number (info, high);
4525 /* Make a set type. */
4528 ieee_set_type (p, bitstringp)
4532 struct ieee_handle *info = (struct ieee_handle *) p;
4533 unsigned int eleindx;
4535 eleindx = ieee_pop_type (info);
4537 /* FIXME: We don't know the size, so we just use 4. */
4539 return (ieee_define_type (info, 0, true)
4540 && ieee_write_number (info, 's')
4541 && ieee_write_number (info, 4)
4542 && ieee_write_number (info, eleindx));
4545 /* Make an offset type. */
4548 ieee_offset_type (p)
4551 struct ieee_handle *info = (struct ieee_handle *) p;
4552 unsigned int targetindx, baseindx;
4554 targetindx = ieee_pop_type (info);
4555 baseindx = ieee_pop_type (info);
4557 /* FIXME: The MRI C++ compiler does not appear to generate any
4558 useful type information about an offset type. It just records a
4559 pointer to member as an integer. The MRI/HP IEEE spec does
4560 describe a pmisc record which can be used for a pointer to
4561 member. Unfortunately, it does not describe the target type,
4562 which seems pretty important. I'm going to punt this for now. */
4564 return ieee_int_type (p, 4, true);
4567 /* Make a method type. */
4570 ieee_method_type (p, domain, argcount, varargs)
4576 struct ieee_handle *info = (struct ieee_handle *) p;
4578 /* FIXME: The MRI/HP IEEE spec defines a pmisc record to use for a
4579 method, but the definition is incomplete. We just output an 'x'
4583 (void) ieee_pop_type (info);
4585 return ieee_function_type (p, argcount, varargs);
4588 /* Make a const qualified type. */
4594 struct ieee_handle *info = (struct ieee_handle *) p;
4599 size = info->type_stack->type.size;
4600 unsignedp = info->type_stack->type.unsignedp;
4601 indx = ieee_pop_type (info);
4602 return (ieee_define_type (info, size, unsignedp)
4603 && ieee_write_number (info, 'n')
4604 && ieee_write_number (info, 1)
4605 && ieee_write_number (info, indx));
4608 /* Make a volatile qualified type. */
4611 ieee_volatile_type (p)
4614 struct ieee_handle *info = (struct ieee_handle *) p;
4619 size = info->type_stack->type.size;
4620 unsignedp = info->type_stack->type.unsignedp;
4621 indx = ieee_pop_type (info);
4622 return (ieee_define_type (info, size, unsignedp)
4623 && ieee_write_number (info, 'n')
4624 && ieee_write_number (info, 2)
4625 && ieee_write_number (info, indx));
4628 /* Convert an enum debug_visibility into a CXXFLAGS value. */
4631 ieee_vis_to_flags (visibility)
4632 enum debug_visibility visibility;
4638 case DEBUG_VISIBILITY_PUBLIC:
4639 return CXXFLAGS_VISIBILITY_PUBLIC;
4640 case DEBUG_VISIBILITY_PRIVATE:
4641 return CXXFLAGS_VISIBILITY_PRIVATE;
4642 case DEBUG_VISIBILITY_PROTECTED:
4643 return CXXFLAGS_VISIBILITY_PROTECTED;
4648 /* Start defining a struct type. We build it in the strdef field on
4649 the stack, to avoid confusing type definitions required by the
4650 fields with the struct type itself. */
4653 ieee_start_struct_type (p, tag, id, structp, size)
4660 struct ieee_handle *info = (struct ieee_handle *) p;
4661 struct ieee_buf *strdef;
4664 if (! ieee_define_named_type (info, tag, true, id, size, true, &strdef)
4665 || ! ieee_write_number (info, structp ? 'S' : 'U')
4666 || ! ieee_write_number (info, size))
4669 info->type_stack->type.strdef = strdef;
4674 /* Add a field to a struct. */
4677 ieee_struct_field (p, name, bitpos, bitsize, visibility)
4682 enum debug_visibility visibility;
4684 struct ieee_handle *info = (struct ieee_handle *) p;
4690 size = info->type_stack->type.size;
4691 unsignedp = info->type_stack->type.unsignedp;
4692 indx = ieee_pop_type (info);
4694 assert (info->type_stack != NULL && info->type_stack->type.strdef != NULL);
4696 if (info->type_stack->type.classdef != NULL)
4701 /* This is a class. We must add a description of this field to
4702 the class records we are building. */
4704 flags = ieee_vis_to_flags (visibility);
4705 nindx = info->type_stack->type.classdef->indx;
4706 if (! ieee_change_buffer (info,
4707 &info->type_stack->type.classdef->pmiscbuf)
4708 || ! ieee_write_asn (info, nindx, 'd')
4709 || ! ieee_write_asn (info, nindx, flags)
4710 || ! ieee_write_atn65 (info, nindx, name)
4711 || ! ieee_write_atn65 (info, nindx, name))
4713 info->type_stack->type.classdef->pmisccount += 4;
4716 /* If the bitsize doesn't match the expected size, we need to output
4718 if (size == 0 || bitsize == size * 8)
4719 offset = bitpos / 8;
4722 if (! ieee_define_type (info, 0, unsignedp)
4723 || ! ieee_write_number (info, 'g')
4724 || ! ieee_write_number (info, unsignedp ? 0 : 1)
4725 || ! ieee_write_number (info, indx))
4727 indx = ieee_pop_type (info);
4731 /* Switch to the struct we are building in order to output this
4732 field definition. */
4733 return (ieee_change_buffer (info, &info->type_stack->type.strdef)
4734 && ieee_write_id (info, name)
4735 && ieee_write_number (info, indx)
4736 && ieee_write_number (info, offset));
4739 /* Finish up a struct type. */
4742 ieee_end_struct_type (p)
4745 struct ieee_handle *info = (struct ieee_handle *) p;
4746 struct ieee_buf **pb;
4748 assert (info->type_stack != NULL && info->type_stack->type.strdef != NULL);
4750 /* Make sure we have started the types block. */
4751 if (info->types == NULL)
4753 if (! ieee_change_buffer (info, &info->types)
4754 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
4755 || ! ieee_write_byte (info, 1)
4756 || ! ieee_write_number (info, 0)
4757 || ! ieee_write_id (info, info->modname))
4761 /* Append the struct definition to the types. */
4762 for (pb = &info->types; *pb != NULL; pb = &(*pb)->next)
4764 *pb = info->type_stack->type.strdef;
4765 info->type_stack->type.strdef = NULL;
4767 /* Leave the struct on the type stack. */
4772 /* Start a class type. */
4775 ieee_start_class_type (p, tag, id, structp, size, vptr, ownvptr)
4784 struct ieee_handle *info = (struct ieee_handle *) p;
4786 struct ieee_buf *pmiscbuf;
4788 struct ieee_type_class *classdef;
4789 struct ieee_name_type *nt;
4791 /* A C++ class is output as a C++ struct along with a set of pmisc
4792 records describing the class. */
4794 /* We need to have a name so that we can associate the struct and
4800 t = (char *) xmalloc (20);
4801 sprintf (t, "__anon%u", id);
4805 /* We can't write out the virtual table information until we have
4806 finished the class, because we don't know the virtual table size.
4807 We get the size from the largest voffset we see. */
4809 if (vptr && ! ownvptr)
4811 assert (info->type_stack->type.classdef != NULL);
4812 vclass = info->type_stack->type.classdef->name;
4813 (void) ieee_pop_type (info);
4816 if (! ieee_start_struct_type (p, tag, id, structp, size))
4819 indx = info->name_indx;
4822 /* We write out pmisc records into the classdef field. We will
4823 write out the pmisc start after we know the number of records we
4826 if (! ieee_change_buffer (info, &pmiscbuf)
4827 || ! ieee_write_asn (info, indx, 'T')
4828 || ! ieee_write_asn (info, indx, structp ? 'o' : 'u')
4829 || ! ieee_write_atn65 (info, indx, tag))
4832 classdef = (struct ieee_type_class *) xmalloc (sizeof *classdef);
4833 memset (classdef, 0, sizeof *classdef);
4835 classdef->name = tag;
4836 classdef->indx = indx;
4837 classdef->pmiscbuf = pmiscbuf;
4838 classdef->pmisccount = 3;
4839 classdef->vclass = vclass;
4840 classdef->ownvptr = ownvptr;
4842 info->type_stack->type.classdef = classdef;
4844 /* We need to fill in the classdef in the tag as well, so that it
4845 will be set when ieee_tag_type is called. */
4846 for (nt = info->tags; nt != NULL; nt = nt->next)
4847 if (nt->name[0] == tag[0]
4848 && strcmp (nt->name, tag) == 0)
4850 assert (nt != NULL);
4851 nt->type.classdef = classdef;
4856 /* Add a static member to a class. */
4859 ieee_class_static_member (p, name, physname, visibility)
4862 const char *physname;
4863 enum debug_visibility visibility;
4865 struct ieee_handle *info = (struct ieee_handle *) p;
4869 /* We don't care about the type. Hopefully there will be a call
4870 ieee_variable declaring the physical name and the type, since
4871 that is where an IEEE consumer must get the type. */
4872 (void) ieee_pop_type (info);
4874 assert (info->type_stack != NULL
4875 && info->type_stack->type.classdef != NULL);
4877 flags = ieee_vis_to_flags (visibility);
4878 flags |= CXXFLAGS_STATIC;
4880 nindx = info->type_stack->type.classdef->indx;
4882 if (! ieee_change_buffer (info, &info->type_stack->type.classdef->pmiscbuf)
4883 || ! ieee_write_asn (info, nindx, 'd')
4884 || ! ieee_write_asn (info, nindx, flags)
4885 || ! ieee_write_atn65 (info, nindx, name)
4886 || ! ieee_write_atn65 (info, nindx, physname))
4888 info->type_stack->type.classdef->pmisccount += 4;
4893 /* Add a base class to a class. */
4896 ieee_class_baseclass (p, bitpos, virtual, visibility)
4900 enum debug_visibility visibility;
4902 struct ieee_handle *info = (struct ieee_handle *) p;
4909 assert (info->type_stack != NULL
4910 && info->type_stack->type.classdef != NULL
4911 && info->type_stack->next != NULL
4912 && info->type_stack->next->type.classdef != NULL
4913 && info->type_stack->next->type.strdef != NULL);
4915 bname = info->type_stack->type.classdef->name;
4916 bindx = ieee_pop_type (info);
4918 /* We are currently defining both a struct and a class. We must
4919 write out a field definition in the struct which holds the base
4920 class. The stabs debugging reader will create a field named
4921 _vb$CLASS for a virtual base class, so we just use that. FIXME:
4922 we should not depend upon a detail of stabs debugging. */
4925 fname = (char *) xmalloc (strlen (bname) + sizeof "_vb$");
4926 sprintf (fname, "_vb$%s", bname);
4927 flags = BASEFLAGS_VIRTUAL;
4931 fname = (char *) xmalloc (strlen (bname) + sizeof "_b$");
4932 sprintf (fname, "_b$%s", bname);
4934 if (! ieee_change_buffer (info, &info->type_stack->type.strdef)
4935 || ! ieee_write_id (info, fname)
4936 || ! ieee_write_number (info, bindx)
4937 || ! ieee_write_number (info, bitpos / 8))
4942 if (visibility == DEBUG_VISIBILITY_PRIVATE)
4943 flags |= BASEFLAGS_PRIVATE;
4945 nindx = info->type_stack->type.classdef->indx;
4947 if (! ieee_change_buffer (info, &info->type_stack->type.classdef->pmiscbuf)
4948 || ! ieee_write_asn (info, nindx, 'b')
4949 || ! ieee_write_asn (info, nindx, flags)
4950 || ! ieee_write_atn65 (info, nindx, bname)
4951 || ! ieee_write_asn (info, nindx, 0)
4952 || ! ieee_write_atn65 (info, nindx, fname))
4954 info->type_stack->type.classdef->pmisccount += 5;
4961 /* Start building a method for a class. */
4964 ieee_class_start_method (p, name)
4968 struct ieee_handle *info = (struct ieee_handle *) p;
4970 assert (info->type_stack != NULL
4971 && info->type_stack->type.classdef != NULL
4972 && info->type_stack->type.classdef->method == NULL);
4974 info->type_stack->type.classdef->method = name;
4979 /* Define a new method variant, either static or not. */
4982 ieee_class_method_var (info, physname, visibility, staticp, constp,
4983 volatilep, voffset, context)
4984 struct ieee_handle *info;
4985 const char *physname;
4986 enum debug_visibility visibility;
4997 /* We don't need the type of the method. An IEEE consumer which
4998 wants the type must track down the function by the physical name
4999 and get the type from that. */
5000 (void) ieee_pop_type (info);
5002 /* We don't use the context. FIXME: We probably ought to use it to
5003 adjust the voffset somehow, but I don't really know how. */
5005 (void) ieee_pop_type (info);
5007 assert (info->type_stack != NULL
5008 && info->type_stack->type.classdef != NULL
5009 && info->type_stack->type.classdef->method != NULL);
5011 flags = ieee_vis_to_flags (visibility);
5013 /* FIXME: We never set CXXFLAGS_OVERRIDE, CXXFLAGS_OPERATOR,
5014 CXXFLAGS_CTORDTOR, CXXFLAGS_CTOR, or CXXFLAGS_INLINE. */
5017 flags |= CXXFLAGS_STATIC;
5019 flags |= CXXFLAGS_CONST;
5021 flags |= CXXFLAGS_VOLATILE;
5023 nindx = info->type_stack->type.classdef->indx;
5025 virtual = context || voffset > 0;
5027 if (! ieee_change_buffer (info,
5028 &info->type_stack->type.classdef->pmiscbuf)
5029 || ! ieee_write_asn (info, nindx, virtual ? 'v' : 'm')
5030 || ! ieee_write_asn (info, nindx, flags)
5031 || ! ieee_write_atn65 (info, nindx,
5032 info->type_stack->type.classdef->method)
5033 || ! ieee_write_atn65 (info, nindx, physname))
5038 if (voffset > info->type_stack->type.classdef->voffset)
5039 info->type_stack->type.classdef->voffset = voffset;
5040 /* FIXME: The size of a vtable entry depends upon the
5042 if (! ieee_write_asn (info, nindx, (voffset / 4) + 1))
5044 ++info->type_stack->type.classdef->pmisccount;
5047 if (! ieee_write_asn (info, nindx, 0))
5050 info->type_stack->type.classdef->pmisccount += 5;
5055 /* Define a new method variant. */
5058 ieee_class_method_variant (p, physname, visibility, constp, volatilep,
5061 const char *physname;
5062 enum debug_visibility visibility;
5068 struct ieee_handle *info = (struct ieee_handle *) p;
5070 return ieee_class_method_var (info, physname, visibility, false, constp,
5071 volatilep, voffset, context);
5074 /* Define a new static method variant. */
5077 ieee_class_static_method_variant (p, physname, visibility, constp, volatilep)
5079 const char *physname;
5080 enum debug_visibility visibility;
5084 struct ieee_handle *info = (struct ieee_handle *) p;
5086 return ieee_class_method_var (info, physname, visibility, true, constp,
5087 volatilep, 0, false);
5090 /* Finish up a method. */
5093 ieee_class_end_method (p)
5096 struct ieee_handle *info = (struct ieee_handle *) p;
5098 assert (info->type_stack != NULL
5099 && info->type_stack->type.classdef != NULL
5100 && info->type_stack->type.classdef->method != NULL);
5102 info->type_stack->type.classdef->method = NULL;
5107 /* Finish up a class. */
5110 ieee_end_class_type (p)
5113 struct ieee_handle *info = (struct ieee_handle *) p;
5115 struct ieee_buf **pb;
5117 assert (info->type_stack != NULL
5118 && info->type_stack->type.classdef != NULL);
5120 nindx = info->type_stack->type.classdef->indx;
5122 /* If we have a virtual table, we can write out the information now. */
5123 if (info->type_stack->type.classdef->vclass != NULL
5124 || info->type_stack->type.classdef->ownvptr)
5128 /* FIXME: This calculation is architecture dependent. */
5129 vsize = (info->type_stack->type.classdef->voffset + 4) / 4;
5131 if (! ieee_change_buffer (info,
5132 &info->type_stack->type.classdef->pmiscbuf)
5133 || ! ieee_write_asn (info, nindx, 'z')
5134 || ! ieee_write_atn65 (info, nindx, "")
5135 || ! ieee_write_asn (info, nindx, vsize))
5137 if (info->type_stack->type.classdef->ownvptr)
5139 if (! ieee_write_atn65 (info, nindx, ""))
5144 if (! ieee_write_atn65 (info, nindx,
5145 info->type_stack->type.classdef->vclass))
5148 if (! ieee_write_asn (info, nindx, 0))
5150 info->type_stack->type.classdef->pmisccount += 5;
5153 /* Now that we know the number of pmisc records, we can write out
5154 the atn62 which starts the pmisc records, and append them to the
5157 if (! ieee_change_buffer (info, &info->cxx)
5158 || ! ieee_write_byte (info, (int) ieee_nn_record)
5159 || ! ieee_write_number (info, nindx)
5160 || ! ieee_write_id (info, "")
5161 || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
5162 || ! ieee_write_number (info, nindx)
5163 || ! ieee_write_number (info, 0)
5164 || ! ieee_write_number (info, 62)
5165 || ! ieee_write_number (info, 80)
5166 || ! ieee_write_number (info,
5167 info->type_stack->type.classdef->pmisccount))
5170 for (pb = &info->cxx; *pb != NULL; pb = &(*pb)->next)
5172 *pb = info->type_stack->type.classdef->pmiscbuf;
5174 return ieee_end_struct_type (p);
5177 /* Push a previously seen typedef onto the type stack. */
5180 ieee_typedef_type (p, name)
5184 struct ieee_handle *info = (struct ieee_handle *) p;
5185 register struct ieee_name_type *nt;
5187 for (nt = info->typedefs; nt != NULL; nt = nt->next)
5189 if (nt->name[0] == name[0]
5190 && strcmp (nt->name, name) == 0)
5192 if (! ieee_push_type (info, nt->type.indx, nt->type.size,
5193 nt->type.unsignedp))
5195 /* Copy over any other type information we may have. */
5196 info->type_stack->type = nt->type;
5204 /* Push a tagged type onto the type stack. */
5207 ieee_tag_type (p, name, id, kind)
5211 enum debug_type_kind kind;
5213 struct ieee_handle *info = (struct ieee_handle *) p;
5214 register struct ieee_name_type *nt;
5219 sprintf (ab, "__anon%u", id);
5223 for (nt = info->tags; nt != NULL; nt = nt->next)
5225 if (nt->name[0] == name[0]
5226 && strcmp (nt->name, name) == 0)
5228 if (! ieee_push_type (info, nt->type.indx, nt->type.size,
5229 nt->type.unsignedp))
5231 /* Copy over any other type information we may have. */
5232 info->type_stack->type = nt->type;
5237 nt = (struct ieee_name_type *) xmalloc (sizeof *nt);
5238 memset (nt, 0, sizeof *nt);
5241 nt->type.indx = info->type_indx;
5245 nt->next = info->tags;
5248 return ieee_push_type (info, nt->type.indx, 0, false);
5251 /* Output a typedef. */
5254 ieee_typdef (p, name)
5258 struct ieee_handle *info = (struct ieee_handle *) p;
5259 struct ieee_name_type *nt;
5264 nt = (struct ieee_name_type *) xmalloc (sizeof *nt);
5265 memset (nt, 0, sizeof *nt);
5267 nt->type = info->type_stack->type;
5268 nt->kind = DEBUG_KIND_ILLEGAL;
5270 nt->next = info->typedefs;
5271 info->typedefs = nt;
5273 size = info->type_stack->type.size;
5274 unsignedp = info->type_stack->type.unsignedp;
5275 indx = ieee_pop_type (info);
5277 /* If this is a simple builtin type using a builtin name, we don't
5278 want to output the typedef itself. We also want to change the
5279 type index to correspond to the name being used. We recognize
5280 names used in stabs debugging output even if they don't exactly
5281 correspond to the names used for the IEEE builtin types. */
5282 if (indx <= (unsigned int) builtin_bcd_float)
5287 switch ((enum builtin_types) indx)
5293 if (strcmp (name, "void") == 0)
5297 case builtin_signed_char:
5299 if (strcmp (name, "signed char") == 0)
5301 indx = (unsigned int) builtin_signed_char;
5304 else if (strcmp (name, "char") == 0)
5306 indx = (unsigned int) builtin_char;
5311 case builtin_unsigned_char:
5312 if (strcmp (name, "unsigned char") == 0)
5316 case builtin_signed_short_int:
5318 case builtin_short_int:
5319 case builtin_signed_short:
5320 if (strcmp (name, "signed short int") == 0)
5322 indx = (unsigned int) builtin_signed_short_int;
5325 else if (strcmp (name, "short") == 0)
5327 indx = (unsigned int) builtin_short;
5330 else if (strcmp (name, "short int") == 0)
5332 indx = (unsigned int) builtin_short_int;
5335 else if (strcmp (name, "signed short") == 0)
5337 indx = (unsigned int) builtin_signed_short;
5342 case builtin_unsigned_short_int:
5343 case builtin_unsigned_short:
5344 if (strcmp (name, "unsigned short int") == 0
5345 || strcmp (name, "short unsigned int") == 0)
5347 indx = builtin_unsigned_short_int;
5350 else if (strcmp (name, "unsigned short") == 0)
5352 indx = builtin_unsigned_short;
5357 case builtin_signed_long:
5358 case builtin_int: /* FIXME: Size depends upon architecture. */
5360 if (strcmp (name, "signed long") == 0)
5362 indx = builtin_signed_long;
5365 else if (strcmp (name, "int") == 0)
5370 else if (strcmp (name, "long") == 0
5371 || strcmp (name, "long int") == 0)
5373 indx = builtin_long;
5378 case builtin_unsigned_long:
5379 case builtin_unsigned: /* FIXME: Size depends upon architecture. */
5380 case builtin_unsigned_int: /* FIXME: Like builtin_unsigned. */
5381 if (strcmp (name, "unsigned long") == 0
5382 || strcmp (name, "long unsigned int") == 0)
5384 indx = builtin_unsigned_long;
5387 else if (strcmp (name, "unsigned") == 0)
5389 indx = builtin_unsigned;
5392 else if (strcmp (name, "unsigned int") == 0)
5394 indx = builtin_unsigned_int;
5399 case builtin_signed_long_long:
5400 if (strcmp (name, "signed long long") == 0
5401 || strcmp (name, "long long int") == 0)
5405 case builtin_unsigned_long_long:
5406 if (strcmp (name, "unsigned long long") == 0
5407 || strcmp (name, "long long unsigned int") == 0)
5412 if (strcmp (name, "float") == 0)
5416 case builtin_double:
5417 if (strcmp (name, "double") == 0)
5421 case builtin_long_double:
5422 if (strcmp (name, "long double") == 0)
5426 case builtin_long_long_double:
5427 if (strcmp (name, "long long double") == 0)
5434 nt->type.indx = indx;
5439 if (! ieee_define_named_type (info, name, false, 0, size, unsignedp,
5440 (struct ieee_buf **) NULL)
5441 || ! ieee_write_number (info, 'T')
5442 || ! ieee_write_number (info, indx))
5445 /* Remove the type we just added to the type stack. */
5446 (void) ieee_pop_type (info);
5451 /* Output a tag for a type. We don't have to do anything here. */
5458 struct ieee_handle *info = (struct ieee_handle *) p;
5460 (void) ieee_pop_type (info);
5464 /* Output an integer constant. */
5467 ieee_int_constant (p, name, val)
5476 /* Output a floating point constant. */
5479 ieee_float_constant (p, name, val)
5488 /* Output a typed constant. */
5491 ieee_typed_constant (p, name, val)
5496 struct ieee_handle *info = (struct ieee_handle *) p;
5499 (void) ieee_pop_type (info);
5503 /* Output a variable. */
5506 ieee_variable (p, name, kind, val)
5509 enum debug_var_kind kind;
5512 struct ieee_handle *info = (struct ieee_handle *) p;
5513 unsigned int name_indx;
5515 unsigned int type_indx;
5518 /* Make sure the variable section is started. */
5519 if (info->vars != NULL)
5521 if (! ieee_change_buffer (info, &info->vars))
5526 if (! ieee_change_buffer (info, &info->vars)
5527 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
5528 || ! ieee_write_byte (info, 3)
5529 || ! ieee_write_number (info, 0)
5530 || ! ieee_write_id (info, info->modname))
5534 name_indx = info->name_indx;
5537 size = info->type_stack->type.size;
5538 type_indx = ieee_pop_type (info);
5540 /* Write out an NN and an ATN record for this variable. */
5541 if (! ieee_write_byte (info, (int) ieee_nn_record)
5542 || ! ieee_write_number (info, name_indx)
5543 || ! ieee_write_id (info, name)
5544 || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
5545 || ! ieee_write_number (info, name_indx)
5546 || ! ieee_write_number (info, type_indx))
5554 if (! ieee_write_number (info, 8)
5555 || ! ieee_add_range (info, val, val + size))
5560 case DEBUG_LOCAL_STATIC:
5561 if (! ieee_write_number (info, 3)
5562 || ! ieee_add_range (info, val, val + size))
5567 if (! ieee_write_number (info, 1)
5568 || ! ieee_write_number (info, val))
5572 case DEBUG_REGISTER:
5573 if (! ieee_write_number (info, 2)
5574 || ! ieee_write_number (info,
5575 ieee_genreg_to_regno (info->abfd, val)))
5583 if (! ieee_write_asn (info, name_indx, val))
5590 /* Start outputting information for a function. */
5593 ieee_start_function (p, name, global)
5598 struct ieee_handle *info = (struct ieee_handle *) p;
5601 /* Make sure the variable section is started. */
5602 if (info->vars != NULL)
5604 if (! ieee_change_buffer (info, &info->vars))
5609 if (! ieee_change_buffer (info, &info->vars)
5610 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
5611 || ! ieee_write_byte (info, 3)
5612 || ! ieee_write_number (info, 0)
5613 || ! ieee_write_id (info, info->modname))
5617 indx = ieee_pop_type (info);
5619 /* The address is written out as the first block. */
5621 ++info->block_depth;
5623 return (ieee_write_byte (info, (int) ieee_bb_record_enum)
5624 && ieee_write_byte (info, global ? 4 : 6)
5625 && ieee_write_number (info, 0)
5626 && ieee_write_id (info, name)
5627 && ieee_write_number (info, 0)
5628 && ieee_write_number (info, indx));
5631 /* Add a function parameter. This will normally be called before the
5632 first block, so we postpone them until we see the block. */
5635 ieee_function_parameter (p, name, kind, val)
5638 enum debug_parm_kind kind;
5641 struct ieee_handle *info = (struct ieee_handle *) p;
5642 struct ieee_pending_parm *m, **pm;
5644 assert (info->block_depth == 1);
5646 m = (struct ieee_pending_parm *) xmalloc (sizeof *m);
5647 memset (m, 0, sizeof *m);
5651 m->type = ieee_pop_type (info);
5655 for (pm = &info->pending_parms; *pm != NULL; pm = &(*pm)->next)
5662 /* Output pending function parameters. */
5665 ieee_output_pending_parms (info)
5666 struct ieee_handle *info;
5668 struct ieee_pending_parm *m;
5670 m = info->pending_parms;
5673 struct ieee_pending_parm *next;
5674 enum debug_var_kind vkind;
5681 case DEBUG_PARM_STACK:
5682 case DEBUG_PARM_REFERENCE:
5683 vkind = DEBUG_LOCAL;
5685 case DEBUG_PARM_REG:
5686 case DEBUG_PARM_REF_REG:
5687 vkind = DEBUG_REGISTER;
5691 if (! ieee_push_type (info, m->type, 0, false)
5692 || ! ieee_variable ((PTR) info, m->name, vkind, m->val))
5695 /* FIXME: We should output a pmisc note here for reference
5702 info->pending_parms = NULL;
5707 /* Start a block. If this is the first block, we output the address
5708 to finish the BB4 or BB6, and then output the function parameters. */
5711 ieee_start_block (p, addr)
5715 struct ieee_handle *info = (struct ieee_handle *) p;
5717 if (! ieee_change_buffer (info, &info->vars))
5720 if (info->block_depth == 1)
5722 if (! ieee_write_number (info, addr)
5723 || ! ieee_output_pending_parms (info))
5728 if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
5729 || ! ieee_write_byte (info, 6)
5730 || ! ieee_write_number (info, 0)
5731 || ! ieee_write_id (info, "")
5732 || ! ieee_write_number (info, 0)
5733 || ! ieee_write_number (info, 0)
5734 || ! ieee_write_number (info, addr))
5738 if (! ieee_start_range (info, addr))
5741 ++info->block_depth;
5749 ieee_end_block (p, addr)
5753 struct ieee_handle *info = (struct ieee_handle *) p;
5755 if (! ieee_change_buffer (info, &info->vars)
5756 || ! ieee_write_byte (info, (int) ieee_be_record_enum)
5757 || ! ieee_write_number (info, addr))
5760 if (! ieee_end_range (info, addr))
5763 --info->block_depth;
5765 if (addr > info->highaddr)
5766 info->highaddr = addr;
5771 /* End a function. */
5774 ieee_end_function (p)
5777 struct ieee_handle *info = (struct ieee_handle *) p;
5779 assert (info->block_depth == 1);
5781 --info->block_depth;
5786 /* Record line number information. */
5789 ieee_lineno (p, filename, lineno, addr)
5791 const char *filename;
5792 unsigned long lineno;
5795 struct ieee_handle *info = (struct ieee_handle *) p;
5797 assert (info->filename != NULL);
5799 /* Make sure we have a line number block. */
5800 if (info->linenos != NULL)
5802 if (! ieee_change_buffer (info, &info->linenos))
5807 info->lineno_name_indx = info->name_indx;
5809 if (! ieee_change_buffer (info, &info->linenos)
5810 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
5811 || ! ieee_write_byte (info, 5)
5812 || ! ieee_write_number (info, 0)
5813 || ! ieee_write_id (info, info->filename)
5814 || ! ieee_write_byte (info, (int) ieee_nn_record)
5815 || ! ieee_write_number (info, info->lineno_name_indx)
5816 || ! ieee_write_id (info, ""))
5818 info->lineno_filename = info->filename;
5821 if (strcmp (filename, info->lineno_filename) != 0)
5823 if (strcmp (info->filename, info->lineno_filename) != 0)
5825 /* We were not in the main file. Close the block for the
5827 if (! ieee_write_byte (info, (int) ieee_be_record_enum))
5830 if (strcmp (info->filename, filename) != 0)
5832 /* We are not changing to the main file. Open a block for
5833 the new included file. */
5834 if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
5835 || ! ieee_write_byte (info, 5)
5836 || ! ieee_write_number (info, 0)
5837 || ! ieee_write_id (info, filename))
5840 info->lineno_filename = filename;
5843 return (ieee_write_2bytes (info, (int) ieee_atn_record_enum)
5844 && ieee_write_number (info, info->lineno_name_indx)
5845 && ieee_write_number (info, 0)
5846 && ieee_write_number (info, 7)
5847 && ieee_write_number (info, lineno)
5848 && ieee_write_number (info, 0)
5849 && ieee_write_asn (info, info->lineno_name_indx, addr));