1998-05-24 06:35:33 +08:00
#!/bin/sh
1998-10-31 16:30:53 +08:00
#
1998-05-24 06:35:33 +08:00
# This script parses the output of a gcc bootstrap when using warning
# flags and determines various statistics.
1998-10-31 16:30:53 +08:00
#
2000-12-15 04:09:41 +08:00
# usage: warn_summary [-llf] [-s stage] [-nosub|-ch|-cp|-f|-java|-intl|-fixinc]
1998-10-31 16:30:53 +08:00
# [-pass|-wpass] [file(s)]
#
# -llf
2001-07-01 18:25:32 +08:00
# Filter out long lines from the bootstrap output before any other
1998-10-31 16:30:53 +08:00
# action. This is useful for systems with broken awks/greps which choke
# on long lines. It is not done by default as it sometimes slows things
# down.
#
# -s number
# Take warnings from stage "Number". Stage 0 means show warnings from
# before and after the gcc bootstrap directory. E.g. libraries, etc.
# This presupposes using "gcc -W*" for the stage1 compiler.
#
# -nosub
# Only show warnings from the gcc top level directory.
2000-12-15 04:09:41 +08:00
# -ch|-cp|-f|-java|-intl|-fixinc
1998-10-31 16:30:53 +08:00
# Only show warnings from the specified language subdirectory.
2000-12-15 04:09:41 +08:00
# These override each other so only the last one passed takes effect.
1998-10-31 16:30:53 +08:00
#
# -pass
# Pass through the bootstrap output after filtering stage and subdir
# (useful for manual inspection.) This is all lines, not just warnings.
# -wpass
# Pass through only warnings from the bootstrap output after filtering
# stage and subdir.
1998-05-24 06:35:33 +08:00
#
# By Kaveh Ghazi (ghazi@caip.rutgers.edu) 12/13/97.
1998-10-31 16:30:53 +08:00
# Some awks choke on long lines, sed seems to do a better job.
# Truncate lines > 255 characters. RE '.\{255,\}' doesn't seem to work. :-(
# Only do this if -llf was specified, because it can really slow things down.
longLineFilter()
{
if test -z "$llf" ; then
2000-12-15 04:09:41 +08:00
cat
1998-10-31 16:30:53 +08:00
else
2000-12-15 04:09:41 +08:00
sed 's/^\(...............................................................................................................................................................................................................................................................\).*/\1/'
1998-10-31 16:30:53 +08:00
fi
}
1998-10-05 19:27:05 +08:00
# This function does one of three things. It either passes through
# all warning data, or passes through gcc toplevel warnings, or passes
# through a particular subdirectory set of warnings.
subdirectoryFilter()
{
2000-12-15 04:09:41 +08:00
longLineFilter | (
1998-10-31 16:30:53 +08:00
if test -z "$filter" ; then
1998-10-05 19:27:05 +08:00
# Pass through all lines.
1998-10-31 16:30:53 +08:00
cat
1998-10-05 19:27:05 +08:00
else
if test "$filter" = nosub ; then
# Omit all subdirectories.
2000-12-15 04:09:41 +08:00
egrep -v '/gcc/(ch|cp|f|java|intl|fixinc)/'
1998-10-05 19:27:05 +08:00
else
# Pass through only subdir $filter.
2000-12-15 04:09:41 +08:00
grep "/gcc/$filter/"
1998-10-05 19:27:05 +08:00
fi
1998-10-31 16:30:53 +08:00
fi )
1998-10-05 19:27:05 +08:00
}
1998-10-31 16:30:53 +08:00
# This function displays all lines from stageN of the bootstrap. If
# stage==0, then show lines prior to stage1 and lines from after the last
# stage. I.e. utilities, libraries, etc.
stageNfilter()
1998-05-24 06:35:33 +08:00
{
1998-10-31 16:30:53 +08:00
if test "$stageN" -lt 1 ; then
# stage "0" means check everything *but* gcc.
$AWK "BEGIN{t=1} ; /^Bootstrapping the compiler/{t=0} ; /^Building runtime libraries/{t=1} ; {if(t==1)print}"
else
if test "$stageN" -eq 1 ; then
$AWK "/^Bootstrapping the compiler|^Building the C and C\+\+ compiler/{t=1} ; /stage$stageN/{t=0} ; {if(t==1)print}"
else
stageNminus1=`expr $stageN - 1`
2001-01-16 01:53:57 +08:00
$AWK "/stage${stageNminus1}\//{t=1} ; /stage$stageN/{t=0} ; {if(t==1)print}"
1998-10-31 16:30:53 +08:00
fi
fi
}
# This function displays lines containing warnings.
warningFilter()
{
2000-12-15 04:09:41 +08:00
grep ' warning: '
1998-05-24 06:35:33 +08:00
}
1998-10-31 16:30:53 +08:00
# This function replaces `xxx' with `???', where xxx is usually some
# variable or function name. This allows similar warnings to be
# counted together when summarizing. However it avoids replacing
# certain C keywords which are known appear in various messages.
keywordFilter() {
sed 's/.*warning: //;
s/`\(int\)'"'"'/"\1"/g;
s/`\(long\)'"'"'/"\1"/g;
s/`\(char\)'"'"'/"\1"/g;
s/`\(inline\)'"'"'/"\1"/g;
s/`\(else\)'"'"'/"\1"/g;
s/`\(return\)'"'"'/"\1"/g;
s/`\(static\)'"'"'/"\1"/g;
s/`\(extern\)'"'"'/"\1"/g;
s/`\(const\)'"'"'/"\1"/g;
s/`\(noreturn\)'"'"'/"\1"/g;
s/`\(longjmp\)'"'"' or `\(vfork\)'"'"'/"\1" or "\2"/g;
s/`'"[^']*'/"'`???'"'/g;"'
s/.*format, .* arg (arg [0-9][0-9]*)/??? format, ??? arg (arg ???)/;
s/\([( ]\)arg [0-9][0-9]*\([) ]\)/\1arg ???\2/;
s/"\([^"]*\)"/`\1'"'"'/g'
}
2000-12-15 04:09:41 +08:00
# This function strips out relative pathnames for source files printed
# by the warningFilter function. This is done so that as the snapshot
# directory name changes every week, the output of this program can be
# compared to previous runs without spurious diffs caused by source
# directory name changes.
srcdirFilter()
{
sed '
s%^[^ ]*/\(gcc/\)%\1%;
s%^[^ ]*/\(include/\)%\1%;
s%^[^ ]*/\(texinfo/\)%\1%;
s%^[^ ]*/\(fastjar/\)%\1%;
s%^[^ ]*/\(zlib/\)%\1%;
s%^[^ ]*/\(lib[a-z23+-]*/\)%\1%;'
}
1998-10-31 16:30:53 +08:00
# Start the main section.
2000-12-15 04:09:41 +08:00
usage="usage: `basename $0` [-llf] [-s stage] [-nosub|-ch|-cp|-f|-java|-intl|-fixinc] [-pass|-wpass] [file(s)]"
1998-06-01 08:26:36 +08:00
stageN=3
1998-10-31 16:30:53 +08:00
tmpfile=/tmp/tmp-warn.$$
# Remove $tmpfile on exit and various signals.
trap "rm -f $tmpfile" 0
trap "rm -f $tmpfile ; exit 1" 1 2 3 5 9 13 15
1998-06-01 08:26:36 +08:00
1998-05-24 06:35:33 +08:00
# Find a good awk.
if test -z "$AWK" ; then
for AWK in gawk nawk awk ; do
if type $AWK 2>&1 | grep 'not found' > /dev/null 2>&1 ; then
:
else
break
fi
done
fi
1998-10-31 16:30:53 +08:00
# Parse command line arguments.
1998-06-01 08:26:36 +08:00
while test -n "$1" ; do
case "$1" in
1998-10-31 16:30:53 +08:00
-llf) llf=1 ; shift ;;
2000-12-15 04:09:41 +08:00
-s) if test -z "$2"; then echo $usage 1>&2; exit 1; fi
stageN="$2"; shift 2 ;;
1998-06-01 08:26:36 +08:00
-s*) stageN="`expr $1 : '-s\(.*\)'`" ; shift ;;
2000-12-15 04:09:41 +08:00
-nosub|-ch|-cp|-f|-java|-intl|-fixinc) filter="`expr $1 : '-\(.*\)'`" ; shift ;;
1998-10-31 16:30:53 +08:00
-pass) pass=1 ; shift ;;
-wpass) pass=w ; shift ;;
2000-12-15 04:09:41 +08:00
-*) echo $usage 1>&2 ; exit 1 ;;
1998-06-01 08:26:36 +08:00
*) break ;;
esac
done
1998-10-05 19:27:05 +08:00
# Check for a valid value of $stageN.
case "$stageN" in
1998-10-31 16:30:53 +08:00
[0-9]) ;;
2000-12-15 04:09:41 +08:00
*) echo "Stage <$stageN> must be in the range [0..9]." 1>&2 ; exit 1 ;;
1998-10-05 19:27:05 +08:00
esac
1998-06-01 08:26:36 +08:00
1998-05-24 06:35:33 +08:00
for file in "$@" ; do
2000-12-15 04:09:41 +08:00
stageNfilter < $file | subdirectoryFilter > $tmpfile
1998-10-31 16:30:53 +08:00
# (Just) show me the warnings.
if test "$pass" != '' ; then
if test "$pass" = w ; then
2000-12-15 04:09:41 +08:00
warningFilter < $tmpfile
1998-10-31 16:30:53 +08:00
else
cat $tmpfile
fi
continue
fi
if test -z "$filter" ; then
1998-10-05 19:27:05 +08:00
echo "Counting all warnings,"
else
if test "$filter" = nosub ; then
echo "Counting non-subdirectory warnings,"
else
echo "Counting warnings in the gcc/$filter subdirectory,"
fi
fi
2000-12-15 04:09:41 +08:00
count=`warningFilter < $tmpfile | wc -l`
1998-10-05 19:27:05 +08:00
echo there are $count warnings in stage$stageN of this bootstrap.
1998-05-24 06:35:33 +08:00
echo
echo Number of warnings per file:
2000-12-15 04:09:41 +08:00
warningFilter < $tmpfile | srcdirFilter | $AWK -F: '{print$1}' | sort | \
uniq -c | sort -nr
1998-05-24 06:35:33 +08:00
echo
echo Number of warning types:
2000-12-15 04:09:41 +08:00
warningFilter < $tmpfile | keywordFilter | sort | uniq -c | sort -nr
1998-05-24 06:35:33 +08:00
done