FreeCalypso > hg > freecalypso-reveng
annotate leo-obj/tool/richsym.c @ 150:df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Tue, 29 Apr 2014 07:51:28 +0000 |
parents | fdf3137c703a |
children | 6fe08feee018 |
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 { |
149
fdf3137c703a
tiobjd richsym handling: prep for handling function locals
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
148
diff
changeset
|
139 unsigned idx; |
fdf3137c703a
tiobjd richsym handling: prep for handling function locals
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
148
diff
changeset
|
140 |
144
fd772de226cb
tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
141 switch (sym->type & 0xF) { |
fd772de226cb
tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
142 case T_VOID: |
fd772de226cb
tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
143 return("void"); |
fd772de226cb
tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
144 case T_CHAR: |
fd772de226cb
tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
145 if (is_typedef) |
fd772de226cb
tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
146 return("signed char"); |
fd772de226cb
tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
147 else |
fd772de226cb
tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
148 return("char"); |
fd772de226cb
tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
149 case T_SHORT: |
fd772de226cb
tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
150 return("short"); |
fd772de226cb
tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
151 case T_INT: |
fd772de226cb
tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
152 return("int"); |
fd772de226cb
tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
153 case T_LONG: |
fd772de226cb
tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
154 return("long"); |
fd772de226cb
tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
155 case T_FLOAT: |
fd772de226cb
tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
156 return("float"); |
fd772de226cb
tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
157 case T_DOUBLE: |
fd772de226cb
tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
158 return("double"); |
fd772de226cb
tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
159 case T_STRUCT: |
149
fdf3137c703a
tiobjd richsym handling: prep for handling function locals
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
148
diff
changeset
|
160 idx = get_u32(sym->aux); |
fdf3137c703a
tiobjd richsym handling: prep for handling function locals
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
148
diff
changeset
|
161 if (idx) |
fdf3137c703a
tiobjd richsym handling: prep for handling function locals
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
148
diff
changeset
|
162 return get_struct_type_name(idx, C_STRTAG, is_typedef); |
fdf3137c703a
tiobjd richsym handling: prep for handling function locals
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
148
diff
changeset
|
163 else |
fdf3137c703a
tiobjd richsym handling: prep for handling function locals
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
148
diff
changeset
|
164 return("struct ?"); |
144
fd772de226cb
tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
165 case T_UNION: |
149
fdf3137c703a
tiobjd richsym handling: prep for handling function locals
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
148
diff
changeset
|
166 idx = get_u32(sym->aux); |
fdf3137c703a
tiobjd richsym handling: prep for handling function locals
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
148
diff
changeset
|
167 if (idx) |
fdf3137c703a
tiobjd richsym handling: prep for handling function locals
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
148
diff
changeset
|
168 return get_struct_type_name(idx, C_UNTAG, is_typedef); |
fdf3137c703a
tiobjd richsym handling: prep for handling function locals
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
148
diff
changeset
|
169 else |
fdf3137c703a
tiobjd richsym handling: prep for handling function locals
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
148
diff
changeset
|
170 return("union ?"); |
144
fd772de226cb
tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
171 case T_ENUM: |
149
fdf3137c703a
tiobjd richsym handling: prep for handling function locals
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
148
diff
changeset
|
172 idx = get_u32(sym->aux); |
fdf3137c703a
tiobjd richsym handling: prep for handling function locals
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
148
diff
changeset
|
173 if (idx) |
fdf3137c703a
tiobjd richsym handling: prep for handling function locals
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
148
diff
changeset
|
174 return get_struct_type_name(idx, C_ENTAG, is_typedef); |
fdf3137c703a
tiobjd richsym handling: prep for handling function locals
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
148
diff
changeset
|
175 else |
fdf3137c703a
tiobjd richsym handling: prep for handling function locals
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
148
diff
changeset
|
176 return("enum ?"); |
144
fd772de226cb
tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
177 case T_UCHAR: |
fd772de226cb
tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
178 if (is_typedef) |
fd772de226cb
tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
179 return("unsigned char"); |
fd772de226cb
tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
180 else |
fd772de226cb
tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
181 return("u_char"); |
fd772de226cb
tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
182 case T_USHORT: |
fd772de226cb
tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
183 if (is_typedef) |
fd772de226cb
tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
184 return("unsigned short"); |
fd772de226cb
tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
185 else |
fd772de226cb
tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
186 return("u_short"); |
fd772de226cb
tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
187 case T_UINT: |
fd772de226cb
tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
188 return("unsigned"); |
fd772de226cb
tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
189 case T_ULONG: |
fd772de226cb
tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
190 if (is_typedef) |
fd772de226cb
tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
191 return("unsigned long"); |
fd772de226cb
tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
192 else |
fd772de226cb
tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
193 return("u_long"); |
fd772de226cb
tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
194 default: |
fd772de226cb
tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
195 return("__unknown_base_type"); |
fd772de226cb
tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
196 } |
fd772de226cb
tiobjd: started implementing rich symbolic info parsing
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
197 } |
145
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
198 |
149
fdf3137c703a
tiobjd richsym handling: prep for handling function locals
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
148
diff
changeset
|
199 static char * |
fdf3137c703a
tiobjd richsym handling: prep for handling function locals
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
148
diff
changeset
|
200 cdecl_obj_name(sym) |
fdf3137c703a
tiobjd richsym handling: prep for handling function locals
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
148
diff
changeset
|
201 struct internal_syment *sym; |
fdf3137c703a
tiobjd richsym handling: prep for handling function locals
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
148
diff
changeset
|
202 { |
fdf3137c703a
tiobjd richsym handling: prep for handling function locals
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
148
diff
changeset
|
203 char *buf; |
fdf3137c703a
tiobjd richsym handling: prep for handling function locals
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
148
diff
changeset
|
204 int isund, len; |
fdf3137c703a
tiobjd richsym handling: prep for handling function locals
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
148
diff
changeset
|
205 |
150
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
206 switch (sym->name[0]) { |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
207 case '_': |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
208 isund = 1; |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
209 break; |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
210 case '$': |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
211 if ((sym->type & 0x30) == 0x20) |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
212 isund = 1; |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
213 else |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
214 isund = 0; |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
215 break; |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
216 default: |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
217 isund = 0; |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
218 } |
149
fdf3137c703a
tiobjd richsym handling: prep for handling function locals
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
148
diff
changeset
|
219 len = strlen(sym->name) + 1; |
fdf3137c703a
tiobjd richsym handling: prep for handling function locals
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
148
diff
changeset
|
220 if (isund) |
fdf3137c703a
tiobjd richsym handling: prep for handling function locals
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
148
diff
changeset
|
221 len--; |
fdf3137c703a
tiobjd richsym handling: prep for handling function locals
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
148
diff
changeset
|
222 else |
fdf3137c703a
tiobjd richsym handling: prep for handling function locals
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
148
diff
changeset
|
223 len += 2; |
fdf3137c703a
tiobjd richsym handling: prep for handling function locals
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
148
diff
changeset
|
224 buf = malloc(len); |
fdf3137c703a
tiobjd richsym handling: prep for handling function locals
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
148
diff
changeset
|
225 if (!buf) { |
fdf3137c703a
tiobjd richsym handling: prep for handling function locals
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
148
diff
changeset
|
226 perror("malloc"); |
fdf3137c703a
tiobjd richsym handling: prep for handling function locals
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
148
diff
changeset
|
227 exit(1); |
fdf3137c703a
tiobjd richsym handling: prep for handling function locals
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
148
diff
changeset
|
228 } |
fdf3137c703a
tiobjd richsym handling: prep for handling function locals
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
148
diff
changeset
|
229 if (isund) |
fdf3137c703a
tiobjd richsym handling: prep for handling function locals
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
148
diff
changeset
|
230 strcpy(buf, sym->name + 1); |
fdf3137c703a
tiobjd richsym handling: prep for handling function locals
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
148
diff
changeset
|
231 else |
fdf3137c703a
tiobjd richsym handling: prep for handling function locals
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
148
diff
changeset
|
232 sprintf(buf, "\"%s\"", sym->name); |
fdf3137c703a
tiobjd richsym handling: prep for handling function locals
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
148
diff
changeset
|
233 return(buf); |
fdf3137c703a
tiobjd richsym handling: prep for handling function locals
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
148
diff
changeset
|
234 } |
fdf3137c703a
tiobjd richsym handling: prep for handling function locals
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
148
diff
changeset
|
235 |
145
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
236 richsym_print_in_c(prefix, sym, is_typedef) |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
237 char *prefix; |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
238 struct internal_syment *sym; |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
239 { |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
240 char *base_type, *s1, *s2; |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
241 int dertype, last_ptr, narray; |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
242 |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
243 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
|
244 dertype = sym->type >> 4; |
149
fdf3137c703a
tiobjd richsym handling: prep for handling function locals
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
148
diff
changeset
|
245 s1 = cdecl_obj_name(sym); |
145
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
246 last_ptr = 0; |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
247 narray = 0; |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
248 for (; dertype; dertype >>= 2) { |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
249 switch (dertype & 3) { |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
250 case DT_NON: |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
251 fprintf(stderr, |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
252 "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
|
253 sym->number); |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
254 exit(1); |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
255 case DT_PTR: |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
256 s2 = malloc(strlen(s1) + 2); |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
257 if (!s2) { |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
258 perror("malloc"); |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
259 exit(1); |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
260 } |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
261 sprintf(s2, "*%s", s1); |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
262 free(s1); |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
263 s1 = s2; |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
264 last_ptr = 1; |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
265 continue; |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
266 } |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
267 if (last_ptr) { |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
268 s2 = malloc(strlen(s1) + 3); |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
269 if (!s2) { |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
270 perror("malloc"); |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
271 exit(1); |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
272 } |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
273 sprintf(s2, "(%s)", s1); |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
274 free(s1); |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
275 s1 = s2; |
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 switch (dertype & 3) { |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
278 case DT_FCN: |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
279 s2 = malloc(strlen(s1) + 3); |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
280 if (!s2) { |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
281 perror("malloc"); |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
282 exit(1); |
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 sprintf(s2, "%s()", s1); |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
285 free(s1); |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
286 s1 = s2; |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
287 break; |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
288 case DT_ARY: |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
289 if (narray >= 4) { |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
290 fprintf(stderr, |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
291 "error: symbol #%u: too many [] types\n", |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
292 sym->number); |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
293 exit(1); |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
294 } |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
295 s2 = malloc(strlen(s1) + 8); |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
296 if (!s2) { |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
297 perror("malloc"); |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
298 exit(1); |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
299 } |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
300 sprintf(s2, "%s[%u]", s1, |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
301 get_u16(sym->aux + 8 + narray * 2)); |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
302 free(s1); |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
303 s1 = s2; |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
304 narray++; |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
305 break; |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
306 default: |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
307 fprintf(stderr, |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
308 "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
|
309 exit(1); |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
310 } |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
311 last_ptr = 0; |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
312 } |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
313 printf("%s%s %s;", prefix, base_type, s1); |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
314 free(s1); |
148
13cc7e19ecec
tiobjd disasm -g: support -b as well
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
146
diff
changeset
|
315 if (richsym_print_bitsize && (sym->type & 0x30) != 0x20) |
145
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 } |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
319 |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
320 cmd_ctypes(argc, argv) |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
321 char **argv; |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
322 { |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
323 int c; |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
324 unsigned n; |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
325 struct internal_syment *sym; |
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 while ((c = getopt(argc, argv, "b")) != EOF) |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
328 switch (c) { |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
329 case 'b': |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
330 richsym_print_bitsize++; |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
331 continue; |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
332 default: |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
333 /* error msg already printed */ |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
334 exit(1); |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
335 } |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
336 |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
337 get_int_section_table(); |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
338 get_int_symbol_table(); |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
339 richsym_initial_preen(); |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
340 for (n = 0; n < nsymtab; n++) { |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
341 sym = symtab[n]; |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
342 if (!sym) |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
343 continue; |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
344 switch (sym->class) { |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
345 case C_FILE: |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
346 printf("/* from %s */\n", sym->name); |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
347 continue; |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
348 case C_STRTAG: |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
349 case C_UNTAG: |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
350 case C_ENTAG: |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
351 printf("%s {", sym->struct_name_raw); |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
352 if (richsym_print_bitsize && sym->aux) |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
353 printf("\t/* %u bits */", get_u32(sym->aux+4)); |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
354 putchar('\n'); |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
355 continue; |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
356 case C_EOS: |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
357 fputs("};", stdout); |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
358 if (richsym_print_bitsize && sym->aux) |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
359 printf("\t/* %u bits */", get_u32(sym->aux+4)); |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
360 putchar('\n'); |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
361 continue; |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
362 case C_MOS: |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
363 case C_MOU: |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
364 case C_MOE: |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
365 case C_TPDEF: |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
366 break; |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
367 default: |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
368 continue; |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
369 } |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
370 if (sym->name[0] != '_') { |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
371 printf( |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
372 "/* 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
|
373 sym->number, |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
374 storage_class_to_string(sym->class, 0)); |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
375 continue; |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
376 } |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
377 if (!sym->aux && sym->class != C_MOE) { |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
378 printf( |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
379 "/* 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
|
380 sym->number, |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
381 storage_class_to_string(sym->class, 0)); |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
382 continue; |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
383 } |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
384 switch (sym->class) { |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
385 case C_MOS: |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
386 case C_MOU: |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
387 if (sym->scnum != -1) |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
388 printf("\t/* MOS/MOU section != ABS! */\n"); |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
389 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
|
390 printf("\t/* offset: %u bits */\n", sym->value); |
145
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
391 richsym_print_in_c("\t", sym, 0); |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
392 continue; |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
393 case C_MOE: |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
394 if (sym->scnum != -1) { |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
395 printf("\t/* MOE section != ABS! */\n"); |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
396 continue; |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
397 } |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
398 printf("\t%s = %u;", sym->name + 1, sym->value); |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
399 if (sym->value >= 10) |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
400 printf("\t/* 0x%x */", sym->value); |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
401 putchar('\n'); |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
402 continue; |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
403 case C_TPDEF: |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
404 richsym_print_in_c("typedef ", sym, |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
405 !(sym->type & 0xFFF0)); |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
406 continue; |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
407 } |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
408 } |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
409 exit(0); |
25d3ead621f8
tiobjd: ctypes command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
144
diff
changeset
|
410 } |
150
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
411 |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
412 static int |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
413 localsym_sanity_check(sym) |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
414 struct internal_syment *sym; |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
415 { |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
416 if (!sym->aux) { |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
417 printf("; symbol #%u of class %s has no aux record\n", |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
418 sym->number, storage_class_to_string(sym->class, 0)); |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
419 return(-1); |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
420 } |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
421 if (sym->scnum != -1) { |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
422 printf("; symbol #%u of class %s: section != ABS\n", |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
423 sym->number, storage_class_to_string(sym->class, 0)); |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
424 return(-1); |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
425 } |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
426 return(0); |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
427 } |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
428 |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
429 void |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
430 richsym_function_locals(headsym) |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
431 struct internal_syment *headsym; |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
432 { |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
433 unsigned n; |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
434 struct internal_syment *sym; |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
435 char classbuf[8]; |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
436 |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
437 for (n = headsym->number + 1; n < nsymtab; n++) { |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
438 sym = symtab[n]; |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
439 if (!sym) |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
440 continue; |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
441 switch (sym->class) { |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
442 case C_REG: |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
443 case C_REGPARM: |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
444 if (localsym_sanity_check(sym) < 0) |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
445 continue; |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
446 if (sym->value > 0xF) { |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
447 printf( |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
448 "; symbol #%u of class %s: value is not a valid register number\n", |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
449 sym->number, |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
450 storage_class_to_string(sym->class, 0)); |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
451 continue; |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
452 } |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
453 printf("; %s r%u: ", |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
454 storage_class_to_string(sym->class, 0), |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
455 sym->value); |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
456 richsym_print_in_c("", sym, 0); |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
457 continue; |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
458 case C_ARG: |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
459 case C_AUTO: |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
460 if (localsym_sanity_check(sym) < 0) |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
461 continue; |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
462 printf("; %s at 0x%x: ", |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
463 storage_class_to_string(sym->class, 0), |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
464 sym->value); |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
465 richsym_print_in_c("", sym, 0); |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
466 continue; |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
467 case C_FCN: |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
468 return; |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
469 default: |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
470 printf( |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
471 "; presumed local symbol #%u: unexpected class %s\n", |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
472 sym->number, |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
473 storage_class_to_string(sym->class, classbuf)); |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
474 return; |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
475 } |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
476 } |
df01a4f4c272
tiobjd disasm -g: dump of function locals implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
149
diff
changeset
|
477 } |