[Cocci] Problem matching macro invoked on file scope

Håkon Løvdal
2013-01-07T15:34:09Z

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.