1: /*
   2:  *	Program Name:   strdump.c
   3:  *	Date: January 21, 1994
   4:  *	Author: S.M. Schultz
   5:  *
   6:  *	-----------------   Modification History   ---------------
   7:  *      Version Date            Reason For Modification
   8:  *      1.0     12Feb94         1. Initial release into the public domain.
   9: */
  10: 
  11: /*
  12:  * Dump the symbol table of a program to stdout, one symbol per line in
  13:  * the form:
  14:  *
  15:  *	symbol_string  type  overlay  value
  16:  *
  17:  * Typical use is to feed the output of this program into:
  18:  *
  19:  *    "sort +0 -1 +1n -2 +2n -3 +3n -4 -u"
  20:  *
  21:  * This program is used by 'strcompact' to compress the string (and
  22:  * symbol) tables of an executable.
  23: */
  24: 
  25: #include <sys/types.h>
  26: #include <sys/dir.h>
  27: #include <stdio.h>
  28: #include <ctype.h>
  29: #include <a.out.h>
  30: #include <sys/file.h>
  31: #include <string.h>
  32: 
  33:     char    **xargv;    /* global copy of argv */
  34:     char    *strp;      /* pointer to in-memory string table */
  35:     struct  xexec xhdr; /* the extended a.out header */
  36: 
  37: extern  char    *malloc();
  38: 
  39: main(argc, argv)
  40:     int argc;
  41:     char    **argv;
  42:     {
  43: 
  44:     if  (argc != 2)
  45:         {
  46:         fprintf(stderr, "%s:  need a file name\n", argv[0]);
  47:         exit(1);
  48:         }
  49:     xargv = ++argv;
  50:     namelist();
  51:     exit(0);
  52:     }
  53: 
  54: namelist()
  55:     {
  56:     char    ibuf[BUFSIZ];
  57:     register FILE   *fi;
  58:     off_t   o, stroff;
  59:     long    strsiz;
  60:     register int n;
  61: 
  62:     fi = fopen(*xargv, "r");
  63:     if  (fi == NULL)
  64:         error("cannot open");
  65:     setbuf(fi, ibuf);
  66: 
  67:     fread((char *)&xhdr, 1, sizeof(xhdr), fi);
  68:     if  (N_BADMAG(xhdr.e))
  69:         error("bad format");
  70:     rewind(fi);
  71: 
  72:     o = N_SYMOFF(xhdr);
  73:     fseek(fi, o, L_SET);
  74:     n = xhdr.e.a_syms / sizeof(struct nlist);
  75:     if  (n == 0)
  76:         error("no name list");
  77: 
  78:     stroff = N_STROFF(xhdr);
  79:     fseek(fi, stroff, L_SET);
  80:     if  (fread(&strsiz, sizeof (long), 1, fi) != 1)
  81:         error("no string table");
  82:     strp = (char *)malloc((int)strsiz);
  83:     if  (strp == NULL || strsiz > 48 * 1024L)
  84:         error("no memory for strings");
  85:     if  (fread(strp+sizeof(strsiz),(int)strsiz-sizeof(strsiz),1,fi)!=1)
  86:         error("error reading strings");
  87: 
  88:     fseek(fi, o, L_SET);
  89:     dumpsyms(fi, n);
  90:     free((char *)strp);
  91:     fclose(fi);
  92:     }
  93: 
  94: dumpsyms(fi, nsyms)
  95:     register FILE *fi;
  96:     int nsyms;
  97:     {
  98:     register int n;
  99:     struct  nlist sym;
 100:     register struct nlist *sp;
 101: 
 102:     sp = &sym;
 103:     for (n = 0; n < nsyms; n++)
 104:         {
 105:         fread(&sym, sizeof sym, 1, fi);
 106:         printf("%s %u %u %u\n", strp + (int)sp->n_un.n_strx, sp->n_type,
 107:             sp->n_ovly, sp->n_value);
 108:         }
 109:     }
 110: 
 111: error(s)
 112:     char *s;
 113:     {
 114:     fprintf(stderr, "syms: %s: %s\n", *xargv, s);
 115:     exit(1);
 116:     }

Defined functions

dumpsyms defined in line 94; used 1 times
  • in line 89
error defined in line 111; used 6 times
main defined in line 39; never used
namelist defined in line 54; used 1 times
  • in line 50

Defined variables

strp defined in line 34; used 5 times
xargv defined in line 33; used 3 times
xhdr defined in line 35; used 6 times
Last modified: 1994-02-22
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2487
Valid CSS Valid XHTML 1.0 Strict