header dependency; Was: [rfc] Re-merged regcache.h patch
Andrew Cagney
ac131313@cygnus.com
Wed Feb 28 07:29:00 GMT 2001
Hello,
When revising the regcache.h patch, I knocked up the attatched (perl
free zone :-) script. It grubs around the source identifying which .c
files actually use functions/variables from a given header file.
While this script is probably best treated as a novelty - it only just
works for regcache.h - I'm wondering if anyone knows of a GPL package
that does this analysis properly.
Andrew
#!/bin/sh
parser=/tmp/do-analize-include-parse
refs=/tmp/do-analize-include-refs
files=/tmp/do-analize-include-files
good=/tmp/do-analize-include-good
rm ${parser}
rm ${refs}
# Generate a parser to recognize any reference to a method in "$@"
echo "Creating parse script" 1>&2
cat "$@" | awk '
# external pointer
$0 != n = gensub (/^extern [^\(\*]*\*([_[:alpha:]][_[:alnum:]]*);$/, "\\1", 1) {
print "/[^[:alnum:]]" n "[[:space:]]*\\[/ { p = 1 } # pointer"
}
$0 != n = gensub (/^extern [^\(]*[^_\([:alnum:]]([_[:alpha:]][_[:alnum:]]*)[[:space:]]\(.*$/, "\\1", 1) {
print "/[^[:alnum:]]" n "[[:space:]]*\\(/ { p = 1 } # function"
}
' >> ${parser}
cat <<EOF >> ${parser}
p { print FILENAME ":" NR ":" \$0; p = 0; }
EOF
cat ${parser}
# Parse the source files printing out a list of all references
echo "Parsing" 1>&2
find * \
-name '*-stub.c' -prune \
-o -name 'nlm' -prune \
-o -name 'gdbserver' -prune \
-o -name 'testsuite' -prune \
-o -name '*\.c' -type f -print | xargs awk -f ${parser} > ${refs}
# Create a summary file of files containing refs
cut -d: -f1 < ${refs} | sort -u > ${files}
# Check to see if the file includes our target
xargs grep -e '#include *"'$1'"' < ${files} | cut -d: -f 1 | sort > ${good}
diff ${good} ${files}
More information about the Gdb
mailing list