From 56770462c2d38bd4c246ade8af6187583f69cbd3 Mon Sep 17 00:00:00 2001 From: Ben Gras Date: Thu, 5 Aug 2010 14:09:06 +0000 Subject: [PATCH] merge datasizes and unstack --- commands/Makefile | 2 +- commands/datasizes/Makefile | 4 -- commands/datasizes/datasizes.sh | 14 ------ commands/unstack/Makefile | 2 + commands/unstack/unstack.sh | 77 ++++++++++++++++++++++++++------- 5 files changed, 64 insertions(+), 35 deletions(-) delete mode 100644 commands/datasizes/Makefile delete mode 100644 commands/datasizes/datasizes.sh diff --git a/commands/Makefile b/commands/Makefile index 03de65826..978ccefb4 100644 --- a/commands/Makefile +++ b/commands/Makefile @@ -7,7 +7,7 @@ SUBDIR= aal add_route adduser advent arp ash at autil awk \ binpackages binsizes bzip2 bzip2recover cal calendar \ cat cawf cd cdprobe checkhier chmem \ chmod chown chroot ci cksum cleantmp clear cmp co \ - comm compress cp crc cron crontab cut datasizes date \ + comm compress cp crc cron crontab cut date \ dd de decomp16 DESCRIBE dev2name devsize df dhcpd \ dhrystone diff dirname dis88 du dumpcore easypack \ ed eject elle elvis env expand factor file \ diff --git a/commands/datasizes/Makefile b/commands/datasizes/Makefile deleted file mode 100644 index 95e6110cf..000000000 --- a/commands/datasizes/Makefile +++ /dev/null @@ -1,4 +0,0 @@ -SCRIPTS= datasizes.sh -MAN= - -.include diff --git a/commands/datasizes/datasizes.sh b/commands/datasizes/datasizes.sh deleted file mode 100644 index 2c45a672d..000000000 --- a/commands/datasizes/datasizes.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/sh - -if [ $# -ne 1 ] -then echo "Usage: $0 " - exit 1 -fi - -if file $1 | grep NSYM >/dev/null 2>&1; then - NM="gnm --radix=d" -else - NM="acknm -d" -fi - -$NM -n $1 | grep ' [bBdD] [^.]' | awk '{ if (lastpos) printf "%10ld kB %s\n", ($1-lastpos)/1024, lastname; lastpos=$1; lastname=$3 }' | sort -n diff --git a/commands/unstack/Makefile b/commands/unstack/Makefile index 13cbdce35..9527eb335 100644 --- a/commands/unstack/Makefile +++ b/commands/unstack/Makefile @@ -1,4 +1,6 @@ SCRIPTS= unstack.sh MAN= +LINKS+=$(BINDIR)/unstack $(BINDIR)/datasizes + .include diff --git a/commands/unstack/unstack.sh b/commands/unstack/unstack.sh index 648f76092..1be8c93c4 100644 --- a/commands/unstack/unstack.sh +++ b/commands/unstack/unstack.sh @@ -1,26 +1,71 @@ #!/bin/sh +# 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 if [ $# -lt 1 ] -then echo "Usage: $0 [0x... [0x... ] ]" +then echo "Usage: unstack [0x... [0x... ] ]" + echo " datasizes " exit 1 fi -PATH=$PATH:/usr/gnu/bin:/usr/pkg/bin - -if file $1 | grep NSYM >/dev/null 2>&1; then - NM="gnm --radix=d" -else - NM="acknm -d" -fi +# Check invocation mode +case "`basename $0`" in + datasizes) + mode=data + ;; + unstack) + mode=stack + ;; + *) + echo "Invoked as $0?" + exit 1 + ;; +esac +# Get executable name executable=$1 shift -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 +# 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" +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 + -- 2.44.0