# GDB script to list of problems using awk.
#
-# Copyright (C) 2002-2012 Free Software Foundation, Inc.
+# Copyright (C) 2002-2019 Free Software Foundation, Inc.
#
# This file is part of GDB.
#
# Permanent checks take the form:
-# Do not use XXXX, ISO C 90 implies YYYY
+# Do not use XXXX, C++11 implies YYYY
# Do not use XXXX, instead use YYYY''.
# and should never be removed.
Error: $1
Usage:
- $0 --print-doc --print-idx -Wall -Werror -W<category> <file> ...
+ $0 --print-doc --print-idx -Wall -Werror -WCATEGORY FILE ...
Options:
--print-doc Print a list of all potential problems, then exit.
--print-idx Include the problems IDX (index or key) in every message.
-Werror Treat all problems as errors.
-Wall Report all problems.
-Wari Report problems that should be fixed in new code.
- -W<category> Report problems in the specifed category. Vaid categories
+ -WCATEGORY Report problems in the specifed category. The category
+ can be prefixed with "no-". Valid categories
are: ${all}
EOF
exit 1
# Validate all errors and warnings.
for w in ${warning} ${error}
do
+ case "$w" in
+ no-*) w=`echo x$w | sed -e 's/xno-//'`;;
+ esac
+
case " ${all} " in
*" ${w} "* ) ;;
* ) usage "Unknown option -W${w}" ;;
done
for w in ${warning}
do
- warnings="${warnings} warning[ari_${w}] = 1;"
+ val=1
+ case "$w" in
+ no-*) w=`echo x$w | sed -e 's/xno-//'`; val=0 ;;
+ esac
+ warnings="${warnings} warning[ari_${w}] = $val;"
done
for e in ${error}
do
- errors="${errors} error[ari_${e}] = 1;"
+ val=1
+ case "$e" in
+ no-*) e=`echo x$e | sed -e 's/xno-//'`; val=0 ;;
+ esac
+ errors="${errors} error[ari_${e}] = $val;"
done
if [ "$AWK" = "" ] ; then
}
-# Things in comments
-
-BEGIN { doc["GNU/Linux"] = "\
-Do not use `Linux'\'', instead use `Linux kernel'\'' or `GNU/Linux system'\'';\
- comments should clearly differentiate between the two (this test assumes that\
- word `Linux'\'' appears on the same line as the word `GNU'\'' or `kernel'\''\
- or a kernel version"
- category["GNU/Linux"] = ari_comment
-}
-/(^|[^_[:alnum:]])Linux([^_[:alnum:]]|$)/ \
-&& !/(^|[^_[:alnum:]])Linux\[sic\]([^_[:alnum:]]|$)/ \
-&& !/(^|[^_[:alnum:]])GNU\/Linux([^_[:alnum:]]|$)/ \
-&& !/(^|[^_[:alnum:]])Linux kernel([^_[:alnum:]]|$)/ \
-&& !/(^|[^_[:alnum:]])Linux [[:digit:]]\.[[:digit:]]+)/ {
- fail("GNU/Linux")
-}
-
-BEGIN { doc["ARGSUSED"] = "\
-Do not use ARGSUSED, unnecessary"
- category["ARGSUSED"] = ari_regression
-}
-/(^|[^_[:alnum:]])ARGSUSED([^_[:alnum:]]|$)/ {
- fail("ARGSUSED")
-}
-
-
# SNIP - Strip out comments - SNIP
FNR == 1 {
fail("assert.h")
}
-BEGIN { doc["dirent.h"] = "\
-Do not include dirent.h, instead include gdb_dirent.h"
- category["dirent.h"] = ari_regression
-}
-/^#[[:space:]]*include[[:space:]]*.dirent\.h./ {
- fail("dirent.h")
-}
-
BEGIN { doc["regex.h"] = "\
Do not include regex.h, instead include gdb_regex.h"
category["regex.h"] = ari_regression
fail("gnu regex.h")
}
-BEGIN { doc["stat.h"] = "\
-Do not include stat.h or sys/stat.h, instead include gdb_stat.h"
- category["stat.h"] = ari_regression
- fix("stat.h", "gdb/gdb_stat.h", 1)
-}
-/^#[[:space:]]*include[[:space:]]*.stat\.h./ \
-|| /^#[[:space:]]*include[[:space:]]*.sys\/stat\.h./ {
- fail("stat.h")
-}
-
BEGIN { doc["wait.h"] = "\
Do not include wait.h or sys/wait.h, instead include gdb_wait.h"
- fix("wait.h", "gdb/gdb_wait.h", 2);
+ fix("wait.h", "gdbsupport/gdb_wait.h", 2);
category["wait.h"] = ari_regression
}
/^#[[:space:]]*include[[:space:]]*.wait\.h./ \
target address, or host_address_to_string() for a host address"
category["%p"] = ari_code
}
-/%p/ && !/%prec/ {
+# Allow gdb %p extensions, but not other uses of %p.
+/%p[^[\]sF]/ && !/%prec/ {
fail("%p")
}
cont_p { $0 = full_line $0; cont_p = 0; full_line = ""; }
-# GDB uses ISO C 90. Check for any non pure ISO C 90 code
-
-BEGIN { doc["PARAMS"] = "\
-Do not use PARAMS(), ISO C 90 implies prototypes"
- category["PARAMS"] = ari_regression
-}
-/(^|[^_[:alnum:]])PARAMS([^_[:alnum:]]|$)/ {
- fail("PARAMS")
-}
-
-BEGIN { doc["__func__"] = "\
-Do not use __func__, ISO C 90 does not support this macro"
- category["__func__"] = ari_regression
- fix("__func__", "common/gdb_assert.h", 1)
-}
-/(^|[^_[:alnum:]])__func__([^_[:alnum:]]|$)/ {
- fail("__func__")
-}
-
BEGIN { doc["__FUNCTION__"] = "\
-Do not use __FUNCTION__, ISO C 90 does not support this macro"
+Do not use __FUNCTION__, C++11 does not support this macro"
category["__FUNCTION__"] = ari_regression
}
/(^|[^_[:alnum:]])__FUNCTION__([^_[:alnum:]]|$)/ {
}
BEGIN { doc["PTR"] = "\
-Do not use PTR, ISO C 90 implies `void *'\''"
+Do not use PTR, C++11 implies `void *'\''"
category["PTR"] = ari_regression
#fix("PTR", "gdb/utils.c", 6)
}
editCase_full_line = ""
}
(possible_editCase) {
- if (ARI_OK == "ediCase function") {
+ if (ARI_OK == "editCase function") {
possible_editCase = 0
}
# Closing brace found?
}
-# Functions without any parameter should have (void)
-# after their name not simply ().
-BEGIN { doc["no parameter function"] = "\
-Function having no parameter should be declared with funcname (void)."
- category["no parameter function"] = ari_code
-}
-/^[a-zA-Z][a-z0-9A-Z_]*[[:space:]]*\(\)/ {
- fail("no parameter function")
-}
-
BEGIN { doc["hash"] = "\
Do not use ` #...'\'', instead use `#...'\''(some compilers only correctly \
parse a C preprocessor directive when `#'\'' is the first character on \
Do not use &&, or || at the end of a line"
category["OP eol"] = ari_code
}
-/(\|\||\&\&|==|!=)[[:space:]]*$/ {
+# * operator needs a special treatment as it can be a
+# valid end of line for a pointer type definition
+# Only catch case where an assignment or an opening brace is present
+/(\|\||\&\&|==|!=|[[:space:]][+\-\/])[[:space:]]*$/ \
+|| /(\(|=)[[:space:]].*[[:space:]]\*[[:space:]]*$/ {
fail("OP eol")
}
Do not use strerror(), instead use safe_strerror()"
category["strerror"] = ari_regression
fix("strerror", "gdb/gdb_string.h", 1)
- fix("strerror", "gdb/mingw-hdep.c", 1)
- fix("strerror", "gdb/posix-hdep.c", 1)
+ fix("strerror", "gdb/gdbsupport/mingw-strerror.c", 1)
+ fix("strerror", "gdb/gdbsupport/posix-strerror.c", 1)
}
/(^|[^_[:alnum:]])strerror[[:space:]]*\(/ {
fail("strerror")
BEGIN { doc["long long"] = "\
Do not use `long long'\'', instead use LONGEST"
category["long long"] = ari_code
- # defs.h needs two such patterns for LONGEST and ULONGEST definitions
- fix("long long", "gdb/defs.h", 2)
}
/(^|[^_[:alnum:]])long[[:space:]]+long([^_[:alnum:]]|$)/ {
fail("long long")
}
-BEGIN { doc["ATTRIBUTE_UNUSED"] = "\
-Do not use ATTRIBUTE_UNUSED, do not bother (GDB is compiled with -Werror and, \
-consequently, is not able to tolerate false warnings. Since -Wunused-param \
-produces such warnings, neither that warning flag nor ATTRIBUTE_UNUSED \
-are used by GDB"
- category["ATTRIBUTE_UNUSED"] = ari_regression
-}
-/(^|[^_[:alnum:]])ATTRIBUTE_UNUSED([^_[:alnum:]]|$)/ {
- fail("ATTRIBUTE_UNUSED")
-}
-
BEGIN { doc["ATTR_FORMAT"] = "\
Do not use ATTR_FORMAT, use ATTRIBUTE_PRINTF instead"
category["ATTR_FORMAT"] = ari_regression
BEGIN { doc["abort"] = "\
Do not use abort, instead use internal_error; GDB should never abort"
category["abort"] = ari_regression
- fix("abort", "gdb/utils.c", 3)
}
/(^|[^_[:alnum:]])abort[[:space:]]*\(/ {
fail("abort")
BEGIN { doc["SOLIB_ADD"] = "\
Replace SOLIB_ADD with nothing, not needed?"
- category["SOLIB_ADD"] = ari_deprecate
+ category["SOLIB_ADD"] = ari_regression
}
/(^|[^_[:alnum:]])SOLIB_ADD([^_[:alnum:]]|$)/ {
fail("SOLIB_ADD")
BEGIN { doc["SOLIB_CREATE_INFERIOR_HOOK"] = "\
Replace SOLIB_CREATE_INFERIOR_HOOK with nothing, not needed?"
- category["SOLIB_CREATE_INFERIOR_HOOK"] = ari_deprecate
+ category["SOLIB_CREATE_INFERIOR_HOOK"] = ari_regression
}
/(^|[^_[:alnum:]])SOLIB_CREATE_INFERIOR_HOOK([^_[:alnum:]]|$)/ {
fail("SOLIB_CREATE_INFERIOR_HOOK")
BEGIN { doc["PC_SOLIB"] = "\
Replace PC_SOLIB with nothing, not needed?"
- category["PC_SOLIB"] = ari_deprecate
+ category["PC_SOLIB"] = ari_regression
}
/(^|[^_[:alnum:]])PC_SOLIB([^_[:alnum:]]|$)/ {
fail("PC_SOLIB")
}
BEGIN { doc["bcmp"] = "\
-Do not use bcmp(), ISO C 90 implies memcmp()"
+Do not use bcmp(), C++11 implies memcmp()"
category["bcmp"] = ari_regression
}
/(^|[^_[:alnum:]])bcmp[[:space:]]*\(/ {
}
BEGIN { doc["setlinebuf"] = "\
-Do not use setlinebuf(), ISO C 90 implies setvbuf()"
+Do not use setlinebuf(), C++11 implies setvbuf()"
category["setlinebuf"] = ari_regression
}
/(^|[^_[:alnum:]])setlinebuf[[:space:]]*\(/ {
}
BEGIN { doc["bcopy"] = "\
-Do not use bcopy(), ISO C 90 implies memcpy() and memmove()"
+Do not use bcopy(), C++11 implies memcpy() and memmove()"
category["bcopy"] = ari_regression
}
/(^|[^_[:alnum:]])bcopy[[:space:]]*\(/ {
BEGIN { doc["floatformat_to_double"] = "\
Do not use floatformat_to_double() from libierty, \
instead use floatformat_to_doublest()"
- fix("floatformat_to_double", "gdb/doublest.c", 1)
category["floatformat_to_double"] = ari_regression
}
/(^|[^_[:alnum:]])floatformat_to_double[[:space:]]*\(/ {
BEGIN { doc["floatformat_from_double"] = "\
Do not use floatformat_from_double() from libierty, \
-instead use floatformat_from_doublest()"
+instead use host_float_ops<T>::from_target()"
category["floatformat_from_double"] = ari_regression
}
/(^|[^_[:alnum:]])floatformat_from_double[[:space:]]*\(/ {
category["write_pc"] = ari_deprecate
}
/(^|[^_[:alnum:]])write_pc[[:space:]]*\(/ || \
-/(^|[^_[:alnum:]])set_gdbarch_write_pc[[:space:]]*\(/ || \
/(^|[^_[:alnum:]])TARGET_WRITE_PC[[:space:]]*\(/ {
fail("write_pc")
}
BEGIN { doc["vasprintf"] = "\
Do not use vasprintf(), instead use xstrvprintf"
- fix("vasprintf", "common/common-utils.c", 1)
+ fix("vasprintf", "gdbsupport/common-utils.c", 1)
category["vasprintf"] = ari_regression
}
/(^|[^_[:alnum:]])vasprintf[[:space:]]*\(/ {
fail("vasprintf")
}
-BEGIN { doc["xasprintf"] = "\
-Do not use xasprintf(), instead use xstrprintf"
- fix("xasprintf", "common/common-utils.h", 1)
- fix("xasprintf", "common/common-utils.c", 1)
- category["xasprintf"] = ari_regression
+BEGIN { doc["printf_vma"] = "\
+Do not use printf_vma, instead use paddress or phex_nz"
+ category["printf_vma"] = ari_code
}
-/(^|[^_[:alnum:]])xasprintf[[:space:]]*\(/ {
- fail("xasprintf")
+/(^|[^_[:alnum:]])printf_vma[[:space:]]*\(/ {
+ fail("printf_vma")
}
-BEGIN { doc["xvasprintf"] = "\
-Do not use xvasprintf(), instead use xstrvprintf"
- fix("xvasprintf", "common/common-utils.h", 1)
- fix("xvasprintf", "common/common-utils.c", 1)
- category["xvasprintf"] = ari_regression
+BEGIN { doc["sprintf_vma"] = "\
+Do not use sprintf_vma, instead use paddress or phex_nz"
+ category["sprintf_vma"] = ari_code
}
-/(^|[^_[:alnum:]])xvasprintf[[:space:]]*\(/ {
- fail("xvasprintf")
+/(^|[^_[:alnum:]])sprintf_vma[[:space:]]*\(/ {
+ fail("sprintf_vma")
}
# More generic memory operations
fail("strnicmp")
}
-# Boolean expressions and conditionals
-
-BEGIN { doc["boolean"] = "\
-Do not use `boolean'\'', use `int'\'' instead"
- category["boolean"] = ari_regression
-}
-/(^|[^_[:alnum:]])boolean([^_[:alnum:]]|$)/ {
- if (is_yacc_or_lex == 0) {
- fail("boolean")
- }
-}
-
-BEGIN { doc["false"] = "\
-Definitely do not use `false'\'' in boolean expressions"
- category["false"] = ari_regression
-}
-/(^|[^_[:alnum:]])false([^_[:alnum:]]|$)/ {
- if (is_yacc_or_lex == 0) {
- fail("false")
- }
-}
-
-BEGIN { doc["true"] = "\
-Do not try to use `true'\'' in boolean expressions"
- category["true"] = ari_regression
-}
-/(^|[^_[:alnum:]])true([^_[:alnum:]]|$)/ {
- if (is_yacc_or_lex == 0) {
- fail("true")
- }
-}
-
# Typedefs that are either redundant or can be reduced to `struct
# type *''.
# Must be placed before if assignment otherwise ARI exceptions
fail("strlen d_name")
}
-BEGIN { doc["var_boolean"] = "\
-Replace var_boolean with add_setshow_boolean_cmd"
- category["var_boolean"] = ari_regression
- fix("var_boolean", "gdb/command.h", 1)
- # fix only uses the last directory level
- fix("var_boolean", "cli/cli-decode.c", 2)
-}
-/(^|[^_[:alnum:]])var_boolean([^_[:alnum:]]|$)/ {
- if (($0 !~ /(^|[^_[:alnum:]])case *var_boolean:/) \
- && ($0 !~ /(^|[^_[:alnum:]])[=!]= *var_boolean/)) {
- fail("var_boolean")
- }
-}
-
BEGIN { doc["generic_use_struct_convention"] = "\
Replace generic_use_struct_convention with nothing, \
EXTRACT_STRUCT_VALUE_ADDRESS is a predicate"