warn_summary revision 1.1 1 1.1 mrg #!/bin/sh
2 1.1 mrg #
3 1.1 mrg # This script parses the output of a gcc bootstrap when using warning
4 1.1 mrg # flags and determines various statistics.
5 1.1 mrg #
6 1.1 mrg # usage: warn_summary [-llf] [-s stage] [-nosub|-ch|-cp|-f|-fortran|-java|-ada|-intl|-fixinc]
7 1.1 mrg # [-pass|-wpass] [file(s)]
8 1.1 mrg #
9 1.1 mrg # -llf
10 1.1 mrg # Filter out long lines from the bootstrap output before any other
11 1.1 mrg # action. This is useful for systems with broken awks/greps which choke
12 1.1 mrg # on long lines. It is not done by default as it sometimes slows things
13 1.1 mrg # down.
14 1.1 mrg #
15 1.1 mrg # -s number
16 1.1 mrg # Take warnings from stage "Number". Stage 0 means show warnings from
17 1.1 mrg # before and after the gcc bootstrap directory. E.g. libraries, etc.
18 1.1 mrg # This presupposes using "gcc -W*" for the stage1 compiler.
19 1.1 mrg #
20 1.1 mrg # -nosub
21 1.1 mrg # Only show warnings from the gcc top level directory.
22 1.1 mrg # -ch|-cp|-f|-fortran|-java|-ada|-intl|-fixinc
23 1.1 mrg # Only show warnings from the specified gcc subdirectory.
24 1.1 mrg # These override each other so only the last one passed takes effect.
25 1.1 mrg #
26 1.1 mrg # -pass
27 1.1 mrg # Pass through the bootstrap output after filtering stage and subdir
28 1.1 mrg # (useful for manual inspection.) This is all lines, not just warnings.
29 1.1 mrg # -wpass
30 1.1 mrg # Pass through only warnings from the bootstrap output after filtering
31 1.1 mrg # stage and subdir.
32 1.1 mrg #
33 1.1 mrg # By Kaveh Ghazi (ghazi (at] caip.rutgers.edu) 12/13/97.
34 1.1 mrg
35 1.1 mrg
36 1.1 mrg # Some awks choke on long lines, sed seems to do a better job.
37 1.1 mrg # Truncate lines > 255 characters. RE '.\{255,\}' doesn't seem to work. :-(
38 1.1 mrg # Only do this if -llf was specified, because it can really slow things down.
39 1.1 mrg longLineFilter()
40 1.1 mrg {
41 1.1 mrg if test -z "$llf" ; then
42 1.1 mrg cat
43 1.1 mrg else
44 1.1 mrg sed 's/^\(...............................................................................................................................................................................................................................................................\).*/\1/'
45 1.1 mrg fi
46 1.1 mrg }
47 1.1 mrg
48 1.1 mrg # This function does one of three things. It either passes through
49 1.1 mrg # all warning data, or passes through gcc toplevel warnings, or passes
50 1.1 mrg # through a particular subdirectory set of warnings.
51 1.1 mrg subdirectoryFilter()
52 1.1 mrg {
53 1.1 mrg longLineFilter | (
54 1.1 mrg if test -z "$filter" ; then
55 1.1 mrg # Pass through all lines.
56 1.1 mrg cat
57 1.1 mrg else
58 1.1 mrg if test "$filter" = nosub ; then
59 1.1 mrg # Omit all subdirectories.
60 1.1 mrg egrep -v '/gcc/(ch|cp|f|fortran|java|ada|intl|fixinc)/'
61 1.1 mrg else
62 1.1 mrg # Pass through only subdir $filter.
63 1.1 mrg grep "/gcc/$filter/"
64 1.1 mrg fi
65 1.1 mrg fi )
66 1.1 mrg }
67 1.1 mrg
68 1.1 mrg # This function displays all lines from stageN of the bootstrap. If
69 1.1 mrg # stage==0, then show lines prior to stage1 and lines from after the last
70 1.1 mrg # stage. I.e. utilities, libraries, etc.
71 1.1 mrg stageNfilter()
72 1.1 mrg {
73 1.1 mrg if test "$stageN" -lt 1 ; then
74 1.1 mrg # stage "0" means check everything *but* gcc.
75 1.1 mrg $AWK "BEGIN{t=1} ; /^Bootstrapping the compiler/{t=0} ; /^Building runtime libraries/{t=1} ; {if(t==1)print}"
76 1.1 mrg else
77 1.1 mrg if test "$stageN" -eq 1 ; then
78 1.1 mrg $AWK "/^Bootstrapping the compiler|^Building the C and C\+\+ compiler/{t=1} ; /stage$stageN/{t=0} ; {if(t==1)print}"
79 1.1 mrg else
80 1.1 mrg stageNminus1=`expr $stageN - 1`
81 1.1 mrg $AWK "/stage${stageNminus1}\//{t=1} ; /stage$stageN/{t=0} ; {if(t==1)print}"
82 1.1 mrg fi
83 1.1 mrg fi
84 1.1 mrg }
85 1.1 mrg
86 1.1 mrg # This function displays lines containing warnings.
87 1.1 mrg warningFilter()
88 1.1 mrg {
89 1.1 mrg grep ' warning: '
90 1.1 mrg }
91 1.1 mrg
92 1.1 mrg # This function replaces `xxx' with `???', where xxx is usually some
93 1.1 mrg # variable or function name. This allows similar warnings to be
94 1.1 mrg # counted together when summarizing. However it avoids replacing
95 1.1 mrg # certain C keywords which are known appear in various messages.
96 1.1 mrg
97 1.1 mrg keywordFilter() {
98 1.1 mrg sed 's/.*warning: //;
99 1.1 mrg s/`\(int\)'"'"'/"\1"/g;
100 1.1 mrg s/`\(long\)'"'"'/"\1"/g;
101 1.1 mrg s/`\(char\)'"'"'/"\1"/g;
102 1.1 mrg s/`\(inline\)'"'"'/"\1"/g;
103 1.1 mrg s/`\(else\)'"'"'/"\1"/g;
104 1.1 mrg s/`\(return\)'"'"'/"\1"/g;
105 1.1 mrg s/`\(static\)'"'"'/"\1"/g;
106 1.1 mrg s/`\(extern\)'"'"'/"\1"/g;
107 1.1 mrg s/`\(const\)'"'"'/"\1"/g;
108 1.1 mrg s/`\(noreturn\)'"'"'/"\1"/g;
109 1.1 mrg s/`\(longjmp\)'"'"' or `\(vfork\)'"'"'/"\1" or "\2"/g;
110 1.1 mrg s/'"[\`'][^']*'/"'"???"/g;
111 1.1 mrg s/.*format, .* arg (arg [0-9][0-9]*)/??? format, ??? arg (arg ???)/;
112 1.1 mrg s/\([( ]\)arg [0-9][0-9]*\([) ]\)/\1arg ???\2/;
113 1.1 mrg s/"\([^"]*\)"/`\1'"'"'/g'
114 1.1 mrg }
115 1.1 mrg
116 1.1 mrg # This function strips out relative pathnames for source files printed
117 1.1 mrg # by the warningFilter function. This is done so that as the snapshot
118 1.1 mrg # directory name changes every week, the output of this program can be
119 1.1 mrg # compared to previous runs without spurious diffs caused by source
120 1.1 mrg # directory name changes.
121 1.1 mrg
122 1.1 mrg srcdirFilter()
123 1.1 mrg {
124 1.1 mrg sed '
125 1.1 mrg s%^[^ ]*/\(gcc/\)%\1%;
126 1.1 mrg s%^[^ ]*/\(include/\)%\1%;
127 1.1 mrg s%^[^ ]*/\(texinfo/\)%\1%;
128 1.1 mrg s%^[^ ]*/\(fastjar/\)%\1%;
129 1.1 mrg s%^[^ ]*/\(zlib/\)%\1%;
130 1.1 mrg s%^[^ ]*/\(fixincludes/\)%\1%;
131 1.1 mrg s%^[^ ]*/\(sim/\)%\1%;
132 1.1 mrg s%^[^ ]*/\(newlib/\)%\1%;
133 1.1 mrg s%^[^ ]*/\(mpfr/\)%\1%;
134 1.1 mrg s%^[^ ]*/\(lib[a-z23+-]*/\)%\1%;'
135 1.1 mrg }
136 1.1 mrg
137 1.1 mrg # Start the main section.
138 1.1 mrg
139 1.1 mrg usage="usage: `basename $0` [-llf] [-s stage] [-nosub|-ch|-cp|-f|-fortran|-java|-ada|-intl|-fixinc] [-pass|-wpass] [file(s)]"
140 1.1 mrg stageN=3
141 1.1 mrg tmpfile=/tmp/tmp-warn.$$
142 1.1 mrg
143 1.1 mrg # Remove $tmpfile on exit and various signals.
144 1.1 mrg trap "rm -f $tmpfile" 0
145 1.1 mrg trap "rm -f $tmpfile ; exit 1" 1 2 3 5 9 13 15
146 1.1 mrg
147 1.1 mrg # Find a good awk.
148 1.1 mrg if test -z "$AWK" ; then
149 1.1 mrg for AWK in gawk nawk awk ; do
150 1.1 mrg if type $AWK 2>&1 | grep 'not found' > /dev/null 2>&1 ; then
151 1.1 mrg :
152 1.1 mrg else
153 1.1 mrg break
154 1.1 mrg fi
155 1.1 mrg done
156 1.1 mrg fi
157 1.1 mrg
158 1.1 mrg # Parse command line arguments.
159 1.1 mrg while test -n "$1" ; do
160 1.1 mrg case "$1" in
161 1.1 mrg -llf) llf=1 ; shift ;;
162 1.1 mrg -s) if test -z "$2"; then echo $usage 1>&2; exit 1; fi
163 1.1 mrg stageN="$2"; shift 2 ;;
164 1.1 mrg -s*) stageN="`expr $1 : '-s\(.*\)'`" ; shift ;;
165 1.1 mrg -nosub|-ch|-cp|-f|-fortran|-java|-ada|-intl|-fixinc) filter="`expr $1 : '-\(.*\)'`" ; shift ;;
166 1.1 mrg -pass) pass=1 ; shift ;;
167 1.1 mrg -wpass) pass=w ; shift ;;
168 1.1 mrg -*) echo $usage 1>&2 ; exit 1 ;;
169 1.1 mrg *) break ;;
170 1.1 mrg esac
171 1.1 mrg done
172 1.1 mrg
173 1.1 mrg # Check for a valid value of $stageN.
174 1.1 mrg case "$stageN" in
175 1.1 mrg [0-9]) ;;
176 1.1 mrg *) echo "Stage <$stageN> must be in the range [0..9]." 1>&2 ; exit 1 ;;
177 1.1 mrg esac
178 1.1 mrg
179 1.1 mrg for file in "$@" ; do
180 1.1 mrg
181 1.1 mrg stageNfilter < $file | subdirectoryFilter > $tmpfile
182 1.1 mrg
183 1.1 mrg # (Just) show me the warnings.
184 1.1 mrg if test "$pass" != '' ; then
185 1.1 mrg if test "$pass" = w ; then
186 1.1 mrg warningFilter < $tmpfile
187 1.1 mrg else
188 1.1 mrg cat $tmpfile
189 1.1 mrg fi
190 1.1 mrg continue
191 1.1 mrg fi
192 1.1 mrg
193 1.1 mrg if test -z "$filter" ; then
194 1.1 mrg echo "Counting all warnings,"
195 1.1 mrg else
196 1.1 mrg if test "$filter" = nosub ; then
197 1.1 mrg echo "Counting non-subdirectory warnings,"
198 1.1 mrg else
199 1.1 mrg echo "Counting warnings in the gcc/$filter subdirectory,"
200 1.1 mrg fi
201 1.1 mrg fi
202 1.1 mrg count=`warningFilter < $tmpfile | wc -l`
203 1.1 mrg echo there are $count warnings in stage$stageN of this bootstrap.
204 1.1 mrg
205 1.1 mrg echo
206 1.1 mrg echo Number of warnings per file:
207 1.1 mrg warningFilter < $tmpfile | srcdirFilter | $AWK -F: '{print$1}' | sort | \
208 1.1 mrg uniq -c | sort -nr
209 1.1 mrg
210 1.1 mrg echo
211 1.1 mrg echo Number of warning types:
212 1.1 mrg warningFilter < $tmpfile | keywordFilter | sort | uniq -c | sort -nr
213 1.1 mrg
214 1.1 mrg done
215