* [Cocci] How to use coccinelle as a kind of grep -l ?
@ 2014-12-01 10:12 Francois Berenger
2014-12-01 10:23 ` Francois Berenger
2014-12-01 10:24 ` Julia Lawall
0 siblings, 2 replies; 4+ messages in thread
From: Francois Berenger @ 2014-12-01 10:12 UTC (permalink / raw)
To: cocci
Hello,
Inside of applying any patch, I need to use coccinelle
in order to detect certain C files that match a given pattern
in a source code tree.
Is it possible to use coccinelle for that, how?
--
Regards,
Francois.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Cocci] How to use coccinelle as a kind of grep -l ?
2014-12-01 10:12 [Cocci] How to use coccinelle as a kind of grep -l ? Francois Berenger
@ 2014-12-01 10:23 ` Francois Berenger
2014-12-01 10:37 ` Nicholas Mc Guire
2014-12-01 10:24 ` Julia Lawall
1 sibling, 1 reply; 4+ messages in thread
From: Francois Berenger @ 2014-12-01 10:23 UTC (permalink / raw)
To: cocci
On 12/01/2014 11:12 AM, Francois Berenger wrote:
> Hello,
>
Instead of applying ...
> Inside of applying any patch, I need to use coccinelle
> in order to detect certain C files that match a given pattern
> in a source code tree.
>
> Is it possible to use coccinelle for that, how?
>
--
Regards,
Francois.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Cocci] How to use coccinelle as a kind of grep -l ?
2014-12-01 10:12 [Cocci] How to use coccinelle as a kind of grep -l ? Francois Berenger
2014-12-01 10:23 ` Francois Berenger
@ 2014-12-01 10:24 ` Julia Lawall
1 sibling, 0 replies; 4+ messages in thread
From: Julia Lawall @ 2014-12-01 10:24 UTC (permalink / raw)
To: cocci
On Mon, 1 Dec 2014, Francois Berenger wrote:
> Hello,
>
> Inside of applying any patch, I need to use coccinelle
> in order to detect certain C files that match a given pattern
> in a source code tree.
>
> Is it possible to use coccinelle for that, how?
Yes. One way is to put * on the lines of interest, in place of - or +.
Then you will get a diff in which the matched lines of interest are marked
with -. With emacs diff mode, you can jump from the diff to the context
in the source file.
Another way is to use position variables and use ocaml or python to print
a message indicating wher you found whatever is of interest.
You can find many examples of both uses in the examples in the Linux
kernel source tree, in the scripts/coccinelle subdirectory.
julia
>
> --
> Regards,
> Francois.
> _______________________________________________
> Cocci mailing list
> Cocci at systeme.lip6.fr
> https://systeme.lip6.fr/mailman/listinfo/cocci
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Cocci] How to use coccinelle as a kind of grep -l ?
2014-12-01 10:23 ` Francois Berenger
@ 2014-12-01 10:37 ` Nicholas Mc Guire
0 siblings, 0 replies; 4+ messages in thread
From: Nicholas Mc Guire @ 2014-12-01 10:37 UTC (permalink / raw)
To: cocci
On Mon, 01 Dec 2014, Francois Berenger wrote:
> On 12/01/2014 11:12 AM, Francois Berenger wrote:
>> Hello,
>>
>
> Instead of applying ...
>
>> Inside of applying any patch, I need to use coccinelle
>> in order to detect certain C files that match a given pattern
>> in a source code tree.
>>
>> Is it possible to use coccinelle for that, how?
>>
>
here is a simple (hopefuly correct) example of a scanner - that will look
for inbalanced use of spinlocks and bh disable/enable - it reports one
line per file that matches giving the name and line-numbers of the
potentially inballanced calls.
@r1@
identifier f;
expression E;
position p1,p2,p3;
@@
f(...) {
<...
(
spin_lock_bh(E)@p1;
...
spin_unlock(E)@p2;
...
local_bh_enable()@p3;
|
local_bh_disable()@p2;
...
spin_lock(E)@p3;
...
spin_unlock_bh(E)@p1;
)
...>
}
@script:python@
p1 << r1.p1;
p2 << r1.p2;
p3 << r1.p3;
@@
print "file:%s at lines %s %s %s" % (p1[0].file,p1[0].line, p2[0].line, p3[0].line)
put this in a file called scan.cocci and running with the below command
gives me:
hofrat at debian:/usr/src/linux-next$ spatch --cocci-file /tmp/scan.cocci --dir net/core/
HANDLING: net/core/datagram.c
HANDLING: net/core/netpoll.c
...
HANDLING: net/core/sock.c
file:net/core/sock.c at lines 2396 2406 2411
file:net/core/sock.c@lines 2346 2350 2355
...
thx!
hofrat
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-12-01 10:37 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-01 10:12 [Cocci] How to use coccinelle as a kind of grep -l ? Francois Berenger
2014-12-01 10:23 ` Francois Berenger
2014-12-01 10:37 ` Nicholas Mc Guire
2014-12-01 10:24 ` Julia Lawall
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.