a.out symbol table problems

Peter Corke pic at mimir.dmt.oz
Mon Dec 8 15:50:12 AEST 1986


I have been experimenting with the nlist(3) function to obtain the
address and type of C global variables.  nlist() returns a structure
from the a.out file's symbol table, that contains the symbol's address,
its segment (text, data, bss), and n_desc which I gather should have 
its type (double, int, short etc) encoded in bitfields (according to 
man 5 stab).

However, the nlist() function returns nonsense for this field of the
structure.  If I "cc -S" the source, I see that the compiler is generating
the .stabs directives with the correct values in all fields.  It seems
that after linking this field contains garbage.  A small demo program is
appended which prints out the field values returned.  The variables f & g
which are of the same type, have different n_desc values; 124 & 125 
respectively.

This effect occurs on a Vax/4.2bsd and a Sun 3.2 system.  If anybody has
any ideas please mail me at the address below.

Thanks,

Peter

----------------- cut here ----------------------------------------------
#include	<stdio.h>
#include	<nlist.h>

int	i;
float	f, g;

struct nlist	n[] =
	{
		{"_i"},
		{"_f"},
		{"_g"},
		{""}
	};

main(ac, av)
int	ac;
char	**av;
{
	struct nlist	*p = n;

	printf("nlist status %d\n", nlist(av[0], n));
	while (p->n_name[0] != '\0') {
		printf("%s, typ %x, val %x, desc %x\n", 
			p->n_name, p->n_type, 
			p->n_value, p->n_desc
		);
		p++;
	}
}
----------------- cut here ----------------------------------------------

-- 
Peter Corke,                   PHONE: +61 (03)487-9259
CSIRO                          ACSNET:pic at mimir.dmt.oz
Div. Manufacturing Technology  ARPA:  pic%mimir.dmt.oz at seismo.arpa	
Melbourne                      CSNET: pic at mimir.dmt.oz
Australia.                     UUCP: {seismo,ukc,mcvax}!munnari!mimir.dmt!pic
3072                                 {decvax,pesnta,vax135}!mulga!mimir.dmt!pic



More information about the Comp.unix.wizards mailing list