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