4b0fddfee7d101da3e0d239a9cab16f347681bea
3 # GDB script to list of problems using awk.
5 # Copyright (C) 2002-2019 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, C++11 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 -WCATEGORY 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 -WCATEGORY Report problems in the specifed category. Valid 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:]]*\*\// {
258 # SNIP - Strip out comments - SNIP
263 comment_p && /\*\// { gsub (/^([^\*]|\*+[^\/\*])*\*+\//, " "); comment_p = 0; }
265 !comment_p { gsub (/\/\*([^\*]|\*+[^\/\*])*\*+\//, " "); }
266 !comment_p && /(^|[^"])\/\*/ { gsub (/\/\*.*$/, " "); comment_p = 1; }
269 BEGIN { doc["_ markup"] = "\
270 All messages should be marked up with _."
271 category["_ markup"] = ari_gettext
273 /^[^"]*[[:space:]](warning|error|error_no_arg|query|perror_with_name)[[:space:]]*\([^_\(a-z]/ {
279 BEGIN { doc["trailing new line"] = "\
280 A message should not have a trailing new line"
281 category["trailing new line"] = ari_gettext
283 /(^|[^_[:alnum:]])(warning|error)[[:space:]]*\(_\(".*\\n"\)[\),]/ {
284 fail("trailing new line")
287 # Include files for which GDB has a custom version.
289 BEGIN { doc["assert.h"] = "\
290 Do not include assert.h, instead include \"gdb_assert.h\"";
291 category["assert.h"] = ari_regression
292 fix("assert.h", "gdb/gdb_assert.h", 0) # it does not use it
294 /^#[[:space:]]*include[[:space:]]+.assert\.h./ {
298 BEGIN { doc["regex.h"] = "\
299 Do not include regex.h, instead include gdb_regex.h"
300 category["regex.h"] = ari_regression
301 fix("regex.h", "gdb/gdb_regex.h", 1)
303 /^#[[:space:]]*include[[:space:]]*.regex\.h./ {
307 BEGIN { doc["xregex.h"] = "\
308 Do not include xregex.h, instead include gdb_regex.h"
309 category["xregex.h"] = ari_regression
310 fix("xregex.h", "gdb/gdb_regex.h", 1)
312 /^#[[:space:]]*include[[:space:]]*.xregex\.h./ {
316 BEGIN { doc["gnu-regex.h"] = "\
317 Do not include gnu-regex.h, instead include gdb_regex.h"
318 category["gnu-regex.h"] = ari_regression
320 /^#[[:space:]]*include[[:space:]]*.gnu-regex\.h./ {
324 BEGIN { doc["wait.h"] = "\
325 Do not include wait.h or sys/wait.h, instead include gdb_wait.h"
326 fix("wait.h", "gdbsupport/gdb_wait.h", 2);
327 category["wait.h"] = ari_regression
329 /^#[[:space:]]*include[[:space:]]*.wait\.h./ \
330 || /^#[[:space:]]*include[[:space:]]*.sys\/wait\.h./ {
334 BEGIN { doc["vfork.h"] = "\
335 Do not include vfork.h, instead include gdb_vfork.h"
336 fix("vfork.h", "gdb/gdb_vfork.h", 1);
337 category["vfork.h"] = ari_regression
339 /^#[[:space:]]*include[[:space:]]*.vfork\.h./ {
343 BEGIN { doc["error not internal-warning"] = "\
344 Do not use error(\"internal-warning\"), instead use internal_warning"
345 category["error not internal-warning"] = ari_regression
347 /error.*\"[Ii]nternal.warning/ {
348 fail("error not internal-warning")
351 BEGIN { doc["%p"] = "\
352 Do not use printf(\"%p\"), instead use printf(\"%s\",paddr()) to dump a \
353 target address, or host_address_to_string() for a host address"
354 category["%p"] = ari_code
356 # Allow gdb %p extensions, but not other uses of %p.
357 /%p[^[\]sF]/ && !/%prec/ {
361 BEGIN { doc["%ll"] = "\
362 Do not use printf(\"%ll\"), instead use printf(\"%s\",phex()) to dump a \
363 `long long'\'' value"
364 category["%ll"] = ari_code
367 /%[0-9]*ll/ && !/scanf \(.*%[0-9]*ll/ {
372 # SNIP - Strip out strings - SNIP
374 # Test on top.c, scm-valprint.c, remote-rdi.c, ada-lang.c
379 # Strip escaped characters.
380 { gsub(/\\./, "."); }
381 # Strip quoted quotes.
382 { gsub(/'\''.'\''/, "'\''.'\''"); }
383 # End of multi-line string
385 if (trace_string) print "EOS:" FNR, $0;
386 gsub (/^[^\"]*\"/, "'\''");
389 # Middle of multi-line string, discard line.
391 if (trace_string) print "MOS:" FNR, $0;
394 # Strip complete strings from the middle of the line
395 !string_p && /\"[^\"]*\"/ {
396 if (trace_string) print "COS:" FNR, $0;
397 gsub (/\"[^\"]*\"/, "'\''");
399 # Start of multi-line string
400 BEGIN { doc["multi-line string"] = "\
401 Multi-line string must have the newline escaped"
402 category["multi-line string"] = ari_regression
405 if (trace_string) print "SOS:" FNR, $0;
407 fail("multi-line string")
409 gsub (/\"[^\"]*$/, "'\''");
417 # Accumulate continuation lines
421 !cont_p { full_line = ""; }
422 /[^\\]\\$/ { gsub (/\\$/, ""); full_line = full_line $0; cont_p = 1; next; }
423 cont_p { $0 = full_line $0; cont_p = 0; full_line = ""; }
426 BEGIN { doc["__FUNCTION__"] = "\
427 Do not use __FUNCTION__, C++11 does not support this macro"
428 category["__FUNCTION__"] = ari_regression
430 /(^|[^_[:alnum:]])__FUNCTION__([^_[:alnum:]]|$)/ {
434 BEGIN { doc["__CYGWIN32__"] = "\
435 Do not use __CYGWIN32__, instead use __CYGWIN__ or, better, an explicit \
437 category["__CYGWIN32__"] = ari_regression
439 /(^|[^_[:alnum:]])__CYGWIN32__([^_[:alnum:]]|$)/ {
443 BEGIN { doc["PTR"] = "\
444 Do not use PTR, C++11 implies `void *'\''"
445 category["PTR"] = ari_regression
446 #fix("PTR", "gdb/utils.c", 6)
448 /(^|[^_[:alnum:]])PTR([^_[:alnum:]]|$)/ {
452 BEGIN { doc["UCASE function"] = "\
453 Function name is uppercase."
454 category["UCASE function"] = ari_code
459 if (ARI_OK == "UCASE function") {
462 # Closing brace found?
463 else if (UCASE_full_line ~ \
464 /^[A-Z][[:alnum:]_]*[[:space:]]*\([^()]*\).*$/) {
465 if ((UCASE_full_line ~ \
466 /^[A-Z][[:alnum:]_]*[[:space:]]*\([^()]*\)[[:space:]]*$/) \
467 && ($0 ~ /^\{/) && (is_yacc_or_lex == 0)) {
471 $0 = UCASE_full_line;
472 fail("UCASE function")
479 UCASE_full_line = UCASE_full_line $0;
482 /^[A-Z][[:alnum:]_]*[[:space:]]*\([^()]*(|\))[[:space:]]*$/ {
484 if (ARI_OK == "UCASE function") {
492 BEGIN { doc["editCase function"] = "\
493 Function name starts lower case but has uppercased letters."
494 category["editCase function"] = ari_code
495 possible_editCase = 0
496 editCase_full_line = ""
498 (possible_editCase) {
499 if (ARI_OK == "editCase function") {
500 possible_editCase = 0
502 # Closing brace found?
503 else if (editCase_full_line ~ \
504 /^[a-z][a-z0-9_]*[A-Z][a-z0-9A-Z_]*[[:space:]]*\([^()]*\).*$/) {
505 if ((editCase_full_line ~ \
506 /^[a-z][a-z0-9_]*[A-Z][a-z0-9A-Z_]*[[:space:]]*\([^()]*\)[[:space:]]*$/) \
507 && ($0 ~ /^\{/) && (is_yacc_or_lex == 0)) {
511 $0 = editCase_full_line;
512 fail("editCase function")
516 possible_editCase = 0
517 editCase_full_line = ""
519 editCase_full_line = editCase_full_line $0;
522 /^[a-z][a-z0-9_]*[A-Z][a-z0-9A-Z_]*[[:space:]]*\([^()]*(|\))[[:space:]]*$/ {
523 possible_editCase = 1
524 if (ARI_OK == "editCase function") {
525 possible_editCase = 0
528 editCase_full_line = $0
531 # Only function implementation should be on first column
532 BEGIN { doc["function call in first column"] = "\
533 Function name in first column should be restricted to function implementation"
534 category["function call in first column"] = ari_code
536 /^[a-z][a-z0-9_]*[[:space:]]*\((|[^*][^()]*)\)[[:space:]]*[^ \t]+/ {
537 fail("function call in first column")
541 BEGIN { doc["hash"] = "\
542 Do not use ` #...'\'', instead use `#...'\''(some compilers only correctly \
543 parse a C preprocessor directive when `#'\'' is the first character on \
545 category["hash"] = ari_regression
551 BEGIN { doc["OP eol"] = "\
552 Do not use &&, or || at the end of a line"
553 category["OP eol"] = ari_code
555 # * operator needs a special treatment as it can be a
556 # valid end of line for a pointer type definition
557 # Only catch case where an assignment or an opening brace is present
558 /(\|\||\&\&|==|!=|[[:space:]][+\-\/])[[:space:]]*$/ \
559 || /(\(|=)[[:space:]].*[[:space:]]\*[[:space:]]*$/ {
563 BEGIN { doc["strerror"] = "\
564 Do not use strerror(), instead use safe_strerror()"
565 category["strerror"] = ari_regression
566 fix("strerror", "gdb/gdb_string.h", 1)
567 fix("strerror", "gdb/gdbsupport/mingw-strerror.c", 1)
568 fix("strerror", "gdb/gdbsupport/posix-strerror.c", 1)
570 /(^|[^_[:alnum:]])strerror[[:space:]]*\(/ {
574 BEGIN { doc["long long"] = "\
575 Do not use `long long'\'', instead use LONGEST"
576 category["long long"] = ari_code
577 # defs.h needs two such patterns for LONGEST and ULONGEST definitions
578 fix("long long", "gdb/defs.h", 2)
580 /(^|[^_[:alnum:]])long[[:space:]]+long([^_[:alnum:]]|$)/ {
584 BEGIN { doc["ATTR_FORMAT"] = "\
585 Do not use ATTR_FORMAT, use ATTRIBUTE_PRINTF instead"
586 category["ATTR_FORMAT"] = ari_regression
588 /(^|[^_[:alnum:]])ATTR_FORMAT([^_[:alnum:]]|$)/ {
592 BEGIN { doc["ATTR_NORETURN"] = "\
593 Do not use ATTR_NORETURN, use ATTRIBUTE_NORETURN instead"
594 category["ATTR_NORETURN"] = ari_regression
596 /(^|[^_[:alnum:]])ATTR_NORETURN([^_[:alnum:]]|$)/ {
597 fail("ATTR_NORETURN")
600 BEGIN { doc["NORETURN"] = "\
601 Do not use NORETURN, use ATTRIBUTE_NORETURN instead"
602 category["NORETURN"] = ari_regression
604 /(^|[^_[:alnum:]])NORETURN([^_[:alnum:]]|$)/ {
611 BEGIN { doc["multiple messages"] = "\
612 Do not use multiple calls to warning or error, instead use a single call"
613 category["multiple messages"] = ari_gettext
618 /(^|[^_[:alnum:]])(warning|error)[[:space:]]*\(/ {
619 if (FNR == warning_fnr + 1) {
620 fail("multiple messages")
626 # Commented out, but left inside sources, just in case.
627 # BEGIN { doc["inline"] = "\
628 # Do not use the inline attribute; \
629 # since the compiler generally ignores this, better algorithm selection \
630 # is needed to improved performance"
631 # category["inline"] = ari_code
633 # /(^|[^_[:alnum:]])inline([^_[:alnum:]]|$)/ {
637 # This test is obsolete as this type
638 # has been deprecated and finally suppressed from GDB sources
639 #BEGIN { doc["obj_private"] = "\
640 #Replace obj_private with objfile_data"
641 # category["obj_private"] = ari_obsolete
643 #/(^|[^_[:alnum:]])obj_private([^_[:alnum:]]|$)/ {
644 # fail("obj_private")
647 BEGIN { doc["abort"] = "\
648 Do not use abort, instead use internal_error; GDB should never abort"
649 category["abort"] = ari_regression
651 /(^|[^_[:alnum:]])abort[[:space:]]*\(/ {
655 BEGIN { doc["basename"] = "\
656 Do not use basename, instead use lbasename"
657 category["basename"] = ari_regression
659 /(^|[^_[:alnum:]])basename[[:space:]]*\(/ {
663 BEGIN { doc["assert"] = "\
664 Do not use assert, instead use gdb_assert or internal_error; assert \
665 calls abort and GDB should never call abort"
666 category["assert"] = ari_regression
668 /(^|[^_[:alnum:]])assert[[:space:]]*\(/ {
672 BEGIN { doc["TARGET_HAS_HARDWARE_WATCHPOINTS"] = "\
673 Replace TARGET_HAS_HARDWARE_WATCHPOINTS with nothing, not needed"
674 category["TARGET_HAS_HARDWARE_WATCHPOINTS"] = ari_regression
676 /(^|[^_[:alnum:]])TARGET_HAS_HARDWARE_WATCHPOINTS([^_[:alnum:]]|$)/ {
677 fail("TARGET_HAS_HARDWARE_WATCHPOINTS")
680 BEGIN { doc["ADD_SHARED_SYMBOL_FILES"] = "\
681 Replace ADD_SHARED_SYMBOL_FILES with nothing, not needed?"
682 category["ADD_SHARED_SYMBOL_FILES"] = ari_regression
684 /(^|[^_[:alnum:]])ADD_SHARED_SYMBOL_FILES([^_[:alnum:]]|$)/ {
685 fail("ADD_SHARED_SYMBOL_FILES")
688 BEGIN { doc["SOLIB_ADD"] = "\
689 Replace SOLIB_ADD with nothing, not needed?"
690 category["SOLIB_ADD"] = ari_regression
692 /(^|[^_[:alnum:]])SOLIB_ADD([^_[:alnum:]]|$)/ {
696 BEGIN { doc["SOLIB_CREATE_INFERIOR_HOOK"] = "\
697 Replace SOLIB_CREATE_INFERIOR_HOOK with nothing, not needed?"
698 category["SOLIB_CREATE_INFERIOR_HOOK"] = ari_regression
700 /(^|[^_[:alnum:]])SOLIB_CREATE_INFERIOR_HOOK([^_[:alnum:]]|$)/ {
701 fail("SOLIB_CREATE_INFERIOR_HOOK")
704 BEGIN { doc["SOLIB_LOADED_LIBRARY_PATHNAME"] = "\
705 Replace SOLIB_LOADED_LIBRARY_PATHNAME with nothing, not needed?"
706 category["SOLIB_LOADED_LIBRARY_PATHNAME"] = ari_regression
708 /(^|[^_[:alnum:]])SOLIB_LOADED_LIBRARY_PATHNAME([^_[:alnum:]]|$)/ {
709 fail("SOLIB_LOADED_LIBRARY_PATHNAME")
712 BEGIN { doc["REGISTER_U_ADDR"] = "\
713 Replace REGISTER_U_ADDR with nothing, not needed?"
714 category["REGISTER_U_ADDR"] = ari_regression
716 /(^|[^_[:alnum:]])REGISTER_U_ADDR([^_[:alnum:]]|$)/ {
717 fail("REGISTER_U_ADDR")
720 BEGIN { doc["PROCESS_LINENUMBER_HOOK"] = "\
721 Replace PROCESS_LINENUMBER_HOOK with nothing, not needed?"
722 category["PROCESS_LINENUMBER_HOOK"] = ari_regression
724 /(^|[^_[:alnum:]])PROCESS_LINENUMBER_HOOK([^_[:alnum:]]|$)/ {
725 fail("PROCESS_LINENUMBER_HOOK")
728 BEGIN { doc["PC_SOLIB"] = "\
729 Replace PC_SOLIB with nothing, not needed?"
730 category["PC_SOLIB"] = ari_regression
732 /(^|[^_[:alnum:]])PC_SOLIB([^_[:alnum:]]|$)/ {
736 BEGIN { doc["IN_SOLIB_DYNSYM_RESOLVE_CODE"] = "\
737 Replace IN_SOLIB_DYNSYM_RESOLVE_CODE with nothing, not needed?"
738 category["IN_SOLIB_DYNSYM_RESOLVE_CODE"] = ari_regression
740 /(^|[^_[:alnum:]])IN_SOLIB_DYNSYM_RESOLVE_CODE([^_[:alnum:]]|$)/ {
741 fail("IN_SOLIB_DYNSYM_RESOLVE_CODE")
744 BEGIN { doc["GCC_COMPILED_FLAG_SYMBOL"] = "\
745 Replace GCC_COMPILED_FLAG_SYMBOL with nothing, not needed?"
746 category["GCC_COMPILED_FLAG_SYMBOL"] = ari_deprecate
748 /(^|[^_[:alnum:]])GCC_COMPILED_FLAG_SYMBOL([^_[:alnum:]]|$)/ {
749 fail("GCC_COMPILED_FLAG_SYMBOL")
752 BEGIN { doc["GCC2_COMPILED_FLAG_SYMBOL"] = "\
753 Replace GCC2_COMPILED_FLAG_SYMBOL with nothing, not needed?"
754 category["GCC2_COMPILED_FLAG_SYMBOL"] = ari_deprecate
756 /(^|[^_[:alnum:]])GCC2_COMPILED_FLAG_SYMBOL([^_[:alnum:]]|$)/ {
757 fail("GCC2_COMPILED_FLAG_SYMBOL")
760 BEGIN { doc["FUNCTION_EPILOGUE_SIZE"] = "\
761 Replace FUNCTION_EPILOGUE_SIZE with nothing, not needed?"
762 category["FUNCTION_EPILOGUE_SIZE"] = ari_regression
764 /(^|[^_[:alnum:]])FUNCTION_EPILOGUE_SIZE([^_[:alnum:]]|$)/ {
765 fail("FUNCTION_EPILOGUE_SIZE")
768 BEGIN { doc["HAVE_VFORK"] = "\
769 Do not use HAVE_VFORK, instead include \"gdb_vfork.h\" and call vfork() \
771 category["HAVE_VFORK"] = ari_regression
773 /(^|[^_[:alnum:]])HAVE_VFORK([^_[:alnum:]]|$)/ {
777 BEGIN { doc["bcmp"] = "\
778 Do not use bcmp(), C++11 implies memcmp()"
779 category["bcmp"] = ari_regression
781 /(^|[^_[:alnum:]])bcmp[[:space:]]*\(/ {
785 BEGIN { doc["setlinebuf"] = "\
786 Do not use setlinebuf(), C++11 implies setvbuf()"
787 category["setlinebuf"] = ari_regression
789 /(^|[^_[:alnum:]])setlinebuf[[:space:]]*\(/ {
793 BEGIN { doc["bcopy"] = "\
794 Do not use bcopy(), C++11 implies memcpy() and memmove()"
795 category["bcopy"] = ari_regression
797 /(^|[^_[:alnum:]])bcopy[[:space:]]*\(/ {
801 BEGIN { doc["get_frame_base"] = "\
802 Replace get_frame_base with get_frame_id, get_frame_base_address, \
803 get_frame_locals_address, or get_frame_args_address."
804 category["get_frame_base"] = ari_obsolete
806 /(^|[^_[:alnum:]])get_frame_base([^_[:alnum:]]|$)/ {
807 fail("get_frame_base")
810 BEGIN { doc["floatformat_to_double"] = "\
811 Do not use floatformat_to_double() from libierty, \
812 instead use floatformat_to_doublest()"
813 category["floatformat_to_double"] = ari_regression
815 /(^|[^_[:alnum:]])floatformat_to_double[[:space:]]*\(/ {
816 fail("floatformat_to_double")
819 BEGIN { doc["floatformat_from_double"] = "\
820 Do not use floatformat_from_double() from libierty, \
821 instead use host_float_ops<T>::from_target()"
822 category["floatformat_from_double"] = ari_regression
824 /(^|[^_[:alnum:]])floatformat_from_double[[:space:]]*\(/ {
825 fail("floatformat_from_double")
828 BEGIN { doc["BIG_ENDIAN"] = "\
829 Do not use BIG_ENDIAN, instead use BFD_ENDIAN_BIG"
830 category["BIG_ENDIAN"] = ari_regression
832 /(^|[^_[:alnum:]])BIG_ENDIAN([^_[:alnum:]]|$)/ {
836 BEGIN { doc["LITTLE_ENDIAN"] = "\
837 Do not use LITTLE_ENDIAN, instead use BFD_ENDIAN_LITTLE";
838 category["LITTLE_ENDIAN"] = ari_regression
840 /(^|[^_[:alnum:]])LITTLE_ENDIAN([^_[:alnum:]]|$)/ {
841 fail("LITTLE_ENDIAN")
844 BEGIN { doc["BIG_ENDIAN"] = "\
845 Do not use BIG_ENDIAN, instead use BFD_ENDIAN_BIG"
846 category["BIG_ENDIAN"] = ari_regression
848 /(^|[^_[:alnum:]])BIG_ENDIAN([^_[:alnum:]]|$)/ {
852 BEGIN { doc["sec_ptr"] = "\
853 Instead of sec_ptr, use struct bfd_section";
854 category["sec_ptr"] = ari_regression
856 /(^|[^_[:alnum:]])sec_ptr([^_[:alnum:]]|$)/ {
860 BEGIN { doc["frame_unwind_unsigned_register"] = "\
861 Replace frame_unwind_unsigned_register with frame_unwind_register_unsigned"
862 category["frame_unwind_unsigned_register"] = ari_regression
864 /(^|[^_[:alnum:]])frame_unwind_unsigned_register([^_[:alnum:]]|$)/ {
865 fail("frame_unwind_unsigned_register")
868 BEGIN { doc["frame_register_read"] = "\
869 Replace frame_register_read() with get_frame_register(), or \
870 possibly introduce a new method safe_get_frame_register()"
871 category["frame_register_read"] = ari_obsolete
873 /(^|[^_[:alnum:]])frame_register_read([^_[:alnum:]]|$)/ {
874 fail("frame_register_read")
877 BEGIN { doc["read_register"] = "\
878 Replace read_register() with regcache_read() et.al."
879 category["read_register"] = ari_regression
881 /(^|[^_[:alnum:]])read_register([^_[:alnum:]]|$)/ {
882 fail("read_register")
885 BEGIN { doc["write_register"] = "\
886 Replace write_register() with regcache_read() et.al."
887 category["write_register"] = ari_regression
889 /(^|[^_[:alnum:]])write_register([^_[:alnum:]]|$)/ {
890 fail("write_register")
893 function report(name) {
894 # Drop any trailing _P.
895 name = gensub(/(_P|_p)$/, "", 1, name)
896 # Convert to lower case
898 # Split into category and bug
899 cat = gensub(/^([[:alpha:]]+)_([_[:alnum:]]*)$/, "\\1", 1, name)
900 bug = gensub(/^([[:alpha:]]+)_([_[:alnum:]]*)$/, "\\2", 1, name)
903 doc[name] = "Do not use " cat " " bug ", see declaration for details"
908 /(^|[^_[:alnum:]])(DEPRECATED|deprecated|set_gdbarch_deprecated|LEGACY|legacy|set_gdbarch_legacy)_/ {
912 name = gensub(/^(|.*[^_[:alnum:]])((DEPRECATED|deprecated|LEGACY|legacy)_[_[:alnum:]]*)(.*)$/, "\\2", 1, line)
913 line = gensub(/^(|.*[^_[:alnum:]])((DEPRECATED|deprecated|LEGACY|legacy)_[_[:alnum:]]*)(.*)$/, "\\1 \\4", 1, line)
914 # print "name =", name, "line =", line
915 if (name == line) break;
920 # Count the number of times each architecture method is set
921 /(^|[^_[:alnum:]])set_gdbarch_[_[:alnum:]]*([^_[:alnum:]]|$)/ {
922 name = gensub(/^.*set_gdbarch_([_[:alnum:]]*).*$/, "\\1", 1, $0)
923 doc["set " name] = "\
924 Call to set_gdbarch_" name
925 category["set " name] = ari_gdbarch
929 # Count the number of times each tm/xm/nm macro is defined or undefined
930 /^#[[:space:]]*(undef|define)[[:space:]]+[[:alnum:]_]+.*$/ \
931 && !/^#[[:space:]]*(undef|define)[[:space:]]+[[:alnum:]_]+_H($|[[:space:]])/ \
932 && FILENAME ~ /(^|\/)config\/(|[^\/]*\/)(tm-|xm-|nm-).*\.h$/ {
933 basename = gensub(/(^|.*\/)([^\/]*)$/, "\\2", 1, FILENAME)
934 type = gensub(/^(tm|xm|nm)-.*\.h$/, "\\1", 1, basename)
935 name = gensub(/^#[[:space:]]*(undef|define)[[:space:]]+([[:alnum:]_]+).*$/, "\\2", 1, $0)
936 if (type == basename) {
939 doc[type " " name] = "\
940 Do not define macros such as " name " in a tm, nm or xm file, \
941 in fact do not provide a tm, nm or xm file"
942 category[type " " name] = ari_macro
946 BEGIN { doc["deprecated_registers"] = "\
947 Replace deprecated_registers with nothing, they have reached \
949 category["deprecated_registers"] = ari_eol
951 /(^|[^_[:alnum:]])deprecated_registers([^_[:alnum:]]|$)/ {
952 fail("deprecated_registers")
955 BEGIN { doc["read_pc"] = "\
956 Replace READ_PC() with frame_pc_unwind; \
957 at present the inferior function call code still uses this"
958 category["read_pc"] = ari_deprecate
960 /(^|[^_[:alnum:]])read_pc[[:space:]]*\(/ || \
961 /(^|[^_[:alnum:]])set_gdbarch_read_pc[[:space:]]*\(/ || \
962 /(^|[^_[:alnum:]])TARGET_READ_PC[[:space:]]*\(/ {
966 BEGIN { doc["write_pc"] = "\
967 Replace write_pc() with get_frame_base_address or get_frame_id; \
968 at present the inferior function call code still uses this when doing \
969 a DECR_PC_AFTER_BREAK"
970 category["write_pc"] = ari_deprecate
972 /(^|[^_[:alnum:]])write_pc[[:space:]]*\(/ || \
973 /(^|[^_[:alnum:]])TARGET_WRITE_PC[[:space:]]*\(/ {
977 BEGIN { doc["generic_target_write_pc"] = "\
978 Replace generic_target_write_pc with a per-architecture implementation, \
979 this relies on PC_REGNUM which is being eliminated"
980 category["generic_target_write_pc"] = ari_regression
982 /(^|[^_[:alnum:]])generic_target_write_pc([^_[:alnum:]]|$)/ {
983 fail("generic_target_write_pc")
986 BEGIN { doc["read_sp"] = "\
987 Replace read_sp() with frame_sp_unwind"
988 category["read_sp"] = ari_regression
990 /(^|[^_[:alnum:]])read_sp[[:space:]]*\(/ || \
991 /(^|[^_[:alnum:]])set_gdbarch_read_sp[[:space:]]*\(/ || \
992 /(^|[^_[:alnum:]])TARGET_READ_SP[[:space:]]*\(/ {
996 BEGIN { doc["register_cached"] = "\
997 Replace register_cached() with nothing, does not have a regcache parameter"
998 category["register_cached"] = ari_regression
1000 /(^|[^_[:alnum:]])register_cached[[:space:]]*\(/ {
1001 fail("register_cached")
1004 BEGIN { doc["set_register_cached"] = "\
1005 Replace set_register_cached() with nothing, does not have a regcache parameter"
1006 category["set_register_cached"] = ari_regression
1008 /(^|[^_[:alnum:]])set_register_cached[[:space:]]*\(/ {
1009 fail("set_register_cached")
1012 # Print functions: Use versions that either check for buffer overflow
1013 # or safely allocate a fresh buffer.
1015 BEGIN { doc["sprintf"] = "\
1016 Do not use sprintf, instead use xsnprintf or xstrprintf"
1017 category["sprintf"] = ari_code
1019 /(^|[^_[:alnum:]])sprintf[[:space:]]*\(/ {
1023 BEGIN { doc["vsprintf"] = "\
1024 Do not use vsprintf(), instead use xstrvprintf"
1025 category["vsprintf"] = ari_regression
1027 /(^|[^_[:alnum:]])vsprintf[[:space:]]*\(/ {
1031 BEGIN { doc["asprintf"] = "\
1032 Do not use asprintf(), instead use xstrprintf()"
1033 category["asprintf"] = ari_regression
1035 /(^|[^_[:alnum:]])asprintf[[:space:]]*\(/ {
1039 BEGIN { doc["vasprintf"] = "\
1040 Do not use vasprintf(), instead use xstrvprintf"
1041 fix("vasprintf", "gdbsupport/common-utils.c", 1)
1042 category["vasprintf"] = ari_regression
1044 /(^|[^_[:alnum:]])vasprintf[[:space:]]*\(/ {
1048 BEGIN { doc["printf_vma"] = "\
1049 Do not use printf_vma, instead use paddress or phex_nz"
1050 category["printf_vma"] = ari_code
1052 /(^|[^_[:alnum:]])printf_vma[[:space:]]*\(/ {
1056 BEGIN { doc["sprintf_vma"] = "\
1057 Do not use sprintf_vma, instead use paddress or phex_nz"
1058 category["sprintf_vma"] = ari_code
1060 /(^|[^_[:alnum:]])sprintf_vma[[:space:]]*\(/ {
1064 # More generic memory operations
1066 BEGIN { doc["bzero"] = "\
1067 Do not use bzero(), instead use memset()"
1068 category["bzero"] = ari_regression
1070 /(^|[^_[:alnum:]])bzero[[:space:]]*\(/ {
1074 BEGIN { doc["strdup"] = "\
1075 Do not use strdup(), instead use xstrdup()";
1076 category["strdup"] = ari_regression
1078 /(^|[^_[:alnum:]])strdup[[:space:]]*\(/ {
1082 BEGIN { doc["strsave"] = "\
1083 Do not use strsave(), instead use xstrdup() et.al."
1084 category["strsave"] = ari_regression
1086 /(^|[^_[:alnum:]])strsave[[:space:]]*\(/ {
1090 # String compare functions
1092 BEGIN { doc["strnicmp"] = "\
1093 Do not use strnicmp(), instead use strncasecmp()"
1094 category["strnicmp"] = ari_regression
1096 /(^|[^_[:alnum:]])strnicmp[[:space:]]*\(/ {
1100 # Typedefs that are either redundant or can be reduced to `struct
1102 # Must be placed before if assignment otherwise ARI exceptions
1103 # are not handled correctly.
1105 BEGIN { doc["d_namelen"] = "\
1106 Do not use dirent.d_namelen, instead use NAMELEN"
1107 category["d_namelen"] = ari_regression
1109 /(^|[^_[:alnum:]])d_namelen([^_[:alnum:]]|$)/ {
1113 BEGIN { doc["strlen d_name"] = "\
1114 Do not use strlen dirent.d_name, instead use NAMELEN"
1115 category["strlen d_name"] = ari_regression
1117 /(^|[^_[:alnum:]])strlen[[:space:]]*\(.*[^_[:alnum:]]d_name([^_[:alnum:]]|$)/ {
1118 fail("strlen d_name")
1121 BEGIN { doc["generic_use_struct_convention"] = "\
1122 Replace generic_use_struct_convention with nothing, \
1123 EXTRACT_STRUCT_VALUE_ADDRESS is a predicate"
1124 category["generic_use_struct_convention"] = ari_regression
1126 /(^|[^_[:alnum:]])generic_use_struct_convention([^_[:alnum:]]|$)/ {
1127 fail("generic_use_struct_convention")
1130 BEGIN { doc["if assignment"] = "\
1131 An IF statement'\''s expression contains an assignment (the GNU coding \
1132 standard discourages this)"
1133 category["if assignment"] = ari_code
1135 BEGIN { doc["if clause more than 50 lines"] = "\
1136 An IF statement'\''s expression expands over 50 lines"
1137 category["if clause more than 50 lines"] = ari_code
1140 # Accumulate continuation lines
1145 /(^|[^_[:alnum:]])if / {
1150 if_brace_end_pos = 0;
1154 # We want everything up to closing brace of same level
1156 if (if_count > 50) {
1157 print "multiline if: " if_full_line $0
1158 fail("if clause more than 50 lines")
1162 if (if_count == 1) {
1163 i = index($0,"if ");
1167 for (i=i; i <= length($0); i++) {
1168 char = substr($0,i,1);
1169 if (char == "(") { if_brace_level++; }
1172 if (!if_brace_level) {
1173 if_brace_end_pos = i;
1174 after_if = substr($0,i+1,length($0));
1175 # Do not parse what is following
1180 if (if_brace_level == 0) {
1181 $0 = substr($0,1,i);
1184 if_full_line = if_full_line $0;
1190 # if we arrive here, we need to concatenate, but we are at brace level 0
1192 (if_brace_end_pos) {
1193 $0 = if_full_line substr($0,1,if_brace_end_pos);
1195 # print "IF: multi line " if_count " found at " FILENAME ":" FNR " \"" $0 "\""
1200 /(^|[^_[:alnum:]])if .* = / {
1201 # print "fail in if " $0
1202 fail("if assignment")
1204 (if_brace_end_pos) {
1206 if_brace_end_pos = 0;
1210 # Printout of all found bug
This page took 0.056678 seconds and 4 git commands to generate.