1 /* ieee.c -- Read and write IEEE-695 debugging information.
2 Copyright (C) 1996-2015 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 3 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., 51 Franklin Street - Fifth Floor, Boston, MA
22 /* This file reads and writes IEEE-695 debugging information. */
28 #include "libiberty.h"
31 #include "filenames.h"
33 /* This structure holds an entry on the block stack. */
37 /* The kind of block. */
39 /* The source file name, for a BB5 block. */
41 /* The index of the function type, for a BB4 or BB6 block. */
43 /* TRUE if this function is being skipped. */
47 /* This structure is the block stack. */
49 #define BLOCKSTACK_SIZE (16)
51 struct ieee_blockstack
53 /* The stack pointer. */
54 struct ieee_block
*bsp
;
56 struct ieee_block stack
[BLOCKSTACK_SIZE
];
59 /* This structure holds information for a variable. */
79 /* Slot if we make an indirect type. */
81 /* Kind of variable or function. */
82 enum ieee_var_kind kind
;
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 bfd_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 (struct ieee_info
*, const bfd_byte
*, const char *);
253 static void ieee_eof (struct ieee_info
*);
254 static char *savestring (const char *, unsigned long);
255 static bfd_boolean ieee_read_number
256 (struct ieee_info
*, const bfd_byte
**, bfd_vma
*);
257 static bfd_boolean ieee_read_optional_number
258 (struct ieee_info
*, const bfd_byte
**, bfd_vma
*, bfd_boolean
*);
259 static bfd_boolean ieee_read_id
260 (struct ieee_info
*, const bfd_byte
**, const char **, unsigned long *);
261 static bfd_boolean ieee_read_optional_id
262 (struct ieee_info
*, const bfd_byte
**, const char **, unsigned long *,
264 static bfd_boolean ieee_read_expression
265 (struct ieee_info
*, const bfd_byte
**, bfd_vma
*);
266 static debug_type ieee_builtin_type
267 (struct ieee_info
*, const bfd_byte
*, unsigned int);
268 static bfd_boolean ieee_alloc_type
269 (struct ieee_info
*, unsigned int, bfd_boolean
);
270 static bfd_boolean ieee_read_type_index
271 (struct ieee_info
*, const bfd_byte
**, debug_type
*);
272 static int ieee_regno_to_genreg (bfd
*, int);
273 static int ieee_genreg_to_regno (bfd
*, int);
274 static bfd_boolean
parse_ieee_bb (struct ieee_info
*, const bfd_byte
**);
275 static bfd_boolean
parse_ieee_be (struct ieee_info
*, const bfd_byte
**);
276 static bfd_boolean
parse_ieee_nn (struct ieee_info
*, const bfd_byte
**);
277 static bfd_boolean
parse_ieee_ty (struct ieee_info
*, const bfd_byte
**);
278 static bfd_boolean
parse_ieee_atn (struct ieee_info
*, const bfd_byte
**);
279 static bfd_boolean ieee_read_cxx_misc
280 (struct ieee_info
*, const bfd_byte
**, unsigned long);
281 static bfd_boolean ieee_read_cxx_class
282 (struct ieee_info
*, const bfd_byte
**, unsigned long);
283 static bfd_boolean ieee_read_cxx_defaults
284 (struct ieee_info
*, const bfd_byte
**, unsigned long);
285 static bfd_boolean ieee_read_reference
286 (struct ieee_info
*, const bfd_byte
**);
287 static bfd_boolean ieee_require_asn
288 (struct ieee_info
*, const bfd_byte
**, bfd_vma
*);
289 static bfd_boolean ieee_require_atn65
290 (struct ieee_info
*, const bfd_byte
**, const char **, unsigned long *);
292 /* Report an error in the IEEE debugging information. */
295 ieee_error (struct ieee_info
*info
, const bfd_byte
*p
, const char *s
)
298 fprintf (stderr
, "%s: 0x%lx: %s (0x%x)\n", bfd_get_filename (info
->abfd
),
299 (unsigned long) (p
- info
->bytes
), s
, *p
);
301 fprintf (stderr
, "%s: %s\n", bfd_get_filename (info
->abfd
), s
);
304 /* Report an unexpected EOF in the IEEE debugging information. */
307 ieee_eof (struct ieee_info
*info
)
309 ieee_error (info
, (const bfd_byte
*) NULL
,
310 _("unexpected end of debugging information"));
313 /* Save a string in memory. */
316 savestring (const char *start
, unsigned long len
)
320 ret
= (char *) xmalloc (len
+ 1);
321 memcpy (ret
, start
, len
);
326 /* Read a number which must be present in an IEEE file. */
329 ieee_read_number (struct ieee_info
*info
, const bfd_byte
**pp
, bfd_vma
*pv
)
331 return ieee_read_optional_number (info
, pp
, pv
, (bfd_boolean
*) NULL
);
334 /* Read a number in an IEEE file. If ppresent is not NULL, the number
335 need not be there. */
338 ieee_read_optional_number (struct ieee_info
*info
, const bfd_byte
**pp
,
339 bfd_vma
*pv
, bfd_boolean
*ppresent
)
341 ieee_record_enum_type b
;
343 if (*pp
>= info
->pend
)
345 if (ppresent
!= NULL
)
354 b
= (ieee_record_enum_type
) **pp
;
357 if (b
<= ieee_number_end_enum
)
360 if (ppresent
!= NULL
)
365 if (b
>= ieee_number_repeat_start_enum
&& b
<= ieee_number_repeat_end_enum
)
369 i
= (int) b
- (int) ieee_number_repeat_start_enum
;
370 if (*pp
+ i
- 1 >= info
->pend
)
384 if (ppresent
!= NULL
)
390 if (ppresent
!= NULL
)
397 ieee_error (info
, *pp
- 1, _("invalid number"));
401 /* Read a required string from an IEEE file. */
404 ieee_read_id (struct ieee_info
*info
, const bfd_byte
**pp
,
405 const char **pname
, unsigned long *pnamlen
)
407 return ieee_read_optional_id (info
, pp
, pname
, pnamlen
, (bfd_boolean
*) NULL
);
410 /* Read a string from an IEEE file. If ppresent is not NULL, the
411 string is optional. */
414 ieee_read_optional_id (struct ieee_info
*info
, const bfd_byte
**pp
,
415 const char **pname
, unsigned long *pnamlen
,
416 bfd_boolean
*ppresent
)
421 if (*pp
>= info
->pend
)
432 else if ((ieee_record_enum_type
) b
== ieee_extension_length_1_enum
)
437 else if ((ieee_record_enum_type
) b
== ieee_extension_length_2_enum
)
439 len
= (**pp
<< 8) + (*pp
)[1];
444 if (ppresent
!= NULL
)
450 ieee_error (info
, *pp
- 1, _("invalid string length"));
454 if ((unsigned long) (info
->pend
- *pp
) < len
)
460 *pname
= (const char *) *pp
;
464 if (ppresent
!= NULL
)
470 /* Read an expression from an IEEE file. Since this code is only used
471 to parse debugging information, I haven't bothered to write a full
472 blown IEEE expression parser. I've only thrown in the things I've
473 seen in debugging information. This can be easily extended if
477 ieee_read_expression (struct ieee_info
*info
, const bfd_byte
**pp
,
480 const bfd_byte
*expr_start
;
481 #define EXPR_STACK_SIZE (10)
482 bfd_vma expr_stack
[EXPR_STACK_SIZE
];
491 const bfd_byte
*start
;
494 ieee_record_enum_type c
;
498 if (! ieee_read_optional_number (info
, pp
, &val
, &present
))
503 if (esp
- expr_stack
>= EXPR_STACK_SIZE
)
505 ieee_error (info
, start
, _("expression stack overflow"));
512 c
= (ieee_record_enum_type
) **pp
;
514 if (c
>= ieee_module_beginning_enum
)
525 ieee_error (info
, start
, _("unsupported IEEE expression operator"));
528 case ieee_variable_R_enum
:
533 if (! ieee_read_number (info
, pp
, &indx
))
535 for (s
= info
->abfd
->sections
; s
!= NULL
; s
= s
->next
)
536 if ((bfd_vma
) s
->target_index
== indx
)
540 ieee_error (info
, start
, _("unknown section"));
544 if (esp
- expr_stack
>= EXPR_STACK_SIZE
)
546 ieee_error (info
, start
, _("expression stack overflow"));
550 *esp
++ = bfd_get_section_vma (info
->abfd
, s
);
554 case ieee_function_plus_enum
:
555 case ieee_function_minus_enum
:
559 if (esp
- expr_stack
< 2)
561 ieee_error (info
, start
, _("expression stack underflow"));
573 if (esp
- 1 != expr_stack
)
575 ieee_error (info
, expr_start
, _("expression stack mismatch"));
584 /* Return an IEEE builtin type. */
587 ieee_builtin_type (struct ieee_info
*info
, const bfd_byte
*p
,
594 if (indx
< BUILTIN_TYPE_COUNT
595 && info
->types
.builtins
[indx
] != DEBUG_TYPE_NULL
)
596 return info
->types
.builtins
[indx
];
598 dhandle
= info
->dhandle
;
600 if (indx
>= 32 && indx
< 64)
602 type
= debug_make_pointer_type (dhandle
,
603 ieee_builtin_type (info
, p
, indx
- 32));
604 assert (indx
< BUILTIN_TYPE_COUNT
);
605 info
->types
.builtins
[indx
] = type
;
609 switch ((enum builtin_types
) indx
)
612 ieee_error (info
, p
, _("unknown builtin type"));
615 case builtin_unknown
:
616 type
= debug_make_void_type (dhandle
);
621 type
= debug_make_void_type (dhandle
);
625 case builtin_signed_char
:
626 type
= debug_make_int_type (dhandle
, 1, FALSE
);
627 name
= "signed char";
630 case builtin_unsigned_char
:
631 type
= debug_make_int_type (dhandle
, 1, TRUE
);
632 name
= "unsigned char";
635 case builtin_signed_short_int
:
636 type
= debug_make_int_type (dhandle
, 2, FALSE
);
637 name
= "signed short int";
640 case builtin_unsigned_short_int
:
641 type
= debug_make_int_type (dhandle
, 2, TRUE
);
642 name
= "unsigned short int";
645 case builtin_signed_long
:
646 type
= debug_make_int_type (dhandle
, 4, FALSE
);
647 name
= "signed long";
650 case builtin_unsigned_long
:
651 type
= debug_make_int_type (dhandle
, 4, TRUE
);
652 name
= "unsigned long";
655 case builtin_signed_long_long
:
656 type
= debug_make_int_type (dhandle
, 8, FALSE
);
657 name
= "signed long long";
660 case builtin_unsigned_long_long
:
661 type
= debug_make_int_type (dhandle
, 8, TRUE
);
662 name
= "unsigned long long";
666 type
= debug_make_float_type (dhandle
, 4);
671 type
= debug_make_float_type (dhandle
, 8);
675 case builtin_long_double
:
676 /* FIXME: The size for this type should depend upon the
678 type
= debug_make_float_type (dhandle
, 12);
679 name
= "long double";
682 case builtin_long_long_double
:
683 type
= debug_make_float_type (dhandle
, 16);
684 name
= "long long double";
687 case builtin_quoted_string
:
688 type
= debug_make_array_type (dhandle
,
689 ieee_builtin_type (info
, p
,
692 ieee_builtin_type (info
, p
,
696 name
= "QUOTED STRING";
699 case builtin_instruction_address
:
700 /* FIXME: This should be a code address. */
701 type
= debug_make_int_type (dhandle
, 4, TRUE
);
702 name
= "instruction address";
706 /* FIXME: The size for this type should depend upon the
708 type
= debug_make_int_type (dhandle
, 4, FALSE
);
712 case builtin_unsigned
:
713 /* FIXME: The size for this type should depend upon the
715 type
= debug_make_int_type (dhandle
, 4, TRUE
);
719 case builtin_unsigned_int
:
720 /* FIXME: The size for this type should depend upon the
722 type
= debug_make_int_type (dhandle
, 4, TRUE
);
723 name
= "unsigned int";
727 type
= debug_make_int_type (dhandle
, 1, FALSE
);
732 type
= debug_make_int_type (dhandle
, 4, FALSE
);
737 type
= debug_make_int_type (dhandle
, 2, FALSE
);
741 case builtin_unsigned_short
:
742 type
= debug_make_int_type (dhandle
, 2, TRUE
);
743 name
= "unsigned short";
746 case builtin_short_int
:
747 type
= debug_make_int_type (dhandle
, 2, FALSE
);
751 case builtin_signed_short
:
752 type
= debug_make_int_type (dhandle
, 2, FALSE
);
753 name
= "signed short";
756 case builtin_bcd_float
:
757 ieee_error (info
, p
, _("BCD float type not supported"));
758 return DEBUG_TYPE_NULL
;
762 type
= debug_name_type (dhandle
, name
, type
);
764 assert (indx
< BUILTIN_TYPE_COUNT
);
766 info
->types
.builtins
[indx
] = type
;
771 /* Allocate more space in the type table. If ref is TRUE, this is a
772 reference to the type; if it is not already defined, we should set
773 up an indirect type. */
776 ieee_alloc_type (struct ieee_info
*info
, unsigned int indx
, bfd_boolean ref
)
779 register struct ieee_type
*t
;
780 struct ieee_type
*tend
;
782 if (indx
>= info
->types
.alloc
)
784 nalloc
= info
->types
.alloc
;
787 while (indx
>= nalloc
)
790 info
->types
.types
= ((struct ieee_type
*)
791 xrealloc (info
->types
.types
,
792 nalloc
* sizeof *info
->types
.types
));
794 memset (info
->types
.types
+ info
->types
.alloc
, 0,
795 (nalloc
- info
->types
.alloc
) * sizeof *info
->types
.types
);
797 tend
= info
->types
.types
+ nalloc
;
798 for (t
= info
->types
.types
+ info
->types
.alloc
; t
< tend
; t
++)
799 t
->type
= DEBUG_TYPE_NULL
;
801 info
->types
.alloc
= nalloc
;
806 t
= info
->types
.types
+ indx
;
809 t
->pslot
= (debug_type
*) xmalloc (sizeof *t
->pslot
);
810 *t
->pslot
= DEBUG_TYPE_NULL
;
811 t
->type
= debug_make_indirect_type (info
->dhandle
, t
->pslot
,
812 (const char *) NULL
);
821 /* Read a type index and return the corresponding type. */
824 ieee_read_type_index (struct ieee_info
*info
, const bfd_byte
**pp
,
827 const bfd_byte
*start
;
832 if (! ieee_read_number (info
, pp
, &indx
))
837 *ptype
= ieee_builtin_type (info
, start
, indx
);
844 if (! ieee_alloc_type (info
, indx
, TRUE
))
847 *ptype
= info
->types
.types
[indx
].type
;
852 /* Parse IEEE debugging information for a file. This is passed the
853 bytes which compose the Debug Information Part of an IEEE file. */
856 parse_ieee (void *dhandle
, bfd
*abfd
, const bfd_byte
*bytes
, bfd_size_type len
)
858 struct ieee_info info
;
860 const bfd_byte
*p
, *pend
;
862 info
.dhandle
= dhandle
;
865 info
.pend
= bytes
+ len
;
866 info
.blockstack
.bsp
= info
.blockstack
.stack
;
867 info
.saw_filename
= FALSE
;
869 info
.vars
.vars
= NULL
;
870 info
.global_vars
= NULL
;
871 info
.types
.alloc
= 0;
872 info
.types
.types
= NULL
;
873 info
.global_types
= NULL
;
875 for (i
= 0; i
< BUILTIN_TYPE_COUNT
; i
++)
876 info
.types
.builtins
[i
] = DEBUG_TYPE_NULL
;
882 const bfd_byte
*record_start
;
883 ieee_record_enum_type c
;
887 c
= (ieee_record_enum_type
) *p
++;
889 if (c
== ieee_at_record_enum
)
890 c
= (ieee_record_enum_type
) (((unsigned int) c
<< 8) | *p
++);
892 if (c
<= ieee_number_repeat_end_enum
)
894 ieee_error (&info
, record_start
, _("unexpected number"));
901 ieee_error (&info
, record_start
, _("unexpected record type"));
904 case ieee_bb_record_enum
:
905 if (! parse_ieee_bb (&info
, &p
))
909 case ieee_be_record_enum
:
910 if (! parse_ieee_be (&info
, &p
))
915 if (! parse_ieee_nn (&info
, &p
))
919 case ieee_ty_record_enum
:
920 if (! parse_ieee_ty (&info
, &p
))
924 case ieee_atn_record_enum
:
925 if (! parse_ieee_atn (&info
, &p
))
931 if (info
.blockstack
.bsp
!= info
.blockstack
.stack
)
933 ieee_error (&info
, (const bfd_byte
*) NULL
,
934 _("blocks left on stack at end"));
941 /* Handle an IEEE BB record. */
944 parse_ieee_bb (struct ieee_info
*info
, const bfd_byte
**pp
)
946 const bfd_byte
*block_start
;
950 unsigned long namlen
;
951 char *namcopy
= NULL
;
960 if (! ieee_read_number (info
, pp
, &size
)
961 || ! ieee_read_id (info
, pp
, &name
, &namlen
))
964 fnindx
= (unsigned int) -1;
970 /* BB1: Type definitions local to a module. */
971 namcopy
= savestring (name
, namlen
);
974 if (! debug_set_filename (info
->dhandle
, namcopy
))
976 info
->saw_filename
= TRUE
;
978 /* Discard any variables or types we may have seen before. */
979 if (info
->vars
.vars
!= NULL
)
980 free (info
->vars
.vars
);
981 info
->vars
.vars
= NULL
;
982 info
->vars
.alloc
= 0;
983 if (info
->types
.types
!= NULL
)
984 free (info
->types
.types
);
985 info
->types
.types
= NULL
;
986 info
->types
.alloc
= 0;
988 /* Initialize the types to the global types. */
989 if (info
->global_types
!= NULL
)
991 info
->types
.alloc
= info
->global_types
->alloc
;
992 info
->types
.types
= ((struct ieee_type
*)
993 xmalloc (info
->types
.alloc
994 * sizeof (*info
->types
.types
)));
995 memcpy (info
->types
.types
, info
->global_types
->types
,
996 info
->types
.alloc
* sizeof (*info
->types
.types
));
1002 /* BB2: Global type definitions. The name is supposed to be
1003 empty, but we don't check. */
1004 if (! debug_set_filename (info
->dhandle
, "*global*"))
1006 info
->saw_filename
= TRUE
;
1010 /* BB3: High level module block begin. We don't have to do
1011 anything here. The name is supposed to be the same as for
1012 the BB1, but we don't check. */
1016 /* BB4: Global function. */
1018 bfd_vma stackspace
, typindx
, offset
;
1019 debug_type return_type
;
1021 if (! ieee_read_number (info
, pp
, &stackspace
)
1022 || ! ieee_read_number (info
, pp
, &typindx
)
1023 || ! ieee_read_expression (info
, pp
, &offset
))
1026 /* We have no way to record the stack space. FIXME. */
1030 return_type
= ieee_builtin_type (info
, block_start
, typindx
);
1031 if (return_type
== DEBUG_TYPE_NULL
)
1037 if (! ieee_alloc_type (info
, typindx
, TRUE
))
1040 return_type
= info
->types
.types
[typindx
].type
;
1041 if (debug_get_type_kind (info
->dhandle
, return_type
)
1042 == DEBUG_KIND_FUNCTION
)
1043 return_type
= debug_get_return_type (info
->dhandle
,
1047 namcopy
= savestring (name
, namlen
);
1048 if (namcopy
== NULL
)
1050 if (! debug_record_function (info
->dhandle
, namcopy
, return_type
,
1057 /* BB5: File name for source line numbers. */
1061 /* We ignore the date and time. FIXME. */
1062 for (i
= 0; i
< 6; i
++)
1065 bfd_boolean present
;
1067 if (! ieee_read_optional_number (info
, pp
, &ignore
, &present
))
1073 if (! info
->saw_filename
)
1075 namcopy
= savestring (name
, namlen
);
1076 if (namcopy
== NULL
)
1078 if (! debug_set_filename (info
->dhandle
, namcopy
))
1080 info
->saw_filename
= TRUE
;
1083 namcopy
= savestring (name
, namlen
);
1084 if (namcopy
== NULL
)
1086 if (! debug_start_source (info
->dhandle
, namcopy
))
1092 /* BB6: Local function or block. */
1094 bfd_vma stackspace
, typindx
, offset
;
1096 if (! ieee_read_number (info
, pp
, &stackspace
)
1097 || ! ieee_read_number (info
, pp
, &typindx
)
1098 || ! ieee_read_expression (info
, pp
, &offset
))
1101 /* We have no way to record the stack space. FIXME. */
1105 if (! debug_start_block (info
->dhandle
, offset
))
1107 /* Change b to indicate that this is a block
1108 rather than a function. */
1113 /* The MRI C++ compiler will output a fake function named
1114 __XRYCPP to hold C++ debugging information. We skip
1115 that function. This is not crucial, but it makes
1116 converting from IEEE to other debug formats work
1118 if (strncmp (name
, "__XRYCPP", namlen
) == 0)
1122 debug_type return_type
;
1126 return_type
= ieee_builtin_type (info
, block_start
,
1128 if (return_type
== NULL
)
1134 if (! ieee_alloc_type (info
, typindx
, TRUE
))
1137 return_type
= info
->types
.types
[typindx
].type
;
1138 if (debug_get_type_kind (info
->dhandle
, return_type
)
1139 == DEBUG_KIND_FUNCTION
)
1140 return_type
= debug_get_return_type (info
->dhandle
,
1144 namcopy
= savestring (name
, namlen
);
1145 if (namcopy
== NULL
)
1147 if (! debug_record_function (info
->dhandle
, namcopy
,
1148 return_type
, FALSE
, offset
))
1156 /* BB10: Assembler module scope. In the normal case, we
1157 completely ignore all this information. FIXME. */
1159 const char *inam
, *vstr
;
1160 unsigned long inamlen
, vstrlen
;
1162 bfd_boolean present
;
1165 if (! info
->saw_filename
)
1167 namcopy
= savestring (name
, namlen
);
1168 if (namcopy
== NULL
)
1170 if (! debug_set_filename (info
->dhandle
, namcopy
))
1172 info
->saw_filename
= TRUE
;
1175 if (! ieee_read_id (info
, pp
, &inam
, &inamlen
)
1176 || ! ieee_read_number (info
, pp
, &tool_type
)
1177 || ! ieee_read_optional_id (info
, pp
, &vstr
, &vstrlen
, &present
))
1179 for (i
= 0; i
< 6; i
++)
1183 if (! ieee_read_optional_number (info
, pp
, &ignore
, &present
))
1192 /* BB11: Module section. We completely ignore all this
1193 information. FIXME. */
1195 bfd_vma sectype
, secindx
, offset
, map
;
1196 bfd_boolean present
;
1198 if (! ieee_read_number (info
, pp
, §ype
)
1199 || ! ieee_read_number (info
, pp
, &secindx
)
1200 || ! ieee_read_expression (info
, pp
, &offset
)
1201 || ! ieee_read_optional_number (info
, pp
, &map
, &present
))
1207 ieee_error (info
, block_start
, _("unknown BB type"));
1212 /* Push this block on the block stack. */
1214 if (info
->blockstack
.bsp
>= info
->blockstack
.stack
+ BLOCKSTACK_SIZE
)
1216 ieee_error (info
, (const bfd_byte
*) NULL
, _("stack overflow"));
1220 info
->blockstack
.bsp
->kind
= b
;
1222 info
->blockstack
.bsp
->filename
= namcopy
;
1223 info
->blockstack
.bsp
->fnindx
= fnindx
;
1224 info
->blockstack
.bsp
->skip
= skip
;
1225 ++info
->blockstack
.bsp
;
1230 /* Handle an IEEE BE record. */
1233 parse_ieee_be (struct ieee_info
*info
, const bfd_byte
**pp
)
1237 if (info
->blockstack
.bsp
<= info
->blockstack
.stack
)
1239 ieee_error (info
, *pp
, _("stack underflow"));
1242 --info
->blockstack
.bsp
;
1244 switch (info
->blockstack
.bsp
->kind
)
1247 /* When we end the global typedefs block, we copy out the
1248 contents of info->vars. This is because the variable indices
1249 may be reused in the local blocks. However, we need to
1250 preserve them so that we can locate a function returning a
1251 reference variable whose type is named in the global typedef
1253 info
->global_vars
= ((struct ieee_vars
*)
1254 xmalloc (sizeof *info
->global_vars
));
1255 info
->global_vars
->alloc
= info
->vars
.alloc
;
1256 info
->global_vars
->vars
= ((struct ieee_var
*)
1257 xmalloc (info
->vars
.alloc
1258 * sizeof (*info
->vars
.vars
)));
1259 memcpy (info
->global_vars
->vars
, info
->vars
.vars
,
1260 info
->vars
.alloc
* sizeof (*info
->vars
.vars
));
1262 /* We also copy out the non builtin parts of info->types, since
1263 the types are discarded when we start a new block. */
1264 info
->global_types
= ((struct ieee_types
*)
1265 xmalloc (sizeof *info
->global_types
));
1266 info
->global_types
->alloc
= info
->types
.alloc
;
1267 info
->global_types
->types
= ((struct ieee_type
*)
1268 xmalloc (info
->types
.alloc
1269 * sizeof (*info
->types
.types
)));
1270 memcpy (info
->global_types
->types
, info
->types
.types
,
1271 info
->types
.alloc
* sizeof (*info
->types
.types
));
1272 memset (info
->global_types
->builtins
, 0,
1273 sizeof (info
->global_types
->builtins
));
1279 if (! ieee_read_expression (info
, pp
, &offset
))
1281 if (! info
->blockstack
.bsp
->skip
)
1283 if (! debug_end_function (info
->dhandle
, offset
+ 1))
1289 /* This is BE6 when BB6 started a block rather than a local
1291 if (! ieee_read_expression (info
, pp
, &offset
))
1293 if (! debug_end_block (info
->dhandle
, offset
+ 1))
1298 /* When we end a BB5, we look up the stack for the last BB5, if
1299 there is one, so that we can call debug_start_source. */
1300 if (info
->blockstack
.bsp
> info
->blockstack
.stack
)
1302 struct ieee_block
*bl
;
1304 bl
= info
->blockstack
.bsp
;
1310 if (! debug_start_source (info
->dhandle
, bl
->filename
))
1315 while (bl
!= info
->blockstack
.stack
);
1320 if (! ieee_read_expression (info
, pp
, &offset
))
1322 /* We just ignore the module size. FIXME. */
1326 /* Other block types do not have any trailing information. */
1333 /* Parse an NN record. */
1336 parse_ieee_nn (struct ieee_info
*info
, const bfd_byte
**pp
)
1338 const bfd_byte
*nn_start
;
1341 unsigned long namlen
;
1345 if (! ieee_read_number (info
, pp
, &varindx
)
1346 || ! ieee_read_id (info
, pp
, &name
, &namlen
))
1351 ieee_error (info
, nn_start
, _("illegal variable index"));
1356 if (varindx
>= info
->vars
.alloc
)
1360 alloc
= info
->vars
.alloc
;
1363 while (varindx
>= alloc
)
1365 info
->vars
.vars
= ((struct ieee_var
*)
1366 xrealloc (info
->vars
.vars
,
1367 alloc
* sizeof *info
->vars
.vars
));
1368 memset (info
->vars
.vars
+ info
->vars
.alloc
, 0,
1369 (alloc
- info
->vars
.alloc
) * sizeof *info
->vars
.vars
);
1370 info
->vars
.alloc
= alloc
;
1373 info
->vars
.vars
[varindx
].name
= name
;
1374 info
->vars
.vars
[varindx
].namlen
= namlen
;
1379 /* Parse a TY record. */
1382 parse_ieee_ty (struct ieee_info
*info
, const bfd_byte
**pp
)
1384 const bfd_byte
*ty_start
, *ty_var_start
, *ty_code_start
;
1385 bfd_vma typeindx
, varindx
, tc
;
1387 bfd_boolean tag
, typdef
;
1388 debug_type
*arg_slots
;
1389 unsigned long type_bitsize
;
1394 if (! ieee_read_number (info
, pp
, &typeindx
))
1399 ieee_error (info
, ty_start
, _("illegal type index"));
1404 if (! ieee_alloc_type (info
, typeindx
, FALSE
))
1409 ieee_error (info
, *pp
, _("unknown TY code"));
1416 if (! ieee_read_number (info
, pp
, &varindx
))
1421 ieee_error (info
, ty_var_start
, _("illegal variable index"));
1426 if (varindx
>= info
->vars
.alloc
|| info
->vars
.vars
[varindx
].name
== NULL
)
1428 ieee_error (info
, ty_var_start
, _("undefined variable in TY"));
1432 ty_code_start
= *pp
;
1434 if (! ieee_read_number (info
, pp
, &tc
))
1437 dhandle
= info
->dhandle
;
1446 ieee_error (info
, ty_code_start
, _("unknown TY code"));
1450 /* Unknown type, with size. We treat it as int. FIXME. */
1454 if (! ieee_read_number (info
, pp
, &size
))
1456 type
= debug_make_int_type (dhandle
, size
, FALSE
);
1460 case 'A': /* Array. */
1461 case 'a': /* FORTRAN array in column/row order. FIXME: Not
1462 distinguished from normal array. */
1464 debug_type ele_type
;
1465 bfd_vma lower
, upper
;
1467 if (! ieee_read_type_index (info
, pp
, &ele_type
)
1468 || ! ieee_read_number (info
, pp
, &lower
)
1469 || ! ieee_read_number (info
, pp
, &upper
))
1471 type
= debug_make_array_type (dhandle
, ele_type
,
1472 ieee_builtin_type (info
, ty_code_start
,
1475 (bfd_signed_vma
) lower
,
1476 (bfd_signed_vma
) upper
,
1482 /* Simple enumeration. */
1488 bfd_signed_vma
*vals
;
1491 if (! ieee_read_number (info
, pp
, &size
))
1493 /* FIXME: we ignore the enumeration size. */
1496 names
= (const char **) xmalloc (alloc
* sizeof *names
);
1497 memset (names
, 0, alloc
* sizeof *names
);
1502 unsigned long namlen
;
1503 bfd_boolean present
;
1505 if (! ieee_read_optional_id (info
, pp
, &name
, &namlen
, &present
))
1513 names
= ((const char **)
1514 xrealloc (names
, alloc
* sizeof *names
));
1517 names
[c
] = savestring (name
, namlen
);
1518 if (names
[c
] == NULL
)
1525 vals
= (bfd_signed_vma
*) xmalloc (c
* sizeof *vals
);
1526 for (i
= 0; i
< c
; i
++)
1529 type
= debug_make_enum_type (dhandle
, names
, vals
);
1535 /* Struct with bit fields. */
1539 debug_field
*fields
;
1542 if (! ieee_read_number (info
, pp
, &size
))
1546 fields
= (debug_field
*) xmalloc (alloc
* sizeof *fields
);
1551 unsigned long namlen
;
1552 bfd_boolean present
;
1554 bfd_vma bitpos
, bitsize
;
1556 if (! ieee_read_optional_id (info
, pp
, &name
, &namlen
, &present
))
1560 if (! ieee_read_type_index (info
, pp
, &ftype
)
1561 || ! ieee_read_number (info
, pp
, &bitpos
)
1562 || ! ieee_read_number (info
, pp
, &bitsize
))
1568 fields
= ((debug_field
*)
1569 xrealloc (fields
, alloc
* sizeof *fields
));
1572 fields
[c
] = debug_make_field (dhandle
, savestring (name
, namlen
),
1573 ftype
, bitpos
, bitsize
,
1574 DEBUG_VISIBILITY_PUBLIC
);
1575 if (fields
[c
] == NULL
)
1582 type
= debug_make_struct_type (dhandle
, TRUE
, size
, fields
);
1592 bfd_signed_vma
*vals
;
1596 names
= (const char **) xmalloc (alloc
* sizeof *names
);
1597 vals
= (bfd_signed_vma
*) xmalloc (alloc
* sizeof *names
);
1602 unsigned long namlen
;
1603 bfd_boolean present
;
1606 if (! ieee_read_optional_id (info
, pp
, &name
, &namlen
, &present
))
1610 if (! ieee_read_number (info
, pp
, &val
))
1613 /* If the length of the name is zero, then the value is
1614 actually the size of the enum. We ignore this
1615 information. FIXME. */
1622 names
= ((const char **)
1623 xrealloc (names
, alloc
* sizeof *names
));
1624 vals
= ((bfd_signed_vma
*)
1625 xrealloc (vals
, alloc
* sizeof *vals
));
1628 names
[c
] = savestring (name
, namlen
);
1629 if (names
[c
] == NULL
)
1631 vals
[c
] = (bfd_signed_vma
) val
;
1637 type
= debug_make_enum_type (dhandle
, names
, vals
);
1642 case 'O': /* Small pointer. We don't distinguish small and large
1644 case 'P': /* Large pointer. */
1648 if (! ieee_read_type_index (info
, pp
, &t
))
1650 type
= debug_make_pointer_type (dhandle
, t
);
1657 bfd_vma low
, high
, signedp
, size
;
1659 if (! ieee_read_number (info
, pp
, &low
)
1660 || ! ieee_read_number (info
, pp
, &high
)
1661 || ! ieee_read_number (info
, pp
, &signedp
)
1662 || ! ieee_read_number (info
, pp
, &size
))
1665 type
= debug_make_range_type (dhandle
,
1666 debug_make_int_type (dhandle
, size
,
1668 (bfd_signed_vma
) low
,
1669 (bfd_signed_vma
) high
);
1673 case 'S': /* Struct. */
1674 case 'U': /* Union. */
1678 debug_field
*fields
;
1681 if (! ieee_read_number (info
, pp
, &size
))
1685 fields
= (debug_field
*) xmalloc (alloc
* sizeof *fields
);
1690 unsigned long namlen
;
1691 bfd_boolean present
;
1697 if (! ieee_read_optional_id (info
, pp
, &name
, &namlen
, &present
))
1701 if (! ieee_read_number (info
, pp
, &tindx
)
1702 || ! ieee_read_number (info
, pp
, &offset
))
1707 ftype
= ieee_builtin_type (info
, ty_code_start
, tindx
);
1713 struct ieee_type
*t
;
1716 if (! ieee_alloc_type (info
, tindx
, TRUE
))
1718 t
= info
->types
.types
+ tindx
;
1720 bitsize
= t
->bitsize
;
1728 fields
= ((debug_field
*)
1729 xrealloc (fields
, alloc
* sizeof *fields
));
1732 fields
[c
] = debug_make_field (dhandle
, savestring (name
, namlen
),
1733 ftype
, offset
, bitsize
,
1734 DEBUG_VISIBILITY_PUBLIC
);
1735 if (fields
[c
] == NULL
)
1742 type
= debug_make_struct_type (dhandle
, tc
== 'S', size
, fields
);
1749 if (! ieee_read_type_index (info
, pp
, &type
))
1755 /* Procedure. FIXME: This is an extern declaration, which we
1756 have no way of representing. */
1761 bfd_boolean present
;
1762 struct ieee_var
*pv
;
1764 /* FIXME: We ignore the attribute and the argument names. */
1766 if (! ieee_read_number (info
, pp
, &attr
)
1767 || ! ieee_read_type_index (info
, pp
, &rtype
)
1768 || ! ieee_read_number (info
, pp
, &nargs
))
1773 unsigned long namlen
;
1775 if (! ieee_read_optional_id (info
, pp
, &name
, &namlen
, &present
))
1780 pv
= info
->vars
.vars
+ varindx
;
1781 pv
->kind
= IEEE_EXTERNAL
;
1783 && debug_get_type_kind (dhandle
, rtype
) == DEBUG_KIND_POINTER
)
1785 /* Set up the return type as an indirect type pointing to
1786 the variable slot, so that we can change it to a
1787 reference later if appropriate. */
1788 pv
->pslot
= (debug_type
*) xmalloc (sizeof *pv
->pslot
);
1790 rtype
= debug_make_indirect_type (dhandle
, pv
->pslot
,
1791 (const char *) NULL
);
1794 type
= debug_make_function_type (dhandle
, rtype
, (debug_type
*) NULL
,
1801 /* Void. This is not documented, but the MRI compiler emits it. */
1802 type
= debug_make_void_type (dhandle
);
1806 /* Array with 0 lower bound. */
1811 if (! ieee_read_type_index (info
, pp
, &etype
)
1812 || ! ieee_read_number (info
, pp
, &high
))
1815 type
= debug_make_array_type (dhandle
, etype
,
1816 ieee_builtin_type (info
, ty_code_start
,
1819 0, (bfd_signed_vma
) high
, FALSE
);
1823 case 'c': /* Complex. */
1824 case 'd': /* Double complex. */
1827 unsigned long namlen
;
1829 /* FIXME: I don't know what the name means. */
1831 if (! ieee_read_id (info
, pp
, &name
, &namlen
))
1834 type
= debug_make_complex_type (dhandle
, tc
== 'c' ? 4 : 8);
1839 /* Pascal file name. FIXME. */
1840 ieee_error (info
, ty_code_start
, _("Pascal file name not supported"));
1844 /* Bitfield type. */
1846 bfd_vma signedp
, bitsize
, dummy
;
1847 const bfd_byte
*hold
;
1848 bfd_boolean present
;
1850 if (! ieee_read_number (info
, pp
, &signedp
)
1851 || ! ieee_read_number (info
, pp
, &bitsize
))
1854 /* I think the documentation says that there is a type index,
1855 but some actual files do not have one. */
1857 if (! ieee_read_optional_number (info
, pp
, &dummy
, &present
))
1861 /* FIXME: This is just a guess. */
1862 type
= debug_make_int_type (dhandle
, 4,
1863 signedp
? FALSE
: TRUE
);
1868 if (! ieee_read_type_index (info
, pp
, &type
))
1871 type_bitsize
= bitsize
;
1881 if (! ieee_read_number (info
, pp
, &kind
)
1882 || ! ieee_read_type_index (info
, pp
, &t
))
1888 ieee_error (info
, ty_start
, _("unsupported qualifier"));
1892 type
= debug_make_const_type (dhandle
, t
);
1896 type
= debug_make_volatile_type (dhandle
, t
);
1908 if (! ieee_read_number (info
, pp
, &size
)
1909 || ! ieee_read_type_index (info
, pp
, &etype
))
1912 /* FIXME: We ignore the size. */
1914 type
= debug_make_set_type (dhandle
, etype
, FALSE
);
1919 /* Procedure with compiler dependencies. */
1921 struct ieee_var
*pv
;
1922 bfd_vma attr
, frame_type
, push_mask
, nargs
, level
, father
;
1924 debug_type
*arg_types
;
1925 bfd_boolean varargs
;
1926 bfd_boolean present
;
1928 /* FIXME: We ignore some of this information. */
1930 pv
= info
->vars
.vars
+ varindx
;
1932 if (! ieee_read_number (info
, pp
, &attr
)
1933 || ! ieee_read_number (info
, pp
, &frame_type
)
1934 || ! ieee_read_number (info
, pp
, &push_mask
)
1935 || ! ieee_read_type_index (info
, pp
, &rtype
)
1936 || ! ieee_read_number (info
, pp
, &nargs
))
1938 if (nargs
== (bfd_vma
) -1)
1947 arg_types
= ((debug_type
*)
1948 xmalloc ((nargs
+ 1) * sizeof *arg_types
));
1949 for (i
= 0; i
< nargs
; i
++)
1950 if (! ieee_read_type_index (info
, pp
, arg_types
+ i
))
1953 /* If the last type is pointer to void, this is really a
1954 varargs function. */
1960 last
= arg_types
[nargs
- 1];
1961 if (debug_get_type_kind (dhandle
, last
) == DEBUG_KIND_POINTER
1962 && (debug_get_type_kind (dhandle
,
1963 debug_get_target_type (dhandle
,
1965 == DEBUG_KIND_VOID
))
1972 /* If there are any pointer arguments, turn them into
1973 indirect types in case we later need to convert them to
1975 for (i
= 0; i
< nargs
; i
++)
1977 if (debug_get_type_kind (dhandle
, arg_types
[i
])
1978 == DEBUG_KIND_POINTER
)
1980 if (arg_slots
== NULL
)
1982 arg_slots
= ((debug_type
*)
1983 xmalloc (nargs
* sizeof *arg_slots
));
1984 memset (arg_slots
, 0, nargs
* sizeof *arg_slots
);
1986 arg_slots
[i
] = arg_types
[i
];
1988 debug_make_indirect_type (dhandle
,
1990 (const char *) NULL
);
1994 arg_types
[nargs
] = DEBUG_TYPE_NULL
;
1996 if (! ieee_read_number (info
, pp
, &level
)
1997 || ! ieee_read_optional_number (info
, pp
, &father
, &present
))
2000 /* We can't distinguish between a global function and a static
2002 pv
->kind
= IEEE_FUNCTION
;
2005 && debug_get_type_kind (dhandle
, rtype
) == DEBUG_KIND_POINTER
)
2007 /* Set up the return type as an indirect type pointing to
2008 the variable slot, so that we can change it to a
2009 reference later if appropriate. */
2010 pv
->pslot
= (debug_type
*) xmalloc (sizeof *pv
->pslot
);
2012 rtype
= debug_make_indirect_type (dhandle
, pv
->pslot
,
2013 (const char *) NULL
);
2016 type
= debug_make_function_type (dhandle
, rtype
, arg_types
, varargs
);
2021 /* Record the type in the table. */
2023 if (type
== DEBUG_TYPE_NULL
)
2026 info
->vars
.vars
[varindx
].type
= type
;
2029 && info
->vars
.vars
[varindx
].namlen
> 0)
2033 name
= savestring (info
->vars
.vars
[varindx
].name
,
2034 info
->vars
.vars
[varindx
].namlen
);
2036 type
= debug_name_type (dhandle
, name
, type
);
2037 else if (tc
== 'E' || tc
== 'N')
2038 type
= debug_tag_type (dhandle
, name
, type
);
2041 struct ieee_tag
*it
;
2043 /* We must allocate all struct tags as indirect types, so
2044 that if we later see a definition of the tag as a C++
2045 record we can update the indirect slot and automatically
2046 change all the existing references. */
2047 it
= (struct ieee_tag
*) xmalloc (sizeof *it
);
2048 memset (it
, 0, sizeof *it
);
2049 it
->next
= info
->tags
;
2054 type
= debug_make_indirect_type (dhandle
, &it
->slot
, name
);
2055 type
= debug_tag_type (dhandle
, name
, type
);
2063 info
->types
.types
[typeindx
].type
= type
;
2064 info
->types
.types
[typeindx
].arg_slots
= arg_slots
;
2065 info
->types
.types
[typeindx
].bitsize
= type_bitsize
;
2067 /* We may have already allocated type as an indirect type pointing
2068 to slot. It does no harm to replace the indirect type with the
2069 real type. Filling in slot as well handles the indirect types
2070 which are already hanging around. */
2071 if (info
->types
.types
[typeindx
].pslot
!= NULL
)
2072 *info
->types
.types
[typeindx
].pslot
= type
;
2077 /* Parse an ATN record. */
2080 parse_ieee_atn (struct ieee_info
*info
, const bfd_byte
**pp
)
2082 const bfd_byte
*atn_start
, *atn_code_start
;
2084 struct ieee_var
*pvar
;
2088 bfd_vma v
, v2
, v3
, v4
, v5
;
2090 unsigned long namlen
;
2092 bfd_boolean present
;
2097 if (! ieee_read_number (info
, pp
, &varindx
)
2098 || ! ieee_read_type_index (info
, pp
, &type
))
2101 atn_code_start
= *pp
;
2103 if (! ieee_read_number (info
, pp
, &atn_code
))
2112 else if (varindx
< 32)
2114 /* The MRI compiler reportedly sometimes emits variable lifetime
2115 information for a register. We just ignore it. */
2117 return ieee_read_number (info
, pp
, &v
);
2119 ieee_error (info
, atn_start
, _("illegal variable index"));
2125 if (varindx
>= info
->vars
.alloc
2126 || info
->vars
.vars
[varindx
].name
== NULL
)
2128 /* The MRI compiler or linker sometimes omits the NN record
2129 for a pmisc record. */
2132 if (varindx
>= info
->vars
.alloc
)
2136 alloc
= info
->vars
.alloc
;
2139 while (varindx
>= alloc
)
2141 info
->vars
.vars
= ((struct ieee_var
*)
2142 xrealloc (info
->vars
.vars
,
2144 * sizeof *info
->vars
.vars
)));
2145 memset (info
->vars
.vars
+ info
->vars
.alloc
, 0,
2146 ((alloc
- info
->vars
.alloc
)
2147 * sizeof *info
->vars
.vars
));
2148 info
->vars
.alloc
= alloc
;
2151 pvar
= info
->vars
.vars
+ varindx
;
2157 ieee_error (info
, atn_start
, _("undefined variable in ATN"));
2162 pvar
= info
->vars
.vars
+ varindx
;
2167 namlen
= pvar
->namlen
;
2170 dhandle
= info
->dhandle
;
2172 /* If we are going to call debug_record_variable with a pointer
2173 type, change the type to an indirect type so that we can later
2174 change it to a reference type if we encounter a C++ pmisc 'R'
2177 && type
!= DEBUG_TYPE_NULL
2178 && debug_get_type_kind (dhandle
, type
) == DEBUG_KIND_POINTER
)
2188 pvar
->pslot
= (debug_type
*) xmalloc (sizeof *pvar
->pslot
);
2189 *pvar
->pslot
= type
;
2190 type
= debug_make_indirect_type (dhandle
, pvar
->pslot
,
2191 (const char *) NULL
);
2200 ieee_error (info
, atn_code_start
, _("unknown ATN type"));
2204 /* Automatic variable. */
2205 if (! ieee_read_number (info
, pp
, &v
))
2207 namcopy
= savestring (name
, namlen
);
2209 type
= debug_make_void_type (dhandle
);
2211 pvar
->kind
= IEEE_LOCAL
;
2212 return debug_record_variable (dhandle
, namcopy
, type
, DEBUG_LOCAL
, v
);
2215 /* Register variable. */
2216 if (! ieee_read_number (info
, pp
, &v
))
2218 namcopy
= savestring (name
, namlen
);
2220 type
= debug_make_void_type (dhandle
);
2222 pvar
->kind
= IEEE_LOCAL
;
2223 return debug_record_variable (dhandle
, namcopy
, type
, DEBUG_REGISTER
,
2224 ieee_regno_to_genreg (info
->abfd
, v
));
2227 /* Static variable. */
2228 if (! ieee_require_asn (info
, pp
, &v
))
2230 namcopy
= savestring (name
, namlen
);
2232 type
= debug_make_void_type (dhandle
);
2233 if (info
->blockstack
.bsp
<= info
->blockstack
.stack
)
2236 blocktype
= info
->blockstack
.bsp
[-1].kind
;
2239 if (blocktype
== 4 || blocktype
== 6)
2240 pvar
->kind
= IEEE_LOCAL
;
2242 pvar
->kind
= IEEE_STATIC
;
2244 return debug_record_variable (dhandle
, namcopy
, type
,
2245 (blocktype
== 4 || blocktype
== 6
2246 ? DEBUG_LOCAL_STATIC
2251 /* External function. We don't currently record these. FIXME. */
2253 pvar
->kind
= IEEE_EXTERNAL
;
2257 /* External variable. We don't currently record these. FIXME. */
2259 pvar
->kind
= IEEE_EXTERNAL
;
2263 if (! ieee_read_number (info
, pp
, &v
)
2264 || ! ieee_read_number (info
, pp
, &v2
)
2265 || ! ieee_read_optional_number (info
, pp
, &v3
, &present
))
2269 if (! ieee_read_optional_number (info
, pp
, &v4
, &present
))
2273 /* We just ignore the two optional fields in v3 and v4, since
2274 they are not defined. */
2276 if (! ieee_require_asn (info
, pp
, &v3
))
2279 /* We have no way to record the column number. FIXME. */
2281 return debug_record_line (dhandle
, v
, v3
);
2284 /* Global variable. */
2285 if (! ieee_require_asn (info
, pp
, &v
))
2287 namcopy
= savestring (name
, namlen
);
2289 type
= debug_make_void_type (dhandle
);
2291 pvar
->kind
= IEEE_GLOBAL
;
2292 return debug_record_variable (dhandle
, namcopy
, type
, DEBUG_GLOBAL
, v
);
2295 /* Variable lifetime information. */
2296 if (! ieee_read_number (info
, pp
, &v
))
2299 /* We have no way to record this information. FIXME. */
2303 /* Locked register. The spec says that there are two required
2304 fields, but at least on occasion the MRI compiler only emits
2306 if (! ieee_read_number (info
, pp
, &v
)
2307 || ! ieee_read_optional_number (info
, pp
, &v2
, &present
))
2310 /* I think this means a variable that is both in a register and
2311 a frame slot. We ignore the frame slot. FIXME. */
2313 namcopy
= savestring (name
, namlen
);
2315 type
= debug_make_void_type (dhandle
);
2317 pvar
->kind
= IEEE_LOCAL
;
2318 return debug_record_variable (dhandle
, namcopy
, type
, DEBUG_REGISTER
, v
);
2321 /* Reserved for FORTRAN common. */
2322 ieee_error (info
, atn_code_start
, _("unsupported ATN11"));
2324 /* Return TRUE to keep going. */
2328 /* Based variable. */
2332 if (! ieee_read_number (info
, pp
, &v
)
2333 || ! ieee_read_number (info
, pp
, &v2
)
2334 || ! ieee_read_optional_number (info
, pp
, &v3
, &present
))
2338 if (! ieee_read_optional_number (info
, pp
, &v4
, &present
))
2342 if (! ieee_read_optional_number (info
, pp
, &v5
, &present
))
2347 /* We have no way to record this information. FIXME. */
2349 ieee_error (info
, atn_code_start
, _("unsupported ATN12"));
2351 /* Return TRUE to keep going. */
2355 /* Constant. The description of this that I have is ambiguous,
2356 so I'm not going to try to implement it. */
2357 if (! ieee_read_number (info
, pp
, &v
)
2358 || ! ieee_read_optional_number (info
, pp
, &v2
, &present
))
2362 if (! ieee_read_optional_number (info
, pp
, &v2
, &present
))
2366 if (! ieee_read_optional_id (info
, pp
, &name
, &namlen
, &present
))
2371 if ((ieee_record_enum_type
) **pp
== ieee_e2_first_byte_enum
)
2373 if (! ieee_require_asn (info
, pp
, &v3
))
2380 /* Static variable from assembler. */
2382 if (! ieee_read_number (info
, pp
, &v
)
2383 || ! ieee_read_optional_number (info
, pp
, &v2
, &present
)
2384 || ! ieee_require_asn (info
, pp
, &v3
))
2386 namcopy
= savestring (name
, namlen
);
2387 /* We don't really handle this correctly. FIXME. */
2388 return debug_record_variable (dhandle
, namcopy
,
2389 debug_make_void_type (dhandle
),
2390 v2
!= 0 ? DEBUG_GLOBAL
: DEBUG_STATIC
,
2394 /* Procedure miscellaneous information. */
2396 /* Variable miscellaneous information. */
2398 /* Module miscellaneous information. */
2399 if (! ieee_read_number (info
, pp
, &v
)
2400 || ! ieee_read_number (info
, pp
, &v2
)
2401 || ! ieee_read_optional_id (info
, pp
, &name
, &namlen
, &present
))
2404 if (atn_code
== 62 && v
== 80)
2408 ieee_error (info
, atn_code_start
,
2409 _("unexpected string in C++ misc"));
2412 return ieee_read_cxx_misc (info
, pp
, v2
);
2415 /* We just ignore all of this stuff. FIXME. */
2417 for (; v2
> 0; --v2
)
2419 switch ((ieee_record_enum_type
) **pp
)
2422 ieee_error (info
, *pp
, _("bad misc record"));
2425 case ieee_at_record_enum
:
2426 if (! ieee_require_atn65 (info
, pp
, &name
, &namlen
))
2430 case ieee_e2_first_byte_enum
:
2431 if (! ieee_require_asn (info
, pp
, &v3
))
2443 /* Handle C++ debugging miscellaneous records. This is called for
2444 procedure miscellaneous records of type 80. */
2447 ieee_read_cxx_misc (struct ieee_info
*info
, const bfd_byte
**pp
,
2448 unsigned long count
)
2450 const bfd_byte
*start
;
2455 /* Get the category of C++ misc record. */
2456 if (! ieee_require_asn (info
, pp
, &category
))
2463 ieee_error (info
, start
, _("unrecognized C++ misc record"));
2467 if (! ieee_read_cxx_class (info
, pp
, count
))
2475 unsigned long namlen
;
2477 /* The IEEE spec indicates that the 'M' record only has a
2478 flags field. The MRI compiler also emits the name of the
2481 if (! ieee_require_asn (info
, pp
, &flags
))
2483 if (*pp
< info
->pend
2484 && (ieee_record_enum_type
) **pp
== ieee_at_record_enum
)
2486 if (! ieee_require_atn65 (info
, pp
, &name
, &namlen
))
2490 /* This is emitted for method functions, but I don't think we
2491 care very much. It might help if it told us useful
2492 information like the class with which this function is
2493 associated, but it doesn't, so it isn't helpful. */
2498 if (! ieee_read_cxx_defaults (info
, pp
, count
))
2504 const char *name
, *mangled
, *cxx_class
;
2505 unsigned long namlen
, mangledlen
, classlen
;
2508 /* Pointer to member. */
2510 if (! ieee_require_atn65 (info
, pp
, &name
, &namlen
)
2511 || ! ieee_require_atn65 (info
, pp
, &mangled
, &mangledlen
)
2512 || ! ieee_require_atn65 (info
, pp
, &cxx_class
, &classlen
)
2513 || ! ieee_require_asn (info
, pp
, &control
))
2516 /* FIXME: We should now track down name and change its type. */
2521 if (! ieee_read_reference (info
, pp
))
2529 /* Read a C++ class definition. This is a pmisc type 80 record of
2533 ieee_read_cxx_class (struct ieee_info
*info
, const bfd_byte
**pp
,
2534 unsigned long count
)
2536 const bfd_byte
*start
;
2539 unsigned long taglen
;
2540 struct ieee_tag
*it
;
2542 debug_field
*fields
;
2543 unsigned int field_count
, field_alloc
;
2544 debug_baseclass
*baseclasses
;
2545 unsigned int baseclasses_count
, baseclasses_alloc
;
2546 const debug_field
*structfields
;
2550 unsigned long namlen
;
2551 debug_method_variant
*variants
;
2555 unsigned int methods_count
, methods_alloc
;
2556 debug_type vptrbase
;
2557 bfd_boolean ownvptr
;
2558 debug_method
*dmethods
;
2562 if (! ieee_require_asn (info
, pp
, &cxx_class
))
2566 if (! ieee_require_atn65 (info
, pp
, &tag
, &taglen
))
2570 /* Find the C struct with this name. */
2571 for (it
= info
->tags
; it
!= NULL
; it
= it
->next
)
2572 if (it
->name
[0] == tag
[0]
2573 && strncmp (it
->name
, tag
, taglen
) == 0
2574 && strlen (it
->name
) == taglen
)
2578 ieee_error (info
, start
, _("undefined C++ object"));
2582 dhandle
= info
->dhandle
;
2588 baseclasses_count
= 0;
2589 baseclasses_alloc
= 0;
2593 vptrbase
= DEBUG_TYPE_NULL
;
2596 structfields
= debug_get_fields (dhandle
, it
->type
);
2601 const bfd_byte
*spec_start
;
2605 if (! ieee_require_asn (info
, pp
, &id
))
2612 ieee_error (info
, spec_start
, _("unrecognized C++ object spec"));
2617 bfd_vma flags
, cinline
;
2618 const char *base
, *fieldname
;
2619 unsigned long baselen
, fieldlen
;
2621 debug_type basetype
;
2623 bfd_boolean virtualp
;
2624 enum debug_visibility visibility
;
2625 debug_baseclass baseclass
;
2627 /* This represents a base or friend class. */
2629 if (! ieee_require_asn (info
, pp
, &flags
)
2630 || ! ieee_require_atn65 (info
, pp
, &base
, &baselen
)
2631 || ! ieee_require_asn (info
, pp
, &cinline
)
2632 || ! ieee_require_atn65 (info
, pp
, &fieldname
, &fieldlen
))
2636 /* We have no way of recording friend information, so we
2638 if ((flags
& BASEFLAGS_FRIEND
) != 0)
2641 /* I assume that either all of the members of the
2642 baseclass are included in the object, starting at the
2643 beginning of the object, or that none of them are
2646 if ((fieldlen
== 0) == (cinline
== 0))
2648 ieee_error (info
, start
, _("unsupported C++ object type"));
2652 basecopy
= savestring (base
, baselen
);
2653 basetype
= debug_find_tagged_type (dhandle
, basecopy
,
2654 DEBUG_KIND_ILLEGAL
);
2656 if (basetype
== DEBUG_TYPE_NULL
)
2658 ieee_error (info
, start
, _("C++ base class not defined"));
2666 const debug_field
*pf
;
2668 if (structfields
== NULL
)
2670 ieee_error (info
, start
, _("C++ object has no fields"));
2674 for (pf
= structfields
; *pf
!= DEBUG_FIELD_NULL
; pf
++)
2678 fname
= debug_get_field_name (dhandle
, *pf
);
2681 if (fname
[0] == fieldname
[0]
2682 && strncmp (fname
, fieldname
, fieldlen
) == 0
2683 && strlen (fname
) == fieldlen
)
2686 if (*pf
== DEBUG_FIELD_NULL
)
2688 ieee_error (info
, start
,
2689 _("C++ base class not found in container"));
2693 bitpos
= debug_get_field_bitpos (dhandle
, *pf
);
2696 if ((flags
& BASEFLAGS_VIRTUAL
) != 0)
2700 if ((flags
& BASEFLAGS_PRIVATE
) != 0)
2701 visibility
= DEBUG_VISIBILITY_PRIVATE
;
2703 visibility
= DEBUG_VISIBILITY_PUBLIC
;
2705 baseclass
= debug_make_baseclass (dhandle
, basetype
, bitpos
,
2706 virtualp
, visibility
);
2707 if (baseclass
== DEBUG_BASECLASS_NULL
)
2710 if (baseclasses_count
+ 1 >= baseclasses_alloc
)
2712 baseclasses_alloc
+= 10;
2713 baseclasses
= ((debug_baseclass
*)
2714 xrealloc (baseclasses
,
2716 * sizeof *baseclasses
)));
2719 baseclasses
[baseclasses_count
] = baseclass
;
2720 ++baseclasses_count
;
2721 baseclasses
[baseclasses_count
] = DEBUG_BASECLASS_NULL
;
2728 const char *fieldname
, *mangledname
;
2729 unsigned long fieldlen
, mangledlen
;
2731 bfd_boolean staticp
;
2733 const debug_field
*pf
= NULL
;
2734 enum debug_visibility visibility
;
2737 /* This represents a data member. */
2739 if (! ieee_require_asn (info
, pp
, &flags
)
2740 || ! ieee_require_atn65 (info
, pp
, &fieldname
, &fieldlen
)
2741 || ! ieee_require_atn65 (info
, pp
, &mangledname
, &mangledlen
))
2745 fieldcopy
= savestring (fieldname
, fieldlen
);
2747 staticp
= (flags
& CXXFLAGS_STATIC
) != 0 ? TRUE
: FALSE
;
2751 struct ieee_var
*pv
, *pvend
;
2753 /* See if we can find a definition for this variable. */
2754 pv
= info
->vars
.vars
;
2755 pvend
= pv
+ info
->vars
.alloc
;
2756 for (; pv
< pvend
; pv
++)
2757 if (pv
->namlen
== mangledlen
2758 && strncmp (pv
->name
, mangledname
, mangledlen
) == 0)
2764 /* This can happen if the variable is never used. */
2765 ftype
= ieee_builtin_type (info
, start
,
2766 (unsigned int) builtin_void
);
2773 if (structfields
== NULL
)
2775 ieee_error (info
, start
, _("C++ object has no fields"));
2779 for (pf
= structfields
, findx
= 0;
2780 *pf
!= DEBUG_FIELD_NULL
;
2785 fname
= debug_get_field_name (dhandle
, *pf
);
2788 if (fname
[0] == mangledname
[0]
2789 && strncmp (fname
, mangledname
, mangledlen
) == 0
2790 && strlen (fname
) == mangledlen
)
2793 if (*pf
== DEBUG_FIELD_NULL
)
2795 ieee_error (info
, start
,
2796 _("C++ data member not found in container"));
2800 ftype
= debug_get_field_type (dhandle
, *pf
);
2802 if (debug_get_type_kind (dhandle
, ftype
) == DEBUG_KIND_POINTER
)
2804 /* We might need to convert this field into a
2805 reference type later on, so make it an indirect
2807 if (it
->fslots
== NULL
)
2810 const debug_field
*pfcnt
;
2813 for (pfcnt
= structfields
;
2814 *pfcnt
!= DEBUG_FIELD_NULL
;
2817 it
->fslots
= ((debug_type
*)
2818 xmalloc (fcnt
* sizeof *it
->fslots
));
2819 memset (it
->fslots
, 0,
2820 fcnt
* sizeof *it
->fslots
);
2823 if (ftype
== DEBUG_TYPE_NULL
)
2825 it
->fslots
[findx
] = ftype
;
2826 ftype
= debug_make_indirect_type (dhandle
,
2828 (const char *) NULL
);
2831 if (ftype
== DEBUG_TYPE_NULL
)
2834 switch (flags
& CXXFLAGS_VISIBILITY
)
2837 ieee_error (info
, start
, _("unknown C++ visibility"));
2840 case CXXFLAGS_VISIBILITY_PUBLIC
:
2841 visibility
= DEBUG_VISIBILITY_PUBLIC
;
2844 case CXXFLAGS_VISIBILITY_PRIVATE
:
2845 visibility
= DEBUG_VISIBILITY_PRIVATE
;
2848 case CXXFLAGS_VISIBILITY_PROTECTED
:
2849 visibility
= DEBUG_VISIBILITY_PROTECTED
;
2857 mangledcopy
= savestring (mangledname
, mangledlen
);
2859 field
= debug_make_static_member (dhandle
, fieldcopy
,
2865 bfd_vma bitpos
, bitsize
;
2867 bitpos
= debug_get_field_bitpos (dhandle
, *pf
);
2868 bitsize
= debug_get_field_bitsize (dhandle
, *pf
);
2869 if (bitpos
== (bfd_vma
) -1 || bitsize
== (bfd_vma
) -1)
2871 ieee_error (info
, start
, _("bad C++ field bit pos or size"));
2874 field
= debug_make_field (dhandle
, fieldcopy
, ftype
, bitpos
,
2875 bitsize
, visibility
);
2878 if (field
== DEBUG_FIELD_NULL
)
2881 if (field_count
+ 1 >= field_alloc
)
2884 fields
= ((debug_field
*)
2885 xrealloc (fields
, field_alloc
* sizeof *fields
));
2888 fields
[field_count
] = field
;
2890 fields
[field_count
] = DEBUG_FIELD_NULL
;
2897 bfd_vma flags
, voffset
, control
;
2898 const char *name
, *mangled
;
2899 unsigned long namlen
, mangledlen
;
2900 struct ieee_var
*pv
, *pvend
;
2902 enum debug_visibility visibility
;
2903 bfd_boolean constp
, volatilep
;
2905 debug_method_variant mv
;
2906 struct ieee_method
*meth
;
2909 if (! ieee_require_asn (info
, pp
, &flags
)
2910 || ! ieee_require_atn65 (info
, pp
, &name
, &namlen
)
2911 || ! ieee_require_atn65 (info
, pp
, &mangled
, &mangledlen
))
2918 if (! ieee_require_asn (info
, pp
, &voffset
))
2922 if (! ieee_require_asn (info
, pp
, &control
))
2926 /* We just ignore the control information. */
2928 /* We have no way to represent friend information, so we
2930 if ((flags
& CXXFLAGS_FRIEND
) != 0)
2933 /* We should already have seen a type for the function. */
2934 pv
= info
->vars
.vars
;
2935 pvend
= pv
+ info
->vars
.alloc
;
2936 for (; pv
< pvend
; pv
++)
2937 if (pv
->namlen
== mangledlen
2938 && strncmp (pv
->name
, mangled
, mangledlen
) == 0)
2943 /* We won't have type information for this function if
2944 it is not included in this file. We don't try to
2945 handle this case. FIXME. */
2946 type
= (debug_make_function_type
2948 ieee_builtin_type (info
, start
,
2949 (unsigned int) builtin_void
),
2950 (debug_type
*) NULL
,
2955 debug_type return_type
;
2956 const debug_type
*arg_types
;
2957 bfd_boolean varargs
;
2959 if (debug_get_type_kind (dhandle
, pv
->type
)
2960 != DEBUG_KIND_FUNCTION
)
2962 ieee_error (info
, start
,
2963 _("bad type for C++ method function"));
2967 return_type
= debug_get_return_type (dhandle
, pv
->type
);
2968 arg_types
= debug_get_parameter_types (dhandle
, pv
->type
,
2970 if (return_type
== DEBUG_TYPE_NULL
|| arg_types
== NULL
)
2972 ieee_error (info
, start
,
2973 _("no type information for C++ method function"));
2977 type
= debug_make_method_type (dhandle
, return_type
, it
->type
,
2978 (debug_type
*) arg_types
,
2981 if (type
== DEBUG_TYPE_NULL
)
2984 switch (flags
& CXXFLAGS_VISIBILITY
)
2987 ieee_error (info
, start
, _("unknown C++ visibility"));
2990 case CXXFLAGS_VISIBILITY_PUBLIC
:
2991 visibility
= DEBUG_VISIBILITY_PUBLIC
;
2994 case CXXFLAGS_VISIBILITY_PRIVATE
:
2995 visibility
= DEBUG_VISIBILITY_PRIVATE
;
2998 case CXXFLAGS_VISIBILITY_PROTECTED
:
2999 visibility
= DEBUG_VISIBILITY_PROTECTED
;
3003 constp
= (flags
& CXXFLAGS_CONST
) != 0 ? TRUE
: FALSE
;
3004 volatilep
= (flags
& CXXFLAGS_VOLATILE
) != 0 ? TRUE
: FALSE
;
3006 mangledcopy
= savestring (mangled
, mangledlen
);
3008 if ((flags
& CXXFLAGS_STATIC
) != 0)
3012 ieee_error (info
, start
, _("C++ static virtual method"));
3015 mv
= debug_make_static_method_variant (dhandle
, mangledcopy
,
3021 debug_type vcontext
;
3024 vcontext
= DEBUG_TYPE_NULL
;
3027 /* FIXME: How can we calculate this correctly? */
3028 vcontext
= it
->type
;
3030 mv
= debug_make_method_variant (dhandle
, mangledcopy
, type
,
3035 if (mv
== DEBUG_METHOD_VARIANT_NULL
)
3038 for (meth
= methods
, im
= 0; im
< methods_count
; meth
++, im
++)
3039 if (meth
->namlen
== namlen
3040 && strncmp (meth
->name
, name
, namlen
) == 0)
3042 if (im
>= methods_count
)
3044 if (methods_count
>= methods_alloc
)
3046 methods_alloc
+= 10;
3047 methods
= ((struct ieee_method
*)
3049 methods_alloc
* sizeof *methods
));
3051 methods
[methods_count
].name
= name
;
3052 methods
[methods_count
].namlen
= namlen
;
3053 methods
[methods_count
].variants
= NULL
;
3054 methods
[methods_count
].count
= 0;
3055 methods
[methods_count
].alloc
= 0;
3056 meth
= methods
+ methods_count
;
3060 if (meth
->count
+ 1 >= meth
->alloc
)
3063 meth
->variants
= ((debug_method_variant
*)
3064 xrealloc (meth
->variants
,
3066 * sizeof *meth
->variants
)));
3069 meth
->variants
[meth
->count
] = mv
;
3071 meth
->variants
[meth
->count
] = DEBUG_METHOD_VARIANT_NULL
;
3079 /* We have no way to store this information, so we just
3081 if (! ieee_require_asn (info
, pp
, &spec
))
3084 if ((spec
& 4) != 0)
3086 const char *filename
;
3087 unsigned long filenamlen
;
3090 if (! ieee_require_atn65 (info
, pp
, &filename
, &filenamlen
)
3091 || ! ieee_require_asn (info
, pp
, &lineno
))
3095 else if ((spec
& 8) != 0)
3097 const char *mangled
;
3098 unsigned long mangledlen
;
3100 if (! ieee_require_atn65 (info
, pp
, &mangled
, &mangledlen
))
3106 ieee_error (info
, start
,
3107 _("unrecognized C++ object overhead spec"));
3115 const char *vname
, *base
;
3116 unsigned long vnamelen
, baselen
;
3117 bfd_vma vsize
, control
;
3119 /* A virtual table pointer. */
3121 if (! ieee_require_atn65 (info
, pp
, &vname
, &vnamelen
)
3122 || ! ieee_require_asn (info
, pp
, &vsize
)
3123 || ! ieee_require_atn65 (info
, pp
, &base
, &baselen
)
3124 || ! ieee_require_asn (info
, pp
, &control
))
3128 /* We just ignore the control number. We don't care what
3129 the virtual table name is. We have no way to store the
3130 virtual table size, and I don't think we care anyhow. */
3132 /* FIXME: We can't handle multiple virtual table pointers. */
3140 basecopy
= savestring (base
, baselen
);
3141 vptrbase
= debug_find_tagged_type (dhandle
, basecopy
,
3142 DEBUG_KIND_ILLEGAL
);
3144 if (vptrbase
== DEBUG_TYPE_NULL
)
3146 ieee_error (info
, start
, _("undefined C++ vtable"));
3155 /* Now that we have seen all the method variants, we can call
3156 debug_make_method for each one. */
3158 if (methods_count
== 0)
3164 dmethods
= ((debug_method
*)
3165 xmalloc ((methods_count
+ 1) * sizeof *dmethods
));
3166 for (i
= 0; i
< methods_count
; i
++)
3170 namcopy
= savestring (methods
[i
].name
, methods
[i
].namlen
);
3171 dmethods
[i
] = debug_make_method (dhandle
, namcopy
,
3172 methods
[i
].variants
);
3173 if (dmethods
[i
] == DEBUG_METHOD_NULL
)
3176 dmethods
[i
] = DEBUG_METHOD_NULL
;
3180 /* The struct type was created as an indirect type pointing at
3181 it->slot. We update it->slot to automatically update all
3182 references to this struct. */
3183 it
->slot
= debug_make_object_type (dhandle
,
3185 debug_get_type_size (dhandle
,
3187 fields
, baseclasses
, dmethods
,
3189 if (it
->slot
== DEBUG_TYPE_NULL
)
3195 /* Read C++ default argument value and reference type information. */
3198 ieee_read_cxx_defaults (struct ieee_info
*info
, const bfd_byte
**pp
,
3199 unsigned long count
)
3201 const bfd_byte
*start
;
3203 unsigned long fnlen
;
3208 /* Giving the function name before the argument count is an addendum
3209 to the spec. The function name is demangled, though, so this
3210 record must always refer to the current function. */
3212 if (info
->blockstack
.bsp
<= info
->blockstack
.stack
3213 || info
->blockstack
.bsp
[-1].fnindx
== (unsigned int) -1)
3215 ieee_error (info
, start
, _("C++ default values not in a function"));
3219 if (! ieee_require_atn65 (info
, pp
, &fnname
, &fnlen
)
3220 || ! ieee_require_asn (info
, pp
, &defcount
))
3224 while (defcount
-- > 0)
3228 unsigned long strvallen
;
3230 if (! ieee_require_asn (info
, pp
, &type
))
3242 if (! ieee_require_asn (info
, pp
, &val
))
3249 if (! ieee_require_atn65 (info
, pp
, &strval
, &strvallen
))
3255 ieee_error (info
, start
, _("unrecognized C++ default type"));
3259 /* We have no way to record the default argument values, so we
3260 just ignore them. FIXME. */
3263 /* Any remaining arguments are indices of parameters that are really
3268 debug_type
*arg_slots
;
3270 dhandle
= info
->dhandle
;
3271 arg_slots
= info
->types
.types
[info
->blockstack
.bsp
[-1].fnindx
].arg_slots
;
3277 if (! ieee_require_asn (info
, pp
, &indx
))
3279 /* The index is 1 based. */
3281 if (arg_slots
== NULL
3282 || arg_slots
[indx
] == DEBUG_TYPE_NULL
3283 || (debug_get_type_kind (dhandle
, arg_slots
[indx
])
3284 != DEBUG_KIND_POINTER
))
3286 ieee_error (info
, start
, _("reference parameter is not a pointer"));
3290 target
= debug_get_target_type (dhandle
, arg_slots
[indx
]);
3291 arg_slots
[indx
] = debug_make_reference_type (dhandle
, target
);
3292 if (arg_slots
[indx
] == DEBUG_TYPE_NULL
)
3300 /* Read a C++ reference definition. */
3303 ieee_read_reference (struct ieee_info
*info
, const bfd_byte
**pp
)
3305 const bfd_byte
*start
;
3307 const char *cxx_class
, *name
;
3308 unsigned long classlen
, namlen
;
3314 if (! ieee_require_asn (info
, pp
, &flags
))
3317 /* Giving the class name before the member name is in an addendum to
3321 if (! ieee_require_atn65 (info
, pp
, &cxx_class
, &classlen
))
3325 if (! ieee_require_atn65 (info
, pp
, &name
, &namlen
))
3333 /* We search from the last variable indices to the first in
3334 hopes of finding local variables correctly. We search the
3335 local variables on the first pass, and the global variables
3336 on the second. FIXME: This probably won't work in all cases.
3337 On the other hand, I don't know what will. */
3338 for (pass
= 0; pass
< 2; pass
++)
3340 struct ieee_vars
*vars
;
3342 struct ieee_var
*pv
= NULL
;
3348 vars
= info
->global_vars
;
3353 for (i
= (int) vars
->alloc
- 1; i
>= 0; i
--)
3357 pv
= vars
->vars
+ i
;
3359 if (pv
->pslot
== NULL
3360 || pv
->namlen
!= namlen
3361 || strncmp (pv
->name
, name
, namlen
) != 0)
3368 ieee_error (info
, start
,
3369 _("unrecognized C++ reference type"));
3373 /* Global variable or function. */
3374 if (pv
->kind
== IEEE_GLOBAL
3375 || pv
->kind
== IEEE_EXTERNAL
3376 || pv
->kind
== IEEE_FUNCTION
)
3381 /* Global static variable or function. */
3382 if (pv
->kind
== IEEE_STATIC
3383 || pv
->kind
== IEEE_FUNCTION
)
3388 /* Local variable. */
3389 if (pv
->kind
== IEEE_LOCAL
)
3407 struct ieee_tag
*it
;
3409 for (it
= info
->tags
; it
!= NULL
; it
= it
->next
)
3411 if (it
->name
[0] == cxx_class
[0]
3412 && strncmp (it
->name
, cxx_class
, classlen
) == 0
3413 && strlen (it
->name
) == classlen
)
3415 if (it
->fslots
!= NULL
)
3417 const debug_field
*pf
;
3420 pf
= debug_get_fields (info
->dhandle
, it
->type
);
3423 ieee_error (info
, start
,
3424 "C++ reference in class with no fields");
3428 for (findx
= 0; *pf
!= DEBUG_FIELD_NULL
; pf
++, findx
++)
3432 fname
= debug_get_field_name (info
->dhandle
, *pf
);
3435 if (strncmp (fname
, name
, namlen
) == 0
3436 && strlen (fname
) == namlen
)
3438 pslot
= it
->fslots
+ findx
;
3451 ieee_error (info
, start
, _("C++ reference not found"));
3455 /* We allocated the type of the object as an indirect type pointing
3456 to *pslot, which we can now update to be a reference type. */
3457 if (debug_get_type_kind (info
->dhandle
, *pslot
) != DEBUG_KIND_POINTER
)
3459 ieee_error (info
, start
, _("C++ reference is not pointer"));
3463 target
= debug_get_target_type (info
->dhandle
, *pslot
);
3464 *pslot
= debug_make_reference_type (info
->dhandle
, target
);
3465 if (*pslot
== DEBUG_TYPE_NULL
)
3471 /* Require an ASN record. */
3474 ieee_require_asn (struct ieee_info
*info
, const bfd_byte
**pp
, bfd_vma
*pv
)
3476 const bfd_byte
*start
;
3477 ieee_record_enum_type c
;
3482 c
= (ieee_record_enum_type
) **pp
;
3483 if (c
!= ieee_e2_first_byte_enum
)
3485 ieee_error (info
, start
, _("missing required ASN"));
3490 c
= (ieee_record_enum_type
) (((unsigned int) c
<< 8) | **pp
);
3491 if (c
!= ieee_asn_record_enum
)
3493 ieee_error (info
, start
, _("missing required ASN"));
3498 /* Just ignore the variable index. */
3499 if (! ieee_read_number (info
, pp
, &varindx
))
3502 return ieee_read_expression (info
, pp
, pv
);
3505 /* Require an ATN65 record. */
3508 ieee_require_atn65 (struct ieee_info
*info
, const bfd_byte
**pp
,
3509 const char **pname
, unsigned long *pnamlen
)
3511 const bfd_byte
*start
;
3512 ieee_record_enum_type c
;
3513 bfd_vma name_indx
, type_indx
, atn_code
;
3517 c
= (ieee_record_enum_type
) **pp
;
3518 if (c
!= ieee_at_record_enum
)
3520 ieee_error (info
, start
, _("missing required ATN65"));
3525 c
= (ieee_record_enum_type
) (((unsigned int) c
<< 8) | **pp
);
3526 if (c
!= ieee_atn_record_enum
)
3528 ieee_error (info
, start
, _("missing required ATN65"));
3533 if (! ieee_read_number (info
, pp
, &name_indx
)
3534 || ! ieee_read_number (info
, pp
, &type_indx
)
3535 || ! ieee_read_number (info
, pp
, &atn_code
))
3538 /* Just ignore name_indx. */
3540 if (type_indx
!= 0 || atn_code
!= 65)
3542 ieee_error (info
, start
, _("bad ATN65 record"));
3546 return ieee_read_id (info
, pp
, pname
, pnamlen
);
3549 /* Convert a register number in IEEE debugging information into a
3550 generic register number. */
3553 ieee_regno_to_genreg (bfd
*abfd
, int r
)
3555 switch (bfd_get_arch (abfd
))
3558 /* For some reasons stabs adds 2 to the floating point register
3565 /* Stabs uses 0 to 15 for r0 to r15, 16 to 31 for g0 to g15, and
3566 32 to 35 for fp0 to fp3. */
3577 /* Convert a generic register number to an IEEE specific one. */
3580 ieee_genreg_to_regno (bfd
*abfd
, int r
)
3582 switch (bfd_get_arch (abfd
))
3585 /* For some reason stabs add 2 to the floating point register
3592 /* Stabs uses 0 to 15 for r0 to r15, 16 to 31 for g0 to g15, and
3593 32 to 35 for fp0 to fp3. */
3604 /* These routines build IEEE debugging information out of the generic
3605 debugging information. */
3607 /* We build the IEEE debugging information byte by byte. Rather than
3608 waste time copying data around, we use a linked list of buffers to
3611 #define IEEE_BUFSIZE (490)
3616 struct ieee_buf
*next
;
3617 /* Number of data bytes in this buffer. */
3620 bfd_byte buf
[IEEE_BUFSIZE
];
3623 /* A list of buffers. */
3628 struct ieee_buf
*head
;
3629 /* Tail--last buffer on list. */
3630 struct ieee_buf
*tail
;
3633 /* In order to generate the BB11 blocks required by the HP emulator,
3634 we keep track of ranges of addresses which correspond to a given
3635 compilation unit. */
3640 struct ieee_range
*next
;
3647 /* This structure holds information for a class on the type stack. */
3649 struct ieee_type_class
3651 /* The name index in the debugging information. */
3653 /* The pmisc records for the class. */
3654 struct ieee_buflist pmiscbuf
;
3655 /* The number of pmisc records. */
3656 unsigned int pmisccount
;
3657 /* The name of the class holding the virtual table, if not this
3660 /* Whether this class holds its own virtual table. */
3661 bfd_boolean ownvptr
;
3662 /* The largest virtual table offset seen so far. */
3664 /* The current method. */
3666 /* Additional pmisc records used to record fields of reference type. */
3667 struct ieee_buflist refs
;
3670 /* This is how we store types for the writing routines. Most types
3671 are simply represented by a type index. */
3673 struct ieee_write_type
3677 /* The size of the type, if known. */
3679 /* The name of the type, if any. */
3681 /* If this is a function or method type, we build the type here, and
3682 only add it to the output buffers if we need it. */
3683 struct ieee_buflist fndef
;
3684 /* If this is a struct, this is where the struct definition is
3686 struct ieee_buflist strdef
;
3687 /* If this is a class, this is where the class information is built. */
3688 struct ieee_type_class
*classdef
;
3689 /* Whether the type is unsigned. */
3690 unsigned int unsignedp
: 1;
3691 /* Whether this is a reference type. */
3692 unsigned int referencep
: 1;
3693 /* Whether this is in the local type block. */
3694 unsigned int localp
: 1;
3695 /* Whether this is a duplicate struct definition which we are
3697 unsigned int ignorep
: 1;
3700 /* This is the type stack used by the debug writing routines. FIXME:
3701 We could generate more efficient output if we remembered when we
3702 have output a particular type before. */
3704 struct ieee_type_stack
3706 /* Next entry on stack. */
3707 struct ieee_type_stack
*next
;
3708 /* Type information. */
3709 struct ieee_write_type type
;
3712 /* This is a list of associations between a name and some types.
3713 These are used for typedefs and tags. */
3715 struct ieee_name_type
3717 /* Next type for this name. */
3718 struct ieee_name_type
*next
;
3719 /* ID number. For a typedef, this is the index of the type to which
3720 this name is typedefed. */
3723 struct ieee_write_type type
;
3724 /* If this is a tag which has not yet been defined, this is the
3725 kind. If the tag has been defined, this is DEBUG_KIND_ILLEGAL. */
3726 enum debug_type_kind kind
;
3729 /* We use a hash table to associate names and types. */
3731 struct ieee_name_type_hash_table
3733 struct bfd_hash_table root
;
3736 struct ieee_name_type_hash_entry
3738 struct bfd_hash_entry root
;
3739 /* Information for this name. */
3740 struct ieee_name_type
*types
;
3743 /* This is a list of enums. */
3745 struct ieee_defined_enum
3748 struct ieee_defined_enum
*next
;
3751 /* Whether this enum has been defined. */
3752 bfd_boolean defined
;
3758 bfd_signed_vma
*vals
;
3761 /* We keep a list of modified versions of types, so that we don't
3762 output them more than once. */
3764 struct ieee_modified_type
3766 /* Pointer to this type. */
3767 unsigned int pointer
;
3768 /* Function with unknown arguments returning this type. */
3769 unsigned int function
;
3770 /* Const version of this type. */
3771 unsigned int const_qualified
;
3772 /* Volatile version of this type. */
3773 unsigned int volatile_qualified
;
3774 /* List of arrays of this type of various bounds. */
3775 struct ieee_modified_array_type
*arrays
;
3778 /* A list of arrays bounds. */
3780 struct ieee_modified_array_type
3782 /* Next array bounds. */
3783 struct ieee_modified_array_type
*next
;
3784 /* Type index with these bounds. */
3789 bfd_signed_vma high
;
3792 /* This is a list of pending function parameter information. We don't
3793 output them until we see the first block. */
3795 struct ieee_pending_parm
3797 /* Next pending parameter. */
3798 struct ieee_pending_parm
*next
;
3803 /* Whether the type is a reference. */
3804 bfd_boolean referencep
;
3806 enum debug_parm_kind kind
;
3811 /* This is the handle passed down by debug_write. */
3815 /* BFD we are writing to. */
3817 /* Whether we got an error in a subroutine called via traverse or
3818 map_over_sections. */
3820 /* Current data buffer list. */
3821 struct ieee_buflist
*current
;
3822 /* Current data buffer. */
3823 struct ieee_buf
*curbuf
;
3824 /* Filename of current compilation unit. */
3825 const char *filename
;
3826 /* Module name of current compilation unit. */
3827 const char *modname
;
3828 /* List of buffer for global types. */
3829 struct ieee_buflist global_types
;
3830 /* List of finished data buffers. */
3831 struct ieee_buflist data
;
3832 /* List of buffers for typedefs in the current compilation unit. */
3833 struct ieee_buflist types
;
3834 /* List of buffers for variables and functions in the current
3835 compilation unit. */
3836 struct ieee_buflist vars
;
3837 /* List of buffers for C++ class definitions in the current
3838 compilation unit. */
3839 struct ieee_buflist cxx
;
3840 /* List of buffers for line numbers in the current compilation unit. */
3841 struct ieee_buflist linenos
;
3842 /* Ranges for the current compilation unit. */
3843 struct ieee_range
*ranges
;
3844 /* Ranges for all debugging information. */
3845 struct ieee_range
*global_ranges
;
3846 /* Nested pending ranges. */
3847 struct ieee_range
*pending_ranges
;
3849 struct ieee_type_stack
*type_stack
;
3850 /* Next unallocated type index. */
3851 unsigned int type_indx
;
3852 /* Next unallocated name index. */
3853 unsigned int name_indx
;
3855 struct ieee_name_type_hash_table typedefs
;
3857 struct ieee_name_type_hash_table tags
;
3859 struct ieee_defined_enum
*enums
;
3860 /* Modified versions of types. */
3861 struct ieee_modified_type
*modified
;
3862 /* Number of entries allocated in modified. */
3863 unsigned int modified_alloc
;
3864 /* 4 byte complex type. */
3865 unsigned int complex_float_index
;
3866 /* 8 byte complex type. */
3867 unsigned int complex_double_index
;
3868 /* The depth of block nesting. This is 0 outside a function, and 1
3869 just after start_function is called. */
3870 unsigned int block_depth
;
3871 /* The name of the current function. */
3873 /* List of buffers for the type of the function we are currently
3875 struct ieee_buflist fntype
;
3876 /* List of buffers for the parameters of the function we are
3877 currently writing out. */
3878 struct ieee_buflist fnargs
;
3879 /* Number of arguments written to fnargs. */
3880 unsigned int fnargcount
;
3881 /* Pending function parameters. */
3882 struct ieee_pending_parm
*pending_parms
;
3883 /* Current line number filename. */
3884 const char *lineno_filename
;
3885 /* Line number name index. */
3886 unsigned int lineno_name_indx
;
3887 /* Filename of pending line number. */
3888 const char *pending_lineno_filename
;
3889 /* Pending line number. */
3890 unsigned long pending_lineno
;
3891 /* Address of pending line number. */
3892 bfd_vma pending_lineno_addr
;
3893 /* Highest address seen at end of procedure. */
3897 static bfd_boolean ieee_init_buffer
3898 (struct ieee_handle
*, struct ieee_buflist
*);
3899 static bfd_boolean ieee_change_buffer
3900 (struct ieee_handle
*, struct ieee_buflist
*);
3901 static bfd_boolean ieee_append_buffer
3902 (struct ieee_handle
*, struct ieee_buflist
*, struct ieee_buflist
*);
3903 static bfd_boolean
ieee_real_write_byte (struct ieee_handle
*, int);
3904 static bfd_boolean
ieee_write_2bytes (struct ieee_handle
*, int);
3905 static bfd_boolean
ieee_write_number (struct ieee_handle
*, bfd_vma
);
3906 static bfd_boolean
ieee_write_id (struct ieee_handle
*, const char *);
3907 static bfd_boolean ieee_write_asn
3908 (struct ieee_handle
*, unsigned int, bfd_vma
);
3909 static bfd_boolean ieee_write_atn65
3910 (struct ieee_handle
*, unsigned int, const char *);
3911 static bfd_boolean ieee_push_type
3912 (struct ieee_handle
*, unsigned int, unsigned int, bfd_boolean
,
3914 static unsigned int ieee_pop_type (struct ieee_handle
*);
3915 static void ieee_pop_unused_type (struct ieee_handle
*);
3916 static unsigned int ieee_pop_type_used (struct ieee_handle
*, bfd_boolean
);
3917 static bfd_boolean ieee_add_range
3918 (struct ieee_handle
*, bfd_boolean
, bfd_vma
, bfd_vma
);
3919 static bfd_boolean
ieee_start_range (struct ieee_handle
*, bfd_vma
);
3920 static bfd_boolean
ieee_end_range (struct ieee_handle
*, bfd_vma
);
3921 static bfd_boolean ieee_define_type
3922 (struct ieee_handle
*, unsigned int, bfd_boolean
, bfd_boolean
);
3923 static bfd_boolean ieee_define_named_type
3924 (struct ieee_handle
*, const char *, unsigned int, unsigned int,
3925 bfd_boolean
, bfd_boolean
, struct ieee_buflist
*);
3926 static struct ieee_modified_type
*ieee_get_modified_info
3927 (struct ieee_handle
*, unsigned int);
3928 static struct bfd_hash_entry
*ieee_name_type_newfunc
3929 (struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *);
3930 static bfd_boolean ieee_write_undefined_tag
3931 (struct ieee_name_type_hash_entry
*, void *);
3932 static bfd_boolean
ieee_finish_compilation_unit (struct ieee_handle
*);
3933 static void ieee_add_bb11_blocks (bfd
*, asection
*, void *);
3934 static bfd_boolean ieee_add_bb11
3935 (struct ieee_handle
*, asection
*, bfd_vma
, bfd_vma
);
3936 static bfd_boolean
ieee_output_pending_parms (struct ieee_handle
*);
3937 static unsigned int ieee_vis_to_flags (enum debug_visibility
);
3938 static bfd_boolean ieee_class_method_var
3939 (struct ieee_handle
*, const char *, enum debug_visibility
, bfd_boolean
,
3940 bfd_boolean
, bfd_boolean
, bfd_vma
, bfd_boolean
);
3942 static bfd_boolean
ieee_start_compilation_unit (void *, const char *);
3943 static bfd_boolean
ieee_start_source (void *, const char *);
3944 static bfd_boolean
ieee_empty_type (void *);
3945 static bfd_boolean
ieee_void_type (void *);
3946 static bfd_boolean
ieee_int_type (void *, unsigned int, bfd_boolean
);
3947 static bfd_boolean
ieee_float_type (void *, unsigned int);
3948 static bfd_boolean
ieee_complex_type (void *, unsigned int);
3949 static bfd_boolean
ieee_bool_type (void *, unsigned int);
3950 static bfd_boolean ieee_enum_type
3951 (void *, const char *, const char **, bfd_signed_vma
*);
3952 static bfd_boolean
ieee_pointer_type (void *);
3953 static bfd_boolean
ieee_function_type (void *, int, bfd_boolean
);
3954 static bfd_boolean
ieee_reference_type (void *);
3955 static bfd_boolean
ieee_range_type (void *, bfd_signed_vma
, bfd_signed_vma
);
3956 static bfd_boolean ieee_array_type
3957 (void *, bfd_signed_vma
, bfd_signed_vma
, bfd_boolean
);
3958 static bfd_boolean
ieee_set_type (void *, bfd_boolean
);
3959 static bfd_boolean
ieee_offset_type (void *);
3960 static bfd_boolean
ieee_method_type (void *, bfd_boolean
, int, bfd_boolean
);
3961 static bfd_boolean
ieee_const_type (void *);
3962 static bfd_boolean
ieee_volatile_type (void *);
3963 static bfd_boolean ieee_start_struct_type
3964 (void *, const char *, unsigned int, bfd_boolean
, unsigned int);
3965 static bfd_boolean ieee_struct_field
3966 (void *, const char *, bfd_vma
, bfd_vma
, enum debug_visibility
);
3967 static bfd_boolean
ieee_end_struct_type (void *);
3968 static bfd_boolean ieee_start_class_type
3969 (void *, const char *, unsigned int, bfd_boolean
, unsigned int, bfd_boolean
,
3971 static bfd_boolean ieee_class_static_member
3972 (void *, const char *, const char *, enum debug_visibility
);
3973 static bfd_boolean ieee_class_baseclass
3974 (void *, bfd_vma
, bfd_boolean
, enum debug_visibility
);
3975 static bfd_boolean
ieee_class_start_method (void *, const char *);
3976 static bfd_boolean ieee_class_method_variant
3977 (void *, const char *, enum debug_visibility
, bfd_boolean
, bfd_boolean
,
3978 bfd_vma
, bfd_boolean
);
3979 static bfd_boolean ieee_class_static_method_variant
3980 (void *, const char *, enum debug_visibility
, bfd_boolean
, bfd_boolean
);
3981 static bfd_boolean
ieee_class_end_method (void *);
3982 static bfd_boolean
ieee_end_class_type (void *);
3983 static bfd_boolean
ieee_typedef_type (void *, const char *);
3984 static bfd_boolean ieee_tag_type
3985 (void *, const char *, unsigned int, enum debug_type_kind
);
3986 static bfd_boolean
ieee_typdef (void *, const char *);
3987 static bfd_boolean
ieee_tag (void *, const char *);
3988 static bfd_boolean
ieee_int_constant (void *, const char *, bfd_vma
);
3989 static bfd_boolean
ieee_float_constant (void *, const char *, double);
3990 static bfd_boolean
ieee_typed_constant (void *, const char *, bfd_vma
);
3991 static bfd_boolean ieee_variable
3992 (void *, const char *, enum debug_var_kind
, bfd_vma
);
3993 static bfd_boolean
ieee_start_function (void *, const char *, bfd_boolean
);
3994 static bfd_boolean ieee_function_parameter
3995 (void *, const char *, enum debug_parm_kind
, bfd_vma
);
3996 static bfd_boolean
ieee_start_block (void *, bfd_vma
);
3997 static bfd_boolean
ieee_end_block (void *, bfd_vma
);
3998 static bfd_boolean
ieee_end_function (void *);
3999 static bfd_boolean
ieee_lineno (void *, const char *, unsigned long, bfd_vma
);
4001 static const struct debug_write_fns ieee_fns
=
4003 ieee_start_compilation_unit
,
4014 ieee_reference_type
,
4022 ieee_start_struct_type
,
4024 ieee_end_struct_type
,
4025 ieee_start_class_type
,
4026 ieee_class_static_member
,
4027 ieee_class_baseclass
,
4028 ieee_class_start_method
,
4029 ieee_class_method_variant
,
4030 ieee_class_static_method_variant
,
4031 ieee_class_end_method
,
4032 ieee_end_class_type
,
4038 ieee_float_constant
,
4039 ieee_typed_constant
,
4041 ieee_start_function
,
4042 ieee_function_parameter
,
4049 /* Initialize a buffer to be empty. */
4052 ieee_init_buffer (struct ieee_handle
*info ATTRIBUTE_UNUSED
,
4053 struct ieee_buflist
*buflist
)
4055 buflist
->head
= NULL
;
4056 buflist
->tail
= NULL
;
4060 /* See whether a buffer list has any data. */
4062 #define ieee_buffer_emptyp(buflist) ((buflist)->head == NULL)
4064 /* Change the current buffer to a specified buffer chain. */
4067 ieee_change_buffer (struct ieee_handle
*info
, struct ieee_buflist
*buflist
)
4069 if (buflist
->head
== NULL
)
4071 struct ieee_buf
*buf
;
4073 buf
= (struct ieee_buf
*) xmalloc (sizeof *buf
);
4076 buflist
->head
= buf
;
4077 buflist
->tail
= buf
;
4080 info
->current
= buflist
;
4081 info
->curbuf
= buflist
->tail
;
4086 /* Append a buffer chain. */
4089 ieee_append_buffer (struct ieee_handle
*info ATTRIBUTE_UNUSED
,
4090 struct ieee_buflist
*mainbuf
,
4091 struct ieee_buflist
*newbuf
)
4093 if (newbuf
->head
!= NULL
)
4095 if (mainbuf
->head
== NULL
)
4096 mainbuf
->head
= newbuf
->head
;
4098 mainbuf
->tail
->next
= newbuf
->head
;
4099 mainbuf
->tail
= newbuf
->tail
;
4104 /* Write a byte into the buffer. We use a macro for speed and a
4105 function for the complex cases. */
4107 #define ieee_write_byte(info, b) \
4108 ((info)->curbuf->c < IEEE_BUFSIZE \
4109 ? ((info)->curbuf->buf[(info)->curbuf->c++] = (b), TRUE) \
4110 : ieee_real_write_byte ((info), (b)))
4113 ieee_real_write_byte (struct ieee_handle
*info
, int b
)
4115 if (info
->curbuf
->c
>= IEEE_BUFSIZE
)
4119 n
= (struct ieee_buf
*) xmalloc (sizeof *n
);
4122 if (info
->current
->head
== NULL
)
4123 info
->current
->head
= n
;
4125 info
->current
->tail
->next
= n
;
4126 info
->current
->tail
= n
;
4130 info
->curbuf
->buf
[info
->curbuf
->c
] = b
;
4136 /* Write out two bytes. */
4139 ieee_write_2bytes (struct ieee_handle
*info
, int i
)
4141 return (ieee_write_byte (info
, i
>> 8)
4142 && ieee_write_byte (info
, i
& 0xff));
4145 /* Write out an integer. */
4148 ieee_write_number (struct ieee_handle
*info
, bfd_vma v
)
4155 if (v
<= (bfd_vma
) ieee_number_end_enum
)
4156 return ieee_write_byte (info
, (int) v
);
4167 if (c
> (unsigned int) (ieee_number_repeat_end_enum
4168 - ieee_number_repeat_start_enum
))
4170 fprintf (stderr
, _("IEEE numeric overflow: 0x"));
4171 fprintf_vma (stderr
, v
);
4172 fprintf (stderr
, "\n");
4176 if (! ieee_write_byte (info
, (int) ieee_number_repeat_start_enum
+ c
))
4178 for (; c
> 0; --c
, ++p
)
4180 if (! ieee_write_byte (info
, *p
))
4187 /* Write out a string. */
4190 ieee_write_id (struct ieee_handle
*info
, const char *s
)
4197 if (! ieee_write_byte (info
, len
))
4200 else if (len
<= 0xff)
4202 if (! ieee_write_byte (info
, (int) ieee_extension_length_1_enum
)
4203 || ! ieee_write_byte (info
, len
))
4206 else if (len
<= 0xffff)
4208 if (! ieee_write_byte (info
, (int) ieee_extension_length_2_enum
)
4209 || ! ieee_write_2bytes (info
, len
))
4214 fprintf (stderr
, _("IEEE string length overflow: %u\n"), len
);
4218 for (; *s
!= '\0'; s
++)
4219 if (! ieee_write_byte (info
, *s
))
4225 /* Write out an ASN record. */
4228 ieee_write_asn (struct ieee_handle
*info
, unsigned int indx
, bfd_vma val
)
4230 return (ieee_write_2bytes (info
, (int) ieee_asn_record_enum
)
4231 && ieee_write_number (info
, indx
)
4232 && ieee_write_number (info
, val
));
4235 /* Write out an ATN65 record. */
4238 ieee_write_atn65 (struct ieee_handle
*info
, unsigned int indx
, const char *s
)
4240 return (ieee_write_2bytes (info
, (int) ieee_atn_record_enum
)
4241 && ieee_write_number (info
, indx
)
4242 && ieee_write_number (info
, 0)
4243 && ieee_write_number (info
, 65)
4244 && ieee_write_id (info
, s
));
4247 /* Push a type index onto the type stack. */
4250 ieee_push_type (struct ieee_handle
*info
, unsigned int indx
,
4251 unsigned int size
, bfd_boolean unsignedp
, bfd_boolean localp
)
4253 struct ieee_type_stack
*ts
;
4255 ts
= (struct ieee_type_stack
*) xmalloc (sizeof *ts
);
4256 memset (ts
, 0, sizeof *ts
);
4258 ts
->type
.indx
= indx
;
4259 ts
->type
.size
= size
;
4260 ts
->type
.unsignedp
= unsignedp
;
4261 ts
->type
.localp
= localp
;
4263 ts
->next
= info
->type_stack
;
4264 info
->type_stack
= ts
;
4269 /* Pop a type index off the type stack. */
4272 ieee_pop_type (struct ieee_handle
*info
)
4274 return ieee_pop_type_used (info
, TRUE
);
4277 /* Pop an unused type index off the type stack. */
4280 ieee_pop_unused_type (struct ieee_handle
*info
)
4282 (void) ieee_pop_type_used (info
, FALSE
);
4285 /* Pop a used or unused type index off the type stack. */
4288 ieee_pop_type_used (struct ieee_handle
*info
, bfd_boolean used
)
4290 struct ieee_type_stack
*ts
;
4293 ts
= info
->type_stack
;
4294 assert (ts
!= NULL
);
4296 /* If this is a function type, and we need it, we need to append the
4297 actual definition to the typedef block now. */
4298 if (used
&& ! ieee_buffer_emptyp (&ts
->type
.fndef
))
4300 struct ieee_buflist
*buflist
;
4302 if (ts
->type
.localp
)
4304 /* Make sure we have started the types block. */
4305 if (ieee_buffer_emptyp (&info
->types
))
4307 if (! ieee_change_buffer (info
, &info
->types
)
4308 || ! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
4309 || ! ieee_write_byte (info
, 1)
4310 || ! ieee_write_number (info
, 0)
4311 || ! ieee_write_id (info
, info
->modname
))
4314 buflist
= &info
->types
;
4318 /* Make sure we started the global type block. */
4319 if (ieee_buffer_emptyp (&info
->global_types
))
4321 if (! ieee_change_buffer (info
, &info
->global_types
)
4322 || ! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
4323 || ! ieee_write_byte (info
, 2)
4324 || ! ieee_write_number (info
, 0)
4325 || ! ieee_write_id (info
, ""))
4328 buflist
= &info
->global_types
;
4331 if (! ieee_append_buffer (info
, buflist
, &ts
->type
.fndef
))
4335 ret
= ts
->type
.indx
;
4336 info
->type_stack
= ts
->next
;
4341 /* Add a range of bytes included in the current compilation unit. */
4344 ieee_add_range (struct ieee_handle
*info
, bfd_boolean global
, bfd_vma low
,
4347 struct ieee_range
**plist
, *r
, **pr
;
4349 if (low
== (bfd_vma
) -1 || high
== (bfd_vma
) -1 || low
== high
)
4353 plist
= &info
->global_ranges
;
4355 plist
= &info
->ranges
;
4357 for (r
= *plist
; r
!= NULL
; r
= r
->next
)
4359 if (high
>= r
->low
&& low
<= r
->high
)
4361 /* The new range overlaps r. */
4367 while (*pr
!= NULL
&& (*pr
)->low
<= r
->high
)
4369 struct ieee_range
*n
;
4371 if ((*pr
)->high
> r
->high
)
4372 r
->high
= (*pr
)->high
;
4381 r
= (struct ieee_range
*) xmalloc (sizeof *r
);
4382 memset (r
, 0, sizeof *r
);
4387 /* Store the ranges sorted by address. */
4388 for (pr
= plist
; *pr
!= NULL
; pr
= &(*pr
)->next
)
4389 if ((*pr
)->low
> high
)
4397 /* Start a new range for which we only have the low address. */
4400 ieee_start_range (struct ieee_handle
*info
, bfd_vma low
)
4402 struct ieee_range
*r
;
4404 r
= (struct ieee_range
*) xmalloc (sizeof *r
);
4405 memset (r
, 0, sizeof *r
);
4407 r
->next
= info
->pending_ranges
;
4408 info
->pending_ranges
= r
;
4412 /* Finish a range started by ieee_start_range. */
4415 ieee_end_range (struct ieee_handle
*info
, bfd_vma high
)
4417 struct ieee_range
*r
;
4420 assert (info
->pending_ranges
!= NULL
);
4421 r
= info
->pending_ranges
;
4423 info
->pending_ranges
= r
->next
;
4425 return ieee_add_range (info
, FALSE
, low
, high
);
4428 /* Start defining a type. */
4431 ieee_define_type (struct ieee_handle
*info
, unsigned int size
,
4432 bfd_boolean unsignedp
, bfd_boolean localp
)
4434 return ieee_define_named_type (info
, (const char *) NULL
,
4435 (unsigned int) -1, size
, unsignedp
,
4436 localp
, (struct ieee_buflist
*) NULL
);
4439 /* Start defining a named type. */
4442 ieee_define_named_type (struct ieee_handle
*info
, const char *name
,
4443 unsigned int indx
, unsigned int size
,
4444 bfd_boolean unsignedp
, bfd_boolean localp
,
4445 struct ieee_buflist
*buflist
)
4447 unsigned int type_indx
;
4448 unsigned int name_indx
;
4450 if (indx
!= (unsigned int) -1)
4454 type_indx
= info
->type_indx
;
4458 name_indx
= info
->name_indx
;
4464 /* If we were given a buffer, use it; otherwise, use either the
4465 local or the global type information, and make sure that the type
4466 block is started. */
4467 if (buflist
!= NULL
)
4469 if (! ieee_change_buffer (info
, buflist
))
4474 if (! ieee_buffer_emptyp (&info
->types
))
4476 if (! ieee_change_buffer (info
, &info
->types
))
4481 if (! ieee_change_buffer (info
, &info
->types
)
4482 || ! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
4483 || ! ieee_write_byte (info
, 1)
4484 || ! ieee_write_number (info
, 0)
4485 || ! ieee_write_id (info
, info
->modname
))
4491 if (! ieee_buffer_emptyp (&info
->global_types
))
4493 if (! ieee_change_buffer (info
, &info
->global_types
))
4498 if (! ieee_change_buffer (info
, &info
->global_types
)
4499 || ! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
4500 || ! ieee_write_byte (info
, 2)
4501 || ! ieee_write_number (info
, 0)
4502 || ! ieee_write_id (info
, ""))
4507 /* Push the new type on the type stack, write out an NN record, and
4508 write out the start of a TY record. The caller will then finish
4510 if (! ieee_push_type (info
, type_indx
, size
, unsignedp
, localp
))
4513 return (ieee_write_byte (info
, (int) ieee_nn_record
)
4514 && ieee_write_number (info
, name_indx
)
4515 && ieee_write_id (info
, name
)
4516 && ieee_write_byte (info
, (int) ieee_ty_record_enum
)
4517 && ieee_write_number (info
, type_indx
)
4518 && ieee_write_byte (info
, 0xce)
4519 && ieee_write_number (info
, name_indx
));
4522 /* Get an entry to the list of modified versions of a type. */
4524 static struct ieee_modified_type
*
4525 ieee_get_modified_info (struct ieee_handle
*info
, unsigned int indx
)
4527 if (indx
>= info
->modified_alloc
)
4529 unsigned int nalloc
;
4531 nalloc
= info
->modified_alloc
;
4534 while (indx
>= nalloc
)
4536 info
->modified
= ((struct ieee_modified_type
*)
4537 xrealloc (info
->modified
,
4538 nalloc
* sizeof *info
->modified
));
4539 memset (info
->modified
+ info
->modified_alloc
, 0,
4540 (nalloc
- info
->modified_alloc
) * sizeof *info
->modified
);
4541 info
->modified_alloc
= nalloc
;
4544 return info
->modified
+ indx
;
4547 /* Routines for the hash table mapping names to types. */
4549 /* Initialize an entry in the hash table. */
4551 static struct bfd_hash_entry
*
4552 ieee_name_type_newfunc (struct bfd_hash_entry
*entry
,
4553 struct bfd_hash_table
*table
, const char *string
)
4555 struct ieee_name_type_hash_entry
*ret
=
4556 (struct ieee_name_type_hash_entry
*) entry
;
4558 /* Allocate the structure if it has not already been allocated by a
4561 ret
= ((struct ieee_name_type_hash_entry
*)
4562 bfd_hash_allocate (table
, sizeof *ret
));
4566 /* Call the allocation method of the superclass. */
4567 ret
= ((struct ieee_name_type_hash_entry
*)
4568 bfd_hash_newfunc ((struct bfd_hash_entry
*) ret
, table
, string
));
4571 /* Set local fields. */
4575 return (struct bfd_hash_entry
*) ret
;
4578 /* Look up an entry in the hash table. */
4580 #define ieee_name_type_hash_lookup(table, string, create, copy) \
4581 ((struct ieee_name_type_hash_entry *) \
4582 bfd_hash_lookup (&(table)->root, (string), (create), (copy)))
4584 /* Traverse the hash table. */
4586 #define ieee_name_type_hash_traverse(table, func, info) \
4587 (bfd_hash_traverse \
4589 (bfd_boolean (*) (struct bfd_hash_entry *, void *)) (func), \
4592 /* The general routine to write out IEEE debugging information. */
4595 write_ieee_debugging_info (bfd
*abfd
, void *dhandle
)
4597 struct ieee_handle info
;
4602 memset (&info
, 0, sizeof info
);
4604 info
.type_indx
= 256;
4605 info
.name_indx
= 32;
4607 if (!bfd_hash_table_init (&info
.typedefs
.root
, ieee_name_type_newfunc
,
4608 sizeof (struct ieee_name_type_hash_entry
))
4609 || !bfd_hash_table_init (&info
.tags
.root
, ieee_name_type_newfunc
,
4610 sizeof (struct ieee_name_type_hash_entry
)))
4613 if (! ieee_init_buffer (&info
, &info
.global_types
)
4614 || ! ieee_init_buffer (&info
, &info
.data
)
4615 || ! ieee_init_buffer (&info
, &info
.types
)
4616 || ! ieee_init_buffer (&info
, &info
.vars
)
4617 || ! ieee_init_buffer (&info
, &info
.cxx
)
4618 || ! ieee_init_buffer (&info
, &info
.linenos
)
4619 || ! ieee_init_buffer (&info
, &info
.fntype
)
4620 || ! ieee_init_buffer (&info
, &info
.fnargs
))
4623 if (! debug_write (dhandle
, &ieee_fns
, (void *) &info
))
4626 if (info
.filename
!= NULL
)
4628 if (! ieee_finish_compilation_unit (&info
))
4632 /* Put any undefined tags in the global typedef information. */
4634 ieee_name_type_hash_traverse (&info
.tags
,
4635 ieee_write_undefined_tag
,
4640 /* Prepend the global typedef information to the other data. */
4641 if (! ieee_buffer_emptyp (&info
.global_types
))
4643 /* The HP debugger seems to have a bug in which it ignores the
4644 last entry in the global types, so we add a dummy entry. */
4645 if (! ieee_change_buffer (&info
, &info
.global_types
)
4646 || ! ieee_write_byte (&info
, (int) ieee_nn_record
)
4647 || ! ieee_write_number (&info
, info
.name_indx
)
4648 || ! ieee_write_id (&info
, "")
4649 || ! ieee_write_byte (&info
, (int) ieee_ty_record_enum
)
4650 || ! ieee_write_number (&info
, info
.type_indx
)
4651 || ! ieee_write_byte (&info
, 0xce)
4652 || ! ieee_write_number (&info
, info
.name_indx
)
4653 || ! ieee_write_number (&info
, 'P')
4654 || ! ieee_write_number (&info
, (int) builtin_void
+ 32)
4655 || ! ieee_write_byte (&info
, (int) ieee_be_record_enum
))
4658 if (! ieee_append_buffer (&info
, &info
.global_types
, &info
.data
))
4660 info
.data
= info
.global_types
;
4663 /* Make sure that we have declare BB11 blocks for each range in the
4664 file. They are added to info->vars. */
4666 if (! ieee_init_buffer (&info
, &info
.vars
))
4668 bfd_map_over_sections (abfd
, ieee_add_bb11_blocks
, (void *) &info
);
4671 if (! ieee_buffer_emptyp (&info
.vars
))
4673 if (! ieee_change_buffer (&info
, &info
.vars
)
4674 || ! ieee_write_byte (&info
, (int) ieee_be_record_enum
))
4677 if (! ieee_append_buffer (&info
, &info
.data
, &info
.vars
))
4681 /* Now all the data is in info.data. Write it out to the BFD. We
4682 normally would need to worry about whether all the other sections
4683 are set up yet, but the IEEE backend will handle this particular
4684 case correctly regardless. */
4685 if (ieee_buffer_emptyp (&info
.data
))
4687 /* There is no debugging information. */
4691 s
= bfd_make_section_with_flags (abfd
, ".debug",
4692 SEC_DEBUGGING
| SEC_HAS_CONTENTS
);
4694 err
= "bfd_make_section";
4700 for (b
= info
.data
.head
; b
!= NULL
; b
= b
->next
)
4702 if (! bfd_set_section_size (abfd
, s
, size
))
4703 err
= "bfd_set_section_size";
4710 for (b
= info
.data
.head
; b
!= NULL
; b
= b
->next
)
4712 if (! bfd_set_section_contents (abfd
, s
, b
->buf
, offset
, b
->c
))
4714 err
= "bfd_set_section_contents";
4723 fprintf (stderr
, "%s: %s: %s\n", bfd_get_filename (abfd
), err
,
4724 bfd_errmsg (bfd_get_error ()));
4728 bfd_hash_table_free (&info
.typedefs
.root
);
4729 bfd_hash_table_free (&info
.tags
.root
);
4734 /* Write out information for an undefined tag. This is called via
4735 ieee_name_type_hash_traverse. */
4738 ieee_write_undefined_tag (struct ieee_name_type_hash_entry
*h
, void *p
)
4740 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
4741 struct ieee_name_type
*nt
;
4743 for (nt
= h
->types
; nt
!= NULL
; nt
= nt
->next
)
4745 unsigned int name_indx
;
4748 if (nt
->kind
== DEBUG_KIND_ILLEGAL
)
4751 if (ieee_buffer_emptyp (&info
->global_types
))
4753 if (! ieee_change_buffer (info
, &info
->global_types
)
4754 || ! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
4755 || ! ieee_write_byte (info
, 2)
4756 || ! ieee_write_number (info
, 0)
4757 || ! ieee_write_id (info
, ""))
4765 if (! ieee_change_buffer (info
, &info
->global_types
))
4772 name_indx
= info
->name_indx
;
4774 if (! ieee_write_byte (info
, (int) ieee_nn_record
)
4775 || ! ieee_write_number (info
, name_indx
)
4776 || ! ieee_write_id (info
, nt
->type
.name
)
4777 || ! ieee_write_byte (info
, (int) ieee_ty_record_enum
)
4778 || ! ieee_write_number (info
, nt
->type
.indx
)
4779 || ! ieee_write_byte (info
, 0xce)
4780 || ! ieee_write_number (info
, name_indx
))
4792 case DEBUG_KIND_STRUCT
:
4793 case DEBUG_KIND_CLASS
:
4796 case DEBUG_KIND_UNION
:
4797 case DEBUG_KIND_UNION_CLASS
:
4800 case DEBUG_KIND_ENUM
:
4804 if (! ieee_write_number (info
, code
)
4805 || ! ieee_write_number (info
, 0))
4815 /* Start writing out information for a compilation unit. */
4818 ieee_start_compilation_unit (void *p
, const char *filename
)
4820 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
4821 const char *modname
;
4822 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
4823 const char *backslash
;
4827 if (info
->filename
!= NULL
)
4829 if (! ieee_finish_compilation_unit (info
))
4833 info
->filename
= filename
;
4834 modname
= strrchr (filename
, '/');
4835 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
4836 /* We could have a mixed forward/back slash case. */
4837 backslash
= strrchr (filename
, '\\');
4838 if (modname
== NULL
|| (backslash
!= NULL
&& backslash
> modname
))
4839 modname
= backslash
;
4842 if (modname
!= NULL
)
4844 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
4845 else if (filename
[0] && filename
[1] == ':')
4846 modname
= filename
+ 2;
4851 c
= xstrdup (modname
);
4852 s
= strrchr (c
, '.');
4857 if (! ieee_init_buffer (info
, &info
->types
)
4858 || ! ieee_init_buffer (info
, &info
->vars
)
4859 || ! ieee_init_buffer (info
, &info
->cxx
)
4860 || ! ieee_init_buffer (info
, &info
->linenos
))
4862 info
->ranges
= NULL
;
4864 /* Always include a BB1 and a BB3 block. That is what the output of
4865 the MRI linker seems to look like. */
4866 if (! ieee_change_buffer (info
, &info
->types
)
4867 || ! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
4868 || ! ieee_write_byte (info
, 1)
4869 || ! ieee_write_number (info
, 0)
4870 || ! ieee_write_id (info
, info
->modname
))
4874 if (! ieee_change_buffer (info
, &info
->vars
)
4875 || ! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
4876 || ! ieee_write_byte (info
, 3)
4877 || ! ieee_write_number (info
, 0)
4878 || ! ieee_write_id (info
, info
->modname
))
4884 /* Finish up a compilation unit. */
4887 ieee_finish_compilation_unit (struct ieee_handle
*info
)
4889 struct ieee_range
*r
;
4891 if (! ieee_buffer_emptyp (&info
->types
))
4893 if (! ieee_change_buffer (info
, &info
->types
)
4894 || ! ieee_write_byte (info
, (int) ieee_be_record_enum
))
4898 if (! ieee_buffer_emptyp (&info
->cxx
))
4900 /* Append any C++ information to the global function and
4901 variable information. */
4902 assert (! ieee_buffer_emptyp (&info
->vars
));
4903 if (! ieee_change_buffer (info
, &info
->vars
))
4906 /* We put the pmisc records in a dummy procedure, just as the
4907 MRI compiler does. */
4908 if (! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
4909 || ! ieee_write_byte (info
, 6)
4910 || ! ieee_write_number (info
, 0)
4911 || ! ieee_write_id (info
, "__XRYCPP")
4912 || ! ieee_write_number (info
, 0)
4913 || ! ieee_write_number (info
, 0)
4914 || ! ieee_write_number (info
, info
->highaddr
- 1)
4915 || ! ieee_append_buffer (info
, &info
->vars
, &info
->cxx
)
4916 || ! ieee_change_buffer (info
, &info
->vars
)
4917 || ! ieee_write_byte (info
, (int) ieee_be_record_enum
)
4918 || ! ieee_write_number (info
, info
->highaddr
- 1))
4922 if (! ieee_buffer_emptyp (&info
->vars
))
4924 if (! ieee_change_buffer (info
, &info
->vars
)
4925 || ! ieee_write_byte (info
, (int) ieee_be_record_enum
))
4929 if (info
->pending_lineno_filename
!= NULL
)
4931 /* Force out the pending line number. */
4932 if (! ieee_lineno ((void *) info
, (const char *) NULL
, 0, (bfd_vma
) -1))
4935 if (! ieee_buffer_emptyp (&info
->linenos
))
4937 if (! ieee_change_buffer (info
, &info
->linenos
)
4938 || ! ieee_write_byte (info
, (int) ieee_be_record_enum
))
4940 if (filename_cmp (info
->filename
, info
->lineno_filename
) != 0)
4942 /* We were not in the main file. We just closed the
4943 included line number block, and now we must close the
4944 main line number block. */
4945 if (! ieee_write_byte (info
, (int) ieee_be_record_enum
))
4950 if (! ieee_append_buffer (info
, &info
->data
, &info
->types
)
4951 || ! ieee_append_buffer (info
, &info
->data
, &info
->vars
)
4952 || ! ieee_append_buffer (info
, &info
->data
, &info
->linenos
))
4955 /* Build BB10/BB11 blocks based on the ranges we recorded. */
4956 if (! ieee_change_buffer (info
, &info
->data
))
4959 if (! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
4960 || ! ieee_write_byte (info
, 10)
4961 || ! ieee_write_number (info
, 0)
4962 || ! ieee_write_id (info
, info
->modname
)
4963 || ! ieee_write_id (info
, "")
4964 || ! ieee_write_number (info
, 0)
4965 || ! ieee_write_id (info
, "GNU objcopy"))
4968 for (r
= info
->ranges
; r
!= NULL
; r
= r
->next
)
4977 /* Find the section corresponding to this range. */
4978 for (s
= info
->abfd
->sections
; s
!= NULL
; s
= s
->next
)
4980 if (bfd_get_section_vma (info
->abfd
, s
) <= low
4981 && high
<= (bfd_get_section_vma (info
->abfd
, s
)
4982 + bfd_section_size (info
->abfd
, s
)))
4988 /* Just ignore this range. */
4992 /* Coalesce ranges if it seems reasonable. */
4993 while (r
->next
!= NULL
4994 && high
+ 0x1000 >= r
->next
->low
4996 <= (bfd_get_section_vma (info
->abfd
, s
)
4997 + bfd_section_size (info
->abfd
, s
))))
5003 if ((s
->flags
& SEC_CODE
) != 0)
5005 else if ((s
->flags
& SEC_READONLY
) != 0)
5010 if (! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
5011 || ! ieee_write_byte (info
, 11)
5012 || ! ieee_write_number (info
, 0)
5013 || ! ieee_write_id (info
, "")
5014 || ! ieee_write_number (info
, kind
)
5015 || ! ieee_write_number (info
, s
->index
+ IEEE_SECTION_NUMBER_BASE
)
5016 || ! ieee_write_number (info
, low
)
5017 || ! ieee_write_byte (info
, (int) ieee_be_record_enum
)
5018 || ! ieee_write_number (info
, high
- low
))
5021 /* Add this range to the list of global ranges. */
5022 if (! ieee_add_range (info
, TRUE
, low
, high
))
5026 if (! ieee_write_byte (info
, (int) ieee_be_record_enum
))
5032 /* Add BB11 blocks describing each range that we have not already
5036 ieee_add_bb11_blocks (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*sec
, void *data
)
5038 struct ieee_handle
*info
= (struct ieee_handle
*) data
;
5040 struct ieee_range
*r
;
5042 low
= bfd_get_section_vma (abfd
, sec
);
5043 high
= low
+ bfd_section_size (abfd
, sec
);
5045 /* Find the first range at or after this section. The ranges are
5046 sorted by address. */
5047 for (r
= info
->global_ranges
; r
!= NULL
; r
= r
->next
)
5053 if (r
== NULL
|| r
->low
>= high
)
5055 if (! ieee_add_bb11 (info
, sec
, low
, high
))
5061 && r
->low
- low
> 0x100)
5063 if (! ieee_add_bb11 (info
, sec
, low
, r
->low
))
5075 /* Add a single BB11 block for a range. We add it to info->vars. */
5078 ieee_add_bb11 (struct ieee_handle
*info
, asection
*sec
, bfd_vma low
,
5083 if (! ieee_buffer_emptyp (&info
->vars
))
5085 if (! ieee_change_buffer (info
, &info
->vars
))
5090 const char *filename
, *modname
;
5091 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
5092 const char *backslash
;
5096 /* Start the enclosing BB10 block. */
5097 filename
= bfd_get_filename (info
->abfd
);
5098 modname
= strrchr (filename
, '/');
5099 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
5100 backslash
= strrchr (filename
, '\\');
5101 if (modname
== NULL
|| (backslash
!= NULL
&& backslash
> modname
))
5102 modname
= backslash
;
5105 if (modname
!= NULL
)
5107 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
5108 else if (filename
[0] && filename
[1] == ':')
5109 modname
= filename
+ 2;
5114 c
= xstrdup (modname
);
5115 s
= strrchr (c
, '.');
5119 if (! ieee_change_buffer (info
, &info
->vars
)
5120 || ! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
5121 || ! ieee_write_byte (info
, 10)
5122 || ! ieee_write_number (info
, 0)
5123 || ! ieee_write_id (info
, c
)
5124 || ! ieee_write_id (info
, "")
5125 || ! ieee_write_number (info
, 0)
5126 || ! ieee_write_id (info
, "GNU objcopy"))
5135 if ((sec
->flags
& SEC_CODE
) != 0)
5137 else if ((sec
->flags
& SEC_READONLY
) != 0)
5142 if (! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
5143 || ! ieee_write_byte (info
, 11)
5144 || ! ieee_write_number (info
, 0)
5145 || ! ieee_write_id (info
, "")
5146 || ! ieee_write_number (info
, kind
)
5147 || ! ieee_write_number (info
, sec
->index
+ IEEE_SECTION_NUMBER_BASE
)
5148 || ! ieee_write_number (info
, low
)
5149 || ! ieee_write_byte (info
, (int) ieee_be_record_enum
)
5150 || ! ieee_write_number (info
, high
- low
))
5156 /* Start recording information from a particular source file. This is
5157 used to record which file defined which types, variables, etc. It
5158 is not used for line numbers, since the lineno entry point passes
5159 down the file name anyhow. IEEE debugging information doesn't seem
5160 to store this information anywhere. */
5163 ieee_start_source (void *p ATTRIBUTE_UNUSED
,
5164 const char *filename ATTRIBUTE_UNUSED
)
5169 /* Make an empty type. */
5172 ieee_empty_type (void *p
)
5174 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
5176 return ieee_push_type (info
, (int) builtin_unknown
, 0, FALSE
, FALSE
);
5179 /* Make a void type. */
5182 ieee_void_type (void *p
)
5184 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
5186 return ieee_push_type (info
, (int) builtin_void
, 0, FALSE
, FALSE
);
5189 /* Make an integer type. */
5192 ieee_int_type (void *p
, unsigned int size
, bfd_boolean unsignedp
)
5194 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
5200 indx
= (int) builtin_signed_char
;
5203 indx
= (int) builtin_signed_short_int
;
5206 indx
= (int) builtin_signed_long
;
5209 indx
= (int) builtin_signed_long_long
;
5212 fprintf (stderr
, _("IEEE unsupported integer type size %u\n"), size
);
5219 return ieee_push_type (info
, indx
, size
, unsignedp
, FALSE
);
5222 /* Make a floating point type. */
5225 ieee_float_type (void *p
, unsigned int size
)
5227 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
5233 indx
= (int) builtin_float
;
5236 indx
= (int) builtin_double
;
5239 /* FIXME: This size really depends upon the processor. */
5240 indx
= (int) builtin_long_double
;
5243 indx
= (int) builtin_long_long_double
;
5246 fprintf (stderr
, _("IEEE unsupported float type size %u\n"), size
);
5250 return ieee_push_type (info
, indx
, size
, FALSE
, FALSE
);
5253 /* Make a complex type. */
5256 ieee_complex_type (void *p
, unsigned int size
)
5258 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
5264 if (info
->complex_float_index
!= 0)
5265 return ieee_push_type (info
, info
->complex_float_index
, size
* 2,
5271 /* These cases can be output by gcc -gstabs. Outputting the
5272 wrong type is better than crashing. */
5274 if (info
->complex_double_index
!= 0)
5275 return ieee_push_type (info
, info
->complex_double_index
, size
* 2,
5280 fprintf (stderr
, _("IEEE unsupported complex type size %u\n"), size
);
5284 /* FIXME: I don't know what the string is for. */
5285 if (! ieee_define_type (info
, size
* 2, FALSE
, FALSE
)
5286 || ! ieee_write_number (info
, code
)
5287 || ! ieee_write_id (info
, ""))
5291 info
->complex_float_index
= info
->type_stack
->type
.indx
;
5293 info
->complex_double_index
= info
->type_stack
->type
.indx
;
5298 /* Make a boolean type. IEEE doesn't support these, so we just make
5299 an integer type instead. */
5302 ieee_bool_type (void *p
, unsigned int size
)
5304 return ieee_int_type (p
, size
, TRUE
);
5307 /* Make an enumeration. */
5310 ieee_enum_type (void *p
, const char *tag
, const char **names
,
5311 bfd_signed_vma
*vals
)
5313 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
5314 struct ieee_defined_enum
*e
;
5315 bfd_boolean localp
, simple
;
5320 indx
= (unsigned int) -1;
5321 for (e
= info
->enums
; e
!= NULL
; e
= e
->next
)
5331 || tag
[0] != e
->tag
[0]
5332 || strcmp (tag
, e
->tag
) != 0)
5338 /* This enum tag has been seen but not defined. */
5343 if (names
!= NULL
&& e
->names
!= NULL
)
5345 for (i
= 0; names
[i
] != NULL
&& e
->names
[i
] != NULL
; i
++)
5347 if (names
[i
][0] != e
->names
[i
][0]
5348 || vals
[i
] != e
->vals
[i
]
5349 || strcmp (names
[i
], e
->names
[i
]) != 0)
5354 if ((names
== NULL
&& e
->names
== NULL
)
5358 && e
->names
[i
] == NULL
))
5360 /* We've seen this enum before. */
5361 return ieee_push_type (info
, e
->indx
, 0, TRUE
, FALSE
);
5366 /* We've already seen an enum of the same name, so we must make
5367 sure to output this one locally. */
5373 /* If this is a simple enumeration, in which the values start at 0
5374 and always increment by 1, we can use type E. Otherwise we must
5380 for (i
= 0; names
[i
] != NULL
; i
++)
5390 if (! ieee_define_named_type (info
, tag
, indx
, 0, TRUE
, localp
,
5391 (struct ieee_buflist
*) NULL
)
5392 || ! ieee_write_number (info
, simple
? 'E' : 'N'))
5396 /* FIXME: This is supposed to be the enumeration size, but we
5397 don't store that. */
5398 if (! ieee_write_number (info
, 4))
5403 for (i
= 0; names
[i
] != NULL
; i
++)
5405 if (! ieee_write_id (info
, names
[i
]))
5409 if (! ieee_write_number (info
, vals
[i
]))
5417 if (indx
== (unsigned int) -1)
5419 e
= (struct ieee_defined_enum
*) xmalloc (sizeof *e
);
5420 memset (e
, 0, sizeof *e
);
5421 e
->indx
= info
->type_stack
->type
.indx
;
5424 e
->next
= info
->enums
;
5436 /* Make a pointer type. */
5439 ieee_pointer_type (void *p
)
5441 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
5444 struct ieee_modified_type
*m
= NULL
;
5446 localp
= info
->type_stack
->type
.localp
;
5447 indx
= ieee_pop_type (info
);
5449 /* A pointer to a simple builtin type can be obtained by adding 32.
5450 FIXME: Will this be a short pointer, and will that matter? */
5452 return ieee_push_type (info
, indx
+ 32, 0, TRUE
, FALSE
);
5456 m
= ieee_get_modified_info ((struct ieee_handle
*) p
, indx
);
5460 /* FIXME: The size should depend upon the architecture. */
5462 return ieee_push_type (info
, m
->pointer
, 4, TRUE
, FALSE
);
5465 if (! ieee_define_type (info
, 4, TRUE
, localp
)
5466 || ! ieee_write_number (info
, 'P')
5467 || ! ieee_write_number (info
, indx
))
5471 m
->pointer
= info
->type_stack
->type
.indx
;
5476 /* Make a function type. This will be called for a method, but we
5477 don't want to actually add it to the type table in that case. We
5478 handle this by defining the type in a private buffer, and only
5479 adding that buffer to the typedef block if we are going to use it. */
5482 ieee_function_type (void *p
, int argcount
, bfd_boolean varargs
)
5484 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
5486 unsigned int *args
= NULL
;
5488 unsigned int retindx
;
5489 struct ieee_buflist fndef
;
5490 struct ieee_modified_type
*m
;
5496 args
= (unsigned int *) xmalloc (argcount
* sizeof *args
);
5497 for (i
= argcount
- 1; i
>= 0; i
--)
5499 if (info
->type_stack
->type
.localp
)
5501 args
[i
] = ieee_pop_type (info
);
5504 else if (argcount
< 0)
5507 if (info
->type_stack
->type
.localp
)
5509 retindx
= ieee_pop_type (info
);
5512 if (argcount
< 0 && ! localp
)
5514 m
= ieee_get_modified_info ((struct ieee_handle
*) p
, retindx
);
5518 if (m
->function
> 0)
5519 return ieee_push_type (info
, m
->function
, 0, TRUE
, FALSE
);
5522 /* An attribute of 0x41 means that the frame and push mask are
5524 if (! ieee_init_buffer (info
, &fndef
)
5525 || ! ieee_define_named_type (info
, (const char *) NULL
,
5526 (unsigned int) -1, 0, TRUE
, localp
,
5528 || ! ieee_write_number (info
, 'x')
5529 || ! ieee_write_number (info
, 0x41)
5530 || ! ieee_write_number (info
, 0)
5531 || ! ieee_write_number (info
, 0)
5532 || ! ieee_write_number (info
, retindx
)
5533 || ! ieee_write_number (info
, (bfd_vma
) argcount
+ (varargs
? 1 : 0)))
5540 for (i
= 0; i
< argcount
; i
++)
5541 if (! ieee_write_number (info
, args
[i
]))
5547 /* A varargs function is represented by writing out the last
5548 argument as type void *, although this makes little sense. */
5549 if (! ieee_write_number (info
, (bfd_vma
) builtin_void
+ 32))
5553 if (! ieee_write_number (info
, 0))
5556 /* We wrote the information into fndef, in case we don't need it.
5557 It will be appended to info->types by ieee_pop_type. */
5558 info
->type_stack
->type
.fndef
= fndef
;
5561 m
->function
= info
->type_stack
->type
.indx
;
5566 /* Make a reference type. */
5569 ieee_reference_type (void *p
)
5571 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
5573 /* IEEE appears to record a normal pointer type, and then use a
5574 pmisc record to indicate that it is really a reference. */
5576 if (! ieee_pointer_type (p
))
5578 info
->type_stack
->type
.referencep
= TRUE
;
5582 /* Make a range type. */
5585 ieee_range_type (void *p
, bfd_signed_vma low
, bfd_signed_vma high
)
5587 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
5589 bfd_boolean unsignedp
, localp
;
5591 size
= info
->type_stack
->type
.size
;
5592 unsignedp
= info
->type_stack
->type
.unsignedp
;
5593 localp
= info
->type_stack
->type
.localp
;
5594 ieee_pop_unused_type (info
);
5595 return (ieee_define_type (info
, size
, unsignedp
, localp
)
5596 && ieee_write_number (info
, 'R')
5597 && ieee_write_number (info
, (bfd_vma
) low
)
5598 && ieee_write_number (info
, (bfd_vma
) high
)
5599 && ieee_write_number (info
, unsignedp
? 0 : 1)
5600 && ieee_write_number (info
, size
));
5603 /* Make an array type. */
5606 ieee_array_type (void *p
, bfd_signed_vma low
, bfd_signed_vma high
,
5607 bfd_boolean stringp ATTRIBUTE_UNUSED
)
5609 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
5610 unsigned int eleindx
;
5613 struct ieee_modified_type
*m
= NULL
;
5614 struct ieee_modified_array_type
*a
;
5616 /* IEEE does not store the range, so we just ignore it. */
5617 ieee_pop_unused_type (info
);
5618 localp
= info
->type_stack
->type
.localp
;
5619 size
= info
->type_stack
->type
.size
;
5620 eleindx
= ieee_pop_type (info
);
5622 /* If we don't know the range, treat the size as exactly one
5625 size
*= (high
- low
) + 1;
5629 m
= ieee_get_modified_info (info
, eleindx
);
5633 for (a
= m
->arrays
; a
!= NULL
; a
= a
->next
)
5635 if (a
->low
== low
&& a
->high
== high
)
5636 return ieee_push_type (info
, a
->indx
, size
, FALSE
, FALSE
);
5640 if (! ieee_define_type (info
, size
, FALSE
, localp
)
5641 || ! ieee_write_number (info
, low
== 0 ? 'Z' : 'C')
5642 || ! ieee_write_number (info
, eleindx
))
5646 if (! ieee_write_number (info
, low
))
5650 if (! ieee_write_number (info
, high
+ 1))
5655 a
= (struct ieee_modified_array_type
*) xmalloc (sizeof *a
);
5656 memset (a
, 0, sizeof *a
);
5658 a
->indx
= info
->type_stack
->type
.indx
;
5662 a
->next
= m
->arrays
;
5669 /* Make a set type. */
5672 ieee_set_type (void *p
, bfd_boolean bitstringp ATTRIBUTE_UNUSED
)
5674 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
5676 unsigned int eleindx
;
5678 localp
= info
->type_stack
->type
.localp
;
5679 eleindx
= ieee_pop_type (info
);
5681 /* FIXME: We don't know the size, so we just use 4. */
5683 return (ieee_define_type (info
, 0, TRUE
, localp
)
5684 && ieee_write_number (info
, 's')
5685 && ieee_write_number (info
, 4)
5686 && ieee_write_number (info
, eleindx
));
5689 /* Make an offset type. */
5692 ieee_offset_type (void *p
)
5694 /* FIXME: The MRI C++ compiler does not appear to generate any
5695 useful type information about an offset type. It just records a
5696 pointer to member as an integer. The MRI/HP IEEE spec does
5697 describe a pmisc record which can be used for a pointer to
5698 member. Unfortunately, it does not describe the target type,
5699 which seems pretty important. I'm going to punt this for now. */
5701 return ieee_int_type (p
, 4, TRUE
);
5704 /* Make a method type. */
5707 ieee_method_type (void *p
, bfd_boolean domain
, int argcount
,
5708 bfd_boolean varargs
)
5710 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
5712 /* FIXME: The MRI/HP IEEE spec defines a pmisc record to use for a
5713 method, but the definition is incomplete. We just output an 'x'
5717 ieee_pop_unused_type (info
);
5719 return ieee_function_type (p
, argcount
, varargs
);
5722 /* Make a const qualified type. */
5725 ieee_const_type (void *p
)
5727 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
5729 bfd_boolean unsignedp
, localp
;
5731 struct ieee_modified_type
*m
= NULL
;
5733 size
= info
->type_stack
->type
.size
;
5734 unsignedp
= info
->type_stack
->type
.unsignedp
;
5735 localp
= info
->type_stack
->type
.localp
;
5736 indx
= ieee_pop_type (info
);
5740 m
= ieee_get_modified_info (info
, indx
);
5744 if (m
->const_qualified
> 0)
5745 return ieee_push_type (info
, m
->const_qualified
, size
, unsignedp
,
5749 if (! ieee_define_type (info
, size
, unsignedp
, localp
)
5750 || ! ieee_write_number (info
, 'n')
5751 || ! ieee_write_number (info
, 1)
5752 || ! ieee_write_number (info
, indx
))
5756 m
->const_qualified
= info
->type_stack
->type
.indx
;
5761 /* Make a volatile qualified type. */
5764 ieee_volatile_type (void *p
)
5766 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
5768 bfd_boolean unsignedp
, localp
;
5770 struct ieee_modified_type
*m
= NULL
;
5772 size
= info
->type_stack
->type
.size
;
5773 unsignedp
= info
->type_stack
->type
.unsignedp
;
5774 localp
= info
->type_stack
->type
.localp
;
5775 indx
= ieee_pop_type (info
);
5779 m
= ieee_get_modified_info (info
, indx
);
5783 if (m
->volatile_qualified
> 0)
5784 return ieee_push_type (info
, m
->volatile_qualified
, size
, unsignedp
,
5788 if (! ieee_define_type (info
, size
, unsignedp
, localp
)
5789 || ! ieee_write_number (info
, 'n')
5790 || ! ieee_write_number (info
, 2)
5791 || ! ieee_write_number (info
, indx
))
5795 m
->volatile_qualified
= info
->type_stack
->type
.indx
;
5800 /* Convert an enum debug_visibility into a CXXFLAGS value. */
5803 ieee_vis_to_flags (enum debug_visibility visibility
)
5809 case DEBUG_VISIBILITY_PUBLIC
:
5810 return CXXFLAGS_VISIBILITY_PUBLIC
;
5811 case DEBUG_VISIBILITY_PRIVATE
:
5812 return CXXFLAGS_VISIBILITY_PRIVATE
;
5813 case DEBUG_VISIBILITY_PROTECTED
:
5814 return CXXFLAGS_VISIBILITY_PROTECTED
;
5819 /* Start defining a struct type. We build it in the strdef field on
5820 the stack, to avoid confusing type definitions required by the
5821 fields with the struct type itself. */
5824 ieee_start_struct_type (void *p
, const char *tag
, unsigned int id
,
5825 bfd_boolean structp
, unsigned int size
)
5827 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
5828 bfd_boolean localp
, ignorep
;
5832 struct ieee_name_type_hash_entry
*h
;
5833 struct ieee_name_type
*nt
, *ntlook
;
5834 struct ieee_buflist strdef
;
5839 /* We need to create a tag for internal use even if we don't want
5840 one for external use. This will let us refer to an anonymous
5849 sprintf (ab
, "__anon%u", id
);
5854 /* If we already have references to the tag, we must use the
5855 existing type index. */
5856 h
= ieee_name_type_hash_lookup (&info
->tags
, look
, TRUE
, copy
);
5861 for (ntlook
= h
->types
; ntlook
!= NULL
; ntlook
= ntlook
->next
)
5863 if (ntlook
->id
== id
)
5865 else if (! ntlook
->type
.localp
)
5867 /* We are creating a duplicate definition of a globally
5868 defined tag. Force it to be local to avoid
5876 assert (localp
== nt
->type
.localp
);
5877 if (nt
->kind
== DEBUG_KIND_ILLEGAL
&& ! localp
)
5879 /* We've already seen a global definition of the type.
5880 Ignore this new definition. */
5886 nt
= (struct ieee_name_type
*) xmalloc (sizeof *nt
);
5887 memset (nt
, 0, sizeof *nt
);
5889 nt
->type
.name
= h
->root
.string
;
5890 nt
->next
= h
->types
;
5892 nt
->type
.indx
= info
->type_indx
;
5896 nt
->kind
= DEBUG_KIND_ILLEGAL
;
5898 if (! ieee_init_buffer (info
, &strdef
)
5899 || ! ieee_define_named_type (info
, tag
, nt
->type
.indx
, size
, TRUE
,
5901 || ! ieee_write_number (info
, structp
? 'S' : 'U')
5902 || ! ieee_write_number (info
, size
))
5909 /* We never want nt->type.name to be NULL. We want the rest of
5910 the type to be the object set up on the type stack; it will
5911 have a NULL name if tag is NULL. */
5912 hold
= nt
->type
.name
;
5913 nt
->type
= info
->type_stack
->type
;
5914 nt
->type
.name
= hold
;
5917 info
->type_stack
->type
.name
= tag
;
5918 info
->type_stack
->type
.strdef
= strdef
;
5919 info
->type_stack
->type
.ignorep
= ignorep
;
5924 /* Add a field to a struct. */
5927 ieee_struct_field (void *p
, const char *name
, bfd_vma bitpos
, bfd_vma bitsize
,
5928 enum debug_visibility visibility
)
5930 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
5932 bfd_boolean unsignedp
;
5933 bfd_boolean referencep
;
5938 assert (info
->type_stack
!= NULL
5939 && info
->type_stack
->next
!= NULL
5940 && ! ieee_buffer_emptyp (&info
->type_stack
->next
->type
.strdef
));
5942 /* If we are ignoring this struct definition, just pop and ignore
5944 if (info
->type_stack
->next
->type
.ignorep
)
5946 ieee_pop_unused_type (info
);
5950 size
= info
->type_stack
->type
.size
;
5951 unsignedp
= info
->type_stack
->type
.unsignedp
;
5952 referencep
= info
->type_stack
->type
.referencep
;
5953 localp
= info
->type_stack
->type
.localp
;
5954 indx
= ieee_pop_type (info
);
5957 info
->type_stack
->type
.localp
= TRUE
;
5959 if (info
->type_stack
->type
.classdef
!= NULL
)
5964 /* This is a class. We must add a description of this field to
5965 the class records we are building. */
5967 flags
= ieee_vis_to_flags (visibility
);
5968 nindx
= info
->type_stack
->type
.classdef
->indx
;
5969 if (! ieee_change_buffer (info
,
5970 &info
->type_stack
->type
.classdef
->pmiscbuf
)
5971 || ! ieee_write_asn (info
, nindx
, 'd')
5972 || ! ieee_write_asn (info
, nindx
, flags
)
5973 || ! ieee_write_atn65 (info
, nindx
, name
)
5974 || ! ieee_write_atn65 (info
, nindx
, name
))
5976 info
->type_stack
->type
.classdef
->pmisccount
+= 4;
5980 /* We need to output a record recording that this field is
5981 really of reference type. We put this on the refs field
5982 of classdef, so that it can be appended to the C++
5983 records after the class is defined. */
5985 nindx
= info
->name_indx
;
5988 if (! ieee_change_buffer (info
,
5989 &info
->type_stack
->type
.classdef
->refs
)
5990 || ! ieee_write_byte (info
, (int) ieee_nn_record
)
5991 || ! ieee_write_number (info
, nindx
)
5992 || ! ieee_write_id (info
, "")
5993 || ! ieee_write_2bytes (info
, (int) ieee_atn_record_enum
)
5994 || ! ieee_write_number (info
, nindx
)
5995 || ! ieee_write_number (info
, 0)
5996 || ! ieee_write_number (info
, 62)
5997 || ! ieee_write_number (info
, 80)
5998 || ! ieee_write_number (info
, 4)
5999 || ! ieee_write_asn (info
, nindx
, 'R')
6000 || ! ieee_write_asn (info
, nindx
, 3)
6001 || ! ieee_write_atn65 (info
, nindx
, info
->type_stack
->type
.name
)
6002 || ! ieee_write_atn65 (info
, nindx
, name
))
6007 /* If the bitsize doesn't match the expected size, we need to output
6009 if (size
== 0 || bitsize
== 0 || bitsize
== size
* 8)
6010 offset
= bitpos
/ 8;
6013 if (! ieee_define_type (info
, 0, unsignedp
,
6014 info
->type_stack
->type
.localp
)
6015 || ! ieee_write_number (info
, 'g')
6016 || ! ieee_write_number (info
, unsignedp
? 0 : 1)
6017 || ! ieee_write_number (info
, bitsize
)
6018 || ! ieee_write_number (info
, indx
))
6020 indx
= ieee_pop_type (info
);
6024 /* Switch to the struct we are building in order to output this
6025 field definition. */
6026 return (ieee_change_buffer (info
, &info
->type_stack
->type
.strdef
)
6027 && ieee_write_id (info
, name
)
6028 && ieee_write_number (info
, indx
)
6029 && ieee_write_number (info
, offset
));
6032 /* Finish up a struct type. */
6035 ieee_end_struct_type (void *p
)
6037 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
6038 struct ieee_buflist
*pb
;
6040 assert (info
->type_stack
!= NULL
6041 && ! ieee_buffer_emptyp (&info
->type_stack
->type
.strdef
));
6043 /* If we were ignoring this struct definition because it was a
6044 duplicate definition, just through away whatever bytes we have
6045 accumulated. Leave the type on the stack. */
6046 if (info
->type_stack
->type
.ignorep
)
6049 /* If this is not a duplicate definition of this tag, then localp
6050 will be FALSE, and we can put it in the global type block.
6051 FIXME: We should avoid outputting duplicate definitions which are
6053 if (! info
->type_stack
->type
.localp
)
6055 /* Make sure we have started the global type block. */
6056 if (ieee_buffer_emptyp (&info
->global_types
))
6058 if (! ieee_change_buffer (info
, &info
->global_types
)
6059 || ! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
6060 || ! ieee_write_byte (info
, 2)
6061 || ! ieee_write_number (info
, 0)
6062 || ! ieee_write_id (info
, ""))
6065 pb
= &info
->global_types
;
6069 /* Make sure we have started the types block. */
6070 if (ieee_buffer_emptyp (&info
->types
))
6072 if (! ieee_change_buffer (info
, &info
->types
)
6073 || ! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
6074 || ! ieee_write_byte (info
, 1)
6075 || ! ieee_write_number (info
, 0)
6076 || ! ieee_write_id (info
, info
->modname
))
6082 /* Append the struct definition to the types. */
6083 if (! ieee_append_buffer (info
, pb
, &info
->type_stack
->type
.strdef
)
6084 || ! ieee_init_buffer (info
, &info
->type_stack
->type
.strdef
))
6087 /* Leave the struct on the type stack. */
6092 /* Start a class type. */
6095 ieee_start_class_type (void *p
, const char *tag
, unsigned int id
,
6096 bfd_boolean structp
, unsigned int size
,
6097 bfd_boolean vptr
, bfd_boolean ownvptr
)
6099 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
6101 struct ieee_buflist pmiscbuf
;
6103 struct ieee_type_class
*classdef
;
6105 /* A C++ class is output as a C++ struct along with a set of pmisc
6106 records describing the class. */
6108 /* We need to have a name so that we can associate the struct and
6114 t
= (char *) xmalloc (20);
6115 sprintf (t
, "__anon%u", id
);
6119 /* We can't write out the virtual table information until we have
6120 finished the class, because we don't know the virtual table size.
6121 We get the size from the largest voffset we see. */
6123 if (vptr
&& ! ownvptr
)
6125 vclass
= info
->type_stack
->type
.name
;
6126 assert (vclass
!= NULL
);
6127 /* We don't call ieee_pop_unused_type, since the class should
6129 (void) ieee_pop_type (info
);
6132 if (! ieee_start_struct_type (p
, tag
, id
, structp
, size
))
6135 indx
= info
->name_indx
;
6138 /* We write out pmisc records into the classdef field. We will
6139 write out the pmisc start after we know the number of records we
6141 if (! ieee_init_buffer (info
, &pmiscbuf
)
6142 || ! ieee_change_buffer (info
, &pmiscbuf
)
6143 || ! ieee_write_asn (info
, indx
, 'T')
6144 || ! ieee_write_asn (info
, indx
, structp
? 'o' : 'u')
6145 || ! ieee_write_atn65 (info
, indx
, tag
))
6148 classdef
= (struct ieee_type_class
*) xmalloc (sizeof *classdef
);
6149 memset (classdef
, 0, sizeof *classdef
);
6151 classdef
->indx
= indx
;
6152 classdef
->pmiscbuf
= pmiscbuf
;
6153 classdef
->pmisccount
= 3;
6154 classdef
->vclass
= vclass
;
6155 classdef
->ownvptr
= ownvptr
;
6157 info
->type_stack
->type
.classdef
= classdef
;
6162 /* Add a static member to a class. */
6165 ieee_class_static_member (void *p
, const char *name
, const char *physname
,
6166 enum debug_visibility visibility
)
6168 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
6172 /* We don't care about the type. Hopefully there will be a call to
6173 ieee_variable declaring the physical name and the type, since
6174 that is where an IEEE consumer must get the type. */
6175 ieee_pop_unused_type (info
);
6177 assert (info
->type_stack
!= NULL
6178 && info
->type_stack
->type
.classdef
!= NULL
);
6180 flags
= ieee_vis_to_flags (visibility
);
6181 flags
|= CXXFLAGS_STATIC
;
6183 nindx
= info
->type_stack
->type
.classdef
->indx
;
6185 if (! ieee_change_buffer (info
, &info
->type_stack
->type
.classdef
->pmiscbuf
)
6186 || ! ieee_write_asn (info
, nindx
, 'd')
6187 || ! ieee_write_asn (info
, nindx
, flags
)
6188 || ! ieee_write_atn65 (info
, nindx
, name
)
6189 || ! ieee_write_atn65 (info
, nindx
, physname
))
6191 info
->type_stack
->type
.classdef
->pmisccount
+= 4;
6196 /* Add a base class to a class. */
6199 ieee_class_baseclass (void *p
, bfd_vma bitpos
, bfd_boolean is_virtual
,
6200 enum debug_visibility visibility
)
6202 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
6210 assert (info
->type_stack
!= NULL
6211 && info
->type_stack
->type
.name
!= NULL
6212 && info
->type_stack
->next
!= NULL
6213 && info
->type_stack
->next
->type
.classdef
!= NULL
6214 && ! ieee_buffer_emptyp (&info
->type_stack
->next
->type
.strdef
));
6216 bname
= info
->type_stack
->type
.name
;
6217 localp
= info
->type_stack
->type
.localp
;
6218 bindx
= ieee_pop_type (info
);
6220 /* We are currently defining both a struct and a class. We must
6221 write out a field definition in the struct which holds the base
6222 class. The stabs debugging reader will create a field named
6223 _vb$CLASS for a virtual base class, so we just use that. FIXME:
6224 we should not depend upon a detail of stabs debugging. */
6227 fname
= (char *) xmalloc (strlen (bname
) + sizeof "_vb$");
6228 sprintf (fname
, "_vb$%s", bname
);
6229 flags
= BASEFLAGS_VIRTUAL
;
6234 info
->type_stack
->type
.localp
= TRUE
;
6236 fname
= (char *) xmalloc (strlen (bname
) + sizeof "_b$");
6237 sprintf (fname
, "_b$%s", bname
);
6239 if (! ieee_change_buffer (info
, &info
->type_stack
->type
.strdef
)
6240 || ! ieee_write_id (info
, fname
)
6241 || ! ieee_write_number (info
, bindx
)
6242 || ! ieee_write_number (info
, bitpos
/ 8))
6250 if (visibility
== DEBUG_VISIBILITY_PRIVATE
)
6251 flags
|= BASEFLAGS_PRIVATE
;
6253 nindx
= info
->type_stack
->type
.classdef
->indx
;
6255 if (! ieee_change_buffer (info
, &info
->type_stack
->type
.classdef
->pmiscbuf
)
6256 || ! ieee_write_asn (info
, nindx
, 'b')
6257 || ! ieee_write_asn (info
, nindx
, flags
)
6258 || ! ieee_write_atn65 (info
, nindx
, bname
)
6259 || ! ieee_write_asn (info
, nindx
, 0)
6260 || ! ieee_write_atn65 (info
, nindx
, fname
))
6265 info
->type_stack
->type
.classdef
->pmisccount
+= 5;
6272 /* Start building a method for a class. */
6275 ieee_class_start_method (void *p
, const char *name
)
6277 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
6279 assert (info
->type_stack
!= NULL
6280 && info
->type_stack
->type
.classdef
!= NULL
6281 && info
->type_stack
->type
.classdef
->method
== NULL
);
6283 info
->type_stack
->type
.classdef
->method
= name
;
6288 /* Define a new method variant, either static or not. */
6291 ieee_class_method_var (struct ieee_handle
*info
, const char *physname
,
6292 enum debug_visibility visibility
,
6293 bfd_boolean staticp
, bfd_boolean constp
,
6294 bfd_boolean volatilep
, bfd_vma voffset
,
6295 bfd_boolean context
)
6299 bfd_boolean is_virtual
;
6301 /* We don't need the type of the method. An IEEE consumer which
6302 wants the type must track down the function by the physical name
6303 and get the type from that. */
6304 ieee_pop_unused_type (info
);
6306 /* We don't use the context. FIXME: We probably ought to use it to
6307 adjust the voffset somehow, but I don't really know how. */
6309 ieee_pop_unused_type (info
);
6311 assert (info
->type_stack
!= NULL
6312 && info
->type_stack
->type
.classdef
!= NULL
6313 && info
->type_stack
->type
.classdef
->method
!= NULL
);
6315 flags
= ieee_vis_to_flags (visibility
);
6317 /* FIXME: We never set CXXFLAGS_OVERRIDE, CXXFLAGS_OPERATOR,
6318 CXXFLAGS_CTORDTOR, CXXFLAGS_CTOR, or CXXFLAGS_INLINE. */
6321 flags
|= CXXFLAGS_STATIC
;
6323 flags
|= CXXFLAGS_CONST
;
6325 flags
|= CXXFLAGS_VOLATILE
;
6327 nindx
= info
->type_stack
->type
.classdef
->indx
;
6329 is_virtual
= context
|| voffset
> 0;
6331 if (! ieee_change_buffer (info
,
6332 &info
->type_stack
->type
.classdef
->pmiscbuf
)
6333 || ! ieee_write_asn (info
, nindx
, is_virtual
? 'v' : 'm')
6334 || ! ieee_write_asn (info
, nindx
, flags
)
6335 || ! ieee_write_atn65 (info
, nindx
,
6336 info
->type_stack
->type
.classdef
->method
)
6337 || ! ieee_write_atn65 (info
, nindx
, physname
))
6342 if (voffset
> info
->type_stack
->type
.classdef
->voffset
)
6343 info
->type_stack
->type
.classdef
->voffset
= voffset
;
6344 if (! ieee_write_asn (info
, nindx
, voffset
))
6346 ++info
->type_stack
->type
.classdef
->pmisccount
;
6349 if (! ieee_write_asn (info
, nindx
, 0))
6352 info
->type_stack
->type
.classdef
->pmisccount
+= 5;
6357 /* Define a new method variant. */
6360 ieee_class_method_variant (void *p
, const char *physname
,
6361 enum debug_visibility visibility
,
6362 bfd_boolean constp
, bfd_boolean volatilep
,
6363 bfd_vma voffset
, bfd_boolean context
)
6365 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
6367 return ieee_class_method_var (info
, physname
, visibility
, FALSE
, constp
,
6368 volatilep
, voffset
, context
);
6371 /* Define a new static method variant. */
6374 ieee_class_static_method_variant (void *p
, const char *physname
,
6375 enum debug_visibility visibility
,
6376 bfd_boolean constp
, bfd_boolean volatilep
)
6378 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
6380 return ieee_class_method_var (info
, physname
, visibility
, TRUE
, constp
,
6381 volatilep
, 0, FALSE
);
6384 /* Finish up a method. */
6387 ieee_class_end_method (void *p
)
6389 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
6391 assert (info
->type_stack
!= NULL
6392 && info
->type_stack
->type
.classdef
!= NULL
6393 && info
->type_stack
->type
.classdef
->method
!= NULL
);
6395 info
->type_stack
->type
.classdef
->method
= NULL
;
6400 /* Finish up a class. */
6403 ieee_end_class_type (void *p
)
6405 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
6408 assert (info
->type_stack
!= NULL
6409 && info
->type_stack
->type
.classdef
!= NULL
);
6411 /* If we were ignoring this class definition because it was a
6412 duplicate definition, just through away whatever bytes we have
6413 accumulated. Leave the type on the stack. */
6414 if (info
->type_stack
->type
.ignorep
)
6417 nindx
= info
->type_stack
->type
.classdef
->indx
;
6419 /* If we have a virtual table, we can write out the information now. */
6420 if (info
->type_stack
->type
.classdef
->vclass
!= NULL
6421 || info
->type_stack
->type
.classdef
->ownvptr
)
6423 if (! ieee_change_buffer (info
,
6424 &info
->type_stack
->type
.classdef
->pmiscbuf
)
6425 || ! ieee_write_asn (info
, nindx
, 'z')
6426 || ! ieee_write_atn65 (info
, nindx
, "")
6427 || ! ieee_write_asn (info
, nindx
,
6428 info
->type_stack
->type
.classdef
->voffset
))
6430 if (info
->type_stack
->type
.classdef
->ownvptr
)
6432 if (! ieee_write_atn65 (info
, nindx
, ""))
6437 if (! ieee_write_atn65 (info
, nindx
,
6438 info
->type_stack
->type
.classdef
->vclass
))
6441 if (! ieee_write_asn (info
, nindx
, 0))
6443 info
->type_stack
->type
.classdef
->pmisccount
+= 5;
6446 /* Now that we know the number of pmisc records, we can write out
6447 the atn62 which starts the pmisc records, and append them to the
6450 if (! ieee_change_buffer (info
, &info
->cxx
)
6451 || ! ieee_write_byte (info
, (int) ieee_nn_record
)
6452 || ! ieee_write_number (info
, nindx
)
6453 || ! ieee_write_id (info
, "")
6454 || ! ieee_write_2bytes (info
, (int) ieee_atn_record_enum
)
6455 || ! ieee_write_number (info
, nindx
)
6456 || ! ieee_write_number (info
, 0)
6457 || ! ieee_write_number (info
, 62)
6458 || ! ieee_write_number (info
, 80)
6459 || ! ieee_write_number (info
,
6460 info
->type_stack
->type
.classdef
->pmisccount
))
6463 if (! ieee_append_buffer (info
, &info
->cxx
,
6464 &info
->type_stack
->type
.classdef
->pmiscbuf
))
6466 if (! ieee_buffer_emptyp (&info
->type_stack
->type
.classdef
->refs
))
6468 if (! ieee_append_buffer (info
, &info
->cxx
,
6469 &info
->type_stack
->type
.classdef
->refs
))
6473 return ieee_end_struct_type (p
);
6476 /* Push a previously seen typedef onto the type stack. */
6479 ieee_typedef_type (void *p
, const char *name
)
6481 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
6482 struct ieee_name_type_hash_entry
*h
;
6483 struct ieee_name_type
*nt
;
6485 h
= ieee_name_type_hash_lookup (&info
->typedefs
, name
, FALSE
, FALSE
);
6487 /* h should never be NULL, since that would imply that the generic
6488 debugging code has asked for a typedef which it has not yet
6492 /* We always use the most recently defined type for this name, which
6493 will be the first one on the list. */
6496 if (! ieee_push_type (info
, nt
->type
.indx
, nt
->type
.size
,
6497 nt
->type
.unsignedp
, nt
->type
.localp
))
6500 /* Copy over any other type information we may have. */
6501 info
->type_stack
->type
= nt
->type
;
6506 /* Push a tagged type onto the type stack. */
6509 ieee_tag_type (void *p
, const char *name
, unsigned int id
,
6510 enum debug_type_kind kind
)
6512 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
6516 struct ieee_name_type_hash_entry
*h
;
6517 struct ieee_name_type
*nt
;
6519 if (kind
== DEBUG_KIND_ENUM
)
6521 struct ieee_defined_enum
*e
;
6525 for (e
= info
->enums
; e
!= NULL
; e
= e
->next
)
6526 if (e
->tag
!= NULL
&& strcmp (e
->tag
, name
) == 0)
6527 return ieee_push_type (info
, e
->indx
, 0, TRUE
, FALSE
);
6529 e
= (struct ieee_defined_enum
*) xmalloc (sizeof *e
);
6530 memset (e
, 0, sizeof *e
);
6532 e
->indx
= info
->type_indx
;
6537 e
->next
= info
->enums
;
6540 return ieee_push_type (info
, e
->indx
, 0, TRUE
, FALSE
);
6548 sprintf (ab
, "__anon%u", id
);
6553 h
= ieee_name_type_hash_lookup (&info
->tags
, name
, TRUE
, copy
);
6557 for (nt
= h
->types
; nt
!= NULL
; nt
= nt
->next
)
6561 if (! ieee_push_type (info
, nt
->type
.indx
, nt
->type
.size
,
6562 nt
->type
.unsignedp
, nt
->type
.localp
))
6564 /* Copy over any other type information we may have. */
6565 info
->type_stack
->type
= nt
->type
;
6569 if (! nt
->type
.localp
)
6571 /* This is a duplicate of a global type, so it must be
6577 nt
= (struct ieee_name_type
*) xmalloc (sizeof *nt
);
6578 memset (nt
, 0, sizeof *nt
);
6581 nt
->type
.name
= h
->root
.string
;
6582 nt
->type
.indx
= info
->type_indx
;
6583 nt
->type
.localp
= localp
;
6587 nt
->next
= h
->types
;
6590 if (! ieee_push_type (info
, nt
->type
.indx
, 0, FALSE
, localp
))
6593 info
->type_stack
->type
.name
= h
->root
.string
;
6598 /* Output a typedef. */
6601 ieee_typdef (void *p
, const char *name
)
6603 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
6604 struct ieee_write_type type
;
6608 struct ieee_name_type_hash_entry
*h
;
6609 struct ieee_name_type
*nt
;
6611 type
= info
->type_stack
->type
;
6614 /* If this is a simple builtin type using a builtin name, we don't
6615 want to output the typedef itself. We also want to change the
6616 type index to correspond to the name being used. We recognize
6617 names used in stabs debugging output even if they don't exactly
6618 correspond to the names used for the IEEE builtin types. */
6620 if (indx
<= (unsigned int) builtin_bcd_float
)
6622 switch ((enum builtin_types
) indx
)
6628 if (strcmp (name
, "void") == 0)
6632 case builtin_signed_char
:
6634 if (strcmp (name
, "signed char") == 0)
6636 indx
= (unsigned int) builtin_signed_char
;
6639 else if (strcmp (name
, "char") == 0)
6641 indx
= (unsigned int) builtin_char
;
6646 case builtin_unsigned_char
:
6647 if (strcmp (name
, "unsigned char") == 0)
6651 case builtin_signed_short_int
:
6653 case builtin_short_int
:
6654 case builtin_signed_short
:
6655 if (strcmp (name
, "signed short int") == 0)
6657 indx
= (unsigned int) builtin_signed_short_int
;
6660 else if (strcmp (name
, "short") == 0)
6662 indx
= (unsigned int) builtin_short
;
6665 else if (strcmp (name
, "short int") == 0)
6667 indx
= (unsigned int) builtin_short_int
;
6670 else if (strcmp (name
, "signed short") == 0)
6672 indx
= (unsigned int) builtin_signed_short
;
6677 case builtin_unsigned_short_int
:
6678 case builtin_unsigned_short
:
6679 if (strcmp (name
, "unsigned short int") == 0
6680 || strcmp (name
, "short unsigned int") == 0)
6682 indx
= builtin_unsigned_short_int
;
6685 else if (strcmp (name
, "unsigned short") == 0)
6687 indx
= builtin_unsigned_short
;
6692 case builtin_signed_long
:
6693 case builtin_int
: /* FIXME: Size depends upon architecture. */
6695 if (strcmp (name
, "signed long") == 0)
6697 indx
= builtin_signed_long
;
6700 else if (strcmp (name
, "int") == 0)
6705 else if (strcmp (name
, "long") == 0
6706 || strcmp (name
, "long int") == 0)
6708 indx
= builtin_long
;
6713 case builtin_unsigned_long
:
6714 case builtin_unsigned
: /* FIXME: Size depends upon architecture. */
6715 case builtin_unsigned_int
: /* FIXME: Like builtin_unsigned. */
6716 if (strcmp (name
, "unsigned long") == 0
6717 || strcmp (name
, "long unsigned int") == 0)
6719 indx
= builtin_unsigned_long
;
6722 else if (strcmp (name
, "unsigned") == 0)
6724 indx
= builtin_unsigned
;
6727 else if (strcmp (name
, "unsigned int") == 0)
6729 indx
= builtin_unsigned_int
;
6734 case builtin_signed_long_long
:
6735 if (strcmp (name
, "signed long long") == 0
6736 || strcmp (name
, "long long int") == 0)
6740 case builtin_unsigned_long_long
:
6741 if (strcmp (name
, "unsigned long long") == 0
6742 || strcmp (name
, "long long unsigned int") == 0)
6747 if (strcmp (name
, "float") == 0)
6751 case builtin_double
:
6752 if (strcmp (name
, "double") == 0)
6756 case builtin_long_double
:
6757 if (strcmp (name
, "long double") == 0)
6761 case builtin_long_long_double
:
6762 if (strcmp (name
, "long long double") == 0)
6771 h
= ieee_name_type_hash_lookup (&info
->typedefs
, name
, TRUE
, FALSE
);
6775 /* See if we have already defined this type with this name. */
6776 localp
= type
.localp
;
6777 for (nt
= h
->types
; nt
!= NULL
; nt
= nt
->next
)
6781 /* If this is a global definition, then we don't need to
6782 do anything here. */
6783 if (! nt
->type
.localp
)
6785 ieee_pop_unused_type (info
);
6791 /* This is a duplicate definition, so make this one local. */
6796 /* We need to add a new typedef for this type. */
6798 nt
= (struct ieee_name_type
*) xmalloc (sizeof *nt
);
6799 memset (nt
, 0, sizeof *nt
);
6802 nt
->type
.name
= name
;
6803 nt
->type
.localp
= localp
;
6804 nt
->kind
= DEBUG_KIND_ILLEGAL
;
6806 nt
->next
= h
->types
;
6811 /* This is one of the builtin typedefs, so we don't need to
6812 actually define it. */
6813 ieee_pop_unused_type (info
);
6817 indx
= ieee_pop_type (info
);
6819 if (! ieee_define_named_type (info
, name
, (unsigned int) -1, type
.size
,
6820 type
.unsignedp
, localp
,
6821 (struct ieee_buflist
*) NULL
)
6822 || ! ieee_write_number (info
, 'T')
6823 || ! ieee_write_number (info
, indx
))
6826 /* Remove the type we just added to the type stack. This should not
6827 be ieee_pop_unused_type, since the type is used, we just don't
6829 (void) ieee_pop_type (info
);
6834 /* Output a tag for a type. We don't have to do anything here. */
6837 ieee_tag (void *p
, const char *name ATTRIBUTE_UNUSED
)
6839 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
6841 /* This should not be ieee_pop_unused_type, since we want the type
6843 (void) ieee_pop_type (info
);
6847 /* Output an integer constant. */
6850 ieee_int_constant (void *p ATTRIBUTE_UNUSED
, const char *name ATTRIBUTE_UNUSED
,
6851 bfd_vma val ATTRIBUTE_UNUSED
)
6857 /* Output a floating point constant. */
6860 ieee_float_constant (void *p ATTRIBUTE_UNUSED
,
6861 const char *name ATTRIBUTE_UNUSED
,
6862 double val ATTRIBUTE_UNUSED
)
6868 /* Output a typed constant. */
6871 ieee_typed_constant (void *p
, const char *name ATTRIBUTE_UNUSED
,
6872 bfd_vma val ATTRIBUTE_UNUSED
)
6874 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
6877 ieee_pop_unused_type (info
);
6881 /* Output a variable. */
6884 ieee_variable (void *p
, const char *name
, enum debug_var_kind kind
,
6887 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
6888 unsigned int name_indx
;
6890 bfd_boolean referencep
;
6891 unsigned int type_indx
;
6895 size
= info
->type_stack
->type
.size
;
6896 referencep
= info
->type_stack
->type
.referencep
;
6897 type_indx
= ieee_pop_type (info
);
6899 assert (! ieee_buffer_emptyp (&info
->vars
));
6900 if (! ieee_change_buffer (info
, &info
->vars
))
6903 name_indx
= info
->name_indx
;
6906 /* Write out an NN and an ATN record for this variable. */
6907 if (! ieee_write_byte (info
, (int) ieee_nn_record
)
6908 || ! ieee_write_number (info
, name_indx
)
6909 || ! ieee_write_id (info
, name
)
6910 || ! ieee_write_2bytes (info
, (int) ieee_atn_record_enum
)
6911 || ! ieee_write_number (info
, name_indx
)
6912 || ! ieee_write_number (info
, type_indx
))
6920 if (! ieee_write_number (info
, 8)
6921 || ! ieee_add_range (info
, FALSE
, val
, val
+ size
))
6927 if (! ieee_write_number (info
, 3)
6928 || ! ieee_add_range (info
, FALSE
, val
, val
+ size
))
6933 case DEBUG_LOCAL_STATIC
:
6934 if (! ieee_write_number (info
, 3)
6935 || ! ieee_add_range (info
, FALSE
, val
, val
+ size
))
6941 if (! ieee_write_number (info
, 1)
6942 || ! ieee_write_number (info
, val
))
6947 case DEBUG_REGISTER
:
6948 if (! ieee_write_number (info
, 2)
6949 || ! ieee_write_number (info
,
6950 ieee_genreg_to_regno (info
->abfd
, val
)))
6959 if (! ieee_write_asn (info
, name_indx
, val
))
6963 /* If this is really a reference type, then we just output it with
6964 pointer type, and must now output a C++ record indicating that it
6965 is really reference type. */
6970 nindx
= info
->name_indx
;
6973 /* If this is a global variable, we want to output the misc
6974 record in the C++ misc record block. Otherwise, we want to
6975 output it just after the variable definition, which is where
6976 the current buffer is. */
6979 if (! ieee_change_buffer (info
, &info
->cxx
))
6983 if (! ieee_write_byte (info
, (int) ieee_nn_record
)
6984 || ! ieee_write_number (info
, nindx
)
6985 || ! ieee_write_id (info
, "")
6986 || ! ieee_write_2bytes (info
, (int) ieee_atn_record_enum
)
6987 || ! ieee_write_number (info
, nindx
)
6988 || ! ieee_write_number (info
, 0)
6989 || ! ieee_write_number (info
, 62)
6990 || ! ieee_write_number (info
, 80)
6991 || ! ieee_write_number (info
, 3)
6992 || ! ieee_write_asn (info
, nindx
, 'R')
6993 || ! ieee_write_asn (info
, nindx
, refflag
)
6994 || ! ieee_write_atn65 (info
, nindx
, name
))
7001 /* Start outputting information for a function. */
7004 ieee_start_function (void *p
, const char *name
, bfd_boolean global
)
7006 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
7007 bfd_boolean referencep
;
7008 unsigned int retindx
, typeindx
;
7010 referencep
= info
->type_stack
->type
.referencep
;
7011 retindx
= ieee_pop_type (info
);
7013 /* Besides recording a BB4 or BB6 block, we record the type of the
7014 function in the BB1 typedef block. We can't write out the full
7015 type until we have seen all the parameters, so we accumulate it
7016 in info->fntype and info->fnargs. */
7017 if (! ieee_buffer_emptyp (&info
->fntype
))
7019 /* FIXME: This might happen someday if we support nested
7024 info
->fnname
= name
;
7026 /* An attribute of 0x40 means that the push mask is unknown. */
7027 if (! ieee_define_named_type (info
, name
, (unsigned int) -1, 0, FALSE
, TRUE
,
7029 || ! ieee_write_number (info
, 'x')
7030 || ! ieee_write_number (info
, 0x40)
7031 || ! ieee_write_number (info
, 0)
7032 || ! ieee_write_number (info
, 0)
7033 || ! ieee_write_number (info
, retindx
))
7036 typeindx
= ieee_pop_type (info
);
7038 if (! ieee_init_buffer (info
, &info
->fnargs
))
7040 info
->fnargcount
= 0;
7042 /* If the function return value is actually a reference type, we
7043 must add a record indicating that. */
7048 nindx
= info
->name_indx
;
7050 if (! ieee_change_buffer (info
, &info
->cxx
)
7051 || ! ieee_write_byte (info
, (int) ieee_nn_record
)
7052 || ! ieee_write_number (info
, nindx
)
7053 || ! ieee_write_id (info
, "")
7054 || ! ieee_write_2bytes (info
, (int) ieee_atn_record_enum
)
7055 || ! ieee_write_number (info
, nindx
)
7056 || ! ieee_write_number (info
, 0)
7057 || ! ieee_write_number (info
, 62)
7058 || ! ieee_write_number (info
, 80)
7059 || ! ieee_write_number (info
, 3)
7060 || ! ieee_write_asn (info
, nindx
, 'R')
7061 || ! ieee_write_asn (info
, nindx
, global
? 0 : 1)
7062 || ! ieee_write_atn65 (info
, nindx
, name
))
7066 assert (! ieee_buffer_emptyp (&info
->vars
));
7067 if (! ieee_change_buffer (info
, &info
->vars
))
7070 /* The address is written out as the first block. */
7072 ++info
->block_depth
;
7074 return (ieee_write_byte (info
, (int) ieee_bb_record_enum
)
7075 && ieee_write_byte (info
, global
? 4 : 6)
7076 && ieee_write_number (info
, 0)
7077 && ieee_write_id (info
, name
)
7078 && ieee_write_number (info
, 0)
7079 && ieee_write_number (info
, typeindx
));
7082 /* Add a function parameter. This will normally be called before the
7083 first block, so we postpone them until we see the block. */
7086 ieee_function_parameter (void *p
, const char *name
, enum debug_parm_kind kind
,
7089 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
7090 struct ieee_pending_parm
*m
, **pm
;
7092 assert (info
->block_depth
== 1);
7094 m
= (struct ieee_pending_parm
*) xmalloc (sizeof *m
);
7095 memset (m
, 0, sizeof *m
);
7099 m
->referencep
= info
->type_stack
->type
.referencep
;
7100 m
->type
= ieee_pop_type (info
);
7104 for (pm
= &info
->pending_parms
; *pm
!= NULL
; pm
= &(*pm
)->next
)
7108 /* Add the type to the fnargs list. */
7109 if (! ieee_change_buffer (info
, &info
->fnargs
)
7110 || ! ieee_write_number (info
, m
->type
))
7117 /* Output pending function parameters. */
7120 ieee_output_pending_parms (struct ieee_handle
*info
)
7122 struct ieee_pending_parm
*m
;
7123 unsigned int refcount
;
7126 for (m
= info
->pending_parms
; m
!= NULL
; m
= m
->next
)
7128 enum debug_var_kind vkind
;
7135 case DEBUG_PARM_STACK
:
7136 case DEBUG_PARM_REFERENCE
:
7137 vkind
= DEBUG_LOCAL
;
7139 case DEBUG_PARM_REG
:
7140 case DEBUG_PARM_REF_REG
:
7141 vkind
= DEBUG_REGISTER
;
7145 if (! ieee_push_type (info
, m
->type
, 0, FALSE
, FALSE
))
7147 info
->type_stack
->type
.referencep
= m
->referencep
;
7150 if (! ieee_variable ((void *) info
, m
->name
, vkind
, m
->val
))
7154 /* If there are any reference parameters, we need to output a
7155 miscellaneous record indicating them. */
7158 unsigned int nindx
, varindx
;
7160 /* FIXME: The MRI compiler outputs the demangled function name
7161 here, but we are outputting the mangled name. */
7162 nindx
= info
->name_indx
;
7164 if (! ieee_change_buffer (info
, &info
->vars
)
7165 || ! ieee_write_byte (info
, (int) ieee_nn_record
)
7166 || ! ieee_write_number (info
, nindx
)
7167 || ! ieee_write_id (info
, "")
7168 || ! ieee_write_2bytes (info
, (int) ieee_atn_record_enum
)
7169 || ! ieee_write_number (info
, nindx
)
7170 || ! ieee_write_number (info
, 0)
7171 || ! ieee_write_number (info
, 62)
7172 || ! ieee_write_number (info
, 80)
7173 || ! ieee_write_number (info
, refcount
+ 3)
7174 || ! ieee_write_asn (info
, nindx
, 'B')
7175 || ! ieee_write_atn65 (info
, nindx
, info
->fnname
)
7176 || ! ieee_write_asn (info
, nindx
, 0))
7178 for (m
= info
->pending_parms
, varindx
= 1;
7180 m
= m
->next
, varindx
++)
7184 if (! ieee_write_asn (info
, nindx
, varindx
))
7190 m
= info
->pending_parms
;
7193 struct ieee_pending_parm
*next
;
7200 info
->pending_parms
= NULL
;
7205 /* Start a block. If this is the first block, we output the address
7206 to finish the BB4 or BB6, and then output the function parameters. */
7209 ieee_start_block (void *p
, bfd_vma addr
)
7211 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
7213 if (! ieee_change_buffer (info
, &info
->vars
))
7216 if (info
->block_depth
== 1)
7218 if (! ieee_write_number (info
, addr
)
7219 || ! ieee_output_pending_parms (info
))
7224 if (! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
7225 || ! ieee_write_byte (info
, 6)
7226 || ! ieee_write_number (info
, 0)
7227 || ! ieee_write_id (info
, "")
7228 || ! ieee_write_number (info
, 0)
7229 || ! ieee_write_number (info
, 0)
7230 || ! ieee_write_number (info
, addr
))
7234 if (! ieee_start_range (info
, addr
))
7237 ++info
->block_depth
;
7245 ieee_end_block (void *p
, bfd_vma addr
)
7247 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
7249 /* The address we are given is the end of the block, but IEEE seems
7250 to want to the address of the last byte in the block, so we
7252 if (! ieee_change_buffer (info
, &info
->vars
)
7253 || ! ieee_write_byte (info
, (int) ieee_be_record_enum
)
7254 || ! ieee_write_number (info
, addr
- 1))
7257 if (! ieee_end_range (info
, addr
))
7260 --info
->block_depth
;
7262 if (addr
> info
->highaddr
)
7263 info
->highaddr
= addr
;
7268 /* End a function. */
7271 ieee_end_function (void *p
)
7273 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
7275 assert (info
->block_depth
== 1);
7277 --info
->block_depth
;
7279 /* Now we can finish up fntype, and add it to the typdef section.
7280 At this point, fntype is the 'x' type up to the argument count,
7281 and fnargs is the argument types. We must add the argument
7282 count, and we must add the level. FIXME: We don't record varargs
7283 functions correctly. In fact, stabs debugging does not give us
7284 enough information to do so. */
7285 if (! ieee_change_buffer (info
, &info
->fntype
)
7286 || ! ieee_write_number (info
, info
->fnargcount
)
7287 || ! ieee_change_buffer (info
, &info
->fnargs
)
7288 || ! ieee_write_number (info
, 0))
7291 /* Make sure the typdef block has been started. */
7292 if (ieee_buffer_emptyp (&info
->types
))
7294 if (! ieee_change_buffer (info
, &info
->types
)
7295 || ! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
7296 || ! ieee_write_byte (info
, 1)
7297 || ! ieee_write_number (info
, 0)
7298 || ! ieee_write_id (info
, info
->modname
))
7302 if (! ieee_append_buffer (info
, &info
->types
, &info
->fntype
)
7303 || ! ieee_append_buffer (info
, &info
->types
, &info
->fnargs
))
7306 info
->fnname
= NULL
;
7307 if (! ieee_init_buffer (info
, &info
->fntype
)
7308 || ! ieee_init_buffer (info
, &info
->fnargs
))
7310 info
->fnargcount
= 0;
7315 /* Record line number information. */
7318 ieee_lineno (void *p
, const char *filename
, unsigned long lineno
, bfd_vma addr
)
7320 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
7322 assert (info
->filename
!= NULL
);
7324 /* The HP simulator seems to get confused when more than one line is
7325 listed for the same address, at least if they are in different
7326 files. We handle this by always listing the last line for a
7327 given address, since that seems to be the one that gdb uses. */
7328 if (info
->pending_lineno_filename
!= NULL
7329 && addr
!= info
->pending_lineno_addr
)
7331 /* Make sure we have a line number block. */
7332 if (! ieee_buffer_emptyp (&info
->linenos
))
7334 if (! ieee_change_buffer (info
, &info
->linenos
))
7339 info
->lineno_name_indx
= info
->name_indx
;
7341 if (! ieee_change_buffer (info
, &info
->linenos
)
7342 || ! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
7343 || ! ieee_write_byte (info
, 5)
7344 || ! ieee_write_number (info
, 0)
7345 || ! ieee_write_id (info
, info
->filename
)
7346 || ! ieee_write_byte (info
, (int) ieee_nn_record
)
7347 || ! ieee_write_number (info
, info
->lineno_name_indx
)
7348 || ! ieee_write_id (info
, ""))
7350 info
->lineno_filename
= info
->filename
;
7353 if (filename_cmp (info
->pending_lineno_filename
,
7354 info
->lineno_filename
) != 0)
7356 if (filename_cmp (info
->filename
, info
->lineno_filename
) != 0)
7358 /* We were not in the main file. Close the block for the
7360 if (! ieee_write_byte (info
, (int) ieee_be_record_enum
))
7362 if (filename_cmp (info
->filename
,
7363 info
->pending_lineno_filename
) == 0)
7365 /* We need a new NN record, and we aren't about to
7367 info
->lineno_name_indx
= info
->name_indx
;
7369 if (! ieee_write_byte (info
, (int) ieee_nn_record
)
7370 || ! ieee_write_number (info
, info
->lineno_name_indx
)
7371 || ! ieee_write_id (info
, ""))
7375 if (filename_cmp (info
->filename
,
7376 info
->pending_lineno_filename
) != 0)
7378 /* We are not changing to the main file. Open a block for
7379 the new included file. */
7380 info
->lineno_name_indx
= info
->name_indx
;
7382 if (! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
7383 || ! ieee_write_byte (info
, 5)
7384 || ! ieee_write_number (info
, 0)
7385 || ! ieee_write_id (info
, info
->pending_lineno_filename
)
7386 || ! ieee_write_byte (info
, (int) ieee_nn_record
)
7387 || ! ieee_write_number (info
, info
->lineno_name_indx
)
7388 || ! ieee_write_id (info
, ""))
7391 info
->lineno_filename
= info
->pending_lineno_filename
;
7394 if (! ieee_write_2bytes (info
, (int) ieee_atn_record_enum
)
7395 || ! ieee_write_number (info
, info
->lineno_name_indx
)
7396 || ! ieee_write_number (info
, 0)
7397 || ! ieee_write_number (info
, 7)
7398 || ! ieee_write_number (info
, info
->pending_lineno
)
7399 || ! ieee_write_number (info
, 0)
7400 || ! ieee_write_asn (info
, info
->lineno_name_indx
,
7401 info
->pending_lineno_addr
))
7405 info
->pending_lineno_filename
= filename
;
7406 info
->pending_lineno
= lineno
;
7407 info
->pending_lineno_addr
= addr
;