1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/common/bin/diffexec.sh Tue Apr 10 08:18:28 2012 -0700 1.3 @@ -0,0 +1,150 @@ 1.4 +#!/bin/bash 1.5 +# 1.6 +# Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 1.7 +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 +# 1.9 +# This code is free software; you can redistribute it and/or modify it 1.10 +# under the terms of the GNU General Public License version 2 only, as 1.11 +# published by the Free Software Foundation. 1.12 +# 1.13 +# This code is distributed in the hope that it will be useful, but WITHOUT 1.14 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.15 +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.16 +# version 2 for more details (a copy is included in the LICENSE file that 1.17 +# accompanied this code). 1.18 +# 1.19 +# You should have received a copy of the GNU General Public License version 1.20 +# 2 along with this work; if not, write to the Free Software Foundation, 1.21 +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.22 +# 1.23 +# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.24 +# or visit www.oracle.com if you need additional information or have any 1.25 +# questions. 1.26 +# 1.27 + 1.28 +if [ $# -lt 2 ] 1.29 +then 1.30 + echo "Diff two executables. Return codes:" 1.31 + echo "0 - no diff" 1.32 + echo "1 - Identical symbols AND size, BUT not bytewise identical" 1.33 + echo "2 - Identical symbols BUT NEW size" 1.34 + echo "3 - Differences, content BUT SAME size" 1.35 + echo "4 - Differences, content AND size" 1.36 + echo "10 - Could not perform diff" 1.37 + echo "Use 'quiet' to disable any output." 1.38 + echo "Syntax: $0 file1 file2 [quiet]" 1.39 + exit 10 1.40 +fi 1.41 + 1.42 +if [ ! -f $1 ] 1.43 +then 1.44 + echo $1 does not exist 1.45 + exit 10 1.46 +fi 1.47 + 1.48 +if [ ! -f $2 ] 1.49 +then 1.50 + echo $2 does not exist 1.51 + exit 10 1.52 +fi 1.53 + 1.54 +if [ "`uname`" == "SunOS" ]; then 1.55 + NM=gnm 1.56 + STAT=gstat 1.57 +elif [ $OSTYPE == "cygwin" ]; then 1.58 + NM="$VS100COMNTOOLS/../../VC/bin/amd64/dumpbin.exe" 1.59 + NM_ARGS=/exports 1.60 + STAT=stat 1.61 +else 1.62 + NM=nm 1.63 + STAT=stat 1.64 +fi 1.65 + 1.66 +# Should the differences be viewed? 1.67 +VIEW= 1.68 +# You can do export DIFF=meld to view 1.69 +# any differences using meld instead. 1.70 +if [ -n "$DIFF" ]; then 1.71 + DIFF="$DIFF" 1.72 +else 1.73 + DIFF=diff 1.74 +fi 1.75 +OLD=$(cd $(dirname $1) && pwd)/$(basename $1) 1.76 +NEW=$(cd $(dirname $2) && pwd)/$(basename $2) 1.77 + 1.78 +OLD_SIZE=$($STAT -c%s "$OLD") 1.79 +NEW_SIZE=$($STAT -c%s "$NEW") 1.80 + 1.81 +if [ $# -gt 3 ] 1.82 +then 1.83 + ROOT1=$(cd $3 && pwd) 1.84 + ROOT2=$(cd $4 && pwd) 1.85 + OLD_NAME=$(echo $OLD | sed "s|$ROOT1/||") 1.86 + NEW_NAME=$(echo $NEW | sed "s|$ROOT2/||") 1.87 + if [ "x$5" == "xview" ]; then VIEW=view; fi 1.88 +else 1.89 + ROOT1=$(dirname $OLD)/ 1.90 + ROOT2=$(dirname $NEW)/ 1.91 + OLD_NAME=$OLD 1.92 + NEW_NAME=$NEW 1.93 + if [ "x$3" == "xview" ]; then VIEW=view; fi 1.94 +fi 1.95 + 1.96 +if cmp $OLD $NEW > /dev/null 1.97 +then 1.98 + # The files were bytewise identical. 1.99 + echo Identical: $OLD_NAME 1.100 + exit 0 1.101 +fi 1.102 + 1.103 +OLD_SYMBOLS=$COMPARE_ROOT/$OLD_NAME.old 1.104 +NEW_SYMBOLS=$COMPARE_ROOT/$NEW_NAME.new 1.105 + 1.106 +mkdir -p $(dirname $OLD_SYMBOLS) 1.107 +mkdir -p $(dirname $NEW_SYMBOLS) 1.108 + 1.109 +if [ $OSTYPE == "cygwin" ]; then 1.110 + "$NM" $NM_ARGS $OLD | grep " = " > $OLD_SYMBOLS 1.111 + "$NM" $NM_ARGS $NEW | grep " = " > $NEW_SYMBOLS 1.112 + "$NM" $NM_ARGS $OLD > $OLD_SYMBOLS.full 1.113 + "$NM" $NM_ARGS $NEW > $NEW_SYMBOLS.full 1.114 +else 1.115 + # Strip the addresses, just compare the ordering of the symbols. 1.116 + $NM $OLD | cut -f 2- -d ' ' > $OLD_SYMBOLS 1.117 + $NM $NEW | cut -f 2- -d ' ' > $NEW_SYMBOLS 1.118 + # But store the full information for easy diff access. 1.119 + $NM $OLD > $OLD_SYMBOLS.full 1.120 + $NM $NEW > $NEW_SYMBOLS.full 1.121 +fi 1.122 + 1.123 +DIFFS=$(LANG=C diff $OLD_SYMBOLS $NEW_SYMBOLS) 1.124 + 1.125 +RESULT=0 1.126 + 1.127 +if [ -n "$DIFFS" ]; then 1.128 + if [ $OLD_SIZE -ne $NEW_SIZE ] 1.129 + then 1.130 + echo Differences, content AND size : $OLD_NAME 1.131 + RESULT=4 1.132 + else 1.133 + echo Differences, content BUT SAME size: $OLD_NAME 1.134 + RESULT=3 1.135 + fi 1.136 + if [ "x$VIEW" == "xview" ]; then 1.137 + LANG=C $DIFF $OLD_SYMBOLS $NEW_SYMBOLS 1.138 + fi 1.139 +else 1.140 + if [ $OLD_SIZE -ne $NEW_SIZE ] 1.141 + then 1.142 + echo Identical symbols BUT NEW size : $OLD_NAME 1.143 + RESULT=2 1.144 + else 1.145 + echo Identical symbols AND size, BUT not bytewise identical: $OLD_NAME 1.146 + RESULT=1 1.147 + fi 1.148 +fi 1.149 + 1.150 +exit $RESULT 1.151 + 1.152 + 1.153 +