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'?
9 then EXTRANM
="cat $IPCVECS"
14 then echo "Usage: unstack <executable> [0x... [0x... ] ]"
18 # Check invocation mode
19 case "`basename $0`" in
21 echo "datasizes is obsolete; please use nm --size-sort instead."
37 if ! which gawk
>/dev
/null
2>&1
38 then echo "Please install gawk."
42 # Invoke binutils nm or ack nm?
43 if file $executable |
grep ELF
>/dev
/null
2>&1
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 }'
61 ) |
sort -x |
grep ' [Tt] [^.]' >$SYMLIST
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;