-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathprdbg.c
2840 lines (2302 loc) · 62 KB
/
prdbg.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
/* prdbg.c -- Print out generic debugging information.
Copyright (C) 1995-2019 Free Software Foundation, Inc.
Written by Ian Lance Taylor <[email protected]>.
Tags style generation written by Salvador E. Tropea <[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 prints out the generic debugging information, by
supplying a set of routines to debug_write. */
#include "sysdep.h"
#include <assert.h>
#include "bfd.h"
#include "libiberty.h"
#include "demangle.h"
#include "debug.h"
#include "budbg.h"
/* This is the structure we use as a handle for these routines. */
struct pr_handle
{
/* File to print information to. */
FILE *f;
/* Current indentation level. */
unsigned int indent;
/* Type stack. */
struct pr_stack *stack;
/* Parameter number we are about to output. */
int parameter;
/* The following are used only by the tags code (tg_). */
/* Name of the file we are using. */
char *filename;
/* The BFD. */
bfd *abfd;
/* The symbols table for this BFD. */
asymbol **syms;
/* Pointer to a function to demangle symbols. */
char *(*demangler) (bfd *, const char *, int);
};
/* The type stack. */
struct pr_stack
{
/* Next element on the stack. */
struct pr_stack *next;
/* This element. */
char *type;
/* Current visibility of fields if this is a class. */
enum debug_visibility visibility;
/* Name of the current method we are handling. */
const char *method;
/* The following are used only by the tags code (tg_). */
/* Type for the container (struct, union, class, union class). */
const char *flavor;
/* A comma separated list of parent classes. */
char *parents;
/* How many parents contains parents. */
int num_parents;
};
static void indent (struct pr_handle *);
static bfd_boolean push_type (struct pr_handle *, const char *);
static bfd_boolean prepend_type (struct pr_handle *, const char *);
static bfd_boolean append_type (struct pr_handle *, const char *);
static bfd_boolean substitute_type (struct pr_handle *, const char *);
static bfd_boolean indent_type (struct pr_handle *);
static char *pop_type (struct pr_handle *);
static void print_vma (bfd_vma, char *, bfd_boolean, bfd_boolean);
static bfd_boolean pr_fix_visibility
(struct pr_handle *, enum debug_visibility);
static bfd_boolean pr_start_compilation_unit (void *, const char *);
static bfd_boolean pr_start_source (void *, const char *);
static bfd_boolean pr_empty_type (void *);
static bfd_boolean pr_void_type (void *);
static bfd_boolean pr_int_type (void *, unsigned int, bfd_boolean);
static bfd_boolean pr_float_type (void *, unsigned int);
static bfd_boolean pr_complex_type (void *, unsigned int);
static bfd_boolean pr_bool_type (void *, unsigned int);
static bfd_boolean pr_enum_type
(void *, const char *, const char **, bfd_signed_vma *);
static bfd_boolean pr_pointer_type (void *);
static bfd_boolean pr_function_type (void *, int, bfd_boolean);
static bfd_boolean pr_reference_type (void *);
static bfd_boolean pr_range_type (void *, bfd_signed_vma, bfd_signed_vma);
static bfd_boolean pr_array_type
(void *, bfd_signed_vma, bfd_signed_vma, bfd_boolean);
static bfd_boolean pr_set_type (void *, bfd_boolean);
static bfd_boolean pr_offset_type (void *);
static bfd_boolean pr_method_type (void *, bfd_boolean, int, bfd_boolean);
static bfd_boolean pr_const_type (void *);
static bfd_boolean pr_volatile_type (void *);
static bfd_boolean pr_start_struct_type
(void *, const char *, unsigned int, bfd_boolean, unsigned int);
static bfd_boolean pr_struct_field
(void *, const char *, bfd_vma, bfd_vma, enum debug_visibility);
static bfd_boolean pr_end_struct_type (void *);
static bfd_boolean pr_start_class_type
(void *, const char *, unsigned int, bfd_boolean, unsigned int,
bfd_boolean, bfd_boolean);
static bfd_boolean pr_class_static_member
(void *, const char *, const char *, enum debug_visibility);
static bfd_boolean pr_class_baseclass
(void *, bfd_vma, bfd_boolean, enum debug_visibility);
static bfd_boolean pr_class_start_method (void *, const char *);
static bfd_boolean pr_class_method_variant
(void *, const char *, enum debug_visibility, bfd_boolean, bfd_boolean,
bfd_vma, bfd_boolean);
static bfd_boolean pr_class_static_method_variant
(void *, const char *, enum debug_visibility, bfd_boolean, bfd_boolean);
static bfd_boolean pr_class_end_method (void *);
static bfd_boolean pr_end_class_type (void *);
static bfd_boolean pr_typedef_type (void *, const char *);
static bfd_boolean pr_tag_type
(void *, const char *, unsigned int, enum debug_type_kind);
static bfd_boolean pr_typdef (void *, const char *);
static bfd_boolean pr_tag (void *, const char *);
static bfd_boolean pr_int_constant (void *, const char *, bfd_vma);
static bfd_boolean pr_float_constant (void *, const char *, double);
static bfd_boolean pr_typed_constant (void *, const char *, bfd_vma);
static bfd_boolean pr_variable
(void *, const char *, enum debug_var_kind, bfd_vma);
static bfd_boolean pr_start_function (void *, const char *, bfd_boolean);
static bfd_boolean pr_function_parameter
(void *, const char *, enum debug_parm_kind, bfd_vma);
static bfd_boolean pr_start_block (void *, bfd_vma);
static bfd_boolean pr_end_block (void *, bfd_vma);
static bfd_boolean pr_end_function (void *);
static bfd_boolean pr_lineno (void *, const char *, unsigned long, bfd_vma);
static bfd_boolean append_parent (struct pr_handle *, const char *);
/* Only used by tg_ code. */
static bfd_boolean tg_fix_visibility
(struct pr_handle *, enum debug_visibility);
static void find_address_in_section (bfd *, asection *, void *);
static void translate_addresses (bfd *, char *, FILE *, asymbol **);
static const char *visibility_name (enum debug_visibility);
/* Tags style replacements. */
static bfd_boolean tg_start_compilation_unit (void *, const char *);
static bfd_boolean tg_start_source (void *, const char *);
static bfd_boolean tg_enum_type
(void *, const char *, const char **, bfd_signed_vma *);
static bfd_boolean tg_start_struct_type
(void *, const char *, unsigned int, bfd_boolean, unsigned int);
static bfd_boolean pr_struct_field
(void *, const char *, bfd_vma, bfd_vma, enum debug_visibility);
static bfd_boolean tg_struct_field
(void *, const char *, bfd_vma, bfd_vma, enum debug_visibility);
static bfd_boolean tg_struct_field
(void *, const char *, bfd_vma, bfd_vma, enum debug_visibility);
static bfd_boolean tg_end_struct_type (void *);
static bfd_boolean tg_start_class_type
(void *, const char *, unsigned int, bfd_boolean, unsigned int, bfd_boolean, bfd_boolean);
static bfd_boolean tg_class_static_member
(void *, const char *, const char *, enum debug_visibility);
static bfd_boolean tg_class_baseclass
(void *, bfd_vma, bfd_boolean, enum debug_visibility);
static bfd_boolean tg_class_method_variant
(void *, const char *, enum debug_visibility, bfd_boolean, bfd_boolean, bfd_vma, bfd_boolean);
static bfd_boolean tg_class_static_method_variant
(void *, const char *, enum debug_visibility, bfd_boolean, bfd_boolean);
static bfd_boolean tg_end_class_type (void *);
static bfd_boolean tg_tag_type
(void *, const char *, unsigned int, enum debug_type_kind);
static bfd_boolean tg_typdef (void *, const char *);
static bfd_boolean tg_tag (void *, const char *);
static bfd_boolean tg_int_constant (void *, const char *, bfd_vma);
static bfd_boolean tg_float_constant (void *, const char *, double);
static bfd_boolean tg_typed_constant (void *, const char *, bfd_vma);
static bfd_boolean tg_variable
(void *, const char *, enum debug_var_kind, bfd_vma);
static bfd_boolean tg_start_function (void *, const char *, bfd_boolean);
static bfd_boolean tg_function_parameter
(void *, const char *, enum debug_parm_kind, bfd_vma);
static bfd_boolean tg_start_block (void *, bfd_vma);
static bfd_boolean tg_end_block (void *, bfd_vma);
static bfd_boolean tg_lineno (void *, const char *, unsigned long, bfd_vma);
static const struct debug_write_fns pr_fns =
{
pr_start_compilation_unit,
pr_start_source,
pr_empty_type,
pr_void_type,
pr_int_type,
pr_float_type,
pr_complex_type,
pr_bool_type,
pr_enum_type,
pr_pointer_type,
pr_function_type,
pr_reference_type,
pr_range_type,
pr_array_type,
pr_set_type,
pr_offset_type,
pr_method_type,
pr_const_type,
pr_volatile_type,
pr_start_struct_type,
pr_struct_field,
pr_end_struct_type,
pr_start_class_type,
pr_class_static_member,
pr_class_baseclass,
pr_class_start_method,
pr_class_method_variant,
pr_class_static_method_variant,
pr_class_end_method,
pr_end_class_type,
pr_typedef_type,
pr_tag_type,
pr_typdef,
pr_tag,
pr_int_constant,
pr_float_constant,
pr_typed_constant,
pr_variable,
pr_start_function,
pr_function_parameter,
pr_start_block,
pr_end_block,
pr_end_function,
pr_lineno
};
static const struct debug_write_fns tg_fns =
{
tg_start_compilation_unit,
tg_start_source,
pr_empty_type, /* Same, push_type. */
pr_void_type, /* Same, push_type. */
pr_int_type, /* Same, push_type. */
pr_float_type, /* Same, push_type. */
pr_complex_type, /* Same, push_type. */
pr_bool_type, /* Same, push_type. */
tg_enum_type,
pr_pointer_type, /* Same, changes to pointer. */
pr_function_type, /* Same, push_type. */
pr_reference_type, /* Same, changes to reference. */
pr_range_type, /* FIXME: What's that?. */
pr_array_type, /* Same, push_type. */
pr_set_type, /* FIXME: What's that?. */
pr_offset_type, /* FIXME: What's that?. */
pr_method_type, /* Same. */
pr_const_type, /* Same, changes to const. */
pr_volatile_type, /* Same, changes to volatile. */
tg_start_struct_type,
tg_struct_field,
tg_end_struct_type,
tg_start_class_type,
tg_class_static_member,
tg_class_baseclass,
pr_class_start_method, /* Same, remembers that's a method. */
tg_class_method_variant,
tg_class_static_method_variant,
pr_class_end_method, /* Same, forgets that's a method. */
tg_end_class_type,
pr_typedef_type, /* Same, just push type. */
tg_tag_type,
tg_typdef,
tg_tag,
tg_int_constant, /* Untested. */
tg_float_constant, /* Untested. */
tg_typed_constant, /* Untested. */
tg_variable,
tg_start_function,
tg_function_parameter,
tg_start_block,
tg_end_block,
pr_end_function, /* Same, does nothing. */
tg_lineno
};
static int demangle_flags = DMGL_ANSI | DMGL_PARAMS;
/* Print out the generic debugging information recorded in dhandle. */
bfd_boolean
print_debugging_info (FILE *f, void *dhandle, bfd *abfd, asymbol **syms,
char * (*demangler) (struct bfd *, const char *, int),
bfd_boolean as_tags)
{
struct pr_handle info;
info.f = f;
info.indent = 0;
info.stack = NULL;
info.parameter = 0;
info.filename = NULL;
info.abfd = abfd;
info.syms = syms;
info.demangler = demangler;
if (as_tags)
{
fputs ("!_TAG_FILE_FORMAT\t2\t/extended format/\n", f);
fputs ("!_TAG_FILE_SORTED\t0\t/0=unsorted, 1=sorted/\n", f);
fputs ("!_TAG_PROGRAM_AUTHOR\tIan Lance Taylor, Salvador E. Tropea and others\t//\n", f);
fputs ("!_TAG_PROGRAM_NAME\tobjdump\t/From GNU binutils/\n", f);
}
return as_tags ? debug_write (dhandle, &tg_fns, (void *) & info)
: debug_write (dhandle, &pr_fns, (void *) & info);
}
/* Indent to the current indentation level. */
static void
indent (struct pr_handle *info)
{
unsigned int i;
for (i = 0; i < info->indent; i++)
putc (' ', info->f);
}
/* Push a type on the type stack. */
static bfd_boolean
push_type (struct pr_handle *info, const char *type)
{
struct pr_stack *n;
if (type == NULL)
return FALSE;
n = (struct pr_stack *) xmalloc (sizeof *n);
memset (n, 0, sizeof *n);
n->type = xstrdup (type);
n->visibility = DEBUG_VISIBILITY_IGNORE;
n->method = NULL;
n->next = info->stack;
info->stack = n;
return TRUE;
}
/* Prepend a string onto the type on the top of the type stack. */
static bfd_boolean
prepend_type (struct pr_handle *info, const char *s)
{
char *n;
assert (info->stack != NULL);
n = (char *) xmalloc (strlen (s) + strlen (info->stack->type) + 1);
sprintf (n, "%s%s", s, info->stack->type);
free (info->stack->type);
info->stack->type = n;
return TRUE;
}
/* Append a string to the type on the top of the type stack. */
static bfd_boolean
append_type (struct pr_handle *info, const char *s)
{
unsigned int len;
if (s == NULL)
return FALSE;
assert (info->stack != NULL);
len = strlen (info->stack->type);
info->stack->type = (char *) xrealloc (info->stack->type,
len + strlen (s) + 1);
strcpy (info->stack->type + len, s);
return TRUE;
}
/* Append a string to the parents on the top of the type stack. */
static bfd_boolean
append_parent (struct pr_handle *info, const char *s)
{
unsigned int len;
if (s == NULL)
return FALSE;
assert (info->stack != NULL);
len = info->stack->parents ? strlen (info->stack->parents) : 0;
info->stack->parents = (char *) xrealloc (info->stack->parents,
len + strlen (s) + 1);
strcpy (info->stack->parents + len, s);
return TRUE;
}
/* We use an underscore to indicate where the name should go in a type
string. This function substitutes a string for the underscore. If
there is no underscore, the name follows the type. */
static bfd_boolean
substitute_type (struct pr_handle *info, const char *s)
{
char *u;
assert (info->stack != NULL);
u = strchr (info->stack->type, '|');
if (u != NULL)
{
char *n;
n = (char *) xmalloc (strlen (info->stack->type) + strlen (s));
memcpy (n, info->stack->type, u - info->stack->type);
strcpy (n + (u - info->stack->type), s);
strcat (n, u + 1);
free (info->stack->type);
info->stack->type = n;
return TRUE;
}
if (strchr (s, '|') != NULL
&& (strchr (info->stack->type, '{') != NULL
|| strchr (info->stack->type, '(') != NULL))
{
if (! prepend_type (info, "(")
|| ! append_type (info, ")"))
return FALSE;
}
if (*s == '\0')
return TRUE;
return (append_type (info, " ")
&& append_type (info, s));
}
/* Indent the type at the top of the stack by appending spaces. */
static bfd_boolean
indent_type (struct pr_handle *info)
{
unsigned int i;
for (i = 0; i < info->indent; i++)
{
if (! append_type (info, " "))
return FALSE;
}
return TRUE;
}
/* Pop a type from the type stack. */
static char *
pop_type (struct pr_handle *info)
{
struct pr_stack *o;
char *ret;
assert (info->stack != NULL);
o = info->stack;
info->stack = o->next;
ret = o->type;
free (o);
return ret;
}
/* Print a VMA value into a string. */
static void
print_vma (bfd_vma vma, char *buf, bfd_boolean unsignedp, bfd_boolean hexp)
{
if (sizeof (vma) <= sizeof (unsigned long))
{
if (hexp)
sprintf (buf, "0x%lx", (unsigned long) vma);
else if (unsignedp)
sprintf (buf, "%lu", (unsigned long) vma);
else
sprintf (buf, "%ld", (long) vma);
}
#if BFD_HOST_64BIT_LONG_LONG
else if (sizeof (vma) <= sizeof (unsigned long long))
{
#ifndef __MSVCRT__
if (hexp)
sprintf (buf, "0x%llx", (unsigned long long) vma);
else if (unsignedp)
sprintf (buf, "%llu", (unsigned long long) vma);
else
sprintf (buf, "%lld", (long long) vma);
#else
if (hexp)
sprintf (buf, "0x%I64x", (unsigned long long) vma);
else if (unsignedp)
sprintf (buf, "%I64u", (unsigned long long) vma);
else
sprintf (buf, "%I64d", (long long) vma);
#endif
}
#endif
else
{
buf[0] = '0';
buf[1] = 'x';
sprintf_vma (buf + 2, vma);
}
}
/* Start a new compilation unit. */
static bfd_boolean
pr_start_compilation_unit (void *p, const char *filename)
{
struct pr_handle *info = (struct pr_handle *) p;
assert (info->indent == 0);
fprintf (info->f, "%s:\n", filename);
return TRUE;
}
/* Start a source file within a compilation unit. */
static bfd_boolean
pr_start_source (void *p, const char *filename)
{
struct pr_handle *info = (struct pr_handle *) p;
assert (info->indent == 0);
fprintf (info->f, " %s:\n", filename);
return TRUE;
}
/* Push an empty type onto the type stack. */
static bfd_boolean
pr_empty_type (void *p)
{
struct pr_handle *info = (struct pr_handle *) p;
return push_type (info, "<undefined>");
}
/* Push a void type onto the type stack. */
static bfd_boolean
pr_void_type (void *p)
{
struct pr_handle *info = (struct pr_handle *) p;
return push_type (info, "void");
}
/* Push an integer type onto the type stack. */
static bfd_boolean
pr_int_type (void *p, unsigned int size, bfd_boolean unsignedp)
{
struct pr_handle *info = (struct pr_handle *) p;
char ab[40];
sprintf (ab, "%sint%d", unsignedp ? "u" : "", size * 8);
return push_type (info, ab);
}
/* Push a floating type onto the type stack. */
static bfd_boolean
pr_float_type (void *p, unsigned int size)
{
struct pr_handle *info = (struct pr_handle *) p;
char ab[40];
if (size == 4)
return push_type (info, "float");
else if (size == 8)
return push_type (info, "double");
sprintf (ab, "float%d", size * 8);
return push_type (info, ab);
}
/* Push a complex type onto the type stack. */
static bfd_boolean
pr_complex_type (void *p, unsigned int size)
{
struct pr_handle *info = (struct pr_handle *) p;
if (! pr_float_type (p, size))
return FALSE;
return prepend_type (info, "complex ");
}
/* Push a bfd_boolean type onto the type stack. */
static bfd_boolean
pr_bool_type (void *p, unsigned int size)
{
struct pr_handle *info = (struct pr_handle *) p;
char ab[40];
sprintf (ab, "bool%d", size * 8);
return push_type (info, ab);
}
/* Push an enum type onto the type stack. */
static bfd_boolean
pr_enum_type (void *p, const char *tag, const char **names,
bfd_signed_vma *values)
{
struct pr_handle *info = (struct pr_handle *) p;
unsigned int i;
bfd_signed_vma val;
if (! push_type (info, "enum "))
return FALSE;
if (tag != NULL)
{
if (! append_type (info, tag)
|| ! append_type (info, " "))
return FALSE;
}
if (! append_type (info, "{ "))
return FALSE;
if (names == NULL)
{
if (! append_type (info, "/* undefined */"))
return FALSE;
}
else
{
val = 0;
for (i = 0; names[i] != NULL; i++)
{
if (i > 0)
{
if (! append_type (info, ", "))
return FALSE;
}
if (! append_type (info, names[i]))
return FALSE;
if (values[i] != val)
{
char ab[22];
print_vma (values[i], ab, FALSE, FALSE);
if (! append_type (info, " = ")
|| ! append_type (info, ab))
return FALSE;
val = values[i];
}
++val;
}
}
return append_type (info, " }");
}
/* Turn the top type on the stack into a pointer. */
static bfd_boolean
pr_pointer_type (void *p)
{
struct pr_handle *info = (struct pr_handle *) p;
char *s;
assert (info->stack != NULL);
s = strchr (info->stack->type, '|');
if (s != NULL && s[1] == '[')
return substitute_type (info, "(*|)");
return substitute_type (info, "*|");
}
/* Turn the top type on the stack into a function returning that type. */
static bfd_boolean
pr_function_type (void *p, int argcount, bfd_boolean varargs)
{
struct pr_handle *info = (struct pr_handle *) p;
char **arg_types;
unsigned int len;
char *s;
assert (info->stack != NULL);
len = 10;
if (argcount <= 0)
{
arg_types = NULL;
len += 15;
}
else
{
int i;
arg_types = (char **) xmalloc (argcount * sizeof *arg_types);
for (i = argcount - 1; i >= 0; i--)
{
if (! substitute_type (info, ""))
{
free (arg_types);
return FALSE;
}
arg_types[i] = pop_type (info);
if (arg_types[i] == NULL)
{
free (arg_types);
return FALSE;
}
len += strlen (arg_types[i]) + 2;
}
if (varargs)
len += 5;
}
/* Now the return type is on the top of the stack. */
s = (char *) xmalloc (len);
LITSTRCPY (s, "(|) (");
if (argcount < 0)
strcat (s, "/* unknown */");
else
{
int i;
for (i = 0; i < argcount; i++)
{
if (i > 0)
strcat (s, ", ");
strcat (s, arg_types[i]);
}
if (varargs)
{
if (i > 0)
strcat (s, ", ");
strcat (s, "...");
}
if (argcount > 0)
free (arg_types);
}
strcat (s, ")");
if (! substitute_type (info, s))
return FALSE;
free (s);
return TRUE;
}
/* Turn the top type on the stack into a reference to that type. */
static bfd_boolean
pr_reference_type (void *p)
{
struct pr_handle *info = (struct pr_handle *) p;
assert (info->stack != NULL);
return substitute_type (info, "&|");
}
/* Make a range type. */
static bfd_boolean
pr_range_type (void *p, bfd_signed_vma lower, bfd_signed_vma upper)
{
struct pr_handle *info = (struct pr_handle *) p;
char abl[22], abu[22];
assert (info->stack != NULL);
if (! substitute_type (info, ""))
return FALSE;
print_vma (lower, abl, FALSE, FALSE);
print_vma (upper, abu, FALSE, FALSE);
return (prepend_type (info, "range (")
&& append_type (info, "):")
&& append_type (info, abl)
&& append_type (info, ":")
&& append_type (info, abu));
}
/* Make an array type. */
static bfd_boolean
pr_array_type (void *p, bfd_signed_vma lower, bfd_signed_vma upper,
bfd_boolean stringp)
{
struct pr_handle *info = (struct pr_handle *) p;
char *range_type;
char abl[22], abu[22], ab[50];
range_type = pop_type (info);
if (range_type == NULL)
return FALSE;
if (lower == 0)
{
if (upper == -1)
sprintf (ab, "|[]");
else
{
print_vma (upper + 1, abu, FALSE, FALSE);
sprintf (ab, "|[%s]", abu);
}
}
else
{
print_vma (lower, abl, FALSE, FALSE);
print_vma (upper, abu, FALSE, FALSE);
sprintf (ab, "|[%s:%s]", abl, abu);
}
if (! substitute_type (info, ab))
return FALSE;
if (strcmp (range_type, "int") != 0)
{
if (! append_type (info, ":")
|| ! append_type (info, range_type))
return FALSE;
}
if (stringp)
{
if (! append_type (info, " /* string */"))
return FALSE;
}
return TRUE;
}
/* Make a set type. */
static bfd_boolean
pr_set_type (void *p, bfd_boolean bitstringp)
{
struct pr_handle *info = (struct pr_handle *) p;
if (! substitute_type (info, ""))
return FALSE;
if (! prepend_type (info, "set { ")
|| ! append_type (info, " }"))
return FALSE;
if (bitstringp)
{
if (! append_type (info, "/* bitstring */"))
return FALSE;
}
return TRUE;
}
/* Make an offset type. */
static bfd_boolean
pr_offset_type (void *p)
{
struct pr_handle *info = (struct pr_handle *) p;
char *t;
if (! substitute_type (info, ""))
return FALSE;
t = pop_type (info);
if (t == NULL)
return FALSE;
return (substitute_type (info, "")
&& prepend_type (info, " ")
&& prepend_type (info, t)
&& append_type (info, "::|"));
}
/* Make a method type. */
static bfd_boolean
pr_method_type (void *p, bfd_boolean domain, int argcount, bfd_boolean varargs)
{
struct pr_handle *info = (struct pr_handle *) p;
unsigned int len;
char *domain_type;
char **arg_types;
char *s;
len = 10;
if (! domain)
domain_type = NULL;
else
{
if (! substitute_type (info, ""))
return FALSE;
domain_type = pop_type (info);
if (domain_type == NULL)
return FALSE;
if (CONST_STRNEQ (domain_type, "class ")
&& strchr (domain_type + sizeof "class " - 1, ' ') == NULL)
domain_type += sizeof "class " - 1;
else if (CONST_STRNEQ (domain_type, "union class ")
&& (strchr (domain_type + sizeof "union class " - 1, ' ')
== NULL))
domain_type += sizeof "union class " - 1;
len += strlen (domain_type);
}
if (argcount <= 0)
{
arg_types = NULL;
len += 15;
}
else
{
int i;
arg_types = (char **) xmalloc (argcount * sizeof *arg_types);
for (i = argcount - 1; i >= 0; i--)
{
if (! substitute_type (info, ""))
{
free (arg_types);
return FALSE;
}
arg_types[i] = pop_type (info);
if (arg_types[i] == NULL)
{
free (arg_types);
return FALSE;
}
len += strlen (arg_types[i]) + 2;
}
if (varargs)
len += 5;
}
/* Now the return type is on the top of the stack. */
s = (char *) xmalloc (len);
if (! domain)
*s = '\0';
else
strcpy (s, domain_type);
strcat (s, "::| (");
if (argcount < 0)
strcat (s, "/* unknown */");
else
{
int i;
for (i = 0; i < argcount; i++)
{
if (i > 0)
strcat (s, ", ");
strcat (s, arg_types[i]);
}
if (varargs)