1 static char rcsid[] = "$Id: ashow.c,v 1.6 1994/06/24 10:13:45 ceriel Exp $";
3 * show - make the contents of an ACK object file human readable.
11 #define OK 0 /* Return value of gethead if Orl Korekt. */
12 #define BMASK 0xFF /* To extract least significant 8 bits from an int. */
20 register char **arg = argv;
21 struct outhead header;
24 if (! rd_open(*arg)) {
25 error("%s: cannot read %s\n", prog, *arg);
29 if (BADMAGIC(header)) {
30 error("%s: %s not an ACK object file\n", prog, *arg);
32 printf("%s:\n", *arg);
40 * Read an ACK object file from `fp' and show it in a human readable way.
41 * NB. The header has already been read and is in the struct outhead `headp'
45 register struct outhead *headp;
48 register struct outname *np;
49 register struct outname *name; /* Dynamically allocated name-array. */
50 register char *string;/* Base of string area. */
51 extern char *myalloc();
53 printf("Version %d\n", headp->oh_stamp);
54 showflags((unsigned) headp->oh_flags);
58 for (i = 0; i < headp->oh_nsect; i++) {
59 printf("Section %d:\n", i);
63 * Show relocation information.
65 for (i = 0; i < headp->oh_nrelo; i++) {
66 printf("Relocation record %d:\n", i);
70 * We get all struct outname's and the strings in core first.
72 name = (struct outname *) myalloc(headp->oh_nname * SZ_NAME);
73 string = myalloc((unsigned) headp->oh_nchar);
74 rd_name(name, headp->oh_nname);
75 for (np = &name[0]; np < &name[headp->oh_nname]; np++) {
76 if (np->on_foff != 0) {
77 np->on_foff -= OFF_CHAR(*headp);
78 if (np->on_foff >= headp->oh_nchar || np->on_foff < 0) {
81 else np->on_mptr = string + np->on_foff;
85 * Transfer strings from file to core.
87 rd_string(string, headp->oh_nchar);
89 * Now we can show all names.
91 for (np = &name[0]; np < &name[headp->oh_nname]; np++) {
92 printf("Name %d:\n", np - name);
98 * Show flags from header.
103 if (flagword & HF_LINK) printf("unresolved references left\n");
111 struct outsect section;
113 rd_sect(§ion, 1);
114 printf("\tstartaddress in machine\t%ld\n", section.os_base);
115 printf("\tsection size in machine\t%ld\n", section.os_size);
116 printf("\tstartaddress in file\t%ld\n", section.os_foff);
117 printf("\tsection size in file\t%ld\n", section.os_flen);
118 printf("\tsection alignment\t%ld\n", section.os_lign);
122 * Show a relocation record.
126 struct outrelo relrec;
129 switch (relrec.or_type & RELSZ) {
131 printf("\t1 byte\n");
134 printf("\t2 bytes\n");
137 printf("\t4 bytes\n");
140 error("\tunexpected relocation length\n");
143 if (relrec.or_type & RELPC) printf("\tpc relative\n");
144 if (relrec.or_type & RELBR) printf("\tbytes reversed\n");
145 if (relrec.or_type & RELWR) printf("\twords reversed\n");
146 printf("\treferencing section\t%d\n", (relrec.or_sect & BMASK) - S_MIN);
147 printf("\treferenced symbol index\t%d\n", relrec.or_nami);
148 printf("\treferencing address\t%ld\n", relrec.or_addr);
152 * Show the name in the struct `namep' points to.
155 struct outname *namep;
158 printf("\t%s\n", namep->on_mptr);
160 printf("\tno name\n");
161 switch (namep->on_type & S_TYP) {
163 printf("\tundefined\n");
166 printf("\tabsolute\n");
169 printf("\tcross reference\n");
171 printf("\tin section %d\n", (namep->on_type & S_TYP) - S_MIN);
174 if (namep->on_type & S_EXT) printf("\texternal\n");
175 if (namep->on_type & S_STB) {
176 printf("\tstab 0x%x\n", namep->on_type >> 8);
177 printf("\tdesc 0x%x\n", namep->on_desc);
179 else switch (namep->on_type & S_ETC) {
181 printf("\tsection name\n"); break;
183 printf("\thll source line item\n"); break;
185 printf("\thll source file item\n"); break;
187 printf("\tass src file item\n"); break;
189 printf("\tcommon\n"); break;
193 printf("\tstab 0x%x\n", namep->on_type >> 8);
194 printf("\tdesc 0x%x\n", namep->on_desc);
196 printf("\tvalue %ld\n", namep->on_valu);
200 * Core allocation via malloc() but fatal if no core.
207 extern char *malloc();
210 if (rcp == (char *) 0) {
211 error("Out of core\n");
218 error(s, a1, a2, a3, a4)
222 fprintf(stderr, s, a1, a2, a3, a4);
227 error("Error in reading the object file\n");