[cocci] Can we match a known macro by macro name instead of expanded function name?

Tobias Deiminger <[email protected]>
Newsgroups fr.inria.cocci
Message-ID <[email protected]>
Hi,

my newbie assumption was we could match the following by macro name

   // my.c
   SYSCALL_DEFINE0(foo_bar) { return; }

using this rules

   // my.cocci
   @r@
   identifier fn =~ "SYSCALL_DEFINE[0-6]+";
   position p;
   @@
   fn@p(...) {...}

   @script:python@
   fn << r.fn;
   p << r.p;
   @@
   print(f"match: {fn} at line {p[0].current_element_line}")


Turns out, SYSCALL_DEFINE0 is a "known macro" from 
/usr/lib/coccinelle/standard.h. In this case coccinelle seems to match 
an identifier on the expanded function name, not the macro name. I.e., 
this would work:

   identifier fn =~ "foo.*";

But I really want to search all syscalls by the conventional macro 
names, i.e. search for SYSCALL_DEFINE[0-6]+. How to do that?

Tobias
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.