3 # GDB script to list of problems using awk.
5 # Copyright (C) 2002-2013 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["ARGSUSED"] = "\
261 Do not use ARGSUSED, unnecessary"
262 category["ARGSUSED"] = ari_regression
264 /(^|[^_[:alnum:]])ARGSUSED([^_[:alnum:]]|$)/ {
269 # SNIP - Strip out comments - SNIP
274 comment_p && /\*\// { gsub (/^([^\*]|\*+[^\/\*])*\*+\//, " "); comment_p = 0; }
276 !comment_p { gsub (/\/\*([^\*]|\*+[^\/\*])*\*+\//, " "); }
277 !comment_p && /(^|[^"])\/\*/ { gsub (/\/\*.*$/, " "); comment_p = 1; }
280 BEGIN { doc["_ markup"] = "\
281 All messages should be marked up with _."
282 category["_ markup"] = ari_gettext
284 /^[^"]*[[:space:]](warning|error|error_no_arg|query|perror_with_name)[[:space:]]*\([^_\(a-z]/ {
290 BEGIN { doc["trailing new line"] = "\
291 A message should not have a trailing new line"
292 category["trailing new line"] = ari_gettext
294 /(^|[^_[:alnum:]])(warning|error)[[:space:]]*\(_\(".*\\n"\)[\),]/ {
295 fail("trailing new line")
298 # Include files for which GDB has a custom version.
300 BEGIN { doc["assert.h"] = "\
301 Do not include assert.h, instead include \"gdb_assert.h\"";
302 category["assert.h"] = ari_regression
303 fix("assert.h", "gdb/gdb_assert.h", 0) # it does not use it
305 /^#[[:space:]]*include[[:space:]]+.assert\.h./ {
309 BEGIN { doc["dirent.h"] = "\
310 Do not include dirent.h, instead include gdb_dirent.h"
311 category["dirent.h"] = ari_regression
313 /^#[[:space:]]*include[[:space:]]*.dirent\.h./ {
317 BEGIN { doc["regex.h"] = "\
318 Do not include regex.h, instead include gdb_regex.h"
319 category["regex.h"] = ari_regression
320 fix("regex.h", "gdb/gdb_regex.h", 1)
322 /^#[[:space:]]*include[[:space:]]*.regex\.h./ {
326 BEGIN { doc["xregex.h"] = "\
327 Do not include xregex.h, instead include gdb_regex.h"
328 category["xregex.h"] = ari_regression
329 fix("xregex.h", "gdb/gdb_regex.h", 1)
331 /^#[[:space:]]*include[[:space:]]*.xregex\.h./ {
335 BEGIN { doc["gnu-regex.h"] = "\
336 Do not include gnu-regex.h, instead include gdb_regex.h"
337 category["gnu-regex.h"] = ari_regression
339 /^#[[:space:]]*include[[:space:]]*.gnu-regex\.h./ {
343 BEGIN { doc["stat.h"] = "\
344 Do not include stat.h or sys/stat.h, instead include gdb_stat.h"
345 category["stat.h"] = ari_regression
346 fix("stat.h", "common/gdb_stat.h", 1)
348 /^#[[:space:]]*include[[:space:]]*.stat\.h./ \
349 || /^#[[:space:]]*include[[:space:]]*.sys\/stat\.h./ {
353 BEGIN { doc["wait.h"] = "\
354 Do not include wait.h or sys/wait.h, instead include gdb_wait.h"
355 fix("wait.h", "common/gdb_wait.h", 2);
356 category["wait.h"] = ari_regression
358 /^#[[:space:]]*include[[:space:]]*.wait\.h./ \
359 || /^#[[:space:]]*include[[:space:]]*.sys\/wait\.h./ {
363 BEGIN { doc["vfork.h"] = "\
364 Do not include vfork.h, instead include gdb_vfork.h"
365 fix("vfork.h", "gdb/gdb_vfork.h", 1);
366 category["vfork.h"] = ari_regression
368 /^#[[:space:]]*include[[:space:]]*.vfork\.h./ {
372 BEGIN { doc["error not internal-warning"] = "\
373 Do not use error(\"internal-warning\"), instead use internal_warning"
374 category["error not internal-warning"] = ari_regression
376 /error.*\"[Ii]nternal.warning/ {
377 fail("error not internal-warning")
380 BEGIN { doc["%p"] = "\
381 Do not use printf(\"%p\"), instead use printf(\"%s\",paddr()) to dump a \
382 target address, or host_address_to_string() for a host address"
383 category["%p"] = ari_code
389 BEGIN { doc["%ll"] = "\
390 Do not use printf(\"%ll\"), instead use printf(\"%s\",phex()) to dump a \
391 `long long'\'' value"
392 category["%ll"] = ari_code
395 /%[0-9]*ll/ && !/scanf \(.*%[0-9]*ll/ {
400 # SNIP - Strip out strings - SNIP
402 # Test on top.c, scm-valprint.c, remote-rdi.c, ada-lang.c
407 # Strip escaped characters.
408 { gsub(/\\./, "."); }
409 # Strip quoted quotes.
410 { gsub(/'\''.'\''/, "'\''.'\''"); }
411 # End of multi-line string
413 if (trace_string) print "EOS:" FNR, $0;
414 gsub (/^[^\"]*\"/, "'\''");
417 # Middle of multi-line string, discard line.
419 if (trace_string) print "MOS:" FNR, $0;
422 # Strip complete strings from the middle of the line
423 !string_p && /\"[^\"]*\"/ {
424 if (trace_string) print "COS:" FNR, $0;
425 gsub (/\"[^\"]*\"/, "'\''");
427 # Start of multi-line string
428 BEGIN { doc["multi-line string"] = "\
429 Multi-line string must have the newline escaped"
430 category["multi-line string"] = ari_regression
433 if (trace_string) print "SOS:" FNR, $0;
435 fail("multi-line string")
437 gsub (/\"[^\"]*$/, "'\''");
445 # Accumulate continuation lines
449 !cont_p { full_line = ""; }
450 /[^\\]\\$/ { gsub (/\\$/, ""); full_line = full_line $0; cont_p = 1; next; }
451 cont_p { $0 = full_line $0; cont_p = 0; full_line = ""; }
454 # GDB uses ISO C 90. Check for any non pure ISO C 90 code
456 BEGIN { doc["PARAMS"] = "\
457 Do not use PARAMS(), ISO C 90 implies prototypes"
458 category["PARAMS"] = ari_regression
460 /(^|[^_[:alnum:]])PARAMS([^_[:alnum:]]|$)/ {
464 BEGIN { doc["__func__"] = "\
465 Do not use __func__, ISO C 90 does not support this macro"
466 category["__func__"] = ari_regression
467 fix("__func__", "common/gdb_assert.h", 1)
469 /(^|[^_[:alnum:]])__func__([^_[:alnum:]]|$)/ {
473 BEGIN { doc["__FUNCTION__"] = "\
474 Do not use __FUNCTION__, ISO C 90 does not support this macro"
475 category["__FUNCTION__"] = ari_regression
477 /(^|[^_[:alnum:]])__FUNCTION__([^_[:alnum:]]|$)/ {
481 BEGIN { doc["__CYGWIN32__"] = "\
482 Do not use __CYGWIN32__, instead use __CYGWIN__ or, better, an explicit \
484 category["__CYGWIN32__"] = ari_regression
486 /(^|[^_[:alnum:]])__CYGWIN32__([^_[:alnum:]]|$)/ {
490 BEGIN { doc["PTR"] = "\
491 Do not use PTR, ISO C 90 implies `void *'\''"
492 category["PTR"] = ari_regression
493 #fix("PTR", "gdb/utils.c", 6)
495 /(^|[^_[:alnum:]])PTR([^_[:alnum:]]|$)/ {
499 BEGIN { doc["UCASE function"] = "\
500 Function name is uppercase."
501 category["UCASE function"] = ari_code
506 if (ARI_OK == "UCASE function") {
509 # Closing brace found?
510 else if (UCASE_full_line ~ \
511 /^[A-Z][[:alnum:]_]*[[:space:]]*\([^()]*\).*$/) {
512 if ((UCASE_full_line ~ \
513 /^[A-Z][[:alnum:]_]*[[:space:]]*\([^()]*\)[[:space:]]*$/) \
514 && ($0 ~ /^\{/) && (is_yacc_or_lex == 0)) {
518 $0 = UCASE_full_line;
519 fail("UCASE function")
526 UCASE_full_line = UCASE_full_line $0;
529 /^[A-Z][[:alnum:]_]*[[:space:]]*\([^()]*(|\))[[:space:]]*$/ {
531 if (ARI_OK == "UCASE function") {
539 BEGIN { doc["editCase function"] = "\
540 Function name starts lower case but has uppercased letters."
541 category["editCase function"] = ari_code
542 possible_editCase = 0
543 editCase_full_line = ""
545 (possible_editCase) {
546 if (ARI_OK == "ediCase function") {
547 possible_editCase = 0
549 # Closing brace found?
550 else if (editCase_full_line ~ \
551 /^[a-z][a-z0-9_]*[A-Z][a-z0-9A-Z_]*[[:space:]]*\([^()]*\).*$/) {
552 if ((editCase_full_line ~ \
553 /^[a-z][a-z0-9_]*[A-Z][a-z0-9A-Z_]*[[:space:]]*\([^()]*\)[[:space:]]*$/) \
554 && ($0 ~ /^\{/) && (is_yacc_or_lex == 0)) {
558 $0 = editCase_full_line;
559 fail("editCase function")
563 possible_editCase = 0
564 editCase_full_line = ""
566 editCase_full_line = editCase_full_line $0;
569 /^[a-z][a-z0-9_]*[A-Z][a-z0-9A-Z_]*[[:space:]]*\([^()]*(|\))[[:space:]]*$/ {
570 possible_editCase = 1
571 if (ARI_OK == "editCase function") {
572 possible_editCase = 0
575 editCase_full_line = $0
578 # Only function implementation should be on first column
579 BEGIN { doc["function call in first column"] = "\
580 Function name in first column should be restricted to function implementation"
581 category["function call in first column"] = ari_code
583 /^[a-z][a-z0-9_]*[[:space:]]*\((|[^*][^()]*)\)[[:space:]]*[^ \t]+/ {
584 fail("function call in first column")
588 # Functions without any parameter should have (void)
589 # after their name not simply ().
590 BEGIN { doc["no parameter function"] = "\
591 Function having no parameter should be declared with funcname (void)."
592 category["no parameter function"] = ari_code
594 /^[a-zA-Z][a-z0-9A-Z_]*[[:space:]]*\(\)/ {
595 fail("no parameter function")
598 BEGIN { doc["hash"] = "\
599 Do not use ` #...'\'', instead use `#...'\''(some compilers only correctly \
600 parse a C preprocessor directive when `#'\'' is the first character on \
602 category["hash"] = ari_regression
608 BEGIN { doc["OP eol"] = "\
609 Do not use &&, or || at the end of a line"
610 category["OP eol"] = ari_code
612 /(\|\||\&\&|==|!=)[[:space:]]*$/ {
616 BEGIN { doc["strerror"] = "\
617 Do not use strerror(), instead use safe_strerror()"
618 category["strerror"] = ari_regression
619 fix("strerror", "gdb/gdb_string.h", 1)
620 fix("strerror", "gdb/mingw-hdep.c", 1)
621 fix("strerror", "gdb/posix-hdep.c", 1)
623 /(^|[^_[:alnum:]])strerror[[:space:]]*\(/ {
627 BEGIN { doc["long long"] = "\
628 Do not use `long long'\'', instead use LONGEST"
629 category["long long"] = ari_code
630 # defs.h needs two such patterns for LONGEST and ULONGEST definitions
631 fix("long long", "gdb/defs.h", 2)
633 /(^|[^_[:alnum:]])long[[:space:]]+long([^_[:alnum:]]|$)/ {
637 BEGIN { doc["ATTRIBUTE_UNUSED"] = "\
638 Do not use ATTRIBUTE_UNUSED, do not bother (GDB is compiled with -Werror and, \
639 consequently, is not able to tolerate false warnings. Since -Wunused-param \
640 produces such warnings, neither that warning flag nor ATTRIBUTE_UNUSED \
642 category["ATTRIBUTE_UNUSED"] = ari_regression
644 /(^|[^_[:alnum:]])ATTRIBUTE_UNUSED([^_[:alnum:]]|$)/ {
645 fail("ATTRIBUTE_UNUSED")
648 BEGIN { doc["ATTR_FORMAT"] = "\
649 Do not use ATTR_FORMAT, use ATTRIBUTE_PRINTF instead"
650 category["ATTR_FORMAT"] = ari_regression
652 /(^|[^_[:alnum:]])ATTR_FORMAT([^_[:alnum:]]|$)/ {
656 BEGIN { doc["ATTR_NORETURN"] = "\
657 Do not use ATTR_NORETURN, use ATTRIBUTE_NORETURN instead"
658 category["ATTR_NORETURN"] = ari_regression
660 /(^|[^_[:alnum:]])ATTR_NORETURN([^_[:alnum:]]|$)/ {
661 fail("ATTR_NORETURN")
664 BEGIN { doc["NORETURN"] = "\
665 Do not use NORETURN, use ATTRIBUTE_NORETURN instead"
666 category["NORETURN"] = ari_regression
668 /(^|[^_[:alnum:]])NORETURN([^_[:alnum:]]|$)/ {
675 BEGIN { doc["multiple messages"] = "\
676 Do not use multiple calls to warning or error, instead use a single call"
677 category["multiple messages"] = ari_gettext
682 /(^|[^_[:alnum:]])(warning|error)[[:space:]]*\(/ {
683 if (FNR == warning_fnr + 1) {
684 fail("multiple messages")
690 # Commented out, but left inside sources, just in case.
691 # BEGIN { doc["inline"] = "\
692 # Do not use the inline attribute; \
693 # since the compiler generally ignores this, better algorithm selection \
694 # is needed to improved performance"
695 # category["inline"] = ari_code
697 # /(^|[^_[:alnum:]])inline([^_[:alnum:]]|$)/ {
701 # This test is obsolete as this type
702 # has been deprecated and finally suppressed from GDB sources
703 #BEGIN { doc["obj_private"] = "\
704 #Replace obj_private with objfile_data"
705 # category["obj_private"] = ari_obsolete
707 #/(^|[^_[:alnum:]])obj_private([^_[:alnum:]]|$)/ {
708 # fail("obj_private")
711 BEGIN { doc["abort"] = "\
712 Do not use abort, instead use internal_error; GDB should never abort"
713 category["abort"] = ari_regression
714 fix("abort", "gdb/utils.c", 3)
716 /(^|[^_[:alnum:]])abort[[:space:]]*\(/ {
720 BEGIN { doc["basename"] = "\
721 Do not use basename, instead use lbasename"
722 category["basename"] = ari_regression
724 /(^|[^_[:alnum:]])basename[[:space:]]*\(/ {
728 BEGIN { doc["assert"] = "\
729 Do not use assert, instead use gdb_assert or internal_error; assert \
730 calls abort and GDB should never call abort"
731 category["assert"] = ari_regression
733 /(^|[^_[:alnum:]])assert[[:space:]]*\(/ {
737 BEGIN { doc["TARGET_HAS_HARDWARE_WATCHPOINTS"] = "\
738 Replace TARGET_HAS_HARDWARE_WATCHPOINTS with nothing, not needed"
739 category["TARGET_HAS_HARDWARE_WATCHPOINTS"] = ari_regression
741 /(^|[^_[:alnum:]])TARGET_HAS_HARDWARE_WATCHPOINTS([^_[:alnum:]]|$)/ {
742 fail("TARGET_HAS_HARDWARE_WATCHPOINTS")
745 BEGIN { doc["ADD_SHARED_SYMBOL_FILES"] = "\
746 Replace ADD_SHARED_SYMBOL_FILES with nothing, not needed?"
747 category["ADD_SHARED_SYMBOL_FILES"] = ari_regression
749 /(^|[^_[:alnum:]])ADD_SHARED_SYMBOL_FILES([^_[:alnum:]]|$)/ {
750 fail("ADD_SHARED_SYMBOL_FILES")
753 BEGIN { doc["SOLIB_ADD"] = "\
754 Replace SOLIB_ADD with nothing, not needed?"
755 category["SOLIB_ADD"] = ari_deprecate
757 /(^|[^_[:alnum:]])SOLIB_ADD([^_[:alnum:]]|$)/ {
761 BEGIN { doc["SOLIB_CREATE_INFERIOR_HOOK"] = "\
762 Replace SOLIB_CREATE_INFERIOR_HOOK with nothing, not needed?"
763 category["SOLIB_CREATE_INFERIOR_HOOK"] = ari_deprecate
765 /(^|[^_[:alnum:]])SOLIB_CREATE_INFERIOR_HOOK([^_[:alnum:]]|$)/ {
766 fail("SOLIB_CREATE_INFERIOR_HOOK")
769 BEGIN { doc["SOLIB_LOADED_LIBRARY_PATHNAME"] = "\
770 Replace SOLIB_LOADED_LIBRARY_PATHNAME with nothing, not needed?"
771 category["SOLIB_LOADED_LIBRARY_PATHNAME"] = ari_regression
773 /(^|[^_[:alnum:]])SOLIB_LOADED_LIBRARY_PATHNAME([^_[:alnum:]]|$)/ {
774 fail("SOLIB_LOADED_LIBRARY_PATHNAME")
777 BEGIN { doc["REGISTER_U_ADDR"] = "\
778 Replace REGISTER_U_ADDR with nothing, not needed?"
779 category["REGISTER_U_ADDR"] = ari_regression
781 /(^|[^_[:alnum:]])REGISTER_U_ADDR([^_[:alnum:]]|$)/ {
782 fail("REGISTER_U_ADDR")
785 BEGIN { doc["PROCESS_LINENUMBER_HOOK"] = "\
786 Replace PROCESS_LINENUMBER_HOOK with nothing, not needed?"
787 category["PROCESS_LINENUMBER_HOOK"] = ari_regression
789 /(^|[^_[:alnum:]])PROCESS_LINENUMBER_HOOK([^_[:alnum:]]|$)/ {
790 fail("PROCESS_LINENUMBER_HOOK")
793 BEGIN { doc["PC_SOLIB"] = "\
794 Replace PC_SOLIB with nothing, not needed?"
795 category["PC_SOLIB"] = ari_deprecate
797 /(^|[^_[:alnum:]])PC_SOLIB([^_[:alnum:]]|$)/ {
801 BEGIN { doc["IN_SOLIB_DYNSYM_RESOLVE_CODE"] = "\
802 Replace IN_SOLIB_DYNSYM_RESOLVE_CODE with nothing, not needed?"
803 category["IN_SOLIB_DYNSYM_RESOLVE_CODE"] = ari_regression
805 /(^|[^_[:alnum:]])IN_SOLIB_DYNSYM_RESOLVE_CODE([^_[:alnum:]]|$)/ {
806 fail("IN_SOLIB_DYNSYM_RESOLVE_CODE")
809 BEGIN { doc["GCC_COMPILED_FLAG_SYMBOL"] = "\
810 Replace GCC_COMPILED_FLAG_SYMBOL with nothing, not needed?"
811 category["GCC_COMPILED_FLAG_SYMBOL"] = ari_deprecate
813 /(^|[^_[:alnum:]])GCC_COMPILED_FLAG_SYMBOL([^_[:alnum:]]|$)/ {
814 fail("GCC_COMPILED_FLAG_SYMBOL")
817 BEGIN { doc["GCC2_COMPILED_FLAG_SYMBOL"] = "\
818 Replace GCC2_COMPILED_FLAG_SYMBOL with nothing, not needed?"
819 category["GCC2_COMPILED_FLAG_SYMBOL"] = ari_deprecate
821 /(^|[^_[:alnum:]])GCC2_COMPILED_FLAG_SYMBOL([^_[:alnum:]]|$)/ {
822 fail("GCC2_COMPILED_FLAG_SYMBOL")
825 BEGIN { doc["FUNCTION_EPILOGUE_SIZE"] = "\
826 Replace FUNCTION_EPILOGUE_SIZE with nothing, not needed?"
827 category["FUNCTION_EPILOGUE_SIZE"] = ari_regression
829 /(^|[^_[:alnum:]])FUNCTION_EPILOGUE_SIZE([^_[:alnum:]]|$)/ {
830 fail("FUNCTION_EPILOGUE_SIZE")
833 BEGIN { doc["HAVE_VFORK"] = "\
834 Do not use HAVE_VFORK, instead include \"gdb_vfork.h\" and call vfork() \
836 category["HAVE_VFORK"] = ari_regression
838 /(^|[^_[:alnum:]])HAVE_VFORK([^_[:alnum:]]|$)/ {
842 BEGIN { doc["bcmp"] = "\
843 Do not use bcmp(), ISO C 90 implies memcmp()"
844 category["bcmp"] = ari_regression
846 /(^|[^_[:alnum:]])bcmp[[:space:]]*\(/ {
850 BEGIN { doc["setlinebuf"] = "\
851 Do not use setlinebuf(), ISO C 90 implies setvbuf()"
852 category["setlinebuf"] = ari_regression
854 /(^|[^_[:alnum:]])setlinebuf[[:space:]]*\(/ {
858 BEGIN { doc["bcopy"] = "\
859 Do not use bcopy(), ISO C 90 implies memcpy() and memmove()"
860 category["bcopy"] = ari_regression
862 /(^|[^_[:alnum:]])bcopy[[:space:]]*\(/ {
866 BEGIN { doc["get_frame_base"] = "\
867 Replace get_frame_base with get_frame_id, get_frame_base_address, \
868 get_frame_locals_address, or get_frame_args_address."
869 category["get_frame_base"] = ari_obsolete
871 /(^|[^_[:alnum:]])get_frame_base([^_[:alnum:]]|$)/ {
872 fail("get_frame_base")
875 BEGIN { doc["floatformat_to_double"] = "\
876 Do not use floatformat_to_double() from libierty, \
877 instead use floatformat_to_doublest()"
878 fix("floatformat_to_double", "gdb/doublest.c", 1)
879 category["floatformat_to_double"] = ari_regression
881 /(^|[^_[:alnum:]])floatformat_to_double[[:space:]]*\(/ {
882 fail("floatformat_to_double")
885 BEGIN { doc["floatformat_from_double"] = "\
886 Do not use floatformat_from_double() from libierty, \
887 instead use floatformat_from_doublest()"
888 category["floatformat_from_double"] = ari_regression
890 /(^|[^_[:alnum:]])floatformat_from_double[[:space:]]*\(/ {
891 fail("floatformat_from_double")
894 BEGIN { doc["BIG_ENDIAN"] = "\
895 Do not use BIG_ENDIAN, instead use BFD_ENDIAN_BIG"
896 category["BIG_ENDIAN"] = ari_regression
898 /(^|[^_[:alnum:]])BIG_ENDIAN([^_[:alnum:]]|$)/ {
902 BEGIN { doc["LITTLE_ENDIAN"] = "\
903 Do not use LITTLE_ENDIAN, instead use BFD_ENDIAN_LITTLE";
904 category["LITTLE_ENDIAN"] = ari_regression
906 /(^|[^_[:alnum:]])LITTLE_ENDIAN([^_[:alnum:]]|$)/ {
907 fail("LITTLE_ENDIAN")
910 BEGIN { doc["BIG_ENDIAN"] = "\
911 Do not use BIG_ENDIAN, instead use BFD_ENDIAN_BIG"
912 category["BIG_ENDIAN"] = ari_regression
914 /(^|[^_[:alnum:]])BIG_ENDIAN([^_[:alnum:]]|$)/ {
918 BEGIN { doc["sec_ptr"] = "\
919 Instead of sec_ptr, use struct bfd_section";
920 category["sec_ptr"] = ari_regression
922 /(^|[^_[:alnum:]])sec_ptr([^_[:alnum:]]|$)/ {
926 BEGIN { doc["frame_unwind_unsigned_register"] = "\
927 Replace frame_unwind_unsigned_register with frame_unwind_register_unsigned"
928 category["frame_unwind_unsigned_register"] = ari_regression
930 /(^|[^_[:alnum:]])frame_unwind_unsigned_register([^_[:alnum:]]|$)/ {
931 fail("frame_unwind_unsigned_register")
934 BEGIN { doc["frame_register_read"] = "\
935 Replace frame_register_read() with get_frame_register(), or \
936 possibly introduce a new method safe_get_frame_register()"
937 category["frame_register_read"] = ari_obsolete
939 /(^|[^_[:alnum:]])frame_register_read([^_[:alnum:]]|$)/ {
940 fail("frame_register_read")
943 BEGIN { doc["read_register"] = "\
944 Replace read_register() with regcache_read() et.al."
945 category["read_register"] = ari_regression
947 /(^|[^_[:alnum:]])read_register([^_[:alnum:]]|$)/ {
948 fail("read_register")
951 BEGIN { doc["write_register"] = "\
952 Replace write_register() with regcache_read() et.al."
953 category["write_register"] = ari_regression
955 /(^|[^_[:alnum:]])write_register([^_[:alnum:]]|$)/ {
956 fail("write_register")
959 function report(name) {
960 # Drop any trailing _P.
961 name = gensub(/(_P|_p)$/, "", 1, name)
962 # Convert to lower case
964 # Split into category and bug
965 cat = gensub(/^([[:alpha:]]+)_([_[:alnum:]]*)$/, "\\1", 1, name)
966 bug = gensub(/^([[:alpha:]]+)_([_[:alnum:]]*)$/, "\\2", 1, name)
969 doc[name] = "Do not use " cat " " bug ", see declaration for details"
974 /(^|[^_[:alnum:]])(DEPRECATED|deprecated|set_gdbarch_deprecated|LEGACY|legacy|set_gdbarch_legacy)_/ {
978 name = gensub(/^(|.*[^_[:alnum:]])((DEPRECATED|deprecated|LEGACY|legacy)_[_[:alnum:]]*)(.*)$/, "\\2", 1, line)
979 line = gensub(/^(|.*[^_[:alnum:]])((DEPRECATED|deprecated|LEGACY|legacy)_[_[:alnum:]]*)(.*)$/, "\\1 \\4", 1, line)
980 # print "name =", name, "line =", line
981 if (name == line) break;
986 # Count the number of times each architecture method is set
987 /(^|[^_[:alnum:]])set_gdbarch_[_[:alnum:]]*([^_[:alnum:]]|$)/ {
988 name = gensub(/^.*set_gdbarch_([_[:alnum:]]*).*$/, "\\1", 1, $0)
989 doc["set " name] = "\
990 Call to set_gdbarch_" name
991 category["set " name] = ari_gdbarch
995 # Count the number of times each tm/xm/nm macro is defined or undefined
996 /^#[[:space:]]*(undef|define)[[:space:]]+[[:alnum:]_]+.*$/ \
997 && !/^#[[:space:]]*(undef|define)[[:space:]]+[[:alnum:]_]+_H($|[[:space:]])/ \
998 && FILENAME ~ /(^|\/)config\/(|[^\/]*\/)(tm-|xm-|nm-).*\.h$/ {
999 basename = gensub(/(^|.*\/)([^\/]*)$/, "\\2", 1, FILENAME)
1000 type = gensub(/^(tm|xm|nm)-.*\.h$/, "\\1", 1, basename)
1001 name = gensub(/^#[[:space:]]*(undef|define)[[:space:]]+([[:alnum:]_]+).*$/, "\\2", 1, $0)
1002 if (type == basename) {
1005 doc[type " " name] = "\
1006 Do not define macros such as " name " in a tm, nm or xm file, \
1007 in fact do not provide a tm, nm or xm file"
1008 category[type " " name] = ari_macro
1012 BEGIN { doc["deprecated_registers"] = "\
1013 Replace deprecated_registers with nothing, they have reached \
1015 category["deprecated_registers"] = ari_eol
1017 /(^|[^_[:alnum:]])deprecated_registers([^_[:alnum:]]|$)/ {
1018 fail("deprecated_registers")
1021 BEGIN { doc["read_pc"] = "\
1022 Replace READ_PC() with frame_pc_unwind; \
1023 at present the inferior function call code still uses this"
1024 category["read_pc"] = ari_deprecate
1026 /(^|[^_[:alnum:]])read_pc[[:space:]]*\(/ || \
1027 /(^|[^_[:alnum:]])set_gdbarch_read_pc[[:space:]]*\(/ || \
1028 /(^|[^_[:alnum:]])TARGET_READ_PC[[:space:]]*\(/ {
1032 BEGIN { doc["write_pc"] = "\
1033 Replace write_pc() with get_frame_base_address or get_frame_id; \
1034 at present the inferior function call code still uses this when doing \
1035 a DECR_PC_AFTER_BREAK"
1036 category["write_pc"] = ari_deprecate
1038 /(^|[^_[:alnum:]])write_pc[[:space:]]*\(/ || \
1039 /(^|[^_[:alnum:]])set_gdbarch_write_pc[[:space:]]*\(/ || \
1040 /(^|[^_[:alnum:]])TARGET_WRITE_PC[[:space:]]*\(/ {
1044 BEGIN { doc["generic_target_write_pc"] = "\
1045 Replace generic_target_write_pc with a per-architecture implementation, \
1046 this relies on PC_REGNUM which is being eliminated"
1047 category["generic_target_write_pc"] = ari_regression
1049 /(^|[^_[:alnum:]])generic_target_write_pc([^_[:alnum:]]|$)/ {
1050 fail("generic_target_write_pc")
1053 BEGIN { doc["read_sp"] = "\
1054 Replace read_sp() with frame_sp_unwind"
1055 category["read_sp"] = ari_regression
1057 /(^|[^_[:alnum:]])read_sp[[:space:]]*\(/ || \
1058 /(^|[^_[:alnum:]])set_gdbarch_read_sp[[:space:]]*\(/ || \
1059 /(^|[^_[:alnum:]])TARGET_READ_SP[[:space:]]*\(/ {
1063 BEGIN { doc["register_cached"] = "\
1064 Replace register_cached() with nothing, does not have a regcache parameter"
1065 category["register_cached"] = ari_regression
1067 /(^|[^_[:alnum:]])register_cached[[:space:]]*\(/ {
1068 fail("register_cached")
1071 BEGIN { doc["set_register_cached"] = "\
1072 Replace set_register_cached() with nothing, does not have a regcache parameter"
1073 category["set_register_cached"] = ari_regression
1075 /(^|[^_[:alnum:]])set_register_cached[[:space:]]*\(/ {
1076 fail("set_register_cached")
1079 # Print functions: Use versions that either check for buffer overflow
1080 # or safely allocate a fresh buffer.
1082 BEGIN { doc["sprintf"] = "\
1083 Do not use sprintf, instead use xsnprintf or xstrprintf"
1084 category["sprintf"] = ari_code
1086 /(^|[^_[:alnum:]])sprintf[[:space:]]*\(/ {
1090 BEGIN { doc["vsprintf"] = "\
1091 Do not use vsprintf(), instead use xstrvprintf"
1092 category["vsprintf"] = ari_regression
1094 /(^|[^_[:alnum:]])vsprintf[[:space:]]*\(/ {
1098 BEGIN { doc["asprintf"] = "\
1099 Do not use asprintf(), instead use xstrprintf()"
1100 category["asprintf"] = ari_regression
1102 /(^|[^_[:alnum:]])asprintf[[:space:]]*\(/ {
1106 BEGIN { doc["vasprintf"] = "\
1107 Do not use vasprintf(), instead use xstrvprintf"
1108 fix("vasprintf", "common/common-utils.c", 1)
1109 category["vasprintf"] = ari_regression
1111 /(^|[^_[:alnum:]])vasprintf[[:space:]]*\(/ {
1115 # More generic memory operations
1117 BEGIN { doc["bzero"] = "\
1118 Do not use bzero(), instead use memset()"
1119 category["bzero"] = ari_regression
1121 /(^|[^_[:alnum:]])bzero[[:space:]]*\(/ {
1125 BEGIN { doc["strdup"] = "\
1126 Do not use strdup(), instead use xstrdup()";
1127 category["strdup"] = ari_regression
1129 /(^|[^_[:alnum:]])strdup[[:space:]]*\(/ {
1133 BEGIN { doc["strsave"] = "\
1134 Do not use strsave(), instead use xstrdup() et.al."
1135 category["strsave"] = ari_regression
1137 /(^|[^_[:alnum:]])strsave[[:space:]]*\(/ {
1141 # String compare functions
1143 BEGIN { doc["strnicmp"] = "\
1144 Do not use strnicmp(), instead use strncasecmp()"
1145 category["strnicmp"] = ari_regression
1147 /(^|[^_[:alnum:]])strnicmp[[:space:]]*\(/ {
1151 # Boolean expressions and conditionals
1153 BEGIN { doc["boolean"] = "\
1154 Do not use `boolean'\'', use `int'\'' instead"
1155 category["boolean"] = ari_regression
1157 /(^|[^_[:alnum:]])boolean([^_[:alnum:]]|$)/ {
1158 if (is_yacc_or_lex == 0) {
1163 BEGIN { doc["false"] = "\
1164 Definitely do not use `false'\'' in boolean expressions"
1165 category["false"] = ari_regression
1167 /(^|[^_[:alnum:]])false([^_[:alnum:]]|$)/ {
1168 if (is_yacc_or_lex == 0) {
1173 BEGIN { doc["true"] = "\
1174 Do not try to use `true'\'' in boolean expressions"
1175 category["true"] = ari_regression
1177 /(^|[^_[:alnum:]])true([^_[:alnum:]]|$)/ {
1178 if (is_yacc_or_lex == 0) {
1183 # Typedefs that are either redundant or can be reduced to `struct
1185 # Must be placed before if assignment otherwise ARI exceptions
1186 # are not handled correctly.
1188 BEGIN { doc["d_namelen"] = "\
1189 Do not use dirent.d_namelen, instead use NAMELEN"
1190 category["d_namelen"] = ari_regression
1192 /(^|[^_[:alnum:]])d_namelen([^_[:alnum:]]|$)/ {
1196 BEGIN { doc["strlen d_name"] = "\
1197 Do not use strlen dirent.d_name, instead use NAMELEN"
1198 category["strlen d_name"] = ari_regression
1200 /(^|[^_[:alnum:]])strlen[[:space:]]*\(.*[^_[:alnum:]]d_name([^_[:alnum:]]|$)/ {
1201 fail("strlen d_name")
1204 BEGIN { doc["var_boolean"] = "\
1205 Replace var_boolean with add_setshow_boolean_cmd"
1206 category["var_boolean"] = ari_regression
1207 fix("var_boolean", "gdb/command.h", 1)
1208 # fix only uses the last directory level
1209 fix("var_boolean", "cli/cli-decode.c", 2)
1211 /(^|[^_[:alnum:]])var_boolean([^_[:alnum:]]|$)/ {
1212 if (($0 !~ /(^|[^_[:alnum:]])case *var_boolean:/) \
1213 && ($0 !~ /(^|[^_[:alnum:]])[=!]= *var_boolean/)) {
1218 BEGIN { doc["generic_use_struct_convention"] = "\
1219 Replace generic_use_struct_convention with nothing, \
1220 EXTRACT_STRUCT_VALUE_ADDRESS is a predicate"
1221 category["generic_use_struct_convention"] = ari_regression
1223 /(^|[^_[:alnum:]])generic_use_struct_convention([^_[:alnum:]]|$)/ {
1224 fail("generic_use_struct_convention")
1227 BEGIN { doc["if assignment"] = "\
1228 An IF statement'\''s expression contains an assignment (the GNU coding \
1229 standard discourages this)"
1230 category["if assignment"] = ari_code
1232 BEGIN { doc["if clause more than 50 lines"] = "\
1233 An IF statement'\''s expression expands over 50 lines"
1234 category["if clause more than 50 lines"] = ari_code
1237 # Accumulate continuation lines
1242 /(^|[^_[:alnum:]])if / {
1247 if_brace_end_pos = 0;
1251 # We want everything up to closing brace of same level
1253 if (if_count > 50) {
1254 print "multiline if: " if_full_line $0
1255 fail("if clause more than 50 lines")
1259 if (if_count == 1) {
1260 i = index($0,"if ");
1264 for (i=i; i <= length($0); i++) {
1265 char = substr($0,i,1);
1266 if (char == "(") { if_brace_level++; }
1269 if (!if_brace_level) {
1270 if_brace_end_pos = i;
1271 after_if = substr($0,i+1,length($0));
1272 # Do not parse what is following
1277 if (if_brace_level == 0) {
1278 $0 = substr($0,1,i);
1281 if_full_line = if_full_line $0;
1287 # if we arrive here, we need to concatenate, but we are at brace level 0
1289 (if_brace_end_pos) {
1290 $0 = if_full_line substr($0,1,if_brace_end_pos);
1292 # print "IF: multi line " if_count " found at " FILENAME ":" FNR " \"" $0 "\""
1297 /(^|[^_[:alnum:]])if .* = / {
1298 # print "fail in if " $0
1299 fail("if assignment")
1301 (if_brace_end_pos) {
1303 if_brace_end_pos = 0;
1307 # Printout of all found bug
This page took 0.060299 seconds and 5 git commands to generate.