1 /* ieee.c -- Read and write IEEE-695 debugging information.
2 Copyright 1996, 1998, 2000, 2001, 2002 Free Software Foundation, Inc.
3 Written by Ian Lance Taylor <ian@cygnus.com>.
5 This file is part of GNU Binutils.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22 /* This file reads and writes IEEE-695 debugging information. */
30 #include "libiberty.h"
33 #include "filenames.h"
35 /* This structure holds an entry on the block stack. */
39 /* The kind of block. */
41 /* The source file name, for a BB5 block. */
43 /* The index of the function type, for a BB4 or BB6 block. */
45 /* True if this function is being skipped. */
49 /* This structure is the block stack. */
51 #define BLOCKSTACK_SIZE (16)
53 struct ieee_blockstack
55 /* The stack pointer. */
56 struct ieee_block
*bsp
;
58 struct ieee_block stack
[BLOCKSTACK_SIZE
];
61 /* This structure holds information for a variable. */
71 /* Slot if we make an indirect type. */
73 /* Kind of variable or function. */
85 /* This structure holds all the variables. */
89 /* Number of slots allocated. */
92 struct ieee_var
*vars
;
95 /* This structure holds information for a type. We need this because
96 we don't want to represent bitfields as real types. */
102 /* Slot if this is type is referenced before it is defined. */
104 /* Slots for arguments if we make indirect types for them. */
105 debug_type
*arg_slots
;
106 /* If this is a bitfield, this is the size in bits. If this is not
107 a bitfield, this is zero. */
108 unsigned long bitsize
;
111 /* This structure holds all the type information. */
115 /* Number of slots allocated. */
118 struct ieee_type
*types
;
120 #define BUILTIN_TYPE_COUNT (60)
121 debug_type builtins
[BUILTIN_TYPE_COUNT
];
124 /* This structure holds a linked last of structs with their tag names,
125 so that we can convert them to C++ classes if necessary. */
130 struct ieee_tag
*next
;
133 /* The type of the tag. */
135 /* The tagged type is an indirect type pointing at this slot. */
137 /* This is an array of slots used when a field type is converted
138 into a indirect type, in case it needs to be later converted into
143 /* This structure holds the information we pass around to the parsing
148 /* The debugging handle. */
152 /* The start of the bytes to be parsed. */
153 const bfd_byte
*bytes
;
154 /* The end of the bytes to be parsed. */
155 const bfd_byte
*pend
;
156 /* The block stack. */
157 struct ieee_blockstack blockstack
;
158 /* Whether we have seen a BB1 or BB2. */
159 boolean saw_filename
;
161 struct ieee_vars vars
;
162 /* The global variables, after a global typedef block. */
163 struct ieee_vars
*global_vars
;
165 struct ieee_types types
;
166 /* The global types, after a global typedef block. */
167 struct ieee_types
*global_types
;
168 /* The list of tagged structs. */
169 struct ieee_tag
*tags
;
172 /* Basic builtin types, not including the pointers. */
178 builtin_signed_char
= 2,
179 builtin_unsigned_char
= 3,
180 builtin_signed_short_int
= 4,
181 builtin_unsigned_short_int
= 5,
182 builtin_signed_long
= 6,
183 builtin_unsigned_long
= 7,
184 builtin_signed_long_long
= 8,
185 builtin_unsigned_long_long
= 9,
188 builtin_long_double
= 12,
189 builtin_long_long_double
= 13,
190 builtin_quoted_string
= 14,
191 builtin_instruction_address
= 15,
193 builtin_unsigned
= 17,
194 builtin_unsigned_int
= 18,
198 builtin_unsigned_short
= 22,
199 builtin_short_int
= 23,
200 builtin_signed_short
= 24,
201 builtin_bcd_float
= 25
204 /* These are the values found in the derivation flags of a 'b'
205 component record of a 'T' type extension record in a C++ pmisc
206 record. These are bitmasks. */
208 /* Set for a private base class, clear for a public base class.
209 Protected base classes are not supported. */
210 #define BASEFLAGS_PRIVATE (0x1)
211 /* Set for a virtual base class. */
212 #define BASEFLAGS_VIRTUAL (0x2)
213 /* Set for a friend class, clear for a base class. */
214 #define BASEFLAGS_FRIEND (0x10)
216 /* These are the values found in the specs flags of a 'd', 'm', or 'v'
217 component record of a 'T' type extension record in a C++ pmisc
218 record. The same flags are used for a 'M' record in a C++ pmisc
221 /* The lower two bits hold visibility information. */
222 #define CXXFLAGS_VISIBILITY (0x3)
223 /* This value in the lower two bits indicates a public member. */
224 #define CXXFLAGS_VISIBILITY_PUBLIC (0x0)
225 /* This value in the lower two bits indicates a private member. */
226 #define CXXFLAGS_VISIBILITY_PRIVATE (0x1)
227 /* This value in the lower two bits indicates a protected member. */
228 #define CXXFLAGS_VISIBILITY_PROTECTED (0x2)
229 /* Set for a static member. */
230 #define CXXFLAGS_STATIC (0x4)
231 /* Set for a virtual override. */
232 #define CXXFLAGS_OVERRIDE (0x8)
233 /* Set for a friend function. */
234 #define CXXFLAGS_FRIEND (0x10)
235 /* Set for a const function. */
236 #define CXXFLAGS_CONST (0x20)
237 /* Set for a volatile function. */
238 #define CXXFLAGS_VOLATILE (0x40)
239 /* Set for an overloaded function. */
240 #define CXXFLAGS_OVERLOADED (0x80)
241 /* Set for an operator function. */
242 #define CXXFLAGS_OPERATOR (0x100)
243 /* Set for a constructor or destructor. */
244 #define CXXFLAGS_CTORDTOR (0x400)
245 /* Set for a constructor. */
246 #define CXXFLAGS_CTOR (0x200)
247 /* Set for an inline function. */
248 #define CXXFLAGS_INLINE (0x800)
250 /* Local functions. */
252 static void ieee_error
253 PARAMS ((struct ieee_info
*, const bfd_byte
*, const char *));
254 static void ieee_eof
PARAMS ((struct ieee_info
*));
255 static char *savestring
PARAMS ((const char *, unsigned long));
256 static boolean ieee_read_number
257 PARAMS ((struct ieee_info
*, const bfd_byte
**, bfd_vma
*));
258 static boolean ieee_read_optional_number
259 PARAMS ((struct ieee_info
*, const bfd_byte
**, bfd_vma
*, boolean
*));
260 static boolean ieee_read_id
261 PARAMS ((struct ieee_info
*, const bfd_byte
**, const char **,
263 static boolean ieee_read_optional_id
264 PARAMS ((struct ieee_info
*, const bfd_byte
**, const char **,
265 unsigned long *, boolean
*));
266 static boolean ieee_read_expression
267 PARAMS ((struct ieee_info
*, const bfd_byte
**, bfd_vma
*));
268 static debug_type ieee_builtin_type
269 PARAMS ((struct ieee_info
*, const bfd_byte
*, unsigned int));
270 static boolean ieee_alloc_type
271 PARAMS ((struct ieee_info
*, unsigned int, boolean
));
272 static boolean ieee_read_type_index
273 PARAMS ((struct ieee_info
*, const bfd_byte
**, debug_type
*));
274 static int ieee_regno_to_genreg
PARAMS ((bfd
*, int));
275 static int ieee_genreg_to_regno
PARAMS ((bfd
*, int));
276 static boolean parse_ieee_bb
PARAMS ((struct ieee_info
*, const bfd_byte
**));
277 static boolean parse_ieee_be
PARAMS ((struct ieee_info
*, const bfd_byte
**));
278 static boolean parse_ieee_nn
PARAMS ((struct ieee_info
*, const bfd_byte
**));
279 static boolean parse_ieee_ty
PARAMS ((struct ieee_info
*, const bfd_byte
**));
280 static boolean parse_ieee_atn
PARAMS ((struct ieee_info
*, const bfd_byte
**));
281 static boolean ieee_read_cxx_misc
282 PARAMS ((struct ieee_info
*, const bfd_byte
**, unsigned long));
283 static boolean ieee_read_cxx_class
284 PARAMS ((struct ieee_info
*, const bfd_byte
**, unsigned long));
285 static boolean ieee_read_cxx_defaults
286 PARAMS ((struct ieee_info
*, const bfd_byte
**, unsigned long));
287 static boolean ieee_read_reference
288 PARAMS ((struct ieee_info
*, const bfd_byte
**));
289 static boolean ieee_require_asn
290 PARAMS ((struct ieee_info
*, const bfd_byte
**, bfd_vma
*));
291 static boolean ieee_require_atn65
292 PARAMS ((struct ieee_info
*, const bfd_byte
**, const char **,
295 /* Report an error in the IEEE debugging information. */
298 ieee_error (info
, p
, s
)
299 struct ieee_info
*info
;
304 fprintf (stderr
, "%s: 0x%lx: %s (0x%x)\n", bfd_get_filename (info
->abfd
),
305 (unsigned long) (p
- info
->bytes
), s
, *p
);
307 fprintf (stderr
, "%s: %s\n", bfd_get_filename (info
->abfd
), s
);
310 /* Report an unexpected EOF in the IEEE debugging information. */
314 struct ieee_info
*info
;
316 ieee_error (info
, (const bfd_byte
*) NULL
,
317 _("unexpected end of debugging information"));
320 /* Save a string in memory. */
323 savestring (start
, len
)
329 ret
= (char *) xmalloc (len
+ 1);
330 memcpy (ret
, start
, len
);
335 /* Read a number which must be present in an IEEE file. */
338 ieee_read_number (info
, pp
, pv
)
339 struct ieee_info
*info
;
343 return ieee_read_optional_number (info
, pp
, pv
, (boolean
*) NULL
);
346 /* Read a number in an IEEE file. If ppresent is not NULL, the number
347 need not be there. */
350 ieee_read_optional_number (info
, pp
, pv
, ppresent
)
351 struct ieee_info
*info
;
356 ieee_record_enum_type b
;
358 if (*pp
>= info
->pend
)
360 if (ppresent
!= NULL
)
369 b
= (ieee_record_enum_type
) **pp
;
372 if (b
<= ieee_number_end_enum
)
375 if (ppresent
!= NULL
)
380 if (b
>= ieee_number_repeat_start_enum
&& b
<= ieee_number_repeat_end_enum
)
384 i
= (int) b
- (int) ieee_number_repeat_start_enum
;
385 if (*pp
+ i
- 1 >= info
->pend
)
399 if (ppresent
!= NULL
)
405 if (ppresent
!= NULL
)
412 ieee_error (info
, *pp
- 1, _("invalid number"));
416 /* Read a required string from an IEEE file. */
419 ieee_read_id (info
, pp
, pname
, pnamlen
)
420 struct ieee_info
*info
;
423 unsigned long *pnamlen
;
425 return ieee_read_optional_id (info
, pp
, pname
, pnamlen
, (boolean
*) NULL
);
428 /* Read a string from an IEEE file. If ppresent is not NULL, the
429 string is optional. */
432 ieee_read_optional_id (info
, pp
, pname
, pnamlen
, ppresent
)
433 struct ieee_info
*info
;
436 unsigned long *pnamlen
;
442 if (*pp
>= info
->pend
)
453 else if ((ieee_record_enum_type
) b
== ieee_extension_length_1_enum
)
458 else if ((ieee_record_enum_type
) b
== ieee_extension_length_2_enum
)
460 len
= (**pp
<< 8) + (*pp
)[1];
465 if (ppresent
!= NULL
)
471 ieee_error (info
, *pp
- 1, _("invalid string length"));
475 if ((unsigned long) (info
->pend
- *pp
) < len
)
481 *pname
= (const char *) *pp
;
485 if (ppresent
!= NULL
)
491 /* Read an expression from an IEEE file. Since this code is only used
492 to parse debugging information, I haven't bothered to write a full
493 blown IEEE expression parser. I've only thrown in the things I've
494 seen in debugging information. This can be easily extended if
498 ieee_read_expression (info
, pp
, pv
)
499 struct ieee_info
*info
;
503 const bfd_byte
*expr_start
;
504 #define EXPR_STACK_SIZE (10)
505 bfd_vma expr_stack
[EXPR_STACK_SIZE
];
514 const bfd_byte
*start
;
517 ieee_record_enum_type c
;
521 if (! ieee_read_optional_number (info
, pp
, &val
, &present
))
526 if (esp
- expr_stack
>= EXPR_STACK_SIZE
)
528 ieee_error (info
, start
, _("expression stack overflow"));
535 c
= (ieee_record_enum_type
) **pp
;
537 if (c
>= ieee_module_beginning_enum
)
548 ieee_error (info
, start
, _("unsupported IEEE expression operator"));
551 case ieee_variable_R_enum
:
556 if (! ieee_read_number (info
, pp
, &indx
))
558 for (s
= info
->abfd
->sections
; s
!= NULL
; s
= s
->next
)
559 if ((bfd_vma
) s
->target_index
== indx
)
563 ieee_error (info
, start
, _("unknown section"));
567 if (esp
- expr_stack
>= EXPR_STACK_SIZE
)
569 ieee_error (info
, start
, _("expression stack overflow"));
573 *esp
++ = bfd_get_section_vma (info
->abfd
, s
);
577 case ieee_function_plus_enum
:
578 case ieee_function_minus_enum
:
582 if (esp
- expr_stack
< 2)
584 ieee_error (info
, start
, _("expression stack underflow"));
596 if (esp
- 1 != expr_stack
)
598 ieee_error (info
, expr_start
, _("expression stack mismatch"));
607 /* Return an IEEE builtin type. */
610 ieee_builtin_type (info
, p
, indx
)
611 struct ieee_info
*info
;
619 if (indx
< BUILTIN_TYPE_COUNT
620 && info
->types
.builtins
[indx
] != DEBUG_TYPE_NULL
)
621 return info
->types
.builtins
[indx
];
623 dhandle
= info
->dhandle
;
625 if (indx
>= 32 && indx
< 64)
627 type
= debug_make_pointer_type (dhandle
,
628 ieee_builtin_type (info
, p
, indx
- 32));
629 assert (indx
< BUILTIN_TYPE_COUNT
);
630 info
->types
.builtins
[indx
] = type
;
634 switch ((enum builtin_types
) indx
)
637 ieee_error (info
, p
, _("unknown builtin type"));
640 case builtin_unknown
:
641 type
= debug_make_void_type (dhandle
);
646 type
= debug_make_void_type (dhandle
);
650 case builtin_signed_char
:
651 type
= debug_make_int_type (dhandle
, 1, false);
652 name
= "signed char";
655 case builtin_unsigned_char
:
656 type
= debug_make_int_type (dhandle
, 1, true);
657 name
= "unsigned char";
660 case builtin_signed_short_int
:
661 type
= debug_make_int_type (dhandle
, 2, false);
662 name
= "signed short int";
665 case builtin_unsigned_short_int
:
666 type
= debug_make_int_type (dhandle
, 2, true);
667 name
= "unsigned short int";
670 case builtin_signed_long
:
671 type
= debug_make_int_type (dhandle
, 4, false);
672 name
= "signed long";
675 case builtin_unsigned_long
:
676 type
= debug_make_int_type (dhandle
, 4, true);
677 name
= "unsigned long";
680 case builtin_signed_long_long
:
681 type
= debug_make_int_type (dhandle
, 8, false);
682 name
= "signed long long";
685 case builtin_unsigned_long_long
:
686 type
= debug_make_int_type (dhandle
, 8, true);
687 name
= "unsigned long long";
691 type
= debug_make_float_type (dhandle
, 4);
696 type
= debug_make_float_type (dhandle
, 8);
700 case builtin_long_double
:
701 /* FIXME: The size for this type should depend upon the
703 type
= debug_make_float_type (dhandle
, 12);
704 name
= "long double";
707 case builtin_long_long_double
:
708 type
= debug_make_float_type (dhandle
, 16);
709 name
= "long long double";
712 case builtin_quoted_string
:
713 type
= debug_make_array_type (dhandle
,
714 ieee_builtin_type (info
, p
,
717 ieee_builtin_type (info
, p
,
721 name
= "QUOTED STRING";
724 case builtin_instruction_address
:
725 /* FIXME: This should be a code address. */
726 type
= debug_make_int_type (dhandle
, 4, true);
727 name
= "instruction address";
731 /* FIXME: The size for this type should depend upon the
733 type
= debug_make_int_type (dhandle
, 4, false);
737 case builtin_unsigned
:
738 /* FIXME: The size for this type should depend upon the
740 type
= debug_make_int_type (dhandle
, 4, true);
744 case builtin_unsigned_int
:
745 /* FIXME: The size for this type should depend upon the
747 type
= debug_make_int_type (dhandle
, 4, true);
748 name
= "unsigned int";
752 type
= debug_make_int_type (dhandle
, 1, false);
757 type
= debug_make_int_type (dhandle
, 4, false);
762 type
= debug_make_int_type (dhandle
, 2, false);
766 case builtin_unsigned_short
:
767 type
= debug_make_int_type (dhandle
, 2, true);
768 name
= "unsigned short";
771 case builtin_short_int
:
772 type
= debug_make_int_type (dhandle
, 2, false);
776 case builtin_signed_short
:
777 type
= debug_make_int_type (dhandle
, 2, false);
778 name
= "signed short";
781 case builtin_bcd_float
:
782 ieee_error (info
, p
, _("BCD float type not supported"));
783 return DEBUG_TYPE_NULL
;
787 type
= debug_name_type (dhandle
, name
, type
);
789 assert (indx
< BUILTIN_TYPE_COUNT
);
791 info
->types
.builtins
[indx
] = type
;
796 /* Allocate more space in the type table. If ref is true, this is a
797 reference to the type; if it is not already defined, we should set
798 up an indirect type. */
801 ieee_alloc_type (info
, indx
, ref
)
802 struct ieee_info
*info
;
807 register struct ieee_type
*t
;
808 struct ieee_type
*tend
;
810 if (indx
>= info
->types
.alloc
)
812 nalloc
= info
->types
.alloc
;
815 while (indx
>= nalloc
)
818 info
->types
.types
= ((struct ieee_type
*)
819 xrealloc (info
->types
.types
,
820 nalloc
* sizeof *info
->types
.types
));
822 memset (info
->types
.types
+ info
->types
.alloc
, 0,
823 (nalloc
- info
->types
.alloc
) * sizeof *info
->types
.types
);
825 tend
= info
->types
.types
+ nalloc
;
826 for (t
= info
->types
.types
+ info
->types
.alloc
; t
< tend
; t
++)
827 t
->type
= DEBUG_TYPE_NULL
;
829 info
->types
.alloc
= nalloc
;
834 t
= info
->types
.types
+ indx
;
837 t
->pslot
= (debug_type
*) xmalloc (sizeof *t
->pslot
);
838 *t
->pslot
= DEBUG_TYPE_NULL
;
839 t
->type
= debug_make_indirect_type (info
->dhandle
, t
->pslot
,
840 (const char *) NULL
);
849 /* Read a type index and return the corresponding type. */
852 ieee_read_type_index (info
, pp
, ptype
)
853 struct ieee_info
*info
;
857 const bfd_byte
*start
;
862 if (! ieee_read_number (info
, pp
, &indx
))
867 *ptype
= ieee_builtin_type (info
, start
, indx
);
874 if (! ieee_alloc_type (info
, indx
, true))
877 *ptype
= info
->types
.types
[indx
].type
;
882 /* Parse IEEE debugging information for a file. This is passed the
883 bytes which compose the Debug Information Part of an IEEE file. */
886 parse_ieee (dhandle
, abfd
, bytes
, len
)
889 const bfd_byte
*bytes
;
892 struct ieee_info info
;
894 const bfd_byte
*p
, *pend
;
896 info
.dhandle
= dhandle
;
899 info
.pend
= bytes
+ len
;
900 info
.blockstack
.bsp
= info
.blockstack
.stack
;
901 info
.saw_filename
= false;
903 info
.vars
.vars
= NULL
;
904 info
.global_vars
= NULL
;
905 info
.types
.alloc
= 0;
906 info
.types
.types
= NULL
;
907 info
.global_types
= NULL
;
909 for (i
= 0; i
< BUILTIN_TYPE_COUNT
; i
++)
910 info
.types
.builtins
[i
] = DEBUG_TYPE_NULL
;
916 const bfd_byte
*record_start
;
917 ieee_record_enum_type c
;
921 c
= (ieee_record_enum_type
) *p
++;
923 if (c
== ieee_at_record_enum
)
924 c
= (ieee_record_enum_type
) (((unsigned int) c
<< 8) | *p
++);
926 if (c
<= ieee_number_repeat_end_enum
)
928 ieee_error (&info
, record_start
, _("unexpected number"));
935 ieee_error (&info
, record_start
, _("unexpected record type"));
938 case ieee_bb_record_enum
:
939 if (! parse_ieee_bb (&info
, &p
))
943 case ieee_be_record_enum
:
944 if (! parse_ieee_be (&info
, &p
))
949 if (! parse_ieee_nn (&info
, &p
))
953 case ieee_ty_record_enum
:
954 if (! parse_ieee_ty (&info
, &p
))
958 case ieee_atn_record_enum
:
959 if (! parse_ieee_atn (&info
, &p
))
965 if (info
.blockstack
.bsp
!= info
.blockstack
.stack
)
967 ieee_error (&info
, (const bfd_byte
*) NULL
,
968 _("blocks left on stack at end"));
975 /* Handle an IEEE BB record. */
978 parse_ieee_bb (info
, pp
)
979 struct ieee_info
*info
;
982 const bfd_byte
*block_start
;
986 unsigned long namlen
;
987 char *namcopy
= NULL
;
996 if (! ieee_read_number (info
, pp
, &size
)
997 || ! ieee_read_id (info
, pp
, &name
, &namlen
))
1000 fnindx
= (unsigned int) -1;
1006 /* BB1: Type definitions local to a module. */
1007 namcopy
= savestring (name
, namlen
);
1008 if (namcopy
== NULL
)
1010 if (! debug_set_filename (info
->dhandle
, namcopy
))
1012 info
->saw_filename
= true;
1014 /* Discard any variables or types we may have seen before. */
1015 if (info
->vars
.vars
!= NULL
)
1016 free (info
->vars
.vars
);
1017 info
->vars
.vars
= NULL
;
1018 info
->vars
.alloc
= 0;
1019 if (info
->types
.types
!= NULL
)
1020 free (info
->types
.types
);
1021 info
->types
.types
= NULL
;
1022 info
->types
.alloc
= 0;
1024 /* Initialize the types to the global types. */
1025 if (info
->global_types
!= NULL
)
1027 info
->types
.alloc
= info
->global_types
->alloc
;
1028 info
->types
.types
= ((struct ieee_type
*)
1029 xmalloc (info
->types
.alloc
1030 * sizeof (*info
->types
.types
)));
1031 memcpy (info
->types
.types
, info
->global_types
->types
,
1032 info
->types
.alloc
* sizeof (*info
->types
.types
));
1038 /* BB2: Global type definitions. The name is supposed to be
1039 empty, but we don't check. */
1040 if (! debug_set_filename (info
->dhandle
, "*global*"))
1042 info
->saw_filename
= true;
1046 /* BB3: High level module block begin. We don't have to do
1047 anything here. The name is supposed to be the same as for
1048 the BB1, but we don't check. */
1052 /* BB4: Global function. */
1054 bfd_vma stackspace
, typindx
, offset
;
1055 debug_type return_type
;
1057 if (! ieee_read_number (info
, pp
, &stackspace
)
1058 || ! ieee_read_number (info
, pp
, &typindx
)
1059 || ! ieee_read_expression (info
, pp
, &offset
))
1062 /* We have no way to record the stack space. FIXME. */
1066 return_type
= ieee_builtin_type (info
, block_start
, typindx
);
1067 if (return_type
== DEBUG_TYPE_NULL
)
1073 if (! ieee_alloc_type (info
, typindx
, true))
1076 return_type
= info
->types
.types
[typindx
].type
;
1077 if (debug_get_type_kind (info
->dhandle
, return_type
)
1078 == DEBUG_KIND_FUNCTION
)
1079 return_type
= debug_get_return_type (info
->dhandle
,
1083 namcopy
= savestring (name
, namlen
);
1084 if (namcopy
== NULL
)
1086 if (! debug_record_function (info
->dhandle
, namcopy
, return_type
,
1093 /* BB5: File name for source line numbers. */
1097 /* We ignore the date and time. FIXME. */
1098 for (i
= 0; i
< 6; i
++)
1103 if (! ieee_read_optional_number (info
, pp
, &ignore
, &present
))
1109 namcopy
= savestring (name
, namlen
);
1110 if (namcopy
== NULL
)
1112 if (! debug_start_source (info
->dhandle
, namcopy
))
1118 /* BB6: Local function or block. */
1120 bfd_vma stackspace
, typindx
, offset
;
1122 if (! ieee_read_number (info
, pp
, &stackspace
)
1123 || ! ieee_read_number (info
, pp
, &typindx
)
1124 || ! ieee_read_expression (info
, pp
, &offset
))
1127 /* We have no way to record the stack space. FIXME. */
1131 if (! debug_start_block (info
->dhandle
, offset
))
1133 /* Change b to indicate that this is a block
1134 rather than a function. */
1139 /* The MRI C++ compiler will output a fake function named
1140 __XRYCPP to hold C++ debugging information. We skip
1141 that function. This is not crucial, but it makes
1142 converting from IEEE to other debug formats work
1144 if (strncmp (name
, "__XRYCPP", namlen
) == 0)
1148 debug_type return_type
;
1152 return_type
= ieee_builtin_type (info
, block_start
,
1154 if (return_type
== NULL
)
1160 if (! ieee_alloc_type (info
, typindx
, true))
1163 return_type
= info
->types
.types
[typindx
].type
;
1164 if (debug_get_type_kind (info
->dhandle
, return_type
)
1165 == DEBUG_KIND_FUNCTION
)
1166 return_type
= debug_get_return_type (info
->dhandle
,
1170 namcopy
= savestring (name
, namlen
);
1171 if (namcopy
== NULL
)
1173 if (! debug_record_function (info
->dhandle
, namcopy
,
1174 return_type
, false, offset
))
1182 /* BB10: Assembler module scope. In the normal case, we
1183 completely ignore all this information. FIXME. */
1185 const char *inam
, *vstr
;
1186 unsigned long inamlen
, vstrlen
;
1191 if (! info
->saw_filename
)
1193 namcopy
= savestring (name
, namlen
);
1194 if (namcopy
== NULL
)
1196 if (! debug_set_filename (info
->dhandle
, namcopy
))
1198 info
->saw_filename
= true;
1201 if (! ieee_read_id (info
, pp
, &inam
, &inamlen
)
1202 || ! ieee_read_number (info
, pp
, &tool_type
)
1203 || ! ieee_read_optional_id (info
, pp
, &vstr
, &vstrlen
, &present
))
1205 for (i
= 0; i
< 6; i
++)
1209 if (! ieee_read_optional_number (info
, pp
, &ignore
, &present
))
1218 /* BB11: Module section. We completely ignore all this
1219 information. FIXME. */
1221 bfd_vma sectype
, secindx
, offset
, map
;
1224 if (! ieee_read_number (info
, pp
, §ype
)
1225 || ! ieee_read_number (info
, pp
, &secindx
)
1226 || ! ieee_read_expression (info
, pp
, &offset
)
1227 || ! ieee_read_optional_number (info
, pp
, &map
, &present
))
1233 ieee_error (info
, block_start
, _("unknown BB type"));
1238 /* Push this block on the block stack. */
1240 if (info
->blockstack
.bsp
>= info
->blockstack
.stack
+ BLOCKSTACK_SIZE
)
1242 ieee_error (info
, (const bfd_byte
*) NULL
, _("stack overflow"));
1246 info
->blockstack
.bsp
->kind
= b
;
1248 info
->blockstack
.bsp
->filename
= namcopy
;
1249 info
->blockstack
.bsp
->fnindx
= fnindx
;
1250 info
->blockstack
.bsp
->skip
= skip
;
1251 ++info
->blockstack
.bsp
;
1256 /* Handle an IEEE BE record. */
1259 parse_ieee_be (info
, pp
)
1260 struct ieee_info
*info
;
1261 const bfd_byte
**pp
;
1265 if (info
->blockstack
.bsp
<= info
->blockstack
.stack
)
1267 ieee_error (info
, *pp
, _("stack underflow"));
1270 --info
->blockstack
.bsp
;
1272 switch (info
->blockstack
.bsp
->kind
)
1275 /* When we end the global typedefs block, we copy out the the
1276 contents of info->vars. This is because the variable indices
1277 may be reused in the local blocks. However, we need to
1278 preserve them so that we can locate a function returning a
1279 reference variable whose type is named in the global typedef
1281 info
->global_vars
= ((struct ieee_vars
*)
1282 xmalloc (sizeof *info
->global_vars
));
1283 info
->global_vars
->alloc
= info
->vars
.alloc
;
1284 info
->global_vars
->vars
= ((struct ieee_var
*)
1285 xmalloc (info
->vars
.alloc
1286 * sizeof (*info
->vars
.vars
)));
1287 memcpy (info
->global_vars
->vars
, info
->vars
.vars
,
1288 info
->vars
.alloc
* sizeof (*info
->vars
.vars
));
1290 /* We also copy out the non builtin parts of info->types, since
1291 the types are discarded when we start a new block. */
1292 info
->global_types
= ((struct ieee_types
*)
1293 xmalloc (sizeof *info
->global_types
));
1294 info
->global_types
->alloc
= info
->types
.alloc
;
1295 info
->global_types
->types
= ((struct ieee_type
*)
1296 xmalloc (info
->types
.alloc
1297 * sizeof (*info
->types
.types
)));
1298 memcpy (info
->global_types
->types
, info
->types
.types
,
1299 info
->types
.alloc
* sizeof (*info
->types
.types
));
1300 memset (info
->global_types
->builtins
, 0,
1301 sizeof (info
->global_types
->builtins
));
1307 if (! ieee_read_expression (info
, pp
, &offset
))
1309 if (! info
->blockstack
.bsp
->skip
)
1311 if (! debug_end_function (info
->dhandle
, offset
+ 1))
1317 /* This is BE6 when BB6 started a block rather than a local
1319 if (! ieee_read_expression (info
, pp
, &offset
))
1321 if (! debug_end_block (info
->dhandle
, offset
+ 1))
1326 /* When we end a BB5, we look up the stack for the last BB5, if
1327 there is one, so that we can call debug_start_source. */
1328 if (info
->blockstack
.bsp
> info
->blockstack
.stack
)
1330 struct ieee_block
*bl
;
1332 bl
= info
->blockstack
.bsp
;
1338 if (! debug_start_source (info
->dhandle
, bl
->filename
))
1343 while (bl
!= info
->blockstack
.stack
);
1348 if (! ieee_read_expression (info
, pp
, &offset
))
1350 /* We just ignore the module size. FIXME. */
1354 /* Other block types do not have any trailing information. */
1361 /* Parse an NN record. */
1364 parse_ieee_nn (info
, pp
)
1365 struct ieee_info
*info
;
1366 const bfd_byte
**pp
;
1368 const bfd_byte
*nn_start
;
1371 unsigned long namlen
;
1375 if (! ieee_read_number (info
, pp
, &varindx
)
1376 || ! ieee_read_id (info
, pp
, &name
, &namlen
))
1381 ieee_error (info
, nn_start
, _("illegal variable index"));
1386 if (varindx
>= info
->vars
.alloc
)
1390 alloc
= info
->vars
.alloc
;
1393 while (varindx
>= alloc
)
1395 info
->vars
.vars
= ((struct ieee_var
*)
1396 xrealloc (info
->vars
.vars
,
1397 alloc
* sizeof *info
->vars
.vars
));
1398 memset (info
->vars
.vars
+ info
->vars
.alloc
, 0,
1399 (alloc
- info
->vars
.alloc
) * sizeof *info
->vars
.vars
);
1400 info
->vars
.alloc
= alloc
;
1403 info
->vars
.vars
[varindx
].name
= name
;
1404 info
->vars
.vars
[varindx
].namlen
= namlen
;
1409 /* Parse a TY record. */
1412 parse_ieee_ty (info
, pp
)
1413 struct ieee_info
*info
;
1414 const bfd_byte
**pp
;
1416 const bfd_byte
*ty_start
, *ty_var_start
, *ty_code_start
;
1417 bfd_vma typeindx
, varindx
, tc
;
1419 boolean tag
, typdef
;
1420 debug_type
*arg_slots
;
1421 unsigned long type_bitsize
;
1426 if (! ieee_read_number (info
, pp
, &typeindx
))
1431 ieee_error (info
, ty_start
, _("illegal type index"));
1436 if (! ieee_alloc_type (info
, typeindx
, false))
1441 ieee_error (info
, *pp
, _("unknown TY code"));
1448 if (! ieee_read_number (info
, pp
, &varindx
))
1453 ieee_error (info
, ty_var_start
, _("illegal variable index"));
1458 if (varindx
>= info
->vars
.alloc
|| info
->vars
.vars
[varindx
].name
== NULL
)
1460 ieee_error (info
, ty_var_start
, _("undefined variable in TY"));
1464 ty_code_start
= *pp
;
1466 if (! ieee_read_number (info
, pp
, &tc
))
1469 dhandle
= info
->dhandle
;
1478 ieee_error (info
, ty_code_start
, _("unknown TY code"));
1482 /* Unknown type, with size. We treat it as int. FIXME. */
1486 if (! ieee_read_number (info
, pp
, &size
))
1488 type
= debug_make_int_type (dhandle
, size
, false);
1492 case 'A': /* Array. */
1493 case 'a': /* FORTRAN array in column/row order. FIXME: Not
1494 distinguished from normal array. */
1496 debug_type ele_type
;
1497 bfd_vma lower
, upper
;
1499 if (! ieee_read_type_index (info
, pp
, &ele_type
)
1500 || ! ieee_read_number (info
, pp
, &lower
)
1501 || ! ieee_read_number (info
, pp
, &upper
))
1503 type
= debug_make_array_type (dhandle
, ele_type
,
1504 ieee_builtin_type (info
, ty_code_start
,
1507 (bfd_signed_vma
) lower
,
1508 (bfd_signed_vma
) upper
,
1514 /* Simple enumeration. */
1520 bfd_signed_vma
*vals
;
1523 if (! ieee_read_number (info
, pp
, &size
))
1525 /* FIXME: we ignore the enumeration size. */
1528 names
= (const char **) xmalloc (alloc
* sizeof *names
);
1529 memset (names
, 0, alloc
* sizeof *names
);
1534 unsigned long namlen
;
1537 if (! ieee_read_optional_id (info
, pp
, &name
, &namlen
, &present
))
1545 names
= ((const char **)
1546 xrealloc (names
, alloc
* sizeof *names
));
1549 names
[c
] = savestring (name
, namlen
);
1550 if (names
[c
] == NULL
)
1557 vals
= (bfd_signed_vma
*) xmalloc (c
* sizeof *vals
);
1558 for (i
= 0; i
< c
; i
++)
1561 type
= debug_make_enum_type (dhandle
, names
, vals
);
1567 /* Struct with bit fields. */
1571 debug_field
*fields
;
1574 if (! ieee_read_number (info
, pp
, &size
))
1578 fields
= (debug_field
*) xmalloc (alloc
* sizeof *fields
);
1583 unsigned long namlen
;
1586 bfd_vma bitpos
, bitsize
;
1588 if (! ieee_read_optional_id (info
, pp
, &name
, &namlen
, &present
))
1592 if (! ieee_read_type_index (info
, pp
, &ftype
)
1593 || ! ieee_read_number (info
, pp
, &bitpos
)
1594 || ! ieee_read_number (info
, pp
, &bitsize
))
1600 fields
= ((debug_field
*)
1601 xrealloc (fields
, alloc
* sizeof *fields
));
1604 fields
[c
] = debug_make_field (dhandle
, savestring (name
, namlen
),
1605 ftype
, bitpos
, bitsize
,
1606 DEBUG_VISIBILITY_PUBLIC
);
1607 if (fields
[c
] == NULL
)
1614 type
= debug_make_struct_type (dhandle
, true, size
, fields
);
1624 bfd_signed_vma
*vals
;
1628 names
= (const char **) xmalloc (alloc
* sizeof *names
);
1629 vals
= (bfd_signed_vma
*) xmalloc (alloc
* sizeof *names
);
1634 unsigned long namlen
;
1638 if (! ieee_read_optional_id (info
, pp
, &name
, &namlen
, &present
))
1642 if (! ieee_read_number (info
, pp
, &val
))
1645 /* If the length of the name is zero, then the value is
1646 actually the size of the enum. We ignore this
1647 information. FIXME. */
1654 names
= ((const char **)
1655 xrealloc (names
, alloc
* sizeof *names
));
1656 vals
= ((bfd_signed_vma
*)
1657 xrealloc (vals
, alloc
* sizeof *vals
));
1660 names
[c
] = savestring (name
, namlen
);
1661 if (names
[c
] == NULL
)
1663 vals
[c
] = (bfd_signed_vma
) val
;
1669 type
= debug_make_enum_type (dhandle
, names
, vals
);
1674 case 'O': /* Small pointer. We don't distinguish small and large
1676 case 'P': /* Large pointer. */
1680 if (! ieee_read_type_index (info
, pp
, &t
))
1682 type
= debug_make_pointer_type (dhandle
, t
);
1689 bfd_vma low
, high
, signedp
, size
;
1691 if (! ieee_read_number (info
, pp
, &low
)
1692 || ! ieee_read_number (info
, pp
, &high
)
1693 || ! ieee_read_number (info
, pp
, &signedp
)
1694 || ! ieee_read_number (info
, pp
, &size
))
1697 type
= debug_make_range_type (dhandle
,
1698 debug_make_int_type (dhandle
, size
,
1700 (bfd_signed_vma
) low
,
1701 (bfd_signed_vma
) high
);
1705 case 'S': /* Struct. */
1706 case 'U': /* Union. */
1710 debug_field
*fields
;
1713 if (! ieee_read_number (info
, pp
, &size
))
1717 fields
= (debug_field
*) xmalloc (alloc
* sizeof *fields
);
1722 unsigned long namlen
;
1729 if (! ieee_read_optional_id (info
, pp
, &name
, &namlen
, &present
))
1733 if (! ieee_read_number (info
, pp
, &tindx
)
1734 || ! ieee_read_number (info
, pp
, &offset
))
1739 ftype
= ieee_builtin_type (info
, ty_code_start
, tindx
);
1745 struct ieee_type
*t
;
1748 if (! ieee_alloc_type (info
, tindx
, true))
1750 t
= info
->types
.types
+ tindx
;
1752 bitsize
= t
->bitsize
;
1760 fields
= ((debug_field
*)
1761 xrealloc (fields
, alloc
* sizeof *fields
));
1764 fields
[c
] = debug_make_field (dhandle
, savestring (name
, namlen
),
1765 ftype
, offset
, bitsize
,
1766 DEBUG_VISIBILITY_PUBLIC
);
1767 if (fields
[c
] == NULL
)
1774 type
= debug_make_struct_type (dhandle
, tc
== 'S', size
, fields
);
1781 if (! ieee_read_type_index (info
, pp
, &type
))
1787 /* Procedure. FIXME: This is an extern declaration, which we
1788 have no way of representing. */
1794 struct ieee_var
*pv
;
1796 /* FIXME: We ignore the attribute and the argument names. */
1798 if (! ieee_read_number (info
, pp
, &attr
)
1799 || ! ieee_read_type_index (info
, pp
, &rtype
)
1800 || ! ieee_read_number (info
, pp
, &nargs
))
1805 unsigned long namlen
;
1807 if (! ieee_read_optional_id (info
, pp
, &name
, &namlen
, &present
))
1812 pv
= info
->vars
.vars
+ varindx
;
1813 pv
->kind
= IEEE_EXTERNAL
;
1815 && debug_get_type_kind (dhandle
, rtype
) == DEBUG_KIND_POINTER
)
1817 /* Set up the return type as an indirect type pointing to
1818 the variable slot, so that we can change it to a
1819 reference later if appropriate. */
1820 pv
->pslot
= (debug_type
*) xmalloc (sizeof *pv
->pslot
);
1822 rtype
= debug_make_indirect_type (dhandle
, pv
->pslot
,
1823 (const char *) NULL
);
1826 type
= debug_make_function_type (dhandle
, rtype
, (debug_type
*) NULL
,
1832 /* Void. This is not documented, but the MRI compiler emits it. */
1833 type
= debug_make_void_type (dhandle
);
1837 /* Array with 0 lower bound. */
1842 if (! ieee_read_type_index (info
, pp
, &etype
)
1843 || ! ieee_read_number (info
, pp
, &high
))
1846 type
= debug_make_array_type (dhandle
, etype
,
1847 ieee_builtin_type (info
, ty_code_start
,
1850 0, (bfd_signed_vma
) high
, false);
1854 case 'c': /* Complex. */
1855 case 'd': /* Double complex. */
1858 unsigned long namlen
;
1860 /* FIXME: I don't know what the name means. */
1862 if (! ieee_read_id (info
, pp
, &name
, &namlen
))
1865 type
= debug_make_complex_type (dhandle
, tc
== 'c' ? 4 : 8);
1870 /* Pascal file name. FIXME. */
1871 ieee_error (info
, ty_code_start
, _("Pascal file name not supported"));
1875 /* Bitfield type. */
1877 bfd_vma signedp
, bitsize
, dummy
;
1878 const bfd_byte
*hold
;
1881 if (! ieee_read_number (info
, pp
, &signedp
)
1882 || ! ieee_read_number (info
, pp
, &bitsize
))
1885 /* I think the documentation says that there is a type index,
1886 but some actual files do not have one. */
1888 if (! ieee_read_optional_number (info
, pp
, &dummy
, &present
))
1892 /* FIXME: This is just a guess. */
1893 type
= debug_make_int_type (dhandle
, 4,
1894 signedp
? false : true);
1899 if (! ieee_read_type_index (info
, pp
, &type
))
1902 type_bitsize
= bitsize
;
1912 if (! ieee_read_number (info
, pp
, &kind
)
1913 || ! ieee_read_type_index (info
, pp
, &t
))
1919 ieee_error (info
, ty_start
, _("unsupported qualifier"));
1923 type
= debug_make_const_type (dhandle
, t
);
1927 type
= debug_make_volatile_type (dhandle
, t
);
1939 if (! ieee_read_number (info
, pp
, &size
)
1940 || ! ieee_read_type_index (info
, pp
, &etype
))
1943 /* FIXME: We ignore the size. */
1945 type
= debug_make_set_type (dhandle
, etype
, false);
1950 /* Procedure with compiler dependencies. */
1952 struct ieee_var
*pv
;
1953 bfd_vma attr
, frame_type
, push_mask
, nargs
, level
, father
;
1955 debug_type
*arg_types
;
1959 /* FIXME: We ignore some of this information. */
1961 pv
= info
->vars
.vars
+ varindx
;
1963 if (! ieee_read_number (info
, pp
, &attr
)
1964 || ! ieee_read_number (info
, pp
, &frame_type
)
1965 || ! ieee_read_number (info
, pp
, &push_mask
)
1966 || ! ieee_read_type_index (info
, pp
, &rtype
)
1967 || ! ieee_read_number (info
, pp
, &nargs
))
1969 if (nargs
== (bfd_vma
) -1)
1978 arg_types
= ((debug_type
*)
1979 xmalloc ((nargs
+ 1) * sizeof *arg_types
));
1980 for (i
= 0; i
< nargs
; i
++)
1981 if (! ieee_read_type_index (info
, pp
, arg_types
+ i
))
1984 /* If the last type is pointer to void, this is really a
1985 varargs function. */
1991 last
= arg_types
[nargs
- 1];
1992 if (debug_get_type_kind (dhandle
, last
) == DEBUG_KIND_POINTER
1993 && (debug_get_type_kind (dhandle
,
1994 debug_get_target_type (dhandle
,
1996 == DEBUG_KIND_VOID
))
2003 /* If there are any pointer arguments, turn them into
2004 indirect types in case we later need to convert them to
2006 for (i
= 0; i
< nargs
; i
++)
2008 if (debug_get_type_kind (dhandle
, arg_types
[i
])
2009 == DEBUG_KIND_POINTER
)
2011 if (arg_slots
== NULL
)
2013 arg_slots
= ((debug_type
*)
2014 xmalloc (nargs
* sizeof *arg_slots
));
2015 memset (arg_slots
, 0, nargs
* sizeof *arg_slots
);
2017 arg_slots
[i
] = arg_types
[i
];
2019 debug_make_indirect_type (dhandle
,
2021 (const char *) NULL
);
2025 arg_types
[nargs
] = DEBUG_TYPE_NULL
;
2027 if (! ieee_read_number (info
, pp
, &level
)
2028 || ! ieee_read_optional_number (info
, pp
, &father
, &present
))
2031 /* We can't distinguish between a global function and a static
2033 pv
->kind
= IEEE_FUNCTION
;
2036 && debug_get_type_kind (dhandle
, rtype
) == DEBUG_KIND_POINTER
)
2038 /* Set up the return type as an indirect type pointing to
2039 the variable slot, so that we can change it to a
2040 reference later if appropriate. */
2041 pv
->pslot
= (debug_type
*) xmalloc (sizeof *pv
->pslot
);
2043 rtype
= debug_make_indirect_type (dhandle
, pv
->pslot
,
2044 (const char *) NULL
);
2047 type
= debug_make_function_type (dhandle
, rtype
, arg_types
, varargs
);
2052 /* Record the type in the table. */
2054 if (type
== DEBUG_TYPE_NULL
)
2057 info
->vars
.vars
[varindx
].type
= type
;
2060 && info
->vars
.vars
[varindx
].namlen
> 0)
2064 name
= savestring (info
->vars
.vars
[varindx
].name
,
2065 info
->vars
.vars
[varindx
].namlen
);
2067 type
= debug_name_type (dhandle
, name
, type
);
2068 else if (tc
== 'E' || tc
== 'N')
2069 type
= debug_tag_type (dhandle
, name
, type
);
2072 struct ieee_tag
*it
;
2074 /* We must allocate all struct tags as indirect types, so
2075 that if we later see a definition of the tag as a C++
2076 record we can update the indirect slot and automatically
2077 change all the existing references. */
2078 it
= (struct ieee_tag
*) xmalloc (sizeof *it
);
2079 memset (it
, 0, sizeof *it
);
2080 it
->next
= info
->tags
;
2085 type
= debug_make_indirect_type (dhandle
, &it
->slot
, name
);
2086 type
= debug_tag_type (dhandle
, name
, type
);
2094 info
->types
.types
[typeindx
].type
= type
;
2095 info
->types
.types
[typeindx
].arg_slots
= arg_slots
;
2096 info
->types
.types
[typeindx
].bitsize
= type_bitsize
;
2098 /* We may have already allocated type as an indirect type pointing
2099 to slot. It does no harm to replace the indirect type with the
2100 real type. Filling in slot as well handles the indirect types
2101 which are already hanging around. */
2102 if (info
->types
.types
[typeindx
].pslot
!= NULL
)
2103 *info
->types
.types
[typeindx
].pslot
= type
;
2108 /* Parse an ATN record. */
2111 parse_ieee_atn (info
, pp
)
2112 struct ieee_info
*info
;
2113 const bfd_byte
**pp
;
2115 const bfd_byte
*atn_start
, *atn_code_start
;
2117 struct ieee_var
*pvar
;
2121 bfd_vma v
, v2
, v3
, v4
, v5
;
2123 unsigned long namlen
;
2130 if (! ieee_read_number (info
, pp
, &varindx
)
2131 || ! ieee_read_type_index (info
, pp
, &type
))
2134 atn_code_start
= *pp
;
2136 if (! ieee_read_number (info
, pp
, &atn_code
))
2145 else if (varindx
< 32)
2147 /* The MRI compiler reportedly sometimes emits variable lifetime
2148 information for a register. We just ignore it. */
2150 return ieee_read_number (info
, pp
, &v
);
2152 ieee_error (info
, atn_start
, _("illegal variable index"));
2158 if (varindx
>= info
->vars
.alloc
2159 || info
->vars
.vars
[varindx
].name
== NULL
)
2161 /* The MRI compiler or linker sometimes omits the NN record
2162 for a pmisc record. */
2165 if (varindx
>= info
->vars
.alloc
)
2169 alloc
= info
->vars
.alloc
;
2172 while (varindx
>= alloc
)
2174 info
->vars
.vars
= ((struct ieee_var
*)
2175 xrealloc (info
->vars
.vars
,
2177 * sizeof *info
->vars
.vars
)));
2178 memset (info
->vars
.vars
+ info
->vars
.alloc
, 0,
2179 ((alloc
- info
->vars
.alloc
)
2180 * sizeof *info
->vars
.vars
));
2181 info
->vars
.alloc
= alloc
;
2184 pvar
= info
->vars
.vars
+ varindx
;
2190 ieee_error (info
, atn_start
, _("undefined variable in ATN"));
2195 pvar
= info
->vars
.vars
+ varindx
;
2200 namlen
= pvar
->namlen
;
2203 dhandle
= info
->dhandle
;
2205 /* If we are going to call debug_record_variable with a pointer
2206 type, change the type to an indirect type so that we can later
2207 change it to a reference type if we encounter a C++ pmisc 'R'
2210 && type
!= DEBUG_TYPE_NULL
2211 && debug_get_type_kind (dhandle
, type
) == DEBUG_KIND_POINTER
)
2221 pvar
->pslot
= (debug_type
*) xmalloc (sizeof *pvar
->pslot
);
2222 *pvar
->pslot
= type
;
2223 type
= debug_make_indirect_type (dhandle
, pvar
->pslot
,
2224 (const char *) NULL
);
2233 ieee_error (info
, atn_code_start
, _("unknown ATN type"));
2237 /* Automatic variable. */
2238 if (! ieee_read_number (info
, pp
, &v
))
2240 namcopy
= savestring (name
, namlen
);
2242 type
= debug_make_void_type (dhandle
);
2244 pvar
->kind
= IEEE_LOCAL
;
2245 return debug_record_variable (dhandle
, namcopy
, type
, DEBUG_LOCAL
, v
);
2248 /* Register variable. */
2249 if (! ieee_read_number (info
, pp
, &v
))
2251 namcopy
= savestring (name
, namlen
);
2253 type
= debug_make_void_type (dhandle
);
2255 pvar
->kind
= IEEE_LOCAL
;
2256 return debug_record_variable (dhandle
, namcopy
, type
, DEBUG_REGISTER
,
2257 ieee_regno_to_genreg (info
->abfd
, v
));
2260 /* Static variable. */
2261 if (! ieee_require_asn (info
, pp
, &v
))
2263 namcopy
= savestring (name
, namlen
);
2265 type
= debug_make_void_type (dhandle
);
2266 if (info
->blockstack
.bsp
<= info
->blockstack
.stack
)
2269 blocktype
= info
->blockstack
.bsp
[-1].kind
;
2272 if (blocktype
== 4 || blocktype
== 6)
2273 pvar
->kind
= IEEE_LOCAL
;
2275 pvar
->kind
= IEEE_STATIC
;
2277 return debug_record_variable (dhandle
, namcopy
, type
,
2278 (blocktype
== 4 || blocktype
== 6
2279 ? DEBUG_LOCAL_STATIC
2284 /* External function. We don't currently record these. FIXME. */
2286 pvar
->kind
= IEEE_EXTERNAL
;
2290 /* External variable. We don't currently record these. FIXME. */
2292 pvar
->kind
= IEEE_EXTERNAL
;
2296 if (! ieee_read_number (info
, pp
, &v
)
2297 || ! ieee_read_number (info
, pp
, &v2
)
2298 || ! ieee_read_optional_number (info
, pp
, &v3
, &present
))
2302 if (! ieee_read_optional_number (info
, pp
, &v4
, &present
))
2306 /* We just ignore the two optional fields in v3 and v4, since
2307 they are not defined. */
2309 if (! ieee_require_asn (info
, pp
, &v3
))
2312 /* We have no way to record the column number. FIXME. */
2314 return debug_record_line (dhandle
, v
, v3
);
2317 /* Global variable. */
2318 if (! ieee_require_asn (info
, pp
, &v
))
2320 namcopy
= savestring (name
, namlen
);
2322 type
= debug_make_void_type (dhandle
);
2324 pvar
->kind
= IEEE_GLOBAL
;
2325 return debug_record_variable (dhandle
, namcopy
, type
, DEBUG_GLOBAL
, v
);
2328 /* Variable lifetime information. */
2329 if (! ieee_read_number (info
, pp
, &v
))
2332 /* We have no way to record this information. FIXME. */
2336 /* Locked register. The spec says that there are two required
2337 fields, but at least on occasion the MRI compiler only emits
2339 if (! ieee_read_number (info
, pp
, &v
)
2340 || ! ieee_read_optional_number (info
, pp
, &v2
, &present
))
2343 /* I think this means a variable that is both in a register and
2344 a frame slot. We ignore the frame slot. FIXME. */
2346 namcopy
= savestring (name
, namlen
);
2348 type
= debug_make_void_type (dhandle
);
2350 pvar
->kind
= IEEE_LOCAL
;
2351 return debug_record_variable (dhandle
, namcopy
, type
, DEBUG_REGISTER
, v
);
2354 /* Reserved for FORTRAN common. */
2355 ieee_error (info
, atn_code_start
, _("unsupported ATN11"));
2357 /* Return true to keep going. */
2361 /* Based variable. */
2365 if (! ieee_read_number (info
, pp
, &v
)
2366 || ! ieee_read_number (info
, pp
, &v2
)
2367 || ! ieee_read_optional_number (info
, pp
, &v3
, &present
))
2371 if (! ieee_read_optional_number (info
, pp
, &v4
, &present
))
2375 if (! ieee_read_optional_number (info
, pp
, &v5
, &present
))
2380 /* We have no way to record this information. FIXME. */
2382 ieee_error (info
, atn_code_start
, _("unsupported ATN12"));
2384 /* Return true to keep going. */
2388 /* Constant. The description of this that I have is ambiguous,
2389 so I'm not going to try to implement it. */
2390 if (! ieee_read_number (info
, pp
, &v
)
2391 || ! ieee_read_optional_number (info
, pp
, &v2
, &present
))
2395 if (! ieee_read_optional_number (info
, pp
, &v2
, &present
))
2399 if (! ieee_read_optional_id (info
, pp
, &name
, &namlen
, &present
))
2404 if ((ieee_record_enum_type
) **pp
== ieee_e2_first_byte_enum
)
2406 if (! ieee_require_asn (info
, pp
, &v3
))
2413 /* Static variable from assembler. */
2415 if (! ieee_read_number (info
, pp
, &v
)
2416 || ! ieee_read_optional_number (info
, pp
, &v2
, &present
)
2417 || ! ieee_require_asn (info
, pp
, &v3
))
2419 namcopy
= savestring (name
, namlen
);
2420 /* We don't really handle this correctly. FIXME. */
2421 return debug_record_variable (dhandle
, namcopy
,
2422 debug_make_void_type (dhandle
),
2423 v2
!= 0 ? DEBUG_GLOBAL
: DEBUG_STATIC
,
2427 /* Procedure miscellaneous information. */
2429 /* Variable miscellaneous information. */
2431 /* Module miscellaneous information. */
2432 if (! ieee_read_number (info
, pp
, &v
)
2433 || ! ieee_read_number (info
, pp
, &v2
)
2434 || ! ieee_read_optional_id (info
, pp
, &name
, &namlen
, &present
))
2437 if (atn_code
== 62 && v
== 80)
2441 ieee_error (info
, atn_code_start
,
2442 _("unexpected string in C++ misc"));
2445 return ieee_read_cxx_misc (info
, pp
, v2
);
2448 /* We just ignore all of this stuff. FIXME. */
2450 for (; v2
> 0; --v2
)
2452 switch ((ieee_record_enum_type
) **pp
)
2455 ieee_error (info
, *pp
, _("bad misc record"));
2458 case ieee_at_record_enum
:
2459 if (! ieee_require_atn65 (info
, pp
, &name
, &namlen
))
2463 case ieee_e2_first_byte_enum
:
2464 if (! ieee_require_asn (info
, pp
, &v3
))
2476 /* Handle C++ debugging miscellaneous records. This is called for
2477 procedure miscellaneous records of type 80. */
2480 ieee_read_cxx_misc (info
, pp
, count
)
2481 struct ieee_info
*info
;
2482 const bfd_byte
**pp
;
2483 unsigned long count
;
2485 const bfd_byte
*start
;
2490 /* Get the category of C++ misc record. */
2491 if (! ieee_require_asn (info
, pp
, &category
))
2498 ieee_error (info
, start
, _("unrecognized C++ misc record"));
2502 if (! ieee_read_cxx_class (info
, pp
, count
))
2510 unsigned long namlen
;
2512 /* The IEEE spec indicates that the 'M' record only has a
2513 flags field. The MRI compiler also emits the name of the
2516 if (! ieee_require_asn (info
, pp
, &flags
))
2518 if (*pp
< info
->pend
2519 && (ieee_record_enum_type
) **pp
== ieee_at_record_enum
)
2521 if (! ieee_require_atn65 (info
, pp
, &name
, &namlen
))
2525 /* This is emitted for method functions, but I don't think we
2526 care very much. It might help if it told us useful
2527 information like the class with which this function is
2528 associated, but it doesn't, so it isn't helpful. */
2533 if (! ieee_read_cxx_defaults (info
, pp
, count
))
2539 const char *name
, *mangled
, *class;
2540 unsigned long namlen
, mangledlen
, classlen
;
2543 /* Pointer to member. */
2545 if (! ieee_require_atn65 (info
, pp
, &name
, &namlen
)
2546 || ! ieee_require_atn65 (info
, pp
, &mangled
, &mangledlen
)
2547 || ! ieee_require_atn65 (info
, pp
, &class, &classlen
)
2548 || ! ieee_require_asn (info
, pp
, &control
))
2551 /* FIXME: We should now track down name and change its type. */
2556 if (! ieee_read_reference (info
, pp
))
2564 /* Read a C++ class definition. This is a pmisc type 80 record of
2568 ieee_read_cxx_class (info
, pp
, count
)
2569 struct ieee_info
*info
;
2570 const bfd_byte
**pp
;
2571 unsigned long count
;
2573 const bfd_byte
*start
;
2576 unsigned long taglen
;
2577 struct ieee_tag
*it
;
2579 debug_field
*fields
;
2580 unsigned int field_count
, field_alloc
;
2581 debug_baseclass
*baseclasses
;
2582 unsigned int baseclasses_count
, baseclasses_alloc
;
2583 const debug_field
*structfields
;
2587 unsigned long namlen
;
2588 debug_method_variant
*variants
;
2592 unsigned int methods_count
, methods_alloc
;
2593 debug_type vptrbase
;
2595 debug_method
*dmethods
;
2599 if (! ieee_require_asn (info
, pp
, &class))
2603 if (! ieee_require_atn65 (info
, pp
, &tag
, &taglen
))
2607 /* Find the C struct with this name. */
2608 for (it
= info
->tags
; it
!= NULL
; it
= it
->next
)
2609 if (it
->name
[0] == tag
[0]
2610 && strncmp (it
->name
, tag
, taglen
) == 0
2611 && strlen (it
->name
) == taglen
)
2615 ieee_error (info
, start
, _("undefined C++ object"));
2619 dhandle
= info
->dhandle
;
2625 baseclasses_count
= 0;
2626 baseclasses_alloc
= 0;
2630 vptrbase
= DEBUG_TYPE_NULL
;
2633 structfields
= debug_get_fields (dhandle
, it
->type
);
2638 const bfd_byte
*spec_start
;
2642 if (! ieee_require_asn (info
, pp
, &id
))
2649 ieee_error (info
, spec_start
, _("unrecognized C++ object spec"));
2654 bfd_vma flags
, cinline
;
2655 const char *basename
, *fieldname
;
2656 unsigned long baselen
, fieldlen
;
2658 debug_type basetype
;
2661 enum debug_visibility visibility
;
2662 debug_baseclass baseclass
;
2664 /* This represents a base or friend class. */
2666 if (! ieee_require_asn (info
, pp
, &flags
)
2667 || ! ieee_require_atn65 (info
, pp
, &basename
, &baselen
)
2668 || ! ieee_require_asn (info
, pp
, &cinline
)
2669 || ! ieee_require_atn65 (info
, pp
, &fieldname
, &fieldlen
))
2673 /* We have no way of recording friend information, so we
2675 if ((flags
& BASEFLAGS_FRIEND
) != 0)
2678 /* I assume that either all of the members of the
2679 baseclass are included in the object, starting at the
2680 beginning of the object, or that none of them are
2683 if ((fieldlen
== 0) == (cinline
== 0))
2685 ieee_error (info
, start
, _("unsupported C++ object type"));
2689 basecopy
= savestring (basename
, baselen
);
2690 basetype
= debug_find_tagged_type (dhandle
, basecopy
,
2691 DEBUG_KIND_ILLEGAL
);
2693 if (basetype
== DEBUG_TYPE_NULL
)
2695 ieee_error (info
, start
, _("C++ base class not defined"));
2703 const debug_field
*pf
;
2705 if (structfields
== NULL
)
2707 ieee_error (info
, start
, _("C++ object has no fields"));
2711 for (pf
= structfields
; *pf
!= DEBUG_FIELD_NULL
; pf
++)
2715 fname
= debug_get_field_name (dhandle
, *pf
);
2718 if (fname
[0] == fieldname
[0]
2719 && strncmp (fname
, fieldname
, fieldlen
) == 0
2720 && strlen (fname
) == fieldlen
)
2723 if (*pf
== DEBUG_FIELD_NULL
)
2725 ieee_error (info
, start
,
2726 _("C++ base class not found in container"));
2730 bitpos
= debug_get_field_bitpos (dhandle
, *pf
);
2733 if ((flags
& BASEFLAGS_VIRTUAL
) != 0)
2737 if ((flags
& BASEFLAGS_PRIVATE
) != 0)
2738 visibility
= DEBUG_VISIBILITY_PRIVATE
;
2740 visibility
= DEBUG_VISIBILITY_PUBLIC
;
2742 baseclass
= debug_make_baseclass (dhandle
, basetype
, bitpos
,
2743 virtualp
, visibility
);
2744 if (baseclass
== DEBUG_BASECLASS_NULL
)
2747 if (baseclasses_count
+ 1 >= baseclasses_alloc
)
2749 baseclasses_alloc
+= 10;
2750 baseclasses
= ((debug_baseclass
*)
2751 xrealloc (baseclasses
,
2753 * sizeof *baseclasses
)));
2756 baseclasses
[baseclasses_count
] = baseclass
;
2757 ++baseclasses_count
;
2758 baseclasses
[baseclasses_count
] = DEBUG_BASECLASS_NULL
;
2765 const char *fieldname
, *mangledname
;
2766 unsigned long fieldlen
, mangledlen
;
2770 const debug_field
*pf
= NULL
;
2771 enum debug_visibility visibility
;
2774 /* This represents a data member. */
2776 if (! ieee_require_asn (info
, pp
, &flags
)
2777 || ! ieee_require_atn65 (info
, pp
, &fieldname
, &fieldlen
)
2778 || ! ieee_require_atn65 (info
, pp
, &mangledname
, &mangledlen
))
2782 fieldcopy
= savestring (fieldname
, fieldlen
);
2784 staticp
= (flags
& CXXFLAGS_STATIC
) != 0 ? true : false;
2788 struct ieee_var
*pv
, *pvend
;
2790 /* See if we can find a definition for this variable. */
2791 pv
= info
->vars
.vars
;
2792 pvend
= pv
+ info
->vars
.alloc
;
2793 for (; pv
< pvend
; pv
++)
2794 if (pv
->namlen
== mangledlen
2795 && strncmp (pv
->name
, mangledname
, mangledlen
) == 0)
2801 /* This can happen if the variable is never used. */
2802 ftype
= ieee_builtin_type (info
, start
,
2803 (unsigned int) builtin_void
);
2810 if (structfields
== NULL
)
2812 ieee_error (info
, start
, _("C++ object has no fields"));
2816 for (pf
= structfields
, findx
= 0;
2817 *pf
!= DEBUG_FIELD_NULL
;
2822 fname
= debug_get_field_name (dhandle
, *pf
);
2825 if (fname
[0] == mangledname
[0]
2826 && strncmp (fname
, mangledname
, mangledlen
) == 0
2827 && strlen (fname
) == mangledlen
)
2830 if (*pf
== DEBUG_FIELD_NULL
)
2832 ieee_error (info
, start
,
2833 _("C++ data member not found in container"));
2837 ftype
= debug_get_field_type (dhandle
, *pf
);
2839 if (debug_get_type_kind (dhandle
, ftype
) == DEBUG_KIND_POINTER
)
2841 /* We might need to convert this field into a
2842 reference type later on, so make it an indirect
2844 if (it
->fslots
== NULL
)
2847 const debug_field
*pfcnt
;
2850 for (pfcnt
= structfields
;
2851 *pfcnt
!= DEBUG_FIELD_NULL
;
2854 it
->fslots
= ((debug_type
*)
2855 xmalloc (fcnt
* sizeof *it
->fslots
));
2856 memset (it
->fslots
, 0,
2857 fcnt
* sizeof *it
->fslots
);
2860 if (ftype
== DEBUG_TYPE_NULL
)
2862 it
->fslots
[findx
] = ftype
;
2863 ftype
= debug_make_indirect_type (dhandle
,
2865 (const char *) NULL
);
2868 if (ftype
== DEBUG_TYPE_NULL
)
2871 switch (flags
& CXXFLAGS_VISIBILITY
)
2874 ieee_error (info
, start
, _("unknown C++ visibility"));
2877 case CXXFLAGS_VISIBILITY_PUBLIC
:
2878 visibility
= DEBUG_VISIBILITY_PUBLIC
;
2881 case CXXFLAGS_VISIBILITY_PRIVATE
:
2882 visibility
= DEBUG_VISIBILITY_PRIVATE
;
2885 case CXXFLAGS_VISIBILITY_PROTECTED
:
2886 visibility
= DEBUG_VISIBILITY_PROTECTED
;
2894 mangledcopy
= savestring (mangledname
, mangledlen
);
2896 field
= debug_make_static_member (dhandle
, fieldcopy
,
2902 bfd_vma bitpos
, bitsize
;
2904 bitpos
= debug_get_field_bitpos (dhandle
, *pf
);
2905 bitsize
= debug_get_field_bitsize (dhandle
, *pf
);
2906 if (bitpos
== (bfd_vma
) -1 || bitsize
== (bfd_vma
) -1)
2908 ieee_error (info
, start
, _("bad C++ field bit pos or size"));
2911 field
= debug_make_field (dhandle
, fieldcopy
, ftype
, bitpos
,
2912 bitsize
, visibility
);
2915 if (field
== DEBUG_FIELD_NULL
)
2918 if (field_count
+ 1 >= field_alloc
)
2921 fields
= ((debug_field
*)
2922 xrealloc (fields
, field_alloc
* sizeof *fields
));
2925 fields
[field_count
] = field
;
2927 fields
[field_count
] = DEBUG_FIELD_NULL
;
2934 bfd_vma flags
, voffset
, control
;
2935 const char *name
, *mangled
;
2936 unsigned long namlen
, mangledlen
;
2937 struct ieee_var
*pv
, *pvend
;
2939 enum debug_visibility visibility
;
2940 boolean constp
, volatilep
;
2942 debug_method_variant mv
;
2943 struct ieee_method
*meth
;
2946 if (! ieee_require_asn (info
, pp
, &flags
)
2947 || ! ieee_require_atn65 (info
, pp
, &name
, &namlen
)
2948 || ! ieee_require_atn65 (info
, pp
, &mangled
, &mangledlen
))
2955 if (! ieee_require_asn (info
, pp
, &voffset
))
2959 if (! ieee_require_asn (info
, pp
, &control
))
2963 /* We just ignore the control information. */
2965 /* We have no way to represent friend information, so we
2967 if ((flags
& CXXFLAGS_FRIEND
) != 0)
2970 /* We should already have seen a type for the function. */
2971 pv
= info
->vars
.vars
;
2972 pvend
= pv
+ info
->vars
.alloc
;
2973 for (; pv
< pvend
; pv
++)
2974 if (pv
->namlen
== mangledlen
2975 && strncmp (pv
->name
, mangled
, mangledlen
) == 0)
2980 /* We won't have type information for this function if
2981 it is not included in this file. We don't try to
2982 handle this case. FIXME. */
2983 type
= (debug_make_function_type
2985 ieee_builtin_type (info
, start
,
2986 (unsigned int) builtin_void
),
2987 (debug_type
*) NULL
,
2992 debug_type return_type
;
2993 const debug_type
*arg_types
;
2996 if (debug_get_type_kind (dhandle
, pv
->type
)
2997 != DEBUG_KIND_FUNCTION
)
2999 ieee_error (info
, start
,
3000 _("bad type for C++ method function"));
3004 return_type
= debug_get_return_type (dhandle
, pv
->type
);
3005 arg_types
= debug_get_parameter_types (dhandle
, pv
->type
,
3007 if (return_type
== DEBUG_TYPE_NULL
|| arg_types
== NULL
)
3009 ieee_error (info
, start
,
3010 _("no type information for C++ method function"));
3014 type
= debug_make_method_type (dhandle
, return_type
, it
->type
,
3015 (debug_type
*) arg_types
,
3018 if (type
== DEBUG_TYPE_NULL
)
3021 switch (flags
& CXXFLAGS_VISIBILITY
)
3024 ieee_error (info
, start
, _("unknown C++ visibility"));
3027 case CXXFLAGS_VISIBILITY_PUBLIC
:
3028 visibility
= DEBUG_VISIBILITY_PUBLIC
;
3031 case CXXFLAGS_VISIBILITY_PRIVATE
:
3032 visibility
= DEBUG_VISIBILITY_PRIVATE
;
3035 case CXXFLAGS_VISIBILITY_PROTECTED
:
3036 visibility
= DEBUG_VISIBILITY_PROTECTED
;
3040 constp
= (flags
& CXXFLAGS_CONST
) != 0 ? true : false;
3041 volatilep
= (flags
& CXXFLAGS_VOLATILE
) != 0 ? true : false;
3043 mangledcopy
= savestring (mangled
, mangledlen
);
3045 if ((flags
& CXXFLAGS_STATIC
) != 0)
3049 ieee_error (info
, start
, _("C++ static virtual method"));
3052 mv
= debug_make_static_method_variant (dhandle
, mangledcopy
,
3058 debug_type vcontext
;
3061 vcontext
= DEBUG_TYPE_NULL
;
3064 /* FIXME: How can we calculate this correctly? */
3065 vcontext
= it
->type
;
3067 mv
= debug_make_method_variant (dhandle
, mangledcopy
, type
,
3072 if (mv
== DEBUG_METHOD_VARIANT_NULL
)
3075 for (meth
= methods
, im
= 0; im
< methods_count
; meth
++, im
++)
3076 if (meth
->namlen
== namlen
3077 && strncmp (meth
->name
, name
, namlen
) == 0)
3079 if (im
>= methods_count
)
3081 if (methods_count
>= methods_alloc
)
3083 methods_alloc
+= 10;
3084 methods
= ((struct ieee_method
*)
3086 methods_alloc
* sizeof *methods
));
3088 methods
[methods_count
].name
= name
;
3089 methods
[methods_count
].namlen
= namlen
;
3090 methods
[methods_count
].variants
= NULL
;
3091 methods
[methods_count
].count
= 0;
3092 methods
[methods_count
].alloc
= 0;
3093 meth
= methods
+ methods_count
;
3097 if (meth
->count
+ 1 >= meth
->alloc
)
3100 meth
->variants
= ((debug_method_variant
*)
3101 xrealloc (meth
->variants
,
3103 * sizeof *meth
->variants
)));
3106 meth
->variants
[meth
->count
] = mv
;
3108 meth
->variants
[meth
->count
] = DEBUG_METHOD_VARIANT_NULL
;
3116 /* We have no way to store this information, so we just
3118 if (! ieee_require_asn (info
, pp
, &spec
))
3121 if ((spec
& 4) != 0)
3123 const char *filename
;
3124 unsigned long filenamlen
;
3127 if (! ieee_require_atn65 (info
, pp
, &filename
, &filenamlen
)
3128 || ! ieee_require_asn (info
, pp
, &lineno
))
3132 else if ((spec
& 8) != 0)
3134 const char *mangled
;
3135 unsigned long mangledlen
;
3137 if (! ieee_require_atn65 (info
, pp
, &mangled
, &mangledlen
))
3143 ieee_error (info
, start
,
3144 _("unrecognized C++ object overhead spec"));
3152 const char *vname
, *basename
;
3153 unsigned long vnamelen
, baselen
;
3154 bfd_vma vsize
, control
;
3156 /* A virtual table pointer. */
3158 if (! ieee_require_atn65 (info
, pp
, &vname
, &vnamelen
)
3159 || ! ieee_require_asn (info
, pp
, &vsize
)
3160 || ! ieee_require_atn65 (info
, pp
, &basename
, &baselen
)
3161 || ! ieee_require_asn (info
, pp
, &control
))
3165 /* We just ignore the control number. We don't care what
3166 the virtual table name is. We have no way to store the
3167 virtual table size, and I don't think we care anyhow. */
3169 /* FIXME: We can't handle multiple virtual table pointers. */
3177 basecopy
= savestring (basename
, baselen
);
3178 vptrbase
= debug_find_tagged_type (dhandle
, basecopy
,
3179 DEBUG_KIND_ILLEGAL
);
3181 if (vptrbase
== DEBUG_TYPE_NULL
)
3183 ieee_error (info
, start
, _("undefined C++ vtable"));
3192 /* Now that we have seen all the method variants, we can call
3193 debug_make_method for each one. */
3195 if (methods_count
== 0)
3201 dmethods
= ((debug_method
*)
3202 xmalloc ((methods_count
+ 1) * sizeof *dmethods
));
3203 for (i
= 0; i
< methods_count
; i
++)
3207 namcopy
= savestring (methods
[i
].name
, methods
[i
].namlen
);
3208 dmethods
[i
] = debug_make_method (dhandle
, namcopy
,
3209 methods
[i
].variants
);
3210 if (dmethods
[i
] == DEBUG_METHOD_NULL
)
3213 dmethods
[i
] = DEBUG_METHOD_NULL
;
3217 /* The struct type was created as an indirect type pointing at
3218 it->slot. We update it->slot to automatically update all
3219 references to this struct. */
3220 it
->slot
= debug_make_object_type (dhandle
,
3222 debug_get_type_size (dhandle
,
3224 fields
, baseclasses
, dmethods
,
3226 if (it
->slot
== DEBUG_TYPE_NULL
)
3232 /* Read C++ default argument value and reference type information. */
3235 ieee_read_cxx_defaults (info
, pp
, count
)
3236 struct ieee_info
*info
;
3237 const bfd_byte
**pp
;
3238 unsigned long count
;
3240 const bfd_byte
*start
;
3242 unsigned long fnlen
;
3247 /* Giving the function name before the argument count is an addendum
3248 to the spec. The function name is demangled, though, so this
3249 record must always refer to the current function. */
3251 if (info
->blockstack
.bsp
<= info
->blockstack
.stack
3252 || info
->blockstack
.bsp
[-1].fnindx
== (unsigned int) -1)
3254 ieee_error (info
, start
, _("C++ default values not in a function"));
3258 if (! ieee_require_atn65 (info
, pp
, &fnname
, &fnlen
)
3259 || ! ieee_require_asn (info
, pp
, &defcount
))
3263 while (defcount
-- > 0)
3267 unsigned long strvallen
;
3269 if (! ieee_require_asn (info
, pp
, &type
))
3281 if (! ieee_require_asn (info
, pp
, &val
))
3288 if (! ieee_require_atn65 (info
, pp
, &strval
, &strvallen
))
3294 ieee_error (info
, start
, _("unrecognized C++ default type"));
3298 /* We have no way to record the default argument values, so we
3299 just ignore them. FIXME. */
3302 /* Any remaining arguments are indices of parameters that are really
3307 debug_type
*arg_slots
;
3309 dhandle
= info
->dhandle
;
3310 arg_slots
= info
->types
.types
[info
->blockstack
.bsp
[-1].fnindx
].arg_slots
;
3316 if (! ieee_require_asn (info
, pp
, &indx
))
3318 /* The index is 1 based. */
3320 if (arg_slots
== NULL
3321 || arg_slots
[indx
] == DEBUG_TYPE_NULL
3322 || (debug_get_type_kind (dhandle
, arg_slots
[indx
])
3323 != DEBUG_KIND_POINTER
))
3325 ieee_error (info
, start
, _("reference parameter is not a pointer"));
3329 target
= debug_get_target_type (dhandle
, arg_slots
[indx
]);
3330 arg_slots
[indx
] = debug_make_reference_type (dhandle
, target
);
3331 if (arg_slots
[indx
] == DEBUG_TYPE_NULL
)
3339 /* Read a C++ reference definition. */
3342 ieee_read_reference (info
, pp
)
3343 struct ieee_info
*info
;
3344 const bfd_byte
**pp
;
3346 const bfd_byte
*start
;
3348 const char *class, *name
;
3349 unsigned long classlen
, namlen
;
3355 if (! ieee_require_asn (info
, pp
, &flags
))
3358 /* Giving the class name before the member name is in an addendum to
3362 if (! ieee_require_atn65 (info
, pp
, &class, &classlen
))
3366 if (! ieee_require_atn65 (info
, pp
, &name
, &namlen
))
3374 /* We search from the last variable indices to the first in
3375 hopes of finding local variables correctly. We search the
3376 local variables on the first pass, and the global variables
3377 on the second. FIXME: This probably won't work in all cases.
3378 On the other hand, I don't know what will. */
3379 for (pass
= 0; pass
< 2; pass
++)
3381 struct ieee_vars
*vars
;
3383 struct ieee_var
*pv
= NULL
;
3389 vars
= info
->global_vars
;
3394 for (i
= (int) vars
->alloc
- 1; i
>= 0; i
--)
3398 pv
= vars
->vars
+ i
;
3400 if (pv
->pslot
== NULL
3401 || pv
->namlen
!= namlen
3402 || strncmp (pv
->name
, name
, namlen
) != 0)
3409 ieee_error (info
, start
,
3410 _("unrecognized C++ reference type"));
3414 /* Global variable or function. */
3415 if (pv
->kind
== IEEE_GLOBAL
3416 || pv
->kind
== IEEE_EXTERNAL
3417 || pv
->kind
== IEEE_FUNCTION
)
3422 /* Global static variable or function. */
3423 if (pv
->kind
== IEEE_STATIC
3424 || pv
->kind
== IEEE_FUNCTION
)
3429 /* Local variable. */
3430 if (pv
->kind
== IEEE_LOCAL
)
3448 struct ieee_tag
*it
;
3450 for (it
= info
->tags
; it
!= NULL
; it
= it
->next
)
3452 if (it
->name
[0] == class[0]
3453 && strncmp (it
->name
, class, classlen
) == 0
3454 && strlen (it
->name
) == classlen
)
3456 if (it
->fslots
!= NULL
)
3458 const debug_field
*pf
;
3461 pf
= debug_get_fields (info
->dhandle
, it
->type
);
3464 ieee_error (info
, start
,
3465 "C++ reference in class with no fields");
3469 for (findx
= 0; *pf
!= DEBUG_FIELD_NULL
; pf
++, findx
++)
3473 fname
= debug_get_field_name (info
->dhandle
, *pf
);
3476 if (strncmp (fname
, name
, namlen
) == 0
3477 && strlen (fname
) == namlen
)
3479 pslot
= it
->fslots
+ findx
;
3492 ieee_error (info
, start
, _("C++ reference not found"));
3496 /* We allocated the type of the object as an indirect type pointing
3497 to *pslot, which we can now update to be a reference type. */
3498 if (debug_get_type_kind (info
->dhandle
, *pslot
) != DEBUG_KIND_POINTER
)
3500 ieee_error (info
, start
, _("C++ reference is not pointer"));
3504 target
= debug_get_target_type (info
->dhandle
, *pslot
);
3505 *pslot
= debug_make_reference_type (info
->dhandle
, target
);
3506 if (*pslot
== DEBUG_TYPE_NULL
)
3512 /* Require an ASN record. */
3515 ieee_require_asn (info
, pp
, pv
)
3516 struct ieee_info
*info
;
3517 const bfd_byte
**pp
;
3520 const bfd_byte
*start
;
3521 ieee_record_enum_type c
;
3526 c
= (ieee_record_enum_type
) **pp
;
3527 if (c
!= ieee_e2_first_byte_enum
)
3529 ieee_error (info
, start
, _("missing required ASN"));
3534 c
= (ieee_record_enum_type
) (((unsigned int) c
<< 8) | **pp
);
3535 if (c
!= ieee_asn_record_enum
)
3537 ieee_error (info
, start
, _("missing required ASN"));
3542 /* Just ignore the variable index. */
3543 if (! ieee_read_number (info
, pp
, &varindx
))
3546 return ieee_read_expression (info
, pp
, pv
);
3549 /* Require an ATN65 record. */
3552 ieee_require_atn65 (info
, pp
, pname
, pnamlen
)
3553 struct ieee_info
*info
;
3554 const bfd_byte
**pp
;
3556 unsigned long *pnamlen
;
3558 const bfd_byte
*start
;
3559 ieee_record_enum_type c
;
3560 bfd_vma name_indx
, type_indx
, atn_code
;
3564 c
= (ieee_record_enum_type
) **pp
;
3565 if (c
!= ieee_at_record_enum
)
3567 ieee_error (info
, start
, _("missing required ATN65"));
3572 c
= (ieee_record_enum_type
) (((unsigned int) c
<< 8) | **pp
);
3573 if (c
!= ieee_atn_record_enum
)
3575 ieee_error (info
, start
, _("missing required ATN65"));
3580 if (! ieee_read_number (info
, pp
, &name_indx
)
3581 || ! ieee_read_number (info
, pp
, &type_indx
)
3582 || ! ieee_read_number (info
, pp
, &atn_code
))
3585 /* Just ignore name_indx. */
3587 if (type_indx
!= 0 || atn_code
!= 65)
3589 ieee_error (info
, start
, _("bad ATN65 record"));
3593 return ieee_read_id (info
, pp
, pname
, pnamlen
);
3596 /* Convert a register number in IEEE debugging information into a
3597 generic register number. */
3600 ieee_regno_to_genreg (abfd
, r
)
3604 switch (bfd_get_arch (abfd
))
3607 /* For some reasons stabs adds 2 to the floating point register
3614 /* Stabs uses 0 to 15 for r0 to r15, 16 to 31 for g0 to g15, and
3615 32 to 35 for fp0 to fp3. */
3626 /* Convert a generic register number to an IEEE specific one. */
3629 ieee_genreg_to_regno (abfd
, r
)
3633 switch (bfd_get_arch (abfd
))
3636 /* For some reason stabs add 2 to the floating point register
3643 /* Stabs uses 0 to 15 for r0 to r15, 16 to 31 for g0 to g15, and
3644 32 to 35 for fp0 to fp3. */
3655 /* These routines build IEEE debugging information out of the generic
3656 debugging information. */
3658 /* We build the IEEE debugging information byte by byte. Rather than
3659 waste time copying data around, we use a linked list of buffers to
3662 #define IEEE_BUFSIZE (490)
3667 struct ieee_buf
*next
;
3668 /* Number of data bytes in this buffer. */
3671 bfd_byte buf
[IEEE_BUFSIZE
];
3674 /* A list of buffers. */
3679 struct ieee_buf
*head
;
3680 /* Tail--last buffer on list. */
3681 struct ieee_buf
*tail
;
3684 /* In order to generate the BB11 blocks required by the HP emulator,
3685 we keep track of ranges of addresses which correspond to a given
3686 compilation unit. */
3691 struct ieee_range
*next
;
3698 /* This structure holds information for a class on the type stack. */
3700 struct ieee_type_class
3702 /* The name index in the debugging information. */
3704 /* The pmisc records for the class. */
3705 struct ieee_buflist pmiscbuf
;
3706 /* The number of pmisc records. */
3707 unsigned int pmisccount
;
3708 /* The name of the class holding the virtual table, if not this
3711 /* Whether this class holds its own virtual table. */
3713 /* The largest virtual table offset seen so far. */
3715 /* The current method. */
3717 /* Additional pmisc records used to record fields of reference type. */
3718 struct ieee_buflist refs
;
3721 /* This is how we store types for the writing routines. Most types
3722 are simply represented by a type index. */
3724 struct ieee_write_type
3728 /* The size of the type, if known. */
3730 /* The name of the type, if any. */
3732 /* If this is a function or method type, we build the type here, and
3733 only add it to the output buffers if we need it. */
3734 struct ieee_buflist fndef
;
3735 /* If this is a struct, this is where the struct definition is
3737 struct ieee_buflist strdef
;
3738 /* If this is a class, this is where the class information is built. */
3739 struct ieee_type_class
*classdef
;
3740 /* Whether the type is unsigned. */
3741 unsigned int unsignedp
: 1;
3742 /* Whether this is a reference type. */
3743 unsigned int referencep
: 1;
3744 /* Whether this is in the local type block. */
3745 unsigned int localp
: 1;
3746 /* Whether this is a duplicate struct definition which we are
3748 unsigned int ignorep
: 1;
3751 /* This is the type stack used by the debug writing routines. FIXME:
3752 We could generate more efficient output if we remembered when we
3753 have output a particular type before. */
3755 struct ieee_type_stack
3757 /* Next entry on stack. */
3758 struct ieee_type_stack
*next
;
3759 /* Type information. */
3760 struct ieee_write_type type
;
3763 /* This is a list of associations between a name and some types.
3764 These are used for typedefs and tags. */
3766 struct ieee_name_type
3768 /* Next type for this name. */
3769 struct ieee_name_type
*next
;
3770 /* ID number. For a typedef, this is the index of the type to which
3771 this name is typedefed. */
3774 struct ieee_write_type type
;
3775 /* If this is a tag which has not yet been defined, this is the
3776 kind. If the tag has been defined, this is DEBUG_KIND_ILLEGAL. */
3777 enum debug_type_kind kind
;
3780 /* We use a hash table to associate names and types. */
3782 struct ieee_name_type_hash_table
3784 struct bfd_hash_table root
;
3787 struct ieee_name_type_hash_entry
3789 struct bfd_hash_entry root
;
3790 /* Information for this name. */
3791 struct ieee_name_type
*types
;
3794 /* This is a list of enums. */
3796 struct ieee_defined_enum
3799 struct ieee_defined_enum
*next
;
3802 /* Whether this enum has been defined. */
3809 bfd_signed_vma
*vals
;
3812 /* We keep a list of modified versions of types, so that we don't
3813 output them more than once. */
3815 struct ieee_modified_type
3817 /* Pointer to this type. */
3818 unsigned int pointer
;
3819 /* Function with unknown arguments returning this type. */
3820 unsigned int function
;
3821 /* Const version of this type. */
3822 unsigned int const_qualified
;
3823 /* Volatile version of this type. */
3824 unsigned int volatile_qualified
;
3825 /* List of arrays of this type of various bounds. */
3826 struct ieee_modified_array_type
*arrays
;
3829 /* A list of arrays bounds. */
3831 struct ieee_modified_array_type
3833 /* Next array bounds. */
3834 struct ieee_modified_array_type
*next
;
3835 /* Type index with these bounds. */
3840 bfd_signed_vma high
;
3843 /* This is a list of pending function parameter information. We don't
3844 output them until we see the first block. */
3846 struct ieee_pending_parm
3848 /* Next pending parameter. */
3849 struct ieee_pending_parm
*next
;
3854 /* Whether the type is a reference. */
3857 enum debug_parm_kind kind
;
3862 /* This is the handle passed down by debug_write. */
3866 /* BFD we are writing to. */
3868 /* Whether we got an error in a subroutine called via traverse or
3869 map_over_sections. */
3871 /* Current data buffer list. */
3872 struct ieee_buflist
*current
;
3873 /* Current data buffer. */
3874 struct ieee_buf
*curbuf
;
3875 /* Filename of current compilation unit. */
3876 const char *filename
;
3877 /* Module name of current compilation unit. */
3878 const char *modname
;
3879 /* List of buffer for global types. */
3880 struct ieee_buflist global_types
;
3881 /* List of finished data buffers. */
3882 struct ieee_buflist data
;
3883 /* List of buffers for typedefs in the current compilation unit. */
3884 struct ieee_buflist types
;
3885 /* List of buffers for variables and functions in the current
3886 compilation unit. */
3887 struct ieee_buflist vars
;
3888 /* List of buffers for C++ class definitions in the current
3889 compilation unit. */
3890 struct ieee_buflist cxx
;
3891 /* List of buffers for line numbers in the current compilation unit. */
3892 struct ieee_buflist linenos
;
3893 /* Ranges for the current compilation unit. */
3894 struct ieee_range
*ranges
;
3895 /* Ranges for all debugging information. */
3896 struct ieee_range
*global_ranges
;
3897 /* Nested pending ranges. */
3898 struct ieee_range
*pending_ranges
;
3900 struct ieee_type_stack
*type_stack
;
3901 /* Next unallocated type index. */
3902 unsigned int type_indx
;
3903 /* Next unallocated name index. */
3904 unsigned int name_indx
;
3906 struct ieee_name_type_hash_table typedefs
;
3908 struct ieee_name_type_hash_table tags
;
3910 struct ieee_defined_enum
*enums
;
3911 /* Modified versions of types. */
3912 struct ieee_modified_type
*modified
;
3913 /* Number of entries allocated in modified. */
3914 unsigned int modified_alloc
;
3915 /* 4 byte complex type. */
3916 unsigned int complex_float_index
;
3917 /* 8 byte complex type. */
3918 unsigned int complex_double_index
;
3919 /* The depth of block nesting. This is 0 outside a function, and 1
3920 just after start_function is called. */
3921 unsigned int block_depth
;
3922 /* The name of the current function. */
3924 /* List of buffers for the type of the function we are currently
3926 struct ieee_buflist fntype
;
3927 /* List of buffers for the parameters of the function we are
3928 currently writing out. */
3929 struct ieee_buflist fnargs
;
3930 /* Number of arguments written to fnargs. */
3931 unsigned int fnargcount
;
3932 /* Pending function parameters. */
3933 struct ieee_pending_parm
*pending_parms
;
3934 /* Current line number filename. */
3935 const char *lineno_filename
;
3936 /* Line number name index. */
3937 unsigned int lineno_name_indx
;
3938 /* Filename of pending line number. */
3939 const char *pending_lineno_filename
;
3940 /* Pending line number. */
3941 unsigned long pending_lineno
;
3942 /* Address of pending line number. */
3943 bfd_vma pending_lineno_addr
;
3944 /* Highest address seen at end of procedure. */
3948 static boolean ieee_init_buffer
3949 PARAMS ((struct ieee_handle
*, struct ieee_buflist
*));
3950 static boolean ieee_change_buffer
3951 PARAMS ((struct ieee_handle
*, struct ieee_buflist
*));
3952 static boolean ieee_append_buffer
3953 PARAMS ((struct ieee_handle
*, struct ieee_buflist
*,
3954 struct ieee_buflist
*));
3955 static boolean ieee_real_write_byte
PARAMS ((struct ieee_handle
*, int));
3956 static boolean ieee_write_2bytes
PARAMS ((struct ieee_handle
*, int));
3957 static boolean ieee_write_number
PARAMS ((struct ieee_handle
*, bfd_vma
));
3958 static boolean ieee_write_id
PARAMS ((struct ieee_handle
*, const char *));
3959 static boolean ieee_write_asn
3960 PARAMS ((struct ieee_handle
*, unsigned int, bfd_vma
));
3961 static boolean ieee_write_atn65
3962 PARAMS ((struct ieee_handle
*, unsigned int, const char *));
3963 static boolean ieee_push_type
3964 PARAMS ((struct ieee_handle
*, unsigned int, unsigned int, boolean
,
3966 static unsigned int ieee_pop_type
PARAMS ((struct ieee_handle
*));
3967 static void ieee_pop_unused_type
PARAMS ((struct ieee_handle
*));
3968 static unsigned int ieee_pop_type_used
3969 PARAMS ((struct ieee_handle
*, boolean
));
3970 static boolean ieee_add_range
3971 PARAMS ((struct ieee_handle
*, boolean
, bfd_vma
, bfd_vma
));
3972 static boolean ieee_start_range
PARAMS ((struct ieee_handle
*, bfd_vma
));
3973 static boolean ieee_end_range
PARAMS ((struct ieee_handle
*, bfd_vma
));
3974 static boolean ieee_define_type
3975 PARAMS ((struct ieee_handle
*, unsigned int, boolean
, boolean
));
3976 static boolean ieee_define_named_type
3977 PARAMS ((struct ieee_handle
*, const char *, unsigned int, unsigned int,
3978 boolean
, boolean
, struct ieee_buflist
*));
3979 static struct ieee_modified_type
*ieee_get_modified_info
3980 PARAMS ((struct ieee_handle
*, unsigned int));
3981 static struct bfd_hash_entry
*ieee_name_type_newfunc
3982 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
3983 static boolean ieee_write_undefined_tag
3984 PARAMS ((struct ieee_name_type_hash_entry
*, PTR
));
3985 static boolean ieee_finish_compilation_unit
PARAMS ((struct ieee_handle
*));
3986 static void ieee_add_bb11_blocks
PARAMS ((bfd
*, asection
*, PTR
));
3987 static boolean ieee_add_bb11
3988 PARAMS ((struct ieee_handle
*, asection
*, bfd_vma
, bfd_vma
));
3989 static boolean ieee_output_pending_parms
PARAMS ((struct ieee_handle
*));
3990 static unsigned int ieee_vis_to_flags
PARAMS ((enum debug_visibility
));
3991 static boolean ieee_class_method_var
3992 PARAMS ((struct ieee_handle
*, const char *, enum debug_visibility
, boolean
,
3993 boolean
, boolean
, bfd_vma
, boolean
));
3995 static boolean ieee_start_compilation_unit
PARAMS ((PTR
, const char *));
3996 static boolean ieee_start_source
PARAMS ((PTR
, const char *));
3997 static boolean ieee_empty_type
PARAMS ((PTR
));
3998 static boolean ieee_void_type
PARAMS ((PTR
));
3999 static boolean ieee_int_type
PARAMS ((PTR
, unsigned int, boolean
));
4000 static boolean ieee_float_type
PARAMS ((PTR
, unsigned int));
4001 static boolean ieee_complex_type
PARAMS ((PTR
, unsigned int));
4002 static boolean ieee_bool_type
PARAMS ((PTR
, unsigned int));
4003 static boolean ieee_enum_type
4004 PARAMS ((PTR
, const char *, const char **, bfd_signed_vma
*));
4005 static boolean ieee_pointer_type
PARAMS ((PTR
));
4006 static boolean ieee_function_type
PARAMS ((PTR
, int, boolean
));
4007 static boolean ieee_reference_type
PARAMS ((PTR
));
4008 static boolean ieee_range_type
PARAMS ((PTR
, bfd_signed_vma
, bfd_signed_vma
));
4009 static boolean ieee_array_type
4010 PARAMS ((PTR
, bfd_signed_vma
, bfd_signed_vma
, boolean
));
4011 static boolean ieee_set_type
PARAMS ((PTR
, boolean
));
4012 static boolean ieee_offset_type
PARAMS ((PTR
));
4013 static boolean ieee_method_type
PARAMS ((PTR
, boolean
, int, boolean
));
4014 static boolean ieee_const_type
PARAMS ((PTR
));
4015 static boolean ieee_volatile_type
PARAMS ((PTR
));
4016 static boolean ieee_start_struct_type
4017 PARAMS ((PTR
, const char *, unsigned int, boolean
, unsigned int));
4018 static boolean ieee_struct_field
4019 PARAMS ((PTR
, const char *, bfd_vma
, bfd_vma
, enum debug_visibility
));
4020 static boolean ieee_end_struct_type
PARAMS ((PTR
));
4021 static boolean ieee_start_class_type
4022 PARAMS ((PTR
, const char *, unsigned int, boolean
, unsigned int, boolean
,
4024 static boolean ieee_class_static_member
4025 PARAMS ((PTR
, const char *, const char *, enum debug_visibility
));
4026 static boolean ieee_class_baseclass
4027 PARAMS ((PTR
, bfd_vma
, boolean
, enum debug_visibility
));
4028 static boolean ieee_class_start_method
PARAMS ((PTR
, const char *));
4029 static boolean ieee_class_method_variant
4030 PARAMS ((PTR
, const char *, enum debug_visibility
, boolean
, boolean
,
4032 static boolean ieee_class_static_method_variant
4033 PARAMS ((PTR
, const char *, enum debug_visibility
, boolean
, boolean
));
4034 static boolean ieee_class_end_method
PARAMS ((PTR
));
4035 static boolean ieee_end_class_type
PARAMS ((PTR
));
4036 static boolean ieee_typedef_type
PARAMS ((PTR
, const char *));
4037 static boolean ieee_tag_type
4038 PARAMS ((PTR
, const char *, unsigned int, enum debug_type_kind
));
4039 static boolean ieee_typdef
PARAMS ((PTR
, const char *));
4040 static boolean ieee_tag
PARAMS ((PTR
, const char *));
4041 static boolean ieee_int_constant
PARAMS ((PTR
, const char *, bfd_vma
));
4042 static boolean ieee_float_constant
PARAMS ((PTR
, const char *, double));
4043 static boolean ieee_typed_constant
PARAMS ((PTR
, const char *, bfd_vma
));
4044 static boolean ieee_variable
4045 PARAMS ((PTR
, const char *, enum debug_var_kind
, bfd_vma
));
4046 static boolean ieee_start_function
PARAMS ((PTR
, const char *, boolean
));
4047 static boolean ieee_function_parameter
4048 PARAMS ((PTR
, const char *, enum debug_parm_kind
, bfd_vma
));
4049 static boolean ieee_start_block
PARAMS ((PTR
, bfd_vma
));
4050 static boolean ieee_end_block
PARAMS ((PTR
, bfd_vma
));
4051 static boolean ieee_end_function
PARAMS ((PTR
));
4052 static boolean ieee_lineno
4053 PARAMS ((PTR
, const char *, unsigned long, bfd_vma
));
4055 static const struct debug_write_fns ieee_fns
=
4057 ieee_start_compilation_unit
,
4068 ieee_reference_type
,
4076 ieee_start_struct_type
,
4078 ieee_end_struct_type
,
4079 ieee_start_class_type
,
4080 ieee_class_static_member
,
4081 ieee_class_baseclass
,
4082 ieee_class_start_method
,
4083 ieee_class_method_variant
,
4084 ieee_class_static_method_variant
,
4085 ieee_class_end_method
,
4086 ieee_end_class_type
,
4092 ieee_float_constant
,
4093 ieee_typed_constant
,
4095 ieee_start_function
,
4096 ieee_function_parameter
,
4103 /* Initialize a buffer to be empty. */
4106 ieee_init_buffer (info
, buflist
)
4107 struct ieee_handle
*info ATTRIBUTE_UNUSED
;
4108 struct ieee_buflist
*buflist
;
4110 buflist
->head
= NULL
;
4111 buflist
->tail
= NULL
;
4115 /* See whether a buffer list has any data. */
4117 #define ieee_buffer_emptyp(buflist) ((buflist)->head == NULL)
4119 /* Change the current buffer to a specified buffer chain. */
4122 ieee_change_buffer (info
, buflist
)
4123 struct ieee_handle
*info
;
4124 struct ieee_buflist
*buflist
;
4126 if (buflist
->head
== NULL
)
4128 struct ieee_buf
*buf
;
4130 buf
= (struct ieee_buf
*) xmalloc (sizeof *buf
);
4133 buflist
->head
= buf
;
4134 buflist
->tail
= buf
;
4137 info
->current
= buflist
;
4138 info
->curbuf
= buflist
->tail
;
4143 /* Append a buffer chain. */
4146 ieee_append_buffer (info
, mainbuf
, newbuf
)
4147 struct ieee_handle
*info ATTRIBUTE_UNUSED
;
4148 struct ieee_buflist
*mainbuf
;
4149 struct ieee_buflist
*newbuf
;
4151 if (newbuf
->head
!= NULL
)
4153 if (mainbuf
->head
== NULL
)
4154 mainbuf
->head
= newbuf
->head
;
4156 mainbuf
->tail
->next
= newbuf
->head
;
4157 mainbuf
->tail
= newbuf
->tail
;
4162 /* Write a byte into the buffer. We use a macro for speed and a
4163 function for the complex cases. */
4165 #define ieee_write_byte(info, b) \
4166 ((info)->curbuf->c < IEEE_BUFSIZE \
4167 ? ((info)->curbuf->buf[(info)->curbuf->c++] = (b), true) \
4168 : ieee_real_write_byte ((info), (b)))
4171 ieee_real_write_byte (info
, b
)
4172 struct ieee_handle
*info
;
4175 if (info
->curbuf
->c
>= IEEE_BUFSIZE
)
4179 n
= (struct ieee_buf
*) xmalloc (sizeof *n
);
4182 if (info
->current
->head
== NULL
)
4183 info
->current
->head
= n
;
4185 info
->current
->tail
->next
= n
;
4186 info
->current
->tail
= n
;
4190 info
->curbuf
->buf
[info
->curbuf
->c
] = b
;
4196 /* Write out two bytes. */
4199 ieee_write_2bytes (info
, i
)
4200 struct ieee_handle
*info
;
4203 return (ieee_write_byte (info
, i
>> 8)
4204 && ieee_write_byte (info
, i
& 0xff));
4207 /* Write out an integer. */
4210 ieee_write_number (info
, v
)
4211 struct ieee_handle
*info
;
4219 if (v
<= (bfd_vma
) ieee_number_end_enum
)
4220 return ieee_write_byte (info
, (int) v
);
4231 if (c
> (unsigned int) (ieee_number_repeat_end_enum
4232 - ieee_number_repeat_start_enum
))
4234 fprintf (stderr
, _("IEEE numeric overflow: 0x"));
4235 fprintf_vma (stderr
, v
);
4236 fprintf (stderr
, "\n");
4240 if (! ieee_write_byte (info
, (int) ieee_number_repeat_start_enum
+ c
))
4242 for (; c
> 0; --c
, ++p
)
4244 if (! ieee_write_byte (info
, *p
))
4251 /* Write out a string. */
4254 ieee_write_id (info
, s
)
4255 struct ieee_handle
*info
;
4263 if (! ieee_write_byte (info
, len
))
4266 else if (len
<= 0xff)
4268 if (! ieee_write_byte (info
, (int) ieee_extension_length_1_enum
)
4269 || ! ieee_write_byte (info
, len
))
4272 else if (len
<= 0xffff)
4274 if (! ieee_write_byte (info
, (int) ieee_extension_length_2_enum
)
4275 || ! ieee_write_2bytes (info
, len
))
4280 fprintf (stderr
, _("IEEE string length overflow: %u\n"), len
);
4284 for (; *s
!= '\0'; s
++)
4285 if (! ieee_write_byte (info
, *s
))
4291 /* Write out an ASN record. */
4294 ieee_write_asn (info
, indx
, val
)
4295 struct ieee_handle
*info
;
4299 return (ieee_write_2bytes (info
, (int) ieee_asn_record_enum
)
4300 && ieee_write_number (info
, indx
)
4301 && ieee_write_number (info
, val
));
4304 /* Write out an ATN65 record. */
4307 ieee_write_atn65 (info
, indx
, s
)
4308 struct ieee_handle
*info
;
4312 return (ieee_write_2bytes (info
, (int) ieee_atn_record_enum
)
4313 && ieee_write_number (info
, indx
)
4314 && ieee_write_number (info
, 0)
4315 && ieee_write_number (info
, 65)
4316 && ieee_write_id (info
, s
));
4319 /* Push a type index onto the type stack. */
4322 ieee_push_type (info
, indx
, size
, unsignedp
, localp
)
4323 struct ieee_handle
*info
;
4329 struct ieee_type_stack
*ts
;
4331 ts
= (struct ieee_type_stack
*) xmalloc (sizeof *ts
);
4332 memset (ts
, 0, sizeof *ts
);
4334 ts
->type
.indx
= indx
;
4335 ts
->type
.size
= size
;
4336 ts
->type
.unsignedp
= unsignedp
;
4337 ts
->type
.localp
= localp
;
4339 ts
->next
= info
->type_stack
;
4340 info
->type_stack
= ts
;
4345 /* Pop a type index off the type stack. */
4348 ieee_pop_type (info
)
4349 struct ieee_handle
*info
;
4351 return ieee_pop_type_used (info
, true);
4354 /* Pop an unused type index off the type stack. */
4357 ieee_pop_unused_type (info
)
4358 struct ieee_handle
*info
;
4360 (void) ieee_pop_type_used (info
, false);
4363 /* Pop a used or unused type index off the type stack. */
4366 ieee_pop_type_used (info
, used
)
4367 struct ieee_handle
*info
;
4370 struct ieee_type_stack
*ts
;
4373 ts
= info
->type_stack
;
4374 assert (ts
!= NULL
);
4376 /* If this is a function type, and we need it, we need to append the
4377 actual definition to the typedef block now. */
4378 if (used
&& ! ieee_buffer_emptyp (&ts
->type
.fndef
))
4380 struct ieee_buflist
*buflist
;
4382 if (ts
->type
.localp
)
4384 /* Make sure we have started the types block. */
4385 if (ieee_buffer_emptyp (&info
->types
))
4387 if (! ieee_change_buffer (info
, &info
->types
)
4388 || ! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
4389 || ! ieee_write_byte (info
, 1)
4390 || ! ieee_write_number (info
, 0)
4391 || ! ieee_write_id (info
, info
->modname
))
4394 buflist
= &info
->types
;
4398 /* Make sure we started the global type block. */
4399 if (ieee_buffer_emptyp (&info
->global_types
))
4401 if (! ieee_change_buffer (info
, &info
->global_types
)
4402 || ! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
4403 || ! ieee_write_byte (info
, 2)
4404 || ! ieee_write_number (info
, 0)
4405 || ! ieee_write_id (info
, ""))
4408 buflist
= &info
->global_types
;
4411 if (! ieee_append_buffer (info
, buflist
, &ts
->type
.fndef
))
4415 ret
= ts
->type
.indx
;
4416 info
->type_stack
= ts
->next
;
4421 /* Add a range of bytes included in the current compilation unit. */
4424 ieee_add_range (info
, global
, low
, high
)
4425 struct ieee_handle
*info
;
4430 struct ieee_range
**plist
, *r
, **pr
;
4432 if (low
== (bfd_vma
) -1 || high
== (bfd_vma
) -1 || low
== high
)
4436 plist
= &info
->global_ranges
;
4438 plist
= &info
->ranges
;
4440 for (r
= *plist
; r
!= NULL
; r
= r
->next
)
4442 if (high
>= r
->low
&& low
<= r
->high
)
4444 /* The new range overlaps r. */
4450 while (*pr
!= NULL
&& (*pr
)->low
<= r
->high
)
4452 struct ieee_range
*n
;
4454 if ((*pr
)->high
> r
->high
)
4455 r
->high
= (*pr
)->high
;
4464 r
= (struct ieee_range
*) xmalloc (sizeof *r
);
4465 memset (r
, 0, sizeof *r
);
4470 /* Store the ranges sorted by address. */
4471 for (pr
= plist
; *pr
!= NULL
; pr
= &(*pr
)->next
)
4472 if ((*pr
)->low
> high
)
4480 /* Start a new range for which we only have the low address. */
4483 ieee_start_range (info
, low
)
4484 struct ieee_handle
*info
;
4487 struct ieee_range
*r
;
4489 r
= (struct ieee_range
*) xmalloc (sizeof *r
);
4490 memset (r
, 0, sizeof *r
);
4492 r
->next
= info
->pending_ranges
;
4493 info
->pending_ranges
= r
;
4497 /* Finish a range started by ieee_start_range. */
4500 ieee_end_range (info
, high
)
4501 struct ieee_handle
*info
;
4504 struct ieee_range
*r
;
4507 assert (info
->pending_ranges
!= NULL
);
4508 r
= info
->pending_ranges
;
4510 info
->pending_ranges
= r
->next
;
4512 return ieee_add_range (info
, false, low
, high
);
4515 /* Start defining a type. */
4518 ieee_define_type (info
, size
, unsignedp
, localp
)
4519 struct ieee_handle
*info
;
4524 return ieee_define_named_type (info
, (const char *) NULL
,
4525 (unsigned int) -1, size
, unsignedp
,
4526 localp
, (struct ieee_buflist
*) NULL
);
4529 /* Start defining a named type. */
4532 ieee_define_named_type (info
, name
, indx
, size
, unsignedp
, localp
, buflist
)
4533 struct ieee_handle
*info
;
4539 struct ieee_buflist
*buflist
;
4541 unsigned int type_indx
;
4542 unsigned int name_indx
;
4544 if (indx
!= (unsigned int) -1)
4548 type_indx
= info
->type_indx
;
4552 name_indx
= info
->name_indx
;
4558 /* If we were given a buffer, use it; otherwise, use either the
4559 local or the global type information, and make sure that the type
4560 block is started. */
4561 if (buflist
!= NULL
)
4563 if (! ieee_change_buffer (info
, buflist
))
4568 if (! ieee_buffer_emptyp (&info
->types
))
4570 if (! ieee_change_buffer (info
, &info
->types
))
4575 if (! ieee_change_buffer (info
, &info
->types
)
4576 || ! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
4577 || ! ieee_write_byte (info
, 1)
4578 || ! ieee_write_number (info
, 0)
4579 || ! ieee_write_id (info
, info
->modname
))
4585 if (! ieee_buffer_emptyp (&info
->global_types
))
4587 if (! ieee_change_buffer (info
, &info
->global_types
))
4592 if (! ieee_change_buffer (info
, &info
->global_types
)
4593 || ! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
4594 || ! ieee_write_byte (info
, 2)
4595 || ! ieee_write_number (info
, 0)
4596 || ! ieee_write_id (info
, ""))
4601 /* Push the new type on the type stack, write out an NN record, and
4602 write out the start of a TY record. The caller will then finish
4604 if (! ieee_push_type (info
, type_indx
, size
, unsignedp
, localp
))
4607 return (ieee_write_byte (info
, (int) ieee_nn_record
)
4608 && ieee_write_number (info
, name_indx
)
4609 && ieee_write_id (info
, name
)
4610 && ieee_write_byte (info
, (int) ieee_ty_record_enum
)
4611 && ieee_write_number (info
, type_indx
)
4612 && ieee_write_byte (info
, 0xce)
4613 && ieee_write_number (info
, name_indx
));
4616 /* Get an entry to the list of modified versions of a type. */
4618 static struct ieee_modified_type
*
4619 ieee_get_modified_info (info
, indx
)
4620 struct ieee_handle
*info
;
4623 if (indx
>= info
->modified_alloc
)
4625 unsigned int nalloc
;
4627 nalloc
= info
->modified_alloc
;
4630 while (indx
>= nalloc
)
4632 info
->modified
= ((struct ieee_modified_type
*)
4633 xrealloc (info
->modified
,
4634 nalloc
* sizeof *info
->modified
));
4635 memset (info
->modified
+ info
->modified_alloc
, 0,
4636 (nalloc
- info
->modified_alloc
) * sizeof *info
->modified
);
4637 info
->modified_alloc
= nalloc
;
4640 return info
->modified
+ indx
;
4643 /* Routines for the hash table mapping names to types. */
4645 /* Initialize an entry in the hash table. */
4647 static struct bfd_hash_entry
*
4648 ieee_name_type_newfunc (entry
, table
, string
)
4649 struct bfd_hash_entry
*entry
;
4650 struct bfd_hash_table
*table
;
4653 struct ieee_name_type_hash_entry
*ret
=
4654 (struct ieee_name_type_hash_entry
*) entry
;
4656 /* Allocate the structure if it has not already been allocated by a
4659 ret
= ((struct ieee_name_type_hash_entry
*)
4660 bfd_hash_allocate (table
, sizeof *ret
));
4664 /* Call the allocation method of the superclass. */
4665 ret
= ((struct ieee_name_type_hash_entry
*)
4666 bfd_hash_newfunc ((struct bfd_hash_entry
*) ret
, table
, string
));
4669 /* Set local fields. */
4673 return (struct bfd_hash_entry
*) ret
;
4676 /* Look up an entry in the hash table. */
4678 #define ieee_name_type_hash_lookup(table, string, create, copy) \
4679 ((struct ieee_name_type_hash_entry *) \
4680 bfd_hash_lookup (&(table)->root, (string), (create), (copy)))
4682 /* Traverse the hash table. */
4684 #define ieee_name_type_hash_traverse(table, func, info) \
4685 (bfd_hash_traverse \
4687 (boolean (*) PARAMS ((struct bfd_hash_entry *, PTR))) (func), \
4690 /* The general routine to write out IEEE debugging information. */
4693 write_ieee_debugging_info (abfd
, dhandle
)
4697 struct ieee_handle info
;
4702 memset (&info
, 0, sizeof info
);
4704 info
.type_indx
= 256;
4705 info
.name_indx
= 32;
4707 if (! bfd_hash_table_init (&info
.typedefs
.root
, ieee_name_type_newfunc
)
4708 || ! bfd_hash_table_init (&info
.tags
.root
, ieee_name_type_newfunc
))
4711 if (! ieee_init_buffer (&info
, &info
.global_types
)
4712 || ! ieee_init_buffer (&info
, &info
.data
)
4713 || ! ieee_init_buffer (&info
, &info
.types
)
4714 || ! ieee_init_buffer (&info
, &info
.vars
)
4715 || ! ieee_init_buffer (&info
, &info
.cxx
)
4716 || ! ieee_init_buffer (&info
, &info
.linenos
)
4717 || ! ieee_init_buffer (&info
, &info
.fntype
)
4718 || ! ieee_init_buffer (&info
, &info
.fnargs
))
4721 if (! debug_write (dhandle
, &ieee_fns
, (PTR
) &info
))
4724 if (info
.filename
!= NULL
)
4726 if (! ieee_finish_compilation_unit (&info
))
4730 /* Put any undefined tags in the global typedef information. */
4732 ieee_name_type_hash_traverse (&info
.tags
,
4733 ieee_write_undefined_tag
,
4738 /* Prepend the global typedef information to the other data. */
4739 if (! ieee_buffer_emptyp (&info
.global_types
))
4741 /* The HP debugger seems to have a bug in which it ignores the
4742 last entry in the global types, so we add a dummy entry. */
4743 if (! ieee_change_buffer (&info
, &info
.global_types
)
4744 || ! ieee_write_byte (&info
, (int) ieee_nn_record
)
4745 || ! ieee_write_number (&info
, info
.name_indx
)
4746 || ! ieee_write_id (&info
, "")
4747 || ! ieee_write_byte (&info
, (int) ieee_ty_record_enum
)
4748 || ! ieee_write_number (&info
, info
.type_indx
)
4749 || ! ieee_write_byte (&info
, 0xce)
4750 || ! ieee_write_number (&info
, info
.name_indx
)
4751 || ! ieee_write_number (&info
, 'P')
4752 || ! ieee_write_number (&info
, (int) builtin_void
+ 32)
4753 || ! ieee_write_byte (&info
, (int) ieee_be_record_enum
))
4756 if (! ieee_append_buffer (&info
, &info
.global_types
, &info
.data
))
4758 info
.data
= info
.global_types
;
4761 /* Make sure that we have declare BB11 blocks for each range in the
4762 file. They are added to info->vars. */
4764 if (! ieee_init_buffer (&info
, &info
.vars
))
4766 bfd_map_over_sections (abfd
, ieee_add_bb11_blocks
, (PTR
) &info
);
4769 if (! ieee_buffer_emptyp (&info
.vars
))
4771 if (! ieee_change_buffer (&info
, &info
.vars
)
4772 || ! ieee_write_byte (&info
, (int) ieee_be_record_enum
))
4775 if (! ieee_append_buffer (&info
, &info
.data
, &info
.vars
))
4779 /* Now all the data is in info.data. Write it out to the BFD. We
4780 normally would need to worry about whether all the other sections
4781 are set up yet, but the IEEE backend will handle this particular
4782 case correctly regardless. */
4783 if (ieee_buffer_emptyp (&info
.data
))
4785 /* There is no debugging information. */
4789 s
= bfd_make_section (abfd
, ".debug");
4791 err
= "bfd_make_section";
4794 if (! bfd_set_section_flags (abfd
, s
, SEC_DEBUGGING
| SEC_HAS_CONTENTS
))
4795 err
= "bfd_set_section_flags";
4802 for (b
= info
.data
.head
; b
!= NULL
; b
= b
->next
)
4804 if (! bfd_set_section_size (abfd
, s
, size
))
4805 err
= "bfd_set_section_size";
4812 for (b
= info
.data
.head
; b
!= NULL
; b
= b
->next
)
4814 if (! bfd_set_section_contents (abfd
, s
, b
->buf
, offset
, b
->c
))
4816 err
= "bfd_set_section_contents";
4825 fprintf (stderr
, "%s: %s: %s\n", bfd_get_filename (abfd
), err
,
4826 bfd_errmsg (bfd_get_error ()));
4830 bfd_hash_table_free (&info
.typedefs
.root
);
4831 bfd_hash_table_free (&info
.tags
.root
);
4836 /* Write out information for an undefined tag. This is called via
4837 ieee_name_type_hash_traverse. */
4840 ieee_write_undefined_tag (h
, p
)
4841 struct ieee_name_type_hash_entry
*h
;
4844 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
4845 struct ieee_name_type
*nt
;
4847 for (nt
= h
->types
; nt
!= NULL
; nt
= nt
->next
)
4849 unsigned int name_indx
;
4852 if (nt
->kind
== DEBUG_KIND_ILLEGAL
)
4855 if (ieee_buffer_emptyp (&info
->global_types
))
4857 if (! ieee_change_buffer (info
, &info
->global_types
)
4858 || ! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
4859 || ! ieee_write_byte (info
, 2)
4860 || ! ieee_write_number (info
, 0)
4861 || ! ieee_write_id (info
, ""))
4869 if (! ieee_change_buffer (info
, &info
->global_types
))
4876 name_indx
= info
->name_indx
;
4878 if (! ieee_write_byte (info
, (int) ieee_nn_record
)
4879 || ! ieee_write_number (info
, name_indx
)
4880 || ! ieee_write_id (info
, nt
->type
.name
)
4881 || ! ieee_write_byte (info
, (int) ieee_ty_record_enum
)
4882 || ! ieee_write_number (info
, nt
->type
.indx
)
4883 || ! ieee_write_byte (info
, 0xce)
4884 || ! ieee_write_number (info
, name_indx
))
4896 case DEBUG_KIND_STRUCT
:
4897 case DEBUG_KIND_CLASS
:
4900 case DEBUG_KIND_UNION
:
4901 case DEBUG_KIND_UNION_CLASS
:
4904 case DEBUG_KIND_ENUM
:
4908 if (! ieee_write_number (info
, code
)
4909 || ! ieee_write_number (info
, 0))
4919 /* Start writing out information for a compilation unit. */
4922 ieee_start_compilation_unit (p
, filename
)
4924 const char *filename
;
4926 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
4927 const char *modname
;
4928 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
4929 const char *backslash
;
4934 if (info
->filename
!= NULL
)
4936 if (! ieee_finish_compilation_unit (info
))
4940 info
->filename
= filename
;
4941 modname
= strrchr (filename
, '/');
4942 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
4943 /* We could have a mixed forward/back slash case. */
4944 backslash
= strrchr (filename
, '\\');
4945 if (modname
== NULL
|| (backslash
!= NULL
&& backslash
> modname
))
4946 modname
= backslash
;
4949 if (modname
!= NULL
)
4951 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
4952 else if (filename
[0] && filename
[1] == ':')
4953 modname
= filename
+ 2;
4958 c
= xstrdup (modname
);
4959 s
= strrchr (c
, '.');
4964 if (! ieee_init_buffer (info
, &info
->types
)
4965 || ! ieee_init_buffer (info
, &info
->vars
)
4966 || ! ieee_init_buffer (info
, &info
->cxx
)
4967 || ! ieee_init_buffer (info
, &info
->linenos
))
4969 info
->ranges
= NULL
;
4971 /* Always include a BB1 and a BB3 block. That is what the output of
4972 the MRI linker seems to look like. */
4973 if (! ieee_change_buffer (info
, &info
->types
)
4974 || ! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
4975 || ! ieee_write_byte (info
, 1)
4976 || ! ieee_write_number (info
, 0)
4977 || ! ieee_write_id (info
, info
->modname
))
4980 nindx
= info
->name_indx
;
4982 if (! ieee_change_buffer (info
, &info
->vars
)
4983 || ! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
4984 || ! ieee_write_byte (info
, 3)
4985 || ! ieee_write_number (info
, 0)
4986 || ! ieee_write_id (info
, info
->modname
))
4992 /* Finish up a compilation unit. */
4995 ieee_finish_compilation_unit (info
)
4996 struct ieee_handle
*info
;
4998 struct ieee_range
*r
;
5000 if (! ieee_buffer_emptyp (&info
->types
))
5002 if (! ieee_change_buffer (info
, &info
->types
)
5003 || ! ieee_write_byte (info
, (int) ieee_be_record_enum
))
5007 if (! ieee_buffer_emptyp (&info
->cxx
))
5009 /* Append any C++ information to the global function and
5010 variable information. */
5011 assert (! ieee_buffer_emptyp (&info
->vars
));
5012 if (! ieee_change_buffer (info
, &info
->vars
))
5015 /* We put the pmisc records in a dummy procedure, just as the
5016 MRI compiler does. */
5017 if (! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
5018 || ! ieee_write_byte (info
, 6)
5019 || ! ieee_write_number (info
, 0)
5020 || ! ieee_write_id (info
, "__XRYCPP")
5021 || ! ieee_write_number (info
, 0)
5022 || ! ieee_write_number (info
, 0)
5023 || ! ieee_write_number (info
, info
->highaddr
- 1)
5024 || ! ieee_append_buffer (info
, &info
->vars
, &info
->cxx
)
5025 || ! ieee_change_buffer (info
, &info
->vars
)
5026 || ! ieee_write_byte (info
, (int) ieee_be_record_enum
)
5027 || ! ieee_write_number (info
, info
->highaddr
- 1))
5031 if (! ieee_buffer_emptyp (&info
->vars
))
5033 if (! ieee_change_buffer (info
, &info
->vars
)
5034 || ! ieee_write_byte (info
, (int) ieee_be_record_enum
))
5038 if (info
->pending_lineno_filename
!= NULL
)
5040 /* Force out the pending line number. */
5041 if (! ieee_lineno ((PTR
) info
, (const char *) NULL
, 0, (bfd_vma
) -1))
5044 if (! ieee_buffer_emptyp (&info
->linenos
))
5046 if (! ieee_change_buffer (info
, &info
->linenos
)
5047 || ! ieee_write_byte (info
, (int) ieee_be_record_enum
))
5049 if (strcmp (info
->filename
, info
->lineno_filename
) != 0)
5051 /* We were not in the main file. We just closed the
5052 included line number block, and now we must close the
5053 main line number block. */
5054 if (! ieee_write_byte (info
, (int) ieee_be_record_enum
))
5059 if (! ieee_append_buffer (info
, &info
->data
, &info
->types
)
5060 || ! ieee_append_buffer (info
, &info
->data
, &info
->vars
)
5061 || ! ieee_append_buffer (info
, &info
->data
, &info
->linenos
))
5064 /* Build BB10/BB11 blocks based on the ranges we recorded. */
5065 if (! ieee_change_buffer (info
, &info
->data
))
5068 if (! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
5069 || ! ieee_write_byte (info
, 10)
5070 || ! ieee_write_number (info
, 0)
5071 || ! ieee_write_id (info
, info
->modname
)
5072 || ! ieee_write_id (info
, "")
5073 || ! ieee_write_number (info
, 0)
5074 || ! ieee_write_id (info
, "GNU objcopy"))
5077 for (r
= info
->ranges
; r
!= NULL
; r
= r
->next
)
5086 /* Find the section corresponding to this range. */
5087 for (s
= info
->abfd
->sections
; s
!= NULL
; s
= s
->next
)
5089 if (bfd_get_section_vma (info
->abfd
, s
) <= low
5090 && high
<= (bfd_get_section_vma (info
->abfd
, s
)
5091 + bfd_section_size (info
->abfd
, s
)))
5097 /* Just ignore this range. */
5101 /* Coalesce ranges if it seems reasonable. */
5102 while (r
->next
!= NULL
5103 && high
+ 0x1000 >= r
->next
->low
5105 <= (bfd_get_section_vma (info
->abfd
, s
)
5106 + bfd_section_size (info
->abfd
, s
))))
5112 if ((s
->flags
& SEC_CODE
) != 0)
5114 else if ((s
->flags
& SEC_READONLY
) != 0)
5119 if (! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
5120 || ! ieee_write_byte (info
, 11)
5121 || ! ieee_write_number (info
, 0)
5122 || ! ieee_write_id (info
, "")
5123 || ! ieee_write_number (info
, kind
)
5124 || ! ieee_write_number (info
, s
->index
+ IEEE_SECTION_NUMBER_BASE
)
5125 || ! ieee_write_number (info
, low
)
5126 || ! ieee_write_byte (info
, (int) ieee_be_record_enum
)
5127 || ! ieee_write_number (info
, high
- low
))
5130 /* Add this range to the list of global ranges. */
5131 if (! ieee_add_range (info
, true, low
, high
))
5135 if (! ieee_write_byte (info
, (int) ieee_be_record_enum
))
5141 /* Add BB11 blocks describing each range that we have not already
5145 ieee_add_bb11_blocks (abfd
, sec
, data
)
5146 bfd
*abfd ATTRIBUTE_UNUSED
;
5150 struct ieee_handle
*info
= (struct ieee_handle
*) data
;
5152 struct ieee_range
*r
;
5154 low
= bfd_get_section_vma (abfd
, sec
);
5155 high
= low
+ bfd_section_size (abfd
, sec
);
5157 /* Find the first range at or after this section. The ranges are
5158 sorted by address. */
5159 for (r
= info
->global_ranges
; r
!= NULL
; r
= r
->next
)
5165 if (r
== NULL
|| r
->low
>= high
)
5167 if (! ieee_add_bb11 (info
, sec
, low
, high
))
5173 && r
->low
- low
> 0x100)
5175 if (! ieee_add_bb11 (info
, sec
, low
, r
->low
))
5187 /* Add a single BB11 block for a range. We add it to info->vars. */
5190 ieee_add_bb11 (info
, sec
, low
, high
)
5191 struct ieee_handle
*info
;
5198 if (! ieee_buffer_emptyp (&info
->vars
))
5200 if (! ieee_change_buffer (info
, &info
->vars
))
5205 const char *filename
, *modname
;
5206 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
5207 const char *backslash
;
5211 /* Start the enclosing BB10 block. */
5212 filename
= bfd_get_filename (info
->abfd
);
5213 modname
= strrchr (filename
, '/');
5214 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
5215 backslash
= strrchr (filename
, '\\');
5216 if (modname
== NULL
|| (backslash
!= NULL
&& backslash
> modname
))
5217 modname
= backslash
;
5220 if (modname
!= NULL
)
5222 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
5223 else if (filename
[0] && filename
[1] == ':')
5224 modname
= filename
+ 2;
5229 c
= xstrdup (modname
);
5230 s
= strrchr (c
, '.');
5234 if (! ieee_change_buffer (info
, &info
->vars
)
5235 || ! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
5236 || ! ieee_write_byte (info
, 10)
5237 || ! ieee_write_number (info
, 0)
5238 || ! ieee_write_id (info
, c
)
5239 || ! ieee_write_id (info
, "")
5240 || ! ieee_write_number (info
, 0)
5241 || ! ieee_write_id (info
, "GNU objcopy"))
5247 if ((sec
->flags
& SEC_CODE
) != 0)
5249 else if ((sec
->flags
& SEC_READONLY
) != 0)
5254 if (! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
5255 || ! ieee_write_byte (info
, 11)
5256 || ! ieee_write_number (info
, 0)
5257 || ! ieee_write_id (info
, "")
5258 || ! ieee_write_number (info
, kind
)
5259 || ! ieee_write_number (info
, sec
->index
+ IEEE_SECTION_NUMBER_BASE
)
5260 || ! ieee_write_number (info
, low
)
5261 || ! ieee_write_byte (info
, (int) ieee_be_record_enum
)
5262 || ! ieee_write_number (info
, high
- low
))
5268 /* Start recording information from a particular source file. This is
5269 used to record which file defined which types, variables, etc. It
5270 is not used for line numbers, since the lineno entry point passes
5271 down the file name anyhow. IEEE debugging information doesn't seem
5272 to store this information anywhere. */
5275 ieee_start_source (p
, filename
)
5276 PTR p ATTRIBUTE_UNUSED
;
5277 const char *filename ATTRIBUTE_UNUSED
;
5282 /* Make an empty type. */
5288 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
5290 return ieee_push_type (info
, (int) builtin_unknown
, 0, false, false);
5293 /* Make a void type. */
5299 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
5301 return ieee_push_type (info
, (int) builtin_void
, 0, false, false);
5304 /* Make an integer type. */
5307 ieee_int_type (p
, size
, unsignedp
)
5312 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
5318 indx
= (int) builtin_signed_char
;
5321 indx
= (int) builtin_signed_short_int
;
5324 indx
= (int) builtin_signed_long
;
5327 indx
= (int) builtin_signed_long_long
;
5330 fprintf (stderr
, _("IEEE unsupported integer type size %u\n"), size
);
5337 return ieee_push_type (info
, indx
, size
, unsignedp
, false);
5340 /* Make a floating point type. */
5343 ieee_float_type (p
, size
)
5347 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
5353 indx
= (int) builtin_float
;
5356 indx
= (int) builtin_double
;
5359 /* FIXME: This size really depends upon the processor. */
5360 indx
= (int) builtin_long_double
;
5363 indx
= (int) builtin_long_long_double
;
5366 fprintf (stderr
, _("IEEE unsupported float type size %u\n"), size
);
5370 return ieee_push_type (info
, indx
, size
, false, false);
5373 /* Make a complex type. */
5376 ieee_complex_type (p
, size
)
5380 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
5386 if (info
->complex_float_index
!= 0)
5387 return ieee_push_type (info
, info
->complex_float_index
, size
* 2,
5393 /* These cases can be output by gcc -gstabs. Outputting the
5394 wrong type is better than crashing. */
5396 if (info
->complex_double_index
!= 0)
5397 return ieee_push_type (info
, info
->complex_double_index
, size
* 2,
5402 fprintf (stderr
, _("IEEE unsupported complex type size %u\n"), size
);
5406 /* FIXME: I don't know what the string is for. */
5407 if (! ieee_define_type (info
, size
* 2, false, false)
5408 || ! ieee_write_number (info
, code
)
5409 || ! ieee_write_id (info
, ""))
5413 info
->complex_float_index
= info
->type_stack
->type
.indx
;
5415 info
->complex_double_index
= info
->type_stack
->type
.indx
;
5420 /* Make a boolean type. IEEE doesn't support these, so we just make
5421 an integer type instead. */
5424 ieee_bool_type (p
, size
)
5428 return ieee_int_type (p
, size
, true);
5431 /* Make an enumeration. */
5434 ieee_enum_type (p
, tag
, names
, vals
)
5438 bfd_signed_vma
*vals
;
5440 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
5441 struct ieee_defined_enum
*e
;
5442 boolean localp
, simple
;
5447 indx
= (unsigned int) -1;
5448 for (e
= info
->enums
; e
!= NULL
; e
= e
->next
)
5458 || tag
[0] != e
->tag
[0]
5459 || strcmp (tag
, e
->tag
) != 0)
5465 /* This enum tag has been seen but not defined. */
5470 if (names
!= NULL
&& e
->names
!= NULL
)
5472 for (i
= 0; names
[i
] != NULL
&& e
->names
[i
] != NULL
; i
++)
5474 if (names
[i
][0] != e
->names
[i
][0]
5475 || vals
[i
] != e
->vals
[i
]
5476 || strcmp (names
[i
], e
->names
[i
]) != 0)
5481 if ((names
== NULL
&& e
->names
== NULL
)
5485 && e
->names
[i
] == NULL
))
5487 /* We've seen this enum before. */
5488 return ieee_push_type (info
, e
->indx
, 0, true, false);
5493 /* We've already seen an enum of the same name, so we must make
5494 sure to output this one locally. */
5500 /* If this is a simple enumeration, in which the values start at 0
5501 and always increment by 1, we can use type E. Otherwise we must
5507 for (i
= 0; names
[i
] != NULL
; i
++)
5517 if (! ieee_define_named_type (info
, tag
, indx
, 0, true, localp
,
5518 (struct ieee_buflist
*) NULL
)
5519 || ! ieee_write_number (info
, simple
? 'E' : 'N'))
5523 /* FIXME: This is supposed to be the enumeration size, but we
5524 don't store that. */
5525 if (! ieee_write_number (info
, 4))
5530 for (i
= 0; names
[i
] != NULL
; i
++)
5532 if (! ieee_write_id (info
, names
[i
]))
5536 if (! ieee_write_number (info
, vals
[i
]))
5544 if (indx
== (unsigned int) -1)
5546 e
= (struct ieee_defined_enum
*) xmalloc (sizeof *e
);
5547 memset (e
, 0, sizeof *e
);
5548 e
->indx
= info
->type_stack
->type
.indx
;
5551 e
->next
= info
->enums
;
5563 /* Make a pointer type. */
5566 ieee_pointer_type (p
)
5569 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
5572 struct ieee_modified_type
*m
= NULL
;
5574 localp
= info
->type_stack
->type
.localp
;
5575 indx
= ieee_pop_type (info
);
5577 /* A pointer to a simple builtin type can be obtained by adding 32.
5578 FIXME: Will this be a short pointer, and will that matter? */
5580 return ieee_push_type (info
, indx
+ 32, 0, true, false);
5584 m
= ieee_get_modified_info (p
, indx
);
5588 /* FIXME: The size should depend upon the architecture. */
5590 return ieee_push_type (info
, m
->pointer
, 4, true, false);
5593 if (! ieee_define_type (info
, 4, true, localp
)
5594 || ! ieee_write_number (info
, 'P')
5595 || ! ieee_write_number (info
, indx
))
5599 m
->pointer
= info
->type_stack
->type
.indx
;
5604 /* Make a function type. This will be called for a method, but we
5605 don't want to actually add it to the type table in that case. We
5606 handle this by defining the type in a private buffer, and only
5607 adding that buffer to the typedef block if we are going to use it. */
5610 ieee_function_type (p
, argcount
, varargs
)
5615 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
5617 unsigned int *args
= NULL
;
5619 unsigned int retindx
;
5620 struct ieee_buflist fndef
;
5621 struct ieee_modified_type
*m
;
5627 args
= (unsigned int *) xmalloc (argcount
* sizeof *args
);
5628 for (i
= argcount
- 1; i
>= 0; i
--)
5630 if (info
->type_stack
->type
.localp
)
5632 args
[i
] = ieee_pop_type (info
);
5635 else if (argcount
< 0)
5638 if (info
->type_stack
->type
.localp
)
5640 retindx
= ieee_pop_type (info
);
5643 if (argcount
< 0 && ! localp
)
5645 m
= ieee_get_modified_info (p
, retindx
);
5649 if (m
->function
> 0)
5650 return ieee_push_type (info
, m
->function
, 0, true, false);
5653 /* An attribute of 0x41 means that the frame and push mask are
5655 if (! ieee_init_buffer (info
, &fndef
)
5656 || ! ieee_define_named_type (info
, (const char *) NULL
,
5657 (unsigned int) -1, 0, true, localp
,
5659 || ! ieee_write_number (info
, 'x')
5660 || ! ieee_write_number (info
, 0x41)
5661 || ! ieee_write_number (info
, 0)
5662 || ! ieee_write_number (info
, 0)
5663 || ! ieee_write_number (info
, retindx
)
5664 || ! ieee_write_number (info
, (bfd_vma
) argcount
+ (varargs
? 1 : 0)))
5668 for (i
= 0; i
< argcount
; i
++)
5669 if (! ieee_write_number (info
, args
[i
]))
5675 /* A varargs function is represented by writing out the last
5676 argument as type void *, although this makes little sense. */
5677 if (! ieee_write_number (info
, (bfd_vma
) builtin_void
+ 32))
5681 if (! ieee_write_number (info
, 0))
5684 /* We wrote the information into fndef, in case we don't need it.
5685 It will be appended to info->types by ieee_pop_type. */
5686 info
->type_stack
->type
.fndef
= fndef
;
5689 m
->function
= info
->type_stack
->type
.indx
;
5694 /* Make a reference type. */
5697 ieee_reference_type (p
)
5700 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
5702 /* IEEE appears to record a normal pointer type, and then use a
5703 pmisc record to indicate that it is really a reference. */
5705 if (! ieee_pointer_type (p
))
5707 info
->type_stack
->type
.referencep
= true;
5711 /* Make a range type. */
5714 ieee_range_type (p
, low
, high
)
5717 bfd_signed_vma high
;
5719 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
5721 boolean unsignedp
, localp
;
5723 size
= info
->type_stack
->type
.size
;
5724 unsignedp
= info
->type_stack
->type
.unsignedp
;
5725 localp
= info
->type_stack
->type
.localp
;
5726 ieee_pop_unused_type (info
);
5727 return (ieee_define_type (info
, size
, unsignedp
, localp
)
5728 && ieee_write_number (info
, 'R')
5729 && ieee_write_number (info
, (bfd_vma
) low
)
5730 && ieee_write_number (info
, (bfd_vma
) high
)
5731 && ieee_write_number (info
, unsignedp
? 0 : 1)
5732 && ieee_write_number (info
, size
));
5735 /* Make an array type. */
5738 ieee_array_type (p
, low
, high
, stringp
)
5741 bfd_signed_vma high
;
5742 boolean stringp ATTRIBUTE_UNUSED
;
5744 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
5745 unsigned int eleindx
;
5748 struct ieee_modified_type
*m
= NULL
;
5749 struct ieee_modified_array_type
*a
;
5751 /* IEEE does not store the range, so we just ignore it. */
5752 ieee_pop_unused_type (info
);
5753 localp
= info
->type_stack
->type
.localp
;
5754 size
= info
->type_stack
->type
.size
;
5755 eleindx
= ieee_pop_type (info
);
5757 /* If we don't know the range, treat the size as exactly one
5760 size
*= (high
- low
) + 1;
5764 m
= ieee_get_modified_info (info
, eleindx
);
5768 for (a
= m
->arrays
; a
!= NULL
; a
= a
->next
)
5770 if (a
->low
== low
&& a
->high
== high
)
5771 return ieee_push_type (info
, a
->indx
, size
, false, false);
5775 if (! ieee_define_type (info
, size
, false, localp
)
5776 || ! ieee_write_number (info
, low
== 0 ? 'Z' : 'C')
5777 || ! ieee_write_number (info
, eleindx
))
5781 if (! ieee_write_number (info
, low
))
5785 if (! ieee_write_number (info
, high
+ 1))
5790 a
= (struct ieee_modified_array_type
*) xmalloc (sizeof *a
);
5791 memset (a
, 0, sizeof *a
);
5793 a
->indx
= info
->type_stack
->type
.indx
;
5797 a
->next
= m
->arrays
;
5804 /* Make a set type. */
5807 ieee_set_type (p
, bitstringp
)
5809 boolean bitstringp ATTRIBUTE_UNUSED
;
5811 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
5813 unsigned int eleindx
;
5815 localp
= info
->type_stack
->type
.localp
;
5816 eleindx
= ieee_pop_type (info
);
5818 /* FIXME: We don't know the size, so we just use 4. */
5820 return (ieee_define_type (info
, 0, true, localp
)
5821 && ieee_write_number (info
, 's')
5822 && ieee_write_number (info
, 4)
5823 && ieee_write_number (info
, eleindx
));
5826 /* Make an offset type. */
5829 ieee_offset_type (p
)
5832 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
5833 unsigned int targetindx
, baseindx
;
5835 targetindx
= ieee_pop_type (info
);
5836 baseindx
= ieee_pop_type (info
);
5838 /* FIXME: The MRI C++ compiler does not appear to generate any
5839 useful type information about an offset type. It just records a
5840 pointer to member as an integer. The MRI/HP IEEE spec does
5841 describe a pmisc record which can be used for a pointer to
5842 member. Unfortunately, it does not describe the target type,
5843 which seems pretty important. I'm going to punt this for now. */
5845 return ieee_int_type (p
, 4, true);
5848 /* Make a method type. */
5851 ieee_method_type (p
, domain
, argcount
, varargs
)
5857 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
5859 /* FIXME: The MRI/HP IEEE spec defines a pmisc record to use for a
5860 method, but the definition is incomplete. We just output an 'x'
5864 ieee_pop_unused_type (info
);
5866 return ieee_function_type (p
, argcount
, varargs
);
5869 /* Make a const qualified type. */
5875 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
5877 boolean unsignedp
, localp
;
5879 struct ieee_modified_type
*m
= NULL
;
5881 size
= info
->type_stack
->type
.size
;
5882 unsignedp
= info
->type_stack
->type
.unsignedp
;
5883 localp
= info
->type_stack
->type
.localp
;
5884 indx
= ieee_pop_type (info
);
5888 m
= ieee_get_modified_info (info
, indx
);
5892 if (m
->const_qualified
> 0)
5893 return ieee_push_type (info
, m
->const_qualified
, size
, unsignedp
,
5897 if (! ieee_define_type (info
, size
, unsignedp
, localp
)
5898 || ! ieee_write_number (info
, 'n')
5899 || ! ieee_write_number (info
, 1)
5900 || ! ieee_write_number (info
, indx
))
5904 m
->const_qualified
= info
->type_stack
->type
.indx
;
5909 /* Make a volatile qualified type. */
5912 ieee_volatile_type (p
)
5915 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
5917 boolean unsignedp
, localp
;
5919 struct ieee_modified_type
*m
= NULL
;
5921 size
= info
->type_stack
->type
.size
;
5922 unsignedp
= info
->type_stack
->type
.unsignedp
;
5923 localp
= info
->type_stack
->type
.localp
;
5924 indx
= ieee_pop_type (info
);
5928 m
= ieee_get_modified_info (info
, indx
);
5932 if (m
->volatile_qualified
> 0)
5933 return ieee_push_type (info
, m
->volatile_qualified
, size
, unsignedp
,
5937 if (! ieee_define_type (info
, size
, unsignedp
, localp
)
5938 || ! ieee_write_number (info
, 'n')
5939 || ! ieee_write_number (info
, 2)
5940 || ! ieee_write_number (info
, indx
))
5944 m
->volatile_qualified
= info
->type_stack
->type
.indx
;
5949 /* Convert an enum debug_visibility into a CXXFLAGS value. */
5952 ieee_vis_to_flags (visibility
)
5953 enum debug_visibility visibility
;
5959 case DEBUG_VISIBILITY_PUBLIC
:
5960 return CXXFLAGS_VISIBILITY_PUBLIC
;
5961 case DEBUG_VISIBILITY_PRIVATE
:
5962 return CXXFLAGS_VISIBILITY_PRIVATE
;
5963 case DEBUG_VISIBILITY_PROTECTED
:
5964 return CXXFLAGS_VISIBILITY_PROTECTED
;
5969 /* Start defining a struct type. We build it in the strdef field on
5970 the stack, to avoid confusing type definitions required by the
5971 fields with the struct type itself. */
5974 ieee_start_struct_type (p
, tag
, id
, structp
, size
)
5981 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
5982 boolean localp
, ignorep
;
5986 struct ieee_name_type_hash_entry
*h
;
5987 struct ieee_name_type
*nt
, *ntlook
;
5988 struct ieee_buflist strdef
;
5993 /* We need to create a tag for internal use even if we don't want
5994 one for external use. This will let us refer to an anonymous
6003 sprintf (ab
, "__anon%u", id
);
6008 /* If we already have references to the tag, we must use the
6009 existing type index. */
6010 h
= ieee_name_type_hash_lookup (&info
->tags
, look
, true, copy
);
6015 for (ntlook
= h
->types
; ntlook
!= NULL
; ntlook
= ntlook
->next
)
6017 if (ntlook
->id
== id
)
6019 else if (! ntlook
->type
.localp
)
6021 /* We are creating a duplicate definition of a globally
6022 defined tag. Force it to be local to avoid
6030 assert (localp
== nt
->type
.localp
);
6031 if (nt
->kind
== DEBUG_KIND_ILLEGAL
&& ! localp
)
6033 /* We've already seen a global definition of the type.
6034 Ignore this new definition. */
6040 nt
= (struct ieee_name_type
*) xmalloc (sizeof *nt
);
6041 memset (nt
, 0, sizeof *nt
);
6043 nt
->type
.name
= h
->root
.string
;
6044 nt
->next
= h
->types
;
6046 nt
->type
.indx
= info
->type_indx
;
6050 nt
->kind
= DEBUG_KIND_ILLEGAL
;
6052 if (! ieee_init_buffer (info
, &strdef
)
6053 || ! ieee_define_named_type (info
, tag
, nt
->type
.indx
, size
, true,
6055 || ! ieee_write_number (info
, structp
? 'S' : 'U')
6056 || ! ieee_write_number (info
, size
))
6063 /* We never want nt->type.name to be NULL. We want the rest of
6064 the type to be the object set up on the type stack; it will
6065 have a NULL name if tag is NULL. */
6066 hold
= nt
->type
.name
;
6067 nt
->type
= info
->type_stack
->type
;
6068 nt
->type
.name
= hold
;
6071 info
->type_stack
->type
.name
= tag
;
6072 info
->type_stack
->type
.strdef
= strdef
;
6073 info
->type_stack
->type
.ignorep
= ignorep
;
6078 /* Add a field to a struct. */
6081 ieee_struct_field (p
, name
, bitpos
, bitsize
, visibility
)
6086 enum debug_visibility visibility
;
6088 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
6096 assert (info
->type_stack
!= NULL
6097 && info
->type_stack
->next
!= NULL
6098 && ! ieee_buffer_emptyp (&info
->type_stack
->next
->type
.strdef
));
6100 /* If we are ignoring this struct definition, just pop and ignore
6102 if (info
->type_stack
->next
->type
.ignorep
)
6104 ieee_pop_unused_type (info
);
6108 size
= info
->type_stack
->type
.size
;
6109 unsignedp
= info
->type_stack
->type
.unsignedp
;
6110 referencep
= info
->type_stack
->type
.referencep
;
6111 localp
= info
->type_stack
->type
.localp
;
6112 indx
= ieee_pop_type (info
);
6115 info
->type_stack
->type
.localp
= true;
6117 if (info
->type_stack
->type
.classdef
!= NULL
)
6122 /* This is a class. We must add a description of this field to
6123 the class records we are building. */
6125 flags
= ieee_vis_to_flags (visibility
);
6126 nindx
= info
->type_stack
->type
.classdef
->indx
;
6127 if (! ieee_change_buffer (info
,
6128 &info
->type_stack
->type
.classdef
->pmiscbuf
)
6129 || ! ieee_write_asn (info
, nindx
, 'd')
6130 || ! ieee_write_asn (info
, nindx
, flags
)
6131 || ! ieee_write_atn65 (info
, nindx
, name
)
6132 || ! ieee_write_atn65 (info
, nindx
, name
))
6134 info
->type_stack
->type
.classdef
->pmisccount
+= 4;
6140 /* We need to output a record recording that this field is
6141 really of reference type. We put this on the refs field
6142 of classdef, so that it can be appended to the C++
6143 records after the class is defined. */
6145 nindx
= info
->name_indx
;
6148 if (! ieee_change_buffer (info
,
6149 &info
->type_stack
->type
.classdef
->refs
)
6150 || ! ieee_write_byte (info
, (int) ieee_nn_record
)
6151 || ! ieee_write_number (info
, nindx
)
6152 || ! ieee_write_id (info
, "")
6153 || ! ieee_write_2bytes (info
, (int) ieee_atn_record_enum
)
6154 || ! ieee_write_number (info
, nindx
)
6155 || ! ieee_write_number (info
, 0)
6156 || ! ieee_write_number (info
, 62)
6157 || ! ieee_write_number (info
, 80)
6158 || ! ieee_write_number (info
, 4)
6159 || ! ieee_write_asn (info
, nindx
, 'R')
6160 || ! ieee_write_asn (info
, nindx
, 3)
6161 || ! ieee_write_atn65 (info
, nindx
, info
->type_stack
->type
.name
)
6162 || ! ieee_write_atn65 (info
, nindx
, name
))
6167 /* If the bitsize doesn't match the expected size, we need to output
6169 if (size
== 0 || bitsize
== 0 || bitsize
== size
* 8)
6170 offset
= bitpos
/ 8;
6173 if (! ieee_define_type (info
, 0, unsignedp
,
6174 info
->type_stack
->type
.localp
)
6175 || ! ieee_write_number (info
, 'g')
6176 || ! ieee_write_number (info
, unsignedp
? 0 : 1)
6177 || ! ieee_write_number (info
, bitsize
)
6178 || ! ieee_write_number (info
, indx
))
6180 indx
= ieee_pop_type (info
);
6184 /* Switch to the struct we are building in order to output this
6185 field definition. */
6186 return (ieee_change_buffer (info
, &info
->type_stack
->type
.strdef
)
6187 && ieee_write_id (info
, name
)
6188 && ieee_write_number (info
, indx
)
6189 && ieee_write_number (info
, offset
));
6192 /* Finish up a struct type. */
6195 ieee_end_struct_type (p
)
6198 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
6199 struct ieee_buflist
*pb
;
6201 assert (info
->type_stack
!= NULL
6202 && ! ieee_buffer_emptyp (&info
->type_stack
->type
.strdef
));
6204 /* If we were ignoring this struct definition because it was a
6205 duplicate defintion, just through away whatever bytes we have
6206 accumulated. Leave the type on the stack. */
6207 if (info
->type_stack
->type
.ignorep
)
6210 /* If this is not a duplicate definition of this tag, then localp
6211 will be false, and we can put it in the global type block.
6212 FIXME: We should avoid outputting duplicate definitions which are
6214 if (! info
->type_stack
->type
.localp
)
6216 /* Make sure we have started the global type block. */
6217 if (ieee_buffer_emptyp (&info
->global_types
))
6219 if (! ieee_change_buffer (info
, &info
->global_types
)
6220 || ! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
6221 || ! ieee_write_byte (info
, 2)
6222 || ! ieee_write_number (info
, 0)
6223 || ! ieee_write_id (info
, ""))
6226 pb
= &info
->global_types
;
6230 /* Make sure we have started the types block. */
6231 if (ieee_buffer_emptyp (&info
->types
))
6233 if (! ieee_change_buffer (info
, &info
->types
)
6234 || ! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
6235 || ! ieee_write_byte (info
, 1)
6236 || ! ieee_write_number (info
, 0)
6237 || ! ieee_write_id (info
, info
->modname
))
6243 /* Append the struct definition to the types. */
6244 if (! ieee_append_buffer (info
, pb
, &info
->type_stack
->type
.strdef
)
6245 || ! ieee_init_buffer (info
, &info
->type_stack
->type
.strdef
))
6248 /* Leave the struct on the type stack. */
6253 /* Start a class type. */
6256 ieee_start_class_type (p
, tag
, id
, structp
, size
, vptr
, ownvptr
)
6265 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
6267 struct ieee_buflist pmiscbuf
;
6269 struct ieee_type_class
*classdef
;
6271 /* A C++ class is output as a C++ struct along with a set of pmisc
6272 records describing the class. */
6274 /* We need to have a name so that we can associate the struct and
6280 t
= (char *) xmalloc (20);
6281 sprintf (t
, "__anon%u", id
);
6285 /* We can't write out the virtual table information until we have
6286 finished the class, because we don't know the virtual table size.
6287 We get the size from the largest voffset we see. */
6289 if (vptr
&& ! ownvptr
)
6291 vclass
= info
->type_stack
->type
.name
;
6292 assert (vclass
!= NULL
);
6293 /* We don't call ieee_pop_unused_type, since the class should
6295 (void) ieee_pop_type (info
);
6298 if (! ieee_start_struct_type (p
, tag
, id
, structp
, size
))
6301 indx
= info
->name_indx
;
6304 /* We write out pmisc records into the classdef field. We will
6305 write out the pmisc start after we know the number of records we
6307 if (! ieee_init_buffer (info
, &pmiscbuf
)
6308 || ! ieee_change_buffer (info
, &pmiscbuf
)
6309 || ! ieee_write_asn (info
, indx
, 'T')
6310 || ! ieee_write_asn (info
, indx
, structp
? 'o' : 'u')
6311 || ! ieee_write_atn65 (info
, indx
, tag
))
6314 classdef
= (struct ieee_type_class
*) xmalloc (sizeof *classdef
);
6315 memset (classdef
, 0, sizeof *classdef
);
6317 classdef
->indx
= indx
;
6318 classdef
->pmiscbuf
= pmiscbuf
;
6319 classdef
->pmisccount
= 3;
6320 classdef
->vclass
= vclass
;
6321 classdef
->ownvptr
= ownvptr
;
6323 info
->type_stack
->type
.classdef
= classdef
;
6328 /* Add a static member to a class. */
6331 ieee_class_static_member (p
, name
, physname
, visibility
)
6334 const char *physname
;
6335 enum debug_visibility visibility
;
6337 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
6341 /* We don't care about the type. Hopefully there will be a call to
6342 ieee_variable declaring the physical name and the type, since
6343 that is where an IEEE consumer must get the type. */
6344 ieee_pop_unused_type (info
);
6346 assert (info
->type_stack
!= NULL
6347 && info
->type_stack
->type
.classdef
!= NULL
);
6349 flags
= ieee_vis_to_flags (visibility
);
6350 flags
|= CXXFLAGS_STATIC
;
6352 nindx
= info
->type_stack
->type
.classdef
->indx
;
6354 if (! ieee_change_buffer (info
, &info
->type_stack
->type
.classdef
->pmiscbuf
)
6355 || ! ieee_write_asn (info
, nindx
, 'd')
6356 || ! ieee_write_asn (info
, nindx
, flags
)
6357 || ! ieee_write_atn65 (info
, nindx
, name
)
6358 || ! ieee_write_atn65 (info
, nindx
, physname
))
6360 info
->type_stack
->type
.classdef
->pmisccount
+= 4;
6365 /* Add a base class to a class. */
6368 ieee_class_baseclass (p
, bitpos
, virtual, visibility
)
6372 enum debug_visibility visibility
;
6374 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
6382 assert (info
->type_stack
!= NULL
6383 && info
->type_stack
->type
.name
!= NULL
6384 && info
->type_stack
->next
!= NULL
6385 && info
->type_stack
->next
->type
.classdef
!= NULL
6386 && ! ieee_buffer_emptyp (&info
->type_stack
->next
->type
.strdef
));
6388 bname
= info
->type_stack
->type
.name
;
6389 localp
= info
->type_stack
->type
.localp
;
6390 bindx
= ieee_pop_type (info
);
6392 /* We are currently defining both a struct and a class. We must
6393 write out a field definition in the struct which holds the base
6394 class. The stabs debugging reader will create a field named
6395 _vb$CLASS for a virtual base class, so we just use that. FIXME:
6396 we should not depend upon a detail of stabs debugging. */
6399 fname
= (char *) xmalloc (strlen (bname
) + sizeof "_vb$");
6400 sprintf (fname
, "_vb$%s", bname
);
6401 flags
= BASEFLAGS_VIRTUAL
;
6406 info
->type_stack
->type
.localp
= true;
6408 fname
= (char *) xmalloc (strlen (bname
) + sizeof "_b$");
6409 sprintf (fname
, "_b$%s", bname
);
6411 if (! ieee_change_buffer (info
, &info
->type_stack
->type
.strdef
)
6412 || ! ieee_write_id (info
, fname
)
6413 || ! ieee_write_number (info
, bindx
)
6414 || ! ieee_write_number (info
, bitpos
/ 8))
6419 if (visibility
== DEBUG_VISIBILITY_PRIVATE
)
6420 flags
|= BASEFLAGS_PRIVATE
;
6422 nindx
= info
->type_stack
->type
.classdef
->indx
;
6424 if (! ieee_change_buffer (info
, &info
->type_stack
->type
.classdef
->pmiscbuf
)
6425 || ! ieee_write_asn (info
, nindx
, 'b')
6426 || ! ieee_write_asn (info
, nindx
, flags
)
6427 || ! ieee_write_atn65 (info
, nindx
, bname
)
6428 || ! ieee_write_asn (info
, nindx
, 0)
6429 || ! ieee_write_atn65 (info
, nindx
, fname
))
6431 info
->type_stack
->type
.classdef
->pmisccount
+= 5;
6438 /* Start building a method for a class. */
6441 ieee_class_start_method (p
, name
)
6445 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
6447 assert (info
->type_stack
!= NULL
6448 && info
->type_stack
->type
.classdef
!= NULL
6449 && info
->type_stack
->type
.classdef
->method
== NULL
);
6451 info
->type_stack
->type
.classdef
->method
= name
;
6456 /* Define a new method variant, either static or not. */
6459 ieee_class_method_var (info
, physname
, visibility
, staticp
, constp
,
6460 volatilep
, voffset
, context
)
6461 struct ieee_handle
*info
;
6462 const char *physname
;
6463 enum debug_visibility visibility
;
6474 /* We don't need the type of the method. An IEEE consumer which
6475 wants the type must track down the function by the physical name
6476 and get the type from that. */
6477 ieee_pop_unused_type (info
);
6479 /* We don't use the context. FIXME: We probably ought to use it to
6480 adjust the voffset somehow, but I don't really know how. */
6482 ieee_pop_unused_type (info
);
6484 assert (info
->type_stack
!= NULL
6485 && info
->type_stack
->type
.classdef
!= NULL
6486 && info
->type_stack
->type
.classdef
->method
!= NULL
);
6488 flags
= ieee_vis_to_flags (visibility
);
6490 /* FIXME: We never set CXXFLAGS_OVERRIDE, CXXFLAGS_OPERATOR,
6491 CXXFLAGS_CTORDTOR, CXXFLAGS_CTOR, or CXXFLAGS_INLINE. */
6494 flags
|= CXXFLAGS_STATIC
;
6496 flags
|= CXXFLAGS_CONST
;
6498 flags
|= CXXFLAGS_VOLATILE
;
6500 nindx
= info
->type_stack
->type
.classdef
->indx
;
6502 virtual = context
|| voffset
> 0;
6504 if (! ieee_change_buffer (info
,
6505 &info
->type_stack
->type
.classdef
->pmiscbuf
)
6506 || ! ieee_write_asn (info
, nindx
, virtual ? 'v' : 'm')
6507 || ! ieee_write_asn (info
, nindx
, flags
)
6508 || ! ieee_write_atn65 (info
, nindx
,
6509 info
->type_stack
->type
.classdef
->method
)
6510 || ! ieee_write_atn65 (info
, nindx
, physname
))
6515 if (voffset
> info
->type_stack
->type
.classdef
->voffset
)
6516 info
->type_stack
->type
.classdef
->voffset
= voffset
;
6517 if (! ieee_write_asn (info
, nindx
, voffset
))
6519 ++info
->type_stack
->type
.classdef
->pmisccount
;
6522 if (! ieee_write_asn (info
, nindx
, 0))
6525 info
->type_stack
->type
.classdef
->pmisccount
+= 5;
6530 /* Define a new method variant. */
6533 ieee_class_method_variant (p
, physname
, visibility
, constp
, volatilep
,
6536 const char *physname
;
6537 enum debug_visibility visibility
;
6543 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
6545 return ieee_class_method_var (info
, physname
, visibility
, false, constp
,
6546 volatilep
, voffset
, context
);
6549 /* Define a new static method variant. */
6552 ieee_class_static_method_variant (p
, physname
, visibility
, constp
, volatilep
)
6554 const char *physname
;
6555 enum debug_visibility visibility
;
6559 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
6561 return ieee_class_method_var (info
, physname
, visibility
, true, constp
,
6562 volatilep
, 0, false);
6565 /* Finish up a method. */
6568 ieee_class_end_method (p
)
6571 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
6573 assert (info
->type_stack
!= NULL
6574 && info
->type_stack
->type
.classdef
!= NULL
6575 && info
->type_stack
->type
.classdef
->method
!= NULL
);
6577 info
->type_stack
->type
.classdef
->method
= NULL
;
6582 /* Finish up a class. */
6585 ieee_end_class_type (p
)
6588 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
6591 assert (info
->type_stack
!= NULL
6592 && info
->type_stack
->type
.classdef
!= NULL
);
6594 /* If we were ignoring this class definition because it was a
6595 duplicate definition, just through away whatever bytes we have
6596 accumulated. Leave the type on the stack. */
6597 if (info
->type_stack
->type
.ignorep
)
6600 nindx
= info
->type_stack
->type
.classdef
->indx
;
6602 /* If we have a virtual table, we can write out the information now. */
6603 if (info
->type_stack
->type
.classdef
->vclass
!= NULL
6604 || info
->type_stack
->type
.classdef
->ownvptr
)
6606 if (! ieee_change_buffer (info
,
6607 &info
->type_stack
->type
.classdef
->pmiscbuf
)
6608 || ! ieee_write_asn (info
, nindx
, 'z')
6609 || ! ieee_write_atn65 (info
, nindx
, "")
6610 || ! ieee_write_asn (info
, nindx
,
6611 info
->type_stack
->type
.classdef
->voffset
))
6613 if (info
->type_stack
->type
.classdef
->ownvptr
)
6615 if (! ieee_write_atn65 (info
, nindx
, ""))
6620 if (! ieee_write_atn65 (info
, nindx
,
6621 info
->type_stack
->type
.classdef
->vclass
))
6624 if (! ieee_write_asn (info
, nindx
, 0))
6626 info
->type_stack
->type
.classdef
->pmisccount
+= 5;
6629 /* Now that we know the number of pmisc records, we can write out
6630 the atn62 which starts the pmisc records, and append them to the
6633 if (! ieee_change_buffer (info
, &info
->cxx
)
6634 || ! ieee_write_byte (info
, (int) ieee_nn_record
)
6635 || ! ieee_write_number (info
, nindx
)
6636 || ! ieee_write_id (info
, "")
6637 || ! ieee_write_2bytes (info
, (int) ieee_atn_record_enum
)
6638 || ! ieee_write_number (info
, nindx
)
6639 || ! ieee_write_number (info
, 0)
6640 || ! ieee_write_number (info
, 62)
6641 || ! ieee_write_number (info
, 80)
6642 || ! ieee_write_number (info
,
6643 info
->type_stack
->type
.classdef
->pmisccount
))
6646 if (! ieee_append_buffer (info
, &info
->cxx
,
6647 &info
->type_stack
->type
.classdef
->pmiscbuf
))
6649 if (! ieee_buffer_emptyp (&info
->type_stack
->type
.classdef
->refs
))
6651 if (! ieee_append_buffer (info
, &info
->cxx
,
6652 &info
->type_stack
->type
.classdef
->refs
))
6656 return ieee_end_struct_type (p
);
6659 /* Push a previously seen typedef onto the type stack. */
6662 ieee_typedef_type (p
, name
)
6666 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
6667 struct ieee_name_type_hash_entry
*h
;
6668 struct ieee_name_type
*nt
;
6670 h
= ieee_name_type_hash_lookup (&info
->typedefs
, name
, false, false);
6672 /* h should never be NULL, since that would imply that the generic
6673 debugging code has asked for a typedef which it has not yet
6677 /* We always use the most recently defined type for this name, which
6678 will be the first one on the list. */
6681 if (! ieee_push_type (info
, nt
->type
.indx
, nt
->type
.size
,
6682 nt
->type
.unsignedp
, nt
->type
.localp
))
6685 /* Copy over any other type information we may have. */
6686 info
->type_stack
->type
= nt
->type
;
6691 /* Push a tagged type onto the type stack. */
6694 ieee_tag_type (p
, name
, id
, kind
)
6698 enum debug_type_kind kind
;
6700 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
6704 struct ieee_name_type_hash_entry
*h
;
6705 struct ieee_name_type
*nt
;
6707 if (kind
== DEBUG_KIND_ENUM
)
6709 struct ieee_defined_enum
*e
;
6713 for (e
= info
->enums
; e
!= NULL
; e
= e
->next
)
6714 if (e
->tag
!= NULL
&& strcmp (e
->tag
, name
) == 0)
6715 return ieee_push_type (info
, e
->indx
, 0, true, false);
6717 e
= (struct ieee_defined_enum
*) xmalloc (sizeof *e
);
6718 memset (e
, 0, sizeof *e
);
6720 e
->indx
= info
->type_indx
;
6725 e
->next
= info
->enums
;
6728 return ieee_push_type (info
, e
->indx
, 0, true, false);
6736 sprintf (ab
, "__anon%u", id
);
6741 h
= ieee_name_type_hash_lookup (&info
->tags
, name
, true, copy
);
6745 for (nt
= h
->types
; nt
!= NULL
; nt
= nt
->next
)
6749 if (! ieee_push_type (info
, nt
->type
.indx
, nt
->type
.size
,
6750 nt
->type
.unsignedp
, nt
->type
.localp
))
6752 /* Copy over any other type information we may have. */
6753 info
->type_stack
->type
= nt
->type
;
6757 if (! nt
->type
.localp
)
6759 /* This is a duplicate of a global type, so it must be
6765 nt
= (struct ieee_name_type
*) xmalloc (sizeof *nt
);
6766 memset (nt
, 0, sizeof *nt
);
6769 nt
->type
.name
= h
->root
.string
;
6770 nt
->type
.indx
= info
->type_indx
;
6771 nt
->type
.localp
= localp
;
6775 nt
->next
= h
->types
;
6778 if (! ieee_push_type (info
, nt
->type
.indx
, 0, false, localp
))
6781 info
->type_stack
->type
.name
= h
->root
.string
;
6786 /* Output a typedef. */
6789 ieee_typdef (p
, name
)
6793 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
6794 struct ieee_write_type type
;
6798 struct ieee_name_type_hash_entry
*h
;
6799 struct ieee_name_type
*nt
;
6801 type
= info
->type_stack
->type
;
6804 /* If this is a simple builtin type using a builtin name, we don't
6805 want to output the typedef itself. We also want to change the
6806 type index to correspond to the name being used. We recognize
6807 names used in stabs debugging output even if they don't exactly
6808 correspond to the names used for the IEEE builtin types. */
6810 if (indx
<= (unsigned int) builtin_bcd_float
)
6812 switch ((enum builtin_types
) indx
)
6818 if (strcmp (name
, "void") == 0)
6822 case builtin_signed_char
:
6824 if (strcmp (name
, "signed char") == 0)
6826 indx
= (unsigned int) builtin_signed_char
;
6829 else if (strcmp (name
, "char") == 0)
6831 indx
= (unsigned int) builtin_char
;
6836 case builtin_unsigned_char
:
6837 if (strcmp (name
, "unsigned char") == 0)
6841 case builtin_signed_short_int
:
6843 case builtin_short_int
:
6844 case builtin_signed_short
:
6845 if (strcmp (name
, "signed short int") == 0)
6847 indx
= (unsigned int) builtin_signed_short_int
;
6850 else if (strcmp (name
, "short") == 0)
6852 indx
= (unsigned int) builtin_short
;
6855 else if (strcmp (name
, "short int") == 0)
6857 indx
= (unsigned int) builtin_short_int
;
6860 else if (strcmp (name
, "signed short") == 0)
6862 indx
= (unsigned int) builtin_signed_short
;
6867 case builtin_unsigned_short_int
:
6868 case builtin_unsigned_short
:
6869 if (strcmp (name
, "unsigned short int") == 0
6870 || strcmp (name
, "short unsigned int") == 0)
6872 indx
= builtin_unsigned_short_int
;
6875 else if (strcmp (name
, "unsigned short") == 0)
6877 indx
= builtin_unsigned_short
;
6882 case builtin_signed_long
:
6883 case builtin_int
: /* FIXME: Size depends upon architecture. */
6885 if (strcmp (name
, "signed long") == 0)
6887 indx
= builtin_signed_long
;
6890 else if (strcmp (name
, "int") == 0)
6895 else if (strcmp (name
, "long") == 0
6896 || strcmp (name
, "long int") == 0)
6898 indx
= builtin_long
;
6903 case builtin_unsigned_long
:
6904 case builtin_unsigned
: /* FIXME: Size depends upon architecture. */
6905 case builtin_unsigned_int
: /* FIXME: Like builtin_unsigned. */
6906 if (strcmp (name
, "unsigned long") == 0
6907 || strcmp (name
, "long unsigned int") == 0)
6909 indx
= builtin_unsigned_long
;
6912 else if (strcmp (name
, "unsigned") == 0)
6914 indx
= builtin_unsigned
;
6917 else if (strcmp (name
, "unsigned int") == 0)
6919 indx
= builtin_unsigned_int
;
6924 case builtin_signed_long_long
:
6925 if (strcmp (name
, "signed long long") == 0
6926 || strcmp (name
, "long long int") == 0)
6930 case builtin_unsigned_long_long
:
6931 if (strcmp (name
, "unsigned long long") == 0
6932 || strcmp (name
, "long long unsigned int") == 0)
6937 if (strcmp (name
, "float") == 0)
6941 case builtin_double
:
6942 if (strcmp (name
, "double") == 0)
6946 case builtin_long_double
:
6947 if (strcmp (name
, "long double") == 0)
6951 case builtin_long_long_double
:
6952 if (strcmp (name
, "long long double") == 0)
6961 h
= ieee_name_type_hash_lookup (&info
->typedefs
, name
, true, false);
6965 /* See if we have already defined this type with this name. */
6966 localp
= type
.localp
;
6967 for (nt
= h
->types
; nt
!= NULL
; nt
= nt
->next
)
6971 /* If this is a global definition, then we don't need to
6972 do anything here. */
6973 if (! nt
->type
.localp
)
6975 ieee_pop_unused_type (info
);
6981 /* This is a duplicate definition, so make this one local. */
6986 /* We need to add a new typedef for this type. */
6988 nt
= (struct ieee_name_type
*) xmalloc (sizeof *nt
);
6989 memset (nt
, 0, sizeof *nt
);
6992 nt
->type
.name
= name
;
6993 nt
->type
.localp
= localp
;
6994 nt
->kind
= DEBUG_KIND_ILLEGAL
;
6996 nt
->next
= h
->types
;
7001 /* This is one of the builtin typedefs, so we don't need to
7002 actually define it. */
7003 ieee_pop_unused_type (info
);
7007 indx
= ieee_pop_type (info
);
7009 if (! ieee_define_named_type (info
, name
, (unsigned int) -1, type
.size
,
7010 type
.unsignedp
, localp
,
7011 (struct ieee_buflist
*) NULL
)
7012 || ! ieee_write_number (info
, 'T')
7013 || ! ieee_write_number (info
, indx
))
7016 /* Remove the type we just added to the type stack. This should not
7017 be ieee_pop_unused_type, since the type is used, we just don't
7019 (void) ieee_pop_type (info
);
7024 /* Output a tag for a type. We don't have to do anything here. */
7029 const char *name ATTRIBUTE_UNUSED
;
7031 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
7033 /* This should not be ieee_pop_unused_type, since we want the type
7035 (void) ieee_pop_type (info
);
7039 /* Output an integer constant. */
7042 ieee_int_constant (p
, name
, val
)
7043 PTR p ATTRIBUTE_UNUSED
;
7044 const char *name ATTRIBUTE_UNUSED
;
7045 bfd_vma val ATTRIBUTE_UNUSED
;
7051 /* Output a floating point constant. */
7054 ieee_float_constant (p
, name
, val
)
7055 PTR p ATTRIBUTE_UNUSED
;
7056 const char *name ATTRIBUTE_UNUSED
;
7057 double val ATTRIBUTE_UNUSED
;
7063 /* Output a typed constant. */
7066 ieee_typed_constant (p
, name
, val
)
7068 const char *name ATTRIBUTE_UNUSED
;
7069 bfd_vma val ATTRIBUTE_UNUSED
;
7071 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
7074 ieee_pop_unused_type (info
);
7078 /* Output a variable. */
7081 ieee_variable (p
, name
, kind
, val
)
7084 enum debug_var_kind kind
;
7087 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
7088 unsigned int name_indx
;
7091 unsigned int type_indx
;
7095 size
= info
->type_stack
->type
.size
;
7096 referencep
= info
->type_stack
->type
.referencep
;
7097 type_indx
= ieee_pop_type (info
);
7099 assert (! ieee_buffer_emptyp (&info
->vars
));
7100 if (! ieee_change_buffer (info
, &info
->vars
))
7103 name_indx
= info
->name_indx
;
7106 /* Write out an NN and an ATN record for this variable. */
7107 if (! ieee_write_byte (info
, (int) ieee_nn_record
)
7108 || ! ieee_write_number (info
, name_indx
)
7109 || ! ieee_write_id (info
, name
)
7110 || ! ieee_write_2bytes (info
, (int) ieee_atn_record_enum
)
7111 || ! ieee_write_number (info
, name_indx
)
7112 || ! ieee_write_number (info
, type_indx
))
7120 if (! ieee_write_number (info
, 8)
7121 || ! ieee_add_range (info
, false, val
, val
+ size
))
7127 if (! ieee_write_number (info
, 3)
7128 || ! ieee_add_range (info
, false, val
, val
+ size
))
7133 case DEBUG_LOCAL_STATIC
:
7134 if (! ieee_write_number (info
, 3)
7135 || ! ieee_add_range (info
, false, val
, val
+ size
))
7141 if (! ieee_write_number (info
, 1)
7142 || ! ieee_write_number (info
, val
))
7147 case DEBUG_REGISTER
:
7148 if (! ieee_write_number (info
, 2)
7149 || ! ieee_write_number (info
,
7150 ieee_genreg_to_regno (info
->abfd
, val
)))
7159 if (! ieee_write_asn (info
, name_indx
, val
))
7163 /* If this is really a reference type, then we just output it with
7164 pointer type, and must now output a C++ record indicating that it
7165 is really reference type. */
7170 nindx
= info
->name_indx
;
7173 /* If this is a global variable, we want to output the misc
7174 record in the C++ misc record block. Otherwise, we want to
7175 output it just after the variable definition, which is where
7176 the current buffer is. */
7179 if (! ieee_change_buffer (info
, &info
->cxx
))
7183 if (! ieee_write_byte (info
, (int) ieee_nn_record
)
7184 || ! ieee_write_number (info
, nindx
)
7185 || ! ieee_write_id (info
, "")
7186 || ! ieee_write_2bytes (info
, (int) ieee_atn_record_enum
)
7187 || ! ieee_write_number (info
, nindx
)
7188 || ! ieee_write_number (info
, 0)
7189 || ! ieee_write_number (info
, 62)
7190 || ! ieee_write_number (info
, 80)
7191 || ! ieee_write_number (info
, 3)
7192 || ! ieee_write_asn (info
, nindx
, 'R')
7193 || ! ieee_write_asn (info
, nindx
, refflag
)
7194 || ! ieee_write_atn65 (info
, nindx
, name
))
7201 /* Start outputting information for a function. */
7204 ieee_start_function (p
, name
, global
)
7209 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
7211 unsigned int retindx
, typeindx
;
7213 referencep
= info
->type_stack
->type
.referencep
;
7214 retindx
= ieee_pop_type (info
);
7216 /* Besides recording a BB4 or BB6 block, we record the type of the
7217 function in the BB1 typedef block. We can't write out the full
7218 type until we have seen all the parameters, so we accumulate it
7219 in info->fntype and info->fnargs. */
7220 if (! ieee_buffer_emptyp (&info
->fntype
))
7222 /* FIXME: This might happen someday if we support nested
7227 info
->fnname
= name
;
7229 /* An attribute of 0x40 means that the push mask is unknown. */
7230 if (! ieee_define_named_type (info
, name
, (unsigned int) -1, 0, false, true,
7232 || ! ieee_write_number (info
, 'x')
7233 || ! ieee_write_number (info
, 0x40)
7234 || ! ieee_write_number (info
, 0)
7235 || ! ieee_write_number (info
, 0)
7236 || ! ieee_write_number (info
, retindx
))
7239 typeindx
= ieee_pop_type (info
);
7241 if (! ieee_init_buffer (info
, &info
->fnargs
))
7243 info
->fnargcount
= 0;
7245 /* If the function return value is actually a reference type, we
7246 must add a record indicating that. */
7251 nindx
= info
->name_indx
;
7253 if (! ieee_change_buffer (info
, &info
->cxx
)
7254 || ! ieee_write_byte (info
, (int) ieee_nn_record
)
7255 || ! ieee_write_number (info
, nindx
)
7256 || ! ieee_write_id (info
, "")
7257 || ! ieee_write_2bytes (info
, (int) ieee_atn_record_enum
)
7258 || ! ieee_write_number (info
, nindx
)
7259 || ! ieee_write_number (info
, 0)
7260 || ! ieee_write_number (info
, 62)
7261 || ! ieee_write_number (info
, 80)
7262 || ! ieee_write_number (info
, 3)
7263 || ! ieee_write_asn (info
, nindx
, 'R')
7264 || ! ieee_write_asn (info
, nindx
, global
? 0 : 1)
7265 || ! ieee_write_atn65 (info
, nindx
, name
))
7269 assert (! ieee_buffer_emptyp (&info
->vars
));
7270 if (! ieee_change_buffer (info
, &info
->vars
))
7273 /* The address is written out as the first block. */
7275 ++info
->block_depth
;
7277 return (ieee_write_byte (info
, (int) ieee_bb_record_enum
)
7278 && ieee_write_byte (info
, global
? 4 : 6)
7279 && ieee_write_number (info
, 0)
7280 && ieee_write_id (info
, name
)
7281 && ieee_write_number (info
, 0)
7282 && ieee_write_number (info
, typeindx
));
7285 /* Add a function parameter. This will normally be called before the
7286 first block, so we postpone them until we see the block. */
7289 ieee_function_parameter (p
, name
, kind
, val
)
7292 enum debug_parm_kind kind
;
7295 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
7296 struct ieee_pending_parm
*m
, **pm
;
7298 assert (info
->block_depth
== 1);
7300 m
= (struct ieee_pending_parm
*) xmalloc (sizeof *m
);
7301 memset (m
, 0, sizeof *m
);
7305 m
->referencep
= info
->type_stack
->type
.referencep
;
7306 m
->type
= ieee_pop_type (info
);
7310 for (pm
= &info
->pending_parms
; *pm
!= NULL
; pm
= &(*pm
)->next
)
7314 /* Add the type to the fnargs list. */
7315 if (! ieee_change_buffer (info
, &info
->fnargs
)
7316 || ! ieee_write_number (info
, m
->type
))
7323 /* Output pending function parameters. */
7326 ieee_output_pending_parms (info
)
7327 struct ieee_handle
*info
;
7329 struct ieee_pending_parm
*m
;
7330 unsigned int refcount
;
7333 for (m
= info
->pending_parms
; m
!= NULL
; m
= m
->next
)
7335 enum debug_var_kind vkind
;
7342 case DEBUG_PARM_STACK
:
7343 case DEBUG_PARM_REFERENCE
:
7344 vkind
= DEBUG_LOCAL
;
7346 case DEBUG_PARM_REG
:
7347 case DEBUG_PARM_REF_REG
:
7348 vkind
= DEBUG_REGISTER
;
7352 if (! ieee_push_type (info
, m
->type
, 0, false, false))
7354 info
->type_stack
->type
.referencep
= m
->referencep
;
7357 if (! ieee_variable ((PTR
) info
, m
->name
, vkind
, m
->val
))
7361 /* If there are any reference parameters, we need to output a
7362 miscellaneous record indicating them. */
7365 unsigned int nindx
, varindx
;
7367 /* FIXME: The MRI compiler outputs the demangled function name
7368 here, but we are outputting the mangled name. */
7369 nindx
= info
->name_indx
;
7371 if (! ieee_change_buffer (info
, &info
->vars
)
7372 || ! ieee_write_byte (info
, (int) ieee_nn_record
)
7373 || ! ieee_write_number (info
, nindx
)
7374 || ! ieee_write_id (info
, "")
7375 || ! ieee_write_2bytes (info
, (int) ieee_atn_record_enum
)
7376 || ! ieee_write_number (info
, nindx
)
7377 || ! ieee_write_number (info
, 0)
7378 || ! ieee_write_number (info
, 62)
7379 || ! ieee_write_number (info
, 80)
7380 || ! ieee_write_number (info
, refcount
+ 3)
7381 || ! ieee_write_asn (info
, nindx
, 'B')
7382 || ! ieee_write_atn65 (info
, nindx
, info
->fnname
)
7383 || ! ieee_write_asn (info
, nindx
, 0))
7385 for (m
= info
->pending_parms
, varindx
= 1;
7387 m
= m
->next
, varindx
++)
7391 if (! ieee_write_asn (info
, nindx
, varindx
))
7397 m
= info
->pending_parms
;
7400 struct ieee_pending_parm
*next
;
7407 info
->pending_parms
= NULL
;
7412 /* Start a block. If this is the first block, we output the address
7413 to finish the BB4 or BB6, and then output the function parameters. */
7416 ieee_start_block (p
, addr
)
7420 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
7422 if (! ieee_change_buffer (info
, &info
->vars
))
7425 if (info
->block_depth
== 1)
7427 if (! ieee_write_number (info
, addr
)
7428 || ! ieee_output_pending_parms (info
))
7433 if (! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
7434 || ! ieee_write_byte (info
, 6)
7435 || ! ieee_write_number (info
, 0)
7436 || ! ieee_write_id (info
, "")
7437 || ! ieee_write_number (info
, 0)
7438 || ! ieee_write_number (info
, 0)
7439 || ! ieee_write_number (info
, addr
))
7443 if (! ieee_start_range (info
, addr
))
7446 ++info
->block_depth
;
7454 ieee_end_block (p
, addr
)
7458 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
7460 /* The address we are given is the end of the block, but IEEE seems
7461 to want to the address of the last byte in the block, so we
7463 if (! ieee_change_buffer (info
, &info
->vars
)
7464 || ! ieee_write_byte (info
, (int) ieee_be_record_enum
)
7465 || ! ieee_write_number (info
, addr
- 1))
7468 if (! ieee_end_range (info
, addr
))
7471 --info
->block_depth
;
7473 if (addr
> info
->highaddr
)
7474 info
->highaddr
= addr
;
7479 /* End a function. */
7482 ieee_end_function (p
)
7485 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
7487 assert (info
->block_depth
== 1);
7489 --info
->block_depth
;
7491 /* Now we can finish up fntype, and add it to the typdef section.
7492 At this point, fntype is the 'x' type up to the argument count,
7493 and fnargs is the argument types. We must add the argument
7494 count, and we must add the level. FIXME: We don't record varargs
7495 functions correctly. In fact, stabs debugging does not give us
7496 enough information to do so. */
7497 if (! ieee_change_buffer (info
, &info
->fntype
)
7498 || ! ieee_write_number (info
, info
->fnargcount
)
7499 || ! ieee_change_buffer (info
, &info
->fnargs
)
7500 || ! ieee_write_number (info
, 0))
7503 /* Make sure the typdef block has been started. */
7504 if (ieee_buffer_emptyp (&info
->types
))
7506 if (! ieee_change_buffer (info
, &info
->types
)
7507 || ! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
7508 || ! ieee_write_byte (info
, 1)
7509 || ! ieee_write_number (info
, 0)
7510 || ! ieee_write_id (info
, info
->modname
))
7514 if (! ieee_append_buffer (info
, &info
->types
, &info
->fntype
)
7515 || ! ieee_append_buffer (info
, &info
->types
, &info
->fnargs
))
7518 info
->fnname
= NULL
;
7519 if (! ieee_init_buffer (info
, &info
->fntype
)
7520 || ! ieee_init_buffer (info
, &info
->fnargs
))
7522 info
->fnargcount
= 0;
7527 /* Record line number information. */
7530 ieee_lineno (p
, filename
, lineno
, addr
)
7532 const char *filename
;
7533 unsigned long lineno
;
7536 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
7538 assert (info
->filename
!= NULL
);
7540 /* The HP simulator seems to get confused when more than one line is
7541 listed for the same address, at least if they are in different
7542 files. We handle this by always listing the last line for a
7543 given address, since that seems to be the one that gdb uses. */
7544 if (info
->pending_lineno_filename
!= NULL
7545 && addr
!= info
->pending_lineno_addr
)
7547 /* Make sure we have a line number block. */
7548 if (! ieee_buffer_emptyp (&info
->linenos
))
7550 if (! ieee_change_buffer (info
, &info
->linenos
))
7555 info
->lineno_name_indx
= info
->name_indx
;
7557 if (! ieee_change_buffer (info
, &info
->linenos
)
7558 || ! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
7559 || ! ieee_write_byte (info
, 5)
7560 || ! ieee_write_number (info
, 0)
7561 || ! ieee_write_id (info
, info
->filename
)
7562 || ! ieee_write_byte (info
, (int) ieee_nn_record
)
7563 || ! ieee_write_number (info
, info
->lineno_name_indx
)
7564 || ! ieee_write_id (info
, ""))
7566 info
->lineno_filename
= info
->filename
;
7569 if (strcmp (info
->pending_lineno_filename
, info
->lineno_filename
) != 0)
7571 if (strcmp (info
->filename
, info
->lineno_filename
) != 0)
7573 /* We were not in the main file. Close the block for the
7575 if (! ieee_write_byte (info
, (int) ieee_be_record_enum
))
7577 if (strcmp (info
->filename
, info
->pending_lineno_filename
) == 0)
7579 /* We need a new NN record, and we aren't about to
7581 info
->lineno_name_indx
= info
->name_indx
;
7583 if (! ieee_write_byte (info
, (int) ieee_nn_record
)
7584 || ! ieee_write_number (info
, info
->lineno_name_indx
)
7585 || ! ieee_write_id (info
, ""))
7589 if (strcmp (info
->filename
, info
->pending_lineno_filename
) != 0)
7591 /* We are not changing to the main file. Open a block for
7592 the new included file. */
7593 info
->lineno_name_indx
= info
->name_indx
;
7595 if (! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
7596 || ! ieee_write_byte (info
, 5)
7597 || ! ieee_write_number (info
, 0)
7598 || ! ieee_write_id (info
, info
->pending_lineno_filename
)
7599 || ! ieee_write_byte (info
, (int) ieee_nn_record
)
7600 || ! ieee_write_number (info
, info
->lineno_name_indx
)
7601 || ! ieee_write_id (info
, ""))
7604 info
->lineno_filename
= info
->pending_lineno_filename
;
7607 if (! ieee_write_2bytes (info
, (int) ieee_atn_record_enum
)
7608 || ! ieee_write_number (info
, info
->lineno_name_indx
)
7609 || ! ieee_write_number (info
, 0)
7610 || ! ieee_write_number (info
, 7)
7611 || ! ieee_write_number (info
, info
->pending_lineno
)
7612 || ! ieee_write_number (info
, 0)
7613 || ! ieee_write_asn (info
, info
->lineno_name_indx
,
7614 info
->pending_lineno_addr
))
7618 info
->pending_lineno_filename
= filename
;
7619 info
->pending_lineno
= lineno
;
7620 info
->pending_lineno_addr
= addr
;