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