1 /* ieee.c -- Write out IEEE-695 debugging information.
2 Copyright (C) 1996 Free Software Foundation, Inc.
3 Written by Ian Lance Taylor <ian@cygnus.com>.
5 This file is part of GNU Binutils.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22 /* This file reads and writes IEEE-695 debugging information. */
30 #include "libiberty.h"
34 /* This structure holds an entry on the block stack. */
38 /* The kind of block. */
40 /* The source file name, for a BB5 block. */
44 /* This structure is the block stack. */
46 #define BLOCKSTACK_SIZE (16)
48 struct ieee_blockstack
50 /* The stack pointer. */
51 struct ieee_block *bsp;
53 struct ieee_block stack[BLOCKSTACK_SIZE];
56 /* This structure holds information for a variable. */
68 /* This structure holds all the variables. */
72 /* Number of slots allocated. */
75 struct ieee_var *vars;
78 /* This structure holds information for a type. We need this because
79 we don't want to represent bitfields as real types. */
85 /* 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 is how we store types for the writing routines. Most types
3140 are simply represented by a type index. */
3142 struct ieee_write_type
3146 /* The size of the type, if known. */
3148 /* If this is a struct, this is where the struct definition is
3150 struct ieee_buf *strdef;
3151 /* Whether the type is unsigned. */
3152 unsigned int unsignedp : 1;
3153 /* Whether this is a reference type. */
3154 unsigned int referencep : 1;
3157 /* This is the type stack used by the debug writing routines. FIXME:
3158 We could generate more efficient output if we remembered when we
3159 have output a particular type before. */
3161 struct ieee_type_stack
3163 /* Next entry on stack. */
3164 struct ieee_type_stack *next;
3165 /* Type information. */
3166 struct ieee_write_type type;
3169 /* This is a list of associations between names and types. This could
3170 be more efficiently implemented as a hash table. */
3172 struct ieee_name_type
3174 /* Next name/type assocation. */
3175 struct ieee_name_type *next;
3179 struct ieee_write_type type;
3180 /* If this is a tag which has not yet been defined, this is the
3181 kind. If the tag has been defined, this is DEBUG_KIND_ILLEGAL. */
3182 enum debug_type_kind kind;
3185 /* This is a list of pending function parameter information. We don't
3186 output them until we see the first block. */
3188 struct ieee_pending_parm
3190 /* Next pending parameter. */
3191 struct ieee_pending_parm *next;
3197 enum debug_parm_kind kind;
3202 /* This is the handle passed down by debug_write. */
3206 /* BFD we are writing to. */
3208 /* Current data buffer. */
3209 struct ieee_buf *current;
3210 /* Filename of current compilation unit. */
3211 const char *filename;
3212 /* Module name of current compilation unit. */
3213 const char *modname;
3214 /* List of finished data buffers. */
3215 struct ieee_buf *data;
3216 /* List of buffers for typedefs in the current compilation unit. */
3217 struct ieee_buf *types;
3218 /* List of buffers for variables and functions in the current
3219 compilation unit. */
3220 struct ieee_buf *vars;
3221 /* List of buffers for line numbers in the current compilation unit. */
3222 struct ieee_buf *linenos;
3223 /* Ranges for the current compilation unit. */
3224 struct ieee_range *ranges;
3225 /* Nested pending ranges. */
3226 struct ieee_range *pending_ranges;
3228 struct ieee_type_stack *type_stack;
3229 /* Next unallocated type index. */
3230 unsigned int type_indx;
3231 /* Next unallocated name index. */
3232 unsigned int name_indx;
3234 struct ieee_name_type *typedefs;
3236 struct ieee_name_type *tags;
3237 /* The depth of block nesting. This is 0 outside a function, and 1
3238 just after start_function is called. */
3239 unsigned int block_depth;
3240 /* Pending function parameters. */
3241 struct ieee_pending_parm *pending_parms;
3242 /* Current line number filename. */
3243 const char *lineno_filename;
3244 /* Line number name index. */
3245 unsigned int lineno_name_indx;
3248 static boolean ieee_change_buffer
3249 PARAMS ((struct ieee_handle *, struct ieee_buf **));
3250 static boolean ieee_push_type
3251 PARAMS ((struct ieee_handle *, unsigned int, unsigned int, boolean));
3252 static unsigned int ieee_pop_type PARAMS ((struct ieee_handle *));
3253 static boolean ieee_add_range
3254 PARAMS ((struct ieee_handle *, bfd_vma, bfd_vma));
3255 static boolean ieee_start_range PARAMS ((struct ieee_handle *, bfd_vma));
3256 static boolean ieee_end_range PARAMS ((struct ieee_handle *, bfd_vma));
3257 static boolean ieee_real_write_byte PARAMS ((struct ieee_handle *, int));
3258 static boolean ieee_write_2bytes PARAMS ((struct ieee_handle *, int));
3259 static boolean ieee_write_number PARAMS ((struct ieee_handle *, bfd_vma));
3260 static boolean ieee_write_id PARAMS ((struct ieee_handle *, const char *));
3261 static boolean ieee_define_type
3262 PARAMS ((struct ieee_handle *, unsigned int, boolean));
3263 static boolean ieee_define_named_type
3264 PARAMS ((struct ieee_handle *, const char *, boolean, unsigned int, boolean,
3265 struct ieee_buf **));
3266 static boolean ieee_finish_compilation_unit PARAMS ((struct ieee_handle *));
3267 static boolean ieee_output_pending_parms PARAMS ((struct ieee_handle *));
3269 static boolean ieee_start_compilation_unit PARAMS ((PTR, const char *));
3270 static boolean ieee_start_source PARAMS ((PTR, const char *));
3271 static boolean ieee_empty_type PARAMS ((PTR));
3272 static boolean ieee_void_type PARAMS ((PTR));
3273 static boolean ieee_int_type PARAMS ((PTR, unsigned int, boolean));
3274 static boolean ieee_float_type PARAMS ((PTR, unsigned int));
3275 static boolean ieee_complex_type PARAMS ((PTR, unsigned int));
3276 static boolean ieee_bool_type PARAMS ((PTR, unsigned int));
3277 static boolean ieee_enum_type
3278 PARAMS ((PTR, const char *, const char **, bfd_signed_vma *));
3279 static boolean ieee_pointer_type PARAMS ((PTR));
3280 static boolean ieee_function_type PARAMS ((PTR, int, boolean));
3281 static boolean ieee_reference_type PARAMS ((PTR));
3282 static boolean ieee_range_type PARAMS ((PTR, bfd_signed_vma, bfd_signed_vma));
3283 static boolean ieee_array_type
3284 PARAMS ((PTR, bfd_signed_vma, bfd_signed_vma, boolean));
3285 static boolean ieee_set_type PARAMS ((PTR, boolean));
3286 static boolean ieee_offset_type PARAMS ((PTR));
3287 static boolean ieee_method_type PARAMS ((PTR, boolean, int, boolean));
3288 static boolean ieee_const_type PARAMS ((PTR));
3289 static boolean ieee_volatile_type PARAMS ((PTR));
3290 static boolean ieee_start_struct_type
3291 PARAMS ((PTR, const char *, unsigned int, boolean, unsigned int));
3292 static boolean ieee_struct_field
3293 PARAMS ((PTR, const char *, bfd_vma, bfd_vma, enum debug_visibility));
3294 static boolean ieee_end_struct_type PARAMS ((PTR));
3295 static boolean ieee_start_class_type
3296 PARAMS ((PTR, const char *, unsigned int, boolean, unsigned int, boolean,
3298 static boolean ieee_class_static_member
3299 PARAMS ((PTR, const char *, const char *, enum debug_visibility));
3300 static boolean ieee_class_baseclass
3301 PARAMS ((PTR, bfd_vma, boolean, enum debug_visibility));
3302 static boolean ieee_class_start_method PARAMS ((PTR, const char *));
3303 static boolean ieee_class_method_variant
3304 PARAMS ((PTR, const char *, enum debug_visibility, boolean, boolean,
3306 static boolean ieee_class_static_method_variant
3307 PARAMS ((PTR, const char *, enum debug_visibility, boolean, boolean));
3308 static boolean ieee_class_end_method PARAMS ((PTR));
3309 static boolean ieee_end_class_type PARAMS ((PTR));
3310 static boolean ieee_typedef_type PARAMS ((PTR, const char *));
3311 static boolean ieee_tag_type
3312 PARAMS ((PTR, const char *, unsigned int, enum debug_type_kind));
3313 static boolean ieee_typdef PARAMS ((PTR, const char *));
3314 static boolean ieee_tag PARAMS ((PTR, const char *));
3315 static boolean ieee_int_constant PARAMS ((PTR, const char *, bfd_vma));
3316 static boolean ieee_float_constant PARAMS ((PTR, const char *, double));
3317 static boolean ieee_typed_constant PARAMS ((PTR, const char *, bfd_vma));
3318 static boolean ieee_variable
3319 PARAMS ((PTR, const char *, enum debug_var_kind, bfd_vma));
3320 static boolean ieee_start_function PARAMS ((PTR, const char *, boolean));
3321 static boolean ieee_function_parameter
3322 PARAMS ((PTR, const char *, enum debug_parm_kind, bfd_vma));
3323 static boolean ieee_start_block PARAMS ((PTR, bfd_vma));
3324 static boolean ieee_end_block PARAMS ((PTR, bfd_vma));
3325 static boolean ieee_end_function PARAMS ((PTR));
3326 static boolean ieee_lineno
3327 PARAMS ((PTR, const char *, unsigned long, bfd_vma));
3329 static const struct debug_write_fns ieee_fns =
3331 ieee_start_compilation_unit,
3342 ieee_reference_type,
3350 ieee_start_struct_type,
3352 ieee_end_struct_type,
3353 ieee_start_class_type,
3354 ieee_class_static_member,
3355 ieee_class_baseclass,
3356 ieee_class_start_method,
3357 ieee_class_method_variant,
3358 ieee_class_static_method_variant,
3359 ieee_class_end_method,
3360 ieee_end_class_type,
3366 ieee_float_constant,
3367 ieee_typed_constant,
3369 ieee_start_function,
3370 ieee_function_parameter,
3377 /* Change the current buffer to a specified buffer chain. */
3380 ieee_change_buffer (info, ppbuf)
3381 struct ieee_handle *info;
3382 struct ieee_buf **ppbuf;
3384 struct ieee_buf *buf;
3388 for (buf = *ppbuf; buf->next != NULL; buf = buf->next)
3393 buf = (struct ieee_buf *) xmalloc (sizeof *buf);
3399 info->current = buf;
3403 /* Push a type index onto the type stack. */
3406 ieee_push_type (info, indx, size, unsignedp)
3407 struct ieee_handle *info;
3412 struct ieee_type_stack *ts;
3414 ts = (struct ieee_type_stack *) xmalloc (sizeof *ts);
3415 memset (ts, 0, sizeof *ts);
3417 ts->type.indx = indx;
3418 ts->type.size = size;
3419 ts->type.unsignedp = unsignedp;
3421 ts->next = info->type_stack;
3422 info->type_stack = ts;
3427 /* Pop a type index off the type stack. */
3430 ieee_pop_type (info)
3431 struct ieee_handle *info;
3433 struct ieee_type_stack *ts;
3436 ts = info->type_stack;
3437 assert (ts != NULL);
3438 ret = ts->type.indx;
3439 info->type_stack = ts->next;
3444 /* Add a range of bytes included in the current compilation unit. */
3447 ieee_add_range (info, low, high)
3448 struct ieee_handle *info;
3452 struct ieee_range *r, **pr;
3454 if (low == (bfd_vma) -1 || high == (bfd_vma) -1)
3457 for (r = info->ranges; r != NULL; r = r->next)
3459 if (high >= r->low && low <= r->high)
3461 /* The new range overlaps r. */
3467 while (*pr != NULL && (*pr)->low <= r->high)
3469 struct ieee_range *n;
3471 if ((*pr)->high > r->high)
3472 r->high = (*pr)->high;
3481 r = (struct ieee_range *) xmalloc (sizeof *r);
3482 memset (r, 0, sizeof *r);
3487 /* Store the ranges sorted by address. */
3488 for (pr = &info->ranges; *pr != NULL; pr = &(*pr)->next)
3489 if ((*pr)->next != NULL && (*pr)->next->low > high)
3497 /* Start a new range for which we only have the low address. */
3500 ieee_start_range (info, low)
3501 struct ieee_handle *info;
3504 struct ieee_range *r;
3506 r = (struct ieee_range *) xmalloc (sizeof *r);
3507 memset (r, 0, sizeof *r);
3509 r->next = info->pending_ranges;
3510 info->pending_ranges = r;
3514 /* Finish a range started by ieee_start_range. */
3517 ieee_end_range (info, high)
3518 struct ieee_handle *info;
3521 struct ieee_range *r;
3524 assert (info->pending_ranges != NULL);
3525 r = info->pending_ranges;
3527 info->pending_ranges = r->next;
3529 return ieee_add_range (info, low, high);
3532 /* Write a byte into the buffer. We use a macro for speed and a
3533 function for the complex cases. */
3535 #define ieee_write_byte(info, b) \
3536 ((info)->current->c < IEEE_BUFSIZE \
3537 ? ((info)->current->buf[(info)->current->c++] = (b), true) \
3538 : ieee_real_write_byte ((info), (b)))
3541 ieee_real_write_byte (info, b)
3542 struct ieee_handle *info;
3545 if (info->current->c >= IEEE_BUFSIZE)
3549 n = (struct ieee_buf *) xmalloc (sizeof *n);
3552 info->current->next = n;
3556 info->current->buf[info->current->c] = b;
3562 /* Write out two bytes. */
3565 ieee_write_2bytes (info, i)
3566 struct ieee_handle *info;
3569 return (ieee_write_byte (info, i >> 8)
3570 && ieee_write_byte (info, i & 0xff));
3573 /* Write out an integer. */
3576 ieee_write_number (info, v)
3577 struct ieee_handle *info;
3585 if (v <= (bfd_vma) ieee_number_end_enum)
3586 return ieee_write_byte (info, (int) v);
3597 if (c > (unsigned int) (ieee_number_repeat_end_enum
3598 - ieee_number_repeat_start_enum))
3600 fprintf (stderr, "IEEE numeric overflow: 0x");
3601 fprintf_vma (stderr, v);
3602 fprintf (stderr, "\n");
3606 if (! ieee_write_byte (info, (int) ieee_number_repeat_start_enum + c))
3608 for (; c > 0; --c, ++p)
3610 if (! ieee_write_byte (info, *p))
3617 /* Write out a string. */
3620 ieee_write_id (info, s)
3621 struct ieee_handle *info;
3629 if (! ieee_write_byte (info, len))
3632 else if (len <= 0xff)
3634 if (! ieee_write_byte (info, (int) ieee_extension_length_1_enum)
3635 || ! ieee_write_byte (info, len))
3638 else if (len <= 0xffff)
3640 if (! ieee_write_byte (info, (int) ieee_extension_length_2_enum)
3641 || ! ieee_write_2bytes (info, len))
3646 fprintf (stderr, "IEEE string length overflow: %u\n", len);
3650 for (; *s != '\0'; s++)
3651 if (! ieee_write_byte (info, *s))
3657 /* Start defining a type. */
3660 ieee_define_type (info, size, unsignedp)
3661 struct ieee_handle *info;
3665 return ieee_define_named_type (info, (const char *) NULL, false, size,
3666 unsignedp, (struct ieee_buf **) NULL);
3669 /* Start defining a named type. */
3672 ieee_define_named_type (info, name, tagp, size, unsignedp, ppbuf)
3673 struct ieee_handle *info;
3678 struct ieee_buf **ppbuf;
3680 unsigned int type_indx;
3681 unsigned int name_indx;
3683 if (! tagp || name == NULL || *name == '\0')
3685 type_indx = info->type_indx;
3690 struct ieee_name_type *nt;
3692 /* The name is a tag. If we have already defined the tag, we
3693 must use the existing type index. */
3694 for (nt = info->tags; nt != NULL; nt = nt->next)
3695 if (nt->name[0] == name[0]
3696 && strcmp (nt->name, name) == 0)
3701 nt = (struct ieee_name_type *) xmalloc (sizeof *nt);
3702 memset (nt, 0, sizeof *nt);
3704 nt->next = info->tags;
3706 nt->type.indx = info->type_indx;
3710 nt->type.size = size;
3711 nt->type.unsignedp = unsignedp;
3712 nt->kind = DEBUG_KIND_ILLEGAL;
3714 type_indx = nt->type.indx;
3717 name_indx = info->name_indx;
3723 /* If we were given a buffer, use it; otherwise, use the general
3724 type information, and make sure that the type block is started. */
3727 if (! ieee_change_buffer (info, ppbuf))
3730 else if (info->types != NULL)
3732 if (! ieee_change_buffer (info, &info->types))
3737 if (! ieee_change_buffer (info, &info->types)
3738 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
3739 || ! ieee_write_byte (info, 1)
3740 || ! ieee_write_number (info, 0)
3741 || ! ieee_write_id (info, info->modname))
3745 /* Push the new type on the type stack, write out an NN record, and
3746 write out the start of a TY record. The caller will then finish
3748 return (ieee_push_type (info, type_indx, size, unsignedp)
3749 && ieee_write_byte (info, (int) ieee_nn_record)
3750 && ieee_write_number (info, name_indx)
3751 && ieee_write_id (info, name)
3752 && ieee_write_byte (info, (int) ieee_ty_record_enum)
3753 && ieee_write_number (info, type_indx)
3754 && ieee_write_byte (info, 0xce)
3755 && ieee_write_number (info, name_indx));
3758 /* The general routine to write out IEEE debugging information. */
3761 write_ieee_debugging_info (abfd, dhandle)
3765 struct ieee_handle info;
3766 struct ieee_buf *tags;
3767 struct ieee_name_type *nt;
3772 memset (&info, 0, sizeof info);
3774 info.type_indx = 256;
3775 info.name_indx = 32;
3777 if (! debug_write (dhandle, &ieee_fns, (PTR) &info))
3780 if (info.filename != NULL)
3782 if (! ieee_finish_compilation_unit (&info))
3786 /* Put any undefined tags in the global typedef information. */
3788 for (nt = info.tags; nt != NULL; nt = nt->next)
3790 unsigned int name_indx;
3793 if (nt->kind == DEBUG_KIND_ILLEGAL)
3797 if (! ieee_change_buffer (&info, &tags)
3798 || ! ieee_write_byte (&info, (int) ieee_bb_record_enum)
3799 || ! ieee_write_byte (&info, 2)
3800 || ! ieee_write_number (&info, 0)
3801 || ! ieee_write_id (&info, ""))
3804 name_indx = info.name_indx;
3806 if (! ieee_write_byte (&info, (int) ieee_nn_record)
3807 || ! ieee_write_number (&info, name_indx)
3808 || ! ieee_write_id (&info, nt->name)
3809 || ! ieee_write_byte (&info, (int) ieee_ty_record_enum)
3810 || ! ieee_write_number (&info, nt->type.indx)
3811 || ! ieee_write_byte (&info, 0xce)
3812 || ! ieee_write_number (&info, name_indx))
3819 case DEBUG_KIND_STRUCT:
3820 case DEBUG_KIND_CLASS:
3823 case DEBUG_KIND_UNION:
3824 case DEBUG_KIND_UNION_CLASS:
3827 case DEBUG_KIND_ENUM:
3831 if (! ieee_write_number (&info, code)
3832 || ! ieee_write_number (&info, 0))
3837 struct ieee_buf **pb;
3839 if (! ieee_write_byte (&info, (int) ieee_be_record_enum))
3842 for (pb = &tags; *pb != NULL; pb = &(*pb)->next)
3848 /* Now all the data is in info.data. Write it out to the BFD. We
3849 normally would need to worry about whether all the other sections
3850 are set up yet, but the IEEE backend will handle this particular
3851 case correctly regardless. */
3852 if (info.data == NULL)
3854 /* There is no debugging information. */
3858 s = bfd_make_section (abfd, ".debug");
3860 err = "bfd_make_section";
3863 if (! bfd_set_section_flags (abfd, s, SEC_DEBUGGING | SEC_HAS_CONTENTS))
3864 err = "bfd_set_section_flags";
3871 for (b = info.data; b != NULL; b = b->next)
3873 if (! bfd_set_section_size (abfd, s, size))
3874 err = "bfd_set_section_size";
3881 for (b = info.data; b != NULL; b = b->next)
3883 if (! bfd_set_section_contents (abfd, s, b->buf, offset, b->c))
3885 err = "bfd_set_section_contents";
3894 fprintf (stderr, "%s: %s: %s\n", bfd_get_filename (abfd), err,
3895 bfd_errmsg (bfd_get_error ()));
3902 /* Start writing out information for a compilation unit. */
3905 ieee_start_compilation_unit (p, filename)
3907 const char *filename;
3909 struct ieee_handle *info = (struct ieee_handle *) p;
3910 const char *modname;
3913 if (info->filename != NULL)
3915 if (! ieee_finish_compilation_unit (info))
3919 info->filename = filename;
3920 modname = strrchr (filename, '/');
3921 if (modname != NULL)
3925 modname = strrchr (filename, '\\');
3926 if (modname != NULL)
3931 c = xstrdup (modname);
3932 s = strrchr (c, '.');
3939 info->linenos = NULL;
3940 info->ranges = NULL;
3945 /* Finish up a compilation unit. */
3948 ieee_finish_compilation_unit (info)
3949 struct ieee_handle *info;
3951 struct ieee_buf **pp;
3952 struct ieee_range *r;
3954 if (info->types != NULL)
3956 if (! ieee_change_buffer (info, &info->types)
3957 || ! ieee_write_byte (info, (int) ieee_be_record_enum))
3961 if (info->vars != NULL)
3963 if (! ieee_change_buffer (info, &info->vars)
3964 || ! ieee_write_byte (info, (int) ieee_be_record_enum))
3968 if (info->linenos != NULL)
3970 if (! ieee_change_buffer (info, &info->linenos)
3971 || ! ieee_write_byte (info, (int) ieee_be_record_enum))
3975 for (pp = &info->data; *pp != NULL; pp = &(*pp)->next)
3978 for (; *pp != NULL; pp = &(*pp)->next)
3981 for (; *pp != NULL; pp = &(*pp)->next)
3983 *pp = info->linenos;
3985 /* Build BB10/BB11 blocks based on the ranges we recorded. */
3986 if (! ieee_change_buffer (info, &info->data))
3989 if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
3990 || ! ieee_write_byte (info, 10)
3991 || ! ieee_write_number (info, 0)
3992 || ! ieee_write_id (info, info->modname)
3993 || ! ieee_write_id (info, "")
3994 || ! ieee_write_number (info, 0)
3995 || ! ieee_write_id (info, "GNU objcopy"))
3998 for (r = info->ranges; r != NULL; r = r->next)
4007 /* Find the section corresponding to this range. */
4008 for (s = info->abfd->sections; s != NULL; s = s->next)
4010 if (bfd_get_section_vma (info->abfd, s) <= low
4011 && high <= (bfd_get_section_vma (info->abfd, s)
4012 + bfd_section_size (info->abfd, s)))
4018 /* Just ignore this range. */
4022 /* Coalesce ranges if it seems reasonable. */
4023 while (r->next != NULL
4024 && high + 64 >= r->next->low
4026 <= (bfd_get_section_vma (info->abfd, s)
4027 + bfd_section_size (info->abfd, s))))
4030 high = r->next->high;
4033 if ((s->flags & SEC_CODE) != 0)
4035 else if ((s->flags & SEC_READONLY) != 0)
4040 if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
4041 || ! ieee_write_byte (info, 11)
4042 || ! ieee_write_number (info, 0)
4043 || ! ieee_write_id (info, "")
4044 || ! ieee_write_number (info, kind)
4045 || ! ieee_write_number (info, s->index)
4046 || ! ieee_write_number (info, low)
4047 || ! ieee_write_byte (info, (int) ieee_be_record_enum)
4048 || ! ieee_write_number (info, high - low))
4052 if (! ieee_write_byte (info, (int) ieee_be_record_enum))
4058 /* Start recording information from a particular source file. This is
4059 used to record which file defined which types, variables, etc. It
4060 is not used for line numbers, since the lineno entry point passes
4061 down the file name anyhow. IEEE debugging information doesn't seem
4062 to store this information anywhere. */
4066 ieee_start_source (p, filename)
4068 const char *filename;
4073 /* Make an empty type. */
4079 struct ieee_handle *info = (struct ieee_handle *) p;
4081 return ieee_push_type (info, 0, 0, false);
4084 /* Make a void type. */
4090 struct ieee_handle *info = (struct ieee_handle *) p;
4092 return ieee_push_type (info, 1, 0, false);
4095 /* Make an integer type. */
4098 ieee_int_type (p, size, unsignedp)
4103 struct ieee_handle *info = (struct ieee_handle *) p;
4109 indx = (int) builtin_signed_char;
4112 indx = (int) builtin_signed_short_int;
4115 indx = (int) builtin_signed_long;
4118 indx = (int) builtin_signed_long_long;
4121 fprintf (stderr, "IEEE unsupported integer type size %u\n", size);
4128 return ieee_push_type (info, indx, size, unsignedp);
4131 /* Make a floating point type. */
4134 ieee_float_type (p, size)
4138 struct ieee_handle *info = (struct ieee_handle *) p;
4144 indx = (int) builtin_float;
4147 indx = (int) builtin_double;
4150 /* FIXME: This size really depends upon the processor. */
4151 indx = (int) builtin_long_double;
4154 indx = (int) builtin_long_long_double;
4157 fprintf (stderr, "IEEE unsupported float type size %u\n", size);
4161 return ieee_push_type (info, indx, size, false);
4164 /* Make a complex type. */
4167 ieee_complex_type (p, size)
4171 struct ieee_handle *info = (struct ieee_handle *) p;
4183 fprintf (stderr, "IEEE unsupported complex type size %u\n", size);
4187 /* FIXME: I don't know what the string is for. */
4188 return (ieee_define_type (info, size, false)
4189 && ieee_write_number (info, code)
4190 && ieee_write_id (info, ""));
4193 /* Make a boolean type. IEEE doesn't support these, so we just make
4194 an integer type instead. */
4197 ieee_bool_type (p, size)
4201 return ieee_int_type (p, size, true);
4204 /* Make an enumeration. */
4207 ieee_enum_type (p, tag, names, vals)
4211 bfd_signed_vma *vals;
4213 struct ieee_handle *info = (struct ieee_handle *) p;
4217 /* If this is a simple enumeration, in which the values start at 0
4218 and always increment by 1, we can use type E. Otherwise we must
4224 for (i = 0; names[i] != NULL; i++)
4234 if (! ieee_define_named_type (info, tag, true, 0, true,
4235 (struct ieee_buf **) NULL)
4236 || ! ieee_write_number (info, simple ? 'E' : 'N'))
4240 /* FIXME: This is supposed to be the enumeration size, but we
4241 don't store that. */
4242 if (! ieee_write_number (info, 4))
4247 for (i = 0; names[i] != NULL; i++)
4249 if (! ieee_write_id (info, names[i]))
4253 if (! ieee_write_number (info, vals[i]))
4262 /* Make a pointer type. */
4265 ieee_pointer_type (p)
4268 struct ieee_handle *info = (struct ieee_handle *) p;
4271 indx = ieee_pop_type (info);
4273 /* A pointer to a simple builtin type can be obtained by adding 32. */
4275 return ieee_push_type (info, indx + 32, 0, true);
4277 return (ieee_define_type (info, 0, true)
4278 && ieee_write_number (info, 'P')
4279 && ieee_write_number (info, indx));
4282 /* Make a function type. */
4285 ieee_function_type (p, argcount, varargs)
4290 struct ieee_handle *info = (struct ieee_handle *) p;
4291 unsigned int *args = NULL;
4293 unsigned int retindx;
4297 args = (unsigned int *) xmalloc (argcount * sizeof *args);
4298 for (i = argcount - 1; i >= 0; i--)
4299 args[i] = ieee_pop_type (info);
4301 else if (argcount < 0)
4304 retindx = ieee_pop_type (info);
4306 /* An attribute of 0x41 means that the frame and push mask are
4308 if (! ieee_define_type (info, 0, true)
4309 || ! ieee_write_number (info, 'x')
4310 || ! ieee_write_number (info, 0x41)
4311 || ! ieee_write_number (info, 0)
4312 || ! ieee_write_number (info, 0)
4313 || ! ieee_write_number (info, retindx)
4314 || ! ieee_write_number (info, (bfd_vma) argcount + (varargs ? 1 : 0)))
4318 for (i = 0; i < argcount; i++)
4319 if (! ieee_write_number (info, args[i]))
4325 /* A varargs function is represented by writing out the last
4326 argument as type void *, although this makes little sense. */
4327 if (! ieee_write_number (info, (bfd_vma) builtin_void + 32))
4331 return ieee_write_number (info, 0);
4334 /* Make a reference type. */
4337 ieee_reference_type (p)
4340 struct ieee_handle *info = (struct ieee_handle *) p;
4342 /* IEEE appears to record a normal pointer type, and then use a
4343 pmisc record to indicate that it is really a reference. */
4345 if (! ieee_pointer_type (p))
4347 info->type_stack->type.referencep = true;
4351 /* Make a range type. */
4354 ieee_range_type (p, low, high)
4357 bfd_signed_vma high;
4359 struct ieee_handle *info = (struct ieee_handle *) p;
4363 size = info->type_stack->type.size;
4364 unsignedp = info->type_stack->type.unsignedp;
4365 (void) ieee_pop_type (info);
4366 return (ieee_define_type (info, size, unsignedp)
4367 && ieee_write_number (info, 'R')
4368 && ieee_write_number (info, (bfd_vma) low)
4369 && ieee_write_number (info, (bfd_vma) high)
4370 && ieee_write_number (info, unsignedp ? 0 : 1)
4371 && ieee_write_number (info, size));
4374 /* Make an array type. */
4378 ieee_array_type (p, low, high, stringp)
4381 bfd_signed_vma high;
4384 struct ieee_handle *info = (struct ieee_handle *) p;
4385 unsigned int eleindx;
4387 /* IEEE does not store the range, so we just ignore it. */
4388 (void) ieee_pop_type (info);
4389 eleindx = ieee_pop_type (info);
4391 if (! ieee_define_type (info, 0, false)
4392 || ! ieee_write_number (info, low == 0 ? 'Z' : 'C')
4393 || ! ieee_write_number (info, eleindx))
4397 if (! ieee_write_number (info, low))
4401 return ieee_write_number (info, high);
4404 /* Make a set type. */
4407 ieee_set_type (p, bitstringp)
4411 struct ieee_handle *info = (struct ieee_handle *) p;
4412 unsigned int eleindx;
4414 eleindx = ieee_pop_type (info);
4416 /* FIXME: We don't know the size, so we just use 4. */
4418 return (ieee_define_type (info, 0, true)
4419 && ieee_write_number (info, 's')
4420 && ieee_write_number (info, 4)
4421 && ieee_write_number (info, eleindx));
4424 /* Make an offset type. */
4427 ieee_offset_type (p)
4430 struct ieee_handle *info = (struct ieee_handle *) p;
4431 unsigned int targetindx, baseindx;
4433 targetindx = ieee_pop_type (info);
4434 baseindx = ieee_pop_type (info);
4436 /* FIXME: The MRI C++ compiler does not appear to generate any
4437 useful type information about an offset type. It just records a
4438 pointer to member as an integer. The MRI/HP IEEE spec does
4439 describe a pmisc record which can be used for a pointer to
4440 member. Unfortunately, it does not describe the target type,
4441 which seems pretty important. I'm going to punt this for now. */
4443 return ieee_int_type (p, 4, true);
4446 /* Make a method type. */
4449 ieee_method_type (p, domain, argcount, varargs)
4455 struct ieee_handle *info = (struct ieee_handle *) p;
4457 /* FIXME: The MRI/HP IEEE spec defines a pmisc record to use for a
4458 method, but the definition is incomplete. We just output an 'x'
4462 (void) ieee_pop_type (info);
4464 return ieee_function_type (p, argcount, varargs);
4467 /* Make a const qualified type. */
4473 struct ieee_handle *info = (struct ieee_handle *) p;
4478 size = info->type_stack->type.size;
4479 unsignedp = info->type_stack->type.unsignedp;
4480 indx = ieee_pop_type (info);
4481 return (ieee_define_type (info, size, unsignedp)
4482 && ieee_write_number (info, 'n')
4483 && ieee_write_number (info, 1)
4484 && ieee_write_number (info, indx));
4487 /* Make a volatile qualified type. */
4490 ieee_volatile_type (p)
4493 struct ieee_handle *info = (struct ieee_handle *) p;
4498 size = info->type_stack->type.size;
4499 unsignedp = info->type_stack->type.unsignedp;
4500 indx = ieee_pop_type (info);
4501 return (ieee_define_type (info, size, unsignedp)
4502 && ieee_write_number (info, 'n')
4503 && ieee_write_number (info, 2)
4504 && ieee_write_number (info, indx));
4507 /* Start defining a struct type. We build it in the strdef field on
4508 the stack, to avoid confusing type definitions required by the
4509 fields with the struct type itself. */
4512 ieee_start_struct_type (p, tag, id, structp, size)
4519 struct ieee_handle *info = (struct ieee_handle *) p;
4520 struct ieee_buf *strdef;
4523 if (! ieee_define_named_type (info, tag, true, size, true, &strdef)
4524 || ! ieee_write_number (info, structp ? 'S' : 'U')
4525 || ! ieee_write_number (info, size))
4528 info->type_stack->type.strdef = strdef;
4533 /* Add a field to a struct. */
4536 ieee_struct_field (p, name, bitpos, bitsize, visibility)
4541 enum debug_visibility visibility;
4543 struct ieee_handle *info = (struct ieee_handle *) p;
4549 size = info->type_stack->type.size;
4550 unsignedp = info->type_stack->type.unsignedp;
4551 indx = ieee_pop_type (info);
4553 assert (info->type_stack != NULL && info->type_stack->type.strdef != NULL);
4555 /* If the bitsize doesn't match the expected size, we need to output
4557 if (size == 0 || bitsize == size * 8)
4558 offset = bitpos / 8;
4561 if (! ieee_define_type (info, 0, unsignedp)
4562 || ! ieee_write_number (info, 'g')
4563 || ! ieee_write_number (info, unsignedp ? 0 : 1)
4564 || ! ieee_write_number (info, indx))
4566 indx = ieee_pop_type (info);
4570 /* Switch to the struct we are building in order to output this
4571 field definition. */
4572 return (ieee_change_buffer (info, &info->type_stack->type.strdef)
4573 && ieee_write_id (info, name)
4574 && ieee_write_number (info, indx)
4575 && ieee_write_number (info, offset));
4578 /* Finish up a struct type. */
4581 ieee_end_struct_type (p)
4584 struct ieee_handle *info = (struct ieee_handle *) p;
4585 struct ieee_buf **pb;
4587 assert (info->type_stack != NULL && info->type_stack->type.strdef != NULL);
4589 /* Make sure we have started the types block. */
4590 if (info->types == NULL)
4592 if (! ieee_change_buffer (info, &info->types)
4593 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
4594 || ! ieee_write_byte (info, 1)
4595 || ! ieee_write_number (info, 0)
4596 || ! ieee_write_id (info, info->modname))
4600 /* Append the struct definition to the types. */
4601 for (pb = &info->types; *pb != NULL; pb = &(*pb)->next)
4603 *pb = info->type_stack->type.strdef;
4604 info->type_stack->type.strdef = NULL;
4606 /* Leave the struct on the type stack. */
4611 /* Start a class type. */
4614 ieee_start_class_type (p, tag, id, structp, size, vptr, ownvptr)
4623 struct ieee_handle *info = (struct ieee_handle *) p;
4626 if (vptr && ! ownvptr)
4627 (void) ieee_pop_type (info);
4628 return ieee_start_struct_type (p, tag, id, structp, size);
4631 /* Add a static member to a class. */
4634 ieee_class_static_member (p, name, physname, visibility)
4637 const char *physname;
4638 enum debug_visibility visibility;
4640 struct ieee_handle *info = (struct ieee_handle *) p;
4643 (void) ieee_pop_type (info);
4647 /* Add a base class to a class. */
4650 ieee_class_baseclass (p, bitpos, virtual, visibility)
4654 enum debug_visibility visibility;
4656 struct ieee_handle *info = (struct ieee_handle *) p;
4659 (void) ieee_pop_type (info);
4663 /* Start building a method for a class. */
4666 ieee_class_start_method (p, name)
4674 /* Define a new method variant. */
4677 ieee_class_method_variant (p, physname, visibility, constp, volatilep,
4680 const char *physname;
4681 enum debug_visibility visibility;
4687 struct ieee_handle *info = (struct ieee_handle *) p;
4690 (void) ieee_pop_type (info);
4692 (void) ieee_pop_type (info);
4696 /* Define a new static method variant. */
4699 ieee_class_static_method_variant (p, physname, visibility, constp, volatilep)
4701 const char *physname;
4702 enum debug_visibility visibility;
4706 struct ieee_handle *info = (struct ieee_handle *) p;
4709 (void) ieee_pop_type (info);
4713 /* Finish up a method. */
4716 ieee_class_end_method (p)
4723 /* Finish up a class. */
4726 ieee_end_class_type (p)
4729 return ieee_end_struct_type (p);
4732 /* Push a previously seen typedef onto the type stack. */
4735 ieee_typedef_type (p, name)
4739 struct ieee_handle *info = (struct ieee_handle *) p;
4740 register struct ieee_name_type *nt;
4742 for (nt = info->typedefs; nt != NULL; nt = nt->next)
4744 if (nt->name[0] == name[0]
4745 && strcmp (nt->name, name) == 0)
4747 if (! ieee_push_type (info, nt->type.indx, nt->type.size,
4748 nt->type.unsignedp))
4750 /* Copy over any other type information we may have. */
4751 info->type_stack->type = nt->type;
4759 /* Push a tagged type onto the type stack. */
4762 ieee_tag_type (p, name, id, kind)
4766 enum debug_type_kind kind;
4768 struct ieee_handle *info = (struct ieee_handle *) p;
4769 register struct ieee_name_type *nt;
4774 for (nt = info->tags; nt != NULL; nt = nt->next)
4776 if (nt->name[0] == name[0]
4777 && strcmp (nt->name, name) == 0)
4779 if (! ieee_push_type (info, nt->type.indx, nt->type.size,
4780 nt->type.unsignedp))
4782 /* Copy over any other type information we may have. */
4783 info->type_stack->type = nt->type;
4788 nt = (struct ieee_name_type *) xmalloc (sizeof *nt);
4789 memset (nt, 0, sizeof *nt);
4792 nt->type.indx = info->type_indx;
4796 nt->next = info->tags;
4799 return ieee_push_type (info, nt->type.indx, 0, false);
4802 /* Output a typedef. */
4805 ieee_typdef (p, name)
4809 struct ieee_handle *info = (struct ieee_handle *) p;
4810 struct ieee_name_type *nt;
4815 nt = (struct ieee_name_type *) xmalloc (sizeof *nt);
4816 memset (nt, 0, sizeof *nt);
4818 nt->type = info->type_stack->type;
4819 nt->kind = DEBUG_KIND_ILLEGAL;
4821 nt->next = info->typedefs;
4822 info->typedefs = nt;
4824 size = info->type_stack->type.size;
4825 unsignedp = info->type_stack->type.unsignedp;
4826 indx = ieee_pop_type (info);
4828 /* If this is a simple builtin type using a builtin name, we don't
4829 want to output the typedef itself. We also want to change the
4830 type index to correspond to the name being used. We recognize
4831 names used in stabs debugging output even if they don't exactly
4832 correspond to the names used for the IEEE builtin types. */
4833 if (indx <= (unsigned int) builtin_bcd_float)
4838 switch ((enum builtin_types) indx)
4844 if (strcmp (name, "void") == 0)
4848 case builtin_signed_char:
4850 if (strcmp (name, "signed char") == 0)
4852 indx = (unsigned int) builtin_signed_char;
4855 else if (strcmp (name, "char") == 0)
4857 indx = (unsigned int) builtin_char;
4862 case builtin_unsigned_char:
4863 if (strcmp (name, "unsigned char") == 0)
4867 case builtin_signed_short_int:
4869 case builtin_short_int:
4870 case builtin_signed_short:
4871 if (strcmp (name, "signed short int") == 0)
4873 indx = (unsigned int) builtin_signed_short_int;
4876 else if (strcmp (name, "short") == 0)
4878 indx = (unsigned int) builtin_short;
4881 else if (strcmp (name, "short int") == 0)
4883 indx = (unsigned int) builtin_short_int;
4886 else if (strcmp (name, "signed short") == 0)
4888 indx = (unsigned int) builtin_signed_short;
4893 case builtin_unsigned_short_int:
4894 case builtin_unsigned_short:
4895 if (strcmp (name, "unsigned short int") == 0
4896 || strcmp (name, "short unsigned int") == 0)
4898 indx = builtin_unsigned_short_int;
4901 else if (strcmp (name, "unsigned short") == 0)
4903 indx = builtin_unsigned_short;
4908 case builtin_signed_long:
4909 case builtin_int: /* FIXME: Size depends upon architecture. */
4911 if (strcmp (name, "signed long") == 0)
4913 indx = builtin_signed_long;
4916 else if (strcmp (name, "int") == 0)
4921 else if (strcmp (name, "long") == 0
4922 || strcmp (name, "long int") == 0)
4924 indx = builtin_long;
4929 case builtin_unsigned_long:
4930 case builtin_unsigned: /* FIXME: Size depends upon architecture. */
4931 case builtin_unsigned_int: /* FIXME: Like builtin_unsigned. */
4932 if (strcmp (name, "unsigned long") == 0
4933 || strcmp (name, "long unsigned int") == 0)
4935 indx = builtin_unsigned_long;
4938 else if (strcmp (name, "unsigned") == 0)
4940 indx = builtin_unsigned;
4943 else if (strcmp (name, "unsigned int") == 0)
4945 indx = builtin_unsigned_int;
4950 case builtin_signed_long_long:
4951 if (strcmp (name, "signed long long") == 0
4952 || strcmp (name, "long long int") == 0)
4956 case builtin_unsigned_long_long:
4957 if (strcmp (name, "unsigned long long") == 0
4958 || strcmp (name, "long long unsigned int") == 0)
4963 if (strcmp (name, "float") == 0)
4967 case builtin_double:
4968 if (strcmp (name, "double") == 0)
4972 case builtin_long_double:
4973 if (strcmp (name, "long double") == 0)
4977 case builtin_long_long_double:
4978 if (strcmp (name, "long long double") == 0)
4985 nt->type.indx = indx;
4990 if (! ieee_define_named_type (info, name, false, size, unsignedp,
4991 (struct ieee_buf **) NULL)
4992 || ! ieee_write_number (info, 'T')
4993 || ! ieee_write_number (info, indx))
4996 /* Remove the type we just added to the type stack. */
4997 (void) ieee_pop_type (info);
5002 /* Output a tag for a type. We don't have to do anything here. */
5009 struct ieee_handle *info = (struct ieee_handle *) p;
5011 (void) ieee_pop_type (info);
5015 /* Output an integer constant. */
5018 ieee_int_constant (p, name, val)
5027 /* Output a floating point constant. */
5030 ieee_float_constant (p, name, val)
5039 /* Output a typed constant. */
5042 ieee_typed_constant (p, name, val)
5047 struct ieee_handle *info = (struct ieee_handle *) p;
5050 (void) ieee_pop_type (info);
5054 /* Output a variable. */
5057 ieee_variable (p, name, kind, val)
5060 enum debug_var_kind kind;
5063 struct ieee_handle *info = (struct ieee_handle *) p;
5064 unsigned int name_indx;
5066 unsigned int type_indx;
5069 /* Make sure the variable section is started. */
5070 if (info->vars != NULL)
5072 if (! ieee_change_buffer (info, &info->vars))
5077 if (! ieee_change_buffer (info, &info->vars)
5078 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
5079 || ! ieee_write_byte (info, 3)
5080 || ! ieee_write_number (info, 0)
5081 || ! ieee_write_id (info, info->modname))
5085 name_indx = info->name_indx;
5088 size = info->type_stack->type.size;
5089 type_indx = ieee_pop_type (info);
5091 /* Write out an NN and an ATN record for this variable. */
5092 if (! ieee_write_byte (info, (int) ieee_nn_record)
5093 || ! ieee_write_number (info, name_indx)
5094 || ! ieee_write_id (info, name)
5095 || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
5096 || ! ieee_write_number (info, name_indx)
5097 || ! ieee_write_number (info, type_indx))
5105 if (! ieee_write_number (info, 8)
5106 || ! ieee_add_range (info, val, val + size))
5111 case DEBUG_LOCAL_STATIC:
5112 if (! ieee_write_number (info, 3)
5113 || ! ieee_add_range (info, val, val + size))
5118 if (! ieee_write_number (info, 1)
5119 || ! ieee_write_number (info, val))
5123 case DEBUG_REGISTER:
5124 if (! ieee_write_number (info, 2)
5125 || ! ieee_write_number (info,
5126 ieee_genreg_to_regno (info->abfd, val)))
5134 if (! ieee_write_2bytes (info, (int) ieee_asn_record_enum)
5135 || ! ieee_write_number (info, name_indx)
5136 || ! ieee_write_number (info, val))
5143 /* Start outputting information for a function. */
5146 ieee_start_function (p, name, global)
5151 struct ieee_handle *info = (struct ieee_handle *) p;
5154 /* Make sure the variable section is started. */
5155 if (info->vars != NULL)
5157 if (! ieee_change_buffer (info, &info->vars))
5162 if (! ieee_change_buffer (info, &info->vars)
5163 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
5164 || ! ieee_write_byte (info, 3)
5165 || ! ieee_write_number (info, 0)
5166 || ! ieee_write_id (info, info->modname))
5170 indx = ieee_pop_type (info);
5172 /* The address is written out as the first block. */
5174 ++info->block_depth;
5176 return (ieee_write_byte (info, (int) ieee_bb_record_enum)
5177 && ieee_write_byte (info, global ? 4 : 6)
5178 && ieee_write_number (info, 0)
5179 && ieee_write_id (info, name)
5180 && ieee_write_number (info, 0)
5181 && ieee_write_number (info, indx));
5184 /* Add a function parameter. This will normally be called before the
5185 first block, so we postpone them until we see the block. */
5188 ieee_function_parameter (p, name, kind, val)
5191 enum debug_parm_kind kind;
5194 struct ieee_handle *info = (struct ieee_handle *) p;
5195 struct ieee_pending_parm *m, **pm;
5197 assert (info->block_depth == 1);
5199 m = (struct ieee_pending_parm *) xmalloc (sizeof *m);
5200 memset (m, 0, sizeof *m);
5204 m->type = ieee_pop_type (info);
5208 for (pm = &info->pending_parms; *pm != NULL; pm = &(*pm)->next)
5215 /* Output pending function parameters. */
5218 ieee_output_pending_parms (info)
5219 struct ieee_handle *info;
5221 struct ieee_pending_parm *m;
5223 m = info->pending_parms;
5226 struct ieee_pending_parm *next;
5227 enum debug_var_kind vkind;
5234 case DEBUG_PARM_STACK:
5235 case DEBUG_PARM_REFERENCE:
5236 vkind = DEBUG_LOCAL;
5238 case DEBUG_PARM_REG:
5239 case DEBUG_PARM_REF_REG:
5240 vkind = DEBUG_REGISTER;
5244 if (! ieee_push_type (info, m->type, 0, false)
5245 || ! ieee_variable ((PTR) info, m->name, vkind, m->val))
5248 /* FIXME: We should output a pmisc note here for reference
5255 info->pending_parms = NULL;
5260 /* Start a block. If this is the first block, we output the address
5261 to finish the BB4 or BB6, and then output the function parameters. */
5264 ieee_start_block (p, addr)
5268 struct ieee_handle *info = (struct ieee_handle *) p;
5270 if (! ieee_change_buffer (info, &info->vars))
5273 if (info->block_depth == 1)
5275 if (! ieee_write_number (info, addr)
5276 || ! ieee_output_pending_parms (info))
5281 if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
5282 || ! ieee_write_byte (info, 6)
5283 || ! ieee_write_byte (info, 0)
5284 || ! ieee_write_id (info, "")
5285 || ! ieee_write_number (info, 0)
5286 || ! ieee_write_number (info, 0)
5287 || ! ieee_write_number (info, addr))
5291 if (! ieee_start_range (info, addr))
5294 ++info->block_depth;
5302 ieee_end_block (p, addr)
5306 struct ieee_handle *info = (struct ieee_handle *) p;
5308 if (! ieee_change_buffer (info, &info->vars)
5309 || ! ieee_write_byte (info, (int) ieee_be_record_enum)
5310 || ! ieee_write_number (info, addr))
5313 if (! ieee_end_range (info, addr))
5316 --info->block_depth;
5321 /* End a function. */
5324 ieee_end_function (p)
5327 struct ieee_handle *info = (struct ieee_handle *) p;
5329 assert (info->block_depth == 1);
5331 --info->block_depth;
5336 /* Record line number information. */
5339 ieee_lineno (p, filename, lineno, addr)
5341 const char *filename;
5342 unsigned long lineno;
5345 struct ieee_handle *info = (struct ieee_handle *) p;
5347 assert (info->filename != NULL);
5349 /* Make sure we have a line number block. */
5350 if (info->linenos != NULL)
5352 if (! ieee_change_buffer (info, &info->linenos))
5357 info->lineno_name_indx = info->name_indx;
5359 if (! ieee_change_buffer (info, &info->linenos)
5360 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
5361 || ! ieee_write_byte (info, 5)
5362 || ! ieee_write_number (info, 0)
5363 || ! ieee_write_id (info, info->filename)
5364 || ! ieee_write_byte (info, (int) ieee_nn_record)
5365 || ! ieee_write_number (info, info->lineno_name_indx)
5366 || ! ieee_write_id (info, ""))
5368 info->lineno_filename = info->filename;
5371 if (strcmp (filename, info->lineno_filename) != 0)
5373 if (strcmp (info->filename, info->lineno_filename) != 0)
5375 /* We were not in the main file. Close the block for the
5377 if (! ieee_write_byte (info, (int) ieee_be_record_enum))
5380 if (strcmp (info->filename, filename) != 0)
5382 /* We are not changing to the main file. Open a block for
5383 the new included file. */
5384 if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
5385 || ! ieee_write_byte (info, 5)
5386 || ! ieee_write_number (info, 0)
5387 || ! ieee_write_id (info, filename))
5390 info->lineno_filename = filename;
5393 return (ieee_write_2bytes (info, (int) ieee_atn_record_enum)
5394 && ieee_write_number (info, info->lineno_name_indx)
5395 && ieee_write_number (info, 0)
5396 && ieee_write_number (info, 7)
5397 && ieee_write_number (info, lineno)
5398 && ieee_write_number (info, 0)
5399 && ieee_write_2bytes (info, (int) ieee_asn_record_enum)
5400 && ieee_write_number (info, info->lineno_name_indx)
5401 && ieee_write_number (info, addr));