1 /* ieee.c -- Read and write IEEE-695 debugging information.
2 Copyright 1996, 1998, 1999, 2000, 2001, 2002, 2003
3 Free Software Foundation, Inc.
4 Written by Ian Lance Taylor <ian@cygnus.com>.
6 This file is part of GNU Binutils.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23 /* This file reads and writes IEEE-695 debugging information. */
31 #include "libiberty.h"
34 #include "filenames.h"
36 /* This structure holds an entry on the block stack. */
40 /* The kind of block. */
42 /* The source file name, for a BB5 block. */
44 /* The index of the function type, for a BB4 or BB6 block. */
46 /* TRUE if this function is being skipped. */
50 /* This structure is the block stack. */
52 #define BLOCKSTACK_SIZE (16)
54 struct ieee_blockstack
56 /* The stack pointer. */
57 struct ieee_block
*bsp
;
59 struct ieee_block stack
[BLOCKSTACK_SIZE
];
62 /* This structure holds information for a variable. */
72 /* Slot if we make an indirect type. */
74 /* Kind of variable or function. */
86 /* This structure holds all the variables. */
90 /* Number of slots allocated. */
93 struct ieee_var
*vars
;
96 /* This structure holds information for a type. We need this because
97 we don't want to represent bitfields as real types. */
103 /* Slot if this is type is referenced before it is defined. */
105 /* Slots for arguments if we make indirect types for them. */
106 debug_type
*arg_slots
;
107 /* If this is a bitfield, this is the size in bits. If this is not
108 a bitfield, this is zero. */
109 unsigned long bitsize
;
112 /* This structure holds all the type information. */
116 /* Number of slots allocated. */
119 struct ieee_type
*types
;
121 #define BUILTIN_TYPE_COUNT (60)
122 debug_type builtins
[BUILTIN_TYPE_COUNT
];
125 /* This structure holds a linked last of structs with their tag names,
126 so that we can convert them to C++ classes if necessary. */
131 struct ieee_tag
*next
;
134 /* The type of the tag. */
136 /* The tagged type is an indirect type pointing at this slot. */
138 /* This is an array of slots used when a field type is converted
139 into a indirect type, in case it needs to be later converted into
144 /* This structure holds the information we pass around to the parsing
149 /* The debugging handle. */
153 /* The start of the bytes to be parsed. */
154 const bfd_byte
*bytes
;
155 /* The end of the bytes to be parsed. */
156 const bfd_byte
*pend
;
157 /* The block stack. */
158 struct ieee_blockstack blockstack
;
159 /* Whether we have seen a BB1 or BB2. */
160 bfd_boolean saw_filename
;
162 struct ieee_vars vars
;
163 /* The global variables, after a global typedef block. */
164 struct ieee_vars
*global_vars
;
166 struct ieee_types types
;
167 /* The global types, after a global typedef block. */
168 struct ieee_types
*global_types
;
169 /* The list of tagged structs. */
170 struct ieee_tag
*tags
;
173 /* Basic builtin types, not including the pointers. */
179 builtin_signed_char
= 2,
180 builtin_unsigned_char
= 3,
181 builtin_signed_short_int
= 4,
182 builtin_unsigned_short_int
= 5,
183 builtin_signed_long
= 6,
184 builtin_unsigned_long
= 7,
185 builtin_signed_long_long
= 8,
186 builtin_unsigned_long_long
= 9,
189 builtin_long_double
= 12,
190 builtin_long_long_double
= 13,
191 builtin_quoted_string
= 14,
192 builtin_instruction_address
= 15,
194 builtin_unsigned
= 17,
195 builtin_unsigned_int
= 18,
199 builtin_unsigned_short
= 22,
200 builtin_short_int
= 23,
201 builtin_signed_short
= 24,
202 builtin_bcd_float
= 25
205 /* These are the values found in the derivation flags of a 'b'
206 component record of a 'T' type extension record in a C++ pmisc
207 record. These are bitmasks. */
209 /* Set for a private base class, clear for a public base class.
210 Protected base classes are not supported. */
211 #define BASEFLAGS_PRIVATE (0x1)
212 /* Set for a virtual base class. */
213 #define BASEFLAGS_VIRTUAL (0x2)
214 /* Set for a friend class, clear for a base class. */
215 #define BASEFLAGS_FRIEND (0x10)
217 /* These are the values found in the specs flags of a 'd', 'm', or 'v'
218 component record of a 'T' type extension record in a C++ pmisc
219 record. The same flags are used for a 'M' record in a C++ pmisc
222 /* The lower two bits hold visibility information. */
223 #define CXXFLAGS_VISIBILITY (0x3)
224 /* This value in the lower two bits indicates a public member. */
225 #define CXXFLAGS_VISIBILITY_PUBLIC (0x0)
226 /* This value in the lower two bits indicates a private member. */
227 #define CXXFLAGS_VISIBILITY_PRIVATE (0x1)
228 /* This value in the lower two bits indicates a protected member. */
229 #define CXXFLAGS_VISIBILITY_PROTECTED (0x2)
230 /* Set for a static member. */
231 #define CXXFLAGS_STATIC (0x4)
232 /* Set for a virtual override. */
233 #define CXXFLAGS_OVERRIDE (0x8)
234 /* Set for a friend function. */
235 #define CXXFLAGS_FRIEND (0x10)
236 /* Set for a const function. */
237 #define CXXFLAGS_CONST (0x20)
238 /* Set for a volatile function. */
239 #define CXXFLAGS_VOLATILE (0x40)
240 /* Set for an overloaded function. */
241 #define CXXFLAGS_OVERLOADED (0x80)
242 /* Set for an operator function. */
243 #define CXXFLAGS_OPERATOR (0x100)
244 /* Set for a constructor or destructor. */
245 #define CXXFLAGS_CTORDTOR (0x400)
246 /* Set for a constructor. */
247 #define CXXFLAGS_CTOR (0x200)
248 /* Set for an inline function. */
249 #define CXXFLAGS_INLINE (0x800)
251 /* Local functions. */
253 static void ieee_error (struct ieee_info
*, const bfd_byte
*, const char *);
254 static void ieee_eof (struct ieee_info
*);
255 static char *savestring (const char *, unsigned long);
256 static bfd_boolean ieee_read_number
257 (struct ieee_info
*, const bfd_byte
**, bfd_vma
*);
258 static bfd_boolean ieee_read_optional_number
259 (struct ieee_info
*, const bfd_byte
**, bfd_vma
*, bfd_boolean
*);
260 static bfd_boolean ieee_read_id
261 (struct ieee_info
*, const bfd_byte
**, const char **, unsigned long *);
262 static bfd_boolean ieee_read_optional_id
263 (struct ieee_info
*, const bfd_byte
**, const char **, unsigned long *,
265 static bfd_boolean ieee_read_expression
266 (struct ieee_info
*, const bfd_byte
**, bfd_vma
*);
267 static debug_type ieee_builtin_type
268 (struct ieee_info
*, const bfd_byte
*, unsigned int);
269 static bfd_boolean ieee_alloc_type
270 (struct ieee_info
*, unsigned int, bfd_boolean
);
271 static bfd_boolean ieee_read_type_index
272 (struct ieee_info
*, const bfd_byte
**, debug_type
*);
273 static int ieee_regno_to_genreg (bfd
*, int);
274 static int ieee_genreg_to_regno (bfd
*, int);
275 static bfd_boolean
parse_ieee_bb (struct ieee_info
*, const bfd_byte
**);
276 static bfd_boolean
parse_ieee_be (struct ieee_info
*, const bfd_byte
**);
277 static bfd_boolean
parse_ieee_nn (struct ieee_info
*, const bfd_byte
**);
278 static bfd_boolean
parse_ieee_ty (struct ieee_info
*, const bfd_byte
**);
279 static bfd_boolean
parse_ieee_atn (struct ieee_info
*, const bfd_byte
**);
280 static bfd_boolean ieee_read_cxx_misc
281 (struct ieee_info
*, const bfd_byte
**, unsigned long);
282 static bfd_boolean ieee_read_cxx_class
283 (struct ieee_info
*, const bfd_byte
**, unsigned long);
284 static bfd_boolean ieee_read_cxx_defaults
285 (struct ieee_info
*, const bfd_byte
**, unsigned long);
286 static bfd_boolean ieee_read_reference
287 (struct ieee_info
*, const bfd_byte
**);
288 static bfd_boolean ieee_require_asn
289 (struct ieee_info
*, const bfd_byte
**, bfd_vma
*);
290 static bfd_boolean ieee_require_atn65
291 (struct ieee_info
*, const bfd_byte
**, const char **, unsigned long *);
293 /* Report an error in the IEEE debugging information. */
296 ieee_error (struct ieee_info
*info
, const bfd_byte
*p
, const char *s
)
299 fprintf (stderr
, "%s: 0x%lx: %s (0x%x)\n", bfd_get_filename (info
->abfd
),
300 (unsigned long) (p
- info
->bytes
), s
, *p
);
302 fprintf (stderr
, "%s: %s\n", bfd_get_filename (info
->abfd
), s
);
305 /* Report an unexpected EOF in the IEEE debugging information. */
308 ieee_eof (struct ieee_info
*info
)
310 ieee_error (info
, (const bfd_byte
*) NULL
,
311 _("unexpected end of debugging information"));
314 /* Save a string in memory. */
317 savestring (const char *start
, unsigned long len
)
321 ret
= (char *) xmalloc (len
+ 1);
322 memcpy (ret
, start
, len
);
327 /* Read a number which must be present in an IEEE file. */
330 ieee_read_number (struct ieee_info
*info
, const bfd_byte
**pp
, bfd_vma
*pv
)
332 return ieee_read_optional_number (info
, pp
, pv
, (bfd_boolean
*) NULL
);
335 /* Read a number in an IEEE file. If ppresent is not NULL, the number
336 need not be there. */
339 ieee_read_optional_number (struct ieee_info
*info
, const bfd_byte
**pp
,
340 bfd_vma
*pv
, bfd_boolean
*ppresent
)
342 ieee_record_enum_type b
;
344 if (*pp
>= info
->pend
)
346 if (ppresent
!= NULL
)
355 b
= (ieee_record_enum_type
) **pp
;
358 if (b
<= ieee_number_end_enum
)
361 if (ppresent
!= NULL
)
366 if (b
>= ieee_number_repeat_start_enum
&& b
<= ieee_number_repeat_end_enum
)
370 i
= (int) b
- (int) ieee_number_repeat_start_enum
;
371 if (*pp
+ i
- 1 >= info
->pend
)
385 if (ppresent
!= NULL
)
391 if (ppresent
!= NULL
)
398 ieee_error (info
, *pp
- 1, _("invalid number"));
402 /* Read a required string from an IEEE file. */
405 ieee_read_id (struct ieee_info
*info
, const bfd_byte
**pp
,
406 const char **pname
, unsigned long *pnamlen
)
408 return ieee_read_optional_id (info
, pp
, pname
, pnamlen
, (bfd_boolean
*) NULL
);
411 /* Read a string from an IEEE file. If ppresent is not NULL, the
412 string is optional. */
415 ieee_read_optional_id (struct ieee_info
*info
, const bfd_byte
**pp
,
416 const char **pname
, unsigned long *pnamlen
,
417 bfd_boolean
*ppresent
)
422 if (*pp
>= info
->pend
)
433 else if ((ieee_record_enum_type
) b
== ieee_extension_length_1_enum
)
438 else if ((ieee_record_enum_type
) b
== ieee_extension_length_2_enum
)
440 len
= (**pp
<< 8) + (*pp
)[1];
445 if (ppresent
!= NULL
)
451 ieee_error (info
, *pp
- 1, _("invalid string length"));
455 if ((unsigned long) (info
->pend
- *pp
) < len
)
461 *pname
= (const char *) *pp
;
465 if (ppresent
!= NULL
)
471 /* Read an expression from an IEEE file. Since this code is only used
472 to parse debugging information, I haven't bothered to write a full
473 blown IEEE expression parser. I've only thrown in the things I've
474 seen in debugging information. This can be easily extended if
478 ieee_read_expression (struct ieee_info
*info
, const bfd_byte
**pp
,
481 const bfd_byte
*expr_start
;
482 #define EXPR_STACK_SIZE (10)
483 bfd_vma expr_stack
[EXPR_STACK_SIZE
];
492 const bfd_byte
*start
;
495 ieee_record_enum_type c
;
499 if (! ieee_read_optional_number (info
, pp
, &val
, &present
))
504 if (esp
- expr_stack
>= EXPR_STACK_SIZE
)
506 ieee_error (info
, start
, _("expression stack overflow"));
513 c
= (ieee_record_enum_type
) **pp
;
515 if (c
>= ieee_module_beginning_enum
)
526 ieee_error (info
, start
, _("unsupported IEEE expression operator"));
529 case ieee_variable_R_enum
:
534 if (! ieee_read_number (info
, pp
, &indx
))
536 for (s
= info
->abfd
->sections
; s
!= NULL
; s
= s
->next
)
537 if ((bfd_vma
) s
->target_index
== indx
)
541 ieee_error (info
, start
, _("unknown section"));
545 if (esp
- expr_stack
>= EXPR_STACK_SIZE
)
547 ieee_error (info
, start
, _("expression stack overflow"));
551 *esp
++ = bfd_get_section_vma (info
->abfd
, s
);
555 case ieee_function_plus_enum
:
556 case ieee_function_minus_enum
:
560 if (esp
- expr_stack
< 2)
562 ieee_error (info
, start
, _("expression stack underflow"));
574 if (esp
- 1 != expr_stack
)
576 ieee_error (info
, expr_start
, _("expression stack mismatch"));
585 /* Return an IEEE builtin type. */
588 ieee_builtin_type (struct ieee_info
*info
, const bfd_byte
*p
,
595 if (indx
< BUILTIN_TYPE_COUNT
596 && info
->types
.builtins
[indx
] != DEBUG_TYPE_NULL
)
597 return info
->types
.builtins
[indx
];
599 dhandle
= info
->dhandle
;
601 if (indx
>= 32 && indx
< 64)
603 type
= debug_make_pointer_type (dhandle
,
604 ieee_builtin_type (info
, p
, indx
- 32));
605 assert (indx
< BUILTIN_TYPE_COUNT
);
606 info
->types
.builtins
[indx
] = type
;
610 switch ((enum builtin_types
) indx
)
613 ieee_error (info
, p
, _("unknown builtin type"));
616 case builtin_unknown
:
617 type
= debug_make_void_type (dhandle
);
622 type
= debug_make_void_type (dhandle
);
626 case builtin_signed_char
:
627 type
= debug_make_int_type (dhandle
, 1, FALSE
);
628 name
= "signed char";
631 case builtin_unsigned_char
:
632 type
= debug_make_int_type (dhandle
, 1, TRUE
);
633 name
= "unsigned char";
636 case builtin_signed_short_int
:
637 type
= debug_make_int_type (dhandle
, 2, FALSE
);
638 name
= "signed short int";
641 case builtin_unsigned_short_int
:
642 type
= debug_make_int_type (dhandle
, 2, TRUE
);
643 name
= "unsigned short int";
646 case builtin_signed_long
:
647 type
= debug_make_int_type (dhandle
, 4, FALSE
);
648 name
= "signed long";
651 case builtin_unsigned_long
:
652 type
= debug_make_int_type (dhandle
, 4, TRUE
);
653 name
= "unsigned long";
656 case builtin_signed_long_long
:
657 type
= debug_make_int_type (dhandle
, 8, FALSE
);
658 name
= "signed long long";
661 case builtin_unsigned_long_long
:
662 type
= debug_make_int_type (dhandle
, 8, TRUE
);
663 name
= "unsigned long long";
667 type
= debug_make_float_type (dhandle
, 4);
672 type
= debug_make_float_type (dhandle
, 8);
676 case builtin_long_double
:
677 /* FIXME: The size for this type should depend upon the
679 type
= debug_make_float_type (dhandle
, 12);
680 name
= "long double";
683 case builtin_long_long_double
:
684 type
= debug_make_float_type (dhandle
, 16);
685 name
= "long long double";
688 case builtin_quoted_string
:
689 type
= debug_make_array_type (dhandle
,
690 ieee_builtin_type (info
, p
,
693 ieee_builtin_type (info
, p
,
697 name
= "QUOTED STRING";
700 case builtin_instruction_address
:
701 /* FIXME: This should be a code address. */
702 type
= debug_make_int_type (dhandle
, 4, TRUE
);
703 name
= "instruction address";
707 /* FIXME: The size for this type should depend upon the
709 type
= debug_make_int_type (dhandle
, 4, FALSE
);
713 case builtin_unsigned
:
714 /* FIXME: The size for this type should depend upon the
716 type
= debug_make_int_type (dhandle
, 4, TRUE
);
720 case builtin_unsigned_int
:
721 /* FIXME: The size for this type should depend upon the
723 type
= debug_make_int_type (dhandle
, 4, TRUE
);
724 name
= "unsigned int";
728 type
= debug_make_int_type (dhandle
, 1, FALSE
);
733 type
= debug_make_int_type (dhandle
, 4, FALSE
);
738 type
= debug_make_int_type (dhandle
, 2, FALSE
);
742 case builtin_unsigned_short
:
743 type
= debug_make_int_type (dhandle
, 2, TRUE
);
744 name
= "unsigned short";
747 case builtin_short_int
:
748 type
= debug_make_int_type (dhandle
, 2, FALSE
);
752 case builtin_signed_short
:
753 type
= debug_make_int_type (dhandle
, 2, FALSE
);
754 name
= "signed short";
757 case builtin_bcd_float
:
758 ieee_error (info
, p
, _("BCD float type not supported"));
759 return DEBUG_TYPE_NULL
;
763 type
= debug_name_type (dhandle
, name
, type
);
765 assert (indx
< BUILTIN_TYPE_COUNT
);
767 info
->types
.builtins
[indx
] = type
;
772 /* Allocate more space in the type table. If ref is TRUE, this is a
773 reference to the type; if it is not already defined, we should set
774 up an indirect type. */
777 ieee_alloc_type (struct ieee_info
*info
, unsigned int indx
, bfd_boolean ref
)
780 register struct ieee_type
*t
;
781 struct ieee_type
*tend
;
783 if (indx
>= info
->types
.alloc
)
785 nalloc
= info
->types
.alloc
;
788 while (indx
>= nalloc
)
791 info
->types
.types
= ((struct ieee_type
*)
792 xrealloc (info
->types
.types
,
793 nalloc
* sizeof *info
->types
.types
));
795 memset (info
->types
.types
+ info
->types
.alloc
, 0,
796 (nalloc
- info
->types
.alloc
) * sizeof *info
->types
.types
);
798 tend
= info
->types
.types
+ nalloc
;
799 for (t
= info
->types
.types
+ info
->types
.alloc
; t
< tend
; t
++)
800 t
->type
= DEBUG_TYPE_NULL
;
802 info
->types
.alloc
= nalloc
;
807 t
= info
->types
.types
+ indx
;
810 t
->pslot
= (debug_type
*) xmalloc (sizeof *t
->pslot
);
811 *t
->pslot
= DEBUG_TYPE_NULL
;
812 t
->type
= debug_make_indirect_type (info
->dhandle
, t
->pslot
,
813 (const char *) NULL
);
822 /* Read a type index and return the corresponding type. */
825 ieee_read_type_index (struct ieee_info
*info
, const bfd_byte
**pp
,
828 const bfd_byte
*start
;
833 if (! ieee_read_number (info
, pp
, &indx
))
838 *ptype
= ieee_builtin_type (info
, start
, indx
);
845 if (! ieee_alloc_type (info
, indx
, TRUE
))
848 *ptype
= info
->types
.types
[indx
].type
;
853 /* Parse IEEE debugging information for a file. This is passed the
854 bytes which compose the Debug Information Part of an IEEE file. */
857 parse_ieee (void *dhandle
, bfd
*abfd
, const bfd_byte
*bytes
, bfd_size_type len
)
859 struct ieee_info info
;
861 const bfd_byte
*p
, *pend
;
863 info
.dhandle
= dhandle
;
866 info
.pend
= bytes
+ len
;
867 info
.blockstack
.bsp
= info
.blockstack
.stack
;
868 info
.saw_filename
= FALSE
;
870 info
.vars
.vars
= NULL
;
871 info
.global_vars
= NULL
;
872 info
.types
.alloc
= 0;
873 info
.types
.types
= NULL
;
874 info
.global_types
= NULL
;
876 for (i
= 0; i
< BUILTIN_TYPE_COUNT
; i
++)
877 info
.types
.builtins
[i
] = DEBUG_TYPE_NULL
;
883 const bfd_byte
*record_start
;
884 ieee_record_enum_type c
;
888 c
= (ieee_record_enum_type
) *p
++;
890 if (c
== ieee_at_record_enum
)
891 c
= (ieee_record_enum_type
) (((unsigned int) c
<< 8) | *p
++);
893 if (c
<= ieee_number_repeat_end_enum
)
895 ieee_error (&info
, record_start
, _("unexpected number"));
902 ieee_error (&info
, record_start
, _("unexpected record type"));
905 case ieee_bb_record_enum
:
906 if (! parse_ieee_bb (&info
, &p
))
910 case ieee_be_record_enum
:
911 if (! parse_ieee_be (&info
, &p
))
916 if (! parse_ieee_nn (&info
, &p
))
920 case ieee_ty_record_enum
:
921 if (! parse_ieee_ty (&info
, &p
))
925 case ieee_atn_record_enum
:
926 if (! parse_ieee_atn (&info
, &p
))
932 if (info
.blockstack
.bsp
!= info
.blockstack
.stack
)
934 ieee_error (&info
, (const bfd_byte
*) NULL
,
935 _("blocks left on stack at end"));
942 /* Handle an IEEE BB record. */
945 parse_ieee_bb (struct ieee_info
*info
, const bfd_byte
**pp
)
947 const bfd_byte
*block_start
;
951 unsigned long namlen
;
952 char *namcopy
= NULL
;
961 if (! ieee_read_number (info
, pp
, &size
)
962 || ! ieee_read_id (info
, pp
, &name
, &namlen
))
965 fnindx
= (unsigned int) -1;
971 /* BB1: Type definitions local to a module. */
972 namcopy
= savestring (name
, namlen
);
975 if (! debug_set_filename (info
->dhandle
, namcopy
))
977 info
->saw_filename
= TRUE
;
979 /* Discard any variables or types we may have seen before. */
980 if (info
->vars
.vars
!= NULL
)
981 free (info
->vars
.vars
);
982 info
->vars
.vars
= NULL
;
983 info
->vars
.alloc
= 0;
984 if (info
->types
.types
!= NULL
)
985 free (info
->types
.types
);
986 info
->types
.types
= NULL
;
987 info
->types
.alloc
= 0;
989 /* Initialize the types to the global types. */
990 if (info
->global_types
!= NULL
)
992 info
->types
.alloc
= info
->global_types
->alloc
;
993 info
->types
.types
= ((struct ieee_type
*)
994 xmalloc (info
->types
.alloc
995 * sizeof (*info
->types
.types
)));
996 memcpy (info
->types
.types
, info
->global_types
->types
,
997 info
->types
.alloc
* sizeof (*info
->types
.types
));
1003 /* BB2: Global type definitions. The name is supposed to be
1004 empty, but we don't check. */
1005 if (! debug_set_filename (info
->dhandle
, "*global*"))
1007 info
->saw_filename
= TRUE
;
1011 /* BB3: High level module block begin. We don't have to do
1012 anything here. The name is supposed to be the same as for
1013 the BB1, but we don't check. */
1017 /* BB4: Global function. */
1019 bfd_vma stackspace
, typindx
, offset
;
1020 debug_type return_type
;
1022 if (! ieee_read_number (info
, pp
, &stackspace
)
1023 || ! ieee_read_number (info
, pp
, &typindx
)
1024 || ! ieee_read_expression (info
, pp
, &offset
))
1027 /* We have no way to record the stack space. FIXME. */
1031 return_type
= ieee_builtin_type (info
, block_start
, typindx
);
1032 if (return_type
== DEBUG_TYPE_NULL
)
1038 if (! ieee_alloc_type (info
, typindx
, TRUE
))
1041 return_type
= info
->types
.types
[typindx
].type
;
1042 if (debug_get_type_kind (info
->dhandle
, return_type
)
1043 == DEBUG_KIND_FUNCTION
)
1044 return_type
= debug_get_return_type (info
->dhandle
,
1048 namcopy
= savestring (name
, namlen
);
1049 if (namcopy
== NULL
)
1051 if (! debug_record_function (info
->dhandle
, namcopy
, return_type
,
1058 /* BB5: File name for source line numbers. */
1062 /* We ignore the date and time. FIXME. */
1063 for (i
= 0; i
< 6; i
++)
1066 bfd_boolean present
;
1068 if (! ieee_read_optional_number (info
, pp
, &ignore
, &present
))
1074 namcopy
= savestring (name
, namlen
);
1075 if (namcopy
== NULL
)
1077 if (! debug_start_source (info
->dhandle
, namcopy
))
1083 /* BB6: Local function or block. */
1085 bfd_vma stackspace
, typindx
, offset
;
1087 if (! ieee_read_number (info
, pp
, &stackspace
)
1088 || ! ieee_read_number (info
, pp
, &typindx
)
1089 || ! ieee_read_expression (info
, pp
, &offset
))
1092 /* We have no way to record the stack space. FIXME. */
1096 if (! debug_start_block (info
->dhandle
, offset
))
1098 /* Change b to indicate that this is a block
1099 rather than a function. */
1104 /* The MRI C++ compiler will output a fake function named
1105 __XRYCPP to hold C++ debugging information. We skip
1106 that function. This is not crucial, but it makes
1107 converting from IEEE to other debug formats work
1109 if (strncmp (name
, "__XRYCPP", namlen
) == 0)
1113 debug_type return_type
;
1117 return_type
= ieee_builtin_type (info
, block_start
,
1119 if (return_type
== NULL
)
1125 if (! ieee_alloc_type (info
, typindx
, TRUE
))
1128 return_type
= info
->types
.types
[typindx
].type
;
1129 if (debug_get_type_kind (info
->dhandle
, return_type
)
1130 == DEBUG_KIND_FUNCTION
)
1131 return_type
= debug_get_return_type (info
->dhandle
,
1135 namcopy
= savestring (name
, namlen
);
1136 if (namcopy
== NULL
)
1138 if (! debug_record_function (info
->dhandle
, namcopy
,
1139 return_type
, FALSE
, offset
))
1147 /* BB10: Assembler module scope. In the normal case, we
1148 completely ignore all this information. FIXME. */
1150 const char *inam
, *vstr
;
1151 unsigned long inamlen
, vstrlen
;
1153 bfd_boolean present
;
1156 if (! info
->saw_filename
)
1158 namcopy
= savestring (name
, namlen
);
1159 if (namcopy
== NULL
)
1161 if (! debug_set_filename (info
->dhandle
, namcopy
))
1163 info
->saw_filename
= TRUE
;
1166 if (! ieee_read_id (info
, pp
, &inam
, &inamlen
)
1167 || ! ieee_read_number (info
, pp
, &tool_type
)
1168 || ! ieee_read_optional_id (info
, pp
, &vstr
, &vstrlen
, &present
))
1170 for (i
= 0; i
< 6; i
++)
1174 if (! ieee_read_optional_number (info
, pp
, &ignore
, &present
))
1183 /* BB11: Module section. We completely ignore all this
1184 information. FIXME. */
1186 bfd_vma sectype
, secindx
, offset
, map
;
1187 bfd_boolean present
;
1189 if (! ieee_read_number (info
, pp
, §ype
)
1190 || ! ieee_read_number (info
, pp
, &secindx
)
1191 || ! ieee_read_expression (info
, pp
, &offset
)
1192 || ! ieee_read_optional_number (info
, pp
, &map
, &present
))
1198 ieee_error (info
, block_start
, _("unknown BB type"));
1203 /* Push this block on the block stack. */
1205 if (info
->blockstack
.bsp
>= info
->blockstack
.stack
+ BLOCKSTACK_SIZE
)
1207 ieee_error (info
, (const bfd_byte
*) NULL
, _("stack overflow"));
1211 info
->blockstack
.bsp
->kind
= b
;
1213 info
->blockstack
.bsp
->filename
= namcopy
;
1214 info
->blockstack
.bsp
->fnindx
= fnindx
;
1215 info
->blockstack
.bsp
->skip
= skip
;
1216 ++info
->blockstack
.bsp
;
1221 /* Handle an IEEE BE record. */
1224 parse_ieee_be (struct ieee_info
*info
, const bfd_byte
**pp
)
1228 if (info
->blockstack
.bsp
<= info
->blockstack
.stack
)
1230 ieee_error (info
, *pp
, _("stack underflow"));
1233 --info
->blockstack
.bsp
;
1235 switch (info
->blockstack
.bsp
->kind
)
1238 /* When we end the global typedefs block, we copy out the
1239 contents of info->vars. This is because the variable indices
1240 may be reused in the local blocks. However, we need to
1241 preserve them so that we can locate a function returning a
1242 reference variable whose type is named in the global typedef
1244 info
->global_vars
= ((struct ieee_vars
*)
1245 xmalloc (sizeof *info
->global_vars
));
1246 info
->global_vars
->alloc
= info
->vars
.alloc
;
1247 info
->global_vars
->vars
= ((struct ieee_var
*)
1248 xmalloc (info
->vars
.alloc
1249 * sizeof (*info
->vars
.vars
)));
1250 memcpy (info
->global_vars
->vars
, info
->vars
.vars
,
1251 info
->vars
.alloc
* sizeof (*info
->vars
.vars
));
1253 /* We also copy out the non builtin parts of info->types, since
1254 the types are discarded when we start a new block. */
1255 info
->global_types
= ((struct ieee_types
*)
1256 xmalloc (sizeof *info
->global_types
));
1257 info
->global_types
->alloc
= info
->types
.alloc
;
1258 info
->global_types
->types
= ((struct ieee_type
*)
1259 xmalloc (info
->types
.alloc
1260 * sizeof (*info
->types
.types
)));
1261 memcpy (info
->global_types
->types
, info
->types
.types
,
1262 info
->types
.alloc
* sizeof (*info
->types
.types
));
1263 memset (info
->global_types
->builtins
, 0,
1264 sizeof (info
->global_types
->builtins
));
1270 if (! ieee_read_expression (info
, pp
, &offset
))
1272 if (! info
->blockstack
.bsp
->skip
)
1274 if (! debug_end_function (info
->dhandle
, offset
+ 1))
1280 /* This is BE6 when BB6 started a block rather than a local
1282 if (! ieee_read_expression (info
, pp
, &offset
))
1284 if (! debug_end_block (info
->dhandle
, offset
+ 1))
1289 /* When we end a BB5, we look up the stack for the last BB5, if
1290 there is one, so that we can call debug_start_source. */
1291 if (info
->blockstack
.bsp
> info
->blockstack
.stack
)
1293 struct ieee_block
*bl
;
1295 bl
= info
->blockstack
.bsp
;
1301 if (! debug_start_source (info
->dhandle
, bl
->filename
))
1306 while (bl
!= info
->blockstack
.stack
);
1311 if (! ieee_read_expression (info
, pp
, &offset
))
1313 /* We just ignore the module size. FIXME. */
1317 /* Other block types do not have any trailing information. */
1324 /* Parse an NN record. */
1327 parse_ieee_nn (struct ieee_info
*info
, const bfd_byte
**pp
)
1329 const bfd_byte
*nn_start
;
1332 unsigned long namlen
;
1336 if (! ieee_read_number (info
, pp
, &varindx
)
1337 || ! ieee_read_id (info
, pp
, &name
, &namlen
))
1342 ieee_error (info
, nn_start
, _("illegal variable index"));
1347 if (varindx
>= info
->vars
.alloc
)
1351 alloc
= info
->vars
.alloc
;
1354 while (varindx
>= alloc
)
1356 info
->vars
.vars
= ((struct ieee_var
*)
1357 xrealloc (info
->vars
.vars
,
1358 alloc
* sizeof *info
->vars
.vars
));
1359 memset (info
->vars
.vars
+ info
->vars
.alloc
, 0,
1360 (alloc
- info
->vars
.alloc
) * sizeof *info
->vars
.vars
);
1361 info
->vars
.alloc
= alloc
;
1364 info
->vars
.vars
[varindx
].name
= name
;
1365 info
->vars
.vars
[varindx
].namlen
= namlen
;
1370 /* Parse a TY record. */
1373 parse_ieee_ty (struct ieee_info
*info
, const bfd_byte
**pp
)
1375 const bfd_byte
*ty_start
, *ty_var_start
, *ty_code_start
;
1376 bfd_vma typeindx
, varindx
, tc
;
1378 bfd_boolean tag
, typdef
;
1379 debug_type
*arg_slots
;
1380 unsigned long type_bitsize
;
1385 if (! ieee_read_number (info
, pp
, &typeindx
))
1390 ieee_error (info
, ty_start
, _("illegal type index"));
1395 if (! ieee_alloc_type (info
, typeindx
, FALSE
))
1400 ieee_error (info
, *pp
, _("unknown TY code"));
1407 if (! ieee_read_number (info
, pp
, &varindx
))
1412 ieee_error (info
, ty_var_start
, _("illegal variable index"));
1417 if (varindx
>= info
->vars
.alloc
|| info
->vars
.vars
[varindx
].name
== NULL
)
1419 ieee_error (info
, ty_var_start
, _("undefined variable in TY"));
1423 ty_code_start
= *pp
;
1425 if (! ieee_read_number (info
, pp
, &tc
))
1428 dhandle
= info
->dhandle
;
1437 ieee_error (info
, ty_code_start
, _("unknown TY code"));
1441 /* Unknown type, with size. We treat it as int. FIXME. */
1445 if (! ieee_read_number (info
, pp
, &size
))
1447 type
= debug_make_int_type (dhandle
, size
, FALSE
);
1451 case 'A': /* Array. */
1452 case 'a': /* FORTRAN array in column/row order. FIXME: Not
1453 distinguished from normal array. */
1455 debug_type ele_type
;
1456 bfd_vma lower
, upper
;
1458 if (! ieee_read_type_index (info
, pp
, &ele_type
)
1459 || ! ieee_read_number (info
, pp
, &lower
)
1460 || ! ieee_read_number (info
, pp
, &upper
))
1462 type
= debug_make_array_type (dhandle
, ele_type
,
1463 ieee_builtin_type (info
, ty_code_start
,
1466 (bfd_signed_vma
) lower
,
1467 (bfd_signed_vma
) upper
,
1473 /* Simple enumeration. */
1479 bfd_signed_vma
*vals
;
1482 if (! ieee_read_number (info
, pp
, &size
))
1484 /* FIXME: we ignore the enumeration size. */
1487 names
= (const char **) xmalloc (alloc
* sizeof *names
);
1488 memset (names
, 0, alloc
* sizeof *names
);
1493 unsigned long namlen
;
1494 bfd_boolean present
;
1496 if (! ieee_read_optional_id (info
, pp
, &name
, &namlen
, &present
))
1504 names
= ((const char **)
1505 xrealloc (names
, alloc
* sizeof *names
));
1508 names
[c
] = savestring (name
, namlen
);
1509 if (names
[c
] == NULL
)
1516 vals
= (bfd_signed_vma
*) xmalloc (c
* sizeof *vals
);
1517 for (i
= 0; i
< c
; i
++)
1520 type
= debug_make_enum_type (dhandle
, names
, vals
);
1526 /* Struct with bit fields. */
1530 debug_field
*fields
;
1533 if (! ieee_read_number (info
, pp
, &size
))
1537 fields
= (debug_field
*) xmalloc (alloc
* sizeof *fields
);
1542 unsigned long namlen
;
1543 bfd_boolean present
;
1545 bfd_vma bitpos
, bitsize
;
1547 if (! ieee_read_optional_id (info
, pp
, &name
, &namlen
, &present
))
1551 if (! ieee_read_type_index (info
, pp
, &ftype
)
1552 || ! ieee_read_number (info
, pp
, &bitpos
)
1553 || ! ieee_read_number (info
, pp
, &bitsize
))
1559 fields
= ((debug_field
*)
1560 xrealloc (fields
, alloc
* sizeof *fields
));
1563 fields
[c
] = debug_make_field (dhandle
, savestring (name
, namlen
),
1564 ftype
, bitpos
, bitsize
,
1565 DEBUG_VISIBILITY_PUBLIC
);
1566 if (fields
[c
] == NULL
)
1573 type
= debug_make_struct_type (dhandle
, TRUE
, size
, fields
);
1583 bfd_signed_vma
*vals
;
1587 names
= (const char **) xmalloc (alloc
* sizeof *names
);
1588 vals
= (bfd_signed_vma
*) xmalloc (alloc
* sizeof *names
);
1593 unsigned long namlen
;
1594 bfd_boolean present
;
1597 if (! ieee_read_optional_id (info
, pp
, &name
, &namlen
, &present
))
1601 if (! ieee_read_number (info
, pp
, &val
))
1604 /* If the length of the name is zero, then the value is
1605 actually the size of the enum. We ignore this
1606 information. FIXME. */
1613 names
= ((const char **)
1614 xrealloc (names
, alloc
* sizeof *names
));
1615 vals
= ((bfd_signed_vma
*)
1616 xrealloc (vals
, alloc
* sizeof *vals
));
1619 names
[c
] = savestring (name
, namlen
);
1620 if (names
[c
] == NULL
)
1622 vals
[c
] = (bfd_signed_vma
) val
;
1628 type
= debug_make_enum_type (dhandle
, names
, vals
);
1633 case 'O': /* Small pointer. We don't distinguish small and large
1635 case 'P': /* Large pointer. */
1639 if (! ieee_read_type_index (info
, pp
, &t
))
1641 type
= debug_make_pointer_type (dhandle
, t
);
1648 bfd_vma low
, high
, signedp
, size
;
1650 if (! ieee_read_number (info
, pp
, &low
)
1651 || ! ieee_read_number (info
, pp
, &high
)
1652 || ! ieee_read_number (info
, pp
, &signedp
)
1653 || ! ieee_read_number (info
, pp
, &size
))
1656 type
= debug_make_range_type (dhandle
,
1657 debug_make_int_type (dhandle
, size
,
1659 (bfd_signed_vma
) low
,
1660 (bfd_signed_vma
) high
);
1664 case 'S': /* Struct. */
1665 case 'U': /* Union. */
1669 debug_field
*fields
;
1672 if (! ieee_read_number (info
, pp
, &size
))
1676 fields
= (debug_field
*) xmalloc (alloc
* sizeof *fields
);
1681 unsigned long namlen
;
1682 bfd_boolean present
;
1688 if (! ieee_read_optional_id (info
, pp
, &name
, &namlen
, &present
))
1692 if (! ieee_read_number (info
, pp
, &tindx
)
1693 || ! ieee_read_number (info
, pp
, &offset
))
1698 ftype
= ieee_builtin_type (info
, ty_code_start
, tindx
);
1704 struct ieee_type
*t
;
1707 if (! ieee_alloc_type (info
, tindx
, TRUE
))
1709 t
= info
->types
.types
+ tindx
;
1711 bitsize
= t
->bitsize
;
1719 fields
= ((debug_field
*)
1720 xrealloc (fields
, alloc
* sizeof *fields
));
1723 fields
[c
] = debug_make_field (dhandle
, savestring (name
, namlen
),
1724 ftype
, offset
, bitsize
,
1725 DEBUG_VISIBILITY_PUBLIC
);
1726 if (fields
[c
] == NULL
)
1733 type
= debug_make_struct_type (dhandle
, tc
== 'S', size
, fields
);
1740 if (! ieee_read_type_index (info
, pp
, &type
))
1746 /* Procedure. FIXME: This is an extern declaration, which we
1747 have no way of representing. */
1752 bfd_boolean present
;
1753 struct ieee_var
*pv
;
1755 /* FIXME: We ignore the attribute and the argument names. */
1757 if (! ieee_read_number (info
, pp
, &attr
)
1758 || ! ieee_read_type_index (info
, pp
, &rtype
)
1759 || ! ieee_read_number (info
, pp
, &nargs
))
1764 unsigned long namlen
;
1766 if (! ieee_read_optional_id (info
, pp
, &name
, &namlen
, &present
))
1771 pv
= info
->vars
.vars
+ varindx
;
1772 pv
->kind
= IEEE_EXTERNAL
;
1774 && debug_get_type_kind (dhandle
, rtype
) == DEBUG_KIND_POINTER
)
1776 /* Set up the return type as an indirect type pointing to
1777 the variable slot, so that we can change it to a
1778 reference later if appropriate. */
1779 pv
->pslot
= (debug_type
*) xmalloc (sizeof *pv
->pslot
);
1781 rtype
= debug_make_indirect_type (dhandle
, pv
->pslot
,
1782 (const char *) NULL
);
1785 type
= debug_make_function_type (dhandle
, rtype
, (debug_type
*) NULL
,
1791 /* Void. This is not documented, but the MRI compiler emits it. */
1792 type
= debug_make_void_type (dhandle
);
1796 /* Array with 0 lower bound. */
1801 if (! ieee_read_type_index (info
, pp
, &etype
)
1802 || ! ieee_read_number (info
, pp
, &high
))
1805 type
= debug_make_array_type (dhandle
, etype
,
1806 ieee_builtin_type (info
, ty_code_start
,
1809 0, (bfd_signed_vma
) high
, FALSE
);
1813 case 'c': /* Complex. */
1814 case 'd': /* Double complex. */
1817 unsigned long namlen
;
1819 /* FIXME: I don't know what the name means. */
1821 if (! ieee_read_id (info
, pp
, &name
, &namlen
))
1824 type
= debug_make_complex_type (dhandle
, tc
== 'c' ? 4 : 8);
1829 /* Pascal file name. FIXME. */
1830 ieee_error (info
, ty_code_start
, _("Pascal file name not supported"));
1834 /* Bitfield type. */
1836 bfd_vma signedp
, bitsize
, dummy
;
1837 const bfd_byte
*hold
;
1838 bfd_boolean present
;
1840 if (! ieee_read_number (info
, pp
, &signedp
)
1841 || ! ieee_read_number (info
, pp
, &bitsize
))
1844 /* I think the documentation says that there is a type index,
1845 but some actual files do not have one. */
1847 if (! ieee_read_optional_number (info
, pp
, &dummy
, &present
))
1851 /* FIXME: This is just a guess. */
1852 type
= debug_make_int_type (dhandle
, 4,
1853 signedp
? FALSE
: TRUE
);
1858 if (! ieee_read_type_index (info
, pp
, &type
))
1861 type_bitsize
= bitsize
;
1871 if (! ieee_read_number (info
, pp
, &kind
)
1872 || ! ieee_read_type_index (info
, pp
, &t
))
1878 ieee_error (info
, ty_start
, _("unsupported qualifier"));
1882 type
= debug_make_const_type (dhandle
, t
);
1886 type
= debug_make_volatile_type (dhandle
, t
);
1898 if (! ieee_read_number (info
, pp
, &size
)
1899 || ! ieee_read_type_index (info
, pp
, &etype
))
1902 /* FIXME: We ignore the size. */
1904 type
= debug_make_set_type (dhandle
, etype
, FALSE
);
1909 /* Procedure with compiler dependencies. */
1911 struct ieee_var
*pv
;
1912 bfd_vma attr
, frame_type
, push_mask
, nargs
, level
, father
;
1914 debug_type
*arg_types
;
1915 bfd_boolean varargs
;
1916 bfd_boolean present
;
1918 /* FIXME: We ignore some of this information. */
1920 pv
= info
->vars
.vars
+ varindx
;
1922 if (! ieee_read_number (info
, pp
, &attr
)
1923 || ! ieee_read_number (info
, pp
, &frame_type
)
1924 || ! ieee_read_number (info
, pp
, &push_mask
)
1925 || ! ieee_read_type_index (info
, pp
, &rtype
)
1926 || ! ieee_read_number (info
, pp
, &nargs
))
1928 if (nargs
== (bfd_vma
) -1)
1937 arg_types
= ((debug_type
*)
1938 xmalloc ((nargs
+ 1) * sizeof *arg_types
));
1939 for (i
= 0; i
< nargs
; i
++)
1940 if (! ieee_read_type_index (info
, pp
, arg_types
+ i
))
1943 /* If the last type is pointer to void, this is really a
1944 varargs function. */
1950 last
= arg_types
[nargs
- 1];
1951 if (debug_get_type_kind (dhandle
, last
) == DEBUG_KIND_POINTER
1952 && (debug_get_type_kind (dhandle
,
1953 debug_get_target_type (dhandle
,
1955 == DEBUG_KIND_VOID
))
1962 /* If there are any pointer arguments, turn them into
1963 indirect types in case we later need to convert them to
1965 for (i
= 0; i
< nargs
; i
++)
1967 if (debug_get_type_kind (dhandle
, arg_types
[i
])
1968 == DEBUG_KIND_POINTER
)
1970 if (arg_slots
== NULL
)
1972 arg_slots
= ((debug_type
*)
1973 xmalloc (nargs
* sizeof *arg_slots
));
1974 memset (arg_slots
, 0, nargs
* sizeof *arg_slots
);
1976 arg_slots
[i
] = arg_types
[i
];
1978 debug_make_indirect_type (dhandle
,
1980 (const char *) NULL
);
1984 arg_types
[nargs
] = DEBUG_TYPE_NULL
;
1986 if (! ieee_read_number (info
, pp
, &level
)
1987 || ! ieee_read_optional_number (info
, pp
, &father
, &present
))
1990 /* We can't distinguish between a global function and a static
1992 pv
->kind
= IEEE_FUNCTION
;
1995 && debug_get_type_kind (dhandle
, rtype
) == DEBUG_KIND_POINTER
)
1997 /* Set up the return type as an indirect type pointing to
1998 the variable slot, so that we can change it to a
1999 reference later if appropriate. */
2000 pv
->pslot
= (debug_type
*) xmalloc (sizeof *pv
->pslot
);
2002 rtype
= debug_make_indirect_type (dhandle
, pv
->pslot
,
2003 (const char *) NULL
);
2006 type
= debug_make_function_type (dhandle
, rtype
, arg_types
, varargs
);
2011 /* Record the type in the table. */
2013 if (type
== DEBUG_TYPE_NULL
)
2016 info
->vars
.vars
[varindx
].type
= type
;
2019 && info
->vars
.vars
[varindx
].namlen
> 0)
2023 name
= savestring (info
->vars
.vars
[varindx
].name
,
2024 info
->vars
.vars
[varindx
].namlen
);
2026 type
= debug_name_type (dhandle
, name
, type
);
2027 else if (tc
== 'E' || tc
== 'N')
2028 type
= debug_tag_type (dhandle
, name
, type
);
2031 struct ieee_tag
*it
;
2033 /* We must allocate all struct tags as indirect types, so
2034 that if we later see a definition of the tag as a C++
2035 record we can update the indirect slot and automatically
2036 change all the existing references. */
2037 it
= (struct ieee_tag
*) xmalloc (sizeof *it
);
2038 memset (it
, 0, sizeof *it
);
2039 it
->next
= info
->tags
;
2044 type
= debug_make_indirect_type (dhandle
, &it
->slot
, name
);
2045 type
= debug_tag_type (dhandle
, name
, type
);
2053 info
->types
.types
[typeindx
].type
= type
;
2054 info
->types
.types
[typeindx
].arg_slots
= arg_slots
;
2055 info
->types
.types
[typeindx
].bitsize
= type_bitsize
;
2057 /* We may have already allocated type as an indirect type pointing
2058 to slot. It does no harm to replace the indirect type with the
2059 real type. Filling in slot as well handles the indirect types
2060 which are already hanging around. */
2061 if (info
->types
.types
[typeindx
].pslot
!= NULL
)
2062 *info
->types
.types
[typeindx
].pslot
= type
;
2067 /* Parse an ATN record. */
2070 parse_ieee_atn (struct ieee_info
*info
, const bfd_byte
**pp
)
2072 const bfd_byte
*atn_start
, *atn_code_start
;
2074 struct ieee_var
*pvar
;
2078 bfd_vma v
, v2
, v3
, v4
, v5
;
2080 unsigned long namlen
;
2082 bfd_boolean present
;
2087 if (! ieee_read_number (info
, pp
, &varindx
)
2088 || ! ieee_read_type_index (info
, pp
, &type
))
2091 atn_code_start
= *pp
;
2093 if (! ieee_read_number (info
, pp
, &atn_code
))
2102 else if (varindx
< 32)
2104 /* The MRI compiler reportedly sometimes emits variable lifetime
2105 information for a register. We just ignore it. */
2107 return ieee_read_number (info
, pp
, &v
);
2109 ieee_error (info
, atn_start
, _("illegal variable index"));
2115 if (varindx
>= info
->vars
.alloc
2116 || info
->vars
.vars
[varindx
].name
== NULL
)
2118 /* The MRI compiler or linker sometimes omits the NN record
2119 for a pmisc record. */
2122 if (varindx
>= info
->vars
.alloc
)
2126 alloc
= info
->vars
.alloc
;
2129 while (varindx
>= alloc
)
2131 info
->vars
.vars
= ((struct ieee_var
*)
2132 xrealloc (info
->vars
.vars
,
2134 * sizeof *info
->vars
.vars
)));
2135 memset (info
->vars
.vars
+ info
->vars
.alloc
, 0,
2136 ((alloc
- info
->vars
.alloc
)
2137 * sizeof *info
->vars
.vars
));
2138 info
->vars
.alloc
= alloc
;
2141 pvar
= info
->vars
.vars
+ varindx
;
2147 ieee_error (info
, atn_start
, _("undefined variable in ATN"));
2152 pvar
= info
->vars
.vars
+ varindx
;
2157 namlen
= pvar
->namlen
;
2160 dhandle
= info
->dhandle
;
2162 /* If we are going to call debug_record_variable with a pointer
2163 type, change the type to an indirect type so that we can later
2164 change it to a reference type if we encounter a C++ pmisc 'R'
2167 && type
!= DEBUG_TYPE_NULL
2168 && debug_get_type_kind (dhandle
, type
) == DEBUG_KIND_POINTER
)
2178 pvar
->pslot
= (debug_type
*) xmalloc (sizeof *pvar
->pslot
);
2179 *pvar
->pslot
= type
;
2180 type
= debug_make_indirect_type (dhandle
, pvar
->pslot
,
2181 (const char *) NULL
);
2190 ieee_error (info
, atn_code_start
, _("unknown ATN type"));
2194 /* Automatic variable. */
2195 if (! ieee_read_number (info
, pp
, &v
))
2197 namcopy
= savestring (name
, namlen
);
2199 type
= debug_make_void_type (dhandle
);
2201 pvar
->kind
= IEEE_LOCAL
;
2202 return debug_record_variable (dhandle
, namcopy
, type
, DEBUG_LOCAL
, v
);
2205 /* Register variable. */
2206 if (! ieee_read_number (info
, pp
, &v
))
2208 namcopy
= savestring (name
, namlen
);
2210 type
= debug_make_void_type (dhandle
);
2212 pvar
->kind
= IEEE_LOCAL
;
2213 return debug_record_variable (dhandle
, namcopy
, type
, DEBUG_REGISTER
,
2214 ieee_regno_to_genreg (info
->abfd
, v
));
2217 /* Static variable. */
2218 if (! ieee_require_asn (info
, pp
, &v
))
2220 namcopy
= savestring (name
, namlen
);
2222 type
= debug_make_void_type (dhandle
);
2223 if (info
->blockstack
.bsp
<= info
->blockstack
.stack
)
2226 blocktype
= info
->blockstack
.bsp
[-1].kind
;
2229 if (blocktype
== 4 || blocktype
== 6)
2230 pvar
->kind
= IEEE_LOCAL
;
2232 pvar
->kind
= IEEE_STATIC
;
2234 return debug_record_variable (dhandle
, namcopy
, type
,
2235 (blocktype
== 4 || blocktype
== 6
2236 ? DEBUG_LOCAL_STATIC
2241 /* External function. We don't currently record these. FIXME. */
2243 pvar
->kind
= IEEE_EXTERNAL
;
2247 /* External variable. We don't currently record these. FIXME. */
2249 pvar
->kind
= IEEE_EXTERNAL
;
2253 if (! ieee_read_number (info
, pp
, &v
)
2254 || ! ieee_read_number (info
, pp
, &v2
)
2255 || ! ieee_read_optional_number (info
, pp
, &v3
, &present
))
2259 if (! ieee_read_optional_number (info
, pp
, &v4
, &present
))
2263 /* We just ignore the two optional fields in v3 and v4, since
2264 they are not defined. */
2266 if (! ieee_require_asn (info
, pp
, &v3
))
2269 /* We have no way to record the column number. FIXME. */
2271 return debug_record_line (dhandle
, v
, v3
);
2274 /* Global variable. */
2275 if (! ieee_require_asn (info
, pp
, &v
))
2277 namcopy
= savestring (name
, namlen
);
2279 type
= debug_make_void_type (dhandle
);
2281 pvar
->kind
= IEEE_GLOBAL
;
2282 return debug_record_variable (dhandle
, namcopy
, type
, DEBUG_GLOBAL
, v
);
2285 /* Variable lifetime information. */
2286 if (! ieee_read_number (info
, pp
, &v
))
2289 /* We have no way to record this information. FIXME. */
2293 /* Locked register. The spec says that there are two required
2294 fields, but at least on occasion the MRI compiler only emits
2296 if (! ieee_read_number (info
, pp
, &v
)
2297 || ! ieee_read_optional_number (info
, pp
, &v2
, &present
))
2300 /* I think this means a variable that is both in a register and
2301 a frame slot. We ignore the frame slot. FIXME. */
2303 namcopy
= savestring (name
, namlen
);
2305 type
= debug_make_void_type (dhandle
);
2307 pvar
->kind
= IEEE_LOCAL
;
2308 return debug_record_variable (dhandle
, namcopy
, type
, DEBUG_REGISTER
, v
);
2311 /* Reserved for FORTRAN common. */
2312 ieee_error (info
, atn_code_start
, _("unsupported ATN11"));
2314 /* Return TRUE to keep going. */
2318 /* Based variable. */
2322 if (! ieee_read_number (info
, pp
, &v
)
2323 || ! ieee_read_number (info
, pp
, &v2
)
2324 || ! ieee_read_optional_number (info
, pp
, &v3
, &present
))
2328 if (! ieee_read_optional_number (info
, pp
, &v4
, &present
))
2332 if (! ieee_read_optional_number (info
, pp
, &v5
, &present
))
2337 /* We have no way to record this information. FIXME. */
2339 ieee_error (info
, atn_code_start
, _("unsupported ATN12"));
2341 /* Return TRUE to keep going. */
2345 /* Constant. The description of this that I have is ambiguous,
2346 so I'm not going to try to implement it. */
2347 if (! ieee_read_number (info
, pp
, &v
)
2348 || ! ieee_read_optional_number (info
, pp
, &v2
, &present
))
2352 if (! ieee_read_optional_number (info
, pp
, &v2
, &present
))
2356 if (! ieee_read_optional_id (info
, pp
, &name
, &namlen
, &present
))
2361 if ((ieee_record_enum_type
) **pp
== ieee_e2_first_byte_enum
)
2363 if (! ieee_require_asn (info
, pp
, &v3
))
2370 /* Static variable from assembler. */
2372 if (! ieee_read_number (info
, pp
, &v
)
2373 || ! ieee_read_optional_number (info
, pp
, &v2
, &present
)
2374 || ! ieee_require_asn (info
, pp
, &v3
))
2376 namcopy
= savestring (name
, namlen
);
2377 /* We don't really handle this correctly. FIXME. */
2378 return debug_record_variable (dhandle
, namcopy
,
2379 debug_make_void_type (dhandle
),
2380 v2
!= 0 ? DEBUG_GLOBAL
: DEBUG_STATIC
,
2384 /* Procedure miscellaneous information. */
2386 /* Variable miscellaneous information. */
2388 /* Module miscellaneous information. */
2389 if (! ieee_read_number (info
, pp
, &v
)
2390 || ! ieee_read_number (info
, pp
, &v2
)
2391 || ! ieee_read_optional_id (info
, pp
, &name
, &namlen
, &present
))
2394 if (atn_code
== 62 && v
== 80)
2398 ieee_error (info
, atn_code_start
,
2399 _("unexpected string in C++ misc"));
2402 return ieee_read_cxx_misc (info
, pp
, v2
);
2405 /* We just ignore all of this stuff. FIXME. */
2407 for (; v2
> 0; --v2
)
2409 switch ((ieee_record_enum_type
) **pp
)
2412 ieee_error (info
, *pp
, _("bad misc record"));
2415 case ieee_at_record_enum
:
2416 if (! ieee_require_atn65 (info
, pp
, &name
, &namlen
))
2420 case ieee_e2_first_byte_enum
:
2421 if (! ieee_require_asn (info
, pp
, &v3
))
2433 /* Handle C++ debugging miscellaneous records. This is called for
2434 procedure miscellaneous records of type 80. */
2437 ieee_read_cxx_misc (struct ieee_info
*info
, const bfd_byte
**pp
,
2438 unsigned long count
)
2440 const bfd_byte
*start
;
2445 /* Get the category of C++ misc record. */
2446 if (! ieee_require_asn (info
, pp
, &category
))
2453 ieee_error (info
, start
, _("unrecognized C++ misc record"));
2457 if (! ieee_read_cxx_class (info
, pp
, count
))
2465 unsigned long namlen
;
2467 /* The IEEE spec indicates that the 'M' record only has a
2468 flags field. The MRI compiler also emits the name of the
2471 if (! ieee_require_asn (info
, pp
, &flags
))
2473 if (*pp
< info
->pend
2474 && (ieee_record_enum_type
) **pp
== ieee_at_record_enum
)
2476 if (! ieee_require_atn65 (info
, pp
, &name
, &namlen
))
2480 /* This is emitted for method functions, but I don't think we
2481 care very much. It might help if it told us useful
2482 information like the class with which this function is
2483 associated, but it doesn't, so it isn't helpful. */
2488 if (! ieee_read_cxx_defaults (info
, pp
, count
))
2494 const char *name
, *mangled
, *class;
2495 unsigned long namlen
, mangledlen
, classlen
;
2498 /* Pointer to member. */
2500 if (! ieee_require_atn65 (info
, pp
, &name
, &namlen
)
2501 || ! ieee_require_atn65 (info
, pp
, &mangled
, &mangledlen
)
2502 || ! ieee_require_atn65 (info
, pp
, &class, &classlen
)
2503 || ! ieee_require_asn (info
, pp
, &control
))
2506 /* FIXME: We should now track down name and change its type. */
2511 if (! ieee_read_reference (info
, pp
))
2519 /* Read a C++ class definition. This is a pmisc type 80 record of
2523 ieee_read_cxx_class (struct ieee_info
*info
, const bfd_byte
**pp
,
2524 unsigned long count
)
2526 const bfd_byte
*start
;
2529 unsigned long taglen
;
2530 struct ieee_tag
*it
;
2532 debug_field
*fields
;
2533 unsigned int field_count
, field_alloc
;
2534 debug_baseclass
*baseclasses
;
2535 unsigned int baseclasses_count
, baseclasses_alloc
;
2536 const debug_field
*structfields
;
2540 unsigned long namlen
;
2541 debug_method_variant
*variants
;
2545 unsigned int methods_count
, methods_alloc
;
2546 debug_type vptrbase
;
2547 bfd_boolean ownvptr
;
2548 debug_method
*dmethods
;
2552 if (! ieee_require_asn (info
, pp
, &class))
2556 if (! ieee_require_atn65 (info
, pp
, &tag
, &taglen
))
2560 /* Find the C struct with this name. */
2561 for (it
= info
->tags
; it
!= NULL
; it
= it
->next
)
2562 if (it
->name
[0] == tag
[0]
2563 && strncmp (it
->name
, tag
, taglen
) == 0
2564 && strlen (it
->name
) == taglen
)
2568 ieee_error (info
, start
, _("undefined C++ object"));
2572 dhandle
= info
->dhandle
;
2578 baseclasses_count
= 0;
2579 baseclasses_alloc
= 0;
2583 vptrbase
= DEBUG_TYPE_NULL
;
2586 structfields
= debug_get_fields (dhandle
, it
->type
);
2591 const bfd_byte
*spec_start
;
2595 if (! ieee_require_asn (info
, pp
, &id
))
2602 ieee_error (info
, spec_start
, _("unrecognized C++ object spec"));
2607 bfd_vma flags
, cinline
;
2608 const char *basename
, *fieldname
;
2609 unsigned long baselen
, fieldlen
;
2611 debug_type basetype
;
2613 bfd_boolean virtualp
;
2614 enum debug_visibility visibility
;
2615 debug_baseclass baseclass
;
2617 /* This represents a base or friend class. */
2619 if (! ieee_require_asn (info
, pp
, &flags
)
2620 || ! ieee_require_atn65 (info
, pp
, &basename
, &baselen
)
2621 || ! ieee_require_asn (info
, pp
, &cinline
)
2622 || ! ieee_require_atn65 (info
, pp
, &fieldname
, &fieldlen
))
2626 /* We have no way of recording friend information, so we
2628 if ((flags
& BASEFLAGS_FRIEND
) != 0)
2631 /* I assume that either all of the members of the
2632 baseclass are included in the object, starting at the
2633 beginning of the object, or that none of them are
2636 if ((fieldlen
== 0) == (cinline
== 0))
2638 ieee_error (info
, start
, _("unsupported C++ object type"));
2642 basecopy
= savestring (basename
, baselen
);
2643 basetype
= debug_find_tagged_type (dhandle
, basecopy
,
2644 DEBUG_KIND_ILLEGAL
);
2646 if (basetype
== DEBUG_TYPE_NULL
)
2648 ieee_error (info
, start
, _("C++ base class not defined"));
2656 const debug_field
*pf
;
2658 if (structfields
== NULL
)
2660 ieee_error (info
, start
, _("C++ object has no fields"));
2664 for (pf
= structfields
; *pf
!= DEBUG_FIELD_NULL
; pf
++)
2668 fname
= debug_get_field_name (dhandle
, *pf
);
2671 if (fname
[0] == fieldname
[0]
2672 && strncmp (fname
, fieldname
, fieldlen
) == 0
2673 && strlen (fname
) == fieldlen
)
2676 if (*pf
== DEBUG_FIELD_NULL
)
2678 ieee_error (info
, start
,
2679 _("C++ base class not found in container"));
2683 bitpos
= debug_get_field_bitpos (dhandle
, *pf
);
2686 if ((flags
& BASEFLAGS_VIRTUAL
) != 0)
2690 if ((flags
& BASEFLAGS_PRIVATE
) != 0)
2691 visibility
= DEBUG_VISIBILITY_PRIVATE
;
2693 visibility
= DEBUG_VISIBILITY_PUBLIC
;
2695 baseclass
= debug_make_baseclass (dhandle
, basetype
, bitpos
,
2696 virtualp
, visibility
);
2697 if (baseclass
== DEBUG_BASECLASS_NULL
)
2700 if (baseclasses_count
+ 1 >= baseclasses_alloc
)
2702 baseclasses_alloc
+= 10;
2703 baseclasses
= ((debug_baseclass
*)
2704 xrealloc (baseclasses
,
2706 * sizeof *baseclasses
)));
2709 baseclasses
[baseclasses_count
] = baseclass
;
2710 ++baseclasses_count
;
2711 baseclasses
[baseclasses_count
] = DEBUG_BASECLASS_NULL
;
2718 const char *fieldname
, *mangledname
;
2719 unsigned long fieldlen
, mangledlen
;
2721 bfd_boolean staticp
;
2723 const debug_field
*pf
= NULL
;
2724 enum debug_visibility visibility
;
2727 /* This represents a data member. */
2729 if (! ieee_require_asn (info
, pp
, &flags
)
2730 || ! ieee_require_atn65 (info
, pp
, &fieldname
, &fieldlen
)
2731 || ! ieee_require_atn65 (info
, pp
, &mangledname
, &mangledlen
))
2735 fieldcopy
= savestring (fieldname
, fieldlen
);
2737 staticp
= (flags
& CXXFLAGS_STATIC
) != 0 ? TRUE
: FALSE
;
2741 struct ieee_var
*pv
, *pvend
;
2743 /* See if we can find a definition for this variable. */
2744 pv
= info
->vars
.vars
;
2745 pvend
= pv
+ info
->vars
.alloc
;
2746 for (; pv
< pvend
; pv
++)
2747 if (pv
->namlen
== mangledlen
2748 && strncmp (pv
->name
, mangledname
, mangledlen
) == 0)
2754 /* This can happen if the variable is never used. */
2755 ftype
= ieee_builtin_type (info
, start
,
2756 (unsigned int) builtin_void
);
2763 if (structfields
== NULL
)
2765 ieee_error (info
, start
, _("C++ object has no fields"));
2769 for (pf
= structfields
, findx
= 0;
2770 *pf
!= DEBUG_FIELD_NULL
;
2775 fname
= debug_get_field_name (dhandle
, *pf
);
2778 if (fname
[0] == mangledname
[0]
2779 && strncmp (fname
, mangledname
, mangledlen
) == 0
2780 && strlen (fname
) == mangledlen
)
2783 if (*pf
== DEBUG_FIELD_NULL
)
2785 ieee_error (info
, start
,
2786 _("C++ data member not found in container"));
2790 ftype
= debug_get_field_type (dhandle
, *pf
);
2792 if (debug_get_type_kind (dhandle
, ftype
) == DEBUG_KIND_POINTER
)
2794 /* We might need to convert this field into a
2795 reference type later on, so make it an indirect
2797 if (it
->fslots
== NULL
)
2800 const debug_field
*pfcnt
;
2803 for (pfcnt
= structfields
;
2804 *pfcnt
!= DEBUG_FIELD_NULL
;
2807 it
->fslots
= ((debug_type
*)
2808 xmalloc (fcnt
* sizeof *it
->fslots
));
2809 memset (it
->fslots
, 0,
2810 fcnt
* sizeof *it
->fslots
);
2813 if (ftype
== DEBUG_TYPE_NULL
)
2815 it
->fslots
[findx
] = ftype
;
2816 ftype
= debug_make_indirect_type (dhandle
,
2818 (const char *) NULL
);
2821 if (ftype
== DEBUG_TYPE_NULL
)
2824 switch (flags
& CXXFLAGS_VISIBILITY
)
2827 ieee_error (info
, start
, _("unknown C++ visibility"));
2830 case CXXFLAGS_VISIBILITY_PUBLIC
:
2831 visibility
= DEBUG_VISIBILITY_PUBLIC
;
2834 case CXXFLAGS_VISIBILITY_PRIVATE
:
2835 visibility
= DEBUG_VISIBILITY_PRIVATE
;
2838 case CXXFLAGS_VISIBILITY_PROTECTED
:
2839 visibility
= DEBUG_VISIBILITY_PROTECTED
;
2847 mangledcopy
= savestring (mangledname
, mangledlen
);
2849 field
= debug_make_static_member (dhandle
, fieldcopy
,
2855 bfd_vma bitpos
, bitsize
;
2857 bitpos
= debug_get_field_bitpos (dhandle
, *pf
);
2858 bitsize
= debug_get_field_bitsize (dhandle
, *pf
);
2859 if (bitpos
== (bfd_vma
) -1 || bitsize
== (bfd_vma
) -1)
2861 ieee_error (info
, start
, _("bad C++ field bit pos or size"));
2864 field
= debug_make_field (dhandle
, fieldcopy
, ftype
, bitpos
,
2865 bitsize
, visibility
);
2868 if (field
== DEBUG_FIELD_NULL
)
2871 if (field_count
+ 1 >= field_alloc
)
2874 fields
= ((debug_field
*)
2875 xrealloc (fields
, field_alloc
* sizeof *fields
));
2878 fields
[field_count
] = field
;
2880 fields
[field_count
] = DEBUG_FIELD_NULL
;
2887 bfd_vma flags
, voffset
, control
;
2888 const char *name
, *mangled
;
2889 unsigned long namlen
, mangledlen
;
2890 struct ieee_var
*pv
, *pvend
;
2892 enum debug_visibility visibility
;
2893 bfd_boolean constp
, volatilep
;
2895 debug_method_variant mv
;
2896 struct ieee_method
*meth
;
2899 if (! ieee_require_asn (info
, pp
, &flags
)
2900 || ! ieee_require_atn65 (info
, pp
, &name
, &namlen
)
2901 || ! ieee_require_atn65 (info
, pp
, &mangled
, &mangledlen
))
2908 if (! ieee_require_asn (info
, pp
, &voffset
))
2912 if (! ieee_require_asn (info
, pp
, &control
))
2916 /* We just ignore the control information. */
2918 /* We have no way to represent friend information, so we
2920 if ((flags
& CXXFLAGS_FRIEND
) != 0)
2923 /* We should already have seen a type for the function. */
2924 pv
= info
->vars
.vars
;
2925 pvend
= pv
+ info
->vars
.alloc
;
2926 for (; pv
< pvend
; pv
++)
2927 if (pv
->namlen
== mangledlen
2928 && strncmp (pv
->name
, mangled
, mangledlen
) == 0)
2933 /* We won't have type information for this function if
2934 it is not included in this file. We don't try to
2935 handle this case. FIXME. */
2936 type
= (debug_make_function_type
2938 ieee_builtin_type (info
, start
,
2939 (unsigned int) builtin_void
),
2940 (debug_type
*) NULL
,
2945 debug_type return_type
;
2946 const debug_type
*arg_types
;
2947 bfd_boolean varargs
;
2949 if (debug_get_type_kind (dhandle
, pv
->type
)
2950 != DEBUG_KIND_FUNCTION
)
2952 ieee_error (info
, start
,
2953 _("bad type for C++ method function"));
2957 return_type
= debug_get_return_type (dhandle
, pv
->type
);
2958 arg_types
= debug_get_parameter_types (dhandle
, pv
->type
,
2960 if (return_type
== DEBUG_TYPE_NULL
|| arg_types
== NULL
)
2962 ieee_error (info
, start
,
2963 _("no type information for C++ method function"));
2967 type
= debug_make_method_type (dhandle
, return_type
, it
->type
,
2968 (debug_type
*) arg_types
,
2971 if (type
== DEBUG_TYPE_NULL
)
2974 switch (flags
& CXXFLAGS_VISIBILITY
)
2977 ieee_error (info
, start
, _("unknown C++ visibility"));
2980 case CXXFLAGS_VISIBILITY_PUBLIC
:
2981 visibility
= DEBUG_VISIBILITY_PUBLIC
;
2984 case CXXFLAGS_VISIBILITY_PRIVATE
:
2985 visibility
= DEBUG_VISIBILITY_PRIVATE
;
2988 case CXXFLAGS_VISIBILITY_PROTECTED
:
2989 visibility
= DEBUG_VISIBILITY_PROTECTED
;
2993 constp
= (flags
& CXXFLAGS_CONST
) != 0 ? TRUE
: FALSE
;
2994 volatilep
= (flags
& CXXFLAGS_VOLATILE
) != 0 ? TRUE
: FALSE
;
2996 mangledcopy
= savestring (mangled
, mangledlen
);
2998 if ((flags
& CXXFLAGS_STATIC
) != 0)
3002 ieee_error (info
, start
, _("C++ static virtual method"));
3005 mv
= debug_make_static_method_variant (dhandle
, mangledcopy
,
3011 debug_type vcontext
;
3014 vcontext
= DEBUG_TYPE_NULL
;
3017 /* FIXME: How can we calculate this correctly? */
3018 vcontext
= it
->type
;
3020 mv
= debug_make_method_variant (dhandle
, mangledcopy
, type
,
3025 if (mv
== DEBUG_METHOD_VARIANT_NULL
)
3028 for (meth
= methods
, im
= 0; im
< methods_count
; meth
++, im
++)
3029 if (meth
->namlen
== namlen
3030 && strncmp (meth
->name
, name
, namlen
) == 0)
3032 if (im
>= methods_count
)
3034 if (methods_count
>= methods_alloc
)
3036 methods_alloc
+= 10;
3037 methods
= ((struct ieee_method
*)
3039 methods_alloc
* sizeof *methods
));
3041 methods
[methods_count
].name
= name
;
3042 methods
[methods_count
].namlen
= namlen
;
3043 methods
[methods_count
].variants
= NULL
;
3044 methods
[methods_count
].count
= 0;
3045 methods
[methods_count
].alloc
= 0;
3046 meth
= methods
+ methods_count
;
3050 if (meth
->count
+ 1 >= meth
->alloc
)
3053 meth
->variants
= ((debug_method_variant
*)
3054 xrealloc (meth
->variants
,
3056 * sizeof *meth
->variants
)));
3059 meth
->variants
[meth
->count
] = mv
;
3061 meth
->variants
[meth
->count
] = DEBUG_METHOD_VARIANT_NULL
;
3069 /* We have no way to store this information, so we just
3071 if (! ieee_require_asn (info
, pp
, &spec
))
3074 if ((spec
& 4) != 0)
3076 const char *filename
;
3077 unsigned long filenamlen
;
3080 if (! ieee_require_atn65 (info
, pp
, &filename
, &filenamlen
)
3081 || ! ieee_require_asn (info
, pp
, &lineno
))
3085 else if ((spec
& 8) != 0)
3087 const char *mangled
;
3088 unsigned long mangledlen
;
3090 if (! ieee_require_atn65 (info
, pp
, &mangled
, &mangledlen
))
3096 ieee_error (info
, start
,
3097 _("unrecognized C++ object overhead spec"));
3105 const char *vname
, *basename
;
3106 unsigned long vnamelen
, baselen
;
3107 bfd_vma vsize
, control
;
3109 /* A virtual table pointer. */
3111 if (! ieee_require_atn65 (info
, pp
, &vname
, &vnamelen
)
3112 || ! ieee_require_asn (info
, pp
, &vsize
)
3113 || ! ieee_require_atn65 (info
, pp
, &basename
, &baselen
)
3114 || ! ieee_require_asn (info
, pp
, &control
))
3118 /* We just ignore the control number. We don't care what
3119 the virtual table name is. We have no way to store the
3120 virtual table size, and I don't think we care anyhow. */
3122 /* FIXME: We can't handle multiple virtual table pointers. */
3130 basecopy
= savestring (basename
, baselen
);
3131 vptrbase
= debug_find_tagged_type (dhandle
, basecopy
,
3132 DEBUG_KIND_ILLEGAL
);
3134 if (vptrbase
== DEBUG_TYPE_NULL
)
3136 ieee_error (info
, start
, _("undefined C++ vtable"));
3145 /* Now that we have seen all the method variants, we can call
3146 debug_make_method for each one. */
3148 if (methods_count
== 0)
3154 dmethods
= ((debug_method
*)
3155 xmalloc ((methods_count
+ 1) * sizeof *dmethods
));
3156 for (i
= 0; i
< methods_count
; i
++)
3160 namcopy
= savestring (methods
[i
].name
, methods
[i
].namlen
);
3161 dmethods
[i
] = debug_make_method (dhandle
, namcopy
,
3162 methods
[i
].variants
);
3163 if (dmethods
[i
] == DEBUG_METHOD_NULL
)
3166 dmethods
[i
] = DEBUG_METHOD_NULL
;
3170 /* The struct type was created as an indirect type pointing at
3171 it->slot. We update it->slot to automatically update all
3172 references to this struct. */
3173 it
->slot
= debug_make_object_type (dhandle
,
3175 debug_get_type_size (dhandle
,
3177 fields
, baseclasses
, dmethods
,
3179 if (it
->slot
== DEBUG_TYPE_NULL
)
3185 /* Read C++ default argument value and reference type information. */
3188 ieee_read_cxx_defaults (struct ieee_info
*info
, const bfd_byte
**pp
,
3189 unsigned long count
)
3191 const bfd_byte
*start
;
3193 unsigned long fnlen
;
3198 /* Giving the function name before the argument count is an addendum
3199 to the spec. The function name is demangled, though, so this
3200 record must always refer to the current function. */
3202 if (info
->blockstack
.bsp
<= info
->blockstack
.stack
3203 || info
->blockstack
.bsp
[-1].fnindx
== (unsigned int) -1)
3205 ieee_error (info
, start
, _("C++ default values not in a function"));
3209 if (! ieee_require_atn65 (info
, pp
, &fnname
, &fnlen
)
3210 || ! ieee_require_asn (info
, pp
, &defcount
))
3214 while (defcount
-- > 0)
3218 unsigned long strvallen
;
3220 if (! ieee_require_asn (info
, pp
, &type
))
3232 if (! ieee_require_asn (info
, pp
, &val
))
3239 if (! ieee_require_atn65 (info
, pp
, &strval
, &strvallen
))
3245 ieee_error (info
, start
, _("unrecognized C++ default type"));
3249 /* We have no way to record the default argument values, so we
3250 just ignore them. FIXME. */
3253 /* Any remaining arguments are indices of parameters that are really
3258 debug_type
*arg_slots
;
3260 dhandle
= info
->dhandle
;
3261 arg_slots
= info
->types
.types
[info
->blockstack
.bsp
[-1].fnindx
].arg_slots
;
3267 if (! ieee_require_asn (info
, pp
, &indx
))
3269 /* The index is 1 based. */
3271 if (arg_slots
== NULL
3272 || arg_slots
[indx
] == DEBUG_TYPE_NULL
3273 || (debug_get_type_kind (dhandle
, arg_slots
[indx
])
3274 != DEBUG_KIND_POINTER
))
3276 ieee_error (info
, start
, _("reference parameter is not a pointer"));
3280 target
= debug_get_target_type (dhandle
, arg_slots
[indx
]);
3281 arg_slots
[indx
] = debug_make_reference_type (dhandle
, target
);
3282 if (arg_slots
[indx
] == DEBUG_TYPE_NULL
)
3290 /* Read a C++ reference definition. */
3293 ieee_read_reference (struct ieee_info
*info
, const bfd_byte
**pp
)
3295 const bfd_byte
*start
;
3297 const char *class, *name
;
3298 unsigned long classlen
, namlen
;
3304 if (! ieee_require_asn (info
, pp
, &flags
))
3307 /* Giving the class name before the member name is in an addendum to
3311 if (! ieee_require_atn65 (info
, pp
, &class, &classlen
))
3315 if (! ieee_require_atn65 (info
, pp
, &name
, &namlen
))
3323 /* We search from the last variable indices to the first in
3324 hopes of finding local variables correctly. We search the
3325 local variables on the first pass, and the global variables
3326 on the second. FIXME: This probably won't work in all cases.
3327 On the other hand, I don't know what will. */
3328 for (pass
= 0; pass
< 2; pass
++)
3330 struct ieee_vars
*vars
;
3332 struct ieee_var
*pv
= NULL
;
3338 vars
= info
->global_vars
;
3343 for (i
= (int) vars
->alloc
- 1; i
>= 0; i
--)
3347 pv
= vars
->vars
+ i
;
3349 if (pv
->pslot
== NULL
3350 || pv
->namlen
!= namlen
3351 || strncmp (pv
->name
, name
, namlen
) != 0)
3358 ieee_error (info
, start
,
3359 _("unrecognized C++ reference type"));
3363 /* Global variable or function. */
3364 if (pv
->kind
== IEEE_GLOBAL
3365 || pv
->kind
== IEEE_EXTERNAL
3366 || pv
->kind
== IEEE_FUNCTION
)
3371 /* Global static variable or function. */
3372 if (pv
->kind
== IEEE_STATIC
3373 || pv
->kind
== IEEE_FUNCTION
)
3378 /* Local variable. */
3379 if (pv
->kind
== IEEE_LOCAL
)
3397 struct ieee_tag
*it
;
3399 for (it
= info
->tags
; it
!= NULL
; it
= it
->next
)
3401 if (it
->name
[0] == class[0]
3402 && strncmp (it
->name
, class, classlen
) == 0
3403 && strlen (it
->name
) == classlen
)
3405 if (it
->fslots
!= NULL
)
3407 const debug_field
*pf
;
3410 pf
= debug_get_fields (info
->dhandle
, it
->type
);
3413 ieee_error (info
, start
,
3414 "C++ reference in class with no fields");
3418 for (findx
= 0; *pf
!= DEBUG_FIELD_NULL
; pf
++, findx
++)
3422 fname
= debug_get_field_name (info
->dhandle
, *pf
);
3425 if (strncmp (fname
, name
, namlen
) == 0
3426 && strlen (fname
) == namlen
)
3428 pslot
= it
->fslots
+ findx
;
3441 ieee_error (info
, start
, _("C++ reference not found"));
3445 /* We allocated the type of the object as an indirect type pointing
3446 to *pslot, which we can now update to be a reference type. */
3447 if (debug_get_type_kind (info
->dhandle
, *pslot
) != DEBUG_KIND_POINTER
)
3449 ieee_error (info
, start
, _("C++ reference is not pointer"));
3453 target
= debug_get_target_type (info
->dhandle
, *pslot
);
3454 *pslot
= debug_make_reference_type (info
->dhandle
, target
);
3455 if (*pslot
== DEBUG_TYPE_NULL
)
3461 /* Require an ASN record. */
3464 ieee_require_asn (struct ieee_info
*info
, const bfd_byte
**pp
, bfd_vma
*pv
)
3466 const bfd_byte
*start
;
3467 ieee_record_enum_type c
;
3472 c
= (ieee_record_enum_type
) **pp
;
3473 if (c
!= ieee_e2_first_byte_enum
)
3475 ieee_error (info
, start
, _("missing required ASN"));
3480 c
= (ieee_record_enum_type
) (((unsigned int) c
<< 8) | **pp
);
3481 if (c
!= ieee_asn_record_enum
)
3483 ieee_error (info
, start
, _("missing required ASN"));
3488 /* Just ignore the variable index. */
3489 if (! ieee_read_number (info
, pp
, &varindx
))
3492 return ieee_read_expression (info
, pp
, pv
);
3495 /* Require an ATN65 record. */
3498 ieee_require_atn65 (struct ieee_info
*info
, const bfd_byte
**pp
,
3499 const char **pname
, unsigned long *pnamlen
)
3501 const bfd_byte
*start
;
3502 ieee_record_enum_type c
;
3503 bfd_vma name_indx
, type_indx
, atn_code
;
3507 c
= (ieee_record_enum_type
) **pp
;
3508 if (c
!= ieee_at_record_enum
)
3510 ieee_error (info
, start
, _("missing required ATN65"));
3515 c
= (ieee_record_enum_type
) (((unsigned int) c
<< 8) | **pp
);
3516 if (c
!= ieee_atn_record_enum
)
3518 ieee_error (info
, start
, _("missing required ATN65"));
3523 if (! ieee_read_number (info
, pp
, &name_indx
)
3524 || ! ieee_read_number (info
, pp
, &type_indx
)
3525 || ! ieee_read_number (info
, pp
, &atn_code
))
3528 /* Just ignore name_indx. */
3530 if (type_indx
!= 0 || atn_code
!= 65)
3532 ieee_error (info
, start
, _("bad ATN65 record"));
3536 return ieee_read_id (info
, pp
, pname
, pnamlen
);
3539 /* Convert a register number in IEEE debugging information into a
3540 generic register number. */
3543 ieee_regno_to_genreg (bfd
*abfd
, int r
)
3545 switch (bfd_get_arch (abfd
))
3548 /* For some reasons stabs adds 2 to the floating point register
3555 /* Stabs uses 0 to 15 for r0 to r15, 16 to 31 for g0 to g15, and
3556 32 to 35 for fp0 to fp3. */
3567 /* Convert a generic register number to an IEEE specific one. */
3570 ieee_genreg_to_regno (bfd
*abfd
, int r
)
3572 switch (bfd_get_arch (abfd
))
3575 /* For some reason stabs add 2 to the floating point register
3582 /* Stabs uses 0 to 15 for r0 to r15, 16 to 31 for g0 to g15, and
3583 32 to 35 for fp0 to fp3. */
3594 /* These routines build IEEE debugging information out of the generic
3595 debugging information. */
3597 /* We build the IEEE debugging information byte by byte. Rather than
3598 waste time copying data around, we use a linked list of buffers to
3601 #define IEEE_BUFSIZE (490)
3606 struct ieee_buf
*next
;
3607 /* Number of data bytes in this buffer. */
3610 bfd_byte buf
[IEEE_BUFSIZE
];
3613 /* A list of buffers. */
3618 struct ieee_buf
*head
;
3619 /* Tail--last buffer on list. */
3620 struct ieee_buf
*tail
;
3623 /* In order to generate the BB11 blocks required by the HP emulator,
3624 we keep track of ranges of addresses which correspond to a given
3625 compilation unit. */
3630 struct ieee_range
*next
;
3637 /* This structure holds information for a class on the type stack. */
3639 struct ieee_type_class
3641 /* The name index in the debugging information. */
3643 /* The pmisc records for the class. */
3644 struct ieee_buflist pmiscbuf
;
3645 /* The number of pmisc records. */
3646 unsigned int pmisccount
;
3647 /* The name of the class holding the virtual table, if not this
3650 /* Whether this class holds its own virtual table. */
3651 bfd_boolean ownvptr
;
3652 /* The largest virtual table offset seen so far. */
3654 /* The current method. */
3656 /* Additional pmisc records used to record fields of reference type. */
3657 struct ieee_buflist refs
;
3660 /* This is how we store types for the writing routines. Most types
3661 are simply represented by a type index. */
3663 struct ieee_write_type
3667 /* The size of the type, if known. */
3669 /* The name of the type, if any. */
3671 /* If this is a function or method type, we build the type here, and
3672 only add it to the output buffers if we need it. */
3673 struct ieee_buflist fndef
;
3674 /* If this is a struct, this is where the struct definition is
3676 struct ieee_buflist strdef
;
3677 /* If this is a class, this is where the class information is built. */
3678 struct ieee_type_class
*classdef
;
3679 /* Whether the type is unsigned. */
3680 unsigned int unsignedp
: 1;
3681 /* Whether this is a reference type. */
3682 unsigned int referencep
: 1;
3683 /* Whether this is in the local type block. */
3684 unsigned int localp
: 1;
3685 /* Whether this is a duplicate struct definition which we are
3687 unsigned int ignorep
: 1;
3690 /* This is the type stack used by the debug writing routines. FIXME:
3691 We could generate more efficient output if we remembered when we
3692 have output a particular type before. */
3694 struct ieee_type_stack
3696 /* Next entry on stack. */
3697 struct ieee_type_stack
*next
;
3698 /* Type information. */
3699 struct ieee_write_type type
;
3702 /* This is a list of associations between a name and some types.
3703 These are used for typedefs and tags. */
3705 struct ieee_name_type
3707 /* Next type for this name. */
3708 struct ieee_name_type
*next
;
3709 /* ID number. For a typedef, this is the index of the type to which
3710 this name is typedefed. */
3713 struct ieee_write_type type
;
3714 /* If this is a tag which has not yet been defined, this is the
3715 kind. If the tag has been defined, this is DEBUG_KIND_ILLEGAL. */
3716 enum debug_type_kind kind
;
3719 /* We use a hash table to associate names and types. */
3721 struct ieee_name_type_hash_table
3723 struct bfd_hash_table root
;
3726 struct ieee_name_type_hash_entry
3728 struct bfd_hash_entry root
;
3729 /* Information for this name. */
3730 struct ieee_name_type
*types
;
3733 /* This is a list of enums. */
3735 struct ieee_defined_enum
3738 struct ieee_defined_enum
*next
;
3741 /* Whether this enum has been defined. */
3742 bfd_boolean defined
;
3748 bfd_signed_vma
*vals
;
3751 /* We keep a list of modified versions of types, so that we don't
3752 output them more than once. */
3754 struct ieee_modified_type
3756 /* Pointer to this type. */
3757 unsigned int pointer
;
3758 /* Function with unknown arguments returning this type. */
3759 unsigned int function
;
3760 /* Const version of this type. */
3761 unsigned int const_qualified
;
3762 /* Volatile version of this type. */
3763 unsigned int volatile_qualified
;
3764 /* List of arrays of this type of various bounds. */
3765 struct ieee_modified_array_type
*arrays
;
3768 /* A list of arrays bounds. */
3770 struct ieee_modified_array_type
3772 /* Next array bounds. */
3773 struct ieee_modified_array_type
*next
;
3774 /* Type index with these bounds. */
3779 bfd_signed_vma high
;
3782 /* This is a list of pending function parameter information. We don't
3783 output them until we see the first block. */
3785 struct ieee_pending_parm
3787 /* Next pending parameter. */
3788 struct ieee_pending_parm
*next
;
3793 /* Whether the type is a reference. */
3794 bfd_boolean referencep
;
3796 enum debug_parm_kind kind
;
3801 /* This is the handle passed down by debug_write. */
3805 /* BFD we are writing to. */
3807 /* Whether we got an error in a subroutine called via traverse or
3808 map_over_sections. */
3810 /* Current data buffer list. */
3811 struct ieee_buflist
*current
;
3812 /* Current data buffer. */
3813 struct ieee_buf
*curbuf
;
3814 /* Filename of current compilation unit. */
3815 const char *filename
;
3816 /* Module name of current compilation unit. */
3817 const char *modname
;
3818 /* List of buffer for global types. */
3819 struct ieee_buflist global_types
;
3820 /* List of finished data buffers. */
3821 struct ieee_buflist data
;
3822 /* List of buffers for typedefs in the current compilation unit. */
3823 struct ieee_buflist types
;
3824 /* List of buffers for variables and functions in the current
3825 compilation unit. */
3826 struct ieee_buflist vars
;
3827 /* List of buffers for C++ class definitions in the current
3828 compilation unit. */
3829 struct ieee_buflist cxx
;
3830 /* List of buffers for line numbers in the current compilation unit. */
3831 struct ieee_buflist linenos
;
3832 /* Ranges for the current compilation unit. */
3833 struct ieee_range
*ranges
;
3834 /* Ranges for all debugging information. */
3835 struct ieee_range
*global_ranges
;
3836 /* Nested pending ranges. */
3837 struct ieee_range
*pending_ranges
;
3839 struct ieee_type_stack
*type_stack
;
3840 /* Next unallocated type index. */
3841 unsigned int type_indx
;
3842 /* Next unallocated name index. */
3843 unsigned int name_indx
;
3845 struct ieee_name_type_hash_table typedefs
;
3847 struct ieee_name_type_hash_table tags
;
3849 struct ieee_defined_enum
*enums
;
3850 /* Modified versions of types. */
3851 struct ieee_modified_type
*modified
;
3852 /* Number of entries allocated in modified. */
3853 unsigned int modified_alloc
;
3854 /* 4 byte complex type. */
3855 unsigned int complex_float_index
;
3856 /* 8 byte complex type. */
3857 unsigned int complex_double_index
;
3858 /* The depth of block nesting. This is 0 outside a function, and 1
3859 just after start_function is called. */
3860 unsigned int block_depth
;
3861 /* The name of the current function. */
3863 /* List of buffers for the type of the function we are currently
3865 struct ieee_buflist fntype
;
3866 /* List of buffers for the parameters of the function we are
3867 currently writing out. */
3868 struct ieee_buflist fnargs
;
3869 /* Number of arguments written to fnargs. */
3870 unsigned int fnargcount
;
3871 /* Pending function parameters. */
3872 struct ieee_pending_parm
*pending_parms
;
3873 /* Current line number filename. */
3874 const char *lineno_filename
;
3875 /* Line number name index. */
3876 unsigned int lineno_name_indx
;
3877 /* Filename of pending line number. */
3878 const char *pending_lineno_filename
;
3879 /* Pending line number. */
3880 unsigned long pending_lineno
;
3881 /* Address of pending line number. */
3882 bfd_vma pending_lineno_addr
;
3883 /* Highest address seen at end of procedure. */
3887 static bfd_boolean ieee_init_buffer
3888 (struct ieee_handle
*, struct ieee_buflist
*);
3889 static bfd_boolean ieee_change_buffer
3890 (struct ieee_handle
*, struct ieee_buflist
*);
3891 static bfd_boolean ieee_append_buffer
3892 (struct ieee_handle
*, struct ieee_buflist
*, struct ieee_buflist
*);
3893 static bfd_boolean
ieee_real_write_byte (struct ieee_handle
*, int);
3894 static bfd_boolean
ieee_write_2bytes (struct ieee_handle
*, int);
3895 static bfd_boolean
ieee_write_number (struct ieee_handle
*, bfd_vma
);
3896 static bfd_boolean
ieee_write_id (struct ieee_handle
*, const char *);
3897 static bfd_boolean ieee_write_asn
3898 (struct ieee_handle
*, unsigned int, bfd_vma
);
3899 static bfd_boolean ieee_write_atn65
3900 (struct ieee_handle
*, unsigned int, const char *);
3901 static bfd_boolean ieee_push_type
3902 (struct ieee_handle
*, unsigned int, unsigned int, bfd_boolean
,
3904 static unsigned int ieee_pop_type (struct ieee_handle
*);
3905 static void ieee_pop_unused_type (struct ieee_handle
*);
3906 static unsigned int ieee_pop_type_used (struct ieee_handle
*, bfd_boolean
);
3907 static bfd_boolean ieee_add_range
3908 (struct ieee_handle
*, bfd_boolean
, bfd_vma
, bfd_vma
);
3909 static bfd_boolean
ieee_start_range (struct ieee_handle
*, bfd_vma
);
3910 static bfd_boolean
ieee_end_range (struct ieee_handle
*, bfd_vma
);
3911 static bfd_boolean ieee_define_type
3912 (struct ieee_handle
*, unsigned int, bfd_boolean
, bfd_boolean
);
3913 static bfd_boolean ieee_define_named_type
3914 (struct ieee_handle
*, const char *, unsigned int, unsigned int,
3915 bfd_boolean
, bfd_boolean
, struct ieee_buflist
*);
3916 static struct ieee_modified_type
*ieee_get_modified_info
3917 (struct ieee_handle
*, unsigned int);
3918 static struct bfd_hash_entry
*ieee_name_type_newfunc
3919 (struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *);
3920 static bfd_boolean ieee_write_undefined_tag
3921 (struct ieee_name_type_hash_entry
*, void *);
3922 static bfd_boolean
ieee_finish_compilation_unit (struct ieee_handle
*);
3923 static void ieee_add_bb11_blocks (bfd
*, asection
*, void *);
3924 static bfd_boolean ieee_add_bb11
3925 (struct ieee_handle
*, asection
*, bfd_vma
, bfd_vma
);
3926 static bfd_boolean
ieee_output_pending_parms (struct ieee_handle
*);
3927 static unsigned int ieee_vis_to_flags (enum debug_visibility
);
3928 static bfd_boolean ieee_class_method_var
3929 (struct ieee_handle
*, const char *, enum debug_visibility
, bfd_boolean
,
3930 bfd_boolean
, bfd_boolean
, bfd_vma
, bfd_boolean
);
3932 static bfd_boolean
ieee_start_compilation_unit (void *, const char *);
3933 static bfd_boolean
ieee_start_source (void *, const char *);
3934 static bfd_boolean
ieee_empty_type (void *);
3935 static bfd_boolean
ieee_void_type (void *);
3936 static bfd_boolean
ieee_int_type (void *, unsigned int, bfd_boolean
);
3937 static bfd_boolean
ieee_float_type (void *, unsigned int);
3938 static bfd_boolean
ieee_complex_type (void *, unsigned int);
3939 static bfd_boolean
ieee_bool_type (void *, unsigned int);
3940 static bfd_boolean ieee_enum_type
3941 (void *, const char *, const char **, bfd_signed_vma
*);
3942 static bfd_boolean
ieee_pointer_type (void *);
3943 static bfd_boolean
ieee_function_type (void *, int, bfd_boolean
);
3944 static bfd_boolean
ieee_reference_type (void *);
3945 static bfd_boolean
ieee_range_type (void *, bfd_signed_vma
, bfd_signed_vma
);
3946 static bfd_boolean ieee_array_type
3947 (void *, bfd_signed_vma
, bfd_signed_vma
, bfd_boolean
);
3948 static bfd_boolean
ieee_set_type (void *, bfd_boolean
);
3949 static bfd_boolean
ieee_offset_type (void *);
3950 static bfd_boolean
ieee_method_type (void *, bfd_boolean
, int, bfd_boolean
);
3951 static bfd_boolean
ieee_const_type (void *);
3952 static bfd_boolean
ieee_volatile_type (void *);
3953 static bfd_boolean ieee_start_struct_type
3954 (void *, const char *, unsigned int, bfd_boolean
, unsigned int);
3955 static bfd_boolean ieee_struct_field
3956 (void *, const char *, bfd_vma
, bfd_vma
, enum debug_visibility
);
3957 static bfd_boolean
ieee_end_struct_type (void *);
3958 static bfd_boolean ieee_start_class_type
3959 (void *, const char *, unsigned int, bfd_boolean
, unsigned int, bfd_boolean
,
3961 static bfd_boolean ieee_class_static_member
3962 (void *, const char *, const char *, enum debug_visibility
);
3963 static bfd_boolean ieee_class_baseclass
3964 (void *, bfd_vma
, bfd_boolean
, enum debug_visibility
);
3965 static bfd_boolean
ieee_class_start_method (void *, const char *);
3966 static bfd_boolean ieee_class_method_variant
3967 (void *, const char *, enum debug_visibility
, bfd_boolean
, bfd_boolean
,
3968 bfd_vma
, bfd_boolean
);
3969 static bfd_boolean ieee_class_static_method_variant
3970 (void *, const char *, enum debug_visibility
, bfd_boolean
, bfd_boolean
);
3971 static bfd_boolean
ieee_class_end_method (void *);
3972 static bfd_boolean
ieee_end_class_type (void *);
3973 static bfd_boolean
ieee_typedef_type (void *, const char *);
3974 static bfd_boolean ieee_tag_type
3975 (void *, const char *, unsigned int, enum debug_type_kind
);
3976 static bfd_boolean
ieee_typdef (void *, const char *);
3977 static bfd_boolean
ieee_tag (void *, const char *);
3978 static bfd_boolean
ieee_int_constant (void *, const char *, bfd_vma
);
3979 static bfd_boolean
ieee_float_constant (void *, const char *, double);
3980 static bfd_boolean
ieee_typed_constant (void *, const char *, bfd_vma
);
3981 static bfd_boolean ieee_variable
3982 (void *, const char *, enum debug_var_kind
, bfd_vma
);
3983 static bfd_boolean
ieee_start_function (void *, const char *, bfd_boolean
);
3984 static bfd_boolean ieee_function_parameter
3985 (void *, const char *, enum debug_parm_kind
, bfd_vma
);
3986 static bfd_boolean
ieee_start_block (void *, bfd_vma
);
3987 static bfd_boolean
ieee_end_block (void *, bfd_vma
);
3988 static bfd_boolean
ieee_end_function (void *);
3989 static bfd_boolean
ieee_lineno (void *, const char *, unsigned long, bfd_vma
);
3991 static const struct debug_write_fns ieee_fns
=
3993 ieee_start_compilation_unit
,
4004 ieee_reference_type
,
4012 ieee_start_struct_type
,
4014 ieee_end_struct_type
,
4015 ieee_start_class_type
,
4016 ieee_class_static_member
,
4017 ieee_class_baseclass
,
4018 ieee_class_start_method
,
4019 ieee_class_method_variant
,
4020 ieee_class_static_method_variant
,
4021 ieee_class_end_method
,
4022 ieee_end_class_type
,
4028 ieee_float_constant
,
4029 ieee_typed_constant
,
4031 ieee_start_function
,
4032 ieee_function_parameter
,
4039 /* Initialize a buffer to be empty. */
4042 ieee_init_buffer (struct ieee_handle
*info ATTRIBUTE_UNUSED
,
4043 struct ieee_buflist
*buflist
)
4045 buflist
->head
= NULL
;
4046 buflist
->tail
= NULL
;
4050 /* See whether a buffer list has any data. */
4052 #define ieee_buffer_emptyp(buflist) ((buflist)->head == NULL)
4054 /* Change the current buffer to a specified buffer chain. */
4057 ieee_change_buffer (struct ieee_handle
*info
, struct ieee_buflist
*buflist
)
4059 if (buflist
->head
== NULL
)
4061 struct ieee_buf
*buf
;
4063 buf
= (struct ieee_buf
*) xmalloc (sizeof *buf
);
4066 buflist
->head
= buf
;
4067 buflist
->tail
= buf
;
4070 info
->current
= buflist
;
4071 info
->curbuf
= buflist
->tail
;
4076 /* Append a buffer chain. */
4079 ieee_append_buffer (struct ieee_handle
*info ATTRIBUTE_UNUSED
,
4080 struct ieee_buflist
*mainbuf
,
4081 struct ieee_buflist
*newbuf
)
4083 if (newbuf
->head
!= NULL
)
4085 if (mainbuf
->head
== NULL
)
4086 mainbuf
->head
= newbuf
->head
;
4088 mainbuf
->tail
->next
= newbuf
->head
;
4089 mainbuf
->tail
= newbuf
->tail
;
4094 /* Write a byte into the buffer. We use a macro for speed and a
4095 function for the complex cases. */
4097 #define ieee_write_byte(info, b) \
4098 ((info)->curbuf->c < IEEE_BUFSIZE \
4099 ? ((info)->curbuf->buf[(info)->curbuf->c++] = (b), TRUE) \
4100 : ieee_real_write_byte ((info), (b)))
4103 ieee_real_write_byte (struct ieee_handle
*info
, int b
)
4105 if (info
->curbuf
->c
>= IEEE_BUFSIZE
)
4109 n
= (struct ieee_buf
*) xmalloc (sizeof *n
);
4112 if (info
->current
->head
== NULL
)
4113 info
->current
->head
= n
;
4115 info
->current
->tail
->next
= n
;
4116 info
->current
->tail
= n
;
4120 info
->curbuf
->buf
[info
->curbuf
->c
] = b
;
4126 /* Write out two bytes. */
4129 ieee_write_2bytes (struct ieee_handle
*info
, int i
)
4131 return (ieee_write_byte (info
, i
>> 8)
4132 && ieee_write_byte (info
, i
& 0xff));
4135 /* Write out an integer. */
4138 ieee_write_number (struct ieee_handle
*info
, bfd_vma v
)
4145 if (v
<= (bfd_vma
) ieee_number_end_enum
)
4146 return ieee_write_byte (info
, (int) v
);
4157 if (c
> (unsigned int) (ieee_number_repeat_end_enum
4158 - ieee_number_repeat_start_enum
))
4160 fprintf (stderr
, _("IEEE numeric overflow: 0x"));
4161 fprintf_vma (stderr
, v
);
4162 fprintf (stderr
, "\n");
4166 if (! ieee_write_byte (info
, (int) ieee_number_repeat_start_enum
+ c
))
4168 for (; c
> 0; --c
, ++p
)
4170 if (! ieee_write_byte (info
, *p
))
4177 /* Write out a string. */
4180 ieee_write_id (struct ieee_handle
*info
, const char *s
)
4187 if (! ieee_write_byte (info
, len
))
4190 else if (len
<= 0xff)
4192 if (! ieee_write_byte (info
, (int) ieee_extension_length_1_enum
)
4193 || ! ieee_write_byte (info
, len
))
4196 else if (len
<= 0xffff)
4198 if (! ieee_write_byte (info
, (int) ieee_extension_length_2_enum
)
4199 || ! ieee_write_2bytes (info
, len
))
4204 fprintf (stderr
, _("IEEE string length overflow: %u\n"), len
);
4208 for (; *s
!= '\0'; s
++)
4209 if (! ieee_write_byte (info
, *s
))
4215 /* Write out an ASN record. */
4218 ieee_write_asn (struct ieee_handle
*info
, unsigned int indx
, bfd_vma val
)
4220 return (ieee_write_2bytes (info
, (int) ieee_asn_record_enum
)
4221 && ieee_write_number (info
, indx
)
4222 && ieee_write_number (info
, val
));
4225 /* Write out an ATN65 record. */
4228 ieee_write_atn65 (struct ieee_handle
*info
, unsigned int indx
, const char *s
)
4230 return (ieee_write_2bytes (info
, (int) ieee_atn_record_enum
)
4231 && ieee_write_number (info
, indx
)
4232 && ieee_write_number (info
, 0)
4233 && ieee_write_number (info
, 65)
4234 && ieee_write_id (info
, s
));
4237 /* Push a type index onto the type stack. */
4240 ieee_push_type (struct ieee_handle
*info
, unsigned int indx
,
4241 unsigned int size
, bfd_boolean unsignedp
, bfd_boolean localp
)
4243 struct ieee_type_stack
*ts
;
4245 ts
= (struct ieee_type_stack
*) xmalloc (sizeof *ts
);
4246 memset (ts
, 0, sizeof *ts
);
4248 ts
->type
.indx
= indx
;
4249 ts
->type
.size
= size
;
4250 ts
->type
.unsignedp
= unsignedp
;
4251 ts
->type
.localp
= localp
;
4253 ts
->next
= info
->type_stack
;
4254 info
->type_stack
= ts
;
4259 /* Pop a type index off the type stack. */
4262 ieee_pop_type (struct ieee_handle
*info
)
4264 return ieee_pop_type_used (info
, TRUE
);
4267 /* Pop an unused type index off the type stack. */
4270 ieee_pop_unused_type (struct ieee_handle
*info
)
4272 (void) ieee_pop_type_used (info
, FALSE
);
4275 /* Pop a used or unused type index off the type stack. */
4278 ieee_pop_type_used (struct ieee_handle
*info
, bfd_boolean used
)
4280 struct ieee_type_stack
*ts
;
4283 ts
= info
->type_stack
;
4284 assert (ts
!= NULL
);
4286 /* If this is a function type, and we need it, we need to append the
4287 actual definition to the typedef block now. */
4288 if (used
&& ! ieee_buffer_emptyp (&ts
->type
.fndef
))
4290 struct ieee_buflist
*buflist
;
4292 if (ts
->type
.localp
)
4294 /* Make sure we have started the types block. */
4295 if (ieee_buffer_emptyp (&info
->types
))
4297 if (! ieee_change_buffer (info
, &info
->types
)
4298 || ! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
4299 || ! ieee_write_byte (info
, 1)
4300 || ! ieee_write_number (info
, 0)
4301 || ! ieee_write_id (info
, info
->modname
))
4304 buflist
= &info
->types
;
4308 /* Make sure we started the global type block. */
4309 if (ieee_buffer_emptyp (&info
->global_types
))
4311 if (! ieee_change_buffer (info
, &info
->global_types
)
4312 || ! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
4313 || ! ieee_write_byte (info
, 2)
4314 || ! ieee_write_number (info
, 0)
4315 || ! ieee_write_id (info
, ""))
4318 buflist
= &info
->global_types
;
4321 if (! ieee_append_buffer (info
, buflist
, &ts
->type
.fndef
))
4325 ret
= ts
->type
.indx
;
4326 info
->type_stack
= ts
->next
;
4331 /* Add a range of bytes included in the current compilation unit. */
4334 ieee_add_range (struct ieee_handle
*info
, bfd_boolean global
, bfd_vma low
,
4337 struct ieee_range
**plist
, *r
, **pr
;
4339 if (low
== (bfd_vma
) -1 || high
== (bfd_vma
) -1 || low
== high
)
4343 plist
= &info
->global_ranges
;
4345 plist
= &info
->ranges
;
4347 for (r
= *plist
; r
!= NULL
; r
= r
->next
)
4349 if (high
>= r
->low
&& low
<= r
->high
)
4351 /* The new range overlaps r. */
4357 while (*pr
!= NULL
&& (*pr
)->low
<= r
->high
)
4359 struct ieee_range
*n
;
4361 if ((*pr
)->high
> r
->high
)
4362 r
->high
= (*pr
)->high
;
4371 r
= (struct ieee_range
*) xmalloc (sizeof *r
);
4372 memset (r
, 0, sizeof *r
);
4377 /* Store the ranges sorted by address. */
4378 for (pr
= plist
; *pr
!= NULL
; pr
= &(*pr
)->next
)
4379 if ((*pr
)->low
> high
)
4387 /* Start a new range for which we only have the low address. */
4390 ieee_start_range (struct ieee_handle
*info
, bfd_vma low
)
4392 struct ieee_range
*r
;
4394 r
= (struct ieee_range
*) xmalloc (sizeof *r
);
4395 memset (r
, 0, sizeof *r
);
4397 r
->next
= info
->pending_ranges
;
4398 info
->pending_ranges
= r
;
4402 /* Finish a range started by ieee_start_range. */
4405 ieee_end_range (struct ieee_handle
*info
, bfd_vma high
)
4407 struct ieee_range
*r
;
4410 assert (info
->pending_ranges
!= NULL
);
4411 r
= info
->pending_ranges
;
4413 info
->pending_ranges
= r
->next
;
4415 return ieee_add_range (info
, FALSE
, low
, high
);
4418 /* Start defining a type. */
4421 ieee_define_type (struct ieee_handle
*info
, unsigned int size
,
4422 bfd_boolean unsignedp
, bfd_boolean localp
)
4424 return ieee_define_named_type (info
, (const char *) NULL
,
4425 (unsigned int) -1, size
, unsignedp
,
4426 localp
, (struct ieee_buflist
*) NULL
);
4429 /* Start defining a named type. */
4432 ieee_define_named_type (struct ieee_handle
*info
, const char *name
,
4433 unsigned int indx
, unsigned int size
,
4434 bfd_boolean unsignedp
, bfd_boolean localp
,
4435 struct ieee_buflist
*buflist
)
4437 unsigned int type_indx
;
4438 unsigned int name_indx
;
4440 if (indx
!= (unsigned int) -1)
4444 type_indx
= info
->type_indx
;
4448 name_indx
= info
->name_indx
;
4454 /* If we were given a buffer, use it; otherwise, use either the
4455 local or the global type information, and make sure that the type
4456 block is started. */
4457 if (buflist
!= NULL
)
4459 if (! ieee_change_buffer (info
, buflist
))
4464 if (! ieee_buffer_emptyp (&info
->types
))
4466 if (! ieee_change_buffer (info
, &info
->types
))
4471 if (! ieee_change_buffer (info
, &info
->types
)
4472 || ! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
4473 || ! ieee_write_byte (info
, 1)
4474 || ! ieee_write_number (info
, 0)
4475 || ! ieee_write_id (info
, info
->modname
))
4481 if (! ieee_buffer_emptyp (&info
->global_types
))
4483 if (! ieee_change_buffer (info
, &info
->global_types
))
4488 if (! ieee_change_buffer (info
, &info
->global_types
)
4489 || ! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
4490 || ! ieee_write_byte (info
, 2)
4491 || ! ieee_write_number (info
, 0)
4492 || ! ieee_write_id (info
, ""))
4497 /* Push the new type on the type stack, write out an NN record, and
4498 write out the start of a TY record. The caller will then finish
4500 if (! ieee_push_type (info
, type_indx
, size
, unsignedp
, localp
))
4503 return (ieee_write_byte (info
, (int) ieee_nn_record
)
4504 && ieee_write_number (info
, name_indx
)
4505 && ieee_write_id (info
, name
)
4506 && ieee_write_byte (info
, (int) ieee_ty_record_enum
)
4507 && ieee_write_number (info
, type_indx
)
4508 && ieee_write_byte (info
, 0xce)
4509 && ieee_write_number (info
, name_indx
));
4512 /* Get an entry to the list of modified versions of a type. */
4514 static struct ieee_modified_type
*
4515 ieee_get_modified_info (struct ieee_handle
*info
, unsigned int indx
)
4517 if (indx
>= info
->modified_alloc
)
4519 unsigned int nalloc
;
4521 nalloc
= info
->modified_alloc
;
4524 while (indx
>= nalloc
)
4526 info
->modified
= ((struct ieee_modified_type
*)
4527 xrealloc (info
->modified
,
4528 nalloc
* sizeof *info
->modified
));
4529 memset (info
->modified
+ info
->modified_alloc
, 0,
4530 (nalloc
- info
->modified_alloc
) * sizeof *info
->modified
);
4531 info
->modified_alloc
= nalloc
;
4534 return info
->modified
+ indx
;
4537 /* Routines for the hash table mapping names to types. */
4539 /* Initialize an entry in the hash table. */
4541 static struct bfd_hash_entry
*
4542 ieee_name_type_newfunc (struct bfd_hash_entry
*entry
,
4543 struct bfd_hash_table
*table
, const char *string
)
4545 struct ieee_name_type_hash_entry
*ret
=
4546 (struct ieee_name_type_hash_entry
*) entry
;
4548 /* Allocate the structure if it has not already been allocated by a
4551 ret
= ((struct ieee_name_type_hash_entry
*)
4552 bfd_hash_allocate (table
, sizeof *ret
));
4556 /* Call the allocation method of the superclass. */
4557 ret
= ((struct ieee_name_type_hash_entry
*)
4558 bfd_hash_newfunc ((struct bfd_hash_entry
*) ret
, table
, string
));
4561 /* Set local fields. */
4565 return (struct bfd_hash_entry
*) ret
;
4568 /* Look up an entry in the hash table. */
4570 #define ieee_name_type_hash_lookup(table, string, create, copy) \
4571 ((struct ieee_name_type_hash_entry *) \
4572 bfd_hash_lookup (&(table)->root, (string), (create), (copy)))
4574 /* Traverse the hash table. */
4576 #define ieee_name_type_hash_traverse(table, func, info) \
4577 (bfd_hash_traverse \
4579 (bfd_boolean (*) (struct bfd_hash_entry *, void *)) (func), \
4582 /* The general routine to write out IEEE debugging information. */
4585 write_ieee_debugging_info (bfd
*abfd
, void *dhandle
)
4587 struct ieee_handle info
;
4592 memset (&info
, 0, sizeof info
);
4594 info
.type_indx
= 256;
4595 info
.name_indx
= 32;
4597 if (! bfd_hash_table_init (&info
.typedefs
.root
, ieee_name_type_newfunc
)
4598 || ! bfd_hash_table_init (&info
.tags
.root
, ieee_name_type_newfunc
))
4601 if (! ieee_init_buffer (&info
, &info
.global_types
)
4602 || ! ieee_init_buffer (&info
, &info
.data
)
4603 || ! ieee_init_buffer (&info
, &info
.types
)
4604 || ! ieee_init_buffer (&info
, &info
.vars
)
4605 || ! ieee_init_buffer (&info
, &info
.cxx
)
4606 || ! ieee_init_buffer (&info
, &info
.linenos
)
4607 || ! ieee_init_buffer (&info
, &info
.fntype
)
4608 || ! ieee_init_buffer (&info
, &info
.fnargs
))
4611 if (! debug_write (dhandle
, &ieee_fns
, (void *) &info
))
4614 if (info
.filename
!= NULL
)
4616 if (! ieee_finish_compilation_unit (&info
))
4620 /* Put any undefined tags in the global typedef information. */
4622 ieee_name_type_hash_traverse (&info
.tags
,
4623 ieee_write_undefined_tag
,
4628 /* Prepend the global typedef information to the other data. */
4629 if (! ieee_buffer_emptyp (&info
.global_types
))
4631 /* The HP debugger seems to have a bug in which it ignores the
4632 last entry in the global types, so we add a dummy entry. */
4633 if (! ieee_change_buffer (&info
, &info
.global_types
)
4634 || ! ieee_write_byte (&info
, (int) ieee_nn_record
)
4635 || ! ieee_write_number (&info
, info
.name_indx
)
4636 || ! ieee_write_id (&info
, "")
4637 || ! ieee_write_byte (&info
, (int) ieee_ty_record_enum
)
4638 || ! ieee_write_number (&info
, info
.type_indx
)
4639 || ! ieee_write_byte (&info
, 0xce)
4640 || ! ieee_write_number (&info
, info
.name_indx
)
4641 || ! ieee_write_number (&info
, 'P')
4642 || ! ieee_write_number (&info
, (int) builtin_void
+ 32)
4643 || ! ieee_write_byte (&info
, (int) ieee_be_record_enum
))
4646 if (! ieee_append_buffer (&info
, &info
.global_types
, &info
.data
))
4648 info
.data
= info
.global_types
;
4651 /* Make sure that we have declare BB11 blocks for each range in the
4652 file. They are added to info->vars. */
4654 if (! ieee_init_buffer (&info
, &info
.vars
))
4656 bfd_map_over_sections (abfd
, ieee_add_bb11_blocks
, (void *) &info
);
4659 if (! ieee_buffer_emptyp (&info
.vars
))
4661 if (! ieee_change_buffer (&info
, &info
.vars
)
4662 || ! ieee_write_byte (&info
, (int) ieee_be_record_enum
))
4665 if (! ieee_append_buffer (&info
, &info
.data
, &info
.vars
))
4669 /* Now all the data is in info.data. Write it out to the BFD. We
4670 normally would need to worry about whether all the other sections
4671 are set up yet, but the IEEE backend will handle this particular
4672 case correctly regardless. */
4673 if (ieee_buffer_emptyp (&info
.data
))
4675 /* There is no debugging information. */
4679 s
= bfd_make_section (abfd
, ".debug");
4681 err
= "bfd_make_section";
4684 if (! bfd_set_section_flags (abfd
, s
, SEC_DEBUGGING
| SEC_HAS_CONTENTS
))
4685 err
= "bfd_set_section_flags";
4692 for (b
= info
.data
.head
; b
!= NULL
; b
= b
->next
)
4694 if (! bfd_set_section_size (abfd
, s
, size
))
4695 err
= "bfd_set_section_size";
4702 for (b
= info
.data
.head
; b
!= NULL
; b
= b
->next
)
4704 if (! bfd_set_section_contents (abfd
, s
, b
->buf
, offset
, b
->c
))
4706 err
= "bfd_set_section_contents";
4715 fprintf (stderr
, "%s: %s: %s\n", bfd_get_filename (abfd
), err
,
4716 bfd_errmsg (bfd_get_error ()));
4720 bfd_hash_table_free (&info
.typedefs
.root
);
4721 bfd_hash_table_free (&info
.tags
.root
);
4726 /* Write out information for an undefined tag. This is called via
4727 ieee_name_type_hash_traverse. */
4730 ieee_write_undefined_tag (struct ieee_name_type_hash_entry
*h
, void *p
)
4732 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
4733 struct ieee_name_type
*nt
;
4735 for (nt
= h
->types
; nt
!= NULL
; nt
= nt
->next
)
4737 unsigned int name_indx
;
4740 if (nt
->kind
== DEBUG_KIND_ILLEGAL
)
4743 if (ieee_buffer_emptyp (&info
->global_types
))
4745 if (! ieee_change_buffer (info
, &info
->global_types
)
4746 || ! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
4747 || ! ieee_write_byte (info
, 2)
4748 || ! ieee_write_number (info
, 0)
4749 || ! ieee_write_id (info
, ""))
4757 if (! ieee_change_buffer (info
, &info
->global_types
))
4764 name_indx
= info
->name_indx
;
4766 if (! ieee_write_byte (info
, (int) ieee_nn_record
)
4767 || ! ieee_write_number (info
, name_indx
)
4768 || ! ieee_write_id (info
, nt
->type
.name
)
4769 || ! ieee_write_byte (info
, (int) ieee_ty_record_enum
)
4770 || ! ieee_write_number (info
, nt
->type
.indx
)
4771 || ! ieee_write_byte (info
, 0xce)
4772 || ! ieee_write_number (info
, name_indx
))
4784 case DEBUG_KIND_STRUCT
:
4785 case DEBUG_KIND_CLASS
:
4788 case DEBUG_KIND_UNION
:
4789 case DEBUG_KIND_UNION_CLASS
:
4792 case DEBUG_KIND_ENUM
:
4796 if (! ieee_write_number (info
, code
)
4797 || ! ieee_write_number (info
, 0))
4807 /* Start writing out information for a compilation unit. */
4810 ieee_start_compilation_unit (void *p
, const char *filename
)
4812 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
4813 const char *modname
;
4814 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
4815 const char *backslash
;
4820 if (info
->filename
!= NULL
)
4822 if (! ieee_finish_compilation_unit (info
))
4826 info
->filename
= filename
;
4827 modname
= strrchr (filename
, '/');
4828 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
4829 /* We could have a mixed forward/back slash case. */
4830 backslash
= strrchr (filename
, '\\');
4831 if (modname
== NULL
|| (backslash
!= NULL
&& backslash
> modname
))
4832 modname
= backslash
;
4835 if (modname
!= NULL
)
4837 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
4838 else if (filename
[0] && filename
[1] == ':')
4839 modname
= filename
+ 2;
4844 c
= xstrdup (modname
);
4845 s
= strrchr (c
, '.');
4850 if (! ieee_init_buffer (info
, &info
->types
)
4851 || ! ieee_init_buffer (info
, &info
->vars
)
4852 || ! ieee_init_buffer (info
, &info
->cxx
)
4853 || ! ieee_init_buffer (info
, &info
->linenos
))
4855 info
->ranges
= NULL
;
4857 /* Always include a BB1 and a BB3 block. That is what the output of
4858 the MRI linker seems to look like. */
4859 if (! ieee_change_buffer (info
, &info
->types
)
4860 || ! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
4861 || ! ieee_write_byte (info
, 1)
4862 || ! ieee_write_number (info
, 0)
4863 || ! ieee_write_id (info
, info
->modname
))
4866 nindx
= info
->name_indx
;
4868 if (! ieee_change_buffer (info
, &info
->vars
)
4869 || ! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
4870 || ! ieee_write_byte (info
, 3)
4871 || ! ieee_write_number (info
, 0)
4872 || ! ieee_write_id (info
, info
->modname
))
4878 /* Finish up a compilation unit. */
4881 ieee_finish_compilation_unit (struct ieee_handle
*info
)
4883 struct ieee_range
*r
;
4885 if (! ieee_buffer_emptyp (&info
->types
))
4887 if (! ieee_change_buffer (info
, &info
->types
)
4888 || ! ieee_write_byte (info
, (int) ieee_be_record_enum
))
4892 if (! ieee_buffer_emptyp (&info
->cxx
))
4894 /* Append any C++ information to the global function and
4895 variable information. */
4896 assert (! ieee_buffer_emptyp (&info
->vars
));
4897 if (! ieee_change_buffer (info
, &info
->vars
))
4900 /* We put the pmisc records in a dummy procedure, just as the
4901 MRI compiler does. */
4902 if (! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
4903 || ! ieee_write_byte (info
, 6)
4904 || ! ieee_write_number (info
, 0)
4905 || ! ieee_write_id (info
, "__XRYCPP")
4906 || ! ieee_write_number (info
, 0)
4907 || ! ieee_write_number (info
, 0)
4908 || ! ieee_write_number (info
, info
->highaddr
- 1)
4909 || ! ieee_append_buffer (info
, &info
->vars
, &info
->cxx
)
4910 || ! ieee_change_buffer (info
, &info
->vars
)
4911 || ! ieee_write_byte (info
, (int) ieee_be_record_enum
)
4912 || ! ieee_write_number (info
, info
->highaddr
- 1))
4916 if (! ieee_buffer_emptyp (&info
->vars
))
4918 if (! ieee_change_buffer (info
, &info
->vars
)
4919 || ! ieee_write_byte (info
, (int) ieee_be_record_enum
))
4923 if (info
->pending_lineno_filename
!= NULL
)
4925 /* Force out the pending line number. */
4926 if (! ieee_lineno ((void *) info
, (const char *) NULL
, 0, (bfd_vma
) -1))
4929 if (! ieee_buffer_emptyp (&info
->linenos
))
4931 if (! ieee_change_buffer (info
, &info
->linenos
)
4932 || ! ieee_write_byte (info
, (int) ieee_be_record_enum
))
4934 if (strcmp (info
->filename
, info
->lineno_filename
) != 0)
4936 /* We were not in the main file. We just closed the
4937 included line number block, and now we must close the
4938 main line number block. */
4939 if (! ieee_write_byte (info
, (int) ieee_be_record_enum
))
4944 if (! ieee_append_buffer (info
, &info
->data
, &info
->types
)
4945 || ! ieee_append_buffer (info
, &info
->data
, &info
->vars
)
4946 || ! ieee_append_buffer (info
, &info
->data
, &info
->linenos
))
4949 /* Build BB10/BB11 blocks based on the ranges we recorded. */
4950 if (! ieee_change_buffer (info
, &info
->data
))
4953 if (! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
4954 || ! ieee_write_byte (info
, 10)
4955 || ! ieee_write_number (info
, 0)
4956 || ! ieee_write_id (info
, info
->modname
)
4957 || ! ieee_write_id (info
, "")
4958 || ! ieee_write_number (info
, 0)
4959 || ! ieee_write_id (info
, "GNU objcopy"))
4962 for (r
= info
->ranges
; r
!= NULL
; r
= r
->next
)
4971 /* Find the section corresponding to this range. */
4972 for (s
= info
->abfd
->sections
; s
!= NULL
; s
= s
->next
)
4974 if (bfd_get_section_vma (info
->abfd
, s
) <= low
4975 && high
<= (bfd_get_section_vma (info
->abfd
, s
)
4976 + bfd_section_size (info
->abfd
, s
)))
4982 /* Just ignore this range. */
4986 /* Coalesce ranges if it seems reasonable. */
4987 while (r
->next
!= NULL
4988 && high
+ 0x1000 >= r
->next
->low
4990 <= (bfd_get_section_vma (info
->abfd
, s
)
4991 + bfd_section_size (info
->abfd
, s
))))
4997 if ((s
->flags
& SEC_CODE
) != 0)
4999 else if ((s
->flags
& SEC_READONLY
) != 0)
5004 if (! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
5005 || ! ieee_write_byte (info
, 11)
5006 || ! ieee_write_number (info
, 0)
5007 || ! ieee_write_id (info
, "")
5008 || ! ieee_write_number (info
, kind
)
5009 || ! ieee_write_number (info
, s
->index
+ IEEE_SECTION_NUMBER_BASE
)
5010 || ! ieee_write_number (info
, low
)
5011 || ! ieee_write_byte (info
, (int) ieee_be_record_enum
)
5012 || ! ieee_write_number (info
, high
- low
))
5015 /* Add this range to the list of global ranges. */
5016 if (! ieee_add_range (info
, TRUE
, low
, high
))
5020 if (! ieee_write_byte (info
, (int) ieee_be_record_enum
))
5026 /* Add BB11 blocks describing each range that we have not already
5030 ieee_add_bb11_blocks (bfd
*abfd ATTRIBUTE_UNUSED
, asection
*sec
, void *data
)
5032 struct ieee_handle
*info
= (struct ieee_handle
*) data
;
5034 struct ieee_range
*r
;
5036 low
= bfd_get_section_vma (abfd
, sec
);
5037 high
= low
+ bfd_section_size (abfd
, sec
);
5039 /* Find the first range at or after this section. The ranges are
5040 sorted by address. */
5041 for (r
= info
->global_ranges
; r
!= NULL
; r
= r
->next
)
5047 if (r
== NULL
|| r
->low
>= high
)
5049 if (! ieee_add_bb11 (info
, sec
, low
, high
))
5055 && r
->low
- low
> 0x100)
5057 if (! ieee_add_bb11 (info
, sec
, low
, r
->low
))
5069 /* Add a single BB11 block for a range. We add it to info->vars. */
5072 ieee_add_bb11 (struct ieee_handle
*info
, asection
*sec
, bfd_vma low
,
5077 if (! ieee_buffer_emptyp (&info
->vars
))
5079 if (! ieee_change_buffer (info
, &info
->vars
))
5084 const char *filename
, *modname
;
5085 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
5086 const char *backslash
;
5090 /* Start the enclosing BB10 block. */
5091 filename
= bfd_get_filename (info
->abfd
);
5092 modname
= strrchr (filename
, '/');
5093 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
5094 backslash
= strrchr (filename
, '\\');
5095 if (modname
== NULL
|| (backslash
!= NULL
&& backslash
> modname
))
5096 modname
= backslash
;
5099 if (modname
!= NULL
)
5101 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
5102 else if (filename
[0] && filename
[1] == ':')
5103 modname
= filename
+ 2;
5108 c
= xstrdup (modname
);
5109 s
= strrchr (c
, '.');
5113 if (! ieee_change_buffer (info
, &info
->vars
)
5114 || ! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
5115 || ! ieee_write_byte (info
, 10)
5116 || ! ieee_write_number (info
, 0)
5117 || ! ieee_write_id (info
, c
)
5118 || ! ieee_write_id (info
, "")
5119 || ! ieee_write_number (info
, 0)
5120 || ! ieee_write_id (info
, "GNU objcopy"))
5126 if ((sec
->flags
& SEC_CODE
) != 0)
5128 else if ((sec
->flags
& SEC_READONLY
) != 0)
5133 if (! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
5134 || ! ieee_write_byte (info
, 11)
5135 || ! ieee_write_number (info
, 0)
5136 || ! ieee_write_id (info
, "")
5137 || ! ieee_write_number (info
, kind
)
5138 || ! ieee_write_number (info
, sec
->index
+ IEEE_SECTION_NUMBER_BASE
)
5139 || ! ieee_write_number (info
, low
)
5140 || ! ieee_write_byte (info
, (int) ieee_be_record_enum
)
5141 || ! ieee_write_number (info
, high
- low
))
5147 /* Start recording information from a particular source file. This is
5148 used to record which file defined which types, variables, etc. It
5149 is not used for line numbers, since the lineno entry point passes
5150 down the file name anyhow. IEEE debugging information doesn't seem
5151 to store this information anywhere. */
5154 ieee_start_source (void *p ATTRIBUTE_UNUSED
,
5155 const char *filename ATTRIBUTE_UNUSED
)
5160 /* Make an empty type. */
5163 ieee_empty_type (void *p
)
5165 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
5167 return ieee_push_type (info
, (int) builtin_unknown
, 0, FALSE
, FALSE
);
5170 /* Make a void type. */
5173 ieee_void_type (void *p
)
5175 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
5177 return ieee_push_type (info
, (int) builtin_void
, 0, FALSE
, FALSE
);
5180 /* Make an integer type. */
5183 ieee_int_type (void *p
, unsigned int size
, bfd_boolean unsignedp
)
5185 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
5191 indx
= (int) builtin_signed_char
;
5194 indx
= (int) builtin_signed_short_int
;
5197 indx
= (int) builtin_signed_long
;
5200 indx
= (int) builtin_signed_long_long
;
5203 fprintf (stderr
, _("IEEE unsupported integer type size %u\n"), size
);
5210 return ieee_push_type (info
, indx
, size
, unsignedp
, FALSE
);
5213 /* Make a floating point type. */
5216 ieee_float_type (void *p
, unsigned int size
)
5218 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
5224 indx
= (int) builtin_float
;
5227 indx
= (int) builtin_double
;
5230 /* FIXME: This size really depends upon the processor. */
5231 indx
= (int) builtin_long_double
;
5234 indx
= (int) builtin_long_long_double
;
5237 fprintf (stderr
, _("IEEE unsupported float type size %u\n"), size
);
5241 return ieee_push_type (info
, indx
, size
, FALSE
, FALSE
);
5244 /* Make a complex type. */
5247 ieee_complex_type (void *p
, unsigned int size
)
5249 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
5255 if (info
->complex_float_index
!= 0)
5256 return ieee_push_type (info
, info
->complex_float_index
, size
* 2,
5262 /* These cases can be output by gcc -gstabs. Outputting the
5263 wrong type is better than crashing. */
5265 if (info
->complex_double_index
!= 0)
5266 return ieee_push_type (info
, info
->complex_double_index
, size
* 2,
5271 fprintf (stderr
, _("IEEE unsupported complex type size %u\n"), size
);
5275 /* FIXME: I don't know what the string is for. */
5276 if (! ieee_define_type (info
, size
* 2, FALSE
, FALSE
)
5277 || ! ieee_write_number (info
, code
)
5278 || ! ieee_write_id (info
, ""))
5282 info
->complex_float_index
= info
->type_stack
->type
.indx
;
5284 info
->complex_double_index
= info
->type_stack
->type
.indx
;
5289 /* Make a boolean type. IEEE doesn't support these, so we just make
5290 an integer type instead. */
5293 ieee_bool_type (void *p
, unsigned int size
)
5295 return ieee_int_type (p
, size
, TRUE
);
5298 /* Make an enumeration. */
5301 ieee_enum_type (void *p
, const char *tag
, const char **names
,
5302 bfd_signed_vma
*vals
)
5304 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
5305 struct ieee_defined_enum
*e
;
5306 bfd_boolean localp
, simple
;
5311 indx
= (unsigned int) -1;
5312 for (e
= info
->enums
; e
!= NULL
; e
= e
->next
)
5322 || tag
[0] != e
->tag
[0]
5323 || strcmp (tag
, e
->tag
) != 0)
5329 /* This enum tag has been seen but not defined. */
5334 if (names
!= NULL
&& e
->names
!= NULL
)
5336 for (i
= 0; names
[i
] != NULL
&& e
->names
[i
] != NULL
; i
++)
5338 if (names
[i
][0] != e
->names
[i
][0]
5339 || vals
[i
] != e
->vals
[i
]
5340 || strcmp (names
[i
], e
->names
[i
]) != 0)
5345 if ((names
== NULL
&& e
->names
== NULL
)
5349 && e
->names
[i
] == NULL
))
5351 /* We've seen this enum before. */
5352 return ieee_push_type (info
, e
->indx
, 0, TRUE
, FALSE
);
5357 /* We've already seen an enum of the same name, so we must make
5358 sure to output this one locally. */
5364 /* If this is a simple enumeration, in which the values start at 0
5365 and always increment by 1, we can use type E. Otherwise we must
5371 for (i
= 0; names
[i
] != NULL
; i
++)
5381 if (! ieee_define_named_type (info
, tag
, indx
, 0, TRUE
, localp
,
5382 (struct ieee_buflist
*) NULL
)
5383 || ! ieee_write_number (info
, simple
? 'E' : 'N'))
5387 /* FIXME: This is supposed to be the enumeration size, but we
5388 don't store that. */
5389 if (! ieee_write_number (info
, 4))
5394 for (i
= 0; names
[i
] != NULL
; i
++)
5396 if (! ieee_write_id (info
, names
[i
]))
5400 if (! ieee_write_number (info
, vals
[i
]))
5408 if (indx
== (unsigned int) -1)
5410 e
= (struct ieee_defined_enum
*) xmalloc (sizeof *e
);
5411 memset (e
, 0, sizeof *e
);
5412 e
->indx
= info
->type_stack
->type
.indx
;
5415 e
->next
= info
->enums
;
5427 /* Make a pointer type. */
5430 ieee_pointer_type (void *p
)
5432 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
5435 struct ieee_modified_type
*m
= NULL
;
5437 localp
= info
->type_stack
->type
.localp
;
5438 indx
= ieee_pop_type (info
);
5440 /* A pointer to a simple builtin type can be obtained by adding 32.
5441 FIXME: Will this be a short pointer, and will that matter? */
5443 return ieee_push_type (info
, indx
+ 32, 0, TRUE
, FALSE
);
5447 m
= ieee_get_modified_info (p
, indx
);
5451 /* FIXME: The size should depend upon the architecture. */
5453 return ieee_push_type (info
, m
->pointer
, 4, TRUE
, FALSE
);
5456 if (! ieee_define_type (info
, 4, TRUE
, localp
)
5457 || ! ieee_write_number (info
, 'P')
5458 || ! ieee_write_number (info
, indx
))
5462 m
->pointer
= info
->type_stack
->type
.indx
;
5467 /* Make a function type. This will be called for a method, but we
5468 don't want to actually add it to the type table in that case. We
5469 handle this by defining the type in a private buffer, and only
5470 adding that buffer to the typedef block if we are going to use it. */
5473 ieee_function_type (void *p
, int argcount
, bfd_boolean varargs
)
5475 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
5477 unsigned int *args
= NULL
;
5479 unsigned int retindx
;
5480 struct ieee_buflist fndef
;
5481 struct ieee_modified_type
*m
;
5487 args
= (unsigned int *) xmalloc (argcount
* sizeof *args
);
5488 for (i
= argcount
- 1; i
>= 0; i
--)
5490 if (info
->type_stack
->type
.localp
)
5492 args
[i
] = ieee_pop_type (info
);
5495 else if (argcount
< 0)
5498 if (info
->type_stack
->type
.localp
)
5500 retindx
= ieee_pop_type (info
);
5503 if (argcount
< 0 && ! localp
)
5505 m
= ieee_get_modified_info (p
, retindx
);
5509 if (m
->function
> 0)
5510 return ieee_push_type (info
, m
->function
, 0, TRUE
, FALSE
);
5513 /* An attribute of 0x41 means that the frame and push mask are
5515 if (! ieee_init_buffer (info
, &fndef
)
5516 || ! ieee_define_named_type (info
, (const char *) NULL
,
5517 (unsigned int) -1, 0, TRUE
, localp
,
5519 || ! ieee_write_number (info
, 'x')
5520 || ! ieee_write_number (info
, 0x41)
5521 || ! ieee_write_number (info
, 0)
5522 || ! ieee_write_number (info
, 0)
5523 || ! ieee_write_number (info
, retindx
)
5524 || ! ieee_write_number (info
, (bfd_vma
) argcount
+ (varargs
? 1 : 0)))
5528 for (i
= 0; i
< argcount
; i
++)
5529 if (! ieee_write_number (info
, args
[i
]))
5535 /* A varargs function is represented by writing out the last
5536 argument as type void *, although this makes little sense. */
5537 if (! ieee_write_number (info
, (bfd_vma
) builtin_void
+ 32))
5541 if (! ieee_write_number (info
, 0))
5544 /* We wrote the information into fndef, in case we don't need it.
5545 It will be appended to info->types by ieee_pop_type. */
5546 info
->type_stack
->type
.fndef
= fndef
;
5549 m
->function
= info
->type_stack
->type
.indx
;
5554 /* Make a reference type. */
5557 ieee_reference_type (void *p
)
5559 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
5561 /* IEEE appears to record a normal pointer type, and then use a
5562 pmisc record to indicate that it is really a reference. */
5564 if (! ieee_pointer_type (p
))
5566 info
->type_stack
->type
.referencep
= TRUE
;
5570 /* Make a range type. */
5573 ieee_range_type (void *p
, bfd_signed_vma low
, bfd_signed_vma high
)
5575 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
5577 bfd_boolean unsignedp
, localp
;
5579 size
= info
->type_stack
->type
.size
;
5580 unsignedp
= info
->type_stack
->type
.unsignedp
;
5581 localp
= info
->type_stack
->type
.localp
;
5582 ieee_pop_unused_type (info
);
5583 return (ieee_define_type (info
, size
, unsignedp
, localp
)
5584 && ieee_write_number (info
, 'R')
5585 && ieee_write_number (info
, (bfd_vma
) low
)
5586 && ieee_write_number (info
, (bfd_vma
) high
)
5587 && ieee_write_number (info
, unsignedp
? 0 : 1)
5588 && ieee_write_number (info
, size
));
5591 /* Make an array type. */
5594 ieee_array_type (void *p
, bfd_signed_vma low
, bfd_signed_vma high
,
5595 bfd_boolean stringp ATTRIBUTE_UNUSED
)
5597 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
5598 unsigned int eleindx
;
5601 struct ieee_modified_type
*m
= NULL
;
5602 struct ieee_modified_array_type
*a
;
5604 /* IEEE does not store the range, so we just ignore it. */
5605 ieee_pop_unused_type (info
);
5606 localp
= info
->type_stack
->type
.localp
;
5607 size
= info
->type_stack
->type
.size
;
5608 eleindx
= ieee_pop_type (info
);
5610 /* If we don't know the range, treat the size as exactly one
5613 size
*= (high
- low
) + 1;
5617 m
= ieee_get_modified_info (info
, eleindx
);
5621 for (a
= m
->arrays
; a
!= NULL
; a
= a
->next
)
5623 if (a
->low
== low
&& a
->high
== high
)
5624 return ieee_push_type (info
, a
->indx
, size
, FALSE
, FALSE
);
5628 if (! ieee_define_type (info
, size
, FALSE
, localp
)
5629 || ! ieee_write_number (info
, low
== 0 ? 'Z' : 'C')
5630 || ! ieee_write_number (info
, eleindx
))
5634 if (! ieee_write_number (info
, low
))
5638 if (! ieee_write_number (info
, high
+ 1))
5643 a
= (struct ieee_modified_array_type
*) xmalloc (sizeof *a
);
5644 memset (a
, 0, sizeof *a
);
5646 a
->indx
= info
->type_stack
->type
.indx
;
5650 a
->next
= m
->arrays
;
5657 /* Make a set type. */
5660 ieee_set_type (void *p
, bfd_boolean bitstringp ATTRIBUTE_UNUSED
)
5662 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
5664 unsigned int eleindx
;
5666 localp
= info
->type_stack
->type
.localp
;
5667 eleindx
= ieee_pop_type (info
);
5669 /* FIXME: We don't know the size, so we just use 4. */
5671 return (ieee_define_type (info
, 0, TRUE
, localp
)
5672 && ieee_write_number (info
, 's')
5673 && ieee_write_number (info
, 4)
5674 && ieee_write_number (info
, eleindx
));
5677 /* Make an offset type. */
5680 ieee_offset_type (void *p
)
5682 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
5683 unsigned int targetindx
, baseindx
;
5685 targetindx
= ieee_pop_type (info
);
5686 baseindx
= ieee_pop_type (info
);
5688 /* FIXME: The MRI C++ compiler does not appear to generate any
5689 useful type information about an offset type. It just records a
5690 pointer to member as an integer. The MRI/HP IEEE spec does
5691 describe a pmisc record which can be used for a pointer to
5692 member. Unfortunately, it does not describe the target type,
5693 which seems pretty important. I'm going to punt this for now. */
5695 return ieee_int_type (p
, 4, TRUE
);
5698 /* Make a method type. */
5701 ieee_method_type (void *p
, bfd_boolean domain
, int argcount
,
5702 bfd_boolean varargs
)
5704 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
5706 /* FIXME: The MRI/HP IEEE spec defines a pmisc record to use for a
5707 method, but the definition is incomplete. We just output an 'x'
5711 ieee_pop_unused_type (info
);
5713 return ieee_function_type (p
, argcount
, varargs
);
5716 /* Make a const qualified type. */
5719 ieee_const_type (void *p
)
5721 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
5723 bfd_boolean unsignedp
, localp
;
5725 struct ieee_modified_type
*m
= NULL
;
5727 size
= info
->type_stack
->type
.size
;
5728 unsignedp
= info
->type_stack
->type
.unsignedp
;
5729 localp
= info
->type_stack
->type
.localp
;
5730 indx
= ieee_pop_type (info
);
5734 m
= ieee_get_modified_info (info
, indx
);
5738 if (m
->const_qualified
> 0)
5739 return ieee_push_type (info
, m
->const_qualified
, size
, unsignedp
,
5743 if (! ieee_define_type (info
, size
, unsignedp
, localp
)
5744 || ! ieee_write_number (info
, 'n')
5745 || ! ieee_write_number (info
, 1)
5746 || ! ieee_write_number (info
, indx
))
5750 m
->const_qualified
= info
->type_stack
->type
.indx
;
5755 /* Make a volatile qualified type. */
5758 ieee_volatile_type (void *p
)
5760 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
5762 bfd_boolean unsignedp
, localp
;
5764 struct ieee_modified_type
*m
= NULL
;
5766 size
= info
->type_stack
->type
.size
;
5767 unsignedp
= info
->type_stack
->type
.unsignedp
;
5768 localp
= info
->type_stack
->type
.localp
;
5769 indx
= ieee_pop_type (info
);
5773 m
= ieee_get_modified_info (info
, indx
);
5777 if (m
->volatile_qualified
> 0)
5778 return ieee_push_type (info
, m
->volatile_qualified
, size
, unsignedp
,
5782 if (! ieee_define_type (info
, size
, unsignedp
, localp
)
5783 || ! ieee_write_number (info
, 'n')
5784 || ! ieee_write_number (info
, 2)
5785 || ! ieee_write_number (info
, indx
))
5789 m
->volatile_qualified
= info
->type_stack
->type
.indx
;
5794 /* Convert an enum debug_visibility into a CXXFLAGS value. */
5797 ieee_vis_to_flags (enum debug_visibility visibility
)
5803 case DEBUG_VISIBILITY_PUBLIC
:
5804 return CXXFLAGS_VISIBILITY_PUBLIC
;
5805 case DEBUG_VISIBILITY_PRIVATE
:
5806 return CXXFLAGS_VISIBILITY_PRIVATE
;
5807 case DEBUG_VISIBILITY_PROTECTED
:
5808 return CXXFLAGS_VISIBILITY_PROTECTED
;
5813 /* Start defining a struct type. We build it in the strdef field on
5814 the stack, to avoid confusing type definitions required by the
5815 fields with the struct type itself. */
5818 ieee_start_struct_type (void *p
, const char *tag
, unsigned int id
,
5819 bfd_boolean structp
, unsigned int size
)
5821 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
5822 bfd_boolean localp
, ignorep
;
5826 struct ieee_name_type_hash_entry
*h
;
5827 struct ieee_name_type
*nt
, *ntlook
;
5828 struct ieee_buflist strdef
;
5833 /* We need to create a tag for internal use even if we don't want
5834 one for external use. This will let us refer to an anonymous
5843 sprintf (ab
, "__anon%u", id
);
5848 /* If we already have references to the tag, we must use the
5849 existing type index. */
5850 h
= ieee_name_type_hash_lookup (&info
->tags
, look
, TRUE
, copy
);
5855 for (ntlook
= h
->types
; ntlook
!= NULL
; ntlook
= ntlook
->next
)
5857 if (ntlook
->id
== id
)
5859 else if (! ntlook
->type
.localp
)
5861 /* We are creating a duplicate definition of a globally
5862 defined tag. Force it to be local to avoid
5870 assert (localp
== nt
->type
.localp
);
5871 if (nt
->kind
== DEBUG_KIND_ILLEGAL
&& ! localp
)
5873 /* We've already seen a global definition of the type.
5874 Ignore this new definition. */
5880 nt
= (struct ieee_name_type
*) xmalloc (sizeof *nt
);
5881 memset (nt
, 0, sizeof *nt
);
5883 nt
->type
.name
= h
->root
.string
;
5884 nt
->next
= h
->types
;
5886 nt
->type
.indx
= info
->type_indx
;
5890 nt
->kind
= DEBUG_KIND_ILLEGAL
;
5892 if (! ieee_init_buffer (info
, &strdef
)
5893 || ! ieee_define_named_type (info
, tag
, nt
->type
.indx
, size
, TRUE
,
5895 || ! ieee_write_number (info
, structp
? 'S' : 'U')
5896 || ! ieee_write_number (info
, size
))
5903 /* We never want nt->type.name to be NULL. We want the rest of
5904 the type to be the object set up on the type stack; it will
5905 have a NULL name if tag is NULL. */
5906 hold
= nt
->type
.name
;
5907 nt
->type
= info
->type_stack
->type
;
5908 nt
->type
.name
= hold
;
5911 info
->type_stack
->type
.name
= tag
;
5912 info
->type_stack
->type
.strdef
= strdef
;
5913 info
->type_stack
->type
.ignorep
= ignorep
;
5918 /* Add a field to a struct. */
5921 ieee_struct_field (void *p
, const char *name
, bfd_vma bitpos
, bfd_vma bitsize
,
5922 enum debug_visibility visibility
)
5924 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
5926 bfd_boolean unsignedp
;
5927 bfd_boolean referencep
;
5932 assert (info
->type_stack
!= NULL
5933 && info
->type_stack
->next
!= NULL
5934 && ! ieee_buffer_emptyp (&info
->type_stack
->next
->type
.strdef
));
5936 /* If we are ignoring this struct definition, just pop and ignore
5938 if (info
->type_stack
->next
->type
.ignorep
)
5940 ieee_pop_unused_type (info
);
5944 size
= info
->type_stack
->type
.size
;
5945 unsignedp
= info
->type_stack
->type
.unsignedp
;
5946 referencep
= info
->type_stack
->type
.referencep
;
5947 localp
= info
->type_stack
->type
.localp
;
5948 indx
= ieee_pop_type (info
);
5951 info
->type_stack
->type
.localp
= TRUE
;
5953 if (info
->type_stack
->type
.classdef
!= NULL
)
5958 /* This is a class. We must add a description of this field to
5959 the class records we are building. */
5961 flags
= ieee_vis_to_flags (visibility
);
5962 nindx
= info
->type_stack
->type
.classdef
->indx
;
5963 if (! ieee_change_buffer (info
,
5964 &info
->type_stack
->type
.classdef
->pmiscbuf
)
5965 || ! ieee_write_asn (info
, nindx
, 'd')
5966 || ! ieee_write_asn (info
, nindx
, flags
)
5967 || ! ieee_write_atn65 (info
, nindx
, name
)
5968 || ! ieee_write_atn65 (info
, nindx
, name
))
5970 info
->type_stack
->type
.classdef
->pmisccount
+= 4;
5976 /* We need to output a record recording that this field is
5977 really of reference type. We put this on the refs field
5978 of classdef, so that it can be appended to the C++
5979 records after the class is defined. */
5981 nindx
= info
->name_indx
;
5984 if (! ieee_change_buffer (info
,
5985 &info
->type_stack
->type
.classdef
->refs
)
5986 || ! ieee_write_byte (info
, (int) ieee_nn_record
)
5987 || ! ieee_write_number (info
, nindx
)
5988 || ! ieee_write_id (info
, "")
5989 || ! ieee_write_2bytes (info
, (int) ieee_atn_record_enum
)
5990 || ! ieee_write_number (info
, nindx
)
5991 || ! ieee_write_number (info
, 0)
5992 || ! ieee_write_number (info
, 62)
5993 || ! ieee_write_number (info
, 80)
5994 || ! ieee_write_number (info
, 4)
5995 || ! ieee_write_asn (info
, nindx
, 'R')
5996 || ! ieee_write_asn (info
, nindx
, 3)
5997 || ! ieee_write_atn65 (info
, nindx
, info
->type_stack
->type
.name
)
5998 || ! ieee_write_atn65 (info
, nindx
, name
))
6003 /* If the bitsize doesn't match the expected size, we need to output
6005 if (size
== 0 || bitsize
== 0 || bitsize
== size
* 8)
6006 offset
= bitpos
/ 8;
6009 if (! ieee_define_type (info
, 0, unsignedp
,
6010 info
->type_stack
->type
.localp
)
6011 || ! ieee_write_number (info
, 'g')
6012 || ! ieee_write_number (info
, unsignedp
? 0 : 1)
6013 || ! ieee_write_number (info
, bitsize
)
6014 || ! ieee_write_number (info
, indx
))
6016 indx
= ieee_pop_type (info
);
6020 /* Switch to the struct we are building in order to output this
6021 field definition. */
6022 return (ieee_change_buffer (info
, &info
->type_stack
->type
.strdef
)
6023 && ieee_write_id (info
, name
)
6024 && ieee_write_number (info
, indx
)
6025 && ieee_write_number (info
, offset
));
6028 /* Finish up a struct type. */
6031 ieee_end_struct_type (void *p
)
6033 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
6034 struct ieee_buflist
*pb
;
6036 assert (info
->type_stack
!= NULL
6037 && ! ieee_buffer_emptyp (&info
->type_stack
->type
.strdef
));
6039 /* If we were ignoring this struct definition because it was a
6040 duplicate definition, just through away whatever bytes we have
6041 accumulated. Leave the type on the stack. */
6042 if (info
->type_stack
->type
.ignorep
)
6045 /* If this is not a duplicate definition of this tag, then localp
6046 will be FALSE, and we can put it in the global type block.
6047 FIXME: We should avoid outputting duplicate definitions which are
6049 if (! info
->type_stack
->type
.localp
)
6051 /* Make sure we have started the global type block. */
6052 if (ieee_buffer_emptyp (&info
->global_types
))
6054 if (! ieee_change_buffer (info
, &info
->global_types
)
6055 || ! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
6056 || ! ieee_write_byte (info
, 2)
6057 || ! ieee_write_number (info
, 0)
6058 || ! ieee_write_id (info
, ""))
6061 pb
= &info
->global_types
;
6065 /* Make sure we have started the types block. */
6066 if (ieee_buffer_emptyp (&info
->types
))
6068 if (! ieee_change_buffer (info
, &info
->types
)
6069 || ! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
6070 || ! ieee_write_byte (info
, 1)
6071 || ! ieee_write_number (info
, 0)
6072 || ! ieee_write_id (info
, info
->modname
))
6078 /* Append the struct definition to the types. */
6079 if (! ieee_append_buffer (info
, pb
, &info
->type_stack
->type
.strdef
)
6080 || ! ieee_init_buffer (info
, &info
->type_stack
->type
.strdef
))
6083 /* Leave the struct on the type stack. */
6088 /* Start a class type. */
6091 ieee_start_class_type (void *p
, const char *tag
, unsigned int id
,
6092 bfd_boolean structp
, unsigned int size
,
6093 bfd_boolean vptr
, bfd_boolean ownvptr
)
6095 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
6097 struct ieee_buflist pmiscbuf
;
6099 struct ieee_type_class
*classdef
;
6101 /* A C++ class is output as a C++ struct along with a set of pmisc
6102 records describing the class. */
6104 /* We need to have a name so that we can associate the struct and
6110 t
= (char *) xmalloc (20);
6111 sprintf (t
, "__anon%u", id
);
6115 /* We can't write out the virtual table information until we have
6116 finished the class, because we don't know the virtual table size.
6117 We get the size from the largest voffset we see. */
6119 if (vptr
&& ! ownvptr
)
6121 vclass
= info
->type_stack
->type
.name
;
6122 assert (vclass
!= NULL
);
6123 /* We don't call ieee_pop_unused_type, since the class should
6125 (void) ieee_pop_type (info
);
6128 if (! ieee_start_struct_type (p
, tag
, id
, structp
, size
))
6131 indx
= info
->name_indx
;
6134 /* We write out pmisc records into the classdef field. We will
6135 write out the pmisc start after we know the number of records we
6137 if (! ieee_init_buffer (info
, &pmiscbuf
)
6138 || ! ieee_change_buffer (info
, &pmiscbuf
)
6139 || ! ieee_write_asn (info
, indx
, 'T')
6140 || ! ieee_write_asn (info
, indx
, structp
? 'o' : 'u')
6141 || ! ieee_write_atn65 (info
, indx
, tag
))
6144 classdef
= (struct ieee_type_class
*) xmalloc (sizeof *classdef
);
6145 memset (classdef
, 0, sizeof *classdef
);
6147 classdef
->indx
= indx
;
6148 classdef
->pmiscbuf
= pmiscbuf
;
6149 classdef
->pmisccount
= 3;
6150 classdef
->vclass
= vclass
;
6151 classdef
->ownvptr
= ownvptr
;
6153 info
->type_stack
->type
.classdef
= classdef
;
6158 /* Add a static member to a class. */
6161 ieee_class_static_member (void *p
, const char *name
, const char *physname
,
6162 enum debug_visibility visibility
)
6164 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
6168 /* We don't care about the type. Hopefully there will be a call to
6169 ieee_variable declaring the physical name and the type, since
6170 that is where an IEEE consumer must get the type. */
6171 ieee_pop_unused_type (info
);
6173 assert (info
->type_stack
!= NULL
6174 && info
->type_stack
->type
.classdef
!= NULL
);
6176 flags
= ieee_vis_to_flags (visibility
);
6177 flags
|= CXXFLAGS_STATIC
;
6179 nindx
= info
->type_stack
->type
.classdef
->indx
;
6181 if (! ieee_change_buffer (info
, &info
->type_stack
->type
.classdef
->pmiscbuf
)
6182 || ! ieee_write_asn (info
, nindx
, 'd')
6183 || ! ieee_write_asn (info
, nindx
, flags
)
6184 || ! ieee_write_atn65 (info
, nindx
, name
)
6185 || ! ieee_write_atn65 (info
, nindx
, physname
))
6187 info
->type_stack
->type
.classdef
->pmisccount
+= 4;
6192 /* Add a base class to a class. */
6195 ieee_class_baseclass (void *p
, bfd_vma bitpos
, bfd_boolean
virtual,
6196 enum debug_visibility visibility
)
6198 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
6206 assert (info
->type_stack
!= NULL
6207 && info
->type_stack
->type
.name
!= NULL
6208 && info
->type_stack
->next
!= NULL
6209 && info
->type_stack
->next
->type
.classdef
!= NULL
6210 && ! ieee_buffer_emptyp (&info
->type_stack
->next
->type
.strdef
));
6212 bname
= info
->type_stack
->type
.name
;
6213 localp
= info
->type_stack
->type
.localp
;
6214 bindx
= ieee_pop_type (info
);
6216 /* We are currently defining both a struct and a class. We must
6217 write out a field definition in the struct which holds the base
6218 class. The stabs debugging reader will create a field named
6219 _vb$CLASS for a virtual base class, so we just use that. FIXME:
6220 we should not depend upon a detail of stabs debugging. */
6223 fname
= (char *) xmalloc (strlen (bname
) + sizeof "_vb$");
6224 sprintf (fname
, "_vb$%s", bname
);
6225 flags
= BASEFLAGS_VIRTUAL
;
6230 info
->type_stack
->type
.localp
= TRUE
;
6232 fname
= (char *) xmalloc (strlen (bname
) + sizeof "_b$");
6233 sprintf (fname
, "_b$%s", bname
);
6235 if (! ieee_change_buffer (info
, &info
->type_stack
->type
.strdef
)
6236 || ! ieee_write_id (info
, fname
)
6237 || ! ieee_write_number (info
, bindx
)
6238 || ! ieee_write_number (info
, bitpos
/ 8))
6243 if (visibility
== DEBUG_VISIBILITY_PRIVATE
)
6244 flags
|= BASEFLAGS_PRIVATE
;
6246 nindx
= info
->type_stack
->type
.classdef
->indx
;
6248 if (! ieee_change_buffer (info
, &info
->type_stack
->type
.classdef
->pmiscbuf
)
6249 || ! ieee_write_asn (info
, nindx
, 'b')
6250 || ! ieee_write_asn (info
, nindx
, flags
)
6251 || ! ieee_write_atn65 (info
, nindx
, bname
)
6252 || ! ieee_write_asn (info
, nindx
, 0)
6253 || ! ieee_write_atn65 (info
, nindx
, fname
))
6255 info
->type_stack
->type
.classdef
->pmisccount
+= 5;
6262 /* Start building a method for a class. */
6265 ieee_class_start_method (void *p
, const char *name
)
6267 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
6269 assert (info
->type_stack
!= NULL
6270 && info
->type_stack
->type
.classdef
!= NULL
6271 && info
->type_stack
->type
.classdef
->method
== NULL
);
6273 info
->type_stack
->type
.classdef
->method
= name
;
6278 /* Define a new method variant, either static or not. */
6281 ieee_class_method_var (struct ieee_handle
*info
, const char *physname
,
6282 enum debug_visibility visibility
,
6283 bfd_boolean staticp
, bfd_boolean constp
,
6284 bfd_boolean volatilep
, bfd_vma voffset
,
6285 bfd_boolean context
)
6289 bfd_boolean
virtual;
6291 /* We don't need the type of the method. An IEEE consumer which
6292 wants the type must track down the function by the physical name
6293 and get the type from that. */
6294 ieee_pop_unused_type (info
);
6296 /* We don't use the context. FIXME: We probably ought to use it to
6297 adjust the voffset somehow, but I don't really know how. */
6299 ieee_pop_unused_type (info
);
6301 assert (info
->type_stack
!= NULL
6302 && info
->type_stack
->type
.classdef
!= NULL
6303 && info
->type_stack
->type
.classdef
->method
!= NULL
);
6305 flags
= ieee_vis_to_flags (visibility
);
6307 /* FIXME: We never set CXXFLAGS_OVERRIDE, CXXFLAGS_OPERATOR,
6308 CXXFLAGS_CTORDTOR, CXXFLAGS_CTOR, or CXXFLAGS_INLINE. */
6311 flags
|= CXXFLAGS_STATIC
;
6313 flags
|= CXXFLAGS_CONST
;
6315 flags
|= CXXFLAGS_VOLATILE
;
6317 nindx
= info
->type_stack
->type
.classdef
->indx
;
6319 virtual = context
|| voffset
> 0;
6321 if (! ieee_change_buffer (info
,
6322 &info
->type_stack
->type
.classdef
->pmiscbuf
)
6323 || ! ieee_write_asn (info
, nindx
, virtual ? 'v' : 'm')
6324 || ! ieee_write_asn (info
, nindx
, flags
)
6325 || ! ieee_write_atn65 (info
, nindx
,
6326 info
->type_stack
->type
.classdef
->method
)
6327 || ! ieee_write_atn65 (info
, nindx
, physname
))
6332 if (voffset
> info
->type_stack
->type
.classdef
->voffset
)
6333 info
->type_stack
->type
.classdef
->voffset
= voffset
;
6334 if (! ieee_write_asn (info
, nindx
, voffset
))
6336 ++info
->type_stack
->type
.classdef
->pmisccount
;
6339 if (! ieee_write_asn (info
, nindx
, 0))
6342 info
->type_stack
->type
.classdef
->pmisccount
+= 5;
6347 /* Define a new method variant. */
6350 ieee_class_method_variant (void *p
, const char *physname
,
6351 enum debug_visibility visibility
,
6352 bfd_boolean constp
, bfd_boolean volatilep
,
6353 bfd_vma voffset
, bfd_boolean context
)
6355 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
6357 return ieee_class_method_var (info
, physname
, visibility
, FALSE
, constp
,
6358 volatilep
, voffset
, context
);
6361 /* Define a new static method variant. */
6364 ieee_class_static_method_variant (void *p
, const char *physname
,
6365 enum debug_visibility visibility
,
6366 bfd_boolean constp
, bfd_boolean volatilep
)
6368 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
6370 return ieee_class_method_var (info
, physname
, visibility
, TRUE
, constp
,
6371 volatilep
, 0, FALSE
);
6374 /* Finish up a method. */
6377 ieee_class_end_method (void *p
)
6379 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
6381 assert (info
->type_stack
!= NULL
6382 && info
->type_stack
->type
.classdef
!= NULL
6383 && info
->type_stack
->type
.classdef
->method
!= NULL
);
6385 info
->type_stack
->type
.classdef
->method
= NULL
;
6390 /* Finish up a class. */
6393 ieee_end_class_type (void *p
)
6395 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
6398 assert (info
->type_stack
!= NULL
6399 && info
->type_stack
->type
.classdef
!= NULL
);
6401 /* If we were ignoring this class definition because it was a
6402 duplicate definition, just through away whatever bytes we have
6403 accumulated. Leave the type on the stack. */
6404 if (info
->type_stack
->type
.ignorep
)
6407 nindx
= info
->type_stack
->type
.classdef
->indx
;
6409 /* If we have a virtual table, we can write out the information now. */
6410 if (info
->type_stack
->type
.classdef
->vclass
!= NULL
6411 || info
->type_stack
->type
.classdef
->ownvptr
)
6413 if (! ieee_change_buffer (info
,
6414 &info
->type_stack
->type
.classdef
->pmiscbuf
)
6415 || ! ieee_write_asn (info
, nindx
, 'z')
6416 || ! ieee_write_atn65 (info
, nindx
, "")
6417 || ! ieee_write_asn (info
, nindx
,
6418 info
->type_stack
->type
.classdef
->voffset
))
6420 if (info
->type_stack
->type
.classdef
->ownvptr
)
6422 if (! ieee_write_atn65 (info
, nindx
, ""))
6427 if (! ieee_write_atn65 (info
, nindx
,
6428 info
->type_stack
->type
.classdef
->vclass
))
6431 if (! ieee_write_asn (info
, nindx
, 0))
6433 info
->type_stack
->type
.classdef
->pmisccount
+= 5;
6436 /* Now that we know the number of pmisc records, we can write out
6437 the atn62 which starts the pmisc records, and append them to the
6440 if (! ieee_change_buffer (info
, &info
->cxx
)
6441 || ! ieee_write_byte (info
, (int) ieee_nn_record
)
6442 || ! ieee_write_number (info
, nindx
)
6443 || ! ieee_write_id (info
, "")
6444 || ! ieee_write_2bytes (info
, (int) ieee_atn_record_enum
)
6445 || ! ieee_write_number (info
, nindx
)
6446 || ! ieee_write_number (info
, 0)
6447 || ! ieee_write_number (info
, 62)
6448 || ! ieee_write_number (info
, 80)
6449 || ! ieee_write_number (info
,
6450 info
->type_stack
->type
.classdef
->pmisccount
))
6453 if (! ieee_append_buffer (info
, &info
->cxx
,
6454 &info
->type_stack
->type
.classdef
->pmiscbuf
))
6456 if (! ieee_buffer_emptyp (&info
->type_stack
->type
.classdef
->refs
))
6458 if (! ieee_append_buffer (info
, &info
->cxx
,
6459 &info
->type_stack
->type
.classdef
->refs
))
6463 return ieee_end_struct_type (p
);
6466 /* Push a previously seen typedef onto the type stack. */
6469 ieee_typedef_type (void *p
, const char *name
)
6471 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
6472 struct ieee_name_type_hash_entry
*h
;
6473 struct ieee_name_type
*nt
;
6475 h
= ieee_name_type_hash_lookup (&info
->typedefs
, name
, FALSE
, FALSE
);
6477 /* h should never be NULL, since that would imply that the generic
6478 debugging code has asked for a typedef which it has not yet
6482 /* We always use the most recently defined type for this name, which
6483 will be the first one on the list. */
6486 if (! ieee_push_type (info
, nt
->type
.indx
, nt
->type
.size
,
6487 nt
->type
.unsignedp
, nt
->type
.localp
))
6490 /* Copy over any other type information we may have. */
6491 info
->type_stack
->type
= nt
->type
;
6496 /* Push a tagged type onto the type stack. */
6499 ieee_tag_type (void *p
, const char *name
, unsigned int id
,
6500 enum debug_type_kind kind
)
6502 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
6506 struct ieee_name_type_hash_entry
*h
;
6507 struct ieee_name_type
*nt
;
6509 if (kind
== DEBUG_KIND_ENUM
)
6511 struct ieee_defined_enum
*e
;
6515 for (e
= info
->enums
; e
!= NULL
; e
= e
->next
)
6516 if (e
->tag
!= NULL
&& strcmp (e
->tag
, name
) == 0)
6517 return ieee_push_type (info
, e
->indx
, 0, TRUE
, FALSE
);
6519 e
= (struct ieee_defined_enum
*) xmalloc (sizeof *e
);
6520 memset (e
, 0, sizeof *e
);
6522 e
->indx
= info
->type_indx
;
6527 e
->next
= info
->enums
;
6530 return ieee_push_type (info
, e
->indx
, 0, TRUE
, FALSE
);
6538 sprintf (ab
, "__anon%u", id
);
6543 h
= ieee_name_type_hash_lookup (&info
->tags
, name
, TRUE
, copy
);
6547 for (nt
= h
->types
; nt
!= NULL
; nt
= nt
->next
)
6551 if (! ieee_push_type (info
, nt
->type
.indx
, nt
->type
.size
,
6552 nt
->type
.unsignedp
, nt
->type
.localp
))
6554 /* Copy over any other type information we may have. */
6555 info
->type_stack
->type
= nt
->type
;
6559 if (! nt
->type
.localp
)
6561 /* This is a duplicate of a global type, so it must be
6567 nt
= (struct ieee_name_type
*) xmalloc (sizeof *nt
);
6568 memset (nt
, 0, sizeof *nt
);
6571 nt
->type
.name
= h
->root
.string
;
6572 nt
->type
.indx
= info
->type_indx
;
6573 nt
->type
.localp
= localp
;
6577 nt
->next
= h
->types
;
6580 if (! ieee_push_type (info
, nt
->type
.indx
, 0, FALSE
, localp
))
6583 info
->type_stack
->type
.name
= h
->root
.string
;
6588 /* Output a typedef. */
6591 ieee_typdef (void *p
, const char *name
)
6593 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
6594 struct ieee_write_type type
;
6598 struct ieee_name_type_hash_entry
*h
;
6599 struct ieee_name_type
*nt
;
6601 type
= info
->type_stack
->type
;
6604 /* If this is a simple builtin type using a builtin name, we don't
6605 want to output the typedef itself. We also want to change the
6606 type index to correspond to the name being used. We recognize
6607 names used in stabs debugging output even if they don't exactly
6608 correspond to the names used for the IEEE builtin types. */
6610 if (indx
<= (unsigned int) builtin_bcd_float
)
6612 switch ((enum builtin_types
) indx
)
6618 if (strcmp (name
, "void") == 0)
6622 case builtin_signed_char
:
6624 if (strcmp (name
, "signed char") == 0)
6626 indx
= (unsigned int) builtin_signed_char
;
6629 else if (strcmp (name
, "char") == 0)
6631 indx
= (unsigned int) builtin_char
;
6636 case builtin_unsigned_char
:
6637 if (strcmp (name
, "unsigned char") == 0)
6641 case builtin_signed_short_int
:
6643 case builtin_short_int
:
6644 case builtin_signed_short
:
6645 if (strcmp (name
, "signed short int") == 0)
6647 indx
= (unsigned int) builtin_signed_short_int
;
6650 else if (strcmp (name
, "short") == 0)
6652 indx
= (unsigned int) builtin_short
;
6655 else if (strcmp (name
, "short int") == 0)
6657 indx
= (unsigned int) builtin_short_int
;
6660 else if (strcmp (name
, "signed short") == 0)
6662 indx
= (unsigned int) builtin_signed_short
;
6667 case builtin_unsigned_short_int
:
6668 case builtin_unsigned_short
:
6669 if (strcmp (name
, "unsigned short int") == 0
6670 || strcmp (name
, "short unsigned int") == 0)
6672 indx
= builtin_unsigned_short_int
;
6675 else if (strcmp (name
, "unsigned short") == 0)
6677 indx
= builtin_unsigned_short
;
6682 case builtin_signed_long
:
6683 case builtin_int
: /* FIXME: Size depends upon architecture. */
6685 if (strcmp (name
, "signed long") == 0)
6687 indx
= builtin_signed_long
;
6690 else if (strcmp (name
, "int") == 0)
6695 else if (strcmp (name
, "long") == 0
6696 || strcmp (name
, "long int") == 0)
6698 indx
= builtin_long
;
6703 case builtin_unsigned_long
:
6704 case builtin_unsigned
: /* FIXME: Size depends upon architecture. */
6705 case builtin_unsigned_int
: /* FIXME: Like builtin_unsigned. */
6706 if (strcmp (name
, "unsigned long") == 0
6707 || strcmp (name
, "long unsigned int") == 0)
6709 indx
= builtin_unsigned_long
;
6712 else if (strcmp (name
, "unsigned") == 0)
6714 indx
= builtin_unsigned
;
6717 else if (strcmp (name
, "unsigned int") == 0)
6719 indx
= builtin_unsigned_int
;
6724 case builtin_signed_long_long
:
6725 if (strcmp (name
, "signed long long") == 0
6726 || strcmp (name
, "long long int") == 0)
6730 case builtin_unsigned_long_long
:
6731 if (strcmp (name
, "unsigned long long") == 0
6732 || strcmp (name
, "long long unsigned int") == 0)
6737 if (strcmp (name
, "float") == 0)
6741 case builtin_double
:
6742 if (strcmp (name
, "double") == 0)
6746 case builtin_long_double
:
6747 if (strcmp (name
, "long double") == 0)
6751 case builtin_long_long_double
:
6752 if (strcmp (name
, "long long double") == 0)
6761 h
= ieee_name_type_hash_lookup (&info
->typedefs
, name
, TRUE
, FALSE
);
6765 /* See if we have already defined this type with this name. */
6766 localp
= type
.localp
;
6767 for (nt
= h
->types
; nt
!= NULL
; nt
= nt
->next
)
6771 /* If this is a global definition, then we don't need to
6772 do anything here. */
6773 if (! nt
->type
.localp
)
6775 ieee_pop_unused_type (info
);
6781 /* This is a duplicate definition, so make this one local. */
6786 /* We need to add a new typedef for this type. */
6788 nt
= (struct ieee_name_type
*) xmalloc (sizeof *nt
);
6789 memset (nt
, 0, sizeof *nt
);
6792 nt
->type
.name
= name
;
6793 nt
->type
.localp
= localp
;
6794 nt
->kind
= DEBUG_KIND_ILLEGAL
;
6796 nt
->next
= h
->types
;
6801 /* This is one of the builtin typedefs, so we don't need to
6802 actually define it. */
6803 ieee_pop_unused_type (info
);
6807 indx
= ieee_pop_type (info
);
6809 if (! ieee_define_named_type (info
, name
, (unsigned int) -1, type
.size
,
6810 type
.unsignedp
, localp
,
6811 (struct ieee_buflist
*) NULL
)
6812 || ! ieee_write_number (info
, 'T')
6813 || ! ieee_write_number (info
, indx
))
6816 /* Remove the type we just added to the type stack. This should not
6817 be ieee_pop_unused_type, since the type is used, we just don't
6819 (void) ieee_pop_type (info
);
6824 /* Output a tag for a type. We don't have to do anything here. */
6827 ieee_tag (void *p
, const char *name ATTRIBUTE_UNUSED
)
6829 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
6831 /* This should not be ieee_pop_unused_type, since we want the type
6833 (void) ieee_pop_type (info
);
6837 /* Output an integer constant. */
6840 ieee_int_constant (void *p ATTRIBUTE_UNUSED
, const char *name ATTRIBUTE_UNUSED
,
6841 bfd_vma val ATTRIBUTE_UNUSED
)
6847 /* Output a floating point constant. */
6850 ieee_float_constant (void *p ATTRIBUTE_UNUSED
,
6851 const char *name ATTRIBUTE_UNUSED
,
6852 double val ATTRIBUTE_UNUSED
)
6858 /* Output a typed constant. */
6861 ieee_typed_constant (void *p
, const char *name ATTRIBUTE_UNUSED
,
6862 bfd_vma val ATTRIBUTE_UNUSED
)
6864 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
6867 ieee_pop_unused_type (info
);
6871 /* Output a variable. */
6874 ieee_variable (void *p
, const char *name
, enum debug_var_kind kind
,
6877 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
6878 unsigned int name_indx
;
6880 bfd_boolean referencep
;
6881 unsigned int type_indx
;
6885 size
= info
->type_stack
->type
.size
;
6886 referencep
= info
->type_stack
->type
.referencep
;
6887 type_indx
= ieee_pop_type (info
);
6889 assert (! ieee_buffer_emptyp (&info
->vars
));
6890 if (! ieee_change_buffer (info
, &info
->vars
))
6893 name_indx
= info
->name_indx
;
6896 /* Write out an NN and an ATN record for this variable. */
6897 if (! ieee_write_byte (info
, (int) ieee_nn_record
)
6898 || ! ieee_write_number (info
, name_indx
)
6899 || ! ieee_write_id (info
, name
)
6900 || ! ieee_write_2bytes (info
, (int) ieee_atn_record_enum
)
6901 || ! ieee_write_number (info
, name_indx
)
6902 || ! ieee_write_number (info
, type_indx
))
6910 if (! ieee_write_number (info
, 8)
6911 || ! ieee_add_range (info
, FALSE
, val
, val
+ size
))
6917 if (! ieee_write_number (info
, 3)
6918 || ! ieee_add_range (info
, FALSE
, val
, val
+ size
))
6923 case DEBUG_LOCAL_STATIC
:
6924 if (! ieee_write_number (info
, 3)
6925 || ! ieee_add_range (info
, FALSE
, val
, val
+ size
))
6931 if (! ieee_write_number (info
, 1)
6932 || ! ieee_write_number (info
, val
))
6937 case DEBUG_REGISTER
:
6938 if (! ieee_write_number (info
, 2)
6939 || ! ieee_write_number (info
,
6940 ieee_genreg_to_regno (info
->abfd
, val
)))
6949 if (! ieee_write_asn (info
, name_indx
, val
))
6953 /* If this is really a reference type, then we just output it with
6954 pointer type, and must now output a C++ record indicating that it
6955 is really reference type. */
6960 nindx
= info
->name_indx
;
6963 /* If this is a global variable, we want to output the misc
6964 record in the C++ misc record block. Otherwise, we want to
6965 output it just after the variable definition, which is where
6966 the current buffer is. */
6969 if (! ieee_change_buffer (info
, &info
->cxx
))
6973 if (! ieee_write_byte (info
, (int) ieee_nn_record
)
6974 || ! ieee_write_number (info
, nindx
)
6975 || ! ieee_write_id (info
, "")
6976 || ! ieee_write_2bytes (info
, (int) ieee_atn_record_enum
)
6977 || ! ieee_write_number (info
, nindx
)
6978 || ! ieee_write_number (info
, 0)
6979 || ! ieee_write_number (info
, 62)
6980 || ! ieee_write_number (info
, 80)
6981 || ! ieee_write_number (info
, 3)
6982 || ! ieee_write_asn (info
, nindx
, 'R')
6983 || ! ieee_write_asn (info
, nindx
, refflag
)
6984 || ! ieee_write_atn65 (info
, nindx
, name
))
6991 /* Start outputting information for a function. */
6994 ieee_start_function (void *p
, const char *name
, bfd_boolean global
)
6996 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
6997 bfd_boolean referencep
;
6998 unsigned int retindx
, typeindx
;
7000 referencep
= info
->type_stack
->type
.referencep
;
7001 retindx
= ieee_pop_type (info
);
7003 /* Besides recording a BB4 or BB6 block, we record the type of the
7004 function in the BB1 typedef block. We can't write out the full
7005 type until we have seen all the parameters, so we accumulate it
7006 in info->fntype and info->fnargs. */
7007 if (! ieee_buffer_emptyp (&info
->fntype
))
7009 /* FIXME: This might happen someday if we support nested
7014 info
->fnname
= name
;
7016 /* An attribute of 0x40 means that the push mask is unknown. */
7017 if (! ieee_define_named_type (info
, name
, (unsigned int) -1, 0, FALSE
, TRUE
,
7019 || ! ieee_write_number (info
, 'x')
7020 || ! ieee_write_number (info
, 0x40)
7021 || ! ieee_write_number (info
, 0)
7022 || ! ieee_write_number (info
, 0)
7023 || ! ieee_write_number (info
, retindx
))
7026 typeindx
= ieee_pop_type (info
);
7028 if (! ieee_init_buffer (info
, &info
->fnargs
))
7030 info
->fnargcount
= 0;
7032 /* If the function return value is actually a reference type, we
7033 must add a record indicating that. */
7038 nindx
= info
->name_indx
;
7040 if (! ieee_change_buffer (info
, &info
->cxx
)
7041 || ! ieee_write_byte (info
, (int) ieee_nn_record
)
7042 || ! ieee_write_number (info
, nindx
)
7043 || ! ieee_write_id (info
, "")
7044 || ! ieee_write_2bytes (info
, (int) ieee_atn_record_enum
)
7045 || ! ieee_write_number (info
, nindx
)
7046 || ! ieee_write_number (info
, 0)
7047 || ! ieee_write_number (info
, 62)
7048 || ! ieee_write_number (info
, 80)
7049 || ! ieee_write_number (info
, 3)
7050 || ! ieee_write_asn (info
, nindx
, 'R')
7051 || ! ieee_write_asn (info
, nindx
, global
? 0 : 1)
7052 || ! ieee_write_atn65 (info
, nindx
, name
))
7056 assert (! ieee_buffer_emptyp (&info
->vars
));
7057 if (! ieee_change_buffer (info
, &info
->vars
))
7060 /* The address is written out as the first block. */
7062 ++info
->block_depth
;
7064 return (ieee_write_byte (info
, (int) ieee_bb_record_enum
)
7065 && ieee_write_byte (info
, global
? 4 : 6)
7066 && ieee_write_number (info
, 0)
7067 && ieee_write_id (info
, name
)
7068 && ieee_write_number (info
, 0)
7069 && ieee_write_number (info
, typeindx
));
7072 /* Add a function parameter. This will normally be called before the
7073 first block, so we postpone them until we see the block. */
7076 ieee_function_parameter (void *p
, const char *name
, enum debug_parm_kind kind
,
7079 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
7080 struct ieee_pending_parm
*m
, **pm
;
7082 assert (info
->block_depth
== 1);
7084 m
= (struct ieee_pending_parm
*) xmalloc (sizeof *m
);
7085 memset (m
, 0, sizeof *m
);
7089 m
->referencep
= info
->type_stack
->type
.referencep
;
7090 m
->type
= ieee_pop_type (info
);
7094 for (pm
= &info
->pending_parms
; *pm
!= NULL
; pm
= &(*pm
)->next
)
7098 /* Add the type to the fnargs list. */
7099 if (! ieee_change_buffer (info
, &info
->fnargs
)
7100 || ! ieee_write_number (info
, m
->type
))
7107 /* Output pending function parameters. */
7110 ieee_output_pending_parms (struct ieee_handle
*info
)
7112 struct ieee_pending_parm
*m
;
7113 unsigned int refcount
;
7116 for (m
= info
->pending_parms
; m
!= NULL
; m
= m
->next
)
7118 enum debug_var_kind vkind
;
7125 case DEBUG_PARM_STACK
:
7126 case DEBUG_PARM_REFERENCE
:
7127 vkind
= DEBUG_LOCAL
;
7129 case DEBUG_PARM_REG
:
7130 case DEBUG_PARM_REF_REG
:
7131 vkind
= DEBUG_REGISTER
;
7135 if (! ieee_push_type (info
, m
->type
, 0, FALSE
, FALSE
))
7137 info
->type_stack
->type
.referencep
= m
->referencep
;
7140 if (! ieee_variable ((void *) info
, m
->name
, vkind
, m
->val
))
7144 /* If there are any reference parameters, we need to output a
7145 miscellaneous record indicating them. */
7148 unsigned int nindx
, varindx
;
7150 /* FIXME: The MRI compiler outputs the demangled function name
7151 here, but we are outputting the mangled name. */
7152 nindx
= info
->name_indx
;
7154 if (! ieee_change_buffer (info
, &info
->vars
)
7155 || ! ieee_write_byte (info
, (int) ieee_nn_record
)
7156 || ! ieee_write_number (info
, nindx
)
7157 || ! ieee_write_id (info
, "")
7158 || ! ieee_write_2bytes (info
, (int) ieee_atn_record_enum
)
7159 || ! ieee_write_number (info
, nindx
)
7160 || ! ieee_write_number (info
, 0)
7161 || ! ieee_write_number (info
, 62)
7162 || ! ieee_write_number (info
, 80)
7163 || ! ieee_write_number (info
, refcount
+ 3)
7164 || ! ieee_write_asn (info
, nindx
, 'B')
7165 || ! ieee_write_atn65 (info
, nindx
, info
->fnname
)
7166 || ! ieee_write_asn (info
, nindx
, 0))
7168 for (m
= info
->pending_parms
, varindx
= 1;
7170 m
= m
->next
, varindx
++)
7174 if (! ieee_write_asn (info
, nindx
, varindx
))
7180 m
= info
->pending_parms
;
7183 struct ieee_pending_parm
*next
;
7190 info
->pending_parms
= NULL
;
7195 /* Start a block. If this is the first block, we output the address
7196 to finish the BB4 or BB6, and then output the function parameters. */
7199 ieee_start_block (void *p
, bfd_vma addr
)
7201 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
7203 if (! ieee_change_buffer (info
, &info
->vars
))
7206 if (info
->block_depth
== 1)
7208 if (! ieee_write_number (info
, addr
)
7209 || ! ieee_output_pending_parms (info
))
7214 if (! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
7215 || ! ieee_write_byte (info
, 6)
7216 || ! ieee_write_number (info
, 0)
7217 || ! ieee_write_id (info
, "")
7218 || ! ieee_write_number (info
, 0)
7219 || ! ieee_write_number (info
, 0)
7220 || ! ieee_write_number (info
, addr
))
7224 if (! ieee_start_range (info
, addr
))
7227 ++info
->block_depth
;
7235 ieee_end_block (void *p
, bfd_vma addr
)
7237 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
7239 /* The address we are given is the end of the block, but IEEE seems
7240 to want to the address of the last byte in the block, so we
7242 if (! ieee_change_buffer (info
, &info
->vars
)
7243 || ! ieee_write_byte (info
, (int) ieee_be_record_enum
)
7244 || ! ieee_write_number (info
, addr
- 1))
7247 if (! ieee_end_range (info
, addr
))
7250 --info
->block_depth
;
7252 if (addr
> info
->highaddr
)
7253 info
->highaddr
= addr
;
7258 /* End a function. */
7261 ieee_end_function (void *p
)
7263 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
7265 assert (info
->block_depth
== 1);
7267 --info
->block_depth
;
7269 /* Now we can finish up fntype, and add it to the typdef section.
7270 At this point, fntype is the 'x' type up to the argument count,
7271 and fnargs is the argument types. We must add the argument
7272 count, and we must add the level. FIXME: We don't record varargs
7273 functions correctly. In fact, stabs debugging does not give us
7274 enough information to do so. */
7275 if (! ieee_change_buffer (info
, &info
->fntype
)
7276 || ! ieee_write_number (info
, info
->fnargcount
)
7277 || ! ieee_change_buffer (info
, &info
->fnargs
)
7278 || ! ieee_write_number (info
, 0))
7281 /* Make sure the typdef block has been started. */
7282 if (ieee_buffer_emptyp (&info
->types
))
7284 if (! ieee_change_buffer (info
, &info
->types
)
7285 || ! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
7286 || ! ieee_write_byte (info
, 1)
7287 || ! ieee_write_number (info
, 0)
7288 || ! ieee_write_id (info
, info
->modname
))
7292 if (! ieee_append_buffer (info
, &info
->types
, &info
->fntype
)
7293 || ! ieee_append_buffer (info
, &info
->types
, &info
->fnargs
))
7296 info
->fnname
= NULL
;
7297 if (! ieee_init_buffer (info
, &info
->fntype
)
7298 || ! ieee_init_buffer (info
, &info
->fnargs
))
7300 info
->fnargcount
= 0;
7305 /* Record line number information. */
7308 ieee_lineno (void *p
, const char *filename
, unsigned long lineno
, bfd_vma addr
)
7310 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
7312 assert (info
->filename
!= NULL
);
7314 /* The HP simulator seems to get confused when more than one line is
7315 listed for the same address, at least if they are in different
7316 files. We handle this by always listing the last line for a
7317 given address, since that seems to be the one that gdb uses. */
7318 if (info
->pending_lineno_filename
!= NULL
7319 && addr
!= info
->pending_lineno_addr
)
7321 /* Make sure we have a line number block. */
7322 if (! ieee_buffer_emptyp (&info
->linenos
))
7324 if (! ieee_change_buffer (info
, &info
->linenos
))
7329 info
->lineno_name_indx
= info
->name_indx
;
7331 if (! ieee_change_buffer (info
, &info
->linenos
)
7332 || ! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
7333 || ! ieee_write_byte (info
, 5)
7334 || ! ieee_write_number (info
, 0)
7335 || ! ieee_write_id (info
, info
->filename
)
7336 || ! ieee_write_byte (info
, (int) ieee_nn_record
)
7337 || ! ieee_write_number (info
, info
->lineno_name_indx
)
7338 || ! ieee_write_id (info
, ""))
7340 info
->lineno_filename
= info
->filename
;
7343 if (strcmp (info
->pending_lineno_filename
, info
->lineno_filename
) != 0)
7345 if (strcmp (info
->filename
, info
->lineno_filename
) != 0)
7347 /* We were not in the main file. Close the block for the
7349 if (! ieee_write_byte (info
, (int) ieee_be_record_enum
))
7351 if (strcmp (info
->filename
, info
->pending_lineno_filename
) == 0)
7353 /* We need a new NN record, and we aren't about to
7355 info
->lineno_name_indx
= info
->name_indx
;
7357 if (! ieee_write_byte (info
, (int) ieee_nn_record
)
7358 || ! ieee_write_number (info
, info
->lineno_name_indx
)
7359 || ! ieee_write_id (info
, ""))
7363 if (strcmp (info
->filename
, info
->pending_lineno_filename
) != 0)
7365 /* We are not changing to the main file. Open a block for
7366 the new included file. */
7367 info
->lineno_name_indx
= info
->name_indx
;
7369 if (! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
7370 || ! ieee_write_byte (info
, 5)
7371 || ! ieee_write_number (info
, 0)
7372 || ! ieee_write_id (info
, info
->pending_lineno_filename
)
7373 || ! ieee_write_byte (info
, (int) ieee_nn_record
)
7374 || ! ieee_write_number (info
, info
->lineno_name_indx
)
7375 || ! ieee_write_id (info
, ""))
7378 info
->lineno_filename
= info
->pending_lineno_filename
;
7381 if (! ieee_write_2bytes (info
, (int) ieee_atn_record_enum
)
7382 || ! ieee_write_number (info
, info
->lineno_name_indx
)
7383 || ! ieee_write_number (info
, 0)
7384 || ! ieee_write_number (info
, 7)
7385 || ! ieee_write_number (info
, info
->pending_lineno
)
7386 || ! ieee_write_number (info
, 0)
7387 || ! ieee_write_asn (info
, info
->lineno_name_indx
,
7388 info
->pending_lineno_addr
))
7392 info
->pending_lineno_filename
= filename
;
7393 info
->pending_lineno
= lineno
;
7394 info
->pending_lineno_addr
= addr
;