umount: getopt return value is int, not char
[minix.git] / commands / unstack / unstack.sh
blob0af45c9d34bb4acef5fe5813992b071d3453b7ea
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
52 $NM $executable | sed 's/^/0x/'
53 $EXTRANM | sed 's/^/0x/'
55 # Add shared libraries
56 ldd -f"%p %x\n" $executable 2>/dev/null | while read lib addr
57 do echo >&2 "Adding $lib at $addr"
58 nm -n $lib | sed 's/^/0x/' | grep ' [Tt] ' | \
59 gawk -v liboffset=$addr -v libname=$lib --non-decimal-data '{ printf "0x%lx %s %s[%s]\n", $1+liboffset, $2, $3, libname }'
60 done
61 ) | sort -x | grep ' [Tt] [^.]' >$SYMLIST
63 while [ $# -gt 0 ]
64 do gawk <$SYMLIST --non-decimal-data -v symoffset=$1 '
65 { if($1 > symoffset) { printf "%s+0x%x\n", name, symoffset-prevoffset; exit }
66 name=$3; prevoffset=$1;
68 shift
69 done
71 rm -f $SYMLIST
73 exit 1