On Sat, May 16, 2020 at 4:49 PM Julia Lawall <[email protected]> wrote:
>
>
>
> On Sat, 16 May 2020, Chuhong Yuan wrote:
>
> > Hi all,
> > I want to write a script to match function calls in macros
> > but I don't know how to do that.
> > Here is an example:
> >
> > #define __INIT_WORK(_work, _func, _onstack)     \
> >     do {     \
> >         static struct lock_class_key __key; \
> >         \
> >         __init_work((_work), _onstack); \
> >         (_work)->data = (atomic_long_t) WORK_DATA_INIT(); \
> >         lockdep_init_map(&(_work)->lockdep_map,
> > "(work_completion)"#_work, &__key, 0); \
> >         INIT_LIST_HEAD(&(_work)->entry); \
> >         (_work)->func = (_func); \
> >     } while (0)
> >
> > In this example, I want to match function calls
> > like __init_work() and lockdep_init_map() in this macro.
> > So how to implement this by Coccinelle?
>
> I would suggest to take your file and run spatch --parse-c on the file.
> If you find BAD or bad in front of the lines of this code then the problem
> is that the code is not being parsed.  I suspect that the # is the
> problem.
>

I have run parse-c and it says the example file is perfect.

> Normally, Coccinelle will match code inside of macro definitions, but only
> if it is able to parse the macro definition, and the ability to parse
> macro definitions is somewhat limited.
>

My expression is not very clear.
I want to know which macros have function calls and what functions do they call.
So I wrote a script like this:

- #define mac(...) ... f(...) ...

But it does not work on the example.

> julia
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

Reply via email to