minix/commands/unstack/unstack.sh

74 lines
1.3 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
# 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... ] ]"
echo " datasizes <executable>"
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)
mode=data
;;
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
2010-08-05 16:09:06 +02:00
# gnu nm can be gnm or nm
if which gnm >/dev/null 2>&1
then GNM=gnm
else GNM=nm
fi
# Invoke gnu nm or ack nm?
if file $executable | grep NSYM >/dev/null 2>&1
then NM="$GNM --radix=d"
2010-12-10 16:18:30 +01:00
elif file $executable | grep ELF >/dev/null 2>&1
then NM="$GNM --radix=d"
2010-08-05 16:09:06 +02:00
else NM="acknm -d"
fi
# Invoked as unstack?
if [ $mode = stack ]
then
while [ $# -gt 0 ]
do dec="`printf %d $1`"
$NM -n $executable | grep ' [Tt] [^.]' | awk '
{ if($1 > '$dec') { printf "%s+0x%x\n", name, '$dec'-offset; exit }
name=$3; offset=$1
}'
shift
done
exit 0
fi
# Invoked as datasizes?
if [ $mode = data ]
then
$NM -n $executable |
grep ' [bBdD] [^.]' | awk '{ if (lastpos) printf "%10ld kB %s\n", ($1-lastpos)/1024, lastname; lastpos=$1; lastname=$3 }' | sort -n
exit 0
fi
# Can't happen.
echo "Impossible invocation."
exit 1