Remove "fix" call for "long long" from ARI
[deliverable/binutils-gdb.git] / gdb / contrib / ari / gdb_ari.sh
CommitLineData
b786c521
PM
1#!/bin/sh
2
3# GDB script to list of problems using awk.
4#
42a4f53d 5# Copyright (C) 2002-2019 Free Software Foundation, Inc.
b786c521
PM
6#
7# This file is part of GDB.
8#
9# This program is free software; you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation; either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program. If not, see <http://www.gnu.org/licenses/>.
21
22# Make certain that the script is not running in an internationalized
23# environment.
24
84f13595
PM
25LANG=C ; export LANG
26LC_ALL=C ; export LC_ALL
b786c521
PM
27
28# Permanent checks take the form:
29
56f79b63 30# Do not use XXXX, C++11 implies YYYY
b786c521
PM
31# Do not use XXXX, instead use YYYY''.
32
33# and should never be removed.
34
35# Temporary checks take the form:
36
37# Replace XXXX with YYYY
38
39# and once they reach zero, can be eliminated.
40
41# FIXME: It should be able to override this on the command line
42error="regression"
43warning="regression"
44ari="regression eol code comment deprecated legacy obsolete gettext"
45all="regression eol code comment deprecated legacy obsolete gettext deprecate internal gdbarch macro"
46print_doc=0
47print_idx=0
48
49usage ()
50{
51 cat <<EOF 1>&2
52Error: $1
53
54Usage:
98f9338a 55 $0 --print-doc --print-idx -Wall -Werror -WCATEGORY FILE ...
b786c521
PM
56Options:
57 --print-doc Print a list of all potential problems, then exit.
58 --print-idx Include the problems IDX (index or key) in every message.
59 --src=file Write source lines to file.
60 -Werror Treat all problems as errors.
61 -Wall Report all problems.
62 -Wari Report problems that should be fixed in new code.
63456183
TT
63 -WCATEGORY Report problems in the specifed category. The category
64 can be prefixed with "no-". Valid categories
b786c521
PM
65 are: ${all}
66EOF
67 exit 1
68}
69
70
71# Parse the various options
72Woptions=
73srclines=""
74while test $# -gt 0
75do
76 case "$1" in
77 -Wall ) Woptions="${all}" ;;
78 -Wari ) Woptions="${ari}" ;;
79 -Werror ) Werror=1 ;;
80 -W* ) Woptions="${Woptions} `echo x$1 | sed -e 's/x-W//'`" ;;
81 --print-doc ) print_doc=1 ;;
82 --print-idx ) print_idx=1 ;;
83 --src=* ) srclines="`echo $1 | sed -e 's/--src=/srclines=\"/'`\"" ;;
84 -- ) shift ; break ;;
85 - ) break ;;
86 -* ) usage "$1: unknown option" ;;
87 * ) break ;;
88 esac
89 shift
90done
91if test -n "$Woptions" ; then
92 warning="$Woptions"
93 error=
94fi
95
96
97# -Werror implies treating all warnings as errors.
98if test -n "${Werror}" ; then
99 error="${error} ${warning}"
100fi
101
102
103# Validate all errors and warnings.
104for w in ${warning} ${error}
105do
63456183
TT
106 case "$w" in
107 no-*) w=`echo x$w | sed -e 's/xno-//'`;;
108 esac
109
b786c521
PM
110 case " ${all} " in
111 *" ${w} "* ) ;;
112 * ) usage "Unknown option -W${w}" ;;
113 esac
114done
115
116
117# make certain that there is at least one file.
118if test $# -eq 0 -a ${print_doc} = 0
119then
120 usage "Missing file."
121fi
122
123
124# Convert the errors/warnings into corresponding array entries.
125for a in ${all}
126do
127 aris="${aris} ari_${a} = \"${a}\";"
128done
129for w in ${warning}
130do
63456183
TT
131 val=1
132 case "$w" in
133 no-*) w=`echo x$w | sed -e 's/xno-//'`; val=0 ;;
134 esac
135 warnings="${warnings} warning[ari_${w}] = $val;"
b786c521
PM
136done
137for e in ${error}
138do
63456183
TT
139 val=1
140 case "$e" in
141 no-*) e=`echo x$e | sed -e 's/xno-//'`; val=0 ;;
142 esac
143 errors="${errors} error[ari_${e}] = $val;"
b786c521
PM
144done
145
84f13595 146if [ "$AWK" = "" ] ; then
b786c521
PM
147 AWK=awk
148fi
149
150${AWK} -- '
151BEGIN {
152 # NOTE, for a per-file begin use "FNR == 1".
153 '"${aris}"'
154 '"${errors}"'
155 '"${warnings}"'
156 '"${srclines}"'
157 print_doc = '$print_doc'
158 print_idx = '$print_idx'
159 PWD = "'`pwd`'"
160}
161
162# Print the error message for BUG. Append SUPLEMENT if non-empty.
163function print_bug(file,line,prefix,category,bug,doc,supplement, suffix,idx) {
164 if (print_idx) {
165 idx = bug ": "
166 } else {
167 idx = ""
168 }
169 if (supplement) {
170 suffix = " (" supplement ")"
171 } else {
172 suffix = ""
173 }
174 # ari.*.bug: <FILE>:<LINE>: <CATEGORY>: <BUG>: <DOC>
175 print file ":" line ": " prefix category ": " idx doc suffix
176 if (srclines != "") {
177 print file ":" line ":" $0 >> srclines
178 }
179}
180
181function fix(bug,file,count) {
182 skip[bug, file] = count
183 skipped[bug, file] = 0
184}
185
186function fail(bug,supplement) {
187 if (doc[bug] == "") {
188 print_bug("", 0, "internal: ", "internal", "internal", "Missing doc for bug " bug)
189 exit
190 }
191 if (category[bug] == "") {
192 print_bug("", 0, "internal: ", "internal", "internal", "Missing category for bug " bug)
193 exit
194 }
195
196 if (ARI_OK == bug) {
197 return
198 }
199 # Trim the filename down to just DIRECTORY/FILE so that it can be
200 # robustly used by the FIX code.
201
202 if (FILENAME ~ /^\//) {
203 canonicalname = FILENAME
204 } else {
205 canonicalname = PWD "/" FILENAME
206 }
207 shortname = gensub (/^.*\/([^\\]*\/[^\\]*)$/, "\\1", 1, canonicalname)
208
209 skipped[bug, shortname]++
210 if (skip[bug, shortname] >= skipped[bug, shortname]) {
211 # print FILENAME, FNR, skip[bug, FILENAME], skipped[bug, FILENAME], bug
212 # Do nothing
213 } else if (error[category[bug]]) {
214 # ari.*.bug: <FILE>:<LINE>: <CATEGORY>: <BUG>: <DOC>
215 print_bug(FILENAME, FNR, "", category[bug], bug, doc[bug], supplement)
216 } else if (warning[category[bug]]) {
217 # ari.*.bug: <FILE>:<LINE>: <CATEGORY>: <BUG>: <DOC>
218 print_bug(FILENAME, FNR, "warning: ", category[bug], bug, doc[bug], supplement)
219 }
220}
221
222FNR == 1 {
223 seen[FILENAME] = 1
224 if (match(FILENAME, "\\.[ly]$")) {
225 # FILENAME is a lex or yacc source
226 is_yacc_or_lex = 1
227 }
228 else {
229 is_yacc_or_lex = 0
230 }
231}
232END {
233 if (print_idx) {
234 idx = bug ": "
235 } else {
236 idx = ""
237 }
238 # Did we do only a partial skip?
239 for (bug_n_file in skip) {
240 split (bug_n_file, a, SUBSEP)
241 bug = a[1]
242 file = a[2]
243 if (seen[file] && (skipped[bug_n_file] < skip[bug_n_file])) {
244 # ari.*.bug: <FILE>:<LINE>: <CATEGORY>: <BUG>: <DOC>
245 b = file " missing " bug
246 print_bug(file, 0, "", "internal", file " missing " bug, "Expecting " skip[bug_n_file] " occurances of bug " bug " in file " file ", only found " skipped[bug_n_file])
247 }
248 }
249}
250
251
252# Skip OBSOLETE lines
253/(^|[^_[:alnum:]])OBSOLETE([^_[:alnum:]]|$)/ { next; }
254
255# Skip ARI lines
256
257BEGIN {
258 ARI_OK = ""
259}
260
261/\/\* ARI:[[:space:]]*(.*)[[:space:]]*\*\// {
262 ARI_OK = gensub(/^.*\/\* ARI:[[:space:]]*(.*[^[:space:]])[[:space:]]*\*\/.*$/, "\\1", 1, $0)
263 # print "ARI line found \"" $0 "\""
264 # print "ARI_OK \"" ARI_OK "\""
265}
266! /\/\* ARI:[[:space:]]*(.*)[[:space:]]*\*\// {
267 ARI_OK = ""
268}
269
270
b786c521
PM
271# SNIP - Strip out comments - SNIP
272
273FNR == 1 {
274 comment_p = 0
275}
276comment_p && /\*\// { gsub (/^([^\*]|\*+[^\/\*])*\*+\//, " "); comment_p = 0; }
277comment_p { next; }
278!comment_p { gsub (/\/\*([^\*]|\*+[^\/\*])*\*+\//, " "); }
279!comment_p && /(^|[^"])\/\*/ { gsub (/\/\*.*$/, " "); comment_p = 1; }
280
281
282BEGIN { doc["_ markup"] = "\
283All messages should be marked up with _."
284 category["_ markup"] = ari_gettext
285}
286/^[^"]*[[:space:]](warning|error|error_no_arg|query|perror_with_name)[[:space:]]*\([^_\(a-z]/ {
287 if (! /\("%s"/) {
288 fail("_ markup")
289 }
290}
291
292BEGIN { doc["trailing new line"] = "\
293A message should not have a trailing new line"
294 category["trailing new line"] = ari_gettext
295}
296/(^|[^_[:alnum:]])(warning|error)[[:space:]]*\(_\(".*\\n"\)[\),]/ {
297 fail("trailing new line")
298}
299
300# Include files for which GDB has a custom version.
301
302BEGIN { doc["assert.h"] = "\
303Do not include assert.h, instead include \"gdb_assert.h\"";
304 category["assert.h"] = ari_regression
305 fix("assert.h", "gdb/gdb_assert.h", 0) # it does not use it
306}
307/^#[[:space:]]*include[[:space:]]+.assert\.h./ {
308 fail("assert.h")
309}
310
b786c521
PM
311BEGIN { doc["regex.h"] = "\
312Do not include regex.h, instead include gdb_regex.h"
313 category["regex.h"] = ari_regression
314 fix("regex.h", "gdb/gdb_regex.h", 1)
315}
316/^#[[:space:]]*include[[:space:]]*.regex\.h./ {
317 fail("regex.h")
318}
319
320BEGIN { doc["xregex.h"] = "\
321Do not include xregex.h, instead include gdb_regex.h"
322 category["xregex.h"] = ari_regression
323 fix("xregex.h", "gdb/gdb_regex.h", 1)
324}
325/^#[[:space:]]*include[[:space:]]*.xregex\.h./ {
326 fail("xregex.h")
327}
328
329BEGIN { doc["gnu-regex.h"] = "\
330Do not include gnu-regex.h, instead include gdb_regex.h"
331 category["gnu-regex.h"] = ari_regression
332}
333/^#[[:space:]]*include[[:space:]]*.gnu-regex\.h./ {
334 fail("gnu regex.h")
335}
336
b786c521
PM
337BEGIN { doc["wait.h"] = "\
338Do not include wait.h or sys/wait.h, instead include gdb_wait.h"
268a13a5 339 fix("wait.h", "gdbsupport/gdb_wait.h", 2);
b786c521
PM
340 category["wait.h"] = ari_regression
341}
342/^#[[:space:]]*include[[:space:]]*.wait\.h./ \
343|| /^#[[:space:]]*include[[:space:]]*.sys\/wait\.h./ {
344 fail("wait.h")
345}
346
347BEGIN { doc["vfork.h"] = "\
348Do not include vfork.h, instead include gdb_vfork.h"
349 fix("vfork.h", "gdb/gdb_vfork.h", 1);
350 category["vfork.h"] = ari_regression
351}
352/^#[[:space:]]*include[[:space:]]*.vfork\.h./ {
353 fail("vfork.h")
354}
355
356BEGIN { doc["error not internal-warning"] = "\
357Do not use error(\"internal-warning\"), instead use internal_warning"
358 category["error not internal-warning"] = ari_regression
359}
360/error.*\"[Ii]nternal.warning/ {
361 fail("error not internal-warning")
362}
363
364BEGIN { doc["%p"] = "\
365Do not use printf(\"%p\"), instead use printf(\"%s\",paddr()) to dump a \
366target address, or host_address_to_string() for a host address"
367 category["%p"] = ari_code
368}
cd6fdaa1
TT
369# Allow gdb %p extensions, but not other uses of %p.
370/%p[^[\]sF]/ && !/%prec/ {
b786c521
PM
371 fail("%p")
372}
373
374BEGIN { doc["%ll"] = "\
375Do not use printf(\"%ll\"), instead use printf(\"%s\",phex()) to dump a \
376`long long'\'' value"
377 category["%ll"] = ari_code
378}
379# Allow %ll in scanf
380/%[0-9]*ll/ && !/scanf \(.*%[0-9]*ll/ {
381 fail("%ll")
382}
383
384
385# SNIP - Strip out strings - SNIP
386
387# Test on top.c, scm-valprint.c, remote-rdi.c, ada-lang.c
388FNR == 1 {
389 string_p = 0
390 trace_string = 0
391}
392# Strip escaped characters.
393{ gsub(/\\./, "."); }
394# Strip quoted quotes.
395{ gsub(/'\''.'\''/, "'\''.'\''"); }
396# End of multi-line string
397string_p && /\"/ {
398 if (trace_string) print "EOS:" FNR, $0;
399 gsub (/^[^\"]*\"/, "'\''");
400 string_p = 0;
401}
402# Middle of multi-line string, discard line.
403string_p {
404 if (trace_string) print "MOS:" FNR, $0;
405 $0 = ""
406}
407# Strip complete strings from the middle of the line
408!string_p && /\"[^\"]*\"/ {
409 if (trace_string) print "COS:" FNR, $0;
410 gsub (/\"[^\"]*\"/, "'\''");
411}
412# Start of multi-line string
413BEGIN { doc["multi-line string"] = "\
414Multi-line string must have the newline escaped"
415 category["multi-line string"] = ari_regression
416}
417!string_p && /\"/ {
418 if (trace_string) print "SOS:" FNR, $0;
419 if (/[^\\]$/) {
420 fail("multi-line string")
421 }
422 gsub (/\"[^\"]*$/, "'\''");
423 string_p = 1;
424}
425# { print }
426
427# Multi-line string
428string_p &&
429
430# Accumulate continuation lines
431FNR == 1 {
432 cont_p = 0
433}
434!cont_p { full_line = ""; }
435/[^\\]\\$/ { gsub (/\\$/, ""); full_line = full_line $0; cont_p = 1; next; }
436cont_p { $0 = full_line $0; cont_p = 0; full_line = ""; }
437
438
b786c521 439BEGIN { doc["__FUNCTION__"] = "\
56f79b63 440Do not use __FUNCTION__, C++11 does not support this macro"
b786c521
PM
441 category["__FUNCTION__"] = ari_regression
442}
443/(^|[^_[:alnum:]])__FUNCTION__([^_[:alnum:]]|$)/ {
444 fail("__FUNCTION__")
445}
446
447BEGIN { doc["__CYGWIN32__"] = "\
448Do not use __CYGWIN32__, instead use __CYGWIN__ or, better, an explicit \
449autoconf tests"
450 category["__CYGWIN32__"] = ari_regression
451}
452/(^|[^_[:alnum:]])__CYGWIN32__([^_[:alnum:]]|$)/ {
453 fail("__CYGWIN32__")
454}
455
456BEGIN { doc["PTR"] = "\
56f79b63 457Do not use PTR, C++11 implies `void *'\''"
b786c521
PM
458 category["PTR"] = ari_regression
459 #fix("PTR", "gdb/utils.c", 6)
460}
461/(^|[^_[:alnum:]])PTR([^_[:alnum:]]|$)/ {
462 fail("PTR")
463}
464
465BEGIN { doc["UCASE function"] = "\
466Function name is uppercase."
467 category["UCASE function"] = ari_code
468 possible_UCASE = 0
469 UCASE_full_line = ""
470}
471(possible_UCASE) {
472 if (ARI_OK == "UCASE function") {
473 possible_UCASE = 0
474 }
475 # Closing brace found?
476 else if (UCASE_full_line ~ \
477 /^[A-Z][[:alnum:]_]*[[:space:]]*\([^()]*\).*$/) {
478 if ((UCASE_full_line ~ \
479 /^[A-Z][[:alnum:]_]*[[:space:]]*\([^()]*\)[[:space:]]*$/) \
480 && ($0 ~ /^\{/) && (is_yacc_or_lex == 0)) {
481 store_FNR = FNR
482 FNR = possible_FNR
483 store_0 = $0;
484 $0 = UCASE_full_line;
485 fail("UCASE function")
486 FNR = store_FNR
487 $0 = store_0;
488 }
489 possible_UCASE = 0
490 UCASE_full_line = ""
491 } else {
492 UCASE_full_line = UCASE_full_line $0;
493 }
494}
495/^[A-Z][[:alnum:]_]*[[:space:]]*\([^()]*(|\))[[:space:]]*$/ {
496 possible_UCASE = 1
497 if (ARI_OK == "UCASE function") {
498 possible_UCASE = 0
499 }
500 possible_FNR = FNR
501 UCASE_full_line = $0
502}
503
504
505BEGIN { doc["editCase function"] = "\
506Function name starts lower case but has uppercased letters."
507 category["editCase function"] = ari_code
508 possible_editCase = 0
509 editCase_full_line = ""
510}
511(possible_editCase) {
47d21dc5 512 if (ARI_OK == "editCase function") {
b786c521
PM
513 possible_editCase = 0
514 }
515 # Closing brace found?
516 else if (editCase_full_line ~ \
517/^[a-z][a-z0-9_]*[A-Z][a-z0-9A-Z_]*[[:space:]]*\([^()]*\).*$/) {
518 if ((editCase_full_line ~ \
519/^[a-z][a-z0-9_]*[A-Z][a-z0-9A-Z_]*[[:space:]]*\([^()]*\)[[:space:]]*$/) \
520 && ($0 ~ /^\{/) && (is_yacc_or_lex == 0)) {
521 store_FNR = FNR
522 FNR = possible_FNR
523 store_0 = $0;
524 $0 = editCase_full_line;
525 fail("editCase function")
526 FNR = store_FNR
527 $0 = store_0;
528 }
529 possible_editCase = 0
530 editCase_full_line = ""
531 } else {
532 editCase_full_line = editCase_full_line $0;
533 }
534}
535/^[a-z][a-z0-9_]*[A-Z][a-z0-9A-Z_]*[[:space:]]*\([^()]*(|\))[[:space:]]*$/ {
536 possible_editCase = 1
537 if (ARI_OK == "editCase function") {
538 possible_editCase = 0
539 }
540 possible_FNR = FNR
541 editCase_full_line = $0
542}
543
544# Only function implementation should be on first column
545BEGIN { doc["function call in first column"] = "\
546Function name in first column should be restricted to function implementation"
547 category["function call in first column"] = ari_code
548}
549/^[a-z][a-z0-9_]*[[:space:]]*\((|[^*][^()]*)\)[[:space:]]*[^ \t]+/ {
550 fail("function call in first column")
551}
552
553
b786c521
PM
554BEGIN { doc["hash"] = "\
555Do not use ` #...'\'', instead use `#...'\''(some compilers only correctly \
556parse a C preprocessor directive when `#'\'' is the first character on \
557the line)"
558 category["hash"] = ari_regression
559}
560/^[[:space:]]+#/ {
561 fail("hash")
562}
563
564BEGIN { doc["OP eol"] = "\
565Do not use &&, or || at the end of a line"
566 category["OP eol"] = ari_code
567}
e3f1ad4f
PM
568# * operator needs a special treatment as it can be a
569# valid end of line for a pointer type definition
570# Only catch case where an assignment or an opening brace is present
571/(\|\||\&\&|==|!=|[[:space:]][+\-\/])[[:space:]]*$/ \
572|| /(\(|=)[[:space:]].*[[:space:]]\*[[:space:]]*$/ {
b786c521
PM
573 fail("OP eol")
574}
575
576BEGIN { doc["strerror"] = "\
577Do not use strerror(), instead use safe_strerror()"
578 category["strerror"] = ari_regression
579 fix("strerror", "gdb/gdb_string.h", 1)
268a13a5
TT
580 fix("strerror", "gdb/gdbsupport/mingw-strerror.c", 1)
581 fix("strerror", "gdb/gdbsupport/posix-strerror.c", 1)
b786c521
PM
582}
583/(^|[^_[:alnum:]])strerror[[:space:]]*\(/ {
584 fail("strerror")
585}
586
587BEGIN { doc["long long"] = "\
588Do not use `long long'\'', instead use LONGEST"
589 category["long long"] = ari_code
b786c521
PM
590}
591/(^|[^_[:alnum:]])long[[:space:]]+long([^_[:alnum:]]|$)/ {
592 fail("long long")
593}
594
b786c521
PM
595BEGIN { doc["ATTR_FORMAT"] = "\
596Do not use ATTR_FORMAT, use ATTRIBUTE_PRINTF instead"
597 category["ATTR_FORMAT"] = ari_regression
598}
599/(^|[^_[:alnum:]])ATTR_FORMAT([^_[:alnum:]]|$)/ {
600 fail("ATTR_FORMAT")
601}
602
603BEGIN { doc["ATTR_NORETURN"] = "\
604Do not use ATTR_NORETURN, use ATTRIBUTE_NORETURN instead"
605 category["ATTR_NORETURN"] = ari_regression
606}
607/(^|[^_[:alnum:]])ATTR_NORETURN([^_[:alnum:]]|$)/ {
608 fail("ATTR_NORETURN")
609}
610
611BEGIN { doc["NORETURN"] = "\
612Do not use NORETURN, use ATTRIBUTE_NORETURN instead"
613 category["NORETURN"] = ari_regression
614}
615/(^|[^_[:alnum:]])NORETURN([^_[:alnum:]]|$)/ {
616 fail("NORETURN")
617}
618
619
620# General problems
621
622BEGIN { doc["multiple messages"] = "\
623Do not use multiple calls to warning or error, instead use a single call"
624 category["multiple messages"] = ari_gettext
625}
626FNR == 1 {
627 warning_fnr = -1
628}
629/(^|[^_[:alnum:]])(warning|error)[[:space:]]*\(/ {
630 if (FNR == warning_fnr + 1) {
631 fail("multiple messages")
632 } else {
633 warning_fnr = FNR
634 }
635}
636
637# Commented out, but left inside sources, just in case.
638# BEGIN { doc["inline"] = "\
639# Do not use the inline attribute; \
640# since the compiler generally ignores this, better algorithm selection \
641# is needed to improved performance"
642# category["inline"] = ari_code
643# }
644# /(^|[^_[:alnum:]])inline([^_[:alnum:]]|$)/ {
645# fail("inline")
646# }
647
648# This test is obsolete as this type
649# has been deprecated and finally suppressed from GDB sources
650#BEGIN { doc["obj_private"] = "\
651#Replace obj_private with objfile_data"
652# category["obj_private"] = ari_obsolete
653#}
654#/(^|[^_[:alnum:]])obj_private([^_[:alnum:]]|$)/ {
655# fail("obj_private")
656#}
657
658BEGIN { doc["abort"] = "\
659Do not use abort, instead use internal_error; GDB should never abort"
660 category["abort"] = ari_regression
b786c521
PM
661}
662/(^|[^_[:alnum:]])abort[[:space:]]*\(/ {
663 fail("abort")
664}
665
666BEGIN { doc["basename"] = "\
667Do not use basename, instead use lbasename"
668 category["basename"] = ari_regression
669}
670/(^|[^_[:alnum:]])basename[[:space:]]*\(/ {
671 fail("basename")
672}
673
674BEGIN { doc["assert"] = "\
675Do not use assert, instead use gdb_assert or internal_error; assert \
676calls abort and GDB should never call abort"
677 category["assert"] = ari_regression
678}
679/(^|[^_[:alnum:]])assert[[:space:]]*\(/ {
680 fail("assert")
681}
682
683BEGIN { doc["TARGET_HAS_HARDWARE_WATCHPOINTS"] = "\
684Replace TARGET_HAS_HARDWARE_WATCHPOINTS with nothing, not needed"
685 category["TARGET_HAS_HARDWARE_WATCHPOINTS"] = ari_regression
686}
687/(^|[^_[:alnum:]])TARGET_HAS_HARDWARE_WATCHPOINTS([^_[:alnum:]]|$)/ {
688 fail("TARGET_HAS_HARDWARE_WATCHPOINTS")
689}
690
691BEGIN { doc["ADD_SHARED_SYMBOL_FILES"] = "\
692Replace ADD_SHARED_SYMBOL_FILES with nothing, not needed?"
693 category["ADD_SHARED_SYMBOL_FILES"] = ari_regression
694}
695/(^|[^_[:alnum:]])ADD_SHARED_SYMBOL_FILES([^_[:alnum:]]|$)/ {
696 fail("ADD_SHARED_SYMBOL_FILES")
697}
698
699BEGIN { doc["SOLIB_ADD"] = "\
700Replace SOLIB_ADD with nothing, not needed?"
27fd0c6b 701 category["SOLIB_ADD"] = ari_regression
b786c521
PM
702}
703/(^|[^_[:alnum:]])SOLIB_ADD([^_[:alnum:]]|$)/ {
704 fail("SOLIB_ADD")
705}
706
707BEGIN { doc["SOLIB_CREATE_INFERIOR_HOOK"] = "\
708Replace SOLIB_CREATE_INFERIOR_HOOK with nothing, not needed?"
27fd0c6b 709 category["SOLIB_CREATE_INFERIOR_HOOK"] = ari_regression
b786c521
PM
710}
711/(^|[^_[:alnum:]])SOLIB_CREATE_INFERIOR_HOOK([^_[:alnum:]]|$)/ {
712 fail("SOLIB_CREATE_INFERIOR_HOOK")
713}
714
715BEGIN { doc["SOLIB_LOADED_LIBRARY_PATHNAME"] = "\
716Replace SOLIB_LOADED_LIBRARY_PATHNAME with nothing, not needed?"
717 category["SOLIB_LOADED_LIBRARY_PATHNAME"] = ari_regression
718}
719/(^|[^_[:alnum:]])SOLIB_LOADED_LIBRARY_PATHNAME([^_[:alnum:]]|$)/ {
720 fail("SOLIB_LOADED_LIBRARY_PATHNAME")
721}
722
723BEGIN { doc["REGISTER_U_ADDR"] = "\
724Replace REGISTER_U_ADDR with nothing, not needed?"
725 category["REGISTER_U_ADDR"] = ari_regression
726}
727/(^|[^_[:alnum:]])REGISTER_U_ADDR([^_[:alnum:]]|$)/ {
728 fail("REGISTER_U_ADDR")
729}
730
731BEGIN { doc["PROCESS_LINENUMBER_HOOK"] = "\
732Replace PROCESS_LINENUMBER_HOOK with nothing, not needed?"
733 category["PROCESS_LINENUMBER_HOOK"] = ari_regression
734}
735/(^|[^_[:alnum:]])PROCESS_LINENUMBER_HOOK([^_[:alnum:]]|$)/ {
736 fail("PROCESS_LINENUMBER_HOOK")
737}
738
739BEGIN { doc["PC_SOLIB"] = "\
740Replace PC_SOLIB with nothing, not needed?"
27fd0c6b 741 category["PC_SOLIB"] = ari_regression
b786c521
PM
742}
743/(^|[^_[:alnum:]])PC_SOLIB([^_[:alnum:]]|$)/ {
744 fail("PC_SOLIB")
745}
746
747BEGIN { doc["IN_SOLIB_DYNSYM_RESOLVE_CODE"] = "\
748Replace IN_SOLIB_DYNSYM_RESOLVE_CODE with nothing, not needed?"
749 category["IN_SOLIB_DYNSYM_RESOLVE_CODE"] = ari_regression
750}
751/(^|[^_[:alnum:]])IN_SOLIB_DYNSYM_RESOLVE_CODE([^_[:alnum:]]|$)/ {
752 fail("IN_SOLIB_DYNSYM_RESOLVE_CODE")
753}
754
755BEGIN { doc["GCC_COMPILED_FLAG_SYMBOL"] = "\
756Replace GCC_COMPILED_FLAG_SYMBOL with nothing, not needed?"
757 category["GCC_COMPILED_FLAG_SYMBOL"] = ari_deprecate
758}
759/(^|[^_[:alnum:]])GCC_COMPILED_FLAG_SYMBOL([^_[:alnum:]]|$)/ {
760 fail("GCC_COMPILED_FLAG_SYMBOL")
761}
762
763BEGIN { doc["GCC2_COMPILED_FLAG_SYMBOL"] = "\
764Replace GCC2_COMPILED_FLAG_SYMBOL with nothing, not needed?"
765 category["GCC2_COMPILED_FLAG_SYMBOL"] = ari_deprecate
766}
767/(^|[^_[:alnum:]])GCC2_COMPILED_FLAG_SYMBOL([^_[:alnum:]]|$)/ {
768 fail("GCC2_COMPILED_FLAG_SYMBOL")
769}
770
771BEGIN { doc["FUNCTION_EPILOGUE_SIZE"] = "\
772Replace FUNCTION_EPILOGUE_SIZE with nothing, not needed?"
773 category["FUNCTION_EPILOGUE_SIZE"] = ari_regression
774}
775/(^|[^_[:alnum:]])FUNCTION_EPILOGUE_SIZE([^_[:alnum:]]|$)/ {
776 fail("FUNCTION_EPILOGUE_SIZE")
777}
778
779BEGIN { doc["HAVE_VFORK"] = "\
780Do not use HAVE_VFORK, instead include \"gdb_vfork.h\" and call vfork() \
781unconditionally"
782 category["HAVE_VFORK"] = ari_regression
783}
784/(^|[^_[:alnum:]])HAVE_VFORK([^_[:alnum:]]|$)/ {
785 fail("HAVE_VFORK")
786}
787
788BEGIN { doc["bcmp"] = "\
56f79b63 789Do not use bcmp(), C++11 implies memcmp()"
b786c521
PM
790 category["bcmp"] = ari_regression
791}
792/(^|[^_[:alnum:]])bcmp[[:space:]]*\(/ {
793 fail("bcmp")
794}
795
796BEGIN { doc["setlinebuf"] = "\
56f79b63 797Do not use setlinebuf(), C++11 implies setvbuf()"
b786c521
PM
798 category["setlinebuf"] = ari_regression
799}
800/(^|[^_[:alnum:]])setlinebuf[[:space:]]*\(/ {
801 fail("setlinebuf")
802}
803
804BEGIN { doc["bcopy"] = "\
56f79b63 805Do not use bcopy(), C++11 implies memcpy() and memmove()"
b786c521
PM
806 category["bcopy"] = ari_regression
807}
808/(^|[^_[:alnum:]])bcopy[[:space:]]*\(/ {
809 fail("bcopy")
810}
811
812BEGIN { doc["get_frame_base"] = "\
813Replace get_frame_base with get_frame_id, get_frame_base_address, \
814get_frame_locals_address, or get_frame_args_address."
815 category["get_frame_base"] = ari_obsolete
816}
817/(^|[^_[:alnum:]])get_frame_base([^_[:alnum:]]|$)/ {
818 fail("get_frame_base")
819}
820
821BEGIN { doc["floatformat_to_double"] = "\
822Do not use floatformat_to_double() from libierty, \
823instead use floatformat_to_doublest()"
b786c521
PM
824 category["floatformat_to_double"] = ari_regression
825}
826/(^|[^_[:alnum:]])floatformat_to_double[[:space:]]*\(/ {
827 fail("floatformat_to_double")
828}
829
830BEGIN { doc["floatformat_from_double"] = "\
831Do not use floatformat_from_double() from libierty, \
8aaaf757 832instead use host_float_ops<T>::from_target()"
b786c521
PM
833 category["floatformat_from_double"] = ari_regression
834}
835/(^|[^_[:alnum:]])floatformat_from_double[[:space:]]*\(/ {
836 fail("floatformat_from_double")
837}
838
839BEGIN { doc["BIG_ENDIAN"] = "\
840Do not use BIG_ENDIAN, instead use BFD_ENDIAN_BIG"
841 category["BIG_ENDIAN"] = ari_regression
842}
843/(^|[^_[:alnum:]])BIG_ENDIAN([^_[:alnum:]]|$)/ {
844 fail("BIG_ENDIAN")
845}
846
847BEGIN { doc["LITTLE_ENDIAN"] = "\
848Do not use LITTLE_ENDIAN, instead use BFD_ENDIAN_LITTLE";
849 category["LITTLE_ENDIAN"] = ari_regression
850}
851/(^|[^_[:alnum:]])LITTLE_ENDIAN([^_[:alnum:]]|$)/ {
852 fail("LITTLE_ENDIAN")
853}
854
855BEGIN { doc["BIG_ENDIAN"] = "\
856Do not use BIG_ENDIAN, instead use BFD_ENDIAN_BIG"
857 category["BIG_ENDIAN"] = ari_regression
858}
859/(^|[^_[:alnum:]])BIG_ENDIAN([^_[:alnum:]]|$)/ {
860 fail("BIG_ENDIAN")
861}
862
863BEGIN { doc["sec_ptr"] = "\
864Instead of sec_ptr, use struct bfd_section";
865 category["sec_ptr"] = ari_regression
866}
867/(^|[^_[:alnum:]])sec_ptr([^_[:alnum:]]|$)/ {
868 fail("sec_ptr")
869}
870
871BEGIN { doc["frame_unwind_unsigned_register"] = "\
872Replace frame_unwind_unsigned_register with frame_unwind_register_unsigned"
873 category["frame_unwind_unsigned_register"] = ari_regression
874}
875/(^|[^_[:alnum:]])frame_unwind_unsigned_register([^_[:alnum:]]|$)/ {
876 fail("frame_unwind_unsigned_register")
877}
878
879BEGIN { doc["frame_register_read"] = "\
880Replace frame_register_read() with get_frame_register(), or \
881possibly introduce a new method safe_get_frame_register()"
882 category["frame_register_read"] = ari_obsolete
883}
884/(^|[^_[:alnum:]])frame_register_read([^_[:alnum:]]|$)/ {
885 fail("frame_register_read")
886}
887
888BEGIN { doc["read_register"] = "\
889Replace read_register() with regcache_read() et.al."
890 category["read_register"] = ari_regression
891}
892/(^|[^_[:alnum:]])read_register([^_[:alnum:]]|$)/ {
893 fail("read_register")
894}
895
896BEGIN { doc["write_register"] = "\
897Replace write_register() with regcache_read() et.al."
898 category["write_register"] = ari_regression
899}
900/(^|[^_[:alnum:]])write_register([^_[:alnum:]]|$)/ {
901 fail("write_register")
902}
903
904function report(name) {
905 # Drop any trailing _P.
906 name = gensub(/(_P|_p)$/, "", 1, name)
907 # Convert to lower case
908 name = tolower(name)
909 # Split into category and bug
910 cat = gensub(/^([[:alpha:]]+)_([_[:alnum:]]*)$/, "\\1", 1, name)
911 bug = gensub(/^([[:alpha:]]+)_([_[:alnum:]]*)$/, "\\2", 1, name)
912 # Report it
913 name = cat " " bug
914 doc[name] = "Do not use " cat " " bug ", see declaration for details"
915 category[name] = cat
916 fail(name)
917}
918
919/(^|[^_[:alnum:]])(DEPRECATED|deprecated|set_gdbarch_deprecated|LEGACY|legacy|set_gdbarch_legacy)_/ {
920 line = $0
921 # print "0 =", $0
922 while (1) {
923 name = gensub(/^(|.*[^_[:alnum:]])((DEPRECATED|deprecated|LEGACY|legacy)_[_[:alnum:]]*)(.*)$/, "\\2", 1, line)
924 line = gensub(/^(|.*[^_[:alnum:]])((DEPRECATED|deprecated|LEGACY|legacy)_[_[:alnum:]]*)(.*)$/, "\\1 \\4", 1, line)
925 # print "name =", name, "line =", line
926 if (name == line) break;
927 report(name)
928 }
929}
930
931# Count the number of times each architecture method is set
932/(^|[^_[:alnum:]])set_gdbarch_[_[:alnum:]]*([^_[:alnum:]]|$)/ {
933 name = gensub(/^.*set_gdbarch_([_[:alnum:]]*).*$/, "\\1", 1, $0)
934 doc["set " name] = "\
935Call to set_gdbarch_" name
936 category["set " name] = ari_gdbarch
937 fail("set " name)
938}
939
940# Count the number of times each tm/xm/nm macro is defined or undefined
941/^#[[:space:]]*(undef|define)[[:space:]]+[[:alnum:]_]+.*$/ \
942&& !/^#[[:space:]]*(undef|define)[[:space:]]+[[:alnum:]_]+_H($|[[:space:]])/ \
943&& FILENAME ~ /(^|\/)config\/(|[^\/]*\/)(tm-|xm-|nm-).*\.h$/ {
944 basename = gensub(/(^|.*\/)([^\/]*)$/, "\\2", 1, FILENAME)
945 type = gensub(/^(tm|xm|nm)-.*\.h$/, "\\1", 1, basename)
946 name = gensub(/^#[[:space:]]*(undef|define)[[:space:]]+([[:alnum:]_]+).*$/, "\\2", 1, $0)
947 if (type == basename) {
948 type = "macro"
949 }
950 doc[type " " name] = "\
951Do not define macros such as " name " in a tm, nm or xm file, \
952in fact do not provide a tm, nm or xm file"
953 category[type " " name] = ari_macro
954 fail(type " " name)
955}
956
957BEGIN { doc["deprecated_registers"] = "\
958Replace deprecated_registers with nothing, they have reached \
959end-of-life"
960 category["deprecated_registers"] = ari_eol
961}
962/(^|[^_[:alnum:]])deprecated_registers([^_[:alnum:]]|$)/ {
963 fail("deprecated_registers")
964}
965
966BEGIN { doc["read_pc"] = "\
967Replace READ_PC() with frame_pc_unwind; \
968at present the inferior function call code still uses this"
969 category["read_pc"] = ari_deprecate
970}
971/(^|[^_[:alnum:]])read_pc[[:space:]]*\(/ || \
972/(^|[^_[:alnum:]])set_gdbarch_read_pc[[:space:]]*\(/ || \
973/(^|[^_[:alnum:]])TARGET_READ_PC[[:space:]]*\(/ {
974 fail("read_pc")
975}
976
977BEGIN { doc["write_pc"] = "\
978Replace write_pc() with get_frame_base_address or get_frame_id; \
979at present the inferior function call code still uses this when doing \
980a DECR_PC_AFTER_BREAK"
981 category["write_pc"] = ari_deprecate
982}
983/(^|[^_[:alnum:]])write_pc[[:space:]]*\(/ || \
b786c521
PM
984/(^|[^_[:alnum:]])TARGET_WRITE_PC[[:space:]]*\(/ {
985 fail("write_pc")
986}
987
988BEGIN { doc["generic_target_write_pc"] = "\
989Replace generic_target_write_pc with a per-architecture implementation, \
990this relies on PC_REGNUM which is being eliminated"
991 category["generic_target_write_pc"] = ari_regression
992}
993/(^|[^_[:alnum:]])generic_target_write_pc([^_[:alnum:]]|$)/ {
994 fail("generic_target_write_pc")
995}
996
997BEGIN { doc["read_sp"] = "\
998Replace read_sp() with frame_sp_unwind"
999 category["read_sp"] = ari_regression
1000}
1001/(^|[^_[:alnum:]])read_sp[[:space:]]*\(/ || \
1002/(^|[^_[:alnum:]])set_gdbarch_read_sp[[:space:]]*\(/ || \
1003/(^|[^_[:alnum:]])TARGET_READ_SP[[:space:]]*\(/ {
1004 fail("read_sp")
1005}
1006
1007BEGIN { doc["register_cached"] = "\
1008Replace register_cached() with nothing, does not have a regcache parameter"
1009 category["register_cached"] = ari_regression
1010}
1011/(^|[^_[:alnum:]])register_cached[[:space:]]*\(/ {
1012 fail("register_cached")
1013}
1014
1015BEGIN { doc["set_register_cached"] = "\
1016Replace set_register_cached() with nothing, does not have a regcache parameter"
1017 category["set_register_cached"] = ari_regression
1018}
1019/(^|[^_[:alnum:]])set_register_cached[[:space:]]*\(/ {
1020 fail("set_register_cached")
1021}
1022
1023# Print functions: Use versions that either check for buffer overflow
1024# or safely allocate a fresh buffer.
1025
1026BEGIN { doc["sprintf"] = "\
1027Do not use sprintf, instead use xsnprintf or xstrprintf"
1028 category["sprintf"] = ari_code
1029}
1030/(^|[^_[:alnum:]])sprintf[[:space:]]*\(/ {
1031 fail("sprintf")
1032}
1033
1034BEGIN { doc["vsprintf"] = "\
1035Do not use vsprintf(), instead use xstrvprintf"
1036 category["vsprintf"] = ari_regression
1037}
1038/(^|[^_[:alnum:]])vsprintf[[:space:]]*\(/ {
1039 fail("vsprintf")
1040}
1041
1042BEGIN { doc["asprintf"] = "\
1043Do not use asprintf(), instead use xstrprintf()"
1044 category["asprintf"] = ari_regression
1045}
1046/(^|[^_[:alnum:]])asprintf[[:space:]]*\(/ {
1047 fail("asprintf")
1048}
1049
1050BEGIN { doc["vasprintf"] = "\
1051Do not use vasprintf(), instead use xstrvprintf"
268a13a5 1052 fix("vasprintf", "gdbsupport/common-utils.c", 1)
b786c521
PM
1053 category["vasprintf"] = ari_regression
1054}
1055/(^|[^_[:alnum:]])vasprintf[[:space:]]*\(/ {
1056 fail("vasprintf")
1057}
1058
cc188e5f
JB
1059BEGIN { doc["printf_vma"] = "\
1060Do not use printf_vma, instead use paddress or phex_nz"
1061 category["printf_vma"] = ari_code
1062}
1063/(^|[^_[:alnum:]])printf_vma[[:space:]]*\(/ {
1064 fail("printf_vma")
1065}
1066
1067BEGIN { doc["sprintf_vma"] = "\
1068Do not use sprintf_vma, instead use paddress or phex_nz"
1069 category["sprintf_vma"] = ari_code
1070}
1071/(^|[^_[:alnum:]])sprintf_vma[[:space:]]*\(/ {
1072 fail("sprintf_vma")
1073}
1074
b786c521
PM
1075# More generic memory operations
1076
1077BEGIN { doc["bzero"] = "\
1078Do not use bzero(), instead use memset()"
1079 category["bzero"] = ari_regression
1080}
1081/(^|[^_[:alnum:]])bzero[[:space:]]*\(/ {
1082 fail("bzero")
1083}
1084
1085BEGIN { doc["strdup"] = "\
1086Do not use strdup(), instead use xstrdup()";
1087 category["strdup"] = ari_regression
1088}
1089/(^|[^_[:alnum:]])strdup[[:space:]]*\(/ {
1090 fail("strdup")
1091}
1092
1093BEGIN { doc["strsave"] = "\
1094Do not use strsave(), instead use xstrdup() et.al."
1095 category["strsave"] = ari_regression
1096}
1097/(^|[^_[:alnum:]])strsave[[:space:]]*\(/ {
1098 fail("strsave")
1099}
1100
1101# String compare functions
1102
1103BEGIN { doc["strnicmp"] = "\
1104Do not use strnicmp(), instead use strncasecmp()"
1105 category["strnicmp"] = ari_regression
1106}
1107/(^|[^_[:alnum:]])strnicmp[[:space:]]*\(/ {
1108 fail("strnicmp")
1109}
1110
b786c521
PM
1111# Typedefs that are either redundant or can be reduced to `struct
1112# type *''.
1113# Must be placed before if assignment otherwise ARI exceptions
1114# are not handled correctly.
1115
1116BEGIN { doc["d_namelen"] = "\
1117Do not use dirent.d_namelen, instead use NAMELEN"
1118 category["d_namelen"] = ari_regression
1119}
1120/(^|[^_[:alnum:]])d_namelen([^_[:alnum:]]|$)/ {
1121 fail("d_namelen")
1122}
1123
1124BEGIN { doc["strlen d_name"] = "\
1125Do not use strlen dirent.d_name, instead use NAMELEN"
1126 category["strlen d_name"] = ari_regression
1127}
1128/(^|[^_[:alnum:]])strlen[[:space:]]*\(.*[^_[:alnum:]]d_name([^_[:alnum:]]|$)/ {
1129 fail("strlen d_name")
1130}
1131
b786c521
PM
1132BEGIN { doc["generic_use_struct_convention"] = "\
1133Replace generic_use_struct_convention with nothing, \
1134EXTRACT_STRUCT_VALUE_ADDRESS is a predicate"
1135 category["generic_use_struct_convention"] = ari_regression
1136}
1137/(^|[^_[:alnum:]])generic_use_struct_convention([^_[:alnum:]]|$)/ {
1138 fail("generic_use_struct_convention")
1139}
1140
1141BEGIN { doc["if assignment"] = "\
1142An IF statement'\''s expression contains an assignment (the GNU coding \
1143standard discourages this)"
1144 category["if assignment"] = ari_code
1145}
1146BEGIN { doc["if clause more than 50 lines"] = "\
1147An IF statement'\''s expression expands over 50 lines"
1148 category["if clause more than 50 lines"] = ari_code
1149}
1150#
1151# Accumulate continuation lines
1152FNR == 1 {
1153 in_if = 0
1154}
1155
1156/(^|[^_[:alnum:]])if / {
1157 in_if = 1;
1158 if_brace_level = 0;
1159 if_cont_p = 0;
1160 if_count = 0;
1161 if_brace_end_pos = 0;
1162 if_full_line = "";
1163}
1164(in_if) {
1165 # We want everything up to closing brace of same level
1166 if_count++;
1167 if (if_count > 50) {
1168 print "multiline if: " if_full_line $0
1169 fail("if clause more than 50 lines")
1170 if_brace_level = 0;
1171 if_full_line = "";
1172 } else {
1173 if (if_count == 1) {
1174 i = index($0,"if ");
1175 } else {
1176 i = 1;
1177 }
1178 for (i=i; i <= length($0); i++) {
1179 char = substr($0,i,1);
1180 if (char == "(") { if_brace_level++; }
1181 if (char == ")") {
1182 if_brace_level--;
1183 if (!if_brace_level) {
1184 if_brace_end_pos = i;
1185 after_if = substr($0,i+1,length($0));
1186 # Do not parse what is following
1187 break;
1188 }
1189 }
1190 }
1191 if (if_brace_level == 0) {
1192 $0 = substr($0,1,i);
1193 in_if = 0;
1194 } else {
1195 if_full_line = if_full_line $0;
1196 if_cont_p = 1;
1197 next;
1198 }
1199 }
1200}
1201# if we arrive here, we need to concatenate, but we are at brace level 0
1202
1203(if_brace_end_pos) {
1204 $0 = if_full_line substr($0,1,if_brace_end_pos);
1205 if (if_count > 1) {
1206 # print "IF: multi line " if_count " found at " FILENAME ":" FNR " \"" $0 "\""
1207 }
1208 if_cont_p = 0;
1209 if_full_line = "";
1210}
1211/(^|[^_[:alnum:]])if .* = / {
1212 # print "fail in if " $0
1213 fail("if assignment")
1214}
1215(if_brace_end_pos) {
1216 $0 = $0 after_if;
1217 if_brace_end_pos = 0;
1218 in_if = 0;
1219}
1220
1221# Printout of all found bug
1222
1223BEGIN {
1224 if (print_doc) {
1225 for (bug in doc) {
1226 fail(bug)
1227 }
1228 exit
1229 }
1230}' "$@"
1231
This page took 0.539017 seconds and 4 git commands to generate.