From: joel@abigale.uucp (Joel Rosi-Schwartz)
Newsgroups: comp.lang.perl
Subject: locsym - A program to locate undefined references
Date: 16 Aug 92 15:37:42 GMT
Organization: Techne Research, Finchampstead, Berkshire (UK)

This is the firts beta release of locsym, but lets be honest about it,
beta may be a bit optimistic ;-)

There is no manual yet and this code is for sure guaranteed *NOT* to
be portable across platforms yet.  It probably could use a bunch of
options (just so we feel good about loving Un*x). Error checking is
minimal, but so far I do not see a real reason to clutter the code,
but I am sure that you will find 100 reasons I'm over optimistic ;-)

What it does do is a task I have spent endless hours doing by hand.
Ever go to compile a program off the net and have a bunch of:

    undefined               first referenced
     symbol                     in file
    superFunc                    ppp.o
    ld fatal: Symbol referencing errors. No output written to ppp

Now don't be macho and lie ;-)

Well what I've always done is:
	1. man superFunc
		nope no page for that or the library is not listed ;-(
	2. run for every lib dir
		for lib in lib*.a
		do
			ar t $lib | egrep superFunc
			echo $lib
		done
	  
Or some such nonsense. And yeh most of the time I would find what I was
looking for, or firgue out I don't have it.

Well finally there is an easier way.  Just run mksymdb which will create
a dbm database on all archives on your machine.  Then whenever you want
to know where something is just say

	# locsym superFunc
	superFunc: not found

but how about

	# locsym getcwd
	getcwd:
			/lib/libc.a
			/usr/lib/libp/libc.a

or

	# locsym getcwd printf timezone

	getcwd:
			/lib/libc.a
			/usr/lib/libp/libc.a

	printf:
			/lib/libc.a
			/lib/libc_s.a
			/usr/lib/libp/libc.a

	timezone:
			/lib/libc.a
			/usr/lib/libp/libc.a

or even

	# locsym ^[esf]printf

	eprintf:
			/usr/local/lib/libparse.a

	sprintf:
			/lib/libc.a
			/lib/libc_s.a
			/usr/lib/libp/libc.a

	fprintf:
			/lib/libc.a
			/lib/libc_s.a
			/usr/lib/libp/libc.a


Pretty nifty huh?

Here are the caveats. I built this on SCO Unix 3.2 and after looking
at Larry's library extract code in Configure I figrue this is going
to be real fun to get working on a bunch of platforms.  The hard part
is going to be all of the different flags to "nm" and to handle the
varous outputs from "nm".  Nothing else should be system dependent, but
that is enough ;-(

I am will to take responsibility for maintaining this, but I do not
have access to a bunch of different systems.  If you figure out what
is need on your system, please send it back to me.  I will try to figure
out how to put it all into one script that intellegently figures out
what it needs to do.  Any suggestions towards this end and how to
make this faster and more robust are much welcome.

I hope this is useful.  Use it in peace and good health.

Cheers,
Joel

     ==================================================================
     ||               T E C H N E   R E S E A R C H                  ||
     ||  ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++  ||
     ||                     Joel Rosi-Schwartz                       ||
     ||   Hildorien House            +   Email: joel@abigale.UUCP    ||
     ||   12 Waverley Way            +    (pyrltd!abigale.UUCP!joel) ||
     ||   Finchampstead, Wokingham   +   Phone: +44 (734) 730.260    ||
     ||   Berkshire RG11 4YD (UK)    +   Fax:   +44 (734) 730.272    ||
     ==================================================================

---- cut here -----  snip/snip  -------------------------------------------
#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of archive 1 (of 1)."
# Contents:  INSTALL MANIFEST locsym mksymdb
# Wrapped by joel@abigale on Sun Aug 16 16:26:30 1992
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'INSTALL' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'INSTALL'\"
else
echo shar: Extracting \"'INSTALL'\" \(393 characters\)
sed "s/^X//" >'INSTALL' <<'END_OF_FILE'
XNo big deal here.  The two things to look out for are the
Xlocation of the symbols database and the list of directories
Xwhich are parsed for libraries.  Not that the list of dirs is
Xfor the "root" to start the search in, as I use find to pick
Xup all of the libs below these points.  If you change the
Xlocation of the database in "mksymdb" make sure to also change
Xit in "locsym".
X
XCheers,
Xjoel
END_OF_FILE
if test 393 -ne `wc -c <'INSTALL'`; then
    echo shar: \"'INSTALL'\" unpacked with wrong size!
fi
# end of 'INSTALL'
fi
if test -f 'MANIFEST' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'MANIFEST'\"
else
echo shar: Extracting \"'MANIFEST'\" \(220 characters\)
sed "s/^X//" >'MANIFEST' <<'END_OF_FILE'
X   File Name		Archive #	Description
X-----------------------------------------------------------
X INSTALL                    1	
X MANIFEST                   1	
X locsym                     1	
X mksymdb                    1	
END_OF_FILE
if test 220 -ne `wc -c <'MANIFEST'`; then
    echo shar: \"'MANIFEST'\" unpacked with wrong size!
fi
# end of 'MANIFEST'
fi
if test -f 'locsym' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'locsym'\"
else
echo shar: Extracting \"'locsym'\" \(6676 characters\)
sed "s/^X//" >'locsym' <<'END_OF_FILE'
X#!/usr/local/bin/perl
Xeval "exec /usr/local/bin/perl -S $0 $*"
X    if $running_under_some_shell;
X
X  #          $Id: locsym,v 1.1 1992/08/16 14:30:26 joel Exp root $
X  # ======================================================================== #
X  #                                                                          #
X  #  locsym and its sister program mksymdb attemts to handle the common      #
X  #  progamming problem of finding which library or libraries contains       #
X  #  the definition of a given symbol.  mksymdb needs only be run once to    #
X  #  set up the dbm database (or, of course, if you change your libraries).  #
X  #  After that to find a given function or extern definition is a quick     #
X  #  look-up using locdb.                                                    #
X  #                                                                          #
X  #  This code is for sure not portable across systems at this point.  I've  #
X  #  looked at Larry Wall's Configrue program to get an idea of what needs   #
X  #  to be done to make it portable and only understand half of it (maybe;-) #
X  #  Please send me any code towards this end and I will try to maintain     #
X  #  this such that as many systems as possible work without kluges.         #
X  #                                                                          #
X  #  The sole purpose of the copyright is so I don't get sued and my soul ;-)#
X  #  intention is that it should be as helpful and useful to as many folks   #
X  #  as possible, without anyone trying to hoard it or claim it as their     #
X  #  own.  Use it in peace and good health.                                  #
X  #                                                                          #
X  #  Suggestions, advice, bug reports and flames to:                         #
X  #                                                                          #
X  #        Joel Rosi-Schwartz                                                #
X  #        Techne Research                                                   #
X  #        The United Kingdom                                                #
X  #        E-mail: joel@abigale.UUPC                                         #
X  #        Or: uknet.ac.uk!pyrltd.uucp!abigale.uucp!joel                     #
X  #        Phone: +44 734 730.260                                            #
X  #        Fax: +44 734 730.272                                              #
X  #                                                                          #
X  # ======================================================================== #
X
X#
X# How much noise do we want ;-)
X#
X$verbose = 0;
X$quiet = 0;
X$debug = 0;
X
X#
X# Our symbols database.
X#
X$symdb = '/usr/local/etc/symdb';
X%SYMDB = ();
X
X#
X# Open up a existing symbols database.
X#
Xdbmopen (%SYMDB, $symdb, undef());
X
X#
X# Loop over ARGV and find all the requested symbols.
X# If the user hands us a regex, then we do a long
X# search through the whole database, otherwise we
X# do a quick lookup.
X#
X
Xforeach $symbol (@ARGV) {
X	if ( $symbol =~ /[*?+[{\\^]/) {
X		$found = 0;
X
X		while (($key, $val) = each %SYMDB) {
X			if ($key =~ /$symbol/) {
X				@archives = split (' ', $val);
X				if (@archives) {
X					$found = 1;
X					print "$key:\n";
X					foreach $archive (@archives) {
X						print "        $archive\n";
X					}
X					print "\n";
X				}
X			}
X		}
X
X		print "$symbol: not found\n" unless $found;
X	} else {
X		@archives = split (' ', $SYMDB{$symbol});
X		if (@archives) {
X			print "$symbol:\n";
X			foreach $archive (@archives) {
X				print "        $archive\n";
X			}
X			print "\n";
X		}
X		else {
X			print "$symbol: not found\n";
X			print "\n";
X		}
X	}
X}
X
X#
X# And say bye
X#
Xdbmclose (SYMDB);
Xexit 0;
X
X  #############################################################################
X  #                                                                           #
X  #  Copyright (c) 1992 Techne Research                                       #
X  #  Copyright (c) 1992 Joel Rosi-Schwartz                                    #
X  #  All rights reserved.                                                     #
X  #                                                                           #
X  #  Redistribution and use in source and binary forms, with or without       #
X  #  modification, are permitted provided that the following conditions       #
X  #  are met:                                                                 #
X  #  1. Redistributions of source code must retain the above copyright        #
X  #     notice, this list of conditions and the following disclaimer.         #
X  #  2. Redistributions in binary form must reproduce the above copyright     #
X  #     notice, this list of conditions and the following disclaimer in the   #
X  #     documentation and/or other materials provided with the distribution.  #
X  #  3. All advertising materials mentioning features or use of this software #
X  #     must display the following acknowledgement:                           #
X  #       This product includes software developed by the Techne Research     #
X  #  4. The name of Techne Research may not be used to endorse or promote     #
X  #     products derived from this software without specific prior written    #
X  #     permission.                                                           #
X  #                                                                           #
X  #  THIS SOFTWARE IS PROVIDED BY THE TECHNE RESEARCH (UK) ``AS IS'' AND      #
X  #  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE    #
X  #  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR       #
X  #  PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL COMDISCO SYSTEMS INC BE       #
X  #  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR      #
X  #  CONSEQUENTIAL #  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT     #
X  #  OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR       #
X  #  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,    #
X  #  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE     #
X  #  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,        #
X  #  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.                       #
X  #                                                                           #
X  # This copyright notice derived from material copyrighted by the Regents    #
X  # of the University of California.                                          #
X  #                                                                           #
X  #############################################################################
X
X#
END_OF_FILE
if test 6676 -ne `wc -c <'locsym'`; then
    echo shar: \"'locsym'\" unpacked with wrong size!
fi
chmod +x 'locsym'
# end of 'locsym'
fi
if test -f 'mksymdb' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'mksymdb'\"
else
echo shar: Extracting \"'mksymdb'\" \(7997 characters\)
sed "s/^X//" >'mksymdb' <<'END_OF_FILE'
X#!/usr/local/bin/perl
Xeval "exec /usr/local/bin/perl -S $0 $*"
X    if $running_under_some_shell;
X
X  #          $Id: mksymdb,v 1.1 1992/08/16 14:30:26 joel Exp root $
X  # ======================================================================== #
X  #                                                                          #
X  #   Copyright (c)       1992 by Techne Resarch                             #
X  #   Copyright (c)       1992 by Joel Rosi-Schwartz                         #
X  #   All Rights Reserved                                                    #
X  #                                                                          #
X  #   Full Copyright notice at bottom of file.                               #
X  #                                                                          #
X  #  mksymdb and its sister program locsym attemts to handle the common      #
X  #  progamming problem of finding which library or libraries contains       #
X  #  the definition of a given symbol.  mksymdb needs only be run once to    #
X  #  set up the dbm database (or, of course, if you change your libraries).  #
X  #  After that to find a given function or extern definition is a quick     #
X  #  look-up using locdb.                                                    #
X  #                                                                          #
X  #  This code is for sure not portable across systems at this point.  I've  #
X  #  looked at Larry Wall's Configrue program to get an idea of what needs   #
X  #  to be done to make it portable and only understand half of it (maybe;-) #
X  #  Please send me any code towards this end and I will try to maintain     #
X  #  this such that as many systems as possible work without kluges.         #
X  #                                                                          #
X  #  The sole purpose of the copyright is so I don't get sued and my soul ;-)#
X  #  intention is that it should be as helpful and useful to as many folks   #
X  #  as possible, without anyone trying to hoard it or claim it as their     #
X  #  own.  Use it in peace and good health.                                  #
X  #                                                                          #
X  #  Suggestions, advice, bug reports and flames to:                         #
X  #                                                                          #
X  #        Joel Rosi-Schwartz                                                #
X  #        Techne Research                                                   #
X  #        The United Kingdom                                                #
X  #        E-mail: joel@abigale.UUPC                                         #
X  #        Or: uknet.ac.uk!pyrltd.uucp!abigale.uucp!joel                     #
X  #        Phone: +44 734 730.260                                            #
X  #        Fax: +44 734 730.272                                              #
X  #                                                                          #
X  # ======================================================================== #
X
X#
X# How much noise do we want ;-)
X#
X$verbose = 0;
X$quiet = 0;
X$debug = 0;
X
X#
X# The root directories of all archives we will parse.
X#
X@libroots = (
X	'/lib',
X	'/usr/lib',
X	'/usr/local/lib',
X	);
X
X#
X# The "nm" command which will create quickly parseable output.
X#
X$nmcmd = 'nm -p';
X
X#
X# Our symbols database.
X#
X$symdb = '/usr/local/etc/symdb';
X%SYMDB = ();
X
X#
X# Save the sysmdb iff it exists, JIC.
X#
Xif ( -e "${symdb}.pag") {
X	print STDERR "${symdb}.pag exists. Saving in ${symdb}.pag-\n"
X		unless $quiet;
X	rename ("${symdb}.pag", "${symdb}.pag-") ||
X		die "Could not rename ${symdb}.pag: $!\n";
X}
X
Xif ( -e "${symdb}.dir") {
X	print STDERR "${symdb}.dir exists. Saving in ${symdb}.dir-\n"
X		unless $quiet;
X	rename ("${symdb}.dir", "${symdb}.dir-") ||
X		die "Could not rename ${symdb}.dir: $!\n";
X}
X
X#
X# Open up a new one.
X#
Xdbmopen (%SYMDB, $symdb, 0666);
X
X#
X# Gather up all of the ".a" files to parse.
X# Note that the regex in find is "lib*.a", since I explicity
X# want to avoid the Xenix [SML] libs.
X#
Xprint STDERR "Locating all archives, please be patient ..." unless $quiet;
X@archives = `find @libroots -type f -name "lib*.a" -print`;
Xprint STDERR " done\n" unless $quiet;
X
X#
X# Okay, lets take a look.
X# We open each archive in turn and add the archive name to
X# the list for each externally visible symbol.
X#
Xforeach $archive (@archives) {
X	%seen = ();		# to weed out duplicate symbols
X	chop $archive;
X	print STDERR "Processing $archive\n" unless $quiet;
X	open (NMOUT, "$nmcmd $archive|");
X
X	while (<NMOUT>) {
X		$symbol = '';
X		chop;
X		if (/^.*\s+[ATDS]\s+([^_.].*)/o) { $symbol = $1 };
X		next unless $symbol;
X		# weed out file names from shared libs
X		next if $symbol =~ m=^/shlib/=o;
X		# only one per archive, thank you
X		next if $seen{$symbol}++;
X		$SYMDB{$symbol} .= " $archive";
X		print STDERR "$symbol: $SYMDB{$symbol}\n" if $verbose;
X	}
X}
X
X#
X# And say bye
X#
Xdbmclose (SYMDB);
Xprint STDERR "Processing complete\n" unless $quiet;
Xexit 0;
X
X  #############################################################################
X  #                                                                           #
X  #  Copyright (c) 1992 Techne Research                                       #
X  #  Copyright (c) 1992 Joel Rosi-Schwartz                                    #
X  #  All rights reserved.                                                     #
X  #                                                                           #
X  #  Redistribution and use in source and binary forms, with or without       #
X  #  modification, are permitted provided that the following conditions       #
X  #  are met:                                                                 #
X  #  1. Redistributions of source code must retain the above copyright        #
X  #     notice, this list of conditions and the following disclaimer.         #
X  #  2. Redistributions in binary form must reproduce the above copyright     #
X  #     notice, this list of conditions and the following disclaimer in the   #
X  #     documentation and/or other materials provided with the distribution.  #
X  #  3. All advertising materials mentioning features or use of this software #
X  #     must display the following acknowledgement:                           #
X  #       This product includes software developed by the Techne Research     #
X  #  4. The name of Techne Research may not be used to endorse or promote     #
X  #     products derived from this software without specific prior written    #
X  #     permission.                                                           #
X  #                                                                           #
X  #  THIS SOFTWARE IS PROVIDED BY THE TECHNE RESEARCH (UK) ``AS IS'' AND      #
X  #  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE    #
X  #  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR       #
X  #  PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL COMDISCO SYSTEMS INC BE       #
X  #  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR      #
X  #  CONSEQUENTIAL #  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT     #
X  #  OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR       #
X  #  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,    #
X  #  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE     #
X  #  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,        #
X  #  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.                       #
X  #                                                                           #
X  # This copyright notice derived from material copyrighted by the Regents    #
X  # of the University of California.                                          #
X  #                                                                           #
X  #############################################################################
X
X#
END_OF_FILE
if test 7997 -ne `wc -c <'mksymdb'`; then
    echo shar: \"'mksymdb'\" unpacked with wrong size!
fi
chmod +x 'mksymdb'
# end of 'mksymdb'
fi
echo shar: End of archive 1 \(of 1\).
cp /dev/null ark1isdone
MISSING=""
for I in 1 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have the archive.
    rm -f ark[1-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0
-- 
     ==================================================================
     ||               T E C H N E   R E S E A R C H                  ||
     ||  ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++  ||
     ||                     Joel Rosi-Schwartz                       ||
     ||   Hildorien House            +   Email: joel@abigale.UUCP    ||
     ||   12 Waverley Way            +    (pyrltd!abigale.UUCP!joel) ||
     ||   Finchampstead, Wokingham   +   Phone: +44 (734) 730.260    ||
     ||   Berkshire RG11 4YD (UK)    +   Fax:   +44 (734) 730.272    ||
     ==================================================================