1 /* ieee.c -- Read and write IEEE-695 debugging information.
2 Copyright 1996, 1998, 1999, 2000, 2001, 2002, 2003, 2006, 2007, 2008
3 Free Software Foundation, Inc.
4 Written by Ian Lance Taylor <ian@cygnus.com>.
6 This file is part of GNU Binutils.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
23 /* This file reads and writes IEEE-695 debugging information. */
29 #include "libiberty.h"
32 #include "filenames.h"
34 /* This structure holds an entry on the block stack. */
38 /* The kind of block. */
40 /* The source file name, for a BB5 block. */
42 /* The index of the function type, for a BB4 or BB6 block. */
44 /* TRUE if this function is being skipped. */
48 /* This structure is the block stack. */
50 #define BLOCKSTACK_SIZE (16)
52 struct ieee_blockstack
54 /* The stack pointer. */
55 struct ieee_block *bsp;
57 struct ieee_block stack[BLOCKSTACK_SIZE];
60 /* This structure holds information for a variable. */
70 /* Slot if we make an indirect type. */
72 /* Kind of variable or function. */
84 /* This structure holds all the variables. */
88 /* Number of slots allocated. */
91 struct ieee_var *vars;
94 /* This structure holds information for a type. We need this because
95 we don't want to represent bitfields as real types. */
101 /* Slot if this is type is referenced before it is defined. */
103 /* Slots for arguments if we make indirect types for them. */
104 debug_type *arg_slots;
105 /* If this is a bitfield, this is the size in bits. If this is not
106 a bitfield, this is zero. */
107 unsigned long bitsize;
110 /* This structure holds all the type information. */
114 /* Number of slots allocated. */
117 struct ieee_type *types;
119 #define BUILTIN_TYPE_COUNT (60)
120 debug_type builtins[BUILTIN_TYPE_COUNT];
123 /* This structure holds a linked last of structs with their tag names,
124 so that we can convert them to C++ classes if necessary. */
129 struct ieee_tag *next;
132 /* The type of the tag. */
134 /* The tagged type is an indirect type pointing at this slot. */
136 /* This is an array of slots used when a field type is converted
137 into a indirect type, in case it needs to be later converted into
142 /* This structure holds the information we pass around to the parsing
147 /* The debugging handle. */
151 /* The start of the bytes to be parsed. */
152 const bfd_byte *bytes;
153 /* The end of the bytes to be parsed. */
154 const bfd_byte *pend;
155 /* The block stack. */
156 struct ieee_blockstack blockstack;
157 /* Whether we have seen a BB1 or BB2. */
158 bfd_boolean saw_filename;
160 struct ieee_vars vars;
161 /* The global variables, after a global typedef block. */
162 struct ieee_vars *global_vars;
164 struct ieee_types types;
165 /* The global types, after a global typedef block. */
166 struct ieee_types *global_types;
167 /* The list of tagged structs. */
168 struct ieee_tag *tags;
171 /* Basic builtin types, not including the pointers. */
177 builtin_signed_char = 2,
178 builtin_unsigned_char = 3,
179 builtin_signed_short_int = 4,
180 builtin_unsigned_short_int = 5,
181 builtin_signed_long = 6,
182 builtin_unsigned_long = 7,
183 builtin_signed_long_long = 8,
184 builtin_unsigned_long_long = 9,
187 builtin_long_double = 12,
188 builtin_long_long_double = 13,
189 builtin_quoted_string = 14,
190 builtin_instruction_address = 15,
192 builtin_unsigned = 17,
193 builtin_unsigned_int = 18,
197 builtin_unsigned_short = 22,
198 builtin_short_int = 23,
199 builtin_signed_short = 24,
200 builtin_bcd_float = 25
203 /* These are the values found in the derivation flags of a 'b'
204 component record of a 'T' type extension record in a C++ pmisc
205 record. These are bitmasks. */
207 /* Set for a private base class, clear for a public base class.
208 Protected base classes are not supported. */
209 #define BASEFLAGS_PRIVATE (0x1)
210 /* Set for a virtual base class. */
211 #define BASEFLAGS_VIRTUAL (0x2)
212 /* Set for a friend class, clear for a base class. */
213 #define BASEFLAGS_FRIEND (0x10)
215 /* These are the values found in the specs flags of a 'd', 'm', or 'v'
216 component record of a 'T' type extension record in a C++ pmisc
217 record. The same flags are used for a 'M' record in a C++ pmisc
220 /* The lower two bits hold visibility information. */
221 #define CXXFLAGS_VISIBILITY (0x3)
222 /* This value in the lower two bits indicates a public member. */
223 #define CXXFLAGS_VISIBILITY_PUBLIC (0x0)
224 /* This value in the lower two bits indicates a private member. */
225 #define CXXFLAGS_VISIBILITY_PRIVATE (0x1)
226 /* This value in the lower two bits indicates a protected member. */
227 #define CXXFLAGS_VISIBILITY_PROTECTED (0x2)
228 /* Set for a static member. */
229 #define CXXFLAGS_STATIC (0x4)
230 /* Set for a virtual override. */
231 #define CXXFLAGS_OVERRIDE (0x8)
232 /* Set for a friend function. */
233 #define CXXFLAGS_FRIEND (0x10)
234 /* Set for a const function. */
235 #define CXXFLAGS_CONST (0x20)
236 /* Set for a volatile function. */
237 #define CXXFLAGS_VOLATILE (0x40)
238 /* Set for an overloaded function. */
239 #define CXXFLAGS_OVERLOADED (0x80)
240 /* Set for an operator function. */
241 #define CXXFLAGS_OPERATOR (0x100)
242 /* Set for a constructor or destructor. */
243 #define CXXFLAGS_CTORDTOR (0x400)
244 /* Set for a constructor. */
245 #define CXXFLAGS_CTOR (0x200)
246 /* Set for an inline function. */
247 #define CXXFLAGS_INLINE (0x800)
249 /* Local functions. */
251 static void ieee_error (struct ieee_info *, const bfd_byte *, const char *);
252 static void ieee_eof (struct ieee_info *);
253 static char *savestring (const char *, unsigned long);
254 static bfd_boolean ieee_read_number
255 (struct ieee_info *, const bfd_byte **, bfd_vma *);
256 static bfd_boolean ieee_read_optional_number
257 (struct ieee_info *, const bfd_byte **, bfd_vma *, bfd_boolean *);
258 static bfd_boolean ieee_read_id
259 (struct ieee_info *, const bfd_byte **, const char **, unsigned long *);
260 static bfd_boolean ieee_read_optional_id
261 (struct ieee_info *, const bfd_byte **, const char **, unsigned long *,
263 static bfd_boolean ieee_read_expression
264 (struct ieee_info *, const bfd_byte **, bfd_vma *);
265 static debug_type ieee_builtin_type
266 (struct ieee_info *, const bfd_byte *, unsigned int);
267 static bfd_boolean ieee_alloc_type
268 (struct ieee_info *, unsigned int, bfd_boolean);
269 static bfd_boolean ieee_read_type_index
270 (struct ieee_info *, const bfd_byte **, debug_type *);
271 static int ieee_regno_to_genreg (bfd *, int);
272 static int ieee_genreg_to_regno (bfd *, int);
273 static bfd_boolean parse_ieee_bb (struct ieee_info *, const bfd_byte **);
274 static bfd_boolean parse_ieee_be (struct ieee_info *, const bfd_byte **);
275 static bfd_boolean parse_ieee_nn (struct ieee_info *, const bfd_byte **);
276 static bfd_boolean parse_ieee_ty (struct ieee_info *, const bfd_byte **);
277 static bfd_boolean parse_ieee_atn (struct ieee_info *, const bfd_byte **);
278 static bfd_boolean ieee_read_cxx_misc
279 (struct ieee_info *, const bfd_byte **, unsigned long);
280 static bfd_boolean ieee_read_cxx_class
281 (struct ieee_info *, const bfd_byte **, unsigned long);
282 static bfd_boolean ieee_read_cxx_defaults
283 (struct ieee_info *, const bfd_byte **, unsigned long);
284 static bfd_boolean ieee_read_reference
285 (struct ieee_info *, const bfd_byte **);
286 static bfd_boolean ieee_require_asn
287 (struct ieee_info *, const bfd_byte **, bfd_vma *);
288 static bfd_boolean ieee_require_atn65
289 (struct ieee_info *, const bfd_byte **, const char **, unsigned long *);
291 /* Report an error in the IEEE debugging information. */
294 ieee_error (struct ieee_info *info, const bfd_byte *p, const char *s)
297 fprintf (stderr, "%s: 0x%lx: %s (0x%x)\n", bfd_get_filename (info->abfd),
298 (unsigned long) (p - info->bytes), s, *p);
300 fprintf (stderr, "%s: %s\n", bfd_get_filename (info->abfd), s);
303 /* Report an unexpected EOF in the IEEE debugging information. */
306 ieee_eof (struct ieee_info *info)
308 ieee_error (info, (const bfd_byte *) NULL,
309 _("unexpected end of debugging information"));
312 /* Save a string in memory. */
315 savestring (const char *start, unsigned long len)
319 ret = (char *) xmalloc (len + 1);
320 memcpy (ret, start, len);
325 /* Read a number which must be present in an IEEE file. */
328 ieee_read_number (struct ieee_info *info, const bfd_byte **pp, bfd_vma *pv)
330 return ieee_read_optional_number (info, pp, pv, (bfd_boolean *) NULL);
333 /* Read a number in an IEEE file. If ppresent is not NULL, the number
334 need not be there. */
337 ieee_read_optional_number (struct ieee_info *info, const bfd_byte **pp,
338 bfd_vma *pv, bfd_boolean *ppresent)
340 ieee_record_enum_type b;
342 if (*pp >= info->pend)
344 if (ppresent != NULL)
353 b = (ieee_record_enum_type) **pp;
356 if (b <= ieee_number_end_enum)
359 if (ppresent != NULL)
364 if (b >= ieee_number_repeat_start_enum && b <= ieee_number_repeat_end_enum)
368 i = (int) b - (int) ieee_number_repeat_start_enum;
369 if (*pp + i - 1 >= info->pend)
383 if (ppresent != NULL)
389 if (ppresent != NULL)
396 ieee_error (info, *pp - 1, _("invalid number"));
400 /* Read a required string from an IEEE file. */
403 ieee_read_id (struct ieee_info *info, const bfd_byte **pp,
404 const char **pname, unsigned long *pnamlen)
406 return ieee_read_optional_id (info, pp, pname, pnamlen, (bfd_boolean *) NULL);
409 /* Read a string from an IEEE file. If ppresent is not NULL, the
410 string is optional. */
413 ieee_read_optional_id (struct ieee_info *info, const bfd_byte **pp,
414 const char **pname, unsigned long *pnamlen,
415 bfd_boolean *ppresent)
420 if (*pp >= info->pend)
431 else if ((ieee_record_enum_type) b == ieee_extension_length_1_enum)
436 else if ((ieee_record_enum_type) b == ieee_extension_length_2_enum)
438 len = (**pp << 8) + (*pp)[1];
443 if (ppresent != NULL)
449 ieee_error (info, *pp - 1, _("invalid string length"));
453 if ((unsigned long) (info->pend - *pp) < len)
459 *pname = (const char *) *pp;
463 if (ppresent != NULL)
469 /* Read an expression from an IEEE file. Since this code is only used
470 to parse debugging information, I haven't bothered to write a full
471 blown IEEE expression parser. I've only thrown in the things I've
472 seen in debugging information. This can be easily extended if
476 ieee_read_expression (struct ieee_info *info, const bfd_byte **pp,
479 const bfd_byte *expr_start;
480 #define EXPR_STACK_SIZE (10)
481 bfd_vma expr_stack[EXPR_STACK_SIZE];
490 const bfd_byte *start;
493 ieee_record_enum_type c;
497 if (! ieee_read_optional_number (info, pp, &val, &present))
502 if (esp - expr_stack >= EXPR_STACK_SIZE)
504 ieee_error (info, start, _("expression stack overflow"));
511 c = (ieee_record_enum_type) **pp;
513 if (c >= ieee_module_beginning_enum)
524 ieee_error (info, start, _("unsupported IEEE expression operator"));
527 case ieee_variable_R_enum:
532 if (! ieee_read_number (info, pp, &indx))
534 for (s = info->abfd->sections; s != NULL; s = s->next)
535 if ((bfd_vma) s->target_index == indx)
539 ieee_error (info, start, _("unknown section"));
543 if (esp - expr_stack >= EXPR_STACK_SIZE)
545 ieee_error (info, start, _("expression stack overflow"));
549 *esp++ = bfd_get_section_vma (info->abfd, s);
553 case ieee_function_plus_enum:
554 case ieee_function_minus_enum:
558 if (esp - expr_stack < 2)
560 ieee_error (info, start, _("expression stack underflow"));
572 if (esp - 1 != expr_stack)
574 ieee_error (info, expr_start, _("expression stack mismatch"));
583 /* Return an IEEE builtin type. */
586 ieee_builtin_type (struct ieee_info *info, const bfd_byte *p,
593 if (indx < BUILTIN_TYPE_COUNT
594 && info->types.builtins[indx] != DEBUG_TYPE_NULL)
595 return info->types.builtins[indx];
597 dhandle = info->dhandle;
599 if (indx >= 32 && indx < 64)
601 type = debug_make_pointer_type (dhandle,
602 ieee_builtin_type (info, p, indx - 32));
603 assert (indx < BUILTIN_TYPE_COUNT);
604 info->types.builtins[indx] = type;
608 switch ((enum builtin_types) indx)
611 ieee_error (info, p, _("unknown builtin type"));
614 case builtin_unknown:
615 type = debug_make_void_type (dhandle);
620 type = debug_make_void_type (dhandle);
624 case builtin_signed_char:
625 type = debug_make_int_type (dhandle, 1, FALSE);
626 name = "signed char";
629 case builtin_unsigned_char:
630 type = debug_make_int_type (dhandle, 1, TRUE);
631 name = "unsigned char";
634 case builtin_signed_short_int:
635 type = debug_make_int_type (dhandle, 2, FALSE);
636 name = "signed short int";
639 case builtin_unsigned_short_int:
640 type = debug_make_int_type (dhandle, 2, TRUE);
641 name = "unsigned short int";
644 case builtin_signed_long:
645 type = debug_make_int_type (dhandle, 4, FALSE);
646 name = "signed long";
649 case builtin_unsigned_long:
650 type = debug_make_int_type (dhandle, 4, TRUE);
651 name = "unsigned long";
654 case builtin_signed_long_long:
655 type = debug_make_int_type (dhandle, 8, FALSE);
656 name = "signed long long";
659 case builtin_unsigned_long_long:
660 type = debug_make_int_type (dhandle, 8, TRUE);
661 name = "unsigned long long";
665 type = debug_make_float_type (dhandle, 4);
670 type = debug_make_float_type (dhandle, 8);
674 case builtin_long_double:
675 /* FIXME: The size for this type should depend upon the
677 type = debug_make_float_type (dhandle, 12);
678 name = "long double";
681 case builtin_long_long_double:
682 type = debug_make_float_type (dhandle, 16);
683 name = "long long double";
686 case builtin_quoted_string:
687 type = debug_make_array_type (dhandle,
688 ieee_builtin_type (info, p,
691 ieee_builtin_type (info, p,
695 name = "QUOTED STRING";
698 case builtin_instruction_address:
699 /* FIXME: This should be a code address. */
700 type = debug_make_int_type (dhandle, 4, TRUE);
701 name = "instruction address";
705 /* FIXME: The size for this type should depend upon the
707 type = debug_make_int_type (dhandle, 4, FALSE);
711 case builtin_unsigned:
712 /* FIXME: The size for this type should depend upon the
714 type = debug_make_int_type (dhandle, 4, TRUE);
718 case builtin_unsigned_int:
719 /* FIXME: The size for this type should depend upon the
721 type = debug_make_int_type (dhandle, 4, TRUE);
722 name = "unsigned int";
726 type = debug_make_int_type (dhandle, 1, FALSE);
731 type = debug_make_int_type (dhandle, 4, FALSE);
736 type = debug_make_int_type (dhandle, 2, FALSE);
740 case builtin_unsigned_short:
741 type = debug_make_int_type (dhandle, 2, TRUE);
742 name = "unsigned short";
745 case builtin_short_int:
746 type = debug_make_int_type (dhandle, 2, FALSE);
750 case builtin_signed_short:
751 type = debug_make_int_type (dhandle, 2, FALSE);
752 name = "signed short";
755 case builtin_bcd_float:
756 ieee_error (info, p, _("BCD float type not supported"));
757 return DEBUG_TYPE_NULL;
761 type = debug_name_type (dhandle, name, type);
763 assert (indx < BUILTIN_TYPE_COUNT);
765 info->types.builtins[indx] = type;
770 /* Allocate more space in the type table. If ref is TRUE, this is a
771 reference to the type; if it is not already defined, we should set
772 up an indirect type. */
775 ieee_alloc_type (struct ieee_info *info, unsigned int indx, bfd_boolean ref)
778 register struct ieee_type *t;
779 struct ieee_type *tend;
781 if (indx >= info->types.alloc)
783 nalloc = info->types.alloc;
786 while (indx >= nalloc)
789 info->types.types = ((struct ieee_type *)
790 xrealloc (info->types.types,
791 nalloc * sizeof *info->types.types));
793 memset (info->types.types + info->types.alloc, 0,
794 (nalloc - info->types.alloc) * sizeof *info->types.types);
796 tend = info->types.types + nalloc;
797 for (t = info->types.types + info->types.alloc; t < tend; t++)
798 t->type = DEBUG_TYPE_NULL;
800 info->types.alloc = nalloc;
805 t = info->types.types + indx;
808 t->pslot = (debug_type *) xmalloc (sizeof *t->pslot);
809 *t->pslot = DEBUG_TYPE_NULL;
810 t->type = debug_make_indirect_type (info->dhandle, t->pslot,
811 (const char *) NULL);
820 /* Read a type index and return the corresponding type. */
823 ieee_read_type_index (struct ieee_info *info, const bfd_byte **pp,
826 const bfd_byte *start;
831 if (! ieee_read_number (info, pp, &indx))
836 *ptype = ieee_builtin_type (info, start, indx);
843 if (! ieee_alloc_type (info, indx, TRUE))
846 *ptype = info->types.types[indx].type;
851 /* Parse IEEE debugging information for a file. This is passed the
852 bytes which compose the Debug Information Part of an IEEE file. */
855 parse_ieee (void *dhandle, bfd *abfd, const bfd_byte *bytes, bfd_size_type len)
857 struct ieee_info info;
859 const bfd_byte *p, *pend;
861 info.dhandle = dhandle;
864 info.pend = bytes + len;
865 info.blockstack.bsp = info.blockstack.stack;
866 info.saw_filename = FALSE;
868 info.vars.vars = NULL;
869 info.global_vars = NULL;
870 info.types.alloc = 0;
871 info.types.types = NULL;
872 info.global_types = NULL;
874 for (i = 0; i < BUILTIN_TYPE_COUNT; i++)
875 info.types.builtins[i] = DEBUG_TYPE_NULL;
881 const bfd_byte *record_start;
882 ieee_record_enum_type c;
886 c = (ieee_record_enum_type) *p++;
888 if (c == ieee_at_record_enum)
889 c = (ieee_record_enum_type) (((unsigned int) c << 8) | *p++);
891 if (c <= ieee_number_repeat_end_enum)
893 ieee_error (&info, record_start, _("unexpected number"));
900 ieee_error (&info, record_start, _("unexpected record type"));
903 case ieee_bb_record_enum:
904 if (! parse_ieee_bb (&info, &p))
908 case ieee_be_record_enum:
909 if (! parse_ieee_be (&info, &p))
914 if (! parse_ieee_nn (&info, &p))
918 case ieee_ty_record_enum:
919 if (! parse_ieee_ty (&info, &p))
923 case ieee_atn_record_enum:
924 if (! parse_ieee_atn (&info, &p))
930 if (info.blockstack.bsp != info.blockstack.stack)
932 ieee_error (&info, (const bfd_byte *) NULL,
933 _("blocks left on stack at end"));
940 /* Handle an IEEE BB record. */
943 parse_ieee_bb (struct ieee_info *info, const bfd_byte **pp)
945 const bfd_byte *block_start;
949 unsigned long namlen;
950 char *namcopy = NULL;
959 if (! ieee_read_number (info, pp, &size)
960 || ! ieee_read_id (info, pp, &name, &namlen))
963 fnindx = (unsigned int) -1;
969 /* BB1: Type definitions local to a module. */
970 namcopy = savestring (name, namlen);
973 if (! debug_set_filename (info->dhandle, namcopy))
975 info->saw_filename = TRUE;
977 /* Discard any variables or types we may have seen before. */
978 if (info->vars.vars != NULL)
979 free (info->vars.vars);
980 info->vars.vars = NULL;
981 info->vars.alloc = 0;
982 if (info->types.types != NULL)
983 free (info->types.types);
984 info->types.types = NULL;
985 info->types.alloc = 0;
987 /* Initialize the types to the global types. */
988 if (info->global_types != NULL)
990 info->types.alloc = info->global_types->alloc;
991 info->types.types = ((struct ieee_type *)
992 xmalloc (info->types.alloc
993 * sizeof (*info->types.types)));
994 memcpy (info->types.types, info->global_types->types,
995 info->types.alloc * sizeof (*info->types.types));
1001 /* BB2: Global type definitions. The name is supposed to be
1002 empty, but we don't check. */
1003 if (! debug_set_filename (info->dhandle, "*global*"))
1005 info->saw_filename = TRUE;
1009 /* BB3: High level module block begin. We don't have to do
1010 anything here. The name is supposed to be the same as for
1011 the BB1, but we don't check. */
1015 /* BB4: Global function. */
1017 bfd_vma stackspace, typindx, offset;
1018 debug_type return_type;
1020 if (! ieee_read_number (info, pp, &stackspace)
1021 || ! ieee_read_number (info, pp, &typindx)
1022 || ! ieee_read_expression (info, pp, &offset))
1025 /* We have no way to record the stack space. FIXME. */
1029 return_type = ieee_builtin_type (info, block_start, typindx);
1030 if (return_type == DEBUG_TYPE_NULL)
1036 if (! ieee_alloc_type (info, typindx, TRUE))
1039 return_type = info->types.types[typindx].type;
1040 if (debug_get_type_kind (info->dhandle, return_type)
1041 == DEBUG_KIND_FUNCTION)
1042 return_type = debug_get_return_type (info->dhandle,
1046 namcopy = savestring (name, namlen);
1047 if (namcopy == NULL)
1049 if (! debug_record_function (info->dhandle, namcopy, return_type,
1056 /* BB5: File name for source line numbers. */
1060 /* We ignore the date and time. FIXME. */
1061 for (i = 0; i < 6; i++)
1064 bfd_boolean present;
1066 if (! ieee_read_optional_number (info, pp, &ignore, &present))
1072 namcopy = savestring (name, namlen);
1073 if (namcopy == NULL)
1075 if (! debug_start_source (info->dhandle, namcopy))
1081 /* BB6: Local function or block. */
1083 bfd_vma stackspace, typindx, offset;
1085 if (! ieee_read_number (info, pp, &stackspace)
1086 || ! ieee_read_number (info, pp, &typindx)
1087 || ! ieee_read_expression (info, pp, &offset))
1090 /* We have no way to record the stack space. FIXME. */
1094 if (! debug_start_block (info->dhandle, offset))
1096 /* Change b to indicate that this is a block
1097 rather than a function. */
1102 /* The MRI C++ compiler will output a fake function named
1103 __XRYCPP to hold C++ debugging information. We skip
1104 that function. This is not crucial, but it makes
1105 converting from IEEE to other debug formats work
1107 if (strncmp (name, "__XRYCPP", namlen) == 0)
1111 debug_type return_type;
1115 return_type = ieee_builtin_type (info, block_start,
1117 if (return_type == NULL)
1123 if (! ieee_alloc_type (info, typindx, TRUE))
1126 return_type = info->types.types[typindx].type;
1127 if (debug_get_type_kind (info->dhandle, return_type)
1128 == DEBUG_KIND_FUNCTION)
1129 return_type = debug_get_return_type (info->dhandle,
1133 namcopy = savestring (name, namlen);
1134 if (namcopy == NULL)
1136 if (! debug_record_function (info->dhandle, namcopy,
1137 return_type, FALSE, offset))
1145 /* BB10: Assembler module scope. In the normal case, we
1146 completely ignore all this information. FIXME. */
1148 const char *inam, *vstr;
1149 unsigned long inamlen, vstrlen;
1151 bfd_boolean present;
1154 if (! info->saw_filename)
1156 namcopy = savestring (name, namlen);
1157 if (namcopy == NULL)
1159 if (! debug_set_filename (info->dhandle, namcopy))
1161 info->saw_filename = TRUE;
1164 if (! ieee_read_id (info, pp, &inam, &inamlen)
1165 || ! ieee_read_number (info, pp, &tool_type)
1166 || ! ieee_read_optional_id (info, pp, &vstr, &vstrlen, &present))
1168 for (i = 0; i < 6; i++)
1172 if (! ieee_read_optional_number (info, pp, &ignore, &present))
1181 /* BB11: Module section. We completely ignore all this
1182 information. FIXME. */
1184 bfd_vma sectype, secindx, offset, map;
1185 bfd_boolean present;
1187 if (! ieee_read_number (info, pp, §ype)
1188 || ! ieee_read_number (info, pp, &secindx)
1189 || ! ieee_read_expression (info, pp, &offset)
1190 || ! ieee_read_optional_number (info, pp, &map, &present))
1196 ieee_error (info, block_start, _("unknown BB type"));
1201 /* Push this block on the block stack. */
1203 if (info->blockstack.bsp >= info->blockstack.stack + BLOCKSTACK_SIZE)
1205 ieee_error (info, (const bfd_byte *) NULL, _("stack overflow"));
1209 info->blockstack.bsp->kind = b;
1211 info->blockstack.bsp->filename = namcopy;
1212 info->blockstack.bsp->fnindx = fnindx;
1213 info->blockstack.bsp->skip = skip;
1214 ++info->blockstack.bsp;
1219 /* Handle an IEEE BE record. */
1222 parse_ieee_be (struct ieee_info *info, const bfd_byte **pp)
1226 if (info->blockstack.bsp <= info->blockstack.stack)
1228 ieee_error (info, *pp, _("stack underflow"));
1231 --info->blockstack.bsp;
1233 switch (info->blockstack.bsp->kind)
1236 /* When we end the global typedefs block, we copy out the
1237 contents of info->vars. This is because the variable indices
1238 may be reused in the local blocks. However, we need to
1239 preserve them so that we can locate a function returning a
1240 reference variable whose type is named in the global typedef
1242 info->global_vars = ((struct ieee_vars *)
1243 xmalloc (sizeof *info->global_vars));
1244 info->global_vars->alloc = info->vars.alloc;
1245 info->global_vars->vars = ((struct ieee_var *)
1246 xmalloc (info->vars.alloc
1247 * sizeof (*info->vars.vars)));
1248 memcpy (info->global_vars->vars, info->vars.vars,
1249 info->vars.alloc * sizeof (*info->vars.vars));
1251 /* We also copy out the non builtin parts of info->types, since
1252 the types are discarded when we start a new block. */
1253 info->global_types = ((struct ieee_types *)
1254 xmalloc (sizeof *info->global_types));
1255 info->global_types->alloc = info->types.alloc;
1256 info->global_types->types = ((struct ieee_type *)
1257 xmalloc (info->types.alloc
1258 * sizeof (*info->types.types)));
1259 memcpy (info->global_types->types, info->types.types,
1260 info->types.alloc * sizeof (*info->types.types));
1261 memset (info->global_types->builtins, 0,
1262 sizeof (info->global_types->builtins));
1268 if (! ieee_read_expression (info, pp, &offset))
1270 if (! info->blockstack.bsp->skip)
1272 if (! debug_end_function (info->dhandle, offset + 1))
1278 /* This is BE6 when BB6 started a block rather than a local
1280 if (! ieee_read_expression (info, pp, &offset))
1282 if (! debug_end_block (info->dhandle, offset + 1))
1287 /* When we end a BB5, we look up the stack for the last BB5, if
1288 there is one, so that we can call debug_start_source. */
1289 if (info->blockstack.bsp > info->blockstack.stack)
1291 struct ieee_block *bl;
1293 bl = info->blockstack.bsp;
1299 if (! debug_start_source (info->dhandle, bl->filename))
1304 while (bl != info->blockstack.stack);
1309 if (! ieee_read_expression (info, pp, &offset))
1311 /* We just ignore the module size. FIXME. */
1315 /* Other block types do not have any trailing information. */
1322 /* Parse an NN record. */
1325 parse_ieee_nn (struct ieee_info *info, const bfd_byte **pp)
1327 const bfd_byte *nn_start;
1330 unsigned long namlen;
1334 if (! ieee_read_number (info, pp, &varindx)
1335 || ! ieee_read_id (info, pp, &name, &namlen))
1340 ieee_error (info, nn_start, _("illegal variable index"));
1345 if (varindx >= info->vars.alloc)
1349 alloc = info->vars.alloc;
1352 while (varindx >= alloc)
1354 info->vars.vars = ((struct ieee_var *)
1355 xrealloc (info->vars.vars,
1356 alloc * sizeof *info->vars.vars));
1357 memset (info->vars.vars + info->vars.alloc, 0,
1358 (alloc - info->vars.alloc) * sizeof *info->vars.vars);
1359 info->vars.alloc = alloc;
1362 info->vars.vars[varindx].name = name;
1363 info->vars.vars[varindx].namlen = namlen;
1368 /* Parse a TY record. */
1371 parse_ieee_ty (struct ieee_info *info, const bfd_byte **pp)
1373 const bfd_byte *ty_start, *ty_var_start, *ty_code_start;
1374 bfd_vma typeindx, varindx, tc;
1376 bfd_boolean tag, typdef;
1377 debug_type *arg_slots;
1378 unsigned long type_bitsize;
1383 if (! ieee_read_number (info, pp, &typeindx))
1388 ieee_error (info, ty_start, _("illegal type index"));
1393 if (! ieee_alloc_type (info, typeindx, FALSE))
1398 ieee_error (info, *pp, _("unknown TY code"));
1405 if (! ieee_read_number (info, pp, &varindx))
1410 ieee_error (info, ty_var_start, _("illegal variable index"));
1415 if (varindx >= info->vars.alloc || info->vars.vars[varindx].name == NULL)
1417 ieee_error (info, ty_var_start, _("undefined variable in TY"));
1421 ty_code_start = *pp;
1423 if (! ieee_read_number (info, pp, &tc))
1426 dhandle = info->dhandle;
1435 ieee_error (info, ty_code_start, _("unknown TY code"));
1439 /* Unknown type, with size. We treat it as int. FIXME. */
1443 if (! ieee_read_number (info, pp, &size))
1445 type = debug_make_int_type (dhandle, size, FALSE);
1449 case 'A': /* Array. */
1450 case 'a': /* FORTRAN array in column/row order. FIXME: Not
1451 distinguished from normal array. */
1453 debug_type ele_type;
1454 bfd_vma lower, upper;
1456 if (! ieee_read_type_index (info, pp, &ele_type)
1457 || ! ieee_read_number (info, pp, &lower)
1458 || ! ieee_read_number (info, pp, &upper))
1460 type = debug_make_array_type (dhandle, ele_type,
1461 ieee_builtin_type (info, ty_code_start,
1464 (bfd_signed_vma) lower,
1465 (bfd_signed_vma) upper,
1471 /* Simple enumeration. */
1477 bfd_signed_vma *vals;
1480 if (! ieee_read_number (info, pp, &size))
1482 /* FIXME: we ignore the enumeration size. */
1485 names = (const char **) xmalloc (alloc * sizeof *names);
1486 memset (names, 0, alloc * sizeof *names);
1491 unsigned long namlen;
1492 bfd_boolean present;
1494 if (! ieee_read_optional_id (info, pp, &name, &namlen, &present))
1502 names = ((const char **)
1503 xrealloc (names, alloc * sizeof *names));
1506 names[c] = savestring (name, namlen);
1507 if (names[c] == NULL)
1514 vals = (bfd_signed_vma *) xmalloc (c * sizeof *vals);
1515 for (i = 0; i < c; i++)
1518 type = debug_make_enum_type (dhandle, names, vals);
1524 /* Struct with bit fields. */
1528 debug_field *fields;
1531 if (! ieee_read_number (info, pp, &size))
1535 fields = (debug_field *) xmalloc (alloc * sizeof *fields);
1540 unsigned long namlen;
1541 bfd_boolean present;
1543 bfd_vma bitpos, bitsize;
1545 if (! ieee_read_optional_id (info, pp, &name, &namlen, &present))
1549 if (! ieee_read_type_index (info, pp, &ftype)
1550 || ! ieee_read_number (info, pp, &bitpos)
1551 || ! ieee_read_number (info, pp, &bitsize))
1557 fields = ((debug_field *)
1558 xrealloc (fields, alloc * sizeof *fields));
1561 fields[c] = debug_make_field (dhandle, savestring (name, namlen),
1562 ftype, bitpos, bitsize,
1563 DEBUG_VISIBILITY_PUBLIC);
1564 if (fields[c] == NULL)
1571 type = debug_make_struct_type (dhandle, TRUE, size, fields);
1581 bfd_signed_vma *vals;
1585 names = (const char **) xmalloc (alloc * sizeof *names);
1586 vals = (bfd_signed_vma *) xmalloc (alloc * sizeof *names);
1591 unsigned long namlen;
1592 bfd_boolean present;
1595 if (! ieee_read_optional_id (info, pp, &name, &namlen, &present))
1599 if (! ieee_read_number (info, pp, &val))
1602 /* If the length of the name is zero, then the value is
1603 actually the size of the enum. We ignore this
1604 information. FIXME. */
1611 names = ((const char **)
1612 xrealloc (names, alloc * sizeof *names));
1613 vals = ((bfd_signed_vma *)
1614 xrealloc (vals, alloc * sizeof *vals));
1617 names[c] = savestring (name, namlen);
1618 if (names[c] == NULL)
1620 vals[c] = (bfd_signed_vma) val;
1626 type = debug_make_enum_type (dhandle, names, vals);
1631 case 'O': /* Small pointer. We don't distinguish small and large
1633 case 'P': /* Large pointer. */
1637 if (! ieee_read_type_index (info, pp, &t))
1639 type = debug_make_pointer_type (dhandle, t);
1646 bfd_vma low, high, signedp, size;
1648 if (! ieee_read_number (info, pp, &low)
1649 || ! ieee_read_number (info, pp, &high)
1650 || ! ieee_read_number (info, pp, &signedp)
1651 || ! ieee_read_number (info, pp, &size))
1654 type = debug_make_range_type (dhandle,
1655 debug_make_int_type (dhandle, size,
1657 (bfd_signed_vma) low,
1658 (bfd_signed_vma) high);
1662 case 'S': /* Struct. */
1663 case 'U': /* Union. */
1667 debug_field *fields;
1670 if (! ieee_read_number (info, pp, &size))
1674 fields = (debug_field *) xmalloc (alloc * sizeof *fields);
1679 unsigned long namlen;
1680 bfd_boolean present;
1686 if (! ieee_read_optional_id (info, pp, &name, &namlen, &present))
1690 if (! ieee_read_number (info, pp, &tindx)
1691 || ! ieee_read_number (info, pp, &offset))
1696 ftype = ieee_builtin_type (info, ty_code_start, tindx);
1702 struct ieee_type *t;
1705 if (! ieee_alloc_type (info, tindx, TRUE))
1707 t = info->types.types + tindx;
1709 bitsize = t->bitsize;
1717 fields = ((debug_field *)
1718 xrealloc (fields, alloc * sizeof *fields));
1721 fields[c] = debug_make_field (dhandle, savestring (name, namlen),
1722 ftype, offset, bitsize,
1723 DEBUG_VISIBILITY_PUBLIC);
1724 if (fields[c] == NULL)
1731 type = debug_make_struct_type (dhandle, tc == 'S', size, fields);
1738 if (! ieee_read_type_index (info, pp, &type))
1744 /* Procedure. FIXME: This is an extern declaration, which we
1745 have no way of representing. */
1750 bfd_boolean present;
1751 struct ieee_var *pv;
1753 /* FIXME: We ignore the attribute and the argument names. */
1755 if (! ieee_read_number (info, pp, &attr)
1756 || ! ieee_read_type_index (info, pp, &rtype)
1757 || ! ieee_read_number (info, pp, &nargs))
1762 unsigned long namlen;
1764 if (! ieee_read_optional_id (info, pp, &name, &namlen, &present))
1769 pv = info->vars.vars + varindx;
1770 pv->kind = IEEE_EXTERNAL;
1772 && debug_get_type_kind (dhandle, rtype) == DEBUG_KIND_POINTER)
1774 /* Set up the return type as an indirect type pointing to
1775 the variable slot, so that we can change it to a
1776 reference later if appropriate. */
1777 pv->pslot = (debug_type *) xmalloc (sizeof *pv->pslot);
1779 rtype = debug_make_indirect_type (dhandle, pv->pslot,
1780 (const char *) NULL);
1783 type = debug_make_function_type (dhandle, rtype, (debug_type *) NULL,
1789 /* Void. This is not documented, but the MRI compiler emits it. */
1790 type = debug_make_void_type (dhandle);
1794 /* Array with 0 lower bound. */
1799 if (! ieee_read_type_index (info, pp, &etype)
1800 || ! ieee_read_number (info, pp, &high))
1803 type = debug_make_array_type (dhandle, etype,
1804 ieee_builtin_type (info, ty_code_start,
1807 0, (bfd_signed_vma) high, FALSE);
1811 case 'c': /* Complex. */
1812 case 'd': /* Double complex. */
1815 unsigned long namlen;
1817 /* FIXME: I don't know what the name means. */
1819 if (! ieee_read_id (info, pp, &name, &namlen))
1822 type = debug_make_complex_type (dhandle, tc == 'c' ? 4 : 8);
1827 /* Pascal file name. FIXME. */
1828 ieee_error (info, ty_code_start, _("Pascal file name not supported"));
1832 /* Bitfield type. */
1834 bfd_vma signedp, bitsize, dummy;
1835 const bfd_byte *hold;
1836 bfd_boolean present;
1838 if (! ieee_read_number (info, pp, &signedp)
1839 || ! ieee_read_number (info, pp, &bitsize))
1842 /* I think the documentation says that there is a type index,
1843 but some actual files do not have one. */
1845 if (! ieee_read_optional_number (info, pp, &dummy, &present))
1849 /* FIXME: This is just a guess. */
1850 type = debug_make_int_type (dhandle, 4,
1851 signedp ? FALSE : TRUE);
1856 if (! ieee_read_type_index (info, pp, &type))
1859 type_bitsize = bitsize;
1869 if (! ieee_read_number (info, pp, &kind)
1870 || ! ieee_read_type_index (info, pp, &t))
1876 ieee_error (info, ty_start, _("unsupported qualifier"));
1880 type = debug_make_const_type (dhandle, t);
1884 type = debug_make_volatile_type (dhandle, t);
1896 if (! ieee_read_number (info, pp, &size)
1897 || ! ieee_read_type_index (info, pp, &etype))
1900 /* FIXME: We ignore the size. */
1902 type = debug_make_set_type (dhandle, etype, FALSE);
1907 /* Procedure with compiler dependencies. */
1909 struct ieee_var *pv;
1910 bfd_vma attr, frame_type, push_mask, nargs, level, father;
1912 debug_type *arg_types;
1913 bfd_boolean varargs;
1914 bfd_boolean present;
1916 /* FIXME: We ignore some of this information. */
1918 pv = info->vars.vars + varindx;
1920 if (! ieee_read_number (info, pp, &attr)
1921 || ! ieee_read_number (info, pp, &frame_type)
1922 || ! ieee_read_number (info, pp, &push_mask)
1923 || ! ieee_read_type_index (info, pp, &rtype)
1924 || ! ieee_read_number (info, pp, &nargs))
1926 if (nargs == (bfd_vma) -1)
1935 arg_types = ((debug_type *)
1936 xmalloc ((nargs + 1) * sizeof *arg_types));
1937 for (i = 0; i < nargs; i++)
1938 if (! ieee_read_type_index (info, pp, arg_types + i))
1941 /* If the last type is pointer to void, this is really a
1942 varargs function. */
1948 last = arg_types[nargs - 1];
1949 if (debug_get_type_kind (dhandle, last) == DEBUG_KIND_POINTER
1950 && (debug_get_type_kind (dhandle,
1951 debug_get_target_type (dhandle,
1953 == DEBUG_KIND_VOID))
1960 /* If there are any pointer arguments, turn them into
1961 indirect types in case we later need to convert them to
1963 for (i = 0; i < nargs; i++)
1965 if (debug_get_type_kind (dhandle, arg_types[i])
1966 == DEBUG_KIND_POINTER)
1968 if (arg_slots == NULL)
1970 arg_slots = ((debug_type *)
1971 xmalloc (nargs * sizeof *arg_slots));
1972 memset (arg_slots, 0, nargs * sizeof *arg_slots);
1974 arg_slots[i] = arg_types[i];
1976 debug_make_indirect_type (dhandle,
1978 (const char *) NULL);
1982 arg_types[nargs] = DEBUG_TYPE_NULL;
1984 if (! ieee_read_number (info, pp, &level)
1985 || ! ieee_read_optional_number (info, pp, &father, &present))
1988 /* We can't distinguish between a global function and a static
1990 pv->kind = IEEE_FUNCTION;
1993 && debug_get_type_kind (dhandle, rtype) == DEBUG_KIND_POINTER)
1995 /* Set up the return type as an indirect type pointing to
1996 the variable slot, so that we can change it to a
1997 reference later if appropriate. */
1998 pv->pslot = (debug_type *) xmalloc (sizeof *pv->pslot);
2000 rtype = debug_make_indirect_type (dhandle, pv->pslot,
2001 (const char *) NULL);
2004 type = debug_make_function_type (dhandle, rtype, arg_types, varargs);
2009 /* Record the type in the table. */
2011 if (type == DEBUG_TYPE_NULL)
2014 info->vars.vars[varindx].type = type;
2017 && info->vars.vars[varindx].namlen > 0)
2021 name = savestring (info->vars.vars[varindx].name,
2022 info->vars.vars[varindx].namlen);
2024 type = debug_name_type (dhandle, name, type);
2025 else if (tc == 'E' || tc == 'N')
2026 type = debug_tag_type (dhandle, name, type);
2029 struct ieee_tag *it;
2031 /* We must allocate all struct tags as indirect types, so
2032 that if we later see a definition of the tag as a C++
2033 record we can update the indirect slot and automatically
2034 change all the existing references. */
2035 it = (struct ieee_tag *) xmalloc (sizeof *it);
2036 memset (it, 0, sizeof *it);
2037 it->next = info->tags;
2042 type = debug_make_indirect_type (dhandle, &it->slot, name);
2043 type = debug_tag_type (dhandle, name, type);
2051 info->types.types[typeindx].type = type;
2052 info->types.types[typeindx].arg_slots = arg_slots;
2053 info->types.types[typeindx].bitsize = type_bitsize;
2055 /* We may have already allocated type as an indirect type pointing
2056 to slot. It does no harm to replace the indirect type with the
2057 real type. Filling in slot as well handles the indirect types
2058 which are already hanging around. */
2059 if (info->types.types[typeindx].pslot != NULL)
2060 *info->types.types[typeindx].pslot = type;
2065 /* Parse an ATN record. */
2068 parse_ieee_atn (struct ieee_info *info, const bfd_byte **pp)
2070 const bfd_byte *atn_start, *atn_code_start;
2072 struct ieee_var *pvar;
2076 bfd_vma v, v2, v3, v4, v5;
2078 unsigned long namlen;
2080 bfd_boolean present;
2085 if (! ieee_read_number (info, pp, &varindx)
2086 || ! ieee_read_type_index (info, pp, &type))
2089 atn_code_start = *pp;
2091 if (! ieee_read_number (info, pp, &atn_code))
2100 else if (varindx < 32)
2102 /* The MRI compiler reportedly sometimes emits variable lifetime
2103 information for a register. We just ignore it. */
2105 return ieee_read_number (info, pp, &v);
2107 ieee_error (info, atn_start, _("illegal variable index"));
2113 if (varindx >= info->vars.alloc
2114 || info->vars.vars[varindx].name == NULL)
2116 /* The MRI compiler or linker sometimes omits the NN record
2117 for a pmisc record. */
2120 if (varindx >= info->vars.alloc)
2124 alloc = info->vars.alloc;
2127 while (varindx >= alloc)
2129 info->vars.vars = ((struct ieee_var *)
2130 xrealloc (info->vars.vars,
2132 * sizeof *info->vars.vars)));
2133 memset (info->vars.vars + info->vars.alloc, 0,
2134 ((alloc - info->vars.alloc)
2135 * sizeof *info->vars.vars));
2136 info->vars.alloc = alloc;
2139 pvar = info->vars.vars + varindx;
2145 ieee_error (info, atn_start, _("undefined variable in ATN"));
2150 pvar = info->vars.vars + varindx;
2155 namlen = pvar->namlen;
2158 dhandle = info->dhandle;
2160 /* If we are going to call debug_record_variable with a pointer
2161 type, change the type to an indirect type so that we can later
2162 change it to a reference type if we encounter a C++ pmisc 'R'
2165 && type != DEBUG_TYPE_NULL
2166 && debug_get_type_kind (dhandle, type) == DEBUG_KIND_POINTER)
2176 pvar->pslot = (debug_type *) xmalloc (sizeof *pvar->pslot);
2177 *pvar->pslot = type;
2178 type = debug_make_indirect_type (dhandle, pvar->pslot,
2179 (const char *) NULL);
2188 ieee_error (info, atn_code_start, _("unknown ATN type"));
2192 /* Automatic variable. */
2193 if (! ieee_read_number (info, pp, &v))
2195 namcopy = savestring (name, namlen);
2197 type = debug_make_void_type (dhandle);
2199 pvar->kind = IEEE_LOCAL;
2200 return debug_record_variable (dhandle, namcopy, type, DEBUG_LOCAL, v);
2203 /* Register variable. */
2204 if (! ieee_read_number (info, pp, &v))
2206 namcopy = savestring (name, namlen);
2208 type = debug_make_void_type (dhandle);
2210 pvar->kind = IEEE_LOCAL;
2211 return debug_record_variable (dhandle, namcopy, type, DEBUG_REGISTER,
2212 ieee_regno_to_genreg (info->abfd, v));
2215 /* Static variable. */
2216 if (! ieee_require_asn (info, pp, &v))
2218 namcopy = savestring (name, namlen);
2220 type = debug_make_void_type (dhandle);
2221 if (info->blockstack.bsp <= info->blockstack.stack)
2224 blocktype = info->blockstack.bsp[-1].kind;
2227 if (blocktype == 4 || blocktype == 6)
2228 pvar->kind = IEEE_LOCAL;
2230 pvar->kind = IEEE_STATIC;
2232 return debug_record_variable (dhandle, namcopy, type,
2233 (blocktype == 4 || blocktype == 6
2234 ? DEBUG_LOCAL_STATIC
2239 /* External function. We don't currently record these. FIXME. */
2241 pvar->kind = IEEE_EXTERNAL;
2245 /* External variable. We don't currently record these. FIXME. */
2247 pvar->kind = IEEE_EXTERNAL;
2251 if (! ieee_read_number (info, pp, &v)
2252 || ! ieee_read_number (info, pp, &v2)
2253 || ! ieee_read_optional_number (info, pp, &v3, &present))
2257 if (! ieee_read_optional_number (info, pp, &v4, &present))
2261 /* We just ignore the two optional fields in v3 and v4, since
2262 they are not defined. */
2264 if (! ieee_require_asn (info, pp, &v3))
2267 /* We have no way to record the column number. FIXME. */
2269 return debug_record_line (dhandle, v, v3);
2272 /* Global variable. */
2273 if (! ieee_require_asn (info, pp, &v))
2275 namcopy = savestring (name, namlen);
2277 type = debug_make_void_type (dhandle);
2279 pvar->kind = IEEE_GLOBAL;
2280 return debug_record_variable (dhandle, namcopy, type, DEBUG_GLOBAL, v);
2283 /* Variable lifetime information. */
2284 if (! ieee_read_number (info, pp, &v))
2287 /* We have no way to record this information. FIXME. */
2291 /* Locked register. The spec says that there are two required
2292 fields, but at least on occasion the MRI compiler only emits
2294 if (! ieee_read_number (info, pp, &v)
2295 || ! ieee_read_optional_number (info, pp, &v2, &present))
2298 /* I think this means a variable that is both in a register and
2299 a frame slot. We ignore the frame slot. FIXME. */
2301 namcopy = savestring (name, namlen);
2303 type = debug_make_void_type (dhandle);
2305 pvar->kind = IEEE_LOCAL;
2306 return debug_record_variable (dhandle, namcopy, type, DEBUG_REGISTER, v);
2309 /* Reserved for FORTRAN common. */
2310 ieee_error (info, atn_code_start, _("unsupported ATN11"));
2312 /* Return TRUE to keep going. */
2316 /* Based variable. */
2320 if (! ieee_read_number (info, pp, &v)
2321 || ! ieee_read_number (info, pp, &v2)
2322 || ! ieee_read_optional_number (info, pp, &v3, &present))
2326 if (! ieee_read_optional_number (info, pp, &v4, &present))
2330 if (! ieee_read_optional_number (info, pp, &v5, &present))
2335 /* We have no way to record this information. FIXME. */
2337 ieee_error (info, atn_code_start, _("unsupported ATN12"));
2339 /* Return TRUE to keep going. */
2343 /* Constant. The description of this that I have is ambiguous,
2344 so I'm not going to try to implement it. */
2345 if (! ieee_read_number (info, pp, &v)
2346 || ! ieee_read_optional_number (info, pp, &v2, &present))
2350 if (! ieee_read_optional_number (info, pp, &v2, &present))
2354 if (! ieee_read_optional_id (info, pp, &name, &namlen, &present))
2359 if ((ieee_record_enum_type) **pp == ieee_e2_first_byte_enum)
2361 if (! ieee_require_asn (info, pp, &v3))
2368 /* Static variable from assembler. */
2370 if (! ieee_read_number (info, pp, &v)
2371 || ! ieee_read_optional_number (info, pp, &v2, &present)
2372 || ! ieee_require_asn (info, pp, &v3))
2374 namcopy = savestring (name, namlen);
2375 /* We don't really handle this correctly. FIXME. */
2376 return debug_record_variable (dhandle, namcopy,
2377 debug_make_void_type (dhandle),
2378 v2 != 0 ? DEBUG_GLOBAL : DEBUG_STATIC,
2382 /* Procedure miscellaneous information. */
2384 /* Variable miscellaneous information. */
2386 /* Module miscellaneous information. */
2387 if (! ieee_read_number (info, pp, &v)
2388 || ! ieee_read_number (info, pp, &v2)
2389 || ! ieee_read_optional_id (info, pp, &name, &namlen, &present))
2392 if (atn_code == 62 && v == 80)
2396 ieee_error (info, atn_code_start,
2397 _("unexpected string in C++ misc"));
2400 return ieee_read_cxx_misc (info, pp, v2);
2403 /* We just ignore all of this stuff. FIXME. */
2405 for (; v2 > 0; --v2)
2407 switch ((ieee_record_enum_type) **pp)
2410 ieee_error (info, *pp, _("bad misc record"));
2413 case ieee_at_record_enum:
2414 if (! ieee_require_atn65 (info, pp, &name, &namlen))
2418 case ieee_e2_first_byte_enum:
2419 if (! ieee_require_asn (info, pp, &v3))
2431 /* Handle C++ debugging miscellaneous records. This is called for
2432 procedure miscellaneous records of type 80. */
2435 ieee_read_cxx_misc (struct ieee_info *info, const bfd_byte **pp,
2436 unsigned long count)
2438 const bfd_byte *start;
2443 /* Get the category of C++ misc record. */
2444 if (! ieee_require_asn (info, pp, &category))
2451 ieee_error (info, start, _("unrecognized C++ misc record"));
2455 if (! ieee_read_cxx_class (info, pp, count))
2463 unsigned long namlen;
2465 /* The IEEE spec indicates that the 'M' record only has a
2466 flags field. The MRI compiler also emits the name of the
2469 if (! ieee_require_asn (info, pp, &flags))
2471 if (*pp < info->pend
2472 && (ieee_record_enum_type) **pp == ieee_at_record_enum)
2474 if (! ieee_require_atn65 (info, pp, &name, &namlen))
2478 /* This is emitted for method functions, but I don't think we
2479 care very much. It might help if it told us useful
2480 information like the class with which this function is
2481 associated, but it doesn't, so it isn't helpful. */
2486 if (! ieee_read_cxx_defaults (info, pp, count))
2492 const char *name, *mangled, *class;
2493 unsigned long namlen, mangledlen, classlen;
2496 /* Pointer to member. */
2498 if (! ieee_require_atn65 (info, pp, &name, &namlen)
2499 || ! ieee_require_atn65 (info, pp, &mangled, &mangledlen)
2500 || ! ieee_require_atn65 (info, pp, &class, &classlen)
2501 || ! ieee_require_asn (info, pp, &control))
2504 /* FIXME: We should now track down name and change its type. */
2509 if (! ieee_read_reference (info, pp))
2517 /* Read a C++ class definition. This is a pmisc type 80 record of
2521 ieee_read_cxx_class (struct ieee_info *info, const bfd_byte **pp,
2522 unsigned long count)
2524 const bfd_byte *start;
2527 unsigned long taglen;
2528 struct ieee_tag *it;
2530 debug_field *fields;
2531 unsigned int field_count, field_alloc;
2532 debug_baseclass *baseclasses;
2533 unsigned int baseclasses_count, baseclasses_alloc;
2534 const debug_field *structfields;
2538 unsigned long namlen;
2539 debug_method_variant *variants;
2543 unsigned int methods_count, methods_alloc;
2544 debug_type vptrbase;
2545 bfd_boolean ownvptr;
2546 debug_method *dmethods;
2550 if (! ieee_require_asn (info, pp, &class))
2554 if (! ieee_require_atn65 (info, pp, &tag, &taglen))
2558 /* Find the C struct with this name. */
2559 for (it = info->tags; it != NULL; it = it->next)
2560 if (it->name[0] == tag[0]
2561 && strncmp (it->name, tag, taglen) == 0
2562 && strlen (it->name) == taglen)
2566 ieee_error (info, start, _("undefined C++ object"));
2570 dhandle = info->dhandle;
2576 baseclasses_count = 0;
2577 baseclasses_alloc = 0;
2581 vptrbase = DEBUG_TYPE_NULL;
2584 structfields = debug_get_fields (dhandle, it->type);
2589 const bfd_byte *spec_start;
2593 if (! ieee_require_asn (info, pp, &id))
2600 ieee_error (info, spec_start, _("unrecognized C++ object spec"));
2605 bfd_vma flags, cinline;
2606 const char *basename, *fieldname;
2607 unsigned long baselen, fieldlen;
2609 debug_type basetype;
2611 bfd_boolean virtualp;
2612 enum debug_visibility visibility;
2613 debug_baseclass baseclass;
2615 /* This represents a base or friend class. */
2617 if (! ieee_require_asn (info, pp, &flags)
2618 || ! ieee_require_atn65 (info, pp, &basename, &baselen)
2619 || ! ieee_require_asn (info, pp, &cinline)
2620 || ! ieee_require_atn65 (info, pp, &fieldname, &fieldlen))
2624 /* We have no way of recording friend information, so we
2626 if ((flags & BASEFLAGS_FRIEND) != 0)
2629 /* I assume that either all of the members of the
2630 baseclass are included in the object, starting at the
2631 beginning of the object, or that none of them are
2634 if ((fieldlen == 0) == (cinline == 0))
2636 ieee_error (info, start, _("unsupported C++ object type"));
2640 basecopy = savestring (basename, baselen);
2641 basetype = debug_find_tagged_type (dhandle, basecopy,
2642 DEBUG_KIND_ILLEGAL);
2644 if (basetype == DEBUG_TYPE_NULL)
2646 ieee_error (info, start, _("C++ base class not defined"));
2654 const debug_field *pf;
2656 if (structfields == NULL)
2658 ieee_error (info, start, _("C++ object has no fields"));
2662 for (pf = structfields; *pf != DEBUG_FIELD_NULL; pf++)
2666 fname = debug_get_field_name (dhandle, *pf);
2669 if (fname[0] == fieldname[0]
2670 && strncmp (fname, fieldname, fieldlen) == 0
2671 && strlen (fname) == fieldlen)
2674 if (*pf == DEBUG_FIELD_NULL)
2676 ieee_error (info, start,
2677 _("C++ base class not found in container"));
2681 bitpos = debug_get_field_bitpos (dhandle, *pf);
2684 if ((flags & BASEFLAGS_VIRTUAL) != 0)
2688 if ((flags & BASEFLAGS_PRIVATE) != 0)
2689 visibility = DEBUG_VISIBILITY_PRIVATE;
2691 visibility = DEBUG_VISIBILITY_PUBLIC;
2693 baseclass = debug_make_baseclass (dhandle, basetype, bitpos,
2694 virtualp, visibility);
2695 if (baseclass == DEBUG_BASECLASS_NULL)
2698 if (baseclasses_count + 1 >= baseclasses_alloc)
2700 baseclasses_alloc += 10;
2701 baseclasses = ((debug_baseclass *)
2702 xrealloc (baseclasses,
2704 * sizeof *baseclasses)));
2707 baseclasses[baseclasses_count] = baseclass;
2708 ++baseclasses_count;
2709 baseclasses[baseclasses_count] = DEBUG_BASECLASS_NULL;
2716 const char *fieldname, *mangledname;
2717 unsigned long fieldlen, mangledlen;
2719 bfd_boolean staticp;
2721 const debug_field *pf = NULL;
2722 enum debug_visibility visibility;
2725 /* This represents a data member. */
2727 if (! ieee_require_asn (info, pp, &flags)
2728 || ! ieee_require_atn65 (info, pp, &fieldname, &fieldlen)
2729 || ! ieee_require_atn65 (info, pp, &mangledname, &mangledlen))
2733 fieldcopy = savestring (fieldname, fieldlen);
2735 staticp = (flags & CXXFLAGS_STATIC) != 0 ? TRUE : FALSE;
2739 struct ieee_var *pv, *pvend;
2741 /* See if we can find a definition for this variable. */
2742 pv = info->vars.vars;
2743 pvend = pv + info->vars.alloc;
2744 for (; pv < pvend; pv++)
2745 if (pv->namlen == mangledlen
2746 && strncmp (pv->name, mangledname, mangledlen) == 0)
2752 /* This can happen if the variable is never used. */
2753 ftype = ieee_builtin_type (info, start,
2754 (unsigned int) builtin_void);
2761 if (structfields == NULL)
2763 ieee_error (info, start, _("C++ object has no fields"));
2767 for (pf = structfields, findx = 0;
2768 *pf != DEBUG_FIELD_NULL;
2773 fname = debug_get_field_name (dhandle, *pf);
2776 if (fname[0] == mangledname[0]
2777 && strncmp (fname, mangledname, mangledlen) == 0
2778 && strlen (fname) == mangledlen)
2781 if (*pf == DEBUG_FIELD_NULL)
2783 ieee_error (info, start,
2784 _("C++ data member not found in container"));
2788 ftype = debug_get_field_type (dhandle, *pf);
2790 if (debug_get_type_kind (dhandle, ftype) == DEBUG_KIND_POINTER)
2792 /* We might need to convert this field into a
2793 reference type later on, so make it an indirect
2795 if (it->fslots == NULL)
2798 const debug_field *pfcnt;
2801 for (pfcnt = structfields;
2802 *pfcnt != DEBUG_FIELD_NULL;
2805 it->fslots = ((debug_type *)
2806 xmalloc (fcnt * sizeof *it->fslots));
2807 memset (it->fslots, 0,
2808 fcnt * sizeof *it->fslots);
2811 if (ftype == DEBUG_TYPE_NULL)
2813 it->fslots[findx] = ftype;
2814 ftype = debug_make_indirect_type (dhandle,
2816 (const char *) NULL);
2819 if (ftype == DEBUG_TYPE_NULL)
2822 switch (flags & CXXFLAGS_VISIBILITY)
2825 ieee_error (info, start, _("unknown C++ visibility"));
2828 case CXXFLAGS_VISIBILITY_PUBLIC:
2829 visibility = DEBUG_VISIBILITY_PUBLIC;
2832 case CXXFLAGS_VISIBILITY_PRIVATE:
2833 visibility = DEBUG_VISIBILITY_PRIVATE;
2836 case CXXFLAGS_VISIBILITY_PROTECTED:
2837 visibility = DEBUG_VISIBILITY_PROTECTED;
2845 mangledcopy = savestring (mangledname, mangledlen);
2847 field = debug_make_static_member (dhandle, fieldcopy,
2853 bfd_vma bitpos, bitsize;
2855 bitpos = debug_get_field_bitpos (dhandle, *pf);
2856 bitsize = debug_get_field_bitsize (dhandle, *pf);
2857 if (bitpos == (bfd_vma) -1 || bitsize == (bfd_vma) -1)
2859 ieee_error (info, start, _("bad C++ field bit pos or size"));
2862 field = debug_make_field (dhandle, fieldcopy, ftype, bitpos,
2863 bitsize, visibility);
2866 if (field == DEBUG_FIELD_NULL)
2869 if (field_count + 1 >= field_alloc)
2872 fields = ((debug_field *)
2873 xrealloc (fields, field_alloc * sizeof *fields));
2876 fields[field_count] = field;
2878 fields[field_count] = DEBUG_FIELD_NULL;
2885 bfd_vma flags, voffset, control;
2886 const char *name, *mangled;
2887 unsigned long namlen, mangledlen;
2888 struct ieee_var *pv, *pvend;
2890 enum debug_visibility visibility;
2891 bfd_boolean constp, volatilep;
2893 debug_method_variant mv;
2894 struct ieee_method *meth;
2897 if (! ieee_require_asn (info, pp, &flags)
2898 || ! ieee_require_atn65 (info, pp, &name, &namlen)
2899 || ! ieee_require_atn65 (info, pp, &mangled, &mangledlen))
2906 if (! ieee_require_asn (info, pp, &voffset))
2910 if (! ieee_require_asn (info, pp, &control))
2914 /* We just ignore the control information. */
2916 /* We have no way to represent friend information, so we
2918 if ((flags & CXXFLAGS_FRIEND) != 0)
2921 /* We should already have seen a type for the function. */
2922 pv = info->vars.vars;
2923 pvend = pv + info->vars.alloc;
2924 for (; pv < pvend; pv++)
2925 if (pv->namlen == mangledlen
2926 && strncmp (pv->name, mangled, mangledlen) == 0)
2931 /* We won't have type information for this function if
2932 it is not included in this file. We don't try to
2933 handle this case. FIXME. */
2934 type = (debug_make_function_type
2936 ieee_builtin_type (info, start,
2937 (unsigned int) builtin_void),
2938 (debug_type *) NULL,
2943 debug_type return_type;
2944 const debug_type *arg_types;
2945 bfd_boolean varargs;
2947 if (debug_get_type_kind (dhandle, pv->type)
2948 != DEBUG_KIND_FUNCTION)
2950 ieee_error (info, start,
2951 _("bad type for C++ method function"));
2955 return_type = debug_get_return_type (dhandle, pv->type);
2956 arg_types = debug_get_parameter_types (dhandle, pv->type,
2958 if (return_type == DEBUG_TYPE_NULL || arg_types == NULL)
2960 ieee_error (info, start,
2961 _("no type information for C++ method function"));
2965 type = debug_make_method_type (dhandle, return_type, it->type,
2966 (debug_type *) arg_types,
2969 if (type == DEBUG_TYPE_NULL)
2972 switch (flags & CXXFLAGS_VISIBILITY)
2975 ieee_error (info, start, _("unknown C++ visibility"));
2978 case CXXFLAGS_VISIBILITY_PUBLIC:
2979 visibility = DEBUG_VISIBILITY_PUBLIC;
2982 case CXXFLAGS_VISIBILITY_PRIVATE:
2983 visibility = DEBUG_VISIBILITY_PRIVATE;
2986 case CXXFLAGS_VISIBILITY_PROTECTED:
2987 visibility = DEBUG_VISIBILITY_PROTECTED;
2991 constp = (flags & CXXFLAGS_CONST) != 0 ? TRUE : FALSE;
2992 volatilep = (flags & CXXFLAGS_VOLATILE) != 0 ? TRUE : FALSE;
2994 mangledcopy = savestring (mangled, mangledlen);
2996 if ((flags & CXXFLAGS_STATIC) != 0)
3000 ieee_error (info, start, _("C++ static virtual method"));
3003 mv = debug_make_static_method_variant (dhandle, mangledcopy,
3009 debug_type vcontext;
3012 vcontext = DEBUG_TYPE_NULL;
3015 /* FIXME: How can we calculate this correctly? */
3016 vcontext = it->type;
3018 mv = debug_make_method_variant (dhandle, mangledcopy, type,
3023 if (mv == DEBUG_METHOD_VARIANT_NULL)
3026 for (meth = methods, im = 0; im < methods_count; meth++, im++)
3027 if (meth->namlen == namlen
3028 && strncmp (meth->name, name, namlen) == 0)
3030 if (im >= methods_count)
3032 if (methods_count >= methods_alloc)
3034 methods_alloc += 10;
3035 methods = ((struct ieee_method *)
3037 methods_alloc * sizeof *methods));
3039 methods[methods_count].name = name;
3040 methods[methods_count].namlen = namlen;
3041 methods[methods_count].variants = NULL;
3042 methods[methods_count].count = 0;
3043 methods[methods_count].alloc = 0;
3044 meth = methods + methods_count;
3048 if (meth->count + 1 >= meth->alloc)
3051 meth->variants = ((debug_method_variant *)
3052 xrealloc (meth->variants,
3054 * sizeof *meth->variants)));
3057 meth->variants[meth->count] = mv;
3059 meth->variants[meth->count] = DEBUG_METHOD_VARIANT_NULL;
3067 /* We have no way to store this information, so we just
3069 if (! ieee_require_asn (info, pp, &spec))
3072 if ((spec & 4) != 0)
3074 const char *filename;
3075 unsigned long filenamlen;
3078 if (! ieee_require_atn65 (info, pp, &filename, &filenamlen)
3079 || ! ieee_require_asn (info, pp, &lineno))
3083 else if ((spec & 8) != 0)
3085 const char *mangled;
3086 unsigned long mangledlen;
3088 if (! ieee_require_atn65 (info, pp, &mangled, &mangledlen))
3094 ieee_error (info, start,
3095 _("unrecognized C++ object overhead spec"));
3103 const char *vname, *basename;
3104 unsigned long vnamelen, baselen;
3105 bfd_vma vsize, control;
3107 /* A virtual table pointer. */
3109 if (! ieee_require_atn65 (info, pp, &vname, &vnamelen)
3110 || ! ieee_require_asn (info, pp, &vsize)
3111 || ! ieee_require_atn65 (info, pp, &basename, &baselen)
3112 || ! ieee_require_asn (info, pp, &control))
3116 /* We just ignore the control number. We don't care what
3117 the virtual table name is. We have no way to store the
3118 virtual table size, and I don't think we care anyhow. */
3120 /* FIXME: We can't handle multiple virtual table pointers. */
3128 basecopy = savestring (basename, baselen);
3129 vptrbase = debug_find_tagged_type (dhandle, basecopy,
3130 DEBUG_KIND_ILLEGAL);
3132 if (vptrbase == DEBUG_TYPE_NULL)
3134 ieee_error (info, start, _("undefined C++ vtable"));
3143 /* Now that we have seen all the method variants, we can call
3144 debug_make_method for each one. */
3146 if (methods_count == 0)
3152 dmethods = ((debug_method *)
3153 xmalloc ((methods_count + 1) * sizeof *dmethods));
3154 for (i = 0; i < methods_count; i++)
3158 namcopy = savestring (methods[i].name, methods[i].namlen);
3159 dmethods[i] = debug_make_method (dhandle, namcopy,
3160 methods[i].variants);
3161 if (dmethods[i] == DEBUG_METHOD_NULL)
3164 dmethods[i] = DEBUG_METHOD_NULL;
3168 /* The struct type was created as an indirect type pointing at
3169 it->slot. We update it->slot to automatically update all
3170 references to this struct. */
3171 it->slot = debug_make_object_type (dhandle,
3173 debug_get_type_size (dhandle,
3175 fields, baseclasses, dmethods,
3177 if (it->slot == DEBUG_TYPE_NULL)
3183 /* Read C++ default argument value and reference type information. */
3186 ieee_read_cxx_defaults (struct ieee_info *info, const bfd_byte **pp,
3187 unsigned long count)
3189 const bfd_byte *start;
3191 unsigned long fnlen;
3196 /* Giving the function name before the argument count is an addendum
3197 to the spec. The function name is demangled, though, so this
3198 record must always refer to the current function. */
3200 if (info->blockstack.bsp <= info->blockstack.stack
3201 || info->blockstack.bsp[-1].fnindx == (unsigned int) -1)
3203 ieee_error (info, start, _("C++ default values not in a function"));
3207 if (! ieee_require_atn65 (info, pp, &fnname, &fnlen)
3208 || ! ieee_require_asn (info, pp, &defcount))
3212 while (defcount-- > 0)
3216 unsigned long strvallen;
3218 if (! ieee_require_asn (info, pp, &type))
3230 if (! ieee_require_asn (info, pp, &val))
3237 if (! ieee_require_atn65 (info, pp, &strval, &strvallen))
3243 ieee_error (info, start, _("unrecognized C++ default type"));
3247 /* We have no way to record the default argument values, so we
3248 just ignore them. FIXME. */
3251 /* Any remaining arguments are indices of parameters that are really
3256 debug_type *arg_slots;
3258 dhandle = info->dhandle;
3259 arg_slots = info->types.types[info->blockstack.bsp[-1].fnindx].arg_slots;
3265 if (! ieee_require_asn (info, pp, &indx))
3267 /* The index is 1 based. */
3269 if (arg_slots == NULL
3270 || arg_slots[indx] == DEBUG_TYPE_NULL
3271 || (debug_get_type_kind (dhandle, arg_slots[indx])
3272 != DEBUG_KIND_POINTER))
3274 ieee_error (info, start, _("reference parameter is not a pointer"));
3278 target = debug_get_target_type (dhandle, arg_slots[indx]);
3279 arg_slots[indx] = debug_make_reference_type (dhandle, target);
3280 if (arg_slots[indx] == DEBUG_TYPE_NULL)
3288 /* Read a C++ reference definition. */
3291 ieee_read_reference (struct ieee_info *info, const bfd_byte **pp)
3293 const bfd_byte *start;
3295 const char *class, *name;
3296 unsigned long classlen, namlen;
3302 if (! ieee_require_asn (info, pp, &flags))
3305 /* Giving the class name before the member name is in an addendum to
3309 if (! ieee_require_atn65 (info, pp, &class, &classlen))
3313 if (! ieee_require_atn65 (info, pp, &name, &namlen))
3321 /* We search from the last variable indices to the first in
3322 hopes of finding local variables correctly. We search the
3323 local variables on the first pass, and the global variables
3324 on the second. FIXME: This probably won't work in all cases.
3325 On the other hand, I don't know what will. */
3326 for (pass = 0; pass < 2; pass++)
3328 struct ieee_vars *vars;
3330 struct ieee_var *pv = NULL;
3336 vars = info->global_vars;
3341 for (i = (int) vars->alloc - 1; i >= 0; i--)
3345 pv = vars->vars + i;
3347 if (pv->pslot == NULL
3348 || pv->namlen != namlen
3349 || strncmp (pv->name, name, namlen) != 0)
3356 ieee_error (info, start,
3357 _("unrecognized C++ reference type"));
3361 /* Global variable or function. */
3362 if (pv->kind == IEEE_GLOBAL
3363 || pv->kind == IEEE_EXTERNAL
3364 || pv->kind == IEEE_FUNCTION)
3369 /* Global static variable or function. */
3370 if (pv->kind == IEEE_STATIC
3371 || pv->kind == IEEE_FUNCTION)
3376 /* Local variable. */
3377 if (pv->kind == IEEE_LOCAL)
3395 struct ieee_tag *it;
3397 for (it = info->tags; it != NULL; it = it->next)
3399 if (it->name[0] == class[0]
3400 && strncmp (it->name, class, classlen) == 0
3401 && strlen (it->name) == classlen)
3403 if (it->fslots != NULL)
3405 const debug_field *pf;
3408 pf = debug_get_fields (info->dhandle, it->type);
3411 ieee_error (info, start,
3412 "C++ reference in class with no fields");
3416 for (findx = 0; *pf != DEBUG_FIELD_NULL; pf++, findx++)
3420 fname = debug_get_field_name (info->dhandle, *pf);
3423 if (strncmp (fname, name, namlen) == 0
3424 && strlen (fname) == namlen)
3426 pslot = it->fslots + findx;
3439 ieee_error (info, start, _("C++ reference not found"));
3443 /* We allocated the type of the object as an indirect type pointing
3444 to *pslot, which we can now update to be a reference type. */
3445 if (debug_get_type_kind (info->dhandle, *pslot) != DEBUG_KIND_POINTER)
3447 ieee_error (info, start, _("C++ reference is not pointer"));
3451 target = debug_get_target_type (info->dhandle, *pslot);
3452 *pslot = debug_make_reference_type (info->dhandle, target);
3453 if (*pslot == DEBUG_TYPE_NULL)
3459 /* Require an ASN record. */
3462 ieee_require_asn (struct ieee_info *info, const bfd_byte **pp, bfd_vma *pv)
3464 const bfd_byte *start;
3465 ieee_record_enum_type c;
3470 c = (ieee_record_enum_type) **pp;
3471 if (c != ieee_e2_first_byte_enum)
3473 ieee_error (info, start, _("missing required ASN"));
3478 c = (ieee_record_enum_type) (((unsigned int) c << 8) | **pp);
3479 if (c != ieee_asn_record_enum)
3481 ieee_error (info, start, _("missing required ASN"));
3486 /* Just ignore the variable index. */
3487 if (! ieee_read_number (info, pp, &varindx))
3490 return ieee_read_expression (info, pp, pv);
3493 /* Require an ATN65 record. */
3496 ieee_require_atn65 (struct ieee_info *info, const bfd_byte **pp,
3497 const char **pname, unsigned long *pnamlen)
3499 const bfd_byte *start;
3500 ieee_record_enum_type c;
3501 bfd_vma name_indx, type_indx, atn_code;
3505 c = (ieee_record_enum_type) **pp;
3506 if (c != ieee_at_record_enum)
3508 ieee_error (info, start, _("missing required ATN65"));
3513 c = (ieee_record_enum_type) (((unsigned int) c << 8) | **pp);
3514 if (c != ieee_atn_record_enum)
3516 ieee_error (info, start, _("missing required ATN65"));
3521 if (! ieee_read_number (info, pp, &name_indx)
3522 || ! ieee_read_number (info, pp, &type_indx)
3523 || ! ieee_read_number (info, pp, &atn_code))
3526 /* Just ignore name_indx. */
3528 if (type_indx != 0 || atn_code != 65)
3530 ieee_error (info, start, _("bad ATN65 record"));
3534 return ieee_read_id (info, pp, pname, pnamlen);
3537 /* Convert a register number in IEEE debugging information into a
3538 generic register number. */
3541 ieee_regno_to_genreg (bfd *abfd, int r)
3543 switch (bfd_get_arch (abfd))
3546 /* For some reasons stabs adds 2 to the floating point register
3553 /* Stabs uses 0 to 15 for r0 to r15, 16 to 31 for g0 to g15, and
3554 32 to 35 for fp0 to fp3. */
3565 /* Convert a generic register number to an IEEE specific one. */
3568 ieee_genreg_to_regno (bfd *abfd, int r)
3570 switch (bfd_get_arch (abfd))
3573 /* For some reason stabs add 2 to the floating point register
3580 /* Stabs uses 0 to 15 for r0 to r15, 16 to 31 for g0 to g15, and
3581 32 to 35 for fp0 to fp3. */
3592 /* These routines build IEEE debugging information out of the generic
3593 debugging information. */
3595 /* We build the IEEE debugging information byte by byte. Rather than
3596 waste time copying data around, we use a linked list of buffers to
3599 #define IEEE_BUFSIZE (490)
3604 struct ieee_buf *next;
3605 /* Number of data bytes in this buffer. */
3608 bfd_byte buf[IEEE_BUFSIZE];
3611 /* A list of buffers. */
3616 struct ieee_buf *head;
3617 /* Tail--last buffer on list. */
3618 struct ieee_buf *tail;
3621 /* In order to generate the BB11 blocks required by the HP emulator,
3622 we keep track of ranges of addresses which correspond to a given
3623 compilation unit. */
3628 struct ieee_range *next;
3635 /* This structure holds information for a class on the type stack. */
3637 struct ieee_type_class
3639 /* The name index in the debugging information. */
3641 /* The pmisc records for the class. */
3642 struct ieee_buflist pmiscbuf;
3643 /* The number of pmisc records. */
3644 unsigned int pmisccount;
3645 /* The name of the class holding the virtual table, if not this
3648 /* Whether this class holds its own virtual table. */
3649 bfd_boolean ownvptr;
3650 /* The largest virtual table offset seen so far. */
3652 /* The current method. */
3654 /* Additional pmisc records used to record fields of reference type. */
3655 struct ieee_buflist refs;
3658 /* This is how we store types for the writing routines. Most types
3659 are simply represented by a type index. */
3661 struct ieee_write_type
3665 /* The size of the type, if known. */
3667 /* The name of the type, if any. */
3669 /* If this is a function or method type, we build the type here, and
3670 only add it to the output buffers if we need it. */
3671 struct ieee_buflist fndef;
3672 /* If this is a struct, this is where the struct definition is
3674 struct ieee_buflist strdef;
3675 /* If this is a class, this is where the class information is built. */
3676 struct ieee_type_class *classdef;
3677 /* Whether the type is unsigned. */
3678 unsigned int unsignedp : 1;
3679 /* Whether this is a reference type. */
3680 unsigned int referencep : 1;
3681 /* Whether this is in the local type block. */
3682 unsigned int localp : 1;
3683 /* Whether this is a duplicate struct definition which we are
3685 unsigned int ignorep : 1;
3688 /* This is the type stack used by the debug writing routines. FIXME:
3689 We could generate more efficient output if we remembered when we
3690 have output a particular type before. */
3692 struct ieee_type_stack
3694 /* Next entry on stack. */
3695 struct ieee_type_stack *next;
3696 /* Type information. */
3697 struct ieee_write_type type;
3700 /* This is a list of associations between a name and some types.
3701 These are used for typedefs and tags. */
3703 struct ieee_name_type
3705 /* Next type for this name. */
3706 struct ieee_name_type *next;
3707 /* ID number. For a typedef, this is the index of the type to which
3708 this name is typedefed. */
3711 struct ieee_write_type type;
3712 /* If this is a tag which has not yet been defined, this is the
3713 kind. If the tag has been defined, this is DEBUG_KIND_ILLEGAL. */
3714 enum debug_type_kind kind;
3717 /* We use a hash table to associate names and types. */
3719 struct ieee_name_type_hash_table
3721 struct bfd_hash_table root;
3724 struct ieee_name_type_hash_entry
3726 struct bfd_hash_entry root;
3727 /* Information for this name. */
3728 struct ieee_name_type *types;
3731 /* This is a list of enums. */
3733 struct ieee_defined_enum
3736 struct ieee_defined_enum *next;
3739 /* Whether this enum has been defined. */
3740 bfd_boolean defined;
3746 bfd_signed_vma *vals;
3749 /* We keep a list of modified versions of types, so that we don't
3750 output them more than once. */
3752 struct ieee_modified_type
3754 /* Pointer to this type. */
3755 unsigned int pointer;
3756 /* Function with unknown arguments returning this type. */
3757 unsigned int function;
3758 /* Const version of this type. */
3759 unsigned int const_qualified;
3760 /* Volatile version of this type. */
3761 unsigned int volatile_qualified;
3762 /* List of arrays of this type of various bounds. */
3763 struct ieee_modified_array_type *arrays;
3766 /* A list of arrays bounds. */
3768 struct ieee_modified_array_type
3770 /* Next array bounds. */
3771 struct ieee_modified_array_type *next;
3772 /* Type index with these bounds. */
3777 bfd_signed_vma high;
3780 /* This is a list of pending function parameter information. We don't
3781 output them until we see the first block. */
3783 struct ieee_pending_parm
3785 /* Next pending parameter. */
3786 struct ieee_pending_parm *next;
3791 /* Whether the type is a reference. */
3792 bfd_boolean referencep;
3794 enum debug_parm_kind kind;
3799 /* This is the handle passed down by debug_write. */
3803 /* BFD we are writing to. */
3805 /* Whether we got an error in a subroutine called via traverse or
3806 map_over_sections. */
3808 /* Current data buffer list. */
3809 struct ieee_buflist *current;
3810 /* Current data buffer. */
3811 struct ieee_buf *curbuf;
3812 /* Filename of current compilation unit. */
3813 const char *filename;
3814 /* Module name of current compilation unit. */
3815 const char *modname;
3816 /* List of buffer for global types. */
3817 struct ieee_buflist global_types;
3818 /* List of finished data buffers. */
3819 struct ieee_buflist data;
3820 /* List of buffers for typedefs in the current compilation unit. */
3821 struct ieee_buflist types;
3822 /* List of buffers for variables and functions in the current
3823 compilation unit. */
3824 struct ieee_buflist vars;
3825 /* List of buffers for C++ class definitions in the current
3826 compilation unit. */
3827 struct ieee_buflist cxx;
3828 /* List of buffers for line numbers in the current compilation unit. */
3829 struct ieee_buflist linenos;
3830 /* Ranges for the current compilation unit. */
3831 struct ieee_range *ranges;
3832 /* Ranges for all debugging information. */
3833 struct ieee_range *global_ranges;
3834 /* Nested pending ranges. */
3835 struct ieee_range *pending_ranges;
3837 struct ieee_type_stack *type_stack;
3838 /* Next unallocated type index. */
3839 unsigned int type_indx;
3840 /* Next unallocated name index. */
3841 unsigned int name_indx;
3843 struct ieee_name_type_hash_table typedefs;
3845 struct ieee_name_type_hash_table tags;
3847 struct ieee_defined_enum *enums;
3848 /* Modified versions of types. */
3849 struct ieee_modified_type *modified;
3850 /* Number of entries allocated in modified. */
3851 unsigned int modified_alloc;
3852 /* 4 byte complex type. */
3853 unsigned int complex_float_index;
3854 /* 8 byte complex type. */
3855 unsigned int complex_double_index;
3856 /* The depth of block nesting. This is 0 outside a function, and 1
3857 just after start_function is called. */
3858 unsigned int block_depth;
3859 /* The name of the current function. */
3861 /* List of buffers for the type of the function we are currently
3863 struct ieee_buflist fntype;
3864 /* List of buffers for the parameters of the function we are
3865 currently writing out. */
3866 struct ieee_buflist fnargs;
3867 /* Number of arguments written to fnargs. */
3868 unsigned int fnargcount;
3869 /* Pending function parameters. */
3870 struct ieee_pending_parm *pending_parms;
3871 /* Current line number filename. */
3872 const char *lineno_filename;
3873 /* Line number name index. */
3874 unsigned int lineno_name_indx;
3875 /* Filename of pending line number. */
3876 const char *pending_lineno_filename;
3877 /* Pending line number. */
3878 unsigned long pending_lineno;
3879 /* Address of pending line number. */
3880 bfd_vma pending_lineno_addr;
3881 /* Highest address seen at end of procedure. */
3885 static bfd_boolean ieee_init_buffer
3886 (struct ieee_handle *, struct ieee_buflist *);
3887 static bfd_boolean ieee_change_buffer
3888 (struct ieee_handle *, struct ieee_buflist *);
3889 static bfd_boolean ieee_append_buffer
3890 (struct ieee_handle *, struct ieee_buflist *, struct ieee_buflist *);
3891 static bfd_boolean ieee_real_write_byte (struct ieee_handle *, int);
3892 static bfd_boolean ieee_write_2bytes (struct ieee_handle *, int);
3893 static bfd_boolean ieee_write_number (struct ieee_handle *, bfd_vma);
3894 static bfd_boolean ieee_write_id (struct ieee_handle *, const char *);
3895 static bfd_boolean ieee_write_asn
3896 (struct ieee_handle *, unsigned int, bfd_vma);
3897 static bfd_boolean ieee_write_atn65
3898 (struct ieee_handle *, unsigned int, const char *);
3899 static bfd_boolean ieee_push_type
3900 (struct ieee_handle *, unsigned int, unsigned int, bfd_boolean,
3902 static unsigned int ieee_pop_type (struct ieee_handle *);
3903 static void ieee_pop_unused_type (struct ieee_handle *);
3904 static unsigned int ieee_pop_type_used (struct ieee_handle *, bfd_boolean);
3905 static bfd_boolean ieee_add_range
3906 (struct ieee_handle *, bfd_boolean, bfd_vma, bfd_vma);
3907 static bfd_boolean ieee_start_range (struct ieee_handle *, bfd_vma);
3908 static bfd_boolean ieee_end_range (struct ieee_handle *, bfd_vma);
3909 static bfd_boolean ieee_define_type
3910 (struct ieee_handle *, unsigned int, bfd_boolean, bfd_boolean);
3911 static bfd_boolean ieee_define_named_type
3912 (struct ieee_handle *, const char *, unsigned int, unsigned int,
3913 bfd_boolean, bfd_boolean, struct ieee_buflist *);
3914 static struct ieee_modified_type *ieee_get_modified_info
3915 (struct ieee_handle *, unsigned int);
3916 static struct bfd_hash_entry *ieee_name_type_newfunc
3917 (struct bfd_hash_entry *, struct bfd_hash_table *, const char *);
3918 static bfd_boolean ieee_write_undefined_tag
3919 (struct ieee_name_type_hash_entry *, void *);
3920 static bfd_boolean ieee_finish_compilation_unit (struct ieee_handle *);
3921 static void ieee_add_bb11_blocks (bfd *, asection *, void *);
3922 static bfd_boolean ieee_add_bb11
3923 (struct ieee_handle *, asection *, bfd_vma, bfd_vma);
3924 static bfd_boolean ieee_output_pending_parms (struct ieee_handle *);
3925 static unsigned int ieee_vis_to_flags (enum debug_visibility);
3926 static bfd_boolean ieee_class_method_var
3927 (struct ieee_handle *, const char *, enum debug_visibility, bfd_boolean,
3928 bfd_boolean, bfd_boolean, bfd_vma, bfd_boolean);
3930 static bfd_boolean ieee_start_compilation_unit (void *, const char *);
3931 static bfd_boolean ieee_start_source (void *, const char *);
3932 static bfd_boolean ieee_empty_type (void *);
3933 static bfd_boolean ieee_void_type (void *);
3934 static bfd_boolean ieee_int_type (void *, unsigned int, bfd_boolean);
3935 static bfd_boolean ieee_float_type (void *, unsigned int);
3936 static bfd_boolean ieee_complex_type (void *, unsigned int);
3937 static bfd_boolean ieee_bool_type (void *, unsigned int);
3938 static bfd_boolean ieee_enum_type
3939 (void *, const char *, const char **, bfd_signed_vma *);
3940 static bfd_boolean ieee_pointer_type (void *);
3941 static bfd_boolean ieee_function_type (void *, int, bfd_boolean);
3942 static bfd_boolean ieee_reference_type (void *);
3943 static bfd_boolean ieee_range_type (void *, bfd_signed_vma, bfd_signed_vma);
3944 static bfd_boolean ieee_array_type
3945 (void *, bfd_signed_vma, bfd_signed_vma, bfd_boolean);
3946 static bfd_boolean ieee_set_type (void *, bfd_boolean);
3947 static bfd_boolean ieee_offset_type (void *);
3948 static bfd_boolean ieee_method_type (void *, bfd_boolean, int, bfd_boolean);
3949 static bfd_boolean ieee_const_type (void *);
3950 static bfd_boolean ieee_volatile_type (void *);
3951 static bfd_boolean ieee_start_struct_type
3952 (void *, const char *, unsigned int, bfd_boolean, unsigned int);
3953 static bfd_boolean ieee_struct_field
3954 (void *, const char *, bfd_vma, bfd_vma, enum debug_visibility);
3955 static bfd_boolean ieee_end_struct_type (void *);
3956 static bfd_boolean ieee_start_class_type
3957 (void *, const char *, unsigned int, bfd_boolean, unsigned int, bfd_boolean,
3959 static bfd_boolean ieee_class_static_member
3960 (void *, const char *, const char *, enum debug_visibility);
3961 static bfd_boolean ieee_class_baseclass
3962 (void *, bfd_vma, bfd_boolean, enum debug_visibility);
3963 static bfd_boolean ieee_class_start_method (void *, const char *);
3964 static bfd_boolean ieee_class_method_variant
3965 (void *, const char *, enum debug_visibility, bfd_boolean, bfd_boolean,
3966 bfd_vma, bfd_boolean);
3967 static bfd_boolean ieee_class_static_method_variant
3968 (void *, const char *, enum debug_visibility, bfd_boolean, bfd_boolean);
3969 static bfd_boolean ieee_class_end_method (void *);
3970 static bfd_boolean ieee_end_class_type (void *);
3971 static bfd_boolean ieee_typedef_type (void *, const char *);
3972 static bfd_boolean ieee_tag_type
3973 (void *, const char *, unsigned int, enum debug_type_kind);
3974 static bfd_boolean ieee_typdef (void *, const char *);
3975 static bfd_boolean ieee_tag (void *, const char *);
3976 static bfd_boolean ieee_int_constant (void *, const char *, bfd_vma);
3977 static bfd_boolean ieee_float_constant (void *, const char *, double);
3978 static bfd_boolean ieee_typed_constant (void *, const char *, bfd_vma);
3979 static bfd_boolean ieee_variable
3980 (void *, const char *, enum debug_var_kind, bfd_vma);
3981 static bfd_boolean ieee_start_function (void *, const char *, bfd_boolean);
3982 static bfd_boolean ieee_function_parameter
3983 (void *, const char *, enum debug_parm_kind, bfd_vma);
3984 static bfd_boolean ieee_start_block (void *, bfd_vma);
3985 static bfd_boolean ieee_end_block (void *, bfd_vma);
3986 static bfd_boolean ieee_end_function (void *);
3987 static bfd_boolean ieee_lineno (void *, const char *, unsigned long, bfd_vma);
3989 static const struct debug_write_fns ieee_fns =
3991 ieee_start_compilation_unit,
4002 ieee_reference_type,
4010 ieee_start_struct_type,
4012 ieee_end_struct_type,
4013 ieee_start_class_type,
4014 ieee_class_static_member,
4015 ieee_class_baseclass,
4016 ieee_class_start_method,
4017 ieee_class_method_variant,
4018 ieee_class_static_method_variant,
4019 ieee_class_end_method,
4020 ieee_end_class_type,
4026 ieee_float_constant,
4027 ieee_typed_constant,
4029 ieee_start_function,
4030 ieee_function_parameter,
4037 /* Initialize a buffer to be empty. */
4040 ieee_init_buffer (struct ieee_handle *info ATTRIBUTE_UNUSED,
4041 struct ieee_buflist *buflist)
4043 buflist->head = NULL;
4044 buflist->tail = NULL;
4048 /* See whether a buffer list has any data. */
4050 #define ieee_buffer_emptyp(buflist) ((buflist)->head == NULL)
4052 /* Change the current buffer to a specified buffer chain. */
4055 ieee_change_buffer (struct ieee_handle *info, struct ieee_buflist *buflist)
4057 if (buflist->head == NULL)
4059 struct ieee_buf *buf;
4061 buf = (struct ieee_buf *) xmalloc (sizeof *buf);
4064 buflist->head = buf;
4065 buflist->tail = buf;
4068 info->current = buflist;
4069 info->curbuf = buflist->tail;
4074 /* Append a buffer chain. */
4077 ieee_append_buffer (struct ieee_handle *info ATTRIBUTE_UNUSED,
4078 struct ieee_buflist *mainbuf,
4079 struct ieee_buflist *newbuf)
4081 if (newbuf->head != NULL)
4083 if (mainbuf->head == NULL)
4084 mainbuf->head = newbuf->head;
4086 mainbuf->tail->next = newbuf->head;
4087 mainbuf->tail = newbuf->tail;
4092 /* Write a byte into the buffer. We use a macro for speed and a
4093 function for the complex cases. */
4095 #define ieee_write_byte(info, b) \
4096 ((info)->curbuf->c < IEEE_BUFSIZE \
4097 ? ((info)->curbuf->buf[(info)->curbuf->c++] = (b), TRUE) \
4098 : ieee_real_write_byte ((info), (b)))
4101 ieee_real_write_byte (struct ieee_handle *info, int b)
4103 if (info->curbuf->c >= IEEE_BUFSIZE)
4107 n = (struct ieee_buf *) xmalloc (sizeof *n);
4110 if (info->current->head == NULL)
4111 info->current->head = n;
4113 info->current->tail->next = n;
4114 info->current->tail = n;
4118 info->curbuf->buf[info->curbuf->c] = b;
4124 /* Write out two bytes. */
4127 ieee_write_2bytes (struct ieee_handle *info, int i)
4129 return (ieee_write_byte (info, i >> 8)
4130 && ieee_write_byte (info, i & 0xff));
4133 /* Write out an integer. */
4136 ieee_write_number (struct ieee_handle *info, bfd_vma v)
4143 if (v <= (bfd_vma) ieee_number_end_enum)
4144 return ieee_write_byte (info, (int) v);
4155 if (c > (unsigned int) (ieee_number_repeat_end_enum
4156 - ieee_number_repeat_start_enum))
4158 fprintf (stderr, _("IEEE numeric overflow: 0x"));
4159 fprintf_vma (stderr, v);
4160 fprintf (stderr, "\n");
4164 if (! ieee_write_byte (info, (int) ieee_number_repeat_start_enum + c))
4166 for (; c > 0; --c, ++p)
4168 if (! ieee_write_byte (info, *p))
4175 /* Write out a string. */
4178 ieee_write_id (struct ieee_handle *info, const char *s)
4185 if (! ieee_write_byte (info, len))
4188 else if (len <= 0xff)
4190 if (! ieee_write_byte (info, (int) ieee_extension_length_1_enum)
4191 || ! ieee_write_byte (info, len))
4194 else if (len <= 0xffff)
4196 if (! ieee_write_byte (info, (int) ieee_extension_length_2_enum)
4197 || ! ieee_write_2bytes (info, len))
4202 fprintf (stderr, _("IEEE string length overflow: %u\n"), len);
4206 for (; *s != '\0'; s++)
4207 if (! ieee_write_byte (info, *s))
4213 /* Write out an ASN record. */
4216 ieee_write_asn (struct ieee_handle *info, unsigned int indx, bfd_vma val)
4218 return (ieee_write_2bytes (info, (int) ieee_asn_record_enum)
4219 && ieee_write_number (info, indx)
4220 && ieee_write_number (info, val));
4223 /* Write out an ATN65 record. */
4226 ieee_write_atn65 (struct ieee_handle *info, unsigned int indx, const char *s)
4228 return (ieee_write_2bytes (info, (int) ieee_atn_record_enum)
4229 && ieee_write_number (info, indx)
4230 && ieee_write_number (info, 0)
4231 && ieee_write_number (info, 65)
4232 && ieee_write_id (info, s));
4235 /* Push a type index onto the type stack. */
4238 ieee_push_type (struct ieee_handle *info, unsigned int indx,
4239 unsigned int size, bfd_boolean unsignedp, bfd_boolean localp)
4241 struct ieee_type_stack *ts;
4243 ts = (struct ieee_type_stack *) xmalloc (sizeof *ts);
4244 memset (ts, 0, sizeof *ts);
4246 ts->type.indx = indx;
4247 ts->type.size = size;
4248 ts->type.unsignedp = unsignedp;
4249 ts->type.localp = localp;
4251 ts->next = info->type_stack;
4252 info->type_stack = ts;
4257 /* Pop a type index off the type stack. */
4260 ieee_pop_type (struct ieee_handle *info)
4262 return ieee_pop_type_used (info, TRUE);
4265 /* Pop an unused type index off the type stack. */
4268 ieee_pop_unused_type (struct ieee_handle *info)
4270 (void) ieee_pop_type_used (info, FALSE);
4273 /* Pop a used or unused type index off the type stack. */
4276 ieee_pop_type_used (struct ieee_handle *info, bfd_boolean used)
4278 struct ieee_type_stack *ts;
4281 ts = info->type_stack;
4282 assert (ts != NULL);
4284 /* If this is a function type, and we need it, we need to append the
4285 actual definition to the typedef block now. */
4286 if (used && ! ieee_buffer_emptyp (&ts->type.fndef))
4288 struct ieee_buflist *buflist;
4290 if (ts->type.localp)
4292 /* Make sure we have started the types block. */
4293 if (ieee_buffer_emptyp (&info->types))
4295 if (! ieee_change_buffer (info, &info->types)
4296 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
4297 || ! ieee_write_byte (info, 1)
4298 || ! ieee_write_number (info, 0)
4299 || ! ieee_write_id (info, info->modname))
4302 buflist = &info->types;
4306 /* Make sure we started the global type block. */
4307 if (ieee_buffer_emptyp (&info->global_types))
4309 if (! ieee_change_buffer (info, &info->global_types)
4310 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
4311 || ! ieee_write_byte (info, 2)
4312 || ! ieee_write_number (info, 0)
4313 || ! ieee_write_id (info, ""))
4316 buflist = &info->global_types;
4319 if (! ieee_append_buffer (info, buflist, &ts->type.fndef))
4323 ret = ts->type.indx;
4324 info->type_stack = ts->next;
4329 /* Add a range of bytes included in the current compilation unit. */
4332 ieee_add_range (struct ieee_handle *info, bfd_boolean global, bfd_vma low,
4335 struct ieee_range **plist, *r, **pr;
4337 if (low == (bfd_vma) -1 || high == (bfd_vma) -1 || low == high)
4341 plist = &info->global_ranges;
4343 plist = &info->ranges;
4345 for (r = *plist; r != NULL; r = r->next)
4347 if (high >= r->low && low <= r->high)
4349 /* The new range overlaps r. */
4355 while (*pr != NULL && (*pr)->low <= r->high)
4357 struct ieee_range *n;
4359 if ((*pr)->high > r->high)
4360 r->high = (*pr)->high;
4369 r = (struct ieee_range *) xmalloc (sizeof *r);
4370 memset (r, 0, sizeof *r);
4375 /* Store the ranges sorted by address. */
4376 for (pr = plist; *pr != NULL; pr = &(*pr)->next)
4377 if ((*pr)->low > high)
4385 /* Start a new range for which we only have the low address. */
4388 ieee_start_range (struct ieee_handle *info, bfd_vma low)
4390 struct ieee_range *r;
4392 r = (struct ieee_range *) xmalloc (sizeof *r);
4393 memset (r, 0, sizeof *r);
4395 r->next = info->pending_ranges;
4396 info->pending_ranges = r;
4400 /* Finish a range started by ieee_start_range. */
4403 ieee_end_range (struct ieee_handle *info, bfd_vma high)
4405 struct ieee_range *r;
4408 assert (info->pending_ranges != NULL);
4409 r = info->pending_ranges;
4411 info->pending_ranges = r->next;
4413 return ieee_add_range (info, FALSE, low, high);
4416 /* Start defining a type. */
4419 ieee_define_type (struct ieee_handle *info, unsigned int size,
4420 bfd_boolean unsignedp, bfd_boolean localp)
4422 return ieee_define_named_type (info, (const char *) NULL,
4423 (unsigned int) -1, size, unsignedp,
4424 localp, (struct ieee_buflist *) NULL);
4427 /* Start defining a named type. */
4430 ieee_define_named_type (struct ieee_handle *info, const char *name,
4431 unsigned int indx, unsigned int size,
4432 bfd_boolean unsignedp, bfd_boolean localp,
4433 struct ieee_buflist *buflist)
4435 unsigned int type_indx;
4436 unsigned int name_indx;
4438 if (indx != (unsigned int) -1)
4442 type_indx = info->type_indx;
4446 name_indx = info->name_indx;
4452 /* If we were given a buffer, use it; otherwise, use either the
4453 local or the global type information, and make sure that the type
4454 block is started. */
4455 if (buflist != NULL)
4457 if (! ieee_change_buffer (info, buflist))
4462 if (! ieee_buffer_emptyp (&info->types))
4464 if (! ieee_change_buffer (info, &info->types))
4469 if (! ieee_change_buffer (info, &info->types)
4470 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
4471 || ! ieee_write_byte (info, 1)
4472 || ! ieee_write_number (info, 0)
4473 || ! ieee_write_id (info, info->modname))
4479 if (! ieee_buffer_emptyp (&info->global_types))
4481 if (! ieee_change_buffer (info, &info->global_types))
4486 if (! ieee_change_buffer (info, &info->global_types)
4487 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
4488 || ! ieee_write_byte (info, 2)
4489 || ! ieee_write_number (info, 0)
4490 || ! ieee_write_id (info, ""))
4495 /* Push the new type on the type stack, write out an NN record, and
4496 write out the start of a TY record. The caller will then finish
4498 if (! ieee_push_type (info, type_indx, size, unsignedp, localp))
4501 return (ieee_write_byte (info, (int) ieee_nn_record)
4502 && ieee_write_number (info, name_indx)
4503 && ieee_write_id (info, name)
4504 && ieee_write_byte (info, (int) ieee_ty_record_enum)
4505 && ieee_write_number (info, type_indx)
4506 && ieee_write_byte (info, 0xce)
4507 && ieee_write_number (info, name_indx));
4510 /* Get an entry to the list of modified versions of a type. */
4512 static struct ieee_modified_type *
4513 ieee_get_modified_info (struct ieee_handle *info, unsigned int indx)
4515 if (indx >= info->modified_alloc)
4517 unsigned int nalloc;
4519 nalloc = info->modified_alloc;
4522 while (indx >= nalloc)
4524 info->modified = ((struct ieee_modified_type *)
4525 xrealloc (info->modified,
4526 nalloc * sizeof *info->modified));
4527 memset (info->modified + info->modified_alloc, 0,
4528 (nalloc - info->modified_alloc) * sizeof *info->modified);
4529 info->modified_alloc = nalloc;
4532 return info->modified + indx;
4535 /* Routines for the hash table mapping names to types. */
4537 /* Initialize an entry in the hash table. */
4539 static struct bfd_hash_entry *
4540 ieee_name_type_newfunc (struct bfd_hash_entry *entry,
4541 struct bfd_hash_table *table, const char *string)
4543 struct ieee_name_type_hash_entry *ret =
4544 (struct ieee_name_type_hash_entry *) entry;
4546 /* Allocate the structure if it has not already been allocated by a
4549 ret = ((struct ieee_name_type_hash_entry *)
4550 bfd_hash_allocate (table, sizeof *ret));
4554 /* Call the allocation method of the superclass. */
4555 ret = ((struct ieee_name_type_hash_entry *)
4556 bfd_hash_newfunc ((struct bfd_hash_entry *) ret, table, string));
4559 /* Set local fields. */
4563 return (struct bfd_hash_entry *) ret;
4566 /* Look up an entry in the hash table. */
4568 #define ieee_name_type_hash_lookup(table, string, create, copy) \
4569 ((struct ieee_name_type_hash_entry *) \
4570 bfd_hash_lookup (&(table)->root, (string), (create), (copy)))
4572 /* Traverse the hash table. */
4574 #define ieee_name_type_hash_traverse(table, func, info) \
4575 (bfd_hash_traverse \
4577 (bfd_boolean (*) (struct bfd_hash_entry *, void *)) (func), \
4580 /* The general routine to write out IEEE debugging information. */
4583 write_ieee_debugging_info (bfd *abfd, void *dhandle)
4585 struct ieee_handle info;
4590 memset (&info, 0, sizeof info);
4592 info.type_indx = 256;
4593 info.name_indx = 32;
4595 if (!bfd_hash_table_init (&info.typedefs.root, ieee_name_type_newfunc,
4596 sizeof (struct ieee_name_type_hash_entry))
4597 || !bfd_hash_table_init (&info.tags.root, ieee_name_type_newfunc,
4598 sizeof (struct ieee_name_type_hash_entry)))
4601 if (! ieee_init_buffer (&info, &info.global_types)
4602 || ! ieee_init_buffer (&info, &info.data)
4603 || ! ieee_init_buffer (&info, &info.types)
4604 || ! ieee_init_buffer (&info, &info.vars)
4605 || ! ieee_init_buffer (&info, &info.cxx)
4606 || ! ieee_init_buffer (&info, &info.linenos)
4607 || ! ieee_init_buffer (&info, &info.fntype)
4608 || ! ieee_init_buffer (&info, &info.fnargs))
4611 if (! debug_write (dhandle, &ieee_fns, (void *) &info))
4614 if (info.filename != NULL)
4616 if (! ieee_finish_compilation_unit (&info))
4620 /* Put any undefined tags in the global typedef information. */
4622 ieee_name_type_hash_traverse (&info.tags,
4623 ieee_write_undefined_tag,
4628 /* Prepend the global typedef information to the other data. */
4629 if (! ieee_buffer_emptyp (&info.global_types))
4631 /* The HP debugger seems to have a bug in which it ignores the
4632 last entry in the global types, so we add a dummy entry. */
4633 if (! ieee_change_buffer (&info, &info.global_types)
4634 || ! ieee_write_byte (&info, (int) ieee_nn_record)
4635 || ! ieee_write_number (&info, info.name_indx)
4636 || ! ieee_write_id (&info, "")
4637 || ! ieee_write_byte (&info, (int) ieee_ty_record_enum)
4638 || ! ieee_write_number (&info, info.type_indx)
4639 || ! ieee_write_byte (&info, 0xce)
4640 || ! ieee_write_number (&info, info.name_indx)
4641 || ! ieee_write_number (&info, 'P')
4642 || ! ieee_write_number (&info, (int) builtin_void + 32)
4643 || ! ieee_write_byte (&info, (int) ieee_be_record_enum))
4646 if (! ieee_append_buffer (&info, &info.global_types, &info.data))
4648 info.data = info.global_types;
4651 /* Make sure that we have declare BB11 blocks for each range in the
4652 file. They are added to info->vars. */
4654 if (! ieee_init_buffer (&info, &info.vars))
4656 bfd_map_over_sections (abfd, ieee_add_bb11_blocks, (void *) &info);
4659 if (! ieee_buffer_emptyp (&info.vars))
4661 if (! ieee_change_buffer (&info, &info.vars)
4662 || ! ieee_write_byte (&info, (int) ieee_be_record_enum))
4665 if (! ieee_append_buffer (&info, &info.data, &info.vars))
4669 /* Now all the data is in info.data. Write it out to the BFD. We
4670 normally would need to worry about whether all the other sections
4671 are set up yet, but the IEEE backend will handle this particular
4672 case correctly regardless. */
4673 if (ieee_buffer_emptyp (&info.data))
4675 /* There is no debugging information. */
4679 s = bfd_make_section_with_flags (abfd, ".debug",
4680 SEC_DEBUGGING | SEC_HAS_CONTENTS);
4682 err = "bfd_make_section";
4688 for (b = info.data.head; b != NULL; b = b->next)
4690 if (! bfd_set_section_size (abfd, s, size))
4691 err = "bfd_set_section_size";
4698 for (b = info.data.head; b != NULL; b = b->next)
4700 if (! bfd_set_section_contents (abfd, s, b->buf, offset, b->c))
4702 err = "bfd_set_section_contents";
4711 fprintf (stderr, "%s: %s: %s\n", bfd_get_filename (abfd), err,
4712 bfd_errmsg (bfd_get_error ()));
4716 bfd_hash_table_free (&info.typedefs.root);
4717 bfd_hash_table_free (&info.tags.root);
4722 /* Write out information for an undefined tag. This is called via
4723 ieee_name_type_hash_traverse. */
4726 ieee_write_undefined_tag (struct ieee_name_type_hash_entry *h, void *p)
4728 struct ieee_handle *info = (struct ieee_handle *) p;
4729 struct ieee_name_type *nt;
4731 for (nt = h->types; nt != NULL; nt = nt->next)
4733 unsigned int name_indx;
4736 if (nt->kind == DEBUG_KIND_ILLEGAL)
4739 if (ieee_buffer_emptyp (&info->global_types))
4741 if (! ieee_change_buffer (info, &info->global_types)
4742 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
4743 || ! ieee_write_byte (info, 2)
4744 || ! ieee_write_number (info, 0)
4745 || ! ieee_write_id (info, ""))
4753 if (! ieee_change_buffer (info, &info->global_types))
4760 name_indx = info->name_indx;
4762 if (! ieee_write_byte (info, (int) ieee_nn_record)
4763 || ! ieee_write_number (info, name_indx)
4764 || ! ieee_write_id (info, nt->type.name)
4765 || ! ieee_write_byte (info, (int) ieee_ty_record_enum)
4766 || ! ieee_write_number (info, nt->type.indx)
4767 || ! ieee_write_byte (info, 0xce)
4768 || ! ieee_write_number (info, name_indx))
4780 case DEBUG_KIND_STRUCT:
4781 case DEBUG_KIND_CLASS:
4784 case DEBUG_KIND_UNION:
4785 case DEBUG_KIND_UNION_CLASS:
4788 case DEBUG_KIND_ENUM:
4792 if (! ieee_write_number (info, code)
4793 || ! ieee_write_number (info, 0))
4803 /* Start writing out information for a compilation unit. */
4806 ieee_start_compilation_unit (void *p, const char *filename)
4808 struct ieee_handle *info = (struct ieee_handle *) p;
4809 const char *modname;
4810 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
4811 const char *backslash;
4816 if (info->filename != NULL)
4818 if (! ieee_finish_compilation_unit (info))
4822 info->filename = filename;
4823 modname = strrchr (filename, '/');
4824 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
4825 /* We could have a mixed forward/back slash case. */
4826 backslash = strrchr (filename, '\\');
4827 if (modname == NULL || (backslash != NULL && backslash > modname))
4828 modname = backslash;
4831 if (modname != NULL)
4833 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
4834 else if (filename[0] && filename[1] == ':')
4835 modname = filename + 2;
4840 c = xstrdup (modname);
4841 s = strrchr (c, '.');
4846 if (! ieee_init_buffer (info, &info->types)
4847 || ! ieee_init_buffer (info, &info->vars)
4848 || ! ieee_init_buffer (info, &info->cxx)
4849 || ! ieee_init_buffer (info, &info->linenos))
4851 info->ranges = NULL;
4853 /* Always include a BB1 and a BB3 block. That is what the output of
4854 the MRI linker seems to look like. */
4855 if (! ieee_change_buffer (info, &info->types)
4856 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
4857 || ! ieee_write_byte (info, 1)
4858 || ! ieee_write_number (info, 0)
4859 || ! ieee_write_id (info, info->modname))
4862 nindx = info->name_indx;
4864 if (! ieee_change_buffer (info, &info->vars)
4865 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
4866 || ! ieee_write_byte (info, 3)
4867 || ! ieee_write_number (info, 0)
4868 || ! ieee_write_id (info, info->modname))
4874 /* Finish up a compilation unit. */
4877 ieee_finish_compilation_unit (struct ieee_handle *info)
4879 struct ieee_range *r;
4881 if (! ieee_buffer_emptyp (&info->types))
4883 if (! ieee_change_buffer (info, &info->types)
4884 || ! ieee_write_byte (info, (int) ieee_be_record_enum))
4888 if (! ieee_buffer_emptyp (&info->cxx))
4890 /* Append any C++ information to the global function and
4891 variable information. */
4892 assert (! ieee_buffer_emptyp (&info->vars));
4893 if (! ieee_change_buffer (info, &info->vars))
4896 /* We put the pmisc records in a dummy procedure, just as the
4897 MRI compiler does. */
4898 if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
4899 || ! ieee_write_byte (info, 6)
4900 || ! ieee_write_number (info, 0)
4901 || ! ieee_write_id (info, "__XRYCPP")
4902 || ! ieee_write_number (info, 0)
4903 || ! ieee_write_number (info, 0)
4904 || ! ieee_write_number (info, info->highaddr - 1)
4905 || ! ieee_append_buffer (info, &info->vars, &info->cxx)
4906 || ! ieee_change_buffer (info, &info->vars)
4907 || ! ieee_write_byte (info, (int) ieee_be_record_enum)
4908 || ! ieee_write_number (info, info->highaddr - 1))
4912 if (! ieee_buffer_emptyp (&info->vars))
4914 if (! ieee_change_buffer (info, &info->vars)
4915 || ! ieee_write_byte (info, (int) ieee_be_record_enum))
4919 if (info->pending_lineno_filename != NULL)
4921 /* Force out the pending line number. */
4922 if (! ieee_lineno ((void *) info, (const char *) NULL, 0, (bfd_vma) -1))
4925 if (! ieee_buffer_emptyp (&info->linenos))
4927 if (! ieee_change_buffer (info, &info->linenos)
4928 || ! ieee_write_byte (info, (int) ieee_be_record_enum))
4930 if (strcmp (info->filename, info->lineno_filename) != 0)
4932 /* We were not in the main file. We just closed the
4933 included line number block, and now we must close the
4934 main line number block. */
4935 if (! ieee_write_byte (info, (int) ieee_be_record_enum))
4940 if (! ieee_append_buffer (info, &info->data, &info->types)
4941 || ! ieee_append_buffer (info, &info->data, &info->vars)
4942 || ! ieee_append_buffer (info, &info->data, &info->linenos))
4945 /* Build BB10/BB11 blocks based on the ranges we recorded. */
4946 if (! ieee_change_buffer (info, &info->data))
4949 if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
4950 || ! ieee_write_byte (info, 10)
4951 || ! ieee_write_number (info, 0)
4952 || ! ieee_write_id (info, info->modname)
4953 || ! ieee_write_id (info, "")
4954 || ! ieee_write_number (info, 0)
4955 || ! ieee_write_id (info, "GNU objcopy"))
4958 for (r = info->ranges; r != NULL; r = r->next)
4967 /* Find the section corresponding to this range. */
4968 for (s = info->abfd->sections; s != NULL; s = s->next)
4970 if (bfd_get_section_vma (info->abfd, s) <= low
4971 && high <= (bfd_get_section_vma (info->abfd, s)
4972 + bfd_section_size (info->abfd, s)))
4978 /* Just ignore this range. */
4982 /* Coalesce ranges if it seems reasonable. */
4983 while (r->next != NULL
4984 && high + 0x1000 >= r->next->low
4986 <= (bfd_get_section_vma (info->abfd, s)
4987 + bfd_section_size (info->abfd, s))))
4993 if ((s->flags & SEC_CODE) != 0)
4995 else if ((s->flags & SEC_READONLY) != 0)
5000 if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
5001 || ! ieee_write_byte (info, 11)
5002 || ! ieee_write_number (info, 0)
5003 || ! ieee_write_id (info, "")
5004 || ! ieee_write_number (info, kind)
5005 || ! ieee_write_number (info, s->index + IEEE_SECTION_NUMBER_BASE)
5006 || ! ieee_write_number (info, low)
5007 || ! ieee_write_byte (info, (int) ieee_be_record_enum)
5008 || ! ieee_write_number (info, high - low))
5011 /* Add this range to the list of global ranges. */
5012 if (! ieee_add_range (info, TRUE, low, high))
5016 if (! ieee_write_byte (info, (int) ieee_be_record_enum))
5022 /* Add BB11 blocks describing each range that we have not already
5026 ieee_add_bb11_blocks (bfd *abfd ATTRIBUTE_UNUSED, asection *sec, void *data)
5028 struct ieee_handle *info = (struct ieee_handle *) data;
5030 struct ieee_range *r;
5032 low = bfd_get_section_vma (abfd, sec);
5033 high = low + bfd_section_size (abfd, sec);
5035 /* Find the first range at or after this section. The ranges are
5036 sorted by address. */
5037 for (r = info->global_ranges; r != NULL; r = r->next)
5043 if (r == NULL || r->low >= high)
5045 if (! ieee_add_bb11 (info, sec, low, high))
5051 && r->low - low > 0x100)
5053 if (! ieee_add_bb11 (info, sec, low, r->low))
5065 /* Add a single BB11 block for a range. We add it to info->vars. */
5068 ieee_add_bb11 (struct ieee_handle *info, asection *sec, bfd_vma low,
5073 if (! ieee_buffer_emptyp (&info->vars))
5075 if (! ieee_change_buffer (info, &info->vars))
5080 const char *filename, *modname;
5081 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
5082 const char *backslash;
5086 /* Start the enclosing BB10 block. */
5087 filename = bfd_get_filename (info->abfd);
5088 modname = strrchr (filename, '/');
5089 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
5090 backslash = strrchr (filename, '\\');
5091 if (modname == NULL || (backslash != NULL && backslash > modname))
5092 modname = backslash;
5095 if (modname != NULL)
5097 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
5098 else if (filename[0] && filename[1] == ':')
5099 modname = filename + 2;
5104 c = xstrdup (modname);
5105 s = strrchr (c, '.');
5109 if (! ieee_change_buffer (info, &info->vars)
5110 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
5111 || ! ieee_write_byte (info, 10)
5112 || ! ieee_write_number (info, 0)
5113 || ! ieee_write_id (info, c)
5114 || ! ieee_write_id (info, "")
5115 || ! ieee_write_number (info, 0)
5116 || ! ieee_write_id (info, "GNU objcopy"))
5122 if ((sec->flags & SEC_CODE) != 0)
5124 else if ((sec->flags & SEC_READONLY) != 0)
5129 if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
5130 || ! ieee_write_byte (info, 11)
5131 || ! ieee_write_number (info, 0)
5132 || ! ieee_write_id (info, "")
5133 || ! ieee_write_number (info, kind)
5134 || ! ieee_write_number (info, sec->index + IEEE_SECTION_NUMBER_BASE)
5135 || ! ieee_write_number (info, low)
5136 || ! ieee_write_byte (info, (int) ieee_be_record_enum)
5137 || ! ieee_write_number (info, high - low))
5143 /* Start recording information from a particular source file. This is
5144 used to record which file defined which types, variables, etc. It
5145 is not used for line numbers, since the lineno entry point passes
5146 down the file name anyhow. IEEE debugging information doesn't seem
5147 to store this information anywhere. */
5150 ieee_start_source (void *p ATTRIBUTE_UNUSED,
5151 const char *filename ATTRIBUTE_UNUSED)
5156 /* Make an empty type. */
5159 ieee_empty_type (void *p)
5161 struct ieee_handle *info = (struct ieee_handle *) p;
5163 return ieee_push_type (info, (int) builtin_unknown, 0, FALSE, FALSE);
5166 /* Make a void type. */
5169 ieee_void_type (void *p)
5171 struct ieee_handle *info = (struct ieee_handle *) p;
5173 return ieee_push_type (info, (int) builtin_void, 0, FALSE, FALSE);
5176 /* Make an integer type. */
5179 ieee_int_type (void *p, unsigned int size, bfd_boolean unsignedp)
5181 struct ieee_handle *info = (struct ieee_handle *) p;
5187 indx = (int) builtin_signed_char;
5190 indx = (int) builtin_signed_short_int;
5193 indx = (int) builtin_signed_long;
5196 indx = (int) builtin_signed_long_long;
5199 fprintf (stderr, _("IEEE unsupported integer type size %u\n"), size);
5206 return ieee_push_type (info, indx, size, unsignedp, FALSE);
5209 /* Make a floating point type. */
5212 ieee_float_type (void *p, unsigned int size)
5214 struct ieee_handle *info = (struct ieee_handle *) p;
5220 indx = (int) builtin_float;
5223 indx = (int) builtin_double;
5226 /* FIXME: This size really depends upon the processor. */
5227 indx = (int) builtin_long_double;
5230 indx = (int) builtin_long_long_double;
5233 fprintf (stderr, _("IEEE unsupported float type size %u\n"), size);
5237 return ieee_push_type (info, indx, size, FALSE, FALSE);
5240 /* Make a complex type. */
5243 ieee_complex_type (void *p, unsigned int size)
5245 struct ieee_handle *info = (struct ieee_handle *) p;
5251 if (info->complex_float_index != 0)
5252 return ieee_push_type (info, info->complex_float_index, size * 2,
5258 /* These cases can be output by gcc -gstabs. Outputting the
5259 wrong type is better than crashing. */
5261 if (info->complex_double_index != 0)
5262 return ieee_push_type (info, info->complex_double_index, size * 2,
5267 fprintf (stderr, _("IEEE unsupported complex type size %u\n"), size);
5271 /* FIXME: I don't know what the string is for. */
5272 if (! ieee_define_type (info, size * 2, FALSE, FALSE)
5273 || ! ieee_write_number (info, code)
5274 || ! ieee_write_id (info, ""))
5278 info->complex_float_index = info->type_stack->type.indx;
5280 info->complex_double_index = info->type_stack->type.indx;
5285 /* Make a boolean type. IEEE doesn't support these, so we just make
5286 an integer type instead. */
5289 ieee_bool_type (void *p, unsigned int size)
5291 return ieee_int_type (p, size, TRUE);
5294 /* Make an enumeration. */
5297 ieee_enum_type (void *p, const char *tag, const char **names,
5298 bfd_signed_vma *vals)
5300 struct ieee_handle *info = (struct ieee_handle *) p;
5301 struct ieee_defined_enum *e;
5302 bfd_boolean localp, simple;
5307 indx = (unsigned int) -1;
5308 for (e = info->enums; e != NULL; e = e->next)
5318 || tag[0] != e->tag[0]
5319 || strcmp (tag, e->tag) != 0)
5325 /* This enum tag has been seen but not defined. */
5330 if (names != NULL && e->names != NULL)
5332 for (i = 0; names[i] != NULL && e->names[i] != NULL; i++)
5334 if (names[i][0] != e->names[i][0]
5335 || vals[i] != e->vals[i]
5336 || strcmp (names[i], e->names[i]) != 0)
5341 if ((names == NULL && e->names == NULL)
5345 && e->names[i] == NULL))
5347 /* We've seen this enum before. */
5348 return ieee_push_type (info, e->indx, 0, TRUE, FALSE);
5353 /* We've already seen an enum of the same name, so we must make
5354 sure to output this one locally. */
5360 /* If this is a simple enumeration, in which the values start at 0
5361 and always increment by 1, we can use type E. Otherwise we must
5367 for (i = 0; names[i] != NULL; i++)
5377 if (! ieee_define_named_type (info, tag, indx, 0, TRUE, localp,
5378 (struct ieee_buflist *) NULL)
5379 || ! ieee_write_number (info, simple ? 'E' : 'N'))
5383 /* FIXME: This is supposed to be the enumeration size, but we
5384 don't store that. */
5385 if (! ieee_write_number (info, 4))
5390 for (i = 0; names[i] != NULL; i++)
5392 if (! ieee_write_id (info, names[i]))
5396 if (! ieee_write_number (info, vals[i]))
5404 if (indx == (unsigned int) -1)
5406 e = (struct ieee_defined_enum *) xmalloc (sizeof *e);
5407 memset (e, 0, sizeof *e);
5408 e->indx = info->type_stack->type.indx;
5411 e->next = info->enums;
5423 /* Make a pointer type. */
5426 ieee_pointer_type (void *p)
5428 struct ieee_handle *info = (struct ieee_handle *) p;
5431 struct ieee_modified_type *m = NULL;
5433 localp = info->type_stack->type.localp;
5434 indx = ieee_pop_type (info);
5436 /* A pointer to a simple builtin type can be obtained by adding 32.
5437 FIXME: Will this be a short pointer, and will that matter? */
5439 return ieee_push_type (info, indx + 32, 0, TRUE, FALSE);
5443 m = ieee_get_modified_info (p, indx);
5447 /* FIXME: The size should depend upon the architecture. */
5449 return ieee_push_type (info, m->pointer, 4, TRUE, FALSE);
5452 if (! ieee_define_type (info, 4, TRUE, localp)
5453 || ! ieee_write_number (info, 'P')
5454 || ! ieee_write_number (info, indx))
5458 m->pointer = info->type_stack->type.indx;
5463 /* Make a function type. This will be called for a method, but we
5464 don't want to actually add it to the type table in that case. We
5465 handle this by defining the type in a private buffer, and only
5466 adding that buffer to the typedef block if we are going to use it. */
5469 ieee_function_type (void *p, int argcount, bfd_boolean varargs)
5471 struct ieee_handle *info = (struct ieee_handle *) p;
5473 unsigned int *args = NULL;
5475 unsigned int retindx;
5476 struct ieee_buflist fndef;
5477 struct ieee_modified_type *m;
5483 args = (unsigned int *) xmalloc (argcount * sizeof *args);
5484 for (i = argcount - 1; i >= 0; i--)
5486 if (info->type_stack->type.localp)
5488 args[i] = ieee_pop_type (info);
5491 else if (argcount < 0)
5494 if (info->type_stack->type.localp)
5496 retindx = ieee_pop_type (info);
5499 if (argcount < 0 && ! localp)
5501 m = ieee_get_modified_info (p, retindx);
5505 if (m->function > 0)
5506 return ieee_push_type (info, m->function, 0, TRUE, FALSE);
5509 /* An attribute of 0x41 means that the frame and push mask are
5511 if (! ieee_init_buffer (info, &fndef)
5512 || ! ieee_define_named_type (info, (const char *) NULL,
5513 (unsigned int) -1, 0, TRUE, localp,
5515 || ! ieee_write_number (info, 'x')
5516 || ! ieee_write_number (info, 0x41)
5517 || ! ieee_write_number (info, 0)
5518 || ! ieee_write_number (info, 0)
5519 || ! ieee_write_number (info, retindx)
5520 || ! ieee_write_number (info, (bfd_vma) argcount + (varargs ? 1 : 0)))
5524 for (i = 0; i < argcount; i++)
5525 if (! ieee_write_number (info, args[i]))
5531 /* A varargs function is represented by writing out the last
5532 argument as type void *, although this makes little sense. */
5533 if (! ieee_write_number (info, (bfd_vma) builtin_void + 32))
5537 if (! ieee_write_number (info, 0))
5540 /* We wrote the information into fndef, in case we don't need it.
5541 It will be appended to info->types by ieee_pop_type. */
5542 info->type_stack->type.fndef = fndef;
5545 m->function = info->type_stack->type.indx;
5550 /* Make a reference type. */
5553 ieee_reference_type (void *p)
5555 struct ieee_handle *info = (struct ieee_handle *) p;
5557 /* IEEE appears to record a normal pointer type, and then use a
5558 pmisc record to indicate that it is really a reference. */
5560 if (! ieee_pointer_type (p))
5562 info->type_stack->type.referencep = TRUE;
5566 /* Make a range type. */
5569 ieee_range_type (void *p, bfd_signed_vma low, bfd_signed_vma high)
5571 struct ieee_handle *info = (struct ieee_handle *) p;
5573 bfd_boolean unsignedp, localp;
5575 size = info->type_stack->type.size;
5576 unsignedp = info->type_stack->type.unsignedp;
5577 localp = info->type_stack->type.localp;
5578 ieee_pop_unused_type (info);
5579 return (ieee_define_type (info, size, unsignedp, localp)
5580 && ieee_write_number (info, 'R')
5581 && ieee_write_number (info, (bfd_vma) low)
5582 && ieee_write_number (info, (bfd_vma) high)
5583 && ieee_write_number (info, unsignedp ? 0 : 1)
5584 && ieee_write_number (info, size));
5587 /* Make an array type. */
5590 ieee_array_type (void *p, bfd_signed_vma low, bfd_signed_vma high,
5591 bfd_boolean stringp ATTRIBUTE_UNUSED)
5593 struct ieee_handle *info = (struct ieee_handle *) p;
5594 unsigned int eleindx;
5597 struct ieee_modified_type *m = NULL;
5598 struct ieee_modified_array_type *a;
5600 /* IEEE does not store the range, so we just ignore it. */
5601 ieee_pop_unused_type (info);
5602 localp = info->type_stack->type.localp;
5603 size = info->type_stack->type.size;
5604 eleindx = ieee_pop_type (info);
5606 /* If we don't know the range, treat the size as exactly one
5609 size *= (high - low) + 1;
5613 m = ieee_get_modified_info (info, eleindx);
5617 for (a = m->arrays; a != NULL; a = a->next)
5619 if (a->low == low && a->high == high)
5620 return ieee_push_type (info, a->indx, size, FALSE, FALSE);
5624 if (! ieee_define_type (info, size, FALSE, localp)
5625 || ! ieee_write_number (info, low == 0 ? 'Z' : 'C')
5626 || ! ieee_write_number (info, eleindx))
5630 if (! ieee_write_number (info, low))
5634 if (! ieee_write_number (info, high + 1))
5639 a = (struct ieee_modified_array_type *) xmalloc (sizeof *a);
5640 memset (a, 0, sizeof *a);
5642 a->indx = info->type_stack->type.indx;
5646 a->next = m->arrays;
5653 /* Make a set type. */
5656 ieee_set_type (void *p, bfd_boolean bitstringp ATTRIBUTE_UNUSED)
5658 struct ieee_handle *info = (struct ieee_handle *) p;
5660 unsigned int eleindx;
5662 localp = info->type_stack->type.localp;
5663 eleindx = ieee_pop_type (info);
5665 /* FIXME: We don't know the size, so we just use 4. */
5667 return (ieee_define_type (info, 0, TRUE, localp)
5668 && ieee_write_number (info, 's')
5669 && ieee_write_number (info, 4)
5670 && ieee_write_number (info, eleindx));
5673 /* Make an offset type. */
5676 ieee_offset_type (void *p)
5678 struct ieee_handle *info = (struct ieee_handle *) p;
5679 unsigned int targetindx, baseindx;
5681 targetindx = ieee_pop_type (info);
5682 baseindx = ieee_pop_type (info);
5684 /* FIXME: The MRI C++ compiler does not appear to generate any
5685 useful type information about an offset type. It just records a
5686 pointer to member as an integer. The MRI/HP IEEE spec does
5687 describe a pmisc record which can be used for a pointer to
5688 member. Unfortunately, it does not describe the target type,
5689 which seems pretty important. I'm going to punt this for now. */
5691 return ieee_int_type (p, 4, TRUE);
5694 /* Make a method type. */
5697 ieee_method_type (void *p, bfd_boolean domain, int argcount,
5698 bfd_boolean varargs)
5700 struct ieee_handle *info = (struct ieee_handle *) p;
5702 /* FIXME: The MRI/HP IEEE spec defines a pmisc record to use for a
5703 method, but the definition is incomplete. We just output an 'x'
5707 ieee_pop_unused_type (info);
5709 return ieee_function_type (p, argcount, varargs);
5712 /* Make a const qualified type. */
5715 ieee_const_type (void *p)
5717 struct ieee_handle *info = (struct ieee_handle *) p;
5719 bfd_boolean unsignedp, localp;
5721 struct ieee_modified_type *m = NULL;
5723 size = info->type_stack->type.size;
5724 unsignedp = info->type_stack->type.unsignedp;
5725 localp = info->type_stack->type.localp;
5726 indx = ieee_pop_type (info);
5730 m = ieee_get_modified_info (info, indx);
5734 if (m->const_qualified > 0)
5735 return ieee_push_type (info, m->const_qualified, size, unsignedp,
5739 if (! ieee_define_type (info, size, unsignedp, localp)
5740 || ! ieee_write_number (info, 'n')
5741 || ! ieee_write_number (info, 1)
5742 || ! ieee_write_number (info, indx))
5746 m->const_qualified = info->type_stack->type.indx;
5751 /* Make a volatile qualified type. */
5754 ieee_volatile_type (void *p)
5756 struct ieee_handle *info = (struct ieee_handle *) p;
5758 bfd_boolean unsignedp, localp;
5760 struct ieee_modified_type *m = NULL;
5762 size = info->type_stack->type.size;
5763 unsignedp = info->type_stack->type.unsignedp;
5764 localp = info->type_stack->type.localp;
5765 indx = ieee_pop_type (info);
5769 m = ieee_get_modified_info (info, indx);
5773 if (m->volatile_qualified > 0)
5774 return ieee_push_type (info, m->volatile_qualified, size, unsignedp,
5778 if (! ieee_define_type (info, size, unsignedp, localp)
5779 || ! ieee_write_number (info, 'n')
5780 || ! ieee_write_number (info, 2)
5781 || ! ieee_write_number (info, indx))
5785 m->volatile_qualified = info->type_stack->type.indx;
5790 /* Convert an enum debug_visibility into a CXXFLAGS value. */
5793 ieee_vis_to_flags (enum debug_visibility visibility)
5799 case DEBUG_VISIBILITY_PUBLIC:
5800 return CXXFLAGS_VISIBILITY_PUBLIC;
5801 case DEBUG_VISIBILITY_PRIVATE:
5802 return CXXFLAGS_VISIBILITY_PRIVATE;
5803 case DEBUG_VISIBILITY_PROTECTED:
5804 return CXXFLAGS_VISIBILITY_PROTECTED;
5809 /* Start defining a struct type. We build it in the strdef field on
5810 the stack, to avoid confusing type definitions required by the
5811 fields with the struct type itself. */
5814 ieee_start_struct_type (void *p, const char *tag, unsigned int id,
5815 bfd_boolean structp, unsigned int size)
5817 struct ieee_handle *info = (struct ieee_handle *) p;
5818 bfd_boolean localp, ignorep;
5822 struct ieee_name_type_hash_entry *h;
5823 struct ieee_name_type *nt, *ntlook;
5824 struct ieee_buflist strdef;
5829 /* We need to create a tag for internal use even if we don't want
5830 one for external use. This will let us refer to an anonymous
5839 sprintf (ab, "__anon%u", id);
5844 /* If we already have references to the tag, we must use the
5845 existing type index. */
5846 h = ieee_name_type_hash_lookup (&info->tags, look, TRUE, copy);
5851 for (ntlook = h->types; ntlook != NULL; ntlook = ntlook->next)
5853 if (ntlook->id == id)
5855 else if (! ntlook->type.localp)
5857 /* We are creating a duplicate definition of a globally
5858 defined tag. Force it to be local to avoid
5866 assert (localp == nt->type.localp);
5867 if (nt->kind == DEBUG_KIND_ILLEGAL && ! localp)
5869 /* We've already seen a global definition of the type.
5870 Ignore this new definition. */
5876 nt = (struct ieee_name_type *) xmalloc (sizeof *nt);
5877 memset (nt, 0, sizeof *nt);
5879 nt->type.name = h->root.string;
5880 nt->next = h->types;
5882 nt->type.indx = info->type_indx;
5886 nt->kind = DEBUG_KIND_ILLEGAL;
5888 if (! ieee_init_buffer (info, &strdef)
5889 || ! ieee_define_named_type (info, tag, nt->type.indx, size, TRUE,
5891 || ! ieee_write_number (info, structp ? 'S' : 'U')
5892 || ! ieee_write_number (info, size))
5899 /* We never want nt->type.name to be NULL. We want the rest of
5900 the type to be the object set up on the type stack; it will
5901 have a NULL name if tag is NULL. */
5902 hold = nt->type.name;
5903 nt->type = info->type_stack->type;
5904 nt->type.name = hold;
5907 info->type_stack->type.name = tag;
5908 info->type_stack->type.strdef = strdef;
5909 info->type_stack->type.ignorep = ignorep;
5914 /* Add a field to a struct. */
5917 ieee_struct_field (void *p, const char *name, bfd_vma bitpos, bfd_vma bitsize,
5918 enum debug_visibility visibility)
5920 struct ieee_handle *info = (struct ieee_handle *) p;
5922 bfd_boolean unsignedp;
5923 bfd_boolean referencep;
5928 assert (info->type_stack != NULL
5929 && info->type_stack->next != NULL
5930 && ! ieee_buffer_emptyp (&info->type_stack->next->type.strdef));
5932 /* If we are ignoring this struct definition, just pop and ignore
5934 if (info->type_stack->next->type.ignorep)
5936 ieee_pop_unused_type (info);
5940 size = info->type_stack->type.size;
5941 unsignedp = info->type_stack->type.unsignedp;
5942 referencep = info->type_stack->type.referencep;
5943 localp = info->type_stack->type.localp;
5944 indx = ieee_pop_type (info);
5947 info->type_stack->type.localp = TRUE;
5949 if (info->type_stack->type.classdef != NULL)
5954 /* This is a class. We must add a description of this field to
5955 the class records we are building. */
5957 flags = ieee_vis_to_flags (visibility);
5958 nindx = info->type_stack->type.classdef->indx;
5959 if (! ieee_change_buffer (info,
5960 &info->type_stack->type.classdef->pmiscbuf)
5961 || ! ieee_write_asn (info, nindx, 'd')
5962 || ! ieee_write_asn (info, nindx, flags)
5963 || ! ieee_write_atn65 (info, nindx, name)
5964 || ! ieee_write_atn65 (info, nindx, name))
5966 info->type_stack->type.classdef->pmisccount += 4;
5972 /* We need to output a record recording that this field is
5973 really of reference type. We put this on the refs field
5974 of classdef, so that it can be appended to the C++
5975 records after the class is defined. */
5977 nindx = info->name_indx;
5980 if (! ieee_change_buffer (info,
5981 &info->type_stack->type.classdef->refs)
5982 || ! ieee_write_byte (info, (int) ieee_nn_record)
5983 || ! ieee_write_number (info, nindx)
5984 || ! ieee_write_id (info, "")
5985 || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
5986 || ! ieee_write_number (info, nindx)
5987 || ! ieee_write_number (info, 0)
5988 || ! ieee_write_number (info, 62)
5989 || ! ieee_write_number (info, 80)
5990 || ! ieee_write_number (info, 4)
5991 || ! ieee_write_asn (info, nindx, 'R')
5992 || ! ieee_write_asn (info, nindx, 3)
5993 || ! ieee_write_atn65 (info, nindx, info->type_stack->type.name)
5994 || ! ieee_write_atn65 (info, nindx, name))
5999 /* If the bitsize doesn't match the expected size, we need to output
6001 if (size == 0 || bitsize == 0 || bitsize == size * 8)
6002 offset = bitpos / 8;
6005 if (! ieee_define_type (info, 0, unsignedp,
6006 info->type_stack->type.localp)
6007 || ! ieee_write_number (info, 'g')
6008 || ! ieee_write_number (info, unsignedp ? 0 : 1)
6009 || ! ieee_write_number (info, bitsize)
6010 || ! ieee_write_number (info, indx))
6012 indx = ieee_pop_type (info);
6016 /* Switch to the struct we are building in order to output this
6017 field definition. */
6018 return (ieee_change_buffer (info, &info->type_stack->type.strdef)
6019 && ieee_write_id (info, name)
6020 && ieee_write_number (info, indx)
6021 && ieee_write_number (info, offset));
6024 /* Finish up a struct type. */
6027 ieee_end_struct_type (void *p)
6029 struct ieee_handle *info = (struct ieee_handle *) p;
6030 struct ieee_buflist *pb;
6032 assert (info->type_stack != NULL
6033 && ! ieee_buffer_emptyp (&info->type_stack->type.strdef));
6035 /* If we were ignoring this struct definition because it was a
6036 duplicate definition, just through away whatever bytes we have
6037 accumulated. Leave the type on the stack. */
6038 if (info->type_stack->type.ignorep)
6041 /* If this is not a duplicate definition of this tag, then localp
6042 will be FALSE, and we can put it in the global type block.
6043 FIXME: We should avoid outputting duplicate definitions which are
6045 if (! info->type_stack->type.localp)
6047 /* Make sure we have started the global type block. */
6048 if (ieee_buffer_emptyp (&info->global_types))
6050 if (! ieee_change_buffer (info, &info->global_types)
6051 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
6052 || ! ieee_write_byte (info, 2)
6053 || ! ieee_write_number (info, 0)
6054 || ! ieee_write_id (info, ""))
6057 pb = &info->global_types;
6061 /* Make sure we have started the types block. */
6062 if (ieee_buffer_emptyp (&info->types))
6064 if (! ieee_change_buffer (info, &info->types)
6065 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
6066 || ! ieee_write_byte (info, 1)
6067 || ! ieee_write_number (info, 0)
6068 || ! ieee_write_id (info, info->modname))
6074 /* Append the struct definition to the types. */
6075 if (! ieee_append_buffer (info, pb, &info->type_stack->type.strdef)
6076 || ! ieee_init_buffer (info, &info->type_stack->type.strdef))
6079 /* Leave the struct on the type stack. */
6084 /* Start a class type. */
6087 ieee_start_class_type (void *p, const char *tag, unsigned int id,
6088 bfd_boolean structp, unsigned int size,
6089 bfd_boolean vptr, bfd_boolean ownvptr)
6091 struct ieee_handle *info = (struct ieee_handle *) p;
6093 struct ieee_buflist pmiscbuf;
6095 struct ieee_type_class *classdef;
6097 /* A C++ class is output as a C++ struct along with a set of pmisc
6098 records describing the class. */
6100 /* We need to have a name so that we can associate the struct and
6106 t = (char *) xmalloc (20);
6107 sprintf (t, "__anon%u", id);
6111 /* We can't write out the virtual table information until we have
6112 finished the class, because we don't know the virtual table size.
6113 We get the size from the largest voffset we see. */
6115 if (vptr && ! ownvptr)
6117 vclass = info->type_stack->type.name;
6118 assert (vclass != NULL);
6119 /* We don't call ieee_pop_unused_type, since the class should
6121 (void) ieee_pop_type (info);
6124 if (! ieee_start_struct_type (p, tag, id, structp, size))
6127 indx = info->name_indx;
6130 /* We write out pmisc records into the classdef field. We will
6131 write out the pmisc start after we know the number of records we
6133 if (! ieee_init_buffer (info, &pmiscbuf)
6134 || ! ieee_change_buffer (info, &pmiscbuf)
6135 || ! ieee_write_asn (info, indx, 'T')
6136 || ! ieee_write_asn (info, indx, structp ? 'o' : 'u')
6137 || ! ieee_write_atn65 (info, indx, tag))
6140 classdef = (struct ieee_type_class *) xmalloc (sizeof *classdef);
6141 memset (classdef, 0, sizeof *classdef);
6143 classdef->indx = indx;
6144 classdef->pmiscbuf = pmiscbuf;
6145 classdef->pmisccount = 3;
6146 classdef->vclass = vclass;
6147 classdef->ownvptr = ownvptr;
6149 info->type_stack->type.classdef = classdef;
6154 /* Add a static member to a class. */
6157 ieee_class_static_member (void *p, const char *name, const char *physname,
6158 enum debug_visibility visibility)
6160 struct ieee_handle *info = (struct ieee_handle *) p;
6164 /* We don't care about the type. Hopefully there will be a call to
6165 ieee_variable declaring the physical name and the type, since
6166 that is where an IEEE consumer must get the type. */
6167 ieee_pop_unused_type (info);
6169 assert (info->type_stack != NULL
6170 && info->type_stack->type.classdef != NULL);
6172 flags = ieee_vis_to_flags (visibility);
6173 flags |= CXXFLAGS_STATIC;
6175 nindx = info->type_stack->type.classdef->indx;
6177 if (! ieee_change_buffer (info, &info->type_stack->type.classdef->pmiscbuf)
6178 || ! ieee_write_asn (info, nindx, 'd')
6179 || ! ieee_write_asn (info, nindx, flags)
6180 || ! ieee_write_atn65 (info, nindx, name)
6181 || ! ieee_write_atn65 (info, nindx, physname))
6183 info->type_stack->type.classdef->pmisccount += 4;
6188 /* Add a base class to a class. */
6191 ieee_class_baseclass (void *p, bfd_vma bitpos, bfd_boolean virtual,
6192 enum debug_visibility visibility)
6194 struct ieee_handle *info = (struct ieee_handle *) p;
6202 assert (info->type_stack != NULL
6203 && info->type_stack->type.name != NULL
6204 && info->type_stack->next != NULL
6205 && info->type_stack->next->type.classdef != NULL
6206 && ! ieee_buffer_emptyp (&info->type_stack->next->type.strdef));
6208 bname = info->type_stack->type.name;
6209 localp = info->type_stack->type.localp;
6210 bindx = ieee_pop_type (info);
6212 /* We are currently defining both a struct and a class. We must
6213 write out a field definition in the struct which holds the base
6214 class. The stabs debugging reader will create a field named
6215 _vb$CLASS for a virtual base class, so we just use that. FIXME:
6216 we should not depend upon a detail of stabs debugging. */
6219 fname = (char *) xmalloc (strlen (bname) + sizeof "_vb$");
6220 sprintf (fname, "_vb$%s", bname);
6221 flags = BASEFLAGS_VIRTUAL;
6226 info->type_stack->type.localp = TRUE;
6228 fname = (char *) xmalloc (strlen (bname) + sizeof "_b$");
6229 sprintf (fname, "_b$%s", bname);
6231 if (! ieee_change_buffer (info, &info->type_stack->type.strdef)
6232 || ! ieee_write_id (info, fname)
6233 || ! ieee_write_number (info, bindx)
6234 || ! ieee_write_number (info, bitpos / 8))
6239 if (visibility == DEBUG_VISIBILITY_PRIVATE)
6240 flags |= BASEFLAGS_PRIVATE;
6242 nindx = info->type_stack->type.classdef->indx;
6244 if (! ieee_change_buffer (info, &info->type_stack->type.classdef->pmiscbuf)
6245 || ! ieee_write_asn (info, nindx, 'b')
6246 || ! ieee_write_asn (info, nindx, flags)
6247 || ! ieee_write_atn65 (info, nindx, bname)
6248 || ! ieee_write_asn (info, nindx, 0)
6249 || ! ieee_write_atn65 (info, nindx, fname))
6251 info->type_stack->type.classdef->pmisccount += 5;
6258 /* Start building a method for a class. */
6261 ieee_class_start_method (void *p, const char *name)
6263 struct ieee_handle *info = (struct ieee_handle *) p;
6265 assert (info->type_stack != NULL
6266 && info->type_stack->type.classdef != NULL
6267 && info->type_stack->type.classdef->method == NULL);
6269 info->type_stack->type.classdef->method = name;
6274 /* Define a new method variant, either static or not. */
6277 ieee_class_method_var (struct ieee_handle *info, const char *physname,
6278 enum debug_visibility visibility,
6279 bfd_boolean staticp, bfd_boolean constp,
6280 bfd_boolean volatilep, bfd_vma voffset,
6281 bfd_boolean context)
6285 bfd_boolean virtual;
6287 /* We don't need the type of the method. An IEEE consumer which
6288 wants the type must track down the function by the physical name
6289 and get the type from that. */
6290 ieee_pop_unused_type (info);
6292 /* We don't use the context. FIXME: We probably ought to use it to
6293 adjust the voffset somehow, but I don't really know how. */
6295 ieee_pop_unused_type (info);
6297 assert (info->type_stack != NULL
6298 && info->type_stack->type.classdef != NULL
6299 && info->type_stack->type.classdef->method != NULL);
6301 flags = ieee_vis_to_flags (visibility);
6303 /* FIXME: We never set CXXFLAGS_OVERRIDE, CXXFLAGS_OPERATOR,
6304 CXXFLAGS_CTORDTOR, CXXFLAGS_CTOR, or CXXFLAGS_INLINE. */
6307 flags |= CXXFLAGS_STATIC;
6309 flags |= CXXFLAGS_CONST;
6311 flags |= CXXFLAGS_VOLATILE;
6313 nindx = info->type_stack->type.classdef->indx;
6315 virtual = context || voffset > 0;
6317 if (! ieee_change_buffer (info,
6318 &info->type_stack->type.classdef->pmiscbuf)
6319 || ! ieee_write_asn (info, nindx, virtual ? 'v' : 'm')
6320 || ! ieee_write_asn (info, nindx, flags)
6321 || ! ieee_write_atn65 (info, nindx,
6322 info->type_stack->type.classdef->method)
6323 || ! ieee_write_atn65 (info, nindx, physname))
6328 if (voffset > info->type_stack->type.classdef->voffset)
6329 info->type_stack->type.classdef->voffset = voffset;
6330 if (! ieee_write_asn (info, nindx, voffset))
6332 ++info->type_stack->type.classdef->pmisccount;
6335 if (! ieee_write_asn (info, nindx, 0))
6338 info->type_stack->type.classdef->pmisccount += 5;
6343 /* Define a new method variant. */
6346 ieee_class_method_variant (void *p, const char *physname,
6347 enum debug_visibility visibility,
6348 bfd_boolean constp, bfd_boolean volatilep,
6349 bfd_vma voffset, bfd_boolean context)
6351 struct ieee_handle *info = (struct ieee_handle *) p;
6353 return ieee_class_method_var (info, physname, visibility, FALSE, constp,
6354 volatilep, voffset, context);
6357 /* Define a new static method variant. */
6360 ieee_class_static_method_variant (void *p, const char *physname,
6361 enum debug_visibility visibility,
6362 bfd_boolean constp, bfd_boolean volatilep)
6364 struct ieee_handle *info = (struct ieee_handle *) p;
6366 return ieee_class_method_var (info, physname, visibility, TRUE, constp,
6367 volatilep, 0, FALSE);
6370 /* Finish up a method. */
6373 ieee_class_end_method (void *p)
6375 struct ieee_handle *info = (struct ieee_handle *) p;
6377 assert (info->type_stack != NULL
6378 && info->type_stack->type.classdef != NULL
6379 && info->type_stack->type.classdef->method != NULL);
6381 info->type_stack->type.classdef->method = NULL;
6386 /* Finish up a class. */
6389 ieee_end_class_type (void *p)
6391 struct ieee_handle *info = (struct ieee_handle *) p;
6394 assert (info->type_stack != NULL
6395 && info->type_stack->type.classdef != NULL);
6397 /* If we were ignoring this class definition because it was a
6398 duplicate definition, just through away whatever bytes we have
6399 accumulated. Leave the type on the stack. */
6400 if (info->type_stack->type.ignorep)
6403 nindx = info->type_stack->type.classdef->indx;
6405 /* If we have a virtual table, we can write out the information now. */
6406 if (info->type_stack->type.classdef->vclass != NULL
6407 || info->type_stack->type.classdef->ownvptr)
6409 if (! ieee_change_buffer (info,
6410 &info->type_stack->type.classdef->pmiscbuf)
6411 || ! ieee_write_asn (info, nindx, 'z')
6412 || ! ieee_write_atn65 (info, nindx, "")
6413 || ! ieee_write_asn (info, nindx,
6414 info->type_stack->type.classdef->voffset))
6416 if (info->type_stack->type.classdef->ownvptr)
6418 if (! ieee_write_atn65 (info, nindx, ""))
6423 if (! ieee_write_atn65 (info, nindx,
6424 info->type_stack->type.classdef->vclass))
6427 if (! ieee_write_asn (info, nindx, 0))
6429 info->type_stack->type.classdef->pmisccount += 5;
6432 /* Now that we know the number of pmisc records, we can write out
6433 the atn62 which starts the pmisc records, and append them to the
6436 if (! ieee_change_buffer (info, &info->cxx)
6437 || ! ieee_write_byte (info, (int) ieee_nn_record)
6438 || ! ieee_write_number (info, nindx)
6439 || ! ieee_write_id (info, "")
6440 || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
6441 || ! ieee_write_number (info, nindx)
6442 || ! ieee_write_number (info, 0)
6443 || ! ieee_write_number (info, 62)
6444 || ! ieee_write_number (info, 80)
6445 || ! ieee_write_number (info,
6446 info->type_stack->type.classdef->pmisccount))
6449 if (! ieee_append_buffer (info, &info->cxx,
6450 &info->type_stack->type.classdef->pmiscbuf))
6452 if (! ieee_buffer_emptyp (&info->type_stack->type.classdef->refs))
6454 if (! ieee_append_buffer (info, &info->cxx,
6455 &info->type_stack->type.classdef->refs))
6459 return ieee_end_struct_type (p);
6462 /* Push a previously seen typedef onto the type stack. */
6465 ieee_typedef_type (void *p, const char *name)
6467 struct ieee_handle *info = (struct ieee_handle *) p;
6468 struct ieee_name_type_hash_entry *h;
6469 struct ieee_name_type *nt;
6471 h = ieee_name_type_hash_lookup (&info->typedefs, name, FALSE, FALSE);
6473 /* h should never be NULL, since that would imply that the generic
6474 debugging code has asked for a typedef which it has not yet
6478 /* We always use the most recently defined type for this name, which
6479 will be the first one on the list. */
6482 if (! ieee_push_type (info, nt->type.indx, nt->type.size,
6483 nt->type.unsignedp, nt->type.localp))
6486 /* Copy over any other type information we may have. */
6487 info->type_stack->type = nt->type;
6492 /* Push a tagged type onto the type stack. */
6495 ieee_tag_type (void *p, const char *name, unsigned int id,
6496 enum debug_type_kind kind)
6498 struct ieee_handle *info = (struct ieee_handle *) p;
6502 struct ieee_name_type_hash_entry *h;
6503 struct ieee_name_type *nt;
6505 if (kind == DEBUG_KIND_ENUM)
6507 struct ieee_defined_enum *e;
6511 for (e = info->enums; e != NULL; e = e->next)
6512 if (e->tag != NULL && strcmp (e->tag, name) == 0)
6513 return ieee_push_type (info, e->indx, 0, TRUE, FALSE);
6515 e = (struct ieee_defined_enum *) xmalloc (sizeof *e);
6516 memset (e, 0, sizeof *e);
6518 e->indx = info->type_indx;
6523 e->next = info->enums;
6526 return ieee_push_type (info, e->indx, 0, TRUE, FALSE);
6534 sprintf (ab, "__anon%u", id);
6539 h = ieee_name_type_hash_lookup (&info->tags, name, TRUE, copy);
6543 for (nt = h->types; nt != NULL; nt = nt->next)
6547 if (! ieee_push_type (info, nt->type.indx, nt->type.size,
6548 nt->type.unsignedp, nt->type.localp))
6550 /* Copy over any other type information we may have. */
6551 info->type_stack->type = nt->type;
6555 if (! nt->type.localp)
6557 /* This is a duplicate of a global type, so it must be
6563 nt = (struct ieee_name_type *) xmalloc (sizeof *nt);
6564 memset (nt, 0, sizeof *nt);
6567 nt->type.name = h->root.string;
6568 nt->type.indx = info->type_indx;
6569 nt->type.localp = localp;
6573 nt->next = h->types;
6576 if (! ieee_push_type (info, nt->type.indx, 0, FALSE, localp))
6579 info->type_stack->type.name = h->root.string;
6584 /* Output a typedef. */
6587 ieee_typdef (void *p, const char *name)
6589 struct ieee_handle *info = (struct ieee_handle *) p;
6590 struct ieee_write_type type;
6594 struct ieee_name_type_hash_entry *h;
6595 struct ieee_name_type *nt;
6597 type = info->type_stack->type;
6600 /* If this is a simple builtin type using a builtin name, we don't
6601 want to output the typedef itself. We also want to change the
6602 type index to correspond to the name being used. We recognize
6603 names used in stabs debugging output even if they don't exactly
6604 correspond to the names used for the IEEE builtin types. */
6606 if (indx <= (unsigned int) builtin_bcd_float)
6608 switch ((enum builtin_types) indx)
6614 if (strcmp (name, "void") == 0)
6618 case builtin_signed_char:
6620 if (strcmp (name, "signed char") == 0)
6622 indx = (unsigned int) builtin_signed_char;
6625 else if (strcmp (name, "char") == 0)
6627 indx = (unsigned int) builtin_char;
6632 case builtin_unsigned_char:
6633 if (strcmp (name, "unsigned char") == 0)
6637 case builtin_signed_short_int:
6639 case builtin_short_int:
6640 case builtin_signed_short:
6641 if (strcmp (name, "signed short int") == 0)
6643 indx = (unsigned int) builtin_signed_short_int;
6646 else if (strcmp (name, "short") == 0)
6648 indx = (unsigned int) builtin_short;
6651 else if (strcmp (name, "short int") == 0)
6653 indx = (unsigned int) builtin_short_int;
6656 else if (strcmp (name, "signed short") == 0)
6658 indx = (unsigned int) builtin_signed_short;
6663 case builtin_unsigned_short_int:
6664 case builtin_unsigned_short:
6665 if (strcmp (name, "unsigned short int") == 0
6666 || strcmp (name, "short unsigned int") == 0)
6668 indx = builtin_unsigned_short_int;
6671 else if (strcmp (name, "unsigned short") == 0)
6673 indx = builtin_unsigned_short;
6678 case builtin_signed_long:
6679 case builtin_int: /* FIXME: Size depends upon architecture. */
6681 if (strcmp (name, "signed long") == 0)
6683 indx = builtin_signed_long;
6686 else if (strcmp (name, "int") == 0)
6691 else if (strcmp (name, "long") == 0
6692 || strcmp (name, "long int") == 0)
6694 indx = builtin_long;
6699 case builtin_unsigned_long:
6700 case builtin_unsigned: /* FIXME: Size depends upon architecture. */
6701 case builtin_unsigned_int: /* FIXME: Like builtin_unsigned. */
6702 if (strcmp (name, "unsigned long") == 0
6703 || strcmp (name, "long unsigned int") == 0)
6705 indx = builtin_unsigned_long;
6708 else if (strcmp (name, "unsigned") == 0)
6710 indx = builtin_unsigned;
6713 else if (strcmp (name, "unsigned int") == 0)
6715 indx = builtin_unsigned_int;
6720 case builtin_signed_long_long:
6721 if (strcmp (name, "signed long long") == 0
6722 || strcmp (name, "long long int") == 0)
6726 case builtin_unsigned_long_long:
6727 if (strcmp (name, "unsigned long long") == 0
6728 || strcmp (name, "long long unsigned int") == 0)
6733 if (strcmp (name, "float") == 0)
6737 case builtin_double:
6738 if (strcmp (name, "double") == 0)
6742 case builtin_long_double:
6743 if (strcmp (name, "long double") == 0)
6747 case builtin_long_long_double:
6748 if (strcmp (name, "long long double") == 0)
6757 h = ieee_name_type_hash_lookup (&info->typedefs, name, TRUE, FALSE);
6761 /* See if we have already defined this type with this name. */
6762 localp = type.localp;
6763 for (nt = h->types; nt != NULL; nt = nt->next)
6767 /* If this is a global definition, then we don't need to
6768 do anything here. */
6769 if (! nt->type.localp)
6771 ieee_pop_unused_type (info);
6777 /* This is a duplicate definition, so make this one local. */
6782 /* We need to add a new typedef for this type. */
6784 nt = (struct ieee_name_type *) xmalloc (sizeof *nt);
6785 memset (nt, 0, sizeof *nt);
6788 nt->type.name = name;
6789 nt->type.localp = localp;
6790 nt->kind = DEBUG_KIND_ILLEGAL;
6792 nt->next = h->types;
6797 /* This is one of the builtin typedefs, so we don't need to
6798 actually define it. */
6799 ieee_pop_unused_type (info);
6803 indx = ieee_pop_type (info);
6805 if (! ieee_define_named_type (info, name, (unsigned int) -1, type.size,
6806 type.unsignedp, localp,
6807 (struct ieee_buflist *) NULL)
6808 || ! ieee_write_number (info, 'T')
6809 || ! ieee_write_number (info, indx))
6812 /* Remove the type we just added to the type stack. This should not
6813 be ieee_pop_unused_type, since the type is used, we just don't
6815 (void) ieee_pop_type (info);
6820 /* Output a tag for a type. We don't have to do anything here. */
6823 ieee_tag (void *p, const char *name ATTRIBUTE_UNUSED)
6825 struct ieee_handle *info = (struct ieee_handle *) p;
6827 /* This should not be ieee_pop_unused_type, since we want the type
6829 (void) ieee_pop_type (info);
6833 /* Output an integer constant. */
6836 ieee_int_constant (void *p ATTRIBUTE_UNUSED, const char *name ATTRIBUTE_UNUSED,
6837 bfd_vma val ATTRIBUTE_UNUSED)
6843 /* Output a floating point constant. */
6846 ieee_float_constant (void *p ATTRIBUTE_UNUSED,
6847 const char *name ATTRIBUTE_UNUSED,
6848 double val ATTRIBUTE_UNUSED)
6854 /* Output a typed constant. */
6857 ieee_typed_constant (void *p, const char *name ATTRIBUTE_UNUSED,
6858 bfd_vma val ATTRIBUTE_UNUSED)
6860 struct ieee_handle *info = (struct ieee_handle *) p;
6863 ieee_pop_unused_type (info);
6867 /* Output a variable. */
6870 ieee_variable (void *p, const char *name, enum debug_var_kind kind,
6873 struct ieee_handle *info = (struct ieee_handle *) p;
6874 unsigned int name_indx;
6876 bfd_boolean referencep;
6877 unsigned int type_indx;
6881 size = info->type_stack->type.size;
6882 referencep = info->type_stack->type.referencep;
6883 type_indx = ieee_pop_type (info);
6885 assert (! ieee_buffer_emptyp (&info->vars));
6886 if (! ieee_change_buffer (info, &info->vars))
6889 name_indx = info->name_indx;
6892 /* Write out an NN and an ATN record for this variable. */
6893 if (! ieee_write_byte (info, (int) ieee_nn_record)
6894 || ! ieee_write_number (info, name_indx)
6895 || ! ieee_write_id (info, name)
6896 || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
6897 || ! ieee_write_number (info, name_indx)
6898 || ! ieee_write_number (info, type_indx))
6906 if (! ieee_write_number (info, 8)
6907 || ! ieee_add_range (info, FALSE, val, val + size))
6913 if (! ieee_write_number (info, 3)
6914 || ! ieee_add_range (info, FALSE, val, val + size))
6919 case DEBUG_LOCAL_STATIC:
6920 if (! ieee_write_number (info, 3)
6921 || ! ieee_add_range (info, FALSE, val, val + size))
6927 if (! ieee_write_number (info, 1)
6928 || ! ieee_write_number (info, val))
6933 case DEBUG_REGISTER:
6934 if (! ieee_write_number (info, 2)
6935 || ! ieee_write_number (info,
6936 ieee_genreg_to_regno (info->abfd, val)))
6945 if (! ieee_write_asn (info, name_indx, val))
6949 /* If this is really a reference type, then we just output it with
6950 pointer type, and must now output a C++ record indicating that it
6951 is really reference type. */
6956 nindx = info->name_indx;
6959 /* If this is a global variable, we want to output the misc
6960 record in the C++ misc record block. Otherwise, we want to
6961 output it just after the variable definition, which is where
6962 the current buffer is. */
6965 if (! ieee_change_buffer (info, &info->cxx))
6969 if (! ieee_write_byte (info, (int) ieee_nn_record)
6970 || ! ieee_write_number (info, nindx)
6971 || ! ieee_write_id (info, "")
6972 || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
6973 || ! ieee_write_number (info, nindx)
6974 || ! ieee_write_number (info, 0)
6975 || ! ieee_write_number (info, 62)
6976 || ! ieee_write_number (info, 80)
6977 || ! ieee_write_number (info, 3)
6978 || ! ieee_write_asn (info, nindx, 'R')
6979 || ! ieee_write_asn (info, nindx, refflag)
6980 || ! ieee_write_atn65 (info, nindx, name))
6987 /* Start outputting information for a function. */
6990 ieee_start_function (void *p, const char *name, bfd_boolean global)
6992 struct ieee_handle *info = (struct ieee_handle *) p;
6993 bfd_boolean referencep;
6994 unsigned int retindx, typeindx;
6996 referencep = info->type_stack->type.referencep;
6997 retindx = ieee_pop_type (info);
6999 /* Besides recording a BB4 or BB6 block, we record the type of the
7000 function in the BB1 typedef block. We can't write out the full
7001 type until we have seen all the parameters, so we accumulate it
7002 in info->fntype and info->fnargs. */
7003 if (! ieee_buffer_emptyp (&info->fntype))
7005 /* FIXME: This might happen someday if we support nested
7010 info->fnname = name;
7012 /* An attribute of 0x40 means that the push mask is unknown. */
7013 if (! ieee_define_named_type (info, name, (unsigned int) -1, 0, FALSE, TRUE,
7015 || ! ieee_write_number (info, 'x')
7016 || ! ieee_write_number (info, 0x40)
7017 || ! ieee_write_number (info, 0)
7018 || ! ieee_write_number (info, 0)
7019 || ! ieee_write_number (info, retindx))
7022 typeindx = ieee_pop_type (info);
7024 if (! ieee_init_buffer (info, &info->fnargs))
7026 info->fnargcount = 0;
7028 /* If the function return value is actually a reference type, we
7029 must add a record indicating that. */
7034 nindx = info->name_indx;
7036 if (! ieee_change_buffer (info, &info->cxx)
7037 || ! ieee_write_byte (info, (int) ieee_nn_record)
7038 || ! ieee_write_number (info, nindx)
7039 || ! ieee_write_id (info, "")
7040 || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
7041 || ! ieee_write_number (info, nindx)
7042 || ! ieee_write_number (info, 0)
7043 || ! ieee_write_number (info, 62)
7044 || ! ieee_write_number (info, 80)
7045 || ! ieee_write_number (info, 3)
7046 || ! ieee_write_asn (info, nindx, 'R')
7047 || ! ieee_write_asn (info, nindx, global ? 0 : 1)
7048 || ! ieee_write_atn65 (info, nindx, name))
7052 assert (! ieee_buffer_emptyp (&info->vars));
7053 if (! ieee_change_buffer (info, &info->vars))
7056 /* The address is written out as the first block. */
7058 ++info->block_depth;
7060 return (ieee_write_byte (info, (int) ieee_bb_record_enum)
7061 && ieee_write_byte (info, global ? 4 : 6)
7062 && ieee_write_number (info, 0)
7063 && ieee_write_id (info, name)
7064 && ieee_write_number (info, 0)
7065 && ieee_write_number (info, typeindx));
7068 /* Add a function parameter. This will normally be called before the
7069 first block, so we postpone them until we see the block. */
7072 ieee_function_parameter (void *p, const char *name, enum debug_parm_kind kind,
7075 struct ieee_handle *info = (struct ieee_handle *) p;
7076 struct ieee_pending_parm *m, **pm;
7078 assert (info->block_depth == 1);
7080 m = (struct ieee_pending_parm *) xmalloc (sizeof *m);
7081 memset (m, 0, sizeof *m);
7085 m->referencep = info->type_stack->type.referencep;
7086 m->type = ieee_pop_type (info);
7090 for (pm = &info->pending_parms; *pm != NULL; pm = &(*pm)->next)
7094 /* Add the type to the fnargs list. */
7095 if (! ieee_change_buffer (info, &info->fnargs)
7096 || ! ieee_write_number (info, m->type))
7103 /* Output pending function parameters. */
7106 ieee_output_pending_parms (struct ieee_handle *info)
7108 struct ieee_pending_parm *m;
7109 unsigned int refcount;
7112 for (m = info->pending_parms; m != NULL; m = m->next)
7114 enum debug_var_kind vkind;
7121 case DEBUG_PARM_STACK:
7122 case DEBUG_PARM_REFERENCE:
7123 vkind = DEBUG_LOCAL;
7125 case DEBUG_PARM_REG:
7126 case DEBUG_PARM_REF_REG:
7127 vkind = DEBUG_REGISTER;
7131 if (! ieee_push_type (info, m->type, 0, FALSE, FALSE))
7133 info->type_stack->type.referencep = m->referencep;
7136 if (! ieee_variable ((void *) info, m->name, vkind, m->val))
7140 /* If there are any reference parameters, we need to output a
7141 miscellaneous record indicating them. */
7144 unsigned int nindx, varindx;
7146 /* FIXME: The MRI compiler outputs the demangled function name
7147 here, but we are outputting the mangled name. */
7148 nindx = info->name_indx;
7150 if (! ieee_change_buffer (info, &info->vars)
7151 || ! ieee_write_byte (info, (int) ieee_nn_record)
7152 || ! ieee_write_number (info, nindx)
7153 || ! ieee_write_id (info, "")
7154 || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
7155 || ! ieee_write_number (info, nindx)
7156 || ! ieee_write_number (info, 0)
7157 || ! ieee_write_number (info, 62)
7158 || ! ieee_write_number (info, 80)
7159 || ! ieee_write_number (info, refcount + 3)
7160 || ! ieee_write_asn (info, nindx, 'B')
7161 || ! ieee_write_atn65 (info, nindx, info->fnname)
7162 || ! ieee_write_asn (info, nindx, 0))
7164 for (m = info->pending_parms, varindx = 1;
7166 m = m->next, varindx++)
7170 if (! ieee_write_asn (info, nindx, varindx))
7176 m = info->pending_parms;
7179 struct ieee_pending_parm *next;
7186 info->pending_parms = NULL;
7191 /* Start a block. If this is the first block, we output the address
7192 to finish the BB4 or BB6, and then output the function parameters. */
7195 ieee_start_block (void *p, bfd_vma addr)
7197 struct ieee_handle *info = (struct ieee_handle *) p;
7199 if (! ieee_change_buffer (info, &info->vars))
7202 if (info->block_depth == 1)
7204 if (! ieee_write_number (info, addr)
7205 || ! ieee_output_pending_parms (info))
7210 if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
7211 || ! ieee_write_byte (info, 6)
7212 || ! ieee_write_number (info, 0)
7213 || ! ieee_write_id (info, "")
7214 || ! ieee_write_number (info, 0)
7215 || ! ieee_write_number (info, 0)
7216 || ! ieee_write_number (info, addr))
7220 if (! ieee_start_range (info, addr))
7223 ++info->block_depth;
7231 ieee_end_block (void *p, bfd_vma addr)
7233 struct ieee_handle *info = (struct ieee_handle *) p;
7235 /* The address we are given is the end of the block, but IEEE seems
7236 to want to the address of the last byte in the block, so we
7238 if (! ieee_change_buffer (info, &info->vars)
7239 || ! ieee_write_byte (info, (int) ieee_be_record_enum)
7240 || ! ieee_write_number (info, addr - 1))
7243 if (! ieee_end_range (info, addr))
7246 --info->block_depth;
7248 if (addr > info->highaddr)
7249 info->highaddr = addr;
7254 /* End a function. */
7257 ieee_end_function (void *p)
7259 struct ieee_handle *info = (struct ieee_handle *) p;
7261 assert (info->block_depth == 1);
7263 --info->block_depth;
7265 /* Now we can finish up fntype, and add it to the typdef section.
7266 At this point, fntype is the 'x' type up to the argument count,
7267 and fnargs is the argument types. We must add the argument
7268 count, and we must add the level. FIXME: We don't record varargs
7269 functions correctly. In fact, stabs debugging does not give us
7270 enough information to do so. */
7271 if (! ieee_change_buffer (info, &info->fntype)
7272 || ! ieee_write_number (info, info->fnargcount)
7273 || ! ieee_change_buffer (info, &info->fnargs)
7274 || ! ieee_write_number (info, 0))
7277 /* Make sure the typdef block has been started. */
7278 if (ieee_buffer_emptyp (&info->types))
7280 if (! ieee_change_buffer (info, &info->types)
7281 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
7282 || ! ieee_write_byte (info, 1)
7283 || ! ieee_write_number (info, 0)
7284 || ! ieee_write_id (info, info->modname))
7288 if (! ieee_append_buffer (info, &info->types, &info->fntype)
7289 || ! ieee_append_buffer (info, &info->types, &info->fnargs))
7292 info->fnname = NULL;
7293 if (! ieee_init_buffer (info, &info->fntype)
7294 || ! ieee_init_buffer (info, &info->fnargs))
7296 info->fnargcount = 0;
7301 /* Record line number information. */
7304 ieee_lineno (void *p, const char *filename, unsigned long lineno, bfd_vma addr)
7306 struct ieee_handle *info = (struct ieee_handle *) p;
7308 assert (info->filename != NULL);
7310 /* The HP simulator seems to get confused when more than one line is
7311 listed for the same address, at least if they are in different
7312 files. We handle this by always listing the last line for a
7313 given address, since that seems to be the one that gdb uses. */
7314 if (info->pending_lineno_filename != NULL
7315 && addr != info->pending_lineno_addr)
7317 /* Make sure we have a line number block. */
7318 if (! ieee_buffer_emptyp (&info->linenos))
7320 if (! ieee_change_buffer (info, &info->linenos))
7325 info->lineno_name_indx = info->name_indx;
7327 if (! ieee_change_buffer (info, &info->linenos)
7328 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
7329 || ! ieee_write_byte (info, 5)
7330 || ! ieee_write_number (info, 0)
7331 || ! ieee_write_id (info, info->filename)
7332 || ! ieee_write_byte (info, (int) ieee_nn_record)
7333 || ! ieee_write_number (info, info->lineno_name_indx)
7334 || ! ieee_write_id (info, ""))
7336 info->lineno_filename = info->filename;
7339 if (strcmp (info->pending_lineno_filename, info->lineno_filename) != 0)
7341 if (strcmp (info->filename, info->lineno_filename) != 0)
7343 /* We were not in the main file. Close the block for the
7345 if (! ieee_write_byte (info, (int) ieee_be_record_enum))
7347 if (strcmp (info->filename, info->pending_lineno_filename) == 0)
7349 /* We need a new NN record, and we aren't about to
7351 info->lineno_name_indx = info->name_indx;
7353 if (! ieee_write_byte (info, (int) ieee_nn_record)
7354 || ! ieee_write_number (info, info->lineno_name_indx)
7355 || ! ieee_write_id (info, ""))
7359 if (strcmp (info->filename, info->pending_lineno_filename) != 0)
7361 /* We are not changing to the main file. Open a block for
7362 the new included file. */
7363 info->lineno_name_indx = info->name_indx;
7365 if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
7366 || ! ieee_write_byte (info, 5)
7367 || ! ieee_write_number (info, 0)
7368 || ! ieee_write_id (info, info->pending_lineno_filename)
7369 || ! ieee_write_byte (info, (int) ieee_nn_record)
7370 || ! ieee_write_number (info, info->lineno_name_indx)
7371 || ! ieee_write_id (info, ""))
7374 info->lineno_filename = info->pending_lineno_filename;
7377 if (! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
7378 || ! ieee_write_number (info, info->lineno_name_indx)
7379 || ! ieee_write_number (info, 0)
7380 || ! ieee_write_number (info, 7)
7381 || ! ieee_write_number (info, info->pending_lineno)
7382 || ! ieee_write_number (info, 0)
7383 || ! ieee_write_asn (info, info->lineno_name_indx,
7384 info->pending_lineno_addr))
7388 info->pending_lineno_filename = filename;
7389 info->pending_lineno = lineno;
7390 info->pending_lineno_addr = addr;