gdb/contrib/ari/gdb_ari.sh - gdb

Functions defined

Source code

  1. #!/bin/sh

  2. # GDB script to list of problems using awk.
  3. #
  4. # Copyright (C) 2002-2015 Free Software Foundation, Inc.
  5. #
  6. # This file is part of GDB.
  7. #
  8. # This program is free software; you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation; either version 3 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with this program.  If not, see <http://www.gnu.org/licenses/>.

  20. # Make certain that the script is not running in an internationalized
  21. # environment.

  22. LANG=C ; export LANG
  23. LC_ALL=C ; export LC_ALL

  24. # Permanent checks take the form:

  25. #     Do not use XXXX, ISO C 90 implies YYYY
  26. #     Do not use XXXX, instead use YYYY''.

  27. # and should never be removed.

  28. # Temporary checks take the form:

  29. #     Replace XXXX with YYYY

  30. # and once they reach zero, can be eliminated.

  31. # FIXME: It should be able to override this on the command line
  32. error="regression"
  33. warning="regression"
  34. ari="regression eol code comment deprecated legacy obsolete gettext"
  35. all="regression eol code comment deprecated legacy obsolete gettext deprecate internal gdbarch macro"
  36. print_doc=0
  37. print_idx=0

  38. usage ()
  39. {
  40.     cat <<EOF 1>&2
  41. Error: $1

  42. Usage:
  43.     $0 --print-doc --print-idx -Wall -Werror -W<category> <file> ...
  44. Options:
  45.   --print-doc    Print a list of all potential problems, then exit.
  46.   --print-idx    Include the problems IDX (index or key) in every message.
  47.   --src=file     Write source lines to file.
  48.   -Werror        Treat all problems as errors.
  49.   -Wall          Report all problems.
  50.   -Wari          Report problems that should be fixed in new code.
  51.   -W<category>   Report problems in the specifed category.  Vaid categories
  52.                  are: ${all}
  53. EOF
  54.     exit 1
  55. }


  56. # Parse the various options
  57. Woptions=
  58. srclines=""
  59. while test $# -gt 0
  60. do
  61.     case "$1" in
  62.     -Wall ) Woptions="${all}" ;;
  63.     -Wari ) Woptions="${ari}" ;;
  64.     -Werror ) Werror=1 ;;
  65.     -W* ) Woptions="${Woptions} `echo x$1 | sed -e 's/x-W//'`" ;;
  66.     --print-doc ) print_doc=1 ;;
  67.     --print-idx ) print_idx=1 ;;
  68.     --src=* ) srclines="`echo $1 | sed -e 's/--src=/srclines=\"/'`\"" ;;
  69.     -- ) shift ; break ;;
  70.     - ) break ;;
  71.     -* ) usage "$1: unknown option" ;;
  72.     * ) break ;;
  73.     esac
  74.     shift
  75. done
  76. if test -n "$Woptions" ; then
  77.     warning="$Woptions"
  78.     error=
  79. fi


  80. # -Werror implies treating all warnings as errors.
  81. if test -n "${Werror}" ; then
  82.     error="${error} ${warning}"
  83. fi


  84. # Validate all errors and warnings.
  85. for w in ${warning} ${error}
  86. do
  87.     case " ${all} " in
  88.     *" ${w} "* ) ;;
  89.     * ) usage "Unknown option -W${w}" ;;
  90.     esac
  91. done


  92. # make certain that there is at least one file.
  93. if test $# -eq 0 -a ${print_doc} = 0
  94. then
  95.     usage "Missing file."
  96. fi


  97. # Convert the errors/warnings into corresponding array entries.
  98. for a in ${all}
  99. do
  100.     aris="${aris} ari_${a} = \"${a}\";"
  101. done
  102. for w in ${warning}
  103. do
  104.     warnings="${warnings} warning[ari_${w}] = 1;"
  105. done
  106. for e in ${error}
  107. do
  108.     errors="${errors} error[ari_${e}]  = 1;"
  109. done

  110. if [ "$AWK" = "" ] ; then
  111.   AWK=awk
  112. fi

  113. ${AWK} -- '
  114. BEGIN {
  115.     # NOTE, for a per-file begin use "FNR == 1".
  116.     '"${aris}"'
  117.     '"${errors}"'
  118.     '"${warnings}"'
  119.     '"${srclines}"'
  120.     print_doc =  '$print_doc'
  121.     print_idx =  '$print_idx'
  122.     PWD = "'`pwd`'"
  123. }

  124. # Print the error message for BUG.  Append SUPLEMENT if non-empty.
  125. function print_bug(file,line,prefix,category,bug,doc,supplement, suffix,idx) {
  126.     if (print_idx) {
  127.         idx = bug ": "
  128.     } else {
  129.         idx = ""
  130.     }
  131.     if (supplement) {
  132.         suffix = " (" supplement ")"
  133.     } else {
  134.         suffix = ""
  135.     }
  136.     # ari.*.bug: <FILE>:<LINE>: <CATEGORY>: <BUG>: <DOC>
  137.     print file ":" line ": " prefix category ": " idx doc suffix
  138.     if (srclines != "") {
  139.         print file ":" line ":" $0 >> srclines
  140.     }
  141. }

  142. function fix(bug,file,count) {
  143.     skip[bug, file] = count
  144.     skipped[bug, file] = 0
  145. }

  146. function fail(bug,supplement) {
  147.     if (doc[bug] == "") {
  148.         print_bug("", 0, "internal: ", "internal", "internal", "Missing doc for bug " bug)
  149.         exit
  150.     }
  151.     if (category[bug] == "") {
  152.         print_bug("", 0, "internal: ", "internal", "internal", "Missing category for bug " bug)
  153.         exit
  154.     }

  155.     if (ARI_OK == bug) {
  156.         return
  157.     }
  158.     # Trim the filename down to just DIRECTORY/FILE so that it can be
  159.     # robustly used by the FIX code.

  160.     if (FILENAME ~ /^\//) {
  161.         canonicalname = FILENAME
  162.     } else {
  163.         canonicalname = PWD "/" FILENAME
  164.     }
  165.     shortname = gensub (/^.*\/([^\\]*\/[^\\]*)$/, "\\1", 1, canonicalname)

  166.     skipped[bug, shortname]++
  167.     if (skip[bug, shortname] >= skipped[bug, shortname]) {
  168.         # print FILENAME, FNR, skip[bug, FILENAME], skipped[bug, FILENAME], bug
  169.         # Do nothing
  170.     } else if (error[category[bug]]) {
  171.         # ari.*.bug: <FILE>:<LINE>: <CATEGORY>: <BUG>: <DOC>
  172.         print_bug(FILENAME, FNR, "", category[bug], bug, doc[bug], supplement)
  173.     } else if (warning[category[bug]]) {
  174.         # ari.*.bug: <FILE>:<LINE>: <CATEGORY>: <BUG>: <DOC>
  175.         print_bug(FILENAME, FNR, "warning: ", category[bug], bug, doc[bug], supplement)
  176.     }
  177. }

  178. FNR == 1 {
  179.     seen[FILENAME] = 1
  180.     if (match(FILENAME, "\\.[ly]$")) {
  181.       # FILENAME is a lex or yacc source
  182.       is_yacc_or_lex = 1
  183.     }
  184.     else {
  185.       is_yacc_or_lex = 0
  186.     }
  187. }
  188. END {
  189.     if (print_idx) {
  190.         idx = bug ": "
  191.     } else {
  192.         idx = ""
  193.     }
  194.     # Did we do only a partial skip?
  195.     for (bug_n_file in skip) {
  196.         split (bug_n_file, a, SUBSEP)
  197.         bug = a[1]
  198.         file = a[2]
  199.         if (seen[file] && (skipped[bug_n_file] < skip[bug_n_file])) {
  200.             # ari.*.bug: <FILE>:<LINE>: <CATEGORY>: <BUG>: <DOC>
  201.             b = file " missing " bug
  202.             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])
  203.         }
  204.     }
  205. }


  206. # Skip OBSOLETE lines
  207. /(^|[^_[:alnum:]])OBSOLETE([^_[:alnum:]]|$)/ { next; }

  208. # Skip ARI lines

  209. BEGIN {
  210.     ARI_OK = ""
  211. }

  212. /\/\* ARI:[[:space:]]*(.*)[[:space:]]*\*\// {
  213.     ARI_OK = gensub(/^.*\/\* ARI:[[:space:]]*(.*[^[:space:]])[[:space:]]*\*\/.*$/, "\\1", 1, $0)
  214.     # print "ARI line found \"" $0 "\""
  215.     # print "ARI_OK \"" ARI_OK "\""
  216. }
  217. ! /\/\* ARI:[[:space:]]*(.*)[[:space:]]*\*\// {
  218.     ARI_OK = ""
  219. }


  220. # Things in comments

  221. BEGIN { doc["ARGSUSED"] = "\
  222. Do not use ARGSUSED, unnecessary"
  223.     category["ARGSUSED"] = ari_regression
  224. }
  225. /(^|[^_[:alnum:]])ARGSUSED([^_[:alnum:]]|$)/ {
  226.     fail("ARGSUSED")
  227. }


  228. # SNIP - Strip out comments - SNIP

  229. FNR == 1 {
  230.     comment_p = 0
  231. }
  232. comment_p && /\*\// { gsub (/^([^\*]|\*+[^\/\*])*\*+\//, " "); comment_p = 0; }
  233. comment_p { next; }
  234. !comment_p { gsub (/\/\*([^\*]|\*+[^\/\*])*\*+\//, " "); }
  235. !comment_p && /(^|[^"])\/\*/ { gsub (/\/\*.*$/, " "); comment_p = 1; }


  236. BEGIN { doc["_ markup"] = "\
  237. All messages should be marked up with _."
  238.     category["_ markup"] = ari_gettext
  239. }
  240. /^[^"]*[[:space:]](warning|error|error_no_arg|query|perror_with_name)[[:space:]]*\([^_\(a-z]/ {
  241.     if (! /\("%s"/) {
  242.         fail("_ markup")
  243.     }
  244. }

  245. BEGIN { doc["trailing new line"] = "\
  246. A message should not have a trailing new line"
  247.     category["trailing new line"] = ari_gettext
  248. }
  249. /(^|[^_[:alnum:]])(warning|error)[[:space:]]*\(_\(".*\\n"\)[\),]/ {
  250.     fail("trailing new line")
  251. }

  252. # Include files for which GDB has a custom version.

  253. BEGIN { doc["assert.h"] = "\
  254. Do not include assert.h, instead include \"gdb_assert.h\"";
  255.     category["assert.h"] = ari_regression
  256.     fix("assert.h", "gdb/gdb_assert.h", 0) # it does not use it
  257. }
  258. /^#[[:space:]]*include[[:space:]]+.assert\.h./ {
  259.     fail("assert.h")
  260. }

  261. BEGIN { doc["regex.h"] = "\
  262. Do not include regex.h, instead include gdb_regex.h"
  263.     category["regex.h"] = ari_regression
  264.     fix("regex.h", "gdb/gdb_regex.h", 1)
  265. }
  266. /^#[[:space:]]*include[[:space:]]*.regex\.h./ {
  267.     fail("regex.h")
  268. }

  269. BEGIN { doc["xregex.h"] = "\
  270. Do not include xregex.h, instead include gdb_regex.h"
  271.     category["xregex.h"] = ari_regression
  272.     fix("xregex.h", "gdb/gdb_regex.h", 1)
  273. }
  274. /^#[[:space:]]*include[[:space:]]*.xregex\.h./ {
  275.     fail("xregex.h")
  276. }

  277. BEGIN { doc["gnu-regex.h"] = "\
  278. Do not include gnu-regex.h, instead include gdb_regex.h"
  279.     category["gnu-regex.h"] = ari_regression
  280. }
  281. /^#[[:space:]]*include[[:space:]]*.gnu-regex\.h./ {
  282.     fail("gnu regex.h")
  283. }

  284. BEGIN { doc["wait.h"] = "\
  285. Do not include wait.h or sys/wait.h, instead include gdb_wait.h"
  286.     fix("wait.h", "common/gdb_wait.h", 2);
  287.     category["wait.h"] = ari_regression
  288. }
  289. /^#[[:space:]]*include[[:space:]]*.wait\.h./ \
  290. || /^#[[:space:]]*include[[:space:]]*.sys\/wait\.h./ {
  291.     fail("wait.h")
  292. }

  293. BEGIN { doc["vfork.h"] = "\
  294. Do not include vfork.h, instead include gdb_vfork.h"
  295.     fix("vfork.h", "gdb/gdb_vfork.h", 1);
  296.     category["vfork.h"] = ari_regression
  297. }
  298. /^#[[:space:]]*include[[:space:]]*.vfork\.h./ {
  299.     fail("vfork.h")
  300. }

  301. BEGIN { doc["error not internal-warning"] = "\
  302. Do not use error(\"internal-warning\"), instead use internal_warning"
  303.     category["error not internal-warning"] = ari_regression
  304. }
  305. /error.*\"[Ii]nternal.warning/ {
  306.     fail("error not internal-warning")
  307. }

  308. BEGIN { doc["%p"] = "\
  309. Do not use printf(\"%p\"), instead use printf(\"%s\",paddr()) to dump a \
  310. target address, or host_address_to_string() for a host address"
  311.     category["%p"] = ari_code
  312. }
  313. /%p/ && !/%prec/ {
  314.     fail("%p")
  315. }

  316. BEGIN { doc["%ll"] = "\
  317. Do not use printf(\"%ll\"), instead use printf(\"%s\",phex()) to dump a \
  318. `long long'\'' value"
  319.     category["%ll"] = ari_code
  320. }
  321. # Allow %ll in scanf
  322. /%[0-9]*ll/ && !/scanf \(.*%[0-9]*ll/ {
  323.     fail("%ll")
  324. }


  325. # SNIP - Strip out strings - SNIP

  326. # Test on top.c, scm-valprint.c, remote-rdi.c, ada-lang.c
  327. FNR == 1 {
  328.     string_p = 0
  329.     trace_string = 0
  330. }
  331. # Strip escaped characters.
  332. { gsub(/\\./, "."); }
  333. # Strip quoted quotes.
  334. { gsub(/'\''.'\''/, "'\''.'\''"); }
  335. # End of multi-line string
  336. string_p && /\"/ {
  337.     if (trace_string) print "EOS:" FNR, $0;
  338.     gsub (/^[^\"]*\"/, "'\''");
  339.     string_p = 0;
  340. }
  341. # Middle of multi-line string, discard line.
  342. string_p {
  343.     if (trace_string) print "MOS:" FNR, $0;
  344.     $0 = ""
  345. }
  346. # Strip complete strings from the middle of the line
  347. !string_p && /\"[^\"]*\"/ {
  348.     if (trace_string) print "COS:" FNR, $0;
  349.     gsub (/\"[^\"]*\"/, "'\''");
  350. }
  351. # Start of multi-line string
  352. BEGIN { doc["multi-line string"] = "\
  353. Multi-line string must have the newline escaped"
  354.     category["multi-line string"] = ari_regression
  355. }
  356. !string_p && /\"/ {
  357.     if (trace_string) print "SOS:" FNR, $0;
  358.     if (/[^\\]$/) {
  359.         fail("multi-line string")
  360.     }
  361.     gsub (/\"[^\"]*$/, "'\''");
  362.     string_p = 1;
  363. }
  364. # { print }

  365. # Multi-line string
  366. string_p &&

  367. # Accumulate continuation lines
  368. FNR == 1 {
  369.     cont_p = 0
  370. }
  371. !cont_p { full_line = ""; }
  372. /[^\\]\\$/ { gsub (/\\$/, ""); full_line = full_line $0; cont_p = 1; next; }
  373. cont_p { $0 = full_line $0; cont_p = 0; full_line = ""; }


  374. # GDB uses ISO C 90.  Check for any non pure ISO C 90 code

  375. BEGIN { doc["PARAMS"] = "\
  376. Do not use PARAMS(), ISO C 90 implies prototypes"
  377.     category["PARAMS"] = ari_regression
  378. }
  379. /(^|[^_[:alnum:]])PARAMS([^_[:alnum:]]|$)/ {
  380.     fail("PARAMS")
  381. }

  382. BEGIN { doc["__func__"] = "\
  383. Do not use __func__, ISO C 90 does not support this macro"
  384.     category["__func__"] = ari_regression
  385.     fix("__func__", "common/gdb_assert.h", 1)
  386. }
  387. /(^|[^_[:alnum:]])__func__([^_[:alnum:]]|$)/ {
  388.     fail("__func__")
  389. }

  390. BEGIN { doc["__FUNCTION__"] = "\
  391. Do not use __FUNCTION__, ISO C 90 does not support this macro"
  392.     category["__FUNCTION__"] = ari_regression
  393. }
  394. /(^|[^_[:alnum:]])__FUNCTION__([^_[:alnum:]]|$)/ {
  395.     fail("__FUNCTION__")
  396. }

  397. BEGIN { doc["__CYGWIN32__"] = "\
  398. Do not use __CYGWIN32__, instead use __CYGWIN__ or, better, an explicit \
  399. autoconf tests"
  400.     category["__CYGWIN32__"] = ari_regression
  401. }
  402. /(^|[^_[:alnum:]])__CYGWIN32__([^_[:alnum:]]|$)/ {
  403.     fail("__CYGWIN32__")
  404. }

  405. BEGIN { doc["PTR"] = "\
  406. Do not use PTR, ISO C 90 implies `void *'\''"
  407.     category["PTR"] = ari_regression
  408.     #fix("PTR", "gdb/utils.c", 6)
  409. }
  410. /(^|[^_[:alnum:]])PTR([^_[:alnum:]]|$)/ {
  411.     fail("PTR")
  412. }

  413. BEGIN { doc["UCASE function"] = "\
  414. Function name is uppercase."
  415.     category["UCASE function"] = ari_code
  416.     possible_UCASE = 0
  417.     UCASE_full_line = ""
  418. }
  419. (possible_UCASE) {
  420.     if (ARI_OK == "UCASE function") {
  421.         possible_UCASE = 0
  422.     }
  423.     # Closing brace found?
  424.     else if (UCASE_full_line ~ \
  425.         /^[A-Z][[:alnum:]_]*[[:space:]]*\([^()]*\).*$/) {
  426.         if ((UCASE_full_line ~ \
  427.             /^[A-Z][[:alnum:]_]*[[:space:]]*\([^()]*\)[[:space:]]*$/) \
  428.             && ($0 ~ /^\{/) && (is_yacc_or_lex == 0)) {
  429.             store_FNR = FNR
  430.             FNR = possible_FNR
  431.             store_0 = $0;
  432.             $0 = UCASE_full_line;
  433.             fail("UCASE function")
  434.             FNR = store_FNR
  435.             $0 = store_0;
  436.         }
  437.         possible_UCASE = 0
  438.         UCASE_full_line = ""
  439.     } else {
  440.         UCASE_full_line = UCASE_full_line $0;
  441.     }
  442. }
  443. /^[A-Z][[:alnum:]_]*[[:space:]]*\([^()]*(|\))[[:space:]]*$/ {
  444.     possible_UCASE = 1
  445.     if (ARI_OK == "UCASE function") {
  446.         possible_UCASE = 0
  447.     }
  448.     possible_FNR = FNR
  449.     UCASE_full_line = $0
  450. }


  451. BEGIN { doc["editCase function"] = "\
  452. Function name starts lower case but has uppercased letters."
  453.     category["editCase function"] = ari_code
  454.     possible_editCase = 0
  455.     editCase_full_line = ""
  456. }
  457. (possible_editCase) {
  458.     if (ARI_OK == "editCase function") {
  459.         possible_editCase = 0
  460.     }
  461.     # Closing brace found?
  462.     else if (editCase_full_line ~ \
  463. /^[a-z][a-z0-9_]*[A-Z][a-z0-9A-Z_]*[[:space:]]*\([^()]*\).*$/) {
  464.         if ((editCase_full_line ~ \
  465. /^[a-z][a-z0-9_]*[A-Z][a-z0-9A-Z_]*[[:space:]]*\([^()]*\)[[:space:]]*$/) \
  466.             && ($0 ~ /^\{/) && (is_yacc_or_lex == 0)) {
  467.             store_FNR = FNR
  468.             FNR = possible_FNR
  469.             store_0 = $0;
  470.             $0 = editCase_full_line;
  471.             fail("editCase function")
  472.             FNR = store_FNR
  473.             $0 = store_0;
  474.         }
  475.         possible_editCase = 0
  476.         editCase_full_line = ""
  477.     } else {
  478.         editCase_full_line = editCase_full_line $0;
  479.     }
  480. }
  481. /^[a-z][a-z0-9_]*[A-Z][a-z0-9A-Z_]*[[:space:]]*\([^()]*(|\))[[:space:]]*$/ {
  482.     possible_editCase = 1
  483.     if (ARI_OK == "editCase function") {
  484.         possible_editCase = 0
  485.     }
  486.     possible_FNR = FNR
  487.     editCase_full_line = $0
  488. }

  489. # Only function implementation should be on first column
  490. BEGIN { doc["function call in first column"] = "\
  491. Function name in first column should be restricted to function implementation"
  492.     category["function call in first column"] = ari_code
  493. }
  494. /^[a-z][a-z0-9_]*[[:space:]]*\((|[^*][^()]*)\)[[:space:]]*[^ \t]+/ {
  495.     fail("function call in first column")
  496. }


  497. # Functions without any parameter should have (void)
  498. # after their name not simply ().
  499. BEGIN { doc["no parameter function"] = "\
  500. Function having no parameter should be declared with funcname (void)."
  501.     category["no parameter function"] = ari_code
  502. }
  503. /^[a-zA-Z][a-z0-9A-Z_]*[[:space:]]*\(\)/ {
  504.     fail("no parameter function")
  505. }

  506. BEGIN { doc["hash"] = "\
  507. Do not use ` #...'\'', instead use `#...'\''(some compilers only correctly \
  508. parse a C preprocessor directive when `#'\'' is the first character on \
  509. the line)"
  510.     category["hash"] = ari_regression
  511. }
  512. /^[[:space:]]+#/ {
  513.     fail("hash")
  514. }

  515. BEGIN { doc["OP eol"] = "\
  516. Do not use &&, or || at the end of a line"
  517.     category["OP eol"] = ari_code
  518. }
  519. # * operator needs a special treatment as it can be a
  520. # valid end of line for a pointer type definition
  521. # Only catch case where an assignment or an opening brace is present
  522. /(\|\||\&\&|==|!=|[[:space:]][+\-\/])[[:space:]]*$/ \
  523. || /(\(|=)[[:space:]].*[[:space:]]\*[[:space:]]*$/ {
  524.     fail("OP eol")
  525. }

  526. BEGIN { doc["strerror"] = "\
  527. Do not use strerror(), instead use safe_strerror()"
  528.     category["strerror"] = ari_regression
  529.     fix("strerror", "gdb/gdb_string.h", 1)
  530.     fix("strerror", "gdb/mingw-hdep.c", 1)
  531.     fix("strerror", "gdb/posix-hdep.c", 1)
  532. }
  533. /(^|[^_[:alnum:]])strerror[[:space:]]*\(/ {
  534.     fail("strerror")
  535. }

  536. BEGIN { doc["long long"] = "\
  537. Do not use `long long'\'', instead use LONGEST"
  538.     category["long long"] = ari_code
  539.     # defs.h needs two such patterns for LONGEST and ULONGEST definitions
  540.     fix("long long", "gdb/defs.h", 2)
  541. }
  542. /(^|[^_[:alnum:]])long[[:space:]]+long([^_[:alnum:]]|$)/ {
  543.     fail("long long")
  544. }

  545. BEGIN { doc["ATTRIBUTE_UNUSED"] = "\
  546. Do not use ATTRIBUTE_UNUSED, do not bother (GDB is compiled with -Werror and, \
  547. consequently, is not able to tolerate false warnings.  Since -Wunused-param \
  548. produces such warnings, neither that warning flag nor ATTRIBUTE_UNUSED \
  549. are used by GDB"
  550.     category["ATTRIBUTE_UNUSED"] = ari_regression
  551. }
  552. /(^|[^_[:alnum:]])ATTRIBUTE_UNUSED([^_[:alnum:]]|$)/ {
  553.     fail("ATTRIBUTE_UNUSED")
  554. }

  555. BEGIN { doc["ATTR_FORMAT"] = "\
  556. Do not use ATTR_FORMAT, use ATTRIBUTE_PRINTF instead"
  557.     category["ATTR_FORMAT"] = ari_regression
  558. }
  559. /(^|[^_[:alnum:]])ATTR_FORMAT([^_[:alnum:]]|$)/ {
  560.     fail("ATTR_FORMAT")
  561. }

  562. BEGIN { doc["ATTR_NORETURN"] = "\
  563. Do not use ATTR_NORETURN, use ATTRIBUTE_NORETURN instead"
  564.     category["ATTR_NORETURN"] = ari_regression
  565. }
  566. /(^|[^_[:alnum:]])ATTR_NORETURN([^_[:alnum:]]|$)/ {
  567.     fail("ATTR_NORETURN")
  568. }

  569. BEGIN { doc["NORETURN"] = "\
  570. Do not use NORETURN, use ATTRIBUTE_NORETURN instead"
  571.     category["NORETURN"] = ari_regression
  572. }
  573. /(^|[^_[:alnum:]])NORETURN([^_[:alnum:]]|$)/ {
  574.     fail("NORETURN")
  575. }


  576. # General problems

  577. BEGIN { doc["multiple messages"] = "\
  578. Do not use multiple calls to warning or error, instead use a single call"
  579.     category["multiple messages"] = ari_gettext
  580. }
  581. FNR == 1 {
  582.     warning_fnr = -1
  583. }
  584. /(^|[^_[:alnum:]])(warning|error)[[:space:]]*\(/ {
  585.     if (FNR == warning_fnr + 1) {
  586.         fail("multiple messages")
  587.     } else {
  588.         warning_fnr = FNR
  589.     }
  590. }

  591. # Commented out, but left inside sources, just in case.
  592. # BEGIN { doc["inline"] = "\
  593. # Do not use the inline attribute; \
  594. # since the compiler generally ignores this, better algorithm selection \
  595. # is needed to improved performance"
  596. #    category["inline"] = ari_code
  597. # }
  598. # /(^|[^_[:alnum:]])inline([^_[:alnum:]]|$)/ {
  599. #     fail("inline")
  600. # }

  601. # This test is obsolete as this type
  602. # has been deprecated and finally suppressed from GDB sources
  603. #BEGIN { doc["obj_private"] = "\
  604. #Replace obj_private with objfile_data"
  605. #    category["obj_private"] = ari_obsolete
  606. #}
  607. #/(^|[^_[:alnum:]])obj_private([^_[:alnum:]]|$)/ {
  608. #    fail("obj_private")
  609. #}

  610. BEGIN { doc["abort"] = "\
  611. Do not use abort, instead use internal_error; GDB should never abort"
  612.     category["abort"] = ari_regression
  613.     fix("abort", "gdb/utils.c", 3)
  614. }
  615. /(^|[^_[:alnum:]])abort[[:space:]]*\(/ {
  616.     fail("abort")
  617. }

  618. BEGIN { doc["basename"] = "\
  619. Do not use basename, instead use lbasename"
  620.     category["basename"] = ari_regression
  621. }
  622. /(^|[^_[:alnum:]])basename[[:space:]]*\(/ {
  623.     fail("basename")
  624. }

  625. BEGIN { doc["assert"] = "\
  626. Do not use assert, instead use gdb_assert or internal_error; assert \
  627. calls abort and GDB should never call abort"
  628.     category["assert"] = ari_regression
  629. }
  630. /(^|[^_[:alnum:]])assert[[:space:]]*\(/ {
  631.     fail("assert")
  632. }

  633. BEGIN { doc["TARGET_HAS_HARDWARE_WATCHPOINTS"] = "\
  634. Replace TARGET_HAS_HARDWARE_WATCHPOINTS with nothing, not needed"
  635.     category["TARGET_HAS_HARDWARE_WATCHPOINTS"] = ari_regression
  636. }
  637. /(^|[^_[:alnum:]])TARGET_HAS_HARDWARE_WATCHPOINTS([^_[:alnum:]]|$)/ {
  638.     fail("TARGET_HAS_HARDWARE_WATCHPOINTS")
  639. }

  640. BEGIN { doc["ADD_SHARED_SYMBOL_FILES"] = "\
  641. Replace ADD_SHARED_SYMBOL_FILES with nothing, not needed?"
  642.     category["ADD_SHARED_SYMBOL_FILES"] = ari_regression
  643. }
  644. /(^|[^_[:alnum:]])ADD_SHARED_SYMBOL_FILES([^_[:alnum:]]|$)/ {
  645.     fail("ADD_SHARED_SYMBOL_FILES")
  646. }

  647. BEGIN { doc["SOLIB_ADD"] = "\
  648. Replace SOLIB_ADD with nothing, not needed?"
  649.     category["SOLIB_ADD"] = ari_regression
  650. }
  651. /(^|[^_[:alnum:]])SOLIB_ADD([^_[:alnum:]]|$)/ {
  652.     fail("SOLIB_ADD")
  653. }

  654. BEGIN { doc["SOLIB_CREATE_INFERIOR_HOOK"] = "\
  655. Replace SOLIB_CREATE_INFERIOR_HOOK with nothing, not needed?"
  656.     category["SOLIB_CREATE_INFERIOR_HOOK"] = ari_regression
  657. }
  658. /(^|[^_[:alnum:]])SOLIB_CREATE_INFERIOR_HOOK([^_[:alnum:]]|$)/ {
  659.     fail("SOLIB_CREATE_INFERIOR_HOOK")
  660. }

  661. BEGIN { doc["SOLIB_LOADED_LIBRARY_PATHNAME"] = "\
  662. Replace SOLIB_LOADED_LIBRARY_PATHNAME with nothing, not needed?"
  663.     category["SOLIB_LOADED_LIBRARY_PATHNAME"] = ari_regression
  664. }
  665. /(^|[^_[:alnum:]])SOLIB_LOADED_LIBRARY_PATHNAME([^_[:alnum:]]|$)/ {
  666.     fail("SOLIB_LOADED_LIBRARY_PATHNAME")
  667. }

  668. BEGIN { doc["REGISTER_U_ADDR"] = "\
  669. Replace REGISTER_U_ADDR with nothing, not needed?"
  670.     category["REGISTER_U_ADDR"] = ari_regression
  671. }
  672. /(^|[^_[:alnum:]])REGISTER_U_ADDR([^_[:alnum:]]|$)/ {
  673.     fail("REGISTER_U_ADDR")
  674. }

  675. BEGIN { doc["PROCESS_LINENUMBER_HOOK"] = "\
  676. Replace PROCESS_LINENUMBER_HOOK with nothing, not needed?"
  677.     category["PROCESS_LINENUMBER_HOOK"] = ari_regression
  678. }
  679. /(^|[^_[:alnum:]])PROCESS_LINENUMBER_HOOK([^_[:alnum:]]|$)/ {
  680.     fail("PROCESS_LINENUMBER_HOOK")
  681. }

  682. BEGIN { doc["PC_SOLIB"] = "\
  683. Replace PC_SOLIB with nothing, not needed?"
  684.     category["PC_SOLIB"] = ari_regression
  685. }
  686. /(^|[^_[:alnum:]])PC_SOLIB([^_[:alnum:]]|$)/ {
  687.     fail("PC_SOLIB")
  688. }

  689. BEGIN { doc["IN_SOLIB_DYNSYM_RESOLVE_CODE"] = "\
  690. Replace IN_SOLIB_DYNSYM_RESOLVE_CODE with nothing, not needed?"
  691.     category["IN_SOLIB_DYNSYM_RESOLVE_CODE"] = ari_regression
  692. }
  693. /(^|[^_[:alnum:]])IN_SOLIB_DYNSYM_RESOLVE_CODE([^_[:alnum:]]|$)/ {
  694.     fail("IN_SOLIB_DYNSYM_RESOLVE_CODE")
  695. }

  696. BEGIN { doc["GCC_COMPILED_FLAG_SYMBOL"] = "\
  697. Replace GCC_COMPILED_FLAG_SYMBOL with nothing, not needed?"
  698.     category["GCC_COMPILED_FLAG_SYMBOL"] = ari_deprecate
  699. }
  700. /(^|[^_[:alnum:]])GCC_COMPILED_FLAG_SYMBOL([^_[:alnum:]]|$)/ {
  701.     fail("GCC_COMPILED_FLAG_SYMBOL")
  702. }

  703. BEGIN { doc["GCC2_COMPILED_FLAG_SYMBOL"] = "\
  704. Replace GCC2_COMPILED_FLAG_SYMBOL with nothing, not needed?"
  705.     category["GCC2_COMPILED_FLAG_SYMBOL"] = ari_deprecate
  706. }
  707. /(^|[^_[:alnum:]])GCC2_COMPILED_FLAG_SYMBOL([^_[:alnum:]]|$)/ {
  708.     fail("GCC2_COMPILED_FLAG_SYMBOL")
  709. }

  710. BEGIN { doc["FUNCTION_EPILOGUE_SIZE"] = "\
  711. Replace FUNCTION_EPILOGUE_SIZE with nothing, not needed?"
  712.     category["FUNCTION_EPILOGUE_SIZE"] = ari_regression
  713. }
  714. /(^|[^_[:alnum:]])FUNCTION_EPILOGUE_SIZE([^_[:alnum:]]|$)/ {
  715.     fail("FUNCTION_EPILOGUE_SIZE")
  716. }

  717. BEGIN { doc["HAVE_VFORK"] = "\
  718. Do not use HAVE_VFORK, instead include \"gdb_vfork.h\" and call vfork() \
  719. unconditionally"
  720.     category["HAVE_VFORK"] = ari_regression
  721. }
  722. /(^|[^_[:alnum:]])HAVE_VFORK([^_[:alnum:]]|$)/ {
  723.     fail("HAVE_VFORK")
  724. }

  725. BEGIN { doc["bcmp"] = "\
  726. Do not use bcmp(), ISO C 90 implies memcmp()"
  727.     category["bcmp"] = ari_regression
  728. }
  729. /(^|[^_[:alnum:]])bcmp[[:space:]]*\(/ {
  730.     fail("bcmp")
  731. }

  732. BEGIN { doc["setlinebuf"] = "\
  733. Do not use setlinebuf(), ISO C 90 implies setvbuf()"
  734.     category["setlinebuf"] = ari_regression
  735. }
  736. /(^|[^_[:alnum:]])setlinebuf[[:space:]]*\(/ {
  737.     fail("setlinebuf")
  738. }

  739. BEGIN { doc["bcopy"] = "\
  740. Do not use bcopy(), ISO C 90 implies memcpy() and memmove()"
  741.     category["bcopy"] = ari_regression
  742. }
  743. /(^|[^_[:alnum:]])bcopy[[:space:]]*\(/ {
  744.     fail("bcopy")
  745. }

  746. BEGIN { doc["get_frame_base"] = "\
  747. Replace get_frame_base with get_frame_id, get_frame_base_address, \
  748. get_frame_locals_address, or get_frame_args_address."
  749.     category["get_frame_base"] = ari_obsolete
  750. }
  751. /(^|[^_[:alnum:]])get_frame_base([^_[:alnum:]]|$)/ {
  752.     fail("get_frame_base")
  753. }

  754. BEGIN { doc["floatformat_to_double"] = "\
  755. Do not use floatformat_to_double() from libierty, \
  756. instead use floatformat_to_doublest()"
  757.     fix("floatformat_to_double", "gdb/doublest.c", 1)
  758.     category["floatformat_to_double"] = ari_regression
  759. }
  760. /(^|[^_[:alnum:]])floatformat_to_double[[:space:]]*\(/ {
  761.     fail("floatformat_to_double")
  762. }

  763. BEGIN { doc["floatformat_from_double"] = "\
  764. Do not use floatformat_from_double() from libierty, \
  765. instead use floatformat_from_doublest()"
  766.     category["floatformat_from_double"] = ari_regression
  767. }
  768. /(^|[^_[:alnum:]])floatformat_from_double[[:space:]]*\(/ {
  769.     fail("floatformat_from_double")
  770. }

  771. BEGIN { doc["BIG_ENDIAN"] = "\
  772. Do not use BIG_ENDIAN, instead use BFD_ENDIAN_BIG"
  773.     category["BIG_ENDIAN"] = ari_regression
  774. }
  775. /(^|[^_[:alnum:]])BIG_ENDIAN([^_[:alnum:]]|$)/ {
  776.     fail("BIG_ENDIAN")
  777. }

  778. BEGIN { doc["LITTLE_ENDIAN"] = "\
  779. Do not use LITTLE_ENDIAN, instead use BFD_ENDIAN_LITTLE";
  780.     category["LITTLE_ENDIAN"] = ari_regression
  781. }
  782. /(^|[^_[:alnum:]])LITTLE_ENDIAN([^_[:alnum:]]|$)/ {
  783.     fail("LITTLE_ENDIAN")
  784. }

  785. BEGIN { doc["BIG_ENDIAN"] = "\
  786. Do not use BIG_ENDIAN, instead use BFD_ENDIAN_BIG"
  787.     category["BIG_ENDIAN"] = ari_regression
  788. }
  789. /(^|[^_[:alnum:]])BIG_ENDIAN([^_[:alnum:]]|$)/ {
  790.     fail("BIG_ENDIAN")
  791. }

  792. BEGIN { doc["sec_ptr"] = "\
  793. Instead of sec_ptr, use struct bfd_section";
  794.     category["sec_ptr"] = ari_regression
  795. }
  796. /(^|[^_[:alnum:]])sec_ptr([^_[:alnum:]]|$)/ {
  797.     fail("sec_ptr")
  798. }

  799. BEGIN { doc["frame_unwind_unsigned_register"] = "\
  800. Replace frame_unwind_unsigned_register with frame_unwind_register_unsigned"
  801.     category["frame_unwind_unsigned_register"] = ari_regression
  802. }
  803. /(^|[^_[:alnum:]])frame_unwind_unsigned_register([^_[:alnum:]]|$)/ {
  804.     fail("frame_unwind_unsigned_register")
  805. }

  806. BEGIN { doc["frame_register_read"] = "\
  807. Replace frame_register_read() with get_frame_register(), or \
  808. possibly introduce a new method safe_get_frame_register()"
  809.     category["frame_register_read"] = ari_obsolete
  810. }
  811. /(^|[^_[:alnum:]])frame_register_read([^_[:alnum:]]|$)/ {
  812.     fail("frame_register_read")
  813. }

  814. BEGIN { doc["read_register"] = "\
  815. Replace read_register() with regcache_read() et.al."
  816.     category["read_register"] = ari_regression
  817. }
  818. /(^|[^_[:alnum:]])read_register([^_[:alnum:]]|$)/ {
  819.     fail("read_register")
  820. }

  821. BEGIN { doc["write_register"] = "\
  822. Replace write_register() with regcache_read() et.al."
  823.     category["write_register"] = ari_regression
  824. }
  825. /(^|[^_[:alnum:]])write_register([^_[:alnum:]]|$)/ {
  826.     fail("write_register")
  827. }

  828. function report(name) {
  829.     # Drop any trailing _P.
  830.     name = gensub(/(_P|_p)$/, "", 1, name)
  831.     # Convert to lower case
  832.     name = tolower(name)
  833.     # Split into category and bug
  834.     cat = gensub(/^([[:alpha:]]+)_([_[:alnum:]]*)$/, "\\1", 1, name)
  835.     bug = gensub(/^([[:alpha:]]+)_([_[:alnum:]]*)$/, "\\2", 1, name)
  836.     # Report it
  837.     name = cat " " bug
  838.     doc[name] = "Do not use " cat " " bug ", see declaration for details"
  839.     category[name] = cat
  840.     fail(name)
  841. }

  842. /(^|[^_[:alnum:]])(DEPRECATED|deprecated|set_gdbarch_deprecated|LEGACY|legacy|set_gdbarch_legacy)_/ {
  843.     line = $0
  844.     # print "0 =", $0
  845.     while (1) {
  846.         name = gensub(/^(|.*[^_[:alnum:]])((DEPRECATED|deprecated|LEGACY|legacy)_[_[:alnum:]]*)(.*)$/, "\\2", 1, line)
  847.         line = gensub(/^(|.*[^_[:alnum:]])((DEPRECATED|deprecated|LEGACY|legacy)_[_[:alnum:]]*)(.*)$/, "\\1 \\4", 1, line)
  848.         # print "name =", name, "line =", line
  849.         if (name == line) break;
  850.         report(name)
  851.     }
  852. }

  853. # Count the number of times each architecture method is set
  854. /(^|[^_[:alnum:]])set_gdbarch_[_[:alnum:]]*([^_[:alnum:]]|$)/ {
  855.     name = gensub(/^.*set_gdbarch_([_[:alnum:]]*).*$/, "\\1", 1, $0)
  856.     doc["set " name] = "\
  857. Call to set_gdbarch_" name
  858.     category["set " name] = ari_gdbarch
  859.     fail("set " name)
  860. }

  861. # Count the number of times each tm/xm/nm macro is defined or undefined
  862. /^#[[:space:]]*(undef|define)[[:space:]]+[[:alnum:]_]+.*$/ \
  863. && !/^#[[:space:]]*(undef|define)[[:space:]]+[[:alnum:]_]+_H($|[[:space:]])/ \
  864. && FILENAME ~ /(^|\/)config\/(|[^\/]*\/)(tm-|xm-|nm-).*\.h$/ {
  865.     basename = gensub(/(^|.*\/)([^\/]*)$/, "\\2", 1, FILENAME)
  866.     type = gensub(/^(tm|xm|nm)-.*\.h$/, "\\1", 1, basename)
  867.     name = gensub(/^#[[:space:]]*(undef|define)[[:space:]]+([[:alnum:]_]+).*$/, "\\2", 1, $0)
  868.     if (type == basename) {
  869.         type = "macro"
  870.     }
  871.     doc[type " " name] = "\
  872. Do not define macros such as " name " in a tm, nm or xm file, \
  873. in fact do not provide a tm, nm or xm file"
  874.     category[type " " name] = ari_macro
  875.     fail(type " " name)
  876. }

  877. BEGIN { doc["deprecated_registers"] = "\
  878. Replace deprecated_registers with nothing, they have reached \
  879. end-of-life"
  880.     category["deprecated_registers"] = ari_eol
  881. }
  882. /(^|[^_[:alnum:]])deprecated_registers([^_[:alnum:]]|$)/ {
  883.     fail("deprecated_registers")
  884. }

  885. BEGIN { doc["read_pc"] = "\
  886. Replace READ_PC() with frame_pc_unwind; \
  887. at present the inferior function call code still uses this"
  888.     category["read_pc"] = ari_deprecate
  889. }
  890. /(^|[^_[:alnum:]])read_pc[[:space:]]*\(/ || \
  891. /(^|[^_[:alnum:]])set_gdbarch_read_pc[[:space:]]*\(/ || \
  892. /(^|[^_[:alnum:]])TARGET_READ_PC[[:space:]]*\(/ {
  893.     fail("read_pc")
  894. }

  895. BEGIN { doc["write_pc"] = "\
  896. Replace write_pc() with get_frame_base_address or get_frame_id; \
  897. at present the inferior function call code still uses this when doing \
  898. a DECR_PC_AFTER_BREAK"
  899.     category["write_pc"] = ari_deprecate
  900. }
  901. /(^|[^_[:alnum:]])write_pc[[:space:]]*\(/ || \
  902. /(^|[^_[:alnum:]])TARGET_WRITE_PC[[:space:]]*\(/ {
  903.     fail("write_pc")
  904. }

  905. BEGIN { doc["generic_target_write_pc"] = "\
  906. Replace generic_target_write_pc with a per-architecture implementation, \
  907. this relies on PC_REGNUM which is being eliminated"
  908.     category["generic_target_write_pc"] = ari_regression
  909. }
  910. /(^|[^_[:alnum:]])generic_target_write_pc([^_[:alnum:]]|$)/ {
  911.     fail("generic_target_write_pc")
  912. }

  913. BEGIN { doc["read_sp"] = "\
  914. Replace read_sp() with frame_sp_unwind"
  915.     category["read_sp"] = ari_regression
  916. }
  917. /(^|[^_[:alnum:]])read_sp[[:space:]]*\(/ || \
  918. /(^|[^_[:alnum:]])set_gdbarch_read_sp[[:space:]]*\(/ || \
  919. /(^|[^_[:alnum:]])TARGET_READ_SP[[:space:]]*\(/ {
  920.     fail("read_sp")
  921. }

  922. BEGIN { doc["register_cached"] = "\
  923. Replace register_cached() with nothing, does not have a regcache parameter"
  924.     category["register_cached"] = ari_regression
  925. }
  926. /(^|[^_[:alnum:]])register_cached[[:space:]]*\(/ {
  927.     fail("register_cached")
  928. }

  929. BEGIN { doc["set_register_cached"] = "\
  930. Replace set_register_cached() with nothing, does not have a regcache parameter"
  931.     category["set_register_cached"] = ari_regression
  932. }
  933. /(^|[^_[:alnum:]])set_register_cached[[:space:]]*\(/ {
  934.     fail("set_register_cached")
  935. }

  936. # Print functions: Use versions that either check for buffer overflow
  937. # or safely allocate a fresh buffer.

  938. BEGIN { doc["sprintf"] = "\
  939. Do not use sprintf, instead use xsnprintf or xstrprintf"
  940.     category["sprintf"] = ari_code
  941. }
  942. /(^|[^_[:alnum:]])sprintf[[:space:]]*\(/ {
  943.     fail("sprintf")
  944. }

  945. BEGIN { doc["vsprintf"] = "\
  946. Do not use vsprintf(), instead use xstrvprintf"
  947.     category["vsprintf"] = ari_regression
  948. }
  949. /(^|[^_[:alnum:]])vsprintf[[:space:]]*\(/ {
  950.     fail("vsprintf")
  951. }

  952. BEGIN { doc["asprintf"] = "\
  953. Do not use asprintf(), instead use xstrprintf()"
  954.     category["asprintf"] = ari_regression
  955. }
  956. /(^|[^_[:alnum:]])asprintf[[:space:]]*\(/ {
  957.     fail("asprintf")
  958. }

  959. BEGIN { doc["vasprintf"] = "\
  960. Do not use vasprintf(), instead use xstrvprintf"
  961.     fix("vasprintf", "common/common-utils.c", 1)
  962.     category["vasprintf"] = ari_regression
  963. }
  964. /(^|[^_[:alnum:]])vasprintf[[:space:]]*\(/ {
  965.     fail("vasprintf")
  966. }

  967. # More generic memory operations

  968. BEGIN { doc["bzero"] = "\
  969. Do not use bzero(), instead use memset()"
  970.     category["bzero"] = ari_regression
  971. }
  972. /(^|[^_[:alnum:]])bzero[[:space:]]*\(/ {
  973.     fail("bzero")
  974. }

  975. BEGIN { doc["strdup"] = "\
  976. Do not use strdup(), instead use xstrdup()";
  977.     category["strdup"] = ari_regression
  978. }
  979. /(^|[^_[:alnum:]])strdup[[:space:]]*\(/ {
  980.     fail("strdup")
  981. }

  982. BEGIN { doc["strsave"] = "\
  983. Do not use strsave(), instead use xstrdup() et.al."
  984.     category["strsave"] = ari_regression
  985. }
  986. /(^|[^_[:alnum:]])strsave[[:space:]]*\(/ {
  987.     fail("strsave")
  988. }

  989. # String compare functions

  990. BEGIN { doc["strnicmp"] = "\
  991. Do not use strnicmp(), instead use strncasecmp()"
  992.     category["strnicmp"] = ari_regression
  993. }
  994. /(^|[^_[:alnum:]])strnicmp[[:space:]]*\(/ {
  995.     fail("strnicmp")
  996. }

  997. # Boolean expressions and conditionals

  998. BEGIN { doc["boolean"] = "\
  999. Do not use `boolean'\'',  use `int'\'' instead"
  1000.     category["boolean"] = ari_regression
  1001. }
  1002. /(^|[^_[:alnum:]])boolean([^_[:alnum:]]|$)/ {
  1003.     if (is_yacc_or_lex == 0) {
  1004.        fail("boolean")
  1005.     }
  1006. }

  1007. BEGIN { doc["false"] = "\
  1008. Definitely do not use `false'\'' in boolean expressions"
  1009.     category["false"] = ari_regression
  1010. }
  1011. /(^|[^_[:alnum:]])false([^_[:alnum:]]|$)/ {
  1012.     if (is_yacc_or_lex == 0) {
  1013.        fail("false")
  1014.     }
  1015. }

  1016. BEGIN { doc["true"] = "\
  1017. Do not try to use `true'\'' in boolean expressions"
  1018.     category["true"] = ari_regression
  1019. }
  1020. /(^|[^_[:alnum:]])true([^_[:alnum:]]|$)/ {
  1021.     if (is_yacc_or_lex == 0) {
  1022.        fail("true")
  1023.     }
  1024. }

  1025. # Typedefs that are either redundant or can be reduced to `struct
  1026. # type *''.
  1027. # Must be placed before if assignment otherwise ARI exceptions
  1028. # are not handled correctly.

  1029. BEGIN { doc["d_namelen"] = "\
  1030. Do not use dirent.d_namelen, instead use NAMELEN"
  1031.     category["d_namelen"] = ari_regression
  1032. }
  1033. /(^|[^_[:alnum:]])d_namelen([^_[:alnum:]]|$)/ {
  1034.     fail("d_namelen")
  1035. }

  1036. BEGIN { doc["strlen d_name"] = "\
  1037. Do not use strlen dirent.d_name, instead use NAMELEN"
  1038.     category["strlen d_name"] = ari_regression
  1039. }
  1040. /(^|[^_[:alnum:]])strlen[[:space:]]*\(.*[^_[:alnum:]]d_name([^_[:alnum:]]|$)/ {
  1041.     fail("strlen d_name")
  1042. }

  1043. BEGIN { doc["var_boolean"] = "\
  1044. Replace var_boolean with add_setshow_boolean_cmd"
  1045.     category["var_boolean"] = ari_regression
  1046.     fix("var_boolean", "gdb/command.h", 1)
  1047.     # fix only uses the last directory level
  1048.     fix("var_boolean", "cli/cli-decode.c", 2)
  1049. }
  1050. /(^|[^_[:alnum:]])var_boolean([^_[:alnum:]]|$)/ {
  1051.     if (($0 !~ /(^|[^_[:alnum:]])case *var_boolean:/) \
  1052.         && ($0 !~ /(^|[^_[:alnum:]])[=!]= *var_boolean/)) {
  1053.         fail("var_boolean")
  1054.     }
  1055. }

  1056. BEGIN { doc["generic_use_struct_convention"] = "\
  1057. Replace generic_use_struct_convention with nothing, \
  1058. EXTRACT_STRUCT_VALUE_ADDRESS is a predicate"
  1059.     category["generic_use_struct_convention"] = ari_regression
  1060. }
  1061. /(^|[^_[:alnum:]])generic_use_struct_convention([^_[:alnum:]]|$)/ {
  1062.     fail("generic_use_struct_convention")
  1063. }

  1064. BEGIN { doc["if assignment"] = "\
  1065. An IF statement'\''s expression contains an assignment (the GNU coding \
  1066. standard discourages this)"
  1067.     category["if assignment"] = ari_code
  1068. }
  1069. BEGIN { doc["if clause more than 50 lines"] = "\
  1070. An IF statement'\''s expression expands over 50 lines"
  1071.     category["if clause more than 50 lines"] = ari_code
  1072. }
  1073. #
  1074. # Accumulate continuation lines
  1075. FNR == 1 {
  1076.     in_if = 0
  1077. }

  1078. /(^|[^_[:alnum:]])if / {
  1079.     in_if = 1;
  1080.     if_brace_level = 0;
  1081.     if_cont_p = 0;
  1082.     if_count = 0;
  1083.     if_brace_end_pos = 0;
  1084.     if_full_line = "";
  1085. }
  1086. (in_if)  {
  1087.     # We want everything up to closing brace of same level
  1088.     if_count++;
  1089.     if (if_count > 50) {
  1090.         print "multiline if: " if_full_line $0
  1091.         fail("if clause more than 50 lines")
  1092.         if_brace_level = 0;
  1093.         if_full_line = "";
  1094.     } else {
  1095.         if (if_count == 1) {
  1096.             i = index($0,"if ");
  1097.         } else {
  1098.             i = 1;
  1099.         }
  1100.         for (i=i; i <= length($0); i++) {
  1101.             char = substr($0,i,1);
  1102.             if (char == "(") { if_brace_level++; }
  1103.             if (char == ")") {
  1104.                 if_brace_level--;
  1105.                 if (!if_brace_level) {
  1106.                     if_brace_end_pos = i;
  1107.                     after_if = substr($0,i+1,length($0));
  1108.                     # Do not parse what is following
  1109.                     break;
  1110.                 }
  1111.             }
  1112.         }
  1113.         if (if_brace_level == 0) {
  1114.             $0 = substr($0,1,i);
  1115.             in_if = 0;
  1116.         } else {
  1117.             if_full_line = if_full_line $0;
  1118.             if_cont_p = 1;
  1119.             next;
  1120.         }
  1121.     }
  1122. }
  1123. # if we arrive here, we need to concatenate, but we are at brace level 0

  1124. (if_brace_end_pos) {
  1125.     $0 = if_full_line substr($0,1,if_brace_end_pos);
  1126.     if (if_count > 1) {
  1127.         # print "IF: multi line " if_count " found at " FILENAME ":" FNR " \"" $0 "\""
  1128.     }
  1129.     if_cont_p = 0;
  1130.     if_full_line = "";
  1131. }
  1132. /(^|[^_[:alnum:]])if .* = / {
  1133.     # print "fail in if " $0
  1134.     fail("if assignment")
  1135. }
  1136. (if_brace_end_pos) {
  1137.     $0 = $0 after_if;
  1138.     if_brace_end_pos = 0;
  1139.     in_if = 0;
  1140. }

  1141. # Printout of all found bug

  1142. BEGIN {
  1143.     if (print_doc) {
  1144.         for (bug in doc) {
  1145.             fail(bug)
  1146.         }
  1147.         exit
  1148.     }
  1149. }' "$@"