Skip to content

Commit 3544d5c

Browse files
committed
Merge tag 'cocci-7.0-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/jlawall/linux
Pull coccinelle updates from Julia Lawall: "This simplifies and clarifies the handling of output generated by Coccinelle that is sent to standard error. By default, this goes to /dev/null. Remind the user of that and encourage them to provide another file name (Benjamin Philip)" * tag 'cocci-7.0-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/jlawall/linux: Documentation: Coccinelle: document debug log handling scripts: coccicheck: warn on unset debug file scripts: coccicheck: simplify debug file handling
2 parents 9813616 + e3a22b5 commit 3544d5c

2 files changed

Lines changed: 29 additions & 13 deletions

File tree

Documentation/dev-tools/coccinelle.rst

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,18 @@ To enable verbose messages set the V= variable, for example::
127127

128128
make coccicheck MODE=report V=1
129129

130+
By default, coccicheck will print debug logs to stdout and redirect stderr to
131+
/dev/null. This can make coccicheck output difficult to read and understand.
132+
Debug and error messages can instead be written to a debug file instead by
133+
setting the ``DEBUG_FILE`` variable::
134+
135+
make coccicheck MODE=report DEBUG_FILE="cocci.log"
136+
137+
Coccinelle cannot overwrite a debug file. Instead of repeatedly deleting a log
138+
file, you could include the datetime in the debug file name::
139+
140+
make coccicheck MODE=report DEBUG_FILE="cocci-$(date -Iseconds).log"
141+
130142
Coccinelle parallelization
131143
--------------------------
132144

@@ -208,11 +220,10 @@ include options matching the options used when we compile the kernel.
208220
You can learn what these options are by using V=1; you could then
209221
manually run Coccinelle with debug options added.
210222

211-
Alternatively you can debug running Coccinelle against SmPL patches
212-
by asking for stderr to be redirected to stderr. By default stderr
213-
is redirected to /dev/null; if you'd like to capture stderr you
214-
can specify the ``DEBUG_FILE="file.txt"`` option to coccicheck. For
215-
instance::
223+
An easier approach to debug running Coccinelle against SmPL patches is to ask
224+
coccicheck to redirect stderr to a debug file. As mentioned in the examples, by
225+
default stderr is redirected to /dev/null; if you'd like to capture stderr you
226+
can specify the ``DEBUG_FILE="file.txt"`` option to coccicheck. For instance::
216227

217228
rm -f cocci.err
218229
make coccicheck COCCI=scripts/coccinelle/free/kfree.cocci MODE=report DEBUG_FILE=cocci.err

scripts/coccicheck

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ run_cmd_parmap() {
138138
if [ $VERBOSE -ne 0 ] ; then
139139
echo "Running ($NPROC in parallel): $@"
140140
fi
141-
if [ "$DEBUG_FILE" != "/dev/null" -a "$DEBUG_FILE" != "" ]; then
141+
if [ "$DEBUG_FILE" != "/dev/null" ]; then
142142
echo $@>>$DEBUG_FILE
143143
$@ 2>>$DEBUG_FILE
144144
else
@@ -259,13 +259,18 @@ coccinelle () {
259259

260260
}
261261

262-
if [ "$DEBUG_FILE" != "/dev/null" -a "$DEBUG_FILE" != "" ]; then
263-
if [ -f $DEBUG_FILE ]; then
264-
echo "Debug file $DEBUG_FILE exists, bailing"
265-
exit
266-
fi
267-
else
268-
DEBUG_FILE="/dev/null"
262+
if [ "$DEBUG_FILE" = "" ]; then
263+
echo 'You have not explicitly specified the debug file to use.'
264+
echo 'Using default "/dev/null" as debug file.'
265+
echo 'Debug logs will be printed to stdout.'
266+
echo 'You can specify the debug file with "make coccicheck DEBUG_FILE=<debug_file>"'
267+
echo ''
268+
DEBUG_FILE="/dev/null"
269+
fi
270+
271+
if [ -f $DEBUG_FILE ]; then
272+
echo "Debug file $DEBUG_FILE exists, bailing"
273+
exit
269274
fi
270275

271276
if [ "$COCCI" = "" ] ; then

0 commit comments

Comments
 (0)