197ec5308Schristos#!/bin/sh
297ec5308Schristos
397ec5308Schristos# GDB script to list of problems using awk.
497ec5308Schristos#
5*184b2d41Schristos# Copyright (C) 2002-2020 Free Software Foundation, Inc.
697ec5308Schristos#
797ec5308Schristos# This file is part of GDB.
897ec5308Schristos#
997ec5308Schristos# This program is free software; you can redistribute it and/or modify
1097ec5308Schristos# it under the terms of the GNU General Public License as published by
1197ec5308Schristos# the Free Software Foundation; either version 3 of the License, or
1297ec5308Schristos# (at your option) any later version.
1397ec5308Schristos#
1497ec5308Schristos# This program is distributed in the hope that it will be useful,
1597ec5308Schristos# but WITHOUT ANY WARRANTY; without even the implied warranty of
1697ec5308Schristos# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1797ec5308Schristos# GNU General Public License for more details.
1897ec5308Schristos#
1997ec5308Schristos# You should have received a copy of the GNU General Public License
2097ec5308Schristos# along with this program.  If not, see <http://www.gnu.org/licenses/>.
2197ec5308Schristos
2297ec5308Schristos# Make certain that the script is not running in an internationalized
2397ec5308Schristos# environment.
2497ec5308Schristos
2597ec5308SchristosLANG=C ; export LANG
2697ec5308SchristosLC_ALL=C ; export LC_ALL
2797ec5308Schristos
2897ec5308Schristos# Permanent checks take the form:
2997ec5308Schristos
30*184b2d41Schristos#     Do not use XXXX, C++11 implies YYYY
3197ec5308Schristos#     Do not use XXXX, instead use YYYY''.
3297ec5308Schristos
3397ec5308Schristos# and should never be removed.
3497ec5308Schristos
3597ec5308Schristos# Temporary checks take the form:
3697ec5308Schristos
3797ec5308Schristos#     Replace XXXX with YYYY
3897ec5308Schristos
3997ec5308Schristos# and once they reach zero, can be eliminated.
4097ec5308Schristos
4197ec5308Schristos# FIXME: It should be able to override this on the command line
4297ec5308Schristoserror="regression"
4397ec5308Schristoswarning="regression"
4497ec5308Schristosari="regression eol code comment deprecated legacy obsolete gettext"
4597ec5308Schristosall="regression eol code comment deprecated legacy obsolete gettext deprecate internal gdbarch macro"
4697ec5308Schristosprint_doc=0
4797ec5308Schristosprint_idx=0
4897ec5308Schristos
4997ec5308Schristosusage ()
5097ec5308Schristos{
5197ec5308Schristos    cat <<EOF 1>&2
5297ec5308SchristosError: $1
5397ec5308Schristos
5497ec5308SchristosUsage:
55*184b2d41Schristos    $0 --print-doc --print-idx -Wall -Werror -WCATEGORY FILE ...
5697ec5308SchristosOptions:
5797ec5308Schristos  --print-doc    Print a list of all potential problems, then exit.
5897ec5308Schristos  --print-idx    Include the problems IDX (index or key) in every message.
5997ec5308Schristos  --src=file     Write source lines to file.
6097ec5308Schristos  -Werror        Treat all problems as errors.
6197ec5308Schristos  -Wall          Report all problems.
6297ec5308Schristos  -Wari          Report problems that should be fixed in new code.
63*184b2d41Schristos  -WCATEGORY     Report problems in the specifed category.  The category
64*184b2d41Schristos                 can be prefixed with "no-".  Valid categories
6597ec5308Schristos                 are: ${all}
6697ec5308SchristosEOF
6797ec5308Schristos    exit 1
6897ec5308Schristos}
6997ec5308Schristos
7097ec5308Schristos
7197ec5308Schristos# Parse the various options
7297ec5308SchristosWoptions=
7397ec5308Schristossrclines=""
7497ec5308Schristoswhile test $# -gt 0
7597ec5308Schristosdo
7697ec5308Schristos    case "$1" in
7797ec5308Schristos    -Wall ) Woptions="${all}" ;;
7897ec5308Schristos    -Wari ) Woptions="${ari}" ;;
7997ec5308Schristos    -Werror ) Werror=1 ;;
8097ec5308Schristos    -W* ) Woptions="${Woptions} `echo x$1 | sed -e 's/x-W//'`" ;;
8197ec5308Schristos    --print-doc ) print_doc=1 ;;
8297ec5308Schristos    --print-idx ) print_idx=1 ;;
8397ec5308Schristos    --src=* ) srclines="`echo $1 | sed -e 's/--src=/srclines=\"/'`\"" ;;
8497ec5308Schristos    -- ) shift ; break ;;
8597ec5308Schristos    - ) break ;;
8697ec5308Schristos    -* ) usage "$1: unknown option" ;;
8797ec5308Schristos    * ) break ;;
8897ec5308Schristos    esac
8997ec5308Schristos    shift
9097ec5308Schristosdone
9197ec5308Schristosif test -n "$Woptions" ; then
9297ec5308Schristos    warning="$Woptions"
9397ec5308Schristos    error=
9497ec5308Schristosfi
9597ec5308Schristos
9697ec5308Schristos
9797ec5308Schristos# -Werror implies treating all warnings as errors.
9897ec5308Schristosif test -n "${Werror}" ; then
9997ec5308Schristos    error="${error} ${warning}"
10097ec5308Schristosfi
10197ec5308Schristos
10297ec5308Schristos
10397ec5308Schristos# Validate all errors and warnings.
10497ec5308Schristosfor w in ${warning} ${error}
10597ec5308Schristosdo
106*184b2d41Schristos    case "$w" in
107*184b2d41Schristos	no-*) w=`echo x$w | sed -e 's/xno-//'`;;
108*184b2d41Schristos    esac
109*184b2d41Schristos
11097ec5308Schristos    case " ${all} " in
11197ec5308Schristos    *" ${w} "* ) ;;
11297ec5308Schristos    * ) usage "Unknown option -W${w}" ;;
11397ec5308Schristos    esac
11497ec5308Schristosdone
11597ec5308Schristos
11697ec5308Schristos
11797ec5308Schristos# make certain that there is at least one file.
11897ec5308Schristosif test $# -eq 0 -a ${print_doc} = 0
11997ec5308Schristosthen
12097ec5308Schristos    usage "Missing file."
12197ec5308Schristosfi
12297ec5308Schristos
12397ec5308Schristos
12497ec5308Schristos# Convert the errors/warnings into corresponding array entries.
12597ec5308Schristosfor a in ${all}
12697ec5308Schristosdo
12797ec5308Schristos    aris="${aris} ari_${a} = \"${a}\";"
12897ec5308Schristosdone
12997ec5308Schristosfor w in ${warning}
13097ec5308Schristosdo
131*184b2d41Schristos    val=1
132*184b2d41Schristos    case "$w" in
133*184b2d41Schristos	no-*) w=`echo x$w | sed -e 's/xno-//'`; val=0 ;;
134*184b2d41Schristos    esac
135*184b2d41Schristos    warnings="${warnings} warning[ari_${w}] = $val;"
13697ec5308Schristosdone
13797ec5308Schristosfor e in ${error}
13897ec5308Schristosdo
139*184b2d41Schristos    val=1
140*184b2d41Schristos    case "$e" in
141*184b2d41Schristos	no-*) e=`echo x$e | sed -e 's/xno-//'`; val=0 ;;
142*184b2d41Schristos    esac
143*184b2d41Schristos    errors="${errors} error[ari_${e}]  = $val;"
14497ec5308Schristosdone
14597ec5308Schristos
14697ec5308Schristosif [ "$AWK" = "" ] ; then
14797ec5308Schristos  AWK=awk
14897ec5308Schristosfi
14997ec5308Schristos
15097ec5308Schristos${AWK} -- '
15197ec5308SchristosBEGIN {
15297ec5308Schristos    # NOTE, for a per-file begin use "FNR == 1".
15397ec5308Schristos    '"${aris}"'
15497ec5308Schristos    '"${errors}"'
15597ec5308Schristos    '"${warnings}"'
15697ec5308Schristos    '"${srclines}"'
15797ec5308Schristos    print_doc =  '$print_doc'
15897ec5308Schristos    print_idx =  '$print_idx'
15997ec5308Schristos    PWD = "'`pwd`'"
16097ec5308Schristos}
16197ec5308Schristos
16297ec5308Schristos# Print the error message for BUG.  Append SUPLEMENT if non-empty.
16397ec5308Schristosfunction print_bug(file,line,prefix,category,bug,doc,supplement, suffix,idx) {
16497ec5308Schristos    if (print_idx) {
16597ec5308Schristos	idx = bug ": "
16697ec5308Schristos    } else {
16797ec5308Schristos	idx = ""
16897ec5308Schristos    }
16997ec5308Schristos    if (supplement) {
17097ec5308Schristos	suffix = " (" supplement ")"
17197ec5308Schristos    } else {
17297ec5308Schristos	suffix = ""
17397ec5308Schristos    }
17497ec5308Schristos    # ari.*.bug: <FILE>:<LINE>: <CATEGORY>: <BUG>: <DOC>
17597ec5308Schristos    print file ":" line ": " prefix category ": " idx doc suffix
17697ec5308Schristos    if (srclines != "") {
17797ec5308Schristos	print file ":" line ":" $0 >> srclines
17897ec5308Schristos    }
17997ec5308Schristos}
18097ec5308Schristos
18197ec5308Schristosfunction fix(bug,file,count) {
18297ec5308Schristos    skip[bug, file] = count
18397ec5308Schristos    skipped[bug, file] = 0
18497ec5308Schristos}
18597ec5308Schristos
18697ec5308Schristosfunction fail(bug,supplement) {
18797ec5308Schristos    if (doc[bug] == "") {
18897ec5308Schristos	print_bug("", 0, "internal: ", "internal", "internal", "Missing doc for bug " bug)
18997ec5308Schristos	exit
19097ec5308Schristos    }
19197ec5308Schristos    if (category[bug] == "") {
19297ec5308Schristos	print_bug("", 0, "internal: ", "internal", "internal", "Missing category for bug " bug)
19397ec5308Schristos	exit
19497ec5308Schristos    }
19597ec5308Schristos
19697ec5308Schristos    if (ARI_OK == bug) {
19797ec5308Schristos	return
19897ec5308Schristos    }
19997ec5308Schristos    # Trim the filename down to just DIRECTORY/FILE so that it can be
20097ec5308Schristos    # robustly used by the FIX code.
20197ec5308Schristos
20297ec5308Schristos    if (FILENAME ~ /^\//) {
20397ec5308Schristos	canonicalname = FILENAME
20497ec5308Schristos    } else {
20597ec5308Schristos        canonicalname = PWD "/" FILENAME
20697ec5308Schristos    }
20797ec5308Schristos    shortname = gensub (/^.*\/([^\\]*\/[^\\]*)$/, "\\1", 1, canonicalname)
20897ec5308Schristos
20997ec5308Schristos    skipped[bug, shortname]++
21097ec5308Schristos    if (skip[bug, shortname] >= skipped[bug, shortname]) {
21197ec5308Schristos	# print FILENAME, FNR, skip[bug, FILENAME], skipped[bug, FILENAME], bug
21297ec5308Schristos	# Do nothing
21397ec5308Schristos    } else if (error[category[bug]]) {
21497ec5308Schristos	# ari.*.bug: <FILE>:<LINE>: <CATEGORY>: <BUG>: <DOC>
21597ec5308Schristos	print_bug(FILENAME, FNR, "", category[bug], bug, doc[bug], supplement)
21697ec5308Schristos    } else if (warning[category[bug]]) {
21797ec5308Schristos	# ari.*.bug: <FILE>:<LINE>: <CATEGORY>: <BUG>: <DOC>
21897ec5308Schristos	print_bug(FILENAME, FNR, "warning: ", category[bug], bug, doc[bug], supplement)
21997ec5308Schristos    }
22097ec5308Schristos}
22197ec5308Schristos
22297ec5308SchristosFNR == 1 {
22397ec5308Schristos    seen[FILENAME] = 1
22497ec5308Schristos    if (match(FILENAME, "\\.[ly]$")) {
22597ec5308Schristos      # FILENAME is a lex or yacc source
22697ec5308Schristos      is_yacc_or_lex = 1
22797ec5308Schristos    }
22897ec5308Schristos    else {
22997ec5308Schristos      is_yacc_or_lex = 0
23097ec5308Schristos    }
23197ec5308Schristos}
23297ec5308SchristosEND {
23397ec5308Schristos    if (print_idx) {
23497ec5308Schristos	idx = bug ": "
23597ec5308Schristos    } else {
23697ec5308Schristos	idx = ""
23797ec5308Schristos    }
23897ec5308Schristos    # Did we do only a partial skip?
23997ec5308Schristos    for (bug_n_file in skip) {
24097ec5308Schristos	split (bug_n_file, a, SUBSEP)
24197ec5308Schristos	bug = a[1]
24297ec5308Schristos	file = a[2]
24397ec5308Schristos	if (seen[file] && (skipped[bug_n_file] < skip[bug_n_file])) {
24497ec5308Schristos	    # ari.*.bug: <FILE>:<LINE>: <CATEGORY>: <BUG>: <DOC>
24597ec5308Schristos	    b = file " missing " bug
24697ec5308Schristos	    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])
24797ec5308Schristos	}
24897ec5308Schristos    }
24997ec5308Schristos}
25097ec5308Schristos
25197ec5308Schristos
25297ec5308Schristos# Skip OBSOLETE lines
25397ec5308Schristos/(^|[^_[:alnum:]])OBSOLETE([^_[:alnum:]]|$)/ { next; }
25497ec5308Schristos
25597ec5308Schristos# Skip ARI lines
25697ec5308Schristos
25797ec5308SchristosBEGIN {
25897ec5308Schristos    ARI_OK = ""
25997ec5308Schristos}
26097ec5308Schristos
26197ec5308Schristos/\/\* ARI:[[:space:]]*(.*)[[:space:]]*\*\// {
26297ec5308Schristos    ARI_OK = gensub(/^.*\/\* ARI:[[:space:]]*(.*[^[:space:]])[[:space:]]*\*\/.*$/, "\\1", 1, $0)
26397ec5308Schristos    # print "ARI line found \"" $0 "\""
26497ec5308Schristos    # print "ARI_OK \"" ARI_OK "\""
26597ec5308Schristos}
26697ec5308Schristos! /\/\* ARI:[[:space:]]*(.*)[[:space:]]*\*\// {
26797ec5308Schristos    ARI_OK = ""
26897ec5308Schristos}
26997ec5308Schristos
27097ec5308Schristos
27197ec5308Schristos# SNIP - Strip out comments - SNIP
27297ec5308Schristos
27397ec5308SchristosFNR == 1 {
27497ec5308Schristos    comment_p = 0
27597ec5308Schristos}
27697ec5308Schristoscomment_p && /\*\// { gsub (/^([^\*]|\*+[^\/\*])*\*+\//, " "); comment_p = 0; }
27797ec5308Schristoscomment_p { next; }
27897ec5308Schristos!comment_p { gsub (/\/\*([^\*]|\*+[^\/\*])*\*+\//, " "); }
27997ec5308Schristos!comment_p && /(^|[^"])\/\*/ { gsub (/\/\*.*$/, " "); comment_p = 1; }
28097ec5308Schristos
28197ec5308Schristos
28297ec5308SchristosBEGIN { doc["_ markup"] = "\
28397ec5308SchristosAll messages should be marked up with _."
28497ec5308Schristos    category["_ markup"] = ari_gettext
28597ec5308Schristos}
28697ec5308Schristos/^[^"]*[[:space:]](warning|error|error_no_arg|query|perror_with_name)[[:space:]]*\([^_\(a-z]/ {
28797ec5308Schristos    if (! /\("%s"/) {
28897ec5308Schristos	fail("_ markup")
28997ec5308Schristos    }
29097ec5308Schristos}
29197ec5308Schristos
29297ec5308SchristosBEGIN { doc["trailing new line"] = "\
29397ec5308SchristosA message should not have a trailing new line"
29497ec5308Schristos    category["trailing new line"] = ari_gettext
29597ec5308Schristos}
29697ec5308Schristos/(^|[^_[:alnum:]])(warning|error)[[:space:]]*\(_\(".*\\n"\)[\),]/ {
29797ec5308Schristos    fail("trailing new line")
29897ec5308Schristos}
29997ec5308Schristos
30097ec5308Schristos# Include files for which GDB has a custom version.
30197ec5308Schristos
30297ec5308SchristosBEGIN { doc["assert.h"] = "\
30397ec5308SchristosDo not include assert.h, instead include \"gdb_assert.h\"";
30497ec5308Schristos    category["assert.h"] = ari_regression
30597ec5308Schristos    fix("assert.h", "gdb/gdb_assert.h", 0) # it does not use it
30697ec5308Schristos}
30797ec5308Schristos/^#[[:space:]]*include[[:space:]]+.assert\.h./ {
30897ec5308Schristos    fail("assert.h")
30997ec5308Schristos}
31097ec5308Schristos
31197ec5308SchristosBEGIN { doc["regex.h"] = "\
31297ec5308SchristosDo not include regex.h, instead include gdb_regex.h"
31397ec5308Schristos    category["regex.h"] = ari_regression
31497ec5308Schristos    fix("regex.h", "gdb/gdb_regex.h", 1)
31597ec5308Schristos}
31697ec5308Schristos/^#[[:space:]]*include[[:space:]]*.regex\.h./ {
31797ec5308Schristos    fail("regex.h")
31897ec5308Schristos}
31997ec5308Schristos
32097ec5308SchristosBEGIN { doc["xregex.h"] = "\
32197ec5308SchristosDo not include xregex.h, instead include gdb_regex.h"
32297ec5308Schristos    category["xregex.h"] = ari_regression
32397ec5308Schristos    fix("xregex.h", "gdb/gdb_regex.h", 1)
32497ec5308Schristos}
32597ec5308Schristos/^#[[:space:]]*include[[:space:]]*.xregex\.h./ {
32697ec5308Schristos    fail("xregex.h")
32797ec5308Schristos}
32897ec5308Schristos
32997ec5308SchristosBEGIN { doc["gnu-regex.h"] = "\
33097ec5308SchristosDo not include gnu-regex.h, instead include gdb_regex.h"
33197ec5308Schristos    category["gnu-regex.h"] = ari_regression
33297ec5308Schristos}
33397ec5308Schristos/^#[[:space:]]*include[[:space:]]*.gnu-regex\.h./ {
33497ec5308Schristos    fail("gnu regex.h")
33597ec5308Schristos}
33697ec5308Schristos
33797ec5308SchristosBEGIN { doc["wait.h"] = "\
33897ec5308SchristosDo not include wait.h or sys/wait.h, instead include gdb_wait.h"
339*184b2d41Schristos    fix("wait.h", "gdbsupport/gdb_wait.h", 2);
34097ec5308Schristos    category["wait.h"] = ari_regression
34197ec5308Schristos}
34297ec5308Schristos/^#[[:space:]]*include[[:space:]]*.wait\.h./ \
34397ec5308Schristos|| /^#[[:space:]]*include[[:space:]]*.sys\/wait\.h./ {
34497ec5308Schristos    fail("wait.h")
34597ec5308Schristos}
34697ec5308Schristos
34797ec5308SchristosBEGIN { doc["vfork.h"] = "\
34897ec5308SchristosDo not include vfork.h, instead include gdb_vfork.h"
34997ec5308Schristos    fix("vfork.h", "gdb/gdb_vfork.h", 1);
35097ec5308Schristos    category["vfork.h"] = ari_regression
35197ec5308Schristos}
35297ec5308Schristos/^#[[:space:]]*include[[:space:]]*.vfork\.h./ {
35397ec5308Schristos    fail("vfork.h")
35497ec5308Schristos}
35597ec5308Schristos
35697ec5308SchristosBEGIN { doc["error not internal-warning"] = "\
35797ec5308SchristosDo not use error(\"internal-warning\"), instead use internal_warning"
35897ec5308Schristos    category["error not internal-warning"] = ari_regression
35997ec5308Schristos}
36097ec5308Schristos/error.*\"[Ii]nternal.warning/ {
36197ec5308Schristos    fail("error not internal-warning")
36297ec5308Schristos}
36397ec5308Schristos
36497ec5308SchristosBEGIN { doc["%p"] = "\
36597ec5308SchristosDo not use printf(\"%p\"), instead use printf(\"%s\",paddr()) to dump a \
36697ec5308Schristostarget address, or host_address_to_string() for a host address"
36797ec5308Schristos    category["%p"] = ari_code
36897ec5308Schristos}
369*184b2d41Schristos# Allow gdb %p extensions, but not other uses of %p.
370*184b2d41Schristos/%p[^[\]sF]/ && !/%prec/ {
37197ec5308Schristos    fail("%p")
37297ec5308Schristos}
37397ec5308Schristos
37497ec5308SchristosBEGIN { doc["%ll"] = "\
37597ec5308SchristosDo not use printf(\"%ll\"), instead use printf(\"%s\",phex()) to dump a \
37697ec5308Schristos`long long'\'' value"
37797ec5308Schristos    category["%ll"] = ari_code
37897ec5308Schristos}
37997ec5308Schristos# Allow %ll in scanf
38097ec5308Schristos/%[0-9]*ll/ && !/scanf \(.*%[0-9]*ll/ {
38197ec5308Schristos    fail("%ll")
38297ec5308Schristos}
38397ec5308Schristos
38497ec5308Schristos
38597ec5308Schristos# SNIP - Strip out strings - SNIP
38697ec5308Schristos
38797ec5308Schristos# Test on top.c, scm-valprint.c, remote-rdi.c, ada-lang.c
38897ec5308SchristosFNR == 1 {
38997ec5308Schristos    string_p = 0
39097ec5308Schristos    trace_string = 0
39197ec5308Schristos}
39297ec5308Schristos# Strip escaped characters.
39397ec5308Schristos{ gsub(/\\./, "."); }
39497ec5308Schristos# Strip quoted quotes.
39597ec5308Schristos{ gsub(/'\''.'\''/, "'\''.'\''"); }
39697ec5308Schristos# End of multi-line string
39797ec5308Schristosstring_p && /\"/ {
39897ec5308Schristos    if (trace_string) print "EOS:" FNR, $0;
39997ec5308Schristos    gsub (/^[^\"]*\"/, "'\''");
40097ec5308Schristos    string_p = 0;
40197ec5308Schristos}
40297ec5308Schristos# Middle of multi-line string, discard line.
40397ec5308Schristosstring_p {
40497ec5308Schristos    if (trace_string) print "MOS:" FNR, $0;
40597ec5308Schristos    $0 = ""
40697ec5308Schristos}
40797ec5308Schristos# Strip complete strings from the middle of the line
40897ec5308Schristos!string_p && /\"[^\"]*\"/ {
40997ec5308Schristos    if (trace_string) print "COS:" FNR, $0;
41097ec5308Schristos    gsub (/\"[^\"]*\"/, "'\''");
41197ec5308Schristos}
41297ec5308Schristos# Start of multi-line string
41397ec5308SchristosBEGIN { doc["multi-line string"] = "\
41497ec5308SchristosMulti-line string must have the newline escaped"
41597ec5308Schristos    category["multi-line string"] = ari_regression
41697ec5308Schristos}
41797ec5308Schristos!string_p && /\"/ {
41897ec5308Schristos    if (trace_string) print "SOS:" FNR, $0;
41997ec5308Schristos    if (/[^\\]$/) {
42097ec5308Schristos	fail("multi-line string")
42197ec5308Schristos    }
42297ec5308Schristos    gsub (/\"[^\"]*$/, "'\''");
42397ec5308Schristos    string_p = 1;
42497ec5308Schristos}
42597ec5308Schristos# { print }
42697ec5308Schristos
42797ec5308Schristos# Multi-line string
42897ec5308Schristosstring_p &&
42997ec5308Schristos
43097ec5308Schristos# Accumulate continuation lines
43197ec5308SchristosFNR == 1 {
43297ec5308Schristos    cont_p = 0
43397ec5308Schristos}
43497ec5308Schristos!cont_p { full_line = ""; }
43597ec5308Schristos/[^\\]\\$/ { gsub (/\\$/, ""); full_line = full_line $0; cont_p = 1; next; }
43697ec5308Schristoscont_p { $0 = full_line $0; cont_p = 0; full_line = ""; }
43797ec5308Schristos
43897ec5308Schristos
43997ec5308SchristosBEGIN { doc["__FUNCTION__"] = "\
440*184b2d41SchristosDo not use __FUNCTION__, C++11 does not support this macro"
44197ec5308Schristos    category["__FUNCTION__"] = ari_regression
44297ec5308Schristos}
44397ec5308Schristos/(^|[^_[:alnum:]])__FUNCTION__([^_[:alnum:]]|$)/ {
44497ec5308Schristos    fail("__FUNCTION__")
44597ec5308Schristos}
44697ec5308Schristos
44797ec5308SchristosBEGIN { doc["__CYGWIN32__"] = "\
44897ec5308SchristosDo not use __CYGWIN32__, instead use __CYGWIN__ or, better, an explicit \
44997ec5308Schristosautoconf tests"
45097ec5308Schristos    category["__CYGWIN32__"] = ari_regression
45197ec5308Schristos}
45297ec5308Schristos/(^|[^_[:alnum:]])__CYGWIN32__([^_[:alnum:]]|$)/ {
45397ec5308Schristos    fail("__CYGWIN32__")
45497ec5308Schristos}
45597ec5308Schristos
45697ec5308SchristosBEGIN { doc["PTR"] = "\
457*184b2d41SchristosDo not use PTR, C++11 implies `void *'\''"
45897ec5308Schristos    category["PTR"] = ari_regression
45997ec5308Schristos    #fix("PTR", "gdb/utils.c", 6)
46097ec5308Schristos}
46197ec5308Schristos/(^|[^_[:alnum:]])PTR([^_[:alnum:]]|$)/ {
46297ec5308Schristos    fail("PTR")
46397ec5308Schristos}
46497ec5308Schristos
46597ec5308SchristosBEGIN { doc["UCASE function"] = "\
46697ec5308SchristosFunction name is uppercase."
46797ec5308Schristos    category["UCASE function"] = ari_code
46897ec5308Schristos    possible_UCASE = 0
46997ec5308Schristos    UCASE_full_line = ""
47097ec5308Schristos}
47197ec5308Schristos(possible_UCASE) {
47297ec5308Schristos    if (ARI_OK == "UCASE function") {
47397ec5308Schristos	possible_UCASE = 0
47497ec5308Schristos    }
47597ec5308Schristos    # Closing brace found?
47697ec5308Schristos    else if (UCASE_full_line ~ \
47797ec5308Schristos	/^[A-Z][[:alnum:]_]*[[:space:]]*\([^()]*\).*$/) {
47897ec5308Schristos	if ((UCASE_full_line ~ \
47997ec5308Schristos	    /^[A-Z][[:alnum:]_]*[[:space:]]*\([^()]*\)[[:space:]]*$/) \
48097ec5308Schristos	    && ($0 ~ /^\{/) && (is_yacc_or_lex == 0)) {
48197ec5308Schristos	    store_FNR = FNR
48297ec5308Schristos	    FNR = possible_FNR
48397ec5308Schristos	    store_0 = $0;
48497ec5308Schristos	    $0 = UCASE_full_line;
48597ec5308Schristos	    fail("UCASE function")
48697ec5308Schristos	    FNR = store_FNR
48797ec5308Schristos	    $0 = store_0;
48897ec5308Schristos	}
48997ec5308Schristos	possible_UCASE = 0
49097ec5308Schristos	UCASE_full_line = ""
49197ec5308Schristos    } else {
49297ec5308Schristos	UCASE_full_line = UCASE_full_line $0;
49397ec5308Schristos    }
49497ec5308Schristos}
49597ec5308Schristos/^[A-Z][[:alnum:]_]*[[:space:]]*\([^()]*(|\))[[:space:]]*$/ {
49697ec5308Schristos    possible_UCASE = 1
49797ec5308Schristos    if (ARI_OK == "UCASE function") {
49897ec5308Schristos	possible_UCASE = 0
49997ec5308Schristos    }
50097ec5308Schristos    possible_FNR = FNR
50197ec5308Schristos    UCASE_full_line = $0
50297ec5308Schristos}
50397ec5308Schristos
50497ec5308Schristos
50597ec5308SchristosBEGIN { doc["editCase function"] = "\
50697ec5308SchristosFunction name starts lower case but has uppercased letters."
50797ec5308Schristos    category["editCase function"] = ari_code
50897ec5308Schristos    possible_editCase = 0
50997ec5308Schristos    editCase_full_line = ""
51097ec5308Schristos}
51197ec5308Schristos(possible_editCase) {
51297ec5308Schristos    if (ARI_OK == "editCase function") {
51397ec5308Schristos	possible_editCase = 0
51497ec5308Schristos    }
51597ec5308Schristos    # Closing brace found?
51697ec5308Schristos    else if (editCase_full_line ~ \
51797ec5308Schristos/^[a-z][a-z0-9_]*[A-Z][a-z0-9A-Z_]*[[:space:]]*\([^()]*\).*$/) {
51897ec5308Schristos	if ((editCase_full_line ~ \
51997ec5308Schristos/^[a-z][a-z0-9_]*[A-Z][a-z0-9A-Z_]*[[:space:]]*\([^()]*\)[[:space:]]*$/) \
52097ec5308Schristos	    && ($0 ~ /^\{/) && (is_yacc_or_lex == 0)) {
52197ec5308Schristos	    store_FNR = FNR
52297ec5308Schristos	    FNR = possible_FNR
52397ec5308Schristos	    store_0 = $0;
52497ec5308Schristos	    $0 = editCase_full_line;
52597ec5308Schristos	    fail("editCase function")
52697ec5308Schristos	    FNR = store_FNR
52797ec5308Schristos	    $0 = store_0;
52897ec5308Schristos	}
52997ec5308Schristos	possible_editCase = 0
53097ec5308Schristos	editCase_full_line = ""
53197ec5308Schristos    } else {
53297ec5308Schristos	editCase_full_line = editCase_full_line $0;
53397ec5308Schristos    }
53497ec5308Schristos}
53597ec5308Schristos/^[a-z][a-z0-9_]*[A-Z][a-z0-9A-Z_]*[[:space:]]*\([^()]*(|\))[[:space:]]*$/ {
53697ec5308Schristos    possible_editCase = 1
53797ec5308Schristos    if (ARI_OK == "editCase function") {
53897ec5308Schristos        possible_editCase = 0
53997ec5308Schristos    }
54097ec5308Schristos    possible_FNR = FNR
54197ec5308Schristos    editCase_full_line = $0
54297ec5308Schristos}
54397ec5308Schristos
54497ec5308Schristos# Only function implementation should be on first column
54597ec5308SchristosBEGIN { doc["function call in first column"] = "\
54697ec5308SchristosFunction name in first column should be restricted to function implementation"
54797ec5308Schristos    category["function call in first column"] = ari_code
54897ec5308Schristos}
54997ec5308Schristos/^[a-z][a-z0-9_]*[[:space:]]*\((|[^*][^()]*)\)[[:space:]]*[^ \t]+/ {
55097ec5308Schristos    fail("function call in first column")
55197ec5308Schristos}
55297ec5308Schristos
55397ec5308Schristos
55497ec5308SchristosBEGIN { doc["hash"] = "\
55597ec5308SchristosDo not use ` #...'\'', instead use `#...'\''(some compilers only correctly \
55697ec5308Schristosparse a C preprocessor directive when `#'\'' is the first character on \
55797ec5308Schristosthe line)"
55897ec5308Schristos    category["hash"] = ari_regression
55997ec5308Schristos}
56097ec5308Schristos/^[[:space:]]+#/ {
56197ec5308Schristos    fail("hash")
56297ec5308Schristos}
56397ec5308Schristos
56497ec5308SchristosBEGIN { doc["OP eol"] = "\
56597ec5308SchristosDo not use &&, or || at the end of a line"
56697ec5308Schristos    category["OP eol"] = ari_code
56797ec5308Schristos}
56897ec5308Schristos# * operator needs a special treatment as it can be a
56997ec5308Schristos# valid end of line for a pointer type definition
57097ec5308Schristos# Only catch case where an assignment or an opening brace is present
57197ec5308Schristos/(\|\||\&\&|==|!=|[[:space:]][+\-\/])[[:space:]]*$/ \
57297ec5308Schristos|| /(\(|=)[[:space:]].*[[:space:]]\*[[:space:]]*$/ {
57397ec5308Schristos    fail("OP eol")
57497ec5308Schristos}
57597ec5308Schristos
57697ec5308SchristosBEGIN { doc["strerror"] = "\
57797ec5308SchristosDo not use strerror(), instead use safe_strerror()"
57897ec5308Schristos    category["strerror"] = ari_regression
57997ec5308Schristos    fix("strerror", "gdb/gdb_string.h", 1)
580*184b2d41Schristos    fix("strerror", "gdb/gdbsupport/mingw-strerror.c", 1)
581*184b2d41Schristos    fix("strerror", "gdb/gdbsupport/posix-strerror.c", 1)
58297ec5308Schristos}
58397ec5308Schristos/(^|[^_[:alnum:]])strerror[[:space:]]*\(/ {
58497ec5308Schristos    fail("strerror")
58597ec5308Schristos}
58697ec5308Schristos
58797ec5308SchristosBEGIN { doc["long long"] = "\
58897ec5308SchristosDo not use `long long'\'', instead use LONGEST"
58997ec5308Schristos    category["long long"] = ari_code
59097ec5308Schristos}
59197ec5308Schristos/(^|[^_[:alnum:]])long[[:space:]]+long([^_[:alnum:]]|$)/ {
59297ec5308Schristos    fail("long long")
59397ec5308Schristos}
59497ec5308Schristos
59597ec5308SchristosBEGIN { doc["ATTR_FORMAT"] = "\
59697ec5308SchristosDo not use ATTR_FORMAT, use ATTRIBUTE_PRINTF instead"
59797ec5308Schristos    category["ATTR_FORMAT"] = ari_regression
59897ec5308Schristos}
59997ec5308Schristos/(^|[^_[:alnum:]])ATTR_FORMAT([^_[:alnum:]]|$)/ {
60097ec5308Schristos    fail("ATTR_FORMAT")
60197ec5308Schristos}
60297ec5308Schristos
60397ec5308SchristosBEGIN { doc["ATTR_NORETURN"] = "\
60497ec5308SchristosDo not use ATTR_NORETURN, use ATTRIBUTE_NORETURN instead"
60597ec5308Schristos    category["ATTR_NORETURN"] = ari_regression
60697ec5308Schristos}
60797ec5308Schristos/(^|[^_[:alnum:]])ATTR_NORETURN([^_[:alnum:]]|$)/ {
60897ec5308Schristos    fail("ATTR_NORETURN")
60997ec5308Schristos}
61097ec5308Schristos
61197ec5308SchristosBEGIN { doc["NORETURN"] = "\
61297ec5308SchristosDo not use NORETURN, use ATTRIBUTE_NORETURN instead"
61397ec5308Schristos    category["NORETURN"] = ari_regression
61497ec5308Schristos}
61597ec5308Schristos/(^|[^_[:alnum:]])NORETURN([^_[:alnum:]]|$)/ {
61697ec5308Schristos    fail("NORETURN")
61797ec5308Schristos}
61897ec5308Schristos
61997ec5308Schristos
62097ec5308Schristos# General problems
62197ec5308Schristos
62297ec5308Schristos# Commented out, but left inside sources, just in case.
62397ec5308Schristos# BEGIN { doc["inline"] = "\
62497ec5308Schristos# Do not use the inline attribute; \
62597ec5308Schristos# since the compiler generally ignores this, better algorithm selection \
62697ec5308Schristos# is needed to improved performance"
62797ec5308Schristos#    category["inline"] = ari_code
62897ec5308Schristos# }
62997ec5308Schristos# /(^|[^_[:alnum:]])inline([^_[:alnum:]]|$)/ {
63097ec5308Schristos#     fail("inline")
63197ec5308Schristos# }
63297ec5308Schristos
63397ec5308Schristos# This test is obsolete as this type
63497ec5308Schristos# has been deprecated and finally suppressed from GDB sources
63597ec5308Schristos#BEGIN { doc["obj_private"] = "\
63697ec5308Schristos#Replace obj_private with objfile_data"
63797ec5308Schristos#    category["obj_private"] = ari_obsolete
63897ec5308Schristos#}
63997ec5308Schristos#/(^|[^_[:alnum:]])obj_private([^_[:alnum:]]|$)/ {
64097ec5308Schristos#    fail("obj_private")
64197ec5308Schristos#}
64297ec5308Schristos
64397ec5308SchristosBEGIN { doc["abort"] = "\
64497ec5308SchristosDo not use abort, instead use internal_error; GDB should never abort"
64597ec5308Schristos    category["abort"] = ari_regression
64697ec5308Schristos}
64797ec5308Schristos/(^|[^_[:alnum:]])abort[[:space:]]*\(/ {
64897ec5308Schristos    fail("abort")
64997ec5308Schristos}
65097ec5308Schristos
65197ec5308SchristosBEGIN { doc["basename"] = "\
65297ec5308SchristosDo not use basename, instead use lbasename"
65397ec5308Schristos    category["basename"] = ari_regression
65497ec5308Schristos}
65597ec5308Schristos/(^|[^_[:alnum:]])basename[[:space:]]*\(/ {
65697ec5308Schristos    fail("basename")
65797ec5308Schristos}
65897ec5308Schristos
65997ec5308SchristosBEGIN { doc["assert"] = "\
66097ec5308SchristosDo not use assert, instead use gdb_assert or internal_error; assert \
66197ec5308Schristoscalls abort and GDB should never call abort"
66297ec5308Schristos    category["assert"] = ari_regression
66397ec5308Schristos}
66497ec5308Schristos/(^|[^_[:alnum:]])assert[[:space:]]*\(/ {
66597ec5308Schristos    fail("assert")
66697ec5308Schristos}
66797ec5308Schristos
66897ec5308SchristosBEGIN { doc["TARGET_HAS_HARDWARE_WATCHPOINTS"] = "\
66997ec5308SchristosReplace TARGET_HAS_HARDWARE_WATCHPOINTS with nothing, not needed"
67097ec5308Schristos    category["TARGET_HAS_HARDWARE_WATCHPOINTS"] = ari_regression
67197ec5308Schristos}
67297ec5308Schristos/(^|[^_[:alnum:]])TARGET_HAS_HARDWARE_WATCHPOINTS([^_[:alnum:]]|$)/ {
67397ec5308Schristos    fail("TARGET_HAS_HARDWARE_WATCHPOINTS")
67497ec5308Schristos}
67597ec5308Schristos
67697ec5308SchristosBEGIN { doc["ADD_SHARED_SYMBOL_FILES"] = "\
67797ec5308SchristosReplace ADD_SHARED_SYMBOL_FILES with nothing, not needed?"
67897ec5308Schristos    category["ADD_SHARED_SYMBOL_FILES"] = ari_regression
67997ec5308Schristos}
68097ec5308Schristos/(^|[^_[:alnum:]])ADD_SHARED_SYMBOL_FILES([^_[:alnum:]]|$)/ {
68197ec5308Schristos    fail("ADD_SHARED_SYMBOL_FILES")
68297ec5308Schristos}
68397ec5308Schristos
68497ec5308SchristosBEGIN { doc["SOLIB_ADD"] = "\
68597ec5308SchristosReplace SOLIB_ADD with nothing, not needed?"
68697ec5308Schristos    category["SOLIB_ADD"] = ari_regression
68797ec5308Schristos}
68897ec5308Schristos/(^|[^_[:alnum:]])SOLIB_ADD([^_[:alnum:]]|$)/ {
68997ec5308Schristos    fail("SOLIB_ADD")
69097ec5308Schristos}
69197ec5308Schristos
69297ec5308SchristosBEGIN { doc["SOLIB_CREATE_INFERIOR_HOOK"] = "\
69397ec5308SchristosReplace SOLIB_CREATE_INFERIOR_HOOK with nothing, not needed?"
69497ec5308Schristos    category["SOLIB_CREATE_INFERIOR_HOOK"] = ari_regression
69597ec5308Schristos}
69697ec5308Schristos/(^|[^_[:alnum:]])SOLIB_CREATE_INFERIOR_HOOK([^_[:alnum:]]|$)/ {
69797ec5308Schristos    fail("SOLIB_CREATE_INFERIOR_HOOK")
69897ec5308Schristos}
69997ec5308Schristos
70097ec5308SchristosBEGIN { doc["SOLIB_LOADED_LIBRARY_PATHNAME"] = "\
70197ec5308SchristosReplace SOLIB_LOADED_LIBRARY_PATHNAME with nothing, not needed?"
70297ec5308Schristos    category["SOLIB_LOADED_LIBRARY_PATHNAME"] = ari_regression
70397ec5308Schristos}
70497ec5308Schristos/(^|[^_[:alnum:]])SOLIB_LOADED_LIBRARY_PATHNAME([^_[:alnum:]]|$)/ {
70597ec5308Schristos    fail("SOLIB_LOADED_LIBRARY_PATHNAME")
70697ec5308Schristos}
70797ec5308Schristos
70897ec5308SchristosBEGIN { doc["REGISTER_U_ADDR"] = "\
70997ec5308SchristosReplace REGISTER_U_ADDR with nothing, not needed?"
71097ec5308Schristos    category["REGISTER_U_ADDR"] = ari_regression
71197ec5308Schristos}
71297ec5308Schristos/(^|[^_[:alnum:]])REGISTER_U_ADDR([^_[:alnum:]]|$)/ {
71397ec5308Schristos    fail("REGISTER_U_ADDR")
71497ec5308Schristos}
71597ec5308Schristos
71697ec5308SchristosBEGIN { doc["PROCESS_LINENUMBER_HOOK"] = "\
71797ec5308SchristosReplace PROCESS_LINENUMBER_HOOK with nothing, not needed?"
71897ec5308Schristos    category["PROCESS_LINENUMBER_HOOK"] = ari_regression
71997ec5308Schristos}
72097ec5308Schristos/(^|[^_[:alnum:]])PROCESS_LINENUMBER_HOOK([^_[:alnum:]]|$)/ {
72197ec5308Schristos    fail("PROCESS_LINENUMBER_HOOK")
72297ec5308Schristos}
72397ec5308Schristos
72497ec5308SchristosBEGIN { doc["PC_SOLIB"] = "\
72597ec5308SchristosReplace PC_SOLIB with nothing, not needed?"
72697ec5308Schristos    category["PC_SOLIB"] = ari_regression
72797ec5308Schristos}
72897ec5308Schristos/(^|[^_[:alnum:]])PC_SOLIB([^_[:alnum:]]|$)/ {
72997ec5308Schristos    fail("PC_SOLIB")
73097ec5308Schristos}
73197ec5308Schristos
73297ec5308SchristosBEGIN { doc["IN_SOLIB_DYNSYM_RESOLVE_CODE"] = "\
73397ec5308SchristosReplace IN_SOLIB_DYNSYM_RESOLVE_CODE with nothing, not needed?"
73497ec5308Schristos    category["IN_SOLIB_DYNSYM_RESOLVE_CODE"] = ari_regression
73597ec5308Schristos}
73697ec5308Schristos/(^|[^_[:alnum:]])IN_SOLIB_DYNSYM_RESOLVE_CODE([^_[:alnum:]]|$)/ {
73797ec5308Schristos    fail("IN_SOLIB_DYNSYM_RESOLVE_CODE")
73897ec5308Schristos}
73997ec5308Schristos
74097ec5308SchristosBEGIN { doc["GCC_COMPILED_FLAG_SYMBOL"] = "\
74197ec5308SchristosReplace GCC_COMPILED_FLAG_SYMBOL with nothing, not needed?"
74297ec5308Schristos    category["GCC_COMPILED_FLAG_SYMBOL"] = ari_deprecate
74397ec5308Schristos}
74497ec5308Schristos/(^|[^_[:alnum:]])GCC_COMPILED_FLAG_SYMBOL([^_[:alnum:]]|$)/ {
74597ec5308Schristos    fail("GCC_COMPILED_FLAG_SYMBOL")
74697ec5308Schristos}
74797ec5308Schristos
74897ec5308SchristosBEGIN { doc["GCC2_COMPILED_FLAG_SYMBOL"] = "\
74997ec5308SchristosReplace GCC2_COMPILED_FLAG_SYMBOL with nothing, not needed?"
75097ec5308Schristos    category["GCC2_COMPILED_FLAG_SYMBOL"] = ari_deprecate
75197ec5308Schristos}
75297ec5308Schristos/(^|[^_[:alnum:]])GCC2_COMPILED_FLAG_SYMBOL([^_[:alnum:]]|$)/ {
75397ec5308Schristos    fail("GCC2_COMPILED_FLAG_SYMBOL")
75497ec5308Schristos}
75597ec5308Schristos
75697ec5308SchristosBEGIN { doc["FUNCTION_EPILOGUE_SIZE"] = "\
75797ec5308SchristosReplace FUNCTION_EPILOGUE_SIZE with nothing, not needed?"
75897ec5308Schristos    category["FUNCTION_EPILOGUE_SIZE"] = ari_regression
75997ec5308Schristos}
76097ec5308Schristos/(^|[^_[:alnum:]])FUNCTION_EPILOGUE_SIZE([^_[:alnum:]]|$)/ {
76197ec5308Schristos    fail("FUNCTION_EPILOGUE_SIZE")
76297ec5308Schristos}
76397ec5308Schristos
76497ec5308SchristosBEGIN { doc["HAVE_VFORK"] = "\
76597ec5308SchristosDo not use HAVE_VFORK, instead include \"gdb_vfork.h\" and call vfork() \
76697ec5308Schristosunconditionally"
76797ec5308Schristos    category["HAVE_VFORK"] = ari_regression
76897ec5308Schristos}
76997ec5308Schristos/(^|[^_[:alnum:]])HAVE_VFORK([^_[:alnum:]]|$)/ {
77097ec5308Schristos    fail("HAVE_VFORK")
77197ec5308Schristos}
77297ec5308Schristos
77397ec5308SchristosBEGIN { doc["bcmp"] = "\
774*184b2d41SchristosDo not use bcmp(), C++11 implies memcmp()"
77597ec5308Schristos    category["bcmp"] = ari_regression
77697ec5308Schristos}
77797ec5308Schristos/(^|[^_[:alnum:]])bcmp[[:space:]]*\(/ {
77897ec5308Schristos    fail("bcmp")
77997ec5308Schristos}
78097ec5308Schristos
78197ec5308SchristosBEGIN { doc["setlinebuf"] = "\
782*184b2d41SchristosDo not use setlinebuf(), C++11 implies setvbuf()"
78397ec5308Schristos    category["setlinebuf"] = ari_regression
78497ec5308Schristos}
78597ec5308Schristos/(^|[^_[:alnum:]])setlinebuf[[:space:]]*\(/ {
78697ec5308Schristos    fail("setlinebuf")
78797ec5308Schristos}
78897ec5308Schristos
78997ec5308SchristosBEGIN { doc["bcopy"] = "\
790*184b2d41SchristosDo not use bcopy(), C++11 implies memcpy() and memmove()"
79197ec5308Schristos    category["bcopy"] = ari_regression
79297ec5308Schristos}
79397ec5308Schristos/(^|[^_[:alnum:]])bcopy[[:space:]]*\(/ {
79497ec5308Schristos    fail("bcopy")
79597ec5308Schristos}
79697ec5308Schristos
79797ec5308SchristosBEGIN { doc["get_frame_base"] = "\
79897ec5308SchristosReplace get_frame_base with get_frame_id, get_frame_base_address, \
79997ec5308Schristosget_frame_locals_address, or get_frame_args_address."
80097ec5308Schristos    category["get_frame_base"] = ari_obsolete
80197ec5308Schristos}
80297ec5308Schristos/(^|[^_[:alnum:]])get_frame_base([^_[:alnum:]]|$)/ {
80397ec5308Schristos    fail("get_frame_base")
80497ec5308Schristos}
80597ec5308Schristos
80697ec5308SchristosBEGIN { doc["floatformat_to_double"] = "\
80797ec5308SchristosDo not use floatformat_to_double() from libierty, \
80897ec5308Schristosinstead use floatformat_to_doublest()"
80997ec5308Schristos    category["floatformat_to_double"] = ari_regression
81097ec5308Schristos}
81197ec5308Schristos/(^|[^_[:alnum:]])floatformat_to_double[[:space:]]*\(/ {
81297ec5308Schristos    fail("floatformat_to_double")
81397ec5308Schristos}
81497ec5308Schristos
81597ec5308SchristosBEGIN { doc["floatformat_from_double"] = "\
81697ec5308SchristosDo not use floatformat_from_double() from libierty, \
817*184b2d41Schristosinstead use host_float_ops<T>::from_target()"
81897ec5308Schristos    category["floatformat_from_double"] = ari_regression
81997ec5308Schristos}
82097ec5308Schristos/(^|[^_[:alnum:]])floatformat_from_double[[:space:]]*\(/ {
82197ec5308Schristos    fail("floatformat_from_double")
82297ec5308Schristos}
82397ec5308Schristos
82497ec5308SchristosBEGIN { doc["BIG_ENDIAN"] = "\
82597ec5308SchristosDo not use BIG_ENDIAN, instead use BFD_ENDIAN_BIG"
82697ec5308Schristos    category["BIG_ENDIAN"] = ari_regression
82797ec5308Schristos}
82897ec5308Schristos/(^|[^_[:alnum:]])BIG_ENDIAN([^_[:alnum:]]|$)/ {
82997ec5308Schristos    fail("BIG_ENDIAN")
83097ec5308Schristos}
83197ec5308Schristos
83297ec5308SchristosBEGIN { doc["LITTLE_ENDIAN"] = "\
83397ec5308SchristosDo not use LITTLE_ENDIAN, instead use BFD_ENDIAN_LITTLE";
83497ec5308Schristos    category["LITTLE_ENDIAN"] = ari_regression
83597ec5308Schristos}
83697ec5308Schristos/(^|[^_[:alnum:]])LITTLE_ENDIAN([^_[:alnum:]]|$)/ {
83797ec5308Schristos    fail("LITTLE_ENDIAN")
83897ec5308Schristos}
83997ec5308Schristos
84097ec5308SchristosBEGIN { doc["BIG_ENDIAN"] = "\
84197ec5308SchristosDo not use BIG_ENDIAN, instead use BFD_ENDIAN_BIG"
84297ec5308Schristos    category["BIG_ENDIAN"] = ari_regression
84397ec5308Schristos}
84497ec5308Schristos/(^|[^_[:alnum:]])BIG_ENDIAN([^_[:alnum:]]|$)/ {
84597ec5308Schristos    fail("BIG_ENDIAN")
84697ec5308Schristos}
84797ec5308Schristos
84897ec5308SchristosBEGIN { doc["sec_ptr"] = "\
84997ec5308SchristosInstead of sec_ptr, use struct bfd_section";
85097ec5308Schristos    category["sec_ptr"] = ari_regression
85197ec5308Schristos}
85297ec5308Schristos/(^|[^_[:alnum:]])sec_ptr([^_[:alnum:]]|$)/ {
85397ec5308Schristos    fail("sec_ptr")
85497ec5308Schristos}
85597ec5308Schristos
85697ec5308SchristosBEGIN { doc["frame_unwind_unsigned_register"] = "\
85797ec5308SchristosReplace frame_unwind_unsigned_register with frame_unwind_register_unsigned"
85897ec5308Schristos    category["frame_unwind_unsigned_register"] = ari_regression
85997ec5308Schristos}
86097ec5308Schristos/(^|[^_[:alnum:]])frame_unwind_unsigned_register([^_[:alnum:]]|$)/ {
86197ec5308Schristos    fail("frame_unwind_unsigned_register")
86297ec5308Schristos}
86397ec5308Schristos
86497ec5308SchristosBEGIN { doc["frame_register_read"] = "\
86597ec5308SchristosReplace frame_register_read() with get_frame_register(), or \
86697ec5308Schristospossibly introduce a new method safe_get_frame_register()"
86797ec5308Schristos    category["frame_register_read"] = ari_obsolete
86897ec5308Schristos}
86997ec5308Schristos/(^|[^_[:alnum:]])frame_register_read([^_[:alnum:]]|$)/ {
87097ec5308Schristos    fail("frame_register_read")
87197ec5308Schristos}
87297ec5308Schristos
87397ec5308SchristosBEGIN { doc["read_register"] = "\
87497ec5308SchristosReplace read_register() with regcache_read() et.al."
87597ec5308Schristos    category["read_register"] = ari_regression
87697ec5308Schristos}
87797ec5308Schristos/(^|[^_[:alnum:]])read_register([^_[:alnum:]]|$)/ {
87897ec5308Schristos    fail("read_register")
87997ec5308Schristos}
88097ec5308Schristos
88197ec5308SchristosBEGIN { doc["write_register"] = "\
88297ec5308SchristosReplace write_register() with regcache_read() et.al."
88397ec5308Schristos    category["write_register"] = ari_regression
88497ec5308Schristos}
88597ec5308Schristos/(^|[^_[:alnum:]])write_register([^_[:alnum:]]|$)/ {
88697ec5308Schristos    fail("write_register")
88797ec5308Schristos}
88897ec5308Schristos
88997ec5308Schristosfunction report(name) {
89097ec5308Schristos    # Drop any trailing _P.
89197ec5308Schristos    name = gensub(/(_P|_p)$/, "", 1, name)
89297ec5308Schristos    # Convert to lower case
89397ec5308Schristos    name = tolower(name)
89497ec5308Schristos    # Split into category and bug
89597ec5308Schristos    cat = gensub(/^([[:alpha:]]+)_([_[:alnum:]]*)$/, "\\1", 1, name)
89697ec5308Schristos    bug = gensub(/^([[:alpha:]]+)_([_[:alnum:]]*)$/, "\\2", 1, name)
89797ec5308Schristos    # Report it
89897ec5308Schristos    name = cat " " bug
89997ec5308Schristos    doc[name] = "Do not use " cat " " bug ", see declaration for details"
90097ec5308Schristos    category[name] = cat
90197ec5308Schristos    fail(name)
90297ec5308Schristos}
90397ec5308Schristos
90497ec5308Schristos/(^|[^_[:alnum:]])(DEPRECATED|deprecated|set_gdbarch_deprecated|LEGACY|legacy|set_gdbarch_legacy)_/ {
90597ec5308Schristos    line = $0
90697ec5308Schristos    # print "0 =", $0
90797ec5308Schristos    while (1) {
90897ec5308Schristos	name = gensub(/^(|.*[^_[:alnum:]])((DEPRECATED|deprecated|LEGACY|legacy)_[_[:alnum:]]*)(.*)$/, "\\2", 1, line)
90997ec5308Schristos	line = gensub(/^(|.*[^_[:alnum:]])((DEPRECATED|deprecated|LEGACY|legacy)_[_[:alnum:]]*)(.*)$/, "\\1 \\4", 1, line)
91097ec5308Schristos	# print "name =", name, "line =", line
91197ec5308Schristos	if (name == line) break;
91297ec5308Schristos	report(name)
91397ec5308Schristos    }
91497ec5308Schristos}
91597ec5308Schristos
91697ec5308Schristos# Count the number of times each architecture method is set
91797ec5308Schristos/(^|[^_[:alnum:]])set_gdbarch_[_[:alnum:]]*([^_[:alnum:]]|$)/ {
91897ec5308Schristos    name = gensub(/^.*set_gdbarch_([_[:alnum:]]*).*$/, "\\1", 1, $0)
91997ec5308Schristos    doc["set " name] = "\
92097ec5308SchristosCall to set_gdbarch_" name
92197ec5308Schristos    category["set " name] = ari_gdbarch
92297ec5308Schristos    fail("set " name)
92397ec5308Schristos}
92497ec5308Schristos
92597ec5308Schristos# Count the number of times each tm/xm/nm macro is defined or undefined
92697ec5308Schristos/^#[[:space:]]*(undef|define)[[:space:]]+[[:alnum:]_]+.*$/ \
92797ec5308Schristos&& !/^#[[:space:]]*(undef|define)[[:space:]]+[[:alnum:]_]+_H($|[[:space:]])/ \
92897ec5308Schristos&& FILENAME ~ /(^|\/)config\/(|[^\/]*\/)(tm-|xm-|nm-).*\.h$/ {
92997ec5308Schristos    basename = gensub(/(^|.*\/)([^\/]*)$/, "\\2", 1, FILENAME)
93097ec5308Schristos    type = gensub(/^(tm|xm|nm)-.*\.h$/, "\\1", 1, basename)
93197ec5308Schristos    name = gensub(/^#[[:space:]]*(undef|define)[[:space:]]+([[:alnum:]_]+).*$/, "\\2", 1, $0)
93297ec5308Schristos    if (type == basename) {
93397ec5308Schristos        type = "macro"
93497ec5308Schristos    }
93597ec5308Schristos    doc[type " " name] = "\
93697ec5308SchristosDo not define macros such as " name " in a tm, nm or xm file, \
93797ec5308Schristosin fact do not provide a tm, nm or xm file"
93897ec5308Schristos    category[type " " name] = ari_macro
93997ec5308Schristos    fail(type " " name)
94097ec5308Schristos}
94197ec5308Schristos
94297ec5308SchristosBEGIN { doc["deprecated_registers"] = "\
94397ec5308SchristosReplace deprecated_registers with nothing, they have reached \
94497ec5308Schristosend-of-life"
94597ec5308Schristos    category["deprecated_registers"] = ari_eol
94697ec5308Schristos}
94797ec5308Schristos/(^|[^_[:alnum:]])deprecated_registers([^_[:alnum:]]|$)/ {
94897ec5308Schristos    fail("deprecated_registers")
94997ec5308Schristos}
95097ec5308Schristos
95197ec5308SchristosBEGIN { doc["read_pc"] = "\
95297ec5308SchristosReplace READ_PC() with frame_pc_unwind; \
95397ec5308Schristosat present the inferior function call code still uses this"
95497ec5308Schristos    category["read_pc"] = ari_deprecate
95597ec5308Schristos}
95697ec5308Schristos/(^|[^_[:alnum:]])read_pc[[:space:]]*\(/ || \
95797ec5308Schristos/(^|[^_[:alnum:]])set_gdbarch_read_pc[[:space:]]*\(/ || \
95897ec5308Schristos/(^|[^_[:alnum:]])TARGET_READ_PC[[:space:]]*\(/ {
95997ec5308Schristos    fail("read_pc")
96097ec5308Schristos}
96197ec5308Schristos
96297ec5308SchristosBEGIN { doc["write_pc"] = "\
96397ec5308SchristosReplace write_pc() with get_frame_base_address or get_frame_id; \
96497ec5308Schristosat present the inferior function call code still uses this when doing \
96597ec5308Schristosa DECR_PC_AFTER_BREAK"
96697ec5308Schristos    category["write_pc"] = ari_deprecate
96797ec5308Schristos}
96897ec5308Schristos/(^|[^_[:alnum:]])write_pc[[:space:]]*\(/ || \
96997ec5308Schristos/(^|[^_[:alnum:]])TARGET_WRITE_PC[[:space:]]*\(/ {
97097ec5308Schristos    fail("write_pc")
97197ec5308Schristos}
97297ec5308Schristos
97397ec5308SchristosBEGIN { doc["generic_target_write_pc"] = "\
97497ec5308SchristosReplace generic_target_write_pc with a per-architecture implementation, \
97597ec5308Schristosthis relies on PC_REGNUM which is being eliminated"
97697ec5308Schristos    category["generic_target_write_pc"] = ari_regression
97797ec5308Schristos}
97897ec5308Schristos/(^|[^_[:alnum:]])generic_target_write_pc([^_[:alnum:]]|$)/ {
97997ec5308Schristos    fail("generic_target_write_pc")
98097ec5308Schristos}
98197ec5308Schristos
98297ec5308SchristosBEGIN { doc["read_sp"] = "\
98397ec5308SchristosReplace read_sp() with frame_sp_unwind"
98497ec5308Schristos    category["read_sp"] = ari_regression
98597ec5308Schristos}
98697ec5308Schristos/(^|[^_[:alnum:]])read_sp[[:space:]]*\(/ || \
98797ec5308Schristos/(^|[^_[:alnum:]])set_gdbarch_read_sp[[:space:]]*\(/ || \
98897ec5308Schristos/(^|[^_[:alnum:]])TARGET_READ_SP[[:space:]]*\(/ {
98997ec5308Schristos    fail("read_sp")
99097ec5308Schristos}
99197ec5308Schristos
99297ec5308SchristosBEGIN { doc["register_cached"] = "\
99397ec5308SchristosReplace register_cached() with nothing, does not have a regcache parameter"
99497ec5308Schristos    category["register_cached"] = ari_regression
99597ec5308Schristos}
99697ec5308Schristos/(^|[^_[:alnum:]])register_cached[[:space:]]*\(/ {
99797ec5308Schristos    fail("register_cached")
99897ec5308Schristos}
99997ec5308Schristos
100097ec5308SchristosBEGIN { doc["set_register_cached"] = "\
100197ec5308SchristosReplace set_register_cached() with nothing, does not have a regcache parameter"
100297ec5308Schristos    category["set_register_cached"] = ari_regression
100397ec5308Schristos}
100497ec5308Schristos/(^|[^_[:alnum:]])set_register_cached[[:space:]]*\(/ {
100597ec5308Schristos    fail("set_register_cached")
100697ec5308Schristos}
100797ec5308Schristos
100897ec5308Schristos# Print functions: Use versions that either check for buffer overflow
100997ec5308Schristos# or safely allocate a fresh buffer.
101097ec5308Schristos
101197ec5308SchristosBEGIN { doc["sprintf"] = "\
101297ec5308SchristosDo not use sprintf, instead use xsnprintf or xstrprintf"
101397ec5308Schristos    category["sprintf"] = ari_code
101497ec5308Schristos}
101597ec5308Schristos/(^|[^_[:alnum:]])sprintf[[:space:]]*\(/ {
101697ec5308Schristos    fail("sprintf")
101797ec5308Schristos}
101897ec5308Schristos
101997ec5308SchristosBEGIN { doc["vsprintf"] = "\
102097ec5308SchristosDo not use vsprintf(), instead use xstrvprintf"
102197ec5308Schristos    category["vsprintf"] = ari_regression
102297ec5308Schristos}
102397ec5308Schristos/(^|[^_[:alnum:]])vsprintf[[:space:]]*\(/ {
102497ec5308Schristos    fail("vsprintf")
102597ec5308Schristos}
102697ec5308Schristos
102797ec5308SchristosBEGIN { doc["asprintf"] = "\
102897ec5308SchristosDo not use asprintf(), instead use xstrprintf()"
102997ec5308Schristos    category["asprintf"] = ari_regression
103097ec5308Schristos}
103197ec5308Schristos/(^|[^_[:alnum:]])asprintf[[:space:]]*\(/ {
103297ec5308Schristos    fail("asprintf")
103397ec5308Schristos}
103497ec5308Schristos
103597ec5308SchristosBEGIN { doc["vasprintf"] = "\
103697ec5308SchristosDo not use vasprintf(), instead use xstrvprintf"
1037*184b2d41Schristos    fix("vasprintf", "gdbsupport/common-utils.c", 1)
103897ec5308Schristos    category["vasprintf"] = ari_regression
103997ec5308Schristos}
104097ec5308Schristos/(^|[^_[:alnum:]])vasprintf[[:space:]]*\(/ {
104197ec5308Schristos    fail("vasprintf")
104297ec5308Schristos}
104397ec5308Schristos
104415d8e94aSchristosBEGIN { doc["printf_vma"] = "\
104515d8e94aSchristosDo not use printf_vma, instead use paddress or phex_nz"
104615d8e94aSchristos    category["printf_vma"] = ari_code
104715d8e94aSchristos}
104815d8e94aSchristos/(^|[^_[:alnum:]])printf_vma[[:space:]]*\(/ {
104915d8e94aSchristos    fail("printf_vma")
105015d8e94aSchristos}
105115d8e94aSchristos
105215d8e94aSchristosBEGIN { doc["sprintf_vma"] = "\
105315d8e94aSchristosDo not use sprintf_vma, instead use paddress or phex_nz"
105415d8e94aSchristos    category["sprintf_vma"] = ari_code
105515d8e94aSchristos}
105615d8e94aSchristos/(^|[^_[:alnum:]])sprintf_vma[[:space:]]*\(/ {
105715d8e94aSchristos    fail("sprintf_vma")
105815d8e94aSchristos}
105915d8e94aSchristos
106097ec5308Schristos# More generic memory operations
106197ec5308Schristos
106297ec5308SchristosBEGIN { doc["bzero"] = "\
106397ec5308SchristosDo not use bzero(), instead use memset()"
106497ec5308Schristos    category["bzero"] = ari_regression
106597ec5308Schristos}
106697ec5308Schristos/(^|[^_[:alnum:]])bzero[[:space:]]*\(/ {
106797ec5308Schristos    fail("bzero")
106897ec5308Schristos}
106997ec5308Schristos
107097ec5308SchristosBEGIN { doc["strdup"] = "\
107197ec5308SchristosDo not use strdup(), instead use xstrdup()";
107297ec5308Schristos    category["strdup"] = ari_regression
107397ec5308Schristos}
107497ec5308Schristos/(^|[^_[:alnum:]])strdup[[:space:]]*\(/ {
107597ec5308Schristos    fail("strdup")
107697ec5308Schristos}
107797ec5308Schristos
107897ec5308SchristosBEGIN { doc["strsave"] = "\
107997ec5308SchristosDo not use strsave(), instead use xstrdup() et.al."
108097ec5308Schristos    category["strsave"] = ari_regression
108197ec5308Schristos}
108297ec5308Schristos/(^|[^_[:alnum:]])strsave[[:space:]]*\(/ {
108397ec5308Schristos    fail("strsave")
108497ec5308Schristos}
108597ec5308Schristos
108697ec5308Schristos# String compare functions
108797ec5308Schristos
108897ec5308SchristosBEGIN { doc["strnicmp"] = "\
108997ec5308SchristosDo not use strnicmp(), instead use strncasecmp()"
109097ec5308Schristos    category["strnicmp"] = ari_regression
109197ec5308Schristos}
109297ec5308Schristos/(^|[^_[:alnum:]])strnicmp[[:space:]]*\(/ {
109397ec5308Schristos    fail("strnicmp")
109497ec5308Schristos}
109597ec5308Schristos
109697ec5308Schristos# Typedefs that are either redundant or can be reduced to `struct
109797ec5308Schristos# type *''.
109897ec5308Schristos# Must be placed before if assignment otherwise ARI exceptions
109997ec5308Schristos# are not handled correctly.
110097ec5308Schristos
110197ec5308SchristosBEGIN { doc["d_namelen"] = "\
110297ec5308SchristosDo not use dirent.d_namelen, instead use NAMELEN"
110397ec5308Schristos    category["d_namelen"] = ari_regression
110497ec5308Schristos}
110597ec5308Schristos/(^|[^_[:alnum:]])d_namelen([^_[:alnum:]]|$)/ {
110697ec5308Schristos    fail("d_namelen")
110797ec5308Schristos}
110897ec5308Schristos
110997ec5308SchristosBEGIN { doc["strlen d_name"] = "\
111097ec5308SchristosDo not use strlen dirent.d_name, instead use NAMELEN"
111197ec5308Schristos    category["strlen d_name"] = ari_regression
111297ec5308Schristos}
111397ec5308Schristos/(^|[^_[:alnum:]])strlen[[:space:]]*\(.*[^_[:alnum:]]d_name([^_[:alnum:]]|$)/ {
111497ec5308Schristos    fail("strlen d_name")
111597ec5308Schristos}
111697ec5308Schristos
111797ec5308SchristosBEGIN { doc["generic_use_struct_convention"] = "\
111897ec5308SchristosReplace generic_use_struct_convention with nothing, \
111997ec5308SchristosEXTRACT_STRUCT_VALUE_ADDRESS is a predicate"
112097ec5308Schristos    category["generic_use_struct_convention"] = ari_regression
112197ec5308Schristos}
112297ec5308Schristos/(^|[^_[:alnum:]])generic_use_struct_convention([^_[:alnum:]]|$)/ {
112397ec5308Schristos    fail("generic_use_struct_convention")
112497ec5308Schristos}
112597ec5308Schristos
112697ec5308SchristosBEGIN { doc["if assignment"] = "\
112797ec5308SchristosAn IF statement'\''s expression contains an assignment (the GNU coding \
112897ec5308Schristosstandard discourages this)"
112997ec5308Schristos    category["if assignment"] = ari_code
113097ec5308Schristos}
113197ec5308SchristosBEGIN { doc["if clause more than 50 lines"] = "\
113297ec5308SchristosAn IF statement'\''s expression expands over 50 lines"
113397ec5308Schristos    category["if clause more than 50 lines"] = ari_code
113497ec5308Schristos}
113597ec5308Schristos#
113697ec5308Schristos# Accumulate continuation lines
113797ec5308SchristosFNR == 1 {
113897ec5308Schristos    in_if = 0
113997ec5308Schristos}
114097ec5308Schristos
114197ec5308Schristos/(^|[^_[:alnum:]])if / {
114297ec5308Schristos    in_if = 1;
114397ec5308Schristos    if_brace_level = 0;
114497ec5308Schristos    if_cont_p = 0;
114597ec5308Schristos    if_count = 0;
114697ec5308Schristos    if_brace_end_pos = 0;
114797ec5308Schristos    if_full_line = "";
114897ec5308Schristos}
114997ec5308Schristos(in_if)  {
115097ec5308Schristos    # We want everything up to closing brace of same level
115197ec5308Schristos    if_count++;
115297ec5308Schristos    if (if_count > 50) {
115397ec5308Schristos	print "multiline if: " if_full_line $0
115497ec5308Schristos	fail("if clause more than 50 lines")
115597ec5308Schristos	if_brace_level = 0;
115697ec5308Schristos	if_full_line = "";
115797ec5308Schristos    } else {
115897ec5308Schristos	if (if_count == 1) {
115997ec5308Schristos	    i = index($0,"if ");
116097ec5308Schristos	} else {
116197ec5308Schristos	    i = 1;
116297ec5308Schristos	}
116397ec5308Schristos	for (i=i; i <= length($0); i++) {
116497ec5308Schristos	    char = substr($0,i,1);
116597ec5308Schristos	    if (char == "(") { if_brace_level++; }
116697ec5308Schristos	    if (char == ")") {
116797ec5308Schristos		if_brace_level--;
116897ec5308Schristos		if (!if_brace_level) {
116997ec5308Schristos		    if_brace_end_pos = i;
117097ec5308Schristos		    after_if = substr($0,i+1,length($0));
117197ec5308Schristos		    # Do not parse what is following
117297ec5308Schristos		    break;
117397ec5308Schristos		}
117497ec5308Schristos	    }
117597ec5308Schristos	}
117697ec5308Schristos	if (if_brace_level == 0) {
117797ec5308Schristos	    $0 = substr($0,1,i);
117897ec5308Schristos	    in_if = 0;
117997ec5308Schristos	} else {
118097ec5308Schristos	    if_full_line = if_full_line $0;
118197ec5308Schristos	    if_cont_p = 1;
118297ec5308Schristos	    next;
118397ec5308Schristos	}
118497ec5308Schristos    }
118597ec5308Schristos}
118697ec5308Schristos# if we arrive here, we need to concatenate, but we are at brace level 0
118797ec5308Schristos
118897ec5308Schristos(if_brace_end_pos) {
118997ec5308Schristos    $0 = if_full_line substr($0,1,if_brace_end_pos);
119097ec5308Schristos    if (if_count > 1) {
119197ec5308Schristos	# print "IF: multi line " if_count " found at " FILENAME ":" FNR " \"" $0 "\""
119297ec5308Schristos    }
119397ec5308Schristos    if_cont_p = 0;
119497ec5308Schristos    if_full_line = "";
119597ec5308Schristos}
119697ec5308Schristos/(^|[^_[:alnum:]])if .* = / {
119797ec5308Schristos    # print "fail in if " $0
119897ec5308Schristos    fail("if assignment")
119997ec5308Schristos}
120097ec5308Schristos(if_brace_end_pos) {
120197ec5308Schristos    $0 = $0 after_if;
120297ec5308Schristos    if_brace_end_pos = 0;
120397ec5308Schristos    in_if = 0;
120497ec5308Schristos}
120597ec5308Schristos
120697ec5308Schristos# Printout of all found bug
120797ec5308Schristos
120897ec5308SchristosBEGIN {
120997ec5308Schristos    if (print_doc) {
121097ec5308Schristos	for (bug in doc) {
121197ec5308Schristos	    fail(bug)
121297ec5308Schristos	}
121397ec5308Schristos	exit
121497ec5308Schristos    }
121597ec5308Schristos}' "$@"
121697ec5308Schristos
1217