From: Roel Kluin <12o3l@tiscali.nl>
To: kernel-janitors@vger.kernel.org
Subject: bash script to parse DPRINTKs etc.
Date: Tue, 02 Oct 2007 00:04:18 +0000 [thread overview]
Message-ID: <47018B02.5000906@tiscali.nl> (raw)
I wrote this bash script to change DPRINTK and other non-standard debugging to a form that can be added as a menu option.
it does not add the kconfig options, I'm not sure how to put that in this script. It appends to a file ../kcs what Kconfig file it thinks that should be edited, and the CONFIG_*_DEBUG option to add there, and the source file in which changes were made.
---
query="^[ \t]*#[ \t]*define[ \t]*[A-Za-z0-9_]*([ \t]*\([A-Za-z0-9_]*\)[\.]*[ \t]*)[ \t]*printk([ \t]*\1[ \t]*)[ \t]*$"
m0[0]="^[ \t]*#[ \t]*if[ \t]0[ \t]*$"
m0[1]="^[ \t]*#[ \t]*ifdef[ \t]*[a-zA-Z0-9_]*[ \t]*$"
m0[2]="^[ \t]*#[ \t]*if[ \t]*[a-zA-Z0-9_]*[ \t]*$"
m0[3]="^[ \t]*#[ \t]*ifndef[ \t]*[a-zA-Z0-9_]*[ \t]*$"
m[1]="^[ \t]*#[ \t]*define[ \t]*[A-Za-z0-9_]*([ \t]*\([A-Za-z0-9_]*\)[\.]*[ \t]*)[ \t]*printk([ \t]*\1[ \t]*)[ \t]*$"
m[2]="^[ \t]*#[ \t]*else[ \t]*$"
m[3]="^[ \t]*#[ \t]*define[ \t]*[a-zA-Z0-9_]*([a-zA-Z0-9_]*[\.]*)[ \t]*$"
m[4]="^[ \t]*#[ \t]*endif[ \t]*$"
# TODO: also for .h files (and files that include them)
#$dbg="echo"
for f in `find -name *.[c]`; do
grep -q "${m[1]}" $f
if [ $? -eq 0 ]; then
echo $f
match=`grep -B1 -A3 "${m[1]}" $f`;
let i=0
ret=$( echo "${match}" | while read line; do
if [ $i -ne 0 ]; then
if [ -z "`echo "$line" | grep "${m[$i]}"`" ]; then
echo fail;
break;
fi
else
tmp=$( for w in ${#m0[@]}; do
if [ "`echo "$line" | grep "${m0[$w]}"`" ]; then
echo $w;
fi
done )
if [ -z "$tmp" ]; then
echo fail;
break;
else
echo $w;
fi
fi
let i++
done )
if [ "$ret" = "fail" ]; then
echo sorry, failed:
grep -B1 -A3 "${m[1]}" $f
echo "------------------"
continue;
fi
head -n60 $f;
echo "${match}";
echo "enter a CONFIG string for file $f (omit CONFIG_ and _DEBUG; end with ctrl+D; \"q\" will exit script)"
test=$(cat)
[ "$test" = "q" ] && exit 0;
test="CONFIG_${test#CONFIG_}"
test="${test%CONFIG_}_DEBUG"
echo string entered was $test
echo -n "$test " >> ../kcs
# TODO Kconfig edit
dir=`dirname $f`
while [ ! -f "$dir/Kconfig" ]; do
dir="${dir%/*}"
if [ "$dir" = "." ]; then
echo could not find Kconfig for $f
continue;
fi
done
echo -n "$dir/Kconfig " >> ../kcs
echo "$f" >> ../kcs
linenr=`grep -n "${m[1]}" $f | cut -d ":" -f1`;
qr=`echo "$match" | sed -n "/^[ \t]*#[ \t]*define[ \t]*\([A-Za-z0-9_]*\)(.*printk.*/ s/^[ \t]*#[ \t]*define[ \t]*\([A-Za-z0-9_]*\)(.*printk.*/\1/p"`
$dbg sed -i "/$qr/ s/$qr/pr_debug/g" $f
sed -n "/$qr/ s/$qr/pr_debug/p" $f
if [ "$ret" = "0" ]; then
continue;
elif [ "$ret" = "1" ]; then
qr2=`echo "$match" | sed -n "/^[ \t]*#[ \t]*ifdef[ \t]*\([a-zA-Z0-9_]*\)[ \t]*$/ s/^[ \t]*#[ \t]*ifdef[ \t]*\([a-zA-Z0-9_]*\)[ \t]*$/\1/p"`
elif [ "$ret" = "2" ]; then
qr2=`echo "$match" | sed -n "/^[ \t]*#[ \t]*if[ \t]*\([a-zA-Z0-9_]*\)[ \t]*$/ s/^[ \t]*#[ \t]*if[ \t]*\([a-zA-Z0-9_]*\)[ \t]*$/\1/p"`
elif [ "$ret" = "3" ]; then
qr2=`echo "$match" | sed -n "/^[ \t]*#[ \t]*ifndef[ \t]*\([a-zA-Z0-9_]*\)[ \t]*$/ s/^[ \t]*#[ \t]*ifndef[ \t]*\([a-zA-Z0-9_]*\)[ \t]*$/\1/p"`
fi
$dbg sed -i "/[ \t]*#[ \t]*undef[ \t]*$qr2[ \t]*$/d" $f
sed -n "/[ \t]*#[ \t]*undef[ \t]*$qr2[ \t]*$/p" $f
$dbg sed -i "/[ \t]*#[ \t]*define[ \t]*$qr2[ \t]*$/d" $f
sed -n "/[ \t]*#[ \t]*define[ \t]*$qr2[ \t]*$/p" $f
$dbg sed -i "`expr $linenr - 1` s/.*/#ifdef $test/" $f
sed -n "`expr $linenr - 1` s/.*/#ifdef $test/p" $f
$dbg sed -i "`expr $linenr` s/.*/#\tdefine DEBUG 1/" $f
sed -n "`expr $linenr` s/.*/#\tdefine DEBUG 1/p" $f
$dbg sed -i "`expr $linenr + 1` s/.*/#endif/" $f
sed -n "`expr $linenr + 1` s/.*/#endif/p" $f
$dbg sed -i "`expr $linenr + 2` s/.*/#include <linux\/kernel\.h>/" $f
sed -n "`expr $linenr + 2` s/.*/#include <linux\/kernel\.h>/p" $f
$dbg sed -i "`expr $linenr + 3`d" $f
fi
done
reply other threads:[~2007-10-02 0:04 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=47018B02.5000906@tiscali.nl \
--to=12o3l@tiscali.nl \
--cc=kernel-janitors@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.