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