43f0206de07e479362fc0435c9bd642a0555874d
3 # GDB script to list of problems using awk.
5 # Copyright (C) 2002-2016 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["regex.h"] = "\
310 Do not include regex.h, instead include gdb_regex.h"
311 category["regex.h"] = ari_regression
312 fix("regex.h", "gdb/gdb_regex.h", 1)
314 /^#[[:space:]]*include[[:space:]]*.regex\.h./ {
318 BEGIN { doc["xregex.h"] = "\
319 Do not include xregex.h, instead include gdb_regex.h"
320 category["xregex.h"] = ari_regression
321 fix("xregex.h", "gdb/gdb_regex.h", 1)
323 /^#[[:space:]]*include[[:space:]]*.xregex\.h./ {
327 BEGIN { doc["gnu-regex.h"] = "\
328 Do not include gnu-regex.h, instead include gdb_regex.h"
329 category["gnu-regex.h"] = ari_regression
331 /^#[[:space:]]*include[[:space:]]*.gnu-regex\.h./ {
335 BEGIN { doc["wait.h"] = "\
336 Do not include wait.h or sys/wait.h, instead include gdb_wait.h"
337 fix("wait.h", "common/gdb_wait.h", 2);
338 category["wait.h"] = ari_regression
340 /^#[[:space:]]*include[[:space:]]*.wait\.h./ \
341 || /^#[[:space:]]*include[[:space:]]*.sys\/wait\.h./ {
345 BEGIN { doc["vfork.h"] = "\
346 Do not include vfork.h, instead include gdb_vfork.h"
347 fix("vfork.h", "gdb/gdb_vfork.h", 1);
348 category["vfork.h"] = ari_regression
350 /^#[[:space:]]*include[[:space:]]*.vfork\.h./ {
354 BEGIN { doc["error not internal-warning"] = "\
355 Do not use error(\"internal-warning\"), instead use internal_warning"
356 category["error not internal-warning"] = ari_regression
358 /error.*\"[Ii]nternal.warning/ {
359 fail("error not internal-warning")
362 BEGIN { doc["%p"] = "\
363 Do not use printf(\"%p\"), instead use printf(\"%s\",paddr()) to dump a \
364 target address, or host_address_to_string() for a host address"
365 category["%p"] = ari_code
371 BEGIN { doc["%ll"] = "\
372 Do not use printf(\"%ll\"), instead use printf(\"%s\",phex()) to dump a \
373 `long long'\'' value"
374 category["%ll"] = ari_code
377 /%[0-9]*ll/ && !/scanf \(.*%[0-9]*ll/ {
382 # SNIP - Strip out strings - SNIP
384 # Test on top.c, scm-valprint.c, remote-rdi.c, ada-lang.c
389 # Strip escaped characters.
390 { gsub(/\\./, "."); }
391 # Strip quoted quotes.
392 { gsub(/'\''.'\''/, "'\''.'\''"); }
393 # End of multi-line string
395 if (trace_string) print "EOS:" FNR, $0;
396 gsub (/^[^\"]*\"/, "'\''");
399 # Middle of multi-line string, discard line.
401 if (trace_string) print "MOS:" FNR, $0;
404 # Strip complete strings from the middle of the line
405 !string_p && /\"[^\"]*\"/ {
406 if (trace_string) print "COS:" FNR, $0;
407 gsub (/\"[^\"]*\"/, "'\''");
409 # Start of multi-line string
410 BEGIN { doc["multi-line string"] = "\
411 Multi-line string must have the newline escaped"
412 category["multi-line string"] = ari_regression
415 if (trace_string) print "SOS:" FNR, $0;
417 fail("multi-line string")
419 gsub (/\"[^\"]*$/, "'\''");
427 # Accumulate continuation lines
431 !cont_p { full_line = ""; }
432 /[^\\]\\$/ { gsub (/\\$/, ""); full_line = full_line $0; cont_p = 1; next; }
433 cont_p { $0 = full_line $0; cont_p = 0; full_line = ""; }
436 # GDB uses ISO C 90. Check for any non pure ISO C 90 code
438 BEGIN { doc["PARAMS"] = "\
439 Do not use PARAMS(), ISO C 90 implies prototypes"
440 category["PARAMS"] = ari_regression
442 /(^|[^_[:alnum:]])PARAMS([^_[:alnum:]]|$)/ {
446 BEGIN { doc["__func__"] = "\
447 Do not use __func__, ISO C 90 does not support this macro"
448 category["__func__"] = ari_regression
449 fix("__func__", "common/gdb_assert.h", 1)
451 /(^|[^_[:alnum:]])__func__([^_[:alnum:]]|$)/ {
455 BEGIN { doc["__FUNCTION__"] = "\
456 Do not use __FUNCTION__, ISO C 90 does not support this macro"
457 category["__FUNCTION__"] = ari_regression
459 /(^|[^_[:alnum:]])__FUNCTION__([^_[:alnum:]]|$)/ {
463 BEGIN { doc["__CYGWIN32__"] = "\
464 Do not use __CYGWIN32__, instead use __CYGWIN__ or, better, an explicit \
466 category["__CYGWIN32__"] = ari_regression
468 /(^|[^_[:alnum:]])__CYGWIN32__([^_[:alnum:]]|$)/ {
472 BEGIN { doc["PTR"] = "\
473 Do not use PTR, ISO C 90 implies `void *'\''"
474 category["PTR"] = ari_regression
475 #fix("PTR", "gdb/utils.c", 6)
477 /(^|[^_[:alnum:]])PTR([^_[:alnum:]]|$)/ {
481 BEGIN { doc["UCASE function"] = "\
482 Function name is uppercase."
483 category["UCASE function"] = ari_code
488 if (ARI_OK == "UCASE function") {
491 # Closing brace found?
492 else if (UCASE_full_line ~ \
493 /^[A-Z][[:alnum:]_]*[[:space:]]*\([^()]*\).*$/) {
494 if ((UCASE_full_line ~ \
495 /^[A-Z][[:alnum:]_]*[[:space:]]*\([^()]*\)[[:space:]]*$/) \
496 && ($0 ~ /^\{/) && (is_yacc_or_lex == 0)) {
500 $0 = UCASE_full_line;
501 fail("UCASE function")
508 UCASE_full_line = UCASE_full_line $0;
511 /^[A-Z][[:alnum:]_]*[[:space:]]*\([^()]*(|\))[[:space:]]*$/ {
513 if (ARI_OK == "UCASE function") {
521 BEGIN { doc["editCase function"] = "\
522 Function name starts lower case but has uppercased letters."
523 category["editCase function"] = ari_code
524 possible_editCase = 0
525 editCase_full_line = ""
527 (possible_editCase) {
528 if (ARI_OK == "editCase function") {
529 possible_editCase = 0
531 # Closing brace found?
532 else if (editCase_full_line ~ \
533 /^[a-z][a-z0-9_]*[A-Z][a-z0-9A-Z_]*[[:space:]]*\([^()]*\).*$/) {
534 if ((editCase_full_line ~ \
535 /^[a-z][a-z0-9_]*[A-Z][a-z0-9A-Z_]*[[:space:]]*\([^()]*\)[[:space:]]*$/) \
536 && ($0 ~ /^\{/) && (is_yacc_or_lex == 0)) {
540 $0 = editCase_full_line;
541 fail("editCase function")
545 possible_editCase = 0
546 editCase_full_line = ""
548 editCase_full_line = editCase_full_line $0;
551 /^[a-z][a-z0-9_]*[A-Z][a-z0-9A-Z_]*[[:space:]]*\([^()]*(|\))[[:space:]]*$/ {
552 possible_editCase = 1
553 if (ARI_OK == "editCase function") {
554 possible_editCase = 0
557 editCase_full_line = $0
560 # Only function implementation should be on first column
561 BEGIN { doc["function call in first column"] = "\
562 Function name in first column should be restricted to function implementation"
563 category["function call in first column"] = ari_code
565 /^[a-z][a-z0-9_]*[[:space:]]*\((|[^*][^()]*)\)[[:space:]]*[^ \t]+/ {
566 fail("function call in first column")
570 # Functions without any parameter should have (void)
571 # after their name not simply ().
572 BEGIN { doc["no parameter function"] = "\
573 Function having no parameter should be declared with funcname (void)."
574 category["no parameter function"] = ari_code
576 /^[a-zA-Z][a-z0-9A-Z_]*[[:space:]]*\(\)/ {
577 fail("no parameter function")
580 BEGIN { doc["hash"] = "\
581 Do not use ` #...'\'', instead use `#...'\''(some compilers only correctly \
582 parse a C preprocessor directive when `#'\'' is the first character on \
584 category["hash"] = ari_regression
590 BEGIN { doc["OP eol"] = "\
591 Do not use &&, or || at the end of a line"
592 category["OP eol"] = ari_code
594 # * operator needs a special treatment as it can be a
595 # valid end of line for a pointer type definition
596 # Only catch case where an assignment or an opening brace is present
597 /(\|\||\&\&|==|!=|[[:space:]][+\-\/])[[:space:]]*$/ \
598 || /(\(|=)[[:space:]].*[[:space:]]\*[[:space:]]*$/ {
602 BEGIN { doc["strerror"] = "\
603 Do not use strerror(), instead use safe_strerror()"
604 category["strerror"] = ari_regression
605 fix("strerror", "gdb/gdb_string.h", 1)
606 fix("strerror", "gdb/common/mingw-strerror.c", 1)
607 fix("strerror", "gdb/common/posix-strerror.c", 1)
609 /(^|[^_[:alnum:]])strerror[[:space:]]*\(/ {
613 BEGIN { doc["long long"] = "\
614 Do not use `long long'\'', instead use LONGEST"
615 category["long long"] = ari_code
616 # defs.h needs two such patterns for LONGEST and ULONGEST definitions
617 fix("long long", "gdb/defs.h", 2)
619 /(^|[^_[:alnum:]])long[[:space:]]+long([^_[:alnum:]]|$)/ {
623 BEGIN { doc["ATTRIBUTE_UNUSED"] = "\
624 Do not use ATTRIBUTE_UNUSED, do not bother (GDB is compiled with -Werror and, \
625 consequently, is not able to tolerate false warnings. Since -Wunused-param \
626 produces such warnings, neither that warning flag nor ATTRIBUTE_UNUSED \
628 category["ATTRIBUTE_UNUSED"] = ari_regression
630 /(^|[^_[:alnum:]])ATTRIBUTE_UNUSED([^_[:alnum:]]|$)/ {
631 fail("ATTRIBUTE_UNUSED")
634 BEGIN { doc["ATTR_FORMAT"] = "\
635 Do not use ATTR_FORMAT, use ATTRIBUTE_PRINTF instead"
636 category["ATTR_FORMAT"] = ari_regression
638 /(^|[^_[:alnum:]])ATTR_FORMAT([^_[:alnum:]]|$)/ {
642 BEGIN { doc["ATTR_NORETURN"] = "\
643 Do not use ATTR_NORETURN, use ATTRIBUTE_NORETURN instead"
644 category["ATTR_NORETURN"] = ari_regression
646 /(^|[^_[:alnum:]])ATTR_NORETURN([^_[:alnum:]]|$)/ {
647 fail("ATTR_NORETURN")
650 BEGIN { doc["NORETURN"] = "\
651 Do not use NORETURN, use ATTRIBUTE_NORETURN instead"
652 category["NORETURN"] = ari_regression
654 /(^|[^_[:alnum:]])NORETURN([^_[:alnum:]]|$)/ {
661 BEGIN { doc["multiple messages"] = "\
662 Do not use multiple calls to warning or error, instead use a single call"
663 category["multiple messages"] = ari_gettext
668 /(^|[^_[:alnum:]])(warning|error)[[:space:]]*\(/ {
669 if (FNR == warning_fnr + 1) {
670 fail("multiple messages")
676 # Commented out, but left inside sources, just in case.
677 # BEGIN { doc["inline"] = "\
678 # Do not use the inline attribute; \
679 # since the compiler generally ignores this, better algorithm selection \
680 # is needed to improved performance"
681 # category["inline"] = ari_code
683 # /(^|[^_[:alnum:]])inline([^_[:alnum:]]|$)/ {
687 # This test is obsolete as this type
688 # has been deprecated and finally suppressed from GDB sources
689 #BEGIN { doc["obj_private"] = "\
690 #Replace obj_private with objfile_data"
691 # category["obj_private"] = ari_obsolete
693 #/(^|[^_[:alnum:]])obj_private([^_[:alnum:]]|$)/ {
694 # fail("obj_private")
697 BEGIN { doc["abort"] = "\
698 Do not use abort, instead use internal_error; GDB should never abort"
699 category["abort"] = ari_regression
700 fix("abort", "gdb/utils.c", 3)
702 /(^|[^_[:alnum:]])abort[[:space:]]*\(/ {
706 BEGIN { doc["basename"] = "\
707 Do not use basename, instead use lbasename"
708 category["basename"] = ari_regression
710 /(^|[^_[:alnum:]])basename[[:space:]]*\(/ {
714 BEGIN { doc["assert"] = "\
715 Do not use assert, instead use gdb_assert or internal_error; assert \
716 calls abort and GDB should never call abort"
717 category["assert"] = ari_regression
719 /(^|[^_[:alnum:]])assert[[:space:]]*\(/ {
723 BEGIN { doc["TARGET_HAS_HARDWARE_WATCHPOINTS"] = "\
724 Replace TARGET_HAS_HARDWARE_WATCHPOINTS with nothing, not needed"
725 category["TARGET_HAS_HARDWARE_WATCHPOINTS"] = ari_regression
727 /(^|[^_[:alnum:]])TARGET_HAS_HARDWARE_WATCHPOINTS([^_[:alnum:]]|$)/ {
728 fail("TARGET_HAS_HARDWARE_WATCHPOINTS")
731 BEGIN { doc["ADD_SHARED_SYMBOL_FILES"] = "\
732 Replace ADD_SHARED_SYMBOL_FILES with nothing, not needed?"
733 category["ADD_SHARED_SYMBOL_FILES"] = ari_regression
735 /(^|[^_[:alnum:]])ADD_SHARED_SYMBOL_FILES([^_[:alnum:]]|$)/ {
736 fail("ADD_SHARED_SYMBOL_FILES")
739 BEGIN { doc["SOLIB_ADD"] = "\
740 Replace SOLIB_ADD with nothing, not needed?"
741 category["SOLIB_ADD"] = ari_regression
743 /(^|[^_[:alnum:]])SOLIB_ADD([^_[:alnum:]]|$)/ {
747 BEGIN { doc["SOLIB_CREATE_INFERIOR_HOOK"] = "\
748 Replace SOLIB_CREATE_INFERIOR_HOOK with nothing, not needed?"
749 category["SOLIB_CREATE_INFERIOR_HOOK"] = ari_regression
751 /(^|[^_[:alnum:]])SOLIB_CREATE_INFERIOR_HOOK([^_[:alnum:]]|$)/ {
752 fail("SOLIB_CREATE_INFERIOR_HOOK")
755 BEGIN { doc["SOLIB_LOADED_LIBRARY_PATHNAME"] = "\
756 Replace SOLIB_LOADED_LIBRARY_PATHNAME with nothing, not needed?"
757 category["SOLIB_LOADED_LIBRARY_PATHNAME"] = ari_regression
759 /(^|[^_[:alnum:]])SOLIB_LOADED_LIBRARY_PATHNAME([^_[:alnum:]]|$)/ {
760 fail("SOLIB_LOADED_LIBRARY_PATHNAME")
763 BEGIN { doc["REGISTER_U_ADDR"] = "\
764 Replace REGISTER_U_ADDR with nothing, not needed?"
765 category["REGISTER_U_ADDR"] = ari_regression
767 /(^|[^_[:alnum:]])REGISTER_U_ADDR([^_[:alnum:]]|$)/ {
768 fail("REGISTER_U_ADDR")
771 BEGIN { doc["PROCESS_LINENUMBER_HOOK"] = "\
772 Replace PROCESS_LINENUMBER_HOOK with nothing, not needed?"
773 category["PROCESS_LINENUMBER_HOOK"] = ari_regression
775 /(^|[^_[:alnum:]])PROCESS_LINENUMBER_HOOK([^_[:alnum:]]|$)/ {
776 fail("PROCESS_LINENUMBER_HOOK")
779 BEGIN { doc["PC_SOLIB"] = "\
780 Replace PC_SOLIB with nothing, not needed?"
781 category["PC_SOLIB"] = ari_regression
783 /(^|[^_[:alnum:]])PC_SOLIB([^_[:alnum:]]|$)/ {
787 BEGIN { doc["IN_SOLIB_DYNSYM_RESOLVE_CODE"] = "\
788 Replace IN_SOLIB_DYNSYM_RESOLVE_CODE with nothing, not needed?"
789 category["IN_SOLIB_DYNSYM_RESOLVE_CODE"] = ari_regression
791 /(^|[^_[:alnum:]])IN_SOLIB_DYNSYM_RESOLVE_CODE([^_[:alnum:]]|$)/ {
792 fail("IN_SOLIB_DYNSYM_RESOLVE_CODE")
795 BEGIN { doc["GCC_COMPILED_FLAG_SYMBOL"] = "\
796 Replace GCC_COMPILED_FLAG_SYMBOL with nothing, not needed?"
797 category["GCC_COMPILED_FLAG_SYMBOL"] = ari_deprecate
799 /(^|[^_[:alnum:]])GCC_COMPILED_FLAG_SYMBOL([^_[:alnum:]]|$)/ {
800 fail("GCC_COMPILED_FLAG_SYMBOL")
803 BEGIN { doc["GCC2_COMPILED_FLAG_SYMBOL"] = "\
804 Replace GCC2_COMPILED_FLAG_SYMBOL with nothing, not needed?"
805 category["GCC2_COMPILED_FLAG_SYMBOL"] = ari_deprecate
807 /(^|[^_[:alnum:]])GCC2_COMPILED_FLAG_SYMBOL([^_[:alnum:]]|$)/ {
808 fail("GCC2_COMPILED_FLAG_SYMBOL")
811 BEGIN { doc["FUNCTION_EPILOGUE_SIZE"] = "\
812 Replace FUNCTION_EPILOGUE_SIZE with nothing, not needed?"
813 category["FUNCTION_EPILOGUE_SIZE"] = ari_regression
815 /(^|[^_[:alnum:]])FUNCTION_EPILOGUE_SIZE([^_[:alnum:]]|$)/ {
816 fail("FUNCTION_EPILOGUE_SIZE")
819 BEGIN { doc["HAVE_VFORK"] = "\
820 Do not use HAVE_VFORK, instead include \"gdb_vfork.h\" and call vfork() \
822 category["HAVE_VFORK"] = ari_regression
824 /(^|[^_[:alnum:]])HAVE_VFORK([^_[:alnum:]]|$)/ {
828 BEGIN { doc["bcmp"] = "\
829 Do not use bcmp(), ISO C 90 implies memcmp()"
830 category["bcmp"] = ari_regression
832 /(^|[^_[:alnum:]])bcmp[[:space:]]*\(/ {
836 BEGIN { doc["setlinebuf"] = "\
837 Do not use setlinebuf(), ISO C 90 implies setvbuf()"
838 category["setlinebuf"] = ari_regression
840 /(^|[^_[:alnum:]])setlinebuf[[:space:]]*\(/ {
844 BEGIN { doc["bcopy"] = "\
845 Do not use bcopy(), ISO C 90 implies memcpy() and memmove()"
846 category["bcopy"] = ari_regression
848 /(^|[^_[:alnum:]])bcopy[[:space:]]*\(/ {
852 BEGIN { doc["get_frame_base"] = "\
853 Replace get_frame_base with get_frame_id, get_frame_base_address, \
854 get_frame_locals_address, or get_frame_args_address."
855 category["get_frame_base"] = ari_obsolete
857 /(^|[^_[:alnum:]])get_frame_base([^_[:alnum:]]|$)/ {
858 fail("get_frame_base")
861 BEGIN { doc["floatformat_to_double"] = "\
862 Do not use floatformat_to_double() from libierty, \
863 instead use floatformat_to_doublest()"
864 fix("floatformat_to_double", "gdb/doublest.c", 1)
865 category["floatformat_to_double"] = ari_regression
867 /(^|[^_[:alnum:]])floatformat_to_double[[:space:]]*\(/ {
868 fail("floatformat_to_double")
871 BEGIN { doc["floatformat_from_double"] = "\
872 Do not use floatformat_from_double() from libierty, \
873 instead use floatformat_from_doublest()"
874 category["floatformat_from_double"] = ari_regression
876 /(^|[^_[:alnum:]])floatformat_from_double[[:space:]]*\(/ {
877 fail("floatformat_from_double")
880 BEGIN { doc["BIG_ENDIAN"] = "\
881 Do not use BIG_ENDIAN, instead use BFD_ENDIAN_BIG"
882 category["BIG_ENDIAN"] = ari_regression
884 /(^|[^_[:alnum:]])BIG_ENDIAN([^_[:alnum:]]|$)/ {
888 BEGIN { doc["LITTLE_ENDIAN"] = "\
889 Do not use LITTLE_ENDIAN, instead use BFD_ENDIAN_LITTLE";
890 category["LITTLE_ENDIAN"] = ari_regression
892 /(^|[^_[:alnum:]])LITTLE_ENDIAN([^_[:alnum:]]|$)/ {
893 fail("LITTLE_ENDIAN")
896 BEGIN { doc["BIG_ENDIAN"] = "\
897 Do not use BIG_ENDIAN, instead use BFD_ENDIAN_BIG"
898 category["BIG_ENDIAN"] = ari_regression
900 /(^|[^_[:alnum:]])BIG_ENDIAN([^_[:alnum:]]|$)/ {
904 BEGIN { doc["sec_ptr"] = "\
905 Instead of sec_ptr, use struct bfd_section";
906 category["sec_ptr"] = ari_regression
908 /(^|[^_[:alnum:]])sec_ptr([^_[:alnum:]]|$)/ {
912 BEGIN { doc["frame_unwind_unsigned_register"] = "\
913 Replace frame_unwind_unsigned_register with frame_unwind_register_unsigned"
914 category["frame_unwind_unsigned_register"] = ari_regression
916 /(^|[^_[:alnum:]])frame_unwind_unsigned_register([^_[:alnum:]]|$)/ {
917 fail("frame_unwind_unsigned_register")
920 BEGIN { doc["frame_register_read"] = "\
921 Replace frame_register_read() with get_frame_register(), or \
922 possibly introduce a new method safe_get_frame_register()"
923 category["frame_register_read"] = ari_obsolete
925 /(^|[^_[:alnum:]])frame_register_read([^_[:alnum:]]|$)/ {
926 fail("frame_register_read")
929 BEGIN { doc["read_register"] = "\
930 Replace read_register() with regcache_read() et.al."
931 category["read_register"] = ari_regression
933 /(^|[^_[:alnum:]])read_register([^_[:alnum:]]|$)/ {
934 fail("read_register")
937 BEGIN { doc["write_register"] = "\
938 Replace write_register() with regcache_read() et.al."
939 category["write_register"] = ari_regression
941 /(^|[^_[:alnum:]])write_register([^_[:alnum:]]|$)/ {
942 fail("write_register")
945 function report(name) {
946 # Drop any trailing _P.
947 name = gensub(/(_P|_p)$/, "", 1, name)
948 # Convert to lower case
950 # Split into category and bug
951 cat = gensub(/^([[:alpha:]]+)_([_[:alnum:]]*)$/, "\\1", 1, name)
952 bug = gensub(/^([[:alpha:]]+)_([_[:alnum:]]*)$/, "\\2", 1, name)
955 doc[name] = "Do not use " cat " " bug ", see declaration for details"
960 /(^|[^_[:alnum:]])(DEPRECATED|deprecated|set_gdbarch_deprecated|LEGACY|legacy|set_gdbarch_legacy)_/ {
964 name = gensub(/^(|.*[^_[:alnum:]])((DEPRECATED|deprecated|LEGACY|legacy)_[_[:alnum:]]*)(.*)$/, "\\2", 1, line)
965 line = gensub(/^(|.*[^_[:alnum:]])((DEPRECATED|deprecated|LEGACY|legacy)_[_[:alnum:]]*)(.*)$/, "\\1 \\4", 1, line)
966 # print "name =", name, "line =", line
967 if (name == line) break;
972 # Count the number of times each architecture method is set
973 /(^|[^_[:alnum:]])set_gdbarch_[_[:alnum:]]*([^_[:alnum:]]|$)/ {
974 name = gensub(/^.*set_gdbarch_([_[:alnum:]]*).*$/, "\\1", 1, $0)
975 doc["set " name] = "\
976 Call to set_gdbarch_" name
977 category["set " name] = ari_gdbarch
981 # Count the number of times each tm/xm/nm macro is defined or undefined
982 /^#[[:space:]]*(undef|define)[[:space:]]+[[:alnum:]_]+.*$/ \
983 && !/^#[[:space:]]*(undef|define)[[:space:]]+[[:alnum:]_]+_H($|[[:space:]])/ \
984 && FILENAME ~ /(^|\/)config\/(|[^\/]*\/)(tm-|xm-|nm-).*\.h$/ {
985 basename = gensub(/(^|.*\/)([^\/]*)$/, "\\2", 1, FILENAME)
986 type = gensub(/^(tm|xm|nm)-.*\.h$/, "\\1", 1, basename)
987 name = gensub(/^#[[:space:]]*(undef|define)[[:space:]]+([[:alnum:]_]+).*$/, "\\2", 1, $0)
988 if (type == basename) {
991 doc[type " " name] = "\
992 Do not define macros such as " name " in a tm, nm or xm file, \
993 in fact do not provide a tm, nm or xm file"
994 category[type " " name] = ari_macro
998 BEGIN { doc["deprecated_registers"] = "\
999 Replace deprecated_registers with nothing, they have reached \
1001 category["deprecated_registers"] = ari_eol
1003 /(^|[^_[:alnum:]])deprecated_registers([^_[:alnum:]]|$)/ {
1004 fail("deprecated_registers")
1007 BEGIN { doc["read_pc"] = "\
1008 Replace READ_PC() with frame_pc_unwind; \
1009 at present the inferior function call code still uses this"
1010 category["read_pc"] = ari_deprecate
1012 /(^|[^_[:alnum:]])read_pc[[:space:]]*\(/ || \
1013 /(^|[^_[:alnum:]])set_gdbarch_read_pc[[:space:]]*\(/ || \
1014 /(^|[^_[:alnum:]])TARGET_READ_PC[[:space:]]*\(/ {
1018 BEGIN { doc["write_pc"] = "\
1019 Replace write_pc() with get_frame_base_address or get_frame_id; \
1020 at present the inferior function call code still uses this when doing \
1021 a DECR_PC_AFTER_BREAK"
1022 category["write_pc"] = ari_deprecate
1024 /(^|[^_[:alnum:]])write_pc[[:space:]]*\(/ || \
1025 /(^|[^_[:alnum:]])TARGET_WRITE_PC[[:space:]]*\(/ {
1029 BEGIN { doc["generic_target_write_pc"] = "\
1030 Replace generic_target_write_pc with a per-architecture implementation, \
1031 this relies on PC_REGNUM which is being eliminated"
1032 category["generic_target_write_pc"] = ari_regression
1034 /(^|[^_[:alnum:]])generic_target_write_pc([^_[:alnum:]]|$)/ {
1035 fail("generic_target_write_pc")
1038 BEGIN { doc["read_sp"] = "\
1039 Replace read_sp() with frame_sp_unwind"
1040 category["read_sp"] = ari_regression
1042 /(^|[^_[:alnum:]])read_sp[[:space:]]*\(/ || \
1043 /(^|[^_[:alnum:]])set_gdbarch_read_sp[[:space:]]*\(/ || \
1044 /(^|[^_[:alnum:]])TARGET_READ_SP[[:space:]]*\(/ {
1048 BEGIN { doc["register_cached"] = "\
1049 Replace register_cached() with nothing, does not have a regcache parameter"
1050 category["register_cached"] = ari_regression
1052 /(^|[^_[:alnum:]])register_cached[[:space:]]*\(/ {
1053 fail("register_cached")
1056 BEGIN { doc["set_register_cached"] = "\
1057 Replace set_register_cached() with nothing, does not have a regcache parameter"
1058 category["set_register_cached"] = ari_regression
1060 /(^|[^_[:alnum:]])set_register_cached[[:space:]]*\(/ {
1061 fail("set_register_cached")
1064 # Print functions: Use versions that either check for buffer overflow
1065 # or safely allocate a fresh buffer.
1067 BEGIN { doc["sprintf"] = "\
1068 Do not use sprintf, instead use xsnprintf or xstrprintf"
1069 category["sprintf"] = ari_code
1071 /(^|[^_[:alnum:]])sprintf[[:space:]]*\(/ {
1075 BEGIN { doc["vsprintf"] = "\
1076 Do not use vsprintf(), instead use xstrvprintf"
1077 category["vsprintf"] = ari_regression
1079 /(^|[^_[:alnum:]])vsprintf[[:space:]]*\(/ {
1083 BEGIN { doc["asprintf"] = "\
1084 Do not use asprintf(), instead use xstrprintf()"
1085 category["asprintf"] = ari_regression
1087 /(^|[^_[:alnum:]])asprintf[[:space:]]*\(/ {
1091 BEGIN { doc["vasprintf"] = "\
1092 Do not use vasprintf(), instead use xstrvprintf"
1093 fix("vasprintf", "common/common-utils.c", 1)
1094 category["vasprintf"] = ari_regression
1096 /(^|[^_[:alnum:]])vasprintf[[:space:]]*\(/ {
1100 # More generic memory operations
1102 BEGIN { doc["bzero"] = "\
1103 Do not use bzero(), instead use memset()"
1104 category["bzero"] = ari_regression
1106 /(^|[^_[:alnum:]])bzero[[:space:]]*\(/ {
1110 BEGIN { doc["strdup"] = "\
1111 Do not use strdup(), instead use xstrdup()";
1112 category["strdup"] = ari_regression
1114 /(^|[^_[:alnum:]])strdup[[:space:]]*\(/ {
1118 BEGIN { doc["strsave"] = "\
1119 Do not use strsave(), instead use xstrdup() et.al."
1120 category["strsave"] = ari_regression
1122 /(^|[^_[:alnum:]])strsave[[:space:]]*\(/ {
1126 # String compare functions
1128 BEGIN { doc["strnicmp"] = "\
1129 Do not use strnicmp(), instead use strncasecmp()"
1130 category["strnicmp"] = ari_regression
1132 /(^|[^_[:alnum:]])strnicmp[[:space:]]*\(/ {
1136 # Boolean expressions and conditionals
1138 BEGIN { doc["boolean"] = "\
1139 Do not use `boolean'\'', use `int'\'' instead"
1140 category["boolean"] = ari_regression
1142 /(^|[^_[:alnum:]])boolean([^_[:alnum:]]|$)/ {
1143 if (is_yacc_or_lex == 0) {
1148 BEGIN { doc["false"] = "\
1149 Definitely do not use `false'\'' in boolean expressions"
1150 category["false"] = ari_regression
1152 /(^|[^_[:alnum:]])false([^_[:alnum:]]|$)/ {
1153 if (is_yacc_or_lex == 0) {
1158 BEGIN { doc["true"] = "\
1159 Do not try to use `true'\'' in boolean expressions"
1160 category["true"] = ari_regression
1162 /(^|[^_[:alnum:]])true([^_[:alnum:]]|$)/ {
1163 if (is_yacc_or_lex == 0) {
1168 # Typedefs that are either redundant or can be reduced to `struct
1170 # Must be placed before if assignment otherwise ARI exceptions
1171 # are not handled correctly.
1173 BEGIN { doc["d_namelen"] = "\
1174 Do not use dirent.d_namelen, instead use NAMELEN"
1175 category["d_namelen"] = ari_regression
1177 /(^|[^_[:alnum:]])d_namelen([^_[:alnum:]]|$)/ {
1181 BEGIN { doc["strlen d_name"] = "\
1182 Do not use strlen dirent.d_name, instead use NAMELEN"
1183 category["strlen d_name"] = ari_regression
1185 /(^|[^_[:alnum:]])strlen[[:space:]]*\(.*[^_[:alnum:]]d_name([^_[:alnum:]]|$)/ {
1186 fail("strlen d_name")
1189 BEGIN { doc["var_boolean"] = "\
1190 Replace var_boolean with add_setshow_boolean_cmd"
1191 category["var_boolean"] = ari_regression
1192 fix("var_boolean", "gdb/command.h", 1)
1193 # fix only uses the last directory level
1194 fix("var_boolean", "cli/cli-decode.c", 2)
1196 /(^|[^_[:alnum:]])var_boolean([^_[:alnum:]]|$)/ {
1197 if (($0 !~ /(^|[^_[:alnum:]])case *var_boolean:/) \
1198 && ($0 !~ /(^|[^_[:alnum:]])[=!]= *var_boolean/)) {
1203 BEGIN { doc["generic_use_struct_convention"] = "\
1204 Replace generic_use_struct_convention with nothing, \
1205 EXTRACT_STRUCT_VALUE_ADDRESS is a predicate"
1206 category["generic_use_struct_convention"] = ari_regression
1208 /(^|[^_[:alnum:]])generic_use_struct_convention([^_[:alnum:]]|$)/ {
1209 fail("generic_use_struct_convention")
1212 BEGIN { doc["if assignment"] = "\
1213 An IF statement'\''s expression contains an assignment (the GNU coding \
1214 standard discourages this)"
1215 category["if assignment"] = ari_code
1217 BEGIN { doc["if clause more than 50 lines"] = "\
1218 An IF statement'\''s expression expands over 50 lines"
1219 category["if clause more than 50 lines"] = ari_code
1222 # Accumulate continuation lines
1227 /(^|[^_[:alnum:]])if / {
1232 if_brace_end_pos = 0;
1236 # We want everything up to closing brace of same level
1238 if (if_count > 50) {
1239 print "multiline if: " if_full_line $0
1240 fail("if clause more than 50 lines")
1244 if (if_count == 1) {
1245 i = index($0,"if ");
1249 for (i=i; i <= length($0); i++) {
1250 char = substr($0,i,1);
1251 if (char == "(") { if_brace_level++; }
1254 if (!if_brace_level) {
1255 if_brace_end_pos = i;
1256 after_if = substr($0,i+1,length($0));
1257 # Do not parse what is following
1262 if (if_brace_level == 0) {
1263 $0 = substr($0,1,i);
1266 if_full_line = if_full_line $0;
1272 # if we arrive here, we need to concatenate, but we are at brace level 0
1274 (if_brace_end_pos) {
1275 $0 = if_full_line substr($0,1,if_brace_end_pos);
1277 # print "IF: multi line " if_count " found at " FILENAME ":" FNR " \"" $0 "\""
1282 /(^|[^_[:alnum:]])if .* = / {
1283 # print "fail in if " $0
1284 fail("if assignment")
1286 (if_brace_end_pos) {
1288 if_brace_end_pos = 0;
1292 # Printout of all found bug
This page took 0.0593 seconds and 4 git commands to generate.