import-trace: import symbol size if available

Instead of using the address difference between two neighboring symbols as
an indication for the symbol's size, import the size as reported by
`nm -S'.

Additionally, this change fixes an off-by-one, which had the effect that
the last symbol in the list was not imported at all.

Change-Id: I3c8e139b788018702526bb968e36d248dc3fe8fc
This commit is contained in:
Horst Schirmeier
2016-02-14 14:41:10 +01:00
parent cae6860e4e
commit 927d6a5103

View File

@ -48,10 +48,20 @@ EOT
LAST_ADDR=
LAST_SYMBOL=
nm -n -C $ELF | egrep '^[0-9a-fA-F]' | while read line
# The "dummy" entry at the end makes sure the last real symbol from the
# nm output makes it into the database.
(nm -n -S -C $ELF; echo ffffffff a dummy) \
| egrep '^[0-9a-fA-F]' | while read line
do
ADDR=$(echo "$line"|awk '{print $1}')
SYMBOL=$(echo "$line"|awk '{for (i=1; i<=NF-2; i++) $i = $(i+2); NF-=2; print}')
SIZE=$(echo "$line"|awk '{print $2}')
if echo $SIZE | egrep -q '^[0-9a-fA-F]{8}'; then
SYMBOL=$(echo "$line"|awk '{for (i=1; i<=NF-3; i++) $i = $(i+3); NF-=3; print}')
else
SIZE=unknown
SYMBOL=$(echo "$line"|awk '{for (i=1; i<=NF-2; i++) $i = $(i+2); NF-=2; print}')
fi
if [ $LAST_ADDR ]; then
# only create INSERT-line, if $ADDR is new to us
@ -60,8 +70,16 @@ EOT
echo "($ID, cast(0x$LAST_ADDR AS UNSIGNED), CAST(0x$ADDR AS UNSIGNED)-CAST(0x$LAST_ADDR AS UNSIGNED), '$LAST_SYMBOL');"
fi
fi
LAST_ADDR=$ADDR
LAST_SYMBOL=$SYMBOL
if [ $SIZE != unknown ]; then
echo "INSERT INTO $TABLE (variant_id, address, size, name) VALUES "
echo "($ID, cast(0x$ADDR AS UNSIGNED), CAST(0x$SIZE AS UNSIGNED), '$SYMBOL');"
LAST_ADDR=
LAST_SYMBOL=
else
LAST_ADDR=$ADDR
LAST_SYMBOL=$SYMBOL
fi
done
) | $MYSQL