bignm - namelist huge objects

Keith Packard keith at motel6.UUCP
Thu Mar 20 17:59:42 AEST 1986


I have been working on several *large* programs for my 11/73 system,
several versions of rogue and a full implementation of hack version 1.0.2.

These programs often have text sizes exceeding 150K and a proportionally
large symbol table.  The standard nm(1) program cannot read these symbol
tables, even to just dump them out.  I wrote a quick program that simply
reads the symbol table and prints each symbol just as it is found.  If
sorted output is desired, simply pipe it through sort(1).  I call it
"bignm".  Obviously this program is only designed to work on 2.9BSD
unix systems, it is unnecessary on any other system.

Keith Packard
tektronix!reed!motel6!keith

-------------------cut here this is not a shell archive-----------------------
/*
 *	bignm
 *
 *	just read and dump the symbol table - nothing fancy
 */

# include	<sys/types.h>
# include	<a.out.h>
# include	<stdio.h>

struct exec	header;
struct ovlhdr	overlay;
struct nlist	name;

main (argc, argv)
char	**argv;
{
	char	*file;
	FILE	*aout;
	long	symoff;
	unsigned	nsyms;
	char	type;
	int	i;

	while (file = *++argv) {
		if ((aout = fopen (file, "r")) == NULL) {
			perror (file);
			continue;
		}
		fread (&header, sizeof (header), 1, aout);
		if (N_BADMAG (header.a_magic)) {
			fprintf (stderr, "%s not an a.out file\n", file);
			fclose (aout);
			continue;
		}
		nsyms = header.a_syms / sizeof (struct nlist);
		if (nsyms == 0) {
			fprintf (stderr, "%s is stripped\n", file);
			fclose (aout);
			continue;
		}
		symoff = (long) N_TXTOFF (header) + (long) header.a_text +
			 (long) header.a_data;
		if (header.a_magic == A_MAGIC5 || header.a_magic == A_MAGIC6){
			fread (&overlay, sizeof (overlay), 1, aout);
			for (i = 0; i < NOVL; i++)
				symoff += (long) overlay.ov_siz[i];
		}
		fseek (aout, (long) symoff, 0);
		while (nsyms--) {
			fread (&name, sizeof (name), 1, aout);
			printf ("%-8.8s ", name.n_name);
			switch (name.n_type) {
			case N_UNDF:
				type = 'U';
				break;
			case N_ABS:
				type = 'a';
				break;
			case N_ABS|N_EXT:
				type = 'A';
				break;
			case N_TEXT:
				type = 't';
				break;
			case N_TEXT|N_EXT:
				type = 'T';
				break;
			case N_DATA:
				type = 'd';
				break;
			case N_DATA|N_EXT:
				type = 'D';
				break;
			case N_BSS:
				type = 'b';
				break;
			case N_BSS|N_EXT:
				type = 'B';
				break;
			case N_REG:
				type = 'r';
				break;
			case N_FN:
				type = 'f';
				break;
			default:
				type = '?';
				break;
			}
			putchar (type);
			putchar (' ');
			printf (FORMAT, name.n_value);
			putchar ('\n');
		}
		fclose (aout);
	}
}



More information about the Comp.bugs.2bsd mailing list