Update years in copyright notice for the GDB files.
[deliverable/binutils-gdb.git] / gdb / contrib / ari / gdb_ari.sh
1 #!/bin/sh
2
3 # GDB script to list of problems using awk.
4 #
5 # Copyright (C) 2002-2013 Free Software Foundation, Inc.
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
25 LANG=C ; export LANG
26 LC_ALL=C ; export LC_ALL
27
28 # Permanent checks take the form:
29
30 # Do not use XXXX, ISO C 90 implies YYYY
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.
63 -W<category> Report problems in the specifed category. Vaid categories
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
133 if [ "$AWK" = "" ] ; then
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
258 # Things in comments
259
260 BEGIN { doc["GNU/Linux"] = "\
261 Do not use `Linux'\'', instead use `Linux kernel'\'' or `GNU/Linux system'\'';\
262 comments should clearly differentiate between the two (this test assumes that\
263 word `Linux'\'' appears on the same line as the word `GNU'\'' or `kernel'\''\
264 or a kernel version"
265 category["GNU/Linux"] = ari_comment
266 }
267 /(^|[^_[:alnum:]])Linux([^_[:alnum:]]|$)/ \
268 && !/(^|[^_[:alnum:]])Linux\[sic\]([^_[:alnum:]]|$)/ \
269 && !/(^|[^_[:alnum:]])GNU\/Linux([^_[:alnum:]]|$)/ \
270 && !/(^|[^_[:alnum:]])Linux kernel([^_[:alnum:]]|$)/ \
271 && !/(^|[^_[:alnum:]])Linux [[:digit:]]\.[[:digit:]]+)/ {
272 fail("GNU/Linux")
273 }
274
275 BEGIN { doc["ARGSUSED"] = "\
276 Do not use ARGSUSED, unnecessary"
277 category["ARGSUSED"] = ari_regression
278 }
279 /(^|[^_[:alnum:]])ARGSUSED([^_[:alnum:]]|$)/ {
280 fail("ARGSUSED")
281 }
282
283
284 # SNIP - Strip out comments - SNIP
285
286 FNR == 1 {
287 comment_p = 0
288 }
289 comment_p && /\*\// { gsub (/^([^\*]|\*+[^\/\*])*\*+\//, " "); comment_p = 0; }
290 comment_p { next; }
291 !comment_p { gsub (/\/\*([^\*]|\*+[^\/\*])*\*+\//, " "); }
292 !comment_p && /(^|[^"])\/\*/ { gsub (/\/\*.*$/, " "); comment_p = 1; }
293
294
295 BEGIN { doc["_ markup"] = "\
296 All messages should be marked up with _."
297 category["_ markup"] = ari_gettext
298 }
299 /^[^"]*[[:space:]](warning|error|error_no_arg|query|perror_with_name)[[:space:]]*\([^_\(a-z]/ {
300 if (! /\("%s"/) {
301 fail("_ markup")
302 }
303 }
304
305 BEGIN { doc["trailing new line"] = "\
306 A message should not have a trailing new line"
307 category["trailing new line"] = ari_gettext
308 }
309 /(^|[^_[:alnum:]])(warning|error)[[:space:]]*\(_\(".*\\n"\)[\),]/ {
310 fail("trailing new line")
311 }
312
313 # Include files for which GDB has a custom version.
314
315 BEGIN { doc["assert.h"] = "\
316 Do not include assert.h, instead include \"gdb_assert.h\"";
317 category["assert.h"] = ari_regression
318 fix("assert.h", "gdb/gdb_assert.h", 0) # it does not use it
319 }
320 /^#[[:space:]]*include[[:space:]]+.assert\.h./ {
321 fail("assert.h")
322 }
323
324 BEGIN { doc["dirent.h"] = "\
325 Do not include dirent.h, instead include gdb_dirent.h"
326 category["dirent.h"] = ari_regression
327 }
328 /^#[[:space:]]*include[[:space:]]*.dirent\.h./ {
329 fail("dirent.h")
330 }
331
332 BEGIN { doc["regex.h"] = "\
333 Do not include regex.h, instead include gdb_regex.h"
334 category["regex.h"] = ari_regression
335 fix("regex.h", "gdb/gdb_regex.h", 1)
336 }
337 /^#[[:space:]]*include[[:space:]]*.regex\.h./ {
338 fail("regex.h")
339 }
340
341 BEGIN { doc["xregex.h"] = "\
342 Do not include xregex.h, instead include gdb_regex.h"
343 category["xregex.h"] = ari_regression
344 fix("xregex.h", "gdb/gdb_regex.h", 1)
345 }
346 /^#[[:space:]]*include[[:space:]]*.xregex\.h./ {
347 fail("xregex.h")
348 }
349
350 BEGIN { doc["gnu-regex.h"] = "\
351 Do not include gnu-regex.h, instead include gdb_regex.h"
352 category["gnu-regex.h"] = ari_regression
353 }
354 /^#[[:space:]]*include[[:space:]]*.gnu-regex\.h./ {
355 fail("gnu regex.h")
356 }
357
358 BEGIN { doc["stat.h"] = "\
359 Do not include stat.h or sys/stat.h, instead include gdb_stat.h"
360 category["stat.h"] = ari_regression
361 fix("stat.h", "common/gdb_stat.h", 1)
362 }
363 /^#[[:space:]]*include[[:space:]]*.stat\.h./ \
364 || /^#[[:space:]]*include[[:space:]]*.sys\/stat\.h./ {
365 fail("stat.h")
366 }
367
368 BEGIN { doc["wait.h"] = "\
369 Do not include wait.h or sys/wait.h, instead include gdb_wait.h"
370 fix("wait.h", "common/gdb_wait.h", 2);
371 category["wait.h"] = ari_regression
372 }
373 /^#[[:space:]]*include[[:space:]]*.wait\.h./ \
374 || /^#[[:space:]]*include[[:space:]]*.sys\/wait\.h./ {
375 fail("wait.h")
376 }
377
378 BEGIN { doc["vfork.h"] = "\
379 Do not include vfork.h, instead include gdb_vfork.h"
380 fix("vfork.h", "gdb/gdb_vfork.h", 1);
381 category["vfork.h"] = ari_regression
382 }
383 /^#[[:space:]]*include[[:space:]]*.vfork\.h./ {
384 fail("vfork.h")
385 }
386
387 BEGIN { doc["error not internal-warning"] = "\
388 Do not use error(\"internal-warning\"), instead use internal_warning"
389 category["error not internal-warning"] = ari_regression
390 }
391 /error.*\"[Ii]nternal.warning/ {
392 fail("error not internal-warning")
393 }
394
395 BEGIN { doc["%p"] = "\
396 Do not use printf(\"%p\"), instead use printf(\"%s\",paddr()) to dump a \
397 target address, or host_address_to_string() for a host address"
398 category["%p"] = ari_code
399 }
400 /%p/ && !/%prec/ {
401 fail("%p")
402 }
403
404 BEGIN { doc["%ll"] = "\
405 Do not use printf(\"%ll\"), instead use printf(\"%s\",phex()) to dump a \
406 `long long'\'' value"
407 category["%ll"] = ari_code
408 }
409 # Allow %ll in scanf
410 /%[0-9]*ll/ && !/scanf \(.*%[0-9]*ll/ {
411 fail("%ll")
412 }
413
414
415 # SNIP - Strip out strings - SNIP
416
417 # Test on top.c, scm-valprint.c, remote-rdi.c, ada-lang.c
418 FNR == 1 {
419 string_p = 0
420 trace_string = 0
421 }
422 # Strip escaped characters.
423 { gsub(/\\./, "."); }
424 # Strip quoted quotes.
425 { gsub(/'\''.'\''/, "'\''.'\''"); }
426 # End of multi-line string
427 string_p && /\"/ {
428 if (trace_string) print "EOS:" FNR, $0;
429 gsub (/^[^\"]*\"/, "'\''");
430 string_p = 0;
431 }
432 # Middle of multi-line string, discard line.
433 string_p {
434 if (trace_string) print "MOS:" FNR, $0;
435 $0 = ""
436 }
437 # Strip complete strings from the middle of the line
438 !string_p && /\"[^\"]*\"/ {
439 if (trace_string) print "COS:" FNR, $0;
440 gsub (/\"[^\"]*\"/, "'\''");
441 }
442 # Start of multi-line string
443 BEGIN { doc["multi-line string"] = "\
444 Multi-line string must have the newline escaped"
445 category["multi-line string"] = ari_regression
446 }
447 !string_p && /\"/ {
448 if (trace_string) print "SOS:" FNR, $0;
449 if (/[^\\]$/) {
450 fail("multi-line string")
451 }
452 gsub (/\"[^\"]*$/, "'\''");
453 string_p = 1;
454 }
455 # { print }
456
457 # Multi-line string
458 string_p &&
459
460 # Accumulate continuation lines
461 FNR == 1 {
462 cont_p = 0
463 }
464 !cont_p { full_line = ""; }
465 /[^\\]\\$/ { gsub (/\\$/, ""); full_line = full_line $0; cont_p = 1; next; }
466 cont_p { $0 = full_line $0; cont_p = 0; full_line = ""; }
467
468
469 # GDB uses ISO C 90. Check for any non pure ISO C 90 code
470
471 BEGIN { doc["PARAMS"] = "\
472 Do not use PARAMS(), ISO C 90 implies prototypes"
473 category["PARAMS"] = ari_regression
474 }
475 /(^|[^_[:alnum:]])PARAMS([^_[:alnum:]]|$)/ {
476 fail("PARAMS")
477 }
478
479 BEGIN { doc["__func__"] = "\
480 Do not use __func__, ISO C 90 does not support this macro"
481 category["__func__"] = ari_regression
482 fix("__func__", "common/gdb_assert.h", 1)
483 }
484 /(^|[^_[:alnum:]])__func__([^_[:alnum:]]|$)/ {
485 fail("__func__")
486 }
487
488 BEGIN { doc["__FUNCTION__"] = "\
489 Do not use __FUNCTION__, ISO C 90 does not support this macro"
490 category["__FUNCTION__"] = ari_regression
491 }
492 /(^|[^_[:alnum:]])__FUNCTION__([^_[:alnum:]]|$)/ {
493 fail("__FUNCTION__")
494 }
495
496 BEGIN { doc["__CYGWIN32__"] = "\
497 Do not use __CYGWIN32__, instead use __CYGWIN__ or, better, an explicit \
498 autoconf tests"
499 category["__CYGWIN32__"] = ari_regression
500 }
501 /(^|[^_[:alnum:]])__CYGWIN32__([^_[:alnum:]]|$)/ {
502 fail("__CYGWIN32__")
503 }
504
505 BEGIN { doc["PTR"] = "\
506 Do not use PTR, ISO C 90 implies `void *'\''"
507 category["PTR"] = ari_regression
508 #fix("PTR", "gdb/utils.c", 6)
509 }
510 /(^|[^_[:alnum:]])PTR([^_[:alnum:]]|$)/ {
511 fail("PTR")
512 }
513
514 BEGIN { doc["UCASE function"] = "\
515 Function name is uppercase."
516 category["UCASE function"] = ari_code
517 possible_UCASE = 0
518 UCASE_full_line = ""
519 }
520 (possible_UCASE) {
521 if (ARI_OK == "UCASE function") {
522 possible_UCASE = 0
523 }
524 # Closing brace found?
525 else if (UCASE_full_line ~ \
526 /^[A-Z][[:alnum:]_]*[[:space:]]*\([^()]*\).*$/) {
527 if ((UCASE_full_line ~ \
528 /^[A-Z][[:alnum:]_]*[[:space:]]*\([^()]*\)[[:space:]]*$/) \
529 && ($0 ~ /^\{/) && (is_yacc_or_lex == 0)) {
530 store_FNR = FNR
531 FNR = possible_FNR
532 store_0 = $0;
533 $0 = UCASE_full_line;
534 fail("UCASE function")
535 FNR = store_FNR
536 $0 = store_0;
537 }
538 possible_UCASE = 0
539 UCASE_full_line = ""
540 } else {
541 UCASE_full_line = UCASE_full_line $0;
542 }
543 }
544 /^[A-Z][[:alnum:]_]*[[:space:]]*\([^()]*(|\))[[:space:]]*$/ {
545 possible_UCASE = 1
546 if (ARI_OK == "UCASE function") {
547 possible_UCASE = 0
548 }
549 possible_FNR = FNR
550 UCASE_full_line = $0
551 }
552
553
554 BEGIN { doc["editCase function"] = "\
555 Function name starts lower case but has uppercased letters."
556 category["editCase function"] = ari_code
557 possible_editCase = 0
558 editCase_full_line = ""
559 }
560 (possible_editCase) {
561 if (ARI_OK == "ediCase function") {
562 possible_editCase = 0
563 }
564 # Closing brace found?
565 else if (editCase_full_line ~ \
566 /^[a-z][a-z0-9_]*[A-Z][a-z0-9A-Z_]*[[:space:]]*\([^()]*\).*$/) {
567 if ((editCase_full_line ~ \
568 /^[a-z][a-z0-9_]*[A-Z][a-z0-9A-Z_]*[[:space:]]*\([^()]*\)[[:space:]]*$/) \
569 && ($0 ~ /^\{/) && (is_yacc_or_lex == 0)) {
570 store_FNR = FNR
571 FNR = possible_FNR
572 store_0 = $0;
573 $0 = editCase_full_line;
574 fail("editCase function")
575 FNR = store_FNR
576 $0 = store_0;
577 }
578 possible_editCase = 0
579 editCase_full_line = ""
580 } else {
581 editCase_full_line = editCase_full_line $0;
582 }
583 }
584 /^[a-z][a-z0-9_]*[A-Z][a-z0-9A-Z_]*[[:space:]]*\([^()]*(|\))[[:space:]]*$/ {
585 possible_editCase = 1
586 if (ARI_OK == "editCase function") {
587 possible_editCase = 0
588 }
589 possible_FNR = FNR
590 editCase_full_line = $0
591 }
592
593 # Only function implementation should be on first column
594 BEGIN { doc["function call in first column"] = "\
595 Function name in first column should be restricted to function implementation"
596 category["function call in first column"] = ari_code
597 }
598 /^[a-z][a-z0-9_]*[[:space:]]*\((|[^*][^()]*)\)[[:space:]]*[^ \t]+/ {
599 fail("function call in first column")
600 }
601
602
603 # Functions without any parameter should have (void)
604 # after their name not simply ().
605 BEGIN { doc["no parameter function"] = "\
606 Function having no parameter should be declared with funcname (void)."
607 category["no parameter function"] = ari_code
608 }
609 /^[a-zA-Z][a-z0-9A-Z_]*[[:space:]]*\(\)/ {
610 fail("no parameter function")
611 }
612
613 BEGIN { doc["hash"] = "\
614 Do not use ` #...'\'', instead use `#...'\''(some compilers only correctly \
615 parse a C preprocessor directive when `#'\'' is the first character on \
616 the line)"
617 category["hash"] = ari_regression
618 }
619 /^[[:space:]]+#/ {
620 fail("hash")
621 }
622
623 BEGIN { doc["OP eol"] = "\
624 Do not use &&, or || at the end of a line"
625 category["OP eol"] = ari_code
626 }
627 /(\|\||\&\&|==|!=)[[:space:]]*$/ {
628 fail("OP eol")
629 }
630
631 BEGIN { doc["strerror"] = "\
632 Do not use strerror(), instead use safe_strerror()"
633 category["strerror"] = ari_regression
634 fix("strerror", "gdb/gdb_string.h", 1)
635 fix("strerror", "gdb/mingw-hdep.c", 1)
636 fix("strerror", "gdb/posix-hdep.c", 1)
637 }
638 /(^|[^_[:alnum:]])strerror[[:space:]]*\(/ {
639 fail("strerror")
640 }
641
642 BEGIN { doc["long long"] = "\
643 Do not use `long long'\'', instead use LONGEST"
644 category["long long"] = ari_code
645 # defs.h needs two such patterns for LONGEST and ULONGEST definitions
646 fix("long long", "gdb/defs.h", 2)
647 }
648 /(^|[^_[:alnum:]])long[[:space:]]+long([^_[:alnum:]]|$)/ {
649 fail("long long")
650 }
651
652 BEGIN { doc["ATTRIBUTE_UNUSED"] = "\
653 Do not use ATTRIBUTE_UNUSED, do not bother (GDB is compiled with -Werror and, \
654 consequently, is not able to tolerate false warnings. Since -Wunused-param \
655 produces such warnings, neither that warning flag nor ATTRIBUTE_UNUSED \
656 are used by GDB"
657 category["ATTRIBUTE_UNUSED"] = ari_regression
658 }
659 /(^|[^_[:alnum:]])ATTRIBUTE_UNUSED([^_[:alnum:]]|$)/ {
660 fail("ATTRIBUTE_UNUSED")
661 }
662
663 BEGIN { doc["ATTR_FORMAT"] = "\
664 Do not use ATTR_FORMAT, use ATTRIBUTE_PRINTF instead"
665 category["ATTR_FORMAT"] = ari_regression
666 }
667 /(^|[^_[:alnum:]])ATTR_FORMAT([^_[:alnum:]]|$)/ {
668 fail("ATTR_FORMAT")
669 }
670
671 BEGIN { doc["ATTR_NORETURN"] = "\
672 Do not use ATTR_NORETURN, use ATTRIBUTE_NORETURN instead"
673 category["ATTR_NORETURN"] = ari_regression
674 }
675 /(^|[^_[:alnum:]])ATTR_NORETURN([^_[:alnum:]]|$)/ {
676 fail("ATTR_NORETURN")
677 }
678
679 BEGIN { doc["NORETURN"] = "\
680 Do not use NORETURN, use ATTRIBUTE_NORETURN instead"
681 category["NORETURN"] = ari_regression
682 }
683 /(^|[^_[:alnum:]])NORETURN([^_[:alnum:]]|$)/ {
684 fail("NORETURN")
685 }
686
687
688 # General problems
689
690 BEGIN { doc["multiple messages"] = "\
691 Do not use multiple calls to warning or error, instead use a single call"
692 category["multiple messages"] = ari_gettext
693 }
694 FNR == 1 {
695 warning_fnr = -1
696 }
697 /(^|[^_[:alnum:]])(warning|error)[[:space:]]*\(/ {
698 if (FNR == warning_fnr + 1) {
699 fail("multiple messages")
700 } else {
701 warning_fnr = FNR
702 }
703 }
704
705 # Commented out, but left inside sources, just in case.
706 # BEGIN { doc["inline"] = "\
707 # Do not use the inline attribute; \
708 # since the compiler generally ignores this, better algorithm selection \
709 # is needed to improved performance"
710 # category["inline"] = ari_code
711 # }
712 # /(^|[^_[:alnum:]])inline([^_[:alnum:]]|$)/ {
713 # fail("inline")
714 # }
715
716 # This test is obsolete as this type
717 # has been deprecated and finally suppressed from GDB sources
718 #BEGIN { doc["obj_private"] = "\
719 #Replace obj_private with objfile_data"
720 # category["obj_private"] = ari_obsolete
721 #}
722 #/(^|[^_[:alnum:]])obj_private([^_[:alnum:]]|$)/ {
723 # fail("obj_private")
724 #}
725
726 BEGIN { doc["abort"] = "\
727 Do not use abort, instead use internal_error; GDB should never abort"
728 category["abort"] = ari_regression
729 fix("abort", "gdb/utils.c", 3)
730 }
731 /(^|[^_[:alnum:]])abort[[:space:]]*\(/ {
732 fail("abort")
733 }
734
735 BEGIN { doc["basename"] = "\
736 Do not use basename, instead use lbasename"
737 category["basename"] = ari_regression
738 }
739 /(^|[^_[:alnum:]])basename[[:space:]]*\(/ {
740 fail("basename")
741 }
742
743 BEGIN { doc["assert"] = "\
744 Do not use assert, instead use gdb_assert or internal_error; assert \
745 calls abort and GDB should never call abort"
746 category["assert"] = ari_regression
747 }
748 /(^|[^_[:alnum:]])assert[[:space:]]*\(/ {
749 fail("assert")
750 }
751
752 BEGIN { doc["TARGET_HAS_HARDWARE_WATCHPOINTS"] = "\
753 Replace TARGET_HAS_HARDWARE_WATCHPOINTS with nothing, not needed"
754 category["TARGET_HAS_HARDWARE_WATCHPOINTS"] = ari_regression
755 }
756 /(^|[^_[:alnum:]])TARGET_HAS_HARDWARE_WATCHPOINTS([^_[:alnum:]]|$)/ {
757 fail("TARGET_HAS_HARDWARE_WATCHPOINTS")
758 }
759
760 BEGIN { doc["ADD_SHARED_SYMBOL_FILES"] = "\
761 Replace ADD_SHARED_SYMBOL_FILES with nothing, not needed?"
762 category["ADD_SHARED_SYMBOL_FILES"] = ari_regression
763 }
764 /(^|[^_[:alnum:]])ADD_SHARED_SYMBOL_FILES([^_[:alnum:]]|$)/ {
765 fail("ADD_SHARED_SYMBOL_FILES")
766 }
767
768 BEGIN { doc["SOLIB_ADD"] = "\
769 Replace SOLIB_ADD with nothing, not needed?"
770 category["SOLIB_ADD"] = ari_deprecate
771 }
772 /(^|[^_[:alnum:]])SOLIB_ADD([^_[:alnum:]]|$)/ {
773 fail("SOLIB_ADD")
774 }
775
776 BEGIN { doc["SOLIB_CREATE_INFERIOR_HOOK"] = "\
777 Replace SOLIB_CREATE_INFERIOR_HOOK with nothing, not needed?"
778 category["SOLIB_CREATE_INFERIOR_HOOK"] = ari_deprecate
779 }
780 /(^|[^_[:alnum:]])SOLIB_CREATE_INFERIOR_HOOK([^_[:alnum:]]|$)/ {
781 fail("SOLIB_CREATE_INFERIOR_HOOK")
782 }
783
784 BEGIN { doc["SOLIB_LOADED_LIBRARY_PATHNAME"] = "\
785 Replace SOLIB_LOADED_LIBRARY_PATHNAME with nothing, not needed?"
786 category["SOLIB_LOADED_LIBRARY_PATHNAME"] = ari_regression
787 }
788 /(^|[^_[:alnum:]])SOLIB_LOADED_LIBRARY_PATHNAME([^_[:alnum:]]|$)/ {
789 fail("SOLIB_LOADED_LIBRARY_PATHNAME")
790 }
791
792 BEGIN { doc["REGISTER_U_ADDR"] = "\
793 Replace REGISTER_U_ADDR with nothing, not needed?"
794 category["REGISTER_U_ADDR"] = ari_regression
795 }
796 /(^|[^_[:alnum:]])REGISTER_U_ADDR([^_[:alnum:]]|$)/ {
797 fail("REGISTER_U_ADDR")
798 }
799
800 BEGIN { doc["PROCESS_LINENUMBER_HOOK"] = "\
801 Replace PROCESS_LINENUMBER_HOOK with nothing, not needed?"
802 category["PROCESS_LINENUMBER_HOOK"] = ari_regression
803 }
804 /(^|[^_[:alnum:]])PROCESS_LINENUMBER_HOOK([^_[:alnum:]]|$)/ {
805 fail("PROCESS_LINENUMBER_HOOK")
806 }
807
808 BEGIN { doc["PC_SOLIB"] = "\
809 Replace PC_SOLIB with nothing, not needed?"
810 category["PC_SOLIB"] = ari_deprecate
811 }
812 /(^|[^_[:alnum:]])PC_SOLIB([^_[:alnum:]]|$)/ {
813 fail("PC_SOLIB")
814 }
815
816 BEGIN { doc["IN_SOLIB_DYNSYM_RESOLVE_CODE"] = "\
817 Replace IN_SOLIB_DYNSYM_RESOLVE_CODE with nothing, not needed?"
818 category["IN_SOLIB_DYNSYM_RESOLVE_CODE"] = ari_regression
819 }
820 /(^|[^_[:alnum:]])IN_SOLIB_DYNSYM_RESOLVE_CODE([^_[:alnum:]]|$)/ {
821 fail("IN_SOLIB_DYNSYM_RESOLVE_CODE")
822 }
823
824 BEGIN { doc["GCC_COMPILED_FLAG_SYMBOL"] = "\
825 Replace GCC_COMPILED_FLAG_SYMBOL with nothing, not needed?"
826 category["GCC_COMPILED_FLAG_SYMBOL"] = ari_deprecate
827 }
828 /(^|[^_[:alnum:]])GCC_COMPILED_FLAG_SYMBOL([^_[:alnum:]]|$)/ {
829 fail("GCC_COMPILED_FLAG_SYMBOL")
830 }
831
832 BEGIN { doc["GCC2_COMPILED_FLAG_SYMBOL"] = "\
833 Replace GCC2_COMPILED_FLAG_SYMBOL with nothing, not needed?"
834 category["GCC2_COMPILED_FLAG_SYMBOL"] = ari_deprecate
835 }
836 /(^|[^_[:alnum:]])GCC2_COMPILED_FLAG_SYMBOL([^_[:alnum:]]|$)/ {
837 fail("GCC2_COMPILED_FLAG_SYMBOL")
838 }
839
840 BEGIN { doc["FUNCTION_EPILOGUE_SIZE"] = "\
841 Replace FUNCTION_EPILOGUE_SIZE with nothing, not needed?"
842 category["FUNCTION_EPILOGUE_SIZE"] = ari_regression
843 }
844 /(^|[^_[:alnum:]])FUNCTION_EPILOGUE_SIZE([^_[:alnum:]]|$)/ {
845 fail("FUNCTION_EPILOGUE_SIZE")
846 }
847
848 BEGIN { doc["HAVE_VFORK"] = "\
849 Do not use HAVE_VFORK, instead include \"gdb_vfork.h\" and call vfork() \
850 unconditionally"
851 category["HAVE_VFORK"] = ari_regression
852 }
853 /(^|[^_[:alnum:]])HAVE_VFORK([^_[:alnum:]]|$)/ {
854 fail("HAVE_VFORK")
855 }
856
857 BEGIN { doc["bcmp"] = "\
858 Do not use bcmp(), ISO C 90 implies memcmp()"
859 category["bcmp"] = ari_regression
860 }
861 /(^|[^_[:alnum:]])bcmp[[:space:]]*\(/ {
862 fail("bcmp")
863 }
864
865 BEGIN { doc["setlinebuf"] = "\
866 Do not use setlinebuf(), ISO C 90 implies setvbuf()"
867 category["setlinebuf"] = ari_regression
868 }
869 /(^|[^_[:alnum:]])setlinebuf[[:space:]]*\(/ {
870 fail("setlinebuf")
871 }
872
873 BEGIN { doc["bcopy"] = "\
874 Do not use bcopy(), ISO C 90 implies memcpy() and memmove()"
875 category["bcopy"] = ari_regression
876 }
877 /(^|[^_[:alnum:]])bcopy[[:space:]]*\(/ {
878 fail("bcopy")
879 }
880
881 BEGIN { doc["get_frame_base"] = "\
882 Replace get_frame_base with get_frame_id, get_frame_base_address, \
883 get_frame_locals_address, or get_frame_args_address."
884 category["get_frame_base"] = ari_obsolete
885 }
886 /(^|[^_[:alnum:]])get_frame_base([^_[:alnum:]]|$)/ {
887 fail("get_frame_base")
888 }
889
890 BEGIN { doc["floatformat_to_double"] = "\
891 Do not use floatformat_to_double() from libierty, \
892 instead use floatformat_to_doublest()"
893 fix("floatformat_to_double", "gdb/doublest.c", 1)
894 category["floatformat_to_double"] = ari_regression
895 }
896 /(^|[^_[:alnum:]])floatformat_to_double[[:space:]]*\(/ {
897 fail("floatformat_to_double")
898 }
899
900 BEGIN { doc["floatformat_from_double"] = "\
901 Do not use floatformat_from_double() from libierty, \
902 instead use floatformat_from_doublest()"
903 category["floatformat_from_double"] = ari_regression
904 }
905 /(^|[^_[:alnum:]])floatformat_from_double[[:space:]]*\(/ {
906 fail("floatformat_from_double")
907 }
908
909 BEGIN { doc["BIG_ENDIAN"] = "\
910 Do not use BIG_ENDIAN, instead use BFD_ENDIAN_BIG"
911 category["BIG_ENDIAN"] = ari_regression
912 }
913 /(^|[^_[:alnum:]])BIG_ENDIAN([^_[:alnum:]]|$)/ {
914 fail("BIG_ENDIAN")
915 }
916
917 BEGIN { doc["LITTLE_ENDIAN"] = "\
918 Do not use LITTLE_ENDIAN, instead use BFD_ENDIAN_LITTLE";
919 category["LITTLE_ENDIAN"] = ari_regression
920 }
921 /(^|[^_[:alnum:]])LITTLE_ENDIAN([^_[:alnum:]]|$)/ {
922 fail("LITTLE_ENDIAN")
923 }
924
925 BEGIN { doc["BIG_ENDIAN"] = "\
926 Do not use BIG_ENDIAN, instead use BFD_ENDIAN_BIG"
927 category["BIG_ENDIAN"] = ari_regression
928 }
929 /(^|[^_[:alnum:]])BIG_ENDIAN([^_[:alnum:]]|$)/ {
930 fail("BIG_ENDIAN")
931 }
932
933 BEGIN { doc["sec_ptr"] = "\
934 Instead of sec_ptr, use struct bfd_section";
935 category["sec_ptr"] = ari_regression
936 }
937 /(^|[^_[:alnum:]])sec_ptr([^_[:alnum:]]|$)/ {
938 fail("sec_ptr")
939 }
940
941 BEGIN { doc["frame_unwind_unsigned_register"] = "\
942 Replace frame_unwind_unsigned_register with frame_unwind_register_unsigned"
943 category["frame_unwind_unsigned_register"] = ari_regression
944 }
945 /(^|[^_[:alnum:]])frame_unwind_unsigned_register([^_[:alnum:]]|$)/ {
946 fail("frame_unwind_unsigned_register")
947 }
948
949 BEGIN { doc["frame_register_read"] = "\
950 Replace frame_register_read() with get_frame_register(), or \
951 possibly introduce a new method safe_get_frame_register()"
952 category["frame_register_read"] = ari_obsolete
953 }
954 /(^|[^_[:alnum:]])frame_register_read([^_[:alnum:]]|$)/ {
955 fail("frame_register_read")
956 }
957
958 BEGIN { doc["read_register"] = "\
959 Replace read_register() with regcache_read() et.al."
960 category["read_register"] = ari_regression
961 }
962 /(^|[^_[:alnum:]])read_register([^_[:alnum:]]|$)/ {
963 fail("read_register")
964 }
965
966 BEGIN { doc["write_register"] = "\
967 Replace write_register() with regcache_read() et.al."
968 category["write_register"] = ari_regression
969 }
970 /(^|[^_[:alnum:]])write_register([^_[:alnum:]]|$)/ {
971 fail("write_register")
972 }
973
974 function report(name) {
975 # Drop any trailing _P.
976 name = gensub(/(_P|_p)$/, "", 1, name)
977 # Convert to lower case
978 name = tolower(name)
979 # Split into category and bug
980 cat = gensub(/^([[:alpha:]]+)_([_[:alnum:]]*)$/, "\\1", 1, name)
981 bug = gensub(/^([[:alpha:]]+)_([_[:alnum:]]*)$/, "\\2", 1, name)
982 # Report it
983 name = cat " " bug
984 doc[name] = "Do not use " cat " " bug ", see declaration for details"
985 category[name] = cat
986 fail(name)
987 }
988
989 /(^|[^_[:alnum:]])(DEPRECATED|deprecated|set_gdbarch_deprecated|LEGACY|legacy|set_gdbarch_legacy)_/ {
990 line = $0
991 # print "0 =", $0
992 while (1) {
993 name = gensub(/^(|.*[^_[:alnum:]])((DEPRECATED|deprecated|LEGACY|legacy)_[_[:alnum:]]*)(.*)$/, "\\2", 1, line)
994 line = gensub(/^(|.*[^_[:alnum:]])((DEPRECATED|deprecated|LEGACY|legacy)_[_[:alnum:]]*)(.*)$/, "\\1 \\4", 1, line)
995 # print "name =", name, "line =", line
996 if (name == line) break;
997 report(name)
998 }
999 }
1000
1001 # Count the number of times each architecture method is set
1002 /(^|[^_[:alnum:]])set_gdbarch_[_[:alnum:]]*([^_[:alnum:]]|$)/ {
1003 name = gensub(/^.*set_gdbarch_([_[:alnum:]]*).*$/, "\\1", 1, $0)
1004 doc["set " name] = "\
1005 Call to set_gdbarch_" name
1006 category["set " name] = ari_gdbarch
1007 fail("set " name)
1008 }
1009
1010 # Count the number of times each tm/xm/nm macro is defined or undefined
1011 /^#[[:space:]]*(undef|define)[[:space:]]+[[:alnum:]_]+.*$/ \
1012 && !/^#[[:space:]]*(undef|define)[[:space:]]+[[:alnum:]_]+_H($|[[:space:]])/ \
1013 && FILENAME ~ /(^|\/)config\/(|[^\/]*\/)(tm-|xm-|nm-).*\.h$/ {
1014 basename = gensub(/(^|.*\/)([^\/]*)$/, "\\2", 1, FILENAME)
1015 type = gensub(/^(tm|xm|nm)-.*\.h$/, "\\1", 1, basename)
1016 name = gensub(/^#[[:space:]]*(undef|define)[[:space:]]+([[:alnum:]_]+).*$/, "\\2", 1, $0)
1017 if (type == basename) {
1018 type = "macro"
1019 }
1020 doc[type " " name] = "\
1021 Do not define macros such as " name " in a tm, nm or xm file, \
1022 in fact do not provide a tm, nm or xm file"
1023 category[type " " name] = ari_macro
1024 fail(type " " name)
1025 }
1026
1027 BEGIN { doc["deprecated_registers"] = "\
1028 Replace deprecated_registers with nothing, they have reached \
1029 end-of-life"
1030 category["deprecated_registers"] = ari_eol
1031 }
1032 /(^|[^_[:alnum:]])deprecated_registers([^_[:alnum:]]|$)/ {
1033 fail("deprecated_registers")
1034 }
1035
1036 BEGIN { doc["read_pc"] = "\
1037 Replace READ_PC() with frame_pc_unwind; \
1038 at present the inferior function call code still uses this"
1039 category["read_pc"] = ari_deprecate
1040 }
1041 /(^|[^_[:alnum:]])read_pc[[:space:]]*\(/ || \
1042 /(^|[^_[:alnum:]])set_gdbarch_read_pc[[:space:]]*\(/ || \
1043 /(^|[^_[:alnum:]])TARGET_READ_PC[[:space:]]*\(/ {
1044 fail("read_pc")
1045 }
1046
1047 BEGIN { doc["write_pc"] = "\
1048 Replace write_pc() with get_frame_base_address or get_frame_id; \
1049 at present the inferior function call code still uses this when doing \
1050 a DECR_PC_AFTER_BREAK"
1051 category["write_pc"] = ari_deprecate
1052 }
1053 /(^|[^_[:alnum:]])write_pc[[:space:]]*\(/ || \
1054 /(^|[^_[:alnum:]])set_gdbarch_write_pc[[:space:]]*\(/ || \
1055 /(^|[^_[:alnum:]])TARGET_WRITE_PC[[:space:]]*\(/ {
1056 fail("write_pc")
1057 }
1058
1059 BEGIN { doc["generic_target_write_pc"] = "\
1060 Replace generic_target_write_pc with a per-architecture implementation, \
1061 this relies on PC_REGNUM which is being eliminated"
1062 category["generic_target_write_pc"] = ari_regression
1063 }
1064 /(^|[^_[:alnum:]])generic_target_write_pc([^_[:alnum:]]|$)/ {
1065 fail("generic_target_write_pc")
1066 }
1067
1068 BEGIN { doc["read_sp"] = "\
1069 Replace read_sp() with frame_sp_unwind"
1070 category["read_sp"] = ari_regression
1071 }
1072 /(^|[^_[:alnum:]])read_sp[[:space:]]*\(/ || \
1073 /(^|[^_[:alnum:]])set_gdbarch_read_sp[[:space:]]*\(/ || \
1074 /(^|[^_[:alnum:]])TARGET_READ_SP[[:space:]]*\(/ {
1075 fail("read_sp")
1076 }
1077
1078 BEGIN { doc["register_cached"] = "\
1079 Replace register_cached() with nothing, does not have a regcache parameter"
1080 category["register_cached"] = ari_regression
1081 }
1082 /(^|[^_[:alnum:]])register_cached[[:space:]]*\(/ {
1083 fail("register_cached")
1084 }
1085
1086 BEGIN { doc["set_register_cached"] = "\
1087 Replace set_register_cached() with nothing, does not have a regcache parameter"
1088 category["set_register_cached"] = ari_regression
1089 }
1090 /(^|[^_[:alnum:]])set_register_cached[[:space:]]*\(/ {
1091 fail("set_register_cached")
1092 }
1093
1094 # Print functions: Use versions that either check for buffer overflow
1095 # or safely allocate a fresh buffer.
1096
1097 BEGIN { doc["sprintf"] = "\
1098 Do not use sprintf, instead use xsnprintf or xstrprintf"
1099 category["sprintf"] = ari_code
1100 }
1101 /(^|[^_[:alnum:]])sprintf[[:space:]]*\(/ {
1102 fail("sprintf")
1103 }
1104
1105 BEGIN { doc["vsprintf"] = "\
1106 Do not use vsprintf(), instead use xstrvprintf"
1107 category["vsprintf"] = ari_regression
1108 }
1109 /(^|[^_[:alnum:]])vsprintf[[:space:]]*\(/ {
1110 fail("vsprintf")
1111 }
1112
1113 BEGIN { doc["asprintf"] = "\
1114 Do not use asprintf(), instead use xstrprintf()"
1115 category["asprintf"] = ari_regression
1116 }
1117 /(^|[^_[:alnum:]])asprintf[[:space:]]*\(/ {
1118 fail("asprintf")
1119 }
1120
1121 BEGIN { doc["vasprintf"] = "\
1122 Do not use vasprintf(), instead use xstrvprintf"
1123 fix("vasprintf", "common/common-utils.c", 1)
1124 category["vasprintf"] = ari_regression
1125 }
1126 /(^|[^_[:alnum:]])vasprintf[[:space:]]*\(/ {
1127 fail("vasprintf")
1128 }
1129
1130 # More generic memory operations
1131
1132 BEGIN { doc["bzero"] = "\
1133 Do not use bzero(), instead use memset()"
1134 category["bzero"] = ari_regression
1135 }
1136 /(^|[^_[:alnum:]])bzero[[:space:]]*\(/ {
1137 fail("bzero")
1138 }
1139
1140 BEGIN { doc["strdup"] = "\
1141 Do not use strdup(), instead use xstrdup()";
1142 category["strdup"] = ari_regression
1143 }
1144 /(^|[^_[:alnum:]])strdup[[:space:]]*\(/ {
1145 fail("strdup")
1146 }
1147
1148 BEGIN { doc["strsave"] = "\
1149 Do not use strsave(), instead use xstrdup() et.al."
1150 category["strsave"] = ari_regression
1151 }
1152 /(^|[^_[:alnum:]])strsave[[:space:]]*\(/ {
1153 fail("strsave")
1154 }
1155
1156 # String compare functions
1157
1158 BEGIN { doc["strnicmp"] = "\
1159 Do not use strnicmp(), instead use strncasecmp()"
1160 category["strnicmp"] = ari_regression
1161 }
1162 /(^|[^_[:alnum:]])strnicmp[[:space:]]*\(/ {
1163 fail("strnicmp")
1164 }
1165
1166 # Boolean expressions and conditionals
1167
1168 BEGIN { doc["boolean"] = "\
1169 Do not use `boolean'\'', use `int'\'' instead"
1170 category["boolean"] = ari_regression
1171 }
1172 /(^|[^_[:alnum:]])boolean([^_[:alnum:]]|$)/ {
1173 if (is_yacc_or_lex == 0) {
1174 fail("boolean")
1175 }
1176 }
1177
1178 BEGIN { doc["false"] = "\
1179 Definitely do not use `false'\'' in boolean expressions"
1180 category["false"] = ari_regression
1181 }
1182 /(^|[^_[:alnum:]])false([^_[:alnum:]]|$)/ {
1183 if (is_yacc_or_lex == 0) {
1184 fail("false")
1185 }
1186 }
1187
1188 BEGIN { doc["true"] = "\
1189 Do not try to use `true'\'' in boolean expressions"
1190 category["true"] = ari_regression
1191 }
1192 /(^|[^_[:alnum:]])true([^_[:alnum:]]|$)/ {
1193 if (is_yacc_or_lex == 0) {
1194 fail("true")
1195 }
1196 }
1197
1198 # Typedefs that are either redundant or can be reduced to `struct
1199 # type *''.
1200 # Must be placed before if assignment otherwise ARI exceptions
1201 # are not handled correctly.
1202
1203 BEGIN { doc["d_namelen"] = "\
1204 Do not use dirent.d_namelen, instead use NAMELEN"
1205 category["d_namelen"] = ari_regression
1206 }
1207 /(^|[^_[:alnum:]])d_namelen([^_[:alnum:]]|$)/ {
1208 fail("d_namelen")
1209 }
1210
1211 BEGIN { doc["strlen d_name"] = "\
1212 Do not use strlen dirent.d_name, instead use NAMELEN"
1213 category["strlen d_name"] = ari_regression
1214 }
1215 /(^|[^_[:alnum:]])strlen[[:space:]]*\(.*[^_[:alnum:]]d_name([^_[:alnum:]]|$)/ {
1216 fail("strlen d_name")
1217 }
1218
1219 BEGIN { doc["var_boolean"] = "\
1220 Replace var_boolean with add_setshow_boolean_cmd"
1221 category["var_boolean"] = ari_regression
1222 fix("var_boolean", "gdb/command.h", 1)
1223 # fix only uses the last directory level
1224 fix("var_boolean", "cli/cli-decode.c", 2)
1225 }
1226 /(^|[^_[:alnum:]])var_boolean([^_[:alnum:]]|$)/ {
1227 if (($0 !~ /(^|[^_[:alnum:]])case *var_boolean:/) \
1228 && ($0 !~ /(^|[^_[:alnum:]])[=!]= *var_boolean/)) {
1229 fail("var_boolean")
1230 }
1231 }
1232
1233 BEGIN { doc["generic_use_struct_convention"] = "\
1234 Replace generic_use_struct_convention with nothing, \
1235 EXTRACT_STRUCT_VALUE_ADDRESS is a predicate"
1236 category["generic_use_struct_convention"] = ari_regression
1237 }
1238 /(^|[^_[:alnum:]])generic_use_struct_convention([^_[:alnum:]]|$)/ {
1239 fail("generic_use_struct_convention")
1240 }
1241
1242 BEGIN { doc["if assignment"] = "\
1243 An IF statement'\''s expression contains an assignment (the GNU coding \
1244 standard discourages this)"
1245 category["if assignment"] = ari_code
1246 }
1247 BEGIN { doc["if clause more than 50 lines"] = "\
1248 An IF statement'\''s expression expands over 50 lines"
1249 category["if clause more than 50 lines"] = ari_code
1250 }
1251 #
1252 # Accumulate continuation lines
1253 FNR == 1 {
1254 in_if = 0
1255 }
1256
1257 /(^|[^_[:alnum:]])if / {
1258 in_if = 1;
1259 if_brace_level = 0;
1260 if_cont_p = 0;
1261 if_count = 0;
1262 if_brace_end_pos = 0;
1263 if_full_line = "";
1264 }
1265 (in_if) {
1266 # We want everything up to closing brace of same level
1267 if_count++;
1268 if (if_count > 50) {
1269 print "multiline if: " if_full_line $0
1270 fail("if clause more than 50 lines")
1271 if_brace_level = 0;
1272 if_full_line = "";
1273 } else {
1274 if (if_count == 1) {
1275 i = index($0,"if ");
1276 } else {
1277 i = 1;
1278 }
1279 for (i=i; i <= length($0); i++) {
1280 char = substr($0,i,1);
1281 if (char == "(") { if_brace_level++; }
1282 if (char == ")") {
1283 if_brace_level--;
1284 if (!if_brace_level) {
1285 if_brace_end_pos = i;
1286 after_if = substr($0,i+1,length($0));
1287 # Do not parse what is following
1288 break;
1289 }
1290 }
1291 }
1292 if (if_brace_level == 0) {
1293 $0 = substr($0,1,i);
1294 in_if = 0;
1295 } else {
1296 if_full_line = if_full_line $0;
1297 if_cont_p = 1;
1298 next;
1299 }
1300 }
1301 }
1302 # if we arrive here, we need to concatenate, but we are at brace level 0
1303
1304 (if_brace_end_pos) {
1305 $0 = if_full_line substr($0,1,if_brace_end_pos);
1306 if (if_count > 1) {
1307 # print "IF: multi line " if_count " found at " FILENAME ":" FNR " \"" $0 "\""
1308 }
1309 if_cont_p = 0;
1310 if_full_line = "";
1311 }
1312 /(^|[^_[:alnum:]])if .* = / {
1313 # print "fail in if " $0
1314 fail("if assignment")
1315 }
1316 (if_brace_end_pos) {
1317 $0 = $0 after_if;
1318 if_brace_end_pos = 0;
1319 in_if = 0;
1320 }
1321
1322 # Printout of all found bug
1323
1324 BEGIN {
1325 if (print_doc) {
1326 for (bug in doc) {
1327 fail(bug)
1328 }
1329 exit
1330 }
1331 }' "$@"
1332
This page took 0.057256 seconds and 5 git commands to generate.