source: trunk/src/binutils/binutils/ieee.c@ 10

Last change on this file since 10 was 10, checked in by bird, 22 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 189.3 KB
Line 
1/* ieee.c -- Read and write IEEE-695 debugging information.
2 Copyright 1996, 1998, 2000, 2001 Free Software Foundation, Inc.
3 Written by Ian Lance Taylor <ian@cygnus.com>.
4
5 This file is part of GNU Binutils.
6
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.
11
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.
16
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
20 02111-1307, USA. */
21
22/* This file reads and writes IEEE-695 debugging information. */
23
24#include <stdio.h>
25#include <assert.h>
26
27#include "bfd.h"
28#include "ieee.h"
29#include "bucomm.h"
30#include "libiberty.h"
31#include "debug.h"
32#include "budbg.h"
33#include "filenames.h"
34
35/* This structure holds an entry on the block stack. */
36
37struct ieee_block
38{
39 /* The kind of block. */
40 int kind;
41 /* The source file name, for a BB5 block. */
42 const char *filename;
43 /* The index of the function type, for a BB4 or BB6 block. */
44 unsigned int fnindx;
45 /* True if this function is being skipped. */
46 boolean skip;
47};
48
49/* This structure is the block stack. */
50
51#define BLOCKSTACK_SIZE (16)
52
53struct ieee_blockstack
54{
55 /* The stack pointer. */
56 struct ieee_block *bsp;
57 /* The stack. */
58 struct ieee_block stack[BLOCKSTACK_SIZE];
59};
60
61/* This structure holds information for a variable. */
62
63struct ieee_var
64{
65 /* Start of name. */
66 const char *name;
67 /* Length of name. */
68 unsigned long namlen;
69 /* Type. */
70 debug_type type;
71 /* Slot if we make an indirect type. */
72 debug_type *pslot;
73 /* Kind of variable or function. */
74 enum
75 {
76 IEEE_UNKNOWN,
77 IEEE_EXTERNAL,
78 IEEE_GLOBAL,
79 IEEE_STATIC,
80 IEEE_LOCAL,
81 IEEE_FUNCTION
82 } kind;
83};
84
85/* This structure holds all the variables. */
86
87struct ieee_vars
88{
89 /* Number of slots allocated. */
90 unsigned int alloc;
91 /* Variables. */
92 struct ieee_var *vars;
93};
94
95/* This structure holds information for a type. We need this because
96 we don't want to represent bitfields as real types. */
97
98struct ieee_type
99{
100 /* Type. */
101 debug_type type;
102 /* Slot if this is type is referenced before it is defined. */
103 debug_type *pslot;
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;
109};
110
111/* This structure holds all the type information. */
112
113struct ieee_types
114{
115 /* Number of slots allocated. */
116 unsigned int alloc;
117 /* Types. */
118 struct ieee_type *types;
119 /* Builtin types. */
120#define BUILTIN_TYPE_COUNT (60)
121 debug_type builtins[BUILTIN_TYPE_COUNT];
122};
123
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. */
126
127struct ieee_tag
128{
129 /* Next tag. */
130 struct ieee_tag *next;
131 /* This tag name. */
132 const char *name;
133 /* The type of the tag. */
134 debug_type type;
135 /* The tagged type is an indirect type pointing at this slot. */
136 debug_type 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
139 a reference type. */
140 debug_type *fslots;
141};
142
143/* This structure holds the information we pass around to the parsing
144 functions. */
145
146struct ieee_info
147{
148 /* The debugging handle. */
149 PTR dhandle;
150 /* The BFD. */
151 bfd *abfd;
152 /* The start of the bytes to be parsed. */
153 const bfd_byte *bytes;
154 /* The end of the bytes to be parsed. */
155 const bfd_byte *pend;
156 /* The block stack. */
157 struct ieee_blockstack blockstack;
158 /* Whether we have seen a BB1 or BB2. */
159 boolean saw_filename;
160 /* The variables. */
161 struct ieee_vars vars;
162 /* The global variables, after a global typedef block. */
163 struct ieee_vars *global_vars;
164 /* The types. */
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;
170};
171
172/* Basic builtin types, not including the pointers. */
173
174enum builtin_types
175{
176 builtin_unknown = 0,
177 builtin_void = 1,
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,
186 builtin_float = 10,
187 builtin_double = 11,
188 builtin_long_double = 12,
189 builtin_long_long_double = 13,
190 builtin_quoted_string = 14,
191 builtin_instruction_address = 15,
192 builtin_int = 16,
193 builtin_unsigned = 17,
194 builtin_unsigned_int = 18,
195 builtin_char = 19,
196 builtin_long = 20,
197 builtin_short = 21,
198 builtin_unsigned_short = 22,
199 builtin_short_int = 23,
200 builtin_signed_short = 24,
201 builtin_bcd_float = 25
202};
203
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. */
207
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)
215
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
219 record. */
220
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)
249
250/* Local functions. */
251
252static void ieee_error
253 PARAMS ((struct ieee_info *, const bfd_byte *, const char *));
254static void ieee_eof PARAMS ((struct ieee_info *));
255static char *savestring PARAMS ((const char *, unsigned long));
256static boolean ieee_read_number
257 PARAMS ((struct ieee_info *, const bfd_byte **, bfd_vma *));
258static boolean ieee_read_optional_number
259 PARAMS ((struct ieee_info *, const bfd_byte **, bfd_vma *, boolean *));
260static boolean ieee_read_id
261 PARAMS ((struct ieee_info *, const bfd_byte **, const char **,
262 unsigned long *));
263static boolean ieee_read_optional_id
264 PARAMS ((struct ieee_info *, const bfd_byte **, const char **,
265 unsigned long *, boolean *));
266static boolean ieee_read_expression
267 PARAMS ((struct ieee_info *, const bfd_byte **, bfd_vma *));
268static debug_type ieee_builtin_type
269 PARAMS ((struct ieee_info *, const bfd_byte *, unsigned int));
270static boolean ieee_alloc_type
271 PARAMS ((struct ieee_info *, unsigned int, boolean));
272static boolean ieee_read_type_index
273 PARAMS ((struct ieee_info *, const bfd_byte **, debug_type *));
274static int ieee_regno_to_genreg PARAMS ((bfd *, int));
275static int ieee_genreg_to_regno PARAMS ((bfd *, int));
276static boolean parse_ieee_bb PARAMS ((struct ieee_info *, const bfd_byte **));
277static boolean parse_ieee_be PARAMS ((struct ieee_info *, const bfd_byte **));
278static boolean parse_ieee_nn PARAMS ((struct ieee_info *, const bfd_byte **));
279static boolean parse_ieee_ty PARAMS ((struct ieee_info *, const bfd_byte **));
280static boolean parse_ieee_atn PARAMS ((struct ieee_info *, const bfd_byte **));
281static boolean ieee_read_cxx_misc
282 PARAMS ((struct ieee_info *, const bfd_byte **, unsigned long));
283static boolean ieee_read_cxx_class
284 PARAMS ((struct ieee_info *, const bfd_byte **, unsigned long));
285static boolean ieee_read_cxx_defaults
286 PARAMS ((struct ieee_info *, const bfd_byte **, unsigned long));
287static boolean ieee_read_reference
288 PARAMS ((struct ieee_info *, const bfd_byte **));
289static boolean ieee_require_asn
290 PARAMS ((struct ieee_info *, const bfd_byte **, bfd_vma *));
291static boolean ieee_require_atn65
292 PARAMS ((struct ieee_info *, const bfd_byte **, const char **,
293 unsigned long *));
294
295/* Report an error in the IEEE debugging information. */
296
297static void
298ieee_error (info, p, s)
299 struct ieee_info *info;
300 const bfd_byte *p;
301 const char *s;
302{
303 if (p != NULL)
304 fprintf (stderr, "%s: 0x%lx: %s (0x%x)\n", bfd_get_filename (info->abfd),
305 (unsigned long) (p - info->bytes), s, *p);
306 else
307 fprintf (stderr, "%s: %s\n", bfd_get_filename (info->abfd), s);
308}
309
310/* Report an unexpected EOF in the IEEE debugging information. */
311
312static void
313ieee_eof (info)
314 struct ieee_info *info;
315{
316 ieee_error (info, (const bfd_byte *) NULL,
317 _("unexpected end of debugging information"));
318}
319
320/* Save a string in memory. */
321
322static char *
323savestring (start, len)
324 const char *start;
325 unsigned long len;
326{
327 char *ret;
328
329 ret = (char *) xmalloc (len + 1);
330 memcpy (ret, start, len);
331 ret[len] = '\0';
332 return ret;
333}
334
335/* Read a number which must be present in an IEEE file. */
336
337static boolean
338ieee_read_number (info, pp, pv)
339 struct ieee_info *info;
340 const bfd_byte **pp;
341 bfd_vma *pv;
342{
343 return ieee_read_optional_number (info, pp, pv, (boolean *) NULL);
344}
345
346/* Read a number in an IEEE file. If ppresent is not NULL, the number
347 need not be there. */
348
349static boolean
350ieee_read_optional_number (info, pp, pv, ppresent)
351 struct ieee_info *info;
352 const bfd_byte **pp;
353 bfd_vma *pv;
354 boolean *ppresent;
355{
356 ieee_record_enum_type b;
357
358 if (*pp >= info->pend)
359 {
360 if (ppresent != NULL)
361 {
362 *ppresent = false;
363 return true;
364 }
365 ieee_eof (info);
366 return false;
367 }
368
369 b = (ieee_record_enum_type) **pp;
370 ++*pp;
371
372 if (b <= ieee_number_end_enum)
373 {
374 *pv = (bfd_vma) b;
375 if (ppresent != NULL)
376 *ppresent = true;
377 return true;
378 }
379
380 if (b >= ieee_number_repeat_start_enum && b <= ieee_number_repeat_end_enum)
381 {
382 unsigned int i;
383
384 i = (int) b - (int) ieee_number_repeat_start_enum;
385 if (*pp + i - 1 >= info->pend)
386 {
387 ieee_eof (info);
388 return false;
389 }
390
391 *pv = 0;
392 for (; i > 0; i--)
393 {
394 *pv <<= 8;
395 *pv += **pp;
396 ++*pp;
397 }
398
399 if (ppresent != NULL)
400 *ppresent = true;
401
402 return true;
403 }
404
405 if (ppresent != NULL)
406 {
407 --*pp;
408 *ppresent = false;
409 return true;
410 }
411
412 ieee_error (info, *pp - 1, _("invalid number"));
413 return false;
414}
415
416/* Read a required string from an IEEE file. */
417
418static boolean
419ieee_read_id (info, pp, pname, pnamlen)
420 struct ieee_info *info;
421 const bfd_byte **pp;
422 const char **pname;
423 unsigned long *pnamlen;
424{
425 return ieee_read_optional_id (info, pp, pname, pnamlen, (boolean *) NULL);
426}
427
428/* Read a string from an IEEE file. If ppresent is not NULL, the
429 string is optional. */
430
431static boolean
432ieee_read_optional_id (info, pp, pname, pnamlen, ppresent)
433 struct ieee_info *info;
434 const bfd_byte **pp;
435 const char **pname;
436 unsigned long *pnamlen;
437 boolean *ppresent;
438{
439 bfd_byte b;
440 unsigned long len;
441
442 if (*pp >= info->pend)
443 {
444 ieee_eof (info);
445 return false;
446 }
447
448 b = **pp;
449 ++*pp;
450
451 if (b <= 0x7f)
452 len = b;
453 else if ((ieee_record_enum_type) b == ieee_extension_length_1_enum)
454 {
455 len = **pp;
456 ++*pp;
457 }
458 else if ((ieee_record_enum_type) b == ieee_extension_length_2_enum)
459 {
460 len = (**pp << 8) + (*pp)[1];
461 *pp += 2;
462 }
463 else
464 {
465 if (ppresent != NULL)
466 {
467 --*pp;
468 *ppresent = false;
469 return true;
470 }
471 ieee_error (info, *pp - 1, _("invalid string length"));
472 return false;
473 }
474
475 if ((unsigned long) (info->pend - *pp) < len)
476 {
477 ieee_eof (info);
478 return false;
479 }
480
481 *pname = (const char *) *pp;
482 *pnamlen = len;
483 *pp += len;
484
485 if (ppresent != NULL)
486 *ppresent = true;
487
488 return true;
489}
490
491/* Read an expression from an IEEE file. Since this code is only used
492 to parse debugging information, I haven't bothered to write a full
493 blown IEEE expression parser. I've only thrown in the things I've
494 seen in debugging information. This can be easily extended if
495 necessary. */
496
497static boolean
498ieee_read_expression (info, pp, pv)
499 struct ieee_info *info;
500 const bfd_byte **pp;
501 bfd_vma *pv;
502{
503 const bfd_byte *expr_start;
504#define EXPR_STACK_SIZE (10)
505 bfd_vma expr_stack[EXPR_STACK_SIZE];
506 bfd_vma *esp;
507
508 expr_start = *pp;
509
510 esp = expr_stack;
511
512 while (1)
513 {
514 const bfd_byte *start;
515 bfd_vma val;
516 boolean present;
517 ieee_record_enum_type c;
518
519 start = *pp;
520
521 if (! ieee_read_optional_number (info, pp, &val, &present))
522 return false;
523
524 if (present)
525 {
526 if (esp - expr_stack >= EXPR_STACK_SIZE)
527 {
528 ieee_error (info, start, _("expression stack overflow"));
529 return false;
530 }
531 *esp++ = val;
532 continue;
533 }
534
535 c = (ieee_record_enum_type) **pp;
536
537 if (c >= ieee_module_beginning_enum)
538 break;
539
540 ++*pp;
541
542 if (c == ieee_comma)
543 break;
544
545 switch (c)
546 {
547 default:
548 ieee_error (info, start, _("unsupported IEEE expression operator"));
549 break;
550
551 case ieee_variable_R_enum:
552 {
553 bfd_vma indx;
554 asection *s;
555
556 if (! ieee_read_number (info, pp, &indx))
557 return false;
558 for (s = info->abfd->sections; s != NULL; s = s->next)
559 if ((bfd_vma) s->target_index == indx)
560 break;
561 if (s == NULL)
562 {
563 ieee_error (info, start, _("unknown section"));
564 return false;
565 }
566
567 if (esp - expr_stack >= EXPR_STACK_SIZE)
568 {
569 ieee_error (info, start, _("expression stack overflow"));
570 return false;
571 }
572
573 *esp++ = bfd_get_section_vma (info->abfd, s);
574 }
575 break;
576
577 case ieee_function_plus_enum:
578 case ieee_function_minus_enum:
579 {
580 bfd_vma v1, v2;
581
582 if (esp - expr_stack < 2)
583 {
584 ieee_error (info, start, _("expression stack underflow"));
585 return false;
586 }
587
588 v1 = *--esp;
589 v2 = *--esp;
590 *esp++ = v1 + v2;
591 }
592 break;
593 }
594 }
595
596 if (esp - 1 != expr_stack)
597 {
598 ieee_error (info, expr_start, _("expression stack mismatch"));
599 return false;
600 }
601
602 *pv = *--esp;
603
604 return true;
605}
606
607/* Return an IEEE builtin type. */
608
609static debug_type
610ieee_builtin_type (info, p, indx)
611 struct ieee_info *info;
612 const bfd_byte *p;
613 unsigned int indx;
614{
615 PTR dhandle;
616 debug_type type;
617 const char *name;
618
619 if (indx < BUILTIN_TYPE_COUNT
620 && info->types.builtins[indx] != DEBUG_TYPE_NULL)
621 return info->types.builtins[indx];
622
623 dhandle = info->dhandle;
624
625 if (indx >= 32 && indx < 64)
626 {
627 type = debug_make_pointer_type (dhandle,
628 ieee_builtin_type (info, p, indx - 32));
629 assert (indx < BUILTIN_TYPE_COUNT);
630 info->types.builtins[indx] = type;
631 return type;
632 }
633
634 switch ((enum builtin_types) indx)
635 {
636 default:
637 ieee_error (info, p, _("unknown builtin type"));
638 return NULL;
639
640 case builtin_unknown:
641 type = debug_make_void_type (dhandle);
642 name = NULL;
643 break;
644
645 case builtin_void:
646 type = debug_make_void_type (dhandle);
647 name = "void";
648 break;
649
650 case builtin_signed_char:
651 type = debug_make_int_type (dhandle, 1, false);
652 name = "signed char";
653 break;
654
655 case builtin_unsigned_char:
656 type = debug_make_int_type (dhandle, 1, true);
657 name = "unsigned char";
658 break;
659
660 case builtin_signed_short_int:
661 type = debug_make_int_type (dhandle, 2, false);
662 name = "signed short int";
663 break;
664
665 case builtin_unsigned_short_int:
666 type = debug_make_int_type (dhandle, 2, true);
667 name = "unsigned short int";
668 break;
669
670 case builtin_signed_long:
671 type = debug_make_int_type (dhandle, 4, false);
672 name = "signed long";
673 break;
674
675 case builtin_unsigned_long:
676 type = debug_make_int_type (dhandle, 4, true);
677 name = "unsigned long";
678 break;
679
680 case builtin_signed_long_long:
681 type = debug_make_int_type (dhandle, 8, false);
682 name = "signed long long";
683 break;
684
685 case builtin_unsigned_long_long:
686 type = debug_make_int_type (dhandle, 8, true);
687 name = "unsigned long long";
688 break;
689
690 case builtin_float:
691 type = debug_make_float_type (dhandle, 4);
692 name = "float";
693 break;
694
695 case builtin_double:
696 type = debug_make_float_type (dhandle, 8);
697 name = "double";
698 break;
699
700 case builtin_long_double:
701 /* FIXME: The size for this type should depend upon the
702 processor. */
703 type = debug_make_float_type (dhandle, 12);
704 name = "long double";
705 break;
706
707 case builtin_long_long_double:
708 type = debug_make_float_type (dhandle, 16);
709 name = "long long double";
710 break;
711
712 case builtin_quoted_string:
713 type = debug_make_array_type (dhandle,
714 ieee_builtin_type (info, p,
715 ((unsigned int)
716 builtin_char)),
717 ieee_builtin_type (info, p,
718 ((unsigned int)
719 builtin_int)),
720 0, -1, true);
721 name = "QUOTED STRING";
722 break;
723
724 case builtin_instruction_address:
725 /* FIXME: This should be a code address. */
726 type = debug_make_int_type (dhandle, 4, true);
727 name = "instruction address";
728 break;
729
730 case builtin_int:
731 /* FIXME: The size for this type should depend upon the
732 processor. */
733 type = debug_make_int_type (dhandle, 4, false);
734 name = "int";
735 break;
736
737 case builtin_unsigned:
738 /* FIXME: The size for this type should depend upon the
739 processor. */
740 type = debug_make_int_type (dhandle, 4, true);
741 name = "unsigned";
742 break;
743
744 case builtin_unsigned_int:
745 /* FIXME: The size for this type should depend upon the
746 processor. */
747 type = debug_make_int_type (dhandle, 4, true);
748 name = "unsigned int";
749 break;
750
751 case builtin_char:
752 type = debug_make_int_type (dhandle, 1, false);
753 name = "char";
754 break;
755
756 case builtin_long:
757 type = debug_make_int_type (dhandle, 4, false);
758 name = "long";
759 break;
760
761 case builtin_short:
762 type = debug_make_int_type (dhandle, 2, false);
763 name = "short";
764 break;
765
766 case builtin_unsigned_short:
767 type = debug_make_int_type (dhandle, 2, true);
768 name = "unsigned short";
769 break;
770
771 case builtin_short_int:
772 type = debug_make_int_type (dhandle, 2, false);
773 name = "short int";
774 break;
775
776 case builtin_signed_short:
777 type = debug_make_int_type (dhandle, 2, false);
778 name = "signed short";
779 break;
780
781 case builtin_bcd_float:
782 ieee_error (info, p, _("BCD float type not supported"));
783 return DEBUG_TYPE_NULL;
784 }
785
786 if (name != NULL)
787 type = debug_name_type (dhandle, name, type);
788
789 assert (indx < BUILTIN_TYPE_COUNT);
790
791 info->types.builtins[indx] = type;
792
793 return type;
794}
795
796/* Allocate more space in the type table. If ref is true, this is a
797 reference to the type; if it is not already defined, we should set
798 up an indirect type. */
799
800static boolean
801ieee_alloc_type (info, indx, ref)
802 struct ieee_info *info;
803 unsigned int indx;
804 boolean ref;
805{
806 unsigned int nalloc;
807 register struct ieee_type *t;
808 struct ieee_type *tend;
809
810 if (indx >= info->types.alloc)
811 {
812 nalloc = info->types.alloc;
813 if (nalloc == 0)
814 nalloc = 4;
815 while (indx >= nalloc)
816 nalloc *= 2;
817
818 info->types.types = ((struct ieee_type *)
819 xrealloc (info->types.types,
820 nalloc * sizeof *info->types.types));
821
822 memset (info->types.types + info->types.alloc, 0,
823 (nalloc - info->types.alloc) * sizeof *info->types.types);
824
825 tend = info->types.types + nalloc;
826 for (t = info->types.types + info->types.alloc; t < tend; t++)
827 t->type = DEBUG_TYPE_NULL;
828
829 info->types.alloc = nalloc;
830 }
831
832 if (ref)
833 {
834 t = info->types.types + indx;
835 if (t->type == NULL)
836 {
837 t->pslot = (debug_type *) xmalloc (sizeof *t->pslot);
838 *t->pslot = DEBUG_TYPE_NULL;
839 t->type = debug_make_indirect_type (info->dhandle, t->pslot,
840 (const char *) NULL);
841 if (t->type == NULL)
842 return false;
843 }
844 }
845
846 return true;
847}
848
849/* Read a type index and return the corresponding type. */
850
851static boolean
852ieee_read_type_index (info, pp, ptype)
853 struct ieee_info *info;
854 const bfd_byte **pp;
855 debug_type *ptype;
856{
857 const bfd_byte *start;
858 bfd_vma indx;
859
860 start = *pp;
861
862 if (! ieee_read_number (info, pp, &indx))
863 return false;
864
865 if (indx < 256)
866 {
867 *ptype = ieee_builtin_type (info, start, indx);
868 if (*ptype == NULL)
869 return false;
870 return true;
871 }
872
873 indx -= 256;
874 if (! ieee_alloc_type (info, indx, true))
875 return false;
876
877 *ptype = info->types.types[indx].type;
878
879 return true;
880}
881
882/* Parse IEEE debugging information for a file. This is passed the
883 bytes which compose the Debug Information Part of an IEEE file. */
884
885boolean
886parse_ieee (dhandle, abfd, bytes, len)
887 PTR dhandle;
888 bfd *abfd;
889 const bfd_byte *bytes;
890 bfd_size_type len;
891{
892 struct ieee_info info;
893 unsigned int i;
894 const bfd_byte *p, *pend;
895
896 info.dhandle = dhandle;
897 info.abfd = abfd;
898 info.bytes = bytes;
899 info.pend = bytes + len;
900 info.blockstack.bsp = info.blockstack.stack;
901 info.saw_filename = false;
902 info.vars.alloc = 0;
903 info.vars.vars = NULL;
904 info.global_vars = NULL;
905 info.types.alloc = 0;
906 info.types.types = NULL;
907 info.global_types = NULL;
908 info.tags = NULL;
909 for (i = 0; i < BUILTIN_TYPE_COUNT; i++)
910 info.types.builtins[i] = DEBUG_TYPE_NULL;
911
912 p = bytes;
913 pend = info.pend;
914 while (p < pend)
915 {
916 const bfd_byte *record_start;
917 ieee_record_enum_type c;
918
919 record_start = p;
920
921 c = (ieee_record_enum_type) *p++;
922
923 if (c == ieee_at_record_enum)
924 c = (ieee_record_enum_type) (((unsigned int) c << 8) | *p++);
925
926 if (c <= ieee_number_repeat_end_enum)
927 {
928 ieee_error (&info, record_start, _("unexpected number"));
929 return false;
930 }
931
932 switch (c)
933 {
934 default:
935 ieee_error (&info, record_start, _("unexpected record type"));
936 return false;
937
938 case ieee_bb_record_enum:
939 if (! parse_ieee_bb (&info, &p))
940 return false;
941 break;
942
943 case ieee_be_record_enum:
944 if (! parse_ieee_be (&info, &p))
945 return false;
946 break;
947
948 case ieee_nn_record:
949 if (! parse_ieee_nn (&info, &p))
950 return false;
951 break;
952
953 case ieee_ty_record_enum:
954 if (! parse_ieee_ty (&info, &p))
955 return false;
956 break;
957
958 case ieee_atn_record_enum:
959 if (! parse_ieee_atn (&info, &p))
960 return false;
961 break;
962 }
963 }
964
965 if (info.blockstack.bsp != info.blockstack.stack)
966 {
967 ieee_error (&info, (const bfd_byte *) NULL,
968 _("blocks left on stack at end"));
969 return false;
970 }
971
972 return true;
973}
974
975/* Handle an IEEE BB record. */
976
977static boolean
978parse_ieee_bb (info, pp)
979 struct ieee_info *info;
980 const bfd_byte **pp;
981{
982 const bfd_byte *block_start;
983 bfd_byte b;
984 bfd_vma size;
985 const char *name;
986 unsigned long namlen;
987 char *namcopy = NULL;
988 unsigned int fnindx;
989 boolean skip;
990
991 block_start = *pp;
992
993 b = **pp;
994 ++*pp;
995
996 if (! ieee_read_number (info, pp, &size)
997 || ! ieee_read_id (info, pp, &name, &namlen))
998 return false;
999
1000 fnindx = (unsigned int) -1;
1001 skip = false;
1002
1003 switch (b)
1004 {
1005 case 1:
1006 /* BB1: Type definitions local to a module. */
1007 namcopy = savestring (name, namlen);
1008 if (namcopy == NULL)
1009 return false;
1010 if (! debug_set_filename (info->dhandle, namcopy))
1011 return false;
1012 info->saw_filename = true;
1013
1014 /* Discard any variables or types we may have seen before. */
1015 if (info->vars.vars != NULL)
1016 free (info->vars.vars);
1017 info->vars.vars = NULL;
1018 info->vars.alloc = 0;
1019 if (info->types.types != NULL)
1020 free (info->types.types);
1021 info->types.types = NULL;
1022 info->types.alloc = 0;
1023
1024 /* Initialize the types to the global types. */
1025 if (info->global_types != NULL)
1026 {
1027 info->types.alloc = info->global_types->alloc;
1028 info->types.types = ((struct ieee_type *)
1029 xmalloc (info->types.alloc
1030 * sizeof (*info->types.types)));
1031 memcpy (info->types.types, info->global_types->types,
1032 info->types.alloc * sizeof (*info->types.types));
1033 }
1034
1035 break;
1036
1037 case 2:
1038 /* BB2: Global type definitions. The name is supposed to be
1039 empty, but we don't check. */
1040 if (! debug_set_filename (info->dhandle, "*global*"))
1041 return false;
1042 info->saw_filename = true;
1043 break;
1044
1045 case 3:
1046 /* BB3: High level module block begin. We don't have to do
1047 anything here. The name is supposed to be the same as for
1048 the BB1, but we don't check. */
1049 break;
1050
1051 case 4:
1052 /* BB4: Global function. */
1053 {
1054 bfd_vma stackspace, typindx, offset;
1055 debug_type return_type;
1056
1057 if (! ieee_read_number (info, pp, &stackspace)
1058 || ! ieee_read_number (info, pp, &typindx)
1059 || ! ieee_read_expression (info, pp, &offset))
1060 return false;
1061
1062 /* We have no way to record the stack space. FIXME. */
1063
1064 if (typindx < 256)
1065 {
1066 return_type = ieee_builtin_type (info, block_start, typindx);
1067 if (return_type == DEBUG_TYPE_NULL)
1068 return false;
1069 }
1070 else
1071 {
1072 typindx -= 256;
1073 if (! ieee_alloc_type (info, typindx, true))
1074 return false;
1075 fnindx = typindx;
1076 return_type = info->types.types[typindx].type;
1077 if (debug_get_type_kind (info->dhandle, return_type)
1078 == DEBUG_KIND_FUNCTION)
1079 return_type = debug_get_return_type (info->dhandle,
1080 return_type);
1081 }
1082
1083 namcopy = savestring (name, namlen);
1084 if (namcopy == NULL)
1085 return false;
1086 if (! debug_record_function (info->dhandle, namcopy, return_type,
1087 true, offset))
1088 return false;
1089 }
1090 break;
1091
1092 case 5:
1093 /* BB5: File name for source line numbers. */
1094 {
1095 unsigned int i;
1096
1097 /* We ignore the date and time. FIXME. */
1098 for (i = 0; i < 6; i++)
1099 {
1100 bfd_vma ignore;
1101 boolean present;
1102
1103 if (! ieee_read_optional_number (info, pp, &ignore, &present))
1104 return false;
1105 if (! present)
1106 break;
1107 }
1108
1109 namcopy = savestring (name, namlen);
1110 if (namcopy == NULL)
1111 return false;
1112 if (! debug_start_source (info->dhandle, namcopy))
1113 return false;
1114 }
1115 break;
1116
1117 case 6:
1118 /* BB6: Local function or block. */
1119 {
1120 bfd_vma stackspace, typindx, offset;
1121
1122 if (! ieee_read_number (info, pp, &stackspace)
1123 || ! ieee_read_number (info, pp, &typindx)
1124 || ! ieee_read_expression (info, pp, &offset))
1125 return false;
1126
1127 /* We have no way to record the stack space. FIXME. */
1128
1129 if (namlen == 0)
1130 {
1131 if (! debug_start_block (info->dhandle, offset))
1132 return false;
1133 /* Change b to indicate that this is a block
1134 rather than a function. */
1135 b = 0x86;
1136 }
1137 else
1138 {
1139 /* The MRI C++ compiler will output a fake function named
1140 __XRYCPP to hold C++ debugging information. We skip
1141 that function. This is not crucial, but it makes
1142 converting from IEEE to other debug formats work
1143 better. */
1144 if (strncmp (name, "__XRYCPP", namlen) == 0)
1145 skip = true;
1146 else
1147 {
1148 debug_type return_type;
1149
1150 if (typindx < 256)
1151 {
1152 return_type = ieee_builtin_type (info, block_start,
1153 typindx);
1154 if (return_type == NULL)
1155 return false;
1156 }
1157 else
1158 {
1159 typindx -= 256;
1160 if (! ieee_alloc_type (info, typindx, true))
1161 return false;
1162 fnindx = typindx;
1163 return_type = info->types.types[typindx].type;
1164 if (debug_get_type_kind (info->dhandle, return_type)
1165 == DEBUG_KIND_FUNCTION)
1166 return_type = debug_get_return_type (info->dhandle,
1167 return_type);
1168 }
1169
1170 namcopy = savestring (name, namlen);
1171 if (namcopy == NULL)
1172 return false;
1173 if (! debug_record_function (info->dhandle, namcopy,
1174 return_type, false, offset))
1175 return false;
1176 }
1177 }
1178 }
1179 break;
1180
1181 case 10:
1182 /* BB10: Assembler module scope. In the normal case, we
1183 completely ignore all this information. FIXME. */
1184 {
1185 const char *inam, *vstr;
1186 unsigned long inamlen, vstrlen;
1187 bfd_vma tool_type;
1188 boolean present;
1189 unsigned int i;
1190
1191 if (! info->saw_filename)
1192 {
1193 namcopy = savestring (name, namlen);
1194 if (namcopy == NULL)
1195 return false;
1196 if (! debug_set_filename (info->dhandle, namcopy))
1197 return false;
1198 info->saw_filename = true;
1199 }
1200
1201 if (! ieee_read_id (info, pp, &inam, &inamlen)
1202 || ! ieee_read_number (info, pp, &tool_type)
1203 || ! ieee_read_optional_id (info, pp, &vstr, &vstrlen, &present))
1204 return false;
1205 for (i = 0; i < 6; i++)
1206 {
1207 bfd_vma ignore;
1208
1209 if (! ieee_read_optional_number (info, pp, &ignore, &present))
1210 return false;
1211 if (! present)
1212 break;
1213 }
1214 }
1215 break;
1216
1217 case 11:
1218 /* BB11: Module section. We completely ignore all this
1219 information. FIXME. */
1220 {
1221 bfd_vma sectype, secindx, offset, map;
1222 boolean present;
1223
1224 if (! ieee_read_number (info, pp, &sectype)
1225 || ! ieee_read_number (info, pp, &secindx)
1226 || ! ieee_read_expression (info, pp, &offset)
1227 || ! ieee_read_optional_number (info, pp, &map, &present))
1228 return false;
1229 }
1230 break;
1231
1232 default:
1233 ieee_error (info, block_start, _("unknown BB type"));
1234 return false;
1235 }
1236
1237
1238 /* Push this block on the block stack. */
1239
1240 if (info->blockstack.bsp >= info->blockstack.stack + BLOCKSTACK_SIZE)
1241 {
1242 ieee_error (info, (const bfd_byte *) NULL, _("stack overflow"));
1243 return false;
1244 }
1245
1246 info->blockstack.bsp->kind = b;
1247 if (b == 5)
1248 info->blockstack.bsp->filename = namcopy;
1249 info->blockstack.bsp->fnindx = fnindx;
1250 info->blockstack.bsp->skip = skip;
1251 ++info->blockstack.bsp;
1252
1253 return true;
1254}
1255
1256/* Handle an IEEE BE record. */
1257
1258static boolean
1259parse_ieee_be (info, pp)
1260 struct ieee_info *info;
1261 const bfd_byte **pp;
1262{
1263 bfd_vma offset;
1264
1265 if (info->blockstack.bsp <= info->blockstack.stack)
1266 {
1267 ieee_error (info, *pp, _("stack underflow"));
1268 return false;
1269 }
1270 --info->blockstack.bsp;
1271
1272 switch (info->blockstack.bsp->kind)
1273 {
1274 case 2:
1275 /* When we end the global typedefs block, we copy out the the
1276 contents of info->vars. This is because the variable indices
1277 may be reused in the local blocks. However, we need to
1278 preserve them so that we can locate a function returning a
1279 reference variable whose type is named in the global typedef
1280 block. */
1281 info->global_vars = ((struct ieee_vars *)
1282 xmalloc (sizeof *info->global_vars));
1283 info->global_vars->alloc = info->vars.alloc;
1284 info->global_vars->vars = ((struct ieee_var *)
1285 xmalloc (info->vars.alloc
1286 * sizeof (*info->vars.vars)));
1287 memcpy (info->global_vars->vars, info->vars.vars,
1288 info->vars.alloc * sizeof (*info->vars.vars));
1289
1290 /* We also copy out the non builtin parts of info->types, since
1291 the types are discarded when we start a new block. */
1292 info->global_types = ((struct ieee_types *)
1293 xmalloc (sizeof *info->global_types));
1294 info->global_types->alloc = info->types.alloc;
1295 info->global_types->types = ((struct ieee_type *)
1296 xmalloc (info->types.alloc
1297 * sizeof (*info->types.types)));
1298 memcpy (info->global_types->types, info->types.types,
1299 info->types.alloc * sizeof (*info->types.types));
1300 memset (info->global_types->builtins, 0,
1301 sizeof (info->global_types->builtins));
1302
1303 break;
1304
1305 case 4:
1306 case 6:
1307 if (! ieee_read_expression (info, pp, &offset))
1308 return false;
1309 if (! info->blockstack.bsp->skip)
1310 {
1311 if (! debug_end_function (info->dhandle, offset + 1))
1312 return false;
1313 }
1314 break;
1315
1316 case 0x86:
1317 /* This is BE6 when BB6 started a block rather than a local
1318 function. */
1319 if (! ieee_read_expression (info, pp, &offset))
1320 return false;
1321 if (! debug_end_block (info->dhandle, offset + 1))
1322 return false;
1323 break;
1324
1325 case 5:
1326 /* When we end a BB5, we look up the stack for the last BB5, if
1327 there is one, so that we can call debug_start_source. */
1328 if (info->blockstack.bsp > info->blockstack.stack)
1329 {
1330 struct ieee_block *bl;
1331
1332 bl = info->blockstack.bsp;
1333 do
1334 {
1335 --bl;
1336 if (bl->kind == 5)
1337 {
1338 if (! debug_start_source (info->dhandle, bl->filename))
1339 return false;
1340 break;
1341 }
1342 }
1343 while (bl != info->blockstack.stack);
1344 }
1345 break;
1346
1347 case 11:
1348 if (! ieee_read_expression (info, pp, &offset))
1349 return false;
1350 /* We just ignore the module size. FIXME. */
1351 break;
1352
1353 default:
1354 /* Other block types do not have any trailing information. */
1355 break;
1356 }
1357
1358 return true;
1359}
1360
1361/* Parse an NN record. */
1362
1363static boolean
1364parse_ieee_nn (info, pp)
1365 struct ieee_info *info;
1366 const bfd_byte **pp;
1367{
1368 const bfd_byte *nn_start;
1369 bfd_vma varindx;
1370 const char *name;
1371 unsigned long namlen;
1372
1373 nn_start = *pp;
1374
1375 if (! ieee_read_number (info, pp, &varindx)
1376 || ! ieee_read_id (info, pp, &name, &namlen))
1377 return false;
1378
1379 if (varindx < 32)
1380 {
1381 ieee_error (info, nn_start, _("illegal variable index"));
1382 return false;
1383 }
1384 varindx -= 32;
1385
1386 if (varindx >= info->vars.alloc)
1387 {
1388 unsigned int alloc;
1389
1390 alloc = info->vars.alloc;
1391 if (alloc == 0)
1392 alloc = 4;
1393 while (varindx >= alloc)
1394 alloc *= 2;
1395 info->vars.vars = ((struct ieee_var *)
1396 xrealloc (info->vars.vars,
1397 alloc * sizeof *info->vars.vars));
1398 memset (info->vars.vars + info->vars.alloc, 0,
1399 (alloc - info->vars.alloc) * sizeof *info->vars.vars);
1400 info->vars.alloc = alloc;
1401 }
1402
1403 info->vars.vars[varindx].name = name;
1404 info->vars.vars[varindx].namlen = namlen;
1405
1406 return true;
1407}
1408
1409/* Parse a TY record. */
1410
1411static boolean
1412parse_ieee_ty (info, pp)
1413 struct ieee_info *info;
1414 const bfd_byte **pp;
1415{
1416 const bfd_byte *ty_start, *ty_var_start, *ty_code_start;
1417 bfd_vma typeindx, varindx, tc;
1418 PTR dhandle;
1419 boolean tag, typdef;
1420 debug_type *arg_slots;
1421 unsigned long type_bitsize;
1422 debug_type type;
1423
1424 ty_start = *pp;
1425
1426 if (! ieee_read_number (info, pp, &typeindx))
1427 return false;
1428
1429 if (typeindx < 256)
1430 {
1431 ieee_error (info, ty_start, _("illegal type index"));
1432 return false;
1433 }
1434
1435 typeindx -= 256;
1436 if (! ieee_alloc_type (info, typeindx, false))
1437 return false;
1438
1439 if (**pp != 0xce)
1440 {
1441 ieee_error (info, *pp, _("unknown TY code"));
1442 return false;
1443 }
1444 ++*pp;
1445
1446 ty_var_start = *pp;
1447
1448 if (! ieee_read_number (info, pp, &varindx))
1449 return false;
1450
1451 if (varindx < 32)
1452 {
1453 ieee_error (info, ty_var_start, _("illegal variable index"));
1454 return false;
1455 }
1456 varindx -= 32;
1457
1458 if (varindx >= info->vars.alloc || info->vars.vars[varindx].name == NULL)
1459 {
1460 ieee_error (info, ty_var_start, _("undefined variable in TY"));
1461 return false;
1462 }
1463
1464 ty_code_start = *pp;
1465
1466 if (! ieee_read_number (info, pp, &tc))
1467 return false;
1468
1469 dhandle = info->dhandle;
1470
1471 tag = false;
1472 typdef = false;
1473 arg_slots = NULL;
1474 type_bitsize = 0;
1475 switch (tc)
1476 {
1477 default:
1478 ieee_error (info, ty_code_start, _("unknown TY code"));
1479 return false;
1480
1481 case '!':
1482 /* Unknown type, with size. We treat it as int. FIXME. */
1483 {
1484 bfd_vma size;
1485
1486 if (! ieee_read_number (info, pp, &size))
1487 return false;
1488 type = debug_make_int_type (dhandle, size, false);
1489 }
1490 break;
1491
1492 case 'A': /* Array. */
1493 case 'a': /* FORTRAN array in column/row order. FIXME: Not
1494 distinguished from normal array. */
1495 {
1496 debug_type ele_type;
1497 bfd_vma lower, upper;
1498
1499 if (! ieee_read_type_index (info, pp, &ele_type)
1500 || ! ieee_read_number (info, pp, &lower)
1501 || ! ieee_read_number (info, pp, &upper))
1502 return false;
1503 type = debug_make_array_type (dhandle, ele_type,
1504 ieee_builtin_type (info, ty_code_start,
1505 ((unsigned int)
1506 builtin_int)),
1507 (bfd_signed_vma) lower,
1508 (bfd_signed_vma) upper,
1509 false);
1510 }
1511 break;
1512
1513 case 'E':
1514 /* Simple enumeration. */
1515 {
1516 bfd_vma size;
1517 unsigned int alloc;
1518 const char **names;
1519 unsigned int c;
1520 bfd_signed_vma *vals;
1521 unsigned int i;
1522
1523 if (! ieee_read_number (info, pp, &size))
1524 return false;
1525 /* FIXME: we ignore the enumeration size. */
1526
1527 alloc = 10;
1528 names = (const char **) xmalloc (alloc * sizeof *names);
1529 memset (names, 0, alloc * sizeof *names);
1530 c = 0;
1531 while (1)
1532 {
1533 const char *name;
1534 unsigned long namlen;
1535 boolean present;
1536
1537 if (! ieee_read_optional_id (info, pp, &name, &namlen, &present))
1538 return false;
1539 if (! present)
1540 break;
1541
1542 if (c + 1 >= alloc)
1543 {
1544 alloc += 10;
1545 names = ((const char **)
1546 xrealloc (names, alloc * sizeof *names));
1547 }
1548
1549 names[c] = savestring (name, namlen);
1550 if (names[c] == NULL)
1551 return false;
1552 ++c;
1553 }
1554
1555 names[c] = NULL;
1556
1557 vals = (bfd_signed_vma *) xmalloc (c * sizeof *vals);
1558 for (i = 0; i < c; i++)
1559 vals[i] = i;
1560
1561 type = debug_make_enum_type (dhandle, names, vals);
1562 tag = true;
1563 }
1564 break;
1565
1566 case 'G':
1567 /* Struct with bit fields. */
1568 {
1569 bfd_vma size;
1570 unsigned int alloc;
1571 debug_field *fields;
1572 unsigned int c;
1573
1574 if (! ieee_read_number (info, pp, &size))
1575 return false;
1576
1577 alloc = 10;
1578 fields = (debug_field *) xmalloc (alloc * sizeof *fields);
1579 c = 0;
1580 while (1)
1581 {
1582 const char *name;
1583 unsigned long namlen;
1584 boolean present;
1585 debug_type ftype;
1586 bfd_vma bitpos, bitsize;
1587
1588 if (! ieee_read_optional_id (info, pp, &name, &namlen, &present))
1589 return false;
1590 if (! present)
1591 break;
1592 if (! ieee_read_type_index (info, pp, &ftype)
1593 || ! ieee_read_number (info, pp, &bitpos)
1594 || ! ieee_read_number (info, pp, &bitsize))
1595 return false;
1596
1597 if (c + 1 >= alloc)
1598 {
1599 alloc += 10;
1600 fields = ((debug_field *)
1601 xrealloc (fields, alloc * sizeof *fields));
1602 }
1603
1604 fields[c] = debug_make_field (dhandle, savestring (name, namlen),
1605 ftype, bitpos, bitsize,
1606 DEBUG_VISIBILITY_PUBLIC);
1607 if (fields[c] == NULL)
1608 return false;
1609 ++c;
1610 }
1611
1612 fields[c] = NULL;
1613
1614 type = debug_make_struct_type (dhandle, true, size, fields);
1615 tag = true;
1616 }
1617 break;
1618
1619 case 'N':
1620 /* Enumeration. */
1621 {
1622 unsigned int alloc;
1623 const char **names;
1624 bfd_signed_vma *vals;
1625 unsigned int c;
1626
1627 alloc = 10;
1628 names = (const char **) xmalloc (alloc * sizeof *names);
1629 vals = (bfd_signed_vma *) xmalloc (alloc * sizeof *names);
1630 c = 0;
1631 while (1)
1632 {
1633 const char *name;
1634 unsigned long namlen;
1635 boolean present;
1636 bfd_vma val;
1637
1638 if (! ieee_read_optional_id (info, pp, &name, &namlen, &present))
1639 return false;
1640 if (! present)
1641 break;
1642 if (! ieee_read_number (info, pp, &val))
1643 return false;
1644
1645 /* If the length of the name is zero, then the value is
1646 actually the size of the enum. We ignore this
1647 information. FIXME. */
1648 if (namlen == 0)
1649 continue;
1650
1651 if (c + 1 >= alloc)
1652 {
1653 alloc += 10;
1654 names = ((const char **)
1655 xrealloc (names, alloc * sizeof *names));
1656 vals = ((bfd_signed_vma *)
1657 xrealloc (vals, alloc * sizeof *vals));
1658 }
1659
1660 names[c] = savestring (name, namlen);
1661 if (names[c] == NULL)
1662 return false;
1663 vals[c] = (bfd_signed_vma) val;
1664 ++c;
1665 }
1666
1667 names[c] = NULL;
1668
1669 type = debug_make_enum_type (dhandle, names, vals);
1670 tag = true;
1671 }
1672 break;
1673
1674 case 'O': /* Small pointer. We don't distinguish small and large
1675 pointers. FIXME. */
1676 case 'P': /* Large pointer. */
1677 {
1678 debug_type t;
1679
1680 if (! ieee_read_type_index (info, pp, &t))
1681 return false;
1682 type = debug_make_pointer_type (dhandle, t);
1683 }
1684 break;
1685
1686 case 'R':
1687 /* Range. */
1688 {
1689 bfd_vma low, high, signedp, size;
1690
1691 if (! ieee_read_number (info, pp, &low)
1692 || ! ieee_read_number (info, pp, &high)
1693 || ! ieee_read_number (info, pp, &signedp)
1694 || ! ieee_read_number (info, pp, &size))
1695 return false;
1696
1697 type = debug_make_range_type (dhandle,
1698 debug_make_int_type (dhandle, size,
1699 ! signedp),
1700 (bfd_signed_vma) low,
1701 (bfd_signed_vma) high);
1702 }
1703 break;
1704
1705 case 'S': /* Struct. */
1706 case 'U': /* Union. */
1707 {
1708 bfd_vma size;
1709 unsigned int alloc;
1710 debug_field *fields;
1711 unsigned int c;
1712
1713 if (! ieee_read_number (info, pp, &size))
1714 return false;
1715
1716 alloc = 10;
1717 fields = (debug_field *) xmalloc (alloc * sizeof *fields);
1718 c = 0;
1719 while (1)
1720 {
1721 const char *name;
1722 unsigned long namlen;
1723 boolean present;
1724 bfd_vma tindx;
1725 bfd_vma offset;
1726 debug_type ftype;
1727 bfd_vma bitsize;
1728
1729 if (! ieee_read_optional_id (info, pp, &name, &namlen, &present))
1730 return false;
1731 if (! present)
1732 break;
1733 if (! ieee_read_number (info, pp, &tindx)
1734 || ! ieee_read_number (info, pp, &offset))
1735 return false;
1736
1737 if (tindx < 256)
1738 {
1739 ftype = ieee_builtin_type (info, ty_code_start, tindx);
1740 bitsize = 0;
1741 offset *= 8;
1742 }
1743 else
1744 {
1745 struct ieee_type *t;
1746
1747 tindx -= 256;
1748 if (! ieee_alloc_type (info, tindx, true))
1749 return false;
1750 t = info->types.types + tindx;
1751 ftype = t->type;
1752 bitsize = t->bitsize;
1753 if (bitsize == 0)
1754 offset *= 8;
1755 }
1756
1757 if (c + 1 >= alloc)
1758 {
1759 alloc += 10;
1760 fields = ((debug_field *)
1761 xrealloc (fields, alloc * sizeof *fields));
1762 }
1763
1764 fields[c] = debug_make_field (dhandle, savestring (name, namlen),
1765 ftype, offset, bitsize,
1766 DEBUG_VISIBILITY_PUBLIC);
1767 if (fields[c] == NULL)
1768 return false;
1769 ++c;
1770 }
1771
1772 fields[c] = NULL;
1773
1774 type = debug_make_struct_type (dhandle, tc == 'S', size, fields);
1775 tag = true;
1776 }
1777 break;
1778
1779 case 'T':
1780 /* Typedef. */
1781 if (! ieee_read_type_index (info, pp, &type))
1782 return false;
1783 typdef = true;
1784 break;
1785
1786 case 'X':
1787 /* Procedure. FIXME: This is an extern declaration, which we
1788 have no way of representing. */
1789 {
1790 bfd_vma attr;
1791 debug_type rtype;
1792 bfd_vma nargs;
1793 boolean present;
1794 struct ieee_var *pv;
1795
1796 /* FIXME: We ignore the attribute and the argument names. */
1797
1798 if (! ieee_read_number (info, pp, &attr)
1799 || ! ieee_read_type_index (info, pp, &rtype)
1800 || ! ieee_read_number (info, pp, &nargs))
1801 return false;
1802 do
1803 {
1804 const char *name;
1805 unsigned long namlen;
1806
1807 if (! ieee_read_optional_id (info, pp, &name, &namlen, &present))
1808 return false;
1809 }
1810 while (present);
1811
1812 pv = info->vars.vars + varindx;
1813 pv->kind = IEEE_EXTERNAL;
1814 if (pv->namlen > 0
1815 && debug_get_type_kind (dhandle, rtype) == DEBUG_KIND_POINTER)
1816 {
1817 /* Set up the return type as an indirect type pointing to
1818 the variable slot, so that we can change it to a
1819 reference later if appropriate. */
1820 pv->pslot = (debug_type *) xmalloc (sizeof *pv->pslot);
1821 *pv->pslot = rtype;
1822 rtype = debug_make_indirect_type (dhandle, pv->pslot,
1823 (const char *) NULL);
1824 }
1825
1826 type = debug_make_function_type (dhandle, rtype, (debug_type *) NULL,
1827 false);
1828 }
1829 break;
1830
1831 case 'V':
1832 /* Void. This is not documented, but the MRI compiler emits it. */
1833 type = debug_make_void_type (dhandle);
1834 break;
1835
1836 case 'Z':
1837 /* Array with 0 lower bound. */
1838 {
1839 debug_type etype;
1840 bfd_vma high;
1841
1842 if (! ieee_read_type_index (info, pp, &etype)
1843 || ! ieee_read_number (info, pp, &high))
1844 return false;
1845
1846 type = debug_make_array_type (dhandle, etype,
1847 ieee_builtin_type (info, ty_code_start,
1848 ((unsigned int)
1849 builtin_int)),
1850 0, (bfd_signed_vma) high, false);
1851 }
1852 break;
1853
1854 case 'c': /* Complex. */
1855 case 'd': /* Double complex. */
1856 {
1857 const char *name;
1858 unsigned long namlen;
1859
1860 /* FIXME: I don't know what the name means. */
1861
1862 if (! ieee_read_id (info, pp, &name, &namlen))
1863 return false;
1864
1865 type = debug_make_complex_type (dhandle, tc == 'c' ? 4 : 8);
1866 }
1867 break;
1868
1869 case 'f':
1870 /* Pascal file name. FIXME. */
1871 ieee_error (info, ty_code_start, _("Pascal file name not supported"));
1872 return false;
1873
1874 case 'g':
1875 /* Bitfield type. */
1876 {
1877 bfd_vma signedp, bitsize, dummy;
1878 const bfd_byte *hold;
1879 boolean present;
1880
1881 if (! ieee_read_number (info, pp, &signedp)
1882 || ! ieee_read_number (info, pp, &bitsize))
1883 return false;
1884
1885 /* I think the documentation says that there is a type index,
1886 but some actual files do not have one. */
1887 hold = *pp;
1888 if (! ieee_read_optional_number (info, pp, &dummy, &present))
1889 return false;
1890 if (! present)
1891 {
1892 /* FIXME: This is just a guess. */
1893 type = debug_make_int_type (dhandle, 4,
1894 signedp ? false : true);
1895 }
1896 else
1897 {
1898 *pp = hold;
1899 if (! ieee_read_type_index (info, pp, &type))
1900 return false;
1901 }
1902 type_bitsize = bitsize;
1903 }
1904 break;
1905
1906 case 'n':
1907 /* Qualifier. */
1908 {
1909 bfd_vma kind;
1910 debug_type t;
1911
1912 if (! ieee_read_number (info, pp, &kind)
1913 || ! ieee_read_type_index (info, pp, &t))
1914 return false;
1915
1916 switch (kind)
1917 {
1918 default:
1919 ieee_error (info, ty_start, _("unsupported qualifer"));
1920 return false;
1921
1922 case 1:
1923 type = debug_make_const_type (dhandle, t);
1924 break;
1925
1926 case 2:
1927 type = debug_make_volatile_type (dhandle, t);
1928 break;
1929 }
1930 }
1931 break;
1932
1933 case 's':
1934 /* Set. */
1935 {
1936 bfd_vma size;
1937 debug_type etype;
1938
1939 if (! ieee_read_number (info, pp, &size)
1940 || ! ieee_read_type_index (info, pp, &etype))
1941 return false;
1942
1943 /* FIXME: We ignore the size. */
1944
1945 type = debug_make_set_type (dhandle, etype, false);
1946 }
1947 break;
1948
1949 case 'x':
1950 /* Procedure with compiler dependencies. */
1951 {
1952 struct ieee_var *pv;
1953 bfd_vma attr, frame_type, push_mask, nargs, level, father;
1954 debug_type rtype;
1955 debug_type *arg_types;
1956 boolean varargs;
1957 boolean present;
1958
1959 /* FIXME: We ignore some of this information. */
1960
1961 pv = info->vars.vars + varindx;
1962
1963 if (! ieee_read_number (info, pp, &attr)
1964 || ! ieee_read_number (info, pp, &frame_type)
1965 || ! ieee_read_number (info, pp, &push_mask)
1966 || ! ieee_read_type_index (info, pp, &rtype)
1967 || ! ieee_read_number (info, pp, &nargs))
1968 return false;
1969 if (nargs == (bfd_vma) -1)
1970 {
1971 arg_types = NULL;
1972 varargs = false;
1973 }
1974 else
1975 {
1976 unsigned int i;
1977
1978 arg_types = ((debug_type *)
1979 xmalloc ((nargs + 1) * sizeof *arg_types));
1980 for (i = 0; i < nargs; i++)
1981 if (! ieee_read_type_index (info, pp, arg_types + i))
1982 return false;
1983
1984 /* If the last type is pointer to void, this is really a
1985 varargs function. */
1986 varargs = false;
1987 if (nargs > 0)
1988 {
1989 debug_type last;
1990
1991 last = arg_types[nargs - 1];
1992 if (debug_get_type_kind (dhandle, last) == DEBUG_KIND_POINTER
1993 && (debug_get_type_kind (dhandle,
1994 debug_get_target_type (dhandle,
1995 last))
1996 == DEBUG_KIND_VOID))
1997 {
1998 --nargs;
1999 varargs = true;
2000 }
2001 }
2002
2003 /* If there are any pointer arguments, turn them into
2004 indirect types in case we later need to convert them to
2005 reference types. */
2006 for (i = 0; i < nargs; i++)
2007 {
2008 if (debug_get_type_kind (dhandle, arg_types[i])
2009 == DEBUG_KIND_POINTER)
2010 {
2011 if (arg_slots == NULL)
2012 {
2013 arg_slots = ((debug_type *)
2014 xmalloc (nargs * sizeof *arg_slots));
2015 memset (arg_slots, 0, nargs * sizeof *arg_slots);
2016 }
2017 arg_slots[i] = arg_types[i];
2018 arg_types[i] =
2019 debug_make_indirect_type (dhandle,
2020 arg_slots + i,
2021 (const char *) NULL);
2022 }
2023 }
2024
2025 arg_types[nargs] = DEBUG_TYPE_NULL;
2026 }
2027 if (! ieee_read_number (info, pp, &level)
2028 || ! ieee_read_optional_number (info, pp, &father, &present))
2029 return false;
2030
2031 /* We can't distinguish between a global function and a static
2032 function. */
2033 pv->kind = IEEE_FUNCTION;
2034
2035 if (pv->namlen > 0
2036 && debug_get_type_kind (dhandle, rtype) == DEBUG_KIND_POINTER)
2037 {
2038 /* Set up the return type as an indirect type pointing to
2039 the variable slot, so that we can change it to a
2040 reference later if appropriate. */
2041 pv->pslot = (debug_type *) xmalloc (sizeof *pv->pslot);
2042 *pv->pslot = rtype;
2043 rtype = debug_make_indirect_type (dhandle, pv->pslot,
2044 (const char *) NULL);
2045 }
2046
2047 type = debug_make_function_type (dhandle, rtype, arg_types, varargs);
2048 }
2049 break;
2050 }
2051
2052 /* Record the type in the table. */
2053
2054 if (type == DEBUG_TYPE_NULL)
2055 return false;
2056
2057 info->vars.vars[varindx].type = type;
2058
2059 if ((tag || typdef)
2060 && info->vars.vars[varindx].namlen > 0)
2061 {
2062 const char *name;
2063
2064 name = savestring (info->vars.vars[varindx].name,
2065 info->vars.vars[varindx].namlen);
2066 if (typdef)
2067 type = debug_name_type (dhandle, name, type);
2068 else if (tc == 'E' || tc == 'N')
2069 type = debug_tag_type (dhandle, name, type);
2070 else
2071 {
2072 struct ieee_tag *it;
2073
2074 /* We must allocate all struct tags as indirect types, so
2075 that if we later see a definition of the tag as a C++
2076 record we can update the indirect slot and automatically
2077 change all the existing references. */
2078 it = (struct ieee_tag *) xmalloc (sizeof *it);
2079 memset (it, 0, sizeof *it);
2080 it->next = info->tags;
2081 info->tags = it;
2082 it->name = name;
2083 it->slot = type;
2084
2085 type = debug_make_indirect_type (dhandle, &it->slot, name);
2086 type = debug_tag_type (dhandle, name, type);
2087
2088 it->type = type;
2089 }
2090 if (type == NULL)
2091 return false;
2092 }
2093
2094 info->types.types[typeindx].type = type;
2095 info->types.types[typeindx].arg_slots = arg_slots;
2096 info->types.types[typeindx].bitsize = type_bitsize;
2097
2098 /* We may have already allocated type as an indirect type pointing
2099 to slot. It does no harm to replace the indirect type with the
2100 real type. Filling in slot as well handles the indirect types
2101 which are already hanging around. */
2102 if (info->types.types[typeindx].pslot != NULL)
2103 *info->types.types[typeindx].pslot = type;
2104
2105 return true;
2106}
2107
2108/* Parse an ATN record. */
2109
2110static boolean
2111parse_ieee_atn (info, pp)
2112 struct ieee_info *info;
2113 const bfd_byte **pp;
2114{
2115 const bfd_byte *atn_start, *atn_code_start;
2116 bfd_vma varindx;
2117 struct ieee_var *pvar;
2118 debug_type type;
2119 bfd_vma atn_code;
2120 PTR dhandle;
2121 bfd_vma v, v2, v3, v4, v5;
2122 const char *name;
2123 unsigned long namlen;
2124 char *namcopy;
2125 boolean present;
2126 int blocktype;
2127
2128 atn_start = *pp;
2129
2130 if (! ieee_read_number (info, pp, &varindx)
2131 || ! ieee_read_type_index (info, pp, &type))
2132 return false;
2133
2134 atn_code_start = *pp;
2135
2136 if (! ieee_read_number (info, pp, &atn_code))
2137 return false;
2138
2139 if (varindx == 0)
2140 {
2141 pvar = NULL;
2142 name = "";
2143 namlen = 0;
2144 }
2145 else if (varindx < 32)
2146 {
2147 /* The MRI compiler reportedly sometimes emits variable lifetime
2148 information for a register. We just ignore it. */
2149 if (atn_code == 9)
2150 return ieee_read_number (info, pp, &v);
2151
2152 ieee_error (info, atn_start, _("illegal variable index"));
2153 return false;
2154 }
2155 else
2156 {
2157 varindx -= 32;
2158 if (varindx >= info->vars.alloc
2159 || info->vars.vars[varindx].name == NULL)
2160 {
2161 /* The MRI compiler or linker sometimes omits the NN record
2162 for a pmisc record. */
2163 if (atn_code == 62)
2164 {
2165 if (varindx >= info->vars.alloc)
2166 {
2167 unsigned int alloc;
2168
2169 alloc = info->vars.alloc;
2170 if (alloc == 0)
2171 alloc = 4;
2172 while (varindx >= alloc)
2173 alloc *= 2;
2174 info->vars.vars = ((struct ieee_var *)
2175 xrealloc (info->vars.vars,
2176 (alloc
2177 * sizeof *info->vars.vars)));
2178 memset (info->vars.vars + info->vars.alloc, 0,
2179 ((alloc - info->vars.alloc)
2180 * sizeof *info->vars.vars));
2181 info->vars.alloc = alloc;
2182 }
2183
2184 pvar = info->vars.vars + varindx;
2185 pvar->name = "";
2186 pvar->namlen = 0;
2187 }
2188 else
2189 {
2190 ieee_error (info, atn_start, _("undefined variable in ATN"));
2191 return false;
2192 }
2193 }
2194
2195 pvar = info->vars.vars + varindx;
2196
2197 pvar->type = type;
2198
2199 name = pvar->name;
2200 namlen = pvar->namlen;
2201 }
2202
2203 dhandle = info->dhandle;
2204
2205 /* If we are going to call debug_record_variable with a pointer
2206 type, change the type to an indirect type so that we can later
2207 change it to a reference type if we encounter a C++ pmisc 'R'
2208 record. */
2209 if (pvar != NULL
2210 && type != DEBUG_TYPE_NULL
2211 && debug_get_type_kind (dhandle, type) == DEBUG_KIND_POINTER)
2212 {
2213 switch (atn_code)
2214 {
2215 case 1:
2216 case 2:
2217 case 3:
2218 case 5:
2219 case 8:
2220 case 10:
2221 pvar->pslot = (debug_type *) xmalloc (sizeof *pvar->pslot);
2222 *pvar->pslot = type;
2223 type = debug_make_indirect_type (dhandle, pvar->pslot,
2224 (const char *) NULL);
2225 pvar->type = type;
2226 break;
2227 }
2228 }
2229
2230 switch (atn_code)
2231 {
2232 default:
2233 ieee_error (info, atn_code_start, _("unknown ATN type"));
2234 return false;
2235
2236 case 1:
2237 /* Automatic variable. */
2238 if (! ieee_read_number (info, pp, &v))
2239 return false;
2240 namcopy = savestring (name, namlen);
2241 if (type == NULL)
2242 type = debug_make_void_type (dhandle);
2243 if (pvar != NULL)
2244 pvar->kind = IEEE_LOCAL;
2245 return debug_record_variable (dhandle, namcopy, type, DEBUG_LOCAL, v);
2246
2247 case 2:
2248 /* Register variable. */
2249 if (! ieee_read_number (info, pp, &v))
2250 return false;
2251 namcopy = savestring (name, namlen);
2252 if (type == NULL)
2253 type = debug_make_void_type (dhandle);
2254 if (pvar != NULL)
2255 pvar->kind = IEEE_LOCAL;
2256 return debug_record_variable (dhandle, namcopy, type, DEBUG_REGISTER,
2257 ieee_regno_to_genreg (info->abfd, v));
2258
2259 case 3:
2260 /* Static variable. */
2261 if (! ieee_require_asn (info, pp, &v))
2262 return false;
2263 namcopy = savestring (name, namlen);
2264 if (type == NULL)
2265 type = debug_make_void_type (dhandle);
2266 if (info->blockstack.bsp <= info->blockstack.stack)
2267 blocktype = 0;
2268 else
2269 blocktype = info->blockstack.bsp[-1].kind;
2270 if (pvar != NULL)
2271 {
2272 if (blocktype == 4 || blocktype == 6)
2273 pvar->kind = IEEE_LOCAL;
2274 else
2275 pvar->kind = IEEE_STATIC;
2276 }
2277 return debug_record_variable (dhandle, namcopy, type,
2278 (blocktype == 4 || blocktype == 6
2279 ? DEBUG_LOCAL_STATIC
2280 : DEBUG_STATIC),
2281 v);
2282
2283 case 4:
2284 /* External function. We don't currently record these. FIXME. */
2285 if (pvar != NULL)
2286 pvar->kind = IEEE_EXTERNAL;
2287 return true;
2288
2289 case 5:
2290 /* External variable. We don't currently record these. FIXME. */
2291 if (pvar != NULL)
2292 pvar->kind = IEEE_EXTERNAL;
2293 return true;
2294
2295 case 7:
2296 if (! ieee_read_number (info, pp, &v)
2297 || ! ieee_read_number (info, pp, &v2)
2298 || ! ieee_read_optional_number (info, pp, &v3, &present))
2299 return false;
2300 if (present)
2301 {
2302 if (! ieee_read_optional_number (info, pp, &v4, &present))
2303 return false;
2304 }
2305
2306 /* We just ignore the two optional fields in v3 and v4, since
2307 they are not defined. */
2308
2309 if (! ieee_require_asn (info, pp, &v3))
2310 return false;
2311
2312 /* We have no way to record the column number. FIXME. */
2313
2314 return debug_record_line (dhandle, v, v3);
2315
2316 case 8:
2317 /* Global variable. */
2318 if (! ieee_require_asn (info, pp, &v))
2319 return false;
2320 namcopy = savestring (name, namlen);
2321 if (type == NULL)
2322 type = debug_make_void_type (dhandle);
2323 if (pvar != NULL)
2324 pvar->kind = IEEE_GLOBAL;
2325 return debug_record_variable (dhandle, namcopy, type, DEBUG_GLOBAL, v);
2326
2327 case 9:
2328 /* Variable lifetime information. */
2329 if (! ieee_read_number (info, pp, &v))
2330 return false;
2331
2332 /* We have no way to record this information. FIXME. */
2333 return true;
2334
2335 case 10:
2336 /* Locked register. The spec says that there are two required
2337 fields, but at least on occasion the MRI compiler only emits
2338 one. */
2339 if (! ieee_read_number (info, pp, &v)
2340 || ! ieee_read_optional_number (info, pp, &v2, &present))
2341 return false;
2342
2343 /* I think this means a variable that is both in a register and
2344 a frame slot. We ignore the frame slot. FIXME. */
2345
2346 namcopy = savestring (name, namlen);
2347 if (type == NULL)
2348 type = debug_make_void_type (dhandle);
2349 if (pvar != NULL)
2350 pvar->kind = IEEE_LOCAL;
2351 return debug_record_variable (dhandle, namcopy, type, DEBUG_REGISTER, v);
2352
2353 case 11:
2354 /* Reserved for FORTRAN common. */
2355 ieee_error (info, atn_code_start, _("unsupported ATN11"));
2356
2357 /* Return true to keep going. */
2358 return true;
2359
2360 case 12:
2361 /* Based variable. */
2362 v3 = 0;
2363 v4 = 0x80;
2364 v5 = 0;
2365 if (! ieee_read_number (info, pp, &v)
2366 || ! ieee_read_number (info, pp, &v2)
2367 || ! ieee_read_optional_number (info, pp, &v3, &present))
2368 return false;
2369 if (present)
2370 {
2371 if (! ieee_read_optional_number (info, pp, &v4, &present))
2372 return false;
2373 if (present)
2374 {
2375 if (! ieee_read_optional_number (info, pp, &v5, &present))
2376 return false;
2377 }
2378 }
2379
2380 /* We have no way to record this information. FIXME. */
2381
2382 ieee_error (info, atn_code_start, _("unsupported ATN12"));
2383
2384 /* Return true to keep going. */
2385 return true;
2386
2387 case 16:
2388 /* Constant. The description of this that I have is ambiguous,
2389 so I'm not going to try to implement it. */
2390 if (! ieee_read_number (info, pp, &v)
2391 || ! ieee_read_optional_number (info, pp, &v2, &present))
2392 return false;
2393 if (present)
2394 {
2395 if (! ieee_read_optional_number (info, pp, &v2, &present))
2396 return false;
2397 if (present)
2398 {
2399 if (! ieee_read_optional_id (info, pp, &name, &namlen, &present))
2400 return false;
2401 }
2402 }
2403
2404 if ((ieee_record_enum_type) **pp == ieee_e2_first_byte_enum)
2405 {
2406 if (! ieee_require_asn (info, pp, &v3))
2407 return false;
2408 }
2409
2410 return true;
2411
2412 case 19:
2413 /* Static variable from assembler. */
2414 v2 = 0;
2415 if (! ieee_read_number (info, pp, &v)
2416 || ! ieee_read_optional_number (info, pp, &v2, &present)
2417 || ! ieee_require_asn (info, pp, &v3))
2418 return false;
2419 namcopy = savestring (name, namlen);
2420 /* We don't really handle this correctly. FIXME. */
2421 return debug_record_variable (dhandle, namcopy,
2422 debug_make_void_type (dhandle),
2423 v2 != 0 ? DEBUG_GLOBAL : DEBUG_STATIC,
2424 v3);
2425
2426 case 62:
2427 /* Procedure miscellaneous information. */
2428 case 63:
2429 /* Variable miscellaneous information. */
2430 case 64:
2431 /* Module miscellaneous information. */
2432 if (! ieee_read_number (info, pp, &v)
2433 || ! ieee_read_number (info, pp, &v2)
2434 || ! ieee_read_optional_id (info, pp, &name, &namlen, &present))
2435 return false;
2436
2437 if (atn_code == 62 && v == 80)
2438 {
2439 if (present)
2440 {
2441 ieee_error (info, atn_code_start,
2442 _("unexpected string in C++ misc"));
2443 return false;
2444 }
2445 return ieee_read_cxx_misc (info, pp, v2);
2446 }
2447
2448 /* We just ignore all of this stuff. FIXME. */
2449
2450 for (; v2 > 0; --v2)
2451 {
2452 switch ((ieee_record_enum_type) **pp)
2453 {
2454 default:
2455 ieee_error (info, *pp, _("bad misc record"));
2456 return false;
2457
2458 case ieee_at_record_enum:
2459 if (! ieee_require_atn65 (info, pp, &name, &namlen))
2460 return false;
2461 break;
2462
2463 case ieee_e2_first_byte_enum:
2464 if (! ieee_require_asn (info, pp, &v3))
2465 return false;
2466 break;
2467 }
2468 }
2469
2470 return true;
2471 }
2472
2473 /*NOTREACHED*/
2474}
2475
2476/* Handle C++ debugging miscellaneous records. This is called for
2477 procedure miscellaneous records of type 80. */
2478
2479static boolean
2480ieee_read_cxx_misc (info, pp, count)
2481 struct ieee_info *info;
2482 const bfd_byte **pp;
2483 unsigned long count;
2484{
2485 const bfd_byte *start;
2486 bfd_vma category;
2487
2488 start = *pp;
2489
2490 /* Get the category of C++ misc record. */
2491 if (! ieee_require_asn (info, pp, &category))
2492 return false;
2493 --count;
2494
2495 switch (category)
2496 {
2497 default:
2498 ieee_error (info, start, _("unrecognized C++ misc record"));
2499 return false;
2500
2501 case 'T':
2502 if (! ieee_read_cxx_class (info, pp, count))
2503 return false;
2504 break;
2505
2506 case 'M':
2507 {
2508 bfd_vma flags;
2509 const char *name;
2510 unsigned long namlen;
2511
2512 /* The IEEE spec indicates that the 'M' record only has a
2513 flags field. The MRI compiler also emits the name of the
2514 function. */
2515
2516 if (! ieee_require_asn (info, pp, &flags))
2517 return false;
2518 if (*pp < info->pend
2519 && (ieee_record_enum_type) **pp == ieee_at_record_enum)
2520 {
2521 if (! ieee_require_atn65 (info, pp, &name, &namlen))
2522 return false;
2523 }
2524
2525 /* This is emitted for method functions, but I don't think we
2526 care very much. It might help if it told us useful
2527 information like the class with which this function is
2528 associated, but it doesn't, so it isn't helpful. */
2529 }
2530 break;
2531
2532 case 'B':
2533 if (! ieee_read_cxx_defaults (info, pp, count))
2534 return false;
2535 break;
2536
2537 case 'z':
2538 {
2539 const char *name, *mangled, *class;
2540 unsigned long namlen, mangledlen, classlen;
2541 bfd_vma control;
2542
2543 /* Pointer to member. */
2544
2545 if (! ieee_require_atn65 (info, pp, &name, &namlen)
2546 || ! ieee_require_atn65 (info, pp, &mangled, &mangledlen)
2547 || ! ieee_require_atn65 (info, pp, &class, &classlen)
2548 || ! ieee_require_asn (info, pp, &control))
2549 return false;
2550
2551 /* FIXME: We should now track down name and change its type. */
2552 }
2553 break;
2554
2555 case 'R':
2556 if (! ieee_read_reference (info, pp))
2557 return false;
2558 break;
2559 }
2560
2561 return true;
2562}
2563
2564/* Read a C++ class definition. This is a pmisc type 80 record of
2565 category 'T'. */
2566
2567static boolean
2568ieee_read_cxx_class (info, pp, count)
2569 struct ieee_info *info;
2570 const bfd_byte **pp;
2571 unsigned long count;
2572{
2573 const bfd_byte *start;
2574 bfd_vma class;
2575 const char *tag;
2576 unsigned long taglen;
2577 struct ieee_tag *it;
2578 PTR dhandle;
2579 debug_field *fields;
2580 unsigned int field_count, field_alloc;
2581 debug_baseclass *baseclasses;
2582 unsigned int baseclasses_count, baseclasses_alloc;
2583 const debug_field *structfields;
2584 struct ieee_method
2585 {
2586 const char *name;
2587 unsigned long namlen;
2588 debug_method_variant *variants;
2589 unsigned count;
2590 unsigned int alloc;
2591 } *methods;
2592 unsigned int methods_count, methods_alloc;
2593 debug_type vptrbase;
2594 boolean ownvptr;
2595 debug_method *dmethods;
2596
2597 start = *pp;
2598
2599 if (! ieee_require_asn (info, pp, &class))
2600 return false;
2601 --count;
2602
2603 if (! ieee_require_atn65 (info, pp, &tag, &taglen))
2604 return false;
2605 --count;
2606
2607 /* Find the C struct with this name. */
2608 for (it = info->tags; it != NULL; it = it->next)
2609 if (it->name[0] == tag[0]
2610 && strncmp (it->name, tag, taglen) == 0
2611 && strlen (it->name) == taglen)
2612 break;
2613 if (it == NULL)
2614 {
2615 ieee_error (info, start, _("undefined C++ object"));
2616 return false;
2617 }
2618
2619 dhandle = info->dhandle;
2620
2621 fields = NULL;
2622 field_count = 0;
2623 field_alloc = 0;
2624 baseclasses = NULL;
2625 baseclasses_count = 0;
2626 baseclasses_alloc = 0;
2627 methods = NULL;
2628 methods_count = 0;
2629 methods_alloc = 0;
2630 vptrbase = DEBUG_TYPE_NULL;
2631 ownvptr = false;
2632
2633 structfields = debug_get_fields (dhandle, it->type);
2634
2635 while (count > 0)
2636 {
2637 bfd_vma id;
2638 const bfd_byte *spec_start;
2639
2640 spec_start = *pp;
2641
2642 if (! ieee_require_asn (info, pp, &id))
2643 return false;
2644 --count;
2645
2646 switch (id)
2647 {
2648 default:
2649 ieee_error (info, spec_start, _("unrecognized C++ object spec"));
2650 return false;
2651
2652 case 'b':
2653 {
2654 bfd_vma flags, cinline;
2655 const char *basename, *fieldname;
2656 unsigned long baselen, fieldlen;
2657 char *basecopy;
2658 debug_type basetype;
2659 bfd_vma bitpos;
2660 boolean virtualp;
2661 enum debug_visibility visibility;
2662 debug_baseclass baseclass;
2663
2664 /* This represents a base or friend class. */
2665
2666 if (! ieee_require_asn (info, pp, &flags)
2667 || ! ieee_require_atn65 (info, pp, &basename, &baselen)
2668 || ! ieee_require_asn (info, pp, &cinline)
2669 || ! ieee_require_atn65 (info, pp, &fieldname, &fieldlen))
2670 return false;
2671 count -= 4;
2672
2673 /* We have no way of recording friend information, so we
2674 just ignore it. */
2675 if ((flags & BASEFLAGS_FRIEND) != 0)
2676 break;
2677
2678 /* I assume that either all of the members of the
2679 baseclass are included in the object, starting at the
2680 beginning of the object, or that none of them are
2681 included. */
2682
2683 if ((fieldlen == 0) == (cinline == 0))
2684 {
2685 ieee_error (info, start, _("unsupported C++ object type"));
2686 return false;
2687 }
2688
2689 basecopy = savestring (basename, baselen);
2690 basetype = debug_find_tagged_type (dhandle, basecopy,
2691 DEBUG_KIND_ILLEGAL);
2692 free (basecopy);
2693 if (basetype == DEBUG_TYPE_NULL)
2694 {
2695 ieee_error (info, start, _("C++ base class not defined"));
2696 return false;
2697 }
2698
2699 if (fieldlen == 0)
2700 bitpos = 0;
2701 else
2702 {
2703 const debug_field *pf;
2704
2705 if (structfields == NULL)
2706 {
2707 ieee_error (info, start, _("C++ object has no fields"));
2708 return false;
2709 }
2710
2711 for (pf = structfields; *pf != DEBUG_FIELD_NULL; pf++)
2712 {
2713 const char *fname;
2714
2715 fname = debug_get_field_name (dhandle, *pf);
2716 if (fname == NULL)
2717 return false;
2718 if (fname[0] == fieldname[0]
2719 && strncmp (fname, fieldname, fieldlen) == 0
2720 && strlen (fname) == fieldlen)
2721 break;
2722 }
2723 if (*pf == DEBUG_FIELD_NULL)
2724 {
2725 ieee_error (info, start,
2726 _("C++ base class not found in container"));
2727 return false;
2728 }
2729
2730 bitpos = debug_get_field_bitpos (dhandle, *pf);
2731 }
2732
2733 if ((flags & BASEFLAGS_VIRTUAL) != 0)
2734 virtualp = true;
2735 else
2736 virtualp = false;
2737 if ((flags & BASEFLAGS_PRIVATE) != 0)
2738 visibility = DEBUG_VISIBILITY_PRIVATE;
2739 else
2740 visibility = DEBUG_VISIBILITY_PUBLIC;
2741
2742 baseclass = debug_make_baseclass (dhandle, basetype, bitpos,
2743 virtualp, visibility);
2744 if (baseclass == DEBUG_BASECLASS_NULL)
2745 return false;
2746
2747 if (baseclasses_count + 1 >= baseclasses_alloc)
2748 {
2749 baseclasses_alloc += 10;
2750 baseclasses = ((debug_baseclass *)
2751 xrealloc (baseclasses,
2752 (baseclasses_alloc
2753 * sizeof *baseclasses)));
2754 }
2755
2756 baseclasses[baseclasses_count] = baseclass;
2757 ++baseclasses_count;
2758 baseclasses[baseclasses_count] = DEBUG_BASECLASS_NULL;
2759 }
2760 break;
2761
2762 case 'd':
2763 {
2764 bfd_vma flags;
2765 const char *fieldname, *mangledname;
2766 unsigned long fieldlen, mangledlen;
2767 char *fieldcopy;
2768 boolean staticp;
2769 debug_type ftype;
2770 const debug_field *pf = NULL;
2771 enum debug_visibility visibility;
2772 debug_field field;
2773
2774 /* This represents a data member. */
2775
2776 if (! ieee_require_asn (info, pp, &flags)
2777 || ! ieee_require_atn65 (info, pp, &fieldname, &fieldlen)
2778 || ! ieee_require_atn65 (info, pp, &mangledname, &mangledlen))
2779 return false;
2780 count -= 3;
2781
2782 fieldcopy = savestring (fieldname, fieldlen);
2783
2784 staticp = (flags & CXXFLAGS_STATIC) != 0 ? true : false;
2785
2786 if (staticp)
2787 {
2788 struct ieee_var *pv, *pvend;
2789
2790 /* See if we can find a definition for this variable. */
2791 pv = info->vars.vars;
2792 pvend = pv + info->vars.alloc;
2793 for (; pv < pvend; pv++)
2794 if (pv->namlen == mangledlen
2795 && strncmp (pv->name, mangledname, mangledlen) == 0)
2796 break;
2797 if (pv < pvend)
2798 ftype = pv->type;
2799 else
2800 {
2801 /* This can happen if the variable is never used. */
2802 ftype = ieee_builtin_type (info, start,
2803 (unsigned int) builtin_void);
2804 }
2805 }
2806 else
2807 {
2808 unsigned int findx;
2809
2810 if (structfields == NULL)
2811 {
2812 ieee_error (info, start, _("C++ object has no fields"));
2813 return false;
2814 }
2815
2816 for (pf = structfields, findx = 0;
2817 *pf != DEBUG_FIELD_NULL;
2818 pf++, findx++)
2819 {
2820 const char *fname;
2821
2822 fname = debug_get_field_name (dhandle, *pf);
2823 if (fname == NULL)
2824 return false;
2825 if (fname[0] == mangledname[0]
2826 && strncmp (fname, mangledname, mangledlen) == 0
2827 && strlen (fname) == mangledlen)
2828 break;
2829 }
2830 if (*pf == DEBUG_FIELD_NULL)
2831 {
2832 ieee_error (info, start,
2833 _("C++ data member not found in container"));
2834 return false;
2835 }
2836
2837 ftype = debug_get_field_type (dhandle, *pf);
2838
2839 if (debug_get_type_kind (dhandle, ftype) == DEBUG_KIND_POINTER)
2840 {
2841 /* We might need to convert this field into a
2842 reference type later on, so make it an indirect
2843 type. */
2844 if (it->fslots == NULL)
2845 {
2846 unsigned int fcnt;
2847 const debug_field *pfcnt;
2848
2849 fcnt = 0;
2850 for (pfcnt = structfields;
2851 *pfcnt != DEBUG_FIELD_NULL;
2852 pfcnt++)
2853 ++fcnt;
2854 it->fslots = ((debug_type *)
2855 xmalloc (fcnt * sizeof *it->fslots));
2856 memset (it->fslots, 0,
2857 fcnt * sizeof *it->fslots);
2858 }
2859
2860 if (ftype == DEBUG_TYPE_NULL)
2861 return false;
2862 it->fslots[findx] = ftype;
2863 ftype = debug_make_indirect_type (dhandle,
2864 it->fslots + findx,
2865 (const char *) NULL);
2866 }
2867 }
2868 if (ftype == DEBUG_TYPE_NULL)
2869 return false;
2870
2871 switch (flags & CXXFLAGS_VISIBILITY)
2872 {
2873 default:
2874 ieee_error (info, start, _("unknown C++ visibility"));
2875 return false;
2876
2877 case CXXFLAGS_VISIBILITY_PUBLIC:
2878 visibility = DEBUG_VISIBILITY_PUBLIC;
2879 break;
2880
2881 case CXXFLAGS_VISIBILITY_PRIVATE:
2882 visibility = DEBUG_VISIBILITY_PRIVATE;
2883 break;
2884
2885 case CXXFLAGS_VISIBILITY_PROTECTED:
2886 visibility = DEBUG_VISIBILITY_PROTECTED;
2887 break;
2888 }
2889
2890 if (staticp)
2891 {
2892 char *mangledcopy;
2893
2894 mangledcopy = savestring (mangledname, mangledlen);
2895
2896 field = debug_make_static_member (dhandle, fieldcopy,
2897 ftype, mangledcopy,
2898 visibility);
2899 }
2900 else
2901 {
2902 bfd_vma bitpos, bitsize;
2903
2904 bitpos = debug_get_field_bitpos (dhandle, *pf);
2905 bitsize = debug_get_field_bitsize (dhandle, *pf);
2906 if (bitpos == (bfd_vma) -1 || bitsize == (bfd_vma) -1)
2907 {
2908 ieee_error (info, start, _("bad C++ field bit pos or size"));
2909 return false;
2910 }
2911 field = debug_make_field (dhandle, fieldcopy, ftype, bitpos,
2912 bitsize, visibility);
2913 }
2914
2915 if (field == DEBUG_FIELD_NULL)
2916 return false;
2917
2918 if (field_count + 1 >= field_alloc)
2919 {
2920 field_alloc += 10;
2921 fields = ((debug_field *)
2922 xrealloc (fields, field_alloc * sizeof *fields));
2923 }
2924
2925 fields[field_count] = field;
2926 ++field_count;
2927 fields[field_count] = DEBUG_FIELD_NULL;
2928 }
2929 break;
2930
2931 case 'm':
2932 case 'v':
2933 {
2934 bfd_vma flags, voffset, control;
2935 const char *name, *mangled;
2936 unsigned long namlen, mangledlen;
2937 struct ieee_var *pv, *pvend;
2938 debug_type type;
2939 enum debug_visibility visibility;
2940 boolean constp, volatilep;
2941 char *mangledcopy;
2942 debug_method_variant mv;
2943 struct ieee_method *meth;
2944 unsigned int im;
2945
2946 if (! ieee_require_asn (info, pp, &flags)
2947 || ! ieee_require_atn65 (info, pp, &name, &namlen)
2948 || ! ieee_require_atn65 (info, pp, &mangled, &mangledlen))
2949 return false;
2950 count -= 3;
2951 if (id != 'v')
2952 voffset = 0;
2953 else
2954 {
2955 if (! ieee_require_asn (info, pp, &voffset))
2956 return false;
2957 --count;
2958 }
2959 if (! ieee_require_asn (info, pp, &control))
2960 return false;
2961 --count;
2962
2963 /* We just ignore the control information. */
2964
2965 /* We have no way to represent friend information, so we
2966 just ignore it. */
2967 if ((flags & CXXFLAGS_FRIEND) != 0)
2968 break;
2969
2970 /* We should already have seen a type for the function. */
2971 pv = info->vars.vars;
2972 pvend = pv + info->vars.alloc;
2973 for (; pv < pvend; pv++)
2974 if (pv->namlen == mangledlen
2975 && strncmp (pv->name, mangled, mangledlen) == 0)
2976 break;
2977
2978 if (pv >= pvend)
2979 {
2980 /* We won't have type information for this function if
2981 it is not included in this file. We don't try to
2982 handle this case. FIXME. */
2983 type = (debug_make_function_type
2984 (dhandle,
2985 ieee_builtin_type (info, start,
2986 (unsigned int) builtin_void),
2987 (debug_type *) NULL,
2988 false));
2989 }
2990 else
2991 {
2992 debug_type return_type;
2993 const debug_type *arg_types;
2994 boolean varargs;
2995
2996 if (debug_get_type_kind (dhandle, pv->type)
2997 != DEBUG_KIND_FUNCTION)
2998 {
2999 ieee_error (info, start,
3000 _("bad type for C++ method function"));
3001 return false;
3002 }
3003
3004 return_type = debug_get_return_type (dhandle, pv->type);
3005 arg_types = debug_get_parameter_types (dhandle, pv->type,
3006 &varargs);
3007 if (return_type == DEBUG_TYPE_NULL || arg_types == NULL)
3008 {
3009 ieee_error (info, start,
3010 _("no type information for C++ method function"));
3011 return false;
3012 }
3013
3014 type = debug_make_method_type (dhandle, return_type, it->type,
3015 (debug_type *) arg_types,
3016 varargs);
3017 }
3018 if (type == DEBUG_TYPE_NULL)
3019 return false;
3020
3021 switch (flags & CXXFLAGS_VISIBILITY)
3022 {
3023 default:
3024 ieee_error (info, start, _("unknown C++ visibility"));
3025 return false;
3026
3027 case CXXFLAGS_VISIBILITY_PUBLIC:
3028 visibility = DEBUG_VISIBILITY_PUBLIC;
3029 break;
3030
3031 case CXXFLAGS_VISIBILITY_PRIVATE:
3032 visibility = DEBUG_VISIBILITY_PRIVATE;
3033 break;
3034
3035 case CXXFLAGS_VISIBILITY_PROTECTED:
3036 visibility = DEBUG_VISIBILITY_PROTECTED;
3037 break;
3038 }
3039
3040 constp = (flags & CXXFLAGS_CONST) != 0 ? true : false;
3041 volatilep = (flags & CXXFLAGS_VOLATILE) != 0 ? true : false;
3042
3043 mangledcopy = savestring (mangled, mangledlen);
3044
3045 if ((flags & CXXFLAGS_STATIC) != 0)
3046 {
3047 if (id == 'v')
3048 {
3049 ieee_error (info, start, _("C++ static virtual method"));
3050 return false;
3051 }
3052 mv = debug_make_static_method_variant (dhandle, mangledcopy,
3053 type, visibility,
3054 constp, volatilep);
3055 }
3056 else
3057 {
3058 debug_type vcontext;
3059
3060 if (id != 'v')
3061 vcontext = DEBUG_TYPE_NULL;
3062 else
3063 {
3064 /* FIXME: How can we calculate this correctly? */
3065 vcontext = it->type;
3066 }
3067 mv = debug_make_method_variant (dhandle, mangledcopy, type,
3068 visibility, constp,
3069 volatilep, voffset,
3070 vcontext);
3071 }
3072 if (mv == DEBUG_METHOD_VARIANT_NULL)
3073 return false;
3074
3075 for (meth = methods, im = 0; im < methods_count; meth++, im++)
3076 if (meth->namlen == namlen
3077 && strncmp (meth->name, name, namlen) == 0)
3078 break;
3079 if (im >= methods_count)
3080 {
3081 if (methods_count >= methods_alloc)
3082 {
3083 methods_alloc += 10;
3084 methods = ((struct ieee_method *)
3085 xrealloc (methods,
3086 methods_alloc * sizeof *methods));
3087 }
3088 methods[methods_count].name = name;
3089 methods[methods_count].namlen = namlen;
3090 methods[methods_count].variants = NULL;
3091 methods[methods_count].count = 0;
3092 methods[methods_count].alloc = 0;
3093 meth = methods + methods_count;
3094 ++methods_count;
3095 }
3096
3097 if (meth->count + 1 >= meth->alloc)
3098 {
3099 meth->alloc += 10;
3100 meth->variants = ((debug_method_variant *)
3101 xrealloc (meth->variants,
3102 (meth->alloc
3103 * sizeof *meth->variants)));
3104 }
3105
3106 meth->variants[meth->count] = mv;
3107 ++meth->count;
3108 meth->variants[meth->count] = DEBUG_METHOD_VARIANT_NULL;
3109 }
3110 break;
3111
3112 case 'o':
3113 {
3114 bfd_vma spec;
3115
3116 /* We have no way to store this information, so we just
3117 ignore it. */
3118 if (! ieee_require_asn (info, pp, &spec))
3119 return false;
3120 --count;
3121 if ((spec & 4) != 0)
3122 {
3123 const char *filename;
3124 unsigned long filenamlen;
3125 bfd_vma lineno;
3126
3127 if (! ieee_require_atn65 (info, pp, &filename, &filenamlen)
3128 || ! ieee_require_asn (info, pp, &lineno))
3129 return false;
3130 count -= 2;
3131 }
3132 else if ((spec & 8) != 0)
3133 {
3134 const char *mangled;
3135 unsigned long mangledlen;
3136
3137 if (! ieee_require_atn65 (info, pp, &mangled, &mangledlen))
3138 return false;
3139 --count;
3140 }
3141 else
3142 {
3143 ieee_error (info, start,
3144 _("unrecognized C++ object overhead spec"));
3145 return false;
3146 }
3147 }
3148 break;
3149
3150 case 'z':
3151 {
3152 const char *vname, *basename;
3153 unsigned long vnamelen, baselen;
3154 bfd_vma vsize, control;
3155
3156 /* A virtual table pointer. */
3157
3158 if (! ieee_require_atn65 (info, pp, &vname, &vnamelen)
3159 || ! ieee_require_asn (info, pp, &vsize)
3160 || ! ieee_require_atn65 (info, pp, &basename, &baselen)
3161 || ! ieee_require_asn (info, pp, &control))
3162 return false;
3163 count -= 4;
3164
3165 /* We just ignore the control number. We don't care what
3166 the virtual table name is. We have no way to store the
3167 virtual table size, and I don't think we care anyhow. */
3168
3169 /* FIXME: We can't handle multiple virtual table pointers. */
3170
3171 if (baselen == 0)
3172 ownvptr = true;
3173 else
3174 {
3175 char *basecopy;
3176
3177 basecopy = savestring (basename, baselen);
3178 vptrbase = debug_find_tagged_type (dhandle, basecopy,
3179 DEBUG_KIND_ILLEGAL);
3180 free (basecopy);
3181 if (vptrbase == DEBUG_TYPE_NULL)
3182 {
3183 ieee_error (info, start, _("undefined C++ vtable"));
3184 return false;
3185 }
3186 }
3187 }
3188 break;
3189 }
3190 }
3191
3192 /* Now that we have seen all the method variants, we can call
3193 debug_make_method for each one. */
3194
3195 if (methods_count == 0)
3196 dmethods = NULL;
3197 else
3198 {
3199 unsigned int i;
3200
3201 dmethods = ((debug_method *)
3202 xmalloc ((methods_count + 1) * sizeof *dmethods));
3203 for (i = 0; i < methods_count; i++)
3204 {
3205 char *namcopy;
3206
3207 namcopy = savestring (methods[i].name, methods[i].namlen);
3208 dmethods[i] = debug_make_method (dhandle, namcopy,
3209 methods[i].variants);
3210 if (dmethods[i] == DEBUG_METHOD_NULL)
3211 return false;
3212 }
3213 dmethods[i] = DEBUG_METHOD_NULL;
3214 free (methods);
3215 }
3216
3217 /* The struct type was created as an indirect type pointing at
3218 it->slot. We update it->slot to automatically update all
3219 references to this struct. */
3220 it->slot = debug_make_object_type (dhandle,
3221 class != 'u',
3222 debug_get_type_size (dhandle,
3223 it->slot),
3224 fields, baseclasses, dmethods,
3225 vptrbase, ownvptr);
3226 if (it->slot == DEBUG_TYPE_NULL)
3227 return false;
3228
3229 return true;
3230}
3231
3232/* Read C++ default argument value and reference type information. */
3233
3234static boolean
3235ieee_read_cxx_defaults (info, pp, count)
3236 struct ieee_info *info;
3237 const bfd_byte **pp;
3238 unsigned long count;
3239{
3240 const bfd_byte *start;
3241 const char *fnname;
3242 unsigned long fnlen;
3243 bfd_vma defcount;
3244
3245 start = *pp;
3246
3247 /* Giving the function name before the argument count is an addendum
3248 to the spec. The function name is demangled, though, so this
3249 record must always refer to the current function. */
3250
3251 if (info->blockstack.bsp <= info->blockstack.stack
3252 || info->blockstack.bsp[-1].fnindx == (unsigned int) -1)
3253 {
3254 ieee_error (info, start, _("C++ default values not in a function"));
3255 return false;
3256 }
3257
3258 if (! ieee_require_atn65 (info, pp, &fnname, &fnlen)
3259 || ! ieee_require_asn (info, pp, &defcount))
3260 return false;
3261 count -= 2;
3262
3263 while (defcount-- > 0)
3264 {
3265 bfd_vma type, val;
3266 const char *strval;
3267 unsigned long strvallen;
3268
3269 if (! ieee_require_asn (info, pp, &type))
3270 return false;
3271 --count;
3272
3273 switch (type)
3274 {
3275 case 0:
3276 case 4:
3277 break;
3278
3279 case 1:
3280 case 2:
3281 if (! ieee_require_asn (info, pp, &val))
3282 return false;
3283 --count;
3284 break;
3285
3286 case 3:
3287 case 7:
3288 if (! ieee_require_atn65 (info, pp, &strval, &strvallen))
3289 return false;
3290 --count;
3291 break;
3292
3293 default:
3294 ieee_error (info, start, _("unrecognized C++ default type"));
3295 return false;
3296 }
3297
3298 /* We have no way to record the default argument values, so we
3299 just ignore them. FIXME. */
3300 }
3301
3302 /* Any remaining arguments are indices of parameters that are really
3303 reference type. */
3304 if (count > 0)
3305 {
3306 PTR dhandle;
3307 debug_type *arg_slots;
3308
3309 dhandle = info->dhandle;
3310 arg_slots = info->types.types[info->blockstack.bsp[-1].fnindx].arg_slots;
3311 while (count-- > 0)
3312 {
3313 bfd_vma indx;
3314 debug_type target;
3315
3316 if (! ieee_require_asn (info, pp, &indx))
3317 return false;
3318 /* The index is 1 based. */
3319 --indx;
3320 if (arg_slots == NULL
3321 || arg_slots[indx] == DEBUG_TYPE_NULL
3322 || (debug_get_type_kind (dhandle, arg_slots[indx])
3323 != DEBUG_KIND_POINTER))
3324 {
3325 ieee_error (info, start, _("reference parameter is not a pointer"));
3326 return false;
3327 }
3328
3329 target = debug_get_target_type (dhandle, arg_slots[indx]);
3330 arg_slots[indx] = debug_make_reference_type (dhandle, target);
3331 if (arg_slots[indx] == DEBUG_TYPE_NULL)
3332 return false;
3333 }
3334 }
3335
3336 return true;
3337}
3338
3339/* Read a C++ reference definition. */
3340
3341static boolean
3342ieee_read_reference (info, pp)
3343 struct ieee_info *info;
3344 const bfd_byte **pp;
3345{
3346 const bfd_byte *start;
3347 bfd_vma flags;
3348 const char *class, *name;
3349 unsigned long classlen, namlen;
3350 debug_type *pslot;
3351 debug_type target;
3352
3353 start = *pp;
3354
3355 if (! ieee_require_asn (info, pp, &flags))
3356 return false;
3357
3358 /* Giving the class name before the member name is in an addendum to
3359 the spec. */
3360 if (flags == 3)
3361 {
3362 if (! ieee_require_atn65 (info, pp, &class, &classlen))
3363 return false;
3364 }
3365
3366 if (! ieee_require_atn65 (info, pp, &name, &namlen))
3367 return false;
3368
3369 pslot = NULL;
3370 if (flags != 3)
3371 {
3372 int pass;
3373
3374 /* We search from the last variable indices to the first in
3375 hopes of finding local variables correctly. We search the
3376 local variables on the first pass, and the global variables
3377 on the second. FIXME: This probably won't work in all cases.
3378 On the other hand, I don't know what will. */
3379 for (pass = 0; pass < 2; pass++)
3380 {
3381 struct ieee_vars *vars;
3382 int i;
3383 struct ieee_var *pv = NULL;
3384
3385 if (pass == 0)
3386 vars = &info->vars;
3387 else
3388 {
3389 vars = info->global_vars;
3390 if (vars == NULL)
3391 break;
3392 }
3393
3394 for (i = (int) vars->alloc - 1; i >= 0; i--)
3395 {
3396 boolean found;
3397
3398 pv = vars->vars + i;
3399
3400 if (pv->pslot == NULL
3401 || pv->namlen != namlen
3402 || strncmp (pv->name, name, namlen) != 0)
3403 continue;
3404
3405 found = false;
3406 switch (flags)
3407 {
3408 default:
3409 ieee_error (info, start,
3410 _("unrecognized C++ reference type"));
3411 return false;
3412
3413 case 0:
3414 /* Global variable or function. */
3415 if (pv->kind == IEEE_GLOBAL
3416 || pv->kind == IEEE_EXTERNAL
3417 || pv->kind == IEEE_FUNCTION)
3418 found = true;
3419 break;
3420
3421 case 1:
3422 /* Global static variable or function. */
3423 if (pv->kind == IEEE_STATIC
3424 || pv->kind == IEEE_FUNCTION)
3425 found = true;
3426 break;
3427
3428 case 2:
3429 /* Local variable. */
3430 if (pv->kind == IEEE_LOCAL)
3431 found = true;
3432 break;
3433 }
3434
3435 if (found)
3436 break;
3437 }
3438
3439 if (i >= 0)
3440 {
3441 pslot = pv->pslot;
3442 break;
3443 }
3444 }
3445 }
3446 else
3447 {
3448 struct ieee_tag *it;
3449
3450 for (it = info->tags; it != NULL; it = it->next)
3451 {
3452 if (it->name[0] == class[0]
3453 && strncmp (it->name, class, classlen) == 0
3454 && strlen (it->name) == classlen)
3455 {
3456 if (it->fslots != NULL)
3457 {
3458 const debug_field *pf;
3459 unsigned int findx;
3460
3461 pf = debug_get_fields (info->dhandle, it->type);
3462 if (pf == NULL)
3463 {
3464 ieee_error (info, start,
3465 "C++ reference in class with no fields");
3466 return false;
3467 }
3468
3469 for (findx = 0; *pf != DEBUG_FIELD_NULL; pf++, findx++)
3470 {
3471 const char *fname;
3472
3473 fname = debug_get_field_name (info->dhandle, *pf);
3474 if (fname == NULL)
3475 return false;
3476 if (strncmp (fname, name, namlen) == 0
3477 && strlen (fname) == namlen)
3478 {
3479 pslot = it->fslots + findx;
3480 break;
3481 }
3482 }
3483 }
3484
3485 break;
3486 }
3487 }
3488 }
3489
3490 if (pslot == NULL)
3491 {
3492 ieee_error (info, start, _("C++ reference not found"));
3493 return false;
3494 }
3495
3496 /* We allocated the type of the object as an indirect type pointing
3497 to *pslot, which we can now update to be a reference type. */
3498 if (debug_get_type_kind (info->dhandle, *pslot) != DEBUG_KIND_POINTER)
3499 {
3500 ieee_error (info, start, _("C++ reference is not pointer"));
3501 return false;
3502 }
3503
3504 target = debug_get_target_type (info->dhandle, *pslot);
3505 *pslot = debug_make_reference_type (info->dhandle, target);
3506 if (*pslot == DEBUG_TYPE_NULL)
3507 return false;
3508
3509 return true;
3510}
3511
3512/* Require an ASN record. */
3513
3514static boolean
3515ieee_require_asn (info, pp, pv)
3516 struct ieee_info *info;
3517 const bfd_byte **pp;
3518 bfd_vma *pv;
3519{
3520 const bfd_byte *start;
3521 ieee_record_enum_type c;
3522 bfd_vma varindx;
3523
3524 start = *pp;
3525
3526 c = (ieee_record_enum_type) **pp;
3527 if (c != ieee_e2_first_byte_enum)
3528 {
3529 ieee_error (info, start, _("missing required ASN"));
3530 return false;
3531 }
3532 ++*pp;
3533
3534 c = (ieee_record_enum_type) (((unsigned int) c << 8) | **pp);
3535 if (c != ieee_asn_record_enum)
3536 {
3537 ieee_error (info, start, _("missing required ASN"));
3538 return false;
3539 }
3540 ++*pp;
3541
3542 /* Just ignore the variable index. */
3543 if (! ieee_read_number (info, pp, &varindx))
3544 return false;
3545
3546 return ieee_read_expression (info, pp, pv);
3547}
3548
3549/* Require an ATN65 record. */
3550
3551static boolean
3552ieee_require_atn65 (info, pp, pname, pnamlen)
3553 struct ieee_info *info;
3554 const bfd_byte **pp;
3555 const char **pname;
3556 unsigned long *pnamlen;
3557{
3558 const bfd_byte *start;
3559 ieee_record_enum_type c;
3560 bfd_vma name_indx, type_indx, atn_code;
3561
3562 start = *pp;
3563
3564 c = (ieee_record_enum_type) **pp;
3565 if (c != ieee_at_record_enum)
3566 {
3567 ieee_error (info, start, _("missing required ATN65"));
3568 return false;
3569 }
3570 ++*pp;
3571
3572 c = (ieee_record_enum_type) (((unsigned int) c << 8) | **pp);
3573 if (c != ieee_atn_record_enum)
3574 {
3575 ieee_error (info, start, _("missing required ATN65"));
3576 return false;
3577 }
3578 ++*pp;
3579
3580 if (! ieee_read_number (info, pp, &name_indx)
3581 || ! ieee_read_number (info, pp, &type_indx)
3582 || ! ieee_read_number (info, pp, &atn_code))
3583 return false;
3584
3585 /* Just ignore name_indx. */
3586
3587 if (type_indx != 0 || atn_code != 65)
3588 {
3589 ieee_error (info, start, _("bad ATN65 record"));
3590 return false;
3591 }
3592
3593 return ieee_read_id (info, pp, pname, pnamlen);
3594}
3595
3596
3597/* Convert a register number in IEEE debugging information into a
3598 generic register number. */
3599
3600static int
3601ieee_regno_to_genreg (abfd, r)
3602 bfd *abfd;
3603 int r;
3604{
3605 switch (bfd_get_arch (abfd))
3606 {
3607 case bfd_arch_m68k:
3608 /* For some reasons stabs adds 2 to the floating point register
3609 numbers. */
3610 if (r >= 16)
3611 r += 2;
3612 break;
3613
3614 case bfd_arch_i960:
3615 /* Stabs uses 0 to 15 for r0 to r15, 16 to 31 for g0 to g15, and
3616 32 to 35 for fp0 to fp3. */
3617 --r;
3618 break;
3619
3620 default:
3621 break;
3622 }
3623
3624 return r;
3625}
3626
3627/* Convert a generic register number to an IEEE specific one. */
3628
3629static int
3630ieee_genreg_to_regno (abfd, r)
3631 bfd *abfd;
3632 int r;
3633{
3634 switch (bfd_get_arch (abfd))
3635 {
3636 case bfd_arch_m68k:
3637 /* For some reason stabs add 2 to the floating point register
3638 numbers. */
3639 if (r >= 18)
3640 r -= 2;
3641 break;
3642
3643 case bfd_arch_i960:
3644 /* Stabs uses 0 to 15 for r0 to r15, 16 to 31 for g0 to g15, and
3645 32 to 35 for fp0 to fp3. */
3646 ++r;
3647 break;
3648
3649 default:
3650 break;
3651 }
3652
3653 return r;
3654}
3655
3656
3657/* These routines build IEEE debugging information out of the generic
3658 debugging information. */
3659
3660/* We build the IEEE debugging information byte by byte. Rather than
3661 waste time copying data around, we use a linked list of buffers to
3662 hold the data. */
3663
3664#define IEEE_BUFSIZE (490)
3665
3666struct ieee_buf
3667{
3668 /* Next buffer. */
3669 struct ieee_buf *next;
3670 /* Number of data bytes in this buffer. */
3671 unsigned int c;
3672 /* Bytes. */
3673 bfd_byte buf[IEEE_BUFSIZE];
3674};
3675
3676/* A list of buffers. */
3677
3678struct ieee_buflist
3679{
3680 /* Head of list. */
3681 struct ieee_buf *head;
3682 /* Tail--last buffer on list. */
3683 struct ieee_buf *tail;
3684};
3685
3686/* In order to generate the BB11 blocks required by the HP emulator,
3687 we keep track of ranges of addresses which correspond to a given
3688 compilation unit. */
3689
3690struct ieee_range
3691{
3692 /* Next range. */
3693 struct ieee_range *next;
3694 /* Low address. */
3695 bfd_vma low;
3696 /* High address. */
3697 bfd_vma high;
3698};
3699
3700/* This structure holds information for a class on the type stack. */
3701
3702struct ieee_type_class
3703{
3704 /* The name index in the debugging information. */
3705 unsigned int indx;
3706 /* The pmisc records for the class. */
3707 struct ieee_buflist pmiscbuf;
3708 /* The number of pmisc records. */
3709 unsigned int pmisccount;
3710 /* The name of the class holding the virtual table, if not this
3711 class. */
3712 const char *vclass;
3713 /* Whether this class holds its own virtual table. */
3714 boolean ownvptr;
3715 /* The largest virtual table offset seen so far. */
3716 bfd_vma voffset;
3717 /* The current method. */
3718 const char *method;
3719 /* Additional pmisc records used to record fields of reference type. */
3720 struct ieee_buflist refs;
3721};
3722
3723/* This is how we store types for the writing routines. Most types
3724 are simply represented by a type index. */
3725
3726struct ieee_write_type
3727{
3728 /* Type index. */
3729 unsigned int indx;
3730 /* The size of the type, if known. */
3731 unsigned int size;
3732 /* The name of the type, if any. */
3733 const char *name;
3734 /* If this is a function or method type, we build the type here, and
3735 only add it to the output buffers if we need it. */
3736 struct ieee_buflist fndef;
3737 /* If this is a struct, this is where the struct definition is
3738 built. */
3739 struct ieee_buflist strdef;
3740 /* If this is a class, this is where the class information is built. */
3741 struct ieee_type_class *classdef;
3742 /* Whether the type is unsigned. */
3743 unsigned int unsignedp : 1;
3744 /* Whether this is a reference type. */
3745 unsigned int referencep : 1;
3746 /* Whether this is in the local type block. */
3747 unsigned int localp : 1;
3748 /* Whether this is a duplicate struct definition which we are
3749 ignoring. */
3750 unsigned int ignorep : 1;
3751};
3752
3753/* This is the type stack used by the debug writing routines. FIXME:
3754 We could generate more efficient output if we remembered when we
3755 have output a particular type before. */
3756
3757struct ieee_type_stack
3758{
3759 /* Next entry on stack. */
3760 struct ieee_type_stack *next;
3761 /* Type information. */
3762 struct ieee_write_type type;
3763};
3764
3765/* This is a list of associations between a name and some types.
3766 These are used for typedefs and tags. */
3767
3768struct ieee_name_type
3769{
3770 /* Next type for this name. */
3771 struct ieee_name_type *next;
3772 /* ID number. For a typedef, this is the index of the type to which
3773 this name is typedefed. */
3774 unsigned int id;
3775 /* Type. */
3776 struct ieee_write_type type;
3777 /* If this is a tag which has not yet been defined, this is the
3778 kind. If the tag has been defined, this is DEBUG_KIND_ILLEGAL. */
3779 enum debug_type_kind kind;
3780};
3781
3782/* We use a hash table to associate names and types. */
3783
3784struct ieee_name_type_hash_table
3785{
3786 struct bfd_hash_table root;
3787};
3788
3789struct ieee_name_type_hash_entry
3790{
3791 struct bfd_hash_entry root;
3792 /* Information for this name. */
3793 struct ieee_name_type *types;
3794};
3795
3796/* This is a list of enums. */
3797
3798struct ieee_defined_enum
3799{
3800 /* Next enum. */
3801 struct ieee_defined_enum *next;
3802 /* Type index. */
3803 unsigned int indx;
3804 /* Whether this enum has been defined. */
3805 boolean defined;
3806 /* Tag. */
3807 const char *tag;
3808 /* Names. */
3809 const char **names;
3810 /* Values. */
3811 bfd_signed_vma *vals;
3812};
3813
3814/* We keep a list of modified versions of types, so that we don't
3815 output them more than once. */
3816
3817struct ieee_modified_type
3818{
3819 /* Pointer to this type. */
3820 unsigned int pointer;
3821 /* Function with unknown arguments returning this type. */
3822 unsigned int function;
3823 /* Const version of this type. */
3824 unsigned int const_qualified;
3825 /* Volatile version of this type. */
3826 unsigned int volatile_qualified;
3827 /* List of arrays of this type of various bounds. */
3828 struct ieee_modified_array_type *arrays;
3829};
3830
3831/* A list of arrays bounds. */
3832
3833struct ieee_modified_array_type
3834{
3835 /* Next array bounds. */
3836 struct ieee_modified_array_type *next;
3837 /* Type index with these bounds. */
3838 unsigned int indx;
3839 /* Low bound. */
3840 bfd_signed_vma low;
3841 /* High bound. */
3842 bfd_signed_vma high;
3843};
3844
3845/* This is a list of pending function parameter information. We don't
3846 output them until we see the first block. */
3847
3848struct ieee_pending_parm
3849{
3850 /* Next pending parameter. */
3851 struct ieee_pending_parm *next;
3852 /* Name. */
3853 const char *name;
3854 /* Type index. */
3855 unsigned int type;
3856 /* Whether the type is a reference. */
3857 boolean referencep;
3858 /* Kind. */
3859 enum debug_parm_kind kind;
3860 /* Value. */
3861 bfd_vma val;
3862};
3863
3864/* This is the handle passed down by debug_write. */
3865
3866struct ieee_handle
3867{
3868 /* BFD we are writing to. */
3869 bfd *abfd;
3870 /* Whether we got an error in a subroutine called via traverse or
3871 map_over_sections. */
3872 boolean error;
3873 /* Current data buffer list. */
3874 struct ieee_buflist *current;
3875 /* Current data buffer. */
3876 struct ieee_buf *curbuf;
3877 /* Filename of current compilation unit. */
3878 const char *filename;
3879 /* Module name of current compilation unit. */
3880 const char *modname;
3881 /* List of buffer for global types. */
3882 struct ieee_buflist global_types;
3883 /* List of finished data buffers. */
3884 struct ieee_buflist data;
3885 /* List of buffers for typedefs in the current compilation unit. */
3886 struct ieee_buflist types;
3887 /* List of buffers for variables and functions in the current
3888 compilation unit. */
3889 struct ieee_buflist vars;
3890 /* List of buffers for C++ class definitions in the current
3891 compilation unit. */
3892 struct ieee_buflist cxx;
3893 /* List of buffers for line numbers in the current compilation unit. */
3894 struct ieee_buflist linenos;
3895 /* Ranges for the current compilation unit. */
3896 struct ieee_range *ranges;
3897 /* Ranges for all debugging information. */
3898 struct ieee_range *global_ranges;
3899 /* Nested pending ranges. */
3900 struct ieee_range *pending_ranges;
3901 /* Type stack. */
3902 struct ieee_type_stack *type_stack;
3903 /* Next unallocated type index. */
3904 unsigned int type_indx;
3905 /* Next unallocated name index. */
3906 unsigned int name_indx;
3907 /* Typedefs. */
3908 struct ieee_name_type_hash_table typedefs;
3909 /* Tags. */
3910 struct ieee_name_type_hash_table tags;
3911 /* Enums. */
3912 struct ieee_defined_enum *enums;
3913 /* Modified versions of types. */
3914 struct ieee_modified_type *modified;
3915 /* Number of entries allocated in modified. */
3916 unsigned int modified_alloc;
3917 /* 4 byte complex type. */
3918 unsigned int complex_float_index;
3919 /* 8 byte complex type. */
3920 unsigned int complex_double_index;
3921 /* The depth of block nesting. This is 0 outside a function, and 1
3922 just after start_function is called. */
3923 unsigned int block_depth;
3924 /* The name of the current function. */
3925 const char *fnname;
3926 /* List of buffers for the type of the function we are currently
3927 writing out. */
3928 struct ieee_buflist fntype;
3929 /* List of buffers for the parameters of the function we are
3930 currently writing out. */
3931 struct ieee_buflist fnargs;
3932 /* Number of arguments written to fnargs. */
3933 unsigned int fnargcount;
3934 /* Pending function parameters. */
3935 struct ieee_pending_parm *pending_parms;
3936 /* Current line number filename. */
3937 const char *lineno_filename;
3938 /* Line number name index. */
3939 unsigned int lineno_name_indx;
3940 /* Filename of pending line number. */
3941 const char *pending_lineno_filename;
3942 /* Pending line number. */
3943 unsigned long pending_lineno;
3944 /* Address of pending line number. */
3945 bfd_vma pending_lineno_addr;
3946 /* Highest address seen at end of procedure. */
3947 bfd_vma highaddr;
3948};
3949
3950static boolean ieee_init_buffer
3951 PARAMS ((struct ieee_handle *, struct ieee_buflist *));
3952static boolean ieee_change_buffer
3953 PARAMS ((struct ieee_handle *, struct ieee_buflist *));
3954static boolean ieee_append_buffer
3955 PARAMS ((struct ieee_handle *, struct ieee_buflist *,
3956 struct ieee_buflist *));
3957static boolean ieee_real_write_byte PARAMS ((struct ieee_handle *, int));
3958static boolean ieee_write_2bytes PARAMS ((struct ieee_handle *, int));
3959static boolean ieee_write_number PARAMS ((struct ieee_handle *, bfd_vma));
3960static boolean ieee_write_id PARAMS ((struct ieee_handle *, const char *));
3961static boolean ieee_write_asn
3962 PARAMS ((struct ieee_handle *, unsigned int, bfd_vma));
3963static boolean ieee_write_atn65
3964 PARAMS ((struct ieee_handle *, unsigned int, const char *));
3965static boolean ieee_push_type
3966 PARAMS ((struct ieee_handle *, unsigned int, unsigned int, boolean,
3967 boolean));
3968static unsigned int ieee_pop_type PARAMS ((struct ieee_handle *));
3969static void ieee_pop_unused_type PARAMS ((struct ieee_handle *));
3970static unsigned int ieee_pop_type_used
3971 PARAMS ((struct ieee_handle *, boolean));
3972static boolean ieee_add_range
3973 PARAMS ((struct ieee_handle *, boolean, bfd_vma, bfd_vma));
3974static boolean ieee_start_range PARAMS ((struct ieee_handle *, bfd_vma));
3975static boolean ieee_end_range PARAMS ((struct ieee_handle *, bfd_vma));
3976static boolean ieee_define_type
3977 PARAMS ((struct ieee_handle *, unsigned int, boolean, boolean));
3978static boolean ieee_define_named_type
3979 PARAMS ((struct ieee_handle *, const char *, unsigned int, unsigned int,
3980 boolean, boolean, struct ieee_buflist *));
3981static struct ieee_modified_type *ieee_get_modified_info
3982 PARAMS ((struct ieee_handle *, unsigned int));
3983static struct bfd_hash_entry *ieee_name_type_newfunc
3984 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
3985static boolean ieee_write_undefined_tag
3986 PARAMS ((struct ieee_name_type_hash_entry *, PTR));
3987static boolean ieee_finish_compilation_unit PARAMS ((struct ieee_handle *));
3988static void ieee_add_bb11_blocks PARAMS ((bfd *, asection *, PTR));
3989static boolean ieee_add_bb11
3990 PARAMS ((struct ieee_handle *, asection *, bfd_vma, bfd_vma));
3991static boolean ieee_output_pending_parms PARAMS ((struct ieee_handle *));
3992static unsigned int ieee_vis_to_flags PARAMS ((enum debug_visibility));
3993static boolean ieee_class_method_var
3994 PARAMS ((struct ieee_handle *, const char *, enum debug_visibility, boolean,
3995 boolean, boolean, bfd_vma, boolean));
3996
3997static boolean ieee_start_compilation_unit PARAMS ((PTR, const char *));
3998static boolean ieee_start_source PARAMS ((PTR, const char *));
3999static boolean ieee_empty_type PARAMS ((PTR));
4000static boolean ieee_void_type PARAMS ((PTR));
4001static boolean ieee_int_type PARAMS ((PTR, unsigned int, boolean));
4002static boolean ieee_float_type PARAMS ((PTR, unsigned int));
4003static boolean ieee_complex_type PARAMS ((PTR, unsigned int));
4004static boolean ieee_bool_type PARAMS ((PTR, unsigned int));
4005static boolean ieee_enum_type
4006 PARAMS ((PTR, const char *, const char **, bfd_signed_vma *));
4007static boolean ieee_pointer_type PARAMS ((PTR));
4008static boolean ieee_function_type PARAMS ((PTR, int, boolean));
4009static boolean ieee_reference_type PARAMS ((PTR));
4010static boolean ieee_range_type PARAMS ((PTR, bfd_signed_vma, bfd_signed_vma));
4011static boolean ieee_array_type
4012 PARAMS ((PTR, bfd_signed_vma, bfd_signed_vma, boolean));
4013static boolean ieee_set_type PARAMS ((PTR, boolean));
4014static boolean ieee_offset_type PARAMS ((PTR));
4015static boolean ieee_method_type PARAMS ((PTR, boolean, int, boolean));
4016static boolean ieee_const_type PARAMS ((PTR));
4017static boolean ieee_volatile_type PARAMS ((PTR));
4018static boolean ieee_start_struct_type
4019 PARAMS ((PTR, const char *, unsigned int, boolean, unsigned int));
4020static boolean ieee_struct_field
4021 PARAMS ((PTR, const char *, bfd_vma, bfd_vma, enum debug_visibility));
4022static boolean ieee_end_struct_type PARAMS ((PTR));
4023static boolean ieee_start_class_type
4024 PARAMS ((PTR, const char *, unsigned int, boolean, unsigned int, boolean,
4025 boolean));
4026static boolean ieee_class_static_member
4027 PARAMS ((PTR, const char *, const char *, enum debug_visibility));
4028static boolean ieee_class_baseclass
4029 PARAMS ((PTR, bfd_vma, boolean, enum debug_visibility));
4030static boolean ieee_class_start_method PARAMS ((PTR, const char *));
4031static boolean ieee_class_method_variant
4032 PARAMS ((PTR, const char *, enum debug_visibility, boolean, boolean,
4033 bfd_vma, boolean));
4034static boolean ieee_class_static_method_variant
4035 PARAMS ((PTR, const char *, enum debug_visibility, boolean, boolean));
4036static boolean ieee_class_end_method PARAMS ((PTR));
4037static boolean ieee_end_class_type PARAMS ((PTR));
4038static boolean ieee_typedef_type PARAMS ((PTR, const char *));
4039static boolean ieee_tag_type
4040 PARAMS ((PTR, const char *, unsigned int, enum debug_type_kind));
4041static boolean ieee_typdef PARAMS ((PTR, const char *));
4042static boolean ieee_tag PARAMS ((PTR, const char *));
4043static boolean ieee_int_constant PARAMS ((PTR, const char *, bfd_vma));
4044static boolean ieee_float_constant PARAMS ((PTR, const char *, double));
4045static boolean ieee_typed_constant PARAMS ((PTR, const char *, bfd_vma));
4046static boolean ieee_variable
4047 PARAMS ((PTR, const char *, enum debug_var_kind, bfd_vma));
4048static boolean ieee_start_function PARAMS ((PTR, const char *, boolean));
4049static boolean ieee_function_parameter
4050 PARAMS ((PTR, const char *, enum debug_parm_kind, bfd_vma));
4051static boolean ieee_start_block PARAMS ((PTR, bfd_vma));
4052static boolean ieee_end_block PARAMS ((PTR, bfd_vma));
4053static boolean ieee_end_function PARAMS ((PTR));
4054static boolean ieee_lineno
4055 PARAMS ((PTR, const char *, unsigned long, bfd_vma));
4056
4057static const struct debug_write_fns ieee_fns =
4058{
4059 ieee_start_compilation_unit,
4060 ieee_start_source,
4061 ieee_empty_type,
4062 ieee_void_type,
4063 ieee_int_type,
4064 ieee_float_type,
4065 ieee_complex_type,
4066 ieee_bool_type,
4067 ieee_enum_type,
4068 ieee_pointer_type,
4069 ieee_function_type,
4070 ieee_reference_type,
4071 ieee_range_type,
4072 ieee_array_type,
4073 ieee_set_type,
4074 ieee_offset_type,
4075 ieee_method_type,
4076 ieee_const_type,
4077 ieee_volatile_type,
4078 ieee_start_struct_type,
4079 ieee_struct_field,
4080 ieee_end_struct_type,
4081 ieee_start_class_type,
4082 ieee_class_static_member,
4083 ieee_class_baseclass,
4084 ieee_class_start_method,
4085 ieee_class_method_variant,
4086 ieee_class_static_method_variant,
4087 ieee_class_end_method,
4088 ieee_end_class_type,
4089 ieee_typedef_type,
4090 ieee_tag_type,
4091 ieee_typdef,
4092 ieee_tag,
4093 ieee_int_constant,
4094 ieee_float_constant,
4095 ieee_typed_constant,
4096 ieee_variable,
4097 ieee_start_function,
4098 ieee_function_parameter,
4099 ieee_start_block,
4100 ieee_end_block,
4101 ieee_end_function,
4102 ieee_lineno
4103};
4104
4105/* Initialize a buffer to be empty. */
4106
4107/*ARGSUSED*/
4108static boolean
4109ieee_init_buffer (info, buflist)
4110 struct ieee_handle *info ATTRIBUTE_UNUSED;
4111 struct ieee_buflist *buflist;
4112{
4113 buflist->head = NULL;
4114 buflist->tail = NULL;
4115 return true;
4116}
4117
4118/* See whether a buffer list has any data. */
4119
4120#define ieee_buffer_emptyp(buflist) ((buflist)->head == NULL)
4121
4122/* Change the current buffer to a specified buffer chain. */
4123
4124static boolean
4125ieee_change_buffer (info, buflist)
4126 struct ieee_handle *info;
4127 struct ieee_buflist *buflist;
4128{
4129 if (buflist->head == NULL)
4130 {
4131 struct ieee_buf *buf;
4132
4133 buf = (struct ieee_buf *) xmalloc (sizeof *buf);
4134 buf->next = NULL;
4135 buf->c = 0;
4136 buflist->head = buf;
4137 buflist->tail = buf;
4138 }
4139
4140 info->current = buflist;
4141 info->curbuf = buflist->tail;
4142
4143 return true;
4144}
4145
4146/* Append a buffer chain. */
4147
4148/*ARGSUSED*/
4149static boolean
4150ieee_append_buffer (info, mainbuf, newbuf)
4151 struct ieee_handle *info ATTRIBUTE_UNUSED;
4152 struct ieee_buflist *mainbuf;
4153 struct ieee_buflist *newbuf;
4154{
4155 if (newbuf->head != NULL)
4156 {
4157 if (mainbuf->head == NULL)
4158 mainbuf->head = newbuf->head;
4159 else
4160 mainbuf->tail->next = newbuf->head;
4161 mainbuf->tail = newbuf->tail;
4162 }
4163 return true;
4164}
4165
4166/* Write a byte into the buffer. We use a macro for speed and a
4167 function for the complex cases. */
4168
4169#define ieee_write_byte(info, b) \
4170 ((info)->curbuf->c < IEEE_BUFSIZE \
4171 ? ((info)->curbuf->buf[(info)->curbuf->c++] = (b), true) \
4172 : ieee_real_write_byte ((info), (b)))
4173
4174static boolean
4175ieee_real_write_byte (info, b)
4176 struct ieee_handle *info;
4177 int b;
4178{
4179 if (info->curbuf->c >= IEEE_BUFSIZE)
4180 {
4181 struct ieee_buf *n;
4182
4183 n = (struct ieee_buf *) xmalloc (sizeof *n);
4184 n->next = NULL;
4185 n->c = 0;
4186 if (info->current->head == NULL)
4187 info->current->head = n;
4188 else
4189 info->current->tail->next = n;
4190 info->current->tail = n;
4191 info->curbuf = n;
4192 }
4193
4194 info->curbuf->buf[info->curbuf->c] = b;
4195 ++info->curbuf->c;
4196
4197 return true;
4198}
4199
4200/* Write out two bytes. */
4201
4202static boolean
4203ieee_write_2bytes (info, i)
4204 struct ieee_handle *info;
4205 int i;
4206{
4207 return (ieee_write_byte (info, i >> 8)
4208 && ieee_write_byte (info, i & 0xff));
4209}
4210
4211/* Write out an integer. */
4212
4213static boolean
4214ieee_write_number (info, v)
4215 struct ieee_handle *info;
4216 bfd_vma v;
4217{
4218 bfd_vma t;
4219 bfd_byte ab[20];
4220 bfd_byte *p;
4221 unsigned int c;
4222
4223 if (v <= (bfd_vma) ieee_number_end_enum)
4224 return ieee_write_byte (info, (int) v);
4225
4226 t = v;
4227 p = ab + sizeof ab;
4228 while (t != 0)
4229 {
4230 *--p = t & 0xff;
4231 t >>= 8;
4232 }
4233 c = (ab + 20) - p;
4234
4235 if (c > (unsigned int) (ieee_number_repeat_end_enum
4236 - ieee_number_repeat_start_enum))
4237 {
4238 fprintf (stderr, _("IEEE numeric overflow: 0x"));
4239 fprintf_vma (stderr, v);
4240 fprintf (stderr, "\n");
4241 return false;
4242 }
4243
4244 if (! ieee_write_byte (info, (int) ieee_number_repeat_start_enum + c))
4245 return false;
4246 for (; c > 0; --c, ++p)
4247 {
4248 if (! ieee_write_byte (info, *p))
4249 return false;
4250 }
4251
4252 return true;
4253}
4254
4255/* Write out a string. */
4256
4257static boolean
4258ieee_write_id (info, s)
4259 struct ieee_handle *info;
4260 const char *s;
4261{
4262 unsigned int len;
4263
4264 len = strlen (s);
4265 if (len <= 0x7f)
4266 {
4267 if (! ieee_write_byte (info, len))
4268 return false;
4269 }
4270 else if (len <= 0xff)
4271 {
4272 if (! ieee_write_byte (info, (int) ieee_extension_length_1_enum)
4273 || ! ieee_write_byte (info, len))
4274 return false;
4275 }
4276 else if (len <= 0xffff)
4277 {
4278 if (! ieee_write_byte (info, (int) ieee_extension_length_2_enum)
4279 || ! ieee_write_2bytes (info, len))
4280 return false;
4281 }
4282 else
4283 {
4284 fprintf (stderr, _("IEEE string length overflow: %u\n"), len);
4285 return false;
4286 }
4287
4288 for (; *s != '\0'; s++)
4289 if (! ieee_write_byte (info, *s))
4290 return false;
4291
4292 return true;
4293}
4294
4295/* Write out an ASN record. */
4296
4297static boolean
4298ieee_write_asn (info, indx, val)
4299 struct ieee_handle *info;
4300 unsigned int indx;
4301 bfd_vma val;
4302{
4303 return (ieee_write_2bytes (info, (int) ieee_asn_record_enum)
4304 && ieee_write_number (info, indx)
4305 && ieee_write_number (info, val));
4306}
4307
4308/* Write out an ATN65 record. */
4309
4310static boolean
4311ieee_write_atn65 (info, indx, s)
4312 struct ieee_handle *info;
4313 unsigned int indx;
4314 const char *s;
4315{
4316 return (ieee_write_2bytes (info, (int) ieee_atn_record_enum)
4317 && ieee_write_number (info, indx)
4318 && ieee_write_number (info, 0)
4319 && ieee_write_number (info, 65)
4320 && ieee_write_id (info, s));
4321}
4322
4323/* Push a type index onto the type stack. */
4324
4325static boolean
4326ieee_push_type (info, indx, size, unsignedp, localp)
4327 struct ieee_handle *info;
4328 unsigned int indx;
4329 unsigned int size;
4330 boolean unsignedp;
4331 boolean localp;
4332{
4333 struct ieee_type_stack *ts;
4334
4335 ts = (struct ieee_type_stack *) xmalloc (sizeof *ts);
4336 memset (ts, 0, sizeof *ts);
4337
4338 ts->type.indx = indx;
4339 ts->type.size = size;
4340 ts->type.unsignedp = unsignedp;
4341 ts->type.localp = localp;
4342
4343 ts->next = info->type_stack;
4344 info->type_stack = ts;
4345
4346 return true;
4347}
4348
4349/* Pop a type index off the type stack. */
4350
4351static unsigned int
4352ieee_pop_type (info)
4353 struct ieee_handle *info;
4354{
4355 return ieee_pop_type_used (info, true);
4356}
4357
4358/* Pop an unused type index off the type stack. */
4359
4360static void
4361ieee_pop_unused_type (info)
4362 struct ieee_handle *info;
4363{
4364 (void) ieee_pop_type_used (info, false);
4365}
4366
4367/* Pop a used or unused type index off the type stack. */
4368
4369static unsigned int
4370ieee_pop_type_used (info, used)
4371 struct ieee_handle *info;
4372 boolean used;
4373{
4374 struct ieee_type_stack *ts;
4375 unsigned int ret;
4376
4377 ts = info->type_stack;
4378 assert (ts != NULL);
4379
4380 /* If this is a function type, and we need it, we need to append the
4381 actual definition to the typedef block now. */
4382 if (used && ! ieee_buffer_emptyp (&ts->type.fndef))
4383 {
4384 struct ieee_buflist *buflist;
4385
4386 if (ts->type.localp)
4387 {
4388 /* Make sure we have started the types block. */
4389 if (ieee_buffer_emptyp (&info->types))
4390 {
4391 if (! ieee_change_buffer (info, &info->types)
4392 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
4393 || ! ieee_write_byte (info, 1)
4394 || ! ieee_write_number (info, 0)
4395 || ! ieee_write_id (info, info->modname))
4396 return false;
4397 }
4398 buflist = &info->types;
4399 }
4400 else
4401 {
4402 /* Make sure we started the global type block. */
4403 if (ieee_buffer_emptyp (&info->global_types))
4404 {
4405 if (! ieee_change_buffer (info, &info->global_types)
4406 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
4407 || ! ieee_write_byte (info, 2)
4408 || ! ieee_write_number (info, 0)
4409 || ! ieee_write_id (info, ""))
4410 return false;
4411 }
4412 buflist = &info->global_types;
4413 }
4414
4415 if (! ieee_append_buffer (info, buflist, &ts->type.fndef))
4416 return false;
4417 }
4418
4419 ret = ts->type.indx;
4420 info->type_stack = ts->next;
4421 free (ts);
4422 return ret;
4423}
4424
4425/* Add a range of bytes included in the current compilation unit. */
4426
4427static boolean
4428ieee_add_range (info, global, low, high)
4429 struct ieee_handle *info;
4430 boolean global;
4431 bfd_vma low;
4432 bfd_vma high;
4433{
4434 struct ieee_range **plist, *r, **pr;
4435
4436 if (low == (bfd_vma) -1 || high == (bfd_vma) -1 || low == high)
4437 return true;
4438
4439 if (global)
4440 plist = &info->global_ranges;
4441 else
4442 plist = &info->ranges;
4443
4444 for (r = *plist; r != NULL; r = r->next)
4445 {
4446 if (high >= r->low && low <= r->high)
4447 {
4448 /* The new range overlaps r. */
4449 if (low < r->low)
4450 r->low = low;
4451 if (high > r->high)
4452 r->high = high;
4453 pr = &r->next;
4454 while (*pr != NULL && (*pr)->low <= r->high)
4455 {
4456 struct ieee_range *n;
4457
4458 if ((*pr)->high > r->high)
4459 r->high = (*pr)->high;
4460 n = (*pr)->next;
4461 free (*pr);
4462 *pr = n;
4463 }
4464 return true;
4465 }
4466 }
4467
4468 r = (struct ieee_range *) xmalloc (sizeof *r);
4469 memset (r, 0, sizeof *r);
4470
4471 r->low = low;
4472 r->high = high;
4473
4474 /* Store the ranges sorted by address. */
4475 for (pr = plist; *pr != NULL; pr = &(*pr)->next)
4476 if ((*pr)->low > high)
4477 break;
4478 r->next = *pr;
4479 *pr = r;
4480
4481 return true;
4482}
4483
4484/* Start a new range for which we only have the low address. */
4485
4486static boolean
4487ieee_start_range (info, low)
4488 struct ieee_handle *info;
4489 bfd_vma low;
4490{
4491 struct ieee_range *r;
4492
4493 r = (struct ieee_range *) xmalloc (sizeof *r);
4494 memset (r, 0, sizeof *r);
4495 r->low = low;
4496 r->next = info->pending_ranges;
4497 info->pending_ranges = r;
4498 return true;
4499}
4500
4501/* Finish a range started by ieee_start_range. */
4502
4503static boolean
4504ieee_end_range (info, high)
4505 struct ieee_handle *info;
4506 bfd_vma high;
4507{
4508 struct ieee_range *r;
4509 bfd_vma low;
4510
4511 assert (info->pending_ranges != NULL);
4512 r = info->pending_ranges;
4513 low = r->low;
4514 info->pending_ranges = r->next;
4515 free (r);
4516 return ieee_add_range (info, false, low, high);
4517}
4518
4519/* Start defining a type. */
4520
4521static boolean
4522ieee_define_type (info, size, unsignedp, localp)
4523 struct ieee_handle *info;
4524 unsigned int size;
4525 boolean unsignedp;
4526 boolean localp;
4527{
4528 return ieee_define_named_type (info, (const char *) NULL,
4529 (unsigned int) -1, size, unsignedp,
4530 localp, (struct ieee_buflist *) NULL);
4531}
4532
4533/* Start defining a named type. */
4534
4535static boolean
4536ieee_define_named_type (info, name, indx, size, unsignedp, localp, buflist)
4537 struct ieee_handle *info;
4538 const char *name;
4539 unsigned int indx;
4540 unsigned int size;
4541 boolean unsignedp;
4542 boolean localp;
4543 struct ieee_buflist *buflist;
4544{
4545 unsigned int type_indx;
4546 unsigned int name_indx;
4547
4548 if (indx != (unsigned int) -1)
4549 type_indx = indx;
4550 else
4551 {
4552 type_indx = info->type_indx;
4553 ++info->type_indx;
4554 }
4555
4556 name_indx = info->name_indx;
4557 ++info->name_indx;
4558
4559 if (name == NULL)
4560 name = "";
4561
4562 /* If we were given a buffer, use it; otherwise, use either the
4563 local or the global type information, and make sure that the type
4564 block is started. */
4565 if (buflist != NULL)
4566 {
4567 if (! ieee_change_buffer (info, buflist))
4568 return false;
4569 }
4570 else if (localp)
4571 {
4572 if (! ieee_buffer_emptyp (&info->types))
4573 {
4574 if (! ieee_change_buffer (info, &info->types))
4575 return false;
4576 }
4577 else
4578 {
4579 if (! ieee_change_buffer (info, &info->types)
4580 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
4581 || ! ieee_write_byte (info, 1)
4582 || ! ieee_write_number (info, 0)
4583 || ! ieee_write_id (info, info->modname))
4584 return false;
4585 }
4586 }
4587 else
4588 {
4589 if (! ieee_buffer_emptyp (&info->global_types))
4590 {
4591 if (! ieee_change_buffer (info, &info->global_types))
4592 return false;
4593 }
4594 else
4595 {
4596 if (! ieee_change_buffer (info, &info->global_types)
4597 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
4598 || ! ieee_write_byte (info, 2)
4599 || ! ieee_write_number (info, 0)
4600 || ! ieee_write_id (info, ""))
4601 return false;
4602 }
4603 }
4604
4605 /* Push the new type on the type stack, write out an NN record, and
4606 write out the start of a TY record. The caller will then finish
4607 the TY record. */
4608 if (! ieee_push_type (info, type_indx, size, unsignedp, localp))
4609 return false;
4610
4611 return (ieee_write_byte (info, (int) ieee_nn_record)
4612 && ieee_write_number (info, name_indx)
4613 && ieee_write_id (info, name)
4614 && ieee_write_byte (info, (int) ieee_ty_record_enum)
4615 && ieee_write_number (info, type_indx)
4616 && ieee_write_byte (info, 0xce)
4617 && ieee_write_number (info, name_indx));
4618}
4619
4620/* Get an entry to the list of modified versions of a type. */
4621
4622static struct ieee_modified_type *
4623ieee_get_modified_info (info, indx)
4624 struct ieee_handle *info;
4625 unsigned int indx;
4626{
4627 if (indx >= info->modified_alloc)
4628 {
4629 unsigned int nalloc;
4630
4631 nalloc = info->modified_alloc;
4632 if (nalloc == 0)
4633 nalloc = 16;
4634 while (indx >= nalloc)
4635 nalloc *= 2;
4636 info->modified = ((struct ieee_modified_type *)
4637 xrealloc (info->modified,
4638 nalloc * sizeof *info->modified));
4639 memset (info->modified + info->modified_alloc, 0,
4640 (nalloc - info->modified_alloc) * sizeof *info->modified);
4641 info->modified_alloc = nalloc;
4642 }
4643
4644 return info->modified + indx;
4645}
4646
4647
4648/* Routines for the hash table mapping names to types. */
4649
4650/* Initialize an entry in the hash table. */
4651
4652static struct bfd_hash_entry *
4653ieee_name_type_newfunc (entry, table, string)
4654 struct bfd_hash_entry *entry;
4655 struct bfd_hash_table *table;
4656 const char *string;
4657{
4658 struct ieee_name_type_hash_entry *ret =
4659 (struct ieee_name_type_hash_entry *) entry;
4660
4661 /* Allocate the structure if it has not already been allocated by a
4662 subclass. */
4663 if (ret == NULL)
4664 ret = ((struct ieee_name_type_hash_entry *)
4665 bfd_hash_allocate (table, sizeof *ret));
4666 if (ret == NULL)
4667 return NULL;
4668
4669 /* Call the allocation method of the superclass. */
4670 ret = ((struct ieee_name_type_hash_entry *)
4671 bfd_hash_newfunc ((struct bfd_hash_entry *) ret, table, string));
4672 if (ret)
4673 {
4674 /* Set local fields. */
4675 ret->types = NULL;
4676 }
4677
4678 return (struct bfd_hash_entry *) ret;
4679}
4680
4681/* Look up an entry in the hash table. */
4682
4683#define ieee_name_type_hash_lookup(table, string, create, copy) \
4684 ((struct ieee_name_type_hash_entry *) \
4685 bfd_hash_lookup (&(table)->root, (string), (create), (copy)))
4686
4687/* Traverse the hash table. */
4688
4689#define ieee_name_type_hash_traverse(table, func, info) \
4690 (bfd_hash_traverse \
4691 (&(table)->root, \
4692 (boolean (*) PARAMS ((struct bfd_hash_entry *, PTR))) (func), \
4693 (info)))
4694
4695
4696/* The general routine to write out IEEE debugging information. */
4697
4698boolean
4699write_ieee_debugging_info (abfd, dhandle)
4700 bfd *abfd;
4701 PTR dhandle;
4702{
4703 struct ieee_handle info;
4704 asection *s;
4705 const char *err;
4706 struct ieee_buf *b;
4707
4708 memset (&info, 0, sizeof info);
4709 info.abfd = abfd;
4710 info.type_indx = 256;
4711 info.name_indx = 32;
4712
4713 if (! bfd_hash_table_init (&info.typedefs.root, ieee_name_type_newfunc)
4714 || ! bfd_hash_table_init (&info.tags.root, ieee_name_type_newfunc))
4715 return false;
4716
4717 if (! ieee_init_buffer (&info, &info.global_types)
4718 || ! ieee_init_buffer (&info, &info.data)
4719 || ! ieee_init_buffer (&info, &info.types)
4720 || ! ieee_init_buffer (&info, &info.vars)
4721 || ! ieee_init_buffer (&info, &info.cxx)
4722 || ! ieee_init_buffer (&info, &info.linenos)
4723 || ! ieee_init_buffer (&info, &info.fntype)
4724 || ! ieee_init_buffer (&info, &info.fnargs))
4725 return false;
4726
4727 if (! debug_write (dhandle, &ieee_fns, (PTR) &info))
4728 return false;
4729
4730 if (info.filename != NULL)
4731 {
4732 if (! ieee_finish_compilation_unit (&info))
4733 return false;
4734 }
4735
4736 /* Put any undefined tags in the global typedef information. */
4737 info.error = false;
4738 ieee_name_type_hash_traverse (&info.tags,
4739 ieee_write_undefined_tag,
4740 (PTR) &info);
4741 if (info.error)
4742 return false;
4743
4744 /* Prepend the global typedef information to the other data. */
4745 if (! ieee_buffer_emptyp (&info.global_types))
4746 {
4747 /* The HP debugger seems to have a bug in which it ignores the
4748 last entry in the global types, so we add a dummy entry. */
4749 if (! ieee_change_buffer (&info, &info.global_types)
4750 || ! ieee_write_byte (&info, (int) ieee_nn_record)
4751 || ! ieee_write_number (&info, info.name_indx)
4752 || ! ieee_write_id (&info, "")
4753 || ! ieee_write_byte (&info, (int) ieee_ty_record_enum)
4754 || ! ieee_write_number (&info, info.type_indx)
4755 || ! ieee_write_byte (&info, 0xce)
4756 || ! ieee_write_number (&info, info.name_indx)
4757 || ! ieee_write_number (&info, 'P')
4758 || ! ieee_write_number (&info, (int) builtin_void + 32)
4759 || ! ieee_write_byte (&info, (int) ieee_be_record_enum))
4760 return false;
4761
4762 if (! ieee_append_buffer (&info, &info.global_types, &info.data))
4763 return false;
4764 info.data = info.global_types;
4765 }
4766
4767 /* Make sure that we have declare BB11 blocks for each range in the
4768 file. They are added to info->vars. */
4769 info.error = false;
4770 if (! ieee_init_buffer (&info, &info.vars))
4771 return false;
4772 bfd_map_over_sections (abfd, ieee_add_bb11_blocks, (PTR) &info);
4773 if (info.error)
4774 return false;
4775 if (! ieee_buffer_emptyp (&info.vars))
4776 {
4777 if (! ieee_change_buffer (&info, &info.vars)
4778 || ! ieee_write_byte (&info, (int) ieee_be_record_enum))
4779 return false;
4780
4781 if (! ieee_append_buffer (&info, &info.data, &info.vars))
4782 return false;
4783 }
4784
4785 /* Now all the data is in info.data. Write it out to the BFD. We
4786 normally would need to worry about whether all the other sections
4787 are set up yet, but the IEEE backend will handle this particular
4788 case correctly regardless. */
4789 if (ieee_buffer_emptyp (&info.data))
4790 {
4791 /* There is no debugging information. */
4792 return true;
4793 }
4794 err = NULL;
4795 s = bfd_make_section (abfd, ".debug");
4796 if (s == NULL)
4797 err = "bfd_make_section";
4798 if (err == NULL)
4799 {
4800 if (! bfd_set_section_flags (abfd, s, SEC_DEBUGGING | SEC_HAS_CONTENTS))
4801 err = "bfd_set_section_flags";
4802 }
4803 if (err == NULL)
4804 {
4805 bfd_size_type size;
4806
4807 size = 0;
4808 for (b = info.data.head; b != NULL; b = b->next)
4809 size += b->c;
4810 if (! bfd_set_section_size (abfd, s, size))
4811 err = "bfd_set_section_size";
4812 }
4813 if (err == NULL)
4814 {
4815 file_ptr offset;
4816
4817 offset = 0;
4818 for (b = info.data.head; b != NULL; b = b->next)
4819 {
4820 if (! bfd_set_section_contents (abfd, s, b->buf, offset, b->c))
4821 {
4822 err = "bfd_set_section_contents";
4823 break;
4824 }
4825 offset += b->c;
4826 }
4827 }
4828
4829 if (err != NULL)
4830 {
4831 fprintf (stderr, "%s: %s: %s\n", bfd_get_filename (abfd), err,
4832 bfd_errmsg (bfd_get_error ()));
4833 return false;
4834 }
4835
4836 bfd_hash_table_free (&info.typedefs.root);
4837 bfd_hash_table_free (&info.tags.root);
4838
4839 return true;
4840}
4841
4842/* Write out information for an undefined tag. This is called via
4843 ieee_name_type_hash_traverse. */
4844
4845static boolean
4846ieee_write_undefined_tag (h, p)
4847 struct ieee_name_type_hash_entry *h;
4848 PTR p;
4849{
4850 struct ieee_handle *info = (struct ieee_handle *) p;
4851 struct ieee_name_type *nt;
4852
4853 for (nt = h->types; nt != NULL; nt = nt->next)
4854 {
4855 unsigned int name_indx;
4856 char code;
4857
4858 if (nt->kind == DEBUG_KIND_ILLEGAL)
4859 continue;
4860
4861 if (ieee_buffer_emptyp (&info->global_types))
4862 {
4863 if (! ieee_change_buffer (info, &info->global_types)
4864 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
4865 || ! ieee_write_byte (info, 2)
4866 || ! ieee_write_number (info, 0)
4867 || ! ieee_write_id (info, ""))
4868 {
4869 info->error = true;
4870 return false;
4871 }
4872 }
4873 else
4874 {
4875 if (! ieee_change_buffer (info, &info->global_types))
4876 {
4877 info->error = true;
4878 return false;
4879 }
4880 }
4881
4882 name_indx = info->name_indx;
4883 ++info->name_indx;
4884 if (! ieee_write_byte (info, (int) ieee_nn_record)
4885 || ! ieee_write_number (info, name_indx)
4886 || ! ieee_write_id (info, nt->type.name)
4887 || ! ieee_write_byte (info, (int) ieee_ty_record_enum)
4888 || ! ieee_write_number (info, nt->type.indx)
4889 || ! ieee_write_byte (info, 0xce)
4890 || ! ieee_write_number (info, name_indx))
4891 {
4892 info->error = true;
4893 return false;
4894 }
4895
4896 switch (nt->kind)
4897 {
4898 default:
4899 abort ();
4900 info->error = true;
4901 return false;
4902 case DEBUG_KIND_STRUCT:
4903 case DEBUG_KIND_CLASS:
4904 code = 'S';
4905 break;
4906 case DEBUG_KIND_UNION:
4907 case DEBUG_KIND_UNION_CLASS:
4908 code = 'U';
4909 break;
4910 case DEBUG_KIND_ENUM:
4911 code = 'E';
4912 break;
4913 }
4914 if (! ieee_write_number (info, code)
4915 || ! ieee_write_number (info, 0))
4916 {
4917 info->error = true;
4918 return false;
4919 }
4920 }
4921
4922 return true;
4923}
4924
4925/* Start writing out information for a compilation unit. */
4926
4927static boolean
4928ieee_start_compilation_unit (p, filename)
4929 PTR p;
4930 const char *filename;
4931{
4932 struct ieee_handle *info = (struct ieee_handle *) p;
4933 const char *modname;
4934#ifdef HAVE_DOS_BASED_FILE_SYSTEM
4935 const char *backslash;
4936#endif
4937 char *c, *s;
4938 unsigned int nindx;
4939
4940 if (info->filename != NULL)
4941 {
4942 if (! ieee_finish_compilation_unit (info))
4943 return false;
4944 }
4945
4946 info->filename = filename;
4947 modname = strrchr (filename, '/');
4948#ifdef HAVE_DOS_BASED_FILE_SYSTEM
4949 /* We could have a mixed forward/back slash case. */
4950 backslash = strrchr (filename, '\\');
4951 if (modname == NULL || (backslash != NULL && backslash > modname))
4952 modname = backslash;
4953#endif
4954
4955 if (modname != NULL)
4956 ++modname;
4957#ifdef HAVE_DOS_BASED_FILE_SYSTEM
4958 else if (filename[0] && filename[1] == ':')
4959 modname = filename + 2;
4960#endif
4961 else
4962 modname = filename;
4963
4964 c = xstrdup (modname);
4965 s = strrchr (c, '.');
4966 if (s != NULL)
4967 *s = '\0';
4968 info->modname = c;
4969
4970 if (! ieee_init_buffer (info, &info->types)
4971 || ! ieee_init_buffer (info, &info->vars)
4972 || ! ieee_init_buffer (info, &info->cxx)
4973 || ! ieee_init_buffer (info, &info->linenos))
4974 return false;
4975 info->ranges = NULL;
4976
4977 /* Always include a BB1 and a BB3 block. That is what the output of
4978 the MRI linker seems to look like. */
4979 if (! ieee_change_buffer (info, &info->types)
4980 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
4981 || ! ieee_write_byte (info, 1)
4982 || ! ieee_write_number (info, 0)
4983 || ! ieee_write_id (info, info->modname))
4984 return false;
4985
4986 nindx = info->name_indx;
4987 ++info->name_indx;
4988 if (! ieee_change_buffer (info, &info->vars)
4989 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
4990 || ! ieee_write_byte (info, 3)
4991 || ! ieee_write_number (info, 0)
4992 || ! ieee_write_id (info, info->modname))
4993 return false;
4994
4995 return true;
4996}
4997
4998/* Finish up a compilation unit. */
4999
5000static boolean
5001ieee_finish_compilation_unit (info)
5002 struct ieee_handle *info;
5003{
5004 struct ieee_range *r;
5005
5006 if (! ieee_buffer_emptyp (&info->types))
5007 {
5008 if (! ieee_change_buffer (info, &info->types)
5009 || ! ieee_write_byte (info, (int) ieee_be_record_enum))
5010 return false;
5011 }
5012
5013 if (! ieee_buffer_emptyp (&info->cxx))
5014 {
5015 /* Append any C++ information to the global function and
5016 variable information. */
5017 assert (! ieee_buffer_emptyp (&info->vars));
5018 if (! ieee_change_buffer (info, &info->vars))
5019 return false;
5020
5021 /* We put the pmisc records in a dummy procedure, just as the
5022 MRI compiler does. */
5023 if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
5024 || ! ieee_write_byte (info, 6)
5025 || ! ieee_write_number (info, 0)
5026 || ! ieee_write_id (info, "__XRYCPP")
5027 || ! ieee_write_number (info, 0)
5028 || ! ieee_write_number (info, 0)
5029 || ! ieee_write_number (info, info->highaddr - 1)
5030 || ! ieee_append_buffer (info, &info->vars, &info->cxx)
5031 || ! ieee_change_buffer (info, &info->vars)
5032 || ! ieee_write_byte (info, (int) ieee_be_record_enum)
5033 || ! ieee_write_number (info, info->highaddr - 1))
5034 return false;
5035 }
5036
5037 if (! ieee_buffer_emptyp (&info->vars))
5038 {
5039 if (! ieee_change_buffer (info, &info->vars)
5040 || ! ieee_write_byte (info, (int) ieee_be_record_enum))
5041 return false;
5042 }
5043
5044 if (info->pending_lineno_filename != NULL)
5045 {
5046 /* Force out the pending line number. */
5047 if (! ieee_lineno ((PTR) info, (const char *) NULL, 0, (bfd_vma) -1))
5048 return false;
5049 }
5050 if (! ieee_buffer_emptyp (&info->linenos))
5051 {
5052 if (! ieee_change_buffer (info, &info->linenos)
5053 || ! ieee_write_byte (info, (int) ieee_be_record_enum))
5054 return false;
5055 if (strcmp (info->filename, info->lineno_filename) != 0)
5056 {
5057 /* We were not in the main file. We just closed the
5058 included line number block, and now we must close the
5059 main line number block. */
5060 if (! ieee_write_byte (info, (int) ieee_be_record_enum))
5061 return false;
5062 }
5063 }
5064
5065 if (! ieee_append_buffer (info, &info->data, &info->types)
5066 || ! ieee_append_buffer (info, &info->data, &info->vars)
5067 || ! ieee_append_buffer (info, &info->data, &info->linenos))
5068 return false;
5069
5070 /* Build BB10/BB11 blocks based on the ranges we recorded. */
5071 if (! ieee_change_buffer (info, &info->data))
5072 return false;
5073
5074 if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
5075 || ! ieee_write_byte (info, 10)
5076 || ! ieee_write_number (info, 0)
5077 || ! ieee_write_id (info, info->modname)
5078 || ! ieee_write_id (info, "")
5079 || ! ieee_write_number (info, 0)
5080 || ! ieee_write_id (info, "GNU objcopy"))
5081 return false;
5082
5083 for (r = info->ranges; r != NULL; r = r->next)
5084 {
5085 bfd_vma low, high;
5086 asection *s;
5087 int kind;
5088
5089 low = r->low;
5090 high = r->high;
5091
5092 /* Find the section corresponding to this range. */
5093 for (s = info->abfd->sections; s != NULL; s = s->next)
5094 {
5095 if (bfd_get_section_vma (info->abfd, s) <= low
5096 && high <= (bfd_get_section_vma (info->abfd, s)
5097 + bfd_section_size (info->abfd, s)))
5098 break;
5099 }
5100
5101 if (s == NULL)
5102 {
5103 /* Just ignore this range. */
5104 continue;
5105 }
5106
5107 /* Coalesce ranges if it seems reasonable. */
5108 while (r->next != NULL
5109 && high + 0x1000 >= r->next->low
5110 && (r->next->high
5111 <= (bfd_get_section_vma (info->abfd, s)
5112 + bfd_section_size (info->abfd, s))))
5113 {
5114 r = r->next;
5115 high = r->high;
5116 }
5117
5118 if ((s->flags & SEC_CODE) != 0)
5119 kind = 1;
5120 else if ((s->flags & SEC_READONLY) != 0)
5121 kind = 3;
5122 else
5123 kind = 2;
5124
5125 if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
5126 || ! ieee_write_byte (info, 11)
5127 || ! ieee_write_number (info, 0)
5128 || ! ieee_write_id (info, "")
5129 || ! ieee_write_number (info, kind)
5130 || ! ieee_write_number (info, s->index + IEEE_SECTION_NUMBER_BASE)
5131 || ! ieee_write_number (info, low)
5132 || ! ieee_write_byte (info, (int) ieee_be_record_enum)
5133 || ! ieee_write_number (info, high - low))
5134 return false;
5135
5136 /* Add this range to the list of global ranges. */
5137 if (! ieee_add_range (info, true, low, high))
5138 return false;
5139 }
5140
5141 if (! ieee_write_byte (info, (int) ieee_be_record_enum))
5142 return false;
5143
5144 return true;
5145}
5146
5147/* Add BB11 blocks describing each range that we have not already
5148 described. */
5149
5150static void
5151ieee_add_bb11_blocks (abfd, sec, data)
5152 bfd *abfd ATTRIBUTE_UNUSED;
5153 asection *sec;
5154 PTR data;
5155{
5156 struct ieee_handle *info = (struct ieee_handle *) data;
5157 bfd_vma low, high;
5158 struct ieee_range *r;
5159
5160 low = bfd_get_section_vma (abfd, sec);
5161 high = low + bfd_section_size (abfd, sec);
5162
5163 /* Find the first range at or after this section. The ranges are
5164 sorted by address. */
5165 for (r = info->global_ranges; r != NULL; r = r->next)
5166 if (r->high > low)
5167 break;
5168
5169 while (low < high)
5170 {
5171 if (r == NULL || r->low >= high)
5172 {
5173 if (! ieee_add_bb11 (info, sec, low, high))
5174 info->error = true;
5175 return;
5176 }
5177
5178 if (low < r->low
5179 && r->low - low > 0x100)
5180 {
5181 if (! ieee_add_bb11 (info, sec, low, r->low))
5182 {
5183 info->error = true;
5184 return;
5185 }
5186 }
5187 low = r->high;
5188
5189 r = r->next;
5190 }
5191}
5192
5193/* Add a single BB11 block for a range. We add it to info->vars. */
5194
5195static boolean
5196ieee_add_bb11 (info, sec, low, high)
5197 struct ieee_handle *info;
5198 asection *sec;
5199 bfd_vma low;
5200 bfd_vma high;
5201{
5202 int kind;
5203
5204 if (! ieee_buffer_emptyp (&info->vars))
5205 {
5206 if (! ieee_change_buffer (info, &info->vars))
5207 return false;
5208 }
5209 else
5210 {
5211 const char *filename, *modname;
5212#ifdef HAVE_DOS_BASED_FILE_SYSTEM
5213 const char *backslash;
5214#endif
5215 char *c, *s;
5216
5217 /* Start the enclosing BB10 block. */
5218 filename = bfd_get_filename (info->abfd);
5219 modname = strrchr (filename, '/');
5220#ifdef HAVE_DOS_BASED_FILE_SYSTEM
5221 backslash = strrchr (filename, '\\');
5222 if (modname == NULL || (backslash != NULL && backslash > modname))
5223 modname = backslash;
5224#endif
5225
5226 if (modname != NULL)
5227 ++modname;
5228#ifdef HAVE_DOS_BASED_FILE_SYSTEM
5229 else if (filename[0] && filename[1] == ':')
5230 modname = filename + 2;
5231#endif
5232 else
5233 modname = filename;
5234
5235 c = xstrdup (modname);
5236 s = strrchr (c, '.');
5237 if (s != NULL)
5238 *s = '\0';
5239
5240 if (! ieee_change_buffer (info, &info->vars)
5241 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
5242 || ! ieee_write_byte (info, 10)
5243 || ! ieee_write_number (info, 0)
5244 || ! ieee_write_id (info, c)
5245 || ! ieee_write_id (info, "")
5246 || ! ieee_write_number (info, 0)
5247 || ! ieee_write_id (info, "GNU objcopy"))
5248 return false;
5249
5250 free (c);
5251 }
5252
5253 if ((sec->flags & SEC_CODE) != 0)
5254 kind = 1;
5255 else if ((sec->flags & SEC_READONLY) != 0)
5256 kind = 3;
5257 else
5258 kind = 2;
5259
5260 if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
5261 || ! ieee_write_byte (info, 11)
5262 || ! ieee_write_number (info, 0)
5263 || ! ieee_write_id (info, "")
5264 || ! ieee_write_number (info, kind)
5265 || ! ieee_write_number (info, sec->index + IEEE_SECTION_NUMBER_BASE)
5266 || ! ieee_write_number (info, low)
5267 || ! ieee_write_byte (info, (int) ieee_be_record_enum)
5268 || ! ieee_write_number (info, high - low))
5269 return false;
5270
5271 return true;
5272}
5273
5274/* Start recording information from a particular source file. This is
5275 used to record which file defined which types, variables, etc. It
5276 is not used for line numbers, since the lineno entry point passes
5277 down the file name anyhow. IEEE debugging information doesn't seem
5278 to store this information anywhere. */
5279
5280/*ARGSUSED*/
5281static boolean
5282ieee_start_source (p, filename)
5283 PTR p ATTRIBUTE_UNUSED;
5284 const char *filename ATTRIBUTE_UNUSED;
5285{
5286 return true;
5287}
5288
5289/* Make an empty type. */
5290
5291static boolean
5292ieee_empty_type (p)
5293 PTR p;
5294{
5295 struct ieee_handle *info = (struct ieee_handle *) p;
5296
5297 return ieee_push_type (info, (int) builtin_unknown, 0, false, false);
5298}
5299
5300/* Make a void type. */
5301
5302static boolean
5303ieee_void_type (p)
5304 PTR p;
5305{
5306 struct ieee_handle *info = (struct ieee_handle *) p;
5307
5308 return ieee_push_type (info, (int) builtin_void, 0, false, false);
5309}
5310
5311/* Make an integer type. */
5312
5313static boolean
5314ieee_int_type (p, size, unsignedp)
5315 PTR p;
5316 unsigned int size;
5317 boolean unsignedp;
5318{
5319 struct ieee_handle *info = (struct ieee_handle *) p;
5320 unsigned int indx;
5321
5322 switch (size)
5323 {
5324 case 1:
5325 indx = (int) builtin_signed_char;
5326 break;
5327 case 2:
5328 indx = (int) builtin_signed_short_int;
5329 break;
5330 case 4:
5331 indx = (int) builtin_signed_long;
5332 break;
5333 case 8:
5334 indx = (int) builtin_signed_long_long;
5335 break;
5336 default:
5337 fprintf (stderr, _("IEEE unsupported integer type size %u\n"), size);
5338 return false;
5339 }
5340
5341 if (unsignedp)
5342 ++indx;
5343
5344 return ieee_push_type (info, indx, size, unsignedp, false);
5345}
5346
5347/* Make a floating point type. */
5348
5349static boolean
5350ieee_float_type (p, size)
5351 PTR p;
5352 unsigned int size;
5353{
5354 struct ieee_handle *info = (struct ieee_handle *) p;
5355 unsigned int indx;
5356
5357 switch (size)
5358 {
5359 case 4:
5360 indx = (int) builtin_float;
5361 break;
5362 case 8:
5363 indx = (int) builtin_double;
5364 break;
5365 case 12:
5366 /* FIXME: This size really depends upon the processor. */
5367 indx = (int) builtin_long_double;
5368 break;
5369 case 16:
5370 indx = (int) builtin_long_long_double;
5371 break;
5372 default:
5373 fprintf (stderr, _("IEEE unsupported float type size %u\n"), size);
5374 return false;
5375 }
5376
5377 return ieee_push_type (info, indx, size, false, false);
5378}
5379
5380/* Make a complex type. */
5381
5382static boolean
5383ieee_complex_type (p, size)
5384 PTR p;
5385 unsigned int size;
5386{
5387 struct ieee_handle *info = (struct ieee_handle *) p;
5388 char code;
5389
5390 switch (size)
5391 {
5392 case 4:
5393 if (info->complex_float_index != 0)
5394 return ieee_push_type (info, info->complex_float_index, size * 2,
5395 false, false);
5396 code = 'c';
5397 break;
5398 case 12:
5399 case 16:
5400 /* These cases can be output by gcc -gstabs. Outputting the
5401 wrong type is better than crashing. */
5402 case 8:
5403 if (info->complex_double_index != 0)
5404 return ieee_push_type (info, info->complex_double_index, size * 2,
5405 false, false);
5406 code = 'd';
5407 break;
5408 default:
5409 fprintf (stderr, _("IEEE unsupported complex type size %u\n"), size);
5410 return false;
5411 }
5412
5413 /* FIXME: I don't know what the string is for. */
5414 if (! ieee_define_type (info, size * 2, false, false)
5415 || ! ieee_write_number (info, code)
5416 || ! ieee_write_id (info, ""))
5417 return false;
5418
5419 if (size == 4)
5420 info->complex_float_index = info->type_stack->type.indx;
5421 else
5422 info->complex_double_index = info->type_stack->type.indx;
5423
5424 return true;
5425}
5426
5427/* Make a boolean type. IEEE doesn't support these, so we just make
5428 an integer type instead. */
5429
5430static boolean
5431ieee_bool_type (p, size)
5432 PTR p;
5433 unsigned int size;
5434{
5435 return ieee_int_type (p, size, true);
5436}
5437
5438/* Make an enumeration. */
5439
5440static boolean
5441ieee_enum_type (p, tag, names, vals)
5442 PTR p;
5443 const char *tag;
5444 const char **names;
5445 bfd_signed_vma *vals;
5446{
5447 struct ieee_handle *info = (struct ieee_handle *) p;
5448 struct ieee_defined_enum *e;
5449 boolean localp, simple;
5450 unsigned int indx;
5451 int i = 0;
5452
5453 localp = false;
5454 indx = (unsigned int) -1;
5455 for (e = info->enums; e != NULL; e = e->next)
5456 {
5457 if (tag == NULL)
5458 {
5459 if (e->tag != NULL)
5460 continue;
5461 }
5462 else
5463 {
5464 if (e->tag == NULL
5465 || tag[0] != e->tag[0]
5466 || strcmp (tag, e->tag) != 0)
5467 continue;
5468 }
5469
5470 if (! e->defined)
5471 {
5472 /* This enum tag has been seen but not defined. */
5473 indx = e->indx;
5474 break;
5475 }
5476
5477 if (names != NULL && e->names != NULL)
5478 {
5479 for (i = 0; names[i] != NULL && e->names[i] != NULL; i++)
5480 {
5481 if (names[i][0] != e->names[i][0]
5482 || vals[i] != e->vals[i]
5483 || strcmp (names[i], e->names[i]) != 0)
5484 break;
5485 }
5486 }
5487
5488 if ((names == NULL && e->names == NULL)
5489 || (names != NULL
5490 && e->names != NULL
5491 && names[i] == NULL
5492 && e->names[i] == NULL))
5493 {
5494 /* We've seen this enum before. */
5495 return ieee_push_type (info, e->indx, 0, true, false);
5496 }
5497
5498 if (tag != NULL)
5499 {
5500 /* We've already seen an enum of the same name, so we must make
5501 sure to output this one locally. */
5502 localp = true;
5503 break;
5504 }
5505 }
5506
5507 /* If this is a simple enumeration, in which the values start at 0
5508 and always increment by 1, we can use type E. Otherwise we must
5509 use type N. */
5510
5511 simple = true;
5512 if (names != NULL)
5513 {
5514 for (i = 0; names[i] != NULL; i++)
5515 {
5516 if (vals[i] != i)
5517 {
5518 simple = false;
5519 break;
5520 }
5521 }
5522 }
5523
5524 if (! ieee_define_named_type (info, tag, indx, 0, true, localp,
5525 (struct ieee_buflist *) NULL)
5526 || ! ieee_write_number (info, simple ? 'E' : 'N'))
5527 return false;
5528 if (simple)
5529 {
5530 /* FIXME: This is supposed to be the enumeration size, but we
5531 don't store that. */
5532 if (! ieee_write_number (info, 4))
5533 return false;
5534 }
5535 if (names != NULL)
5536 {
5537 for (i = 0; names[i] != NULL; i++)
5538 {
5539 if (! ieee_write_id (info, names[i]))
5540 return false;
5541 if (! simple)
5542 {
5543 if (! ieee_write_number (info, vals[i]))
5544 return false;
5545 }
5546 }
5547 }
5548
5549 if (! localp)
5550 {
5551 if (indx == (unsigned int) -1)
5552 {
5553 e = (struct ieee_defined_enum *) xmalloc (sizeof *e);
5554 memset (e, 0, sizeof *e);
5555 e->indx = info->type_stack->type.indx;
5556 e->tag = tag;
5557
5558 e->next = info->enums;
5559 info->enums = e;
5560 }
5561
5562 e->names = names;
5563 e->vals = vals;
5564 e->defined = true;
5565 }
5566
5567 return true;
5568}
5569
5570/* Make a pointer type. */
5571
5572static boolean
5573ieee_pointer_type (p)
5574 PTR p;
5575{
5576 struct ieee_handle *info = (struct ieee_handle *) p;
5577 boolean localp;
5578 unsigned int indx;
5579 struct ieee_modified_type *m = NULL;
5580
5581 localp = info->type_stack->type.localp;
5582 indx = ieee_pop_type (info);
5583
5584 /* A pointer to a simple builtin type can be obtained by adding 32.
5585 FIXME: Will this be a short pointer, and will that matter? */
5586 if (indx < 32)
5587 return ieee_push_type (info, indx + 32, 0, true, false);
5588
5589 if (! localp)
5590 {
5591 m = ieee_get_modified_info (p, indx);
5592 if (m == NULL)
5593 return false;
5594
5595 /* FIXME: The size should depend upon the architecture. */
5596 if (m->pointer > 0)
5597 return ieee_push_type (info, m->pointer, 4, true, false);
5598 }
5599
5600 if (! ieee_define_type (info, 4, true, localp)
5601 || ! ieee_write_number (info, 'P')
5602 || ! ieee_write_number (info, indx))
5603 return false;
5604
5605 if (! localp)
5606 m->pointer = info->type_stack->type.indx;
5607
5608 return true;
5609}
5610
5611/* Make a function type. This will be called for a method, but we
5612 don't want to actually add it to the type table in that case. We
5613 handle this by defining the type in a private buffer, and only
5614 adding that buffer to the typedef block if we are going to use it. */
5615
5616static boolean
5617ieee_function_type (p, argcount, varargs)
5618 PTR p;
5619 int argcount;
5620 boolean varargs;
5621{
5622 struct ieee_handle *info = (struct ieee_handle *) p;
5623 boolean localp;
5624 unsigned int *args = NULL;
5625 int i;
5626 unsigned int retindx;
5627 struct ieee_buflist fndef;
5628 struct ieee_modified_type *m;
5629
5630 localp = false;
5631
5632 if (argcount > 0)
5633 {
5634 args = (unsigned int *) xmalloc (argcount * sizeof *args);
5635 for (i = argcount - 1; i >= 0; i--)
5636 {
5637 if (info->type_stack->type.localp)
5638 localp = true;
5639 args[i] = ieee_pop_type (info);
5640 }
5641 }
5642 else if (argcount < 0)
5643 varargs = false;
5644
5645 if (info->type_stack->type.localp)
5646 localp = true;
5647 retindx = ieee_pop_type (info);
5648
5649 m = NULL;
5650 if (argcount < 0 && ! localp)
5651 {
5652 m = ieee_get_modified_info (p, retindx);
5653 if (m == NULL)
5654 return false;
5655
5656 if (m->function > 0)
5657 return ieee_push_type (info, m->function, 0, true, false);
5658 }
5659
5660 /* An attribute of 0x41 means that the frame and push mask are
5661 unknown. */
5662 if (! ieee_init_buffer (info, &fndef)
5663 || ! ieee_define_named_type (info, (const char *) NULL,
5664 (unsigned int) -1, 0, true, localp,
5665 &fndef)
5666 || ! ieee_write_number (info, 'x')
5667 || ! ieee_write_number (info, 0x41)
5668 || ! ieee_write_number (info, 0)
5669 || ! ieee_write_number (info, 0)
5670 || ! ieee_write_number (info, retindx)
5671 || ! ieee_write_number (info, (bfd_vma) argcount + (varargs ? 1 : 0)))
5672 return false;
5673 if (argcount > 0)
5674 {
5675 for (i = 0; i < argcount; i++)
5676 if (! ieee_write_number (info, args[i]))
5677 return false;
5678 free (args);
5679 }
5680 if (varargs)
5681 {
5682 /* A varargs function is represented by writing out the last
5683 argument as type void *, although this makes little sense. */
5684 if (! ieee_write_number (info, (bfd_vma) builtin_void + 32))
5685 return false;
5686 }
5687
5688 if (! ieee_write_number (info, 0))
5689 return false;
5690
5691 /* We wrote the information into fndef, in case we don't need it.
5692 It will be appended to info->types by ieee_pop_type. */
5693 info->type_stack->type.fndef = fndef;
5694
5695 if (m != NULL)
5696 m->function = info->type_stack->type.indx;
5697
5698 return true;
5699}
5700
5701/* Make a reference type. */
5702
5703static boolean
5704ieee_reference_type (p)
5705 PTR p;
5706{
5707 struct ieee_handle *info = (struct ieee_handle *) p;
5708
5709 /* IEEE appears to record a normal pointer type, and then use a
5710 pmisc record to indicate that it is really a reference. */
5711
5712 if (! ieee_pointer_type (p))
5713 return false;
5714 info->type_stack->type.referencep = true;
5715 return true;
5716}
5717
5718/* Make a range type. */
5719
5720static boolean
5721ieee_range_type (p, low, high)
5722 PTR p;
5723 bfd_signed_vma low;
5724 bfd_signed_vma high;
5725{
5726 struct ieee_handle *info = (struct ieee_handle *) p;
5727 unsigned int size;
5728 boolean unsignedp, localp;
5729
5730 size = info->type_stack->type.size;
5731 unsignedp = info->type_stack->type.unsignedp;
5732 localp = info->type_stack->type.localp;
5733 ieee_pop_unused_type (info);
5734 return (ieee_define_type (info, size, unsignedp, localp)
5735 && ieee_write_number (info, 'R')
5736 && ieee_write_number (info, (bfd_vma) low)
5737 && ieee_write_number (info, (bfd_vma) high)
5738 && ieee_write_number (info, unsignedp ? 0 : 1)
5739 && ieee_write_number (info, size));
5740}
5741
5742/* Make an array type. */
5743
5744/*ARGSUSED*/
5745static boolean
5746ieee_array_type (p, low, high, stringp)
5747 PTR p;
5748 bfd_signed_vma low;
5749 bfd_signed_vma high;
5750 boolean stringp ATTRIBUTE_UNUSED;
5751{
5752 struct ieee_handle *info = (struct ieee_handle *) p;
5753 unsigned int eleindx;
5754 boolean localp;
5755 unsigned int size;
5756 struct ieee_modified_type *m = NULL;
5757 struct ieee_modified_array_type *a;
5758
5759 /* IEEE does not store the range, so we just ignore it. */
5760 ieee_pop_unused_type (info);
5761 localp = info->type_stack->type.localp;
5762 size = info->type_stack->type.size;
5763 eleindx = ieee_pop_type (info);
5764
5765 /* If we don't know the range, treat the size as exactly one
5766 element. */
5767 if (low < high)
5768 size *= (high - low) + 1;
5769
5770 if (! localp)
5771 {
5772 m = ieee_get_modified_info (info, eleindx);
5773 if (m == NULL)
5774 return false;
5775
5776 for (a = m->arrays; a != NULL; a = a->next)
5777 {
5778 if (a->low == low && a->high == high)
5779 return ieee_push_type (info, a->indx, size, false, false);
5780 }
5781 }
5782
5783 if (! ieee_define_type (info, size, false, localp)
5784 || ! ieee_write_number (info, low == 0 ? 'Z' : 'C')
5785 || ! ieee_write_number (info, eleindx))
5786 return false;
5787 if (low != 0)
5788 {
5789 if (! ieee_write_number (info, low))
5790 return false;
5791 }
5792
5793 if (! ieee_write_number (info, high + 1))
5794 return false;
5795
5796 if (! localp)
5797 {
5798 a = (struct ieee_modified_array_type *) xmalloc (sizeof *a);
5799 memset (a, 0, sizeof *a);
5800
5801 a->indx = info->type_stack->type.indx;
5802 a->low = low;
5803 a->high = high;
5804
5805 a->next = m->arrays;
5806 m->arrays = a;
5807 }
5808
5809 return true;
5810}
5811
5812/* Make a set type. */
5813
5814static boolean
5815ieee_set_type (p, bitstringp)
5816 PTR p;
5817 boolean bitstringp ATTRIBUTE_UNUSED;
5818{
5819 struct ieee_handle *info = (struct ieee_handle *) p;
5820 boolean localp;
5821 unsigned int eleindx;
5822
5823 localp = info->type_stack->type.localp;
5824 eleindx = ieee_pop_type (info);
5825
5826 /* FIXME: We don't know the size, so we just use 4. */
5827
5828 return (ieee_define_type (info, 0, true, localp)
5829 && ieee_write_number (info, 's')
5830 && ieee_write_number (info, 4)
5831 && ieee_write_number (info, eleindx));
5832}
5833
5834/* Make an offset type. */
5835
5836static boolean
5837ieee_offset_type (p)
5838 PTR p;
5839{
5840 struct ieee_handle *info = (struct ieee_handle *) p;
5841 unsigned int targetindx, baseindx;
5842
5843 targetindx = ieee_pop_type (info);
5844 baseindx = ieee_pop_type (info);
5845
5846 /* FIXME: The MRI C++ compiler does not appear to generate any
5847 useful type information about an offset type. It just records a
5848 pointer to member as an integer. The MRI/HP IEEE spec does
5849 describe a pmisc record which can be used for a pointer to
5850 member. Unfortunately, it does not describe the target type,
5851 which seems pretty important. I'm going to punt this for now. */
5852
5853 return ieee_int_type (p, 4, true);
5854}
5855
5856/* Make a method type. */
5857
5858static boolean
5859ieee_method_type (p, domain, argcount, varargs)
5860 PTR p;
5861 boolean domain;
5862 int argcount;
5863 boolean varargs;
5864{
5865 struct ieee_handle *info = (struct ieee_handle *) p;
5866
5867 /* FIXME: The MRI/HP IEEE spec defines a pmisc record to use for a
5868 method, but the definition is incomplete. We just output an 'x'
5869 type. */
5870
5871 if (domain)
5872 ieee_pop_unused_type (info);
5873
5874 return ieee_function_type (p, argcount, varargs);
5875}
5876
5877/* Make a const qualified type. */
5878
5879static boolean
5880ieee_const_type (p)
5881 PTR p;
5882{
5883 struct ieee_handle *info = (struct ieee_handle *) p;
5884 unsigned int size;
5885 boolean unsignedp, localp;
5886 unsigned int indx;
5887 struct ieee_modified_type *m = NULL;
5888
5889 size = info->type_stack->type.size;
5890 unsignedp = info->type_stack->type.unsignedp;
5891 localp = info->type_stack->type.localp;
5892 indx = ieee_pop_type (info);
5893
5894 if (! localp)
5895 {
5896 m = ieee_get_modified_info (info, indx);
5897 if (m == NULL)
5898 return false;
5899
5900 if (m->const_qualified > 0)
5901 return ieee_push_type (info, m->const_qualified, size, unsignedp,
5902 false);
5903 }
5904
5905 if (! ieee_define_type (info, size, unsignedp, localp)
5906 || ! ieee_write_number (info, 'n')
5907 || ! ieee_write_number (info, 1)
5908 || ! ieee_write_number (info, indx))
5909 return false;
5910
5911 if (! localp)
5912 m->const_qualified = info->type_stack->type.indx;
5913
5914 return true;
5915}
5916
5917/* Make a volatile qualified type. */
5918
5919static boolean
5920ieee_volatile_type (p)
5921 PTR p;
5922{
5923 struct ieee_handle *info = (struct ieee_handle *) p;
5924 unsigned int size;
5925 boolean unsignedp, localp;
5926 unsigned int indx;
5927 struct ieee_modified_type *m = NULL;
5928
5929 size = info->type_stack->type.size;
5930 unsignedp = info->type_stack->type.unsignedp;
5931 localp = info->type_stack->type.localp;
5932 indx = ieee_pop_type (info);
5933
5934 if (! localp)
5935 {
5936 m = ieee_get_modified_info (info, indx);
5937 if (m == NULL)
5938 return false;
5939
5940 if (m->volatile_qualified > 0)
5941 return ieee_push_type (info, m->volatile_qualified, size, unsignedp,
5942 false);
5943 }
5944
5945 if (! ieee_define_type (info, size, unsignedp, localp)
5946 || ! ieee_write_number (info, 'n')
5947 || ! ieee_write_number (info, 2)
5948 || ! ieee_write_number (info, indx))
5949 return false;
5950
5951 if (! localp)
5952 m->volatile_qualified = info->type_stack->type.indx;
5953
5954 return true;
5955}
5956
5957/* Convert an enum debug_visibility into a CXXFLAGS value. */
5958
5959static unsigned int
5960ieee_vis_to_flags (visibility)
5961 enum debug_visibility visibility;
5962{
5963 switch (visibility)
5964 {
5965 default:
5966 abort ();
5967 case DEBUG_VISIBILITY_PUBLIC:
5968 return CXXFLAGS_VISIBILITY_PUBLIC;
5969 case DEBUG_VISIBILITY_PRIVATE:
5970 return CXXFLAGS_VISIBILITY_PRIVATE;
5971 case DEBUG_VISIBILITY_PROTECTED:
5972 return CXXFLAGS_VISIBILITY_PROTECTED;
5973 }
5974 /*NOTREACHED*/
5975}
5976
5977/* Start defining a struct type. We build it in the strdef field on
5978 the stack, to avoid confusing type definitions required by the
5979 fields with the struct type itself. */
5980
5981static boolean
5982ieee_start_struct_type (p, tag, id, structp, size)
5983 PTR p;
5984 const char *tag;
5985 unsigned int id;
5986 boolean structp;
5987 unsigned int size;
5988{
5989 struct ieee_handle *info = (struct ieee_handle *) p;
5990 boolean localp, ignorep;
5991 boolean copy;
5992 char ab[20];
5993 const char *look;
5994 struct ieee_name_type_hash_entry *h;
5995 struct ieee_name_type *nt, *ntlook;
5996 struct ieee_buflist strdef;
5997
5998 localp = false;
5999 ignorep = false;
6000
6001 /* We need to create a tag for internal use even if we don't want
6002 one for external use. This will let us refer to an anonymous
6003 struct. */
6004 if (tag != NULL)
6005 {
6006 look = tag;
6007 copy = false;
6008 }
6009 else
6010 {
6011 sprintf (ab, "__anon%u", id);
6012 look = ab;
6013 copy = true;
6014 }
6015
6016 /* If we already have references to the tag, we must use the
6017 existing type index. */
6018 h = ieee_name_type_hash_lookup (&info->tags, look, true, copy);
6019 if (h == NULL)
6020 return false;
6021
6022 nt = NULL;
6023 for (ntlook = h->types; ntlook != NULL; ntlook = ntlook->next)
6024 {
6025 if (ntlook->id == id)
6026 nt = ntlook;
6027 else if (! ntlook->type.localp)
6028 {
6029 /* We are creating a duplicate definition of a globally
6030 defined tag. Force it to be local to avoid
6031 confusion. */
6032 localp = true;
6033 }
6034 }
6035
6036 if (nt != NULL)
6037 {
6038 assert (localp == nt->type.localp);
6039 if (nt->kind == DEBUG_KIND_ILLEGAL && ! localp)
6040 {
6041 /* We've already seen a global definition of the type.
6042 Ignore this new definition. */
6043 ignorep = true;
6044 }
6045 }
6046 else
6047 {
6048 nt = (struct ieee_name_type *) xmalloc (sizeof *nt);
6049 memset (nt, 0, sizeof *nt);
6050 nt->id = id;
6051 nt->type.name = h->root.string;
6052 nt->next = h->types;
6053 h->types = nt;
6054 nt->type.indx = info->type_indx;
6055 ++info->type_indx;
6056 }
6057
6058 nt->kind = DEBUG_KIND_ILLEGAL;
6059
6060 if (! ieee_init_buffer (info, &strdef)
6061 || ! ieee_define_named_type (info, tag, nt->type.indx, size, true,
6062 localp, &strdef)
6063 || ! ieee_write_number (info, structp ? 'S' : 'U')
6064 || ! ieee_write_number (info, size))
6065 return false;
6066
6067 if (! ignorep)
6068 {
6069 const char *hold;
6070
6071 /* We never want nt->type.name to be NULL. We want the rest of
6072 the type to be the object set up on the type stack; it will
6073 have a NULL name if tag is NULL. */
6074 hold = nt->type.name;
6075 nt->type = info->type_stack->type;
6076 nt->type.name = hold;
6077 }
6078
6079 info->type_stack->type.name = tag;
6080 info->type_stack->type.strdef = strdef;
6081 info->type_stack->type.ignorep = ignorep;
6082
6083 return true;
6084}
6085
6086/* Add a field to a struct. */
6087
6088static boolean
6089ieee_struct_field (p, name, bitpos, bitsize, visibility)
6090 PTR p;
6091 const char *name;
6092 bfd_vma bitpos;
6093 bfd_vma bitsize;
6094 enum debug_visibility visibility;
6095{
6096 struct ieee_handle *info = (struct ieee_handle *) p;
6097 unsigned int size;
6098 boolean unsignedp;
6099 boolean referencep;
6100 boolean localp;
6101 unsigned int indx;
6102 bfd_vma offset;
6103
6104 assert (info->type_stack != NULL
6105 && info->type_stack->next != NULL
6106 && ! ieee_buffer_emptyp (&info->type_stack->next->type.strdef));
6107
6108 /* If we are ignoring this struct definition, just pop and ignore
6109 the type. */
6110 if (info->type_stack->next->type.ignorep)
6111 {
6112 ieee_pop_unused_type (info);
6113 return true;
6114 }
6115
6116 size = info->type_stack->type.size;
6117 unsignedp = info->type_stack->type.unsignedp;
6118 referencep = info->type_stack->type.referencep;
6119 localp = info->type_stack->type.localp;
6120 indx = ieee_pop_type (info);
6121
6122 if (localp)
6123 info->type_stack->type.localp = true;
6124
6125 if (info->type_stack->type.classdef != NULL)
6126 {
6127 unsigned int flags;
6128 unsigned int nindx;
6129
6130 /* This is a class. We must add a description of this field to
6131 the class records we are building. */
6132
6133 flags = ieee_vis_to_flags (visibility);
6134 nindx = info->type_stack->type.classdef->indx;
6135 if (! ieee_change_buffer (info,
6136 &info->type_stack->type.classdef->pmiscbuf)
6137 || ! ieee_write_asn (info, nindx, 'd')
6138 || ! ieee_write_asn (info, nindx, flags)
6139 || ! ieee_write_atn65 (info, nindx, name)
6140 || ! ieee_write_atn65 (info, nindx, name))
6141 return false;
6142 info->type_stack->type.classdef->pmisccount += 4;
6143
6144 if (referencep)
6145 {
6146 unsigned int nindx;
6147
6148 /* We need to output a record recording that this field is
6149 really of reference type. We put this on the refs field
6150 of classdef, so that it can be appended to the C++
6151 records after the class is defined. */
6152
6153 nindx = info->name_indx;
6154 ++info->name_indx;
6155
6156 if (! ieee_change_buffer (info,
6157 &info->type_stack->type.classdef->refs)
6158 || ! ieee_write_byte (info, (int) ieee_nn_record)
6159 || ! ieee_write_number (info, nindx)
6160 || ! ieee_write_id (info, "")
6161 || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
6162 || ! ieee_write_number (info, nindx)
6163 || ! ieee_write_number (info, 0)
6164 || ! ieee_write_number (info, 62)
6165 || ! ieee_write_number (info, 80)
6166 || ! ieee_write_number (info, 4)
6167 || ! ieee_write_asn (info, nindx, 'R')
6168 || ! ieee_write_asn (info, nindx, 3)
6169 || ! ieee_write_atn65 (info, nindx, info->type_stack->type.name)
6170 || ! ieee_write_atn65 (info, nindx, name))
6171 return false;
6172 }
6173 }
6174
6175 /* If the bitsize doesn't match the expected size, we need to output
6176 a bitfield type. */
6177 if (size == 0 || bitsize == 0 || bitsize == size * 8)
6178 offset = bitpos / 8;
6179 else
6180 {
6181 if (! ieee_define_type (info, 0, unsignedp,
6182 info->type_stack->type.localp)
6183 || ! ieee_write_number (info, 'g')
6184 || ! ieee_write_number (info, unsignedp ? 0 : 1)
6185 || ! ieee_write_number (info, bitsize)
6186 || ! ieee_write_number (info, indx))
6187 return false;
6188 indx = ieee_pop_type (info);
6189 offset = bitpos;
6190 }
6191
6192 /* Switch to the struct we are building in order to output this
6193 field definition. */
6194 return (ieee_change_buffer (info, &info->type_stack->type.strdef)
6195 && ieee_write_id (info, name)
6196 && ieee_write_number (info, indx)
6197 && ieee_write_number (info, offset));
6198}
6199
6200/* Finish up a struct type. */
6201
6202static boolean
6203ieee_end_struct_type (p)
6204 PTR p;
6205{
6206 struct ieee_handle *info = (struct ieee_handle *) p;
6207 struct ieee_buflist *pb;
6208
6209 assert (info->type_stack != NULL
6210 && ! ieee_buffer_emptyp (&info->type_stack->type.strdef));
6211
6212 /* If we were ignoring this struct definition because it was a
6213 duplicate defintion, just through away whatever bytes we have
6214 accumulated. Leave the type on the stack. */
6215 if (info->type_stack->type.ignorep)
6216 return true;
6217
6218 /* If this is not a duplicate definition of this tag, then localp
6219 will be false, and we can put it in the global type block.
6220 FIXME: We should avoid outputting duplicate definitions which are
6221 the same. */
6222 if (! info->type_stack->type.localp)
6223 {
6224 /* Make sure we have started the global type block. */
6225 if (ieee_buffer_emptyp (&info->global_types))
6226 {
6227 if (! ieee_change_buffer (info, &info->global_types)
6228 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
6229 || ! ieee_write_byte (info, 2)
6230 || ! ieee_write_number (info, 0)
6231 || ! ieee_write_id (info, ""))
6232 return false;
6233 }
6234 pb = &info->global_types;
6235 }
6236 else
6237 {
6238 /* Make sure we have started the types block. */
6239 if (ieee_buffer_emptyp (&info->types))
6240 {
6241 if (! ieee_change_buffer (info, &info->types)
6242 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
6243 || ! ieee_write_byte (info, 1)
6244 || ! ieee_write_number (info, 0)
6245 || ! ieee_write_id (info, info->modname))
6246 return false;
6247 }
6248 pb = &info->types;
6249 }
6250
6251 /* Append the struct definition to the types. */
6252 if (! ieee_append_buffer (info, pb, &info->type_stack->type.strdef)
6253 || ! ieee_init_buffer (info, &info->type_stack->type.strdef))
6254 return false;
6255
6256 /* Leave the struct on the type stack. */
6257
6258 return true;
6259}
6260
6261/* Start a class type. */
6262
6263static boolean
6264ieee_start_class_type (p, tag, id, structp, size, vptr, ownvptr)
6265 PTR p;
6266 const char *tag;
6267 unsigned int id;
6268 boolean structp;
6269 unsigned int size;
6270 boolean vptr;
6271 boolean ownvptr;
6272{
6273 struct ieee_handle *info = (struct ieee_handle *) p;
6274 const char *vclass;
6275 struct ieee_buflist pmiscbuf;
6276 unsigned int indx;
6277 struct ieee_type_class *classdef;
6278
6279 /* A C++ class is output as a C++ struct along with a set of pmisc
6280 records describing the class. */
6281
6282 /* We need to have a name so that we can associate the struct and
6283 the class. */
6284 if (tag == NULL)
6285 {
6286 char *t;
6287
6288 t = (char *) xmalloc (20);
6289 sprintf (t, "__anon%u", id);
6290 tag = t;
6291 }
6292
6293 /* We can't write out the virtual table information until we have
6294 finished the class, because we don't know the virtual table size.
6295 We get the size from the largest voffset we see. */
6296 vclass = NULL;
6297 if (vptr && ! ownvptr)
6298 {
6299 vclass = info->type_stack->type.name;
6300 assert (vclass != NULL);
6301 /* We don't call ieee_pop_unused_type, since the class should
6302 get defined. */
6303 (void) ieee_pop_type (info);
6304 }
6305
6306 if (! ieee_start_struct_type (p, tag, id, structp, size))
6307 return false;
6308
6309 indx = info->name_indx;
6310 ++info->name_indx;
6311
6312 /* We write out pmisc records into the classdef field. We will
6313 write out the pmisc start after we know the number of records we
6314 need. */
6315 if (! ieee_init_buffer (info, &pmiscbuf)
6316 || ! ieee_change_buffer (info, &pmiscbuf)
6317 || ! ieee_write_asn (info, indx, 'T')
6318 || ! ieee_write_asn (info, indx, structp ? 'o' : 'u')
6319 || ! ieee_write_atn65 (info, indx, tag))
6320 return false;
6321
6322 classdef = (struct ieee_type_class *) xmalloc (sizeof *classdef);
6323 memset (classdef, 0, sizeof *classdef);
6324
6325 classdef->indx = indx;
6326 classdef->pmiscbuf = pmiscbuf;
6327 classdef->pmisccount = 3;
6328 classdef->vclass = vclass;
6329 classdef->ownvptr = ownvptr;
6330
6331 info->type_stack->type.classdef = classdef;
6332
6333 return true;
6334}
6335
6336/* Add a static member to a class. */
6337
6338static boolean
6339ieee_class_static_member (p, name, physname, visibility)
6340 PTR p;
6341 const char *name;
6342 const char *physname;
6343 enum debug_visibility visibility;
6344{
6345 struct ieee_handle *info = (struct ieee_handle *) p;
6346 unsigned int flags;
6347 unsigned int nindx;
6348
6349 /* We don't care about the type. Hopefully there will be a call to
6350 ieee_variable declaring the physical name and the type, since
6351 that is where an IEEE consumer must get the type. */
6352 ieee_pop_unused_type (info);
6353
6354 assert (info->type_stack != NULL
6355 && info->type_stack->type.classdef != NULL);
6356
6357 flags = ieee_vis_to_flags (visibility);
6358 flags |= CXXFLAGS_STATIC;
6359
6360 nindx = info->type_stack->type.classdef->indx;
6361
6362 if (! ieee_change_buffer (info, &info->type_stack->type.classdef->pmiscbuf)
6363 || ! ieee_write_asn (info, nindx, 'd')
6364 || ! ieee_write_asn (info, nindx, flags)
6365 || ! ieee_write_atn65 (info, nindx, name)
6366 || ! ieee_write_atn65 (info, nindx, physname))
6367 return false;
6368 info->type_stack->type.classdef->pmisccount += 4;
6369
6370 return true;
6371}
6372
6373/* Add a base class to a class. */
6374
6375static boolean
6376ieee_class_baseclass (p, bitpos, virtual, visibility)
6377 PTR p;
6378 bfd_vma bitpos;
6379 boolean virtual;
6380 enum debug_visibility visibility;
6381{
6382 struct ieee_handle *info = (struct ieee_handle *) p;
6383 const char *bname;
6384 boolean localp;
6385 unsigned int bindx;
6386 char *fname;
6387 unsigned int flags;
6388 unsigned int nindx;
6389
6390 assert (info->type_stack != NULL
6391 && info->type_stack->type.name != NULL
6392 && info->type_stack->next != NULL
6393 && info->type_stack->next->type.classdef != NULL
6394 && ! ieee_buffer_emptyp (&info->type_stack->next->type.strdef));
6395
6396 bname = info->type_stack->type.name;
6397 localp = info->type_stack->type.localp;
6398 bindx = ieee_pop_type (info);
6399
6400 /* We are currently defining both a struct and a class. We must
6401 write out a field definition in the struct which holds the base
6402 class. The stabs debugging reader will create a field named
6403 _vb$CLASS for a virtual base class, so we just use that. FIXME:
6404 we should not depend upon a detail of stabs debugging. */
6405 if (virtual)
6406 {
6407 fname = (char *) xmalloc (strlen (bname) + sizeof "_vb$");
6408 sprintf (fname, "_vb$%s", bname);
6409 flags = BASEFLAGS_VIRTUAL;
6410 }
6411 else
6412 {
6413 if (localp)
6414 info->type_stack->type.localp = true;
6415
6416 fname = (char *) xmalloc (strlen (bname) + sizeof "_b$");
6417 sprintf (fname, "_b$%s", bname);
6418
6419 if (! ieee_change_buffer (info, &info->type_stack->type.strdef)
6420 || ! ieee_write_id (info, fname)
6421 || ! ieee_write_number (info, bindx)
6422 || ! ieee_write_number (info, bitpos / 8))
6423 return false;
6424 flags = 0;
6425 }
6426
6427 if (visibility == DEBUG_VISIBILITY_PRIVATE)
6428 flags |= BASEFLAGS_PRIVATE;
6429
6430 nindx = info->type_stack->type.classdef->indx;
6431
6432 if (! ieee_change_buffer (info, &info->type_stack->type.classdef->pmiscbuf)
6433 || ! ieee_write_asn (info, nindx, 'b')
6434 || ! ieee_write_asn (info, nindx, flags)
6435 || ! ieee_write_atn65 (info, nindx, bname)
6436 || ! ieee_write_asn (info, nindx, 0)
6437 || ! ieee_write_atn65 (info, nindx, fname))
6438 return false;
6439 info->type_stack->type.classdef->pmisccount += 5;
6440
6441 free (fname);
6442
6443 return true;
6444}
6445
6446/* Start building a method for a class. */
6447
6448static boolean
6449ieee_class_start_method (p, name)
6450 PTR p;
6451 const char *name;
6452{
6453 struct ieee_handle *info = (struct ieee_handle *) p;
6454
6455 assert (info->type_stack != NULL
6456 && info->type_stack->type.classdef != NULL
6457 && info->type_stack->type.classdef->method == NULL);
6458
6459 info->type_stack->type.classdef->method = name;
6460
6461 return true;
6462}
6463
6464/* Define a new method variant, either static or not. */
6465
6466static boolean
6467ieee_class_method_var (info, physname, visibility, staticp, constp,
6468 volatilep, voffset, context)
6469 struct ieee_handle *info;
6470 const char *physname;
6471 enum debug_visibility visibility;
6472 boolean staticp;
6473 boolean constp;
6474 boolean volatilep;
6475 bfd_vma voffset;
6476 boolean context;
6477{
6478 unsigned int flags;
6479 unsigned int nindx;
6480 boolean virtual;
6481
6482 /* We don't need the type of the method. An IEEE consumer which
6483 wants the type must track down the function by the physical name
6484 and get the type from that. */
6485 ieee_pop_unused_type (info);
6486
6487 /* We don't use the context. FIXME: We probably ought to use it to
6488 adjust the voffset somehow, but I don't really know how. */
6489 if (context)
6490 ieee_pop_unused_type (info);
6491
6492 assert (info->type_stack != NULL
6493 && info->type_stack->type.classdef != NULL
6494 && info->type_stack->type.classdef->method != NULL);
6495
6496 flags = ieee_vis_to_flags (visibility);
6497
6498 /* FIXME: We never set CXXFLAGS_OVERRIDE, CXXFLAGS_OPERATOR,
6499 CXXFLAGS_CTORDTOR, CXXFLAGS_CTOR, or CXXFLAGS_INLINE. */
6500
6501 if (staticp)
6502 flags |= CXXFLAGS_STATIC;
6503 if (constp)
6504 flags |= CXXFLAGS_CONST;
6505 if (volatilep)
6506 flags |= CXXFLAGS_VOLATILE;
6507
6508 nindx = info->type_stack->type.classdef->indx;
6509
6510 virtual = context || voffset > 0;
6511
6512 if (! ieee_change_buffer (info,
6513 &info->type_stack->type.classdef->pmiscbuf)
6514 || ! ieee_write_asn (info, nindx, virtual ? 'v' : 'm')
6515 || ! ieee_write_asn (info, nindx, flags)
6516 || ! ieee_write_atn65 (info, nindx,
6517 info->type_stack->type.classdef->method)
6518 || ! ieee_write_atn65 (info, nindx, physname))
6519 return false;
6520
6521 if (virtual)
6522 {
6523 if (voffset > info->type_stack->type.classdef->voffset)
6524 info->type_stack->type.classdef->voffset = voffset;
6525 if (! ieee_write_asn (info, nindx, voffset))
6526 return false;
6527 ++info->type_stack->type.classdef->pmisccount;
6528 }
6529
6530 if (! ieee_write_asn (info, nindx, 0))
6531 return false;
6532
6533 info->type_stack->type.classdef->pmisccount += 5;
6534
6535 return true;
6536}
6537
6538/* Define a new method variant. */
6539
6540static boolean
6541ieee_class_method_variant (p, physname, visibility, constp, volatilep,
6542 voffset, context)
6543 PTR p;
6544 const char *physname;
6545 enum debug_visibility visibility;
6546 boolean constp;
6547 boolean volatilep;
6548 bfd_vma voffset;
6549 boolean context;
6550{
6551 struct ieee_handle *info = (struct ieee_handle *) p;
6552
6553 return ieee_class_method_var (info, physname, visibility, false, constp,
6554 volatilep, voffset, context);
6555}
6556
6557/* Define a new static method variant. */
6558
6559static boolean
6560ieee_class_static_method_variant (p, physname, visibility, constp, volatilep)
6561 PTR p;
6562 const char *physname;
6563 enum debug_visibility visibility;
6564 boolean constp;
6565 boolean volatilep;
6566{
6567 struct ieee_handle *info = (struct ieee_handle *) p;
6568
6569 return ieee_class_method_var (info, physname, visibility, true, constp,
6570 volatilep, 0, false);
6571}
6572
6573/* Finish up a method. */
6574
6575static boolean
6576ieee_class_end_method (p)
6577 PTR p;
6578{
6579 struct ieee_handle *info = (struct ieee_handle *) p;
6580
6581 assert (info->type_stack != NULL
6582 && info->type_stack->type.classdef != NULL
6583 && info->type_stack->type.classdef->method != NULL);
6584
6585 info->type_stack->type.classdef->method = NULL;
6586
6587 return true;
6588}
6589
6590/* Finish up a class. */
6591
6592static boolean
6593ieee_end_class_type (p)
6594 PTR p;
6595{
6596 struct ieee_handle *info = (struct ieee_handle *) p;
6597 unsigned int nindx;
6598
6599 assert (info->type_stack != NULL
6600 && info->type_stack->type.classdef != NULL);
6601
6602 /* If we were ignoring this class definition because it was a
6603 duplicate definition, just through away whatever bytes we have
6604 accumulated. Leave the type on the stack. */
6605 if (info->type_stack->type.ignorep)
6606 return true;
6607
6608 nindx = info->type_stack->type.classdef->indx;
6609
6610 /* If we have a virtual table, we can write out the information now. */
6611 if (info->type_stack->type.classdef->vclass != NULL
6612 || info->type_stack->type.classdef->ownvptr)
6613 {
6614 if (! ieee_change_buffer (info,
6615 &info->type_stack->type.classdef->pmiscbuf)
6616 || ! ieee_write_asn (info, nindx, 'z')
6617 || ! ieee_write_atn65 (info, nindx, "")
6618 || ! ieee_write_asn (info, nindx,
6619 info->type_stack->type.classdef->voffset))
6620 return false;
6621 if (info->type_stack->type.classdef->ownvptr)
6622 {
6623 if (! ieee_write_atn65 (info, nindx, ""))
6624 return false;
6625 }
6626 else
6627 {
6628 if (! ieee_write_atn65 (info, nindx,
6629 info->type_stack->type.classdef->vclass))
6630 return false;
6631 }
6632 if (! ieee_write_asn (info, nindx, 0))
6633 return false;
6634 info->type_stack->type.classdef->pmisccount += 5;
6635 }
6636
6637 /* Now that we know the number of pmisc records, we can write out
6638 the atn62 which starts the pmisc records, and append them to the
6639 C++ buffers. */
6640
6641 if (! ieee_change_buffer (info, &info->cxx)
6642 || ! ieee_write_byte (info, (int) ieee_nn_record)
6643 || ! ieee_write_number (info, nindx)
6644 || ! ieee_write_id (info, "")
6645 || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
6646 || ! ieee_write_number (info, nindx)
6647 || ! ieee_write_number (info, 0)
6648 || ! ieee_write_number (info, 62)
6649 || ! ieee_write_number (info, 80)
6650 || ! ieee_write_number (info,
6651 info->type_stack->type.classdef->pmisccount))
6652 return false;
6653
6654 if (! ieee_append_buffer (info, &info->cxx,
6655 &info->type_stack->type.classdef->pmiscbuf))
6656 return false;
6657 if (! ieee_buffer_emptyp (&info->type_stack->type.classdef->refs))
6658 {
6659 if (! ieee_append_buffer (info, &info->cxx,
6660 &info->type_stack->type.classdef->refs))
6661 return false;
6662 }
6663
6664 return ieee_end_struct_type (p);
6665}
6666
6667/* Push a previously seen typedef onto the type stack. */
6668
6669static boolean
6670ieee_typedef_type (p, name)
6671 PTR p;
6672 const char *name;
6673{
6674 struct ieee_handle *info = (struct ieee_handle *) p;
6675 struct ieee_name_type_hash_entry *h;
6676 struct ieee_name_type *nt;
6677
6678 h = ieee_name_type_hash_lookup (&info->typedefs, name, false, false);
6679
6680 /* h should never be NULL, since that would imply that the generic
6681 debugging code has asked for a typedef which it has not yet
6682 defined. */
6683 assert (h != NULL);
6684
6685 /* We always use the most recently defined type for this name, which
6686 will be the first one on the list. */
6687
6688 nt = h->types;
6689 if (! ieee_push_type (info, nt->type.indx, nt->type.size,
6690 nt->type.unsignedp, nt->type.localp))
6691 return false;
6692
6693 /* Copy over any other type information we may have. */
6694 info->type_stack->type = nt->type;
6695
6696 return true;
6697}
6698
6699/* Push a tagged type onto the type stack. */
6700
6701static boolean
6702ieee_tag_type (p, name, id, kind)
6703 PTR p;
6704 const char *name;
6705 unsigned int id;
6706 enum debug_type_kind kind;
6707{
6708 struct ieee_handle *info = (struct ieee_handle *) p;
6709 boolean localp;
6710 boolean copy;
6711 char ab[20];
6712 struct ieee_name_type_hash_entry *h;
6713 struct ieee_name_type *nt;
6714
6715 if (kind == DEBUG_KIND_ENUM)
6716 {
6717 struct ieee_defined_enum *e;
6718
6719 if (name == NULL)
6720 abort ();
6721 for (e = info->enums; e != NULL; e = e->next)
6722 if (e->tag != NULL && strcmp (e->tag, name) == 0)
6723 return ieee_push_type (info, e->indx, 0, true, false);
6724
6725 e = (struct ieee_defined_enum *) xmalloc (sizeof *e);
6726 memset (e, 0, sizeof *e);
6727
6728 e->indx = info->type_indx;
6729 ++info->type_indx;
6730 e->tag = name;
6731 e->defined = false;
6732
6733 e->next = info->enums;
6734 info->enums = e;
6735
6736 return ieee_push_type (info, e->indx, 0, true, false);
6737 }
6738
6739 localp = false;
6740
6741 copy = false;
6742 if (name == NULL)
6743 {
6744 sprintf (ab, "__anon%u", id);
6745 name = ab;
6746 copy = true;
6747 }
6748
6749 h = ieee_name_type_hash_lookup (&info->tags, name, true, copy);
6750 if (h == NULL)
6751 return false;
6752
6753 for (nt = h->types; nt != NULL; nt = nt->next)
6754 {
6755 if (nt->id == id)
6756 {
6757 if (! ieee_push_type (info, nt->type.indx, nt->type.size,
6758 nt->type.unsignedp, nt->type.localp))
6759 return false;
6760 /* Copy over any other type information we may have. */
6761 info->type_stack->type = nt->type;
6762 return true;
6763 }
6764
6765 if (! nt->type.localp)
6766 {
6767 /* This is a duplicate of a global type, so it must be
6768 local. */
6769 localp = true;
6770 }
6771 }
6772
6773 nt = (struct ieee_name_type *) xmalloc (sizeof *nt);
6774 memset (nt, 0, sizeof *nt);
6775
6776 nt->id = id;
6777 nt->type.name = h->root.string;
6778 nt->type.indx = info->type_indx;
6779 nt->type.localp = localp;
6780 ++info->type_indx;
6781 nt->kind = kind;
6782
6783 nt->next = h->types;
6784 h->types = nt;
6785
6786 if (! ieee_push_type (info, nt->type.indx, 0, false, localp))
6787 return false;
6788
6789 info->type_stack->type.name = h->root.string;
6790
6791 return true;
6792}
6793
6794/* Output a typedef. */
6795
6796static boolean
6797ieee_typdef (p, name)
6798 PTR p;
6799 const char *name;
6800{
6801 struct ieee_handle *info = (struct ieee_handle *) p;
6802 struct ieee_write_type type;
6803 unsigned int indx;
6804 boolean found;
6805 boolean localp;
6806 struct ieee_name_type_hash_entry *h;
6807 struct ieee_name_type *nt;
6808
6809 type = info->type_stack->type;
6810 indx = type.indx;
6811
6812 /* If this is a simple builtin type using a builtin name, we don't
6813 want to output the typedef itself. We also want to change the
6814 type index to correspond to the name being used. We recognize
6815 names used in stabs debugging output even if they don't exactly
6816 correspond to the names used for the IEEE builtin types. */
6817 found = false;
6818 if (indx <= (unsigned int) builtin_bcd_float)
6819 {
6820 switch ((enum builtin_types) indx)
6821 {
6822 default:
6823 break;
6824
6825 case builtin_void:
6826 if (strcmp (name, "void") == 0)
6827 found = true;
6828 break;
6829
6830 case builtin_signed_char:
6831 case builtin_char:
6832 if (strcmp (name, "signed char") == 0)
6833 {
6834 indx = (unsigned int) builtin_signed_char;
6835 found = true;
6836 }
6837 else if (strcmp (name, "char") == 0)
6838 {
6839 indx = (unsigned int) builtin_char;
6840 found = true;
6841 }
6842 break;
6843
6844 case builtin_unsigned_char:
6845 if (strcmp (name, "unsigned char") == 0)
6846 found = true;
6847 break;
6848
6849 case builtin_signed_short_int:
6850 case builtin_short:
6851 case builtin_short_int:
6852 case builtin_signed_short:
6853 if (strcmp (name, "signed short int") == 0)
6854 {
6855 indx = (unsigned int) builtin_signed_short_int;
6856 found = true;
6857 }
6858 else if (strcmp (name, "short") == 0)
6859 {
6860 indx = (unsigned int) builtin_short;
6861 found = true;
6862 }
6863 else if (strcmp (name, "short int") == 0)
6864 {
6865 indx = (unsigned int) builtin_short_int;
6866 found = true;
6867 }
6868 else if (strcmp (name, "signed short") == 0)
6869 {
6870 indx = (unsigned int) builtin_signed_short;
6871 found = true;
6872 }
6873 break;
6874
6875 case builtin_unsigned_short_int:
6876 case builtin_unsigned_short:
6877 if (strcmp (name, "unsigned short int") == 0
6878 || strcmp (name, "short unsigned int") == 0)
6879 {
6880 indx = builtin_unsigned_short_int;
6881 found = true;
6882 }
6883 else if (strcmp (name, "unsigned short") == 0)
6884 {
6885 indx = builtin_unsigned_short;
6886 found = true;
6887 }
6888 break;
6889
6890 case builtin_signed_long:
6891 case builtin_int: /* FIXME: Size depends upon architecture. */
6892 case builtin_long:
6893 if (strcmp (name, "signed long") == 0)
6894 {
6895 indx = builtin_signed_long;
6896 found = true;
6897 }
6898 else if (strcmp (name, "int") == 0)
6899 {
6900 indx = builtin_int;
6901 found = true;
6902 }
6903 else if (strcmp (name, "long") == 0
6904 || strcmp (name, "long int") == 0)
6905 {
6906 indx = builtin_long;
6907 found = true;
6908 }
6909 break;
6910
6911 case builtin_unsigned_long:
6912 case builtin_unsigned: /* FIXME: Size depends upon architecture. */
6913 case builtin_unsigned_int: /* FIXME: Like builtin_unsigned. */
6914 if (strcmp (name, "unsigned long") == 0
6915 || strcmp (name, "long unsigned int") == 0)
6916 {
6917 indx = builtin_unsigned_long;
6918 found = true;
6919 }
6920 else if (strcmp (name, "unsigned") == 0)
6921 {
6922 indx = builtin_unsigned;
6923 found = true;
6924 }
6925 else if (strcmp (name, "unsigned int") == 0)
6926 {
6927 indx = builtin_unsigned_int;
6928 found = true;
6929 }
6930 break;
6931
6932 case builtin_signed_long_long:
6933 if (strcmp (name, "signed long long") == 0
6934 || strcmp (name, "long long int") == 0)
6935 found = true;
6936 break;
6937
6938 case builtin_unsigned_long_long:
6939 if (strcmp (name, "unsigned long long") == 0
6940 || strcmp (name, "long long unsigned int") == 0)
6941 found = true;
6942 break;
6943
6944 case builtin_float:
6945 if (strcmp (name, "float") == 0)
6946 found = true;
6947 break;
6948
6949 case builtin_double:
6950 if (strcmp (name, "double") == 0)
6951 found = true;
6952 break;
6953
6954 case builtin_long_double:
6955 if (strcmp (name, "long double") == 0)
6956 found = true;
6957 break;
6958
6959 case builtin_long_long_double:
6960 if (strcmp (name, "long long double") == 0)
6961 found = true;
6962 break;
6963 }
6964
6965 if (found)
6966 type.indx = indx;
6967 }
6968
6969 h = ieee_name_type_hash_lookup (&info->typedefs, name, true, false);
6970 if (h == NULL)
6971 return false;
6972
6973 /* See if we have already defined this type with this name. */
6974 localp = type.localp;
6975 for (nt = h->types; nt != NULL; nt = nt->next)
6976 {
6977 if (nt->id == indx)
6978 {
6979 /* If this is a global definition, then we don't need to
6980 do anything here. */
6981 if (! nt->type.localp)
6982 {
6983 ieee_pop_unused_type (info);
6984 return true;
6985 }
6986 }
6987 else
6988 {
6989 /* This is a duplicate definition, so make this one local. */
6990 localp = true;
6991 }
6992 }
6993
6994 /* We need to add a new typedef for this type. */
6995
6996 nt = (struct ieee_name_type *) xmalloc (sizeof *nt);
6997 memset (nt, 0, sizeof *nt);
6998 nt->id = indx;
6999 nt->type = type;
7000 nt->type.name = name;
7001 nt->type.localp = localp;
7002 nt->kind = DEBUG_KIND_ILLEGAL;
7003
7004 nt->next = h->types;
7005 h->types = nt;
7006
7007 if (found)
7008 {
7009 /* This is one of the builtin typedefs, so we don't need to
7010 actually define it. */
7011 ieee_pop_unused_type (info);
7012 return true;
7013 }
7014
7015 indx = ieee_pop_type (info);
7016
7017 if (! ieee_define_named_type (info, name, (unsigned int) -1, type.size,
7018 type.unsignedp, localp,
7019 (struct ieee_buflist *) NULL)
7020 || ! ieee_write_number (info, 'T')
7021 || ! ieee_write_number (info, indx))
7022 return false;
7023
7024 /* Remove the type we just added to the type stack. This should not
7025 be ieee_pop_unused_type, since the type is used, we just don't
7026 need it now. */
7027 (void) ieee_pop_type (info);
7028
7029 return true;
7030}
7031
7032/* Output a tag for a type. We don't have to do anything here. */
7033
7034static boolean
7035ieee_tag (p, name)
7036 PTR p;
7037 const char *name ATTRIBUTE_UNUSED;
7038{
7039 struct ieee_handle *info = (struct ieee_handle *) p;
7040
7041 /* This should not be ieee_pop_unused_type, since we want the type
7042 to be defined. */
7043 (void) ieee_pop_type (info);
7044 return true;
7045}
7046
7047/* Output an integer constant. */
7048
7049static boolean
7050ieee_int_constant (p, name, val)
7051 PTR p ATTRIBUTE_UNUSED;
7052 const char *name ATTRIBUTE_UNUSED;
7053 bfd_vma val ATTRIBUTE_UNUSED;
7054{
7055 /* FIXME. */
7056 return true;
7057}
7058
7059/* Output a floating point constant. */
7060
7061static boolean
7062ieee_float_constant (p, name, val)
7063 PTR p ATTRIBUTE_UNUSED;
7064 const char *name ATTRIBUTE_UNUSED;
7065 double val ATTRIBUTE_UNUSED;
7066{
7067 /* FIXME. */
7068 return true;
7069}
7070
7071/* Output a typed constant. */
7072
7073static boolean
7074ieee_typed_constant (p, name, val)
7075 PTR p;
7076 const char *name ATTRIBUTE_UNUSED;
7077 bfd_vma val ATTRIBUTE_UNUSED;
7078{
7079 struct ieee_handle *info = (struct ieee_handle *) p;
7080
7081 /* FIXME. */
7082 ieee_pop_unused_type (info);
7083 return true;
7084}
7085
7086/* Output a variable. */
7087
7088static boolean
7089ieee_variable (p, name, kind, val)
7090 PTR p;
7091 const char *name;
7092 enum debug_var_kind kind;
7093 bfd_vma val;
7094{
7095 struct ieee_handle *info = (struct ieee_handle *) p;
7096 unsigned int name_indx;
7097 unsigned int size;
7098 boolean referencep;
7099 unsigned int type_indx;
7100 boolean asn;
7101 int refflag;
7102
7103 size = info->type_stack->type.size;
7104 referencep = info->type_stack->type.referencep;
7105 type_indx = ieee_pop_type (info);
7106
7107 assert (! ieee_buffer_emptyp (&info->vars));
7108 if (! ieee_change_buffer (info, &info->vars))
7109 return false;
7110
7111 name_indx = info->name_indx;
7112 ++info->name_indx;
7113
7114 /* Write out an NN and an ATN record for this variable. */
7115 if (! ieee_write_byte (info, (int) ieee_nn_record)
7116 || ! ieee_write_number (info, name_indx)
7117 || ! ieee_write_id (info, name)
7118 || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
7119 || ! ieee_write_number (info, name_indx)
7120 || ! ieee_write_number (info, type_indx))
7121 return false;
7122 switch (kind)
7123 {
7124 default:
7125 abort ();
7126 return false;
7127 case DEBUG_GLOBAL:
7128 if (! ieee_write_number (info, 8)
7129 || ! ieee_add_range (info, false, val, val + size))
7130 return false;
7131 refflag = 0;
7132 asn = true;
7133 break;
7134 case DEBUG_STATIC:
7135 if (! ieee_write_number (info, 3)
7136 || ! ieee_add_range (info, false, val, val + size))
7137 return false;
7138 refflag = 1;
7139 asn = true;
7140 break;
7141 case DEBUG_LOCAL_STATIC:
7142 if (! ieee_write_number (info, 3)
7143 || ! ieee_add_range (info, false, val, val + size))
7144 return false;
7145 refflag = 2;
7146 asn = true;
7147 break;
7148 case DEBUG_LOCAL:
7149 if (! ieee_write_number (info, 1)
7150 || ! ieee_write_number (info, val))
7151 return false;
7152 refflag = 2;
7153 asn = false;
7154 break;
7155 case DEBUG_REGISTER:
7156 if (! ieee_write_number (info, 2)
7157 || ! ieee_write_number (info,
7158 ieee_genreg_to_regno (info->abfd, val)))
7159 return false;
7160 refflag = 2;
7161 asn = false;
7162 break;
7163 }
7164
7165 if (asn)
7166 {
7167 if (! ieee_write_asn (info, name_indx, val))
7168 return false;
7169 }
7170
7171 /* If this is really a reference type, then we just output it with
7172 pointer type, and must now output a C++ record indicating that it
7173 is really reference type. */
7174 if (referencep)
7175 {
7176 unsigned int nindx;
7177
7178 nindx = info->name_indx;
7179 ++info->name_indx;
7180
7181 /* If this is a global variable, we want to output the misc
7182 record in the C++ misc record block. Otherwise, we want to
7183 output it just after the variable definition, which is where
7184 the current buffer is. */
7185 if (refflag != 2)
7186 {
7187 if (! ieee_change_buffer (info, &info->cxx))
7188 return false;
7189 }
7190
7191 if (! ieee_write_byte (info, (int) ieee_nn_record)
7192 || ! ieee_write_number (info, nindx)
7193 || ! ieee_write_id (info, "")
7194 || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
7195 || ! ieee_write_number (info, nindx)
7196 || ! ieee_write_number (info, 0)
7197 || ! ieee_write_number (info, 62)
7198 || ! ieee_write_number (info, 80)
7199 || ! ieee_write_number (info, 3)
7200 || ! ieee_write_asn (info, nindx, 'R')
7201 || ! ieee_write_asn (info, nindx, refflag)
7202 || ! ieee_write_atn65 (info, nindx, name))
7203 return false;
7204 }
7205
7206 return true;
7207}
7208
7209/* Start outputting information for a function. */
7210
7211static boolean
7212ieee_start_function (p, name, global)
7213 PTR p;
7214 const char *name;
7215 boolean global;
7216{
7217 struct ieee_handle *info = (struct ieee_handle *) p;
7218 boolean referencep;
7219 unsigned int retindx, typeindx;
7220
7221 referencep = info->type_stack->type.referencep;
7222 retindx = ieee_pop_type (info);
7223
7224 /* Besides recording a BB4 or BB6 block, we record the type of the
7225 function in the BB1 typedef block. We can't write out the full
7226 type until we have seen all the parameters, so we accumulate it
7227 in info->fntype and info->fnargs. */
7228 if (! ieee_buffer_emptyp (&info->fntype))
7229 {
7230 /* FIXME: This might happen someday if we support nested
7231 functions. */
7232 abort ();
7233 }
7234
7235 info->fnname = name;
7236
7237 /* An attribute of 0x40 means that the push mask is unknown. */
7238 if (! ieee_define_named_type (info, name, (unsigned int) -1, 0, false, true,
7239 &info->fntype)
7240 || ! ieee_write_number (info, 'x')
7241 || ! ieee_write_number (info, 0x40)
7242 || ! ieee_write_number (info, 0)
7243 || ! ieee_write_number (info, 0)
7244 || ! ieee_write_number (info, retindx))
7245 return false;
7246
7247 typeindx = ieee_pop_type (info);
7248
7249 if (! ieee_init_buffer (info, &info->fnargs))
7250 return false;
7251 info->fnargcount = 0;
7252
7253 /* If the function return value is actually a reference type, we
7254 must add a record indicating that. */
7255 if (referencep)
7256 {
7257 unsigned int nindx;
7258
7259 nindx = info->name_indx;
7260 ++info->name_indx;
7261 if (! ieee_change_buffer (info, &info->cxx)
7262 || ! ieee_write_byte (info, (int) ieee_nn_record)
7263 || ! ieee_write_number (info, nindx)
7264 || ! ieee_write_id (info, "")
7265 || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
7266 || ! ieee_write_number (info, nindx)
7267 || ! ieee_write_number (info, 0)
7268 || ! ieee_write_number (info, 62)
7269 || ! ieee_write_number (info, 80)
7270 || ! ieee_write_number (info, 3)
7271 || ! ieee_write_asn (info, nindx, 'R')
7272 || ! ieee_write_asn (info, nindx, global ? 0 : 1)
7273 || ! ieee_write_atn65 (info, nindx, name))
7274 return false;
7275 }
7276
7277 assert (! ieee_buffer_emptyp (&info->vars));
7278 if (! ieee_change_buffer (info, &info->vars))
7279 return false;
7280
7281 /* The address is written out as the first block. */
7282
7283 ++info->block_depth;
7284
7285 return (ieee_write_byte (info, (int) ieee_bb_record_enum)
7286 && ieee_write_byte (info, global ? 4 : 6)
7287 && ieee_write_number (info, 0)
7288 && ieee_write_id (info, name)
7289 && ieee_write_number (info, 0)
7290 && ieee_write_number (info, typeindx));
7291}
7292
7293/* Add a function parameter. This will normally be called before the
7294 first block, so we postpone them until we see the block. */
7295
7296static boolean
7297ieee_function_parameter (p, name, kind, val)
7298 PTR p;
7299 const char *name;
7300 enum debug_parm_kind kind;
7301 bfd_vma val;
7302{
7303 struct ieee_handle *info = (struct ieee_handle *) p;
7304 struct ieee_pending_parm *m, **pm;
7305
7306 assert (info->block_depth == 1);
7307
7308 m = (struct ieee_pending_parm *) xmalloc (sizeof *m);
7309 memset (m, 0, sizeof *m);
7310
7311 m->next = NULL;
7312 m->name = name;
7313 m->referencep = info->type_stack->type.referencep;
7314 m->type = ieee_pop_type (info);
7315 m->kind = kind;
7316 m->val = val;
7317
7318 for (pm = &info->pending_parms; *pm != NULL; pm = &(*pm)->next)
7319 ;
7320 *pm = m;
7321
7322 /* Add the type to the fnargs list. */
7323 if (! ieee_change_buffer (info, &info->fnargs)
7324 || ! ieee_write_number (info, m->type))
7325 return false;
7326 ++info->fnargcount;
7327
7328 return true;
7329}
7330
7331/* Output pending function parameters. */
7332
7333static boolean
7334ieee_output_pending_parms (info)
7335 struct ieee_handle *info;
7336{
7337 struct ieee_pending_parm *m;
7338 unsigned int refcount;
7339
7340 refcount = 0;
7341 for (m = info->pending_parms; m != NULL; m = m->next)
7342 {
7343 enum debug_var_kind vkind;
7344
7345 switch (m->kind)
7346 {
7347 default:
7348 abort ();
7349 return false;
7350 case DEBUG_PARM_STACK:
7351 case DEBUG_PARM_REFERENCE:
7352 vkind = DEBUG_LOCAL;
7353 break;
7354 case DEBUG_PARM_REG:
7355 case DEBUG_PARM_REF_REG:
7356 vkind = DEBUG_REGISTER;
7357 break;
7358 }
7359
7360 if (! ieee_push_type (info, m->type, 0, false, false))
7361 return false;
7362 info->type_stack->type.referencep = m->referencep;
7363 if (m->referencep)
7364 ++refcount;
7365 if (! ieee_variable ((PTR) info, m->name, vkind, m->val))
7366 return false;
7367 }
7368
7369 /* If there are any reference parameters, we need to output a
7370 miscellaneous record indicating them. */
7371 if (refcount > 0)
7372 {
7373 unsigned int nindx, varindx;
7374
7375 /* FIXME: The MRI compiler outputs the demangled function name
7376 here, but we are outputting the mangled name. */
7377 nindx = info->name_indx;
7378 ++info->name_indx;
7379 if (! ieee_change_buffer (info, &info->vars)
7380 || ! ieee_write_byte (info, (int) ieee_nn_record)
7381 || ! ieee_write_number (info, nindx)
7382 || ! ieee_write_id (info, "")
7383 || ! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
7384 || ! ieee_write_number (info, nindx)
7385 || ! ieee_write_number (info, 0)
7386 || ! ieee_write_number (info, 62)
7387 || ! ieee_write_number (info, 80)
7388 || ! ieee_write_number (info, refcount + 3)
7389 || ! ieee_write_asn (info, nindx, 'B')
7390 || ! ieee_write_atn65 (info, nindx, info->fnname)
7391 || ! ieee_write_asn (info, nindx, 0))
7392 return false;
7393 for (m = info->pending_parms, varindx = 1;
7394 m != NULL;
7395 m = m->next, varindx++)
7396 {
7397 if (m->referencep)
7398 {
7399 if (! ieee_write_asn (info, nindx, varindx))
7400 return false;
7401 }
7402 }
7403 }
7404
7405 m = info->pending_parms;
7406 while (m != NULL)
7407 {
7408 struct ieee_pending_parm *next;
7409
7410 next = m->next;
7411 free (m);
7412 m = next;
7413 }
7414
7415 info->pending_parms = NULL;
7416
7417 return true;
7418}
7419
7420/* Start a block. If this is the first block, we output the address
7421 to finish the BB4 or BB6, and then output the function parameters. */
7422
7423static boolean
7424ieee_start_block (p, addr)
7425 PTR p;
7426 bfd_vma addr;
7427{
7428 struct ieee_handle *info = (struct ieee_handle *) p;
7429
7430 if (! ieee_change_buffer (info, &info->vars))
7431 return false;
7432
7433 if (info->block_depth == 1)
7434 {
7435 if (! ieee_write_number (info, addr)
7436 || ! ieee_output_pending_parms (info))
7437 return false;
7438 }
7439 else
7440 {
7441 if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
7442 || ! ieee_write_byte (info, 6)
7443 || ! ieee_write_number (info, 0)
7444 || ! ieee_write_id (info, "")
7445 || ! ieee_write_number (info, 0)
7446 || ! ieee_write_number (info, 0)
7447 || ! ieee_write_number (info, addr))
7448 return false;
7449 }
7450
7451 if (! ieee_start_range (info, addr))
7452 return false;
7453
7454 ++info->block_depth;
7455
7456 return true;
7457}
7458
7459/* End a block. */
7460
7461static boolean
7462ieee_end_block (p, addr)
7463 PTR p;
7464 bfd_vma addr;
7465{
7466 struct ieee_handle *info = (struct ieee_handle *) p;
7467
7468 /* The address we are given is the end of the block, but IEEE seems
7469 to want to the address of the last byte in the block, so we
7470 subtract one. */
7471 if (! ieee_change_buffer (info, &info->vars)
7472 || ! ieee_write_byte (info, (int) ieee_be_record_enum)
7473 || ! ieee_write_number (info, addr - 1))
7474 return false;
7475
7476 if (! ieee_end_range (info, addr))
7477 return false;
7478
7479 --info->block_depth;
7480
7481 if (addr > info->highaddr)
7482 info->highaddr = addr;
7483
7484 return true;
7485}
7486
7487/* End a function. */
7488
7489static boolean
7490ieee_end_function (p)
7491 PTR p;
7492{
7493 struct ieee_handle *info = (struct ieee_handle *) p;
7494
7495 assert (info->block_depth == 1);
7496
7497 --info->block_depth;
7498
7499 /* Now we can finish up fntype, and add it to the typdef section.
7500 At this point, fntype is the 'x' type up to the argument count,
7501 and fnargs is the argument types. We must add the argument
7502 count, and we must add the level. FIXME: We don't record varargs
7503 functions correctly. In fact, stabs debugging does not give us
7504 enough information to do so. */
7505 if (! ieee_change_buffer (info, &info->fntype)
7506 || ! ieee_write_number (info, info->fnargcount)
7507 || ! ieee_change_buffer (info, &info->fnargs)
7508 || ! ieee_write_number (info, 0))
7509 return false;
7510
7511 /* Make sure the typdef block has been started. */
7512 if (ieee_buffer_emptyp (&info->types))
7513 {
7514 if (! ieee_change_buffer (info, &info->types)
7515 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
7516 || ! ieee_write_byte (info, 1)
7517 || ! ieee_write_number (info, 0)
7518 || ! ieee_write_id (info, info->modname))
7519 return false;
7520 }
7521
7522 if (! ieee_append_buffer (info, &info->types, &info->fntype)
7523 || ! ieee_append_buffer (info, &info->types, &info->fnargs))
7524 return false;
7525
7526 info->fnname = NULL;
7527 if (! ieee_init_buffer (info, &info->fntype)
7528 || ! ieee_init_buffer (info, &info->fnargs))
7529 return false;
7530 info->fnargcount = 0;
7531
7532 return true;
7533}
7534
7535/* Record line number information. */
7536
7537static boolean
7538ieee_lineno (p, filename, lineno, addr)
7539 PTR p;
7540 const char *filename;
7541 unsigned long lineno;
7542 bfd_vma addr;
7543{
7544 struct ieee_handle *info = (struct ieee_handle *) p;
7545
7546 assert (info->filename != NULL);
7547
7548 /* The HP simulator seems to get confused when more than one line is
7549 listed for the same address, at least if they are in different
7550 files. We handle this by always listing the last line for a
7551 given address, since that seems to be the one that gdb uses. */
7552 if (info->pending_lineno_filename != NULL
7553 && addr != info->pending_lineno_addr)
7554 {
7555 /* Make sure we have a line number block. */
7556 if (! ieee_buffer_emptyp (&info->linenos))
7557 {
7558 if (! ieee_change_buffer (info, &info->linenos))
7559 return false;
7560 }
7561 else
7562 {
7563 info->lineno_name_indx = info->name_indx;
7564 ++info->name_indx;
7565 if (! ieee_change_buffer (info, &info->linenos)
7566 || ! ieee_write_byte (info, (int) ieee_bb_record_enum)
7567 || ! ieee_write_byte (info, 5)
7568 || ! ieee_write_number (info, 0)
7569 || ! ieee_write_id (info, info->filename)
7570 || ! ieee_write_byte (info, (int) ieee_nn_record)
7571 || ! ieee_write_number (info, info->lineno_name_indx)
7572 || ! ieee_write_id (info, ""))
7573 return false;
7574 info->lineno_filename = info->filename;
7575 }
7576
7577 if (strcmp (info->pending_lineno_filename, info->lineno_filename) != 0)
7578 {
7579 if (strcmp (info->filename, info->lineno_filename) != 0)
7580 {
7581 /* We were not in the main file. Close the block for the
7582 included file. */
7583 if (! ieee_write_byte (info, (int) ieee_be_record_enum))
7584 return false;
7585 if (strcmp (info->filename, info->pending_lineno_filename) == 0)
7586 {
7587 /* We need a new NN record, and we aren't about to
7588 output one. */
7589 info->lineno_name_indx = info->name_indx;
7590 ++info->name_indx;
7591 if (! ieee_write_byte (info, (int) ieee_nn_record)
7592 || ! ieee_write_number (info, info->lineno_name_indx)
7593 || ! ieee_write_id (info, ""))
7594 return false;
7595 }
7596 }
7597 if (strcmp (info->filename, info->pending_lineno_filename) != 0)
7598 {
7599 /* We are not changing to the main file. Open a block for
7600 the new included file. */
7601 info->lineno_name_indx = info->name_indx;
7602 ++info->name_indx;
7603 if (! ieee_write_byte (info, (int) ieee_bb_record_enum)
7604 || ! ieee_write_byte (info, 5)
7605 || ! ieee_write_number (info, 0)
7606 || ! ieee_write_id (info, info->pending_lineno_filename)
7607 || ! ieee_write_byte (info, (int) ieee_nn_record)
7608 || ! ieee_write_number (info, info->lineno_name_indx)
7609 || ! ieee_write_id (info, ""))
7610 return false;
7611 }
7612 info->lineno_filename = info->pending_lineno_filename;
7613 }
7614
7615 if (! ieee_write_2bytes (info, (int) ieee_atn_record_enum)
7616 || ! ieee_write_number (info, info->lineno_name_indx)
7617 || ! ieee_write_number (info, 0)
7618 || ! ieee_write_number (info, 7)
7619 || ! ieee_write_number (info, info->pending_lineno)
7620 || ! ieee_write_number (info, 0)
7621 || ! ieee_write_asn (info, info->lineno_name_indx,
7622 info->pending_lineno_addr))
7623 return false;
7624 }
7625
7626 info->pending_lineno_filename = filename;
7627 info->pending_lineno = lineno;
7628 info->pending_lineno_addr = addr;
7629
7630 return true;
7631}
Note: See TracBrowser for help on using the repository browser.