This is the mail archive of the gdb@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

header dependency; Was: [rfc] Re-merged regcache.h patch


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}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]