* [Cocci] Problem matching macro invoked on file scope
@ 2013-01-07 15:34 Håkon Løvdal
2013-01-07 15:43 ` Lars-Peter Clausen
2013-01-07 15:45 ` Julia Lawall
0 siblings, 2 replies; 6+ messages in thread
From: Håkon Løvdal @ 2013-01-07 15:34 UTC (permalink / raw)
To: cocci
Hi list. I have trouble getting coccinelle to match macros invoked on
file scope (as opposed to invoked inside a function).
Example: grepping the whole linux source code for ASYNC_DOMAIN gets
three matches:
linux/drivers/scsi/scsi.c:ASYNC_DOMAIN(scsi_sd_probe_domain);
linux/include/linux/async.h:#define ASYNC_DOMAIN(_name) \
linux/kernel/async.c:static ASYNC_DOMAIN(async_running);
so if I want to know what identifier names that are used as arguments
to ASYNC_DOMAIN I see the answer right there, but let's say I want to
use coccinelle to find the answer.
$ cat find_ASYNC_DOMAIN.cocci
@rule1@
identifier id;
@@
ASYNC_DOMAIN(id);
@script:python@
id << rule1.id;
@@
print "ASYNC_DOMAIN is called with _name equal to %s" % (id)
$ ./spatch --sp-file find_ASYNC_DOMAIN.cocci linux/drivers/scsi/scsi.c
linux/kernel/async.c
init_defs_builtins: /tmp/coccinelle/share/coccinelle/standard.h
HANDLING: linux/drivers/scsi/scsi.c linux/kernel/async.c
$ cat dummy_async_domain_test.c
ASYNC_DOMAIN(mytest1);
ASYNC_DOMAIN(
mytest2
);
int main(int argc, char *argv[])
{
ASYNC_DOMAIN(mytest3);
ASYNC_DOMAIN(
mytest4
);
return 0;
}
$ ./spatch --sp-file find_ASYNC_DOMAIN.cocci dummy_async_domain_test.c
init_defs_builtins: /tmp/coccinelle/share/coccinelle/standard.h
HANDLING: dummy_async_domain_test.c
ASYNC_DOMAIN is called with _name equal to mytest3
ASYNC_DOMAIN is called with _name equal to mytest4
$
As you can see the script fails to match ASYNC_DOMAIN when it is put on
file scope but if I put it inside a function it is found. What do I need
to change in order to match on file scope?
BR H?kon L?vdal
PS
This was sort of a continuation of my last post, but I drilled down to the
problem to be just macro on file scope and I though it is more clean to
start a new thread.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Cocci] Problem matching macro invoked on file scope
2013-01-07 15:34 [Cocci] Problem matching macro invoked on file scope Håkon Løvdal
@ 2013-01-07 15:43 ` Lars-Peter Clausen
2013-01-08 9:22 ` Håkon Løvdal
2013-01-07 15:45 ` Julia Lawall
1 sibling, 1 reply; 6+ messages in thread
From: Lars-Peter Clausen @ 2013-01-07 15:43 UTC (permalink / raw)
To: cocci
On 01/07/2013 04:34 PM, H?kon L?vdal wrote:
> Hi list. I have trouble getting coccinelle to match macros invoked on
> file scope (as opposed to invoked inside a function).
>
> Example: grepping the whole linux source code for ASYNC_DOMAIN gets
> three matches:
>
> linux/drivers/scsi/scsi.c:ASYNC_DOMAIN(scsi_sd_probe_domain);
> linux/include/linux/async.h:#define ASYNC_DOMAIN(_name) \
> linux/kernel/async.c:static ASYNC_DOMAIN(async_running);
>
> so if I want to know what identifier names that are used as arguments
> to ASYNC_DOMAIN I see the answer right there, but let's say I want to
> use coccinelle to find the answer.
>
>
>
> $ cat find_ASYNC_DOMAIN.cocci
>
> @rule1@
> identifier id;
> @@
>
> ASYNC_DOMAIN(id);
>
> @script:python@
> id << rule1.id;
> @@
>
> print "ASYNC_DOMAIN is called with _name equal to %s" % (id)
>
>
> $ ./spatch --sp-file find_ASYNC_DOMAIN.cocci linux/drivers/scsi/scsi.c
> linux/kernel/async.c
> init_defs_builtins: /tmp/coccinelle/share/coccinelle/standard.h
> HANDLING: linux/drivers/scsi/scsi.c linux/kernel/async.c
> $ cat dummy_async_domain_test.c
>
>
> ASYNC_DOMAIN(mytest1);
> ASYNC_DOMAIN(
> mytest2
> );
>
> int main(int argc, char *argv[])
> {
> ASYNC_DOMAIN(mytest3);
> ASYNC_DOMAIN(
> mytest4
> );
> return 0;
> }
>
> $ ./spatch --sp-file find_ASYNC_DOMAIN.cocci dummy_async_domain_test.c
> init_defs_builtins: /tmp/coccinelle/share/coccinelle/standard.h
> HANDLING: dummy_async_domain_test.c
> ASYNC_DOMAIN is called with _name equal to mytest3
> ASYNC_DOMAIN is called with _name equal to mytest4
> $
>
>
>
> As you can see the script fails to match ASYNC_DOMAIN when it is put on
> file scope but if I put it inside a function it is found. What do I need
> to change in order to match on file scope?
>
Hi,
try to add
declarer name ASYNC_DOMAIN;
to your cocci rule.
- Lars
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Cocci] Problem matching macro invoked on file scope
2013-01-07 15:34 [Cocci] Problem matching macro invoked on file scope Håkon Løvdal
2013-01-07 15:43 ` Lars-Peter Clausen
@ 2013-01-07 15:45 ` Julia Lawall
1 sibling, 0 replies; 6+ messages in thread
From: Julia Lawall @ 2013-01-07 15:45 UTC (permalink / raw)
To: cocci
declarer name ASYNC_DOMAIN;
Off topic, but worth mentioning, there is also iterator name for declaring
loop constructs.
julia
On Mon, 7 Jan 2013, H?kon L?vdal wrote:
> Hi list. I have trouble getting coccinelle to match macros invoked on
> file scope (as opposed to invoked inside a function).
>
> Example: grepping the whole linux source code for ASYNC_DOMAIN gets
> three matches:
>
> linux/drivers/scsi/scsi.c:ASYNC_DOMAIN(scsi_sd_probe_domain);
> linux/include/linux/async.h:#define ASYNC_DOMAIN(_name) \
> linux/kernel/async.c:static ASYNC_DOMAIN(async_running);
>
> so if I want to know what identifier names that are used as arguments
> to ASYNC_DOMAIN I see the answer right there, but let's say I want to
> use coccinelle to find the answer.
>
>
>
> $ cat find_ASYNC_DOMAIN.cocci
>
> @rule1@
> identifier id;
> @@
>
> ASYNC_DOMAIN(id);
>
> @script:python@
> id << rule1.id;
> @@
>
> print "ASYNC_DOMAIN is called with _name equal to %s" % (id)
>
>
> $ ./spatch --sp-file find_ASYNC_DOMAIN.cocci linux/drivers/scsi/scsi.c
> linux/kernel/async.c
> init_defs_builtins: /tmp/coccinelle/share/coccinelle/standard.h
> HANDLING: linux/drivers/scsi/scsi.c linux/kernel/async.c
> $ cat dummy_async_domain_test.c
>
>
> ASYNC_DOMAIN(mytest1);
> ASYNC_DOMAIN(
> mytest2
> );
>
> int main(int argc, char *argv[])
> {
> ASYNC_DOMAIN(mytest3);
> ASYNC_DOMAIN(
> mytest4
> );
> return 0;
> }
>
> $ ./spatch --sp-file find_ASYNC_DOMAIN.cocci dummy_async_domain_test.c
> init_defs_builtins: /tmp/coccinelle/share/coccinelle/standard.h
> HANDLING: dummy_async_domain_test.c
> ASYNC_DOMAIN is called with _name equal to mytest3
> ASYNC_DOMAIN is called with _name equal to mytest4
> $
>
>
>
> As you can see the script fails to match ASYNC_DOMAIN when it is put on
> file scope but if I put it inside a function it is found. What do I need
> to change in order to match on file scope?
>
> BR H?kon L?vdal
>
>
> PS
> This was sort of a continuation of my last post, but I drilled down to the
> problem to be just macro on file scope and I though it is more clean to
> start a new thread.
> _______________________________________________
> Cocci mailing list
> Cocci at systeme.lip6.fr
> https://systeme.lip6.fr/mailman/listinfo/cocci
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Cocci] Problem matching macro invoked on file scope
2013-01-07 15:43 ` Lars-Peter Clausen
@ 2013-01-08 9:22 ` Håkon Løvdal
2013-01-08 9:28 ` Julia Lawall
0 siblings, 1 reply; 6+ messages in thread
From: Håkon Løvdal @ 2013-01-08 9:22 UTC (permalink / raw)
To: cocci
On 7 January 2013 16:43, Lars-Peter Clausen <lars@metafoo.de> wrote:
> Hi,
>
> try to add
>
> declarer name ASYNC_DOMAIN;
>
> to your cocci rule.
Exellent, yes this was exactly what I was missing. With that the script prints
ASYNC_DOMAIN is called with _name equal to async_running
ASYNC_DOMAIN is called with _name equal to scsi_sd_probe_domain
for the linux files. So the problem I started with is solved.
The following is not important to get an answer to, but I was a little
bit surprised and would like to understand the issue.
I ran the script on the dummy_async_domain_test.c file as well and it
now only matches mytest1 and mytest2, which is expected behaviour as far
as I can tell. Out of curiosity I thought that if I wanted to match all
four cases then I could just add an additional rule without declarer, e.g.
// with declarer
@rule1@
declarer name ASYNC_DOMAIN;
identifier id;
@@
ASYNC_DOMAIN(id);
@script:python@
id << rule1.id;
@@
print "1: ASYNC_DOMAIN is called with _name equal to %s" % (id)
// without declarer
@rule2@
identifier id;
@@
ASYNC_DOMAIN(id);
@script:python@
id << rule2.id;
@@
print "2: ASYNC_DOMAIN is called with _name equal to %s" % (id)
but running with this gives
1: ASYNC_DOMAIN is called with _name equal to mytest1
1: ASYNC_DOMAIN is called with _name equal to mytest2
2: ASYNC_DOMAIN is called with _name equal to mytest1
2: ASYNC_DOMAIN is called with _name equal to mytest2
so it seems that the declarer property from rule1 is "leaking" into
rule2 as well. Is this intended behaviour? If I reverse the order and
put rule2 and the corresponding python script@the top then it prints
like I expected in the first place.
2: ASYNC_DOMAIN is called with _name equal to mytest3
2: ASYNC_DOMAIN is called with _name equal to mytest4
1: ASYNC_DOMAIN is called with _name equal to mytest1
1: ASYNC_DOMAIN is called with _name equal to mytest2
BR H?kon L?vdal
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Cocci] Problem matching macro invoked on file scope
2013-01-08 9:22 ` Håkon Løvdal
@ 2013-01-08 9:28 ` Julia Lawall
2013-01-08 9:33 ` Håkon Løvdal
0 siblings, 1 reply; 6+ messages in thread
From: Julia Lawall @ 2013-01-08 9:28 UTC (permalink / raw)
To: cocci
On Tue, 8 Jan 2013, H?kon L?vdal wrote:
> On 7 January 2013 16:43, Lars-Peter Clausen <lars@metafoo.de> wrote:
> > Hi,
> >
> > try to add
> >
> > declarer name ASYNC_DOMAIN;
> >
> > to your cocci rule.
>
> Exellent, yes this was exactly what I was missing. With that the script prints
>
> ASYNC_DOMAIN is called with _name equal to async_running
> ASYNC_DOMAIN is called with _name equal to scsi_sd_probe_domain
>
> for the linux files. So the problem I started with is solved.
> The following is not important to get an answer to, but I was a little
> bit surprised and would like to understand the issue.
>
> I ran the script on the dummy_async_domain_test.c file as well and it
> now only matches mytest1 and mytest2, which is expected behaviour as far
> as I can tell. Out of curiosity I thought that if I wanted to match all
> four cases then I could just add an additional rule without declarer, e.g.
>
>
> // with declarer
> @rule1@
> declarer name ASYNC_DOMAIN;
> identifier id;
> @@
> ASYNC_DOMAIN(id);
>
> @script:python@
> id << rule1.id;
> @@
> print "1: ASYNC_DOMAIN is called with _name equal to %s" % (id)
>
> // without declarer
> @rule2@
> identifier id;
> @@
> ASYNC_DOMAIN(id);
>
> @script:python@
> id << rule2.id;
> @@
> print "2: ASYNC_DOMAIN is called with _name equal to %s" % (id)
>
>
> but running with this gives
>
> 1: ASYNC_DOMAIN is called with _name equal to mytest1
> 1: ASYNC_DOMAIN is called with _name equal to mytest2
> 2: ASYNC_DOMAIN is called with _name equal to mytest1
> 2: ASYNC_DOMAIN is called with _name equal to mytest2
>
> so it seems that the declarer property from rule1 is "leaking" into
> rule2 as well. Is this intended behaviour? If I reverse the order and
> put rule2 and the corresponding python script at the top then it prints
> like I expected in the first place.
>
> 2: ASYNC_DOMAIN is called with _name equal to mytest3
> 2: ASYNC_DOMAIN is called with _name equal to mytest4
> 1: ASYNC_DOMAIN is called with _name equal to mytest1
> 1: ASYNC_DOMAIN is called with _name equal to mytest2
Yes, for typedefs, declarer names, and iterator names, it assumes that
once you have declared them, you would always like to use them in that
way.
julia
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Cocci] Problem matching macro invoked on file scope
2013-01-08 9:28 ` Julia Lawall
@ 2013-01-08 9:33 ` Håkon Løvdal
0 siblings, 0 replies; 6+ messages in thread
From: Håkon Løvdal @ 2013-01-08 9:33 UTC (permalink / raw)
To: cocci
On 8 January 2013 10:28, Julia Lawall <julia.lawall@lip6.fr> wrote:
> Yes, for typedefs, declarer names, and iterator names, it assumes that
> once you have declared them, you would always like to use them in that
> way.
Ok, good to know.
BR H?kon L?vdal
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2013-01-08 9:33 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-01-07 15:34 [Cocci] Problem matching macro invoked on file scope Håkon Løvdal
2013-01-07 15:43 ` Lars-Peter Clausen
2013-01-08 9:22 ` Håkon Løvdal
2013-01-08 9:28 ` Julia Lawall
2013-01-08 9:33 ` Håkon Løvdal
2013-01-07 15:45 ` Julia Lawall
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox