On Wed, 20 Nov 2019, Enrico Weigelt, metux IT consult wrote:

> Hi folks,
>
>
> is there a way to scan for code lines that access certain struct
> members ?

@@
struct structure_of_interest x;
@@

* x.field_of_interest

This will take care of pointers as well.

If you want to check on many types and fields, you can use the following
rule:

@@
identifier virtual.ty;
struct ty x;
identifier virtual.fld;
@@

* x.fld

Then you can run it with the command-line options:

-D ty=type_of_interest -D fld=field_of_interest

To figure out all the types, Coccinelle may need information from header
files.  So you could run it with the options

--recursive-includes --include-headers-for-types --relax-include-path

This will take a long time.

It may be useful to use to python code to note the file in which the
reference occurs, and then only print a message if it is a file that is of
concern.  So you could have:

@r@
identifier virtual.ty;
struct ty x;
identifier virtual.fld;
position p;
@@

* x.fld@p

@script:python@
p << r.p;
@@

... p[0].file ...

Let me know if anything is not clear.

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

Reply via email to