symbolize.sh (944B)
1 #!/bin/sh 2 3 # parse the .dot file and translate 4 # addresses to symbol names. 5 6 if [ ! -n "$1" ]; then 7 echo "Usage: `basename $0` bin" 1>&2 8 exit 1 9 fi 10 11 CGRAPH_OUT=$(test -n "$CGRAPH_OUT" && echo $CGRAPH_OUT || \ 12 echo callgraph.dot) 13 14 if [ ! -f "$CGRAPH_OUT" ]; then 15 echo "$CGRAPH_OUT does not exist!" 1>&2 16 exit 1 17 fi 18 19 # remove duplicate function calls 20 echo "digraph G {" > $CGRAPH_OUT.tmp 21 grep '\->' $CGRAPH_OUT | sort | uniq >> $CGRAPH_OUT.tmp 22 echo "}" >> $CGRAPH_OUT.tmp 23 mv $CGRAPH_OUT.tmp $CGRAPH_OUT 24 25 # do the translation 26 echo "digraph G {" > $CGRAPH_OUT.tmp 27 for i in `grep '\->' $CGRAPH_OUT | sed 's/[ \t]*//g' \ 28 | sed 's/"//g' | sed 's/\->/:/g'`; do 29 l=`echo $i | awk -F: '{print $1}'` 30 r=`echo $i | awk -F: '{print $2}'` 31 # could use addr2line here 32 l=`nm $1 | grep $l | awk '{print $3}'` 33 r=`nm $1 | grep $r | awk '{print $3}'` 34 echo -e "\t$l -> $r" >> $CGRAPH_OUT.tmp 35 done 36 echo "}" >> $CGRAPH_OUT.tmp 37 mv $CGRAPH_OUT.tmp $CGRAPH_OUT