1 /* ieee.c -- Read and write IEEE-695 debugging information.
2 Copyright 1996, 1998, 2000, 2001, 2002 Free Software Foundation, Inc.
3 Written by Ian Lance Taylor <ian@cygnus.com>.
5 This file is part of GNU Binutils.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22 /* This file reads and writes IEEE-695 debugging information. */
30 #include "libiberty.h"
33 #include "filenames.h"
35 /* This structure holds an entry on the block stack. */
39 /* The kind of block. */
41 /* The source file name, for a BB5 block. */
43 /* The index of the function type, for a BB4 or BB6 block. */
45 /* TRUE if this function is being skipped. */
49 /* This structure is the block stack. */
51 #define BLOCKSTACK_SIZE (16)
53 struct ieee_blockstack
55 /* The stack pointer. */
56 struct ieee_block
*bsp
;
58 struct ieee_block stack
[BLOCKSTACK_SIZE
];
61 /* This structure holds information for a variable. */
71 /* Slot if we make an indirect type. */
73 /* Kind of variable or function. */
85 /* This structure holds all the variables. */
89 /* Number of slots allocated. */
92 struct ieee_var
*vars
;
95 /* This structure holds information for a type. We need this because
96 we don't want to represent bitfields as real types. */
102 /* Slot if this is type is referenced before it is defined. */
104 /* Slots for arguments if we make indirect types for them. */
105 debug_type
*arg_slots
;
106 /* If this is a bitfield, this is the size in bits. If this is not
107 a bitfield, this is zero. */
108 unsigned long bitsize
;
111 /* This structure holds all the type information. */
115 /* Number of slots allocated. */
118 struct ieee_type
*types
;
120 #define BUILTIN_TYPE_COUNT (60)
121 debug_type builtins
[BUILTIN_TYPE_COUNT
];
124 /* This structure holds a linked last of structs with their tag names,
125 so that we can convert them to C++ classes if necessary. */
130 struct ieee_tag
*next
;
133 /* The type of the tag. */
135 /* The tagged type is an indirect type pointing at this slot. */
137 /* This is an array of slots used when a field type is converted
138 into a indirect type, in case it needs to be later converted into
143 /* This structure holds the information we pass around to the parsing
148 /* The debugging handle. */
152 /* The start of the bytes to be parsed. */
153 const bfd_byte
*bytes
;
154 /* The end of the bytes to be parsed. */
155 const bfd_byte
*pend
;
156 /* The block stack. */
157 struct ieee_blockstack blockstack
;
158 /* Whether we have seen a BB1 or BB2. */
159 bfd_boolean saw_filename
;
161 struct ieee_vars vars
;
162 /* The global variables, after a global typedef block. */
163 struct ieee_vars
*global_vars
;
165 struct ieee_types types
;
166 /* The global types, after a global typedef block. */
167 struct ieee_types
*global_types
;
168 /* The list of tagged structs. */
169 struct ieee_tag
*tags
;
172 /* Basic builtin types, not including the pointers. */
178 builtin_signed_char
= 2,
179 builtin_unsigned_char
= 3,
180 builtin_signed_short_int
= 4,
181 builtin_unsigned_short_int
= 5,
182 builtin_signed_long
= 6,
183 builtin_unsigned_long
= 7,
184 builtin_signed_long_long
= 8,
185 builtin_unsigned_long_long
= 9,
188 builtin_long_double
= 12,
189 builtin_long_long_double
= 13,
190 builtin_quoted_string
= 14,
191 builtin_instruction_address
= 15,
193 builtin_unsigned
= 17,
194 builtin_unsigned_int
= 18,
198 builtin_unsigned_short
= 22,
199 builtin_short_int
= 23,
200 builtin_signed_short
= 24,
201 builtin_bcd_float
= 25
204 /* These are the values found in the derivation flags of a 'b'
205 component record of a 'T' type extension record in a C++ pmisc
206 record. These are bitmasks. */
208 /* Set for a private base class, clear for a public base class.
209 Protected base classes are not supported. */
210 #define BASEFLAGS_PRIVATE (0x1)
211 /* Set for a virtual base class. */
212 #define BASEFLAGS_VIRTUAL (0x2)
213 /* Set for a friend class, clear for a base class. */
214 #define BASEFLAGS_FRIEND (0x10)
216 /* These are the values found in the specs flags of a 'd', 'm', or 'v'
217 component record of a 'T' type extension record in a C++ pmisc
218 record. The same flags are used for a 'M' record in a C++ pmisc
221 /* The lower two bits hold visibility information. */
222 #define CXXFLAGS_VISIBILITY (0x3)
223 /* This value in the lower two bits indicates a public member. */
224 #define CXXFLAGS_VISIBILITY_PUBLIC (0x0)
225 /* This value in the lower two bits indicates a private member. */
226 #define CXXFLAGS_VISIBILITY_PRIVATE (0x1)
227 /* This value in the lower two bits indicates a protected member. */
228 #define CXXFLAGS_VISIBILITY_PROTECTED (0x2)
229 /* Set for a static member. */
230 #define CXXFLAGS_STATIC (0x4)
231 /* Set for a virtual override. */
232 #define CXXFLAGS_OVERRIDE (0x8)
233 /* Set for a friend function. */
234 #define CXXFLAGS_FRIEND (0x10)
235 /* Set for a const function. */
236 #define CXXFLAGS_CONST (0x20)
237 /* Set for a volatile function. */
238 #define CXXFLAGS_VOLATILE (0x40)
239 /* Set for an overloaded function. */
240 #define CXXFLAGS_OVERLOADED (0x80)
241 /* Set for an operator function. */
242 #define CXXFLAGS_OPERATOR (0x100)
243 /* Set for a constructor or destructor. */
244 #define CXXFLAGS_CTORDTOR (0x400)
245 /* Set for a constructor. */
246 #define CXXFLAGS_CTOR (0x200)
247 /* Set for an inline function. */
248 #define CXXFLAGS_INLINE (0x800)
250 /* Local functions. */
252 static void ieee_error
253 PARAMS ((struct ieee_info
*, const bfd_byte
*, const char *));
255 PARAMS ((struct ieee_info
*));
256 static char *savestring
257 PARAMS ((const char *, unsigned long));
258 static bfd_boolean ieee_read_number
259 PARAMS ((struct ieee_info
*, const bfd_byte
**, bfd_vma
*));
260 static bfd_boolean ieee_read_optional_number
261 PARAMS ((struct ieee_info
*, const bfd_byte
**, bfd_vma
*, bfd_boolean
*));
262 static bfd_boolean ieee_read_id
263 PARAMS ((struct ieee_info
*, const bfd_byte
**, const char **,
265 static bfd_boolean ieee_read_optional_id
266 PARAMS ((struct ieee_info
*, const bfd_byte
**, const char **,
267 unsigned long *, bfd_boolean
*));
268 static bfd_boolean ieee_read_expression
269 PARAMS ((struct ieee_info
*, const bfd_byte
**, bfd_vma
*));
270 static debug_type ieee_builtin_type
271 PARAMS ((struct ieee_info
*, const bfd_byte
*, unsigned int));
272 static bfd_boolean ieee_alloc_type
273 PARAMS ((struct ieee_info
*, unsigned int, bfd_boolean
));
274 static bfd_boolean ieee_read_type_index
275 PARAMS ((struct ieee_info
*, const bfd_byte
**, debug_type
*));
276 static int ieee_regno_to_genreg
277 PARAMS ((bfd
*, int));
278 static int ieee_genreg_to_regno
279 PARAMS ((bfd
*, int));
280 static bfd_boolean parse_ieee_bb
281 PARAMS ((struct ieee_info
*, const bfd_byte
**));
282 static bfd_boolean parse_ieee_be
283 PARAMS ((struct ieee_info
*, const bfd_byte
**));
284 static bfd_boolean parse_ieee_nn
285 PARAMS ((struct ieee_info
*, const bfd_byte
**));
286 static bfd_boolean parse_ieee_ty
287 PARAMS ((struct ieee_info
*, const bfd_byte
**));
288 static bfd_boolean parse_ieee_atn
289 PARAMS ((struct ieee_info
*, const bfd_byte
**));
290 static bfd_boolean ieee_read_cxx_misc
291 PARAMS ((struct ieee_info
*, const bfd_byte
**, unsigned long));
292 static bfd_boolean ieee_read_cxx_class
293 PARAMS ((struct ieee_info
*, const bfd_byte
**, unsigned long));
294 static bfd_boolean ieee_read_cxx_defaults
295 PARAMS ((struct ieee_info
*, const bfd_byte
**, unsigned long));
296 static bfd_boolean ieee_read_reference
297 PARAMS ((struct ieee_info
*, const bfd_byte
**));
298 static bfd_boolean ieee_require_asn
299 PARAMS ((struct ieee_info
*, const bfd_byte
**, bfd_vma
*));
300 static bfd_boolean ieee_require_atn65
301 PARAMS ((struct ieee_info
*, const bfd_byte
**, const char **,
304 /* Report an error in the IEEE debugging information. */
307 ieee_error (info
, p
, s
)
308 struct ieee_info
*info
;
313 fprintf (stderr
, "%s: 0x%lx: %s (0x%x)\n", bfd_get_filename (info
->abfd
),
314 (unsigned long) (p
- info
->bytes
), s
, *p
);
316 fprintf (stderr
, "%s: %s\n", bfd_get_filename (info
->abfd
), s
);
319 /* Report an unexpected EOF in the IEEE debugging information. */
323 struct ieee_info
*info
;
325 ieee_error (info
, (const bfd_byte
*) NULL
,
326 _("unexpected end of debugging information"));
329 /* Save a string in memory. */
332 savestring (start
, len
)
338 ret
= (char *) xmalloc (len
+ 1);
339 memcpy (ret
, start
, len
);
344 /* Read a number which must be present in an IEEE file. */
347 ieee_read_number (info
, pp
, pv
)
348 struct ieee_info
*info
;
352 return ieee_read_optional_number (info
, pp
, pv
, (bfd_boolean
*) NULL
);
355 /* Read a number in an IEEE file. If ppresent is not NULL, the number
356 need not be there. */
359 ieee_read_optional_number (info
, pp
, pv
, ppresent
)
360 struct ieee_info
*info
;
363 bfd_boolean
*ppresent
;
365 ieee_record_enum_type b
;
367 if (*pp
>= info
->pend
)
369 if (ppresent
!= NULL
)
378 b
= (ieee_record_enum_type
) **pp
;
381 if (b
<= ieee_number_end_enum
)
384 if (ppresent
!= NULL
)
389 if (b
>= ieee_number_repeat_start_enum
&& b
<= ieee_number_repeat_end_enum
)
393 i
= (int) b
- (int) ieee_number_repeat_start_enum
;
394 if (*pp
+ i
- 1 >= info
->pend
)
408 if (ppresent
!= NULL
)
414 if (ppresent
!= NULL
)
421 ieee_error (info
, *pp
- 1, _("invalid number"));
425 /* Read a required string from an IEEE file. */
428 ieee_read_id (info
, pp
, pname
, pnamlen
)
429 struct ieee_info
*info
;
432 unsigned long *pnamlen
;
434 return ieee_read_optional_id (info
, pp
, pname
, pnamlen
, (bfd_boolean
*) NULL
);
437 /* Read a string from an IEEE file. If ppresent is not NULL, the
438 string is optional. */
441 ieee_read_optional_id (info
, pp
, pname
, pnamlen
, ppresent
)
442 struct ieee_info
*info
;
445 unsigned long *pnamlen
;
446 bfd_boolean
*ppresent
;
451 if (*pp
>= info
->pend
)
462 else if ((ieee_record_enum_type
) b
== ieee_extension_length_1_enum
)
467 else if ((ieee_record_enum_type
) b
== ieee_extension_length_2_enum
)
469 len
= (**pp
<< 8) + (*pp
)[1];
474 if (ppresent
!= NULL
)
480 ieee_error (info
, *pp
- 1, _("invalid string length"));
484 if ((unsigned long) (info
->pend
- *pp
) < len
)
490 *pname
= (const char *) *pp
;
494 if (ppresent
!= NULL
)
500 /* Read an expression from an IEEE file. Since this code is only used
501 to parse debugging information, I haven't bothered to write a full
502 blown IEEE expression parser. I've only thrown in the things I've
503 seen in debugging information. This can be easily extended if
507 ieee_read_expression (info
, pp
, pv
)
508 struct ieee_info
*info
;
512 const bfd_byte
*expr_start
;
513 #define EXPR_STACK_SIZE (10)
514 bfd_vma expr_stack
[EXPR_STACK_SIZE
];
523 const bfd_byte
*start
;
526 ieee_record_enum_type c
;
530 if (! ieee_read_optional_number (info
, pp
, &val
, &present
))
535 if (esp
- expr_stack
>= EXPR_STACK_SIZE
)
537 ieee_error (info
, start
, _("expression stack overflow"));
544 c
= (ieee_record_enum_type
) **pp
;
546 if (c
>= ieee_module_beginning_enum
)
557 ieee_error (info
, start
, _("unsupported IEEE expression operator"));
560 case ieee_variable_R_enum
:
565 if (! ieee_read_number (info
, pp
, &indx
))
567 for (s
= info
->abfd
->sections
; s
!= NULL
; s
= s
->next
)
568 if ((bfd_vma
) s
->target_index
== indx
)
572 ieee_error (info
, start
, _("unknown section"));
576 if (esp
- expr_stack
>= EXPR_STACK_SIZE
)
578 ieee_error (info
, start
, _("expression stack overflow"));
582 *esp
++ = bfd_get_section_vma (info
->abfd
, s
);
586 case ieee_function_plus_enum
:
587 case ieee_function_minus_enum
:
591 if (esp
- expr_stack
< 2)
593 ieee_error (info
, start
, _("expression stack underflow"));
605 if (esp
- 1 != expr_stack
)
607 ieee_error (info
, expr_start
, _("expression stack mismatch"));
616 /* Return an IEEE builtin type. */
619 ieee_builtin_type (info
, p
, indx
)
620 struct ieee_info
*info
;
628 if (indx
< BUILTIN_TYPE_COUNT
629 && info
->types
.builtins
[indx
] != DEBUG_TYPE_NULL
)
630 return info
->types
.builtins
[indx
];
632 dhandle
= info
->dhandle
;
634 if (indx
>= 32 && indx
< 64)
636 type
= debug_make_pointer_type (dhandle
,
637 ieee_builtin_type (info
, p
, indx
- 32));
638 assert (indx
< BUILTIN_TYPE_COUNT
);
639 info
->types
.builtins
[indx
] = type
;
643 switch ((enum builtin_types
) indx
)
646 ieee_error (info
, p
, _("unknown builtin type"));
649 case builtin_unknown
:
650 type
= debug_make_void_type (dhandle
);
655 type
= debug_make_void_type (dhandle
);
659 case builtin_signed_char
:
660 type
= debug_make_int_type (dhandle
, 1, FALSE
);
661 name
= "signed char";
664 case builtin_unsigned_char
:
665 type
= debug_make_int_type (dhandle
, 1, TRUE
);
666 name
= "unsigned char";
669 case builtin_signed_short_int
:
670 type
= debug_make_int_type (dhandle
, 2, FALSE
);
671 name
= "signed short int";
674 case builtin_unsigned_short_int
:
675 type
= debug_make_int_type (dhandle
, 2, TRUE
);
676 name
= "unsigned short int";
679 case builtin_signed_long
:
680 type
= debug_make_int_type (dhandle
, 4, FALSE
);
681 name
= "signed long";
684 case builtin_unsigned_long
:
685 type
= debug_make_int_type (dhandle
, 4, TRUE
);
686 name
= "unsigned long";
689 case builtin_signed_long_long
:
690 type
= debug_make_int_type (dhandle
, 8, FALSE
);
691 name
= "signed long long";
694 case builtin_unsigned_long_long
:
695 type
= debug_make_int_type (dhandle
, 8, TRUE
);
696 name
= "unsigned long long";
700 type
= debug_make_float_type (dhandle
, 4);
705 type
= debug_make_float_type (dhandle
, 8);
709 case builtin_long_double
:
710 /* FIXME: The size for this type should depend upon the
712 type
= debug_make_float_type (dhandle
, 12);
713 name
= "long double";
716 case builtin_long_long_double
:
717 type
= debug_make_float_type (dhandle
, 16);
718 name
= "long long double";
721 case builtin_quoted_string
:
722 type
= debug_make_array_type (dhandle
,
723 ieee_builtin_type (info
, p
,
726 ieee_builtin_type (info
, p
,
730 name
= "QUOTED STRING";
733 case builtin_instruction_address
:
734 /* FIXME: This should be a code address. */
735 type
= debug_make_int_type (dhandle
, 4, TRUE
);
736 name
= "instruction address";
740 /* FIXME: The size for this type should depend upon the
742 type
= debug_make_int_type (dhandle
, 4, FALSE
);
746 case builtin_unsigned
:
747 /* FIXME: The size for this type should depend upon the
749 type
= debug_make_int_type (dhandle
, 4, TRUE
);
753 case builtin_unsigned_int
:
754 /* FIXME: The size for this type should depend upon the
756 type
= debug_make_int_type (dhandle
, 4, TRUE
);
757 name
= "unsigned int";
761 type
= debug_make_int_type (dhandle
, 1, FALSE
);
766 type
= debug_make_int_type (dhandle
, 4, FALSE
);
771 type
= debug_make_int_type (dhandle
, 2, FALSE
);
775 case builtin_unsigned_short
:
776 type
= debug_make_int_type (dhandle
, 2, TRUE
);
777 name
= "unsigned short";
780 case builtin_short_int
:
781 type
= debug_make_int_type (dhandle
, 2, FALSE
);
785 case builtin_signed_short
:
786 type
= debug_make_int_type (dhandle
, 2, FALSE
);
787 name
= "signed short";
790 case builtin_bcd_float
:
791 ieee_error (info
, p
, _("BCD float type not supported"));
792 return DEBUG_TYPE_NULL
;
796 type
= debug_name_type (dhandle
, name
, type
);
798 assert (indx
< BUILTIN_TYPE_COUNT
);
800 info
->types
.builtins
[indx
] = type
;
805 /* Allocate more space in the type table. If ref is TRUE, this is a
806 reference to the type; if it is not already defined, we should set
807 up an indirect type. */
810 ieee_alloc_type (info
, indx
, ref
)
811 struct ieee_info
*info
;
816 register struct ieee_type
*t
;
817 struct ieee_type
*tend
;
819 if (indx
>= info
->types
.alloc
)
821 nalloc
= info
->types
.alloc
;
824 while (indx
>= nalloc
)
827 info
->types
.types
= ((struct ieee_type
*)
828 xrealloc (info
->types
.types
,
829 nalloc
* sizeof *info
->types
.types
));
831 memset (info
->types
.types
+ info
->types
.alloc
, 0,
832 (nalloc
- info
->types
.alloc
) * sizeof *info
->types
.types
);
834 tend
= info
->types
.types
+ nalloc
;
835 for (t
= info
->types
.types
+ info
->types
.alloc
; t
< tend
; t
++)
836 t
->type
= DEBUG_TYPE_NULL
;
838 info
->types
.alloc
= nalloc
;
843 t
= info
->types
.types
+ indx
;
846 t
->pslot
= (debug_type
*) xmalloc (sizeof *t
->pslot
);
847 *t
->pslot
= DEBUG_TYPE_NULL
;
848 t
->type
= debug_make_indirect_type (info
->dhandle
, t
->pslot
,
849 (const char *) NULL
);
858 /* Read a type index and return the corresponding type. */
861 ieee_read_type_index (info
, pp
, ptype
)
862 struct ieee_info
*info
;
866 const bfd_byte
*start
;
871 if (! ieee_read_number (info
, pp
, &indx
))
876 *ptype
= ieee_builtin_type (info
, start
, indx
);
883 if (! ieee_alloc_type (info
, indx
, TRUE
))
886 *ptype
= info
->types
.types
[indx
].type
;
891 /* Parse IEEE debugging information for a file. This is passed the
892 bytes which compose the Debug Information Part of an IEEE file. */
895 parse_ieee (dhandle
, abfd
, bytes
, len
)
898 const bfd_byte
*bytes
;
901 struct ieee_info info
;
903 const bfd_byte
*p
, *pend
;
905 info
.dhandle
= dhandle
;
908 info
.pend
= bytes
+ len
;
909 info
.blockstack
.bsp
= info
.blockstack
.stack
;
910 info
.saw_filename
= FALSE
;
912 info
.vars
.vars
= NULL
;
913 info
.global_vars
= NULL
;
914 info
.types
.alloc
= 0;
915 info
.types
.types
= NULL
;
916 info
.global_types
= NULL
;
918 for (i
= 0; i
< BUILTIN_TYPE_COUNT
; i
++)
919 info
.types
.builtins
[i
] = DEBUG_TYPE_NULL
;
925 const bfd_byte
*record_start
;
926 ieee_record_enum_type c
;
930 c
= (ieee_record_enum_type
) *p
++;
932 if (c
== ieee_at_record_enum
)
933 c
= (ieee_record_enum_type
) (((unsigned int) c
<< 8) | *p
++);
935 if (c
<= ieee_number_repeat_end_enum
)
937 ieee_error (&info
, record_start
, _("unexpected number"));
944 ieee_error (&info
, record_start
, _("unexpected record type"));
947 case ieee_bb_record_enum
:
948 if (! parse_ieee_bb (&info
, &p
))
952 case ieee_be_record_enum
:
953 if (! parse_ieee_be (&info
, &p
))
958 if (! parse_ieee_nn (&info
, &p
))
962 case ieee_ty_record_enum
:
963 if (! parse_ieee_ty (&info
, &p
))
967 case ieee_atn_record_enum
:
968 if (! parse_ieee_atn (&info
, &p
))
974 if (info
.blockstack
.bsp
!= info
.blockstack
.stack
)
976 ieee_error (&info
, (const bfd_byte
*) NULL
,
977 _("blocks left on stack at end"));
984 /* Handle an IEEE BB record. */
987 parse_ieee_bb (info
, pp
)
988 struct ieee_info
*info
;
991 const bfd_byte
*block_start
;
995 unsigned long namlen
;
996 char *namcopy
= NULL
;
1005 if (! ieee_read_number (info
, pp
, &size
)
1006 || ! ieee_read_id (info
, pp
, &name
, &namlen
))
1009 fnindx
= (unsigned int) -1;
1015 /* BB1: Type definitions local to a module. */
1016 namcopy
= savestring (name
, namlen
);
1017 if (namcopy
== NULL
)
1019 if (! debug_set_filename (info
->dhandle
, namcopy
))
1021 info
->saw_filename
= TRUE
;
1023 /* Discard any variables or types we may have seen before. */
1024 if (info
->vars
.vars
!= NULL
)
1025 free (info
->vars
.vars
);
1026 info
->vars
.vars
= NULL
;
1027 info
->vars
.alloc
= 0;
1028 if (info
->types
.types
!= NULL
)
1029 free (info
->types
.types
);
1030 info
->types
.types
= NULL
;
1031 info
->types
.alloc
= 0;
1033 /* Initialize the types to the global types. */
1034 if (info
->global_types
!= NULL
)
1036 info
->types
.alloc
= info
->global_types
->alloc
;
1037 info
->types
.types
= ((struct ieee_type
*)
1038 xmalloc (info
->types
.alloc
1039 * sizeof (*info
->types
.types
)));
1040 memcpy (info
->types
.types
, info
->global_types
->types
,
1041 info
->types
.alloc
* sizeof (*info
->types
.types
));
1047 /* BB2: Global type definitions. The name is supposed to be
1048 empty, but we don't check. */
1049 if (! debug_set_filename (info
->dhandle
, "*global*"))
1051 info
->saw_filename
= TRUE
;
1055 /* BB3: High level module block begin. We don't have to do
1056 anything here. The name is supposed to be the same as for
1057 the BB1, but we don't check. */
1061 /* BB4: Global function. */
1063 bfd_vma stackspace
, typindx
, offset
;
1064 debug_type return_type
;
1066 if (! ieee_read_number (info
, pp
, &stackspace
)
1067 || ! ieee_read_number (info
, pp
, &typindx
)
1068 || ! ieee_read_expression (info
, pp
, &offset
))
1071 /* We have no way to record the stack space. FIXME. */
1075 return_type
= ieee_builtin_type (info
, block_start
, typindx
);
1076 if (return_type
== DEBUG_TYPE_NULL
)
1082 if (! ieee_alloc_type (info
, typindx
, TRUE
))
1085 return_type
= info
->types
.types
[typindx
].type
;
1086 if (debug_get_type_kind (info
->dhandle
, return_type
)
1087 == DEBUG_KIND_FUNCTION
)
1088 return_type
= debug_get_return_type (info
->dhandle
,
1092 namcopy
= savestring (name
, namlen
);
1093 if (namcopy
== NULL
)
1095 if (! debug_record_function (info
->dhandle
, namcopy
, return_type
,
1102 /* BB5: File name for source line numbers. */
1106 /* We ignore the date and time. FIXME. */
1107 for (i
= 0; i
< 6; i
++)
1110 bfd_boolean present
;
1112 if (! ieee_read_optional_number (info
, pp
, &ignore
, &present
))
1118 namcopy
= savestring (name
, namlen
);
1119 if (namcopy
== NULL
)
1121 if (! debug_start_source (info
->dhandle
, namcopy
))
1127 /* BB6: Local function or block. */
1129 bfd_vma stackspace
, typindx
, offset
;
1131 if (! ieee_read_number (info
, pp
, &stackspace
)
1132 || ! ieee_read_number (info
, pp
, &typindx
)
1133 || ! ieee_read_expression (info
, pp
, &offset
))
1136 /* We have no way to record the stack space. FIXME. */
1140 if (! debug_start_block (info
->dhandle
, offset
))
1142 /* Change b to indicate that this is a block
1143 rather than a function. */
1148 /* The MRI C++ compiler will output a fake function named
1149 __XRYCPP to hold C++ debugging information. We skip
1150 that function. This is not crucial, but it makes
1151 converting from IEEE to other debug formats work
1153 if (strncmp (name
, "__XRYCPP", namlen
) == 0)
1157 debug_type return_type
;
1161 return_type
= ieee_builtin_type (info
, block_start
,
1163 if (return_type
== NULL
)
1169 if (! ieee_alloc_type (info
, typindx
, TRUE
))
1172 return_type
= info
->types
.types
[typindx
].type
;
1173 if (debug_get_type_kind (info
->dhandle
, return_type
)
1174 == DEBUG_KIND_FUNCTION
)
1175 return_type
= debug_get_return_type (info
->dhandle
,
1179 namcopy
= savestring (name
, namlen
);
1180 if (namcopy
== NULL
)
1182 if (! debug_record_function (info
->dhandle
, namcopy
,
1183 return_type
, FALSE
, offset
))
1191 /* BB10: Assembler module scope. In the normal case, we
1192 completely ignore all this information. FIXME. */
1194 const char *inam
, *vstr
;
1195 unsigned long inamlen
, vstrlen
;
1197 bfd_boolean present
;
1200 if (! info
->saw_filename
)
1202 namcopy
= savestring (name
, namlen
);
1203 if (namcopy
== NULL
)
1205 if (! debug_set_filename (info
->dhandle
, namcopy
))
1207 info
->saw_filename
= TRUE
;
1210 if (! ieee_read_id (info
, pp
, &inam
, &inamlen
)
1211 || ! ieee_read_number (info
, pp
, &tool_type
)
1212 || ! ieee_read_optional_id (info
, pp
, &vstr
, &vstrlen
, &present
))
1214 for (i
= 0; i
< 6; i
++)
1218 if (! ieee_read_optional_number (info
, pp
, &ignore
, &present
))
1227 /* BB11: Module section. We completely ignore all this
1228 information. FIXME. */
1230 bfd_vma sectype
, secindx
, offset
, map
;
1231 bfd_boolean present
;
1233 if (! ieee_read_number (info
, pp
, §ype
)
1234 || ! ieee_read_number (info
, pp
, &secindx
)
1235 || ! ieee_read_expression (info
, pp
, &offset
)
1236 || ! ieee_read_optional_number (info
, pp
, &map
, &present
))
1242 ieee_error (info
, block_start
, _("unknown BB type"));
1247 /* Push this block on the block stack. */
1249 if (info
->blockstack
.bsp
>= info
->blockstack
.stack
+ BLOCKSTACK_SIZE
)
1251 ieee_error (info
, (const bfd_byte
*) NULL
, _("stack overflow"));
1255 info
->blockstack
.bsp
->kind
= b
;
1257 info
->blockstack
.bsp
->filename
= namcopy
;
1258 info
->blockstack
.bsp
->fnindx
= fnindx
;
1259 info
->blockstack
.bsp
->skip
= skip
;
1260 ++info
->blockstack
.bsp
;
1265 /* Handle an IEEE BE record. */
1268 parse_ieee_be (info
, pp
)
1269 struct ieee_info
*info
;
1270 const bfd_byte
**pp
;
1274 if (info
->blockstack
.bsp
<= info
->blockstack
.stack
)
1276 ieee_error (info
, *pp
, _("stack underflow"));
1279 --info
->blockstack
.bsp
;
1281 switch (info
->blockstack
.bsp
->kind
)
1284 /* When we end the global typedefs block, we copy out the the
1285 contents of info->vars. This is because the variable indices
1286 may be reused in the local blocks. However, we need to
1287 preserve them so that we can locate a function returning a
1288 reference variable whose type is named in the global typedef
1290 info
->global_vars
= ((struct ieee_vars
*)
1291 xmalloc (sizeof *info
->global_vars
));
1292 info
->global_vars
->alloc
= info
->vars
.alloc
;
1293 info
->global_vars
->vars
= ((struct ieee_var
*)
1294 xmalloc (info
->vars
.alloc
1295 * sizeof (*info
->vars
.vars
)));
1296 memcpy (info
->global_vars
->vars
, info
->vars
.vars
,
1297 info
->vars
.alloc
* sizeof (*info
->vars
.vars
));
1299 /* We also copy out the non builtin parts of info->types, since
1300 the types are discarded when we start a new block. */
1301 info
->global_types
= ((struct ieee_types
*)
1302 xmalloc (sizeof *info
->global_types
));
1303 info
->global_types
->alloc
= info
->types
.alloc
;
1304 info
->global_types
->types
= ((struct ieee_type
*)
1305 xmalloc (info
->types
.alloc
1306 * sizeof (*info
->types
.types
)));
1307 memcpy (info
->global_types
->types
, info
->types
.types
,
1308 info
->types
.alloc
* sizeof (*info
->types
.types
));
1309 memset (info
->global_types
->builtins
, 0,
1310 sizeof (info
->global_types
->builtins
));
1316 if (! ieee_read_expression (info
, pp
, &offset
))
1318 if (! info
->blockstack
.bsp
->skip
)
1320 if (! debug_end_function (info
->dhandle
, offset
+ 1))
1326 /* This is BE6 when BB6 started a block rather than a local
1328 if (! ieee_read_expression (info
, pp
, &offset
))
1330 if (! debug_end_block (info
->dhandle
, offset
+ 1))
1335 /* When we end a BB5, we look up the stack for the last BB5, if
1336 there is one, so that we can call debug_start_source. */
1337 if (info
->blockstack
.bsp
> info
->blockstack
.stack
)
1339 struct ieee_block
*bl
;
1341 bl
= info
->blockstack
.bsp
;
1347 if (! debug_start_source (info
->dhandle
, bl
->filename
))
1352 while (bl
!= info
->blockstack
.stack
);
1357 if (! ieee_read_expression (info
, pp
, &offset
))
1359 /* We just ignore the module size. FIXME. */
1363 /* Other block types do not have any trailing information. */
1370 /* Parse an NN record. */
1373 parse_ieee_nn (info
, pp
)
1374 struct ieee_info
*info
;
1375 const bfd_byte
**pp
;
1377 const bfd_byte
*nn_start
;
1380 unsigned long namlen
;
1384 if (! ieee_read_number (info
, pp
, &varindx
)
1385 || ! ieee_read_id (info
, pp
, &name
, &namlen
))
1390 ieee_error (info
, nn_start
, _("illegal variable index"));
1395 if (varindx
>= info
->vars
.alloc
)
1399 alloc
= info
->vars
.alloc
;
1402 while (varindx
>= alloc
)
1404 info
->vars
.vars
= ((struct ieee_var
*)
1405 xrealloc (info
->vars
.vars
,
1406 alloc
* sizeof *info
->vars
.vars
));
1407 memset (info
->vars
.vars
+ info
->vars
.alloc
, 0,
1408 (alloc
- info
->vars
.alloc
) * sizeof *info
->vars
.vars
);
1409 info
->vars
.alloc
= alloc
;
1412 info
->vars
.vars
[varindx
].name
= name
;
1413 info
->vars
.vars
[varindx
].namlen
= namlen
;
1418 /* Parse a TY record. */
1421 parse_ieee_ty (info
, pp
)
1422 struct ieee_info
*info
;
1423 const bfd_byte
**pp
;
1425 const bfd_byte
*ty_start
, *ty_var_start
, *ty_code_start
;
1426 bfd_vma typeindx
, varindx
, tc
;
1428 bfd_boolean tag
, typdef
;
1429 debug_type
*arg_slots
;
1430 unsigned long type_bitsize
;
1435 if (! ieee_read_number (info
, pp
, &typeindx
))
1440 ieee_error (info
, ty_start
, _("illegal type index"));
1445 if (! ieee_alloc_type (info
, typeindx
, FALSE
))
1450 ieee_error (info
, *pp
, _("unknown TY code"));
1457 if (! ieee_read_number (info
, pp
, &varindx
))
1462 ieee_error (info
, ty_var_start
, _("illegal variable index"));
1467 if (varindx
>= info
->vars
.alloc
|| info
->vars
.vars
[varindx
].name
== NULL
)
1469 ieee_error (info
, ty_var_start
, _("undefined variable in TY"));
1473 ty_code_start
= *pp
;
1475 if (! ieee_read_number (info
, pp
, &tc
))
1478 dhandle
= info
->dhandle
;
1487 ieee_error (info
, ty_code_start
, _("unknown TY code"));
1491 /* Unknown type, with size. We treat it as int. FIXME. */
1495 if (! ieee_read_number (info
, pp
, &size
))
1497 type
= debug_make_int_type (dhandle
, size
, FALSE
);
1501 case 'A': /* Array. */
1502 case 'a': /* FORTRAN array in column/row order. FIXME: Not
1503 distinguished from normal array. */
1505 debug_type ele_type
;
1506 bfd_vma lower
, upper
;
1508 if (! ieee_read_type_index (info
, pp
, &ele_type
)
1509 || ! ieee_read_number (info
, pp
, &lower
)
1510 || ! ieee_read_number (info
, pp
, &upper
))
1512 type
= debug_make_array_type (dhandle
, ele_type
,
1513 ieee_builtin_type (info
, ty_code_start
,
1516 (bfd_signed_vma
) lower
,
1517 (bfd_signed_vma
) upper
,
1523 /* Simple enumeration. */
1529 bfd_signed_vma
*vals
;
1532 if (! ieee_read_number (info
, pp
, &size
))
1534 /* FIXME: we ignore the enumeration size. */
1537 names
= (const char **) xmalloc (alloc
* sizeof *names
);
1538 memset (names
, 0, alloc
* sizeof *names
);
1543 unsigned long namlen
;
1544 bfd_boolean present
;
1546 if (! ieee_read_optional_id (info
, pp
, &name
, &namlen
, &present
))
1554 names
= ((const char **)
1555 xrealloc (names
, alloc
* sizeof *names
));
1558 names
[c
] = savestring (name
, namlen
);
1559 if (names
[c
] == NULL
)
1566 vals
= (bfd_signed_vma
*) xmalloc (c
* sizeof *vals
);
1567 for (i
= 0; i
< c
; i
++)
1570 type
= debug_make_enum_type (dhandle
, names
, vals
);
1576 /* Struct with bit fields. */
1580 debug_field
*fields
;
1583 if (! ieee_read_number (info
, pp
, &size
))
1587 fields
= (debug_field
*) xmalloc (alloc
* sizeof *fields
);
1592 unsigned long namlen
;
1593 bfd_boolean present
;
1595 bfd_vma bitpos
, bitsize
;
1597 if (! ieee_read_optional_id (info
, pp
, &name
, &namlen
, &present
))
1601 if (! ieee_read_type_index (info
, pp
, &ftype
)
1602 || ! ieee_read_number (info
, pp
, &bitpos
)
1603 || ! ieee_read_number (info
, pp
, &bitsize
))
1609 fields
= ((debug_field
*)
1610 xrealloc (fields
, alloc
* sizeof *fields
));
1613 fields
[c
] = debug_make_field (dhandle
, savestring (name
, namlen
),
1614 ftype
, bitpos
, bitsize
,
1615 DEBUG_VISIBILITY_PUBLIC
);
1616 if (fields
[c
] == NULL
)
1623 type
= debug_make_struct_type (dhandle
, TRUE
, size
, fields
);
1633 bfd_signed_vma
*vals
;
1637 names
= (const char **) xmalloc (alloc
* sizeof *names
);
1638 vals
= (bfd_signed_vma
*) xmalloc (alloc
* sizeof *names
);
1643 unsigned long namlen
;
1644 bfd_boolean present
;
1647 if (! ieee_read_optional_id (info
, pp
, &name
, &namlen
, &present
))
1651 if (! ieee_read_number (info
, pp
, &val
))
1654 /* If the length of the name is zero, then the value is
1655 actually the size of the enum. We ignore this
1656 information. FIXME. */
1663 names
= ((const char **)
1664 xrealloc (names
, alloc
* sizeof *names
));
1665 vals
= ((bfd_signed_vma
*)
1666 xrealloc (vals
, alloc
* sizeof *vals
));
1669 names
[c
] = savestring (name
, namlen
);
1670 if (names
[c
] == NULL
)
1672 vals
[c
] = (bfd_signed_vma
) val
;
1678 type
= debug_make_enum_type (dhandle
, names
, vals
);
1683 case 'O': /* Small pointer. We don't distinguish small and large
1685 case 'P': /* Large pointer. */
1689 if (! ieee_read_type_index (info
, pp
, &t
))
1691 type
= debug_make_pointer_type (dhandle
, t
);
1698 bfd_vma low
, high
, signedp
, size
;
1700 if (! ieee_read_number (info
, pp
, &low
)
1701 || ! ieee_read_number (info
, pp
, &high
)
1702 || ! ieee_read_number (info
, pp
, &signedp
)
1703 || ! ieee_read_number (info
, pp
, &size
))
1706 type
= debug_make_range_type (dhandle
,
1707 debug_make_int_type (dhandle
, size
,
1709 (bfd_signed_vma
) low
,
1710 (bfd_signed_vma
) high
);
1714 case 'S': /* Struct. */
1715 case 'U': /* Union. */
1719 debug_field
*fields
;
1722 if (! ieee_read_number (info
, pp
, &size
))
1726 fields
= (debug_field
*) xmalloc (alloc
* sizeof *fields
);
1731 unsigned long namlen
;
1732 bfd_boolean present
;
1738 if (! ieee_read_optional_id (info
, pp
, &name
, &namlen
, &present
))
1742 if (! ieee_read_number (info
, pp
, &tindx
)
1743 || ! ieee_read_number (info
, pp
, &offset
))
1748 ftype
= ieee_builtin_type (info
, ty_code_start
, tindx
);
1754 struct ieee_type
*t
;
1757 if (! ieee_alloc_type (info
, tindx
, TRUE
))
1759 t
= info
->types
.types
+ tindx
;
1761 bitsize
= t
->bitsize
;
1769 fields
= ((debug_field
*)
1770 xrealloc (fields
, alloc
* sizeof *fields
));
1773 fields
[c
] = debug_make_field (dhandle
, savestring (name
, namlen
),
1774 ftype
, offset
, bitsize
,
1775 DEBUG_VISIBILITY_PUBLIC
);
1776 if (fields
[c
] == NULL
)
1783 type
= debug_make_struct_type (dhandle
, tc
== 'S', size
, fields
);
1790 if (! ieee_read_type_index (info
, pp
, &type
))
1796 /* Procedure. FIXME: This is an extern declaration, which we
1797 have no way of representing. */
1802 bfd_boolean present
;
1803 struct ieee_var
*pv
;
1805 /* FIXME: We ignore the attribute and the argument names. */
1807 if (! ieee_read_number (info
, pp
, &attr
)
1808 || ! ieee_read_type_index (info
, pp
, &rtype
)
1809 || ! ieee_read_number (info
, pp
, &nargs
))
1814 unsigned long namlen
;
1816 if (! ieee_read_optional_id (info
, pp
, &name
, &namlen
, &present
))
1821 pv
= info
->vars
.vars
+ varindx
;
1822 pv
->kind
= IEEE_EXTERNAL
;
1824 && debug_get_type_kind (dhandle
, rtype
) == DEBUG_KIND_POINTER
)
1826 /* Set up the return type as an indirect type pointing to
1827 the variable slot, so that we can change it to a
1828 reference later if appropriate. */
1829 pv
->pslot
= (debug_type
*) xmalloc (sizeof *pv
->pslot
);
1831 rtype
= debug_make_indirect_type (dhandle
, pv
->pslot
,
1832 (const char *) NULL
);
1835 type
= debug_make_function_type (dhandle
, rtype
, (debug_type
*) NULL
,
1841 /* Void. This is not documented, but the MRI compiler emits it. */
1842 type
= debug_make_void_type (dhandle
);
1846 /* Array with 0 lower bound. */
1851 if (! ieee_read_type_index (info
, pp
, &etype
)
1852 || ! ieee_read_number (info
, pp
, &high
))
1855 type
= debug_make_array_type (dhandle
, etype
,
1856 ieee_builtin_type (info
, ty_code_start
,
1859 0, (bfd_signed_vma
) high
, FALSE
);
1863 case 'c': /* Complex. */
1864 case 'd': /* Double complex. */
1867 unsigned long namlen
;
1869 /* FIXME: I don't know what the name means. */
1871 if (! ieee_read_id (info
, pp
, &name
, &namlen
))
1874 type
= debug_make_complex_type (dhandle
, tc
== 'c' ? 4 : 8);
1879 /* Pascal file name. FIXME. */
1880 ieee_error (info
, ty_code_start
, _("Pascal file name not supported"));
1884 /* Bitfield type. */
1886 bfd_vma signedp
, bitsize
, dummy
;
1887 const bfd_byte
*hold
;
1888 bfd_boolean present
;
1890 if (! ieee_read_number (info
, pp
, &signedp
)
1891 || ! ieee_read_number (info
, pp
, &bitsize
))
1894 /* I think the documentation says that there is a type index,
1895 but some actual files do not have one. */
1897 if (! ieee_read_optional_number (info
, pp
, &dummy
, &present
))
1901 /* FIXME: This is just a guess. */
1902 type
= debug_make_int_type (dhandle
, 4,
1903 signedp
? FALSE
: TRUE
);
1908 if (! ieee_read_type_index (info
, pp
, &type
))
1911 type_bitsize
= bitsize
;
1921 if (! ieee_read_number (info
, pp
, &kind
)
1922 || ! ieee_read_type_index (info
, pp
, &t
))
1928 ieee_error (info
, ty_start
, _("unsupported qualifier"));
1932 type
= debug_make_const_type (dhandle
, t
);
1936 type
= debug_make_volatile_type (dhandle
, t
);
1948 if (! ieee_read_number (info
, pp
, &size
)
1949 || ! ieee_read_type_index (info
, pp
, &etype
))
1952 /* FIXME: We ignore the size. */
1954 type
= debug_make_set_type (dhandle
, etype
, FALSE
);
1959 /* Procedure with compiler dependencies. */
1961 struct ieee_var
*pv
;
1962 bfd_vma attr
, frame_type
, push_mask
, nargs
, level
, father
;
1964 debug_type
*arg_types
;
1965 bfd_boolean varargs
;
1966 bfd_boolean present
;
1968 /* FIXME: We ignore some of this information. */
1970 pv
= info
->vars
.vars
+ varindx
;
1972 if (! ieee_read_number (info
, pp
, &attr
)
1973 || ! ieee_read_number (info
, pp
, &frame_type
)
1974 || ! ieee_read_number (info
, pp
, &push_mask
)
1975 || ! ieee_read_type_index (info
, pp
, &rtype
)
1976 || ! ieee_read_number (info
, pp
, &nargs
))
1978 if (nargs
== (bfd_vma
) -1)
1987 arg_types
= ((debug_type
*)
1988 xmalloc ((nargs
+ 1) * sizeof *arg_types
));
1989 for (i
= 0; i
< nargs
; i
++)
1990 if (! ieee_read_type_index (info
, pp
, arg_types
+ i
))
1993 /* If the last type is pointer to void, this is really a
1994 varargs function. */
2000 last
= arg_types
[nargs
- 1];
2001 if (debug_get_type_kind (dhandle
, last
) == DEBUG_KIND_POINTER
2002 && (debug_get_type_kind (dhandle
,
2003 debug_get_target_type (dhandle
,
2005 == DEBUG_KIND_VOID
))
2012 /* If there are any pointer arguments, turn them into
2013 indirect types in case we later need to convert them to
2015 for (i
= 0; i
< nargs
; i
++)
2017 if (debug_get_type_kind (dhandle
, arg_types
[i
])
2018 == DEBUG_KIND_POINTER
)
2020 if (arg_slots
== NULL
)
2022 arg_slots
= ((debug_type
*)
2023 xmalloc (nargs
* sizeof *arg_slots
));
2024 memset (arg_slots
, 0, nargs
* sizeof *arg_slots
);
2026 arg_slots
[i
] = arg_types
[i
];
2028 debug_make_indirect_type (dhandle
,
2030 (const char *) NULL
);
2034 arg_types
[nargs
] = DEBUG_TYPE_NULL
;
2036 if (! ieee_read_number (info
, pp
, &level
)
2037 || ! ieee_read_optional_number (info
, pp
, &father
, &present
))
2040 /* We can't distinguish between a global function and a static
2042 pv
->kind
= IEEE_FUNCTION
;
2045 && debug_get_type_kind (dhandle
, rtype
) == DEBUG_KIND_POINTER
)
2047 /* Set up the return type as an indirect type pointing to
2048 the variable slot, so that we can change it to a
2049 reference later if appropriate. */
2050 pv
->pslot
= (debug_type
*) xmalloc (sizeof *pv
->pslot
);
2052 rtype
= debug_make_indirect_type (dhandle
, pv
->pslot
,
2053 (const char *) NULL
);
2056 type
= debug_make_function_type (dhandle
, rtype
, arg_types
, varargs
);
2061 /* Record the type in the table. */
2063 if (type
== DEBUG_TYPE_NULL
)
2066 info
->vars
.vars
[varindx
].type
= type
;
2069 && info
->vars
.vars
[varindx
].namlen
> 0)
2073 name
= savestring (info
->vars
.vars
[varindx
].name
,
2074 info
->vars
.vars
[varindx
].namlen
);
2076 type
= debug_name_type (dhandle
, name
, type
);
2077 else if (tc
== 'E' || tc
== 'N')
2078 type
= debug_tag_type (dhandle
, name
, type
);
2081 struct ieee_tag
*it
;
2083 /* We must allocate all struct tags as indirect types, so
2084 that if we later see a definition of the tag as a C++
2085 record we can update the indirect slot and automatically
2086 change all the existing references. */
2087 it
= (struct ieee_tag
*) xmalloc (sizeof *it
);
2088 memset (it
, 0, sizeof *it
);
2089 it
->next
= info
->tags
;
2094 type
= debug_make_indirect_type (dhandle
, &it
->slot
, name
);
2095 type
= debug_tag_type (dhandle
, name
, type
);
2103 info
->types
.types
[typeindx
].type
= type
;
2104 info
->types
.types
[typeindx
].arg_slots
= arg_slots
;
2105 info
->types
.types
[typeindx
].bitsize
= type_bitsize
;
2107 /* We may have already allocated type as an indirect type pointing
2108 to slot. It does no harm to replace the indirect type with the
2109 real type. Filling in slot as well handles the indirect types
2110 which are already hanging around. */
2111 if (info
->types
.types
[typeindx
].pslot
!= NULL
)
2112 *info
->types
.types
[typeindx
].pslot
= type
;
2117 /* Parse an ATN record. */
2120 parse_ieee_atn (info
, pp
)
2121 struct ieee_info
*info
;
2122 const bfd_byte
**pp
;
2124 const bfd_byte
*atn_start
, *atn_code_start
;
2126 struct ieee_var
*pvar
;
2130 bfd_vma v
, v2
, v3
, v4
, v5
;
2132 unsigned long namlen
;
2134 bfd_boolean present
;
2139 if (! ieee_read_number (info
, pp
, &varindx
)
2140 || ! ieee_read_type_index (info
, pp
, &type
))
2143 atn_code_start
= *pp
;
2145 if (! ieee_read_number (info
, pp
, &atn_code
))
2154 else if (varindx
< 32)
2156 /* The MRI compiler reportedly sometimes emits variable lifetime
2157 information for a register. We just ignore it. */
2159 return ieee_read_number (info
, pp
, &v
);
2161 ieee_error (info
, atn_start
, _("illegal variable index"));
2167 if (varindx
>= info
->vars
.alloc
2168 || info
->vars
.vars
[varindx
].name
== NULL
)
2170 /* The MRI compiler or linker sometimes omits the NN record
2171 for a pmisc record. */
2174 if (varindx
>= info
->vars
.alloc
)
2178 alloc
= info
->vars
.alloc
;
2181 while (varindx
>= alloc
)
2183 info
->vars
.vars
= ((struct ieee_var
*)
2184 xrealloc (info
->vars
.vars
,
2186 * sizeof *info
->vars
.vars
)));
2187 memset (info
->vars
.vars
+ info
->vars
.alloc
, 0,
2188 ((alloc
- info
->vars
.alloc
)
2189 * sizeof *info
->vars
.vars
));
2190 info
->vars
.alloc
= alloc
;
2193 pvar
= info
->vars
.vars
+ varindx
;
2199 ieee_error (info
, atn_start
, _("undefined variable in ATN"));
2204 pvar
= info
->vars
.vars
+ varindx
;
2209 namlen
= pvar
->namlen
;
2212 dhandle
= info
->dhandle
;
2214 /* If we are going to call debug_record_variable with a pointer
2215 type, change the type to an indirect type so that we can later
2216 change it to a reference type if we encounter a C++ pmisc 'R'
2219 && type
!= DEBUG_TYPE_NULL
2220 && debug_get_type_kind (dhandle
, type
) == DEBUG_KIND_POINTER
)
2230 pvar
->pslot
= (debug_type
*) xmalloc (sizeof *pvar
->pslot
);
2231 *pvar
->pslot
= type
;
2232 type
= debug_make_indirect_type (dhandle
, pvar
->pslot
,
2233 (const char *) NULL
);
2242 ieee_error (info
, atn_code_start
, _("unknown ATN type"));
2246 /* Automatic variable. */
2247 if (! ieee_read_number (info
, pp
, &v
))
2249 namcopy
= savestring (name
, namlen
);
2251 type
= debug_make_void_type (dhandle
);
2253 pvar
->kind
= IEEE_LOCAL
;
2254 return debug_record_variable (dhandle
, namcopy
, type
, DEBUG_LOCAL
, v
);
2257 /* Register variable. */
2258 if (! ieee_read_number (info
, pp
, &v
))
2260 namcopy
= savestring (name
, namlen
);
2262 type
= debug_make_void_type (dhandle
);
2264 pvar
->kind
= IEEE_LOCAL
;
2265 return debug_record_variable (dhandle
, namcopy
, type
, DEBUG_REGISTER
,
2266 ieee_regno_to_genreg (info
->abfd
, v
));
2269 /* Static variable. */
2270 if (! ieee_require_asn (info
, pp
, &v
))
2272 namcopy
= savestring (name
, namlen
);
2274 type
= debug_make_void_type (dhandle
);
2275 if (info
->blockstack
.bsp
<= info
->blockstack
.stack
)
2278 blocktype
= info
->blockstack
.bsp
[-1].kind
;
2281 if (blocktype
== 4 || blocktype
== 6)
2282 pvar
->kind
= IEEE_LOCAL
;
2284 pvar
->kind
= IEEE_STATIC
;
2286 return debug_record_variable (dhandle
, namcopy
, type
,
2287 (blocktype
== 4 || blocktype
== 6
2288 ? DEBUG_LOCAL_STATIC
2293 /* External function. We don't currently record these. FIXME. */
2295 pvar
->kind
= IEEE_EXTERNAL
;
2299 /* External variable. We don't currently record these. FIXME. */
2301 pvar
->kind
= IEEE_EXTERNAL
;
2305 if (! ieee_read_number (info
, pp
, &v
)
2306 || ! ieee_read_number (info
, pp
, &v2
)
2307 || ! ieee_read_optional_number (info
, pp
, &v3
, &present
))
2311 if (! ieee_read_optional_number (info
, pp
, &v4
, &present
))
2315 /* We just ignore the two optional fields in v3 and v4, since
2316 they are not defined. */
2318 if (! ieee_require_asn (info
, pp
, &v3
))
2321 /* We have no way to record the column number. FIXME. */
2323 return debug_record_line (dhandle
, v
, v3
);
2326 /* Global variable. */
2327 if (! ieee_require_asn (info
, pp
, &v
))
2329 namcopy
= savestring (name
, namlen
);
2331 type
= debug_make_void_type (dhandle
);
2333 pvar
->kind
= IEEE_GLOBAL
;
2334 return debug_record_variable (dhandle
, namcopy
, type
, DEBUG_GLOBAL
, v
);
2337 /* Variable lifetime information. */
2338 if (! ieee_read_number (info
, pp
, &v
))
2341 /* We have no way to record this information. FIXME. */
2345 /* Locked register. The spec says that there are two required
2346 fields, but at least on occasion the MRI compiler only emits
2348 if (! ieee_read_number (info
, pp
, &v
)
2349 || ! ieee_read_optional_number (info
, pp
, &v2
, &present
))
2352 /* I think this means a variable that is both in a register and
2353 a frame slot. We ignore the frame slot. FIXME. */
2355 namcopy
= savestring (name
, namlen
);
2357 type
= debug_make_void_type (dhandle
);
2359 pvar
->kind
= IEEE_LOCAL
;
2360 return debug_record_variable (dhandle
, namcopy
, type
, DEBUG_REGISTER
, v
);
2363 /* Reserved for FORTRAN common. */
2364 ieee_error (info
, atn_code_start
, _("unsupported ATN11"));
2366 /* Return TRUE to keep going. */
2370 /* Based variable. */
2374 if (! ieee_read_number (info
, pp
, &v
)
2375 || ! ieee_read_number (info
, pp
, &v2
)
2376 || ! ieee_read_optional_number (info
, pp
, &v3
, &present
))
2380 if (! ieee_read_optional_number (info
, pp
, &v4
, &present
))
2384 if (! ieee_read_optional_number (info
, pp
, &v5
, &present
))
2389 /* We have no way to record this information. FIXME. */
2391 ieee_error (info
, atn_code_start
, _("unsupported ATN12"));
2393 /* Return TRUE to keep going. */
2397 /* Constant. The description of this that I have is ambiguous,
2398 so I'm not going to try to implement it. */
2399 if (! ieee_read_number (info
, pp
, &v
)
2400 || ! ieee_read_optional_number (info
, pp
, &v2
, &present
))
2404 if (! ieee_read_optional_number (info
, pp
, &v2
, &present
))
2408 if (! ieee_read_optional_id (info
, pp
, &name
, &namlen
, &present
))
2413 if ((ieee_record_enum_type
) **pp
== ieee_e2_first_byte_enum
)
2415 if (! ieee_require_asn (info
, pp
, &v3
))
2422 /* Static variable from assembler. */
2424 if (! ieee_read_number (info
, pp
, &v
)
2425 || ! ieee_read_optional_number (info
, pp
, &v2
, &present
)
2426 || ! ieee_require_asn (info
, pp
, &v3
))
2428 namcopy
= savestring (name
, namlen
);
2429 /* We don't really handle this correctly. FIXME. */
2430 return debug_record_variable (dhandle
, namcopy
,
2431 debug_make_void_type (dhandle
),
2432 v2
!= 0 ? DEBUG_GLOBAL
: DEBUG_STATIC
,
2436 /* Procedure miscellaneous information. */
2438 /* Variable miscellaneous information. */
2440 /* Module miscellaneous information. */
2441 if (! ieee_read_number (info
, pp
, &v
)
2442 || ! ieee_read_number (info
, pp
, &v2
)
2443 || ! ieee_read_optional_id (info
, pp
, &name
, &namlen
, &present
))
2446 if (atn_code
== 62 && v
== 80)
2450 ieee_error (info
, atn_code_start
,
2451 _("unexpected string in C++ misc"));
2454 return ieee_read_cxx_misc (info
, pp
, v2
);
2457 /* We just ignore all of this stuff. FIXME. */
2459 for (; v2
> 0; --v2
)
2461 switch ((ieee_record_enum_type
) **pp
)
2464 ieee_error (info
, *pp
, _("bad misc record"));
2467 case ieee_at_record_enum
:
2468 if (! ieee_require_atn65 (info
, pp
, &name
, &namlen
))
2472 case ieee_e2_first_byte_enum
:
2473 if (! ieee_require_asn (info
, pp
, &v3
))
2485 /* Handle C++ debugging miscellaneous records. This is called for
2486 procedure miscellaneous records of type 80. */
2489 ieee_read_cxx_misc (info
, pp
, count
)
2490 struct ieee_info
*info
;
2491 const bfd_byte
**pp
;
2492 unsigned long count
;
2494 const bfd_byte
*start
;
2499 /* Get the category of C++ misc record. */
2500 if (! ieee_require_asn (info
, pp
, &category
))
2507 ieee_error (info
, start
, _("unrecognized C++ misc record"));
2511 if (! ieee_read_cxx_class (info
, pp
, count
))
2519 unsigned long namlen
;
2521 /* The IEEE spec indicates that the 'M' record only has a
2522 flags field. The MRI compiler also emits the name of the
2525 if (! ieee_require_asn (info
, pp
, &flags
))
2527 if (*pp
< info
->pend
2528 && (ieee_record_enum_type
) **pp
== ieee_at_record_enum
)
2530 if (! ieee_require_atn65 (info
, pp
, &name
, &namlen
))
2534 /* This is emitted for method functions, but I don't think we
2535 care very much. It might help if it told us useful
2536 information like the class with which this function is
2537 associated, but it doesn't, so it isn't helpful. */
2542 if (! ieee_read_cxx_defaults (info
, pp
, count
))
2548 const char *name
, *mangled
, *class;
2549 unsigned long namlen
, mangledlen
, classlen
;
2552 /* Pointer to member. */
2554 if (! ieee_require_atn65 (info
, pp
, &name
, &namlen
)
2555 || ! ieee_require_atn65 (info
, pp
, &mangled
, &mangledlen
)
2556 || ! ieee_require_atn65 (info
, pp
, &class, &classlen
)
2557 || ! ieee_require_asn (info
, pp
, &control
))
2560 /* FIXME: We should now track down name and change its type. */
2565 if (! ieee_read_reference (info
, pp
))
2573 /* Read a C++ class definition. This is a pmisc type 80 record of
2577 ieee_read_cxx_class (info
, pp
, count
)
2578 struct ieee_info
*info
;
2579 const bfd_byte
**pp
;
2580 unsigned long count
;
2582 const bfd_byte
*start
;
2585 unsigned long taglen
;
2586 struct ieee_tag
*it
;
2588 debug_field
*fields
;
2589 unsigned int field_count
, field_alloc
;
2590 debug_baseclass
*baseclasses
;
2591 unsigned int baseclasses_count
, baseclasses_alloc
;
2592 const debug_field
*structfields
;
2596 unsigned long namlen
;
2597 debug_method_variant
*variants
;
2601 unsigned int methods_count
, methods_alloc
;
2602 debug_type vptrbase
;
2603 bfd_boolean ownvptr
;
2604 debug_method
*dmethods
;
2608 if (! ieee_require_asn (info
, pp
, &class))
2612 if (! ieee_require_atn65 (info
, pp
, &tag
, &taglen
))
2616 /* Find the C struct with this name. */
2617 for (it
= info
->tags
; it
!= NULL
; it
= it
->next
)
2618 if (it
->name
[0] == tag
[0]
2619 && strncmp (it
->name
, tag
, taglen
) == 0
2620 && strlen (it
->name
) == taglen
)
2624 ieee_error (info
, start
, _("undefined C++ object"));
2628 dhandle
= info
->dhandle
;
2634 baseclasses_count
= 0;
2635 baseclasses_alloc
= 0;
2639 vptrbase
= DEBUG_TYPE_NULL
;
2642 structfields
= debug_get_fields (dhandle
, it
->type
);
2647 const bfd_byte
*spec_start
;
2651 if (! ieee_require_asn (info
, pp
, &id
))
2658 ieee_error (info
, spec_start
, _("unrecognized C++ object spec"));
2663 bfd_vma flags
, cinline
;
2664 const char *basename
, *fieldname
;
2665 unsigned long baselen
, fieldlen
;
2667 debug_type basetype
;
2669 bfd_boolean virtualp
;
2670 enum debug_visibility visibility
;
2671 debug_baseclass baseclass
;
2673 /* This represents a base or friend class. */
2675 if (! ieee_require_asn (info
, pp
, &flags
)
2676 || ! ieee_require_atn65 (info
, pp
, &basename
, &baselen
)
2677 || ! ieee_require_asn (info
, pp
, &cinline
)
2678 || ! ieee_require_atn65 (info
, pp
, &fieldname
, &fieldlen
))
2682 /* We have no way of recording friend information, so we
2684 if ((flags
& BASEFLAGS_FRIEND
) != 0)
2687 /* I assume that either all of the members of the
2688 baseclass are included in the object, starting at the
2689 beginning of the object, or that none of them are
2692 if ((fieldlen
== 0) == (cinline
== 0))
2694 ieee_error (info
, start
, _("unsupported C++ object type"));
2698 basecopy
= savestring (basename
, baselen
);
2699 basetype
= debug_find_tagged_type (dhandle
, basecopy
,
2700 DEBUG_KIND_ILLEGAL
);
2702 if (basetype
== DEBUG_TYPE_NULL
)
2704 ieee_error (info
, start
, _("C++ base class not defined"));
2712 const debug_field
*pf
;
2714 if (structfields
== NULL
)
2716 ieee_error (info
, start
, _("C++ object has no fields"));
2720 for (pf
= structfields
; *pf
!= DEBUG_FIELD_NULL
; pf
++)
2724 fname
= debug_get_field_name (dhandle
, *pf
);
2727 if (fname
[0] == fieldname
[0]
2728 && strncmp (fname
, fieldname
, fieldlen
) == 0
2729 && strlen (fname
) == fieldlen
)
2732 if (*pf
== DEBUG_FIELD_NULL
)
2734 ieee_error (info
, start
,
2735 _("C++ base class not found in container"));
2739 bitpos
= debug_get_field_bitpos (dhandle
, *pf
);
2742 if ((flags
& BASEFLAGS_VIRTUAL
) != 0)
2746 if ((flags
& BASEFLAGS_PRIVATE
) != 0)
2747 visibility
= DEBUG_VISIBILITY_PRIVATE
;
2749 visibility
= DEBUG_VISIBILITY_PUBLIC
;
2751 baseclass
= debug_make_baseclass (dhandle
, basetype
, bitpos
,
2752 virtualp
, visibility
);
2753 if (baseclass
== DEBUG_BASECLASS_NULL
)
2756 if (baseclasses_count
+ 1 >= baseclasses_alloc
)
2758 baseclasses_alloc
+= 10;
2759 baseclasses
= ((debug_baseclass
*)
2760 xrealloc (baseclasses
,
2762 * sizeof *baseclasses
)));
2765 baseclasses
[baseclasses_count
] = baseclass
;
2766 ++baseclasses_count
;
2767 baseclasses
[baseclasses_count
] = DEBUG_BASECLASS_NULL
;
2774 const char *fieldname
, *mangledname
;
2775 unsigned long fieldlen
, mangledlen
;
2777 bfd_boolean staticp
;
2779 const debug_field
*pf
= NULL
;
2780 enum debug_visibility visibility
;
2783 /* This represents a data member. */
2785 if (! ieee_require_asn (info
, pp
, &flags
)
2786 || ! ieee_require_atn65 (info
, pp
, &fieldname
, &fieldlen
)
2787 || ! ieee_require_atn65 (info
, pp
, &mangledname
, &mangledlen
))
2791 fieldcopy
= savestring (fieldname
, fieldlen
);
2793 staticp
= (flags
& CXXFLAGS_STATIC
) != 0 ? TRUE
: FALSE
;
2797 struct ieee_var
*pv
, *pvend
;
2799 /* See if we can find a definition for this variable. */
2800 pv
= info
->vars
.vars
;
2801 pvend
= pv
+ info
->vars
.alloc
;
2802 for (; pv
< pvend
; pv
++)
2803 if (pv
->namlen
== mangledlen
2804 && strncmp (pv
->name
, mangledname
, mangledlen
) == 0)
2810 /* This can happen if the variable is never used. */
2811 ftype
= ieee_builtin_type (info
, start
,
2812 (unsigned int) builtin_void
);
2819 if (structfields
== NULL
)
2821 ieee_error (info
, start
, _("C++ object has no fields"));
2825 for (pf
= structfields
, findx
= 0;
2826 *pf
!= DEBUG_FIELD_NULL
;
2831 fname
= debug_get_field_name (dhandle
, *pf
);
2834 if (fname
[0] == mangledname
[0]
2835 && strncmp (fname
, mangledname
, mangledlen
) == 0
2836 && strlen (fname
) == mangledlen
)
2839 if (*pf
== DEBUG_FIELD_NULL
)
2841 ieee_error (info
, start
,
2842 _("C++ data member not found in container"));
2846 ftype
= debug_get_field_type (dhandle
, *pf
);
2848 if (debug_get_type_kind (dhandle
, ftype
) == DEBUG_KIND_POINTER
)
2850 /* We might need to convert this field into a
2851 reference type later on, so make it an indirect
2853 if (it
->fslots
== NULL
)
2856 const debug_field
*pfcnt
;
2859 for (pfcnt
= structfields
;
2860 *pfcnt
!= DEBUG_FIELD_NULL
;
2863 it
->fslots
= ((debug_type
*)
2864 xmalloc (fcnt
* sizeof *it
->fslots
));
2865 memset (it
->fslots
, 0,
2866 fcnt
* sizeof *it
->fslots
);
2869 if (ftype
== DEBUG_TYPE_NULL
)
2871 it
->fslots
[findx
] = ftype
;
2872 ftype
= debug_make_indirect_type (dhandle
,
2874 (const char *) NULL
);
2877 if (ftype
== DEBUG_TYPE_NULL
)
2880 switch (flags
& CXXFLAGS_VISIBILITY
)
2883 ieee_error (info
, start
, _("unknown C++ visibility"));
2886 case CXXFLAGS_VISIBILITY_PUBLIC
:
2887 visibility
= DEBUG_VISIBILITY_PUBLIC
;
2890 case CXXFLAGS_VISIBILITY_PRIVATE
:
2891 visibility
= DEBUG_VISIBILITY_PRIVATE
;
2894 case CXXFLAGS_VISIBILITY_PROTECTED
:
2895 visibility
= DEBUG_VISIBILITY_PROTECTED
;
2903 mangledcopy
= savestring (mangledname
, mangledlen
);
2905 field
= debug_make_static_member (dhandle
, fieldcopy
,
2911 bfd_vma bitpos
, bitsize
;
2913 bitpos
= debug_get_field_bitpos (dhandle
, *pf
);
2914 bitsize
= debug_get_field_bitsize (dhandle
, *pf
);
2915 if (bitpos
== (bfd_vma
) -1 || bitsize
== (bfd_vma
) -1)
2917 ieee_error (info
, start
, _("bad C++ field bit pos or size"));
2920 field
= debug_make_field (dhandle
, fieldcopy
, ftype
, bitpos
,
2921 bitsize
, visibility
);
2924 if (field
== DEBUG_FIELD_NULL
)
2927 if (field_count
+ 1 >= field_alloc
)
2930 fields
= ((debug_field
*)
2931 xrealloc (fields
, field_alloc
* sizeof *fields
));
2934 fields
[field_count
] = field
;
2936 fields
[field_count
] = DEBUG_FIELD_NULL
;
2943 bfd_vma flags
, voffset
, control
;
2944 const char *name
, *mangled
;
2945 unsigned long namlen
, mangledlen
;
2946 struct ieee_var
*pv
, *pvend
;
2948 enum debug_visibility visibility
;
2949 bfd_boolean constp
, volatilep
;
2951 debug_method_variant mv
;
2952 struct ieee_method
*meth
;
2955 if (! ieee_require_asn (info
, pp
, &flags
)
2956 || ! ieee_require_atn65 (info
, pp
, &name
, &namlen
)
2957 || ! ieee_require_atn65 (info
, pp
, &mangled
, &mangledlen
))
2964 if (! ieee_require_asn (info
, pp
, &voffset
))
2968 if (! ieee_require_asn (info
, pp
, &control
))
2972 /* We just ignore the control information. */
2974 /* We have no way to represent friend information, so we
2976 if ((flags
& CXXFLAGS_FRIEND
) != 0)
2979 /* We should already have seen a type for the function. */
2980 pv
= info
->vars
.vars
;
2981 pvend
= pv
+ info
->vars
.alloc
;
2982 for (; pv
< pvend
; pv
++)
2983 if (pv
->namlen
== mangledlen
2984 && strncmp (pv
->name
, mangled
, mangledlen
) == 0)
2989 /* We won't have type information for this function if
2990 it is not included in this file. We don't try to
2991 handle this case. FIXME. */
2992 type
= (debug_make_function_type
2994 ieee_builtin_type (info
, start
,
2995 (unsigned int) builtin_void
),
2996 (debug_type
*) NULL
,
3001 debug_type return_type
;
3002 const debug_type
*arg_types
;
3003 bfd_boolean varargs
;
3005 if (debug_get_type_kind (dhandle
, pv
->type
)
3006 != DEBUG_KIND_FUNCTION
)
3008 ieee_error (info
, start
,
3009 _("bad type for C++ method function"));
3013 return_type
= debug_get_return_type (dhandle
, pv
->type
);
3014 arg_types
= debug_get_parameter_types (dhandle
, pv
->type
,
3016 if (return_type
== DEBUG_TYPE_NULL
|| arg_types
== NULL
)
3018 ieee_error (info
, start
,
3019 _("no type information for C++ method function"));
3023 type
= debug_make_method_type (dhandle
, return_type
, it
->type
,
3024 (debug_type
*) arg_types
,
3027 if (type
== DEBUG_TYPE_NULL
)
3030 switch (flags
& CXXFLAGS_VISIBILITY
)
3033 ieee_error (info
, start
, _("unknown C++ visibility"));
3036 case CXXFLAGS_VISIBILITY_PUBLIC
:
3037 visibility
= DEBUG_VISIBILITY_PUBLIC
;
3040 case CXXFLAGS_VISIBILITY_PRIVATE
:
3041 visibility
= DEBUG_VISIBILITY_PRIVATE
;
3044 case CXXFLAGS_VISIBILITY_PROTECTED
:
3045 visibility
= DEBUG_VISIBILITY_PROTECTED
;
3049 constp
= (flags
& CXXFLAGS_CONST
) != 0 ? TRUE
: FALSE
;
3050 volatilep
= (flags
& CXXFLAGS_VOLATILE
) != 0 ? TRUE
: FALSE
;
3052 mangledcopy
= savestring (mangled
, mangledlen
);
3054 if ((flags
& CXXFLAGS_STATIC
) != 0)
3058 ieee_error (info
, start
, _("C++ static virtual method"));
3061 mv
= debug_make_static_method_variant (dhandle
, mangledcopy
,
3067 debug_type vcontext
;
3070 vcontext
= DEBUG_TYPE_NULL
;
3073 /* FIXME: How can we calculate this correctly? */
3074 vcontext
= it
->type
;
3076 mv
= debug_make_method_variant (dhandle
, mangledcopy
, type
,
3081 if (mv
== DEBUG_METHOD_VARIANT_NULL
)
3084 for (meth
= methods
, im
= 0; im
< methods_count
; meth
++, im
++)
3085 if (meth
->namlen
== namlen
3086 && strncmp (meth
->name
, name
, namlen
) == 0)
3088 if (im
>= methods_count
)
3090 if (methods_count
>= methods_alloc
)
3092 methods_alloc
+= 10;
3093 methods
= ((struct ieee_method
*)
3095 methods_alloc
* sizeof *methods
));
3097 methods
[methods_count
].name
= name
;
3098 methods
[methods_count
].namlen
= namlen
;
3099 methods
[methods_count
].variants
= NULL
;
3100 methods
[methods_count
].count
= 0;
3101 methods
[methods_count
].alloc
= 0;
3102 meth
= methods
+ methods_count
;
3106 if (meth
->count
+ 1 >= meth
->alloc
)
3109 meth
->variants
= ((debug_method_variant
*)
3110 xrealloc (meth
->variants
,
3112 * sizeof *meth
->variants
)));
3115 meth
->variants
[meth
->count
] = mv
;
3117 meth
->variants
[meth
->count
] = DEBUG_METHOD_VARIANT_NULL
;
3125 /* We have no way to store this information, so we just
3127 if (! ieee_require_asn (info
, pp
, &spec
))
3130 if ((spec
& 4) != 0)
3132 const char *filename
;
3133 unsigned long filenamlen
;
3136 if (! ieee_require_atn65 (info
, pp
, &filename
, &filenamlen
)
3137 || ! ieee_require_asn (info
, pp
, &lineno
))
3141 else if ((spec
& 8) != 0)
3143 const char *mangled
;
3144 unsigned long mangledlen
;
3146 if (! ieee_require_atn65 (info
, pp
, &mangled
, &mangledlen
))
3152 ieee_error (info
, start
,
3153 _("unrecognized C++ object overhead spec"));
3161 const char *vname
, *basename
;
3162 unsigned long vnamelen
, baselen
;
3163 bfd_vma vsize
, control
;
3165 /* A virtual table pointer. */
3167 if (! ieee_require_atn65 (info
, pp
, &vname
, &vnamelen
)
3168 || ! ieee_require_asn (info
, pp
, &vsize
)
3169 || ! ieee_require_atn65 (info
, pp
, &basename
, &baselen
)
3170 || ! ieee_require_asn (info
, pp
, &control
))
3174 /* We just ignore the control number. We don't care what
3175 the virtual table name is. We have no way to store the
3176 virtual table size, and I don't think we care anyhow. */
3178 /* FIXME: We can't handle multiple virtual table pointers. */
3186 basecopy
= savestring (basename
, baselen
);
3187 vptrbase
= debug_find_tagged_type (dhandle
, basecopy
,
3188 DEBUG_KIND_ILLEGAL
);
3190 if (vptrbase
== DEBUG_TYPE_NULL
)
3192 ieee_error (info
, start
, _("undefined C++ vtable"));
3201 /* Now that we have seen all the method variants, we can call
3202 debug_make_method for each one. */
3204 if (methods_count
== 0)
3210 dmethods
= ((debug_method
*)
3211 xmalloc ((methods_count
+ 1) * sizeof *dmethods
));
3212 for (i
= 0; i
< methods_count
; i
++)
3216 namcopy
= savestring (methods
[i
].name
, methods
[i
].namlen
);
3217 dmethods
[i
] = debug_make_method (dhandle
, namcopy
,
3218 methods
[i
].variants
);
3219 if (dmethods
[i
] == DEBUG_METHOD_NULL
)
3222 dmethods
[i
] = DEBUG_METHOD_NULL
;
3226 /* The struct type was created as an indirect type pointing at
3227 it->slot. We update it->slot to automatically update all
3228 references to this struct. */
3229 it
->slot
= debug_make_object_type (dhandle
,
3231 debug_get_type_size (dhandle
,
3233 fields
, baseclasses
, dmethods
,
3235 if (it
->slot
== DEBUG_TYPE_NULL
)
3241 /* Read C++ default argument value and reference type information. */
3244 ieee_read_cxx_defaults (info
, pp
, count
)
3245 struct ieee_info
*info
;
3246 const bfd_byte
**pp
;
3247 unsigned long count
;
3249 const bfd_byte
*start
;
3251 unsigned long fnlen
;
3256 /* Giving the function name before the argument count is an addendum
3257 to the spec. The function name is demangled, though, so this
3258 record must always refer to the current function. */
3260 if (info
->blockstack
.bsp
<= info
->blockstack
.stack
3261 || info
->blockstack
.bsp
[-1].fnindx
== (unsigned int) -1)
3263 ieee_error (info
, start
, _("C++ default values not in a function"));
3267 if (! ieee_require_atn65 (info
, pp
, &fnname
, &fnlen
)
3268 || ! ieee_require_asn (info
, pp
, &defcount
))
3272 while (defcount
-- > 0)
3276 unsigned long strvallen
;
3278 if (! ieee_require_asn (info
, pp
, &type
))
3290 if (! ieee_require_asn (info
, pp
, &val
))
3297 if (! ieee_require_atn65 (info
, pp
, &strval
, &strvallen
))
3303 ieee_error (info
, start
, _("unrecognized C++ default type"));
3307 /* We have no way to record the default argument values, so we
3308 just ignore them. FIXME. */
3311 /* Any remaining arguments are indices of parameters that are really
3316 debug_type
*arg_slots
;
3318 dhandle
= info
->dhandle
;
3319 arg_slots
= info
->types
.types
[info
->blockstack
.bsp
[-1].fnindx
].arg_slots
;
3325 if (! ieee_require_asn (info
, pp
, &indx
))
3327 /* The index is 1 based. */
3329 if (arg_slots
== NULL
3330 || arg_slots
[indx
] == DEBUG_TYPE_NULL
3331 || (debug_get_type_kind (dhandle
, arg_slots
[indx
])
3332 != DEBUG_KIND_POINTER
))
3334 ieee_error (info
, start
, _("reference parameter is not a pointer"));
3338 target
= debug_get_target_type (dhandle
, arg_slots
[indx
]);
3339 arg_slots
[indx
] = debug_make_reference_type (dhandle
, target
);
3340 if (arg_slots
[indx
] == DEBUG_TYPE_NULL
)
3348 /* Read a C++ reference definition. */
3351 ieee_read_reference (info
, pp
)
3352 struct ieee_info
*info
;
3353 const bfd_byte
**pp
;
3355 const bfd_byte
*start
;
3357 const char *class, *name
;
3358 unsigned long classlen
, namlen
;
3364 if (! ieee_require_asn (info
, pp
, &flags
))
3367 /* Giving the class name before the member name is in an addendum to
3371 if (! ieee_require_atn65 (info
, pp
, &class, &classlen
))
3375 if (! ieee_require_atn65 (info
, pp
, &name
, &namlen
))
3383 /* We search from the last variable indices to the first in
3384 hopes of finding local variables correctly. We search the
3385 local variables on the first pass, and the global variables
3386 on the second. FIXME: This probably won't work in all cases.
3387 On the other hand, I don't know what will. */
3388 for (pass
= 0; pass
< 2; pass
++)
3390 struct ieee_vars
*vars
;
3392 struct ieee_var
*pv
= NULL
;
3398 vars
= info
->global_vars
;
3403 for (i
= (int) vars
->alloc
- 1; i
>= 0; i
--)
3407 pv
= vars
->vars
+ i
;
3409 if (pv
->pslot
== NULL
3410 || pv
->namlen
!= namlen
3411 || strncmp (pv
->name
, name
, namlen
) != 0)
3418 ieee_error (info
, start
,
3419 _("unrecognized C++ reference type"));
3423 /* Global variable or function. */
3424 if (pv
->kind
== IEEE_GLOBAL
3425 || pv
->kind
== IEEE_EXTERNAL
3426 || pv
->kind
== IEEE_FUNCTION
)
3431 /* Global static variable or function. */
3432 if (pv
->kind
== IEEE_STATIC
3433 || pv
->kind
== IEEE_FUNCTION
)
3438 /* Local variable. */
3439 if (pv
->kind
== IEEE_LOCAL
)
3457 struct ieee_tag
*it
;
3459 for (it
= info
->tags
; it
!= NULL
; it
= it
->next
)
3461 if (it
->name
[0] == class[0]
3462 && strncmp (it
->name
, class, classlen
) == 0
3463 && strlen (it
->name
) == classlen
)
3465 if (it
->fslots
!= NULL
)
3467 const debug_field
*pf
;
3470 pf
= debug_get_fields (info
->dhandle
, it
->type
);
3473 ieee_error (info
, start
,
3474 "C++ reference in class with no fields");
3478 for (findx
= 0; *pf
!= DEBUG_FIELD_NULL
; pf
++, findx
++)
3482 fname
= debug_get_field_name (info
->dhandle
, *pf
);
3485 if (strncmp (fname
, name
, namlen
) == 0
3486 && strlen (fname
) == namlen
)
3488 pslot
= it
->fslots
+ findx
;
3501 ieee_error (info
, start
, _("C++ reference not found"));
3505 /* We allocated the type of the object as an indirect type pointing
3506 to *pslot, which we can now update to be a reference type. */
3507 if (debug_get_type_kind (info
->dhandle
, *pslot
) != DEBUG_KIND_POINTER
)
3509 ieee_error (info
, start
, _("C++ reference is not pointer"));
3513 target
= debug_get_target_type (info
->dhandle
, *pslot
);
3514 *pslot
= debug_make_reference_type (info
->dhandle
, target
);
3515 if (*pslot
== DEBUG_TYPE_NULL
)
3521 /* Require an ASN record. */
3524 ieee_require_asn (info
, pp
, pv
)
3525 struct ieee_info
*info
;
3526 const bfd_byte
**pp
;
3529 const bfd_byte
*start
;
3530 ieee_record_enum_type c
;
3535 c
= (ieee_record_enum_type
) **pp
;
3536 if (c
!= ieee_e2_first_byte_enum
)
3538 ieee_error (info
, start
, _("missing required ASN"));
3543 c
= (ieee_record_enum_type
) (((unsigned int) c
<< 8) | **pp
);
3544 if (c
!= ieee_asn_record_enum
)
3546 ieee_error (info
, start
, _("missing required ASN"));
3551 /* Just ignore the variable index. */
3552 if (! ieee_read_number (info
, pp
, &varindx
))
3555 return ieee_read_expression (info
, pp
, pv
);
3558 /* Require an ATN65 record. */
3561 ieee_require_atn65 (info
, pp
, pname
, pnamlen
)
3562 struct ieee_info
*info
;
3563 const bfd_byte
**pp
;
3565 unsigned long *pnamlen
;
3567 const bfd_byte
*start
;
3568 ieee_record_enum_type c
;
3569 bfd_vma name_indx
, type_indx
, atn_code
;
3573 c
= (ieee_record_enum_type
) **pp
;
3574 if (c
!= ieee_at_record_enum
)
3576 ieee_error (info
, start
, _("missing required ATN65"));
3581 c
= (ieee_record_enum_type
) (((unsigned int) c
<< 8) | **pp
);
3582 if (c
!= ieee_atn_record_enum
)
3584 ieee_error (info
, start
, _("missing required ATN65"));
3589 if (! ieee_read_number (info
, pp
, &name_indx
)
3590 || ! ieee_read_number (info
, pp
, &type_indx
)
3591 || ! ieee_read_number (info
, pp
, &atn_code
))
3594 /* Just ignore name_indx. */
3596 if (type_indx
!= 0 || atn_code
!= 65)
3598 ieee_error (info
, start
, _("bad ATN65 record"));
3602 return ieee_read_id (info
, pp
, pname
, pnamlen
);
3605 /* Convert a register number in IEEE debugging information into a
3606 generic register number. */
3609 ieee_regno_to_genreg (abfd
, r
)
3613 switch (bfd_get_arch (abfd
))
3616 /* For some reasons stabs adds 2 to the floating point register
3623 /* Stabs uses 0 to 15 for r0 to r15, 16 to 31 for g0 to g15, and
3624 32 to 35 for fp0 to fp3. */
3635 /* Convert a generic register number to an IEEE specific one. */
3638 ieee_genreg_to_regno (abfd
, r
)
3642 switch (bfd_get_arch (abfd
))
3645 /* For some reason stabs add 2 to the floating point register
3652 /* Stabs uses 0 to 15 for r0 to r15, 16 to 31 for g0 to g15, and
3653 32 to 35 for fp0 to fp3. */
3664 /* These routines build IEEE debugging information out of the generic
3665 debugging information. */
3667 /* We build the IEEE debugging information byte by byte. Rather than
3668 waste time copying data around, we use a linked list of buffers to
3671 #define IEEE_BUFSIZE (490)
3676 struct ieee_buf
*next
;
3677 /* Number of data bytes in this buffer. */
3680 bfd_byte buf
[IEEE_BUFSIZE
];
3683 /* A list of buffers. */
3688 struct ieee_buf
*head
;
3689 /* Tail--last buffer on list. */
3690 struct ieee_buf
*tail
;
3693 /* In order to generate the BB11 blocks required by the HP emulator,
3694 we keep track of ranges of addresses which correspond to a given
3695 compilation unit. */
3700 struct ieee_range
*next
;
3707 /* This structure holds information for a class on the type stack. */
3709 struct ieee_type_class
3711 /* The name index in the debugging information. */
3713 /* The pmisc records for the class. */
3714 struct ieee_buflist pmiscbuf
;
3715 /* The number of pmisc records. */
3716 unsigned int pmisccount
;
3717 /* The name of the class holding the virtual table, if not this
3720 /* Whether this class holds its own virtual table. */
3721 bfd_boolean ownvptr
;
3722 /* The largest virtual table offset seen so far. */
3724 /* The current method. */
3726 /* Additional pmisc records used to record fields of reference type. */
3727 struct ieee_buflist refs
;
3730 /* This is how we store types for the writing routines. Most types
3731 are simply represented by a type index. */
3733 struct ieee_write_type
3737 /* The size of the type, if known. */
3739 /* The name of the type, if any. */
3741 /* If this is a function or method type, we build the type here, and
3742 only add it to the output buffers if we need it. */
3743 struct ieee_buflist fndef
;
3744 /* If this is a struct, this is where the struct definition is
3746 struct ieee_buflist strdef
;
3747 /* If this is a class, this is where the class information is built. */
3748 struct ieee_type_class
*classdef
;
3749 /* Whether the type is unsigned. */
3750 unsigned int unsignedp
: 1;
3751 /* Whether this is a reference type. */
3752 unsigned int referencep
: 1;
3753 /* Whether this is in the local type block. */
3754 unsigned int localp
: 1;
3755 /* Whether this is a duplicate struct definition which we are
3757 unsigned int ignorep
: 1;
3760 /* This is the type stack used by the debug writing routines. FIXME:
3761 We could generate more efficient output if we remembered when we
3762 have output a particular type before. */
3764 struct ieee_type_stack
3766 /* Next entry on stack. */
3767 struct ieee_type_stack
*next
;
3768 /* Type information. */
3769 struct ieee_write_type type
;
3772 /* This is a list of associations between a name and some types.
3773 These are used for typedefs and tags. */
3775 struct ieee_name_type
3777 /* Next type for this name. */
3778 struct ieee_name_type
*next
;
3779 /* ID number. For a typedef, this is the index of the type to which
3780 this name is typedefed. */
3783 struct ieee_write_type type
;
3784 /* If this is a tag which has not yet been defined, this is the
3785 kind. If the tag has been defined, this is DEBUG_KIND_ILLEGAL. */
3786 enum debug_type_kind kind
;
3789 /* We use a hash table to associate names and types. */
3791 struct ieee_name_type_hash_table
3793 struct bfd_hash_table root
;
3796 struct ieee_name_type_hash_entry
3798 struct bfd_hash_entry root
;
3799 /* Information for this name. */
3800 struct ieee_name_type
*types
;
3803 /* This is a list of enums. */
3805 struct ieee_defined_enum
3808 struct ieee_defined_enum
*next
;
3811 /* Whether this enum has been defined. */
3812 bfd_boolean defined
;
3818 bfd_signed_vma
*vals
;
3821 /* We keep a list of modified versions of types, so that we don't
3822 output them more than once. */
3824 struct ieee_modified_type
3826 /* Pointer to this type. */
3827 unsigned int pointer
;
3828 /* Function with unknown arguments returning this type. */
3829 unsigned int function
;
3830 /* Const version of this type. */
3831 unsigned int const_qualified
;
3832 /* Volatile version of this type. */
3833 unsigned int volatile_qualified
;
3834 /* List of arrays of this type of various bounds. */
3835 struct ieee_modified_array_type
*arrays
;
3838 /* A list of arrays bounds. */
3840 struct ieee_modified_array_type
3842 /* Next array bounds. */
3843 struct ieee_modified_array_type
*next
;
3844 /* Type index with these bounds. */
3849 bfd_signed_vma high
;
3852 /* This is a list of pending function parameter information. We don't
3853 output them until we see the first block. */
3855 struct ieee_pending_parm
3857 /* Next pending parameter. */
3858 struct ieee_pending_parm
*next
;
3863 /* Whether the type is a reference. */
3864 bfd_boolean referencep
;
3866 enum debug_parm_kind kind
;
3871 /* This is the handle passed down by debug_write. */
3875 /* BFD we are writing to. */
3877 /* Whether we got an error in a subroutine called via traverse or
3878 map_over_sections. */
3880 /* Current data buffer list. */
3881 struct ieee_buflist
*current
;
3882 /* Current data buffer. */
3883 struct ieee_buf
*curbuf
;
3884 /* Filename of current compilation unit. */
3885 const char *filename
;
3886 /* Module name of current compilation unit. */
3887 const char *modname
;
3888 /* List of buffer for global types. */
3889 struct ieee_buflist global_types
;
3890 /* List of finished data buffers. */
3891 struct ieee_buflist data
;
3892 /* List of buffers for typedefs in the current compilation unit. */
3893 struct ieee_buflist types
;
3894 /* List of buffers for variables and functions in the current
3895 compilation unit. */
3896 struct ieee_buflist vars
;
3897 /* List of buffers for C++ class definitions in the current
3898 compilation unit. */
3899 struct ieee_buflist cxx
;
3900 /* List of buffers for line numbers in the current compilation unit. */
3901 struct ieee_buflist linenos
;
3902 /* Ranges for the current compilation unit. */
3903 struct ieee_range
*ranges
;
3904 /* Ranges for all debugging information. */
3905 struct ieee_range
*global_ranges
;
3906 /* Nested pending ranges. */
3907 struct ieee_range
*pending_ranges
;
3909 struct ieee_type_stack
*type_stack
;
3910 /* Next unallocated type index. */
3911 unsigned int type_indx
;
3912 /* Next unallocated name index. */
3913 unsigned int name_indx
;
3915 struct ieee_name_type_hash_table typedefs
;
3917 struct ieee_name_type_hash_table tags
;
3919 struct ieee_defined_enum
*enums
;
3920 /* Modified versions of types. */
3921 struct ieee_modified_type
*modified
;
3922 /* Number of entries allocated in modified. */
3923 unsigned int modified_alloc
;
3924 /* 4 byte complex type. */
3925 unsigned int complex_float_index
;
3926 /* 8 byte complex type. */
3927 unsigned int complex_double_index
;
3928 /* The depth of block nesting. This is 0 outside a function, and 1
3929 just after start_function is called. */
3930 unsigned int block_depth
;
3931 /* The name of the current function. */
3933 /* List of buffers for the type of the function we are currently
3935 struct ieee_buflist fntype
;
3936 /* List of buffers for the parameters of the function we are
3937 currently writing out. */
3938 struct ieee_buflist fnargs
;
3939 /* Number of arguments written to fnargs. */
3940 unsigned int fnargcount
;
3941 /* Pending function parameters. */
3942 struct ieee_pending_parm
*pending_parms
;
3943 /* Current line number filename. */
3944 const char *lineno_filename
;
3945 /* Line number name index. */
3946 unsigned int lineno_name_indx
;
3947 /* Filename of pending line number. */
3948 const char *pending_lineno_filename
;
3949 /* Pending line number. */
3950 unsigned long pending_lineno
;
3951 /* Address of pending line number. */
3952 bfd_vma pending_lineno_addr
;
3953 /* Highest address seen at end of procedure. */
3957 static bfd_boolean ieee_init_buffer
3958 PARAMS ((struct ieee_handle
*, struct ieee_buflist
*));
3959 static bfd_boolean ieee_change_buffer
3960 PARAMS ((struct ieee_handle
*, struct ieee_buflist
*));
3961 static bfd_boolean ieee_append_buffer
3962 PARAMS ((struct ieee_handle
*, struct ieee_buflist
*,
3963 struct ieee_buflist
*));
3964 static bfd_boolean ieee_real_write_byte
3965 PARAMS ((struct ieee_handle
*, int));
3966 static bfd_boolean ieee_write_2bytes
3967 PARAMS ((struct ieee_handle
*, int));
3968 static bfd_boolean ieee_write_number
3969 PARAMS ((struct ieee_handle
*, bfd_vma
));
3970 static bfd_boolean ieee_write_id
3971 PARAMS ((struct ieee_handle
*, const char *));
3972 static bfd_boolean ieee_write_asn
3973 PARAMS ((struct ieee_handle
*, unsigned int, bfd_vma
));
3974 static bfd_boolean ieee_write_atn65
3975 PARAMS ((struct ieee_handle
*, unsigned int, const char *));
3976 static bfd_boolean ieee_push_type
3977 PARAMS ((struct ieee_handle
*, unsigned int, unsigned int, bfd_boolean
,
3979 static unsigned int ieee_pop_type
3980 PARAMS ((struct ieee_handle
*));
3981 static void ieee_pop_unused_type
3982 PARAMS ((struct ieee_handle
*));
3983 static unsigned int ieee_pop_type_used
3984 PARAMS ((struct ieee_handle
*, bfd_boolean
));
3985 static bfd_boolean ieee_add_range
3986 PARAMS ((struct ieee_handle
*, bfd_boolean
, bfd_vma
, bfd_vma
));
3987 static bfd_boolean ieee_start_range
3988 PARAMS ((struct ieee_handle
*, bfd_vma
));
3989 static bfd_boolean ieee_end_range
3990 PARAMS ((struct ieee_handle
*, bfd_vma
));
3991 static bfd_boolean ieee_define_type
3992 PARAMS ((struct ieee_handle
*, unsigned int, bfd_boolean
, bfd_boolean
));
3993 static bfd_boolean ieee_define_named_type
3994 PARAMS ((struct ieee_handle
*, const char *, unsigned int, unsigned int,
3995 bfd_boolean
, bfd_boolean
, struct ieee_buflist
*));
3996 static struct ieee_modified_type
*ieee_get_modified_info
3997 PARAMS ((struct ieee_handle
*, unsigned int));
3998 static struct bfd_hash_entry
*ieee_name_type_newfunc
3999 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
4000 static bfd_boolean ieee_write_undefined_tag
4001 PARAMS ((struct ieee_name_type_hash_entry
*, PTR
));
4002 static bfd_boolean ieee_finish_compilation_unit
4003 PARAMS ((struct ieee_handle
*));
4004 static void ieee_add_bb11_blocks
4005 PARAMS ((bfd
*, asection
*, PTR
));
4006 static bfd_boolean ieee_add_bb11
4007 PARAMS ((struct ieee_handle
*, asection
*, bfd_vma
, bfd_vma
));
4008 static bfd_boolean ieee_output_pending_parms
4009 PARAMS ((struct ieee_handle
*));
4010 static unsigned int ieee_vis_to_flags
4011 PARAMS ((enum debug_visibility
));
4012 static bfd_boolean ieee_class_method_var
4013 PARAMS ((struct ieee_handle
*, const char *, enum debug_visibility
, bfd_boolean
,
4014 bfd_boolean
, bfd_boolean
, bfd_vma
, bfd_boolean
));
4016 static bfd_boolean ieee_start_compilation_unit
4017 PARAMS ((PTR
, const char *));
4018 static bfd_boolean ieee_start_source
4019 PARAMS ((PTR
, const char *));
4020 static bfd_boolean ieee_empty_type
4022 static bfd_boolean ieee_void_type
4024 static bfd_boolean ieee_int_type
4025 PARAMS ((PTR
, unsigned int, bfd_boolean
));
4026 static bfd_boolean ieee_float_type
4027 PARAMS ((PTR
, unsigned int));
4028 static bfd_boolean ieee_complex_type
4029 PARAMS ((PTR
, unsigned int));
4030 static bfd_boolean ieee_bool_type
4031 PARAMS ((PTR
, unsigned int));
4032 static bfd_boolean ieee_enum_type
4033 PARAMS ((PTR
, const char *, const char **, bfd_signed_vma
*));
4034 static bfd_boolean ieee_pointer_type
4036 static bfd_boolean ieee_function_type
4037 PARAMS ((PTR
, int, bfd_boolean
));
4038 static bfd_boolean ieee_reference_type
4040 static bfd_boolean ieee_range_type
4041 PARAMS ((PTR
, bfd_signed_vma
, bfd_signed_vma
));
4042 static bfd_boolean ieee_array_type
4043 PARAMS ((PTR
, bfd_signed_vma
, bfd_signed_vma
, bfd_boolean
));
4044 static bfd_boolean ieee_set_type
4045 PARAMS ((PTR
, bfd_boolean
));
4046 static bfd_boolean ieee_offset_type
4048 static bfd_boolean ieee_method_type
4049 PARAMS ((PTR
, bfd_boolean
, int, bfd_boolean
));
4050 static bfd_boolean ieee_const_type
4052 static bfd_boolean ieee_volatile_type
4054 static bfd_boolean ieee_start_struct_type
4055 PARAMS ((PTR
, const char *, unsigned int, bfd_boolean
, unsigned int));
4056 static bfd_boolean ieee_struct_field
4057 PARAMS ((PTR
, const char *, bfd_vma
, bfd_vma
, enum debug_visibility
));
4058 static bfd_boolean ieee_end_struct_type
4060 static bfd_boolean ieee_start_class_type
4061 PARAMS ((PTR
, const char *, unsigned int, bfd_boolean
, unsigned int, bfd_boolean
,
4063 static bfd_boolean ieee_class_static_member
4064 PARAMS ((PTR
, const char *, const char *, enum debug_visibility
));
4065 static bfd_boolean ieee_class_baseclass
4066 PARAMS ((PTR
, bfd_vma
, bfd_boolean
, enum debug_visibility
));
4067 static bfd_boolean ieee_class_start_method
4068 PARAMS ((PTR
, const char *));
4069 static bfd_boolean ieee_class_method_variant
4070 PARAMS ((PTR
, const char *, enum debug_visibility
, bfd_boolean
, bfd_boolean
,
4071 bfd_vma
, bfd_boolean
));
4072 static bfd_boolean ieee_class_static_method_variant
4073 PARAMS ((PTR
, const char *, enum debug_visibility
, bfd_boolean
, bfd_boolean
));
4074 static bfd_boolean ieee_class_end_method
4076 static bfd_boolean ieee_end_class_type
4078 static bfd_boolean ieee_typedef_type
4079 PARAMS ((PTR
, const char *));
4080 static bfd_boolean ieee_tag_type
4081 PARAMS ((PTR
, const char *, unsigned int, enum debug_type_kind
));
4082 static bfd_boolean ieee_typdef
4083 PARAMS ((PTR
, const char *));
4084 static bfd_boolean ieee_tag
4085 PARAMS ((PTR
, const char *));
4086 static bfd_boolean ieee_int_constant
4087 PARAMS ((PTR
, const char *, bfd_vma
));
4088 static bfd_boolean ieee_float_constant
4089 PARAMS ((PTR
, const char *, double));
4090 static bfd_boolean ieee_typed_constant
4091 PARAMS ((PTR
, const char *, bfd_vma
));
4092 static bfd_boolean ieee_variable
4093 PARAMS ((PTR
, const char *, enum debug_var_kind
, bfd_vma
));
4094 static bfd_boolean ieee_start_function
4095 PARAMS ((PTR
, const char *, bfd_boolean
));
4096 static bfd_boolean ieee_function_parameter
4097 PARAMS ((PTR
, const char *, enum debug_parm_kind
, bfd_vma
));
4098 static bfd_boolean ieee_start_block
4099 PARAMS ((PTR
, bfd_vma
));
4100 static bfd_boolean ieee_end_block
4101 PARAMS ((PTR
, bfd_vma
));
4102 static bfd_boolean ieee_end_function
4104 static bfd_boolean ieee_lineno
4105 PARAMS ((PTR
, const char *, unsigned long, bfd_vma
));
4107 static const struct debug_write_fns ieee_fns
=
4109 ieee_start_compilation_unit
,
4120 ieee_reference_type
,
4128 ieee_start_struct_type
,
4130 ieee_end_struct_type
,
4131 ieee_start_class_type
,
4132 ieee_class_static_member
,
4133 ieee_class_baseclass
,
4134 ieee_class_start_method
,
4135 ieee_class_method_variant
,
4136 ieee_class_static_method_variant
,
4137 ieee_class_end_method
,
4138 ieee_end_class_type
,
4144 ieee_float_constant
,
4145 ieee_typed_constant
,
4147 ieee_start_function
,
4148 ieee_function_parameter
,
4155 /* Initialize a buffer to be empty. */
4158 ieee_init_buffer (info
, buflist
)
4159 struct ieee_handle
*info ATTRIBUTE_UNUSED
;
4160 struct ieee_buflist
*buflist
;
4162 buflist
->head
= NULL
;
4163 buflist
->tail
= NULL
;
4167 /* See whether a buffer list has any data. */
4169 #define ieee_buffer_emptyp(buflist) ((buflist)->head == NULL)
4171 /* Change the current buffer to a specified buffer chain. */
4174 ieee_change_buffer (info
, buflist
)
4175 struct ieee_handle
*info
;
4176 struct ieee_buflist
*buflist
;
4178 if (buflist
->head
== NULL
)
4180 struct ieee_buf
*buf
;
4182 buf
= (struct ieee_buf
*) xmalloc (sizeof *buf
);
4185 buflist
->head
= buf
;
4186 buflist
->tail
= buf
;
4189 info
->current
= buflist
;
4190 info
->curbuf
= buflist
->tail
;
4195 /* Append a buffer chain. */
4198 ieee_append_buffer (info
, mainbuf
, newbuf
)
4199 struct ieee_handle
*info ATTRIBUTE_UNUSED
;
4200 struct ieee_buflist
*mainbuf
;
4201 struct ieee_buflist
*newbuf
;
4203 if (newbuf
->head
!= NULL
)
4205 if (mainbuf
->head
== NULL
)
4206 mainbuf
->head
= newbuf
->head
;
4208 mainbuf
->tail
->next
= newbuf
->head
;
4209 mainbuf
->tail
= newbuf
->tail
;
4214 /* Write a byte into the buffer. We use a macro for speed and a
4215 function for the complex cases. */
4217 #define ieee_write_byte(info, b) \
4218 ((info)->curbuf->c < IEEE_BUFSIZE \
4219 ? ((info)->curbuf->buf[(info)->curbuf->c++] = (b), TRUE) \
4220 : ieee_real_write_byte ((info), (b)))
4223 ieee_real_write_byte (info
, b
)
4224 struct ieee_handle
*info
;
4227 if (info
->curbuf
->c
>= IEEE_BUFSIZE
)
4231 n
= (struct ieee_buf
*) xmalloc (sizeof *n
);
4234 if (info
->current
->head
== NULL
)
4235 info
->current
->head
= n
;
4237 info
->current
->tail
->next
= n
;
4238 info
->current
->tail
= n
;
4242 info
->curbuf
->buf
[info
->curbuf
->c
] = b
;
4248 /* Write out two bytes. */
4251 ieee_write_2bytes (info
, i
)
4252 struct ieee_handle
*info
;
4255 return (ieee_write_byte (info
, i
>> 8)
4256 && ieee_write_byte (info
, i
& 0xff));
4259 /* Write out an integer. */
4262 ieee_write_number (info
, v
)
4263 struct ieee_handle
*info
;
4271 if (v
<= (bfd_vma
) ieee_number_end_enum
)
4272 return ieee_write_byte (info
, (int) v
);
4283 if (c
> (unsigned int) (ieee_number_repeat_end_enum
4284 - ieee_number_repeat_start_enum
))
4286 fprintf (stderr
, _("IEEE numeric overflow: 0x"));
4287 fprintf_vma (stderr
, v
);
4288 fprintf (stderr
, "\n");
4292 if (! ieee_write_byte (info
, (int) ieee_number_repeat_start_enum
+ c
))
4294 for (; c
> 0; --c
, ++p
)
4296 if (! ieee_write_byte (info
, *p
))
4303 /* Write out a string. */
4306 ieee_write_id (info
, s
)
4307 struct ieee_handle
*info
;
4315 if (! ieee_write_byte (info
, len
))
4318 else if (len
<= 0xff)
4320 if (! ieee_write_byte (info
, (int) ieee_extension_length_1_enum
)
4321 || ! ieee_write_byte (info
, len
))
4324 else if (len
<= 0xffff)
4326 if (! ieee_write_byte (info
, (int) ieee_extension_length_2_enum
)
4327 || ! ieee_write_2bytes (info
, len
))
4332 fprintf (stderr
, _("IEEE string length overflow: %u\n"), len
);
4336 for (; *s
!= '\0'; s
++)
4337 if (! ieee_write_byte (info
, *s
))
4343 /* Write out an ASN record. */
4346 ieee_write_asn (info
, indx
, val
)
4347 struct ieee_handle
*info
;
4351 return (ieee_write_2bytes (info
, (int) ieee_asn_record_enum
)
4352 && ieee_write_number (info
, indx
)
4353 && ieee_write_number (info
, val
));
4356 /* Write out an ATN65 record. */
4359 ieee_write_atn65 (info
, indx
, s
)
4360 struct ieee_handle
*info
;
4364 return (ieee_write_2bytes (info
, (int) ieee_atn_record_enum
)
4365 && ieee_write_number (info
, indx
)
4366 && ieee_write_number (info
, 0)
4367 && ieee_write_number (info
, 65)
4368 && ieee_write_id (info
, s
));
4371 /* Push a type index onto the type stack. */
4374 ieee_push_type (info
, indx
, size
, unsignedp
, localp
)
4375 struct ieee_handle
*info
;
4378 bfd_boolean unsignedp
;
4381 struct ieee_type_stack
*ts
;
4383 ts
= (struct ieee_type_stack
*) xmalloc (sizeof *ts
);
4384 memset (ts
, 0, sizeof *ts
);
4386 ts
->type
.indx
= indx
;
4387 ts
->type
.size
= size
;
4388 ts
->type
.unsignedp
= unsignedp
;
4389 ts
->type
.localp
= localp
;
4391 ts
->next
= info
->type_stack
;
4392 info
->type_stack
= ts
;
4397 /* Pop a type index off the type stack. */
4400 ieee_pop_type (info
)
4401 struct ieee_handle
*info
;
4403 return ieee_pop_type_used (info
, TRUE
);
4406 /* Pop an unused type index off the type stack. */
4409 ieee_pop_unused_type (info
)
4410 struct ieee_handle
*info
;
4412 (void) ieee_pop_type_used (info
, FALSE
);
4415 /* Pop a used or unused type index off the type stack. */
4418 ieee_pop_type_used (info
, used
)
4419 struct ieee_handle
*info
;
4422 struct ieee_type_stack
*ts
;
4425 ts
= info
->type_stack
;
4426 assert (ts
!= NULL
);
4428 /* If this is a function type, and we need it, we need to append the
4429 actual definition to the typedef block now. */
4430 if (used
&& ! ieee_buffer_emptyp (&ts
->type
.fndef
))
4432 struct ieee_buflist
*buflist
;
4434 if (ts
->type
.localp
)
4436 /* Make sure we have started the types block. */
4437 if (ieee_buffer_emptyp (&info
->types
))
4439 if (! ieee_change_buffer (info
, &info
->types
)
4440 || ! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
4441 || ! ieee_write_byte (info
, 1)
4442 || ! ieee_write_number (info
, 0)
4443 || ! ieee_write_id (info
, info
->modname
))
4446 buflist
= &info
->types
;
4450 /* Make sure we started the global type block. */
4451 if (ieee_buffer_emptyp (&info
->global_types
))
4453 if (! ieee_change_buffer (info
, &info
->global_types
)
4454 || ! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
4455 || ! ieee_write_byte (info
, 2)
4456 || ! ieee_write_number (info
, 0)
4457 || ! ieee_write_id (info
, ""))
4460 buflist
= &info
->global_types
;
4463 if (! ieee_append_buffer (info
, buflist
, &ts
->type
.fndef
))
4467 ret
= ts
->type
.indx
;
4468 info
->type_stack
= ts
->next
;
4473 /* Add a range of bytes included in the current compilation unit. */
4476 ieee_add_range (info
, global
, low
, high
)
4477 struct ieee_handle
*info
;
4482 struct ieee_range
**plist
, *r
, **pr
;
4484 if (low
== (bfd_vma
) -1 || high
== (bfd_vma
) -1 || low
== high
)
4488 plist
= &info
->global_ranges
;
4490 plist
= &info
->ranges
;
4492 for (r
= *plist
; r
!= NULL
; r
= r
->next
)
4494 if (high
>= r
->low
&& low
<= r
->high
)
4496 /* The new range overlaps r. */
4502 while (*pr
!= NULL
&& (*pr
)->low
<= r
->high
)
4504 struct ieee_range
*n
;
4506 if ((*pr
)->high
> r
->high
)
4507 r
->high
= (*pr
)->high
;
4516 r
= (struct ieee_range
*) xmalloc (sizeof *r
);
4517 memset (r
, 0, sizeof *r
);
4522 /* Store the ranges sorted by address. */
4523 for (pr
= plist
; *pr
!= NULL
; pr
= &(*pr
)->next
)
4524 if ((*pr
)->low
> high
)
4532 /* Start a new range for which we only have the low address. */
4535 ieee_start_range (info
, low
)
4536 struct ieee_handle
*info
;
4539 struct ieee_range
*r
;
4541 r
= (struct ieee_range
*) xmalloc (sizeof *r
);
4542 memset (r
, 0, sizeof *r
);
4544 r
->next
= info
->pending_ranges
;
4545 info
->pending_ranges
= r
;
4549 /* Finish a range started by ieee_start_range. */
4552 ieee_end_range (info
, high
)
4553 struct ieee_handle
*info
;
4556 struct ieee_range
*r
;
4559 assert (info
->pending_ranges
!= NULL
);
4560 r
= info
->pending_ranges
;
4562 info
->pending_ranges
= r
->next
;
4564 return ieee_add_range (info
, FALSE
, low
, high
);
4567 /* Start defining a type. */
4570 ieee_define_type (info
, size
, unsignedp
, localp
)
4571 struct ieee_handle
*info
;
4573 bfd_boolean unsignedp
;
4576 return ieee_define_named_type (info
, (const char *) NULL
,
4577 (unsigned int) -1, size
, unsignedp
,
4578 localp
, (struct ieee_buflist
*) NULL
);
4581 /* Start defining a named type. */
4584 ieee_define_named_type (info
, name
, indx
, size
, unsignedp
, localp
, buflist
)
4585 struct ieee_handle
*info
;
4589 bfd_boolean unsignedp
;
4591 struct ieee_buflist
*buflist
;
4593 unsigned int type_indx
;
4594 unsigned int name_indx
;
4596 if (indx
!= (unsigned int) -1)
4600 type_indx
= info
->type_indx
;
4604 name_indx
= info
->name_indx
;
4610 /* If we were given a buffer, use it; otherwise, use either the
4611 local or the global type information, and make sure that the type
4612 block is started. */
4613 if (buflist
!= NULL
)
4615 if (! ieee_change_buffer (info
, buflist
))
4620 if (! ieee_buffer_emptyp (&info
->types
))
4622 if (! ieee_change_buffer (info
, &info
->types
))
4627 if (! ieee_change_buffer (info
, &info
->types
)
4628 || ! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
4629 || ! ieee_write_byte (info
, 1)
4630 || ! ieee_write_number (info
, 0)
4631 || ! ieee_write_id (info
, info
->modname
))
4637 if (! ieee_buffer_emptyp (&info
->global_types
))
4639 if (! ieee_change_buffer (info
, &info
->global_types
))
4644 if (! ieee_change_buffer (info
, &info
->global_types
)
4645 || ! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
4646 || ! ieee_write_byte (info
, 2)
4647 || ! ieee_write_number (info
, 0)
4648 || ! ieee_write_id (info
, ""))
4653 /* Push the new type on the type stack, write out an NN record, and
4654 write out the start of a TY record. The caller will then finish
4656 if (! ieee_push_type (info
, type_indx
, size
, unsignedp
, localp
))
4659 return (ieee_write_byte (info
, (int) ieee_nn_record
)
4660 && ieee_write_number (info
, name_indx
)
4661 && ieee_write_id (info
, name
)
4662 && ieee_write_byte (info
, (int) ieee_ty_record_enum
)
4663 && ieee_write_number (info
, type_indx
)
4664 && ieee_write_byte (info
, 0xce)
4665 && ieee_write_number (info
, name_indx
));
4668 /* Get an entry to the list of modified versions of a type. */
4670 static struct ieee_modified_type
*
4671 ieee_get_modified_info (info
, indx
)
4672 struct ieee_handle
*info
;
4675 if (indx
>= info
->modified_alloc
)
4677 unsigned int nalloc
;
4679 nalloc
= info
->modified_alloc
;
4682 while (indx
>= nalloc
)
4684 info
->modified
= ((struct ieee_modified_type
*)
4685 xrealloc (info
->modified
,
4686 nalloc
* sizeof *info
->modified
));
4687 memset (info
->modified
+ info
->modified_alloc
, 0,
4688 (nalloc
- info
->modified_alloc
) * sizeof *info
->modified
);
4689 info
->modified_alloc
= nalloc
;
4692 return info
->modified
+ indx
;
4695 /* Routines for the hash table mapping names to types. */
4697 /* Initialize an entry in the hash table. */
4699 static struct bfd_hash_entry
*
4700 ieee_name_type_newfunc (entry
, table
, string
)
4701 struct bfd_hash_entry
*entry
;
4702 struct bfd_hash_table
*table
;
4705 struct ieee_name_type_hash_entry
*ret
=
4706 (struct ieee_name_type_hash_entry
*) entry
;
4708 /* Allocate the structure if it has not already been allocated by a
4711 ret
= ((struct ieee_name_type_hash_entry
*)
4712 bfd_hash_allocate (table
, sizeof *ret
));
4716 /* Call the allocation method of the superclass. */
4717 ret
= ((struct ieee_name_type_hash_entry
*)
4718 bfd_hash_newfunc ((struct bfd_hash_entry
*) ret
, table
, string
));
4721 /* Set local fields. */
4725 return (struct bfd_hash_entry
*) ret
;
4728 /* Look up an entry in the hash table. */
4730 #define ieee_name_type_hash_lookup(table, string, create, copy) \
4731 ((struct ieee_name_type_hash_entry *) \
4732 bfd_hash_lookup (&(table)->root, (string), (create), (copy)))
4734 /* Traverse the hash table. */
4736 #define ieee_name_type_hash_traverse(table, func, info) \
4737 (bfd_hash_traverse \
4739 (bfd_boolean (*) PARAMS ((struct bfd_hash_entry *, PTR))) (func), \
4742 /* The general routine to write out IEEE debugging information. */
4745 write_ieee_debugging_info (abfd
, dhandle
)
4749 struct ieee_handle info
;
4754 memset (&info
, 0, sizeof info
);
4756 info
.type_indx
= 256;
4757 info
.name_indx
= 32;
4759 if (! bfd_hash_table_init (&info
.typedefs
.root
, ieee_name_type_newfunc
)
4760 || ! bfd_hash_table_init (&info
.tags
.root
, ieee_name_type_newfunc
))
4763 if (! ieee_init_buffer (&info
, &info
.global_types
)
4764 || ! ieee_init_buffer (&info
, &info
.data
)
4765 || ! ieee_init_buffer (&info
, &info
.types
)
4766 || ! ieee_init_buffer (&info
, &info
.vars
)
4767 || ! ieee_init_buffer (&info
, &info
.cxx
)
4768 || ! ieee_init_buffer (&info
, &info
.linenos
)
4769 || ! ieee_init_buffer (&info
, &info
.fntype
)
4770 || ! ieee_init_buffer (&info
, &info
.fnargs
))
4773 if (! debug_write (dhandle
, &ieee_fns
, (PTR
) &info
))
4776 if (info
.filename
!= NULL
)
4778 if (! ieee_finish_compilation_unit (&info
))
4782 /* Put any undefined tags in the global typedef information. */
4784 ieee_name_type_hash_traverse (&info
.tags
,
4785 ieee_write_undefined_tag
,
4790 /* Prepend the global typedef information to the other data. */
4791 if (! ieee_buffer_emptyp (&info
.global_types
))
4793 /* The HP debugger seems to have a bug in which it ignores the
4794 last entry in the global types, so we add a dummy entry. */
4795 if (! ieee_change_buffer (&info
, &info
.global_types
)
4796 || ! ieee_write_byte (&info
, (int) ieee_nn_record
)
4797 || ! ieee_write_number (&info
, info
.name_indx
)
4798 || ! ieee_write_id (&info
, "")
4799 || ! ieee_write_byte (&info
, (int) ieee_ty_record_enum
)
4800 || ! ieee_write_number (&info
, info
.type_indx
)
4801 || ! ieee_write_byte (&info
, 0xce)
4802 || ! ieee_write_number (&info
, info
.name_indx
)
4803 || ! ieee_write_number (&info
, 'P')
4804 || ! ieee_write_number (&info
, (int) builtin_void
+ 32)
4805 || ! ieee_write_byte (&info
, (int) ieee_be_record_enum
))
4808 if (! ieee_append_buffer (&info
, &info
.global_types
, &info
.data
))
4810 info
.data
= info
.global_types
;
4813 /* Make sure that we have declare BB11 blocks for each range in the
4814 file. They are added to info->vars. */
4816 if (! ieee_init_buffer (&info
, &info
.vars
))
4818 bfd_map_over_sections (abfd
, ieee_add_bb11_blocks
, (PTR
) &info
);
4821 if (! ieee_buffer_emptyp (&info
.vars
))
4823 if (! ieee_change_buffer (&info
, &info
.vars
)
4824 || ! ieee_write_byte (&info
, (int) ieee_be_record_enum
))
4827 if (! ieee_append_buffer (&info
, &info
.data
, &info
.vars
))
4831 /* Now all the data is in info.data. Write it out to the BFD. We
4832 normally would need to worry about whether all the other sections
4833 are set up yet, but the IEEE backend will handle this particular
4834 case correctly regardless. */
4835 if (ieee_buffer_emptyp (&info
.data
))
4837 /* There is no debugging information. */
4841 s
= bfd_make_section (abfd
, ".debug");
4843 err
= "bfd_make_section";
4846 if (! bfd_set_section_flags (abfd
, s
, SEC_DEBUGGING
| SEC_HAS_CONTENTS
))
4847 err
= "bfd_set_section_flags";
4854 for (b
= info
.data
.head
; b
!= NULL
; b
= b
->next
)
4856 if (! bfd_set_section_size (abfd
, s
, size
))
4857 err
= "bfd_set_section_size";
4864 for (b
= info
.data
.head
; b
!= NULL
; b
= b
->next
)
4866 if (! bfd_set_section_contents (abfd
, s
, b
->buf
, offset
, b
->c
))
4868 err
= "bfd_set_section_contents";
4877 fprintf (stderr
, "%s: %s: %s\n", bfd_get_filename (abfd
), err
,
4878 bfd_errmsg (bfd_get_error ()));
4882 bfd_hash_table_free (&info
.typedefs
.root
);
4883 bfd_hash_table_free (&info
.tags
.root
);
4888 /* Write out information for an undefined tag. This is called via
4889 ieee_name_type_hash_traverse. */
4892 ieee_write_undefined_tag (h
, p
)
4893 struct ieee_name_type_hash_entry
*h
;
4896 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
4897 struct ieee_name_type
*nt
;
4899 for (nt
= h
->types
; nt
!= NULL
; nt
= nt
->next
)
4901 unsigned int name_indx
;
4904 if (nt
->kind
== DEBUG_KIND_ILLEGAL
)
4907 if (ieee_buffer_emptyp (&info
->global_types
))
4909 if (! ieee_change_buffer (info
, &info
->global_types
)
4910 || ! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
4911 || ! ieee_write_byte (info
, 2)
4912 || ! ieee_write_number (info
, 0)
4913 || ! ieee_write_id (info
, ""))
4921 if (! ieee_change_buffer (info
, &info
->global_types
))
4928 name_indx
= info
->name_indx
;
4930 if (! ieee_write_byte (info
, (int) ieee_nn_record
)
4931 || ! ieee_write_number (info
, name_indx
)
4932 || ! ieee_write_id (info
, nt
->type
.name
)
4933 || ! ieee_write_byte (info
, (int) ieee_ty_record_enum
)
4934 || ! ieee_write_number (info
, nt
->type
.indx
)
4935 || ! ieee_write_byte (info
, 0xce)
4936 || ! ieee_write_number (info
, name_indx
))
4948 case DEBUG_KIND_STRUCT
:
4949 case DEBUG_KIND_CLASS
:
4952 case DEBUG_KIND_UNION
:
4953 case DEBUG_KIND_UNION_CLASS
:
4956 case DEBUG_KIND_ENUM
:
4960 if (! ieee_write_number (info
, code
)
4961 || ! ieee_write_number (info
, 0))
4971 /* Start writing out information for a compilation unit. */
4974 ieee_start_compilation_unit (p
, filename
)
4976 const char *filename
;
4978 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
4979 const char *modname
;
4980 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
4981 const char *backslash
;
4986 if (info
->filename
!= NULL
)
4988 if (! ieee_finish_compilation_unit (info
))
4992 info
->filename
= filename
;
4993 modname
= strrchr (filename
, '/');
4994 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
4995 /* We could have a mixed forward/back slash case. */
4996 backslash
= strrchr (filename
, '\\');
4997 if (modname
== NULL
|| (backslash
!= NULL
&& backslash
> modname
))
4998 modname
= backslash
;
5001 if (modname
!= NULL
)
5003 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
5004 else if (filename
[0] && filename
[1] == ':')
5005 modname
= filename
+ 2;
5010 c
= xstrdup (modname
);
5011 s
= strrchr (c
, '.');
5016 if (! ieee_init_buffer (info
, &info
->types
)
5017 || ! ieee_init_buffer (info
, &info
->vars
)
5018 || ! ieee_init_buffer (info
, &info
->cxx
)
5019 || ! ieee_init_buffer (info
, &info
->linenos
))
5021 info
->ranges
= NULL
;
5023 /* Always include a BB1 and a BB3 block. That is what the output of
5024 the MRI linker seems to look like. */
5025 if (! ieee_change_buffer (info
, &info
->types
)
5026 || ! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
5027 || ! ieee_write_byte (info
, 1)
5028 || ! ieee_write_number (info
, 0)
5029 || ! ieee_write_id (info
, info
->modname
))
5032 nindx
= info
->name_indx
;
5034 if (! ieee_change_buffer (info
, &info
->vars
)
5035 || ! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
5036 || ! ieee_write_byte (info
, 3)
5037 || ! ieee_write_number (info
, 0)
5038 || ! ieee_write_id (info
, info
->modname
))
5044 /* Finish up a compilation unit. */
5047 ieee_finish_compilation_unit (info
)
5048 struct ieee_handle
*info
;
5050 struct ieee_range
*r
;
5052 if (! ieee_buffer_emptyp (&info
->types
))
5054 if (! ieee_change_buffer (info
, &info
->types
)
5055 || ! ieee_write_byte (info
, (int) ieee_be_record_enum
))
5059 if (! ieee_buffer_emptyp (&info
->cxx
))
5061 /* Append any C++ information to the global function and
5062 variable information. */
5063 assert (! ieee_buffer_emptyp (&info
->vars
));
5064 if (! ieee_change_buffer (info
, &info
->vars
))
5067 /* We put the pmisc records in a dummy procedure, just as the
5068 MRI compiler does. */
5069 if (! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
5070 || ! ieee_write_byte (info
, 6)
5071 || ! ieee_write_number (info
, 0)
5072 || ! ieee_write_id (info
, "__XRYCPP")
5073 || ! ieee_write_number (info
, 0)
5074 || ! ieee_write_number (info
, 0)
5075 || ! ieee_write_number (info
, info
->highaddr
- 1)
5076 || ! ieee_append_buffer (info
, &info
->vars
, &info
->cxx
)
5077 || ! ieee_change_buffer (info
, &info
->vars
)
5078 || ! ieee_write_byte (info
, (int) ieee_be_record_enum
)
5079 || ! ieee_write_number (info
, info
->highaddr
- 1))
5083 if (! ieee_buffer_emptyp (&info
->vars
))
5085 if (! ieee_change_buffer (info
, &info
->vars
)
5086 || ! ieee_write_byte (info
, (int) ieee_be_record_enum
))
5090 if (info
->pending_lineno_filename
!= NULL
)
5092 /* Force out the pending line number. */
5093 if (! ieee_lineno ((PTR
) info
, (const char *) NULL
, 0, (bfd_vma
) -1))
5096 if (! ieee_buffer_emptyp (&info
->linenos
))
5098 if (! ieee_change_buffer (info
, &info
->linenos
)
5099 || ! ieee_write_byte (info
, (int) ieee_be_record_enum
))
5101 if (strcmp (info
->filename
, info
->lineno_filename
) != 0)
5103 /* We were not in the main file. We just closed the
5104 included line number block, and now we must close the
5105 main line number block. */
5106 if (! ieee_write_byte (info
, (int) ieee_be_record_enum
))
5111 if (! ieee_append_buffer (info
, &info
->data
, &info
->types
)
5112 || ! ieee_append_buffer (info
, &info
->data
, &info
->vars
)
5113 || ! ieee_append_buffer (info
, &info
->data
, &info
->linenos
))
5116 /* Build BB10/BB11 blocks based on the ranges we recorded. */
5117 if (! ieee_change_buffer (info
, &info
->data
))
5120 if (! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
5121 || ! ieee_write_byte (info
, 10)
5122 || ! ieee_write_number (info
, 0)
5123 || ! ieee_write_id (info
, info
->modname
)
5124 || ! ieee_write_id (info
, "")
5125 || ! ieee_write_number (info
, 0)
5126 || ! ieee_write_id (info
, "GNU objcopy"))
5129 for (r
= info
->ranges
; r
!= NULL
; r
= r
->next
)
5138 /* Find the section corresponding to this range. */
5139 for (s
= info
->abfd
->sections
; s
!= NULL
; s
= s
->next
)
5141 if (bfd_get_section_vma (info
->abfd
, s
) <= low
5142 && high
<= (bfd_get_section_vma (info
->abfd
, s
)
5143 + bfd_section_size (info
->abfd
, s
)))
5149 /* Just ignore this range. */
5153 /* Coalesce ranges if it seems reasonable. */
5154 while (r
->next
!= NULL
5155 && high
+ 0x1000 >= r
->next
->low
5157 <= (bfd_get_section_vma (info
->abfd
, s
)
5158 + bfd_section_size (info
->abfd
, s
))))
5164 if ((s
->flags
& SEC_CODE
) != 0)
5166 else if ((s
->flags
& SEC_READONLY
) != 0)
5171 if (! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
5172 || ! ieee_write_byte (info
, 11)
5173 || ! ieee_write_number (info
, 0)
5174 || ! ieee_write_id (info
, "")
5175 || ! ieee_write_number (info
, kind
)
5176 || ! ieee_write_number (info
, s
->index
+ IEEE_SECTION_NUMBER_BASE
)
5177 || ! ieee_write_number (info
, low
)
5178 || ! ieee_write_byte (info
, (int) ieee_be_record_enum
)
5179 || ! ieee_write_number (info
, high
- low
))
5182 /* Add this range to the list of global ranges. */
5183 if (! ieee_add_range (info
, TRUE
, low
, high
))
5187 if (! ieee_write_byte (info
, (int) ieee_be_record_enum
))
5193 /* Add BB11 blocks describing each range that we have not already
5197 ieee_add_bb11_blocks (abfd
, sec
, data
)
5198 bfd
*abfd ATTRIBUTE_UNUSED
;
5202 struct ieee_handle
*info
= (struct ieee_handle
*) data
;
5204 struct ieee_range
*r
;
5206 low
= bfd_get_section_vma (abfd
, sec
);
5207 high
= low
+ bfd_section_size (abfd
, sec
);
5209 /* Find the first range at or after this section. The ranges are
5210 sorted by address. */
5211 for (r
= info
->global_ranges
; r
!= NULL
; r
= r
->next
)
5217 if (r
== NULL
|| r
->low
>= high
)
5219 if (! ieee_add_bb11 (info
, sec
, low
, high
))
5225 && r
->low
- low
> 0x100)
5227 if (! ieee_add_bb11 (info
, sec
, low
, r
->low
))
5239 /* Add a single BB11 block for a range. We add it to info->vars. */
5242 ieee_add_bb11 (info
, sec
, low
, high
)
5243 struct ieee_handle
*info
;
5250 if (! ieee_buffer_emptyp (&info
->vars
))
5252 if (! ieee_change_buffer (info
, &info
->vars
))
5257 const char *filename
, *modname
;
5258 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
5259 const char *backslash
;
5263 /* Start the enclosing BB10 block. */
5264 filename
= bfd_get_filename (info
->abfd
);
5265 modname
= strrchr (filename
, '/');
5266 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
5267 backslash
= strrchr (filename
, '\\');
5268 if (modname
== NULL
|| (backslash
!= NULL
&& backslash
> modname
))
5269 modname
= backslash
;
5272 if (modname
!= NULL
)
5274 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
5275 else if (filename
[0] && filename
[1] == ':')
5276 modname
= filename
+ 2;
5281 c
= xstrdup (modname
);
5282 s
= strrchr (c
, '.');
5286 if (! ieee_change_buffer (info
, &info
->vars
)
5287 || ! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
5288 || ! ieee_write_byte (info
, 10)
5289 || ! ieee_write_number (info
, 0)
5290 || ! ieee_write_id (info
, c
)
5291 || ! ieee_write_id (info
, "")
5292 || ! ieee_write_number (info
, 0)
5293 || ! ieee_write_id (info
, "GNU objcopy"))
5299 if ((sec
->flags
& SEC_CODE
) != 0)
5301 else if ((sec
->flags
& SEC_READONLY
) != 0)
5306 if (! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
5307 || ! ieee_write_byte (info
, 11)
5308 || ! ieee_write_number (info
, 0)
5309 || ! ieee_write_id (info
, "")
5310 || ! ieee_write_number (info
, kind
)
5311 || ! ieee_write_number (info
, sec
->index
+ IEEE_SECTION_NUMBER_BASE
)
5312 || ! ieee_write_number (info
, low
)
5313 || ! ieee_write_byte (info
, (int) ieee_be_record_enum
)
5314 || ! ieee_write_number (info
, high
- low
))
5320 /* Start recording information from a particular source file. This is
5321 used to record which file defined which types, variables, etc. It
5322 is not used for line numbers, since the lineno entry point passes
5323 down the file name anyhow. IEEE debugging information doesn't seem
5324 to store this information anywhere. */
5327 ieee_start_source (p
, filename
)
5328 PTR p ATTRIBUTE_UNUSED
;
5329 const char *filename ATTRIBUTE_UNUSED
;
5334 /* Make an empty type. */
5340 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
5342 return ieee_push_type (info
, (int) builtin_unknown
, 0, FALSE
, FALSE
);
5345 /* Make a void type. */
5351 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
5353 return ieee_push_type (info
, (int) builtin_void
, 0, FALSE
, FALSE
);
5356 /* Make an integer type. */
5359 ieee_int_type (p
, size
, unsignedp
)
5362 bfd_boolean unsignedp
;
5364 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
5370 indx
= (int) builtin_signed_char
;
5373 indx
= (int) builtin_signed_short_int
;
5376 indx
= (int) builtin_signed_long
;
5379 indx
= (int) builtin_signed_long_long
;
5382 fprintf (stderr
, _("IEEE unsupported integer type size %u\n"), size
);
5389 return ieee_push_type (info
, indx
, size
, unsignedp
, FALSE
);
5392 /* Make a floating point type. */
5395 ieee_float_type (p
, size
)
5399 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
5405 indx
= (int) builtin_float
;
5408 indx
= (int) builtin_double
;
5411 /* FIXME: This size really depends upon the processor. */
5412 indx
= (int) builtin_long_double
;
5415 indx
= (int) builtin_long_long_double
;
5418 fprintf (stderr
, _("IEEE unsupported float type size %u\n"), size
);
5422 return ieee_push_type (info
, indx
, size
, FALSE
, FALSE
);
5425 /* Make a complex type. */
5428 ieee_complex_type (p
, size
)
5432 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
5438 if (info
->complex_float_index
!= 0)
5439 return ieee_push_type (info
, info
->complex_float_index
, size
* 2,
5445 /* These cases can be output by gcc -gstabs. Outputting the
5446 wrong type is better than crashing. */
5448 if (info
->complex_double_index
!= 0)
5449 return ieee_push_type (info
, info
->complex_double_index
, size
* 2,
5454 fprintf (stderr
, _("IEEE unsupported complex type size %u\n"), size
);
5458 /* FIXME: I don't know what the string is for. */
5459 if (! ieee_define_type (info
, size
* 2, FALSE
, FALSE
)
5460 || ! ieee_write_number (info
, code
)
5461 || ! ieee_write_id (info
, ""))
5465 info
->complex_float_index
= info
->type_stack
->type
.indx
;
5467 info
->complex_double_index
= info
->type_stack
->type
.indx
;
5472 /* Make a boolean type. IEEE doesn't support these, so we just make
5473 an integer type instead. */
5476 ieee_bool_type (p
, size
)
5480 return ieee_int_type (p
, size
, TRUE
);
5483 /* Make an enumeration. */
5486 ieee_enum_type (p
, tag
, names
, vals
)
5490 bfd_signed_vma
*vals
;
5492 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
5493 struct ieee_defined_enum
*e
;
5494 bfd_boolean localp
, simple
;
5499 indx
= (unsigned int) -1;
5500 for (e
= info
->enums
; e
!= NULL
; e
= e
->next
)
5510 || tag
[0] != e
->tag
[0]
5511 || strcmp (tag
, e
->tag
) != 0)
5517 /* This enum tag has been seen but not defined. */
5522 if (names
!= NULL
&& e
->names
!= NULL
)
5524 for (i
= 0; names
[i
] != NULL
&& e
->names
[i
] != NULL
; i
++)
5526 if (names
[i
][0] != e
->names
[i
][0]
5527 || vals
[i
] != e
->vals
[i
]
5528 || strcmp (names
[i
], e
->names
[i
]) != 0)
5533 if ((names
== NULL
&& e
->names
== NULL
)
5537 && e
->names
[i
] == NULL
))
5539 /* We've seen this enum before. */
5540 return ieee_push_type (info
, e
->indx
, 0, TRUE
, FALSE
);
5545 /* We've already seen an enum of the same name, so we must make
5546 sure to output this one locally. */
5552 /* If this is a simple enumeration, in which the values start at 0
5553 and always increment by 1, we can use type E. Otherwise we must
5559 for (i
= 0; names
[i
] != NULL
; i
++)
5569 if (! ieee_define_named_type (info
, tag
, indx
, 0, TRUE
, localp
,
5570 (struct ieee_buflist
*) NULL
)
5571 || ! ieee_write_number (info
, simple
? 'E' : 'N'))
5575 /* FIXME: This is supposed to be the enumeration size, but we
5576 don't store that. */
5577 if (! ieee_write_number (info
, 4))
5582 for (i
= 0; names
[i
] != NULL
; i
++)
5584 if (! ieee_write_id (info
, names
[i
]))
5588 if (! ieee_write_number (info
, vals
[i
]))
5596 if (indx
== (unsigned int) -1)
5598 e
= (struct ieee_defined_enum
*) xmalloc (sizeof *e
);
5599 memset (e
, 0, sizeof *e
);
5600 e
->indx
= info
->type_stack
->type
.indx
;
5603 e
->next
= info
->enums
;
5615 /* Make a pointer type. */
5618 ieee_pointer_type (p
)
5621 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
5624 struct ieee_modified_type
*m
= NULL
;
5626 localp
= info
->type_stack
->type
.localp
;
5627 indx
= ieee_pop_type (info
);
5629 /* A pointer to a simple builtin type can be obtained by adding 32.
5630 FIXME: Will this be a short pointer, and will that matter? */
5632 return ieee_push_type (info
, indx
+ 32, 0, TRUE
, FALSE
);
5636 m
= ieee_get_modified_info (p
, indx
);
5640 /* FIXME: The size should depend upon the architecture. */
5642 return ieee_push_type (info
, m
->pointer
, 4, TRUE
, FALSE
);
5645 if (! ieee_define_type (info
, 4, TRUE
, localp
)
5646 || ! ieee_write_number (info
, 'P')
5647 || ! ieee_write_number (info
, indx
))
5651 m
->pointer
= info
->type_stack
->type
.indx
;
5656 /* Make a function type. This will be called for a method, but we
5657 don't want to actually add it to the type table in that case. We
5658 handle this by defining the type in a private buffer, and only
5659 adding that buffer to the typedef block if we are going to use it. */
5662 ieee_function_type (p
, argcount
, varargs
)
5665 bfd_boolean varargs
;
5667 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
5669 unsigned int *args
= NULL
;
5671 unsigned int retindx
;
5672 struct ieee_buflist fndef
;
5673 struct ieee_modified_type
*m
;
5679 args
= (unsigned int *) xmalloc (argcount
* sizeof *args
);
5680 for (i
= argcount
- 1; i
>= 0; i
--)
5682 if (info
->type_stack
->type
.localp
)
5684 args
[i
] = ieee_pop_type (info
);
5687 else if (argcount
< 0)
5690 if (info
->type_stack
->type
.localp
)
5692 retindx
= ieee_pop_type (info
);
5695 if (argcount
< 0 && ! localp
)
5697 m
= ieee_get_modified_info (p
, retindx
);
5701 if (m
->function
> 0)
5702 return ieee_push_type (info
, m
->function
, 0, TRUE
, FALSE
);
5705 /* An attribute of 0x41 means that the frame and push mask are
5707 if (! ieee_init_buffer (info
, &fndef
)
5708 || ! ieee_define_named_type (info
, (const char *) NULL
,
5709 (unsigned int) -1, 0, TRUE
, localp
,
5711 || ! ieee_write_number (info
, 'x')
5712 || ! ieee_write_number (info
, 0x41)
5713 || ! ieee_write_number (info
, 0)
5714 || ! ieee_write_number (info
, 0)
5715 || ! ieee_write_number (info
, retindx
)
5716 || ! ieee_write_number (info
, (bfd_vma
) argcount
+ (varargs
? 1 : 0)))
5720 for (i
= 0; i
< argcount
; i
++)
5721 if (! ieee_write_number (info
, args
[i
]))
5727 /* A varargs function is represented by writing out the last
5728 argument as type void *, although this makes little sense. */
5729 if (! ieee_write_number (info
, (bfd_vma
) builtin_void
+ 32))
5733 if (! ieee_write_number (info
, 0))
5736 /* We wrote the information into fndef, in case we don't need it.
5737 It will be appended to info->types by ieee_pop_type. */
5738 info
->type_stack
->type
.fndef
= fndef
;
5741 m
->function
= info
->type_stack
->type
.indx
;
5746 /* Make a reference type. */
5749 ieee_reference_type (p
)
5752 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
5754 /* IEEE appears to record a normal pointer type, and then use a
5755 pmisc record to indicate that it is really a reference. */
5757 if (! ieee_pointer_type (p
))
5759 info
->type_stack
->type
.referencep
= TRUE
;
5763 /* Make a range type. */
5766 ieee_range_type (p
, low
, high
)
5769 bfd_signed_vma high
;
5771 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
5773 bfd_boolean unsignedp
, localp
;
5775 size
= info
->type_stack
->type
.size
;
5776 unsignedp
= info
->type_stack
->type
.unsignedp
;
5777 localp
= info
->type_stack
->type
.localp
;
5778 ieee_pop_unused_type (info
);
5779 return (ieee_define_type (info
, size
, unsignedp
, localp
)
5780 && ieee_write_number (info
, 'R')
5781 && ieee_write_number (info
, (bfd_vma
) low
)
5782 && ieee_write_number (info
, (bfd_vma
) high
)
5783 && ieee_write_number (info
, unsignedp
? 0 : 1)
5784 && ieee_write_number (info
, size
));
5787 /* Make an array type. */
5790 ieee_array_type (p
, low
, high
, stringp
)
5793 bfd_signed_vma high
;
5794 bfd_boolean stringp ATTRIBUTE_UNUSED
;
5796 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
5797 unsigned int eleindx
;
5800 struct ieee_modified_type
*m
= NULL
;
5801 struct ieee_modified_array_type
*a
;
5803 /* IEEE does not store the range, so we just ignore it. */
5804 ieee_pop_unused_type (info
);
5805 localp
= info
->type_stack
->type
.localp
;
5806 size
= info
->type_stack
->type
.size
;
5807 eleindx
= ieee_pop_type (info
);
5809 /* If we don't know the range, treat the size as exactly one
5812 size
*= (high
- low
) + 1;
5816 m
= ieee_get_modified_info (info
, eleindx
);
5820 for (a
= m
->arrays
; a
!= NULL
; a
= a
->next
)
5822 if (a
->low
== low
&& a
->high
== high
)
5823 return ieee_push_type (info
, a
->indx
, size
, FALSE
, FALSE
);
5827 if (! ieee_define_type (info
, size
, FALSE
, localp
)
5828 || ! ieee_write_number (info
, low
== 0 ? 'Z' : 'C')
5829 || ! ieee_write_number (info
, eleindx
))
5833 if (! ieee_write_number (info
, low
))
5837 if (! ieee_write_number (info
, high
+ 1))
5842 a
= (struct ieee_modified_array_type
*) xmalloc (sizeof *a
);
5843 memset (a
, 0, sizeof *a
);
5845 a
->indx
= info
->type_stack
->type
.indx
;
5849 a
->next
= m
->arrays
;
5856 /* Make a set type. */
5859 ieee_set_type (p
, bitstringp
)
5861 bfd_boolean bitstringp ATTRIBUTE_UNUSED
;
5863 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
5865 unsigned int eleindx
;
5867 localp
= info
->type_stack
->type
.localp
;
5868 eleindx
= ieee_pop_type (info
);
5870 /* FIXME: We don't know the size, so we just use 4. */
5872 return (ieee_define_type (info
, 0, TRUE
, localp
)
5873 && ieee_write_number (info
, 's')
5874 && ieee_write_number (info
, 4)
5875 && ieee_write_number (info
, eleindx
));
5878 /* Make an offset type. */
5881 ieee_offset_type (p
)
5884 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
5885 unsigned int targetindx
, baseindx
;
5887 targetindx
= ieee_pop_type (info
);
5888 baseindx
= ieee_pop_type (info
);
5890 /* FIXME: The MRI C++ compiler does not appear to generate any
5891 useful type information about an offset type. It just records a
5892 pointer to member as an integer. The MRI/HP IEEE spec does
5893 describe a pmisc record which can be used for a pointer to
5894 member. Unfortunately, it does not describe the target type,
5895 which seems pretty important. I'm going to punt this for now. */
5897 return ieee_int_type (p
, 4, TRUE
);
5900 /* Make a method type. */
5903 ieee_method_type (p
, domain
, argcount
, varargs
)
5907 bfd_boolean varargs
;
5909 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
5911 /* FIXME: The MRI/HP IEEE spec defines a pmisc record to use for a
5912 method, but the definition is incomplete. We just output an 'x'
5916 ieee_pop_unused_type (info
);
5918 return ieee_function_type (p
, argcount
, varargs
);
5921 /* Make a const qualified type. */
5927 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
5929 bfd_boolean unsignedp
, localp
;
5931 struct ieee_modified_type
*m
= NULL
;
5933 size
= info
->type_stack
->type
.size
;
5934 unsignedp
= info
->type_stack
->type
.unsignedp
;
5935 localp
= info
->type_stack
->type
.localp
;
5936 indx
= ieee_pop_type (info
);
5940 m
= ieee_get_modified_info (info
, indx
);
5944 if (m
->const_qualified
> 0)
5945 return ieee_push_type (info
, m
->const_qualified
, size
, unsignedp
,
5949 if (! ieee_define_type (info
, size
, unsignedp
, localp
)
5950 || ! ieee_write_number (info
, 'n')
5951 || ! ieee_write_number (info
, 1)
5952 || ! ieee_write_number (info
, indx
))
5956 m
->const_qualified
= info
->type_stack
->type
.indx
;
5961 /* Make a volatile qualified type. */
5964 ieee_volatile_type (p
)
5967 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
5969 bfd_boolean unsignedp
, localp
;
5971 struct ieee_modified_type
*m
= NULL
;
5973 size
= info
->type_stack
->type
.size
;
5974 unsignedp
= info
->type_stack
->type
.unsignedp
;
5975 localp
= info
->type_stack
->type
.localp
;
5976 indx
= ieee_pop_type (info
);
5980 m
= ieee_get_modified_info (info
, indx
);
5984 if (m
->volatile_qualified
> 0)
5985 return ieee_push_type (info
, m
->volatile_qualified
, size
, unsignedp
,
5989 if (! ieee_define_type (info
, size
, unsignedp
, localp
)
5990 || ! ieee_write_number (info
, 'n')
5991 || ! ieee_write_number (info
, 2)
5992 || ! ieee_write_number (info
, indx
))
5996 m
->volatile_qualified
= info
->type_stack
->type
.indx
;
6001 /* Convert an enum debug_visibility into a CXXFLAGS value. */
6004 ieee_vis_to_flags (visibility
)
6005 enum debug_visibility visibility
;
6011 case DEBUG_VISIBILITY_PUBLIC
:
6012 return CXXFLAGS_VISIBILITY_PUBLIC
;
6013 case DEBUG_VISIBILITY_PRIVATE
:
6014 return CXXFLAGS_VISIBILITY_PRIVATE
;
6015 case DEBUG_VISIBILITY_PROTECTED
:
6016 return CXXFLAGS_VISIBILITY_PROTECTED
;
6021 /* Start defining a struct type. We build it in the strdef field on
6022 the stack, to avoid confusing type definitions required by the
6023 fields with the struct type itself. */
6026 ieee_start_struct_type (p
, tag
, id
, structp
, size
)
6030 bfd_boolean structp
;
6033 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
6034 bfd_boolean localp
, ignorep
;
6038 struct ieee_name_type_hash_entry
*h
;
6039 struct ieee_name_type
*nt
, *ntlook
;
6040 struct ieee_buflist strdef
;
6045 /* We need to create a tag for internal use even if we don't want
6046 one for external use. This will let us refer to an anonymous
6055 sprintf (ab
, "__anon%u", id
);
6060 /* If we already have references to the tag, we must use the
6061 existing type index. */
6062 h
= ieee_name_type_hash_lookup (&info
->tags
, look
, TRUE
, copy
);
6067 for (ntlook
= h
->types
; ntlook
!= NULL
; ntlook
= ntlook
->next
)
6069 if (ntlook
->id
== id
)
6071 else if (! ntlook
->type
.localp
)
6073 /* We are creating a duplicate definition of a globally
6074 defined tag. Force it to be local to avoid
6082 assert (localp
== nt
->type
.localp
);
6083 if (nt
->kind
== DEBUG_KIND_ILLEGAL
&& ! localp
)
6085 /* We've already seen a global definition of the type.
6086 Ignore this new definition. */
6092 nt
= (struct ieee_name_type
*) xmalloc (sizeof *nt
);
6093 memset (nt
, 0, sizeof *nt
);
6095 nt
->type
.name
= h
->root
.string
;
6096 nt
->next
= h
->types
;
6098 nt
->type
.indx
= info
->type_indx
;
6102 nt
->kind
= DEBUG_KIND_ILLEGAL
;
6104 if (! ieee_init_buffer (info
, &strdef
)
6105 || ! ieee_define_named_type (info
, tag
, nt
->type
.indx
, size
, TRUE
,
6107 || ! ieee_write_number (info
, structp
? 'S' : 'U')
6108 || ! ieee_write_number (info
, size
))
6115 /* We never want nt->type.name to be NULL. We want the rest of
6116 the type to be the object set up on the type stack; it will
6117 have a NULL name if tag is NULL. */
6118 hold
= nt
->type
.name
;
6119 nt
->type
= info
->type_stack
->type
;
6120 nt
->type
.name
= hold
;
6123 info
->type_stack
->type
.name
= tag
;
6124 info
->type_stack
->type
.strdef
= strdef
;
6125 info
->type_stack
->type
.ignorep
= ignorep
;
6130 /* Add a field to a struct. */
6133 ieee_struct_field (p
, name
, bitpos
, bitsize
, visibility
)
6138 enum debug_visibility visibility
;
6140 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
6142 bfd_boolean unsignedp
;
6143 bfd_boolean referencep
;
6148 assert (info
->type_stack
!= NULL
6149 && info
->type_stack
->next
!= NULL
6150 && ! ieee_buffer_emptyp (&info
->type_stack
->next
->type
.strdef
));
6152 /* If we are ignoring this struct definition, just pop and ignore
6154 if (info
->type_stack
->next
->type
.ignorep
)
6156 ieee_pop_unused_type (info
);
6160 size
= info
->type_stack
->type
.size
;
6161 unsignedp
= info
->type_stack
->type
.unsignedp
;
6162 referencep
= info
->type_stack
->type
.referencep
;
6163 localp
= info
->type_stack
->type
.localp
;
6164 indx
= ieee_pop_type (info
);
6167 info
->type_stack
->type
.localp
= TRUE
;
6169 if (info
->type_stack
->type
.classdef
!= NULL
)
6174 /* This is a class. We must add a description of this field to
6175 the class records we are building. */
6177 flags
= ieee_vis_to_flags (visibility
);
6178 nindx
= info
->type_stack
->type
.classdef
->indx
;
6179 if (! ieee_change_buffer (info
,
6180 &info
->type_stack
->type
.classdef
->pmiscbuf
)
6181 || ! ieee_write_asn (info
, nindx
, 'd')
6182 || ! ieee_write_asn (info
, nindx
, flags
)
6183 || ! ieee_write_atn65 (info
, nindx
, name
)
6184 || ! ieee_write_atn65 (info
, nindx
, name
))
6186 info
->type_stack
->type
.classdef
->pmisccount
+= 4;
6192 /* We need to output a record recording that this field is
6193 really of reference type. We put this on the refs field
6194 of classdef, so that it can be appended to the C++
6195 records after the class is defined. */
6197 nindx
= info
->name_indx
;
6200 if (! ieee_change_buffer (info
,
6201 &info
->type_stack
->type
.classdef
->refs
)
6202 || ! ieee_write_byte (info
, (int) ieee_nn_record
)
6203 || ! ieee_write_number (info
, nindx
)
6204 || ! ieee_write_id (info
, "")
6205 || ! ieee_write_2bytes (info
, (int) ieee_atn_record_enum
)
6206 || ! ieee_write_number (info
, nindx
)
6207 || ! ieee_write_number (info
, 0)
6208 || ! ieee_write_number (info
, 62)
6209 || ! ieee_write_number (info
, 80)
6210 || ! ieee_write_number (info
, 4)
6211 || ! ieee_write_asn (info
, nindx
, 'R')
6212 || ! ieee_write_asn (info
, nindx
, 3)
6213 || ! ieee_write_atn65 (info
, nindx
, info
->type_stack
->type
.name
)
6214 || ! ieee_write_atn65 (info
, nindx
, name
))
6219 /* If the bitsize doesn't match the expected size, we need to output
6221 if (size
== 0 || bitsize
== 0 || bitsize
== size
* 8)
6222 offset
= bitpos
/ 8;
6225 if (! ieee_define_type (info
, 0, unsignedp
,
6226 info
->type_stack
->type
.localp
)
6227 || ! ieee_write_number (info
, 'g')
6228 || ! ieee_write_number (info
, unsignedp
? 0 : 1)
6229 || ! ieee_write_number (info
, bitsize
)
6230 || ! ieee_write_number (info
, indx
))
6232 indx
= ieee_pop_type (info
);
6236 /* Switch to the struct we are building in order to output this
6237 field definition. */
6238 return (ieee_change_buffer (info
, &info
->type_stack
->type
.strdef
)
6239 && ieee_write_id (info
, name
)
6240 && ieee_write_number (info
, indx
)
6241 && ieee_write_number (info
, offset
));
6244 /* Finish up a struct type. */
6247 ieee_end_struct_type (p
)
6250 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
6251 struct ieee_buflist
*pb
;
6253 assert (info
->type_stack
!= NULL
6254 && ! ieee_buffer_emptyp (&info
->type_stack
->type
.strdef
));
6256 /* If we were ignoring this struct definition because it was a
6257 duplicate defintion, just through away whatever bytes we have
6258 accumulated. Leave the type on the stack. */
6259 if (info
->type_stack
->type
.ignorep
)
6262 /* If this is not a duplicate definition of this tag, then localp
6263 will be FALSE, and we can put it in the global type block.
6264 FIXME: We should avoid outputting duplicate definitions which are
6266 if (! info
->type_stack
->type
.localp
)
6268 /* Make sure we have started the global type block. */
6269 if (ieee_buffer_emptyp (&info
->global_types
))
6271 if (! ieee_change_buffer (info
, &info
->global_types
)
6272 || ! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
6273 || ! ieee_write_byte (info
, 2)
6274 || ! ieee_write_number (info
, 0)
6275 || ! ieee_write_id (info
, ""))
6278 pb
= &info
->global_types
;
6282 /* Make sure we have started the types block. */
6283 if (ieee_buffer_emptyp (&info
->types
))
6285 if (! ieee_change_buffer (info
, &info
->types
)
6286 || ! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
6287 || ! ieee_write_byte (info
, 1)
6288 || ! ieee_write_number (info
, 0)
6289 || ! ieee_write_id (info
, info
->modname
))
6295 /* Append the struct definition to the types. */
6296 if (! ieee_append_buffer (info
, pb
, &info
->type_stack
->type
.strdef
)
6297 || ! ieee_init_buffer (info
, &info
->type_stack
->type
.strdef
))
6300 /* Leave the struct on the type stack. */
6305 /* Start a class type. */
6308 ieee_start_class_type (p
, tag
, id
, structp
, size
, vptr
, ownvptr
)
6312 bfd_boolean structp
;
6315 bfd_boolean ownvptr
;
6317 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
6319 struct ieee_buflist pmiscbuf
;
6321 struct ieee_type_class
*classdef
;
6323 /* A C++ class is output as a C++ struct along with a set of pmisc
6324 records describing the class. */
6326 /* We need to have a name so that we can associate the struct and
6332 t
= (char *) xmalloc (20);
6333 sprintf (t
, "__anon%u", id
);
6337 /* We can't write out the virtual table information until we have
6338 finished the class, because we don't know the virtual table size.
6339 We get the size from the largest voffset we see. */
6341 if (vptr
&& ! ownvptr
)
6343 vclass
= info
->type_stack
->type
.name
;
6344 assert (vclass
!= NULL
);
6345 /* We don't call ieee_pop_unused_type, since the class should
6347 (void) ieee_pop_type (info
);
6350 if (! ieee_start_struct_type (p
, tag
, id
, structp
, size
))
6353 indx
= info
->name_indx
;
6356 /* We write out pmisc records into the classdef field. We will
6357 write out the pmisc start after we know the number of records we
6359 if (! ieee_init_buffer (info
, &pmiscbuf
)
6360 || ! ieee_change_buffer (info
, &pmiscbuf
)
6361 || ! ieee_write_asn (info
, indx
, 'T')
6362 || ! ieee_write_asn (info
, indx
, structp
? 'o' : 'u')
6363 || ! ieee_write_atn65 (info
, indx
, tag
))
6366 classdef
= (struct ieee_type_class
*) xmalloc (sizeof *classdef
);
6367 memset (classdef
, 0, sizeof *classdef
);
6369 classdef
->indx
= indx
;
6370 classdef
->pmiscbuf
= pmiscbuf
;
6371 classdef
->pmisccount
= 3;
6372 classdef
->vclass
= vclass
;
6373 classdef
->ownvptr
= ownvptr
;
6375 info
->type_stack
->type
.classdef
= classdef
;
6380 /* Add a static member to a class. */
6383 ieee_class_static_member (p
, name
, physname
, visibility
)
6386 const char *physname
;
6387 enum debug_visibility visibility
;
6389 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
6393 /* We don't care about the type. Hopefully there will be a call to
6394 ieee_variable declaring the physical name and the type, since
6395 that is where an IEEE consumer must get the type. */
6396 ieee_pop_unused_type (info
);
6398 assert (info
->type_stack
!= NULL
6399 && info
->type_stack
->type
.classdef
!= NULL
);
6401 flags
= ieee_vis_to_flags (visibility
);
6402 flags
|= CXXFLAGS_STATIC
;
6404 nindx
= info
->type_stack
->type
.classdef
->indx
;
6406 if (! ieee_change_buffer (info
, &info
->type_stack
->type
.classdef
->pmiscbuf
)
6407 || ! ieee_write_asn (info
, nindx
, 'd')
6408 || ! ieee_write_asn (info
, nindx
, flags
)
6409 || ! ieee_write_atn65 (info
, nindx
, name
)
6410 || ! ieee_write_atn65 (info
, nindx
, physname
))
6412 info
->type_stack
->type
.classdef
->pmisccount
+= 4;
6417 /* Add a base class to a class. */
6420 ieee_class_baseclass (p
, bitpos
, virtual, visibility
)
6423 bfd_boolean
virtual;
6424 enum debug_visibility visibility
;
6426 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
6434 assert (info
->type_stack
!= NULL
6435 && info
->type_stack
->type
.name
!= NULL
6436 && info
->type_stack
->next
!= NULL
6437 && info
->type_stack
->next
->type
.classdef
!= NULL
6438 && ! ieee_buffer_emptyp (&info
->type_stack
->next
->type
.strdef
));
6440 bname
= info
->type_stack
->type
.name
;
6441 localp
= info
->type_stack
->type
.localp
;
6442 bindx
= ieee_pop_type (info
);
6444 /* We are currently defining both a struct and a class. We must
6445 write out a field definition in the struct which holds the base
6446 class. The stabs debugging reader will create a field named
6447 _vb$CLASS for a virtual base class, so we just use that. FIXME:
6448 we should not depend upon a detail of stabs debugging. */
6451 fname
= (char *) xmalloc (strlen (bname
) + sizeof "_vb$");
6452 sprintf (fname
, "_vb$%s", bname
);
6453 flags
= BASEFLAGS_VIRTUAL
;
6458 info
->type_stack
->type
.localp
= TRUE
;
6460 fname
= (char *) xmalloc (strlen (bname
) + sizeof "_b$");
6461 sprintf (fname
, "_b$%s", bname
);
6463 if (! ieee_change_buffer (info
, &info
->type_stack
->type
.strdef
)
6464 || ! ieee_write_id (info
, fname
)
6465 || ! ieee_write_number (info
, bindx
)
6466 || ! ieee_write_number (info
, bitpos
/ 8))
6471 if (visibility
== DEBUG_VISIBILITY_PRIVATE
)
6472 flags
|= BASEFLAGS_PRIVATE
;
6474 nindx
= info
->type_stack
->type
.classdef
->indx
;
6476 if (! ieee_change_buffer (info
, &info
->type_stack
->type
.classdef
->pmiscbuf
)
6477 || ! ieee_write_asn (info
, nindx
, 'b')
6478 || ! ieee_write_asn (info
, nindx
, flags
)
6479 || ! ieee_write_atn65 (info
, nindx
, bname
)
6480 || ! ieee_write_asn (info
, nindx
, 0)
6481 || ! ieee_write_atn65 (info
, nindx
, fname
))
6483 info
->type_stack
->type
.classdef
->pmisccount
+= 5;
6490 /* Start building a method for a class. */
6493 ieee_class_start_method (p
, name
)
6497 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
6499 assert (info
->type_stack
!= NULL
6500 && info
->type_stack
->type
.classdef
!= NULL
6501 && info
->type_stack
->type
.classdef
->method
== NULL
);
6503 info
->type_stack
->type
.classdef
->method
= name
;
6508 /* Define a new method variant, either static or not. */
6511 ieee_class_method_var (info
, physname
, visibility
, staticp
, constp
,
6512 volatilep
, voffset
, context
)
6513 struct ieee_handle
*info
;
6514 const char *physname
;
6515 enum debug_visibility visibility
;
6516 bfd_boolean staticp
;
6518 bfd_boolean volatilep
;
6520 bfd_boolean context
;
6524 bfd_boolean
virtual;
6526 /* We don't need the type of the method. An IEEE consumer which
6527 wants the type must track down the function by the physical name
6528 and get the type from that. */
6529 ieee_pop_unused_type (info
);
6531 /* We don't use the context. FIXME: We probably ought to use it to
6532 adjust the voffset somehow, but I don't really know how. */
6534 ieee_pop_unused_type (info
);
6536 assert (info
->type_stack
!= NULL
6537 && info
->type_stack
->type
.classdef
!= NULL
6538 && info
->type_stack
->type
.classdef
->method
!= NULL
);
6540 flags
= ieee_vis_to_flags (visibility
);
6542 /* FIXME: We never set CXXFLAGS_OVERRIDE, CXXFLAGS_OPERATOR,
6543 CXXFLAGS_CTORDTOR, CXXFLAGS_CTOR, or CXXFLAGS_INLINE. */
6546 flags
|= CXXFLAGS_STATIC
;
6548 flags
|= CXXFLAGS_CONST
;
6550 flags
|= CXXFLAGS_VOLATILE
;
6552 nindx
= info
->type_stack
->type
.classdef
->indx
;
6554 virtual = context
|| voffset
> 0;
6556 if (! ieee_change_buffer (info
,
6557 &info
->type_stack
->type
.classdef
->pmiscbuf
)
6558 || ! ieee_write_asn (info
, nindx
, virtual ? 'v' : 'm')
6559 || ! ieee_write_asn (info
, nindx
, flags
)
6560 || ! ieee_write_atn65 (info
, nindx
,
6561 info
->type_stack
->type
.classdef
->method
)
6562 || ! ieee_write_atn65 (info
, nindx
, physname
))
6567 if (voffset
> info
->type_stack
->type
.classdef
->voffset
)
6568 info
->type_stack
->type
.classdef
->voffset
= voffset
;
6569 if (! ieee_write_asn (info
, nindx
, voffset
))
6571 ++info
->type_stack
->type
.classdef
->pmisccount
;
6574 if (! ieee_write_asn (info
, nindx
, 0))
6577 info
->type_stack
->type
.classdef
->pmisccount
+= 5;
6582 /* Define a new method variant. */
6585 ieee_class_method_variant (p
, physname
, visibility
, constp
, volatilep
,
6588 const char *physname
;
6589 enum debug_visibility visibility
;
6591 bfd_boolean volatilep
;
6593 bfd_boolean context
;
6595 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
6597 return ieee_class_method_var (info
, physname
, visibility
, FALSE
, constp
,
6598 volatilep
, voffset
, context
);
6601 /* Define a new static method variant. */
6604 ieee_class_static_method_variant (p
, physname
, visibility
, constp
, volatilep
)
6606 const char *physname
;
6607 enum debug_visibility visibility
;
6609 bfd_boolean volatilep
;
6611 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
6613 return ieee_class_method_var (info
, physname
, visibility
, TRUE
, constp
,
6614 volatilep
, 0, FALSE
);
6617 /* Finish up a method. */
6620 ieee_class_end_method (p
)
6623 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
6625 assert (info
->type_stack
!= NULL
6626 && info
->type_stack
->type
.classdef
!= NULL
6627 && info
->type_stack
->type
.classdef
->method
!= NULL
);
6629 info
->type_stack
->type
.classdef
->method
= NULL
;
6634 /* Finish up a class. */
6637 ieee_end_class_type (p
)
6640 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
6643 assert (info
->type_stack
!= NULL
6644 && info
->type_stack
->type
.classdef
!= NULL
);
6646 /* If we were ignoring this class definition because it was a
6647 duplicate definition, just through away whatever bytes we have
6648 accumulated. Leave the type on the stack. */
6649 if (info
->type_stack
->type
.ignorep
)
6652 nindx
= info
->type_stack
->type
.classdef
->indx
;
6654 /* If we have a virtual table, we can write out the information now. */
6655 if (info
->type_stack
->type
.classdef
->vclass
!= NULL
6656 || info
->type_stack
->type
.classdef
->ownvptr
)
6658 if (! ieee_change_buffer (info
,
6659 &info
->type_stack
->type
.classdef
->pmiscbuf
)
6660 || ! ieee_write_asn (info
, nindx
, 'z')
6661 || ! ieee_write_atn65 (info
, nindx
, "")
6662 || ! ieee_write_asn (info
, nindx
,
6663 info
->type_stack
->type
.classdef
->voffset
))
6665 if (info
->type_stack
->type
.classdef
->ownvptr
)
6667 if (! ieee_write_atn65 (info
, nindx
, ""))
6672 if (! ieee_write_atn65 (info
, nindx
,
6673 info
->type_stack
->type
.classdef
->vclass
))
6676 if (! ieee_write_asn (info
, nindx
, 0))
6678 info
->type_stack
->type
.classdef
->pmisccount
+= 5;
6681 /* Now that we know the number of pmisc records, we can write out
6682 the atn62 which starts the pmisc records, and append them to the
6685 if (! ieee_change_buffer (info
, &info
->cxx
)
6686 || ! ieee_write_byte (info
, (int) ieee_nn_record
)
6687 || ! ieee_write_number (info
, nindx
)
6688 || ! ieee_write_id (info
, "")
6689 || ! ieee_write_2bytes (info
, (int) ieee_atn_record_enum
)
6690 || ! ieee_write_number (info
, nindx
)
6691 || ! ieee_write_number (info
, 0)
6692 || ! ieee_write_number (info
, 62)
6693 || ! ieee_write_number (info
, 80)
6694 || ! ieee_write_number (info
,
6695 info
->type_stack
->type
.classdef
->pmisccount
))
6698 if (! ieee_append_buffer (info
, &info
->cxx
,
6699 &info
->type_stack
->type
.classdef
->pmiscbuf
))
6701 if (! ieee_buffer_emptyp (&info
->type_stack
->type
.classdef
->refs
))
6703 if (! ieee_append_buffer (info
, &info
->cxx
,
6704 &info
->type_stack
->type
.classdef
->refs
))
6708 return ieee_end_struct_type (p
);
6711 /* Push a previously seen typedef onto the type stack. */
6714 ieee_typedef_type (p
, name
)
6718 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
6719 struct ieee_name_type_hash_entry
*h
;
6720 struct ieee_name_type
*nt
;
6722 h
= ieee_name_type_hash_lookup (&info
->typedefs
, name
, FALSE
, FALSE
);
6724 /* h should never be NULL, since that would imply that the generic
6725 debugging code has asked for a typedef which it has not yet
6729 /* We always use the most recently defined type for this name, which
6730 will be the first one on the list. */
6733 if (! ieee_push_type (info
, nt
->type
.indx
, nt
->type
.size
,
6734 nt
->type
.unsignedp
, nt
->type
.localp
))
6737 /* Copy over any other type information we may have. */
6738 info
->type_stack
->type
= nt
->type
;
6743 /* Push a tagged type onto the type stack. */
6746 ieee_tag_type (p
, name
, id
, kind
)
6750 enum debug_type_kind kind
;
6752 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
6756 struct ieee_name_type_hash_entry
*h
;
6757 struct ieee_name_type
*nt
;
6759 if (kind
== DEBUG_KIND_ENUM
)
6761 struct ieee_defined_enum
*e
;
6765 for (e
= info
->enums
; e
!= NULL
; e
= e
->next
)
6766 if (e
->tag
!= NULL
&& strcmp (e
->tag
, name
) == 0)
6767 return ieee_push_type (info
, e
->indx
, 0, TRUE
, FALSE
);
6769 e
= (struct ieee_defined_enum
*) xmalloc (sizeof *e
);
6770 memset (e
, 0, sizeof *e
);
6772 e
->indx
= info
->type_indx
;
6777 e
->next
= info
->enums
;
6780 return ieee_push_type (info
, e
->indx
, 0, TRUE
, FALSE
);
6788 sprintf (ab
, "__anon%u", id
);
6793 h
= ieee_name_type_hash_lookup (&info
->tags
, name
, TRUE
, copy
);
6797 for (nt
= h
->types
; nt
!= NULL
; nt
= nt
->next
)
6801 if (! ieee_push_type (info
, nt
->type
.indx
, nt
->type
.size
,
6802 nt
->type
.unsignedp
, nt
->type
.localp
))
6804 /* Copy over any other type information we may have. */
6805 info
->type_stack
->type
= nt
->type
;
6809 if (! nt
->type
.localp
)
6811 /* This is a duplicate of a global type, so it must be
6817 nt
= (struct ieee_name_type
*) xmalloc (sizeof *nt
);
6818 memset (nt
, 0, sizeof *nt
);
6821 nt
->type
.name
= h
->root
.string
;
6822 nt
->type
.indx
= info
->type_indx
;
6823 nt
->type
.localp
= localp
;
6827 nt
->next
= h
->types
;
6830 if (! ieee_push_type (info
, nt
->type
.indx
, 0, FALSE
, localp
))
6833 info
->type_stack
->type
.name
= h
->root
.string
;
6838 /* Output a typedef. */
6841 ieee_typdef (p
, name
)
6845 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
6846 struct ieee_write_type type
;
6850 struct ieee_name_type_hash_entry
*h
;
6851 struct ieee_name_type
*nt
;
6853 type
= info
->type_stack
->type
;
6856 /* If this is a simple builtin type using a builtin name, we don't
6857 want to output the typedef itself. We also want to change the
6858 type index to correspond to the name being used. We recognize
6859 names used in stabs debugging output even if they don't exactly
6860 correspond to the names used for the IEEE builtin types. */
6862 if (indx
<= (unsigned int) builtin_bcd_float
)
6864 switch ((enum builtin_types
) indx
)
6870 if (strcmp (name
, "void") == 0)
6874 case builtin_signed_char
:
6876 if (strcmp (name
, "signed char") == 0)
6878 indx
= (unsigned int) builtin_signed_char
;
6881 else if (strcmp (name
, "char") == 0)
6883 indx
= (unsigned int) builtin_char
;
6888 case builtin_unsigned_char
:
6889 if (strcmp (name
, "unsigned char") == 0)
6893 case builtin_signed_short_int
:
6895 case builtin_short_int
:
6896 case builtin_signed_short
:
6897 if (strcmp (name
, "signed short int") == 0)
6899 indx
= (unsigned int) builtin_signed_short_int
;
6902 else if (strcmp (name
, "short") == 0)
6904 indx
= (unsigned int) builtin_short
;
6907 else if (strcmp (name
, "short int") == 0)
6909 indx
= (unsigned int) builtin_short_int
;
6912 else if (strcmp (name
, "signed short") == 0)
6914 indx
= (unsigned int) builtin_signed_short
;
6919 case builtin_unsigned_short_int
:
6920 case builtin_unsigned_short
:
6921 if (strcmp (name
, "unsigned short int") == 0
6922 || strcmp (name
, "short unsigned int") == 0)
6924 indx
= builtin_unsigned_short_int
;
6927 else if (strcmp (name
, "unsigned short") == 0)
6929 indx
= builtin_unsigned_short
;
6934 case builtin_signed_long
:
6935 case builtin_int
: /* FIXME: Size depends upon architecture. */
6937 if (strcmp (name
, "signed long") == 0)
6939 indx
= builtin_signed_long
;
6942 else if (strcmp (name
, "int") == 0)
6947 else if (strcmp (name
, "long") == 0
6948 || strcmp (name
, "long int") == 0)
6950 indx
= builtin_long
;
6955 case builtin_unsigned_long
:
6956 case builtin_unsigned
: /* FIXME: Size depends upon architecture. */
6957 case builtin_unsigned_int
: /* FIXME: Like builtin_unsigned. */
6958 if (strcmp (name
, "unsigned long") == 0
6959 || strcmp (name
, "long unsigned int") == 0)
6961 indx
= builtin_unsigned_long
;
6964 else if (strcmp (name
, "unsigned") == 0)
6966 indx
= builtin_unsigned
;
6969 else if (strcmp (name
, "unsigned int") == 0)
6971 indx
= builtin_unsigned_int
;
6976 case builtin_signed_long_long
:
6977 if (strcmp (name
, "signed long long") == 0
6978 || strcmp (name
, "long long int") == 0)
6982 case builtin_unsigned_long_long
:
6983 if (strcmp (name
, "unsigned long long") == 0
6984 || strcmp (name
, "long long unsigned int") == 0)
6989 if (strcmp (name
, "float") == 0)
6993 case builtin_double
:
6994 if (strcmp (name
, "double") == 0)
6998 case builtin_long_double
:
6999 if (strcmp (name
, "long double") == 0)
7003 case builtin_long_long_double
:
7004 if (strcmp (name
, "long long double") == 0)
7013 h
= ieee_name_type_hash_lookup (&info
->typedefs
, name
, TRUE
, FALSE
);
7017 /* See if we have already defined this type with this name. */
7018 localp
= type
.localp
;
7019 for (nt
= h
->types
; nt
!= NULL
; nt
= nt
->next
)
7023 /* If this is a global definition, then we don't need to
7024 do anything here. */
7025 if (! nt
->type
.localp
)
7027 ieee_pop_unused_type (info
);
7033 /* This is a duplicate definition, so make this one local. */
7038 /* We need to add a new typedef for this type. */
7040 nt
= (struct ieee_name_type
*) xmalloc (sizeof *nt
);
7041 memset (nt
, 0, sizeof *nt
);
7044 nt
->type
.name
= name
;
7045 nt
->type
.localp
= localp
;
7046 nt
->kind
= DEBUG_KIND_ILLEGAL
;
7048 nt
->next
= h
->types
;
7053 /* This is one of the builtin typedefs, so we don't need to
7054 actually define it. */
7055 ieee_pop_unused_type (info
);
7059 indx
= ieee_pop_type (info
);
7061 if (! ieee_define_named_type (info
, name
, (unsigned int) -1, type
.size
,
7062 type
.unsignedp
, localp
,
7063 (struct ieee_buflist
*) NULL
)
7064 || ! ieee_write_number (info
, 'T')
7065 || ! ieee_write_number (info
, indx
))
7068 /* Remove the type we just added to the type stack. This should not
7069 be ieee_pop_unused_type, since the type is used, we just don't
7071 (void) ieee_pop_type (info
);
7076 /* Output a tag for a type. We don't have to do anything here. */
7081 const char *name ATTRIBUTE_UNUSED
;
7083 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
7085 /* This should not be ieee_pop_unused_type, since we want the type
7087 (void) ieee_pop_type (info
);
7091 /* Output an integer constant. */
7094 ieee_int_constant (p
, name
, val
)
7095 PTR p ATTRIBUTE_UNUSED
;
7096 const char *name ATTRIBUTE_UNUSED
;
7097 bfd_vma val ATTRIBUTE_UNUSED
;
7103 /* Output a floating point constant. */
7106 ieee_float_constant (p
, name
, val
)
7107 PTR p ATTRIBUTE_UNUSED
;
7108 const char *name ATTRIBUTE_UNUSED
;
7109 double val ATTRIBUTE_UNUSED
;
7115 /* Output a typed constant. */
7118 ieee_typed_constant (p
, name
, val
)
7120 const char *name ATTRIBUTE_UNUSED
;
7121 bfd_vma val ATTRIBUTE_UNUSED
;
7123 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
7126 ieee_pop_unused_type (info
);
7130 /* Output a variable. */
7133 ieee_variable (p
, name
, kind
, val
)
7136 enum debug_var_kind kind
;
7139 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
7140 unsigned int name_indx
;
7142 bfd_boolean referencep
;
7143 unsigned int type_indx
;
7147 size
= info
->type_stack
->type
.size
;
7148 referencep
= info
->type_stack
->type
.referencep
;
7149 type_indx
= ieee_pop_type (info
);
7151 assert (! ieee_buffer_emptyp (&info
->vars
));
7152 if (! ieee_change_buffer (info
, &info
->vars
))
7155 name_indx
= info
->name_indx
;
7158 /* Write out an NN and an ATN record for this variable. */
7159 if (! ieee_write_byte (info
, (int) ieee_nn_record
)
7160 || ! ieee_write_number (info
, name_indx
)
7161 || ! ieee_write_id (info
, name
)
7162 || ! ieee_write_2bytes (info
, (int) ieee_atn_record_enum
)
7163 || ! ieee_write_number (info
, name_indx
)
7164 || ! ieee_write_number (info
, type_indx
))
7172 if (! ieee_write_number (info
, 8)
7173 || ! ieee_add_range (info
, FALSE
, val
, val
+ size
))
7179 if (! ieee_write_number (info
, 3)
7180 || ! ieee_add_range (info
, FALSE
, val
, val
+ size
))
7185 case DEBUG_LOCAL_STATIC
:
7186 if (! ieee_write_number (info
, 3)
7187 || ! ieee_add_range (info
, FALSE
, val
, val
+ size
))
7193 if (! ieee_write_number (info
, 1)
7194 || ! ieee_write_number (info
, val
))
7199 case DEBUG_REGISTER
:
7200 if (! ieee_write_number (info
, 2)
7201 || ! ieee_write_number (info
,
7202 ieee_genreg_to_regno (info
->abfd
, val
)))
7211 if (! ieee_write_asn (info
, name_indx
, val
))
7215 /* If this is really a reference type, then we just output it with
7216 pointer type, and must now output a C++ record indicating that it
7217 is really reference type. */
7222 nindx
= info
->name_indx
;
7225 /* If this is a global variable, we want to output the misc
7226 record in the C++ misc record block. Otherwise, we want to
7227 output it just after the variable definition, which is where
7228 the current buffer is. */
7231 if (! ieee_change_buffer (info
, &info
->cxx
))
7235 if (! ieee_write_byte (info
, (int) ieee_nn_record
)
7236 || ! ieee_write_number (info
, nindx
)
7237 || ! ieee_write_id (info
, "")
7238 || ! ieee_write_2bytes (info
, (int) ieee_atn_record_enum
)
7239 || ! ieee_write_number (info
, nindx
)
7240 || ! ieee_write_number (info
, 0)
7241 || ! ieee_write_number (info
, 62)
7242 || ! ieee_write_number (info
, 80)
7243 || ! ieee_write_number (info
, 3)
7244 || ! ieee_write_asn (info
, nindx
, 'R')
7245 || ! ieee_write_asn (info
, nindx
, refflag
)
7246 || ! ieee_write_atn65 (info
, nindx
, name
))
7253 /* Start outputting information for a function. */
7256 ieee_start_function (p
, name
, global
)
7261 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
7262 bfd_boolean referencep
;
7263 unsigned int retindx
, typeindx
;
7265 referencep
= info
->type_stack
->type
.referencep
;
7266 retindx
= ieee_pop_type (info
);
7268 /* Besides recording a BB4 or BB6 block, we record the type of the
7269 function in the BB1 typedef block. We can't write out the full
7270 type until we have seen all the parameters, so we accumulate it
7271 in info->fntype and info->fnargs. */
7272 if (! ieee_buffer_emptyp (&info
->fntype
))
7274 /* FIXME: This might happen someday if we support nested
7279 info
->fnname
= name
;
7281 /* An attribute of 0x40 means that the push mask is unknown. */
7282 if (! ieee_define_named_type (info
, name
, (unsigned int) -1, 0, FALSE
, TRUE
,
7284 || ! ieee_write_number (info
, 'x')
7285 || ! ieee_write_number (info
, 0x40)
7286 || ! ieee_write_number (info
, 0)
7287 || ! ieee_write_number (info
, 0)
7288 || ! ieee_write_number (info
, retindx
))
7291 typeindx
= ieee_pop_type (info
);
7293 if (! ieee_init_buffer (info
, &info
->fnargs
))
7295 info
->fnargcount
= 0;
7297 /* If the function return value is actually a reference type, we
7298 must add a record indicating that. */
7303 nindx
= info
->name_indx
;
7305 if (! ieee_change_buffer (info
, &info
->cxx
)
7306 || ! ieee_write_byte (info
, (int) ieee_nn_record
)
7307 || ! ieee_write_number (info
, nindx
)
7308 || ! ieee_write_id (info
, "")
7309 || ! ieee_write_2bytes (info
, (int) ieee_atn_record_enum
)
7310 || ! ieee_write_number (info
, nindx
)
7311 || ! ieee_write_number (info
, 0)
7312 || ! ieee_write_number (info
, 62)
7313 || ! ieee_write_number (info
, 80)
7314 || ! ieee_write_number (info
, 3)
7315 || ! ieee_write_asn (info
, nindx
, 'R')
7316 || ! ieee_write_asn (info
, nindx
, global
? 0 : 1)
7317 || ! ieee_write_atn65 (info
, nindx
, name
))
7321 assert (! ieee_buffer_emptyp (&info
->vars
));
7322 if (! ieee_change_buffer (info
, &info
->vars
))
7325 /* The address is written out as the first block. */
7327 ++info
->block_depth
;
7329 return (ieee_write_byte (info
, (int) ieee_bb_record_enum
)
7330 && ieee_write_byte (info
, global
? 4 : 6)
7331 && ieee_write_number (info
, 0)
7332 && ieee_write_id (info
, name
)
7333 && ieee_write_number (info
, 0)
7334 && ieee_write_number (info
, typeindx
));
7337 /* Add a function parameter. This will normally be called before the
7338 first block, so we postpone them until we see the block. */
7341 ieee_function_parameter (p
, name
, kind
, val
)
7344 enum debug_parm_kind kind
;
7347 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
7348 struct ieee_pending_parm
*m
, **pm
;
7350 assert (info
->block_depth
== 1);
7352 m
= (struct ieee_pending_parm
*) xmalloc (sizeof *m
);
7353 memset (m
, 0, sizeof *m
);
7357 m
->referencep
= info
->type_stack
->type
.referencep
;
7358 m
->type
= ieee_pop_type (info
);
7362 for (pm
= &info
->pending_parms
; *pm
!= NULL
; pm
= &(*pm
)->next
)
7366 /* Add the type to the fnargs list. */
7367 if (! ieee_change_buffer (info
, &info
->fnargs
)
7368 || ! ieee_write_number (info
, m
->type
))
7375 /* Output pending function parameters. */
7378 ieee_output_pending_parms (info
)
7379 struct ieee_handle
*info
;
7381 struct ieee_pending_parm
*m
;
7382 unsigned int refcount
;
7385 for (m
= info
->pending_parms
; m
!= NULL
; m
= m
->next
)
7387 enum debug_var_kind vkind
;
7394 case DEBUG_PARM_STACK
:
7395 case DEBUG_PARM_REFERENCE
:
7396 vkind
= DEBUG_LOCAL
;
7398 case DEBUG_PARM_REG
:
7399 case DEBUG_PARM_REF_REG
:
7400 vkind
= DEBUG_REGISTER
;
7404 if (! ieee_push_type (info
, m
->type
, 0, FALSE
, FALSE
))
7406 info
->type_stack
->type
.referencep
= m
->referencep
;
7409 if (! ieee_variable ((PTR
) info
, m
->name
, vkind
, m
->val
))
7413 /* If there are any reference parameters, we need to output a
7414 miscellaneous record indicating them. */
7417 unsigned int nindx
, varindx
;
7419 /* FIXME: The MRI compiler outputs the demangled function name
7420 here, but we are outputting the mangled name. */
7421 nindx
= info
->name_indx
;
7423 if (! ieee_change_buffer (info
, &info
->vars
)
7424 || ! ieee_write_byte (info
, (int) ieee_nn_record
)
7425 || ! ieee_write_number (info
, nindx
)
7426 || ! ieee_write_id (info
, "")
7427 || ! ieee_write_2bytes (info
, (int) ieee_atn_record_enum
)
7428 || ! ieee_write_number (info
, nindx
)
7429 || ! ieee_write_number (info
, 0)
7430 || ! ieee_write_number (info
, 62)
7431 || ! ieee_write_number (info
, 80)
7432 || ! ieee_write_number (info
, refcount
+ 3)
7433 || ! ieee_write_asn (info
, nindx
, 'B')
7434 || ! ieee_write_atn65 (info
, nindx
, info
->fnname
)
7435 || ! ieee_write_asn (info
, nindx
, 0))
7437 for (m
= info
->pending_parms
, varindx
= 1;
7439 m
= m
->next
, varindx
++)
7443 if (! ieee_write_asn (info
, nindx
, varindx
))
7449 m
= info
->pending_parms
;
7452 struct ieee_pending_parm
*next
;
7459 info
->pending_parms
= NULL
;
7464 /* Start a block. If this is the first block, we output the address
7465 to finish the BB4 or BB6, and then output the function parameters. */
7468 ieee_start_block (p
, addr
)
7472 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
7474 if (! ieee_change_buffer (info
, &info
->vars
))
7477 if (info
->block_depth
== 1)
7479 if (! ieee_write_number (info
, addr
)
7480 || ! ieee_output_pending_parms (info
))
7485 if (! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
7486 || ! ieee_write_byte (info
, 6)
7487 || ! ieee_write_number (info
, 0)
7488 || ! ieee_write_id (info
, "")
7489 || ! ieee_write_number (info
, 0)
7490 || ! ieee_write_number (info
, 0)
7491 || ! ieee_write_number (info
, addr
))
7495 if (! ieee_start_range (info
, addr
))
7498 ++info
->block_depth
;
7506 ieee_end_block (p
, addr
)
7510 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
7512 /* The address we are given is the end of the block, but IEEE seems
7513 to want to the address of the last byte in the block, so we
7515 if (! ieee_change_buffer (info
, &info
->vars
)
7516 || ! ieee_write_byte (info
, (int) ieee_be_record_enum
)
7517 || ! ieee_write_number (info
, addr
- 1))
7520 if (! ieee_end_range (info
, addr
))
7523 --info
->block_depth
;
7525 if (addr
> info
->highaddr
)
7526 info
->highaddr
= addr
;
7531 /* End a function. */
7534 ieee_end_function (p
)
7537 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
7539 assert (info
->block_depth
== 1);
7541 --info
->block_depth
;
7543 /* Now we can finish up fntype, and add it to the typdef section.
7544 At this point, fntype is the 'x' type up to the argument count,
7545 and fnargs is the argument types. We must add the argument
7546 count, and we must add the level. FIXME: We don't record varargs
7547 functions correctly. In fact, stabs debugging does not give us
7548 enough information to do so. */
7549 if (! ieee_change_buffer (info
, &info
->fntype
)
7550 || ! ieee_write_number (info
, info
->fnargcount
)
7551 || ! ieee_change_buffer (info
, &info
->fnargs
)
7552 || ! ieee_write_number (info
, 0))
7555 /* Make sure the typdef block has been started. */
7556 if (ieee_buffer_emptyp (&info
->types
))
7558 if (! ieee_change_buffer (info
, &info
->types
)
7559 || ! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
7560 || ! ieee_write_byte (info
, 1)
7561 || ! ieee_write_number (info
, 0)
7562 || ! ieee_write_id (info
, info
->modname
))
7566 if (! ieee_append_buffer (info
, &info
->types
, &info
->fntype
)
7567 || ! ieee_append_buffer (info
, &info
->types
, &info
->fnargs
))
7570 info
->fnname
= NULL
;
7571 if (! ieee_init_buffer (info
, &info
->fntype
)
7572 || ! ieee_init_buffer (info
, &info
->fnargs
))
7574 info
->fnargcount
= 0;
7579 /* Record line number information. */
7582 ieee_lineno (p
, filename
, lineno
, addr
)
7584 const char *filename
;
7585 unsigned long lineno
;
7588 struct ieee_handle
*info
= (struct ieee_handle
*) p
;
7590 assert (info
->filename
!= NULL
);
7592 /* The HP simulator seems to get confused when more than one line is
7593 listed for the same address, at least if they are in different
7594 files. We handle this by always listing the last line for a
7595 given address, since that seems to be the one that gdb uses. */
7596 if (info
->pending_lineno_filename
!= NULL
7597 && addr
!= info
->pending_lineno_addr
)
7599 /* Make sure we have a line number block. */
7600 if (! ieee_buffer_emptyp (&info
->linenos
))
7602 if (! ieee_change_buffer (info
, &info
->linenos
))
7607 info
->lineno_name_indx
= info
->name_indx
;
7609 if (! ieee_change_buffer (info
, &info
->linenos
)
7610 || ! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
7611 || ! ieee_write_byte (info
, 5)
7612 || ! ieee_write_number (info
, 0)
7613 || ! ieee_write_id (info
, info
->filename
)
7614 || ! ieee_write_byte (info
, (int) ieee_nn_record
)
7615 || ! ieee_write_number (info
, info
->lineno_name_indx
)
7616 || ! ieee_write_id (info
, ""))
7618 info
->lineno_filename
= info
->filename
;
7621 if (strcmp (info
->pending_lineno_filename
, info
->lineno_filename
) != 0)
7623 if (strcmp (info
->filename
, info
->lineno_filename
) != 0)
7625 /* We were not in the main file. Close the block for the
7627 if (! ieee_write_byte (info
, (int) ieee_be_record_enum
))
7629 if (strcmp (info
->filename
, info
->pending_lineno_filename
) == 0)
7631 /* We need a new NN record, and we aren't about to
7633 info
->lineno_name_indx
= info
->name_indx
;
7635 if (! ieee_write_byte (info
, (int) ieee_nn_record
)
7636 || ! ieee_write_number (info
, info
->lineno_name_indx
)
7637 || ! ieee_write_id (info
, ""))
7641 if (strcmp (info
->filename
, info
->pending_lineno_filename
) != 0)
7643 /* We are not changing to the main file. Open a block for
7644 the new included file. */
7645 info
->lineno_name_indx
= info
->name_indx
;
7647 if (! ieee_write_byte (info
, (int) ieee_bb_record_enum
)
7648 || ! ieee_write_byte (info
, 5)
7649 || ! ieee_write_number (info
, 0)
7650 || ! ieee_write_id (info
, info
->pending_lineno_filename
)
7651 || ! ieee_write_byte (info
, (int) ieee_nn_record
)
7652 || ! ieee_write_number (info
, info
->lineno_name_indx
)
7653 || ! ieee_write_id (info
, ""))
7656 info
->lineno_filename
= info
->pending_lineno_filename
;
7659 if (! ieee_write_2bytes (info
, (int) ieee_atn_record_enum
)
7660 || ! ieee_write_number (info
, info
->lineno_name_indx
)
7661 || ! ieee_write_number (info
, 0)
7662 || ! ieee_write_number (info
, 7)
7663 || ! ieee_write_number (info
, info
->pending_lineno
)
7664 || ! ieee_write_number (info
, 0)
7665 || ! ieee_write_asn (info
, info
->lineno_name_indx
,
7666 info
->pending_lineno_addr
))
7670 info
->pending_lineno_filename
= filename
;
7671 info
->pending_lineno
= lineno
;
7672 info
->pending_lineno_addr
= addr
;