]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - binutils/ieee.c
* ieee.c: New file with code to read IEEE debugging information.
[thirdparty/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 /* If this is a bitfield, this is the size in bits. If this is not
86 a bitfield, this is zero. */
87 unsigned long bitsize;
88 /* If this is a function type ('x' or 'X') this is the return type. */
89 debug_type return_type;
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 static void ieee_error
106 PARAMS ((bfd *, const bfd_byte *, const bfd_byte *, const char *));
107 static void ieee_eof PARAMS ((bfd *));
108 static char *savestring PARAMS ((const char *, unsigned long));
109 static boolean ieee_read_number
110 PARAMS ((bfd *, const bfd_byte *, const bfd_byte **, const bfd_byte *,
111 bfd_vma *));
112 static boolean ieee_read_optional_number
113 PARAMS ((bfd *, const bfd_byte *, const bfd_byte **, const bfd_byte *,
114 bfd_vma *, boolean *));
115 static boolean ieee_read_id
116 PARAMS ((bfd *, const bfd_byte *, const bfd_byte **, const bfd_byte *,
117 const char **, unsigned long *));
118 static boolean ieee_read_optional_id
119 PARAMS ((bfd *, const bfd_byte *, const bfd_byte **, const bfd_byte *,
120 const char **, unsigned long *, boolean *));
121 static boolean ieee_read_expression
122 PARAMS ((bfd *, const bfd_byte *, const bfd_byte **, const bfd_byte *,
123 bfd_vma *));
124 static debug_type ieee_builtin_type
125 PARAMS ((PTR, bfd *, struct ieee_types *, const bfd_byte *,
126 const bfd_byte *, unsigned int));
127 static boolean ieee_read_type_index
128 PARAMS ((PTR, bfd *, struct ieee_types *, const bfd_byte *,
129 const bfd_byte **, const bfd_byte *, debug_type *));
130 static int ieee_regno_to_gen PARAMS ((bfd *, int));
131 static boolean parse_ieee_bb
132 PARAMS ((PTR, bfd *, struct ieee_types *, struct ieee_blockstack *,
133 const bfd_byte *, const bfd_byte **, const bfd_byte *));
134 static boolean parse_ieee_be
135 PARAMS ((PTR, bfd *, struct ieee_blockstack *, const bfd_byte *,
136 const bfd_byte **, const bfd_byte *));
137 static boolean parse_ieee_nn
138 PARAMS ((PTR, bfd *, struct ieee_vars *, const bfd_byte *,
139 const bfd_byte **, const bfd_byte *));
140 static boolean parse_ieee_ty
141 PARAMS ((PTR, bfd *, struct ieee_types *, struct ieee_vars *,
142 const bfd_byte *, const bfd_byte **, const bfd_byte *));
143 static boolean parse_ieee_atn
144 PARAMS ((PTR, bfd *, struct ieee_types *, struct ieee_vars *, int,
145 const bfd_byte *, const bfd_byte **, const bfd_byte *));
146 static boolean ieee_require_asn
147 PARAMS ((bfd *, const bfd_byte *, const bfd_byte **, const bfd_byte *,
148 bfd_vma *));
149
150 /* Report an error in the IEEE debugging information. */
151
152 static void
153 ieee_error (abfd, bytes, p, s)
154 bfd *abfd;
155 const bfd_byte *bytes;
156 const bfd_byte *p;
157 const char *s;
158 {
159 if (p != NULL)
160 fprintf (stderr, "%s: 0x%lx: %s (0x%x)\n", bfd_get_filename (abfd),
161 (unsigned long) (p - bytes), s, *p);
162 else
163 fprintf (stderr, "%s: %s\n", bfd_get_filename (abfd), s);
164 }
165
166 /* Report an unexpected EOF in the IEEE debugging information. */
167
168 static void
169 ieee_eof (abfd)
170 bfd *abfd;
171 {
172 ieee_error (abfd, (const bfd_byte *) NULL, (const bfd_byte *) NULL,
173 "unexpected end of debugging information");
174 }
175
176 /* Save a string in memory. */
177
178 static char *
179 savestring (start, len)
180 const char *start;
181 unsigned long len;
182 {
183 char *ret;
184
185 ret = (char *) xmalloc (len + 1);
186 memcpy (ret, start, len);
187 ret[len] = '\0';
188 return ret;
189 }
190
191 /* Read a number which must be present in an IEEE file. */
192
193 static boolean
194 ieee_read_number (abfd, bytes, pp, pend, pv)
195 bfd *abfd;
196 const bfd_byte *bytes;
197 const bfd_byte **pp;
198 const bfd_byte *pend;
199 bfd_vma *pv;
200 {
201 return ieee_read_optional_number (abfd, bytes, pp, pend, pv,
202 (boolean *) NULL);
203 }
204
205 /* Read a number in an IEEE file. If ppresent is not NULL, the number
206 need not be there. */
207
208 static boolean
209 ieee_read_optional_number (abfd, bytes, pp, pend, pv, ppresent)
210 bfd *abfd;
211 const bfd_byte *bytes;
212 const bfd_byte **pp;
213 const bfd_byte *pend;
214 bfd_vma *pv;
215 boolean *ppresent;
216 {
217 ieee_record_enum_type b;
218
219 if (*pp >= pend)
220 {
221 if (ppresent != NULL)
222 {
223 *ppresent = false;
224 return true;
225 }
226 ieee_eof (abfd);
227 return false;
228 }
229
230 b = (ieee_record_enum_type) **pp;
231 ++*pp;
232
233 if (b <= ieee_number_end_enum)
234 {
235 *pv = (bfd_vma) b;
236 if (ppresent != NULL)
237 *ppresent = true;
238 return true;
239 }
240
241 if (b >= ieee_number_repeat_start_enum && b <= ieee_number_repeat_end_enum)
242 {
243 unsigned int i;
244
245 i = (int) b - (int) ieee_number_repeat_start_enum;
246 if (*pp + i - 1 >= pend)
247 {
248 ieee_eof (abfd);
249 return false;
250 }
251
252 *pv = 0;
253 for (; i > 0; i--)
254 {
255 *pv <<= 8;
256 *pv += **pp;
257 ++*pp;
258 }
259
260 if (ppresent != NULL)
261 *ppresent = true;
262
263 return true;
264 }
265
266 if (ppresent != NULL)
267 {
268 --*pp;
269 *ppresent = false;
270 return true;
271 }
272
273 ieee_error (abfd, bytes, *pp - 1, "invalid number");
274 return false;
275 }
276
277 /* Read a required string from an IEEE file. */
278
279 static boolean
280 ieee_read_id (abfd, bytes, pp, pend, pname, pnamlen)
281 bfd *abfd;
282 const bfd_byte *bytes;
283 const bfd_byte **pp;
284 const bfd_byte *pend;
285 const char **pname;
286 unsigned long *pnamlen;
287 {
288 return ieee_read_optional_id (abfd, bytes, pp, pend, pname, pnamlen,
289 (boolean *) NULL);
290 }
291
292 /* Read a string from an IEEE file. If ppresent is not NULL, the
293 string is optional. */
294
295 static boolean
296 ieee_read_optional_id (abfd, bytes, pp, pend, pname, pnamlen, ppresent)
297 bfd *abfd;
298 const bfd_byte *bytes;
299 const bfd_byte **pp;
300 const bfd_byte *pend;
301 const char **pname;
302 unsigned long *pnamlen;
303 boolean *ppresent;
304 {
305 bfd_byte b;
306 unsigned long len;
307
308 if (*pp >= pend)
309 {
310 ieee_eof (abfd);
311 return false;
312 }
313
314 b = **pp;
315 ++*pp;
316
317 if (b <= 0x7f)
318 len = b;
319 else if ((ieee_record_enum_type) b == ieee_extension_length_1_enum)
320 {
321 len = **pp;
322 ++*pp;
323 }
324 else if ((ieee_record_enum_type) b == ieee_extension_length_2_enum)
325 {
326 len = (**pp << 8) + (*pp)[1];
327 *pp += 2;
328 }
329 else
330 {
331 if (ppresent != NULL)
332 {
333 --*pp;
334 *ppresent = false;
335 return true;
336 }
337 ieee_error (abfd, bytes, *pp - 1, "invalid string length");
338 return false;
339 }
340
341 if ((unsigned long) (pend - *pp) < len)
342 {
343 ieee_eof (abfd);
344 return false;
345 }
346
347 *pname = (const char *) *pp;
348 *pnamlen = len;
349 *pp += len;
350
351 if (ppresent != NULL)
352 *ppresent = true;
353
354 return true;
355 }
356
357 /* Read an expression from an IEEE file. Since this code is only used
358 to parse debugging information, I haven't bothered to write a full
359 blown IEEE expression parser. I've only thrown in the things I've
360 seen in debugging information. This can be easily extended if
361 necessary. */
362
363 static boolean
364 ieee_read_expression (abfd, bytes, pp, pend, pv)
365 bfd *abfd;
366 const bfd_byte *bytes;
367 const bfd_byte **pp;
368 const bfd_byte *pend;
369 bfd_vma *pv;
370 {
371 const bfd_byte *expr_start;
372 #define EXPR_STACK_SIZE (10)
373 bfd_vma expr_stack[EXPR_STACK_SIZE];
374 bfd_vma *esp;
375
376 expr_start = *pp;
377
378 esp = expr_stack;
379
380 while (1)
381 {
382 const bfd_byte *start;
383 bfd_vma val;
384 boolean present;
385 ieee_record_enum_type c;
386
387 start = *pp;
388
389 if (! ieee_read_optional_number (abfd, bytes, pp, pend, &val, &present))
390 return false;
391
392 if (present)
393 {
394 if (esp - expr_stack >= EXPR_STACK_SIZE)
395 {
396 ieee_error (abfd, bytes, start, "expression stack overflow");
397 return false;
398 }
399 *esp++ = val;
400 continue;
401 }
402
403 c = (ieee_record_enum_type) **pp;
404
405 if (c >= ieee_module_beginning_enum)
406 break;
407
408 ++*pp;
409
410 if (c == ieee_comma)
411 break;
412
413 switch (c)
414 {
415 default:
416 ieee_error (abfd, bytes, start,
417 "unsupported IEEE expression operator");
418 break;
419
420 case ieee_variable_R_enum:
421 {
422 bfd_vma indx;
423 asection *s;
424
425 if (! ieee_read_number (abfd, bytes, pp, pend, &indx))
426 return false;
427 for (s = abfd->sections; s != NULL; s = s->next)
428 if ((bfd_vma) s->target_index == indx)
429 break;
430 if (s == NULL)
431 {
432 ieee_error (abfd, bytes, start, "unknown section");
433 return false;
434 }
435
436 if (esp - expr_stack >= EXPR_STACK_SIZE)
437 {
438 ieee_error (abfd, bytes, start, "expression stack overflow");
439 return false;
440 }
441
442 *esp++ = bfd_get_section_vma (abfd, s);
443 }
444 break;
445
446 case ieee_function_plus_enum:
447 case ieee_function_minus_enum:
448 {
449 bfd_vma v1, v2;
450
451 if (esp - expr_stack < 2)
452 {
453 ieee_error (abfd, bytes, start, "expression stack underflow");
454 return false;
455 }
456
457 v1 = *--esp;
458 v2 = *--esp;
459 *esp++ = v1 + v2;
460 }
461 break;
462 }
463 }
464
465 if (esp - 1 != expr_stack)
466 {
467 ieee_error (abfd, bytes, expr_start, "expression stack mismatch");
468 return false;
469 }
470
471 *pv = *--esp;
472
473 return true;
474 }
475
476 /* Return an IEEE builtin type. */
477
478 static debug_type
479 ieee_builtin_type (dhandle, abfd, types, bytes, p, indx)
480 PTR dhandle;
481 bfd *abfd;
482 struct ieee_types *types;
483 const bfd_byte *bytes;
484 const bfd_byte *p;
485 unsigned int indx;
486 {
487 boolean ptr;
488 debug_type type;
489 const char *name;
490
491 if (indx < BUILTIN_TYPE_COUNT
492 && types->builtins[indx] != DEBUG_TYPE_NULL)
493 return types->builtins[indx];
494
495 ptr = false;
496 switch (indx)
497 {
498 default:
499 ieee_error (abfd, bytes, p, "unknown builtin type");
500 return NULL;
501
502 case 32:
503 ptr = true;
504 /* Fall through. */
505 case 0:
506 type = debug_make_void_type (dhandle);
507 name = NULL;
508 break;
509
510 case 33:
511 ptr = true;
512 /* Fall through. */
513 case 1:
514 type = debug_make_void_type (dhandle);
515 name = "void";
516 break;
517
518 case 34:
519 ptr = true;
520 /* Fall through. */
521 case 2:
522 type = debug_make_int_type (dhandle, 1, false);
523 name = "signed char";
524 break;
525
526 case 35:
527 ptr = true;
528 /* Fall through. */
529 case 3:
530 type = debug_make_int_type (dhandle, 1, true);
531 name = "unsigned char";
532 break;
533
534 case 36:
535 ptr = true;
536 /* Fall through. */
537 case 4:
538 type = debug_make_int_type (dhandle, 2, false);
539 name = "signed short int";
540 break;
541
542 case 37:
543 ptr = true;
544 /* Fall through. */
545 case 5:
546 type = debug_make_int_type (dhandle, 2, true);
547 name = "unsigned short int";
548 break;
549
550 case 38:
551 ptr = true;
552 /* Fall through. */
553 case 6:
554 type = debug_make_int_type (dhandle, 4, false);
555 name = "signed long";
556 break;
557
558 case 39:
559 ptr = true;
560 /* Fall through. */
561 case 7:
562 type = debug_make_int_type (dhandle, 4, true);
563 name = "unsigned long";
564 break;
565
566 case 40:
567 ptr = true;
568 /* Fall through. */
569 case 8:
570 type = debug_make_int_type (dhandle, 8, false);
571 name = "signed long long";
572 break;
573
574 case 41:
575 ptr = true;
576 /* Fall through. */
577 case 9:
578 type = debug_make_int_type (dhandle, 8, true);
579 name = "unsigned long long";
580 break;
581
582 case 42:
583 ptr = true;
584 /* Fall through. */
585 case 10:
586 type = debug_make_float_type (dhandle, 4);
587 name = "float";
588 break;
589
590 case 43:
591 ptr = true;
592 /* Fall through. */
593 case 11:
594 type = debug_make_float_type (dhandle, 8);
595 name = "double";
596 break;
597
598 case 44:
599 ptr = true;
600 /* Fall through. */
601 case 12:
602 /* FIXME: The size for this type should depend upon the
603 processor. */
604 type = debug_make_float_type (dhandle, 12);
605 name = "long double";
606 break;
607
608 case 45:
609 ptr = true;
610 /* Fall through. */
611 case 13:
612 type = debug_make_float_type (dhandle, 16);
613 name = "long long double";
614 break;
615
616 case 46:
617 ptr = true;
618 /* Fall through. */
619 case 14:
620 type = debug_make_array_type (dhandle,
621 ieee_builtin_type (dhandle, abfd, types,
622 bytes, p, 19),
623 ieee_builtin_type (dhandle, abfd, types,
624 bytes, p, 16),
625 0, -1, true);
626 name = "QUOTED STRING";
627 break;
628
629 case 47:
630 ptr = true;
631 /* Fall through. */
632 case 15:
633 /* FIXME: This should be a code address. */
634 type = debug_make_int_type (dhandle, 4, true);
635 name = "instruction address";
636 break;
637
638 case 48:
639 ptr = true;
640 /* Fall through. */
641 case 16:
642 /* FIXME: The size for this type should depend upon the
643 processor. */
644 type = debug_make_int_type (dhandle, 4, false);
645 name = "int";
646 break;
647
648 case 49:
649 ptr = true;
650 /* Fall through. */
651 case 17:
652 /* FIXME: The size for this type should depend upon the
653 processor. */
654 type = debug_make_int_type (dhandle, 4, true);
655 name = "unsigned";
656 break;
657
658 case 50:
659 ptr = true;
660 /* Fall through. */
661 case 18:
662 /* FIXME: The size for this type should depend upon the
663 processor. */
664 type = debug_make_int_type (dhandle, 4, true);
665 name = "unsigned int";
666 break;
667
668 case 51:
669 ptr = true;
670 /* Fall through. */
671 case 19:
672 type = debug_make_int_type (dhandle, 1, false);
673 name = "char";
674 break;
675
676 case 52:
677 ptr = true;
678 /* Fall through. */
679 case 20:
680 type = debug_make_int_type (dhandle, 4, false);
681 name = "long";
682 break;
683
684 case 53:
685 ptr = true;
686 /* Fall through. */
687 case 21:
688 type = debug_make_int_type (dhandle, 2, false);
689 name = "short";
690 break;
691
692 case 54:
693 ptr = true;
694 /* Fall through. */
695 case 22:
696 type = debug_make_int_type (dhandle, 2, true);
697 name = "unsigned short";
698 break;
699
700 case 55:
701 ptr = true;
702 /* Fall through. */
703 case 23:
704 type = debug_make_int_type (dhandle, 2, false);
705 name = "short int";
706 break;
707
708 case 56:
709 ptr = true;
710 /* Fall through. */
711 case 24:
712 type = debug_make_int_type (dhandle, 2, false);
713 name = "signed short";
714 break;
715
716 case 57:
717 ptr = true;
718 /* Fall through. */
719 case 25:
720 ieee_error (abfd, bytes, p, "BCD float type not supported");
721 return false;
722 }
723
724 if (ptr)
725 type = debug_make_pointer_type (dhandle, type);
726 else if (name != NULL)
727 type = debug_name_type (dhandle, name, type);
728
729 assert (indx < BUILTIN_TYPE_COUNT);
730
731 types->builtins[indx] = type;
732
733 return type;
734 }
735
736 /* Read a type index and return the corresponding type. */
737
738 static boolean
739 ieee_read_type_index (dhandle, abfd, types, bytes, pp, pend, ptype)
740 PTR dhandle;
741 bfd *abfd;
742 struct ieee_types *types;
743 const bfd_byte *bytes;
744 const bfd_byte **pp;
745 const bfd_byte *pend;
746 debug_type *ptype;
747 {
748 const bfd_byte *start;
749 bfd_vma indx;
750
751 start = *pp;
752
753 if (! ieee_read_number (abfd, bytes, pp, pend, &indx))
754 return false;
755
756 if (indx < 256)
757 {
758 *ptype = ieee_builtin_type (dhandle, abfd, types, bytes, start, indx);
759 if (*ptype == NULL)
760 return false;
761 return true;
762 }
763
764 indx -= 256;
765 if (indx >= types->alloc
766 || types->types[indx].type == DEBUG_TYPE_NULL)
767 {
768 ieee_error (abfd, bytes, start, "undefined type");
769 return false;
770 }
771
772 *ptype = types->types[indx].type;
773
774 return true;
775 }
776
777 /* Convert a register number in IEEE debugging information into a
778 generic register number. */
779
780 static int
781 ieee_regno_to_gen (abfd, r)
782 bfd *abfd;
783 int r;
784 {
785 return r;
786 }
787
788 /* Parse IEEE debugging information for a file. This is passed the
789 bytes which compose the Debug Information Part of an IEEE file. */
790
791 boolean
792 parse_ieee (dhandle, abfd, bytes, len)
793 PTR dhandle;
794 bfd *abfd;
795 const bfd_byte *bytes;
796 bfd_size_type len;
797 {
798 struct ieee_blockstack blockstack;
799 struct ieee_vars vars;
800 struct ieee_types types;
801 unsigned int i;
802 const bfd_byte *p, *pend;
803
804 blockstack.bsp = blockstack.stack;
805 vars.alloc = 0;
806 vars.vars = NULL;
807 types.alloc = 0;
808 types.types = NULL;
809 for (i = 0; i < BUILTIN_TYPE_COUNT; i++)
810 types.builtins[i] = DEBUG_TYPE_NULL;
811
812 p = bytes;
813 pend = bytes + len;
814 while (p < pend)
815 {
816 const bfd_byte *record_start;
817 ieee_record_enum_type c;
818
819 record_start = p;
820
821 c = (ieee_record_enum_type) *p++;
822
823 if (c == ieee_at_record_enum)
824 c = (ieee_record_enum_type) (((unsigned int) c << 8) | *p++);
825
826 if (c <= ieee_number_repeat_end_enum)
827 {
828 ieee_error (abfd, bytes, record_start, "unexpected number");
829 return false;
830 }
831
832 switch (c)
833 {
834 default:
835 ieee_error (abfd, bytes, record_start, "unexpected record type");
836 return false;
837
838 case ieee_bb_record_enum:
839 if (! parse_ieee_bb (dhandle, abfd, &types, &blockstack, bytes,
840 &p, pend))
841 return false;
842 break;
843
844 case ieee_be_record_enum:
845 if (! parse_ieee_be (dhandle, abfd, &blockstack, bytes, &p, pend))
846 return false;
847 break;
848
849 case ieee_nn_record:
850 if (! parse_ieee_nn (dhandle, abfd, &vars, bytes, &p, pend))
851 return false;
852 break;
853
854 case ieee_ty_record_enum:
855 if (! parse_ieee_ty (dhandle, abfd, &types, &vars, bytes, &p, pend))
856 return false;
857 break;
858
859 case ieee_atn_record_enum:
860 if (! parse_ieee_atn (dhandle, abfd, &types, &vars,
861 (blockstack.bsp <= blockstack.stack
862 ? 0
863 : blockstack.bsp[-1].kind),
864 bytes, &p, pend))
865 return false;
866 break;
867 }
868 }
869
870 if (blockstack.bsp != blockstack.stack)
871 {
872 ieee_error (abfd, (const bfd_byte *) NULL, (const bfd_byte *) NULL,
873 "blocks left on stack at end");
874 return false;
875 }
876
877 return true;
878 }
879
880 /* Handle an IEEE BB record. */
881
882 static boolean
883 parse_ieee_bb (dhandle, abfd, types, blockstack, bytes, pp, pend)
884 PTR dhandle;
885 bfd *abfd;
886 struct ieee_types *types;
887 struct ieee_blockstack *blockstack;
888 const bfd_byte *bytes;
889 const bfd_byte **pp;
890 const bfd_byte *pend;
891 {
892 const bfd_byte *block_start;
893 bfd_byte b;
894 bfd_vma size;
895 const char *name;
896 unsigned long namlen;
897 char *namcopy;
898
899 block_start = *pp;
900
901 b = **pp;
902 ++*pp;
903
904 if (! ieee_read_number (abfd, bytes, pp, pend, &size)
905 || ! ieee_read_id (abfd, bytes, pp, pend, &name, &namlen))
906 return false;
907
908 switch (b)
909 {
910 case 1:
911 /* BB1: Type definitions local to a module. */
912 namcopy = savestring (name, namlen);
913 if (namcopy == NULL)
914 return false;
915 if (! debug_set_filename (dhandle, namcopy))
916 return false;
917 break;
918
919 case 2:
920 /* BB2: Global type definitions. The name is supposed to be
921 empty, but we don't check. */
922 if (! debug_set_filename (dhandle, "*global*"))
923 return false;
924 break;
925
926 case 3:
927 /* BB3: High level module block begin. We don't have to do
928 anything here. The name is supposed to be the same as for
929 the BB1, but we don't check. */
930 break;
931
932 case 4:
933 /* BB4: Global function. */
934 {
935 bfd_vma stackspace, typindx, offset;
936 debug_type return_type;
937
938 if (! ieee_read_number (abfd, bytes, pp, pend, &stackspace)
939 || ! ieee_read_number (abfd, bytes, pp, pend, &typindx)
940 || ! ieee_read_expression (abfd, bytes, pp, pend, &offset))
941 return false;
942
943 /* We have no way to record the stack space. FIXME. */
944
945 if (typindx < 256)
946 {
947 return_type = ieee_builtin_type (dhandle, abfd, types, bytes,
948 block_start, typindx);
949 if (return_type == NULL)
950 return false;
951 }
952 else
953 {
954 typindx -= 256;
955 if (typindx >= types->alloc
956 || types->types[typindx].type == DEBUG_TYPE_NULL)
957 {
958 ieee_error (abfd, bytes, block_start, "undefined type index");
959 return false;
960 }
961 return_type = types->types[typindx].return_type;
962 if (return_type == NULL)
963 return_type = types->types[typindx].type;
964 }
965
966 namcopy = savestring (name, namlen);
967 if (namcopy == NULL)
968 return false;
969 if (! debug_record_function (dhandle, namcopy, return_type,
970 true, offset))
971 return false;
972 }
973 break;
974
975 case 5:
976 /* BB5: File name for source line numbers. */
977 {
978 unsigned int i;
979
980 /* We ignore the date and time. FIXME. */
981 for (i = 0; i < 6; i++)
982 {
983 bfd_vma ignore;
984 boolean present;
985
986 if (! ieee_read_optional_number (abfd, bytes, pp, pend, &ignore,
987 &present))
988 return false;
989 if (! present)
990 break;
991 }
992
993 namcopy = savestring (name, namlen);
994 if (namcopy == NULL)
995 return false;
996 if (! debug_start_source (dhandle, namcopy))
997 return false;
998 }
999 break;
1000
1001 case 6:
1002 /* BB6: Local function or block. */
1003 {
1004 bfd_vma stackspace, typindx, offset;
1005
1006 if (! ieee_read_number (abfd, bytes, pp, pend, &stackspace)
1007 || ! ieee_read_number (abfd, bytes, pp, pend, &typindx)
1008 || ! ieee_read_expression (abfd, bytes, pp, pend, &offset))
1009 return false;
1010
1011 /* We have no way to record the stack space. FIXME. */
1012
1013 if (namlen == 0)
1014 {
1015 if (! debug_start_block (dhandle, offset))
1016 return false;
1017 /* Change b to indicate that this is a block
1018 rather than a function. */
1019 b = 0x86;
1020 }
1021 else
1022 {
1023 debug_type return_type;
1024
1025 if (typindx < 256)
1026 {
1027 return_type = ieee_builtin_type (dhandle, abfd, types, bytes,
1028 block_start, typindx);
1029 if (return_type == NULL)
1030 return false;
1031 }
1032 else
1033 {
1034 typindx -= 256;
1035 if (typindx >= types->alloc
1036 || types->types[typindx].type == DEBUG_TYPE_NULL)
1037 {
1038 ieee_error (abfd, bytes, block_start,
1039 "undefined type index");
1040 return false;
1041 }
1042 return_type = types->types[typindx].return_type;
1043 if (return_type == NULL)
1044 return_type = types->types[typindx].type;
1045 }
1046
1047 namcopy = savestring (name, namlen);
1048 if (namcopy == NULL)
1049 return false;
1050 if (! debug_record_function (dhandle, namcopy, return_type,
1051 false, offset))
1052 return false;
1053 }
1054 }
1055 break;
1056
1057 case 10:
1058 /* BB10: Assembler module scope. We completely ignore all this
1059 information. FIXME. */
1060 {
1061 const char *inam, *vstr;
1062 unsigned long inamlen, vstrlen;
1063 bfd_vma tool_type;
1064 boolean present;
1065 unsigned int i;
1066
1067 if (! ieee_read_id (abfd, bytes, pp, pend, &inam, &inamlen)
1068 || ! ieee_read_number (abfd, bytes, pp, pend, &tool_type)
1069 || ! ieee_read_optional_id (abfd, bytes, pp, pend, &vstr, &vstrlen,
1070 &present))
1071 return false;
1072 for (i = 0; i < 6; i++)
1073 {
1074 bfd_vma ignore;
1075
1076 if (! ieee_read_optional_number (abfd, bytes, pp, pend, &ignore,
1077 &present))
1078 return false;
1079 if (! present)
1080 break;
1081 }
1082 }
1083 break;
1084
1085 case 11:
1086 /* BB11: Module section. We completely ignore all this
1087 information. FIXME. */
1088 {
1089 bfd_vma sectype, secindx, offset, map;
1090 boolean present;
1091
1092 if (! ieee_read_number (abfd, bytes, pp, pend, &sectype)
1093 || ! ieee_read_number (abfd, bytes, pp, pend, &secindx)
1094 || ! ieee_read_expression (abfd, bytes, pp, pend, &offset)
1095 || ! ieee_read_optional_number (abfd, bytes, pp, pend, &map,
1096 &present))
1097 return false;
1098 }
1099 break;
1100
1101 default:
1102 ieee_error (abfd, bytes, block_start, "unknown BB type");
1103 return false;
1104 }
1105
1106
1107 /* Push this block on the block stack. */
1108
1109 if (blockstack->bsp >= blockstack->stack + BLOCKSTACK_SIZE)
1110 {
1111 ieee_error (abfd, (const bfd_byte *) NULL, (const bfd_byte *) NULL,
1112 "stack overflow");
1113 return false;
1114 }
1115
1116 blockstack->bsp->kind = b;
1117 if (b == 5)
1118 blockstack->bsp->filename = namcopy;
1119 ++blockstack->bsp;
1120
1121 return true;
1122 }
1123
1124 /* Handle an IEEE BE record. */
1125
1126 static boolean
1127 parse_ieee_be (dhandle, abfd, blockstack, bytes, pp, pend)
1128 PTR dhandle;
1129 bfd *abfd;
1130 struct ieee_blockstack *blockstack;
1131 const bfd_byte *bytes;
1132 const bfd_byte **pp;
1133 const bfd_byte *pend;
1134 {
1135 bfd_vma offset;
1136
1137 if (blockstack->bsp <= blockstack->stack)
1138 {
1139 ieee_error (abfd, bytes, *pp, "stack underflow");
1140 return false;
1141 }
1142 --blockstack->bsp;
1143
1144 switch (blockstack->bsp->kind)
1145 {
1146 case 4:
1147 case 6:
1148 if (! ieee_read_expression (abfd, bytes, pp, pend, &offset))
1149 return false;
1150 if (! debug_end_function (dhandle, offset))
1151 return false;
1152 break;
1153
1154 case 0x86:
1155 /* This is BE6 when BB6 started a block rather than a local
1156 function. */
1157 if (! ieee_read_expression (abfd, bytes, pp, pend, &offset))
1158 return false;
1159 if (! debug_end_block (dhandle, offset))
1160 return false;
1161 break;
1162
1163 case 5:
1164 /* When we end a BB5, we look up the stack for the last BB5, if
1165 there is one, so that we can call debug_start_source. */
1166 if (blockstack->bsp > blockstack->stack)
1167 {
1168 struct ieee_block *bl;
1169
1170 bl = blockstack->bsp;
1171 do
1172 {
1173 --bl;
1174 if (bl->kind == 5)
1175 {
1176 if (! debug_start_source (dhandle, bl->filename))
1177 return false;
1178 break;
1179 }
1180 }
1181 while (bl != blockstack->stack);
1182 }
1183 break;
1184
1185 case 11:
1186 if (! ieee_read_expression (abfd, bytes, pp, pend, &offset))
1187 return false;
1188 /* We just ignore the module size. FIXME. */
1189 break;
1190
1191 default:
1192 /* Other block types do not have any trailing information. */
1193 break;
1194 }
1195
1196 return true;
1197 }
1198
1199 /* Parse an NN record. */
1200
1201 static boolean
1202 parse_ieee_nn (dhandle, abfd, vars, bytes, pp, pend)
1203 PTR dhandle;
1204 bfd *abfd;
1205 struct ieee_vars *vars;
1206 const bfd_byte *bytes;
1207 const bfd_byte **pp;
1208 const bfd_byte *pend;
1209 {
1210 const bfd_byte *nn_start;
1211 bfd_vma varindx;
1212 const char *name;
1213 unsigned long namlen;
1214
1215 nn_start = *pp;
1216
1217 if (! ieee_read_number (abfd, bytes, pp, pend, &varindx)
1218 || ! ieee_read_id (abfd, bytes, pp, pend, &name, &namlen))
1219 return false;
1220
1221 if (varindx < 32)
1222 {
1223 ieee_error (abfd, bytes, nn_start, "illegal variable index");
1224 return false;
1225 }
1226 varindx -= 32;
1227
1228 if (varindx >= vars->alloc)
1229 {
1230 unsigned int alloc;
1231
1232 alloc = vars->alloc;
1233 if (alloc == 0)
1234 alloc = 4;
1235 while (varindx >= alloc)
1236 alloc *= 2;
1237 vars->vars = ((struct ieee_var *)
1238 xrealloc (vars->vars, alloc * sizeof *vars->vars));
1239 memset (vars->vars + vars->alloc, 0,
1240 (alloc - vars->alloc) * sizeof *vars->vars);
1241 vars->alloc = alloc;
1242 }
1243
1244 vars->vars[varindx].name = name;
1245 vars->vars[varindx].namlen = namlen;
1246
1247 return true;
1248 }
1249
1250 /* Parse a TY record. */
1251
1252 static boolean
1253 parse_ieee_ty (dhandle, abfd, types, vars, bytes, pp, pend)
1254 PTR dhandle;
1255 bfd *abfd;
1256 struct ieee_types *types;
1257 struct ieee_vars *vars;
1258 const bfd_byte *bytes;
1259 const bfd_byte **pp;
1260 const bfd_byte *pend;
1261 {
1262 const bfd_byte *ty_start, *ty_var_start, *ty_code_start;
1263 bfd_vma typeindx, varindx, tc;
1264 debug_type type;
1265 boolean tag, typdef;
1266 unsigned long type_bitsize;
1267 debug_type return_type;
1268
1269 ty_start = *pp;
1270
1271 if (! ieee_read_number (abfd, bytes, pp, pend, &typeindx))
1272 return false;
1273
1274 if (typeindx < 256)
1275 {
1276 ieee_error (abfd, bytes, ty_start, "illegal type index");
1277 return false;
1278 }
1279 typeindx -= 256;
1280
1281 if (typeindx >= types->alloc)
1282 {
1283 unsigned int nalloc;
1284 struct ieee_type *t, *tend;
1285
1286 nalloc = types->alloc;
1287 if (nalloc == 0)
1288 nalloc = 4;
1289 while (typeindx >= nalloc)
1290 nalloc *= 2;
1291 types->types = ((struct ieee_type *)
1292 xrealloc (types->types, nalloc * sizeof *types->types));
1293 tend = types->types + nalloc;
1294 for (t = types->types + types->alloc; t < tend; t++)
1295 {
1296 t->bitsize = 0;
1297 t->type = DEBUG_TYPE_NULL;
1298 }
1299 types->alloc = nalloc;
1300 }
1301
1302 if (**pp != 0xce)
1303 {
1304 ieee_error (abfd, bytes, *pp, "unknown TY code");
1305 return false;
1306 }
1307 ++*pp;
1308
1309 ty_var_start = *pp;
1310
1311 if (! ieee_read_number (abfd, bytes, pp, pend, &varindx))
1312 return false;
1313
1314 if (varindx < 32)
1315 {
1316 ieee_error (abfd, bytes, ty_var_start, "illegal variable index");
1317 return false;
1318 }
1319 varindx -= 32;
1320
1321 if (varindx >= vars->alloc || vars->vars[varindx].name == NULL)
1322 {
1323 ieee_error (abfd, bytes, ty_var_start, "undefined variable in TY");
1324 return false;
1325 }
1326
1327 ty_code_start = *pp;
1328
1329 if (! ieee_read_number (abfd, bytes, pp, pend, &tc))
1330 return false;
1331
1332 tag = false;
1333 typdef = false;
1334 type_bitsize = 0;
1335 return_type = DEBUG_TYPE_NULL;
1336 switch (tc)
1337 {
1338 default:
1339 ieee_error (abfd, bytes, ty_code_start, "unknown TY code");
1340 return false;
1341
1342 case '!':
1343 /* Unknown type, with size. We treat it as int. FIXME. */
1344 {
1345 bfd_vma size;
1346
1347 if (! ieee_read_number (abfd, bytes, pp, pend, &size))
1348 return false;
1349 type = debug_make_int_type (dhandle, size, false);
1350 }
1351 break;
1352
1353 case 'A': /* Array. */
1354 case 'a': /* FORTRAN array in column/row order. FIXME: Not
1355 distinguished from normal array. */
1356 {
1357 debug_type ele_type;
1358 bfd_vma lower, upper;
1359
1360 if (! ieee_read_type_index (dhandle, abfd, types, bytes, pp, pend,
1361 &ele_type)
1362 || ! ieee_read_number (abfd, bytes, pp, pend, &lower)
1363 || ! ieee_read_number (abfd, bytes, pp, pend, &upper))
1364 return false;
1365 type = debug_make_array_type (dhandle, ele_type,
1366 debug_make_int_type (dhandle, 4, false),
1367 (bfd_signed_vma) lower,
1368 (bfd_signed_vma) upper,
1369 false);
1370 }
1371 break;
1372
1373 case 'E':
1374 /* Simple enumeration. */
1375 {
1376 bfd_vma size;
1377 unsigned int alloc;
1378 const char **names;
1379 unsigned int c;
1380 bfd_signed_vma *vals;
1381 unsigned int i;
1382
1383 if (! ieee_read_number (abfd, bytes, pp, pend, &size))
1384 return false;
1385 /* FIXME: we ignore the enumeration size. */
1386
1387 alloc = 10;
1388 names = (const char **) xmalloc (alloc * sizeof *names);
1389 memset (names, 0, alloc * sizeof *names);
1390 c = 0;
1391 while (1)
1392 {
1393 const char *name;
1394 unsigned long namlen;
1395 boolean present;
1396
1397 if (! ieee_read_optional_id (abfd, bytes, pp, pend, &name,
1398 &namlen, &present))
1399 return false;
1400 if (! present)
1401 break;
1402
1403 if (c + 1 >= alloc)
1404 {
1405 alloc += 10;
1406 names = ((const char **)
1407 xrealloc (names, alloc * sizeof *names));
1408 }
1409
1410 names[c] = savestring (name, namlen);
1411 if (names[c] == NULL)
1412 return false;
1413 ++c;
1414 }
1415
1416 names[c] = NULL;
1417
1418 vals = (bfd_signed_vma *) xmalloc (c * sizeof *vals);
1419 for (i = 0; i < c; i++)
1420 vals[i] = i;
1421
1422 type = debug_make_enum_type (dhandle, names, vals);
1423 tag = true;
1424 }
1425 break;
1426
1427 case 'G':
1428 /* Struct with bit fields. */
1429 {
1430 bfd_vma size;
1431 unsigned int alloc;
1432 debug_field *fields;
1433 unsigned int c;
1434
1435 if (! ieee_read_number (abfd, bytes, pp, pend, &size))
1436 return false;
1437
1438 alloc = 10;
1439 fields = (debug_field *) xmalloc (alloc * sizeof *fields);
1440 c = 0;
1441 while (1)
1442 {
1443 const char *name;
1444 unsigned long namlen;
1445 boolean present;
1446 debug_type ftype;
1447 bfd_vma bitpos, bitsize;
1448
1449 if (! ieee_read_optional_id (abfd, bytes, pp, pend, &name,
1450 &namlen, &present))
1451 return false;
1452 if (! present)
1453 break;
1454 if (! ieee_read_type_index (dhandle, abfd, types, bytes, pp, pend,
1455 &ftype)
1456 || ! ieee_read_number (abfd, bytes, pp, pend, &bitpos)
1457 || ! ieee_read_number (abfd, bytes, pp, pend, &bitsize))
1458 return false;
1459
1460 if (c + 1 >= alloc)
1461 {
1462 alloc += 10;
1463 fields = ((debug_field *)
1464 xrealloc (fields, alloc * sizeof *fields));
1465 }
1466
1467 fields[c] = debug_make_field (dhandle, savestring (name, namlen),
1468 ftype, bitpos, bitsize,
1469 DEBUG_VISIBILITY_PUBLIC);
1470 if (fields[c] == NULL)
1471 return false;
1472 ++c;
1473 }
1474
1475 fields[c] = NULL;
1476
1477 type = debug_make_struct_type (dhandle, true, size, fields);
1478 tag = true;
1479 }
1480 break;
1481
1482 case 'N':
1483 /* Enumeration. */
1484 {
1485 unsigned int alloc;
1486 const char **names;
1487 bfd_signed_vma *vals;
1488 unsigned int c;
1489
1490 alloc = 10;
1491 names = (const char **) xmalloc (alloc * sizeof *names);
1492 vals = (bfd_signed_vma *) xmalloc (alloc * sizeof *names);
1493 c = 0;
1494 while (1)
1495 {
1496 const char *name;
1497 unsigned long namlen;
1498 boolean present;
1499 bfd_vma val;
1500
1501 if (! ieee_read_optional_id (abfd, bytes, pp, pend, &name,
1502 &namlen, &present))
1503 return false;
1504 if (! present)
1505 break;
1506 if (! ieee_read_number (abfd, bytes, pp, pend, &val))
1507 return false;
1508
1509 /* If the length of the name is zero, then the value is
1510 actually the size of the enum. We ignore this
1511 information. FIXME. */
1512 if (namlen == 0)
1513 continue;
1514
1515 if (c + 1 >= alloc)
1516 {
1517 alloc += 10;
1518 names = ((const char **)
1519 xrealloc (names, alloc * sizeof *names));
1520 vals = ((bfd_signed_vma *)
1521 xrealloc (vals, alloc * sizeof *vals));
1522 }
1523
1524 names[c] = savestring (name, namlen);
1525 if (names[c] == NULL)
1526 return false;
1527 vals[c] = (bfd_signed_vma) val;
1528 ++c;
1529 }
1530
1531 names[c] = NULL;
1532
1533 type = debug_make_enum_type (dhandle, names, vals);
1534 tag = true;
1535 }
1536 break;
1537
1538 case 'O': /* Small pointer. We don't distinguish small and large
1539 pointers. FIXME. */
1540 case 'P': /* Large pointer. */
1541 {
1542 debug_type t;
1543
1544 if (! ieee_read_type_index (dhandle, abfd, types, bytes, pp, pend, &t))
1545 return false;
1546 type = debug_make_pointer_type (dhandle, t);
1547 }
1548 break;
1549
1550 case 'R':
1551 /* Range. */
1552 {
1553 bfd_vma low, high, signedp, size;
1554
1555 if (! ieee_read_number (abfd, bytes, pp, pend, &low)
1556 || ! ieee_read_number (abfd, bytes, pp, pend, &high)
1557 || ! ieee_read_number (abfd, bytes, pp, pend, &signedp)
1558 || ! ieee_read_number (abfd, bytes, pp, pend, &size))
1559 return false;
1560
1561 type = debug_make_range_type (dhandle,
1562 debug_make_int_type (dhandle, size,
1563 ! signedp),
1564 (bfd_signed_vma) low,
1565 (bfd_signed_vma) high);
1566 }
1567 break;
1568
1569 case 'S': /* Struct. */
1570 case 'U': /* Union. */
1571 {
1572 bfd_vma size;
1573 unsigned int alloc;
1574 debug_field *fields;
1575 unsigned int c;
1576
1577 if (! ieee_read_number (abfd, bytes, pp, pend, &size))
1578 return false;
1579
1580 alloc = 10;
1581 fields = (debug_field *) xmalloc (alloc * sizeof *fields);
1582 c = 0;
1583 while (1)
1584 {
1585 const char *name;
1586 unsigned long namlen;
1587 boolean present;
1588 bfd_vma tindx;
1589 bfd_vma offset;
1590 debug_type ftype;
1591 bfd_vma bitsize;
1592
1593 if (! ieee_read_optional_id (abfd, bytes, pp, pend, &name,
1594 &namlen, &present))
1595 return false;
1596 if (! present)
1597 break;
1598 if (! ieee_read_number (abfd, bytes, pp, pend, &tindx)
1599 || ! ieee_read_number (abfd, bytes, pp, pend, &offset))
1600 return false;
1601
1602 if (tindx < 256)
1603 {
1604 ftype = ieee_builtin_type (dhandle, abfd, types, bytes,
1605 ty_code_start, tindx);
1606 bitsize = 0;
1607 offset *= 8;
1608 }
1609 else
1610 {
1611 struct ieee_type *t;
1612
1613 tindx -= 256;
1614 if (tindx >= types->alloc
1615 || types->types[tindx].type == DEBUG_TYPE_NULL)
1616 {
1617 ieee_error (abfd, bytes, ty_start, "undefined type index");
1618 return false;
1619 }
1620 t = &types->types[tindx];
1621 ftype = t->type;
1622 bitsize = t->bitsize;
1623 if (bitsize == 0)
1624 offset *= 8;
1625 }
1626
1627 if (c + 1 >= alloc)
1628 {
1629 alloc += 10;
1630 fields = ((debug_field *)
1631 xrealloc (fields, alloc * sizeof *fields));
1632 }
1633
1634 fields[c] = debug_make_field (dhandle, savestring (name, namlen),
1635 ftype, offset, bitsize,
1636 DEBUG_VISIBILITY_PUBLIC);
1637 if (fields[c] == NULL)
1638 return false;
1639 ++c;
1640 }
1641
1642 fields[c] = NULL;
1643
1644 type = debug_make_struct_type (dhandle, tc == 'S', size, fields);
1645 tag = true;
1646 }
1647 break;
1648
1649 case 'T':
1650 /* Typedef. */
1651 if (! ieee_read_type_index (dhandle, abfd, types, bytes, pp, pend,
1652 &type))
1653 return false;
1654 typdef = true;
1655 break;
1656
1657 case 'X':
1658 /* Procedure. FIXME: This is an extern declaration, which we
1659 have no way of representing. */
1660 {
1661 bfd_vma attr;
1662 debug_type rtype;
1663 bfd_vma nargs;
1664 boolean present;
1665
1666 /* FIXME: We ignore the attribute and the argument names. */
1667
1668 if (! ieee_read_number (abfd, bytes, pp, pend, &attr)
1669 || ! ieee_read_type_index (dhandle, abfd, types, bytes, pp, pend,
1670 &rtype)
1671 || ! ieee_read_number (abfd, bytes, pp, pend, &nargs))
1672 return false;
1673 do
1674 {
1675 const char *name;
1676 unsigned long namlen;
1677
1678 if (! ieee_read_optional_id (abfd, bytes, pp, pend, &name,
1679 &namlen, &present))
1680 return false;
1681 }
1682 while (present);
1683
1684 type = debug_make_function_type (dhandle, rtype);
1685 return_type = rtype;
1686 }
1687 break;
1688
1689 case 'Z':
1690 /* Array with 0 lower bound. */
1691 {
1692 debug_type etype;
1693 bfd_vma high;
1694
1695 if (! ieee_read_type_index (dhandle, abfd, types, bytes, pp, pend,
1696 &etype)
1697 || ! ieee_read_number (abfd, bytes, pp, pend, &high))
1698 return false;
1699
1700 type = debug_make_array_type (dhandle, etype,
1701 debug_make_int_type (dhandle, 4, false),
1702 0, (bfd_signed_vma) high, false);
1703 }
1704 break;
1705
1706 case 'c': /* Complex. */
1707 case 'd': /* Double complex. */
1708 {
1709 const char *name;
1710 unsigned long namlen;
1711
1712 /* FIXME: I don't know what the name means. */
1713
1714 if (! ieee_read_id (abfd, bytes, pp, pend, &name, &namlen))
1715 return false;
1716
1717 type = debug_make_complex_type (dhandle, tc == 'c' ? 4 : 8);
1718 }
1719 break;
1720
1721 case 'f':
1722 /* Pascal file name. FIXME. */
1723 ieee_error (abfd, bytes, ty_code_start,
1724 "Pascal file name not supported");
1725 return false;
1726
1727 case 'g':
1728 /* Bitfield type. */
1729 {
1730 bfd_vma signedp, bitsize;
1731
1732 if (! ieee_read_number (abfd, bytes, pp, pend, &signedp)
1733 || ! ieee_read_number (abfd, bytes, pp, pend, &bitsize)
1734 || ! ieee_read_type_index (dhandle, abfd, types, bytes, pp, pend,
1735 &type))
1736 return false;
1737
1738 /* FIXME: This is just a guess. */
1739 if (! signedp)
1740 type = debug_make_int_type (dhandle, 4, true);
1741 type_bitsize = bitsize;
1742 }
1743 break;
1744
1745 case 'n':
1746 /* Qualifier. */
1747 {
1748 bfd_vma kind;
1749 debug_type t;
1750
1751 if (! ieee_read_number (abfd, bytes, pp, pend, &kind)
1752 || ! ieee_read_type_index (dhandle, abfd, types, bytes, pp, pend,
1753 &t))
1754 return false;
1755
1756 switch (kind)
1757 {
1758 default:
1759 ieee_error (abfd, bytes, ty_start, "unsupported qualifer");
1760 return false;
1761
1762 case 1:
1763 type = debug_make_const_type (dhandle, t);
1764 break;
1765
1766 case 2:
1767 type = debug_make_volatile_type (dhandle, t);
1768 break;
1769 }
1770 }
1771 break;
1772
1773 case 's':
1774 /* Set. */
1775 {
1776 bfd_vma size;
1777 debug_type etype;
1778
1779 if (! ieee_read_number (abfd, bytes, pp, pend, &size)
1780 || ! ieee_read_type_index (dhandle, abfd, types, bytes, pp, pend,
1781 &etype))
1782 return false;
1783
1784 /* FIXME: We ignore the size. */
1785
1786 type = debug_make_set_type (dhandle, etype, false);
1787 }
1788 break;
1789
1790 case 'x':
1791 /* Procedure with compiler dependencies. FIXME: This is an
1792 extern declaration, which we have no way of representing. */
1793 {
1794 bfd_vma attr, frame_type, push_mask, nargs, level, father;
1795 debug_type rtype;
1796 boolean present;
1797
1798 /* FIXME: We ignore almost all this information. */
1799
1800 if (! ieee_read_number (abfd, bytes, pp, pend, &attr)
1801 || ! ieee_read_number (abfd, bytes, pp, pend, &frame_type)
1802 || ! ieee_read_number (abfd, bytes, pp, pend, &push_mask)
1803 || ! ieee_read_type_index (dhandle, abfd, types, bytes, pp, pend,
1804 &rtype)
1805 || ! ieee_read_number (abfd, bytes, pp, pend, &nargs))
1806 return false;
1807 if (nargs != (bfd_vma) -1)
1808 {
1809 for (; nargs > 0; nargs--)
1810 {
1811 debug_type atype;
1812
1813 if (! ieee_read_type_index (dhandle, abfd, types, bytes, pp,
1814 pend, &atype))
1815 return false;
1816 }
1817 }
1818 if (! ieee_read_number (abfd, bytes, pp, pend, &level)
1819 || ! ieee_read_optional_number (abfd, bytes, pp, pend, &father,
1820 &present))
1821 return false;
1822
1823 type = debug_make_function_type (dhandle, rtype);
1824 return_type = rtype;
1825 }
1826 break;
1827 }
1828
1829 /* Record the type in the table. If the corresponding NN record has
1830 a name, name it. FIXME: Is this always correct? */
1831
1832 if (type == NULL)
1833 return false;
1834
1835 if ((tag || typdef)
1836 && vars->vars[varindx].namlen > 0)
1837 {
1838 const char *name;
1839
1840 name = savestring (vars->vars[varindx].name,
1841 vars->vars[varindx].namlen);
1842 if (tag)
1843 type = debug_tag_type (dhandle, name, type);
1844 else
1845 type = debug_name_type (dhandle, name, type);
1846 if (type == NULL)
1847 return false;
1848 }
1849
1850 types->types[typeindx].type = type;
1851 types->types[typeindx].bitsize = type_bitsize;
1852 types->types[typeindx].return_type = return_type;
1853
1854 return true;
1855 }
1856
1857 /* Parse an ATN record. */
1858
1859 static boolean
1860 parse_ieee_atn (dhandle, abfd, types, vars, blocktype, bytes, pp, pend)
1861 PTR dhandle;
1862 bfd *abfd;
1863 struct ieee_types *types;
1864 struct ieee_vars *vars;
1865 int blocktype;
1866 const bfd_byte *bytes;
1867 const bfd_byte **pp;
1868 const bfd_byte *pend;
1869 {
1870 const bfd_byte *atn_start, *atn_code_start;
1871 bfd_vma varindx;
1872 boolean zeroindx;
1873 debug_type type;
1874 bfd_vma atn_code;
1875 bfd_vma v, v2, v3, v4, v5;
1876 const char *name;
1877 unsigned long namlen;
1878 char *namcopy;
1879 boolean present;
1880
1881 atn_start = *pp;
1882
1883 if (! ieee_read_number (abfd, bytes, pp, pend, &varindx)
1884 || ! ieee_read_type_index (dhandle, abfd, types, bytes, pp, pend, &type))
1885 return false;
1886
1887 atn_code_start = *pp;
1888
1889 if (! ieee_read_number (abfd, bytes, pp, pend, &atn_code))
1890 return false;
1891
1892 if (varindx == 0)
1893 {
1894 zeroindx = true;
1895 name = "";
1896 namlen = 0;
1897 }
1898 else if (varindx < 32)
1899 {
1900 ieee_error (abfd, bytes, atn_start, "illegal variable index");
1901 return false;
1902 }
1903 else
1904 {
1905 varindx -= 32;
1906 zeroindx = false;
1907 if (varindx >= vars->alloc || vars->vars[varindx].name == NULL)
1908 {
1909 ieee_error (abfd, bytes, atn_start, "undefined variable in ATN");
1910 return false;
1911 }
1912
1913 vars->vars[varindx].type = type;
1914
1915 name = vars->vars[varindx].name;
1916 namlen = vars->vars[varindx].namlen;
1917 }
1918
1919 switch (atn_code)
1920 {
1921 default:
1922 ieee_error (abfd, bytes, atn_code_start, "unknown ATN type");
1923 return false;
1924
1925 case 1:
1926 /* Automatic variable. */
1927 if (! ieee_read_number (abfd, bytes, pp, pend, &v))
1928 return false;
1929 namcopy = savestring (name, namlen);
1930 if (type == NULL)
1931 type = debug_make_void_type (dhandle);
1932 return debug_record_variable (dhandle, namcopy, type, DEBUG_LOCAL, v);
1933
1934 case 2:
1935 /* Register variable. */
1936 if (! ieee_read_number (abfd, bytes, pp, pend, &v))
1937 return false;
1938 namcopy = savestring (name, namlen);
1939 if (type == NULL)
1940 type = debug_make_void_type (dhandle);
1941 return debug_record_variable (dhandle, namcopy, type, DEBUG_REGISTER,
1942 ieee_regno_to_gen (abfd, v));
1943
1944 case 3:
1945 /* Static variable. */
1946 if (! ieee_require_asn (abfd, bytes, pp, pend, &v))
1947 return false;
1948 namcopy = savestring (name, namlen);
1949 if (type == NULL)
1950 type = debug_make_void_type (dhandle);
1951 return debug_record_variable (dhandle, namcopy, type,
1952 (blocktype == 4 || blocktype == 6
1953 ? DEBUG_LOCAL_STATIC
1954 : DEBUG_STATIC),
1955 v);
1956
1957 case 4:
1958 /* External function. We don't currently record these. FIXME. */
1959 return true;
1960
1961 case 5:
1962 /* External variable. We don't currently record these. FIXME. */
1963 return true;
1964
1965 case 7:
1966 if (! ieee_read_number (abfd, bytes, pp, pend, &v)
1967 || ! ieee_read_number (abfd, bytes, pp, pend, &v2)
1968 || ! ieee_read_optional_number (abfd, bytes, pp, pend, &v3,
1969 &present))
1970 return false;
1971 if (present)
1972 {
1973 if (! ieee_read_optional_number (abfd, bytes, pp, pend, &v4,
1974 &present))
1975 return false;
1976 }
1977
1978 /* We just ignore the two optional fields in v3 and v4, since
1979 they are not defined. */
1980
1981 if (! ieee_require_asn (abfd, bytes, pp, pend, &v3))
1982 return false;
1983
1984 /* We have no way to record the column number. FIXME. */
1985
1986 return debug_record_line (dhandle, v, v3);
1987
1988 case 8:
1989 /* Global variable. */
1990 if (! ieee_require_asn (abfd, bytes, pp, pend, &v))
1991 return false;
1992 namcopy = savestring (name, namlen);
1993 if (type == NULL)
1994 type = debug_make_void_type (dhandle);
1995 return debug_record_variable (dhandle, namcopy, type, DEBUG_GLOBAL, v);
1996
1997 case 9:
1998 /* Variable lifetime information. */
1999 if (! ieee_read_number (abfd, bytes, pp, pend, &v))
2000 return false;
2001
2002 /* We have no way to record this information. FIXME. */
2003 return true;
2004
2005 case 10:
2006 /* Locked register. */
2007 if (! ieee_read_number (abfd, bytes, pp, pend, &v)
2008 || ! ieee_read_number (abfd, bytes, pp, pend, &v2))
2009 return false;
2010
2011 /* I don't know what this means. FIXME. */
2012
2013 ieee_error (abfd, bytes, atn_code_start, "unsupported ATN10");
2014
2015 /* Return true to keep going. */
2016 return true;
2017
2018 case 11:
2019 /* Reserved for FORTRAN common. */
2020 ieee_error (abfd, bytes, atn_code_start, "unsupported ATN11");
2021
2022 /* Return true to keep going. */
2023 return true;
2024
2025 case 12:
2026 /* Based variable. */
2027 v3 = 0;
2028 v4 = 0x80;
2029 v5 = 0;
2030 if (! ieee_read_number (abfd, bytes, pp, pend, &v)
2031 || ! ieee_read_number (abfd, bytes, pp, pend, &v2)
2032 || ! ieee_read_optional_number (abfd, bytes, pp, pend, &v3,
2033 &present))
2034 return false;
2035 if (present)
2036 {
2037 if (! ieee_read_optional_number (abfd, bytes, pp, pend, &v4,
2038 &present))
2039 return false;
2040 if (present)
2041 {
2042 if (! ieee_read_optional_number (abfd, bytes, pp, pend, &v5,
2043 &present))
2044 return false;
2045 }
2046 }
2047
2048 /* We have no way to record this information. FIXME. */
2049
2050 ieee_error (abfd, bytes, atn_code_start, "unsupported ATN12");
2051
2052 /* Return true to keep going. */
2053 return true;
2054
2055 case 16:
2056 /* Constant. The description of this that I have is ambiguous,
2057 so I'm not going to try to implement it. */
2058 ieee_error (abfd, bytes, atn_code_start, "unsupported ATN16");
2059 return false;
2060
2061 case 19:
2062 /* Static variable from assembler. */
2063 v2 = 0;
2064 if (! ieee_read_number (abfd, bytes, pp, pend, &v)
2065 || ! ieee_read_optional_number (abfd, bytes, pp, pend, &v2,
2066 &present)
2067 || ! ieee_require_asn (abfd, bytes, pp, pend, &v3))
2068 return false;
2069 namcopy = savestring (name, namlen);
2070 /* We don't really handle this correctly. FIXME. */
2071 return debug_record_variable (dhandle, namcopy,
2072 debug_make_void_type (dhandle),
2073 v2 != 0 ? DEBUG_GLOBAL : DEBUG_STATIC,
2074 v3);
2075
2076 case 62:
2077 /* Procedure miscellaneous information. */
2078 case 63:
2079 /* Variable miscellaneous information. */
2080 case 64:
2081 /* Module miscellaneous information. */
2082 if (! ieee_read_number (abfd, bytes, pp, pend, &v)
2083 || ! ieee_read_number (abfd, bytes, pp, pend, &v2)
2084 || ! ieee_read_optional_id (abfd, bytes, pp, pend, &name, &namlen,
2085 &present))
2086 return false;
2087
2088 /* We just ignore all of this stuff. FIXME. */
2089
2090 for (; v2 > 0; --v2)
2091 {
2092 ieee_record_enum_type c;
2093 bfd_vma vindx;
2094 const char *str;
2095 unsigned long strlen;
2096
2097 c = (ieee_record_enum_type) **pp;
2098 ++*pp;
2099 if (c != ieee_at_record_enum
2100 && c != ieee_e2_first_byte_enum)
2101 {
2102 ieee_error (abfd, bytes, *pp - 1, "bad misc record");
2103 return false;
2104 }
2105
2106 c = (ieee_record_enum_type) (((unsigned int) c << 8) | **pp);
2107 ++*pp;
2108 switch (c)
2109 {
2110 default:
2111 ieee_error (abfd, bytes, *pp - 2, "bad misc record");
2112 return false;
2113
2114 case ieee_atn_record_enum:
2115 if (! ieee_read_number (abfd, bytes, pp, pend, &vindx))
2116 return false;
2117 if ((*pp)[0] != 0 || (*pp)[1] != 65)
2118 {
2119 ieee_error (abfd, bytes, *pp, "bad atn in misc");
2120 return false;
2121 }
2122 *pp += 2;
2123 if (! ieee_read_id (abfd, bytes, pp, pend, &str, &strlen))
2124 return false;
2125 break;
2126
2127 case ieee_asn_record_enum:
2128 if (! ieee_read_number (abfd, bytes, pp, pend, &vindx)
2129 || ! ieee_read_expression (abfd, bytes, pp, pend, &v3))
2130 return false;
2131 break;
2132 }
2133 }
2134
2135 return true;
2136 }
2137
2138 /*NOTREACHED*/
2139 }
2140
2141 /* Require an ASN record. */
2142
2143 static boolean
2144 ieee_require_asn (abfd, bytes, pp, pend, pv)
2145 bfd *abfd;
2146 const bfd_byte *bytes;
2147 const bfd_byte **pp;
2148 const bfd_byte *pend;
2149 bfd_vma *pv;
2150 {
2151 const bfd_byte *start;
2152 ieee_record_enum_type c;
2153 bfd_vma varindx;
2154
2155 start = *pp;
2156
2157 c = (ieee_record_enum_type) **pp;
2158 if (c != ieee_e2_first_byte_enum)
2159 {
2160 ieee_error (abfd, bytes, start, "missing required ASN");
2161 return false;
2162 }
2163 ++*pp;
2164
2165 c = (ieee_record_enum_type) (((unsigned int) c << 8) | **pp);
2166 if (c != ieee_asn_record_enum)
2167 {
2168 ieee_error (abfd, bytes, start, "missing required ASN");
2169 return false;
2170 }
2171 ++*pp;
2172
2173 /* Just ignore the variable index. */
2174 if (! ieee_read_number (abfd, bytes, pp, pend, &varindx))
2175 return false;
2176
2177 return ieee_read_expression (abfd, bytes, pp, pend, pv);
2178 }