Commit | Line | Data |
---|---|---|
b786c521 PM |
1 | #!/bin/sh |
2 | ||
3 | # GDB script to list of problems using awk. | |
4 | # | |
42a4f53d | 5 | # Copyright (C) 2002-2019 Free Software Foundation, Inc. |
b786c521 PM |
6 | # |
7 | # This file is part of GDB. | |
8 | # | |
9 | # This program is free software; you can redistribute it and/or modify | |
10 | # it under the terms of the GNU General Public License as published by | |
11 | # the Free Software Foundation; either version 3 of the License, or | |
12 | # (at your option) any later version. | |
13 | # | |
14 | # This program is distributed in the hope that it will be useful, | |
15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | # GNU General Public License for more details. | |
18 | # | |
19 | # You should have received a copy of the GNU General Public License | |
20 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
21 | ||
22 | # Make certain that the script is not running in an internationalized | |
23 | # environment. | |
24 | ||
84f13595 PM |
25 | LANG=C ; export LANG |
26 | LC_ALL=C ; export LC_ALL | |
b786c521 PM |
27 | |
28 | # Permanent checks take the form: | |
29 | ||
56f79b63 | 30 | # Do not use XXXX, C++11 implies YYYY |
b786c521 PM |
31 | # Do not use XXXX, instead use YYYY''. |
32 | ||
33 | # and should never be removed. | |
34 | ||
35 | # Temporary checks take the form: | |
36 | ||
37 | # Replace XXXX with YYYY | |
38 | ||
39 | # and once they reach zero, can be eliminated. | |
40 | ||
41 | # FIXME: It should be able to override this on the command line | |
42 | error="regression" | |
43 | warning="regression" | |
44 | ari="regression eol code comment deprecated legacy obsolete gettext" | |
45 | all="regression eol code comment deprecated legacy obsolete gettext deprecate internal gdbarch macro" | |
46 | print_doc=0 | |
47 | print_idx=0 | |
48 | ||
49 | usage () | |
50 | { | |
51 | cat <<EOF 1>&2 | |
52 | Error: $1 | |
53 | ||
54 | Usage: | |
55 | $0 --print-doc --print-idx -Wall -Werror -W<category> <file> ... | |
56 | Options: | |
57 | --print-doc Print a list of all potential problems, then exit. | |
58 | --print-idx Include the problems IDX (index or key) in every message. | |
59 | --src=file Write source lines to file. | |
60 | -Werror Treat all problems as errors. | |
61 | -Wall Report all problems. | |
62 | -Wari Report problems that should be fixed in new code. | |
3bbd9f18 | 63 | -W<category> Report problems in the specifed category. Valid categories |
b786c521 PM |
64 | are: ${all} |
65 | EOF | |
66 | exit 1 | |
67 | } | |
68 | ||
69 | ||
70 | # Parse the various options | |
71 | Woptions= | |
72 | srclines="" | |
73 | while test $# -gt 0 | |
74 | do | |
75 | case "$1" in | |
76 | -Wall ) Woptions="${all}" ;; | |
77 | -Wari ) Woptions="${ari}" ;; | |
78 | -Werror ) Werror=1 ;; | |
79 | -W* ) Woptions="${Woptions} `echo x$1 | sed -e 's/x-W//'`" ;; | |
80 | --print-doc ) print_doc=1 ;; | |
81 | --print-idx ) print_idx=1 ;; | |
82 | --src=* ) srclines="`echo $1 | sed -e 's/--src=/srclines=\"/'`\"" ;; | |
83 | -- ) shift ; break ;; | |
84 | - ) break ;; | |
85 | -* ) usage "$1: unknown option" ;; | |
86 | * ) break ;; | |
87 | esac | |
88 | shift | |
89 | done | |
90 | if test -n "$Woptions" ; then | |
91 | warning="$Woptions" | |
92 | error= | |
93 | fi | |
94 | ||
95 | ||
96 | # -Werror implies treating all warnings as errors. | |
97 | if test -n "${Werror}" ; then | |
98 | error="${error} ${warning}" | |
99 | fi | |
100 | ||
101 | ||
102 | # Validate all errors and warnings. | |
103 | for w in ${warning} ${error} | |
104 | do | |
105 | case " ${all} " in | |
106 | *" ${w} "* ) ;; | |
107 | * ) usage "Unknown option -W${w}" ;; | |
108 | esac | |
109 | done | |
110 | ||
111 | ||
112 | # make certain that there is at least one file. | |
113 | if test $# -eq 0 -a ${print_doc} = 0 | |
114 | then | |
115 | usage "Missing file." | |
116 | fi | |
117 | ||
118 | ||
119 | # Convert the errors/warnings into corresponding array entries. | |
120 | for a in ${all} | |
121 | do | |
122 | aris="${aris} ari_${a} = \"${a}\";" | |
123 | done | |
124 | for w in ${warning} | |
125 | do | |
126 | warnings="${warnings} warning[ari_${w}] = 1;" | |
127 | done | |
128 | for e in ${error} | |
129 | do | |
130 | errors="${errors} error[ari_${e}] = 1;" | |
131 | done | |
132 | ||
84f13595 | 133 | if [ "$AWK" = "" ] ; then |
b786c521 PM |
134 | AWK=awk |
135 | fi | |
136 | ||
137 | ${AWK} -- ' | |
138 | BEGIN { | |
139 | # NOTE, for a per-file begin use "FNR == 1". | |
140 | '"${aris}"' | |
141 | '"${errors}"' | |
142 | '"${warnings}"' | |
143 | '"${srclines}"' | |
144 | print_doc = '$print_doc' | |
145 | print_idx = '$print_idx' | |
146 | PWD = "'`pwd`'" | |
147 | } | |
148 | ||
149 | # Print the error message for BUG. Append SUPLEMENT if non-empty. | |
150 | function print_bug(file,line,prefix,category,bug,doc,supplement, suffix,idx) { | |
151 | if (print_idx) { | |
152 | idx = bug ": " | |
153 | } else { | |
154 | idx = "" | |
155 | } | |
156 | if (supplement) { | |
157 | suffix = " (" supplement ")" | |
158 | } else { | |
159 | suffix = "" | |
160 | } | |
161 | # ari.*.bug: <FILE>:<LINE>: <CATEGORY>: <BUG>: <DOC> | |
162 | print file ":" line ": " prefix category ": " idx doc suffix | |
163 | if (srclines != "") { | |
164 | print file ":" line ":" $0 >> srclines | |
165 | } | |
166 | } | |
167 | ||
168 | function fix(bug,file,count) { | |
169 | skip[bug, file] = count | |
170 | skipped[bug, file] = 0 | |
171 | } | |
172 | ||
173 | function fail(bug,supplement) { | |
174 | if (doc[bug] == "") { | |
175 | print_bug("", 0, "internal: ", "internal", "internal", "Missing doc for bug " bug) | |
176 | exit | |
177 | } | |
178 | if (category[bug] == "") { | |
179 | print_bug("", 0, "internal: ", "internal", "internal", "Missing category for bug " bug) | |
180 | exit | |
181 | } | |
182 | ||
183 | if (ARI_OK == bug) { | |
184 | return | |
185 | } | |
186 | # Trim the filename down to just DIRECTORY/FILE so that it can be | |
187 | # robustly used by the FIX code. | |
188 | ||
189 | if (FILENAME ~ /^\//) { | |
190 | canonicalname = FILENAME | |
191 | } else { | |
192 | canonicalname = PWD "/" FILENAME | |
193 | } | |
194 | shortname = gensub (/^.*\/([^\\]*\/[^\\]*)$/, "\\1", 1, canonicalname) | |
195 | ||
196 | skipped[bug, shortname]++ | |
197 | if (skip[bug, shortname] >= skipped[bug, shortname]) { | |
198 | # print FILENAME, FNR, skip[bug, FILENAME], skipped[bug, FILENAME], bug | |
199 | # Do nothing | |
200 | } else if (error[category[bug]]) { | |
201 | # ari.*.bug: <FILE>:<LINE>: <CATEGORY>: <BUG>: <DOC> | |
202 | print_bug(FILENAME, FNR, "", category[bug], bug, doc[bug], supplement) | |
203 | } else if (warning[category[bug]]) { | |
204 | # ari.*.bug: <FILE>:<LINE>: <CATEGORY>: <BUG>: <DOC> | |
205 | print_bug(FILENAME, FNR, "warning: ", category[bug], bug, doc[bug], supplement) | |
206 | } | |
207 | } | |
208 | ||
209 | FNR == 1 { | |
210 | seen[FILENAME] = 1 | |
211 | if (match(FILENAME, "\\.[ly]$")) { | |
212 | # FILENAME is a lex or yacc source | |
213 | is_yacc_or_lex = 1 | |
214 | } | |
215 | else { | |
216 | is_yacc_or_lex = 0 | |
217 | } | |
218 | } | |
219 | END { | |
220 | if (print_idx) { | |
221 | idx = bug ": " | |
222 | } else { | |
223 | idx = "" | |
224 | } | |
225 | # Did we do only a partial skip? | |
226 | for (bug_n_file in skip) { | |
227 | split (bug_n_file, a, SUBSEP) | |
228 | bug = a[1] | |
229 | file = a[2] | |
230 | if (seen[file] && (skipped[bug_n_file] < skip[bug_n_file])) { | |
231 | # ari.*.bug: <FILE>:<LINE>: <CATEGORY>: <BUG>: <DOC> | |
232 | b = file " missing " bug | |
233 | print_bug(file, 0, "", "internal", file " missing " bug, "Expecting " skip[bug_n_file] " occurances of bug " bug " in file " file ", only found " skipped[bug_n_file]) | |
234 | } | |
235 | } | |
236 | } | |
237 | ||
238 | ||
239 | # Skip OBSOLETE lines | |
240 | /(^|[^_[:alnum:]])OBSOLETE([^_[:alnum:]]|$)/ { next; } | |
241 | ||
242 | # Skip ARI lines | |
243 | ||
244 | BEGIN { | |
245 | ARI_OK = "" | |
246 | } | |
247 | ||
248 | /\/\* ARI:[[:space:]]*(.*)[[:space:]]*\*\// { | |
249 | ARI_OK = gensub(/^.*\/\* ARI:[[:space:]]*(.*[^[:space:]])[[:space:]]*\*\/.*$/, "\\1", 1, $0) | |
250 | # print "ARI line found \"" $0 "\"" | |
251 | # print "ARI_OK \"" ARI_OK "\"" | |
252 | } | |
253 | ! /\/\* ARI:[[:space:]]*(.*)[[:space:]]*\*\// { | |
254 | ARI_OK = "" | |
255 | } | |
256 | ||
257 | ||
b786c521 PM |
258 | # SNIP - Strip out comments - SNIP |
259 | ||
260 | FNR == 1 { | |
261 | comment_p = 0 | |
262 | } | |
263 | comment_p && /\*\// { gsub (/^([^\*]|\*+[^\/\*])*\*+\//, " "); comment_p = 0; } | |
264 | comment_p { next; } | |
265 | !comment_p { gsub (/\/\*([^\*]|\*+[^\/\*])*\*+\//, " "); } | |
266 | !comment_p && /(^|[^"])\/\*/ { gsub (/\/\*.*$/, " "); comment_p = 1; } | |
267 | ||
268 | ||
269 | BEGIN { doc["_ markup"] = "\ | |
270 | All messages should be marked up with _." | |
271 | category["_ markup"] = ari_gettext | |
272 | } | |
273 | /^[^"]*[[:space:]](warning|error|error_no_arg|query|perror_with_name)[[:space:]]*\([^_\(a-z]/ { | |
274 | if (! /\("%s"/) { | |
275 | fail("_ markup") | |
276 | } | |
277 | } | |
278 | ||
279 | BEGIN { doc["trailing new line"] = "\ | |
280 | A message should not have a trailing new line" | |
281 | category["trailing new line"] = ari_gettext | |
282 | } | |
283 | /(^|[^_[:alnum:]])(warning|error)[[:space:]]*\(_\(".*\\n"\)[\),]/ { | |
284 | fail("trailing new line") | |
285 | } | |
286 | ||
287 | # Include files for which GDB has a custom version. | |
288 | ||
289 | BEGIN { doc["assert.h"] = "\ | |
290 | Do not include assert.h, instead include \"gdb_assert.h\""; | |
291 | category["assert.h"] = ari_regression | |
292 | fix("assert.h", "gdb/gdb_assert.h", 0) # it does not use it | |
293 | } | |
294 | /^#[[:space:]]*include[[:space:]]+.assert\.h./ { | |
295 | fail("assert.h") | |
296 | } | |
297 | ||
b786c521 PM |
298 | BEGIN { doc["regex.h"] = "\ |
299 | Do not include regex.h, instead include gdb_regex.h" | |
300 | category["regex.h"] = ari_regression | |
301 | fix("regex.h", "gdb/gdb_regex.h", 1) | |
302 | } | |
303 | /^#[[:space:]]*include[[:space:]]*.regex\.h./ { | |
304 | fail("regex.h") | |
305 | } | |
306 | ||
307 | BEGIN { doc["xregex.h"] = "\ | |
308 | Do not include xregex.h, instead include gdb_regex.h" | |
309 | category["xregex.h"] = ari_regression | |
310 | fix("xregex.h", "gdb/gdb_regex.h", 1) | |
311 | } | |
312 | /^#[[:space:]]*include[[:space:]]*.xregex\.h./ { | |
313 | fail("xregex.h") | |
314 | } | |
315 | ||
316 | BEGIN { doc["gnu-regex.h"] = "\ | |
317 | Do not include gnu-regex.h, instead include gdb_regex.h" | |
318 | category["gnu-regex.h"] = ari_regression | |
319 | } | |
320 | /^#[[:space:]]*include[[:space:]]*.gnu-regex\.h./ { | |
321 | fail("gnu regex.h") | |
322 | } | |
323 | ||
b786c521 PM |
324 | BEGIN { doc["wait.h"] = "\ |
325 | Do not include wait.h or sys/wait.h, instead include gdb_wait.h" | |
268a13a5 | 326 | fix("wait.h", "gdbsupport/gdb_wait.h", 2); |
b786c521 PM |
327 | category["wait.h"] = ari_regression |
328 | } | |
329 | /^#[[:space:]]*include[[:space:]]*.wait\.h./ \ | |
330 | || /^#[[:space:]]*include[[:space:]]*.sys\/wait\.h./ { | |
331 | fail("wait.h") | |
332 | } | |
333 | ||
334 | BEGIN { doc["vfork.h"] = "\ | |
335 | Do not include vfork.h, instead include gdb_vfork.h" | |
336 | fix("vfork.h", "gdb/gdb_vfork.h", 1); | |
337 | category["vfork.h"] = ari_regression | |
338 | } | |
339 | /^#[[:space:]]*include[[:space:]]*.vfork\.h./ { | |
340 | fail("vfork.h") | |
341 | } | |
342 | ||
343 | BEGIN { doc["error not internal-warning"] = "\ | |
344 | Do not use error(\"internal-warning\"), instead use internal_warning" | |
345 | category["error not internal-warning"] = ari_regression | |
346 | } | |
347 | /error.*\"[Ii]nternal.warning/ { | |
348 | fail("error not internal-warning") | |
349 | } | |
350 | ||
351 | BEGIN { doc["%p"] = "\ | |
352 | Do not use printf(\"%p\"), instead use printf(\"%s\",paddr()) to dump a \ | |
353 | target address, or host_address_to_string() for a host address" | |
354 | category["%p"] = ari_code | |
355 | } | |
356 | /%p/ && !/%prec/ { | |
357 | fail("%p") | |
358 | } | |
359 | ||
360 | BEGIN { doc["%ll"] = "\ | |
361 | Do not use printf(\"%ll\"), instead use printf(\"%s\",phex()) to dump a \ | |
362 | `long long'\'' value" | |
363 | category["%ll"] = ari_code | |
364 | } | |
365 | # Allow %ll in scanf | |
366 | /%[0-9]*ll/ && !/scanf \(.*%[0-9]*ll/ { | |
367 | fail("%ll") | |
368 | } | |
369 | ||
370 | ||
371 | # SNIP - Strip out strings - SNIP | |
372 | ||
373 | # Test on top.c, scm-valprint.c, remote-rdi.c, ada-lang.c | |
374 | FNR == 1 { | |
375 | string_p = 0 | |
376 | trace_string = 0 | |
377 | } | |
378 | # Strip escaped characters. | |
379 | { gsub(/\\./, "."); } | |
380 | # Strip quoted quotes. | |
381 | { gsub(/'\''.'\''/, "'\''.'\''"); } | |
382 | # End of multi-line string | |
383 | string_p && /\"/ { | |
384 | if (trace_string) print "EOS:" FNR, $0; | |
385 | gsub (/^[^\"]*\"/, "'\''"); | |
386 | string_p = 0; | |
387 | } | |
388 | # Middle of multi-line string, discard line. | |
389 | string_p { | |
390 | if (trace_string) print "MOS:" FNR, $0; | |
391 | $0 = "" | |
392 | } | |
393 | # Strip complete strings from the middle of the line | |
394 | !string_p && /\"[^\"]*\"/ { | |
395 | if (trace_string) print "COS:" FNR, $0; | |
396 | gsub (/\"[^\"]*\"/, "'\''"); | |
397 | } | |
398 | # Start of multi-line string | |
399 | BEGIN { doc["multi-line string"] = "\ | |
400 | Multi-line string must have the newline escaped" | |
401 | category["multi-line string"] = ari_regression | |
402 | } | |
403 | !string_p && /\"/ { | |
404 | if (trace_string) print "SOS:" FNR, $0; | |
405 | if (/[^\\]$/) { | |
406 | fail("multi-line string") | |
407 | } | |
408 | gsub (/\"[^\"]*$/, "'\''"); | |
409 | string_p = 1; | |
410 | } | |
411 | # { print } | |
412 | ||
413 | # Multi-line string | |
414 | string_p && | |
415 | ||
416 | # Accumulate continuation lines | |
417 | FNR == 1 { | |
418 | cont_p = 0 | |
419 | } | |
420 | !cont_p { full_line = ""; } | |
421 | /[^\\]\\$/ { gsub (/\\$/, ""); full_line = full_line $0; cont_p = 1; next; } | |
422 | cont_p { $0 = full_line $0; cont_p = 0; full_line = ""; } | |
423 | ||
424 | ||
b786c521 | 425 | BEGIN { doc["__FUNCTION__"] = "\ |
56f79b63 | 426 | Do not use __FUNCTION__, C++11 does not support this macro" |
b786c521 PM |
427 | category["__FUNCTION__"] = ari_regression |
428 | } | |
429 | /(^|[^_[:alnum:]])__FUNCTION__([^_[:alnum:]]|$)/ { | |
430 | fail("__FUNCTION__") | |
431 | } | |
432 | ||
433 | BEGIN { doc["__CYGWIN32__"] = "\ | |
434 | Do not use __CYGWIN32__, instead use __CYGWIN__ or, better, an explicit \ | |
435 | autoconf tests" | |
436 | category["__CYGWIN32__"] = ari_regression | |
437 | } | |
438 | /(^|[^_[:alnum:]])__CYGWIN32__([^_[:alnum:]]|$)/ { | |
439 | fail("__CYGWIN32__") | |
440 | } | |
441 | ||
442 | BEGIN { doc["PTR"] = "\ | |
56f79b63 | 443 | Do not use PTR, C++11 implies `void *'\''" |
b786c521 PM |
444 | category["PTR"] = ari_regression |
445 | #fix("PTR", "gdb/utils.c", 6) | |
446 | } | |
447 | /(^|[^_[:alnum:]])PTR([^_[:alnum:]]|$)/ { | |
448 | fail("PTR") | |
449 | } | |
450 | ||
451 | BEGIN { doc["UCASE function"] = "\ | |
452 | Function name is uppercase." | |
453 | category["UCASE function"] = ari_code | |
454 | possible_UCASE = 0 | |
455 | UCASE_full_line = "" | |
456 | } | |
457 | (possible_UCASE) { | |
458 | if (ARI_OK == "UCASE function") { | |
459 | possible_UCASE = 0 | |
460 | } | |
461 | # Closing brace found? | |
462 | else if (UCASE_full_line ~ \ | |
463 | /^[A-Z][[:alnum:]_]*[[:space:]]*\([^()]*\).*$/) { | |
464 | if ((UCASE_full_line ~ \ | |
465 | /^[A-Z][[:alnum:]_]*[[:space:]]*\([^()]*\)[[:space:]]*$/) \ | |
466 | && ($0 ~ /^\{/) && (is_yacc_or_lex == 0)) { | |
467 | store_FNR = FNR | |
468 | FNR = possible_FNR | |
469 | store_0 = $0; | |
470 | $0 = UCASE_full_line; | |
471 | fail("UCASE function") | |
472 | FNR = store_FNR | |
473 | $0 = store_0; | |
474 | } | |
475 | possible_UCASE = 0 | |
476 | UCASE_full_line = "" | |
477 | } else { | |
478 | UCASE_full_line = UCASE_full_line $0; | |
479 | } | |
480 | } | |
481 | /^[A-Z][[:alnum:]_]*[[:space:]]*\([^()]*(|\))[[:space:]]*$/ { | |
482 | possible_UCASE = 1 | |
483 | if (ARI_OK == "UCASE function") { | |
484 | possible_UCASE = 0 | |
485 | } | |
486 | possible_FNR = FNR | |
487 | UCASE_full_line = $0 | |
488 | } | |
489 | ||
490 | ||
491 | BEGIN { doc["editCase function"] = "\ | |
492 | Function name starts lower case but has uppercased letters." | |
493 | category["editCase function"] = ari_code | |
494 | possible_editCase = 0 | |
495 | editCase_full_line = "" | |
496 | } | |
497 | (possible_editCase) { | |
47d21dc5 | 498 | if (ARI_OK == "editCase function") { |
b786c521 PM |
499 | possible_editCase = 0 |
500 | } | |
501 | # Closing brace found? | |
502 | else if (editCase_full_line ~ \ | |
503 | /^[a-z][a-z0-9_]*[A-Z][a-z0-9A-Z_]*[[:space:]]*\([^()]*\).*$/) { | |
504 | if ((editCase_full_line ~ \ | |
505 | /^[a-z][a-z0-9_]*[A-Z][a-z0-9A-Z_]*[[:space:]]*\([^()]*\)[[:space:]]*$/) \ | |
506 | && ($0 ~ /^\{/) && (is_yacc_or_lex == 0)) { | |
507 | store_FNR = FNR | |
508 | FNR = possible_FNR | |
509 | store_0 = $0; | |
510 | $0 = editCase_full_line; | |
511 | fail("editCase function") | |
512 | FNR = store_FNR | |
513 | $0 = store_0; | |
514 | } | |
515 | possible_editCase = 0 | |
516 | editCase_full_line = "" | |
517 | } else { | |
518 | editCase_full_line = editCase_full_line $0; | |
519 | } | |
520 | } | |
521 | /^[a-z][a-z0-9_]*[A-Z][a-z0-9A-Z_]*[[:space:]]*\([^()]*(|\))[[:space:]]*$/ { | |
522 | possible_editCase = 1 | |
523 | if (ARI_OK == "editCase function") { | |
524 | possible_editCase = 0 | |
525 | } | |
526 | possible_FNR = FNR | |
527 | editCase_full_line = $0 | |
528 | } | |
529 | ||
530 | # Only function implementation should be on first column | |
531 | BEGIN { doc["function call in first column"] = "\ | |
532 | Function name in first column should be restricted to function implementation" | |
533 | category["function call in first column"] = ari_code | |
534 | } | |
535 | /^[a-z][a-z0-9_]*[[:space:]]*\((|[^*][^()]*)\)[[:space:]]*[^ \t]+/ { | |
536 | fail("function call in first column") | |
537 | } | |
538 | ||
539 | ||
b786c521 PM |
540 | BEGIN { doc["hash"] = "\ |
541 | Do not use ` #...'\'', instead use `#...'\''(some compilers only correctly \ | |
542 | parse a C preprocessor directive when `#'\'' is the first character on \ | |
543 | the line)" | |
544 | category["hash"] = ari_regression | |
545 | } | |
546 | /^[[:space:]]+#/ { | |
547 | fail("hash") | |
548 | } | |
549 | ||
550 | BEGIN { doc["OP eol"] = "\ | |
551 | Do not use &&, or || at the end of a line" | |
552 | category["OP eol"] = ari_code | |
553 | } | |
e3f1ad4f PM |
554 | # * operator needs a special treatment as it can be a |
555 | # valid end of line for a pointer type definition | |
556 | # Only catch case where an assignment or an opening brace is present | |
557 | /(\|\||\&\&|==|!=|[[:space:]][+\-\/])[[:space:]]*$/ \ | |
558 | || /(\(|=)[[:space:]].*[[:space:]]\*[[:space:]]*$/ { | |
b786c521 PM |
559 | fail("OP eol") |
560 | } | |
561 | ||
562 | BEGIN { doc["strerror"] = "\ | |
563 | Do not use strerror(), instead use safe_strerror()" | |
564 | category["strerror"] = ari_regression | |
565 | fix("strerror", "gdb/gdb_string.h", 1) | |
268a13a5 TT |
566 | fix("strerror", "gdb/gdbsupport/mingw-strerror.c", 1) |
567 | fix("strerror", "gdb/gdbsupport/posix-strerror.c", 1) | |
b786c521 PM |
568 | } |
569 | /(^|[^_[:alnum:]])strerror[[:space:]]*\(/ { | |
570 | fail("strerror") | |
571 | } | |
572 | ||
573 | BEGIN { doc["long long"] = "\ | |
574 | Do not use `long long'\'', instead use LONGEST" | |
575 | category["long long"] = ari_code | |
576 | # defs.h needs two such patterns for LONGEST and ULONGEST definitions | |
577 | fix("long long", "gdb/defs.h", 2) | |
578 | } | |
579 | /(^|[^_[:alnum:]])long[[:space:]]+long([^_[:alnum:]]|$)/ { | |
580 | fail("long long") | |
581 | } | |
582 | ||
583 | BEGIN { doc["ATTRIBUTE_UNUSED"] = "\ | |
584 | Do not use ATTRIBUTE_UNUSED, do not bother (GDB is compiled with -Werror and, \ | |
585 | consequently, is not able to tolerate false warnings. Since -Wunused-param \ | |
586 | produces such warnings, neither that warning flag nor ATTRIBUTE_UNUSED \ | |
587 | are used by GDB" | |
588 | category["ATTRIBUTE_UNUSED"] = ari_regression | |
589 | } | |
590 | /(^|[^_[:alnum:]])ATTRIBUTE_UNUSED([^_[:alnum:]]|$)/ { | |
591 | fail("ATTRIBUTE_UNUSED") | |
592 | } | |
593 | ||
594 | BEGIN { doc["ATTR_FORMAT"] = "\ | |
595 | Do not use ATTR_FORMAT, use ATTRIBUTE_PRINTF instead" | |
596 | category["ATTR_FORMAT"] = ari_regression | |
597 | } | |
598 | /(^|[^_[:alnum:]])ATTR_FORMAT([^_[:alnum:]]|$)/ { | |
599 | fail("ATTR_FORMAT") | |
600 | } | |
601 | ||
602 | BEGIN { doc["ATTR_NORETURN"] = "\ | |
603 | Do not use ATTR_NORETURN, use ATTRIBUTE_NORETURN instead" | |
604 | category["ATTR_NORETURN"] = ari_regression | |
605 | } | |
606 | /(^|[^_[:alnum:]])ATTR_NORETURN([^_[:alnum:]]|$)/ { | |
607 | fail("ATTR_NORETURN") | |
608 | } | |
609 | ||
610 | BEGIN { doc["NORETURN"] = "\ | |
611 | Do not use NORETURN, use ATTRIBUTE_NORETURN instead" | |
612 | category["NORETURN"] = ari_regression | |
613 | } | |
614 | /(^|[^_[:alnum:]])NORETURN([^_[:alnum:]]|$)/ { | |
615 | fail("NORETURN") | |
616 | } | |
617 | ||
618 | ||
619 | # General problems | |
620 | ||
621 | BEGIN { doc["multiple messages"] = "\ | |
622 | Do not use multiple calls to warning or error, instead use a single call" | |
623 | category["multiple messages"] = ari_gettext | |
624 | } | |
625 | FNR == 1 { | |
626 | warning_fnr = -1 | |
627 | } | |
628 | /(^|[^_[:alnum:]])(warning|error)[[:space:]]*\(/ { | |
629 | if (FNR == warning_fnr + 1) { | |
630 | fail("multiple messages") | |
631 | } else { | |
632 | warning_fnr = FNR | |
633 | } | |
634 | } | |
635 | ||
636 | # Commented out, but left inside sources, just in case. | |
637 | # BEGIN { doc["inline"] = "\ | |
638 | # Do not use the inline attribute; \ | |
639 | # since the compiler generally ignores this, better algorithm selection \ | |
640 | # is needed to improved performance" | |
641 | # category["inline"] = ari_code | |
642 | # } | |
643 | # /(^|[^_[:alnum:]])inline([^_[:alnum:]]|$)/ { | |
644 | # fail("inline") | |
645 | # } | |
646 | ||
647 | # This test is obsolete as this type | |
648 | # has been deprecated and finally suppressed from GDB sources | |
649 | #BEGIN { doc["obj_private"] = "\ | |
650 | #Replace obj_private with objfile_data" | |
651 | # category["obj_private"] = ari_obsolete | |
652 | #} | |
653 | #/(^|[^_[:alnum:]])obj_private([^_[:alnum:]]|$)/ { | |
654 | # fail("obj_private") | |
655 | #} | |
656 | ||
657 | BEGIN { doc["abort"] = "\ | |
658 | Do not use abort, instead use internal_error; GDB should never abort" | |
659 | category["abort"] = ari_regression | |
660 | fix("abort", "gdb/utils.c", 3) | |
661 | } | |
662 | /(^|[^_[:alnum:]])abort[[:space:]]*\(/ { | |
663 | fail("abort") | |
664 | } | |
665 | ||
666 | BEGIN { doc["basename"] = "\ | |
667 | Do not use basename, instead use lbasename" | |
668 | category["basename"] = ari_regression | |
669 | } | |
670 | /(^|[^_[:alnum:]])basename[[:space:]]*\(/ { | |
671 | fail("basename") | |
672 | } | |
673 | ||
674 | BEGIN { doc["assert"] = "\ | |
675 | Do not use assert, instead use gdb_assert or internal_error; assert \ | |
676 | calls abort and GDB should never call abort" | |
677 | category["assert"] = ari_regression | |
678 | } | |
679 | /(^|[^_[:alnum:]])assert[[:space:]]*\(/ { | |
680 | fail("assert") | |
681 | } | |
682 | ||
683 | BEGIN { doc["TARGET_HAS_HARDWARE_WATCHPOINTS"] = "\ | |
684 | Replace TARGET_HAS_HARDWARE_WATCHPOINTS with nothing, not needed" | |
685 | category["TARGET_HAS_HARDWARE_WATCHPOINTS"] = ari_regression | |
686 | } | |
687 | /(^|[^_[:alnum:]])TARGET_HAS_HARDWARE_WATCHPOINTS([^_[:alnum:]]|$)/ { | |
688 | fail("TARGET_HAS_HARDWARE_WATCHPOINTS") | |
689 | } | |
690 | ||
691 | BEGIN { doc["ADD_SHARED_SYMBOL_FILES"] = "\ | |
692 | Replace ADD_SHARED_SYMBOL_FILES with nothing, not needed?" | |
693 | category["ADD_SHARED_SYMBOL_FILES"] = ari_regression | |
694 | } | |
695 | /(^|[^_[:alnum:]])ADD_SHARED_SYMBOL_FILES([^_[:alnum:]]|$)/ { | |
696 | fail("ADD_SHARED_SYMBOL_FILES") | |
697 | } | |
698 | ||
699 | BEGIN { doc["SOLIB_ADD"] = "\ | |
700 | Replace SOLIB_ADD with nothing, not needed?" | |
27fd0c6b | 701 | category["SOLIB_ADD"] = ari_regression |
b786c521 PM |
702 | } |
703 | /(^|[^_[:alnum:]])SOLIB_ADD([^_[:alnum:]]|$)/ { | |
704 | fail("SOLIB_ADD") | |
705 | } | |
706 | ||
707 | BEGIN { doc["SOLIB_CREATE_INFERIOR_HOOK"] = "\ | |
708 | Replace SOLIB_CREATE_INFERIOR_HOOK with nothing, not needed?" | |
27fd0c6b | 709 | category["SOLIB_CREATE_INFERIOR_HOOK"] = ari_regression |
b786c521 PM |
710 | } |
711 | /(^|[^_[:alnum:]])SOLIB_CREATE_INFERIOR_HOOK([^_[:alnum:]]|$)/ { | |
712 | fail("SOLIB_CREATE_INFERIOR_HOOK") | |
713 | } | |
714 | ||
715 | BEGIN { doc["SOLIB_LOADED_LIBRARY_PATHNAME"] = "\ | |
716 | Replace SOLIB_LOADED_LIBRARY_PATHNAME with nothing, not needed?" | |
717 | category["SOLIB_LOADED_LIBRARY_PATHNAME"] = ari_regression | |
718 | } | |
719 | /(^|[^_[:alnum:]])SOLIB_LOADED_LIBRARY_PATHNAME([^_[:alnum:]]|$)/ { | |
720 | fail("SOLIB_LOADED_LIBRARY_PATHNAME") | |
721 | } | |
722 | ||
723 | BEGIN { doc["REGISTER_U_ADDR"] = "\ | |
724 | Replace REGISTER_U_ADDR with nothing, not needed?" | |
725 | category["REGISTER_U_ADDR"] = ari_regression | |
726 | } | |
727 | /(^|[^_[:alnum:]])REGISTER_U_ADDR([^_[:alnum:]]|$)/ { | |
728 | fail("REGISTER_U_ADDR") | |
729 | } | |
730 | ||
731 | BEGIN { doc["PROCESS_LINENUMBER_HOOK"] = "\ | |
732 | Replace PROCESS_LINENUMBER_HOOK with nothing, not needed?" | |
733 | category["PROCESS_LINENUMBER_HOOK"] = ari_regression | |
734 | } | |
735 | /(^|[^_[:alnum:]])PROCESS_LINENUMBER_HOOK([^_[:alnum:]]|$)/ { | |
736 | fail("PROCESS_LINENUMBER_HOOK") | |
737 | } | |
738 | ||
739 | BEGIN { doc["PC_SOLIB"] = "\ | |
740 | Replace PC_SOLIB with nothing, not needed?" | |
27fd0c6b | 741 | category["PC_SOLIB"] = ari_regression |
b786c521 PM |
742 | } |
743 | /(^|[^_[:alnum:]])PC_SOLIB([^_[:alnum:]]|$)/ { | |
744 | fail("PC_SOLIB") | |
745 | } | |
746 | ||
747 | BEGIN { doc["IN_SOLIB_DYNSYM_RESOLVE_CODE"] = "\ | |
748 | Replace IN_SOLIB_DYNSYM_RESOLVE_CODE with nothing, not needed?" | |
749 | category["IN_SOLIB_DYNSYM_RESOLVE_CODE"] = ari_regression | |
750 | } | |
751 | /(^|[^_[:alnum:]])IN_SOLIB_DYNSYM_RESOLVE_CODE([^_[:alnum:]]|$)/ { | |
752 | fail("IN_SOLIB_DYNSYM_RESOLVE_CODE") | |
753 | } | |
754 | ||
755 | BEGIN { doc["GCC_COMPILED_FLAG_SYMBOL"] = "\ | |
756 | Replace GCC_COMPILED_FLAG_SYMBOL with nothing, not needed?" | |
757 | category["GCC_COMPILED_FLAG_SYMBOL"] = ari_deprecate | |
758 | } | |
759 | /(^|[^_[:alnum:]])GCC_COMPILED_FLAG_SYMBOL([^_[:alnum:]]|$)/ { | |
760 | fail("GCC_COMPILED_FLAG_SYMBOL") | |
761 | } | |
762 | ||
763 | BEGIN { doc["GCC2_COMPILED_FLAG_SYMBOL"] = "\ | |
764 | Replace GCC2_COMPILED_FLAG_SYMBOL with nothing, not needed?" | |
765 | category["GCC2_COMPILED_FLAG_SYMBOL"] = ari_deprecate | |
766 | } | |
767 | /(^|[^_[:alnum:]])GCC2_COMPILED_FLAG_SYMBOL([^_[:alnum:]]|$)/ { | |
768 | fail("GCC2_COMPILED_FLAG_SYMBOL") | |
769 | } | |
770 | ||
771 | BEGIN { doc["FUNCTION_EPILOGUE_SIZE"] = "\ | |
772 | Replace FUNCTION_EPILOGUE_SIZE with nothing, not needed?" | |
773 | category["FUNCTION_EPILOGUE_SIZE"] = ari_regression | |
774 | } | |
775 | /(^|[^_[:alnum:]])FUNCTION_EPILOGUE_SIZE([^_[:alnum:]]|$)/ { | |
776 | fail("FUNCTION_EPILOGUE_SIZE") | |
777 | } | |
778 | ||
779 | BEGIN { doc["HAVE_VFORK"] = "\ | |
780 | Do not use HAVE_VFORK, instead include \"gdb_vfork.h\" and call vfork() \ | |
781 | unconditionally" | |
782 | category["HAVE_VFORK"] = ari_regression | |
783 | } | |
784 | /(^|[^_[:alnum:]])HAVE_VFORK([^_[:alnum:]]|$)/ { | |
785 | fail("HAVE_VFORK") | |
786 | } | |
787 | ||
788 | BEGIN { doc["bcmp"] = "\ | |
56f79b63 | 789 | Do not use bcmp(), C++11 implies memcmp()" |
b786c521 PM |
790 | category["bcmp"] = ari_regression |
791 | } | |
792 | /(^|[^_[:alnum:]])bcmp[[:space:]]*\(/ { | |
793 | fail("bcmp") | |
794 | } | |
795 | ||
796 | BEGIN { doc["setlinebuf"] = "\ | |
56f79b63 | 797 | Do not use setlinebuf(), C++11 implies setvbuf()" |
b786c521 PM |
798 | category["setlinebuf"] = ari_regression |
799 | } | |
800 | /(^|[^_[:alnum:]])setlinebuf[[:space:]]*\(/ { | |
801 | fail("setlinebuf") | |
802 | } | |
803 | ||
804 | BEGIN { doc["bcopy"] = "\ | |
56f79b63 | 805 | Do not use bcopy(), C++11 implies memcpy() and memmove()" |
b786c521 PM |
806 | category["bcopy"] = ari_regression |
807 | } | |
808 | /(^|[^_[:alnum:]])bcopy[[:space:]]*\(/ { | |
809 | fail("bcopy") | |
810 | } | |
811 | ||
812 | BEGIN { doc["get_frame_base"] = "\ | |
813 | Replace get_frame_base with get_frame_id, get_frame_base_address, \ | |
814 | get_frame_locals_address, or get_frame_args_address." | |
815 | category["get_frame_base"] = ari_obsolete | |
816 | } | |
817 | /(^|[^_[:alnum:]])get_frame_base([^_[:alnum:]]|$)/ { | |
818 | fail("get_frame_base") | |
819 | } | |
820 | ||
821 | BEGIN { doc["floatformat_to_double"] = "\ | |
822 | Do not use floatformat_to_double() from libierty, \ | |
823 | instead use floatformat_to_doublest()" | |
824 | fix("floatformat_to_double", "gdb/doublest.c", 1) | |
825 | category["floatformat_to_double"] = ari_regression | |
826 | } | |
827 | /(^|[^_[:alnum:]])floatformat_to_double[[:space:]]*\(/ { | |
828 | fail("floatformat_to_double") | |
829 | } | |
830 | ||
831 | BEGIN { doc["floatformat_from_double"] = "\ | |
832 | Do not use floatformat_from_double() from libierty, \ | |
833 | instead use floatformat_from_doublest()" | |
834 | category["floatformat_from_double"] = ari_regression | |
835 | } | |
836 | /(^|[^_[:alnum:]])floatformat_from_double[[:space:]]*\(/ { | |
837 | fail("floatformat_from_double") | |
838 | } | |
839 | ||
840 | BEGIN { doc["BIG_ENDIAN"] = "\ | |
841 | Do not use BIG_ENDIAN, instead use BFD_ENDIAN_BIG" | |
842 | category["BIG_ENDIAN"] = ari_regression | |
843 | } | |
844 | /(^|[^_[:alnum:]])BIG_ENDIAN([^_[:alnum:]]|$)/ { | |
845 | fail("BIG_ENDIAN") | |
846 | } | |
847 | ||
848 | BEGIN { doc["LITTLE_ENDIAN"] = "\ | |
849 | Do not use LITTLE_ENDIAN, instead use BFD_ENDIAN_LITTLE"; | |
850 | category["LITTLE_ENDIAN"] = ari_regression | |
851 | } | |
852 | /(^|[^_[:alnum:]])LITTLE_ENDIAN([^_[:alnum:]]|$)/ { | |
853 | fail("LITTLE_ENDIAN") | |
854 | } | |
855 | ||
856 | BEGIN { doc["BIG_ENDIAN"] = "\ | |
857 | Do not use BIG_ENDIAN, instead use BFD_ENDIAN_BIG" | |
858 | category["BIG_ENDIAN"] = ari_regression | |
859 | } | |
860 | /(^|[^_[:alnum:]])BIG_ENDIAN([^_[:alnum:]]|$)/ { | |
861 | fail("BIG_ENDIAN") | |
862 | } | |
863 | ||
864 | BEGIN { doc["sec_ptr"] = "\ | |
865 | Instead of sec_ptr, use struct bfd_section"; | |
866 | category["sec_ptr"] = ari_regression | |
867 | } | |
868 | /(^|[^_[:alnum:]])sec_ptr([^_[:alnum:]]|$)/ { | |
869 | fail("sec_ptr") | |
870 | } | |
871 | ||
872 | BEGIN { doc["frame_unwind_unsigned_register"] = "\ | |
873 | Replace frame_unwind_unsigned_register with frame_unwind_register_unsigned" | |
874 | category["frame_unwind_unsigned_register"] = ari_regression | |
875 | } | |
876 | /(^|[^_[:alnum:]])frame_unwind_unsigned_register([^_[:alnum:]]|$)/ { | |
877 | fail("frame_unwind_unsigned_register") | |
878 | } | |
879 | ||
880 | BEGIN { doc["frame_register_read"] = "\ | |
881 | Replace frame_register_read() with get_frame_register(), or \ | |
882 | possibly introduce a new method safe_get_frame_register()" | |
883 | category["frame_register_read"] = ari_obsolete | |
884 | } | |
885 | /(^|[^_[:alnum:]])frame_register_read([^_[:alnum:]]|$)/ { | |
886 | fail("frame_register_read") | |
887 | } | |
888 | ||
889 | BEGIN { doc["read_register"] = "\ | |
890 | Replace read_register() with regcache_read() et.al." | |
891 | category["read_register"] = ari_regression | |
892 | } | |
893 | /(^|[^_[:alnum:]])read_register([^_[:alnum:]]|$)/ { | |
894 | fail("read_register") | |
895 | } | |
896 | ||
897 | BEGIN { doc["write_register"] = "\ | |
898 | Replace write_register() with regcache_read() et.al." | |
899 | category["write_register"] = ari_regression | |
900 | } | |
901 | /(^|[^_[:alnum:]])write_register([^_[:alnum:]]|$)/ { | |
902 | fail("write_register") | |
903 | } | |
904 | ||
905 | function report(name) { | |
906 | # Drop any trailing _P. | |
907 | name = gensub(/(_P|_p)$/, "", 1, name) | |
908 | # Convert to lower case | |
909 | name = tolower(name) | |
910 | # Split into category and bug | |
911 | cat = gensub(/^([[:alpha:]]+)_([_[:alnum:]]*)$/, "\\1", 1, name) | |
912 | bug = gensub(/^([[:alpha:]]+)_([_[:alnum:]]*)$/, "\\2", 1, name) | |
913 | # Report it | |
914 | name = cat " " bug | |
915 | doc[name] = "Do not use " cat " " bug ", see declaration for details" | |
916 | category[name] = cat | |
917 | fail(name) | |
918 | } | |
919 | ||
920 | /(^|[^_[:alnum:]])(DEPRECATED|deprecated|set_gdbarch_deprecated|LEGACY|legacy|set_gdbarch_legacy)_/ { | |
921 | line = $0 | |
922 | # print "0 =", $0 | |
923 | while (1) { | |
924 | name = gensub(/^(|.*[^_[:alnum:]])((DEPRECATED|deprecated|LEGACY|legacy)_[_[:alnum:]]*)(.*)$/, "\\2", 1, line) | |
925 | line = gensub(/^(|.*[^_[:alnum:]])((DEPRECATED|deprecated|LEGACY|legacy)_[_[:alnum:]]*)(.*)$/, "\\1 \\4", 1, line) | |
926 | # print "name =", name, "line =", line | |
927 | if (name == line) break; | |
928 | report(name) | |
929 | } | |
930 | } | |
931 | ||
932 | # Count the number of times each architecture method is set | |
933 | /(^|[^_[:alnum:]])set_gdbarch_[_[:alnum:]]*([^_[:alnum:]]|$)/ { | |
934 | name = gensub(/^.*set_gdbarch_([_[:alnum:]]*).*$/, "\\1", 1, $0) | |
935 | doc["set " name] = "\ | |
936 | Call to set_gdbarch_" name | |
937 | category["set " name] = ari_gdbarch | |
938 | fail("set " name) | |
939 | } | |
940 | ||
941 | # Count the number of times each tm/xm/nm macro is defined or undefined | |
942 | /^#[[:space:]]*(undef|define)[[:space:]]+[[:alnum:]_]+.*$/ \ | |
943 | && !/^#[[:space:]]*(undef|define)[[:space:]]+[[:alnum:]_]+_H($|[[:space:]])/ \ | |
944 | && FILENAME ~ /(^|\/)config\/(|[^\/]*\/)(tm-|xm-|nm-).*\.h$/ { | |
945 | basename = gensub(/(^|.*\/)([^\/]*)$/, "\\2", 1, FILENAME) | |
946 | type = gensub(/^(tm|xm|nm)-.*\.h$/, "\\1", 1, basename) | |
947 | name = gensub(/^#[[:space:]]*(undef|define)[[:space:]]+([[:alnum:]_]+).*$/, "\\2", 1, $0) | |
948 | if (type == basename) { | |
949 | type = "macro" | |
950 | } | |
951 | doc[type " " name] = "\ | |
952 | Do not define macros such as " name " in a tm, nm or xm file, \ | |
953 | in fact do not provide a tm, nm or xm file" | |
954 | category[type " " name] = ari_macro | |
955 | fail(type " " name) | |
956 | } | |
957 | ||
958 | BEGIN { doc["deprecated_registers"] = "\ | |
959 | Replace deprecated_registers with nothing, they have reached \ | |
960 | end-of-life" | |
961 | category["deprecated_registers"] = ari_eol | |
962 | } | |
963 | /(^|[^_[:alnum:]])deprecated_registers([^_[:alnum:]]|$)/ { | |
964 | fail("deprecated_registers") | |
965 | } | |
966 | ||
967 | BEGIN { doc["read_pc"] = "\ | |
968 | Replace READ_PC() with frame_pc_unwind; \ | |
969 | at present the inferior function call code still uses this" | |
970 | category["read_pc"] = ari_deprecate | |
971 | } | |
972 | /(^|[^_[:alnum:]])read_pc[[:space:]]*\(/ || \ | |
973 | /(^|[^_[:alnum:]])set_gdbarch_read_pc[[:space:]]*\(/ || \ | |
974 | /(^|[^_[:alnum:]])TARGET_READ_PC[[:space:]]*\(/ { | |
975 | fail("read_pc") | |
976 | } | |
977 | ||
978 | BEGIN { doc["write_pc"] = "\ | |
979 | Replace write_pc() with get_frame_base_address or get_frame_id; \ | |
980 | at present the inferior function call code still uses this when doing \ | |
981 | a DECR_PC_AFTER_BREAK" | |
982 | category["write_pc"] = ari_deprecate | |
983 | } | |
984 | /(^|[^_[:alnum:]])write_pc[[:space:]]*\(/ || \ | |
b786c521 PM |
985 | /(^|[^_[:alnum:]])TARGET_WRITE_PC[[:space:]]*\(/ { |
986 | fail("write_pc") | |
987 | } | |
988 | ||
989 | BEGIN { doc["generic_target_write_pc"] = "\ | |
990 | Replace generic_target_write_pc with a per-architecture implementation, \ | |
991 | this relies on PC_REGNUM which is being eliminated" | |
992 | category["generic_target_write_pc"] = ari_regression | |
993 | } | |
994 | /(^|[^_[:alnum:]])generic_target_write_pc([^_[:alnum:]]|$)/ { | |
995 | fail("generic_target_write_pc") | |
996 | } | |
997 | ||
998 | BEGIN { doc["read_sp"] = "\ | |
999 | Replace read_sp() with frame_sp_unwind" | |
1000 | category["read_sp"] = ari_regression | |
1001 | } | |
1002 | /(^|[^_[:alnum:]])read_sp[[:space:]]*\(/ || \ | |
1003 | /(^|[^_[:alnum:]])set_gdbarch_read_sp[[:space:]]*\(/ || \ | |
1004 | /(^|[^_[:alnum:]])TARGET_READ_SP[[:space:]]*\(/ { | |
1005 | fail("read_sp") | |
1006 | } | |
1007 | ||
1008 | BEGIN { doc["register_cached"] = "\ | |
1009 | Replace register_cached() with nothing, does not have a regcache parameter" | |
1010 | category["register_cached"] = ari_regression | |
1011 | } | |
1012 | /(^|[^_[:alnum:]])register_cached[[:space:]]*\(/ { | |
1013 | fail("register_cached") | |
1014 | } | |
1015 | ||
1016 | BEGIN { doc["set_register_cached"] = "\ | |
1017 | Replace set_register_cached() with nothing, does not have a regcache parameter" | |
1018 | category["set_register_cached"] = ari_regression | |
1019 | } | |
1020 | /(^|[^_[:alnum:]])set_register_cached[[:space:]]*\(/ { | |
1021 | fail("set_register_cached") | |
1022 | } | |
1023 | ||
1024 | # Print functions: Use versions that either check for buffer overflow | |
1025 | # or safely allocate a fresh buffer. | |
1026 | ||
1027 | BEGIN { doc["sprintf"] = "\ | |
1028 | Do not use sprintf, instead use xsnprintf or xstrprintf" | |
1029 | category["sprintf"] = ari_code | |
1030 | } | |
1031 | /(^|[^_[:alnum:]])sprintf[[:space:]]*\(/ { | |
1032 | fail("sprintf") | |
1033 | } | |
1034 | ||
1035 | BEGIN { doc["vsprintf"] = "\ | |
1036 | Do not use vsprintf(), instead use xstrvprintf" | |
1037 | category["vsprintf"] = ari_regression | |
1038 | } | |
1039 | /(^|[^_[:alnum:]])vsprintf[[:space:]]*\(/ { | |
1040 | fail("vsprintf") | |
1041 | } | |
1042 | ||
1043 | BEGIN { doc["asprintf"] = "\ | |
1044 | Do not use asprintf(), instead use xstrprintf()" | |
1045 | category["asprintf"] = ari_regression | |
1046 | } | |
1047 | /(^|[^_[:alnum:]])asprintf[[:space:]]*\(/ { | |
1048 | fail("asprintf") | |
1049 | } | |
1050 | ||
1051 | BEGIN { doc["vasprintf"] = "\ | |
1052 | Do not use vasprintf(), instead use xstrvprintf" | |
268a13a5 | 1053 | fix("vasprintf", "gdbsupport/common-utils.c", 1) |
b786c521 PM |
1054 | category["vasprintf"] = ari_regression |
1055 | } | |
1056 | /(^|[^_[:alnum:]])vasprintf[[:space:]]*\(/ { | |
1057 | fail("vasprintf") | |
1058 | } | |
1059 | ||
cc188e5f JB |
1060 | BEGIN { doc["printf_vma"] = "\ |
1061 | Do not use printf_vma, instead use paddress or phex_nz" | |
1062 | category["printf_vma"] = ari_code | |
1063 | } | |
1064 | /(^|[^_[:alnum:]])printf_vma[[:space:]]*\(/ { | |
1065 | fail("printf_vma") | |
1066 | } | |
1067 | ||
1068 | BEGIN { doc["sprintf_vma"] = "\ | |
1069 | Do not use sprintf_vma, instead use paddress or phex_nz" | |
1070 | category["sprintf_vma"] = ari_code | |
1071 | } | |
1072 | /(^|[^_[:alnum:]])sprintf_vma[[:space:]]*\(/ { | |
1073 | fail("sprintf_vma") | |
1074 | } | |
1075 | ||
b786c521 PM |
1076 | # More generic memory operations |
1077 | ||
1078 | BEGIN { doc["bzero"] = "\ | |
1079 | Do not use bzero(), instead use memset()" | |
1080 | category["bzero"] = ari_regression | |
1081 | } | |
1082 | /(^|[^_[:alnum:]])bzero[[:space:]]*\(/ { | |
1083 | fail("bzero") | |
1084 | } | |
1085 | ||
1086 | BEGIN { doc["strdup"] = "\ | |
1087 | Do not use strdup(), instead use xstrdup()"; | |
1088 | category["strdup"] = ari_regression | |
1089 | } | |
1090 | /(^|[^_[:alnum:]])strdup[[:space:]]*\(/ { | |
1091 | fail("strdup") | |
1092 | } | |
1093 | ||
1094 | BEGIN { doc["strsave"] = "\ | |
1095 | Do not use strsave(), instead use xstrdup() et.al." | |
1096 | category["strsave"] = ari_regression | |
1097 | } | |
1098 | /(^|[^_[:alnum:]])strsave[[:space:]]*\(/ { | |
1099 | fail("strsave") | |
1100 | } | |
1101 | ||
1102 | # String compare functions | |
1103 | ||
1104 | BEGIN { doc["strnicmp"] = "\ | |
1105 | Do not use strnicmp(), instead use strncasecmp()" | |
1106 | category["strnicmp"] = ari_regression | |
1107 | } | |
1108 | /(^|[^_[:alnum:]])strnicmp[[:space:]]*\(/ { | |
1109 | fail("strnicmp") | |
1110 | } | |
1111 | ||
1112 | # Boolean expressions and conditionals | |
1113 | ||
1114 | BEGIN { doc["boolean"] = "\ | |
1f2e9c5e | 1115 | Do not use `boolean'\'', use `bool'\'' instead" |
b786c521 PM |
1116 | category["boolean"] = ari_regression |
1117 | } | |
1118 | /(^|[^_[:alnum:]])boolean([^_[:alnum:]]|$)/ { | |
1119 | if (is_yacc_or_lex == 0) { | |
1120 | fail("boolean") | |
1121 | } | |
1122 | } | |
1123 | ||
b786c521 PM |
1124 | # Typedefs that are either redundant or can be reduced to `struct |
1125 | # type *''. | |
1126 | # Must be placed before if assignment otherwise ARI exceptions | |
1127 | # are not handled correctly. | |
1128 | ||
1129 | BEGIN { doc["d_namelen"] = "\ | |
1130 | Do not use dirent.d_namelen, instead use NAMELEN" | |
1131 | category["d_namelen"] = ari_regression | |
1132 | } | |
1133 | /(^|[^_[:alnum:]])d_namelen([^_[:alnum:]]|$)/ { | |
1134 | fail("d_namelen") | |
1135 | } | |
1136 | ||
1137 | BEGIN { doc["strlen d_name"] = "\ | |
1138 | Do not use strlen dirent.d_name, instead use NAMELEN" | |
1139 | category["strlen d_name"] = ari_regression | |
1140 | } | |
1141 | /(^|[^_[:alnum:]])strlen[[:space:]]*\(.*[^_[:alnum:]]d_name([^_[:alnum:]]|$)/ { | |
1142 | fail("strlen d_name") | |
1143 | } | |
1144 | ||
1145 | BEGIN { doc["var_boolean"] = "\ | |
1146 | Replace var_boolean with add_setshow_boolean_cmd" | |
1147 | category["var_boolean"] = ari_regression | |
1148 | fix("var_boolean", "gdb/command.h", 1) | |
1149 | # fix only uses the last directory level | |
1150 | fix("var_boolean", "cli/cli-decode.c", 2) | |
1151 | } | |
1152 | /(^|[^_[:alnum:]])var_boolean([^_[:alnum:]]|$)/ { | |
84f13595 PM |
1153 | if (($0 !~ /(^|[^_[:alnum:]])case *var_boolean:/) \ |
1154 | && ($0 !~ /(^|[^_[:alnum:]])[=!]= *var_boolean/)) { | |
b786c521 PM |
1155 | fail("var_boolean") |
1156 | } | |
1157 | } | |
1158 | ||
1159 | BEGIN { doc["generic_use_struct_convention"] = "\ | |
1160 | Replace generic_use_struct_convention with nothing, \ | |
1161 | EXTRACT_STRUCT_VALUE_ADDRESS is a predicate" | |
1162 | category["generic_use_struct_convention"] = ari_regression | |
1163 | } | |
1164 | /(^|[^_[:alnum:]])generic_use_struct_convention([^_[:alnum:]]|$)/ { | |
1165 | fail("generic_use_struct_convention") | |
1166 | } | |
1167 | ||
1168 | BEGIN { doc["if assignment"] = "\ | |
1169 | An IF statement'\''s expression contains an assignment (the GNU coding \ | |
1170 | standard discourages this)" | |
1171 | category["if assignment"] = ari_code | |
1172 | } | |
1173 | BEGIN { doc["if clause more than 50 lines"] = "\ | |
1174 | An IF statement'\''s expression expands over 50 lines" | |
1175 | category["if clause more than 50 lines"] = ari_code | |
1176 | } | |
1177 | # | |
1178 | # Accumulate continuation lines | |
1179 | FNR == 1 { | |
1180 | in_if = 0 | |
1181 | } | |
1182 | ||
1183 | /(^|[^_[:alnum:]])if / { | |
1184 | in_if = 1; | |
1185 | if_brace_level = 0; | |
1186 | if_cont_p = 0; | |
1187 | if_count = 0; | |
1188 | if_brace_end_pos = 0; | |
1189 | if_full_line = ""; | |
1190 | } | |
1191 | (in_if) { | |
1192 | # We want everything up to closing brace of same level | |
1193 | if_count++; | |
1194 | if (if_count > 50) { | |
1195 | print "multiline if: " if_full_line $0 | |
1196 | fail("if clause more than 50 lines") | |
1197 | if_brace_level = 0; | |
1198 | if_full_line = ""; | |
1199 | } else { | |
1200 | if (if_count == 1) { | |
1201 | i = index($0,"if "); | |
1202 | } else { | |
1203 | i = 1; | |
1204 | } | |
1205 | for (i=i; i <= length($0); i++) { | |
1206 | char = substr($0,i,1); | |
1207 | if (char == "(") { if_brace_level++; } | |
1208 | if (char == ")") { | |
1209 | if_brace_level--; | |
1210 | if (!if_brace_level) { | |
1211 | if_brace_end_pos = i; | |
1212 | after_if = substr($0,i+1,length($0)); | |
1213 | # Do not parse what is following | |
1214 | break; | |
1215 | } | |
1216 | } | |
1217 | } | |
1218 | if (if_brace_level == 0) { | |
1219 | $0 = substr($0,1,i); | |
1220 | in_if = 0; | |
1221 | } else { | |
1222 | if_full_line = if_full_line $0; | |
1223 | if_cont_p = 1; | |
1224 | next; | |
1225 | } | |
1226 | } | |
1227 | } | |
1228 | # if we arrive here, we need to concatenate, but we are at brace level 0 | |
1229 | ||
1230 | (if_brace_end_pos) { | |
1231 | $0 = if_full_line substr($0,1,if_brace_end_pos); | |
1232 | if (if_count > 1) { | |
1233 | # print "IF: multi line " if_count " found at " FILENAME ":" FNR " \"" $0 "\"" | |
1234 | } | |
1235 | if_cont_p = 0; | |
1236 | if_full_line = ""; | |
1237 | } | |
1238 | /(^|[^_[:alnum:]])if .* = / { | |
1239 | # print "fail in if " $0 | |
1240 | fail("if assignment") | |
1241 | } | |
1242 | (if_brace_end_pos) { | |
1243 | $0 = $0 after_if; | |
1244 | if_brace_end_pos = 0; | |
1245 | in_if = 0; | |
1246 | } | |
1247 | ||
1248 | # Printout of all found bug | |
1249 | ||
1250 | BEGIN { | |
1251 | if (print_doc) { | |
1252 | for (bug in doc) { | |
1253 | fail(bug) | |
1254 | } | |
1255 | exit | |
1256 | } | |
1257 | }' "$@" | |
1258 |