minix/commands/unstack/unstack.sh

65 lines
1.1 KiB
Bash
Raw Normal View History

2007-03-21 10:33:39 +01:00
#!/bin/sh
2010-08-05 16:09:06 +02:00
# Look at /usr/pkg/bin first in case there is an old nm in /usr/bin
PATH=/usr/pkg/bin:$PATH:/usr/gnu/bin
# Does procfs give us some extra 'symbols'?
IPCVECS=/proc/ipcvecs
if [ -f $IPCVECS ]
then EXTRANM="cat $IPCVECS"
fi
2010-08-05 16:09:06 +02:00
# Check usage
2007-03-21 10:33:39 +01:00
if [ $# -lt 1 ]
2010-08-05 16:09:06 +02:00
then echo "Usage: unstack <executable> [0x... [0x... ] ]"
2007-03-21 10:33:39 +01:00
exit 1
fi
2010-08-05 16:09:06 +02:00
# Check invocation mode
case "`basename $0`" in
datasizes)
echo "datasizes is obsolete; please use nm --size-sort instead."
exit 1
2010-08-05 16:09:06 +02:00
;;
unstack)
mode=stack
;;
*)
echo "Invoked as $0?"
exit 1
;;
esac
2010-08-05 16:09:06 +02:00
# Get executable name
2007-03-21 10:33:39 +01:00
executable=$1
shift
if ! which gawk >/dev/null 2>&1
then echo "Please install gawk."
exit 1
2010-08-05 16:09:06 +02:00
fi
# Invoke binutils nm or ack nm?
if file $executable | grep ELF >/dev/null 2>&1
then NM="nm"
else NM="acknm"
2010-08-05 16:09:06 +02:00
fi
SYMLIST=/tmp/unstack.$$
2010-08-05 16:09:06 +02:00
# store sorted, filtered nm output once
( $NM $executable ; $EXTRANM ) | sed 's/^/0x/' | sort -x | grep ' [Tt] [^.]' >$SYMLIST
2010-08-05 16:09:06 +02:00
while [ $# -gt 0 ]
do gawk <$SYMLIST --non-decimal-data -v symoffset=$1 '
{ if($1 > symoffset) { printf "%s+0x%x\n", name, symoffset-prevoffset; exit }
name=$3; prevoffset=$1;
}'
shift
done
2010-08-05 16:09:06 +02:00
rm -f $SYMLIST
2010-08-05 16:09:06 +02:00
exit 1