From: lars@metafoo.de (Lars-Peter Clausen)
To: cocci@systeme.lip6.fr
Subject: [Cocci] Problem matching macro invoked on file scope
Date: Mon, 07 Jan 2013 16:43:28 +0100 [thread overview]
Message-ID: <50EAED20.8040500@metafoo.de> (raw)
In-Reply-To: <CAACXqO-cqgSvc4k-881NV5Q7MrAs-HN28Aha-pM8deo+hA9gQg@mail.gmail.com>
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
next prev parent reply other threads:[~2013-01-07 15:43 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
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=50EAED20.8040500@metafoo.de \
--to=lars@metafoo.de \
--cc=cocci@systeme.lip6.fr \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox