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

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

This commit was generated by cvs2svn to compensate for changes in r609,
which included commits to RCS files with non-trunk default branches.

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