On 29/02/2012 07:29, Julia Lawall wrote:
On Wed, 29 Feb 2012, David Wagner wrote:

With Coccinelle, you can make arbitrarily complicated matches. Look at
the examples on the webiste. They are a bit oriented towards bug
finding, but you should get the idea.

I also imagined it could be possible to parse the code and build an
SQL database from it but I'm not sure that it is fit and I can only
begin to imagine all the problems I would run into.

You can also use python or ocaml to insert information into a database.

Do you know of someone who has done that or is it just a suggestion ? Maybe it could be worth a try once I manage to get a grasp at spatch. It's great that there is a Python support; that will save me some effort (or you could say it's a shame I won't have to learn OCaml) :)


Here is your semantic patch, using ocaml scripting:

@initialize:ocaml@
let tbl = Hashtbl.create 101

@match@
identifier virtual.func;
expression e1,e2;
@@

func(e1,e2)

@script:ocaml@
e2 << match.e2;
@@

if not (Hashtbl.mem tbl e2) then Hashtbl.add tbl e2 ()

@finalize:ocaml@
let elements =
Hashtbl.fold (fun key _ rest -> key :: rest) tbl [] in
Printf.printf "(%s)" (String.concat ", " elements)

func is a virtual identifier so you can give it on the command line:

spatch -sp_file david.cocci -D func=usb_submit_urb -dir /path/to/linux

gives

(flags, GFP_KERNEL, gfp_flags, GFP_ATOMIC, mf, gfp, mem_flags, GFP_NOIO,
gfp_mask, f)

Awesome !
I guess it could be possible with something like
"
e2 = x
...
func(e1,e2)
"
to be sometimes able to get the real value of gfp_flags, for instance ?
Is "nesting"/"including" spatches possible ?
Anyway, I will explore the possibilities of Coccinelle and find out by myself.


If you want to do this on a large code base, you may want to run glimpse
or idutils on it first to improve efficiency. For glimpse, there is
coccinelle/scripts/glimpseindex_cocci.sh to use the right options. Then
run coccinelle with --use-glimpse. Glimpse is not free software though.
I guess you just run it in the normal way and then use the option
--use-idutils with spatch.

ok


julia


Thanks a lot for your help !
David.

_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)

Reply via email to