annotate leo-obj/tool/richsym.c @ 146:70631c246df0

tiobjd ctypes: buglet in the -bb mode
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Tue, 29 Apr 2014 05:18:09 +0000
parents 25d3ead621f8
children 13cc7e19ecec
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
144
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1 /*
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
2 * Code for working with the "rich" symbolic info
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
3 * present in TI's GPF libraries
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
4 */
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
5
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
6 #include <sys/types.h>
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
7 #include <stdio.h>
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
8 #include <stdlib.h>
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
9 #include <string.h>
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
10 #include <strings.h>
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
11 #include "intstruct.h"
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
12 #include "coffconst.h"
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
13 #include "globals.h"
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
14
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
15 extern unsigned get_u16(), get_u32();
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
16 extern char *storage_class_to_string();
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
17
145
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
18 int richsym_print_bitsize;
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
19
144
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
20 static int
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
21 try_typedef_hack(struct_sym)
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
22 struct internal_syment *struct_sym;
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
23 {
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
24 unsigned tpdef_cand;
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
25 struct internal_syment *tpdef_sym;
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
26
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
27 if (!struct_sym->aux)
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
28 return(0);
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
29 tpdef_cand = get_u32(struct_sym->aux + 12);
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
30 if (tpdef_cand >= nsymtab)
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
31 return(0);
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
32 tpdef_sym = symtab[tpdef_cand];
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
33 if (!tpdef_sym)
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
34 return(0);
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
35 if (tpdef_sym->class != C_TPDEF)
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
36 return(0);
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
37 if (tpdef_sym->type != struct_sym->type)
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
38 return(0);
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
39 if (tpdef_sym->name[0] != '_')
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
40 return(0);
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
41 if (!tpdef_sym->aux)
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
42 return(0);
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
43 if (get_u32(tpdef_sym->aux) != struct_sym->number)
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
44 return(0);
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
45 struct_sym->struct_name = tpdef_sym->name + 1;
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
46 return(1);
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
47 }
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
48
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
49 static void
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
50 preen_strtag_sym(sym, kw, expect_type)
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
51 struct internal_syment *sym;
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
52 char *kw;
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
53 {
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
54 char *buf;
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
55 int isund, len;
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
56
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
57 isund = (sym->name[0] == '_');
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
58 len = strlen(kw) + 1 + strlen(sym->name) + 1;
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
59 if (isund)
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
60 len--;
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
61 else
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
62 len += 2;
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
63 buf = malloc(len);
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
64 if (!buf) {
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
65 perror("malloc");
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
66 exit(1);
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
67 }
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
68 if (isund)
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
69 sprintf(buf, "%s %s", kw, sym->name + 1);
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
70 else
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
71 sprintf(buf, "%s \"%s\"", kw, sym->name);
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
72 sym->struct_name = buf;
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
73 sym->struct_name_raw = buf;
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
74 if (sym->type != expect_type) {
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
75 fprintf(stderr,
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
76 "warning: type/class mismatch on tag symbol #%u\n",
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
77 sym->number);
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
78 return;
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
79 }
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
80 if (isund)
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
81 return;
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
82 try_typedef_hack(sym);
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
83 }
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
84
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
85 richsym_initial_preen()
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
86 {
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
87 unsigned n;
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
88 struct internal_syment *sym;
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
89
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
90 for (n = 0; n < nsymtab; n++) {
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
91 sym = symtab[n];
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
92 if (!sym)
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
93 continue;
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
94 switch (sym->class) {
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
95 case C_STRTAG:
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
96 preen_strtag_sym(sym, "struct", T_STRUCT);
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
97 continue;
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
98 case C_UNTAG:
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
99 preen_strtag_sym(sym, "union", T_UNION);
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
100 continue;
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
101 case C_ENTAG:
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
102 preen_strtag_sym(sym, "enum", T_ENUM);
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
103 continue;
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
104 }
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
105 }
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
106 }
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
107
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
108 char *
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
109 get_struct_type_name(idx, expect_class, is_typedef)
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
110 unsigned idx;
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
111 {
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
112 struct internal_syment *sym;
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
113
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
114 if (idx >= nsymtab) {
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
115 inv_idx: fprintf(stderr,
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
116 "error: ref to invalid syment #%u for struct tag\n",
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
117 idx);
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
118 exit(1);
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
119 }
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
120 sym = symtab[idx];
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
121 if (!sym)
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
122 goto inv_idx;
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
123 if (sym->class != expect_class) {
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
124 fprintf(stderr,
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
125 "error: ref to syment #%u for struct tag, class != %s\n",
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
126 idx, storage_class_to_string(expect_class, 0));
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
127 exit(1);
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
128 }
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
129 if (is_typedef)
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
130 return(sym->struct_name_raw);
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
131 else
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
132 return(sym->struct_name);
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
133 }
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
134
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
135 char *
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
136 get_base_type_of_syment(sym, is_typedef)
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
137 struct internal_syment *sym;
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
138 {
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
139 switch (sym->type & 0xF) {
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
140 case T_VOID:
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
141 return("void");
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
142 case T_CHAR:
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
143 if (is_typedef)
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
144 return("signed char");
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
145 else
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
146 return("char");
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
147 case T_SHORT:
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
148 return("short");
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
149 case T_INT:
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
150 return("int");
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
151 case T_LONG:
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
152 return("long");
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
153 case T_FLOAT:
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
154 return("float");
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
155 case T_DOUBLE:
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
156 return("double");
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
157 case T_STRUCT:
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
158 return get_struct_type_name(get_u32(sym->aux), C_STRTAG,
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
159 is_typedef);
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
160 case T_UNION:
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
161 return get_struct_type_name(get_u32(sym->aux), C_UNTAG,
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
162 is_typedef);
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
163 case T_ENUM:
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
164 return get_struct_type_name(get_u32(sym->aux), C_ENTAG,
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
165 is_typedef);
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
166 case T_UCHAR:
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
167 if (is_typedef)
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
168 return("unsigned char");
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
169 else
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
170 return("u_char");
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
171 case T_USHORT:
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
172 if (is_typedef)
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
173 return("unsigned short");
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
174 else
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
175 return("u_short");
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
176 case T_UINT:
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
177 return("unsigned");
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
178 case T_ULONG:
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
179 if (is_typedef)
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
180 return("unsigned long");
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
181 else
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
182 return("u_long");
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
183 default:
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
184 return("__unknown_base_type");
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
185 }
fd772de226cb tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
186 }
145
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
187
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
188 richsym_print_in_c(prefix, sym, is_typedef)
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
189 char *prefix;
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
190 struct internal_syment *sym;
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
191 {
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
192 char *base_type, *s1, *s2;
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
193 int dertype, last_ptr, narray;
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
194
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
195 base_type = get_base_type_of_syment(sym, is_typedef);
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
196 dertype = sym->type >> 4;
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
197 s1 = malloc(strlen(sym->name));
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
198 if (!s1) {
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
199 perror("malloc");
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
200 exit(1);
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
201 }
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
202 strcpy(s1, sym->name + 1);
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
203 last_ptr = 0;
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
204 narray = 0;
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
205 for (; dertype; dertype >>= 2) {
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
206 switch (dertype & 3) {
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
207 case DT_NON:
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
208 fprintf(stderr,
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
209 "error: symbol #%u: DT_NON followed by more derived types\n",
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
210 sym->number);
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
211 exit(1);
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
212 case DT_PTR:
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
213 s2 = malloc(strlen(s1) + 2);
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
214 if (!s2) {
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
215 perror("malloc");
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
216 exit(1);
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
217 }
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
218 sprintf(s2, "*%s", s1);
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
219 free(s1);
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
220 s1 = s2;
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
221 last_ptr = 1;
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
222 continue;
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
223 }
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
224 if (last_ptr) {
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
225 s2 = malloc(strlen(s1) + 3);
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
226 if (!s2) {
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
227 perror("malloc");
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
228 exit(1);
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
229 }
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
230 sprintf(s2, "(%s)", s1);
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
231 free(s1);
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
232 s1 = s2;
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
233 }
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
234 switch (dertype & 3) {
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
235 case DT_FCN:
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
236 s2 = malloc(strlen(s1) + 3);
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
237 if (!s2) {
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
238 perror("malloc");
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
239 exit(1);
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
240 }
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
241 sprintf(s2, "%s()", s1);
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
242 free(s1);
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
243 s1 = s2;
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
244 break;
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
245 case DT_ARY:
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
246 if (narray >= 4) {
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
247 fprintf(stderr,
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
248 "error: symbol #%u: too many [] types\n",
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
249 sym->number);
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
250 exit(1);
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
251 }
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
252 s2 = malloc(strlen(s1) + 8);
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
253 if (!s2) {
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
254 perror("malloc");
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
255 exit(1);
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
256 }
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
257 sprintf(s2, "%s[%u]", s1,
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
258 get_u16(sym->aux + 8 + narray * 2));
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
259 free(s1);
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
260 s1 = s2;
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
261 narray++;
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
262 break;
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
263 default:
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
264 fprintf(stderr,
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
265 "BUG in richsym_print_in_c(): bad derived type\n");
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
266 exit(1);
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
267 }
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
268 last_ptr = 0;
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
269 }
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
270 printf("%s%s %s;", prefix, base_type, s1);
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
271 free(s1);
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
272 if (richsym_print_bitsize)
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
273 printf("\t/* %u bits */", get_u32(sym->aux + 4));
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
274 putchar('\n');
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
275 }
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
276
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
277 cmd_ctypes(argc, argv)
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
278 char **argv;
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
279 {
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
280 int c;
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
281 unsigned n;
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
282 struct internal_syment *sym;
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
283
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
284 while ((c = getopt(argc, argv, "b")) != EOF)
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
285 switch (c) {
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
286 case 'b':
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
287 richsym_print_bitsize++;
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
288 continue;
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
289 default:
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
290 /* error msg already printed */
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
291 exit(1);
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
292 }
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
293
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
294 get_int_section_table();
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
295 get_int_symbol_table();
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
296 richsym_initial_preen();
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
297 for (n = 0; n < nsymtab; n++) {
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
298 sym = symtab[n];
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
299 if (!sym)
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
300 continue;
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
301 switch (sym->class) {
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
302 case C_FILE:
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
303 printf("/* from %s */\n", sym->name);
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
304 continue;
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
305 case C_STRTAG:
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
306 case C_UNTAG:
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
307 case C_ENTAG:
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
308 printf("%s {", sym->struct_name_raw);
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
309 if (richsym_print_bitsize && sym->aux)
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
310 printf("\t/* %u bits */", get_u32(sym->aux+4));
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
311 putchar('\n');
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
312 continue;
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
313 case C_EOS:
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
314 fputs("};", stdout);
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
315 if (richsym_print_bitsize && sym->aux)
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
316 printf("\t/* %u bits */", get_u32(sym->aux+4));
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
317 putchar('\n');
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
318 continue;
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
319 case C_MOS:
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
320 case C_MOU:
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
321 case C_MOE:
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
322 case C_TPDEF:
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
323 break;
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
324 default:
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
325 continue;
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
326 }
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
327 if (sym->name[0] != '_') {
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
328 printf(
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
329 "/* symbol #%u of class %s has no leading underscore */\n",
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
330 sym->number,
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
331 storage_class_to_string(sym->class, 0));
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
332 continue;
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
333 }
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
334 if (!sym->aux && sym->class != C_MOE) {
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
335 printf(
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
336 "/* symbol #%u of class %s has no aux record */\n",
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
337 sym->number,
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
338 storage_class_to_string(sym->class, 0));
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
339 continue;
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
340 }
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
341 switch (sym->class) {
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
342 case C_MOS:
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
343 case C_MOU:
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
344 if (sym->scnum != -1)
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
345 printf("\t/* MOS/MOU section != ABS! */\n");
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
346 else if (richsym_print_bitsize >= 2)
146
70631c246df0 tiobjd ctypes: buglet in the -bb mode
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 145
diff changeset
347 printf("\t/* offset: %u bits */\n", sym->value);
145
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
348 richsym_print_in_c("\t", sym, 0);
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
349 continue;
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
350 case C_MOE:
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
351 if (sym->scnum != -1) {
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
352 printf("\t/* MOE section != ABS! */\n");
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
353 continue;
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
354 }
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
355 printf("\t%s = %u;", sym->name + 1, sym->value);
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
356 if (sym->value >= 10)
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
357 printf("\t/* 0x%x */", sym->value);
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
358 putchar('\n');
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
359 continue;
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
360 case C_TPDEF:
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
361 richsym_print_in_c("typedef ", sym,
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
362 !(sym->type & 0xFFF0));
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
363 continue;
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
364 }
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
365 }
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
366 exit(0);
25d3ead621f8 tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 144
diff changeset
367 }