cocci.inria.fr archive mirror
 help / color / mirror / Atom feed
From: Julia Lawall <julia.lawall@lip6.fr>
To: "Enrico Weigelt, metux IT consult" <lkml@metux.net>
Cc: Coccinelle <cocci@systeme.lip6.fr>
Subject: Re: [Cocci] field access scoping / check who accesses certain struct members ?
Date: Wed, 20 Nov 2019 21:44:13 +0100 (CET)	[thread overview]
Message-ID: <alpine.DEB.2.21.1911202134250.2595@hadrien> (raw)
In-Reply-To: <66e7cfc9-e1c9-2b89-5d22-c6f6910aad1b@metux.net>



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
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

  reply	other threads:[~2019-11-20 20:44 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-20 19:50 [Cocci] field access scoping / check who accesses certain struct members ? Enrico Weigelt, metux IT consult
2019-11-20 20:44 ` Julia Lawall [this message]
2019-11-21 16:04   ` Markus Elfring

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=alpine.DEB.2.21.1911202134250.2595@hadrien \
    --to=julia.lawall@lip6.fr \
    --cc=cocci@systeme.lip6.fr \
    --cc=lkml@metux.net \
    /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;
as well as URLs for NNTP newsgroup(s).