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