aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/coccinelle.txt
diff options
context:
space:
mode:
Diffstat (limited to 'Documentation/coccinelle.txt')
-rw-r--r--Documentation/coccinelle.txt54
1 files changed, 43 insertions, 11 deletions
diff --git a/Documentation/coccinelle.txt b/Documentation/coccinelle.txt
index cd2b02837066..96b690348ba1 100644
--- a/Documentation/coccinelle.txt
+++ b/Documentation/coccinelle.txt
@@ -24,6 +24,9 @@ of many distributions, e.g. :
24You can get the latest version released from the Coccinelle homepage at 24You can get the latest version released from the Coccinelle homepage at
25http://coccinelle.lip6.fr/ 25http://coccinelle.lip6.fr/
26 26
27Information and tips about Coccinelle are also provided on the wiki
28pages at http://cocci.ekstranet.diku.dk/wiki/doku.php
29
27Once you have it, run the following command: 30Once you have it, run the following command:
28 31
29 ./configure 32 ./configure
@@ -33,6 +36,10 @@ as a regular user, and install it with
33 36
34 sudo make install 37 sudo make install
35 38
39The semantic patches in the kernel will work best with Coccinelle version
400.2.4 or later. Using earlier versions may incur some parse errors in the
41semantic patch code, but any results that are obtained should still be
42correct.
36 43
37 Using Coccinelle on the Linux kernel 44 Using Coccinelle on the Linux kernel
38~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 45~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -41,20 +48,22 @@ A Coccinelle-specific target is defined in the top level
41Makefile. This target is named 'coccicheck' and calls the 'coccicheck' 48Makefile. This target is named 'coccicheck' and calls the 'coccicheck'
42front-end in the 'scripts' directory. 49front-end in the 'scripts' directory.
43 50
44Four modes are defined: report, patch, context, and org. The mode to 51Four modes are defined: patch, report, context, and org. The mode to
45use is specified by setting the MODE variable with 'MODE=<mode>'. 52use is specified by setting the MODE variable with 'MODE=<mode>'.
46 53
54'patch' proposes a fix, when possible.
55
47'report' generates a list in the following format: 56'report' generates a list in the following format:
48 file:line:column-column: message 57 file:line:column-column: message
49 58
50'patch' proposes a fix, when possible.
51
52'context' highlights lines of interest and their context in a 59'context' highlights lines of interest and their context in a
53diff-like style.Lines of interest are indicated with '-'. 60diff-like style.Lines of interest are indicated with '-'.
54 61
55'org' generates a report in the Org mode format of Emacs. 62'org' generates a report in the Org mode format of Emacs.
56 63
57Note that not all semantic patches implement all modes. 64Note that not all semantic patches implement all modes. For easy use
65of Coccinelle, the default mode is "chain" which tries the previous
66modes in the order above until one succeeds.
58 67
59To make a report for every semantic patch, run the following command: 68To make a report for every semantic patch, run the following command:
60 69
@@ -68,9 +77,9 @@ To produce patches, run:
68 77
69 78
70The coccicheck target applies every semantic patch available in the 79The coccicheck target applies every semantic patch available in the
71subdirectories of 'scripts/coccinelle' to the entire Linux kernel. 80sub-directories of 'scripts/coccinelle' to the entire Linux kernel.
72 81
73For each semantic patch, a changelog message is proposed. It gives a 82For each semantic patch, a commit message is proposed. It gives a
74description of the problem being checked by the semantic patch, and 83description of the problem being checked by the semantic patch, and
75includes a reference to Coccinelle. 84includes a reference to Coccinelle.
76 85
@@ -93,12 +102,35 @@ or
93 make coccicheck COCCI=<my_SP.cocci> MODE=report 102 make coccicheck COCCI=<my_SP.cocci> MODE=report
94 103
95 104
105 Using Coccinelle on (modified) files
106~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
107
108To apply Coccinelle on a file basis, instead of a directory basis, the
109following command may be used:
110
111 make C=1 CHECK="scripts/coccicheck"
112
113To check only newly edited code, use the value 2 for the C flag, i.e.
114
115 make C=2 CHECK="scripts/coccicheck"
116
117This runs every semantic patch in scripts/coccinelle by default. The
118COCCI variable may additionally be used to only apply a single
119semantic patch as shown in the previous section.
120
121The "chain" mode is the default. You can select another one with the
122MODE variable explained above.
123
124In this mode, there is no information about semantic patches
125displayed, and no commit message proposed.
126
127
96 Proposing new semantic patches 128 Proposing new semantic patches
97~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 129~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
98 130
99New semantic patches can be proposed and submitted by kernel 131New semantic patches can be proposed and submitted by kernel
100developers. For sake of clarity, they should be organized in the 132developers. For sake of clarity, they should be organized in the
101subdirectories of 'scripts/coccinelle/'. 133sub-directories of 'scripts/coccinelle/'.
102 134
103 135
104 Detailed description of the 'report' mode 136 Detailed description of the 'report' mode
@@ -111,7 +143,7 @@ Example:
111 143
112Running 144Running
113 145
114 make coccicheck MODE=report COCCI=scripts/coccinelle/err_cast.cocci 146 make coccicheck MODE=report COCCI=scripts/coccinelle/api/err_cast.cocci
115 147
116will execute the following part of the SmPL script. 148will execute the following part of the SmPL script.
117 149
@@ -149,7 +181,7 @@ identified.
149Example: 181Example:
150 182
151Running 183Running
152 make coccicheck MODE=patch COCCI=scripts/coccinelle/err_cast.cocci 184 make coccicheck MODE=patch COCCI=scripts/coccinelle/api/err_cast.cocci
153 185
154will execute the following part of the SmPL script. 186will execute the following part of the SmPL script.
155 187
@@ -193,7 +225,7 @@ NOTE: The diff-like output generated is NOT an applicable patch. The
193Example: 225Example:
194 226
195Running 227Running
196 make coccicheck MODE=context COCCI=scripts/coccinelle/err_cast.cocci 228 make coccicheck MODE=context COCCI=scripts/coccinelle/api/err_cast.cocci
197 229
198will execute the following part of the SmPL script. 230will execute the following part of the SmPL script.
199 231
@@ -228,7 +260,7 @@ diff -u -p /home/user/linux/crypto/ctr.c /tmp/nothing
228Example: 260Example:
229 261
230Running 262Running
231 make coccicheck MODE=org COCCI=scripts/coccinelle/err_cast.cocci 263 make coccicheck MODE=org COCCI=scripts/coccinelle/api/err_cast.cocci
232 264
233will execute the following part of the SmPL script. 265will execute the following part of the SmPL script.
234 266