21ad58eb918b6e1a13ed0943d235c7c228a8b8a9
3 # GDB script to list of problems using awk.
5 # Copyright (C) 2002-2012 Free Software Foundation, Inc.
7 # This file is part of GDB.
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.
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.
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/>.
22 # Make certain that the script is not running in an internationalized
26 LC_ALL
=c
; export LC_ALL
28 # Permanent checks take the form:
30 # Do not use XXXX, ISO C 90 implies YYYY
31 # Do not use XXXX, instead use YYYY''.
33 # and should never be removed.
35 # Temporary checks take the form:
37 # Replace XXXX with YYYY
39 # and once they reach zero, can be eliminated.
41 # FIXME: It should be able to override this on the command line
44 ari
="regression eol code comment deprecated legacy obsolete gettext"
45 all
="regression eol code comment deprecated legacy obsolete gettext deprecate internal gdbarch macro"
55 $0 --print-doc --print-idx -Wall -Werror -W<category> <file> ...
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
70 # Parse the various options
76 -Wall ) Woptions
="${all}" ;;
77 -Wari ) Woptions
="${ari}" ;;
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=\"/'`\"" ;;
85 -* ) usage
"$1: unknown option" ;;
90 if test -n "$Woptions" ; then
96 # -Werror implies treating all warnings as errors.
97 if test -n "${Werror}" ; then
98 error
="${error} ${warning}"
102 # Validate all errors and warnings.
103 for w
in ${warning} ${error}
107 * ) usage
"Unknown option -W${w}" ;;
112 # make certain that there is at least one file.
113 if test $# -eq 0 -a ${print_doc} = 0
115 usage
"Missing file."
119 # Convert the errors/warnings into corresponding array entries.
122 aris
="${aris} ari_${a} = \"${a}\";"
126 warnings
="${warnings} warning[ari_${w}] = 1;"
130 errors
="${errors} error[ari_${e}] = 1;"
133 if [ "$AWK" == "" ] ; then
139 # NOTE, for a per-file begin use "FNR == 1".
144 print_doc = '$print_doc'
145 print_idx = '$print_idx'
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) {
157 suffix = " (" supplement ")"
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
168 function fix(bug,file,count) {
169 skip[bug, file] = count
170 skipped[bug, file] = 0
173 function fail(bug,supplement) {
174 if (doc[bug] == "") {
175 print_bug("", 0, "internal: ", "internal", "internal", "Missing doc for bug " bug)
178 if (category[bug] == "") {
179 print_bug("", 0, "internal: ", "internal", "internal", "Missing category for bug " bug)
186 # Trim the filename down to just DIRECTORY/FILE so that it can be
187 # robustly used by the FIX code.
189 if (FILENAME ~ /^\//) {
190 canonicalname = FILENAME
192 canonicalname = PWD "/" FILENAME
194 shortname = gensub (/^.*\/([^\\]*\/[^\\]*)$/, "\\1", 1, canonicalname)
196 skipped[bug, shortname]++
197 if (skip[bug, shortname] >= skipped[bug, shortname]) {
198 # print FILENAME, FNR, skip[bug, FILENAME], skipped[bug, FILENAME], bug
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)
211 if (match(FILENAME, "\\.[ly]$")) {
212 # FILENAME is a lex or yacc source
225 # Did we do only a partial skip?
226 for (bug_n_file in skip) {
227 split (bug_n_file, a, SUBSEP)
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])
239 # Skip OBSOLETE lines
240 /(^|[^_[:alnum:]])OBSOLETE([^_[:alnum:]]|$)/ { next; }
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 "\""
253 ! /\/\* ARI:[[:space:]]*(.*)[[:space:]]*\*\// {
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'\''\
265 category["GNU/Linux"] = ari_comment
267 /(^|[^_[:alnum:]])Linux([^_[:alnum:]]|$)/ \
268 && !/(^|[^_[:alnum:]])Linux\[sic\]([^_[:alnum:]]|$)/ \
269 && !/(^|[^_[:alnum:]])GNU\/Linux([^_[:alnum:]]|$)/ \
270 && !/(^|[^_[:alnum:]])Linux kernel([^_[:alnum:]]|$)/ \
271 && !/(^|[^_[:alnum:]])Linux [:digit:]\.[:digit:]+)/ {
275 BEGIN { doc["ARGSUSED"] = "\
276 Do not use ARGSUSED, unnecessary"
277 category["ARGSUSED"] = ari_regression
279 /(^|[^_[:alnum:]])ARGSUSED([^_[:alnum:]]|$)/ {
284 # SNIP - Strip out comments - SNIP
289 comment_p && /\*\// { gsub (/^([^\*]|\*+[^\/\*])*\*+\//, " "); comment_p = 0; }
291 !comment_p { gsub (/\/\*([^\*]|\*+[^\/\*])*\*+\//, " "); }
292 !comment_p && /(^|[^"])\/\*/ { gsub (/\/\*.*$/, " "); comment_p = 1; }
295 BEGIN { doc["_ markup"] = "\
296 All messages should be marked up with _."
297 category["_ markup"] = ari_gettext
299 /^[^"]*[[:space:]](warning|error|error_no_arg|query|perror_with_name)[[:space:]]*\([^_\(a-z]/ {
305 BEGIN { doc["trailing new line"] = "\
306 A message should not have a trailing new line"
307 category["trailing new line"] = ari_gettext
309 /(^|[^_[:alnum:]])(warning|error)[[:space:]]*\(_\(".*\\n"\)[\),]/ {
310 fail("trailing new line")
313 # Include files for which GDB has a custom version.
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
320 /^#[[:space:]]*include[[:space:]]+.assert\.h./ {
324 BEGIN { doc["dirent.h"] = "\
325 Do not include dirent.h, instead include gdb_dirent.h"
326 category["dirent.h"] = ari_regression
328 /^#[[:space:]]*include[[:space:]]*.dirent\.h./ {
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)
337 /^#[[:space:]]*include[[:space:]]*.regex\.h./ {
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)
346 /^#[[:space:]]*include[[:space:]]*.xregex\.h./ {
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
354 /^#[[:space:]]*include[[:space:]]*.gnu-regex\.h./ {
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", "gdb/gdb_stat.h", 1)
363 /^#[[:space:]]*include[[:space:]]*.stat\.h./ \
364 || /^#[[:space:]]*include[[:space:]]*.sys\/stat\.h./ {
368 BEGIN { doc["wait.h"] = "\
369 Do not include wait.h or sys/wait.h, instead include gdb_wait.h"
370 fix("wait.h", "gdb/gdb_wait.h", 2);
371 category["wait.h"] = ari_regression
373 /^#[[:space:]]*include[[:space:]]*.wait\.h./ \
374 || /^#[[:space:]]*include[[:space:]]*.sys\/wait\.h./ {
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
383 /^#[[:space:]]*include[[:space:]]*.vfork\.h./ {
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
391 /error.*\"[Ii]nternal.warning/ {
392 fail("error not internal-warning")
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
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
410 /%[0-9]*ll/ && !/scanf \(.*%[0-9]*ll/ {
415 # SNIP - Strip out strings - SNIP
417 # Test on top.c, scm-valprint.c, remote-rdi.c, ada-lang.c
422 # Strip escaped characters.
423 { gsub(/\\./, "."); }
424 # Strip quoted quotes.
425 { gsub(/'\''.'\''/, "'\''.'\''"); }
426 # End of multi-line string
428 if (trace_string) print "EOS:" FNR, $0;
429 gsub (/^[^\"]*\"/, "'\''");
432 # Middle of multi-line string, discard line.
434 if (trace_string) print "MOS:" FNR, $0;
437 # Strip complete strings from the middle of the line
438 !string_p && /\"[^\"]*\"/ {
439 if (trace_string) print "COS:" FNR, $0;
440 gsub (/\"[^\"]*\"/, "'\''");
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
448 if (trace_string) print "SOS:" FNR, $0;
450 fail("multi-line string")
452 gsub (/\"[^\"]*$/, "'\''");
460 # Accumulate continuation lines
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 = ""; }
469 # GDB uses ISO C 90. Check for any non pure ISO C 90 code
471 BEGIN { doc["PARAMS"] = "\
472 Do not use PARAMS(), ISO C 90 implies prototypes"
473 category["PARAMS"] = ari_regression
475 /(^|[^_[:alnum:]])PARAMS([^_[:alnum:]]|$)/ {
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__", "gdb/gdb_assert.h", 1)
484 /(^|[^_[:alnum:]])__func__([^_[:alnum:]]|$)/ {
488 BEGIN { doc["__FUNCTION__"] = "\
489 Do not use __FUNCTION__, ISO C 90 does not support this macro"
490 category["__FUNCTION__"] = ari_regression
492 /(^|[^_[:alnum:]])__FUNCTION__([^_[:alnum:]]|$)/ {
496 BEGIN { doc["__CYGWIN32__"] = "\
497 Do not use __CYGWIN32__, instead use __CYGWIN__ or, better, an explicit \
499 category["__CYGWIN32__"] = ari_regression
501 /(^|[^_[:alnum:]])__CYGWIN32__([^_[:alnum:]]|$)/ {
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)
510 /(^|[^_[:alnum:]])PTR([^_[:alnum:]]|$)/ {
514 BEGIN { doc["UCASE function"] = "\
515 Function name is uppercase."
516 category["UCASE function"] = ari_code
521 if (ARI_OK == "UCASE function") {
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)) {
533 $0 = UCASE_full_line;
534 fail("UCASE function")
541 UCASE_full_line = UCASE_full_line $0;
544 /^[A-Z][[:alnum:]_]*[[:space:]]*\([^()]*(|\))[[:space:]]*$/ {
546 if (ARI_OK == "UCASE function") {
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 = ""
560 (possible_editCase) {
561 if (ARI_OK == "ediCase function") {
562 possible_editCase = 0
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)) {
573 $0 = editCase_full_line;
574 fail("editCase function")
578 possible_editCase = 0
579 editCase_full_line = ""
581 editCase_full_line = editCase_full_line $0;
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
590 editCase_full_line = $0
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
598 /^[a-z][a-z0-9_]*[[:space:]]*\((|[^*][^()]*)\)[[:space:]]*[^ \t]+/ {
599 fail("function call in first column")
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
609 /^[a-zA-Z][a-z0-9A-Z_]*[[:space:]]*\(\)/ {
610 fail("no parameter function")
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 \
617 category["hash"] = ari_regression
623 BEGIN { doc["OP eol"] = "\
624 Do not use &&, or || at the end of a line"
625 category["OP eol"] = ari_code
627 /(\|\||\&\&|==|!=)[[:space:]]*$/ {
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)
638 /(^|[^_[:alnum:]])strerror[[:space:]]*\(/ {
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)
648 /(^|[^_[:alnum:]])long[[:space:]]+long([^_[:alnum:]]|$)/ {
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 \
657 category["ATTRIBUTE_UNUSED"] = ari_regression
659 /(^|[^_[:alnum:]])ATTRIBUTE_UNUSED([^_[:alnum:]]|$)/ {
660 fail("ATTRIBUTE_UNUSED")
663 BEGIN { doc["ATTR_FORMAT"] = "\
664 Do not use ATTR_FORMAT, use ATTRIBUTE_PRINTF instead"
665 category["ATTR_FORMAT"] = ari_regression
667 /(^|[^_[:alnum:]])ATTR_FORMAT([^_[:alnum:]]|$)/ {
671 BEGIN { doc["ATTR_NORETURN"] = "\
672 Do not use ATTR_NORETURN, use ATTRIBUTE_NORETURN instead"
673 category["ATTR_NORETURN"] = ari_regression
675 /(^|[^_[:alnum:]])ATTR_NORETURN([^_[:alnum:]]|$)/ {
676 fail("ATTR_NORETURN")
679 BEGIN { doc["NORETURN"] = "\
680 Do not use NORETURN, use ATTRIBUTE_NORETURN instead"
681 category["NORETURN"] = ari_regression
683 /(^|[^_[:alnum:]])NORETURN([^_[:alnum:]]|$)/ {
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
697 /(^|[^_[:alnum:]])(warning|error)[[:space:]]*\(/ {
698 if (FNR == warning_fnr + 1) {
699 fail("multiple messages")
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
712 # /(^|[^_[:alnum:]])inline([^_[:alnum:]]|$)/ {
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
722 #/(^|[^_[:alnum:]])obj_private([^_[:alnum:]]|$)/ {
723 # fail("obj_private")
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)
731 /(^|[^_[:alnum:]])abort[[:space:]]*\(/ {
735 BEGIN { doc["basename"] = "\
736 Do not use basename, instead use lbasename"
737 category["basename"] = ari_regression
739 /(^|[^_[:alnum:]])basename[[:space:]]*\(/ {
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
748 /(^|[^_[:alnum:]])assert[[:space:]]*\(/ {
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
756 /(^|[^_[:alnum:]])TARGET_HAS_HARDWARE_WATCHPOINTS([^_[:alnum:]]|$)/ {
757 fail("TARGET_HAS_HARDWARE_WATCHPOINTS")
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
764 /(^|[^_[:alnum:]])ADD_SHARED_SYMBOL_FILES([^_[:alnum:]]|$)/ {
765 fail("ADD_SHARED_SYMBOL_FILES")
768 BEGIN { doc["SOLIB_ADD"] = "\
769 Replace SOLIB_ADD with nothing, not needed?"
770 category["SOLIB_ADD"] = ari_deprecate
772 /(^|[^_[:alnum:]])SOLIB_ADD([^_[:alnum:]]|$)/ {
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
780 /(^|[^_[:alnum:]])SOLIB_CREATE_INFERIOR_HOOK([^_[:alnum:]]|$)/ {
781 fail("SOLIB_CREATE_INFERIOR_HOOK")
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
788 /(^|[^_[:alnum:]])SOLIB_LOADED_LIBRARY_PATHNAME([^_[:alnum:]]|$)/ {
789 fail("SOLIB_LOADED_LIBRARY_PATHNAME")
792 BEGIN { doc["REGISTER_U_ADDR"] = "\
793 Replace REGISTER_U_ADDR with nothing, not needed?"
794 category["REGISTER_U_ADDR"] = ari_regression
796 /(^|[^_[:alnum:]])REGISTER_U_ADDR([^_[:alnum:]]|$)/ {
797 fail("REGISTER_U_ADDR")
800 BEGIN { doc["PROCESS_LINENUMBER_HOOK"] = "\
801 Replace PROCESS_LINENUMBER_HOOK with nothing, not needed?"
802 category["PROCESS_LINENUMBER_HOOK"] = ari_regression
804 /(^|[^_[:alnum:]])PROCESS_LINENUMBER_HOOK([^_[:alnum:]]|$)/ {
805 fail("PROCESS_LINENUMBER_HOOK")
808 BEGIN { doc["PC_SOLIB"] = "\
809 Replace PC_SOLIB with nothing, not needed?"
810 category["PC_SOLIB"] = ari_deprecate
812 /(^|[^_[:alnum:]])PC_SOLIB([^_[:alnum:]]|$)/ {
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
820 /(^|[^_[:alnum:]])IN_SOLIB_DYNSYM_RESOLVE_CODE([^_[:alnum:]]|$)/ {
821 fail("IN_SOLIB_DYNSYM_RESOLVE_CODE")
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
828 /(^|[^_[:alnum:]])GCC_COMPILED_FLAG_SYMBOL([^_[:alnum:]]|$)/ {
829 fail("GCC_COMPILED_FLAG_SYMBOL")
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
836 /(^|[^_[:alnum:]])GCC2_COMPILED_FLAG_SYMBOL([^_[:alnum:]]|$)/ {
837 fail("GCC2_COMPILED_FLAG_SYMBOL")
840 BEGIN { doc["FUNCTION_EPILOGUE_SIZE"] = "\
841 Replace FUNCTION_EPILOGUE_SIZE with nothing, not needed?"
842 category["FUNCTION_EPILOGUE_SIZE"] = ari_regression
844 /(^|[^_[:alnum:]])FUNCTION_EPILOGUE_SIZE([^_[:alnum:]]|$)/ {
845 fail("FUNCTION_EPILOGUE_SIZE")
848 BEGIN { doc["HAVE_VFORK"] = "\
849 Do not use HAVE_VFORK, instead include \"gdb_vfork.h\" and call vfork() \
851 category["HAVE_VFORK"] = ari_regression
853 /(^|[^_[:alnum:]])HAVE_VFORK([^_[:alnum:]]|$)/ {
857 BEGIN { doc["bcmp"] = "\
858 Do not use bcmp(), ISO C 90 implies memcmp()"
859 category["bcmp"] = ari_regression
861 /(^|[^_[:alnum:]])bcmp[[:space:]]*\(/ {
865 BEGIN { doc["setlinebuf"] = "\
866 Do not use setlinebuf(), ISO C 90 implies setvbuf()"
867 category["setlinebuf"] = ari_regression
869 /(^|[^_[:alnum:]])setlinebuf[[:space:]]*\(/ {
873 BEGIN { doc["bcopy"] = "\
874 Do not use bcopy(), ISO C 90 implies memcpy() and memmove()"
875 category["bcopy"] = ari_regression
877 /(^|[^_[:alnum:]])bcopy[[:space:]]*\(/ {
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
886 /(^|[^_[:alnum:]])get_frame_base([^_[:alnum:]]|$)/ {
887 fail("get_frame_base")
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
896 /(^|[^_[:alnum:]])floatformat_to_double[[:space:]]*\(/ {
897 fail("floatformat_to_double")
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
905 /(^|[^_[:alnum:]])floatformat_from_double[[:space:]]*\(/ {
906 fail("floatformat_from_double")
909 BEGIN { doc["BIG_ENDIAN"] = "\
910 Do not use BIG_ENDIAN, instead use BFD_ENDIAN_BIG"
911 category["BIG_ENDIAN"] = ari_regression
913 /(^|[^_[:alnum:]])BIG_ENDIAN([^_[:alnum:]]|$)/ {
917 BEGIN { doc["LITTLE_ENDIAN"] = "\
918 Do not use LITTLE_ENDIAN, instead use BFD_ENDIAN_LITTLE";
919 category["LITTLE_ENDIAN"] = ari_regression
921 /(^|[^_[:alnum:]])LITTLE_ENDIAN([^_[:alnum:]]|$)/ {
922 fail("LITTLE_ENDIAN")
925 BEGIN { doc["BIG_ENDIAN"] = "\
926 Do not use BIG_ENDIAN, instead use BFD_ENDIAN_BIG"
927 category["BIG_ENDIAN"] = ari_regression
929 /(^|[^_[:alnum:]])BIG_ENDIAN([^_[:alnum:]]|$)/ {
933 BEGIN { doc["sec_ptr"] = "\
934 Instead of sec_ptr, use struct bfd_section";
935 category["sec_ptr"] = ari_regression
937 /(^|[^_[:alnum:]])sec_ptr([^_[:alnum:]]|$)/ {
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
945 /(^|[^_[:alnum:]])frame_unwind_unsigned_register([^_[:alnum:]]|$)/ {
946 fail("frame_unwind_unsigned_register")
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
954 /(^|[^_[:alnum:]])frame_register_read([^_[:alnum:]]|$)/ {
955 fail("frame_register_read")
958 BEGIN { doc["read_register"] = "\
959 Replace read_register() with regcache_read() et.al."
960 category["read_register"] = ari_regression
962 /(^|[^_[:alnum:]])read_register([^_[:alnum:]]|$)/ {
963 fail("read_register")
966 BEGIN { doc["write_register"] = "\
967 Replace write_register() with regcache_read() et.al."
968 category["write_register"] = ari_regression
970 /(^|[^_[:alnum:]])write_register([^_[:alnum:]]|$)/ {
971 fail("write_register")
974 function report(name) {
975 # Drop any trailing _P.
976 name = gensub(/(_P|_p)$/, "", 1, name)
977 # Convert to lower case
979 # Split into category and bug
980 cat = gensub(/^([[:alpha:]]+)_([_[:alnum:]]*)$/, "\\1", 1, name)
981 bug = gensub(/^([[:alpha:]]+)_([_[:alnum:]]*)$/, "\\2", 1, name)
984 doc[name] = "Do not use " cat " " bug ", see declaration for details"
989 /(^|[^_[:alnum:]])(DEPRECATED|deprecated|set_gdbarch_deprecated|LEGACY|legacy|set_gdbarch_legacy)_/ {
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;
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
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) {
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
1027 BEGIN { doc["deprecated_registers"] = "\
1028 Replace deprecated_registers with nothing, they have reached \
1030 category["deprecated_registers"] = ari_eol
1032 /(^|[^_[:alnum:]])deprecated_registers([^_[:alnum:]]|$)/ {
1033 fail("deprecated_registers")
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
1041 /(^|[^_[:alnum:]])read_pc[[:space:]]*\(/ || \
1042 /(^|[^_[:alnum:]])set_gdbarch_read_pc[[:space:]]*\(/ || \
1043 /(^|[^_[:alnum:]])TARGET_READ_PC[[:space:]]*\(/ {
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
1053 /(^|[^_[:alnum:]])write_pc[[:space:]]*\(/ || \
1054 /(^|[^_[:alnum:]])set_gdbarch_write_pc[[:space:]]*\(/ || \
1055 /(^|[^_[:alnum:]])TARGET_WRITE_PC[[:space:]]*\(/ {
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
1064 /(^|[^_[:alnum:]])generic_target_write_pc([^_[:alnum:]]|$)/ {
1065 fail("generic_target_write_pc")
1068 BEGIN { doc["read_sp"] = "\
1069 Replace read_sp() with frame_sp_unwind"
1070 category["read_sp"] = ari_regression
1072 /(^|[^_[:alnum:]])read_sp[[:space:]]*\(/ || \
1073 /(^|[^_[:alnum:]])set_gdbarch_read_sp[[:space:]]*\(/ || \
1074 /(^|[^_[:alnum:]])TARGET_READ_SP[[:space:]]*\(/ {
1078 BEGIN { doc["register_cached"] = "\
1079 Replace register_cached() with nothing, does not have a regcache parameter"
1080 category["register_cached"] = ari_regression
1082 /(^|[^_[:alnum:]])register_cached[[:space:]]*\(/ {
1083 fail("register_cached")
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
1090 /(^|[^_[:alnum:]])set_register_cached[[:space:]]*\(/ {
1091 fail("set_register_cached")
1094 # Print functions: Use versions that either check for buffer overflow
1095 # or safely allocate a fresh buffer.
1097 BEGIN { doc["sprintf"] = "\
1098 Do not use sprintf, instead use xsnprintf or xstrprintf"
1099 category["sprintf"] = ari_code
1101 /(^|[^_[:alnum:]])sprintf[[:space:]]*\(/ {
1105 BEGIN { doc["vsprintf"] = "\
1106 Do not use vsprintf(), instead use xstrvprintf"
1107 category["vsprintf"] = ari_regression
1109 /(^|[^_[:alnum:]])vsprintf[[:space:]]*\(/ {
1113 BEGIN { doc["asprintf"] = "\
1114 Do not use asprintf(), instead use xstrprintf()"
1115 category["asprintf"] = ari_regression
1117 /(^|[^_[:alnum:]])asprintf[[:space:]]*\(/ {
1121 BEGIN { doc["vasprintf"] = "\
1122 Do not use vasprintf(), instead use xstrvprintf"
1123 fix("vasprintf", "gdb/utils.c", 1)
1124 category["vasprintf"] = ari_regression
1126 /(^|[^_[:alnum:]])vasprintf[[:space:]]*\(/ {
1130 BEGIN { doc["xasprintf"] = "\
1131 Do not use xasprintf(), instead use xstrprintf"
1132 fix("xasprintf", "gdb/defs.h", 1)
1133 fix("xasprintf", "gdb/utils.c", 1)
1134 category["xasprintf"] = ari_regression
1136 /(^|[^_[:alnum:]])xasprintf[[:space:]]*\(/ {
1140 BEGIN { doc["xvasprintf"] = "\
1141 Do not use xvasprintf(), instead use xstrvprintf"
1142 fix("xvasprintf", "gdb/defs.h", 1)
1143 fix("xvasprintf", "gdb/utils.c", 1)
1144 category["xvasprintf"] = ari_regression
1146 /(^|[^_[:alnum:]])xvasprintf[[:space:]]*\(/ {
1150 # More generic memory operations
1152 BEGIN { doc["bzero"] = "\
1153 Do not use bzero(), instead use memset()"
1154 category["bzero"] = ari_regression
1156 /(^|[^_[:alnum:]])bzero[[:space:]]*\(/ {
1160 BEGIN { doc["strdup"] = "\
1161 Do not use strdup(), instead use xstrdup()";
1162 category["strdup"] = ari_regression
1164 /(^|[^_[:alnum:]])strdup[[:space:]]*\(/ {
1168 BEGIN { doc["strsave"] = "\
1169 Do not use strsave(), instead use xstrdup() et.al."
1170 category["strsave"] = ari_regression
1172 /(^|[^_[:alnum:]])strsave[[:space:]]*\(/ {
1176 # String compare functions
1178 BEGIN { doc["strnicmp"] = "\
1179 Do not use strnicmp(), instead use strncasecmp()"
1180 category["strnicmp"] = ari_regression
1182 /(^|[^_[:alnum:]])strnicmp[[:space:]]*\(/ {
1186 # Boolean expressions and conditionals
1188 BEGIN { doc["boolean"] = "\
1189 Do not use `boolean'\'', use `int'\'' instead"
1190 category["boolean"] = ari_regression
1192 /(^|[^_[:alnum:]])boolean([^_[:alnum:]]|$)/ {
1193 if (is_yacc_or_lex == 0) {
1198 BEGIN { doc["false"] = "\
1199 Definitely do not use `false'\'' in boolean expressions"
1200 category["false"] = ari_regression
1202 /(^|[^_[:alnum:]])false([^_[:alnum:]]|$)/ {
1203 if (is_yacc_or_lex == 0) {
1208 BEGIN { doc["true"] = "\
1209 Do not try to use `true'\'' in boolean expressions"
1210 category["true"] = ari_regression
1212 /(^|[^_[:alnum:]])true([^_[:alnum:]]|$)/ {
1213 if (is_yacc_or_lex == 0) {
1218 # Typedefs that are either redundant or can be reduced to `struct
1220 # Must be placed before if assignment otherwise ARI exceptions
1221 # are not handled correctly.
1223 BEGIN { doc["d_namelen"] = "\
1224 Do not use dirent.d_namelen, instead use NAMELEN"
1225 category["d_namelen"] = ari_regression
1227 /(^|[^_[:alnum:]])d_namelen([^_[:alnum:]]|$)/ {
1231 BEGIN { doc["strlen d_name"] = "\
1232 Do not use strlen dirent.d_name, instead use NAMELEN"
1233 category["strlen d_name"] = ari_regression
1235 /(^|[^_[:alnum:]])strlen[[:space:]]*\(.*[^_[:alnum:]]d_name([^_[:alnum:]]|$)/ {
1236 fail("strlen d_name")
1239 BEGIN { doc["var_boolean"] = "\
1240 Replace var_boolean with add_setshow_boolean_cmd"
1241 category["var_boolean"] = ari_regression
1242 fix("var_boolean", "gdb/command.h", 1)
1243 # fix only uses the last directory level
1244 fix("var_boolean", "cli/cli-decode.c", 2)
1246 /(^|[^_[:alnum:]])var_boolean([^_[:alnum:]]|$)/ {
1247 if ($0 !~ /(^|[^_[:alnum:]])case *var_boolean:/) {
1252 BEGIN { doc["generic_use_struct_convention"] = "\
1253 Replace generic_use_struct_convention with nothing, \
1254 EXTRACT_STRUCT_VALUE_ADDRESS is a predicate"
1255 category["generic_use_struct_convention"] = ari_regression
1257 /(^|[^_[:alnum:]])generic_use_struct_convention([^_[:alnum:]]|$)/ {
1258 fail("generic_use_struct_convention")
1261 BEGIN { doc["if assignment"] = "\
1262 An IF statement'\''s expression contains an assignment (the GNU coding \
1263 standard discourages this)"
1264 category["if assignment"] = ari_code
1266 BEGIN { doc["if clause more than 50 lines"] = "\
1267 An IF statement'\''s expression expands over 50 lines"
1268 category["if clause more than 50 lines"] = ari_code
1271 # Accumulate continuation lines
1276 /(^|[^_[:alnum:]])if / {
1281 if_brace_end_pos = 0;
1285 # We want everything up to closing brace of same level
1287 if (if_count > 50) {
1288 print "multiline if: " if_full_line $0
1289 fail("if clause more than 50 lines")
1293 if (if_count == 1) {
1294 i = index($0,"if ");
1298 for (i=i; i <= length($0); i++) {
1299 char = substr($0,i,1);
1300 if (char == "(") { if_brace_level++; }
1303 if (!if_brace_level) {
1304 if_brace_end_pos = i;
1305 after_if = substr($0,i+1,length($0));
1306 # Do not parse what is following
1311 if (if_brace_level == 0) {
1312 $0 = substr($0,1,i);
1315 if_full_line = if_full_line $0;
1321 # if we arrive here, we need to concatenate, but we are at brace level 0
1323 (if_brace_end_pos) {
1324 $0 = if_full_line substr($0,1,if_brace_end_pos);
1326 # print "IF: multi line " if_count " found at " FILENAME ":" FNR " \"" $0 "\""
1331 /(^|[^_[:alnum:]])if .* = / {
1332 # print "fail in if " $0
1333 fail("if assignment")
1335 (if_brace_end_pos) {
1337 if_brace_end_pos = 0;
1341 # Printout of all found bug
This page took 0.080916 seconds and 3 git commands to generate.