[117] | 1 | #!/bin/bash |
---|
| 2 | |
---|
| 3 | #----------------------------------------------------------- |
---|
| 4 | # $Id: instruction_flow_diff.sh 117 2009-05-16 14:42:39Z rosiere $ |
---|
| 5 | #----------------------------------------------------------- |
---|
| 6 | |
---|
| 7 | #-----[ usage ]--------------------------------------------- |
---|
| 8 | function usage () |
---|
| 9 | { |
---|
| 10 | echo "Usage : ${0} file1 file2"; |
---|
| 11 | echo "Arguments : "; |
---|
| 12 | echo " * file1 : instruction flow file 1 (original)"; |
---|
| 13 | echo " * file2 : instruction flow file 2"; |
---|
| 14 | exit; |
---|
| 15 | } |
---|
| 16 | |
---|
| 17 | #-----[ test_usage ]---------------------------------------- |
---|
| 18 | function test_usage () |
---|
| 19 | { |
---|
| 20 | if test ${#} -ne 2; then |
---|
| 21 | usage ${*}; |
---|
| 22 | fi; |
---|
| 23 | |
---|
| 24 | if test ! -f ${1} -o ! -f ${2}; then |
---|
| 25 | usage ${*}; |
---|
| 26 | fi; |
---|
| 27 | } |
---|
| 28 | |
---|
| 29 | #-----[ main ]---------------------------------------------- |
---|
| 30 | function main () |
---|
| 31 | { |
---|
| 32 | test_usage ${*}; |
---|
| 33 | |
---|
| 34 | # Read symbol file and take function address and function name |
---|
| 35 | local -a array1_address; |
---|
| 36 | local -i cpt1; |
---|
| 37 | local -i cpt2; |
---|
| 38 | local address1; |
---|
| 39 | local address2; |
---|
| 40 | |
---|
| 41 | # Read instruction flow file 1 |
---|
| 42 | cpt1=0; |
---|
| 43 | while read line; do |
---|
| 44 | if test $(echo "${line}" |grep -c "OK") -gt 0; then |
---|
| 45 | # extract address |
---|
| 46 | address1=$(echo ${line} | cut -d' ' -f2); |
---|
| 47 | |
---|
| 48 | array1_address[${cpt1}]=${address1}; |
---|
| 49 | |
---|
| 50 | cpt1=$((${cpt1}+1)); |
---|
| 51 | fi; |
---|
| 52 | done < ${1}; |
---|
| 53 | |
---|
| 54 | # Read instruction flow file 2 and compare with flow 1 |
---|
| 55 | cpt1=0; |
---|
| 56 | cpt2=1; |
---|
| 57 | address1=${array1_address[${cpt1}]}; |
---|
| 58 | |
---|
| 59 | while read line; do |
---|
| 60 | if test $(echo "${line}" |grep -c "OK") -gt 0; then |
---|
| 61 | |
---|
| 62 | if test ${cpt1} -eq ${#array1_address[*]}; then |
---|
| 63 | echo "file \"${1}\" is empty, not file \"${2}\"."; |
---|
| 64 | exit; |
---|
| 65 | fi; |
---|
| 66 | |
---|
| 67 | # extract address |
---|
| 68 | address2=$(echo ${line} | cut -d' ' -f2); |
---|
| 69 | |
---|
| 70 | # test address |
---|
| 71 | if test "${address1}" != "${address2}"; then |
---|
| 72 | echo "diff line ${cpt2} :"; |
---|
| 73 | echo "${line}"; |
---|
| 74 | exit; |
---|
| 75 | fi; |
---|
| 76 | |
---|
| 77 | cpt1=$((${cpt1}+1)); |
---|
| 78 | address1=${array1_address[${cpt1}]}; |
---|
| 79 | |
---|
| 80 | fi; |
---|
| 81 | cpt2=$((${cpt2}+1)); |
---|
| 82 | done < ${2}; |
---|
| 83 | |
---|
| 84 | if test ${cpt1} -ne ${#array1_address[*]}; then |
---|
| 85 | echo "file \"${2}\" is empty, not file \"${1}\"."; |
---|
| 86 | exit; |
---|
| 87 | else |
---|
| 88 | echo "no diff."; |
---|
| 89 | fi; |
---|
| 90 | |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | #-----[ Corps ]--------------------------------------------- |
---|
| 94 | main ${*}; |
---|