-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathieee.c
7410 lines (6295 loc) · 187 KB
/
ieee.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* ieee.c -- Read and write IEEE-695 debugging information.
Copyright (C) 1996-2014 Free Software Foundation, Inc.
Written by Ian Lance Taylor <[email protected]>.
This file is part of GNU Binutils.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
02110-1301, USA. */
/* This file reads and writes IEEE-695 debugging information. */
#include "sysdep.h"
#include <assert.h>
#include "bfd.h"
#include "ieee.h"
#include "libiberty.h"
#include "debug.h"
#include "budbg.h"
#include "filenames.h"
/* This structure holds an entry on the block stack. */
struct ieee_block
{
/* The kind of block. */
int kind;
/* The source file name, for a BB5 block. */
const char *filename;
/* The index of the function type, for a BB4 or BB6 block. */
unsigned int fnindx;
/* TRUE if this function is being skipped. */
bfd_boolean skip;
};
/* This structure is the block stack. */
#define BLOCKSTACK_SIZE (16)
struct ieee_blockstack
{
/* The stack pointer. */
struct ieee_block *bsp;
/* The stack. */
struct ieee_block stack[BLOCKSTACK_SIZE];
};
/* This structure holds information for a variable. */
enum ieee_var_kind
{
IEEE_UNKNOWN,
IEEE_EXTERNAL,
IEEE_GLOBAL,
IEEE_STATIC,
IEEE_LOCAL,
IEEE_FUNCTION
};
struct ieee_var
{
/* Start of name. */
const char *name;
/* Length of name. */
unsigned long namlen;
/* Type. */
debug_type type;
/* Slot if we make an indirect type. */
debug_type *pslot;
/* Kind of variable or function. */
enum ieee_var_kind kind;
};
/* This structure holds all the variables. */
struct ieee_vars
{
/* Number of slots allocated. */
unsigned int alloc;
/* Variables. */
struct ieee_var *vars;
};
/* This structure holds information for a type. We need this because
we don't want to represent bitfields as real types. */
struct ieee_type
{
/* Type. */
debug_type type;
/* Slot if this is type is referenced before it is defined. */
debug_type *pslot;
/* Slots for arguments if we make indirect types for them. */
debug_type *arg_slots;
/* If this is a bitfield, this is the size in bits. If this is not
a bitfield, this is zero. */
unsigned long bitsize;
};
/* This structure holds all the type information. */
struct ieee_types
{
/* Number of slots allocated. */
unsigned int alloc;
/* Types. */
struct ieee_type *types;
/* Builtin types. */
#define BUILTIN_TYPE_COUNT (60)
debug_type builtins[BUILTIN_TYPE_COUNT];
};
/* This structure holds a linked last of structs with their tag names,
so that we can convert them to C++ classes if necessary. */
struct ieee_tag
{
/* Next tag. */
struct ieee_tag *next;
/* This tag name. */
const char *name;
/* The type of the tag. */
debug_type type;
/* The tagged type is an indirect type pointing at this slot. */
debug_type slot;
/* This is an array of slots used when a field type is converted
into a indirect type, in case it needs to be later converted into
a reference type. */
debug_type *fslots;
};
/* This structure holds the information we pass around to the parsing
functions. */
struct ieee_info
{
/* The debugging handle. */
void *dhandle;
/* The BFD. */
bfd *abfd;
/* The start of the bytes to be parsed. */
const bfd_byte *bytes;
/* The end of the bytes to be parsed. */
const bfd_byte *pend;
/* The block stack. */
struct ieee_blockstack blockstack;
/* Whether we have seen a BB1 or BB2. */
bfd_boolean saw_filename;
/* The variables. */
struct ieee_vars vars;
/* The global variables, after a global typedef block. */
struct ieee_vars *global_vars;
/* The types. */
struct ieee_types types;
/* The global types, after a global typedef block. */
struct ieee_types *global_types;
/* The list of tagged structs. */
struct ieee_tag *tags;
};
/* Basic builtin types, not including the pointers. */
enum builtin_types
{
builtin_unknown = 0,
builtin_void = 1,
builtin_signed_char = 2,
builtin_unsigned_char = 3,
builtin_signed_short_int = 4,
builtin_unsigned_short_int = 5,
builtin_signed_long = 6,
builtin_unsigned_long = 7,
builtin_signed_long_long = 8,
builtin_unsigned_long_long = 9,
builtin_float = 10,
builtin_double = 11,
builtin_long_double = 12,
builtin_long_long_double = 13,
builtin_quoted_string = 14,
builtin_instruction_address = 15,
builtin_int = 16,
builtin_unsigned = 17,
builtin_unsigned_int = 18,
builtin_char = 19,
builtin_long = 20,
builtin_short = 21,
builtin_unsigned_short = 22,
builtin_short_int = 23,
builtin_signed_short = 24,
builtin_bcd_float = 25
};
/* These are the values found in the derivation flags of a 'b'
component record of a 'T' type extension record in a C++ pmisc
record. These are bitmasks. */
/* Set for a private base class, clear for a public base class.
Protected base classes are not supported. */
#define BASEFLAGS_PRIVATE (0x1)
/* Set for a virtual base class. */
#define BASEFLAGS_VIRTUAL (0x2)
/* Set for a friend class, clear for a base class. */
#define BASEFLAGS_FRIEND (0x10)
/* These are the values found in the specs flags of a 'd', 'm', or 'v'
component record of a 'T' type extension record in a C++ pmisc
record. The same flags are used for a 'M' record in a C++ pmisc
record. */
/* The lower two bits hold visibility information. */
#define CXXFLAGS_VISIBILITY (0x3)
/* This value in the lower two bits indicates a public member. */
#define CXXFLAGS_VISIBILITY_PUBLIC (0x0)
/* This value in the lower two bits indicates a private member. */
#define CXXFLAGS_VISIBILITY_PRIVATE (0x1)
/* This value in the lower two bits indicates a protected member. */
#define CXXFLAGS_VISIBILITY_PROTECTED (0x2)
/* Set for a static member. */
#define CXXFLAGS_STATIC (0x4)
/* Set for a virtual override. */
#define CXXFLAGS_OVERRIDE (0x8)
/* Set for a friend function. */
#define CXXFLAGS_FRIEND (0x10)
/* Set for a const function. */
#define CXXFLAGS_CONST (0x20)
/* Set for a volatile function. */
#define CXXFLAGS_VOLATILE (0x40)
/* Set for an overloaded function. */
#define CXXFLAGS_OVERLOADED (0x80)
/* Set for an operator function. */
#define CXXFLAGS_OPERATOR (0x100)
/* Set for a constructor or destructor. */
#define CXXFLAGS_CTORDTOR (0x400)
/* Set for a constructor. */
#define CXXFLAGS_CTOR (0x200)
/* Set for an inline function. */
#define CXXFLAGS_INLINE (0x800)
/* Local functions. */
static void ieee_error (struct ieee_info *, const bfd_byte *, const char *);
static void ieee_eof (struct ieee_info *);
static char *savestring (const char *, unsigned long);
static bfd_boolean ieee_read_number
(struct ieee_info *, const bfd_byte **, bfd_vma *);
static bfd_boolean ieee_read_optional_number
(struct ieee_info *, const bfd_byte **, bfd_vma *, bfd_boolean *);
static bfd_boolean ieee_read_id
(struct ieee_info *, const bfd_byte **, const char **, unsigned long *);
static bfd_boolean ieee_read_optional_id
(struct ieee_info *, const bfd_byte **, const char **, unsigned long *,
bfd_boolean *);
static bfd_boolean ieee_read_expression
(struct ieee_info *, const bfd_byte **, bfd_vma *);
static debug_type ieee_builtin_type
(struct ieee_info *, const bfd_byte *, unsigned int);
static bfd_boolean ieee_alloc_type
(struct ieee_info *, unsigned int, bfd_boolean);
static bfd_boolean ieee_read_type_index
(struct ieee_info *, const bfd_byte **, debug_type *);
static int ieee_regno_to_genreg (bfd *, int);
static int ieee_genreg_to_regno (bfd *, int);
static bfd_boolean parse_ieee_bb (struct ieee_info *, const bfd_byte **);
static bfd_boolean parse_ieee_be (struct ieee_info *, const bfd_byte **);
static bfd_boolean parse_ieee_nn (struct ieee_info *, const bfd_byte **);
static bfd_boolean parse_ieee_ty (struct ieee_info *, const bfd_byte **);
static bfd_boolean parse_ieee_atn (struct ieee_info *, const bfd_byte **);
static bfd_boolean ieee_read_cxx_misc
(struct ieee_info *, const bfd_byte **, unsigned long);
static bfd_boolean ieee_read_cxx_class
(struct ieee_info *, const bfd_byte **, unsigned long);
static bfd_boolean ieee_read_cxx_defaults
(struct ieee_info *, const bfd_byte **, unsigned long);
static bfd_boolean ieee_read_reference
(struct ieee_info *, const bfd_byte **);
static bfd_boolean ieee_require_asn
(struct ieee_info *, const bfd_byte **, bfd_vma *);
static bfd_boolean ieee_require_atn65
(struct ieee_info *, const bfd_byte **, const char **, unsigned long *);
/* Report an error in the IEEE debugging information. */
static void
ieee_error (struct ieee_info *info, const bfd_byte *p, const char *s)
{
if (p != NULL)
fprintf (stderr, "%s: 0x%lx: %s (0x%x)\n", bfd_get_filename (info->abfd),
(unsigned long) (p - info->bytes), s, *p);
else
fprintf (stderr, "%s: %s\n", bfd_get_filename (info->abfd), s);
}
/* Report an unexpected EOF in the IEEE debugging information. */
static void
ieee_eof (struct ieee_info *info)
{
ieee_error (info, (const bfd_byte *) NULL,
_("unexpected end of debugging information"));
}
/* Save a string in memory. */
static char *
savestring (const char *start, unsigned long len)
{
char *ret;
ret = (char *) xmalloc (len + 1);
memcpy (ret, start, len);
ret[len] = '\0';
return ret;
}
/* Read a number which must be present in an IEEE file. */
static bfd_boolean
ieee_read_number (struct ieee_info *info, const bfd_byte **pp, bfd_vma *pv)
{
return ieee_read_optional_number (info, pp, pv, (bfd_boolean *) NULL);
}
/* Read a number in an IEEE file. If ppresent is not NULL, the number
need not be there. */
static bfd_boolean
ieee_read_optional_number (struct ieee_info *info, const bfd_byte **pp,
bfd_vma *pv, bfd_boolean *ppresent)
{
ieee_record_enum_type b;
if (*pp >= info->pend)
{
if (ppresent != NULL)
{
*ppresent = FALSE;
return TRUE;
}
ieee_eof (info);
return FALSE;
}
b = (ieee_record_enum_type) **pp;
++*pp;
if (b <= ieee_number_end_enum)
{
*pv = (bfd_vma) b;
if (ppresent != NULL)
*ppresent = TRUE;
return TRUE;
}
if (b >= ieee_number_repeat_start_enum && b <= ieee_number_repeat_end_enum)
{
unsigned int i;
i = (int) b - (int) ieee_number_repeat_start_enum;
if (*pp + i - 1 >= info->pend)
{
ieee_eof (info);
return FALSE;
}
*pv = 0;
for (; i > 0; i--)
{
*pv <<= 8;
*pv += **pp;
++*pp;
}
if (ppresent != NULL)
*ppresent = TRUE;
return TRUE;
}
if (ppresent != NULL)
{
--*pp;
*ppresent = FALSE;
return TRUE;
}
ieee_error (info, *pp - 1, _("invalid number"));
return FALSE;
}
/* Read a required string from an IEEE file. */
static bfd_boolean
ieee_read_id (struct ieee_info *info, const bfd_byte **pp,
const char **pname, unsigned long *pnamlen)
{
return ieee_read_optional_id (info, pp, pname, pnamlen, (bfd_boolean *) NULL);
}
/* Read a string from an IEEE file. If ppresent is not NULL, the
string is optional. */
static bfd_boolean
ieee_read_optional_id (struct ieee_info *info, const bfd_byte **pp,
const char **pname, unsigned long *pnamlen,
bfd_boolean *ppresent)
{
bfd_byte b;
unsigned long len;
if (*pp >= info->pend)
{
ieee_eof (info);
return FALSE;
}
b = **pp;
++*pp;
if (b <= 0x7f)
len = b;
else if ((ieee_record_enum_type) b == ieee_extension_length_1_enum)
{
len = **pp;
++*pp;
}
else if ((ieee_record_enum_type) b == ieee_extension_length_2_enum)
{
len = (**pp << 8) + (*pp)[1];
*pp += 2;
}
else
{
if (ppresent != NULL)
{
--*pp;
*ppresent = FALSE;
return TRUE;
}
ieee_error (info, *pp - 1, _("invalid string length"));
return FALSE;
}
if ((unsigned long) (info->pend - *pp) < len)
{
ieee_eof (info);
return FALSE;
}
*pname = (const char *) *pp;
*pnamlen = len;
*pp += len;
if (ppresent != NULL)
*ppresent = TRUE;
return TRUE;
}
/* Read an expression from an IEEE file. Since this code is only used
to parse debugging information, I haven't bothered to write a full
blown IEEE expression parser. I've only thrown in the things I've
seen in debugging information. This can be easily extended if
necessary. */
static bfd_boolean
ieee_read_expression (struct ieee_info *info, const bfd_byte **pp,
bfd_vma *pv)
{
const bfd_byte *expr_start;
#define EXPR_STACK_SIZE (10)
bfd_vma expr_stack[EXPR_STACK_SIZE];
bfd_vma *esp;
expr_start = *pp;
esp = expr_stack;
while (1)
{
const bfd_byte *start;
bfd_vma val;
bfd_boolean present;
ieee_record_enum_type c;
start = *pp;
if (! ieee_read_optional_number (info, pp, &val, &present))
return FALSE;
if (present)
{
if (esp - expr_stack >= EXPR_STACK_SIZE)
{
ieee_error (info, start, _("expression stack overflow"));
return FALSE;
}
*esp++ = val;
continue;
}
c = (ieee_record_enum_type) **pp;
if (c >= ieee_module_beginning_enum)
break;
++*pp;
if (c == ieee_comma)
break;
switch (c)
{
default:
ieee_error (info, start, _("unsupported IEEE expression operator"));
break;
case ieee_variable_R_enum:
{
bfd_vma indx;
asection *s;
if (! ieee_read_number (info, pp, &indx))
return FALSE;
for (s = info->abfd->sections; s != NULL; s = s->next)
if ((bfd_vma) s->target_index == indx)
break;
if (s == NULL)
{
ieee_error (info, start, _("unknown section"));
return FALSE;
}
if (esp - expr_stack >= EXPR_STACK_SIZE)
{
ieee_error (info, start, _("expression stack overflow"));
return FALSE;
}
*esp++ = bfd_get_section_vma (info->abfd, s);
}
break;
case ieee_function_plus_enum:
case ieee_function_minus_enum:
{
bfd_vma v1, v2;
if (esp - expr_stack < 2)
{
ieee_error (info, start, _("expression stack underflow"));
return FALSE;
}
v1 = *--esp;
v2 = *--esp;
*esp++ = v1 + v2;
}
break;
}
}
if (esp - 1 != expr_stack)
{
ieee_error (info, expr_start, _("expression stack mismatch"));
return FALSE;
}
*pv = *--esp;
return TRUE;
}
/* Return an IEEE builtin type. */
static debug_type
ieee_builtin_type (struct ieee_info *info, const bfd_byte *p,
unsigned int indx)
{
void *dhandle;
debug_type type;
const char *name;
if (indx < BUILTIN_TYPE_COUNT
&& info->types.builtins[indx] != DEBUG_TYPE_NULL)
return info->types.builtins[indx];
dhandle = info->dhandle;
if (indx >= 32 && indx < 64)
{
type = debug_make_pointer_type (dhandle,
ieee_builtin_type (info, p, indx - 32));
assert (indx < BUILTIN_TYPE_COUNT);
info->types.builtins[indx] = type;
return type;
}
switch ((enum builtin_types) indx)
{
default:
ieee_error (info, p, _("unknown builtin type"));
return NULL;
case builtin_unknown:
type = debug_make_void_type (dhandle);
name = NULL;
break;
case builtin_void:
type = debug_make_void_type (dhandle);
name = "void";
break;
case builtin_signed_char:
type = debug_make_int_type (dhandle, 1, FALSE);
name = "signed char";
break;
case builtin_unsigned_char:
type = debug_make_int_type (dhandle, 1, TRUE);
name = "unsigned char";
break;
case builtin_signed_short_int:
type = debug_make_int_type (dhandle, 2, FALSE);
name = "signed short int";
break;
case builtin_unsigned_short_int:
type = debug_make_int_type (dhandle, 2, TRUE);
name = "unsigned short int";
break;
case builtin_signed_long:
type = debug_make_int_type (dhandle, 4, FALSE);
name = "signed long";
break;
case builtin_unsigned_long:
type = debug_make_int_type (dhandle, 4, TRUE);
name = "unsigned long";
break;
case builtin_signed_long_long:
type = debug_make_int_type (dhandle, 8, FALSE);
name = "signed long long";
break;
case builtin_unsigned_long_long:
type = debug_make_int_type (dhandle, 8, TRUE);
name = "unsigned long long";
break;
case builtin_float:
type = debug_make_float_type (dhandle, 4);
name = "float";
break;
case builtin_double:
type = debug_make_float_type (dhandle, 8);
name = "double";
break;
case builtin_long_double:
/* FIXME: The size for this type should depend upon the
processor. */
type = debug_make_float_type (dhandle, 12);
name = "long double";
break;
case builtin_long_long_double:
type = debug_make_float_type (dhandle, 16);
name = "long long double";
break;
case builtin_quoted_string:
type = debug_make_array_type (dhandle,
ieee_builtin_type (info, p,
((unsigned int)
builtin_char)),
ieee_builtin_type (info, p,
((unsigned int)
builtin_int)),
0, -1, TRUE);
name = "QUOTED STRING";
break;
case builtin_instruction_address:
/* FIXME: This should be a code address. */
type = debug_make_int_type (dhandle, 4, TRUE);
name = "instruction address";
break;
case builtin_int:
/* FIXME: The size for this type should depend upon the
processor. */
type = debug_make_int_type (dhandle, 4, FALSE);
name = "int";
break;
case builtin_unsigned:
/* FIXME: The size for this type should depend upon the
processor. */
type = debug_make_int_type (dhandle, 4, TRUE);
name = "unsigned";
break;
case builtin_unsigned_int:
/* FIXME: The size for this type should depend upon the
processor. */
type = debug_make_int_type (dhandle, 4, TRUE);
name = "unsigned int";
break;
case builtin_char:
type = debug_make_int_type (dhandle, 1, FALSE);
name = "char";
break;
case builtin_long:
type = debug_make_int_type (dhandle, 4, FALSE);
name = "long";
break;
case builtin_short:
type = debug_make_int_type (dhandle, 2, FALSE);
name = "short";
break;
case builtin_unsigned_short:
type = debug_make_int_type (dhandle, 2, TRUE);
name = "unsigned short";
break;
case builtin_short_int:
type = debug_make_int_type (dhandle, 2, FALSE);
name = "short int";
break;
case builtin_signed_short:
type = debug_make_int_type (dhandle, 2, FALSE);
name = "signed short";
break;
case builtin_bcd_float:
ieee_error (info, p, _("BCD float type not supported"));
return DEBUG_TYPE_NULL;
}
if (name != NULL)
type = debug_name_type (dhandle, name, type);
assert (indx < BUILTIN_TYPE_COUNT);
info->types.builtins[indx] = type;
return type;
}
/* Allocate more space in the type table. If ref is TRUE, this is a
reference to the type; if it is not already defined, we should set
up an indirect type. */
static bfd_boolean
ieee_alloc_type (struct ieee_info *info, unsigned int indx, bfd_boolean ref)
{
unsigned int nalloc;
register struct ieee_type *t;
struct ieee_type *tend;
if (indx >= info->types.alloc)
{
nalloc = info->types.alloc;
if (nalloc == 0)
nalloc = 4;
while (indx >= nalloc)
nalloc *= 2;
info->types.types = ((struct ieee_type *)
xrealloc (info->types.types,
nalloc * sizeof *info->types.types));
memset (info->types.types + info->types.alloc, 0,
(nalloc - info->types.alloc) * sizeof *info->types.types);
tend = info->types.types + nalloc;
for (t = info->types.types + info->types.alloc; t < tend; t++)
t->type = DEBUG_TYPE_NULL;
info->types.alloc = nalloc;
}
if (ref)
{
t = info->types.types + indx;
if (t->type == NULL)
{
t->pslot = (debug_type *) xmalloc (sizeof *t->pslot);
*t->pslot = DEBUG_TYPE_NULL;
t->type = debug_make_indirect_type (info->dhandle, t->pslot,
(const char *) NULL);
if (t->type == NULL)
return FALSE;
}
}
return TRUE;
}
/* Read a type index and return the corresponding type. */
static bfd_boolean
ieee_read_type_index (struct ieee_info *info, const bfd_byte **pp,
debug_type *ptype)
{
const bfd_byte *start;
bfd_vma indx;
start = *pp;
if (! ieee_read_number (info, pp, &indx))
return FALSE;
if (indx < 256)
{
*ptype = ieee_builtin_type (info, start, indx);
if (*ptype == NULL)
return FALSE;
return TRUE;
}
indx -= 256;
if (! ieee_alloc_type (info, indx, TRUE))
return FALSE;
*ptype = info->types.types[indx].type;
return TRUE;
}
/* Parse IEEE debugging information for a file. This is passed the
bytes which compose the Debug Information Part of an IEEE file. */
bfd_boolean
parse_ieee (void *dhandle, bfd *abfd, const bfd_byte *bytes, bfd_size_type len)
{
struct ieee_info info;
unsigned int i;
const bfd_byte *p, *pend;
info.dhandle = dhandle;
info.abfd = abfd;
info.bytes = bytes;
info.pend = bytes + len;
info.blockstack.bsp = info.blockstack.stack;
info.saw_filename = FALSE;
info.vars.alloc = 0;
info.vars.vars = NULL;
info.global_vars = NULL;
info.types.alloc = 0;
info.types.types = NULL;
info.global_types = NULL;
info.tags = NULL;
for (i = 0; i < BUILTIN_TYPE_COUNT; i++)
info.types.builtins[i] = DEBUG_TYPE_NULL;
p = bytes;
pend = info.pend;
while (p < pend)
{
const bfd_byte *record_start;
ieee_record_enum_type c;
record_start = p;
c = (ieee_record_enum_type) *p++;
if (c == ieee_at_record_enum)
c = (ieee_record_enum_type) (((unsigned int) c << 8) | *p++);
if (c <= ieee_number_repeat_end_enum)
{
ieee_error (&info, record_start, _("unexpected number"));
return FALSE;
}
switch (c)
{
default:
ieee_error (&info, record_start, _("unexpected record type"));
return FALSE;
case ieee_bb_record_enum:
if (! parse_ieee_bb (&info, &p))
return FALSE;
break;
case ieee_be_record_enum:
if (! parse_ieee_be (&info, &p))
return FALSE;
break;
case ieee_nn_record:
if (! parse_ieee_nn (&info, &p))
return FALSE;
break;
case ieee_ty_record_enum:
if (! parse_ieee_ty (&info, &p))
return FALSE;
break;
case ieee_atn_record_enum:
if (! parse_ieee_atn (&info, &p))
return FALSE;
break;
}
}
if (info.blockstack.bsp != info.blockstack.stack)
{
ieee_error (&info, (const bfd_byte *) NULL,
_("blocks left on stack at end"));
return FALSE;
}
return TRUE;
}
/* Handle an IEEE BB record. */
static bfd_boolean
parse_ieee_bb (struct ieee_info *info, const bfd_byte **pp)
{
const bfd_byte *block_start;
bfd_byte b;
bfd_vma size;
const char *name;
unsigned long namlen;
char *namcopy = NULL;
unsigned int fnindx;
bfd_boolean skip;
block_start = *pp;
b = **pp;
++*pp;
if (! ieee_read_number (info, pp, &size)
|| ! ieee_read_id (info, pp, &name, &namlen))
return FALSE;
fnindx = (unsigned int) -1;
skip = FALSE;
switch (b)
{
case 1:
/* BB1: Type definitions local to a module. */
namcopy = savestring (name, namlen);
if (namcopy == NULL)
return FALSE;
if (! debug_set_filename (info->dhandle, namcopy))
return FALSE;
info->saw_filename = TRUE;
/* Discard any variables or types we may have seen before. */
if (info->vars.vars != NULL)
free (info->vars.vars);
info->vars.vars = NULL;
info->vars.alloc = 0;
if (info->types.types != NULL)
free (info->types.types);
info->types.types = NULL;
info->types.alloc = 0;
/* Initialize the types to the global types. */
if (info->global_types != NULL)
{
info->types.alloc = info->global_types->alloc;
info->types.types = ((struct ieee_type *)
xmalloc (info->types.alloc
* sizeof (*info->types.types)));
memcpy (info->types.types, info->global_types->types,
info->types.alloc * sizeof (*info->types.types));
}
break;