BSD 3 development
[unix-history] / usr / src / cmd / nm.c
index 2d3ee27..1c620f3 100644 (file)
@@ -8,12 +8,14 @@
 
 
 #include       <ar.h>
 
 
 #include       <ar.h>
-#include       <a.out.h>
 #include       <stdio.h>
 #include       <ctype.h>
 #include       <stdio.h>
 #include       <ctype.h>
+#include       <a.out.h>
+#include       <pagsiz.h>
+
 #define        MAGIC   exp.a_magic
 #define        BADMAG  MAGIC!=A_MAGIC1 && MAGIC!=A_MAGIC2  \
 #define        MAGIC   exp.a_magic
 #define        BADMAG  MAGIC!=A_MAGIC1 && MAGIC!=A_MAGIC2  \
-               && MAGIC!=A_MAGIC3 && MAGIC!=A_MAGIC4
+               && MAGIC!=A_MAGIC3 && MAGIC!=A_MAGIC4 && MAGIC != 0412 && MAGIC != 0413
 #define        SELECT  arch_flg ? arp.ar_name : *argv
 int    numsort_flg;
 int    undef_flg;
 #define        SELECT  arch_flg ? arp.ar_name : *argv
 int    numsort_flg;
 int    undef_flg;
@@ -103,9 +105,9 @@ char **argv;
                        fread((char *)&exp, 1, sizeof(struct exec), fi);
                        if (BADMAG)             /* archive element not in  */
                                continue;       /* proper format - skip it */
                        fread((char *)&exp, 1, sizeof(struct exec), fi);
                        if (BADMAG)             /* archive element not in  */
                                continue;       /* proper format - skip it */
-                       o = (long)exp.a_text + exp.a_data;
-                       if ((exp.a_flag & 01) == 0)
-                               o *= 2;
+                       o = (long)exp.a_text + exp.a_data + exp.a_trsize + exp.a_drsize;
+                       if (MAGIC==0412 || MAGIC==0413)
+                               o += PAGSIZ - sizeof(struct exec);
                        fseek(fi, o, 1);
                        n = exp.a_syms / sizeof(struct nlist);
                        if (n == 0) {
                        fseek(fi, o, 1);
                        n = exp.a_syms / sizeof(struct nlist);
                        if (n == 0) {
@@ -117,15 +119,46 @@ char **argv;
                                fread((char *)&sym, 1, sizeof(sym), fi);
                                if (globl_flg && (sym.n_type&N_EXT)==0)
                                        continue;
                                fread((char *)&sym, 1, sizeof(sym), fi);
                                if (globl_flg && (sym.n_type&N_EXT)==0)
                                        continue;
-                               switch (sym.n_type&N_TYPE) {
+                               if (symp==NULL)
+                                       symp = (struct nlist *)malloc(sizeof(struct nlist));
+                               else {
+                                       symp = (struct nlist *)realloc(symp, (i+1)*sizeof(struct nlist));
+                               }
+                               if (symp == NULL) {
+                                       fprintf(stderr, "nm: out of memory on %s\n", *argv);
+                                       exit(2);
+                               }
+                               symp[i++] = sym;
+                       }
+                       if (nosort_flg==0)
+                               qsort(symp, i, sizeof(struct nlist), compare);
+                       if ((arch_flg || narg>1) && prep_flg==0)
+                               printf("\n%s:\n", SELECT);
+                       for (n=0; n<i; n++) {
+                               if (prep_flg) {
+                                       if (arch_flg)
+                                               printf("%s:", *argv);
+                                       printf("%s:", SELECT);
+                               }
+                               c = symp[n].n_type;
+                               
+                               if (c & STABTYPE) {
+                                       printf("%08x - %-8.8s %02x %02x %04x\n",
+                                               symp[n].n_value,
+                                               symp[n].n_name,
+                                               symp[n].n_type & 0xff,
+                                               symp[n].n_other & 0xff,
+                                               symp[n].n_desc & 0xffff);
+                                       continue;
+                               }
+                               switch (c&(N_TYPE-N_EXT)) {
 
                                case N_UNDF:
                                        c = 'u';
 
                                case N_UNDF:
                                        c = 'u';
-                                       if (sym.n_value)
+                                       if (symp[n].n_value)
                                                c = 'c';
                                        break;
 
                                                c = 'c';
                                        break;
 
-                               default:
                                case N_ABS:
                                        c = 'a';
                                        break;
                                case N_ABS:
                                        c = 'a';
                                        break;
@@ -146,46 +179,25 @@ char **argv;
                                        c = 'f';
                                        break;
 
                                        c = 'f';
                                        break;
 
+/*
                                case N_REG:
                                        c = 'r';
                                        break;
                                case N_REG:
                                        c = 'r';
                                        break;
+ */
                                }
                                if (undef_flg && c!='u')
                                        continue;
                                }
                                if (undef_flg && c!='u')
                                        continue;
-                               if (sym.n_type&N_EXT)
+                               if (symp[n].n_type&N_EXT)
                                        c = toupper(c);
                                        c = toupper(c);
-                               sym.n_type = c;
-                               if (symp==NULL)
-                                       symp = (struct nlist *)malloc(sizeof(struct nlist));
-                               else {
-                                       symp = (struct nlist *)realloc(symp, (i+1)*sizeof(struct nlist));
-                               }
-                               if (symp == NULL) {
-                                       fprintf(stderr, "nm: out of memory on %s\n", *argv);
-                                       exit(2);
-                               }
-                               symp[i++] = sym;
-                       }
-                       if (nosort_flg==0)
-                               qsort(symp, i, sizeof(struct nlist), compare);
-                       if ((arch_flg || narg>1) && prep_flg==0)
-                               printf("\n%s:\n", SELECT);
-                       for (n=0; n<i; n++) {
-                               if (prep_flg) {
-                                       if (arch_flg)
-                                               printf("%s:", *argv);
-                                       printf("%s:", SELECT);
-                               }
-                               c = symp[n].n_type;
                                if (!undef_flg) {
                                        if (c=='u' || c=='U')
                                if (!undef_flg) {
                                        if (c=='u' || c=='U')
-                                               printf("      ");
+                                               printf("        ");
                                        else
                                                printf(FORMAT, symp[n].n_value);
                                        printf(" %c ", c);
                                }
                                printf("%.8s\n", symp[n].n_name);
                                        else
                                                printf(FORMAT, symp[n].n_value);
                                        printf(" %c ", c);
                                }
                                printf("%.8s\n", symp[n].n_name);
-                       }
+               l1:;    }
                        if (symp)
                                free((char *)symp);
                } while(arch_flg && nextel(fi));
                        if (symp)
                                free((char *)symp);
                } while(arch_flg && nextel(fi));