mkfs, mkproto: minor improvements
[minix.git] / commands / unstack / unstack.sh
blob118913216108577f992459d0c2e25f5811c939b7
1 #!/bin/sh
3 # Look at /usr/pkg/bin first in case there is an old nm in /usr/bin
4 PATH=/usr/pkg/bin:$PATH:/usr/gnu/bin
6 # Does procfs give us some extra 'symbols'?
7 IPCVECS=/proc/ipcvecs
8 if [ -f $IPCVECS ]
9 then EXTRANM="cat $IPCVECS"
12 # Check usage
13 if [ $# -lt 1 ]
14 then echo "Usage: unstack <executable> [0x... [0x... ] ]"
15 exit 1
18 # Check invocation mode
19 case "`basename $0`" in
20 datasizes)
21 echo "datasizes is obsolete; please use nm --size-sort instead."
22 exit 1
24 unstack)
25 mode=stack
28 echo "Invoked as $0?"
29 exit 1
31 esac
33 # Get executable name
34 executable=$1
35 shift
37 if ! which gawk >/dev/null 2>&1
38 then echo "Please install gawk."
39 exit 1
42 # Invoke binutils nm or ack nm?
43 if file $executable | grep ELF >/dev/null 2>&1
44 then NM="nm"
45 else NM="acknm"
48 SYMLIST=/tmp/unstack.$$
50 # store sorted, filtered nm output once
51 ( $NM $executable ; $EXTRANM ) | sed 's/^/0x/' | sort -x | grep ' [Tt] [^.]' >$SYMLIST
53 while [ $# -gt 0 ]
54 do gawk <$SYMLIST --non-decimal-data -v symoffset=$1 '
55 { if($1 > symoffset) { printf "%s+0x%x\n", name, symoffset-prevoffset; exit }
56 name=$3; prevoffset=$1;
58 shift
59 done
61 rm -f $SYMLIST
63 exit 1