11844Swollman#!/bin/sh 250476Speter# 31844Swollman# This script parses the output of a gcc bootstrap when using warning 41638Srgrimes# flags and determines various statistics. 594940Sru# 61638Srgrimes# usage: warn_summary [-llf] [-s stage] [-nosub|-ch|-cp|-f|-java] 742915Sjdp# [-pass|-wpass] [file(s)] 842915Sjdp# 942915Sjdp# -llf 1042915Sjdp# Filter out long lines from the bootstap output before any other 1142915Sjdp# action. This is useful for systems with broken awks/greps which choke 1242915Sjdp# on long lines. It is not done by default as it sometimes slows things 1342915Sjdp# down. 1442915Sjdp# 1599362Sru# -s number 1642915Sjdp# Take warnings from stage "Number". Stage 0 means show warnings from 1729141Speter# before and after the gcc bootstrap directory. E.g. libraries, etc. 18125119Sru# This presupposes using "gcc -W*" for the stage1 compiler. 19100332Sru# 20100332Sru# -nosub 2142915Sjdp# Only show warnings from the gcc top level directory. 2242915Sjdp# -ch|-cp|-f|-java 2329141Speter# Only show warnings from the specified language subdirectory. 24119607Sru# These flags assume the output contains "Entering/Leaving" messages from 25117034Sgordon# gnu make. They override each other so only the last one takes effect. 26119607Sru# 27117034Sgordon# -pass 282827Sjkh# Pass through the bootstrap output after filtering stage and subdir 292827Sjkh# (useful for manual inspection.) This is all lines, not just warnings. 302827Sjkh# -wpass 312827Sjkh# Pass through only warnings from the bootstrap output after filtering 322827Sjkh# stage and subdir. 331638Srgrimes# 342827Sjkh# By Kaveh Ghazi (ghazi@caip.rutgers.edu) 12/13/97. 351638Srgrimes 3618529Sbde 3718529Sbde# Some awks choke on long lines, sed seems to do a better job. 381638Srgrimes# Truncate lines > 255 characters. RE '.\{255,\}' doesn't seem to work. :-( 3942450Sjdp# Only do this if -llf was specified, because it can really slow things down. 401638SrgrimeslongLineFilter() 41117173Sru{ 421638Srgrimes if test -z "$llf" ; then 4396512Sru cat $1 4496512Sru else 4596512Sru sed 's/^\(...............................................................................................................................................................................................................................................................\).*/\1/' $1 4696512Sru fi 4796512Sru} 4896512Sru 4996512Sru# This function does one of three things. It either passes through 5096512Sru# all warning data, or passes through gcc toplevel warnings, or passes 511638Srgrimes# through a particular subdirectory set of warnings. 5224761SjdpsubdirectoryFilter() 531638Srgrimes{ 5442450Sjdp longLineFilter $1 | ( 551844Swollman if test -z "$filter" ; then 561844Swollman # Pass through all lines. 5736673Sdt cat 5824761Sjdp else 591844Swollman if test "$filter" = nosub ; then 6042450Sjdp # Omit all subdirectories. 611844Swollman $AWK 'BEGIN{t=1} ; /Entering directory.*\/gcc\/[a-z]/{t--} ; /Leaving directory.*\/gcc\/[a-z]/{t++} ; {if(t==1)print}' 621844Swollman else 631844Swollman # Pass through only subdir $filter. 6424761Sjdp $AWK "BEGIN {t=-1} ; /^cd $filter; make/{t=0} ; /Entering directory .*\/gcc\/$filter/{t++} ; /Leaving directory .*\/gcc\/$filter/{t--} ; {if(t==1)print}" 651844Swollman fi 6642450Sjdp fi ) 671844Swollman} 681844Swollman 6936054Sbde# This function displays all lines from stageN of the bootstrap. If 7036054Sbde# stage==0, then show lines prior to stage1 and lines from after the last 7136054Sbde# stage. I.e. utilities, libraries, etc. 7242450SjdpstageNfilter() 7336054Sbde{ 7436054Sbde if test "$stageN" -lt 1 ; then 75117173Sru # stage "0" means check everything *but* gcc. 76117159Sru $AWK "BEGIN{t=1} ; /^Bootstrapping the compiler/{t=0} ; /^Building runtime libraries/{t=1} ; {if(t==1)print}" 771638Srgrimes else 78117173Sru if test "$stageN" -eq 1 ; then 79117173Sru $AWK "/^Bootstrapping the compiler|^Building the C and C\+\+ compiler/{t=1} ; /stage$stageN/{t=0} ; {if(t==1)print}" 80117173Sru else 81117173Sru stageNminus1=`expr $stageN - 1` 82117173Sru $AWK "/stage$stageNminus1/{t=1} ; /stage$stageN/{t=0} ; {if(t==1)print}" 83117173Sru fi 84117173Sru fi 851844Swollman} 86117122Sru 871844Swollman# This function displays lines containing warnings. 8842450SjdpwarningFilter() 89117122Sru{ 901844Swollman grep ' warning: ' $1 9196512Sru} 921638Srgrimes 9399362Sru# This function replaces `xxx' with `???', where xxx is usually some 9499362Sru# variable or function name. This allows similar warnings to be 9599362Sru# counted together when summarizing. However it avoids replacing 9699362Sru# certain C keywords which are known appear in various messages. 9796512Sru 9896512SrukeywordFilter() { 991638Srgrimes sed 's/.*warning: //; 10096512Sru s/`\(int\)'"'"'/"\1"/g; 10196512Sru s/`\(long\)'"'"'/"\1"/g; 10296512Sru s/`\(char\)'"'"'/"\1"/g; 10396512Sru s/`\(inline\)'"'"'/"\1"/g; 10496512Sru s/`\(else\)'"'"'/"\1"/g; 10599362Sru s/`\(return\)'"'"'/"\1"/g; 1061638Srgrimes s/`\(static\)'"'"'/"\1"/g; 10796512Sru s/`\(extern\)'"'"'/"\1"/g; 10895114Sobrien s/`\(const\)'"'"'/"\1"/g; 10999362Sru s/`\(noreturn\)'"'"'/"\1"/g; 11096512Sru s/`\(longjmp\)'"'"' or `\(vfork\)'"'"'/"\1" or "\2"/g; 11196512Sru s/`'"[^']*'/"'`???'"'/g;"' 11295306Sru s/.*format, .* arg (arg [0-9][0-9]*)/??? format, ??? arg (arg ???)/; 11396512Sru s/\([( ]\)arg [0-9][0-9]*\([) ]\)/\1arg ???\2/; 11496512Sru s/"\([^"]*\)"/`\1'"'"'/g' 11596512Sru} 11696512Sru 11796512Sru 11874805Sru# Start the main section. 1191844Swollman 12099362Sruusage="usage: `basename $0` [-llf] [-s stage] [-nosub|-ch|-cp|-f|-java] [-pass|-wpass] [file(s)]" 12199362SrustageN=3 12296512Srutmpfile=/tmp/tmp-warn.$$ 12399362Sru 1241844Swollman# Remove $tmpfile on exit and various signals. 12596512Srutrap "rm -f $tmpfile" 0 12696512Srutrap "rm -f $tmpfile ; exit 1" 1 2 3 5 9 13 15 1271638Srgrimes 12842915Sjdp# Find a good awk. 12942915Sjdpif test -z "$AWK" ; then 13096512Sru for AWK in gawk nawk awk ; do 13142915Sjdp if type $AWK 2>&1 | grep 'not found' > /dev/null 2>&1 ; then 13296512Sru : 13342915Sjdp else 13496343Sobrien break 13596512Sru fi 13691011Sru done 13728945Speterfi 1381844Swollman 13999362Sru# Parse command line arguments. 14096512Sruwhile test -n "$1" ; do 14196512Sru case "$1" in 14296512Sru -llf) llf=1 ; shift ;; 1432353Sbde -s) if test -z "$2"; then echo $usage; exit 1; fi; stageN="$2"; shift 2 ;; 14496512Sru -s*) stageN="`expr $1 : '-s\(.*\)'`" ; shift ;; 14596512Sru -nosub|-ch|-cp|-f|-java) filter="`expr $1 : '-\(.*\)'`" ; shift ;; 14696512Sru -pass) pass=1 ; shift ;; 1473859Sbde -wpass) pass=w ; shift ;; 1481844Swollman -*) echo $usage ; exit 1 ;; 149103713Smarkm *) break ;; 15096512Sru esac 15196512Srudone 15296512Sru 15396512Sru# Check for a valid value of $stageN. 15492491Smarkmcase "$stageN" in 15596512Sru [0-9]) ;; 15696512Sru *) echo "Stage <$stageN> must be in the range [0..9]." ; exit 1 ;; 15792491Smarkmesac 15892491Smarkm 1591638Srgrimesfor file in "$@" ; do 16096512Sru 16196512Sru subdirectoryFilter $file | stageNfilter > $tmpfile 16296512Sru 16396512Sru # (Just) show me the warnings. 16496512Sru if test "$pass" != '' ; then 16596512Sru if test "$pass" = w ; then 1661638Srgrimes warningFilter $tmpfile 1671638Srgrimes else 16834179Sbde cat $tmpfile 16924750Sbde fi 17042450Sjdp continue 17124750Sbde fi 17224750Sbde 17342915Sjdp if test -z "$filter" ; then 17431809Sbde echo "Counting all warnings," 17542915Sjdp else 17627910Sasami if test "$filter" = nosub ; then 17728945Speter echo "Counting non-subdirectory warnings," 1781638Srgrimes else 1791638Srgrimes echo "Counting warnings in the gcc/$filter subdirectory," 1801638Srgrimes fi 18148204Sjmg fi 1822298Swollman count=`warningFilter $tmpfile | wc -l` 1832298Swollman echo there are $count warnings in stage$stageN of this bootstrap. 1842298Swollman 18549328Shoek echo 18649328Shoek echo Number of warnings per file: 18749328Shoek warningFilter $tmpfile | $AWK -F: '{print$1}' | sort | uniq -c | sort -nr 18849328Shoek 18956971Sru echo 19049328Shoek echo Number of warning types: 19149328Shoek warningFilter $tmpfile | keywordFilter | sort | uniq -c | sort -nr 19249328Shoek 19349328Shoekdone 19499362Sru