🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.bugs.2bsd
Article #305

bignm - namelist huge objects

#305
From: Keith Packard
Date: Thu, 20 Mar 1986 07:59
113 lines
3241 bytes
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);
	}
}
Technical Details
Message-ID: <202@motel6.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!genrad!panda!talcott!harvard!seismo!lll-crg!lll-lcc!qantel!hplabs!tektronix!reed!motel6!keith

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!genrad!panda!talcott!harvard!seismo!lll-crg!lll-lcc!qantel!hplabs!tektronix!reed!motel6!keith
From: keith@motel6.UUCP (Keith Packard)
Newsgroups: net.bugs.2bsd
Subject: bignm - namelist huge objects
Message-ID: <202@motel6.UUCP>
Date: Thu, 20-Mar-86 02:59:42 EST
Article-I.D.: motel6.202
Posted: Thu Mar 20 02:59:42 1986
Date-Received: Sat, 22-Mar-86 23:29:02 EST
Distribution: net
Organization: 5440 SE 41st, Portland, OR
Lines: 113