02c3647388ccfe30368dc4f62815a1004b5e25d4
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. The category
64 can be prefixed with "no-". Valid categories
71 # Parse the various options
77 -Wall ) Woptions
="${all}" ;;
78 -Wari ) Woptions
="${ari}" ;;
80 -W* ) Woptions
="${Woptions} `echo x$1 | sed -e 's/x-W//'`" ;;
81 --print-doc ) print_doc
=1 ;;
82 --print-idx ) print_idx
=1 ;;
83 --src=* ) srclines
="`echo $1 | sed -e 's/--src=/srclines=\"/'`\"" ;;
86 -* ) usage
"$1: unknown option" ;;
91 if test -n "$Woptions" ; then
97 # -Werror implies treating all warnings as errors.
98 if test -n "${Werror}" ; then
99 error
="${error} ${warning}"
103 # Validate all errors and warnings.
104 for w
in ${warning} ${error}
107 no-
*) w
=`echo x$w | sed -e 's/xno-//'`;;
112 * ) usage
"Unknown option -W${w}" ;;
117 # make certain that there is at least one file.
118 if test $# -eq 0 -a ${print_doc} = 0
120 usage
"Missing file."
124 # Convert the errors/warnings into corresponding array entries.
127 aris
="${aris} ari_${a} = \"${a}\";"
133 no-
*) w
=`echo x$w | sed -e 's/xno-//'`; val
=0 ;;
135 warnings
="${warnings} warning[ari_${w}] = $val;"
141 no-
*) e
=`echo x$e | sed -e 's/xno-//'`; val
=0 ;;
143 errors
="${errors} error[ari_${e}] = $val;"
146 if [ "$AWK" = "" ] ; then
152 # NOTE, for a per-file begin use "FNR == 1".
157 print_doc = '$print_doc'
158 print_idx = '$print_idx'
162 # Print the error message for BUG. Append SUPLEMENT if non-empty.
163 function print_bug(file,line,prefix,category,bug,doc,supplement, suffix,idx) {
170 suffix = " (" supplement ")"
174 # ari.*.bug: <FILE>:<LINE>: <CATEGORY>: <BUG>: <DOC>
175 print file ":" line ": " prefix category ": " idx doc suffix
176 if (srclines != "") {
177 print file ":" line ":" $0 >> srclines
181 function fix(bug,file,count) {
182 skip[bug, file] = count
183 skipped[bug, file] = 0
186 function fail(bug,supplement) {
187 if (doc[bug] == "") {
188 print_bug("", 0, "internal: ", "internal", "internal", "Missing doc for bug " bug)
191 if (category[bug] == "") {
192 print_bug("", 0, "internal: ", "internal", "internal", "Missing category for bug " bug)
199 # Trim the filename down to just DIRECTORY/FILE so that it can be
200 # robustly used by the FIX code.
202 if (FILENAME ~ /^\//) {
203 canonicalname = FILENAME
205 canonicalname = PWD "/" FILENAME
207 shortname = gensub (/^.*\/([^\\]*\/[^\\]*)$/, "\\1", 1, canonicalname)
209 skipped[bug, shortname]++
210 if (skip[bug, shortname] >= skipped[bug, shortname]) {
211 # print FILENAME, FNR, skip[bug, FILENAME], skipped[bug, FILENAME], bug
213 } else if (error[category[bug]]) {
214 # ari.*.bug: <FILE>:<LINE>: <CATEGORY>: <BUG>: <DOC>
215 print_bug(FILENAME, FNR, "", category[bug], bug, doc[bug], supplement)
216 } else if (warning[category[bug]]) {
217 # ari.*.bug: <FILE>:<LINE>: <CATEGORY>: <BUG>: <DOC>
218 print_bug(FILENAME, FNR, "warning: ", category[bug], bug, doc[bug], supplement)
224 if (match(FILENAME, "\\.[ly]$")) {
225 # FILENAME is a lex or yacc source
238 # Did we do only a partial skip?
239 for (bug_n_file in skip) {
240 split (bug_n_file, a, SUBSEP)
243 if (seen[file] && (skipped[bug_n_file] < skip[bug_n_file])) {
244 # ari.*.bug: <FILE>:<LINE>: <CATEGORY>: <BUG>: <DOC>
245 b = file " missing " bug
246 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])
252 # Skip OBSOLETE lines
253 /(^|[^_[:alnum:]])OBSOLETE([^_[:alnum:]]|$)/ { next; }
261 /\/\* ARI:[[:space:]]*(.*)[[:space:]]*\*\// {
262 ARI_OK = gensub(/^.*\/\* ARI:[[:space:]]*(.*[^[:space:]])[[:space:]]*\*\/.*$/, "\\1", 1, $0)
263 # print "ARI line found \"" $0 "\""
264 # print "ARI_OK \"" ARI_OK "\""
266 ! /\/\* ARI:[[:space:]]*(.*)[[:space:]]*\*\// {
271 # SNIP - Strip out comments - SNIP
276 comment_p && /\*\// { gsub (/^([^\*]|\*+[^\/\*])*\*+\//, " "); comment_p = 0; }
278 !comment_p { gsub (/\/\*([^\*]|\*+[^\/\*])*\*+\//, " "); }
279 !comment_p && /(^|[^"])\/\*/ { gsub (/\/\*.*$/, " "); comment_p = 1; }
282 BEGIN { doc["_ markup"] = "\
283 All messages should be marked up with _."
284 category["_ markup"] = ari_gettext
286 /^[^"]*[[:space:]](warning|error|error_no_arg|query|perror_with_name)[[:space:]]*\([^_\(a-z]/ {
292 BEGIN { doc["trailing new line"] = "\
293 A message should not have a trailing new line"
294 category["trailing new line"] = ari_gettext
296 /(^|[^_[:alnum:]])(warning|error)[[:space:]]*\(_\(".*\\n"\)[\),]/ {
297 fail("trailing new line")
300 # Include files for which GDB has a custom version.
302 BEGIN { doc["assert.h"] = "\
303 Do not include assert.h, instead include \"gdb_assert.h\"";
304 category["assert.h"] = ari_regression
305 fix("assert.h", "gdb/gdb_assert.h", 0) # it does not use it
307 /^#[[:space:]]*include[[:space:]]+.assert\.h./ {
311 BEGIN { doc["regex.h"] = "\
312 Do not include regex.h, instead include gdb_regex.h"
313 category["regex.h"] = ari_regression
314 fix("regex.h", "gdb/gdb_regex.h", 1)
316 /^#[[:space:]]*include[[:space:]]*.regex\.h./ {
320 BEGIN { doc["xregex.h"] = "\
321 Do not include xregex.h, instead include gdb_regex.h"
322 category["xregex.h"] = ari_regression
323 fix("xregex.h", "gdb/gdb_regex.h", 1)
325 /^#[[:space:]]*include[[:space:]]*.xregex\.h./ {
329 BEGIN { doc["gnu-regex.h"] = "\
330 Do not include gnu-regex.h, instead include gdb_regex.h"
331 category["gnu-regex.h"] = ari_regression
333 /^#[[:space:]]*include[[:space:]]*.gnu-regex\.h./ {
337 BEGIN { doc["wait.h"] = "\
338 Do not include wait.h or sys/wait.h, instead include gdb_wait.h"
339 fix("wait.h", "gdbsupport/gdb_wait.h", 2);
340 category["wait.h"] = ari_regression
342 /^#[[:space:]]*include[[:space:]]*.wait\.h./ \
343 || /^#[[:space:]]*include[[:space:]]*.sys\/wait\.h./ {
347 BEGIN { doc["vfork.h"] = "\
348 Do not include vfork.h, instead include gdb_vfork.h"
349 fix("vfork.h", "gdb/gdb_vfork.h", 1);
350 category["vfork.h"] = ari_regression
352 /^#[[:space:]]*include[[:space:]]*.vfork\.h./ {
356 BEGIN { doc["error not internal-warning"] = "\
357 Do not use error(\"internal-warning\"), instead use internal_warning"
358 category["error not internal-warning"] = ari_regression
360 /error.*\"[Ii]nternal.warning/ {
361 fail("error not internal-warning")
364 BEGIN { doc["%p"] = "\
365 Do not use printf(\"%p\"), instead use printf(\"%s\",paddr()) to dump a \
366 target address, or host_address_to_string() for a host address"
367 category["%p"] = ari_code
369 # Allow gdb %p extensions, but not other uses of %p.
370 /%p[^[\]sF]/ && !/%prec/ {
374 BEGIN { doc["%ll"] = "\
375 Do not use printf(\"%ll\"), instead use printf(\"%s\",phex()) to dump a \
376 `long long'\'' value"
377 category["%ll"] = ari_code
380 /%[0-9]*ll/ && !/scanf \(.*%[0-9]*ll/ {
385 # SNIP - Strip out strings - SNIP
387 # Test on top.c, scm-valprint.c, remote-rdi.c, ada-lang.c
392 # Strip escaped characters.
393 { gsub(/\\./, "."); }
394 # Strip quoted quotes.
395 { gsub(/'\''.'\''/, "'\''.'\''"); }
396 # End of multi-line string
398 if (trace_string) print "EOS:" FNR, $0;
399 gsub (/^[^\"]*\"/, "'\''");
402 # Middle of multi-line string, discard line.
404 if (trace_string) print "MOS:" FNR, $0;
407 # Strip complete strings from the middle of the line
408 !string_p && /\"[^\"]*\"/ {
409 if (trace_string) print "COS:" FNR, $0;
410 gsub (/\"[^\"]*\"/, "'\''");
412 # Start of multi-line string
413 BEGIN { doc["multi-line string"] = "\
414 Multi-line string must have the newline escaped"
415 category["multi-line string"] = ari_regression
418 if (trace_string) print "SOS:" FNR, $0;
420 fail("multi-line string")
422 gsub (/\"[^\"]*$/, "'\''");
430 # Accumulate continuation lines
434 !cont_p { full_line = ""; }
435 /[^\\]\\$/ { gsub (/\\$/, ""); full_line = full_line $0; cont_p = 1; next; }
436 cont_p { $0 = full_line $0; cont_p = 0; full_line = ""; }
439 BEGIN { doc["__FUNCTION__"] = "\
440 Do not use __FUNCTION__, C++11 does not support this macro"
441 category["__FUNCTION__"] = ari_regression
443 /(^|[^_[:alnum:]])__FUNCTION__([^_[:alnum:]]|$)/ {
447 BEGIN { doc["__CYGWIN32__"] = "\
448 Do not use __CYGWIN32__, instead use __CYGWIN__ or, better, an explicit \
450 category["__CYGWIN32__"] = ari_regression
452 /(^|[^_[:alnum:]])__CYGWIN32__([^_[:alnum:]]|$)/ {
456 BEGIN { doc["PTR"] = "\
457 Do not use PTR, C++11 implies `void *'\''"
458 category["PTR"] = ari_regression
459 #fix("PTR", "gdb/utils.c", 6)
461 /(^|[^_[:alnum:]])PTR([^_[:alnum:]]|$)/ {
465 BEGIN { doc["UCASE function"] = "\
466 Function name is uppercase."
467 category["UCASE function"] = ari_code
472 if (ARI_OK == "UCASE function") {
475 # Closing brace found?
476 else if (UCASE_full_line ~ \
477 /^[A-Z][[:alnum:]_]*[[:space:]]*\([^()]*\).*$/) {
478 if ((UCASE_full_line ~ \
479 /^[A-Z][[:alnum:]_]*[[:space:]]*\([^()]*\)[[:space:]]*$/) \
480 && ($0 ~ /^\{/) && (is_yacc_or_lex == 0)) {
484 $0 = UCASE_full_line;
485 fail("UCASE function")
492 UCASE_full_line = UCASE_full_line $0;
495 /^[A-Z][[:alnum:]_]*[[:space:]]*\([^()]*(|\))[[:space:]]*$/ {
497 if (ARI_OK == "UCASE function") {
505 BEGIN { doc["editCase function"] = "\
506 Function name starts lower case but has uppercased letters."
507 category["editCase function"] = ari_code
508 possible_editCase = 0
509 editCase_full_line = ""
511 (possible_editCase) {
512 if (ARI_OK == "editCase function") {
513 possible_editCase = 0
515 # Closing brace found?
516 else if (editCase_full_line ~ \
517 /^[a-z][a-z0-9_]*[A-Z][a-z0-9A-Z_]*[[:space:]]*\([^()]*\).*$/) {
518 if ((editCase_full_line ~ \
519 /^[a-z][a-z0-9_]*[A-Z][a-z0-9A-Z_]*[[:space:]]*\([^()]*\)[[:space:]]*$/) \
520 && ($0 ~ /^\{/) && (is_yacc_or_lex == 0)) {
524 $0 = editCase_full_line;
525 fail("editCase function")
529 possible_editCase = 0
530 editCase_full_line = ""
532 editCase_full_line = editCase_full_line $0;
535 /^[a-z][a-z0-9_]*[A-Z][a-z0-9A-Z_]*[[:space:]]*\([^()]*(|\))[[:space:]]*$/ {
536 possible_editCase = 1
537 if (ARI_OK == "editCase function") {
538 possible_editCase = 0
541 editCase_full_line = $0
544 # Only function implementation should be on first column
545 BEGIN { doc["function call in first column"] = "\
546 Function name in first column should be restricted to function implementation"
547 category["function call in first column"] = ari_code
549 /^[a-z][a-z0-9_]*[[:space:]]*\((|[^*][^()]*)\)[[:space:]]*[^ \t]+/ {
550 fail("function call in first column")
554 BEGIN { doc["hash"] = "\
555 Do not use ` #...'\'', instead use `#...'\''(some compilers only correctly \
556 parse a C preprocessor directive when `#'\'' is the first character on \
558 category["hash"] = ari_regression
564 BEGIN { doc["OP eol"] = "\
565 Do not use &&, or || at the end of a line"
566 category["OP eol"] = ari_code
568 # * operator needs a special treatment as it can be a
569 # valid end of line for a pointer type definition
570 # Only catch case where an assignment or an opening brace is present
571 /(\|\||\&\&|==|!=|[[:space:]][+\-\/])[[:space:]]*$/ \
572 || /(\(|=)[[:space:]].*[[:space:]]\*[[:space:]]*$/ {
576 BEGIN { doc["strerror"] = "\
577 Do not use strerror(), instead use safe_strerror()"
578 category["strerror"] = ari_regression
579 fix("strerror", "gdb/gdb_string.h", 1)
580 fix("strerror", "gdb/gdbsupport/mingw-strerror.c", 1)
581 fix("strerror", "gdb/gdbsupport/posix-strerror.c", 1)
583 /(^|[^_[:alnum:]])strerror[[:space:]]*\(/ {
587 BEGIN { doc["long long"] = "\
588 Do not use `long long'\'', instead use LONGEST"
589 category["long long"] = ari_code
590 # defs.h needs two such patterns for LONGEST and ULONGEST definitions
591 fix("long long", "gdb/defs.h", 2)
593 /(^|[^_[:alnum:]])long[[:space:]]+long([^_[:alnum:]]|$)/ {
597 BEGIN { doc["ATTR_FORMAT"] = "\
598 Do not use ATTR_FORMAT, use ATTRIBUTE_PRINTF instead"
599 category["ATTR_FORMAT"] = ari_regression
601 /(^|[^_[:alnum:]])ATTR_FORMAT([^_[:alnum:]]|$)/ {
605 BEGIN { doc["ATTR_NORETURN"] = "\
606 Do not use ATTR_NORETURN, use ATTRIBUTE_NORETURN instead"
607 category["ATTR_NORETURN"] = ari_regression
609 /(^|[^_[:alnum:]])ATTR_NORETURN([^_[:alnum:]]|$)/ {
610 fail("ATTR_NORETURN")
613 BEGIN { doc["NORETURN"] = "\
614 Do not use NORETURN, use ATTRIBUTE_NORETURN instead"
615 category["NORETURN"] = ari_regression
617 /(^|[^_[:alnum:]])NORETURN([^_[:alnum:]]|$)/ {
624 BEGIN { doc["multiple messages"] = "\
625 Do not use multiple calls to warning or error, instead use a single call"
626 category["multiple messages"] = ari_gettext
631 /(^|[^_[:alnum:]])(warning|error)[[:space:]]*\(/ {
632 if (FNR == warning_fnr + 1) {
633 fail("multiple messages")
639 # Commented out, but left inside sources, just in case.
640 # BEGIN { doc["inline"] = "\
641 # Do not use the inline attribute; \
642 # since the compiler generally ignores this, better algorithm selection \
643 # is needed to improved performance"
644 # category["inline"] = ari_code
646 # /(^|[^_[:alnum:]])inline([^_[:alnum:]]|$)/ {
650 # This test is obsolete as this type
651 # has been deprecated and finally suppressed from GDB sources
652 #BEGIN { doc["obj_private"] = "\
653 #Replace obj_private with objfile_data"
654 # category["obj_private"] = ari_obsolete
656 #/(^|[^_[:alnum:]])obj_private([^_[:alnum:]]|$)/ {
657 # fail("obj_private")
660 BEGIN { doc["abort"] = "\
661 Do not use abort, instead use internal_error; GDB should never abort"
662 category["abort"] = ari_regression
664 /(^|[^_[:alnum:]])abort[[:space:]]*\(/ {
668 BEGIN { doc["basename"] = "\
669 Do not use basename, instead use lbasename"
670 category["basename"] = ari_regression
672 /(^|[^_[:alnum:]])basename[[:space:]]*\(/ {
676 BEGIN { doc["assert"] = "\
677 Do not use assert, instead use gdb_assert or internal_error; assert \
678 calls abort and GDB should never call abort"
679 category["assert"] = ari_regression
681 /(^|[^_[:alnum:]])assert[[:space:]]*\(/ {
685 BEGIN { doc["TARGET_HAS_HARDWARE_WATCHPOINTS"] = "\
686 Replace TARGET_HAS_HARDWARE_WATCHPOINTS with nothing, not needed"
687 category["TARGET_HAS_HARDWARE_WATCHPOINTS"] = ari_regression
689 /(^|[^_[:alnum:]])TARGET_HAS_HARDWARE_WATCHPOINTS([^_[:alnum:]]|$)/ {
690 fail("TARGET_HAS_HARDWARE_WATCHPOINTS")
693 BEGIN { doc["ADD_SHARED_SYMBOL_FILES"] = "\
694 Replace ADD_SHARED_SYMBOL_FILES with nothing, not needed?"
695 category["ADD_SHARED_SYMBOL_FILES"] = ari_regression
697 /(^|[^_[:alnum:]])ADD_SHARED_SYMBOL_FILES([^_[:alnum:]]|$)/ {
698 fail("ADD_SHARED_SYMBOL_FILES")
701 BEGIN { doc["SOLIB_ADD"] = "\
702 Replace SOLIB_ADD with nothing, not needed?"
703 category["SOLIB_ADD"] = ari_regression
705 /(^|[^_[:alnum:]])SOLIB_ADD([^_[:alnum:]]|$)/ {
709 BEGIN { doc["SOLIB_CREATE_INFERIOR_HOOK"] = "\
710 Replace SOLIB_CREATE_INFERIOR_HOOK with nothing, not needed?"
711 category["SOLIB_CREATE_INFERIOR_HOOK"] = ari_regression
713 /(^|[^_[:alnum:]])SOLIB_CREATE_INFERIOR_HOOK([^_[:alnum:]]|$)/ {
714 fail("SOLIB_CREATE_INFERIOR_HOOK")
717 BEGIN { doc["SOLIB_LOADED_LIBRARY_PATHNAME"] = "\
718 Replace SOLIB_LOADED_LIBRARY_PATHNAME with nothing, not needed?"
719 category["SOLIB_LOADED_LIBRARY_PATHNAME"] = ari_regression
721 /(^|[^_[:alnum:]])SOLIB_LOADED_LIBRARY_PATHNAME([^_[:alnum:]]|$)/ {
722 fail("SOLIB_LOADED_LIBRARY_PATHNAME")
725 BEGIN { doc["REGISTER_U_ADDR"] = "\
726 Replace REGISTER_U_ADDR with nothing, not needed?"
727 category["REGISTER_U_ADDR"] = ari_regression
729 /(^|[^_[:alnum:]])REGISTER_U_ADDR([^_[:alnum:]]|$)/ {
730 fail("REGISTER_U_ADDR")
733 BEGIN { doc["PROCESS_LINENUMBER_HOOK"] = "\
734 Replace PROCESS_LINENUMBER_HOOK with nothing, not needed?"
735 category["PROCESS_LINENUMBER_HOOK"] = ari_regression
737 /(^|[^_[:alnum:]])PROCESS_LINENUMBER_HOOK([^_[:alnum:]]|$)/ {
738 fail("PROCESS_LINENUMBER_HOOK")
741 BEGIN { doc["PC_SOLIB"] = "\
742 Replace PC_SOLIB with nothing, not needed?"
743 category["PC_SOLIB"] = ari_regression
745 /(^|[^_[:alnum:]])PC_SOLIB([^_[:alnum:]]|$)/ {
749 BEGIN { doc["IN_SOLIB_DYNSYM_RESOLVE_CODE"] = "\
750 Replace IN_SOLIB_DYNSYM_RESOLVE_CODE with nothing, not needed?"
751 category["IN_SOLIB_DYNSYM_RESOLVE_CODE"] = ari_regression
753 /(^|[^_[:alnum:]])IN_SOLIB_DYNSYM_RESOLVE_CODE([^_[:alnum:]]|$)/ {
754 fail("IN_SOLIB_DYNSYM_RESOLVE_CODE")
757 BEGIN { doc["GCC_COMPILED_FLAG_SYMBOL"] = "\
758 Replace GCC_COMPILED_FLAG_SYMBOL with nothing, not needed?"
759 category["GCC_COMPILED_FLAG_SYMBOL"] = ari_deprecate
761 /(^|[^_[:alnum:]])GCC_COMPILED_FLAG_SYMBOL([^_[:alnum:]]|$)/ {
762 fail("GCC_COMPILED_FLAG_SYMBOL")
765 BEGIN { doc["GCC2_COMPILED_FLAG_SYMBOL"] = "\
766 Replace GCC2_COMPILED_FLAG_SYMBOL with nothing, not needed?"
767 category["GCC2_COMPILED_FLAG_SYMBOL"] = ari_deprecate
769 /(^|[^_[:alnum:]])GCC2_COMPILED_FLAG_SYMBOL([^_[:alnum:]]|$)/ {
770 fail("GCC2_COMPILED_FLAG_SYMBOL")
773 BEGIN { doc["FUNCTION_EPILOGUE_SIZE"] = "\
774 Replace FUNCTION_EPILOGUE_SIZE with nothing, not needed?"
775 category["FUNCTION_EPILOGUE_SIZE"] = ari_regression
777 /(^|[^_[:alnum:]])FUNCTION_EPILOGUE_SIZE([^_[:alnum:]]|$)/ {
778 fail("FUNCTION_EPILOGUE_SIZE")
781 BEGIN { doc["HAVE_VFORK"] = "\
782 Do not use HAVE_VFORK, instead include \"gdb_vfork.h\" and call vfork() \
784 category["HAVE_VFORK"] = ari_regression
786 /(^|[^_[:alnum:]])HAVE_VFORK([^_[:alnum:]]|$)/ {
790 BEGIN { doc["bcmp"] = "\
791 Do not use bcmp(), C++11 implies memcmp()"
792 category["bcmp"] = ari_regression
794 /(^|[^_[:alnum:]])bcmp[[:space:]]*\(/ {
798 BEGIN { doc["setlinebuf"] = "\
799 Do not use setlinebuf(), C++11 implies setvbuf()"
800 category["setlinebuf"] = ari_regression
802 /(^|[^_[:alnum:]])setlinebuf[[:space:]]*\(/ {
806 BEGIN { doc["bcopy"] = "\
807 Do not use bcopy(), C++11 implies memcpy() and memmove()"
808 category["bcopy"] = ari_regression
810 /(^|[^_[:alnum:]])bcopy[[:space:]]*\(/ {
814 BEGIN { doc["get_frame_base"] = "\
815 Replace get_frame_base with get_frame_id, get_frame_base_address, \
816 get_frame_locals_address, or get_frame_args_address."
817 category["get_frame_base"] = ari_obsolete
819 /(^|[^_[:alnum:]])get_frame_base([^_[:alnum:]]|$)/ {
820 fail("get_frame_base")
823 BEGIN { doc["floatformat_to_double"] = "\
824 Do not use floatformat_to_double() from libierty, \
825 instead use floatformat_to_doublest()"
826 category["floatformat_to_double"] = ari_regression
828 /(^|[^_[:alnum:]])floatformat_to_double[[:space:]]*\(/ {
829 fail("floatformat_to_double")
832 BEGIN { doc["floatformat_from_double"] = "\
833 Do not use floatformat_from_double() from libierty, \
834 instead use host_float_ops<T>::from_target()"
835 category["floatformat_from_double"] = ari_regression
837 /(^|[^_[:alnum:]])floatformat_from_double[[:space:]]*\(/ {
838 fail("floatformat_from_double")
841 BEGIN { doc["BIG_ENDIAN"] = "\
842 Do not use BIG_ENDIAN, instead use BFD_ENDIAN_BIG"
843 category["BIG_ENDIAN"] = ari_regression
845 /(^|[^_[:alnum:]])BIG_ENDIAN([^_[:alnum:]]|$)/ {
849 BEGIN { doc["LITTLE_ENDIAN"] = "\
850 Do not use LITTLE_ENDIAN, instead use BFD_ENDIAN_LITTLE";
851 category["LITTLE_ENDIAN"] = ari_regression
853 /(^|[^_[:alnum:]])LITTLE_ENDIAN([^_[:alnum:]]|$)/ {
854 fail("LITTLE_ENDIAN")
857 BEGIN { doc["BIG_ENDIAN"] = "\
858 Do not use BIG_ENDIAN, instead use BFD_ENDIAN_BIG"
859 category["BIG_ENDIAN"] = ari_regression
861 /(^|[^_[:alnum:]])BIG_ENDIAN([^_[:alnum:]]|$)/ {
865 BEGIN { doc["sec_ptr"] = "\
866 Instead of sec_ptr, use struct bfd_section";
867 category["sec_ptr"] = ari_regression
869 /(^|[^_[:alnum:]])sec_ptr([^_[:alnum:]]|$)/ {
873 BEGIN { doc["frame_unwind_unsigned_register"] = "\
874 Replace frame_unwind_unsigned_register with frame_unwind_register_unsigned"
875 category["frame_unwind_unsigned_register"] = ari_regression
877 /(^|[^_[:alnum:]])frame_unwind_unsigned_register([^_[:alnum:]]|$)/ {
878 fail("frame_unwind_unsigned_register")
881 BEGIN { doc["frame_register_read"] = "\
882 Replace frame_register_read() with get_frame_register(), or \
883 possibly introduce a new method safe_get_frame_register()"
884 category["frame_register_read"] = ari_obsolete
886 /(^|[^_[:alnum:]])frame_register_read([^_[:alnum:]]|$)/ {
887 fail("frame_register_read")
890 BEGIN { doc["read_register"] = "\
891 Replace read_register() with regcache_read() et.al."
892 category["read_register"] = ari_regression
894 /(^|[^_[:alnum:]])read_register([^_[:alnum:]]|$)/ {
895 fail("read_register")
898 BEGIN { doc["write_register"] = "\
899 Replace write_register() with regcache_read() et.al."
900 category["write_register"] = ari_regression
902 /(^|[^_[:alnum:]])write_register([^_[:alnum:]]|$)/ {
903 fail("write_register")
906 function report(name) {
907 # Drop any trailing _P.
908 name = gensub(/(_P|_p)$/, "", 1, name)
909 # Convert to lower case
911 # Split into category and bug
912 cat = gensub(/^([[:alpha:]]+)_([_[:alnum:]]*)$/, "\\1", 1, name)
913 bug = gensub(/^([[:alpha:]]+)_([_[:alnum:]]*)$/, "\\2", 1, name)
916 doc[name] = "Do not use " cat " " bug ", see declaration for details"
921 /(^|[^_[:alnum:]])(DEPRECATED|deprecated|set_gdbarch_deprecated|LEGACY|legacy|set_gdbarch_legacy)_/ {
925 name = gensub(/^(|.*[^_[:alnum:]])((DEPRECATED|deprecated|LEGACY|legacy)_[_[:alnum:]]*)(.*)$/, "\\2", 1, line)
926 line = gensub(/^(|.*[^_[:alnum:]])((DEPRECATED|deprecated|LEGACY|legacy)_[_[:alnum:]]*)(.*)$/, "\\1 \\4", 1, line)
927 # print "name =", name, "line =", line
928 if (name == line) break;
933 # Count the number of times each architecture method is set
934 /(^|[^_[:alnum:]])set_gdbarch_[_[:alnum:]]*([^_[:alnum:]]|$)/ {
935 name = gensub(/^.*set_gdbarch_([_[:alnum:]]*).*$/, "\\1", 1, $0)
936 doc["set " name] = "\
937 Call to set_gdbarch_" name
938 category["set " name] = ari_gdbarch
942 # Count the number of times each tm/xm/nm macro is defined or undefined
943 /^#[[:space:]]*(undef|define)[[:space:]]+[[:alnum:]_]+.*$/ \
944 && !/^#[[:space:]]*(undef|define)[[:space:]]+[[:alnum:]_]+_H($|[[:space:]])/ \
945 && FILENAME ~ /(^|\/)config\/(|[^\/]*\/)(tm-|xm-|nm-).*\.h$/ {
946 basename = gensub(/(^|.*\/)([^\/]*)$/, "\\2", 1, FILENAME)
947 type = gensub(/^(tm|xm|nm)-.*\.h$/, "\\1", 1, basename)
948 name = gensub(/^#[[:space:]]*(undef|define)[[:space:]]+([[:alnum:]_]+).*$/, "\\2", 1, $0)
949 if (type == basename) {
952 doc[type " " name] = "\
953 Do not define macros such as " name " in a tm, nm or xm file, \
954 in fact do not provide a tm, nm or xm file"
955 category[type " " name] = ari_macro
959 BEGIN { doc["deprecated_registers"] = "\
960 Replace deprecated_registers with nothing, they have reached \
962 category["deprecated_registers"] = ari_eol
964 /(^|[^_[:alnum:]])deprecated_registers([^_[:alnum:]]|$)/ {
965 fail("deprecated_registers")
968 BEGIN { doc["read_pc"] = "\
969 Replace READ_PC() with frame_pc_unwind; \
970 at present the inferior function call code still uses this"
971 category["read_pc"] = ari_deprecate
973 /(^|[^_[:alnum:]])read_pc[[:space:]]*\(/ || \
974 /(^|[^_[:alnum:]])set_gdbarch_read_pc[[:space:]]*\(/ || \
975 /(^|[^_[:alnum:]])TARGET_READ_PC[[:space:]]*\(/ {
979 BEGIN { doc["write_pc"] = "\
980 Replace write_pc() with get_frame_base_address or get_frame_id; \
981 at present the inferior function call code still uses this when doing \
982 a DECR_PC_AFTER_BREAK"
983 category["write_pc"] = ari_deprecate
985 /(^|[^_[:alnum:]])write_pc[[:space:]]*\(/ || \
986 /(^|[^_[:alnum:]])TARGET_WRITE_PC[[:space:]]*\(/ {
990 BEGIN { doc["generic_target_write_pc"] = "\
991 Replace generic_target_write_pc with a per-architecture implementation, \
992 this relies on PC_REGNUM which is being eliminated"
993 category["generic_target_write_pc"] = ari_regression
995 /(^|[^_[:alnum:]])generic_target_write_pc([^_[:alnum:]]|$)/ {
996 fail("generic_target_write_pc")
999 BEGIN { doc["read_sp"] = "\
1000 Replace read_sp() with frame_sp_unwind"
1001 category["read_sp"] = ari_regression
1003 /(^|[^_[:alnum:]])read_sp[[:space:]]*\(/ || \
1004 /(^|[^_[:alnum:]])set_gdbarch_read_sp[[:space:]]*\(/ || \
1005 /(^|[^_[:alnum:]])TARGET_READ_SP[[:space:]]*\(/ {
1009 BEGIN { doc["register_cached"] = "\
1010 Replace register_cached() with nothing, does not have a regcache parameter"
1011 category["register_cached"] = ari_regression
1013 /(^|[^_[:alnum:]])register_cached[[:space:]]*\(/ {
1014 fail("register_cached")
1017 BEGIN { doc["set_register_cached"] = "\
1018 Replace set_register_cached() with nothing, does not have a regcache parameter"
1019 category["set_register_cached"] = ari_regression
1021 /(^|[^_[:alnum:]])set_register_cached[[:space:]]*\(/ {
1022 fail("set_register_cached")
1025 # Print functions: Use versions that either check for buffer overflow
1026 # or safely allocate a fresh buffer.
1028 BEGIN { doc["sprintf"] = "\
1029 Do not use sprintf, instead use xsnprintf or xstrprintf"
1030 category["sprintf"] = ari_code
1032 /(^|[^_[:alnum:]])sprintf[[:space:]]*\(/ {
1036 BEGIN { doc["vsprintf"] = "\
1037 Do not use vsprintf(), instead use xstrvprintf"
1038 category["vsprintf"] = ari_regression
1040 /(^|[^_[:alnum:]])vsprintf[[:space:]]*\(/ {
1044 BEGIN { doc["asprintf"] = "\
1045 Do not use asprintf(), instead use xstrprintf()"
1046 category["asprintf"] = ari_regression
1048 /(^|[^_[:alnum:]])asprintf[[:space:]]*\(/ {
1052 BEGIN { doc["vasprintf"] = "\
1053 Do not use vasprintf(), instead use xstrvprintf"
1054 fix("vasprintf", "gdbsupport/common-utils.c", 1)
1055 category["vasprintf"] = ari_regression
1057 /(^|[^_[:alnum:]])vasprintf[[:space:]]*\(/ {
1061 BEGIN { doc["printf_vma"] = "\
1062 Do not use printf_vma, instead use paddress or phex_nz"
1063 category["printf_vma"] = ari_code
1065 /(^|[^_[:alnum:]])printf_vma[[:space:]]*\(/ {
1069 BEGIN { doc["sprintf_vma"] = "\
1070 Do not use sprintf_vma, instead use paddress or phex_nz"
1071 category["sprintf_vma"] = ari_code
1073 /(^|[^_[:alnum:]])sprintf_vma[[:space:]]*\(/ {
1077 # More generic memory operations
1079 BEGIN { doc["bzero"] = "\
1080 Do not use bzero(), instead use memset()"
1081 category["bzero"] = ari_regression
1083 /(^|[^_[:alnum:]])bzero[[:space:]]*\(/ {
1087 BEGIN { doc["strdup"] = "\
1088 Do not use strdup(), instead use xstrdup()";
1089 category["strdup"] = ari_regression
1091 /(^|[^_[:alnum:]])strdup[[:space:]]*\(/ {
1095 BEGIN { doc["strsave"] = "\
1096 Do not use strsave(), instead use xstrdup() et.al."
1097 category["strsave"] = ari_regression
1099 /(^|[^_[:alnum:]])strsave[[:space:]]*\(/ {
1103 # String compare functions
1105 BEGIN { doc["strnicmp"] = "\
1106 Do not use strnicmp(), instead use strncasecmp()"
1107 category["strnicmp"] = ari_regression
1109 /(^|[^_[:alnum:]])strnicmp[[:space:]]*\(/ {
1113 # Typedefs that are either redundant or can be reduced to `struct
1115 # Must be placed before if assignment otherwise ARI exceptions
1116 # are not handled correctly.
1118 BEGIN { doc["d_namelen"] = "\
1119 Do not use dirent.d_namelen, instead use NAMELEN"
1120 category["d_namelen"] = ari_regression
1122 /(^|[^_[:alnum:]])d_namelen([^_[:alnum:]]|$)/ {
1126 BEGIN { doc["strlen d_name"] = "\
1127 Do not use strlen dirent.d_name, instead use NAMELEN"
1128 category["strlen d_name"] = ari_regression
1130 /(^|[^_[:alnum:]])strlen[[:space:]]*\(.*[^_[:alnum:]]d_name([^_[:alnum:]]|$)/ {
1131 fail("strlen d_name")
1134 BEGIN { doc["generic_use_struct_convention"] = "\
1135 Replace generic_use_struct_convention with nothing, \
1136 EXTRACT_STRUCT_VALUE_ADDRESS is a predicate"
1137 category["generic_use_struct_convention"] = ari_regression
1139 /(^|[^_[:alnum:]])generic_use_struct_convention([^_[:alnum:]]|$)/ {
1140 fail("generic_use_struct_convention")
1143 BEGIN { doc["if assignment"] = "\
1144 An IF statement'\''s expression contains an assignment (the GNU coding \
1145 standard discourages this)"
1146 category["if assignment"] = ari_code
1148 BEGIN { doc["if clause more than 50 lines"] = "\
1149 An IF statement'\''s expression expands over 50 lines"
1150 category["if clause more than 50 lines"] = ari_code
1153 # Accumulate continuation lines
1158 /(^|[^_[:alnum:]])if / {
1163 if_brace_end_pos = 0;
1167 # We want everything up to closing brace of same level
1169 if (if_count > 50) {
1170 print "multiline if: " if_full_line $0
1171 fail("if clause more than 50 lines")
1175 if (if_count == 1) {
1176 i = index($0,"if ");
1180 for (i=i; i <= length($0); i++) {
1181 char = substr($0,i,1);
1182 if (char == "(") { if_brace_level++; }
1185 if (!if_brace_level) {
1186 if_brace_end_pos = i;
1187 after_if = substr($0,i+1,length($0));
1188 # Do not parse what is following
1193 if (if_brace_level == 0) {
1194 $0 = substr($0,1,i);
1197 if_full_line = if_full_line $0;
1203 # if we arrive here, we need to concatenate, but we are at brace level 0
1205 (if_brace_end_pos) {
1206 $0 = if_full_line substr($0,1,if_brace_end_pos);
1208 # print "IF: multi line " if_count " found at " FILENAME ":" FNR " \"" $0 "\""
1213 /(^|[^_[:alnum:]])if .* = / {
1214 # print "fail in if " $0
1215 fail("if assignment")
1217 (if_brace_end_pos) {
1219 if_brace_end_pos = 0;
1223 # Printout of all found bug
This page took 0.054754 seconds and 3 git commands to generate.