[Cocci] Finding embedded function names?

Joe Perches joe at perches.com
Fri Dec 5 08:28:36 CET 2014


On Fri, 2014-12-05 at 08:18 +0100, Julia Lawall wrote:
> On Thu, 4 Dec 2014, Joe Perches wrote:
> > Is it possible for coccinelle to look at the name
> > of a function that might be embedded in a format?
> > ie for:
> > void testme(void)
> > {
> > 	printf("testme: some message\n");
> > }
> > Can it find the "testme" embedded in a format string?
> 
> Yes, by using python/ocaml:
> 
> @r@
> char [] c;
> position p;
> identifier f;
> @@
> 
> f(...,c at p,...)
> 
> @script:ocaml@
> c << r.c;
> p << r.p;
> @@
> 
> let ce = (List.hd p).current_element in
> if List.length(Str.split_delim (Str.regexp ce) c) > 1
> then Printf.printf "%s:%d: %s\n"
>        (List.hd p).file (List.hd p).line c

Good to know, thanks.

> Here are some results:
> 
> drivers/net/wireless/zd1211rw/zd_usb.c:1573: "%s usb_exit()\n"
[]
> The idea would be to replace these by %s and __func__?  That would also be 
> possible.

Yes and no.

A lot of these are function tracing style messages and
those should just be deleted.

Otherwise, yes.




More information about the Cocci mailing list